@hyperjump/json-schema 0.20.0 → 0.21.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 +37 -0
- package/dist/json-schema-amd.js +155 -109
- 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 +155 -109
- package/dist/json-schema-cjs.js.map +1 -1
- package/dist/json-schema-cjs.min.js +1 -1
- package/dist/json-schema-cjs.min.js.map +1 -1
- package/dist/json-schema-esm.js +155 -109
- 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 +155 -109
- 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 +155 -109
- 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 +155 -109
- 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/dist/json-schema-iife.js
CHANGED
|
@@ -2091,6 +2091,88 @@ var JsonSchema = (function (exports) {
|
|
|
2091
2091
|
|
|
2092
2092
|
var instance = { nil: nil$1, cons, uri: uri$1, value: value$1, has: has$1, typeOf: typeOf$1, step: step$1, entries: entries$3, keys: keys$1, map: map$4, filter: filter$1, reduce: reduce$3, every: every$1, some: some$1, length: length$1 };
|
|
2093
2093
|
|
|
2094
|
+
var entries$2 = async (doc) => Object.entries(await doc);
|
|
2095
|
+
|
|
2096
|
+
const curry$7 = justCurryIt;
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
var map$3 = curry$7(async (fn, doc) => (await doc).map(fn));
|
|
2100
|
+
|
|
2101
|
+
const curry$6 = justCurryIt;
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
var reduce$2 = curry$6(async (fn, acc, doc) => {
|
|
2105
|
+
return (await doc).reduce(async (acc, item) => fn(await acc, item), acc);
|
|
2106
|
+
});
|
|
2107
|
+
|
|
2108
|
+
const curry$5 = justCurryIt;
|
|
2109
|
+
const reduce$1 = reduce$2;
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
var filter = curry$5(async (fn, doc, options = {}) => {
|
|
2113
|
+
return reduce$1(async (acc, item) => {
|
|
2114
|
+
return (await fn(item)) ? acc.concat([item]) : acc;
|
|
2115
|
+
}, [], doc, options);
|
|
2116
|
+
});
|
|
2117
|
+
|
|
2118
|
+
const curry$4 = justCurryIt;
|
|
2119
|
+
const map$2 = map$3;
|
|
2120
|
+
|
|
2121
|
+
|
|
2122
|
+
var some = curry$4(async (fn, doc) => {
|
|
2123
|
+
const results = await map$2(fn, doc);
|
|
2124
|
+
return (await Promise.all(results))
|
|
2125
|
+
.some((a) => a);
|
|
2126
|
+
});
|
|
2127
|
+
|
|
2128
|
+
const curry$3 = justCurryIt;
|
|
2129
|
+
const map$1 = map$3;
|
|
2130
|
+
|
|
2131
|
+
|
|
2132
|
+
var every = curry$3(async (fn, doc) => {
|
|
2133
|
+
const results = await map$1(fn, doc);
|
|
2134
|
+
return (await Promise.all(results))
|
|
2135
|
+
.every((a) => a);
|
|
2136
|
+
});
|
|
2137
|
+
|
|
2138
|
+
const curry$2 = justCurryIt;
|
|
2139
|
+
|
|
2140
|
+
|
|
2141
|
+
var pipeline$1 = curry$2((fns, doc) => {
|
|
2142
|
+
return fns.reduce(async (acc, fn) => fn(await acc), doc);
|
|
2143
|
+
});
|
|
2144
|
+
|
|
2145
|
+
var all = (doc) => Promise.all(doc);
|
|
2146
|
+
|
|
2147
|
+
const pipeline = pipeline$1;
|
|
2148
|
+
const entries$1 = entries$2;
|
|
2149
|
+
const reduce = reduce$2;
|
|
2150
|
+
|
|
2151
|
+
|
|
2152
|
+
var allValues = (doc) => {
|
|
2153
|
+
return pipeline([
|
|
2154
|
+
entries$1,
|
|
2155
|
+
reduce(async (acc, [propertyName, propertyValue]) => {
|
|
2156
|
+
acc[propertyName] = await propertyValue;
|
|
2157
|
+
return acc;
|
|
2158
|
+
}, {})
|
|
2159
|
+
], doc);
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2162
|
+
var lib$2 = {
|
|
2163
|
+
entries: entries$2,
|
|
2164
|
+
map: map$3,
|
|
2165
|
+
filter: filter,
|
|
2166
|
+
reduce: reduce$2,
|
|
2167
|
+
some: some,
|
|
2168
|
+
every: every,
|
|
2169
|
+
pipeline: pipeline$1,
|
|
2170
|
+
all: all,
|
|
2171
|
+
allValues: allValues
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
var fetch_browser = fetch;
|
|
2175
|
+
|
|
2094
2176
|
var contentType = {};
|
|
2095
2177
|
|
|
2096
2178
|
/*!
|
|
@@ -2145,7 +2227,7 @@ var JsonSchema = (function (exports) {
|
|
|
2145
2227
|
*/
|
|
2146
2228
|
|
|
2147
2229
|
contentType.format = format$1;
|
|
2148
|
-
contentType.parse = parse;
|
|
2230
|
+
contentType.parse = parse$1;
|
|
2149
2231
|
|
|
2150
2232
|
/**
|
|
2151
2233
|
* Format object to media type.
|
|
@@ -2196,7 +2278,7 @@ var JsonSchema = (function (exports) {
|
|
|
2196
2278
|
* @public
|
|
2197
2279
|
*/
|
|
2198
2280
|
|
|
2199
|
-
function parse (string) {
|
|
2281
|
+
function parse$1 (string) {
|
|
2200
2282
|
if (!string) {
|
|
2201
2283
|
throw new TypeError('argument string is required')
|
|
2202
2284
|
}
|
|
@@ -2314,97 +2396,47 @@ var JsonSchema = (function (exports) {
|
|
|
2314
2396
|
this.type = type;
|
|
2315
2397
|
}
|
|
2316
2398
|
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
const curry$7 = justCurryIt;
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
var map$3 = curry$7(async (fn, doc) => (await doc).map(fn));
|
|
2323
|
-
|
|
2324
|
-
const curry$6 = justCurryIt;
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
var reduce$2 = curry$6(async (fn, acc, doc) => {
|
|
2328
|
-
return (await doc).reduce(async (acc, item) => fn(await acc, item), acc);
|
|
2329
|
-
});
|
|
2330
|
-
|
|
2331
|
-
const curry$5 = justCurryIt;
|
|
2332
|
-
const reduce$1 = reduce$2;
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
var filter = curry$5(async (fn, doc, options = {}) => {
|
|
2336
|
-
return reduce$1(async (acc, item) => {
|
|
2337
|
-
return (await fn(item)) ? acc.concat([item]) : acc;
|
|
2338
|
-
}, [], doc, options);
|
|
2339
|
-
});
|
|
2340
|
-
|
|
2341
|
-
const curry$4 = justCurryIt;
|
|
2342
|
-
const map$2 = map$3;
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
var some = curry$4(async (fn, doc) => {
|
|
2346
|
-
const results = await map$2(fn, doc);
|
|
2347
|
-
return (await Promise.all(results))
|
|
2348
|
-
.some((a) => a);
|
|
2349
|
-
});
|
|
2350
|
-
|
|
2351
|
-
const curry$3 = justCurryIt;
|
|
2352
|
-
const map$1 = map$3;
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
var every = curry$3(async (fn, doc) => {
|
|
2356
|
-
const results = await map$1(fn, doc);
|
|
2357
|
-
return (await Promise.all(results))
|
|
2358
|
-
.every((a) => a);
|
|
2359
|
-
});
|
|
2360
|
-
|
|
2361
|
-
const curry$2 = justCurryIt;
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
var pipeline$1 = curry$2((fns, doc) => {
|
|
2365
|
-
return fns.reduce(async (acc, fn) => fn(await acc), doc);
|
|
2366
|
-
});
|
|
2399
|
+
const contentTypeParser = contentType;
|
|
2367
2400
|
|
|
2368
|
-
var all = (doc) => Promise.all(doc);
|
|
2369
2401
|
|
|
2370
|
-
const
|
|
2371
|
-
const entries$1 = entries$2;
|
|
2372
|
-
const reduce = reduce$2;
|
|
2402
|
+
const mediaTypePlugins = {};
|
|
2373
2403
|
|
|
2404
|
+
const addPlugin = (contentType, plugin) => {
|
|
2405
|
+
mediaTypePlugins[contentType] = plugin;
|
|
2406
|
+
};
|
|
2374
2407
|
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
}, {})
|
|
2382
|
-
], doc);
|
|
2408
|
+
const parse = (response) => {
|
|
2409
|
+
const contentType = contentTypeParser.parse(response.headers.get("content-type")).type;
|
|
2410
|
+
if (!(contentType in mediaTypePlugins)) {
|
|
2411
|
+
throw Error(`${response.url} is not a schema. Found a document with media type: ${contentType}`);
|
|
2412
|
+
}
|
|
2413
|
+
return mediaTypePlugins[contentType].parse(response);
|
|
2383
2414
|
};
|
|
2384
2415
|
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
all: all,
|
|
2394
|
-
allValues: allValues
|
|
2416
|
+
const getContentType = (path) => {
|
|
2417
|
+
for (const contentType in mediaTypePlugins) {
|
|
2418
|
+
if (mediaTypePlugins[contentType].matcher(path)) {
|
|
2419
|
+
return contentType;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
return "application/octet-stream";
|
|
2395
2424
|
};
|
|
2396
2425
|
|
|
2397
|
-
var
|
|
2426
|
+
var mediaTypes = { addPlugin, parse, getContentType };
|
|
2398
2427
|
|
|
2399
|
-
const contentTypeParser = contentType;
|
|
2400
2428
|
const curry$1 = justCurryIt;
|
|
2401
2429
|
const Pact$a = lib$2;
|
|
2402
2430
|
const JsonPointer = lib$3;
|
|
2403
2431
|
const { jsonTypeOf, resolveUrl: resolveUrl$1, urlFragment, pathRelative } = common$1;
|
|
2404
2432
|
const fetch$1 = fetch_browser;
|
|
2405
2433
|
const Reference$1 = reference;
|
|
2434
|
+
const MediaTypes$1 = mediaTypes;
|
|
2406
2435
|
|
|
2407
2436
|
|
|
2437
|
+
const core201909Id = "https://json-schema.org/draft/2019-09/vocab/core";
|
|
2438
|
+
const core202012Id = "https://json-schema.org/draft/2020-12/vocab/core";
|
|
2439
|
+
|
|
2408
2440
|
// Config
|
|
2409
2441
|
const config = {};
|
|
2410
2442
|
const dialectJsonSchemaVersion = {};
|
|
@@ -2417,10 +2449,8 @@ var JsonSchema = (function (exports) {
|
|
|
2417
2449
|
};
|
|
2418
2450
|
|
|
2419
2451
|
const getConfig = (dialectId, key) => {
|
|
2420
|
-
const jsonSchemaVersion = dialectJsonSchemaVersion[dialectId]
|
|
2421
|
-
|
|
2422
|
-
return config[jsonSchemaVersion][key];
|
|
2423
|
-
}
|
|
2452
|
+
const jsonSchemaVersion = dialectJsonSchemaVersion[dialectId];
|
|
2453
|
+
return config[jsonSchemaVersion]?.[key];
|
|
2424
2454
|
};
|
|
2425
2455
|
|
|
2426
2456
|
// Schema Management
|
|
@@ -2429,6 +2459,7 @@ var JsonSchema = (function (exports) {
|
|
|
2429
2459
|
|
|
2430
2460
|
const add$1 = (schema, url = "", defaultSchemaVersion = "") => {
|
|
2431
2461
|
schema = JSON.parse(JSON.stringify(schema));
|
|
2462
|
+
const externalId = resolveUrl$1(url, "");
|
|
2432
2463
|
|
|
2433
2464
|
// Dialect / JSON Schema Version
|
|
2434
2465
|
const dialectId = resolveUrl$1(schema["$schema"] || defaultSchemaVersion, "");
|
|
@@ -2437,35 +2468,43 @@ var JsonSchema = (function (exports) {
|
|
|
2437
2468
|
}
|
|
2438
2469
|
delete schema["$schema"];
|
|
2439
2470
|
|
|
2440
|
-
|
|
2441
|
-
if (
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2471
|
+
// JSON Schema version
|
|
2472
|
+
if (!(dialectId in dialectJsonSchemaVersion)) {
|
|
2473
|
+
if (schema?.$vocabulary?.[core201909Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core201909Id)[0]) {
|
|
2474
|
+
dialectJsonSchemaVersion[dialectId] = core201909Id;
|
|
2475
|
+
} else if (schema?.$vocabulary?.[core202012Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core202012Id)[0]) {
|
|
2476
|
+
dialectJsonSchemaVersion[dialectId] = core202012Id;
|
|
2477
|
+
} else if (dialectId === getSchemaIdentifier(schema, externalId, dialectId)[0]) {
|
|
2478
|
+
dialectJsonSchemaVersion[dialectId] = dialectId;
|
|
2479
|
+
} else if (!(dialectId in schemaStore)) {
|
|
2480
|
+
throw Error(`Couldn't determine JSON Schema version for dialect: '${dialectId}'`);
|
|
2481
|
+
} else {
|
|
2482
|
+
const metaSchema = schemaStore[dialectId];
|
|
2483
|
+
if (metaSchema.vocabulary[core201909Id] === true) {
|
|
2484
|
+
dialectJsonSchemaVersion[dialectId] = core201909Id;
|
|
2485
|
+
} else if (metaSchema.vocabulary[core202012Id] === true) {
|
|
2486
|
+
dialectJsonSchemaVersion[dialectId] = core202012Id;
|
|
2487
|
+
} else {
|
|
2488
|
+
dialectJsonSchemaVersion[dialectId] = dialectJsonSchemaVersion[metaSchema.dialectId];
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2447
2491
|
}
|
|
2448
2492
|
|
|
2449
|
-
// Identifier
|
|
2450
|
-
const
|
|
2451
|
-
|
|
2452
|
-
const externalId = resolveUrl$1(url, "");
|
|
2453
|
-
if (!externalId && !resolveUrl$1(schema[baseToken] || "", "")) {
|
|
2493
|
+
// Internal Identifier
|
|
2494
|
+
const [id, fragment] = getSchemaIdentifier(schema, externalId, dialectJsonSchemaVersion[dialectId]);
|
|
2495
|
+
if (!id) {
|
|
2454
2496
|
throw Error("Couldn't determine an identifier for the schema");
|
|
2455
2497
|
}
|
|
2456
|
-
const
|
|
2457
|
-
const id = resolveUrl$1(internalUrl, "");
|
|
2458
|
-
const fragment = urlFragment(internalUrl);
|
|
2498
|
+
const baseToken = getConfig(dialectId, "baseToken");
|
|
2459
2499
|
delete schema[baseToken];
|
|
2460
|
-
if (fragment && baseToken === anchorToken) {
|
|
2461
|
-
schema[anchorToken] = anchorToken !== baseToken ? encodeURI(fragment) : `#${encodeURI(fragment)}`;
|
|
2462
|
-
}
|
|
2463
2500
|
if (externalId) {
|
|
2464
2501
|
schemaStoreAlias[externalId] = id;
|
|
2465
2502
|
}
|
|
2466
2503
|
|
|
2467
|
-
|
|
2468
|
-
|
|
2504
|
+
const anchorToken = getConfig(dialectId, "anchorToken");
|
|
2505
|
+
if (fragment && baseToken === anchorToken) {
|
|
2506
|
+
schema[anchorToken] = anchorToken !== baseToken ? encodeURI(fragment) : `#${encodeURI(fragment)}`;
|
|
2507
|
+
}
|
|
2469
2508
|
|
|
2470
2509
|
// recursiveAnchor
|
|
2471
2510
|
const dynamicAnchors = {};
|
|
@@ -2501,6 +2540,12 @@ var JsonSchema = (function (exports) {
|
|
|
2501
2540
|
return id;
|
|
2502
2541
|
};
|
|
2503
2542
|
|
|
2543
|
+
const getSchemaIdentifier = (schema, externalId, jsonSchemaVersion) => {
|
|
2544
|
+
const baseToken = config[jsonSchemaVersion]?.["baseToken"];
|
|
2545
|
+
const internalUrl = resolveUrl$1(externalId, schema[baseToken] || "");
|
|
2546
|
+
return [resolveUrl$1(internalUrl, ""), urlFragment(internalUrl)];
|
|
2547
|
+
};
|
|
2548
|
+
|
|
2504
2549
|
const processSchema = (subject, id, dialectId, pointer, anchors, dynamicAnchors) => {
|
|
2505
2550
|
if (jsonTypeOf(subject, "object")) {
|
|
2506
2551
|
const embeddedSchemaDialectId = typeof subject.$schema === "string" ? resolveUrl$1(subject.$schema, "") : dialectId;
|
|
@@ -2578,14 +2623,7 @@ var JsonSchema = (function (exports) {
|
|
|
2578
2623
|
throw Error(`Failed to retrieve schema with id: ${id}`);
|
|
2579
2624
|
}
|
|
2580
2625
|
|
|
2581
|
-
|
|
2582
|
-
const contentType = contentTypeParser.parse(response.headers.get("content-type")).type;
|
|
2583
|
-
if (contentType !== "application/schema+json") {
|
|
2584
|
-
throw Error(`${id} is not a schema. Found a document with media type: ${contentType}`);
|
|
2585
|
-
}
|
|
2586
|
-
}
|
|
2587
|
-
|
|
2588
|
-
add$1(await response.json(), id);
|
|
2626
|
+
add$1(await MediaTypes$1.parse(response), id);
|
|
2589
2627
|
}
|
|
2590
2628
|
|
|
2591
2629
|
const storedSchema = getStoredSchema(id);
|
|
@@ -2728,6 +2766,7 @@ var JsonSchema = (function (exports) {
|
|
|
2728
2766
|
const Instance$E = instance;
|
|
2729
2767
|
const Schema$R = schema$5;
|
|
2730
2768
|
const InvalidSchemaError$2 = invalidSchemaError;
|
|
2769
|
+
const MediaTypes = mediaTypes;
|
|
2731
2770
|
|
|
2732
2771
|
|
|
2733
2772
|
const FLAG = "FLAG", BASIC = "BASIC", DETAILED = "DETAILED", VERBOSE = "VERBOSE";
|
|
@@ -2735,6 +2774,11 @@ var JsonSchema = (function (exports) {
|
|
|
2735
2774
|
let metaOutputFormat = DETAILED;
|
|
2736
2775
|
let shouldMetaValidate = true;
|
|
2737
2776
|
|
|
2777
|
+
MediaTypes.addPlugin("application/schema+json", {
|
|
2778
|
+
parse: async (response) => await response.json(),
|
|
2779
|
+
matcher: (path) => path.endsWith(".schema.json")
|
|
2780
|
+
});
|
|
2781
|
+
|
|
2738
2782
|
const validate$2 = async (schema, value = undefined, outputFormat = undefined) => {
|
|
2739
2783
|
const compiled = await compile$O(schema);
|
|
2740
2784
|
const interpretAst = (value, outputFormat) => interpret$O(compiled, Instance$E.cons(value), outputFormat);
|
|
@@ -2914,7 +2958,8 @@ var JsonSchema = (function (exports) {
|
|
|
2914
2958
|
validate: validate$2, compile: compile$O, interpret: interpret$O,
|
|
2915
2959
|
setMetaOutputFormat, setShouldMetaValidate, FLAG, BASIC, DETAILED, VERBOSE,
|
|
2916
2960
|
add, getKeyword, hasKeyword, defineVocabulary,
|
|
2917
|
-
compileSchema, interpretSchema, collectEvaluatedProperties: collectEvaluatedProperties$e, collectEvaluatedItems: collectEvaluatedItems$f
|
|
2961
|
+
compileSchema, interpretSchema, collectEvaluatedProperties: collectEvaluatedProperties$e, collectEvaluatedItems: collectEvaluatedItems$f,
|
|
2962
|
+
addMediaTypePlugin: MediaTypes.addPlugin
|
|
2918
2963
|
};
|
|
2919
2964
|
|
|
2920
2965
|
const Schema$Q = schema$5;
|
|
@@ -5628,6 +5673,7 @@ var JsonSchema = (function (exports) {
|
|
|
5628
5673
|
interpret: Core.interpret,
|
|
5629
5674
|
setMetaOutputFormat: Core.setMetaOutputFormat,
|
|
5630
5675
|
setShouldMetaValidate: Core.setShouldMetaValidate,
|
|
5676
|
+
addMediaTypePlugin: Core.addMediaTypePlugin,
|
|
5631
5677
|
FLAG: Core.FLAG,
|
|
5632
5678
|
BASIC: Core.BASIC,
|
|
5633
5679
|
DETAILED: Core.DETAILED,
|