@adguard/dnr-converter 1.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 +476 -0
- package/dist/cli.cjs +58912 -0
- package/dist/constants.js +23 -0
- package/dist/declarative-rule/declarative-rule.js +15 -0
- package/dist/declarative-rule/header-info.js +12 -0
- package/dist/declarative-rule/modify-header-info.js +31 -0
- package/dist/declarative-rule/query-key-value.js +12 -0
- package/dist/declarative-rule/query-transform.js +12 -0
- package/dist/declarative-rule/redirect.js +14 -0
- package/dist/declarative-rule/rule-action.js +44 -0
- package/dist/declarative-rule/rule-condition.js +77 -0
- package/dist/declarative-rule/url-transform.js +30 -0
- package/dist/errors/conversion-errors/empty-domains-error.js +24 -0
- package/dist/errors/conversion-errors/empty-resources-error.js +24 -0
- package/dist/errors/conversion-errors/index.js +17 -0
- package/dist/errors/conversion-errors/invalid-declarative-rule-error.js +22 -0
- package/dist/errors/conversion-errors/unsupported-modifier-error.js +20 -0
- package/dist/errors/conversion-errors/unsupported-regexp-error.js +27 -0
- package/dist/errors/converter-options-errors/empty-or-negative-number-of-rules-error.js +18 -0
- package/dist/errors/converter-options-errors/index.js +15 -0
- package/dist/errors/converter-options-errors/negative-number-of-rules-error.js +18 -0
- package/dist/errors/converter-options-errors/resources-path-error.js +18 -0
- package/dist/errors/limitation-errors/index.js +17 -0
- package/dist/errors/limitation-errors/max-scanned-rules-error.js +20 -0
- package/dist/errors/limitation-errors/too-many-error.js +28 -0
- package/dist/errors/limitation-errors/too-many-regexp-rules-error.js +25 -0
- package/dist/errors/limitation-errors/too-many-rules-error.js +25 -0
- package/dist/errors/limitation-errors/too-many-unsafe-rules-error.js +25 -0
- package/dist/errors/unavailable-sources-errors/unavailable-filter-source-error.js +21 -0
- package/dist/errors/unavailable-sources-errors/unavailable-ruleset-source-error.js +21 -0
- package/dist/filter/filter.js +92 -0
- package/dist/filter-converter/filter-converter.js +385 -0
- package/dist/grouped-rules-converters/url-transform-converter.js +340 -0
- package/dist/index.js +30 -0
- package/dist/package.json.js +3 -0
- package/dist/re2-regexp/re2-validator.js +37 -0
- package/dist/re2-regexp/regex-validator-extension.js +30 -0
- package/dist/re2.wasm +0 -0
- package/dist/rule/option-names.js +65 -0
- package/dist/rule/rule-badfilter.js +81 -0
- package/dist/rule/rule-priority.js +88 -0
- package/dist/rule/rule-validator.js +455 -0
- package/dist/rule/rule.js +853 -0
- package/dist/rule/string-utils.js +49 -0
- package/dist/rule-converters/csp-converter.js +105 -0
- package/dist/rule-converters/regular-rule-converter.js +789 -0
- package/dist/rule-converters/remove-header-converter.js +97 -0
- package/dist/rule-converters/rules-converter.js +365 -0
- package/dist/rule-converters/rules-grouper.js +75 -0
- package/dist/rules-scanner/rules-scanner.js +136 -0
- package/dist/ruleset/metadata-rule.js +35 -0
- package/dist/ruleset/metadata-ruleset.js +162 -0
- package/dist/ruleset/rules-hash-map.js +71 -0
- package/dist/ruleset/ruleset-with-source-map.js +406 -0
- package/dist/ruleset/ruleset.js +54 -0
- package/dist/ruleset/source-map.js +283 -0
- package/dist/types/cli/convert-filters.d.ts +32 -0
- package/dist/types/cli/index.d.ts +7 -0
- package/dist/types/cli/utils.d.ts +19 -0
- package/dist/types/src/declarative-rule/declarative-rule.d.ts +32 -0
- package/dist/types/src/declarative-rule/header-info.d.ts +31 -0
- package/dist/types/src/declarative-rule/modify-header-info.d.ts +46 -0
- package/dist/types/src/declarative-rule/query-key-value.d.ts +24 -0
- package/dist/types/src/declarative-rule/query-transform.d.ts +21 -0
- package/dist/types/src/declarative-rule/redirect.d.ts +32 -0
- package/dist/types/src/declarative-rule/rule-action.d.ts +68 -0
- package/dist/types/src/declarative-rule/rule-condition.d.ts +262 -0
- package/dist/types/src/declarative-rule/url-transform.d.ts +69 -0
- package/dist/types/src/errors/conversion-errors/empty-domains-error.d.ts +21 -0
- package/dist/types/src/errors/conversion-errors/empty-resources-error.d.ts +21 -0
- package/dist/types/src/errors/conversion-errors/index.d.ts +27 -0
- package/dist/types/src/errors/conversion-errors/invalid-declarative-rule-error.d.ts +30 -0
- package/dist/types/src/errors/conversion-errors/unsupported-modifier-error.d.ts +20 -0
- package/dist/types/src/errors/conversion-errors/unsupported-regexp-error.d.ts +23 -0
- package/dist/types/src/errors/converter-options-errors/empty-or-negative-number-of-rules-error.d.ts +13 -0
- package/dist/types/src/errors/converter-options-errors/index.d.ts +23 -0
- package/dist/types/src/errors/converter-options-errors/negative-number-of-rules-error.d.ts +13 -0
- package/dist/types/src/errors/converter-options-errors/resources-path-error.d.ts +13 -0
- package/dist/types/src/errors/limitation-errors/index.d.ts +27 -0
- package/dist/types/src/errors/limitation-errors/max-scanned-rules-error.d.ts +18 -0
- package/dist/types/src/errors/limitation-errors/too-many-error.d.ts +33 -0
- package/dist/types/src/errors/limitation-errors/too-many-regexp-rules-error.d.ts +21 -0
- package/dist/types/src/errors/limitation-errors/too-many-rules-error.d.ts +21 -0
- package/dist/types/src/errors/limitation-errors/too-many-unsafe-rules-error.d.ts +21 -0
- package/dist/types/src/errors/unavailable-sources-errors/unavailable-filter-source-error.d.ts +19 -0
- package/dist/types/src/errors/unavailable-sources-errors/unavailable-ruleset-source-error.d.ts +19 -0
- package/dist/types/src/filter/filter.d.ts +74 -0
- package/dist/types/src/filter/types.d.ts +45 -0
- package/dist/types/src/filter-converter/conversion-result.d.ts +35 -0
- package/dist/types/src/filter-converter/filter-converter-options.d.ts +81 -0
- package/dist/types/src/filter-converter/filter-converter.d.ts +197 -0
- package/dist/types/src/index.d.ts +37 -0
- package/dist/types/src/rule/rule-types.d.ts +33 -0
- package/dist/types/src/rule/rule-validator.d.ts +185 -0
- package/dist/types/src/rule/rule.d.ts +269 -0
- package/dist/types/src/ruleset/metadata-ruleset.d.ts +128 -0
- package/dist/types/src/ruleset/rules-hash-map.d.ts +70 -0
- package/dist/types/src/ruleset/ruleset-with-source-map.d.ts +318 -0
- package/dist/types/src/ruleset/ruleset.d.ts +86 -0
- package/dist/types/src/ruleset/source-map.d.ts +45 -0
- package/dist/types/src/ruleset/types.d.ts +68 -0
- package/dist/types/src/utils/is-safe-rule.d.ts +20 -0
- package/dist/types/src/utils/ruleset-utils.d.ts +45 -0
- package/dist/types/src/version.d.ts +6 -0
- package/dist/url-transform-converter.js +338 -0
- package/dist/utils/error.js +22 -0
- package/dist/utils/is-safe-rule.js +25 -0
- package/dist/utils/lazy-loader.js +116 -0
- package/dist/utils/lazy.js +50 -0
- package/dist/utils/ruleset-utils.js +76 -0
- package/dist/utils/string.js +180 -0
- package/dist/utils/valibot.js +74 -0
- package/dist/version.js +7 -0
- package/package.json +122 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name of the Content-Security-Policy header.
|
|
3
|
+
*/ const CSP_HEADER_NAME = 'Content-Security-Policy';
|
|
4
|
+
/**
|
|
5
|
+
* Name of the Permissions-Policy header.
|
|
6
|
+
*/ const PERMISSIONS_POLICY_HEADER_NAME = 'Permissions-Policy';
|
|
7
|
+
/**
|
|
8
|
+
* Enclose regex in two backslashes to mark a regex rule.
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#regular-expressions-support}
|
|
11
|
+
*/ const MASK_REGEX_RULE = '/';
|
|
12
|
+
/**
|
|
13
|
+
* Negation character used in modifier values (e.g. `$removeparam=~param`).
|
|
14
|
+
*/ const MASK_NEGATE_CHARACTER = '~';
|
|
15
|
+
/**
|
|
16
|
+
* This is a wildcard character. It is used to represent "any set of characters".
|
|
17
|
+
* This can also be an empty string or a string of any length.
|
|
18
|
+
*/ const MASK_ANY_CHARACTER = '*';
|
|
19
|
+
/**
|
|
20
|
+
* Space character.
|
|
21
|
+
*/ const SPACE_CHARACTER = ' ';
|
|
22
|
+
|
|
23
|
+
export { CSP_HEADER_NAME, MASK_ANY_CHARACTER, MASK_NEGATE_CHARACTER, MASK_REGEX_RULE, PERMISSIONS_POLICY_HEADER_NAME, SPACE_CHARACTER };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { RuleActionValidator } from './rule-action.js';
|
|
4
|
+
import { RuleConditionValidator } from './rule-condition.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validator for {@link DeclarativeRule}.
|
|
8
|
+
*/ const DeclarativeRuleValidator = strictObjectByType({
|
|
9
|
+
action: RuleActionValidator,
|
|
10
|
+
condition: RuleConditionValidator,
|
|
11
|
+
id: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
12
|
+
priority: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1)))
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export { DeclarativeRuleValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Validator for {@link HeaderInfo}.
|
|
6
|
+
*/ const HeaderInfoValidator = strictObjectByType({
|
|
7
|
+
values: v.optional(v.array(v.string())),
|
|
8
|
+
excludedValues: v.optional(v.array(v.string())),
|
|
9
|
+
header: v.string()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { HeaderInfoValidator };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Enum that represents the possible operations for a header modification.
|
|
6
|
+
*
|
|
7
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-HeaderOperation}
|
|
8
|
+
*
|
|
9
|
+
* @since Chrome 86
|
|
10
|
+
*/ var HeaderOperation = /*#__PURE__*/ function(HeaderOperation) {
|
|
11
|
+
/**
|
|
12
|
+
* Adds a new entry for the specified header.
|
|
13
|
+
* This operation is not supported for request headers.
|
|
14
|
+
*/ HeaderOperation["Append"] = "append";
|
|
15
|
+
/**
|
|
16
|
+
* Sets a new value for the specified header, removing any existing headers with the same name.
|
|
17
|
+
*/ HeaderOperation["Set"] = "set";
|
|
18
|
+
/**
|
|
19
|
+
* Removes all entries for the specified header.
|
|
20
|
+
*/ HeaderOperation["Remove"] = "remove";
|
|
21
|
+
return HeaderOperation;
|
|
22
|
+
}({});
|
|
23
|
+
/**
|
|
24
|
+
* Validator for {@link ModifyHeaderInfo}.
|
|
25
|
+
*/ const ModifyHeaderInfoValidator = strictObjectByType({
|
|
26
|
+
header: v.string(),
|
|
27
|
+
operation: v.enum(HeaderOperation),
|
|
28
|
+
value: v.optional(v.string())
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export { HeaderOperation, ModifyHeaderInfoValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Validator for {@link QueryKeyValue}.
|
|
6
|
+
*/ const QueryKeyValueValidator = strictObjectByType({
|
|
7
|
+
key: v.string(),
|
|
8
|
+
replaceOnly: v.optional(v.boolean()),
|
|
9
|
+
value: v.string()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { QueryKeyValueValidator };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { QueryKeyValueValidator } from './query-key-value.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Validator for {@link QueryTransform}.
|
|
7
|
+
*/ const QueryTransformValidator = strictObjectByType({
|
|
8
|
+
addOrReplaceParams: v.optional(v.array(QueryKeyValueValidator)),
|
|
9
|
+
removeParams: v.optional(v.array(v.string()))
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { QueryTransformValidator };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { URLTransformValidator } from './url-transform.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Validator for {@link Redirect}.
|
|
7
|
+
*/ const RedirectValidator = strictObjectByType({
|
|
8
|
+
extensionPath: v.optional(v.string()),
|
|
9
|
+
regexSubstitution: v.optional(v.string()),
|
|
10
|
+
transform: v.optional(URLTransformValidator),
|
|
11
|
+
url: v.optional(v.string())
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { RedirectValidator };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { ModifyHeaderInfoValidator } from './modify-header-info.js';
|
|
4
|
+
import { RedirectValidator } from './redirect.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Enum that represents the kind of action to take if a given condition matches.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleActionType}
|
|
10
|
+
*/ var RuleActionType = /*#__PURE__*/ function(RuleActionType) {
|
|
11
|
+
/**
|
|
12
|
+
* Block the network request.
|
|
13
|
+
*/ RuleActionType["Block"] = "block";
|
|
14
|
+
/**
|
|
15
|
+
* Redirect the network request.
|
|
16
|
+
*/ RuleActionType["Redirect"] = "redirect";
|
|
17
|
+
/**
|
|
18
|
+
* Allow the network request.
|
|
19
|
+
*
|
|
20
|
+
* The request won't be intercepted if there is an allow rule which matches it.
|
|
21
|
+
*/ RuleActionType["Allow"] = "allow";
|
|
22
|
+
/**
|
|
23
|
+
* Upgrade the network request url's scheme to `https` if the request is `http` or `ftp`.
|
|
24
|
+
*/ RuleActionType["UpgradeScheme"] = "upgradeScheme";
|
|
25
|
+
/**
|
|
26
|
+
* Modify request/response headers from the network request.
|
|
27
|
+
*
|
|
28
|
+
* @since Chrome 86
|
|
29
|
+
*/ RuleActionType["ModifyHeaders"] = "modifyHeaders";
|
|
30
|
+
/**
|
|
31
|
+
* Allow all requests within a frame hierarchy, including the frame request itself.
|
|
32
|
+
*/ RuleActionType["AllowAllRequests"] = "allowAllRequests";
|
|
33
|
+
return RuleActionType;
|
|
34
|
+
}({});
|
|
35
|
+
/**
|
|
36
|
+
* Validator for {@link RuleAction}.
|
|
37
|
+
*/ const RuleActionValidator = strictObjectByType({
|
|
38
|
+
redirect: v.optional(RedirectValidator),
|
|
39
|
+
requestHeaders: v.optional(v.array(ModifyHeaderInfoValidator)),
|
|
40
|
+
responseHeaders: v.optional(v.array(ModifyHeaderInfoValidator)),
|
|
41
|
+
type: v.enum(RuleActionType)
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { RuleActionType, RuleActionValidator };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { HeaderInfoValidator } from './header-info.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enum that represents request is first or third party to the frame in which it originated.
|
|
7
|
+
* A request is said to be first party if it has the same domain (eTLD+1) as the frame in which the request originated.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest#type-DomainType}
|
|
10
|
+
*/ var DomainType = /*#__PURE__*/ function(DomainType) {
|
|
11
|
+
/**
|
|
12
|
+
* The network request is first party to the frame in which it originated.
|
|
13
|
+
*/ DomainType["FirstParty"] = "firstParty";
|
|
14
|
+
/**
|
|
15
|
+
* The network request is third party to the frame in which it originated.
|
|
16
|
+
*/ DomainType["ThirdParty"] = "thirdParty";
|
|
17
|
+
return DomainType;
|
|
18
|
+
}({});
|
|
19
|
+
/**
|
|
20
|
+
* Enum that represents the HTTP request method of a network request.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RequestMethod}
|
|
23
|
+
*/ var RequestMethod = /*#__PURE__*/ function(RequestMethod) {
|
|
24
|
+
RequestMethod["Connect"] = "connect";
|
|
25
|
+
RequestMethod["Delete"] = "delete";
|
|
26
|
+
RequestMethod["Get"] = "get";
|
|
27
|
+
RequestMethod["Head"] = "head";
|
|
28
|
+
RequestMethod["Options"] = "options";
|
|
29
|
+
RequestMethod["Patch"] = "patch";
|
|
30
|
+
RequestMethod["Post"] = "post";
|
|
31
|
+
RequestMethod["Put"] = "put";
|
|
32
|
+
return RequestMethod;
|
|
33
|
+
}({});
|
|
34
|
+
/**
|
|
35
|
+
* Enum that represents resource type of the network request.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest#type-ResourceType}
|
|
38
|
+
*/ var ResourceType = /*#__PURE__*/ function(ResourceType) {
|
|
39
|
+
ResourceType["MainFrame"] = "main_frame";
|
|
40
|
+
ResourceType["SubFrame"] = "sub_frame";
|
|
41
|
+
ResourceType["Stylesheet"] = "stylesheet";
|
|
42
|
+
ResourceType["Script"] = "script";
|
|
43
|
+
ResourceType["Image"] = "image";
|
|
44
|
+
ResourceType["Font"] = "font";
|
|
45
|
+
ResourceType["Object"] = "object";
|
|
46
|
+
ResourceType["XmlHttpRequest"] = "xmlhttprequest";
|
|
47
|
+
ResourceType["Ping"] = "ping";
|
|
48
|
+
ResourceType["CspReport"] = "csp_report";
|
|
49
|
+
ResourceType["Media"] = "media";
|
|
50
|
+
ResourceType["WebSocket"] = "websocket";
|
|
51
|
+
ResourceType["WebTransport"] = "webtransport";
|
|
52
|
+
ResourceType["WebBundle"] = "webbundle";
|
|
53
|
+
ResourceType["Other"] = "other";
|
|
54
|
+
return ResourceType;
|
|
55
|
+
}({});
|
|
56
|
+
/**
|
|
57
|
+
* Validator for {@link RuleCondition}.
|
|
58
|
+
*/ const RuleConditionValidator = strictObjectByType({
|
|
59
|
+
domainType: v.optional(v.enum(DomainType)),
|
|
60
|
+
initiatorDomains: v.optional(v.pipe(v.array(v.string()), v.nonEmpty())),
|
|
61
|
+
excludedInitiatorDomains: v.optional(v.array(v.string())),
|
|
62
|
+
requestDomains: v.optional(v.pipe(v.array(v.string()), v.nonEmpty())),
|
|
63
|
+
excludedRequestDomains: v.optional(v.array(v.string())),
|
|
64
|
+
responseHeaders: v.optional(v.array(HeaderInfoValidator)),
|
|
65
|
+
excludedResponseHeaders: v.optional(v.array(HeaderInfoValidator)),
|
|
66
|
+
tabIds: v.optional(v.pipe(v.array(v.number()), v.nonEmpty())),
|
|
67
|
+
excludedTabIds: v.optional(v.array(v.number())),
|
|
68
|
+
requestMethods: v.optional(v.pipe(v.array(v.enum(RequestMethod)), v.nonEmpty())),
|
|
69
|
+
excludedRequestMethods: v.optional(v.array(v.enum(RequestMethod))),
|
|
70
|
+
resourceTypes: v.optional(v.pipe(v.array(v.enum(ResourceType)), v.nonEmpty())),
|
|
71
|
+
excludedResourceTypes: v.optional(v.array(v.enum(ResourceType))),
|
|
72
|
+
regexFilter: v.optional(v.string()),
|
|
73
|
+
urlFilter: v.optional(v.pipe(v.string(), v.nonEmpty())),
|
|
74
|
+
isUrlFilterCaseSensitive: v.optional(v.boolean())
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export { DomainType, RequestMethod, ResourceType, RuleConditionValidator };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import { strictObjectByType } from '../utils/valibot.js';
|
|
3
|
+
import { QueryTransformValidator } from './query-transform.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enum that represents URL transformation schemes.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-URLTransform}
|
|
9
|
+
*/ var URLTransformScheme = /*#__PURE__*/ function(URLTransformScheme) {
|
|
10
|
+
URLTransformScheme["Http"] = "http";
|
|
11
|
+
URLTransformScheme["Https"] = "https";
|
|
12
|
+
URLTransformScheme["Ftp"] = "ftp";
|
|
13
|
+
URLTransformScheme["ChromeExtension"] = "chrome-extension";
|
|
14
|
+
return URLTransformScheme;
|
|
15
|
+
}({});
|
|
16
|
+
/**
|
|
17
|
+
* Validator for {@link URLTransform}.
|
|
18
|
+
*/ const URLTransformValidator = strictObjectByType({
|
|
19
|
+
fragment: v.optional(v.string()),
|
|
20
|
+
host: v.optional(v.string()),
|
|
21
|
+
password: v.optional(v.string()),
|
|
22
|
+
path: v.optional(v.string()),
|
|
23
|
+
port: v.optional(v.string()),
|
|
24
|
+
query: v.optional(v.string()),
|
|
25
|
+
queryTransform: v.optional(QueryTransformValidator),
|
|
26
|
+
scheme: v.optional(v.enum(URLTransformScheme)),
|
|
27
|
+
username: v.optional(v.string())
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export { URLTransformScheme, URLTransformValidator };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes error when converted rule contains an empty list of domains, but original contains.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link InvalidDeclarativeRuleError} parent class.
|
|
7
|
+
*/ class EmptyDomainsError extends InvalidDeclarativeRuleError {
|
|
8
|
+
/**
|
|
9
|
+
* Describes error when converted rule contains an empty list of domains, but original contains.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param rule {@link Rule}.
|
|
13
|
+
* @param declarativeRule {@link DeclarativeRule}.
|
|
14
|
+
*/ constructor(message, rule, declarativeRule){
|
|
15
|
+
super(message, rule, declarativeRule);
|
|
16
|
+
// For proper work of the "instanceof" operator
|
|
17
|
+
Object.setPrototypeOf(this, EmptyDomainsError.prototype);
|
|
18
|
+
// Set the error name to the class name only after setting the prototype
|
|
19
|
+
// to avoid issues with name being overwritten in some environments
|
|
20
|
+
this.name = this.constructor.name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { EmptyDomainsError };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes error when converted rule contains empty list of resources types.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link InvalidDeclarativeRuleError} parent class.
|
|
7
|
+
*/ class EmptyResourcesError extends InvalidDeclarativeRuleError {
|
|
8
|
+
/**
|
|
9
|
+
* Describes error when converted rule contains empty list of resources types.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param rule {@link Rule}.
|
|
13
|
+
* @param declarativeRule {@link DeclarativeRule}.
|
|
14
|
+
*/ constructor(message, rule, declarativeRule){
|
|
15
|
+
super(message, rule, declarativeRule);
|
|
16
|
+
// For proper work of the "instanceof" operator
|
|
17
|
+
Object.setPrototypeOf(this, EmptyResourcesError.prototype);
|
|
18
|
+
// Set the error name to the class name only after setting the prototype
|
|
19
|
+
// to avoid issues with name being overwritten in some environments
|
|
20
|
+
this.name = this.constructor.name;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { EmptyResourcesError };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EmptyDomainsError } from './empty-domains-error.js';
|
|
2
|
+
import { EmptyResourcesError } from './empty-resources-error.js';
|
|
3
|
+
import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
|
|
4
|
+
import { UnsupportedModifierError } from './unsupported-modifier-error.js';
|
|
5
|
+
import { UnsupportedRegexpError } from './unsupported-regexp-error.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type guard for {@link ConversionError}.
|
|
9
|
+
*
|
|
10
|
+
* @param error The error to check.
|
|
11
|
+
*
|
|
12
|
+
* @returns `true` if the error is a {@link ConversionError}, `false` otherwise.
|
|
13
|
+
*/ function isConversionError(error) {
|
|
14
|
+
return error instanceof EmptyDomainsError || error instanceof EmptyResourcesError || error instanceof InvalidDeclarativeRuleError || error instanceof UnsupportedModifierError || error instanceof UnsupportedRegexpError;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { EmptyDomainsError, EmptyResourcesError, InvalidDeclarativeRuleError, UnsupportedModifierError, UnsupportedRegexpError, isConversionError };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes abstract error when declarative rule is invalid.
|
|
3
|
+
*/ class InvalidDeclarativeRuleError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes abstract error when declarative rule is invalid.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
* @param rule {@link Rule}.
|
|
9
|
+
* @param declarativeRule {@link DeclarativeRule}.
|
|
10
|
+
*/ constructor(message, rule, declarativeRule){
|
|
11
|
+
super(message);
|
|
12
|
+
// For proper work of the "instanceof" operator
|
|
13
|
+
Object.setPrototypeOf(this, InvalidDeclarativeRuleError.prototype);
|
|
14
|
+
// Set the error name to the class name only after setting the prototype
|
|
15
|
+
// to avoid issues with name being overwritten in some environments
|
|
16
|
+
this.name = this.constructor.name;
|
|
17
|
+
this.declarativeRule = declarativeRule;
|
|
18
|
+
this.rule = rule;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { InvalidDeclarativeRuleError };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes an error when a source network rule contains some of the unsupported modifiers.
|
|
3
|
+
*/ class UnsupportedModifierError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes an error when a source network rule contains some of the unsupported modifiers.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
* @param rule {@link Rule}.
|
|
9
|
+
*/ constructor(message, rule){
|
|
10
|
+
super(message);
|
|
11
|
+
// For proper work of the "instanceof" operator
|
|
12
|
+
Object.setPrototypeOf(this, UnsupportedModifierError.prototype);
|
|
13
|
+
// Set the error name to the class name only after setting the prototype
|
|
14
|
+
// to avoid issues with name being overwritten in some environments
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
this.rule = rule;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { UnsupportedModifierError };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes an error when the converted rule contains an unsupported RE2 regexp syntax error.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link InvalidDeclarativeRuleError} parent class.
|
|
7
|
+
* @see https://github.com/google/re2/wiki/Syntax
|
|
8
|
+
*/ class UnsupportedRegexpError extends InvalidDeclarativeRuleError {
|
|
9
|
+
/**
|
|
10
|
+
* Describes an error when the converted rule contains an unsupported RE2 regexp syntax error.
|
|
11
|
+
*
|
|
12
|
+
* @param message Message of error.
|
|
13
|
+
* @param rule {@link Rule}.
|
|
14
|
+
* @param declarativeRule {@link DeclarativeRule}.
|
|
15
|
+
* @param reason Describes a reason of the error.
|
|
16
|
+
*/ constructor(message, rule, declarativeRule, reason){
|
|
17
|
+
super(message, rule, declarativeRule);
|
|
18
|
+
// For proper work of the "instanceof" operator
|
|
19
|
+
Object.setPrototypeOf(this, UnsupportedRegexpError.prototype);
|
|
20
|
+
// Set the error name to the class name only after setting the prototype
|
|
21
|
+
// to avoid issues with name being overwritten in some environments
|
|
22
|
+
this.name = this.constructor.name;
|
|
23
|
+
this.reason = reason;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { UnsupportedRegexpError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes error when maximum number of rules is equal or less than `0`.
|
|
3
|
+
*/ class EmptyOrNegativeNumberOfRulesError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes error when maximum number of rules is equal or less than `0`.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
*/ constructor(message){
|
|
9
|
+
super(message);
|
|
10
|
+
// For proper work of the "instanceof" operator
|
|
11
|
+
Object.setPrototypeOf(this, EmptyOrNegativeNumberOfRulesError.prototype);
|
|
12
|
+
// Set the error name to the class name only after setting the prototype
|
|
13
|
+
// to avoid issues with name being overwritten in some environments
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { EmptyOrNegativeNumberOfRulesError };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EmptyOrNegativeNumberOfRulesError } from './empty-or-negative-number-of-rules-error.js';
|
|
2
|
+
import { NegativeNumberOfRulesError } from './negative-number-of-rules-error.js';
|
|
3
|
+
import { ResourcesPathError } from './resources-path-error.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type guard for {@link ConverterOptionsError}.
|
|
7
|
+
*
|
|
8
|
+
* @param error The error to check.
|
|
9
|
+
*
|
|
10
|
+
* @returns `true` if the error is a {@link ConverterOptionsError}, `false` otherwise.
|
|
11
|
+
*/ function isConverterOptionsError(error) {
|
|
12
|
+
return error instanceof EmptyOrNegativeNumberOfRulesError || error instanceof NegativeNumberOfRulesError || error instanceof ResourcesPathError;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { EmptyOrNegativeNumberOfRulesError, NegativeNumberOfRulesError, ResourcesPathError, isConverterOptionsError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes error when maximum number of rules is less than `0`.
|
|
3
|
+
*/ class NegativeNumberOfRulesError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes error when maximum number of rules is less than `0`.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
*/ constructor(message){
|
|
9
|
+
super(message);
|
|
10
|
+
// For proper work of the "instanceof" operator
|
|
11
|
+
Object.setPrototypeOf(this, NegativeNumberOfRulesError.prototype);
|
|
12
|
+
// Set the error name to the class name only after setting the prototype
|
|
13
|
+
// to avoid issues with name being overwritten in some environments
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { NegativeNumberOfRulesError };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes error when the resources path does not start with a slash or it ends with a slash.
|
|
3
|
+
*/ class ResourcesPathError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes error when the resources path does not start with a slash or it ends with a slash.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
*/ constructor(message){
|
|
9
|
+
super(message);
|
|
10
|
+
// For proper work of the "instanceof" operator
|
|
11
|
+
Object.setPrototypeOf(this, ResourcesPathError.prototype);
|
|
12
|
+
// Set the error name to the class name only after setting the prototype
|
|
13
|
+
// to avoid issues with name being overwritten in some environments
|
|
14
|
+
this.name = this.constructor.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ResourcesPathError };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MaxScannedRulesError } from './max-scanned-rules-error.js';
|
|
2
|
+
import { TooManyError } from './too-many-error.js';
|
|
3
|
+
import { TooManyRegexpRulesError } from './too-many-regexp-rules-error.js';
|
|
4
|
+
import { TooManyRulesError } from './too-many-rules-error.js';
|
|
5
|
+
import { TooManyUnsafeRulesError } from './too-many-unsafe-rules-error.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type guard for {@link LimitationError}.
|
|
9
|
+
*
|
|
10
|
+
* @param error The error to check.
|
|
11
|
+
*
|
|
12
|
+
* @returns `true` if the error is a {@link LimitationError}, `false` otherwise.
|
|
13
|
+
*/ function isLimitationError(error) {
|
|
14
|
+
return error instanceof MaxScannedRulesError || error instanceof TooManyError || error instanceof TooManyRegexpRulesError || error instanceof TooManyRulesError || error instanceof TooManyUnsafeRulesError;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { MaxScannedRulesError, TooManyError, TooManyRegexpRulesError, TooManyRulesError, TooManyUnsafeRulesError, isLimitationError };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Describes an error when the maximum number of rules is reached and some rules are skipped from scanning.
|
|
3
|
+
*/ class MaxScannedRulesError extends Error {
|
|
4
|
+
/**
|
|
5
|
+
* Describes an error when the maximum number of rules is reached and some rules are skipped from scanning.
|
|
6
|
+
*
|
|
7
|
+
* @param message Message of error.
|
|
8
|
+
* @param lineIndex Line index of the filter from which the rules are skipped.
|
|
9
|
+
*/ constructor(message, lineIndex){
|
|
10
|
+
super(message);
|
|
11
|
+
// For proper work of the "instanceof" operator
|
|
12
|
+
Object.setPrototypeOf(this, MaxScannedRulesError.prototype);
|
|
13
|
+
// Set the error name to the class name only after setting the prototype
|
|
14
|
+
// to avoid issues with name being overwritten in some environments
|
|
15
|
+
this.name = this.constructor.name;
|
|
16
|
+
this.lineIndex = lineIndex;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { MaxScannedRulesError };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('../../ruleset/source-map').Source} Source
|
|
3
|
+
*/ /**
|
|
4
|
+
* Describes an error when the maximum number of something is reached.
|
|
5
|
+
*
|
|
6
|
+
* Note: This class is intended to be extended by more specific error classes.
|
|
7
|
+
*/ class TooManyError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Describes an error when the maximum number of something is reached.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
|
|
13
|
+
* @param numberOfMaximumRules Number of maximum rules.
|
|
14
|
+
* @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
|
|
15
|
+
*/ constructor(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules){
|
|
16
|
+
super(message);
|
|
17
|
+
// For proper work of the "instanceof" operator
|
|
18
|
+
Object.setPrototypeOf(this, TooManyError.prototype);
|
|
19
|
+
// Set the error name to the class name only after setting the prototype
|
|
20
|
+
// to avoid issues with name being overwritten in some environments
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
this.excludedRulesIds = excludedRulesIds;
|
|
23
|
+
this.numberOfMaximumRules = numberOfMaximumRules;
|
|
24
|
+
this.numberOfExcludedDeclarativeRules = numberOfExcludedDeclarativeRules;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { TooManyError };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TooManyError } from './too-many-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../../ruleset/source-map').Source} Source
|
|
5
|
+
*/ /**
|
|
6
|
+
* Describes an error when the maximum number of regexp rules is reached.
|
|
7
|
+
*/ class TooManyRegexpRulesError extends TooManyError {
|
|
8
|
+
/**
|
|
9
|
+
* Describes an error when the maximum number of regexp rules is reached.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
|
|
13
|
+
* @param numberOfMaximumRules Number of maximum rules.
|
|
14
|
+
* @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
|
|
15
|
+
*/ constructor(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules){
|
|
16
|
+
super(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules);
|
|
17
|
+
// For proper work of the "instanceof" operator
|
|
18
|
+
Object.setPrototypeOf(this, TooManyRegexpRulesError.prototype);
|
|
19
|
+
// Set the error name to the class name only after setting the prototype
|
|
20
|
+
// to avoid issues with name being overwritten in some environments
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { TooManyRegexpRulesError };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TooManyError } from './too-many-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../../ruleset/source-map').Source} Source
|
|
5
|
+
*/ /**
|
|
6
|
+
* Describes an error when the maximum number of rules is reached.
|
|
7
|
+
*/ class TooManyRulesError extends TooManyError {
|
|
8
|
+
/**
|
|
9
|
+
* Describes an error when the maximum number of rules is reached.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
|
|
13
|
+
* @param numberOfMaximumRules Number of maximum rules.
|
|
14
|
+
* @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
|
|
15
|
+
*/ constructor(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules){
|
|
16
|
+
super(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules);
|
|
17
|
+
// For proper work of the "instanceof" operator
|
|
18
|
+
Object.setPrototypeOf(this, TooManyRulesError.prototype);
|
|
19
|
+
// Set the error name to the class name only after setting the prototype
|
|
20
|
+
// to avoid issues with name being overwritten in some environments
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { TooManyRulesError };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TooManyError } from './too-many-error.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {import('../../ruleset/source-map').Source} Source
|
|
5
|
+
*/ /**
|
|
6
|
+
* Describes an error when the maximum number of unsafe rules is reached.
|
|
7
|
+
*/ class TooManyUnsafeRulesError extends TooManyError {
|
|
8
|
+
/**
|
|
9
|
+
* Describes an error when the maximum number of unsafe rules is reached.
|
|
10
|
+
*
|
|
11
|
+
* @param message Message of error.
|
|
12
|
+
* @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
|
|
13
|
+
* @param numberOfMaximumRules Number of maximum rules.
|
|
14
|
+
* @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
|
|
15
|
+
*/ constructor(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules){
|
|
16
|
+
super(message, excludedRulesIds, numberOfMaximumRules, numberOfExcludedDeclarativeRules);
|
|
17
|
+
// For proper work of the "instanceof" operator
|
|
18
|
+
Object.setPrototypeOf(this, TooManyUnsafeRulesError.prototype);
|
|
19
|
+
// Set the error name to the class name only after setting the prototype
|
|
20
|
+
// to avoid issues with name being overwritten in some environments
|
|
21
|
+
this.name = this.constructor.name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { TooManyUnsafeRulesError };
|