@xyo-network/diviner-jsonpath-aggregate-memory 2.84.19 → 2.85.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.map +1 -1
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +56 -44
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +59 -47
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.ts.map +1 -1
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +61 -45
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +64 -48
- package/dist/node/index.js.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.ts.map +1 -1
- package/package.json +15 -13
- package/src/Diviner.ts +10 -6
- package/src/jsonpath/reducePayloads.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EA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,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,69 +31,82 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
31
|
// src/Diviner.ts
|
|
31
32
|
var import_assert = require("@xylabs/assert");
|
|
32
33
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
34
|
+
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
33
35
|
var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
|
|
34
36
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
37
|
+
var import_payload_utils = require("@xyo-network/payload-utils");
|
|
35
38
|
|
|
36
39
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
37
40
|
var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
|
|
38
|
-
var jsonPathToTransformersDictionary = (schemaTransforms) => {
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
41
|
+
var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms) => {
|
|
42
|
+
return Object.fromEntries(Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
|
|
43
|
+
const transformers = jsonPathTransformerExpressions.map(import_diviner_jsonpath_memory.toPayloadTransformer);
|
|
44
|
+
return [
|
|
45
|
+
schema,
|
|
46
|
+
transformers
|
|
47
|
+
];
|
|
48
|
+
}));
|
|
49
|
+
}, "jsonPathToTransformersDictionary");
|
|
46
50
|
|
|
47
51
|
// src/jsonpath/reducePayloads.ts
|
|
52
|
+
var import_exists = require("@xylabs/exists");
|
|
48
53
|
var import_hash = require("@xyo-network/hash");
|
|
49
54
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
50
|
-
var reducePayloads = async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
51
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
55
|
+
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
56
|
+
const payloadFields = payloads.filter(import_exists.exists).flatMap((payload) => {
|
|
52
57
|
const transformers = payloadTransformers[payload.schema];
|
|
53
58
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
54
59
|
});
|
|
55
|
-
const baseObject = excludeSources ? {} : {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const baseObject = excludeSources ? {} : {
|
|
61
|
+
sources: (await import_hash.PayloadHasher.hashPairs([
|
|
62
|
+
...payloads
|
|
63
|
+
])).map(([, hash]) => hash)
|
|
64
|
+
};
|
|
65
|
+
return await new import_payload_builder.PayloadBuilder({
|
|
66
|
+
schema: destinationSchema
|
|
67
|
+
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
68
|
+
}, "reducePayloads");
|
|
69
|
+
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
70
|
+
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
71
|
+
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
72
|
+
}));
|
|
73
|
+
}, "reducePayloadsArray");
|
|
65
74
|
|
|
66
75
|
// src/Diviner.ts
|
|
67
76
|
var moduleName = "JsonPathAggregateDiviner";
|
|
68
77
|
var JsonPathAggregateDiviner = class extends import_abstract_diviner.AbstractDiviner {
|
|
69
|
-
static
|
|
78
|
+
static {
|
|
79
|
+
__name(this, "JsonPathAggregateDiviner");
|
|
80
|
+
}
|
|
81
|
+
static configSchemas = [
|
|
82
|
+
import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema
|
|
83
|
+
];
|
|
70
84
|
_transforms;
|
|
71
85
|
_payloadTransformers;
|
|
72
86
|
_transformableSchemas;
|
|
73
87
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
* The schema to use for the destination payloads
|
|
89
|
+
*/
|
|
76
90
|
get destinationSchema() {
|
|
77
91
|
return this.config.destinationSchema ?? import_payload_model.PayloadSchema;
|
|
78
92
|
}
|
|
79
93
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
* Dictionary of schemas to payload transformers
|
|
95
|
+
*/
|
|
82
96
|
get payloadTransformers() {
|
|
83
97
|
if (!this._payloadTransformers)
|
|
84
98
|
this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
85
99
|
return this._payloadTransformers;
|
|
86
100
|
}
|
|
87
101
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
* The dictionary of schemas to JSON Path transform expressions
|
|
103
|
+
*/
|
|
90
104
|
get schemaTransforms() {
|
|
91
105
|
return (0, import_assert.assertEx)(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
108
|
+
* List of transformable schemas for this diviner
|
|
109
|
+
*/
|
|
96
110
|
get transformableSchemas() {
|
|
97
111
|
if (!this._transformableSchemas)
|
|
98
112
|
this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
@@ -101,27 +115,25 @@ var JsonPathAggregateDiviner = class extends import_abstract_diviner.AbstractDiv
|
|
|
101
115
|
async divineHandler(payloads) {
|
|
102
116
|
if (!payloads)
|
|
103
117
|
return [];
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
this.payloadTransformers,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
);
|
|
110
|
-
return [reducedPayloads];
|
|
118
|
+
const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(payloads) : await (0, import_payload_utils.combinationsBySchema)(payloads, this.transformableSchemas);
|
|
119
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
120
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
121
|
+
}));
|
|
122
|
+
return reducedPayloads;
|
|
111
123
|
}
|
|
112
124
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
* Identifies if a payload is one that is transformed by this diviner
|
|
126
|
+
* @param x The candidate payload
|
|
127
|
+
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
128
|
+
*/
|
|
117
129
|
isTransformablePayload = (x) => {
|
|
118
130
|
return this.transformableSchemas.includes(x?.schema);
|
|
119
131
|
};
|
|
120
132
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
* Identifies if a schema is one that is transformed by this diviner
|
|
134
|
+
* @param schema The candidate schema
|
|
135
|
+
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
136
|
+
*/
|
|
125
137
|
isTransformableSchema = (schema) => {
|
|
126
138
|
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
127
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAA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EF;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKR,IAAc,oBAA4B;AACxC,WAAO,KAAK,OAAO,qBAAqB;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,IAAc,sBAA6D;AACzE,QAAI,CAAC,KAAK;AAAsB,WAAK,uBAAuB,iCAAiC,KAAK,gBAAgB;AAClH,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAc,mBAAmE;AAC/E,eAAO,wBAAS,KAAK,QAAQ,kBAAkB,MAAM,GAAG,UAAU,2CAA2C;AAAA,EAC/G;AAAA;AAAA;AAAA;AAAA,EAKA,IAAc,uBAAiC;AAC7C,QAAI,CAAC,KAAK;AAAuB,WAAK,wBAAwB,OAAO,KAAK,KAAK,gBAAgB;AAC/F,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC;AAAU,aAAO,CAAC;AACvB,UAAM,kBAAkB,MAAM;AAAA,MAC5B;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,OAAO,kBAAkB;AAAA,IAChC;AACA,WAAO,CAAC,eAAe;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,yBAAyB,CAAC,MAAe;AACjD,WAAO,KAAK,qBAAqB,SAAS,GAAG,MAAM;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,wBAAwB,CAAC,WAA2B;AAC5D,WAAO,OAAO,WAAW,WAAW,KAAK,qBAAqB,SAAS,MAAM,IAAI;AAAA,EACnF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,gCAAmC;AACnC,8CAMO;AAEP,2BAAuC;AACvC,2BAAiE;;;ACXjE,qCAAqC;AAS9B,IAAMA,mCAAmC,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4B;AACxC,WAAO,KAAKC,OAAOD,qBAAqBE;EAC1C;;;;EAKA,IAAcC,sBAA6D;AACzE,QAAI,CAAC,KAAKL;AAAsB,WAAKA,uBAAuBM,iCAAiC,KAAKC,gBAAgB;AAClH,WAAO,KAAKP;EACd;;;;EAKA,IAAcO,mBAAmE;AAC/E,eAAOC,wBAAS,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,eAAe,KAAKL,qBAAqBM,SAASC,4CAAAA,IACpD,UAAMC,iDAA2BJ,QAAAA,IACjC,UAAMK,2CAAqBL,UAAU,KAAKJ,oBAAoB;AAClE,UAAMU,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaQ,IAAI,CAACC,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKlB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAOsB,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,71 +1,85 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/Diviner.ts
|
|
2
5
|
import { assertEx } from "@xylabs/assert";
|
|
3
6
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
7
|
+
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
8
|
+
import { JsonPathAggregateDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
7
9
|
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
10
|
+
import { combinationsByBoundwitness, combinationsBySchema } from "@xyo-network/payload-utils";
|
|
8
11
|
|
|
9
12
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
10
13
|
import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
|
|
11
|
-
var jsonPathToTransformersDictionary = (schemaTransforms) => {
|
|
12
|
-
return Object.fromEntries(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
14
|
+
var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms) => {
|
|
15
|
+
return Object.fromEntries(Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
|
|
16
|
+
const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer);
|
|
17
|
+
return [
|
|
18
|
+
schema,
|
|
19
|
+
transformers
|
|
20
|
+
];
|
|
21
|
+
}));
|
|
22
|
+
}, "jsonPathToTransformersDictionary");
|
|
19
23
|
|
|
20
24
|
// src/jsonpath/reducePayloads.ts
|
|
25
|
+
import { exists } from "@xylabs/exists";
|
|
21
26
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
22
27
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
23
|
-
var reducePayloads = async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
24
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
28
|
+
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
29
|
+
const payloadFields = payloads.filter(exists).flatMap((payload) => {
|
|
25
30
|
const transformers = payloadTransformers[payload.schema];
|
|
26
31
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
27
32
|
});
|
|
28
|
-
const baseObject = excludeSources ? {} : {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const baseObject = excludeSources ? {} : {
|
|
34
|
+
sources: (await PayloadHasher.hashPairs([
|
|
35
|
+
...payloads
|
|
36
|
+
])).map(([, hash]) => hash)
|
|
37
|
+
};
|
|
38
|
+
return await new PayloadBuilder({
|
|
39
|
+
schema: destinationSchema
|
|
40
|
+
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
41
|
+
}, "reducePayloads");
|
|
42
|
+
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
43
|
+
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
44
|
+
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
45
|
+
}));
|
|
46
|
+
}, "reducePayloadsArray");
|
|
38
47
|
|
|
39
48
|
// src/Diviner.ts
|
|
40
49
|
var moduleName = "JsonPathAggregateDiviner";
|
|
41
50
|
var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
42
|
-
static
|
|
51
|
+
static {
|
|
52
|
+
__name(this, "JsonPathAggregateDiviner");
|
|
53
|
+
}
|
|
54
|
+
static configSchemas = [
|
|
55
|
+
JsonPathAggregateDivinerConfigSchema
|
|
56
|
+
];
|
|
43
57
|
_transforms;
|
|
44
58
|
_payloadTransformers;
|
|
45
59
|
_transformableSchemas;
|
|
46
60
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
61
|
+
* The schema to use for the destination payloads
|
|
62
|
+
*/
|
|
49
63
|
get destinationSchema() {
|
|
50
64
|
return this.config.destinationSchema ?? PayloadSchema;
|
|
51
65
|
}
|
|
52
66
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
67
|
+
* Dictionary of schemas to payload transformers
|
|
68
|
+
*/
|
|
55
69
|
get payloadTransformers() {
|
|
56
70
|
if (!this._payloadTransformers)
|
|
57
71
|
this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
58
72
|
return this._payloadTransformers;
|
|
59
73
|
}
|
|
60
74
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
* The dictionary of schemas to JSON Path transform expressions
|
|
76
|
+
*/
|
|
63
77
|
get schemaTransforms() {
|
|
64
78
|
return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
65
79
|
}
|
|
66
80
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
* List of transformable schemas for this diviner
|
|
82
|
+
*/
|
|
69
83
|
get transformableSchemas() {
|
|
70
84
|
if (!this._transformableSchemas)
|
|
71
85
|
this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
@@ -74,27 +88,25 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
|
74
88
|
async divineHandler(payloads) {
|
|
75
89
|
if (!payloads)
|
|
76
90
|
return [];
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
this.payloadTransformers,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
return [reducedPayloads];
|
|
91
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(payloads) : await combinationsBySchema(payloads, this.transformableSchemas);
|
|
92
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
93
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
94
|
+
}));
|
|
95
|
+
return reducedPayloads;
|
|
84
96
|
}
|
|
85
97
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
98
|
+
* Identifies if a payload is one that is transformed by this diviner
|
|
99
|
+
* @param x The candidate payload
|
|
100
|
+
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
101
|
+
*/
|
|
90
102
|
isTransformablePayload = (x) => {
|
|
91
103
|
return this.transformableSchemas.includes(x?.schema);
|
|
92
104
|
};
|
|
93
105
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
* Identifies if a schema is one that is transformed by this diviner
|
|
107
|
+
* @param schema The candidate schema
|
|
108
|
+
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
109
|
+
*/
|
|
98
110
|
isTransformableSchema = (schema) => {
|
|
99
111
|
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
100
112
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,OAKK;AAEP,SAAkB,qBAAqB;;;ACTvC,SAAS,4BAA4B;AAS9B,IAAM,mCAAmC,CAC9C,qBAC0C;AAC1C,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,QAAQ,8BAA8B,MAAM;AACjF,YAAM,eAAe,+BAA+B,IAAI,oBAAoB;AAC5E,aAAO,CAAC,QAAQ,YAAY;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;;;AClBA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAWxB,IAAM,iBAA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iC;AAC7C,QAAI,CAAC,KAAK;AAAuB,WAAK,wBAAwB,OAAO,KAAK,KAAK,gBAAgB;AAC/F,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC;AAAU,aAAO,CAAC;AACvB,UAAM,kBAAkB,MAAM;AAAA,MAC5B;AAAA,MACA,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,OAAO,kBAAkB;AAAA,IAChC;AACA,WAAO,CAAC,eAAe;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,yBAAyB,CAAC,MAAe;AACjD,WAAO,KAAK,qBAAqB,SAAS,GAAG,MAAM;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,wBAAwB,CAAC,WAA2B;AAC5D,WAAO,OAAO,WAAW,WAAW,KAAK,qBAAqB,SAAS,MAAM,IAAI;AAAA,EACnF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SAASC,0BAA0B;AACnC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;AACvC,SAASC,4BAA4BC,4BAA4B;;;ACXjE,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,SAASE,cAAc;AAEvB,SAASC,qBAAqB;AAC9B,SAASC,sBAAsB;AAWxB,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAyB,CAACC,YAAAA;AAEtE,UAAM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,UAAmC;AACxE,QAAI,CAACA;AAAU,aAAO,CAAA;AACtB,UAAMC,eAAe,KAAKL,qBAAqBM,SAASC,kBAAAA,IACpD,MAAMC,2BAA2BJ,QAAAA,IACjC,MAAMK,qBAAqBL,UAAU,KAAKJ,oBAAoB;AAClE,UAAMU,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaQ,IAAI,CAACC,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKlB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAOsB,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,GAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;","names":["assertEx","AbstractDiviner","BoundWitnessSchema","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAOnE,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CACxI,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,OAAgB,aAAa,oDAAyC;IAEtE,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAEnD;;OAEG;IACH,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAED;;OAEG;IACH,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAED;;OAEG;IACH,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAazE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D,OAAO,EAEL,8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3,8 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
8
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
18
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
19
25
|
|
|
20
26
|
// src/index.ts
|
|
21
27
|
var src_exports = {};
|
|
@@ -30,70 +36,77 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
36
|
// src/Diviner.ts
|
|
31
37
|
var import_assert = require("@xylabs/assert");
|
|
32
38
|
var import_abstract_diviner = require("@xyo-network/abstract-diviner");
|
|
39
|
+
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
33
40
|
var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
|
|
34
41
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
42
|
+
var import_payload_utils = require("@xyo-network/payload-utils");
|
|
35
43
|
|
|
36
44
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
37
45
|
var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
|
|
38
|
-
var jsonPathToTransformersDictionary = (schemaTransforms) => {
|
|
39
|
-
return Object.fromEntries(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
+
var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms) => {
|
|
47
|
+
return Object.fromEntries(Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
|
|
48
|
+
const transformers = jsonPathTransformerExpressions.map(import_diviner_jsonpath_memory.toPayloadTransformer);
|
|
49
|
+
return [
|
|
50
|
+
schema,
|
|
51
|
+
transformers
|
|
52
|
+
];
|
|
53
|
+
}));
|
|
54
|
+
}, "jsonPathToTransformersDictionary");
|
|
46
55
|
|
|
47
56
|
// src/jsonpath/reducePayloads.ts
|
|
57
|
+
var import_exists = require("@xylabs/exists");
|
|
48
58
|
var import_hash = require("@xyo-network/hash");
|
|
49
59
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
50
|
-
var reducePayloads = async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
51
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
60
|
+
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
61
|
+
const payloadFields = payloads.filter(import_exists.exists).flatMap((payload) => {
|
|
52
62
|
const transformers = payloadTransformers[payload.schema];
|
|
53
63
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
54
64
|
});
|
|
55
|
-
const baseObject = excludeSources ? {} : {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const baseObject = excludeSources ? {} : {
|
|
66
|
+
sources: (await import_hash.PayloadHasher.hashPairs([
|
|
67
|
+
...payloads
|
|
68
|
+
])).map(([, hash]) => hash)
|
|
69
|
+
};
|
|
70
|
+
return await new import_payload_builder.PayloadBuilder({
|
|
71
|
+
schema: destinationSchema
|
|
72
|
+
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
73
|
+
}, "reducePayloads");
|
|
74
|
+
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
75
|
+
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
76
|
+
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
77
|
+
}));
|
|
78
|
+
}, "reducePayloadsArray");
|
|
65
79
|
|
|
66
80
|
// src/Diviner.ts
|
|
67
81
|
var moduleName = "JsonPathAggregateDiviner";
|
|
68
|
-
var
|
|
69
|
-
static configSchemas = [import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema];
|
|
82
|
+
var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends import_abstract_diviner.AbstractDiviner {
|
|
70
83
|
_transforms;
|
|
71
84
|
_payloadTransformers;
|
|
72
85
|
_transformableSchemas;
|
|
73
86
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
* The schema to use for the destination payloads
|
|
88
|
+
*/
|
|
76
89
|
get destinationSchema() {
|
|
77
90
|
return this.config.destinationSchema ?? import_payload_model.PayloadSchema;
|
|
78
91
|
}
|
|
79
92
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
* Dictionary of schemas to payload transformers
|
|
94
|
+
*/
|
|
82
95
|
get payloadTransformers() {
|
|
83
96
|
if (!this._payloadTransformers)
|
|
84
97
|
this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
85
98
|
return this._payloadTransformers;
|
|
86
99
|
}
|
|
87
100
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
* The dictionary of schemas to JSON Path transform expressions
|
|
102
|
+
*/
|
|
90
103
|
get schemaTransforms() {
|
|
91
104
|
var _a;
|
|
92
105
|
return (0, import_assert.assertEx)((_a = this.config) == null ? void 0 : _a.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
93
106
|
}
|
|
94
107
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
* List of transformable schemas for this diviner
|
|
109
|
+
*/
|
|
97
110
|
get transformableSchemas() {
|
|
98
111
|
if (!this._transformableSchemas)
|
|
99
112
|
this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
@@ -102,31 +115,34 @@ var JsonPathAggregateDiviner = class extends import_abstract_diviner.AbstractDiv
|
|
|
102
115
|
async divineHandler(payloads) {
|
|
103
116
|
if (!payloads)
|
|
104
117
|
return [];
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
this.payloadTransformers,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
return [reducedPayloads];
|
|
118
|
+
const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(payloads) : await (0, import_payload_utils.combinationsBySchema)(payloads, this.transformableSchemas);
|
|
119
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
120
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
121
|
+
}));
|
|
122
|
+
return reducedPayloads;
|
|
112
123
|
}
|
|
113
124
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
* Identifies if a payload is one that is transformed by this diviner
|
|
126
|
+
* @param x The candidate payload
|
|
127
|
+
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
128
|
+
*/
|
|
118
129
|
isTransformablePayload = (x) => {
|
|
119
130
|
return this.transformableSchemas.includes(x == null ? void 0 : x.schema);
|
|
120
131
|
};
|
|
121
132
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
* Identifies if a schema is one that is transformed by this diviner
|
|
134
|
+
* @param schema The candidate schema
|
|
135
|
+
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
136
|
+
*/
|
|
126
137
|
isTransformableSchema = (schema) => {
|
|
127
138
|
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
128
139
|
};
|
|
129
140
|
};
|
|
141
|
+
__name(_JsonPathAggregateDiviner, "JsonPathAggregateDiviner");
|
|
142
|
+
__publicField(_JsonPathAggregateDiviner, "configSchemas", [
|
|
143
|
+
import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema
|
|
144
|
+
]);
|
|
145
|
+
var JsonPathAggregateDiviner = _JsonPathAggregateDiviner;
|
|
130
146
|
// Annotate the CommonJS export names for ESM import in node:
|
|
131
147
|
0 && (module.exports = {
|
|
132
148
|
JsonPathAggregateDiviner,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,8CAMO;AAEP,2BAAuC;;;ACTvC,qCAAqC;AAS9B,IAAM,mCAAmC,CAC9C,qBAC0C;AAC1C,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,QAAQ,8BAA8B,MAAM;AACjF,YAAM,eAAe,+BAA+B,IAAI,mDAAoB;AAC5E,aAAO,CAAC,QAAQ,YAAY;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;;;AClBA,kBAA8B;AAC9B,6BAA+B;AAWxB,IAAM,iBAAiB,OAC5B,UACA,qBACA,mBACA,iBAAiB,UACF;AAEf,QAAM,gBAAgB,SAAS,QAAyB,CAAC,YAAY;AAEnE,UAAM,eAAe,oBAAoB,QAAQ,MAAM;AAEvD,WAAO,eAAe,aAAa,IAAI,CAAC,cAAc,UAAU,OAAO,CAAC,IAAI,CAAC;AAAA,EAC/E,CAAC;AAED,QAAM,aAAa,iBAAiB,CAAC,IAAI,EAAE,UAAU,MAAM,0BAAc,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI,EAAE;AAE3H,SAAO,MAAM,IAAI,sCAAkB,EAAE,QAAQ,kBAAkB,CAAC,EAAE,OAAO,OAAO,OAAO,YAAY,GAAG,aAAa,CAAC,EAAE,MAAM;AAC9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;AAAA,EAOU,wBAAwB,CAAC,WAA2B;AAC5D,WAAO,OAAO,WAAW,WAAW,KAAK,qBAAqB,SAAS,MAAM,IAAI;AAAA,EACnF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,8BAAgC;AAChC,gCAAmC;AACnC,8CAMO;AAEP,2BAAuC;AACvC,2BAAiE;;;ACXjE,qCAAqC;AAS9B,IAAMA,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,mDAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,oBAAuB;AAEvB,kBAA8B;AAC9B,6BAA+B;AAWxB,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAyB,CAACC,YAAAA;AAEtE,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,UAAU,MAAMC,0BAAcC,UAAU;SAAIhB;KAAS,GAAGW,IAAI,CAAC,CAAA,EAAGM,IAAAA,MAAUA,IAAAA;EAAM;AAE3H,SAAO,MAAM,IAAIC,sCAAkB;IAAER,QAAQR;EAAkB,CAAA,EAAGiB,OAAOC,OAAOC,OAAOR,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBkB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjC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AwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;AApEU9B;AACR,cANWD,2BAMKiC,iBAAgB;EAACC;;AAN5B,IAAMlC,2BAAN;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,72 +1,85 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
1
9
|
// src/Diviner.ts
|
|
2
10
|
import { assertEx } from "@xylabs/assert";
|
|
3
11
|
import { AbstractDiviner } from "@xyo-network/abstract-diviner";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
12
|
+
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
13
|
+
import { JsonPathAggregateDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
7
14
|
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
15
|
+
import { combinationsByBoundwitness, combinationsBySchema } from "@xyo-network/payload-utils";
|
|
8
16
|
|
|
9
17
|
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
10
18
|
import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
|
|
11
|
-
var jsonPathToTransformersDictionary = (schemaTransforms) => {
|
|
12
|
-
return Object.fromEntries(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
+
var jsonPathToTransformersDictionary = /* @__PURE__ */ __name((schemaTransforms) => {
|
|
20
|
+
return Object.fromEntries(Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
|
|
21
|
+
const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer);
|
|
22
|
+
return [
|
|
23
|
+
schema,
|
|
24
|
+
transformers
|
|
25
|
+
];
|
|
26
|
+
}));
|
|
27
|
+
}, "jsonPathToTransformersDictionary");
|
|
19
28
|
|
|
20
29
|
// src/jsonpath/reducePayloads.ts
|
|
30
|
+
import { exists } from "@xylabs/exists";
|
|
21
31
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
22
32
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
23
|
-
var reducePayloads = async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
24
|
-
const payloadFields = payloads.flatMap((payload) => {
|
|
33
|
+
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
34
|
+
const payloadFields = payloads.filter(exists).flatMap((payload) => {
|
|
25
35
|
const transformers = payloadTransformers[payload.schema];
|
|
26
36
|
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
27
37
|
});
|
|
28
|
-
const baseObject = excludeSources ? {} : {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const baseObject = excludeSources ? {} : {
|
|
39
|
+
sources: (await PayloadHasher.hashPairs([
|
|
40
|
+
...payloads
|
|
41
|
+
])).map(([, hash]) => hash)
|
|
42
|
+
};
|
|
43
|
+
return await new PayloadBuilder({
|
|
44
|
+
schema: destinationSchema
|
|
45
|
+
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
46
|
+
}, "reducePayloads");
|
|
47
|
+
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
48
|
+
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
49
|
+
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
50
|
+
}));
|
|
51
|
+
}, "reducePayloadsArray");
|
|
38
52
|
|
|
39
53
|
// src/Diviner.ts
|
|
40
54
|
var moduleName = "JsonPathAggregateDiviner";
|
|
41
|
-
var
|
|
42
|
-
static configSchemas = [JsonPathAggregateDivinerConfigSchema];
|
|
55
|
+
var _JsonPathAggregateDiviner = class _JsonPathAggregateDiviner extends AbstractDiviner {
|
|
43
56
|
_transforms;
|
|
44
57
|
_payloadTransformers;
|
|
45
58
|
_transformableSchemas;
|
|
46
59
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
* The schema to use for the destination payloads
|
|
61
|
+
*/
|
|
49
62
|
get destinationSchema() {
|
|
50
63
|
return this.config.destinationSchema ?? PayloadSchema;
|
|
51
64
|
}
|
|
52
65
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
66
|
+
* Dictionary of schemas to payload transformers
|
|
67
|
+
*/
|
|
55
68
|
get payloadTransformers() {
|
|
56
69
|
if (!this._payloadTransformers)
|
|
57
70
|
this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
58
71
|
return this._payloadTransformers;
|
|
59
72
|
}
|
|
60
73
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
74
|
+
* The dictionary of schemas to JSON Path transform expressions
|
|
75
|
+
*/
|
|
63
76
|
get schemaTransforms() {
|
|
64
77
|
var _a;
|
|
65
78
|
return assertEx((_a = this.config) == null ? void 0 : _a.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
66
79
|
}
|
|
67
80
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
* List of transformable schemas for this diviner
|
|
82
|
+
*/
|
|
70
83
|
get transformableSchemas() {
|
|
71
84
|
if (!this._transformableSchemas)
|
|
72
85
|
this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
@@ -75,31 +88,34 @@ var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
|
75
88
|
async divineHandler(payloads) {
|
|
76
89
|
if (!payloads)
|
|
77
90
|
return [];
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
this.payloadTransformers,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
return [reducedPayloads];
|
|
91
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(payloads) : await combinationsBySchema(payloads, this.transformableSchemas);
|
|
92
|
+
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
93
|
+
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
94
|
+
}));
|
|
95
|
+
return reducedPayloads;
|
|
85
96
|
}
|
|
86
97
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
* Identifies if a payload is one that is transformed by this diviner
|
|
99
|
+
* @param x The candidate payload
|
|
100
|
+
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
101
|
+
*/
|
|
91
102
|
isTransformablePayload = (x) => {
|
|
92
103
|
return this.transformableSchemas.includes(x == null ? void 0 : x.schema);
|
|
93
104
|
};
|
|
94
105
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
* Identifies if a schema is one that is transformed by this diviner
|
|
107
|
+
* @param schema The candidate schema
|
|
108
|
+
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
109
|
+
*/
|
|
99
110
|
isTransformableSchema = (schema) => {
|
|
100
111
|
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
101
112
|
};
|
|
102
113
|
};
|
|
114
|
+
__name(_JsonPathAggregateDiviner, "JsonPathAggregateDiviner");
|
|
115
|
+
__publicField(_JsonPathAggregateDiviner, "configSchemas", [
|
|
116
|
+
JsonPathAggregateDivinerConfigSchema
|
|
117
|
+
]);
|
|
118
|
+
var JsonPathAggregateDiviner = _JsonPathAggregateDiviner;
|
|
103
119
|
export {
|
|
104
120
|
JsonPathAggregateDiviner,
|
|
105
121
|
jsonPathToTransformersDictionary,
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const reducedPayloads = await reducePayloads<TOut>(\n payloads,\n this.payloadTransformers,\n this.destinationSchema,\n this.config.excludeSources ?? false,\n )\n return [reducedPayloads]\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,OAKK;AAEP,SAAkB,qBAAqB;;;ACTvC,SAAS,4BAA4B;AAS9B,IAAM,mCAAmC,CAC9C,qBAC0C;AAC1C,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,QAAQ,8BAA8B,MAAM;AACjF,YAAM,eAAe,+BAA+B,IAAI,oBAAoB;AAC5E,aAAO,CAAC,QAAQ,YAAY;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;;;AClBA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAWxB,IAAM,iBAAiB,OAC5B,UACA,qBACA,mBACA,iBAAiB,UACF;AAEf,QAAM,gBAAgB,SAAS,QAAyB,CAAC,YAAY;AAEnE,UAAM,eAAe,oBAAoB,QAAQ,MAAM;AAEvD,WAAO,eAAe,aAAa,IAAI,CAAC,cAAc,UAAU,OAAO,CAAC,IAAI,CAAC;AAAA,EAC/E,CAAC;AAED,QAAM,aAAa,iBAAiB,CAAC,IAAI,EAAE,UAAU,MAAM,cAAc,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAA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;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,yBAAyB,CAAC,MAAe;AACjD,WAAO,KAAK,qBAAqB,SAAS,uBAAG,MAAM;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,wBAAwB,CAAC,WAA2B;AAC5D,WAAO,OAAO,WAAW,WAAW,KAAK,qBAAqB,SAAS,MAAM,IAAI;AAAA,EACnF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/abstract-diviner'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override configSchemas = [JsonPathAggregateDivinerConfigSchema]\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const combinations = this.transformableSchemas.includes(BoundWitnessSchema)\n ? await combinationsByBoundwitness(payloads)\n : await combinationsBySchema(payloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport { Payload, PayloadFields } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,uBAAuB;AAChC,SAASC,0BAA0B;AACnC,SACEC,4CAKK;AAEP,SAAkBC,qBAAqB;AACvC,SAASC,4BAA4BC,4BAA4B;;;ACXjE,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,SAASE,cAAc;AAEvB,SAASC,qBAAqB;AAC9B,SAASC,sBAAsB;AAWxB,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAyB,CAACC,YAAAA;AAEtE,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,UAAU,MAAMC,cAAcC,UAAU;SAAIhB;KAAS,GAAGW,IAAI,CAAC,CAAA,EAAGM,IAAAA,MAAUA,IAAAA;EAAM;AAE3H,SAAO,MAAM,IAAIC,eAAkB;IAAER,QAAQR;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AAA;AAEF,WAAON;EACT;;;;;;EAOUO,yBAAyB,CAACC,MAAAA;AAClC,WAAO,KAAKlB,qBAAqBM,SAASY,uBAAGC,MAAAA;EAC/C;;;;;;EAOUC,wBAAwB,CAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKnB,qBAAqBM,SAASa,MAAAA,IAAU;EACnF;AACF;AApEU9B;AACR,cANWD,2BAMKiC,iBAAgB;EAACC;;AAN5B,IAAMlC,2BAAN;","names":["assertEx","AbstractDiviner","BoundWitnessSchema","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadHasher","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadHasher","hashPairs","hash","PayloadBuilder","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","map","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema","configSchemas","JsonPathAggregateDivinerConfigSchema"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrG,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;sBACf,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,yCAc1B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB;;;;2BACf,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,2CAQ1B,CAAA"}
|
package/package.json
CHANGED
|
@@ -11,22 +11,24 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
|
-
"@
|
|
15
|
-
"@xyo-network/diviner
|
|
16
|
-
"@xyo-network/diviner-model": "~2.
|
|
17
|
-
"@xyo-network/
|
|
18
|
-
"@xyo-network/
|
|
19
|
-
"@xyo-network/payload-
|
|
14
|
+
"@xylabs/exists": "^2.13.20",
|
|
15
|
+
"@xyo-network/abstract-diviner": "~2.85.1",
|
|
16
|
+
"@xyo-network/diviner-jsonpath-aggregate-model": "~2.85.1",
|
|
17
|
+
"@xyo-network/diviner-model": "~2.85.1",
|
|
18
|
+
"@xyo-network/hash": "~2.85.1",
|
|
19
|
+
"@xyo-network/payload-builder": "~2.85.1",
|
|
20
|
+
"@xyo-network/payload-model": "~2.85.1",
|
|
21
|
+
"@xyo-network/payload-utils": "~2.85.1"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
24
|
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
23
25
|
"@xylabs/tsconfig": "^3.2.25",
|
|
24
|
-
"@xyo-network/account": "~2.
|
|
25
|
-
"@xyo-network/boundwitness-builder": "~2.
|
|
26
|
-
"@xyo-network/boundwitness-model": "~2.
|
|
27
|
-
"@xyo-network/diviner-jsonpath-memory": "~2.
|
|
28
|
-
"@xyo-network/diviner-jsonpath-model": "~2.
|
|
29
|
-
"@xyo-network/wallet-model": "~2.
|
|
26
|
+
"@xyo-network/account": "~2.85.1",
|
|
27
|
+
"@xyo-network/boundwitness-builder": "~2.85.1",
|
|
28
|
+
"@xyo-network/boundwitness-model": "~2.85.1",
|
|
29
|
+
"@xyo-network/diviner-jsonpath-memory": "~2.85.1",
|
|
30
|
+
"@xyo-network/diviner-jsonpath-model": "~2.85.1",
|
|
31
|
+
"@xyo-network/wallet-model": "~2.85.1",
|
|
30
32
|
"typescript": "^5.3.3"
|
|
31
33
|
},
|
|
32
34
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -68,6 +70,6 @@
|
|
|
68
70
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
69
71
|
},
|
|
70
72
|
"sideEffects": false,
|
|
71
|
-
"version": "2.
|
|
73
|
+
"version": "2.85.1",
|
|
72
74
|
"type": "module"
|
|
73
75
|
}
|
package/src/Diviner.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { AbstractDiviner } from '@xyo-network/abstract-diviner'
|
|
3
|
+
import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
|
|
3
4
|
import {
|
|
4
5
|
JsonPathAggregateDivinerConfigSchema,
|
|
5
6
|
JsonPathAggregateDivinerParams,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
} from '@xyo-network/diviner-jsonpath-aggregate-model'
|
|
10
11
|
import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model'
|
|
11
12
|
import { Payload, PayloadSchema } from '@xyo-network/payload-model'
|
|
13
|
+
import { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'
|
|
12
14
|
|
|
13
15
|
import { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'
|
|
14
16
|
|
|
@@ -59,13 +61,15 @@ export class JsonPathAggregateDiviner<
|
|
|
59
61
|
|
|
60
62
|
protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {
|
|
61
63
|
if (!payloads) return []
|
|
62
|
-
const
|
|
63
|
-
payloads
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const combinations = this.transformableSchemas.includes(BoundWitnessSchema)
|
|
65
|
+
? await combinationsByBoundwitness(payloads)
|
|
66
|
+
: await combinationsBySchema(payloads, this.transformableSchemas)
|
|
67
|
+
const reducedPayloads = await Promise.all(
|
|
68
|
+
combinations.map((combination) => {
|
|
69
|
+
return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)
|
|
70
|
+
}),
|
|
67
71
|
)
|
|
68
|
-
return
|
|
72
|
+
return reducedPayloads
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exists } from '@xylabs/exists'
|
|
1
2
|
import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'
|
|
2
3
|
import { PayloadHasher } from '@xyo-network/hash'
|
|
3
4
|
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
@@ -18,7 +19,7 @@ export const reducePayloads = async <T extends Payload = Payload>(
|
|
|
18
19
|
excludeSources = false,
|
|
19
20
|
): Promise<T> => {
|
|
20
21
|
// Use the payload transformers to convert the fields from the source payloads to the destination fields
|
|
21
|
-
const payloadFields = payloads.flatMap<PayloadFields[]>((payload) => {
|
|
22
|
+
const payloadFields = payloads.filter(exists).flatMap<PayloadFields[]>((payload) => {
|
|
22
23
|
// Find the transformers for this payload
|
|
23
24
|
const transformers = payloadTransformers[payload.schema]
|
|
24
25
|
// If transformers exist, apply them to the payload otherwise return an empty array
|