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