@uipath/flow-tool 1.202.0-preview.142 → 1.202.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE.txt +3 -0
  2. package/dist/THIRD-PARTY-NOTICES.md +2099 -0
  3. package/dist/{authoring-tjs34fam.js → authoring-113fk5ep.js} +2 -2
  4. package/dist/{binding-service-e889rb6d.js → binding-service-bptej768.js} +13 -13
  5. package/dist/{connector-service-4n6z4w1r.js → connector-service-69wbcqx4.js} +12 -12
  6. package/dist/{debug-conversation-trigger-a19yp8dp.js → debug-conversation-trigger-s7zmkrwz.js} +4 -4
  7. package/dist/{debug-http-client-5cjdqr0k.js → debug-http-client-mc67gw2b.js} +2 -2
  8. package/dist/{debug-service-t6bfm7jk.js → debug-service-h0mpv9mh.js} +3 -3
  9. package/dist/{edge-service-3349etck.js → edge-service-2b97wf2r.js} +3 -3
  10. package/dist/{flow-api-ek42cqk4.js → flow-api-p6vabmea.js} +6 -6
  11. package/dist/{flow-debug-service-8ng7d5sd.js → flow-debug-service-z52qzmdh.js} +18 -18
  12. package/dist/{flow-eval-node-target-p1fahj96.js → flow-eval-node-target-q6951hcp.js} +3 -3
  13. package/dist/{flow-eval-run-service-trznqdse.js → flow-eval-run-service-2dts1gez.js} +19 -19
  14. package/dist/{flow-eval-service-jv9psj94.js → flow-eval-service-1rwppd84.js} +7 -7
  15. package/dist/{flow-init-service-w1xshby7.js → flow-init-service-wper25ak.js} +6 -6
  16. package/dist/{flow-io-efgx87ec.js → flow-io-y34mx0vh.js} +3 -3
  17. package/dist/{flow-migrate-service-5bam1aya.js → flow-migrate-service-95kd56rw.js} +3 -3
  18. package/dist/{flow-pack-service-kbmja3v4.js → flow-pack-service-4kzv9wvd.js} +17 -17
  19. package/dist/{flow-validate-service-9yzabfmp.js → flow-validate-service-hr2e664c.js} +18 -18
  20. package/dist/{governance-fetcher-7s3g85yb.js → governance-fetcher-kaarfkse.js} +4 -4
  21. package/dist/{hitl-service-a5sv1eee.js → hitl-service-zxtn9rmm.js} +3 -3
  22. package/dist/{index-thwv3pcg.js → index-4y4rvc7g.js} +3 -3
  23. package/dist/{index-cjqrzba9.js → index-rmym7hm4.js} +3 -3
  24. package/dist/{index-fy1vmc9g.js → index-zw4jx227.js} +2 -2
  25. package/dist/index.js +10 -10
  26. package/dist/init.js +6 -6
  27. package/dist/{input-reader-80xf4jrm.js → input-reader-cex1tqwe.js} +1 -1
  28. package/dist/jmespath-e4a59c8w.js +1485 -0
  29. package/dist/{node-service-p0tbekz4.js → node-service-7kdpce7j.js} +13 -13
  30. package/dist/{node-sync-service-pysr441t.js → node-sync-service-dk9jazv4.js} +3 -3
  31. package/dist/{node-2y7pq3ms.js → node-yz5tz1jx.js} +1429 -2021
  32. package/dist/{packager-tool-ydm1tjsh.js → packager-tool-1gasqbew.js} +3 -3
  33. package/dist/{packager-tool-k3eq8swn.js → packager-tool-29vnb5v1.js} +4 -4
  34. package/dist/{packager-tool-3w2pz4tf.js → packager-tool-2f0mt21x.js} +1 -1
  35. package/dist/{packager-tool-fwgpkhay.js → packager-tool-3wzbcn5q.js} +1 -1
  36. package/dist/{packager-tool-gkhcmb6e.js → packager-tool-4tvdvr4h.js} +4 -4
  37. package/dist/{packager-tool-794zb27w.js → packager-tool-77f5xeqw.js} +3 -3
  38. package/dist/{packager-tool-kt916h96.js → packager-tool-7c18ekyp.js} +1 -1
  39. package/dist/{packager-tool-2hxs99bv.js → packager-tool-7gx51wnq.js} +5 -5
  40. package/dist/{packager-tool-vzybe9wb.js → packager-tool-aea5psjw.js} +2 -2
  41. package/dist/{packager-tool-zn18t1zh.js → packager-tool-bhddcaec.js} +2 -2
  42. package/dist/{packager-tool-dhqh1yy8.js → packager-tool-ck10v2ve.js} +1 -1
  43. package/dist/{packager-tool-c2dne8ka.js → packager-tool-cphdcys0.js} +1 -1
  44. package/dist/{packager-tool-ca7excwn.js → packager-tool-dp4c0936.js} +3 -3
  45. package/dist/{packager-tool-s0hezrwp.js → packager-tool-f0tz69yq.js} +67 -67
  46. package/dist/{packager-tool-z4qrzbc8.js → packager-tool-fgdf2zh8.js} +1 -1
  47. package/dist/{packager-tool-hh3nwvn4.js → packager-tool-g4pc6ngd.js} +1 -1
  48. package/dist/{packager-tool-4dzmsst8.js → packager-tool-gaa5ss24.js} +8 -8
  49. package/dist/{packager-tool-y0xbxcfh.js → packager-tool-m056vsmy.js} +2 -2
  50. package/dist/{packager-tool-96ea95w6.js → packager-tool-n09qbckn.js} +3 -3
  51. package/dist/{packager-tool-9pcw7xkk.js → packager-tool-p96yqdnk.js} +1 -1
  52. package/dist/{packager-tool-qp6jave3.js → packager-tool-py7cevyk.js} +1 -1
  53. package/dist/{packager-tool-f3mgexp7.js → packager-tool-rasvyrt4.js} +2 -2
  54. package/dist/{packager-tool-f4gq9c0t.js → packager-tool-rt64yypa.js} +9 -9
  55. package/dist/{packager-tool-7yq68eyw.js → packager-tool-vdajjr2d.js} +3 -3
  56. package/dist/{packager-tool-jqtn78ta.js → packager-tool-wj9bvt17.js} +4 -4
  57. package/dist/{packager-tool-jgxj7mh4.js → packager-tool-yaabg8qc.js} +5 -5
  58. package/dist/packager-tool.js +2 -2
  59. package/dist/{shared-utils-66cgz53a.js → shared-utils-3cwmvxdc.js} +1 -1
  60. package/dist/{tidy-service-9ekcx77n.js → tidy-service-tfkx6266.js} +4 -4
  61. package/dist/tool.js +10 -10
  62. package/dist/validation.js +18 -18
  63. package/dist/{variable-service-830ryas6.js → variable-service-c0qjsy4j.js} +3 -3
  64. package/dist/{wait-for-flow-job-d7dprmz9.js → wait-for-flow-job-4cyc36yg.js} +6 -6
  65. package/package.json +3 -3
  66. package/dist/index-p3vk57z7.js +0 -2058
@@ -5160,2074 +5160,1482 @@ var init_js_yaml = __esm(() => {
5160
5160
  safeDump
5161
5161
  } = yaml);
5162
5162
  });
5163
- var exports_dist = {};
5164
- __export(exports_dist, {
5165
- Scope: () => Scope,
5166
- TYPE_ANY: () => TYPE_ANY,
5167
- TYPE_ARRAY: () => TYPE_ARRAY,
5168
- TYPE_ARRAY_ARRAY: () => TYPE_ARRAY_ARRAY,
5169
- TYPE_ARRAY_NUMBER: () => TYPE_ARRAY_NUMBER,
5170
- TYPE_ARRAY_OBJECT: () => TYPE_ARRAY_OBJECT,
5171
- TYPE_ARRAY_STRING: () => TYPE_ARRAY_STRING,
5172
- TYPE_BOOLEAN: () => TYPE_BOOLEAN,
5173
- TYPE_EXPREF: () => TYPE_EXPREF,
5174
- TYPE_NULL: () => TYPE_NULL,
5175
- TYPE_NUMBER: () => TYPE_NUMBER,
5176
- TYPE_OBJECT: () => TYPE_OBJECT,
5177
- TYPE_STRING: () => TYPE_STRING,
5178
- TreeInterpreter: () => TreeInterpreter2,
5179
- clearCustomFunctions: () => clearCustomFunctions,
5180
- compile: () => compile,
5181
- default: () => jmespath,
5182
- getCustomFunctions: () => getCustomFunctions,
5183
- getRegisteredFunctions: () => getRegisteredFunctions,
5184
- isRegistered: () => isRegistered,
5185
- jmespath: () => jmespath,
5186
- register: () => register,
5187
- registerFunction: () => registerFunction,
5188
- search: () => search,
5189
- tokenize: () => tokenize,
5190
- unregisterFunction: () => unregisterFunction
5191
- });
5192
- function compile(expression, options) {
5193
- const nodeTree = Parser_default.parse(expression, options);
5194
- return nodeTree;
5195
- }
5196
- function tokenize(expression, options) {
5197
- return Lexer_default.tokenize(expression, options);
5198
- }
5199
- function search(data, expression, options) {
5200
- const nodeTree = Parser_default.parse(expression, options);
5201
- return TreeInterpreter_default.search(nodeTree, data);
5202
- }
5203
- function Scope() {
5204
- return new ScopeChain;
5205
- }
5206
- var isObject = (obj) => {
5207
- return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
5208
- };
5209
- var strictDeepEqual = (first, second) => {
5210
- if (first === second) {
5211
- return true;
5212
- }
5213
- if (typeof first !== typeof second) {
5214
- return false;
5215
- }
5216
- if (Array.isArray(first) && Array.isArray(second)) {
5217
- if (first.length !== second.length) {
5218
- return false;
5219
- }
5220
- for (let i = 0;i < first.length; i += 1) {
5221
- if (!strictDeepEqual(first[i], second[i])) {
5222
- return false;
5223
- }
5224
- }
5225
- return true;
5226
- }
5227
- if (isObject(first) && isObject(second)) {
5228
- const firstEntries = Object.entries(first);
5229
- const secondKeys = new Set(Object.keys(second));
5230
- if (firstEntries.length !== secondKeys.size) {
5231
- return false;
5232
- }
5233
- for (const [key, value] of firstEntries) {
5234
- if (!strictDeepEqual(value, second[key])) {
5163
+ var require_jmespath = __commonJS(function(exports) {
5164
+ (function(exports2) {
5165
+ function isArray(obj) {
5166
+ if (obj !== null) {
5167
+ return Object.prototype.toString.call(obj) === "[object Array]";
5168
+ } else {
5235
5169
  return false;
5236
5170
  }
5237
- secondKeys.delete(key);
5238
5171
  }
5239
- return secondKeys.size === 0;
5240
- }
5241
- return false;
5242
- };
5243
- var isFalse = (obj) => {
5244
- if (obj === null || obj === undefined || obj === false) {
5245
- return true;
5246
- }
5247
- if (typeof obj === "string") {
5248
- return obj === "";
5249
- }
5250
- if (typeof obj === "object") {
5251
- if (Array.isArray(obj)) {
5252
- return obj.length === 0;
5253
- }
5254
- if (obj === null) {
5255
- return true;
5256
- }
5257
- return Object.keys(obj).length === 0;
5258
- }
5259
- return false;
5260
- };
5261
- var isAlpha = (ch) => {
5262
- return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
5263
- };
5264
- var isNum = (ch) => {
5265
- return ch >= "0" && ch <= "9" || ch === "-";
5266
- };
5267
- var isAlphaNum = (ch) => {
5268
- return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
5269
- };
5270
- var ensureInteger = (value) => {
5271
- if (!(typeof value === "number") || Math.floor(value) !== value) {
5272
- throw new Error("invalid-value: expecting an integer.");
5273
- }
5274
- return value;
5275
- };
5276
- var ensurePositiveInteger = (value) => {
5277
- if (!(typeof value === "number") || value < 0 || Math.floor(value) !== value) {
5278
- throw new Error("invalid-value: expecting a non-negative integer.");
5279
- }
5280
- return value;
5281
- };
5282
- var ensureNumbers = (...operands) => {
5283
- for (let i = 0;i < operands.length; i++) {
5284
- if (operands[i] === null || operands[i] === undefined) {
5285
- throw new Error("not-a-number: undefined");
5286
- }
5287
- if (typeof operands[i] !== "number") {
5288
- throw new Error("not-a-number");
5289
- }
5290
- }
5291
- };
5292
- var notZero = (n) => {
5293
- n = +n;
5294
- if (!n) {
5295
- throw new Error("not-a-number: divide by zero");
5296
- }
5297
- return n;
5298
- };
5299
- var add = (left, right) => {
5300
- ensureNumbers(left, right);
5301
- const result = left + right;
5302
- return result;
5303
- };
5304
- var sub = (left, right) => {
5305
- ensureNumbers(left, right);
5306
- const result = left - right;
5307
- return result;
5308
- };
5309
- var mul = (left, right) => {
5310
- ensureNumbers(left, right);
5311
- const result = left * right;
5312
- return result;
5313
- };
5314
- var divide = (left, right) => {
5315
- ensureNumbers(left, right);
5316
- const result = left / notZero(right);
5317
- return result;
5318
- };
5319
- var div = (left, right) => {
5320
- ensureNumbers(left, right);
5321
- const result = Math.floor(left / notZero(right));
5322
- return result;
5323
- };
5324
- var mod = (left, right) => {
5325
- ensureNumbers(left, right);
5326
- const result = left % right;
5327
- return result;
5328
- };
5329
- var findFirst = (subject, sub2, start, end) => {
5330
- if (!subject || !sub2) {
5331
- return null;
5332
- }
5333
- start = Math.max(ensureInteger(start = start || 0), 0);
5334
- end = Math.min(ensureInteger(end = end || subject.length), subject.length);
5335
- const offset = subject.slice(start, end).indexOf(sub2);
5336
- return offset === -1 ? null : offset + start;
5337
- };
5338
- var findLast = (subject, sub2, start, end) => {
5339
- if (!subject || !sub2) {
5340
- return null;
5341
- }
5342
- start = Math.max(ensureInteger(start = start || 0), 0);
5343
- end = Math.min(ensureInteger(end = end || subject.length), subject.length);
5344
- const offset = subject.slice(start, end).lastIndexOf(sub2);
5345
- const result = offset === -1 ? null : offset + start;
5346
- return result;
5347
- };
5348
- var lower = (subject) => subject.toLowerCase();
5349
- var ensurePadFuncParams = (name, width, padding) => {
5350
- padding = padding || " ";
5351
- if (padding.length > 1) {
5352
- throw new Error(`invalid value, ${name} expects its 'pad' parameter to be a valid string with a single codepoint`);
5353
- }
5354
- ensurePositiveInteger(width);
5355
- return padding;
5356
- };
5357
- var padLeft = (subject, width, padding) => {
5358
- padding = ensurePadFuncParams("pad_left", width, padding);
5359
- return subject && subject.padStart(width, padding) || "";
5360
- };
5361
- var padRight = (subject, width, padding) => {
5362
- padding = ensurePadFuncParams("pad_right", width, padding);
5363
- return subject && subject.padEnd(width, padding) || "";
5364
- };
5365
- var replace = (subject, string, by, count) => {
5366
- if (count === 0) {
5367
- return subject;
5368
- }
5369
- if (!count) {
5370
- return subject.split(string).join(by);
5371
- }
5372
- ensurePositiveInteger(count);
5373
- [...Array(count).keys()].map(() => subject = subject.replace(string, by));
5374
- return subject;
5375
- };
5376
- var split = (subject, search2, count) => {
5377
- if (subject.length == 0 && search2.length === 0) {
5378
- return [];
5379
- }
5380
- if (count === null || count === undefined) {
5381
- return subject.split(search2);
5382
- }
5383
- ensurePositiveInteger(count);
5384
- if (count === 0) {
5385
- return [subject];
5386
- }
5387
- const split2 = subject.split(search2);
5388
- return [...split2.slice(0, count), split2.slice(count).join(search2)];
5389
- };
5390
- var trim = (subject, chars) => {
5391
- return trimLeft(trimRight(subject, chars), chars);
5392
- };
5393
- var trimLeft = (subject, chars) => {
5394
- return trimImpl(subject, (list) => new RegExp(`^[${list}]*(.*?)`), chars);
5395
- };
5396
- var trimRight = (subject, chars) => {
5397
- return trimImpl(subject, (list) => new RegExp(`(.*?)[${list}]*$`), chars);
5398
- };
5399
- var trimImpl = (subject, regExper, chars) => {
5400
- const pattern = chars ? chars.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") : "\\s…";
5401
- return subject.replace(regExper(pattern), "$1");
5402
- };
5403
- var upper = (subject) => subject.toUpperCase();
5404
- var basicTokens;
5405
- var operatorStartToken;
5406
- var skipChars;
5407
- var StreamLexer = class {
5408
- _current = 0;
5409
- _enable_legacy_literals = false;
5410
- tokenize(stream, options) {
5411
- const tokens = [];
5412
- this._current = 0;
5413
- this._enable_legacy_literals = options?.enable_legacy_literals || false;
5414
- let start;
5415
- let identifier;
5416
- let token;
5417
- while (this._current < stream.length) {
5418
- if (isAlpha(stream[this._current])) {
5419
- start = this._current;
5420
- identifier = this.consumeUnquotedIdentifier(stream);
5421
- tokens.push({
5422
- start,
5423
- type: "UnquotedIdentifier",
5424
- value: identifier
5425
- });
5426
- } else if (basicTokens[stream[this._current]] !== undefined) {
5427
- tokens.push({
5428
- start: this._current,
5429
- type: basicTokens[stream[this._current]],
5430
- value: stream[this._current]
5431
- });
5432
- this._current += 1;
5433
- } else if (stream[this._current] === "$") {
5434
- start = this._current;
5435
- if (this._current + 1 < stream.length && isAlpha(stream[this._current + 1])) {
5436
- this._current += 1;
5437
- identifier = this.consumeUnquotedIdentifier(stream);
5438
- tokens.push({
5439
- start,
5440
- type: "Variable",
5441
- value: identifier
5442
- });
5443
- } else {
5444
- tokens.push({
5445
- start,
5446
- type: "Root",
5447
- value: stream[this._current]
5448
- });
5449
- this._current += 1;
5450
- }
5451
- } else if (stream[this._current] === "-") {
5452
- if (this._current + 1 < stream.length && isNum(stream[this._current + 1])) {
5453
- const token2 = this.consumeNumber(stream);
5454
- token2 && tokens.push(token2);
5455
- } else {
5456
- const token2 = {
5457
- start: this._current,
5458
- type: "Minus",
5459
- value: "-"
5460
- };
5461
- tokens.push(token2);
5462
- this._current += 1;
5463
- }
5464
- } else if (isNum(stream[this._current])) {
5465
- token = this.consumeNumber(stream);
5466
- tokens.push(token);
5467
- } else if (stream[this._current] === "[") {
5468
- token = this.consumeLBracket(stream);
5469
- tokens.push(token);
5470
- } else if (stream[this._current] === '"') {
5471
- start = this._current;
5472
- identifier = this.consumeQuotedIdentifier(stream);
5473
- tokens.push({
5474
- start,
5475
- type: "QuotedIdentifier",
5476
- value: identifier
5477
- });
5478
- } else if (stream[this._current] === `'`) {
5479
- start = this._current;
5480
- identifier = this.consumeRawStringLiteral(stream);
5481
- tokens.push({
5482
- start,
5483
- type: "Literal",
5484
- value: identifier
5485
- });
5486
- } else if (stream[this._current] === "`") {
5487
- start = this._current;
5488
- const literal = this.consumeLiteral(stream);
5489
- tokens.push({
5490
- start,
5491
- type: "Literal",
5492
- value: literal
5493
- });
5494
- } else if (operatorStartToken[stream[this._current]] !== undefined) {
5495
- token = this.consumeOperator(stream);
5496
- token && tokens.push(token);
5497
- } else if (skipChars[stream[this._current]] !== undefined) {
5498
- this._current += 1;
5172
+ function isObject(obj) {
5173
+ if (obj !== null) {
5174
+ return Object.prototype.toString.call(obj) === "[object Object]";
5499
5175
  } else {
5500
- const error = new Error(`Syntax error: unknown character: ${stream[this._current]}`);
5501
- error.name = "LexerError";
5502
- throw error;
5176
+ return false;
5503
5177
  }
5504
5178
  }
5505
- return tokens;
5506
- }
5507
- consumeUnquotedIdentifier(stream) {
5508
- const start = this._current;
5509
- this._current += 1;
5510
- while (this._current < stream.length && isAlphaNum(stream[this._current])) {
5511
- this._current += 1;
5512
- }
5513
- return stream.slice(start, this._current);
5514
- }
5515
- consumeQuotedIdentifier(stream) {
5516
- const start = this._current;
5517
- this._current += 1;
5518
- const maxLength = stream.length;
5519
- while (stream[this._current] !== '"' && this._current < maxLength) {
5520
- let current = this._current;
5521
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
5522
- current += 2;
5523
- } else {
5524
- current += 1;
5179
+ function strictDeepEqual(first, second) {
5180
+ if (first === second) {
5181
+ return true;
5525
5182
  }
5526
- this._current = current;
5527
- }
5528
- this._current += 1;
5529
- const [value, ok] = this.parseJSON(stream.slice(start, this._current));
5530
- if (!ok) {
5531
- const error = new Error(`syntax: unexpected end of JSON input`);
5532
- error.name = "LexerError";
5533
- throw error;
5534
- }
5535
- return value;
5536
- }
5537
- consumeRawStringLiteral(stream) {
5538
- const start = this._current;
5539
- this._current += 1;
5540
- const maxLength = stream.length;
5541
- while (stream[this._current] !== `'` && this._current < maxLength) {
5542
- let current = this._current;
5543
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === `'`)) {
5544
- current += 2;
5545
- } else {
5546
- current += 1;
5547
- }
5548
- this._current = current;
5549
- }
5550
- this._current += 1;
5551
- const literal = stream.slice(start + 1, this._current - 1);
5552
- return replace(replace(literal, `\\\\`, `\\`), `\\'`, `'`);
5553
- }
5554
- consumeNumber(stream) {
5555
- const start = this._current;
5556
- this._current += 1;
5557
- const maxLength = stream.length;
5558
- while (isNum(stream[this._current]) && this._current < maxLength) {
5559
- this._current += 1;
5560
- }
5561
- const value = parseInt(stream.slice(start, this._current), 10);
5562
- return { start, value, type: "Number" };
5563
- }
5564
- consumeLBracket(stream) {
5565
- const start = this._current;
5566
- this._current += 1;
5567
- if (stream[this._current] === "?") {
5568
- this._current += 1;
5569
- return { start, type: "Filter", value: "[?" };
5570
- }
5571
- if (stream[this._current] === "]") {
5572
- this._current += 1;
5573
- return { start, type: "Flatten", value: "[]" };
5574
- }
5575
- return { start, type: "Lbracket", value: "[" };
5576
- }
5577
- consumeOrElse(stream, peek, token, orElse) {
5578
- const start = this._current;
5579
- this._current += 1;
5580
- if (this._current < stream.length && stream[this._current] === peek) {
5581
- this._current += 1;
5582
- return {
5583
- start,
5584
- type: orElse,
5585
- value: stream.slice(start, this._current)
5586
- };
5587
- }
5588
- return { start, type: token, value: stream[start] };
5589
- }
5590
- consumeOperator(stream) {
5591
- const start = this._current;
5592
- const startingChar = stream[start];
5593
- switch (startingChar) {
5594
- case "!":
5595
- return this.consumeOrElse(stream, "=", "Not", "NE");
5596
- case "<":
5597
- return this.consumeOrElse(stream, "=", "LT", "LTE");
5598
- case ">":
5599
- return this.consumeOrElse(stream, "=", "GT", "GTE");
5600
- case "=":
5601
- return this.consumeOrElse(stream, "=", "Assign", "EQ");
5602
- case "&":
5603
- return this.consumeOrElse(stream, "&", "Expref", "And");
5604
- case "|":
5605
- return this.consumeOrElse(stream, "|", "Pipe", "Or");
5606
- case "/":
5607
- return this.consumeOrElse(stream, "/", "Divide", "Div");
5608
- }
5609
- }
5610
- consumeLiteral(stream) {
5611
- this._current += 1;
5612
- const start = this._current;
5613
- const maxLength = stream.length;
5614
- while (stream[this._current] !== "`" && this._current < maxLength) {
5615
- let current = this._current;
5616
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
5617
- current += 2;
5618
- } else {
5619
- current += 1;
5183
+ var firstType = Object.prototype.toString.call(first);
5184
+ if (firstType !== Object.prototype.toString.call(second)) {
5185
+ return false;
5620
5186
  }
5621
- this._current = current;
5622
- }
5623
- let literalString = stream.slice(start, this._current).trimStart();
5624
- literalString = literalString.replace("\\`", "`");
5625
- let literal = null;
5626
- let ok = false;
5627
- if (this.looksLikeJSON(literalString)) {
5628
- [literal, ok] = this.parseJSON(literalString);
5629
- }
5630
- if (!ok && this._enable_legacy_literals) {
5631
- [literal, ok] = this.parseJSON(`"${literalString}"`);
5632
- }
5633
- if (!ok) {
5634
- const error = new Error(`Syntax error: unexpected end of JSON input or invalid format for a JSON literal: ${stream[this._current]}`);
5635
- error.name = "LexerError";
5636
- throw error;
5637
- }
5638
- this._current += 1;
5639
- return literal;
5640
- }
5641
- looksLikeJSON(literalString) {
5642
- const startingChars = '[{"';
5643
- const jsonLiterals = ["true", "false", "null"];
5644
- const numberLooking = "-0123456789";
5645
- if (literalString === "") {
5646
- return false;
5647
- }
5648
- if (startingChars.includes(literalString[0])) {
5649
- return true;
5650
- }
5651
- if (jsonLiterals.includes(literalString)) {
5652
- return true;
5653
- }
5654
- if (numberLooking.includes(literalString[0])) {
5655
- const [_, ok] = this.parseJSON(literalString);
5656
- return ok;
5657
- }
5658
- return false;
5659
- }
5660
- parseJSON(text) {
5661
- try {
5662
- const json2 = JSON.parse(text);
5663
- return [json2, true];
5664
- } catch {
5665
- return [null, false];
5666
- }
5667
- }
5668
- };
5669
- var Lexer;
5670
- var Lexer_default;
5671
- var bindingPower;
5672
- var TokenParser = class _TokenParser {
5673
- index = 0;
5674
- tokens = [];
5675
- parse(expression, options) {
5676
- this.loadTokens(expression, options || { enable_legacy_literals: false });
5677
- this.index = 0;
5678
- const ast = this.expression(0);
5679
- if (this.lookahead(0) !== "EOF") {
5680
- const token = this.lookaheadToken(0);
5681
- this.errorToken(token, `Syntax error: unexpected token type: ${token.type}, value: ${token.value}`);
5682
- }
5683
- return ast;
5684
- }
5685
- loadTokens(expression, options) {
5686
- this.tokens = Lexer_default.tokenize(expression, options);
5687
- this.tokens.push({ type: "EOF", value: "", start: expression.length });
5688
- }
5689
- expression(rbp) {
5690
- const leftToken = this.lookaheadToken(0);
5691
- this.advance();
5692
- let left = this.nud(leftToken);
5693
- let currentTokenType = this.lookahead(0);
5694
- while (rbp < bindingPower[currentTokenType]) {
5695
- this.advance();
5696
- left = this.led(currentTokenType, left);
5697
- currentTokenType = this.lookahead(0);
5698
- }
5699
- return left;
5700
- }
5701
- lookahead(offset) {
5702
- return this.tokens[this.index + offset].type;
5703
- }
5704
- lookaheadToken(offset) {
5705
- return this.tokens[this.index + offset];
5706
- }
5707
- advance() {
5708
- this.index += 1;
5709
- }
5710
- nud(token) {
5711
- switch (token.type) {
5712
- case "Variable":
5713
- return { type: "Variable", name: token.value };
5714
- case "Literal":
5715
- return { type: "Literal", value: token.value };
5716
- case "UnquotedIdentifier": {
5717
- if (_TokenParser.isKeyword(token, "let") && this.lookahead(0) === "Variable") {
5718
- return this.parseLetExpression();
5719
- } else {
5720
- return { type: "Field", name: token.value };
5187
+ if (isArray(first) === true) {
5188
+ if (first.length !== second.length) {
5189
+ return false;
5721
5190
  }
5722
- }
5723
- case "QuotedIdentifier":
5724
- if (this.lookahead(0) === "Lparen") {
5725
- throw new Error("Syntax error: quoted identifier not allowed for function names.");
5726
- } else {
5727
- return { type: "Field", name: token.value };
5191
+ for (var i = 0;i < first.length; i++) {
5192
+ if (strictDeepEqual(first[i], second[i]) === false) {
5193
+ return false;
5194
+ }
5728
5195
  }
5729
- case "Not": {
5730
- const child = this.expression(bindingPower.Not);
5731
- return { type: "NotExpression", child };
5732
- }
5733
- case "Minus": {
5734
- const child = this.expression(bindingPower.Minus);
5735
- return {
5736
- type: "Unary",
5737
- operator: token.type,
5738
- operand: child
5739
- };
5740
- }
5741
- case "Plus": {
5742
- const child = this.expression(bindingPower.Plus);
5743
- return {
5744
- type: "Unary",
5745
- operator: token.type,
5746
- operand: child
5747
- };
5196
+ return true;
5748
5197
  }
5749
- case "Star": {
5750
- const left = { type: "Identity" };
5751
- return { type: "ValueProjection", left, right: this.parseProjectionRHS(bindingPower.Star) };
5752
- }
5753
- case "Filter":
5754
- return this.led(token.type, { type: "Identity" });
5755
- case "Lbrace":
5756
- return this.parseMultiselectHash();
5757
- case "Flatten": {
5758
- const left = {
5759
- type: "Flatten",
5760
- child: { type: "Identity" }
5761
- };
5762
- const right = this.parseProjectionRHS(bindingPower.Flatten);
5763
- return { type: "Projection", left, right };
5764
- }
5765
- case "Lbracket": {
5766
- if (this.lookahead(0) === "Number" || this.lookahead(0) === "Colon") {
5767
- const right = this.parseIndexExpression();
5768
- return this.projectIfSlice({ type: "Identity" }, right);
5769
- }
5770
- if (this.lookahead(0) === "Star" && this.lookahead(1) === "Rbracket") {
5771
- this.advance();
5772
- this.advance();
5773
- const right = this.parseProjectionRHS(bindingPower.Star);
5774
- return {
5775
- left: { type: "Identity" },
5776
- right,
5777
- type: "Projection"
5778
- };
5198
+ if (isObject(first) === true) {
5199
+ var keysSeen = {};
5200
+ for (var key in first) {
5201
+ if (hasOwnProperty.call(first, key)) {
5202
+ if (strictDeepEqual(first[key], second[key]) === false) {
5203
+ return false;
5204
+ }
5205
+ keysSeen[key] = true;
5206
+ }
5779
5207
  }
5780
- return this.parseMultiselectList();
5781
- }
5782
- case "Current":
5783
- return { type: "Current" };
5784
- case "Root":
5785
- return { type: "Root" };
5786
- case "Expref": {
5787
- const child = this.expression(bindingPower.Expref);
5788
- return { type: "ExpressionReference", child };
5208
+ for (var key2 in second) {
5209
+ if (hasOwnProperty.call(second, key2)) {
5210
+ if (keysSeen[key2] !== true) {
5211
+ return false;
5212
+ }
5213
+ }
5214
+ }
5215
+ return true;
5789
5216
  }
5790
- case "Lparen": {
5791
- const expression = this.expression(0);
5792
- this.match("Rparen");
5793
- return expression;
5217
+ return false;
5218
+ }
5219
+ function isFalse(obj) {
5220
+ if (obj === "" || obj === false || obj === null) {
5221
+ return true;
5222
+ } else if (isArray(obj) && obj.length === 0) {
5223
+ return true;
5224
+ } else if (isObject(obj)) {
5225
+ for (var key in obj) {
5226
+ if (obj.hasOwnProperty(key)) {
5227
+ return false;
5228
+ }
5229
+ }
5230
+ return true;
5231
+ } else {
5232
+ return false;
5794
5233
  }
5795
- default:
5796
- this.errorToken(token);
5797
5234
  }
5798
- }
5799
- led(tokenName, left) {
5800
- switch (tokenName) {
5801
- case "Question": {
5802
- const trueExpr = this.expression(0);
5803
- this.match("Colon");
5804
- const falseExpr = this.expression(0);
5805
- return {
5806
- type: "Ternary",
5807
- condition: left,
5808
- trueExpr,
5809
- falseExpr
5810
- };
5235
+ function objValues(obj) {
5236
+ var keys = Object.keys(obj);
5237
+ var values = [];
5238
+ for (var i = 0;i < keys.length; i++) {
5239
+ values.push(obj[keys[i]]);
5811
5240
  }
5812
- case "Dot": {
5813
- const rbp = bindingPower.Dot;
5814
- if (this.lookahead(0) !== "Star") {
5815
- const right2 = this.parseDotRHS(rbp);
5816
- return { type: "Subexpression", left, right: right2 };
5817
- }
5818
- this.advance();
5819
- const right = this.parseProjectionRHS(rbp);
5820
- return { type: "ValueProjection", left, right };
5821
- }
5822
- case "Pipe": {
5823
- const right = this.expression(bindingPower.Pipe);
5824
- return { type: "Pipe", left, right };
5825
- }
5826
- case "Or": {
5827
- const right = this.expression(bindingPower.Or);
5828
- return { type: "OrExpression", left, right };
5829
- }
5830
- case "And": {
5831
- const right = this.expression(bindingPower.And);
5832
- return { type: "AndExpression", left, right };
5833
- }
5834
- case "Lparen": {
5835
- if (left.type !== "Field") {
5836
- throw new Error("Syntax error: expected a Field node");
5837
- }
5838
- const name = left.name;
5839
- const args = this.parseCommaSeparatedExpressionsUntilToken("Rparen");
5840
- const node = { name, type: "Function", children: args };
5841
- return node;
5842
- }
5843
- case "Filter": {
5844
- const condition = this.expression(0);
5845
- this.match("Rbracket");
5846
- const right = this.lookahead(0) === "Flatten" ? { type: "Identity" } : this.parseProjectionRHS(bindingPower.Filter);
5847
- return { type: "FilterProjection", left, right, condition };
5848
- }
5849
- case "Flatten": {
5850
- const leftNode = { type: "Flatten", child: left };
5851
- const right = this.parseProjectionRHS(bindingPower.Flatten);
5852
- return { type: "Projection", left: leftNode, right };
5853
- }
5854
- case "Assign": {
5855
- const leftNode = left;
5856
- const right = this.expression(0);
5857
- return {
5858
- type: "Binding",
5859
- variable: leftNode.name,
5860
- reference: right
5861
- };
5241
+ return values;
5242
+ }
5243
+ function merge2(a, b) {
5244
+ var merged = {};
5245
+ for (var key in a) {
5246
+ merged[key] = a[key];
5862
5247
  }
5863
- case "EQ":
5864
- case "NE":
5865
- case "GT":
5866
- case "GTE":
5867
- case "LT":
5868
- case "LTE":
5869
- return this.parseComparator(left, tokenName);
5870
- case "Plus":
5871
- case "Minus":
5872
- case "Multiply":
5873
- case "Star":
5874
- case "Divide":
5875
- case "Modulo":
5876
- case "Div":
5877
- return this.parseArithmetic(left, tokenName);
5878
- case "Lbracket": {
5879
- const token = this.lookaheadToken(0);
5880
- if (token.type === "Number" || token.type === "Colon") {
5881
- const right2 = this.parseIndexExpression();
5882
- return this.projectIfSlice(left, right2);
5883
- }
5884
- this.match("Star");
5885
- this.match("Rbracket");
5886
- const right = this.parseProjectionRHS(bindingPower.Star);
5887
- return { type: "Projection", left, right };
5248
+ for (var key2 in b) {
5249
+ merged[key2] = b[key2];
5888
5250
  }
5889
- default:
5890
- return this.errorToken(this.lookaheadToken(0));
5251
+ return merged;
5891
5252
  }
5892
- }
5893
- static isKeyword(token, keyword) {
5894
- return token.type === "UnquotedIdentifier" && token.value === keyword;
5895
- }
5896
- match(tokenType) {
5897
- if (this.lookahead(0) === tokenType) {
5898
- this.advance();
5899
- return;
5253
+ var trimLeft;
5254
+ if (typeof String.prototype.trimLeft === "function") {
5255
+ trimLeft = function(str2) {
5256
+ return str2.trimLeft();
5257
+ };
5900
5258
  } else {
5901
- const token = this.lookaheadToken(0);
5902
- this.errorToken(token, `Syntax error: expected ${tokenType}, got: ${token.type}`);
5903
- }
5904
- }
5905
- errorToken(token, message = "") {
5906
- const error = new Error(message || `Syntax error: invalid token (${token.type}): "${token.value}"`);
5907
- error.name = "ParserError";
5908
- throw error;
5909
- }
5910
- parseIndexExpression() {
5911
- if (this.lookahead(0) === "Colon" || this.lookahead(1) === "Colon") {
5912
- return this.parseSliceExpression();
5913
- }
5914
- const value = Number(this.lookaheadToken(0).value);
5915
- this.advance();
5916
- this.match("Rbracket");
5917
- return { type: "Index", value };
5918
- }
5919
- projectIfSlice(left, right) {
5920
- const indexExpr = {
5921
- type: "IndexExpression",
5922
- left,
5923
- right
5924
- };
5925
- if (right.type === "Slice") {
5926
- return {
5927
- left: indexExpr,
5928
- right: this.parseProjectionRHS(bindingPower.Star),
5929
- type: "Projection"
5259
+ trimLeft = function(str2) {
5260
+ return str2.match(/^\s*(.*)/)[1];
5930
5261
  };
5931
5262
  }
5932
- return indexExpr;
5933
- }
5934
- parseSliceExpression() {
5935
- const parts = [null, null, null];
5936
- let index = 0;
5937
- let current = this.lookaheadToken(0);
5938
- while (current.type != "Rbracket" && index < 3) {
5939
- if (current.type === "Colon") {
5940
- index++;
5941
- if (index === 3) {
5942
- this.errorToken(this.lookaheadToken(0), "Syntax error, too many colons in slice expression");
5943
- }
5944
- this.advance();
5945
- } else if (current.type === "Number") {
5946
- const part = this.lookaheadToken(0).value;
5947
- parts[index] = part;
5948
- this.advance();
5949
- } else {
5950
- const next = this.lookaheadToken(0);
5951
- this.errorToken(next, `Syntax error, unexpected token: ${next.value}(${next.type})`);
5952
- }
5953
- current = this.lookaheadToken(0);
5954
- }
5955
- this.match("Rbracket");
5956
- const [start, stop, step] = parts;
5957
- return { type: "Slice", start, stop, step };
5958
- }
5959
- parseLetExpression() {
5960
- const separated = this.parseCommaSeparatedExpressionsUntilKeyword("in");
5961
- const expression = this.expression(0);
5962
- const bindings = separated.map((binding) => binding);
5963
- return {
5964
- type: "LetExpression",
5965
- bindings,
5966
- expression
5263
+ var TYPE_NUMBER = 0;
5264
+ var TYPE_ANY = 1;
5265
+ var TYPE_STRING = 2;
5266
+ var TYPE_ARRAY = 3;
5267
+ var TYPE_OBJECT = 4;
5268
+ var TYPE_BOOLEAN = 5;
5269
+ var TYPE_EXPREF = 6;
5270
+ var TYPE_NULL = 7;
5271
+ var TYPE_ARRAY_NUMBER = 8;
5272
+ var TYPE_ARRAY_STRING = 9;
5273
+ var TYPE_NAME_TABLE = {
5274
+ 0: "number",
5275
+ 1: "any",
5276
+ 2: "string",
5277
+ 3: "array",
5278
+ 4: "object",
5279
+ 5: "boolean",
5280
+ 6: "expression",
5281
+ 7: "null",
5282
+ 8: "Array<number>",
5283
+ 9: "Array<string>"
5967
5284
  };
5968
- }
5969
- parseCommaSeparatedExpressionsUntilKeyword(keyword) {
5970
- return this.parseCommaSeparatedExpressionsUntil(() => {
5971
- return _TokenParser.isKeyword(this.lookaheadToken(0), keyword);
5972
- }, () => {
5973
- this.advance();
5974
- });
5975
- }
5976
- parseCommaSeparatedExpressionsUntilToken(token) {
5977
- return this.parseCommaSeparatedExpressionsUntil(() => {
5978
- return this.lookahead(0) === token;
5979
- }, () => {
5980
- return this.match(token);
5981
- });
5982
- }
5983
- parseCommaSeparatedExpressionsUntil(isEndToken, matchEndToken) {
5984
- const args = [];
5985
- let expression;
5986
- while (!isEndToken()) {
5987
- expression = this.expression(0);
5988
- if (this.lookahead(0) === "Comma") {
5989
- this.match("Comma");
5990
- }
5991
- args.push(expression);
5992
- }
5993
- matchEndToken();
5994
- return args;
5995
- }
5996
- parseComparator(left, comparator) {
5997
- const right = this.expression(bindingPower[comparator]);
5998
- return { type: "Comparator", name: comparator, left, right };
5999
- }
6000
- parseArithmetic(left, operator) {
6001
- const right = this.expression(bindingPower[operator]);
6002
- return { type: "Arithmetic", operator, left, right };
6003
- }
6004
- parseDotRHS(rbp) {
6005
- const lookahead = this.lookahead(0);
6006
- const exprTokens = ["UnquotedIdentifier", "QuotedIdentifier", "Star"];
6007
- if (exprTokens.includes(lookahead)) {
6008
- return this.expression(rbp);
6009
- }
6010
- if (lookahead === "Lbracket") {
6011
- this.match("Lbracket");
6012
- return this.parseMultiselectList();
6013
- }
6014
- if (lookahead === "Lbrace") {
6015
- this.match("Lbrace");
6016
- return this.parseMultiselectHash();
6017
- }
6018
- const token = this.lookaheadToken(0);
6019
- this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
6020
- }
6021
- parseProjectionRHS(rbp) {
6022
- if (bindingPower[this.lookahead(0)] < 10) {
6023
- return { type: "Identity" };
6024
- }
6025
- if (this.lookahead(0) === "Lbracket") {
6026
- return this.expression(rbp);
6027
- }
6028
- if (this.lookahead(0) === "Filter") {
6029
- return this.expression(rbp);
6030
- }
6031
- if (this.lookahead(0) === "Dot") {
6032
- this.match("Dot");
6033
- return this.parseDotRHS(rbp);
6034
- }
6035
- const token = this.lookaheadToken(0);
6036
- this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
6037
- }
6038
- parseMultiselectList() {
6039
- const expressions = [];
6040
- while (this.lookahead(0) !== "Rbracket") {
6041
- const expression = this.expression(0);
6042
- expressions.push(expression);
6043
- if (this.lookahead(0) === "Comma") {
6044
- this.match("Comma");
6045
- if (this.lookahead(0) === "Rbracket") {
6046
- throw new Error("Syntax error: unexpected token Rbracket");
6047
- }
6048
- }
6049
- }
6050
- this.match("Rbracket");
6051
- return { type: "MultiSelectList", children: expressions };
6052
- }
6053
- parseMultiselectHash() {
6054
- const pairs2 = [];
6055
- const identifierTypes = ["UnquotedIdentifier", "QuotedIdentifier"];
6056
- let keyToken;
6057
- let keyName;
6058
- let value;
6059
- for (;; ) {
6060
- keyToken = this.lookaheadToken(0);
6061
- if (!identifierTypes.includes(keyToken.type)) {
6062
- throw new Error(`Syntax error: expecting an identifier token, got: ${keyToken.type}`);
6063
- }
6064
- keyName = keyToken.value;
6065
- this.advance();
6066
- this.match("Colon");
6067
- value = this.expression(0);
6068
- pairs2.push({ value, type: "KeyValuePair", name: keyName });
6069
- if (this.lookahead(0) === "Comma") {
6070
- this.match("Comma");
6071
- } else if (this.lookahead(0) === "Rbrace") {
6072
- this.match("Rbrace");
6073
- break;
6074
- }
6075
- }
6076
- return { type: "MultiSelectHash", children: pairs2 };
6077
- }
6078
- };
6079
- var Parser;
6080
- var Parser_default;
6081
- var Text = class _Text {
6082
- _text;
6083
- constructor(text) {
6084
- this._text = text;
6085
- }
6086
- get string() {
6087
- return this._text;
6088
- }
6089
- get length() {
6090
- return this.codePoints.length;
6091
- }
6092
- compareTo(other) {
6093
- return _Text.compare(this, new _Text(other));
6094
- }
6095
- static get comparer() {
6096
- const stringComparer = (left, right) => {
6097
- return new _Text(left).compareTo(right);
5285
+ var TOK_EOF = "EOF";
5286
+ var TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier";
5287
+ var TOK_QUOTEDIDENTIFIER = "QuotedIdentifier";
5288
+ var TOK_RBRACKET = "Rbracket";
5289
+ var TOK_RPAREN = "Rparen";
5290
+ var TOK_COMMA = "Comma";
5291
+ var TOK_COLON = "Colon";
5292
+ var TOK_RBRACE = "Rbrace";
5293
+ var TOK_NUMBER = "Number";
5294
+ var TOK_CURRENT = "Current";
5295
+ var TOK_EXPREF = "Expref";
5296
+ var TOK_PIPE = "Pipe";
5297
+ var TOK_OR = "Or";
5298
+ var TOK_AND = "And";
5299
+ var TOK_EQ = "EQ";
5300
+ var TOK_GT = "GT";
5301
+ var TOK_LT = "LT";
5302
+ var TOK_GTE = "GTE";
5303
+ var TOK_LTE = "LTE";
5304
+ var TOK_NE = "NE";
5305
+ var TOK_FLATTEN = "Flatten";
5306
+ var TOK_STAR = "Star";
5307
+ var TOK_FILTER = "Filter";
5308
+ var TOK_DOT = "Dot";
5309
+ var TOK_NOT = "Not";
5310
+ var TOK_LBRACE = "Lbrace";
5311
+ var TOK_LBRACKET = "Lbracket";
5312
+ var TOK_LPAREN = "Lparen";
5313
+ var TOK_LITERAL = "Literal";
5314
+ var basicTokens = {
5315
+ ".": TOK_DOT,
5316
+ "*": TOK_STAR,
5317
+ ",": TOK_COMMA,
5318
+ ":": TOK_COLON,
5319
+ "{": TOK_LBRACE,
5320
+ "}": TOK_RBRACE,
5321
+ "]": TOK_RBRACKET,
5322
+ "(": TOK_LPAREN,
5323
+ ")": TOK_RPAREN,
5324
+ "@": TOK_CURRENT
6098
5325
  };
6099
- return stringComparer;
6100
- }
6101
- static compare(left, right) {
6102
- const leftCp = left.codePoints;
6103
- const rightCp = right.codePoints;
6104
- for (let index = 0;index < Math.min(leftCp.length, rightCp.length); index++) {
6105
- if (leftCp[index] === rightCp[index]) {
6106
- continue;
6107
- }
6108
- return leftCp[index] - rightCp[index] > 0 ? 1 : -1;
6109
- }
6110
- return leftCp.length - rightCp.length > 0 ? 1 : -1;
6111
- }
6112
- reverse() {
6113
- return String.fromCodePoint(...this.codePoints.reverse());
6114
- }
6115
- get codePoints() {
6116
- const array = [...this._text].map((s) => s.codePointAt(0));
6117
- return array;
6118
- }
6119
- };
6120
- var createMathFunction = (mathFn) => ([value]) => mathFn(value);
6121
- var createStringFunction = (stringFn) => ([subject]) => stringFn(subject);
6122
- var createObjectFunction = (objFn) => ([obj]) => objFn(obj);
6123
- var Runtime = class {
6124
- _interpreter;
6125
- _functionTable;
6126
- _customFunctions = /* @__PURE__ */ new Set;
6127
- TYPE_NAME_TABLE = Object.freeze({
6128
- [0]: "number",
6129
- [1]: "any",
6130
- [2]: "string",
6131
- [3]: "array",
6132
- [4]: "object",
6133
- [5]: "boolean",
6134
- [6]: "expression",
6135
- [7]: "null",
6136
- [8]: "Array<number>",
6137
- [10]: "Array<object>",
6138
- [9]: "Array<string>",
6139
- [11]: "Array<Array<any>>"
6140
- });
6141
- constructor(interpreter) {
6142
- this._interpreter = interpreter;
6143
- this._functionTable = this.buildFunctionTable();
6144
- }
6145
- buildFunctionTable() {
6146
- return {
6147
- abs: { _func: createMathFunction(Math.abs), _signature: [{ types: [0] }] },
6148
- ceil: { _func: createMathFunction(Math.ceil), _signature: [{ types: [0] }] },
6149
- floor: { _func: createMathFunction(Math.floor), _signature: [{ types: [0] }] },
6150
- lower: { _func: createStringFunction(lower), _signature: [{ types: [2] }] },
6151
- upper: { _func: createStringFunction(upper), _signature: [{ types: [2] }] },
6152
- keys: { _func: createObjectFunction(Object.keys), _signature: [{ types: [4] }] },
6153
- values: { _func: createObjectFunction(Object.values), _signature: [{ types: [4] }] },
6154
- avg: { _func: this.functionAvg, _signature: [{ types: [8] }] },
6155
- contains: {
6156
- _func: this.functionContains,
6157
- _signature: [
6158
- { types: [2, 3] },
6159
- { types: [1] }
6160
- ]
6161
- },
6162
- ends_with: {
6163
- _func: this.functionEndsWith,
6164
- _signature: [{ types: [2] }, { types: [2] }]
6165
- },
6166
- find_first: {
6167
- _func: this.functionFindFirst,
6168
- _signature: [
6169
- { types: [2] },
6170
- { types: [2] },
6171
- { types: [0], optional: true },
6172
- { types: [0], optional: true }
6173
- ]
6174
- },
6175
- find_last: {
6176
- _func: this.functionFindLast,
6177
- _signature: [
6178
- { types: [2] },
6179
- { types: [2] },
6180
- { types: [0], optional: true },
6181
- { types: [0], optional: true }
6182
- ]
6183
- },
6184
- from_items: { _func: this.functionFromItems, _signature: [{ types: [11] }] },
6185
- group_by: {
6186
- _func: this.functionGroupBy,
6187
- _signature: [{ types: [3] }, { types: [6] }]
6188
- },
6189
- items: { _func: this.functionItems, _signature: [{ types: [4] }] },
6190
- join: {
6191
- _func: this.functionJoin,
6192
- _signature: [{ types: [2] }, { types: [9] }]
6193
- },
6194
- length: {
6195
- _func: this.functionLength,
6196
- _signature: [{ types: [2, 3, 4] }]
6197
- },
6198
- map: {
6199
- _func: this.functionMap,
6200
- _signature: [{ types: [6] }, { types: [3] }]
6201
- },
6202
- max: {
6203
- _func: this.functionMax,
6204
- _signature: [{ types: [8, 9] }]
6205
- },
6206
- max_by: {
6207
- _func: this.functionMaxBy,
6208
- _signature: [{ types: [3] }, { types: [6] }]
6209
- },
6210
- merge: { _func: this.functionMerge, _signature: [{ types: [4], variadic: true }] },
6211
- min: {
6212
- _func: this.functionMin,
6213
- _signature: [{ types: [8, 9] }]
6214
- },
6215
- min_by: {
6216
- _func: this.functionMinBy,
6217
- _signature: [{ types: [3] }, { types: [6] }]
6218
- },
6219
- not_null: { _func: this.functionNotNull, _signature: [{ types: [1], variadic: true }] },
6220
- pad_left: {
6221
- _func: this.functionPadLeft,
6222
- _signature: [
6223
- { types: [2] },
6224
- { types: [0] },
6225
- { types: [2], optional: true }
6226
- ]
6227
- },
6228
- pad_right: {
6229
- _func: this.functionPadRight,
6230
- _signature: [
6231
- { types: [2] },
6232
- { types: [0] },
6233
- { types: [2], optional: true }
6234
- ]
6235
- },
6236
- replace: {
6237
- _func: this.functionReplace,
6238
- _signature: [
6239
- { types: [2] },
6240
- { types: [2] },
6241
- { types: [2] },
6242
- { types: [0], optional: true }
6243
- ]
6244
- },
6245
- reverse: {
6246
- _func: this.functionReverse,
6247
- _signature: [{ types: [2, 3] }]
6248
- },
6249
- sort: {
6250
- _func: this.functionSort,
6251
- _signature: [{ types: [9, 8] }]
5326
+ var operatorStartToken = {
5327
+ "<": true,
5328
+ ">": true,
5329
+ "=": true,
5330
+ "!": true
5331
+ };
5332
+ var skipChars = {
5333
+ " ": true,
5334
+ "\t": true,
5335
+ "\n": true
5336
+ };
5337
+ function isAlpha(ch) {
5338
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
5339
+ }
5340
+ function isNum(ch) {
5341
+ return ch >= "0" && ch <= "9" || ch === "-";
5342
+ }
5343
+ function isAlphaNum(ch) {
5344
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
5345
+ }
5346
+ function Lexer() {}
5347
+ Lexer.prototype = {
5348
+ tokenize: function(stream) {
5349
+ var tokens = [];
5350
+ this._current = 0;
5351
+ var start;
5352
+ var identifier;
5353
+ var token;
5354
+ while (this._current < stream.length) {
5355
+ if (isAlpha(stream[this._current])) {
5356
+ start = this._current;
5357
+ identifier = this._consumeUnquotedIdentifier(stream);
5358
+ tokens.push({
5359
+ type: TOK_UNQUOTEDIDENTIFIER,
5360
+ value: identifier,
5361
+ start
5362
+ });
5363
+ } else if (basicTokens[stream[this._current]] !== undefined) {
5364
+ tokens.push({
5365
+ type: basicTokens[stream[this._current]],
5366
+ value: stream[this._current],
5367
+ start: this._current
5368
+ });
5369
+ this._current++;
5370
+ } else if (isNum(stream[this._current])) {
5371
+ token = this._consumeNumber(stream);
5372
+ tokens.push(token);
5373
+ } else if (stream[this._current] === "[") {
5374
+ token = this._consumeLBracket(stream);
5375
+ tokens.push(token);
5376
+ } else if (stream[this._current] === '"') {
5377
+ start = this._current;
5378
+ identifier = this._consumeQuotedIdentifier(stream);
5379
+ tokens.push({
5380
+ type: TOK_QUOTEDIDENTIFIER,
5381
+ value: identifier,
5382
+ start
5383
+ });
5384
+ } else if (stream[this._current] === "'") {
5385
+ start = this._current;
5386
+ identifier = this._consumeRawStringLiteral(stream);
5387
+ tokens.push({
5388
+ type: TOK_LITERAL,
5389
+ value: identifier,
5390
+ start
5391
+ });
5392
+ } else if (stream[this._current] === "`") {
5393
+ start = this._current;
5394
+ var literal = this._consumeLiteral(stream);
5395
+ tokens.push({
5396
+ type: TOK_LITERAL,
5397
+ value: literal,
5398
+ start
5399
+ });
5400
+ } else if (operatorStartToken[stream[this._current]] !== undefined) {
5401
+ tokens.push(this._consumeOperator(stream));
5402
+ } else if (skipChars[stream[this._current]] !== undefined) {
5403
+ this._current++;
5404
+ } else if (stream[this._current] === "&") {
5405
+ start = this._current;
5406
+ this._current++;
5407
+ if (stream[this._current] === "&") {
5408
+ this._current++;
5409
+ tokens.push({ type: TOK_AND, value: "&&", start });
5410
+ } else {
5411
+ tokens.push({ type: TOK_EXPREF, value: "&", start });
5412
+ }
5413
+ } else if (stream[this._current] === "|") {
5414
+ start = this._current;
5415
+ this._current++;
5416
+ if (stream[this._current] === "|") {
5417
+ this._current++;
5418
+ tokens.push({ type: TOK_OR, value: "||", start });
5419
+ } else {
5420
+ tokens.push({ type: TOK_PIPE, value: "|", start });
5421
+ }
5422
+ } else {
5423
+ var error = new Error("Unknown character:" + stream[this._current]);
5424
+ error.name = "LexerError";
5425
+ throw error;
5426
+ }
5427
+ }
5428
+ return tokens;
6252
5429
  },
6253
- sort_by: {
6254
- _func: this.functionSortBy,
6255
- _signature: [{ types: [3] }, { types: [6] }]
5430
+ _consumeUnquotedIdentifier: function(stream) {
5431
+ var start = this._current;
5432
+ this._current++;
5433
+ while (this._current < stream.length && isAlphaNum(stream[this._current])) {
5434
+ this._current++;
5435
+ }
5436
+ return stream.slice(start, this._current);
6256
5437
  },
6257
- split: {
6258
- _func: this.functionSplit,
6259
- _signature: [
6260
- { types: [2] },
6261
- { types: [2] },
6262
- { types: [0], optional: true }
6263
- ]
5438
+ _consumeQuotedIdentifier: function(stream) {
5439
+ var start = this._current;
5440
+ this._current++;
5441
+ var maxLength = stream.length;
5442
+ while (stream[this._current] !== '"' && this._current < maxLength) {
5443
+ var current = this._current;
5444
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
5445
+ current += 2;
5446
+ } else {
5447
+ current++;
5448
+ }
5449
+ this._current = current;
5450
+ }
5451
+ this._current++;
5452
+ return JSON.parse(stream.slice(start, this._current));
6264
5453
  },
6265
- starts_with: {
6266
- _func: this.functionStartsWith,
6267
- _signature: [{ types: [2] }, { types: [2] }]
5454
+ _consumeRawStringLiteral: function(stream) {
5455
+ var start = this._current;
5456
+ this._current++;
5457
+ var maxLength = stream.length;
5458
+ while (stream[this._current] !== "'" && this._current < maxLength) {
5459
+ var current = this._current;
5460
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "'")) {
5461
+ current += 2;
5462
+ } else {
5463
+ current++;
5464
+ }
5465
+ this._current = current;
5466
+ }
5467
+ this._current++;
5468
+ var literal = stream.slice(start + 1, this._current - 1);
5469
+ return literal.replace("\\'", "'");
6268
5470
  },
6269
- sum: { _func: this.functionSum, _signature: [{ types: [8] }] },
6270
- to_array: { _func: this.functionToArray, _signature: [{ types: [1] }] },
6271
- to_number: { _func: this.functionToNumber, _signature: [{ types: [1] }] },
6272
- to_string: { _func: this.functionToString, _signature: [{ types: [1] }] },
6273
- trim: {
6274
- _func: this.functionTrim,
6275
- _signature: [{ types: [2] }, { types: [2], optional: true }]
5471
+ _consumeNumber: function(stream) {
5472
+ var start = this._current;
5473
+ this._current++;
5474
+ var maxLength = stream.length;
5475
+ while (isNum(stream[this._current]) && this._current < maxLength) {
5476
+ this._current++;
5477
+ }
5478
+ var value = parseInt(stream.slice(start, this._current));
5479
+ return { type: TOK_NUMBER, value, start };
6276
5480
  },
6277
- trim_left: {
6278
- _func: this.functionTrimLeft,
6279
- _signature: [{ types: [2] }, { types: [2], optional: true }]
5481
+ _consumeLBracket: function(stream) {
5482
+ var start = this._current;
5483
+ this._current++;
5484
+ if (stream[this._current] === "?") {
5485
+ this._current++;
5486
+ return { type: TOK_FILTER, value: "[?", start };
5487
+ } else if (stream[this._current] === "]") {
5488
+ this._current++;
5489
+ return { type: TOK_FLATTEN, value: "[]", start };
5490
+ } else {
5491
+ return { type: TOK_LBRACKET, value: "[", start };
5492
+ }
6280
5493
  },
6281
- trim_right: {
6282
- _func: this.functionTrimRight,
6283
- _signature: [{ types: [2] }, { types: [2], optional: true }]
5494
+ _consumeOperator: function(stream) {
5495
+ var start = this._current;
5496
+ var startingChar = stream[start];
5497
+ this._current++;
5498
+ if (startingChar === "!") {
5499
+ if (stream[this._current] === "=") {
5500
+ this._current++;
5501
+ return { type: TOK_NE, value: "!=", start };
5502
+ } else {
5503
+ return { type: TOK_NOT, value: "!", start };
5504
+ }
5505
+ } else if (startingChar === "<") {
5506
+ if (stream[this._current] === "=") {
5507
+ this._current++;
5508
+ return { type: TOK_LTE, value: "<=", start };
5509
+ } else {
5510
+ return { type: TOK_LT, value: "<", start };
5511
+ }
5512
+ } else if (startingChar === ">") {
5513
+ if (stream[this._current] === "=") {
5514
+ this._current++;
5515
+ return { type: TOK_GTE, value: ">=", start };
5516
+ } else {
5517
+ return { type: TOK_GT, value: ">", start };
5518
+ }
5519
+ } else if (startingChar === "=") {
5520
+ if (stream[this._current] === "=") {
5521
+ this._current++;
5522
+ return { type: TOK_EQ, value: "==", start };
5523
+ }
5524
+ }
6284
5525
  },
6285
- type: { _func: this.functionType, _signature: [{ types: [1] }] },
6286
- zip: { _func: this.functionZip, _signature: [{ types: [3], variadic: true }] }
6287
- };
6288
- }
6289
- registerFunction(name, customFunction, signature, options) {
6290
- const result = this._registerInternal(name, customFunction, signature, options);
6291
- if (!result.success) {
6292
- throw new Error(result.message);
6293
- }
6294
- }
6295
- _registerInternal(name, customFunction, signature, options = {}) {
6296
- if (!name || typeof name !== "string" || name.trim() === "") {
6297
- return {
6298
- success: false,
6299
- reason: "invalid-name",
6300
- message: "Function name must be a non-empty string"
6301
- };
6302
- }
6303
- try {
6304
- this.validateInputSignatures(name, signature);
6305
- } catch (error) {
6306
- return {
6307
- success: false,
6308
- reason: "invalid-signature",
6309
- message: error instanceof Error ? error.message : "Invalid function signature"
6310
- };
6311
- }
6312
- const { override = false, warn = false } = options;
6313
- const exists = name in this._functionTable;
6314
- if (exists && !override) {
6315
- return {
6316
- success: false,
6317
- reason: "already-exists",
6318
- message: `Function already defined: ${name}(). Use { override: true } to replace it.`
6319
- };
6320
- }
6321
- if (exists && override && warn) {
6322
- console.warn(`Warning: Overriding existing function: ${name}()`);
6323
- }
6324
- this._functionTable[name] = {
6325
- _func: customFunction.bind(this),
6326
- _signature: signature
6327
- };
6328
- this._customFunctions.add(name);
6329
- const message = exists ? `Function ${name}() overridden successfully` : `Function ${name}() registered successfully`;
6330
- return { success: true, message };
6331
- }
6332
- register(name, customFunction, signature, options = {}) {
6333
- return this._registerInternal(name, customFunction, signature, options);
6334
- }
6335
- unregister(name) {
6336
- if (!this._customFunctions.has(name)) {
6337
- return false;
6338
- }
6339
- delete this._functionTable[name];
6340
- this._customFunctions.delete(name);
6341
- return true;
6342
- }
6343
- isRegistered(name) {
6344
- return name in this._functionTable;
6345
- }
6346
- getRegistered() {
6347
- return Object.keys(this._functionTable);
6348
- }
6349
- getCustomFunctions() {
6350
- return Array.from(this._customFunctions);
6351
- }
6352
- clearCustomFunctions() {
6353
- for (const name of this._customFunctions) {
6354
- delete this._functionTable[name];
6355
- }
6356
- this._customFunctions.clear();
6357
- }
6358
- callFunction(name, resolvedArgs) {
6359
- const functionEntry = this._functionTable[name];
6360
- if (functionEntry === undefined) {
6361
- throw new Error(`Unknown function: ${name}()`);
6362
- }
6363
- this.validateArgs(name, resolvedArgs, functionEntry._signature);
6364
- return functionEntry._func.call(this, resolvedArgs);
6365
- }
6366
- validateInputSignatures(name, signature) {
6367
- for (let i = 0;i < signature.length; i += 1) {
6368
- if ("variadic" in signature[i] && i !== signature.length - 1) {
6369
- throw new Error(`Invalid arity: ${name}() 'variadic' argument ${i + 1} must occur last`);
6370
- }
6371
- }
6372
- }
6373
- validateArgs(name, args, signature) {
6374
- this.validateInputSignatures(name, signature);
6375
- this.validateArity(name, args, signature);
6376
- this.validateTypes(name, args, signature);
6377
- }
6378
- validateArity(name, args, signature) {
6379
- const numberOfRequiredArgs = signature.filter((argSignature) => !(argSignature.optional ?? false)).length;
6380
- const lastArgIsVariadic = signature[signature.length - 1]?.variadic ?? false;
6381
- const tooFewArgs = args.length < numberOfRequiredArgs;
6382
- const tooManyArgs = args.length > signature.length;
6383
- if (lastArgIsVariadic && tooFewArgs || !lastArgIsVariadic && (tooFewArgs || tooManyArgs)) {
6384
- const tooFewModifier = tooFewArgs && (!lastArgIsVariadic && numberOfRequiredArgs > 1 || lastArgIsVariadic) ? "at least " : "";
6385
- const pluralized = signature.length > 1;
6386
- throw new Error(`Invalid arity: ${name}() takes ${tooFewModifier}${numberOfRequiredArgs} argument${pluralized && "s" || ""} but received ${args.length}`);
6387
- }
6388
- }
6389
- validateTypes(name, args, signature) {
6390
- for (let i = 0;i < signature.length; i += 1) {
6391
- const currentSpec = signature[i].types;
6392
- const actualType = this.getTypeName(args[i]);
6393
- if (actualType === undefined) {
6394
- continue;
6395
- }
6396
- const typeMatched = currentSpec.some((expectedType) => this.typeMatches(actualType, expectedType, args[i]));
6397
- if (!typeMatched) {
6398
- const expected = currentSpec.map((typeId) => this.TYPE_NAME_TABLE[typeId]).join(" | ");
6399
- throw new Error(`Invalid type: ${name}() expected argument ${i + 1} to be type (${expected}) but received type ${this.TYPE_NAME_TABLE[actualType]} instead.`);
6400
- }
6401
- }
6402
- }
6403
- typeMatches(actual, expected, argValue) {
6404
- if (expected === 1) {
6405
- return true;
6406
- }
6407
- if (expected === 9 || expected === 8 || expected === 10 || expected === 11 || expected === 3) {
6408
- if (expected === 3) {
6409
- return actual === 3;
6410
- }
6411
- if (actual === 3) {
6412
- let subtype;
6413
- if (expected === 8) {
6414
- subtype = 0;
6415
- } else if (expected === 10) {
6416
- subtype = 4;
6417
- } else if (expected === 9) {
6418
- subtype = 2;
6419
- } else if (expected === 11) {
6420
- subtype = 3;
6421
- }
6422
- const array = argValue;
6423
- for (let i = 0;i < array.length; i += 1) {
6424
- const typeName = this.getTypeName(array[i]);
6425
- if (typeName !== undefined && subtype !== undefined && !this.typeMatches(typeName, subtype, array[i])) {
6426
- return false;
5526
+ _consumeLiteral: function(stream) {
5527
+ this._current++;
5528
+ var start = this._current;
5529
+ var maxLength = stream.length;
5530
+ var literal;
5531
+ while (stream[this._current] !== "`" && this._current < maxLength) {
5532
+ var current = this._current;
5533
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
5534
+ current += 2;
5535
+ } else {
5536
+ current++;
6427
5537
  }
5538
+ this._current = current;
6428
5539
  }
6429
- return true;
6430
- }
6431
- } else {
6432
- return actual === expected;
6433
- }
6434
- return false;
6435
- }
6436
- getTypeName(obj) {
6437
- if (obj === null) {
6438
- return 7;
6439
- }
6440
- if (typeof obj === "string") {
6441
- return 2;
6442
- }
6443
- if (typeof obj === "number") {
6444
- return 0;
6445
- }
6446
- if (typeof obj === "boolean") {
6447
- return 5;
6448
- }
6449
- if (Array.isArray(obj)) {
6450
- return 3;
6451
- }
6452
- if (typeof obj === "object") {
6453
- if (obj.expref) {
6454
- return 6;
6455
- }
6456
- return 4;
6457
- }
6458
- return;
6459
- }
6460
- createKeyFunction(exprefNode, allowedTypes) {
6461
- const interpreter = this._interpreter;
6462
- const keyFunc = (x) => {
6463
- const current = interpreter.visit(exprefNode, x);
6464
- if (!allowedTypes.includes(this.getTypeName(current))) {
6465
- const msg = `Invalid type: expected one of (${allowedTypes.map((t) => this.TYPE_NAME_TABLE[t]).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(current)]}`;
6466
- throw new Error(msg);
6467
- }
6468
- return current;
6469
- };
6470
- return keyFunc;
6471
- }
6472
- functionAvg = ([inputArray]) => {
6473
- if (!inputArray || inputArray.length == 0) {
6474
- return null;
6475
- }
6476
- let sum = 0;
6477
- for (let i = 0;i < inputArray.length; i += 1) {
6478
- sum += inputArray[i];
6479
- }
6480
- return sum / inputArray.length;
6481
- };
6482
- functionContains = ([
6483
- searchable,
6484
- searchValue
6485
- ]) => {
6486
- if (Array.isArray(searchable)) {
6487
- const array = searchable;
6488
- return array.includes(searchValue);
6489
- }
6490
- if (typeof searchable === "string") {
6491
- const text = searchable;
6492
- if (typeof searchValue === "string") {
6493
- return text.includes(searchValue);
6494
- }
6495
- }
6496
- return null;
6497
- };
6498
- functionEndsWith = (resolvedArgs) => {
6499
- const [searchStr, suffix] = resolvedArgs;
6500
- return searchStr.includes(suffix, searchStr.length - suffix.length);
6501
- };
6502
- functionFindFirst = this.createFindFunction(findFirst);
6503
- functionFindLast = this.createFindFunction(findLast);
6504
- createFindFunction(findFn) {
6505
- return (resolvedArgs) => {
6506
- const subject = resolvedArgs[0];
6507
- const search2 = resolvedArgs[1];
6508
- const start = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
6509
- const end = resolvedArgs.length > 3 ? resolvedArgs[3] : undefined;
6510
- return findFn(subject, search2, start, end);
6511
- };
6512
- }
6513
- functionFromItems = ([array]) => {
6514
- array.map((pair) => {
6515
- if (pair.length != 2 || typeof pair[0] !== "string") {
6516
- throw new Error("invalid value, each array must contain two elements, a pair of string and value");
6517
- }
6518
- });
6519
- return Object.fromEntries(array);
6520
- };
6521
- functionGroupBy = ([array, exprefNode]) => {
6522
- const keyFunction = this.createKeyFunction(exprefNode, [2]);
6523
- return array.reduce((acc, cur) => {
6524
- const k = keyFunction(cur ?? {});
6525
- const target = acc[k] = acc[k] || [];
6526
- target.push(cur);
6527
- return acc;
6528
- }, {});
6529
- };
6530
- functionItems = ([inputValue]) => {
6531
- return Object.entries(inputValue);
6532
- };
6533
- functionJoin = (resolvedArgs) => {
6534
- const [joinChar, listJoin] = resolvedArgs;
6535
- return listJoin.join(joinChar);
6536
- };
6537
- functionLength = ([inputValue]) => {
6538
- if (typeof inputValue === "string") {
6539
- return new Text(inputValue).length;
6540
- }
6541
- if (Array.isArray(inputValue)) {
6542
- return inputValue.length;
6543
- }
6544
- return Object.keys(inputValue).length;
6545
- };
6546
- functionMap = ([exprefNode, elements]) => {
6547
- if (!this._interpreter) {
6548
- return [];
6549
- }
6550
- const mapped = [];
6551
- const interpreter = this._interpreter;
6552
- for (let i = 0;i < elements.length; i += 1) {
6553
- mapped.push(interpreter.visit(exprefNode, elements[i]));
6554
- }
6555
- return mapped;
6556
- };
6557
- functionMax = ([inputValue]) => {
6558
- if (!inputValue.length) {
6559
- return null;
6560
- }
6561
- const typeName = this.getTypeName(inputValue[0]);
6562
- if (typeName === 0) {
6563
- return Math.max(...inputValue);
6564
- }
6565
- const elements = inputValue;
6566
- let maxElement = elements[0];
6567
- for (let i = 1;i < elements.length; i += 1) {
6568
- if (maxElement.localeCompare(elements[i]) < 0) {
6569
- maxElement = elements[i];
6570
- }
6571
- }
6572
- return maxElement;
6573
- };
6574
- functionMaxBy = (resolvedArgs) => {
6575
- const exprefNode = resolvedArgs[1];
6576
- const resolvedArray = resolvedArgs[0];
6577
- const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
6578
- let maxNumber = -Infinity;
6579
- let maxRecord;
6580
- let current;
6581
- for (let i = 0;i < resolvedArray.length; i += 1) {
6582
- current = keyFunction && keyFunction(resolvedArray[i]);
6583
- if (current !== undefined && current > maxNumber) {
6584
- maxNumber = current;
6585
- maxRecord = resolvedArray[i];
6586
- }
6587
- }
6588
- return maxRecord || null;
6589
- };
6590
- functionMerge = (resolvedArgs) => {
6591
- let merged = {};
6592
- for (let i = 0;i < resolvedArgs.length; i += 1) {
6593
- const current = resolvedArgs[i];
6594
- merged = Object.assign(merged, current);
6595
- }
6596
- return merged;
6597
- };
6598
- functionMin = ([inputValue]) => {
6599
- if (!inputValue.length) {
6600
- return null;
6601
- }
6602
- const typeName = this.getTypeName(inputValue[0]);
6603
- if (typeName === 0) {
6604
- return Math.min(...inputValue);
6605
- }
6606
- const elements = inputValue;
6607
- let minElement = elements[0];
6608
- for (let i = 1;i < elements.length; i += 1) {
6609
- if (elements[i].localeCompare(minElement) < 0) {
6610
- minElement = elements[i];
6611
- }
6612
- }
6613
- return minElement;
6614
- };
6615
- functionMinBy = (resolvedArgs) => {
6616
- const exprefNode = resolvedArgs[1];
6617
- const resolvedArray = resolvedArgs[0];
6618
- const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
6619
- let minNumber = Infinity;
6620
- let minRecord;
6621
- let current;
6622
- for (let i = 0;i < resolvedArray.length; i += 1) {
6623
- current = keyFunction && keyFunction(resolvedArray[i]);
6624
- if (current !== undefined && current < minNumber) {
6625
- minNumber = current;
6626
- minRecord = resolvedArray[i];
6627
- }
6628
- }
6629
- return minRecord || null;
6630
- };
6631
- functionNotNull = (resolvedArgs) => {
6632
- for (let i = 0;i < resolvedArgs.length; i += 1) {
6633
- if (this.getTypeName(resolvedArgs[i]) !== 7) {
6634
- return resolvedArgs[i];
6635
- }
6636
- }
6637
- return null;
6638
- };
6639
- functionPadLeft = this.createPadFunction(padLeft);
6640
- functionPadRight = this.createPadFunction(padRight);
6641
- createPadFunction(padFn) {
6642
- return (resolvedArgs) => {
6643
- const subject = resolvedArgs[0];
6644
- const width = resolvedArgs[1];
6645
- const padding = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
6646
- return padFn(subject, width, padding);
6647
- };
6648
- }
6649
- functionReplace = (resolvedArgs) => {
6650
- const subject = resolvedArgs[0];
6651
- const string = resolvedArgs[1];
6652
- const by = resolvedArgs[2];
6653
- return replace(subject, string, by, resolvedArgs.length > 3 ? resolvedArgs[3] : undefined);
6654
- };
6655
- functionSplit = (resolvedArgs) => {
6656
- const subject = resolvedArgs[0];
6657
- const search2 = resolvedArgs[1];
6658
- return split(subject, search2, resolvedArgs.length > 2 ? resolvedArgs[2] : undefined);
6659
- };
6660
- functionReverse = ([inputValue]) => {
6661
- const typeName = this.getTypeName(inputValue);
6662
- if (typeName === 2) {
6663
- return new Text(inputValue).reverse();
6664
- }
6665
- const reversedArray = inputValue.slice(0);
6666
- reversedArray.reverse();
6667
- return reversedArray;
6668
- };
6669
- functionSort = ([inputValue]) => {
6670
- if (inputValue.length == 0) {
6671
- return inputValue;
6672
- }
6673
- if (typeof inputValue[0] === "string") {
6674
- return [...inputValue].sort(Text.comparer);
6675
- }
6676
- return [...inputValue].sort();
6677
- };
6678
- functionSortBy = (resolvedArgs) => {
6679
- const sortedArray = resolvedArgs[0].slice(0);
6680
- if (sortedArray.length === 0) {
6681
- return sortedArray;
6682
- }
6683
- const interpreter = this._interpreter;
6684
- const exprefNode = resolvedArgs[1];
6685
- const requiredType = this.getTypeName(interpreter.visit(exprefNode, sortedArray[0]));
6686
- if (requiredType !== undefined && ![0, 2].includes(requiredType)) {
6687
- throw new Error(`Invalid type: unexpected type (${this.TYPE_NAME_TABLE[requiredType]})`);
6688
- }
6689
- function throwInvalidTypeError(rt, item) {
6690
- throw new Error(`Invalid type: expected (${rt.TYPE_NAME_TABLE[requiredType]}), received ${rt.TYPE_NAME_TABLE[rt.getTypeName(item)]}`);
6691
- }
6692
- return sortedArray.sort((a, b) => {
6693
- const exprA = interpreter.visit(exprefNode, a);
6694
- const exprB = interpreter.visit(exprefNode, b);
6695
- if (this.getTypeName(exprA) !== requiredType) {
6696
- throwInvalidTypeError(this, exprA);
6697
- } else if (this.getTypeName(exprB) !== requiredType) {
6698
- throwInvalidTypeError(this, exprB);
6699
- }
6700
- if (requiredType === 2) {
6701
- return Text.comparer(exprA, exprB);
6702
- }
6703
- return exprA - exprB;
6704
- });
6705
- };
6706
- functionStartsWith = ([searchable, searchStr]) => {
6707
- return searchable.startsWith(searchStr);
6708
- };
6709
- functionSum = ([inputValue]) => {
6710
- return inputValue.reduce((x, y) => x + y, 0);
6711
- };
6712
- functionToArray = ([inputValue]) => {
6713
- if (this.getTypeName(inputValue) === 3) {
6714
- return inputValue;
6715
- }
6716
- return [inputValue];
6717
- };
6718
- functionToNumber = ([inputValue]) => {
6719
- const typeName = this.getTypeName(inputValue);
6720
- let convertedValue;
6721
- if (typeName === 0) {
6722
- return inputValue;
6723
- }
6724
- if (typeName === 2) {
6725
- convertedValue = +inputValue;
6726
- if (!isNaN(convertedValue)) {
6727
- return convertedValue;
6728
- }
6729
- }
6730
- return null;
6731
- };
6732
- functionToString = ([inputValue]) => {
6733
- if (this.getTypeName(inputValue) === 2) {
6734
- return inputValue;
6735
- }
6736
- return JSON.stringify(inputValue);
6737
- };
6738
- functionTrim = this.createTrimFunction(trim);
6739
- functionTrimLeft = this.createTrimFunction(trimLeft);
6740
- functionTrimRight = this.createTrimFunction(trimRight);
6741
- createTrimFunction(trimFn) {
6742
- return (resolvedArgs) => {
6743
- const subject = resolvedArgs[0];
6744
- const chars = resolvedArgs.length > 1 ? resolvedArgs[1] : undefined;
6745
- return trimFn(subject, chars);
6746
- };
6747
- }
6748
- functionType = ([inputValue]) => {
6749
- switch (this.getTypeName(inputValue)) {
6750
- case 0:
6751
- return "number";
6752
- case 2:
6753
- return "string";
6754
- case 3:
6755
- return "array";
6756
- case 4:
6757
- return "object";
6758
- case 5:
6759
- return "boolean";
6760
- case 7:
6761
- return "null";
6762
- default:
6763
- throw new Error("invalid-type");
6764
- }
6765
- };
6766
- functionZip = (array) => {
6767
- const length = Math.min(...array.map((arr) => arr.length));
6768
- const result = Array(length).fill(null).map((_, index) => array.map((arr) => arr[index]));
6769
- return result;
6770
- };
6771
- };
6772
- var ScopeChain = class _ScopeChain {
6773
- inner = undefined;
6774
- data = {};
6775
- get currentScopeData() {
6776
- return this.data;
6777
- }
6778
- withScope(data) {
6779
- const outer = new _ScopeChain;
6780
- outer.inner = this;
6781
- outer.data = data;
6782
- return outer;
6783
- }
6784
- getValue(identifier) {
6785
- if (Object.prototype.hasOwnProperty.call(this.data, identifier)) {
6786
- return this.data[identifier];
6787
- }
6788
- if (this.inner) {
6789
- return this.inner.getValue(identifier);
6790
- }
6791
- return null;
6792
- }
6793
- };
6794
- var emptyScopeChain;
6795
- var TreeInterpreter = class _TreeInterpreter {
6796
- runtime;
6797
- _rootValue = null;
6798
- _scope;
6799
- constructor() {
6800
- this.runtime = new Runtime(this);
6801
- this._scope = new ScopeChain;
6802
- }
6803
- withScope(scope) {
6804
- const interpreter = new _TreeInterpreter;
6805
- interpreter.runtime._functionTable = this.runtime._functionTable;
6806
- interpreter._rootValue = this._rootValue;
6807
- interpreter._scope = this._scope.withScope(scope);
6808
- return interpreter;
6809
- }
6810
- search(node, value) {
6811
- this._rootValue = value;
6812
- this._scope = emptyScopeChain;
6813
- return this.visit(node, value);
6814
- }
6815
- visit(node, value) {
6816
- switch (node.type) {
6817
- case "Ternary": {
6818
- const condition = this.visit(node.condition, value);
6819
- if (!isFalse(condition)) {
6820
- return this.visit(node.trueExpr, value);
6821
- }
6822
- return this.visit(node.falseExpr, value);
6823
- }
6824
- case "Field":
6825
- const identifier = node.name;
6826
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
6827
- return null;
5540
+ var literalString = trimLeft(stream.slice(start, this._current));
5541
+ literalString = literalString.replace("\\`", "`");
5542
+ if (this._looksLikeJSON(literalString)) {
5543
+ literal = JSON.parse(literalString);
5544
+ } else {
5545
+ literal = JSON.parse('"' + literalString + '"');
5546
+ }
5547
+ this._current++;
5548
+ return literal;
5549
+ },
5550
+ _looksLikeJSON: function(literalString) {
5551
+ var startingChars = '[{"';
5552
+ var jsonLiterals = ["true", "false", "null"];
5553
+ var numberLooking = "-0123456789";
5554
+ if (literalString === "") {
5555
+ return false;
5556
+ } else if (startingChars.indexOf(literalString[0]) >= 0) {
5557
+ return true;
5558
+ } else if (jsonLiterals.indexOf(literalString) >= 0) {
5559
+ return true;
5560
+ } else if (numberLooking.indexOf(literalString[0]) >= 0) {
5561
+ try {
5562
+ JSON.parse(literalString);
5563
+ return true;
5564
+ } catch (ex) {
5565
+ return false;
5566
+ }
5567
+ } else {
5568
+ return false;
6828
5569
  }
6829
- return value[identifier] ?? null;
6830
- case "LetExpression": {
6831
- const { bindings, expression } = node;
6832
- let scope = {};
6833
- bindings.forEach((binding) => {
6834
- const reference = this.visit(binding, value);
6835
- scope = {
6836
- ...scope,
6837
- ...reference
6838
- };
6839
- });
6840
- return this.withScope(scope).visit(expression, value);
6841
- }
6842
- case "Binding": {
6843
- const { variable, reference } = node;
6844
- const result = this.visit(reference, value);
6845
- return { [variable]: result };
6846
5570
  }
6847
- case "Variable": {
6848
- const variable = node.name;
6849
- if (!this._scope.getValue(variable) && !Object.prototype.hasOwnProperty.call(this._scope.currentScopeData, variable)) {
6850
- throw new Error(`Error referencing undefined variable ${variable}`);
5571
+ };
5572
+ var bindingPower = {};
5573
+ bindingPower[TOK_EOF] = 0;
5574
+ bindingPower[TOK_UNQUOTEDIDENTIFIER] = 0;
5575
+ bindingPower[TOK_QUOTEDIDENTIFIER] = 0;
5576
+ bindingPower[TOK_RBRACKET] = 0;
5577
+ bindingPower[TOK_RPAREN] = 0;
5578
+ bindingPower[TOK_COMMA] = 0;
5579
+ bindingPower[TOK_RBRACE] = 0;
5580
+ bindingPower[TOK_NUMBER] = 0;
5581
+ bindingPower[TOK_CURRENT] = 0;
5582
+ bindingPower[TOK_EXPREF] = 0;
5583
+ bindingPower[TOK_PIPE] = 1;
5584
+ bindingPower[TOK_OR] = 2;
5585
+ bindingPower[TOK_AND] = 3;
5586
+ bindingPower[TOK_EQ] = 5;
5587
+ bindingPower[TOK_GT] = 5;
5588
+ bindingPower[TOK_LT] = 5;
5589
+ bindingPower[TOK_GTE] = 5;
5590
+ bindingPower[TOK_LTE] = 5;
5591
+ bindingPower[TOK_NE] = 5;
5592
+ bindingPower[TOK_FLATTEN] = 9;
5593
+ bindingPower[TOK_STAR] = 20;
5594
+ bindingPower[TOK_FILTER] = 21;
5595
+ bindingPower[TOK_DOT] = 40;
5596
+ bindingPower[TOK_NOT] = 45;
5597
+ bindingPower[TOK_LBRACE] = 50;
5598
+ bindingPower[TOK_LBRACKET] = 55;
5599
+ bindingPower[TOK_LPAREN] = 60;
5600
+ function Parser() {}
5601
+ Parser.prototype = {
5602
+ parse: function(expression) {
5603
+ this._loadTokens(expression);
5604
+ this.index = 0;
5605
+ var ast = this.expression(0);
5606
+ if (this._lookahead(0) !== TOK_EOF) {
5607
+ var t = this._lookaheadToken(0);
5608
+ var error = new Error("Unexpected token type: " + t.type + ", value: " + t.value);
5609
+ error.name = "ParserError";
5610
+ throw error;
6851
5611
  }
6852
- return this._scope.getValue(variable);
6853
- }
6854
- case "IndexExpression":
6855
- return this.visit(node.right, this.visit(node.left, value));
6856
- case "Subexpression": {
6857
- const result = this.visit(node.left, value);
6858
- return result != null ? this.visit(node.right, result) ?? null : null;
6859
- }
6860
- case "Index": {
6861
- if (!Array.isArray(value)) {
6862
- return null;
5612
+ return ast;
5613
+ },
5614
+ _loadTokens: function(expression) {
5615
+ var lexer = new Lexer;
5616
+ var tokens = lexer.tokenize(expression);
5617
+ tokens.push({ type: TOK_EOF, value: "", start: expression.length });
5618
+ this.tokens = tokens;
5619
+ },
5620
+ expression: function(rbp) {
5621
+ var leftToken = this._lookaheadToken(0);
5622
+ this._advance();
5623
+ var left = this.nud(leftToken);
5624
+ var currentToken = this._lookahead(0);
5625
+ while (rbp < bindingPower[currentToken]) {
5626
+ this._advance();
5627
+ left = this.led(currentToken, left);
5628
+ currentToken = this._lookahead(0);
5629
+ }
5630
+ return left;
5631
+ },
5632
+ _lookahead: function(number) {
5633
+ return this.tokens[this.index + number].type;
5634
+ },
5635
+ _lookaheadToken: function(number) {
5636
+ return this.tokens[this.index + number];
5637
+ },
5638
+ _advance: function() {
5639
+ this.index++;
5640
+ },
5641
+ nud: function(token) {
5642
+ var left;
5643
+ var right;
5644
+ var expression;
5645
+ switch (token.type) {
5646
+ case TOK_LITERAL:
5647
+ return { type: "Literal", value: token.value };
5648
+ case TOK_UNQUOTEDIDENTIFIER:
5649
+ return { type: "Field", name: token.value };
5650
+ case TOK_QUOTEDIDENTIFIER:
5651
+ var node = { type: "Field", name: token.value };
5652
+ if (this._lookahead(0) === TOK_LPAREN) {
5653
+ throw new Error("Quoted identifier not allowed for function names.");
5654
+ }
5655
+ return node;
5656
+ case TOK_NOT:
5657
+ right = this.expression(bindingPower.Not);
5658
+ return { type: "NotExpression", children: [right] };
5659
+ case TOK_STAR:
5660
+ left = { type: "Identity" };
5661
+ right = null;
5662
+ if (this._lookahead(0) === TOK_RBRACKET) {
5663
+ right = { type: "Identity" };
5664
+ } else {
5665
+ right = this._parseProjectionRHS(bindingPower.Star);
5666
+ }
5667
+ return { type: "ValueProjection", children: [left, right] };
5668
+ case TOK_FILTER:
5669
+ return this.led(token.type, { type: "Identity" });
5670
+ case TOK_LBRACE:
5671
+ return this._parseMultiselectHash();
5672
+ case TOK_FLATTEN:
5673
+ left = { type: TOK_FLATTEN, children: [{ type: "Identity" }] };
5674
+ right = this._parseProjectionRHS(bindingPower.Flatten);
5675
+ return { type: "Projection", children: [left, right] };
5676
+ case TOK_LBRACKET:
5677
+ if (this._lookahead(0) === TOK_NUMBER || this._lookahead(0) === TOK_COLON) {
5678
+ right = this._parseIndexExpression();
5679
+ return this._projectIfSlice({ type: "Identity" }, right);
5680
+ } else if (this._lookahead(0) === TOK_STAR && this._lookahead(1) === TOK_RBRACKET) {
5681
+ this._advance();
5682
+ this._advance();
5683
+ right = this._parseProjectionRHS(bindingPower.Star);
5684
+ return {
5685
+ type: "Projection",
5686
+ children: [{ type: "Identity" }, right]
5687
+ };
5688
+ }
5689
+ return this._parseMultiselectList();
5690
+ case TOK_CURRENT:
5691
+ return { type: TOK_CURRENT };
5692
+ case TOK_EXPREF:
5693
+ expression = this.expression(bindingPower.Expref);
5694
+ return { type: "ExpressionReference", children: [expression] };
5695
+ case TOK_LPAREN:
5696
+ var args = [];
5697
+ while (this._lookahead(0) !== TOK_RPAREN) {
5698
+ if (this._lookahead(0) === TOK_CURRENT) {
5699
+ expression = { type: TOK_CURRENT };
5700
+ this._advance();
5701
+ } else {
5702
+ expression = this.expression(0);
5703
+ }
5704
+ args.push(expression);
5705
+ }
5706
+ this._match(TOK_RPAREN);
5707
+ return args[0];
5708
+ default:
5709
+ this._errorToken(token);
6863
5710
  }
6864
- const index = node.value < 0 ? value.length + node.value : node.value;
6865
- return value[index] ?? null;
6866
- }
6867
- case "Slice": {
6868
- if (!Array.isArray(value) && typeof value !== "string") {
6869
- return null;
5711
+ },
5712
+ led: function(tokenName, left) {
5713
+ var right;
5714
+ switch (tokenName) {
5715
+ case TOK_DOT:
5716
+ var rbp = bindingPower.Dot;
5717
+ if (this._lookahead(0) !== TOK_STAR) {
5718
+ right = this._parseDotRHS(rbp);
5719
+ return { type: "Subexpression", children: [left, right] };
5720
+ }
5721
+ this._advance();
5722
+ right = this._parseProjectionRHS(rbp);
5723
+ return { type: "ValueProjection", children: [left, right] };
5724
+ case TOK_PIPE:
5725
+ right = this.expression(bindingPower.Pipe);
5726
+ return { type: TOK_PIPE, children: [left, right] };
5727
+ case TOK_OR:
5728
+ right = this.expression(bindingPower.Or);
5729
+ return { type: "OrExpression", children: [left, right] };
5730
+ case TOK_AND:
5731
+ right = this.expression(bindingPower.And);
5732
+ return { type: "AndExpression", children: [left, right] };
5733
+ case TOK_LPAREN:
5734
+ var name = left.name;
5735
+ var args = [];
5736
+ var expression, node;
5737
+ while (this._lookahead(0) !== TOK_RPAREN) {
5738
+ if (this._lookahead(0) === TOK_CURRENT) {
5739
+ expression = { type: TOK_CURRENT };
5740
+ this._advance();
5741
+ } else {
5742
+ expression = this.expression(0);
5743
+ }
5744
+ if (this._lookahead(0) === TOK_COMMA) {
5745
+ this._match(TOK_COMMA);
5746
+ }
5747
+ args.push(expression);
5748
+ }
5749
+ this._match(TOK_RPAREN);
5750
+ node = { type: "Function", name, children: args };
5751
+ return node;
5752
+ case TOK_FILTER:
5753
+ var condition = this.expression(0);
5754
+ this._match(TOK_RBRACKET);
5755
+ if (this._lookahead(0) === TOK_FLATTEN) {
5756
+ right = { type: "Identity" };
5757
+ } else {
5758
+ right = this._parseProjectionRHS(bindingPower.Filter);
5759
+ }
5760
+ return { type: "FilterProjection", children: [left, right, condition] };
5761
+ case TOK_FLATTEN:
5762
+ var leftNode = { type: TOK_FLATTEN, children: [left] };
5763
+ var rightNode = this._parseProjectionRHS(bindingPower.Flatten);
5764
+ return { type: "Projection", children: [leftNode, rightNode] };
5765
+ case TOK_EQ:
5766
+ case TOK_NE:
5767
+ case TOK_GT:
5768
+ case TOK_GTE:
5769
+ case TOK_LT:
5770
+ case TOK_LTE:
5771
+ return this._parseComparator(left, tokenName);
5772
+ case TOK_LBRACKET:
5773
+ var token = this._lookaheadToken(0);
5774
+ if (token.type === TOK_NUMBER || token.type === TOK_COLON) {
5775
+ right = this._parseIndexExpression();
5776
+ return this._projectIfSlice(left, right);
5777
+ }
5778
+ this._match(TOK_STAR);
5779
+ this._match(TOK_RBRACKET);
5780
+ right = this._parseProjectionRHS(bindingPower.Star);
5781
+ return { type: "Projection", children: [left, right] };
5782
+ default:
5783
+ this._errorToken(this._lookaheadToken(0));
6870
5784
  }
6871
- const { start, stop, step } = this.computeSliceParams(value.length, node);
6872
- if (typeof value === "string") {
6873
- const chars = [...value];
6874
- const sliced = this.slice(chars, start, stop, step);
6875
- return sliced.join("");
5785
+ },
5786
+ _match: function(tokenType) {
5787
+ if (this._lookahead(0) === tokenType) {
5788
+ this._advance();
6876
5789
  } else {
6877
- return this.slice(value, start, stop, step);
5790
+ var t = this._lookaheadToken(0);
5791
+ var error = new Error("Expected " + tokenType + ", got: " + t.type);
5792
+ error.name = "ParserError";
5793
+ throw error;
6878
5794
  }
6879
- }
6880
- case "Projection": {
6881
- const { left, right } = node;
6882
- let allowString = false;
6883
- if (left.type === "IndexExpression" && left.right.type === "Slice") {
6884
- allowString = true;
5795
+ },
5796
+ _errorToken: function(token) {
5797
+ var error = new Error("Invalid token (" + token.type + '): "' + token.value + '"');
5798
+ error.name = "ParserError";
5799
+ throw error;
5800
+ },
5801
+ _parseIndexExpression: function() {
5802
+ if (this._lookahead(0) === TOK_COLON || this._lookahead(1) === TOK_COLON) {
5803
+ return this._parseSliceExpression();
5804
+ } else {
5805
+ var node = {
5806
+ type: "Index",
5807
+ value: this._lookaheadToken(0).value
5808
+ };
5809
+ this._advance();
5810
+ this._match(TOK_RBRACKET);
5811
+ return node;
6885
5812
  }
6886
- const base = this.visit(left, value);
6887
- if (allowString && typeof base === "string") {
6888
- return this.visit(right, base);
5813
+ },
5814
+ _projectIfSlice: function(left, right) {
5815
+ var indexExpr = { type: "IndexExpression", children: [left, right] };
5816
+ if (right.type === "Slice") {
5817
+ return {
5818
+ type: "Projection",
5819
+ children: [indexExpr, this._parseProjectionRHS(bindingPower.Star)]
5820
+ };
5821
+ } else {
5822
+ return indexExpr;
6889
5823
  }
6890
- if (!Array.isArray(base)) {
6891
- return null;
5824
+ },
5825
+ _parseSliceExpression: function() {
5826
+ var parts = [null, null, null];
5827
+ var index = 0;
5828
+ var currentToken = this._lookahead(0);
5829
+ while (currentToken !== TOK_RBRACKET && index < 3) {
5830
+ if (currentToken === TOK_COLON) {
5831
+ index++;
5832
+ this._advance();
5833
+ } else if (currentToken === TOK_NUMBER) {
5834
+ parts[index] = this._lookaheadToken(0).value;
5835
+ this._advance();
5836
+ } else {
5837
+ var t = this._lookahead(0);
5838
+ var error = new Error("Syntax error, unexpected token: " + t.value + "(" + t.type + ")");
5839
+ error.name = "Parsererror";
5840
+ throw error;
5841
+ }
5842
+ currentToken = this._lookahead(0);
5843
+ }
5844
+ this._match(TOK_RBRACKET);
5845
+ return {
5846
+ type: "Slice",
5847
+ children: parts
5848
+ };
5849
+ },
5850
+ _parseComparator: function(left, comparator) {
5851
+ var right = this.expression(bindingPower[comparator]);
5852
+ return { type: "Comparator", name: comparator, children: [left, right] };
5853
+ },
5854
+ _parseDotRHS: function(rbp) {
5855
+ var lookahead = this._lookahead(0);
5856
+ var exprTokens = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER, TOK_STAR];
5857
+ if (exprTokens.indexOf(lookahead) >= 0) {
5858
+ return this.expression(rbp);
5859
+ } else if (lookahead === TOK_LBRACKET) {
5860
+ this._match(TOK_LBRACKET);
5861
+ return this._parseMultiselectList();
5862
+ } else if (lookahead === TOK_LBRACE) {
5863
+ this._match(TOK_LBRACE);
5864
+ return this._parseMultiselectHash();
5865
+ }
5866
+ },
5867
+ _parseProjectionRHS: function(rbp) {
5868
+ var right;
5869
+ if (bindingPower[this._lookahead(0)] < 10) {
5870
+ right = { type: "Identity" };
5871
+ } else if (this._lookahead(0) === TOK_LBRACKET) {
5872
+ right = this.expression(rbp);
5873
+ } else if (this._lookahead(0) === TOK_FILTER) {
5874
+ right = this.expression(rbp);
5875
+ } else if (this._lookahead(0) === TOK_DOT) {
5876
+ this._match(TOK_DOT);
5877
+ right = this._parseDotRHS(rbp);
5878
+ } else {
5879
+ var t = this._lookaheadToken(0);
5880
+ var error = new Error("Sytanx error, unexpected token: " + t.value + "(" + t.type + ")");
5881
+ error.name = "ParserError";
5882
+ throw error;
5883
+ }
5884
+ return right;
5885
+ },
5886
+ _parseMultiselectList: function() {
5887
+ var expressions = [];
5888
+ while (this._lookahead(0) !== TOK_RBRACKET) {
5889
+ var expression = this.expression(0);
5890
+ expressions.push(expression);
5891
+ if (this._lookahead(0) === TOK_COMMA) {
5892
+ this._match(TOK_COMMA);
5893
+ if (this._lookahead(0) === TOK_RBRACKET) {
5894
+ throw new Error("Unexpected token Rbracket");
5895
+ }
5896
+ }
6892
5897
  }
6893
- const collected = [];
6894
- for (const elem of base) {
6895
- const current = this.visit(right, elem);
6896
- if (current !== null) {
6897
- collected.push(current);
5898
+ this._match(TOK_RBRACKET);
5899
+ return { type: "MultiSelectList", children: expressions };
5900
+ },
5901
+ _parseMultiselectHash: function() {
5902
+ var pairs2 = [];
5903
+ var identifierTypes = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER];
5904
+ var keyToken, keyName, value, node;
5905
+ for (;; ) {
5906
+ keyToken = this._lookaheadToken(0);
5907
+ if (identifierTypes.indexOf(keyToken.type) < 0) {
5908
+ throw new Error("Expecting an identifier token, got: " + keyToken.type);
5909
+ }
5910
+ keyName = keyToken.value;
5911
+ this._advance();
5912
+ this._match(TOK_COLON);
5913
+ value = this.expression(0);
5914
+ node = { type: "KeyValuePair", name: keyName, value };
5915
+ pairs2.push(node);
5916
+ if (this._lookahead(0) === TOK_COMMA) {
5917
+ this._match(TOK_COMMA);
5918
+ } else if (this._lookahead(0) === TOK_RBRACE) {
5919
+ this._match(TOK_RBRACE);
5920
+ break;
6898
5921
  }
6899
5922
  }
6900
- return collected;
5923
+ return { type: "MultiSelectHash", children: pairs2 };
6901
5924
  }
6902
- case "ValueProjection": {
6903
- const { left, right } = node;
6904
- const base = this.visit(left, value);
6905
- if (base === null || typeof base !== "object" || Array.isArray(base)) {
6906
- return null;
5925
+ };
5926
+ function TreeInterpreter(runtime) {
5927
+ this.runtime = runtime;
5928
+ }
5929
+ TreeInterpreter.prototype = {
5930
+ search: function(node, value) {
5931
+ return this.visit(node, value);
5932
+ },
5933
+ visit: function(node, value) {
5934
+ var matched, current, result, first, second, field, left, right, collected, i;
5935
+ switch (node.type) {
5936
+ case "Field":
5937
+ if (value !== null && isObject(value)) {
5938
+ field = value[node.name];
5939
+ if (field === undefined) {
5940
+ return null;
5941
+ } else {
5942
+ return field;
5943
+ }
5944
+ }
5945
+ return null;
5946
+ case "Subexpression":
5947
+ result = this.visit(node.children[0], value);
5948
+ for (i = 1;i < node.children.length; i++) {
5949
+ result = this.visit(node.children[1], result);
5950
+ if (result === null) {
5951
+ return null;
5952
+ }
5953
+ }
5954
+ return result;
5955
+ case "IndexExpression":
5956
+ left = this.visit(node.children[0], value);
5957
+ right = this.visit(node.children[1], left);
5958
+ return right;
5959
+ case "Index":
5960
+ if (!isArray(value)) {
5961
+ return null;
5962
+ }
5963
+ var index = node.value;
5964
+ if (index < 0) {
5965
+ index = value.length + index;
5966
+ }
5967
+ result = value[index];
5968
+ if (result === undefined) {
5969
+ result = null;
5970
+ }
5971
+ return result;
5972
+ case "Slice":
5973
+ if (!isArray(value)) {
5974
+ return null;
5975
+ }
5976
+ var sliceParams = node.children.slice(0);
5977
+ var computed = this.computeSliceParams(value.length, sliceParams);
5978
+ var start = computed[0];
5979
+ var stop = computed[1];
5980
+ var step = computed[2];
5981
+ result = [];
5982
+ if (step > 0) {
5983
+ for (i = start;i < stop; i += step) {
5984
+ result.push(value[i]);
5985
+ }
5986
+ } else {
5987
+ for (i = start;i > stop; i += step) {
5988
+ result.push(value[i]);
5989
+ }
5990
+ }
5991
+ return result;
5992
+ case "Projection":
5993
+ var base = this.visit(node.children[0], value);
5994
+ if (!isArray(base)) {
5995
+ return null;
5996
+ }
5997
+ collected = [];
5998
+ for (i = 0;i < base.length; i++) {
5999
+ current = this.visit(node.children[1], base[i]);
6000
+ if (current !== null) {
6001
+ collected.push(current);
6002
+ }
6003
+ }
6004
+ return collected;
6005
+ case "ValueProjection":
6006
+ base = this.visit(node.children[0], value);
6007
+ if (!isObject(base)) {
6008
+ return null;
6009
+ }
6010
+ collected = [];
6011
+ var values = objValues(base);
6012
+ for (i = 0;i < values.length; i++) {
6013
+ current = this.visit(node.children[1], values[i]);
6014
+ if (current !== null) {
6015
+ collected.push(current);
6016
+ }
6017
+ }
6018
+ return collected;
6019
+ case "FilterProjection":
6020
+ base = this.visit(node.children[0], value);
6021
+ if (!isArray(base)) {
6022
+ return null;
6023
+ }
6024
+ var filtered = [];
6025
+ var finalResults = [];
6026
+ for (i = 0;i < base.length; i++) {
6027
+ matched = this.visit(node.children[2], base[i]);
6028
+ if (!isFalse(matched)) {
6029
+ filtered.push(base[i]);
6030
+ }
6031
+ }
6032
+ for (var j = 0;j < filtered.length; j++) {
6033
+ current = this.visit(node.children[1], filtered[j]);
6034
+ if (current !== null) {
6035
+ finalResults.push(current);
6036
+ }
6037
+ }
6038
+ return finalResults;
6039
+ case "Comparator":
6040
+ first = this.visit(node.children[0], value);
6041
+ second = this.visit(node.children[1], value);
6042
+ switch (node.name) {
6043
+ case TOK_EQ:
6044
+ result = strictDeepEqual(first, second);
6045
+ break;
6046
+ case TOK_NE:
6047
+ result = !strictDeepEqual(first, second);
6048
+ break;
6049
+ case TOK_GT:
6050
+ result = first > second;
6051
+ break;
6052
+ case TOK_GTE:
6053
+ result = first >= second;
6054
+ break;
6055
+ case TOK_LT:
6056
+ result = first < second;
6057
+ break;
6058
+ case TOK_LTE:
6059
+ result = first <= second;
6060
+ break;
6061
+ default:
6062
+ throw new Error("Unknown comparator: " + node.name);
6063
+ }
6064
+ return result;
6065
+ case TOK_FLATTEN:
6066
+ var original = this.visit(node.children[0], value);
6067
+ if (!isArray(original)) {
6068
+ return null;
6069
+ }
6070
+ var merged = [];
6071
+ for (i = 0;i < original.length; i++) {
6072
+ current = original[i];
6073
+ if (isArray(current)) {
6074
+ merged.push.apply(merged, current);
6075
+ } else {
6076
+ merged.push(current);
6077
+ }
6078
+ }
6079
+ return merged;
6080
+ case "Identity":
6081
+ return value;
6082
+ case "MultiSelectList":
6083
+ if (value === null) {
6084
+ return null;
6085
+ }
6086
+ collected = [];
6087
+ for (i = 0;i < node.children.length; i++) {
6088
+ collected.push(this.visit(node.children[i], value));
6089
+ }
6090
+ return collected;
6091
+ case "MultiSelectHash":
6092
+ if (value === null) {
6093
+ return null;
6094
+ }
6095
+ collected = {};
6096
+ var child;
6097
+ for (i = 0;i < node.children.length; i++) {
6098
+ child = node.children[i];
6099
+ collected[child.name] = this.visit(child.value, value);
6100
+ }
6101
+ return collected;
6102
+ case "OrExpression":
6103
+ matched = this.visit(node.children[0], value);
6104
+ if (isFalse(matched)) {
6105
+ matched = this.visit(node.children[1], value);
6106
+ }
6107
+ return matched;
6108
+ case "AndExpression":
6109
+ first = this.visit(node.children[0], value);
6110
+ if (isFalse(first) === true) {
6111
+ return first;
6112
+ }
6113
+ return this.visit(node.children[1], value);
6114
+ case "NotExpression":
6115
+ first = this.visit(node.children[0], value);
6116
+ return isFalse(first);
6117
+ case "Literal":
6118
+ return node.value;
6119
+ case TOK_PIPE:
6120
+ left = this.visit(node.children[0], value);
6121
+ return this.visit(node.children[1], left);
6122
+ case TOK_CURRENT:
6123
+ return value;
6124
+ case "Function":
6125
+ var resolvedArgs = [];
6126
+ for (i = 0;i < node.children.length; i++) {
6127
+ resolvedArgs.push(this.visit(node.children[i], value));
6128
+ }
6129
+ return this.runtime.callFunction(node.name, resolvedArgs);
6130
+ case "ExpressionReference":
6131
+ var refNode = node.children[0];
6132
+ refNode.jmespathType = TOK_EXPREF;
6133
+ return refNode;
6134
+ default:
6135
+ throw new Error("Unknown node type: " + node.type);
6907
6136
  }
6908
- const collected = [];
6909
- const values = Object.values(base);
6910
- for (const elem of values) {
6911
- const current = this.visit(right, elem);
6912
- if (current !== null) {
6913
- collected.push(current);
6137
+ },
6138
+ computeSliceParams: function(arrayLength, sliceParams) {
6139
+ var start = sliceParams[0];
6140
+ var stop = sliceParams[1];
6141
+ var step = sliceParams[2];
6142
+ var computed = [null, null, null];
6143
+ if (step === null) {
6144
+ step = 1;
6145
+ } else if (step === 0) {
6146
+ var error = new Error("Invalid slice, step cannot be 0");
6147
+ error.name = "RuntimeError";
6148
+ throw error;
6149
+ }
6150
+ var stepValueNegative = step < 0 ? true : false;
6151
+ if (start === null) {
6152
+ start = stepValueNegative ? arrayLength - 1 : 0;
6153
+ } else {
6154
+ start = this.capSliceRange(arrayLength, start, step);
6155
+ }
6156
+ if (stop === null) {
6157
+ stop = stepValueNegative ? -1 : arrayLength;
6158
+ } else {
6159
+ stop = this.capSliceRange(arrayLength, stop, step);
6160
+ }
6161
+ computed[0] = start;
6162
+ computed[1] = stop;
6163
+ computed[2] = step;
6164
+ return computed;
6165
+ },
6166
+ capSliceRange: function(arrayLength, actualValue, step) {
6167
+ if (actualValue < 0) {
6168
+ actualValue += arrayLength;
6169
+ if (actualValue < 0) {
6170
+ actualValue = step < 0 ? -1 : 0;
6914
6171
  }
6172
+ } else if (actualValue >= arrayLength) {
6173
+ actualValue = step < 0 ? arrayLength - 1 : arrayLength;
6915
6174
  }
6916
- return collected;
6175
+ return actualValue;
6917
6176
  }
6918
- case "FilterProjection": {
6919
- const { left, right, condition } = node;
6920
- const base = this.visit(left, value);
6921
- if (!Array.isArray(base)) {
6922
- return null;
6177
+ };
6178
+ function Runtime(interpreter) {
6179
+ this._interpreter = interpreter;
6180
+ this.functionTable = {
6181
+ abs: { _func: this._functionAbs, _signature: [{ types: [TYPE_NUMBER] }] },
6182
+ avg: { _func: this._functionAvg, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
6183
+ ceil: { _func: this._functionCeil, _signature: [{ types: [TYPE_NUMBER] }] },
6184
+ contains: {
6185
+ _func: this._functionContains,
6186
+ _signature: [
6187
+ { types: [TYPE_STRING, TYPE_ARRAY] },
6188
+ { types: [TYPE_ANY] }
6189
+ ]
6190
+ },
6191
+ ends_with: {
6192
+ _func: this._functionEndsWith,
6193
+ _signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
6194
+ },
6195
+ floor: { _func: this._functionFloor, _signature: [{ types: [TYPE_NUMBER] }] },
6196
+ length: {
6197
+ _func: this._functionLength,
6198
+ _signature: [{ types: [TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT] }]
6199
+ },
6200
+ map: {
6201
+ _func: this._functionMap,
6202
+ _signature: [{ types: [TYPE_EXPREF] }, { types: [TYPE_ARRAY] }]
6203
+ },
6204
+ max: {
6205
+ _func: this._functionMax,
6206
+ _signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
6207
+ },
6208
+ merge: {
6209
+ _func: this._functionMerge,
6210
+ _signature: [{ types: [TYPE_OBJECT], variadic: true }]
6211
+ },
6212
+ max_by: {
6213
+ _func: this._functionMaxBy,
6214
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
6215
+ },
6216
+ sum: { _func: this._functionSum, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
6217
+ starts_with: {
6218
+ _func: this._functionStartsWith,
6219
+ _signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
6220
+ },
6221
+ min: {
6222
+ _func: this._functionMin,
6223
+ _signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
6224
+ },
6225
+ min_by: {
6226
+ _func: this._functionMinBy,
6227
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
6228
+ },
6229
+ type: { _func: this._functionType, _signature: [{ types: [TYPE_ANY] }] },
6230
+ keys: { _func: this._functionKeys, _signature: [{ types: [TYPE_OBJECT] }] },
6231
+ values: { _func: this._functionValues, _signature: [{ types: [TYPE_OBJECT] }] },
6232
+ sort: { _func: this._functionSort, _signature: [{ types: [TYPE_ARRAY_STRING, TYPE_ARRAY_NUMBER] }] },
6233
+ sort_by: {
6234
+ _func: this._functionSortBy,
6235
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
6236
+ },
6237
+ join: {
6238
+ _func: this._functionJoin,
6239
+ _signature: [
6240
+ { types: [TYPE_STRING] },
6241
+ { types: [TYPE_ARRAY_STRING] }
6242
+ ]
6243
+ },
6244
+ reverse: {
6245
+ _func: this._functionReverse,
6246
+ _signature: [{ types: [TYPE_STRING, TYPE_ARRAY] }]
6247
+ },
6248
+ to_array: { _func: this._functionToArray, _signature: [{ types: [TYPE_ANY] }] },
6249
+ to_string: { _func: this._functionToString, _signature: [{ types: [TYPE_ANY] }] },
6250
+ to_number: { _func: this._functionToNumber, _signature: [{ types: [TYPE_ANY] }] },
6251
+ not_null: {
6252
+ _func: this._functionNotNull,
6253
+ _signature: [{ types: [TYPE_ANY], variadic: true }]
6923
6254
  }
6924
- const results = [];
6925
- for (const elem of base) {
6926
- const matched = this.visit(condition, elem);
6927
- if (isFalse(matched)) {
6928
- continue;
6255
+ };
6256
+ }
6257
+ Runtime.prototype = {
6258
+ callFunction: function(name, resolvedArgs) {
6259
+ var functionEntry = this.functionTable[name];
6260
+ if (functionEntry === undefined) {
6261
+ throw new Error("Unknown function: " + name + "()");
6262
+ }
6263
+ this._validateArgs(name, resolvedArgs, functionEntry._signature);
6264
+ return functionEntry._func.call(this, resolvedArgs);
6265
+ },
6266
+ _validateArgs: function(name, args, signature) {
6267
+ var pluralized;
6268
+ if (signature[signature.length - 1].variadic) {
6269
+ if (args.length < signature.length) {
6270
+ pluralized = signature.length === 1 ? " argument" : " arguments";
6271
+ throw new Error("ArgumentError: " + name + "() " + "takes at least" + signature.length + pluralized + " but received " + args.length);
6929
6272
  }
6930
- const result = this.visit(right, elem);
6931
- if (result !== null) {
6932
- results.push(result);
6273
+ } else if (args.length !== signature.length) {
6274
+ pluralized = signature.length === 1 ? " argument" : " arguments";
6275
+ throw new Error("ArgumentError: " + name + "() " + "takes " + signature.length + pluralized + " but received " + args.length);
6276
+ }
6277
+ var currentSpec;
6278
+ var actualType;
6279
+ var typeMatched;
6280
+ for (var i = 0;i < signature.length; i++) {
6281
+ typeMatched = false;
6282
+ currentSpec = signature[i].types;
6283
+ actualType = this._getTypeName(args[i]);
6284
+ for (var j = 0;j < currentSpec.length; j++) {
6285
+ if (this._typeMatches(actualType, currentSpec[j], args[i])) {
6286
+ typeMatched = true;
6287
+ break;
6288
+ }
6289
+ }
6290
+ if (!typeMatched) {
6291
+ var expected = currentSpec.map(function(typeIdentifier) {
6292
+ return TYPE_NAME_TABLE[typeIdentifier];
6293
+ }).join(",");
6294
+ throw new Error("TypeError: " + name + "() " + "expected argument " + (i + 1) + " to be type " + expected + " but received type " + TYPE_NAME_TABLE[actualType] + " instead.");
6933
6295
  }
6934
6296
  }
6935
- return results;
6936
- }
6937
- case "Arithmetic": {
6938
- const first = this.visit(node.left, value);
6939
- const second = this.visit(node.right, value);
6940
- switch (node.operator) {
6941
- case "Plus":
6942
- return add(first, second);
6943
- case "Minus":
6944
- return sub(first, second);
6945
- case "Multiply":
6946
- case "Star":
6947
- return mul(first, second);
6948
- case "Divide":
6949
- return divide(first, second);
6950
- case "Modulo":
6951
- return mod(first, second);
6952
- case "Div":
6953
- return div(first, second);
6954
- default:
6955
- throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
6956
- }
6957
- }
6958
- case "Unary": {
6959
- const operand = this.visit(node.operand, value);
6960
- switch (node.operator) {
6961
- case "Plus":
6962
- ensureNumbers(operand);
6963
- return operand;
6964
- case "Minus":
6965
- ensureNumbers(operand);
6966
- return -operand;
6967
- default:
6968
- throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
6297
+ },
6298
+ _typeMatches: function(actual, expected, argValue) {
6299
+ if (expected === TYPE_ANY) {
6300
+ return true;
6969
6301
  }
6970
- }
6971
- case "Comparator": {
6972
- const first = this.visit(node.left, value);
6973
- const second = this.visit(node.right, value);
6974
- switch (node.name) {
6975
- case "EQ":
6976
- return strictDeepEqual(first, second);
6977
- case "NE":
6978
- return !strictDeepEqual(first, second);
6302
+ if (expected === TYPE_ARRAY_STRING || expected === TYPE_ARRAY_NUMBER || expected === TYPE_ARRAY) {
6303
+ if (expected === TYPE_ARRAY) {
6304
+ return actual === TYPE_ARRAY;
6305
+ } else if (actual === TYPE_ARRAY) {
6306
+ var subtype;
6307
+ if (expected === TYPE_ARRAY_NUMBER) {
6308
+ subtype = TYPE_NUMBER;
6309
+ } else if (expected === TYPE_ARRAY_STRING) {
6310
+ subtype = TYPE_STRING;
6311
+ }
6312
+ for (var i = 0;i < argValue.length; i++) {
6313
+ if (!this._typeMatches(this._getTypeName(argValue[i]), subtype, argValue[i])) {
6314
+ return false;
6315
+ }
6316
+ }
6317
+ return true;
6318
+ }
6319
+ } else {
6320
+ return actual === expected;
6321
+ }
6322
+ },
6323
+ _getTypeName: function(obj) {
6324
+ switch (Object.prototype.toString.call(obj)) {
6325
+ case "[object String]":
6326
+ return TYPE_STRING;
6327
+ case "[object Number]":
6328
+ return TYPE_NUMBER;
6329
+ case "[object Array]":
6330
+ return TYPE_ARRAY;
6331
+ case "[object Boolean]":
6332
+ return TYPE_BOOLEAN;
6333
+ case "[object Null]":
6334
+ return TYPE_NULL;
6335
+ case "[object Object]":
6336
+ if (obj.jmespathType === TOK_EXPREF) {
6337
+ return TYPE_EXPREF;
6338
+ } else {
6339
+ return TYPE_OBJECT;
6340
+ }
6341
+ }
6342
+ },
6343
+ _functionStartsWith: function(resolvedArgs) {
6344
+ return resolvedArgs[0].lastIndexOf(resolvedArgs[1]) === 0;
6345
+ },
6346
+ _functionEndsWith: function(resolvedArgs) {
6347
+ var searchStr = resolvedArgs[0];
6348
+ var suffix = resolvedArgs[1];
6349
+ return searchStr.indexOf(suffix, searchStr.length - suffix.length) !== -1;
6350
+ },
6351
+ _functionReverse: function(resolvedArgs) {
6352
+ var typeName = this._getTypeName(resolvedArgs[0]);
6353
+ if (typeName === TYPE_STRING) {
6354
+ var originalStr = resolvedArgs[0];
6355
+ var reversedStr = "";
6356
+ for (var i = originalStr.length - 1;i >= 0; i--) {
6357
+ reversedStr += originalStr[i];
6358
+ }
6359
+ return reversedStr;
6360
+ } else {
6361
+ var reversedArray = resolvedArgs[0].slice(0);
6362
+ reversedArray.reverse();
6363
+ return reversedArray;
6364
+ }
6365
+ },
6366
+ _functionAbs: function(resolvedArgs) {
6367
+ return Math.abs(resolvedArgs[0]);
6368
+ },
6369
+ _functionCeil: function(resolvedArgs) {
6370
+ return Math.ceil(resolvedArgs[0]);
6371
+ },
6372
+ _functionAvg: function(resolvedArgs) {
6373
+ var sum = 0;
6374
+ var inputArray = resolvedArgs[0];
6375
+ for (var i = 0;i < inputArray.length; i++) {
6376
+ sum += inputArray[i];
6377
+ }
6378
+ return sum / inputArray.length;
6379
+ },
6380
+ _functionContains: function(resolvedArgs) {
6381
+ return resolvedArgs[0].indexOf(resolvedArgs[1]) >= 0;
6382
+ },
6383
+ _functionFloor: function(resolvedArgs) {
6384
+ return Math.floor(resolvedArgs[0]);
6385
+ },
6386
+ _functionLength: function(resolvedArgs) {
6387
+ if (!isObject(resolvedArgs[0])) {
6388
+ return resolvedArgs[0].length;
6389
+ } else {
6390
+ return Object.keys(resolvedArgs[0]).length;
6391
+ }
6392
+ },
6393
+ _functionMap: function(resolvedArgs) {
6394
+ var mapped = [];
6395
+ var interpreter = this._interpreter;
6396
+ var exprefNode = resolvedArgs[0];
6397
+ var elements = resolvedArgs[1];
6398
+ for (var i = 0;i < elements.length; i++) {
6399
+ mapped.push(interpreter.visit(exprefNode, elements[i]));
6400
+ }
6401
+ return mapped;
6402
+ },
6403
+ _functionMerge: function(resolvedArgs) {
6404
+ var merged = {};
6405
+ for (var i = 0;i < resolvedArgs.length; i++) {
6406
+ var current = resolvedArgs[i];
6407
+ for (var key in current) {
6408
+ merged[key] = current[key];
6409
+ }
6979
6410
  }
6980
- if (typeof first !== "number" || typeof second !== "number") {
6411
+ return merged;
6412
+ },
6413
+ _functionMax: function(resolvedArgs) {
6414
+ if (resolvedArgs[0].length > 0) {
6415
+ var typeName = this._getTypeName(resolvedArgs[0][0]);
6416
+ if (typeName === TYPE_NUMBER) {
6417
+ return Math.max.apply(Math, resolvedArgs[0]);
6418
+ } else {
6419
+ var elements = resolvedArgs[0];
6420
+ var maxElement = elements[0];
6421
+ for (var i = 1;i < elements.length; i++) {
6422
+ if (maxElement.localeCompare(elements[i]) < 0) {
6423
+ maxElement = elements[i];
6424
+ }
6425
+ }
6426
+ return maxElement;
6427
+ }
6428
+ } else {
6981
6429
  return null;
6982
6430
  }
6983
- switch (node.name) {
6984
- case "GT":
6985
- return first > second;
6986
- case "GTE":
6987
- return first >= second;
6988
- case "LT":
6989
- return first < second;
6990
- case "LTE":
6991
- return first <= second;
6431
+ },
6432
+ _functionMin: function(resolvedArgs) {
6433
+ if (resolvedArgs[0].length > 0) {
6434
+ var typeName = this._getTypeName(resolvedArgs[0][0]);
6435
+ if (typeName === TYPE_NUMBER) {
6436
+ return Math.min.apply(Math, resolvedArgs[0]);
6437
+ } else {
6438
+ var elements = resolvedArgs[0];
6439
+ var minElement = elements[0];
6440
+ for (var i = 1;i < elements.length; i++) {
6441
+ if (elements[i].localeCompare(minElement) < 0) {
6442
+ minElement = elements[i];
6443
+ }
6444
+ }
6445
+ return minElement;
6446
+ }
6447
+ } else {
6448
+ return null;
6992
6449
  }
6993
- }
6994
- case "Flatten": {
6995
- const original = this.visit(node.child, value);
6996
- return Array.isArray(original) ? original.flat() : null;
6997
- }
6998
- case "Root":
6999
- return this._rootValue;
7000
- case "MultiSelectList": {
7001
- const collected = [];
7002
- for (const child of node.children) {
7003
- collected.push(this.visit(child, value));
6450
+ },
6451
+ _functionSum: function(resolvedArgs) {
6452
+ var sum = 0;
6453
+ var listToSum = resolvedArgs[0];
6454
+ for (var i = 0;i < listToSum.length; i++) {
6455
+ sum += listToSum[i];
7004
6456
  }
7005
- return collected;
7006
- }
7007
- case "MultiSelectHash": {
7008
- const collected = {};
7009
- for (const child of node.children) {
7010
- collected[child.name] = this.visit(child.value, value);
6457
+ return sum;
6458
+ },
6459
+ _functionType: function(resolvedArgs) {
6460
+ switch (this._getTypeName(resolvedArgs[0])) {
6461
+ case TYPE_NUMBER:
6462
+ return "number";
6463
+ case TYPE_STRING:
6464
+ return "string";
6465
+ case TYPE_ARRAY:
6466
+ return "array";
6467
+ case TYPE_OBJECT:
6468
+ return "object";
6469
+ case TYPE_BOOLEAN:
6470
+ return "boolean";
6471
+ case TYPE_EXPREF:
6472
+ return "expref";
6473
+ case TYPE_NULL:
6474
+ return "null";
7011
6475
  }
7012
- return collected;
7013
- }
7014
- case "OrExpression": {
7015
- const result = this.visit(node.left, value);
7016
- if (isFalse(result)) {
7017
- return this.visit(node.right, value);
6476
+ },
6477
+ _functionKeys: function(resolvedArgs) {
6478
+ return Object.keys(resolvedArgs[0]);
6479
+ },
6480
+ _functionValues: function(resolvedArgs) {
6481
+ var obj = resolvedArgs[0];
6482
+ var keys = Object.keys(obj);
6483
+ var values = [];
6484
+ for (var i = 0;i < keys.length; i++) {
6485
+ values.push(obj[keys[i]]);
6486
+ }
6487
+ return values;
6488
+ },
6489
+ _functionJoin: function(resolvedArgs) {
6490
+ var joinChar = resolvedArgs[0];
6491
+ var listJoin = resolvedArgs[1];
6492
+ return listJoin.join(joinChar);
6493
+ },
6494
+ _functionToArray: function(resolvedArgs) {
6495
+ if (this._getTypeName(resolvedArgs[0]) === TYPE_ARRAY) {
6496
+ return resolvedArgs[0];
6497
+ } else {
6498
+ return [resolvedArgs[0]];
7018
6499
  }
7019
- return result;
7020
- }
7021
- case "AndExpression": {
7022
- const result = this.visit(node.left, value);
7023
- if (isFalse(result)) {
7024
- return result;
6500
+ },
6501
+ _functionToString: function(resolvedArgs) {
6502
+ if (this._getTypeName(resolvedArgs[0]) === TYPE_STRING) {
6503
+ return resolvedArgs[0];
6504
+ } else {
6505
+ return JSON.stringify(resolvedArgs[0]);
7025
6506
  }
7026
- return this.visit(node.right, value);
7027
- }
7028
- case "NotExpression":
7029
- return isFalse(this.visit(node.child, value));
7030
- case "Literal":
7031
- return node.value;
7032
- case "Pipe":
7033
- return this.visit(node.right, this.visit(node.left, value));
7034
- case "Function": {
7035
- const args = [];
7036
- for (const child of node.children) {
7037
- args.push(this.visit(child, value));
6507
+ },
6508
+ _functionToNumber: function(resolvedArgs) {
6509
+ var typeName = this._getTypeName(resolvedArgs[0]);
6510
+ var convertedValue;
6511
+ if (typeName === TYPE_NUMBER) {
6512
+ return resolvedArgs[0];
6513
+ } else if (typeName === TYPE_STRING) {
6514
+ convertedValue = +resolvedArgs[0];
6515
+ if (!isNaN(convertedValue)) {
6516
+ return convertedValue;
6517
+ }
7038
6518
  }
7039
- return this.runtime.callFunction(node.name, args);
7040
- }
7041
- case "ExpressionReference":
7042
- return {
7043
- expref: true,
7044
- ...node.child
6519
+ return null;
6520
+ },
6521
+ _functionNotNull: function(resolvedArgs) {
6522
+ for (var i = 0;i < resolvedArgs.length; i++) {
6523
+ if (this._getTypeName(resolvedArgs[i]) !== TYPE_NULL) {
6524
+ return resolvedArgs[i];
6525
+ }
6526
+ }
6527
+ return null;
6528
+ },
6529
+ _functionSort: function(resolvedArgs) {
6530
+ var sortedArray = resolvedArgs[0].slice(0);
6531
+ sortedArray.sort();
6532
+ return sortedArray;
6533
+ },
6534
+ _functionSortBy: function(resolvedArgs) {
6535
+ var sortedArray = resolvedArgs[0].slice(0);
6536
+ if (sortedArray.length === 0) {
6537
+ return sortedArray;
6538
+ }
6539
+ var interpreter = this._interpreter;
6540
+ var exprefNode = resolvedArgs[1];
6541
+ var requiredType = this._getTypeName(interpreter.visit(exprefNode, sortedArray[0]));
6542
+ if ([TYPE_NUMBER, TYPE_STRING].indexOf(requiredType) < 0) {
6543
+ throw new Error("TypeError");
6544
+ }
6545
+ var that = this;
6546
+ var decorated = [];
6547
+ for (var i = 0;i < sortedArray.length; i++) {
6548
+ decorated.push([i, sortedArray[i]]);
6549
+ }
6550
+ decorated.sort(function(a, b) {
6551
+ var exprA = interpreter.visit(exprefNode, a[1]);
6552
+ var exprB = interpreter.visit(exprefNode, b[1]);
6553
+ if (that._getTypeName(exprA) !== requiredType) {
6554
+ throw new Error("TypeError: expected " + requiredType + ", received " + that._getTypeName(exprA));
6555
+ } else if (that._getTypeName(exprB) !== requiredType) {
6556
+ throw new Error("TypeError: expected " + requiredType + ", received " + that._getTypeName(exprB));
6557
+ }
6558
+ if (exprA > exprB) {
6559
+ return 1;
6560
+ } else if (exprA < exprB) {
6561
+ return -1;
6562
+ } else {
6563
+ return a[0] - b[0];
6564
+ }
6565
+ });
6566
+ for (var j = 0;j < decorated.length; j++) {
6567
+ sortedArray[j] = decorated[j][1];
6568
+ }
6569
+ return sortedArray;
6570
+ },
6571
+ _functionMaxBy: function(resolvedArgs) {
6572
+ var exprefNode = resolvedArgs[1];
6573
+ var resolvedArray = resolvedArgs[0];
6574
+ var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
6575
+ var maxNumber = -Infinity;
6576
+ var maxRecord;
6577
+ var current;
6578
+ for (var i = 0;i < resolvedArray.length; i++) {
6579
+ current = keyFunction(resolvedArray[i]);
6580
+ if (current > maxNumber) {
6581
+ maxNumber = current;
6582
+ maxRecord = resolvedArray[i];
6583
+ }
6584
+ }
6585
+ return maxRecord;
6586
+ },
6587
+ _functionMinBy: function(resolvedArgs) {
6588
+ var exprefNode = resolvedArgs[1];
6589
+ var resolvedArray = resolvedArgs[0];
6590
+ var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
6591
+ var minNumber = Infinity;
6592
+ var minRecord;
6593
+ var current;
6594
+ for (var i = 0;i < resolvedArray.length; i++) {
6595
+ current = keyFunction(resolvedArray[i]);
6596
+ if (current < minNumber) {
6597
+ minNumber = current;
6598
+ minRecord = resolvedArray[i];
6599
+ }
6600
+ }
6601
+ return minRecord;
6602
+ },
6603
+ createKeyFunction: function(exprefNode, allowedTypes) {
6604
+ var that = this;
6605
+ var interpreter = this._interpreter;
6606
+ var keyFunc = function(x) {
6607
+ var current = interpreter.visit(exprefNode, x);
6608
+ if (allowedTypes.indexOf(that._getTypeName(current)) < 0) {
6609
+ var msg = "TypeError: expected one of " + allowedTypes + ", received " + that._getTypeName(current);
6610
+ throw new Error(msg);
6611
+ }
6612
+ return current;
7045
6613
  };
7046
- case "Current":
7047
- case "Identity":
7048
- return value;
7049
- }
7050
- }
7051
- computeSliceParams(arrayLength, sliceNode) {
7052
- let { start, stop, step } = sliceNode;
7053
- if (step === null) {
7054
- step = 1;
7055
- } else if (step === 0) {
7056
- const error = new Error("Invalid value: slice step cannot be 0");
7057
- error.name = "RuntimeError";
7058
- throw error;
7059
- }
7060
- start = start === null ? step < 0 ? arrayLength - 1 : 0 : this.capSliceRange(arrayLength, start, step);
7061
- stop = stop === null ? step < 0 ? -1 : arrayLength : this.capSliceRange(arrayLength, stop, step);
7062
- return { start, stop, step };
7063
- }
7064
- capSliceRange(arrayLength, actualValue, step) {
7065
- let nextActualValue = actualValue;
7066
- if (nextActualValue < 0) {
7067
- nextActualValue += arrayLength;
7068
- if (nextActualValue < 0) {
7069
- nextActualValue = step < 0 ? -1 : 0;
7070
- }
7071
- } else if (nextActualValue >= arrayLength) {
7072
- nextActualValue = step < 0 ? arrayLength - 1 : arrayLength;
7073
- }
7074
- return nextActualValue;
7075
- }
7076
- slice(collection, start, end, step) {
7077
- const result = [];
7078
- if (step > 0) {
7079
- for (let i = start;i < end; i += step) {
7080
- result.push(collection[i]);
7081
- }
7082
- } else {
7083
- for (let i = start;i > end; i += step) {
7084
- result.push(collection[i]);
6614
+ return keyFunc;
7085
6615
  }
7086
- }
7087
- return result;
7088
- }
7089
- };
7090
- var TreeInterpreterInstance;
7091
- var TreeInterpreter_default;
7092
- var TYPE_ANY = 1;
7093
- var TYPE_ARRAY = 3;
7094
- var TYPE_ARRAY_ARRAY = 11;
7095
- var TYPE_ARRAY_NUMBER = 8;
7096
- var TYPE_ARRAY_OBJECT = 10;
7097
- var TYPE_ARRAY_STRING = 9;
7098
- var TYPE_BOOLEAN = 5;
7099
- var TYPE_EXPREF = 6;
7100
- var TYPE_NULL = 7;
7101
- var TYPE_NUMBER = 0;
7102
- var TYPE_OBJECT = 4;
7103
- var TYPE_STRING = 2;
7104
- var registerFunction = (functionName, customFunction, signature, options) => {
7105
- TreeInterpreter_default.runtime.registerFunction(functionName, customFunction, signature, options);
7106
- };
7107
- var register = (name, customFunction, signature, options) => {
7108
- return TreeInterpreter_default.runtime.register(name, customFunction, signature, options);
7109
- };
7110
- var unregisterFunction = (name) => {
7111
- return TreeInterpreter_default.runtime.unregister(name);
7112
- };
7113
- var isRegistered = (name) => {
7114
- return TreeInterpreter_default.runtime.isRegistered(name);
7115
- };
7116
- var getRegisteredFunctions = () => {
7117
- return TreeInterpreter_default.runtime.getRegistered();
7118
- };
7119
- var getCustomFunctions = () => {
7120
- return TreeInterpreter_default.runtime.getCustomFunctions();
7121
- };
7122
- var clearCustomFunctions = () => {
7123
- TreeInterpreter_default.runtime.clearCustomFunctions();
7124
- };
7125
- var TreeInterpreter2;
7126
- var jmespath;
7127
- var init_dist = __esm(() => {
7128
- basicTokens = {
7129
- "(": "Lparen",
7130
- ")": "Rparen",
7131
- "*": "Star",
7132
- ",": "Comma",
7133
- ".": "Dot",
7134
- ":": "Colon",
7135
- "@": "Current",
7136
- "]": "Rbracket",
7137
- "{": "Lbrace",
7138
- "}": "Rbrace",
7139
- "+": "Plus",
7140
- "%": "Modulo",
7141
- "?": "Question",
7142
- "−": "Minus",
7143
- "×": "Multiply",
7144
- "÷": "Divide"
7145
- };
7146
- operatorStartToken = {
7147
- "!": true,
7148
- "<": true,
7149
- "=": true,
7150
- ">": true,
7151
- "&": true,
7152
- "|": true,
7153
- "/": true
7154
- };
7155
- skipChars = {
7156
- "\t": true,
7157
- "\n": true,
7158
- "\r": true,
7159
- " ": true
7160
- };
7161
- Lexer = new StreamLexer;
7162
- Lexer_default = Lexer;
7163
- bindingPower = {
7164
- ["EOF"]: 0,
7165
- ["Variable"]: 0,
7166
- ["UnquotedIdentifier"]: 0,
7167
- ["QuotedIdentifier"]: 0,
7168
- ["Rbracket"]: 0,
7169
- ["Rparen"]: 0,
7170
- ["Comma"]: 0,
7171
- ["Rbrace"]: 0,
7172
- ["Number"]: 0,
7173
- ["Current"]: 0,
7174
- ["Expref"]: 0,
7175
- ["Root"]: 0,
7176
- ["Assign"]: 1,
7177
- ["Pipe"]: 1,
7178
- ["Question"]: 2,
7179
- ["Or"]: 3,
7180
- ["And"]: 4,
7181
- ["EQ"]: 5,
7182
- ["GT"]: 5,
7183
- ["LT"]: 5,
7184
- ["GTE"]: 5,
7185
- ["LTE"]: 5,
7186
- ["NE"]: 5,
7187
- ["Minus"]: 6,
7188
- ["Plus"]: 6,
7189
- ["Div"]: 7,
7190
- ["Divide"]: 7,
7191
- ["Modulo"]: 7,
7192
- ["Multiply"]: 7,
7193
- ["Flatten"]: 9,
7194
- ["Star"]: 20,
7195
- ["Filter"]: 21,
7196
- ["Dot"]: 40,
7197
- ["Not"]: 45,
7198
- ["Lbrace"]: 50,
7199
- ["Lbracket"]: 55,
7200
- ["Lparen"]: 60
7201
- };
7202
- Parser = new TokenParser;
7203
- Parser_default = Parser;
7204
- emptyScopeChain = new ScopeChain;
7205
- TreeInterpreterInstance = new TreeInterpreter;
7206
- TreeInterpreter_default = TreeInterpreterInstance;
7207
- TreeInterpreter2 = TreeInterpreter_default;
7208
- jmespath = {
7209
- compile,
7210
- registerFunction,
7211
- register,
7212
- unregisterFunction,
7213
- isRegistered,
7214
- getRegisteredFunctions,
7215
- getCustomFunctions,
7216
- clearCustomFunctions,
7217
- search,
7218
- tokenize,
7219
- TreeInterpreter: TreeInterpreter2,
7220
- TYPE_ANY,
7221
- TYPE_ARRAY_NUMBER,
7222
- TYPE_ARRAY_STRING,
7223
- TYPE_ARRAY,
7224
- TYPE_BOOLEAN,
7225
- TYPE_EXPREF,
7226
- TYPE_NULL,
7227
- TYPE_NUMBER,
7228
- TYPE_OBJECT,
7229
- TYPE_STRING
7230
- };
6616
+ };
6617
+ function compile(stream) {
6618
+ var parser = new Parser;
6619
+ var ast = parser.parse(stream);
6620
+ return ast;
6621
+ }
6622
+ function tokenize(stream) {
6623
+ var lexer = new Lexer;
6624
+ return lexer.tokenize(stream);
6625
+ }
6626
+ function search(data, expression) {
6627
+ var parser = new Parser;
6628
+ var runtime = new Runtime;
6629
+ var interpreter = new TreeInterpreter(runtime);
6630
+ runtime._interpreter = interpreter;
6631
+ var node = parser.parse(expression);
6632
+ return interpreter.search(node, data);
6633
+ }
6634
+ exports2.tokenize = tokenize;
6635
+ exports2.compile = compile;
6636
+ exports2.search = search;
6637
+ exports2.strictDeepEqual = strictDeepEqual;
6638
+ })(typeof exports === "undefined" ? exports.jmespath = {} : exports);
7231
6639
  });
7232
6640
  var require_error = __commonJS(function(exports) {
7233
6641
 
@@ -7551,10 +6959,10 @@ var require_help = __commonJS(function(exports) {
7551
6959
  });
7552
6960
  output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
7553
6961
  }
7554
- const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub2) => sub2.helpGroup() || "Commands:");
6962
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
7555
6963
  commandGroups.forEach((commands, group) => {
7556
- const commandList = commands.map((sub2) => {
7557
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub2)), helper.styleSubcommandDescription(helper.subcommandDescription(sub2)));
6964
+ const commandList = commands.map((sub) => {
6965
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
7558
6966
  });
7559
6967
  output = output.concat(this.formatItemList(group, commandList, helper));
7560
6968
  });
@@ -9895,13 +9303,13 @@ function redactValueDetectors(value, maxLength = MAX_VALUE_LENGTH) {
9895
9303
  out = out.replace(EMAIL_PATTERN, (match) => `email#${pseudonymize(match)}`);
9896
9304
  out = out.replace(UUID_PATTERN, (match) => `uuid#${pseudonymize(match)}`);
9897
9305
  out = out.replace(HOST_PORT_PATTERN, (match) => {
9898
- const split2 = match.lastIndexOf(":");
9899
- const host = match.slice(0, split2);
9306
+ const split = match.lastIndexOf(":");
9307
+ const host = match.slice(0, split);
9900
9308
  const extension = host.slice(host.lastIndexOf(".") + 1).toLowerCase();
9901
9309
  if (SOURCE_FILE_EXTENSIONS.has(extension)) {
9902
9310
  return match;
9903
9311
  }
9904
- return `host#${pseudonymize(host)}:${match.slice(split2 + 1)}`;
9312
+ return `host#${pseudonymize(host)}:${match.slice(split + 1)}`;
9905
9313
  });
9906
9314
  out = out.replace(PADDED_BASE64_PATTERN, () => REDACTED);
9907
9315
  out = out.replace(BASE64_WITH_PLUS_PATTERN, (match) => match.includes("+") ? REDACTED : match);
@@ -10082,8 +9490,8 @@ function setExitCode(code) {
10082
9490
  process.exitCode = code;
10083
9491
  }
10084
9492
  function createStorage() {
10085
- const [error, mod2] = catchError(() => __require("node:async_hooks"));
10086
- if (error || typeof mod2?.AsyncLocalStorage !== "function") {
9493
+ const [error, mod] = catchError(() => __require("node:async_hooks"));
9494
+ if (error || typeof mod?.AsyncLocalStorage !== "function") {
10087
9495
  return {
10088
9496
  getStore: () => {
10089
9497
  return;
@@ -10091,7 +9499,7 @@ function createStorage() {
10091
9499
  run: (_store, fn) => fn()
10092
9500
  };
10093
9501
  }
10094
- return new mod2.AsyncLocalStorage;
9502
+ return new mod.AsyncLocalStorage;
10095
9503
  }
10096
9504
  var storageSingleton = singleton("OutputStorage");
10097
9505
  var sinkSlot = singleton("OutputSink");
@@ -10306,13 +9714,13 @@ var jmespathSlot = singleton("JmespathCodec");
10306
9714
  async function loadOutputCodecsAsync(needed) {
10307
9715
  const loads = [];
10308
9716
  if (needed.yaml && yamlSlot.get() === undefined) {
10309
- loads.push(Promise.resolve().then(() => (init_js_yaml(), exports_js_yaml)).then((mod2) => {
10310
- yamlSlot.set(mod2);
9717
+ loads.push(Promise.resolve().then(() => (init_js_yaml(), exports_js_yaml)).then((mod) => {
9718
+ yamlSlot.set(mod);
10311
9719
  }));
10312
9720
  }
10313
9721
  if (needed.filter && jmespathSlot.get() === undefined) {
10314
- loads.push(Promise.resolve().then(() => (init_dist(), exports_dist)).then((mod2) => {
10315
- jmespathSlot.set(mod2);
9722
+ loads.push(Promise.resolve().then(() => __toESM(require_jmespath(), 1)).then((mod) => {
9723
+ jmespathSlot.set(mod);
10316
9724
  }));
10317
9725
  }
10318
9726
  await Promise.all(loads);
@@ -11067,8 +10475,8 @@ class TelemetryService {
11067
10475
  }
11068
10476
  var TIMINGS_ENV_VAR = "UIP_TIMINGS";
11069
10477
  function createStorage2() {
11070
- const [error, mod2] = catchError(() => __require("node:async_hooks"));
11071
- if (error || typeof mod2?.AsyncLocalStorage !== "function") {
10478
+ const [error, mod] = catchError(() => __require("node:async_hooks"));
10479
+ if (error || typeof mod?.AsyncLocalStorage !== "function") {
11072
10480
  return {
11073
10481
  getStore: () => {
11074
10482
  return;
@@ -11076,7 +10484,7 @@ function createStorage2() {
11076
10484
  run: (_store, fn) => fn()
11077
10485
  };
11078
10486
  }
11079
- return new mod2.AsyncLocalStorage;
10487
+ return new mod.AsyncLocalStorage;
11080
10488
  }
11081
10489
  var storageSlot = singleton("TimingStorage");
11082
10490
  var stateSlot = singleton("Timings");
@@ -13767,8 +13175,8 @@ function addSdkUserAgentHeader(headers, userAgent) {
13767
13175
  }
13768
13176
  var package_default = {
13769
13177
  name: "@uipath/project-packager",
13770
- license: "MIT",
13771
- version: "1.202.0-preview.142",
13178
+ license: "SEE LICENSE IN LICENSE.txt",
13179
+ version: "1.202.0",
13772
13180
  description: "UiPath Project Packager - core library for packing individual UiPath projects",
13773
13181
  type: "module",
13774
13182
  main: "./dist/index.js",
@@ -14219,4 +13627,4 @@ export {
14219
13627
  signNupkgsAsync
14220
13628
  };
14221
13629
 
14222
- //# debugId=FE4C63EBB2A0CBE864756E2164756E21
13630
+ //# debugId=892A7E5B638134F564756E2164756E21