@xyo-network/boundwitness-loader 5.3.20 → 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/boundwitness-loader",
3
- "version": "5.3.20",
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,31 +30,49 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@xyo-network/archivist-memory": "~5.3.20",
40
- "@xyo-network/archivist-model": "~5.3.20",
41
- "@xyo-network/boundwitness-model": "~5.3.20",
42
- "@xyo-network/huri": "~5.3.20",
43
- "@xyo-network/payload-model": "~5.3.20",
44
- "async-mutex": "~0.5.0"
39
+ "async-mutex": "~0.5.0",
40
+ "@xyo-network/archivist-memory": "~5.3.24",
41
+ "@xyo-network/boundwitness-model": "~5.3.24",
42
+ "@xyo-network/archivist-model": "~5.3.24",
43
+ "@xyo-network/payload-model": "~5.3.24",
44
+ "@xyo-network/huri": "~5.3.24"
45
45
  },
46
46
  "devDependencies": {
47
- "@xylabs/sdk-js": "^5.0.90",
48
- "@xylabs/tsconfig": "~7.5.6",
47
+ "@opentelemetry/api": "^1.9.1",
48
+ "@types/node": "^25.5.0",
49
+ "@xylabs/sdk-js": "^5.0.93",
50
+ "@xylabs/ts-scripts-common": "~7.6.16",
51
+ "@xylabs/ts-scripts-pnpm": "~7.6.16",
52
+ "@xylabs/tsconfig": "~7.6.16",
53
+ "acorn": "^8.16.0",
54
+ "async-mutex": "~0.5.0",
55
+ "axios": "^1.14.0",
56
+ "esbuild": "^0.28.0",
57
+ "ethers": "^6.16.0",
58
+ "tslib": "^2.8.1",
49
59
  "typescript": "~5.9.3",
60
+ "vite": "^8.0.3",
50
61
  "vitest": "~4.1.2",
51
- "zod": "^4.3.6"
62
+ "zod": "^4.3.6",
63
+ "@xyo-network/archivist-memory": "~5.3.24",
64
+ "@xyo-network/archivist-model": "~5.3.24",
65
+ "@xyo-network/boundwitness-model": "~5.3.24",
66
+ "@xyo-network/huri": "~5.3.24",
67
+ "@xyo-network/payload-model": "~5.3.24"
52
68
  },
53
69
  "peerDependencies": {
54
70
  "@xylabs/sdk-js": "^5",
71
+ "ethers": "^6",
72
+ "tslib": "^2.8.1",
55
73
  "zod": "^4"
56
74
  },
57
75
  "publishConfig": {
58
76
  "access": "public"
59
77
  }
60
- }
78
+ }
package/src/Loader.ts DELETED
@@ -1,69 +0,0 @@
1
- import type { BaseParams, Hash } from '@xylabs/sdk-js'
2
- import { Base, exists } from '@xylabs/sdk-js'
3
- import { MemoryArchivist } from '@xyo-network/archivist-memory'
4
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
5
- import { asBoundWitness } from '@xyo-network/boundwitness-model'
6
- import { Huri } from '@xyo-network/huri'
7
- import type { Payload } from '@xyo-network/payload-model'
8
- import { isAnyPayload } from '@xyo-network/payload-model'
9
- import { Mutex } from 'async-mutex'
10
-
11
- export interface PayloadWorkingSet {
12
- archivists?: ArchivistInstance[]
13
- huriEndpoints?: string[]
14
- payloads?: Payload[]
15
- }
16
-
17
- export interface BoundWitnessLoaderParams extends BaseParams {
18
- cache?: ArchivistInstance
19
- workingSet: PayloadWorkingSet
20
- }
21
-
22
- export class BoundWitnessLoader extends Base<BoundWitnessLoaderParams> {
23
- private _cache?: ArchivistInstance
24
- private _createCacheMutex = new Mutex()
25
-
26
- async load(hash: Hash | Hash[]): Promise<Payload[]> {
27
- if (Array.isArray(hash)) {
28
- return (await Promise.all(hash.map(h => this.load(h)))).flat()
29
- }
30
- const bw = asBoundWitness(await this.getPayload(hash))
31
- if (bw) {
32
- const payloads = (await Promise.all(bw.payload_hashes.map(hash => this.getPayload(hash)))).filter(exists)
33
- return [bw, ...payloads]
34
- }
35
- return []
36
- }
37
-
38
- private async getCache() {
39
- return await this._createCacheMutex.runExclusive(async () => {
40
- this._cache = this._cache ?? this.params.cache ?? (await MemoryArchivist.create({ account: 'random' }))
41
- if (this.params.workingSet.payloads) await this._cache.insert(this.params.workingSet.payloads)
42
- return this._cache
43
- })
44
- }
45
-
46
- private async getPayload(hash: Hash): Promise<Payload | undefined> {
47
- const cache = await this.getCache()
48
- const payloadFromCache = (await cache.get([hash])).at(0)
49
- if (isAnyPayload(payloadFromCache)) {
50
- return payloadFromCache
51
- }
52
-
53
- for (const archivist of this.params.workingSet.archivists ?? []) {
54
- const payloadFromArchivist = await archivist.get([hash])
55
- if (isAnyPayload(payloadFromArchivist)) {
56
- await cache.insert([payloadFromArchivist])
57
- return payloadFromArchivist
58
- }
59
- }
60
-
61
- for (const huriEndpoint of this.params.workingSet.huriEndpoints ?? []) {
62
- const payloadFromHuri = await new Huri(hash, { archivistUri: huriEndpoint }).fetch()
63
- if (isAnyPayload(payloadFromHuri)) {
64
- await cache.insert([payloadFromHuri])
65
- return payloadFromHuri
66
- }
67
- }
68
- }
69
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './Loader.ts'