@xyo-network/diviner-jsonpath-aggregate-memory 2.106.0 → 2.107.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 +0 -22
- package/dist/browser/Diviner.d.cts.map +1 -1
- package/dist/browser/Diviner.d.mts +0 -22
- package/dist/browser/Diviner.d.mts.map +1 -1
- package/dist/browser/Diviner.d.ts +0 -22
- package/dist/browser/Diviner.d.ts.map +1 -1
- package/dist/browser/index.cjs +1 -144
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +1 -123
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts +0 -7
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -1
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts +0 -7
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -1
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts +0 -7
- package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.cts +2 -21
- package/dist/browser/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.mts +2 -21
- package/dist/browser/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/browser/jsonpath/reducePayloads.d.ts +2 -21
- package/dist/browser/jsonpath/reducePayloads.d.ts.map +1 -1
- package/dist/neutral/Diviner.d.cts +0 -22
- package/dist/neutral/Diviner.d.cts.map +1 -1
- package/dist/neutral/Diviner.d.mts +0 -22
- package/dist/neutral/Diviner.d.mts.map +1 -1
- package/dist/neutral/Diviner.d.ts +0 -22
- package/dist/neutral/Diviner.d.ts.map +1 -1
- package/dist/neutral/index.cjs +1 -144
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +1 -123
- package/dist/neutral/index.js.map +1 -1
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.cts +0 -7
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -1
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.mts +0 -7
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -1
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.ts +0 -7
- package/dist/neutral/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -1
- package/dist/neutral/jsonpath/reducePayloads.d.cts +2 -21
- package/dist/neutral/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/neutral/jsonpath/reducePayloads.d.mts +2 -21
- package/dist/neutral/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/neutral/jsonpath/reducePayloads.d.ts +2 -21
- package/dist/neutral/jsonpath/reducePayloads.d.ts.map +1 -1
- package/dist/node/Diviner.d.cts +0 -22
- package/dist/node/Diviner.d.cts.map +1 -1
- package/dist/node/Diviner.d.mts +0 -22
- package/dist/node/Diviner.d.mts.map +1 -1
- package/dist/node/Diviner.d.ts +0 -22
- package/dist/node/Diviner.d.ts.map +1 -1
- package/dist/node/index.cjs +1 -156
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +1 -128
- package/dist/node/index.js.map +1 -1
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts +0 -7
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -1
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts +0 -7
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -1
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts +0 -7
- package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.cts +2 -21
- package/dist/node/jsonpath/reducePayloads.d.cts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.mts +2 -21
- package/dist/node/jsonpath/reducePayloads.d.mts.map +1 -1
- package/dist/node/jsonpath/reducePayloads.d.ts +2 -21
- package/dist/node/jsonpath/reducePayloads.d.ts.map +1 -1
- package/package.json +16 -16
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
2
2
|
import { Payload, WithMeta } from '@xyo-network/payload-model';
|
|
3
|
-
|
|
4
|
-
* Reduces the payloads to a single payload using the supplied transformers
|
|
5
|
-
* @param payloads The payloads to reduce
|
|
6
|
-
* @param payloadTransformers The transformers to use to convert the payloads to the destination payload
|
|
7
|
-
* @param destinationSchema The schema of the destination payload
|
|
8
|
-
* @param excludeSources Exclude the source hashes from the destination payload
|
|
9
|
-
* @returns The reduced payload
|
|
10
|
-
*/
|
|
11
|
-
export declare const reducePayloads: <T extends {
|
|
12
|
-
schema: string;
|
|
13
|
-
} & import("@xyo-network/payload-model").PayloadFields = {
|
|
3
|
+
export declare const reducePayloads: <T extends Payload = {
|
|
14
4
|
schema: string;
|
|
15
5
|
} & import("@xyo-network/payload-model").PayloadFields>(payloads: Payload[], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string, excludeSources?: boolean) => Promise<WithMeta<T>>;
|
|
16
|
-
|
|
17
|
-
* Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
|
|
18
|
-
* @param payloadsArray The arrays of payloads to reduce
|
|
19
|
-
* @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
|
|
20
|
-
* @param excludeSources Exclude the source hashes from the destination payload
|
|
21
|
-
* @returns The reduced payloads
|
|
22
|
-
*/
|
|
23
|
-
export declare const reducePayloadsArray: <T extends {
|
|
24
|
-
schema: string;
|
|
25
|
-
} & import("@xyo-network/payload-model").PayloadFields = {
|
|
6
|
+
export declare const reducePayloadsArray: <T extends Payload = {
|
|
26
7
|
schema: string;
|
|
27
8
|
} & import("@xyo-network/payload-model").PayloadFields>(payloadsArray: Payload[][], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string, excludeSources?: boolean) => Promise<T[]>;
|
|
28
9
|
//# sourceMappingURL=reducePayloads.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAU9D,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,OAAO;;kEAC1C,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,+BAExB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAYrB,CAAA;AASD,eAAO,MAAM,mBAAmB,GAAU,CAAC,SAAS,OAAO;;uEAC1C,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,+BAExB,OAAO,CAAC,CAAC,EAAE,CAMb,CAAA"}
|
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
import { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
2
2
|
import { Payload, WithMeta } from '@xyo-network/payload-model';
|
|
3
|
-
|
|
4
|
-
* Reduces the payloads to a single payload using the supplied transformers
|
|
5
|
-
* @param payloads The payloads to reduce
|
|
6
|
-
* @param payloadTransformers The transformers to use to convert the payloads to the destination payload
|
|
7
|
-
* @param destinationSchema The schema of the destination payload
|
|
8
|
-
* @param excludeSources Exclude the source hashes from the destination payload
|
|
9
|
-
* @returns The reduced payload
|
|
10
|
-
*/
|
|
11
|
-
export declare const reducePayloads: <T extends {
|
|
12
|
-
schema: string;
|
|
13
|
-
} & import("@xyo-network/payload-model").PayloadFields = {
|
|
3
|
+
export declare const reducePayloads: <T extends Payload = {
|
|
14
4
|
schema: string;
|
|
15
5
|
} & import("@xyo-network/payload-model").PayloadFields>(payloads: Payload[], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string, excludeSources?: boolean) => Promise<WithMeta<T>>;
|
|
16
|
-
|
|
17
|
-
* Reduces the arrays of payload arrays to an array of payloads using the supplied transformers
|
|
18
|
-
* @param payloadsArray The arrays of payloads to reduce
|
|
19
|
-
* @param payloadTransformers The transformers to use to convert the payloads to the destination payloads
|
|
20
|
-
* @param excludeSources Exclude the source hashes from the destination payload
|
|
21
|
-
* @returns The reduced payloads
|
|
22
|
-
*/
|
|
23
|
-
export declare const reducePayloadsArray: <T extends {
|
|
24
|
-
schema: string;
|
|
25
|
-
} & import("@xyo-network/payload-model").PayloadFields = {
|
|
6
|
+
export declare const reducePayloadsArray: <T extends Payload = {
|
|
26
7
|
schema: string;
|
|
27
8
|
} & import("@xyo-network/payload-model").PayloadFields>(payloadsArray: Payload[][], payloadTransformers: SchemaToPayloadTransformersDictionary, destinationSchema: string, excludeSources?: boolean) => Promise<T[]>;
|
|
28
9
|
//# sourceMappingURL=reducePayloads.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"reducePayloads.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/reducePayloads.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAErG,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAU9D,eAAO,MAAM,cAAc,GAAU,CAAC,SAAS,OAAO;;kEAC1C,OAAO,EAAE,uBACE,qCAAqC,qBACvC,MAAM,+BAExB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAYrB,CAAA;AASD,eAAO,MAAM,mBAAmB,GAAU,CAAC,SAAS,OAAO;;uEAC1C,OAAO,EAAE,EAAE,uBACL,qCAAqC,qBACvC,MAAM,+BAExB,OAAO,CAAC,CAAC,EAAE,CAMb,CAAA"}
|
|
@@ -8,34 +8,12 @@ export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateD
|
|
|
8
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
9
9
|
private _payloadTransformers;
|
|
10
10
|
private _transformableSchemas;
|
|
11
|
-
/**
|
|
12
|
-
* The schema to use for the destination payloads
|
|
13
|
-
*/
|
|
14
11
|
protected get destinationSchema(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Dictionary of schemas to payload transformers
|
|
17
|
-
*/
|
|
18
12
|
protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
|
|
19
|
-
/**
|
|
20
|
-
* The dictionary of schemas to JSON Path transform expressions
|
|
21
|
-
*/
|
|
22
13
|
protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
|
|
23
|
-
/**
|
|
24
|
-
* List of transformable schemas for this diviner
|
|
25
|
-
*/
|
|
26
14
|
protected get transformableSchemas(): string[];
|
|
27
15
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Identifies if a payload is one that is transformed by this diviner
|
|
30
|
-
* @param x The candidate payload
|
|
31
|
-
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
32
|
-
*/
|
|
33
16
|
protected isTransformablePayload: (x: Payload) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Identifies if a schema is one that is transformed by this diviner
|
|
36
|
-
* @param schema The candidate schema
|
|
37
|
-
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
38
|
-
*/
|
|
39
17
|
protected isTransformableSchema: (schema?: string | null) => boolean;
|
|
40
18
|
}
|
|
41
19
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAoB,MAAM,4BAA4B,CAAA;AAO7F,qBAAa,wBAAwB,CACnC,OAAO,SAAS,8BAA8B,GAAG,8BAA8B,EAC/E,GAAG,SAAS,OAAO,GAAG,OAAO,EAC7B,IAAI,SAAS,OAAO,GAAG,OAAO,EAC9B,UAAU,SAAS,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;
|
|
1
|
+
{"version":3,"file":"Diviner.d.ts","sourceRoot":"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AC;IAyBzE,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAOD,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
|
@@ -8,34 +8,12 @@ export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateD
|
|
|
8
8
|
protected _transforms: PayloadTransformer[] | undefined;
|
|
9
9
|
private _payloadTransformers;
|
|
10
10
|
private _transformableSchemas;
|
|
11
|
-
/**
|
|
12
|
-
* The schema to use for the destination payloads
|
|
13
|
-
*/
|
|
14
11
|
protected get destinationSchema(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Dictionary of schemas to payload transformers
|
|
17
|
-
*/
|
|
18
12
|
protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
|
|
19
|
-
/**
|
|
20
|
-
* The dictionary of schemas to JSON Path transform expressions
|
|
21
|
-
*/
|
|
22
13
|
protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
|
|
23
|
-
/**
|
|
24
|
-
* List of transformable schemas for this diviner
|
|
25
|
-
*/
|
|
26
14
|
protected get transformableSchemas(): string[];
|
|
27
15
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Identifies if a payload is one that is transformed by this diviner
|
|
30
|
-
* @param x The candidate payload
|
|
31
|
-
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
32
|
-
*/
|
|
33
16
|
protected isTransformablePayload: (x: Payload) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Identifies if a schema is one that is transformed by this diviner
|
|
36
|
-
* @param schema The candidate schema
|
|
37
|
-
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
38
|
-
*/
|
|
39
17
|
protected isTransformableSchema: (schema?: string | null) => boolean;
|
|
40
18
|
}
|
|
41
19
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["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_payloadTransformers;
|
|
10
10
|
private _transformableSchemas;
|
|
11
|
-
/**
|
|
12
|
-
* The schema to use for the destination payloads
|
|
13
|
-
*/
|
|
14
11
|
protected get destinationSchema(): string;
|
|
15
|
-
/**
|
|
16
|
-
* Dictionary of schemas to payload transformers
|
|
17
|
-
*/
|
|
18
12
|
protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
|
|
19
|
-
/**
|
|
20
|
-
* The dictionary of schemas to JSON Path transform expressions
|
|
21
|
-
*/
|
|
22
13
|
protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
|
|
23
|
-
/**
|
|
24
|
-
* List of transformable schemas for this diviner
|
|
25
|
-
*/
|
|
26
14
|
protected get transformableSchemas(): string[];
|
|
27
15
|
protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
|
|
28
|
-
/**
|
|
29
|
-
* Identifies if a payload is one that is transformed by this diviner
|
|
30
|
-
* @param x The candidate payload
|
|
31
|
-
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
32
|
-
*/
|
|
33
16
|
protected isTransformablePayload: (x: Payload) => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Identifies if a schema is one that is transformed by this diviner
|
|
36
|
-
* @param schema The candidate schema
|
|
37
|
-
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
38
|
-
*/
|
|
39
17
|
protected isTransformableSchema: (schema?: string | null) => boolean;
|
|
40
18
|
}
|
|
41
19
|
//# sourceMappingURL=Diviner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,EAClB,8CAA8C,EAC9C,qCAAqC,EACtC,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4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,sBAAsB,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,sBAAsB,CAChH,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,EACnC,GAAG,EACH,IAAI,CACL,CACD,SAAQ,eAAe,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,CAAC;IACvD,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAiE;IACjH,gBAAyB,mBAAmB,EAAE,MAAM,CAAuC;IAE3F,SAAS,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAA;IAEvD,OAAO,CAAC,oBAAoB,CAAmD;IAC/E,OAAO,CAAC,qBAAqB,CAAsB;IAKnD,SAAS,KAAK,iBAAiB,IAAI,MAAM,CAExC;IAKD,SAAS,KAAK,mBAAmB,IAAI,qCAAqC,CAGzE;IAKD,SAAS,KAAK,gBAAgB,IAAI,8CAA8C,CAE/E;IAKD,SAAS,KAAK,oBAAoB,IAAI,MAAM,EAAE,CAG7C;cAEwB,aAAa,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAyBzE,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAOD,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -1,145 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
|
|
21
|
-
// src/index.ts
|
|
22
|
-
var src_exports = {};
|
|
23
|
-
__export(src_exports, {
|
|
24
|
-
JsonPathAggregateDiviner: () => JsonPathAggregateDiviner,
|
|
25
|
-
jsonPathToTransformersDictionary: () => jsonPathToTransformersDictionary,
|
|
26
|
-
reducePayloads: () => reducePayloads,
|
|
27
|
-
reducePayloadsArray: () => reducePayloadsArray
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(src_exports);
|
|
30
|
-
|
|
31
|
-
// src/Diviner.ts
|
|
32
|
-
var import_assert = require("@xylabs/assert");
|
|
33
|
-
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
34
|
-
var import_diviner_abstract = require("@xyo-network/diviner-abstract");
|
|
35
|
-
var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
|
|
36
|
-
var import_payload_model = require("@xyo-network/payload-model");
|
|
37
|
-
var import_payload_utils = require("@xyo-network/payload-utils");
|
|
38
|
-
|
|
39
|
-
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
40
|
-
var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
|
|
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");
|
|
50
|
-
|
|
51
|
-
// src/jsonpath/reducePayloads.ts
|
|
52
|
-
var import_exists = require("@xylabs/exists");
|
|
53
|
-
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
54
|
-
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
55
|
-
const payloadFields = payloads.filter(import_exists.exists).flatMap((payload) => {
|
|
56
|
-
const transformers = payloadTransformers[payload.schema];
|
|
57
|
-
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
58
|
-
});
|
|
59
|
-
const baseObject = excludeSources ? {} : {
|
|
60
|
-
sources: await import_payload_builder.PayloadBuilder.dataHashes(payloads)
|
|
61
|
-
};
|
|
62
|
-
return await new import_payload_builder.PayloadBuilder({
|
|
63
|
-
schema: destinationSchema
|
|
64
|
-
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
65
|
-
}, "reducePayloads");
|
|
66
|
-
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
67
|
-
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
68
|
-
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
69
|
-
}));
|
|
70
|
-
}, "reducePayloadsArray");
|
|
71
|
-
|
|
72
|
-
// src/Diviner.ts
|
|
73
|
-
var moduleName = "JsonPathAggregateDiviner";
|
|
74
|
-
var JsonPathAggregateDiviner = class extends import_diviner_abstract.AbstractDiviner {
|
|
75
|
-
static {
|
|
76
|
-
__name(this, "JsonPathAggregateDiviner");
|
|
77
|
-
}
|
|
78
|
-
static configSchemas = [
|
|
79
|
-
...super.configSchemas,
|
|
80
|
-
import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema
|
|
81
|
-
];
|
|
82
|
-
static defaultConfigSchema = import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema;
|
|
83
|
-
_transforms;
|
|
84
|
-
_payloadTransformers;
|
|
85
|
-
_transformableSchemas;
|
|
86
|
-
/**
|
|
87
|
-
* The schema to use for the destination payloads
|
|
88
|
-
*/
|
|
89
|
-
get destinationSchema() {
|
|
90
|
-
return this.config.destinationSchema ?? import_payload_model.PayloadSchema;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Dictionary of schemas to payload transformers
|
|
94
|
-
*/
|
|
95
|
-
get payloadTransformers() {
|
|
96
|
-
if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
97
|
-
return this._payloadTransformers;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The dictionary of schemas to JSON Path transform expressions
|
|
101
|
-
*/
|
|
102
|
-
get schemaTransforms() {
|
|
103
|
-
return (0, import_assert.assertEx)(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* List of transformable schemas for this diviner
|
|
107
|
-
*/
|
|
108
|
-
get transformableSchemas() {
|
|
109
|
-
if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
110
|
-
return this._transformableSchemas;
|
|
111
|
-
}
|
|
112
|
-
async divineHandler(payloads) {
|
|
113
|
-
if (!payloads) return [];
|
|
114
|
-
const strippedPayloads = payloads.map((payload) => {
|
|
115
|
-
const p = {
|
|
116
|
-
...payload
|
|
117
|
-
};
|
|
118
|
-
delete p.$hash;
|
|
119
|
-
delete p.$meta;
|
|
120
|
-
return p;
|
|
121
|
-
});
|
|
122
|
-
const combinations = this.transformableSchemas.includes(import_boundwitness_model.BoundWitnessSchema) ? await (0, import_payload_utils.combinationsByBoundwitness)(strippedPayloads) : await (0, import_payload_utils.combinationsBySchema)(strippedPayloads, this.transformableSchemas);
|
|
123
|
-
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
124
|
-
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
125
|
-
}));
|
|
126
|
-
return reducedPayloads;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Identifies if a payload is one that is transformed by this diviner
|
|
130
|
-
* @param x The candidate payload
|
|
131
|
-
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
132
|
-
*/
|
|
133
|
-
isTransformablePayload = /* @__PURE__ */ __name((x) => {
|
|
134
|
-
return this.transformableSchemas.includes(x?.schema);
|
|
135
|
-
}, "isTransformablePayload");
|
|
136
|
-
/**
|
|
137
|
-
* Identifies if a schema is one that is transformed by this diviner
|
|
138
|
-
* @param schema The candidate schema
|
|
139
|
-
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
140
|
-
*/
|
|
141
|
-
isTransformableSchema = /* @__PURE__ */ __name((schema) => {
|
|
142
|
-
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
143
|
-
}, "isTransformableSchema");
|
|
144
|
-
};
|
|
1
|
+
"use strict";var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var o=(r,a)=>m(r,"name",{value:a,configurable:!0});var B=(r,a)=>{for(var s in a)m(r,s,{get:a[s],enumerable:!0})},O=(r,a,s,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let t of _(a))!j.call(r,t)&&t!==s&&m(r,t,{get:()=>a[t],enumerable:!(e=w(a,t))||e.enumerable});return r};var D=r=>O(m({},"__esModule",{value:!0}),r);var $={};B($,{JsonPathAggregateDiviner:()=>u,jsonPathToTransformersDictionary:()=>h,reducePayloads:()=>c,reducePayloadsArray:()=>v});module.exports=D($);var S=require("@xylabs/assert"),g=require("@xyo-network/boundwitness-model"),T=require("@xyo-network/diviner-abstract"),d=require("@xyo-network/diviner-jsonpath-aggregate-model"),P=require("@xyo-network/payload-model"),f=require("@xyo-network/payload-utils");var y=require("@xyo-network/diviner-jsonpath-memory");var h=o(r=>Object.fromEntries(Object.entries(r).map(([a,s])=>{let e=s.map(y.toPayloadTransformer);return[a,e]})),"jsonPathToTransformersDictionary");var b=require("@xylabs/exists"),l=require("@xyo-network/payload-builder");var c=o(async(r,a,s,e=!1)=>{let t=r.filter(b.exists).flatMap(n=>{let p=a[n.schema];return p?p.map(x=>x(n)):[]}),i=e?{}:{sources:await l.PayloadBuilder.dataHashes(r)};return await new l.PayloadBuilder({schema:s}).fields(Object.assign(i,...t)).build()},"reducePayloads"),v=o(async(r,a,s,e=!1)=>await Promise.all(r.map(async t=>await c(t,a,s,e))),"reducePayloadsArray");var A="JsonPathAggregateDiviner",u=class extends T.AbstractDiviner{static{o(this,"JsonPathAggregateDiviner")}static configSchemas=[...super.configSchemas,d.JsonPathAggregateDivinerConfigSchema];static defaultConfigSchema=d.JsonPathAggregateDivinerConfigSchema;_transforms;_payloadTransformers;_transformableSchemas;get destinationSchema(){return this.config.destinationSchema??P.PayloadSchema}get payloadTransformers(){return this._payloadTransformers||(this._payloadTransformers=h(this.schemaTransforms)),this._payloadTransformers}get schemaTransforms(){return(0,S.assertEx)(this.config?.schemaTransforms,()=>`${A}: Missing config.schemaTransforms section`)}get transformableSchemas(){return this._transformableSchemas||(this._transformableSchemas=Object.keys(this.schemaTransforms)),this._transformableSchemas}async divineHandler(a){if(!a)return[];let s=a.map(i=>{let n={...i};return delete n.$hash,delete n.$meta,n}),e=this.transformableSchemas.includes(g.BoundWitnessSchema)?await(0,f.combinationsByBoundwitness)(s):await(0,f.combinationsBySchema)(s,this.transformableSchemas);return await Promise.all(e.map(i=>c(i,this.payloadTransformers,this.destinationSchema,this.config.excludeSources??!1)))}isTransformablePayload=o(a=>this.transformableSchemas.includes(a?.schema),"isTransformablePayload");isTransformableSchema=o(a=>typeof a=="string"?this.transformableSchemas.includes(a):!1,"isTransformableSchema")};
|
|
145
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathAggregateDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<WithMeta<T>> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<WithoutSchema<Payload>[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: await PayloadBuilder.dataHashes(payloads) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA,oBAAyB;AACzB,gCAAmC;AACnC,8BAAgC;AAChC,8CAMO;AAEP,2BAAiE;AACjE,2BAAiE;;;ACXjE,qCAAqC;AAS9B,IAAMA,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,mDAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,oBAAuB;AAEvB,6BAA8C;AAWvC,IAAME,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,oBAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,SAAS,MAAMC,sCAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,sCAAkB;IAAEL,QAAQR;EAAkB,CAAA,E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kBAAkB,KAAKL,oBAAoB;AAC1E,UAAMgB,kBAAkB,MAAMC,QAAQC,IACpCP,aAAaL,IAAI,CAACa,gBAAAA;AAChB,aAAOC,eAAqBD,aAAa,KAAKvB,qBAAqB,KAAKH,mBAAmB,KAAKC,OAAO2B,kBAAkB,KAAA;IAC3H,CAAA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","names":["jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './jsonpath'\n","import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathAggregateDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<WithMeta<T>> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<WithoutSchema<Payload>[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: await PayloadBuilder.dataHashes(payloads) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTrans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AggregateDiviner","jsonPathToTransformersDictionary","reducePayloads","reducePayloadsArray","__toCommonJS","import_assert","import_boundwitness_model","import_diviner_abstract","import_diviner_jsonpath_aggregate_model","import_payload_model","import_payload_utils","import_diviner_jsonpath_memory","jsonPathToTransformersDictionary","__name","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","import_exists","import_payload_builder","reducePayloads","__name","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","__name","x","schema","isTransformableSchema"]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -1,124 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/Diviner.ts
|
|
5
|
-
import { assertEx } from "@xylabs/assert";
|
|
6
|
-
import { BoundWitnessSchema } from "@xyo-network/boundwitness-model";
|
|
7
|
-
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
8
|
-
import { JsonPathAggregateDivinerConfigSchema } from "@xyo-network/diviner-jsonpath-aggregate-model";
|
|
9
|
-
import { PayloadSchema } from "@xyo-network/payload-model";
|
|
10
|
-
import { combinationsByBoundwitness, combinationsBySchema } from "@xyo-network/payload-utils";
|
|
11
|
-
|
|
12
|
-
// src/jsonpath/jsonPathToTransformersDictionary.ts
|
|
13
|
-
import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
|
|
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");
|
|
23
|
-
|
|
24
|
-
// src/jsonpath/reducePayloads.ts
|
|
25
|
-
import { exists } from "@xylabs/exists";
|
|
26
|
-
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
27
|
-
var reducePayloads = /* @__PURE__ */ __name(async (payloads, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
28
|
-
const payloadFields = payloads.filter(exists).flatMap((payload) => {
|
|
29
|
-
const transformers = payloadTransformers[payload.schema];
|
|
30
|
-
return transformers ? transformers.map((transform) => transform(payload)) : [];
|
|
31
|
-
});
|
|
32
|
-
const baseObject = excludeSources ? {} : {
|
|
33
|
-
sources: await PayloadBuilder.dataHashes(payloads)
|
|
34
|
-
};
|
|
35
|
-
return await new PayloadBuilder({
|
|
36
|
-
schema: destinationSchema
|
|
37
|
-
}).fields(Object.assign(baseObject, ...payloadFields)).build();
|
|
38
|
-
}, "reducePayloads");
|
|
39
|
-
var reducePayloadsArray = /* @__PURE__ */ __name(async (payloadsArray, payloadTransformers, destinationSchema, excludeSources = false) => {
|
|
40
|
-
return await Promise.all(payloadsArray.map(async (payloads) => {
|
|
41
|
-
return await reducePayloads(payloads, payloadTransformers, destinationSchema, excludeSources);
|
|
42
|
-
}));
|
|
43
|
-
}, "reducePayloadsArray");
|
|
44
|
-
|
|
45
|
-
// src/Diviner.ts
|
|
46
|
-
var moduleName = "JsonPathAggregateDiviner";
|
|
47
|
-
var JsonPathAggregateDiviner = class extends AbstractDiviner {
|
|
48
|
-
static {
|
|
49
|
-
__name(this, "JsonPathAggregateDiviner");
|
|
50
|
-
}
|
|
51
|
-
static configSchemas = [
|
|
52
|
-
...super.configSchemas,
|
|
53
|
-
JsonPathAggregateDivinerConfigSchema
|
|
54
|
-
];
|
|
55
|
-
static defaultConfigSchema = JsonPathAggregateDivinerConfigSchema;
|
|
56
|
-
_transforms;
|
|
57
|
-
_payloadTransformers;
|
|
58
|
-
_transformableSchemas;
|
|
59
|
-
/**
|
|
60
|
-
* The schema to use for the destination payloads
|
|
61
|
-
*/
|
|
62
|
-
get destinationSchema() {
|
|
63
|
-
return this.config.destinationSchema ?? PayloadSchema;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Dictionary of schemas to payload transformers
|
|
67
|
-
*/
|
|
68
|
-
get payloadTransformers() {
|
|
69
|
-
if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
|
|
70
|
-
return this._payloadTransformers;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* The dictionary of schemas to JSON Path transform expressions
|
|
74
|
-
*/
|
|
75
|
-
get schemaTransforms() {
|
|
76
|
-
return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* List of transformable schemas for this diviner
|
|
80
|
-
*/
|
|
81
|
-
get transformableSchemas() {
|
|
82
|
-
if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms);
|
|
83
|
-
return this._transformableSchemas;
|
|
84
|
-
}
|
|
85
|
-
async divineHandler(payloads) {
|
|
86
|
-
if (!payloads) return [];
|
|
87
|
-
const strippedPayloads = payloads.map((payload) => {
|
|
88
|
-
const p = {
|
|
89
|
-
...payload
|
|
90
|
-
};
|
|
91
|
-
delete p.$hash;
|
|
92
|
-
delete p.$meta;
|
|
93
|
-
return p;
|
|
94
|
-
});
|
|
95
|
-
const combinations = this.transformableSchemas.includes(BoundWitnessSchema) ? await combinationsByBoundwitness(strippedPayloads) : await combinationsBySchema(strippedPayloads, this.transformableSchemas);
|
|
96
|
-
const reducedPayloads = await Promise.all(combinations.map((combination) => {
|
|
97
|
-
return reducePayloads(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false);
|
|
98
|
-
}));
|
|
99
|
-
return reducedPayloads;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Identifies if a payload is one that is transformed by this diviner
|
|
103
|
-
* @param x The candidate payload
|
|
104
|
-
* @returns True if the payload is one transformed by this diviner, false otherwise
|
|
105
|
-
*/
|
|
106
|
-
isTransformablePayload = /* @__PURE__ */ __name((x) => {
|
|
107
|
-
return this.transformableSchemas.includes(x?.schema);
|
|
108
|
-
}, "isTransformablePayload");
|
|
109
|
-
/**
|
|
110
|
-
* Identifies if a schema is one that is transformed by this diviner
|
|
111
|
-
* @param schema The candidate schema
|
|
112
|
-
* @returns True if this schema is one transformed by this diviner, false otherwise
|
|
113
|
-
*/
|
|
114
|
-
isTransformableSchema = /* @__PURE__ */ __name((schema) => {
|
|
115
|
-
return typeof schema === "string" ? this.transformableSchemas.includes(schema) : false;
|
|
116
|
-
}, "isTransformableSchema");
|
|
117
|
-
};
|
|
118
|
-
export {
|
|
119
|
-
JsonPathAggregateDiviner,
|
|
120
|
-
jsonPathToTransformersDictionary,
|
|
121
|
-
reducePayloads,
|
|
122
|
-
reducePayloadsArray
|
|
123
|
-
};
|
|
1
|
+
var p=Object.defineProperty;var s=(r,a)=>p(r,"name",{value:a,configurable:!0});import{assertEx as S}from"@xylabs/assert";import{BoundWitnessSchema as g}from"@xyo-network/boundwitness-model";import{AbstractDiviner as T}from"@xyo-network/diviner-abstract";import{JsonPathAggregateDivinerConfigSchema as l}from"@xyo-network/diviner-jsonpath-aggregate-model";import{PayloadSchema as P}from"@xyo-network/payload-model";import{combinationsByBoundwitness as x,combinationsBySchema as w}from"@xyo-network/payload-utils";import{toPayloadTransformer as y}from"@xyo-network/diviner-jsonpath-memory";var f=s(r=>Object.fromEntries(Object.entries(r).map(([a,e])=>{let t=e.map(y);return[a,t]})),"jsonPathToTransformersDictionary");import{exists as b}from"@xylabs/exists";import{PayloadBuilder as h}from"@xyo-network/payload-builder";var m=s(async(r,a,e,t=!1)=>{let i=r.filter(b).flatMap(o=>{let c=a[o.schema];return c?c.map(u=>u(o)):[]}),n=t?{}:{sources:await h.dataHashes(r)};return await new h({schema:e}).fields(Object.assign(n,...i)).build()},"reducePayloads"),$=s(async(r,a,e,t=!1)=>await Promise.all(r.map(async i=>await m(i,a,e,t))),"reducePayloadsArray");var _="JsonPathAggregateDiviner",d=class extends T{static{s(this,"JsonPathAggregateDiviner")}static configSchemas=[...super.configSchemas,l];static defaultConfigSchema=l;_transforms;_payloadTransformers;_transformableSchemas;get destinationSchema(){return this.config.destinationSchema??P}get payloadTransformers(){return this._payloadTransformers||(this._payloadTransformers=f(this.schemaTransforms)),this._payloadTransformers}get schemaTransforms(){return S(this.config?.schemaTransforms,()=>`${_}: Missing config.schemaTransforms section`)}get transformableSchemas(){return this._transformableSchemas||(this._transformableSchemas=Object.keys(this.schemaTransforms)),this._transformableSchemas}async divineHandler(a){if(!a)return[];let e=a.map(n=>{let o={...n};return delete o.$hash,delete o.$meta,o}),t=this.transformableSchemas.includes(g)?await x(e):await w(e,this.transformableSchemas);return await Promise.all(t.map(n=>m(n,this.payloadTransformers,this.destinationSchema,this.config.excludeSources??!1)))}isTransformablePayload=s(a=>this.transformableSchemas.includes(a?.schema),"isTransformablePayload");isTransformableSchema=s(a=>typeof a=="string"?this.transformableSchemas.includes(a):!1,"isTransformableSchema")};export{d as JsonPathAggregateDiviner,f as jsonPathToTransformersDictionary,m as reducePayloads,$ as reducePayloadsArray};
|
|
124
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathAggregateDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<WithMeta<T>> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<WithoutSchema<Payload>[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: await PayloadBuilder.dataHashes(payloads) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":";;;;AAAA,SAASA,gBAAgB;AACzB,SAASC,0BAA0B;AACnC,SAASC,uBAAuB;AAChC,SACEC,4CAKK;AAEP,SAAkBC,qBAA+C;AACjE,SAASC,4BAA4BC,4BAA4B;;;ACXjE,SAASC,4BAA4B;AAS9B,IAAMC,mCAAmC,wBAC9CC,qBAAAA;AAEA,SAAOC,OAAOC,YACZD,OAAOE,QAAQH,gBAAAA,EAAkBI,IAAI,CAAC,CAACC,QAAQC,8BAAAA,MAA+B;AAC5E,UAAMC,eAAeD,+BAA+BF,IAAII,oBAAAA;AACxD,WAAO;MAACH;MAAQE;;EAClB,CAAA,CAAA;AAEJ,GATgD;;;ACVhD,SAASE,cAAc;AAEvB,SAASC,sBAAqC;AAWvC,IAAMC,iBAAiB,8BAC5BC,UACAC,qBACAC,mBACAC,iBAAiB,UAAK;AAGtB,QAAMC,gBAAgBJ,SAASK,OAAOC,MAAAA,EAAQC,QAAkC,CAACC,YAAAA;AAE/E,UAAMC,eAAeR,oBAAoBO,QAAQE,MAAM;AAEvD,WAAOD,eAAeA,aAAaE,IAAI,CAACC,cAAcA,UAAUJ,OAAAA,CAAAA,IAAY,CAAA;EAC9E,CAAA;AAEA,QAAMK,aAAaV,iBAAiB,CAAC,IAAI;IAAEW,SAAS,MAAMC,eAAeC,WAAWhB,QAAAA;EAAU;AAE9F,SAAO,MAAM,IAAIe,eAAkB;IAAEL,QAAQR;EAAkB,CAAA,EAAGe,OAAOC,OAAOC,OAAON,YAAAA,GAAeT,aAAAA,CAAAA,EAAgBgB,MAAK;AAC7H,GAjB8B;AA0BvB,IAAMC,sBAAsB,8BACjCC,eACArB,qBACAC,mBACAC,iBAAiB,UAAK;AAEtB,SAAO,MAAMoB,QAAQC,IACnBF,cAAcX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AA,CAAA;AAEF,WAAOL;EACT;;;;;;EAOUM,yBAAyB,wBAACC,MAAAA;AAClC,WAAO,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA;EAC/C,GAFmC;;;;;;EASzBC,wBAAwB,wBAACD,WAAAA;AACjC,WAAO,OAAOA,WAAW,WAAW,KAAKxB,qBAAqBY,SAASY,MAAAA,IAAU;EACnF,GAFkC;AAGpC;","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","reducedPayloads","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","x","schema","isTransformableSchema"]}
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { BoundWitnessSchema } from '@xyo-network/boundwitness-model'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport {\n JsonPathAggregateDivinerConfigSchema,\n JsonPathAggregateDivinerParams,\n PayloadTransformer,\n SchemaToJsonPathTransformExpressionsDictionary,\n SchemaToPayloadTransformersDictionary,\n} from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { DivinerInstance, DivinerModuleEventData } from '@xyo-network/diviner-model'\nimport { Payload, PayloadSchema, Schema, WithOptionalMeta } from '@xyo-network/payload-model'\nimport { combinationsByBoundwitness, combinationsBySchema } from '@xyo-network/payload-utils'\n\nimport { jsonPathToTransformersDictionary, reducePayloads } from './jsonpath'\n\nconst moduleName = 'JsonPathAggregateDiviner'\n\nexport class JsonPathAggregateDiviner<\n TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams,\n TIn extends Payload = Payload,\n TOut extends Payload = Payload,\n TEventData extends DivinerModuleEventData<DivinerInstance<TParams, TIn, TOut>, TIn, TOut> = DivinerModuleEventData<\n DivinerInstance<TParams, TIn, TOut>,\n TIn,\n TOut\n >,\n> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, JsonPathAggregateDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = JsonPathAggregateDivinerConfigSchema\n\n protected _transforms: PayloadTransformer[] | undefined\n\n private _payloadTransformers: SchemaToPayloadTransformersDictionary | undefined\n private _transformableSchemas: string[] | undefined\n\n /**\n * The schema to use for the destination payloads\n */\n protected get destinationSchema(): string {\n return this.config.destinationSchema ?? PayloadSchema\n }\n\n /**\n * Dictionary of schemas to payload transformers\n */\n protected get payloadTransformers(): SchemaToPayloadTransformersDictionary {\n if (!this._payloadTransformers) this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms)\n return this._payloadTransformers\n }\n\n /**\n * The dictionary of schemas to JSON Path transform expressions\n */\n protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary {\n return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`)\n }\n\n /**\n * List of transformable schemas for this diviner\n */\n protected get transformableSchemas(): string[] {\n if (!this._transformableSchemas) this._transformableSchemas = Object.keys(this.schemaTransforms)\n return this._transformableSchemas\n }\n\n protected override async divineHandler(payloads?: TIn[]): Promise<TOut[]> {\n if (!payloads) return []\n const strippedPayloads = payloads.map((payload) => {\n const p = { ...payload } as WithOptionalMeta<TIn>\n delete p.$hash\n delete p.$meta\n return p as TIn\n })\n const combinations =\n this.transformableSchemas.includes(BoundWitnessSchema) ?\n await combinationsByBoundwitness(strippedPayloads)\n : await combinationsBySchema(strippedPayloads, this.transformableSchemas)\n const reducedPayloads = await Promise.all(\n combinations.map((combination) => {\n return reducePayloads<TOut>(combination, this.payloadTransformers, this.destinationSchema, this.config.excludeSources ?? false)\n }),\n )\n return reducedPayloads\n }\n\n /**\n * Identifies if a payload is one that is transformed by this diviner\n * @param x The candidate payload\n * @returns True if the payload is one transformed by this diviner, false otherwise\n */\n protected isTransformablePayload = (x: Payload) => {\n return this.transformableSchemas.includes(x?.schema)\n }\n\n /**\n * Identifies if a schema is one that is transformed by this diviner\n * @param schema The candidate schema\n * @returns True if this schema is one transformed by this diviner, false otherwise\n */\n protected isTransformableSchema = (schema?: string | null) => {\n return typeof schema === 'string' ? this.transformableSchemas.includes(schema) : false\n }\n}\n","import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { toPayloadTransformer } from '@xyo-network/diviner-jsonpath-memory'\n\n/**\n * Materializes the JSON-path expressions into memoized functions by converting a\n * dictionary of schema to JSON Path transform expressions to a dictionary\n * of schema to payload transformers\n * @param schemaTransforms The schema transforms to convert\n * @returns A dictionary of schema to payload transformers\n */\nexport const jsonPathToTransformersDictionary = (\n schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary,\n): SchemaToPayloadTransformersDictionary => {\n return Object.fromEntries(\n Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {\n const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer)\n return [schema, transformers]\n }),\n )\n}\n","import { exists } from '@xylabs/exists'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\nimport { PayloadBuilder, WithoutSchema } from '@xyo-network/payload-builder'\nimport { Payload, WithMeta } from '@xyo-network/payload-model'\n\n/**\n * Reduces the payloads to a single payload using the supplied transformers\n * @param payloads The payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payload\n * @param destinationSchema The schema of the destination payload\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<WithMeta<T>> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const payloadFields = payloads.filter(exists).flatMap<WithoutSchema<Payload>[]>((payload) => {\n // Find the transformers for this payload\n const transformers = payloadTransformers[payload.schema]\n // If transformers exist, apply them to the payload otherwise return an empty array\n return transformers ? transformers.map((transform) => transform(payload)) : []\n })\n // Include all the sources for reference\n const baseObject = excludeSources ? {} : { sources: await PayloadBuilder.dataHashes(payloads) }\n // Build and return the payload\n return await new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign(baseObject, ...payloadFields)).build()\n}\n\n/**\n * Reduces the arrays of payload arrays to an array of payloads using the supplied transformers\n * @param payloadsArray The arrays of payloads to reduce\n * @param payloadTransformers The transformers to use to convert the payloads to the destination payloads\n * @param excludeSources Exclude the source hashes from the destination payload\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n excludeSources = false,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema, excludeSources)\n }),\n )\n}\n"],"mappings":"+EAAA,OAASA,YAAAA,MAAgB,iBACzB,OAASC,sBAAAA,MAA0B,kCACnC,OAASC,mBAAAA,M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AAyBC,oBAA8BD,EAE7CE,YAEFC,qBACAC,sBAKR,IAAcC,mBAA4B,CACxC,OAAO,KAAKC,OAAOD,mBAAqBE,CAC1C,CAKA,IAAcC,qBAA6D,CACzE,OAAK,KAAKL,uBAAsB,KAAKA,qBAAuBM,EAAiC,KAAKC,gBAAgB,GAC3G,KAAKP,oBACd,CAKA,IAAcO,kBAAmE,CAC/E,OAAOC,EAAS,KAAKL,QAAQI,iBAAkB,IAAM,GAAGd,CAAAA,2CAAqD,CAC/G,CAKA,IAAcgB,sBAAiC,CAC7C,OAAK,KAAKR,wBAAuB,KAAKA,sBAAwBS,OAAOC,KAAK,KAAKJ,gBAAgB,GACxF,KAAKN,qBACd,CAEA,MAAyBW,cAAcC,EAAmC,CACxE,GAAI,CAACA,EAAU,MAAO,CAAA,EACtB,IAAMC,EAAmBD,EAASE,IAAKC,GAAAA,CACrC,IAAMC,EAAI,CAAE,GAAGD,CAAQ,EACvB,cAAOC,EAAEC,MACT,OAAOD,EAAEE,MACFF,CACT,CAAA,EACMG,EACJ,KAAKX,qBAAqBY,SAASC,CAAAA,EACjC,MAAMC,EAA2BT,CAAAA,EACjC,MAAMU,EAAqBV,EAAkB,KAAKL,oBAAoB,EAM1E,OALwB,MAAMgB,QAAQC,IACpCN,EAAaL,IAAKY,GACTC,EAAqBD,EAAa,KAAKtB,oBAAqB,KAAKH,kBAAmB,KAAKC,OAAO0B,gBAAkB,EAAA,CAC3H,CAAA,CAGJ,CAOUC,uBAAyBC,EAACC,GAC3B,KAAKvB,qBAAqBY,SAASW,GAAGC,MAAAA,EADZ,0BASzBC,sBAAwBH,EAACE,GAC1B,OAAOA,GAAW,SAAW,KAAKxB,qBAAqBY,SAASY,CAAAA,EAAU,GADjD,wBAGpC","names":["assertEx","BoundWitnessSchema","AbstractDiviner","JsonPathAggregateDivinerConfigSchema","PayloadSchema","combinationsByBoundwitness","combinationsBySchema","toPayloadTransformer","jsonPathToTransformersDictionary","__name","schemaTransforms","Object","fromEntries","entries","map","schema","jsonPathTransformerExpressions","transformers","toPayloadTransformer","exists","PayloadBuilder","reducePayloads","__name","payloads","payloadTransformers","destinationSchema","excludeSources","payloadFields","filter","exists","flatMap","payload","transformers","schema","map","transform","baseObject","sources","PayloadBuilder","dataHashes","fields","Object","assign","build","reducePayloadsArray","payloadsArray","Promise","all","moduleName","JsonPathAggregateDiviner","AbstractDiviner","configSchemas","JsonPathAggregateDivinerConfigSchema","defaultConfigSchema","_transforms","_payloadTransformers","_transformableSchemas","destinationSchema","config","PayloadSchema","payloadTransformers","jsonPathToTransformersDictionary","schemaTransforms","assertEx","transformableSchemas","Object","keys","divineHandler","payloads","strippedPayloads","map","payload","p","$hash","$meta","combinations","includes","BoundWitnessSchema","combinationsByBoundwitness","combinationsBySchema","Promise","all","combination","reducePayloads","excludeSources","isTransformablePayload","__name","x","schema","isTransformableSchema"]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
1
|
import { SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
|
|
2
|
-
/**
|
|
3
|
-
* Materializes the JSON-path expressions into memoized functions by converting a
|
|
4
|
-
* dictionary of schema to JSON Path transform expressions to a dictionary
|
|
5
|
-
* of schema to payload transformers
|
|
6
|
-
* @param schemaTransforms The schema transforms to convert
|
|
7
|
-
* @returns A dictionary of schema to payload transformers
|
|
8
|
-
*/
|
|
9
2
|
export declare const jsonPathToTransformersDictionary: (schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary) => SchemaToPayloadTransformersDictionary;
|
|
10
3
|
//# sourceMappingURL=jsonPathToTransformersDictionary.d.ts.map
|