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