@libdbm/libcel-ts 1.0.2-rc.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +342 -31
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1072 -118
- package/dist/index.mjs +2723 -681
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
class
|
|
2
|
-
constructor(t,
|
|
3
|
-
super(`${t} at ${
|
|
1
|
+
class U extends Error {
|
|
2
|
+
constructor(t, n, i) {
|
|
3
|
+
super(`${t} at ${n}:${i}`), this.line = n, this.column = i, this.name = "ParseError";
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
var
|
|
7
|
-
class
|
|
8
|
-
constructor(t,
|
|
9
|
-
this.type = t, this.value =
|
|
6
|
+
var o = /* @__PURE__ */ ((e) => (e.NULL = "NULL", e.TRUE = "TRUE", e.FALSE = "FALSE", e.INT = "INT", e.UINT = "UINT", e.DOUBLE = "DOUBLE", e.STRING = "STRING", e.BYTES = "BYTES", e.IDENTIFIER = "IDENTIFIER", e.PLUS = "PLUS", e.MINUS = "MINUS", e.STAR = "STAR", e.SLASH = "SLASH", e.PERCENT = "PERCENT", e.EQ = "EQ", e.NE = "NE", e.LT = "LT", e.LE = "LE", e.GT = "GT", e.GE = "GE", e.LOGICAL_AND = "LOGICAL_AND", e.LOGICAL_OR = "LOGICAL_OR", e.BANG = "BANG", e.IN = "IN", e.LPAREN = "LPAREN", e.RPAREN = "RPAREN", e.LBRACKET = "LBRACKET", e.RBRACKET = "RBRACKET", e.LBRACE = "LBRACE", e.RBRACE = "RBRACE", e.DOT = "DOT", e.COMMA = "COMMA", e.COLON = "COLON", e.QUESTION = "QUESTION", e.EOF = "EOF", e))(o || {});
|
|
7
|
+
class w {
|
|
8
|
+
constructor(t, n, i, r) {
|
|
9
|
+
this.type = t, this.value = n, this.line = i, this.column = r;
|
|
10
10
|
}
|
|
11
11
|
toString() {
|
|
12
12
|
return `${this.type}(${this.value})`;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
class
|
|
15
|
+
class de {
|
|
16
16
|
constructor(t) {
|
|
17
17
|
this.input = t, this.position = 0, this.line = 1, this.column = 1, this.lookahead = [];
|
|
18
18
|
}
|
|
@@ -39,139 +39,139 @@ class F {
|
|
|
39
39
|
` ? (this.line++, this.column = 1) : this.column++;
|
|
40
40
|
}
|
|
41
41
|
forward(t) {
|
|
42
|
-
for (let
|
|
42
|
+
for (let n = 0; n < t; n++)
|
|
43
43
|
this.step();
|
|
44
44
|
}
|
|
45
45
|
token() {
|
|
46
46
|
if (this.whitespace(), this.position >= this.input.length)
|
|
47
|
-
return new
|
|
48
|
-
const t = this.position,
|
|
49
|
-
switch (
|
|
47
|
+
return new w("EOF", "", this.line, this.column);
|
|
48
|
+
const t = this.position, n = this.line, i = this.column, r = this.input[this.position];
|
|
49
|
+
switch (r) {
|
|
50
50
|
case "(":
|
|
51
|
-
return this.step(), new
|
|
51
|
+
return this.step(), new w("LPAREN", "(", n, i);
|
|
52
52
|
case ")":
|
|
53
|
-
return this.step(), new
|
|
53
|
+
return this.step(), new w("RPAREN", ")", n, i);
|
|
54
54
|
case "[":
|
|
55
|
-
return this.step(), new
|
|
55
|
+
return this.step(), new w("LBRACKET", "[", n, i);
|
|
56
56
|
case "]":
|
|
57
|
-
return this.step(), new
|
|
57
|
+
return this.step(), new w("RBRACKET", "]", n, i);
|
|
58
58
|
case "{":
|
|
59
|
-
return this.step(), new
|
|
59
|
+
return this.step(), new w("LBRACE", "{", n, i);
|
|
60
60
|
case "}":
|
|
61
|
-
return this.step(), new
|
|
61
|
+
return this.step(), new w("RBRACE", "}", n, i);
|
|
62
62
|
case ",":
|
|
63
|
-
return this.step(), new
|
|
63
|
+
return this.step(), new w("COMMA", ",", n, i);
|
|
64
64
|
case ".":
|
|
65
|
-
return this.step(), new
|
|
65
|
+
return this.step(), new w("DOT", ".", n, i);
|
|
66
66
|
case ":":
|
|
67
|
-
return this.step(), new
|
|
67
|
+
return this.step(), new w("COLON", ":", n, i);
|
|
68
68
|
case "?":
|
|
69
|
-
return this.step(), new
|
|
69
|
+
return this.step(), new w("QUESTION", "?", n, i);
|
|
70
70
|
case "+":
|
|
71
|
-
return this.step(), new
|
|
71
|
+
return this.step(), new w("PLUS", "+", n, i);
|
|
72
72
|
case "*":
|
|
73
|
-
return this.step(), new
|
|
73
|
+
return this.step(), new w("STAR", "*", n, i);
|
|
74
74
|
case "/":
|
|
75
|
-
return this.step(), new
|
|
75
|
+
return this.step(), new w("SLASH", "/", n, i);
|
|
76
76
|
case "%":
|
|
77
|
-
return this.step(), new
|
|
78
|
-
}
|
|
79
|
-
if (
|
|
80
|
-
return this.forward(2), new
|
|
81
|
-
if (
|
|
82
|
-
return this.forward(2), new
|
|
83
|
-
if (
|
|
84
|
-
return this.forward(2), new
|
|
85
|
-
if (
|
|
86
|
-
return this.forward(2), new
|
|
87
|
-
if (
|
|
88
|
-
return this.forward(2), new
|
|
89
|
-
if (
|
|
90
|
-
return this.forward(2), new
|
|
91
|
-
if (
|
|
92
|
-
return this.step(), new
|
|
93
|
-
if (
|
|
94
|
-
return this.step(), new
|
|
95
|
-
if (
|
|
96
|
-
return this.step(), new
|
|
97
|
-
if (
|
|
98
|
-
return this.step(), new
|
|
99
|
-
if (
|
|
100
|
-
return this.string(
|
|
101
|
-
if ((
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
return this.string(
|
|
105
|
-
}
|
|
106
|
-
if ((
|
|
107
|
-
const
|
|
108
|
-
if (
|
|
109
|
-
return this.bytes(
|
|
110
|
-
}
|
|
111
|
-
if (this.isDigit(
|
|
112
|
-
return this.number(
|
|
113
|
-
if (this.isLetter(
|
|
114
|
-
return this.identifier(
|
|
115
|
-
throw new
|
|
116
|
-
}
|
|
117
|
-
string(t,
|
|
118
|
-
let
|
|
119
|
-
if ((this.input[this.position] === "r" || this.input[this.position] === "R") && (
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
77
|
+
return this.step(), new w("PERCENT", "%", n, i);
|
|
78
|
+
}
|
|
79
|
+
if (r === "&" && this.peekChar() === "&")
|
|
80
|
+
return this.forward(2), new w("LOGICAL_AND", "&&", n, i);
|
|
81
|
+
if (r === "|" && this.peekChar() === "|")
|
|
82
|
+
return this.forward(2), new w("LOGICAL_OR", "||", n, i);
|
|
83
|
+
if (r === "=" && this.peekChar() === "=")
|
|
84
|
+
return this.forward(2), new w("EQ", "==", n, i);
|
|
85
|
+
if (r === "!" && this.peekChar() === "=")
|
|
86
|
+
return this.forward(2), new w("NE", "!=", n, i);
|
|
87
|
+
if (r === "<" && this.peekChar() === "=")
|
|
88
|
+
return this.forward(2), new w("LE", "<=", n, i);
|
|
89
|
+
if (r === ">" && this.peekChar() === "=")
|
|
90
|
+
return this.forward(2), new w("GE", ">=", n, i);
|
|
91
|
+
if (r === "<")
|
|
92
|
+
return this.step(), new w("LT", "<", n, i);
|
|
93
|
+
if (r === ">")
|
|
94
|
+
return this.step(), new w("GT", ">", n, i);
|
|
95
|
+
if (r === "!")
|
|
96
|
+
return this.step(), new w("BANG", "!", n, i);
|
|
97
|
+
if (r === "-")
|
|
98
|
+
return this.step(), new w("MINUS", "-", n, i);
|
|
99
|
+
if (r === '"' || r === "'")
|
|
100
|
+
return this.string(n, i, t);
|
|
101
|
+
if ((r === "r" || r === "R") && this.position + 1 < this.input.length) {
|
|
102
|
+
const s = this.input[this.position + 1];
|
|
103
|
+
if (s === '"' || s === "'")
|
|
104
|
+
return this.string(n, i, t);
|
|
105
|
+
}
|
|
106
|
+
if ((r === "b" || r === "B") && this.position + 1 < this.input.length) {
|
|
107
|
+
const s = this.input[this.position + 1];
|
|
108
|
+
if (s === '"' || s === "'")
|
|
109
|
+
return this.bytes(n, i, t);
|
|
110
|
+
}
|
|
111
|
+
if (this.isDigit(r))
|
|
112
|
+
return this.number(n, i, t);
|
|
113
|
+
if (this.isLetter(r) || r === "_")
|
|
114
|
+
return this.identifier(n, i, t);
|
|
115
|
+
throw new U(`Unexpected character: ${r}`, n, i);
|
|
116
|
+
}
|
|
117
|
+
string(t, n, i) {
|
|
118
|
+
let r = !1;
|
|
119
|
+
if ((this.input[this.position] === "r" || this.input[this.position] === "R") && (r = !0, this.step()), this.position + 2 < this.input.length) {
|
|
120
|
+
const c = this.input.substring(this.position, this.position + 3);
|
|
121
|
+
if (c === '"""' || c === "'''") {
|
|
122
122
|
const u = this.input[this.position];
|
|
123
123
|
for (this.forward(3); this.position + 2 < this.input.length; ) {
|
|
124
124
|
if (this.input[this.position] === u && this.input[this.position + 1] === u && this.input[this.position + 2] === u)
|
|
125
|
-
return this.forward(3), new
|
|
125
|
+
return this.forward(3), new w("STRING", this.input.substring(i, this.position), t, n);
|
|
126
126
|
this.step();
|
|
127
127
|
}
|
|
128
|
-
throw new
|
|
128
|
+
throw new U("Unterminated triple-quoted string", t, n);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
const
|
|
131
|
+
const s = this.input[this.position];
|
|
132
132
|
for (this.step(); this.position < this.input.length; ) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
return this.step(), new
|
|
136
|
-
|
|
133
|
+
const c = this.input[this.position];
|
|
134
|
+
if (c === s)
|
|
135
|
+
return this.step(), new w("STRING", this.input.substring(i, this.position), t, n);
|
|
136
|
+
c === "\\" && !r && this.position + 1 < this.input.length ? this.forward(2) : this.step();
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new U("Unterminated string", t, n);
|
|
139
139
|
}
|
|
140
|
-
bytes(t,
|
|
140
|
+
bytes(t, n, i) {
|
|
141
141
|
this.step();
|
|
142
|
-
const
|
|
142
|
+
const r = this.input[this.position];
|
|
143
143
|
for (this.step(); this.position < this.input.length; ) {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
return this.step(), new
|
|
147
|
-
|
|
144
|
+
const s = this.input[this.position];
|
|
145
|
+
if (s === r)
|
|
146
|
+
return this.step(), new w("BYTES", this.input.substring(i, this.position), t, n);
|
|
147
|
+
s === "\\" && this.position + 1 < this.input.length ? this.forward(2) : this.step();
|
|
148
148
|
}
|
|
149
|
-
throw new
|
|
149
|
+
throw new U("Unterminated bytes literal", t, n);
|
|
150
150
|
}
|
|
151
|
-
number(t,
|
|
151
|
+
number(t, n, i) {
|
|
152
152
|
if (this.input[this.position] === "0" && this.position + 1 < this.input.length) {
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
153
|
+
const c = this.input[this.position + 1];
|
|
154
|
+
if (c === "x" || c === "X") {
|
|
155
155
|
for (this.forward(2); this.position < this.input.length && this.isHexDigit(this.input[this.position]); )
|
|
156
156
|
this.step();
|
|
157
157
|
if (this.position < this.input.length) {
|
|
158
158
|
const u = this.input[this.position];
|
|
159
159
|
if (u === "u" || u === "U")
|
|
160
|
-
return this.step(), new
|
|
160
|
+
return this.step(), new w("UINT", this.input.substring(i, this.position), t, n);
|
|
161
161
|
}
|
|
162
|
-
return new
|
|
162
|
+
return new w("INT", this.input.substring(i, this.position), t, n);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
for (; this.position < this.input.length && this.isDigit(this.input[this.position]); )
|
|
166
166
|
this.step();
|
|
167
|
-
let
|
|
167
|
+
let r = !1;
|
|
168
168
|
if (this.position < this.input.length && this.input[this.position] === ".")
|
|
169
|
-
for (
|
|
169
|
+
for (r = !0, this.step(); this.position < this.input.length && this.isDigit(this.input[this.position]); )
|
|
170
170
|
this.step();
|
|
171
171
|
if (this.position < this.input.length) {
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
if (
|
|
172
|
+
const c = this.input[this.position];
|
|
173
|
+
if (c === "e" || c === "E") {
|
|
174
|
+
if (r = !0, this.step(), this.position < this.input.length) {
|
|
175
175
|
const u = this.input[this.position];
|
|
176
176
|
(u === "+" || u === "-") && this.step();
|
|
177
177
|
}
|
|
@@ -179,23 +179,23 @@ class F {
|
|
|
179
179
|
this.step();
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
if (!
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
return this.step(), new
|
|
182
|
+
if (!r && this.position < this.input.length) {
|
|
183
|
+
const c = this.input[this.position];
|
|
184
|
+
if (c === "u" || c === "U")
|
|
185
|
+
return this.step(), new w("UINT", this.input.substring(i, this.position), t, n);
|
|
186
186
|
}
|
|
187
|
-
const
|
|
188
|
-
return new
|
|
187
|
+
const s = r ? "DOUBLE" : "INT";
|
|
188
|
+
return new w(s, this.input.substring(i, this.position), t, n);
|
|
189
189
|
}
|
|
190
|
-
identifier(t,
|
|
190
|
+
identifier(t, n, i) {
|
|
191
191
|
for (; this.position < this.input.length; ) {
|
|
192
|
-
const
|
|
193
|
-
if (!this.isLetterOrDigit(
|
|
192
|
+
const c = this.input[this.position];
|
|
193
|
+
if (!this.isLetterOrDigit(c) && c !== "_")
|
|
194
194
|
break;
|
|
195
195
|
this.step();
|
|
196
196
|
}
|
|
197
|
-
const
|
|
198
|
-
return new
|
|
197
|
+
const r = this.input.substring(i, this.position), s = this.typeOf(r);
|
|
198
|
+
return new w(s, r, t, n);
|
|
199
199
|
}
|
|
200
200
|
typeOf(t) {
|
|
201
201
|
switch (t) {
|
|
@@ -237,16 +237,16 @@ class F {
|
|
|
237
237
|
return this.isLetter(t) || this.isDigit(t);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
var
|
|
241
|
-
class
|
|
242
|
-
constructor(t,
|
|
243
|
-
this.value = t, this.literalType =
|
|
240
|
+
var h = /* @__PURE__ */ ((e) => (e.ADD = "ADD", e.SUBTRACT = "SUBTRACT", e.MULTIPLY = "MULTIPLY", e.DIVIDE = "DIVIDE", e.MODULO = "MODULO", e.EQUAL = "EQUAL", e.NOT_EQUAL = "NOT_EQUAL", e.LESS = "LESS", e.LESS_EQUAL = "LESS_EQUAL", e.GREATER = "GREATER", e.GREATER_EQUAL = "GREATER_EQUAL", e.IN = "IN", e.LOGICAL_AND = "LOGICAL_AND", e.LOGICAL_OR = "LOGICAL_OR", e))(h || {}), J = /* @__PURE__ */ ((e) => (e.NOT = "NOT", e.NEGATE = "NEGATE", e))(J || {}), $ = /* @__PURE__ */ ((e) => (e.NULL_VALUE = "NULL_VALUE", e.BOOL = "BOOL", e.INT = "INT", e.UINT = "UINT", e.DOUBLE = "DOUBLE", e.STRING = "STRING", e.BYTES = "BYTES", e))($ || {});
|
|
241
|
+
class z {
|
|
242
|
+
constructor(t, n) {
|
|
243
|
+
this.value = t, this.literalType = n;
|
|
244
244
|
}
|
|
245
245
|
accept(t) {
|
|
246
246
|
return t.visitLiteral(this);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
class
|
|
249
|
+
class It {
|
|
250
250
|
constructor(t) {
|
|
251
251
|
this.name = t;
|
|
252
252
|
}
|
|
@@ -254,31 +254,31 @@ class U {
|
|
|
254
254
|
return t.visitIdentifier(this);
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
class
|
|
258
|
-
constructor(t,
|
|
259
|
-
this.operand = t, this.field =
|
|
257
|
+
class nt {
|
|
258
|
+
constructor(t, n, i = !1) {
|
|
259
|
+
this.operand = t, this.field = n, this.isTest = i;
|
|
260
260
|
}
|
|
261
261
|
accept(t) {
|
|
262
262
|
return t.visitSelect(this);
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
class
|
|
266
|
-
constructor(t,
|
|
267
|
-
this.operand = t, this.index =
|
|
265
|
+
class we {
|
|
266
|
+
constructor(t, n) {
|
|
267
|
+
this.operand = t, this.index = n;
|
|
268
268
|
}
|
|
269
269
|
accept(t) {
|
|
270
270
|
return t.visitIndex(this);
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
|
-
class
|
|
274
|
-
constructor(t,
|
|
275
|
-
this.target = t, this.functionName =
|
|
273
|
+
class gt {
|
|
274
|
+
constructor(t, n, i, r = !1) {
|
|
275
|
+
this.target = t, this.functionName = n, this.args = i, this.isMacro = r;
|
|
276
276
|
}
|
|
277
277
|
accept(t) {
|
|
278
278
|
return t.visitCall(this);
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
class
|
|
281
|
+
class ge {
|
|
282
282
|
constructor(t) {
|
|
283
283
|
this.elements = t;
|
|
284
284
|
}
|
|
@@ -286,12 +286,12 @@ class q {
|
|
|
286
286
|
return t.visitList(this);
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
class
|
|
290
|
-
constructor(t,
|
|
291
|
-
this.key = t, this.value =
|
|
289
|
+
class be {
|
|
290
|
+
constructor(t, n) {
|
|
291
|
+
this.key = t, this.value = n;
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
class
|
|
294
|
+
class jt {
|
|
295
295
|
constructor(t) {
|
|
296
296
|
this.entries = t;
|
|
297
297
|
}
|
|
@@ -299,55 +299,168 @@ class C {
|
|
|
299
299
|
return t.visitMap(this);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
|
-
class
|
|
303
|
-
constructor(t,
|
|
304
|
-
this.field = t, this.value =
|
|
302
|
+
class me {
|
|
303
|
+
constructor(t, n) {
|
|
304
|
+
this.field = t, this.value = n;
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
class
|
|
308
|
-
constructor(t,
|
|
309
|
-
this.typeName = t, this.fields =
|
|
307
|
+
class Qt {
|
|
308
|
+
constructor(t, n) {
|
|
309
|
+
this.typeName = t, this.fields = n;
|
|
310
310
|
}
|
|
311
311
|
accept(t) {
|
|
312
312
|
return t.visitStruct(this);
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
|
-
class
|
|
316
|
-
constructor(t,
|
|
317
|
-
this.variable = t, this.range =
|
|
315
|
+
class hi {
|
|
316
|
+
constructor(t, n, i, r, s, c, u) {
|
|
317
|
+
this.variable = t, this.range = n, this.accumulator = i, this.initializer = r, this.condition = s, this.step = c, this.result = u;
|
|
318
318
|
}
|
|
319
319
|
accept(t) {
|
|
320
320
|
return t.visitComprehension(this);
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
class
|
|
324
|
-
constructor(t,
|
|
325
|
-
this.op = t, this.operand =
|
|
323
|
+
class At {
|
|
324
|
+
constructor(t, n) {
|
|
325
|
+
this.op = t, this.operand = n;
|
|
326
326
|
}
|
|
327
327
|
accept(t) {
|
|
328
328
|
return t.visitUnary(this);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
|
-
class
|
|
332
|
-
constructor(t,
|
|
333
|
-
this.op = t, this.left =
|
|
331
|
+
class X {
|
|
332
|
+
constructor(t, n, i) {
|
|
333
|
+
this.op = t, this.left = n, this.right = i;
|
|
334
334
|
}
|
|
335
335
|
accept(t) {
|
|
336
336
|
return t.visitBinary(this);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
class
|
|
340
|
-
constructor(t,
|
|
341
|
-
this.condition = t, this.thenExpr =
|
|
339
|
+
class nn {
|
|
340
|
+
constructor(t, n, i) {
|
|
341
|
+
this.condition = t, this.thenExpr = n, this.otherwiseExpr = i;
|
|
342
342
|
}
|
|
343
343
|
accept(t) {
|
|
344
344
|
return t.visitConditional(this);
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
const
|
|
348
|
-
|
|
347
|
+
const Ee = new TextEncoder(), Ie = new TextDecoder("utf-8");
|
|
348
|
+
function B(e) {
|
|
349
|
+
return e instanceof Uint8Array;
|
|
350
|
+
}
|
|
351
|
+
function Mt(e) {
|
|
352
|
+
return Ee.encode(e);
|
|
353
|
+
}
|
|
354
|
+
function en(e) {
|
|
355
|
+
return Ie.decode(e);
|
|
356
|
+
}
|
|
357
|
+
function Ae(e, t) {
|
|
358
|
+
if (e.length !== t.length)
|
|
359
|
+
return !1;
|
|
360
|
+
for (let n = 0; n < e.length; n++)
|
|
361
|
+
if (e[n] !== t[n])
|
|
362
|
+
return !1;
|
|
363
|
+
return !0;
|
|
364
|
+
}
|
|
365
|
+
function ye(e, t) {
|
|
366
|
+
const n = Math.min(e.length, t.length);
|
|
367
|
+
for (let i = 0; i < n; i++) {
|
|
368
|
+
const r = e[i] << 24 >> 24, s = t[i] << 24 >> 24;
|
|
369
|
+
if (r !== s)
|
|
370
|
+
return r < s ? -1 : 1;
|
|
371
|
+
}
|
|
372
|
+
return e.length - t.length;
|
|
373
|
+
}
|
|
374
|
+
function Ne(e, t) {
|
|
375
|
+
const n = new Uint8Array(e.length + t.length);
|
|
376
|
+
return n.set(e, 0), n.set(t, e.length), n;
|
|
377
|
+
}
|
|
378
|
+
function yt(e) {
|
|
379
|
+
let t = "";
|
|
380
|
+
for (const n of e)
|
|
381
|
+
t += n.toString(16).padStart(2, "0");
|
|
382
|
+
return t;
|
|
383
|
+
}
|
|
384
|
+
class l extends Error {
|
|
385
|
+
constructor(t) {
|
|
386
|
+
super(t), this.name = "EvaluationError";
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
class a extends Error {
|
|
390
|
+
constructor(t) {
|
|
391
|
+
super(t), this.name = "ArgumentError";
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function zt(e) {
|
|
395
|
+
return e instanceof l || e instanceof a;
|
|
396
|
+
}
|
|
397
|
+
const K = -(2n ** 63n), at = 2n ** 63n - 1n;
|
|
398
|
+
function fi(e) {
|
|
399
|
+
return typeof e == "bigint";
|
|
400
|
+
}
|
|
401
|
+
function li(e) {
|
|
402
|
+
return typeof e == "number";
|
|
403
|
+
}
|
|
404
|
+
function C(e) {
|
|
405
|
+
return typeof e == "bigint" || typeof e == "number";
|
|
406
|
+
}
|
|
407
|
+
function Le(e) {
|
|
408
|
+
if (e < K || e > at)
|
|
409
|
+
throw new l("Integer overflow");
|
|
410
|
+
return e;
|
|
411
|
+
}
|
|
412
|
+
function Se(e) {
|
|
413
|
+
return Number.isNaN(e) ? 0n : e >= 2 ** 63 ? at : e <= -9223372036854776e3 ? K : BigInt(Math.trunc(e));
|
|
414
|
+
}
|
|
415
|
+
function Yt(e) {
|
|
416
|
+
return e === 0 ? 0 : e;
|
|
417
|
+
}
|
|
418
|
+
function _t(e, t) {
|
|
419
|
+
const n = Yt(e), i = Yt(t);
|
|
420
|
+
if (n < i)
|
|
421
|
+
return -1;
|
|
422
|
+
if (n > i)
|
|
423
|
+
return 1;
|
|
424
|
+
const r = Number.isNaN(n), s = Number.isNaN(i);
|
|
425
|
+
return r && s ? 0 : r ? 1 : s ? -1 : 0;
|
|
426
|
+
}
|
|
427
|
+
function Wt(e, t) {
|
|
428
|
+
if (Number.isInteger(t)) {
|
|
429
|
+
const i = BigInt(t);
|
|
430
|
+
return e < i ? -1 : e > i ? 1 : 0;
|
|
431
|
+
}
|
|
432
|
+
const n = BigInt(Math.floor(t));
|
|
433
|
+
return e <= n ? -1 : 1;
|
|
434
|
+
}
|
|
435
|
+
function Ct(e, t) {
|
|
436
|
+
if (typeof e == "bigint" && typeof t == "bigint")
|
|
437
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
438
|
+
if (typeof e == "number" && typeof t == "number")
|
|
439
|
+
return _t(e, t);
|
|
440
|
+
const n = typeof e == "number" ? e : t;
|
|
441
|
+
return Number.isFinite(n) ? typeof e == "bigint" ? Wt(e, t) : -Wt(t, e) : _t(Number(e), Number(t));
|
|
442
|
+
}
|
|
443
|
+
function rn(e) {
|
|
444
|
+
if (Number.isNaN(e))
|
|
445
|
+
return "NaN";
|
|
446
|
+
if (e === 1 / 0)
|
|
447
|
+
return "Infinity";
|
|
448
|
+
if (e === -1 / 0)
|
|
449
|
+
return "-Infinity";
|
|
450
|
+
if (e === 0)
|
|
451
|
+
return Object.is(e, -0) ? "-0.0" : "0.0";
|
|
452
|
+
const t = Math.abs(e);
|
|
453
|
+
if (t >= 1e-3 && t < 1e7) {
|
|
454
|
+
const s = String(e);
|
|
455
|
+
return s.includes(".") ? s : s + ".0";
|
|
456
|
+
}
|
|
457
|
+
const [n, i] = e.toExponential().split("e");
|
|
458
|
+
return `${n.includes(".") ? n : n + ".0"}E${i.replace("+", "")}`;
|
|
459
|
+
}
|
|
460
|
+
const Oe = /* @__PURE__ */ new Set(["map", "filter", "all", "exists", "existsOne", "sortBy"]), $e = 256;
|
|
461
|
+
class Re {
|
|
349
462
|
constructor(t) {
|
|
350
|
-
this.lexer = new
|
|
463
|
+
this.depth = 0, this.lexer = new de(t), this.current = this.lexer.next();
|
|
351
464
|
}
|
|
352
465
|
/**
|
|
353
466
|
* Parse a CEL expression from the input string.
|
|
@@ -356,8 +469,8 @@ class Y {
|
|
|
356
469
|
*/
|
|
357
470
|
parse() {
|
|
358
471
|
const t = this.parseExpr();
|
|
359
|
-
if (this.current.type !==
|
|
360
|
-
throw new
|
|
472
|
+
if (this.current.type !== o.EOF)
|
|
473
|
+
throw new U(
|
|
361
474
|
`Unexpected token after expression: ${this.current.value}`,
|
|
362
475
|
this.current.line,
|
|
363
476
|
this.current.column
|
|
@@ -366,30 +479,36 @@ class Y {
|
|
|
366
479
|
}
|
|
367
480
|
// expr = conditionalOr ( '?' conditionalOr ':' expr )?
|
|
368
481
|
parseExpr() {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
this.
|
|
373
|
-
|
|
374
|
-
|
|
482
|
+
if (++this.depth > $e)
|
|
483
|
+
throw new U("Expression nesting too deep", this.current.line, this.current.column);
|
|
484
|
+
try {
|
|
485
|
+
const t = this.parseConditionalOr();
|
|
486
|
+
if (this.match(o.QUESTION)) {
|
|
487
|
+
const n = this.parseConditionalOr();
|
|
488
|
+
this.expect(o.COLON);
|
|
489
|
+
const i = this.parseExpr();
|
|
490
|
+
return new nn(t, n, i);
|
|
491
|
+
}
|
|
492
|
+
return t;
|
|
493
|
+
} finally {
|
|
494
|
+
this.depth--;
|
|
375
495
|
}
|
|
376
|
-
return t;
|
|
377
496
|
}
|
|
378
497
|
// conditionalOr = conditionalAnd ( '||' conditionalAnd )*
|
|
379
498
|
parseConditionalOr() {
|
|
380
499
|
let t = this.parseConditionalAnd();
|
|
381
|
-
for (; this.match(
|
|
382
|
-
const
|
|
383
|
-
t = new
|
|
500
|
+
for (; this.match(o.LOGICAL_OR); ) {
|
|
501
|
+
const n = this.parseConditionalAnd();
|
|
502
|
+
t = new X(h.LOGICAL_OR, t, n);
|
|
384
503
|
}
|
|
385
504
|
return t;
|
|
386
505
|
}
|
|
387
506
|
// conditionalAnd = relation ( '&&' relation )*
|
|
388
507
|
parseConditionalAnd() {
|
|
389
508
|
let t = this.parseRelation();
|
|
390
|
-
for (; this.match(
|
|
391
|
-
const
|
|
392
|
-
t = new
|
|
509
|
+
for (; this.match(o.LOGICAL_AND); ) {
|
|
510
|
+
const n = this.parseRelation();
|
|
511
|
+
t = new X(h.LOGICAL_AND, t, n);
|
|
393
512
|
}
|
|
394
513
|
return t;
|
|
395
514
|
}
|
|
@@ -398,58 +517,58 @@ class Y {
|
|
|
398
517
|
parseRelation() {
|
|
399
518
|
let t = this.parseAddition();
|
|
400
519
|
for (; this.isRelationalOp(this.current.type); ) {
|
|
401
|
-
const
|
|
520
|
+
const n = this.current.type;
|
|
402
521
|
this.advance();
|
|
403
522
|
const i = this.parseAddition();
|
|
404
|
-
t = new
|
|
523
|
+
t = new X(this.toBinaryOp(n), t, i);
|
|
405
524
|
}
|
|
406
525
|
return t;
|
|
407
526
|
}
|
|
408
527
|
// addition = multiplication ( ('+' | '-') multiplication )*
|
|
409
528
|
parseAddition() {
|
|
410
529
|
let t = this.parseMultiplication();
|
|
411
|
-
for (; this.current.type ===
|
|
412
|
-
const
|
|
530
|
+
for (; this.current.type === o.PLUS || this.current.type === o.MINUS; ) {
|
|
531
|
+
const n = this.current.type;
|
|
413
532
|
this.advance();
|
|
414
533
|
const i = this.parseMultiplication();
|
|
415
|
-
t = new
|
|
534
|
+
t = new X(n === o.PLUS ? h.ADD : h.SUBTRACT, t, i);
|
|
416
535
|
}
|
|
417
536
|
return t;
|
|
418
537
|
}
|
|
419
538
|
// multiplication = unary ( ('*' | '/' | '%') unary )*
|
|
420
539
|
parseMultiplication() {
|
|
421
540
|
let t = this.parseUnary();
|
|
422
|
-
for (; this.current.type ===
|
|
423
|
-
const
|
|
541
|
+
for (; this.current.type === o.STAR || this.current.type === o.SLASH || this.current.type === o.PERCENT; ) {
|
|
542
|
+
const n = this.current.type;
|
|
424
543
|
this.advance();
|
|
425
|
-
const i = this.parseUnary(),
|
|
426
|
-
t = new
|
|
544
|
+
const i = this.parseUnary(), r = n === o.STAR ? h.MULTIPLY : n === o.SLASH ? h.DIVIDE : h.MODULO;
|
|
545
|
+
t = new X(r, t, i);
|
|
427
546
|
}
|
|
428
547
|
return t;
|
|
429
548
|
}
|
|
430
549
|
// unary = '!'+ member | '-'+ member | member
|
|
431
550
|
parseUnary() {
|
|
432
|
-
return this.current.type ===
|
|
551
|
+
return this.current.type === o.BANG ? (this.advance(), new At(J.NOT, this.parseUnary())) : this.current.type === o.MINUS ? (this.advance(), new At(J.NEGATE, this.parseUnary())) : this.parseMember();
|
|
433
552
|
}
|
|
434
553
|
// member = primary ( selector | index | fieldCall )*
|
|
435
554
|
parseMember() {
|
|
436
555
|
let t = this.parsePrimary();
|
|
437
556
|
for (; ; )
|
|
438
|
-
if (this.current.type ===
|
|
557
|
+
if (this.current.type === o.DOT) {
|
|
439
558
|
this.advance();
|
|
440
|
-
const
|
|
441
|
-
if (this.current.type ===
|
|
559
|
+
const n = this.expectIdentifier();
|
|
560
|
+
if (this.current.type === o.LPAREN) {
|
|
442
561
|
this.advance();
|
|
443
562
|
const i = this.parseExprList();
|
|
444
|
-
this.expect(
|
|
445
|
-
const
|
|
446
|
-
t = new
|
|
563
|
+
this.expect(o.RPAREN);
|
|
564
|
+
const r = Oe.has(n);
|
|
565
|
+
t = new gt(t, n, i, r);
|
|
447
566
|
} else
|
|
448
|
-
t = new
|
|
449
|
-
} else if (this.current.type ===
|
|
567
|
+
t = new nt(t, n);
|
|
568
|
+
} else if (this.current.type === o.LBRACKET) {
|
|
450
569
|
this.advance();
|
|
451
|
-
const
|
|
452
|
-
this.expect(
|
|
570
|
+
const n = this.parseExpr();
|
|
571
|
+
this.expect(o.RBRACKET), t = new we(t, n);
|
|
453
572
|
} else
|
|
454
573
|
break;
|
|
455
574
|
return t;
|
|
@@ -458,244 +577,318 @@ class Y {
|
|
|
458
577
|
parsePrimary() {
|
|
459
578
|
if (this.isLiteralToken(this.current.type))
|
|
460
579
|
return this.parseLiteral();
|
|
461
|
-
if (this.current.type ===
|
|
580
|
+
if (this.current.type === o.LBRACKET)
|
|
462
581
|
return this.parseListLiteral();
|
|
463
|
-
if (this.current.type ===
|
|
582
|
+
if (this.current.type === o.LBRACE)
|
|
464
583
|
return this.parseMapOrStructLiteral(null);
|
|
465
|
-
if (this.current.type ===
|
|
584
|
+
if (this.current.type === o.LPAREN) {
|
|
466
585
|
this.advance();
|
|
467
586
|
const t = this.parseExpr();
|
|
468
|
-
return this.expect(
|
|
587
|
+
return this.expect(o.RPAREN), t;
|
|
469
588
|
}
|
|
470
|
-
if (this.current.type ===
|
|
589
|
+
if (this.current.type === o.DOT) {
|
|
471
590
|
this.advance();
|
|
472
591
|
const t = this.expectIdentifier();
|
|
473
|
-
if (this.current.type ===
|
|
592
|
+
if (this.current.type === o.LPAREN) {
|
|
474
593
|
this.advance();
|
|
475
|
-
const
|
|
476
|
-
return this.expect(
|
|
594
|
+
const n = this.parseExprList();
|
|
595
|
+
return this.expect(o.RPAREN), new gt(null, t, n);
|
|
477
596
|
}
|
|
478
|
-
return new
|
|
597
|
+
return new nt(null, t);
|
|
479
598
|
}
|
|
480
|
-
if (this.current.type ===
|
|
599
|
+
if (this.current.type === o.IDENTIFIER) {
|
|
481
600
|
const t = this.current.value;
|
|
482
|
-
if (this.advance(), this.current.type ===
|
|
601
|
+
if (this.advance(), this.current.type === o.LPAREN) {
|
|
602
|
+
const n = this.current.line, i = this.current.column;
|
|
483
603
|
this.advance();
|
|
484
|
-
const
|
|
485
|
-
return this.expect(
|
|
604
|
+
const r = this.parseExprList();
|
|
605
|
+
return this.expect(o.RPAREN), t === "has" && r.length === 1 ? this.test(r[0], n, i) : new gt(null, t, r);
|
|
486
606
|
}
|
|
487
|
-
if (this.current.type ===
|
|
488
|
-
const
|
|
489
|
-
return this.parseMapOrStructLiteral(
|
|
607
|
+
if (this.current.type === o.DOT && this.isQualifiedStructLiteral()) {
|
|
608
|
+
const n = this.parseQualifiedIdent(t);
|
|
609
|
+
return this.parseMapOrStructLiteral(n);
|
|
490
610
|
}
|
|
491
|
-
return this.current.type ===
|
|
611
|
+
return this.current.type === o.LBRACE ? this.parseMapOrStructLiteral(t) : new It(t);
|
|
492
612
|
}
|
|
493
|
-
throw new
|
|
613
|
+
throw new U(
|
|
494
614
|
`Unexpected token: ${this.current.value}`,
|
|
495
615
|
this.current.line,
|
|
496
616
|
this.current.column
|
|
497
617
|
);
|
|
498
618
|
}
|
|
619
|
+
// Rewrites the has() macro into a presence test on the selected field
|
|
620
|
+
test(t, n, i) {
|
|
621
|
+
if (t instanceof nt)
|
|
622
|
+
return new nt(t.operand, t.field, !0);
|
|
623
|
+
throw new U("has() requires a field selection, for example has(a.b)", n, i);
|
|
624
|
+
}
|
|
499
625
|
// listLiteral = '[' exprList? ','? ']'
|
|
500
626
|
parseListLiteral() {
|
|
501
|
-
this.expect(
|
|
627
|
+
this.expect(o.LBRACKET);
|
|
502
628
|
const t = [];
|
|
503
|
-
return this.current.type !==
|
|
629
|
+
return this.current.type !== o.RBRACKET && (t.push(...this.parseExprList()), this.current.type === o.COMMA && this.advance()), this.expect(o.RBRACKET), new ge(t);
|
|
504
630
|
}
|
|
505
631
|
// mapLiteral or structLiteral
|
|
506
632
|
parseMapOrStructLiteral(t) {
|
|
507
|
-
if (this.expect(
|
|
508
|
-
return this.advance(), t !== null ? new
|
|
509
|
-
if (this.current.type ===
|
|
633
|
+
if (this.expect(o.LBRACE), this.current.type === o.RBRACE)
|
|
634
|
+
return this.advance(), t !== null ? new Qt(t, []) : new jt([]);
|
|
635
|
+
if (this.current.type === o.IDENTIFIER && this.peekAhead(1).type === o.COLON || t !== null) {
|
|
510
636
|
const i = this.parseFieldInits();
|
|
511
|
-
return this.current.type ===
|
|
637
|
+
return this.current.type === o.COMMA && this.advance(), this.expect(o.RBRACE), new Qt(t, i);
|
|
512
638
|
} else {
|
|
513
639
|
const i = this.parseMapInits();
|
|
514
|
-
return this.current.type ===
|
|
640
|
+
return this.current.type === o.COMMA && this.advance(), this.expect(o.RBRACE), new jt(i);
|
|
515
641
|
}
|
|
516
642
|
}
|
|
517
643
|
// exprList = expr ( ',' expr )*
|
|
518
644
|
parseExprList() {
|
|
519
|
-
const t = [],
|
|
520
|
-
if (
|
|
645
|
+
const t = [], n = this.current.type;
|
|
646
|
+
if (n === o.RPAREN || n === o.RBRACKET)
|
|
521
647
|
return t;
|
|
522
|
-
for (t.push(this.parseExpr()); this.current.type ===
|
|
648
|
+
for (t.push(this.parseExpr()); this.current.type === o.COMMA && (this.advance(), !(this.current.type === o.RPAREN || this.current.type === o.RBRACKET)); )
|
|
523
649
|
t.push(this.parseExpr());
|
|
524
650
|
return t;
|
|
525
651
|
}
|
|
526
652
|
// mapInits = mapInit ( ',' mapInit )*
|
|
527
653
|
parseMapInits() {
|
|
528
654
|
const t = [];
|
|
529
|
-
for (t.push(this.parseMapInit()); this.current.type ===
|
|
655
|
+
for (t.push(this.parseMapInit()); this.current.type === o.COMMA && (this.advance(), this.current.type !== o.RBRACE); )
|
|
530
656
|
t.push(this.parseMapInit());
|
|
531
657
|
return t;
|
|
532
658
|
}
|
|
533
659
|
// mapInit = expr ':' expr
|
|
534
660
|
parseMapInit() {
|
|
535
661
|
const t = this.parseExpr();
|
|
536
|
-
this.expect(
|
|
537
|
-
const
|
|
538
|
-
return new
|
|
662
|
+
this.expect(o.COLON);
|
|
663
|
+
const n = this.parseExpr();
|
|
664
|
+
return new be(t, n);
|
|
539
665
|
}
|
|
540
666
|
// fieldInits = fieldInit ( ',' fieldInit )*
|
|
541
667
|
parseFieldInits() {
|
|
542
668
|
const t = [];
|
|
543
|
-
for (t.push(this.parseFieldInit()); this.current.type ===
|
|
669
|
+
for (t.push(this.parseFieldInit()); this.current.type === o.COMMA && (this.advance(), this.current.type !== o.RBRACE); )
|
|
544
670
|
t.push(this.parseFieldInit());
|
|
545
671
|
return t;
|
|
546
672
|
}
|
|
547
673
|
// fieldInit = ident ':' expr
|
|
548
674
|
parseFieldInit() {
|
|
549
675
|
const t = this.expectIdentifier();
|
|
550
|
-
this.expect(
|
|
551
|
-
const
|
|
552
|
-
return new
|
|
676
|
+
this.expect(o.COLON);
|
|
677
|
+
const n = this.parseExpr();
|
|
678
|
+
return new me(t, n);
|
|
553
679
|
}
|
|
554
680
|
// qualifiedIdent = ident ( '.' ident )*
|
|
555
681
|
parseQualifiedIdent(t) {
|
|
556
|
-
let
|
|
557
|
-
for (; this.current.type ===
|
|
558
|
-
this.advance(),
|
|
559
|
-
return
|
|
682
|
+
let n = t;
|
|
683
|
+
for (; this.current.type === o.DOT; )
|
|
684
|
+
this.advance(), n += ".", n += this.expectIdentifier();
|
|
685
|
+
return n;
|
|
560
686
|
}
|
|
561
687
|
parseLiteral() {
|
|
562
688
|
const t = this.current;
|
|
563
689
|
switch (this.advance(), t.type) {
|
|
564
|
-
case
|
|
565
|
-
return new
|
|
566
|
-
case
|
|
567
|
-
return new
|
|
568
|
-
case
|
|
569
|
-
return new
|
|
570
|
-
case
|
|
571
|
-
return new
|
|
572
|
-
case
|
|
573
|
-
return new
|
|
574
|
-
case
|
|
575
|
-
return new
|
|
576
|
-
case
|
|
577
|
-
return new
|
|
578
|
-
case
|
|
579
|
-
return new
|
|
690
|
+
case o.NULL:
|
|
691
|
+
return new z(null, $.NULL_VALUE);
|
|
692
|
+
case o.TRUE:
|
|
693
|
+
return new z(!0, $.BOOL);
|
|
694
|
+
case o.FALSE:
|
|
695
|
+
return new z(!1, $.BOOL);
|
|
696
|
+
case o.INT:
|
|
697
|
+
return new z(this.parseIntLiteral(t), $.INT);
|
|
698
|
+
case o.UINT:
|
|
699
|
+
return new z(this.parseUintLiteral(t), $.UINT);
|
|
700
|
+
case o.DOUBLE:
|
|
701
|
+
return new z(Number(t.value), $.DOUBLE);
|
|
702
|
+
case o.STRING:
|
|
703
|
+
return new z(this.parseStringLiteral(t.value), $.STRING);
|
|
704
|
+
case o.BYTES:
|
|
705
|
+
return new z(this.parseBytesLiteral(t.value), $.BYTES);
|
|
580
706
|
default:
|
|
581
|
-
throw new
|
|
707
|
+
throw new U(`Not a literal: ${t.value}`, t.line, t.column);
|
|
582
708
|
}
|
|
583
709
|
}
|
|
584
710
|
parseIntLiteral(t) {
|
|
585
|
-
|
|
711
|
+
const n = t.value, i = n.startsWith("-"), r = i ? n.substring(1) : n, s = BigInt(r);
|
|
712
|
+
return this.checkRange(i ? -s : s, t);
|
|
586
713
|
}
|
|
587
714
|
parseUintLiteral(t) {
|
|
588
|
-
const
|
|
589
|
-
return
|
|
715
|
+
const n = t.value.substring(0, t.value.length - 1);
|
|
716
|
+
return this.checkRange(BigInt(n), t);
|
|
717
|
+
}
|
|
718
|
+
checkRange(t, n) {
|
|
719
|
+
if (t < K || t > at)
|
|
720
|
+
throw new U(
|
|
721
|
+
`Integer literal out of range: ${n.value}`,
|
|
722
|
+
n.line,
|
|
723
|
+
n.column
|
|
724
|
+
);
|
|
725
|
+
return t;
|
|
590
726
|
}
|
|
591
727
|
parseStringLiteral(t) {
|
|
592
|
-
const
|
|
728
|
+
const n = t.startsWith("r") || t.startsWith("R");
|
|
593
729
|
let i;
|
|
594
|
-
return
|
|
730
|
+
return n && (t.substring(1).startsWith('"""') || t.substring(1).startsWith("'''")) ? i = t.substring(4, t.length - 3) : t.startsWith('"""') || t.startsWith("'''") ? (i = t.substring(3, t.length - 3), i = this.unescapeString(i)) : n ? i = t.substring(2, t.length - 1) : (i = t.substring(1, t.length - 1), i = this.unescapeString(i)), i;
|
|
595
731
|
}
|
|
596
732
|
parseBytesLiteral(t) {
|
|
597
|
-
const
|
|
598
|
-
return this.
|
|
733
|
+
const n = t.substring(2, t.length - 1);
|
|
734
|
+
return this.unescapeBytes(n);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Decodes the escapes of a bytes literal.
|
|
738
|
+
*
|
|
739
|
+
* Character escapes and plain text accumulate in a pending buffer that is
|
|
740
|
+
* UTF-8 encoded when flushed, while \xHH and octal escapes write a raw byte.
|
|
741
|
+
*/
|
|
742
|
+
unescapeBytes(t) {
|
|
743
|
+
const n = [];
|
|
744
|
+
let i = "";
|
|
745
|
+
const r = () => {
|
|
746
|
+
i.length > 0 && (n.push(...Mt(i)), i = "");
|
|
747
|
+
};
|
|
748
|
+
let s = 0;
|
|
749
|
+
for (; s < t.length; ) {
|
|
750
|
+
if (t[s] !== "\\" || s + 1 >= t.length) {
|
|
751
|
+
i += t[s], s++;
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
const c = t[s + 1], u = this.simpleEscape(c);
|
|
755
|
+
u !== null ? (i += u, s += 2) : c === "x" && s + 4 <= t.length ? (r(), n.push(parseInt(t.substring(s + 2, s + 4), 16)), s += 4) : c === "u" && s + 6 <= t.length ? (i += String.fromCharCode(parseInt(t.substring(s + 2, s + 6), 16)), s += 6) : c === "U" && s + 10 <= t.length ? (i += String.fromCodePoint(parseInt(t.substring(s + 2, s + 10), 16)), s += 10) : this.isOctal(t, s) ? (r(), n.push(parseInt(t.substring(s + 1, s + 4), 8)), s += 4) : (i += t[s], s++);
|
|
756
|
+
}
|
|
757
|
+
return r(), Uint8Array.from(n);
|
|
758
|
+
}
|
|
759
|
+
simpleEscape(t) {
|
|
760
|
+
switch (t) {
|
|
761
|
+
case "\\":
|
|
762
|
+
return "\\";
|
|
763
|
+
case '"':
|
|
764
|
+
return '"';
|
|
765
|
+
case "'":
|
|
766
|
+
return "'";
|
|
767
|
+
case "`":
|
|
768
|
+
return "`";
|
|
769
|
+
case "?":
|
|
770
|
+
return "?";
|
|
771
|
+
case "a":
|
|
772
|
+
return "\x07";
|
|
773
|
+
case "b":
|
|
774
|
+
return "\b";
|
|
775
|
+
case "f":
|
|
776
|
+
return "\f";
|
|
777
|
+
case "n":
|
|
778
|
+
return `
|
|
779
|
+
`;
|
|
780
|
+
case "r":
|
|
781
|
+
return "\r";
|
|
782
|
+
case "t":
|
|
783
|
+
return " ";
|
|
784
|
+
case "v":
|
|
785
|
+
return "\v";
|
|
786
|
+
default:
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
isOctal(t, n) {
|
|
791
|
+
return n + 3 < t.length && t[n + 1] >= "0" && t[n + 1] <= "3" && t[n + 2] >= "0" && t[n + 2] <= "7" && t[n + 3] >= "0" && t[n + 3] <= "7";
|
|
599
792
|
}
|
|
600
793
|
unescapeString(t) {
|
|
601
|
-
let
|
|
794
|
+
let n = "", i = 0;
|
|
602
795
|
for (; i < t.length; )
|
|
603
796
|
if (t[i] === "\\" && i + 1 < t.length) {
|
|
604
|
-
const
|
|
605
|
-
switch (
|
|
797
|
+
const r = t[i + 1];
|
|
798
|
+
switch (r) {
|
|
606
799
|
case "\\":
|
|
607
|
-
|
|
800
|
+
n += "\\", i += 2;
|
|
608
801
|
break;
|
|
609
802
|
case '"':
|
|
610
|
-
|
|
803
|
+
n += '"', i += 2;
|
|
611
804
|
break;
|
|
612
805
|
case "'":
|
|
613
|
-
|
|
806
|
+
n += "'", i += 2;
|
|
614
807
|
break;
|
|
615
808
|
case "`":
|
|
616
|
-
|
|
809
|
+
n += "`", i += 2;
|
|
617
810
|
break;
|
|
618
811
|
case "?":
|
|
619
|
-
|
|
812
|
+
n += "?", i += 2;
|
|
620
813
|
break;
|
|
621
814
|
case "a":
|
|
622
|
-
|
|
815
|
+
n += "\x07", i += 2;
|
|
623
816
|
break;
|
|
624
817
|
case "b":
|
|
625
|
-
|
|
818
|
+
n += "\b", i += 2;
|
|
626
819
|
break;
|
|
627
820
|
case "f":
|
|
628
|
-
|
|
821
|
+
n += "\f", i += 2;
|
|
629
822
|
break;
|
|
630
823
|
case "n":
|
|
631
|
-
|
|
824
|
+
n += `
|
|
632
825
|
`, i += 2;
|
|
633
826
|
break;
|
|
634
827
|
case "r":
|
|
635
|
-
|
|
828
|
+
n += "\r", i += 2;
|
|
636
829
|
break;
|
|
637
830
|
case "t":
|
|
638
|
-
|
|
831
|
+
n += " ", i += 2;
|
|
639
832
|
break;
|
|
640
833
|
case "v":
|
|
641
|
-
|
|
834
|
+
n += "\v", i += 2;
|
|
642
835
|
break;
|
|
643
836
|
case "x":
|
|
644
837
|
if (i + 3 < t.length) {
|
|
645
|
-
const
|
|
646
|
-
|
|
838
|
+
const s = t.substring(i + 2, i + 4);
|
|
839
|
+
n += String.fromCharCode(parseInt(s, 16)), i += 4;
|
|
647
840
|
} else
|
|
648
|
-
|
|
841
|
+
n += t[i], i++;
|
|
649
842
|
break;
|
|
650
843
|
case "u":
|
|
651
844
|
if (i + 5 < t.length) {
|
|
652
|
-
const
|
|
653
|
-
|
|
845
|
+
const s = t.substring(i + 2, i + 6);
|
|
846
|
+
n += String.fromCharCode(parseInt(s, 16)), i += 6;
|
|
654
847
|
} else
|
|
655
|
-
|
|
848
|
+
n += t[i], i++;
|
|
656
849
|
break;
|
|
657
850
|
case "U":
|
|
658
851
|
if (i + 9 < t.length) {
|
|
659
|
-
const
|
|
660
|
-
|
|
852
|
+
const s = t.substring(i + 2, i + 10), c = parseInt(s, 16);
|
|
853
|
+
n += String.fromCodePoint(c), i += 10;
|
|
661
854
|
} else
|
|
662
|
-
|
|
855
|
+
n += t[i], i++;
|
|
663
856
|
break;
|
|
664
857
|
default:
|
|
665
|
-
if (i + 3 < t.length &&
|
|
666
|
-
const
|
|
667
|
-
|
|
858
|
+
if (i + 3 < t.length && r >= "0" && r <= "3" && t[i + 2] >= "0" && t[i + 2] <= "7" && t[i + 3] >= "0" && t[i + 3] <= "7") {
|
|
859
|
+
const s = t.substring(i + 1, i + 4);
|
|
860
|
+
n += String.fromCharCode(parseInt(s, 8)), i += 4;
|
|
668
861
|
} else
|
|
669
|
-
|
|
862
|
+
n += t[i], i++;
|
|
670
863
|
}
|
|
671
864
|
} else
|
|
672
|
-
|
|
673
|
-
return
|
|
865
|
+
n += t[i], i++;
|
|
866
|
+
return n;
|
|
674
867
|
}
|
|
675
868
|
isLiteralToken(t) {
|
|
676
|
-
return t ===
|
|
869
|
+
return t === o.NULL || t === o.TRUE || t === o.FALSE || t === o.INT || t === o.UINT || t === o.DOUBLE || t === o.STRING || t === o.BYTES;
|
|
677
870
|
}
|
|
678
871
|
isRelationalOp(t) {
|
|
679
|
-
return t ===
|
|
872
|
+
return t === o.LT || t === o.LE || t === o.GT || t === o.GE || t === o.EQ || t === o.NE || t === o.IN;
|
|
680
873
|
}
|
|
681
874
|
toBinaryOp(t) {
|
|
682
875
|
switch (t) {
|
|
683
|
-
case
|
|
684
|
-
return
|
|
685
|
-
case
|
|
686
|
-
return
|
|
687
|
-
case
|
|
688
|
-
return
|
|
689
|
-
case
|
|
690
|
-
return
|
|
691
|
-
case
|
|
692
|
-
return
|
|
693
|
-
case
|
|
694
|
-
return
|
|
695
|
-
case
|
|
696
|
-
return
|
|
876
|
+
case o.LT:
|
|
877
|
+
return h.LESS;
|
|
878
|
+
case o.LE:
|
|
879
|
+
return h.LESS_EQUAL;
|
|
880
|
+
case o.GT:
|
|
881
|
+
return h.GREATER;
|
|
882
|
+
case o.GE:
|
|
883
|
+
return h.GREATER_EQUAL;
|
|
884
|
+
case o.EQ:
|
|
885
|
+
return h.EQUAL;
|
|
886
|
+
case o.NE:
|
|
887
|
+
return h.NOT_EQUAL;
|
|
888
|
+
case o.IN:
|
|
889
|
+
return h.IN;
|
|
697
890
|
default:
|
|
698
|
-
throw new
|
|
891
|
+
throw new U(
|
|
699
892
|
`Unknown relational operator: ${t}`,
|
|
700
893
|
this.current.line,
|
|
701
894
|
this.current.column
|
|
@@ -707,7 +900,7 @@ class Y {
|
|
|
707
900
|
}
|
|
708
901
|
expect(t) {
|
|
709
902
|
if (this.current.type !== t)
|
|
710
|
-
throw new
|
|
903
|
+
throw new U(
|
|
711
904
|
`Expected ${t} but found ${this.current.type}`,
|
|
712
905
|
this.current.line,
|
|
713
906
|
this.current.column
|
|
@@ -715,8 +908,8 @@ class Y {
|
|
|
715
908
|
this.advance();
|
|
716
909
|
}
|
|
717
910
|
expectIdentifier() {
|
|
718
|
-
if (this.current.type !==
|
|
719
|
-
throw new
|
|
911
|
+
if (this.current.type !== o.IDENTIFIER)
|
|
912
|
+
throw new U(
|
|
720
913
|
`Expected identifier but found ${this.current.value}`,
|
|
721
914
|
this.current.line,
|
|
722
915
|
this.current.column
|
|
@@ -732,289 +925,1709 @@ class Y {
|
|
|
732
925
|
}
|
|
733
926
|
// Check if we have a pattern like: . ident ( . ident )* {
|
|
734
927
|
isQualifiedStructLiteral() {
|
|
735
|
-
let t = 1,
|
|
736
|
-
if (
|
|
928
|
+
let t = 1, n = this.peekAhead(t);
|
|
929
|
+
if (n.type !== o.IDENTIFIER)
|
|
737
930
|
return !1;
|
|
738
|
-
for (t++,
|
|
739
|
-
if (t++,
|
|
931
|
+
for (t++, n = this.peekAhead(t); n.type === o.DOT; ) {
|
|
932
|
+
if (t++, n = this.peekAhead(t), n.type !== o.IDENTIFIER)
|
|
740
933
|
return !1;
|
|
741
|
-
t++,
|
|
934
|
+
t++, n = this.peekAhead(t);
|
|
742
935
|
}
|
|
743
|
-
return
|
|
936
|
+
return n.type === o.LBRACE;
|
|
744
937
|
}
|
|
745
938
|
}
|
|
746
|
-
|
|
939
|
+
const p = class p {
|
|
747
940
|
constructor(t) {
|
|
748
|
-
|
|
941
|
+
this.name = t;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Returns the type with the given name, or null when the name does not denote a CEL type.
|
|
945
|
+
*
|
|
946
|
+
* Used to resolve bare type names such as `int` when they appear as identifiers.
|
|
947
|
+
* `unknown` is deliberately not resolvable.
|
|
948
|
+
*
|
|
949
|
+
* @param name The candidate type name
|
|
950
|
+
* @returns The matching type, or null
|
|
951
|
+
*/
|
|
952
|
+
static of(t) {
|
|
953
|
+
return p.BY_NAME.get(t) ?? null;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Reports whether the value is a Type.
|
|
957
|
+
*/
|
|
958
|
+
static isType(t) {
|
|
959
|
+
return t instanceof p;
|
|
960
|
+
}
|
|
961
|
+
equals(t) {
|
|
962
|
+
return t instanceof p && t.name === this.name;
|
|
963
|
+
}
|
|
964
|
+
toString() {
|
|
965
|
+
return this.name;
|
|
749
966
|
}
|
|
967
|
+
};
|
|
968
|
+
p.NULL = new p("null_type"), p.BOOL = new p("bool"), p.INT = new p("int"), p.UINT = new p("uint"), p.DOUBLE = new p("double"), p.STRING = new p("string"), p.BYTES = new p("bytes"), p.LIST = new p("list"), p.MAP = new p("map"), p.TIMESTAMP = new p("timestamp"), p.DURATION = new p("duration"), p.TYPE = new p("type"), p.UNKNOWN = new p("unknown"), p.BY_NAME = new Map(
|
|
969
|
+
[
|
|
970
|
+
p.NULL,
|
|
971
|
+
p.BOOL,
|
|
972
|
+
p.INT,
|
|
973
|
+
p.UINT,
|
|
974
|
+
p.DOUBLE,
|
|
975
|
+
p.STRING,
|
|
976
|
+
p.BYTES,
|
|
977
|
+
p.LIST,
|
|
978
|
+
p.MAP,
|
|
979
|
+
p.TIMESTAMP,
|
|
980
|
+
p.DURATION,
|
|
981
|
+
p.TYPE
|
|
982
|
+
].map((t) => [t.name, t])
|
|
983
|
+
);
|
|
984
|
+
let y = p;
|
|
985
|
+
const rt = 86400n;
|
|
986
|
+
function Ut(e, t) {
|
|
987
|
+
const n = e / t;
|
|
988
|
+
return e % t !== 0n && e < 0n != t < 0n ? n - 1n : n;
|
|
750
989
|
}
|
|
751
|
-
function
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
990
|
+
function st(e, t) {
|
|
991
|
+
const n = e % t;
|
|
992
|
+
return n !== 0n && n < 0n != t < 0n ? n + t : n;
|
|
993
|
+
}
|
|
994
|
+
function Bt(e, t, n) {
|
|
995
|
+
const i = t <= 2 ? e - 1n : e, r = (i >= 0n ? i : i - 399n) / 400n, s = i - r * 400n, u = (153n * (BigInt(t) + (t > 2 ? -3n : 9n)) + 2n) / 5n + BigInt(n) - 1n, d = s * 365n + s / 4n - s / 100n + u;
|
|
996
|
+
return r * 146097n + d - 719468n;
|
|
997
|
+
}
|
|
998
|
+
function Me(e) {
|
|
999
|
+
const t = e + 719468n, n = (t >= 0n ? t : t - 146096n) / 146097n, i = t - n * 146097n, r = (i - i / 1460n + i / 36524n - i / 146096n) / 365n, s = r + n * 400n, c = i - (365n * r + r / 4n - r / 100n), u = (5n * c + 2n) / 153n, d = Number(c - (153n * u + 2n) / 5n + 1n), E = Number(u < 10n ? u + 3n : u - 9n);
|
|
1000
|
+
return { year: E <= 2 ? s + 1n : s, month: E, day: d };
|
|
1001
|
+
}
|
|
1002
|
+
function Ce(e) {
|
|
1003
|
+
return e % 4n === 0n && (e % 100n !== 0n || e % 400n === 0n);
|
|
1004
|
+
}
|
|
1005
|
+
function Ue(e, t) {
|
|
1006
|
+
switch (t) {
|
|
1007
|
+
case 2:
|
|
1008
|
+
return Ce(e) ? 29 : 28;
|
|
1009
|
+
case 4:
|
|
1010
|
+
case 6:
|
|
1011
|
+
case 9:
|
|
1012
|
+
case 11:
|
|
1013
|
+
return 30;
|
|
1014
|
+
default:
|
|
1015
|
+
return 31;
|
|
768
1016
|
}
|
|
769
|
-
if (typeof r == "boolean")
|
|
770
|
-
return r ? 1 : 0;
|
|
771
|
-
throw new Error(`Cannot convert to int: ${r}`);
|
|
772
1017
|
}
|
|
773
|
-
function
|
|
774
|
-
const t =
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
1018
|
+
function Nt(e) {
|
|
1019
|
+
const t = Ut(e, rt), n = Number(st(e, rt)), { year: i, month: r, day: s } = Me(t);
|
|
1020
|
+
return {
|
|
1021
|
+
year: i,
|
|
1022
|
+
month: r,
|
|
1023
|
+
day: s,
|
|
1024
|
+
hour: Math.floor(n / 3600),
|
|
1025
|
+
minute: Math.floor(n % 3600 / 60),
|
|
1026
|
+
second: n % 60,
|
|
1027
|
+
// 1970-01-01 was a Thursday
|
|
1028
|
+
weekday: Number(st(t + 4n, 7n)),
|
|
1029
|
+
dayOfYear: Number(t - Bt(i, 1, 1)) + 1
|
|
1030
|
+
};
|
|
778
1031
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
throw new Error(`Cannot convert to double: ${r}`);
|
|
1032
|
+
const Kt = /* @__PURE__ */ new Map();
|
|
1033
|
+
function Be(e) {
|
|
1034
|
+
if (typeof e != "string")
|
|
1035
|
+
throw new a(`Time zone must be a string: ${String(e)}`);
|
|
1036
|
+
const t = Kt.get(e);
|
|
1037
|
+
if (t)
|
|
786
1038
|
return t;
|
|
1039
|
+
let n;
|
|
1040
|
+
try {
|
|
1041
|
+
n = new Intl.DateTimeFormat("en-US", {
|
|
1042
|
+
timeZone: e,
|
|
1043
|
+
hourCycle: "h23",
|
|
1044
|
+
era: "short",
|
|
1045
|
+
year: "numeric",
|
|
1046
|
+
month: "numeric",
|
|
1047
|
+
day: "numeric",
|
|
1048
|
+
hour: "numeric",
|
|
1049
|
+
minute: "numeric",
|
|
1050
|
+
second: "numeric"
|
|
1051
|
+
});
|
|
1052
|
+
} catch {
|
|
1053
|
+
throw new a(`Invalid time zone: ${e}`);
|
|
1054
|
+
}
|
|
1055
|
+
return Kt.set(e, n), n;
|
|
1056
|
+
}
|
|
1057
|
+
const Ht = 8640000000000n;
|
|
1058
|
+
function Te(e, t) {
|
|
1059
|
+
if (t > Ht || t < -Ht)
|
|
1060
|
+
throw new l("Timestamp out of range for time zone conversion");
|
|
1061
|
+
const n = e.formatToParts(new Date(Number(t) * 1e3)), i = (u) => n.find((d) => d.type === u)?.value ?? "0";
|
|
1062
|
+
let r = BigInt(i("year"));
|
|
1063
|
+
i("era").startsWith("B") && (r = 1n - r);
|
|
1064
|
+
const s = Number(i("hour")) % 24;
|
|
1065
|
+
return Bt(r, Number(i("month")), Number(i("day"))) * rt + BigInt(s * 3600 + Number(i("minute")) * 60 + Number(i("second"))) - t;
|
|
1066
|
+
}
|
|
1067
|
+
function De(e, t) {
|
|
1068
|
+
if (t == null)
|
|
1069
|
+
return Nt(e);
|
|
1070
|
+
const n = Be(t);
|
|
1071
|
+
return Nt(e + Te(n, e));
|
|
1072
|
+
}
|
|
1073
|
+
const Y = 1000000000n, xe = /^-?(?:\d+(?:\.\d+)?(?:ns|us|µs|ms|s|m|h))+$/, ke = /(\d+)(?:\.(\d+))?(ns|us|µs|ms|s|m|h)/g, Pe = {
|
|
1074
|
+
ns: 1n,
|
|
1075
|
+
us: 1000n,
|
|
1076
|
+
µs: 1000n,
|
|
1077
|
+
ms: 1000000n,
|
|
1078
|
+
s: Y,
|
|
1079
|
+
m: Y * 60n,
|
|
1080
|
+
h: Y * 3600n
|
|
1081
|
+
}, S = class S {
|
|
1082
|
+
constructor(t, n) {
|
|
1083
|
+
this.seconds = t, this.nanos = n;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Creates a duration from seconds and a nanosecond adjustment, normalising the
|
|
1087
|
+
* adjustment into the seconds.
|
|
1088
|
+
*/
|
|
1089
|
+
static ofSeconds(t, n = 0n) {
|
|
1090
|
+
const i = t + Ut(n, Y), r = Number(st(n, Y));
|
|
1091
|
+
return new S(i, r);
|
|
1092
|
+
}
|
|
1093
|
+
static ofNanos(t) {
|
|
1094
|
+
return S.ofSeconds(0n, t);
|
|
1095
|
+
}
|
|
1096
|
+
static ofMillis(t) {
|
|
1097
|
+
return S.ofSeconds(0n, t * 1000000n);
|
|
1098
|
+
}
|
|
1099
|
+
static ofMinutes(t) {
|
|
1100
|
+
return new S(t * 60n, 0);
|
|
1101
|
+
}
|
|
1102
|
+
static ofHours(t) {
|
|
1103
|
+
return new S(t * 3600n, 0);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Parses a CEL duration literal such as `"300ms"`, `"-1.5h"` or `"2h45m"`.
|
|
1107
|
+
*
|
|
1108
|
+
* Units are `ns`, `us`, `µs`, `ms`, `s`, `m` and `h`. The value is accumulated
|
|
1109
|
+
* exactly and rounded half up to the nearest nanosecond.
|
|
1110
|
+
*
|
|
1111
|
+
* @throws ArgumentError if the format is invalid or the span exceeds ±10 000 years
|
|
1112
|
+
*/
|
|
1113
|
+
static parse(t) {
|
|
1114
|
+
if (!xe.test(t))
|
|
1115
|
+
throw new a(`Invalid duration format: ${t}`);
|
|
1116
|
+
const n = Array.from(t.matchAll(ke)), i = Math.max(0, ...n.map((E) => E[2]?.length ?? 0)), r = 10n ** BigInt(i);
|
|
1117
|
+
let s = 0n;
|
|
1118
|
+
for (const E of n) {
|
|
1119
|
+
const b = E[1], N = E[2] ?? "", L = BigInt(b + N) * 10n ** BigInt(i - N.length);
|
|
1120
|
+
s += L * Pe[E[3]];
|
|
1121
|
+
}
|
|
1122
|
+
let c = s / r;
|
|
1123
|
+
s % r * 2n >= r && (c += 1n);
|
|
1124
|
+
const u = c / Y;
|
|
1125
|
+
if (u > S.SPAN)
|
|
1126
|
+
throw new a(`Duration out of range: ${t}`);
|
|
1127
|
+
const d = S.ofSeconds(u, c % Y);
|
|
1128
|
+
return t.startsWith("-") ? d.negated() : d;
|
|
1129
|
+
}
|
|
1130
|
+
/** Reports whether the value is a Duration. */
|
|
1131
|
+
static isDuration(t) {
|
|
1132
|
+
return t instanceof S;
|
|
1133
|
+
}
|
|
1134
|
+
isNegative() {
|
|
1135
|
+
return this.seconds < 0n;
|
|
1136
|
+
}
|
|
1137
|
+
isZero() {
|
|
1138
|
+
return this.seconds === 0n && this.nanos === 0;
|
|
1139
|
+
}
|
|
1140
|
+
negated() {
|
|
1141
|
+
return S.ofSeconds(-this.seconds, -BigInt(this.nanos));
|
|
1142
|
+
}
|
|
1143
|
+
plus(t) {
|
|
1144
|
+
return S.ofSeconds(this.seconds + t.seconds, BigInt(this.nanos + t.nanos));
|
|
1145
|
+
}
|
|
1146
|
+
minus(t) {
|
|
1147
|
+
return S.ofSeconds(this.seconds - t.seconds, BigInt(this.nanos - t.nanos));
|
|
1148
|
+
}
|
|
1149
|
+
/** The total length in nanoseconds. */
|
|
1150
|
+
toNanos() {
|
|
1151
|
+
return this.seconds * Y + BigInt(this.nanos);
|
|
1152
|
+
}
|
|
1153
|
+
/** The whole number of milliseconds, truncated toward zero. */
|
|
1154
|
+
toMillis() {
|
|
1155
|
+
return this.toNanos() / 1000000n;
|
|
1156
|
+
}
|
|
1157
|
+
/** The whole number of seconds, truncated toward negative infinity (the seconds field). */
|
|
1158
|
+
toSeconds() {
|
|
1159
|
+
return this.seconds;
|
|
1160
|
+
}
|
|
1161
|
+
/** The whole number of minutes, truncated toward zero. */
|
|
1162
|
+
toMinutes() {
|
|
1163
|
+
return this.seconds / 60n;
|
|
1164
|
+
}
|
|
1165
|
+
/** The whole number of hours, truncated toward zero. */
|
|
1166
|
+
toHours() {
|
|
1167
|
+
return this.seconds / 3600n;
|
|
1168
|
+
}
|
|
1169
|
+
compareTo(t) {
|
|
1170
|
+
return this.seconds !== t.seconds ? this.seconds < t.seconds ? -1 : 1 : this.nanos - t.nanos;
|
|
1171
|
+
}
|
|
1172
|
+
equals(t) {
|
|
1173
|
+
return t instanceof S && t.seconds === this.seconds && t.nanos === this.nanos;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Renders the duration the way the CEL specification does: a seconds count with
|
|
1177
|
+
* an `s` suffix, for example `"3600s"`, `"1.5s"` or `"-90s"`.
|
|
1178
|
+
*/
|
|
1179
|
+
toString() {
|
|
1180
|
+
if (this.isNegative())
|
|
1181
|
+
return "-" + this.negated().toString();
|
|
1182
|
+
if (this.nanos === 0)
|
|
1183
|
+
return `${this.seconds}s`;
|
|
1184
|
+
const t = String(this.nanos).padStart(9, "0").replace(/0+$/, "");
|
|
1185
|
+
return `${this.seconds}.${t}s`;
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
S.SPAN = 315576000000n, S.ZERO = new S(0n, 0);
|
|
1189
|
+
let I = S;
|
|
1190
|
+
const Xt = 1000000000n, Ge = /^([+-]?\d{4,9})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?([Zz]|[+-]\d{2}:\d{2})$/, M = class M {
|
|
1191
|
+
constructor(t, n) {
|
|
1192
|
+
this.seconds = t, this.nanos = n;
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Creates a timestamp from epoch seconds and a nanosecond adjustment.
|
|
1196
|
+
*
|
|
1197
|
+
* @throws ArgumentError if the instant is outside the supported range
|
|
1198
|
+
*/
|
|
1199
|
+
static ofEpochSeconds(t, n = 0n) {
|
|
1200
|
+
const i = t + Ut(n, Xt), r = Number(st(n, Xt));
|
|
1201
|
+
if (i < M.MIN_SECONDS || i > M.MAX_SECONDS)
|
|
1202
|
+
throw new a(`Timestamp out of range: ${t}`);
|
|
1203
|
+
return new M(i, r);
|
|
1204
|
+
}
|
|
1205
|
+
/** Creates a timestamp from epoch milliseconds. */
|
|
1206
|
+
static ofEpochMillis(t) {
|
|
1207
|
+
return M.ofEpochSeconds(0n, t * 1000000n);
|
|
1208
|
+
}
|
|
1209
|
+
/** Converts a JavaScript Date. */
|
|
1210
|
+
static fromDate(t) {
|
|
1211
|
+
const n = t.getTime();
|
|
1212
|
+
if (Number.isNaN(n))
|
|
1213
|
+
throw new a("Invalid timestamp value: Invalid Date");
|
|
1214
|
+
return M.ofEpochMillis(BigInt(n));
|
|
1215
|
+
}
|
|
1216
|
+
/** The current instant, at millisecond resolution. */
|
|
1217
|
+
static now() {
|
|
1218
|
+
return M.ofEpochMillis(BigInt(Date.now()));
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Parses an RFC 3339 timestamp such as `2024-01-01T00:00:00Z` or
|
|
1222
|
+
* `2024-01-01T01:00:00.5+01:00`.
|
|
1223
|
+
*
|
|
1224
|
+
* @throws ArgumentError if the text is not a valid timestamp
|
|
1225
|
+
*/
|
|
1226
|
+
static parse(t) {
|
|
1227
|
+
const n = Ge.exec(t);
|
|
1228
|
+
if (!n)
|
|
1229
|
+
throw new a(`Invalid timestamp value: ${t}`);
|
|
1230
|
+
const i = BigInt(n[1]), r = Number(n[2]), s = Number(n[3]), c = Number(n[4]), u = Number(n[5]), d = Number(n[6] ?? "0"), E = Number((n[7] ?? "").padEnd(9, "0")), b = n[8];
|
|
1231
|
+
if (r < 1 || r > 12 || s < 1 || s > Ue(i, r) || c > 23 || u > 59 || d > 59)
|
|
1232
|
+
throw new a(`Invalid timestamp value: ${t}`);
|
|
1233
|
+
let N = 0n;
|
|
1234
|
+
if (b !== "Z" && b !== "z") {
|
|
1235
|
+
const k = b.startsWith("-") ? -1n : 1n, wt = Number(b.slice(1, 3)), Ft = Number(b.slice(4, 6));
|
|
1236
|
+
if (wt > 18 || Ft > 59)
|
|
1237
|
+
throw new a(`Invalid timestamp value: ${t}`);
|
|
1238
|
+
N = k * BigInt(wt * 3600 + Ft * 60);
|
|
1239
|
+
}
|
|
1240
|
+
const L = Bt(i, r, s) * rt + BigInt(c * 3600 + u * 60 + d) - N;
|
|
1241
|
+
return M.ofEpochSeconds(L, BigInt(E));
|
|
1242
|
+
}
|
|
1243
|
+
/** Reports whether the value is a Timestamp. */
|
|
1244
|
+
static isTimestamp(t) {
|
|
1245
|
+
return t instanceof M;
|
|
1246
|
+
}
|
|
1247
|
+
/** Converts to a JavaScript Date, truncating to milliseconds. */
|
|
1248
|
+
toDate() {
|
|
1249
|
+
return new Date(Number(this.seconds) * 1e3 + Math.floor(this.nanos / 1e6));
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Adds a duration.
|
|
1253
|
+
*
|
|
1254
|
+
* @throws EvaluationError if the result is outside the supported range
|
|
1255
|
+
*/
|
|
1256
|
+
plus(t) {
|
|
1257
|
+
return this.shift(t.seconds, t.nanos);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Subtracts a duration.
|
|
1261
|
+
*
|
|
1262
|
+
* @throws EvaluationError if the result is outside the supported range
|
|
1263
|
+
*/
|
|
1264
|
+
minus(t) {
|
|
1265
|
+
return this.shift(-t.seconds, -t.nanos);
|
|
1266
|
+
}
|
|
1267
|
+
shift(t, n) {
|
|
1268
|
+
try {
|
|
1269
|
+
return M.ofEpochSeconds(this.seconds + t, BigInt(this.nanos + n));
|
|
1270
|
+
} catch (i) {
|
|
1271
|
+
throw i instanceof a ? new l("Timestamp out of range") : i;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
/** The duration from this instant to another (`other - this`). */
|
|
1275
|
+
until(t) {
|
|
1276
|
+
return I.ofSeconds(t.seconds - this.seconds, BigInt(t.nanos - this.nanos));
|
|
1277
|
+
}
|
|
1278
|
+
compareTo(t) {
|
|
1279
|
+
return this.seconds !== t.seconds ? this.seconds < t.seconds ? -1 : 1 : this.nanos - t.nanos;
|
|
1280
|
+
}
|
|
1281
|
+
equals(t) {
|
|
1282
|
+
return t instanceof M && t.seconds === this.seconds && t.nanos === this.nanos;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Renders the instant in ISO-8601 form, the way java.time.Instant does:
|
|
1286
|
+
* `2024-03-05T14:30:45.250Z`, with the fraction shown in groups of three
|
|
1287
|
+
* digits only as far as needed.
|
|
1288
|
+
*/
|
|
1289
|
+
toString() {
|
|
1290
|
+
const t = Nt(this.seconds), n = (s) => String(s).padStart(2, "0");
|
|
1291
|
+
let i;
|
|
1292
|
+
t.year > 9999n ? i = "+" + t.year : t.year < 0n ? i = "-" + String(-t.year).padStart(4, "0") : i = String(t.year).padStart(4, "0");
|
|
1293
|
+
let r = "";
|
|
1294
|
+
return this.nanos !== 0 && (this.nanos % 1e6 === 0 ? r = "." + String(this.nanos / 1e6).padStart(3, "0") : this.nanos % 1e3 === 0 ? r = "." + String(this.nanos / 1e3).padStart(6, "0") : r = "." + String(this.nanos).padStart(9, "0")), `${i}-${n(t.month)}-${n(t.day)}T${n(t.hour)}:${n(t.minute)}:${n(t.second)}${r}Z`;
|
|
787
1295
|
}
|
|
788
|
-
|
|
1296
|
+
};
|
|
1297
|
+
M.MIN_SECONDS = -31557014167219200n, M.MAX_SECONDS = 31556889864403199n;
|
|
1298
|
+
let A = M, qe = 0;
|
|
1299
|
+
const Vt = /* @__PURE__ */ new WeakMap();
|
|
1300
|
+
let Fe = 0;
|
|
1301
|
+
function Zt(e) {
|
|
1302
|
+
let t = Vt.get(e);
|
|
1303
|
+
return t === void 0 && (t = ++Fe, Vt.set(e, t)), t;
|
|
789
1304
|
}
|
|
790
|
-
function
|
|
791
|
-
return
|
|
1305
|
+
function je(e) {
|
|
1306
|
+
return Number.isNaN(e) ? `nan:${++qe}` : e === 0 ? "n:0" : Number.isInteger(e) ? `n:${BigInt(e)}` : `n:${e}`;
|
|
792
1307
|
}
|
|
793
|
-
function
|
|
794
|
-
|
|
1308
|
+
function G(e) {
|
|
1309
|
+
if (e == null)
|
|
1310
|
+
return "z";
|
|
1311
|
+
switch (typeof e) {
|
|
1312
|
+
case "boolean":
|
|
1313
|
+
return e ? "b:1" : "b:0";
|
|
1314
|
+
case "string":
|
|
1315
|
+
return `s${e.length}:${e}`;
|
|
1316
|
+
case "bigint":
|
|
1317
|
+
return `n:${e}`;
|
|
1318
|
+
case "number":
|
|
1319
|
+
return je(e);
|
|
1320
|
+
case "object":
|
|
1321
|
+
break;
|
|
1322
|
+
default:
|
|
1323
|
+
return `o:${Zt(e)}`;
|
|
1324
|
+
}
|
|
1325
|
+
if (B(e))
|
|
1326
|
+
return `y:${yt(e)}`;
|
|
1327
|
+
if (Array.isArray(e))
|
|
1328
|
+
return `[${e.map(G).join(",")}]`;
|
|
1329
|
+
if (e instanceof Map) {
|
|
1330
|
+
const n = Array.from(
|
|
1331
|
+
e.entries(),
|
|
1332
|
+
([i, r]) => `${G(i)}=${G(r)}`
|
|
1333
|
+
);
|
|
1334
|
+
return n.sort(), `{${n.join(",")}}`;
|
|
1335
|
+
}
|
|
1336
|
+
if (e instanceof A)
|
|
1337
|
+
return `t:${e.seconds}.${e.nanos}`;
|
|
1338
|
+
if (e instanceof I)
|
|
1339
|
+
return `d:${e.seconds}.${e.nanos}`;
|
|
1340
|
+
if (e instanceof y)
|
|
1341
|
+
return `T:${e.name}`;
|
|
1342
|
+
const t = Object.getPrototypeOf(e);
|
|
1343
|
+
if (t === Object.prototype || t === null) {
|
|
1344
|
+
const n = Object.entries(e).map(
|
|
1345
|
+
([i, r]) => `${G(i)}=${G(r)}`
|
|
1346
|
+
);
|
|
1347
|
+
return n.sort(), `{${n.join(",")}}`;
|
|
1348
|
+
}
|
|
1349
|
+
return `o:${Zt(e)}`;
|
|
795
1350
|
}
|
|
796
|
-
|
|
797
|
-
|
|
1351
|
+
class sn {
|
|
1352
|
+
constructor() {
|
|
1353
|
+
this.keys = /* @__PURE__ */ new Set();
|
|
1354
|
+
}
|
|
1355
|
+
/** Adds the value; returns true if it was not already present. */
|
|
1356
|
+
add(t) {
|
|
1357
|
+
const n = G(t);
|
|
1358
|
+
return this.keys.has(n) ? !1 : (this.keys.add(n), !0);
|
|
1359
|
+
}
|
|
1360
|
+
has(t) {
|
|
1361
|
+
return this.keys.has(G(t));
|
|
1362
|
+
}
|
|
1363
|
+
get size() {
|
|
1364
|
+
return this.keys.size;
|
|
1365
|
+
}
|
|
798
1366
|
}
|
|
799
|
-
|
|
800
|
-
|
|
1367
|
+
class Qe {
|
|
1368
|
+
constructor() {
|
|
1369
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
1370
|
+
}
|
|
1371
|
+
set(t, n) {
|
|
1372
|
+
this.entries.set(G(t), n);
|
|
1373
|
+
}
|
|
1374
|
+
get(t) {
|
|
1375
|
+
return this.entries.get(G(t));
|
|
1376
|
+
}
|
|
1377
|
+
has(t) {
|
|
1378
|
+
return this.entries.has(G(t));
|
|
1379
|
+
}
|
|
1380
|
+
get size() {
|
|
1381
|
+
return this.entries.size;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
function Jt(e) {
|
|
1385
|
+
return V(e, /* @__PURE__ */ new Set(), !0);
|
|
1386
|
+
}
|
|
1387
|
+
function bt(e) {
|
|
1388
|
+
return V(e, /* @__PURE__ */ new Set(), !1);
|
|
801
1389
|
}
|
|
802
|
-
function
|
|
1390
|
+
function H(e) {
|
|
1391
|
+
if (typeof e != "object" || e === null)
|
|
1392
|
+
return !1;
|
|
1393
|
+
const t = Object.getPrototypeOf(e);
|
|
1394
|
+
return t === Object.prototype || t === null;
|
|
1395
|
+
}
|
|
1396
|
+
function V(e, t, n) {
|
|
1397
|
+
switch (typeof e) {
|
|
1398
|
+
case "undefined":
|
|
1399
|
+
return null;
|
|
1400
|
+
case "number":
|
|
1401
|
+
return n && Number.isInteger(e) ? BigInt(e) : e;
|
|
1402
|
+
case "bigint":
|
|
1403
|
+
case "string":
|
|
1404
|
+
case "boolean":
|
|
1405
|
+
return e;
|
|
1406
|
+
case "object":
|
|
1407
|
+
break;
|
|
1408
|
+
default:
|
|
1409
|
+
return e;
|
|
1410
|
+
}
|
|
1411
|
+
return e === null ? null : e instanceof Uint8Array || e instanceof A || e instanceof I || e instanceof y ? e : e instanceof Date ? A.fromDate(e) : Array.isArray(e) ? mt(e, t, () => e.map((i) => V(i, t, n))) : e instanceof Map ? mt(e, t, () => {
|
|
1412
|
+
const i = /* @__PURE__ */ new Map();
|
|
1413
|
+
for (const [r, s] of e)
|
|
1414
|
+
i.set(V(r, t, n), V(s, t, n));
|
|
1415
|
+
return i;
|
|
1416
|
+
}) : H(e) ? mt(e, t, () => {
|
|
1417
|
+
const i = /* @__PURE__ */ new Map();
|
|
1418
|
+
for (const [r, s] of Object.entries(e))
|
|
1419
|
+
i.set(r, V(s, t, n));
|
|
1420
|
+
return i;
|
|
1421
|
+
}) : e;
|
|
1422
|
+
}
|
|
1423
|
+
function mt(e, t, n) {
|
|
1424
|
+
if (t.has(e))
|
|
1425
|
+
throw new a("Cyclic value");
|
|
1426
|
+
t.add(e);
|
|
803
1427
|
try {
|
|
804
|
-
return
|
|
805
|
-
}
|
|
806
|
-
|
|
1428
|
+
return n();
|
|
1429
|
+
} finally {
|
|
1430
|
+
t.delete(e);
|
|
807
1431
|
}
|
|
808
1432
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
return
|
|
1433
|
+
const D = 1e6, ze = I.SPAN, Ye = /^[+-]?\d+$/, _e = /^[+-]?(?:\d+\.?\d*(?:[eE][+-]?\d+)?|\.\d+(?:[eE][+-]?\d+)?|Infinity|NaN)$/;
|
|
1434
|
+
function q(e, t) {
|
|
1435
|
+
if (e > D)
|
|
1436
|
+
throw new l(`${t} exceeds the evaluation limit of ${D}`);
|
|
1437
|
+
}
|
|
1438
|
+
function We(e) {
|
|
1439
|
+
return e instanceof Map;
|
|
816
1440
|
}
|
|
817
|
-
function
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1441
|
+
function ht(e) {
|
|
1442
|
+
let t = 0;
|
|
1443
|
+
for (let n = 0; n < e.length; n++) {
|
|
1444
|
+
const i = e.charCodeAt(n);
|
|
1445
|
+
if (i >= 55296 && i <= 56319 && n + 1 < e.length) {
|
|
1446
|
+
const r = e.charCodeAt(n + 1);
|
|
1447
|
+
r >= 56320 && r <= 57343 && n++;
|
|
1448
|
+
}
|
|
1449
|
+
t++;
|
|
1450
|
+
}
|
|
823
1451
|
return t;
|
|
824
1452
|
}
|
|
825
|
-
function
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
1453
|
+
function Tt(e, t) {
|
|
1454
|
+
let n = 0;
|
|
1455
|
+
for (let i = t; i > 0; i--) {
|
|
1456
|
+
if (n >= e.length)
|
|
1457
|
+
return -1;
|
|
1458
|
+
const r = e.charCodeAt(n);
|
|
1459
|
+
if (r >= 55296 && r <= 56319 && n + 1 < e.length) {
|
|
1460
|
+
const s = e.charCodeAt(n + 1);
|
|
1461
|
+
n += s >= 56320 && s <= 57343 ? 2 : 1;
|
|
1462
|
+
} else
|
|
1463
|
+
n++;
|
|
1464
|
+
}
|
|
1465
|
+
return n > e.length ? -1 : n;
|
|
1466
|
+
}
|
|
1467
|
+
function Lt(e) {
|
|
1468
|
+
if (e == null)
|
|
1469
|
+
return 0n;
|
|
1470
|
+
if (typeof e == "string")
|
|
1471
|
+
return BigInt(ht(e));
|
|
1472
|
+
if (B(e) || Array.isArray(e))
|
|
1473
|
+
return BigInt(e.length);
|
|
1474
|
+
if (e instanceof Map)
|
|
1475
|
+
return BigInt(e.size);
|
|
1476
|
+
if (H(e))
|
|
1477
|
+
return BigInt(Object.keys(e).length);
|
|
1478
|
+
throw new a(`size() not supported for type: ${W(e)}`);
|
|
1479
|
+
}
|
|
1480
|
+
function g(e) {
|
|
1481
|
+
if (typeof e == "bigint")
|
|
1482
|
+
return e;
|
|
1483
|
+
if (typeof e == "number")
|
|
1484
|
+
return Se(e);
|
|
1485
|
+
if (typeof e == "string") {
|
|
1486
|
+
if (Ye.test(e.trim()) && e.trim() === e) {
|
|
1487
|
+
const t = BigInt(e);
|
|
1488
|
+
if (t >= K && t <= at)
|
|
1489
|
+
return t;
|
|
844
1490
|
}
|
|
845
|
-
|
|
1491
|
+
throw new a(`Cannot convert to int: ${e}`);
|
|
846
1492
|
}
|
|
847
|
-
|
|
1493
|
+
if (typeof e == "boolean")
|
|
1494
|
+
return e ? 1n : 0n;
|
|
1495
|
+
if (e instanceof A)
|
|
1496
|
+
return e.seconds;
|
|
1497
|
+
throw new a(`Cannot convert to int: ${O(e)}`);
|
|
1498
|
+
}
|
|
1499
|
+
function on(e) {
|
|
1500
|
+
const t = g(e);
|
|
1501
|
+
if (t < 0n)
|
|
1502
|
+
throw new a(`Cannot convert negative value to uint: ${O(e)}`);
|
|
1503
|
+
return t;
|
|
1504
|
+
}
|
|
1505
|
+
function T(e) {
|
|
1506
|
+
if (typeof e == "number")
|
|
1507
|
+
return e;
|
|
1508
|
+
if (typeof e == "bigint")
|
|
1509
|
+
return Number(e);
|
|
1510
|
+
if (typeof e == "string") {
|
|
1511
|
+
const t = e.trim();
|
|
1512
|
+
if (_e.test(t))
|
|
1513
|
+
return Number(t);
|
|
1514
|
+
throw new a(`Cannot convert to double: ${e}`);
|
|
1515
|
+
}
|
|
1516
|
+
throw new a(`Cannot convert to double: ${O(e)}`);
|
|
1517
|
+
}
|
|
1518
|
+
function O(e) {
|
|
1519
|
+
return e == null ? "null" : typeof e == "string" ? e : typeof e == "number" ? rn(e) : typeof e == "bigint" || typeof e == "boolean" ? String(e) : B(e) ? en(e) : Array.isArray(e) ? `[${e.map(O).join(", ")}]` : e instanceof Map ? `{${Array.from(e, ([t, n]) => `${O(t)}=${O(n)}`).join(", ")}}` : H(e) ? `{${Object.entries(e).map(([t, n]) => `${t}=${O(n)}`).join(", ")}}` : String(e);
|
|
1520
|
+
}
|
|
1521
|
+
function ft(e) {
|
|
1522
|
+
if (B(e))
|
|
1523
|
+
return e;
|
|
1524
|
+
if (typeof e == "string")
|
|
1525
|
+
return Mt(e);
|
|
1526
|
+
throw new a(`Cannot convert to bytes: ${O(e)}`);
|
|
1527
|
+
}
|
|
1528
|
+
function cn(e) {
|
|
1529
|
+
return typeof e == "boolean" ? e : typeof e == "bigint" ? e !== 0n : typeof e == "number" ? e !== 0 : typeof e == "string" || Array.isArray(e) ? e.length > 0 : e instanceof Map ? e.size > 0 : H(e) ? Object.keys(e).length > 0 : e != null;
|
|
1530
|
+
}
|
|
1531
|
+
function W(e) {
|
|
1532
|
+
if (e == null)
|
|
1533
|
+
return y.NULL;
|
|
1534
|
+
switch (typeof e) {
|
|
1535
|
+
case "boolean":
|
|
1536
|
+
return y.BOOL;
|
|
1537
|
+
case "bigint":
|
|
1538
|
+
return y.INT;
|
|
1539
|
+
case "number":
|
|
1540
|
+
return y.DOUBLE;
|
|
1541
|
+
case "string":
|
|
1542
|
+
return y.STRING;
|
|
1543
|
+
case "object":
|
|
1544
|
+
break;
|
|
1545
|
+
default:
|
|
1546
|
+
return y.UNKNOWN;
|
|
1547
|
+
}
|
|
1548
|
+
return B(e) ? y.BYTES : e instanceof A ? y.TIMESTAMP : e instanceof I ? y.DURATION : Array.isArray(e) ? y.LIST : e instanceof Map || H(e) ? y.MAP : e instanceof y ? y.TYPE : y.UNKNOWN;
|
|
1549
|
+
}
|
|
1550
|
+
function un(e, t) {
|
|
1551
|
+
return e instanceof Map ? ot(e, t) : H(e) ? typeof t == "string" && Object.prototype.hasOwnProperty.call(e, t) : !1;
|
|
1552
|
+
}
|
|
1553
|
+
function ot(e, t) {
|
|
1554
|
+
if (e.has(t))
|
|
1555
|
+
return !0;
|
|
1556
|
+
for (const n of e.keys())
|
|
1557
|
+
if (j(n, t))
|
|
1558
|
+
return !0;
|
|
1559
|
+
return !1;
|
|
1560
|
+
}
|
|
1561
|
+
function an(e, t) {
|
|
1562
|
+
if (e.has(t))
|
|
1563
|
+
return e.get(t);
|
|
1564
|
+
for (const [n, i] of e)
|
|
1565
|
+
if (j(n, t))
|
|
1566
|
+
return i;
|
|
1567
|
+
}
|
|
1568
|
+
function St(e, t) {
|
|
1569
|
+
let n;
|
|
1570
|
+
try {
|
|
1571
|
+
n = new RegExp(t);
|
|
1572
|
+
} catch {
|
|
1573
|
+
throw new a(`Invalid regular expression: ${t}`);
|
|
1574
|
+
}
|
|
1575
|
+
return n.test(e);
|
|
1576
|
+
}
|
|
1577
|
+
function Dt(e) {
|
|
1578
|
+
if (e == null)
|
|
1579
|
+
return A.now();
|
|
1580
|
+
if (e instanceof A)
|
|
1581
|
+
return e;
|
|
1582
|
+
if (e instanceof Date)
|
|
1583
|
+
return A.fromDate(e);
|
|
1584
|
+
if (typeof e == "string")
|
|
1585
|
+
return A.parse(e);
|
|
1586
|
+
if (typeof e == "bigint")
|
|
1587
|
+
return A.ofEpochSeconds(e);
|
|
1588
|
+
throw new a(`Invalid timestamp value: ${O(e)}`);
|
|
1589
|
+
}
|
|
1590
|
+
function Ke(e) {
|
|
1591
|
+
return I.parse(e);
|
|
1592
|
+
}
|
|
1593
|
+
function hn(e) {
|
|
1594
|
+
if (e instanceof I)
|
|
1595
|
+
return e;
|
|
1596
|
+
if (typeof e == "string")
|
|
1597
|
+
return I.parse(e);
|
|
1598
|
+
throw new a(`Cannot convert to duration: ${O(e)}`);
|
|
848
1599
|
}
|
|
849
|
-
function
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1600
|
+
function Q(e, t) {
|
|
1601
|
+
const n = e instanceof A ? e : Dt(e);
|
|
1602
|
+
return { instant: n, fields: De(n.seconds, t ?? null) };
|
|
1603
|
+
}
|
|
1604
|
+
function fn(e, t = null) {
|
|
1605
|
+
return BigInt(Q(e, t).fields.day);
|
|
1606
|
+
}
|
|
1607
|
+
function ln(e, t = null) {
|
|
1608
|
+
return BigInt(Q(e, t).fields.month - 1);
|
|
1609
|
+
}
|
|
1610
|
+
function pn(e, t = null) {
|
|
1611
|
+
return Q(e, t).fields.year;
|
|
1612
|
+
}
|
|
1613
|
+
function dn(e, t = null) {
|
|
1614
|
+
return e instanceof I ? e.toHours() : BigInt(Q(e, t).fields.hour);
|
|
1615
|
+
}
|
|
1616
|
+
function wn(e, t = null) {
|
|
1617
|
+
return e instanceof I ? e.toMinutes() : BigInt(Q(e, t).fields.minute);
|
|
1618
|
+
}
|
|
1619
|
+
function gn(e, t = null) {
|
|
1620
|
+
return e instanceof I ? e.toSeconds() : BigInt(Q(e, t).fields.second);
|
|
1621
|
+
}
|
|
1622
|
+
function bn(e, t = null) {
|
|
1623
|
+
return e instanceof I ? e.toMillis() : BigInt(Math.floor(Q(e, t).instant.nanos / 1e6));
|
|
1624
|
+
}
|
|
1625
|
+
function mn(e, t = null) {
|
|
1626
|
+
return BigInt(Q(e, t).fields.weekday);
|
|
1627
|
+
}
|
|
1628
|
+
function En(e, t = null) {
|
|
1629
|
+
return BigInt(Q(e, t).fields.dayOfYear - 1);
|
|
1630
|
+
}
|
|
1631
|
+
function xt(e) {
|
|
1632
|
+
if (e.length === 0)
|
|
1633
|
+
throw new a("max() requires at least one argument");
|
|
1634
|
+
let t = e[0];
|
|
1635
|
+
for (let n = 1; n < e.length; n++)
|
|
1636
|
+
v(e[n], t) > 0 && (t = e[n]);
|
|
1637
|
+
return t;
|
|
1638
|
+
}
|
|
1639
|
+
function kt(e) {
|
|
1640
|
+
if (e.length === 0)
|
|
1641
|
+
throw new a("min() requires at least one argument");
|
|
1642
|
+
let t = e[0];
|
|
1643
|
+
for (let n = 1; n < e.length; n++)
|
|
1644
|
+
v(e[n], t) < 0 && (t = e[n]);
|
|
1645
|
+
return t;
|
|
1646
|
+
}
|
|
1647
|
+
function j(e, t) {
|
|
1648
|
+
if (e == null || t === null || t === void 0)
|
|
1649
|
+
return (e ?? null) === (t ?? null);
|
|
1650
|
+
if (B(e) && B(t))
|
|
1651
|
+
return Ae(e, t);
|
|
1652
|
+
if (Array.isArray(e) && Array.isArray(t)) {
|
|
1653
|
+
if (e.length !== t.length)
|
|
854
1654
|
return !1;
|
|
855
|
-
for (let
|
|
856
|
-
if (!
|
|
1655
|
+
for (let r = 0; r < e.length; r++)
|
|
1656
|
+
if (!j(e[r], t[r]))
|
|
857
1657
|
return !1;
|
|
858
1658
|
return !0;
|
|
859
1659
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
if (
|
|
1660
|
+
const n = vt(e), i = vt(t);
|
|
1661
|
+
if (n && i) {
|
|
1662
|
+
if (n.size !== i.size)
|
|
863
1663
|
return !1;
|
|
864
|
-
|
|
865
|
-
|
|
1664
|
+
const r = new Qe();
|
|
1665
|
+
for (const [s, c] of i)
|
|
1666
|
+
r.set(s, c);
|
|
1667
|
+
for (const [s, c] of n)
|
|
1668
|
+
if (!r.has(s) || !j(c, r.get(s)))
|
|
866
1669
|
return !1;
|
|
867
1670
|
return !0;
|
|
868
1671
|
}
|
|
869
|
-
return
|
|
1672
|
+
return (typeof e == "bigint" || typeof e == "number") && (typeof t == "bigint" || typeof t == "number") ? Number.isNaN(e) || Number.isNaN(t) ? !1 : Ct(e, t) === 0 : e instanceof A || e instanceof I || e instanceof y ? e.equals(t) : e === t;
|
|
870
1673
|
}
|
|
871
|
-
function
|
|
872
|
-
|
|
873
|
-
|
|
1674
|
+
function vt(e) {
|
|
1675
|
+
return e instanceof Map ? e : H(e) ? new Map(Object.entries(e)) : null;
|
|
1676
|
+
}
|
|
1677
|
+
const He = j;
|
|
1678
|
+
function v(e, t) {
|
|
1679
|
+
if ((typeof e == "bigint" || typeof e == "number") && (typeof t == "bigint" || typeof t == "number"))
|
|
1680
|
+
return Ct(e, t);
|
|
1681
|
+
if (typeof e == "string" && typeof t == "string")
|
|
1682
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
1683
|
+
if (typeof e == "boolean" && typeof t == "boolean")
|
|
1684
|
+
return e === t ? 0 : e ? 1 : -1;
|
|
1685
|
+
if (e instanceof A && t instanceof A || e instanceof I && t instanceof I)
|
|
1686
|
+
return e.compareTo(t);
|
|
1687
|
+
if (B(e) && B(t))
|
|
1688
|
+
return ye(e, t);
|
|
1689
|
+
throw new a("Cannot compare values of different types");
|
|
1690
|
+
}
|
|
1691
|
+
function lt(e, t) {
|
|
1692
|
+
for (const n of e)
|
|
1693
|
+
if (j(n, t))
|
|
874
1694
|
return !0;
|
|
875
1695
|
return !1;
|
|
876
1696
|
}
|
|
877
|
-
const
|
|
1697
|
+
const pi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
878
1698
|
__proto__: null,
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1699
|
+
LIMIT: D,
|
|
1700
|
+
SPAN: ze,
|
|
1701
|
+
asBool: cn,
|
|
1702
|
+
asBytes: ft,
|
|
1703
|
+
asDouble: T,
|
|
1704
|
+
asDuration: hn,
|
|
1705
|
+
asInt: g,
|
|
1706
|
+
asString: O,
|
|
1707
|
+
asUInt: on,
|
|
1708
|
+
codePointCount: ht,
|
|
1709
|
+
compare: v,
|
|
1710
|
+
contains: ot,
|
|
1711
|
+
containsInArray: lt,
|
|
1712
|
+
dateOf: fn,
|
|
1713
|
+
deepEquals: He,
|
|
1714
|
+
duration: Ke,
|
|
1715
|
+
equals: j,
|
|
1716
|
+
has: un,
|
|
1717
|
+
hoursOf: dn,
|
|
1718
|
+
isMap: We,
|
|
1719
|
+
limit: q,
|
|
1720
|
+
matches: St,
|
|
1721
|
+
max: xt,
|
|
1722
|
+
millisecondsOf: bn,
|
|
1723
|
+
min: kt,
|
|
1724
|
+
minutesOf: wn,
|
|
1725
|
+
monthOf: ln,
|
|
1726
|
+
offsetByCodePoints: Tt,
|
|
1727
|
+
order: Ct,
|
|
1728
|
+
ordinalOf: En,
|
|
1729
|
+
secondsOf: gn,
|
|
1730
|
+
select: an,
|
|
1731
|
+
sizeOf: Lt,
|
|
1732
|
+
timestamp: Dt,
|
|
1733
|
+
typeOf: W,
|
|
1734
|
+
weekdayOf: mn,
|
|
1735
|
+
yearOf: pn
|
|
893
1736
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
894
|
-
|
|
895
|
-
|
|
1737
|
+
function Z(e, t, n) {
|
|
1738
|
+
if (t < 0n || t > BigInt(ht(e)))
|
|
1739
|
+
throw new a(`${n}() index out of range: ${t}`);
|
|
1740
|
+
return Tt(e, Number(t));
|
|
1741
|
+
}
|
|
1742
|
+
function Ot(e, t) {
|
|
1743
|
+
return t < 0 ? -1n : BigInt(ht(e.substring(0, t)));
|
|
1744
|
+
}
|
|
1745
|
+
function In(e, t) {
|
|
1746
|
+
const n = Z(e, t, "charAt");
|
|
1747
|
+
return n === e.length ? "" : String.fromCodePoint(e.codePointAt(n));
|
|
1748
|
+
}
|
|
1749
|
+
function An(e, t, n = 0n) {
|
|
1750
|
+
return Ot(e, e.indexOf(t, Z(e, n, "indexOf")));
|
|
1751
|
+
}
|
|
1752
|
+
function yn(e, t, n) {
|
|
1753
|
+
return n === void 0 ? Ot(e, e.lastIndexOf(t)) : Ot(e, e.lastIndexOf(t, Z(e, n, "lastIndexOf")));
|
|
1754
|
+
}
|
|
1755
|
+
function Nn(e) {
|
|
1756
|
+
return e.replace(/[A-Z]/g, (t) => String.fromCharCode(t.charCodeAt(0) + 32));
|
|
1757
|
+
}
|
|
1758
|
+
function Ln(e) {
|
|
1759
|
+
return e.replace(/[a-z]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 32));
|
|
1760
|
+
}
|
|
1761
|
+
function Sn(e, t, n) {
|
|
1762
|
+
if (n === void 0)
|
|
1763
|
+
return e.substring(Z(e, t, "substring"));
|
|
1764
|
+
if (t > n)
|
|
1765
|
+
throw new a(`substring() range out of bounds: ${t}:${n}`);
|
|
1766
|
+
return e.substring(Z(e, t, "substring"), Z(e, n, "substring"));
|
|
1767
|
+
}
|
|
1768
|
+
function On(e) {
|
|
1769
|
+
return Array.from(e).reverse().join("");
|
|
1770
|
+
}
|
|
1771
|
+
function $n(e, t, n, i = -1n) {
|
|
1772
|
+
if (i === 0n || t === "")
|
|
1773
|
+
return e;
|
|
1774
|
+
let r = "", s = 0, c = 0n;
|
|
1775
|
+
for (; i < 0n || c < i; ) {
|
|
1776
|
+
const u = e.indexOf(t, s);
|
|
1777
|
+
if (u < 0)
|
|
1778
|
+
break;
|
|
1779
|
+
r += e.substring(s, u) + n, q(r.length, "replace()"), s = u + t.length, c++;
|
|
1780
|
+
}
|
|
1781
|
+
return r += e.substring(s), q(r.length, "replace()"), r;
|
|
1782
|
+
}
|
|
1783
|
+
function Rn(e, t, n = -1n) {
|
|
1784
|
+
if (n === 0n)
|
|
1785
|
+
return [];
|
|
1786
|
+
let i;
|
|
1787
|
+
if (t === "" ? i = e === "" ? [""] : [...e.split(""), ""] : i = e.split(t), n > 0n && BigInt(i.length) > n) {
|
|
1788
|
+
const r = Number(n) - 1;
|
|
1789
|
+
i = [...i.slice(0, r), i.slice(r).join(t)];
|
|
1790
|
+
}
|
|
1791
|
+
return i;
|
|
1792
|
+
}
|
|
1793
|
+
function Mn(e, t) {
|
|
1794
|
+
let n = Math.max(0, e.length - 1) * t.length;
|
|
1795
|
+
for (const r of e) {
|
|
1796
|
+
if (typeof r != "string")
|
|
1797
|
+
throw new a("join() requires a list of strings");
|
|
1798
|
+
n += r.length, q(n, "join()");
|
|
1799
|
+
}
|
|
1800
|
+
let i = "";
|
|
1801
|
+
for (const r of e)
|
|
1802
|
+
i.length > 0 && (i += t), i += r;
|
|
1803
|
+
return i;
|
|
1804
|
+
}
|
|
1805
|
+
function Cn(e, t) {
|
|
1806
|
+
let n = "", i = 0, r = 0;
|
|
1807
|
+
for (; r < e.length; ) {
|
|
1808
|
+
const s = e[r];
|
|
1809
|
+
if (s !== "%") {
|
|
1810
|
+
n += s, r++;
|
|
1811
|
+
continue;
|
|
1812
|
+
}
|
|
1813
|
+
if (r + 1 >= e.length)
|
|
1814
|
+
throw new a("format() has a trailing '%'");
|
|
1815
|
+
if (e[r + 1] === "%") {
|
|
1816
|
+
n += "%", r += 2;
|
|
1817
|
+
continue;
|
|
1818
|
+
}
|
|
1819
|
+
let c = -1, u = r + 1;
|
|
1820
|
+
if (e[u] === ".") {
|
|
1821
|
+
u++;
|
|
1822
|
+
const d = u;
|
|
1823
|
+
for (; u < e.length && e[u] >= "0" && e[u] <= "9"; )
|
|
1824
|
+
u++;
|
|
1825
|
+
if (u === d)
|
|
1826
|
+
throw new a("format() precision requires digits");
|
|
1827
|
+
c = Xe(e.substring(d, u));
|
|
1828
|
+
}
|
|
1829
|
+
if (u >= e.length)
|
|
1830
|
+
throw new a("format() has an incomplete verb");
|
|
1831
|
+
if (i >= t.length)
|
|
1832
|
+
throw new a("format() has more verbs than arguments");
|
|
1833
|
+
if (n += Ve(e[u], c, t[i]), n.length > D)
|
|
1834
|
+
throw new l(
|
|
1835
|
+
`format() output exceeds the evaluation limit of ${D}`
|
|
1836
|
+
);
|
|
1837
|
+
i++, r = u + 1;
|
|
1838
|
+
}
|
|
1839
|
+
if (i !== t.length)
|
|
1840
|
+
throw new a("format() has more arguments than verbs");
|
|
1841
|
+
return n;
|
|
1842
|
+
}
|
|
1843
|
+
function Xe(e) {
|
|
1844
|
+
const t = e.length > 18 ? 1 / 0 : Number(e);
|
|
1845
|
+
if (t > D)
|
|
1846
|
+
throw new l(
|
|
1847
|
+
`format() precision exceeds the evaluation limit of ${D}`
|
|
1848
|
+
);
|
|
1849
|
+
return t;
|
|
1850
|
+
}
|
|
1851
|
+
function Ve(e, t, n) {
|
|
1852
|
+
switch (e) {
|
|
1853
|
+
case "s":
|
|
1854
|
+
return O(n);
|
|
1855
|
+
case "d":
|
|
1856
|
+
return g(n).toString();
|
|
1857
|
+
case "f":
|
|
1858
|
+
return ct(T(n), t < 0 ? 6 : t);
|
|
1859
|
+
case "e":
|
|
1860
|
+
return Ze(T(n), t < 0 ? 6 : t);
|
|
1861
|
+
case "b":
|
|
1862
|
+
return typeof n == "boolean" ? String(n) : $t(g(n), 2);
|
|
1863
|
+
case "o":
|
|
1864
|
+
return $t(g(n), 8);
|
|
1865
|
+
case "x":
|
|
1866
|
+
return tn(n, !1);
|
|
1867
|
+
case "X":
|
|
1868
|
+
return tn(n, !0);
|
|
1869
|
+
default:
|
|
1870
|
+
throw new a(`format() has an unknown verb: %${e}`);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
function $t(e, t) {
|
|
1874
|
+
return BigInt.asUintN(64, e).toString(t);
|
|
1875
|
+
}
|
|
1876
|
+
function ct(e, t) {
|
|
1877
|
+
if (!Number.isFinite(e))
|
|
1878
|
+
throw new a(`Cannot format non-finite value: ${e}`);
|
|
1879
|
+
const n = e < 0, [i, r] = Math.abs(e).toExponential().split("e"), s = i.replace(".", ""), c = s.length - 1 - Number(r);
|
|
1880
|
+
let u = BigInt(s);
|
|
1881
|
+
if (c <= t)
|
|
1882
|
+
u *= 10n ** BigInt(t - c);
|
|
1883
|
+
else {
|
|
1884
|
+
const L = 10n ** BigInt(c - t), k = u / L;
|
|
1885
|
+
u = u % L * 2n >= L ? k + 1n : k;
|
|
1886
|
+
}
|
|
1887
|
+
const d = u.toString().padStart(t + 1, "0"), E = d.substring(0, d.length - t), b = d.substring(d.length - t), N = t > 0 ? `${E}.${b}` : E;
|
|
1888
|
+
return n && u !== 0n ? `-${N}` : N;
|
|
1889
|
+
}
|
|
1890
|
+
function Ze(e, t) {
|
|
1891
|
+
if (e === 0)
|
|
1892
|
+
return ct(0, t) + "e+00";
|
|
1893
|
+
if (!Number.isFinite(e))
|
|
1894
|
+
throw new a(`Cannot format non-finite value: ${e}`);
|
|
1895
|
+
const n = Math.floor(Math.log10(Math.abs(e))), i = e / Math.pow(10, n), r = n < 0 ? "-" : "+", s = Math.abs(n);
|
|
1896
|
+
return `${ct(i, t)}e${r}${s < 10 ? "0" : ""}${s}`;
|
|
1897
|
+
}
|
|
1898
|
+
function tn(e, t) {
|
|
1899
|
+
let n;
|
|
1900
|
+
return B(e) ? n = yt(e) : typeof e == "string" ? n = yt(Mt(e)) : n = $t(g(e), 16), t ? n.toUpperCase() : n;
|
|
1901
|
+
}
|
|
1902
|
+
function Un(e) {
|
|
1903
|
+
let t = "";
|
|
1904
|
+
for (let n = 0; n < e.length; n++) {
|
|
1905
|
+
const i = e[n], r = e.charCodeAt(n);
|
|
1906
|
+
switch (i) {
|
|
1907
|
+
case "\\":
|
|
1908
|
+
t += "\\\\";
|
|
1909
|
+
break;
|
|
1910
|
+
case '"':
|
|
1911
|
+
t += '\\"';
|
|
1912
|
+
break;
|
|
1913
|
+
case `
|
|
1914
|
+
`:
|
|
1915
|
+
t += "\\n";
|
|
1916
|
+
break;
|
|
1917
|
+
case "\r":
|
|
1918
|
+
t += "\\r";
|
|
1919
|
+
break;
|
|
1920
|
+
case " ":
|
|
1921
|
+
t += "\\t";
|
|
1922
|
+
break;
|
|
1923
|
+
case "\b":
|
|
1924
|
+
t += "\\b";
|
|
1925
|
+
break;
|
|
1926
|
+
case "\f":
|
|
1927
|
+
t += "\\f";
|
|
1928
|
+
break;
|
|
1929
|
+
case "\x07":
|
|
1930
|
+
t += "\\a";
|
|
1931
|
+
break;
|
|
1932
|
+
case "\v":
|
|
1933
|
+
t += "\\v";
|
|
1934
|
+
break;
|
|
1935
|
+
default:
|
|
1936
|
+
r < 32 || r === 127 ? t += "\\u" + r.toString(16).padStart(4, "0") : t += i;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
return t;
|
|
1940
|
+
}
|
|
1941
|
+
function Pt(e) {
|
|
1942
|
+
return `"${Un(e)}"`;
|
|
1943
|
+
}
|
|
1944
|
+
function Bn(e) {
|
|
1945
|
+
let t = "";
|
|
1946
|
+
for (const n of e)
|
|
1947
|
+
switch (n) {
|
|
1948
|
+
case 92:
|
|
1949
|
+
t += "\\\\";
|
|
1950
|
+
break;
|
|
1951
|
+
case 34:
|
|
1952
|
+
t += '\\"';
|
|
1953
|
+
break;
|
|
1954
|
+
case 10:
|
|
1955
|
+
t += "\\n";
|
|
1956
|
+
break;
|
|
1957
|
+
case 13:
|
|
1958
|
+
t += "\\r";
|
|
1959
|
+
break;
|
|
1960
|
+
case 9:
|
|
1961
|
+
t += "\\t";
|
|
1962
|
+
break;
|
|
1963
|
+
default:
|
|
1964
|
+
n < 32 || n >= 127 ? t += "\\x" + n.toString(16).padStart(2, "0") : t += String.fromCharCode(n);
|
|
1965
|
+
}
|
|
1966
|
+
return t;
|
|
1967
|
+
}
|
|
1968
|
+
const di = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1969
|
+
__proto__: null,
|
|
1970
|
+
charAt: In,
|
|
1971
|
+
escape: Un,
|
|
1972
|
+
escapeBytes: Bn,
|
|
1973
|
+
fixed: ct,
|
|
1974
|
+
format: Cn,
|
|
1975
|
+
indexOf: An,
|
|
1976
|
+
join: Mn,
|
|
1977
|
+
lastIndexOf: yn,
|
|
1978
|
+
lower: Nn,
|
|
1979
|
+
quote: Pt,
|
|
1980
|
+
replace: $n,
|
|
1981
|
+
reverse: On,
|
|
1982
|
+
split: Rn,
|
|
1983
|
+
substring: Sn,
|
|
1984
|
+
upper: Ln
|
|
1985
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1986
|
+
function pt(e, t) {
|
|
1987
|
+
try {
|
|
1988
|
+
return new RegExp(e, t);
|
|
1989
|
+
} catch {
|
|
1990
|
+
throw new a(`Invalid regular expression: ${e}`);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function dt(e) {
|
|
1994
|
+
return pt(e, ""), new RegExp(`${e}|`).exec("").length - 1;
|
|
1995
|
+
}
|
|
1996
|
+
function Tn(e, t, n, i = -1n) {
|
|
1997
|
+
const r = pt(t, "g"), s = Je(n, dt(t), t);
|
|
1998
|
+
let c = "", u = 0, d = 0n, E;
|
|
1999
|
+
for (; (E = r.exec(e)) !== null && !(i >= 0n && d >= i); )
|
|
2000
|
+
c += e.substring(u, E.index) + ve(s, E), q(c.length, "regex.replace()"), u = E.index + E[0].length, E[0].length === 0 && r.lastIndex++, d++;
|
|
2001
|
+
return c += e.substring(u), q(c.length, "regex.replace()"), c;
|
|
2002
|
+
}
|
|
2003
|
+
function Dn(e, t) {
|
|
2004
|
+
const n = dt(t);
|
|
2005
|
+
if (n > 1)
|
|
2006
|
+
throw new a(`extract() supports at most one capture group: ${t}`);
|
|
2007
|
+
const i = pt(t, "").exec(e);
|
|
2008
|
+
return i === null ? null : n === 1 ? i[1] ?? null : i[0];
|
|
2009
|
+
}
|
|
2010
|
+
function xn(e, t) {
|
|
2011
|
+
const n = dt(t);
|
|
2012
|
+
if (n > 1)
|
|
2013
|
+
throw new a(`extractAll() supports at most one capture group: ${t}`);
|
|
2014
|
+
const i = pt(t, "g"), r = [];
|
|
2015
|
+
let s;
|
|
2016
|
+
for (; (s = i.exec(e)) !== null; ) {
|
|
2017
|
+
const c = n === 1 ? s[1] : s[0];
|
|
2018
|
+
c !== void 0 && r.push(c), s[0].length === 0 && i.lastIndex++;
|
|
2019
|
+
}
|
|
2020
|
+
return r;
|
|
2021
|
+
}
|
|
2022
|
+
function Je(e, t, n) {
|
|
2023
|
+
const i = [];
|
|
2024
|
+
let r = "", s = 0;
|
|
2025
|
+
for (; s < e.length; ) {
|
|
2026
|
+
const c = e[s];
|
|
2027
|
+
if (c === "\\" && s + 1 < e.length) {
|
|
2028
|
+
const u = e[s + 1];
|
|
2029
|
+
if (u >= "0" && u <= "9") {
|
|
2030
|
+
const d = u.charCodeAt(0) - 48;
|
|
2031
|
+
if (d > t)
|
|
2032
|
+
throw new a(
|
|
2033
|
+
`Replacement refers to group ${d} but ${n} has ${t}`
|
|
2034
|
+
);
|
|
2035
|
+
r.length > 0 && (i.push({ text: r }), r = ""), i.push({ group: d });
|
|
2036
|
+
} else
|
|
2037
|
+
r += "\\" + u;
|
|
2038
|
+
s += 2;
|
|
2039
|
+
} else
|
|
2040
|
+
r += c, s++;
|
|
2041
|
+
}
|
|
2042
|
+
return r.length > 0 && i.push({ text: r }), i;
|
|
2043
|
+
}
|
|
2044
|
+
function ve(e, t) {
|
|
2045
|
+
let n = "";
|
|
2046
|
+
for (const i of e)
|
|
2047
|
+
"text" in i ? n += i.text : n += t[i.group] ?? "";
|
|
2048
|
+
return n;
|
|
2049
|
+
}
|
|
2050
|
+
const wi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2051
|
+
__proto__: null,
|
|
2052
|
+
extract: Dn,
|
|
2053
|
+
extractAll: xn,
|
|
2054
|
+
groupCount: dt,
|
|
2055
|
+
replace: Tn
|
|
2056
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2057
|
+
function kn(e) {
|
|
2058
|
+
const t = new sn(), n = [];
|
|
2059
|
+
for (const i of e)
|
|
2060
|
+
t.add(i) && n.push(i);
|
|
2061
|
+
return n;
|
|
2062
|
+
}
|
|
2063
|
+
function Gt(e, t = 1n) {
|
|
2064
|
+
if (t < 1n)
|
|
2065
|
+
throw new a("flatten() depth must be at least 1");
|
|
2066
|
+
const n = [];
|
|
2067
|
+
for (const i of e)
|
|
2068
|
+
Array.isArray(i) ? n.push(...t > 1n ? Gt(i, t - 1n) : i) : n.push(i);
|
|
2069
|
+
return n;
|
|
2070
|
+
}
|
|
2071
|
+
function Pn(e) {
|
|
2072
|
+
return [...e].reverse();
|
|
2073
|
+
}
|
|
2074
|
+
function Gn(e, t, n) {
|
|
2075
|
+
if (t < 0n || n > BigInt(e.length) || t > n)
|
|
2076
|
+
throw new a(`slice() range out of bounds: ${t}:${n}`);
|
|
2077
|
+
return e.slice(Number(t), Number(n));
|
|
2078
|
+
}
|
|
2079
|
+
function qn(e) {
|
|
2080
|
+
return [...e].sort(v);
|
|
2081
|
+
}
|
|
2082
|
+
function Fn(e) {
|
|
2083
|
+
if (e.length === 0)
|
|
2084
|
+
throw new a("first() requires a non-empty list");
|
|
2085
|
+
return e[0];
|
|
2086
|
+
}
|
|
2087
|
+
function jn(e) {
|
|
2088
|
+
if (e.length === 0)
|
|
2089
|
+
throw new a("last() requires a non-empty list");
|
|
2090
|
+
return e[e.length - 1];
|
|
2091
|
+
}
|
|
2092
|
+
function Qn(e) {
|
|
2093
|
+
if (e > BigInt(D))
|
|
2094
|
+
throw new l(`range() exceeds the evaluation limit of ${D}`);
|
|
2095
|
+
const t = [];
|
|
2096
|
+
for (let n = 0n; n < e; n++)
|
|
2097
|
+
t.push(n);
|
|
2098
|
+
return t;
|
|
2099
|
+
}
|
|
2100
|
+
function ti(e, t) {
|
|
2101
|
+
return lt(e, t);
|
|
2102
|
+
}
|
|
2103
|
+
const gi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2104
|
+
__proto__: null,
|
|
2105
|
+
contains: ti,
|
|
2106
|
+
distinct: kn,
|
|
2107
|
+
first: Fn,
|
|
2108
|
+
flatten: Gt,
|
|
2109
|
+
last: jn,
|
|
2110
|
+
range: Qn,
|
|
2111
|
+
reverse: Pn,
|
|
2112
|
+
slice: Gn,
|
|
2113
|
+
sort: qn
|
|
2114
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2115
|
+
function zn(e) {
|
|
2116
|
+
const t = new sn();
|
|
2117
|
+
for (const n of e)
|
|
2118
|
+
t.add(n);
|
|
2119
|
+
return t;
|
|
2120
|
+
}
|
|
2121
|
+
function ut(e, t) {
|
|
2122
|
+
const n = zn(e);
|
|
2123
|
+
return t.every((i) => n.has(i));
|
|
2124
|
+
}
|
|
2125
|
+
function Yn(e, t) {
|
|
2126
|
+
return ut(e, t) && ut(t, e);
|
|
2127
|
+
}
|
|
2128
|
+
function _n(e, t) {
|
|
2129
|
+
const n = zn(e);
|
|
2130
|
+
return t.some((i) => n.has(i));
|
|
2131
|
+
}
|
|
2132
|
+
const bi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2133
|
+
__proto__: null,
|
|
2134
|
+
contains: ut,
|
|
2135
|
+
equivalent: Yn,
|
|
2136
|
+
intersects: _n
|
|
2137
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
2138
|
+
function Wn(e) {
|
|
2139
|
+
return e.length === 1 && Array.isArray(e[0]) ? e[0] : e;
|
|
2140
|
+
}
|
|
2141
|
+
function Kn(e) {
|
|
2142
|
+
return xt(Wn(e));
|
|
2143
|
+
}
|
|
2144
|
+
function Hn(e) {
|
|
2145
|
+
return kt(Wn(e));
|
|
2146
|
+
}
|
|
2147
|
+
function Xn(e) {
|
|
2148
|
+
if (typeof e == "number")
|
|
2149
|
+
return Math.abs(e);
|
|
2150
|
+
const t = g(e);
|
|
2151
|
+
if (t === K)
|
|
2152
|
+
throw new l("Integer overflow");
|
|
2153
|
+
return t < 0n ? -t : t;
|
|
2154
|
+
}
|
|
2155
|
+
function Vn(e) {
|
|
2156
|
+
return Math.ceil(T(e));
|
|
2157
|
+
}
|
|
2158
|
+
function Zn(e) {
|
|
2159
|
+
return Math.floor(T(e));
|
|
2160
|
+
}
|
|
2161
|
+
function Jn(e) {
|
|
2162
|
+
const t = T(e);
|
|
2163
|
+
return t < 0 ? -Math.round(-t) : Math.round(t);
|
|
2164
|
+
}
|
|
2165
|
+
function vn(e) {
|
|
2166
|
+
const t = T(e);
|
|
2167
|
+
return t < 0 ? Math.ceil(t) : Math.floor(t);
|
|
2168
|
+
}
|
|
2169
|
+
function te(e) {
|
|
2170
|
+
if (typeof e == "number")
|
|
2171
|
+
return Math.sign(e);
|
|
2172
|
+
const t = g(e);
|
|
2173
|
+
return t < 0n ? -1n : t > 0n ? 1n : 0n;
|
|
2174
|
+
}
|
|
2175
|
+
function ne(e) {
|
|
2176
|
+
return Math.sqrt(T(e));
|
|
2177
|
+
}
|
|
2178
|
+
function ee(e) {
|
|
2179
|
+
return Number.isNaN(T(e));
|
|
2180
|
+
}
|
|
2181
|
+
function ie(e) {
|
|
2182
|
+
const t = T(e);
|
|
2183
|
+
return t === 1 / 0 || t === -1 / 0;
|
|
2184
|
+
}
|
|
2185
|
+
function re(e) {
|
|
2186
|
+
return Number.isFinite(T(e));
|
|
2187
|
+
}
|
|
2188
|
+
function se(e, t) {
|
|
2189
|
+
return BigInt.asIntN(64, g(e) & g(t));
|
|
2190
|
+
}
|
|
2191
|
+
function oe(e, t) {
|
|
2192
|
+
return BigInt.asIntN(64, g(e) | g(t));
|
|
2193
|
+
}
|
|
2194
|
+
function ce(e, t) {
|
|
2195
|
+
return BigInt.asIntN(64, g(e) ^ g(t));
|
|
2196
|
+
}
|
|
2197
|
+
function ue(e) {
|
|
2198
|
+
return BigInt.asIntN(64, ~g(e));
|
|
2199
|
+
}
|
|
2200
|
+
function ae(e) {
|
|
2201
|
+
const t = g(e);
|
|
2202
|
+
if (t < 0n)
|
|
2203
|
+
throw new a(`Shift count must not be negative: ${t}`);
|
|
2204
|
+
return t;
|
|
2205
|
+
}
|
|
2206
|
+
function he(e, t) {
|
|
2207
|
+
const n = ae(t);
|
|
2208
|
+
return n >= 64n ? 0n : BigInt.asIntN(64, g(e) << n);
|
|
2209
|
+
}
|
|
2210
|
+
function fe(e, t) {
|
|
2211
|
+
const n = ae(t);
|
|
2212
|
+
return n >= 64n ? 0n : BigInt.asIntN(64, BigInt.asUintN(64, g(e)) >> n);
|
|
2213
|
+
}
|
|
2214
|
+
const mi = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2215
|
+
__proto__: null,
|
|
2216
|
+
abs: Xn,
|
|
2217
|
+
and: se,
|
|
2218
|
+
ceil: Vn,
|
|
2219
|
+
floor: Zn,
|
|
2220
|
+
greatest: Kn,
|
|
2221
|
+
isFinite: re,
|
|
2222
|
+
isInf: ie,
|
|
2223
|
+
isNaN: ee,
|
|
2224
|
+
least: Hn,
|
|
2225
|
+
left: he,
|
|
2226
|
+
not: ue,
|
|
2227
|
+
or: oe,
|
|
2228
|
+
right: fe,
|
|
2229
|
+
round: Jn,
|
|
2230
|
+
sign: te,
|
|
2231
|
+
sqrt: ne,
|
|
2232
|
+
trunc: vn,
|
|
2233
|
+
xor: ce
|
|
2234
|
+
}, Symbol.toStringTag, { value: "Module" })), P = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", ni = new Map(Array.from(P, (e, t) => [e, t]));
|
|
2235
|
+
function le(e) {
|
|
2236
|
+
const t = ft(e);
|
|
2237
|
+
q(4 * Math.ceil(t.length / 3), "base64.encode()");
|
|
2238
|
+
let n = "", i = 0;
|
|
2239
|
+
for (; i + 2 < t.length; i += 3) {
|
|
2240
|
+
const s = t[i] << 16 | t[i + 1] << 8 | t[i + 2];
|
|
2241
|
+
n += P[s >> 18] + P[s >> 12 & 63] + P[s >> 6 & 63] + P[s & 63];
|
|
2242
|
+
}
|
|
2243
|
+
const r = t.length - i;
|
|
2244
|
+
if (r === 1) {
|
|
2245
|
+
const s = t[i] << 16;
|
|
2246
|
+
n += P[s >> 18] + P[s >> 12 & 63] + "==";
|
|
2247
|
+
} else if (r === 2) {
|
|
2248
|
+
const s = t[i] << 16 | t[i + 1] << 8;
|
|
2249
|
+
n += P[s >> 18] + P[s >> 12 & 63] + P[s >> 6 & 63] + "=";
|
|
2250
|
+
}
|
|
2251
|
+
return n;
|
|
2252
|
+
}
|
|
2253
|
+
function qt(e) {
|
|
2254
|
+
if (typeof e != "string")
|
|
2255
|
+
throw new a("base64.decode() requires string arguments");
|
|
2256
|
+
let t = e, n = 0;
|
|
2257
|
+
for (; t.endsWith("=") && n < 2; )
|
|
2258
|
+
t = t.substring(0, t.length - 1), n++;
|
|
2259
|
+
const i = t.length % 4;
|
|
2260
|
+
if (t.includes("=") || i === 1 || n > 0 && (i === 0 || n !== 4 - i))
|
|
2261
|
+
throw new a(`Invalid base64 input: ${e}`);
|
|
2262
|
+
const r = [];
|
|
2263
|
+
let s = 0, c = 0;
|
|
2264
|
+
for (const u of t) {
|
|
2265
|
+
const d = ni.get(u);
|
|
2266
|
+
if (d === void 0)
|
|
2267
|
+
throw new a(`Invalid base64 input: ${e}`);
|
|
2268
|
+
s = (s << 6 | d) & 65535, c += 6, c >= 8 && (c -= 8, r.push(s >> c & 255));
|
|
2269
|
+
}
|
|
2270
|
+
return Uint8Array.from(r);
|
|
2271
|
+
}
|
|
2272
|
+
function ei(e) {
|
|
2273
|
+
return en(qt(e));
|
|
2274
|
+
}
|
|
2275
|
+
const Ei = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2276
|
+
__proto__: null,
|
|
2277
|
+
decode: qt,
|
|
2278
|
+
encode: le,
|
|
2279
|
+
text: ei
|
|
2280
|
+
}, Symbol.toStringTag, { value: "Module" })), ii = /* @__PURE__ */ new Set([
|
|
2281
|
+
"math.greatest",
|
|
2282
|
+
"math.least",
|
|
2283
|
+
"math.abs",
|
|
2284
|
+
"math.ceil",
|
|
2285
|
+
"math.floor",
|
|
2286
|
+
"math.round",
|
|
2287
|
+
"math.trunc",
|
|
2288
|
+
"math.sign",
|
|
2289
|
+
"math.sqrt",
|
|
2290
|
+
"math.isNaN",
|
|
2291
|
+
"math.isInf",
|
|
2292
|
+
"math.isFinite",
|
|
2293
|
+
"math.bitAnd",
|
|
2294
|
+
"math.bitOr",
|
|
2295
|
+
"math.bitXor",
|
|
2296
|
+
"math.bitNot",
|
|
2297
|
+
"math.bitShiftLeft",
|
|
2298
|
+
"math.bitShiftRight",
|
|
2299
|
+
"sets.contains",
|
|
2300
|
+
"sets.equivalent",
|
|
2301
|
+
"sets.intersects",
|
|
2302
|
+
"base64.encode",
|
|
2303
|
+
"base64.decode",
|
|
2304
|
+
"lists.range",
|
|
2305
|
+
"strings.quote",
|
|
2306
|
+
"regex.replace",
|
|
2307
|
+
"regex.extract",
|
|
2308
|
+
"regex.extractAll"
|
|
2309
|
+
]), ri = /* @__PURE__ */ new Set(["map", "filter", "all", "exists", "existsOne", "sortBy"]), si = /* @__PURE__ */ new Set([
|
|
2310
|
+
"getDate",
|
|
2311
|
+
"getMonth",
|
|
2312
|
+
"getFullYear",
|
|
2313
|
+
"getHours",
|
|
2314
|
+
"getMinutes",
|
|
2315
|
+
"getSeconds",
|
|
2316
|
+
"getMilliseconds",
|
|
2317
|
+
"getDayOfWeek",
|
|
2318
|
+
"getDayOfYear"
|
|
2319
|
+
]);
|
|
2320
|
+
function f(e, t, n, i) {
|
|
2321
|
+
if (t.length < n || t.length > i)
|
|
2322
|
+
throw new a(
|
|
2323
|
+
`${e}() requires ${n === i ? n : `${n} to ${i}`} argument(s)`
|
|
2324
|
+
);
|
|
2325
|
+
}
|
|
2326
|
+
function F(e) {
|
|
2327
|
+
return e.length > 1 ? e[1] : null;
|
|
2328
|
+
}
|
|
2329
|
+
function m(e, t) {
|
|
2330
|
+
if (typeof e == "string")
|
|
2331
|
+
return e;
|
|
2332
|
+
throw new a(`${t}() requires string arguments`);
|
|
2333
|
+
}
|
|
2334
|
+
function R(e, t) {
|
|
2335
|
+
if (Array.isArray(e))
|
|
2336
|
+
return e;
|
|
2337
|
+
throw new a(`${t}() requires a list`);
|
|
2338
|
+
}
|
|
2339
|
+
function x(e, t, n) {
|
|
2340
|
+
return f(e, t, 1, 1), n(t[0]);
|
|
2341
|
+
}
|
|
2342
|
+
function tt(e, t, n) {
|
|
2343
|
+
return f(e, t, 2, 2), n(t[0], t[1]);
|
|
2344
|
+
}
|
|
2345
|
+
class pe {
|
|
2346
|
+
knows(t) {
|
|
2347
|
+
return ii.has(t);
|
|
2348
|
+
}
|
|
2349
|
+
callFunction(t, n) {
|
|
2350
|
+
if (t.indexOf(".") > 0)
|
|
2351
|
+
return this.callQualified(t, n);
|
|
896
2352
|
switch (t) {
|
|
897
2353
|
case "size":
|
|
898
|
-
return
|
|
2354
|
+
return f(t, n, 1, 1), Lt(n[0]);
|
|
899
2355
|
case "int":
|
|
900
|
-
return
|
|
2356
|
+
return f(t, n, 1, 1), g(n[0]);
|
|
901
2357
|
case "uint":
|
|
902
|
-
return
|
|
2358
|
+
return f(t, n, 1, 1), on(n[0]);
|
|
903
2359
|
case "double":
|
|
904
|
-
return
|
|
2360
|
+
return f(t, n, 1, 1), T(n[0]);
|
|
905
2361
|
case "string":
|
|
906
|
-
return
|
|
2362
|
+
return f(t, n, 1, 1), O(n[0]);
|
|
907
2363
|
case "bool":
|
|
908
|
-
return
|
|
2364
|
+
return f(t, n, 1, 1), cn(n[0]);
|
|
909
2365
|
case "type":
|
|
910
|
-
return
|
|
2366
|
+
return f(t, n, 1, 1), W(n[0]);
|
|
911
2367
|
case "has":
|
|
912
|
-
if (
|
|
913
|
-
throw new
|
|
914
|
-
return
|
|
2368
|
+
if (n.length !== 2)
|
|
2369
|
+
throw new a("has() requires 2 arguments");
|
|
2370
|
+
return un(n[0], n[1]);
|
|
915
2371
|
case "matches":
|
|
916
|
-
if (
|
|
917
|
-
throw new
|
|
918
|
-
return
|
|
2372
|
+
if (n.length !== 2)
|
|
2373
|
+
throw new a("matches() requires 2 arguments");
|
|
2374
|
+
return St(m(n[0], t), m(n[1], t));
|
|
2375
|
+
case "timestamp":
|
|
2376
|
+
return f(t, n, 0, 1), Dt(n.length > 0 ? n[0] : null);
|
|
2377
|
+
case "duration":
|
|
2378
|
+
return f(t, n, 1, 1), hn(n[0]);
|
|
2379
|
+
case "getDate":
|
|
2380
|
+
return f(t, n, 1, 2), fn(n[0], F(n));
|
|
2381
|
+
case "getMonth":
|
|
2382
|
+
return f(t, n, 1, 2), ln(n[0], F(n));
|
|
2383
|
+
case "getFullYear":
|
|
2384
|
+
return f(t, n, 1, 2), pn(n[0], F(n));
|
|
2385
|
+
case "getHours":
|
|
2386
|
+
return f(t, n, 1, 2), dn(n[0], F(n));
|
|
2387
|
+
case "getMinutes":
|
|
2388
|
+
return f(t, n, 1, 2), wn(n[0], F(n));
|
|
2389
|
+
case "getSeconds":
|
|
2390
|
+
return f(t, n, 1, 2), gn(n[0], F(n));
|
|
2391
|
+
case "getDayOfWeek":
|
|
2392
|
+
return f(t, n, 1, 2), mn(n[0], F(n));
|
|
2393
|
+
case "getDayOfYear":
|
|
2394
|
+
return f(t, n, 1, 2), En(n[0], F(n));
|
|
2395
|
+
case "getMilliseconds":
|
|
2396
|
+
return f(t, n, 1, 2), bn(n[0], F(n));
|
|
2397
|
+
case "bytes":
|
|
2398
|
+
return f(t, n, 1, 1), ft(n[0]);
|
|
2399
|
+
case "dyn":
|
|
2400
|
+
return f(t, n, 1, 1), n[0];
|
|
919
2401
|
case "max":
|
|
920
|
-
return
|
|
2402
|
+
return xt(n);
|
|
921
2403
|
case "min":
|
|
922
|
-
return
|
|
2404
|
+
return kt(n);
|
|
923
2405
|
default:
|
|
924
|
-
throw new
|
|
2406
|
+
throw new a(`Unknown function: ${t}`);
|
|
925
2407
|
}
|
|
926
2408
|
}
|
|
927
|
-
callMethod(t,
|
|
2409
|
+
callMethod(t, n, i) {
|
|
928
2410
|
if (t == null)
|
|
929
|
-
throw new
|
|
930
|
-
switch (
|
|
2411
|
+
throw new a("Cannot call method on null");
|
|
2412
|
+
switch (n) {
|
|
931
2413
|
case "contains":
|
|
932
2414
|
if (typeof t == "string" && i.length === 1 && typeof i[0] == "string")
|
|
933
2415
|
return t.includes(i[0]);
|
|
934
2416
|
if (Array.isArray(t) && i.length === 1)
|
|
935
|
-
return t
|
|
936
|
-
throw new
|
|
2417
|
+
return lt(t, i[0]);
|
|
2418
|
+
throw new a("Invalid arguments for contains()");
|
|
937
2419
|
case "startsWith":
|
|
938
2420
|
if (typeof t == "string" && i.length === 1 && typeof i[0] == "string")
|
|
939
2421
|
return t.startsWith(i[0]);
|
|
940
|
-
throw new
|
|
2422
|
+
throw new a("startsWith() requires string target and argument");
|
|
941
2423
|
case "endsWith":
|
|
942
2424
|
if (typeof t == "string" && i.length === 1 && typeof i[0] == "string")
|
|
943
2425
|
return t.endsWith(i[0]);
|
|
944
|
-
throw new
|
|
2426
|
+
throw new a("endsWith() requires string target and argument");
|
|
945
2427
|
case "toLowerCase":
|
|
946
2428
|
if (typeof t == "string" && i.length === 0)
|
|
947
2429
|
return t.toLowerCase();
|
|
948
|
-
throw new
|
|
2430
|
+
throw new a("toLowerCase() requires string target");
|
|
949
2431
|
case "toUpperCase":
|
|
950
2432
|
if (typeof t == "string" && i.length === 0)
|
|
951
2433
|
return t.toUpperCase();
|
|
952
|
-
throw new
|
|
2434
|
+
throw new a("toUpperCase() requires string target");
|
|
953
2435
|
case "trim":
|
|
954
2436
|
if (typeof t == "string" && i.length === 0)
|
|
955
2437
|
return t.trim();
|
|
956
|
-
throw new
|
|
2438
|
+
throw new a("trim() requires string target");
|
|
957
2439
|
case "replace":
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
2440
|
+
return f(n, i, 2, 3), $n(
|
|
2441
|
+
m(t, n),
|
|
2442
|
+
m(i[0], n),
|
|
2443
|
+
m(i[1], n),
|
|
2444
|
+
i.length > 2 ? g(i[2]) : -1n
|
|
2445
|
+
);
|
|
961
2446
|
case "split":
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
2447
|
+
return f(n, i, 1, 2), Rn(
|
|
2448
|
+
m(t, n),
|
|
2449
|
+
m(i[0], n),
|
|
2450
|
+
i.length > 1 ? g(i[1]) : -1n
|
|
2451
|
+
);
|
|
2452
|
+
case "charAt":
|
|
2453
|
+
return f(n, i, 1, 1), In(m(t, n), g(i[0]));
|
|
2454
|
+
case "indexOf":
|
|
2455
|
+
return f(n, i, 1, 2), An(
|
|
2456
|
+
m(t, n),
|
|
2457
|
+
m(i[0], n),
|
|
2458
|
+
i.length > 1 ? g(i[1]) : 0n
|
|
2459
|
+
);
|
|
2460
|
+
case "lastIndexOf":
|
|
2461
|
+
return f(n, i, 1, 2), yn(
|
|
2462
|
+
m(t, n),
|
|
2463
|
+
m(i[0], n),
|
|
2464
|
+
i.length > 1 ? g(i[1]) : void 0
|
|
2465
|
+
);
|
|
2466
|
+
case "lowerAscii":
|
|
2467
|
+
return f(n, i, 0, 0), Nn(m(t, n));
|
|
2468
|
+
case "upperAscii":
|
|
2469
|
+
return f(n, i, 0, 0), Ln(m(t, n));
|
|
2470
|
+
case "substring":
|
|
2471
|
+
return f(n, i, 1, 2), Sn(
|
|
2472
|
+
m(t, n),
|
|
2473
|
+
g(i[0]),
|
|
2474
|
+
i.length > 1 ? g(i[1]) : void 0
|
|
2475
|
+
);
|
|
2476
|
+
case "join":
|
|
2477
|
+
return f(n, i, 0, 1), Mn(R(t, n), i.length > 0 ? m(i[0], n) : "");
|
|
2478
|
+
case "format":
|
|
2479
|
+
return f(n, i, 1, 1), Cn(m(t, n), R(i[0], n));
|
|
2480
|
+
case "matches":
|
|
2481
|
+
return f(n, i, 1, 1), St(m(t, n), m(i[0], n));
|
|
2482
|
+
case "reverse":
|
|
2483
|
+
return f(n, i, 0, 0), Array.isArray(t) ? Pn(t) : On(m(t, n));
|
|
2484
|
+
case "distinct":
|
|
2485
|
+
return f(n, i, 0, 0), kn(R(t, n));
|
|
2486
|
+
case "flatten":
|
|
2487
|
+
return f(n, i, 0, 1), Gt(R(t, n), i.length > 0 ? g(i[0]) : 1n);
|
|
2488
|
+
case "slice":
|
|
2489
|
+
return f(n, i, 2, 2), Gn(
|
|
2490
|
+
R(t, n),
|
|
2491
|
+
g(i[0]),
|
|
2492
|
+
g(i[1])
|
|
2493
|
+
);
|
|
2494
|
+
case "sort":
|
|
2495
|
+
return f(n, i, 0, 0), qn(R(t, n));
|
|
2496
|
+
case "first":
|
|
2497
|
+
return f(n, i, 0, 0), Fn(R(t, n));
|
|
2498
|
+
case "last":
|
|
2499
|
+
return f(n, i, 0, 0), jn(R(t, n));
|
|
965
2500
|
case "size":
|
|
966
|
-
return
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
2501
|
+
return Lt(t);
|
|
2502
|
+
default:
|
|
2503
|
+
if (si.has(n))
|
|
2504
|
+
return f(n, i, 0, 1), this.callFunction(n, [t, ...i]);
|
|
2505
|
+
if (ri.has(n))
|
|
2506
|
+
throw new l(
|
|
2507
|
+
`Macro function ${n} was not properly handled by the interpreter`
|
|
2508
|
+
);
|
|
2509
|
+
return this.callNativeMethod(t, n, i);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Dispatches a namespaced function such as `math.abs`.
|
|
2514
|
+
*
|
|
2515
|
+
* @throws ArgumentError if the name is unknown
|
|
2516
|
+
*/
|
|
2517
|
+
callQualified(t, n) {
|
|
2518
|
+
switch (t) {
|
|
2519
|
+
case "math.greatest":
|
|
2520
|
+
return Kn(n);
|
|
2521
|
+
case "math.least":
|
|
2522
|
+
return Hn(n);
|
|
2523
|
+
case "math.abs":
|
|
2524
|
+
return x(t, n, Xn);
|
|
2525
|
+
case "math.ceil":
|
|
2526
|
+
return x(t, n, Vn);
|
|
2527
|
+
case "math.floor":
|
|
2528
|
+
return x(t, n, Zn);
|
|
2529
|
+
case "math.round":
|
|
2530
|
+
return x(t, n, Jn);
|
|
2531
|
+
case "math.trunc":
|
|
2532
|
+
return x(t, n, vn);
|
|
2533
|
+
case "math.sign":
|
|
2534
|
+
return x(t, n, te);
|
|
2535
|
+
case "math.sqrt":
|
|
2536
|
+
return x(t, n, ne);
|
|
2537
|
+
case "math.isNaN":
|
|
2538
|
+
return x(t, n, ee);
|
|
2539
|
+
case "math.isInf":
|
|
2540
|
+
return x(t, n, ie);
|
|
2541
|
+
case "math.isFinite":
|
|
2542
|
+
return x(t, n, re);
|
|
2543
|
+
case "math.bitAnd":
|
|
2544
|
+
return tt(t, n, se);
|
|
2545
|
+
case "math.bitOr":
|
|
2546
|
+
return tt(t, n, oe);
|
|
2547
|
+
case "math.bitXor":
|
|
2548
|
+
return tt(t, n, ce);
|
|
2549
|
+
case "math.bitNot":
|
|
2550
|
+
return x(t, n, ue);
|
|
2551
|
+
case "math.bitShiftLeft":
|
|
2552
|
+
return tt(t, n, he);
|
|
2553
|
+
case "math.bitShiftRight":
|
|
2554
|
+
return tt(t, n, fe);
|
|
2555
|
+
case "sets.contains":
|
|
2556
|
+
return f(t, n, 2, 2), ut(R(n[0], t), R(n[1], t));
|
|
2557
|
+
case "sets.equivalent":
|
|
2558
|
+
return f(t, n, 2, 2), Yn(R(n[0], t), R(n[1], t));
|
|
2559
|
+
case "sets.intersects":
|
|
2560
|
+
return f(t, n, 2, 2), _n(R(n[0], t), R(n[1], t));
|
|
2561
|
+
case "base64.encode":
|
|
2562
|
+
return f(t, n, 1, 1), le(n[0]);
|
|
2563
|
+
case "base64.decode":
|
|
2564
|
+
return f(t, n, 1, 1), qt(m(n[0], t));
|
|
2565
|
+
case "lists.range":
|
|
2566
|
+
return f(t, n, 1, 1), Qn(g(n[0]));
|
|
2567
|
+
case "strings.quote":
|
|
2568
|
+
return f(t, n, 1, 1), Pt(m(n[0], t));
|
|
2569
|
+
case "regex.replace":
|
|
2570
|
+
return f(t, n, 3, 4), Tn(
|
|
2571
|
+
m(n[0], t),
|
|
2572
|
+
m(n[1], t),
|
|
2573
|
+
m(n[2], t),
|
|
2574
|
+
n.length > 3 ? g(n[3]) : -1n
|
|
975
2575
|
);
|
|
2576
|
+
case "regex.extract":
|
|
2577
|
+
return f(t, n, 2, 2), Dn(m(n[0], t), m(n[1], t));
|
|
2578
|
+
case "regex.extractAll":
|
|
2579
|
+
return f(t, n, 2, 2), xn(m(n[0], t), m(n[1], t));
|
|
976
2580
|
default:
|
|
977
|
-
|
|
2581
|
+
throw new a(`Unknown function: ${t}`);
|
|
978
2582
|
}
|
|
979
2583
|
}
|
|
980
2584
|
/**
|
|
981
2585
|
* Attempts to call a native JavaScript method on the target object.
|
|
982
2586
|
*
|
|
983
|
-
*
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
* @
|
|
987
|
-
* @throws
|
|
2587
|
+
* This is the last resort after every named method, the analogue of the Java
|
|
2588
|
+
* library's reflective method call.
|
|
2589
|
+
*
|
|
2590
|
+
* @throws ArgumentError if the method doesn't exist
|
|
2591
|
+
* @throws EvaluationError if the call fails
|
|
988
2592
|
*/
|
|
989
|
-
callNativeMethod(t,
|
|
990
|
-
|
|
2593
|
+
callNativeMethod(t, n, i) {
|
|
2594
|
+
const r = t[n];
|
|
2595
|
+
if (typeof r == "function")
|
|
991
2596
|
try {
|
|
992
|
-
return t
|
|
993
|
-
} catch (
|
|
994
|
-
throw new
|
|
995
|
-
`Invocation of method '${
|
|
2597
|
+
return r.apply(t, i);
|
|
2598
|
+
} catch (s) {
|
|
2599
|
+
throw new l(
|
|
2600
|
+
`Invocation of method '${n}' failed: ${s instanceof Error ? s.message : String(s)}`
|
|
996
2601
|
);
|
|
997
2602
|
}
|
|
998
|
-
throw new
|
|
999
|
-
`No such method '${
|
|
2603
|
+
throw new a(
|
|
2604
|
+
`No such method '${n}' on type ${W(t)} with ${i.length} argument(s)`
|
|
1000
2605
|
);
|
|
1001
2606
|
}
|
|
1002
2607
|
}
|
|
1003
|
-
|
|
2608
|
+
const oi = {
|
|
2609
|
+
[h.LOGICAL_AND]: "&&",
|
|
2610
|
+
[h.LOGICAL_OR]: "||"
|
|
2611
|
+
};
|
|
2612
|
+
class ci {
|
|
1004
2613
|
/**
|
|
1005
2614
|
* Constructs an interpreter with the specified variables and functions.
|
|
1006
2615
|
*
|
|
1007
|
-
* @param variables
|
|
1008
|
-
* @param functions
|
|
2616
|
+
* @param variables Variable bindings as a plain object or Map. If null, no variables are bound.
|
|
2617
|
+
* @param functions The function library. If null, StandardFunctions is used.
|
|
1009
2618
|
*/
|
|
1010
|
-
constructor(t,
|
|
1011
|
-
this.variables =
|
|
2619
|
+
constructor(t, n) {
|
|
2620
|
+
if (this.variables = /* @__PURE__ */ new Map(), t instanceof Map)
|
|
2621
|
+
for (const [i, r] of t)
|
|
2622
|
+
this.variables.set(i, Jt(r));
|
|
2623
|
+
else if (t)
|
|
2624
|
+
for (const [i, r] of Object.entries(t))
|
|
2625
|
+
this.variables.set(i, Jt(r));
|
|
2626
|
+
this.functions = n ?? new pe();
|
|
1012
2627
|
}
|
|
1013
2628
|
/**
|
|
1014
2629
|
* Evaluates a CEL expression and returns its result.
|
|
1015
2630
|
*
|
|
1016
|
-
* @param expr The expression to evaluate
|
|
1017
|
-
* @returns The result of the evaluation
|
|
1018
2631
|
* @throws EvaluationError if evaluation fails
|
|
1019
2632
|
*/
|
|
1020
2633
|
evaluate(t) {
|
|
@@ -1024,244 +2637,418 @@ class H {
|
|
|
1024
2637
|
return t.value;
|
|
1025
2638
|
}
|
|
1026
2639
|
visitIdentifier(t) {
|
|
1027
|
-
if (!(t.name
|
|
1028
|
-
|
|
1029
|
-
|
|
2640
|
+
if (!this.variables.has(t.name)) {
|
|
2641
|
+
const n = y.of(t.name);
|
|
2642
|
+
if (n !== null)
|
|
2643
|
+
return n;
|
|
2644
|
+
throw new l(`Undefined variable: ${t.name}`);
|
|
2645
|
+
}
|
|
2646
|
+
return this.variables.get(t.name);
|
|
1030
2647
|
}
|
|
1031
2648
|
visitSelect(t) {
|
|
1032
|
-
const
|
|
1033
|
-
if (
|
|
2649
|
+
const n = t.operand !== null ? this.evaluate(t.operand) : this.variables;
|
|
2650
|
+
if (n == null) {
|
|
1034
2651
|
if (t.isTest)
|
|
1035
2652
|
return !1;
|
|
1036
|
-
throw new
|
|
2653
|
+
throw new l(`Cannot select field ${t.field} from null`);
|
|
1037
2654
|
}
|
|
1038
|
-
if (
|
|
2655
|
+
if (n instanceof Map) {
|
|
1039
2656
|
if (t.isTest)
|
|
1040
|
-
return t.field
|
|
1041
|
-
if (!(t.field
|
|
1042
|
-
throw new
|
|
1043
|
-
return
|
|
2657
|
+
return n.has(t.field);
|
|
2658
|
+
if (!n.has(t.field))
|
|
2659
|
+
throw new l(`Field ${t.field} not found`);
|
|
2660
|
+
return n.get(t.field);
|
|
1044
2661
|
}
|
|
1045
|
-
throw new
|
|
2662
|
+
throw new l("Cannot select field from non-map type");
|
|
1046
2663
|
}
|
|
1047
2664
|
visitCall(t) {
|
|
1048
2665
|
if (t.isMacro && t.target !== null) {
|
|
1049
2666
|
const i = this.evaluate(t.target);
|
|
1050
2667
|
if (t.args.length === 0)
|
|
1051
|
-
throw new
|
|
1052
|
-
const
|
|
1053
|
-
if (!(
|
|
1054
|
-
throw new
|
|
2668
|
+
throw new l(`Macro ${t.functionName} requires arguments`);
|
|
2669
|
+
const r = t.args[0];
|
|
2670
|
+
if (!(r instanceof It))
|
|
2671
|
+
throw new l(
|
|
1055
2672
|
`First argument to macro ${t.functionName} must be a variable name`
|
|
1056
2673
|
);
|
|
1057
|
-
const o = n.name;
|
|
1058
2674
|
if (t.args.length < 2)
|
|
1059
|
-
throw new
|
|
1060
|
-
const
|
|
1061
|
-
return this.evaluateMacro(i, t.functionName,
|
|
2675
|
+
throw new l(`Macro ${t.functionName} requires an expression argument`);
|
|
2676
|
+
const s = t.args.slice(1);
|
|
2677
|
+
return this.evaluateMacro(i, t.functionName, r.name, s);
|
|
1062
2678
|
}
|
|
1063
|
-
const
|
|
2679
|
+
const n = [];
|
|
1064
2680
|
for (const i of t.args)
|
|
1065
|
-
|
|
2681
|
+
n.push(this.evaluate(i));
|
|
1066
2682
|
if (t.target !== null) {
|
|
1067
|
-
const i = this.
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
2683
|
+
const i = this.qualify(t.target);
|
|
2684
|
+
if (i !== null) {
|
|
2685
|
+
const s = `${i}.${t.functionName}`;
|
|
2686
|
+
if (!this.variables.has(this.root(i)) && this.knows(s))
|
|
2687
|
+
return bt(this.functions.callFunction(s, n));
|
|
2688
|
+
}
|
|
2689
|
+
const r = this.evaluate(t.target);
|
|
2690
|
+
return bt(this.functions.callMethod(r, t.functionName, n));
|
|
2691
|
+
}
|
|
2692
|
+
return bt(this.functions.callFunction(t.functionName, n));
|
|
2693
|
+
}
|
|
2694
|
+
knows(t) {
|
|
2695
|
+
return this.functions.knows?.(t) ?? !1;
|
|
2696
|
+
}
|
|
2697
|
+
// Flattens an identifier or a chain of selections over one into a dotted name, or null
|
|
2698
|
+
qualify(t) {
|
|
2699
|
+
if (t instanceof It)
|
|
2700
|
+
return t.name;
|
|
2701
|
+
if (t instanceof nt && t.operand !== null && !t.isTest) {
|
|
2702
|
+
const n = this.qualify(t.operand);
|
|
2703
|
+
return n === null ? null : `${n}.${t.field}`;
|
|
2704
|
+
}
|
|
2705
|
+
return null;
|
|
2706
|
+
}
|
|
2707
|
+
root(t) {
|
|
2708
|
+
const n = t.indexOf(".");
|
|
2709
|
+
return n < 0 ? t : t.substring(0, n);
|
|
2710
|
+
}
|
|
2711
|
+
evaluateMacro(t, n, i, r) {
|
|
2712
|
+
let s;
|
|
2713
|
+
if (Array.isArray(t))
|
|
2714
|
+
s = t;
|
|
2715
|
+
else if (t instanceof Map)
|
|
2716
|
+
s = Array.from(t.keys());
|
|
2717
|
+
else
|
|
2718
|
+
throw new l(`Macro ${n} requires a list or map target`);
|
|
2719
|
+
const c = this.variables.get(i), u = this.variables.has(i), d = (b) => {
|
|
2720
|
+
this.variables.set(i, b);
|
|
2721
|
+
}, E = r[0];
|
|
1076
2722
|
try {
|
|
1077
|
-
switch (
|
|
2723
|
+
switch (n) {
|
|
1078
2724
|
case "map": {
|
|
1079
|
-
const
|
|
1080
|
-
for (const
|
|
1081
|
-
this.
|
|
1082
|
-
return
|
|
2725
|
+
const b = r.length > 1 ? r[0] : null, N = r.length > 1 ? r[1] : E, L = [];
|
|
2726
|
+
for (const k of s)
|
|
2727
|
+
d(k), !(b !== null && !this.test(b, n)) && L.push(this.evaluate(N));
|
|
2728
|
+
return L;
|
|
1083
2729
|
}
|
|
1084
2730
|
case "filter": {
|
|
1085
|
-
const
|
|
1086
|
-
for (const
|
|
1087
|
-
|
|
1088
|
-
return
|
|
2731
|
+
const b = [];
|
|
2732
|
+
for (const N of s)
|
|
2733
|
+
d(N), this.test(E, n) && b.push(N);
|
|
2734
|
+
return b;
|
|
1089
2735
|
}
|
|
1090
2736
|
case "all": {
|
|
1091
|
-
for (const
|
|
1092
|
-
if (
|
|
2737
|
+
for (const b of s)
|
|
2738
|
+
if (d(b), !this.test(E, n))
|
|
1093
2739
|
return !1;
|
|
1094
2740
|
return !0;
|
|
1095
2741
|
}
|
|
1096
2742
|
case "exists": {
|
|
1097
|
-
for (const
|
|
1098
|
-
if (
|
|
2743
|
+
for (const b of s)
|
|
2744
|
+
if (d(b), this.test(E, n))
|
|
1099
2745
|
return !0;
|
|
1100
2746
|
return !1;
|
|
1101
2747
|
}
|
|
1102
2748
|
case "existsOne": {
|
|
1103
|
-
let
|
|
1104
|
-
for (const
|
|
1105
|
-
if (
|
|
2749
|
+
let b = 0;
|
|
2750
|
+
for (const N of s)
|
|
2751
|
+
if (d(N), this.test(E, n) && (b++, b > 1))
|
|
1106
2752
|
return !1;
|
|
1107
|
-
return
|
|
2753
|
+
return b === 1;
|
|
2754
|
+
}
|
|
2755
|
+
case "sortBy": {
|
|
2756
|
+
const b = [];
|
|
2757
|
+
for (const L of s)
|
|
2758
|
+
d(L), b.push(this.evaluate(E));
|
|
2759
|
+
const N = s.map((L, k) => k);
|
|
2760
|
+
return N.sort((L, k) => v(b[L], b[k])), N.map((L) => s[L]);
|
|
1108
2761
|
}
|
|
1109
2762
|
default:
|
|
1110
|
-
throw new
|
|
2763
|
+
throw new l(`Unknown macro function: ${n}`);
|
|
1111
2764
|
}
|
|
1112
2765
|
} finally {
|
|
1113
|
-
|
|
2766
|
+
u ? this.variables.set(i, c) : this.variables.delete(i);
|
|
1114
2767
|
}
|
|
1115
2768
|
}
|
|
2769
|
+
// Evaluates a macro predicate, which the specification requires to yield a boolean
|
|
2770
|
+
test(t, n) {
|
|
2771
|
+
const i = this.evaluate(t);
|
|
2772
|
+
if (typeof i != "boolean")
|
|
2773
|
+
throw new l(`Macro ${n} requires a boolean predicate`);
|
|
2774
|
+
return i;
|
|
2775
|
+
}
|
|
1116
2776
|
visitList(t) {
|
|
1117
|
-
const
|
|
2777
|
+
const n = [];
|
|
1118
2778
|
for (const i of t.elements)
|
|
1119
|
-
|
|
1120
|
-
return
|
|
2779
|
+
n.push(this.evaluate(i));
|
|
2780
|
+
return n;
|
|
1121
2781
|
}
|
|
1122
2782
|
visitMap(t) {
|
|
1123
|
-
const
|
|
2783
|
+
const n = /* @__PURE__ */ new Map();
|
|
1124
2784
|
for (const i of t.entries) {
|
|
1125
|
-
const
|
|
1126
|
-
|
|
2785
|
+
const r = this.evaluate(i.key), s = this.evaluate(i.value);
|
|
2786
|
+
n.set(r, s);
|
|
1127
2787
|
}
|
|
1128
|
-
return
|
|
2788
|
+
return n;
|
|
1129
2789
|
}
|
|
1130
2790
|
visitStruct(t) {
|
|
1131
|
-
const
|
|
2791
|
+
const n = /* @__PURE__ */ new Map();
|
|
1132
2792
|
for (const i of t.fields)
|
|
1133
|
-
|
|
1134
|
-
return
|
|
2793
|
+
n.set(i.field, this.evaluate(i.value));
|
|
2794
|
+
return n;
|
|
1135
2795
|
}
|
|
1136
2796
|
visitComprehension(t) {
|
|
1137
|
-
const
|
|
1138
|
-
if (!Array.isArray(
|
|
1139
|
-
throw new
|
|
1140
|
-
const i = this.variables
|
|
2797
|
+
const n = this.evaluate(t.range);
|
|
2798
|
+
if (!Array.isArray(n))
|
|
2799
|
+
throw new l("Comprehension range must be a list");
|
|
2800
|
+
const i = this.variables.get(t.variable), r = this.variables.get(t.accumulator), s = this.variables.has(t.variable), c = this.variables.has(t.accumulator);
|
|
1141
2801
|
try {
|
|
1142
2802
|
let u = this.evaluate(t.initializer);
|
|
1143
|
-
this.variables
|
|
1144
|
-
for (const
|
|
1145
|
-
this.variables
|
|
2803
|
+
this.variables.set(t.accumulator, u);
|
|
2804
|
+
for (const d of n)
|
|
2805
|
+
this.variables.set(t.variable, d), this.evaluate(t.condition) === !0 && (u = this.evaluate(t.step), this.variables.set(t.accumulator, u));
|
|
1146
2806
|
return this.evaluate(t.result);
|
|
1147
2807
|
} finally {
|
|
1148
|
-
|
|
2808
|
+
s ? this.variables.set(t.variable, i) : this.variables.delete(t.variable), c ? this.variables.set(t.accumulator, r) : this.variables.delete(t.accumulator);
|
|
1149
2809
|
}
|
|
1150
2810
|
}
|
|
1151
2811
|
visitUnary(t) {
|
|
1152
|
-
const
|
|
2812
|
+
const n = this.evaluate(t.operand);
|
|
1153
2813
|
switch (t.op) {
|
|
1154
|
-
case
|
|
1155
|
-
if (typeof
|
|
1156
|
-
throw new
|
|
1157
|
-
return !
|
|
1158
|
-
case
|
|
1159
|
-
if (typeof
|
|
1160
|
-
|
|
1161
|
-
|
|
2814
|
+
case J.NOT:
|
|
2815
|
+
if (typeof n != "boolean")
|
|
2816
|
+
throw new l("NOT operator requires boolean operand");
|
|
2817
|
+
return !n;
|
|
2818
|
+
case J.NEGATE:
|
|
2819
|
+
if (typeof n == "bigint") {
|
|
2820
|
+
if (n === K)
|
|
2821
|
+
throw new l("Integer overflow");
|
|
2822
|
+
return -n;
|
|
2823
|
+
}
|
|
2824
|
+
if (typeof n == "number")
|
|
2825
|
+
return -n;
|
|
2826
|
+
if (n instanceof I)
|
|
2827
|
+
return n.negated();
|
|
2828
|
+
throw new l("Negation requires numeric operand");
|
|
1162
2829
|
default:
|
|
1163
|
-
throw new
|
|
2830
|
+
throw new l(`Unknown unary operator: ${t.op}`);
|
|
1164
2831
|
}
|
|
1165
2832
|
}
|
|
1166
2833
|
visitBinary(t) {
|
|
1167
|
-
if (t.op ===
|
|
1168
|
-
return this.
|
|
1169
|
-
if (t.op ===
|
|
1170
|
-
return this.
|
|
1171
|
-
const
|
|
2834
|
+
if (t.op === h.LOGICAL_AND)
|
|
2835
|
+
return this.combine(t, !1);
|
|
2836
|
+
if (t.op === h.LOGICAL_OR)
|
|
2837
|
+
return this.combine(t, !0);
|
|
2838
|
+
const n = this.evaluate(t.left), i = this.evaluate(t.right);
|
|
1172
2839
|
switch (t.op) {
|
|
1173
|
-
case
|
|
1174
|
-
if (
|
|
1175
|
-
return
|
|
1176
|
-
if (
|
|
1177
|
-
return
|
|
1178
|
-
if (
|
|
1179
|
-
return
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
if (typeof
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
case c.MULTIPLY:
|
|
1186
|
-
if (typeof e == "number" && typeof i == "number")
|
|
1187
|
-
return e * i;
|
|
1188
|
-
if (typeof e == "string" && typeof i == "number")
|
|
1189
|
-
return e.repeat(i);
|
|
1190
|
-
if (Array.isArray(e) && typeof i == "number") {
|
|
1191
|
-
const n = [];
|
|
1192
|
-
for (let o = 0; o < i; o++)
|
|
1193
|
-
n.push(...e);
|
|
1194
|
-
return n;
|
|
2840
|
+
case h.ADD: {
|
|
2841
|
+
if (B(n) && B(i))
|
|
2842
|
+
return q(n.length + i.length, "Bytes concatenation"), Ne(n, i);
|
|
2843
|
+
if (n instanceof A && i instanceof I)
|
|
2844
|
+
return n.plus(i);
|
|
2845
|
+
if (n instanceof I && i instanceof A)
|
|
2846
|
+
return i.plus(n);
|
|
2847
|
+
if (n instanceof I && i instanceof I)
|
|
2848
|
+
return n.plus(i);
|
|
2849
|
+
if (typeof n == "string" || typeof i == "string") {
|
|
2850
|
+
const r = O(n), s = O(i);
|
|
2851
|
+
return q(r.length + s.length, "String concatenation"), r + s;
|
|
1195
2852
|
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
2853
|
+
if (Array.isArray(n) && Array.isArray(i))
|
|
2854
|
+
return q(n.length + i.length, "List concatenation"), [...n, ...i];
|
|
2855
|
+
if (C(n) && C(i))
|
|
2856
|
+
return this.arithmetic(
|
|
2857
|
+
n,
|
|
2858
|
+
i,
|
|
2859
|
+
(r, s) => r + s,
|
|
2860
|
+
(r, s) => r + s
|
|
2861
|
+
);
|
|
2862
|
+
throw new l("Invalid operands for addition");
|
|
2863
|
+
}
|
|
2864
|
+
case h.SUBTRACT: {
|
|
2865
|
+
if (n instanceof A && i instanceof A)
|
|
2866
|
+
return i.until(n);
|
|
2867
|
+
if (n instanceof A && i instanceof I || n instanceof I && i instanceof I)
|
|
2868
|
+
return n.minus(i);
|
|
2869
|
+
if (C(n) && C(i))
|
|
2870
|
+
return this.arithmetic(
|
|
2871
|
+
n,
|
|
2872
|
+
i,
|
|
2873
|
+
(r, s) => r - s,
|
|
2874
|
+
(r, s) => r - s
|
|
2875
|
+
);
|
|
2876
|
+
throw new l("Subtraction requires numeric operands");
|
|
2877
|
+
}
|
|
2878
|
+
case h.MULTIPLY: {
|
|
2879
|
+
if (C(n) && C(i))
|
|
2880
|
+
return this.arithmetic(
|
|
2881
|
+
n,
|
|
2882
|
+
i,
|
|
2883
|
+
(r, s) => r * s,
|
|
2884
|
+
(r, s) => r * s
|
|
2885
|
+
);
|
|
2886
|
+
if (typeof n == "string" && C(i)) {
|
|
2887
|
+
const r = this.repetitions(i, n.length);
|
|
2888
|
+
return n.repeat(r);
|
|
2889
|
+
}
|
|
2890
|
+
if (Array.isArray(n) && C(i)) {
|
|
2891
|
+
const r = this.repetitions(i, n.length), s = [];
|
|
2892
|
+
for (let c = 0; c < r; c++)
|
|
2893
|
+
s.push(...n);
|
|
2894
|
+
return s;
|
|
2895
|
+
}
|
|
2896
|
+
throw new l("Invalid operands for multiplication");
|
|
2897
|
+
}
|
|
2898
|
+
case h.DIVIDE: {
|
|
2899
|
+
if (C(n) && C(i)) {
|
|
2900
|
+
if (typeof n == "number" || typeof i == "number")
|
|
2901
|
+
return Number(n) / Number(i);
|
|
2902
|
+
if (i === 0n)
|
|
2903
|
+
throw new l("Division by zero");
|
|
2904
|
+
if (n === K && i === -1n)
|
|
2905
|
+
throw new l("Integer overflow");
|
|
2906
|
+
return n / i;
|
|
1202
2907
|
}
|
|
1203
|
-
throw new
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
2908
|
+
throw new l("Division requires numeric operands");
|
|
2909
|
+
}
|
|
2910
|
+
case h.MODULO: {
|
|
2911
|
+
if (typeof n == "bigint" && typeof i == "bigint") {
|
|
2912
|
+
if (i === 0n)
|
|
2913
|
+
throw new l("Modulo by zero");
|
|
2914
|
+
return n % i;
|
|
1209
2915
|
}
|
|
1210
|
-
throw new
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
2916
|
+
throw new l("Modulo requires integer operands");
|
|
2917
|
+
}
|
|
2918
|
+
case h.EQUAL:
|
|
2919
|
+
return j(n, i);
|
|
2920
|
+
case h.NOT_EQUAL:
|
|
2921
|
+
return !j(n, i);
|
|
2922
|
+
case h.LESS:
|
|
2923
|
+
return this.compare(n, i) < 0;
|
|
2924
|
+
case h.LESS_EQUAL:
|
|
2925
|
+
return this.compare(n, i) <= 0;
|
|
2926
|
+
case h.GREATER:
|
|
2927
|
+
return this.compare(n, i) > 0;
|
|
2928
|
+
case h.GREATER_EQUAL:
|
|
2929
|
+
return this.compare(n, i) >= 0;
|
|
2930
|
+
case h.IN: {
|
|
1224
2931
|
if (Array.isArray(i))
|
|
1225
|
-
return
|
|
1226
|
-
if (
|
|
1227
|
-
return
|
|
1228
|
-
if (typeof i == "string" && typeof
|
|
1229
|
-
return i.includes(
|
|
1230
|
-
throw new
|
|
2932
|
+
return lt(i, n);
|
|
2933
|
+
if (i instanceof Map)
|
|
2934
|
+
return ot(i, n);
|
|
2935
|
+
if (typeof i == "string" && typeof n == "string")
|
|
2936
|
+
return i.includes(n);
|
|
2937
|
+
throw new l("IN operator requires list, map, or string on right side");
|
|
2938
|
+
}
|
|
1231
2939
|
default:
|
|
1232
|
-
throw new
|
|
2940
|
+
throw new l(`Unknown binary operator: ${t.op}`);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
// Evaluates a logical operator: the absorbing value wins even when the other operand errors
|
|
2944
|
+
combine(t, n) {
|
|
2945
|
+
const i = this.attempt(t.left);
|
|
2946
|
+
if (i === n)
|
|
2947
|
+
return n;
|
|
2948
|
+
const r = this.attempt(t.right);
|
|
2949
|
+
if (r === n)
|
|
2950
|
+
return n;
|
|
2951
|
+
if (i instanceof Error)
|
|
2952
|
+
throw i;
|
|
2953
|
+
if (r instanceof Error)
|
|
2954
|
+
throw r;
|
|
2955
|
+
if (typeof i != "boolean" || typeof r != "boolean") {
|
|
2956
|
+
const s = oi[t.op] ?? t.op;
|
|
2957
|
+
throw new l(`Logical operator ${s} requires boolean operands`);
|
|
2958
|
+
}
|
|
2959
|
+
return !n;
|
|
2960
|
+
}
|
|
2961
|
+
// Evaluates an operand, returning the error instead of throwing it
|
|
2962
|
+
attempt(t) {
|
|
2963
|
+
try {
|
|
2964
|
+
return this.evaluate(t);
|
|
2965
|
+
} catch (n) {
|
|
2966
|
+
if (zt(n))
|
|
2967
|
+
return n;
|
|
2968
|
+
throw n;
|
|
1233
2969
|
}
|
|
1234
2970
|
}
|
|
1235
2971
|
visitConditional(t) {
|
|
1236
|
-
|
|
2972
|
+
const n = this.evaluate(t.condition);
|
|
2973
|
+
if (typeof n != "boolean")
|
|
2974
|
+
throw new l("Conditional requires a boolean condition");
|
|
2975
|
+
return n ? this.evaluate(t.thenExpr) : this.evaluate(t.otherwiseExpr);
|
|
1237
2976
|
}
|
|
1238
2977
|
visitIndex(t) {
|
|
1239
|
-
const
|
|
1240
|
-
if (
|
|
1241
|
-
throw new
|
|
1242
|
-
if (Array.isArray(
|
|
1243
|
-
if (
|
|
1244
|
-
throw new
|
|
1245
|
-
const
|
|
1246
|
-
if (
|
|
1247
|
-
throw new
|
|
1248
|
-
return
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
2978
|
+
const n = this.evaluate(t.operand), i = this.evaluate(t.index);
|
|
2979
|
+
if (n == null)
|
|
2980
|
+
throw new l("Cannot index null value");
|
|
2981
|
+
if (Array.isArray(n)) {
|
|
2982
|
+
if (!C(i))
|
|
2983
|
+
throw new l("List index must be an integer");
|
|
2984
|
+
const r = Number(typeof i == "number" ? Math.trunc(i) : i);
|
|
2985
|
+
if (r < 0 || r >= n.length)
|
|
2986
|
+
throw new l(`List index out of bounds: ${r}`);
|
|
2987
|
+
return n[r];
|
|
2988
|
+
}
|
|
2989
|
+
if (n instanceof Map) {
|
|
2990
|
+
if (!ot(n, i))
|
|
2991
|
+
throw new l(`Map key not found: ${O(i)}`);
|
|
2992
|
+
return an(n, i);
|
|
2993
|
+
}
|
|
2994
|
+
if (B(n)) {
|
|
2995
|
+
if (!C(i))
|
|
2996
|
+
throw new l("Bytes index must be an integer");
|
|
2997
|
+
const r = Number(typeof i == "number" ? Math.trunc(i) : i);
|
|
2998
|
+
if (r < 0 || r >= n.length)
|
|
2999
|
+
throw new l(`Bytes index out of bounds: ${r}`);
|
|
3000
|
+
return BigInt(n[r]);
|
|
3001
|
+
}
|
|
3002
|
+
if (typeof n == "string") {
|
|
3003
|
+
if (!C(i))
|
|
3004
|
+
throw new l("String index must be an integer");
|
|
3005
|
+
const r = Number(typeof i == "number" ? Math.trunc(i) : i), s = r < 0 ? -1 : Tt(n, r);
|
|
3006
|
+
if (s < 0 || s >= n.length)
|
|
3007
|
+
throw new l(`String index out of bounds: ${r}`);
|
|
3008
|
+
return String.fromCodePoint(n.codePointAt(s));
|
|
3009
|
+
}
|
|
3010
|
+
throw new l(`Cannot index type: ${W(n)}`);
|
|
3011
|
+
}
|
|
3012
|
+
// Validates a repetition count against the evaluation limit, before anything is allocated
|
|
3013
|
+
repetitions(t, n) {
|
|
3014
|
+
const i = typeof t == "bigint" ? t : BigInt(Math.trunc(t));
|
|
3015
|
+
if (i < 0n)
|
|
3016
|
+
throw new l(`Repetition count must not be negative: ${i}`);
|
|
3017
|
+
if (i > BigInt(D) || i * BigInt(n) > BigInt(D))
|
|
3018
|
+
throw new l(`Repetition exceeds the evaluation limit of ${D}`);
|
|
3019
|
+
return Number(i);
|
|
3020
|
+
}
|
|
3021
|
+
// Applies an arithmetic operator: two ints stay exact 64-bit, otherwise both become doubles
|
|
3022
|
+
arithmetic(t, n, i, r) {
|
|
3023
|
+
return typeof t == "bigint" && typeof n == "bigint" ? Le(i(t, n)) : r(Number(t), Number(n));
|
|
3024
|
+
}
|
|
3025
|
+
// Ordering for the relational operators
|
|
3026
|
+
compare(t, n) {
|
|
3027
|
+
if (t == null && n == null)
|
|
3028
|
+
return 0;
|
|
3029
|
+
if (t == null)
|
|
3030
|
+
return -1;
|
|
3031
|
+
if (n == null)
|
|
3032
|
+
return 1;
|
|
3033
|
+
if (Array.isArray(t) && Array.isArray(n)) {
|
|
3034
|
+
const i = Math.min(t.length, n.length);
|
|
3035
|
+
for (let r = 0; r < i; r++) {
|
|
3036
|
+
const s = this.compare(t[r], n[r]);
|
|
3037
|
+
if (s !== 0)
|
|
3038
|
+
return s;
|
|
3039
|
+
}
|
|
3040
|
+
return t.length - n.length;
|
|
3041
|
+
}
|
|
3042
|
+
try {
|
|
3043
|
+
return v(t, n);
|
|
3044
|
+
} catch (i) {
|
|
3045
|
+
throw zt(i) ? new l(
|
|
3046
|
+
`Cannot compare types: ${W(t)} and ${W(n)}`
|
|
3047
|
+
) : i;
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
class ui {
|
|
1265
3052
|
/**
|
|
1266
3053
|
* Creates a new compiled program.
|
|
1267
3054
|
*
|
|
@@ -1270,8 +3057,8 @@ class V {
|
|
|
1270
3057
|
* @param ast The abstract syntax tree of the compiled expression
|
|
1271
3058
|
* @param functions The function library to use for evaluation
|
|
1272
3059
|
*/
|
|
1273
|
-
constructor(t,
|
|
1274
|
-
this.ast = t, this.functions =
|
|
3060
|
+
constructor(t, n) {
|
|
3061
|
+
this.ast = t, this.functions = n;
|
|
1275
3062
|
}
|
|
1276
3063
|
/**
|
|
1277
3064
|
* Evaluates the compiled program with the given variables.
|
|
@@ -1290,12 +3077,12 @@ class V {
|
|
|
1290
3077
|
* ```
|
|
1291
3078
|
*/
|
|
1292
3079
|
evaluate(t = {}) {
|
|
1293
|
-
return new
|
|
3080
|
+
return new ci(t, this.functions).evaluate(this.ast);
|
|
1294
3081
|
}
|
|
1295
3082
|
}
|
|
1296
|
-
class
|
|
3083
|
+
class Rt {
|
|
1297
3084
|
constructor(t) {
|
|
1298
|
-
this.functions = t ?? new
|
|
3085
|
+
this.functions = t ?? new pe();
|
|
1299
3086
|
}
|
|
1300
3087
|
/**
|
|
1301
3088
|
* Compiles a CEL expression using the provided function library.
|
|
@@ -1313,9 +3100,9 @@ class R {
|
|
|
1313
3100
|
* const program = CEL.compile('x + y', new StandardFunctions());
|
|
1314
3101
|
* ```
|
|
1315
3102
|
*/
|
|
1316
|
-
static compile(t,
|
|
1317
|
-
const i = new
|
|
1318
|
-
return new
|
|
3103
|
+
static compile(t, n) {
|
|
3104
|
+
const i = new Re(t);
|
|
3105
|
+
return new ui(i.parse(), n);
|
|
1319
3106
|
}
|
|
1320
3107
|
/**
|
|
1321
3108
|
* Evaluates a CEL expression with the given variables using the provided function library.
|
|
@@ -1335,8 +3122,8 @@ class R {
|
|
|
1335
3122
|
* const result = CEL.eval('x * 2', new StandardFunctions(), { x: 5 });
|
|
1336
3123
|
* ```
|
|
1337
3124
|
*/
|
|
1338
|
-
static eval(t,
|
|
1339
|
-
return this.compile(t,
|
|
3125
|
+
static eval(t, n, i) {
|
|
3126
|
+
return this.compile(t, n).evaluate(i);
|
|
1340
3127
|
}
|
|
1341
3128
|
/**
|
|
1342
3129
|
* Compiles a CEL expression into a reusable program.
|
|
@@ -1357,7 +3144,7 @@ class R {
|
|
|
1357
3144
|
* ```
|
|
1358
3145
|
*/
|
|
1359
3146
|
compile(t) {
|
|
1360
|
-
return
|
|
3147
|
+
return Rt.compile(t, this.functions);
|
|
1361
3148
|
}
|
|
1362
3149
|
/**
|
|
1363
3150
|
* Evaluates a CEL expression with the given variables.
|
|
@@ -1379,36 +3166,291 @@ class R {
|
|
|
1379
3166
|
* });
|
|
1380
3167
|
* ```
|
|
1381
3168
|
*/
|
|
1382
|
-
eval(t,
|
|
1383
|
-
return
|
|
3169
|
+
eval(t, n = {}) {
|
|
3170
|
+
return Rt.eval(t, this.functions, n);
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
const it = 1, Et = 8, ai = 9;
|
|
3174
|
+
class et {
|
|
3175
|
+
/**
|
|
3176
|
+
* @param wrap Whether to break long constructs across lines
|
|
3177
|
+
* @param indent The number of spaces per indentation level
|
|
3178
|
+
* @param width The maximum line width before a construct is broken
|
|
3179
|
+
*/
|
|
3180
|
+
constructor(t, n, i) {
|
|
3181
|
+
this.wrap = t, this.indent = n, this.width = i;
|
|
3182
|
+
}
|
|
3183
|
+
/** Options for a single line rendering. */
|
|
3184
|
+
static compact() {
|
|
3185
|
+
return new et(!1, 0, Number.MAX_SAFE_INTEGER);
|
|
3186
|
+
}
|
|
3187
|
+
/** Options for a multi-line rendering indented by two spaces at a width of 100. */
|
|
3188
|
+
static pretty() {
|
|
3189
|
+
return new et(!0, 2, 100);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
class _ {
|
|
3193
|
+
constructor(t) {
|
|
3194
|
+
this.options = t, this.level = 0;
|
|
3195
|
+
}
|
|
3196
|
+
/**
|
|
3197
|
+
* Renders the given expression as CEL source.
|
|
3198
|
+
*
|
|
3199
|
+
* @param expr The expression to render
|
|
3200
|
+
* @param options The rendering options; compact by default
|
|
3201
|
+
* @returns The rendered text
|
|
3202
|
+
*/
|
|
3203
|
+
static print(t, n = et.compact()) {
|
|
3204
|
+
return new _(n).text(t);
|
|
3205
|
+
}
|
|
3206
|
+
static precedence(t) {
|
|
3207
|
+
if (t instanceof nn)
|
|
3208
|
+
return it;
|
|
3209
|
+
if (t instanceof X)
|
|
3210
|
+
switch (t.op) {
|
|
3211
|
+
case h.LOGICAL_OR:
|
|
3212
|
+
return 2;
|
|
3213
|
+
case h.LOGICAL_AND:
|
|
3214
|
+
return 3;
|
|
3215
|
+
case h.EQUAL:
|
|
3216
|
+
case h.NOT_EQUAL:
|
|
3217
|
+
case h.LESS:
|
|
3218
|
+
case h.LESS_EQUAL:
|
|
3219
|
+
case h.GREATER:
|
|
3220
|
+
case h.GREATER_EQUAL:
|
|
3221
|
+
case h.IN:
|
|
3222
|
+
return 4;
|
|
3223
|
+
case h.ADD:
|
|
3224
|
+
case h.SUBTRACT:
|
|
3225
|
+
return 5;
|
|
3226
|
+
case h.MULTIPLY:
|
|
3227
|
+
case h.DIVIDE:
|
|
3228
|
+
case h.MODULO:
|
|
3229
|
+
return 6;
|
|
3230
|
+
}
|
|
3231
|
+
return t instanceof At ? 7 : ai;
|
|
3232
|
+
}
|
|
3233
|
+
static spelling(t) {
|
|
3234
|
+
switch (t) {
|
|
3235
|
+
case h.ADD:
|
|
3236
|
+
return "+";
|
|
3237
|
+
case h.SUBTRACT:
|
|
3238
|
+
return "-";
|
|
3239
|
+
case h.MULTIPLY:
|
|
3240
|
+
return "*";
|
|
3241
|
+
case h.DIVIDE:
|
|
3242
|
+
return "/";
|
|
3243
|
+
case h.MODULO:
|
|
3244
|
+
return "%";
|
|
3245
|
+
case h.EQUAL:
|
|
3246
|
+
return "==";
|
|
3247
|
+
case h.NOT_EQUAL:
|
|
3248
|
+
return "!=";
|
|
3249
|
+
case h.LESS:
|
|
3250
|
+
return "<";
|
|
3251
|
+
case h.LESS_EQUAL:
|
|
3252
|
+
return "<=";
|
|
3253
|
+
case h.GREATER:
|
|
3254
|
+
return ">";
|
|
3255
|
+
case h.GREATER_EQUAL:
|
|
3256
|
+
return ">=";
|
|
3257
|
+
case h.LOGICAL_AND:
|
|
3258
|
+
return "&&";
|
|
3259
|
+
case h.LOGICAL_OR:
|
|
3260
|
+
return "||";
|
|
3261
|
+
case h.IN:
|
|
3262
|
+
return "in";
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
static decimal(t) {
|
|
3266
|
+
if (!Number.isFinite(t))
|
|
3267
|
+
throw new a(`Cannot render ${t} as a CEL literal`);
|
|
3268
|
+
return rn(t);
|
|
3269
|
+
}
|
|
3270
|
+
// Renders a node without any enclosing parentheses
|
|
3271
|
+
text(t) {
|
|
3272
|
+
if (this.options.wrap) {
|
|
3273
|
+
const n = _.print(t, et.compact());
|
|
3274
|
+
if (this.level * this.options.indent + n.length <= this.options.width)
|
|
3275
|
+
return n;
|
|
3276
|
+
}
|
|
3277
|
+
return t.accept(this);
|
|
3278
|
+
}
|
|
3279
|
+
// Renders a node, adding parentheses when its precedence is below the required level
|
|
3280
|
+
render(t, n) {
|
|
3281
|
+
const i = this.text(t);
|
|
3282
|
+
return _.precedence(t) < n ? `(${i})` : i;
|
|
3283
|
+
}
|
|
3284
|
+
// Renders children one level deeper when wrapping
|
|
3285
|
+
nested(t) {
|
|
3286
|
+
const n = this.options.wrap ? 1 : 0;
|
|
3287
|
+
this.level += n;
|
|
3288
|
+
try {
|
|
3289
|
+
return t();
|
|
3290
|
+
} finally {
|
|
3291
|
+
this.level -= n;
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
visitLiteral(t) {
|
|
3295
|
+
const n = t.value;
|
|
3296
|
+
switch (t.literalType) {
|
|
3297
|
+
case $.NULL_VALUE:
|
|
3298
|
+
return "null";
|
|
3299
|
+
case $.BOOL:
|
|
3300
|
+
case $.INT:
|
|
3301
|
+
return String(n);
|
|
3302
|
+
case $.UINT:
|
|
3303
|
+
return `${n}u`;
|
|
3304
|
+
case $.DOUBLE:
|
|
3305
|
+
return _.decimal(T(n));
|
|
3306
|
+
case $.STRING:
|
|
3307
|
+
return Pt(O(n));
|
|
3308
|
+
case $.BYTES:
|
|
3309
|
+
return `b"${Bn(ft(n))}"`;
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
visitIdentifier(t) {
|
|
3313
|
+
return t.name;
|
|
3314
|
+
}
|
|
3315
|
+
visitSelect(t) {
|
|
3316
|
+
const i = `${t.operand === null ? "" : this.render(t.operand, Et)}.${t.field}`;
|
|
3317
|
+
return t.isTest ? `has(${i})` : i;
|
|
3318
|
+
}
|
|
3319
|
+
visitCall(t) {
|
|
3320
|
+
const n = t.target === null ? "" : `${this.render(t.target, Et)}.`, i = this.nested(() => t.args.map((r) => this.text(r)));
|
|
3321
|
+
return `${n}${t.functionName}${this.group("(", i, ")")}`;
|
|
3322
|
+
}
|
|
3323
|
+
visitList(t) {
|
|
3324
|
+
return this.group("[", this.parts(t.elements), "]");
|
|
3325
|
+
}
|
|
3326
|
+
visitMap(t) {
|
|
3327
|
+
const n = this.nested(
|
|
3328
|
+
() => t.entries.map((i) => `${this.text(i.key)}: ${this.text(i.value)}`)
|
|
3329
|
+
);
|
|
3330
|
+
return this.group("{", n, "}");
|
|
3331
|
+
}
|
|
3332
|
+
visitStruct(t) {
|
|
3333
|
+
const n = this.nested(
|
|
3334
|
+
() => t.fields.map((i) => `${i.field}: ${this.text(i.value)}`)
|
|
3335
|
+
);
|
|
3336
|
+
return `${t.typeName ?? ""}${this.group("{", n, "}")}`;
|
|
3337
|
+
}
|
|
3338
|
+
visitComprehension(t) {
|
|
3339
|
+
const n = [
|
|
3340
|
+
t.variable,
|
|
3341
|
+
this.text(t.range),
|
|
3342
|
+
t.accumulator,
|
|
3343
|
+
this.text(t.initializer),
|
|
3344
|
+
this.text(t.condition),
|
|
3345
|
+
this.text(t.step),
|
|
3346
|
+
this.text(t.result)
|
|
3347
|
+
];
|
|
3348
|
+
return `__comprehension__${this.group("(", n, ")")}`;
|
|
3349
|
+
}
|
|
3350
|
+
visitUnary(t) {
|
|
3351
|
+
return (t.op === J.NOT ? "!" : "-") + this.render(t.operand, 7);
|
|
3352
|
+
}
|
|
3353
|
+
visitBinary(t) {
|
|
3354
|
+
const n = _.precedence(t), i = this.render(t.left, n), r = this.render(t.right, n + 1), s = _.spelling(t.op);
|
|
3355
|
+
return this.options.wrap && (t.op === h.LOGICAL_AND || t.op === h.LOGICAL_OR) ? `${i}
|
|
3356
|
+
${this.pad(this.level)}${s} ${r}` : `${i} ${s} ${r}`;
|
|
3357
|
+
}
|
|
3358
|
+
visitConditional(t) {
|
|
3359
|
+
const n = this.render(t.condition, it + 1), [i, r] = this.nested(() => [
|
|
3360
|
+
this.render(t.thenExpr, it + 1),
|
|
3361
|
+
this.render(t.otherwiseExpr, it)
|
|
3362
|
+
]);
|
|
3363
|
+
if (this.options.wrap) {
|
|
3364
|
+
const s = this.pad(this.level + 1);
|
|
3365
|
+
return `${n}
|
|
3366
|
+
${s}? ${i}
|
|
3367
|
+
${s}: ${r}`;
|
|
3368
|
+
}
|
|
3369
|
+
return `${n} ? ${i} : ${r}`;
|
|
3370
|
+
}
|
|
3371
|
+
visitIndex(t) {
|
|
3372
|
+
return `${this.render(t.operand, Et)}[${this.text(t.index)}]`;
|
|
3373
|
+
}
|
|
3374
|
+
parts(t) {
|
|
3375
|
+
return this.nested(() => t.map((n) => this.text(n)));
|
|
3376
|
+
}
|
|
3377
|
+
group(t, n, i) {
|
|
3378
|
+
if (!this.options.wrap || n.length === 0)
|
|
3379
|
+
return `${t}${n.join(", ")}${i}`;
|
|
3380
|
+
const r = this.pad(this.level + 1);
|
|
3381
|
+
return `${t}
|
|
3382
|
+
${r}${n.join(`,
|
|
3383
|
+
${r}`)}
|
|
3384
|
+
${this.pad(this.level)}${i}`;
|
|
3385
|
+
}
|
|
3386
|
+
pad(t) {
|
|
3387
|
+
return " ".repeat(t * this.options.indent);
|
|
1384
3388
|
}
|
|
1385
3389
|
}
|
|
1386
3390
|
export {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
3391
|
+
a as ArgumentError,
|
|
3392
|
+
X as Binary,
|
|
3393
|
+
h as BinaryOp,
|
|
3394
|
+
Rt as CEL,
|
|
3395
|
+
gt as Call,
|
|
3396
|
+
Ei as Codecs,
|
|
3397
|
+
hi as Comprehension,
|
|
3398
|
+
nn as Conditional,
|
|
3399
|
+
I as Duration,
|
|
3400
|
+
l as EvaluationError,
|
|
3401
|
+
me as FieldInitializer,
|
|
3402
|
+
at as INT64_MAX,
|
|
3403
|
+
K as INT64_MIN,
|
|
3404
|
+
It as Identifier,
|
|
3405
|
+
we as Index,
|
|
3406
|
+
ci as Interpreter,
|
|
3407
|
+
Qe as KeyMap,
|
|
3408
|
+
sn as KeySet,
|
|
3409
|
+
ge as ListExpression,
|
|
3410
|
+
gi as Lists,
|
|
3411
|
+
z as Literal,
|
|
3412
|
+
$ as LiteralType,
|
|
3413
|
+
be as MapEntry,
|
|
3414
|
+
jt as MapExpression,
|
|
3415
|
+
mi as Maths,
|
|
3416
|
+
U as ParseError,
|
|
3417
|
+
Re as Parser,
|
|
3418
|
+
_ as Printer,
|
|
3419
|
+
et as PrinterOptions,
|
|
3420
|
+
ui as Program,
|
|
3421
|
+
wi as Regexes,
|
|
3422
|
+
nt as Select,
|
|
3423
|
+
bi as Sets,
|
|
3424
|
+
pe as StandardFunctions,
|
|
3425
|
+
di as Strings,
|
|
3426
|
+
Qt as Struct,
|
|
3427
|
+
A as Timestamp,
|
|
3428
|
+
y as Type,
|
|
3429
|
+
At as Unary,
|
|
3430
|
+
J as UnaryOp,
|
|
3431
|
+
pi as Utilities,
|
|
3432
|
+
cn as asBool,
|
|
3433
|
+
ye as bytesCompare,
|
|
3434
|
+
Ae as bytesEqual,
|
|
3435
|
+
yt as bytesToHex,
|
|
3436
|
+
G as canonicalKey,
|
|
3437
|
+
Le as checkInt64,
|
|
3438
|
+
Me as civilFromDays,
|
|
3439
|
+
Ne as concatBytes,
|
|
3440
|
+
Bt as daysFromCivil,
|
|
3441
|
+
De as fieldsOf,
|
|
3442
|
+
B as isBytes,
|
|
3443
|
+
li as isDouble,
|
|
3444
|
+
fi as isInt,
|
|
3445
|
+
C as isNumeric,
|
|
3446
|
+
H as isPlainObject,
|
|
3447
|
+
rn as javaDoubleToString,
|
|
3448
|
+
Jt as normalize,
|
|
3449
|
+
bt as normalizeResult,
|
|
3450
|
+
Ct as order,
|
|
3451
|
+
Se as truncateToInt64,
|
|
3452
|
+
Nt as utcFields,
|
|
3453
|
+
en as utf8Decode,
|
|
3454
|
+
Mt as utf8Encode
|
|
1413
3455
|
};
|
|
1414
3456
|
//# sourceMappingURL=index.mjs.map
|