@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.
Files changed (114) hide show
  1. package/README.md +476 -0
  2. package/dist/cli.cjs +58912 -0
  3. package/dist/constants.js +23 -0
  4. package/dist/declarative-rule/declarative-rule.js +15 -0
  5. package/dist/declarative-rule/header-info.js +12 -0
  6. package/dist/declarative-rule/modify-header-info.js +31 -0
  7. package/dist/declarative-rule/query-key-value.js +12 -0
  8. package/dist/declarative-rule/query-transform.js +12 -0
  9. package/dist/declarative-rule/redirect.js +14 -0
  10. package/dist/declarative-rule/rule-action.js +44 -0
  11. package/dist/declarative-rule/rule-condition.js +77 -0
  12. package/dist/declarative-rule/url-transform.js +30 -0
  13. package/dist/errors/conversion-errors/empty-domains-error.js +24 -0
  14. package/dist/errors/conversion-errors/empty-resources-error.js +24 -0
  15. package/dist/errors/conversion-errors/index.js +17 -0
  16. package/dist/errors/conversion-errors/invalid-declarative-rule-error.js +22 -0
  17. package/dist/errors/conversion-errors/unsupported-modifier-error.js +20 -0
  18. package/dist/errors/conversion-errors/unsupported-regexp-error.js +27 -0
  19. package/dist/errors/converter-options-errors/empty-or-negative-number-of-rules-error.js +18 -0
  20. package/dist/errors/converter-options-errors/index.js +15 -0
  21. package/dist/errors/converter-options-errors/negative-number-of-rules-error.js +18 -0
  22. package/dist/errors/converter-options-errors/resources-path-error.js +18 -0
  23. package/dist/errors/limitation-errors/index.js +17 -0
  24. package/dist/errors/limitation-errors/max-scanned-rules-error.js +20 -0
  25. package/dist/errors/limitation-errors/too-many-error.js +28 -0
  26. package/dist/errors/limitation-errors/too-many-regexp-rules-error.js +25 -0
  27. package/dist/errors/limitation-errors/too-many-rules-error.js +25 -0
  28. package/dist/errors/limitation-errors/too-many-unsafe-rules-error.js +25 -0
  29. package/dist/errors/unavailable-sources-errors/unavailable-filter-source-error.js +21 -0
  30. package/dist/errors/unavailable-sources-errors/unavailable-ruleset-source-error.js +21 -0
  31. package/dist/filter/filter.js +92 -0
  32. package/dist/filter-converter/filter-converter.js +385 -0
  33. package/dist/grouped-rules-converters/url-transform-converter.js +340 -0
  34. package/dist/index.js +30 -0
  35. package/dist/package.json.js +3 -0
  36. package/dist/re2-regexp/re2-validator.js +37 -0
  37. package/dist/re2-regexp/regex-validator-extension.js +30 -0
  38. package/dist/re2.wasm +0 -0
  39. package/dist/rule/option-names.js +65 -0
  40. package/dist/rule/rule-badfilter.js +81 -0
  41. package/dist/rule/rule-priority.js +88 -0
  42. package/dist/rule/rule-validator.js +455 -0
  43. package/dist/rule/rule.js +853 -0
  44. package/dist/rule/string-utils.js +49 -0
  45. package/dist/rule-converters/csp-converter.js +105 -0
  46. package/dist/rule-converters/regular-rule-converter.js +789 -0
  47. package/dist/rule-converters/remove-header-converter.js +97 -0
  48. package/dist/rule-converters/rules-converter.js +365 -0
  49. package/dist/rule-converters/rules-grouper.js +75 -0
  50. package/dist/rules-scanner/rules-scanner.js +136 -0
  51. package/dist/ruleset/metadata-rule.js +35 -0
  52. package/dist/ruleset/metadata-ruleset.js +162 -0
  53. package/dist/ruleset/rules-hash-map.js +71 -0
  54. package/dist/ruleset/ruleset-with-source-map.js +406 -0
  55. package/dist/ruleset/ruleset.js +54 -0
  56. package/dist/ruleset/source-map.js +283 -0
  57. package/dist/types/cli/convert-filters.d.ts +32 -0
  58. package/dist/types/cli/index.d.ts +7 -0
  59. package/dist/types/cli/utils.d.ts +19 -0
  60. package/dist/types/src/declarative-rule/declarative-rule.d.ts +32 -0
  61. package/dist/types/src/declarative-rule/header-info.d.ts +31 -0
  62. package/dist/types/src/declarative-rule/modify-header-info.d.ts +46 -0
  63. package/dist/types/src/declarative-rule/query-key-value.d.ts +24 -0
  64. package/dist/types/src/declarative-rule/query-transform.d.ts +21 -0
  65. package/dist/types/src/declarative-rule/redirect.d.ts +32 -0
  66. package/dist/types/src/declarative-rule/rule-action.d.ts +68 -0
  67. package/dist/types/src/declarative-rule/rule-condition.d.ts +262 -0
  68. package/dist/types/src/declarative-rule/url-transform.d.ts +69 -0
  69. package/dist/types/src/errors/conversion-errors/empty-domains-error.d.ts +21 -0
  70. package/dist/types/src/errors/conversion-errors/empty-resources-error.d.ts +21 -0
  71. package/dist/types/src/errors/conversion-errors/index.d.ts +27 -0
  72. package/dist/types/src/errors/conversion-errors/invalid-declarative-rule-error.d.ts +30 -0
  73. package/dist/types/src/errors/conversion-errors/unsupported-modifier-error.d.ts +20 -0
  74. package/dist/types/src/errors/conversion-errors/unsupported-regexp-error.d.ts +23 -0
  75. package/dist/types/src/errors/converter-options-errors/empty-or-negative-number-of-rules-error.d.ts +13 -0
  76. package/dist/types/src/errors/converter-options-errors/index.d.ts +23 -0
  77. package/dist/types/src/errors/converter-options-errors/negative-number-of-rules-error.d.ts +13 -0
  78. package/dist/types/src/errors/converter-options-errors/resources-path-error.d.ts +13 -0
  79. package/dist/types/src/errors/limitation-errors/index.d.ts +27 -0
  80. package/dist/types/src/errors/limitation-errors/max-scanned-rules-error.d.ts +18 -0
  81. package/dist/types/src/errors/limitation-errors/too-many-error.d.ts +33 -0
  82. package/dist/types/src/errors/limitation-errors/too-many-regexp-rules-error.d.ts +21 -0
  83. package/dist/types/src/errors/limitation-errors/too-many-rules-error.d.ts +21 -0
  84. package/dist/types/src/errors/limitation-errors/too-many-unsafe-rules-error.d.ts +21 -0
  85. package/dist/types/src/errors/unavailable-sources-errors/unavailable-filter-source-error.d.ts +19 -0
  86. package/dist/types/src/errors/unavailable-sources-errors/unavailable-ruleset-source-error.d.ts +19 -0
  87. package/dist/types/src/filter/filter.d.ts +74 -0
  88. package/dist/types/src/filter/types.d.ts +45 -0
  89. package/dist/types/src/filter-converter/conversion-result.d.ts +35 -0
  90. package/dist/types/src/filter-converter/filter-converter-options.d.ts +81 -0
  91. package/dist/types/src/filter-converter/filter-converter.d.ts +197 -0
  92. package/dist/types/src/index.d.ts +37 -0
  93. package/dist/types/src/rule/rule-types.d.ts +33 -0
  94. package/dist/types/src/rule/rule-validator.d.ts +185 -0
  95. package/dist/types/src/rule/rule.d.ts +269 -0
  96. package/dist/types/src/ruleset/metadata-ruleset.d.ts +128 -0
  97. package/dist/types/src/ruleset/rules-hash-map.d.ts +70 -0
  98. package/dist/types/src/ruleset/ruleset-with-source-map.d.ts +318 -0
  99. package/dist/types/src/ruleset/ruleset.d.ts +86 -0
  100. package/dist/types/src/ruleset/source-map.d.ts +45 -0
  101. package/dist/types/src/ruleset/types.d.ts +68 -0
  102. package/dist/types/src/utils/is-safe-rule.d.ts +20 -0
  103. package/dist/types/src/utils/ruleset-utils.d.ts +45 -0
  104. package/dist/types/src/version.d.ts +6 -0
  105. package/dist/url-transform-converter.js +338 -0
  106. package/dist/utils/error.js +22 -0
  107. package/dist/utils/is-safe-rule.js +25 -0
  108. package/dist/utils/lazy-loader.js +116 -0
  109. package/dist/utils/lazy.js +50 -0
  110. package/dist/utils/ruleset-utils.js +76 -0
  111. package/dist/utils/string.js +180 -0
  112. package/dist/utils/valibot.js +74 -0
  113. package/dist/version.js +7 -0
  114. package/package.json +122 -0
@@ -0,0 +1,262 @@
1
+ import { HeaderInfo } from './header-info.js';
2
+
3
+ /**
4
+ * Enum that represents request is first or third party to the frame in which it originated.
5
+ * A request is said to be first party if it has the same domain (eTLD+1) as the frame in which the request originated.
6
+ *
7
+ * @see {@link https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest#type-DomainType}
8
+ */
9
+ declare enum DomainType {
10
+ /**
11
+ * The network request is first party to the frame in which it originated.
12
+ */
13
+ FirstParty = "firstParty",
14
+ /**
15
+ * The network request is third party to the frame in which it originated.
16
+ */
17
+ ThirdParty = "thirdParty"
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
+ */
24
+ declare enum RequestMethod {
25
+ Connect = "connect",
26
+ Delete = "delete",
27
+ Get = "get",
28
+ Head = "head",
29
+ Options = "options",
30
+ Patch = "patch",
31
+ Post = "post",
32
+ Put = "put"
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
+ */
39
+ declare enum ResourceType {
40
+ MainFrame = "main_frame",
41
+ SubFrame = "sub_frame",
42
+ Stylesheet = "stylesheet",
43
+ Script = "script",
44
+ Image = "image",
45
+ Font = "font",
46
+ Object = "object",
47
+ XmlHttpRequest = "xmlhttprequest",
48
+ Ping = "ping",
49
+ CspReport = "csp_report",
50
+ Media = "media",
51
+ WebSocket = "websocket",
52
+ WebTransport = "webtransport",
53
+ WebBundle = "webbundle",
54
+ Other = "other"
55
+ }
56
+ /**
57
+ * Rule condition for which the action should be applied.
58
+ *
59
+ * @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-RuleCondition}
60
+ */
61
+ interface RuleCondition {
62
+ /**
63
+ * Specifies whether the network request is first-party or third-party
64
+ * to the domain from which it originated. If omitted, all requests are accepted.
65
+ *
66
+ * @see {@link DomainType}
67
+ */
68
+ domainType?: DomainType;
69
+ /**
70
+ * The rule will only match network requests originating
71
+ * from the list of {@link initiatorDomains}. If the list is omitted,
72
+ * the rule is applied to requests from all domains.
73
+ * An empty list is not allowed.
74
+ *
75
+ * Notes:
76
+ * - Sub-domains like `'a.example.com'` are also allowed.
77
+ * - The entries must consist of only ascii characters.
78
+ * - Use punycode encoding for internationalized domains.
79
+ * - This matches against the request initiator and not the request url.
80
+ * - Sub-domains of the listed domains are also matched.
81
+ *
82
+ * @since Chrome 101
83
+ */
84
+ initiatorDomains?: string[];
85
+ /**
86
+ * The rule will not match network requests originating
87
+ * from the list of {@link excludedInitiatorDomains}.
88
+ * If the list is empty or omitted, no domains are excluded.
89
+ * This takes precedence over {@link initiatorDomains}.
90
+ *
91
+ * Notes:
92
+ * - Sub-domains like `'a.example.com'` are also allowed.
93
+ * - The entries must consist of only ascii characters.
94
+ * - Use punycode encoding for internationalized domains.
95
+ * - This matches against the request initiator and not the request url.
96
+ * - Sub-domains of the listed domains are also excluded.
97
+ *
98
+ * @since Chrome 101
99
+ */
100
+ excludedInitiatorDomains?: string[];
101
+ /**
102
+ * The rule will only match network requests when the domain matches
103
+ * one from the list of {@link requestDomains}. If the list is omitted,
104
+ * the rule is applied to requests from all domains.
105
+ * An empty list is not allowed.
106
+ *
107
+ * Notes:
108
+ * - Sub-domains like `'a.example.com'` are also allowed.
109
+ * - The entries must consist of only ascii characters.
110
+ * - Use punycode encoding for internationalized domains.
111
+ * - Sub-domains of the listed domains are also matched.
112
+ *
113
+ * @since Chrome 101
114
+ */
115
+ requestDomains?: string[];
116
+ /**
117
+ * The rule will not match network requests when the domains
118
+ * matches one from the list of {@link excludedRequestDomains}.
119
+ * If the list is empty or omitted, no domains are excluded.
120
+ * This takes precedence over {@link requestDomains}.
121
+ *
122
+ * Notes:
123
+ * - Sub-domains like `'a.example.com'` are also allowed.
124
+ * - The entries must consist of only ascii characters.
125
+ * - Use punycode encoding for internationalized domains.
126
+ * - Sub-domains of the listed domains are also excluded.
127
+ *
128
+ * @since Chrome 101
129
+ */
130
+ excludedRequestDomains?: string[];
131
+ /**
132
+ * Rule matches if the request matches any response header condition in this list (if specified).
133
+ *
134
+ * @see {@link HeaderInfo}
135
+ *
136
+ * @since Chrome 128
137
+ */
138
+ responseHeaders?: HeaderInfo[];
139
+ /**
140
+ * Rule does not match if the request matches
141
+ * any response header condition in this list (if specified).
142
+ * If both {@link excludedResponseHeaders} and {@link responseHeaders} are specified,
143
+ * then the {@link excludedResponseHeaders} property takes precedence.
144
+ *
145
+ * @see {@link HeaderInfo}
146
+ *
147
+ * @since Chrome 128
148
+ */
149
+ excludedResponseHeaders?: HeaderInfo[];
150
+ /**
151
+ * List of {@link chrome.tabs.Tab.id} which the rule should match.
152
+ * An ID of {@link chrome.tabs.TAB_ID_NONE} matches requests which
153
+ * don't originate from a tab. An empty list is not allowed.
154
+ * Only supported for session-scoped rules.
155
+ *
156
+ * @since Chrome 92
157
+ */
158
+ tabIds?: number[];
159
+ /**
160
+ * List of {@link chrome.tabs.Tab.id} which the rule should not match.
161
+ * An ID of {@link chrome.tabs.TAB_ID_NONE} excludes requests which
162
+ * don't originate from a tab. Only supported for session-scoped rules.
163
+ *
164
+ * @since Chrome 92
165
+ */
166
+ excludedTabIds?: number[];
167
+ /**
168
+ * List of HTTP request methods which the rule can match.
169
+ * Only one of {@link requestMethods} and {@link excludedRequestMethods}
170
+ * should be specified. If neither of them is specified,
171
+ * all request methods are matched. An empty list is not allowed.
172
+ *
173
+ * Note: Specifying a {@link requestMethods} rule condition will also exclude
174
+ * non-HTTP(s) requests, whereas specifying {@link excludedRequestMethods} will not.
175
+ *
176
+ * @see {@link RequestMethod}
177
+ *
178
+ * @since Chrome 91
179
+ */
180
+ requestMethods?: RequestMethod[];
181
+ /**
182
+ * List of request methods which the rule won't match.
183
+ * Only one of {@link requestMethods} and {@link excludedRequestMethods}
184
+ * should be specified. If neither of them is specified,
185
+ * all request methods are matched.
186
+ *
187
+ * @see {@link RequestMethod}
188
+ *
189
+ * @since Chrome 91
190
+ */
191
+ excludedRequestMethods?: RequestMethod[];
192
+ /**
193
+ * List of resource types which the rule can match.
194
+ * Only one of {@link resourceTypes} and {@link excludedResourceTypes}
195
+ * should be specified. If neither of them is specified,
196
+ * all resource types except {@link ResourceType.MainFrame} are blocked.
197
+ * An empty list is not allowed.
198
+ *
199
+ * Note: this must be specified for `AllowAllRequests` rules
200
+ * and may only include the {@link ResourceType.MainFrame} and {@link ResourceType.SubFrame} resource types.
201
+ *
202
+ * @see {@link ResourceType}
203
+ */
204
+ resourceTypes?: ResourceType[];
205
+ /**
206
+ * List of resource types which the rule won't match.
207
+ * Only one of {@link resourceTypes} and {@link excludedResourceTypes}
208
+ * should be specified. If neither of them is specified,
209
+ * all resource types except {@link ResourceType.MainFrame} are blocked.
210
+ *
211
+ * @see {@link ResourceType}
212
+ */
213
+ excludedResourceTypes?: ResourceType[];
214
+ /**
215
+ * Regular expression to match against the network request url.
216
+ * This follows the {@link https://github.com/google/re2/wiki/Syntax | RE2 syntax}.
217
+ *
218
+ * Notes:
219
+ * - Only one of {@link urlFilter} or {@link regexFilter} can be specified.
220
+ * - The {@link regexFilter} must be composed of only ASCII characters.
221
+ * This is matched against a url where the host is encoded in the punycode
222
+ * format (in case of internationalized domains) and any other non-ascii
223
+ * characters are url encoded in utf-8.
224
+ */
225
+ regexFilter?: string;
226
+ /**
227
+ * The pattern which is matched against the network request url. Supported constructs:
228
+ * - `'*'` wildcard: Matches any number of characters.
229
+ * - `'|'` left/right anchor: If used at either end of the pattern,
230
+ * specifies the beginning/end of the url respectively.
231
+ * - `'||'` domain name anchor: If used at the beginning of the pattern,
232
+ * specifies the start of a (sub-)domain of the URL.
233
+ * - `'^'` separator character: This matches anything except a letter,
234
+ * a digit, or one of the following: `'_'`, `'-'`, `'.'`, or `'%'`.
235
+ * This also match the end of the URL.
236
+ *
237
+ * Therefore {@link urlFilter} is composed of the following parts:
238
+ * (optional Left/Domain name anchor) + pattern + (optional Right anchor).
239
+ *
240
+ * If omitted, all urls are matched. An empty string is not allowed.
241
+ *
242
+ * A pattern beginning with `'||*'` is not allowed. Use `'*'` instead.
243
+ *
244
+ * Notes:
245
+ * - Only one of {@link urlFilter} or {@link regexFilter} can be specified.
246
+ * - The {@link urlFilter} must be composed of only ASCII characters.
247
+ * This is matched against a url where the host is encoded
248
+ * in the punycode format (in case of internationalized domains)
249
+ * and any other non-ascii characters are url encoded in utf-8.
250
+ * For example, when the request url is `'http://abc.рф?q=ф'`,
251
+ * the urlFilter will be matched against the url `'http://abc.xn--p1ai/?q=%D1%84'`.
252
+ */
253
+ urlFilter?: string;
254
+ /**
255
+ * Whether the {@link urlFilter} or {@link regexFilter} (whichever is specified)
256
+ * is case sensitive. Default is `false`.
257
+ */
258
+ isUrlFilterCaseSensitive?: boolean;
259
+ }
260
+
261
+ export { DomainType, RequestMethod, ResourceType };
262
+ export type { RuleCondition };
@@ -0,0 +1,69 @@
1
+ import { QueryTransform } from './query-transform.js';
2
+
3
+ /**
4
+ * Enum that represents URL transformation schemes.
5
+ *
6
+ * @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-URLTransform}
7
+ */
8
+ declare enum URLTransformScheme {
9
+ Http = "http",
10
+ Https = "https",
11
+ Ftp = "ftp",
12
+ ChromeExtension = "chrome-extension"
13
+ }
14
+ /**
15
+ * Interface that represents URL transformations.
16
+ *
17
+ * @see {@link https://developer.chrome.com/docs/extensions/reference/declarativeNetRequest/#type-URLTransform}
18
+ */
19
+ interface URLTransform {
20
+ /**
21
+ * The new fragment for the request.
22
+ *
23
+ * Should be either empty `''`, in which case the existing
24
+ * fragment is cleared, or should begin with `'#'`.
25
+ */
26
+ fragment?: string;
27
+ /**
28
+ * The new host for the request.
29
+ */
30
+ host?: string;
31
+ /**
32
+ * The new password for the request.
33
+ */
34
+ password?: string;
35
+ /**
36
+ * The new path for the request. If empty, the existing path is cleared.
37
+ */
38
+ path?: string;
39
+ /**
40
+ * The new port for the request. If empty, the existing port is cleared.
41
+ */
42
+ port?: string;
43
+ /**
44
+ * The new query for the request.
45
+ *
46
+ * Should be either empty `''`, in which case the existing
47
+ * query is cleared, or should begin with `'?'`.
48
+ */
49
+ query?: string;
50
+ /**
51
+ * Add, remove or replace query key-value pairs.
52
+ *
53
+ * @see {@link QueryTransform}
54
+ */
55
+ queryTransform?: QueryTransform;
56
+ /**
57
+ * The new scheme for the request.
58
+ *
59
+ * @see {@link URLTransformScheme}
60
+ */
61
+ scheme?: URLTransformScheme;
62
+ /**
63
+ * The new username for the request.
64
+ */
65
+ username?: string;
66
+ }
67
+
68
+ export { URLTransformScheme };
69
+ export type { URLTransform };
@@ -0,0 +1,21 @@
1
+ import { DeclarativeRule } from '../../declarative-rule/declarative-rule.js';
2
+ import { Rule } from '../../rule/rule.js';
3
+ import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
4
+
5
+ /**
6
+ * Describes error when converted rule contains an empty list of domains, but original contains.
7
+ *
8
+ * @see {@link InvalidDeclarativeRuleError} parent class.
9
+ */
10
+ declare class EmptyDomainsError extends InvalidDeclarativeRuleError {
11
+ /**
12
+ * Describes error when converted rule contains an empty list of domains, but original contains.
13
+ *
14
+ * @param message Message of error.
15
+ * @param rule {@link Rule}.
16
+ * @param declarativeRule {@link DeclarativeRule}.
17
+ */
18
+ constructor(message: string, rule: Rule, declarativeRule: DeclarativeRule);
19
+ }
20
+
21
+ export { EmptyDomainsError };
@@ -0,0 +1,21 @@
1
+ import { DeclarativeRule } from '../../declarative-rule/declarative-rule.js';
2
+ import { Rule } from '../../rule/rule.js';
3
+ import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
4
+
5
+ /**
6
+ * Describes error when converted rule contains empty list of resources types.
7
+ *
8
+ * @see {@link InvalidDeclarativeRuleError} parent class.
9
+ */
10
+ declare class EmptyResourcesError extends InvalidDeclarativeRuleError {
11
+ /**
12
+ * Describes error when converted rule contains empty list of resources types.
13
+ *
14
+ * @param message Message of error.
15
+ * @param rule {@link Rule}.
16
+ * @param declarativeRule {@link DeclarativeRule}.
17
+ */
18
+ constructor(message: string, rule: Rule, declarativeRule: DeclarativeRule);
19
+ }
20
+
21
+ export { EmptyResourcesError };
@@ -0,0 +1,27 @@
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
+ * Union type of all conversion errors.
9
+ *
10
+ * @see {@link EmptyDomainsError}
11
+ * @see {@link EmptyResourcesError}
12
+ * @see {@link InvalidDeclarativeRuleError}
13
+ * @see {@link UnsupportedModifierError}
14
+ * @see {@link UnsupportedRegexpError}
15
+ */
16
+ type ConversionError = EmptyDomainsError | EmptyResourcesError | InvalidDeclarativeRuleError | UnsupportedModifierError | UnsupportedRegexpError;
17
+ /**
18
+ * Type guard for {@link ConversionError}.
19
+ *
20
+ * @param error The error to check.
21
+ *
22
+ * @returns `true` if the error is a {@link ConversionError}, `false` otherwise.
23
+ */
24
+ declare function isConversionError(error: unknown): error is ConversionError;
25
+
26
+ export { EmptyDomainsError, EmptyResourcesError, InvalidDeclarativeRuleError, UnsupportedModifierError, UnsupportedRegexpError, isConversionError };
27
+ export type { ConversionError };
@@ -0,0 +1,30 @@
1
+ import { DeclarativeRule } from '../../declarative-rule/declarative-rule.js';
2
+ import { Rule } from '../../rule/rule.js';
3
+
4
+ /**
5
+ * Describes abstract error when declarative rule is invalid.
6
+ */
7
+ declare abstract class InvalidDeclarativeRuleError extends Error {
8
+ /**
9
+ * {@link Rule} that is invalid.
10
+ */
11
+ rule: Rule;
12
+ /**
13
+ * {@link DeclarativeRule} that is invalid.
14
+ */
15
+ declarativeRule: DeclarativeRule;
16
+ /**
17
+ * Describes a reason of the error.
18
+ */
19
+ reason?: string;
20
+ /**
21
+ * Describes abstract error when declarative rule is invalid.
22
+ *
23
+ * @param message Message of error.
24
+ * @param rule {@link Rule}.
25
+ * @param declarativeRule {@link DeclarativeRule}.
26
+ */
27
+ constructor(message: string, rule: Rule, declarativeRule: DeclarativeRule);
28
+ }
29
+
30
+ export { InvalidDeclarativeRuleError };
@@ -0,0 +1,20 @@
1
+ import { Rule } from '../../rule/rule.js';
2
+
3
+ /**
4
+ * Describes an error when a source network rule contains some of the unsupported modifiers.
5
+ */
6
+ declare class UnsupportedModifierError extends Error {
7
+ /**
8
+ * {@link Rule} related to this error.
9
+ */
10
+ rule: Rule;
11
+ /**
12
+ * Describes an error when a source network rule contains some of the unsupported modifiers.
13
+ *
14
+ * @param message Message of error.
15
+ * @param rule {@link Rule}.
16
+ */
17
+ constructor(message: string, rule: Rule);
18
+ }
19
+
20
+ export { UnsupportedModifierError };
@@ -0,0 +1,23 @@
1
+ import { DeclarativeRule } from '../../declarative-rule/declarative-rule.js';
2
+ import { Rule } from '../../rule/rule.js';
3
+ import { InvalidDeclarativeRuleError } from './invalid-declarative-rule-error.js';
4
+
5
+ /**
6
+ * Describes an error when the converted rule contains an unsupported RE2 regexp syntax error.
7
+ *
8
+ * @see {@link InvalidDeclarativeRuleError} parent class.
9
+ * @see https://github.com/google/re2/wiki/Syntax
10
+ */
11
+ declare class UnsupportedRegexpError extends InvalidDeclarativeRuleError {
12
+ /**
13
+ * Describes an error when the converted rule contains an unsupported RE2 regexp syntax error.
14
+ *
15
+ * @param message Message of error.
16
+ * @param rule {@link Rule}.
17
+ * @param declarativeRule {@link DeclarativeRule}.
18
+ * @param reason Describes a reason of the error.
19
+ */
20
+ constructor(message: string, rule: Rule, declarativeRule: DeclarativeRule, reason?: string);
21
+ }
22
+
23
+ export { UnsupportedRegexpError };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describes error when maximum number of rules is equal or less than `0`.
3
+ */
4
+ declare class EmptyOrNegativeNumberOfRulesError extends Error {
5
+ /**
6
+ * Describes error when maximum number of rules is equal or less than `0`.
7
+ *
8
+ * @param message Message of error.
9
+ */
10
+ constructor(message: string);
11
+ }
12
+
13
+ export { EmptyOrNegativeNumberOfRulesError };
@@ -0,0 +1,23 @@
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
+ * Union type of converter options errors.
7
+ *
8
+ * @see {@link EmptyOrNegativeNumberOfRulesError}
9
+ * @see {@link NegativeNumberOfRulesError}
10
+ * @see {@link ResourcesPathError}
11
+ */
12
+ type ConverterOptionsError = EmptyOrNegativeNumberOfRulesError | NegativeNumberOfRulesError | ResourcesPathError;
13
+ /**
14
+ * Type guard for {@link ConverterOptionsError}.
15
+ *
16
+ * @param error The error to check.
17
+ *
18
+ * @returns `true` if the error is a {@link ConverterOptionsError}, `false` otherwise.
19
+ */
20
+ declare function isConverterOptionsError(error: unknown): error is ConverterOptionsError;
21
+
22
+ export { EmptyOrNegativeNumberOfRulesError, NegativeNumberOfRulesError, ResourcesPathError, isConverterOptionsError };
23
+ export type { ConverterOptionsError };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describes error when maximum number of rules is less than `0`.
3
+ */
4
+ declare class NegativeNumberOfRulesError extends Error {
5
+ /**
6
+ * Describes error when maximum number of rules is less than `0`.
7
+ *
8
+ * @param message Message of error.
9
+ */
10
+ constructor(message: string);
11
+ }
12
+
13
+ export { NegativeNumberOfRulesError };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Describes error when the resources path does not start with a slash or it ends with a slash.
3
+ */
4
+ declare class ResourcesPathError extends Error {
5
+ /**
6
+ * Describes error when the resources path does not start with a slash or it ends with a slash.
7
+ *
8
+ * @param message Message of error.
9
+ */
10
+ constructor(message: string);
11
+ }
12
+
13
+ export { ResourcesPathError };
@@ -0,0 +1,27 @@
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
+ * Union type of all limitation errors.
9
+ *
10
+ * @see {@link MaxScannedRulesError}
11
+ * @see {@link TooManyError}
12
+ * @see {@link TooManyRegexpRulesError}
13
+ * @see {@link TooManyRulesError}
14
+ * @see {@link TooManyUnsafeRulesError}
15
+ */
16
+ type LimitationError = MaxScannedRulesError | TooManyError | TooManyRegexpRulesError | TooManyRulesError | TooManyUnsafeRulesError;
17
+ /**
18
+ * Type guard for {@link LimitationError}.
19
+ *
20
+ * @param error The error to check.
21
+ *
22
+ * @returns `true` if the error is a {@link LimitationError}, `false` otherwise.
23
+ */
24
+ declare function isLimitationError(error: unknown): error is LimitationError;
25
+
26
+ export { MaxScannedRulesError, TooManyError, TooManyRegexpRulesError, TooManyRulesError, TooManyUnsafeRulesError, isLimitationError };
27
+ export type { LimitationError };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Describes an error when the maximum number of rules is reached and some rules are skipped from scanning.
3
+ */
4
+ declare class MaxScannedRulesError extends Error {
5
+ /**
6
+ * Line index of the filter from which the rules are skipped.
7
+ */
8
+ lineIndex: number;
9
+ /**
10
+ * Describes an error when the maximum number of rules is reached and some rules are skipped from scanning.
11
+ *
12
+ * @param message Message of error.
13
+ * @param lineIndex Line index of the filter from which the rules are skipped.
14
+ */
15
+ constructor(message: string, lineIndex: number);
16
+ }
17
+
18
+ export { MaxScannedRulesError };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @typedef {import('../../ruleset/source-map').Source} Source
3
+ */
4
+ /**
5
+ * Describes an error when the maximum number of something is reached.
6
+ *
7
+ * Note: This class is intended to be extended by more specific error classes.
8
+ */
9
+ declare abstract class TooManyError extends Error {
10
+ /**
11
+ * List of excluded source (important!) {@link Source} rules ids.
12
+ */
13
+ excludedRulesIds: number[];
14
+ /**
15
+ * Number of maximum rules.
16
+ */
17
+ numberOfMaximumRules: number;
18
+ /**
19
+ * Number of excluded declarative rules.
20
+ */
21
+ numberOfExcludedDeclarativeRules: number;
22
+ /**
23
+ * Describes an error when the maximum number of something is reached.
24
+ *
25
+ * @param message Message of error.
26
+ * @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
27
+ * @param numberOfMaximumRules Number of maximum rules.
28
+ * @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
29
+ */
30
+ constructor(message: string, excludedRulesIds: number[], numberOfMaximumRules: number, numberOfExcludedDeclarativeRules: number);
31
+ }
32
+
33
+ export { TooManyError };
@@ -0,0 +1,21 @@
1
+ import { TooManyError } from './too-many-error.js';
2
+
3
+ /**
4
+ * @typedef {import('../../ruleset/source-map').Source} Source
5
+ */
6
+ /**
7
+ * Describes an error when the maximum number of regexp rules is reached.
8
+ */
9
+ declare class TooManyRegexpRulesError extends TooManyError {
10
+ /**
11
+ * Describes an error when the maximum number of regexp rules is reached.
12
+ *
13
+ * @param message Message of error.
14
+ * @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
15
+ * @param numberOfMaximumRules Number of maximum rules.
16
+ * @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
17
+ */
18
+ constructor(message: string, excludedRulesIds: number[], numberOfMaximumRules: number, numberOfExcludedDeclarativeRules: number);
19
+ }
20
+
21
+ export { TooManyRegexpRulesError };
@@ -0,0 +1,21 @@
1
+ import { TooManyError } from './too-many-error.js';
2
+
3
+ /**
4
+ * @typedef {import('../../ruleset/source-map').Source} Source
5
+ */
6
+ /**
7
+ * Describes an error when the maximum number of rules is reached.
8
+ */
9
+ declare class TooManyRulesError extends TooManyError {
10
+ /**
11
+ * Describes an error when the maximum number of rules is reached.
12
+ *
13
+ * @param message Message of error.
14
+ * @param excludedRulesIds List of excluded source (important!) {@link Source} rules ids.
15
+ * @param numberOfMaximumRules Number of maximum rules.
16
+ * @param numberOfExcludedDeclarativeRules Number of excluded declarative rules.
17
+ */
18
+ constructor(message: string, excludedRulesIds: number[], numberOfMaximumRules: number, numberOfExcludedDeclarativeRules: number);
19
+ }
20
+
21
+ export { TooManyRulesError };