@getodk/xpath 0.1.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.
Files changed (104) hide show
  1. package/README.md +158 -0
  2. package/dist/.vite/manifest.json +21 -0
  3. package/dist/context/Context.d.ts +27 -0
  4. package/dist/context/EvaluationContext.d.ts +48 -0
  5. package/dist/evaluations/BooleanEvaluation.d.ts +12 -0
  6. package/dist/evaluations/DateTimeLikeEvaluation.d.ts +23 -0
  7. package/dist/evaluations/Evaluation.d.ts +18 -0
  8. package/dist/evaluations/EvaluationType.d.ts +7 -0
  9. package/dist/evaluations/LocationPathEvaluation.d.ts +113 -0
  10. package/dist/evaluations/NodeEvaluation.d.ts +22 -0
  11. package/dist/evaluations/NumberEvaluation.d.ts +12 -0
  12. package/dist/evaluations/StringEvaluation.d.ts +13 -0
  13. package/dist/evaluations/ValueEvaluation.d.ts +24 -0
  14. package/dist/evaluator/Evaluator.d.ts +41 -0
  15. package/dist/evaluator/NamespaceResolver.d.ts +48 -0
  16. package/dist/evaluator/expression/AbsoluteLocationPathExpressionEvaluator.d.ts +7 -0
  17. package/dist/evaluator/expression/BinaryExpressionEvaluator.d.ts +11 -0
  18. package/dist/evaluator/expression/BooleanBinaryExpressionEvaluator.d.ts +17 -0
  19. package/dist/evaluator/expression/ExpressionEvaluator.d.ts +8 -0
  20. package/dist/evaluator/expression/FilterPathExpressionEvaluator.d.ts +12 -0
  21. package/dist/evaluator/expression/FunctionCallExpressionEvaluator.d.ts +16 -0
  22. package/dist/evaluator/expression/LocationPathEvaluator.d.ts +23 -0
  23. package/dist/evaluator/expression/LocationPathExpressionEvaluator.d.ts +8 -0
  24. package/dist/evaluator/expression/NumberExpressionEvaluator.d.ts +10 -0
  25. package/dist/evaluator/expression/NumberLiteralExpressionEvaluator.d.ts +8 -0
  26. package/dist/evaluator/expression/NumericBinaryExpressionEvaluator.d.ts +12 -0
  27. package/dist/evaluator/expression/RelativeLocationPathExpressionEvaluator.d.ts +7 -0
  28. package/dist/evaluator/expression/StringExpressionEvaluator.d.ts +10 -0
  29. package/dist/evaluator/expression/StringLiteralExpressionEvaluator.d.ts +8 -0
  30. package/dist/evaluator/expression/UnaryExpressionEvaluator.d.ts +10 -0
  31. package/dist/evaluator/expression/UnionExpressionEvaluator.d.ts +11 -0
  32. package/dist/evaluator/expression/factory.d.ts +5 -0
  33. package/dist/evaluator/functions/BooleanFunction.d.ts +6 -0
  34. package/dist/evaluator/functions/FunctionAlias.d.ts +4 -0
  35. package/dist/evaluator/functions/FunctionImplementation.d.ts +39 -0
  36. package/dist/evaluator/functions/FunctionLibrary.d.ts +21 -0
  37. package/dist/evaluator/functions/FunctionLibraryCollection.d.ts +41 -0
  38. package/dist/evaluator/functions/NodeSetFunction.d.ts +7 -0
  39. package/dist/evaluator/functions/NumberFunction.d.ts +6 -0
  40. package/dist/evaluator/functions/StringFunction.d.ts +6 -0
  41. package/dist/evaluator/functions/TypedFunctionImplementation.d.ts +8 -0
  42. package/dist/evaluator/functions/index.d.ts +1 -0
  43. package/dist/evaluator/result/BaseResult.d.ts +34 -0
  44. package/dist/evaluator/result/BooleanResult.d.ts +12 -0
  45. package/dist/evaluator/result/NodeSetResult.d.ts +55 -0
  46. package/dist/evaluator/result/NumberResult.d.ts +12 -0
  47. package/dist/evaluator/result/PrimitiveResult.d.ts +12 -0
  48. package/dist/evaluator/result/ResultType.d.ts +13 -0
  49. package/dist/evaluator/result/StringResult.d.ts +12 -0
  50. package/dist/evaluator/result/index.d.ts +7 -0
  51. package/dist/evaluator/step/Step.d.ts +129 -0
  52. package/dist/expressionParser-1Kzq3bIy.js +2356 -0
  53. package/dist/expressionParser-1Kzq3bIy.js.map +1 -0
  54. package/dist/expressionParser.d.ts +2 -0
  55. package/dist/expressionParser.js +2 -0
  56. package/dist/expressionParser.js.map +1 -0
  57. package/dist/functions/_shared/number.d.ts +11 -0
  58. package/dist/functions/_shared/string.d.ts +3 -0
  59. package/dist/functions/enketo/index.d.ts +2 -0
  60. package/dist/functions/fn/boolean.d.ts +8 -0
  61. package/dist/functions/fn/index.d.ts +2 -0
  62. package/dist/functions/fn/node-set.d.ts +11 -0
  63. package/dist/functions/fn/number.d.ts +7 -0
  64. package/dist/functions/fn/string.d.ts +13 -0
  65. package/dist/functions/javarosa/index.d.ts +2 -0
  66. package/dist/functions/javarosa/string.d.ts +2 -0
  67. package/dist/functions/xforms/boolean.d.ts +6 -0
  68. package/dist/functions/xforms/datetime.d.ts +10 -0
  69. package/dist/functions/xforms/geo.d.ts +3 -0
  70. package/dist/functions/xforms/index.d.ts +2 -0
  71. package/dist/functions/xforms/node-set.d.ts +8 -0
  72. package/dist/functions/xforms/number.d.ts +29 -0
  73. package/dist/functions/xforms/select.d.ts +6 -0
  74. package/dist/functions/xforms/string.d.ts +10 -0
  75. package/dist/index.d.ts +3 -0
  76. package/dist/index.js +31976 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/lib/collections/sort.d.ts +1 -0
  79. package/dist/lib/datetime/coercion.d.ts +4 -0
  80. package/dist/lib/datetime/constants.d.ts +6 -0
  81. package/dist/lib/datetime/functions.d.ts +5 -0
  82. package/dist/lib/datetime/predicates.d.ts +5 -0
  83. package/dist/lib/dom/assertions.d.ts +4 -0
  84. package/dist/lib/dom/predicates.d.ts +11 -0
  85. package/dist/lib/dom/sort.d.ts +1 -0
  86. package/dist/lib/dom/traversal.d.ts +21 -0
  87. package/dist/lib/dom/types.d.ts +21 -0
  88. package/dist/lib/dom/xml.d.ts +1 -0
  89. package/dist/lib/iterators/Reiterable.d.ts +15 -0
  90. package/dist/lib/iterators/common.d.ts +17 -0
  91. package/dist/lib/iterators/index.d.ts +3 -0
  92. package/dist/lib/regex/escape.d.ts +1 -0
  93. package/dist/shared/constants.d.ts +13 -0
  94. package/dist/shared/index.d.ts +2 -0
  95. package/dist/shared/interface.d.ts +33 -0
  96. package/dist/static/grammar/ExpressionParser.d.ts +27 -0
  97. package/dist/static/grammar/SyntaxLanguage.d.ts +5 -0
  98. package/dist/static/grammar/SyntaxNode.d.ts +144 -0
  99. package/dist/static/grammar/SyntaxTree.d.ts +6 -0
  100. package/dist/static/grammar/TreeSitterXPathParser.d.ts +38 -0
  101. package/dist/static/grammar/type-names.d.ts +89 -0
  102. package/dist/xforms/XFormsItextTranslations.d.ts +26 -0
  103. package/dist/xforms/XFormsXPathEvaluator.d.ts +18 -0
  104. package/package.json +76 -0
@@ -0,0 +1,8 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import type { AbsoluteLocationPathNode, AnyExprNode, FilterPathExprNode, RelativeLocationPathNode } from '../../static/grammar/SyntaxNode.ts';
4
+ export type ExpressionNode = AbsoluteLocationPathNode | AnyExprNode | FilterPathExprNode | RelativeLocationPathNode;
5
+ export interface ExpressionEvaluator {
6
+ readonly syntaxNode: ExpressionNode;
7
+ evaluate(context: EvaluationContext): Evaluation;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { FilterPathExprNode } from '../../static/grammar/SyntaxNode.ts';
3
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
4
+ import { LocationPathEvaluator } from './LocationPathEvaluator.ts';
5
+ import type { LocationPathExpressionEvaluator } from './LocationPathExpressionEvaluator.ts';
6
+ export declare class FilterPathExpressionEvaluator extends LocationPathEvaluator implements ExpressionEvaluator {
7
+ readonly syntaxNode: FilterPathExprNode;
8
+ readonly filterExpression: LocationPathExpressionEvaluator;
9
+ readonly hasSteps: boolean;
10
+ constructor(syntaxNode: FilterPathExprNode);
11
+ evaluateNodes(context: EvaluationContext): Iterable<Node>;
12
+ }
@@ -0,0 +1,16 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import type { FunctionCallNode } from '../../static/grammar/SyntaxNode.ts';
4
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
5
+ interface FunctionCallName {
6
+ readonly prefix: string | null;
7
+ readonly localName: string;
8
+ }
9
+ export declare class FunctionCallExpressionEvaluator implements ExpressionEvaluator {
10
+ readonly syntaxNode: FunctionCallNode;
11
+ readonly name: FunctionCallName;
12
+ readonly argumentExpressions: readonly ExpressionEvaluator[];
13
+ constructor(syntaxNode: FunctionCallNode);
14
+ evaluate(context: EvaluationContext): Evaluation;
15
+ }
16
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { AbsoluteLocationPathNode, FilterPathExprNode, RelativeLocationPathNode } from '../../static/grammar/SyntaxNode.ts';
3
+ import { type PathExprSteps } from '../step/Step.ts';
4
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
5
+ import { LocationPathExpressionEvaluator } from './LocationPathExpressionEvaluator.ts';
6
+ type LocationPathNode = AbsoluteLocationPathNode | FilterPathExprNode | RelativeLocationPathNode;
7
+ interface LocationPathExpressionOptions {
8
+ readonly isAbsolute: boolean;
9
+ readonly isFilterExprContext: boolean;
10
+ readonly isRoot: boolean;
11
+ readonly isSelf: boolean;
12
+ }
13
+ export declare class LocationPathEvaluator extends LocationPathExpressionEvaluator implements ExpressionEvaluator {
14
+ readonly syntaxNode: LocationPathNode;
15
+ protected isAbsolute: boolean;
16
+ protected isFilterExprContext: boolean;
17
+ protected isRoot: boolean;
18
+ protected isSelf: boolean;
19
+ protected steps: PathExprSteps;
20
+ constructor(syntaxNode: LocationPathNode, options: LocationPathExpressionOptions);
21
+ evaluateNodes(context: EvaluationContext): Iterable<Node>;
22
+ }
23
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import type { ExpressionEvaluator, ExpressionNode } from './ExpressionEvaluator.ts';
4
+ export declare abstract class LocationPathExpressionEvaluator implements ExpressionEvaluator {
5
+ abstract readonly syntaxNode: ExpressionNode;
6
+ abstract evaluateNodes(context: EvaluationContext): Iterable<Node>;
7
+ evaluate(context: EvaluationContext): Evaluation<'NODE'>;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import { NumberEvaluation } from '../../evaluations/NumberEvaluation.ts';
3
+ import type { ExpressionEvaluator, ExpressionNode } from './ExpressionEvaluator.ts';
4
+ export declare abstract class NumberExpressionEvaluator<ConstValue extends number | null = null> implements ExpressionEvaluator {
5
+ protected readonly constValue: ConstValue;
6
+ constructor(constValue: ConstValue);
7
+ abstract readonly syntaxNode: ExpressionNode;
8
+ abstract evaluateNumber(context: EvaluationContext): number;
9
+ evaluate(context: EvaluationContext): NumberEvaluation;
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { NumberNode } from '../../static/grammar/SyntaxNode.ts';
2
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
3
+ import { NumberExpressionEvaluator } from './NumberExpressionEvaluator.ts';
4
+ export declare class NumberLiteralExpressionEvaluator extends NumberExpressionEvaluator<number> implements ExpressionEvaluator {
5
+ readonly syntaxNode: NumberNode;
6
+ constructor(syntaxNode: NumberNode);
7
+ evaluateNumber(): number;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import { NumberEvaluation } from '../../evaluations/NumberEvaluation.ts';
3
+ import type { AdditionExprNode, DivisionExprNode, ModuloExprNode, MultiplicationExprNode, SubtractionExprNode } from '../../static/grammar/SyntaxNode.ts';
4
+ import { BinaryExpressionEvaluator } from './BinaryExpressionEvaluator.ts';
5
+ type NumericBinaryExprNode = AdditionExprNode | DivisionExprNode | ModuloExprNode | MultiplicationExprNode | SubtractionExprNode;
6
+ type NumericOperation<Node extends NumericBinaryExprNode> = Node extends AdditionExprNode ? 'addition' : Node extends DivisionExprNode ? 'division' : Node extends ModuloExprNode ? 'modulo' : Node extends MultiplicationExprNode ? 'multiplication' : Node extends SubtractionExprNode ? 'subtraction' : never;
7
+ export declare class NumericBinaryExpressionEvaluator<Node extends NumericBinaryExprNode> extends BinaryExpressionEvaluator<Node> {
8
+ readonly operation: NumericOperation<Node>;
9
+ constructor(node: Node);
10
+ evaluate(context: EvaluationContext): NumberEvaluation;
11
+ }
12
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { RelativeLocationPathNode } from '../../static/grammar/SyntaxNode.ts';
2
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
3
+ import { LocationPathEvaluator } from './LocationPathEvaluator.ts';
4
+ export declare class RelativeLocationPathExpressionEvaluator extends LocationPathEvaluator implements ExpressionEvaluator {
5
+ readonly syntaxNode: RelativeLocationPathNode;
6
+ constructor(syntaxNode: RelativeLocationPathNode);
7
+ }
@@ -0,0 +1,10 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import { StringEvaluation } from '../../evaluations/StringEvaluation.ts';
3
+ import type { ExpressionEvaluator, ExpressionNode } from './ExpressionEvaluator.ts';
4
+ export declare abstract class StringExpressionEvaluator<ConstValue extends string | null = null> implements ExpressionEvaluator {
5
+ protected readonly constValue: ConstValue;
6
+ constructor(constValue: ConstValue);
7
+ abstract readonly syntaxNode: ExpressionNode;
8
+ abstract evaluateString(context: EvaluationContext): string;
9
+ evaluate(context: EvaluationContext): StringEvaluation;
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { LiteralNode } from '../../static/grammar/SyntaxNode.ts';
2
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
3
+ import { StringExpressionEvaluator } from './StringExpressionEvaluator.ts';
4
+ export declare class StringLiteralExpressionEvaluator extends StringExpressionEvaluator<string> implements ExpressionEvaluator {
5
+ readonly syntaxNode: LiteralNode;
6
+ constructor(syntaxNode: LiteralNode);
7
+ evaluateString(): string;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { UnaryExprNode } from '../../static/grammar/SyntaxNode.ts';
3
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
4
+ import { NumberExpressionEvaluator } from './NumberExpressionEvaluator.ts';
5
+ export declare class UnaryExpressionEvaluator extends NumberExpressionEvaluator {
6
+ readonly syntaxNode: UnaryExprNode;
7
+ readonly operand: ExpressionEvaluator;
8
+ constructor(syntaxNode: UnaryExprNode);
9
+ evaluateNumber(context: EvaluationContext): number;
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { EvaluationContext } from '../../context/EvaluationContext.ts';
2
+ import type { UnionExprNode } from '../../static/grammar/SyntaxNode.ts';
3
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
4
+ import { LocationPathExpressionEvaluator } from './LocationPathExpressionEvaluator.ts';
5
+ export declare class UnionExpressionEvaluator extends LocationPathExpressionEvaluator {
6
+ readonly syntaxNode: UnionExprNode;
7
+ readonly lhs: ExpressionEvaluator;
8
+ readonly rhs: ExpressionEvaluator;
9
+ constructor(syntaxNode: UnionExprNode);
10
+ evaluateNodes(context: EvaluationContext): Iterable<Node>;
11
+ }
@@ -0,0 +1,5 @@
1
+ import type { AnyExprNode, ArgumentNode, ExprNode, XPathNode } from '../../static/grammar/SyntaxNode.ts';
2
+ import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
3
+ type EvaluableExprNode = AnyExprNode | ArgumentNode | ExprNode | XPathNode;
4
+ export declare const createExpression: (syntaxNode: EvaluableExprNode) => ExpressionEvaluator;
5
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { FunctionSignature } from './FunctionImplementation.ts';
2
+ import type { TypedFunctionCallable } from './TypedFunctionImplementation.ts';
3
+ import { TypedFunctionImplementation } from './TypedFunctionImplementation.ts';
4
+ export declare class BooleanFunction<Length extends number> extends TypedFunctionImplementation<boolean, Length> {
5
+ constructor(localName: string, signature: FunctionSignature<Length>, call: TypedFunctionCallable<boolean>);
6
+ }
@@ -0,0 +1,4 @@
1
+ import { FunctionImplementation } from './FunctionImplementation.ts';
2
+ export declare class FunctionAlias<Length extends number> extends FunctionImplementation<Length> {
3
+ constructor(localName: string, baseImplementation: FunctionImplementation<Length>);
4
+ }
@@ -0,0 +1,39 @@
1
+ import type { IterableReadonlyTuple } from '../../../../common/types/collections/IterableReadonlyTuple.ts';
2
+ import type { Context } from '../../context/Context.ts';
3
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
4
+ import type { EvaluationType } from '../../evaluations/EvaluationType.ts';
5
+ import { LocationPathEvaluation } from '../../evaluations/LocationPathEvaluation.ts';
6
+ export declare class UnknownFunctionError extends Error {
7
+ constructor(functionName: string);
8
+ }
9
+ export declare class InvalidArgumentError extends Error {
10
+ constructor(argumentIndex: number, parameter: Parameter | null);
11
+ }
12
+ export type ParameterArityType = 'optional' | 'required' | 'variadic';
13
+ export type ParameterTypeHint = 'any' | 'boolean' | 'node' | 'number' | 'string';
14
+ export interface Parameter {
15
+ readonly arityType: ParameterArityType;
16
+ readonly typeHint?: ParameterTypeHint;
17
+ }
18
+ export type FunctionSignature<Length extends number> = IterableReadonlyTuple<Parameter, Length>;
19
+ export interface EvaluableArgument {
20
+ evaluate(context: Context): Evaluation<EvaluationType>;
21
+ }
22
+ export type ValidArguments<Arguments extends readonly EvaluableArgument[], IsValid extends boolean> = [true] extends [IsValid] ? Arguments : never;
23
+ interface FunctionArity {
24
+ readonly min: number;
25
+ readonly max: number;
26
+ }
27
+ export type FunctionCallable = <Arguments extends readonly EvaluableArgument[]>(context: LocationPathEvaluation, args: Arguments) => Evaluation;
28
+ export declare class FunctionImplementation<Length extends number> {
29
+ readonly localName: string;
30
+ readonly signature: FunctionSignature<Length>;
31
+ readonly arity: FunctionArity;
32
+ protected readonly callable: FunctionCallable;
33
+ constructor(localName: string, signature: FunctionSignature<Length>, runtimeImplementation: FunctionCallable | FunctionImplementation<any>);
34
+ call(context: LocationPathEvaluation, args: readonly EvaluableArgument[]): Evaluation;
35
+ protected validateArguments<Arguments extends readonly EvaluableArgument[]>(args: Arguments): asserts args is ValidArguments<Arguments, true>;
36
+ }
37
+ export interface AnyFunctionImplementation extends FunctionImplementation<number> {
38
+ }
39
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
2
+ import { LocationPathEvaluation } from '../../evaluations/LocationPathEvaluation.ts';
3
+ import type { AnyFunctionImplementation, EvaluableArgument, FunctionImplementation } from './FunctionImplementation.ts';
4
+ type NamespaceURI = string | null;
5
+ type LocalName = string;
6
+ interface QualifiedName {
7
+ readonly namespaceURI: NamespaceURI;
8
+ readonly localName: LocalName;
9
+ }
10
+ export interface LibraryFunction extends AnyFunctionImplementation {
11
+ readonly qualifiedName: QualifiedName;
12
+ }
13
+ export declare class FunctionLibrary {
14
+ readonly namespaceURI: string;
15
+ protected readonly implementations: Map<LocalName, LibraryFunction>;
16
+ constructor(namespaceURI: string, entries: readonly AnyFunctionImplementation[]);
17
+ has(localName: LocalName): boolean;
18
+ call(localName: LocalName, context: LocationPathEvaluation, args: readonly EvaluableArgument[]): Evaluation;
19
+ getImplementation(localName: LocalName): FunctionImplementation<number> | null;
20
+ }
21
+ export {};
@@ -0,0 +1,41 @@
1
+ import type { Context } from '../../context/Context.ts';
2
+ import type { FunctionImplementation } from './FunctionImplementation.ts';
3
+ import type { FunctionLibrary } from './FunctionLibrary.ts';
4
+ interface BaseFunctionNameLookup {
5
+ readonly namespaceURI?: string | null;
6
+ readonly prefix?: string | null;
7
+ readonly localName: string;
8
+ }
9
+ interface NamespacedFunctionNameLookup extends BaseFunctionNameLookup {
10
+ readonly namespaceURI: string | null;
11
+ }
12
+ interface PrefixedFunctionNameLookup extends BaseFunctionNameLookup {
13
+ readonly prefix: string | null;
14
+ }
15
+ type FunctionNameLookup = NamespacedFunctionNameLookup | PrefixedFunctionNameLookup;
16
+ interface FunctionLibraryCollectionOptions {
17
+ /**
18
+ * @default ['http://www.w3.org/2005/xpath-functions']
19
+ */
20
+ readonly defaultNamespaceURIs?: readonly string[];
21
+ }
22
+ export declare class FunctionLibraryCollection {
23
+ /**
24
+ * Default function libraries determine, for a given Evaluator instance and
25
+ * its corresponding FunctionLibraryCollection instance, which function calls
26
+ * may be resolved without a prefix.
27
+ *
28
+ * Unprefixed functions are looked up by local name in each successive default
29
+ * library until one is matched. For example, when both the `xf` and `fn`
30
+ * libraries are defaults (in that order), `number` will resolve to the `xf`
31
+ * namespace because it provides a function with `localName: number`
32
+ * (overriding the default `fn:number`), whereas `string` will resolve to the
33
+ * `fn` namespace, because the `xf` namespace does not override it.
34
+ */
35
+ protected readonly defaultFunctionLibraries: readonly FunctionLibrary[];
36
+ protected readonly namespacedFunctionLibraries: ReadonlyMap<string, FunctionLibrary>;
37
+ constructor(functionLibraries: Iterable<FunctionLibrary>, options?: FunctionLibraryCollectionOptions);
38
+ getDefaultImplementation(localName: string): FunctionImplementation<number> | null;
39
+ getImplementation(context: Context, name: FunctionNameLookup): FunctionImplementation<any> | null;
40
+ }
41
+ export {};
@@ -0,0 +1,7 @@
1
+ import { LocationPathEvaluation } from '../../evaluations/LocationPathEvaluation.ts';
2
+ import type { EvaluableArgument, FunctionSignature } from './FunctionImplementation.ts';
3
+ import { FunctionImplementation } from './FunctionImplementation.ts';
4
+ export type NodeSetFunctionCallable = <Arguments extends readonly EvaluableArgument[]>(context: LocationPathEvaluation, args: Arguments) => Iterable<Node>;
5
+ export declare class NodeSetFunction<Length extends number> extends FunctionImplementation<Length> {
6
+ constructor(localName: string, signature: FunctionSignature<Length>, call: NodeSetFunctionCallable);
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { FunctionSignature } from './FunctionImplementation.ts';
2
+ import type { TypedFunctionCallable } from './TypedFunctionImplementation.ts';
3
+ import { TypedFunctionImplementation } from './TypedFunctionImplementation.ts';
4
+ export declare class NumberFunction<Length extends number> extends TypedFunctionImplementation<number, Length> {
5
+ constructor(localName: string, signature: FunctionSignature<Length>, call: TypedFunctionCallable<number>);
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { FunctionSignature } from './FunctionImplementation.ts';
2
+ import type { TypedFunctionCallable } from './TypedFunctionImplementation.ts';
3
+ import { TypedFunctionImplementation } from './TypedFunctionImplementation.ts';
4
+ export declare class StringFunction<Length extends number> extends TypedFunctionImplementation<string, Length> {
5
+ constructor(localName: string, signature: FunctionSignature<Length>, call: TypedFunctionCallable<string>);
6
+ }
@@ -0,0 +1,8 @@
1
+ import type { Evaluation } from '../../evaluations/Evaluation';
2
+ import { LocationPathEvaluation } from '../../evaluations/LocationPathEvaluation.ts';
3
+ import type { EvaluableArgument, FunctionSignature } from './FunctionImplementation.ts';
4
+ import { FunctionImplementation } from './FunctionImplementation.ts';
5
+ export type TypedFunctionCallable<Type> = <Arguments extends readonly EvaluableArgument[]>(context: LocationPathEvaluation, args: Arguments) => Type;
6
+ export declare class TypedFunctionImplementation<Type, Length extends number> extends FunctionImplementation<Length> {
7
+ protected constructor(localName: string, TypedResult: new (context: LocationPathEvaluation, value: Type) => Evaluation, signature: FunctionSignature<Length>, call: TypedFunctionCallable<Type>);
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ declare const NODE_SET_RESULT_TYPE = -1;
2
+ export type NodeSetResultType = typeof NODE_SET_RESULT_TYPE;
3
+ export type PrimitiveResultType = BaseResult['BOOLEAN_TYPE'] | BaseResult['NUMBER_TYPE'] | BaseResult['STRING_TYPE'];
4
+ type BaseResultType = NodeSetResultType | PrimitiveResultType;
5
+ export declare abstract class BaseResult {
6
+ protected abstract readonly type: BaseResultType;
7
+ protected abstract readonly nodes: Iterable<Node> | null;
8
+ abstract readonly isIntermediateResult: boolean;
9
+ static readonly ANY_TYPE: 0;
10
+ static readonly NUMBER_TYPE: 1;
11
+ static readonly STRING_TYPE: 2;
12
+ static readonly BOOLEAN_TYPE: 3;
13
+ static readonly UNORDERED_NODE_ITERATOR_TYPE: 4;
14
+ static readonly ORDERED_NODE_ITERATOR_TYPE: 5;
15
+ static readonly UNORDERED_NODE_SNAPSHOT_TYPE: 6;
16
+ static readonly ORDERED_NODE_SNAPSHOT_TYPE: 7;
17
+ static readonly ANY_UNORDERED_NODE_TYPE: 8;
18
+ static readonly FIRST_ORDERED_NODE_TYPE: 9;
19
+ readonly ANY_TYPE: 0;
20
+ readonly NUMBER_TYPE: 1;
21
+ readonly STRING_TYPE: 2;
22
+ readonly BOOLEAN_TYPE: 3;
23
+ readonly UNORDERED_NODE_ITERATOR_TYPE: 4;
24
+ readonly ORDERED_NODE_ITERATOR_TYPE: 5;
25
+ readonly UNORDERED_NODE_SNAPSHOT_TYPE: 6;
26
+ readonly ORDERED_NODE_SNAPSHOT_TYPE: 7;
27
+ readonly ANY_UNORDERED_NODE_TYPE: 8;
28
+ readonly FIRST_ORDERED_NODE_TYPE: 9;
29
+ protected static readonly NODE_SET_RESULT_TYPE = -1;
30
+ abstract readonly booleanValue: boolean;
31
+ abstract readonly numberValue: number;
32
+ abstract readonly stringValue: string;
33
+ }
34
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { XPathResult } from '../../shared/index.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import { PrimitiveResult } from './PrimitiveResult.ts';
4
+ export declare class BooleanResult extends PrimitiveResult implements XPathResult {
5
+ readonly isIntermediateResult = false;
6
+ protected readonly type: 3;
7
+ protected readonly nodes: null;
8
+ readonly booleanValue: boolean;
9
+ readonly numberValue: number;
10
+ readonly stringValue: string;
11
+ constructor(evaluation: Evaluation);
12
+ }
@@ -0,0 +1,55 @@
1
+ import type { XPathResult, XPathResultType } from '../../shared/index.ts';
2
+ import { Reiterable } from '../../lib/iterators/index.ts';
3
+ import type { NodeSetResultType } from './BaseResult.ts';
4
+ import { BaseResult } from './BaseResult.ts';
5
+ interface ComputedNodeSetResult {
6
+ readonly computedBooleanValue: boolean;
7
+ readonly computedNumberValue: number;
8
+ readonly computedStringValue: string;
9
+ }
10
+ export declare abstract class NodeSetResult extends BaseResult implements XPathResult {
11
+ protected readonly value: Iterable<Node>;
12
+ readonly isIntermediateResult: boolean;
13
+ protected readonly type: NodeSetResultType;
14
+ protected readonly nodes: Iterable<Node>;
15
+ protected computedBooleanValue: boolean | null;
16
+ protected computedNumberValue: number | null;
17
+ protected computedStringValue: string | null;
18
+ get booleanValue(): boolean;
19
+ get numberValue(): number;
20
+ get stringValue(): string;
21
+ protected computedSnapshotValue: readonly Node[] | null;
22
+ abstract readonly resultType: XPathResultType;
23
+ abstract readonly invalidIteratorState: boolean;
24
+ abstract readonly singleNodeValue: Node | null;
25
+ abstract readonly snapshotLength: number;
26
+ constructor(value: Iterable<Node>);
27
+ protected compute(): ComputedNodeSetResult;
28
+ abstract iterateNext(): Node | null;
29
+ abstract snapshotItem(index: number): Node | null;
30
+ }
31
+ export declare class NodeSetSnapshotResult extends NodeSetResult {
32
+ readonly resultType: XPathResultType;
33
+ readonly snapshot: readonly Node[];
34
+ readonly snapshotIterator: IterableIterator<Node>;
35
+ readonly snapshotLength: number;
36
+ readonly invalidIteratorState: boolean;
37
+ readonly singleNodeValue: Node | null;
38
+ constructor(resultType: XPathResultType, nodes: Iterable<Node>);
39
+ iterateNext(): Node | null;
40
+ snapshotItem(index: number): Node | null;
41
+ }
42
+ export declare class NodeSetIteratorResult extends NodeSetResult {
43
+ readonly resultType: XPathResultType;
44
+ protected activeIterator: IterableIterator<Node> | null;
45
+ protected nodes: Reiterable<Node>;
46
+ readonly invalidIteratorState: boolean;
47
+ protected computedSingleNodeValue: Node | null | undefined;
48
+ get singleNodeValue(): Node | null;
49
+ get snapshotLength(): number;
50
+ constructor(resultType: XPathResultType, nodes: Iterable<Node>);
51
+ protected activateIterator(): IterableIterator<Node>;
52
+ iterateNext(): Node | null;
53
+ snapshotItem(_index: number): Node | null;
54
+ }
55
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { XPathResult } from '../../shared/index.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import { PrimitiveResult } from './PrimitiveResult.ts';
4
+ export declare class NumberResult extends PrimitiveResult implements XPathResult {
5
+ readonly isIntermediateResult = false;
6
+ protected readonly type: 1;
7
+ protected readonly nodes: null;
8
+ readonly booleanValue: boolean;
9
+ readonly numberValue: number;
10
+ readonly stringValue: string;
11
+ constructor(evaluation: Evaluation);
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { XPathResult, XPathResultType } from '../../shared/index.ts';
2
+ import type { PrimitiveResultType } from './BaseResult.ts';
3
+ import { BaseResult } from './BaseResult.ts';
4
+ export declare abstract class PrimitiveResult extends BaseResult implements XPathResult {
5
+ protected abstract readonly type: PrimitiveResultType;
6
+ get resultType(): XPathResultType;
7
+ get singleNodeValue(): Node | null;
8
+ get snapshotLength(): number;
9
+ readonly invalidIteratorState = true;
10
+ iterateNext(): Node | null;
11
+ snapshotItem(_index?: number): Node | null;
12
+ }
@@ -0,0 +1,13 @@
1
+ export declare const ResultTypes: {
2
+ readonly BOOLEAN_TYPE: 3;
3
+ readonly NUMBER_TYPE: 1;
4
+ readonly STRING_TYPE: 2;
5
+ readonly UNORDERED_NODE_ITERATOR_TYPE: 4;
6
+ readonly ORDERED_NODE_ITERATOR_TYPE: 5;
7
+ readonly UNORDERED_NODE_SNAPSHOT_TYPE: 6;
8
+ readonly ORDERED_NODE_SNAPSHOT_TYPE: 7;
9
+ readonly ANY_UNORDERED_NODE_TYPE: 8;
10
+ readonly FIRST_ORDERED_NODE_TYPE: 9;
11
+ };
12
+ export type ResultTypes = typeof ResultTypes;
13
+ export type ResultType = ResultTypes[keyof ResultTypes];
@@ -0,0 +1,12 @@
1
+ import type { XPathResult } from '../../shared/index.ts';
2
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
3
+ import { PrimitiveResult } from './PrimitiveResult.ts';
4
+ export declare class StringResult extends PrimitiveResult implements XPathResult {
5
+ readonly isIntermediateResult = false;
6
+ protected readonly type: 2;
7
+ protected readonly nodes: null;
8
+ readonly booleanValue: boolean;
9
+ readonly numberValue: number;
10
+ readonly stringValue: string;
11
+ constructor(evaluation: Evaluation);
12
+ }
@@ -0,0 +1,7 @@
1
+ import type { Evaluation } from '../../evaluations/Evaluation.ts';
2
+ import type { XPathResultType } from '../../shared/index.ts';
3
+ import { BooleanResult } from './BooleanResult';
4
+ import { NodeSetIteratorResult, NodeSetSnapshotResult } from './NodeSetResult';
5
+ import { NumberResult } from './NumberResult';
6
+ import { StringResult } from './StringResult';
7
+ export declare const toXPathResult: (resultType: XPathResultType, evaluation: Evaluation) => BooleanResult | NodeSetSnapshotResult | NodeSetIteratorResult | NumberResult | StringResult;
@@ -0,0 +1,129 @@
1
+ import type { AbsoluteLocationPathNode, FilterPathExprNode, PredicateNode, RelativeLocationPathNode } from '../../static/grammar/SyntaxNode.ts';
2
+ type AxisType = 'ancestor-or-self' | 'ancestor' | 'attribute' | 'child' | 'descendant-or-self' | 'descendant' | 'following-sibling' | 'following' | 'namespace' | 'parent' | 'preceding-sibling' | 'preceding' | 'self';
3
+ type NodeType = '__NAMED__' | 'comment' | 'node' | 'processing-instruction' | 'text';
4
+ type StepType = 'NodeTypeTest' | 'ProcessingInstructionNameTest' | 'QualifiedNameTest' | 'NodeNameTest' | 'QualifiedWildcardTest' | 'UnqualifiedWildcardTest';
5
+ export declare abstract class BaseStep {
6
+ readonly axisType: AxisType | '__ROOT__';
7
+ abstract readonly stepType: StepType;
8
+ abstract readonly nodeType: NodeType;
9
+ abstract readonly localName: string | null | undefined;
10
+ abstract readonly prefix: string | null | undefined;
11
+ abstract readonly nodeName: string | undefined;
12
+ abstract readonly processingInstructionName: string | undefined;
13
+ abstract readonly predicates: readonly PredicateNode[];
14
+ constructor(axisType: AxisType | '__ROOT__');
15
+ }
16
+ export declare class RootContextStep extends BaseStep {
17
+ readonly axisType = "__ROOT__";
18
+ readonly stepType = "NodeTypeTest";
19
+ readonly nodeType = "node";
20
+ readonly localName: undefined;
21
+ readonly prefix: undefined;
22
+ readonly nodeName: undefined;
23
+ readonly processingInstructionName: undefined;
24
+ readonly predicates: readonly [];
25
+ constructor();
26
+ }
27
+ interface NonRootStep extends BaseStep {
28
+ readonly axisType: AxisType;
29
+ }
30
+ export declare class EvaluationContextNodeStep extends BaseStep implements NonRootStep {
31
+ readonly stepType = "NodeTypeTest";
32
+ readonly axisType = "self";
33
+ readonly nodeType = "node";
34
+ readonly localName: undefined;
35
+ readonly prefix: undefined;
36
+ readonly nodeName: undefined;
37
+ readonly processingInstructionName: undefined;
38
+ readonly predicates: readonly [];
39
+ constructor();
40
+ }
41
+ export declare class FilterExprContextNodeStep extends BaseStep implements NonRootStep {
42
+ readonly stepType = "NodeTypeTest";
43
+ readonly axisType = "self";
44
+ readonly nodeType = "node";
45
+ readonly localName: undefined;
46
+ readonly prefix: undefined;
47
+ readonly nodeName: undefined;
48
+ readonly processingInstructionName: undefined;
49
+ readonly predicates: readonly [];
50
+ constructor();
51
+ }
52
+ export type PathExprContextStep = EvaluationContextNodeStep | FilterExprContextNodeStep | RootContextStep;
53
+ type UnnamedNodeType = Exclude<NodeType, '__NAMED__'>;
54
+ export declare class NodeTypeTestStep extends BaseStep implements NonRootStep {
55
+ readonly axisType: AxisType;
56
+ readonly nodeType: UnnamedNodeType;
57
+ readonly predicates: readonly PredicateNode[];
58
+ readonly stepType = "NodeTypeTest";
59
+ readonly localName: undefined;
60
+ readonly prefix: undefined;
61
+ readonly nodeName: undefined;
62
+ readonly processingInstructionName: undefined;
63
+ constructor(axisType: AxisType, nodeType: UnnamedNodeType, predicates: readonly PredicateNode[]);
64
+ }
65
+ export declare abstract class BaseNameTestStep extends BaseStep implements NonRootStep {
66
+ abstract readonly stepType: Exclude<StepType, 'NodeTypeTest'>;
67
+ abstract readonly axisType: AxisType;
68
+ readonly nodeType = "__NAMED__";
69
+ }
70
+ export declare class ProcessingInstructionNameTestStep extends BaseStep implements NonRootStep {
71
+ readonly axisType: AxisType;
72
+ readonly processingInstructionName: string;
73
+ readonly predicates: readonly PredicateNode[];
74
+ readonly stepType = "ProcessingInstructionNameTest";
75
+ readonly localName: undefined;
76
+ readonly prefix: undefined;
77
+ readonly nodeName: undefined;
78
+ readonly nodeType = "processing-instruction";
79
+ constructor(axisType: AxisType, processingInstructionName: string, predicates: readonly PredicateNode[]);
80
+ }
81
+ export declare class QualifiedNameTestStep extends BaseNameTestStep {
82
+ readonly axisType: AxisType;
83
+ readonly prefix: string;
84
+ readonly localName: string;
85
+ readonly predicates: readonly PredicateNode[];
86
+ readonly stepType = "QualifiedNameTest";
87
+ readonly nodeName: undefined;
88
+ readonly processingInstructionName: undefined;
89
+ constructor(axisType: AxisType, prefix: string, localName: string, predicates: readonly PredicateNode[]);
90
+ }
91
+ export declare class NodeNameTestStep extends BaseNameTestStep {
92
+ readonly axisType: AxisType;
93
+ readonly nodeName: string;
94
+ readonly predicates: readonly PredicateNode[];
95
+ readonly stepType = "NodeNameTest";
96
+ readonly localName: undefined;
97
+ readonly prefix: undefined;
98
+ readonly processingInstructionName: undefined;
99
+ constructor(axisType: AxisType, nodeName: string, predicates: readonly PredicateNode[]);
100
+ }
101
+ export declare class QualifiedWildcardTestStep extends BaseNameTestStep {
102
+ readonly axisType: AxisType;
103
+ readonly prefix: string;
104
+ readonly predicates: readonly PredicateNode[];
105
+ readonly stepType = "QualifiedWildcardTest";
106
+ readonly localName: null;
107
+ readonly nodeName: undefined;
108
+ readonly processingInstructionName: undefined;
109
+ constructor(axisType: AxisType, prefix: string, predicates: readonly PredicateNode[]);
110
+ }
111
+ export declare class UnqualifiedWildcardTestStep extends BaseNameTestStep {
112
+ readonly axisType: AxisType;
113
+ readonly predicates: readonly PredicateNode[];
114
+ readonly stepType = "UnqualifiedWildcardTest";
115
+ readonly localName: null;
116
+ readonly prefix: null;
117
+ readonly nodeName: undefined;
118
+ readonly processingInstructionName: undefined;
119
+ constructor(axisType: AxisType, predicates: readonly PredicateNode[]);
120
+ }
121
+ export type NameTestStep = NodeNameTestStep | ProcessingInstructionNameTestStep | QualifiedNameTestStep | QualifiedWildcardTestStep | UnqualifiedWildcardTestStep;
122
+ export type AnyStep = NameTestStep | NodeTypeTestStep;
123
+ type AnyLocationPathExprNode = AbsoluteLocationPathNode | FilterPathExprNode | RelativeLocationPathNode;
124
+ type ContextualizedStep = Exclude<AnyStep, {
125
+ readonly axisType: '__ROOT__';
126
+ }>;
127
+ export type PathExprSteps = readonly [context: PathExprContextStep, ...steps: ContextualizedStep[]];
128
+ export declare const pathExprSteps: (syntaxNode: AnyLocationPathExprNode) => PathExprSteps;
129
+ export {};