@getodk/xpath 0.3.0 → 0.4.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 +1 @@
1
- export declare const seededRandomize: <T>(values: readonly T[], seed?: number) => T[];
1
+ export declare const seededRandomize: <T>(values: readonly T[], seed?: number | bigint) => T[];
@@ -0,0 +1,4 @@
1
+ import { GeoValueType } from './GeoValueCodec.ts';
2
+ export declare class EncodeGeoValueStubError extends Error {
3
+ constructor(valueType: GeoValueType);
4
+ }
@@ -0,0 +1,33 @@
1
+ export type GeoValueType = 'geopoint' | 'geoshape' | 'geotrace';
2
+ export type GeoValueEncoder<RuntimeInputValue> = (input: RuntimeInputValue) => string;
3
+ export type GeoValueDecoder<RuntimeValue> = (value: string) => RuntimeValue;
4
+ /**
5
+ * @todo This is based on the same concepts expressed by the extant
6
+ * `@getodk/xforms-engine` `ValueCodec` class. It has been stripped down a more
7
+ * minimal interface, which might form a basis for shared responsibilities for
8
+ * value type support between packages. Its introduction now anticipates an
9
+ * imminent opportunity for sharing logic for the following data types:
10
+ *
11
+ * - {@link https://getodk.github.io/xforms-spec/#data-type:geopoint | geopoint}
12
+ * - {@link https://getodk.github.io/xforms-spec/#data-type:geotrace | geotrace}
13
+ * - {@link https://getodk.github.io/xforms-spec/#data-type:geoshape | geoshape}
14
+ *
15
+ * It makes sense to consider how we share this responsibility as we expand the
16
+ * Web Forms project's support for geo-related features, as there are mutually
17
+ * dependent responsibilities for encoding/decoding between the `@getodk/xpath`
18
+ * and `@getodk/xforms-engine` packages.
19
+ *
20
+ * It's also worth considering how we might address similar shared
21
+ * responsibilities for:
22
+ *
23
+ * - non-geo data types, and potential nuances of how those types are expected
24
+ * to behave at the boundary between an ODK XForm's model, and the XPath
25
+ * expressions operating on that model's nodes
26
+ * - XPath casting semantics, and whether/how that responsiblity intersects with
27
+ * those ODK XForms data types
28
+ */
29
+ export interface GeoValueCodec<V extends GeoValueType, RuntimeValue extends RuntimeInputValue, RuntimeInputValue = RuntimeValue> {
30
+ readonly valueType: V;
31
+ readonly encodeValue: GeoValueEncoder<RuntimeInputValue>;
32
+ readonly decodeValue: GeoValueDecoder<RuntimeValue>;
33
+ }
@@ -0,0 +1,28 @@
1
+ export interface GeopointCoordinates {
2
+ readonly latitude: number;
3
+ readonly longitude: number;
4
+ }
5
+ /**
6
+ * @todo this is derived from an interface that was introduced _internally_, to
7
+ * support the initial implementation of these related geo functions:
8
+ *
9
+ * - {@link https://getodk.github.io/xforms-spec/#fn:area | area}
10
+ * - {@link https://getodk.github.io/xforms-spec/#fn:distance | distance}
11
+ *
12
+ * It has been extracted here as a class as a potential basis for sharing
13
+ * geo-related functionality between Web Forms packages.
14
+ *
15
+ * **IMPORTANT:** it's likely that we'll reconsider how we model a
16
+ * {@link https://getodk.github.io/xforms-spec/#data-type:geopoint | geopoint}
17
+ * value, as we consider several shared responsibilities between `@getodk/xpath`
18
+ * and `@getodk/xforms-engine`. Notably, the engine already has a conflicting
19
+ * structural runtime representation and encoding behavior, in its support for
20
+ * {@link https://getodk.github.io/xforms-spec/#secondary-instances---external | external secondary instances}
21
+ * with a {@link https://geojson.org/ | GeoJSON format}.
22
+ */
23
+ export declare class Geopoint implements GeopointCoordinates {
24
+ static fromNodeValue(nodeValue: string): Geopoint | null;
25
+ readonly latitude: number;
26
+ readonly longitude: number;
27
+ private constructor();
28
+ }
@@ -0,0 +1,12 @@
1
+ import { Geopoint } from './Geopoint.ts';
2
+ import { GeopointRuntimeValue } from './geopointCodec.ts';
3
+ import { GeotraceLine } from './GeotraceLine.ts';
4
+ export type GeotracePoints = readonly [Geopoint, Geopoint, ...Geopoint[]];
5
+ export declare class Geotrace {
6
+ readonly geopoints: GeotracePoints;
7
+ static fromEncodedGeotrace(encoded: string): Geotrace | null;
8
+ static fromEncodedValues(values: readonly string[]): Geotrace | null;
9
+ static fromGeopoints(geopoints: readonly GeopointRuntimeValue[]): Geotrace | null;
10
+ readonly lines: readonly GeotraceLine[];
11
+ private constructor();
12
+ }
@@ -0,0 +1,11 @@
1
+ import { Geopoint } from './Geopoint.ts';
2
+ interface GeotraceLinePoints {
3
+ readonly start: Geopoint;
4
+ readonly end: Geopoint;
5
+ }
6
+ export declare class GeotraceLine implements GeotraceLinePoints {
7
+ readonly start: Geopoint;
8
+ readonly end: Geopoint;
9
+ constructor(points: GeotraceLinePoints);
10
+ }
11
+ export {};
@@ -0,0 +1,2 @@
1
+ import { GeoValueEncoder, GeoValueType } from './GeoValueCodec.ts';
2
+ export declare const encodeValueStubFactory: <RuntimeInputValue>(valueType: GeoValueType) => GeoValueEncoder<RuntimeInputValue>;
@@ -0,0 +1,4 @@
1
+ import { Geopoint } from './Geopoint.ts';
2
+ import { GeoValueCodec } from './GeoValueCodec.ts';
3
+ export type GeopointRuntimeValue = Geopoint | null;
4
+ export declare const geopointCodec: GeoValueCodec<'geopoint', GeopointRuntimeValue>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getodk/xpath",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "XPath implementation for ODK Web Forms",
6
6
  "type": "module",
@@ -31,7 +31,7 @@
31
31
  "README.md"
32
32
  ],
33
33
  "engines": {
34
- "node": "^18.20.4 || ^20.17.0 || ^22.9.0",
34
+ "node": "^18.20.5 || ^20.18.1 || ^22.12.0",
35
35
  "yarn": "1.22.22"
36
36
  },
37
37
  "scripts": {
@@ -54,24 +54,27 @@
54
54
  "test:types:test": "tsc --project ./test/tsconfig.json --emitDeclarationOnly false --noEmit"
55
55
  },
56
56
  "dependencies": {
57
- "@getodk/common": "0.5.0",
57
+ "@getodk/common": "0.5.1",
58
58
  "@js-temporal/polyfill": "^0.4.4",
59
59
  "crypto-js": "^4.2.0",
60
60
  "itertools-ts": "^1.27.1"
61
61
  },
62
62
  "devDependencies": {
63
- "@babel/core": "^7.25.2",
63
+ "@babel/core": "^7.26.0",
64
64
  "@getodk/tree-sitter-xpath": "0.1.2",
65
- "@playwright/test": "^1.47.2",
65
+ "@playwright/test": "^1.49.1",
66
66
  "@types/crypto-js": "^4.2.2",
67
- "@vitest/browser": "^2.1.1",
67
+ "@vitest/browser": "^2.1.8",
68
68
  "babel-plugin-transform-jsbi-to-bigint": "^1.4.0",
69
69
  "jsdom": "^25.0.1",
70
- "vite": "^5.4.8",
71
- "vite-plugin-babel": "^1.2.0",
72
- "vite-plugin-dts": "^4.2.2",
70
+ "vite": "^5.4.11",
71
+ "vite-plugin-babel": "^1.3.0",
72
+ "vite-plugin-dts": "^4.3.0",
73
73
  "vite-plugin-no-bundle": "^4.0.0",
74
- "vitest": "^2.1.1",
75
- "web-tree-sitter": "0.23.0"
74
+ "vitest": "^2.1.8",
75
+ "web-tree-sitter": "0.24.5"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public"
76
79
  }
77
80
  }