@xyo-network/payload-utils 5.3.22 → 5.3.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/payload-utils",
3
- "version": "5.3.22",
3
+ "version": "5.3.24",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,40 +30,36 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
35
  "!**/*.test.*",
37
36
  "README.md"
38
37
  ],
39
38
  "dependencies": {
40
- "@xyo-network/boundwitness-model": "~5.3.22",
41
- "@xyo-network/hash": "~5.3.22",
42
- "@xyo-network/payload-builder": "~5.3.22",
43
- "@xyo-network/payload-model": "~5.3.22"
39
+ "@xyo-network/boundwitness-model": "~5.3.24",
40
+ "@xyo-network/hash": "~5.3.24",
41
+ "@xyo-network/payload-builder": "~5.3.24",
42
+ "@xyo-network/payload-model": "~5.3.24"
44
43
  },
45
44
  "devDependencies": {
46
45
  "@opentelemetry/api": "^1.9.1",
47
46
  "@types/node": "^25.5.0",
48
- "@xylabs/sdk-js": "^5.0.91",
49
- "@xylabs/ts-scripts-common": "~7.6.8",
50
- "@xylabs/ts-scripts-yarn3": "~7.6.8",
51
- "@xylabs/tsconfig": "~7.6.8",
52
- "@xylabs/vitest-extended": "~5.0.91",
53
- "@xyo-network/boundwitness-model": "~5.3.22",
54
- "@xyo-network/hash": "~5.3.22",
55
- "@xyo-network/payload-builder": "~5.3.22",
56
- "@xyo-network/payload-model": "~5.3.22",
47
+ "@xylabs/sdk-js": "^5.0.93",
48
+ "@xylabs/ts-scripts-common": "~7.6.16",
49
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
50
+ "@xylabs/tsconfig": "~7.6.16",
51
+ "@xylabs/vitest-extended": "~5.0.93",
57
52
  "acorn": "^8.16.0",
58
53
  "axios": "^1.14.0",
59
- "cosmiconfig": "^9.0.1",
60
- "esbuild": "^0.27.4",
61
- "eslint": "^10.1.0",
62
- "rollup": "^4.60.1",
54
+ "esbuild": "^0.28.0",
63
55
  "typescript": "~5.9.3",
64
56
  "vite": "^8.0.3",
65
57
  "vitest": "~4.1.2",
66
- "zod": "^4.3.6"
58
+ "zod": "^4.3.6",
59
+ "@xyo-network/boundwitness-model": "~5.3.24",
60
+ "@xyo-network/payload-builder": "~5.3.24",
61
+ "@xyo-network/hash": "~5.3.24",
62
+ "@xyo-network/payload-model": "~5.3.24"
67
63
  },
68
64
  "peerDependencies": {
69
65
  "@xylabs/sdk-js": "^5",
@@ -72,4 +68,4 @@
72
68
  "publishConfig": {
73
69
  "access": "public"
74
70
  }
75
- }
71
+ }
@@ -1,29 +0,0 @@
1
- import {
2
- asHash, difference, exists,
3
- } from '@xylabs/sdk-js'
4
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
5
- import { isBoundWitness } from '@xyo-network/boundwitness-model'
6
- import { PayloadBuilder } from '@xyo-network/payload-builder'
7
- import type { Payload } from '@xyo-network/payload-model'
8
-
9
- /**
10
- * Returns tuples of bound witnesses and their payloads from the supplied payloads. Omits
11
- * bound witnesses where the payloads were not included in the supplied payloads.
12
- * @param payloads An array of bound witnesses and payloads
13
- * @returns An array of tuples of bound witnesses and their payloads
14
- */
15
- export const combinationsByBoundwitness = async (payloads: Payload[]): Promise<[BoundWitness, ...Payload[]][]> => {
16
- const bws = new Set<BoundWitness>(payloads.filter(x => isBoundWitness(x)))
17
- const remaining = difference(new Set(payloads), bws)
18
- const payloadDictionary = await PayloadBuilder.toHashMap([...remaining])
19
- const results = [] as [BoundWitness, ...Payload[]][]
20
- for (const bw of bws) {
21
- const { payload_hashes } = bw
22
- const p = payload_hashes.map(h => payloadDictionary[asHash(h, true)]).filter(exists)
23
- if (p.length === payload_hashes.length) {
24
- const complete = [bw, ...p] as [BoundWitness, ...Payload[]]
25
- results.push(complete)
26
- }
27
- }
28
- return results
29
- }
@@ -1,67 +0,0 @@
1
- import { ObjectHasher } from '@xyo-network/hash'
2
- import type { Payload } from '@xyo-network/payload-model'
3
-
4
- /**
5
- * Generates a unique key for a tuple of payloads
6
- * @param payloads An array of payloads
7
- * @returns A string that is a unique key for the payloads
8
- */
9
- const generateKeyForTuple = async (payloads: Payload[]): Promise<string> => {
10
- // return (await Promise.all(array.map((p) => PayloadBuilder.dataHash(p)))).join('|')
11
- await Promise.resolve() // Here to reserve the right to make this async
12
- return payloads.map(p => ObjectHasher.stringifyHashFields(p)).join('|')
13
- }
14
-
15
- /**
16
- * Returns the unique combinations of payloads for the given schemas
17
- * @param payloads An array of payloads
18
- * @param schemas An array of schemas
19
- * @returns An array of unique combinations of payloads
20
- */
21
- export const combinationsBySchema = async (payloads: Payload[], schemas: string[]): Promise<Payload[][]> => {
22
- // Group payloads by schema
23
- const groupedPayloads: Record<string, Payload[]> = Object.fromEntries(schemas.map(schema => [schema, []]))
24
- for (const payload of payloads) {
25
- if (schemas.includes(payload.schema)) {
26
- groupedPayloads[payload.schema].push(payload)
27
- }
28
- }
29
-
30
- // Set to track seen (serialized) combinations for uniqueness check
31
- const seen: Set<string> = new Set()
32
- // Start with an array containing an empty combination
33
- let combinations = [[]] as Payload[][]
34
-
35
- // Iterate over each schema
36
- for (const schema of schemas) {
37
- const newCombinations: Payload[][] = []
38
- // Iterate over existing combinations
39
- for (const combination of combinations) {
40
- // Iterate over payloads for the current schema
41
- for (const payload of groupedPayloads[schema]) {
42
- // Create a new combination by adding the current payload
43
- const newPerm = [...combination, payload]
44
- // Proceed with serialization only if the combination is complete
45
- if (newPerm.length === schemas.length) {
46
- // Serialize the new combination asynchronously
47
- const serialized = await generateKeyForTuple(newPerm)
48
- // Check if the serialized combination is unique
49
- if (!seen.has(serialized)) {
50
- // Add it to the set of seen combinations
51
- seen.add(serialized)
52
- // Add the new combination to the list of new combinations
53
- newCombinations.push(newPerm)
54
- }
55
- } else {
56
- // Add incomplete combinations to the list for further processing
57
- newCombinations.push(newPerm)
58
- }
59
- }
60
- }
61
- // Update the list of combinations for the next schema iteration
62
- combinations = newCombinations
63
- }
64
-
65
- // Return the unique combinations
66
- return combinations
67
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './combinationsByBoundwitness.ts'
2
- export * from './combinationsBySchema.ts'
3
- export * from './intraBoundwitnessSchemaCombinations.ts'
@@ -1,56 +0,0 @@
1
- import { asHash, type Hash } from '@xylabs/sdk-js'
2
- import type { BoundWitness } from '@xyo-network/boundwitness-model'
3
- import type { Schema } from '@xyo-network/payload-model'
4
-
5
- /**
6
- * Returns all the possible combinations of payloads for the supplied schemas within the bound witness
7
- * @param boundwitness The bound witness to search
8
- * @param schemas The schemas to search for unique combinations of
9
- * @returns The payload hashes corresponding to the unique combinations of the supplied schemas
10
- */
11
- export const intraBoundwitnessSchemaCombinations = (boundwitness: BoundWitness, schemas: Schema[]): Hash[][] => {
12
- // Map to store the indices of each element in the source array
13
- const indexMap: Record<string, number[]> = {}
14
-
15
- // Populate the index map with positions of each element
16
- for (const [index, element] of boundwitness.payload_schemas.entries()) {
17
- if (!indexMap[element]) {
18
- indexMap[element] = []
19
- }
20
- indexMap[element].push(index)
21
- }
22
-
23
- // Initialize an array to store unique combinations
24
- let uniqueCombinations = [[]] as number[][]
25
-
26
- // Iterate over each element in the target array
27
- for (const element of schemas) {
28
- const newCombinations: number[][] = []
29
- // Get the array of indices for the current element
30
- const indices = indexMap[element] || []
31
-
32
- // Iterate over existing combinations
33
- for (const combination of uniqueCombinations) {
34
- // Iterate over each index in the indices array
35
- for (const index of indices) {
36
- // Check if the index is already in the combination
37
- if (!combination.includes(index)) {
38
- const newCombination = [...combination, index]
39
- // Only add the new combination if its length matches the current target index
40
- if (newCombination.length === schemas.indexOf(element) + 1) {
41
- newCombinations.push(newCombination)
42
- }
43
- }
44
- }
45
- }
46
-
47
- // Update the unique combinations for the next iteration
48
- uniqueCombinations = newCombinations
49
- }
50
-
51
- return uniqueCombinations.map((indexes) => {
52
- return indexes.map((index) => {
53
- return asHash(boundwitness.payload_hashes[index], true)
54
- })
55
- })
56
- }