@xyo-network/payload-utils 2.85.0 → 2.85.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/browser/combinationsByBoundwitness.d.cts +10 -0
  2. package/dist/browser/combinationsByBoundwitness.d.cts.map +1 -0
  3. package/dist/browser/combinationsByBoundwitness.d.mts +10 -0
  4. package/dist/browser/combinationsByBoundwitness.d.mts.map +1 -0
  5. package/dist/browser/combinationsByBoundwitness.d.ts +10 -0
  6. package/dist/browser/combinationsByBoundwitness.d.ts.map +1 -0
  7. package/dist/browser/index.cjs +68 -3
  8. package/dist/browser/index.cjs.map +1 -1
  9. package/dist/browser/index.d.cts +2 -0
  10. package/dist/browser/index.d.cts.map +1 -1
  11. package/dist/browser/index.d.mts +2 -0
  12. package/dist/browser/index.d.mts.map +1 -1
  13. package/dist/browser/index.d.ts +2 -0
  14. package/dist/browser/index.d.ts.map +1 -1
  15. package/dist/browser/index.js +68 -3
  16. package/dist/browser/index.js.map +1 -1
  17. package/dist/browser/intraBoundwitnessSchemaCombinations.d.cts +9 -0
  18. package/dist/browser/intraBoundwitnessSchemaCombinations.d.cts.map +1 -0
  19. package/dist/browser/intraBoundwitnessSchemaCombinations.d.mts +9 -0
  20. package/dist/browser/intraBoundwitnessSchemaCombinations.d.mts.map +1 -0
  21. package/dist/browser/intraBoundwitnessSchemaCombinations.d.ts +9 -0
  22. package/dist/browser/intraBoundwitnessSchemaCombinations.d.ts.map +1 -0
  23. package/dist/node/combinationsByBoundwitness.d.cts +10 -0
  24. package/dist/node/combinationsByBoundwitness.d.cts.map +1 -0
  25. package/dist/node/combinationsByBoundwitness.d.mts +10 -0
  26. package/dist/node/combinationsByBoundwitness.d.mts.map +1 -0
  27. package/dist/node/combinationsByBoundwitness.d.ts +10 -0
  28. package/dist/node/combinationsByBoundwitness.d.ts.map +1 -0
  29. package/dist/node/index.cjs +71 -4
  30. package/dist/node/index.cjs.map +1 -1
  31. package/dist/node/index.d.cts +2 -0
  32. package/dist/node/index.d.cts.map +1 -1
  33. package/dist/node/index.d.mts +2 -0
  34. package/dist/node/index.d.mts.map +1 -1
  35. package/dist/node/index.d.ts +2 -0
  36. package/dist/node/index.d.ts.map +1 -1
  37. package/dist/node/index.js +68 -3
  38. package/dist/node/index.js.map +1 -1
  39. package/dist/node/intraBoundwitnessSchemaCombinations.d.cts +9 -0
  40. package/dist/node/intraBoundwitnessSchemaCombinations.d.cts.map +1 -0
  41. package/dist/node/intraBoundwitnessSchemaCombinations.d.mts +9 -0
  42. package/dist/node/intraBoundwitnessSchemaCombinations.d.mts.map +1 -0
  43. package/dist/node/intraBoundwitnessSchemaCombinations.d.ts +9 -0
  44. package/dist/node/intraBoundwitnessSchemaCombinations.d.ts.map +1 -0
  45. package/package.json +7 -3
  46. package/src/combinationsByBoundwitness.ts +27 -0
  47. package/src/index.ts +2 -0
  48. package/src/intraBoundwitnessSchemaCombinations.ts +54 -0
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -21,15 +21,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var src_exports = {};
23
23
  __export(src_exports, {
24
- combinationsBySchema: () => combinationsBySchema
24
+ combinationsByBoundwitness: () => combinationsByBoundwitness,
25
+ combinationsBySchema: () => combinationsBySchema,
26
+ intraBoundwitnessSchemaCombinations: () => intraBoundwitnessSchemaCombinations
25
27
  });
26
28
  module.exports = __toCommonJS(src_exports);
27
29
 
28
- // src/combinationsBySchema.ts
30
+ // src/combinationsByBoundwitness.ts
31
+ var import_exists = require("@xylabs/exists");
32
+ var import_set = require("@xylabs/set");
33
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
29
34
  var import_hash = require("@xyo-network/hash");
35
+ var combinationsByBoundwitness = /* @__PURE__ */ __name(async (payloads) => {
36
+ const bws = new Set(payloads.filter(import_boundwitness_model.isBoundWitness));
37
+ const remaining = (0, import_set.difference)(new Set(payloads), bws);
38
+ const payloadDictionary = await import_hash.PayloadHasher.toMap([
39
+ ...remaining
40
+ ]);
41
+ const results = [];
42
+ for (const bw of bws) {
43
+ const { payload_hashes } = bw;
44
+ const p = payload_hashes.map((h) => payloadDictionary[h]).filter(import_exists.exists);
45
+ if (p.length === payload_hashes.length) {
46
+ const complete = [
47
+ bw,
48
+ ...p
49
+ ];
50
+ results.push(complete);
51
+ }
52
+ }
53
+ return results;
54
+ }, "combinationsByBoundwitness");
55
+
56
+ // src/combinationsBySchema.ts
57
+ var import_hash2 = require("@xyo-network/hash");
30
58
  var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
31
59
  await Promise.resolve();
32
- return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
60
+ return payloads.map((p) => import_hash2.PayloadHasher.stringifyHashFields(p)).join("|");
33
61
  }, "generateKeyForTuple");
34
62
  var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
35
63
  const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
@@ -68,4 +96,41 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
68
96
  }
69
97
  return combinations;
70
98
  }, "combinationsBySchema");
99
+
100
+ // src/intraBoundwitnessSchemaCombinations.ts
101
+ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness, schemas) => {
102
+ const indexMap = {};
103
+ for (const [index, element] of boundwitness.payload_schemas.entries()) {
104
+ if (!indexMap[element]) {
105
+ indexMap[element] = [];
106
+ }
107
+ indexMap[element].push(index);
108
+ }
109
+ let uniqueCombinations = [
110
+ []
111
+ ];
112
+ for (const element of schemas) {
113
+ const newCombinations = [];
114
+ const indices = indexMap[element] || [];
115
+ for (const combination of uniqueCombinations) {
116
+ for (const index of indices) {
117
+ if (!combination.includes(index)) {
118
+ const newCombination = [
119
+ ...combination,
120
+ index
121
+ ];
122
+ if (newCombination.length === schemas.indexOf(element) + 1) {
123
+ newCombinations.push(newCombination);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ uniqueCombinations = newCombinations;
129
+ }
130
+ return uniqueCombinations.map((indexes) => {
131
+ return indexes.map((index) => {
132
+ return boundwitness.payload_hashes[index];
133
+ });
134
+ });
135
+ }, "intraBoundwitnessSchemaCombinations");
71
136
  //# 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":";;;;;;;;;;;;;;;;;;;;;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"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness'\nexport * from './combinationsBySchema'\nexport * from './intraBoundwitnessSchemaCombinations'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits\n * bound witnesses where the payloads were not included in the supplied payloads.\n * @param payloads An array of bound witnesses and payloads\n * @returns An array of tuples of bound witnesses and their payloads\n */\nexport const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {\n const bws = new Set<BoundWitness>(payloads.filter(isBoundWitness))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadHasher.toMap([...remaining])\n const results = [] as [BoundWitness, ...Payload[]][]\n for (const bw of bws) {\n const { payload_hashes } = bw\n const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists)\n if (p.length === payload_hashes.length) {\n const complete = [bw, ...p] as [BoundWitness, ...Payload[]]\n results.push(complete)\n }\n }\n return results\n}\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","import { BoundWitness } from '@xyo-network/boundwitness-model'\n\n/**\n * Returns all the possible combinations of payloads for the supplied schemas within the bound witness\n * @param boundwitness The bound witness to search\n * @param schemas The schemas to search for unique combinations of\n * @returns The payload hashes corresponding to the unique combinations of the supplied schemas\n */\nexport const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: string[]): string[][] => {\n // Map to store the indices of each element in the source array\n const indexMap: Record<string, number[]> = {}\n\n // Populate the index map with positions of each element\n for (const [index, element] of boundwitness.payload_schemas.entries()) {\n if (!indexMap[element]) {\n indexMap[element] = []\n }\n indexMap[element].push(index)\n }\n\n // Initialize an array to store unique combinations\n let uniqueCombinations = [[]] as number[][]\n\n // Iterate over each element in the target array\n for (const element of schemas) {\n const newCombinations: number[][] = []\n // Get the array of indices for the current element\n const indices = indexMap[element] || []\n\n // Iterate over existing combinations\n for (const combination of uniqueCombinations) {\n // Iterate over each index in the indices array\n for (const index of indices) {\n // Check if the index is already in the combination\n if (!combination.includes(index)) {\n const newCombination = [...combination, index]\n // Only add the new combination if its length matches the current target index\n if (newCombination.length === schemas.indexOf(element) + 1) {\n newCombinations.push(newCombination)\n }\n }\n }\n }\n\n // Update the unique combinations for the next iteration\n uniqueCombinations = newCombinations\n }\n\n return uniqueCombinations.map((indexes) => {\n return indexes.map((index) => {\n return boundwitness.payload_hashes[index]\n })\n })\n}\n"],"mappings":"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","names":["combinationsByBoundwitness","payloads","bws","Set","filter","isBoundWitness","remaining","difference","payloadDictionary","PayloadHasher","toMap","results","bw","payload_hashes","p","map","h","exists","length","complete","push","import_hash","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","intraBoundwitnessSchemaCombinations","boundwitness","schemas","indexMap","index","element","payload_schemas","entries","push","uniqueCombinations","newCombinations","indices","combination","includes","newCombination","length","indexOf","map","indexes","payload_hashes"]}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,11 +1,37 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // src/combinationsBySchema.ts
4
+ // src/combinationsByBoundwitness.ts
5
+ import { exists } from "@xylabs/exists";
6
+ import { difference } from "@xylabs/set";
7
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
5
8
  import { PayloadHasher } from "@xyo-network/hash";
9
+ var combinationsByBoundwitness = /* @__PURE__ */ __name(async (payloads) => {
10
+ const bws = new Set(payloads.filter(isBoundWitness));
11
+ const remaining = difference(new Set(payloads), bws);
12
+ const payloadDictionary = await PayloadHasher.toMap([
13
+ ...remaining
14
+ ]);
15
+ const results = [];
16
+ for (const bw of bws) {
17
+ const { payload_hashes } = bw;
18
+ const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists);
19
+ if (p.length === payload_hashes.length) {
20
+ const complete = [
21
+ bw,
22
+ ...p
23
+ ];
24
+ results.push(complete);
25
+ }
26
+ }
27
+ return results;
28
+ }, "combinationsByBoundwitness");
29
+
30
+ // src/combinationsBySchema.ts
31
+ import { PayloadHasher as PayloadHasher2 } from "@xyo-network/hash";
6
32
  var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
7
33
  await Promise.resolve();
8
- return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
34
+ return payloads.map((p) => PayloadHasher2.stringifyHashFields(p)).join("|");
9
35
  }, "generateKeyForTuple");
10
36
  var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
11
37
  const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
@@ -44,7 +70,46 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
44
70
  }
45
71
  return combinations;
46
72
  }, "combinationsBySchema");
73
+
74
+ // src/intraBoundwitnessSchemaCombinations.ts
75
+ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness, schemas) => {
76
+ const indexMap = {};
77
+ for (const [index, element] of boundwitness.payload_schemas.entries()) {
78
+ if (!indexMap[element]) {
79
+ indexMap[element] = [];
80
+ }
81
+ indexMap[element].push(index);
82
+ }
83
+ let uniqueCombinations = [
84
+ []
85
+ ];
86
+ for (const element of schemas) {
87
+ const newCombinations = [];
88
+ const indices = indexMap[element] || [];
89
+ for (const combination of uniqueCombinations) {
90
+ for (const index of indices) {
91
+ if (!combination.includes(index)) {
92
+ const newCombination = [
93
+ ...combination,
94
+ index
95
+ ];
96
+ if (newCombination.length === schemas.indexOf(element) + 1) {
97
+ newCombinations.push(newCombination);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ uniqueCombinations = newCombinations;
103
+ }
104
+ return uniqueCombinations.map((indexes) => {
105
+ return indexes.map((index) => {
106
+ return boundwitness.payload_hashes[index];
107
+ });
108
+ });
109
+ }, "intraBoundwitnessSchemaCombinations");
47
110
  export {
48
- combinationsBySchema
111
+ combinationsByBoundwitness,
112
+ combinationsBySchema,
113
+ intraBoundwitnessSchemaCombinations
49
114
  };
50
115
  //# sourceMappingURL=index.js.map
@@ -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":";;;;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"]}
1
+ {"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits\n * bound witnesses where the payloads were not included in the supplied payloads.\n * @param payloads An array of bound witnesses and payloads\n * @returns An array of tuples of bound witnesses and their payloads\n */\nexport const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {\n const bws = new Set<BoundWitness>(payloads.filter(isBoundWitness))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadHasher.toMap([...remaining])\n const results = [] as [BoundWitness, ...Payload[]][]\n for (const bw of bws) {\n const { payload_hashes } = bw\n const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists)\n if (p.length === payload_hashes.length) {\n const complete = [bw, ...p] as [BoundWitness, ...Payload[]]\n results.push(complete)\n }\n }\n return results\n}\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","import { BoundWitness } from '@xyo-network/boundwitness-model'\n\n/**\n * Returns all the possible combinations of payloads for the supplied schemas within the bound witness\n * @param boundwitness The bound witness to search\n * @param schemas The schemas to search for unique combinations of\n * @returns The payload hashes corresponding to the unique combinations of the supplied schemas\n */\nexport const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: string[]): string[][] => {\n // Map to store the indices of each element in the source array\n const indexMap: Record<string, number[]> = {}\n\n // Populate the index map with positions of each element\n for (const [index, element] of boundwitness.payload_schemas.entries()) {\n if (!indexMap[element]) {\n indexMap[element] = []\n }\n indexMap[element].push(index)\n }\n\n // Initialize an array to store unique combinations\n let uniqueCombinations = [[]] as number[][]\n\n // Iterate over each element in the target array\n for (const element of schemas) {\n const newCombinations: number[][] = []\n // Get the array of indices for the current element\n const indices = indexMap[element] || []\n\n // Iterate over existing combinations\n for (const combination of uniqueCombinations) {\n // Iterate over each index in the indices array\n for (const index of indices) {\n // Check if the index is already in the combination\n if (!combination.includes(index)) {\n const newCombination = [...combination, index]\n // Only add the new combination if its length matches the current target index\n if (newCombination.length === schemas.indexOf(element) + 1) {\n newCombinations.push(newCombination)\n }\n }\n }\n }\n\n // Update the unique combinations for the next iteration\n uniqueCombinations = newCombinations\n }\n\n return uniqueCombinations.map((indexes) => {\n return indexes.map((index) => {\n return boundwitness.payload_hashes[index]\n })\n })\n}\n"],"mappings":"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","names":["exists","difference","isBoundWitness","PayloadHasher","combinationsByBoundwitness","payloads","bws","Set","filter","isBoundWitness","remaining","difference","payloadDictionary","PayloadHasher","toMap","results","bw","payload_hashes","p","map","h","exists","length","complete","push","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","intraBoundwitnessSchemaCombinations","boundwitness","schemas","indexMap","index","element","payload_schemas","entries","push","uniqueCombinations","newCombinations","indices","combination","includes","newCombination","length","indexOf","map","indexes","payload_hashes"]}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ import { Payload } from '@xyo-network/payload-model';
3
+ /**
4
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
5
+ * bound witnesses where the payloads were not included in the supplied payloads.
6
+ * @param payloads An array of bound witnesses and payloads
7
+ * @returns An array of tuples of bound witnesses and their payloads
8
+ */
9
+ export declare const combinationsByBoundwitness: (payloads: Payload[]) => Promise<[BoundWitness, ...Payload[]][]>;
10
+ //# sourceMappingURL=combinationsByBoundwitness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAoB,OAAO,EAAE,KAAG,QAAQ,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
@@ -21,15 +21,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/index.ts
22
22
  var src_exports = {};
23
23
  __export(src_exports, {
24
- combinationsBySchema: () => combinationsBySchema
24
+ combinationsByBoundwitness: () => combinationsByBoundwitness,
25
+ combinationsBySchema: () => combinationsBySchema,
26
+ intraBoundwitnessSchemaCombinations: () => intraBoundwitnessSchemaCombinations
25
27
  });
26
28
  module.exports = __toCommonJS(src_exports);
27
29
 
28
- // src/combinationsBySchema.ts
30
+ // src/combinationsByBoundwitness.ts
31
+ var import_exists = require("@xylabs/exists");
32
+ var import_set = require("@xylabs/set");
33
+ var import_boundwitness_model = require("@xyo-network/boundwitness-model");
29
34
  var import_hash = require("@xyo-network/hash");
35
+ var combinationsByBoundwitness = /* @__PURE__ */ __name(async (payloads) => {
36
+ const bws = new Set(payloads.filter(import_boundwitness_model.isBoundWitness));
37
+ const remaining = (0, import_set.difference)(new Set(payloads), bws);
38
+ const payloadDictionary = await import_hash.PayloadHasher.toMap([
39
+ ...remaining
40
+ ]);
41
+ const results = [];
42
+ for (const bw of bws) {
43
+ const { payload_hashes } = bw;
44
+ const p = payload_hashes.map((h) => payloadDictionary[h]).filter(import_exists.exists);
45
+ if (p.length === payload_hashes.length) {
46
+ const complete = [
47
+ bw,
48
+ ...p
49
+ ];
50
+ results.push(complete);
51
+ }
52
+ }
53
+ return results;
54
+ }, "combinationsByBoundwitness");
55
+
56
+ // src/combinationsBySchema.ts
57
+ var import_hash2 = require("@xyo-network/hash");
30
58
  var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
31
59
  await Promise.resolve();
32
- return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
60
+ return payloads.map((p) => import_hash2.PayloadHasher.stringifyHashFields(p)).join("|");
33
61
  }, "generateKeyForTuple");
34
62
  var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
35
63
  const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
@@ -68,8 +96,47 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
68
96
  }
69
97
  return combinations;
70
98
  }, "combinationsBySchema");
99
+
100
+ // src/intraBoundwitnessSchemaCombinations.ts
101
+ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness, schemas) => {
102
+ const indexMap = {};
103
+ for (const [index, element] of boundwitness.payload_schemas.entries()) {
104
+ if (!indexMap[element]) {
105
+ indexMap[element] = [];
106
+ }
107
+ indexMap[element].push(index);
108
+ }
109
+ let uniqueCombinations = [
110
+ []
111
+ ];
112
+ for (const element of schemas) {
113
+ const newCombinations = [];
114
+ const indices = indexMap[element] || [];
115
+ for (const combination of uniqueCombinations) {
116
+ for (const index of indices) {
117
+ if (!combination.includes(index)) {
118
+ const newCombination = [
119
+ ...combination,
120
+ index
121
+ ];
122
+ if (newCombination.length === schemas.indexOf(element) + 1) {
123
+ newCombinations.push(newCombination);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ uniqueCombinations = newCombinations;
129
+ }
130
+ return uniqueCombinations.map((indexes) => {
131
+ return indexes.map((index) => {
132
+ return boundwitness.payload_hashes[index];
133
+ });
134
+ });
135
+ }, "intraBoundwitnessSchemaCombinations");
71
136
  // Annotate the CommonJS export names for ESM import in node:
72
137
  0 && (module.exports = {
73
- combinationsBySchema
138
+ combinationsByBoundwitness,
139
+ combinationsBySchema,
140
+ intraBoundwitnessSchemaCombinations
74
141
  });
75
142
  //# 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":";;;;;;;;;;;;;;;;;;;;;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"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness'\nexport * from './combinationsBySchema'\nexport * from './intraBoundwitnessSchemaCombinations'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits\n * bound witnesses where the payloads were not included in the supplied payloads.\n * @param payloads An array of bound witnesses and payloads\n * @returns An array of tuples of bound witnesses and their payloads\n */\nexport const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {\n const bws = new Set<BoundWitness>(payloads.filter(isBoundWitness))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadHasher.toMap([...remaining])\n const results = [] as [BoundWitness, ...Payload[]][]\n for (const bw of bws) {\n const { payload_hashes } = bw\n const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists)\n if (p.length === payload_hashes.length) {\n const complete = [bw, ...p] as [BoundWitness, ...Payload[]]\n results.push(complete)\n }\n }\n return results\n}\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","import { BoundWitness } from '@xyo-network/boundwitness-model'\n\n/**\n * Returns all the possible combinations of payloads for the supplied schemas within the bound witness\n * @param boundwitness The bound witness to search\n * @param schemas The schemas to search for unique combinations of\n * @returns The payload hashes corresponding to the unique combinations of the supplied schemas\n */\nexport const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: string[]): string[][] => {\n // Map to store the indices of each element in the source array\n const indexMap: Record<string, number[]> = {}\n\n // Populate the index map with positions of each element\n for (const [index, element] of boundwitness.payload_schemas.entries()) {\n if (!indexMap[element]) {\n indexMap[element] = []\n }\n indexMap[element].push(index)\n }\n\n // Initialize an array to store unique combinations\n let uniqueCombinations = [[]] as number[][]\n\n // Iterate over each element in the target array\n for (const element of schemas) {\n const newCombinations: number[][] = []\n // Get the array of indices for the current element\n const indices = indexMap[element] || []\n\n // Iterate over existing combinations\n for (const combination of uniqueCombinations) {\n // Iterate over each index in the indices array\n for (const index of indices) {\n // Check if the index is already in the combination\n if (!combination.includes(index)) {\n const newCombination = [...combination, index]\n // Only add the new combination if its length matches the current target index\n if (newCombination.length === schemas.indexOf(element) + 1) {\n newCombinations.push(newCombination)\n }\n }\n }\n }\n\n // Update the unique combinations for the next iteration\n uniqueCombinations = newCombinations\n }\n\n return uniqueCombinations.map((indexes) => {\n return indexes.map((index) => {\n return boundwitness.payload_hashes[index]\n })\n })\n}\n"],"mappings":"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","names":["combinationsByBoundwitness","payloads","bws","Set","filter","isBoundWitness","remaining","difference","payloadDictionary","PayloadHasher","toMap","results","bw","payload_hashes","p","map","h","exists","length","complete","push","import_hash","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","intraBoundwitnessSchemaCombinations","boundwitness","schemas","indexMap","index","element","payload_schemas","entries","push","uniqueCombinations","newCombinations","indices","combination","includes","newCombination","length","indexOf","map","indexes","payload_hashes"]}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,2 +1,4 @@
1
+ export * from './combinationsByBoundwitness';
1
2
  export * from './combinationsBySchema';
3
+ export * from './intraBoundwitnessSchemaCombinations';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,uCAAuC,CAAA"}
@@ -1,11 +1,37 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // src/combinationsBySchema.ts
4
+ // src/combinationsByBoundwitness.ts
5
+ import { exists } from "@xylabs/exists";
6
+ import { difference } from "@xylabs/set";
7
+ import { isBoundWitness } from "@xyo-network/boundwitness-model";
5
8
  import { PayloadHasher } from "@xyo-network/hash";
9
+ var combinationsByBoundwitness = /* @__PURE__ */ __name(async (payloads) => {
10
+ const bws = new Set(payloads.filter(isBoundWitness));
11
+ const remaining = difference(new Set(payloads), bws);
12
+ const payloadDictionary = await PayloadHasher.toMap([
13
+ ...remaining
14
+ ]);
15
+ const results = [];
16
+ for (const bw of bws) {
17
+ const { payload_hashes } = bw;
18
+ const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists);
19
+ if (p.length === payload_hashes.length) {
20
+ const complete = [
21
+ bw,
22
+ ...p
23
+ ];
24
+ results.push(complete);
25
+ }
26
+ }
27
+ return results;
28
+ }, "combinationsByBoundwitness");
29
+
30
+ // src/combinationsBySchema.ts
31
+ import { PayloadHasher as PayloadHasher2 } from "@xyo-network/hash";
6
32
  var generateKeyForTuple = /* @__PURE__ */ __name(async (payloads) => {
7
33
  await Promise.resolve();
8
- return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
34
+ return payloads.map((p) => PayloadHasher2.stringifyHashFields(p)).join("|");
9
35
  }, "generateKeyForTuple");
10
36
  var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
11
37
  const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
@@ -44,7 +70,46 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
44
70
  }
45
71
  return combinations;
46
72
  }, "combinationsBySchema");
73
+
74
+ // src/intraBoundwitnessSchemaCombinations.ts
75
+ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness, schemas) => {
76
+ const indexMap = {};
77
+ for (const [index, element] of boundwitness.payload_schemas.entries()) {
78
+ if (!indexMap[element]) {
79
+ indexMap[element] = [];
80
+ }
81
+ indexMap[element].push(index);
82
+ }
83
+ let uniqueCombinations = [
84
+ []
85
+ ];
86
+ for (const element of schemas) {
87
+ const newCombinations = [];
88
+ const indices = indexMap[element] || [];
89
+ for (const combination of uniqueCombinations) {
90
+ for (const index of indices) {
91
+ if (!combination.includes(index)) {
92
+ const newCombination = [
93
+ ...combination,
94
+ index
95
+ ];
96
+ if (newCombination.length === schemas.indexOf(element) + 1) {
97
+ newCombinations.push(newCombination);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ uniqueCombinations = newCombinations;
103
+ }
104
+ return uniqueCombinations.map((indexes) => {
105
+ return indexes.map((index) => {
106
+ return boundwitness.payload_hashes[index];
107
+ });
108
+ });
109
+ }, "intraBoundwitnessSchemaCombinations");
47
110
  export {
48
- combinationsBySchema
111
+ combinationsByBoundwitness,
112
+ combinationsBySchema,
113
+ intraBoundwitnessSchemaCombinations
49
114
  };
50
115
  //# sourceMappingURL=index.js.map
@@ -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":";;;;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"]}
1
+ {"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadHasher } from '@xyo-network/hash'\nimport { Payload } from '@xyo-network/payload-model'\n\n/**\n * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits\n * bound witnesses where the payloads were not included in the supplied payloads.\n * @param payloads An array of bound witnesses and payloads\n * @returns An array of tuples of bound witnesses and their payloads\n */\nexport const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {\n const bws = new Set<BoundWitness>(payloads.filter(isBoundWitness))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadHasher.toMap([...remaining])\n const results = [] as [BoundWitness, ...Payload[]][]\n for (const bw of bws) {\n const { payload_hashes } = bw\n const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists)\n if (p.length === payload_hashes.length) {\n const complete = [bw, ...p] as [BoundWitness, ...Payload[]]\n results.push(complete)\n }\n }\n return results\n}\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","import { BoundWitness } from '@xyo-network/boundwitness-model'\n\n/**\n * Returns all the possible combinations of payloads for the supplied schemas within the bound witness\n * @param boundwitness The bound witness to search\n * @param schemas The schemas to search for unique combinations of\n * @returns The payload hashes corresponding to the unique combinations of the supplied schemas\n */\nexport const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: string[]): string[][] => {\n // Map to store the indices of each element in the source array\n const indexMap: Record<string, number[]> = {}\n\n // Populate the index map with positions of each element\n for (const [index, element] of boundwitness.payload_schemas.entries()) {\n if (!indexMap[element]) {\n indexMap[element] = []\n }\n indexMap[element].push(index)\n }\n\n // Initialize an array to store unique combinations\n let uniqueCombinations = [[]] as number[][]\n\n // Iterate over each element in the target array\n for (const element of schemas) {\n const newCombinations: number[][] = []\n // Get the array of indices for the current element\n const indices = indexMap[element] || []\n\n // Iterate over existing combinations\n for (const combination of uniqueCombinations) {\n // Iterate over each index in the indices array\n for (const index of indices) {\n // Check if the index is already in the combination\n if (!combination.includes(index)) {\n const newCombination = [...combination, index]\n // Only add the new combination if its length matches the current target index\n if (newCombination.length === schemas.indexOf(element) + 1) {\n newCombinations.push(newCombination)\n }\n }\n }\n }\n\n // Update the unique combinations for the next iteration\n uniqueCombinations = newCombinations\n }\n\n return uniqueCombinations.map((indexes) => {\n return indexes.map((index) => {\n return boundwitness.payload_hashes[index]\n })\n })\n}\n"],"mappings":"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","names":["exists","difference","isBoundWitness","PayloadHasher","combinationsByBoundwitness","payloads","bws","Set","filter","isBoundWitness","remaining","difference","payloadDictionary","PayloadHasher","toMap","results","bw","payload_hashes","p","map","h","exists","length","complete","push","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","intraBoundwitnessSchemaCombinations","boundwitness","schemas","indexMap","index","element","payload_schemas","entries","push","uniqueCombinations","newCombinations","indices","combination","includes","newCombination","length","indexOf","map","indexes","payload_hashes"]}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model';
2
+ /**
3
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
4
+ * @param boundwitness The bound witness to search
5
+ * @param schemas The schemas to search for unique combinations of
6
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
7
+ */
8
+ export declare const intraBoundwitnessSchemaCombinations: (boundwitness: BoundWitness, schemas: string[]) => string[][];
9
+ //# sourceMappingURL=intraBoundwitnessSchemaCombinations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAE9D;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,iBAAkB,YAAY,WAAW,MAAM,EAAE,KAAG,MAAM,EAAE,EA6C3G,CAAA"}
package/package.json CHANGED
@@ -10,12 +10,16 @@
10
10
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xyo-network/hash": "~2.85.0",
14
- "@xyo-network/payload-model": "~2.85.0"
13
+ "@xylabs/exists": "^2.13.20",
14
+ "@xylabs/set": "^2.13.20",
15
+ "@xyo-network/boundwitness-model": "~2.85.1",
16
+ "@xyo-network/hash": "~2.85.1",
17
+ "@xyo-network/payload-model": "~2.85.1"
15
18
  },
16
19
  "devDependencies": {
17
20
  "@xylabs/ts-scripts-yarn3": "^3.2.25",
18
21
  "@xylabs/tsconfig": "^3.2.25",
22
+ "@xyo-network/boundwitness-builder": "~2.85.1",
19
23
  "typescript": "^5.3.3"
20
24
  },
21
25
  "description": "Primary SDK for using XYO Protocol 2.0",
@@ -57,6 +61,6 @@
57
61
  },
58
62
  "sideEffects": false,
59
63
  "types": "dist/node/index.d.ts",
60
- "version": "2.85.0",
64
+ "version": "2.85.1",
61
65
  "type": "module"
62
66
  }
@@ -0,0 +1,27 @@
1
+ import { exists } from '@xylabs/exists'
2
+ import { difference } from '@xylabs/set'
3
+ import { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'
4
+ import { PayloadHasher } from '@xyo-network/hash'
5
+ import { Payload } from '@xyo-network/payload-model'
6
+
7
+ /**
8
+ * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
9
+ * bound witnesses where the payloads were not included in the supplied payloads.
10
+ * @param payloads An array of bound witnesses and payloads
11
+ * @returns An array of tuples of bound witnesses and their payloads
12
+ */
13
+ export const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {
14
+ const bws = new Set<BoundWitness>(payloads.filter(isBoundWitness))
15
+ const remaining = difference(new Set(payloads), bws)
16
+ const payloadDictionary = await PayloadHasher.toMap([...remaining])
17
+ const results = [] as [BoundWitness, ...Payload[]][]
18
+ for (const bw of bws) {
19
+ const { payload_hashes } = bw
20
+ const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists)
21
+ if (p.length === payload_hashes.length) {
22
+ const complete = [bw, ...p] as [BoundWitness, ...Payload[]]
23
+ results.push(complete)
24
+ }
25
+ }
26
+ return results
27
+ }
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from './combinationsByBoundwitness'
1
2
  export * from './combinationsBySchema'
3
+ export * from './intraBoundwitnessSchemaCombinations'
@@ -0,0 +1,54 @@
1
+ import { BoundWitness } from '@xyo-network/boundwitness-model'
2
+
3
+ /**
4
+ * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
5
+ * @param boundwitness The bound witness to search
6
+ * @param schemas The schemas to search for unique combinations of
7
+ * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
8
+ */
9
+ export const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: string[]): string[][] => {
10
+ // Map to store the indices of each element in the source array
11
+ const indexMap: Record<string, number[]> = {}
12
+
13
+ // Populate the index map with positions of each element
14
+ for (const [index, element] of boundwitness.payload_schemas.entries()) {
15
+ if (!indexMap[element]) {
16
+ indexMap[element] = []
17
+ }
18
+ indexMap[element].push(index)
19
+ }
20
+
21
+ // Initialize an array to store unique combinations
22
+ let uniqueCombinations = [[]] as number[][]
23
+
24
+ // Iterate over each element in the target array
25
+ for (const element of schemas) {
26
+ const newCombinations: number[][] = []
27
+ // Get the array of indices for the current element
28
+ const indices = indexMap[element] || []
29
+
30
+ // Iterate over existing combinations
31
+ for (const combination of uniqueCombinations) {
32
+ // Iterate over each index in the indices array
33
+ for (const index of indices) {
34
+ // Check if the index is already in the combination
35
+ if (!combination.includes(index)) {
36
+ const newCombination = [...combination, index]
37
+ // Only add the new combination if its length matches the current target index
38
+ if (newCombination.length === schemas.indexOf(element) + 1) {
39
+ newCombinations.push(newCombination)
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ // Update the unique combinations for the next iteration
46
+ uniqueCombinations = newCombinations
47
+ }
48
+
49
+ return uniqueCombinations.map((indexes) => {
50
+ return indexes.map((index) => {
51
+ return boundwitness.payload_hashes[index]
52
+ })
53
+ })
54
+ }