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