@uipath/solution-sdk 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.
@@ -4078,2006 +4078,1483 @@ var init_js_yaml = __esm(() => {
4078
4078
  } = yaml);
4079
4079
  });
4080
4080
 
4081
- // ../../node_modules/@jmespath-community/jmespath/dist/index.mjs
4082
- var exports_dist = {};
4083
- __export(exports_dist, {
4084
- Scope: () => Scope,
4085
- TYPE_ANY: () => TYPE_ANY,
4086
- TYPE_ARRAY: () => TYPE_ARRAY,
4087
- TYPE_ARRAY_ARRAY: () => TYPE_ARRAY_ARRAY,
4088
- TYPE_ARRAY_NUMBER: () => TYPE_ARRAY_NUMBER,
4089
- TYPE_ARRAY_OBJECT: () => TYPE_ARRAY_OBJECT,
4090
- TYPE_ARRAY_STRING: () => TYPE_ARRAY_STRING,
4091
- TYPE_BOOLEAN: () => TYPE_BOOLEAN,
4092
- TYPE_EXPREF: () => TYPE_EXPREF,
4093
- TYPE_NULL: () => TYPE_NULL,
4094
- TYPE_NUMBER: () => TYPE_NUMBER,
4095
- TYPE_OBJECT: () => TYPE_OBJECT,
4096
- TYPE_STRING: () => TYPE_STRING,
4097
- TreeInterpreter: () => TreeInterpreter2,
4098
- clearCustomFunctions: () => clearCustomFunctions,
4099
- compile: () => compile,
4100
- default: () => jmespath,
4101
- getCustomFunctions: () => getCustomFunctions,
4102
- getRegisteredFunctions: () => getRegisteredFunctions,
4103
- isRegistered: () => isRegistered,
4104
- jmespath: () => jmespath,
4105
- register: () => register,
4106
- registerFunction: () => registerFunction,
4107
- search: () => search,
4108
- tokenize: () => tokenize,
4109
- unregisterFunction: () => unregisterFunction
4110
- });
4111
- function compile(expression, options) {
4112
- const nodeTree = Parser_default.parse(expression, options);
4113
- return nodeTree;
4114
- }
4115
- function tokenize(expression, options) {
4116
- return Lexer_default.tokenize(expression, options);
4117
- }
4118
- function search(data, expression, options) {
4119
- const nodeTree = Parser_default.parse(expression, options);
4120
- return TreeInterpreter_default.search(nodeTree, data);
4121
- }
4122
- function Scope() {
4123
- return new ScopeChain;
4124
- }
4125
- var isObject = (obj) => {
4126
- return obj !== null && Object.prototype.toString.call(obj) === "[object Object]";
4127
- }, strictDeepEqual = (first, second) => {
4128
- if (first === second) {
4129
- return true;
4130
- }
4131
- if (typeof first !== typeof second) {
4132
- return false;
4133
- }
4134
- if (Array.isArray(first) && Array.isArray(second)) {
4135
- if (first.length !== second.length) {
4136
- return false;
4137
- }
4138
- for (let i = 0;i < first.length; i += 1) {
4139
- if (!strictDeepEqual(first[i], second[i])) {
4140
- return false;
4141
- }
4142
- }
4143
- return true;
4144
- }
4145
- if (isObject(first) && isObject(second)) {
4146
- const firstEntries = Object.entries(first);
4147
- const secondKeys = new Set(Object.keys(second));
4148
- if (firstEntries.length !== secondKeys.size) {
4149
- return false;
4150
- }
4151
- for (const [key, value] of firstEntries) {
4152
- if (!strictDeepEqual(value, second[key])) {
4081
+ // ../../node_modules/jmespath/jmespath.js
4082
+ var require_jmespath = __commonJS(function(exports) {
4083
+ (function(exports2) {
4084
+ function isArray(obj) {
4085
+ if (obj !== null) {
4086
+ return Object.prototype.toString.call(obj) === "[object Array]";
4087
+ } else {
4153
4088
  return false;
4154
4089
  }
4155
- secondKeys.delete(key);
4156
- }
4157
- return secondKeys.size === 0;
4158
- }
4159
- return false;
4160
- }, isFalse = (obj) => {
4161
- if (obj === null || obj === undefined || obj === false) {
4162
- return true;
4163
- }
4164
- if (typeof obj === "string") {
4165
- return obj === "";
4166
- }
4167
- if (typeof obj === "object") {
4168
- if (Array.isArray(obj)) {
4169
- return obj.length === 0;
4170
4090
  }
4171
- if (obj === null) {
4172
- return true;
4173
- }
4174
- return Object.keys(obj).length === 0;
4175
- }
4176
- return false;
4177
- }, isAlpha = (ch) => {
4178
- return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
4179
- }, isNum = (ch) => {
4180
- return ch >= "0" && ch <= "9" || ch === "-";
4181
- }, isAlphaNum = (ch) => {
4182
- return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
4183
- }, ensureInteger = (value) => {
4184
- if (!(typeof value === "number") || Math.floor(value) !== value) {
4185
- throw new Error("invalid-value: expecting an integer.");
4186
- }
4187
- return value;
4188
- }, ensurePositiveInteger = (value) => {
4189
- if (!(typeof value === "number") || value < 0 || Math.floor(value) !== value) {
4190
- throw new Error("invalid-value: expecting a non-negative integer.");
4191
- }
4192
- return value;
4193
- }, ensureNumbers = (...operands) => {
4194
- for (let i = 0;i < operands.length; i++) {
4195
- if (operands[i] === null || operands[i] === undefined) {
4196
- throw new Error("not-a-number: undefined");
4197
- }
4198
- if (typeof operands[i] !== "number") {
4199
- throw new Error("not-a-number");
4200
- }
4201
- }
4202
- }, notZero = (n) => {
4203
- n = +n;
4204
- if (!n) {
4205
- throw new Error("not-a-number: divide by zero");
4206
- }
4207
- return n;
4208
- }, add = (left, right) => {
4209
- ensureNumbers(left, right);
4210
- const result = left + right;
4211
- return result;
4212
- }, sub = (left, right) => {
4213
- ensureNumbers(left, right);
4214
- const result = left - right;
4215
- return result;
4216
- }, mul = (left, right) => {
4217
- ensureNumbers(left, right);
4218
- const result = left * right;
4219
- return result;
4220
- }, divide = (left, right) => {
4221
- ensureNumbers(left, right);
4222
- const result = left / notZero(right);
4223
- return result;
4224
- }, div = (left, right) => {
4225
- ensureNumbers(left, right);
4226
- const result = Math.floor(left / notZero(right));
4227
- return result;
4228
- }, mod = (left, right) => {
4229
- ensureNumbers(left, right);
4230
- const result = left % right;
4231
- return result;
4232
- }, findFirst = (subject, sub2, start, end) => {
4233
- if (!subject || !sub2) {
4234
- return null;
4235
- }
4236
- start = Math.max(ensureInteger(start = start || 0), 0);
4237
- end = Math.min(ensureInteger(end = end || subject.length), subject.length);
4238
- const offset = subject.slice(start, end).indexOf(sub2);
4239
- return offset === -1 ? null : offset + start;
4240
- }, findLast = (subject, sub2, start, end) => {
4241
- if (!subject || !sub2) {
4242
- return null;
4243
- }
4244
- start = Math.max(ensureInteger(start = start || 0), 0);
4245
- end = Math.min(ensureInteger(end = end || subject.length), subject.length);
4246
- const offset = subject.slice(start, end).lastIndexOf(sub2);
4247
- const result = offset === -1 ? null : offset + start;
4248
- return result;
4249
- }, lower = (subject) => subject.toLowerCase(), ensurePadFuncParams = (name, width, padding) => {
4250
- padding = padding || " ";
4251
- if (padding.length > 1) {
4252
- throw new Error(`invalid value, ${name} expects its 'pad' parameter to be a valid string with a single codepoint`);
4253
- }
4254
- ensurePositiveInteger(width);
4255
- return padding;
4256
- }, padLeft = (subject, width, padding) => {
4257
- padding = ensurePadFuncParams("pad_left", width, padding);
4258
- return subject && subject.padStart(width, padding) || "";
4259
- }, padRight = (subject, width, padding) => {
4260
- padding = ensurePadFuncParams("pad_right", width, padding);
4261
- return subject && subject.padEnd(width, padding) || "";
4262
- }, replace = (subject, string, by, count) => {
4263
- if (count === 0) {
4264
- return subject;
4265
- }
4266
- if (!count) {
4267
- return subject.split(string).join(by);
4268
- }
4269
- ensurePositiveInteger(count);
4270
- [...Array(count).keys()].map(() => subject = subject.replace(string, by));
4271
- return subject;
4272
- }, split = (subject, search2, count) => {
4273
- if (subject.length == 0 && search2.length === 0) {
4274
- return [];
4275
- }
4276
- if (count === null || count === undefined) {
4277
- return subject.split(search2);
4278
- }
4279
- ensurePositiveInteger(count);
4280
- if (count === 0) {
4281
- return [subject];
4282
- }
4283
- const split2 = subject.split(search2);
4284
- return [...split2.slice(0, count), split2.slice(count).join(search2)];
4285
- }, trim = (subject, chars) => {
4286
- return trimLeft(trimRight(subject, chars), chars);
4287
- }, trimLeft = (subject, chars) => {
4288
- return trimImpl(subject, (list) => new RegExp(`^[${list}]*(.*?)`), chars);
4289
- }, trimRight = (subject, chars) => {
4290
- return trimImpl(subject, (list) => new RegExp(`(.*?)[${list}]*$`), chars);
4291
- }, trimImpl = (subject, regExper, chars) => {
4292
- const pattern = chars ? chars.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") : "\\s…";
4293
- return subject.replace(regExper(pattern), "$1");
4294
- }, upper = (subject) => subject.toUpperCase(), basicTokens, operatorStartToken, skipChars, StreamLexer = class {
4295
- _current = 0;
4296
- _enable_legacy_literals = false;
4297
- tokenize(stream, options) {
4298
- const tokens = [];
4299
- this._current = 0;
4300
- this._enable_legacy_literals = options?.enable_legacy_literals || false;
4301
- let start;
4302
- let identifier;
4303
- let token;
4304
- while (this._current < stream.length) {
4305
- if (isAlpha(stream[this._current])) {
4306
- start = this._current;
4307
- identifier = this.consumeUnquotedIdentifier(stream);
4308
- tokens.push({
4309
- start,
4310
- type: "UnquotedIdentifier",
4311
- value: identifier
4312
- });
4313
- } else if (basicTokens[stream[this._current]] !== undefined) {
4314
- tokens.push({
4315
- start: this._current,
4316
- type: basicTokens[stream[this._current]],
4317
- value: stream[this._current]
4318
- });
4319
- this._current += 1;
4320
- } else if (stream[this._current] === "$") {
4321
- start = this._current;
4322
- if (this._current + 1 < stream.length && isAlpha(stream[this._current + 1])) {
4323
- this._current += 1;
4324
- identifier = this.consumeUnquotedIdentifier(stream);
4325
- tokens.push({
4326
- start,
4327
- type: "Variable",
4328
- value: identifier
4329
- });
4330
- } else {
4331
- tokens.push({
4332
- start,
4333
- type: "Root",
4334
- value: stream[this._current]
4335
- });
4336
- this._current += 1;
4337
- }
4338
- } else if (stream[this._current] === "-") {
4339
- if (this._current + 1 < stream.length && isNum(stream[this._current + 1])) {
4340
- const token2 = this.consumeNumber(stream);
4341
- token2 && tokens.push(token2);
4342
- } else {
4343
- const token2 = {
4344
- start: this._current,
4345
- type: "Minus",
4346
- value: "-"
4347
- };
4348
- tokens.push(token2);
4349
- this._current += 1;
4350
- }
4351
- } else if (isNum(stream[this._current])) {
4352
- token = this.consumeNumber(stream);
4353
- tokens.push(token);
4354
- } else if (stream[this._current] === "[") {
4355
- token = this.consumeLBracket(stream);
4356
- tokens.push(token);
4357
- } else if (stream[this._current] === '"') {
4358
- start = this._current;
4359
- identifier = this.consumeQuotedIdentifier(stream);
4360
- tokens.push({
4361
- start,
4362
- type: "QuotedIdentifier",
4363
- value: identifier
4364
- });
4365
- } else if (stream[this._current] === `'`) {
4366
- start = this._current;
4367
- identifier = this.consumeRawStringLiteral(stream);
4368
- tokens.push({
4369
- start,
4370
- type: "Literal",
4371
- value: identifier
4372
- });
4373
- } else if (stream[this._current] === "`") {
4374
- start = this._current;
4375
- const literal = this.consumeLiteral(stream);
4376
- tokens.push({
4377
- start,
4378
- type: "Literal",
4379
- value: literal
4380
- });
4381
- } else if (operatorStartToken[stream[this._current]] !== undefined) {
4382
- token = this.consumeOperator(stream);
4383
- token && tokens.push(token);
4384
- } else if (skipChars[stream[this._current]] !== undefined) {
4385
- this._current += 1;
4091
+ function isObject(obj) {
4092
+ if (obj !== null) {
4093
+ return Object.prototype.toString.call(obj) === "[object Object]";
4386
4094
  } else {
4387
- const error = new Error(`Syntax error: unknown character: ${stream[this._current]}`);
4388
- error.name = "LexerError";
4389
- throw error;
4095
+ return false;
4390
4096
  }
4391
4097
  }
4392
- return tokens;
4393
- }
4394
- consumeUnquotedIdentifier(stream) {
4395
- const start = this._current;
4396
- this._current += 1;
4397
- while (this._current < stream.length && isAlphaNum(stream[this._current])) {
4398
- this._current += 1;
4399
- }
4400
- return stream.slice(start, this._current);
4401
- }
4402
- consumeQuotedIdentifier(stream) {
4403
- const start = this._current;
4404
- this._current += 1;
4405
- const maxLength = stream.length;
4406
- while (stream[this._current] !== '"' && this._current < maxLength) {
4407
- let current = this._current;
4408
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
4409
- current += 2;
4410
- } else {
4411
- current += 1;
4098
+ function strictDeepEqual(first, second) {
4099
+ if (first === second) {
4100
+ return true;
4412
4101
  }
4413
- this._current = current;
4414
- }
4415
- this._current += 1;
4416
- const [value, ok] = this.parseJSON(stream.slice(start, this._current));
4417
- if (!ok) {
4418
- const error = new Error(`syntax: unexpected end of JSON input`);
4419
- error.name = "LexerError";
4420
- throw error;
4421
- }
4422
- return value;
4423
- }
4424
- consumeRawStringLiteral(stream) {
4425
- const start = this._current;
4426
- this._current += 1;
4427
- const maxLength = stream.length;
4428
- while (stream[this._current] !== `'` && this._current < maxLength) {
4429
- let current = this._current;
4430
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === `'`)) {
4431
- current += 2;
4432
- } else {
4433
- current += 1;
4434
- }
4435
- this._current = current;
4436
- }
4437
- this._current += 1;
4438
- const literal = stream.slice(start + 1, this._current - 1);
4439
- return replace(replace(literal, `\\\\`, `\\`), `\\'`, `'`);
4440
- }
4441
- consumeNumber(stream) {
4442
- const start = this._current;
4443
- this._current += 1;
4444
- const maxLength = stream.length;
4445
- while (isNum(stream[this._current]) && this._current < maxLength) {
4446
- this._current += 1;
4447
- }
4448
- const value = parseInt(stream.slice(start, this._current), 10);
4449
- return { start, value, type: "Number" };
4450
- }
4451
- consumeLBracket(stream) {
4452
- const start = this._current;
4453
- this._current += 1;
4454
- if (stream[this._current] === "?") {
4455
- this._current += 1;
4456
- return { start, type: "Filter", value: "[?" };
4457
- }
4458
- if (stream[this._current] === "]") {
4459
- this._current += 1;
4460
- return { start, type: "Flatten", value: "[]" };
4461
- }
4462
- return { start, type: "Lbracket", value: "[" };
4463
- }
4464
- consumeOrElse(stream, peek, token, orElse) {
4465
- const start = this._current;
4466
- this._current += 1;
4467
- if (this._current < stream.length && stream[this._current] === peek) {
4468
- this._current += 1;
4469
- return {
4470
- start,
4471
- type: orElse,
4472
- value: stream.slice(start, this._current)
4473
- };
4474
- }
4475
- return { start, type: token, value: stream[start] };
4476
- }
4477
- consumeOperator(stream) {
4478
- const start = this._current;
4479
- const startingChar = stream[start];
4480
- switch (startingChar) {
4481
- case "!":
4482
- return this.consumeOrElse(stream, "=", "Not", "NE");
4483
- case "<":
4484
- return this.consumeOrElse(stream, "=", "LT", "LTE");
4485
- case ">":
4486
- return this.consumeOrElse(stream, "=", "GT", "GTE");
4487
- case "=":
4488
- return this.consumeOrElse(stream, "=", "Assign", "EQ");
4489
- case "&":
4490
- return this.consumeOrElse(stream, "&", "Expref", "And");
4491
- case "|":
4492
- return this.consumeOrElse(stream, "|", "Pipe", "Or");
4493
- case "/":
4494
- return this.consumeOrElse(stream, "/", "Divide", "Div");
4495
- }
4496
- }
4497
- consumeLiteral(stream) {
4498
- this._current += 1;
4499
- const start = this._current;
4500
- const maxLength = stream.length;
4501
- while (stream[this._current] !== "`" && this._current < maxLength) {
4502
- let current = this._current;
4503
- if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
4504
- current += 2;
4505
- } else {
4506
- current += 1;
4102
+ var firstType = Object.prototype.toString.call(first);
4103
+ if (firstType !== Object.prototype.toString.call(second)) {
4104
+ return false;
4507
4105
  }
4508
- this._current = current;
4509
- }
4510
- let literalString = stream.slice(start, this._current).trimStart();
4511
- literalString = literalString.replace("\\`", "`");
4512
- let literal = null;
4513
- let ok = false;
4514
- if (this.looksLikeJSON(literalString)) {
4515
- [literal, ok] = this.parseJSON(literalString);
4516
- }
4517
- if (!ok && this._enable_legacy_literals) {
4518
- [literal, ok] = this.parseJSON(`"${literalString}"`);
4519
- }
4520
- if (!ok) {
4521
- const error = new Error(`Syntax error: unexpected end of JSON input or invalid format for a JSON literal: ${stream[this._current]}`);
4522
- error.name = "LexerError";
4523
- throw error;
4524
- }
4525
- this._current += 1;
4526
- return literal;
4527
- }
4528
- looksLikeJSON(literalString) {
4529
- const startingChars = '[{"';
4530
- const jsonLiterals = ["true", "false", "null"];
4531
- const numberLooking = "-0123456789";
4532
- if (literalString === "") {
4533
- return false;
4534
- }
4535
- if (startingChars.includes(literalString[0])) {
4536
- return true;
4537
- }
4538
- if (jsonLiterals.includes(literalString)) {
4539
- return true;
4540
- }
4541
- if (numberLooking.includes(literalString[0])) {
4542
- const [_, ok] = this.parseJSON(literalString);
4543
- return ok;
4544
- }
4545
- return false;
4546
- }
4547
- parseJSON(text) {
4548
- try {
4549
- const json2 = JSON.parse(text);
4550
- return [json2, true];
4551
- } catch {
4552
- return [null, false];
4553
- }
4554
- }
4555
- }, Lexer, Lexer_default, bindingPower, TokenParser = class _TokenParser {
4556
- index = 0;
4557
- tokens = [];
4558
- parse(expression, options) {
4559
- this.loadTokens(expression, options || { enable_legacy_literals: false });
4560
- this.index = 0;
4561
- const ast = this.expression(0);
4562
- if (this.lookahead(0) !== "EOF") {
4563
- const token = this.lookaheadToken(0);
4564
- this.errorToken(token, `Syntax error: unexpected token type: ${token.type}, value: ${token.value}`);
4565
- }
4566
- return ast;
4567
- }
4568
- loadTokens(expression, options) {
4569
- this.tokens = Lexer_default.tokenize(expression, options);
4570
- this.tokens.push({ type: "EOF", value: "", start: expression.length });
4571
- }
4572
- expression(rbp) {
4573
- const leftToken = this.lookaheadToken(0);
4574
- this.advance();
4575
- let left = this.nud(leftToken);
4576
- let currentTokenType = this.lookahead(0);
4577
- while (rbp < bindingPower[currentTokenType]) {
4578
- this.advance();
4579
- left = this.led(currentTokenType, left);
4580
- currentTokenType = this.lookahead(0);
4581
- }
4582
- return left;
4583
- }
4584
- lookahead(offset) {
4585
- return this.tokens[this.index + offset].type;
4586
- }
4587
- lookaheadToken(offset) {
4588
- return this.tokens[this.index + offset];
4589
- }
4590
- advance() {
4591
- this.index += 1;
4592
- }
4593
- nud(token) {
4594
- switch (token.type) {
4595
- case "Variable":
4596
- return { type: "Variable", name: token.value };
4597
- case "Literal":
4598
- return { type: "Literal", value: token.value };
4599
- case "UnquotedIdentifier": {
4600
- if (_TokenParser.isKeyword(token, "let") && this.lookahead(0) === "Variable") {
4601
- return this.parseLetExpression();
4602
- } else {
4603
- return { type: "Field", name: token.value };
4106
+ if (isArray(first) === true) {
4107
+ if (first.length !== second.length) {
4108
+ return false;
4604
4109
  }
4605
- }
4606
- case "QuotedIdentifier":
4607
- if (this.lookahead(0) === "Lparen") {
4608
- throw new Error("Syntax error: quoted identifier not allowed for function names.");
4609
- } else {
4610
- return { type: "Field", name: token.value };
4110
+ for (var i = 0;i < first.length; i++) {
4111
+ if (strictDeepEqual(first[i], second[i]) === false) {
4112
+ return false;
4113
+ }
4611
4114
  }
4612
- case "Not": {
4613
- const child = this.expression(bindingPower.Not);
4614
- return { type: "NotExpression", child };
4615
- }
4616
- case "Minus": {
4617
- const child = this.expression(bindingPower.Minus);
4618
- return {
4619
- type: "Unary",
4620
- operator: token.type,
4621
- operand: child
4622
- };
4623
- }
4624
- case "Plus": {
4625
- const child = this.expression(bindingPower.Plus);
4626
- return {
4627
- type: "Unary",
4628
- operator: token.type,
4629
- operand: child
4630
- };
4115
+ return true;
4631
4116
  }
4632
- case "Star": {
4633
- const left = { type: "Identity" };
4634
- return { type: "ValueProjection", left, right: this.parseProjectionRHS(bindingPower.Star) };
4635
- }
4636
- case "Filter":
4637
- return this.led(token.type, { type: "Identity" });
4638
- case "Lbrace":
4639
- return this.parseMultiselectHash();
4640
- case "Flatten": {
4641
- const left = {
4642
- type: "Flatten",
4643
- child: { type: "Identity" }
4644
- };
4645
- const right = this.parseProjectionRHS(bindingPower.Flatten);
4646
- return { type: "Projection", left, right };
4647
- }
4648
- case "Lbracket": {
4649
- if (this.lookahead(0) === "Number" || this.lookahead(0) === "Colon") {
4650
- const right = this.parseIndexExpression();
4651
- return this.projectIfSlice({ type: "Identity" }, right);
4652
- }
4653
- if (this.lookahead(0) === "Star" && this.lookahead(1) === "Rbracket") {
4654
- this.advance();
4655
- this.advance();
4656
- const right = this.parseProjectionRHS(bindingPower.Star);
4657
- return {
4658
- left: { type: "Identity" },
4659
- right,
4660
- type: "Projection"
4661
- };
4117
+ if (isObject(first) === true) {
4118
+ var keysSeen = {};
4119
+ for (var key in first) {
4120
+ if (hasOwnProperty.call(first, key)) {
4121
+ if (strictDeepEqual(first[key], second[key]) === false) {
4122
+ return false;
4123
+ }
4124
+ keysSeen[key] = true;
4125
+ }
4662
4126
  }
4663
- return this.parseMultiselectList();
4664
- }
4665
- case "Current":
4666
- return { type: "Current" };
4667
- case "Root":
4668
- return { type: "Root" };
4669
- case "Expref": {
4670
- const child = this.expression(bindingPower.Expref);
4671
- return { type: "ExpressionReference", child };
4127
+ for (var key2 in second) {
4128
+ if (hasOwnProperty.call(second, key2)) {
4129
+ if (keysSeen[key2] !== true) {
4130
+ return false;
4131
+ }
4132
+ }
4133
+ }
4134
+ return true;
4672
4135
  }
4673
- case "Lparen": {
4674
- const expression = this.expression(0);
4675
- this.match("Rparen");
4676
- return expression;
4136
+ return false;
4137
+ }
4138
+ function isFalse(obj) {
4139
+ if (obj === "" || obj === false || obj === null) {
4140
+ return true;
4141
+ } else if (isArray(obj) && obj.length === 0) {
4142
+ return true;
4143
+ } else if (isObject(obj)) {
4144
+ for (var key in obj) {
4145
+ if (obj.hasOwnProperty(key)) {
4146
+ return false;
4147
+ }
4148
+ }
4149
+ return true;
4150
+ } else {
4151
+ return false;
4677
4152
  }
4678
- default:
4679
- this.errorToken(token);
4680
4153
  }
4681
- }
4682
- led(tokenName, left) {
4683
- switch (tokenName) {
4684
- case "Question": {
4685
- const trueExpr = this.expression(0);
4686
- this.match("Colon");
4687
- const falseExpr = this.expression(0);
4688
- return {
4689
- type: "Ternary",
4690
- condition: left,
4691
- trueExpr,
4692
- falseExpr
4693
- };
4154
+ function objValues(obj) {
4155
+ var keys = Object.keys(obj);
4156
+ var values = [];
4157
+ for (var i = 0;i < keys.length; i++) {
4158
+ values.push(obj[keys[i]]);
4694
4159
  }
4695
- case "Dot": {
4696
- const rbp = bindingPower.Dot;
4697
- if (this.lookahead(0) !== "Star") {
4698
- const right2 = this.parseDotRHS(rbp);
4699
- return { type: "Subexpression", left, right: right2 };
4700
- }
4701
- this.advance();
4702
- const right = this.parseProjectionRHS(rbp);
4703
- return { type: "ValueProjection", left, right };
4704
- }
4705
- case "Pipe": {
4706
- const right = this.expression(bindingPower.Pipe);
4707
- return { type: "Pipe", left, right };
4708
- }
4709
- case "Or": {
4710
- const right = this.expression(bindingPower.Or);
4711
- return { type: "OrExpression", left, right };
4712
- }
4713
- case "And": {
4714
- const right = this.expression(bindingPower.And);
4715
- return { type: "AndExpression", left, right };
4716
- }
4717
- case "Lparen": {
4718
- if (left.type !== "Field") {
4719
- throw new Error("Syntax error: expected a Field node");
4720
- }
4721
- const name = left.name;
4722
- const args = this.parseCommaSeparatedExpressionsUntilToken("Rparen");
4723
- const node = { name, type: "Function", children: args };
4724
- return node;
4725
- }
4726
- case "Filter": {
4727
- const condition = this.expression(0);
4728
- this.match("Rbracket");
4729
- const right = this.lookahead(0) === "Flatten" ? { type: "Identity" } : this.parseProjectionRHS(bindingPower.Filter);
4730
- return { type: "FilterProjection", left, right, condition };
4731
- }
4732
- case "Flatten": {
4733
- const leftNode = { type: "Flatten", child: left };
4734
- const right = this.parseProjectionRHS(bindingPower.Flatten);
4735
- return { type: "Projection", left: leftNode, right };
4736
- }
4737
- case "Assign": {
4738
- const leftNode = left;
4739
- const right = this.expression(0);
4740
- return {
4741
- type: "Binding",
4742
- variable: leftNode.name,
4743
- reference: right
4744
- };
4160
+ return values;
4161
+ }
4162
+ function merge2(a, b) {
4163
+ var merged = {};
4164
+ for (var key in a) {
4165
+ merged[key] = a[key];
4745
4166
  }
4746
- case "EQ":
4747
- case "NE":
4748
- case "GT":
4749
- case "GTE":
4750
- case "LT":
4751
- case "LTE":
4752
- return this.parseComparator(left, tokenName);
4753
- case "Plus":
4754
- case "Minus":
4755
- case "Multiply":
4756
- case "Star":
4757
- case "Divide":
4758
- case "Modulo":
4759
- case "Div":
4760
- return this.parseArithmetic(left, tokenName);
4761
- case "Lbracket": {
4762
- const token = this.lookaheadToken(0);
4763
- if (token.type === "Number" || token.type === "Colon") {
4764
- const right2 = this.parseIndexExpression();
4765
- return this.projectIfSlice(left, right2);
4766
- }
4767
- this.match("Star");
4768
- this.match("Rbracket");
4769
- const right = this.parseProjectionRHS(bindingPower.Star);
4770
- return { type: "Projection", left, right };
4167
+ for (var key2 in b) {
4168
+ merged[key2] = b[key2];
4771
4169
  }
4772
- default:
4773
- return this.errorToken(this.lookaheadToken(0));
4170
+ return merged;
4774
4171
  }
4775
- }
4776
- static isKeyword(token, keyword) {
4777
- return token.type === "UnquotedIdentifier" && token.value === keyword;
4778
- }
4779
- match(tokenType) {
4780
- if (this.lookahead(0) === tokenType) {
4781
- this.advance();
4782
- return;
4172
+ var trimLeft;
4173
+ if (typeof String.prototype.trimLeft === "function") {
4174
+ trimLeft = function(str2) {
4175
+ return str2.trimLeft();
4176
+ };
4783
4177
  } else {
4784
- const token = this.lookaheadToken(0);
4785
- this.errorToken(token, `Syntax error: expected ${tokenType}, got: ${token.type}`);
4786
- }
4787
- }
4788
- errorToken(token, message = "") {
4789
- const error = new Error(message || `Syntax error: invalid token (${token.type}): "${token.value}"`);
4790
- error.name = "ParserError";
4791
- throw error;
4792
- }
4793
- parseIndexExpression() {
4794
- if (this.lookahead(0) === "Colon" || this.lookahead(1) === "Colon") {
4795
- return this.parseSliceExpression();
4796
- }
4797
- const value = Number(this.lookaheadToken(0).value);
4798
- this.advance();
4799
- this.match("Rbracket");
4800
- return { type: "Index", value };
4801
- }
4802
- projectIfSlice(left, right) {
4803
- const indexExpr = {
4804
- type: "IndexExpression",
4805
- left,
4806
- right
4807
- };
4808
- if (right.type === "Slice") {
4809
- return {
4810
- left: indexExpr,
4811
- right: this.parseProjectionRHS(bindingPower.Star),
4812
- type: "Projection"
4178
+ trimLeft = function(str2) {
4179
+ return str2.match(/^\s*(.*)/)[1];
4813
4180
  };
4814
4181
  }
4815
- return indexExpr;
4816
- }
4817
- parseSliceExpression() {
4818
- const parts = [null, null, null];
4819
- let index = 0;
4820
- let current = this.lookaheadToken(0);
4821
- while (current.type != "Rbracket" && index < 3) {
4822
- if (current.type === "Colon") {
4823
- index++;
4824
- if (index === 3) {
4825
- this.errorToken(this.lookaheadToken(0), "Syntax error, too many colons in slice expression");
4826
- }
4827
- this.advance();
4828
- } else if (current.type === "Number") {
4829
- const part = this.lookaheadToken(0).value;
4830
- parts[index] = part;
4831
- this.advance();
4832
- } else {
4833
- const next = this.lookaheadToken(0);
4834
- this.errorToken(next, `Syntax error, unexpected token: ${next.value}(${next.type})`);
4835
- }
4836
- current = this.lookaheadToken(0);
4837
- }
4838
- this.match("Rbracket");
4839
- const [start, stop, step] = parts;
4840
- return { type: "Slice", start, stop, step };
4841
- }
4842
- parseLetExpression() {
4843
- const separated = this.parseCommaSeparatedExpressionsUntilKeyword("in");
4844
- const expression = this.expression(0);
4845
- const bindings = separated.map((binding) => binding);
4846
- return {
4847
- type: "LetExpression",
4848
- bindings,
4849
- expression
4182
+ var TYPE_NUMBER = 0;
4183
+ var TYPE_ANY = 1;
4184
+ var TYPE_STRING = 2;
4185
+ var TYPE_ARRAY = 3;
4186
+ var TYPE_OBJECT = 4;
4187
+ var TYPE_BOOLEAN = 5;
4188
+ var TYPE_EXPREF = 6;
4189
+ var TYPE_NULL = 7;
4190
+ var TYPE_ARRAY_NUMBER = 8;
4191
+ var TYPE_ARRAY_STRING = 9;
4192
+ var TYPE_NAME_TABLE = {
4193
+ 0: "number",
4194
+ 1: "any",
4195
+ 2: "string",
4196
+ 3: "array",
4197
+ 4: "object",
4198
+ 5: "boolean",
4199
+ 6: "expression",
4200
+ 7: "null",
4201
+ 8: "Array<number>",
4202
+ 9: "Array<string>"
4850
4203
  };
4851
- }
4852
- parseCommaSeparatedExpressionsUntilKeyword(keyword) {
4853
- return this.parseCommaSeparatedExpressionsUntil(() => {
4854
- return _TokenParser.isKeyword(this.lookaheadToken(0), keyword);
4855
- }, () => {
4856
- this.advance();
4857
- });
4858
- }
4859
- parseCommaSeparatedExpressionsUntilToken(token) {
4860
- return this.parseCommaSeparatedExpressionsUntil(() => {
4861
- return this.lookahead(0) === token;
4862
- }, () => {
4863
- return this.match(token);
4864
- });
4865
- }
4866
- parseCommaSeparatedExpressionsUntil(isEndToken, matchEndToken) {
4867
- const args = [];
4868
- let expression;
4869
- while (!isEndToken()) {
4870
- expression = this.expression(0);
4871
- if (this.lookahead(0) === "Comma") {
4872
- this.match("Comma");
4873
- }
4874
- args.push(expression);
4875
- }
4876
- matchEndToken();
4877
- return args;
4878
- }
4879
- parseComparator(left, comparator) {
4880
- const right = this.expression(bindingPower[comparator]);
4881
- return { type: "Comparator", name: comparator, left, right };
4882
- }
4883
- parseArithmetic(left, operator) {
4884
- const right = this.expression(bindingPower[operator]);
4885
- return { type: "Arithmetic", operator, left, right };
4886
- }
4887
- parseDotRHS(rbp) {
4888
- const lookahead = this.lookahead(0);
4889
- const exprTokens = ["UnquotedIdentifier", "QuotedIdentifier", "Star"];
4890
- if (exprTokens.includes(lookahead)) {
4891
- return this.expression(rbp);
4892
- }
4893
- if (lookahead === "Lbracket") {
4894
- this.match("Lbracket");
4895
- return this.parseMultiselectList();
4896
- }
4897
- if (lookahead === "Lbrace") {
4898
- this.match("Lbrace");
4899
- return this.parseMultiselectHash();
4900
- }
4901
- const token = this.lookaheadToken(0);
4902
- this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
4903
- }
4904
- parseProjectionRHS(rbp) {
4905
- if (bindingPower[this.lookahead(0)] < 10) {
4906
- return { type: "Identity" };
4907
- }
4908
- if (this.lookahead(0) === "Lbracket") {
4909
- return this.expression(rbp);
4910
- }
4911
- if (this.lookahead(0) === "Filter") {
4912
- return this.expression(rbp);
4913
- }
4914
- if (this.lookahead(0) === "Dot") {
4915
- this.match("Dot");
4916
- return this.parseDotRHS(rbp);
4917
- }
4918
- const token = this.lookaheadToken(0);
4919
- this.errorToken(token, `Syntax error, unexpected token: ${token.value}(${token.type})`);
4920
- }
4921
- parseMultiselectList() {
4922
- const expressions = [];
4923
- while (this.lookahead(0) !== "Rbracket") {
4924
- const expression = this.expression(0);
4925
- expressions.push(expression);
4926
- if (this.lookahead(0) === "Comma") {
4927
- this.match("Comma");
4928
- if (this.lookahead(0) === "Rbracket") {
4929
- throw new Error("Syntax error: unexpected token Rbracket");
4930
- }
4931
- }
4932
- }
4933
- this.match("Rbracket");
4934
- return { type: "MultiSelectList", children: expressions };
4935
- }
4936
- parseMultiselectHash() {
4937
- const pairs2 = [];
4938
- const identifierTypes = ["UnquotedIdentifier", "QuotedIdentifier"];
4939
- let keyToken;
4940
- let keyName;
4941
- let value;
4942
- for (;; ) {
4943
- keyToken = this.lookaheadToken(0);
4944
- if (!identifierTypes.includes(keyToken.type)) {
4945
- throw new Error(`Syntax error: expecting an identifier token, got: ${keyToken.type}`);
4946
- }
4947
- keyName = keyToken.value;
4948
- this.advance();
4949
- this.match("Colon");
4950
- value = this.expression(0);
4951
- pairs2.push({ value, type: "KeyValuePair", name: keyName });
4952
- if (this.lookahead(0) === "Comma") {
4953
- this.match("Comma");
4954
- } else if (this.lookahead(0) === "Rbrace") {
4955
- this.match("Rbrace");
4956
- break;
4957
- }
4958
- }
4959
- return { type: "MultiSelectHash", children: pairs2 };
4960
- }
4961
- }, Parser, Parser_default, Text = class _Text {
4962
- _text;
4963
- constructor(text) {
4964
- this._text = text;
4965
- }
4966
- get string() {
4967
- return this._text;
4968
- }
4969
- get length() {
4970
- return this.codePoints.length;
4971
- }
4972
- compareTo(other) {
4973
- return _Text.compare(this, new _Text(other));
4974
- }
4975
- static get comparer() {
4976
- const stringComparer = (left, right) => {
4977
- return new _Text(left).compareTo(right);
4204
+ var TOK_EOF = "EOF";
4205
+ var TOK_UNQUOTEDIDENTIFIER = "UnquotedIdentifier";
4206
+ var TOK_QUOTEDIDENTIFIER = "QuotedIdentifier";
4207
+ var TOK_RBRACKET = "Rbracket";
4208
+ var TOK_RPAREN = "Rparen";
4209
+ var TOK_COMMA = "Comma";
4210
+ var TOK_COLON = "Colon";
4211
+ var TOK_RBRACE = "Rbrace";
4212
+ var TOK_NUMBER = "Number";
4213
+ var TOK_CURRENT = "Current";
4214
+ var TOK_EXPREF = "Expref";
4215
+ var TOK_PIPE = "Pipe";
4216
+ var TOK_OR = "Or";
4217
+ var TOK_AND = "And";
4218
+ var TOK_EQ = "EQ";
4219
+ var TOK_GT = "GT";
4220
+ var TOK_LT = "LT";
4221
+ var TOK_GTE = "GTE";
4222
+ var TOK_LTE = "LTE";
4223
+ var TOK_NE = "NE";
4224
+ var TOK_FLATTEN = "Flatten";
4225
+ var TOK_STAR = "Star";
4226
+ var TOK_FILTER = "Filter";
4227
+ var TOK_DOT = "Dot";
4228
+ var TOK_NOT = "Not";
4229
+ var TOK_LBRACE = "Lbrace";
4230
+ var TOK_LBRACKET = "Lbracket";
4231
+ var TOK_LPAREN = "Lparen";
4232
+ var TOK_LITERAL = "Literal";
4233
+ var basicTokens = {
4234
+ ".": TOK_DOT,
4235
+ "*": TOK_STAR,
4236
+ ",": TOK_COMMA,
4237
+ ":": TOK_COLON,
4238
+ "{": TOK_LBRACE,
4239
+ "}": TOK_RBRACE,
4240
+ "]": TOK_RBRACKET,
4241
+ "(": TOK_LPAREN,
4242
+ ")": TOK_RPAREN,
4243
+ "@": TOK_CURRENT
4978
4244
  };
4979
- return stringComparer;
4980
- }
4981
- static compare(left, right) {
4982
- const leftCp = left.codePoints;
4983
- const rightCp = right.codePoints;
4984
- for (let index = 0;index < Math.min(leftCp.length, rightCp.length); index++) {
4985
- if (leftCp[index] === rightCp[index]) {
4986
- continue;
4987
- }
4988
- return leftCp[index] - rightCp[index] > 0 ? 1 : -1;
4989
- }
4990
- return leftCp.length - rightCp.length > 0 ? 1 : -1;
4991
- }
4992
- reverse() {
4993
- return String.fromCodePoint(...this.codePoints.reverse());
4994
- }
4995
- get codePoints() {
4996
- const array = [...this._text].map((s) => s.codePointAt(0));
4997
- return array;
4998
- }
4999
- }, createMathFunction = (mathFn) => ([value]) => mathFn(value), createStringFunction = (stringFn) => ([subject]) => stringFn(subject), createObjectFunction = (objFn) => ([obj]) => objFn(obj), Runtime = class {
5000
- _interpreter;
5001
- _functionTable;
5002
- _customFunctions = /* @__PURE__ */ new Set;
5003
- TYPE_NAME_TABLE = Object.freeze({
5004
- [0]: "number",
5005
- [1]: "any",
5006
- [2]: "string",
5007
- [3]: "array",
5008
- [4]: "object",
5009
- [5]: "boolean",
5010
- [6]: "expression",
5011
- [7]: "null",
5012
- [8]: "Array<number>",
5013
- [10]: "Array<object>",
5014
- [9]: "Array<string>",
5015
- [11]: "Array<Array<any>>"
5016
- });
5017
- constructor(interpreter) {
5018
- this._interpreter = interpreter;
5019
- this._functionTable = this.buildFunctionTable();
5020
- }
5021
- buildFunctionTable() {
5022
- return {
5023
- abs: { _func: createMathFunction(Math.abs), _signature: [{ types: [0] }] },
5024
- ceil: { _func: createMathFunction(Math.ceil), _signature: [{ types: [0] }] },
5025
- floor: { _func: createMathFunction(Math.floor), _signature: [{ types: [0] }] },
5026
- lower: { _func: createStringFunction(lower), _signature: [{ types: [2] }] },
5027
- upper: { _func: createStringFunction(upper), _signature: [{ types: [2] }] },
5028
- keys: { _func: createObjectFunction(Object.keys), _signature: [{ types: [4] }] },
5029
- values: { _func: createObjectFunction(Object.values), _signature: [{ types: [4] }] },
5030
- avg: { _func: this.functionAvg, _signature: [{ types: [8] }] },
5031
- contains: {
5032
- _func: this.functionContains,
5033
- _signature: [
5034
- { types: [2, 3] },
5035
- { types: [1] }
5036
- ]
5037
- },
5038
- ends_with: {
5039
- _func: this.functionEndsWith,
5040
- _signature: [{ types: [2] }, { types: [2] }]
5041
- },
5042
- find_first: {
5043
- _func: this.functionFindFirst,
5044
- _signature: [
5045
- { types: [2] },
5046
- { types: [2] },
5047
- { types: [0], optional: true },
5048
- { types: [0], optional: true }
5049
- ]
5050
- },
5051
- find_last: {
5052
- _func: this.functionFindLast,
5053
- _signature: [
5054
- { types: [2] },
5055
- { types: [2] },
5056
- { types: [0], optional: true },
5057
- { types: [0], optional: true }
5058
- ]
5059
- },
5060
- from_items: { _func: this.functionFromItems, _signature: [{ types: [11] }] },
5061
- group_by: {
5062
- _func: this.functionGroupBy,
5063
- _signature: [{ types: [3] }, { types: [6] }]
5064
- },
5065
- items: { _func: this.functionItems, _signature: [{ types: [4] }] },
5066
- join: {
5067
- _func: this.functionJoin,
5068
- _signature: [{ types: [2] }, { types: [9] }]
5069
- },
5070
- length: {
5071
- _func: this.functionLength,
5072
- _signature: [{ types: [2, 3, 4] }]
5073
- },
5074
- map: {
5075
- _func: this.functionMap,
5076
- _signature: [{ types: [6] }, { types: [3] }]
5077
- },
5078
- max: {
5079
- _func: this.functionMax,
5080
- _signature: [{ types: [8, 9] }]
5081
- },
5082
- max_by: {
5083
- _func: this.functionMaxBy,
5084
- _signature: [{ types: [3] }, { types: [6] }]
5085
- },
5086
- merge: { _func: this.functionMerge, _signature: [{ types: [4], variadic: true }] },
5087
- min: {
5088
- _func: this.functionMin,
5089
- _signature: [{ types: [8, 9] }]
5090
- },
5091
- min_by: {
5092
- _func: this.functionMinBy,
5093
- _signature: [{ types: [3] }, { types: [6] }]
5094
- },
5095
- not_null: { _func: this.functionNotNull, _signature: [{ types: [1], variadic: true }] },
5096
- pad_left: {
5097
- _func: this.functionPadLeft,
5098
- _signature: [
5099
- { types: [2] },
5100
- { types: [0] },
5101
- { types: [2], optional: true }
5102
- ]
5103
- },
5104
- pad_right: {
5105
- _func: this.functionPadRight,
5106
- _signature: [
5107
- { types: [2] },
5108
- { types: [0] },
5109
- { types: [2], optional: true }
5110
- ]
5111
- },
5112
- replace: {
5113
- _func: this.functionReplace,
5114
- _signature: [
5115
- { types: [2] },
5116
- { types: [2] },
5117
- { types: [2] },
5118
- { types: [0], optional: true }
5119
- ]
5120
- },
5121
- reverse: {
5122
- _func: this.functionReverse,
5123
- _signature: [{ types: [2, 3] }]
4245
+ var operatorStartToken = {
4246
+ "<": true,
4247
+ ">": true,
4248
+ "=": true,
4249
+ "!": true
4250
+ };
4251
+ var skipChars = {
4252
+ " ": true,
4253
+ "\t": true,
4254
+ "\n": true
4255
+ };
4256
+ function isAlpha(ch) {
4257
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch === "_";
4258
+ }
4259
+ function isNum(ch) {
4260
+ return ch >= "0" && ch <= "9" || ch === "-";
4261
+ }
4262
+ function isAlphaNum(ch) {
4263
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "_";
4264
+ }
4265
+ function Lexer() {}
4266
+ Lexer.prototype = {
4267
+ tokenize: function(stream) {
4268
+ var tokens = [];
4269
+ this._current = 0;
4270
+ var start;
4271
+ var identifier;
4272
+ var token;
4273
+ while (this._current < stream.length) {
4274
+ if (isAlpha(stream[this._current])) {
4275
+ start = this._current;
4276
+ identifier = this._consumeUnquotedIdentifier(stream);
4277
+ tokens.push({
4278
+ type: TOK_UNQUOTEDIDENTIFIER,
4279
+ value: identifier,
4280
+ start
4281
+ });
4282
+ } else if (basicTokens[stream[this._current]] !== undefined) {
4283
+ tokens.push({
4284
+ type: basicTokens[stream[this._current]],
4285
+ value: stream[this._current],
4286
+ start: this._current
4287
+ });
4288
+ this._current++;
4289
+ } else if (isNum(stream[this._current])) {
4290
+ token = this._consumeNumber(stream);
4291
+ tokens.push(token);
4292
+ } else if (stream[this._current] === "[") {
4293
+ token = this._consumeLBracket(stream);
4294
+ tokens.push(token);
4295
+ } else if (stream[this._current] === '"') {
4296
+ start = this._current;
4297
+ identifier = this._consumeQuotedIdentifier(stream);
4298
+ tokens.push({
4299
+ type: TOK_QUOTEDIDENTIFIER,
4300
+ value: identifier,
4301
+ start
4302
+ });
4303
+ } else if (stream[this._current] === "'") {
4304
+ start = this._current;
4305
+ identifier = this._consumeRawStringLiteral(stream);
4306
+ tokens.push({
4307
+ type: TOK_LITERAL,
4308
+ value: identifier,
4309
+ start
4310
+ });
4311
+ } else if (stream[this._current] === "`") {
4312
+ start = this._current;
4313
+ var literal = this._consumeLiteral(stream);
4314
+ tokens.push({
4315
+ type: TOK_LITERAL,
4316
+ value: literal,
4317
+ start
4318
+ });
4319
+ } else if (operatorStartToken[stream[this._current]] !== undefined) {
4320
+ tokens.push(this._consumeOperator(stream));
4321
+ } else if (skipChars[stream[this._current]] !== undefined) {
4322
+ this._current++;
4323
+ } else if (stream[this._current] === "&") {
4324
+ start = this._current;
4325
+ this._current++;
4326
+ if (stream[this._current] === "&") {
4327
+ this._current++;
4328
+ tokens.push({ type: TOK_AND, value: "&&", start });
4329
+ } else {
4330
+ tokens.push({ type: TOK_EXPREF, value: "&", start });
4331
+ }
4332
+ } else if (stream[this._current] === "|") {
4333
+ start = this._current;
4334
+ this._current++;
4335
+ if (stream[this._current] === "|") {
4336
+ this._current++;
4337
+ tokens.push({ type: TOK_OR, value: "||", start });
4338
+ } else {
4339
+ tokens.push({ type: TOK_PIPE, value: "|", start });
4340
+ }
4341
+ } else {
4342
+ var error = new Error("Unknown character:" + stream[this._current]);
4343
+ error.name = "LexerError";
4344
+ throw error;
4345
+ }
4346
+ }
4347
+ return tokens;
5124
4348
  },
5125
- sort: {
5126
- _func: this.functionSort,
5127
- _signature: [{ types: [9, 8] }]
4349
+ _consumeUnquotedIdentifier: function(stream) {
4350
+ var start = this._current;
4351
+ this._current++;
4352
+ while (this._current < stream.length && isAlphaNum(stream[this._current])) {
4353
+ this._current++;
4354
+ }
4355
+ return stream.slice(start, this._current);
5128
4356
  },
5129
- sort_by: {
5130
- _func: this.functionSortBy,
5131
- _signature: [{ types: [3] }, { types: [6] }]
4357
+ _consumeQuotedIdentifier: function(stream) {
4358
+ var start = this._current;
4359
+ this._current++;
4360
+ var maxLength = stream.length;
4361
+ while (stream[this._current] !== '"' && this._current < maxLength) {
4362
+ var current = this._current;
4363
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === '"')) {
4364
+ current += 2;
4365
+ } else {
4366
+ current++;
4367
+ }
4368
+ this._current = current;
4369
+ }
4370
+ this._current++;
4371
+ return JSON.parse(stream.slice(start, this._current));
5132
4372
  },
5133
- split: {
5134
- _func: this.functionSplit,
5135
- _signature: [
5136
- { types: [2] },
5137
- { types: [2] },
5138
- { types: [0], optional: true }
5139
- ]
4373
+ _consumeRawStringLiteral: function(stream) {
4374
+ var start = this._current;
4375
+ this._current++;
4376
+ var maxLength = stream.length;
4377
+ while (stream[this._current] !== "'" && this._current < maxLength) {
4378
+ var current = this._current;
4379
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "'")) {
4380
+ current += 2;
4381
+ } else {
4382
+ current++;
4383
+ }
4384
+ this._current = current;
4385
+ }
4386
+ this._current++;
4387
+ var literal = stream.slice(start + 1, this._current - 1);
4388
+ return literal.replace("\\'", "'");
5140
4389
  },
5141
- starts_with: {
5142
- _func: this.functionStartsWith,
5143
- _signature: [{ types: [2] }, { types: [2] }]
4390
+ _consumeNumber: function(stream) {
4391
+ var start = this._current;
4392
+ this._current++;
4393
+ var maxLength = stream.length;
4394
+ while (isNum(stream[this._current]) && this._current < maxLength) {
4395
+ this._current++;
4396
+ }
4397
+ var value = parseInt(stream.slice(start, this._current));
4398
+ return { type: TOK_NUMBER, value, start };
5144
4399
  },
5145
- sum: { _func: this.functionSum, _signature: [{ types: [8] }] },
5146
- to_array: { _func: this.functionToArray, _signature: [{ types: [1] }] },
5147
- to_number: { _func: this.functionToNumber, _signature: [{ types: [1] }] },
5148
- to_string: { _func: this.functionToString, _signature: [{ types: [1] }] },
5149
- trim: {
5150
- _func: this.functionTrim,
5151
- _signature: [{ types: [2] }, { types: [2], optional: true }]
4400
+ _consumeLBracket: function(stream) {
4401
+ var start = this._current;
4402
+ this._current++;
4403
+ if (stream[this._current] === "?") {
4404
+ this._current++;
4405
+ return { type: TOK_FILTER, value: "[?", start };
4406
+ } else if (stream[this._current] === "]") {
4407
+ this._current++;
4408
+ return { type: TOK_FLATTEN, value: "[]", start };
4409
+ } else {
4410
+ return { type: TOK_LBRACKET, value: "[", start };
4411
+ }
5152
4412
  },
5153
- trim_left: {
5154
- _func: this.functionTrimLeft,
5155
- _signature: [{ types: [2] }, { types: [2], optional: true }]
4413
+ _consumeOperator: function(stream) {
4414
+ var start = this._current;
4415
+ var startingChar = stream[start];
4416
+ this._current++;
4417
+ if (startingChar === "!") {
4418
+ if (stream[this._current] === "=") {
4419
+ this._current++;
4420
+ return { type: TOK_NE, value: "!=", start };
4421
+ } else {
4422
+ return { type: TOK_NOT, value: "!", start };
4423
+ }
4424
+ } else if (startingChar === "<") {
4425
+ if (stream[this._current] === "=") {
4426
+ this._current++;
4427
+ return { type: TOK_LTE, value: "<=", start };
4428
+ } else {
4429
+ return { type: TOK_LT, value: "<", start };
4430
+ }
4431
+ } else if (startingChar === ">") {
4432
+ if (stream[this._current] === "=") {
4433
+ this._current++;
4434
+ return { type: TOK_GTE, value: ">=", start };
4435
+ } else {
4436
+ return { type: TOK_GT, value: ">", start };
4437
+ }
4438
+ } else if (startingChar === "=") {
4439
+ if (stream[this._current] === "=") {
4440
+ this._current++;
4441
+ return { type: TOK_EQ, value: "==", start };
4442
+ }
4443
+ }
5156
4444
  },
5157
- trim_right: {
5158
- _func: this.functionTrimRight,
5159
- _signature: [{ types: [2] }, { types: [2], optional: true }]
4445
+ _consumeLiteral: function(stream) {
4446
+ this._current++;
4447
+ var start = this._current;
4448
+ var maxLength = stream.length;
4449
+ var literal;
4450
+ while (stream[this._current] !== "`" && this._current < maxLength) {
4451
+ var current = this._current;
4452
+ if (stream[current] === "\\" && (stream[current + 1] === "\\" || stream[current + 1] === "`")) {
4453
+ current += 2;
4454
+ } else {
4455
+ current++;
4456
+ }
4457
+ this._current = current;
4458
+ }
4459
+ var literalString = trimLeft(stream.slice(start, this._current));
4460
+ literalString = literalString.replace("\\`", "`");
4461
+ if (this._looksLikeJSON(literalString)) {
4462
+ literal = JSON.parse(literalString);
4463
+ } else {
4464
+ literal = JSON.parse('"' + literalString + '"');
4465
+ }
4466
+ this._current++;
4467
+ return literal;
5160
4468
  },
5161
- type: { _func: this.functionType, _signature: [{ types: [1] }] },
5162
- zip: { _func: this.functionZip, _signature: [{ types: [3], variadic: true }] }
5163
- };
5164
- }
5165
- registerFunction(name, customFunction, signature, options) {
5166
- const result = this._registerInternal(name, customFunction, signature, options);
5167
- if (!result.success) {
5168
- throw new Error(result.message);
5169
- }
5170
- }
5171
- _registerInternal(name, customFunction, signature, options = {}) {
5172
- if (!name || typeof name !== "string" || name.trim() === "") {
5173
- return {
5174
- success: false,
5175
- reason: "invalid-name",
5176
- message: "Function name must be a non-empty string"
5177
- };
5178
- }
5179
- try {
5180
- this.validateInputSignatures(name, signature);
5181
- } catch (error) {
5182
- return {
5183
- success: false,
5184
- reason: "invalid-signature",
5185
- message: error instanceof Error ? error.message : "Invalid function signature"
5186
- };
5187
- }
5188
- const { override = false, warn = false } = options;
5189
- const exists = name in this._functionTable;
5190
- if (exists && !override) {
5191
- return {
5192
- success: false,
5193
- reason: "already-exists",
5194
- message: `Function already defined: ${name}(). Use { override: true } to replace it.`
5195
- };
5196
- }
5197
- if (exists && override && warn) {
5198
- console.warn(`Warning: Overriding existing function: ${name}()`);
5199
- }
5200
- this._functionTable[name] = {
5201
- _func: customFunction.bind(this),
5202
- _signature: signature
5203
- };
5204
- this._customFunctions.add(name);
5205
- const message = exists ? `Function ${name}() overridden successfully` : `Function ${name}() registered successfully`;
5206
- return { success: true, message };
5207
- }
5208
- register(name, customFunction, signature, options = {}) {
5209
- return this._registerInternal(name, customFunction, signature, options);
5210
- }
5211
- unregister(name) {
5212
- if (!this._customFunctions.has(name)) {
5213
- return false;
5214
- }
5215
- delete this._functionTable[name];
5216
- this._customFunctions.delete(name);
5217
- return true;
5218
- }
5219
- isRegistered(name) {
5220
- return name in this._functionTable;
5221
- }
5222
- getRegistered() {
5223
- return Object.keys(this._functionTable);
5224
- }
5225
- getCustomFunctions() {
5226
- return Array.from(this._customFunctions);
5227
- }
5228
- clearCustomFunctions() {
5229
- for (const name of this._customFunctions) {
5230
- delete this._functionTable[name];
5231
- }
5232
- this._customFunctions.clear();
5233
- }
5234
- callFunction(name, resolvedArgs) {
5235
- const functionEntry = this._functionTable[name];
5236
- if (functionEntry === undefined) {
5237
- throw new Error(`Unknown function: ${name}()`);
5238
- }
5239
- this.validateArgs(name, resolvedArgs, functionEntry._signature);
5240
- return functionEntry._func.call(this, resolvedArgs);
5241
- }
5242
- validateInputSignatures(name, signature) {
5243
- for (let i = 0;i < signature.length; i += 1) {
5244
- if ("variadic" in signature[i] && i !== signature.length - 1) {
5245
- throw new Error(`Invalid arity: ${name}() 'variadic' argument ${i + 1} must occur last`);
5246
- }
5247
- }
5248
- }
5249
- validateArgs(name, args, signature) {
5250
- this.validateInputSignatures(name, signature);
5251
- this.validateArity(name, args, signature);
5252
- this.validateTypes(name, args, signature);
5253
- }
5254
- validateArity(name, args, signature) {
5255
- const numberOfRequiredArgs = signature.filter((argSignature) => !(argSignature.optional ?? false)).length;
5256
- const lastArgIsVariadic = signature[signature.length - 1]?.variadic ?? false;
5257
- const tooFewArgs = args.length < numberOfRequiredArgs;
5258
- const tooManyArgs = args.length > signature.length;
5259
- if (lastArgIsVariadic && tooFewArgs || !lastArgIsVariadic && (tooFewArgs || tooManyArgs)) {
5260
- const tooFewModifier = tooFewArgs && (!lastArgIsVariadic && numberOfRequiredArgs > 1 || lastArgIsVariadic) ? "at least " : "";
5261
- const pluralized = signature.length > 1;
5262
- throw new Error(`Invalid arity: ${name}() takes ${tooFewModifier}${numberOfRequiredArgs} argument${pluralized && "s" || ""} but received ${args.length}`);
5263
- }
5264
- }
5265
- validateTypes(name, args, signature) {
5266
- for (let i = 0;i < signature.length; i += 1) {
5267
- const currentSpec = signature[i].types;
5268
- const actualType = this.getTypeName(args[i]);
5269
- if (actualType === undefined) {
5270
- continue;
5271
- }
5272
- const typeMatched = currentSpec.some((expectedType) => this.typeMatches(actualType, expectedType, args[i]));
5273
- if (!typeMatched) {
5274
- const expected = currentSpec.map((typeId) => this.TYPE_NAME_TABLE[typeId]).join(" | ");
5275
- throw new Error(`Invalid type: ${name}() expected argument ${i + 1} to be type (${expected}) but received type ${this.TYPE_NAME_TABLE[actualType]} instead.`);
5276
- }
5277
- }
5278
- }
5279
- typeMatches(actual, expected, argValue) {
5280
- if (expected === 1) {
5281
- return true;
5282
- }
5283
- if (expected === 9 || expected === 8 || expected === 10 || expected === 11 || expected === 3) {
5284
- if (expected === 3) {
5285
- return actual === 3;
5286
- }
5287
- if (actual === 3) {
5288
- let subtype;
5289
- if (expected === 8) {
5290
- subtype = 0;
5291
- } else if (expected === 10) {
5292
- subtype = 4;
5293
- } else if (expected === 9) {
5294
- subtype = 2;
5295
- } else if (expected === 11) {
5296
- subtype = 3;
5297
- }
5298
- const array = argValue;
5299
- for (let i = 0;i < array.length; i += 1) {
5300
- const typeName = this.getTypeName(array[i]);
5301
- if (typeName !== undefined && subtype !== undefined && !this.typeMatches(typeName, subtype, array[i])) {
4469
+ _looksLikeJSON: function(literalString) {
4470
+ var startingChars = '[{"';
4471
+ var jsonLiterals = ["true", "false", "null"];
4472
+ var numberLooking = "-0123456789";
4473
+ if (literalString === "") {
4474
+ return false;
4475
+ } else if (startingChars.indexOf(literalString[0]) >= 0) {
4476
+ return true;
4477
+ } else if (jsonLiterals.indexOf(literalString) >= 0) {
4478
+ return true;
4479
+ } else if (numberLooking.indexOf(literalString[0]) >= 0) {
4480
+ try {
4481
+ JSON.parse(literalString);
4482
+ return true;
4483
+ } catch (ex) {
5302
4484
  return false;
5303
4485
  }
4486
+ } else {
4487
+ return false;
5304
4488
  }
5305
- return true;
5306
- }
5307
- } else {
5308
- return actual === expected;
5309
- }
5310
- return false;
5311
- }
5312
- getTypeName(obj) {
5313
- if (obj === null) {
5314
- return 7;
5315
- }
5316
- if (typeof obj === "string") {
5317
- return 2;
5318
- }
5319
- if (typeof obj === "number") {
5320
- return 0;
5321
- }
5322
- if (typeof obj === "boolean") {
5323
- return 5;
5324
- }
5325
- if (Array.isArray(obj)) {
5326
- return 3;
5327
- }
5328
- if (typeof obj === "object") {
5329
- if (obj.expref) {
5330
- return 6;
5331
- }
5332
- return 4;
5333
- }
5334
- return;
5335
- }
5336
- createKeyFunction(exprefNode, allowedTypes) {
5337
- const interpreter = this._interpreter;
5338
- const keyFunc = (x) => {
5339
- const current = interpreter.visit(exprefNode, x);
5340
- if (!allowedTypes.includes(this.getTypeName(current))) {
5341
- const msg = `Invalid type: expected one of (${allowedTypes.map((t) => this.TYPE_NAME_TABLE[t]).join(" | ")}), received ${this.TYPE_NAME_TABLE[this.getTypeName(current)]}`;
5342
- throw new Error(msg);
5343
- }
5344
- return current;
5345
- };
5346
- return keyFunc;
5347
- }
5348
- functionAvg = ([inputArray]) => {
5349
- if (!inputArray || inputArray.length == 0) {
5350
- return null;
5351
- }
5352
- let sum = 0;
5353
- for (let i = 0;i < inputArray.length; i += 1) {
5354
- sum += inputArray[i];
5355
- }
5356
- return sum / inputArray.length;
5357
- };
5358
- functionContains = ([
5359
- searchable,
5360
- searchValue
5361
- ]) => {
5362
- if (Array.isArray(searchable)) {
5363
- const array = searchable;
5364
- return array.includes(searchValue);
5365
- }
5366
- if (typeof searchable === "string") {
5367
- const text = searchable;
5368
- if (typeof searchValue === "string") {
5369
- return text.includes(searchValue);
5370
- }
5371
- }
5372
- return null;
5373
- };
5374
- functionEndsWith = (resolvedArgs) => {
5375
- const [searchStr, suffix] = resolvedArgs;
5376
- return searchStr.includes(suffix, searchStr.length - suffix.length);
5377
- };
5378
- functionFindFirst = this.createFindFunction(findFirst);
5379
- functionFindLast = this.createFindFunction(findLast);
5380
- createFindFunction(findFn) {
5381
- return (resolvedArgs) => {
5382
- const subject = resolvedArgs[0];
5383
- const search2 = resolvedArgs[1];
5384
- const start = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
5385
- const end = resolvedArgs.length > 3 ? resolvedArgs[3] : undefined;
5386
- return findFn(subject, search2, start, end);
5387
- };
5388
- }
5389
- functionFromItems = ([array]) => {
5390
- array.map((pair) => {
5391
- if (pair.length != 2 || typeof pair[0] !== "string") {
5392
- throw new Error("invalid value, each array must contain two elements, a pair of string and value");
5393
- }
5394
- });
5395
- return Object.fromEntries(array);
5396
- };
5397
- functionGroupBy = ([array, exprefNode]) => {
5398
- const keyFunction = this.createKeyFunction(exprefNode, [2]);
5399
- return array.reduce((acc, cur) => {
5400
- const k = keyFunction(cur ?? {});
5401
- const target = acc[k] = acc[k] || [];
5402
- target.push(cur);
5403
- return acc;
5404
- }, {});
5405
- };
5406
- functionItems = ([inputValue]) => {
5407
- return Object.entries(inputValue);
5408
- };
5409
- functionJoin = (resolvedArgs) => {
5410
- const [joinChar, listJoin] = resolvedArgs;
5411
- return listJoin.join(joinChar);
5412
- };
5413
- functionLength = ([inputValue]) => {
5414
- if (typeof inputValue === "string") {
5415
- return new Text(inputValue).length;
5416
- }
5417
- if (Array.isArray(inputValue)) {
5418
- return inputValue.length;
5419
- }
5420
- return Object.keys(inputValue).length;
5421
- };
5422
- functionMap = ([exprefNode, elements]) => {
5423
- if (!this._interpreter) {
5424
- return [];
5425
- }
5426
- const mapped = [];
5427
- const interpreter = this._interpreter;
5428
- for (let i = 0;i < elements.length; i += 1) {
5429
- mapped.push(interpreter.visit(exprefNode, elements[i]));
5430
- }
5431
- return mapped;
5432
- };
5433
- functionMax = ([inputValue]) => {
5434
- if (!inputValue.length) {
5435
- return null;
5436
- }
5437
- const typeName = this.getTypeName(inputValue[0]);
5438
- if (typeName === 0) {
5439
- return Math.max(...inputValue);
5440
- }
5441
- const elements = inputValue;
5442
- let maxElement = elements[0];
5443
- for (let i = 1;i < elements.length; i += 1) {
5444
- if (maxElement.localeCompare(elements[i]) < 0) {
5445
- maxElement = elements[i];
5446
- }
5447
- }
5448
- return maxElement;
5449
- };
5450
- functionMaxBy = (resolvedArgs) => {
5451
- const exprefNode = resolvedArgs[1];
5452
- const resolvedArray = resolvedArgs[0];
5453
- const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
5454
- let maxNumber = -Infinity;
5455
- let maxRecord;
5456
- let current;
5457
- for (let i = 0;i < resolvedArray.length; i += 1) {
5458
- current = keyFunction && keyFunction(resolvedArray[i]);
5459
- if (current !== undefined && current > maxNumber) {
5460
- maxNumber = current;
5461
- maxRecord = resolvedArray[i];
5462
- }
5463
- }
5464
- return maxRecord || null;
5465
- };
5466
- functionMerge = (resolvedArgs) => {
5467
- let merged = {};
5468
- for (let i = 0;i < resolvedArgs.length; i += 1) {
5469
- const current = resolvedArgs[i];
5470
- merged = Object.assign(merged, current);
5471
- }
5472
- return merged;
5473
- };
5474
- functionMin = ([inputValue]) => {
5475
- if (!inputValue.length) {
5476
- return null;
5477
- }
5478
- const typeName = this.getTypeName(inputValue[0]);
5479
- if (typeName === 0) {
5480
- return Math.min(...inputValue);
5481
- }
5482
- const elements = inputValue;
5483
- let minElement = elements[0];
5484
- for (let i = 1;i < elements.length; i += 1) {
5485
- if (elements[i].localeCompare(minElement) < 0) {
5486
- minElement = elements[i];
5487
4489
  }
5488
- }
5489
- return minElement;
5490
- };
5491
- functionMinBy = (resolvedArgs) => {
5492
- const exprefNode = resolvedArgs[1];
5493
- const resolvedArray = resolvedArgs[0];
5494
- const keyFunction = this.createKeyFunction(exprefNode, [0, 2]);
5495
- let minNumber = Infinity;
5496
- let minRecord;
5497
- let current;
5498
- for (let i = 0;i < resolvedArray.length; i += 1) {
5499
- current = keyFunction && keyFunction(resolvedArray[i]);
5500
- if (current !== undefined && current < minNumber) {
5501
- minNumber = current;
5502
- minRecord = resolvedArray[i];
5503
- }
5504
- }
5505
- return minRecord || null;
5506
- };
5507
- functionNotNull = (resolvedArgs) => {
5508
- for (let i = 0;i < resolvedArgs.length; i += 1) {
5509
- if (this.getTypeName(resolvedArgs[i]) !== 7) {
5510
- return resolvedArgs[i];
5511
- }
5512
- }
5513
- return null;
5514
- };
5515
- functionPadLeft = this.createPadFunction(padLeft);
5516
- functionPadRight = this.createPadFunction(padRight);
5517
- createPadFunction(padFn) {
5518
- return (resolvedArgs) => {
5519
- const subject = resolvedArgs[0];
5520
- const width = resolvedArgs[1];
5521
- const padding = resolvedArgs.length > 2 ? resolvedArgs[2] : undefined;
5522
- return padFn(subject, width, padding);
5523
4490
  };
5524
- }
5525
- functionReplace = (resolvedArgs) => {
5526
- const subject = resolvedArgs[0];
5527
- const string = resolvedArgs[1];
5528
- const by = resolvedArgs[2];
5529
- return replace(subject, string, by, resolvedArgs.length > 3 ? resolvedArgs[3] : undefined);
5530
- };
5531
- functionSplit = (resolvedArgs) => {
5532
- const subject = resolvedArgs[0];
5533
- const search2 = resolvedArgs[1];
5534
- return split(subject, search2, resolvedArgs.length > 2 ? resolvedArgs[2] : undefined);
5535
- };
5536
- functionReverse = ([inputValue]) => {
5537
- const typeName = this.getTypeName(inputValue);
5538
- if (typeName === 2) {
5539
- return new Text(inputValue).reverse();
5540
- }
5541
- const reversedArray = inputValue.slice(0);
5542
- reversedArray.reverse();
5543
- return reversedArray;
5544
- };
5545
- functionSort = ([inputValue]) => {
5546
- if (inputValue.length == 0) {
5547
- return inputValue;
5548
- }
5549
- if (typeof inputValue[0] === "string") {
5550
- return [...inputValue].sort(Text.comparer);
5551
- }
5552
- return [...inputValue].sort();
5553
- };
5554
- functionSortBy = (resolvedArgs) => {
5555
- const sortedArray = resolvedArgs[0].slice(0);
5556
- if (sortedArray.length === 0) {
5557
- return sortedArray;
5558
- }
5559
- const interpreter = this._interpreter;
5560
- const exprefNode = resolvedArgs[1];
5561
- const requiredType = this.getTypeName(interpreter.visit(exprefNode, sortedArray[0]));
5562
- if (requiredType !== undefined && ![0, 2].includes(requiredType)) {
5563
- throw new Error(`Invalid type: unexpected type (${this.TYPE_NAME_TABLE[requiredType]})`);
5564
- }
5565
- function throwInvalidTypeError(rt, item) {
5566
- throw new Error(`Invalid type: expected (${rt.TYPE_NAME_TABLE[requiredType]}), received ${rt.TYPE_NAME_TABLE[rt.getTypeName(item)]}`);
5567
- }
5568
- return sortedArray.sort((a, b) => {
5569
- const exprA = interpreter.visit(exprefNode, a);
5570
- const exprB = interpreter.visit(exprefNode, b);
5571
- if (this.getTypeName(exprA) !== requiredType) {
5572
- throwInvalidTypeError(this, exprA);
5573
- } else if (this.getTypeName(exprB) !== requiredType) {
5574
- throwInvalidTypeError(this, exprB);
5575
- }
5576
- if (requiredType === 2) {
5577
- return Text.comparer(exprA, exprB);
5578
- }
5579
- return exprA - exprB;
5580
- });
5581
- };
5582
- functionStartsWith = ([searchable, searchStr]) => {
5583
- return searchable.startsWith(searchStr);
5584
- };
5585
- functionSum = ([inputValue]) => {
5586
- return inputValue.reduce((x, y) => x + y, 0);
5587
- };
5588
- functionToArray = ([inputValue]) => {
5589
- if (this.getTypeName(inputValue) === 3) {
5590
- return inputValue;
5591
- }
5592
- return [inputValue];
5593
- };
5594
- functionToNumber = ([inputValue]) => {
5595
- const typeName = this.getTypeName(inputValue);
5596
- let convertedValue;
5597
- if (typeName === 0) {
5598
- return inputValue;
5599
- }
5600
- if (typeName === 2) {
5601
- convertedValue = +inputValue;
5602
- if (!isNaN(convertedValue)) {
5603
- return convertedValue;
5604
- }
5605
- }
5606
- return null;
5607
- };
5608
- functionToString = ([inputValue]) => {
5609
- if (this.getTypeName(inputValue) === 2) {
5610
- return inputValue;
5611
- }
5612
- return JSON.stringify(inputValue);
5613
- };
5614
- functionTrim = this.createTrimFunction(trim);
5615
- functionTrimLeft = this.createTrimFunction(trimLeft);
5616
- functionTrimRight = this.createTrimFunction(trimRight);
5617
- createTrimFunction(trimFn) {
5618
- return (resolvedArgs) => {
5619
- const subject = resolvedArgs[0];
5620
- const chars = resolvedArgs.length > 1 ? resolvedArgs[1] : undefined;
5621
- return trimFn(subject, chars);
5622
- };
5623
- }
5624
- functionType = ([inputValue]) => {
5625
- switch (this.getTypeName(inputValue)) {
5626
- case 0:
5627
- return "number";
5628
- case 2:
5629
- return "string";
5630
- case 3:
5631
- return "array";
5632
- case 4:
5633
- return "object";
5634
- case 5:
5635
- return "boolean";
5636
- case 7:
5637
- return "null";
5638
- default:
5639
- throw new Error("invalid-type");
5640
- }
5641
- };
5642
- functionZip = (array) => {
5643
- const length = Math.min(...array.map((arr) => arr.length));
5644
- const result = Array(length).fill(null).map((_, index) => array.map((arr) => arr[index]));
5645
- return result;
5646
- };
5647
- }, ScopeChain = class _ScopeChain {
5648
- inner = undefined;
5649
- data = {};
5650
- get currentScopeData() {
5651
- return this.data;
5652
- }
5653
- withScope(data) {
5654
- const outer = new _ScopeChain;
5655
- outer.inner = this;
5656
- outer.data = data;
5657
- return outer;
5658
- }
5659
- getValue(identifier) {
5660
- if (Object.prototype.hasOwnProperty.call(this.data, identifier)) {
5661
- return this.data[identifier];
5662
- }
5663
- if (this.inner) {
5664
- return this.inner.getValue(identifier);
5665
- }
5666
- return null;
5667
- }
5668
- }, emptyScopeChain, TreeInterpreter = class _TreeInterpreter {
5669
- runtime;
5670
- _rootValue = null;
5671
- _scope;
5672
- constructor() {
5673
- this.runtime = new Runtime(this);
5674
- this._scope = new ScopeChain;
5675
- }
5676
- withScope(scope) {
5677
- const interpreter = new _TreeInterpreter;
5678
- interpreter.runtime._functionTable = this.runtime._functionTable;
5679
- interpreter._rootValue = this._rootValue;
5680
- interpreter._scope = this._scope.withScope(scope);
5681
- return interpreter;
5682
- }
5683
- search(node, value) {
5684
- this._rootValue = value;
5685
- this._scope = emptyScopeChain;
5686
- return this.visit(node, value);
5687
- }
5688
- visit(node, value) {
5689
- switch (node.type) {
5690
- case "Ternary": {
5691
- const condition = this.visit(node.condition, value);
5692
- if (!isFalse(condition)) {
5693
- return this.visit(node.trueExpr, value);
5694
- }
5695
- return this.visit(node.falseExpr, value);
5696
- }
5697
- case "Field":
5698
- const identifier = node.name;
5699
- if (value === null || typeof value !== "object" || Array.isArray(value)) {
5700
- return null;
4491
+ var bindingPower = {};
4492
+ bindingPower[TOK_EOF] = 0;
4493
+ bindingPower[TOK_UNQUOTEDIDENTIFIER] = 0;
4494
+ bindingPower[TOK_QUOTEDIDENTIFIER] = 0;
4495
+ bindingPower[TOK_RBRACKET] = 0;
4496
+ bindingPower[TOK_RPAREN] = 0;
4497
+ bindingPower[TOK_COMMA] = 0;
4498
+ bindingPower[TOK_RBRACE] = 0;
4499
+ bindingPower[TOK_NUMBER] = 0;
4500
+ bindingPower[TOK_CURRENT] = 0;
4501
+ bindingPower[TOK_EXPREF] = 0;
4502
+ bindingPower[TOK_PIPE] = 1;
4503
+ bindingPower[TOK_OR] = 2;
4504
+ bindingPower[TOK_AND] = 3;
4505
+ bindingPower[TOK_EQ] = 5;
4506
+ bindingPower[TOK_GT] = 5;
4507
+ bindingPower[TOK_LT] = 5;
4508
+ bindingPower[TOK_GTE] = 5;
4509
+ bindingPower[TOK_LTE] = 5;
4510
+ bindingPower[TOK_NE] = 5;
4511
+ bindingPower[TOK_FLATTEN] = 9;
4512
+ bindingPower[TOK_STAR] = 20;
4513
+ bindingPower[TOK_FILTER] = 21;
4514
+ bindingPower[TOK_DOT] = 40;
4515
+ bindingPower[TOK_NOT] = 45;
4516
+ bindingPower[TOK_LBRACE] = 50;
4517
+ bindingPower[TOK_LBRACKET] = 55;
4518
+ bindingPower[TOK_LPAREN] = 60;
4519
+ function Parser() {}
4520
+ Parser.prototype = {
4521
+ parse: function(expression) {
4522
+ this._loadTokens(expression);
4523
+ this.index = 0;
4524
+ var ast = this.expression(0);
4525
+ if (this._lookahead(0) !== TOK_EOF) {
4526
+ var t = this._lookaheadToken(0);
4527
+ var error = new Error("Unexpected token type: " + t.type + ", value: " + t.value);
4528
+ error.name = "ParserError";
4529
+ throw error;
4530
+ }
4531
+ return ast;
4532
+ },
4533
+ _loadTokens: function(expression) {
4534
+ var lexer = new Lexer;
4535
+ var tokens = lexer.tokenize(expression);
4536
+ tokens.push({ type: TOK_EOF, value: "", start: expression.length });
4537
+ this.tokens = tokens;
4538
+ },
4539
+ expression: function(rbp) {
4540
+ var leftToken = this._lookaheadToken(0);
4541
+ this._advance();
4542
+ var left = this.nud(leftToken);
4543
+ var currentToken = this._lookahead(0);
4544
+ while (rbp < bindingPower[currentToken]) {
4545
+ this._advance();
4546
+ left = this.led(currentToken, left);
4547
+ currentToken = this._lookahead(0);
4548
+ }
4549
+ return left;
4550
+ },
4551
+ _lookahead: function(number) {
4552
+ return this.tokens[this.index + number].type;
4553
+ },
4554
+ _lookaheadToken: function(number) {
4555
+ return this.tokens[this.index + number];
4556
+ },
4557
+ _advance: function() {
4558
+ this.index++;
4559
+ },
4560
+ nud: function(token) {
4561
+ var left;
4562
+ var right;
4563
+ var expression;
4564
+ switch (token.type) {
4565
+ case TOK_LITERAL:
4566
+ return { type: "Literal", value: token.value };
4567
+ case TOK_UNQUOTEDIDENTIFIER:
4568
+ return { type: "Field", name: token.value };
4569
+ case TOK_QUOTEDIDENTIFIER:
4570
+ var node = { type: "Field", name: token.value };
4571
+ if (this._lookahead(0) === TOK_LPAREN) {
4572
+ throw new Error("Quoted identifier not allowed for function names.");
4573
+ }
4574
+ return node;
4575
+ case TOK_NOT:
4576
+ right = this.expression(bindingPower.Not);
4577
+ return { type: "NotExpression", children: [right] };
4578
+ case TOK_STAR:
4579
+ left = { type: "Identity" };
4580
+ right = null;
4581
+ if (this._lookahead(0) === TOK_RBRACKET) {
4582
+ right = { type: "Identity" };
4583
+ } else {
4584
+ right = this._parseProjectionRHS(bindingPower.Star);
4585
+ }
4586
+ return { type: "ValueProjection", children: [left, right] };
4587
+ case TOK_FILTER:
4588
+ return this.led(token.type, { type: "Identity" });
4589
+ case TOK_LBRACE:
4590
+ return this._parseMultiselectHash();
4591
+ case TOK_FLATTEN:
4592
+ left = { type: TOK_FLATTEN, children: [{ type: "Identity" }] };
4593
+ right = this._parseProjectionRHS(bindingPower.Flatten);
4594
+ return { type: "Projection", children: [left, right] };
4595
+ case TOK_LBRACKET:
4596
+ if (this._lookahead(0) === TOK_NUMBER || this._lookahead(0) === TOK_COLON) {
4597
+ right = this._parseIndexExpression();
4598
+ return this._projectIfSlice({ type: "Identity" }, right);
4599
+ } else if (this._lookahead(0) === TOK_STAR && this._lookahead(1) === TOK_RBRACKET) {
4600
+ this._advance();
4601
+ this._advance();
4602
+ right = this._parseProjectionRHS(bindingPower.Star);
4603
+ return {
4604
+ type: "Projection",
4605
+ children: [{ type: "Identity" }, right]
4606
+ };
4607
+ }
4608
+ return this._parseMultiselectList();
4609
+ case TOK_CURRENT:
4610
+ return { type: TOK_CURRENT };
4611
+ case TOK_EXPREF:
4612
+ expression = this.expression(bindingPower.Expref);
4613
+ return { type: "ExpressionReference", children: [expression] };
4614
+ case TOK_LPAREN:
4615
+ var args = [];
4616
+ while (this._lookahead(0) !== TOK_RPAREN) {
4617
+ if (this._lookahead(0) === TOK_CURRENT) {
4618
+ expression = { type: TOK_CURRENT };
4619
+ this._advance();
4620
+ } else {
4621
+ expression = this.expression(0);
4622
+ }
4623
+ args.push(expression);
4624
+ }
4625
+ this._match(TOK_RPAREN);
4626
+ return args[0];
4627
+ default:
4628
+ this._errorToken(token);
4629
+ }
4630
+ },
4631
+ led: function(tokenName, left) {
4632
+ var right;
4633
+ switch (tokenName) {
4634
+ case TOK_DOT:
4635
+ var rbp = bindingPower.Dot;
4636
+ if (this._lookahead(0) !== TOK_STAR) {
4637
+ right = this._parseDotRHS(rbp);
4638
+ return { type: "Subexpression", children: [left, right] };
4639
+ }
4640
+ this._advance();
4641
+ right = this._parseProjectionRHS(rbp);
4642
+ return { type: "ValueProjection", children: [left, right] };
4643
+ case TOK_PIPE:
4644
+ right = this.expression(bindingPower.Pipe);
4645
+ return { type: TOK_PIPE, children: [left, right] };
4646
+ case TOK_OR:
4647
+ right = this.expression(bindingPower.Or);
4648
+ return { type: "OrExpression", children: [left, right] };
4649
+ case TOK_AND:
4650
+ right = this.expression(bindingPower.And);
4651
+ return { type: "AndExpression", children: [left, right] };
4652
+ case TOK_LPAREN:
4653
+ var name = left.name;
4654
+ var args = [];
4655
+ var expression, node;
4656
+ while (this._lookahead(0) !== TOK_RPAREN) {
4657
+ if (this._lookahead(0) === TOK_CURRENT) {
4658
+ expression = { type: TOK_CURRENT };
4659
+ this._advance();
4660
+ } else {
4661
+ expression = this.expression(0);
4662
+ }
4663
+ if (this._lookahead(0) === TOK_COMMA) {
4664
+ this._match(TOK_COMMA);
4665
+ }
4666
+ args.push(expression);
4667
+ }
4668
+ this._match(TOK_RPAREN);
4669
+ node = { type: "Function", name, children: args };
4670
+ return node;
4671
+ case TOK_FILTER:
4672
+ var condition = this.expression(0);
4673
+ this._match(TOK_RBRACKET);
4674
+ if (this._lookahead(0) === TOK_FLATTEN) {
4675
+ right = { type: "Identity" };
4676
+ } else {
4677
+ right = this._parseProjectionRHS(bindingPower.Filter);
4678
+ }
4679
+ return { type: "FilterProjection", children: [left, right, condition] };
4680
+ case TOK_FLATTEN:
4681
+ var leftNode = { type: TOK_FLATTEN, children: [left] };
4682
+ var rightNode = this._parseProjectionRHS(bindingPower.Flatten);
4683
+ return { type: "Projection", children: [leftNode, rightNode] };
4684
+ case TOK_EQ:
4685
+ case TOK_NE:
4686
+ case TOK_GT:
4687
+ case TOK_GTE:
4688
+ case TOK_LT:
4689
+ case TOK_LTE:
4690
+ return this._parseComparator(left, tokenName);
4691
+ case TOK_LBRACKET:
4692
+ var token = this._lookaheadToken(0);
4693
+ if (token.type === TOK_NUMBER || token.type === TOK_COLON) {
4694
+ right = this._parseIndexExpression();
4695
+ return this._projectIfSlice(left, right);
4696
+ }
4697
+ this._match(TOK_STAR);
4698
+ this._match(TOK_RBRACKET);
4699
+ right = this._parseProjectionRHS(bindingPower.Star);
4700
+ return { type: "Projection", children: [left, right] };
4701
+ default:
4702
+ this._errorToken(this._lookaheadToken(0));
4703
+ }
4704
+ },
4705
+ _match: function(tokenType) {
4706
+ if (this._lookahead(0) === tokenType) {
4707
+ this._advance();
4708
+ } else {
4709
+ var t = this._lookaheadToken(0);
4710
+ var error = new Error("Expected " + tokenType + ", got: " + t.type);
4711
+ error.name = "ParserError";
4712
+ throw error;
4713
+ }
4714
+ },
4715
+ _errorToken: function(token) {
4716
+ var error = new Error("Invalid token (" + token.type + '): "' + token.value + '"');
4717
+ error.name = "ParserError";
4718
+ throw error;
4719
+ },
4720
+ _parseIndexExpression: function() {
4721
+ if (this._lookahead(0) === TOK_COLON || this._lookahead(1) === TOK_COLON) {
4722
+ return this._parseSliceExpression();
4723
+ } else {
4724
+ var node = {
4725
+ type: "Index",
4726
+ value: this._lookaheadToken(0).value
4727
+ };
4728
+ this._advance();
4729
+ this._match(TOK_RBRACKET);
4730
+ return node;
5701
4731
  }
5702
- return value[identifier] ?? null;
5703
- case "LetExpression": {
5704
- const { bindings, expression } = node;
5705
- let scope = {};
5706
- bindings.forEach((binding) => {
5707
- const reference = this.visit(binding, value);
5708
- scope = {
5709
- ...scope,
5710
- ...reference
4732
+ },
4733
+ _projectIfSlice: function(left, right) {
4734
+ var indexExpr = { type: "IndexExpression", children: [left, right] };
4735
+ if (right.type === "Slice") {
4736
+ return {
4737
+ type: "Projection",
4738
+ children: [indexExpr, this._parseProjectionRHS(bindingPower.Star)]
5711
4739
  };
5712
- });
5713
- return this.withScope(scope).visit(expression, value);
5714
- }
5715
- case "Binding": {
5716
- const { variable, reference } = node;
5717
- const result = this.visit(reference, value);
5718
- return { [variable]: result };
5719
- }
5720
- case "Variable": {
5721
- const variable = node.name;
5722
- if (!this._scope.getValue(variable) && !Object.prototype.hasOwnProperty.call(this._scope.currentScopeData, variable)) {
5723
- throw new Error(`Error referencing undefined variable ${variable}`);
4740
+ } else {
4741
+ return indexExpr;
5724
4742
  }
5725
- return this._scope.getValue(variable);
5726
- }
5727
- case "IndexExpression":
5728
- return this.visit(node.right, this.visit(node.left, value));
5729
- case "Subexpression": {
5730
- const result = this.visit(node.left, value);
5731
- return result != null ? this.visit(node.right, result) ?? null : null;
5732
- }
5733
- case "Index": {
5734
- if (!Array.isArray(value)) {
5735
- return null;
4743
+ },
4744
+ _parseSliceExpression: function() {
4745
+ var parts = [null, null, null];
4746
+ var index = 0;
4747
+ var currentToken = this._lookahead(0);
4748
+ while (currentToken !== TOK_RBRACKET && index < 3) {
4749
+ if (currentToken === TOK_COLON) {
4750
+ index++;
4751
+ this._advance();
4752
+ } else if (currentToken === TOK_NUMBER) {
4753
+ parts[index] = this._lookaheadToken(0).value;
4754
+ this._advance();
4755
+ } else {
4756
+ var t = this._lookahead(0);
4757
+ var error = new Error("Syntax error, unexpected token: " + t.value + "(" + t.type + ")");
4758
+ error.name = "Parsererror";
4759
+ throw error;
4760
+ }
4761
+ currentToken = this._lookahead(0);
5736
4762
  }
5737
- const index = node.value < 0 ? value.length + node.value : node.value;
5738
- return value[index] ?? null;
5739
- }
5740
- case "Slice": {
5741
- if (!Array.isArray(value) && typeof value !== "string") {
5742
- return null;
4763
+ this._match(TOK_RBRACKET);
4764
+ return {
4765
+ type: "Slice",
4766
+ children: parts
4767
+ };
4768
+ },
4769
+ _parseComparator: function(left, comparator) {
4770
+ var right = this.expression(bindingPower[comparator]);
4771
+ return { type: "Comparator", name: comparator, children: [left, right] };
4772
+ },
4773
+ _parseDotRHS: function(rbp) {
4774
+ var lookahead = this._lookahead(0);
4775
+ var exprTokens = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER, TOK_STAR];
4776
+ if (exprTokens.indexOf(lookahead) >= 0) {
4777
+ return this.expression(rbp);
4778
+ } else if (lookahead === TOK_LBRACKET) {
4779
+ this._match(TOK_LBRACKET);
4780
+ return this._parseMultiselectList();
4781
+ } else if (lookahead === TOK_LBRACE) {
4782
+ this._match(TOK_LBRACE);
4783
+ return this._parseMultiselectHash();
5743
4784
  }
5744
- const { start, stop, step } = this.computeSliceParams(value.length, node);
5745
- if (typeof value === "string") {
5746
- const chars = [...value];
5747
- const sliced = this.slice(chars, start, stop, step);
5748
- return sliced.join("");
4785
+ },
4786
+ _parseProjectionRHS: function(rbp) {
4787
+ var right;
4788
+ if (bindingPower[this._lookahead(0)] < 10) {
4789
+ right = { type: "Identity" };
4790
+ } else if (this._lookahead(0) === TOK_LBRACKET) {
4791
+ right = this.expression(rbp);
4792
+ } else if (this._lookahead(0) === TOK_FILTER) {
4793
+ right = this.expression(rbp);
4794
+ } else if (this._lookahead(0) === TOK_DOT) {
4795
+ this._match(TOK_DOT);
4796
+ right = this._parseDotRHS(rbp);
5749
4797
  } else {
5750
- return this.slice(value, start, stop, step);
4798
+ var t = this._lookaheadToken(0);
4799
+ var error = new Error("Sytanx error, unexpected token: " + t.value + "(" + t.type + ")");
4800
+ error.name = "ParserError";
4801
+ throw error;
4802
+ }
4803
+ return right;
4804
+ },
4805
+ _parseMultiselectList: function() {
4806
+ var expressions = [];
4807
+ while (this._lookahead(0) !== TOK_RBRACKET) {
4808
+ var expression = this.expression(0);
4809
+ expressions.push(expression);
4810
+ if (this._lookahead(0) === TOK_COMMA) {
4811
+ this._match(TOK_COMMA);
4812
+ if (this._lookahead(0) === TOK_RBRACKET) {
4813
+ throw new Error("Unexpected token Rbracket");
4814
+ }
4815
+ }
4816
+ }
4817
+ this._match(TOK_RBRACKET);
4818
+ return { type: "MultiSelectList", children: expressions };
4819
+ },
4820
+ _parseMultiselectHash: function() {
4821
+ var pairs2 = [];
4822
+ var identifierTypes = [TOK_UNQUOTEDIDENTIFIER, TOK_QUOTEDIDENTIFIER];
4823
+ var keyToken, keyName, value, node;
4824
+ for (;; ) {
4825
+ keyToken = this._lookaheadToken(0);
4826
+ if (identifierTypes.indexOf(keyToken.type) < 0) {
4827
+ throw new Error("Expecting an identifier token, got: " + keyToken.type);
4828
+ }
4829
+ keyName = keyToken.value;
4830
+ this._advance();
4831
+ this._match(TOK_COLON);
4832
+ value = this.expression(0);
4833
+ node = { type: "KeyValuePair", name: keyName, value };
4834
+ pairs2.push(node);
4835
+ if (this._lookahead(0) === TOK_COMMA) {
4836
+ this._match(TOK_COMMA);
4837
+ } else if (this._lookahead(0) === TOK_RBRACE) {
4838
+ this._match(TOK_RBRACE);
4839
+ break;
4840
+ }
5751
4841
  }
4842
+ return { type: "MultiSelectHash", children: pairs2 };
5752
4843
  }
5753
- case "Projection": {
5754
- const { left, right } = node;
5755
- let allowString = false;
5756
- if (left.type === "IndexExpression" && left.right.type === "Slice") {
5757
- allowString = true;
4844
+ };
4845
+ function TreeInterpreter(runtime) {
4846
+ this.runtime = runtime;
4847
+ }
4848
+ TreeInterpreter.prototype = {
4849
+ search: function(node, value) {
4850
+ return this.visit(node, value);
4851
+ },
4852
+ visit: function(node, value) {
4853
+ var matched, current, result, first, second, field, left, right, collected, i;
4854
+ switch (node.type) {
4855
+ case "Field":
4856
+ if (value !== null && isObject(value)) {
4857
+ field = value[node.name];
4858
+ if (field === undefined) {
4859
+ return null;
4860
+ } else {
4861
+ return field;
4862
+ }
4863
+ }
4864
+ return null;
4865
+ case "Subexpression":
4866
+ result = this.visit(node.children[0], value);
4867
+ for (i = 1;i < node.children.length; i++) {
4868
+ result = this.visit(node.children[1], result);
4869
+ if (result === null) {
4870
+ return null;
4871
+ }
4872
+ }
4873
+ return result;
4874
+ case "IndexExpression":
4875
+ left = this.visit(node.children[0], value);
4876
+ right = this.visit(node.children[1], left);
4877
+ return right;
4878
+ case "Index":
4879
+ if (!isArray(value)) {
4880
+ return null;
4881
+ }
4882
+ var index = node.value;
4883
+ if (index < 0) {
4884
+ index = value.length + index;
4885
+ }
4886
+ result = value[index];
4887
+ if (result === undefined) {
4888
+ result = null;
4889
+ }
4890
+ return result;
4891
+ case "Slice":
4892
+ if (!isArray(value)) {
4893
+ return null;
4894
+ }
4895
+ var sliceParams = node.children.slice(0);
4896
+ var computed = this.computeSliceParams(value.length, sliceParams);
4897
+ var start = computed[0];
4898
+ var stop = computed[1];
4899
+ var step = computed[2];
4900
+ result = [];
4901
+ if (step > 0) {
4902
+ for (i = start;i < stop; i += step) {
4903
+ result.push(value[i]);
4904
+ }
4905
+ } else {
4906
+ for (i = start;i > stop; i += step) {
4907
+ result.push(value[i]);
4908
+ }
4909
+ }
4910
+ return result;
4911
+ case "Projection":
4912
+ var base = this.visit(node.children[0], value);
4913
+ if (!isArray(base)) {
4914
+ return null;
4915
+ }
4916
+ collected = [];
4917
+ for (i = 0;i < base.length; i++) {
4918
+ current = this.visit(node.children[1], base[i]);
4919
+ if (current !== null) {
4920
+ collected.push(current);
4921
+ }
4922
+ }
4923
+ return collected;
4924
+ case "ValueProjection":
4925
+ base = this.visit(node.children[0], value);
4926
+ if (!isObject(base)) {
4927
+ return null;
4928
+ }
4929
+ collected = [];
4930
+ var values = objValues(base);
4931
+ for (i = 0;i < values.length; i++) {
4932
+ current = this.visit(node.children[1], values[i]);
4933
+ if (current !== null) {
4934
+ collected.push(current);
4935
+ }
4936
+ }
4937
+ return collected;
4938
+ case "FilterProjection":
4939
+ base = this.visit(node.children[0], value);
4940
+ if (!isArray(base)) {
4941
+ return null;
4942
+ }
4943
+ var filtered = [];
4944
+ var finalResults = [];
4945
+ for (i = 0;i < base.length; i++) {
4946
+ matched = this.visit(node.children[2], base[i]);
4947
+ if (!isFalse(matched)) {
4948
+ filtered.push(base[i]);
4949
+ }
4950
+ }
4951
+ for (var j = 0;j < filtered.length; j++) {
4952
+ current = this.visit(node.children[1], filtered[j]);
4953
+ if (current !== null) {
4954
+ finalResults.push(current);
4955
+ }
4956
+ }
4957
+ return finalResults;
4958
+ case "Comparator":
4959
+ first = this.visit(node.children[0], value);
4960
+ second = this.visit(node.children[1], value);
4961
+ switch (node.name) {
4962
+ case TOK_EQ:
4963
+ result = strictDeepEqual(first, second);
4964
+ break;
4965
+ case TOK_NE:
4966
+ result = !strictDeepEqual(first, second);
4967
+ break;
4968
+ case TOK_GT:
4969
+ result = first > second;
4970
+ break;
4971
+ case TOK_GTE:
4972
+ result = first >= second;
4973
+ break;
4974
+ case TOK_LT:
4975
+ result = first < second;
4976
+ break;
4977
+ case TOK_LTE:
4978
+ result = first <= second;
4979
+ break;
4980
+ default:
4981
+ throw new Error("Unknown comparator: " + node.name);
4982
+ }
4983
+ return result;
4984
+ case TOK_FLATTEN:
4985
+ var original = this.visit(node.children[0], value);
4986
+ if (!isArray(original)) {
4987
+ return null;
4988
+ }
4989
+ var merged = [];
4990
+ for (i = 0;i < original.length; i++) {
4991
+ current = original[i];
4992
+ if (isArray(current)) {
4993
+ merged.push.apply(merged, current);
4994
+ } else {
4995
+ merged.push(current);
4996
+ }
4997
+ }
4998
+ return merged;
4999
+ case "Identity":
5000
+ return value;
5001
+ case "MultiSelectList":
5002
+ if (value === null) {
5003
+ return null;
5004
+ }
5005
+ collected = [];
5006
+ for (i = 0;i < node.children.length; i++) {
5007
+ collected.push(this.visit(node.children[i], value));
5008
+ }
5009
+ return collected;
5010
+ case "MultiSelectHash":
5011
+ if (value === null) {
5012
+ return null;
5013
+ }
5014
+ collected = {};
5015
+ var child;
5016
+ for (i = 0;i < node.children.length; i++) {
5017
+ child = node.children[i];
5018
+ collected[child.name] = this.visit(child.value, value);
5019
+ }
5020
+ return collected;
5021
+ case "OrExpression":
5022
+ matched = this.visit(node.children[0], value);
5023
+ if (isFalse(matched)) {
5024
+ matched = this.visit(node.children[1], value);
5025
+ }
5026
+ return matched;
5027
+ case "AndExpression":
5028
+ first = this.visit(node.children[0], value);
5029
+ if (isFalse(first) === true) {
5030
+ return first;
5031
+ }
5032
+ return this.visit(node.children[1], value);
5033
+ case "NotExpression":
5034
+ first = this.visit(node.children[0], value);
5035
+ return isFalse(first);
5036
+ case "Literal":
5037
+ return node.value;
5038
+ case TOK_PIPE:
5039
+ left = this.visit(node.children[0], value);
5040
+ return this.visit(node.children[1], left);
5041
+ case TOK_CURRENT:
5042
+ return value;
5043
+ case "Function":
5044
+ var resolvedArgs = [];
5045
+ for (i = 0;i < node.children.length; i++) {
5046
+ resolvedArgs.push(this.visit(node.children[i], value));
5047
+ }
5048
+ return this.runtime.callFunction(node.name, resolvedArgs);
5049
+ case "ExpressionReference":
5050
+ var refNode = node.children[0];
5051
+ refNode.jmespathType = TOK_EXPREF;
5052
+ return refNode;
5053
+ default:
5054
+ throw new Error("Unknown node type: " + node.type);
5055
+ }
5056
+ },
5057
+ computeSliceParams: function(arrayLength, sliceParams) {
5058
+ var start = sliceParams[0];
5059
+ var stop = sliceParams[1];
5060
+ var step = sliceParams[2];
5061
+ var computed = [null, null, null];
5062
+ if (step === null) {
5063
+ step = 1;
5064
+ } else if (step === 0) {
5065
+ var error = new Error("Invalid slice, step cannot be 0");
5066
+ error.name = "RuntimeError";
5067
+ throw error;
5758
5068
  }
5759
- const base = this.visit(left, value);
5760
- if (allowString && typeof base === "string") {
5761
- return this.visit(right, base);
5069
+ var stepValueNegative = step < 0 ? true : false;
5070
+ if (start === null) {
5071
+ start = stepValueNegative ? arrayLength - 1 : 0;
5072
+ } else {
5073
+ start = this.capSliceRange(arrayLength, start, step);
5762
5074
  }
5763
- if (!Array.isArray(base)) {
5764
- return null;
5075
+ if (stop === null) {
5076
+ stop = stepValueNegative ? -1 : arrayLength;
5077
+ } else {
5078
+ stop = this.capSliceRange(arrayLength, stop, step);
5765
5079
  }
5766
- const collected = [];
5767
- for (const elem of base) {
5768
- const current = this.visit(right, elem);
5769
- if (current !== null) {
5770
- collected.push(current);
5080
+ computed[0] = start;
5081
+ computed[1] = stop;
5082
+ computed[2] = step;
5083
+ return computed;
5084
+ },
5085
+ capSliceRange: function(arrayLength, actualValue, step) {
5086
+ if (actualValue < 0) {
5087
+ actualValue += arrayLength;
5088
+ if (actualValue < 0) {
5089
+ actualValue = step < 0 ? -1 : 0;
5771
5090
  }
5091
+ } else if (actualValue >= arrayLength) {
5092
+ actualValue = step < 0 ? arrayLength - 1 : arrayLength;
5772
5093
  }
5773
- return collected;
5094
+ return actualValue;
5774
5095
  }
5775
- case "ValueProjection": {
5776
- const { left, right } = node;
5777
- const base = this.visit(left, value);
5778
- if (base === null || typeof base !== "object" || Array.isArray(base)) {
5779
- return null;
5096
+ };
5097
+ function Runtime(interpreter) {
5098
+ this._interpreter = interpreter;
5099
+ this.functionTable = {
5100
+ abs: { _func: this._functionAbs, _signature: [{ types: [TYPE_NUMBER] }] },
5101
+ avg: { _func: this._functionAvg, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
5102
+ ceil: { _func: this._functionCeil, _signature: [{ types: [TYPE_NUMBER] }] },
5103
+ contains: {
5104
+ _func: this._functionContains,
5105
+ _signature: [
5106
+ { types: [TYPE_STRING, TYPE_ARRAY] },
5107
+ { types: [TYPE_ANY] }
5108
+ ]
5109
+ },
5110
+ ends_with: {
5111
+ _func: this._functionEndsWith,
5112
+ _signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
5113
+ },
5114
+ floor: { _func: this._functionFloor, _signature: [{ types: [TYPE_NUMBER] }] },
5115
+ length: {
5116
+ _func: this._functionLength,
5117
+ _signature: [{ types: [TYPE_STRING, TYPE_ARRAY, TYPE_OBJECT] }]
5118
+ },
5119
+ map: {
5120
+ _func: this._functionMap,
5121
+ _signature: [{ types: [TYPE_EXPREF] }, { types: [TYPE_ARRAY] }]
5122
+ },
5123
+ max: {
5124
+ _func: this._functionMax,
5125
+ _signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
5126
+ },
5127
+ merge: {
5128
+ _func: this._functionMerge,
5129
+ _signature: [{ types: [TYPE_OBJECT], variadic: true }]
5130
+ },
5131
+ max_by: {
5132
+ _func: this._functionMaxBy,
5133
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
5134
+ },
5135
+ sum: { _func: this._functionSum, _signature: [{ types: [TYPE_ARRAY_NUMBER] }] },
5136
+ starts_with: {
5137
+ _func: this._functionStartsWith,
5138
+ _signature: [{ types: [TYPE_STRING] }, { types: [TYPE_STRING] }]
5139
+ },
5140
+ min: {
5141
+ _func: this._functionMin,
5142
+ _signature: [{ types: [TYPE_ARRAY_NUMBER, TYPE_ARRAY_STRING] }]
5143
+ },
5144
+ min_by: {
5145
+ _func: this._functionMinBy,
5146
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
5147
+ },
5148
+ type: { _func: this._functionType, _signature: [{ types: [TYPE_ANY] }] },
5149
+ keys: { _func: this._functionKeys, _signature: [{ types: [TYPE_OBJECT] }] },
5150
+ values: { _func: this._functionValues, _signature: [{ types: [TYPE_OBJECT] }] },
5151
+ sort: { _func: this._functionSort, _signature: [{ types: [TYPE_ARRAY_STRING, TYPE_ARRAY_NUMBER] }] },
5152
+ sort_by: {
5153
+ _func: this._functionSortBy,
5154
+ _signature: [{ types: [TYPE_ARRAY] }, { types: [TYPE_EXPREF] }]
5155
+ },
5156
+ join: {
5157
+ _func: this._functionJoin,
5158
+ _signature: [
5159
+ { types: [TYPE_STRING] },
5160
+ { types: [TYPE_ARRAY_STRING] }
5161
+ ]
5162
+ },
5163
+ reverse: {
5164
+ _func: this._functionReverse,
5165
+ _signature: [{ types: [TYPE_STRING, TYPE_ARRAY] }]
5166
+ },
5167
+ to_array: { _func: this._functionToArray, _signature: [{ types: [TYPE_ANY] }] },
5168
+ to_string: { _func: this._functionToString, _signature: [{ types: [TYPE_ANY] }] },
5169
+ to_number: { _func: this._functionToNumber, _signature: [{ types: [TYPE_ANY] }] },
5170
+ not_null: {
5171
+ _func: this._functionNotNull,
5172
+ _signature: [{ types: [TYPE_ANY], variadic: true }]
5173
+ }
5174
+ };
5175
+ }
5176
+ Runtime.prototype = {
5177
+ callFunction: function(name, resolvedArgs) {
5178
+ var functionEntry = this.functionTable[name];
5179
+ if (functionEntry === undefined) {
5180
+ throw new Error("Unknown function: " + name + "()");
5780
5181
  }
5781
- const collected = [];
5782
- const values = Object.values(base);
5783
- for (const elem of values) {
5784
- const current = this.visit(right, elem);
5785
- if (current !== null) {
5786
- collected.push(current);
5182
+ this._validateArgs(name, resolvedArgs, functionEntry._signature);
5183
+ return functionEntry._func.call(this, resolvedArgs);
5184
+ },
5185
+ _validateArgs: function(name, args, signature) {
5186
+ var pluralized;
5187
+ if (signature[signature.length - 1].variadic) {
5188
+ if (args.length < signature.length) {
5189
+ pluralized = signature.length === 1 ? " argument" : " arguments";
5190
+ throw new Error("ArgumentError: " + name + "() " + "takes at least" + signature.length + pluralized + " but received " + args.length);
5191
+ }
5192
+ } else if (args.length !== signature.length) {
5193
+ pluralized = signature.length === 1 ? " argument" : " arguments";
5194
+ throw new Error("ArgumentError: " + name + "() " + "takes " + signature.length + pluralized + " but received " + args.length);
5195
+ }
5196
+ var currentSpec;
5197
+ var actualType;
5198
+ var typeMatched;
5199
+ for (var i = 0;i < signature.length; i++) {
5200
+ typeMatched = false;
5201
+ currentSpec = signature[i].types;
5202
+ actualType = this._getTypeName(args[i]);
5203
+ for (var j = 0;j < currentSpec.length; j++) {
5204
+ if (this._typeMatches(actualType, currentSpec[j], args[i])) {
5205
+ typeMatched = true;
5206
+ break;
5207
+ }
5208
+ }
5209
+ if (!typeMatched) {
5210
+ var expected = currentSpec.map(function(typeIdentifier) {
5211
+ return TYPE_NAME_TABLE[typeIdentifier];
5212
+ }).join(",");
5213
+ throw new Error("TypeError: " + name + "() " + "expected argument " + (i + 1) + " to be type " + expected + " but received type " + TYPE_NAME_TABLE[actualType] + " instead.");
5787
5214
  }
5788
5215
  }
5789
- return collected;
5790
- }
5791
- case "FilterProjection": {
5792
- const { left, right, condition } = node;
5793
- const base = this.visit(left, value);
5794
- if (!Array.isArray(base)) {
5795
- return null;
5216
+ },
5217
+ _typeMatches: function(actual, expected, argValue) {
5218
+ if (expected === TYPE_ANY) {
5219
+ return true;
5796
5220
  }
5797
- const results = [];
5798
- for (const elem of base) {
5799
- const matched = this.visit(condition, elem);
5800
- if (isFalse(matched)) {
5801
- continue;
5221
+ if (expected === TYPE_ARRAY_STRING || expected === TYPE_ARRAY_NUMBER || expected === TYPE_ARRAY) {
5222
+ if (expected === TYPE_ARRAY) {
5223
+ return actual === TYPE_ARRAY;
5224
+ } else if (actual === TYPE_ARRAY) {
5225
+ var subtype;
5226
+ if (expected === TYPE_ARRAY_NUMBER) {
5227
+ subtype = TYPE_NUMBER;
5228
+ } else if (expected === TYPE_ARRAY_STRING) {
5229
+ subtype = TYPE_STRING;
5230
+ }
5231
+ for (var i = 0;i < argValue.length; i++) {
5232
+ if (!this._typeMatches(this._getTypeName(argValue[i]), subtype, argValue[i])) {
5233
+ return false;
5234
+ }
5235
+ }
5236
+ return true;
5802
5237
  }
5803
- const result = this.visit(right, elem);
5804
- if (result !== null) {
5805
- results.push(result);
5238
+ } else {
5239
+ return actual === expected;
5240
+ }
5241
+ },
5242
+ _getTypeName: function(obj) {
5243
+ switch (Object.prototype.toString.call(obj)) {
5244
+ case "[object String]":
5245
+ return TYPE_STRING;
5246
+ case "[object Number]":
5247
+ return TYPE_NUMBER;
5248
+ case "[object Array]":
5249
+ return TYPE_ARRAY;
5250
+ case "[object Boolean]":
5251
+ return TYPE_BOOLEAN;
5252
+ case "[object Null]":
5253
+ return TYPE_NULL;
5254
+ case "[object Object]":
5255
+ if (obj.jmespathType === TOK_EXPREF) {
5256
+ return TYPE_EXPREF;
5257
+ } else {
5258
+ return TYPE_OBJECT;
5259
+ }
5260
+ }
5261
+ },
5262
+ _functionStartsWith: function(resolvedArgs) {
5263
+ return resolvedArgs[0].lastIndexOf(resolvedArgs[1]) === 0;
5264
+ },
5265
+ _functionEndsWith: function(resolvedArgs) {
5266
+ var searchStr = resolvedArgs[0];
5267
+ var suffix = resolvedArgs[1];
5268
+ return searchStr.indexOf(suffix, searchStr.length - suffix.length) !== -1;
5269
+ },
5270
+ _functionReverse: function(resolvedArgs) {
5271
+ var typeName = this._getTypeName(resolvedArgs[0]);
5272
+ if (typeName === TYPE_STRING) {
5273
+ var originalStr = resolvedArgs[0];
5274
+ var reversedStr = "";
5275
+ for (var i = originalStr.length - 1;i >= 0; i--) {
5276
+ reversedStr += originalStr[i];
5806
5277
  }
5278
+ return reversedStr;
5279
+ } else {
5280
+ var reversedArray = resolvedArgs[0].slice(0);
5281
+ reversedArray.reverse();
5282
+ return reversedArray;
5807
5283
  }
5808
- return results;
5809
- }
5810
- case "Arithmetic": {
5811
- const first = this.visit(node.left, value);
5812
- const second = this.visit(node.right, value);
5813
- switch (node.operator) {
5814
- case "Plus":
5815
- return add(first, second);
5816
- case "Minus":
5817
- return sub(first, second);
5818
- case "Multiply":
5819
- case "Star":
5820
- return mul(first, second);
5821
- case "Divide":
5822
- return divide(first, second);
5823
- case "Modulo":
5824
- return mod(first, second);
5825
- case "Div":
5826
- return div(first, second);
5827
- default:
5828
- throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
5829
- }
5830
- }
5831
- case "Unary": {
5832
- const operand = this.visit(node.operand, value);
5833
- switch (node.operator) {
5834
- case "Plus":
5835
- ensureNumbers(operand);
5836
- return operand;
5837
- case "Minus":
5838
- ensureNumbers(operand);
5839
- return -operand;
5840
- default:
5841
- throw new Error(`Syntax error: unknown arithmetic operator: ${node.operator}`);
5284
+ },
5285
+ _functionAbs: function(resolvedArgs) {
5286
+ return Math.abs(resolvedArgs[0]);
5287
+ },
5288
+ _functionCeil: function(resolvedArgs) {
5289
+ return Math.ceil(resolvedArgs[0]);
5290
+ },
5291
+ _functionAvg: function(resolvedArgs) {
5292
+ var sum = 0;
5293
+ var inputArray = resolvedArgs[0];
5294
+ for (var i = 0;i < inputArray.length; i++) {
5295
+ sum += inputArray[i];
5842
5296
  }
5843
- }
5844
- case "Comparator": {
5845
- const first = this.visit(node.left, value);
5846
- const second = this.visit(node.right, value);
5847
- switch (node.name) {
5848
- case "EQ":
5849
- return strictDeepEqual(first, second);
5850
- case "NE":
5851
- return !strictDeepEqual(first, second);
5297
+ return sum / inputArray.length;
5298
+ },
5299
+ _functionContains: function(resolvedArgs) {
5300
+ return resolvedArgs[0].indexOf(resolvedArgs[1]) >= 0;
5301
+ },
5302
+ _functionFloor: function(resolvedArgs) {
5303
+ return Math.floor(resolvedArgs[0]);
5304
+ },
5305
+ _functionLength: function(resolvedArgs) {
5306
+ if (!isObject(resolvedArgs[0])) {
5307
+ return resolvedArgs[0].length;
5308
+ } else {
5309
+ return Object.keys(resolvedArgs[0]).length;
5310
+ }
5311
+ },
5312
+ _functionMap: function(resolvedArgs) {
5313
+ var mapped = [];
5314
+ var interpreter = this._interpreter;
5315
+ var exprefNode = resolvedArgs[0];
5316
+ var elements = resolvedArgs[1];
5317
+ for (var i = 0;i < elements.length; i++) {
5318
+ mapped.push(interpreter.visit(exprefNode, elements[i]));
5319
+ }
5320
+ return mapped;
5321
+ },
5322
+ _functionMerge: function(resolvedArgs) {
5323
+ var merged = {};
5324
+ for (var i = 0;i < resolvedArgs.length; i++) {
5325
+ var current = resolvedArgs[i];
5326
+ for (var key in current) {
5327
+ merged[key] = current[key];
5328
+ }
5852
5329
  }
5853
- if (typeof first !== "number" || typeof second !== "number") {
5330
+ return merged;
5331
+ },
5332
+ _functionMax: function(resolvedArgs) {
5333
+ if (resolvedArgs[0].length > 0) {
5334
+ var typeName = this._getTypeName(resolvedArgs[0][0]);
5335
+ if (typeName === TYPE_NUMBER) {
5336
+ return Math.max.apply(Math, resolvedArgs[0]);
5337
+ } else {
5338
+ var elements = resolvedArgs[0];
5339
+ var maxElement = elements[0];
5340
+ for (var i = 1;i < elements.length; i++) {
5341
+ if (maxElement.localeCompare(elements[i]) < 0) {
5342
+ maxElement = elements[i];
5343
+ }
5344
+ }
5345
+ return maxElement;
5346
+ }
5347
+ } else {
5854
5348
  return null;
5855
5349
  }
5856
- switch (node.name) {
5857
- case "GT":
5858
- return first > second;
5859
- case "GTE":
5860
- return first >= second;
5861
- case "LT":
5862
- return first < second;
5863
- case "LTE":
5864
- return first <= second;
5350
+ },
5351
+ _functionMin: function(resolvedArgs) {
5352
+ if (resolvedArgs[0].length > 0) {
5353
+ var typeName = this._getTypeName(resolvedArgs[0][0]);
5354
+ if (typeName === TYPE_NUMBER) {
5355
+ return Math.min.apply(Math, resolvedArgs[0]);
5356
+ } else {
5357
+ var elements = resolvedArgs[0];
5358
+ var minElement = elements[0];
5359
+ for (var i = 1;i < elements.length; i++) {
5360
+ if (elements[i].localeCompare(minElement) < 0) {
5361
+ minElement = elements[i];
5362
+ }
5363
+ }
5364
+ return minElement;
5365
+ }
5366
+ } else {
5367
+ return null;
5865
5368
  }
5866
- }
5867
- case "Flatten": {
5868
- const original = this.visit(node.child, value);
5869
- return Array.isArray(original) ? original.flat() : null;
5870
- }
5871
- case "Root":
5872
- return this._rootValue;
5873
- case "MultiSelectList": {
5874
- const collected = [];
5875
- for (const child of node.children) {
5876
- collected.push(this.visit(child, value));
5369
+ },
5370
+ _functionSum: function(resolvedArgs) {
5371
+ var sum = 0;
5372
+ var listToSum = resolvedArgs[0];
5373
+ for (var i = 0;i < listToSum.length; i++) {
5374
+ sum += listToSum[i];
5877
5375
  }
5878
- return collected;
5879
- }
5880
- case "MultiSelectHash": {
5881
- const collected = {};
5882
- for (const child of node.children) {
5883
- collected[child.name] = this.visit(child.value, value);
5376
+ return sum;
5377
+ },
5378
+ _functionType: function(resolvedArgs) {
5379
+ switch (this._getTypeName(resolvedArgs[0])) {
5380
+ case TYPE_NUMBER:
5381
+ return "number";
5382
+ case TYPE_STRING:
5383
+ return "string";
5384
+ case TYPE_ARRAY:
5385
+ return "array";
5386
+ case TYPE_OBJECT:
5387
+ return "object";
5388
+ case TYPE_BOOLEAN:
5389
+ return "boolean";
5390
+ case TYPE_EXPREF:
5391
+ return "expref";
5392
+ case TYPE_NULL:
5393
+ return "null";
5884
5394
  }
5885
- return collected;
5886
- }
5887
- case "OrExpression": {
5888
- const result = this.visit(node.left, value);
5889
- if (isFalse(result)) {
5890
- return this.visit(node.right, value);
5395
+ },
5396
+ _functionKeys: function(resolvedArgs) {
5397
+ return Object.keys(resolvedArgs[0]);
5398
+ },
5399
+ _functionValues: function(resolvedArgs) {
5400
+ var obj = resolvedArgs[0];
5401
+ var keys = Object.keys(obj);
5402
+ var values = [];
5403
+ for (var i = 0;i < keys.length; i++) {
5404
+ values.push(obj[keys[i]]);
5405
+ }
5406
+ return values;
5407
+ },
5408
+ _functionJoin: function(resolvedArgs) {
5409
+ var joinChar = resolvedArgs[0];
5410
+ var listJoin = resolvedArgs[1];
5411
+ return listJoin.join(joinChar);
5412
+ },
5413
+ _functionToArray: function(resolvedArgs) {
5414
+ if (this._getTypeName(resolvedArgs[0]) === TYPE_ARRAY) {
5415
+ return resolvedArgs[0];
5416
+ } else {
5417
+ return [resolvedArgs[0]];
5891
5418
  }
5892
- return result;
5893
- }
5894
- case "AndExpression": {
5895
- const result = this.visit(node.left, value);
5896
- if (isFalse(result)) {
5897
- return result;
5419
+ },
5420
+ _functionToString: function(resolvedArgs) {
5421
+ if (this._getTypeName(resolvedArgs[0]) === TYPE_STRING) {
5422
+ return resolvedArgs[0];
5423
+ } else {
5424
+ return JSON.stringify(resolvedArgs[0]);
5898
5425
  }
5899
- return this.visit(node.right, value);
5900
- }
5901
- case "NotExpression":
5902
- return isFalse(this.visit(node.child, value));
5903
- case "Literal":
5904
- return node.value;
5905
- case "Pipe":
5906
- return this.visit(node.right, this.visit(node.left, value));
5907
- case "Function": {
5908
- const args = [];
5909
- for (const child of node.children) {
5910
- args.push(this.visit(child, value));
5426
+ },
5427
+ _functionToNumber: function(resolvedArgs) {
5428
+ var typeName = this._getTypeName(resolvedArgs[0]);
5429
+ var convertedValue;
5430
+ if (typeName === TYPE_NUMBER) {
5431
+ return resolvedArgs[0];
5432
+ } else if (typeName === TYPE_STRING) {
5433
+ convertedValue = +resolvedArgs[0];
5434
+ if (!isNaN(convertedValue)) {
5435
+ return convertedValue;
5436
+ }
5911
5437
  }
5912
- return this.runtime.callFunction(node.name, args);
5913
- }
5914
- case "ExpressionReference":
5915
- return {
5916
- expref: true,
5917
- ...node.child
5438
+ return null;
5439
+ },
5440
+ _functionNotNull: function(resolvedArgs) {
5441
+ for (var i = 0;i < resolvedArgs.length; i++) {
5442
+ if (this._getTypeName(resolvedArgs[i]) !== TYPE_NULL) {
5443
+ return resolvedArgs[i];
5444
+ }
5445
+ }
5446
+ return null;
5447
+ },
5448
+ _functionSort: function(resolvedArgs) {
5449
+ var sortedArray = resolvedArgs[0].slice(0);
5450
+ sortedArray.sort();
5451
+ return sortedArray;
5452
+ },
5453
+ _functionSortBy: function(resolvedArgs) {
5454
+ var sortedArray = resolvedArgs[0].slice(0);
5455
+ if (sortedArray.length === 0) {
5456
+ return sortedArray;
5457
+ }
5458
+ var interpreter = this._interpreter;
5459
+ var exprefNode = resolvedArgs[1];
5460
+ var requiredType = this._getTypeName(interpreter.visit(exprefNode, sortedArray[0]));
5461
+ if ([TYPE_NUMBER, TYPE_STRING].indexOf(requiredType) < 0) {
5462
+ throw new Error("TypeError");
5463
+ }
5464
+ var that = this;
5465
+ var decorated = [];
5466
+ for (var i = 0;i < sortedArray.length; i++) {
5467
+ decorated.push([i, sortedArray[i]]);
5468
+ }
5469
+ decorated.sort(function(a, b) {
5470
+ var exprA = interpreter.visit(exprefNode, a[1]);
5471
+ var exprB = interpreter.visit(exprefNode, b[1]);
5472
+ if (that._getTypeName(exprA) !== requiredType) {
5473
+ throw new Error("TypeError: expected " + requiredType + ", received " + that._getTypeName(exprA));
5474
+ } else if (that._getTypeName(exprB) !== requiredType) {
5475
+ throw new Error("TypeError: expected " + requiredType + ", received " + that._getTypeName(exprB));
5476
+ }
5477
+ if (exprA > exprB) {
5478
+ return 1;
5479
+ } else if (exprA < exprB) {
5480
+ return -1;
5481
+ } else {
5482
+ return a[0] - b[0];
5483
+ }
5484
+ });
5485
+ for (var j = 0;j < decorated.length; j++) {
5486
+ sortedArray[j] = decorated[j][1];
5487
+ }
5488
+ return sortedArray;
5489
+ },
5490
+ _functionMaxBy: function(resolvedArgs) {
5491
+ var exprefNode = resolvedArgs[1];
5492
+ var resolvedArray = resolvedArgs[0];
5493
+ var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
5494
+ var maxNumber = -Infinity;
5495
+ var maxRecord;
5496
+ var current;
5497
+ for (var i = 0;i < resolvedArray.length; i++) {
5498
+ current = keyFunction(resolvedArray[i]);
5499
+ if (current > maxNumber) {
5500
+ maxNumber = current;
5501
+ maxRecord = resolvedArray[i];
5502
+ }
5503
+ }
5504
+ return maxRecord;
5505
+ },
5506
+ _functionMinBy: function(resolvedArgs) {
5507
+ var exprefNode = resolvedArgs[1];
5508
+ var resolvedArray = resolvedArgs[0];
5509
+ var keyFunction = this.createKeyFunction(exprefNode, [TYPE_NUMBER, TYPE_STRING]);
5510
+ var minNumber = Infinity;
5511
+ var minRecord;
5512
+ var current;
5513
+ for (var i = 0;i < resolvedArray.length; i++) {
5514
+ current = keyFunction(resolvedArray[i]);
5515
+ if (current < minNumber) {
5516
+ minNumber = current;
5517
+ minRecord = resolvedArray[i];
5518
+ }
5519
+ }
5520
+ return minRecord;
5521
+ },
5522
+ createKeyFunction: function(exprefNode, allowedTypes) {
5523
+ var that = this;
5524
+ var interpreter = this._interpreter;
5525
+ var keyFunc = function(x) {
5526
+ var current = interpreter.visit(exprefNode, x);
5527
+ if (allowedTypes.indexOf(that._getTypeName(current)) < 0) {
5528
+ var msg = "TypeError: expected one of " + allowedTypes + ", received " + that._getTypeName(current);
5529
+ throw new Error(msg);
5530
+ }
5531
+ return current;
5918
5532
  };
5919
- case "Current":
5920
- case "Identity":
5921
- return value;
5922
- }
5923
- }
5924
- computeSliceParams(arrayLength, sliceNode) {
5925
- let { start, stop, step } = sliceNode;
5926
- if (step === null) {
5927
- step = 1;
5928
- } else if (step === 0) {
5929
- const error = new Error("Invalid value: slice step cannot be 0");
5930
- error.name = "RuntimeError";
5931
- throw error;
5932
- }
5933
- start = start === null ? step < 0 ? arrayLength - 1 : 0 : this.capSliceRange(arrayLength, start, step);
5934
- stop = stop === null ? step < 0 ? -1 : arrayLength : this.capSliceRange(arrayLength, stop, step);
5935
- return { start, stop, step };
5936
- }
5937
- capSliceRange(arrayLength, actualValue, step) {
5938
- let nextActualValue = actualValue;
5939
- if (nextActualValue < 0) {
5940
- nextActualValue += arrayLength;
5941
- if (nextActualValue < 0) {
5942
- nextActualValue = step < 0 ? -1 : 0;
5943
- }
5944
- } else if (nextActualValue >= arrayLength) {
5945
- nextActualValue = step < 0 ? arrayLength - 1 : arrayLength;
5946
- }
5947
- return nextActualValue;
5948
- }
5949
- slice(collection, start, end, step) {
5950
- const result = [];
5951
- if (step > 0) {
5952
- for (let i = start;i < end; i += step) {
5953
- result.push(collection[i]);
5954
- }
5955
- } else {
5956
- for (let i = start;i > end; i += step) {
5957
- result.push(collection[i]);
5533
+ return keyFunc;
5958
5534
  }
5959
- }
5960
- return result;
5961
- }
5962
- }, TreeInterpreterInstance, TreeInterpreter_default, TYPE_ANY = 1, TYPE_ARRAY = 3, TYPE_ARRAY_ARRAY = 11, TYPE_ARRAY_NUMBER = 8, TYPE_ARRAY_OBJECT = 10, TYPE_ARRAY_STRING = 9, TYPE_BOOLEAN = 5, TYPE_EXPREF = 6, TYPE_NULL = 7, TYPE_NUMBER = 0, TYPE_OBJECT = 4, TYPE_STRING = 2, registerFunction = (functionName, customFunction, signature, options) => {
5963
- TreeInterpreter_default.runtime.registerFunction(functionName, customFunction, signature, options);
5964
- }, register = (name, customFunction, signature, options) => {
5965
- return TreeInterpreter_default.runtime.register(name, customFunction, signature, options);
5966
- }, unregisterFunction = (name) => {
5967
- return TreeInterpreter_default.runtime.unregister(name);
5968
- }, isRegistered = (name) => {
5969
- return TreeInterpreter_default.runtime.isRegistered(name);
5970
- }, getRegisteredFunctions = () => {
5971
- return TreeInterpreter_default.runtime.getRegistered();
5972
- }, getCustomFunctions = () => {
5973
- return TreeInterpreter_default.runtime.getCustomFunctions();
5974
- }, clearCustomFunctions = () => {
5975
- TreeInterpreter_default.runtime.clearCustomFunctions();
5976
- }, TreeInterpreter2, jmespath;
5977
- var init_dist = __esm(() => {
5978
- basicTokens = {
5979
- "(": "Lparen",
5980
- ")": "Rparen",
5981
- "*": "Star",
5982
- ",": "Comma",
5983
- ".": "Dot",
5984
- ":": "Colon",
5985
- "@": "Current",
5986
- "]": "Rbracket",
5987
- "{": "Lbrace",
5988
- "}": "Rbrace",
5989
- "+": "Plus",
5990
- "%": "Modulo",
5991
- "?": "Question",
5992
- "−": "Minus",
5993
- "×": "Multiply",
5994
- "÷": "Divide"
5995
- };
5996
- operatorStartToken = {
5997
- "!": true,
5998
- "<": true,
5999
- "=": true,
6000
- ">": true,
6001
- "&": true,
6002
- "|": true,
6003
- "/": true
6004
- };
6005
- skipChars = {
6006
- "\t": true,
6007
- "\n": true,
6008
- "\r": true,
6009
- " ": true
6010
- };
6011
- Lexer = new StreamLexer;
6012
- Lexer_default = Lexer;
6013
- bindingPower = {
6014
- ["EOF"]: 0,
6015
- ["Variable"]: 0,
6016
- ["UnquotedIdentifier"]: 0,
6017
- ["QuotedIdentifier"]: 0,
6018
- ["Rbracket"]: 0,
6019
- ["Rparen"]: 0,
6020
- ["Comma"]: 0,
6021
- ["Rbrace"]: 0,
6022
- ["Number"]: 0,
6023
- ["Current"]: 0,
6024
- ["Expref"]: 0,
6025
- ["Root"]: 0,
6026
- ["Assign"]: 1,
6027
- ["Pipe"]: 1,
6028
- ["Question"]: 2,
6029
- ["Or"]: 3,
6030
- ["And"]: 4,
6031
- ["EQ"]: 5,
6032
- ["GT"]: 5,
6033
- ["LT"]: 5,
6034
- ["GTE"]: 5,
6035
- ["LTE"]: 5,
6036
- ["NE"]: 5,
6037
- ["Minus"]: 6,
6038
- ["Plus"]: 6,
6039
- ["Div"]: 7,
6040
- ["Divide"]: 7,
6041
- ["Modulo"]: 7,
6042
- ["Multiply"]: 7,
6043
- ["Flatten"]: 9,
6044
- ["Star"]: 20,
6045
- ["Filter"]: 21,
6046
- ["Dot"]: 40,
6047
- ["Not"]: 45,
6048
- ["Lbrace"]: 50,
6049
- ["Lbracket"]: 55,
6050
- ["Lparen"]: 60
6051
- };
6052
- Parser = new TokenParser;
6053
- Parser_default = Parser;
6054
- emptyScopeChain = new ScopeChain;
6055
- TreeInterpreterInstance = new TreeInterpreter;
6056
- TreeInterpreter_default = TreeInterpreterInstance;
6057
- TreeInterpreter2 = TreeInterpreter_default;
6058
- jmespath = {
6059
- compile,
6060
- registerFunction,
6061
- register,
6062
- unregisterFunction,
6063
- isRegistered,
6064
- getRegisteredFunctions,
6065
- getCustomFunctions,
6066
- clearCustomFunctions,
6067
- search,
6068
- tokenize,
6069
- TreeInterpreter: TreeInterpreter2,
6070
- TYPE_ANY,
6071
- TYPE_ARRAY_NUMBER,
6072
- TYPE_ARRAY_STRING,
6073
- TYPE_ARRAY,
6074
- TYPE_BOOLEAN,
6075
- TYPE_EXPREF,
6076
- TYPE_NULL,
6077
- TYPE_NUMBER,
6078
- TYPE_OBJECT,
6079
- TYPE_STRING
6080
- };
5535
+ };
5536
+ function compile(stream) {
5537
+ var parser = new Parser;
5538
+ var ast = parser.parse(stream);
5539
+ return ast;
5540
+ }
5541
+ function tokenize(stream) {
5542
+ var lexer = new Lexer;
5543
+ return lexer.tokenize(stream);
5544
+ }
5545
+ function search(data, expression) {
5546
+ var parser = new Parser;
5547
+ var runtime = new Runtime;
5548
+ var interpreter = new TreeInterpreter(runtime);
5549
+ runtime._interpreter = interpreter;
5550
+ var node = parser.parse(expression);
5551
+ return interpreter.search(node, data);
5552
+ }
5553
+ exports2.tokenize = tokenize;
5554
+ exports2.compile = compile;
5555
+ exports2.search = search;
5556
+ exports2.strictDeepEqual = strictDeepEqual;
5557
+ })(typeof exports === "undefined" ? exports.jmespath = {} : exports);
6081
5558
  });
6082
5559
 
6083
5560
  // ../../node_modules/commander/lib/error.js
@@ -6406,10 +5883,10 @@ var require_help = __commonJS(function(exports) {
6406
5883
  });
6407
5884
  output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
6408
5885
  }
6409
- const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub2) => sub2.helpGroup() || "Commands:");
5886
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
6410
5887
  commandGroups.forEach((commands, group) => {
6411
- const commandList = commands.map((sub2) => {
6412
- return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub2)), helper.styleSubcommandDescription(helper.subcommandDescription(sub2)));
5888
+ const commandList = commands.map((sub) => {
5889
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
6413
5890
  });
6414
5891
  output = output.concat(this.formatItemList(group, commandList, helper));
6415
5892
  });
@@ -9527,20 +9004,20 @@ var require_tslib = __commonJS(function(exports, module) {
9527
9004
  }
9528
9005
  return cooked;
9529
9006
  };
9530
- __importStar = function(mod2) {
9531
- if (mod2 && mod2.__esModule)
9532
- return mod2;
9007
+ __importStar = function(mod) {
9008
+ if (mod && mod.__esModule)
9009
+ return mod;
9533
9010
  var result = {};
9534
- if (mod2 != null) {
9535
- for (var k in mod2)
9536
- if (Object.hasOwnProperty.call(mod2, k))
9537
- result[k] = mod2[k];
9011
+ if (mod != null) {
9012
+ for (var k in mod)
9013
+ if (Object.hasOwnProperty.call(mod, k))
9014
+ result[k] = mod[k];
9538
9015
  }
9539
- result["default"] = mod2;
9016
+ result["default"] = mod;
9540
9017
  return result;
9541
9018
  };
9542
- __importDefault = function(mod2) {
9543
- return mod2 && mod2.__esModule ? mod2 : { default: mod2 };
9019
+ __importDefault = function(mod) {
9020
+ return mod && mod.__esModule ? mod : { default: mod };
9544
9021
  };
9545
9022
  __classPrivateFieldGet = function(receiver, privateMap) {
9546
9023
  if (!privateMap.has(receiver)) {
@@ -13029,13 +12506,13 @@ var jmespathSlot = singleton("JmespathCodec");
13029
12506
  async function loadOutputCodecsAsync(needed) {
13030
12507
  const loads = [];
13031
12508
  if (needed.yaml && yamlSlot.get() === undefined) {
13032
- loads.push(Promise.resolve().then(() => (init_js_yaml(), exports_js_yaml)).then((mod2) => {
13033
- yamlSlot.set(mod2);
12509
+ loads.push(Promise.resolve().then(() => (init_js_yaml(), exports_js_yaml)).then((mod) => {
12510
+ yamlSlot.set(mod);
13034
12511
  }));
13035
12512
  }
13036
12513
  if (needed.filter && jmespathSlot.get() === undefined) {
13037
- loads.push(Promise.resolve().then(() => (init_dist(), exports_dist)).then((mod2) => {
13038
- jmespathSlot.set(mod2);
12514
+ loads.push(Promise.resolve().then(() => __toESM(require_jmespath(), 1)).then((mod) => {
12515
+ jmespathSlot.set(mod);
13039
12516
  }));
13040
12517
  }
13041
12518
  await Promise.all(loads);
@@ -13792,8 +13269,8 @@ class TelemetryService {
13792
13269
  // ../common/src/timings.ts
13793
13270
  var TIMINGS_ENV_VAR = "UIP_TIMINGS";
13794
13271
  function createStorage2() {
13795
- const [error, mod2] = catchError2(() => __require("node:async_hooks"));
13796
- if (error || typeof mod2?.AsyncLocalStorage !== "function") {
13272
+ const [error, mod] = catchError2(() => __require("node:async_hooks"));
13273
+ if (error || typeof mod?.AsyncLocalStorage !== "function") {
13797
13274
  return {
13798
13275
  getStore: () => {
13799
13276
  return;
@@ -13801,7 +13278,7 @@ function createStorage2() {
13801
13278
  run: (_store, fn) => fn()
13802
13279
  };
13803
13280
  }
13804
- return new mod2.AsyncLocalStorage;
13281
+ return new mod.AsyncLocalStorage;
13805
13282
  }
13806
13283
  var storageSlot = singleton("TimingStorage");
13807
13284
  var stateSlot = singleton("Timings");
@@ -21621,9 +21098,9 @@ class GetResourceConfigurationsComparisonRequestHandler {
21621
21098
  for (const key of request.resourceKeys) {
21622
21099
  if (!key || !key.trim())
21623
21100
  continue;
21624
- const lower2 = key.toLowerCase();
21625
- if (!seen.has(lower2)) {
21626
- seen.add(lower2);
21101
+ const lower = key.toLowerCase();
21102
+ if (!seen.has(lower)) {
21103
+ seen.add(lower);
21627
21104
  distinctKeys.push(key);
21628
21105
  }
21629
21106
  }
@@ -28165,9 +27642,9 @@ class BindingsMetadataSerializer {
28165
27642
  }
28166
27643
  }
28167
27644
  getResourceType(resourceType) {
28168
- const lower2 = resourceType.toLowerCase();
27645
+ const lower = resourceType.toLowerCase();
28169
27646
  for (const [key, value] of Object.entries(models_BindingsResourceType))
28170
- if (typeof value == "number" && key.toLowerCase() === lower2)
27647
+ if (typeof value == "number" && key.toLowerCase() === lower)
28171
27648
  return value;
28172
27649
  return models_BindingsResourceType.Unknown;
28173
27650
  }
@@ -30820,7 +30297,7 @@ class VoidApiResponse {
30820
30297
  // ../orchestrator-sdk/package.json
30821
30298
  var package_default = {
30822
30299
  name: "@uipath/orchestrator-sdk",
30823
- license: "MIT",
30300
+ license: "SEE LICENSE IN LICENSE.txt",
30824
30301
  version: "1.202.0",
30825
30302
  repository: {
30826
30303
  type: "git",
@@ -33125,10 +32602,10 @@ async function createLocalResource(params) {
33125
32602
  return { resource: minted.resource, finalName: minted.finalName };
33126
32603
  }
33127
32604
  function mapUipxTypeToReconcileType(uipxType) {
33128
- const lower2 = uipxType.toLowerCase();
33129
- if (lower2 === "apiautomation")
32605
+ const lower = uipxType.toLowerCase();
32606
+ if (lower === "apiautomation")
33130
32607
  return "Api";
33131
- if (lower2 === "businessrules" || lower2 === "library" || lower2 === "tests") {
32608
+ if (lower === "businessrules" || lower === "library" || lower === "tests") {
33132
32609
  return null;
33133
32610
  }
33134
32611
  return uipxType;
@@ -33392,4 +32869,4 @@ export {
33392
32869
  writeSolutionFile
33393
32870
  };
33394
32871
 
33395
- //# debugId=E988507D1077967864756E2164756E21
32872
+ //# debugId=54112CF1CFC8876064756E2164756E21