@hyperjump/json-schema 0.23.2 → 0.23.4

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