json-p3 1.3.5 → 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.
- package/dist/index.d.ts +1 -1
- package/dist/json-p3.cjs.js +321 -396
- package/dist/json-p3.esm.js +321 -396
- package/dist/json-p3.iife.js +321 -396
- package/dist/json-p3.iife.min.js +1 -1
- package/dist/json-p3.iife.min.js.map +1 -1
- package/dist/path/environment.d.ts +4 -4
- package/dist/path/expression.d.ts +6 -6
- package/dist/path/extra/selectors.d.ts +8 -10
- package/dist/path/index.d.ts +5 -3
- package/dist/path/parse.d.ts +6 -5
- package/dist/path/path.d.ts +5 -5
- package/dist/path/segments.d.ts +38 -0
- package/dist/path/selectors.d.ts +16 -41
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/json-p3.iife.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* json-p3 version
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
@@ -3132,11 +3132,11 @@ var json_p3 = (function (exports) {
|
|
|
3132
3132
|
}
|
|
3133
3133
|
|
|
3134
3134
|
/**
|
|
3135
|
-
* @param
|
|
3135
|
+
* @param node - Nodes matched by preceding selectors.
|
|
3136
3136
|
*/
|
|
3137
3137
|
|
|
3138
3138
|
/**
|
|
3139
|
-
* @param
|
|
3139
|
+
* @param node - Nodes matched by preceding selectors.
|
|
3140
3140
|
*/
|
|
3141
3141
|
|
|
3142
3142
|
/**
|
|
@@ -3148,31 +3148,26 @@ var json_p3 = (function (exports) {
|
|
|
3148
3148
|
* Shorthand and quoted name selector.
|
|
3149
3149
|
*/
|
|
3150
3150
|
class NameSelector extends JSONPathSelector {
|
|
3151
|
-
constructor(environment, token, name
|
|
3151
|
+
constructor(environment, token, name) {
|
|
3152
3152
|
super(environment, token);
|
|
3153
3153
|
this.environment = environment;
|
|
3154
3154
|
this.token = token;
|
|
3155
3155
|
this.name = name;
|
|
3156
|
-
this.shorthand = shorthand;
|
|
3157
3156
|
}
|
|
3158
|
-
resolve(
|
|
3157
|
+
resolve(node) {
|
|
3159
3158
|
const rv = [];
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
rv.push(new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root));
|
|
3163
|
-
}
|
|
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));
|
|
3164
3161
|
}
|
|
3165
3162
|
return rv;
|
|
3166
3163
|
}
|
|
3167
|
-
*lazyResolve(
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
yield new JSONPathNode(node.value[this.name], node.location.concat(this.name), node.root);
|
|
3171
|
-
}
|
|
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);
|
|
3172
3167
|
}
|
|
3173
3168
|
}
|
|
3174
3169
|
toString() {
|
|
3175
|
-
return
|
|
3170
|
+
return `'${this.name}'`;
|
|
3176
3171
|
}
|
|
3177
3172
|
}
|
|
3178
3173
|
|
|
@@ -3189,25 +3184,21 @@ var json_p3 = (function (exports) {
|
|
|
3189
3184
|
throw new JSONPathIndexError("index out of range", this.token);
|
|
3190
3185
|
}
|
|
3191
3186
|
}
|
|
3192
|
-
resolve(
|
|
3187
|
+
resolve(node) {
|
|
3193
3188
|
const rv = [];
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
rv.push(new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root));
|
|
3199
|
-
}
|
|
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));
|
|
3200
3193
|
}
|
|
3201
3194
|
}
|
|
3202
3195
|
return rv;
|
|
3203
3196
|
}
|
|
3204
|
-
*lazyResolve(
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
yield new JSONPathNode(node.value[normIndex], node.location.concat(normIndex), node.root);
|
|
3210
|
-
}
|
|
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);
|
|
3211
3202
|
}
|
|
3212
3203
|
}
|
|
3213
3204
|
}
|
|
@@ -3229,19 +3220,16 @@ var json_p3 = (function (exports) {
|
|
|
3229
3220
|
this.step = step;
|
|
3230
3221
|
this.checkRange(start, stop, step);
|
|
3231
3222
|
}
|
|
3232
|
-
resolve(
|
|
3223
|
+
resolve(node) {
|
|
3233
3224
|
const rv = [];
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
|
|
3238
|
-
}
|
|
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));
|
|
3239
3228
|
}
|
|
3240
3229
|
return rv;
|
|
3241
3230
|
}
|
|
3242
|
-
*lazyResolve(
|
|
3243
|
-
|
|
3244
|
-
if (!isArray(node.value)) continue;
|
|
3231
|
+
*lazyResolve(node) {
|
|
3232
|
+
if (isArray(node.value)) {
|
|
3245
3233
|
for (const [i, value] of this.lazySlice(node.value, this.start, this.stop, this.step)) {
|
|
3246
3234
|
yield new JSONPathNode(value, node.location.concat(i), node.root);
|
|
3247
3235
|
}
|
|
@@ -3347,281 +3335,175 @@ var json_p3 = (function (exports) {
|
|
|
3347
3335
|
}
|
|
3348
3336
|
class WildcardSelector extends JSONPathSelector {
|
|
3349
3337
|
constructor(environment, token) {
|
|
3350
|
-
let shorthand = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3351
3338
|
super(environment, token);
|
|
3352
3339
|
this.environment = environment;
|
|
3353
3340
|
this.token = token;
|
|
3354
|
-
this.shorthand = shorthand;
|
|
3355
3341
|
}
|
|
3356
|
-
resolve(
|
|
3342
|
+
resolve(node) {
|
|
3357
3343
|
const rv = [];
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
|
|
3367
|
-
}
|
|
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));
|
|
3368
3352
|
}
|
|
3369
3353
|
}
|
|
3370
3354
|
return rv;
|
|
3371
3355
|
}
|
|
3372
|
-
*lazyResolve(
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
for (const [key, value] of this.environment.entries(node.value)) {
|
|
3381
|
-
yield new JSONPathNode(value, node.location.concat(key), node.root);
|
|
3382
|
-
}
|
|
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);
|
|
3383
3364
|
}
|
|
3384
3365
|
}
|
|
3385
3366
|
}
|
|
3386
3367
|
toString() {
|
|
3387
|
-
return
|
|
3368
|
+
return "*";
|
|
3388
3369
|
}
|
|
3389
3370
|
}
|
|
3390
|
-
class
|
|
3391
|
-
constructor(environment, token,
|
|
3371
|
+
class FilterSelector extends JSONPathSelector {
|
|
3372
|
+
constructor(environment, token, expression) {
|
|
3392
3373
|
super(environment, token);
|
|
3393
3374
|
this.environment = environment;
|
|
3394
3375
|
this.token = token;
|
|
3395
|
-
this.
|
|
3396
|
-
}
|
|
3397
|
-
resolve(nodes) {
|
|
3398
|
-
const rv = [];
|
|
3399
|
-
if (this.environment.nondeterministic) {
|
|
3400
|
-
for (const root of nodes) {
|
|
3401
|
-
for (const node of this.nondeterministicVisitor(root)) {
|
|
3402
|
-
rv.push(node);
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
} else {
|
|
3406
|
-
for (const node of nodes) {
|
|
3407
|
-
rv.push(node);
|
|
3408
|
-
for (const _node of this.visitor(node)) {
|
|
3409
|
-
rv.push(_node);
|
|
3410
|
-
}
|
|
3411
|
-
}
|
|
3412
|
-
}
|
|
3413
|
-
return this.selector.resolve(rv);
|
|
3414
|
-
}
|
|
3415
|
-
*lazyResolve(nodes) {
|
|
3416
|
-
yield* this.selector.lazyResolve(this._lazyResolve(nodes));
|
|
3417
|
-
}
|
|
3418
|
-
|
|
3419
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
3420
|
-
*_lazyResolve(nodes) {
|
|
3421
|
-
for (const _node of nodes) {
|
|
3422
|
-
const stack = [{
|
|
3423
|
-
node: _node,
|
|
3424
|
-
depth: 0
|
|
3425
|
-
}];
|
|
3426
|
-
yield _node;
|
|
3427
|
-
while (stack.length) {
|
|
3428
|
-
const {
|
|
3429
|
-
node: currentNode,
|
|
3430
|
-
depth
|
|
3431
|
-
} = stack.pop();
|
|
3432
|
-
if (depth >= this.environment.maxRecursionDepth) {
|
|
3433
|
-
throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
|
|
3434
|
-
}
|
|
3435
|
-
if (currentNode.value instanceof String) continue;
|
|
3436
|
-
if (isArray(currentNode.value)) {
|
|
3437
|
-
for (let i = 0; i < currentNode.value.length; i++) {
|
|
3438
|
-
const __node = new JSONPathNode(currentNode.value[i], currentNode.location.concat(i), currentNode.root);
|
|
3439
|
-
yield __node;
|
|
3440
|
-
if (isObject(__node.value)) {
|
|
3441
|
-
stack.push({
|
|
3442
|
-
node: __node,
|
|
3443
|
-
depth: depth + 1
|
|
3444
|
-
});
|
|
3445
|
-
}
|
|
3446
|
-
}
|
|
3447
|
-
} else if (isObject(currentNode.value)) {
|
|
3448
|
-
for (const [key, value] of this.environment.entries(currentNode.value)) {
|
|
3449
|
-
const __node = new JSONPathNode(value, currentNode.location.concat(key), currentNode.root);
|
|
3450
|
-
yield __node;
|
|
3451
|
-
if (isObject(__node.value)) {
|
|
3452
|
-
stack.push({
|
|
3453
|
-
node: __node,
|
|
3454
|
-
depth: depth + 1
|
|
3455
|
-
});
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
}
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
}
|
|
3462
|
-
toString() {
|
|
3463
|
-
return `..${this.selector.toString()}`;
|
|
3376
|
+
this.expression = expression;
|
|
3464
3377
|
}
|
|
3465
|
-
|
|
3466
|
-
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
3467
|
-
if (depth >= this.environment.maxRecursionDepth) {
|
|
3468
|
-
throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
|
|
3469
|
-
}
|
|
3378
|
+
resolve(node) {
|
|
3470
3379
|
const rv = [];
|
|
3471
3380
|
if (node.value instanceof String) return rv;
|
|
3472
3381
|
if (isArray(node.value)) {
|
|
3473
3382
|
for (let i = 0; i < node.value.length; i++) {
|
|
3474
|
-
const
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
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));
|
|
3478
3392
|
}
|
|
3479
3393
|
}
|
|
3480
3394
|
} else if (isObject(node.value)) {
|
|
3481
3395
|
for (const [key, value] of this.environment.entries(node.value)) {
|
|
3482
|
-
const
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
}
|
|
3491
|
-
nondeterministicVisitor(root) {
|
|
3492
|
-
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
3493
|
-
const rv = [root];
|
|
3494
|
-
let queue = this.nondeterministicChildren(root).map(node => [node, depth]);
|
|
3495
|
-
while (queue.length) {
|
|
3496
|
-
const [node, _depth] = queue.shift();
|
|
3497
|
-
rv.push(node);
|
|
3498
|
-
if (_depth >= this.environment.maxRecursionDepth) {
|
|
3499
|
-
throw new JSONPathRecursionLimitError("recursion limit reached", this.token);
|
|
3500
|
-
}
|
|
3501
|
-
|
|
3502
|
-
// Visit child nodes now or queue them for later?
|
|
3503
|
-
const visitChildren = Math.random() < 0.5;
|
|
3504
|
-
for (const child of this.nondeterministicChildren(node)) {
|
|
3505
|
-
if (visitChildren) {
|
|
3506
|
-
rv.push(child);
|
|
3507
|
-
const grandchildren = this.nondeterministicChildren(child).map(n => [n, _depth + 2]);
|
|
3508
|
-
queue = interleave(queue, grandchildren);
|
|
3509
|
-
} else {
|
|
3510
|
-
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));
|
|
3511
3404
|
}
|
|
3512
3405
|
}
|
|
3513
3406
|
}
|
|
3514
3407
|
return rv;
|
|
3515
3408
|
}
|
|
3516
|
-
|
|
3517
|
-
const _rv = [];
|
|
3518
|
-
if (node.value instanceof String) return _rv;
|
|
3409
|
+
*lazyResolve(node) {
|
|
3519
3410
|
if (isArray(node.value)) {
|
|
3520
3411
|
for (let i = 0; i < node.value.length; i++) {
|
|
3521
|
-
|
|
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
|
+
}
|
|
3522
3423
|
}
|
|
3523
|
-
} else if (isObject(node.value)) {
|
|
3424
|
+
} else if (isObject(node.value) && !isString(node.value)) {
|
|
3524
3425
|
for (const [key, value] of this.environment.entries(node.value)) {
|
|
3525
|
-
|
|
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
|
+
}
|
|
3526
3436
|
}
|
|
3527
3437
|
}
|
|
3528
|
-
|
|
3438
|
+
}
|
|
3439
|
+
toString() {
|
|
3440
|
+
return `?${this.expression.toString()}`;
|
|
3529
3441
|
}
|
|
3530
3442
|
}
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
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) {
|
|
3534
3457
|
this.environment = environment;
|
|
3535
3458
|
this.token = token;
|
|
3536
|
-
this.
|
|
3459
|
+
this.selectors = selectors;
|
|
3537
3460
|
}
|
|
3538
3461
|
|
|
3539
|
-
|
|
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 {
|
|
3540
3477
|
resolve(nodes) {
|
|
3541
3478
|
const rv = [];
|
|
3542
3479
|
for (const node of nodes) {
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
for (let i = 0; i < node.value.length; i++) {
|
|
3546
|
-
const value = node.value[i];
|
|
3547
|
-
const filterContext = {
|
|
3548
|
-
environment: this.environment,
|
|
3549
|
-
currentValue: value,
|
|
3550
|
-
rootValue: node.root,
|
|
3551
|
-
currentKey: i
|
|
3552
|
-
};
|
|
3553
|
-
if (this.expression.evaluate(filterContext)) {
|
|
3554
|
-
rv.push(new JSONPathNode(value, node.location.concat(i), node.root));
|
|
3555
|
-
}
|
|
3556
|
-
}
|
|
3557
|
-
} else if (isObject(node.value)) {
|
|
3558
|
-
for (const [key, value] of this.environment.entries(node.value)) {
|
|
3559
|
-
const filterContext = {
|
|
3560
|
-
environment: this.environment,
|
|
3561
|
-
currentValue: value,
|
|
3562
|
-
rootValue: node.root,
|
|
3563
|
-
currentKey: key
|
|
3564
|
-
};
|
|
3565
|
-
if (this.expression.evaluate(filterContext)) {
|
|
3566
|
-
rv.push(new JSONPathNode(value, node.location.concat(key), node.root));
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3480
|
+
for (const selector of this.selectors) {
|
|
3481
|
+
rv.push(...selector.resolve(node));
|
|
3569
3482
|
}
|
|
3570
3483
|
}
|
|
3571
3484
|
return rv;
|
|
3572
3485
|
}
|
|
3573
|
-
|
|
3574
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
3575
3486
|
*lazyResolve(nodes) {
|
|
3576
3487
|
for (const node of nodes) {
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
for (let i = 0; i < node.value.length; i++) {
|
|
3580
|
-
const value = node.value[i];
|
|
3581
|
-
const filterContext = {
|
|
3582
|
-
environment: this.environment,
|
|
3583
|
-
currentValue: value,
|
|
3584
|
-
rootValue: node.root,
|
|
3585
|
-
lazy: true,
|
|
3586
|
-
currentKey: i
|
|
3587
|
-
};
|
|
3588
|
-
if (this.expression.evaluate(filterContext)) {
|
|
3589
|
-
yield new JSONPathNode(value, node.location.concat(i), node.root);
|
|
3590
|
-
}
|
|
3591
|
-
}
|
|
3592
|
-
} else if (isObject(node.value)) {
|
|
3593
|
-
for (const [key, value] of this.environment.entries(node.value)) {
|
|
3594
|
-
const filterContext = {
|
|
3595
|
-
environment: this.environment,
|
|
3596
|
-
currentValue: value,
|
|
3597
|
-
rootValue: node.root,
|
|
3598
|
-
lazy: true,
|
|
3599
|
-
currentKey: key
|
|
3600
|
-
};
|
|
3601
|
-
if (this.expression.evaluate(filterContext)) {
|
|
3602
|
-
yield new JSONPathNode(value, node.location.concat(key), node.root);
|
|
3603
|
-
}
|
|
3604
|
-
}
|
|
3488
|
+
for (const selector of this.selectors) {
|
|
3489
|
+
yield* selector.resolve(node);
|
|
3605
3490
|
}
|
|
3606
3491
|
}
|
|
3607
3492
|
}
|
|
3608
3493
|
toString() {
|
|
3609
|
-
return
|
|
3494
|
+
return `[${this.selectors.map(s => s.toString()).join(", ")}]`;
|
|
3610
3495
|
}
|
|
3611
3496
|
}
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
this.environment = environment;
|
|
3616
|
-
this.token = token;
|
|
3617
|
-
this.items = items;
|
|
3618
|
-
}
|
|
3497
|
+
|
|
3498
|
+
/** The recursive descent segment. */
|
|
3499
|
+
class DescendantSegment extends JSONPathSegment {
|
|
3619
3500
|
resolve(nodes) {
|
|
3620
3501
|
const rv = [];
|
|
3502
|
+
const visitor = (this.environment.nondeterministic ? this.nondeterministicVisit : this.visit).bind(this);
|
|
3621
3503
|
for (const node of nodes) {
|
|
3622
|
-
for (const
|
|
3623
|
-
for (const
|
|
3624
|
-
rv.push(_node);
|
|
3504
|
+
for (const _node of visitor(node)) {
|
|
3505
|
+
for (const selector of this.selectors) {
|
|
3506
|
+
rv.push(...selector.resolve(_node));
|
|
3625
3507
|
}
|
|
3626
3508
|
}
|
|
3627
3509
|
}
|
|
@@ -3629,13 +3511,75 @@ var json_p3 = (function (exports) {
|
|
|
3629
3511
|
}
|
|
3630
3512
|
*lazyResolve(nodes) {
|
|
3631
3513
|
for (const node of nodes) {
|
|
3632
|
-
for (const
|
|
3633
|
-
|
|
3514
|
+
for (const _node of this.visit(node)) {
|
|
3515
|
+
for (const selector of this.selectors) {
|
|
3516
|
+
yield* selector.resolve(_node);
|
|
3517
|
+
}
|
|
3634
3518
|
}
|
|
3635
3519
|
}
|
|
3636
3520
|
}
|
|
3637
3521
|
toString() {
|
|
3638
|
-
return
|
|
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
|
+
}
|
|
3639
3583
|
}
|
|
3640
3584
|
}
|
|
3641
3585
|
|
|
@@ -3674,30 +3618,18 @@ var json_p3 = (function (exports) {
|
|
|
3674
3618
|
return entries;
|
|
3675
3619
|
}
|
|
3676
3620
|
|
|
3677
|
-
var selectors = /*#__PURE__*/Object.freeze({
|
|
3678
|
-
__proto__: null,
|
|
3679
|
-
BracketedSelection: BracketedSelection,
|
|
3680
|
-
FilterSelector: FilterSelector,
|
|
3681
|
-
IndexSelector: IndexSelector,
|
|
3682
|
-
JSONPathSelector: JSONPathSelector,
|
|
3683
|
-
NameSelector: NameSelector,
|
|
3684
|
-
RecursiveDescentSegment: RecursiveDescentSegment,
|
|
3685
|
-
SliceSelector: SliceSelector,
|
|
3686
|
-
WildcardSelector: WildcardSelector
|
|
3687
|
-
});
|
|
3688
|
-
|
|
3689
3621
|
/**
|
|
3690
3622
|
*
|
|
3691
3623
|
*/
|
|
3692
|
-
class
|
|
3624
|
+
class JSONPathQuery {
|
|
3693
3625
|
/**
|
|
3694
3626
|
*
|
|
3695
3627
|
* @param environment -
|
|
3696
|
-
* @param
|
|
3628
|
+
* @param segments -
|
|
3697
3629
|
*/
|
|
3698
|
-
constructor(environment,
|
|
3630
|
+
constructor(environment, segments) {
|
|
3699
3631
|
this.environment = environment;
|
|
3700
|
-
this.
|
|
3632
|
+
this.segments = segments;
|
|
3701
3633
|
}
|
|
3702
3634
|
|
|
3703
3635
|
/**
|
|
@@ -3707,8 +3639,8 @@ var json_p3 = (function (exports) {
|
|
|
3707
3639
|
*/
|
|
3708
3640
|
query(value) {
|
|
3709
3641
|
let nodes = [new JSONPathNode(value, [], value)];
|
|
3710
|
-
for (const
|
|
3711
|
-
nodes =
|
|
3642
|
+
for (const segment of this.segments) {
|
|
3643
|
+
nodes = segment.resolve(nodes);
|
|
3712
3644
|
}
|
|
3713
3645
|
return new JSONPathNodeList(nodes);
|
|
3714
3646
|
}
|
|
@@ -3720,8 +3652,8 @@ var json_p3 = (function (exports) {
|
|
|
3720
3652
|
*/
|
|
3721
3653
|
lazyQuery(value) {
|
|
3722
3654
|
let nodes = [new JSONPathNode(value, [], value)][Symbol.iterator]();
|
|
3723
|
-
for (const
|
|
3724
|
-
nodes =
|
|
3655
|
+
for (const segment of this.segments) {
|
|
3656
|
+
nodes = segment.lazyResolve(nodes);
|
|
3725
3657
|
}
|
|
3726
3658
|
return nodes;
|
|
3727
3659
|
}
|
|
@@ -3745,12 +3677,14 @@ var json_p3 = (function (exports) {
|
|
|
3745
3677
|
*
|
|
3746
3678
|
*/
|
|
3747
3679
|
toString() {
|
|
3748
|
-
return `$${this.
|
|
3680
|
+
return `$${this.segments.map(s => s.toString()).join("")}`;
|
|
3749
3681
|
}
|
|
3750
3682
|
singularQuery() {
|
|
3751
|
-
for (const
|
|
3752
|
-
if (
|
|
3753
|
-
if (
|
|
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
|
+
}
|
|
3754
3688
|
return false;
|
|
3755
3689
|
}
|
|
3756
3690
|
return true;
|
|
@@ -3768,33 +3702,26 @@ var json_p3 = (function (exports) {
|
|
|
3768
3702
|
|
|
3769
3703
|
class KeySelector extends JSONPathSelector {
|
|
3770
3704
|
constructor(environment, token, key) {
|
|
3771
|
-
let shorthand = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
3772
3705
|
super(environment, token);
|
|
3773
3706
|
this.environment = environment;
|
|
3774
3707
|
this.token = token;
|
|
3775
3708
|
this.key = key;
|
|
3776
|
-
this.shorthand = shorthand;
|
|
3777
3709
|
}
|
|
3778
|
-
resolve(
|
|
3710
|
+
resolve(node) {
|
|
3779
3711
|
const rv = [];
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
rv.push(new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root));
|
|
3784
|
-
}
|
|
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));
|
|
3785
3715
|
}
|
|
3786
3716
|
return rv;
|
|
3787
3717
|
}
|
|
3788
|
-
*lazyResolve(
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
if (isObject(node.value) && hasStringKey(node.value, this.key)) {
|
|
3792
|
-
yield new JSONPathNode(this.key, node.location.concat(`${KEY_MARK}${this.key}`), node.root);
|
|
3793
|
-
}
|
|
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);
|
|
3794
3721
|
}
|
|
3795
3722
|
}
|
|
3796
3723
|
toString() {
|
|
3797
|
-
return
|
|
3724
|
+
return `~'${this.key.replaceAll("'", "\\'")}'`;
|
|
3798
3725
|
}
|
|
3799
3726
|
}
|
|
3800
3727
|
|
|
@@ -3803,36 +3730,29 @@ var json_p3 = (function (exports) {
|
|
|
3803
3730
|
*/
|
|
3804
3731
|
class KeysSelector extends JSONPathSelector {
|
|
3805
3732
|
constructor(environment, token) {
|
|
3806
|
-
let shorthand = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3807
3733
|
super(environment, token);
|
|
3808
3734
|
this.environment = environment;
|
|
3809
3735
|
this.token = token;
|
|
3810
|
-
this.shorthand = shorthand;
|
|
3811
3736
|
}
|
|
3812
|
-
resolve(
|
|
3737
|
+
resolve(node) {
|
|
3813
3738
|
const rv = [];
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
|
|
3819
|
-
}
|
|
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));
|
|
3820
3743
|
}
|
|
3821
3744
|
}
|
|
3822
3745
|
return rv;
|
|
3823
3746
|
}
|
|
3824
|
-
*lazyResolve(
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
for (const [key, _] of this.environment.entries(node.value)) {
|
|
3829
|
-
yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
|
|
3830
|
-
}
|
|
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);
|
|
3831
3751
|
}
|
|
3832
3752
|
}
|
|
3833
3753
|
}
|
|
3834
3754
|
toString() {
|
|
3835
|
-
return
|
|
3755
|
+
return "~";
|
|
3836
3756
|
}
|
|
3837
3757
|
}
|
|
3838
3758
|
class KeysFilterSelector extends JSONPathSelector {
|
|
@@ -3842,41 +3762,37 @@ var json_p3 = (function (exports) {
|
|
|
3842
3762
|
this.token = token;
|
|
3843
3763
|
this.expression = expression;
|
|
3844
3764
|
}
|
|
3845
|
-
resolve(
|
|
3765
|
+
resolve(node) {
|
|
3846
3766
|
const rv = [];
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
rv.push(new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root));
|
|
3859
|
-
}
|
|
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));
|
|
3860
3778
|
}
|
|
3861
3779
|
}
|
|
3862
3780
|
}
|
|
3863
3781
|
return rv;
|
|
3864
3782
|
}
|
|
3865
|
-
*lazyResolve(
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
yield new JSONPathNode(key, node.location.concat(`${KEY_MARK}${key}`), node.root);
|
|
3879
|
-
}
|
|
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);
|
|
3880
3796
|
}
|
|
3881
3797
|
}
|
|
3882
3798
|
}
|
|
@@ -3905,52 +3821,59 @@ var json_p3 = (function (exports) {
|
|
|
3905
3821
|
}
|
|
3906
3822
|
parse(stream) {
|
|
3907
3823
|
if (stream.current.kind === TokenKind.ROOT) stream.next();
|
|
3908
|
-
const
|
|
3824
|
+
const segments = this.parseQuery(stream);
|
|
3909
3825
|
if (stream.current.kind !== TokenKind.EOF) {
|
|
3910
3826
|
throw new JSONPathSyntaxError(`unexpected token '${stream.current.kind}'`, stream.current);
|
|
3911
3827
|
}
|
|
3912
|
-
return
|
|
3828
|
+
return segments;
|
|
3913
3829
|
}
|
|
3914
|
-
|
|
3830
|
+
parseQuery(stream) {
|
|
3915
3831
|
let inFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
3916
|
-
const
|
|
3917
|
-
for (;;) {
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
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
|
+
}
|
|
3924
3858
|
}
|
|
3925
|
-
selectors.push(selector);
|
|
3926
3859
|
stream.next();
|
|
3927
3860
|
}
|
|
3928
|
-
return
|
|
3861
|
+
return segments;
|
|
3929
3862
|
}
|
|
3930
|
-
|
|
3863
|
+
parseSelectors(stream) {
|
|
3931
3864
|
switch (stream.current.kind) {
|
|
3932
3865
|
case TokenKind.NAME:
|
|
3933
|
-
return new NameSelector(this.environment, stream.current, stream.current.value
|
|
3866
|
+
return [new NameSelector(this.environment, stream.current, stream.current.value)];
|
|
3934
3867
|
case TokenKind.WILD:
|
|
3935
|
-
return new WildcardSelector(this.environment, stream.current
|
|
3868
|
+
return [new WildcardSelector(this.environment, stream.current)];
|
|
3936
3869
|
case TokenKind.KEY:
|
|
3937
|
-
return new KeySelector(this.environment, stream.current, stream.current.value
|
|
3870
|
+
return [new KeySelector(this.environment, stream.current, stream.current.value)];
|
|
3938
3871
|
case TokenKind.KEYS:
|
|
3939
|
-
return new KeysSelector(this.environment, stream.current
|
|
3940
|
-
case TokenKind.DDOT:
|
|
3941
|
-
{
|
|
3942
|
-
const segmentToken = stream.current;
|
|
3943
|
-
stream.next();
|
|
3944
|
-
const selector = this.parseSegment(stream);
|
|
3945
|
-
if (!selector) {
|
|
3946
|
-
throw new JSONPathSyntaxError("bald descendant segment", stream.current);
|
|
3947
|
-
}
|
|
3948
|
-
return new RecursiveDescentSegment(this.environment, segmentToken, selector);
|
|
3949
|
-
}
|
|
3872
|
+
return [new KeysSelector(this.environment, stream.current)];
|
|
3950
3873
|
case TokenKind.LBRACKET:
|
|
3951
3874
|
return this.parseBracketedSelection(stream);
|
|
3952
3875
|
default:
|
|
3953
|
-
return
|
|
3876
|
+
return [];
|
|
3954
3877
|
}
|
|
3955
3878
|
}
|
|
3956
3879
|
parseIndex(stream) {
|
|
@@ -4007,38 +3930,38 @@ var json_p3 = (function (exports) {
|
|
|
4007
3930
|
}
|
|
4008
3931
|
parseBracketedSelection(stream) {
|
|
4009
3932
|
const token = stream.next();
|
|
4010
|
-
const
|
|
3933
|
+
const selectors = [];
|
|
4011
3934
|
while (stream.current.kind !== TokenKind.RBRACKET) {
|
|
4012
3935
|
switch (stream.current.kind) {
|
|
4013
3936
|
case TokenKind.SINGLE_QUOTE_STRING:
|
|
4014
3937
|
case TokenKind.DOUBLE_QUOTE_STRING:
|
|
4015
|
-
|
|
3938
|
+
selectors.push(new NameSelector(this.environment, stream.current, this.decodeString(stream.current)));
|
|
4016
3939
|
break;
|
|
4017
3940
|
case TokenKind.FILTER:
|
|
4018
|
-
|
|
3941
|
+
selectors.push(this.parseFilter(stream));
|
|
4019
3942
|
break;
|
|
4020
3943
|
case TokenKind.INDEX:
|
|
4021
3944
|
if (stream.peek.kind === TokenKind.COLON) {
|
|
4022
|
-
|
|
3945
|
+
selectors.push(this.parseSlice(stream));
|
|
4023
3946
|
} else {
|
|
4024
|
-
|
|
3947
|
+
selectors.push(this.parseIndex(stream));
|
|
4025
3948
|
}
|
|
4026
3949
|
break;
|
|
4027
3950
|
case TokenKind.COLON:
|
|
4028
|
-
|
|
3951
|
+
selectors.push(this.parseSlice(stream));
|
|
4029
3952
|
break;
|
|
4030
3953
|
case TokenKind.WILD:
|
|
4031
|
-
|
|
3954
|
+
selectors.push(new WildcardSelector(this.environment, stream.current));
|
|
4032
3955
|
break;
|
|
4033
3956
|
case TokenKind.KEY_SINGLE_QUOTE_STRING:
|
|
4034
3957
|
case TokenKind.KEY_DOUBLE_QUOTE_STRING:
|
|
4035
|
-
|
|
3958
|
+
selectors.push(new KeySelector(this.environment, stream.current, this.decodeString(stream.current)));
|
|
4036
3959
|
break;
|
|
4037
3960
|
case TokenKind.KEYS_FILTER:
|
|
4038
|
-
|
|
3961
|
+
selectors.push(this.parseFilter(stream, true));
|
|
4039
3962
|
break;
|
|
4040
3963
|
case TokenKind.KEYS:
|
|
4041
|
-
|
|
3964
|
+
selectors.push(new KeysSelector(this.environment, stream.current));
|
|
4042
3965
|
break;
|
|
4043
3966
|
case TokenKind.EOF:
|
|
4044
3967
|
throw new JSONPathSyntaxError("unexpected end of query", stream.current);
|
|
@@ -4052,10 +3975,10 @@ var json_p3 = (function (exports) {
|
|
|
4052
3975
|
}
|
|
4053
3976
|
stream.next();
|
|
4054
3977
|
}
|
|
4055
|
-
if (!
|
|
3978
|
+
if (!selectors.length) {
|
|
4056
3979
|
throw new JSONPathSyntaxError("empty bracketed segment", token);
|
|
4057
3980
|
}
|
|
4058
|
-
return
|
|
3981
|
+
return selectors;
|
|
4059
3982
|
}
|
|
4060
3983
|
parseFilter(stream) {
|
|
4061
3984
|
let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -4135,11 +4058,11 @@ var json_p3 = (function (exports) {
|
|
|
4135
4058
|
}
|
|
4136
4059
|
parseRootQuery(stream) {
|
|
4137
4060
|
const tok = stream.next();
|
|
4138
|
-
return new RootQuery(tok, new
|
|
4061
|
+
return new RootQuery(tok, new JSONPathQuery(this.environment, this.parseQuery(stream, true)));
|
|
4139
4062
|
}
|
|
4140
4063
|
parseRelativeQuery(stream) {
|
|
4141
4064
|
const tok = stream.next();
|
|
4142
|
-
return new RelativeQuery(tok, new
|
|
4065
|
+
return new RelativeQuery(tok, new JSONPathQuery(this.environment, this.parseQuery(stream, true)));
|
|
4143
4066
|
}
|
|
4144
4067
|
parseCurrentKey(stream) {
|
|
4145
4068
|
return new CurrentKey(stream.current);
|
|
@@ -4441,10 +4364,10 @@ var json_p3 = (function (exports) {
|
|
|
4441
4364
|
|
|
4442
4365
|
/**
|
|
4443
4366
|
* @param path - A JSONPath query to parse.
|
|
4444
|
-
* @returns A new {@link
|
|
4367
|
+
* @returns A new {@link JSONPathQuery} object, bound to this environment.
|
|
4445
4368
|
*/
|
|
4446
4369
|
compile(path) {
|
|
4447
|
-
return new
|
|
4370
|
+
return new JSONPathQuery(this, this.parser.parse(new TokenStream(tokenize(this, path))));
|
|
4448
4371
|
}
|
|
4449
4372
|
|
|
4450
4373
|
/**
|
|
@@ -4499,7 +4422,7 @@ var json_p3 = (function (exports) {
|
|
|
4499
4422
|
/**
|
|
4500
4423
|
* Check the well-typedness of a function's arguments at compile-time.
|
|
4501
4424
|
*
|
|
4502
|
-
* This method is called by the
|
|
4425
|
+
* This method is called by the parser when parsing function calls.
|
|
4503
4426
|
* It is expected to throw a {@link JSONPathTypeError} if the function's
|
|
4504
4427
|
* parameters are not well-typed.
|
|
4505
4428
|
*
|
|
@@ -4526,17 +4449,17 @@ var json_p3 = (function (exports) {
|
|
|
4526
4449
|
for (const [typ, arg, idx] of func.argTypes.map((t, i) => [t, args[i], i])) {
|
|
4527
4450
|
switch (typ) {
|
|
4528
4451
|
case FunctionExpressionType.ValueType:
|
|
4529
|
-
if (!(arg instanceof FilterExpressionLiteral || arg instanceof CurrentKey || arg instanceof
|
|
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)) {
|
|
4530
4453
|
throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of ValueType`, arg.token);
|
|
4531
4454
|
}
|
|
4532
4455
|
break;
|
|
4533
4456
|
case FunctionExpressionType.LogicalType:
|
|
4534
|
-
if (!(arg instanceof
|
|
4457
|
+
if (!(arg instanceof FilterQuery || arg instanceof InfixExpression)) {
|
|
4535
4458
|
throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of LogicalType`, arg.token);
|
|
4536
4459
|
}
|
|
4537
4460
|
break;
|
|
4538
4461
|
case FunctionExpressionType.NodesType:
|
|
4539
|
-
if (!(arg instanceof
|
|
4462
|
+
if (!(arg instanceof FilterQuery || arg instanceof FunctionExtension && this.functionRegister.get(arg.name)?.returnType === FunctionExpressionType.NodesType)) {
|
|
4540
4463
|
throw new JSONPathTypeError(`${token.value}() argument ${idx} must be of NodesType`, arg.token);
|
|
4541
4464
|
}
|
|
4542
4465
|
}
|
|
@@ -4652,14 +4575,16 @@ var json_p3 = (function (exports) {
|
|
|
4652
4575
|
__proto__: null,
|
|
4653
4576
|
DEFAULT_ENVIRONMENT: DEFAULT_ENVIRONMENT,
|
|
4654
4577
|
FunctionExpressionType: FunctionExpressionType,
|
|
4655
|
-
JSONPath: JSONPath,
|
|
4656
4578
|
JSONPathEnvironment: JSONPathEnvironment,
|
|
4657
4579
|
JSONPathError: JSONPathError,
|
|
4658
4580
|
JSONPathIndexError: JSONPathIndexError,
|
|
4659
4581
|
JSONPathLexerError: JSONPathLexerError,
|
|
4660
4582
|
JSONPathNode: JSONPathNode,
|
|
4661
4583
|
JSONPathNodeList: JSONPathNodeList,
|
|
4584
|
+
JSONPathQuery: JSONPathQuery,
|
|
4662
4585
|
JSONPathRecursionLimitError: JSONPathRecursionLimitError,
|
|
4586
|
+
JSONPathSegment: JSONPathSegment,
|
|
4587
|
+
JSONPathSelector: JSONPathSelector,
|
|
4663
4588
|
JSONPathSyntaxError: JSONPathSyntaxError,
|
|
4664
4589
|
JSONPathTypeError: JSONPathTypeError,
|
|
4665
4590
|
KEY_MARK: KEY_MARK,
|
|
@@ -5163,20 +5088,20 @@ var json_p3 = (function (exports) {
|
|
|
5163
5088
|
apply: apply
|
|
5164
5089
|
});
|
|
5165
5090
|
|
|
5166
|
-
const version = "
|
|
5091
|
+
const version = "2.0.0";
|
|
5167
5092
|
|
|
5168
5093
|
exports.DEFAULT_ENVIRONMENT = DEFAULT_ENVIRONMENT;
|
|
5169
5094
|
exports.FunctionExpressionType = FunctionExpressionType;
|
|
5170
5095
|
exports.JSONPatch = JSONPatch;
|
|
5171
5096
|
exports.JSONPatchError = JSONPatchError;
|
|
5172
5097
|
exports.JSONPatchTestFailure = JSONPatchTestFailure;
|
|
5173
|
-
exports.JSONPath = JSONPath;
|
|
5174
5098
|
exports.JSONPathEnvironment = JSONPathEnvironment;
|
|
5175
5099
|
exports.JSONPathError = JSONPathError;
|
|
5176
5100
|
exports.JSONPathIndexError = JSONPathIndexError;
|
|
5177
5101
|
exports.JSONPathLexerError = JSONPathLexerError;
|
|
5178
5102
|
exports.JSONPathNode = JSONPathNode;
|
|
5179
5103
|
exports.JSONPathNodeList = JSONPathNodeList;
|
|
5104
|
+
exports.JSONPathQuery = JSONPathQuery;
|
|
5180
5105
|
exports.JSONPathRecursionLimitError = JSONPathRecursionLimitError;
|
|
5181
5106
|
exports.JSONPathSyntaxError = JSONPathSyntaxError;
|
|
5182
5107
|
exports.JSONPathTypeError = JSONPathTypeError;
|