@xyo-network/schema-cache 2.79.4 → 2.79.5

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.
@@ -57,11 +57,11 @@ var Debounce = class {
57
57
  };
58
58
 
59
59
  // src/SchemaCache.ts
60
- var import_axios = require("@xyo-network/axios");
60
+ var import_axios = require("@xylabs/axios");
61
+ var import_error = require("@xylabs/error");
61
62
  var import_domain_payload_plugin = require("@xyo-network/domain-payload-plugin");
62
- var import_error = require("@xyo-network/error");
63
63
  var import_schema_payload_plugin = require("@xyo-network/schema-payload-plugin");
64
- var import_ajv = __toESM(require("ajv"));
64
+ var import_ajv = __toESM(require("ajv"), 1);
65
65
  var import_lru_cache = require("lru-cache");
66
66
  var getSchemaNameFromSchema = (schema) => {
67
67
  if (schema.$id) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["export * from './Debounce'\nexport * from './SchemaCache'\nexport * from './SchemaNameToValidatorMap'\n","import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xyo-network/axios'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { handleError } from '@xyo-network/error'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAsB;AAEf,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,IAAO,KAAW,SAA2B,UAAU,KAAO;AAClE,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO,KAAK,IAAI,IAAI,GAAG,GAAG;AACxB,gBAAM,oBAAM,GAAG;AACf,UAAI,KAAK,IAAI,IAAI,YAAY,SAAS;AACpC,cAAM,MAAM,uBAAuB,GAAG,GAAG;AAAA,MAC3C;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,mBAA6B;AAC7B,mCAAqC;AACrC,mBAA4B;AAE5B,mCAA4C;AAC5C,iBAAkC;AAClC,uBAAyB;AAKzB,IAAM,0BAA0B,CAAC,WAAyB;AACxD,MAAI,OAAO,KAAK;AACd,WAAO,OAAO;AAAA,EAChB;AACF;AAIO,IAAM,cAAN,MAAM,aAA2E;AAAA;AAAA;AAAA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ACF;AAAA,EACF;AAAA,EAEQ,aAAa,cAAwC;AAC3D,kBACI,OAAO,CAAC,UAAU,MAAM,QAAQ,WAAW,yCAAY,EACxD,QAAQ,CAAC,UAAU;AAClB,WAAK,mBAAmB,KAAyB;AAAA,IACnD,CAAC;AAAA,EACL;AAAA,EAEA,MAAc,YAAY,QAAgB;AACxC,QAAI;AACF,YAAM,SAAS,MAAM,kDAAqB,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,IAAI;AAEX,WAAK,OAAO,IAAI,QAAQ,aAAY,IAAI;AACxC,cAAI,2BAAa,EAAE,GAAG;AACpB,gBAAQ,IAAI,cAAc,GAAG,UAAU,OAAO,GAAG,EAAE;AAAA,MACrD;AACA,oCAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["Ajv"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["export * from './Debounce'\nexport * from './SchemaCache'\nexport * from './SchemaNameToValidatorMap'\n","import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xylabs/axios'\nimport { handleError } from '@xylabs/error'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAsB;AAEf,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,IAAO,KAAW,SAA2B,UAAU,KAAO;AAClE,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO,KAAK,IAAI,IAAI,GAAG,GAAG;AACxB,gBAAM,oBAAM,GAAG;AACf,UAAI,KAAK,IAAI,IAAI,YAAY,SAAS;AACpC,cAAM,MAAM,uBAAuB,GAAG,GAAG;AAAA,MAC3C;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,mBAA6B;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AAM,QAAQ,UAAU;AACtD,YAAM,aAAa,wBAAwB,MAAM,QAAQ,UAAU;AACnE,UAAI,YAAY;AACd,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,kBACI,OAAO,CAAC,UAAU,MAAM,QAAQ,WAAW,yCAAY,EACxD,QAAQ,CAAC,UAAU;AAClB,WAAK,mBAAmB,KAAyB;AAAA,IACnD,CAAC;AAAA,EACL;AAAA,EAEA,MAAc,YAAY,QAAgB;AACxC,QAAI;AACF,YAAM,SAAS,MAAM,kDAAqB,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,IAAI;AAEX,WAAK,OAAO,IAAI,QAAQ,aAAY,IAAI;AACxC,cAAI,2BAAa,EAAE,GAAG;AACpB,gBAAQ,IAAI,cAAc,GAAG,UAAU,OAAO,GAAG,EAAE;AAAA,MACrD;AACA,oCAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["Ajv"]}
@@ -20,9 +20,9 @@ var Debounce = class {
20
20
  };
21
21
 
22
22
  // src/SchemaCache.ts
23
- import { isAxiosError } from "@xyo-network/axios";
23
+ import { isAxiosError } from "@xylabs/axios";
24
+ import { handleError } from "@xylabs/error";
24
25
  import { DomainPayloadWrapper } from "@xyo-network/domain-payload-plugin";
25
- import { handleError } from "@xyo-network/error";
26
26
  import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
27
27
  import Ajv from "ajv";
28
28
  import { LRUCache } from "lru-cache";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xyo-network/axios'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { handleError } from '@xyo-network/error'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAEf,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,M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GAAG,EAAE;AAAA,MACrD;AACA,kBAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xylabs/axios'\nimport { handleError } from '@xylabs/error'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mapp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,QAAQ,aAAY,IAAI;AACxC,UAAI,aAAa,EAAE,GAAG;AACpB,gBAAQ,IAAI,cAAc,GAAG,UAAU,OAAO,GAAG,EAAE;AAAA,MACrD;AACA,kBAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -1,11 +1,48 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Debounce: () => Debounce,
34
+ SchemaCache: () => SchemaCache
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
1
38
  // src/Debounce.ts
2
- import { delay } from "@xylabs/delay";
39
+ var import_delay = require("@xylabs/delay");
3
40
  var Debounce = class {
4
41
  map = /* @__PURE__ */ new Map();
5
42
  async one(key, closure, timeout = 1e4) {
6
43
  const startTime = Date.now();
7
44
  while (this.map.get(key)) {
8
- await delay(100);
45
+ await (0, import_delay.delay)(100);
9
46
  if (Date.now() - startTime > timeout) {
10
47
  throw Error(`Debounce timed out [${key}]`);
11
48
  }
@@ -20,12 +57,12 @@ var Debounce = class {
20
57
  };
21
58
 
22
59
  // src/SchemaCache.ts
23
- import { isAxiosError } from "@xyo-network/axios";
24
- import { DomainPayloadWrapper } from "@xyo-network/domain-payload-plugin";
25
- import { handleError } from "@xyo-network/error";
26
- import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
27
- import Ajv from "ajv";
28
- import { LRUCache } from "lru-cache";
60
+ var import_axios = require("@xylabs/axios");
61
+ var import_error = require("@xylabs/error");
62
+ var import_domain_payload_plugin = require("@xyo-network/domain-payload-plugin");
63
+ var import_schema_payload_plugin = require("@xyo-network/schema-payload-plugin");
64
+ var import_ajv = __toESM(require("ajv"), 1);
65
+ var import_lru_cache = require("lru-cache");
29
66
  var getSchemaNameFromSchema = (schema) => {
30
67
  if (schema.$id) {
31
68
  return schema.$id;
@@ -36,11 +73,11 @@ var SchemaCache = class _SchemaCache {
36
73
  * Object representing `null` since LRU Cache types
37
74
  * only allow for types that derive from object
38
75
  */
39
- static NULL = { payload: { definition: {}, schema: SchemaSchema } };
76
+ static NULL = { payload: { definition: {}, schema: import_schema_payload_plugin.SchemaSchema } };
40
77
  static _instance;
41
78
  onSchemaCached;
42
79
  proxy;
43
- _cache = new LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
80
+ _cache = new import_lru_cache.LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
44
81
  _validators = {};
45
82
  //prevents double discovery
46
83
  getDebounce = new Debounce();
@@ -76,7 +113,7 @@ var SchemaCache = class _SchemaCache {
76
113
  cacheSchemaIfValid(entry) {
77
114
  var _a;
78
115
  if (entry.payload.definition) {
79
- const ajv = new Ajv({ strict: false });
116
+ const ajv = new import_ajv.default({ strict: false });
80
117
  const validator = ajv.compile(entry.payload.definition);
81
118
  const schemaName = getSchemaNameFromSchema(entry.payload.definition);
82
119
  if (schemaName) {
@@ -88,14 +125,14 @@ var SchemaCache = class _SchemaCache {
88
125
  }
89
126
  }
90
127
  cacheSchemas(aliasEntries) {
91
- aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === SchemaSchema).forEach((entry) => {
128
+ aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === import_schema_payload_plugin.SchemaSchema).forEach((entry) => {
92
129
  this.cacheSchemaIfValid(entry);
93
130
  });
94
131
  }
95
132
  async fetchSchema(schema) {
96
133
  var _a;
97
134
  try {
98
- const domain = await DomainPayloadWrapper.discover(schema, this.proxy);
135
+ const domain = await import_domain_payload_plugin.DomainPayloadWrapper.discover(schema, this.proxy);
99
136
  await (domain == null ? void 0 : domain.fetch());
100
137
  this.cacheSchemas(domain == null ? void 0 : domain.aliases);
101
138
  if (this._cache.get(schema) === void 0) {
@@ -103,17 +140,18 @@ var SchemaCache = class _SchemaCache {
103
140
  }
104
141
  } catch (ex) {
105
142
  this._cache.set(schema, _SchemaCache.NULL);
106
- if (isAxiosError(ex)) {
143
+ if ((0, import_axios.isAxiosError)(ex)) {
107
144
  console.log(`Axios Url: ${(_a = ex.response) == null ? void 0 : _a.config.url}`);
108
145
  }
109
- handleError(ex, (error) => {
146
+ (0, import_error.handleError)(ex, (error) => {
110
147
  console.error(`fetchSchema threw: ${error.message}`);
111
148
  });
112
149
  }
113
150
  }
114
151
  };
115
- export {
152
+ // Annotate the CommonJS export names for ESM import in node:
153
+ 0 && (module.exports = {
116
154
  Debounce,
117
155
  SchemaCache
118
- };
119
- //# sourceMappingURL=index.mjs.map
156
+ });
157
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["export * from './Debounce'\nexport * from './SchemaCache'\nexport * from './SchemaNameToValidatorMap'\n","import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xylabs/axios'\nimport { handleError } from '@xylabs/error'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA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AAI,2BAAa,EAAE,GAAG;AACpB,gBAAQ,IAAI,eAAc,QAAG,aAAH,mBAAa,OAAO,GAAG,EAAE;AAAA,MACrD;AACA,oCAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["Ajv"]}
@@ -1,48 +1,11 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- Debounce: () => Debounce,
34
- SchemaCache: () => SchemaCache
35
- });
36
- module.exports = __toCommonJS(src_exports);
37
-
38
1
  // src/Debounce.ts
39
- var import_delay = require("@xylabs/delay");
2
+ import { delay } from "@xylabs/delay";
40
3
  var Debounce = class {
41
4
  map = /* @__PURE__ */ new Map();
42
5
  async one(key, closure, timeout = 1e4) {
43
6
  const startTime = Date.now();
44
7
  while (this.map.get(key)) {
45
- await (0, import_delay.delay)(100);
8
+ await delay(100);
46
9
  if (Date.now() - startTime > timeout) {
47
10
  throw Error(`Debounce timed out [${key}]`);
48
11
  }
@@ -57,12 +20,12 @@ var Debounce = class {
57
20
  };
58
21
 
59
22
  // src/SchemaCache.ts
60
- var import_axios = require("@xyo-network/axios");
61
- var import_domain_payload_plugin = require("@xyo-network/domain-payload-plugin");
62
- var import_error = require("@xyo-network/error");
63
- var import_schema_payload_plugin = require("@xyo-network/schema-payload-plugin");
64
- var import_ajv = __toESM(require("ajv"));
65
- var import_lru_cache = require("lru-cache");
23
+ import { isAxiosError } from "@xylabs/axios";
24
+ import { handleError } from "@xylabs/error";
25
+ import { DomainPayloadWrapper } from "@xyo-network/domain-payload-plugin";
26
+ import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
27
+ import Ajv from "ajv";
28
+ import { LRUCache } from "lru-cache";
66
29
  var getSchemaNameFromSchema = (schema) => {
67
30
  if (schema.$id) {
68
31
  return schema.$id;
@@ -73,11 +36,11 @@ var SchemaCache = class _SchemaCache {
73
36
  * Object representing `null` since LRU Cache types
74
37
  * only allow for types that derive from object
75
38
  */
76
- static NULL = { payload: { definition: {}, schema: import_schema_payload_plugin.SchemaSchema } };
39
+ static NULL = { payload: { definition: {}, schema: SchemaSchema } };
77
40
  static _instance;
78
41
  onSchemaCached;
79
42
  proxy;
80
- _cache = new import_lru_cache.LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
43
+ _cache = new LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
81
44
  _validators = {};
82
45
  //prevents double discovery
83
46
  getDebounce = new Debounce();
@@ -113,7 +76,7 @@ var SchemaCache = class _SchemaCache {
113
76
  cacheSchemaIfValid(entry) {
114
77
  var _a;
115
78
  if (entry.payload.definition) {
116
- const ajv = new import_ajv.default({ strict: false });
79
+ const ajv = new Ajv({ strict: false });
117
80
  const validator = ajv.compile(entry.payload.definition);
118
81
  const schemaName = getSchemaNameFromSchema(entry.payload.definition);
119
82
  if (schemaName) {
@@ -125,14 +88,14 @@ var SchemaCache = class _SchemaCache {
125
88
  }
126
89
  }
127
90
  cacheSchemas(aliasEntries) {
128
- aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === import_schema_payload_plugin.SchemaSchema).forEach((entry) => {
91
+ aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === SchemaSchema).forEach((entry) => {
129
92
  this.cacheSchemaIfValid(entry);
130
93
  });
131
94
  }
132
95
  async fetchSchema(schema) {
133
96
  var _a;
134
97
  try {
135
- const domain = await import_domain_payload_plugin.DomainPayloadWrapper.discover(schema, this.proxy);
98
+ const domain = await DomainPayloadWrapper.discover(schema, this.proxy);
136
99
  await (domain == null ? void 0 : domain.fetch());
137
100
  this.cacheSchemas(domain == null ? void 0 : domain.aliases);
138
101
  if (this._cache.get(schema) === void 0) {
@@ -140,18 +103,17 @@ var SchemaCache = class _SchemaCache {
140
103
  }
141
104
  } catch (ex) {
142
105
  this._cache.set(schema, _SchemaCache.NULL);
143
- if ((0, import_axios.isAxiosError)(ex)) {
106
+ if (isAxiosError(ex)) {
144
107
  console.log(`Axios Url: ${(_a = ex.response) == null ? void 0 : _a.config.url}`);
145
108
  }
146
- (0, import_error.handleError)(ex, (error) => {
109
+ handleError(ex, (error) => {
147
110
  console.error(`fetchSchema threw: ${error.message}`);
148
111
  });
149
112
  }
150
113
  }
151
114
  };
152
- // Annotate the CommonJS export names for ESM import in node:
153
- 0 && (module.exports = {
115
+ export {
154
116
  Debounce,
155
117
  SchemaCache
156
- });
118
+ };
157
119
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["export * from './Debounce'\nexport * from './SchemaCache'\nexport * from './SchemaNameToValidatorMap'\n","import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xyo-network/axios'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { handleError } from '@xyo-network/error'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAsB;AAEf,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,I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AAA,MACrD;AACA,oCAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["Ajv"]}
1
+ {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xylabs/axios'\nimport { handleError } from '@xylabs/error'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";AAA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,QAAQ,aAAY,IAAI;AACxC,UAAI,aAAa,EAAE,GAAG;AACpB,gBAAQ,IAAI,eAAc,QAAG,aAAH,mBAAa,OAAO,GAAG,EAAE;AAAA,MACrD;AACA,kBAAY,IAAI,CAAC,UAAU;AACzB,gBAAQ,MAAM,sBAAsB,MAAM,OAAO,EAAE;AAAA,MACrD,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -9,26 +9,25 @@
9
9
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
10
10
  },
11
11
  "dependencies": {
12
- "@xylabs/delay": "^2.13.3",
13
- "@xyo-network/axios": "~2.79.4",
14
- "@xyo-network/domain-payload-plugin": "~2.79.4",
15
- "@xyo-network/error": "~2.79.4",
16
- "@xyo-network/huri": "~2.79.4",
17
- "@xyo-network/payload-model": "~2.79.4",
18
- "@xyo-network/schema-payload-plugin": "~2.79.4",
12
+ "@xylabs/axios": "^2.13.8",
13
+ "@xylabs/delay": "^2.13.8",
14
+ "@xylabs/error": "^2.13.8",
15
+ "@xyo-network/domain-payload-plugin": "~2.79.5",
16
+ "@xyo-network/huri": "~2.79.5",
17
+ "@xyo-network/payload-model": "~2.79.5",
18
+ "@xyo-network/schema-payload-plugin": "~2.79.5",
19
19
  "ajv": "^8.12.0",
20
20
  "lru-cache": "^10.0.2"
21
21
  },
22
22
  "description": "Primary SDK for using XYO Protocol 2.0",
23
23
  "devDependencies": {
24
- "@xylabs/assert": "^2.13.3",
24
+ "@xylabs/assert": "^2.13.8",
25
25
  "@xylabs/ts-scripts-yarn3": "^3.1.21",
26
26
  "@xylabs/tsconfig-dom": "^3.1.21",
27
- "@xyo-network/network": "~2.79.4",
28
- "@xyo-network/payload-builder": "~2.79.4",
27
+ "@xyo-network/network": "~2.79.5",
28
+ "@xyo-network/payload-builder": "~2.79.5",
29
29
  "typescript": "^5.2.2"
30
30
  },
31
- "docs": "dist/docs.json",
32
31
  "exports": {
33
32
  ".": {
34
33
  "browser": {
@@ -43,19 +42,21 @@
43
42
  },
44
43
  "node": {
45
44
  "require": {
46
- "types": "./dist/node/index.d.ts",
47
- "default": "./dist/node/index.js"
45
+ "types": "./dist/node/index.d.cts",
46
+ "default": "./dist/node/index.cjs"
48
47
  },
49
48
  "import": {
50
49
  "types": "./dist/node/index.d.mts",
51
- "default": "./dist/node/index.mjs"
50
+ "default": "./dist/node/index.js"
52
51
  }
53
52
  }
54
53
  },
55
54
  "./package.json": "./package.json"
56
55
  },
57
- "main": "dist/node/index.js",
58
- "module": "dist/node/index.mjs",
56
+ "main": "dist/node/index.cjs",
57
+ "module": "dist/node/index.js",
58
+ "types": "dist/node/index.d.mts",
59
+ "type": "module",
59
60
  "homepage": "https://xyo.network",
60
61
  "license": "LGPL-3.0-only",
61
62
  "name": "@xyo-network/schema-cache",
@@ -67,6 +68,5 @@
67
68
  "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
68
69
  },
69
70
  "sideEffects": false,
70
- "types": "dist/node/index.d.ts",
71
- "version": "2.79.4"
71
+ "version": "2.79.5"
72
72
  }
@@ -1,6 +1,6 @@
1
- import { isAxiosError } from '@xyo-network/axios'
1
+ import { isAxiosError } from '@xylabs/axios'
2
+ import { handleError } from '@xylabs/error'
2
3
  import { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'
3
- import { handleError } from '@xyo-network/error'
4
4
  import { FetchedPayload } from '@xyo-network/huri'
5
5
  import { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'
6
6
  import Ajv, { SchemaObject } from 'ajv'
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Debounce.ts","../../src/SchemaCache.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\n\nexport class Debounce<TKey = string> {\n private map = new Map<TKey, number>()\n\n async one<T>(key: TKey, closure: () => Promise<T>, timeout = 10000) {\n const startTime = Date.now()\n while (this.map.get(key)) {\n await delay(100)\n if (Date.now() - startTime > timeout) {\n throw 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 { isAxiosError } from '@xyo-network/axios'\nimport { DomainPayloadWrapper } from '@xyo-network/domain-payload-plugin'\nimport { handleError } from '@xyo-network/error'\nimport { FetchedPayload } from '@xyo-network/huri'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\nimport Ajv, { SchemaObject } from 'ajv'\nimport { LRUCache } from 'lru-cache'\n\nimport { Debounce } from './Debounce'\nimport { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap'\n\nconst getSchemaNameFromSchema = (schema: SchemaObject) => {\n if (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 (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 (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 (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 aliasEntries\n ?.filter((entry) => entry.payload.schema === SchemaSchema)\n .forEach((entry) => {\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 (ex) {\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(ex)) {\n console.log(`Axios Url: ${ex.response?.config.url}`)\n }\n handleError(ex, (error) => {\n console.error(`fetchSchema threw: ${error.message}`)\n })\n }\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAEf,IAAM,WAAN,MAA8B;AAAA,EAC3B,MAAM,oBAAI,IAAkB;AAAA,EAEpC,MAAM,IAAO,KAAW,SAA2B,UAAU,KAAO;AAClE,UAAM,YAAY,KAAK,IAAI;AAC3B,WAAO,KAAK,IAAI,IAAI,GAAG,GAAG;AACxB,YAAM,MAAM,GAAG;AACf,UAAI,KAAK,IAAI,IAAI,YAAY,SAAS;AACpC,cAAM,MAAM,uBAAuB,GAAG,GAAG;AAAA,MAC3C;AAAA,IACF;AACA,QAAI;AACF,WAAK,IAAI,IAAI,KAAK,CAAC;AACnB,aAAO,MAAM,QAAQ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