json-p3 2.2.2 → 2.3.0

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.
Files changed (46) hide show
  1. package/README.md +0 -1
  2. package/dist/json-p3.browser.js +5303 -0
  3. package/dist/json-p3.browser.min.js +2 -0
  4. package/dist/json-p3.browser.min.js.map +1 -0
  5. package/dist/json-p3.cjs.js +70 -97
  6. package/dist/json-p3.esm.js +70 -97
  7. package/dist/json-p3.iife.min.js +1 -1
  8. package/dist/json-p3.iife.min.js.map +1 -1
  9. package/package.json +11 -24
  10. package/dist/deep_equals.d.ts +0 -10
  11. package/dist/index.d.ts +0 -10
  12. package/dist/json-p3.iife.js +0 -5366
  13. package/dist/patch/errors.d.ts +0 -11
  14. package/dist/patch/index.d.ts +0 -11
  15. package/dist/patch/patch.d.ts +0 -161
  16. package/dist/path/environment.d.ts +0 -165
  17. package/dist/path/errors.d.ts +0 -65
  18. package/dist/path/expression.d.ts +0 -101
  19. package/dist/path/extra/expression.d.ts +0 -6
  20. package/dist/path/extra/index.d.ts +0 -0
  21. package/dist/path/extra/selectors.d.ts +0 -35
  22. package/dist/path/functions/count.d.ts +0 -7
  23. package/dist/path/functions/function.d.ts +0 -26
  24. package/dist/path/functions/has.d.ts +0 -44
  25. package/dist/path/functions/index.d.ts +0 -11
  26. package/dist/path/functions/length.d.ts +0 -7
  27. package/dist/path/functions/match.d.ts +0 -33
  28. package/dist/path/functions/pattern.d.ts +0 -2
  29. package/dist/path/functions/search.d.ts +0 -34
  30. package/dist/path/functions/value.d.ts +0 -7
  31. package/dist/path/index.d.ts +0 -76
  32. package/dist/path/lex.d.ts +0 -74
  33. package/dist/path/lru_cache.d.ts +0 -10
  34. package/dist/path/node.d.ts +0 -84
  35. package/dist/path/parse.d.ts +0 -61
  36. package/dist/path/path.d.ts +0 -42
  37. package/dist/path/segments.d.ts +0 -39
  38. package/dist/path/selectors.d.ts +0 -85
  39. package/dist/path/serialize.d.ts +0 -6
  40. package/dist/path/token.d.ts +0 -70
  41. package/dist/path/types.d.ts +0 -46
  42. package/dist/pointer/errors.d.ts +0 -42
  43. package/dist/pointer/index.d.ts +0 -24
  44. package/dist/pointer/pointer.d.ts +0 -106
  45. package/dist/tsconfig.tsbuildinfo +0 -1
  46. package/dist/types.d.ts +0 -25
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 2.2.2
2
+ * json-p3 version 2.3.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -335,10 +335,7 @@ class JSONPointer {
335
335
  }
336
336
  static encode(tokens) {
337
337
  if (!tokens.length) return "";
338
- return (
339
- // eslint-disable-next-line prefer-template
340
- "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/")
341
- );
338
+ return "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/");
342
339
  }
343
340
 
344
341
  /**
@@ -355,8 +352,7 @@ class JSONPointer {
355
352
  * If the value pointed to by _pointer_ does not exist in _value_, and
356
353
  * no fallback value is given.
357
354
  */
358
- resolve(value) {
359
- let fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : UNDEFINED;
355
+ resolve(value, fallback = UNDEFINED) {
360
356
  try {
361
357
  return this.tokens.reduce(this.getItem.bind(this), value);
362
358
  } catch (error) {
@@ -461,10 +457,7 @@ class JSONPointer {
461
457
  * @returns A new JSON Pointer that is the concatenation of all tokens or
462
458
  * "parts".
463
459
  */
464
- join() {
465
- for (var _len = arguments.length, tokens = new Array(_len), _key = 0; _key < _len; _key++) {
466
- tokens[_key] = arguments[_key];
467
- }
460
+ join(...tokens) {
468
461
  if (!tokens.length) {
469
462
  return this;
470
463
  }
@@ -513,7 +506,7 @@ class JSONPointer {
513
506
  }
514
507
  }
515
508
  const RE_RELATIVE_POINTER = /(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s;
516
- const RE_INT = /(0|[1-9][0-9]*)/;
509
+ const RE_INT = /(0|[1-9]\d*)/;
517
510
 
518
511
  /**
519
512
  * A relative JSON Pointer.
@@ -632,8 +625,7 @@ class RelativeJSONPointer {
632
625
  * @throws {@link JSONPointerSyntaxError}
633
626
  * If _pointer_ is malformed according to RFC 6901.
634
627
  */
635
- function resolve(pointer, value) {
636
- let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : UNDEFINED;
628
+ function resolve(pointer, value, fallback = UNDEFINED) {
637
629
  return new JSONPointer(pointer).resolve(value, fallback);
638
630
  }
639
631
 
@@ -737,10 +729,7 @@ class JSONPathNode {
737
729
  ...defaultSerializationOptions,
738
730
  ...options
739
731
  };
740
- return (
741
- // eslint-disable-next-line prefer-template
742
- "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("")
743
- );
732
+ return "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("");
744
733
  }
745
734
 
746
735
  /**
@@ -1135,16 +1124,16 @@ var expression = /*#__PURE__*/Object.freeze({
1135
1124
  });
1136
1125
 
1137
1126
  class Count {
1138
- argTypes = (() => [FunctionExpressionType.NodesType])();
1139
- returnType = (() => FunctionExpressionType.ValueType)();
1127
+ argTypes = [FunctionExpressionType.NodesType];
1128
+ returnType = FunctionExpressionType.ValueType;
1140
1129
  call(nodes) {
1141
1130
  return nodes.length;
1142
1131
  }
1143
1132
  }
1144
1133
 
1145
1134
  class Length {
1146
- argTypes = (() => [FunctionExpressionType.ValueType])();
1147
- returnType = (() => FunctionExpressionType.ValueType)();
1135
+ argTypes = [FunctionExpressionType.ValueType];
1136
+ returnType = FunctionExpressionType.ValueType;
1148
1137
  call(value) {
1149
1138
  if (isArray(value) || isString(value)) return value.length;
1150
1139
  if (isObject(value)) return Object.keys(value).length;
@@ -1156,9 +1145,7 @@ class Length {
1156
1145
  * A Least Recently Used cache, implemented as an extended Map.
1157
1146
  */
1158
1147
  class LRUCache extends Map {
1159
- constructor() {
1160
- let maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 128;
1161
- let entries = arguments.length > 1 ? arguments[1] : undefined;
1148
+ constructor(maxSize = 128, entries) {
1162
1149
  if (entries !== undefined) {
1163
1150
  super(entries);
1164
1151
  } else {
@@ -2476,11 +2463,10 @@ var check_1 = {
2476
2463
  var check$1 = check_1.check;
2477
2464
 
2478
2465
  class Match {
2479
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2480
- returnType = (() => FunctionExpressionType.LogicalType)();
2466
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2467
+ returnType = FunctionExpressionType.LogicalType;
2481
2468
  #cache;
2482
- constructor() {
2483
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2469
+ constructor(options = {}) {
2484
2470
  this.options = options;
2485
2471
  this.cacheSize = options.cacheSize ?? 10;
2486
2472
  this.throwErrors = options.throwErrors ?? false;
@@ -2525,11 +2511,10 @@ class Match {
2525
2511
  }
2526
2512
 
2527
2513
  class Search {
2528
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2529
- returnType = (() => FunctionExpressionType.LogicalType)();
2514
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2515
+ returnType = FunctionExpressionType.LogicalType;
2530
2516
  #cache;
2531
- constructor() {
2532
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2517
+ constructor(options = {}) {
2533
2518
  this.options = options;
2534
2519
  this.cacheSize = options.cacheSize ?? 10;
2535
2520
  this.throwErrors = options.throwErrors ?? false;
@@ -2574,8 +2559,8 @@ class Search {
2574
2559
  }
2575
2560
 
2576
2561
  class Value {
2577
- argTypes = (() => [FunctionExpressionType.NodesType])();
2578
- returnType = (() => FunctionExpressionType.ValueType)();
2562
+ argTypes = [FunctionExpressionType.NodesType];
2563
+ returnType = FunctionExpressionType.ValueType;
2579
2564
  call(nodes) {
2580
2565
  if (nodes.length === 1) return nodes.nodes[0].value;
2581
2566
  return Nothing;
@@ -2591,6 +2576,7 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2591
2576
  TokenKind["COMMA"] = "TOKEN_COMMA";
2592
2577
  TokenKind["CURRENT"] = "TOKEN_CURRENT_VALUE";
2593
2578
  TokenKind["CURRENT_KEY"] = "TOKEN_CURRENT_KEY";
2579
+ // non-standard, default `#`
2594
2580
  TokenKind["DDOT"] = "TOKEN_DDOT";
2595
2581
  TokenKind["DOT"] = "TOKEN_DOT";
2596
2582
  TokenKind["DOUBLE_QUOTE_STRING"] = "TOKEN_DOUBLE_QUOTE_STRING";
@@ -2604,10 +2590,15 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2604
2590
  TokenKind["GT"] = "TOKEN_GT";
2605
2591
  TokenKind["INDEX"] = "TOKEN_INDEX";
2606
2592
  TokenKind["KEY"] = "TOKEN_KEY";
2593
+ // non-standard, default `~<name>`
2607
2594
  TokenKind["KEY_DOUBLE_QUOTE_STRING"] = "TOKEN_KEY_DOUBLE_QUOTE_STRING";
2595
+ // non-standard, `~"<name>"`
2608
2596
  TokenKind["KEY_SINGLE_QUOTE_STRING"] = "TOKEN_KEY_SINGLE_QUOTE_STRING";
2597
+ // non-standard, `~'<name>'`
2609
2598
  TokenKind["KEYS"] = "TOKEN_KEYS";
2599
+ // non-standard, default `~`
2610
2600
  TokenKind["KEYS_FILTER"] = "TOKEN_KEYS_FILTER";
2601
+ // non-standard, `~?<expression>`
2611
2602
  TokenKind["LBRACKET"] = "TOKEN_LBRACKET";
2612
2603
  TokenKind["LE"] = "TOKEN_LE";
2613
2604
  TokenKind["LG"] = "TOKEN_LG";
@@ -2691,7 +2682,7 @@ class TokenStream {
2691
2682
  const exponentPattern = /[eE][+-]?\d+/y;
2692
2683
  const functionNamePattern = /[a-z][a-z_0-9]*/y;
2693
2684
  const indexPattern = /-?\d+/y;
2694
- const intPattern = /-?[0-9]+/y;
2685
+ const intPattern = /-?\d+/y;
2695
2686
  const namePattern = /[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y;
2696
2687
  const whitespace = new Set([" ", "\n", "\t", "\r"]);
2697
2688
  const nameFirstPattern = /[\u0080-\uFFFFa-zA-Z_]/; // don't set sticky bit
@@ -3009,7 +3000,6 @@ function lexInsideBracketedSelection(l) {
3009
3000
  continue;
3010
3001
  }
3011
3002
  if (!l.environment.strict && l.acceptMatchRun(l.environment.keysPattern)) {
3012
- // FIXME: fall back to legacy behavior if keysPattern is not the default
3013
3003
  switch (l.peek()) {
3014
3004
  case "'":
3015
3005
  l.ignore(); // ~
@@ -3401,10 +3391,7 @@ class SliceSelector extends JSONPathSelector {
3401
3391
  const step = this.step ? this.step : "1";
3402
3392
  return `${start}:${stop}:${step}`;
3403
3393
  }
3404
- checkRange() {
3405
- for (var _len = arguments.length, indices = new Array(_len), _key = 0; _key < _len; _key++) {
3406
- indices[_key] = arguments[_key];
3407
- }
3394
+ checkRange(...indices) {
3408
3395
  for (const index of indices) {
3409
3396
  if (index !== undefined && (index < this.environment.minIntIndex || index > this.environment.maxIntIndex)) {
3410
3397
  throw new JSONPathIndexError("index out of range", this.token);
@@ -3691,53 +3678,45 @@ class DescendantSegment extends JSONPathSegment {
3691
3678
  toString(options) {
3692
3679
  return `..[${this.selectors.map(s => s.toString(options)).join(", ")}]`;
3693
3680
  }
3694
- visit(node) {
3695
- var _this = this;
3696
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3697
- return function* () {
3698
- if (depth >= _this.environment.maxRecursionDepth) {
3699
- throw new JSONPathRecursionLimitError("recursion limit reached", _this.token);
3681
+ *visit(node, depth = 1) {
3682
+ if (depth >= this.environment.maxRecursionDepth) {
3683
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3684
+ }
3685
+ yield node;
3686
+ if (isArray(node.value)) {
3687
+ for (let i = 0; i < node.value.length; i++) {
3688
+ const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3689
+ yield* this.visit(_node, depth + 1);
3700
3690
  }
3691
+ } else if (isObject(node.value)) {
3692
+ for (const [key, value] of this.environment.entries(node.value)) {
3693
+ const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3694
+ yield* this.visit(_node, depth + 1);
3695
+ }
3696
+ }
3697
+ }
3698
+ *nondeterministicVisit(root, depth = 1) {
3699
+ let queue = Array.from(this.nondeterministicChildren(root)).map(node => [node, depth]);
3700
+ yield root;
3701
+ while (queue.length) {
3702
+ const [node, _depth] = queue.shift();
3701
3703
  yield node;
3702
- if (isArray(node.value)) {
3703
- for (let i = 0; i < node.value.length; i++) {
3704
- const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3705
- yield* _this.visit(_node, depth + 1);
3706
- }
3707
- } else if (isObject(node.value)) {
3708
- for (const [key, value] of _this.environment.entries(node.value)) {
3709
- const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3710
- yield* _this.visit(_node, depth + 1);
3711
- }
3704
+ if (_depth >= this.environment.maxRecursionDepth) {
3705
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3712
3706
  }
3713
- }();
3714
- }
3715
- nondeterministicVisit(root) {
3716
- var _this2 = this;
3717
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3718
- return function* () {
3719
- let queue = Array.from(_this2.nondeterministicChildren(root)).map(node => [node, depth]);
3720
- yield root;
3721
- while (queue.length) {
3722
- const [node, _depth] = queue.shift();
3723
- yield node;
3724
- if (_depth >= _this2.environment.maxRecursionDepth) {
3725
- throw new JSONPathRecursionLimitError("recursion limit reached", _this2.token);
3726
- }
3727
3707
 
3728
- // Visit child nodes now or queue them for later?
3729
- const visitChildren = Math.random() < 0.5;
3730
- for (const child of _this2.nondeterministicChildren(node)) {
3731
- if (visitChildren) {
3732
- yield child;
3733
- const grandchildren = Array.from(_this2.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3734
- queue = interleave(queue, grandchildren);
3735
- } else {
3736
- queue.push([child, _depth + 1]);
3737
- }
3708
+ // Visit child nodes now or queue them for later?
3709
+ const visitChildren = Math.random() < 0.5;
3710
+ for (const child of this.nondeterministicChildren(node)) {
3711
+ if (visitChildren) {
3712
+ yield child;
3713
+ const grandchildren = Array.from(this.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3714
+ queue = interleave(queue, grandchildren);
3715
+ } else {
3716
+ queue.push([child, _depth + 1]);
3738
3717
  }
3739
3718
  }
3740
- }();
3719
+ }
3741
3720
  }
3742
3721
  *nondeterministicChildren(node) {
3743
3722
  if (isString(node.value)) return;
@@ -4003,8 +3982,7 @@ class Parser {
4003
3982
  }
4004
3983
  return segments;
4005
3984
  }
4006
- parseQuery(stream) {
4007
- let inFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3985
+ parseQuery(stream, inFilter = false) {
4008
3986
  const segments = [];
4009
3987
  loop: for (;;) {
4010
3988
  switch (stream.current.kind) {
@@ -4156,8 +4134,7 @@ class Parser {
4156
4134
  }
4157
4135
  return selectors;
4158
4136
  }
4159
- parseFilter(stream) {
4160
- let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
4137
+ parseFilter(stream, keys = false) {
4161
4138
  const tok = stream.next();
4162
4139
  const expr = this.parseFilterExpression(stream);
4163
4140
  if (expr instanceof FunctionExtension) {
@@ -4271,8 +4248,7 @@ class Parser {
4271
4248
  stream.expect(TokenKind.RPAREN);
4272
4249
  return new FunctionExtension(tok, tok.value, this.environment.checkWellTypedness(tok, args));
4273
4250
  }
4274
- parseFilterExpression(stream) {
4275
- let precedence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PRECEDENCE_LOWEST;
4251
+ parseFilterExpression(stream, precedence = PRECEDENCE_LOWEST) {
4276
4252
  const func = this.tokenMap.get(stream.current.kind);
4277
4253
  if (!func) {
4278
4254
  let msg;
@@ -4342,7 +4318,6 @@ class Parser {
4342
4318
  rv.push(this.stringFromCodePoint(codepoint, token));
4343
4319
  break;
4344
4320
  default:
4345
- // TODO: This is unreachable. The lexer will catch unknown escape sequences.
4346
4321
  throw new JSONPathSyntaxError(`unknown escape sequence at index ${token.index + index - 1}`, token);
4347
4322
  }
4348
4323
  } else {
@@ -4522,12 +4497,11 @@ class JSONPathEnvironment {
4522
4497
  * A map of function names to objects implementing the {@link FilterFunction}
4523
4498
  * interface. You are free to set or delete custom filter functions directly.
4524
4499
  */
4525
- functionRegister = (() => new Map())();
4500
+ functionRegister = new Map();
4526
4501
  /**
4527
4502
  * @param options - Environment configuration options.
4528
4503
  */
4529
- constructor() {
4530
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4504
+ constructor(options = {}) {
4531
4505
  this.strict = options.strict ?? true;
4532
4506
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
4533
4507
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) + 1;
@@ -4672,11 +4646,10 @@ class JSONPathEnvironment {
4672
4646
  * value and it contains a property matching the second argument.
4673
4647
  */
4674
4648
  class Has {
4675
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
4676
- returnType = (() => FunctionExpressionType.LogicalType)();
4649
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
4650
+ returnType = FunctionExpressionType.LogicalType;
4677
4651
  #cache;
4678
- constructor() {
4679
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4652
+ constructor(options = {}) {
4680
4653
  this.options = options;
4681
4654
  this.cacheSize = options.cacheSize ?? 10;
4682
4655
  this.throwErrors = options.throwErrors ?? false;
@@ -5325,6 +5298,6 @@ var index = /*#__PURE__*/Object.freeze({
5325
5298
  apply: apply
5326
5299
  });
5327
5300
 
5328
- const version = "2.2.2";
5301
+ const version = "2.3.0";
5329
5302
 
5330
5303
  export { DEFAULT_ENVIRONMENT, FunctionExpressionType, JSONPatch, JSONPatchError, JSONPatchTestFailure, JSONPathEnvironment, JSONPathError, JSONPathIndexError, JSONPathLexerError, JSONPathNode, JSONPathNodeList, JSONPathQuery, JSONPathRecursionLimitError, JSONPathSyntaxError, JSONPathTypeError, JSONPointer, Nothing, RelativeJSONPointer, Token, TokenKind, UNDEFINED, apply, compile, index as jsonpatch, index$1 as jsonpath, index$3 as jsonpointer, lazyQuery, query, resolve, version };