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