@hyperjump/json-schema 0.23.4 → 0.23.5

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.
@@ -44,7 +44,11 @@ var JsonSchema = (function (exports) {
44
44
  };
45
45
  }
46
46
 
47
- var pubsub = {exports: {}};
47
+ var pubsubExports = {};
48
+ var pubsub = {
49
+ get exports(){ return pubsubExports; },
50
+ set exports(v){ pubsubExports = v; },
51
+ };
48
52
 
49
53
  /**
50
54
  * Copyright (c) 2010,2011,2012,2013,2014 Morgan Roderick http://roderick.dk
@@ -398,9 +402,13 @@ var JsonSchema = (function (exports) {
398
402
  return result;
399
403
  };
400
404
  }));
401
- } (pubsub, pubsub.exports));
405
+ } (pubsub, pubsubExports));
402
406
 
403
- var uri_all = {exports: {}};
407
+ var uri_allExports = {};
408
+ var uri_all = {
409
+ get exports(){ return uri_allExports; },
410
+ set exports(v){ uri_allExports = v; },
411
+ };
404
412
 
405
413
  /** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
406
414
 
@@ -1806,9 +1814,9 @@ var JsonSchema = (function (exports) {
1806
1814
 
1807
1815
  })));
1808
1816
 
1809
- } (uri_all, uri_all.exports));
1817
+ } (uri_all, uri_allExports));
1810
1818
 
1811
- const URI = uri_all.exports;
1819
+ const URI = uri_allExports;
1812
1820
 
1813
1821
 
1814
1822
  const isObject$1 = (value) => typeof value === "object" && !Array.isArray(value) && value !== null;
@@ -1904,116 +1912,138 @@ var JsonSchema = (function (exports) {
1904
1912
 
1905
1913
  const nil$2 = "";
1906
1914
 
1907
- const compile$N = (pointer) => {
1915
+ const EXISTS = Symbol("EXISTS");
1916
+
1917
+ const segmentGenerator = (pointer) => {
1908
1918
  if (pointer.length > 0 && pointer[0] !== "/") {
1909
1919
  throw Error("Invalid JSON Pointer");
1910
1920
  }
1911
1921
 
1912
- return pointer.split("/").slice(1).map(unescape);
1913
- };
1922
+ let segmentStart = 1;
1923
+ let segmentEnd = 0;
1914
1924
 
1915
- const get$2 = (pointer, value = undefined) => {
1916
- const ptr = compile$N(pointer);
1925
+ return (mode) => {
1926
+ if (mode === EXISTS) {
1927
+ return segmentEnd < pointer.length;
1928
+ }
1917
1929
 
1918
- const fn = (value) => ptr.reduce(([value, pointer], segment) => {
1919
- return [applySegment(value, segment, pointer), append(segment, pointer)];
1920
- }, [value, ""])[0];
1930
+ if (segmentEnd >= pointer.length) {
1931
+ return;
1932
+ }
1933
+
1934
+ const position = pointer.indexOf("/", segmentStart);
1935
+ segmentEnd = position === -1 ? pointer.length : position;
1936
+ const segment = unescape(pointer.slice(segmentStart, segmentEnd));
1937
+ segmentStart = segmentEnd + 1;
1921
1938
 
1922
- return value === undefined ? fn : fn(value);
1939
+ return segment;
1940
+ };
1941
+ };
1942
+
1943
+ const get$2 = (pointer, subject = undefined) => {
1944
+ const nextSegment = segmentGenerator(pointer);
1945
+ const fn = (subject) => _get(nextSegment, subject, nil$2);
1946
+ return subject === undefined ? fn : fn(subject);
1947
+ };
1948
+
1949
+ const _get = (nextSegment, subject, cursor) => {
1950
+ if (!nextSegment(EXISTS)) {
1951
+ return subject;
1952
+ } else {
1953
+ const segment = nextSegment();
1954
+ return _get(nextSegment, applySegment(subject, segment, cursor), append(segment, cursor));
1955
+ }
1923
1956
  };
1924
1957
 
1925
1958
  const set = (pointer, subject = undefined, value = undefined) => {
1926
- const ptr = compile$N(pointer);
1927
- const fn = curry$a((subject, value) => _set(ptr, subject, value, nil$2));
1959
+ const nextSegment = segmentGenerator(pointer);
1960
+ const fn = curry$a((subject, value) => _set(nextSegment, subject, value, nil$2));
1928
1961
  return subject === undefined ? fn : fn(subject, value);
1929
1962
  };
1930
1963
 
1931
- const _set = (pointer, subject, value, cursor) => {
1932
- if (pointer.length === 0) {
1964
+ const _set = (nextSegment, subject, value, cursor) => {
1965
+ const segment = nextSegment();
1966
+ if (segment === undefined) {
1933
1967
  return value;
1934
- } else if (pointer.length > 1) {
1968
+ } else if (nextSegment(EXISTS)) {
1935
1969
  if (Array.isArray(subject)) {
1936
- const index = pointer.shift();
1937
1970
  const clonedSubject = [...subject];
1938
- clonedSubject[index] = _set(pointer, applySegment(subject, index, cursor), value, append(index, cursor));
1971
+ clonedSubject[segment] = _set(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor));
1939
1972
  return clonedSubject;
1940
1973
  } else {
1941
- const segment = pointer.shift();
1942
- return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
1974
+ return { ...subject, [segment]: _set(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
1943
1975
  }
1944
1976
  } else if (Array.isArray(subject)) {
1945
1977
  const clonedSubject = [...subject];
1946
- const segment = computeSegment(subject, pointer[0]);
1947
- clonedSubject[segment] = value;
1978
+ clonedSubject[computeSegment(subject, segment)] = value;
1948
1979
  return clonedSubject;
1949
1980
  } else if (typeof subject === "object" && subject !== null) {
1950
- return { ...subject, [pointer[0]]: value };
1981
+ return { ...subject, [segment]: value };
1951
1982
  } else {
1952
- return applySegment(subject, pointer[0], cursor);
1983
+ return applySegment(subject, segment, cursor);
1953
1984
  }
1954
1985
  };
1955
1986
 
1956
1987
  const assign = (pointer, subject = undefined, value = undefined) => {
1957
- const ptr = compile$N(pointer);
1958
- const fn = curry$a((subject, value) => _assign(ptr, subject, value, nil$2));
1988
+ const nextSegment = segmentGenerator(pointer);
1989
+ const fn = curry$a((subject, value) => _assign(nextSegment, subject, value, nil$2));
1959
1990
  return subject === undefined ? fn : fn(subject, value);
1960
1991
  };
1961
1992
 
1962
- const _assign = (pointer, subject, value, cursor) => {
1963
- if (pointer.length === 0) {
1993
+ const _assign = (nextSegment, subject, value, cursor) => {
1994
+ const segment = nextSegment();
1995
+ if (segment === undefined) {
1964
1996
  return;
1965
- } else if (pointer.length === 1 && !isScalar(subject)) {
1966
- const segment = computeSegment(subject, pointer[0]);
1967
- subject[segment] = value;
1997
+ } else if (!nextSegment(EXISTS) && !isScalar(subject)) {
1998
+ subject[computeSegment(subject, segment)] = value;
1968
1999
  } else {
1969
- const segment = pointer.shift();
1970
- _assign(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));
2000
+ _assign(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor));
1971
2001
  }
1972
2002
  };
1973
2003
 
1974
2004
  const unset = (pointer, subject = undefined) => {
1975
- const ptr = compile$N(pointer);
1976
- const fn = (subject) => _unset(ptr, subject, nil$2);
2005
+ const nextSegment = segmentGenerator(pointer);
2006
+ const fn = (subject) => _unset(nextSegment, subject, nil$2);
1977
2007
  return subject === undefined ? fn : fn(subject);
1978
2008
  };
1979
2009
 
1980
- const _unset = (pointer, subject, cursor) => {
1981
- if (pointer.length == 0) {
1982
- return undefined;
1983
- } else if (pointer.length > 1) {
1984
- const segment = pointer.shift();
2010
+ const _unset = (nextSegment, subject, cursor) => {
2011
+ const segment = nextSegment();
2012
+ if (segment === undefined) {
2013
+ return;
2014
+ } else if (nextSegment(EXISTS)) {
1985
2015
  const value = applySegment(subject, segment, cursor);
1986
- return { ...subject, [segment]: _unset(pointer, value, append(segment, cursor)) };
2016
+ return { ...subject, [segment]: _unset(nextSegment, value, append(segment, cursor)) };
1987
2017
  } else if (Array.isArray(subject)) {
1988
- return subject.filter((_, ndx) => ndx != pointer[0]);
2018
+ const clonedSubject = [...subject];
2019
+ delete clonedSubject[computeSegment(subject, segment)];
2020
+ return clonedSubject;
1989
2021
  } else if (typeof subject === "object" && subject !== null) {
1990
2022
  // eslint-disable-next-line no-unused-vars
1991
- const { [pointer[0]]: _, ...result } = subject;
2023
+ const { [segment]: _, ...result } = subject;
1992
2024
  return result;
1993
2025
  } else {
1994
- return applySegment(subject, pointer[0], cursor);
2026
+ return applySegment(subject, segment, cursor);
1995
2027
  }
1996
2028
  };
1997
2029
 
1998
2030
  const remove = (pointer, subject = undefined) => {
1999
- const ptr = compile$N(pointer);
2000
- const fn = (subject) => _remove(ptr, subject, nil$2);
2031
+ const nextSegment = segmentGenerator(pointer);
2032
+ const fn = (subject) => _remove(nextSegment, subject, nil$2);
2001
2033
  return subject === undefined ? fn : fn(subject);
2002
2034
  };
2003
2035
 
2004
- const _remove = (pointer, subject, cursor) => {
2005
- if (pointer.length === 0) {
2036
+ const _remove = (nextSegment, subject, cursor) => {
2037
+ const segment = nextSegment();
2038
+ if (segment === undefined) {
2006
2039
  return;
2007
- } else if (pointer.length > 1) {
2008
- const segment = pointer.shift();
2040
+ } else if (nextSegment(EXISTS)) {
2009
2041
  const value = applySegment(subject, segment, cursor);
2010
- _remove(pointer, value, append(segment, cursor));
2011
- } else if (Array.isArray(subject)) {
2012
- subject.splice(pointer[0], 1);
2013
- } else if (typeof subject === "object" && subject !== null) {
2014
- delete subject[pointer[0]];
2042
+ _remove(nextSegment, value, append(segment, cursor));
2043
+ } else if (!isScalar(subject)) {
2044
+ delete subject[segment];
2015
2045
  } else {
2016
- applySegment(subject, pointer[0], cursor);
2046
+ applySegment(subject, segment, cursor);
2017
2047
  }
2018
2048
  };
2019
2049
 
@@ -2234,7 +2264,11 @@ var JsonSchema = (function (exports) {
2234
2264
  allValues: allValues
2235
2265
  };
2236
2266
 
2237
- var moo$1 = {exports: {}};
2267
+ var mooExports = {};
2268
+ var moo$1 = {
2269
+ get exports(){ return mooExports; },
2270
+ set exports(v){ mooExports = v; },
2271
+ };
2238
2272
 
2239
2273
  (function (module) {
2240
2274
  (function(root, factory) {
@@ -2878,7 +2912,7 @@ var JsonSchema = (function (exports) {
2878
2912
  }));
2879
2913
  } (moo$1));
2880
2914
 
2881
- const moo = moo$1.exports;
2915
+ const moo = mooExports;
2882
2916
 
2883
2917
 
2884
2918
  const digit = `[0-9]`;
@@ -3141,8 +3175,8 @@ var JsonSchema = (function (exports) {
3141
3175
  * obs-text = %x80-FF
3142
3176
  * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
3143
3177
  */
3144
- var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
3145
- var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
3178
+ var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g; // eslint-disable-line no-control-regex
3179
+ var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/; // eslint-disable-line no-control-regex
3146
3180
  var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
3147
3181
 
3148
3182
  /**
@@ -3151,7 +3185,7 @@ var JsonSchema = (function (exports) {
3151
3185
  * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
3152
3186
  * obs-text = %x80-FF
3153
3187
  */
3154
- var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
3188
+ var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g; // eslint-disable-line no-control-regex
3155
3189
 
3156
3190
  /**
3157
3191
  * RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6
@@ -3240,7 +3274,7 @@ var JsonSchema = (function (exports) {
3240
3274
 
3241
3275
  var index = header.indexOf(';');
3242
3276
  var type = index !== -1
3243
- ? header.substr(0, index).trim()
3277
+ ? header.slice(0, index).trim()
3244
3278
  : header.trim();
3245
3279
 
3246
3280
  if (!TYPE_REGEXP.test(type)) {
@@ -3266,11 +3300,14 @@ var JsonSchema = (function (exports) {
3266
3300
  key = match[1].toLowerCase();
3267
3301
  value = match[2];
3268
3302
 
3269
- if (value[0] === '"') {
3270
- // remove quotes and escapes
3271
- value = value
3272
- .substr(1, value.length - 2)
3273
- .replace(QESC_REGEXP, '$1');
3303
+ if (value.charCodeAt(0) === 0x22 /* " */) {
3304
+ // remove quotes
3305
+ value = value.slice(1, -1);
3306
+
3307
+ // remove escapes
3308
+ if (value.indexOf('\\') !== -1) {
3309
+ value = value.replace(QESC_REGEXP, '$1');
3310
+ }
3274
3311
  }
3275
3312
 
3276
3313
  obj.parameters[key] = value;
@@ -3719,13 +3756,13 @@ var JsonSchema = (function (exports) {
3719
3756
  toSchema
3720
3757
  };
3721
3758
 
3722
- class InvalidSchemaError$3 extends Error {
3759
+ let InvalidSchemaError$3 = class InvalidSchemaError extends Error {
3723
3760
  constructor(output) {
3724
3761
  super("Invalid Schema");
3725
3762
  this.name = this.constructor.name;
3726
3763
  this.output = output;
3727
3764
  }
3728
- }
3765
+ };
3729
3766
 
3730
3767
  var invalidSchemaError = InvalidSchemaError$3;
3731
3768
 
@@ -3738,7 +3775,7 @@ var JsonSchema = (function (exports) {
3738
3775
  var metaData$4 = { compile: compile$M, interpret: interpret$M };
3739
3776
 
3740
3777
  const curry = justCurryIt$1;
3741
- const PubSub$1 = pubsub.exports;
3778
+ const PubSub$1 = pubsubExports;
3742
3779
  const { resolveUrl } = common$1;
3743
3780
  const Instance$C = instance;
3744
3781
  const Schema$O = schema$5;
@@ -3827,7 +3864,13 @@ var JsonSchema = (function (exports) {
3827
3864
  };
3828
3865
 
3829
3866
  const _keywords = {};
3830
- const getKeyword = (id) => _keywords[id] || metaData$3;
3867
+ const getKeyword = (id) => {
3868
+ if (!_keywords[id]) {
3869
+ addKeyword(id, metaData$3);
3870
+ }
3871
+
3872
+ return _keywords[id];
3873
+ };
3831
3874
  const hasKeyword = (id) => id in _keywords;
3832
3875
  const addKeyword = (id, keywordHandler) => {
3833
3876
  _keywords[id] = {
@@ -3944,7 +3987,7 @@ var JsonSchema = (function (exports) {
3944
3987
  };
3945
3988
 
3946
3989
  const Pact$9 = lib$3;
3947
- const PubSub = pubsub.exports;
3990
+ const PubSub = pubsubExports;
3948
3991
  const Core$x = core$2;
3949
3992
  const Instance$B = instance;
3950
3993
  const Schema$N = schema$5;
@@ -4105,7 +4148,16 @@ var JsonSchema = (function (exports) {
4105
4148
  };
4106
4149
 
4107
4150
  const collectEvaluatedItems$d = (keywordValue, instance, ast, dynamicAnchors) => {
4108
- return interpret$I(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance$y.map((item, ndx) => ndx, instance));
4151
+ if (!interpret$I(keywordValue, instance, ast, dynamicAnchors)) {
4152
+ return false;
4153
+ }
4154
+
4155
+ const evaluatedIndexes = new Set();
4156
+ for (let ndx = keywordValue[0]; ndx < Instance$y.length(instance); ndx++) {
4157
+ evaluatedIndexes.add(ndx);
4158
+ }
4159
+
4160
+ return evaluatedIndexes;
4109
4161
  };
4110
4162
 
4111
4163
  var additionalItems6 = { compile: compile$I, interpret: interpret$I, collectEvaluatedItems: collectEvaluatedItems$d };
@@ -4904,15 +4956,14 @@ var JsonSchema = (function (exports) {
4904
4956
  const [, fragment] = splitUrl(Schema$d.value(dynamicRef));
4905
4957
  const referencedSchema = await Schema$d.get(Schema$d.value(dynamicRef), dynamicRef);
4906
4958
  await Core$a.compileSchema(referencedSchema, ast);
4907
- return [referencedSchema.id, fragment];
4959
+ return [referencedSchema.id, fragment, Schema$d.uri(referencedSchema)];
4908
4960
  };
4909
4961
 
4910
- const interpret$7 = ([id, fragment], instance, ast, dynamicAnchors) => {
4962
+ const interpret$7 = ([id, fragment, ref], instance, ast, dynamicAnchors) => {
4911
4963
  if (fragment in ast.metaData[id].dynamicAnchors) {
4912
4964
  return Core$a.interpretSchema(dynamicAnchors[fragment], instance, ast, dynamicAnchors);
4913
4965
  } else {
4914
- const pointer = Schema$d.getAnchorPointer(ast.metaData[id], fragment);
4915
- return Core$a.interpretSchema(`${id}#${encodeURI(pointer)}`, instance, ast, dynamicAnchors);
4966
+ return Core$a.interpretSchema(ref, instance, ast, dynamicAnchors);
4916
4967
  }
4917
4968
  };
4918
4969
 
@@ -6637,7 +6688,7 @@ var JsonSchema = (function (exports) {
6637
6688
  InvalidSchemaError: InvalidSchemaError
6638
6689
  };
6639
6690
 
6640
- exports["default"] = lib;
6691
+ exports.default = lib;
6641
6692
 
6642
6693
  Object.defineProperty(exports, '__esModule', { value: true });
6643
6694