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