@xyo-network/diviner-jsonpath-aggregate-memory 2.83.0

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.
Files changed (77) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/Diviner.d.cts +40 -0
  4. package/dist/browser/Diviner.d.cts.map +1 -0
  5. package/dist/browser/Diviner.d.mts +40 -0
  6. package/dist/browser/Diviner.d.mts.map +1 -0
  7. package/dist/browser/Diviner.d.ts +40 -0
  8. package/dist/browser/Diviner.d.ts.map +1 -0
  9. package/dist/browser/index.cjs +114 -0
  10. package/dist/browser/index.cjs.map +1 -0
  11. package/dist/browser/index.d.cts +2 -0
  12. package/dist/browser/index.d.cts.map +1 -0
  13. package/dist/browser/index.d.mts +2 -0
  14. package/dist/browser/index.d.mts.map +1 -0
  15. package/dist/browser/index.d.ts +2 -0
  16. package/dist/browser/index.d.ts.map +1 -0
  17. package/dist/browser/index.js +93 -0
  18. package/dist/browser/index.js.map +1 -0
  19. package/dist/browser/jsonpath/index.d.cts +3 -0
  20. package/dist/browser/jsonpath/index.d.cts.map +1 -0
  21. package/dist/browser/jsonpath/index.d.mts +3 -0
  22. package/dist/browser/jsonpath/index.d.mts.map +1 -0
  23. package/dist/browser/jsonpath/index.d.ts +3 -0
  24. package/dist/browser/jsonpath/index.d.ts.map +1 -0
  25. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts +10 -0
  26. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -0
  27. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts +10 -0
  28. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -0
  29. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts +10 -0
  30. package/dist/browser/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -0
  31. package/dist/browser/jsonpath/reducePayloads.d.cts +27 -0
  32. package/dist/browser/jsonpath/reducePayloads.d.cts.map +1 -0
  33. package/dist/browser/jsonpath/reducePayloads.d.mts +27 -0
  34. package/dist/browser/jsonpath/reducePayloads.d.mts.map +1 -0
  35. package/dist/browser/jsonpath/reducePayloads.d.ts +27 -0
  36. package/dist/browser/jsonpath/reducePayloads.d.ts.map +1 -0
  37. package/dist/node/Diviner.d.cts +40 -0
  38. package/dist/node/Diviner.d.cts.map +1 -0
  39. package/dist/node/Diviner.d.mts +40 -0
  40. package/dist/node/Diviner.d.mts.map +1 -0
  41. package/dist/node/Diviner.d.ts +40 -0
  42. package/dist/node/Diviner.d.ts.map +1 -0
  43. package/dist/node/index.d.cts +2 -0
  44. package/dist/node/index.d.cts.map +1 -0
  45. package/dist/node/index.d.mts +2 -0
  46. package/dist/node/index.d.mts.map +1 -0
  47. package/dist/node/index.d.ts +2 -0
  48. package/dist/node/index.d.ts.map +1 -0
  49. package/dist/node/index.js +119 -0
  50. package/dist/node/index.js.map +1 -0
  51. package/dist/node/index.mjs +94 -0
  52. package/dist/node/index.mjs.map +1 -0
  53. package/dist/node/jsonpath/index.d.cts +3 -0
  54. package/dist/node/jsonpath/index.d.cts.map +1 -0
  55. package/dist/node/jsonpath/index.d.mts +3 -0
  56. package/dist/node/jsonpath/index.d.mts.map +1 -0
  57. package/dist/node/jsonpath/index.d.ts +3 -0
  58. package/dist/node/jsonpath/index.d.ts.map +1 -0
  59. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts +10 -0
  60. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.cts.map +1 -0
  61. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts +10 -0
  62. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.mts.map +1 -0
  63. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts +10 -0
  64. package/dist/node/jsonpath/jsonPathToTransformersDictionary.d.ts.map +1 -0
  65. package/dist/node/jsonpath/reducePayloads.d.cts +27 -0
  66. package/dist/node/jsonpath/reducePayloads.d.cts.map +1 -0
  67. package/dist/node/jsonpath/reducePayloads.d.mts +27 -0
  68. package/dist/node/jsonpath/reducePayloads.d.mts.map +1 -0
  69. package/dist/node/jsonpath/reducePayloads.d.ts +27 -0
  70. package/dist/node/jsonpath/reducePayloads.d.ts.map +1 -0
  71. package/package.json +72 -0
  72. package/src/Diviner.ts +83 -0
  73. package/src/index.ts +1 -0
  74. package/src/jsonpath/index.ts +2 -0
  75. package/src/jsonpath/jsonPathToTransformersDictionary.ts +20 -0
  76. package/src/jsonpath/reducePayloads.ts +50 -0
  77. package/typedoc.json +5 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ [![logo][]](https://xyo.network)
2
+
3
+ Part of [sdk-xyo-client-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js)
4
+
5
+ ## License
6
+
7
+ > See the [LICENSE](LICENSE) file for license details
8
+
9
+ ## Credits
10
+
11
+ [Made with 🔥 and ❄️ by XYO](https://xyo.network)
12
+
13
+ [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -0,0 +1,40 @@
1
+ import { AbstractDiviner } from '@xyo-network/abstract-diviner';
2
+ import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
3
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
6
+ static configSchemas: "network.xyo.diviner.jsonpath.config"[];
7
+ protected _transforms: PayloadTransformer[] | undefined;
8
+ private _payloadTransformers;
9
+ private _transformableSchemas;
10
+ /**
11
+ * The schema to use for the destination payloads
12
+ */
13
+ protected get destinationSchema(): string;
14
+ /**
15
+ * Dictionary of schemas to payload transformers
16
+ */
17
+ protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
18
+ /**
19
+ * The dictionary of schemas to JSON Path transform expressions
20
+ */
21
+ protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
22
+ /**
23
+ * List of transformable schemas for this diviner
24
+ */
25
+ protected get transformableSchemas(): string[];
26
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
27
+ /**
28
+ * Identifies if a payload is one that is transformed by this diviner
29
+ * @param x The candidate payload
30
+ * @returns True if the payload is one transformed by this diviner, false otherwise
31
+ */
32
+ protected isTransformablePayload: (x: Payload) => boolean;
33
+ /**
34
+ * Identifies if a schema is one that is transformed by this diviner
35
+ * @param schema The candidate schema
36
+ * @returns True if this schema is one transformed by this diviner, false otherwise
37
+ */
38
+ protected isTransformableSchema: (schema?: string | null) => boolean;
39
+ }
40
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,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,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAMnE,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,0CAAyC;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;IAMzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -0,0 +1,40 @@
1
+ import { AbstractDiviner } from '@xyo-network/abstract-diviner';
2
+ import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
3
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
6
+ static configSchemas: "network.xyo.diviner.jsonpath.config"[];
7
+ protected _transforms: PayloadTransformer[] | undefined;
8
+ private _payloadTransformers;
9
+ private _transformableSchemas;
10
+ /**
11
+ * The schema to use for the destination payloads
12
+ */
13
+ protected get destinationSchema(): string;
14
+ /**
15
+ * Dictionary of schemas to payload transformers
16
+ */
17
+ protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
18
+ /**
19
+ * The dictionary of schemas to JSON Path transform expressions
20
+ */
21
+ protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
22
+ /**
23
+ * List of transformable schemas for this diviner
24
+ */
25
+ protected get transformableSchemas(): string[];
26
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
27
+ /**
28
+ * Identifies if a payload is one that is transformed by this diviner
29
+ * @param x The candidate payload
30
+ * @returns True if the payload is one transformed by this diviner, false otherwise
31
+ */
32
+ protected isTransformablePayload: (x: Payload) => boolean;
33
+ /**
34
+ * Identifies if a schema is one that is transformed by this diviner
35
+ * @param schema The candidate schema
36
+ * @returns True if this schema is one transformed by this diviner, false otherwise
37
+ */
38
+ protected isTransformableSchema: (schema?: string | null) => boolean;
39
+ }
40
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,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,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAMnE,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,0CAAyC;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;IAMzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -0,0 +1,40 @@
1
+ import { AbstractDiviner } from '@xyo-network/abstract-diviner';
2
+ import { JsonPathAggregateDivinerParams, PayloadTransformer, SchemaToJsonPathTransformExpressionsDictionary, SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model';
3
+ import { DivinerModule, DivinerModuleEventData } from '@xyo-network/diviner-model';
4
+ import { Payload } from '@xyo-network/payload-model';
5
+ export declare class JsonPathAggregateDiviner<TParams extends JsonPathAggregateDivinerParams = JsonPathAggregateDivinerParams, TIn extends Payload = Payload, TOut extends Payload = Payload, TEventData extends DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut> = DivinerModuleEventData<DivinerModule<TParams>, TIn, TOut>> extends AbstractDiviner<TParams, TIn, TOut, TEventData> {
6
+ static configSchemas: "network.xyo.diviner.jsonpath.config"[];
7
+ protected _transforms: PayloadTransformer[] | undefined;
8
+ private _payloadTransformers;
9
+ private _transformableSchemas;
10
+ /**
11
+ * The schema to use for the destination payloads
12
+ */
13
+ protected get destinationSchema(): string;
14
+ /**
15
+ * Dictionary of schemas to payload transformers
16
+ */
17
+ protected get payloadTransformers(): SchemaToPayloadTransformersDictionary;
18
+ /**
19
+ * The dictionary of schemas to JSON Path transform expressions
20
+ */
21
+ protected get schemaTransforms(): SchemaToJsonPathTransformExpressionsDictionary;
22
+ /**
23
+ * List of transformable schemas for this diviner
24
+ */
25
+ protected get transformableSchemas(): string[];
26
+ protected divineHandler(payloads?: TIn[]): Promise<TOut[]>;
27
+ /**
28
+ * Identifies if a payload is one that is transformed by this diviner
29
+ * @param x The candidate payload
30
+ * @returns True if the payload is one transformed by this diviner, false otherwise
31
+ */
32
+ protected isTransformablePayload: (x: Payload) => boolean;
33
+ /**
34
+ * Identifies if a schema is one that is transformed by this diviner
35
+ * @param schema The candidate schema
36
+ * @returns True if this schema is one transformed by this diviner, false otherwise
37
+ */
38
+ protected isTransformableSchema: (schema?: string | null) => boolean;
39
+ }
40
+ //# sourceMappingURL=Diviner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Diviner.d.ts","sourceRoot":"","sources":["../../src/Diviner.ts"],"names":[],"mappings":"AACA,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,aAAa,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAClF,OAAO,EAAE,OAAO,EAAiB,MAAM,4BAA4B,CAAA;AAMnE,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,0CAAyC;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;IAMzE;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,MAAO,OAAO,aAE7C;IAED;;;;OAIG;IACH,SAAS,CAAC,qBAAqB,YAAa,MAAM,GAAG,IAAI,aAExD;CACF"}
@@ -0,0 +1,114 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ JsonPathAggregateDiviner: () => JsonPathAggregateDiviner
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/Diviner.ts
28
+ var import_assert = require("@xylabs/assert");
29
+ var import_abstract_diviner = require("@xyo-network/abstract-diviner");
30
+ var import_diviner_jsonpath_aggregate_model = require("@xyo-network/diviner-jsonpath-aggregate-model");
31
+ var import_payload_model = require("@xyo-network/payload-model");
32
+
33
+ // src/jsonpath/jsonPathToTransformersDictionary.ts
34
+ var import_diviner_jsonpath_memory = require("@xyo-network/diviner-jsonpath-memory");
35
+ var jsonPathToTransformersDictionary = (schemaTransforms) => {
36
+ return Object.fromEntries(
37
+ Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
38
+ const transformers = jsonPathTransformerExpressions.map(import_diviner_jsonpath_memory.toPayloadTransformer);
39
+ return [schema, transformers];
40
+ })
41
+ );
42
+ };
43
+
44
+ // src/jsonpath/reducePayloads.ts
45
+ var import_core = require("@xyo-network/core");
46
+ var import_payload_builder = require("@xyo-network/payload-builder");
47
+ var reducePayloads = async (payloads, payloadTransformers, destinationSchema) => {
48
+ const indexFields = payloads.map((payload) => {
49
+ const transformers = payloadTransformers[payload.schema];
50
+ return transformers ? transformers.map((transform) => transform(payload)) : [];
51
+ }).flat();
52
+ const sources = (await import_core.PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash);
53
+ return new import_payload_builder.PayloadBuilder({ schema: destinationSchema }).fields(Object.assign({ sources }, ...indexFields)).build();
54
+ };
55
+
56
+ // src/Diviner.ts
57
+ var moduleName = "JsonPathAggregateDiviner";
58
+ var JsonPathAggregateDiviner = class extends import_abstract_diviner.AbstractDiviner {
59
+ static configSchemas = [import_diviner_jsonpath_aggregate_model.JsonPathAggregateDivinerConfigSchema];
60
+ _transforms;
61
+ _payloadTransformers;
62
+ _transformableSchemas;
63
+ /**
64
+ * The schema to use for the destination payloads
65
+ */
66
+ get destinationSchema() {
67
+ return this.config.destinationSchema ?? import_payload_model.PayloadSchema;
68
+ }
69
+ /**
70
+ * Dictionary of schemas to payload transformers
71
+ */
72
+ get payloadTransformers() {
73
+ if (!this._payloadTransformers)
74
+ this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
75
+ return this._payloadTransformers;
76
+ }
77
+ /**
78
+ * The dictionary of schemas to JSON Path transform expressions
79
+ */
80
+ get schemaTransforms() {
81
+ return (0, import_assert.assertEx)(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
82
+ }
83
+ /**
84
+ * List of transformable schemas for this diviner
85
+ */
86
+ get transformableSchemas() {
87
+ if (!this._transformableSchemas)
88
+ this._transformableSchemas = [...Object.keys(this.schemaTransforms)];
89
+ return this._transformableSchemas;
90
+ }
91
+ async divineHandler(payloads) {
92
+ if (!payloads)
93
+ return [];
94
+ const reducedPayloads = await reducePayloads(payloads, this.payloadTransformers, this.destinationSchema);
95
+ return [reducedPayloads];
96
+ }
97
+ /**
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
+ */
102
+ isTransformablePayload = (x) => {
103
+ return this.transformableSchemas.includes(x?.schema);
104
+ };
105
+ /**
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
+ */
110
+ isTransformableSchema = (schema) => {
111
+ return this.transformableSchemas.some((s) => s === schema);
112
+ };
113
+ };
114
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/jsonpath/jsonPathToTransformersDictionary.ts","../../src/jsonpath/reducePayloads.ts"],"sourcesContent":["export * from './Diviner'\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>(payloads, this.payloadTransformers, this.destinationSchema)\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 this.transformableSchemas.some((s) => s === schema)\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 { PayloadHasher } from '@xyo-network/core'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\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 * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const indexFields = payloads\n .map<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 .flat()\n // Include all the sources for reference\n const sources = (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash)\n // Build and return the index\n return new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign({ sources }, ...indexFields)).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 destinationSchema The schema of the destination payloads\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema)\n }),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;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;;;ACnBA,kBAA8B;AAE9B,6BAA+B;AAUxB,IAAM,iBAAiB,OAC5B,UACA,qBACA,sBACe;AAEf,QAAM,cAAc,SACjB,IAAqB,CAAC,YAAY;AAEjC,UAAM,eAAe,oBAAoB,QAAQ,MAAM;AAEvD,WAAO,eAAe,aAAa,IAAI,CAAC,cAAc,UAAU,OAAO,CAAC,IAAI,CAAC;AAAA,EAC/E,CAAC,EACA,KAAK;AAER,QAAM,WAAW,MAAM,0BAAc,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI;AAErF,SAAO,IAAI,sCAAkB,EAAE,QAAQ,kBAAkB,CAAC,EAAE,OAAO,OAAO,OAAO,EAAE,QAAQ,GAAG,GAAG,WAAW,CAAC,EAAE,MAAM;AACvH;;;AFhBA,IAAM,aAAa;AAEZ,IAAM,2BAAN,cAKG,wCAAgD;AAAA,EACxD,OAAgB,gBAAgB,CAAC,4EAAoC;AAAA,EAE3D;AAAA,EAEF;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,CAAC,GAAG,OAAO,KAAK,KAAK,gBAAgB,CAAC;AACpG,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC;AAAU,aAAO,CAAC;AACvB,UAAM,kBAAkB,MAAM,eAAqB,UAAU,KAAK,qBAAqB,KAAK,iBAAiB;AAC7G,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,KAAK,qBAAqB,KAAK,CAAC,MAAM,MAAM,MAAM;AAAA,EAC3D;AACF;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Diviner';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -0,0 +1,93 @@
1
+ // src/Diviner.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { AbstractDiviner } from "@xyo-network/abstract-diviner";
4
+ import {
5
+ JsonPathAggregateDivinerConfigSchema
6
+ } from "@xyo-network/diviner-jsonpath-aggregate-model";
7
+ import { PayloadSchema } from "@xyo-network/payload-model";
8
+
9
+ // src/jsonpath/jsonPathToTransformersDictionary.ts
10
+ import { toPayloadTransformer } from "@xyo-network/diviner-jsonpath-memory";
11
+ var jsonPathToTransformersDictionary = (schemaTransforms) => {
12
+ return Object.fromEntries(
13
+ Object.entries(schemaTransforms).map(([schema, jsonPathTransformerExpressions]) => {
14
+ const transformers = jsonPathTransformerExpressions.map(toPayloadTransformer);
15
+ return [schema, transformers];
16
+ })
17
+ );
18
+ };
19
+
20
+ // src/jsonpath/reducePayloads.ts
21
+ import { PayloadHasher } from "@xyo-network/core";
22
+ import { PayloadBuilder } from "@xyo-network/payload-builder";
23
+ var reducePayloads = async (payloads, payloadTransformers, destinationSchema) => {
24
+ const indexFields = payloads.map((payload) => {
25
+ const transformers = payloadTransformers[payload.schema];
26
+ return transformers ? transformers.map((transform) => transform(payload)) : [];
27
+ }).flat();
28
+ const sources = (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash);
29
+ return new PayloadBuilder({ schema: destinationSchema }).fields(Object.assign({ sources }, ...indexFields)).build();
30
+ };
31
+
32
+ // src/Diviner.ts
33
+ var moduleName = "JsonPathAggregateDiviner";
34
+ var JsonPathAggregateDiviner = class extends AbstractDiviner {
35
+ static configSchemas = [JsonPathAggregateDivinerConfigSchema];
36
+ _transforms;
37
+ _payloadTransformers;
38
+ _transformableSchemas;
39
+ /**
40
+ * The schema to use for the destination payloads
41
+ */
42
+ get destinationSchema() {
43
+ return this.config.destinationSchema ?? PayloadSchema;
44
+ }
45
+ /**
46
+ * Dictionary of schemas to payload transformers
47
+ */
48
+ get payloadTransformers() {
49
+ if (!this._payloadTransformers)
50
+ this._payloadTransformers = jsonPathToTransformersDictionary(this.schemaTransforms);
51
+ return this._payloadTransformers;
52
+ }
53
+ /**
54
+ * The dictionary of schemas to JSON Path transform expressions
55
+ */
56
+ get schemaTransforms() {
57
+ return assertEx(this.config?.schemaTransforms, () => `${moduleName}: Missing config.schemaTransforms section`);
58
+ }
59
+ /**
60
+ * List of transformable schemas for this diviner
61
+ */
62
+ get transformableSchemas() {
63
+ if (!this._transformableSchemas)
64
+ this._transformableSchemas = [...Object.keys(this.schemaTransforms)];
65
+ return this._transformableSchemas;
66
+ }
67
+ async divineHandler(payloads) {
68
+ if (!payloads)
69
+ return [];
70
+ const reducedPayloads = await reducePayloads(payloads, this.payloadTransformers, this.destinationSchema);
71
+ return [reducedPayloads];
72
+ }
73
+ /**
74
+ * Identifies if a payload is one that is transformed by this diviner
75
+ * @param x The candidate payload
76
+ * @returns True if the payload is one transformed by this diviner, false otherwise
77
+ */
78
+ isTransformablePayload = (x) => {
79
+ return this.transformableSchemas.includes(x?.schema);
80
+ };
81
+ /**
82
+ * Identifies if a schema is one that is transformed by this diviner
83
+ * @param schema The candidate schema
84
+ * @returns True if this schema is one transformed by this diviner, false otherwise
85
+ */
86
+ isTransformableSchema = (schema) => {
87
+ return this.transformableSchemas.some((s) => s === schema);
88
+ };
89
+ };
90
+ export {
91
+ JsonPathAggregateDiviner
92
+ };
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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>(payloads, this.payloadTransformers, this.destinationSchema)\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 this.transformableSchemas.some((s) => s === schema)\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 { PayloadHasher } from '@xyo-network/core'\nimport { SchemaToPayloadTransformersDictionary } from '@xyo-network/diviner-jsonpath-aggregate-model'\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 * @returns The reduced payload\n */\nexport const reducePayloads = async <T extends Payload = Payload>(\n payloads: Payload[],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n): Promise<T> => {\n // Use the payload transformers to convert the fields from the source payloads to the destination fields\n const indexFields = payloads\n .map<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 .flat()\n // Include all the sources for reference\n const sources = (await PayloadHasher.hashPairs([...payloads])).map(([, hash]) => hash)\n // Build and return the index\n return new PayloadBuilder<T>({ schema: destinationSchema }).fields(Object.assign({ sources }, ...indexFields)).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 destinationSchema The schema of the destination payloads\n * @returns The reduced payloads\n */\nexport const reducePayloadsArray = async <T extends Payload = Payload>(\n payloadsArray: Payload[][],\n payloadTransformers: SchemaToPayloadTransformersDictionary,\n destinationSchema: string,\n): Promise<T[]> => {\n return await Promise.all(\n payloadsArray.map(async (payloads) => {\n return await reducePayloads<T>(payloads, payloadTransformers, destinationSchema)\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;;;ACnBA,SAAS,qBAAqB;AAE9B,SAAS,sBAAsB;AAUxB,IAAM,iBAAiB,OAC5B,UACA,qBACA,sBACe;AAEf,QAAM,cAAc,SACjB,IAAqB,CAAC,YAAY;AAEjC,UAAM,eAAe,oBAAoB,QAAQ,MAAM;AAEvD,WAAO,eAAe,aAAa,IAAI,CAAC,cAAc,UAAU,OAAO,CAAC,IAAI,CAAC;AAAA,EAC/E,CAAC,EACA,KAAK;AAER,QAAM,WAAW,MAAM,cAAc,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI;AAErF,SAAO,IAAI,eAAkB,EAAE,QAAQ,kBAAkB,CAAC,EAAE,OAAO,OAAO,OAAO,EAAE,QAAQ,GAAG,GAAG,WAAW,CAAC,EAAE,MAAM;AACvH;;;AFhBA,IAAM,aAAa;AAEZ,IAAM,2BAAN,cAKG,gBAAgD;AAAA,EACxD,OAAgB,gBAAgB,CAAC,oCAAoC;AAAA,EAE3D;AAAA,EAEF;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,WAAO,SAAS,KAAK,QAAQ,kBAAkB,MAAM,GAAG,UAAU,2CAA2C;AAAA,EAC/G;AAAA;AAAA;AAAA;AAAA,EAKA,IAAc,uBAAiC;AAC7C,QAAI,CAAC,KAAK;AAAuB,WAAK,wBAAwB,CAAC,GAAG,OAAO,KAAK,KAAK,gBAAgB,CAAC;AACpG,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,UAAmC;AACxE,QAAI,CAAC;AAAU,aAAO,CAAC;AACvB,UAAM,kBAAkB,MAAM,eAAqB,UAAU,KAAK,qBAAqB,KAAK,iBAAiB;AAC7G,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,KAAK,qBAAqB,KAAK,CAAC,MAAM,MAAM,MAAM;AAAA,EAC3D;AACF;","names":[]}
@@ -0,0 +1,3 @@
1
+ export * from './jsonPathToTransformersDictionary';
2
+ export * from './reducePayloads';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './jsonPathToTransformersDictionary';
2
+ export * from './reducePayloads';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './jsonPathToTransformersDictionary';
2
+ export * from './reducePayloads';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA;AAClD,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,10 @@
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
+ export declare const jsonPathToTransformersDictionary: (schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary) => SchemaToPayloadTransformersDictionary;
10
+ //# sourceMappingURL=jsonPathToTransformersDictionary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonPathToTransformersDictionary.d.ts","sourceRoot":"","sources":["../../../src/jsonpath/jsonPathToTransformersDictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8CAA8C,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAA;AAGrJ;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,qBACzB,8CAA8C,KAC/D,qCAOF,CAAA"}
@@ -0,0 +1,10 @@
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
+ export declare const jsonPathToTransformersDictionary: (schemaTransforms: SchemaToJsonPathTransformExpressionsDictionary) => SchemaToPayloadTransformersDictionary;
10
+ //# sourceMappingURL=jsonPathToTransformersDictionary.d.ts.map