@getodk/xpath 0.6.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.
@@ -1,2 +1,2 @@
1
- export { e as expressionParser } from './expressionParser-BUM7qFCl.js';
1
+ export { e as expressionParser } from './expressionParser-DjyNe4Lw.js';
2
2
  //# sourceMappingURL=expressionParser.js.map
@@ -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
@@ -1,4 +1,4 @@
1
- import { U as UpsertableMap, e as expressionParser, g as getAugmentedNamespace, c as commonjsGlobal, a as getDefaultExportFromCjs } from './expressionParser-BUM7qFCl.js';
1
+ import { U as UpsertableMap, e as expressionParser, g as getAugmentedNamespace, c as commonjsGlobal, a as getDefaultExportFromCjs } from './expressionParser-DjyNe4Lw.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  for (var i = 0; i < m.length; i++) {
@@ -400,7 +400,7 @@ function epochMilliToIso(e, n = 0, t = 0) {
400
400
  return zipProps(Tr, [r.getUTCFullYear(), r.getUTCMonth() + 1, r.getUTCDate() + o, r.getUTCHours(), r.getUTCMinutes(), r.getUTCSeconds(), r.getUTCMilliseconds(), n, t]);
401
401
  }
402
402
  function hashIntlFormatParts(e, n) {
403
- if (n < -864e13) {
403
+ if (n < -Pr) {
404
404
  throw new RangeError(Io);
405
405
  }
406
406
  const t = e.formatToParts(n),
@@ -1084,7 +1084,7 @@ function getSingleInstantFor(e, n, t = 0, o = e.I(n)) {
1084
1084
  }
1085
1085
  const r = isoToEpochNano(n),
1086
1086
  i = ((e, n) => {
1087
- const t = e.R(moveBigNano(n, -864e11));
1087
+ const t = e.R(moveBigNano(n, -Uo));
1088
1088
  return (e => {
1089
1089
  if (e > Uo) {
1090
1090
  throw new RangeError(go);
@@ -1100,7 +1100,7 @@ function getStartOfDayInstantFor(e, n) {
1100
1100
  if (t.length) {
1101
1101
  return t[0];
1102
1102
  }
1103
- const o = moveBigNano(isoToEpochNano(n), -864e11);
1103
+ const o = moveBigNano(isoToEpochNano(n), -Uo);
1104
1104
  return e.O(o, 1);
1105
1105
  }
1106
1106
  function Ye(e, n, t) {
@@ -1322,7 +1322,7 @@ function computeDurationSign(e, n = p) {
1322
1322
  }
1323
1323
  function checkDurationUnits(e) {
1324
1324
  for (const n of dr) {
1325
- clampEntity(n, e[n], -4294967295, di, 1);
1325
+ clampEntity(n, e[n], -di, di, 1);
1326
1326
  }
1327
1327
  return checkDurationTimeUnit(bigNanoToNumber(durationFieldsToBigNano(e), Ro)), e;
1328
1328
  }
@@ -1981,7 +1981,7 @@ function createIntlYearDataCache(e) {
1981
1981
  r += 400 * ko;
1982
1982
  } while ((o = e(r)).year <= t);
1983
1983
  do {
1984
- if (r += (1 - o.day) * ko, o.year === t && (a.push(r), s.push(o.o)), r -= ko, ++i > 100 || r < -864e13) {
1984
+ if (r += (1 - o.day) * ko, o.year === t && (a.push(r), s.push(o.o)), r -= ko, ++i > 100 || r < -Pr) {
1985
1985
  throw new RangeError(fo);
1986
1986
  }
1987
1987
  } while ((o = e(r)).year >= t);
@@ -2774,7 +2774,7 @@ const expectedInteger = (e, n) => `Non-integer ${e}: ${n}`,
2774
2774
  vr = 1e8,
2775
2775
  Pr = vr * ko,
2776
2776
  Er = [vr, 0],
2777
- Sr = [-1e8, 0],
2777
+ Sr = [-vr, 0],
2778
2778
  Fr = 275760,
2779
2779
  wr = -271821,
2780
2780
  en = Intl.DateTimeFormat,
@@ -7164,7 +7164,9 @@ const dateTimeFromString = (timeZone, value) => {
7164
7164
  }
7165
7165
  return Xn.PlainDateTime.from(value).toZonedDateTime(timeZone);
7166
7166
  };
7167
- const toNanoseconds = (milliseconds) => BigInt(milliseconds) * MILLISECOND_NANOSECONDS;
7167
+ const toNanoseconds = (milliseconds) => {
7168
+ return BigInt(Math.round(milliseconds)) * MILLISECOND_NANOSECONDS;
7169
+ };
7168
7170
  const dateTimeFromNumber = (timeZone, milliseconds) => {
7169
7171
  if (Number.isNaN(milliseconds)) {
7170
7172
  return null;
@@ -7457,7 +7459,45 @@ const nodeSet = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
7457
7459
  itext
7458
7460
  }, Symbol.toStringTag, { value: 'Module' }));
7459
7461
 
7460
- const jr = new FunctionLibrary(JAVAROSA_NAMESPACE_URI, [...Object.values(nodeSet)]);
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
+ ]);
7461
7501
 
7462
7502
  const booleanFromString = new BooleanFunction(
7463
7503
  "boolean-from-string",
@@ -14888,6 +14928,10 @@ const hex = /*#__PURE__*/_mergeNamespaces({
14888
14928
  default: encHex
14889
14929
  }, [encHexExports]);
14890
14930
 
14931
+ const base64Decode$1 = (base64Input) => {
14932
+ return new TextDecoder().decode(Uint8Array.from(atob(base64Input), (m) => m.charCodeAt(0)));
14933
+ };
14934
+
14891
14935
  const toStrings = (context, expressions) => {
14892
14936
  return expressions.flatMap((arg) => {
14893
14937
  const result = arg.evaluate(context);
@@ -14899,6 +14943,17 @@ const toStrings = (context, expressions) => {
14899
14943
  });
14900
14944
  };
14901
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
+ );
14902
14957
  const coalesce = new StringFunction(
14903
14958
  "coalesce",
14904
14959
  [
@@ -14988,6 +15043,23 @@ const join = new StringFunction(
14988
15043
  return strings.join(glue);
14989
15044
  }
14990
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
+ );
14991
15063
  const regex = new BooleanFunction(
14992
15064
  "regex",
14993
15065
  [
@@ -15066,11 +15138,13 @@ const uuid = new StringFunction(
15066
15138
 
15067
15139
  const string = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
15068
15140
  __proto__: null,
15141
+ base64Decode,
15069
15142
  coalesce,
15070
15143
  concat,
15071
15144
  digest,
15072
15145
  endsWith,
15073
15146
  join,
15147
+ pulldata,
15074
15148
  regex,
15075
15149
  substr,
15076
15150
  uuid