From 4add67232c51dff5d0d50d755cbc3024fcb1b542 Mon Sep 17 00:00:00 2001 From: Vladimir Bachinskiy Date: Thu, 29 Aug 2024 15:10:03 +0300 Subject: [PATCH] Pull request 323: AG-34945: Add deprecated field to metadata Merge in ADGUARD-FILTERS/compiler from AG-34945 to master Squashed commit of the following: commit 84107afe09ba39f196e8f6d22dc14180d9bfd6e0 Author: Vladimir Bachinskiy Date: Thu Aug 29 14:59:27 2024 +0300 AG-34945: No need to reflect old changes in changelog commit b721a9a6f374ed7257bd1d92da91480080d4af11 Author: Slava Leleka Date: Thu Aug 29 14:57:37 2024 +0300 CHANGELOG.md edited online with Bitbucket commit df1e29293e972c6ab63f87b5c0689db7681bf8da Author: Vladimir Bachinskiy Date: Thu Aug 29 14:43:31 2024 +0300 AG-34945: Changelog commit a1049d3798aa978a9469ba1d2f7becefe344e715 Author: Vladimir Bachinskiy Date: Thu Aug 29 14:35:25 2024 +0300 AG-34945: Add deprecated field to metadata --- CHANGELOG.md | 8 +++++++ schemas/filters.schema.json | 7 ++++++ src/main/platforms/generator.js | 22 +++++++++++++------ src/main/utils/workaround.js | 2 ++ src/test/builder.test.js | 5 +++++ .../filters/filter_2_English/metadata.json | 1 + 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd436104..ef96ad09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.1.146] - 2024-08-29 + +### Added + +- `deprecated` property to the built filters metadata + +[v1.1.146]: https://github.com/AdguardTeam/FiltersCompiler/compare/v1.1.144...v1.1.146 + ## [v1.1.144] - 2024-08-14 ### Fixed diff --git a/schemas/filters.schema.json b/schemas/filters.schema.json index a81b786d..f3ac1812 100644 --- a/schemas/filters.schema.json +++ b/schemas/filters.schema.json @@ -111,6 +111,7 @@ "downloadUrl", "version", "timeUpdated", + "deprecated", "languages", "tags" ], @@ -154,6 +155,12 @@ ], "pattern": "^(.*)$" }, + "deprecated": { + "$id": "#/properties/filters/items/properties/deprecated", + "type": "boolean", + "title": "Filter is deprecated and shoudln't be used", + "default": false + }, "homepage": { "$id": "#/properties/filters/items/properties/homepage", "type": "string", diff --git a/src/main/platforms/generator.js b/src/main/platforms/generator.js index e444a1c9..7f36c329 100644 --- a/src/main/platforms/generator.js +++ b/src/main/platforms/generator.js @@ -338,17 +338,24 @@ module.exports = (() => { }; /** - * In case of backward compatibility - * Adds 'languages' metadata field parsed from 'lang:' tags + * First step of processing filters metadata * - * @param rawFilters + * @param filtersMetadata */ - const parseLangTags = function (rawFilters) { + const processFiltersFromMetadata = function (filtersMetadata) { // do not mutate input parameters const filters = []; // eslint-disable-next-line no-restricted-syntax - for (const filter of rawFilters) { - const newFilter = { ...filter }; + for (const filter of filtersMetadata) { + const newFilter = { + ...filter, + deprecated: Boolean(filter.deprecated), + }; + + /** + * In case of backward compatibility + * Adds 'languages' metadata field parsed from 'lang:' tags + */ if (newFilter.tags) { const filterLanguages = []; let hasRecommended = false; @@ -366,6 +373,7 @@ module.exports = (() => { // Languages will be added for recommended filters only newFilter.languages = hasRecommended ? filterLanguages : []; } + filters.push(newFilter); } @@ -617,7 +625,7 @@ module.exports = (() => { } // do not mutate input parameters - const parsedLangTagsFiltersMetadata = parseLangTags(filtersMetadata); + const parsedLangTagsFiltersMetadata = processFiltersFromMetadata(filtersMetadata); const replacedTagKeywordsFiltersMetadata = replaceTagKeywords(parsedLangTagsFiltersMetadata, tags); const localizations = loadLocales(path.join(filtersDir, '../locales')); diff --git a/src/main/utils/workaround.js b/src/main/utils/workaround.js index 610602fc..cc4da1ba 100644 --- a/src/main/utils/workaround.js +++ b/src/main/utils/workaround.js @@ -147,6 +147,8 @@ module.exports = (() => { delete copy.timeAdded; delete copy.trustLevel; delete copy.downloadUrl; + delete copy.deprecated; + result.filters.push(copy); } diff --git a/src/test/builder.test.js b/src/test/builder.test.js index 0fd56528..52d247d2 100644 --- a/src/test/builder.test.js +++ b/src/test/builder.test.js @@ -384,6 +384,11 @@ describe('Test builder', () => { expect(filtersMetadata.filters[0].tags[0]).toEqual(1); expect(filtersMetadata.filters[0].trustLevel).toEqual('full'); + // Deprecated + filtersMetadata.filters.forEach((filter) => { + expect(filter.deprecated).toBe(filter.filterId === 2); + }); + // Obsolete Filter test expect(filtersMetadata.filters.some((filter) => filter.filterId === 6)).toBeFalsy(); expect(filtersMetadata.filters.some((filter) => filter.name === 'Obsolete Test Filter')).toBeFalsy(); diff --git a/src/test/resources/filters/filter_2_English/metadata.json b/src/test/resources/filters/filter_2_English/metadata.json index 907852bf..bbc679e8 100644 --- a/src/test/resources/filters/filter_2_English/metadata.json +++ b/src/test/resources/filters/filter_2_English/metadata.json @@ -7,6 +7,7 @@ "expires": "2 days", "displayNumber": 101, "groupId": 2, + "deprecated": true, "subscriptionUrl": "https://filters.adtidy.org/extension/chromium/filters/2.txt", "tags": [ "purpose:ads", "lang:en", "lang:pl", "recommended"