@xyo-network/diviner-jsonpath-aggregate-memory 2.85.0 → 2.85.2
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.
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +9 -5
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +9 -5
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.ts.map +1 -1
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +9 -5
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +9 -5
- package/dist/node/index.js.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.ts.map +1 -1
- package/package.json +15 -13
- package/src/Diviner.ts +10 -6
- package/src/jsonpath/reducePayloads.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EA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,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -31,8 +31,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
31
31
|
// src/Diviner.ts
|
|
32
32
|
var import_assert = require("@xylabs/assert");
|
|
33
33
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
34
|
+
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
34
35
|
var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
|
|
35
36
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
37
|
+
var import_payload_utils = require("@xyo-network/payload-utils");
|
|
36
38
|
|
|
37
39
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
38
40
|
var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
|
|
@@ -47,10 +49,11 @@ var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms)
|
|
|
47
49
|
}, "jsonPathToTransformersDictionary");
|
|
48
50
|
|
|
49
51
|
// src/jsonpath/reducePayloads.ts
|
|
52
|
+
var import_exists = require("@xylabs/exists");
|
|
50
53
|
var import_hash = require("@xyo-network/hash");
|
|
51
54
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
52
55
|
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
53
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
56
|
+
const payloadFields = payloads.filter(import_exists.exists).flatMap((payload) => {
|
|
54
57
|
const transformers = payloadTransformers[payload.schema];
|
|
55
58
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
56
59
|
});
|
|
@@ -112,10 +115,11 @@ var JsonPathAggregateDiviner = class extends import_abstract_diviner.AbstractDiv
|
|
|
112
115
|
async divineHandler(payloads) {
|
|
113
116
|
if (!payloads)
|
|
114
117
|
return [];
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(payloads) : await (0, import_payload_utils.combinationsBySchema)(payloads, this.transformableSchemas);
|
|
119
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
120
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
121
|
+
}));
|
|
122
|
+
return reducedPayloads;
|
|
119
123
|
}
|
|
120
124
|
/**
|
|
121
125
|
* Identifies if a payload is one that is transformed by this diviner
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,8CAMO;AAEP,2BAAuC;;;ACTvC,qCAAqC;AAS9B,IAAMA,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,mDAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACThD,kBAA8B;AAC9B,6BAA+B;AAWxB,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,QAAyB,CAACC,YAAAA;AAEvD,UAAMC,eAAeN,oBAAoBK,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaR,iBAAiB,CAAC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;;;;;;EAOUG,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKT,qBAAqBU,SAASD,GAAGE,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKX,qBAAqBU,SAASC,MAAAA,IAAU;EACnF;AACF;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","reducedPayloads","reducePayloads","excludeSources","isTransformablePayload","x","includes","schema","isTransformableSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,gCAAmC;AACnC,8CAMO;AAEP,2BAAuC;AACvC,2BAAiE;;;ACXjE,qCAAqC;AAS9B,IAAMA,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,mDAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,oBAAuB;AAEvB,kBAA8B;AAC9B,6BAA+B;AAWxB,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iB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R;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,eAAe,KAAKL,qBAAqBM,SAASC,4CAAAA,IACpD,UAAMC,iDAA2BJ,QAAAA,IACjC,UAAMK,2CAAqBL,UAAU,KAAKJ,oBAAoB;AAClE,UAAMU,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaQ,IAAI,CAACC,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKlB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAOsB,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -4,8 +4,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/Diviner.ts
|
|
5
5
|
import { assertEx } from "@xylabs/assert";
|
|
6
6
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
7
|
+
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
7
8
|
import { JsonPathAggregateDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
8
9
|
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
10
|
+
import { combinationsByBoundwitness, combinationsBySchema } from "@xyo-network/payload-utils";
|
|
9
11
|
|
|
10
12
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
11
13
|
import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
|
|
@@ -20,10 +22,11 @@ var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms)
|
|
|
20
22
|
}, "jsonPathToTransformersDictionary");
|
|
21
23
|
|
|
22
24
|
// src/jsonpath/reducePayloads.ts
|
|
25
|
+
import { exists } from "@xylabs/exists";
|
|
23
26
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
24
27
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
25
28
|
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
26
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
29
|
+
const payloadFields = payloads.filter(exists).flatMap((payload) => {
|
|
27
30
|
const transformers = payloadTransformers[payload.schema];
|
|
28
31
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
29
32
|
});
|
|
@@ -85,10 +88,11 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
|
85
88
|
async divineHandler(payloads) {
|
|
86
89
|
if (!payloads)
|
|
87
90
|
return [];
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(payloads) : await combinationsBySchema(payloads, this.transformableSchemas);
|
|
92
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
93
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
94
|
+
}));
|
|
95
|
+
return reducedPayloads;
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Identifies if a payload is one that is transformed by this diviner
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;;;ACTvC,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACThD,SAASE,qBAAqB;AAC9B,SAASC,sBAAsB;AAWxB,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,QAAyB,CAACC,YAAAA;AAEvD,UAAMC,eAAeN,oBAAoBK,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaR,iBAAiB,CAAC,IAAI;IAAES,UAAU,MAAMC,cAAcC,UAAU;SAAId;KAAS,GAAGS,IAAI,CAAC,CAAA,EAAGM,IAAAA,MAAUA,IAAAA;EAAM;AAE3H,SAAO,MAAM,IAAIC,eAAkB;IAAER,QAAQN;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAOR,YAAAA,GAAeP,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACArB,qBACAC,mBACAC,iBAAiB,UAAK;AAEtB,SAAO,MAAMoB,QAAQC,IACnBF,cAAcb,IAAI,OAAOT,aAAAA;AACvB,WAAO,MAAMD,eAAkBC,UAAUC,qBAAqBC,mBAAmBC,cAAAA;EACnF,CAAA,CAAA;AAEJ,GAXmC;;;AFzBnC,IAAMsB,aAAa;AAEZ,IAAMC,2BAAN,cAKGC,gBAAAA;EArBV,OAqBUA;;;EACR,OAAgBC,gBAAgB;IAACC;;EAEvBC;EAEFC;EACAC;;;;EAKR,IAAcC,oBAA4B;AACxC,WAAO,KAAKC,OAAOD,qBAAqBE;EAC1C;;;;EAKA,IAAcC,sBAA6D;AACzE,QAAI,CAAC,KAAKL;AAAsB,WAAKA,uBAAuBM,iCAAiC,KAAKC,gBAAgB;AAClH,WAAO,KAAKP;EACd;;;;EAKA,IAAcO,mBAAmE;AAC/E,WAAOC,SAAS,KAAKL,QAAQI,kBAAkB,MAAM,GAAGb,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAce,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,kBAAkB,MAAMC,eAC5BF,UACA,KAAKR,qBACL,KAAKH,mBACL,KAAKC,OAAOa,kBAAkB,KAAA;AAEhC,WAAO;MAACF;;EACV;;;;;;EAOUG,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKT,qBAAqBU,SAASD,GAAGE,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKX,qBAAqBU,SAASC,MAAAA,IAAU;EACnF;AACF;","names":["assertEx","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","reducedPayloads","reducePayloads","excludeSources","isTransformablePayload","x","includes","schema","isTransformableSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SAASC,0BAA0B;AACnC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;AACvC,SAASC,4BAA4BC,4BAA4B;;;ACXjE,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,SAASE,cAAc;AAEvB,SAASC,qBAAqB;AAC9B,SAASC,sBAAsB;AAWxB,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAyB,CAACC,YAAAA;AAEtE,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,UAAU,MAAMC,cAAcC,UAAU;SAAIhB;KAAS,GAAGW,IAAI,CAAC,CAAA,EAAGM,IAAAA,MA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AqBD,aAAa,KAAKlB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAOsB,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;","names":["assertEx","AbstractDiviner","BoundWitnessSchema","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -36,8 +36,10 @@ module.exports = __toCommonJS(src_exports);
|
|
|
36
36
|
// src/Diviner.ts
|
|
37
37
|
var import_assert = require("@xylabs/assert");
|
|
38
38
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
39
|
+
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
39
40
|
var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
|
|
40
41
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
42
|
+
var import_payload_utils = require("@xyo-network/payload-utils");
|
|
41
43
|
|
|
42
44
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
43
45
|
var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
|
|
@@ -52,10 +54,11 @@ var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms)
|
|
|
52
54
|
}, "jsonPathToTransformersDictionary");
|
|
53
55
|
|
|
54
56
|
// src/jsonpath/reducePayloads.ts
|
|
57
|
+
var import_exists = require("@xylabs/exists");
|
|
55
58
|
var import_hash = require("@xyo-network/hash");
|
|
56
59
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
57
60
|
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
58
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
61
|
+
const payloadFields = payloads.filter(import_exists.exists).flatMap((payload) => {
|
|
59
62
|
const transformers = payloadTransformers[payload.schema];
|
|
60
63
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
61
64
|
});
|
|
@@ -112,10 +115,11 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends import_a
|
|
|
112
115
|
async divineHandler(payloads) {
|
|
113
116
|
if (!payloads)
|
|
114
117
|
return [];
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(payloads) : await (0, import_payload_utils.combinationsBySchema)(payloads, this.transformableSchemas);
|
|
119
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
120
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
121
|
+
}));
|
|
122
|
+
return reducedPayloads;
|
|
119
123
|
}
|
|
120
124
|
/**
|
|
121
125
|
* Identifies if a payload is one that is transformed by this diviner
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,8CAMO;AAEP,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BE;EAC1C;;;;EAKA,IAAcC,sBAA6D;AACzE,QAAI,CAAC,KAAKL;AAAsB,WAAKA,uBAAuBM,iCAAiC,KAAKC,gBAAgB;AAClH,WAAO,KAAKP;EACd;;;;EAKA,IAAcO,mBAAmE;AA/CnF;AAgDI,eAAOC,yBAAS,UAAKL,WAAL,mBAAaI,kBAAkB,MAAM,GAAGX,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAca,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,kBAAkB,MAAMC,eAC5BF,UACA,KAAKR,qBACL,KAAKH,mBACL,KAAKC,OAAOa,kBAAkB,KAAA;AAEhC,WAAO;MAACF;;EACV;;;;;;EAOUG,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKT,qBAAqBU,SAASD,uBAAGE,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKX,qBAAqBU,SAASC,MAAAA,IAAU;EACnF;AACF;AAlEUtB;AACR,cANWD,2BAMKyB,iBAAgB;EAACC;;AAN5B,IAAM1B,2BAAN;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","reducedPayloads","reducePayloads","excludeSources","isTransformablePayload","x","includes","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,gCAAmC;AACnC,8CAMO;AAEP,2BAAuC;AACvC,2BAAiE;;;ACXjE,qCAAqC;AAS9B,IAAMA,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,mDAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,oBAAuB;AAEvB,kBAA8B;AAC9B,6BAA+B;AAWxB,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAyB,CAACC,YAAAA;AAEtE,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,UAAU,MAAMC,0BAAcC,UAAU;SAAIhB;KAAS,GAAGW,IAAI,CAAC,CAAA,EAAGM,IAAAA,MAAUA,IAAAA;EAAM;AAE3H,SAAO,MAAM,IAAIC,sCAAkB;IAAER,QAAQR;EAAkB,CAAA,EAAGiB,OAAOC,OAAOC,OAAOR,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBkB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACAvB,qBACAC,mBACAC,i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AAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;AApEU9B;AACR,cANWD,2BAMKiC,iBAAgB;EAACC;;AAN5B,IAAMlC,2BAAN;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
package/dist/node/index.js
CHANGED
|
@@ -9,8 +9,10 @@ var __publicField = (obj, key, value) => {
|
|
|
9
9
|
// src/Diviner.ts
|
|
10
10
|
import { assertEx } from "@xylabs/assert";
|
|
11
11
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
12
|
+
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
12
13
|
import { JsonPathAggregateDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
13
14
|
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
15
|
+
import { combinationsByBoundwitness, combinationsBySchema } from "@xyo-network/payload-utils";
|
|
14
16
|
|
|
15
17
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
16
18
|
import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
|
|
@@ -25,10 +27,11 @@ var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms)
|
|
|
25
27
|
}, "jsonPathToTransformersDictionary");
|
|
26
28
|
|
|
27
29
|
// src/jsonpath/reducePayloads.ts
|
|
30
|
+
import { exists } from "@xylabs/exists";
|
|
28
31
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
29
32
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
30
33
|
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
31
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
34
|
+
const payloadFields = payloads.filter(exists).flatMap((payload) => {
|
|
32
35
|
const transformers = payloadTransformers[payload.schema];
|
|
33
36
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
34
37
|
});
|
|
@@ -85,10 +88,11 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends Abstract
|
|
|
85
88
|
async divineHandler(payloads) {
|
|
86
89
|
if (!payloads)
|
|
87
90
|
return [];
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(payloads) : await combinationsBySchema(payloads, this.transformableSchemas);
|
|
92
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
93
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
94
|
+
}));
|
|
95
|
+
return reducedPayloads;
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Identifies if a payload is one that is transformed by this diviner
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;;;ACTvC,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACThD,SAASE,qBAAqB;AAC9B,SAASC,sBAAsB;AAWx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uB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,kBAAkB,MAAMC,eAC5BF,UACA,KAAKR,qBACL,KAAKH,mBACL,KAAKC,OAAOa,kBAAkB,KAAA;AAEhC,WAAO;MAACF;;EACV;;;;;;EAOUG,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKT,qBAAqBU,SAASD,uBAAGE,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKX,qBAAqBU,SAASC,MAAAA,IAAU;EACnF;AACF;AAlEUtB;AACR,cANWD,2BAMKyB,iBAAgB;EAACC;;AAN5B,IAAM1B,2BAAN;","names":["assertEx","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","reducedPayloads","reducePayloads","excludeSources","isTransformablePayload","x","includes","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | 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\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SAASC,0BAA0B;AACnC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;AACv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AAA;EAGEC;EAEFC;EACAC;;;;EAKR,IAAcC,oBAA4B;AACxC,WAAO,KAAKC,OAAOD,qBAAqBE;EAC1C;;;;EAKA,IAAcC,sBAA6D;AACzE,QAAI,CAAC,KAAKL;AAAsB,WAAKA,uBAAuBM,iCAAiC,KAAKC,gBAAgB;AAClH,WAAO,KAAKP;EACd;;;;EAKA,IAAcO,mBAAmE;AAjDnF;AAkDI,WAAOC,UAAS,UAAKL,WAAL,mBAAaI,kBAAkB,MAAM,GAAGX,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAca,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,eAAe,KAAKL,qBAAqBM,SAASC,kBAAAA,IACpD,MAAMC,2BAA2BJ,QAAAA,IACjC,MAAMK,qBAAqBL,UAAU,KAAKJ,oBAAoB;AAClE,UAAMU,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaQ,IAAI,CAACC,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKlB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAOsB,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,uBAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;AApEU9B;AACR,cANWD,2BAMKiC,iBAAgB;EAACC;;AAN5B,IAAMlC,2BAAN;","names":["assertEx","AbstractDiviner","BoundWitnessSchema","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
package/package.json
CHANGED
|
@@ -11,22 +11,24 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
|
-
"@
|
|
15
|
-
"@xyo-network/diviner
|
|
16
|
-
"@xyo-network/diviner-model": "~2.85.
|
|
17
|
-
"@xyo-network/
|
|
18
|
-
"@xyo-network/
|
|
19
|
-
"@xyo-network/payload-
|
|
14
|
+
"@xylabs/exists": "^2.13.20",
|
|
15
|
+
"@xyo-network/abstract-diviner": "~2.85.2",
|
|
16
|
+
"@xyo-network/diviner-jsonpath-aggregate-model": "~2.85.2",
|
|
17
|
+
"@xyo-network/diviner-model": "~2.85.2",
|
|
18
|
+
"@xyo-network/hash": "~2.85.2",
|
|
19
|
+
"@xyo-network/payload-builder": "~2.85.2",
|
|
20
|
+
"@xyo-network/payload-model": "~2.85.2",
|
|
21
|
+
"@xyo-network/payload-utils": "~2.85.2"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
24
|
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
23
25
|
"@xylabs/tsconfig": "^3.2.25",
|
|
24
|
-
"@xyo-network/account": "~2.85.
|
|
25
|
-
"@xyo-network/boundwitness-builder": "~2.85.
|
|
26
|
-
"@xyo-network/boundwitness-model": "~2.85.
|
|
27
|
-
"@xyo-network/diviner-jsonpath-memory": "~2.85.
|
|
28
|
-
"@xyo-network/diviner-jsonpath-model": "~2.85.
|
|
29
|
-
"@xyo-network/wallet-model": "~2.85.
|
|
26
|
+
"@xyo-network/account": "~2.85.2",
|
|
27
|
+
"@xyo-network/boundwitness-builder": "~2.85.2",
|
|
28
|
+
"@xyo-network/boundwitness-model": "~2.85.2",
|
|
29
|
+
"@xyo-network/diviner-jsonpath-memory": "~2.85.2",
|
|
30
|
+
"@xyo-network/diviner-jsonpath-model": "~2.85.2",
|
|
31
|
+
"@xyo-network/wallet-model": "~2.85.2",
|
|
30
32
|
"typescript": "^5.3.3"
|
|
31
33
|
},
|
|
32
34
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -68,6 +70,6 @@
|
|
|
68
70
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
69
71
|
},
|
|
70
72
|
"sideEffects": false,
|
|
71
|
-
"version": "2.85.
|
|
73
|
+
"version": "2.85.2",
|
|
72
74
|
"type": "module"
|
|
73
75
|
}
|
package/src/Diviner.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
3
|
+
import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
3
4
|
import {
|
|
4
5
|
JsonPathAggregateDivinerConfigSchema,
|
|
5
6
|
JsonPathAggregateDivinerParams,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
} from '@xyo-network/diviner-jsonpath-aggregate-model'
|
|
10
11
|
import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'
|
|
11
12
|
import { Payload, PayloadSchema } from '@xyo-network/payload-model'
|
|
13
|
+
import { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'
|
|
12
14
|
|
|
13
15
|
import { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'
|
|
14
16
|
|
|
@@ -59,13 +61,15 @@ export class JsonPathAggregateDiviner<
|
|
|
59
61
|
|
|
60
62
|
protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
|
|
61
63
|
if (!payloads) return []
|
|
62
|
-
const
|
|
63
|
-
payloads
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema)
|
|
65
|
+
? await combinationsByBoundwitness(payloads)
|
|
66
|
+
: await combinationsBySchema(payloads, this.transformableSchemas)
|
|
67
|
+
const reducedPayloads = await Promise.all(
|
|
68
|
+
combinations.map((combination) => {
|
|
69
|
+
return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)
|
|
70
|
+
}),
|
|
67
71
|
)
|
|
68
|
-
return
|
|
72
|
+
return reducedPayloads
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
1
2
|
import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'
|
|
2
3
|
import { PayloadHasher } from '@xyo-network/hash'
|
|
3
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
@@ -18,7 +19,7 @@ export const reducePayloads = async <T extends Payload = Payload>(
|
|
|
18
19
|
excludeSources = false,
|
|
19
20
|
): Promise<T> => {
|
|
20
21
|
// Use the payload transformers to convert the fields from the source payloads to the destination fields
|
|
21
|
-
const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {
|
|
22
|
+
const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {
|
|
22
23
|
// Find the transformers for this payload
|
|
23
24
|
const transformers = payloadTransformers[payload.schema]
|
|
24
25
|
// If transformers exist, apply them to the payload otherwise return an empty array
|