@adguard/agtree 1.1.2 → 1.1.4

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/dist/agtree.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * AGTree v1.1.2 (build date: Mon, 14 Aug 2023 13:52:06 GMT)
2
+ * AGTree v1.1.4 (build date: Wed, 30 Aug 2023 10:02:46 GMT)
3
3
  * (c) 2023 AdGuard Software Ltd.
4
4
  * Released under the MIT license
5
5
  * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
@@ -60,9 +60,8 @@ declare const enum AdblockSyntax {
60
60
  declare const ADG_SCRIPTLET_MASK = "//scriptlet";
61
61
  declare const UBO_SCRIPTLET_MASK = "js";
62
62
  declare const MODIFIERS_SEPARATOR = ",";
63
- declare const MODIFIER_EXCEPTION_MARKER = "~";
64
63
  declare const MODIFIER_ASSIGN_OPERATOR = "=";
65
- declare const DOMAIN_EXCEPTION_MARKER = "~";
64
+ declare const NEGATION_MARKER = "~";
66
65
  /**
67
66
  * Classic domain separator.
68
67
  *
@@ -72,9 +71,9 @@ declare const DOMAIN_EXCEPTION_MARKER = "~";
72
71
  * example.com,~example.org##.ads
73
72
  * ```
74
73
  */
75
- declare const CLASSIC_DOMAIN_SEPARATOR = ",";
74
+ declare const COMMA_DOMAIN_LIST_SEPARATOR = ",";
76
75
  /**
77
- * Modifier domain separator.
76
+ * Modifier separator for $app, $denyallow, $domain, $method.
78
77
  *
79
78
  * @example
80
79
  * ```adblock
@@ -82,7 +81,7 @@ declare const CLASSIC_DOMAIN_SEPARATOR = ",";
82
81
  * ads.js^$script,domains=example.com|~example.org
83
82
  * ```
84
83
  */
85
- declare const MODIFIER_DOMAIN_SEPARATOR = "|";
84
+ declare const PIPE_MODIFIER_SEPARATOR = "|";
86
85
  declare const HINT_MARKER = "!+";
87
86
  declare const NETWORK_RULE_EXCEPTION_MARKER = "@@";
88
87
  declare const NETWORK_RULE_SEPARATOR = "$";
@@ -161,6 +160,25 @@ declare const enum RuleCategory {
161
160
  */
162
161
  Network = "Network"
163
162
  }
163
+ /**
164
+ * Represents similar types of modifiers values
165
+ * which may be separated by a comma `,` (only for DomainList) or a pipe `|`.
166
+ */
167
+ declare const enum ListNodeType {
168
+ AppList = "AppList",
169
+ DomainList = "DomainList",
170
+ MethodList = "MethodList",
171
+ StealthOptionList = "StealthOptionList"
172
+ }
173
+ /**
174
+ * Represents child items for {@link ListNodeType}.
175
+ */
176
+ declare const enum ListItemNodeType {
177
+ App = "App",
178
+ Domain = "Domain",
179
+ Method = "Method",
180
+ StealthOption = "StealthOption"
181
+ }
164
182
  /**
165
183
  * Represents possible comment types.
166
184
  */
@@ -703,24 +721,82 @@ interface Modifier extends Node {
703
721
  */
704
722
  value?: Value;
705
723
  }
724
+ /**
725
+ * Represents the separator used for various modifier values.
726
+ *
727
+ * @example
728
+ * `||example.com^$app=com.test1.app|TestApp.exe`
729
+ */
730
+ type PipeSeparator = typeof PIPE_MODIFIER_SEPARATOR;
731
+ /**
732
+ * Represents the separator used for basic rules domain list.
733
+ *
734
+ * @example
735
+ * `example.com,example.org###banner`
736
+ */
737
+ type CommaSeparator = typeof COMMA_DOMAIN_LIST_SEPARATOR;
706
738
  /**
707
739
  * Represents the separator used in a domain list.
708
740
  *
709
741
  * @example
710
- * "," for the classic domain list, and "|" for the "domain" modifier parameter
742
+ * - `,` — for the classic domain list,
743
+ * - `|` — for the $domain modifier value
744
+ */
745
+ type DomainListSeparator = CommaSeparator | PipeSeparator;
746
+ /**
747
+ * Common interface for a list item of $app, $denyallow, $domain, $method
748
+ * which have similar syntax.
711
749
  */
712
- type DomainListSeparator = typeof CLASSIC_DOMAIN_SEPARATOR | typeof MODIFIER_DOMAIN_SEPARATOR;
750
+ interface ListItem extends Node {
751
+ type: ListItemNodeType;
752
+ /**
753
+ * Value of the node.
754
+ */
755
+ value: string;
756
+ /**
757
+ * If the value is an negated.
758
+ *
759
+ * @example
760
+ * `~example.com` is negated, but `example.com` is not. `~` is the exception marker here.
761
+ */
762
+ exception: boolean;
763
+ }
713
764
  /**
714
- * Represents a list of domains
765
+ * Represents an element of the app list — $app.
766
+ */
767
+ interface App extends ListItem {
768
+ type: ListItemNodeType.App;
769
+ }
770
+ /**
771
+ * Represents an element of the domain list — $domain, $denyallow.
772
+ */
773
+ interface Domain extends ListItem {
774
+ type: ListItemNodeType.Domain;
775
+ }
776
+ /**
777
+ * Represents an element of the method list — $method.
778
+ */
779
+ interface Method extends ListItem {
780
+ type: ListItemNodeType.Method;
781
+ }
782
+ /**
783
+ * Represents an element of the stealth option list — $stealth.
784
+ */
785
+ interface StealthOption extends ListItem {
786
+ type: ListItemNodeType.StealthOption;
787
+ }
788
+ /**
789
+ * Represents a list of domains.
790
+ * Needed for $domain and $denyallow.
715
791
  *
716
792
  * @example
717
- * `example.com,~example.net`.
793
+ * `example.com,~example.net` or `example.com|~example.net`
718
794
  */
719
795
  interface DomainList extends Node {
720
796
  /**
721
797
  * Type of the node. Basically, the idea is that each main AST part should have a type
722
798
  */
723
- type: 'DomainList';
799
+ type: ListNodeType.DomainList;
724
800
  /**
725
801
  * Separator used in the domain list.
726
802
  */
@@ -731,21 +807,67 @@ interface DomainList extends Node {
731
807
  children: Domain[];
732
808
  }
733
809
  /**
734
- * Represents an element of the domain list (a domain).
810
+ * Represents a list of apps.
811
+ * Needed for $app.
812
+ *
813
+ * @example
814
+ * `Example.exe|com.example.osx`.
735
815
  */
736
- interface Domain extends Node {
737
- type: 'Domain';
816
+ interface AppList extends Node {
738
817
  /**
739
- * Domain name
818
+ * Type of the node. Basically, the idea is that each main AST part should have a type
740
819
  */
741
- value: string;
820
+ type: ListNodeType.AppList;
742
821
  /**
743
- * If the domain is an exception.
744
- *
745
- * @example
746
- * `~example.com` is an exception, but `example.com` is not. `~` is the exception marker here.
822
+ * Separator used in the app list.
747
823
  */
748
- exception: boolean;
824
+ separator: PipeSeparator;
825
+ /**
826
+ * List of apps
827
+ */
828
+ children: App[];
829
+ }
830
+ /**
831
+ * Represents a list of methods.
832
+ * Needed for $method.
833
+ *
834
+ * @example
835
+ * `get|post|put`.
836
+ */
837
+ interface MethodList extends Node {
838
+ /**
839
+ * Type of the node. Basically, the idea is that each main AST part should have a type
840
+ */
841
+ type: ListNodeType.MethodList;
842
+ /**
843
+ * Separator used in the method list.
844
+ */
845
+ separator: PipeSeparator;
846
+ /**
847
+ * List of methods
848
+ */
849
+ children: Method[];
850
+ }
851
+ /**
852
+ * Represents a list of stealth options.
853
+ * Needed for $stealth.
854
+ *
855
+ * @example
856
+ * `referrer|ip`.
857
+ */
858
+ interface StealthOptionList extends Node {
859
+ /**
860
+ * Type of the node. Basically, the idea is that each main AST part should have a type
861
+ */
862
+ type: ListNodeType.StealthOptionList;
863
+ /**
864
+ * Separator used in the stealth option list.
865
+ */
866
+ separator: PipeSeparator;
867
+ /**
868
+ * List of stealth options
869
+ */
870
+ children: StealthOption[];
749
871
  }
750
872
  /**
751
873
  * Represents a CSS injection body.
@@ -1398,6 +1520,25 @@ declare class CosmeticRuleParser {
1398
1520
  static generate(ast: AnyCosmeticRule): string;
1399
1521
  }
1400
1522
 
1523
+ /**
1524
+ * `AppListParser` is responsible for parsing an app list.
1525
+ *
1526
+ * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#app-modifier}
1527
+ */
1528
+ declare class AppListParser {
1529
+ /**
1530
+ * Parses an app list which items are separated by `|`,
1531
+ * e.g. `Example.exe|com.example.osx`.
1532
+ *
1533
+ * @param raw Raw app list
1534
+ * @param loc Location of the app list in the rule. If not set, the default location is used.
1535
+ *
1536
+ * @returns App list AST.
1537
+ * @throws An {@link AdblockSyntaxError} if the app list is syntactically invalid.
1538
+ */
1539
+ static parse(raw: string, loc?: Location): AppList;
1540
+ }
1541
+
1401
1542
  /**
1402
1543
  * `DomainListParser` is responsible for parsing a domain list.
1403
1544
  *
@@ -1411,22 +1552,62 @@ declare class DomainListParser {
1411
1552
  /**
1412
1553
  * Parses a domain list, eg. `example.com,example.org,~example.org`
1413
1554
  *
1414
- * @param raw Raw domain list
1415
- * @param separator Separator character
1416
- * @param loc Location of the domain list
1417
- * @returns Domain list AST
1418
- * @throws If the domain list is syntactically invalid
1555
+ * @param raw Raw domain list.
1556
+ * @param separator Separator character.
1557
+ * @param loc Location of the domain list in the rule. If not set, the default location is used.
1558
+ *
1559
+ * @returns Domain list AST.
1560
+ * @throws An {@link AdblockSyntaxError} if the domain list is syntactically invalid.
1419
1561
  */
1420
1562
  static parse(raw: string, separator?: DomainListSeparator, loc?: Location): DomainList;
1421
1563
  /**
1422
1564
  * Converts a domain list AST to a string.
1423
1565
  *
1424
- * @param ast Domain list AST
1425
- * @returns Raw string
1566
+ * @param ast Domain list AST.
1567
+ *
1568
+ * @returns Raw string.
1426
1569
  */
1427
1570
  static generate(ast: DomainList): string;
1428
1571
  }
1429
1572
 
1573
+ /**
1574
+ * `MethodListParser` is responsible for parsing a method list.
1575
+ *
1576
+ * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#method-modifier}
1577
+ */
1578
+ declare class MethodListParser {
1579
+ /**
1580
+ * Parses a method list which items are separated by `|`,
1581
+ * e.g. `get|post|put`.
1582
+ *
1583
+ * @param raw Raw method list
1584
+ * @param loc Location of the method list in the rule. If not set, the default location is used.
1585
+ *
1586
+ * @returns Method list AST.
1587
+ * @throws An {@link AdblockSyntaxError} if the method list is syntactically invalid.
1588
+ */
1589
+ static parse(raw: string, loc?: Location): MethodList;
1590
+ }
1591
+
1592
+ /**
1593
+ * `StealthOptionListParser` is responsible for parsing a list of stealth options.
1594
+ *
1595
+ * @see {@link https://adguard.app/kb/general/ad-filtering/create-own-filters/#stealth-modifier}
1596
+ */
1597
+ declare class StealthOptionListParser {
1598
+ /**
1599
+ * Parses a stealth option list which items are separated by `|`,
1600
+ * e.g. `dpi|ip`.
1601
+ *
1602
+ * @param raw Raw list of stealth options.
1603
+ * @param loc Location of the stealth option list in the rule. If not set, the default location is used.
1604
+ *
1605
+ * @returns Stealth option list AST.
1606
+ * @throws An {@link AdblockSyntaxError} if the stealth option list is syntactically invalid.
1607
+ */
1608
+ static parse(raw: string, loc?: Location): StealthOptionList;
1609
+ }
1610
+
1430
1611
  /**
1431
1612
  * `FilterListParser` is responsible for parsing a whole adblock filter list (list of rules).
1432
1613
  * It is a wrapper around `RuleParser` which parses each line separately.
@@ -1801,22 +1982,23 @@ declare class RuleConversionError extends Error {
1801
1982
  constructor(message: string);
1802
1983
  }
1803
1984
 
1804
- /**
1805
- * @file Validator for modifiers.
1806
- */
1807
-
1808
1985
  /**
1809
1986
  * Result of modifier validation:
1810
- * - `{ ok: true }` for valid and _fully supported_ modifier;
1811
- * - `{ ok: true, warn: <deprecation notice> }` for valid
1987
+ * - `{ valid: true }` for valid and _fully supported_ modifier;
1988
+ * - `{ valid: true, warn: <deprecation notice> }` for valid
1812
1989
  * and _still supported but deprecated_ modifier;
1813
- * - otherwise `{ ok: true, error: <invalidity reason> }`
1990
+ * - otherwise `{ valid: true, error: <invalidity reason> }`
1814
1991
  */
1815
1992
  type ValidationResult = {
1816
- ok: boolean;
1993
+ valid: boolean;
1817
1994
  error?: string;
1818
1995
  warn?: string;
1819
1996
  };
1997
+
1998
+ /**
1999
+ * @file Validator for modifiers.
2000
+ */
2001
+
1820
2002
  /**
1821
2003
  * Modifier validator class.
1822
2004
  */
@@ -2370,9 +2552,6 @@ declare class CssTree {
2370
2552
  static generateFunctionValue(node: FunctionNode): string;
2371
2553
  }
2372
2554
 
2373
- /**
2374
- * @file Utility functions for domain and hostname validation.
2375
- */
2376
2555
  declare class DomainUtils {
2377
2556
  /**
2378
2557
  * Check if the input is a valid domain or hostname.
@@ -2560,6 +2739,20 @@ declare class QuoteUtils {
2560
2739
  * @returns String without quotes
2561
2740
  */
2562
2741
  static removeQuotes(string: string): string;
2742
+ /**
2743
+ * Wraps given `strings` with `quote` (defaults to single quote `'`)
2744
+ * and joins them with `separator` (defaults to comma+space `, `).
2745
+ *
2746
+ * @param strings Strings to quote and join.
2747
+ * @param quoteType Quote to use.
2748
+ * @param separator Separator to use.
2749
+ *
2750
+ * @returns String with joined items.
2751
+ *
2752
+ * @example
2753
+ * ['abc', 'def']: strings[] -> "'abc', 'def'": string
2754
+ */
2755
+ static quoteAndJoinStrings(strings: string[], quoteType?: QuoteType, separator?: string): string;
2563
2756
  }
2564
2757
 
2565
2758
  /**
@@ -2590,4 +2783,4 @@ declare const FORBIDDEN_CSS_FUNCTIONS: Set<string>;
2590
2783
  */
2591
2784
  declare const version: string;
2592
2785
 
2593
- export { ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyOperator, AnyRule, CLASSIC_DOMAIN_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, CssTree, CssTreeNodeType, CssTreeParserContext, DOMAIN_EXCEPTION_MARKER, Domain, DomainList, DomainListParser, DomainListSeparator, DomainUtils, EXT_CSS_LEGACY_ATTRIBUTES, EXT_CSS_PSEUDO_CLASSES, ElementHidingRule, ElementHidingRuleBody, EmptyRule, ExpressionOperatorNode, ExpressionParenthesisNode, ExpressionVariableNode, FORBIDDEN_CSS_FUNCTIONS, FilterList, FilterListConverter, FilterListParser, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, JsInjectionRule, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, METADATA_HEADERS, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MODIFIER_DOMAIN_SEPARATOR, MODIFIER_EXCEPTION_MARKER, MetadataCommentRule, MetadataCommentRuleParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, Node, NotImplementedError, PREPROCESSOR_MARKER, Parameter, ParameterList, ParameterListParser, PreProcessorCommentRule, PreProcessorCommentRuleParser, QuoteType, QuoteUtils, RegExpUtils, RuleBase, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, UBO_SCRIPTLET_MASK, Value, VariableTable, locRange, modifierValidator, shiftLoc, version };
2786
+ export { ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyOperator, AnyRule, AppListParser, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, CssTree, CssTreeNodeType, CssTreeParserContext, Domain, DomainList, DomainListParser, DomainListSeparator, DomainUtils, EXT_CSS_LEGACY_ATTRIBUTES, EXT_CSS_PSEUDO_CLASSES, ElementHidingRule, ElementHidingRuleBody, EmptyRule, ExpressionOperatorNode, ExpressionParenthesisNode, ExpressionVariableNode, FORBIDDEN_CSS_FUNCTIONS, FilterList, FilterListConverter, FilterListParser, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, JsInjectionRule, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, METADATA_HEADERS, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, Node, NotImplementedError, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, Parameter, ParameterList, ParameterListParser, PreProcessorCommentRule, PreProcessorCommentRuleParser, QuoteType, QuoteUtils, RegExpUtils, RuleBase, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, StealthOptionListParser, UBO_SCRIPTLET_MASK, Value, VariableTable, locRange, modifierValidator, shiftLoc, version };