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
@@ -337,10 +337,7 @@ class JSONPointer {
337
337
  }
338
338
  static encode(tokens) {
339
339
  if (!tokens.length) return "";
340
- return (
341
- // eslint-disable-next-line prefer-template
342
- "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/")
343
- );
340
+ return "/" + tokens.map(token => token.replaceAll("~", "~0").replaceAll("/", "~1")).join("/");
344
341
  }
345
342
 
346
343
  /**
@@ -357,8 +354,7 @@ class JSONPointer {
357
354
  * If the value pointed to by _pointer_ does not exist in _value_, and
358
355
  * no fallback value is given.
359
356
  */
360
- resolve(value) {
361
- let fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : UNDEFINED;
357
+ resolve(value, fallback = UNDEFINED) {
362
358
  try {
363
359
  return this.tokens.reduce(this.getItem.bind(this), value);
364
360
  } catch (error) {
@@ -463,10 +459,7 @@ class JSONPointer {
463
459
  * @returns A new JSON Pointer that is the concatenation of all tokens or
464
460
  * "parts".
465
461
  */
466
- join() {
467
- for (var _len = arguments.length, tokens = new Array(_len), _key = 0; _key < _len; _key++) {
468
- tokens[_key] = arguments[_key];
469
- }
462
+ join(...tokens) {
470
463
  if (!tokens.length) {
471
464
  return this;
472
465
  }
@@ -515,7 +508,7 @@ class JSONPointer {
515
508
  }
516
509
  }
517
510
  const RE_RELATIVE_POINTER = /(?<ORIGIN>\d+)(?<INDEX_G>(?<SIGN>[+-])(?<INDEX>\d))?(?<POINTER>.*)/s;
518
- const RE_INT = /(0|[1-9][0-9]*)/;
511
+ const RE_INT = /(0|[1-9]\d*)/;
519
512
 
520
513
  /**
521
514
  * A relative JSON Pointer.
@@ -634,8 +627,7 @@ class RelativeJSONPointer {
634
627
  * @throws {@link JSONPointerSyntaxError}
635
628
  * If _pointer_ is malformed according to RFC 6901.
636
629
  */
637
- function resolve(pointer, value) {
638
- let fallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : UNDEFINED;
630
+ function resolve(pointer, value, fallback = UNDEFINED) {
639
631
  return new JSONPointer(pointer).resolve(value, fallback);
640
632
  }
641
633
 
@@ -739,10 +731,7 @@ class JSONPathNode {
739
731
  ...defaultSerializationOptions,
740
732
  ...options
741
733
  };
742
- return (
743
- // eslint-disable-next-line prefer-template
744
- "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("")
745
- );
734
+ return "$" + this.location.map(s => isString(s) ? this.decodeNameLocation(s, opts) : `[${s}]`).join("");
746
735
  }
747
736
 
748
737
  /**
@@ -1137,16 +1126,16 @@ var expression = /*#__PURE__*/Object.freeze({
1137
1126
  });
1138
1127
 
1139
1128
  class Count {
1140
- argTypes = (() => [FunctionExpressionType.NodesType])();
1141
- returnType = (() => FunctionExpressionType.ValueType)();
1129
+ argTypes = [FunctionExpressionType.NodesType];
1130
+ returnType = FunctionExpressionType.ValueType;
1142
1131
  call(nodes) {
1143
1132
  return nodes.length;
1144
1133
  }
1145
1134
  }
1146
1135
 
1147
1136
  class Length {
1148
- argTypes = (() => [FunctionExpressionType.ValueType])();
1149
- returnType = (() => FunctionExpressionType.ValueType)();
1137
+ argTypes = [FunctionExpressionType.ValueType];
1138
+ returnType = FunctionExpressionType.ValueType;
1150
1139
  call(value) {
1151
1140
  if (isArray(value) || isString(value)) return value.length;
1152
1141
  if (isObject(value)) return Object.keys(value).length;
@@ -1158,9 +1147,7 @@ class Length {
1158
1147
  * A Least Recently Used cache, implemented as an extended Map.
1159
1148
  */
1160
1149
  class LRUCache extends Map {
1161
- constructor() {
1162
- let maxSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 128;
1163
- let entries = arguments.length > 1 ? arguments[1] : undefined;
1150
+ constructor(maxSize = 128, entries) {
1164
1151
  if (entries !== undefined) {
1165
1152
  super(entries);
1166
1153
  } else {
@@ -2478,11 +2465,10 @@ var check_1 = {
2478
2465
  var check$1 = check_1.check;
2479
2466
 
2480
2467
  class Match {
2481
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2482
- returnType = (() => FunctionExpressionType.LogicalType)();
2468
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2469
+ returnType = FunctionExpressionType.LogicalType;
2483
2470
  #cache;
2484
- constructor() {
2485
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2471
+ constructor(options = {}) {
2486
2472
  this.options = options;
2487
2473
  this.cacheSize = options.cacheSize ?? 10;
2488
2474
  this.throwErrors = options.throwErrors ?? false;
@@ -2527,11 +2513,10 @@ class Match {
2527
2513
  }
2528
2514
 
2529
2515
  class Search {
2530
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2531
- returnType = (() => FunctionExpressionType.LogicalType)();
2516
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2517
+ returnType = FunctionExpressionType.LogicalType;
2532
2518
  #cache;
2533
- constructor() {
2534
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2519
+ constructor(options = {}) {
2535
2520
  this.options = options;
2536
2521
  this.cacheSize = options.cacheSize ?? 10;
2537
2522
  this.throwErrors = options.throwErrors ?? false;
@@ -2576,8 +2561,8 @@ class Search {
2576
2561
  }
2577
2562
 
2578
2563
  class Value {
2579
- argTypes = (() => [FunctionExpressionType.NodesType])();
2580
- returnType = (() => FunctionExpressionType.ValueType)();
2564
+ argTypes = [FunctionExpressionType.NodesType];
2565
+ returnType = FunctionExpressionType.ValueType;
2581
2566
  call(nodes) {
2582
2567
  if (nodes.length === 1) return nodes.nodes[0].value;
2583
2568
  return Nothing;
@@ -2593,6 +2578,7 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2593
2578
  TokenKind["COMMA"] = "TOKEN_COMMA";
2594
2579
  TokenKind["CURRENT"] = "TOKEN_CURRENT_VALUE";
2595
2580
  TokenKind["CURRENT_KEY"] = "TOKEN_CURRENT_KEY";
2581
+ // non-standard, default `#`
2596
2582
  TokenKind["DDOT"] = "TOKEN_DDOT";
2597
2583
  TokenKind["DOT"] = "TOKEN_DOT";
2598
2584
  TokenKind["DOUBLE_QUOTE_STRING"] = "TOKEN_DOUBLE_QUOTE_STRING";
@@ -2606,10 +2592,15 @@ let TokenKind = /*#__PURE__*/function (TokenKind) {
2606
2592
  TokenKind["GT"] = "TOKEN_GT";
2607
2593
  TokenKind["INDEX"] = "TOKEN_INDEX";
2608
2594
  TokenKind["KEY"] = "TOKEN_KEY";
2595
+ // non-standard, default `~<name>`
2609
2596
  TokenKind["KEY_DOUBLE_QUOTE_STRING"] = "TOKEN_KEY_DOUBLE_QUOTE_STRING";
2597
+ // non-standard, `~"<name>"`
2610
2598
  TokenKind["KEY_SINGLE_QUOTE_STRING"] = "TOKEN_KEY_SINGLE_QUOTE_STRING";
2599
+ // non-standard, `~'<name>'`
2611
2600
  TokenKind["KEYS"] = "TOKEN_KEYS";
2601
+ // non-standard, default `~`
2612
2602
  TokenKind["KEYS_FILTER"] = "TOKEN_KEYS_FILTER";
2603
+ // non-standard, `~?<expression>`
2613
2604
  TokenKind["LBRACKET"] = "TOKEN_LBRACKET";
2614
2605
  TokenKind["LE"] = "TOKEN_LE";
2615
2606
  TokenKind["LG"] = "TOKEN_LG";
@@ -2693,7 +2684,7 @@ class TokenStream {
2693
2684
  const exponentPattern = /[eE][+-]?\d+/y;
2694
2685
  const functionNamePattern = /[a-z][a-z_0-9]*/y;
2695
2686
  const indexPattern = /-?\d+/y;
2696
- const intPattern = /-?[0-9]+/y;
2687
+ const intPattern = /-?\d+/y;
2697
2688
  const namePattern = /[\u0080-\uFFFFa-zA-Z_][\u0080-\uFFFFa-zA-Z0-9_-]*/y;
2698
2689
  const whitespace = new Set([" ", "\n", "\t", "\r"]);
2699
2690
  const nameFirstPattern = /[\u0080-\uFFFFa-zA-Z_]/; // don't set sticky bit
@@ -3011,7 +3002,6 @@ function lexInsideBracketedSelection(l) {
3011
3002
  continue;
3012
3003
  }
3013
3004
  if (!l.environment.strict && l.acceptMatchRun(l.environment.keysPattern)) {
3014
- // FIXME: fall back to legacy behavior if keysPattern is not the default
3015
3005
  switch (l.peek()) {
3016
3006
  case "'":
3017
3007
  l.ignore(); // ~
@@ -3403,10 +3393,7 @@ class SliceSelector extends JSONPathSelector {
3403
3393
  const step = this.step ? this.step : "1";
3404
3394
  return `${start}:${stop}:${step}`;
3405
3395
  }
3406
- checkRange() {
3407
- for (var _len = arguments.length, indices = new Array(_len), _key = 0; _key < _len; _key++) {
3408
- indices[_key] = arguments[_key];
3409
- }
3396
+ checkRange(...indices) {
3410
3397
  for (const index of indices) {
3411
3398
  if (index !== undefined && (index < this.environment.minIntIndex || index > this.environment.maxIntIndex)) {
3412
3399
  throw new JSONPathIndexError("index out of range", this.token);
@@ -3693,53 +3680,45 @@ class DescendantSegment extends JSONPathSegment {
3693
3680
  toString(options) {
3694
3681
  return `..[${this.selectors.map(s => s.toString(options)).join(", ")}]`;
3695
3682
  }
3696
- visit(node) {
3697
- var _this = this;
3698
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3699
- return function* () {
3700
- if (depth >= _this.environment.maxRecursionDepth) {
3701
- throw new JSONPathRecursionLimitError("recursion limit reached", _this.token);
3683
+ *visit(node, depth = 1) {
3684
+ if (depth >= this.environment.maxRecursionDepth) {
3685
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3686
+ }
3687
+ yield node;
3688
+ if (isArray(node.value)) {
3689
+ for (let i = 0; i < node.value.length; i++) {
3690
+ const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3691
+ yield* this.visit(_node, depth + 1);
3702
3692
  }
3693
+ } else if (isObject(node.value)) {
3694
+ for (const [key, value] of this.environment.entries(node.value)) {
3695
+ const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3696
+ yield* this.visit(_node, depth + 1);
3697
+ }
3698
+ }
3699
+ }
3700
+ *nondeterministicVisit(root, depth = 1) {
3701
+ let queue = Array.from(this.nondeterministicChildren(root)).map(node => [node, depth]);
3702
+ yield root;
3703
+ while (queue.length) {
3704
+ const [node, _depth] = queue.shift();
3703
3705
  yield node;
3704
- if (isArray(node.value)) {
3705
- for (let i = 0; i < node.value.length; i++) {
3706
- const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3707
- yield* _this.visit(_node, depth + 1);
3708
- }
3709
- } else if (isObject(node.value)) {
3710
- for (const [key, value] of _this.environment.entries(node.value)) {
3711
- const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3712
- yield* _this.visit(_node, depth + 1);
3713
- }
3706
+ if (_depth >= this.environment.maxRecursionDepth) {
3707
+ throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3714
3708
  }
3715
- }();
3716
- }
3717
- nondeterministicVisit(root) {
3718
- var _this2 = this;
3719
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3720
- return function* () {
3721
- let queue = Array.from(_this2.nondeterministicChildren(root)).map(node => [node, depth]);
3722
- yield root;
3723
- while (queue.length) {
3724
- const [node, _depth] = queue.shift();
3725
- yield node;
3726
- if (_depth >= _this2.environment.maxRecursionDepth) {
3727
- throw new JSONPathRecursionLimitError("recursion limit reached", _this2.token);
3728
- }
3729
3709
 
3730
- // Visit child nodes now or queue them for later?
3731
- const visitChildren = Math.random() < 0.5;
3732
- for (const child of _this2.nondeterministicChildren(node)) {
3733
- if (visitChildren) {
3734
- yield child;
3735
- const grandchildren = Array.from(_this2.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3736
- queue = interleave(queue, grandchildren);
3737
- } else {
3738
- queue.push([child, _depth + 1]);
3739
- }
3710
+ // Visit child nodes now or queue them for later?
3711
+ const visitChildren = Math.random() < 0.5;
3712
+ for (const child of this.nondeterministicChildren(node)) {
3713
+ if (visitChildren) {
3714
+ yield child;
3715
+ const grandchildren = Array.from(this.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3716
+ queue = interleave(queue, grandchildren);
3717
+ } else {
3718
+ queue.push([child, _depth + 1]);
3740
3719
  }
3741
3720
  }
3742
- }();
3721
+ }
3743
3722
  }
3744
3723
  *nondeterministicChildren(node) {
3745
3724
  if (isString(node.value)) return;
@@ -4005,8 +3984,7 @@ class Parser {
4005
3984
  }
4006
3985
  return segments;
4007
3986
  }
4008
- parseQuery(stream) {
4009
- let inFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3987
+ parseQuery(stream, inFilter = false) {
4010
3988
  const segments = [];
4011
3989
  loop: for (;;) {
4012
3990
  switch (stream.current.kind) {
@@ -4158,8 +4136,7 @@ class Parser {
4158
4136
  }
4159
4137
  return selectors;
4160
4138
  }
4161
- parseFilter(stream) {
4162
- let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
4139
+ parseFilter(stream, keys = false) {
4163
4140
  const tok = stream.next();
4164
4141
  const expr = this.parseFilterExpression(stream);
4165
4142
  if (expr instanceof FunctionExtension) {
@@ -4273,8 +4250,7 @@ class Parser {
4273
4250
  stream.expect(TokenKind.RPAREN);
4274
4251
  return new FunctionExtension(tok, tok.value, this.environment.checkWellTypedness(tok, args));
4275
4252
  }
4276
- parseFilterExpression(stream) {
4277
- let precedence = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PRECEDENCE_LOWEST;
4253
+ parseFilterExpression(stream, precedence = PRECEDENCE_LOWEST) {
4278
4254
  const func = this.tokenMap.get(stream.current.kind);
4279
4255
  if (!func) {
4280
4256
  let msg;
@@ -4344,7 +4320,6 @@ class Parser {
4344
4320
  rv.push(this.stringFromCodePoint(codepoint, token));
4345
4321
  break;
4346
4322
  default:
4347
- // TODO: This is unreachable. The lexer will catch unknown escape sequences.
4348
4323
  throw new JSONPathSyntaxError(`unknown escape sequence at index ${token.index + index - 1}`, token);
4349
4324
  }
4350
4325
  } else {
@@ -4524,12 +4499,11 @@ class JSONPathEnvironment {
4524
4499
  * A map of function names to objects implementing the {@link FilterFunction}
4525
4500
  * interface. You are free to set or delete custom filter functions directly.
4526
4501
  */
4527
- functionRegister = (() => new Map())();
4502
+ functionRegister = new Map();
4528
4503
  /**
4529
4504
  * @param options - Environment configuration options.
4530
4505
  */
4531
- constructor() {
4532
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4506
+ constructor(options = {}) {
4533
4507
  this.strict = options.strict ?? true;
4534
4508
  this.maxIntIndex = options.maxIntIndex ?? Math.pow(2, 53) - 1;
4535
4509
  this.minIntIndex = options.maxIntIndex ?? -Math.pow(2, 53) + 1;
@@ -4674,11 +4648,10 @@ class JSONPathEnvironment {
4674
4648
  * value and it contains a property matching the second argument.
4675
4649
  */
4676
4650
  class Has {
4677
- argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
4678
- returnType = (() => FunctionExpressionType.LogicalType)();
4651
+ argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
4652
+ returnType = FunctionExpressionType.LogicalType;
4679
4653
  #cache;
4680
- constructor() {
4681
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4654
+ constructor(options = {}) {
4682
4655
  this.options = options;
4683
4656
  this.cacheSize = options.cacheSize ?? 10;
4684
4657
  this.throwErrors = options.throwErrors ?? false;
@@ -5327,7 +5300,7 @@ var index = /*#__PURE__*/Object.freeze({
5327
5300
  apply: apply
5328
5301
  });
5329
5302
 
5330
- const version = "2.2.2";
5303
+ const version = "2.3.0";
5331
5304
 
5332
5305
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
5333
5306
  exports.FunctionExpressionType = FunctionExpressionType;