@adguard/agtree 2.2.0 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/ast-utils/clone.js +61 -0
- package/dist/ast-utils/modifiers.js +53 -0
- package/dist/ast-utils/network-rules.js +41 -0
- package/dist/ast-utils/scriptlets.js +87 -0
- package/dist/common/abp-snippet-injection-body-common.js +23 -0
- package/dist/common/agent-common.js +56 -0
- package/dist/common/ubo-selector-common.js +17 -0
- package/dist/compatibility-tables/base.js +262 -0
- package/dist/compatibility-tables/compatibility-table-data.js +11 -0
- package/dist/compatibility-tables/modifiers.js +55 -0
- package/dist/compatibility-tables/platforms.js +76 -0
- package/dist/compatibility-tables/redirects.js +100 -0
- package/dist/compatibility-tables/schemas/base.js +111 -0
- package/dist/compatibility-tables/schemas/modifier.js +129 -0
- package/dist/compatibility-tables/schemas/platform.js +69 -0
- package/dist/compatibility-tables/schemas/redirect.js +29 -0
- package/dist/compatibility-tables/schemas/resource-type.js +36 -0
- package/dist/compatibility-tables/schemas/scriptlet.js +79 -0
- package/dist/compatibility-tables/scriptlets.js +28 -0
- package/dist/compatibility-tables/utils/platform-helpers.js +105 -0
- package/dist/compatibility-tables/utils/resource-type-helpers.js +61 -0
- package/dist/compatibility-tables/utils/zod-camelcase.js +25 -0
- package/dist/converter/base-interfaces/base-converter.js +59 -0
- package/dist/converter/base-interfaces/conversion-result.js +38 -0
- package/dist/converter/base-interfaces/rule-converter-base.js +60 -0
- package/dist/converter/comment/index.js +54 -0
- package/dist/converter/cosmetic/css.js +69 -0
- package/dist/converter/cosmetic/element-hiding.js +62 -0
- package/dist/converter/cosmetic/header-removal.js +123 -0
- package/dist/converter/cosmetic/html.js +379 -0
- package/dist/converter/cosmetic/index.js +118 -0
- package/dist/converter/cosmetic/rule-modifiers/adg.js +79 -0
- package/dist/converter/cosmetic/scriptlet.js +354 -0
- package/dist/converter/css/index.js +188 -0
- package/dist/converter/data/css.js +126 -0
- package/dist/converter/filter-list.js +88 -0
- package/dist/converter/index.js +8 -0
- package/dist/converter/misc/network-rule-modifier.js +311 -0
- package/dist/converter/network/index.js +99 -0
- package/dist/converter/raw-filter-list.js +56 -0
- package/dist/converter/rule.js +81 -0
- package/dist/deserializer/base-deserializer.js +29 -0
- package/dist/deserializer/comment/agent-comment-deserializer.js +79 -0
- package/dist/deserializer/comment/agent-deserializer.js +65 -0
- package/dist/deserializer/comment/comment-rule-deserializer.js +54 -0
- package/dist/deserializer/comment/config-comment-deserializer.js +111 -0
- package/dist/deserializer/comment/hint-comment-deserializer.js +72 -0
- package/dist/deserializer/comment/hint-deserializer.js +85 -0
- package/dist/deserializer/comment/metadata-comment-deserializer.js +69 -0
- package/dist/deserializer/comment/pre-processor-comment-deserializer.js +112 -0
- package/dist/deserializer/comment/simple-comment-deserializer.js +65 -0
- package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +131 -0
- package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +56 -0
- package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +48 -0
- package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +39 -0
- package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +40 -0
- package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +54 -0
- package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
- package/dist/deserializer/empty-rule-deserializer.js +48 -0
- package/dist/deserializer/filterlist-deserializer.js +85 -0
- package/dist/deserializer/index.js +8 -0
- package/dist/deserializer/invalid-rule-deserializer.js +50 -0
- package/dist/deserializer/invalid-rule-error-node-deserializer.js +50 -0
- package/dist/deserializer/misc/domain-list-deserializer.js +64 -0
- package/dist/deserializer/misc/list-item-deserializer.js +69 -0
- package/dist/deserializer/misc/list-items-deserializer.js +30 -0
- package/dist/deserializer/misc/logical-expression-deserializer.js +196 -0
- package/dist/deserializer/misc/modifier-deserializer.js +87 -0
- package/dist/deserializer/misc/modifier-list-deserializer.js +61 -0
- package/dist/deserializer/misc/parameter-list-deserializer.js +64 -0
- package/dist/deserializer/misc/value-deserializer.js +50 -0
- package/dist/deserializer/network/host-rule-deserializer.js +67 -0
- package/dist/deserializer/network/hostname-list-deserializer.js +56 -0
- package/dist/deserializer/network/network-rule-deserializer.js +65 -0
- package/dist/deserializer/rule-deserializer.js +65 -0
- package/dist/deserializer/syntax-deserialization-map.js +21 -0
- package/dist/errors/adblock-syntax-error.js +39 -0
- package/dist/errors/binary-schema-mismatch-error.js +37 -0
- package/dist/errors/not-implemented-error.js +31 -0
- package/dist/errors/rule-conversion-error.js +26 -0
- package/dist/generator/base-generator.js +27 -0
- package/dist/generator/comment/agent-comment-generator.js +31 -0
- package/dist/generator/comment/agent-generator.js +36 -0
- package/dist/generator/comment/comment-rule-generator.js +47 -0
- package/dist/generator/comment/config-comment-generator.js +45 -0
- package/dist/generator/comment/hint-comment-generator.js +28 -0
- package/dist/generator/comment/hint-generator.js +33 -0
- package/dist/generator/comment/metadata-comment-generator.js +33 -0
- package/dist/generator/comment/pre-processor-comment-generator.js +48 -0
- package/dist/generator/comment/simple-comment-generator.js +29 -0
- package/dist/generator/cosmetic/body/abp-snippet-injection-body-generator.js +38 -0
- package/dist/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +43 -0
- package/dist/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +45 -0
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +94 -0
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +54 -0
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +42 -0
- package/dist/generator/css/adg-css-injection-generator.js +42 -0
- package/dist/generator/filterlist-generator.js +67 -0
- package/dist/generator/index.js +9 -0
- package/dist/generator/misc/domain-list-generator.js +26 -0
- package/dist/generator/misc/list-items-generator.js +39 -0
- package/dist/generator/misc/logical-expression-generator.js +48 -0
- package/dist/generator/misc/modifier-generator.js +34 -0
- package/dist/generator/misc/modifier-list-generator.js +29 -0
- package/dist/generator/misc/parameter-list-generator.js +41 -0
- package/dist/generator/misc/value-generator.js +24 -0
- package/dist/generator/network/host-rule-generator.js +39 -0
- package/dist/generator/network/network-rule-generator.js +38 -0
- package/dist/generator/rule-generator.js +65 -0
- package/dist/index.js +70 -0
- package/dist/marshalling-utils/comment/agent-comment-common.js +21 -0
- package/dist/marshalling-utils/comment/agent-common.js +40 -0
- package/dist/marshalling-utils/comment/config-comment-common.js +54 -0
- package/dist/marshalling-utils/comment/hint-comment-common.js +22 -0
- package/dist/marshalling-utils/comment/hint-common.js +56 -0
- package/dist/marshalling-utils/comment/metadata-comment-common.js +41 -0
- package/dist/marshalling-utils/comment/pre-processor-comment-common.js +59 -0
- package/dist/marshalling-utils/comment/simple-comment-common.js +22 -0
- package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +61 -0
- package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +66 -0
- package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +24 -0
- package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +21 -0
- package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +114 -0
- package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +48 -0
- package/dist/marshalling-utils/empty-rule-common.js +20 -0
- package/dist/marshalling-utils/filter-list-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-error-node-common.js +22 -0
- package/dist/marshalling-utils/misc/binary-type-common.js +66 -0
- package/dist/marshalling-utils/misc/domain-list-common.js +36 -0
- package/dist/marshalling-utils/misc/host-rule-common.js +25 -0
- package/dist/marshalling-utils/misc/hostname-list-common.js +21 -0
- package/dist/marshalling-utils/misc/list-item-common.js +22 -0
- package/dist/marshalling-utils/misc/logical-expression-common.js +83 -0
- package/dist/marshalling-utils/misc/modifier-common.js +231 -0
- package/dist/marshalling-utils/misc/modifier-list-common.js +21 -0
- package/dist/marshalling-utils/misc/parameter-list-common.js +21 -0
- package/dist/marshalling-utils/misc/value-common.js +22 -0
- package/dist/marshalling-utils/network/network-rule-common.js +25 -0
- package/dist/marshalling-utils/syntax-serialization-map.js +30 -0
- package/dist/nodes/index.js +168 -0
- package/dist/package.json.js +9 -0
- package/dist/parser/base-parser.js +30 -0
- package/dist/parser/comment/agent-comment-parser.js +119 -0
- package/dist/parser/comment/agent-parser.js +110 -0
- package/dist/parser/comment/comment-parser.js +108 -0
- package/dist/parser/comment/config-comment-parser.js +137 -0
- package/dist/parser/comment/hint-comment-parser.js +117 -0
- package/dist/parser/comment/hint-parser.js +129 -0
- package/dist/parser/comment/metadata-comment-parser.js +129 -0
- package/dist/parser/comment/preprocessor-parser.js +199 -0
- package/dist/parser/comment/simple-comment-parser.js +106 -0
- package/dist/parser/cosmetic/body/abp-snippet-injection-body-parser.js +79 -0
- package/dist/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +149 -0
- package/dist/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +110 -0
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +453 -0
- package/dist/parser/css/adg-css-injection-parser.js +208 -0
- package/dist/parser/css/balancing.js +94 -0
- package/dist/parser/css/constants.js +18 -0
- package/dist/parser/css/css-token-stream.js +343 -0
- package/dist/parser/css/ubo-selector-parser.js +369 -0
- package/dist/parser/filterlist-parser.js +102 -0
- package/dist/parser/index.js +12 -0
- package/dist/parser/misc/app-list-parser.js +45 -0
- package/dist/parser/misc/domain-list-parser.js +52 -0
- package/dist/parser/misc/list-items-parser.js +116 -0
- package/dist/parser/misc/logical-expression-parser.js +279 -0
- package/dist/parser/misc/method-list-parser.js +46 -0
- package/dist/parser/misc/modifier-list.js +70 -0
- package/dist/parser/misc/modifier-parser.js +89 -0
- package/dist/parser/misc/parameter-list-parser.js +75 -0
- package/dist/parser/misc/stealth-option-list-parser.js +46 -0
- package/dist/parser/misc/ubo-parameter-list-parser.js +149 -0
- package/dist/parser/misc/value-parser.js +37 -0
- package/dist/parser/network/host-rule-parser.js +130 -0
- package/dist/parser/network/network-rule-parser.js +117 -0
- package/dist/parser/options.js +23 -0
- package/dist/parser/rule-parser.js +192 -0
- package/dist/serializer/base-serializer.js +29 -0
- package/dist/serializer/comment/agent-comment-serializer.js +74 -0
- package/dist/serializer/comment/agent-serializer.js +59 -0
- package/dist/serializer/comment/comment-rule-serializer.js +105 -0
- package/dist/serializer/comment/config-comment-serializer.js +82 -0
- package/dist/serializer/comment/hint-comment-serializer.js +65 -0
- package/dist/serializer/comment/hint-serializer.js +54 -0
- package/dist/serializer/comment/metadata-comment-serializer.js +73 -0
- package/dist/serializer/comment/pre-processor-comment-serializer.js +71 -0
- package/dist/serializer/comment/simple-comment-serializer.js +52 -0
- package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +50 -0
- package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +120 -0
- package/dist/serializer/cosmetic/css-injection-body-serializer.js +51 -0
- package/dist/serializer/cosmetic/element-hiding-body-serializer.js +40 -0
- package/dist/serializer/empty-rule-serializer.js +37 -0
- package/dist/serializer/filterlist-serializer.js +45 -0
- package/dist/serializer/index.js +7 -0
- package/dist/serializer/invalid-rule-error-node-serializer.js +41 -0
- package/dist/serializer/invalid-rule-serializer.js +40 -0
- package/dist/serializer/misc/domain-list-serializer.js +64 -0
- package/dist/serializer/misc/list-item-serializer.js +58 -0
- package/dist/serializer/misc/list-items-serializer.js +29 -0
- package/dist/serializer/misc/logical-expression-serializer.js +136 -0
- package/dist/serializer/misc/modifier-list-serializer.js +58 -0
- package/dist/serializer/misc/modifier-serializer.js +49 -0
- package/dist/serializer/misc/parameter-list-serializer.js +52 -0
- package/dist/serializer/misc/value-serializer.js +50 -0
- package/dist/serializer/network/host-rule-serializer.js +70 -0
- package/dist/serializer/network/hostname-list-serializer.js +53 -0
- package/dist/serializer/network/network-rule-serializer.js +54 -0
- package/dist/serializer/rule-serializer.js +61 -0
- package/dist/types/ast-utils/clone.d.ts +26 -0
- package/dist/types/ast-utils/filter-list.d.ts +11 -0
- package/dist/types/ast-utils/modifiers.d.ts +20 -0
- package/dist/types/ast-utils/network-rules.d.ts +15 -0
- package/dist/types/ast-utils/scriptlets.d.ts +52 -0
- package/dist/types/common/abp-snippet-injection-body-common.d.ts +15 -0
- package/dist/types/common/agent-common.d.ts +10 -0
- package/dist/types/common/ubo-selector-common.d.ts +10 -0
- package/dist/types/compatibility-tables/base.d.ts +157 -0
- package/dist/types/compatibility-tables/compatibility-table-data.d.ts +68 -0
- package/dist/types/compatibility-tables/index.d.ts +13 -0
- package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
- package/dist/types/compatibility-tables/platforms.d.ts +49 -0
- package/dist/types/compatibility-tables/redirects.d.ts +33 -0
- package/dist/types/compatibility-tables/schemas/base.d.ts +124 -0
- package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
- package/dist/types/compatibility-tables/schemas/modifier.d.ts +36 -0
- package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
- package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
- package/dist/types/compatibility-tables/schemas/resource-type.d.ts +41 -0
- package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
- package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
- package/dist/types/compatibility-tables/types.d.ts +34 -0
- package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
- package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
- package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
- package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
- package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
- package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
- package/dist/types/converter/comment/index.d.ts +23 -0
- package/dist/types/converter/cosmetic/css.d.ts +23 -0
- package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
- package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
- package/dist/types/converter/cosmetic/html.d.ts +54 -0
- package/dist/types/converter/cosmetic/index.d.ts +33 -0
- package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
- package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
- package/dist/types/converter/css/index.d.ts +40 -0
- package/dist/types/converter/data/css.d.ts +48 -0
- package/dist/types/converter/filter-list.d.ts +31 -0
- package/dist/types/converter/index.d.ts +5 -0
- package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
- package/dist/types/converter/network/index.d.ts +33 -0
- package/dist/types/converter/raw-filter-list.d.ts +31 -0
- package/dist/types/converter/raw-rule.d.ts +28 -0
- package/dist/types/converter/rule.d.ts +37 -0
- package/dist/types/deserializer/base-deserializer.d.ts +15 -0
- package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
- package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
- package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
- package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
- package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
- package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +15 -0
- package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +16 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +19 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/empty-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/filterlist-deserializer.d.ts +34 -0
- package/dist/types/deserializer/index.d.ts +2 -0
- package/dist/types/deserializer/invalid-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/misc/list-item-deserializer.d.ts +19 -0
- package/dist/types/deserializer/misc/list-items-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
- package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
- package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
- package/dist/types/deserializer/network/host-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
- package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
- package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
- package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
- package/dist/types/errors/not-implemented-error.d.ts +14 -0
- package/dist/types/errors/rule-conversion-error.d.ts +14 -0
- package/dist/types/generator/base-generator.d.ts +12 -0
- package/dist/types/generator/comment/agent-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/agent-generator.d.ts +15 -0
- package/dist/types/generator/comment/comment-rule-generator.d.ts +14 -0
- package/dist/types/generator/comment/config-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-generator.d.ts +14 -0
- package/dist/types/generator/comment/index.d.ts +1 -0
- package/dist/types/generator/comment/metadata-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/simple-comment-generator.d.ts +14 -0
- package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +20 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +28 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +18 -0
- package/dist/types/generator/cosmetic/index.d.ts +1 -0
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +15 -0
- package/dist/types/generator/css/ubo-selector-generator.d.ts +14 -0
- package/dist/types/generator/filterlist-generator.d.ts +18 -0
- package/dist/types/generator/index.d.ts +3 -0
- package/dist/types/generator/misc/domain-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/list-items-generator.d.ts +25 -0
- package/dist/types/generator/misc/logical-expression-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-list-generator.d.ts +14 -0
- package/dist/types/generator/misc/parameter-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/value-generator.d.ts +14 -0
- package/dist/types/generator/network/host-rule-generator.d.ts +14 -0
- package/dist/types/generator/network/index.d.ts +2 -0
- package/dist/types/generator/network/network-rule-generator.d.ts +14 -0
- package/dist/types/generator/rule-generator.d.ts +24 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +14 -0
- package/dist/types/marshalling-utils/comment/agent-common.d.ts +20 -0
- package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +42 -0
- package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/comment/hint-common.d.ts +33 -0
- package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +21 -0
- package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +37 -0
- package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +23 -0
- package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +17 -0
- package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +14 -0
- package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +28 -0
- package/dist/types/marshalling-utils/empty-rule-common.d.ts +13 -0
- package/dist/types/marshalling-utils/filter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +57 -0
- package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +24 -0
- package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/list-item-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +47 -0
- package/dist/types/marshalling-utils/misc/modifier-common.d.ts +41 -0
- package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/value-common.d.ts +15 -0
- package/dist/types/marshalling-utils/network/network-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
- package/dist/types/nodes/index.d.ts +1183 -0
- package/dist/types/parser/base-parser.d.ts +16 -0
- package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
- package/dist/types/parser/comment/agent-parser.d.ts +33 -0
- package/dist/types/parser/comment/comment-parser.d.ts +76 -0
- package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
- package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
- package/dist/types/parser/comment/hint-parser.d.ts +30 -0
- package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
- package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
- package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
- package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
- package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
- package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
- package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
- package/dist/types/parser/css/balancing.d.ts +36 -0
- package/dist/types/parser/css/constants.d.ts +10 -0
- package/dist/types/parser/css/css-token-stream.d.ts +210 -0
- package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
- package/dist/types/parser/filterlist-parser.d.ts +29 -0
- package/dist/types/parser/index.d.ts +6 -0
- package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
- package/dist/types/parser/misc/list-items-parser.d.ts +37 -0
- package/dist/types/parser/misc/logical-expression-parser.d.ts +42 -0
- package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/modifier-list.d.ts +24 -0
- package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
- package/dist/types/parser/misc/parameter-list-parser.d.ts +17 -0
- package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +21 -0
- package/dist/types/parser/misc/value-parser.d.ts +18 -0
- package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
- package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
- package/dist/types/parser/options.d.ts +41 -0
- package/dist/types/parser/rule-parser.d.ts +78 -0
- package/dist/types/serializer/base-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
- package/dist/types/serializer/comment/agent-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
- package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
- package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
- package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
- package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
- package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +17 -0
- package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +19 -0
- package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +15 -0
- package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +15 -0
- package/dist/types/serializer/empty-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/filterlist-serializer.d.ts +15 -0
- package/dist/types/serializer/index.d.ts +1 -0
- package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +15 -0
- package/dist/types/serializer/invalid-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
- package/dist/types/serializer/misc/list-item-serializer.d.ts +16 -0
- package/dist/types/serializer/misc/list-items-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/logical-expression-serializer.d.ts +52 -0
- package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
- package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
- package/dist/types/serializer/misc/parameter-list-serializer.d.ts +17 -0
- package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
- package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
- package/dist/types/serializer/network/hostname-list-serializer.d.ts +15 -0
- package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
- package/dist/types/serializer/rule-serializer.d.ts +17 -0
- package/dist/types/utils/adblockers.d.ts +49 -0
- package/dist/types/utils/binary-schema-version.d.ts +9 -0
- package/dist/types/utils/byte-buffer.d.ts +54 -0
- package/dist/types/utils/categorizer.d.ts +14 -0
- package/dist/types/utils/clone.d.ts +15 -0
- package/dist/types/utils/constants.d.ts +188 -0
- package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
- package/dist/types/utils/deep-freeze.d.ts +13 -0
- package/dist/types/utils/domain.d.ts +29 -0
- package/dist/types/utils/error.d.ts +8 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/dist/types/utils/input-byte-buffer.d.ts +146 -0
- package/dist/types/utils/is-chromium.d.ts +7 -0
- package/dist/types/utils/logical-expression.d.ts +45 -0
- package/dist/types/utils/multi-value-map.d.ts +16 -0
- package/dist/types/utils/output-byte-buffer.d.ts +132 -0
- package/dist/types/utils/position-provider.d.ts +46 -0
- package/dist/types/utils/quotes.d.ts +94 -0
- package/dist/types/utils/regexp.d.ts +54 -0
- package/dist/types/utils/storage-interface.d.ts +23 -0
- package/dist/types/utils/string.d.ts +280 -0
- package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
- package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
- package/dist/types/utils/type-guards.d.ts +47 -0
- package/dist/types/validator/constants.d.ts +89 -0
- package/dist/types/validator/helpers.d.ts +37 -0
- package/dist/types/validator/index.d.ts +38 -0
- package/dist/types/validator/value.d.ts +12 -0
- package/dist/types/version.d.ts +5 -0
- package/dist/utils/adblockers.js +56 -0
- package/dist/utils/binary-schema-version.js +17 -0
- package/dist/utils/byte-buffer.js +91 -0
- package/dist/utils/categorizer.js +44 -0
- package/dist/utils/clone.js +28 -0
- package/dist/utils/constants.js +249 -0
- package/dist/utils/cosmetic-rule-separator.js +127 -0
- package/dist/utils/deep-freeze.js +32 -0
- package/dist/utils/domain.js +59 -0
- package/dist/utils/error.js +49 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/input-byte-buffer.js +265 -0
- package/dist/utils/is-chromium.js +20 -0
- package/dist/utils/logical-expression.js +92 -0
- package/dist/utils/multi-value-map.js +33 -0
- package/dist/utils/output-byte-buffer.js +231 -0
- package/dist/utils/position-provider.js +73 -0
- package/dist/utils/quotes.js +214 -0
- package/dist/utils/regexp.js +176 -0
- package/dist/utils/string.js +559 -0
- package/dist/utils/text-decoder-polyfill.js +107 -0
- package/dist/utils/text-encoder-polyfill.js +78 -0
- package/dist/utils/type-guards.js +47 -0
- package/dist/validator/constants.js +210 -0
- package/dist/validator/helpers.js +45 -0
- package/dist/validator/index.js +174 -0
- package/dist/validator/value.js +568 -0
- package/dist/version.js +18 -0
- package/package.json +61 -39
- package/dist/agtree.d.ts +0 -4155
- package/dist/agtree.js +0 -15819
- package/dist/agtree.mjs +0 -15720
- package/dist/compatibility-table-data.js +0 -12782
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { CompatibilityTableBase } from './base.js';
|
|
8
|
+
import { modifiersCompatibilityTableData } from './compatibility-table-data.js';
|
|
9
|
+
import { UNDERSCORE, EMPTY } from '../utils/constants.js';
|
|
10
|
+
import { deepFreeze } from '../utils/deep-freeze.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @file Compatibility tables for modifiers.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Transforms the name of the modifier to a normalized form.
|
|
17
|
+
* This is a special case: the noop modifier normally '_', but it can consist of any number of characters,
|
|
18
|
+
* e.g. '____' is also valid. In this case, we need to normalize the name to '_'.
|
|
19
|
+
*
|
|
20
|
+
* @param name Modifier name to normalize.
|
|
21
|
+
* @returns Normalized modifier name.
|
|
22
|
+
*/
|
|
23
|
+
const noopModifierNameNormalizer = (name) => {
|
|
24
|
+
if (name.startsWith(UNDERSCORE)) {
|
|
25
|
+
if (name.split(EMPTY).every((char) => char === UNDERSCORE)) {
|
|
26
|
+
// in compatibility tables, we just store '_', so we need to reduce the number of underscores to 1
|
|
27
|
+
// before checking the existence of the noop modifier
|
|
28
|
+
return UNDERSCORE;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return name;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Compatibility table for modifiers.
|
|
35
|
+
*/
|
|
36
|
+
class ModifiersCompatibilityTable extends CompatibilityTableBase {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new instance of the compatibility table for modifiers.
|
|
39
|
+
*
|
|
40
|
+
* @param data Compatibility table data.
|
|
41
|
+
*/
|
|
42
|
+
constructor(data) {
|
|
43
|
+
super(data, noopModifierNameNormalizer);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Deep freeze the compatibility table data to avoid accidental modifications.
|
|
48
|
+
*/
|
|
49
|
+
deepFreeze(modifiersCompatibilityTableData);
|
|
50
|
+
/**
|
|
51
|
+
* Compatibility table instance for modifiers.
|
|
52
|
+
*/
|
|
53
|
+
const modifiersCompatibilityTable = new ModifiersCompatibilityTable(modifiersCompatibilityTableData);
|
|
54
|
+
|
|
55
|
+
export { modifiersCompatibilityTable };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable no-bitwise */
|
|
8
|
+
/**
|
|
9
|
+
* @file Provides platform enums.
|
|
10
|
+
* The difference between specific and generic platforms is that specific platforms are individual platforms
|
|
11
|
+
* (e.g. AdGuard for Windows, AdGuard for Android, etc.),
|
|
12
|
+
* while generic platforms are groups of specific platforms
|
|
13
|
+
* (e.g. AdGuard for any OS, AdGuard for any Chromium-based extension, etc.).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* List of specific platforms.
|
|
17
|
+
*/
|
|
18
|
+
const SpecificPlatform = {
|
|
19
|
+
AdgOsWindows: 1,
|
|
20
|
+
AdgOsMac: 1 << 1,
|
|
21
|
+
AdgOsAndroid: 1 << 2,
|
|
22
|
+
AdgExtChrome: 1 << 3,
|
|
23
|
+
AdgExtOpera: 1 << 4,
|
|
24
|
+
AdgExtEdge: 1 << 5,
|
|
25
|
+
AdgExtFirefox: 1 << 6,
|
|
26
|
+
AdgCbAndroid: 1 << 7,
|
|
27
|
+
AdgCbIos: 1 << 8,
|
|
28
|
+
AdgCbSafari: 1 << 9,
|
|
29
|
+
UboExtChrome: 1 << 10,
|
|
30
|
+
UboExtOpera: 1 << 11,
|
|
31
|
+
UboExtEdge: 1 << 12,
|
|
32
|
+
UboExtFirefox: 1 << 13,
|
|
33
|
+
AbpExtChrome: 1 << 14,
|
|
34
|
+
AbpExtOpera: 1 << 15,
|
|
35
|
+
AbpExtEdge: 1 << 16,
|
|
36
|
+
AbpExtFirefox: 1 << 17,
|
|
37
|
+
};
|
|
38
|
+
const AdgOsAny = SpecificPlatform.AdgOsWindows
|
|
39
|
+
| SpecificPlatform.AdgOsMac
|
|
40
|
+
| SpecificPlatform.AdgOsAndroid;
|
|
41
|
+
const AdgSafariAny = SpecificPlatform.AdgCbSafari | SpecificPlatform.AdgCbIos;
|
|
42
|
+
const AdgExtChromium = SpecificPlatform.AdgExtChrome
|
|
43
|
+
| SpecificPlatform.AdgExtOpera
|
|
44
|
+
| SpecificPlatform.AdgExtEdge;
|
|
45
|
+
const AdgExtAny = AdgExtChromium | SpecificPlatform.AdgExtFirefox;
|
|
46
|
+
const AdgAny = AdgExtAny | AdgOsAny | AdgSafariAny | SpecificPlatform.AdgCbAndroid;
|
|
47
|
+
const UboExtChromium = SpecificPlatform.UboExtChrome
|
|
48
|
+
| SpecificPlatform.UboExtOpera
|
|
49
|
+
| SpecificPlatform.UboExtEdge;
|
|
50
|
+
const UboExtAny = UboExtChromium | SpecificPlatform.UboExtFirefox;
|
|
51
|
+
const UboAny = UboExtAny;
|
|
52
|
+
const AbpExtChromium = SpecificPlatform.AbpExtChrome
|
|
53
|
+
| SpecificPlatform.AbpExtOpera
|
|
54
|
+
| SpecificPlatform.AbpExtEdge;
|
|
55
|
+
const AbpExtAny = AbpExtChromium | SpecificPlatform.AbpExtFirefox;
|
|
56
|
+
const AbpAny = AbpExtAny;
|
|
57
|
+
const Any = AdgAny | UboAny | AbpAny;
|
|
58
|
+
/**
|
|
59
|
+
* List of generic platforms (combinations of specific platforms).
|
|
60
|
+
*/
|
|
61
|
+
const GenericPlatform = {
|
|
62
|
+
AdgOsAny,
|
|
63
|
+
AdgSafariAny,
|
|
64
|
+
AdgExtChromium,
|
|
65
|
+
AdgExtAny,
|
|
66
|
+
AdgAny,
|
|
67
|
+
UboExtChromium,
|
|
68
|
+
UboExtAny,
|
|
69
|
+
UboAny,
|
|
70
|
+
AbpExtChromium,
|
|
71
|
+
AbpExtAny,
|
|
72
|
+
AbpAny,
|
|
73
|
+
Any,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { GenericPlatform, SpecificPlatform };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { CompatibilityTableBase } from './base.js';
|
|
8
|
+
import { redirectsCompatibilityTableData } from './compatibility-table-data.js';
|
|
9
|
+
import { deepFreeze } from '../utils/deep-freeze.js';
|
|
10
|
+
import { COLON } from '../utils/constants.js';
|
|
11
|
+
import { getResourceTypeModifier } from './utils/resource-type-helpers.js';
|
|
12
|
+
import { isString, isNull, isUndefined } from '../utils/type-guards.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @file Compatibility tables for redirects.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Prefix for resource redirection names.
|
|
19
|
+
*/
|
|
20
|
+
const ABP_RESOURCE_PREFIX = 'abp-resource:';
|
|
21
|
+
const ABP_RESOURCE_PREFIX_LENGTH = ABP_RESOURCE_PREFIX.length;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes the redirect name.
|
|
24
|
+
*
|
|
25
|
+
* @param name Redirect name to normalize.
|
|
26
|
+
*
|
|
27
|
+
* @returns Normalized redirect name.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* redirectNameNormalizer('abp-resource:my-resource') // => 'my-resource'
|
|
31
|
+
* redirectNameNormalizer('noop.js:99') // => 'noop.js'
|
|
32
|
+
*/
|
|
33
|
+
const redirectNameNormalizer = (name) => {
|
|
34
|
+
// Remove ABP resource prefix, if present
|
|
35
|
+
if (name.startsWith(ABP_RESOURCE_PREFIX)) {
|
|
36
|
+
return name.slice(ABP_RESOURCE_PREFIX_LENGTH);
|
|
37
|
+
}
|
|
38
|
+
// Remove :[integer] priority suffix from the name, if present
|
|
39
|
+
// See:
|
|
40
|
+
// - https://github.com/AdguardTeam/tsurlfilter/issues/59
|
|
41
|
+
// - https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#redirect
|
|
42
|
+
const colonIndex = name.lastIndexOf(COLON);
|
|
43
|
+
if (colonIndex !== -1 && /^\d+$/.test(name.slice(colonIndex + 1))) {
|
|
44
|
+
return name.slice(0, colonIndex);
|
|
45
|
+
}
|
|
46
|
+
return name;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Compatibility table for redirects.
|
|
50
|
+
*/
|
|
51
|
+
class RedirectsCompatibilityTable extends CompatibilityTableBase {
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new instance of the compatibility table for redirects.
|
|
54
|
+
*
|
|
55
|
+
* @param data Compatibility table data.
|
|
56
|
+
*/
|
|
57
|
+
constructor(data) {
|
|
58
|
+
super(data, redirectNameNormalizer);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the resource type adblock modifiers for the redirect for the given platform
|
|
62
|
+
* based on the `resourceTypes` field.
|
|
63
|
+
*
|
|
64
|
+
* @param redirect Redirect name or redirect data.
|
|
65
|
+
* @param platform Platform to get the modifiers for.
|
|
66
|
+
*
|
|
67
|
+
* @returns Set of resource type modifiers or an empty set if the redirect is not found or has no resource types.
|
|
68
|
+
*/
|
|
69
|
+
getResourceTypeModifiers(redirect, platform) {
|
|
70
|
+
let redirectData = null;
|
|
71
|
+
if (isString(redirect)) {
|
|
72
|
+
redirectData = this.getFirst(redirect, platform);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
redirectData = redirect;
|
|
76
|
+
}
|
|
77
|
+
const modifierNames = new Set();
|
|
78
|
+
if (isNull(redirectData) || isUndefined(redirectData.resourceTypes)) {
|
|
79
|
+
return modifierNames;
|
|
80
|
+
}
|
|
81
|
+
for (const resourceType of redirectData.resourceTypes) {
|
|
82
|
+
const modifierName = getResourceTypeModifier(resourceType, platform);
|
|
83
|
+
if (isNull(modifierName)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
modifierNames.add(modifierName);
|
|
87
|
+
}
|
|
88
|
+
return modifierNames;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Deep freeze the compatibility table data to avoid accidental modifications.
|
|
93
|
+
*/
|
|
94
|
+
deepFreeze(redirectsCompatibilityTableData);
|
|
95
|
+
/**
|
|
96
|
+
* Compatibility table instance for redirects.
|
|
97
|
+
*/
|
|
98
|
+
const redirectsCompatibilityTable = new RedirectsCompatibilityTable(redirectsCompatibilityTableData);
|
|
99
|
+
|
|
100
|
+
export { redirectsCompatibilityTable };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
import './platform.js';
|
|
9
|
+
import { zodToCamelCase } from '../utils/zod-camelcase.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file Base compatibility data schema, which is commonly used in compatibility tables.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Zod schema for boolean values. Accepts both boolean and string values.
|
|
16
|
+
*/
|
|
17
|
+
const booleanSchema = zod.union([
|
|
18
|
+
zod.string().transform((val) => val.trim().toLowerCase() === 'true'),
|
|
19
|
+
zod.boolean(),
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
22
|
+
* Zod schema for non-empty string values.
|
|
23
|
+
*/
|
|
24
|
+
const nonEmptyStringSchema = zod
|
|
25
|
+
.string()
|
|
26
|
+
.transform((val) => val.trim())
|
|
27
|
+
.pipe(zod.string().min(1));
|
|
28
|
+
/**
|
|
29
|
+
* Zod schema for base compatibility data.
|
|
30
|
+
* Here we use snake_case properties because the compatibility data is stored in YAML files.
|
|
31
|
+
*/
|
|
32
|
+
const baseCompatibilityDataSchema = zod.object({
|
|
33
|
+
/**
|
|
34
|
+
* Name of the actual entity.
|
|
35
|
+
*/
|
|
36
|
+
name: nonEmptyStringSchema,
|
|
37
|
+
/**
|
|
38
|
+
* List of aliases for the entity (if any).
|
|
39
|
+
*/
|
|
40
|
+
aliases: zod.array(nonEmptyStringSchema).nullable().default(null),
|
|
41
|
+
/**
|
|
42
|
+
* Short description of the actual entity.
|
|
43
|
+
* If not specified or it's value is `null`, then the description is not available.
|
|
44
|
+
*/
|
|
45
|
+
description: nonEmptyStringSchema.nullable().default(null),
|
|
46
|
+
/**
|
|
47
|
+
* Link to the documentation. If not specified or it's value is `null`, then the documentation is not available.
|
|
48
|
+
*/
|
|
49
|
+
docs: nonEmptyStringSchema.nullable().default(null),
|
|
50
|
+
/**
|
|
51
|
+
* The version of the adblocker in which the entity was added.
|
|
52
|
+
* For AdGuard resources, the version of the library is specified.
|
|
53
|
+
*/
|
|
54
|
+
version_added: nonEmptyStringSchema.nullable().default(null),
|
|
55
|
+
/**
|
|
56
|
+
* The version of the adblocker when the entity was removed.
|
|
57
|
+
*/
|
|
58
|
+
version_removed: nonEmptyStringSchema.nullable().default(null),
|
|
59
|
+
/**
|
|
60
|
+
* Describes whether the entity is deprecated.
|
|
61
|
+
*/
|
|
62
|
+
deprecated: booleanSchema.default(false),
|
|
63
|
+
/**
|
|
64
|
+
* Message that describes why the entity is deprecated.
|
|
65
|
+
* If not specified or it's value is `null`, then the message is not available.
|
|
66
|
+
* It's value is omitted if the entity is not marked as deprecated.
|
|
67
|
+
*/
|
|
68
|
+
deprecation_message: nonEmptyStringSchema.nullable().default(null),
|
|
69
|
+
/**
|
|
70
|
+
* Describes whether the entity is removed; for *already removed* features.
|
|
71
|
+
*/
|
|
72
|
+
removed: booleanSchema.default(false),
|
|
73
|
+
/**
|
|
74
|
+
* Message that describes why the entity is removed.
|
|
75
|
+
* If not specified or it's value is `null`, then the message is not available.
|
|
76
|
+
* It's value is omitted if the entity is not marked as deprecated.
|
|
77
|
+
*/
|
|
78
|
+
removal_message: nonEmptyStringSchema.nullable().default(null),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Zod schema for base compatibility data with camelCase properties.
|
|
82
|
+
*/
|
|
83
|
+
zodToCamelCase(baseCompatibilityDataSchema);
|
|
84
|
+
/**
|
|
85
|
+
* Refinement logic for base compatibility data.
|
|
86
|
+
*
|
|
87
|
+
* @param data Base compatibility data.
|
|
88
|
+
* @param ctx Refinement context.
|
|
89
|
+
*/
|
|
90
|
+
const baseRefineLogic = (data, ctx) => {
|
|
91
|
+
if (data.deprecated && !data.deprecation_message) {
|
|
92
|
+
ctx.addIssue({
|
|
93
|
+
code: zod.ZodIssueCode.custom,
|
|
94
|
+
message: 'deprecation_message is required for deprecated modifiers',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!data.deprecated && data.deprecation_message) {
|
|
98
|
+
ctx.addIssue({
|
|
99
|
+
code: zod.ZodIssueCode.custom,
|
|
100
|
+
message: 'deprecation_message is only allowed for deprecated modifiers',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (data.aliases && data.aliases.length !== new Set(data.aliases).size) {
|
|
104
|
+
ctx.addIssue({
|
|
105
|
+
code: zod.ZodIssueCode.custom,
|
|
106
|
+
message: 'Aliases must be unique',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { baseCompatibilityDataSchema, baseRefineLogic, booleanSchema, nonEmptyStringSchema };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
import { zodToCamelCase } from '../utils/zod-camelcase.js';
|
|
9
|
+
import { baseCompatibilityDataSchema, nonEmptyStringSchema, booleanSchema, baseRefineLogic } from './base.js';
|
|
10
|
+
import { getErrorMessage } from '../../utils/error.js';
|
|
11
|
+
import { EMPTY } from '../../utils/constants.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @file Schema for modifier data.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Known validators that don't need to be validated as regex.
|
|
18
|
+
*/
|
|
19
|
+
const KNOWN_VALIDATORS = new Set([
|
|
20
|
+
'csp_value',
|
|
21
|
+
'domain',
|
|
22
|
+
'permissions_value',
|
|
23
|
+
'pipe_separated_apps',
|
|
24
|
+
'pipe_separated_denyallow_domains',
|
|
25
|
+
'pipe_separated_domains',
|
|
26
|
+
'pipe_separated_methods',
|
|
27
|
+
'pipe_separated_stealth_options',
|
|
28
|
+
'regexp',
|
|
29
|
+
'url',
|
|
30
|
+
]);
|
|
31
|
+
/**
|
|
32
|
+
* Zod schema for modifier data.
|
|
33
|
+
*/
|
|
34
|
+
zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
35
|
+
/**
|
|
36
|
+
* List of modifiers that are incompatible with the actual one.
|
|
37
|
+
*/
|
|
38
|
+
conflicts: zod.array(nonEmptyStringSchema).nullable().default(null),
|
|
39
|
+
/**
|
|
40
|
+
* The actual modifier is incompatible with all other modifiers, except the ones listed in `conflicts`.
|
|
41
|
+
*/
|
|
42
|
+
inverse_conflicts: booleanSchema.default(false),
|
|
43
|
+
/**
|
|
44
|
+
* Describes whether the actual modifier supports value assignment. For example, `$domain` is assignable,
|
|
45
|
+
* so it can be used like this: `$domain=domain.com\|~subdomain.domain.com`, where `=` is the assignment operator
|
|
46
|
+
* and `domain.com\|~subdomain.domain.com` is the value.
|
|
47
|
+
*/
|
|
48
|
+
assignable: booleanSchema.default(false),
|
|
49
|
+
/**
|
|
50
|
+
* Describes whether the actual modifier can be negated. For example, `$third-party` is negatable,
|
|
51
|
+
* so it can be used like this: `$~third-party`.
|
|
52
|
+
*/
|
|
53
|
+
negatable: booleanSchema.default(true),
|
|
54
|
+
/**
|
|
55
|
+
* The actual modifier can only be used in blocking rules, it cannot be used in exceptions.
|
|
56
|
+
* If it's value is `true`, then the modifier can be used only in blocking rules.
|
|
57
|
+
* `exception_only` and `block_only` cannot be used together (they are mutually exclusive).
|
|
58
|
+
*/
|
|
59
|
+
block_only: booleanSchema.default(false),
|
|
60
|
+
/**
|
|
61
|
+
* The actual modifier can only be used in exceptions, it cannot be used in blocking rules.
|
|
62
|
+
* If it's value is `true`, then the modifier can be used only in exceptions.
|
|
63
|
+
* `exception_only` and `block_only` cannot be used together (they are mutually exclusive).
|
|
64
|
+
*/
|
|
65
|
+
exception_only: booleanSchema.default(false),
|
|
66
|
+
/**
|
|
67
|
+
* Describes whether the *assignable* modifier value is required.
|
|
68
|
+
* For example, `$cookie` is assignable but it can be used without a value in exception rules:
|
|
69
|
+
* `@@\|\|example.com^$cookie`.
|
|
70
|
+
* If `false`, the `value_format` is required, e.g. the value of `$app` should always be specified
|
|
71
|
+
*/
|
|
72
|
+
value_optional: booleanSchema.default(false),
|
|
73
|
+
/**
|
|
74
|
+
* Describes the format of the value for the *assignable* modifier.
|
|
75
|
+
* Its value can be a regex pattern or a known validator name (e.g. `domain`, `pipe_separated_domains`, etc.).
|
|
76
|
+
*/
|
|
77
|
+
value_format: nonEmptyStringSchema.nullable().default(null),
|
|
78
|
+
/**
|
|
79
|
+
* Describes the flags for the `value_format` regex pattern.
|
|
80
|
+
*/
|
|
81
|
+
value_format_flags: nonEmptyStringSchema.nullable().default(null),
|
|
82
|
+
}).superRefine((data, ctx) => {
|
|
83
|
+
// TODO: find something better, for now we can't add refine logic to the base schema:
|
|
84
|
+
// https://github.com/colinhacks/zod/issues/454#issuecomment-848370721
|
|
85
|
+
baseRefineLogic(data, ctx);
|
|
86
|
+
if (data.block_only && data.exception_only) {
|
|
87
|
+
ctx.addIssue({
|
|
88
|
+
code: zod.ZodIssueCode.custom,
|
|
89
|
+
message: 'block_only and exception_only are mutually exclusive',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (data.assignable && !data.value_format) {
|
|
93
|
+
ctx.addIssue({
|
|
94
|
+
code: zod.ZodIssueCode.custom,
|
|
95
|
+
message: 'value_format is required for assignable modifiers',
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (data.value_format) {
|
|
99
|
+
const valueFormat = data.value_format.trim();
|
|
100
|
+
// if it is a known validator, we don't need to validate it further
|
|
101
|
+
if (KNOWN_VALIDATORS.has(valueFormat)) {
|
|
102
|
+
if (data.value_format_flags) {
|
|
103
|
+
ctx.addIssue({
|
|
104
|
+
code: zod.ZodIssueCode.custom,
|
|
105
|
+
message: 'value_format_flags are not allowed for known validators',
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// otherwise, we need to validate it as a regex
|
|
111
|
+
try {
|
|
112
|
+
new RegExp(valueFormat, data.value_format_flags ?? EMPTY);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
ctx.addIssue({
|
|
116
|
+
code: zod.ZodIssueCode.custom,
|
|
117
|
+
message: getErrorMessage(error),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else if (data.value_format_flags) {
|
|
122
|
+
ctx.addIssue({
|
|
123
|
+
code: zod.ZodIssueCode.custom,
|
|
124
|
+
message: 'value_format is required for value_format_flags',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
export { KNOWN_VALIDATORS };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
import { SPECIFIC_PLATFORM_MAP, GENERIC_PLATFORM_MAP } from '../utils/platform-helpers.js';
|
|
9
|
+
import { isUndefined } from '../../utils/type-guards.js';
|
|
10
|
+
|
|
11
|
+
/* eslint-disable no-bitwise */
|
|
12
|
+
/**
|
|
13
|
+
* @file Platform schema.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Platform separator, e.g. 'adg_os_any|adg_safari_any' means any AdGuard OS platform and
|
|
17
|
+
* any AdGuard Safari content blocker platform.
|
|
18
|
+
*/
|
|
19
|
+
const PLATFORM_SEPARATOR = '|';
|
|
20
|
+
/**
|
|
21
|
+
* Platform negation character, e.g. 'adg_any|~adg_safari_any' means any AdGuard product except
|
|
22
|
+
* Safari content blockers.
|
|
23
|
+
*/
|
|
24
|
+
const PLATFORM_NEGATION = '~';
|
|
25
|
+
/**
|
|
26
|
+
* Parses a raw platform string into a platform bitmask.
|
|
27
|
+
*
|
|
28
|
+
* @param rawPlatforms Raw platform string, e.g. 'adg_safari_any|adg_os_any'.
|
|
29
|
+
*
|
|
30
|
+
* @returns Platform bitmask.
|
|
31
|
+
*/
|
|
32
|
+
const parseRawPlatforms = (rawPlatforms) => {
|
|
33
|
+
// e.g. 'adg_safari_any|adg_os_any'
|
|
34
|
+
const rawPlatformList = rawPlatforms
|
|
35
|
+
.split(PLATFORM_SEPARATOR)
|
|
36
|
+
.map((rawPlatform) => rawPlatform.trim());
|
|
37
|
+
let result = 0;
|
|
38
|
+
for (let rawPlatform of rawPlatformList) {
|
|
39
|
+
// negation, e.g. 'adg_any|~adg_safari_any' means any AdGuard product except Safari content blockers
|
|
40
|
+
let negated = false;
|
|
41
|
+
if (rawPlatform.startsWith(PLATFORM_NEGATION)) {
|
|
42
|
+
negated = true;
|
|
43
|
+
rawPlatform = rawPlatform.slice(1).trim();
|
|
44
|
+
}
|
|
45
|
+
const platform = SPECIFIC_PLATFORM_MAP.get(rawPlatform) ?? GENERIC_PLATFORM_MAP.get(rawPlatform);
|
|
46
|
+
if (isUndefined(platform)) {
|
|
47
|
+
throw new Error(`Unknown platform: ${rawPlatform}`);
|
|
48
|
+
}
|
|
49
|
+
if (negated) {
|
|
50
|
+
result &= ~platform;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
result |= platform;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (result === 0) {
|
|
57
|
+
throw new Error('No platforms specified');
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Platform schema.
|
|
63
|
+
*/
|
|
64
|
+
zod
|
|
65
|
+
.string()
|
|
66
|
+
.min(1)
|
|
67
|
+
.transform((value) => parseRawPlatforms(value));
|
|
68
|
+
|
|
69
|
+
export { parseRawPlatforms };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
import { zodToCamelCase } from '../utils/zod-camelcase.js';
|
|
9
|
+
import { baseCompatibilityDataSchema, booleanSchema, baseRefineLogic } from './base.js';
|
|
10
|
+
import { resourceTypeSchema } from './resource-type.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @file Schema for redirect data.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Zod schema for redirect data.
|
|
17
|
+
*/
|
|
18
|
+
zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
19
|
+
/**
|
|
20
|
+
* Whether the redirect is blocking.
|
|
21
|
+
*/
|
|
22
|
+
is_blocking: booleanSchema.default(false),
|
|
23
|
+
/**
|
|
24
|
+
* Resource type(s) belonging to the redirect.
|
|
25
|
+
*
|
|
26
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-ResourceType}
|
|
27
|
+
*/
|
|
28
|
+
resource_types: zod.array(resourceTypeSchema).default([]),
|
|
29
|
+
}).superRefine(baseRefineLogic));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file Resource type schema.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Resource type.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-ResourceType}
|
|
16
|
+
*/
|
|
17
|
+
const ResourceType = {
|
|
18
|
+
MainFrame: 'main_frame',
|
|
19
|
+
SubFrame: 'sub_frame',
|
|
20
|
+
Stylesheet: 'stylesheet',
|
|
21
|
+
Script: 'script',
|
|
22
|
+
Image: 'image',
|
|
23
|
+
Font: 'font',
|
|
24
|
+
Object: 'object',
|
|
25
|
+
XmlHttpRequest: 'xmlhttprequest',
|
|
26
|
+
Ping: 'ping',
|
|
27
|
+
Media: 'media',
|
|
28
|
+
WebSocket: 'websocket',
|
|
29
|
+
Other: 'other',
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Resource type schema.
|
|
33
|
+
*/
|
|
34
|
+
const resourceTypeSchema = zod.nativeEnum(ResourceType);
|
|
35
|
+
|
|
36
|
+
export { ResourceType, resourceTypeSchema };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import zod from 'zod';
|
|
8
|
+
import { zodToCamelCase } from '../utils/zod-camelcase.js';
|
|
9
|
+
import { nonEmptyStringSchema, booleanSchema, baseCompatibilityDataSchema, baseRefineLogic } from './base.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @file Schema for scriptlet data.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Zod schema for scriptlet parameter data.
|
|
16
|
+
*/
|
|
17
|
+
const scriptletParameterSchema = zod.object({
|
|
18
|
+
/**
|
|
19
|
+
* Name of the actual parameter.
|
|
20
|
+
*/
|
|
21
|
+
name: nonEmptyStringSchema,
|
|
22
|
+
/**
|
|
23
|
+
* Describes whether the parameter is required. Empty parameters are not allowed.
|
|
24
|
+
*/
|
|
25
|
+
required: booleanSchema,
|
|
26
|
+
/**
|
|
27
|
+
* Short description of the parameter.
|
|
28
|
+
* If not specified or it's value is `null`,then the description is not available.
|
|
29
|
+
*/
|
|
30
|
+
description: nonEmptyStringSchema.nullable().default(null),
|
|
31
|
+
/**
|
|
32
|
+
* Regular expression that matches the value of the parameter.
|
|
33
|
+
* If it's value is `null`, then the parameter value is not checked.
|
|
34
|
+
*/
|
|
35
|
+
pattern: nonEmptyStringSchema.nullable().default(null),
|
|
36
|
+
/**
|
|
37
|
+
* Default value of the parameter (if any).
|
|
38
|
+
*/
|
|
39
|
+
default: nonEmptyStringSchema.nullable().default(null),
|
|
40
|
+
/**
|
|
41
|
+
* Describes whether the parameter is used only for debugging purposes.
|
|
42
|
+
*/
|
|
43
|
+
debug: booleanSchema.default(false),
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Zod schema for scriptlet parameters.
|
|
47
|
+
*/
|
|
48
|
+
const scriptletParametersSchema = zod.array(scriptletParameterSchema);
|
|
49
|
+
/**
|
|
50
|
+
* Zod schema for scriptlet data.
|
|
51
|
+
*/
|
|
52
|
+
zodToCamelCase(baseCompatibilityDataSchema.extend({
|
|
53
|
+
/**
|
|
54
|
+
* List of parameters that the scriptlet accepts.
|
|
55
|
+
* **Every** parameter should be listed here, because we check that the scriptlet is used correctly
|
|
56
|
+
* (e.g. that the number of parameters is correct).
|
|
57
|
+
*/
|
|
58
|
+
parameters: scriptletParametersSchema.optional(),
|
|
59
|
+
}).superRefine((data, ctx) => {
|
|
60
|
+
// TODO: find something better, for now we can't add refine logic to the base schema:
|
|
61
|
+
// https://github.com/colinhacks/zod/issues/454#issuecomment-848370721
|
|
62
|
+
baseRefineLogic(data, ctx);
|
|
63
|
+
// we don't allow required parameters after optional ones
|
|
64
|
+
if (!data.parameters) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
let optionalFound = false;
|
|
68
|
+
for (const parameter of data.parameters) {
|
|
69
|
+
if (optionalFound && parameter.required) {
|
|
70
|
+
ctx.addIssue({
|
|
71
|
+
code: zod.ZodIssueCode.custom,
|
|
72
|
+
message: 'Required parameters must be before optional ones',
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (!parameter.required) {
|
|
76
|
+
optionalFound = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}));
|