@hyperjump/json-schema 0.23.2 → 0.23.4

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.
@@ -2014,9 +2014,9 @@ const _remove = (pointer, subject, cursor) => {
2014
2014
  }
2015
2015
  };
2016
2016
 
2017
- const append = curry$a((segment, pointer) => pointer + "/" + escape(segment));
2017
+ const append = curry$a((segment, pointer) => pointer + "/" + escape$1(segment));
2018
2018
 
2019
- const escape = (segment) => segment.toString().replace(/~/g, "~0").replace(/\//g, "~1");
2019
+ const escape$1 = (segment) => segment.toString().replace(/~/g, "~0").replace(/\//g, "~1");
2020
2020
  const unescape = (segment) => segment.toString().replace(/~1/g, "/").replace(/~0/g, "~");
2021
2021
  const computeSegment = (value, segment) => Array.isArray(value) && segment === "-" ? value.length : segment;
2022
2022
 
@@ -2035,7 +2035,7 @@ const applySegment = (value, segment, cursor = "") => {
2035
2035
 
2036
2036
  const isScalar = (value) => value === null || typeof value !== "object";
2037
2037
 
2038
- var lib$3 = { nil: nil$2, append, get: get$2, set, assign, unset, remove };
2038
+ var lib$4 = { nil: nil$2, append, get: get$2, set, assign, unset, remove };
2039
2039
 
2040
2040
  const $__value = Symbol("$__value");
2041
2041
  const $__href = Symbol("$__href");
@@ -2051,7 +2051,7 @@ const value$2 = (ref) => ref[$__value];
2051
2051
 
2052
2052
  var reference = { cons: cons$1, isReference, href, value: value$2 };
2053
2053
 
2054
- const JsonPointer$1 = lib$3;
2054
+ const JsonPointer$3 = lib$4;
2055
2055
  const curry$9 = justCurryIt$1;
2056
2056
  const { resolveUrl: resolveUrl$2, jsonTypeOf: jsonTypeOf$1 } = common$1;
2057
2057
  const Reference$2 = reference;
@@ -2075,7 +2075,7 @@ const typeOf$1 = curry$9((doc, type) => jsonTypeOf$1(value$1(doc), type));
2075
2075
 
2076
2076
  const step$1 = (key, doc) => Object.freeze({
2077
2077
  ...doc,
2078
- pointer: JsonPointer$1.append(key, doc.pointer),
2078
+ pointer: JsonPointer$3.append(key, doc.pointer),
2079
2079
  value: value$1(doc)[key]
2080
2080
  });
2081
2081
 
@@ -2219,7 +2219,7 @@ var allValues = (doc) => {
2219
2219
  ], doc);
2220
2220
  };
2221
2221
 
2222
- var lib$2 = {
2222
+ var lib$3 = {
2223
2223
  entries: entries$2,
2224
2224
  map: map$3,
2225
2225
  filter: filter,
@@ -2231,6 +2231,889 @@ var lib$2 = {
2231
2231
  allValues: allValues
2232
2232
  };
2233
2233
 
2234
+ var moo$1 = {exports: {}};
2235
+
2236
+ (function (module) {
2237
+ (function(root, factory) {
2238
+ if (module.exports) {
2239
+ module.exports = factory();
2240
+ } else {
2241
+ root.moo = factory();
2242
+ }
2243
+ }(commonjsGlobal, function() {
2244
+
2245
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
2246
+ var toString = Object.prototype.toString;
2247
+ var hasSticky = typeof new RegExp().sticky === 'boolean';
2248
+
2249
+ /***************************************************************************/
2250
+
2251
+ function isRegExp(o) { return o && toString.call(o) === '[object RegExp]' }
2252
+ function isObject(o) { return o && typeof o === 'object' && !isRegExp(o) && !Array.isArray(o) }
2253
+
2254
+ function reEscape(s) {
2255
+ return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
2256
+ }
2257
+ function reGroups(s) {
2258
+ var re = new RegExp('|' + s);
2259
+ return re.exec('').length - 1
2260
+ }
2261
+ function reCapture(s) {
2262
+ return '(' + s + ')'
2263
+ }
2264
+ function reUnion(regexps) {
2265
+ if (!regexps.length) return '(?!)'
2266
+ var source = regexps.map(function(s) {
2267
+ return "(?:" + s + ")"
2268
+ }).join('|');
2269
+ return "(?:" + source + ")"
2270
+ }
2271
+
2272
+ function regexpOrLiteral(obj) {
2273
+ if (typeof obj === 'string') {
2274
+ return '(?:' + reEscape(obj) + ')'
2275
+
2276
+ } else if (isRegExp(obj)) {
2277
+ // TODO: consider /u support
2278
+ if (obj.ignoreCase) throw new Error('RegExp /i flag not allowed')
2279
+ if (obj.global) throw new Error('RegExp /g flag is implied')
2280
+ if (obj.sticky) throw new Error('RegExp /y flag is implied')
2281
+ if (obj.multiline) throw new Error('RegExp /m flag is implied')
2282
+ return obj.source
2283
+
2284
+ } else {
2285
+ throw new Error('Not a pattern: ' + obj)
2286
+ }
2287
+ }
2288
+
2289
+ function pad(s, length) {
2290
+ if (s.length > length) {
2291
+ return s
2292
+ }
2293
+ return Array(length - s.length + 1).join(" ") + s
2294
+ }
2295
+
2296
+ function lastNLines(string, numLines) {
2297
+ var position = string.length;
2298
+ var lineBreaks = 0;
2299
+ while (true) {
2300
+ var idx = string.lastIndexOf("\n", position - 1);
2301
+ if (idx === -1) {
2302
+ break;
2303
+ } else {
2304
+ lineBreaks++;
2305
+ }
2306
+ position = idx;
2307
+ if (lineBreaks === numLines) {
2308
+ break;
2309
+ }
2310
+ if (position === 0) {
2311
+ break;
2312
+ }
2313
+ }
2314
+ var startPosition =
2315
+ lineBreaks < numLines ?
2316
+ 0 :
2317
+ position + 1;
2318
+ return string.substring(startPosition).split("\n")
2319
+ }
2320
+
2321
+ function objectToRules(object) {
2322
+ var keys = Object.getOwnPropertyNames(object);
2323
+ var result = [];
2324
+ for (var i = 0; i < keys.length; i++) {
2325
+ var key = keys[i];
2326
+ var thing = object[key];
2327
+ var rules = [].concat(thing);
2328
+ if (key === 'include') {
2329
+ for (var j = 0; j < rules.length; j++) {
2330
+ result.push({include: rules[j]});
2331
+ }
2332
+ continue
2333
+ }
2334
+ var match = [];
2335
+ rules.forEach(function(rule) {
2336
+ if (isObject(rule)) {
2337
+ if (match.length) result.push(ruleOptions(key, match));
2338
+ result.push(ruleOptions(key, rule));
2339
+ match = [];
2340
+ } else {
2341
+ match.push(rule);
2342
+ }
2343
+ });
2344
+ if (match.length) result.push(ruleOptions(key, match));
2345
+ }
2346
+ return result
2347
+ }
2348
+
2349
+ function arrayToRules(array) {
2350
+ var result = [];
2351
+ for (var i = 0; i < array.length; i++) {
2352
+ var obj = array[i];
2353
+ if (obj.include) {
2354
+ var include = [].concat(obj.include);
2355
+ for (var j = 0; j < include.length; j++) {
2356
+ result.push({include: include[j]});
2357
+ }
2358
+ continue
2359
+ }
2360
+ if (!obj.type) {
2361
+ throw new Error('Rule has no type: ' + JSON.stringify(obj))
2362
+ }
2363
+ result.push(ruleOptions(obj.type, obj));
2364
+ }
2365
+ return result
2366
+ }
2367
+
2368
+ function ruleOptions(type, obj) {
2369
+ if (!isObject(obj)) {
2370
+ obj = { match: obj };
2371
+ }
2372
+ if (obj.include) {
2373
+ throw new Error('Matching rules cannot also include states')
2374
+ }
2375
+
2376
+ // nb. error and fallback imply lineBreaks
2377
+ var options = {
2378
+ defaultType: type,
2379
+ lineBreaks: !!obj.error || !!obj.fallback,
2380
+ pop: false,
2381
+ next: null,
2382
+ push: null,
2383
+ error: false,
2384
+ fallback: false,
2385
+ value: null,
2386
+ type: null,
2387
+ shouldThrow: false,
2388
+ };
2389
+
2390
+ // Avoid Object.assign(), so we support IE9+
2391
+ for (var key in obj) {
2392
+ if (hasOwnProperty.call(obj, key)) {
2393
+ options[key] = obj[key];
2394
+ }
2395
+ }
2396
+
2397
+ // type transform cannot be a string
2398
+ if (typeof options.type === 'string' && type !== options.type) {
2399
+ throw new Error("Type transform cannot be a string (type '" + options.type + "' for token '" + type + "')")
2400
+ }
2401
+
2402
+ // convert to array
2403
+ var match = options.match;
2404
+ options.match = Array.isArray(match) ? match : match ? [match] : [];
2405
+ options.match.sort(function(a, b) {
2406
+ return isRegExp(a) && isRegExp(b) ? 0
2407
+ : isRegExp(b) ? -1 : isRegExp(a) ? +1 : b.length - a.length
2408
+ });
2409
+ return options
2410
+ }
2411
+
2412
+ function toRules(spec) {
2413
+ return Array.isArray(spec) ? arrayToRules(spec) : objectToRules(spec)
2414
+ }
2415
+
2416
+ var defaultErrorRule = ruleOptions('error', {lineBreaks: true, shouldThrow: true});
2417
+ function compileRules(rules, hasStates) {
2418
+ var errorRule = null;
2419
+ var fast = Object.create(null);
2420
+ var fastAllowed = true;
2421
+ var unicodeFlag = null;
2422
+ var groups = [];
2423
+ var parts = [];
2424
+
2425
+ // If there is a fallback rule, then disable fast matching
2426
+ for (var i = 0; i < rules.length; i++) {
2427
+ if (rules[i].fallback) {
2428
+ fastAllowed = false;
2429
+ }
2430
+ }
2431
+
2432
+ for (var i = 0; i < rules.length; i++) {
2433
+ var options = rules[i];
2434
+
2435
+ if (options.include) {
2436
+ // all valid inclusions are removed by states() preprocessor
2437
+ throw new Error('Inheritance is not allowed in stateless lexers')
2438
+ }
2439
+
2440
+ if (options.error || options.fallback) {
2441
+ // errorRule can only be set once
2442
+ if (errorRule) {
2443
+ if (!options.fallback === !errorRule.fallback) {
2444
+ throw new Error("Multiple " + (options.fallback ? "fallback" : "error") + " rules not allowed (for token '" + options.defaultType + "')")
2445
+ } else {
2446
+ throw new Error("fallback and error are mutually exclusive (for token '" + options.defaultType + "')")
2447
+ }
2448
+ }
2449
+ errorRule = options;
2450
+ }
2451
+
2452
+ var match = options.match.slice();
2453
+ if (fastAllowed) {
2454
+ while (match.length && typeof match[0] === 'string' && match[0].length === 1) {
2455
+ var word = match.shift();
2456
+ fast[word.charCodeAt(0)] = options;
2457
+ }
2458
+ }
2459
+
2460
+ // Warn about inappropriate state-switching options
2461
+ if (options.pop || options.push || options.next) {
2462
+ if (!hasStates) {
2463
+ throw new Error("State-switching options are not allowed in stateless lexers (for token '" + options.defaultType + "')")
2464
+ }
2465
+ if (options.fallback) {
2466
+ throw new Error("State-switching options are not allowed on fallback tokens (for token '" + options.defaultType + "')")
2467
+ }
2468
+ }
2469
+
2470
+ // Only rules with a .match are included in the RegExp
2471
+ if (match.length === 0) {
2472
+ continue
2473
+ }
2474
+ fastAllowed = false;
2475
+
2476
+ groups.push(options);
2477
+
2478
+ // Check unicode flag is used everywhere or nowhere
2479
+ for (var j = 0; j < match.length; j++) {
2480
+ var obj = match[j];
2481
+ if (!isRegExp(obj)) {
2482
+ continue
2483
+ }
2484
+
2485
+ if (unicodeFlag === null) {
2486
+ unicodeFlag = obj.unicode;
2487
+ } else if (unicodeFlag !== obj.unicode && options.fallback === false) {
2488
+ throw new Error('If one rule is /u then all must be')
2489
+ }
2490
+ }
2491
+
2492
+ // convert to RegExp
2493
+ var pat = reUnion(match.map(regexpOrLiteral));
2494
+
2495
+ // validate
2496
+ var regexp = new RegExp(pat);
2497
+ if (regexp.test("")) {
2498
+ throw new Error("RegExp matches empty string: " + regexp)
2499
+ }
2500
+ var groupCount = reGroups(pat);
2501
+ if (groupCount > 0) {
2502
+ throw new Error("RegExp has capture groups: " + regexp + "\nUse (?: … ) instead")
2503
+ }
2504
+
2505
+ // try and detect rules matching newlines
2506
+ if (!options.lineBreaks && regexp.test('\n')) {
2507
+ throw new Error('Rule should declare lineBreaks: ' + regexp)
2508
+ }
2509
+
2510
+ // store regex
2511
+ parts.push(reCapture(pat));
2512
+ }
2513
+
2514
+
2515
+ // If there's no fallback rule, use the sticky flag so we only look for
2516
+ // matches at the current index.
2517
+ //
2518
+ // If we don't support the sticky flag, then fake it using an irrefutable
2519
+ // match (i.e. an empty pattern).
2520
+ var fallbackRule = errorRule && errorRule.fallback;
2521
+ var flags = hasSticky && !fallbackRule ? 'ym' : 'gm';
2522
+ var suffix = hasSticky || fallbackRule ? '' : '|';
2523
+
2524
+ if (unicodeFlag === true) flags += "u";
2525
+ var combined = new RegExp(reUnion(parts) + suffix, flags);
2526
+ return {regexp: combined, groups: groups, fast: fast, error: errorRule || defaultErrorRule}
2527
+ }
2528
+
2529
+ function compile(rules) {
2530
+ var result = compileRules(toRules(rules));
2531
+ return new Lexer({start: result}, 'start')
2532
+ }
2533
+
2534
+ function checkStateGroup(g, name, map) {
2535
+ var state = g && (g.push || g.next);
2536
+ if (state && !map[state]) {
2537
+ throw new Error("Missing state '" + state + "' (in token '" + g.defaultType + "' of state '" + name + "')")
2538
+ }
2539
+ if (g && g.pop && +g.pop !== 1) {
2540
+ throw new Error("pop must be 1 (in token '" + g.defaultType + "' of state '" + name + "')")
2541
+ }
2542
+ }
2543
+ function compileStates(states, start) {
2544
+ var all = states.$all ? toRules(states.$all) : [];
2545
+ delete states.$all;
2546
+
2547
+ var keys = Object.getOwnPropertyNames(states);
2548
+ if (!start) start = keys[0];
2549
+
2550
+ var ruleMap = Object.create(null);
2551
+ for (var i = 0; i < keys.length; i++) {
2552
+ var key = keys[i];
2553
+ ruleMap[key] = toRules(states[key]).concat(all);
2554
+ }
2555
+ for (var i = 0; i < keys.length; i++) {
2556
+ var key = keys[i];
2557
+ var rules = ruleMap[key];
2558
+ var included = Object.create(null);
2559
+ for (var j = 0; j < rules.length; j++) {
2560
+ var rule = rules[j];
2561
+ if (!rule.include) continue
2562
+ var splice = [j, 1];
2563
+ if (rule.include !== key && !included[rule.include]) {
2564
+ included[rule.include] = true;
2565
+ var newRules = ruleMap[rule.include];
2566
+ if (!newRules) {
2567
+ throw new Error("Cannot include nonexistent state '" + rule.include + "' (in state '" + key + "')")
2568
+ }
2569
+ for (var k = 0; k < newRules.length; k++) {
2570
+ var newRule = newRules[k];
2571
+ if (rules.indexOf(newRule) !== -1) continue
2572
+ splice.push(newRule);
2573
+ }
2574
+ }
2575
+ rules.splice.apply(rules, splice);
2576
+ j--;
2577
+ }
2578
+ }
2579
+
2580
+ var map = Object.create(null);
2581
+ for (var i = 0; i < keys.length; i++) {
2582
+ var key = keys[i];
2583
+ map[key] = compileRules(ruleMap[key], true);
2584
+ }
2585
+
2586
+ for (var i = 0; i < keys.length; i++) {
2587
+ var name = keys[i];
2588
+ var state = map[name];
2589
+ var groups = state.groups;
2590
+ for (var j = 0; j < groups.length; j++) {
2591
+ checkStateGroup(groups[j], name, map);
2592
+ }
2593
+ var fastKeys = Object.getOwnPropertyNames(state.fast);
2594
+ for (var j = 0; j < fastKeys.length; j++) {
2595
+ checkStateGroup(state.fast[fastKeys[j]], name, map);
2596
+ }
2597
+ }
2598
+
2599
+ return new Lexer(map, start)
2600
+ }
2601
+
2602
+ function keywordTransform(map) {
2603
+
2604
+ // Use a JavaScript Map to map keywords to their corresponding token type
2605
+ // unless Map is unsupported, then fall back to using an Object:
2606
+ var isMap = typeof Map !== 'undefined';
2607
+ var reverseMap = isMap ? new Map : Object.create(null);
2608
+
2609
+ var types = Object.getOwnPropertyNames(map);
2610
+ for (var i = 0; i < types.length; i++) {
2611
+ var tokenType = types[i];
2612
+ var item = map[tokenType];
2613
+ var keywordList = Array.isArray(item) ? item : [item];
2614
+ keywordList.forEach(function(keyword) {
2615
+ if (typeof keyword !== 'string') {
2616
+ throw new Error("keyword must be string (in keyword '" + tokenType + "')")
2617
+ }
2618
+ if (isMap) {
2619
+ reverseMap.set(keyword, tokenType);
2620
+ } else {
2621
+ reverseMap[keyword] = tokenType;
2622
+ }
2623
+ });
2624
+ }
2625
+ return function(k) {
2626
+ return isMap ? reverseMap.get(k) : reverseMap[k]
2627
+ }
2628
+ }
2629
+
2630
+ /***************************************************************************/
2631
+
2632
+ var Lexer = function(states, state) {
2633
+ this.startState = state;
2634
+ this.states = states;
2635
+ this.buffer = '';
2636
+ this.stack = [];
2637
+ this.reset();
2638
+ };
2639
+
2640
+ Lexer.prototype.reset = function(data, info) {
2641
+ this.buffer = data || '';
2642
+ this.index = 0;
2643
+ this.line = info ? info.line : 1;
2644
+ this.col = info ? info.col : 1;
2645
+ this.queuedToken = info ? info.queuedToken : null;
2646
+ this.queuedText = info ? info.queuedText: "";
2647
+ this.queuedThrow = info ? info.queuedThrow : null;
2648
+ this.setState(info ? info.state : this.startState);
2649
+ this.stack = info && info.stack ? info.stack.slice() : [];
2650
+ return this
2651
+ };
2652
+
2653
+ Lexer.prototype.save = function() {
2654
+ return {
2655
+ line: this.line,
2656
+ col: this.col,
2657
+ state: this.state,
2658
+ stack: this.stack.slice(),
2659
+ queuedToken: this.queuedToken,
2660
+ queuedText: this.queuedText,
2661
+ queuedThrow: this.queuedThrow,
2662
+ }
2663
+ };
2664
+
2665
+ Lexer.prototype.setState = function(state) {
2666
+ if (!state || this.state === state) return
2667
+ this.state = state;
2668
+ var info = this.states[state];
2669
+ this.groups = info.groups;
2670
+ this.error = info.error;
2671
+ this.re = info.regexp;
2672
+ this.fast = info.fast;
2673
+ };
2674
+
2675
+ Lexer.prototype.popState = function() {
2676
+ this.setState(this.stack.pop());
2677
+ };
2678
+
2679
+ Lexer.prototype.pushState = function(state) {
2680
+ this.stack.push(this.state);
2681
+ this.setState(state);
2682
+ };
2683
+
2684
+ var eat = hasSticky ? function(re, buffer) { // assume re is /y
2685
+ return re.exec(buffer)
2686
+ } : function(re, buffer) { // assume re is /g
2687
+ var match = re.exec(buffer);
2688
+ // will always match, since we used the |(?:) trick
2689
+ if (match[0].length === 0) {
2690
+ return null
2691
+ }
2692
+ return match
2693
+ };
2694
+
2695
+ Lexer.prototype._getGroup = function(match) {
2696
+ var groupCount = this.groups.length;
2697
+ for (var i = 0; i < groupCount; i++) {
2698
+ if (match[i + 1] !== undefined) {
2699
+ return this.groups[i]
2700
+ }
2701
+ }
2702
+ throw new Error('Cannot find token type for matched text')
2703
+ };
2704
+
2705
+ function tokenToString() {
2706
+ return this.value
2707
+ }
2708
+
2709
+ Lexer.prototype.next = function() {
2710
+ var index = this.index;
2711
+
2712
+ // If a fallback token matched, we don't need to re-run the RegExp
2713
+ if (this.queuedGroup) {
2714
+ var token = this._token(this.queuedGroup, this.queuedText, index);
2715
+ this.queuedGroup = null;
2716
+ this.queuedText = "";
2717
+ return token
2718
+ }
2719
+
2720
+ var buffer = this.buffer;
2721
+ if (index === buffer.length) {
2722
+ return // EOF
2723
+ }
2724
+
2725
+ // Fast matching for single characters
2726
+ var group = this.fast[buffer.charCodeAt(index)];
2727
+ if (group) {
2728
+ return this._token(group, buffer.charAt(index), index)
2729
+ }
2730
+
2731
+ // Execute RegExp
2732
+ var re = this.re;
2733
+ re.lastIndex = index;
2734
+ var match = eat(re, buffer);
2735
+
2736
+ // Error tokens match the remaining buffer
2737
+ var error = this.error;
2738
+ if (match == null) {
2739
+ return this._token(error, buffer.slice(index, buffer.length), index)
2740
+ }
2741
+
2742
+ var group = this._getGroup(match);
2743
+ var text = match[0];
2744
+
2745
+ if (error.fallback && match.index !== index) {
2746
+ this.queuedGroup = group;
2747
+ this.queuedText = text;
2748
+
2749
+ // Fallback tokens contain the unmatched portion of the buffer
2750
+ return this._token(error, buffer.slice(index, match.index), index)
2751
+ }
2752
+
2753
+ return this._token(group, text, index)
2754
+ };
2755
+
2756
+ Lexer.prototype._token = function(group, text, offset) {
2757
+ // count line breaks
2758
+ var lineBreaks = 0;
2759
+ if (group.lineBreaks) {
2760
+ var matchNL = /\n/g;
2761
+ var nl = 1;
2762
+ if (text === '\n') {
2763
+ lineBreaks = 1;
2764
+ } else {
2765
+ while (matchNL.exec(text)) { lineBreaks++; nl = matchNL.lastIndex; }
2766
+ }
2767
+ }
2768
+
2769
+ var token = {
2770
+ type: (typeof group.type === 'function' && group.type(text)) || group.defaultType,
2771
+ value: typeof group.value === 'function' ? group.value(text) : text,
2772
+ text: text,
2773
+ toString: tokenToString,
2774
+ offset: offset,
2775
+ lineBreaks: lineBreaks,
2776
+ line: this.line,
2777
+ col: this.col,
2778
+ };
2779
+ // nb. adding more props to token object will make V8 sad!
2780
+
2781
+ var size = text.length;
2782
+ this.index += size;
2783
+ this.line += lineBreaks;
2784
+ if (lineBreaks !== 0) {
2785
+ this.col = size - nl + 1;
2786
+ } else {
2787
+ this.col += size;
2788
+ }
2789
+
2790
+ // throw, if no rule with {error: true}
2791
+ if (group.shouldThrow) {
2792
+ var err = new Error(this.formatError(token, "invalid syntax"));
2793
+ throw err;
2794
+ }
2795
+
2796
+ if (group.pop) this.popState();
2797
+ else if (group.push) this.pushState(group.push);
2798
+ else if (group.next) this.setState(group.next);
2799
+
2800
+ return token
2801
+ };
2802
+
2803
+ if (typeof Symbol !== 'undefined' && Symbol.iterator) {
2804
+ var LexerIterator = function(lexer) {
2805
+ this.lexer = lexer;
2806
+ };
2807
+
2808
+ LexerIterator.prototype.next = function() {
2809
+ var token = this.lexer.next();
2810
+ return {value: token, done: !token}
2811
+ };
2812
+
2813
+ LexerIterator.prototype[Symbol.iterator] = function() {
2814
+ return this
2815
+ };
2816
+
2817
+ Lexer.prototype[Symbol.iterator] = function() {
2818
+ return new LexerIterator(this)
2819
+ };
2820
+ }
2821
+
2822
+ Lexer.prototype.formatError = function(token, message) {
2823
+ if (token == null) {
2824
+ // An undefined token indicates EOF
2825
+ var text = this.buffer.slice(this.index);
2826
+ var token = {
2827
+ text: text,
2828
+ offset: this.index,
2829
+ lineBreaks: text.indexOf('\n') === -1 ? 0 : 1,
2830
+ line: this.line,
2831
+ col: this.col,
2832
+ };
2833
+ }
2834
+
2835
+ var numLinesAround = 2;
2836
+ var firstDisplayedLine = Math.max(token.line - numLinesAround, 1);
2837
+ var lastDisplayedLine = token.line + numLinesAround;
2838
+ var lastLineDigits = String(lastDisplayedLine).length;
2839
+ var displayedLines = lastNLines(
2840
+ this.buffer,
2841
+ (this.line - token.line) + numLinesAround + 1
2842
+ )
2843
+ .slice(0, 5);
2844
+ var errorLines = [];
2845
+ errorLines.push(message + " at line " + token.line + " col " + token.col + ":");
2846
+ errorLines.push("");
2847
+ for (var i = 0; i < displayedLines.length; i++) {
2848
+ var line = displayedLines[i];
2849
+ var lineNo = firstDisplayedLine + i;
2850
+ errorLines.push(pad(String(lineNo), lastLineDigits) + " " + line);
2851
+ if (lineNo === token.line) {
2852
+ errorLines.push(pad("", lastLineDigits + token.col + 1) + "^");
2853
+ }
2854
+ }
2855
+ return errorLines.join("\n")
2856
+ };
2857
+
2858
+ Lexer.prototype.clone = function() {
2859
+ return new Lexer(this.states, this.state)
2860
+ };
2861
+
2862
+ Lexer.prototype.has = function(tokenType) {
2863
+ return true
2864
+ };
2865
+
2866
+
2867
+ return {
2868
+ compile: compile,
2869
+ states: compileStates,
2870
+ error: Object.freeze({error: true}),
2871
+ fallback: Object.freeze({fallback: true}),
2872
+ keywords: keywordTransform,
2873
+ }
2874
+
2875
+ }));
2876
+ } (moo$1));
2877
+
2878
+ const moo = moo$1.exports;
2879
+
2880
+
2881
+ const digit = `[0-9]`;
2882
+ const digit19 = `[1-9]`;
2883
+ const hexdig = `[0-9a-fA-F]`;
2884
+
2885
+ // String
2886
+ const unescaped = `[\\x20-\\x21\\x23-\\x5b\\x5d-\\u{10ffff}]`;
2887
+ const escape = `\\\\`;
2888
+ const escaped = `${escape}(?:["\\/\\\\brfnt]|u${hexdig}{4})`;
2889
+ const char = `(?:${unescaped}|${escaped})`;
2890
+ const string = `"${char}*"`;
2891
+
2892
+ // Number
2893
+ const int = `(?:0|${digit19}${digit}*)`;
2894
+ const frac = `\\.${digit}+`;
2895
+ const e = `[eE]`;
2896
+ const exp = `${e}[-+]?${digit}+`;
2897
+ const number = `-?${int}(?:${frac})?(?:${exp})?`;
2898
+
2899
+ // Whitespace
2900
+ const whitespace = `(?:(?:\\r?\\n)|[ \\t])+`;
2901
+
2902
+ var lexer = (json) => {
2903
+ const lexer = moo.states({
2904
+ main: {
2905
+ WS: { match: new RegExp(whitespace, "u"), lineBreaks: true },
2906
+ true: { match: "true", value: () => true },
2907
+ false: { match: "false", value: () => false },
2908
+ null: { match: "null", value: () => null },
2909
+ number: { match: new RegExp(number, "u"), value: parseFloat },
2910
+ string: { match: new RegExp(string, "u"), value: JSON.parse },
2911
+ "{": "{",
2912
+ "}": "}",
2913
+ "[": "[",
2914
+ "]": "]",
2915
+ ":": ":",
2916
+ ",": ",",
2917
+ error: moo.error
2918
+ }
2919
+ });
2920
+ lexer.reset(json);
2921
+
2922
+ const _next = () => {
2923
+ let token;
2924
+ do {
2925
+ token = lexer.next();
2926
+ if (token?.type === "error") {
2927
+ throw SyntaxError(lexer.formatError(token, "Unrecognized token"));
2928
+ }
2929
+ } while (token?.type === "WS");
2930
+
2931
+ return token;
2932
+ };
2933
+
2934
+ let previous;
2935
+ let nextToken = _next();
2936
+
2937
+ const next = (expectedType = undefined) => {
2938
+ previous = nextToken;
2939
+ nextToken = _next();
2940
+ if (expectedType && previous?.type !== expectedType) {
2941
+ throw SyntaxError(lexer.formatError(previous, `Expected a '${expectedType}'`));
2942
+ }
2943
+ return previous;
2944
+ };
2945
+
2946
+ const peek = () => nextToken;
2947
+
2948
+ const defaultErrorToken = { offset: 0, line: 1, col: 0, text: "" };
2949
+ const syntaxError = (message) => {
2950
+ const referenceToken = previous || defaultErrorToken;
2951
+ const errorToken = {
2952
+ ...referenceToken,
2953
+ offset: referenceToken.offset + referenceToken.text.length,
2954
+ col: referenceToken.col + referenceToken.text.length
2955
+ };
2956
+ throw new SyntaxError(lexer.formatError(errorToken, message));
2957
+ };
2958
+
2959
+ return { next, peek, syntaxError };
2960
+ };
2961
+
2962
+ const JsonPointer$2 = lib$4;
2963
+ const jsonLexer = lexer;
2964
+
2965
+
2966
+ const defaultReviver = (key, value) => value;
2967
+ const parse$3 = (json, reviver = defaultReviver) => {
2968
+ const lexer = jsonLexer(json);
2969
+ const value = parseValue(lexer, "", JsonPointer$2.nil, reviver);
2970
+
2971
+ const token = lexer.peek();
2972
+ if (token) {
2973
+ lexer.syntaxError("A value has been parsed, but more tokens were found");
2974
+ }
2975
+ return value;
2976
+ };
2977
+
2978
+ const parseValue = (lexer, key, pointer, reviver) => {
2979
+ let value;
2980
+ const token = lexer.next();
2981
+ switch (token?.type) {
2982
+ case "true":
2983
+ case "false":
2984
+ case "null":
2985
+ case "number":
2986
+ case "string":
2987
+ value = token.value;
2988
+ break;
2989
+ case "{":
2990
+ value = parseObject(lexer, key, pointer, reviver);
2991
+ break;
2992
+ case "[":
2993
+ value = parseArray(lexer, key, pointer, reviver);
2994
+ break;
2995
+ default:
2996
+ lexer.syntaxError("Expected a JSON value");
2997
+ }
2998
+
2999
+ return reviver(key, value, pointer);
3000
+ };
3001
+
3002
+ const parseObject = (lexer, key, pointer, reviver) => {
3003
+ const value = {};
3004
+
3005
+ if (lexer.peek()?.type !== "}") {
3006
+ parseProperties(lexer, key, pointer, reviver, value);
3007
+ }
3008
+
3009
+ lexer.next("}");
3010
+
3011
+ return value;
3012
+ };
3013
+
3014
+ const parseProperties = (lexer, key, pointer, reviver, value) => {
3015
+ const propertyName = lexer.next("string").value;
3016
+ lexer.next(":");
3017
+ if (!isValueToken(lexer.peek())) {
3018
+ lexer.syntaxError("Expected a JSON value");
3019
+ }
3020
+ value[propertyName] = parseValue(lexer, propertyName, JsonPointer$2.append(propertyName, pointer), reviver);
3021
+
3022
+ if (lexer.peek()?.type === ",") {
3023
+ lexer.next(); // burn comma
3024
+ parseProperties(lexer, propertyName, pointer, reviver, value);
3025
+ } else if (isValueToken(lexer.peek())) {
3026
+ lexer.next(",");
3027
+ }
3028
+ };
3029
+
3030
+ const parseArray = (lexer, key, pointer, reviver) => {
3031
+ const value = [];
3032
+
3033
+ if (lexer.peek()?.type !== "]") {
3034
+ parseItems(lexer, 0, pointer, reviver, value);
3035
+ }
3036
+
3037
+ lexer.next("]");
3038
+
3039
+ return value;
3040
+ };
3041
+
3042
+ const parseItems = (lexer, key, pointer, reviver, value) => {
3043
+ if (!isValueToken(lexer.peek())) {
3044
+ lexer.syntaxError("Expected a JSON value");
3045
+ }
3046
+ value[key] = parseValue(lexer, key, JsonPointer$2.append(key, pointer), reviver);
3047
+ if (lexer.peek()?.type === ",") {
3048
+ lexer.next(); // burn comma
3049
+ parseItems(lexer, key + 1, pointer, reviver, value);
3050
+ } else if (isValueToken(lexer.peek())) {
3051
+ lexer.next(",");
3052
+ }
3053
+ };
3054
+
3055
+ const valueType = new Set(["string", "number", "true", "false", "null", "[", "{"]);
3056
+ const isValueToken = (token) => valueType.has(token?.type);
3057
+
3058
+ var parse_1 = parse$3;
3059
+
3060
+ const JsonPointer$1 = lib$4;
3061
+
3062
+
3063
+ const defaultReplacer = (key, value) => value;
3064
+ const stringify$2 = (value, replacer = defaultReplacer, space = "") => {
3065
+ return stringifyValue(value, replacer, space, "", JsonPointer$1.nil, 1);
3066
+ };
3067
+
3068
+ const stringifyValue = (value, replacer, space, key, pointer, depth) => {
3069
+ value = replacer(key, value, pointer);
3070
+ let result;
3071
+ if (Array.isArray(value)) {
3072
+ result = stringifyArray(value, replacer, space, pointer, depth);
3073
+ } else if (typeof value === "object" && value !== null) {
3074
+ result = stringifyObject(value, replacer, space, pointer, depth);
3075
+ } else {
3076
+ result = JSON.stringify(value);
3077
+ }
3078
+
3079
+ return result;
3080
+ };
3081
+
3082
+ const stringifyArray = (value, replacer, space, pointer, depth) => {
3083
+ if (value.length === 0) {
3084
+ space = "";
3085
+ }
3086
+ const padding = space ? `\n${space.repeat(depth - 1)}` : "";
3087
+ return "[" + padding + space + value
3088
+ .map((item, index) => {
3089
+ const indexPointer = JsonPointer$1.append(index, pointer);
3090
+ return stringifyValue(item, replacer, space, index, indexPointer, depth + 1);
3091
+ })
3092
+ .join(`,${padding}${space}`) + padding + "]";
3093
+ };
3094
+
3095
+ const stringifyObject = (value, replacer, space, pointer, depth) => {
3096
+ if (Object.keys(value).length === 0) {
3097
+ space = "";
3098
+ }
3099
+ const padding = space ? `\n${space.repeat(depth - 1)}` : "";
3100
+ const spacing = space ? " " : "";
3101
+ return "{" + padding + space + Object.entries(value)
3102
+ .map(([key, value]) => {
3103
+ const keyPointer = JsonPointer$1.append(key, pointer);
3104
+ return JSON.stringify(key) + ":" + spacing + stringifyValue(value, replacer, space, key, keyPointer, depth + 1);
3105
+ })
3106
+ .join(`,${padding}${space}`) + padding + "}";
3107
+ };
3108
+
3109
+ var stringify_1 = stringify$2;
3110
+
3111
+ const parse$2 = parse_1;
3112
+ const stringify$1 = stringify_1;
3113
+
3114
+
3115
+ var lib$2 = { parse: parse$2, stringify: stringify$1 };
3116
+
2234
3117
  var fetch_browser = fetch;
2235
3118
 
2236
3119
  var contentType = {};
@@ -2486,8 +3369,9 @@ const getContentType = (path) => {
2486
3369
  var mediaTypes = { addPlugin, parse, getContentType };
2487
3370
 
2488
3371
  const curry$1 = justCurryIt$1;
2489
- const Pact$a = lib$2;
2490
- const JsonPointer = lib$3;
3372
+ const Pact$a = lib$3;
3373
+ const Json = lib$2;
3374
+ const JsonPointer = lib$4;
2491
3375
  const { jsonTypeOf, resolveUrl: resolveUrl$1, urlFragment, pathRelative } = common$1;
2492
3376
  const fetch$1 = fetch_browser;
2493
3377
  const Reference$1 = reference;
@@ -2769,36 +3653,43 @@ const toSchemaDefaultOptions = {
2769
3653
  const toSchema = (schemaDoc, options = {}) => {
2770
3654
  const fullOptions = { ...toSchemaDefaultOptions, ...options };
2771
3655
 
2772
- const schema = JSON.parse(JSON.stringify(schemaDoc.schema, (key, value) => {
2773
- if (!Reference$1.isReference(value)) {
2774
- return value;
3656
+ const anchorToken = getConfig(schemaDoc.dialectId, "anchorToken");
3657
+ const dynamicAnchorToken = getConfig(schemaDoc.dialectId, "dynamicAnchorToken");
3658
+
3659
+ const anchors = {};
3660
+ for (const anchor in schemaDoc.anchors) {
3661
+ if (anchor !== "" && !schemaDoc.dynamicAnchors[anchor]) {
3662
+ anchors[schemaDoc.anchors[anchor]] = anchor;
2775
3663
  }
3664
+ }
2776
3665
 
2777
- const refValue = Reference$1.value(value);
2778
- const embeddedDialect = typeof refValue.$schema === "string" ? resolveUrl$1(refValue.$schema, "") : schemaDoc.dialectId;
2779
- const embeddedToken = getConfig(embeddedDialect, "embeddedToken");
2780
- if (!fullOptions.includeEmbedded && embeddedToken in refValue) {
2781
- return;
3666
+ const dynamicAnchors = {};
3667
+ for (const anchor in schemaDoc.dynamicAnchors) {
3668
+ const pointer = urlFragment(schemaDoc.dynamicAnchors[anchor]);
3669
+ dynamicAnchors[pointer] = anchor;
3670
+ }
3671
+
3672
+ const schema = JSON.parse(Json.stringify(schemaDoc.schema, (key, value, pointer) => {
3673
+ if (Reference$1.isReference(value)) {
3674
+ const refValue = Reference$1.value(value);
3675
+ const embeddedDialect = typeof refValue.$schema === "string" ? resolveUrl$1(refValue.$schema, "") : schemaDoc.dialectId;
3676
+ const embeddedToken = getConfig(embeddedDialect, "embeddedToken");
3677
+ if (!fullOptions.includeEmbedded && embeddedToken in refValue) {
3678
+ return;
3679
+ } else {
3680
+ return Reference$1.value(value);
3681
+ }
2782
3682
  } else {
2783
- return Reference$1.value(value);
3683
+ if (pointer in anchors) {
3684
+ value = { [anchorToken]: anchors[pointer], ...value };
3685
+ }
3686
+ if (pointer in dynamicAnchors) {
3687
+ value = { [dynamicAnchorToken]: dynamicAnchors[pointer], ...value };
3688
+ }
3689
+ return value;
2784
3690
  }
2785
3691
  }));
2786
3692
 
2787
- const dynamicAnchorToken = getConfig(schemaDoc.dialectId, "dynamicAnchorToken");
2788
- Object.entries(schemaDoc.dynamicAnchors)
2789
- .forEach(([anchor, uri]) => {
2790
- const pointer = JsonPointer.append(dynamicAnchorToken, urlFragment(uri));
2791
- JsonPointer.assign(pointer, schema, anchor);
2792
- });
2793
-
2794
- const anchorToken = getConfig(schemaDoc.dialectId, "anchorToken");
2795
- Object.entries(schemaDoc.anchors)
2796
- .filter(([anchor]) => anchor !== "" && !(anchor in schemaDoc.dynamicAnchors))
2797
- .forEach(([anchor, pointer]) => {
2798
- const anchorPointer = JsonPointer.append(anchorToken, pointer);
2799
- JsonPointer.assign(anchorPointer, schema, anchor);
2800
- });
2801
-
2802
3693
  const baseToken = getConfig(schemaDoc.dialectId, "baseToken");
2803
3694
  const id = relativeUri(fullOptions.parentId, schemaDoc.id);
2804
3695
  const dialect = fullOptions.parentDialect === schemaDoc.dialectId ? "" : schemaDoc.dialectId;
@@ -3049,7 +3940,7 @@ var core$2 = {
3049
3940
  addMediaTypePlugin: MediaTypes.addPlugin
3050
3941
  };
3051
3942
 
3052
- const Pact$9 = lib$2;
3943
+ const Pact$9 = lib$3;
3053
3944
  const PubSub = pubsub.exports;
3054
3945
  const Core$x = core$2;
3055
3946
  const Instance$B = instance;
@@ -3280,7 +4171,7 @@ const collectEvaluatedProperties$c = (keywordValue, instance, ast, dynamicAnchor
3280
4171
  var additionalProperties6 = { compile: compile$G, interpret: interpret$G, collectEvaluatedProperties: collectEvaluatedProperties$c };
3281
4172
 
3282
4173
  const { Core: Core$r, Schema: Schema$H } = lib$1;
3283
- const Pact$8 = lib$2;
4174
+ const Pact$8 = lib$3;
3284
4175
 
3285
4176
 
3286
4177
  const compile$F = (schema, ast) => Pact$8.pipeline([
@@ -3309,7 +4200,7 @@ const collectEvaluatedItems$c = (allOf, instance, ast, dynamicAnchors) => {
3309
4200
  var allOf = { compile: compile$F, interpret: interpret$F, collectEvaluatedProperties: collectEvaluatedProperties$b, collectEvaluatedItems: collectEvaluatedItems$c };
3310
4201
 
3311
4202
  const { Core: Core$q, Schema: Schema$G } = lib$1;
3312
- const Pact$7 = lib$2;
4203
+ const Pact$7 = lib$3;
3313
4204
 
3314
4205
 
3315
4206
  const compile$E = (schema, ast) => Pact$7.pipeline([
@@ -3452,7 +4343,7 @@ const collectEvaluatedItems$a = (keywordValue, instance, ast, dynamicAnchors) =>
3452
4343
  var containsMinContainsMaxContains = { compile: compile$B, interpret: interpret$B, collectEvaluatedItems: collectEvaluatedItems$a };
3453
4344
 
3454
4345
  const { Core: Core$n, Schema: Schema$D } = lib$1;
3455
- const Pact$6 = lib$2;
4346
+ const Pact$6 = lib$3;
3456
4347
 
3457
4348
 
3458
4349
  const compile$A = async (schema, ast) => {
@@ -3468,7 +4359,7 @@ const interpret$A = () => true;
3468
4359
  var definitions = { compile: compile$A, interpret: interpret$A };
3469
4360
 
3470
4361
  const { Core: Core$m, Schema: Schema$C, Instance: Instance$s } = lib$1;
3471
- const Pact$5 = lib$2;
4362
+ const Pact$5 = lib$3;
3472
4363
 
3473
4364
 
3474
4365
  const compile$z = (schema, ast) => Pact$5.pipeline([
@@ -3498,7 +4389,7 @@ const interpret$z = (dependencies, instance, ast, dynamicAnchors) => {
3498
4389
  var dependencies = { compile: compile$z, interpret: interpret$z };
3499
4390
 
3500
4391
  const { Schema: Schema$B, Instance: Instance$r } = lib$1;
3501
- const Pact$4 = lib$2;
4392
+ const Pact$4 = lib$3;
3502
4393
 
3503
4394
 
3504
4395
  const compile$y = (schema) => Pact$4.pipeline([
@@ -3518,7 +4409,7 @@ const interpret$y = (dependentRequired, instance) => {
3518
4409
  var dependentRequired = { compile: compile$y, interpret: interpret$y };
3519
4410
 
3520
4411
  const { Core: Core$l, Schema: Schema$A, Instance: Instance$q } = lib$1;
3521
- const Pact$3 = lib$2;
4412
+ const Pact$3 = lib$3;
3522
4413
 
3523
4414
 
3524
4415
  const compile$x = (schema, ast) => Pact$3.pipeline([
@@ -3927,7 +4818,7 @@ const interpret$b = (pattern, instance) => !Instance$9.typeOf(instance, "string"
3927
4818
  var pattern = { compile: compile$b, interpret: interpret$b };
3928
4819
 
3929
4820
  const { Core: Core$d, Schema: Schema$f, Instance: Instance$8 } = lib$1;
3930
- const Pact$2 = lib$2;
4821
+ const Pact$2 = lib$3;
3931
4822
 
3932
4823
 
3933
4824
  const compile$a = (schema, ast) => Pact$2.pipeline([
@@ -3965,7 +4856,7 @@ const splitUrl$1 = (url) => {
3965
4856
  var common = { isObject, escapeRegExp: escapeRegExp$1, splitUrl: splitUrl$1 };
3966
4857
 
3967
4858
  const { Core: Core$c, Schema: Schema$e, Instance: Instance$7 } = lib$1;
3968
- const Pact$1 = lib$2;
4859
+ const Pact$1 = lib$3;
3969
4860
  const { escapeRegExp } = common;
3970
4861
 
3971
4862
 
@@ -4053,7 +4944,7 @@ const interpret$5 = (required, instance) => {
4053
4944
  var required = { compile: compile$5, interpret: interpret$5 };
4054
4945
 
4055
4946
  const { Core: Core$8, Schema: Schema$a, Instance: Instance$4 } = lib$1;
4056
- const Pact = lib$2;
4947
+ const Pact = lib$3;
4057
4948
 
4058
4949
 
4059
4950
  const compile$4 = (schema, ast) => {