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