@xyo-network/schema-cache 2.75.0 → 2.75.2
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/Debounce.d.cts +5 -0
- package/dist/browser/Debounce.d.cts.map +1 -0
- package/dist/browser/Debounce.js +2 -3
- package/dist/browser/Debounce.js.map +1 -1
- package/dist/browser/SchemaCache.d.cts +30 -0
- package/dist/browser/SchemaCache.d.cts.map +1 -0
- package/dist/browser/SchemaCache.js +8 -31
- package/dist/browser/SchemaCache.js.map +1 -1
- package/dist/browser/SchemaNameToValidatorMap.d.cts +17 -0
- package/dist/browser/SchemaNameToValidatorMap.d.cts.map +1 -0
- package/dist/browser/index.d.cts +4 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.js +3 -116
- package/dist/browser/index.js.map +1 -1
- package/dist/docs.json +2590 -0
- package/dist/node/Debounce.d.cts +5 -0
- package/dist/node/Debounce.d.cts.map +1 -0
- package/dist/node/Debounce.js +4 -2
- package/dist/node/Debounce.js.map +1 -1
- package/dist/node/Debounce.mjs +3 -2
- package/dist/node/Debounce.mjs.map +1 -1
- package/dist/node/SchemaCache.d.cts +30 -0
- package/dist/node/SchemaCache.d.cts.map +1 -0
- package/dist/node/SchemaCache.js +40 -14
- package/dist/node/SchemaCache.js.map +1 -1
- package/dist/node/SchemaCache.mjs +38 -13
- package/dist/node/SchemaCache.mjs.map +1 -1
- package/dist/node/SchemaNameToValidatorMap.d.cts +17 -0
- package/dist/node/SchemaNameToValidatorMap.d.cts.map +1 -0
- package/dist/node/SchemaNameToValidatorMap.js +2 -0
- package/dist/node/SchemaNameToValidatorMap.js.map +1 -1
- package/dist/node/index.d.cts +4 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.js +137 -7
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +118 -3
- package/dist/node/index.mjs.map +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Debounce.d.ts","sourceRoot":"","sources":["../../src/Debounce.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ,CAAC,IAAI,GAAG,MAAM;IACjC,OAAO,CAAC,GAAG,CAA0B;IAE/B,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,SAAQ;CAenE"}
|
package/dist/node/Debounce.js
CHANGED
|
@@ -16,13 +16,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/Debounce.ts
|
|
19
21
|
var Debounce_exports = {};
|
|
20
22
|
__export(Debounce_exports, {
|
|
21
23
|
Debounce: () => Debounce
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(Debounce_exports);
|
|
24
26
|
var import_delay = require("@xylabs/delay");
|
|
25
|
-
|
|
27
|
+
var Debounce = class {
|
|
26
28
|
map = /* @__PURE__ */ new Map();
|
|
27
29
|
async one(key, closure, timeout = 1e4) {
|
|
28
30
|
const startTime = Date.now();
|
|
@@ -39,7 +41,7 @@ class Debounce {
|
|
|
39
41
|
this.map.set(key, 0);
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
}
|
|
44
|
+
};
|
|
43
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
46
|
0 && (module.exports = {
|
|
45
47
|
Debounce
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Debounce.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"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Debounce.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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,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;","names":[]}
|
package/dist/node/Debounce.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/Debounce.ts
|
|
1
2
|
import { delay } from "@xylabs/delay";
|
|
2
|
-
|
|
3
|
+
var Debounce = class {
|
|
3
4
|
map = /* @__PURE__ */ new Map();
|
|
4
5
|
async one(key, closure, timeout = 1e4) {
|
|
5
6
|
const startTime = Date.now();
|
|
@@ -16,7 +17,7 @@ class Debounce {
|
|
|
16
17
|
this.map.set(key, 0);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
|
+
};
|
|
20
21
|
export {
|
|
21
22
|
Debounce
|
|
22
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Debounce.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"],"mappings":"AAAA,SAAS,aAAa;AAEf,
|
|
1
|
+
{"version":3,"sources":["../../src/Debounce.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"],"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;AAAA,IACvB,UAAE;AACA,WAAK,IAAI,IAAI,KAAK,CAAC;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FetchedPayload } from '@xyo-network/huri';
|
|
2
|
+
import { SchemaPayload } from '@xyo-network/schema-payload-plugin';
|
|
3
|
+
import { SchemaNameToValidatorMap } from './SchemaNameToValidatorMap';
|
|
4
|
+
export type SchemaCacheEntry = FetchedPayload<SchemaPayload>;
|
|
5
|
+
export declare class SchemaCache<T extends SchemaNameToValidatorMap = SchemaNameToValidatorMap> {
|
|
6
|
+
/**
|
|
7
|
+
* Object representing `null` since LRU Cache types
|
|
8
|
+
* only allow for types that derive from object
|
|
9
|
+
*/
|
|
10
|
+
protected static readonly NULL: SchemaCacheEntry;
|
|
11
|
+
private static _instance?;
|
|
12
|
+
onSchemaCached?: (name: string, entry: SchemaCacheEntry) => void;
|
|
13
|
+
proxy?: string;
|
|
14
|
+
private _cache;
|
|
15
|
+
private _validators;
|
|
16
|
+
private getDebounce;
|
|
17
|
+
private constructor();
|
|
18
|
+
static get instance(): SchemaCache<SchemaNameToValidatorMap>;
|
|
19
|
+
/**
|
|
20
|
+
* A map of cached schema (by name) to payload validators for the schema. A schema
|
|
21
|
+
* must be cached via `get('schema.name')` before it's validator can be used as
|
|
22
|
+
* they are compiled dynamically at runtime upon retrieval.
|
|
23
|
+
*/
|
|
24
|
+
get validators(): T;
|
|
25
|
+
get(schema?: string): Promise<SchemaCacheEntry | undefined | null>;
|
|
26
|
+
private cacheSchemaIfValid;
|
|
27
|
+
private cacheSchemas;
|
|
28
|
+
private fetchSchema;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=SchemaCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaCache.d.ts","sourceRoot":"","sources":["../../src/SchemaCache.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAgB,MAAM,oCAAoC,CAAA;AAKhF,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAQrE,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,0CAKlB;IAED;;;;OAIG;IACH,IAAI,UAAU,IAAI,CAAC,CAElB;IAEK,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,GAAG,IAAI,CAAC;IAcxE,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,YAAY;YAQN,WAAW;CAqB1B"}
|
package/dist/node/SchemaCache.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/SchemaCache.ts
|
|
29
31
|
var SchemaCache_exports = {};
|
|
30
32
|
__export(SchemaCache_exports, {
|
|
31
33
|
SchemaCache: () => SchemaCache
|
|
@@ -37,13 +39,35 @@ var import_error = require("@xyo-network/error");
|
|
|
37
39
|
var import_schema_payload_plugin = require("@xyo-network/schema-payload-plugin");
|
|
38
40
|
var import_ajv = __toESM(require("ajv"));
|
|
39
41
|
var import_lru_cache = require("lru-cache");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
|
|
43
|
+
// src/Debounce.ts
|
|
44
|
+
var import_delay = require("@xylabs/delay");
|
|
45
|
+
var Debounce = class {
|
|
46
|
+
map = /* @__PURE__ */ new Map();
|
|
47
|
+
async one(key, closure, timeout = 1e4) {
|
|
48
|
+
const startTime = Date.now();
|
|
49
|
+
while (this.map.get(key)) {
|
|
50
|
+
await (0, import_delay.delay)(100);
|
|
51
|
+
if (Date.now() - startTime > timeout) {
|
|
52
|
+
throw Error(`Debounce timed out [${key}]`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
this.map.set(key, 1);
|
|
57
|
+
return await closure();
|
|
58
|
+
} finally {
|
|
59
|
+
this.map.set(key, 0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/SchemaCache.ts
|
|
65
|
+
var getSchemaNameFromSchema = (schema) => {
|
|
42
66
|
if (schema.$id) {
|
|
43
67
|
return schema.$id;
|
|
44
68
|
}
|
|
45
69
|
};
|
|
46
|
-
|
|
70
|
+
var SchemaCache = class _SchemaCache {
|
|
47
71
|
/**
|
|
48
72
|
* Object representing `null` since LRU Cache types
|
|
49
73
|
* only allow for types that derive from object
|
|
@@ -55,13 +79,13 @@ class SchemaCache {
|
|
|
55
79
|
_cache = new import_lru_cache.LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
|
|
56
80
|
_validators = {};
|
|
57
81
|
//prevents double discovery
|
|
58
|
-
getDebounce = new
|
|
82
|
+
getDebounce = new Debounce();
|
|
59
83
|
constructor(proxy) {
|
|
60
84
|
this.proxy = proxy;
|
|
61
85
|
}
|
|
62
86
|
static get instance() {
|
|
63
87
|
if (!this._instance) {
|
|
64
|
-
this._instance = new
|
|
88
|
+
this._instance = new _SchemaCache();
|
|
65
89
|
}
|
|
66
90
|
return this._instance;
|
|
67
91
|
}
|
|
@@ -81,11 +105,12 @@ class SchemaCache {
|
|
|
81
105
|
}
|
|
82
106
|
});
|
|
83
107
|
const value = this._cache.get(schema);
|
|
84
|
-
return value ===
|
|
108
|
+
return value === _SchemaCache.NULL ? null : value;
|
|
85
109
|
}
|
|
86
110
|
return void 0;
|
|
87
111
|
}
|
|
88
112
|
cacheSchemaIfValid(entry) {
|
|
113
|
+
var _a;
|
|
89
114
|
if (entry.payload.definition) {
|
|
90
115
|
const ajv = new import_ajv.default({ strict: false });
|
|
91
116
|
const validator = ajv.compile(entry.payload.definition);
|
|
@@ -94,34 +119,35 @@ class SchemaCache {
|
|
|
94
119
|
this._cache.set(schemaName, entry);
|
|
95
120
|
const key = schemaName;
|
|
96
121
|
this._validators[key] = validator;
|
|
97
|
-
this.onSchemaCached
|
|
122
|
+
(_a = this.onSchemaCached) == null ? void 0 : _a.call(this, schemaName, entry);
|
|
98
123
|
}
|
|
99
124
|
}
|
|
100
125
|
}
|
|
101
126
|
cacheSchemas(aliasEntries) {
|
|
102
|
-
aliasEntries
|
|
127
|
+
aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === import_schema_payload_plugin.SchemaSchema).forEach((entry) => {
|
|
103
128
|
this.cacheSchemaIfValid(entry);
|
|
104
129
|
});
|
|
105
130
|
}
|
|
106
131
|
async fetchSchema(schema) {
|
|
132
|
+
var _a;
|
|
107
133
|
try {
|
|
108
134
|
const domain = await import_domain_payload_plugin.DomainPayloadWrapper.discover(schema, this.proxy);
|
|
109
|
-
await domain
|
|
110
|
-
this.cacheSchemas(domain
|
|
135
|
+
await (domain == null ? void 0 : domain.fetch());
|
|
136
|
+
this.cacheSchemas(domain == null ? void 0 : domain.aliases);
|
|
111
137
|
if (this._cache.get(schema) === void 0) {
|
|
112
|
-
this._cache.set(schema,
|
|
138
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
113
139
|
}
|
|
114
140
|
} catch (ex) {
|
|
115
|
-
this._cache.set(schema,
|
|
141
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
116
142
|
if ((0, import_axios.isAxiosError)(ex)) {
|
|
117
|
-
console.log(`Axios Url: ${ex.response
|
|
143
|
+
console.log(`Axios Url: ${(_a = ex.response) == null ? void 0 : _a.config.url}`);
|
|
118
144
|
}
|
|
119
145
|
(0, import_error.handleError)(ex, (error) => {
|
|
120
146
|
console.error(`fetchSchema threw: ${error.message}`);
|
|
121
147
|
});
|
|
122
148
|
}
|
|
123
149
|
}
|
|
124
|
-
}
|
|
150
|
+
};
|
|
125
151
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
152
|
0 && (module.exports = {
|
|
127
153
|
SchemaCache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SchemaCache.ts"],"sourcesContent":["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":"
|
|
1
|
+
{"version":3,"sources":["../../src/SchemaCache.ts","../../src/Debounce.ts"],"sourcesContent":["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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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OAAO,IAAI,QAAQ,aAAY,IAAI;AACxC,cAAI,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,16 +1,39 @@
|
|
|
1
|
+
// src/SchemaCache.ts
|
|
1
2
|
import { isAxiosError } from "@xyo-network/axios";
|
|
2
3
|
import { DomainPayloadWrapper } from "@xyo-network/domain-payload-plugin";
|
|
3
4
|
import { handleError } from "@xyo-network/error";
|
|
4
5
|
import { SchemaSchema } from "@xyo-network/schema-payload-plugin";
|
|
5
6
|
import Ajv from "ajv";
|
|
6
7
|
import { LRUCache } from "lru-cache";
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
// src/Debounce.ts
|
|
10
|
+
import { delay } from "@xylabs/delay";
|
|
11
|
+
var Debounce = class {
|
|
12
|
+
map = /* @__PURE__ */ new Map();
|
|
13
|
+
async one(key, closure, timeout = 1e4) {
|
|
14
|
+
const startTime = Date.now();
|
|
15
|
+
while (this.map.get(key)) {
|
|
16
|
+
await delay(100);
|
|
17
|
+
if (Date.now() - startTime > timeout) {
|
|
18
|
+
throw Error(`Debounce timed out [${key}]`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
this.map.set(key, 1);
|
|
23
|
+
return await closure();
|
|
24
|
+
} finally {
|
|
25
|
+
this.map.set(key, 0);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/SchemaCache.ts
|
|
31
|
+
var getSchemaNameFromSchema = (schema) => {
|
|
9
32
|
if (schema.$id) {
|
|
10
33
|
return schema.$id;
|
|
11
34
|
}
|
|
12
35
|
};
|
|
13
|
-
|
|
36
|
+
var SchemaCache = class _SchemaCache {
|
|
14
37
|
/**
|
|
15
38
|
* Object representing `null` since LRU Cache types
|
|
16
39
|
* only allow for types that derive from object
|
|
@@ -28,7 +51,7 @@ class SchemaCache {
|
|
|
28
51
|
}
|
|
29
52
|
static get instance() {
|
|
30
53
|
if (!this._instance) {
|
|
31
|
-
this._instance = new
|
|
54
|
+
this._instance = new _SchemaCache();
|
|
32
55
|
}
|
|
33
56
|
return this._instance;
|
|
34
57
|
}
|
|
@@ -48,11 +71,12 @@ class SchemaCache {
|
|
|
48
71
|
}
|
|
49
72
|
});
|
|
50
73
|
const value = this._cache.get(schema);
|
|
51
|
-
return value ===
|
|
74
|
+
return value === _SchemaCache.NULL ? null : value;
|
|
52
75
|
}
|
|
53
76
|
return void 0;
|
|
54
77
|
}
|
|
55
78
|
cacheSchemaIfValid(entry) {
|
|
79
|
+
var _a;
|
|
56
80
|
if (entry.payload.definition) {
|
|
57
81
|
const ajv = new Ajv({ strict: false });
|
|
58
82
|
const validator = ajv.compile(entry.payload.definition);
|
|
@@ -61,34 +85,35 @@ class SchemaCache {
|
|
|
61
85
|
this._cache.set(schemaName, entry);
|
|
62
86
|
const key = schemaName;
|
|
63
87
|
this._validators[key] = validator;
|
|
64
|
-
this.onSchemaCached
|
|
88
|
+
(_a = this.onSchemaCached) == null ? void 0 : _a.call(this, schemaName, entry);
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
}
|
|
68
92
|
cacheSchemas(aliasEntries) {
|
|
69
|
-
aliasEntries
|
|
93
|
+
aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === SchemaSchema).forEach((entry) => {
|
|
70
94
|
this.cacheSchemaIfValid(entry);
|
|
71
95
|
});
|
|
72
96
|
}
|
|
73
97
|
async fetchSchema(schema) {
|
|
98
|
+
var _a;
|
|
74
99
|
try {
|
|
75
100
|
const domain = await DomainPayloadWrapper.discover(schema, this.proxy);
|
|
76
|
-
await domain
|
|
77
|
-
this.cacheSchemas(domain
|
|
101
|
+
await (domain == null ? void 0 : domain.fetch());
|
|
102
|
+
this.cacheSchemas(domain == null ? void 0 : domain.aliases);
|
|
78
103
|
if (this._cache.get(schema) === void 0) {
|
|
79
|
-
this._cache.set(schema,
|
|
104
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
80
105
|
}
|
|
81
106
|
} catch (ex) {
|
|
82
|
-
this._cache.set(schema,
|
|
107
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
83
108
|
if (isAxiosError(ex)) {
|
|
84
|
-
console.log(`Axios Url: ${ex.response
|
|
109
|
+
console.log(`Axios Url: ${(_a = ex.response) == null ? void 0 : _a.config.url}`);
|
|
85
110
|
}
|
|
86
111
|
handleError(ex, (error) => {
|
|
87
112
|
console.error(`fetchSchema threw: ${error.message}`);
|
|
88
113
|
});
|
|
89
114
|
}
|
|
90
115
|
}
|
|
91
|
-
}
|
|
116
|
+
};
|
|
92
117
|
export {
|
|
93
118
|
SchemaCache
|
|
94
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SchemaCache.ts"],"sourcesContent":["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,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAE5B,SAAwB,oBAAoB;AAC5C,OAAO,SAA2B;AAClC,SAAS,gBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../src/SchemaCache.ts","../../src/Debounce.ts"],"sourcesContent":["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","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"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,4BAA4B;AACrC,SAAS,mBAAmB;AAE5B,SAAwB,oBAAoB;AAC5C,OAAO,SAA2B;AAClC,SAAS,gBAAgB;;;ACNzB,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;AAAA,IACvB,UAAE;AACA,WAAK,IAAI,IAAI,KAAK,CAAC;AAAA,IACrB;AAAA,EACF;AACF;;;ADTA,IAAM,0BAA0B,CAAC,WAAyB;AACxD,MAAI,OAAO,KAAK;AACd,WAAO,OAAO;AAAA,EAChB;AACF;AAIO,IAAM,cAAN,MAAM,aAA2E;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtF,OAA0B,OAAyB,EAAE,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,aAAa,EAAE;AAAA,EAEvG,OAAe;AAAA,EAEf;AAAA,EACA;AAAA,EAEQ,SAAS,IAAI,SAAmC,EAAE,KAAK,KAAK,KAAK,MAAO,KAAK,EAAE,CAAC;AAAA,EAChF,cAAiB,CAAC;AAAA;AAAA,EAGlB,cAAc,IAA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,KAAK,KAAK;AACrE,aAAM,iCAAQ;AACd,WAAK,aAAa,iCAAQ,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,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":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DomainPayload, DomainSchema } from '@xyo-network/domain-payload-plugin';
|
|
2
|
+
import { Payload, PayloadSchema } from '@xyo-network/payload-model';
|
|
3
|
+
import { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin';
|
|
4
|
+
/**
|
|
5
|
+
* Used in conjunction with schema validation to support compile time type assertion
|
|
6
|
+
* for known schema types.
|
|
7
|
+
*/
|
|
8
|
+
export type NarrowPayload<T extends Payload = Payload> = ((x: Payload) => x is T) | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Used to map known schemas (byt their string name) to the validators which assert their types
|
|
11
|
+
*/
|
|
12
|
+
export interface SchemaNameToValidatorMap {
|
|
13
|
+
[DomainSchema]: NarrowPayload<DomainPayload>;
|
|
14
|
+
[PayloadSchema]: NarrowPayload<Payload>;
|
|
15
|
+
[SchemaSchema]: NarrowPayload<SchemaPayload>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=SchemaNameToValidatorMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaNameToValidatorMap.d.ts","sourceRoot":"","sources":["../../src/SchemaNameToValidatorMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAEhF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;AAE7F;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;IAC5C,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAC7C"}
|
|
@@ -12,6 +12,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/SchemaNameToValidatorMap.ts
|
|
15
17
|
var SchemaNameToValidatorMap_exports = {};
|
|
16
18
|
module.exports = __toCommonJS(SchemaNameToValidatorMap_exports);
|
|
17
19
|
//# sourceMappingURL=SchemaNameToValidatorMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/SchemaNameToValidatorMap.ts"],"sourcesContent":["import { DomainPayload, DomainSchema } from '@xyo-network/domain-payload-plugin'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\n\n/**\n * Used in conjunction with schema validation to support compile time type assertion\n * for known schema types.\n */\nexport type NarrowPayload<T extends Payload = Payload> = ((x: Payload) => x is T) | undefined\n\n/**\n * Used to map known schemas (byt their string name) to the validators which assert their types\n */\nexport interface SchemaNameToValidatorMap {\n [DomainSchema]: NarrowPayload<DomainPayload>\n [PayloadSchema]: NarrowPayload<Payload>\n [SchemaSchema]: NarrowPayload<SchemaPayload>\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/SchemaNameToValidatorMap.ts"],"sourcesContent":["import { DomainPayload, DomainSchema } from '@xyo-network/domain-payload-plugin'\nimport { Payload, PayloadSchema } from '@xyo-network/payload-model'\nimport { SchemaPayload, SchemaSchema } from '@xyo-network/schema-payload-plugin'\n\n/**\n * Used in conjunction with schema validation to support compile time type assertion\n * for known schema types.\n */\nexport type NarrowPayload<T extends Payload = Payload> = ((x: Payload) => x is T) | undefined\n\n/**\n * Used to map known schemas (byt their string name) to the validators which assert their types\n */\nexport interface SchemaNameToValidatorMap {\n [DomainSchema]: NarrowPayload<DomainPayload>\n [PayloadSchema]: NarrowPayload<Payload>\n [SchemaSchema]: NarrowPayload<SchemaPayload>\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,4BAA4B,CAAA"}
|
package/dist/node/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
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
|
+
};
|
|
6
12
|
var __copyProps = (to, from, except, desc) => {
|
|
7
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -11,17 +17,141 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var
|
|
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
|
+
));
|
|
15
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
16
31
|
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Debounce: () => Debounce,
|
|
34
|
+
SchemaCache: () => SchemaCache
|
|
35
|
+
});
|
|
17
36
|
module.exports = __toCommonJS(src_exports);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
37
|
+
|
|
38
|
+
// src/Debounce.ts
|
|
39
|
+
var import_delay = require("@xylabs/delay");
|
|
40
|
+
var Debounce = class {
|
|
41
|
+
map = /* @__PURE__ */ new Map();
|
|
42
|
+
async one(key, closure, timeout = 1e4) {
|
|
43
|
+
const startTime = Date.now();
|
|
44
|
+
while (this.map.get(key)) {
|
|
45
|
+
await (0, import_delay.delay)(100);
|
|
46
|
+
if (Date.now() - startTime > timeout) {
|
|
47
|
+
throw Error(`Debounce timed out [${key}]`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
this.map.set(key, 1);
|
|
52
|
+
return await closure();
|
|
53
|
+
} finally {
|
|
54
|
+
this.map.set(key, 0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// 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");
|
|
66
|
+
var getSchemaNameFromSchema = (schema) => {
|
|
67
|
+
if (schema.$id) {
|
|
68
|
+
return schema.$id;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var SchemaCache = class _SchemaCache {
|
|
72
|
+
/**
|
|
73
|
+
* Object representing `null` since LRU Cache types
|
|
74
|
+
* only allow for types that derive from object
|
|
75
|
+
*/
|
|
76
|
+
static NULL = { payload: { definition: {}, schema: import_schema_payload_plugin.SchemaSchema } };
|
|
77
|
+
static _instance;
|
|
78
|
+
onSchemaCached;
|
|
79
|
+
proxy;
|
|
80
|
+
_cache = new import_lru_cache.LRUCache({ max: 500, ttl: 1e3 * 60 * 5 });
|
|
81
|
+
_validators = {};
|
|
82
|
+
//prevents double discovery
|
|
83
|
+
getDebounce = new Debounce();
|
|
84
|
+
constructor(proxy) {
|
|
85
|
+
this.proxy = proxy;
|
|
86
|
+
}
|
|
87
|
+
static get instance() {
|
|
88
|
+
if (!this._instance) {
|
|
89
|
+
this._instance = new _SchemaCache();
|
|
90
|
+
}
|
|
91
|
+
return this._instance;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A map of cached schema (by name) to payload validators for the schema. A schema
|
|
95
|
+
* must be cached via `get('schema.name')` before it's validator can be used as
|
|
96
|
+
* they are compiled dynamically at runtime upon retrieval.
|
|
97
|
+
*/
|
|
98
|
+
get validators() {
|
|
99
|
+
return this._validators;
|
|
100
|
+
}
|
|
101
|
+
async get(schema) {
|
|
102
|
+
if (schema) {
|
|
103
|
+
await this.getDebounce.one(schema, async () => {
|
|
104
|
+
if (this._cache.get(schema) === void 0) {
|
|
105
|
+
await this.fetchSchema(schema);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const value = this._cache.get(schema);
|
|
109
|
+
return value === _SchemaCache.NULL ? null : value;
|
|
110
|
+
}
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
cacheSchemaIfValid(entry) {
|
|
114
|
+
var _a;
|
|
115
|
+
if (entry.payload.definition) {
|
|
116
|
+
const ajv = new import_ajv.default({ strict: false });
|
|
117
|
+
const validator = ajv.compile(entry.payload.definition);
|
|
118
|
+
const schemaName = getSchemaNameFromSchema(entry.payload.definition);
|
|
119
|
+
if (schemaName) {
|
|
120
|
+
this._cache.set(schemaName, entry);
|
|
121
|
+
const key = schemaName;
|
|
122
|
+
this._validators[key] = validator;
|
|
123
|
+
(_a = this.onSchemaCached) == null ? void 0 : _a.call(this, schemaName, entry);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
cacheSchemas(aliasEntries) {
|
|
128
|
+
aliasEntries == null ? void 0 : aliasEntries.filter((entry) => entry.payload.schema === import_schema_payload_plugin.SchemaSchema).forEach((entry) => {
|
|
129
|
+
this.cacheSchemaIfValid(entry);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async fetchSchema(schema) {
|
|
133
|
+
var _a;
|
|
134
|
+
try {
|
|
135
|
+
const domain = await import_domain_payload_plugin.DomainPayloadWrapper.discover(schema, this.proxy);
|
|
136
|
+
await (domain == null ? void 0 : domain.fetch());
|
|
137
|
+
this.cacheSchemas(domain == null ? void 0 : domain.aliases);
|
|
138
|
+
if (this._cache.get(schema) === void 0) {
|
|
139
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
140
|
+
}
|
|
141
|
+
} catch (ex) {
|
|
142
|
+
this._cache.set(schema, _SchemaCache.NULL);
|
|
143
|
+
if ((0, import_axios.isAxiosError)(ex)) {
|
|
144
|
+
console.log(`Axios Url: ${(_a = ex.response) == null ? void 0 : _a.config.url}`);
|
|
145
|
+
}
|
|
146
|
+
(0, import_error.handleError)(ex, (error) => {
|
|
147
|
+
console.error(`fetchSchema threw: ${error.message}`);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
21
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
153
|
0 && (module.exports = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...require("./SchemaNameToValidatorMap")
|
|
154
|
+
Debounce,
|
|
155
|
+
SchemaCache
|
|
26
156
|
});
|
|
27
157
|
//# sourceMappingURL=index.js.map
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './Debounce'\nexport * from './SchemaCache'\nexport * from './SchemaNameToValidatorMap'\n"],"mappings":"
|
|
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;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