@xyo-network/diviner-jsonpath-memory 5.2.17 → 5.2.19

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,5 +1,5 @@
1
1
  // src/Diviner.ts
2
- import { assertEx } from "@xylabs/assert";
2
+ import { assertEx } from "@xylabs/sdk-js";
3
3
  import { AbstractDiviner } from "@xyo-network/diviner-abstract";
4
4
  import { JsonPathDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-model";
5
5
  import { PayloadBuilder } from "@xyo-network/payload-builder";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/toPayloadTransformer.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport type { JsonPathDivinerParams, PayloadTransformer } from '@xyo-network/diviner-jsonpath-model'\nimport { JsonPathDivinerConfigSchema } from '@xyo-network/diviner-jsonpath-model'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload,\n Schema, WithoutSchema,\n} from '@xyo-network/payload-model'\nimport { PayloadSchema } from '@xyo-network/payload-model'\n\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(): string {\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 return new PayloadBuilder<TOut>({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build()\n }),\n )\n }\n}\n","import type { JsonPathTransformExpression, PayloadTransformer } from '@xyo-network/diviner-jsonpath-model'\nimport type { Payload } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\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) => {\n const {\n defaultValue, destinationField, sourcePathExpression,\n } = transformExpression\n const transformer: PayloadTransformer = (x: Payload) => {\n const source = jsonpath.value(x, sourcePathExpression)\n // TODO: If the expression should return multiple values, use jsonpath.query\n // instead of jsonpath.value\n // const source =\n // isScalarJsonPathExpression(transformExpression.sourcePathExpression) ?\n // jsonpath.value(x, sourcePathExpression)\n // : jsonpath.query(x, sourcePathExpression)\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"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;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AE,MAAM;AAAA,MAC1H,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/toPayloadTransformer.ts"],"sourcesContent":["import { assertEx } from '@xylabs/sdk-js'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport type { JsonPathDivinerParams, PayloadTransformer } from '@xyo-network/diviner-jsonpath-model'\nimport { JsonPathDivinerConfigSchema } from '@xyo-network/diviner-jsonpath-model'\nimport type { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload,\n Schema, WithoutSchema,\n} from '@xyo-network/payload-model'\nimport { PayloadSchema } from '@xyo-network/payload-model'\n\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(): string {\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 return new PayloadBuilder<TOut>({ schema: this.destinationSchema }).fields(Object.assign({ sources }, ...fields)).build()\n }),\n )\n }\n}\n","import type { JsonPathTransformExpression, PayloadTransformer } from '@xyo-network/diviner-jsonpath-model'\nimport type { Payload } from '@xyo-network/payload-model'\nimport jsonpath from 'jsonpath'\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) => {\n const {\n defaultValue, destinationField, sourcePathExpression,\n } = transformExpression\n const transformer: PayloadTransformer = (x: Payload) => {\n const source = jsonpath.value(x, sourcePathExpression)\n // TODO: If the expression should return multiple values, use jsonpath.query\n // instead of jsonpath.value\n // const source =\n // isScalarJsonPathExpression(transformExpression.sourcePathExpression) ?\n // jsonpath.value(x, sourcePathExpression)\n // : jsonpath.query(x, sourcePathExpression)\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"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAS,mCAAmC;AAE5C,SAAS,sBAAsB;AAK/B,SAAS,qBAAqB;;;ACR9B,OAAO,cAAc;AAOd,IAAM,uBAAuB,CAAC,wBAAqD;AACxF,QAAM;AAAA,IACJ;AAAA,IAAc;AAAA,IAAkB;AAAA,EAClC,IAAI;AACJ,QAAM,cAAkC,CAAC,MAAe;AACtD,UAAM,SAAS,SAAS,MAAM,GAAG,oBAAoB;AAOrD,UAAM,cAAuC,CAAC;AAE9C,UAAM,mBAAmB,WAAW,SAAY,eAAe;AAC/D,QAAI,qBAAqB,OAAW,aAAY,gBAAgB,IAAI;AACpE,WAAO;AAAA,EACT;AACA,SAAO;AACT;;;ADdO,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;AAEzD,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;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/diviner-jsonpath-memory",
3
- "version": "5.2.17",
3
+ "version": "5.2.19",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -36,23 +36,23 @@
36
36
  "!**/*.test.*"
37
37
  ],
38
38
  "dependencies": {
39
- "@xylabs/assert": "~5.0.50",
40
- "@xyo-network/diviner-abstract": "~5.2.17",
41
- "@xyo-network/diviner-jsonpath-model": "~5.2.17",
42
- "@xyo-network/diviner-model": "~5.2.17",
43
- "@xyo-network/payload-builder": "~5.2.17",
44
- "@xyo-network/payload-model": "~5.2.17",
39
+ "@xylabs/sdk-js": "~5.0.61",
40
+ "@xyo-network/diviner-abstract": "~5.2.19",
41
+ "@xyo-network/diviner-jsonpath-model": "~5.2.19",
42
+ "@xyo-network/diviner-model": "~5.2.19",
43
+ "@xyo-network/payload-builder": "~5.2.19",
44
+ "@xyo-network/payload-model": "~5.2.19",
45
45
  "jsonpath": "~1.1.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jsonpath": "~0.2.4",
49
- "@xylabs/ts-scripts-yarn3": "~7.2.8",
50
- "@xylabs/tsconfig": "~7.2.8",
51
- "@xylabs/vitest-extended": "~5.0.50",
52
- "@xyo-network/wallet": "~5.2.17",
53
- "@xyo-network/wallet-model": "~5.2.17",
49
+ "@xylabs/ts-scripts-yarn3": "~7.2.32",
50
+ "@xylabs/tsconfig": "~7.2.32",
51
+ "@xylabs/vitest-extended": "~5.0.61",
52
+ "@xyo-network/wallet": "~5.2.19",
53
+ "@xyo-network/wallet-model": "~5.2.19",
54
54
  "typescript": "~5.9.3",
55
- "vitest": "~4.0.15"
55
+ "vitest": "~4.0.16"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
package/src/Diviner.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { assertEx } from '@xylabs/assert'
1
+ import { assertEx } from '@xylabs/sdk-js'
2
2
  import { AbstractDiviner } from '@xyo-network/diviner-abstract'
3
3
  import type { JsonPathDivinerParams, PayloadTransformer } from '@xyo-network/diviner-jsonpath-model'
4
4
  import { JsonPathDivinerConfigSchema } from '@xyo-network/diviner-jsonpath-model'