@hyperjump/json-schema 0.20.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/json-schema-amd.js +212 -135
- package/dist/json-schema-amd.js.map +1 -1
- package/dist/json-schema-amd.min.js +1 -1
- package/dist/json-schema-amd.min.js.map +1 -1
- package/dist/json-schema-cjs.js +212 -135
- package/dist/json-schema-cjs.js.map +1 -1
- package/dist/json-schema-cjs.min.js +2 -2
- package/dist/json-schema-cjs.min.js.map +1 -1
- package/dist/json-schema-esm.js +212 -135
- package/dist/json-schema-esm.js.map +1 -1
- package/dist/json-schema-esm.min.js +1 -1
- package/dist/json-schema-esm.min.js.map +1 -1
- package/dist/json-schema-iife.js +212 -135
- package/dist/json-schema-iife.js.map +1 -1
- package/dist/json-schema-iife.min.js +1 -1
- package/dist/json-schema-iife.min.js.map +1 -1
- package/dist/json-schema-system.js +212 -135
- package/dist/json-schema-system.js.map +1 -1
- package/dist/json-schema-system.min.js +1 -1
- package/dist/json-schema-system.min.js.map +1 -1
- package/dist/json-schema-umd.js +212 -135
- package/dist/json-schema-umd.js.map +1 -1
- package/dist/json-schema-umd.min.js +2 -2
- package/dist/json-schema-umd.min.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/index.mjs +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,6 +88,48 @@ JsonSchema.setMetaOutputFormat(JsonSchema.FLAG);
|
|
|
88
88
|
JsonSchema.setShouldMetaValidate(false);
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
### Media Types
|
|
92
|
+
JSV has a plugin system for adding support for different media types. By default
|
|
93
|
+
it's configured to accept schemas that have the `application/schema+json`
|
|
94
|
+
Content-Type (web) or a `.schema.json` file extension (filesystem). If for
|
|
95
|
+
example, you want to fetch schemas that are written in YAML, you can add a
|
|
96
|
+
MediaTypePlugin to support that.
|
|
97
|
+
|
|
98
|
+
* **Core.addMediaTypePlugin**: (contentType: string, plugin: MediaTypePlugin) => void
|
|
99
|
+
|
|
100
|
+
Add a custom media type handler to support things like YAML or to change the
|
|
101
|
+
way JSON is supported.
|
|
102
|
+
* **MediaTypePlugin**: object
|
|
103
|
+
|
|
104
|
+
* parse: (response: Response, mediaTypeParameters: object) => [SchemaObject, string]
|
|
105
|
+
|
|
106
|
+
Given a fetch Response object, parse the body of the request. Return the
|
|
107
|
+
parsed schema and an optional default dialectId.
|
|
108
|
+
* matcher: (path) => boolean
|
|
109
|
+
|
|
110
|
+
Given a filesystem path, return whether or not the file should be
|
|
111
|
+
considered a member of this media type.
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const JsonSchema = require("@hyperjump/json-schema");
|
|
115
|
+
const YAML = require("yaml");
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// Add support for JSON Schemas written in YAML
|
|
119
|
+
JsonSchema.addMediaTypePlugin("application/schema+yaml", {
|
|
120
|
+
parse: async (response) => [YAML.parse(await response.text()), undefined],
|
|
121
|
+
matcher: (path) => path.endsWith(".schema.yaml")
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Example: Fetch schema with Content-Type: application/schema+yaml from the web
|
|
125
|
+
const schema = await JsonSchema.get("http://example.com/schemas/string");
|
|
126
|
+
|
|
127
|
+
// Example: Fetch from file with JSON Schema YAML file extension
|
|
128
|
+
const schema = await JsonSchema.get("file:///path/to/my/schemas/string.schema.yaml");
|
|
129
|
+
|
|
130
|
+
// Then validate against your schema like normal
|
|
131
|
+
```
|
|
132
|
+
|
|
91
133
|
## TypeScript
|
|
92
134
|
Although the package is written in JavaScript, type definitions are included for
|
|
93
135
|
TypeScript support. The following example shows the types you might want to
|
package/dist/json-schema-amd.js
CHANGED
|
@@ -1911,7 +1911,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
1911
1911
|
return pointer.split("/").slice(1).map(unescape);
|
|
1912
1912
|
};
|
|
1913
1913
|
|
|
1914
|
-
const get$
|
|
1914
|
+
const get$2 = (pointer, value = undefined) => {
|
|
1915
1915
|
const ptr = compile$P(pointer);
|
|
1916
1916
|
|
|
1917
1917
|
const fn = (value) => ptr.reduce(([value, pointer], segment) => {
|
|
@@ -2030,7 +2030,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2030
2030
|
|
|
2031
2031
|
const isScalar = (value) => value === null || typeof value !== "object";
|
|
2032
2032
|
|
|
2033
|
-
var lib$3 = { nil: nil$2, append, get: get$
|
|
2033
|
+
var lib$3 = { nil: nil$2, append, get: get$2, set, assign, unset, remove };
|
|
2034
2034
|
|
|
2035
2035
|
const $__value = Symbol("$__value");
|
|
2036
2036
|
const $__href = Symbol("$__href");
|
|
@@ -2054,6 +2054,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2054
2054
|
|
|
2055
2055
|
const nil$1 = Object.freeze({ id: "", pointer: "", instance: undefined, value: undefined });
|
|
2056
2056
|
const cons = (instance, id = "") => Object.freeze({ ...nil$1, id: resolveUrl$2(id, ""), instance, value: instance });
|
|
2057
|
+
|
|
2058
|
+
const get$1 = (url, instance = nil$1) => {
|
|
2059
|
+
if (!url.startsWith("#")) {
|
|
2060
|
+
throw Error(`No JSON document found at '${url.split("#")[0]}'`);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
return Object.freeze({ ...instance, pointer: url.substr(1) });
|
|
2064
|
+
};
|
|
2065
|
+
|
|
2057
2066
|
const uri$1 = (doc) => `${doc.id}#${encodeURI(doc.pointer)}`;
|
|
2058
2067
|
const value$1 = (doc) => Reference$2.isReference(doc.value) ? Reference$2.value(doc.value) : doc.value;
|
|
2059
2068
|
const has$1 = (key, doc) => key in value$1(doc);
|
|
@@ -2073,6 +2082,9 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2073
2082
|
const map$4 = curry$8((fn, doc) => value$1(doc)
|
|
2074
2083
|
.map((item, ndx, array, thisArg) => fn(step$1(ndx, doc), ndx, array, thisArg)));
|
|
2075
2084
|
|
|
2085
|
+
const forEach = curry$8((fn, doc) => value$1(doc)
|
|
2086
|
+
.forEach((item, ndx, array, thisArg) => fn(step$1(ndx, doc), ndx, array, thisArg)));
|
|
2087
|
+
|
|
2076
2088
|
const filter$1 = curry$8((fn, doc) => value$1(doc)
|
|
2077
2089
|
.map((item, ndx, array, thisArg) => step$1(ndx, doc))
|
|
2078
2090
|
.filter((item, ndx, array, thisArg) => fn(item, ndx, array, thisArg)));
|
|
@@ -2088,7 +2100,92 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2088
2100
|
|
|
2089
2101
|
const length$1 = (doc) => value$1(doc).length;
|
|
2090
2102
|
|
|
2091
|
-
var instance = {
|
|
2103
|
+
var instance = {
|
|
2104
|
+
nil: nil$1, cons, get: get$1, uri: uri$1, value: value$1, has: has$1, typeOf: typeOf$1, length: length$1,
|
|
2105
|
+
step: step$1, entries: entries$3, keys: keys$1, map: map$4, forEach, filter: filter$1, reduce: reduce$3, every: every$1, some: some$1
|
|
2106
|
+
};
|
|
2107
|
+
|
|
2108
|
+
var entries$2 = async (doc) => Object.entries(await doc);
|
|
2109
|
+
|
|
2110
|
+
const curry$7 = justCurryIt;
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
var map$3 = curry$7(async (fn, doc) => (await doc).map(fn));
|
|
2114
|
+
|
|
2115
|
+
const curry$6 = justCurryIt;
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
var reduce$2 = curry$6(async (fn, acc, doc) => {
|
|
2119
|
+
return (await doc).reduce(async (acc, item) => fn(await acc, item), acc);
|
|
2120
|
+
});
|
|
2121
|
+
|
|
2122
|
+
const curry$5 = justCurryIt;
|
|
2123
|
+
const reduce$1 = reduce$2;
|
|
2124
|
+
|
|
2125
|
+
|
|
2126
|
+
var filter = curry$5(async (fn, doc, options = {}) => {
|
|
2127
|
+
return reduce$1(async (acc, item) => {
|
|
2128
|
+
return (await fn(item)) ? acc.concat([item]) : acc;
|
|
2129
|
+
}, [], doc, options);
|
|
2130
|
+
});
|
|
2131
|
+
|
|
2132
|
+
const curry$4 = justCurryIt;
|
|
2133
|
+
const map$2 = map$3;
|
|
2134
|
+
|
|
2135
|
+
|
|
2136
|
+
var some = curry$4(async (fn, doc) => {
|
|
2137
|
+
const results = await map$2(fn, doc);
|
|
2138
|
+
return (await Promise.all(results))
|
|
2139
|
+
.some((a) => a);
|
|
2140
|
+
});
|
|
2141
|
+
|
|
2142
|
+
const curry$3 = justCurryIt;
|
|
2143
|
+
const map$1 = map$3;
|
|
2144
|
+
|
|
2145
|
+
|
|
2146
|
+
var every = curry$3(async (fn, doc) => {
|
|
2147
|
+
const results = await map$1(fn, doc);
|
|
2148
|
+
return (await Promise.all(results))
|
|
2149
|
+
.every((a) => a);
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
const curry$2 = justCurryIt;
|
|
2153
|
+
|
|
2154
|
+
|
|
2155
|
+
var pipeline$1 = curry$2((fns, doc) => {
|
|
2156
|
+
return fns.reduce(async (acc, fn) => fn(await acc), doc);
|
|
2157
|
+
});
|
|
2158
|
+
|
|
2159
|
+
var all = (doc) => Promise.all(doc);
|
|
2160
|
+
|
|
2161
|
+
const pipeline = pipeline$1;
|
|
2162
|
+
const entries$1 = entries$2;
|
|
2163
|
+
const reduce = reduce$2;
|
|
2164
|
+
|
|
2165
|
+
|
|
2166
|
+
var allValues = (doc) => {
|
|
2167
|
+
return pipeline([
|
|
2168
|
+
entries$1,
|
|
2169
|
+
reduce(async (acc, [propertyName, propertyValue]) => {
|
|
2170
|
+
acc[propertyName] = await propertyValue;
|
|
2171
|
+
return acc;
|
|
2172
|
+
}, {})
|
|
2173
|
+
], doc);
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
var lib$2 = {
|
|
2177
|
+
entries: entries$2,
|
|
2178
|
+
map: map$3,
|
|
2179
|
+
filter: filter,
|
|
2180
|
+
reduce: reduce$2,
|
|
2181
|
+
some: some,
|
|
2182
|
+
every: every,
|
|
2183
|
+
pipeline: pipeline$1,
|
|
2184
|
+
all: all,
|
|
2185
|
+
allValues: allValues
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
var fetch_browser = fetch;
|
|
2092
2189
|
|
|
2093
2190
|
var contentType = {};
|
|
2094
2191
|
|
|
@@ -2144,7 +2241,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2144
2241
|
*/
|
|
2145
2242
|
|
|
2146
2243
|
contentType.format = format$1;
|
|
2147
|
-
contentType.parse = parse;
|
|
2244
|
+
contentType.parse = parse$1;
|
|
2148
2245
|
|
|
2149
2246
|
/**
|
|
2150
2247
|
* Format object to media type.
|
|
@@ -2195,7 +2292,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2195
2292
|
* @public
|
|
2196
2293
|
*/
|
|
2197
2294
|
|
|
2198
|
-
function parse (string) {
|
|
2295
|
+
function parse$1 (string) {
|
|
2199
2296
|
if (!string) {
|
|
2200
2297
|
throw new TypeError('argument string is required')
|
|
2201
2298
|
}
|
|
@@ -2313,102 +2410,54 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2313
2410
|
this.type = type;
|
|
2314
2411
|
}
|
|
2315
2412
|
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
const curry$7 = justCurryIt;
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
var map$3 = curry$7(async (fn, doc) => (await doc).map(fn));
|
|
2322
|
-
|
|
2323
|
-
const curry$6 = justCurryIt;
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
var reduce$2 = curry$6(async (fn, acc, doc) => {
|
|
2327
|
-
return (await doc).reduce(async (acc, item) => fn(await acc, item), acc);
|
|
2328
|
-
});
|
|
2329
|
-
|
|
2330
|
-
const curry$5 = justCurryIt;
|
|
2331
|
-
const reduce$1 = reduce$2;
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
var filter = curry$5(async (fn, doc, options = {}) => {
|
|
2335
|
-
return reduce$1(async (acc, item) => {
|
|
2336
|
-
return (await fn(item)) ? acc.concat([item]) : acc;
|
|
2337
|
-
}, [], doc, options);
|
|
2338
|
-
});
|
|
2339
|
-
|
|
2340
|
-
const curry$4 = justCurryIt;
|
|
2341
|
-
const map$2 = map$3;
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
var some = curry$4(async (fn, doc) => {
|
|
2345
|
-
const results = await map$2(fn, doc);
|
|
2346
|
-
return (await Promise.all(results))
|
|
2347
|
-
.some((a) => a);
|
|
2348
|
-
});
|
|
2349
|
-
|
|
2350
|
-
const curry$3 = justCurryIt;
|
|
2351
|
-
const map$1 = map$3;
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
var every = curry$3(async (fn, doc) => {
|
|
2355
|
-
const results = await map$1(fn, doc);
|
|
2356
|
-
return (await Promise.all(results))
|
|
2357
|
-
.every((a) => a);
|
|
2358
|
-
});
|
|
2359
|
-
|
|
2360
|
-
const curry$2 = justCurryIt;
|
|
2361
|
-
|
|
2413
|
+
const contentTypeParser = contentType;
|
|
2362
2414
|
|
|
2363
|
-
var pipeline$1 = curry$2((fns, doc) => {
|
|
2364
|
-
return fns.reduce(async (acc, fn) => fn(await acc), doc);
|
|
2365
|
-
});
|
|
2366
2415
|
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
const pipeline = pipeline$1;
|
|
2370
|
-
const entries$1 = entries$2;
|
|
2371
|
-
const reduce = reduce$2;
|
|
2416
|
+
const mediaTypePlugins = {};
|
|
2372
2417
|
|
|
2418
|
+
const addPlugin = (contentType, plugin) => {
|
|
2419
|
+
mediaTypePlugins[contentType] = plugin;
|
|
2420
|
+
};
|
|
2373
2421
|
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
}, {})
|
|
2381
|
-
], doc);
|
|
2422
|
+
const parse = (response) => {
|
|
2423
|
+
const contentType = contentTypeParser.parse(response.headers.get("content-type"));
|
|
2424
|
+
if (!(contentType.type in mediaTypePlugins)) {
|
|
2425
|
+
throw Error(`${response.url} is not a schema. Found a document with media type: ${contentType.type}`);
|
|
2426
|
+
}
|
|
2427
|
+
return mediaTypePlugins[contentType.type].parse(response, contentType.parameters);
|
|
2382
2428
|
};
|
|
2383
2429
|
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
all: all,
|
|
2393
|
-
allValues: allValues
|
|
2430
|
+
const getContentType = (path) => {
|
|
2431
|
+
for (const contentType in mediaTypePlugins) {
|
|
2432
|
+
if (mediaTypePlugins[contentType].matcher(path)) {
|
|
2433
|
+
return contentType;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
return "application/octet-stream";
|
|
2394
2438
|
};
|
|
2395
2439
|
|
|
2396
|
-
var
|
|
2440
|
+
var mediaTypes = { addPlugin, parse, getContentType };
|
|
2397
2441
|
|
|
2398
|
-
const contentTypeParser = contentType;
|
|
2399
2442
|
const curry$1 = justCurryIt;
|
|
2400
2443
|
const Pact$a = lib$2;
|
|
2401
2444
|
const JsonPointer = lib$3;
|
|
2402
2445
|
const { jsonTypeOf, resolveUrl: resolveUrl$1, urlFragment, pathRelative } = common$1;
|
|
2403
2446
|
const fetch$1 = fetch_browser;
|
|
2404
2447
|
const Reference$1 = reference;
|
|
2448
|
+
const MediaTypes$1 = mediaTypes;
|
|
2449
|
+
|
|
2405
2450
|
|
|
2451
|
+
const core201909Id = "https://json-schema.org/draft/2019-09/vocab/core";
|
|
2452
|
+
const core202012Id = "https://json-schema.org/draft/2020-12/vocab/core";
|
|
2406
2453
|
|
|
2407
2454
|
// Config
|
|
2408
2455
|
const config = {};
|
|
2409
2456
|
const dialectJsonSchemaVersion = {};
|
|
2410
2457
|
|
|
2411
2458
|
const setConfig = (jsonSchemaVersion, key, value) => {
|
|
2459
|
+
dialectJsonSchemaVersion[jsonSchemaVersion] = jsonSchemaVersion;
|
|
2460
|
+
|
|
2412
2461
|
if (!config[jsonSchemaVersion]) {
|
|
2413
2462
|
config[jsonSchemaVersion] = {};
|
|
2414
2463
|
}
|
|
@@ -2416,10 +2465,8 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2416
2465
|
};
|
|
2417
2466
|
|
|
2418
2467
|
const getConfig = (dialectId, key) => {
|
|
2419
|
-
const jsonSchemaVersion = dialectJsonSchemaVersion[dialectId]
|
|
2420
|
-
|
|
2421
|
-
return config[jsonSchemaVersion][key];
|
|
2422
|
-
}
|
|
2468
|
+
const jsonSchemaVersion = dialectJsonSchemaVersion[dialectId];
|
|
2469
|
+
return config[jsonSchemaVersion]?.[key];
|
|
2423
2470
|
};
|
|
2424
2471
|
|
|
2425
2472
|
// Schema Management
|
|
@@ -2428,6 +2475,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2428
2475
|
|
|
2429
2476
|
const add$1 = (schema, url = "", defaultSchemaVersion = "") => {
|
|
2430
2477
|
schema = JSON.parse(JSON.stringify(schema));
|
|
2478
|
+
const externalId = resolveUrl$1(url, "");
|
|
2431
2479
|
|
|
2432
2480
|
// Dialect / JSON Schema Version
|
|
2433
2481
|
const dialectId = resolveUrl$1(schema["$schema"] || defaultSchemaVersion, "");
|
|
@@ -2436,35 +2484,45 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2436
2484
|
}
|
|
2437
2485
|
delete schema["$schema"];
|
|
2438
2486
|
|
|
2439
|
-
|
|
2440
|
-
if (
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2487
|
+
// Determine JSON Schema version
|
|
2488
|
+
if (!(dialectId in dialectJsonSchemaVersion)) {
|
|
2489
|
+
if (schema?.$vocabulary?.[core201909Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core201909Id)[0]) {
|
|
2490
|
+
// Self describing 2019-09 meta-schema
|
|
2491
|
+
dialectJsonSchemaVersion[dialectId] = core201909Id;
|
|
2492
|
+
} else if (schema?.$vocabulary?.[core202012Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core202012Id)[0]) {
|
|
2493
|
+
// Self describing 2020-12 meta-schema
|
|
2494
|
+
dialectJsonSchemaVersion[dialectId] = core202012Id;
|
|
2495
|
+
} else {
|
|
2496
|
+
// Need to look at meta-schema to determine version
|
|
2497
|
+
const metaSchema = schemaStore[dialectId];
|
|
2498
|
+
if (!metaSchema) {
|
|
2499
|
+
throw Error(`Couldn't determine JSON Schema version for dialect: '${dialectId}'`);
|
|
2500
|
+
} else if (metaSchema.vocabulary[core201909Id] === true) {
|
|
2501
|
+
dialectJsonSchemaVersion[dialectId] = core201909Id;
|
|
2502
|
+
} else if (metaSchema.vocabulary[core202012Id] === true) {
|
|
2503
|
+
dialectJsonSchemaVersion[dialectId] = core202012Id;
|
|
2504
|
+
} else {
|
|
2505
|
+
// Assume the jsonSchemaVersion is the meta-schema's dialectId (non-standard behavior)
|
|
2506
|
+
dialectJsonSchemaVersion[dialectId] = dialectJsonSchemaVersion[metaSchema.dialectId];
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2446
2509
|
}
|
|
2447
2510
|
|
|
2448
|
-
// Identifier
|
|
2449
|
-
const
|
|
2450
|
-
|
|
2451
|
-
const externalId = resolveUrl$1(url, "");
|
|
2452
|
-
if (!externalId && !resolveUrl$1(schema[baseToken] || "", "")) {
|
|
2511
|
+
// Internal Identifier
|
|
2512
|
+
const [id, fragment] = getSchemaIdentifier(schema, externalId, dialectJsonSchemaVersion[dialectId]);
|
|
2513
|
+
if (!id) {
|
|
2453
2514
|
throw Error("Couldn't determine an identifier for the schema");
|
|
2454
2515
|
}
|
|
2455
|
-
const
|
|
2456
|
-
const id = resolveUrl$1(internalUrl, "");
|
|
2457
|
-
const fragment = urlFragment(internalUrl);
|
|
2516
|
+
const baseToken = getConfig(dialectId, "baseToken");
|
|
2458
2517
|
delete schema[baseToken];
|
|
2459
|
-
if (fragment && baseToken === anchorToken) {
|
|
2460
|
-
schema[anchorToken] = anchorToken !== baseToken ? encodeURI(fragment) : `#${encodeURI(fragment)}`;
|
|
2461
|
-
}
|
|
2462
2518
|
if (externalId) {
|
|
2463
2519
|
schemaStoreAlias[externalId] = id;
|
|
2464
2520
|
}
|
|
2465
2521
|
|
|
2466
|
-
|
|
2467
|
-
|
|
2522
|
+
const anchorToken = getConfig(dialectId, "anchorToken");
|
|
2523
|
+
if (fragment && baseToken === anchorToken) {
|
|
2524
|
+
schema[anchorToken] = anchorToken !== baseToken ? encodeURI(fragment) : `#${encodeURI(fragment)}`;
|
|
2525
|
+
}
|
|
2468
2526
|
|
|
2469
2527
|
// recursiveAnchor
|
|
2470
2528
|
const dynamicAnchors = {};
|
|
@@ -2500,6 +2558,12 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2500
2558
|
return id;
|
|
2501
2559
|
};
|
|
2502
2560
|
|
|
2561
|
+
const getSchemaIdentifier = (schema, externalId, jsonSchemaVersion) => {
|
|
2562
|
+
const baseToken = config[jsonSchemaVersion]?.["baseToken"];
|
|
2563
|
+
const internalUrl = resolveUrl$1(externalId, schema[baseToken] || "");
|
|
2564
|
+
return [resolveUrl$1(internalUrl, ""), urlFragment(internalUrl)];
|
|
2565
|
+
};
|
|
2566
|
+
|
|
2503
2567
|
const processSchema = (subject, id, dialectId, pointer, anchors, dynamicAnchors) => {
|
|
2504
2568
|
if (jsonTypeOf(subject, "object")) {
|
|
2505
2569
|
const embeddedSchemaDialectId = typeof subject.$schema === "string" ? resolveUrl$1(subject.$schema, "") : dialectId;
|
|
@@ -2577,14 +2641,15 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2577
2641
|
throw Error(`Failed to retrieve schema with id: ${id}`);
|
|
2578
2642
|
}
|
|
2579
2643
|
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2644
|
+
const [schema, defaultDialectId] = await MediaTypes$1.parse(response);
|
|
2645
|
+
|
|
2646
|
+
// Make sure the meta-schema is loaded if this isn't a known dialect
|
|
2647
|
+
const dialectId = resolveUrl$1(schema.$schema, "") || defaultDialectId;
|
|
2648
|
+
if (id !== dialectId && !(dialectId in dialectJsonSchemaVersion)) {
|
|
2649
|
+
await get(dialectId);
|
|
2585
2650
|
}
|
|
2586
2651
|
|
|
2587
|
-
add$1(
|
|
2652
|
+
add$1(schema, id);
|
|
2588
2653
|
}
|
|
2589
2654
|
|
|
2590
2655
|
const storedSchema = getStoredSchema(id);
|
|
@@ -2721,12 +2786,22 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2721
2786
|
|
|
2722
2787
|
var invalidSchemaError = InvalidSchemaError$3;
|
|
2723
2788
|
|
|
2789
|
+
const Schema$R = schema$5;
|
|
2790
|
+
|
|
2791
|
+
|
|
2792
|
+
const compile$O = (schema) => Schema$R.value(schema);
|
|
2793
|
+
const interpret$O = () => true;
|
|
2794
|
+
|
|
2795
|
+
var metaData$4 = { compile: compile$O, interpret: interpret$O };
|
|
2796
|
+
|
|
2724
2797
|
const curry = justCurryIt;
|
|
2725
2798
|
const PubSub$1 = pubsub.exports;
|
|
2726
2799
|
const { resolveUrl } = common$1;
|
|
2727
2800
|
const Instance$E = instance;
|
|
2728
|
-
const Schema$
|
|
2801
|
+
const Schema$Q = schema$5;
|
|
2729
2802
|
const InvalidSchemaError$2 = invalidSchemaError;
|
|
2803
|
+
const MediaTypes = mediaTypes;
|
|
2804
|
+
const metaData$3 = metaData$4;
|
|
2730
2805
|
|
|
2731
2806
|
|
|
2732
2807
|
const FLAG = "FLAG", BASIC = "BASIC", DETAILED = "DETAILED", VERBOSE = "VERBOSE";
|
|
@@ -2734,20 +2809,28 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2734
2809
|
let metaOutputFormat = DETAILED;
|
|
2735
2810
|
let shouldMetaValidate = true;
|
|
2736
2811
|
|
|
2812
|
+
MediaTypes.addPlugin("application/schema+json", {
|
|
2813
|
+
parse: async (response, contentTypeParameters) => [
|
|
2814
|
+
await response.json(),
|
|
2815
|
+
contentTypeParameters.schema || contentTypeParameters.profile
|
|
2816
|
+
],
|
|
2817
|
+
matcher: (path) => path.endsWith(".schema.json")
|
|
2818
|
+
});
|
|
2819
|
+
|
|
2737
2820
|
const validate$2 = async (schema, value = undefined, outputFormat = undefined) => {
|
|
2738
|
-
const compiled = await compile$
|
|
2739
|
-
const interpretAst = (value, outputFormat) => interpret$
|
|
2821
|
+
const compiled = await compile$N(schema);
|
|
2822
|
+
const interpretAst = (value, outputFormat) => interpret$N(compiled, Instance$E.cons(value), outputFormat);
|
|
2740
2823
|
|
|
2741
2824
|
return value === undefined ? interpretAst : interpretAst(value, outputFormat);
|
|
2742
2825
|
};
|
|
2743
2826
|
|
|
2744
|
-
const compile$
|
|
2827
|
+
const compile$N = async (schema) => {
|
|
2745
2828
|
const ast = { metaData: {} };
|
|
2746
2829
|
const schemaUri = await compileSchema(schema, ast);
|
|
2747
2830
|
return { ast, schemaUri };
|
|
2748
2831
|
};
|
|
2749
2832
|
|
|
2750
|
-
const interpret$
|
|
2833
|
+
const interpret$N = curry(({ ast, schemaUri }, value, outputFormat = FLAG) => {
|
|
2751
2834
|
if (![FLAG, BASIC, DETAILED, VERBOSE].includes(outputFormat)) {
|
|
2752
2835
|
throw Error(`The '${outputFormat}' error format is not supported`);
|
|
2753
2836
|
}
|
|
@@ -2801,7 +2884,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2801
2884
|
};
|
|
2802
2885
|
|
|
2803
2886
|
const _keywords = {};
|
|
2804
|
-
const getKeyword = (id) => _keywords[id];
|
|
2887
|
+
const getKeyword = (id) => _keywords[id] || metaData$3;
|
|
2805
2888
|
const hasKeyword = (id) => id in _keywords;
|
|
2806
2889
|
const addKeyword = (id, keywordHandler) => {
|
|
2807
2890
|
_keywords[id] = {
|
|
@@ -2822,10 +2905,10 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2822
2905
|
|
|
2823
2906
|
// Vocabularies
|
|
2824
2907
|
if (!hasKeyword(`${schema.dialectId}#validate`)) {
|
|
2825
|
-
const metaSchema = await Schema$
|
|
2908
|
+
const metaSchema = await Schema$Q.get(schema.dialectId);
|
|
2826
2909
|
|
|
2827
2910
|
// Check for mandatory vocabularies
|
|
2828
|
-
const mandatoryVocabularies = Schema$
|
|
2911
|
+
const mandatoryVocabularies = Schema$Q.getConfig(metaSchema.id, "mandatoryVocabularies") || [];
|
|
2829
2912
|
mandatoryVocabularies.forEach((vocabularyId) => {
|
|
2830
2913
|
if (!metaSchema.vocabulary[vocabularyId]) {
|
|
2831
2914
|
throw Error(`Vocabulary '${vocabularyId}' must be explicitly declared and required`);
|
|
@@ -2848,13 +2931,13 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2848
2931
|
|
|
2849
2932
|
// Meta validation
|
|
2850
2933
|
if (shouldMetaValidate && !schema.validated) {
|
|
2851
|
-
Schema$
|
|
2934
|
+
Schema$Q.markValidated(schema.id);
|
|
2852
2935
|
|
|
2853
2936
|
// Compile
|
|
2854
2937
|
if (!(schema.dialectId in metaValidators)) {
|
|
2855
|
-
const metaSchema = await Schema$
|
|
2856
|
-
const compiledSchema = await compile$
|
|
2857
|
-
metaValidators[metaSchema.id] = interpret$
|
|
2938
|
+
const metaSchema = await Schema$Q.get(schema.dialectId);
|
|
2939
|
+
const compiledSchema = await compile$N(metaSchema);
|
|
2940
|
+
metaValidators[metaSchema.id] = interpret$N(compiledSchema);
|
|
2858
2941
|
}
|
|
2859
2942
|
|
|
2860
2943
|
// Interpret
|
|
@@ -2877,7 +2960,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2877
2960
|
};
|
|
2878
2961
|
|
|
2879
2962
|
const followReferences = async (doc) => {
|
|
2880
|
-
return Schema$
|
|
2963
|
+
return Schema$Q.typeOf(doc, "string") ? followReferences(await Schema$Q.get(Schema$Q.value(doc), doc)) : doc;
|
|
2881
2964
|
};
|
|
2882
2965
|
|
|
2883
2966
|
const interpretSchema = (schemaUri, instance, ast, dynamicAnchors) => {
|
|
@@ -2905,25 +2988,18 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2905
2988
|
};
|
|
2906
2989
|
|
|
2907
2990
|
const add = (schema, url = "", defaultSchemaVersion = "") => {
|
|
2908
|
-
const id = Schema$
|
|
2991
|
+
const id = Schema$Q.add(schema, url, defaultSchemaVersion);
|
|
2909
2992
|
delete metaValidators[id];
|
|
2910
2993
|
};
|
|
2911
2994
|
|
|
2912
2995
|
var core$2 = {
|
|
2913
|
-
validate: validate$2, compile: compile$
|
|
2996
|
+
validate: validate$2, compile: compile$N, interpret: interpret$N,
|
|
2914
2997
|
setMetaOutputFormat, setShouldMetaValidate, FLAG, BASIC, DETAILED, VERBOSE,
|
|
2915
2998
|
add, getKeyword, hasKeyword, defineVocabulary,
|
|
2916
|
-
compileSchema, interpretSchema, collectEvaluatedProperties: collectEvaluatedProperties$e, collectEvaluatedItems: collectEvaluatedItems$f
|
|
2999
|
+
compileSchema, interpretSchema, collectEvaluatedProperties: collectEvaluatedProperties$e, collectEvaluatedItems: collectEvaluatedItems$f,
|
|
3000
|
+
addMediaTypePlugin: MediaTypes.addPlugin
|
|
2917
3001
|
};
|
|
2918
3002
|
|
|
2919
|
-
const Schema$Q = schema$5;
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
const compile$N = (schema) => Schema$Q.value(schema);
|
|
2923
|
-
const interpret$N = () => true;
|
|
2924
|
-
|
|
2925
|
-
var metaData$3 = { compile: compile$N, interpret: interpret$N };
|
|
2926
|
-
|
|
2927
3003
|
const Pact$9 = lib$2;
|
|
2928
3004
|
const PubSub = pubsub.exports;
|
|
2929
3005
|
const Core$x = core$2;
|
|
@@ -2947,7 +3023,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
2947
3023
|
typeof schemaValue === "boolean" ? schemaValue : await Pact$9.pipeline([
|
|
2948
3024
|
Schema$P.entries,
|
|
2949
3025
|
Pact$9.map(([keyword, keywordSchema]) => [`${schema.dialectId}#${keyword}`, keywordSchema]),
|
|
2950
|
-
Pact$9.filter(([keywordId]) =>
|
|
3026
|
+
Pact$9.filter(([keywordId]) => keywordId !== `${schema.dialectId}#validate`),
|
|
2951
3027
|
Pact$9.map(async ([keywordId, keywordSchema]) => {
|
|
2952
3028
|
const keywordAst = await Core$x.getKeyword(keywordId).compile(keywordSchema, ast, schema);
|
|
2953
3029
|
return [keywordId, Schema$P.uri(keywordSchema), keywordAst];
|
|
@@ -3023,7 +3099,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
3023
3099
|
|
|
3024
3100
|
var validate$1 = { compile: compile$M, interpret: interpret$M, collectEvaluatedProperties: collectEvaluatedProperties$d, collectEvaluatedItems: collectEvaluatedItems$e };
|
|
3025
3101
|
|
|
3026
|
-
const metaData$2 = metaData$
|
|
3102
|
+
const metaData$2 = metaData$4;
|
|
3027
3103
|
const validate = validate$1;
|
|
3028
3104
|
|
|
3029
3105
|
|
|
@@ -5627,6 +5703,7 @@ define(['exports'], (function (exports) { 'use strict';
|
|
|
5627
5703
|
interpret: Core.interpret,
|
|
5628
5704
|
setMetaOutputFormat: Core.setMetaOutputFormat,
|
|
5629
5705
|
setShouldMetaValidate: Core.setShouldMetaValidate,
|
|
5706
|
+
addMediaTypePlugin: Core.addMediaTypePlugin,
|
|
5630
5707
|
FLAG: Core.FLAG,
|
|
5631
5708
|
BASIC: Core.BASIC,
|
|
5632
5709
|
DETAILED: Core.DETAILED,
|