@hyperjump/json-schema 0.22.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.
@@ -1912,7 +1912,7 @@ var JsonSchema = (function (exports) {
1912
1912
  return pointer.split("/").slice(1).map(unescape);
1913
1913
  };
1914
1914
 
1915
- const get$1 = (pointer, value = undefined) => {
1915
+ const get$2 = (pointer, value = undefined) => {
1916
1916
  const ptr = compile$P(pointer);
1917
1917
 
1918
1918
  const fn = (value) => ptr.reduce(([value, pointer], segment) => {
@@ -2031,7 +2031,7 @@ var JsonSchema = (function (exports) {
2031
2031
 
2032
2032
  const isScalar = (value) => value === null || typeof value !== "object";
2033
2033
 
2034
- var lib$3 = { nil: nil$2, append, get: get$1, set, assign, unset, remove };
2034
+ var lib$3 = { nil: nil$2, append, get: get$2, set, assign, unset, remove };
2035
2035
 
2036
2036
  const $__value = Symbol("$__value");
2037
2037
  const $__href = Symbol("$__href");
@@ -2055,6 +2055,15 @@ var JsonSchema = (function (exports) {
2055
2055
 
2056
2056
  const nil$1 = Object.freeze({ id: "", pointer: "", instance: undefined, value: undefined });
2057
2057
  const cons = (instance, id = "") => Object.freeze({ ...nil$1, id: resolveUrl$2(id, ""), instance, value: instance });
2058
+
2059
+ const get$1 = (url, instance = nil$1) => {
2060
+ if (!url.startsWith("#")) {
2061
+ throw Error(`No JSON document found at '${url.split("#")[0]}'`);
2062
+ }
2063
+
2064
+ return Object.freeze({ ...instance, pointer: url.substr(1) });
2065
+ };
2066
+
2058
2067
  const uri$1 = (doc) => `${doc.id}#${encodeURI(doc.pointer)}`;
2059
2068
  const value$1 = (doc) => Reference$2.isReference(doc.value) ? Reference$2.value(doc.value) : doc.value;
2060
2069
  const has$1 = (key, doc) => key in value$1(doc);
@@ -2074,6 +2083,9 @@ var JsonSchema = (function (exports) {
2074
2083
  const map$4 = curry$8((fn, doc) => value$1(doc)
2075
2084
  .map((item, ndx, array, thisArg) => fn(step$1(ndx, doc), ndx, array, thisArg)));
2076
2085
 
2086
+ const forEach = curry$8((fn, doc) => value$1(doc)
2087
+ .forEach((item, ndx, array, thisArg) => fn(step$1(ndx, doc), ndx, array, thisArg)));
2088
+
2077
2089
  const filter$1 = curry$8((fn, doc) => value$1(doc)
2078
2090
  .map((item, ndx, array, thisArg) => step$1(ndx, doc))
2079
2091
  .filter((item, ndx, array, thisArg) => fn(item, ndx, array, thisArg)));
@@ -2089,7 +2101,10 @@ var JsonSchema = (function (exports) {
2089
2101
 
2090
2102
  const length$1 = (doc) => value$1(doc).length;
2091
2103
 
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 };
2104
+ var instance = {
2105
+ nil: nil$1, cons, get: get$1, uri: uri$1, value: value$1, has: has$1, typeOf: typeOf$1, length: length$1,
2106
+ 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
2107
+ };
2093
2108
 
2094
2109
  var entries$2 = async (doc) => Object.entries(await doc);
2095
2110
 
@@ -2406,11 +2421,11 @@ var JsonSchema = (function (exports) {
2406
2421
  };
2407
2422
 
2408
2423
  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}`);
2424
+ const contentType = contentTypeParser.parse(response.headers.get("content-type"));
2425
+ if (!(contentType.type in mediaTypePlugins)) {
2426
+ throw Error(`${response.url} is not a schema. Found a document with media type: ${contentType.type}`);
2412
2427
  }
2413
- return mediaTypePlugins[contentType].parse(response);
2428
+ return mediaTypePlugins[contentType.type].parse(response, contentType.parameters);
2414
2429
  };
2415
2430
 
2416
2431
  const getContentType = (path) => {
@@ -2442,6 +2457,8 @@ var JsonSchema = (function (exports) {
2442
2457
  const dialectJsonSchemaVersion = {};
2443
2458
 
2444
2459
  const setConfig = (jsonSchemaVersion, key, value) => {
2460
+ dialectJsonSchemaVersion[jsonSchemaVersion] = jsonSchemaVersion;
2461
+
2445
2462
  if (!config[jsonSchemaVersion]) {
2446
2463
  config[jsonSchemaVersion] = {};
2447
2464
  }
@@ -2468,23 +2485,25 @@ var JsonSchema = (function (exports) {
2468
2485
  }
2469
2486
  delete schema["$schema"];
2470
2487
 
2471
- // JSON Schema version
2488
+ // Determine JSON Schema version
2472
2489
  if (!(dialectId in dialectJsonSchemaVersion)) {
2473
2490
  if (schema?.$vocabulary?.[core201909Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core201909Id)[0]) {
2491
+ // Self describing 2019-09 meta-schema
2474
2492
  dialectJsonSchemaVersion[dialectId] = core201909Id;
2475
2493
  } else if (schema?.$vocabulary?.[core202012Id] === true && dialectId === getSchemaIdentifier(schema, externalId, core202012Id)[0]) {
2494
+ // Self describing 2020-12 meta-schema
2476
2495
  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
2496
  } else {
2497
+ // Need to look at meta-schema to determine version
2482
2498
  const metaSchema = schemaStore[dialectId];
2483
- if (metaSchema.vocabulary[core201909Id] === true) {
2499
+ if (!metaSchema) {
2500
+ throw Error(`Couldn't determine JSON Schema version for dialect: '${dialectId}'`);
2501
+ } else if (metaSchema.vocabulary[core201909Id] === true) {
2484
2502
  dialectJsonSchemaVersion[dialectId] = core201909Id;
2485
2503
  } else if (metaSchema.vocabulary[core202012Id] === true) {
2486
2504
  dialectJsonSchemaVersion[dialectId] = core202012Id;
2487
2505
  } else {
2506
+ // Assume the jsonSchemaVersion is the meta-schema's dialectId (non-standard behavior)
2488
2507
  dialectJsonSchemaVersion[dialectId] = dialectJsonSchemaVersion[metaSchema.dialectId];
2489
2508
  }
2490
2509
  }
@@ -2623,7 +2642,15 @@ var JsonSchema = (function (exports) {
2623
2642
  throw Error(`Failed to retrieve schema with id: ${id}`);
2624
2643
  }
2625
2644
 
2626
- add$1(await MediaTypes$1.parse(response), id);
2645
+ const [schema, defaultDialectId] = await MediaTypes$1.parse(response);
2646
+
2647
+ // Make sure the meta-schema is loaded if this isn't a known dialect
2648
+ const dialectId = resolveUrl$1(schema.$schema, "") || defaultDialectId;
2649
+ if (id !== dialectId && !(dialectId in dialectJsonSchemaVersion)) {
2650
+ await get(dialectId);
2651
+ }
2652
+
2653
+ add$1(schema, id);
2627
2654
  }
2628
2655
 
2629
2656
  const storedSchema = getStoredSchema(id);
@@ -2784,7 +2811,10 @@ var JsonSchema = (function (exports) {
2784
2811
  let shouldMetaValidate = true;
2785
2812
 
2786
2813
  MediaTypes.addPlugin("application/schema+json", {
2787
- parse: async (response) => await response.json(),
2814
+ parse: async (response, contentTypeParameters) => [
2815
+ await response.json(),
2816
+ contentTypeParameters.schema || contentTypeParameters.profile
2817
+ ],
2788
2818
  matcher: (path) => path.endsWith(".schema.json")
2789
2819
  });
2790
2820