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