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