@xyo-network/payload-utils 2.84.16 → 2.85.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.
- package/dist/browser/index.cjs +16 -7
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +18 -7
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +16 -7
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +18 -7
- package/dist/node/index.js.map +1 -1
- package/package.json +3 -3
package/dist/browser/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,24 +27,32 @@ module.exports = __toCommonJS(src_exports);
|
|
|
26
27
|
|
|
27
28
|
// src/combinationsBySchema.ts
|
|
28
29
|
var import_hash = require("@xyo-network/hash");
|
|
29
|
-
var generateKeyForTuple = async (payloads) => {
|
|
30
|
+
var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
|
|
30
31
|
await Promise.resolve();
|
|
31
32
|
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) => [
|
|
33
|
+
}, "generateKeyForTuple");
|
|
34
|
+
var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
35
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
36
|
+
schema,
|
|
37
|
+
[]
|
|
38
|
+
]));
|
|
35
39
|
for (const payload of payloads) {
|
|
36
40
|
if (schemas.includes(payload.schema)) {
|
|
37
41
|
groupedPayloads[payload.schema].push(payload);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
const seen = /* @__PURE__ */ new Set();
|
|
41
|
-
let combinations = [
|
|
45
|
+
let combinations = [
|
|
46
|
+
[]
|
|
47
|
+
];
|
|
42
48
|
for (const schema of schemas) {
|
|
43
49
|
const newCombinations = [];
|
|
44
50
|
for (const combination of combinations) {
|
|
45
51
|
for (const payload of groupedPayloads[schema]) {
|
|
46
|
-
const newPerm = [
|
|
52
|
+
const newPerm = [
|
|
53
|
+
...combination,
|
|
54
|
+
payload
|
|
55
|
+
];
|
|
47
56
|
if (newPerm.length === schemas.length) {
|
|
48
57
|
const serialized = await generateKeyForTuple(newPerm);
|
|
49
58
|
if (!seen.has(serialized)) {
|
|
@@ -58,5 +67,5 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
58
67
|
combinations = newCombinations;
|
|
59
68
|
}
|
|
60
69
|
return combinations;
|
|
61
|
-
};
|
|
70
|
+
}, "combinationsBySchema");
|
|
62
71
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +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":"
|
|
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;;;;;;;ACAA,kBAA8B;AAQ9B,IAAMA,sBAAsB,8BAAOC,aAAAA;AAEjC,QAAMC,QAAQC,QAAO;AACrB,SAAOF,SAASG,IAAI,CAACC,MAAMC,0BAAcC,oBAAoBF,CAAAA,CAAAA,EAAIG,KAAK,GAAA;AACxE,GAJ4B;AAYrB,IAAMC,uBAAuB,8BAAOR,UAAqBS,YAAAA;AAE9D,QAAMC,kBAA6CC,OAAOC,YAAYH,QAAQN,IAAI,CAACU,WAAW;IAACA;IAAQ,CAAA;GAAG,CAAA;AAC1G,aAAWC,WAAWd,UAAU;AAC9B,QAAIS,QAAQM,SAASD,QAAQD,MAAM,GAAG;AACpCH,sBAAgBI,QAAQD,MAAM,EAAEG,KAAKF,OAAAA;IACvC;EACF;AAGA,QAAMG,OAAoB,oBAAIC,IAAAA;AAE9B,MAAIC,eAAe;IAAC,CAAA;;AAGpB,aAAWN,UAAUJ,SAAS;AAC5B,UAAMW,kBAA+B,CAAA;AAErC,eAAWC,eAAeF,cAAc;AAEtC,iBAAWL,WAAWJ,gBAAgBG,MAAAA,GAAS;AAE7C,cAAMS,UAAU;aAAID;UAAaP;;AAEjC,YAAIQ,QAAQC,WAAWd,QAAQc,QAAQ;AAErC,gBAAMC,aAAa,MAAMzB,oBAAoBuB,OAAAA;AAE7C,cAAI,CAACL,KAAKQ,IAAID,UAAAA,GAAa;AAEzBP,iBAAKS,IAAIF,UAAAA;AAETJ,4BAAgBJ,KAAKM,OAAAA;UACvB;QACF,OAAO;AAELF,0BAAgBJ,KAAKM,OAAAA;QACvB;MACF;IACF;AAEAH,mBAAeC;EACjB;AAGA,SAAOD;AACT,GA9CoC;","names":["generateKeyForTuple","payloads","Promise","resolve","map","p","PayloadHasher","stringifyHashFields","join","combinationsBySchema","schemas","groupedPayloads","Object","fromEntries","schema","payload","includes","push","seen","Set","combinations","newCombinations","combination","newPerm","length","serialized","has","add"]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/combinationsBySchema.ts
|
|
2
5
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
3
|
-
var generateKeyForTuple = async (payloads) => {
|
|
6
|
+
var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
|
|
4
7
|
await Promise.resolve();
|
|
5
8
|
return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
|
|
6
|
-
};
|
|
7
|
-
var combinationsBySchema = async (payloads, schemas) => {
|
|
8
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
9
|
+
}, "generateKeyForTuple");
|
|
10
|
+
var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
11
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
12
|
+
schema,
|
|
13
|
+
[]
|
|
14
|
+
]));
|
|
9
15
|
for (const payload of payloads) {
|
|
10
16
|
if (schemas.includes(payload.schema)) {
|
|
11
17
|
groupedPayloads[payload.schema].push(payload);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
const seen = /* @__PURE__ */ new Set();
|
|
15
|
-
let combinations = [
|
|
21
|
+
let combinations = [
|
|
22
|
+
[]
|
|
23
|
+
];
|
|
16
24
|
for (const schema of schemas) {
|
|
17
25
|
const newCombinations = [];
|
|
18
26
|
for (const combination of combinations) {
|
|
19
27
|
for (const payload of groupedPayloads[schema]) {
|
|
20
|
-
const newPerm = [
|
|
28
|
+
const newPerm = [
|
|
29
|
+
...combination,
|
|
30
|
+
payload
|
|
31
|
+
];
|
|
21
32
|
if (newPerm.length === schemas.length) {
|
|
22
33
|
const serialized = await generateKeyForTuple(newPerm);
|
|
23
34
|
if (!seen.has(serialized)) {
|
|
@@ -32,7 +43,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
32
43
|
combinations = newCombinations;
|
|
33
44
|
}
|
|
34
45
|
return combinations;
|
|
35
|
-
};
|
|
46
|
+
}, "combinationsBySchema");
|
|
36
47
|
export {
|
|
37
48
|
combinationsBySchema
|
|
38
49
|
};
|
|
@@ -1 +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":"
|
|
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,SAASA,qBAAqB;AAQ9B,IAAMC,sBAAsB,8BAAOC,aAAAA;AAEjC,QAAMC,QAAQC,QAAO;AACrB,SAAOF,SAASG,IAAI,CAACC,MAAMC,cAAcC,oBAAoBF,CAAAA,CAAAA,EAAIG,KAAK,GAAA;AACxE,GAJ4B;AAYrB,IAAMC,uBAAuB,8BAAOR,UAAqBS,YAAAA;AAE9D,QAAMC,kBAA6CC,OAAOC,YAAYH,QAAQN,IAAI,CAACU,WAAW;IAACA;IAAQ,CAAA;GAAG,CAAA;AAC1G,aAAWC,WAAWd,UAAU;AAC9B,QAAIS,QAAQM,SAASD,QAAQD,MAAM,GAAG;AACpCH,sBAAgBI,QAAQD,MAAM,EAAEG,KAAKF,OAAAA;IACvC;EACF;AAGA,QAAMG,OAAoB,oBAAIC,IAAAA;AAE9B,MAAIC,eAAe;IAAC,CAAA;;AAGpB,aAAWN,UAAUJ,SAAS;AAC5B,UAAMW,kBAA+B,CAAA;AAErC,eAAWC,eAAeF,cAAc;AAEtC,iBAAWL,WAAWJ,gBAAgBG,MAAAA,GAAS;AAE7C,cAAMS,UAAU;aAAID;UAAaP;;AAEjC,YAAIQ,QAAQC,WAAWd,QAAQc,QAAQ;AAErC,gBAAMC,aAAa,MAAMzB,oBAAoBuB,OAAAA;AAE7C,cAAI,CAACL,KAAKQ,IAAID,UAAAA,GAAa;AAEzBP,iBAAKS,IAAIF,UAAAA;AAETJ,4BAAgBJ,KAAKM,OAAAA;UACvB;QACF,OAAO;AAELF,0BAAgBJ,KAAKM,OAAAA;QACvB;MACF;IACF;AAEAH,mBAAeC;EACjB;AAGA,SAAOD;AACT,GA9CoC;","names":["PayloadHasher","generateKeyForTuple","payloads","Promise","resolve","map","p","PayloadHasher","stringifyHashFields","join","combinationsBySchema","schemas","groupedPayloads","Object","fromEntries","schema","payload","includes","push","seen","Set","combinations","newCombinations","combination","newPerm","length","serialized","has","add"]}
|
package/dist/node/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
var __export = (target, all) => {
|
|
7
8
|
for (var name in all)
|
|
8
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -26,24 +27,32 @@ module.exports = __toCommonJS(src_exports);
|
|
|
26
27
|
|
|
27
28
|
// src/combinationsBySchema.ts
|
|
28
29
|
var import_hash = require("@xyo-network/hash");
|
|
29
|
-
var generateKeyForTuple = async (payloads) => {
|
|
30
|
+
var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
|
|
30
31
|
await Promise.resolve();
|
|
31
32
|
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) => [
|
|
33
|
+
}, "generateKeyForTuple");
|
|
34
|
+
var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
35
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
36
|
+
schema,
|
|
37
|
+
[]
|
|
38
|
+
]));
|
|
35
39
|
for (const payload of payloads) {
|
|
36
40
|
if (schemas.includes(payload.schema)) {
|
|
37
41
|
groupedPayloads[payload.schema].push(payload);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
const seen = /* @__PURE__ */ new Set();
|
|
41
|
-
let combinations = [
|
|
45
|
+
let combinations = [
|
|
46
|
+
[]
|
|
47
|
+
];
|
|
42
48
|
for (const schema of schemas) {
|
|
43
49
|
const newCombinations = [];
|
|
44
50
|
for (const combination of combinations) {
|
|
45
51
|
for (const payload of groupedPayloads[schema]) {
|
|
46
|
-
const newPerm = [
|
|
52
|
+
const newPerm = [
|
|
53
|
+
...combination,
|
|
54
|
+
payload
|
|
55
|
+
];
|
|
47
56
|
if (newPerm.length === schemas.length) {
|
|
48
57
|
const serialized = await generateKeyForTuple(newPerm);
|
|
49
58
|
if (!seen.has(serialized)) {
|
|
@@ -58,7 +67,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
58
67
|
combinations = newCombinations;
|
|
59
68
|
}
|
|
60
69
|
return combinations;
|
|
61
|
-
};
|
|
70
|
+
}, "combinationsBySchema");
|
|
62
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
72
|
0 && (module.exports = {
|
|
64
73
|
combinationsBySchema
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +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":"
|
|
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;;;;;;;ACAA,kBAA8B;AAQ9B,IAAMA,sBAAsB,8BAAOC,aAAAA;AAEjC,QAAMC,QAAQC,QAAO;AACrB,SAAOF,SAASG,IAAI,CAACC,MAAMC,0BAAcC,oBAAoBF,CAAAA,CAAAA,EAAIG,KAAK,GAAA;AACxE,GAJ4B;AAYrB,IAAMC,uBAAuB,8BAAOR,UAAqBS,YAAAA;AAE9D,QAAMC,kBAA6CC,OAAOC,YAAYH,QAAQN,IAAI,CAACU,WAAW;IAACA;IAAQ,CAAA;GAAG,CAAA;AAC1G,aAAWC,WAAWd,UAAU;AAC9B,QAAIS,QAAQM,SAASD,QAAQD,MAAM,GAAG;AACpCH,sBAAgBI,QAAQD,MAAM,EAAEG,KAAKF,OAAAA;IACvC;EACF;AAGA,QAAMG,OAAoB,oBAAIC,IAAAA;AAE9B,MAAIC,eAAe;IAAC,CAAA;;AAGpB,aAAWN,UAAUJ,SAAS;AAC5B,UAAMW,kBAA+B,CAAA;AAErC,eAAWC,eAAeF,cAAc;AAEtC,iBAAWL,WAAWJ,gBAAgBG,MAAAA,GAAS;AAE7C,cAAMS,UAAU;aAAID;UAAaP;;AAEjC,YAAIQ,QAAQC,WAAWd,QAAQc,QAAQ;AAErC,gBAAMC,aAAa,MAAMzB,oBAAoBuB,OAAAA;AAE7C,cAAI,CAACL,KAAKQ,IAAID,UAAAA,GAAa;AAEzBP,iBAAKS,IAAIF,UAAAA;AAETJ,4BAAgBJ,KAAKM,OAAAA;UACvB;QACF,OAAO;AAELF,0BAAgBJ,KAAKM,OAAAA;QACvB;MACF;IACF;AAEAH,mBAAeC;EACjB;AAGA,SAAOD;AACT,GA9CoC;","names":["generateKeyForTuple","payloads","Promise","resolve","map","p","PayloadHasher","stringifyHashFields","join","combinationsBySchema","schemas","groupedPayloads","Object","fromEntries","schema","payload","includes","push","seen","Set","combinations","newCombinations","combination","newPerm","length","serialized","has","add"]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
1
4
|
// src/combinationsBySchema.ts
|
|
2
5
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
3
|
-
var generateKeyForTuple = async (payloads) => {
|
|
6
|
+
var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
|
|
4
7
|
await Promise.resolve();
|
|
5
8
|
return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
|
|
6
|
-
};
|
|
7
|
-
var combinationsBySchema = async (payloads, schemas) => {
|
|
8
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
9
|
+
}, "generateKeyForTuple");
|
|
10
|
+
var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
11
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
12
|
+
schema,
|
|
13
|
+
[]
|
|
14
|
+
]));
|
|
9
15
|
for (const payload of payloads) {
|
|
10
16
|
if (schemas.includes(payload.schema)) {
|
|
11
17
|
groupedPayloads[payload.schema].push(payload);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
const seen = /* @__PURE__ */ new Set();
|
|
15
|
-
let combinations = [
|
|
21
|
+
let combinations = [
|
|
22
|
+
[]
|
|
23
|
+
];
|
|
16
24
|
for (const schema of schemas) {
|
|
17
25
|
const newCombinations = [];
|
|
18
26
|
for (const combination of combinations) {
|
|
19
27
|
for (const payload of groupedPayloads[schema]) {
|
|
20
|
-
const newPerm = [
|
|
28
|
+
const newPerm = [
|
|
29
|
+
...combination,
|
|
30
|
+
payload
|
|
31
|
+
];
|
|
21
32
|
if (newPerm.length === schemas.length) {
|
|
22
33
|
const serialized = await generateKeyForTuple(newPerm);
|
|
23
34
|
if (!seen.has(serialized)) {
|
|
@@ -32,7 +43,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
32
43
|
combinations = newCombinations;
|
|
33
44
|
}
|
|
34
45
|
return combinations;
|
|
35
|
-
};
|
|
46
|
+
}, "combinationsBySchema");
|
|
36
47
|
export {
|
|
37
48
|
combinationsBySchema
|
|
38
49
|
};
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +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":"
|
|
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,SAASA,qBAAqB;AAQ9B,IAAMC,sBAAsB,8BAAOC,aAAAA;AAEjC,QAAMC,QAAQC,QAAO;AACrB,SAAOF,SAASG,IAAI,CAACC,MAAMC,cAAcC,oBAAoBF,CAAAA,CAAAA,EAAIG,KAAK,GAAA;AACxE,GAJ4B;AAYrB,IAAMC,uBAAuB,8BAAOR,UAAqBS,YAAAA;AAE9D,QAAMC,kBAA6CC,OAAOC,YAAYH,QAAQN,IAAI,CAACU,WAAW;IAACA;IAAQ,CAAA;GAAG,CAAA;AAC1G,aAAWC,WAAWd,UAAU;AAC9B,QAAIS,QAAQM,SAASD,QAAQD,MAAM,GAAG;AACpCH,sBAAgBI,QAAQD,MAAM,EAAEG,KAAKF,OAAAA;IACvC;EACF;AAGA,QAAMG,OAAoB,oBAAIC,IAAAA;AAE9B,MAAIC,eAAe;IAAC,CAAA;;AAGpB,aAAWN,UAAUJ,SAAS;AAC5B,UAAMW,kBAA+B,CAAA;AAErC,eAAWC,eAAeF,cAAc;AAEtC,iBAAWL,WAAWJ,gBAAgBG,MAAAA,GAAS;AAE7C,cAAMS,UAAU;aAAID;UAAaP;;AAEjC,YAAIQ,QAAQC,WAAWd,QAAQc,QAAQ;AAErC,gBAAMC,aAAa,MAAMzB,oBAAoBuB,OAAAA;AAE7C,cAAI,CAACL,KAAKQ,IAAID,UAAAA,GAAa;AAEzBP,iBAAKS,IAAIF,UAAAA;AAETJ,4BAAgBJ,KAAKM,OAAAA;UACvB;QACF,OAAO;AAELF,0BAAgBJ,KAAKM,OAAAA;QACvB;MACF;IACF;AAEAH,mBAAeC;EACjB;AAGA,SAAOD;AACT,GA9CoC;","names":["PayloadHasher","generateKeyForTuple","payloads","Promise","resolve","map","p","PayloadHasher","stringifyHashFields","join","combinationsBySchema","schemas","groupedPayloads","Object","fromEntries","schema","payload","includes","push","seen","Set","combinations","newCombinations","combination","newPerm","length","serialized","has","add"]}
|
package/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xyo-network/hash": "~2.
|
|
14
|
-
"@xyo-network/payload-model": "~2.
|
|
13
|
+
"@xyo-network/hash": "~2.85.0",
|
|
14
|
+
"@xyo-network/payload-model": "~2.85.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false,
|
|
59
59
|
"types": "dist/node/index.d.ts",
|
|
60
|
-
"version": "2.
|
|
60
|
+
"version": "2.85.0",
|
|
61
61
|
"type": "module"
|
|
62
62
|
}
|