@xyo-network/schema-cache 5.3.29 → 5.4.0

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/README.md CHANGED
@@ -38,234 +38,6 @@ bun add {{name}}
38
38
 
39
39
  See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
40
40
 
41
- ## Reference
42
-
43
- ### packages
44
-
45
- ### sdk-utils
46
-
47
- ### packages
48
-
49
- ### schema-cache
50
-
51
- ### .temp-typedoc
52
-
53
- ### classes
54
-
55
- ### <a id="Debounce"></a>Debounce
56
-
57
- [**@xyo-network/schema-cache**](#../README)
58
-
59
- ***
60
-
61
- ## Type Parameters
62
-
63
- ### TKey
64
-
65
- `TKey` = `string`
66
-
67
- ## Constructors
68
-
69
- ### Constructor
70
-
71
- ```ts
72
- new Debounce<TKey>(): Debounce<TKey>;
73
- ```
74
-
75
- ### Returns
76
-
77
- `Debounce`\<`TKey`\>
78
-
79
- ## Methods
80
-
81
- ### one()
82
-
83
- ```ts
84
- one<T>(
85
- key,
86
- closure,
87
- timeout?): Promise<T>;
88
- ```
89
-
90
- ### Type Parameters
91
-
92
- #### T
93
-
94
- `T`
95
-
96
- ### Parameters
97
-
98
- #### key
99
-
100
- `TKey`
101
-
102
- #### closure
103
-
104
- () => `Promise`\<`T`\>
105
-
106
- #### timeout?
107
-
108
- `number` = `10_000`
109
-
110
- ### Returns
111
-
112
- `Promise`\<`T`\>
113
-
114
- ### <a id="SchemaCache"></a>SchemaCache
115
-
116
- [**@xyo-network/schema-cache**](#../README)
117
-
118
- ***
119
-
120
- ## Type Parameters
121
-
122
- ### T
123
-
124
- `T` *extends* [`SchemaNameToValidatorMap`](#../interfaces/SchemaNameToValidatorMap) = [`SchemaNameToValidatorMap`](#../interfaces/SchemaNameToValidatorMap)
125
-
126
- ## Properties
127
-
128
- ### NULL
129
-
130
- ```ts
131
- protected readonly static NULL: SchemaCacheEntry;
132
- ```
133
-
134
- Object representing `null` since LRU Cache types
135
- only allow for types that derive from object
136
-
137
- ***
138
-
139
- ### onSchemaCached?
140
-
141
- ```ts
142
- optional onSchemaCached?: (name, entry) => void;
143
- ```
144
-
145
- ### Parameters
146
-
147
- #### name
148
-
149
- `string`
150
-
151
- #### entry
152
-
153
- [`SchemaCacheEntry`](#../type-aliases/SchemaCacheEntry)
154
-
155
- ### Returns
156
-
157
- `void`
158
-
159
- ***
160
-
161
- ### proxy?
162
-
163
- ```ts
164
- optional proxy?: string;
165
- ```
166
-
167
- ## Accessors
168
-
169
- ### instance
170
-
171
- ### Get Signature
172
-
173
- ```ts
174
- get static instance(): SchemaCache<SchemaNameToValidatorMap>;
175
- ```
176
-
177
- #### Returns
178
-
179
- `SchemaCache`\<[`SchemaNameToValidatorMap`](#../interfaces/SchemaNameToValidatorMap)\>
180
-
181
- ***
182
-
183
- ### validators
184
-
185
- ### Get Signature
186
-
187
- ```ts
188
- get validators(): T;
189
- ```
190
-
191
- A map of cached schema (by name) to payload validators for the schema. A schema
192
- must be cached via `get('schema.name')` before it's validator can be used as
193
- they are compiled dynamically at runtime upon retrieval.
194
-
195
- #### Returns
196
-
197
- `T`
198
-
199
- ## Methods
200
-
201
- ### get()
202
-
203
- ```ts
204
- get(schema?): Promise<
205
- | SchemaCacheEntry
206
- | null
207
- | undefined>;
208
- ```
209
-
210
- ### Parameters
211
-
212
- #### schema?
213
-
214
- `string`
215
-
216
- ### Returns
217
-
218
- `Promise`\<
219
- \| [`SchemaCacheEntry`](#../type-aliases/SchemaCacheEntry)
220
- \| `null`
221
- \| `undefined`\>
222
-
223
- ### interfaces
224
-
225
- ### <a id="SchemaNameToValidatorMap"></a>SchemaNameToValidatorMap
226
-
227
- [**@xyo-network/schema-cache**](#../README)
228
-
229
- ***
230
-
231
- Used to map known schemas (byt their string name) to the validators which assert their types
232
-
233
- ## Indexable
234
-
235
- ```ts
236
- [key: string]: ((x) => x is Payload) | undefined
237
- ```
238
-
239
- ### type-aliases
240
-
241
- ### <a id="NarrowPayload"></a>NarrowPayload
242
-
243
- [**@xyo-network/schema-cache**](#../README)
244
-
245
- ***
246
-
247
- ```ts
248
- type NarrowPayload<T> = ((x) => x is T) | undefined;
249
- ```
250
-
251
- Used in conjunction with schema validation to support compile time type assertion
252
- for known schema types.
253
-
254
- ## Type Parameters
255
-
256
- ### T
257
-
258
- `T` *extends* `Payload` = `Payload`
259
-
260
- ### <a id="SchemaCacheEntry"></a>SchemaCacheEntry
261
-
262
- [**@xyo-network/schema-cache**](#../README)
263
-
264
- ***
265
-
266
- ```ts
267
- type SchemaCacheEntry = FetchedPayload<SchemaPayload>;
268
- ```
269
41
 
270
42
 
271
43
  [logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaCache.d.ts","sourceRoot":"","sources":["../../src/SchemaCache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAQvE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAQ7E,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,CAAC,CAAA;AAE5D,qBAAa,WAAW,CAAC,CAAC,SAAS,wBAAwB,GAAG,wBAAwB;IACpF;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAwD;IAExG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAa;IAEtC,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAChE,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,OAAO,CAAC,MAAM,CAA2E;IACzF,OAAO,CAAC,WAAW,CAAa;IAGhC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO;IAIP,MAAM,KAAK,QAAQ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qB1B"}
@@ -21,6 +21,7 @@ var Debounce = class {
21
21
 
22
22
  // src/SchemaCache.ts
23
23
  import {
24
+ FetchClientError,
24
25
  handleError,
25
26
  isDefined as isDefined2,
26
27
  isString
@@ -28,7 +29,6 @@ import {
28
29
  import { DomainPayloadWrapper } from "@xyo-network/domain-payload-plugin";
29
30
  import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
30
31
  import { Ajv } from "ajv";
31
- import { isAxiosError } from "axios";
32
32
  import { LRUCache } from "lru-cache";
33
33
  var getSchemaNameFromSchema = (schema) => {
34
34
  if (isString(schema.$id)) {
@@ -105,8 +105,8 @@ var SchemaCache = class _SchemaCache {
105
105
  }
106
106
  } catch (error) {
107
107
  this._cache.set(schema, _SchemaCache.NULL);
108
- if (isAxiosError(error)) {
109
- console.log(`Axios Url: ${error.response?.config.url}`);
108
+ if (error instanceof FetchClientError) {
109
+ console.log(`Fetch Url: ${error.config.url}`);
110
110
  }
111
111
  handleError(error, (error2) => {
112
112
  console.error(`fetchSchema threw: ${error2.message}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay, isDefined } from '@xylabs/sdk-js'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10_000) {\n const startTime = Date.now()\n while (isDefined(this.map.get(key))) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw new Error(`Debounce timed out [${key}]`)\n }\n }\n try {\n this.map.set(key, 1)\n return await closure()\n } finally {\n this.map.set(key, 0)\n }\n }\n}\n","import {\n handleError, isDefined, isString,\n} from '@xylabs/sdk-js'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport type { FetchedPayload } from '@xyo-network/huri'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport type { SchemaObject } from 'ajv'\nimport { Ajv } from 'ajv'\nimport { isAxiosError } from 'axios'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce.ts'\nimport type { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap.ts'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (isString(schema.$id)) {\n return schema.$id\n }\n}\n\nexport type SchemaCacheEntry = FetchedPayload<SchemaPayload>\n\nexport class SchemaCache<T extends SchemaNameToValidatorMap = SchemaNameToValidatorMap> {\n /**\n * Object representing `null` since LRU Cache types\n * only allow for types that derive from object\n */\n protected static readonly NULL: SchemaCacheEntry = { payload: { definition: {}, schema: SchemaSchema } }\n\n private static _instance?: SchemaCache\n\n onSchemaCached?: (name: string, entry: SchemaCacheEntry) => void\n proxy?: string\n\n private _cache = new LRUCache<string, SchemaCacheEntry>({ max: 500, ttl: 1000 * 60 * 5 })\n private _validators: T = {} as T\n\n // prevents double discovery\n private getDebounce = new Debounce()\n\n private constructor(proxy?: string) {\n this.proxy = proxy\n }\n\n static get instance() {\n if (!this._instance) {\n this._instance = new SchemaCache()\n }\n return this._instance\n }\n\n /**\n * A map of cached schema (by name) to payload validators for the schema. A schema\n * must be cached via `get('schema.name')` before it's validator can be used as\n * they are compiled dynamically at runtime upon retrieval.\n */\n get validators(): T {\n return this._validators\n }\n\n async get(schema?: string): Promise<SchemaCacheEntry | undefined | null> {\n if (isString(schema)) {\n await this.getDebounce.one(schema, async () => {\n // If we've never looked for it before, it will be undefined\n if (this._cache.get(schema) === undefined) {\n await this.fetchSchema(schema)\n }\n })\n const value = this._cache.get(schema)\n return value === SchemaCache.NULL ? null : value\n }\n return undefined\n }\n\n private cacheSchemaIfValid(entry: SchemaCacheEntry) {\n // only store them if they match the schema root\n if (isDefined(entry?.payload?.definition)) {\n const ajv = new Ajv({ strict: false })\n // check if it is a valid schema def\n const validator = ajv.compile(entry.payload.definition)\n const schemaName = getSchemaNameFromSchema(entry.payload.definition)\n if (isString(schemaName)) {\n this._cache.set(schemaName, entry)\n const key = schemaName as keyof T\n this._validators[key] = validator as unknown as T[keyof T]\n this.onSchemaCached?.(schemaName, entry)\n }\n }\n }\n\n private cacheSchemas(aliasEntries?: FetchedPayload[] | null) {\n for (const entry of aliasEntries?.filter(entry => entry.payload.schema === SchemaSchema) ?? []) {\n this.cacheSchemaIfValid(entry as SchemaCacheEntry)\n }\n }\n\n private async fetchSchema(schema: string) {\n try {\n const domain = await DomainPayloadWrapper.discover(schema, this.proxy)\n await domain?.fetch()\n this.cacheSchemas(domain?.aliases)\n\n // if it is still undefined, mark it as null (not found)\n if (this._cache.get(schema) === undefined) {\n this._cache.set(schema, SchemaCache.NULL)\n }\n } catch (error) {\n // if failed, set it to NULL, TODO: Make an entry for an error to try again in the future?\n this._cache.set(schema, SchemaCache.NULL)\n if (isAxiosError(error)) {\n console.log(`Axios Url: ${error.response?.config.url}`)\n }\n handleError(error, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";AAAA,SAAS,OAAO,iBAAiB;AAE1B,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,IAAO,KAAW,SAA2B,UAAU,KAAQ;AACnE,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO,UAAU,KAAK,IAAI,IAAI,GAAG,CAAC,GAAG;AACnC,YAAM,MAAM,GAAG;AACf,UAAI,KAAK,IAAI,IAAI,YAAY,SAAS;AACpC,cAAM,IAAI,MAAM,uBAAuB,GAAG,GAAG;AAAA,MAC/C;AAAA,IACF;AACA,QAAI;AACF,WAAK,IAAI,IAAI,KAAK,CAAC;AACnB,aAAO,MAAM,QAAQ;AAAA,IACvB,UAAE;AACA,WAAK,IAAI,IAAI,KAAK,CAAC;AAAA,IACrB;AAAA,EACF;AACF;;;ACpBA;AAAA,EACE;AAAA,EAAa,aAAAA;AAAA,EAAW;AAAA,OACnB;AACP,SAAS,4BAA4B;AAGrC,SAAS,oBAAoB;AAE7B,S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,MAAM,QAAQ,UAAU;AACtD,YAAM,aAAa,wBAAwB,MAAM,QAAQ,UAAU;AACnE,UAAI,SAAS,UAAU,GAAG;AACxB,aAAK,OAAO,IAAI,YAAY,KAAK;AACjC,cAAM,MAAM;AACZ,aAAK,YAAY,GAAG,IAAI;AACxB,aAAK,iBAAiB,YAAY,KAAK;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,aAAa,cAAwC;AAC3D,eAAW,SAAS,cAAc,OAAO,CAAAC,WAASA,OAAM,QAAQ,WAAW,YAAY,KAAK,CAAC,GAAG;AAC9F,WAAK,mBAAmB,KAAyB;AAAA,IACnD;AAAA,EACF;AAAA,EAEA,MAAc,YAAY,QAAgB;AACxC,QAAI;AACF,YAAM,SAAS,MAAM,qBAAqB,SAAS,QAAQ,KAAK,KAAK;AACrE,YAAM,QAAQ,MAAM;AACpB,WAAK,aAAa,QAAQ,OAAO;AAGjC,UAAI,KAAK,OAAO,IAAI,MAAM,MAAM,QAAW;AACzC,aAAK,OAAO,IAAI,QAAQ,aAAY,IAAI;AAAA,MAC1C;AAAA,IACF,SAAS,OAAO;AAEd,WAAK,OAAO,IAAI,QAAQ,aAAY,IAAI;AACxC,UAAI,aAAa,KAAK,GAAG;AACvB,gBAAQ,IAAI,cAAc,MAAM,UAAU,OAAO,GAAG,EAAE;AAAA,MACxD;AACA,kBAAY,OAAO,CAACC,WAAU;AAC5B,gBAAQ,MAAM,sBAAsBA,OAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["isDefined","isDefined","entry","error"]}
1
+ {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay, isDefined } from '@xylabs/sdk-js'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10_000) {\n const startTime = Date.now()\n while (isDefined(this.map.get(key))) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw new Error(`Debounce timed out [${key}]`)\n }\n }\n try {\n this.map.set(key, 1)\n return await closure()\n } finally {\n this.map.set(key, 0)\n }\n }\n}\n","import {\n FetchClientError,\n handleError, isDefined, isString,\n} from '@xylabs/sdk-js'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport type { FetchedPayload } from '@xyo-network/huri'\nimport type { SchemaPayload } from '@xyo-network/schema-payload-plugin'\nimport { SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport type { SchemaObject } from 'ajv'\nimport { Ajv } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce.ts'\nimport type { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap.ts'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (isString(schema.$id)) {\n return schema.$id\n }\n}\n\nexport type SchemaCacheEntry = FetchedPayload<SchemaPayload>\n\nexport class SchemaCache<T extends SchemaNameToValidatorMap = SchemaNameToValidatorMap> {\n /**\n * Object representing `null` since LRU Cache types\n * only allow for types that derive from object\n */\n protected static readonly NULL: SchemaCacheEntry = { payload: { definition: {}, schema: SchemaSchema } }\n\n private static _instance?: SchemaCache\n\n onSchemaCached?: (name: string, entry: SchemaCacheEntry) => void\n proxy?: string\n\n private _cache = new LRUCache<string, SchemaCacheEntry>({ max: 500, ttl: 1000 * 60 * 5 })\n private _validators: T = {} as T\n\n // prevents double discovery\n private getDebounce = new Debounce()\n\n private constructor(proxy?: string) {\n this.proxy = proxy\n }\n\n static get instance() {\n if (!this._instance) {\n this._instance = new SchemaCache()\n }\n return this._instance\n }\n\n /**\n * A map of cached schema (by name) to payload validators for the schema. A schema\n * must be cached via `get('schema.name')` before it's validator can be used as\n * they are compiled dynamically at runtime upon retrieval.\n */\n get validators(): T {\n return this._validators\n }\n\n async get(schema?: string): Promise<SchemaCacheEntry | undefined | null> {\n if (isString(schema)) {\n await this.getDebounce.one(schema, async () => {\n // If we've never looked for it before, it will be undefined\n if (this._cache.get(schema) === undefined) {\n await this.fetchSchema(schema)\n }\n })\n const value = this._cache.get(schema)\n return value === SchemaCache.NULL ? null : value\n }\n return undefined\n }\n\n private cacheSchemaIfValid(entry: SchemaCacheEntry) {\n // only store them if they match the schema root\n if (isDefined(entry?.payload?.definition)) {\n const ajv = new Ajv({ strict: false })\n // check if it is a valid schema def\n const validator = ajv.compile(entry.payload.definition)\n const schemaName = getSchemaNameFromSchema(entry.payload.definition)\n if (isString(schemaName)) {\n this._cache.set(schemaName, entry)\n const key = schemaName as keyof T\n this._validators[key] = validator as unknown as T[keyof T]\n this.onSchemaCached?.(schemaName, entry)\n }\n }\n }\n\n private cacheSchemas(aliasEntries?: FetchedPayload[] | null) {\n for (const entry of aliasEntries?.filter(entry => entry.payload.schema === SchemaSchema) ?? []) {\n this.cacheSchemaIfValid(entry as SchemaCacheEntry)\n }\n }\n\n private async fetchSchema(schema: string) {\n try {\n const domain = await DomainPayloadWrapper.discover(schema, this.proxy)\n await domain?.fetch()\n this.cacheSchemas(domain?.aliases)\n\n // if it is still undefined, mark it as null (not found)\n if (this._cache.get(schema) === undefined) {\n this._cache.set(schema, SchemaCache.NULL)\n }\n } catch (error) {\n // if failed, set it to NULL, TODO: Make an entry for an error to try again in the future?\n this._cache.set(schema, SchemaCache.NULL)\n if (error instanceof FetchClientError) {\n console.log(`Fetch Url: ${error.config.url}`)\n }\n handleError(error, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";AAAA,SAAS,OAAO,iBAAiB;AAE1B,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,IAAO,KAAW,SAA2B,UAAU,KAAQ;AACnE,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO,UAAU,KAAK,IAAI,IAAI,GAAG,CAAC,GAAG;AACnC,YAAM,MAAM,GAAG;AACf,UAAI,KAAK,IAAI,IAAI,YAAY,SAAS;AACpC,cAAM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MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["isDefined","isDefined","entry","error"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/schema-cache",
3
- "version": "5.3.29",
3
+ "version": "5.4.0",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -22,12 +22,10 @@
22
22
  "exports": {
23
23
  ".": {
24
24
  "types": "./dist/neutral/index.d.ts",
25
- "import": "./dist/neutral/index.mjs",
26
25
  "default": "./dist/neutral/index.mjs"
27
26
  },
28
27
  "./package.json": "./package.json"
29
28
  },
30
- "types": "dist/neutral/index.d.ts",
31
29
  "files": [
32
30
  "dist",
33
31
  "!**/*.bench.*",
@@ -36,49 +34,47 @@
36
34
  "README.md"
37
35
  ],
38
36
  "dependencies": {
39
- "@xyo-network/payload-model": "~5.3.29",
40
- "@xyo-network/schema-payload-plugin": "~5.3.29"
37
+ "@xyo-network/payload-model": "~5.4.0",
38
+ "@xyo-network/schema-payload-plugin": "~5.4.0"
41
39
  },
42
40
  "devDependencies": {
43
41
  "@opentelemetry/api": "^1.9.1",
44
- "@types/node": "^25.5.2",
45
- "@xylabs/sdk-js": "^5.0.95",
46
- "@xylabs/ts-scripts-common": "~7.8.4",
47
- "@xylabs/ts-scripts-pnpm": "~7.8.4",
48
- "@xylabs/tsconfig-dom": "~7.8.4",
49
- "@xylabs/vitest-extended": "~5.0.95",
50
- "@xylabs/vitest-matchers": "~5.0.95",
42
+ "@types/node": "^25.6.0",
43
+ "@xylabs/sdk-js": "^5.0.97",
44
+ "@xylabs/toolchain": "~7.10.8",
45
+ "@xylabs/tsconfig": "~7.10.8",
46
+ "@xylabs/tsconfig-dom": "~7.10.8",
47
+ "@xylabs/vitest-extended": "~5.0.97",
48
+ "@xylabs/vitest-matchers": "~5.0.97",
51
49
  "ajv": "^8.18.0",
52
- "axios": "^1.14.0",
53
50
  "esbuild": "^0.28.0",
54
51
  "ethers": "^6.16.0",
55
- "lru-cache": "^11.3.1",
52
+ "lru-cache": "^11.3.5",
56
53
  "pako": "~2.1.0",
57
54
  "typescript": "~5.9.3",
58
- "vite": "^8.0.5",
59
- "vitest": "~4.1.2",
55
+ "vite": "^8.0.8",
56
+ "vitest": "~4.1.4",
60
57
  "zod": "^4.3.6",
61
- "@xyo-network/data": "~5.3.29",
62
- "@xyo-network/account-model": "~5.3.29",
63
- "@xyo-network/network": "~5.3.29",
64
- "@xyo-network/domain-payload-plugin": "~5.3.29",
65
- "@xyo-network/payload-builder": "~5.3.29",
66
- "@xyo-network/huri": "~5.3.29",
67
- "@xyo-network/payload-validator": "~5.3.29",
68
- "@xyo-network/dns": "~5.3.29",
69
- "@xyo-network/elliptic": "~5.3.29",
70
- "@xyo-network/previous-hash-store-model": "~5.3.29",
71
- "@xyo-network/hash": "~5.3.29",
72
- "@xyo-network/wasm": "~5.3.29"
58
+ "@xyo-network/account-model": "~5.4.0",
59
+ "@xyo-network/dns": "~5.4.0",
60
+ "@xyo-network/domain-payload-plugin": "~5.4.0",
61
+ "@xyo-network/data": "~5.4.0",
62
+ "@xyo-network/elliptic": "~5.4.0",
63
+ "@xyo-network/huri": "~5.4.0",
64
+ "@xyo-network/hash": "~5.4.0",
65
+ "@xyo-network/payload-builder": "~5.4.0",
66
+ "@xyo-network/network": "~5.4.0",
67
+ "@xyo-network/payload-validator": "~5.4.0",
68
+ "@xyo-network/previous-hash-store-model": "~5.4.0",
69
+ "@xyo-network/wasm": "~5.4.0"
73
70
  },
74
71
  "peerDependencies": {
75
- "@xylabs/sdk-js": "^5",
72
+ "@xylabs/sdk-js": "^5.0.97",
73
+ "@xyo-network/domain-payload-plugin": "~5.4",
74
+ "@xyo-network/huri": "~5.4",
75
+ "@xyo-network/payload-validator": "~5.4",
76
76
  "ajv": "^8",
77
- "axios": "^1",
78
- "lru-cache": "^11",
79
- "@xyo-network/domain-payload-plugin": "~5.3.29",
80
- "@xyo-network/huri": "~5.3.29",
81
- "@xyo-network/payload-validator": "~5.3.29"
77
+ "lru-cache": "^11.3.5"
82
78
  },
83
79
  "publishConfig": {
84
80
  "access": "public"