json-p3 1.3.4 → 2.0.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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * json-p3 version 1.3.4
2
+ * json-p3 version 2.0.0
3
3
  * https://github.com/jg-rp/json-p3
4
4
  *
5
5
  * MIT License
@@ -920,14 +920,14 @@ var json_p3 = (function (exports) {
920
920
  /**
921
921
  * Base class for relative and absolute JSONPath query expressions.
922
922
  */
923
- class JSONPathQuery extends FilterExpression {
923
+ class FilterQuery extends FilterExpression {
924
924
  constructor(token, path) {
925
925
  super(token);
926
926
  this.token = token;
927
927
  this.path = path;
928
928
  }
929
929
  }
930
- class RelativeQuery extends JSONPathQuery {
930
+ class RelativeQuery extends FilterQuery {
931
931
  evaluate(context) {
932
932
  return context.lazy ? new JSONPathNodeList(Array.from(this.path.lazyQuery(context.currentValue))) : this.path.query(context.currentValue);
933
933
  }
@@ -935,7 +935,7 @@ var json_p3 = (function (exports) {
935
935
  return `@${this.path.toString().slice(1)}`;
936
936
  }
937
937
  }
938
- class RootQuery extends JSONPathQuery {
938
+ class RootQuery extends FilterQuery {
939
939
  evaluate(context) {
940
940
  return context.lazy ? new JSONPathNodeList(Array.from(this.path.lazyQuery(context.rootValue))) : this.path.query(context.rootValue);
941
941
  }
@@ -1029,9 +1029,9 @@ var json_p3 = (function (exports) {
1029
1029
  BooleanLiteral: BooleanLiteral,
1030
1030
  FilterExpression: FilterExpression,
1031
1031
  FilterExpressionLiteral: FilterExpressionLiteral,
1032
+ FilterQuery: FilterQuery,
1032
1033
  FunctionExtension: FunctionExtension,
1033
1034
  InfixExpression: InfixExpression,
1034
- JSONPathQuery: JSONPathQuery,
1035
1035
  LogicalExpression: LogicalExpression,
1036
1036
  NullLiteral: NullLiteral,
1037
1037
  NumberLiteral: NumberLiteral,
@@ -1043,16 +1043,16 @@ var json_p3 = (function (exports) {
1043
1043
  });
1044
1044
 
1045
1045
  class Count {
1046
- argTypes = [FunctionExpressionType.NodesType];
1047
- returnType = FunctionExpressionType.ValueType;
1046
+ argTypes = (() => [FunctionExpressionType.NodesType])();
1047
+ returnType = (() => FunctionExpressionType.ValueType)();
1048
1048
  call(nodes) {
1049
1049
  return nodes.length;
1050
1050
  }
1051
1051
  }
1052
1052
 
1053
1053
  class Length {
1054
- argTypes = [FunctionExpressionType.ValueType];
1055
- returnType = FunctionExpressionType.ValueType;
1054
+ argTypes = (() => [FunctionExpressionType.ValueType])();
1055
+ returnType = (() => FunctionExpressionType.ValueType)();
1056
1056
  call(value) {
1057
1057
  if (isArray(value) || isString(value)) return value.length;
1058
1058
  if (isObject(value)) return Object.keys(value).length;
@@ -1086,7 +1086,10 @@ var json_p3 = (function (exports) {
1086
1086
  if (this.has(key)) {
1087
1087
  this.delete(key);
1088
1088
  } else if (this.size >= this.maxSize) {
1089
- this.delete(this.first());
1089
+ const first = this.first();
1090
+ if (first !== undefined) {
1091
+ this.delete(first);
1092
+ }
1090
1093
  }
1091
1094
  return super.set(key, value);
1092
1095
  }
@@ -2345,8 +2348,8 @@ var json_p3 = (function (exports) {
2345
2348
  var check$1 = check_1.check;
2346
2349
 
2347
2350
  class Match {
2348
- argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2349
- returnType = FunctionExpressionType.LogicalType;
2351
+ argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2352
+ returnType = (() => FunctionExpressionType.LogicalType)();
2350
2353
  #cache;
2351
2354
  constructor() {
2352
2355
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2403,8 +2406,8 @@ var json_p3 = (function (exports) {
2403
2406
  }
2404
2407
 
2405
2408
  class Search {
2406
- argTypes = [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType];
2407
- returnType = FunctionExpressionType.LogicalType;
2409
+ argTypes = (() => [FunctionExpressionType.ValueType, FunctionExpressionType.ValueType])();
2410
+ returnType = (() => FunctionExpressionType.LogicalType)();
2408
2411
  #cache;
2409
2412
  constructor() {
2410
2413
  let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -2452,8 +2455,8 @@ var json_p3 = (function (exports) {
2452
2455
  }
2453
2456
 
2454
2457
  class Value {
2455
- argTypes = [FunctionExpressionType.NodesType];
2456
- returnType = FunctionExpressionType.ValueType;
2458
+ argTypes = (() => [FunctionExpressionType.NodesType])();
2459
+ returnType = (() => FunctionExpressionType.ValueType)();
2457
2460
  call(nodes) {
2458
2461
  if (nodes.length === 1) return nodes.nodes[0].value;
2459
2462
  return Nothing;
@@ -3129,11 +3132,11 @@ var json_p3 = (function (exports) {
3129
3132
  }
3130
3133
 
3131
3134
  /**
3132
- * @param nodes - Nodes matched by preceding selectors.
3135
+ * @param node - Nodes matched by preceding selectors.
3133
3136
  */
3134
3137
 
3135
3138
  /**
3136
- * @param nodes - Nodes matched by preceding selectors.
3139
+ * @param node - Nodes matched by preceding selectors.
3137
3140
  */
3138
3141
 
3139
3142
  /**
@@ -3145,31 +3148,26 @@ var json_p3 = (function (exports) {
3145
3148
  * Shorthand and quoted name selector.
3146
3149
  */
3147
3150
  class NameSelector extends JSONPathSelector {
3148
- constructor(environment, token, name, shorthand) {
3151
+ constructor(environment, token, name) {
3149
3152
  super(environment, token);
3150
3153
  this.environment = environment;
3151
3154
  this.token = token;
3152
3155
  this.name = name;
3153
- this.shorthand = shorthand;
3154
3156
  }
3155
- resolve(nodes) {
3157
+ resolve(node) {
3156
3158
  const rv = [];
3157
- for (const node of nodes) {
3158
- if (!isArray(node.value) && hasStringKey(node.value, this.name)) {
3159
- rv.push(new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root));
3160
- }
3159
+ if (!isArray(node.value) && hasStringKey(node.value, this.name)) {
3160
+ rv.push(new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root));
3161
3161
  }
3162
3162
  return rv;
3163
3163
  }
3164
- *lazyResolve(nodes) {
3165
- for (const node of nodes) {
3166
- if (!isArray(node.value) && hasStringKey(node.value, this.name)) {
3167
- yield new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root);
3168
- }
3164
+ *lazyResolve(node) {
3165
+ if (!isArray(node.value) && hasStringKey(node.value, this.name)) {
3166
+ yield new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root);
3169
3167
  }
3170
3168
  }
3171
3169
  toString() {
3172
- return this.shorthand ? `['${this.name}']` : `'${this.name}'`;
3170
+ return `'${this.name}'`;
3173
3171
  }
3174
3172
  }
3175
3173
 
@@ -3186,25 +3184,21 @@ var json_p3 = (function (exports) {
3186
3184
  throw new JSONPathIndexError("index out of range", this.token);
3187
3185
  }
3188
3186
  }
3189
- resolve(nodes) {
3187
+ resolve(node) {
3190
3188
  const rv = [];
3191
- for (const node of nodes) {
3192
- if (isArray(node.value)) {
3193
- const normIndex = this.normalizedIndex(node.value.length);
3194
- if (normIndex in node.value) {
3195
- rv.push(new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root));
3196
- }
3189
+ if (isArray(node.value)) {
3190
+ const normIndex = this.normalizedIndex(node.value.length);
3191
+ if (normIndex in node.value) {
3192
+ rv.push(new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root));
3197
3193
  }
3198
3194
  }
3199
3195
  return rv;
3200
3196
  }
3201
- *lazyResolve(nodes) {
3202
- for (const node of nodes) {
3203
- if (isArray(node.value)) {
3204
- const normIndex = this.normalizedIndex(node.value.length);
3205
- if (normIndex in node.value) {
3206
- yield new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root);
3207
- }
3197
+ *lazyResolve(node) {
3198
+ if (isArray(node.value)) {
3199
+ const normIndex = this.normalizedIndex(node.value.length);
3200
+ if (normIndex in node.value) {
3201
+ yield new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root);
3208
3202
  }
3209
3203
  }
3210
3204
  }
@@ -3226,19 +3220,16 @@ var json_p3 = (function (exports) {
3226
3220
  this.step = step;
3227
3221
  this.checkRange(start, stop, step);
3228
3222
  }
3229
- resolve(nodes) {
3223
+ resolve(node) {
3230
3224
  const rv = [];
3231
- for (const node of nodes) {
3232
- if (!isArray(node.value)) continue;
3233
- for (const [i, value] of this.slice(node.value, this.start, this.stop, this.step)) {
3234
- rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
3235
- }
3225
+ if (!isArray(node.value)) return rv;
3226
+ for (const [i, value] of this.slice(node.value, this.start, this.stop, this.step)) {
3227
+ rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
3236
3228
  }
3237
3229
  return rv;
3238
3230
  }
3239
- *lazyResolve(nodes) {
3240
- for (const node of nodes) {
3241
- if (!isArray(node.value)) continue;
3231
+ *lazyResolve(node) {
3232
+ if (isArray(node.value)) {
3242
3233
  for (const [i, value] of this.lazySlice(node.value, this.start, this.stop, this.step)) {
3243
3234
  yield new JSONPathNode(value, node.location.concat(i), node.root);
3244
3235
  }
@@ -3344,281 +3335,175 @@ var json_p3 = (function (exports) {
3344
3335
  }
3345
3336
  class WildcardSelector extends JSONPathSelector {
3346
3337
  constructor(environment, token) {
3347
- let shorthand = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3348
3338
  super(environment, token);
3349
3339
  this.environment = environment;
3350
3340
  this.token = token;
3351
- this.shorthand = shorthand;
3352
3341
  }
3353
- resolve(nodes) {
3342
+ resolve(node) {
3354
3343
  const rv = [];
3355
- for (const node of nodes) {
3356
- if (node.value instanceof String) continue;
3357
- if (isArray(node.value)) {
3358
- for (let i = 0; i < node.value.length; i++) {
3359
- rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
3360
- }
3361
- } else if (isObject(node.value)) {
3362
- for (const [key, value] of this.environment.entries(node.value)) {
3363
- rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
3364
- }
3344
+ if (node.value instanceof String) return rv;
3345
+ if (isArray(node.value)) {
3346
+ for (let i = 0; i < node.value.length; i++) {
3347
+ rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
3348
+ }
3349
+ } else if (isObject(node.value)) {
3350
+ for (const [key, value] of this.environment.entries(node.value)) {
3351
+ rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
3365
3352
  }
3366
3353
  }
3367
3354
  return rv;
3368
3355
  }
3369
- *lazyResolve(nodes) {
3370
- for (const node of nodes) {
3371
- if (node.value instanceof String) continue;
3372
- if (isArray(node.value)) {
3373
- for (let i = 0; i < node.value.length; i++) {
3374
- yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3375
- }
3376
- } else if (isObject(node.value)) {
3377
- for (const [key, value] of this.environment.entries(node.value)) {
3378
- yield new JSONPathNode(value, node.location.concat(key), node.root);
3379
- }
3356
+ *lazyResolve(node) {
3357
+ if (isArray(node.value)) {
3358
+ for (let i = 0; i < node.value.length; i++) {
3359
+ yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3360
+ }
3361
+ } else if (isObject(node.value) && !isString(node.value)) {
3362
+ for (const [key, value] of this.environment.entries(node.value)) {
3363
+ yield new JSONPathNode(value, node.location.concat(key), node.root);
3380
3364
  }
3381
3365
  }
3382
3366
  }
3383
3367
  toString() {
3384
- return this.shorthand ? "[*]" : "*";
3368
+ return "*";
3385
3369
  }
3386
3370
  }
3387
- class RecursiveDescentSegment extends JSONPathSelector {
3388
- constructor(environment, token, selector) {
3371
+ class FilterSelector extends JSONPathSelector {
3372
+ constructor(environment, token, expression) {
3389
3373
  super(environment, token);
3390
3374
  this.environment = environment;
3391
3375
  this.token = token;
3392
- this.selector = selector;
3393
- }
3394
- resolve(nodes) {
3395
- const rv = [];
3396
- if (this.environment.nondeterministic) {
3397
- for (const root of nodes) {
3398
- for (const node of this.nondeterministicVisitor(root)) {
3399
- rv.push(node);
3400
- }
3401
- }
3402
- } else {
3403
- for (const node of nodes) {
3404
- rv.push(node);
3405
- for (const _node of this.visitor(node)) {
3406
- rv.push(_node);
3407
- }
3408
- }
3409
- }
3410
- return this.selector.resolve(rv);
3411
- }
3412
- *lazyResolve(nodes) {
3413
- yield* this.selector.lazyResolve(this._lazyResolve(nodes));
3414
- }
3415
-
3416
- // eslint-disable-next-line sonarjs/cognitive-complexity
3417
- *_lazyResolve(nodes) {
3418
- for (const _node of nodes) {
3419
- const stack = [{
3420
- node: _node,
3421
- depth: 0
3422
- }];
3423
- yield _node;
3424
- while (stack.length) {
3425
- const {
3426
- node: currentNode,
3427
- depth
3428
- } = stack.pop();
3429
- if (depth >= this.environment.maxRecursionDepth) {
3430
- throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3431
- }
3432
- if (currentNode.value instanceof String) continue;
3433
- if (isArray(currentNode.value)) {
3434
- for (let i = 0; i < currentNode.value.length; i++) {
3435
- const __node = new JSONPathNode(currentNode.value[i], currentNode.location.concat(i), currentNode.root);
3436
- yield __node;
3437
- if (isObject(__node.value)) {
3438
- stack.push({
3439
- node: __node,
3440
- depth: depth + 1
3441
- });
3442
- }
3443
- }
3444
- } else if (isObject(currentNode.value)) {
3445
- for (const [key, value] of this.environment.entries(currentNode.value)) {
3446
- const __node = new JSONPathNode(value, currentNode.location.concat(key), currentNode.root);
3447
- yield __node;
3448
- if (isObject(__node.value)) {
3449
- stack.push({
3450
- node: __node,
3451
- depth: depth + 1
3452
- });
3453
- }
3454
- }
3455
- }
3456
- }
3457
- }
3458
- }
3459
- toString() {
3460
- return `..${this.selector.toString()}`;
3376
+ this.expression = expression;
3461
3377
  }
3462
- visitor(node) {
3463
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3464
- if (depth >= this.environment.maxRecursionDepth) {
3465
- throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3466
- }
3378
+ resolve(node) {
3467
3379
  const rv = [];
3468
3380
  if (node.value instanceof String) return rv;
3469
3381
  if (isArray(node.value)) {
3470
3382
  for (let i = 0; i < node.value.length; i++) {
3471
- const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3472
- rv.push(_node);
3473
- for (const __node of this.visitor(_node, depth + 1)) {
3474
- rv.push(__node);
3383
+ const value = node.value[i];
3384
+ const filterContext = {
3385
+ environment: this.environment,
3386
+ currentValue: value,
3387
+ rootValue: node.root,
3388
+ currentKey: i
3389
+ };
3390
+ if (this.expression.evaluate(filterContext)) {
3391
+ rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
3475
3392
  }
3476
3393
  }
3477
3394
  } else if (isObject(node.value)) {
3478
3395
  for (const [key, value] of this.environment.entries(node.value)) {
3479
- const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3480
- rv.push(_node);
3481
- for (const __node of this.visitor(_node, depth + 1)) {
3482
- rv.push(__node);
3483
- }
3484
- }
3485
- }
3486
- return rv;
3487
- }
3488
- nondeterministicVisitor(root) {
3489
- let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3490
- const rv = [root];
3491
- let queue = this.nondeterministicChildren(root).map(node => [node, depth]);
3492
- while (queue.length) {
3493
- const [node, _depth] = queue.shift();
3494
- rv.push(node);
3495
- if (_depth >= this.environment.maxRecursionDepth) {
3496
- throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
3497
- }
3498
-
3499
- // Visit child nodes now or queue them for later?
3500
- const visitChildren = Math.random() < 0.5;
3501
- for (const child of this.nondeterministicChildren(node)) {
3502
- if (visitChildren) {
3503
- rv.push(child);
3504
- const grandchildren = this.nondeterministicChildren(child).map(n => [n, _depth + 2]);
3505
- queue = interleave(queue, grandchildren);
3506
- } else {
3507
- queue.push([child, _depth + 1]);
3396
+ const filterContext = {
3397
+ environment: this.environment,
3398
+ currentValue: value,
3399
+ rootValue: node.root,
3400
+ currentKey: key
3401
+ };
3402
+ if (this.expression.evaluate(filterContext)) {
3403
+ rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
3508
3404
  }
3509
3405
  }
3510
3406
  }
3511
3407
  return rv;
3512
3408
  }
3513
- nondeterministicChildren(node) {
3514
- const _rv = [];
3515
- if (node.value instanceof String) return _rv;
3409
+ *lazyResolve(node) {
3516
3410
  if (isArray(node.value)) {
3517
3411
  for (let i = 0; i < node.value.length; i++) {
3518
- _rv.push(new JSONPathNode(node.value[i], node.location.concat(i), node.root));
3412
+ const value = node.value[i];
3413
+ const filterContext = {
3414
+ environment: this.environment,
3415
+ currentValue: value,
3416
+ rootValue: node.root,
3417
+ lazy: true,
3418
+ currentKey: i
3419
+ };
3420
+ if (this.expression.evaluate(filterContext)) {
3421
+ yield new JSONPathNode(value, node.location.concat(i), node.root);
3422
+ }
3519
3423
  }
3520
- } else if (isObject(node.value)) {
3424
+ } else if (isObject(node.value) && !isString(node.value)) {
3521
3425
  for (const [key, value] of this.environment.entries(node.value)) {
3522
- _rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
3426
+ const filterContext = {
3427
+ environment: this.environment,
3428
+ currentValue: value,
3429
+ rootValue: node.root,
3430
+ lazy: true,
3431
+ currentKey: key
3432
+ };
3433
+ if (this.expression.evaluate(filterContext)) {
3434
+ yield new JSONPathNode(value, node.location.concat(key), node.root);
3435
+ }
3523
3436
  }
3524
3437
  }
3525
- return _rv;
3438
+ }
3439
+ toString() {
3440
+ return `?${this.expression.toString()}`;
3526
3441
  }
3527
3442
  }
3528
- class FilterSelector extends JSONPathSelector {
3529
- constructor(environment, token, expression) {
3530
- super(environment, token);
3443
+
3444
+ var selectors = /*#__PURE__*/Object.freeze({
3445
+ __proto__: null,
3446
+ FilterSelector: FilterSelector,
3447
+ IndexSelector: IndexSelector,
3448
+ JSONPathSelector: JSONPathSelector,
3449
+ NameSelector: NameSelector,
3450
+ SliceSelector: SliceSelector,
3451
+ WildcardSelector: WildcardSelector
3452
+ });
3453
+
3454
+ /** Base class for all JSONPath segments. Both shorthand and bracketed. */
3455
+ class JSONPathSegment {
3456
+ constructor(environment, token, selectors) {
3531
3457
  this.environment = environment;
3532
3458
  this.token = token;
3533
- this.expression = expression;
3459
+ this.selectors = selectors;
3534
3460
  }
3535
3461
 
3536
- // eslint-disable-next-line sonarjs/cognitive-complexity
3462
+ /**
3463
+ * @param nodes - Nodes matched by preceding segments.
3464
+ */
3465
+
3466
+ /**
3467
+ * @param nodes - Nodes matched by preceding segments.
3468
+ */
3469
+
3470
+ /**
3471
+ * Return a canonical string representation of this segment.
3472
+ */
3473
+ }
3474
+
3475
+ /** The child selection segment. */
3476
+ class ChildSegment extends JSONPathSegment {
3537
3477
  resolve(nodes) {
3538
3478
  const rv = [];
3539
3479
  for (const node of nodes) {
3540
- if (node.value instanceof String) continue;
3541
- if (isArray(node.value)) {
3542
- for (let i = 0; i < node.value.length; i++) {
3543
- const value = node.value[i];
3544
- const filterContext = {
3545
- environment: this.environment,
3546
- currentValue: value,
3547
- rootValue: node.root,
3548
- currentKey: i
3549
- };
3550
- if (this.expression.evaluate(filterContext)) {
3551
- rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
3552
- }
3553
- }
3554
- } else if (isObject(node.value)) {
3555
- for (const [key, value] of this.environment.entries(node.value)) {
3556
- const filterContext = {
3557
- environment: this.environment,
3558
- currentValue: value,
3559
- rootValue: node.root,
3560
- currentKey: key
3561
- };
3562
- if (this.expression.evaluate(filterContext)) {
3563
- rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
3564
- }
3565
- }
3480
+ for (const selector of this.selectors) {
3481
+ rv.push(...selector.resolve(node));
3566
3482
  }
3567
3483
  }
3568
3484
  return rv;
3569
3485
  }
3570
-
3571
- // eslint-disable-next-line sonarjs/cognitive-complexity
3572
3486
  *lazyResolve(nodes) {
3573
3487
  for (const node of nodes) {
3574
- if (node.value instanceof String) continue;
3575
- if (isArray(node.value)) {
3576
- for (let i = 0; i < node.value.length; i++) {
3577
- const value = node.value[i];
3578
- const filterContext = {
3579
- environment: this.environment,
3580
- currentValue: value,
3581
- rootValue: node.root,
3582
- lazy: true,
3583
- currentKey: i
3584
- };
3585
- if (this.expression.evaluate(filterContext)) {
3586
- yield new JSONPathNode(value, node.location.concat(i), node.root);
3587
- }
3588
- }
3589
- } else if (isObject(node.value)) {
3590
- for (const [key, value] of this.environment.entries(node.value)) {
3591
- const filterContext = {
3592
- environment: this.environment,
3593
- currentValue: value,
3594
- rootValue: node.root,
3595
- lazy: true,
3596
- currentKey: key
3597
- };
3598
- if (this.expression.evaluate(filterContext)) {
3599
- yield new JSONPathNode(value, node.location.concat(key), node.root);
3600
- }
3601
- }
3488
+ for (const selector of this.selectors) {
3489
+ yield* selector.resolve(node);
3602
3490
  }
3603
3491
  }
3604
3492
  }
3605
3493
  toString() {
3606
- return `?${this.expression.toString()}`;
3494
+ return `[${this.selectors.map(s => s.toString()).join(", ")}]`;
3607
3495
  }
3608
3496
  }
3609
- class BracketedSelection extends JSONPathSelector {
3610
- constructor(environment, token, items) {
3611
- super(environment, token);
3612
- this.environment = environment;
3613
- this.token = token;
3614
- this.items = items;
3615
- }
3497
+
3498
+ /** The recursive descent segment. */
3499
+ class DescendantSegment extends JSONPathSegment {
3616
3500
  resolve(nodes) {
3617
3501
  const rv = [];
3502
+ const visitor = (this.environment.nondeterministic ? this.nondeterministicVisit : this.visit).bind(this);
3618
3503
  for (const node of nodes) {
3619
- for (const item of this.items) {
3620
- for (const _node of item.resolve([node])) {
3621
- rv.push(_node);
3504
+ for (const _node of visitor(node)) {
3505
+ for (const selector of this.selectors) {
3506
+ rv.push(...selector.resolve(_node));
3622
3507
  }
3623
3508
  }
3624
3509
  }
@@ -3626,13 +3511,75 @@ var json_p3 = (function (exports) {
3626
3511
  }
3627
3512
  *lazyResolve(nodes) {
3628
3513
  for (const node of nodes) {
3629
- for (const item of this.items) {
3630
- yield* item.lazyResolve([node]);
3514
+ for (const _node of this.visit(node)) {
3515
+ for (const selector of this.selectors) {
3516
+ yield* selector.resolve(_node);
3517
+ }
3631
3518
  }
3632
3519
  }
3633
3520
  }
3634
3521
  toString() {
3635
- return `[${this.items.map(itm => itm.toString()).join(", ")}]`;
3522
+ return `..[${this.selectors.map(s => s.toString()).join(", ")}]`;
3523
+ }
3524
+ visit(node) {
3525
+ var _this = this;
3526
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3527
+ return function* () {
3528
+ if (depth >= _this.environment.maxRecursionDepth) {
3529
+ throw new JSONPathRecursionLimitError("recursion limit reached", _this.token);
3530
+ }
3531
+ yield node;
3532
+ if (isArray(node.value)) {
3533
+ for (let i = 0; i < node.value.length; i++) {
3534
+ const _node = new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3535
+ yield* _this.visit(_node, depth + 1);
3536
+ }
3537
+ } else if (isObject(node.value)) {
3538
+ for (const [key, value] of _this.environment.entries(node.value)) {
3539
+ const _node = new JSONPathNode(value, node.location.concat(key), node.root);
3540
+ yield* _this.visit(_node, depth + 1);
3541
+ }
3542
+ }
3543
+ }();
3544
+ }
3545
+ nondeterministicVisit(root) {
3546
+ var _this2 = this;
3547
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
3548
+ return function* () {
3549
+ let queue = Array.from(_this2.nondeterministicChildren(root)).map(node => [node, depth]);
3550
+ yield root;
3551
+ while (queue.length) {
3552
+ const [node, _depth] = queue.shift();
3553
+ yield node;
3554
+ if (_depth >= _this2.environment.maxRecursionDepth) {
3555
+ throw new JSONPathRecursionLimitError("recursion limit reached", _this2.token);
3556
+ }
3557
+
3558
+ // Visit child nodes now or queue them for later?
3559
+ const visitChildren = Math.random() < 0.5;
3560
+ for (const child of _this2.nondeterministicChildren(node)) {
3561
+ if (visitChildren) {
3562
+ yield child;
3563
+ const grandchildren = Array.from(_this2.nondeterministicChildren(child)).map(n => [n, _depth + 2]);
3564
+ queue = interleave(queue, grandchildren);
3565
+ } else {
3566
+ queue.push([child, _depth + 1]);
3567
+ }
3568
+ }
3569
+ }
3570
+ }();
3571
+ }
3572
+ *nondeterministicChildren(node) {
3573
+ if (isString(node.value)) return;
3574
+ if (isArray(node.value)) {
3575
+ for (let i = 0; i < node.value.length; i++) {
3576
+ yield new JSONPathNode(node.value[i], node.location.concat(i), node.root);
3577
+ }
3578
+ } else if (isObject(node.value)) {
3579
+ for (const [key, value] of this.environment.entries(node.value)) {
3580
+ yield new JSONPathNode(value, node.location.concat(key), node.root);
3581
+ }
3582
+ }
3636
3583
  }
3637
3584
  }
3638
3585
 
@@ -3671,30 +3618,18 @@ var json_p3 = (function (exports) {
3671
3618
  return entries;
3672
3619
  }
3673
3620
 
3674
- var selectors = /*#__PURE__*/Object.freeze({
3675
- __proto__: null,
3676
- BracketedSelection: BracketedSelection,
3677
- FilterSelector: FilterSelector,
3678
- IndexSelector: IndexSelector,
3679
- JSONPathSelector: JSONPathSelector,
3680
- NameSelector: NameSelector,
3681
- RecursiveDescentSegment: RecursiveDescentSegment,
3682
- SliceSelector: SliceSelector,
3683
- WildcardSelector: WildcardSelector
3684
- });
3685
-
3686
3621
  /**
3687
3622
  *
3688
3623
  */
3689
- class JSONPath {
3624
+ class JSONPathQuery {
3690
3625
  /**
3691
3626
  *
3692
3627
  * @param environment -
3693
- * @param selectors -
3628
+ * @param segments -
3694
3629
  */
3695
- constructor(environment, selectors) {
3630
+ constructor(environment, segments) {
3696
3631
  this.environment = environment;
3697
- this.selectors = selectors;
3632
+ this.segments = segments;
3698
3633
  }
3699
3634
 
3700
3635
  /**
@@ -3704,8 +3639,8 @@ var json_p3 = (function (exports) {
3704
3639
  */
3705
3640
  query(value) {
3706
3641
  let nodes = [new JSONPathNode(value, [], value)];
3707
- for (const selector of this.selectors) {
3708
- nodes = selector.resolve(nodes);
3642
+ for (const segment of this.segments) {
3643
+ nodes = segment.resolve(nodes);
3709
3644
  }
3710
3645
  return new JSONPathNodeList(nodes);
3711
3646
  }
@@ -3717,8 +3652,8 @@ var json_p3 = (function (exports) {
3717
3652
  */
3718
3653
  lazyQuery(value) {
3719
3654
  let nodes = [new JSONPathNode(value, [], value)][Symbol.iterator]();
3720
- for (const selector of this.selectors) {
3721
- nodes = selector.lazyResolve(nodes);
3655
+ for (const segment of this.segments) {
3656
+ nodes = segment.lazyResolve(nodes);
3722
3657
  }
3723
3658
  return nodes;
3724
3659
  }
@@ -3742,12 +3677,14 @@ var json_p3 = (function (exports) {
3742
3677
  *
3743
3678
  */
3744
3679
  toString() {
3745
- return `$${this.selectors.map(s => s.toString()).join("")}`;
3680
+ return `$${this.segments.map(s => s.toString()).join("")}`;
3746
3681
  }
3747
3682
  singularQuery() {
3748
- for (const selector of this.selectors) {
3749
- if (selector instanceof NameSelector) continue;
3750
- if (selector instanceof BracketedSelection && selector.items.length === 1 && (selector.items[0] instanceof NameSelector || selector.items[0] instanceof IndexSelector)) continue;
3683
+ for (const segment of this.segments) {
3684
+ if (segment instanceof DescendantSegment) return false;
3685
+ if (segment.selectors.length === 1 && (segment.selectors[0] instanceof NameSelector || segment.selectors[0] instanceof IndexSelector)) {
3686
+ continue;
3687
+ }
3751
3688
  return false;
3752
3689
  }
3753
3690
  return true;
@@ -3765,33 +3702,26 @@ var json_p3 = (function (exports) {
3765
3702
 
3766
3703
  class KeySelector extends JSONPathSelector {
3767
3704
  constructor(environment, token, key) {
3768
- let shorthand = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
3769
3705
  super(environment, token);
3770
3706
  this.environment = environment;
3771
3707
  this.token = token;
3772
3708
  this.key = key;
3773
- this.shorthand = shorthand;
3774
3709
  }
3775
- resolve(nodes) {
3710
+ resolve(node) {
3776
3711
  const rv = [];
3777
- for (const node of nodes) {
3778
- if (node.value instanceof String || isArray(node.value)) continue;
3779
- if (isObject(node.value) && hasStringKey(node.value, this.key)) {
3780
- rv.push(new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root));
3781
- }
3712
+ if (node.value instanceof String || isArray(node.value)) return rv;
3713
+ if (isObject(node.value) && hasStringKey(node.value, this.key)) {
3714
+ rv.push(new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root));
3782
3715
  }
3783
3716
  return rv;
3784
3717
  }
3785
- *lazyResolve(nodes) {
3786
- for (const node of nodes) {
3787
- if (node.value instanceof String || isArray(node.value)) continue;
3788
- if (isObject(node.value) && hasStringKey(node.value, this.key)) {
3789
- yield new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root);
3790
- }
3718
+ *lazyResolve(node) {
3719
+ if (!isString(node.value) && isObject(node.value) && hasStringKey(node.value, this.key)) {
3720
+ yield new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root);
3791
3721
  }
3792
3722
  }
3793
3723
  toString() {
3794
- return this.shorthand ? `[~'${this.key.replaceAll("'", "\\'")}']` : `~'${this.key.replaceAll("'", "\\'")}'`;
3724
+ return `~'${this.key.replaceAll("'", "\\'")}'`;
3795
3725
  }
3796
3726
  }
3797
3727
 
@@ -3800,36 +3730,29 @@ var json_p3 = (function (exports) {
3800
3730
  */
3801
3731
  class KeysSelector extends JSONPathSelector {
3802
3732
  constructor(environment, token) {
3803
- let shorthand = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3804
3733
  super(environment, token);
3805
3734
  this.environment = environment;
3806
3735
  this.token = token;
3807
- this.shorthand = shorthand;
3808
3736
  }
3809
- resolve(nodes) {
3737
+ resolve(node) {
3810
3738
  const rv = [];
3811
- for (const node of nodes) {
3812
- if (node.value instanceof String || isArray(node.value)) continue;
3813
- if (isObject(node.value)) {
3814
- for (const [key, _] of this.environment.entries(node.value)) {
3815
- rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
3816
- }
3739
+ if (node.value instanceof String || isArray(node.value)) return rv;
3740
+ if (isObject(node.value)) {
3741
+ for (const [key, _] of this.environment.entries(node.value)) {
3742
+ rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
3817
3743
  }
3818
3744
  }
3819
3745
  return rv;
3820
3746
  }
3821
- *lazyResolve(nodes) {
3822
- for (const node of nodes) {
3823
- if (node.value instanceof String || isArray(node.value)) continue;
3824
- if (isObject(node.value)) {
3825
- for (const [key, _] of this.environment.entries(node.value)) {
3826
- yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
3827
- }
3747
+ *lazyResolve(node) {
3748
+ if (isObject(node.value) && !isString(node.value) && !isArray(node.value)) {
3749
+ for (const [key, _] of this.environment.entries(node.value)) {
3750
+ yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
3828
3751
  }
3829
3752
  }
3830
3753
  }
3831
3754
  toString() {
3832
- return this.shorthand ? "[~]" : "~";
3755
+ return "~";
3833
3756
  }
3834
3757
  }
3835
3758
  class KeysFilterSelector extends JSONPathSelector {
@@ -3839,41 +3762,37 @@ var json_p3 = (function (exports) {
3839
3762
  this.token = token;
3840
3763
  this.expression = expression;
3841
3764
  }
3842
- resolve(nodes) {
3765
+ resolve(node) {
3843
3766
  const rv = [];
3844
- for (const node of nodes) {
3845
- if (node.value instanceof String || isArray(node.value)) continue;
3846
- if (isObject(node.value)) {
3847
- for (const [key, value] of this.environment.entries(node.value)) {
3848
- const filterContext = {
3849
- environment: this.environment,
3850
- currentValue: value,
3851
- rootValue: node.root,
3852
- currentKey: key
3853
- };
3854
- if (this.expression.evaluate(filterContext)) {
3855
- rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
3856
- }
3767
+ if (node.value instanceof String || isArray(node.value)) return rv;
3768
+ if (isObject(node.value)) {
3769
+ for (const [key, value] of this.environment.entries(node.value)) {
3770
+ const filterContext = {
3771
+ environment: this.environment,
3772
+ currentValue: value,
3773
+ rootValue: node.root,
3774
+ currentKey: key
3775
+ };
3776
+ if (this.expression.evaluate(filterContext)) {
3777
+ rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
3857
3778
  }
3858
3779
  }
3859
3780
  }
3860
3781
  return rv;
3861
3782
  }
3862
- *lazyResolve(nodes) {
3863
- for (const node of nodes) {
3864
- if (node.value instanceof String || isArray(node.value)) continue;
3865
- if (isObject(node.value)) {
3866
- for (const [key, value] of this.environment.entries(node.value)) {
3867
- const filterContext = {
3868
- environment: this.environment,
3869
- currentValue: value,
3870
- rootValue: node.root,
3871
- lazy: true,
3872
- currentKey: key
3873
- };
3874
- if (this.expression.evaluate(filterContext)) {
3875
- yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
3876
- }
3783
+ *lazyResolve(node) {
3784
+ if (node.value instanceof String || isArray(node.value)) return;
3785
+ if (isObject(node.value)) {
3786
+ for (const [key, value] of this.environment.entries(node.value)) {
3787
+ const filterContext = {
3788
+ environment: this.environment,
3789
+ currentValue: value,
3790
+ rootValue: node.root,
3791
+ lazy: true,
3792
+ currentKey: key
3793
+ };
3794
+ if (this.expression.evaluate(filterContext)) {
3795
+ yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
3877
3796
  }
3878
3797
  }
3879
3798
  }
@@ -3902,52 +3821,59 @@ var json_p3 = (function (exports) {
3902
3821
  }
3903
3822
  parse(stream) {
3904
3823
  if (stream.current.kind === TokenKind.ROOT) stream.next();
3905
- const selectors = this.parsePath(stream);
3824
+ const segments = this.parseQuery(stream);
3906
3825
  if (stream.current.kind !== TokenKind.EOF) {
3907
3826
  throw new JSONPathSyntaxError(`unexpected token '${stream.current.kind}'`, stream.current);
3908
3827
  }
3909
- return selectors;
3828
+ return segments;
3910
3829
  }
3911
- parsePath(stream) {
3830
+ parseQuery(stream) {
3912
3831
  let inFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3913
- const selectors = [];
3914
- for (;;) {
3915
- const selector = this.parseSegment(stream);
3916
- if (!selector) {
3917
- if (inFilter) {
3918
- stream.backup();
3919
- }
3920
- break;
3832
+ const segments = [];
3833
+ loop: for (;;) {
3834
+ switch (stream.current.kind) {
3835
+ case TokenKind.DDOT:
3836
+ {
3837
+ const token = stream.next();
3838
+ const selectors = this.parseSelectors(stream);
3839
+ segments.push(new DescendantSegment(this.environment, token, selectors));
3840
+ break;
3841
+ }
3842
+ case TokenKind.LBRACKET:
3843
+ case TokenKind.KEY:
3844
+ case TokenKind.KEYS:
3845
+ case TokenKind.NAME:
3846
+ case TokenKind.WILD:
3847
+ {
3848
+ const token = stream.current;
3849
+ const selectors = this.parseSelectors(stream);
3850
+ segments.push(new ChildSegment(this.environment, token, selectors));
3851
+ break;
3852
+ }
3853
+ default:
3854
+ {
3855
+ if (inFilter) stream.backup();
3856
+ break loop;
3857
+ }
3921
3858
  }
3922
- selectors.push(selector);
3923
3859
  stream.next();
3924
3860
  }
3925
- return selectors;
3861
+ return segments;
3926
3862
  }
3927
- parseSegment(stream) {
3863
+ parseSelectors(stream) {
3928
3864
  switch (stream.current.kind) {
3929
3865
  case TokenKind.NAME:
3930
- return new NameSelector(this.environment, stream.current, stream.current.value, true);
3866
+ return [new NameSelector(this.environment, stream.current, stream.current.value)];
3931
3867
  case TokenKind.WILD:
3932
- return new WildcardSelector(this.environment, stream.current, true);
3868
+ return [new WildcardSelector(this.environment, stream.current)];
3933
3869
  case TokenKind.KEY:
3934
- return new KeySelector(this.environment, stream.current, stream.current.value, true);
3870
+ return [new KeySelector(this.environment, stream.current, stream.current.value)];
3935
3871
  case TokenKind.KEYS:
3936
- return new KeysSelector(this.environment, stream.current, true);
3937
- case TokenKind.DDOT:
3938
- {
3939
- const segmentToken = stream.current;
3940
- stream.next();
3941
- const selector = this.parseSegment(stream);
3942
- if (!selector) {
3943
- throw new JSONPathSyntaxError("bald descendant segment", stream.current);
3944
- }
3945
- return new RecursiveDescentSegment(this.environment, segmentToken, selector);
3946
- }
3872
+ return [new KeysSelector(this.environment, stream.current)];
3947
3873
  case TokenKind.LBRACKET:
3948
3874
  return this.parseBracketedSelection(stream);
3949
3875
  default:
3950
- return null;
3876
+ return [];
3951
3877
  }
3952
3878
  }
3953
3879
  parseIndex(stream) {
@@ -4004,38 +3930,38 @@ var json_p3 = (function (exports) {
4004
3930
  }
4005
3931
  parseBracketedSelection(stream) {
4006
3932
  const token = stream.next();
4007
- const items = [];
3933
+ const selectors = [];
4008
3934
  while (stream.current.kind !== TokenKind.RBRACKET) {
4009
3935
  switch (stream.current.kind) {
4010
3936
  case TokenKind.SINGLE_QUOTE_STRING:
4011
3937
  case TokenKind.DOUBLE_QUOTE_STRING:
4012
- items.push(new NameSelector(this.environment, stream.current, this.decodeString(stream.current), false));
3938
+ selectors.push(new NameSelector(this.environment, stream.current, this.decodeString(stream.current)));
4013
3939
  break;
4014
3940
  case TokenKind.FILTER:
4015
- items.push(this.parseFilter(stream));
3941
+ selectors.push(this.parseFilter(stream));
4016
3942
  break;
4017
3943
  case TokenKind.INDEX:
4018
3944
  if (stream.peek.kind === TokenKind.COLON) {
4019
- items.push(this.parseSlice(stream));
3945
+ selectors.push(this.parseSlice(stream));
4020
3946
  } else {
4021
- items.push(this.parseIndex(stream));
3947
+ selectors.push(this.parseIndex(stream));
4022
3948
  }
4023
3949
  break;
4024
3950
  case TokenKind.COLON:
4025
- items.push(this.parseSlice(stream));
3951
+ selectors.push(this.parseSlice(stream));
4026
3952
  break;
4027
3953
  case TokenKind.WILD:
4028
- items.push(new WildcardSelector(this.environment, stream.current));
3954
+ selectors.push(new WildcardSelector(this.environment, stream.current));
4029
3955
  break;
4030
3956
  case TokenKind.KEY_SINGLE_QUOTE_STRING:
4031
3957
  case TokenKind.KEY_DOUBLE_QUOTE_STRING:
4032
- items.push(new KeySelector(this.environment, stream.current, this.decodeString(stream.current), false));
3958
+ selectors.push(new KeySelector(this.environment, stream.current, this.decodeString(stream.current)));
4033
3959
  break;
4034
3960
  case TokenKind.KEYS_FILTER:
4035
- items.push(this.parseFilter(stream, true));
3961
+ selectors.push(this.parseFilter(stream, true));
4036
3962
  break;
4037
3963
  case TokenKind.KEYS:
4038
- items.push(new KeysSelector(this.environment, stream.current));
3964
+ selectors.push(new KeysSelector(this.environment, stream.current));
4039
3965
  break;
4040
3966
  case TokenKind.EOF:
4041
3967
  throw new JSONPathSyntaxError("unexpected end of query", stream.current);
@@ -4049,10 +3975,10 @@ var json_p3 = (function (exports) {
4049
3975
  }
4050
3976
  stream.next();
4051
3977
  }
4052
- if (!items.length) {
3978
+ if (!selectors.length) {
4053
3979
  throw new JSONPathSyntaxError("empty bracketed segment", token);
4054
3980
  }
4055
- return new BracketedSelection(this.environment, token, items);
3981
+ return selectors;
4056
3982
  }
4057
3983
  parseFilter(stream) {
4058
3984
  let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -4132,11 +4058,11 @@ var json_p3 = (function (exports) {
4132
4058
  }
4133
4059
  parseRootQuery(stream) {
4134
4060
  const tok = stream.next();
4135
- return new RootQuery(tok, new JSONPath(this.environment, this.parsePath(stream, true)));
4061
+ return new RootQuery(tok, new JSONPathQuery(this.environment, this.parseQuery(stream, true)));
4136
4062
  }
4137
4063
  parseRelativeQuery(stream) {
4138
4064
  const tok = stream.next();
4139
- return new RelativeQuery(tok, new JSONPath(this.environment, this.parsePath(stream, true)));
4065
+ return new RelativeQuery(tok, new JSONPathQuery(this.environment, this.parseQuery(stream, true)));
4140
4066
  }
4141
4067
  parseCurrentKey(stream) {
4142
4068
  return new CurrentKey(stream.current);
@@ -4420,7 +4346,7 @@ var json_p3 = (function (exports) {
4420
4346
  * A map of function names to objects implementing the {@link FilterFunction}
4421
4347
  * interface. You are free to set or delete custom filter functions directly.
4422
4348
  */
4423
- functionRegister = new Map();
4349
+ functionRegister = (() => new Map())();
4424
4350
  /**
4425
4351
  * @param options - Environment configuration options.
4426
4352
  */
@@ -4438,10 +4364,10 @@ var json_p3 = (function (exports) {
4438
4364
 
4439
4365
  /**
4440
4366
  * @param path - A JSONPath query to parse.
4441
- * @returns A new {@link JSONPath} object, bound to this environment.
4367
+ * @returns A new {@link JSONPathQuery} object, bound to this environment.
4442
4368
  */
4443
4369
  compile(path) {
4444
- return new JSONPath(this, this.parser.parse(new TokenStream(tokenize(this, path))));
4370
+ return new JSONPathQuery(this, this.parser.parse(new TokenStream(tokenize(this, path))));
4445
4371
  }
4446
4372
 
4447
4373
  /**
@@ -4496,7 +4422,7 @@ var json_p3 = (function (exports) {
4496
4422
  /**
4497
4423
  * Check the well-typedness of a function's arguments at compile-time.
4498
4424
  *
4499
- * This method is called by the {@link Parser} when parsing function calls.
4425
+ * This method is called by the parser when parsing function calls.
4500
4426
  * It is expected to throw a {@link JSONPathTypeError} if the function's
4501
4427
  * parameters are not well-typed.
4502
4428
  *
@@ -4523,17 +4449,17 @@ var json_p3 = (function (exports) {
4523
4449
  for (const [typ, arg, idx] of func.argTypes.map((t, i) => [t, args[i], i])) {
4524
4450
  switch (typ) {
4525
4451
  case FunctionExpressionType.ValueType:
4526
- if (!(arg instanceof FilterExpressionLiteral || arg instanceof CurrentKey || arg instanceof JSONPathQuery && arg.path.singularQuery() || arg instanceof FunctionExtension && this.functionRegister.get(arg.name)?.returnType === FunctionExpressionType.ValueType)) {
4452
+ if (!(arg instanceof FilterExpressionLiteral || arg instanceof CurrentKey || arg instanceof FilterQuery && arg.path.singularQuery() || arg instanceof FunctionExtension && this.functionRegister.get(arg.name)?.returnType === FunctionExpressionType.ValueType)) {
4527
4453
  throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of ValueType`, arg.token);
4528
4454
  }
4529
4455
  break;
4530
4456
  case FunctionExpressionType.LogicalType:
4531
- if (!(arg instanceof JSONPathQuery || arg instanceof InfixExpression)) {
4457
+ if (!(arg instanceof FilterQuery || arg instanceof InfixExpression)) {
4532
4458
  throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of LogicalType`, arg.token);
4533
4459
  }
4534
4460
  break;
4535
4461
  case FunctionExpressionType.NodesType:
4536
- if (!(arg instanceof JSONPathQuery || arg instanceof FunctionExtension && this.functionRegister.get(arg.name)?.returnType === FunctionExpressionType.NodesType)) {
4462
+ if (!(arg instanceof FilterQuery || arg instanceof FunctionExtension && this.functionRegister.get(arg.name)?.returnType === FunctionExpressionType.NodesType)) {
4537
4463
  throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of NodesType`, arg.token);
4538
4464
  }
4539
4465
  }
@@ -4649,14 +4575,16 @@ var json_p3 = (function (exports) {
4649
4575
  __proto__: null,
4650
4576
  DEFAULT_ENVIRONMENT: DEFAULT_ENVIRONMENT,
4651
4577
  FunctionExpressionType: FunctionExpressionType,
4652
- JSONPath: JSONPath,
4653
4578
  JSONPathEnvironment: JSONPathEnvironment,
4654
4579
  JSONPathError: JSONPathError,
4655
4580
  JSONPathIndexError: JSONPathIndexError,
4656
4581
  JSONPathLexerError: JSONPathLexerError,
4657
4582
  JSONPathNode: JSONPathNode,
4658
4583
  JSONPathNodeList: JSONPathNodeList,
4584
+ JSONPathQuery: JSONPathQuery,
4659
4585
  JSONPathRecursionLimitError: JSONPathRecursionLimitError,
4586
+ JSONPathSegment: JSONPathSegment,
4587
+ JSONPathSelector: JSONPathSelector,
4660
4588
  JSONPathSyntaxError: JSONPathSyntaxError,
4661
4589
  JSONPathTypeError: JSONPathTypeError,
4662
4590
  KEY_MARK: KEY_MARK,
@@ -4863,7 +4791,11 @@ var json_p3 = (function (exports) {
4863
4791
  throw new JSONPatchError(`unexpected operation on 'undefined' (${this.name}:${index})`);
4864
4792
  }
4865
4793
  if (isArray(destParent)) {
4866
- destParent.splice(Number(destTarget), 0, sourceObj);
4794
+ if (destTarget === "-") {
4795
+ destParent.push(sourceObj);
4796
+ } else {
4797
+ destParent.splice(Number(destTarget), 0, sourceObj);
4798
+ }
4867
4799
  } else if (isObject(destParent)) {
4868
4800
  destParent[destTarget] = sourceObj;
4869
4801
  } else {
@@ -4905,11 +4837,15 @@ var json_p3 = (function (exports) {
4905
4837
  throw new JSONPatchError(`unexpected operation on 'undefined' (${this.name}:${index})`);
4906
4838
  }
4907
4839
  if (isArray(destParent)) {
4908
- destParent.splice(Number(destTarget), 0, this.deepCopy(sourceObj));
4840
+ if (destTarget === "-") {
4841
+ destParent.push(this.deepCopy(sourceObj));
4842
+ } else {
4843
+ destParent.splice(Number(destTarget), 0, this.deepCopy(sourceObj));
4844
+ }
4909
4845
  } else if (isObject(destParent)) {
4910
4846
  destParent[destTarget] = this.deepCopy(sourceObj);
4911
4847
  } else {
4912
- throw new JSONPatchError(`unexpected operation on '${typeof parent}' (${this.name}:${index})`);
4848
+ throw new JSONPatchError(`unexpected operation on '${typeof destParent}' (${this.name}:${index})`);
4913
4849
  }
4914
4850
  return value;
4915
4851
  }
@@ -5152,20 +5088,20 @@ var json_p3 = (function (exports) {
5152
5088
  apply: apply
5153
5089
  });
5154
5090
 
5155
- const version = "1.3.4";
5091
+ const version = "2.0.0";
5156
5092
 
5157
5093
  exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
5158
5094
  exports.FunctionExpressionType = FunctionExpressionType;
5159
5095
  exports.JSONPatch = JSONPatch;
5160
5096
  exports.JSONPatchError = JSONPatchError;
5161
5097
  exports.JSONPatchTestFailure = JSONPatchTestFailure;
5162
- exports.JSONPath = JSONPath;
5163
5098
  exports.JSONPathEnvironment = JSONPathEnvironment;
5164
5099
  exports.JSONPathError = JSONPathError;
5165
5100
  exports.JSONPathIndexError = JSONPathIndexError;
5166
5101
  exports.JSONPathLexerError = JSONPathLexerError;
5167
5102
  exports.JSONPathNode = JSONPathNode;
5168
5103
  exports.JSONPathNodeList = JSONPathNodeList;
5104
+ exports.JSONPathQuery = JSONPathQuery;
5169
5105
  exports.JSONPathRecursionLimitError = JSONPathRecursionLimitError;
5170
5106
  exports.JSONPathSyntaxError = JSONPathSyntaxError;
5171
5107
  exports.JSONPathTypeError = JSONPathTypeError;