@hyperjump/json-schema 0.23.2 → 0.23.3

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