@xyo-network/diviner-jsonpath-aggregate-memory 2.83.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.
Files changed (77) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/Diviner.d.cts +40 -0
  4. package/dist/browser/Diviner.d.cts.map +1 -0
  5. package/dist/browser/Diviner.d.mts +40 -0
  6. package/dist/browser/Diviner.d.mts.map +1 -0
  7. package/dist/browser/Diviner.d.ts +40 -0
  8. package/dist/browser/Diviner.d.ts.map +1 -0
  9. package/dist/browser/index.cjs +114 -0
  10. package/dist/browser/index.cjs.map +1 -0
  11. package/dist/browser/index.d.cts +2 -0
  12. package/dist/browser/index.d.cts.map +1 -0
  13. package/dist/browser/index.d.mts +2 -0
  14. package/dist/browser/index.d.mts.map +1 -0
  15. package/dist/browser/index.d.ts +2 -0
  16. package/dist/browser/index.d.ts.map +1 -0
  17. package/dist/browser/index.js +93 -0
  18. package/dist/browser/index.js.map +1 -0
  19. package/dist/browser/jsonpath/index.d.cts +3 -0
  20. package/dist/browser/jsonpath/index.d.cts.map +1 -0
  21. package/dist/browser/jsonpath/index.d.mts +3 -0
  22. package/dist/browser/jsonpath/index.d.mts.map +1 -0
  23. package/dist/browser/jsonpath/index.d.ts +3 -0
  24. package/dist/browser/jsonpath/index.d.ts.map +1 -0
  25. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts +10 -0
  26. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -0
  27. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts +10 -0
  28. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -0
  29. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts +10 -0
  30. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -0
  31. package/dist/browser/jsonpath/reducePayloads.d.cts +27 -0
  32. package/dist/browser/jsonpath/reducePayloads.d.cts.map +1 -0
  33. package/dist/browser/jsonpath/reducePayloads.d.mts +27 -0
  34. package/dist/browser/jsonpath/reducePayloads.d.mts.map +1 -0
  35. package/dist/browser/jsonpath/reducePayloads.d.ts +27 -0
  36. package/dist/browser/jsonpath/reducePayloads.d.ts.map +1 -0
  37. package/dist/node/Diviner.d.cts +40 -0
  38. package/dist/node/Diviner.d.cts.map +1 -0
  39. package/dist/node/Diviner.d.mts +40 -0
  40. package/dist/node/Diviner.d.mts.map +1 -0
  41. package/dist/node/Diviner.d.ts +40 -0
  42. package/dist/node/Diviner.d.ts.map +1 -0
  43. package/dist/node/index.d.cts +2 -0
  44. package/dist/node/index.d.cts.map +1 -0
  45. package/dist/node/index.d.mts +2 -0
  46. package/dist/node/index.d.mts.map +1 -0
  47. package/dist/node/index.d.ts +2 -0
  48. package/dist/node/index.d.ts.map +1 -0
  49. package/dist/node/index.js +119 -0
  50. package/dist/node/index.js.map +1 -0
  51. package/dist/node/index.mjs +94 -0
  52. package/dist/node/index.mjs.map +1 -0
  53. package/dist/node/jsonpath/index.d.cts +3 -0
  54. package/dist/node/jsonpath/index.d.cts.map +1 -0
  55. package/dist/node/jsonpath/index.d.mts +3 -0
  56. package/dist/node/jsonpath/index.d.mts.map +1 -0
  57. package/dist/node/jsonpath/index.d.ts +3 -0
  58. package/dist/node/jsonpath/index.d.ts.map +1 -0
  59. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts +10 -0
  60. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -0
  61. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts +10 -0
  62. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -0
  63. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts +10 -0
  64. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -0
  65. package/dist/node/jsonpath/reducePayloads.d.cts +27 -0
  66. package/dist/node/jsonpath/reducePayloads.d.cts.map +1 -0
  67. package/dist/node/jsonpath/reducePayloads.d.mts +27 -0
  68. package/dist/node/jsonpath/reducePayloads.d.mts.map +1 -0
  69. package/dist/node/jsonpath/reducePayloads.d.ts +27 -0
  70. package/dist/node/jsonpath/reducePayloads.d.ts.map +1 -0
  71. package/package.json +72 -0
  72. package/src/Diviner.ts +83 -0
  73. package/src/index.ts +1 -0
  74. package/src/jsonpath/index.ts +2 -0
  75. package/src/jsonpath/jsonPathToTransformersDictionary.ts +20 -0
  76. package/src/jsonpath/reducePayloads.ts +50 -0
  77. package/typedoc.json +5 -0
@@ -0,0 +1,27 @@
1
+ import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
2
+ import { Payload, PayloadFields } from '@xyo-network/payload-model';
3
+ /**
4
+ * Reduces the payloads to a single payload using the supplied transformers
5
+ * @param payloads The payloads to reduce
6
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payload
7
+ * @param destinationSchema The schema of the destination payload
8
+ * @returns The reduced payload
9
+ */
10
+ export declare const reducePayloads: <T extends {
11
+ schema: string;
12
+ } & PayloadFields = {
13
+ schema: string;
14
+ } & PayloadFields>(payloads: Payload[], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T>;
15
+ /**
16
+ * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
17
+ * @param payloadsArray The arrays of payloads to reduce
18
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
19
+ * @param destinationSchema The schema of the destination payloads
20
+ * @returns The reduced payloads
21
+ */
22
+ export declare const reducePayloadsArray: <T extends {
23
+ schema: string;
24
+ } & PayloadFields = {
25
+ schema: string;
26
+ } & PayloadFields>(payloadsArray: Payload[][], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T[]>;
27
+ //# sourceMappingURL=reducePayloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;6BACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,eAe1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;kCACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,iBAO1B,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
2
+ import { Payload, PayloadFields } from '@xyo-network/payload-model';
3
+ /**
4
+ * Reduces the payloads to a single payload using the supplied transformers
5
+ * @param payloads The payloads to reduce
6
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payload
7
+ * @param destinationSchema The schema of the destination payload
8
+ * @returns The reduced payload
9
+ */
10
+ export declare const reducePayloads: <T extends {
11
+ schema: string;
12
+ } & PayloadFields = {
13
+ schema: string;
14
+ } & PayloadFields>(payloads: Payload[], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T>;
15
+ /**
16
+ * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
17
+ * @param payloadsArray The arrays of payloads to reduce
18
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
19
+ * @param destinationSchema The schema of the destination payloads
20
+ * @returns The reduced payloads
21
+ */
22
+ export declare const reducePayloadsArray: <T extends {
23
+ schema: string;
24
+ } & PayloadFields = {
25
+ schema: string;
26
+ } & PayloadFields>(payloadsArray: Payload[][], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T[]>;
27
+ //# sourceMappingURL=reducePayloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;6BACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,eAe1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;kCACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,iBAO1B,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
2
+ import { Payload, PayloadFields } from '@xyo-network/payload-model';
3
+ /**
4
+ * Reduces the payloads to a single payload using the supplied transformers
5
+ * @param payloads The payloads to reduce
6
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payload
7
+ * @param destinationSchema The schema of the destination payload
8
+ * @returns The reduced payload
9
+ */
10
+ export declare const reducePayloads: <T extends {
11
+ schema: string;
12
+ } & PayloadFields = {
13
+ schema: string;
14
+ } & PayloadFields>(payloads: Payload[], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T>;
15
+ /**
16
+ * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
17
+ * @param payloadsArray The arrays of payloads to reduce
18
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
19
+ * @param destinationSchema The schema of the destination payloads
20
+ * @returns The reduced payloads
21
+ */
22
+ export declare const reducePayloadsArray: <T extends {
23
+ schema: string;
24
+ } & PayloadFields = {
25
+ schema: string;
26
+ } & PayloadFields>(payloadsArray: Payload[][], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string) => Promise<T[]>;
27
+ //# sourceMappingURL=reducePayloads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc;;;;6BACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,eAe1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;kCACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,iBAO1B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@xyo-network/diviner-jsonpath-aggregate-memory",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@xylabs/assert": "^2.13.20",
14
+ "@xyo-network/abstract-diviner": "~2.83.0",
15
+ "@xyo-network/core": "~2.83.0",
16
+ "@xyo-network/diviner-jsonpath-aggregate-model": "~2.83.0",
17
+ "@xyo-network/diviner-model": "~2.83.0",
18
+ "@xyo-network/payload-builder": "~2.83.0",
19
+ "@xyo-network/payload-model": "~2.83.0"
20
+ },
21
+ "devDependencies": {
22
+ "@xylabs/ts-scripts-yarn3": "^3.2.10",
23
+ "@xylabs/tsconfig": "^3.2.10",
24
+ "@xyo-network/account": "~2.83.0",
25
+ "@xyo-network/boundwitness-builder": "~2.83.0",
26
+ "@xyo-network/boundwitness-model": "~2.83.0",
27
+ "@xyo-network/diviner-jsonpath-memory": "~2.83.0",
28
+ "@xyo-network/wallet-model": "~2.83.0",
29
+ "typescript": "^5.3.2"
30
+ },
31
+ "description": "Primary SDK for using XYO Protocol 2.0",
32
+ "docs": "dist/docs.json",
33
+ "types": "dist/node/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "browser": {
37
+ "require": {
38
+ "types": "./dist/browser/index.d.cts",
39
+ "default": "./dist/browser/index.cjs"
40
+ },
41
+ "import": {
42
+ "types": "./dist/browser/index.d.mts",
43
+ "default": "./dist/browser/index.js"
44
+ }
45
+ },
46
+ "node": {
47
+ "require": {
48
+ "types": "./dist/node/index.d.ts",
49
+ "default": "./dist/node/index.js"
50
+ },
51
+ "import": {
52
+ "types": "./dist/node/index.d.mts",
53
+ "default": "./dist/node/index.mjs"
54
+ }
55
+ }
56
+ },
57
+ "./package.json": "./package.json"
58
+ },
59
+ "main": "dist/node/index.js",
60
+ "module": "dist/node/index.mjs",
61
+ "homepage": "https://xyo.network",
62
+ "license": "LGPL-3.0-only",
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
69
+ },
70
+ "sideEffects": false,
71
+ "version": "2.83.0"
72
+ }
package/src/Diviner.ts ADDED
@@ -0,0 +1,83 @@
1
+ import { assertEx } from '@xylabs/assert'
2
+ import { AbstractDiviner } from '@xyo-network/abstract-diviner'
3
+ import {
4
+ JsonPathAggregateDivinerConfigSchema,
5
+ JsonPathAggregateDivinerParams,
6
+ PayloadTransformer,
7
+ SchemaToJsonPathTransformExpressionsDictionary,
8
+ SchemaToPayloadTransformersDictionary,
9
+ } from '@xyo-network/diviner-jsonpath-aggregate-model'
10
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'
11
+ import { Payload, PayloadSchema } from '@xyo-network/payload-model'
12
+
13
+ import { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'
14
+
15
+ const moduleName = 'JsonPathAggregateDiviner'
16
+
17
+ export class JsonPathAggregateDiviner<
18
+ TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,
19
+ TIn extends Payload = Payload,
20
+ TOut extends Payload = Payload,
21
+ TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,
22
+ > extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
23
+ static override configSchemas = [JsonPathAggregateDivinerConfigSchema]
24
+
25
+ protected _transforms: PayloadTransformer[] | undefined
26
+
27
+ private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined
28
+ private _transformableSchemas: string[] | undefined
29
+
30
+ /**
31
+ * The schema to use for the destination payloads
32
+ */
33
+ protected get destinationSchema(): string {
34
+ return this.config.destinationSchema ?? PayloadSchema
35
+ }
36
+
37
+ /**
38
+ * Dictionary of schemas to payload transformers
39
+ */
40
+ protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {
41
+ if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)
42
+ return this._payloadTransformers
43
+ }
44
+
45
+ /**
46
+ * The dictionary of schemas to JSON Path transform expressions
47
+ */
48
+ protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {
49
+ return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)
50
+ }
51
+
52
+ /**
53
+ * List of transformable schemas for this diviner
54
+ */
55
+ protected get transformableSchemas(): string[] {
56
+ if (!this._transformableSchemas) this._transformableSchemas = [...Object.keys(this.schemaTransforms)]
57
+ return this._transformableSchemas
58
+ }
59
+
60
+ protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
61
+ if (!payloads) return []
62
+ const reducedPayloads = await reducePayloads<TOut>(payloads, this.payloadTransformers, this.destinationSchema)
63
+ return [reducedPayloads]
64
+ }
65
+
66
+ /**
67
+ * Identifies if a payload is one that is transformed by this diviner
68
+ * @param x The candidate payload
69
+ * @returns True if the payload is one transformed by this diviner, false otherwise
70
+ */
71
+ protected isTransformablePayload = (x: Payload) => {
72
+ return this.transformableSchemas.includes(x?.schema)
73
+ }
74
+
75
+ /**
76
+ * Identifies if a schema is one that is transformed by this diviner
77
+ * @param schema The candidate schema
78
+ * @returns True if this schema is one transformed by this diviner, false otherwise
79
+ */
80
+ protected isTransformableSchema = (schema?: string | null) => {
81
+ return this.transformableSchemas.some((s) => s === schema)
82
+ }
83
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './Diviner'
@@ -0,0 +1,2 @@
1
+ export * from './jsonPathToTransformersDictionary'
2
+ export * from './reducePayloads'
@@ -0,0 +1,20 @@
1
+ import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'
2
+ import { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'
3
+
4
+ /**
5
+ * Materializes the JSON-path expressions into memoized functions by converting a
6
+ * dictionary of schema to JSON Path transform expressions to a dictionary
7
+ * of schema to payload transformers
8
+ * @param schemaTransforms The schema transforms to convert
9
+ * @returns A dictionary of schema to payload transformers
10
+ */
11
+ export const jsonPathToTransformersDictionary = (
12
+ schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,
13
+ ): SchemaToPayloadTransformersDictionary => {
14
+ return Object.fromEntries(
15
+ Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
16
+ const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)
17
+ return [schema, transformers]
18
+ }),
19
+ )
20
+ }
@@ -0,0 +1,50 @@
1
+ import { PayloadHasher } from '@xyo-network/core'
2
+ import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'
3
+ import { PayloadBuilder } from '@xyo-network/payload-builder'
4
+ import { Payload, PayloadFields } from '@xyo-network/payload-model'
5
+
6
+ /**
7
+ * Reduces the payloads to a single payload using the supplied transformers
8
+ * @param payloads The payloads to reduce
9
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payload
10
+ * @param destinationSchema The schema of the destination payload
11
+ * @returns The reduced payload
12
+ */
13
+ export const reducePayloads = async <T extends Payload = Payload>(
14
+ payloads: Payload[],
15
+ payloadTransformers: SchemaToPayloadTransformersDictionary,
16
+ destinationSchema: string,
17
+ ): Promise<T> => {
18
+ // Use the payload transformers to convert the fields from the source payloads to the destination fields
19
+ const indexFields = payloads
20
+ .map<PayloadFields[]>((payload) => {
21
+ // Find the transformers for this payload
22
+ const transformers = payloadTransformers[payload.schema]
23
+ // If transformers exist, apply them to the payload otherwise return an empty array
24
+ return transformers ? transformers.map((transform) => transform(payload)) : []
25
+ })
26
+ .flat()
27
+ // Include all the sources for reference
28
+ const sources = (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash)
29
+ // Build and return the index
30
+ return new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign({ sources }, ...indexFields)).build()
31
+ }
32
+
33
+ /**
34
+ * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
35
+ * @param payloadsArray The arrays of payloads to reduce
36
+ * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
37
+ * @param destinationSchema The schema of the destination payloads
38
+ * @returns The reduced payloads
39
+ */
40
+ export const reducePayloadsArray = async <T extends Payload = Payload>(
41
+ payloadsArray: Payload[][],
42
+ payloadTransformers: SchemaToPayloadTransformersDictionary,
43
+ destinationSchema: string,
44
+ ): Promise<T[]> => {
45
+ return await Promise.all(
46
+ payloadsArray.map(async (payloads) => {
47
+ return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema)
48
+ }),
49
+ )
50
+ }
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }