@adguard/agtree 2.0.0-alpha.0 → 2.0.0

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 v2.0.0-alpha.0 (build date: Mon, 29 Jul 2024 13:43:09 GMT)
2
+ * AGTree v2.0.0 (build date: Thu, 15 Aug 2024 15:06:58 GMT)
3
3
  * (c) 2024 Adguard Software Ltd.
4
4
  * Released under the MIT license
5
5
  * https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
@@ -132,9 +132,13 @@ declare const IF = "if";
132
132
  declare const INCLUDE = "include";
133
133
 
134
134
  /**
135
- * Represents possible logical expression operators.
135
+ * Possible operators in the logical expression.
136
136
  */
137
- type AnyOperator = '&&' | '||' | '!';
137
+ declare const enum OperatorValue {
138
+ Not = "!",
139
+ And = "&&",
140
+ Or = "||"
141
+ }
138
142
  /**
139
143
  * Represents possible new line types.
140
144
  */
@@ -392,7 +396,7 @@ interface ExpressionVariableNode extends Node {
392
396
  */
393
397
  interface ExpressionOperatorNode extends Node {
394
398
  type: 'Operator';
395
- operator: AnyOperator;
399
+ operator: OperatorValue;
396
400
  left: AnyExpressionNode;
397
401
  right?: AnyExpressionNode;
398
402
  }
@@ -1498,16 +1502,23 @@ declare class OutputByteBuffer extends ByteBuffer {
1498
1502
  */
1499
1503
  private offset;
1500
1504
  /**
1501
- * Size of the shared buffer for encoding strings.
1505
+ * Size of the shared buffer for encoding strings in bytes.
1506
+ * This is a divisor of ByteBuffer.CHUNK_SIZE and experience shows that this value works optimally.
1507
+ * This is sufficient for most strings that occur in filter lists (we checked average string length in popular
1508
+ * filter lists).
1502
1509
  */
1503
1510
  private static readonly ENCODER_BUFFER_SIZE;
1504
1511
  /**
1505
- * Threshold for using a shared buffer for encoding strings.
1512
+ * Length threshold for using a shared buffer for encoding strings.
1513
+ * This temp buffer is needed because we write the short strings in it
1514
+ * (so there is no need to constantly allocate a new buffer).
1515
+ * The reason for dividing ENCODER_BUFFER_SIZE by 4 is to ensure that the encoded string fits in the buffer,
1516
+ * if we also take into account the worst possible case (each character is encoded with 4 bytes).
1506
1517
  */
1507
1518
  private static readonly SHORT_STRING_THRESHOLD;
1508
1519
  /**
1509
1520
  * Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
1510
- * 0x1FFFFFFF means 32 bits minus 3 bits, because the last bit in each byte is a flag indicating
1521
+ * 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits because the last bit in each byte is a flag indicating
1511
1522
  * if there are more bytes (except for the last byte).
1512
1523
  */
1513
1524
  static MAX_OPTIMIZED_UINT: number;
@@ -3263,6 +3274,16 @@ declare class RuleConverter extends RuleConverterBase {
3263
3274
  * @throws If the rule is invalid or cannot be converted
3264
3275
  */
3265
3276
  static convertToAdg(rule: AnyRule): NodeConversionResult<AnyRule>;
3277
+ /**
3278
+ * Converts an adblock filtering rule to uBlock Origin format, if possible.
3279
+ *
3280
+ * @param rule Rule node to convert
3281
+ * @returns An object which follows the {@link NodeConversionResult} interface. Its `result` property contains
3282
+ * the array of converted rule nodes, and its `isConverted` flag indicates whether the original rule was converted.
3283
+ * If the rule was not converted, the result array will contain the original node with the same object reference
3284
+ * @throws If the rule is invalid or cannot be converted
3285
+ */
3286
+ static convertToUbo(rule: AnyRule): NodeConversionResult<AnyRule>;
3266
3287
  }
3267
3288
 
3268
3289
  /**
@@ -4074,4 +4095,4 @@ declare const getSpecificPlatformName: (platform: SpecificPlatform) => string;
4074
4095
  */
4075
4096
  declare const AGTREE_VERSION: string;
4076
4097
 
4077
- 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, AGTREE_VERSION, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyNetworkRule, AnyOperator, AnyRule, AppListParser, BINARY_SCHEMA_VERSION, BinarySchemaMismatchError, ByteBuffer, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, CompatibilityTable, CompatibilityTableRow, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, 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, GenericPlatform, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HostRule, HostRuleParser, HostnameList, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, InputByteBuffer, JsInjectionRule, KNOWN_METADATA_HEADERS, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, NetworkRuleType, Node, NotImplementedError, OutputByteBuffer, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, ParameterList, ParameterListParser, ParserOptions, Position, PositionProvider, PreProcessorCommentRule, PreProcessorCommentRuleParser, ProductRecords, QuoteType, QuoteUtils, RawFilterListConverter, RawRuleConverter, RegExpUtils, RowByProduct, RowsByProduct, RuleBase, RuleCategorizer, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, SpecificPlatform, StealthOptionListParser, TextEncoderPolyfillResult, UBO_SCRIPTLET_MASK, Value, VariableTable, decodeTextPolyfill, defaultParserOptions, encodeIntoPolyfill, getPlatformId, getSpecificPlatformName, isGenericPlatform, modifierValidator, modifiersCompatibilityTable, parseRawPlatforms, redirectsCompatibilityTable, scriptletsCompatibilityTable };
4098
+ 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, AGTREE_VERSION, AdblockSyntax, AdblockSyntaxError, Agent, AgentCommentRule, AgentCommentRuleParser, AgentParser, AnyCommentRule, AnyCosmeticRule, AnyExpressionNode, AnyNetworkRule, AnyRule, AppListParser, BINARY_SCHEMA_VERSION, BinarySchemaMismatchError, ByteBuffer, COMMA_DOMAIN_LIST_SEPARATOR, CommentBase, CommentMarker, CommentRule, CommentRuleParser, CommentRuleType, CompatibilityTable, CompatibilityTableRow, ConfigCommentRule, ConfigCommentRuleParser, CosmeticRule, CosmeticRuleParser, CosmeticRuleSeparator, CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils, CosmeticRuleType, CssInjectionRule, CssInjectionRuleBody, 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, GenericPlatform, HINT_MARKER, Hint, HintCommentRule, HintCommentRuleParser, HintParser, HostRule, HostRuleParser, HostnameList, HtmlFilteringRule, HtmlFilteringRuleBody, IF, INCLUDE, InputByteBuffer, JsInjectionRule, KNOWN_METADATA_HEADERS, Location, LocationRange, LogicalExpressionParser, LogicalExpressionUtils, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, MetadataCommentRule, MetadataCommentRuleParser, MethodListParser, Modifier, ModifierList, ModifierListParser, ModifierParser, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, NetworkRule, NetworkRuleParser, NetworkRuleType, Node, NotImplementedError, OutputByteBuffer, PIPE_MODIFIER_SEPARATOR, PREPROCESSOR_MARKER, ParameterList, ParameterListParser, ParserOptions, Position, PositionProvider, PreProcessorCommentRule, PreProcessorCommentRuleParser, ProductRecords, QuoteType, QuoteUtils, RawFilterListConverter, RawRuleConverter, RegExpUtils, RowByProduct, RowsByProduct, RuleBase, RuleCategorizer, RuleCategory, RuleConversionError, RuleConverter, RuleParser, SAFARI_CB_AFFINITY, SPECIAL_REGEX_SYMBOLS, ScriptletInjectionRule, ScriptletInjectionRuleBody, SpecificPlatform, StealthOptionListParser, TextEncoderPolyfillResult, UBO_SCRIPTLET_MASK, Value, VariableTable, decodeTextPolyfill, defaultParserOptions, encodeIntoPolyfill, getPlatformId, getSpecificPlatformName, isGenericPlatform, modifierValidator, modifiersCompatibilityTable, parseRawPlatforms, redirectsCompatibilityTable, scriptletsCompatibilityTable };