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