@xyo-network/diviner-jsonpath 7.2.3 → 7.3.1

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 (41) hide show
  1. package/dist/neutral/index.d.ts +2 -2
  2. package/dist/neutral/index.d.ts.map +1 -1
  3. package/dist/neutral/index.mjs +91 -3
  4. package/dist/neutral/index.mjs.map +4 -4
  5. package/dist/neutral/memory/Diviner.d.ts +20 -0
  6. package/dist/neutral/memory/Diviner.d.ts.map +1 -0
  7. package/dist/neutral/memory/index.d.ts +3 -0
  8. package/dist/neutral/memory/index.d.ts.map +1 -0
  9. package/dist/neutral/memory/jsonpath/index.d.ts +2 -0
  10. package/dist/neutral/memory/jsonpath/index.d.ts.map +1 -0
  11. package/dist/neutral/memory/jsonpath/isScalarJsonPathExpression.d.ts +8 -0
  12. package/dist/neutral/memory/jsonpath/isScalarJsonPathExpression.d.ts.map +1 -0
  13. package/dist/neutral/memory/jsonpath/toPayloadTransformer.d.ts +8 -0
  14. package/dist/neutral/memory/jsonpath/toPayloadTransformer.d.ts.map +1 -0
  15. package/dist/neutral/memory.d.ts +2 -0
  16. package/dist/neutral/memory.d.ts.map +1 -0
  17. package/dist/neutral/memory.mjs +86 -0
  18. package/dist/neutral/memory.mjs.map +7 -0
  19. package/dist/neutral/model/Config.d.ts +43 -0
  20. package/dist/neutral/model/Config.d.ts.map +1 -0
  21. package/dist/neutral/model/Params.d.ts +8 -0
  22. package/dist/neutral/model/Params.d.ts.map +1 -0
  23. package/dist/neutral/model/Schema.d.ts +11 -0
  24. package/dist/neutral/model/Schema.d.ts.map +1 -0
  25. package/dist/neutral/model/index.d.ts +5 -0
  26. package/dist/neutral/model/index.d.ts.map +1 -0
  27. package/dist/neutral/model/jsonpath/JsonPathTransformExpression.d.ts +20 -0
  28. package/dist/neutral/model/jsonpath/JsonPathTransformExpression.d.ts.map +1 -0
  29. package/dist/neutral/model/jsonpath/PayloadTransformer.d.ts +3 -0
  30. package/dist/neutral/model/jsonpath/PayloadTransformer.d.ts.map +1 -0
  31. package/dist/neutral/model/jsonpath/SchemaToJsonPathTransformExpressionDictionary.d.ts +9 -0
  32. package/dist/neutral/model/jsonpath/SchemaToJsonPathTransformExpressionDictionary.d.ts.map +1 -0
  33. package/dist/neutral/model/jsonpath/SchemaToPayloadTransformersDictionary.d.ts +6 -0
  34. package/dist/neutral/model/jsonpath/SchemaToPayloadTransformersDictionary.d.ts.map +1 -0
  35. package/dist/neutral/model/jsonpath/index.d.ts +5 -0
  36. package/dist/neutral/model/jsonpath/index.d.ts.map +1 -0
  37. package/dist/neutral/model.d.ts +2 -0
  38. package/dist/neutral/model.d.ts.map +1 -0
  39. package/dist/neutral/model.mjs +33 -0
  40. package/dist/neutral/model.mjs.map +7 -0
  41. package/package.json +24 -8
@@ -1,3 +1,3 @@
1
- export * from '@xyo-network/diviner-jsonpath-memory';
2
- export * from '@xyo-network/diviner-jsonpath-model';
1
+ export * from './memory.ts';
2
+ export * from './model.ts';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAA;AACpD,cAAc,qCAAqC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
@@ -1,4 +1,92 @@
1
- // src/index.ts
2
- export * from "@xyo-network/diviner-jsonpath-memory";
3
- export * from "@xyo-network/diviner-jsonpath-model";
1
+ // src/memory/Diviner.ts
2
+ import { assertEx } from "@ariestools/sdk";
3
+ import { AbstractDiviner } from "@xyo-network/sdk/diviner-abstract";
4
+ import { PayloadBuilder, PayloadSchema } from "@xyo-network/sdk-protocol";
5
+
6
+ // src/model/Config.ts
7
+ import {
8
+ zodAsFactory,
9
+ zodIsFactory,
10
+ zodToFactory
11
+ } from "@ariestools/sdk";
12
+ import { DivinerConfigZod } from "@xyo-network/sdk/diviner-model";
13
+ import { asSchema as asSchema2 } from "@xyo-network/sdk-protocol";
14
+ import * as z from "zod/mini";
15
+
16
+ // src/model/Schema.ts
17
+ import { asSchema } from "@xyo-network/sdk-protocol";
18
+ var JsonPathDivinerSchema = asSchema("network.xyo.diviner.jsonpath", true);
19
+
20
+ // src/model/Config.ts
21
+ var JsonPathDivinerConfigSchema = asSchema2(`${JsonPathDivinerSchema}.config`, true);
22
+ var JsonPathDivinerConfigZod = z.extend(DivinerConfigZod, {
23
+ destinationSchema: z.optional(z.custom()),
24
+ schema: z.literal(JsonPathDivinerConfigSchema),
25
+ transforms: z.optional(z.array(z.custom()))
26
+ });
27
+ var isJsonPathDivinerConfig = zodIsFactory(JsonPathDivinerConfigZod);
28
+ var asJsonPathDivinerConfig = zodAsFactory(JsonPathDivinerConfigZod, "asJsonPathDivinerConfig");
29
+ var toJsonPathDivinerConfig = zodToFactory(JsonPathDivinerConfigZod, "toJsonPathDivinerConfig");
30
+
31
+ // src/memory/jsonpath/toPayloadTransformer.ts
32
+ import { JSONPath } from "jsonpath-plus";
33
+ var toPayloadTransformer = (transformExpression) => {
34
+ const {
35
+ defaultValue,
36
+ destinationField,
37
+ sourcePathExpression
38
+ } = transformExpression;
39
+ const transformer = (x) => {
40
+ const source = JSONPath({ path: sourcePathExpression, json: x })[0];
41
+ const transformed = {};
42
+ const destinationValue = source === void 0 ? defaultValue : source;
43
+ if (destinationValue !== void 0) transformed[destinationField] = destinationValue;
44
+ return transformed;
45
+ };
46
+ return transformer;
47
+ };
48
+
49
+ // src/memory/Diviner.ts
50
+ var JsonPathDiviner = class extends AbstractDiviner {
51
+ static configSchemas = [...super.configSchemas, JsonPathDivinerConfigSchema];
52
+ static defaultConfigSchema = JsonPathDivinerConfigSchema;
53
+ _transforms;
54
+ /**
55
+ * The schema to use for the destination payloads
56
+ */
57
+ get destinationSchema() {
58
+ return this.config.destinationSchema ?? PayloadSchema;
59
+ }
60
+ /**
61
+ * Dictionary of schemas to payload transformers for creating indexes
62
+ * from the payloads within a Bound Witness
63
+ */
64
+ get transforms() {
65
+ if (!this._transforms) {
66
+ const transforms = assertEx(this.config.transforms, () => "config.transforms is not defined");
67
+ this._transforms = transforms.map(toPayloadTransformer);
68
+ }
69
+ return this._transforms;
70
+ }
71
+ async divineHandler(payloads) {
72
+ if (!payloads) return [];
73
+ return await Promise.all(
74
+ payloads.map(async (payload) => {
75
+ const fields = this.transforms.map((transform) => transform(payload));
76
+ const sources = await PayloadBuilder.dataHashes([payload]);
77
+ return new PayloadBuilder({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build();
78
+ })
79
+ );
80
+ }
81
+ };
82
+ export {
83
+ JsonPathDiviner,
84
+ JsonPathDivinerConfigSchema,
85
+ JsonPathDivinerConfigZod,
86
+ JsonPathDivinerSchema,
87
+ asJsonPathDivinerConfig,
88
+ isJsonPathDivinerConfig,
89
+ toJsonPathDivinerConfig,
90
+ toPayloadTransformer
91
+ };
4
92
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from '@xyo-network/diviner-jsonpath-memory'\nexport * from '@xyo-network/diviner-jsonpath-model'\n"],
5
- "mappings": ";AAAA,cAAc;AACd,cAAc;",
6
- "names": []
3
+ "sources": ["../../src/memory/Diviner.ts", "../../src/model/Config.ts", "../../src/model/Schema.ts", "../../src/memory/jsonpath/toPayloadTransformer.ts"],
4
+ "sourcesContent": ["import { assertEx } from '@ariestools/sdk'\nimport { AbstractDiviner } from '@xyo-network/sdk/diviner-abstract'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk/diviner-model'\nimport type {\n Payload,\n Schema, WithoutSchema,\n} from '@xyo-network/sdk-protocol'\nimport { PayloadBuilder, PayloadSchema } from '@xyo-network/sdk-protocol'\n\nimport type { JsonPathDivinerParams, PayloadTransformer } from '../model/index.ts'\nimport { JsonPathDivinerConfigSchema } from '../model/index.ts'\nimport { toPayloadTransformer } from './jsonpath/index.ts'\n\nexport class JsonPathDiviner<\n TParams extends JsonPathDivinerParams = JsonPathDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): Schema {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers for creating indexes\n * from the payloads within a Bound Witness\n */\n protected get transforms(): PayloadTransformer[] {\n if (!this._transforms) {\n const transforms = assertEx(this.config.transforms, () => 'config.transforms is not defined')\n this._transforms = transforms.map(toPayloadTransformer)\n }\n return this._transforms\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n // Create the indexes from the tuples\n return await Promise.all(\n payloads.map<Promise<TOut>>(async (payload) => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const fields = this.transforms.map(transform => transform(payload)) as WithoutSchema<TOut>[]\n // Include all the sources for reference\n const sources = await PayloadBuilder.dataHashes([payload])\n // Build and return the index\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return new PayloadBuilder<TOut>({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build()\n }),\n )\n }\n}\n", "import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport type { DivinerConfig } from '@xyo-network/sdk/diviner-model'\nimport { DivinerConfigZod } from '@xyo-network/sdk/diviner-model'\nimport type { Schema } from '@xyo-network/sdk-protocol'\nimport { asSchema } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport type { JsonPathTransformExpression } from './jsonpath/index.ts'\nimport { JsonPathDivinerSchema } from './Schema.ts'\n\n/**\n * The config schema for the JSON Path diviner\n */\nexport const JsonPathDivinerConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${JsonPathDivinerSchema}.config`, true)\n\n/**\n * The config schema type for the JSON Path diviner\n */\nexport type JsonPathDivinerConfigSchema = typeof JsonPathDivinerConfigSchema\n\n/**\n * The Zod schema for the JSON Path diviner config\n */\nexport const JsonPathDivinerConfigZod: z.ZodMiniObject<\n Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {\n destinationSchema: z.ZodMiniOptional<z.ZodMiniCustom<Schema, Schema>>\n schema: z.ZodMiniLiteral<JsonPathDivinerConfigSchema>\n transforms: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniCustom<JsonPathTransformExpression, JsonPathTransformExpression>>>\n },\n z.core.$strip\n> = z.extend(DivinerConfigZod, {\n destinationSchema: z.optional(z.custom<Schema>()),\n schema: z.literal(JsonPathDivinerConfigSchema),\n transforms: z.optional(z.array(z.custom<JsonPathTransformExpression>())),\n})\n\n/**\n * The configuration for the JSON Path diviner\n */\nexport type JsonPathDivinerConfig = DivinerConfig<\n {\n /**\n * The schema to use for the destination payloads\n */\n destinationSchema?: Schema\n /**\n * The JSON Path transform expressions to apply to the payloads\n */\n transforms?: JsonPathTransformExpression[]\n } & { schema: JsonPathDivinerConfigSchema }\n>\n\nexport const isJsonPathDivinerConfig: ReturnType<typeof zodIsFactory<JsonPathDivinerConfig>> = zodIsFactory(JsonPathDivinerConfigZod)\nexport const asJsonPathDivinerConfig: ReturnType<typeof zodAsFactory<JsonPathDivinerConfig>> = zodAsFactory(JsonPathDivinerConfigZod, 'asJsonPathDivinerConfig')\nexport const toJsonPathDivinerConfig: ReturnType<typeof zodToFactory<JsonPathDivinerConfig>> = zodToFactory(JsonPathDivinerConfigZod, 'toJsonPathDivinerConfig')\n", "import { asSchema } from '@xyo-network/sdk-protocol'\n/**\n * The schema used for the JSONPath Diviner.\n */\nexport const JsonPathDivinerSchema: 'network.xyo.diviner.jsonpath' & {\n readonly __schema: true\n} = asSchema('network.xyo.diviner.jsonpath', true)\n\n/**\n * The schema type used for the JSONPath Diviner.\n */\nexport type JsonPathDivinerSchema = typeof JsonPathDivinerSchema\n", "/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */\nimport type { Payload } from '@xyo-network/sdk-protocol'\nimport { JSONPath } from 'jsonpath-plus'\n\nimport type { JsonPathTransformExpression, PayloadTransformer } from '../../model/index.ts'\n\n/**\n * Converts a JSON Path transform expression to a payload transformer\n * @param transformExpression The transform expression to convert\n * @returns The payload transformer for the JSON Path transform expression\n */\nexport const toPayloadTransformer = (transformExpression: JsonPathTransformExpression): PayloadTransformer => {\n const {\n defaultValue, destinationField, sourcePathExpression,\n } = transformExpression\n const transformer: PayloadTransformer = (x: Payload) => {\n const source = JSONPath({ path: sourcePathExpression, json: x })[0]\n // TODO: If the expression should return multiple values, drop the [0] and\n // return the full match array from JSONPath({ path, json }) instead of the first match.\n // const source =\n // isScalarJsonPathExpression(transformExpression.sourcePathExpression) ?\n // JSONPath({ path: sourcePathExpression, json: x })[0]\n // : JSONPath({ path: sourcePathExpression, json: x })\n const transformed: Record<string, unknown> = {}\n // Assign the source value to the destination field or the default value if the source is undefined\n const destinationValue = source === undefined ? defaultValue : source\n if (destinationValue !== undefined) transformed[destinationField] = destinationValue\n return transformed\n }\n return transformer\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAMhC,SAAS,gBAAgB,qBAAqB;;;ACP9C;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,wBAAwB;AAEjC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACPnB,SAAS,gBAAgB;AAIlB,IAAM,wBAET,SAAS,gCAAgC,IAAI;;;ADS1C,IAAM,8BAETC,UAAS,GAAG,qBAAqB,WAAW,IAAI;AAU7C,IAAM,2BAOP,SAAO,kBAAkB;AAAA,EAC7B,mBAAqB,WAAW,SAAe,CAAC;AAAA,EAChD,QAAU,UAAQ,2BAA2B;AAAA,EAC7C,YAAc,WAAW,QAAQ,SAAoC,CAAC,CAAC;AACzE,CAAC;AAkBM,IAAM,0BAAkF,aAAa,wBAAwB;AAC7H,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;AACxJ,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;;;AExD/J,SAAS,gBAAgB;AASlB,IAAM,uBAAuB,CAAC,wBAAyE;AAC5G,QAAM;AAAA,IACJ;AAAA,IAAc;AAAA,IAAkB;AAAA,EAClC,IAAI;AACJ,QAAM,cAAkC,CAAC,MAAe;AACtD,UAAM,SAAS,SAAS,EAAE,MAAM,sBAAsB,MAAM,EAAE,CAAC,EAAE,CAAC;AAOlE,UAAM,cAAuC,CAAC;AAE9C,UAAM,mBAAmB,WAAW,SAAY,eAAe;AAC/D,QAAI,qBAAqB,OAAW,aAAY,gBAAgB,IAAI;AACpE,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;AHjBO,IAAM,kBAAN,cASG,gBAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,2BAA2B;AAAA,EACvG,OAAyB,sBAA8B;AAAA,EAE7C;AAAA;AAAA;AAAA;AAAA,EAKV,IAAc,oBAA4B;AACxC,WAAO,KAAK,OAAO,qBAAqB;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAc,aAAmC;AAC/C,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,aAAa,SAAS,KAAK,OAAO,YAAY,MAAM,kCAAkC;AAC5F,WAAK,cAAc,WAAW,IAAI,oBAAoB;AAAA,IACxD;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC,SAAU,QAAO,CAAC;AAEvB,WAAO,MAAM,QAAQ;AAAA,MACnB,SAAS,IAAmB,OAAO,YAAY;AAE7C,cAAM,SAAS,KAAK,WAAW,IAAI,eAAa,UAAU,OAAO,CAAC;AAElE,cAAM,UAAU,MAAM,eAAe,WAAW,CAAC,OAAO,CAAC;AAGzD,eAAO,IAAI,eAAqB,EAAE,QAAQ,KAAK,kBAAkB,CAAC,EAAE,OAAO,OAAO,OAAO,EAAE,QAAQ,GAAG,GAAG,MAAM,CAAC,EAAE,MAAM;AAAA,MAC1H,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
6
+ "names": ["asSchema", "asSchema"]
7
7
  }
@@ -0,0 +1,20 @@
1
+ import { AbstractDiviner } from '@xyo-network/sdk/diviner-abstract';
2
+ import type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk/diviner-model';
3
+ import type { Payload, Schema } from '@xyo-network/sdk-protocol';
4
+ import type { JsonPathDivinerParams, PayloadTransformer } from '../model/index.ts';
5
+ export declare class JsonPathDiviner<TParams extends JsonPathDivinerParams = JsonPathDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
6
+ static readonly configSchemas: Schema[];
7
+ static readonly defaultConfigSchema: Schema;
8
+ protected _transforms: PayloadTransformer[] | undefined;
9
+ /**
10
+ * The schema to use for the destination payloads
11
+ */
12
+ protected get destinationSchema(): Schema;
13
+ /**
14
+ * Dictionary of schemas to payload transformers for creating indexes
15
+ * from the payloads within a Bound Witness
16
+ */
17
+ protected get transforms(): PayloadTransformer[];
18
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
19
+ }
20
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../../src/memory/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAC7F,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACP,MAAM,2BAA2B,CAAA;AAGlC,OAAO,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAIlF,qBAAa,eAAe,CAC1B,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,EAC7D,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAwD;IACxG,gBAAyB,mBAAmB,EAAE,MAAM,CAA8B;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;;OAGG;IACH,SAAS,KAAK,UAAU,IAAI,kBAAkB,EAAE,CAM/C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;CAe1E"}
@@ -0,0 +1,3 @@
1
+ export * from './Diviner.ts';
2
+ export * from './jsonpath/index.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './toPayloadTransformer.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/jsonpath/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Determines if a JSON path expression is a scalar expression (targeting
3
+ * a single property in the JSON object) or a multiple value expression
4
+ * @param jsonPath The JSON path expression to check
5
+ * @returns
6
+ */
7
+ export declare const isScalarJsonPathExpression: (jsonPath: string) => boolean;
8
+ //# sourceMappingURL=isScalarJsonPathExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isScalarJsonPathExpression.d.ts","sourceRoot":"","sources":["../../../../src/memory/jsonpath/isScalarJsonPathExpression.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,UAAU,MAAM,KAAG,OAQ7D,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { JsonPathTransformExpression, PayloadTransformer } from '../../model/index.ts';
2
+ /**
3
+ * Converts a JSON Path transform expression to a payload transformer
4
+ * @param transformExpression The transform expression to convert
5
+ * @returns The payload transformer for the JSON Path transform expression
6
+ */
7
+ export declare const toPayloadTransformer: (transformExpression: JsonPathTransformExpression) => PayloadTransformer;
8
+ //# sourceMappingURL=toPayloadTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toPayloadTransformer.d.ts","sourceRoot":"","sources":["../../../../src/memory/jsonpath/toPayloadTransformer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE3F;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,qBAAqB,2BAA2B,KAAG,kBAmBvF,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './memory/index.ts';
2
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/memory.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,86 @@
1
+ // src/memory/Diviner.ts
2
+ import { assertEx } from "@ariestools/sdk";
3
+ import { AbstractDiviner } from "@xyo-network/sdk/diviner-abstract";
4
+ import { PayloadBuilder, PayloadSchema } from "@xyo-network/sdk-protocol";
5
+
6
+ // src/model/Config.ts
7
+ import {
8
+ zodAsFactory,
9
+ zodIsFactory,
10
+ zodToFactory
11
+ } from "@ariestools/sdk";
12
+ import { DivinerConfigZod } from "@xyo-network/sdk/diviner-model";
13
+ import { asSchema as asSchema2 } from "@xyo-network/sdk-protocol";
14
+ import * as z from "zod/mini";
15
+
16
+ // src/model/Schema.ts
17
+ import { asSchema } from "@xyo-network/sdk-protocol";
18
+ var JsonPathDivinerSchema = asSchema("network.xyo.diviner.jsonpath", true);
19
+
20
+ // src/model/Config.ts
21
+ var JsonPathDivinerConfigSchema = asSchema2(`${JsonPathDivinerSchema}.config`, true);
22
+ var JsonPathDivinerConfigZod = z.extend(DivinerConfigZod, {
23
+ destinationSchema: z.optional(z.custom()),
24
+ schema: z.literal(JsonPathDivinerConfigSchema),
25
+ transforms: z.optional(z.array(z.custom()))
26
+ });
27
+ var isJsonPathDivinerConfig = zodIsFactory(JsonPathDivinerConfigZod);
28
+ var asJsonPathDivinerConfig = zodAsFactory(JsonPathDivinerConfigZod, "asJsonPathDivinerConfig");
29
+ var toJsonPathDivinerConfig = zodToFactory(JsonPathDivinerConfigZod, "toJsonPathDivinerConfig");
30
+
31
+ // src/memory/jsonpath/toPayloadTransformer.ts
32
+ import { JSONPath } from "jsonpath-plus";
33
+ var toPayloadTransformer = (transformExpression) => {
34
+ const {
35
+ defaultValue,
36
+ destinationField,
37
+ sourcePathExpression
38
+ } = transformExpression;
39
+ const transformer = (x) => {
40
+ const source = JSONPath({ path: sourcePathExpression, json: x })[0];
41
+ const transformed = {};
42
+ const destinationValue = source === void 0 ? defaultValue : source;
43
+ if (destinationValue !== void 0) transformed[destinationField] = destinationValue;
44
+ return transformed;
45
+ };
46
+ return transformer;
47
+ };
48
+
49
+ // src/memory/Diviner.ts
50
+ var JsonPathDiviner = class extends AbstractDiviner {
51
+ static configSchemas = [...super.configSchemas, JsonPathDivinerConfigSchema];
52
+ static defaultConfigSchema = JsonPathDivinerConfigSchema;
53
+ _transforms;
54
+ /**
55
+ * The schema to use for the destination payloads
56
+ */
57
+ get destinationSchema() {
58
+ return this.config.destinationSchema ?? PayloadSchema;
59
+ }
60
+ /**
61
+ * Dictionary of schemas to payload transformers for creating indexes
62
+ * from the payloads within a Bound Witness
63
+ */
64
+ get transforms() {
65
+ if (!this._transforms) {
66
+ const transforms = assertEx(this.config.transforms, () => "config.transforms is not defined");
67
+ this._transforms = transforms.map(toPayloadTransformer);
68
+ }
69
+ return this._transforms;
70
+ }
71
+ async divineHandler(payloads) {
72
+ if (!payloads) return [];
73
+ return await Promise.all(
74
+ payloads.map(async (payload) => {
75
+ const fields = this.transforms.map((transform) => transform(payload));
76
+ const sources = await PayloadBuilder.dataHashes([payload]);
77
+ return new PayloadBuilder({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build();
78
+ })
79
+ );
80
+ }
81
+ };
82
+ export {
83
+ JsonPathDiviner,
84
+ toPayloadTransformer
85
+ };
86
+ //# sourceMappingURL=memory.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/memory/Diviner.ts", "../../src/model/Config.ts", "../../src/model/Schema.ts", "../../src/memory/jsonpath/toPayloadTransformer.ts"],
4
+ "sourcesContent": ["import { assertEx } from '@ariestools/sdk'\nimport { AbstractDiviner } from '@xyo-network/sdk/diviner-abstract'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/sdk/diviner-model'\nimport type {\n Payload,\n Schema, WithoutSchema,\n} from '@xyo-network/sdk-protocol'\nimport { PayloadBuilder, PayloadSchema } from '@xyo-network/sdk-protocol'\n\nimport type { JsonPathDivinerParams, PayloadTransformer } from '../model/index.ts'\nimport { JsonPathDivinerConfigSchema } from '../model/index.ts'\nimport { toPayloadTransformer } from './jsonpath/index.ts'\n\nexport class JsonPathDiviner<\n TParams extends JsonPathDivinerParams = JsonPathDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): Schema {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers for creating indexes\n * from the payloads within a Bound Witness\n */\n protected get transforms(): PayloadTransformer[] {\n if (!this._transforms) {\n const transforms = assertEx(this.config.transforms, () => 'config.transforms is not defined')\n this._transforms = transforms.map(toPayloadTransformer)\n }\n return this._transforms\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n // Create the indexes from the tuples\n return await Promise.all(\n payloads.map<Promise<TOut>>(async (payload) => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const fields = this.transforms.map(transform => transform(payload)) as WithoutSchema<TOut>[]\n // Include all the sources for reference\n const sources = await PayloadBuilder.dataHashes([payload])\n // Build and return the index\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return new PayloadBuilder<TOut>({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build()\n }),\n )\n }\n}\n", "import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport type { DivinerConfig } from '@xyo-network/sdk/diviner-model'\nimport { DivinerConfigZod } from '@xyo-network/sdk/diviner-model'\nimport type { Schema } from '@xyo-network/sdk-protocol'\nimport { asSchema } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport type { JsonPathTransformExpression } from './jsonpath/index.ts'\nimport { JsonPathDivinerSchema } from './Schema.ts'\n\n/**\n * The config schema for the JSON Path diviner\n */\nexport const JsonPathDivinerConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${JsonPathDivinerSchema}.config`, true)\n\n/**\n * The config schema type for the JSON Path diviner\n */\nexport type JsonPathDivinerConfigSchema = typeof JsonPathDivinerConfigSchema\n\n/**\n * The Zod schema for the JSON Path diviner config\n */\nexport const JsonPathDivinerConfigZod: z.ZodMiniObject<\n Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {\n destinationSchema: z.ZodMiniOptional<z.ZodMiniCustom<Schema, Schema>>\n schema: z.ZodMiniLiteral<JsonPathDivinerConfigSchema>\n transforms: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniCustom<JsonPathTransformExpression, JsonPathTransformExpression>>>\n },\n z.core.$strip\n> = z.extend(DivinerConfigZod, {\n destinationSchema: z.optional(z.custom<Schema>()),\n schema: z.literal(JsonPathDivinerConfigSchema),\n transforms: z.optional(z.array(z.custom<JsonPathTransformExpression>())),\n})\n\n/**\n * The configuration for the JSON Path diviner\n */\nexport type JsonPathDivinerConfig = DivinerConfig<\n {\n /**\n * The schema to use for the destination payloads\n */\n destinationSchema?: Schema\n /**\n * The JSON Path transform expressions to apply to the payloads\n */\n transforms?: JsonPathTransformExpression[]\n } & { schema: JsonPathDivinerConfigSchema }\n>\n\nexport const isJsonPathDivinerConfig: ReturnType<typeof zodIsFactory<JsonPathDivinerConfig>> = zodIsFactory(JsonPathDivinerConfigZod)\nexport const asJsonPathDivinerConfig: ReturnType<typeof zodAsFactory<JsonPathDivinerConfig>> = zodAsFactory(JsonPathDivinerConfigZod, 'asJsonPathDivinerConfig')\nexport const toJsonPathDivinerConfig: ReturnType<typeof zodToFactory<JsonPathDivinerConfig>> = zodToFactory(JsonPathDivinerConfigZod, 'toJsonPathDivinerConfig')\n", "import { asSchema } from '@xyo-network/sdk-protocol'\n/**\n * The schema used for the JSONPath Diviner.\n */\nexport const JsonPathDivinerSchema: 'network.xyo.diviner.jsonpath' & {\n readonly __schema: true\n} = asSchema('network.xyo.diviner.jsonpath', true)\n\n/**\n * The schema type used for the JSONPath Diviner.\n */\nexport type JsonPathDivinerSchema = typeof JsonPathDivinerSchema\n", "/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */\nimport type { Payload } from '@xyo-network/sdk-protocol'\nimport { JSONPath } from 'jsonpath-plus'\n\nimport type { JsonPathTransformExpression, PayloadTransformer } from '../../model/index.ts'\n\n/**\n * Converts a JSON Path transform expression to a payload transformer\n * @param transformExpression The transform expression to convert\n * @returns The payload transformer for the JSON Path transform expression\n */\nexport const toPayloadTransformer = (transformExpression: JsonPathTransformExpression): PayloadTransformer => {\n const {\n defaultValue, destinationField, sourcePathExpression,\n } = transformExpression\n const transformer: PayloadTransformer = (x: Payload) => {\n const source = JSONPath({ path: sourcePathExpression, json: x })[0]\n // TODO: If the expression should return multiple values, drop the [0] and\n // return the full match array from JSONPath({ path, json }) instead of the first match.\n // const source =\n // isScalarJsonPathExpression(transformExpression.sourcePathExpression) ?\n // JSONPath({ path: sourcePathExpression, json: x })[0]\n // : JSONPath({ path: sourcePathExpression, json: x })\n const transformed: Record<string, unknown> = {}\n // Assign the source value to the destination field or the default value if the source is undefined\n const destinationValue = source === undefined ? defaultValue : source\n if (destinationValue !== undefined) transformed[destinationField] = destinationValue\n return transformed\n }\n return transformer\n}\n"],
5
+ "mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAMhC,SAAS,gBAAgB,qBAAqB;;;ACP9C;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,wBAAwB;AAEjC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACPnB,SAAS,gBAAgB;AAIlB,IAAM,wBAET,SAAS,gCAAgC,IAAI;;;ADS1C,IAAM,8BAETC,UAAS,GAAG,qBAAqB,WAAW,IAAI;AAU7C,IAAM,2BAOP,SAAO,kBAAkB;AAAA,EAC7B,mBAAqB,WAAW,SAAe,CAAC;AAAA,EAChD,QAAU,UAAQ,2BAA2B;AAAA,EAC7C,YAAc,WAAW,QAAQ,SAAoC,CAAC,CAAC;AACzE,CAAC;AAkBM,IAAM,0BAAkF,aAAa,wBAAwB;AAC7H,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;AACxJ,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;;;AExD/J,SAAS,gBAAgB;AASlB,IAAM,uBAAuB,CAAC,wBAAyE;AAC5G,QAAM;AAAA,IACJ;AAAA,IAAc;AAAA,IAAkB;AAAA,EAClC,IAAI;AACJ,QAAM,cAAkC,CAAC,MAAe;AACtD,UAAM,SAAS,SAAS,EAAE,MAAM,sBAAsB,MAAM,EAAE,CAAC,EAAE,CAAC;AAOlE,UAAM,cAAuC,CAAC;AAE9C,UAAM,mBAAmB,WAAW,SAAY,eAAe;AAC/D,QAAI,qBAAqB,OAAW,aAAY,gBAAgB,IAAI;AACpE,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;AHjBO,IAAM,kBAAN,cASG,gBAAgD;AAAA,EACxD,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,2BAA2B;AAAA,EACvG,OAAyB,sBAA8B;AAAA,EAE7C;AAAA;AAAA;AAAA;AAAA,EAKV,IAAc,oBAA4B;AACxC,WAAO,KAAK,OAAO,qBAAqB;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAc,aAAmC;AAC/C,QAAI,CAAC,KAAK,aAAa;AACrB,YAAM,aAAa,SAAS,KAAK,OAAO,YAAY,MAAM,kCAAkC;AAC5F,WAAK,cAAc,WAAW,IAAI,oBAAoB;AAAA,IACxD;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC,SAAU,QAAO,CAAC;AAEvB,WAAO,MAAM,QAAQ;AAAA,MACnB,SAAS,IAAmB,OAAO,YAAY;AAE7C,cAAM,SAAS,KAAK,WAAW,IAAI,eAAa,UAAU,OAAO,CAAC;AAElE,cAAM,UAAU,MAAM,eAAe,WAAW,CAAC,OAAO,CAAC;AAGzD,eAAO,IAAI,eAAqB,EAAE,QAAQ,KAAK,kBAAkB,CAAC,EAAE,OAAO,OAAO,OAAO,EAAE,QAAQ,GAAG,GAAG,MAAM,CAAC,EAAE,MAAM;AAAA,MAC1H,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
6
+ "names": ["asSchema", "asSchema"]
7
+ }
@@ -0,0 +1,43 @@
1
+ import { zodAsFactory, zodIsFactory, zodToFactory } from '@ariestools/sdk';
2
+ import type { DivinerConfig } from '@xyo-network/sdk/diviner-model';
3
+ import { DivinerConfigZod } from '@xyo-network/sdk/diviner-model';
4
+ import type { Schema } from '@xyo-network/sdk-protocol';
5
+ import * as z from 'zod/mini';
6
+ import type { JsonPathTransformExpression } from './jsonpath/index.ts';
7
+ /**
8
+ * The config schema for the JSON Path diviner
9
+ */
10
+ export declare const JsonPathDivinerConfigSchema: string & {
11
+ readonly __schema: true;
12
+ };
13
+ /**
14
+ * The config schema type for the JSON Path diviner
15
+ */
16
+ export type JsonPathDivinerConfigSchema = typeof JsonPathDivinerConfigSchema;
17
+ /**
18
+ * The Zod schema for the JSON Path diviner config
19
+ */
20
+ export declare const JsonPathDivinerConfigZod: z.ZodMiniObject<Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {
21
+ destinationSchema: z.ZodMiniOptional<z.ZodMiniCustom<Schema, Schema>>;
22
+ schema: z.ZodMiniLiteral<JsonPathDivinerConfigSchema>;
23
+ transforms: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniCustom<JsonPathTransformExpression, JsonPathTransformExpression>>>;
24
+ }, z.core.$strip>;
25
+ /**
26
+ * The configuration for the JSON Path diviner
27
+ */
28
+ export type JsonPathDivinerConfig = DivinerConfig<{
29
+ /**
30
+ * The schema to use for the destination payloads
31
+ */
32
+ destinationSchema?: Schema;
33
+ /**
34
+ * The JSON Path transform expressions to apply to the payloads
35
+ */
36
+ transforms?: JsonPathTransformExpression[];
37
+ } & {
38
+ schema: JsonPathDivinerConfigSchema;
39
+ }>;
40
+ export declare const isJsonPathDivinerConfig: ReturnType<typeof zodIsFactory<JsonPathDivinerConfig>>;
41
+ export declare const asJsonPathDivinerConfig: ReturnType<typeof zodAsFactory<JsonPathDivinerConfig>>;
42
+ export declare const toJsonPathDivinerConfig: ReturnType<typeof zodToFactory<JsonPathDivinerConfig>>;
43
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../src/model/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAAE,YAAY,EAAE,YAAY,EACzC,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAGtE;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,GAAG;IACjD,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;CAC4B,CAAA;AAErD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,2BAA2B,CAAA;AAE5E;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,aAAa,CACpD,IAAI,CAAC,CAAC,OAAO,gBAAgB,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,GAAG;IACnD,iBAAiB,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACrE,MAAM,EAAE,CAAC,CAAC,cAAc,CAAC,2BAA2B,CAAC,CAAA;IACrD,UAAU,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,2BAA2B,EAAE,2BAA2B,CAAC,CAAC,CAAC,CAAA;CACzH,EACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAKb,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAC/C;IACE;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;OAEG;IACH,UAAU,CAAC,EAAE,2BAA2B,EAAE,CAAA;CAC3C,GAAG;IAAE,MAAM,EAAE,2BAA2B,CAAA;CAAE,CAC5C,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,qBAAqB,CAAC,CAA0C,CAAA;AACrI,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,qBAAqB,CAAC,CAAqE,CAAA;AAChK,eAAO,MAAM,uBAAuB,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,qBAAqB,CAAC,CAAqE,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { DivinerParams } from '@xyo-network/sdk/diviner-model';
2
+ import type { AnyConfigSchema } from '@xyo-network/sdk/module-model';
3
+ import type { JsonPathDivinerConfig } from './Config.ts';
4
+ /**
5
+ * The params type the JSON Path diviner
6
+ **/
7
+ export type JsonPathDivinerParams = DivinerParams<AnyConfigSchema<JsonPathDivinerConfig>>;
8
+ //# sourceMappingURL=Params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Params.d.ts","sourceRoot":"","sources":["../../../src/model/Params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;IAEI;AACJ,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The schema used for the JSONPath Diviner.
3
+ */
4
+ export declare const JsonPathDivinerSchema: 'network.xyo.diviner.jsonpath' & {
5
+ readonly __schema: true;
6
+ };
7
+ /**
8
+ * The schema type used for the JSONPath Diviner.
9
+ */
10
+ export type JsonPathDivinerSchema = typeof JsonPathDivinerSchema;
11
+ //# sourceMappingURL=Schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/model/Schema.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,8BAA8B,GAAG;IACnE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAA;CACyB,CAAA;AAElD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,qBAAqB,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './Config.ts';
2
+ export * from './jsonpath/index.ts';
3
+ export * from './Params.ts';
4
+ export * from './Schema.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,20 @@
1
+ import type { JsonValue } from '@ariestools/sdk';
2
+ /**
3
+ * Describes the JSON-path transformation to retrieve a field on a source object
4
+ * and the target field to store the value to on a destination object
5
+ */
6
+ export interface JsonPathTransformExpression {
7
+ /**
8
+ * The default value to use if the source field does not exist
9
+ */
10
+ defaultValue?: JsonValue;
11
+ /**
12
+ * The target field to store the source field into on the destination object
13
+ */
14
+ destinationField: string;
15
+ /**
16
+ * The JSON path expressions for the source field on the source object
17
+ */
18
+ sourcePathExpression: string;
19
+ }
20
+ //# sourceMappingURL=JsonPathTransformExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonPathTransformExpression.d.ts","sourceRoot":"","sources":["../../../../src/model/jsonpath/JsonPathTransformExpression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,YAAY,CAAC,EAAE,SAAS,CAAA;IACxB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,oBAAoB,EAAE,MAAM,CAAA;CAC7B"}
@@ -0,0 +1,3 @@
1
+ import type { Payload } from '@xyo-network/sdk-protocol';
2
+ export type PayloadTransformer = (x: Payload) => Partial<Payload>;
3
+ //# sourceMappingURL=PayloadTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PayloadTransformer.d.ts","sourceRoot":"","sources":["../../../../src/model/jsonpath/PayloadTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAIxD,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA"}
@@ -0,0 +1,9 @@
1
+ import type { Schema } from '@xyo-network/sdk-protocol';
2
+ import type { JsonPathTransformExpression } from './JsonPathTransformExpression.ts';
3
+ /**
4
+ * A dictionary of schema to JSON Path transform expressions.
5
+ */
6
+ export type SchemaToJsonPathTransformExpressionsDictionary<T extends Record<Schema, unknown> = Record<Schema, unknown>> = {
7
+ [key in keyof T]: JsonPathTransformExpression[];
8
+ };
9
+ //# sourceMappingURL=SchemaToJsonPathTransformExpressionDictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaToJsonPathTransformExpressionDictionary.d.ts","sourceRoot":"","sources":["../../../../src/model/jsonpath/SchemaToJsonPathTransformExpressionDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAEnF;;GAEG;AACH,MAAM,MAAM,8CAA8C,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACvH,GAAG,IAAI,MAAM,CAAC,GAAG,2BAA2B,EAAE;CAChD,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { PayloadTransformer } from './PayloadTransformer.ts';
2
+ /**
3
+ * A dictionary of schema to payload transformers
4
+ */
5
+ export type SchemaToPayloadTransformersDictionary = Record<string, PayloadTransformer[]>;
6
+ //# sourceMappingURL=SchemaToPayloadTransformersDictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaToPayloadTransformersDictionary.d.ts","sourceRoot":"","sources":["../../../../src/model/jsonpath/SchemaToPayloadTransformersDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './JsonPathTransformExpression.ts';
2
+ export * from './PayloadTransformer.ts';
3
+ export * from './SchemaToJsonPathTransformExpressionDictionary.ts';
4
+ export * from './SchemaToPayloadTransformersDictionary.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/model/jsonpath/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAA;AAChD,cAAc,yBAAyB,CAAA;AACvC,cAAc,oDAAoD,CAAA;AAClE,cAAc,4CAA4C,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './model/index.ts';
2
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,33 @@
1
+ // src/model/Config.ts
2
+ import {
3
+ zodAsFactory,
4
+ zodIsFactory,
5
+ zodToFactory
6
+ } from "@ariestools/sdk";
7
+ import { DivinerConfigZod } from "@xyo-network/sdk/diviner-model";
8
+ import { asSchema as asSchema2 } from "@xyo-network/sdk-protocol";
9
+ import * as z from "zod/mini";
10
+
11
+ // src/model/Schema.ts
12
+ import { asSchema } from "@xyo-network/sdk-protocol";
13
+ var JsonPathDivinerSchema = asSchema("network.xyo.diviner.jsonpath", true);
14
+
15
+ // src/model/Config.ts
16
+ var JsonPathDivinerConfigSchema = asSchema2(`${JsonPathDivinerSchema}.config`, true);
17
+ var JsonPathDivinerConfigZod = z.extend(DivinerConfigZod, {
18
+ destinationSchema: z.optional(z.custom()),
19
+ schema: z.literal(JsonPathDivinerConfigSchema),
20
+ transforms: z.optional(z.array(z.custom()))
21
+ });
22
+ var isJsonPathDivinerConfig = zodIsFactory(JsonPathDivinerConfigZod);
23
+ var asJsonPathDivinerConfig = zodAsFactory(JsonPathDivinerConfigZod, "asJsonPathDivinerConfig");
24
+ var toJsonPathDivinerConfig = zodToFactory(JsonPathDivinerConfigZod, "toJsonPathDivinerConfig");
25
+ export {
26
+ JsonPathDivinerConfigSchema,
27
+ JsonPathDivinerConfigZod,
28
+ JsonPathDivinerSchema,
29
+ asJsonPathDivinerConfig,
30
+ isJsonPathDivinerConfig,
31
+ toJsonPathDivinerConfig
32
+ };
33
+ //# sourceMappingURL=model.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/model/Config.ts", "../../src/model/Schema.ts"],
4
+ "sourcesContent": ["import {\n zodAsFactory, zodIsFactory, zodToFactory,\n} from '@ariestools/sdk'\nimport type { DivinerConfig } from '@xyo-network/sdk/diviner-model'\nimport { DivinerConfigZod } from '@xyo-network/sdk/diviner-model'\nimport type { Schema } from '@xyo-network/sdk-protocol'\nimport { asSchema } from '@xyo-network/sdk-protocol'\nimport * as z from 'zod/mini'\n\nimport type { JsonPathTransformExpression } from './jsonpath/index.ts'\nimport { JsonPathDivinerSchema } from './Schema.ts'\n\n/**\n * The config schema for the JSON Path diviner\n */\nexport const JsonPathDivinerConfigSchema: string & {\n readonly __schema: true\n} = asSchema(`${JsonPathDivinerSchema}.config`, true)\n\n/**\n * The config schema type for the JSON Path diviner\n */\nexport type JsonPathDivinerConfigSchema = typeof JsonPathDivinerConfigSchema\n\n/**\n * The Zod schema for the JSON Path diviner config\n */\nexport const JsonPathDivinerConfigZod: z.ZodMiniObject<\n Omit<(typeof DivinerConfigZod)['shape'], 'schema'> & {\n destinationSchema: z.ZodMiniOptional<z.ZodMiniCustom<Schema, Schema>>\n schema: z.ZodMiniLiteral<JsonPathDivinerConfigSchema>\n transforms: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniCustom<JsonPathTransformExpression, JsonPathTransformExpression>>>\n },\n z.core.$strip\n> = z.extend(DivinerConfigZod, {\n destinationSchema: z.optional(z.custom<Schema>()),\n schema: z.literal(JsonPathDivinerConfigSchema),\n transforms: z.optional(z.array(z.custom<JsonPathTransformExpression>())),\n})\n\n/**\n * The configuration for the JSON Path diviner\n */\nexport type JsonPathDivinerConfig = DivinerConfig<\n {\n /**\n * The schema to use for the destination payloads\n */\n destinationSchema?: Schema\n /**\n * The JSON Path transform expressions to apply to the payloads\n */\n transforms?: JsonPathTransformExpression[]\n } & { schema: JsonPathDivinerConfigSchema }\n>\n\nexport const isJsonPathDivinerConfig: ReturnType<typeof zodIsFactory<JsonPathDivinerConfig>> = zodIsFactory(JsonPathDivinerConfigZod)\nexport const asJsonPathDivinerConfig: ReturnType<typeof zodAsFactory<JsonPathDivinerConfig>> = zodAsFactory(JsonPathDivinerConfigZod, 'asJsonPathDivinerConfig')\nexport const toJsonPathDivinerConfig: ReturnType<typeof zodToFactory<JsonPathDivinerConfig>> = zodToFactory(JsonPathDivinerConfigZod, 'toJsonPathDivinerConfig')\n", "import { asSchema } from '@xyo-network/sdk-protocol'\n/**\n * The schema used for the JSONPath Diviner.\n */\nexport const JsonPathDivinerSchema: 'network.xyo.diviner.jsonpath' & {\n readonly __schema: true\n} = asSchema('network.xyo.diviner.jsonpath', true)\n\n/**\n * The schema type used for the JSONPath Diviner.\n */\nexport type JsonPathDivinerSchema = typeof JsonPathDivinerSchema\n"],
5
+ "mappings": ";AAAA;AAAA,EACE;AAAA,EAAc;AAAA,EAAc;AAAA,OACvB;AAEP,SAAS,wBAAwB;AAEjC,SAAS,YAAAA,iBAAgB;AACzB,YAAY,OAAO;;;ACPnB,SAAS,gBAAgB;AAIlB,IAAM,wBAET,SAAS,gCAAgC,IAAI;;;ADS1C,IAAM,8BAETC,UAAS,GAAG,qBAAqB,WAAW,IAAI;AAU7C,IAAM,2BAOP,SAAO,kBAAkB;AAAA,EAC7B,mBAAqB,WAAW,SAAe,CAAC;AAAA,EAChD,QAAU,UAAQ,2BAA2B;AAAA,EAC7C,YAAc,WAAW,QAAQ,SAAoC,CAAC,CAAC;AACzE,CAAC;AAkBM,IAAM,0BAAkF,aAAa,wBAAwB;AAC7H,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;AACxJ,IAAM,0BAAkF,aAAa,0BAA0B,yBAAyB;",
6
+ "names": ["asSchema", "asSchema"]
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-jsonpath",
3
- "version": "7.2.3",
3
+ "version": "7.3.1",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -24,6 +24,14 @@
24
24
  "types": "./dist/neutral/index.d.ts",
25
25
  "default": "./dist/neutral/index.mjs"
26
26
  },
27
+ "./model": {
28
+ "types": "./dist/neutral/model.d.ts",
29
+ "default": "./dist/neutral/model.mjs"
30
+ },
31
+ "./memory": {
32
+ "types": "./dist/neutral/memory.d.ts",
33
+ "default": "./dist/neutral/memory.mjs"
34
+ },
27
35
  "./package.json": "./package.json"
28
36
  },
29
37
  "files": [
@@ -34,20 +42,28 @@
34
42
  "README.md"
35
43
  ],
36
44
  "dependencies": {
37
- "@xyo-network/diviner-jsonpath-memory": "~7.2.3",
38
- "@xyo-network/diviner-jsonpath-model": "~7.2.3"
45
+ "@xyo-network/sdk": "~7.3.1",
46
+ "jsonpath-plus": "~10.4.0"
39
47
  },
40
48
  "devDependencies": {
41
- "@ariestools/sdk": "~8.1.6",
42
- "@ariestools/toolchain": "~8.7.26",
43
- "@ariestools/tsconfig": "~8.7.26",
49
+ "@ariestools/sdk": "~8.1.9",
50
+ "@ariestools/toolchain": "~9.1.1",
51
+ "@ariestools/tsconfig": "~9.1.1",
52
+ "@ariestools/vitest-extended": "~8.0.3",
44
53
  "@opentelemetry/api": "~1.9.1",
45
- "@xyo-network/sdk-protocol": "~7.2.3",
46
- "eslint": "~10.8.0",
54
+ "@xyo-network/sdk-protocol": "~7.3.3",
55
+ "eslint": "~10.9.0",
47
56
  "eslint-import-resolver-typescript": "~4.4.5",
48
57
  "typescript": "~6.0.3",
58
+ "vite": "~8.2.2",
59
+ "vitest": "~4.1.11",
49
60
  "zod": "~4.4.3"
50
61
  },
62
+ "peerDependencies": {
63
+ "@ariestools/sdk": "^8.1",
64
+ "@xyo-network/sdk-protocol": "^7.3",
65
+ "zod": "^4.4"
66
+ },
51
67
  "engines": {
52
68
  "node": "^24"
53
69
  },