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