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