@getodk/xpath 0.7.0 → 0.8.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
CHANGED
|
@@ -148,7 +148,6 @@ Both evaluator classes provide the following convenience methods:
|
|
|
148
148
|
|
|
149
149
|
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):
|
|
150
150
|
|
|
151
|
-
- `pulldata`
|
|
152
151
|
- `jr:choice-name`
|
|
153
152
|
|
|
154
153
|
### Non-browser environments
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StringFunction } from '../../evaluator/functions/StringFunction.ts';
|
|
2
|
+
/**
|
|
3
|
+
* jr:choice-name function
|
|
4
|
+
* https://getodk.github.io/xforms-spec/#fn:jr:choice-name
|
|
5
|
+
*
|
|
6
|
+
* The first parameter is evaluated to the value to find the label for. Can be a string literal,
|
|
7
|
+
* or a xpath reference which resolves to a string.
|
|
8
|
+
* The second parameter is the xpath reference to the element which enumerates the choices,
|
|
9
|
+
* either by items or an itemset. Valid elements must implement the {@link XPathChoiceNode}
|
|
10
|
+
* interface.
|
|
11
|
+
* Returns the label which can be translated, calculated, and contain markup, for the given
|
|
12
|
+
* choice of the given element.
|
|
13
|
+
*/
|
|
14
|
+
export declare const choiceName: StringFunction;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { BooleanFunction } from '../../evaluator/functions/BooleanFunction.ts';
|
|
2
2
|
import { StringFunction } from '../../evaluator/functions/StringFunction.ts';
|
|
3
|
+
export declare const base64Decode: StringFunction;
|
|
3
4
|
export declare const coalesce: StringFunction;
|
|
4
5
|
export declare const concat: StringFunction;
|
|
5
6
|
export declare const digest: StringFunction;
|
|
6
7
|
export declare const endsWith: BooleanFunction;
|
|
7
8
|
export declare const join: StringFunction;
|
|
9
|
+
export declare const pulldata: StringFunction;
|
|
8
10
|
export declare const regex: BooleanFunction;
|
|
9
11
|
export declare const substr: StringFunction;
|
|
10
12
|
export declare const uuid: StringFunction;
|
package/dist/index.d.ts
CHANGED
|
@@ -44,3 +44,4 @@ export type { XFormsItextTranslationElement, XFormsItextTranslationLanguage, XFo
|
|
|
44
44
|
export type { XFormsSecondaryInstanceElement, XFormsSecondaryInstanceMap, } from './xforms/XFormsSecondaryInstances.ts';
|
|
45
45
|
export { XFormsXPathEvaluator } from './xforms/XFormsXPathEvaluator.ts';
|
|
46
46
|
export type { XFormsXPathEvaluatorOptions, XFormsXPathRootNode, } from './xforms/XFormsXPathEvaluator.ts';
|
|
47
|
+
export type { XPathChoiceNode } from './adapter/interface/XPathChoiceNode.ts';
|
package/dist/index.js
CHANGED
|
@@ -7459,7 +7459,45 @@ const nodeSet = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
7459
7459
|
itext
|
|
7460
7460
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
7461
7461
|
|
|
7462
|
-
const
|
|
7462
|
+
const choiceName = new StringFunction(
|
|
7463
|
+
"choice-name",
|
|
7464
|
+
[
|
|
7465
|
+
{ arityType: "required", typeHint: "string" },
|
|
7466
|
+
{ arityType: "required", typeHint: "string" }
|
|
7467
|
+
],
|
|
7468
|
+
(context, [nodeExpression, valueExpression]) => {
|
|
7469
|
+
const node = nodeExpression.evaluate(context).toString();
|
|
7470
|
+
const value = valueExpression.evaluate(context).toString();
|
|
7471
|
+
const [contextNode] = context.contextNodes;
|
|
7472
|
+
const { domProvider } = context;
|
|
7473
|
+
let nodes;
|
|
7474
|
+
if (contextNode && domProvider.isElement(contextNode)) {
|
|
7475
|
+
nodes = context.evaluator.evaluateNodes(value, { contextNode });
|
|
7476
|
+
} else {
|
|
7477
|
+
nodes = context.evaluator.evaluateNodes(value);
|
|
7478
|
+
}
|
|
7479
|
+
const firstNode = nodes?.[0];
|
|
7480
|
+
if (!firstNode) {
|
|
7481
|
+
return "";
|
|
7482
|
+
}
|
|
7483
|
+
if (!("getChoiceName" in firstNode)) {
|
|
7484
|
+
throw new Error(
|
|
7485
|
+
`Evaluating 'jr:choice-name' on element '${value}' which has no possible choices.`
|
|
7486
|
+
);
|
|
7487
|
+
}
|
|
7488
|
+
return firstNode.getChoiceName(node) ?? "";
|
|
7489
|
+
}
|
|
7490
|
+
);
|
|
7491
|
+
|
|
7492
|
+
const select$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
7493
|
+
__proto__: null,
|
|
7494
|
+
choiceName
|
|
7495
|
+
}, Symbol.toStringTag, { value: 'Module' }));
|
|
7496
|
+
|
|
7497
|
+
const jr = new FunctionLibrary(JAVAROSA_NAMESPACE_URI, [
|
|
7498
|
+
...Object.values(nodeSet),
|
|
7499
|
+
...Object.values(select$1)
|
|
7500
|
+
]);
|
|
7463
7501
|
|
|
7464
7502
|
const booleanFromString = new BooleanFunction(
|
|
7465
7503
|
"boolean-from-string",
|
|
@@ -14890,6 +14928,10 @@ const hex = /*#__PURE__*/_mergeNamespaces({
|
|
|
14890
14928
|
default: encHex
|
|
14891
14929
|
}, [encHexExports]);
|
|
14892
14930
|
|
|
14931
|
+
const base64Decode$1 = (base64Input) => {
|
|
14932
|
+
return new TextDecoder().decode(Uint8Array.from(atob(base64Input), (m) => m.charCodeAt(0)));
|
|
14933
|
+
};
|
|
14934
|
+
|
|
14893
14935
|
const toStrings = (context, expressions) => {
|
|
14894
14936
|
return expressions.flatMap((arg) => {
|
|
14895
14937
|
const result = arg.evaluate(context);
|
|
@@ -14901,6 +14943,17 @@ const toStrings = (context, expressions) => {
|
|
|
14901
14943
|
});
|
|
14902
14944
|
};
|
|
14903
14945
|
|
|
14946
|
+
const base64Decode = new StringFunction(
|
|
14947
|
+
"base64-decode",
|
|
14948
|
+
[{ arityType: "required", typeHint: "string" }],
|
|
14949
|
+
(context, [base64Expression]) => {
|
|
14950
|
+
try {
|
|
14951
|
+
return base64Decode$1(base64Expression.evaluate(context).toString());
|
|
14952
|
+
} catch {
|
|
14953
|
+
return "";
|
|
14954
|
+
}
|
|
14955
|
+
}
|
|
14956
|
+
);
|
|
14904
14957
|
const coalesce = new StringFunction(
|
|
14905
14958
|
"coalesce",
|
|
14906
14959
|
[
|
|
@@ -14990,6 +15043,23 @@ const join = new StringFunction(
|
|
|
14990
15043
|
return strings.join(glue);
|
|
14991
15044
|
}
|
|
14992
15045
|
);
|
|
15046
|
+
const pulldata = new StringFunction(
|
|
15047
|
+
"pulldata",
|
|
15048
|
+
[
|
|
15049
|
+
{ arityType: "required", typeHint: "string" },
|
|
15050
|
+
{ arityType: "required", typeHint: "string" },
|
|
15051
|
+
{ arityType: "required", typeHint: "string" },
|
|
15052
|
+
{ arityType: "required", typeHint: "string" }
|
|
15053
|
+
],
|
|
15054
|
+
(context, [instanceExpression, desiredElementExpression, queryElementExpression, queryExpression]) => {
|
|
15055
|
+
const instanceId = instanceExpression.evaluate(context).toString();
|
|
15056
|
+
const desiredElement = desiredElementExpression.evaluate(context).toString();
|
|
15057
|
+
const queryElement = queryElementExpression.evaluate(context).toString();
|
|
15058
|
+
const query = queryExpression.evaluate(context).toString();
|
|
15059
|
+
const expr = `instance('${instanceId}')/root/item[${queryElement}='${query}']/${desiredElement}`;
|
|
15060
|
+
return context.evaluator.evaluateString(expr);
|
|
15061
|
+
}
|
|
15062
|
+
);
|
|
14993
15063
|
const regex = new BooleanFunction(
|
|
14994
15064
|
"regex",
|
|
14995
15065
|
[
|
|
@@ -15068,11 +15138,13 @@ const uuid = new StringFunction(
|
|
|
15068
15138
|
|
|
15069
15139
|
const string = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
15070
15140
|
__proto__: null,
|
|
15141
|
+
base64Decode,
|
|
15071
15142
|
coalesce,
|
|
15072
15143
|
concat,
|
|
15073
15144
|
digest,
|
|
15074
15145
|
endsWith,
|
|
15075
15146
|
join,
|
|
15147
|
+
pulldata,
|
|
15076
15148
|
regex,
|
|
15077
15149
|
substr,
|
|
15078
15150
|
uuid
|