@xyo-network/payload-utils 2.84.11

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 (38) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +13 -0
  3. package/dist/browser/combinationsBySchema.d.cts +9 -0
  4. package/dist/browser/combinationsBySchema.d.cts.map +1 -0
  5. package/dist/browser/combinationsBySchema.d.mts +9 -0
  6. package/dist/browser/combinationsBySchema.d.mts.map +1 -0
  7. package/dist/browser/combinationsBySchema.d.ts +9 -0
  8. package/dist/browser/combinationsBySchema.d.ts.map +1 -0
  9. package/dist/browser/index.cjs +62 -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 +39 -0
  18. package/dist/browser/index.js.map +1 -0
  19. package/dist/node/combinationsBySchema.d.cts +9 -0
  20. package/dist/node/combinationsBySchema.d.cts.map +1 -0
  21. package/dist/node/combinationsBySchema.d.mts +9 -0
  22. package/dist/node/combinationsBySchema.d.mts.map +1 -0
  23. package/dist/node/combinationsBySchema.d.ts +9 -0
  24. package/dist/node/combinationsBySchema.d.ts.map +1 -0
  25. package/dist/node/index.cjs +66 -0
  26. package/dist/node/index.cjs.map +1 -0
  27. package/dist/node/index.d.cts +2 -0
  28. package/dist/node/index.d.cts.map +1 -0
  29. package/dist/node/index.d.mts +2 -0
  30. package/dist/node/index.d.mts.map +1 -0
  31. package/dist/node/index.d.ts +2 -0
  32. package/dist/node/index.d.ts.map +1 -0
  33. package/dist/node/index.js +39 -0
  34. package/dist/node/index.js.map +1 -0
  35. package/package.json +62 -0
  36. package/src/combinationsBySchema.ts +67 -0
  37. package/src/index.ts +1 -0
  38. 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,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,62 @@
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
+ combinationsBySchema: () => combinationsBySchema
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/combinationsBySchema.ts
28
+ var import_hash = require("@xyo-network/hash");
29
+ var generateKeyForTuple = async (payloads) => {
30
+ await Promise.resolve();
31
+ return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
32
+ };
33
+ var combinationsBySchema = async (payloads, schemas) => {
34
+ const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
35
+ for (const payload of payloads) {
36
+ if (schemas.includes(payload.schema)) {
37
+ groupedPayloads[payload.schema].push(payload);
38
+ }
39
+ }
40
+ const seen = /* @__PURE__ */ new Set();
41
+ let combinations = [[]];
42
+ for (const schema of schemas) {
43
+ const newCombinations = [];
44
+ for (const combination of combinations) {
45
+ for (const payload of groupedPayloads[schema]) {
46
+ const newPerm = [...combination, payload];
47
+ if (newPerm.length === schemas.length) {
48
+ const serialized = await generateKeyForTuple(newPerm);
49
+ if (!seen.has(serialized)) {
50
+ seen.add(serialized);
51
+ newCombinations.push(newPerm);
52
+ }
53
+ } else {
54
+ newCombinations.push(newPerm);
55
+ }
56
+ }
57
+ }
58
+ combinations = newCombinations;
59
+ }
60
+ return combinations;
61
+ };
62
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/combinationsBySchema.ts"],"sourcesContent":["export * from './combinationsBySchema'\n","import { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Generates a unique key for a tuple of payloads\n * @param payloads An array of payloads\n * @returns A string that is a unique key for the payloads\n */\nconst generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {\n // return (await Promise.all(array.map((p) => PayloadHasher.hashAsync(p)))).join('|')\n await Promise.resolve() // Here to reserve the right to make this async\n return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join('|')\n}\n\n/**\n * Returns the unique combinations of payloads for the given schemas\n * @param payloads An array of payloads\n * @param schemas An array of schemas\n * @returns An array of unique combinations of payloads\n */\nexport const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {\n // Group payloads by schema\n const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map((schema) => [schema, []]))\n for (const payload of payloads) {\n if (schemas.includes(payload.schema)) {\n groupedPayloads[payload.schema].push(payload)\n }\n }\n\n // Set to track seen (serialized) combinations for uniqueness check\n const seen: Set<string> = new Set()\n // Start with an array containing an empty combination\n let combinations = [[]] as Payload[][]\n\n // Iterate over each schema\n for (const schema of schemas) {\n const newCombinations: Payload[][] = []\n // Iterate over existing combinations\n for (const combination of combinations) {\n // Iterate over payloads for the current schema\n for (const payload of groupedPayloads[schema]) {\n // Create a new combination by adding the current payload\n const newPerm = [...combination, payload]\n // Proceed with serialization only if the combination is complete\n if (newPerm.length === schemas.length) {\n // Serialize the new combination asynchronously\n const serialized = await generateKeyForTuple(newPerm)\n // Check if the serialized combination is unique\n if (!seen.has(serialized)) {\n // Add it to the set of seen combinations\n seen.add(serialized)\n // Add the new combination to the list of new combinations\n newCombinations.push(newPerm)\n }\n } else {\n // Add incomplete combinations to the list for further processing\n newCombinations.push(newPerm)\n }\n }\n }\n // Update the list of combinations for the next schema iteration\n combinations = newCombinations\n }\n\n // Return the unique combinations\n return combinations\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA8B;AAQ9B,IAAM,sBAAsB,OAAO,aAAyC;AAE1E,QAAM,QAAQ,QAAQ;AACtB,SAAO,SAAS,IAAI,CAAC,MAAM,0BAAc,oBAAoB,CAAC,CAAC,EAAE,KAAK,GAAG;AAC3E;AAQO,IAAM,uBAAuB,OAAO,UAAqB,YAA4C;AAE1G,QAAM,kBAA6C,OAAO,YAAY,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3G,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,SAAS,QAAQ,MAAM,GAAG;AACpC,sBAAgB,QAAQ,MAAM,EAAE,KAAK,OAAO;AAAA,IAC9C;AAAA,EACF;AAGA,QAAM,OAAoB,oBAAI,IAAI;AAElC,MAAI,eAAe,CAAC,CAAC,CAAC;AAGtB,aAAW,UAAU,SAAS;AAC5B,UAAM,kBAA+B,CAAC;AAEtC,eAAW,eAAe,cAAc;AAEtC,iBAAW,WAAW,gBAAgB,MAAM,GAAG;AAE7C,cAAM,UAAU,CAAC,GAAG,aAAa,OAAO;AAExC,YAAI,QAAQ,WAAW,QAAQ,QAAQ;AAErC,gBAAM,aAAa,MAAM,oBAAoB,OAAO;AAEpD,cAAI,CAAC,KAAK,IAAI,UAAU,GAAG;AAEzB,iBAAK,IAAI,UAAU;AAEnB,4BAAgB,KAAK,OAAO;AAAA,UAC9B;AAAA,QACF,OAAO;AAEL,0BAAgB,KAAK,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,39 @@
1
+ // src/combinationsBySchema.ts
2
+ import { PayloadHasher } from "@xyo-network/hash";
3
+ var generateKeyForTuple = async (payloads) => {
4
+ await Promise.resolve();
5
+ return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
6
+ };
7
+ var combinationsBySchema = async (payloads, schemas) => {
8
+ const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
9
+ for (const payload of payloads) {
10
+ if (schemas.includes(payload.schema)) {
11
+ groupedPayloads[payload.schema].push(payload);
12
+ }
13
+ }
14
+ const seen = /* @__PURE__ */ new Set();
15
+ let combinations = [[]];
16
+ for (const schema of schemas) {
17
+ const newCombinations = [];
18
+ for (const combination of combinations) {
19
+ for (const payload of groupedPayloads[schema]) {
20
+ const newPerm = [...combination, payload];
21
+ if (newPerm.length === schemas.length) {
22
+ const serialized = await generateKeyForTuple(newPerm);
23
+ if (!seen.has(serialized)) {
24
+ seen.add(serialized);
25
+ newCombinations.push(newPerm);
26
+ }
27
+ } else {
28
+ newCombinations.push(newPerm);
29
+ }
30
+ }
31
+ }
32
+ combinations = newCombinations;
33
+ }
34
+ return combinations;
35
+ };
36
+ export {
37
+ combinationsBySchema
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/combinationsBySchema.ts"],"sourcesContent":["import { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Generates a unique key for a tuple of payloads\n * @param payloads An array of payloads\n * @returns A string that is a unique key for the payloads\n */\nconst generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {\n // return (await Promise.all(array.map((p) => PayloadHasher.hashAsync(p)))).join('|')\n await Promise.resolve() // Here to reserve the right to make this async\n return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join('|')\n}\n\n/**\n * Returns the unique combinations of payloads for the given schemas\n * @param payloads An array of payloads\n * @param schemas An array of schemas\n * @returns An array of unique combinations of payloads\n */\nexport const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {\n // Group payloads by schema\n const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map((schema) => [schema, []]))\n for (const payload of payloads) {\n if (schemas.includes(payload.schema)) {\n groupedPayloads[payload.schema].push(payload)\n }\n }\n\n // Set to track seen (serialized) combinations for uniqueness check\n const seen: Set<string> = new Set()\n // Start with an array containing an empty combination\n let combinations = [[]] as Payload[][]\n\n // Iterate over each schema\n for (const schema of schemas) {\n const newCombinations: Payload[][] = []\n // Iterate over existing combinations\n for (const combination of combinations) {\n // Iterate over payloads for the current schema\n for (const payload of groupedPayloads[schema]) {\n // Create a new combination by adding the current payload\n const newPerm = [...combination, payload]\n // Proceed with serialization only if the combination is complete\n if (newPerm.length === schemas.length) {\n // Serialize the new combination asynchronously\n const serialized = await generateKeyForTuple(newPerm)\n // Check if the serialized combination is unique\n if (!seen.has(serialized)) {\n // Add it to the set of seen combinations\n seen.add(serialized)\n // Add the new combination to the list of new combinations\n newCombinations.push(newPerm)\n }\n } else {\n // Add incomplete combinations to the list for further processing\n newCombinations.push(newPerm)\n }\n }\n }\n // Update the list of combinations for the next schema iteration\n combinations = newCombinations\n }\n\n // Return the unique combinations\n return combinations\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAQ9B,IAAM,sBAAsB,OAAO,aAAyC;AAE1E,QAAM,QAAQ,QAAQ;AACtB,SAAO,SAAS,IAAI,CAAC,MAAM,cAAc,oBAAoB,CAAC,CAAC,EAAE,KAAK,GAAG;AAC3E;AAQO,IAAM,uBAAuB,OAAO,UAAqB,YAA4C;AAE1G,QAAM,kBAA6C,OAAO,YAAY,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3G,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,SAAS,QAAQ,MAAM,GAAG;AACpC,sBAAgB,QAAQ,MAAM,EAAE,KAAK,OAAO;AAAA,IAC9C;AAAA,EACF;AAGA,QAAM,OAAoB,oBAAI,IAAI;AAElC,MAAI,eAAe,CAAC,CAAC,CAAC;AAGtB,aAAW,UAAU,SAAS;AAC5B,UAAM,kBAA+B,CAAC;AAEtC,eAAW,eAAe,cAAc;AAEtC,iBAAW,WAAW,gBAAgB,MAAM,GAAG;AAE7C,cAAM,UAAU,CAAC,GAAG,aAAa,OAAO;AAExC,YAAI,QAAQ,WAAW,QAAQ,QAAQ;AAErC,gBAAM,aAAa,MAAM,oBAAoB,OAAO;AAEpD,cAAI,CAAC,KAAK,IAAI,UAAU,GAAG;AAEzB,iBAAK,IAAI,UAAU;AAEnB,4BAAgB,KAAK,OAAO;AAAA,UAC9B;AAAA,QACF,OAAO;AAEL,0BAAgB,KAAK,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;","names":[]}
@@ -0,0 +1,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Payload } from '@xyo-network/payload-model';
2
+ /**
3
+ * Returns the unique combinations of payloads for the given schemas
4
+ * @param payloads An array of payloads
5
+ * @param schemas An array of schemas
6
+ * @returns An array of unique combinations of payloads
7
+ */
8
+ export declare const combinationsBySchema: (payloads: Payload[], schemas: string[]) => Promise<Payload[][]>;
9
+ //# sourceMappingURL=combinationsBySchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsBySchema.d.ts","sourceRoot":"","sources":["../../src/combinationsBySchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAapD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAoB,OAAO,EAAE,WAAW,MAAM,EAAE,KAAG,QAAQ,OAAO,EAAE,EAAE,CA8CtG,CAAA"}
@@ -0,0 +1,66 @@
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
+ combinationsBySchema: () => combinationsBySchema
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/combinationsBySchema.ts
28
+ var import_hash = require("@xyo-network/hash");
29
+ var generateKeyForTuple = async (payloads) => {
30
+ await Promise.resolve();
31
+ return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
32
+ };
33
+ var combinationsBySchema = async (payloads, schemas) => {
34
+ const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
35
+ for (const payload of payloads) {
36
+ if (schemas.includes(payload.schema)) {
37
+ groupedPayloads[payload.schema].push(payload);
38
+ }
39
+ }
40
+ const seen = /* @__PURE__ */ new Set();
41
+ let combinations = [[]];
42
+ for (const schema of schemas) {
43
+ const newCombinations = [];
44
+ for (const combination of combinations) {
45
+ for (const payload of groupedPayloads[schema]) {
46
+ const newPerm = [...combination, payload];
47
+ if (newPerm.length === schemas.length) {
48
+ const serialized = await generateKeyForTuple(newPerm);
49
+ if (!seen.has(serialized)) {
50
+ seen.add(serialized);
51
+ newCombinations.push(newPerm);
52
+ }
53
+ } else {
54
+ newCombinations.push(newPerm);
55
+ }
56
+ }
57
+ }
58
+ combinations = newCombinations;
59
+ }
60
+ return combinations;
61
+ };
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ combinationsBySchema
65
+ });
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/combinationsBySchema.ts"],"sourcesContent":["export * from './combinationsBySchema'\n","import { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Generates a unique key for a tuple of payloads\n * @param payloads An array of payloads\n * @returns A string that is a unique key for the payloads\n */\nconst generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {\n // return (await Promise.all(array.map((p) => PayloadHasher.hashAsync(p)))).join('|')\n await Promise.resolve() // Here to reserve the right to make this async\n return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join('|')\n}\n\n/**\n * Returns the unique combinations of payloads for the given schemas\n * @param payloads An array of payloads\n * @param schemas An array of schemas\n * @returns An array of unique combinations of payloads\n */\nexport const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {\n // Group payloads by schema\n const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map((schema) => [schema, []]))\n for (const payload of payloads) {\n if (schemas.includes(payload.schema)) {\n groupedPayloads[payload.schema].push(payload)\n }\n }\n\n // Set to track seen (serialized) combinations for uniqueness check\n const seen: Set<string> = new Set()\n // Start with an array containing an empty combination\n let combinations = [[]] as Payload[][]\n\n // Iterate over each schema\n for (const schema of schemas) {\n const newCombinations: Payload[][] = []\n // Iterate over existing combinations\n for (const combination of combinations) {\n // Iterate over payloads for the current schema\n for (const payload of groupedPayloads[schema]) {\n // Create a new combination by adding the current payload\n const newPerm = [...combination, payload]\n // Proceed with serialization only if the combination is complete\n if (newPerm.length === schemas.length) {\n // Serialize the new combination asynchronously\n const serialized = await generateKeyForTuple(newPerm)\n // Check if the serialized combination is unique\n if (!seen.has(serialized)) {\n // Add it to the set of seen combinations\n seen.add(serialized)\n // Add the new combination to the list of new combinations\n newCombinations.push(newPerm)\n }\n } else {\n // Add incomplete combinations to the list for further processing\n newCombinations.push(newPerm)\n }\n }\n }\n // Update the list of combinations for the next schema iteration\n combinations = newCombinations\n }\n\n // Return the unique combinations\n return combinations\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA8B;AAQ9B,IAAM,sBAAsB,OAAO,aAAyC;AAE1E,QAAM,QAAQ,QAAQ;AACtB,SAAO,SAAS,IAAI,CAAC,MAAM,0BAAc,oBAAoB,CAAC,CAAC,EAAE,KAAK,GAAG;AAC3E;AAQO,IAAM,uBAAuB,OAAO,UAAqB,YAA4C;AAE1G,QAAM,kBAA6C,OAAO,YAAY,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3G,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,SAAS,QAAQ,MAAM,GAAG;AACpC,sBAAgB,QAAQ,MAAM,EAAE,KAAK,OAAO;AAAA,IAC9C;AAAA,EACF;AAGA,QAAM,OAAoB,oBAAI,IAAI;AAElC,MAAI,eAAe,CAAC,CAAC,CAAC;AAGtB,aAAW,UAAU,SAAS;AAC5B,UAAM,kBAA+B,CAAC;AAEtC,eAAW,eAAe,cAAc;AAEtC,iBAAW,WAAW,gBAAgB,MAAM,GAAG;AAE7C,cAAM,UAAU,CAAC,GAAG,aAAa,OAAO;AAExC,YAAI,QAAQ,WAAW,QAAQ,QAAQ;AAErC,gBAAM,aAAa,MAAM,oBAAoB,OAAO;AAEpD,cAAI,CAAC,KAAK,IAAI,UAAU,GAAG;AAEzB,iBAAK,IAAI,UAAU;AAEnB,4BAAgB,KAAK,OAAO;AAAA,UAC9B;AAAA,QACF,OAAO;AAEL,0BAAgB,KAAK,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './combinationsBySchema';
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,wBAAwB,CAAA"}
@@ -0,0 +1,39 @@
1
+ // src/combinationsBySchema.ts
2
+ import { PayloadHasher } from "@xyo-network/hash";
3
+ var generateKeyForTuple = async (payloads) => {
4
+ await Promise.resolve();
5
+ return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
6
+ };
7
+ var combinationsBySchema = async (payloads, schemas) => {
8
+ const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
9
+ for (const payload of payloads) {
10
+ if (schemas.includes(payload.schema)) {
11
+ groupedPayloads[payload.schema].push(payload);
12
+ }
13
+ }
14
+ const seen = /* @__PURE__ */ new Set();
15
+ let combinations = [[]];
16
+ for (const schema of schemas) {
17
+ const newCombinations = [];
18
+ for (const combination of combinations) {
19
+ for (const payload of groupedPayloads[schema]) {
20
+ const newPerm = [...combination, payload];
21
+ if (newPerm.length === schemas.length) {
22
+ const serialized = await generateKeyForTuple(newPerm);
23
+ if (!seen.has(serialized)) {
24
+ seen.add(serialized);
25
+ newCombinations.push(newPerm);
26
+ }
27
+ } else {
28
+ newCombinations.push(newPerm);
29
+ }
30
+ }
31
+ }
32
+ combinations = newCombinations;
33
+ }
34
+ return combinations;
35
+ };
36
+ export {
37
+ combinationsBySchema
38
+ };
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/combinationsBySchema.ts"],"sourcesContent":["import { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Generates a unique key for a tuple of payloads\n * @param payloads An array of payloads\n * @returns A string that is a unique key for the payloads\n */\nconst generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {\n // return (await Promise.all(array.map((p) => PayloadHasher.hashAsync(p)))).join('|')\n await Promise.resolve() // Here to reserve the right to make this async\n return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join('|')\n}\n\n/**\n * Returns the unique combinations of payloads for the given schemas\n * @param payloads An array of payloads\n * @param schemas An array of schemas\n * @returns An array of unique combinations of payloads\n */\nexport const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {\n // Group payloads by schema\n const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map((schema) => [schema, []]))\n for (const payload of payloads) {\n if (schemas.includes(payload.schema)) {\n groupedPayloads[payload.schema].push(payload)\n }\n }\n\n // Set to track seen (serialized) combinations for uniqueness check\n const seen: Set<string> = new Set()\n // Start with an array containing an empty combination\n let combinations = [[]] as Payload[][]\n\n // Iterate over each schema\n for (const schema of schemas) {\n const newCombinations: Payload[][] = []\n // Iterate over existing combinations\n for (const combination of combinations) {\n // Iterate over payloads for the current schema\n for (const payload of groupedPayloads[schema]) {\n // Create a new combination by adding the current payload\n const newPerm = [...combination, payload]\n // Proceed with serialization only if the combination is complete\n if (newPerm.length === schemas.length) {\n // Serialize the new combination asynchronously\n const serialized = await generateKeyForTuple(newPerm)\n // Check if the serialized combination is unique\n if (!seen.has(serialized)) {\n // Add it to the set of seen combinations\n seen.add(serialized)\n // Add the new combination to the list of new combinations\n newCombinations.push(newPerm)\n }\n } else {\n // Add incomplete combinations to the list for further processing\n newCombinations.push(newPerm)\n }\n }\n }\n // Update the list of combinations for the next schema iteration\n combinations = newCombinations\n }\n\n // Return the unique combinations\n return combinations\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAQ9B,IAAM,sBAAsB,OAAO,aAAyC;AAE1E,QAAM,QAAQ,QAAQ;AACtB,SAAO,SAAS,IAAI,CAAC,MAAM,cAAc,oBAAoB,CAAC,CAAC,EAAE,KAAK,GAAG;AAC3E;AAQO,IAAM,uBAAuB,OAAO,UAAqB,YAA4C;AAE1G,QAAM,kBAA6C,OAAO,YAAY,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC3G,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,SAAS,QAAQ,MAAM,GAAG;AACpC,sBAAgB,QAAQ,MAAM,EAAE,KAAK,OAAO;AAAA,IAC9C;AAAA,EACF;AAGA,QAAM,OAAoB,oBAAI,IAAI;AAElC,MAAI,eAAe,CAAC,CAAC,CAAC;AAGtB,aAAW,UAAU,SAAS;AAC5B,UAAM,kBAA+B,CAAC;AAEtC,eAAW,eAAe,cAAc;AAEtC,iBAAW,WAAW,gBAAgB,MAAM,GAAG;AAE7C,cAAM,UAAU,CAAC,GAAG,aAAa,OAAO;AAExC,YAAI,QAAQ,WAAW,QAAQ,QAAQ;AAErC,gBAAM,aAAa,MAAM,oBAAoB,OAAO;AAEpD,cAAI,CAAC,KAAK,IAAI,UAAU,GAAG;AAEzB,iBAAK,IAAI,UAAU;AAEnB,4BAAgB,KAAK,OAAO;AAAA,UAC9B;AAAA,QACF,OAAO;AAEL,0BAAgB,KAAK,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;","names":[]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@xyo-network/payload-utils",
3
+ "author": {
4
+ "email": "support@xyo.network",
5
+ "name": "XYO Development Team",
6
+ "url": "https://xyo.network"
7
+ },
8
+ "bugs": {
9
+ "email": "support@xyo.network",
10
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
+ },
12
+ "dependencies": {
13
+ "@xyo-network/hash": "~2.84.13",
14
+ "@xyo-network/payload-model": "~2.84.13"
15
+ },
16
+ "devDependencies": {
17
+ "@xylabs/ts-scripts-yarn3": "^3.2.25",
18
+ "@xylabs/tsconfig": "^3.2.25",
19
+ "typescript": "^5.3.3"
20
+ },
21
+ "description": "Primary SDK for using XYO Protocol 2.0",
22
+ "exports": {
23
+ ".": {
24
+ "browser": {
25
+ "require": {
26
+ "types": "./dist/browser/index.d.cts",
27
+ "default": "./dist/browser/index.cjs"
28
+ },
29
+ "import": {
30
+ "types": "./dist/browser/index.d.mts",
31
+ "default": "./dist/browser/index.js"
32
+ }
33
+ },
34
+ "node": {
35
+ "require": {
36
+ "types": "./dist/node/index.d.cts",
37
+ "default": "./dist/node/index.cjs"
38
+ },
39
+ "import": {
40
+ "types": "./dist/node/index.d.mts",
41
+ "default": "./dist/node/index.js"
42
+ }
43
+ }
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "main": "dist/node/index.cjs",
48
+ "module": "dist/node/index.js",
49
+ "homepage": "https://xyo.network",
50
+ "license": "LGPL-3.0-only",
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
57
+ },
58
+ "sideEffects": false,
59
+ "types": "dist/node/index.d.ts",
60
+ "version": "2.84.11",
61
+ "type": "module"
62
+ }
@@ -0,0 +1,67 @@
1
+ import { PayloadHasher } from '@xyo-network/hash'
2
+ import { Payload } from '@xyo-network/payload-model'
3
+
4
+ /**
5
+ * Generates a unique key for a tuple of payloads
6
+ * @param payloads An array of payloads
7
+ * @returns A string that is a unique key for the payloads
8
+ */
9
+ const generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {
10
+ // return (await Promise.all(array.map((p) => PayloadHasher.hashAsync(p)))).join('|')
11
+ await Promise.resolve() // Here to reserve the right to make this async
12
+ return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join('|')
13
+ }
14
+
15
+ /**
16
+ * Returns the unique combinations of payloads for the given schemas
17
+ * @param payloads An array of payloads
18
+ * @param schemas An array of schemas
19
+ * @returns An array of unique combinations of payloads
20
+ */
21
+ export const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {
22
+ // Group payloads by schema
23
+ const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map((schema) => [schema, []]))
24
+ for (const payload of payloads) {
25
+ if (schemas.includes(payload.schema)) {
26
+ groupedPayloads[payload.schema].push(payload)
27
+ }
28
+ }
29
+
30
+ // Set to track seen (serialized) combinations for uniqueness check
31
+ const seen: Set<string> = new Set()
32
+ // Start with an array containing an empty combination
33
+ let combinations = [[]] as Payload[][]
34
+
35
+ // Iterate over each schema
36
+ for (const schema of schemas) {
37
+ const newCombinations: Payload[][] = []
38
+ // Iterate over existing combinations
39
+ for (const combination of combinations) {
40
+ // Iterate over payloads for the current schema
41
+ for (const payload of groupedPayloads[schema]) {
42
+ // Create a new combination by adding the current payload
43
+ const newPerm = [...combination, payload]
44
+ // Proceed with serialization only if the combination is complete
45
+ if (newPerm.length === schemas.length) {
46
+ // Serialize the new combination asynchronously
47
+ const serialized = await generateKeyForTuple(newPerm)
48
+ // Check if the serialized combination is unique
49
+ if (!seen.has(serialized)) {
50
+ // Add it to the set of seen combinations
51
+ seen.add(serialized)
52
+ // Add the new combination to the list of new combinations
53
+ newCombinations.push(newPerm)
54
+ }
55
+ } else {
56
+ // Add incomplete combinations to the list for further processing
57
+ newCombinations.push(newPerm)
58
+ }
59
+ }
60
+ }
61
+ // Update the list of combinations for the next schema iteration
62
+ combinations = newCombinations
63
+ }
64
+
65
+ // Return the unique combinations
66
+ return combinations
67
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './combinationsBySchema'
package/typedoc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://typedoc.org/schema.json",
3
+ "entryPoints": ["./src/index.ts"],
4
+ "tsconfig": "./tsconfig.typedoc.json"
5
+ }