@xyo-network/payload-utils 2.110.9 → 2.110.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.cjs +15 -34
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +15 -36
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/index.cjs +15 -34
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +15 -36
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/index.cjs +15 -34
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +15 -36
- package/dist/node/index.js.map +1 -1
- package/package.json +11 -11
package/dist/browser/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ 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 });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,55 +31,42 @@ var import_exists = require("@xylabs/exists");
|
|
|
32
31
|
var import_set = require("@xylabs/set");
|
|
33
32
|
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
34
33
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
35
|
-
var combinationsByBoundwitness =
|
|
34
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
36
35
|
const bws = new Set(payloads.filter(import_boundwitness_model.isBoundWitness));
|
|
37
36
|
const remaining = (0, import_set.difference)(new Set(payloads), bws);
|
|
38
|
-
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([
|
|
39
|
-
...remaining
|
|
40
|
-
]);
|
|
37
|
+
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([...remaining]);
|
|
41
38
|
const results = [];
|
|
42
39
|
for (const bw of bws) {
|
|
43
40
|
const { payload_hashes } = bw;
|
|
44
41
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(import_exists.exists);
|
|
45
42
|
if (p.length === payload_hashes.length) {
|
|
46
|
-
const complete = [
|
|
47
|
-
bw,
|
|
48
|
-
...p
|
|
49
|
-
];
|
|
43
|
+
const complete = [bw, ...p];
|
|
50
44
|
results.push(complete);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
return results;
|
|
54
|
-
}
|
|
48
|
+
};
|
|
55
49
|
|
|
56
50
|
// src/combinationsBySchema.ts
|
|
57
51
|
var import_hash = require("@xyo-network/hash");
|
|
58
|
-
var generateKeyForTuple =
|
|
52
|
+
var generateKeyForTuple = async (payloads) => {
|
|
59
53
|
await Promise.resolve();
|
|
60
54
|
return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
|
|
61
|
-
}
|
|
62
|
-
var combinationsBySchema =
|
|
63
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
64
|
-
schema,
|
|
65
|
-
[]
|
|
66
|
-
]));
|
|
55
|
+
};
|
|
56
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
57
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
67
58
|
for (const payload of payloads) {
|
|
68
59
|
if (schemas.includes(payload.schema)) {
|
|
69
60
|
groupedPayloads[payload.schema].push(payload);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
const seen = /* @__PURE__ */ new Set();
|
|
73
|
-
let combinations = [
|
|
74
|
-
[]
|
|
75
|
-
];
|
|
64
|
+
let combinations = [[]];
|
|
76
65
|
for (const schema of schemas) {
|
|
77
66
|
const newCombinations = [];
|
|
78
67
|
for (const combination of combinations) {
|
|
79
68
|
for (const payload of groupedPayloads[schema]) {
|
|
80
|
-
const newPerm = [
|
|
81
|
-
...combination,
|
|
82
|
-
payload
|
|
83
|
-
];
|
|
69
|
+
const newPerm = [...combination, payload];
|
|
84
70
|
if (newPerm.length === schemas.length) {
|
|
85
71
|
const serialized = await generateKeyForTuple(newPerm);
|
|
86
72
|
if (!seen.has(serialized)) {
|
|
@@ -95,10 +81,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
95
81
|
combinations = newCombinations;
|
|
96
82
|
}
|
|
97
83
|
return combinations;
|
|
98
|
-
}
|
|
84
|
+
};
|
|
99
85
|
|
|
100
86
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
101
|
-
var intraBoundwitnessSchemaCombinations =
|
|
87
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
102
88
|
const indexMap = {};
|
|
103
89
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
104
90
|
if (!indexMap[element]) {
|
|
@@ -106,19 +92,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
92
|
}
|
|
107
93
|
indexMap[element].push(index);
|
|
108
94
|
}
|
|
109
|
-
let uniqueCombinations = [
|
|
110
|
-
[]
|
|
111
|
-
];
|
|
95
|
+
let uniqueCombinations = [[]];
|
|
112
96
|
for (const element of schemas) {
|
|
113
97
|
const newCombinations = [];
|
|
114
98
|
const indices = indexMap[element] || [];
|
|
115
99
|
for (const combination of uniqueCombinations) {
|
|
116
100
|
for (const index of indices) {
|
|
117
101
|
if (!combination.includes(index)) {
|
|
118
|
-
const newCombination = [
|
|
119
|
-
...combination,
|
|
120
|
-
index
|
|
121
|
-
];
|
|
102
|
+
const newCombination = [...combination, index];
|
|
122
103
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
123
104
|
newCombinations.push(newCombination);
|
|
124
105
|
}
|
|
@@ -132,5 +113,5 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
132
113
|
return boundwitness.payload_hashes[index];
|
|
133
114
|
});
|
|
134
115
|
});
|
|
135
|
-
}
|
|
116
|
+
};
|
|
136
117
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;AACvB,iBAA2B;AAC3B,gCAA6C;AAC7C,6BAA+B;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAA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AI,UAAU,GAAG;AAEzB,iBAAK,IAAI,UAAU;AAEnB,4BAAgB,KAAK,OAAO;AAAA,UAC9B;AAAA,QACF,OAAO;AAEL,0BAAgB,KAAK,OAAO;AAAA,QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;;;ACxDO,IAAM,sCAAsC,CAAC,cAA4B,YAAgC;AAE9G,QAAM,WAAqC,CAAC;AAG5C,aAAW,CAAC,OAAO,OAAO,KAAK,aAAa,gBAAgB,QAAQ,GAAG;AACrE,QAAI,CAAC,SAAS,OAAO,GAAG;AACtB,eAAS,OAAO,IAAI,CAAC;AAAA,IACvB;AACA,aAAS,OAAO,EAAE,KAAK,KAAK;AAAA,EAC9B;AAGA,MAAI,qBAAqB,CAAC,CAAC,CAAC;AAG5B,aAAW,WAAW,SAAS;AAC7B,UAAM,kBAA8B,CAAC;AAErC,UAAM,UAAU,SAAS,OAAO,KAAK,CAAC;AAGtC,eAAW,eAAe,oBAAoB;AAE5C,iBAAW,SAAS,SAAS;AAE3B,YAAI,CAAC,YAAY,SAAS,KAAK,GAAG;AAChC,gBAAM,iBAAiB,CAAC,GAAG,aAAa,KAAK;AAE7C,cAAI,eAAe,WAAW,QAAQ,QAAQ,OAAO,IAAI,GAAG;AAC1D,4BAAgB,KAAK,cAAc;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,yBAAqB;AAAA,EACvB;AAEA,SAAO,mBAAmB,IAAI,CAAC,YAAY;AACzC,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,aAAa,eAAe,KAAK;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/browser/index.js
CHANGED
|
@@ -1,60 +1,44 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/combinationsByBoundwitness.ts
|
|
5
2
|
import { exists } from "@xylabs/exists";
|
|
6
3
|
import { difference } from "@xylabs/set";
|
|
7
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
8
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
var combinationsByBoundwitness =
|
|
6
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
10
7
|
const bws = new Set(payloads.filter(isBoundWitness));
|
|
11
8
|
const remaining = difference(new Set(payloads), bws);
|
|
12
|
-
const payloadDictionary = await PayloadBuilder.toDataHashMap([
|
|
13
|
-
...remaining
|
|
14
|
-
]);
|
|
9
|
+
const payloadDictionary = await PayloadBuilder.toDataHashMap([...remaining]);
|
|
15
10
|
const results = [];
|
|
16
11
|
for (const bw of bws) {
|
|
17
12
|
const { payload_hashes } = bw;
|
|
18
13
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists);
|
|
19
14
|
if (p.length === payload_hashes.length) {
|
|
20
|
-
const complete = [
|
|
21
|
-
bw,
|
|
22
|
-
...p
|
|
23
|
-
];
|
|
15
|
+
const complete = [bw, ...p];
|
|
24
16
|
results.push(complete);
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
return results;
|
|
28
|
-
}
|
|
20
|
+
};
|
|
29
21
|
|
|
30
22
|
// src/combinationsBySchema.ts
|
|
31
23
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
32
|
-
var generateKeyForTuple =
|
|
24
|
+
var generateKeyForTuple = async (payloads) => {
|
|
33
25
|
await Promise.resolve();
|
|
34
26
|
return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
|
|
35
|
-
}
|
|
36
|
-
var combinationsBySchema =
|
|
37
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
38
|
-
schema,
|
|
39
|
-
[]
|
|
40
|
-
]));
|
|
27
|
+
};
|
|
28
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
29
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
41
30
|
for (const payload of payloads) {
|
|
42
31
|
if (schemas.includes(payload.schema)) {
|
|
43
32
|
groupedPayloads[payload.schema].push(payload);
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
35
|
const seen = /* @__PURE__ */ new Set();
|
|
47
|
-
let combinations = [
|
|
48
|
-
[]
|
|
49
|
-
];
|
|
36
|
+
let combinations = [[]];
|
|
50
37
|
for (const schema of schemas) {
|
|
51
38
|
const newCombinations = [];
|
|
52
39
|
for (const combination of combinations) {
|
|
53
40
|
for (const payload of groupedPayloads[schema]) {
|
|
54
|
-
const newPerm = [
|
|
55
|
-
...combination,
|
|
56
|
-
payload
|
|
57
|
-
];
|
|
41
|
+
const newPerm = [...combination, payload];
|
|
58
42
|
if (newPerm.length === schemas.length) {
|
|
59
43
|
const serialized = await generateKeyForTuple(newPerm);
|
|
60
44
|
if (!seen.has(serialized)) {
|
|
@@ -69,10 +53,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
69
53
|
combinations = newCombinations;
|
|
70
54
|
}
|
|
71
55
|
return combinations;
|
|
72
|
-
}
|
|
56
|
+
};
|
|
73
57
|
|
|
74
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
75
|
-
var intraBoundwitnessSchemaCombinations =
|
|
59
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
76
60
|
const indexMap = {};
|
|
77
61
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
78
62
|
if (!indexMap[element]) {
|
|
@@ -80,19 +64,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
80
64
|
}
|
|
81
65
|
indexMap[element].push(index);
|
|
82
66
|
}
|
|
83
|
-
let uniqueCombinations = [
|
|
84
|
-
[]
|
|
85
|
-
];
|
|
67
|
+
let uniqueCombinations = [[]];
|
|
86
68
|
for (const element of schemas) {
|
|
87
69
|
const newCombinations = [];
|
|
88
70
|
const indices = indexMap[element] || [];
|
|
89
71
|
for (const combination of uniqueCombinations) {
|
|
90
72
|
for (const index of indices) {
|
|
91
73
|
if (!combination.includes(index)) {
|
|
92
|
-
const newCombination = [
|
|
93
|
-
...combination,
|
|
94
|
-
index
|
|
95
|
-
];
|
|
74
|
+
const newCombination = [...combination, index];
|
|
96
75
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
97
76
|
newCombinations.push(newCombination);
|
|
98
77
|
}
|
|
@@ -106,7 +85,7 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
85
|
return boundwitness.payload_hashes[index];
|
|
107
86
|
});
|
|
108
87
|
});
|
|
109
|
-
}
|
|
88
|
+
};
|
|
110
89
|
export {
|
|
111
90
|
combinationsByBoundwitness,
|
|
112
91
|
combinationsBySchema,
|
|
@@ -1 +1 @@
|
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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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CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/neutral/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ 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 });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,55 +31,42 @@ var import_exists = require("@xylabs/exists");
|
|
|
32
31
|
var import_set = require("@xylabs/set");
|
|
33
32
|
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
34
33
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
35
|
-
var combinationsByBoundwitness =
|
|
34
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
36
35
|
const bws = new Set(payloads.filter(import_boundwitness_model.isBoundWitness));
|
|
37
36
|
const remaining = (0, import_set.difference)(new Set(payloads), bws);
|
|
38
|
-
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([
|
|
39
|
-
...remaining
|
|
40
|
-
]);
|
|
37
|
+
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([...remaining]);
|
|
41
38
|
const results = [];
|
|
42
39
|
for (const bw of bws) {
|
|
43
40
|
const { payload_hashes } = bw;
|
|
44
41
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(import_exists.exists);
|
|
45
42
|
if (p.length === payload_hashes.length) {
|
|
46
|
-
const complete = [
|
|
47
|
-
bw,
|
|
48
|
-
...p
|
|
49
|
-
];
|
|
43
|
+
const complete = [bw, ...p];
|
|
50
44
|
results.push(complete);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
return results;
|
|
54
|
-
}
|
|
48
|
+
};
|
|
55
49
|
|
|
56
50
|
// src/combinationsBySchema.ts
|
|
57
51
|
var import_hash = require("@xyo-network/hash");
|
|
58
|
-
var generateKeyForTuple =
|
|
52
|
+
var generateKeyForTuple = async (payloads) => {
|
|
59
53
|
await Promise.resolve();
|
|
60
54
|
return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
|
|
61
|
-
}
|
|
62
|
-
var combinationsBySchema =
|
|
63
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
64
|
-
schema,
|
|
65
|
-
[]
|
|
66
|
-
]));
|
|
55
|
+
};
|
|
56
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
57
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
67
58
|
for (const payload of payloads) {
|
|
68
59
|
if (schemas.includes(payload.schema)) {
|
|
69
60
|
groupedPayloads[payload.schema].push(payload);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
const seen = /* @__PURE__ */ new Set();
|
|
73
|
-
let combinations = [
|
|
74
|
-
[]
|
|
75
|
-
];
|
|
64
|
+
let combinations = [[]];
|
|
76
65
|
for (const schema of schemas) {
|
|
77
66
|
const newCombinations = [];
|
|
78
67
|
for (const combination of combinations) {
|
|
79
68
|
for (const payload of groupedPayloads[schema]) {
|
|
80
|
-
const newPerm = [
|
|
81
|
-
...combination,
|
|
82
|
-
payload
|
|
83
|
-
];
|
|
69
|
+
const newPerm = [...combination, payload];
|
|
84
70
|
if (newPerm.length === schemas.length) {
|
|
85
71
|
const serialized = await generateKeyForTuple(newPerm);
|
|
86
72
|
if (!seen.has(serialized)) {
|
|
@@ -95,10 +81,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
95
81
|
combinations = newCombinations;
|
|
96
82
|
}
|
|
97
83
|
return combinations;
|
|
98
|
-
}
|
|
84
|
+
};
|
|
99
85
|
|
|
100
86
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
101
|
-
var intraBoundwitnessSchemaCombinations =
|
|
87
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
102
88
|
const indexMap = {};
|
|
103
89
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
104
90
|
if (!indexMap[element]) {
|
|
@@ -106,19 +92,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
92
|
}
|
|
107
93
|
indexMap[element].push(index);
|
|
108
94
|
}
|
|
109
|
-
let uniqueCombinations = [
|
|
110
|
-
[]
|
|
111
|
-
];
|
|
95
|
+
let uniqueCombinations = [[]];
|
|
112
96
|
for (const element of schemas) {
|
|
113
97
|
const newCombinations = [];
|
|
114
98
|
const indices = indexMap[element] || [];
|
|
115
99
|
for (const combination of uniqueCombinations) {
|
|
116
100
|
for (const index of indices) {
|
|
117
101
|
if (!combination.includes(index)) {
|
|
118
|
-
const newCombination = [
|
|
119
|
-
...combination,
|
|
120
|
-
index
|
|
121
|
-
];
|
|
102
|
+
const newCombination = [...combination, index];
|
|
122
103
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
123
104
|
newCombinations.push(newCombination);
|
|
124
105
|
}
|
|
@@ -132,5 +113,5 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
132
113
|
return boundwitness.payload_hashes[index];
|
|
133
114
|
});
|
|
134
115
|
});
|
|
135
|
-
}
|
|
116
|
+
};
|
|
136
117
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;AACvB,iBAA2B;AAC3B,gCAA6C;AAC7C,6BAA+B;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,wCAAc,CAAC;AACjE,QAAM,gBAAY,uBAAW,IAAI,IAAI,QAAQ,GAAG,GAAG;AACnD,QAAM,oBAAoB,MAAM,sCAAe,cAAc,CAAC,GAAG,SAAS,CAAC;AAC3E,QAAM,UAAU,CAAC;AACjB,aAAW,MAAM,KAAK;AACpB,UAAM,EAAE,eAAe,IAAI;AAC3B,UAAM,IAAI,eAAe,IAAI,CAAC,MAAM,kBAAkB,CAAC,CAAC,EAAE,OAAO,oBAAM;AACvE,QAAI,EAAE,WAAW,eAAe,QAAQ;AACtC,YAAM,WAAW,CAAC,IAAI,GAAG,CAAC;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B,eAAS,OAAO,IAAI,CAAC;AAAA,IACvB;AACA,aAAS,OAAO,EAAE,KAAK,KAAK;AAAA,EAC9B;AAGA,MAAI,qBAAqB,CAAC,CAAC,CAAC;AAG5B,aAAW,WAAW,SAAS;AAC7B,UAAM,kBAA8B,CAAC;AAErC,UAAM,UAAU,SAAS,OAAO,KAAK,CAAC;AAGtC,eAAW,eAAe,oBAAoB;AAE5C,iBAAW,SAAS,SAAS;AAE3B,YAAI,CAAC,YAAY,SAAS,KAAK,GAAG;AAChC,gBAAM,iBAAiB,CAAC,GAAG,aAAa,KAAK;AAE7C,cAAI,eAAe,WAAW,QAAQ,QAAQ,OAAO,IAAI,GAAG;AAC1D,4BAAgB,KAAK,cAAc;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,yBAAqB;AAAA,EACvB;AAEA,SAAO,mBAAmB,IAAI,CAAC,YAAY;AACzC,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,aAAa,eAAe,KAAK;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/neutral/index.js
CHANGED
|
@@ -1,60 +1,44 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/combinationsByBoundwitness.ts
|
|
5
2
|
import { exists } from "@xylabs/exists";
|
|
6
3
|
import { difference } from "@xylabs/set";
|
|
7
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
8
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
var combinationsByBoundwitness =
|
|
6
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
10
7
|
const bws = new Set(payloads.filter(isBoundWitness));
|
|
11
8
|
const remaining = difference(new Set(payloads), bws);
|
|
12
|
-
const payloadDictionary = await PayloadBuilder.toDataHashMap([
|
|
13
|
-
...remaining
|
|
14
|
-
]);
|
|
9
|
+
const payloadDictionary = await PayloadBuilder.toDataHashMap([...remaining]);
|
|
15
10
|
const results = [];
|
|
16
11
|
for (const bw of bws) {
|
|
17
12
|
const { payload_hashes } = bw;
|
|
18
13
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists);
|
|
19
14
|
if (p.length === payload_hashes.length) {
|
|
20
|
-
const complete = [
|
|
21
|
-
bw,
|
|
22
|
-
...p
|
|
23
|
-
];
|
|
15
|
+
const complete = [bw, ...p];
|
|
24
16
|
results.push(complete);
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
return results;
|
|
28
|
-
}
|
|
20
|
+
};
|
|
29
21
|
|
|
30
22
|
// src/combinationsBySchema.ts
|
|
31
23
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
32
|
-
var generateKeyForTuple =
|
|
24
|
+
var generateKeyForTuple = async (payloads) => {
|
|
33
25
|
await Promise.resolve();
|
|
34
26
|
return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
|
|
35
|
-
}
|
|
36
|
-
var combinationsBySchema =
|
|
37
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
38
|
-
schema,
|
|
39
|
-
[]
|
|
40
|
-
]));
|
|
27
|
+
};
|
|
28
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
29
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
41
30
|
for (const payload of payloads) {
|
|
42
31
|
if (schemas.includes(payload.schema)) {
|
|
43
32
|
groupedPayloads[payload.schema].push(payload);
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
35
|
const seen = /* @__PURE__ */ new Set();
|
|
47
|
-
let combinations = [
|
|
48
|
-
[]
|
|
49
|
-
];
|
|
36
|
+
let combinations = [[]];
|
|
50
37
|
for (const schema of schemas) {
|
|
51
38
|
const newCombinations = [];
|
|
52
39
|
for (const combination of combinations) {
|
|
53
40
|
for (const payload of groupedPayloads[schema]) {
|
|
54
|
-
const newPerm = [
|
|
55
|
-
...combination,
|
|
56
|
-
payload
|
|
57
|
-
];
|
|
41
|
+
const newPerm = [...combination, payload];
|
|
58
42
|
if (newPerm.length === schemas.length) {
|
|
59
43
|
const serialized = await generateKeyForTuple(newPerm);
|
|
60
44
|
if (!seen.has(serialized)) {
|
|
@@ -69,10 +53,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
69
53
|
combinations = newCombinations;
|
|
70
54
|
}
|
|
71
55
|
return combinations;
|
|
72
|
-
}
|
|
56
|
+
};
|
|
73
57
|
|
|
74
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
75
|
-
var intraBoundwitnessSchemaCombinations =
|
|
59
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
76
60
|
const indexMap = {};
|
|
77
61
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
78
62
|
if (!indexMap[element]) {
|
|
@@ -80,19 +64,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
80
64
|
}
|
|
81
65
|
indexMap[element].push(index);
|
|
82
66
|
}
|
|
83
|
-
let uniqueCombinations = [
|
|
84
|
-
[]
|
|
85
|
-
];
|
|
67
|
+
let uniqueCombinations = [[]];
|
|
86
68
|
for (const element of schemas) {
|
|
87
69
|
const newCombinations = [];
|
|
88
70
|
const indices = indexMap[element] || [];
|
|
89
71
|
for (const combination of uniqueCombinations) {
|
|
90
72
|
for (const index of indices) {
|
|
91
73
|
if (!combination.includes(index)) {
|
|
92
|
-
const newCombination = [
|
|
93
|
-
...combination,
|
|
94
|
-
index
|
|
95
|
-
];
|
|
74
|
+
const newCombination = [...combination, index];
|
|
96
75
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
97
76
|
newCombinations.push(newCombination);
|
|
98
77
|
}
|
|
@@ -106,7 +85,7 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
85
|
return boundwitness.payload_hashes[index];
|
|
107
86
|
});
|
|
108
87
|
});
|
|
109
|
-
}
|
|
88
|
+
};
|
|
110
89
|
export {
|
|
111
90
|
combinationsByBoundwitness,
|
|
112
91
|
combinationsBySchema,
|
|
@@ -1 +1 @@
|
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":";AAAA,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAuB,sBAAsB;AAC7C,SAAS,sBAAsB;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,cAAc,CAAC;AACjE,QAAM,YAAY,WAAW,IAAI,IAAI,QAAQ,GAAG,GAAG;AACnD,QAAM,oBAAoB,MAAM,eAAe,cAAc,CAAC,GAAG,SAAS,CAAC;AAC3E,QAAM,UAAU,CAAC;AACjB,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A,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;;;ACxDO,IAAM,sCAAsC,CAAC,cAA4B,YAAgC;AAE9G,QAAM,WAAqC,CAAC;AAG5C,aAAW,CAAC,OAAO,OAAO,KAAK,aAAa,gBAAgB,QAAQ,GAAG;AACrE,QAAI,CAAC,SAAS,OAAO,GAAG;AACtB,eAAS,OAAO,IAAI,CAAC;AAAA,IACvB;AACA,aAAS,OAAO,EAAE,KAAK,KAAK;AAAA,EAC9B;AAGA,MAAI,qBAAqB,CAAC,CAAC,CAAC;AAG5B,aAAW,WAAW,SAAS;AAC7B,UAAM,kBAA8B,CAAC;AAErC,UAAM,UAAU,SAAS,OAAO,KAAK,CAAC;AAGtC,eAAW,eAAe,oBAAoB;AAE5C,iBAAW,SAAS,SAAS;AAE3B,YAAI,CAAC,YAAY,SAAS,KAAK,GAAG;AAChC,gBAAM,iBAAiB,CAAC,GAAG,aAAa,KAAK;AAE7C,cAAI,eAAe,WAAW,QAAQ,QAAQ,OAAO,IAAI,GAAG;AAC1D,4BAAgB,KAAK,cAAc;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,yBAAqB;AAAA,EACvB;AAEA,SAAO,mBAAmB,IAAI,CAAC,YAAY;AACzC,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,aAAa,eAAe,KAAK;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/node/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ 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 });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -32,55 +31,42 @@ var import_exists = require("@xylabs/exists");
|
|
|
32
31
|
var import_set = require("@xylabs/set");
|
|
33
32
|
var import_boundwitness_model = require("@xyo-network/boundwitness-model");
|
|
34
33
|
var import_payload_builder = require("@xyo-network/payload-builder");
|
|
35
|
-
var combinationsByBoundwitness =
|
|
34
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
36
35
|
const bws = new Set(payloads.filter(import_boundwitness_model.isBoundWitness));
|
|
37
36
|
const remaining = (0, import_set.difference)(new Set(payloads), bws);
|
|
38
|
-
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([
|
|
39
|
-
...remaining
|
|
40
|
-
]);
|
|
37
|
+
const payloadDictionary = await import_payload_builder.PayloadBuilder.toDataHashMap([...remaining]);
|
|
41
38
|
const results = [];
|
|
42
39
|
for (const bw of bws) {
|
|
43
40
|
const { payload_hashes } = bw;
|
|
44
41
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(import_exists.exists);
|
|
45
42
|
if (p.length === payload_hashes.length) {
|
|
46
|
-
const complete = [
|
|
47
|
-
bw,
|
|
48
|
-
...p
|
|
49
|
-
];
|
|
43
|
+
const complete = [bw, ...p];
|
|
50
44
|
results.push(complete);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
return results;
|
|
54
|
-
}
|
|
48
|
+
};
|
|
55
49
|
|
|
56
50
|
// src/combinationsBySchema.ts
|
|
57
51
|
var import_hash = require("@xyo-network/hash");
|
|
58
|
-
var generateKeyForTuple =
|
|
52
|
+
var generateKeyForTuple = async (payloads) => {
|
|
59
53
|
await Promise.resolve();
|
|
60
54
|
return payloads.map((p) => import_hash.PayloadHasher.stringifyHashFields(p)).join("|");
|
|
61
|
-
}
|
|
62
|
-
var combinationsBySchema =
|
|
63
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
64
|
-
schema,
|
|
65
|
-
[]
|
|
66
|
-
]));
|
|
55
|
+
};
|
|
56
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
57
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
67
58
|
for (const payload of payloads) {
|
|
68
59
|
if (schemas.includes(payload.schema)) {
|
|
69
60
|
groupedPayloads[payload.schema].push(payload);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
const seen = /* @__PURE__ */ new Set();
|
|
73
|
-
let combinations = [
|
|
74
|
-
[]
|
|
75
|
-
];
|
|
64
|
+
let combinations = [[]];
|
|
76
65
|
for (const schema of schemas) {
|
|
77
66
|
const newCombinations = [];
|
|
78
67
|
for (const combination of combinations) {
|
|
79
68
|
for (const payload of groupedPayloads[schema]) {
|
|
80
|
-
const newPerm = [
|
|
81
|
-
...combination,
|
|
82
|
-
payload
|
|
83
|
-
];
|
|
69
|
+
const newPerm = [...combination, payload];
|
|
84
70
|
if (newPerm.length === schemas.length) {
|
|
85
71
|
const serialized = await generateKeyForTuple(newPerm);
|
|
86
72
|
if (!seen.has(serialized)) {
|
|
@@ -95,10 +81,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
95
81
|
combinations = newCombinations;
|
|
96
82
|
}
|
|
97
83
|
return combinations;
|
|
98
|
-
}
|
|
84
|
+
};
|
|
99
85
|
|
|
100
86
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
101
|
-
var intraBoundwitnessSchemaCombinations =
|
|
87
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
102
88
|
const indexMap = {};
|
|
103
89
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
104
90
|
if (!indexMap[element]) {
|
|
@@ -106,19 +92,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
92
|
}
|
|
107
93
|
indexMap[element].push(index);
|
|
108
94
|
}
|
|
109
|
-
let uniqueCombinations = [
|
|
110
|
-
[]
|
|
111
|
-
];
|
|
95
|
+
let uniqueCombinations = [[]];
|
|
112
96
|
for (const element of schemas) {
|
|
113
97
|
const newCombinations = [];
|
|
114
98
|
const indices = indexMap[element] || [];
|
|
115
99
|
for (const combination of uniqueCombinations) {
|
|
116
100
|
for (const index of indices) {
|
|
117
101
|
if (!combination.includes(index)) {
|
|
118
|
-
const newCombination = [
|
|
119
|
-
...combination,
|
|
120
|
-
index
|
|
121
|
-
];
|
|
102
|
+
const newCombination = [...combination, index];
|
|
122
103
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
123
104
|
newCombinations.push(newCombination);
|
|
124
105
|
}
|
|
@@ -132,7 +113,7 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
132
113
|
return boundwitness.payload_hashes[index];
|
|
133
114
|
});
|
|
134
115
|
});
|
|
135
|
-
}
|
|
116
|
+
};
|
|
136
117
|
// Annotate the CommonJS export names for ESM import in node:
|
|
137
118
|
0 && (module.exports = {
|
|
138
119
|
combinationsByBoundwitness,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["export * from './combinationsByBoundwitness.js'\nexport * from './combinationsBySchema.js'\nexport * from './intraBoundwitnessSchemaCombinations.js'\n","import { exists } from '@xylabs/exists'\nimport { difference } from '@xylabs/set'\nimport { BoundWitness, isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;AACvB,iBAA2B;AAC3B,gCAA6C;AAC7C,6BAA+B;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,wCAAc,CAAC;AACjE,QAAM,gBAAY,uBAAW,IAAI,IAAI,QAAQ,GAAG,GAAG;AACnD,QAAM,oBAAoB,MAAM,sCAAe,cAAc,CAAC,GAAG,SAAS,CAAC;AAC3E,QAAM,UAAU,CAAC;AACjB,aAAW,MAAM,KAAK;AACpB,UAAM,EAAE,eAAe,IAAI;AAC3B,UAAM,IAAI,eAAe,IAAI,CAAC,MAAM,kBAAkB,CAAC,CAAC,EAAE,OAAO,oBAAM;AACvE,QAAI,EAAE,WAAW,eAAe,QAAQ;AACtC,YAAM,WAAW,CAAC,IAAI,GAAG,CAAC;AAC1B,cAAQ,KAAK,QAAQ;AAAA,IACvB;AAAA,EACF;AACA,SAAO;AACT;;;AC1BA,kBAA8B;AAQ9B,IAAM,sBAAsB,OAAO,aAAyC;AAE1E,QAAM,QAAQ,QAAQ;AACtB,SAAO,SAAS,IAAI,CAAC,MAAM,0BAAc,oBAAoB,CAAC,CAAC,EAAE,KAAK,GAAG;AAC3E;AAQO,IAAM,uBAAuB,OAAO,UAAqB,YAA4C;AAE1G,QAAM,kBAA6C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,SAAS,KAAK,GAAG;AAChC,gBAAM,iBAAiB,CAAC,GAAG,aAAa,KAAK;AAE7C,cAAI,eAAe,WAAW,QAAQ,QAAQ,OAAO,IAAI,GAAG;AAC1D,4BAAgB,KAAK,cAAc;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,yBAAqB;AAAA,EACvB;AAEA,SAAO,mBAAmB,IAAI,CAAC,YAAY;AACzC,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,aAAa,eAAe,KAAK;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -1,60 +1,44 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/combinationsByBoundwitness.ts
|
|
5
2
|
import { exists } from "@xylabs/exists";
|
|
6
3
|
import { difference } from "@xylabs/set";
|
|
7
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
8
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
9
|
-
var combinationsByBoundwitness =
|
|
6
|
+
var combinationsByBoundwitness = async (payloads) => {
|
|
10
7
|
const bws = new Set(payloads.filter(isBoundWitness));
|
|
11
8
|
const remaining = difference(new Set(payloads), bws);
|
|
12
|
-
const payloadDictionary = await PayloadBuilder.toDataHashMap([
|
|
13
|
-
...remaining
|
|
14
|
-
]);
|
|
9
|
+
const payloadDictionary = await PayloadBuilder.toDataHashMap([...remaining]);
|
|
15
10
|
const results = [];
|
|
16
11
|
for (const bw of bws) {
|
|
17
12
|
const { payload_hashes } = bw;
|
|
18
13
|
const p = payload_hashes.map((h) => payloadDictionary[h]).filter(exists);
|
|
19
14
|
if (p.length === payload_hashes.length) {
|
|
20
|
-
const complete = [
|
|
21
|
-
bw,
|
|
22
|
-
...p
|
|
23
|
-
];
|
|
15
|
+
const complete = [bw, ...p];
|
|
24
16
|
results.push(complete);
|
|
25
17
|
}
|
|
26
18
|
}
|
|
27
19
|
return results;
|
|
28
|
-
}
|
|
20
|
+
};
|
|
29
21
|
|
|
30
22
|
// src/combinationsBySchema.ts
|
|
31
23
|
import { PayloadHasher } from "@xyo-network/hash";
|
|
32
|
-
var generateKeyForTuple =
|
|
24
|
+
var generateKeyForTuple = async (payloads) => {
|
|
33
25
|
await Promise.resolve();
|
|
34
26
|
return payloads.map((p) => PayloadHasher.stringifyHashFields(p)).join("|");
|
|
35
|
-
}
|
|
36
|
-
var combinationsBySchema =
|
|
37
|
-
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [
|
|
38
|
-
schema,
|
|
39
|
-
[]
|
|
40
|
-
]));
|
|
27
|
+
};
|
|
28
|
+
var combinationsBySchema = async (payloads, schemas) => {
|
|
29
|
+
const groupedPayloads = Object.fromEntries(schemas.map((schema) => [schema, []]));
|
|
41
30
|
for (const payload of payloads) {
|
|
42
31
|
if (schemas.includes(payload.schema)) {
|
|
43
32
|
groupedPayloads[payload.schema].push(payload);
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
35
|
const seen = /* @__PURE__ */ new Set();
|
|
47
|
-
let combinations = [
|
|
48
|
-
[]
|
|
49
|
-
];
|
|
36
|
+
let combinations = [[]];
|
|
50
37
|
for (const schema of schemas) {
|
|
51
38
|
const newCombinations = [];
|
|
52
39
|
for (const combination of combinations) {
|
|
53
40
|
for (const payload of groupedPayloads[schema]) {
|
|
54
|
-
const newPerm = [
|
|
55
|
-
...combination,
|
|
56
|
-
payload
|
|
57
|
-
];
|
|
41
|
+
const newPerm = [...combination, payload];
|
|
58
42
|
if (newPerm.length === schemas.length) {
|
|
59
43
|
const serialized = await generateKeyForTuple(newPerm);
|
|
60
44
|
if (!seen.has(serialized)) {
|
|
@@ -69,10 +53,10 @@ var combinationsBySchema = /* @__PURE__ */ __name(async (payloads, schemas) => {
|
|
|
69
53
|
combinations = newCombinations;
|
|
70
54
|
}
|
|
71
55
|
return combinations;
|
|
72
|
-
}
|
|
56
|
+
};
|
|
73
57
|
|
|
74
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
75
|
-
var intraBoundwitnessSchemaCombinations =
|
|
59
|
+
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
76
60
|
const indexMap = {};
|
|
77
61
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
78
62
|
if (!indexMap[element]) {
|
|
@@ -80,19 +64,14 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
80
64
|
}
|
|
81
65
|
indexMap[element].push(index);
|
|
82
66
|
}
|
|
83
|
-
let uniqueCombinations = [
|
|
84
|
-
[]
|
|
85
|
-
];
|
|
67
|
+
let uniqueCombinations = [[]];
|
|
86
68
|
for (const element of schemas) {
|
|
87
69
|
const newCombinations = [];
|
|
88
70
|
const indices = indexMap[element] || [];
|
|
89
71
|
for (const combination of uniqueCombinations) {
|
|
90
72
|
for (const index of indices) {
|
|
91
73
|
if (!combination.includes(index)) {
|
|
92
|
-
const newCombination = [
|
|
93
|
-
...combination,
|
|
94
|
-
index
|
|
95
|
-
];
|
|
74
|
+
const newCombination = [...combination, index];
|
|
96
75
|
if (newCombination.length === schemas.indexOf(element) + 1) {
|
|
97
76
|
newCombinations.push(newCombination);
|
|
98
77
|
}
|
|
@@ -106,7 +85,7 @@ var intraBoundwitnessSchemaCombinations = /* @__PURE__ */ __name((boundwitness,
|
|
|
106
85
|
return boundwitness.payload_hashes[index];
|
|
107
86
|
});
|
|
108
87
|
});
|
|
109
|
-
}
|
|
88
|
+
};
|
|
110
89
|
export {
|
|
111
90
|
combinationsByBoundwitness,
|
|
112
91
|
combinationsBySchema,
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":"
|
|
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 { PayloadBuilder } from '@xyo-network/payload-builder'\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 PayloadBuilder.toDataHashMap([...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) => PayloadBuilder.dataHash(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 { Hash } from '@xylabs/hex'\nimport { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { Schema } from '@xyo-network/payload-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: Schema[]): Hash[][] => {\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":";AAAA,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAuB,sBAAsB;AAC7C,SAAS,sBAAsB;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,cAAc,CAAC;AACjE,QAAM,YAAY,WAAW,IAAI,IAAI,QAAQ,GAAG,GAAG;AACnD,QAAM,oBAAoB,MAAM,eAAe,cAAc,CAAC,GAAG,SAAS,CAAC;AAC3E,QAAM,UAAU,CAAC;AACjB,aAAW,MAAM,KAAK;AACpB,UAAM,EAAE,eAAe,IAAI;AAC3B,UAAM,IAAI,eAAe,IAAI,CAAC,MAAM,kBAAkB,CAAC,CAAC,EAAE,OAAO,MAAM;AACvE,QAAI,EAAE,WAAW,eAAe,QAAQ;AACtC,YAAM,WAAW,CAAC,IAAI,GAAG,CAAC;AAC1B,cAAQ,KAAK,QAAQ;AAAA,IACvB;AAAA,EACF;AACA,SAAO;AACT;;;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AK,KAAK;AAAA,EAC9B;AAGA,MAAI,qBAAqB,CAAC,CAAC,CAAC;AAG5B,aAAW,WAAW,SAAS;AAC7B,UAAM,kBAA8B,CAAC;AAErC,UAAM,UAAU,SAAS,OAAO,KAAK,CAAC;AAGtC,eAAW,eAAe,oBAAoB;AAE5C,iBAAW,SAAS,SAAS;AAE3B,YAAI,CAAC,YAAY,SAAS,KAAK,GAAG;AAChC,gBAAM,iBAAiB,CAAC,GAAG,aAAa,KAAK;AAE7C,cAAI,eAAe,WAAW,QAAQ,QAAQ,OAAO,IAAI,GAAG;AAC1D,4BAAgB,KAAK,cAAc;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,yBAAqB;AAAA,EACvB;AAEA,SAAO,mBAAmB,IAAI,CAAC,YAAY;AACzC,WAAO,QAAQ,IAAI,CAAC,UAAU;AAC5B,aAAO,aAAa,eAAe,KAAK;AAAA,IAC1C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/exists": "^3.6.
|
|
14
|
-
"@xylabs/hex": "^3.6.
|
|
15
|
-
"@xylabs/set": "^3.6.
|
|
16
|
-
"@xyo-network/boundwitness-model": "^2.110.
|
|
17
|
-
"@xyo-network/hash": "^2.110.
|
|
18
|
-
"@xyo-network/payload-builder": "^2.110.
|
|
19
|
-
"@xyo-network/payload-model": "^2.110.
|
|
13
|
+
"@xylabs/exists": "^3.6.5",
|
|
14
|
+
"@xylabs/hex": "^3.6.5",
|
|
15
|
+
"@xylabs/set": "^3.6.5",
|
|
16
|
+
"@xyo-network/boundwitness-model": "^2.110.11",
|
|
17
|
+
"@xyo-network/hash": "^2.110.11",
|
|
18
|
+
"@xyo-network/payload-builder": "^2.110.11",
|
|
19
|
+
"@xyo-network/payload-model": "^2.110.11"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@xylabs/ts-scripts-yarn3": "^3.
|
|
23
|
-
"@xylabs/tsconfig": "^3.
|
|
24
|
-
"@xyo-network/boundwitness-builder": "^2.110.
|
|
22
|
+
"@xylabs/ts-scripts-yarn3": "^3.13.3",
|
|
23
|
+
"@xylabs/tsconfig": "^3.13.3",
|
|
24
|
+
"@xyo-network/boundwitness-builder": "^2.110.11",
|
|
25
25
|
"typescript": "^5.5.4"
|
|
26
26
|
},
|
|
27
27
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
@@ -63,6 +63,6 @@
|
|
|
63
63
|
},
|
|
64
64
|
"sideEffects": false,
|
|
65
65
|
"types": "dist/node/index.d.ts",
|
|
66
|
-
"version": "2.110.
|
|
66
|
+
"version": "2.110.11",
|
|
67
67
|
"type": "module"
|
|
68
68
|
}
|