@xyo-network/diviner-jsonpath-aggregate-memory 2.96.2 → 2.97.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/Diviner.d.cts +3 -2
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts +3 -2
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts +3 -2
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +2 -0
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Diviner.d.cts +3 -2
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts +3 -2
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts +3 -2
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +5 -0
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +5 -0
- package/dist/node/index.js.map +1 -1
- package/package.json +13 -13
- package/src/Diviner.ts +3 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -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,
|
|
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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACxG,OAAgB,mBAAmB,EAAE,MAAM,CAAuC;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -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,
|
|
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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACxG,OAAgB,mBAAmB,EAAE,MAAM,CAAuC;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -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,
|
|
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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACxG,OAAgB,mBAAmB,EAAE,MAAM,CAAuC;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -76,8 +76,10 @@ var JsonPathAggregateDiviner = class extends import_diviner_abstract.AbstractDiv
|
|
|
76
76
|
__name(this, "JsonPathAggregateDiviner");
|
|
77
77
|
}
|
|
78
78
|
static configSchemas = [
|
|
79
|
+
...super.configSchemas,
|
|
79
80
|
import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema
|
|
80
81
|
];
|
|
82
|
+
static defaultConfigSchema = import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema;
|
|
81
83
|
_transforms;
|
|
82
84
|
_payloadTransformers;
|
|
83
85
|
_transformableSchemas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { 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, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<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 configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const 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,2BAAyD;AACzD,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,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AkB,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","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'\nexport * from './jsonpath'\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'\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 configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override 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;;;;;;;;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AAU;EACnF;AACF;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","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"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -49,8 +49,10 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
|
49
49
|
__name(this, "JsonPathAggregateDiviner");
|
|
50
50
|
}
|
|
51
51
|
static configSchemas = [
|
|
52
|
+
...super.configSchemas,
|
|
52
53
|
JsonPathAggregateDivinerConfigSchema
|
|
53
54
|
];
|
|
55
|
+
static defaultConfigSchema = JsonPathAggregateDivinerConfigSchema;
|
|
54
56
|
_transforms;
|
|
55
57
|
_payloadTransformers;
|
|
56
58
|
_transformableSchemas;
|
|
@@ -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, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<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 configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const 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,qBAAuC;AACzD,SAASC,4BAA4BC,4BAA4B;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AAOD,qBAAqBE;EAC1C;;;;EAKA,IAAcC,sBAA6D;AACzE,QAAI,CAAC,KAAKL;AAAsB,WAAKA,uBAAuBM,iCAAiC,KAAKC,gBAAgB;AAClH,WAAO,KAAKP;EACd;;;;EAKA,IAAcO,mBAAmE;AAC/E,WAAOC,SAAS,KAAKL,QAAQI,kBAAkB,MAAM,GAAGb,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAce,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;","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","_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'\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 configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override 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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AC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;","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"]}
|
package/dist/node/Diviner.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAA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AK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/node/Diviner.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -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,
|
|
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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACxG,OAAgB,mBAAmB,EAAE,MAAM,CAAuC;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/node/Diviner.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { AbstractDiviner } from '@xyo-network/diviner-abstract';
|
|
2
2
|
import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
3
3
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model';
|
|
4
|
-
import { Payload } from '@xyo-network/payload-model';
|
|
4
|
+
import { Payload, Schema } from '@xyo-network/payload-model';
|
|
5
5
|
export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
6
|
-
static configSchemas:
|
|
6
|
+
static configSchemas: Schema[];
|
|
7
|
+
static defaultConfigSchema: Schema;
|
|
7
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
8
9
|
private _payloadTransformers;
|
|
9
10
|
private _transformableSchemas;
|
|
@@ -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,
|
|
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,OAAgB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACxG,OAAgB,mBAAmB,EAAE,MAAM,CAAuC;IAElF,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAoBzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __reflectGet = Reflect.get;
|
|
6
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
10
|
var __export = (target, all) => {
|
|
@@ -22,6 +24,7 @@ var __publicField = (obj, key, value) => {
|
|
|
22
24
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
25
|
return value;
|
|
24
26
|
};
|
|
27
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
25
28
|
|
|
26
29
|
// src/index.ts
|
|
27
30
|
var src_exports = {};
|
|
@@ -145,8 +148,10 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends import_d
|
|
|
145
148
|
};
|
|
146
149
|
__name(_JsonPathAggregateDiviner, "JsonPathAggregateDiviner");
|
|
147
150
|
__publicField(_JsonPathAggregateDiviner, "configSchemas", [
|
|
151
|
+
...__superGet(_JsonPathAggregateDiviner, _JsonPathAggregateDiviner, "configSchemas"),
|
|
148
152
|
import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema
|
|
149
153
|
]);
|
|
154
|
+
__publicField(_JsonPathAggregateDiviner, "defaultConfigSchema", import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema);
|
|
150
155
|
var JsonPathAggregateDiviner = _JsonPathAggregateDiviner;
|
|
151
156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
157
|
0 && (module.exports = {
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { 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, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<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 configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const 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,2BAAyD;AACzD,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,+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M,GAAGX,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAca,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,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,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,uBAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;AA3EUnC;AACR,cAVWD,2BAUKsC,iBAAgB;EAACC;;AAV5B,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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { 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'\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 configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override 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,OA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T,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,uBAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;AA5EUnC;AACR,cAVWD,2BAUKsC,iBAA0B;KAAI,iEAAMA;EAAeC;;AACnE,cAXWvC,2BAWKwC,uBAA8BD;AAXzC,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"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __reflectGet = Reflect.get;
|
|
2
4
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
6
|
var __publicField = (obj, key, value) => {
|
|
5
7
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
8
|
return value;
|
|
7
9
|
};
|
|
10
|
+
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
8
11
|
|
|
9
12
|
// src/Diviner.ts
|
|
10
13
|
import { assertEx } from "@xylabs/assert";
|
|
@@ -118,8 +121,10 @@ var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends Abstract
|
|
|
118
121
|
};
|
|
119
122
|
__name(_JsonPathAggregateDiviner, "JsonPathAggregateDiviner");
|
|
120
123
|
__publicField(_JsonPathAggregateDiviner, "configSchemas", [
|
|
124
|
+
...__superGet(_JsonPathAggregateDiviner, _JsonPathAggregateDiviner, "configSchemas"),
|
|
121
125
|
JsonPathAggregateDivinerConfigSchema
|
|
122
126
|
]);
|
|
127
|
+
__publicField(_JsonPathAggregateDiviner, "defaultConfigSchema", JsonPathAggregateDivinerConfigSchema);
|
|
123
128
|
var JsonPathAggregateDiviner = _JsonPathAggregateDiviner;
|
|
124
129
|
export {
|
|
125
130
|
JsonPathAggregateDiviner,
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { 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, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<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 configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const 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,gB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nC;AACR,cAVWD,2BAUKsC,iBAAgB;EAACC;;AAV5B,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"]}
|
|
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'\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 configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override 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,Q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uDI,WAAOC,UAAS,UAAKL,WAAL,mBAAaI,kBAAkB,MAAM,GAAGX,UAAAA,2CAAqD;EAC/G;;;;EAKA,IAAca,uBAAiC;AAC7C,QAAI,CAAC,KAAKR;AAAuB,WAAKA,wBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB;AAC/F,WAAO,KAAKN;EACd;EAEA,MAAyBW,cAAcC,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,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,CAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,uBAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF;AACF;AA5EUnC;AACR,cAVWD,2BAUKsC,iBAA0B;KAAI,iEAAMA;EAAeC;;AACnE,cAXWvC,2BAWKwC,uBAA8BD;AAXzC,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"]}
|
package/package.json
CHANGED
|
@@ -12,22 +12,22 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^3.1.8",
|
|
14
14
|
"@xylabs/exists": "^3.1.8",
|
|
15
|
-
"@xyo-network/boundwitness-model": "~2.
|
|
16
|
-
"@xyo-network/diviner-abstract": "~2.
|
|
17
|
-
"@xyo-network/diviner-jsonpath-aggregate-model": "~2.
|
|
18
|
-
"@xyo-network/diviner-jsonpath-memory": "~2.
|
|
19
|
-
"@xyo-network/diviner-model": "~2.
|
|
20
|
-
"@xyo-network/payload-builder": "~2.
|
|
21
|
-
"@xyo-network/payload-model": "~2.
|
|
22
|
-
"@xyo-network/payload-utils": "~2.
|
|
15
|
+
"@xyo-network/boundwitness-model": "~2.97.1",
|
|
16
|
+
"@xyo-network/diviner-abstract": "~2.97.1",
|
|
17
|
+
"@xyo-network/diviner-jsonpath-aggregate-model": "~2.97.1",
|
|
18
|
+
"@xyo-network/diviner-jsonpath-memory": "~2.97.1",
|
|
19
|
+
"@xyo-network/diviner-model": "~2.97.1",
|
|
20
|
+
"@xyo-network/payload-builder": "~2.97.1",
|
|
21
|
+
"@xyo-network/payload-model": "~2.97.1",
|
|
22
|
+
"@xyo-network/payload-utils": "~2.97.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@xylabs/ts-scripts-yarn3": "^3.9.1",
|
|
26
26
|
"@xylabs/tsconfig": "^3.9.1",
|
|
27
|
-
"@xyo-network/account": "~2.
|
|
28
|
-
"@xyo-network/account-model": "~2.
|
|
29
|
-
"@xyo-network/boundwitness-builder": "~2.
|
|
30
|
-
"@xyo-network/diviner-jsonpath-model": "~2.
|
|
27
|
+
"@xyo-network/account": "~2.97.1",
|
|
28
|
+
"@xyo-network/account-model": "~2.97.1",
|
|
29
|
+
"@xyo-network/boundwitness-builder": "~2.97.1",
|
|
30
|
+
"@xyo-network/diviner-jsonpath-model": "~2.97.1",
|
|
31
31
|
"typescript": "^5.4.5"
|
|
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.
|
|
72
|
+
"version": "2.97.1",
|
|
73
73
|
"type": "module"
|
|
74
74
|
}
|
package/src/Diviner.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
SchemaToPayloadTransformersDictionary,
|
|
10
10
|
} from '@xyo-network/diviner-jsonpath-aggregate-model'
|
|
11
11
|
import { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'
|
|
12
|
-
import { Payload, PayloadSchema, WithOptionalMeta } from '@xyo-network/payload-model'
|
|
12
|
+
import { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'
|
|
13
13
|
import { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'
|
|
14
14
|
|
|
15
15
|
import { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'
|
|
@@ -26,7 +26,8 @@ export class JsonPathAggregateDiviner<
|
|
|
26
26
|
TOut
|
|
27
27
|
>,
|
|
28
28
|
> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
|
|
29
|
-
static override configSchemas = [JsonPathAggregateDivinerConfigSchema]
|
|
29
|
+
static override configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]
|
|
30
|
+
static override defaultConfigSchema: Schema = JsonPathAggregateDivinerConfigSchema
|
|
30
31
|
|
|
31
32
|
protected _transforms: PayloadTransformer[] | undefined
|
|
32
33
|
|