@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.
- package/README.md +158 -0
- package/dist/.vite/manifest.json +21 -0
- package/dist/context/Context.d.ts +27 -0
- package/dist/context/EvaluationContext.d.ts +48 -0
- package/dist/evaluations/BooleanEvaluation.d.ts +12 -0
- package/dist/evaluations/DateTimeLikeEvaluation.d.ts +23 -0
- package/dist/evaluations/Evaluation.d.ts +18 -0
- package/dist/evaluations/EvaluationType.d.ts +7 -0
- package/dist/evaluations/LocationPathEvaluation.d.ts +113 -0
- package/dist/evaluations/NodeEvaluation.d.ts +22 -0
- package/dist/evaluations/NumberEvaluation.d.ts +12 -0
- package/dist/evaluations/StringEvaluation.d.ts +13 -0
- package/dist/evaluations/ValueEvaluation.d.ts +24 -0
- package/dist/evaluator/Evaluator.d.ts +41 -0
- package/dist/evaluator/NamespaceResolver.d.ts +48 -0
- package/dist/evaluator/expression/AbsoluteLocationPathExpressionEvaluator.d.ts +7 -0
- package/dist/evaluator/expression/BinaryExpressionEvaluator.d.ts +11 -0
- package/dist/evaluator/expression/BooleanBinaryExpressionEvaluator.d.ts +17 -0
- package/dist/evaluator/expression/ExpressionEvaluator.d.ts +8 -0
- package/dist/evaluator/expression/FilterPathExpressionEvaluator.d.ts +12 -0
- package/dist/evaluator/expression/FunctionCallExpressionEvaluator.d.ts +16 -0
- package/dist/evaluator/expression/LocationPathEvaluator.d.ts +23 -0
- package/dist/evaluator/expression/LocationPathExpressionEvaluator.d.ts +8 -0
- package/dist/evaluator/expression/NumberExpressionEvaluator.d.ts +10 -0
- package/dist/evaluator/expression/NumberLiteralExpressionEvaluator.d.ts +8 -0
- package/dist/evaluator/expression/NumericBinaryExpressionEvaluator.d.ts +12 -0
- package/dist/evaluator/expression/RelativeLocationPathExpressionEvaluator.d.ts +7 -0
- package/dist/evaluator/expression/StringExpressionEvaluator.d.ts +10 -0
- package/dist/evaluator/expression/StringLiteralExpressionEvaluator.d.ts +8 -0
- package/dist/evaluator/expression/UnaryExpressionEvaluator.d.ts +10 -0
- package/dist/evaluator/expression/UnionExpressionEvaluator.d.ts +11 -0
- package/dist/evaluator/expression/factory.d.ts +5 -0
- package/dist/evaluator/functions/BooleanFunction.d.ts +6 -0
- package/dist/evaluator/functions/FunctionAlias.d.ts +4 -0
- package/dist/evaluator/functions/FunctionImplementation.d.ts +39 -0
- package/dist/evaluator/functions/FunctionLibrary.d.ts +21 -0
- package/dist/evaluator/functions/FunctionLibraryCollection.d.ts +41 -0
- package/dist/evaluator/functions/NodeSetFunction.d.ts +7 -0
- package/dist/evaluator/functions/NumberFunction.d.ts +6 -0
- package/dist/evaluator/functions/StringFunction.d.ts +6 -0
- package/dist/evaluator/functions/TypedFunctionImplementation.d.ts +8 -0
- package/dist/evaluator/functions/index.d.ts +1 -0
- package/dist/evaluator/result/BaseResult.d.ts +34 -0
- package/dist/evaluator/result/BooleanResult.d.ts +12 -0
- package/dist/evaluator/result/NodeSetResult.d.ts +55 -0
- package/dist/evaluator/result/NumberResult.d.ts +12 -0
- package/dist/evaluator/result/PrimitiveResult.d.ts +12 -0
- package/dist/evaluator/result/ResultType.d.ts +13 -0
- package/dist/evaluator/result/StringResult.d.ts +12 -0
- package/dist/evaluator/result/index.d.ts +7 -0
- package/dist/evaluator/step/Step.d.ts +129 -0
- package/dist/expressionParser-1Kzq3bIy.js +2356 -0
- package/dist/expressionParser-1Kzq3bIy.js.map +1 -0
- package/dist/expressionParser.d.ts +2 -0
- package/dist/expressionParser.js +2 -0
- package/dist/expressionParser.js.map +1 -0
- package/dist/functions/_shared/number.d.ts +11 -0
- package/dist/functions/_shared/string.d.ts +3 -0
- package/dist/functions/enketo/index.d.ts +2 -0
- package/dist/functions/fn/boolean.d.ts +8 -0
- package/dist/functions/fn/index.d.ts +2 -0
- package/dist/functions/fn/node-set.d.ts +11 -0
- package/dist/functions/fn/number.d.ts +7 -0
- package/dist/functions/fn/string.d.ts +13 -0
- package/dist/functions/javarosa/index.d.ts +2 -0
- package/dist/functions/javarosa/string.d.ts +2 -0
- package/dist/functions/xforms/boolean.d.ts +6 -0
- package/dist/functions/xforms/datetime.d.ts +10 -0
- package/dist/functions/xforms/geo.d.ts +3 -0
- package/dist/functions/xforms/index.d.ts +2 -0
- package/dist/functions/xforms/node-set.d.ts +8 -0
- package/dist/functions/xforms/number.d.ts +29 -0
- package/dist/functions/xforms/select.d.ts +6 -0
- package/dist/functions/xforms/string.d.ts +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31976 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/collections/sort.d.ts +1 -0
- package/dist/lib/datetime/coercion.d.ts +4 -0
- package/dist/lib/datetime/constants.d.ts +6 -0
- package/dist/lib/datetime/functions.d.ts +5 -0
- package/dist/lib/datetime/predicates.d.ts +5 -0
- package/dist/lib/dom/assertions.d.ts +4 -0
- package/dist/lib/dom/predicates.d.ts +11 -0
- package/dist/lib/dom/sort.d.ts +1 -0
- package/dist/lib/dom/traversal.d.ts +21 -0
- package/dist/lib/dom/types.d.ts +21 -0
- package/dist/lib/dom/xml.d.ts +1 -0
- package/dist/lib/iterators/Reiterable.d.ts +15 -0
- package/dist/lib/iterators/common.d.ts +17 -0
- package/dist/lib/iterators/index.d.ts +3 -0
- package/dist/lib/regex/escape.d.ts +1 -0
- package/dist/shared/constants.d.ts +13 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/interface.d.ts +33 -0
- package/dist/static/grammar/ExpressionParser.d.ts +27 -0
- package/dist/static/grammar/SyntaxLanguage.d.ts +5 -0
- package/dist/static/grammar/SyntaxNode.d.ts +144 -0
- package/dist/static/grammar/SyntaxTree.d.ts +6 -0
- package/dist/static/grammar/TreeSitterXPathParser.d.ts +38 -0
- package/dist/static/grammar/type-names.d.ts +89 -0
- package/dist/xforms/XFormsItextTranslations.d.ts +26 -0
- package/dist/xforms/XFormsXPathEvaluator.d.ts +18 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# @getodk/xpath
|
|
2
|
+
|
|
3
|
+
An XPath evaluator, with intent to support:
|
|
4
|
+
|
|
5
|
+
- Full XPath 1.0 syntax and behavior
|
|
6
|
+
- Context-based extensibility of behavior beyond the XPath 1.0 function library
|
|
7
|
+
- [ODK XForms](https://getodk.github.io/xforms-spec/) XPath extensions
|
|
8
|
+
- Non-browser environments (provided a subset of standard DOM APIs)
|
|
9
|
+
- Minor accommodations for certain [Enketo](https://github.com/enketo/enketo/tree/main/packages/openrosa-xpath-evaluator) function aliases:
|
|
10
|
+
- `date-time` is an alias of `date`, which is assumed to be additive
|
|
11
|
+
- `format-date` function is an alias of `format-date-time`, which differs from the ODK XForms spec
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Install this package and its required peer dependencies with `npm` (or the equivalent command for your preferred package manager):
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @getodk/tree-sitter-xpath @getodk/xpath web-tree-sitter
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
To use `@getodk/xpath` at runtime, first create an `XFormsXPathEvaluator`
|
|
24
|
+
instance, specifying the XForm `rootNode`. Usage from that point is
|
|
25
|
+
API-compatible with the standard DOM [`evaluate`
|
|
26
|
+
method](https://developer.mozilla.org/en-US/docs/Web/API/XPathEvaluator/evaluate).
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { XFormsXPathEvaluator } from '@getodk/xpath';
|
|
30
|
+
|
|
31
|
+
// Given an XForms DOM document...
|
|
32
|
+
declare const xform: XMLDocument;
|
|
33
|
+
|
|
34
|
+
const evaluator = new XFormsXPathEvaluator({ rootNode: xform });
|
|
35
|
+
|
|
36
|
+
// A namespace resolver is optional, and the context node can be used (which is the default)
|
|
37
|
+
const nsResolver: XPathNSResolver = xform;
|
|
38
|
+
|
|
39
|
+
const result: XPathResult = evaluator.evaluate(
|
|
40
|
+
'/root/...',
|
|
41
|
+
xform,
|
|
42
|
+
nsResolver,
|
|
43
|
+
XPathResult.ORDERED_NODE_ITERATOR_TYPE
|
|
44
|
+
);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For typical XForms usage, `rootNode` will be either an XForm `XMLDocument` or its primary instance `Element`.
|
|
48
|
+
|
|
49
|
+
For XPath 1.0 functionality without XForms extension functions, you may use `Evaluator` the same way, and `rootNode` is optional:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { Evaluator } from '@getodk/xpath';
|
|
53
|
+
|
|
54
|
+
const evaluator = new Evaluator();
|
|
55
|
+
|
|
56
|
+
// ...
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
In either case, the `result` returned by `evaluate` is API-compatible with the standard DOM [`XPathResult`](https://developer.mozilla.org/en-US/docs/Web/API/XPathResult).
|
|
60
|
+
|
|
61
|
+
### XForms `itext` translations
|
|
62
|
+
|
|
63
|
+
`XFormsXPathEvaluator` supports the JavaRosa `itext` function (`jr:itext` by convention), as specified in ODK XForms, which says:
|
|
64
|
+
|
|
65
|
+
> Obtains an itext value for the provided reference in the active language from the `<itext>` block in the model.
|
|
66
|
+
|
|
67
|
+
This active language state is managed at the `XFormXPathEvaluator` instance level, with the default language (again as specified in ODK XForms) active on construction. You can access a form's available languages, and get or set the active language under the `XFormXPathEvaluator.translations` object.
|
|
68
|
+
|
|
69
|
+
Example:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const domParser = new DOMParser();
|
|
73
|
+
const xform: XMLDocument = domParser.parseFromString(
|
|
74
|
+
`<h:html>
|
|
75
|
+
<h:head>
|
|
76
|
+
<model>
|
|
77
|
+
<itext>
|
|
78
|
+
<translation lang="English" default="true()">
|
|
79
|
+
<text id="hello">
|
|
80
|
+
<value>hello</value>
|
|
81
|
+
</text>
|
|
82
|
+
</translation>
|
|
83
|
+
<translation lang="Español">
|
|
84
|
+
<text id="hello">
|
|
85
|
+
<value>hola</value>
|
|
86
|
+
</text>
|
|
87
|
+
</translation>
|
|
88
|
+
</itext>
|
|
89
|
+
</model>
|
|
90
|
+
</h:head>
|
|
91
|
+
<!-- ... -->
|
|
92
|
+
</h:html>`,
|
|
93
|
+
'text/xml'
|
|
94
|
+
);
|
|
95
|
+
const evaluator = new XFormsXPathEvaluator({ rootNode: xform });
|
|
96
|
+
|
|
97
|
+
evaluator.translations.getLanguages(); // ['English', 'Español']
|
|
98
|
+
evaluator.translations.getActiveLanguage(); // 'English'
|
|
99
|
+
evaluator.evaluate('jr:itext("hello")', xform, null, XPathResult.STRING_TYPE).stringValue; // 'hello'
|
|
100
|
+
|
|
101
|
+
evaluator.translations.setActiveLanguage('Español'); // 'Español'
|
|
102
|
+
evaluator.translations.getActiveLanguage(); // 'Español'
|
|
103
|
+
evaluator.evaluate('jr:itext("hello")', xform, null, XPathResult.STRING_TYPE).stringValue; // 'hola'
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
There are currently a few caveats to `jr:itext` use:
|
|
107
|
+
|
|
108
|
+
- `<itext>` and its translations are evaluated from the **document root** of the `rootNode` specified in `XFormsXPathEvaluator` options. As such:
|
|
109
|
+
|
|
110
|
+
- translations _will_ be resolved if a descendant `rootNode` (e.g. the XForm's primary `<instance>` element) is specified
|
|
111
|
+
|
|
112
|
+
- translations _will not_ be resolved for an XForm in an unusual DOM structure (e.g. a `DocumentFragment`, or in an arbitrary subtree of an unrelated document)
|
|
113
|
+
|
|
114
|
+
- Translations are treated as static, and cached during construction of `XFormsXPathEvaluator`. This is based on typical usage, wherein an XForm definition itself is expected to be static, but it will not (yet) support use cases like authoring an XForm definition.
|
|
115
|
+
|
|
116
|
+
- `<value form="...anything...">` is not yet supported. It's unclear what the interface for this usage might be.
|
|
117
|
+
|
|
118
|
+
- The interface for getting and setting language state is currently experimental pending integration experience, and may be changed in the future. The intent of this interface is to be relatively agnostic to outside state management, and to isolate this sort of stateful context from the XForm DOM, but that approach may also change.
|
|
119
|
+
|
|
120
|
+
### Convenience APIs
|
|
121
|
+
|
|
122
|
+
Both evaluator classes provide the following convenience methods:
|
|
123
|
+
|
|
124
|
+
- `evaluateBoolean(expression: string, options?: { contextNode?: Node }): boolean`
|
|
125
|
+
- `evaluateNumber(expression: string, options?: { contextNode?: Node }): number`
|
|
126
|
+
- `evaluateString(expression: string, options?: { contextNode?: Node }): string`
|
|
127
|
+
- `evaluateNode(expression: string, options?: { contextNode?: Node }): Node | null`
|
|
128
|
+
- `evaluateNodes(expression: string, options?: { contextNode?: Node }): Node[]`
|
|
129
|
+
|
|
130
|
+
(Also provided: `evaluateElement` and `evaluateNonNullElement`, but these are not type safe so use them at your own risk.)
|
|
131
|
+
|
|
132
|
+
## Supported/tested environments
|
|
133
|
+
|
|
134
|
+
- Browsers (latest versions):
|
|
135
|
+
- Chrome/Chromium-based browsers (tested only in Chromium)
|
|
136
|
+
- Firefox
|
|
137
|
+
- Safari/WebKit (tested in WebKit directly)
|
|
138
|
+
- Non-browser runtimes with a DOM compatibility environement:
|
|
139
|
+
- Node (current/LTS; tested with [jsdom](https://github.com/jsdom/jsdom)). Node DOM compatibility **does not** require any native extensions for. DOM compatibility **does not** require any underlying XPath evaluation functionality (though it does currently rely on global constants like `XPathResult`).
|
|
140
|
+
- Other runtimes and DOM compatibility libraries are not currently tested, support is unknown.
|
|
141
|
+
|
|
142
|
+
## Known issues and incompatibilities
|
|
143
|
+
|
|
144
|
+
### XPath 1.0
|
|
145
|
+
|
|
146
|
+
- Expressions with variable references are parsed incorrectly. There is also no API to provide variable values, even if variable references were supported.
|
|
147
|
+
|
|
148
|
+
### ODK XForms
|
|
149
|
+
|
|
150
|
+
We intend to support the full ODK XForms function library, but support is currently incomplete. The following functions are not yet supported (the `jr:` prefix is used by convention to refer to the JavaRosa namespace):
|
|
151
|
+
|
|
152
|
+
- `indexed-repeat`
|
|
153
|
+
- `pulldata`
|
|
154
|
+
- `jr:choice-name`
|
|
155
|
+
|
|
156
|
+
### Non-browser environments
|
|
157
|
+
|
|
158
|
+
The DOM standard is very complex, and compatibility libraries sometimes differ in terms of standards compliance and compatibility with the major browser implementations. It is likely, perhaps inevitable, that there will be edge cases and minor compatiblity issues when using such a library. At time of writing, no such issues are known in our tested environments, but a couple of minor issues have already been found and fixed during the initial test setup.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_expressionParser-1Kzq3bIy.js": {
|
|
3
|
+
"file": "expressionParser-1Kzq3bIy.js"
|
|
4
|
+
},
|
|
5
|
+
"src/expressionParser.ts": {
|
|
6
|
+
"file": "expressionParser.js",
|
|
7
|
+
"src": "src/expressionParser.ts",
|
|
8
|
+
"isEntry": true,
|
|
9
|
+
"imports": [
|
|
10
|
+
"_expressionParser-1Kzq3bIy.js"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"src/index.ts": {
|
|
14
|
+
"file": "index.js",
|
|
15
|
+
"src": "src/index.ts",
|
|
16
|
+
"isEntry": true,
|
|
17
|
+
"imports": [
|
|
18
|
+
"_expressionParser-1Kzq3bIy.js"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { Evaluator } from '../evaluator/Evaluator.ts';
|
|
3
|
+
import type { FunctionLibraryCollection } from '../evaluator/functions/FunctionLibraryCollection.ts';
|
|
4
|
+
import type { ContextDocument, ContextNode, ContextParentNode } from '../lib/dom/types.ts';
|
|
5
|
+
import type { XPathNamespaceResolverObject } from '../shared/interface.ts';
|
|
6
|
+
/**
|
|
7
|
+
* The context in which any XPath expression *or sub-expression* is evaluated.
|
|
8
|
+
*/
|
|
9
|
+
export interface Context {
|
|
10
|
+
readonly evaluator: Evaluator;
|
|
11
|
+
/**
|
|
12
|
+
* The `contextNode` as specified at the {@link Evaluator.evaluate} call site.
|
|
13
|
+
* This value is to remain constant for the entire scope of an evaluation.
|
|
14
|
+
*
|
|
15
|
+
* This explicitly supports the `current()` function, but it may also support
|
|
16
|
+
* a variety of other use cases and optimizations in the future.
|
|
17
|
+
*/
|
|
18
|
+
readonly evaluationContextNode: ContextNode;
|
|
19
|
+
readonly contextDocument: ContextDocument;
|
|
20
|
+
readonly rootNode: ContextParentNode;
|
|
21
|
+
readonly contextNodes: Iterable<ContextNode>;
|
|
22
|
+
contextPosition(): number;
|
|
23
|
+
contextSize(): number;
|
|
24
|
+
readonly functions: FunctionLibraryCollection;
|
|
25
|
+
readonly namespaceResolver: XPathNamespaceResolverObject;
|
|
26
|
+
readonly timeZone: Temporal.TimeZone;
|
|
27
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import { LocationPathEvaluation } from '../evaluations/LocationPathEvaluation.ts';
|
|
3
|
+
import type { Evaluator } from '../evaluator/Evaluator.ts';
|
|
4
|
+
import type { FunctionLibraryCollection } from '../evaluator/functions/FunctionLibraryCollection.ts';
|
|
5
|
+
import type { FilteredTreeWalker, FilteredTreeWalkers } from '../lib/dom/traversal.ts';
|
|
6
|
+
import type { ContextDocument, ContextNode, ContextParentNode } from '../lib/dom/types.ts';
|
|
7
|
+
import type { XPathNamespaceResolverObject } from '../shared/interface.ts';
|
|
8
|
+
import type { Context } from './Context.ts';
|
|
9
|
+
declare class EvaluationContextTreeWalkers implements FilteredTreeWalkers {
|
|
10
|
+
readonly ANY: FilteredTreeWalker<'ANY'>;
|
|
11
|
+
readonly COMMENT: FilteredTreeWalker<'COMMENT'>;
|
|
12
|
+
readonly ELEMENT: FilteredTreeWalker<'ELEMENT'>;
|
|
13
|
+
readonly PROCESSING_INSTRUCTION: FilteredTreeWalker<'PROCESSING_INSTRUCTION'>;
|
|
14
|
+
readonly TEXT: FilteredTreeWalker<'TEXT'>;
|
|
15
|
+
constructor(contextDocument: ContextDocument, rootNode: ContextParentNode);
|
|
16
|
+
}
|
|
17
|
+
export type { EvaluationContextTreeWalkers };
|
|
18
|
+
export interface EvaluationContextOptions {
|
|
19
|
+
readonly document: ContextDocument;
|
|
20
|
+
readonly rootNode: ContextParentNode;
|
|
21
|
+
readonly functions: FunctionLibraryCollection;
|
|
22
|
+
readonly namespaceResolver: XPathNamespaceResolverObject;
|
|
23
|
+
readonly timeZone: Temporal.TimeZone;
|
|
24
|
+
readonly treeWalkers: EvaluationContextTreeWalkers;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The context in which an XPath expression (**not** a sub-expression)
|
|
28
|
+
* is evaluated.
|
|
29
|
+
*/
|
|
30
|
+
export declare class EvaluationContext implements Context {
|
|
31
|
+
readonly evaluator: Evaluator;
|
|
32
|
+
/**
|
|
33
|
+
* @see {@link Context.evaluationContextNode}
|
|
34
|
+
*/
|
|
35
|
+
readonly evaluationContextNode: ContextNode;
|
|
36
|
+
readonly contextDocument: ContextDocument;
|
|
37
|
+
readonly rootNode: ContextParentNode;
|
|
38
|
+
readonly contextNodes: Iterable<ContextNode>;
|
|
39
|
+
readonly functions: FunctionLibraryCollection;
|
|
40
|
+
readonly namespaceResolver: XPathNamespaceResolverObject;
|
|
41
|
+
readonly timeZone: Temporal.TimeZone;
|
|
42
|
+
readonly treeWalkers: EvaluationContextTreeWalkers;
|
|
43
|
+
constructor(evaluator: Evaluator, contextNode: ContextNode, options?: Partial<EvaluationContextOptions>);
|
|
44
|
+
contextPosition(): number;
|
|
45
|
+
contextSize(): number;
|
|
46
|
+
currentContext(): LocationPathEvaluation;
|
|
47
|
+
rootContext(): LocationPathEvaluation;
|
|
48
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
2
|
+
import { ValueEvaluation } from './ValueEvaluation.ts';
|
|
3
|
+
export declare class BooleanEvaluation extends ValueEvaluation<'BOOLEAN'> {
|
|
4
|
+
readonly context: LocationPathEvaluation;
|
|
5
|
+
readonly value: boolean;
|
|
6
|
+
readonly type = "BOOLEAN";
|
|
7
|
+
readonly nodes: null;
|
|
8
|
+
protected readonly booleanValue: boolean;
|
|
9
|
+
protected readonly numberValue: number;
|
|
10
|
+
protected readonly stringValue: string;
|
|
11
|
+
constructor(context: LocationPathEvaluation, value: boolean);
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
3
|
+
import { ValueEvaluation } from './ValueEvaluation.ts';
|
|
4
|
+
interface PrecomputedXPathValues {
|
|
5
|
+
readonly booleanValue?: boolean;
|
|
6
|
+
readonly numberValue?: number;
|
|
7
|
+
readonly stringValue?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class DateTimeLikeEvaluation extends ValueEvaluation<'NUMBER'> {
|
|
10
|
+
readonly context: LocationPathEvaluation;
|
|
11
|
+
protected dateTime: Temporal.ZonedDateTime | null;
|
|
12
|
+
readonly type = "NUMBER";
|
|
13
|
+
readonly nodes: null;
|
|
14
|
+
readonly value: number;
|
|
15
|
+
protected readonly booleanValue: boolean;
|
|
16
|
+
protected readonly numberValue: number;
|
|
17
|
+
protected readonly stringValue: string;
|
|
18
|
+
protected readonly milliseconds: number;
|
|
19
|
+
protected readonly dateString: string;
|
|
20
|
+
protected readonly dateTimeString: string;
|
|
21
|
+
constructor(context: LocationPathEvaluation, dateTime: Temporal.ZonedDateTime | null, precomputedValues?: PrecomputedXPathValues);
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EvaluationType } from './EvaluationType.ts';
|
|
2
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
3
|
+
export interface Evaluation<Type extends EvaluationType = EvaluationType> extends Iterable<Evaluation<Type>> {
|
|
4
|
+
readonly context: LocationPathEvaluation;
|
|
5
|
+
readonly type: Type;
|
|
6
|
+
first(): Evaluation<Type> | null;
|
|
7
|
+
values(): Iterable<Evaluation<Type>>;
|
|
8
|
+
eq(operand: Evaluation): boolean;
|
|
9
|
+
ne(operand: Evaluation): boolean;
|
|
10
|
+
lt(operand: Evaluation): boolean;
|
|
11
|
+
lte(operand: Evaluation): boolean;
|
|
12
|
+
gt(operand: Evaluation): boolean;
|
|
13
|
+
gte(operand: Evaluation): boolean;
|
|
14
|
+
toBoolean(): boolean;
|
|
15
|
+
toNumber(): number;
|
|
16
|
+
toString(): string;
|
|
17
|
+
readonly nodes: Type extends 'NODE' ? Iterable<Node> : null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { Context } from '../context/Context.ts';
|
|
3
|
+
import type { EvaluationContext, EvaluationContextTreeWalkers } from '../context/EvaluationContext.ts';
|
|
4
|
+
import type { Evaluator } from '../evaluator/Evaluator.ts';
|
|
5
|
+
import type { FilterPathExpressionEvaluator } from '../evaluator/expression/FilterPathExpressionEvaluator.ts';
|
|
6
|
+
import type { LocationPathEvaluator } from '../evaluator/expression/LocationPathEvaluator.ts';
|
|
7
|
+
import type { LocationPathExpressionEvaluator } from '../evaluator/expression/LocationPathExpressionEvaluator.ts';
|
|
8
|
+
import type { FunctionLibraryCollection } from '../evaluator/functions/FunctionLibraryCollection.ts';
|
|
9
|
+
import type { NodeSetFunction } from '../evaluator/functions/NodeSetFunction.ts';
|
|
10
|
+
import type { AnyStep } from '../evaluator/step/Step.ts';
|
|
11
|
+
import type { ContextDocument, ContextNode, ContextParentNode } from '../lib/dom/types.ts';
|
|
12
|
+
import { Reiterable } from '../lib/iterators/Reiterable.ts';
|
|
13
|
+
import type { XPathNamespaceResolverObject } from '../shared/interface.ts';
|
|
14
|
+
import type { Evaluation } from './Evaluation.ts';
|
|
15
|
+
import { NodeEvaluation } from './NodeEvaluation.ts';
|
|
16
|
+
type LocationPathParentContext = EvaluationContext | LocationPathEvaluation;
|
|
17
|
+
type EvaluationComparator = (lhs: Evaluation, rhs: Evaluation) => boolean;
|
|
18
|
+
export declare enum AxisName {
|
|
19
|
+
ANCESTOR = "ancestor",
|
|
20
|
+
ANCESTOR_OR_SELF = "ancestor-or-self",
|
|
21
|
+
ATTRIBUTE = "attribute",
|
|
22
|
+
CHILD = "child",
|
|
23
|
+
DESCENDANT = "descendant",
|
|
24
|
+
DESCENDANT_OR_SELF = "descendant-or-self",
|
|
25
|
+
FOLLOWING = "following",
|
|
26
|
+
FOLLOWING_SIBLING = "following-sibling",
|
|
27
|
+
NAMESPACE = "namespace",
|
|
28
|
+
PARENT = "parent",
|
|
29
|
+
PRECEDING = "preceding",
|
|
30
|
+
PRECEDING_SIBLING = "preceding-sibling",
|
|
31
|
+
SELF = "self"
|
|
32
|
+
}
|
|
33
|
+
interface LocationPathEvaluationOptions {
|
|
34
|
+
readonly contextPosition?: number;
|
|
35
|
+
contextSize?: () => number;
|
|
36
|
+
}
|
|
37
|
+
type ArbitraryNodesTemporaryCallee = FilterPathExpressionEvaluator | LocationPathEvaluator | NodeSetFunction<any>;
|
|
38
|
+
export declare class LocationPathEvaluation implements Evaluation<'NODE'>, Context, Iterable<LocationPathEvaluation> {
|
|
39
|
+
readonly parentContext: LocationPathParentContext;
|
|
40
|
+
readonly type = "NODE";
|
|
41
|
+
protected readonly nodeEvaluations: Reiterable<NodeEvaluation>;
|
|
42
|
+
readonly evaluator: Evaluator;
|
|
43
|
+
readonly context: LocationPathEvaluation;
|
|
44
|
+
/**
|
|
45
|
+
* @see {@link Context.evaluationContextNode}
|
|
46
|
+
*/
|
|
47
|
+
readonly evaluationContextNode: ContextNode;
|
|
48
|
+
readonly contextDocument: ContextDocument;
|
|
49
|
+
readonly rootNode: ContextParentNode;
|
|
50
|
+
nodes: Iterable<ContextNode>;
|
|
51
|
+
get contextNodes(): IterableIterator<ContextNode>;
|
|
52
|
+
protected computedContextSize: number | null;
|
|
53
|
+
protected readonly optionsContextSize?: () => number;
|
|
54
|
+
protected readonly initializedContextPosition: number;
|
|
55
|
+
readonly functions: FunctionLibraryCollection;
|
|
56
|
+
readonly namespaceResolver: XPathNamespaceResolverObject;
|
|
57
|
+
readonly treeWalkers: EvaluationContextTreeWalkers;
|
|
58
|
+
readonly timeZone: Temporal.TimeZone;
|
|
59
|
+
/**
|
|
60
|
+
* TODO: this is a temporary accommodation for these cases which are presently
|
|
61
|
+
* not especially well designed:
|
|
62
|
+
*
|
|
63
|
+
* - Functions returning node-sets (i.e. {@link NodeSetFunction} instances).
|
|
64
|
+
* It may make sense to invert control, invoking them from here?
|
|
65
|
+
*
|
|
66
|
+
* - Nodes filtered by predicate in {@link LocationPathExpression}. Such
|
|
67
|
+
* filtering almost certainly should be performed here, in {@link step}.
|
|
68
|
+
*/
|
|
69
|
+
static fromArbitraryNodes(currentContext: LocationPathParentContext, nodes: Iterable<ContextNode>, _temporaryCallee: ArbitraryNodesTemporaryCallee): LocationPathEvaluation;
|
|
70
|
+
static fromCurrentContext(evaluationContext: EvaluationContext): LocationPathEvaluation;
|
|
71
|
+
static fromRoot(parentContext: LocationPathParentContext): LocationPathEvaluation;
|
|
72
|
+
protected constructor(parentContext: LocationPathParentContext, contextNodes: Iterable<ContextNode>, options?: LocationPathEvaluationOptions);
|
|
73
|
+
[Symbol.iterator](): {
|
|
74
|
+
next: () => IteratorResult<LocationPathEvaluation>;
|
|
75
|
+
};
|
|
76
|
+
values(): Iterable<NodeEvaluation>;
|
|
77
|
+
contextPosition(): number;
|
|
78
|
+
contextSize(): number;
|
|
79
|
+
currentContext(): LocationPathEvaluation;
|
|
80
|
+
rootContext(): LocationPathEvaluation;
|
|
81
|
+
protected _first?: NodeEvaluation | null;
|
|
82
|
+
first(): NodeEvaluation | null;
|
|
83
|
+
protected _isEmpty: boolean | null;
|
|
84
|
+
protected isEmpty(): boolean;
|
|
85
|
+
some(predicate: (evaluation: NodeEvaluation) => boolean): boolean;
|
|
86
|
+
toBoolean(): boolean;
|
|
87
|
+
toNumber(): number;
|
|
88
|
+
toString(): string;
|
|
89
|
+
protected compare(comparator: EvaluationComparator, operand: Evaluation): boolean;
|
|
90
|
+
eq(operand: Evaluation): boolean;
|
|
91
|
+
ne(operand: Evaluation): boolean;
|
|
92
|
+
lt(operand: Evaluation): boolean;
|
|
93
|
+
lte(operand: Evaluation): boolean;
|
|
94
|
+
gt(operand: Evaluation): boolean;
|
|
95
|
+
gte(operand: Evaluation): boolean;
|
|
96
|
+
protected getTreeWalker(step: AnyStep): TreeWalker;
|
|
97
|
+
protected ancestor(step: AnyStep): Iterable<ContextNode>;
|
|
98
|
+
protected ancestorOrSelf(step: AnyStep): Iterable<ContextNode>;
|
|
99
|
+
protected attribute(): Iterable<ContextNode>;
|
|
100
|
+
protected child(step: AnyStep): Iterable<ContextNode>;
|
|
101
|
+
protected descendant(step: AnyStep): Iterable<ContextNode>;
|
|
102
|
+
protected descendantOrSelf(step: AnyStep): Iterable<ContextNode>;
|
|
103
|
+
protected following(step: AnyStep): Iterable<ContextNode>;
|
|
104
|
+
protected followingSibling(step: AnyStep): Iterable<ContextNode>;
|
|
105
|
+
protected namespace(): Iterable<ContextNode>;
|
|
106
|
+
protected parent(step: AnyStep): Iterable<ContextNode>;
|
|
107
|
+
protected preceding(step: AnyStep): Iterable<ContextNode>;
|
|
108
|
+
protected precedingSibling(step: AnyStep): Iterable<ContextNode>;
|
|
109
|
+
protected self(): Iterable<ContextNode>;
|
|
110
|
+
step(step: AnyStep): LocationPathEvaluation;
|
|
111
|
+
evaluateLocationPathExpression(expression: LocationPathExpressionEvaluator): LocationPathEvaluation;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
2
|
+
import { ValueEvaluation } from './ValueEvaluation.ts';
|
|
3
|
+
interface NodeEvaluationComputedValues {
|
|
4
|
+
readonly booleanValue: boolean;
|
|
5
|
+
readonly isEmpty: boolean;
|
|
6
|
+
readonly numberValue: number;
|
|
7
|
+
readonly stringValue: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class NodeEvaluation extends ValueEvaluation<'NODE'> {
|
|
10
|
+
readonly context: LocationPathEvaluation;
|
|
11
|
+
readonly value: Node;
|
|
12
|
+
readonly type = "NODE";
|
|
13
|
+
readonly nodes: Iterable<Node>;
|
|
14
|
+
protected computedValues: NodeEvaluationComputedValues | null;
|
|
15
|
+
protected get booleanValue(): boolean;
|
|
16
|
+
protected get numberValue(): number;
|
|
17
|
+
protected get stringValue(): string;
|
|
18
|
+
get isEmpty(): boolean;
|
|
19
|
+
constructor(context: LocationPathEvaluation, value: Node);
|
|
20
|
+
protected computeValues(): NodeEvaluationComputedValues;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
2
|
+
import { ValueEvaluation } from './ValueEvaluation.ts';
|
|
3
|
+
export declare class NumberEvaluation extends ValueEvaluation<'NUMBER'> {
|
|
4
|
+
readonly context: LocationPathEvaluation;
|
|
5
|
+
readonly value: number;
|
|
6
|
+
readonly type = "NUMBER";
|
|
7
|
+
readonly nodes: null;
|
|
8
|
+
protected readonly booleanValue: boolean;
|
|
9
|
+
protected readonly numberValue: number;
|
|
10
|
+
protected readonly stringValue: string;
|
|
11
|
+
constructor(context: LocationPathEvaluation, value: number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
2
|
+
import { ValueEvaluation } from './ValueEvaluation.ts';
|
|
3
|
+
export declare class StringEvaluation extends ValueEvaluation<'STRING'> {
|
|
4
|
+
readonly context: LocationPathEvaluation;
|
|
5
|
+
readonly value: string;
|
|
6
|
+
readonly isEmpty: boolean;
|
|
7
|
+
readonly type = "STRING";
|
|
8
|
+
readonly nodes: null;
|
|
9
|
+
protected readonly booleanValue: boolean;
|
|
10
|
+
protected readonly numberValue: number;
|
|
11
|
+
protected readonly stringValue: string;
|
|
12
|
+
constructor(context: LocationPathEvaluation, value: string, isEmpty?: boolean);
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Evaluation } from './Evaluation.ts';
|
|
2
|
+
import type { EvaluationType, EvaluationTypes } from './EvaluationType.ts';
|
|
3
|
+
import { LocationPathEvaluation } from './LocationPathEvaluation.ts';
|
|
4
|
+
export declare abstract class ValueEvaluation<Type extends EvaluationType> implements Evaluation<Type> {
|
|
5
|
+
abstract readonly context: LocationPathEvaluation;
|
|
6
|
+
abstract readonly type: Type;
|
|
7
|
+
abstract readonly value: EvaluationTypes[Type];
|
|
8
|
+
abstract readonly nodes: Type extends 'NODE' ? Iterable<Node> : null;
|
|
9
|
+
protected abstract readonly booleanValue: boolean;
|
|
10
|
+
protected abstract readonly numberValue: number;
|
|
11
|
+
protected abstract readonly stringValue: string;
|
|
12
|
+
[Symbol.iterator](): IterableIterator<this>;
|
|
13
|
+
first(): this;
|
|
14
|
+
values(): IterableIterator<this>;
|
|
15
|
+
toBoolean(): boolean;
|
|
16
|
+
toNumber(): number;
|
|
17
|
+
toString(): string;
|
|
18
|
+
eq(operand: Evaluation): boolean;
|
|
19
|
+
ne(operand: Evaluation): boolean;
|
|
20
|
+
lt(operand: Evaluation): boolean;
|
|
21
|
+
lte(operand: Evaluation): boolean;
|
|
22
|
+
gt(operand: Evaluation): boolean;
|
|
23
|
+
gte(operand: Evaluation): boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { EvaluationContextOptions } from '../context/EvaluationContext.ts';
|
|
3
|
+
import type { AnyParentNode } from '../lib/dom/types.ts';
|
|
4
|
+
import type { AnyXPathEvaluator, XPathNSResolver, XPathResultType } from '../shared/index.ts';
|
|
5
|
+
import type { ExpressionParser, ParseOptions } from '../static/grammar/ExpressionParser.ts';
|
|
6
|
+
import { FunctionLibraryCollection } from './functions/FunctionLibraryCollection.ts';
|
|
7
|
+
import { ResultTypes } from './result/ResultType.ts';
|
|
8
|
+
export interface EvaluatorOptions {
|
|
9
|
+
readonly functions?: FunctionLibraryCollection;
|
|
10
|
+
readonly parseOptions?: ParseOptions;
|
|
11
|
+
readonly rootNode?: AnyParentNode | null | undefined;
|
|
12
|
+
readonly timeZoneId?: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface EvaluatorConvenienceMethodOptions {
|
|
15
|
+
readonly contextNode?: Node;
|
|
16
|
+
}
|
|
17
|
+
export interface EvaluatorNodeConvenienceMethodOptions<AssertExists extends boolean = false> extends EvaluatorConvenienceMethodOptions {
|
|
18
|
+
readonly assertExists?: AssertExists;
|
|
19
|
+
}
|
|
20
|
+
type EvaluatedNode<AssertExists extends boolean, T extends Node> = AssertExists extends true ? T : T | null;
|
|
21
|
+
export declare class Evaluator implements AnyXPathEvaluator {
|
|
22
|
+
protected readonly parser: ExpressionParser;
|
|
23
|
+
readonly functions: FunctionLibraryCollection;
|
|
24
|
+
readonly parseOptions: ParseOptions;
|
|
25
|
+
readonly resultTypes: ResultTypes;
|
|
26
|
+
readonly rootNodeDocument: Document | XMLDocument | null;
|
|
27
|
+
readonly rootNode: AnyParentNode | null;
|
|
28
|
+
readonly sharedContextOptions: Partial<EvaluationContextOptions>;
|
|
29
|
+
readonly timeZone: Temporal.TimeZone;
|
|
30
|
+
constructor(options?: EvaluatorOptions);
|
|
31
|
+
evaluate(expression: string, contextNode: Node, namespaceResolver: XPathNSResolver | null, resultType: XPathResultType | null): import("./result/BooleanResult.ts").BooleanResult | import("./result/NodeSetResult.ts").NodeSetSnapshotResult | import("./result/NodeSetResult.ts").NodeSetIteratorResult | import("./result/NumberResult.ts").NumberResult | import("./result/StringResult.ts").StringResult;
|
|
32
|
+
protected getContextNode(options: EvaluatorConvenienceMethodOptions): Node;
|
|
33
|
+
evaluateBoolean(expression: string, options?: EvaluatorConvenienceMethodOptions): boolean;
|
|
34
|
+
evaluateNumber(expression: string, options?: EvaluatorConvenienceMethodOptions): number;
|
|
35
|
+
evaluateString(expression: string, options?: EvaluatorConvenienceMethodOptions): string;
|
|
36
|
+
evaluateNode<T extends Node, AssertExists extends boolean = false>(expression: string, options?: EvaluatorNodeConvenienceMethodOptions<AssertExists>): EvaluatedNode<AssertExists, T>;
|
|
37
|
+
evaluateElement<AssertExists extends boolean = false>(expression: string, options?: EvaluatorNodeConvenienceMethodOptions<AssertExists>): EvaluatedNode<AssertExists, Element>;
|
|
38
|
+
evaluateNonNullElement(expression: string, options?: Omit<EvaluatorNodeConvenienceMethodOptions<true>, 'assertExists'>): Element;
|
|
39
|
+
evaluateNodes<T extends Node>(expression: string, options?: EvaluatorNodeConvenienceMethodOptions): T[];
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ENKETO_NAMESPACE_URI, ENKETO_PREFIX, FN_NAMESPACE_URI, FN_PREFIX, HTML_NAMESPACE_URI, HTML_PREFIX, JAVAROSA_NAMESPACE_URI, JAVAROSA_PREFIX, ODK_NAMESPACE_URI, ODK_PREFIX, OPENROSA_XFORMS_NAMESPACE_URI, OPENROSA_XFORMS_PREFIX, XFORMS_NAMESPACE_URI, XFORMS_PREFIX, XHTML_NAMESPACE_URI, XML_NAMESPACE_URI, XML_PREFIX, XMLNS_NAMESPACE_URI, XMLNS_PREFIX } from '../../../common/src/constants/xmlns.ts';
|
|
2
|
+
import type { ContextParentNode } from '../lib/dom/types.ts';
|
|
3
|
+
import type { XPathNamespaceResolverObject } from '../shared/interface.ts';
|
|
4
|
+
export { ENKETO_NAMESPACE_URI, ENKETO_PREFIX, FN_NAMESPACE_URI, FN_PREFIX, HTML_NAMESPACE_URI, HTML_PREFIX, JAVAROSA_NAMESPACE_URI, JAVAROSA_PREFIX, ODK_NAMESPACE_URI, ODK_PREFIX, OPENROSA_XFORMS_NAMESPACE_URI, OPENROSA_XFORMS_PREFIX, XFORMS_NAMESPACE_URI, XFORMS_PREFIX, XHTML_NAMESPACE_URI, XML_NAMESPACE_URI, XML_PREFIX, XMLNS_NAMESPACE_URI, XMLNS_PREFIX, };
|
|
5
|
+
export interface StaticNamespaces<DefaultPrefix extends string, DefaultURI extends string, Mapping extends Record<string, string>> {
|
|
6
|
+
get<Key extends string | null>(key: Key): Key extends null ? DefaultURI : Key extends DefaultPrefix ? DefaultURI : Key extends keyof Mapping ? Mapping[Key] : undefined;
|
|
7
|
+
has(key: null): true;
|
|
8
|
+
has(key: DefaultPrefix | keyof Mapping): true;
|
|
9
|
+
has(key: keyof Mapping): true;
|
|
10
|
+
has(key: string): false;
|
|
11
|
+
}
|
|
12
|
+
export declare class StaticNamespaces<DefaultPrefix extends string, DefaultURI extends string, const Mapping extends Record<string, string>> extends Map<string | null, string> implements ReadonlyMap<string | null, string> {
|
|
13
|
+
protected defaultPrefix: DefaultPrefix;
|
|
14
|
+
protected defaultURI: DefaultURI;
|
|
15
|
+
constructor(defaultPrefix: DefaultPrefix, defaultURI: DefaultURI, namespaces: Mapping);
|
|
16
|
+
}
|
|
17
|
+
export declare const staticNamespaces: StaticNamespaces<"xf", "http://www.w3.org/2002/xforms", {
|
|
18
|
+
readonly enk: "http://enketo.org/xforms";
|
|
19
|
+
readonly fn: "http://www.w3.org/2005/xpath-functions";
|
|
20
|
+
readonly h: "http://www.w3.org/1999/xhtml";
|
|
21
|
+
readonly html: "http://www.w3.org/1999/xhtml";
|
|
22
|
+
readonly xhtml: "http://www.w3.org/1999/xhtml";
|
|
23
|
+
readonly jr: "http://openrosa.org/javarosa";
|
|
24
|
+
readonly javarosa: "http://openrosa.org/javarosa";
|
|
25
|
+
readonly odk: "http://www.opendatakit.org/xforms";
|
|
26
|
+
readonly orx: "http://openrosa.org/xforms";
|
|
27
|
+
readonly 'openrosa-xforms': "http://openrosa.org/xforms";
|
|
28
|
+
readonly xf: "http://www.w3.org/2002/xforms";
|
|
29
|
+
readonly xml: "http://www.w3.org/XML/1998/namespace";
|
|
30
|
+
readonly xmlns: "http://www.w3.org/2000/xmlns/";
|
|
31
|
+
}>;
|
|
32
|
+
export declare class NamespaceResolver implements XPathNamespaceResolverObject {
|
|
33
|
+
protected readonly rootNode: ContextParentNode;
|
|
34
|
+
protected readonly referenceNode?: XPathNamespaceResolverObject | null | undefined;
|
|
35
|
+
protected readonly contextResolver: XPathNamespaceResolverObject;
|
|
36
|
+
constructor(rootNode: ContextParentNode, referenceNode?: XPathNamespaceResolverObject | null | undefined);
|
|
37
|
+
protected lookupNodeNamespaceURI: (node: Node, prefix: string | null) => string | null;
|
|
38
|
+
protected lookupStaticNamespaceURI: (prefix: string | null) => "http://www.w3.org/2002/xforms" | null;
|
|
39
|
+
/**
|
|
40
|
+
* Note: while it is likely consistent with the **spec** to resolve a `null`
|
|
41
|
+
* prefix, it's not typical in a browser environment for the resolver to be
|
|
42
|
+
* consulted for an unprefixed name test in an XPath expression.
|
|
43
|
+
*
|
|
44
|
+
* We _may_ elect to deviate from that typical behavior, as it is the much
|
|
45
|
+
* more **obvious** behavior.
|
|
46
|
+
*/
|
|
47
|
+
lookupNamespaceURI(prefix: string | null): string | null;
|
|
48
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AbsoluteLocationPathNode } from '../../static/grammar/SyntaxNode.ts';
|
|
2
|
+
import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
|
|
3
|
+
import { LocationPathEvaluator } from './LocationPathEvaluator.ts';
|
|
4
|
+
export declare class AbsoluteLocationPathExpressionEvaluator extends LocationPathEvaluator implements ExpressionEvaluator {
|
|
5
|
+
readonly syntaxNode: AbsoluteLocationPathNode;
|
|
6
|
+
constructor(syntaxNode: AbsoluteLocationPathNode);
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EvaluationContext } from '../../context/EvaluationContext.ts';
|
|
2
|
+
import type { Evaluation } from '../../evaluations/Evaluation.ts';
|
|
3
|
+
import type { AnyBinaryExprNode } from '../../static/grammar/SyntaxNode.ts';
|
|
4
|
+
import type { ExpressionEvaluator } from './ExpressionEvaluator.ts';
|
|
5
|
+
export declare abstract class BinaryExpressionEvaluator<Node extends AnyBinaryExprNode> implements ExpressionEvaluator {
|
|
6
|
+
readonly syntaxNode: Node;
|
|
7
|
+
readonly lhs: ExpressionEvaluator;
|
|
8
|
+
readonly rhs: ExpressionEvaluator;
|
|
9
|
+
constructor(syntaxNode: Node);
|
|
10
|
+
abstract evaluate(context: EvaluationContext): Evaluation;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { EvaluationContext } from '../../context/EvaluationContext.ts';
|
|
2
|
+
import { BooleanEvaluation } from '../../evaluations/BooleanEvaluation.ts';
|
|
3
|
+
import type { Evaluation } from '../../evaluations/Evaluation.ts';
|
|
4
|
+
import type { AndExprNode, EqExprNode, GtExprNode, GteExprNode, LtExprNode, LteExprNode, NeExprNode, OrExprNode } from '../../static/grammar/SyntaxNode.ts';
|
|
5
|
+
import { BinaryExpressionEvaluator } from './BinaryExpressionEvaluator.ts';
|
|
6
|
+
type BooleanBinaryExprNode = AndExprNode | EqExprNode | GteExprNode | GtExprNode | LteExprNode | LtExprNode | NeExprNode | OrExprNode;
|
|
7
|
+
type BooleanOperator<Node extends BooleanBinaryExprNode> = Node extends AndExprNode ? 'and' : Node extends EqExprNode ? 'eq' : Node extends GtExprNode ? 'gt' : Node extends GteExprNode ? 'gte' : Node extends LtExprNode ? 'lt' : Node extends LteExprNode ? 'lte' : Node extends NeExprNode ? 'ne' : Node extends OrExprNode ? 'or' : never;
|
|
8
|
+
type CompareOperator = 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'ne';
|
|
9
|
+
export declare class BooleanBinaryExpressionEvaluator<Node extends BooleanBinaryExprNode> extends BinaryExpressionEvaluator<Node> {
|
|
10
|
+
readonly operator: BooleanOperator<Node>;
|
|
11
|
+
constructor(syntaxNode: Node);
|
|
12
|
+
protected and(context: EvaluationContext): Evaluation;
|
|
13
|
+
protected or(context: EvaluationContext): Evaluation;
|
|
14
|
+
protected compare(context: EvaluationContext, operator: CompareOperator): BooleanEvaluation;
|
|
15
|
+
evaluate(context: EvaluationContext): Evaluation;
|
|
16
|
+
}
|
|
17
|
+
export {};
|