@xyo-network/diviner-jsonpath-aggregate-memory 2.110.10 → 2.110.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAoB,MAAM,4BAA4B,CAAA;AAO7F,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,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;I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F,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAoB,MAAM,4BAA4B,CAAA;AAO7F,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,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAKD,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAKD,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAwBzE,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAOD,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -120,10 +120,9 @@ var JsonPathAggregateDiviner = class extends import_diviner_abstract.AbstractDiv
120
120
  return p;
121
121
  });
122
122
  const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(strippedPayloads) : await (0, import_payload_utils.combinationsBySchema)(strippedPayloads, this.transformableSchemas);
123
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
123
+ return await Promise.all(combinations.map((combination) => {
124
124
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
125
125
  }));
126
- return reducedPayloads;
127
126
  }
128
127
  /**
129
128
  * 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.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,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,6BAA8C;AAWvC,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,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;QAAE,GAAGD;MAAQ;AACvB,aAAOC,EAAEC;AACT,aAAOD,EAAEE;AACT,aAAOF;IACT,CAAA;AACA,UAAMG,eACJ,KAAKX,qBAAqBY,SAASC,4CAAAA,IACjC,UAAMC,iDAA2BT,gBAAAA,IACjC,UAAMU,2CAAqBV,kBAAkB,KAAKL,oBAAoB;AAC1E,UAAMgB,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaL,IAAI,CAACa,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKvB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","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","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,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,6BAA8C;AAWvC,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,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,SAAS,MAAMC,sCAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,sCAAkB;IAAEL,QAAQR;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAON,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACArB,qBACAC,mBACAC,iBAAiB,UAAK;AAEtB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0B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;EAEJ;;;;;;EAOUC,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKtB,qBAAqBY,SAASU,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKvB,qBAAqBY,SAASW,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","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","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
@@ -93,10 +93,9 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
93
93
  return p;
94
94
  });
95
95
  const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(strippedPayloads) : await combinationsBySchema(strippedPayloads, this.transformableSchemas);
96
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
96
+ return await Promise.all(combinations.map((combination) => {
97
97
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
98
98
  }));
99
- return reducedPayloads;
100
99
  }
101
100
  /**
102
101
  * 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 { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,0BAA0B;AACnC,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAA+C;AACjE,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,sBAAqC;AAWvC,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,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,SAAS,MAAMC,eAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,eAAkB;IAAEL,QAAQR;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAON,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACArB,qBACAC,mBACAC,iBAAiB,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mBAAmB,KAAKC,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
1
+ {"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,0BAA0B;AACnC,SAASC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AU;EACnF,GAFkC;AAGpC;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAoB,MAAM,4BAA4B,CAAA;AAO7F,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAs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AAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAKD,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAKD,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAwBzE,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAOD,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -120,10 +120,9 @@ var JsonPathAggregateDiviner = class extends import_diviner_abstract.AbstractDiv
120
120
  return p;
121
121
  });
122
122
  const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(strippedPayloads) : await (0, import_payload_utils.combinationsBySchema)(strippedPayloads, this.transformableSchemas);
123
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
123
+ return await Promise.all(combinations.map((combination) => {
124
124
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
125
125
  }));
126
- return reducedPayloads;
127
126
  }
128
127
  /**
129
128
  * 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.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;A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","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","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,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,6BAA8C;AAWvC,IAAME,iBAAiB,8BA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AAC,KAAKR,sBAAuB,MAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA,SAAU,QAAO,CAAA;AACtB,UAAMC,mBAAmBD,SAASE,IAAI,CAACC,YAAAA;AACrC,YAAMC,IAAI;QAAE,GAAGD;MAAQ;AACvB,aAAOC,EAAEC;AACT,aAAOD,EAAEE;AACT,aAAOF;IACT,CAAA;AACA,UAAMG,eACJ,KAAKX,qBAAqBY,SAASC,4CAAAA,IACjC,UAAMC,iDAA2BT,gBAAAA,IACjC,UAAMU,2CAAqBV,kBAAkB,KAAKL,oBAAoB;AAC1E,WAAO,MAAMgB,QAAQC,IACnBN,aAAaL,IAAI,CAACY,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKtB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO0B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;EAEJ;;;;;;EAOUC,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKtB,qBAAqBY,SAASU,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKvB,qBAAqBY,SAASW,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","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","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
@@ -93,10 +93,9 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
93
93
  return p;
94
94
  });
95
95
  const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(strippedPayloads) : await combinationsBySchema(strippedPayloads, this.transformableSchemas);
96
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
96
+ return await Promise.all(combinations.map((combination) => {
97
97
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
98
98
  }));
99
- return reducedPayloads;
100
99
  }
101
100
  /**
102
101
  * 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 { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,0BAA0B;AACnC,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAA+C;AACjE,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,sBAAqC;AAWvC,IAA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7C,QAAI,CAAC,KAAKR,sBAAuB,MAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA,SAAU,QAAO,CAAA;AACtB,UAAMC,mBAAmBD,SAASE,IAAI,CAACC,YAAAA;AACrC,YAAMC,IAAI;QAAE,GAAGD;MAAQ;AACvB,aAAOC,EAAEC;AACT,aAAOD,EAAEE;AACT,aAAOF;IACT,CAAA;AACA,UAAMG,eACJ,KAAKX,qBAAqBY,SAASC,kBAAAA,IACjC,MAAMC,2BAA2BT,gBAAAA,IACjC,MAAMU,qBAAqBV,kBAAkB,KAAKL,oBAAoB;AAC1E,UAAMgB,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaL,IAAI,CAACa,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKvB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
1
+ {"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,0BAA0B;AACnC,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAA+C;AACjE,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,sBAAqC;AAWvC,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;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ACvB,aAAOC,EAAEC;AACT,aAAOD,EAAEE;AACT,aAAOF;IACT,CAAA;AACA,UAAMG,eACJ,KAAKX,qBAAqBY,SAASC,kBAAAA,IACjC,MAAMC,2BAA2BT,gBAAAA,IACjC,MAAMU,qBAAqBV,kBAAkB,KAAKL,oBAAoB;AAC1E,WAAO,MAAMgB,QAAQC,IACnBN,aAAaL,IAAI,CAACY,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKtB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO0B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;EAEJ;;;;;;EAOUC,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKtB,qBAAqBY,SAASU,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKvB,qBAAqBY,SAASW,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAoB,MAAM,4BAA4B,CAAA;AAO7F,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,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAKD,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAKD,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAA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,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAKD,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAKD,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAwBzE,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAOD,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -118,10 +118,9 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends import_d
118
118
  return p;
119
119
  });
120
120
  const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(strippedPayloads) : await (0, import_payload_utils.combinationsBySchema)(strippedPayloads, this.transformableSchemas);
121
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
121
+ return await Promise.all(combinations.map((combination) => {
122
122
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
123
123
  }));
124
- return reducedPayloads;
125
124
  }
126
125
  /**
127
126
  * 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.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,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,6BAA8C;AAWvC,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,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,S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DAA2BT,gBAAAA,IACjC,UAAMU,2CAAqBV,kBAAkB,KAAKL,oBAAoB;AAC1E,UAAMgB,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaL,IAAI,CAACa,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKvB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,uBAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;AA5EUnC;AACR,cAVWD,2BAUcsC,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAXWvC,2BAWcwC,uBAA8BD;AAXlD,IAAMvC,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","PayloadBuilder","dataHashes","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","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner.js'\nexport * from './jsonpath/index.js'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,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,6BAA8C;AAWvC,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,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,SAAS,MAAMC,sCAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,sCAAkB;IAAEL,QAAQR;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAON,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACArB,qBACAC,mBACAC,iBAAiB,UAAK;AAEtB,SAAO,MAAMoB,QAAQ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WAAO,KAAKtB,qBAAqBY,SAASU,uBAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKvB,qBAAqBY,SAASW,MAAAA,IAAU;EACnF,GAFkC;AAGpC;AA3EUlC;AACR,cAVWD,2BAUcqC,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAXWtC,2BAWcuC,uBAA8BD;AAXlD,IAAMtC,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","PayloadBuilder","dataHashes","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","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema"]}
@@ -91,10 +91,9 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends Abstract
91
91
  return p;
92
92
  });
93
93
  const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(strippedPayloads) : await combinationsBySchema(strippedPayloads, this.transformableSchemas);
94
- const reducedPayloads = await Promise.all(combinations.map((combination) => {
94
+ return await Promise.all(combinations.map((combination) => {
95
95
  return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
96
96
  }));
97
- return reducedPayloads;
98
97
  }
99
98
  /**
100
99
  * 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 { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, 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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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,0BAA0B;AACnC,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAA+C;AACjE,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,sBAAqC;AAWvC,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,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,SAAS,MAAMC,eAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,eAAkB;IAAEL,QAAQR;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAON,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,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C,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,uBAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;AA5EUnC;AACR,cAVWD,2BAUcsC,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAXWvC,2BAWcwC,uBAA8BD;AAXlD,IAAMvC,2BAAN;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","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","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema"]}
1
+ {"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath/index.js'\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<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n return await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\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 { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } 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<WithMeta<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<WithoutSchema<Payload>[]>((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 PayloadBuilder.dataHashes(payloads) }\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>(pay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OA,WAAW,WAAW,KAAKvB,qBAAqBY,SAASW,MAAAA,IAAU;EACnF,GAFkC;AAGpC;AA3EUlC;AACR,cAVWD,2BAUcqC,iBAA0B;KAAI,iEAAMA;EAAeC;;AAC5E,cAXWtC,2BAWcuC,uBAA8BD;AAXlD,IAAMtC,2BAAN;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","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","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema"]}
package/package.json CHANGED
@@ -10,24 +10,24 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.6.4",
14
- "@xylabs/exists": "^3.6.4",
15
- "@xyo-network/boundwitness-model": "^2.110.10",
16
- "@xyo-network/diviner-abstract": "^2.110.10",
17
- "@xyo-network/diviner-jsonpath-aggregate-model": "^2.110.10",
18
- "@xyo-network/diviner-jsonpath-memory": "^2.110.10",
19
- "@xyo-network/diviner-model": "^2.110.10",
20
- "@xyo-network/payload-builder": "^2.110.10",
21
- "@xyo-network/payload-model": "^2.110.10",
22
- "@xyo-network/payload-utils": "^2.110.10"
13
+ "@xylabs/assert": "^3.6.5",
14
+ "@xylabs/exists": "^3.6.5",
15
+ "@xyo-network/boundwitness-model": "^2.110.12",
16
+ "@xyo-network/diviner-abstract": "^2.110.12",
17
+ "@xyo-network/diviner-jsonpath-aggregate-model": "^2.110.12",
18
+ "@xyo-network/diviner-jsonpath-memory": "^2.110.12",
19
+ "@xyo-network/diviner-model": "^2.110.12",
20
+ "@xyo-network/payload-builder": "^2.110.12",
21
+ "@xyo-network/payload-model": "^2.110.12",
22
+ "@xyo-network/payload-utils": "^2.110.12"
23
23
  },
24
24
  "devDependencies": {
25
- "@xylabs/ts-scripts-yarn3": "^3.12.4",
26
- "@xylabs/tsconfig": "^3.12.4",
27
- "@xyo-network/account": "^2.110.10",
28
- "@xyo-network/account-model": "^2.110.10",
29
- "@xyo-network/boundwitness-builder": "^2.110.10",
30
- "@xyo-network/diviner-jsonpath-model": "^2.110.10",
25
+ "@xylabs/ts-scripts-yarn3": "^3.13.9",
26
+ "@xylabs/tsconfig": "^3.13.9",
27
+ "@xyo-network/account": "^2.110.12",
28
+ "@xyo-network/account-model": "^2.110.12",
29
+ "@xyo-network/boundwitness-builder": "^2.110.12",
30
+ "@xyo-network/diviner-jsonpath-model": "^2.110.12",
31
31
  "typescript": "^5.5.4"
32
32
  },
33
33
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -69,6 +69,6 @@
69
69
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
70
70
  },
71
71
  "sideEffects": false,
72
- "version": "2.110.10",
72
+ "version": "2.110.12",
73
73
  "type": "module"
74
74
  }
package/src/Diviner.ts CHANGED
@@ -76,12 +76,11 @@ export class JsonPathAggregateDiviner<
76
76
  this.transformableSchemas.includes(BoundWitnessSchema) ?
77
77
  await combinationsByBoundwitness(strippedPayloads)
78
78
  : await combinationsBySchema(strippedPayloads, this.transformableSchemas)
79
- const reducedPayloads = await Promise.all(
79
+ return await Promise.all(
80
80
  combinations.map((combination) => {
81
81
  return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)
82
82
  }),
83
83
  )
84
- return reducedPayloads
85
84
  }
86
85
 
87
86
  /**