@xyo-network/payload-utils 5.2.18 → 5.2.19
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/combinationsByBoundwitness.d.ts.map +1 -1
- package/dist/browser/index.mjs +2 -3
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/intraBoundwitnessSchemaCombinations.d.ts +1 -1
- package/dist/browser/intraBoundwitnessSchemaCombinations.d.ts.map +1 -1
- package/dist/neutral/combinationsByBoundwitness.d.ts.map +1 -1
- package/dist/neutral/index.mjs +2 -3
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/intraBoundwitnessSchemaCombinations.d.ts +1 -1
- package/dist/neutral/intraBoundwitnessSchemaCombinations.d.ts.map +1 -1
- package/dist/node/combinationsByBoundwitness.d.ts.map +1 -1
- package/dist/node/index.mjs +2 -3
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/intraBoundwitnessSchemaCombinations.d.ts +1 -1
- package/dist/node/intraBoundwitnessSchemaCombinations.d.ts.map +1 -1
- package/package.json +12 -13
- package/src/combinationsByBoundwitness.ts +1 -2
- package/src/intraBoundwitnessSchemaCombinations.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAU,UAAU,OAAO,EAAE,KAAG,OAAO,CAAC,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/combinationsByBoundwitness.ts
|
|
2
|
-
import { exists } from "@xylabs/
|
|
3
|
-
import { asHash } from "@xylabs/hex";
|
|
2
|
+
import { asHash, exists } from "@xylabs/sdk-js";
|
|
4
3
|
import { difference } from "@xylabs/set";
|
|
5
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
6
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
@@ -57,7 +56,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
60
|
-
import { asHash as asHash2 } from "@xylabs/
|
|
59
|
+
import { asHash as asHash2 } from "@xylabs/sdk-js";
|
|
61
60
|
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
62
61
|
const indexMap = {};
|
|
63
62
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import { asHash, exists } from '@xylabs/sdk-js'\nimport { difference } from '@xylabs/set'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { 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(x => isBoundWitness(x)))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadBuilder.toHashMap([...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[asHash(h, true)]).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 { ObjectHasher } from '@xyo-network/hash'\nimport type { 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 => ObjectHasher.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 { asHash, type Hash } from '@xylabs/sdk-js'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type { 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 asHash(boundwitness.payload_hashes[index], true)\n })\n })\n}\n"],"mappings":";AAAA,SAAS,QAAQ,cAAc;AAC/B,SAAS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","names":["asHash"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,GAAI,cAAc,YAAY,EAAE,SAAS,MAAM,EAAE,KAAG,IAAI,EAAE,EA6CzG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAU,UAAU,OAAO,EAAE,KAAG,OAAO,CAAC,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/combinationsByBoundwitness.ts
|
|
2
|
-
import { exists } from "@xylabs/
|
|
3
|
-
import { asHash } from "@xylabs/hex";
|
|
2
|
+
import { asHash, exists } from "@xylabs/sdk-js";
|
|
4
3
|
import { difference } from "@xylabs/set";
|
|
5
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
6
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
@@ -57,7 +56,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
60
|
-
import { asHash as asHash2 } from "@xylabs/
|
|
59
|
+
import { asHash as asHash2 } from "@xylabs/sdk-js";
|
|
61
60
|
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
62
61
|
const indexMap = {};
|
|
63
62
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import { asHash, exists } from '@xylabs/sdk-js'\nimport { difference } from '@xylabs/set'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { 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(x => isBoundWitness(x)))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadBuilder.toHashMap([...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[asHash(h, true)]).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 { ObjectHasher } from '@xyo-network/hash'\nimport type { 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 => ObjectHasher.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 { asHash, type Hash } from '@xylabs/sdk-js'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type { 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 asHash(boundwitness.payload_hashes[index], true)\n })\n })\n}\n"],"mappings":";AAAA,SAAS,QAAQ,cAAc;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,OAAK,eAAe,CAAC,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U,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;;;AClEA,SAAS,UAAAA,eAAyB;AAU3B,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,aAAOA,QAAO,aAAa,eAAe,KAAK,GAAG,IAAI;AAAA,IACxD,CAAC;AAAA,EACH,CAAC;AACH;","names":["asHash"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,GAAI,cAAc,YAAY,EAAE,SAAS,MAAM,EAAE,KAAG,IAAI,EAAE,EA6CzG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"combinationsByBoundwitness.d.ts","sourceRoot":"","sources":["../../src/combinationsByBoundwitness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEzD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAU,UAAU,OAAO,EAAE,KAAG,OAAO,CAAC,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,EAAE,CAc5G,CAAA"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/combinationsByBoundwitness.ts
|
|
2
|
-
import { exists } from "@xylabs/
|
|
3
|
-
import { asHash } from "@xylabs/hex";
|
|
2
|
+
import { asHash, exists } from "@xylabs/sdk-js";
|
|
4
3
|
import { difference } from "@xylabs/set";
|
|
5
4
|
import { isBoundWitness } from "@xyo-network/boundwitness-model";
|
|
6
5
|
import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
@@ -57,7 +56,7 @@ var combinationsBySchema = async (payloads, schemas) => {
|
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
// src/intraBoundwitnessSchemaCombinations.ts
|
|
60
|
-
import { asHash as asHash2 } from "@xylabs/
|
|
59
|
+
import { asHash as asHash2 } from "@xylabs/sdk-js";
|
|
61
60
|
var intraBoundwitnessSchemaCombinations = (boundwitness, schemas) => {
|
|
62
61
|
const indexMap = {};
|
|
63
62
|
for (const [index, element] of boundwitness.payload_schemas.entries()) {
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/combinationsByBoundwitness.ts","../../src/combinationsBySchema.ts","../../src/intraBoundwitnessSchemaCombinations.ts"],"sourcesContent":["import { asHash, exists } from '@xylabs/sdk-js'\nimport { difference } from '@xylabs/set'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { isBoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { 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(x => isBoundWitness(x)))\n const remaining = difference(new Set(payloads), bws)\n const payloadDictionary = await PayloadBuilder.toHashMap([...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[asHash(h, true)]).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 { ObjectHasher } from '@xyo-network/hash'\nimport type { 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 => ObjectHasher.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 { asHash, type Hash } from '@xylabs/sdk-js'\nimport type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport type { 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 asHash(boundwitness.payload_hashes[index], true)\n })\n })\n}\n"],"mappings":";AAAA,SAAS,QAAQ,cAAc;AAC/B,SAAS,kBAAkB;AAE3B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AASxB,IAAM,6BAA6B,OAAO,aAAiE;AAChH,QAAM,MAAM,IAAI,IAAkB,SAAS,OAAO,OAAK,eAAe,CAAC,CAAC,CAAC;AACzE,QAAM,YAAY,WAAW,IAAI,IAAI,QAAQ,GAAG,GAAG;AACnD,QAAM,oBAAoB,MAAM,eAAe,UAAU,CAAC,GAAG,SAAS,C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QAC9B;AAAA,MACF;AAAA,IACF;AAEA,mBAAe;AAAA,EACjB;AAGA,SAAO;AACT;;;AClEA,SAAS,UAAAA,eAAyB;AAU3B,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,aAAOA,QAAO,aAAa,eAAe,KAAK,GAAG,IAAI;AAAA,IACxD,CAAC;AAAA,EACH,CAAC;AACH;","names":["asHash"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"intraBoundwitnessSchemaCombinations.d.ts","sourceRoot":"","sources":["../../src/intraBoundwitnessSchemaCombinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,GAAI,cAAc,YAAY,EAAE,SAAS,MAAM,EAAE,KAAG,IAAI,EAAE,EA6CzG,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/payload-utils",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.19",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -36,21 +36,20 @@
|
|
|
36
36
|
"!**/*.test.*"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@xylabs/
|
|
40
|
-
"@xylabs/
|
|
41
|
-
"@
|
|
42
|
-
"@xyo-network/
|
|
43
|
-
"@xyo-network/
|
|
44
|
-
"@xyo-network/payload-
|
|
45
|
-
"@xyo-network/payload-model": "~5.2.18"
|
|
39
|
+
"@xylabs/sdk-js": "~5.0.61",
|
|
40
|
+
"@xylabs/set": "~5.0.61",
|
|
41
|
+
"@xyo-network/boundwitness-model": "~5.2.19",
|
|
42
|
+
"@xyo-network/hash": "~5.2.19",
|
|
43
|
+
"@xyo-network/payload-builder": "~5.2.19",
|
|
44
|
+
"@xyo-network/payload-model": "~5.2.19"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@xylabs/ts-scripts-yarn3": "~7.2.
|
|
49
|
-
"@xylabs/tsconfig": "~7.2.
|
|
50
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
51
|
-
"@xyo-network/boundwitness-builder": "~5.2.
|
|
47
|
+
"@xylabs/ts-scripts-yarn3": "~7.2.32",
|
|
48
|
+
"@xylabs/tsconfig": "~7.2.32",
|
|
49
|
+
"@xylabs/vitest-extended": "~5.0.61",
|
|
50
|
+
"@xyo-network/boundwitness-builder": "~5.2.19",
|
|
52
51
|
"typescript": "~5.9.3",
|
|
53
|
-
"vitest": "~4.0.
|
|
52
|
+
"vitest": "~4.0.16"
|
|
54
53
|
},
|
|
55
54
|
"publishConfig": {
|
|
56
55
|
"access": "public"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { exists } from '@xylabs/
|
|
2
|
-
import { asHash } from '@xylabs/hex'
|
|
1
|
+
import { asHash, exists } from '@xylabs/sdk-js'
|
|
3
2
|
import { difference } from '@xylabs/set'
|
|
4
3
|
import type { BoundWitness } from '@xyo-network/boundwitness-model'
|
|
5
4
|
import { isBoundWitness } from '@xyo-network/boundwitness-model'
|