@libdbm/libcel-ts 1.0.2 → 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.d.ts
CHANGED
|
@@ -1,56 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Returns the absolute value, preserving the numeric type.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
|
|
4
|
+
* @throws EvaluationError if the value is the minimum int, whose magnitude is not representable
|
|
5
|
+
*/
|
|
6
|
+
declare function abs(value: unknown): bigint | number;
|
|
7
|
+
|
|
8
|
+
/** Returns the bitwise AND of two ints. */
|
|
9
|
+
declare function and(left: unknown, right: unknown): bigint;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a function receives an argument it cannot accept.
|
|
6
13
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
14
|
+
* This is the analogue of Java's IllegalArgumentException: wrong arity, an
|
|
15
|
+
* unsupported type, an out-of-range index or an unparsable literal. The logical
|
|
16
|
+
* operators absorb this error alongside EvaluationError.
|
|
9
17
|
*/
|
|
10
|
-
export declare
|
|
18
|
+
export declare class ArgumentError extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
/**
|
|
13
|
-
* Converts the given value to a
|
|
23
|
+
* Converts the given value to a boolean using common truthiness rules.
|
|
14
24
|
*
|
|
15
|
-
*
|
|
25
|
+
* Numbers are true if non-zero. Strings are true if non-empty. Collections and
|
|
26
|
+
* maps are true if non-empty. Null is false.
|
|
27
|
+
*/
|
|
28
|
+
export declare function asBool(value: unknown): boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Converts the given value to bytes, encoding a string as UTF-8.
|
|
16
32
|
*
|
|
17
|
-
* @
|
|
18
|
-
* @returns The converted number value
|
|
19
|
-
* @throws Error if the value cannot be converted
|
|
33
|
+
* @throws ArgumentError if the value cannot be converted
|
|
20
34
|
*/
|
|
21
|
-
declare function
|
|
35
|
+
declare function asBytes(value: unknown): Uint8Array;
|
|
22
36
|
|
|
23
37
|
/**
|
|
24
|
-
* Converts the given value to a
|
|
38
|
+
* Converts the given value to a double.
|
|
25
39
|
*
|
|
26
|
-
* Accepted inputs: number, string
|
|
40
|
+
* Accepted inputs: number, bigint, and string parsable as a decimal number.
|
|
27
41
|
*
|
|
28
|
-
* @
|
|
29
|
-
* @returns The converted integer value
|
|
30
|
-
* @throws Error if the value cannot be converted
|
|
42
|
+
* @throws ArgumentError if the value cannot be converted
|
|
31
43
|
*/
|
|
32
|
-
declare function
|
|
44
|
+
declare function asDouble(value: unknown): number;
|
|
33
45
|
|
|
34
46
|
/**
|
|
35
|
-
* Converts the given value to
|
|
47
|
+
* Converts the given value to a Duration: a Duration is returned as is and a
|
|
48
|
+
* string is parsed.
|
|
36
49
|
*
|
|
37
|
-
*
|
|
50
|
+
* @throws ArgumentError if the value cannot be converted
|
|
51
|
+
*/
|
|
52
|
+
declare function asDuration(value: unknown): Duration;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Converts the given value to a signed 64-bit integer.
|
|
38
56
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
57
|
+
* Accepted inputs: bigint, number (truncated toward zero), string holding a
|
|
58
|
+
* decimal integer, boolean (true = 1), and Timestamp (epoch seconds).
|
|
59
|
+
*
|
|
60
|
+
* @throws ArgumentError if the value cannot be converted
|
|
41
61
|
*/
|
|
42
|
-
declare function
|
|
62
|
+
declare function asInt(value: unknown): bigint;
|
|
43
63
|
|
|
44
64
|
/**
|
|
45
|
-
* Converts the given value to
|
|
65
|
+
* Converts the given value to its string representation.
|
|
46
66
|
*
|
|
47
|
-
*
|
|
67
|
+
* Returns "null" for null, decodes bytes as UTF-8, renders a Duration in the
|
|
68
|
+
* CEL form ("3600s"), a Timestamp in RFC 3339, a double the way Java does
|
|
69
|
+
* ("1.0", "1.0E10") and a Type as its bare name.
|
|
70
|
+
*/
|
|
71
|
+
declare function asString(value: unknown): string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Converts the given value to an unsigned 64-bit integer.
|
|
48
75
|
*
|
|
49
|
-
* @
|
|
50
|
-
* @returns The non-negative integer value
|
|
51
|
-
* @throws Error if the value is negative or cannot be converted
|
|
76
|
+
* @throws ArgumentError if the value is negative or cannot be converted
|
|
52
77
|
*/
|
|
53
|
-
declare function asUInt(value:
|
|
78
|
+
declare function asUInt(value: unknown): bigint;
|
|
54
79
|
|
|
55
80
|
/**
|
|
56
81
|
* Binary operation expression (+, -, *, /, etc.).
|
|
@@ -97,6 +122,20 @@ export declare enum BinaryOp {
|
|
|
97
122
|
LOGICAL_OR = "LOGICAL_OR"
|
|
98
123
|
}
|
|
99
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Orders two byte arrays lexicographically, then by length.
|
|
127
|
+
*
|
|
128
|
+
* Mirrors Java's `Arrays.compare(byte[], byte[])`, which compares each byte as a
|
|
129
|
+
* signed value.
|
|
130
|
+
*/
|
|
131
|
+
export declare function bytesCompare(left: Uint8Array, right: Uint8Array): number;
|
|
132
|
+
|
|
133
|
+
/** Compares two byte arrays by content. */
|
|
134
|
+
export declare function bytesEqual(left: Uint8Array, right: Uint8Array): boolean;
|
|
135
|
+
|
|
136
|
+
/** Renders bytes as lowercase hexadecimal, two digits per byte. */
|
|
137
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
138
|
+
|
|
100
139
|
/**
|
|
101
140
|
* Function or method call expression.
|
|
102
141
|
*/
|
|
@@ -109,6 +148,14 @@ export declare class Call implements Expression {
|
|
|
109
148
|
accept<T>(visitor: Visitor<T>): T;
|
|
110
149
|
}
|
|
111
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Returns a string that is equal for two values exactly when CEL equality holds.
|
|
153
|
+
*/
|
|
154
|
+
export declare function canonicalKey(value: unknown): string;
|
|
155
|
+
|
|
156
|
+
/** Returns the smallest double not less than the value. */
|
|
157
|
+
declare function ceil(value: unknown): number;
|
|
158
|
+
|
|
112
159
|
/**
|
|
113
160
|
* The main entry point for evaluating CEL expressions.
|
|
114
161
|
*
|
|
@@ -170,7 +217,7 @@ export declare class CEL {
|
|
|
170
217
|
* const result = CEL.eval('x * 2', new StandardFunctions(), { x: 5 });
|
|
171
218
|
* ```
|
|
172
219
|
*/
|
|
173
|
-
static eval(expression: string, functions: Functions, variables: Record<string,
|
|
220
|
+
static eval(expression: string, functions: Functions, variables: Record<string, unknown> | Map<string, unknown>): unknown;
|
|
174
221
|
/**
|
|
175
222
|
* Compiles a CEL expression into a reusable program.
|
|
176
223
|
*
|
|
@@ -210,21 +257,72 @@ export declare class CEL {
|
|
|
210
257
|
* });
|
|
211
258
|
* ```
|
|
212
259
|
*/
|
|
213
|
-
eval(expression: string, variables?: Record<string,
|
|
260
|
+
eval(expression: string, variables?: Record<string, unknown> | Map<string, unknown>): unknown;
|
|
214
261
|
}
|
|
215
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Returns the character at the given index as a single character string, or an
|
|
265
|
+
* empty string at the end.
|
|
266
|
+
*
|
|
267
|
+
* @throws ArgumentError if the index is out of range
|
|
268
|
+
*/
|
|
269
|
+
declare function charAt(value: string, index: bigint): string;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Verifies that an integer result fits in 64 bits.
|
|
273
|
+
*
|
|
274
|
+
* @param value The result of an integer operation
|
|
275
|
+
* @returns The value unchanged
|
|
276
|
+
* @throws EvaluationError if the value is outside the signed 64-bit range
|
|
277
|
+
*/
|
|
278
|
+
export declare function checkInt64(value: bigint): bigint;
|
|
279
|
+
|
|
280
|
+
/** The broken-down civil fields of an instant in some zone. */
|
|
281
|
+
declare interface CivilFields {
|
|
282
|
+
year: bigint;
|
|
283
|
+
/** Month of year, 1-12. */
|
|
284
|
+
month: number;
|
|
285
|
+
/** Day of month, 1-31. */
|
|
286
|
+
day: number;
|
|
287
|
+
hour: number;
|
|
288
|
+
minute: number;
|
|
289
|
+
second: number;
|
|
290
|
+
/** Day of week where Sunday is 0. */
|
|
291
|
+
weekday: number;
|
|
292
|
+
/** Day of year, 1-366. */
|
|
293
|
+
dayOfYear: number;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Returns the proleptic Gregorian date for a count of days since 1970-01-01.
|
|
298
|
+
*/
|
|
299
|
+
export declare function civilFromDays(days: bigint): {
|
|
300
|
+
year: bigint;
|
|
301
|
+
month: number;
|
|
302
|
+
day: number;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
declare namespace Codecs {
|
|
306
|
+
export {
|
|
307
|
+
encode,
|
|
308
|
+
decode,
|
|
309
|
+
text
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
export { Codecs }
|
|
313
|
+
|
|
314
|
+
/** Counts the Unicode code points in a string. */
|
|
315
|
+
declare function codePointCount(value: string): number;
|
|
316
|
+
|
|
216
317
|
/**
|
|
217
318
|
* Compares two values using a common set of rules.
|
|
218
319
|
*
|
|
219
|
-
* Supported comparisons: numbers (
|
|
220
|
-
* booleans,
|
|
320
|
+
* Supported comparisons: numbers (exactly, across int and double), strings (by
|
|
321
|
+
* UTF-16 code unit), booleans, timestamps, durations and bytes.
|
|
221
322
|
*
|
|
222
|
-
* @
|
|
223
|
-
* @param b The second value
|
|
224
|
-
* @returns A negative number, zero, or a positive number as a is less than, equal to, or greater than b
|
|
225
|
-
* @throws Error if the values cannot be compared
|
|
323
|
+
* @throws ArgumentError if the values cannot be compared
|
|
226
324
|
*/
|
|
227
|
-
declare function compare(a:
|
|
325
|
+
declare function compare(a: unknown, b: unknown): number;
|
|
228
326
|
|
|
229
327
|
/**
|
|
230
328
|
* Comprehension expression for advanced iteration constructs.
|
|
@@ -241,6 +339,9 @@ export declare class Comprehension implements Expression {
|
|
|
241
339
|
accept<T>(visitor: Visitor<T>): T;
|
|
242
340
|
}
|
|
243
341
|
|
|
342
|
+
/** Concatenates two byte arrays. */
|
|
343
|
+
export declare function concatBytes(left: Uint8Array, right: Uint8Array): Uint8Array;
|
|
344
|
+
|
|
244
345
|
/**
|
|
245
346
|
* Conditional (ternary) expression (condition ? then : otherwise).
|
|
246
347
|
*/
|
|
@@ -253,25 +354,154 @@ export declare class Conditional implements Expression {
|
|
|
253
354
|
}
|
|
254
355
|
|
|
255
356
|
/**
|
|
256
|
-
*
|
|
357
|
+
* Reports whether the map holds the given key, comparing keys the way CEL compares values.
|
|
257
358
|
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
|
|
359
|
+
* An integer key therefore matches a double probe of the same value, so
|
|
360
|
+
* membership, indexing and presence tests all agree.
|
|
361
|
+
*/
|
|
362
|
+
declare function contains(map: Map<unknown, unknown>, key: unknown): boolean;
|
|
363
|
+
|
|
364
|
+
/** Reports whether the list contains the value, using deep equality. */
|
|
365
|
+
declare function contains_2(values: unknown[], value: unknown): boolean;
|
|
366
|
+
|
|
367
|
+
/** Reports whether every element of the subset appears in the values. */
|
|
368
|
+
declare function contains_3(values: unknown[], subset: unknown[]): boolean;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Reports whether the array contains the value under CEL equality.
|
|
261
372
|
*/
|
|
262
|
-
declare function containsInArray(array:
|
|
373
|
+
declare function containsInArray(array: unknown[], value: unknown): boolean;
|
|
374
|
+
|
|
375
|
+
/** Returns the day of month (1-31) for the timestamp, in the zone or UTC. */
|
|
376
|
+
declare function dateOf(value: unknown, zone?: unknown): bigint;
|
|
263
377
|
|
|
264
378
|
/**
|
|
265
|
-
*
|
|
379
|
+
* Returns the number of days since 1970-01-01 for a proleptic Gregorian date.
|
|
266
380
|
*
|
|
267
|
-
* @param
|
|
268
|
-
* @param
|
|
269
|
-
* @
|
|
381
|
+
* @param year The year (may be zero or negative)
|
|
382
|
+
* @param month The month, 1-12
|
|
383
|
+
* @param day The day of month, 1-31
|
|
270
384
|
*/
|
|
271
|
-
declare function
|
|
385
|
+
export declare function daysFromCivil(year: bigint, month: number, day: number): bigint;
|
|
272
386
|
|
|
273
387
|
/**
|
|
274
|
-
*
|
|
388
|
+
* Decodes standard base64 text into bytes.
|
|
389
|
+
*
|
|
390
|
+
* Only the standard alphabet is accepted; padding is optional but must be
|
|
391
|
+
* well formed when present.
|
|
392
|
+
*
|
|
393
|
+
* @throws ArgumentError if the text is not valid base64
|
|
394
|
+
*/
|
|
395
|
+
declare function decode(value: unknown): Uint8Array;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Deep equality check for CEL values. Alias of {@link equals}.
|
|
399
|
+
*/
|
|
400
|
+
declare const deepEquals: typeof equals;
|
|
401
|
+
|
|
402
|
+
/** Removes duplicate elements under CEL equality, preserving first appearance order. */
|
|
403
|
+
declare function distinct(values: unknown[]): unknown[];
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* A CEL duration with nanosecond precision.
|
|
407
|
+
*
|
|
408
|
+
* Follows the java.time convention: `nanos` is always in `0..999_999_999` and the
|
|
409
|
+
* sign is carried by `seconds`, so -1.5s is `{ seconds: -2n, nanos: 500_000_000 }`.
|
|
410
|
+
*/
|
|
411
|
+
export declare class Duration {
|
|
412
|
+
readonly seconds: bigint;
|
|
413
|
+
readonly nanos: number;
|
|
414
|
+
/** The largest number of seconds a duration may span, per the CEL specification. */
|
|
415
|
+
static readonly SPAN = 315576000000n;
|
|
416
|
+
static readonly ZERO: Duration;
|
|
417
|
+
private constructor();
|
|
418
|
+
/**
|
|
419
|
+
* Creates a duration from seconds and a nanosecond adjustment, normalising the
|
|
420
|
+
* adjustment into the seconds.
|
|
421
|
+
*/
|
|
422
|
+
static ofSeconds(seconds: bigint, nanoAdjustment?: bigint): Duration;
|
|
423
|
+
static ofNanos(nanos: bigint): Duration;
|
|
424
|
+
static ofMillis(millis: bigint): Duration;
|
|
425
|
+
static ofMinutes(minutes: bigint): Duration;
|
|
426
|
+
static ofHours(hours: bigint): Duration;
|
|
427
|
+
/**
|
|
428
|
+
* Parses a CEL duration literal such as `"300ms"`, `"-1.5h"` or `"2h45m"`.
|
|
429
|
+
*
|
|
430
|
+
* Units are `ns`, `us`, `µs`, `ms`, `s`, `m` and `h`. The value is accumulated
|
|
431
|
+
* exactly and rounded half up to the nearest nanosecond.
|
|
432
|
+
*
|
|
433
|
+
* @throws ArgumentError if the format is invalid or the span exceeds ±10 000 years
|
|
434
|
+
*/
|
|
435
|
+
static parse(text: string): Duration;
|
|
436
|
+
/** Reports whether the value is a Duration. */
|
|
437
|
+
static isDuration(value: unknown): value is Duration;
|
|
438
|
+
isNegative(): boolean;
|
|
439
|
+
isZero(): boolean;
|
|
440
|
+
negated(): Duration;
|
|
441
|
+
plus(other: Duration): Duration;
|
|
442
|
+
minus(other: Duration): Duration;
|
|
443
|
+
/** The total length in nanoseconds. */
|
|
444
|
+
toNanos(): bigint;
|
|
445
|
+
/** The whole number of milliseconds, truncated toward zero. */
|
|
446
|
+
toMillis(): bigint;
|
|
447
|
+
/** The whole number of seconds, truncated toward negative infinity (the seconds field). */
|
|
448
|
+
toSeconds(): bigint;
|
|
449
|
+
/** The whole number of minutes, truncated toward zero. */
|
|
450
|
+
toMinutes(): bigint;
|
|
451
|
+
/** The whole number of hours, truncated toward zero. */
|
|
452
|
+
toHours(): bigint;
|
|
453
|
+
compareTo(other: Duration): number;
|
|
454
|
+
equals(other: unknown): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Renders the duration the way the CEL specification does: a seconds count with
|
|
457
|
+
* an `s` suffix, for example `"3600s"`, `"1.5s"` or `"-90s"`.
|
|
458
|
+
*/
|
|
459
|
+
toString(): string;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Parses a CEL duration string such as "300ms", "-1.5h" or "2h45m".
|
|
464
|
+
*
|
|
465
|
+
* @throws ArgumentError if the format or unit is invalid
|
|
466
|
+
*/
|
|
467
|
+
declare function duration(value: string): Duration;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Encodes bytes, or a string as UTF-8, in standard base64 with padding.
|
|
471
|
+
*
|
|
472
|
+
* @throws ArgumentError if the value cannot be converted to bytes
|
|
473
|
+
*/
|
|
474
|
+
declare function encode(value: unknown): string;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Compares two values for deep equality.
|
|
478
|
+
*
|
|
479
|
+
* Lists and maps are compared element by element, numbers are compared
|
|
480
|
+
* numerically across int and double, bytes by content, and NaN is never equal
|
|
481
|
+
* to anything.
|
|
482
|
+
*/
|
|
483
|
+
declare function equals(left: unknown, right: unknown): boolean;
|
|
484
|
+
|
|
485
|
+
/** Reports whether the two lists contain the same elements, ignoring order and duplicates. */
|
|
486
|
+
declare function equivalent(left: unknown[], right: unknown[]): boolean;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Escapes the string for inclusion in a CEL string literal, without the
|
|
490
|
+
* enclosing quotes.
|
|
491
|
+
*/
|
|
492
|
+
declare function escape_2(value: string): string;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Escapes bytes for inclusion in a CEL bytes literal, without the enclosing
|
|
496
|
+
* quotes.
|
|
497
|
+
*/
|
|
498
|
+
declare function escapeBytes(value: Uint8Array): string;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Error thrown by the interpreter when an expression cannot be evaluated.
|
|
502
|
+
*
|
|
503
|
+
* Covers undefined variables, type mismatches in operators, division by zero,
|
|
504
|
+
* integer overflow and evaluation limits.
|
|
275
505
|
*/
|
|
276
506
|
export declare class EvaluationError extends Error {
|
|
277
507
|
constructor(message: string);
|
|
@@ -292,6 +522,27 @@ export declare interface Expression {
|
|
|
292
522
|
accept<T>(visitor: Visitor<T>): T;
|
|
293
523
|
}
|
|
294
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Returns the first match of the pattern, or null when there is none.
|
|
527
|
+
*
|
|
528
|
+
* If the pattern declares a capture group, the first group is returned instead of
|
|
529
|
+
* the whole match.
|
|
530
|
+
*
|
|
531
|
+
* @throws ArgumentError if the pattern is invalid or declares more than one group
|
|
532
|
+
*/
|
|
533
|
+
declare function extract(value: string, pattern: string): string | null;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Returns every match of the pattern in the given text.
|
|
537
|
+
*
|
|
538
|
+
* If the pattern declares a capture group, the first group of each match is
|
|
539
|
+
* returned instead of the whole match; matches where the group did not
|
|
540
|
+
* participate are skipped.
|
|
541
|
+
*
|
|
542
|
+
* @throws ArgumentError if the pattern is invalid or declares more than one group
|
|
543
|
+
*/
|
|
544
|
+
declare function extractAll(value: string, pattern: string): string[];
|
|
545
|
+
|
|
295
546
|
/**
|
|
296
547
|
* Field initializer in a struct literal.
|
|
297
548
|
*/
|
|
@@ -301,6 +552,48 @@ export declare class FieldInitializer {
|
|
|
301
552
|
constructor(field: string, value: Expression);
|
|
302
553
|
}
|
|
303
554
|
|
|
555
|
+
/**
|
|
556
|
+
* Breaks a count of seconds since the epoch into civil fields in the given zone.
|
|
557
|
+
*
|
|
558
|
+
* @param seconds Seconds since 1970-01-01T00:00:00Z
|
|
559
|
+
* @param zone An IANA zone identifier, or null for UTC
|
|
560
|
+
*/
|
|
561
|
+
export declare function fieldsOf(seconds: bigint, zone: unknown): CivilFields;
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Returns the first element.
|
|
565
|
+
*
|
|
566
|
+
* @throws ArgumentError if the list is empty
|
|
567
|
+
*/
|
|
568
|
+
declare function first(values: unknown[]): unknown;
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Renders a double with the given number of fractional digits, rounding half up
|
|
572
|
+
* on its shortest decimal representation the way Java's
|
|
573
|
+
* `BigDecimal.valueOf(d).setScale(p, HALF_UP)` does.
|
|
574
|
+
*/
|
|
575
|
+
declare function fixed(value: number, precision: number): string;
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Flattens nested lists to the requested depth.
|
|
579
|
+
*
|
|
580
|
+
* @throws ArgumentError if the depth is less than 1
|
|
581
|
+
*/
|
|
582
|
+
declare function flatten(values: unknown[], depth?: bigint): unknown[];
|
|
583
|
+
|
|
584
|
+
/** Returns the largest double not greater than the value. */
|
|
585
|
+
declare function floor(value: unknown): number;
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Formats a string using the CEL format verbs.
|
|
589
|
+
*
|
|
590
|
+
* Supported verbs are %s, %d, %f, %e, %b, %o, %x, %X and %%, each accepting an
|
|
591
|
+
* optional precision such as %.3f.
|
|
592
|
+
*
|
|
593
|
+
* @throws ArgumentError if a verb is unknown or the argument count does not match
|
|
594
|
+
*/
|
|
595
|
+
declare function format(template: string, args: unknown[]): string;
|
|
596
|
+
|
|
304
597
|
/**
|
|
305
598
|
* Interface for providing functions to CEL expressions.
|
|
306
599
|
*
|
|
@@ -330,6 +623,18 @@ export declare interface Functions {
|
|
|
330
623
|
* @throws Error if the function is not found or if the arguments are invalid
|
|
331
624
|
*/
|
|
332
625
|
callFunction(name: string, args: any[]): any;
|
|
626
|
+
/**
|
|
627
|
+
* Reports whether this library provides a qualified global function with the given name.
|
|
628
|
+
*
|
|
629
|
+
* The interpreter uses this to resolve namespaced calls such as `math.greatest(1, 2)`,
|
|
630
|
+
* which would otherwise be parsed as a field selection followed by a method call. Only
|
|
631
|
+
* names that are not shadowed by a bound variable are ever tested. Implementations that
|
|
632
|
+
* omit this method provide no namespaced functions.
|
|
633
|
+
*
|
|
634
|
+
* @param name The qualified function name, for example "math.greatest"
|
|
635
|
+
* @returns true if the name should be dispatched to callFunction
|
|
636
|
+
*/
|
|
637
|
+
knows?(name: string): boolean;
|
|
333
638
|
/**
|
|
334
639
|
* Calls a method on a target object.
|
|
335
640
|
*
|
|
@@ -343,13 +648,24 @@ export declare interface Functions {
|
|
|
343
648
|
}
|
|
344
649
|
|
|
345
650
|
/**
|
|
346
|
-
*
|
|
651
|
+
* Returns the largest of the given values; a single list argument is spread.
|
|
652
|
+
*
|
|
653
|
+
* @throws ArgumentError if no values are given or they are not comparable
|
|
654
|
+
*/
|
|
655
|
+
declare function greatest(values: unknown[]): unknown;
|
|
656
|
+
|
|
657
|
+
/** Counts the capture groups a pattern declares. */
|
|
658
|
+
declare function groupCount(pattern: string): number;
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Checks whether a map contains the given key.
|
|
347
662
|
*
|
|
348
|
-
* @
|
|
349
|
-
* @param field The field/key to look for (must be a string)
|
|
350
|
-
* @returns true if target is a Map/object and contains the given key; false otherwise
|
|
663
|
+
* @returns true if target is a map and contains the key under CEL equality; false otherwise
|
|
351
664
|
*/
|
|
352
|
-
declare function has(target:
|
|
665
|
+
declare function has(target: unknown, field: unknown): boolean;
|
|
666
|
+
|
|
667
|
+
/** Returns the hour of day for a timestamp, or the whole number of hours in a duration. */
|
|
668
|
+
declare function hoursOf(value: unknown, zone?: unknown): bigint;
|
|
353
669
|
|
|
354
670
|
/**
|
|
355
671
|
* Identifier expression (variable reference).
|
|
@@ -370,45 +686,189 @@ export declare class Index implements Expression {
|
|
|
370
686
|
accept<T>(visitor: Visitor<T>): T;
|
|
371
687
|
}
|
|
372
688
|
|
|
689
|
+
/**
|
|
690
|
+
* Returns the index of the first occurrence of a substring at or after the
|
|
691
|
+
* offset, or -1 when absent.
|
|
692
|
+
*
|
|
693
|
+
* @throws ArgumentError if the offset is out of range
|
|
694
|
+
*/
|
|
695
|
+
declare function indexOf(value: string, search: string, start?: bigint): bigint;
|
|
696
|
+
|
|
697
|
+
/** Largest signed 64-bit integer. */
|
|
698
|
+
export declare const INT64_MAX: bigint;
|
|
699
|
+
|
|
700
|
+
/** Smallest signed 64-bit integer. */
|
|
701
|
+
export declare const INT64_MIN: bigint;
|
|
702
|
+
|
|
373
703
|
/**
|
|
374
704
|
* Interpreter for evaluating CEL expressions.
|
|
375
705
|
*
|
|
376
706
|
* Implements the Visitor pattern to traverse and evaluate the AST produced by the parser.
|
|
377
707
|
* Supports all CEL operations including macros, type conversions, and complex expressions.
|
|
708
|
+
*
|
|
709
|
+
* Variables are normalised into the CEL value model on construction: integer-valued
|
|
710
|
+
* numbers become `bigint`, plain objects become `Map`, and `Date` becomes `Timestamp`.
|
|
711
|
+
*
|
|
712
|
+
* Note: an Interpreter is not safe to share between concurrent evaluations; the
|
|
713
|
+
* variable scope is mutated while macros run.
|
|
378
714
|
*/
|
|
379
|
-
export declare class Interpreter implements Visitor<
|
|
715
|
+
export declare class Interpreter implements Visitor<unknown> {
|
|
380
716
|
private readonly variables;
|
|
381
717
|
private readonly functions;
|
|
382
718
|
/**
|
|
383
719
|
* Constructs an interpreter with the specified variables and functions.
|
|
384
720
|
*
|
|
385
|
-
* @param variables
|
|
386
|
-
* @param functions
|
|
721
|
+
* @param variables Variable bindings as a plain object or Map. If null, no variables are bound.
|
|
722
|
+
* @param functions The function library. If null, StandardFunctions is used.
|
|
387
723
|
*/
|
|
388
|
-
constructor(variables?: Record<string,
|
|
724
|
+
constructor(variables?: Record<string, unknown> | Map<string, unknown> | null, functions?: Functions | null);
|
|
389
725
|
/**
|
|
390
726
|
* Evaluates a CEL expression and returns its result.
|
|
391
727
|
*
|
|
392
|
-
* @param expr The expression to evaluate
|
|
393
|
-
* @returns The result of the evaluation
|
|
394
728
|
* @throws EvaluationError if evaluation fails
|
|
395
729
|
*/
|
|
396
|
-
evaluate(expr: Expression):
|
|
397
|
-
visitLiteral(expr: Literal):
|
|
398
|
-
visitIdentifier(expr: Identifier):
|
|
399
|
-
visitSelect(expr: Select):
|
|
400
|
-
visitCall(expr: Call):
|
|
730
|
+
evaluate(expr: Expression): unknown;
|
|
731
|
+
visitLiteral(expr: Literal): unknown;
|
|
732
|
+
visitIdentifier(expr: Identifier): unknown;
|
|
733
|
+
visitSelect(expr: Select): unknown;
|
|
734
|
+
visitCall(expr: Call): unknown;
|
|
735
|
+
private knows;
|
|
736
|
+
private qualify;
|
|
737
|
+
private root;
|
|
401
738
|
private evaluateMacro;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
739
|
+
private test;
|
|
740
|
+
visitList(expr: ListExpression): unknown;
|
|
741
|
+
visitMap(expr: MapExpression): unknown;
|
|
742
|
+
visitStruct(expr: Struct): unknown;
|
|
743
|
+
visitComprehension(expr: Comprehension): unknown;
|
|
744
|
+
visitUnary(expr: Unary): unknown;
|
|
745
|
+
visitBinary(expr: Binary): unknown;
|
|
746
|
+
private combine;
|
|
747
|
+
private attempt;
|
|
748
|
+
visitConditional(expr: Conditional): unknown;
|
|
749
|
+
visitIndex(expr: Index): unknown;
|
|
750
|
+
private repetitions;
|
|
751
|
+
private arithmetic;
|
|
752
|
+
private compare;
|
|
410
753
|
}
|
|
411
754
|
|
|
755
|
+
/** Reports whether the two lists share at least one element. */
|
|
756
|
+
declare function intersects(left: unknown[], right: unknown[]): boolean;
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Helpers for the CEL bytes type, represented as Uint8Array.
|
|
760
|
+
*/
|
|
761
|
+
/** Reports whether the value is a CEL bytes value. */
|
|
762
|
+
export declare function isBytes(value: unknown): value is Uint8Array;
|
|
763
|
+
|
|
764
|
+
/** Reports whether the value is a CEL double (a number). */
|
|
765
|
+
export declare function isDouble(value: unknown): value is number;
|
|
766
|
+
|
|
767
|
+
/** Reports whether the value is neither NaN nor infinite. */
|
|
768
|
+
declare function isFinite_2(value: unknown): boolean;
|
|
769
|
+
|
|
770
|
+
/** Reports whether the value is positive or negative infinity. */
|
|
771
|
+
declare function isInf(value: unknown): boolean;
|
|
772
|
+
|
|
773
|
+
/** Reports whether the value is a CEL int (a bigint). */
|
|
774
|
+
export declare function isInt(value: unknown): value is bigint;
|
|
775
|
+
|
|
776
|
+
/** Reports whether the value is a CEL map (a Map, or a plain object not yet normalised). */
|
|
777
|
+
declare function isMap(value: unknown): value is Map<unknown, unknown>;
|
|
778
|
+
|
|
779
|
+
/** Reports whether the value is NaN. */
|
|
780
|
+
declare function isNaN_2(value: unknown): boolean;
|
|
781
|
+
|
|
782
|
+
/** Reports whether the value is a CEL int or double. */
|
|
783
|
+
export declare function isNumeric(value: unknown): value is bigint | number;
|
|
784
|
+
|
|
785
|
+
/** Reports whether the value is a plain object (not a class instance). */
|
|
786
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Renders a double the way Java's `Double.toString` does.
|
|
790
|
+
*
|
|
791
|
+
* Values with magnitude in [1e-3, 1e7) print in plain decimal notation with at
|
|
792
|
+
* least one fractional digit (`1.0`, `3.14`); everything else prints in
|
|
793
|
+
* computerised scientific notation (`1.0E10`, `1.234E-5`).
|
|
794
|
+
*/
|
|
795
|
+
export declare function javaDoubleToString(value: number): string;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Joins a list of strings with the given separator.
|
|
799
|
+
*
|
|
800
|
+
* @throws ArgumentError if any element is not a string
|
|
801
|
+
*/
|
|
802
|
+
declare function join(values: unknown[], separator: string): string;
|
|
803
|
+
|
|
804
|
+
/** A map from CEL values to arbitrary values, keyed by CEL equality. */
|
|
805
|
+
export declare class KeyMap<V> {
|
|
806
|
+
private readonly entries;
|
|
807
|
+
set(key: unknown, value: V): void;
|
|
808
|
+
get(key: unknown): V | undefined;
|
|
809
|
+
has(key: unknown): boolean;
|
|
810
|
+
get size(): number;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** A set of CEL values keyed by CEL equality. */
|
|
814
|
+
export declare class KeySet {
|
|
815
|
+
private readonly keys;
|
|
816
|
+
/** Adds the value; returns true if it was not already present. */
|
|
817
|
+
add(value: unknown): boolean;
|
|
818
|
+
has(value: unknown): boolean;
|
|
819
|
+
get size(): number;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Returns the last element.
|
|
824
|
+
*
|
|
825
|
+
* @throws ArgumentError if the list is empty
|
|
826
|
+
*/
|
|
827
|
+
declare function last(values: unknown[]): unknown;
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Returns the index of the last occurrence of a substring, searching backwards
|
|
831
|
+
* from the offset when one is given, or -1 when absent.
|
|
832
|
+
*
|
|
833
|
+
* @throws ArgumentError if the offset is out of range
|
|
834
|
+
*/
|
|
835
|
+
declare function lastIndexOf(value: string, search: string, start?: bigint): bigint;
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Returns the smallest of the given values; a single list argument is spread.
|
|
839
|
+
*
|
|
840
|
+
* @throws ArgumentError if no values are given or they are not comparable
|
|
841
|
+
*/
|
|
842
|
+
declare function least(values: unknown[]): unknown;
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* Shifts an int left by the given number of bits, wrapping at 64 bits.
|
|
846
|
+
*
|
|
847
|
+
* @throws ArgumentError if the count is negative
|
|
848
|
+
*/
|
|
849
|
+
declare function left(value: unknown, count: unknown): bigint;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* The largest collection or string an expression may generate.
|
|
853
|
+
*
|
|
854
|
+
* CEL evaluates untrusted input, so operations whose size is controlled by the
|
|
855
|
+
* expression itself refuse to allocate beyond this ceiling rather than exhausting
|
|
856
|
+
* the heap.
|
|
857
|
+
*/
|
|
858
|
+
declare const LIMIT = 1000000;
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Refuses a result that would exceed {@link LIMIT}.
|
|
862
|
+
*
|
|
863
|
+
* Bounding each operation's output, and not only its inputs, is what stops two
|
|
864
|
+
* separately legal values from being combined into one that exhausts the heap.
|
|
865
|
+
*
|
|
866
|
+
* @param size The size the operation is about to produce
|
|
867
|
+
* @param what The operation being bounded, named in the error message
|
|
868
|
+
* @throws EvaluationError if the size exceeds the limit
|
|
869
|
+
*/
|
|
870
|
+
declare function limit(size: number | bigint, what: string): void;
|
|
871
|
+
|
|
412
872
|
/**
|
|
413
873
|
* List literal expression ([1, 2, 3]).
|
|
414
874
|
*/
|
|
@@ -418,6 +878,21 @@ export declare class ListExpression implements Expression {
|
|
|
418
878
|
accept<T>(visitor: Visitor<T>): T;
|
|
419
879
|
}
|
|
420
880
|
|
|
881
|
+
declare namespace Lists {
|
|
882
|
+
export {
|
|
883
|
+
distinct,
|
|
884
|
+
flatten,
|
|
885
|
+
reverse_2 as reverse,
|
|
886
|
+
slice,
|
|
887
|
+
sort,
|
|
888
|
+
first,
|
|
889
|
+
last,
|
|
890
|
+
range,
|
|
891
|
+
contains_2 as contains
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
export { Lists }
|
|
895
|
+
|
|
421
896
|
/**
|
|
422
897
|
* Literal value expression (null, boolean, number, string, bytes).
|
|
423
898
|
*/
|
|
@@ -441,6 +916,9 @@ export declare enum LiteralType {
|
|
|
441
916
|
BYTES = "BYTES"
|
|
442
917
|
}
|
|
443
918
|
|
|
919
|
+
/** Lowercases the ASCII letters of the string, leaving other characters untouched. */
|
|
920
|
+
declare function lower(value: string): string;
|
|
921
|
+
|
|
444
922
|
/**
|
|
445
923
|
* Map entry (key-value pair in a map literal).
|
|
446
924
|
*/
|
|
@@ -462,36 +940,111 @@ export declare class MapExpression implements Expression {
|
|
|
462
940
|
/**
|
|
463
941
|
* Tests whether the given regular expression matches any part of the text.
|
|
464
942
|
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
* @param text The input text
|
|
468
|
-
* @param pattern The regular expression pattern
|
|
469
|
-
* @returns true if the pattern matches anywhere in the text; false otherwise
|
|
470
|
-
* @throws Error if the pattern is invalid
|
|
943
|
+
* @throws ArgumentError if the pattern is invalid
|
|
471
944
|
*/
|
|
472
945
|
declare function matches(text: string, pattern: string): boolean;
|
|
473
946
|
|
|
947
|
+
declare namespace Maths {
|
|
948
|
+
export {
|
|
949
|
+
greatest,
|
|
950
|
+
least,
|
|
951
|
+
abs,
|
|
952
|
+
ceil,
|
|
953
|
+
floor,
|
|
954
|
+
round,
|
|
955
|
+
trunc,
|
|
956
|
+
sign,
|
|
957
|
+
sqrt,
|
|
958
|
+
isNaN_2 as isNaN,
|
|
959
|
+
isInf,
|
|
960
|
+
isFinite_2 as isFinite,
|
|
961
|
+
and,
|
|
962
|
+
or,
|
|
963
|
+
xor,
|
|
964
|
+
not,
|
|
965
|
+
left,
|
|
966
|
+
right
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
export { Maths }
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Returns the maximum element from a non-empty list of values.
|
|
973
|
+
*
|
|
974
|
+
* @throws ArgumentError if the list is empty or values are not comparable
|
|
975
|
+
*/
|
|
976
|
+
declare function max(values: unknown[]): unknown;
|
|
977
|
+
|
|
978
|
+
/** Returns the millisecond for a timestamp, or the whole number of milliseconds in a duration. */
|
|
979
|
+
declare function millisecondsOf(value: unknown, zone?: unknown): bigint;
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Returns the minimum element from a non-empty list of values.
|
|
983
|
+
*
|
|
984
|
+
* @throws ArgumentError if the list is empty or values are not comparable
|
|
985
|
+
*/
|
|
986
|
+
declare function min(values: unknown[]): unknown;
|
|
987
|
+
|
|
988
|
+
/** Returns the minute for a timestamp, or the whole number of minutes in a duration. */
|
|
989
|
+
declare function minutesOf(value: unknown, zone?: unknown): bigint;
|
|
990
|
+
|
|
991
|
+
/** Returns the zero-based month (0-11) for the timestamp, in the zone or UTC. */
|
|
992
|
+
declare function monthOf(value: unknown, zone?: unknown): bigint;
|
|
993
|
+
|
|
474
994
|
/**
|
|
475
|
-
*
|
|
995
|
+
* Converts a JavaScript value into the CEL value model.
|
|
996
|
+
*
|
|
997
|
+
* Applied to variables entering `Program.evaluate()` and to the results of
|
|
998
|
+
* custom functions, so that every code path inside the interpreter sees exactly
|
|
999
|
+
* one representation per CEL type:
|
|
1000
|
+
*
|
|
1001
|
+
* - `undefined` becomes `null`
|
|
1002
|
+
* - integer-valued numbers become `bigint` (CEL int); other numbers stay doubles
|
|
1003
|
+
* - `Date` becomes `Timestamp`
|
|
1004
|
+
* - arrays are copied with normalised elements
|
|
1005
|
+
* - `Map` instances are copied with normalised keys and values
|
|
1006
|
+
* - plain objects become `Map<string, unknown>`
|
|
1007
|
+
* - `bigint`, `string`, `boolean`, `Uint8Array`, `Timestamp`, `Duration` and `Type`
|
|
1008
|
+
* pass through; other class instances are left as they are
|
|
476
1009
|
*
|
|
477
|
-
*
|
|
1010
|
+
* @throws ArgumentError if the value contains a cycle
|
|
1011
|
+
*/
|
|
1012
|
+
export declare function normalize(value: unknown): unknown;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Converts a value returned by a function into the CEL value model.
|
|
478
1016
|
*
|
|
479
|
-
* @
|
|
480
|
-
*
|
|
481
|
-
*
|
|
1017
|
+
* Like {@link normalize}, except that numbers are left as doubles: a function
|
|
1018
|
+
* returning a JavaScript number has produced a CEL double, and one that wants to
|
|
1019
|
+
* return an int returns a `bigint`.
|
|
482
1020
|
*/
|
|
483
|
-
declare function
|
|
1021
|
+
export declare function normalizeResult(value: unknown): unknown;
|
|
1022
|
+
|
|
1023
|
+
/** Returns the bitwise complement of an int. */
|
|
1024
|
+
declare function not(value: unknown): bigint;
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns the UTF-16 offset of the given code point index, or -1 when the index
|
|
1028
|
+
* exceeds the number of code points.
|
|
1029
|
+
*/
|
|
1030
|
+
declare function offsetByCodePoints(value: string, index: number): number;
|
|
1031
|
+
|
|
1032
|
+
/** Returns the bitwise OR of two ints. */
|
|
1033
|
+
declare function or(left: unknown, right: unknown): bigint;
|
|
484
1034
|
|
|
485
1035
|
/**
|
|
486
|
-
*
|
|
1036
|
+
* Orders two numbers exactly, without the precision loss of a double conversion.
|
|
487
1037
|
*
|
|
488
|
-
*
|
|
1038
|
+
* Two ints compare as integers and two doubles as doubles. A mixed pair is
|
|
1039
|
+
* compared exactly, so an int above the range a double can represent is not
|
|
1040
|
+
* mistaken for the double it would round to.
|
|
489
1041
|
*
|
|
490
|
-
* @
|
|
491
|
-
* @returns The minimum value in the array
|
|
492
|
-
* @throws Error if the array is empty or values are not comparable
|
|
1042
|
+
* @returns A negative number, zero, or a positive number
|
|
493
1043
|
*/
|
|
494
|
-
declare function
|
|
1044
|
+
export declare function order(left: bigint | number, right: bigint | number): number;
|
|
1045
|
+
|
|
1046
|
+
/** Returns the zero-based day of year for the timestamp. */
|
|
1047
|
+
declare function ordinalOf(value: unknown, zone?: unknown): bigint;
|
|
495
1048
|
|
|
496
1049
|
/**
|
|
497
1050
|
* ParseError is thrown when the lexer or parser encounters invalid syntax.
|
|
@@ -509,6 +1062,7 @@ export declare class ParseError extends Error {
|
|
|
509
1062
|
export declare class Parser {
|
|
510
1063
|
private readonly lexer;
|
|
511
1064
|
private current;
|
|
1065
|
+
private depth;
|
|
512
1066
|
constructor(input: string);
|
|
513
1067
|
/**
|
|
514
1068
|
* Parse a CEL expression from the input string.
|
|
@@ -525,6 +1079,7 @@ export declare class Parser {
|
|
|
525
1079
|
private parseUnary;
|
|
526
1080
|
private parseMember;
|
|
527
1081
|
private parsePrimary;
|
|
1082
|
+
private test;
|
|
528
1083
|
private parseListLiteral;
|
|
529
1084
|
private parseMapOrStructLiteral;
|
|
530
1085
|
private parseExprList;
|
|
@@ -536,8 +1091,18 @@ export declare class Parser {
|
|
|
536
1091
|
private parseLiteral;
|
|
537
1092
|
private parseIntLiteral;
|
|
538
1093
|
private parseUintLiteral;
|
|
1094
|
+
private checkRange;
|
|
539
1095
|
private parseStringLiteral;
|
|
540
1096
|
private parseBytesLiteral;
|
|
1097
|
+
/**
|
|
1098
|
+
* Decodes the escapes of a bytes literal.
|
|
1099
|
+
*
|
|
1100
|
+
* Character escapes and plain text accumulate in a pending buffer that is
|
|
1101
|
+
* UTF-8 encoded when flushed, while \xHH and octal escapes write a raw byte.
|
|
1102
|
+
*/
|
|
1103
|
+
private unescapeBytes;
|
|
1104
|
+
private simpleEscape;
|
|
1105
|
+
private isOctal;
|
|
541
1106
|
private unescapeString;
|
|
542
1107
|
private isLiteralToken;
|
|
543
1108
|
private isRelationalOp;
|
|
@@ -550,6 +1115,79 @@ export declare class Parser {
|
|
|
550
1115
|
private isQualifiedStructLiteral;
|
|
551
1116
|
}
|
|
552
1117
|
|
|
1118
|
+
/**
|
|
1119
|
+
* Renders an expression tree back into CEL source text.
|
|
1120
|
+
*
|
|
1121
|
+
* The compact form is a single line that parses back into an equivalent tree,
|
|
1122
|
+
* with parentheses only where operator precedence requires them. The pretty form
|
|
1123
|
+
* breaks lists, maps, structs, argument lists and logical chains across lines
|
|
1124
|
+
* once they no longer fit within the configured width.
|
|
1125
|
+
*
|
|
1126
|
+
* Expressions built by the parser always round-trip. A {@link Comprehension},
|
|
1127
|
+
* which the parser never produces, is rendered in a diagnostic form that is not
|
|
1128
|
+
* valid CEL.
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```typescript
|
|
1132
|
+
* const expr = new Parser('a + (b * c)').parse();
|
|
1133
|
+
* Printer.print(expr); // 'a + b * c'
|
|
1134
|
+
* Printer.print(expr, PrinterOptions.pretty()); // same, it fits on one line
|
|
1135
|
+
* ```
|
|
1136
|
+
*/
|
|
1137
|
+
export declare class Printer implements Visitor<string> {
|
|
1138
|
+
private readonly options;
|
|
1139
|
+
private level;
|
|
1140
|
+
private constructor();
|
|
1141
|
+
/**
|
|
1142
|
+
* Renders the given expression as CEL source.
|
|
1143
|
+
*
|
|
1144
|
+
* @param expr The expression to render
|
|
1145
|
+
* @param options The rendering options; compact by default
|
|
1146
|
+
* @returns The rendered text
|
|
1147
|
+
*/
|
|
1148
|
+
static print(expr: Expression, options?: PrinterOptions): string;
|
|
1149
|
+
private static precedence;
|
|
1150
|
+
private static spelling;
|
|
1151
|
+
private static decimal;
|
|
1152
|
+
private text;
|
|
1153
|
+
private render;
|
|
1154
|
+
private nested;
|
|
1155
|
+
visitLiteral(expr: Literal): string;
|
|
1156
|
+
visitIdentifier(expr: Identifier): string;
|
|
1157
|
+
visitSelect(expr: Select): string;
|
|
1158
|
+
visitCall(expr: Call): string;
|
|
1159
|
+
visitList(expr: ListExpression): string;
|
|
1160
|
+
visitMap(expr: MapExpression): string;
|
|
1161
|
+
visitStruct(expr: Struct): string;
|
|
1162
|
+
visitComprehension(expr: Comprehension): string;
|
|
1163
|
+
visitUnary(expr: Unary): string;
|
|
1164
|
+
visitBinary(expr: Binary): string;
|
|
1165
|
+
visitConditional(expr: Conditional): string;
|
|
1166
|
+
visitIndex(expr: Index): string;
|
|
1167
|
+
private parts;
|
|
1168
|
+
private group;
|
|
1169
|
+
private pad;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Rendering options for {@link Printer}.
|
|
1174
|
+
*/
|
|
1175
|
+
export declare class PrinterOptions {
|
|
1176
|
+
readonly wrap: boolean;
|
|
1177
|
+
readonly indent: number;
|
|
1178
|
+
readonly width: number;
|
|
1179
|
+
/**
|
|
1180
|
+
* @param wrap Whether to break long constructs across lines
|
|
1181
|
+
* @param indent The number of spaces per indentation level
|
|
1182
|
+
* @param width The maximum line width before a construct is broken
|
|
1183
|
+
*/
|
|
1184
|
+
constructor(wrap: boolean, indent: number, width: number);
|
|
1185
|
+
/** Options for a single line rendering. */
|
|
1186
|
+
static compact(): PrinterOptions;
|
|
1187
|
+
/** Options for a multi-line rendering indented by two spaces at a width of 100. */
|
|
1188
|
+
static pretty(): PrinterOptions;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
553
1191
|
/**
|
|
554
1192
|
* A compiled CEL program that can be evaluated multiple times.
|
|
555
1193
|
*
|
|
@@ -595,9 +1233,64 @@ export declare class Program {
|
|
|
595
1233
|
* });
|
|
596
1234
|
* ```
|
|
597
1235
|
*/
|
|
598
|
-
evaluate(variables?: Record<string,
|
|
1236
|
+
evaluate(variables?: Record<string, unknown> | Map<string, unknown>): unknown;
|
|
599
1237
|
}
|
|
600
1238
|
|
|
1239
|
+
/** Returns the string as a quoted CEL string literal, including the double quotes. */
|
|
1240
|
+
declare function quote(value: string): string;
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Returns the integers from zero up to, but not including, the given bound.
|
|
1244
|
+
*
|
|
1245
|
+
* @param count The exclusive upper bound; negative values yield an empty list
|
|
1246
|
+
* @throws EvaluationError if the count exceeds the evaluation limit
|
|
1247
|
+
*/
|
|
1248
|
+
declare function range(count: bigint): bigint[];
|
|
1249
|
+
|
|
1250
|
+
declare namespace Regexes {
|
|
1251
|
+
export {
|
|
1252
|
+
groupCount,
|
|
1253
|
+
replace_2 as replace,
|
|
1254
|
+
extract,
|
|
1255
|
+
extractAll
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
export { Regexes }
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Replaces occurrences of a literal substring.
|
|
1262
|
+
*
|
|
1263
|
+
* @param limit The maximum number of replacements, or -1 for all
|
|
1264
|
+
*/
|
|
1265
|
+
declare function replace(value: string, from: string, to: string, limit?: bigint): string;
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Replaces matches of the pattern with the given replacement.
|
|
1269
|
+
*
|
|
1270
|
+
* @param limit The maximum number of replacements, or -1 for all
|
|
1271
|
+
* @throws ArgumentError if the pattern or a group reference is invalid
|
|
1272
|
+
*/
|
|
1273
|
+
declare function replace_2(value: string, pattern: string, replacement: string, limit?: bigint): string;
|
|
1274
|
+
|
|
1275
|
+
/** Reverses the string, preserving surrogate pairs. */
|
|
1276
|
+
declare function reverse(value: string): string;
|
|
1277
|
+
|
|
1278
|
+
/** Returns the elements in reverse order. */
|
|
1279
|
+
declare function reverse_2(values: unknown[]): unknown[];
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Shifts an int right by the given number of bits, without sign extension.
|
|
1283
|
+
*
|
|
1284
|
+
* @throws ArgumentError if the count is negative
|
|
1285
|
+
*/
|
|
1286
|
+
declare function right(value: unknown, count: unknown): bigint;
|
|
1287
|
+
|
|
1288
|
+
/** Rounds to the nearest double, with ties rounding away from zero. */
|
|
1289
|
+
declare function round(value: unknown): number;
|
|
1290
|
+
|
|
1291
|
+
/** Returns the second for a timestamp, or the whole number of seconds in a duration. */
|
|
1292
|
+
declare function secondsOf(value: unknown, zone?: unknown): bigint;
|
|
1293
|
+
|
|
601
1294
|
/**
|
|
602
1295
|
* Field selection expression (operand.field).
|
|
603
1296
|
*/
|
|
@@ -610,52 +1303,121 @@ export declare class Select implements Expression {
|
|
|
610
1303
|
}
|
|
611
1304
|
|
|
612
1305
|
/**
|
|
613
|
-
*
|
|
614
|
-
*
|
|
1306
|
+
* Returns the value stored under the given key, comparing keys the way CEL compares values.
|
|
1307
|
+
*
|
|
1308
|
+
* @returns The matching value, or undefined when no key matches
|
|
615
1309
|
*/
|
|
1310
|
+
declare function select(map: Map<unknown, unknown>, key: unknown): unknown;
|
|
1311
|
+
|
|
1312
|
+
declare namespace Sets {
|
|
1313
|
+
export {
|
|
1314
|
+
contains_3 as contains,
|
|
1315
|
+
equivalent,
|
|
1316
|
+
intersects
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
export { Sets }
|
|
1320
|
+
|
|
1321
|
+
/** Returns -1, 0 or 1 by sign, preserving the numeric type. */
|
|
1322
|
+
declare function sign(value: unknown): bigint | number;
|
|
1323
|
+
|
|
616
1324
|
/**
|
|
617
1325
|
* Returns the size/length of the given value.
|
|
618
1326
|
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
* - Array: number of elements
|
|
622
|
-
* - Map/Record: number of entries
|
|
623
|
-
* - null: 0
|
|
1327
|
+
* Strings are measured in Unicode code points; bytes, lists and maps by their
|
|
1328
|
+
* element count; null is 0.
|
|
624
1329
|
*
|
|
625
|
-
* @
|
|
626
|
-
* @returns The size for supported types, or 0 for null
|
|
627
|
-
* @throws Error if the value type is unsupported
|
|
1330
|
+
* @throws ArgumentError if the value type is unsupported
|
|
628
1331
|
*/
|
|
629
|
-
declare function sizeOf(value:
|
|
1332
|
+
declare function sizeOf(value: unknown): bigint;
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
* Returns the elements between the given indices.
|
|
1336
|
+
*
|
|
1337
|
+
* @throws ArgumentError if the range is invalid
|
|
1338
|
+
*/
|
|
1339
|
+
declare function slice(values: unknown[], start: bigint, end: bigint): unknown[];
|
|
1340
|
+
|
|
1341
|
+
/**
|
|
1342
|
+
* Sorts the list using the standard CEL ordering.
|
|
1343
|
+
*
|
|
1344
|
+
* @throws ArgumentError if the elements are not mutually comparable
|
|
1345
|
+
*/
|
|
1346
|
+
declare function sort(values: unknown[]): unknown[];
|
|
1347
|
+
|
|
1348
|
+
/** The largest number of seconds a duration may span, per the CEL specification. */
|
|
1349
|
+
declare const SPAN = 315576000000n;
|
|
1350
|
+
|
|
1351
|
+
/**
|
|
1352
|
+
* Splits a string around occurrences of a literal separator, following Java's
|
|
1353
|
+
* `String.split` limit semantics: a positive limit caps the number of parts with
|
|
1354
|
+
* the last part holding the unsplit remainder, and a negative limit keeps trailing
|
|
1355
|
+
* empty strings.
|
|
1356
|
+
*
|
|
1357
|
+
* @param limit The maximum number of parts, or -1 for no limit
|
|
1358
|
+
*/
|
|
1359
|
+
declare function split(value: string, separator: string, limit?: bigint): string[];
|
|
1360
|
+
|
|
1361
|
+
/** Returns the square root as a double. */
|
|
1362
|
+
declare function sqrt(value: unknown): number;
|
|
630
1363
|
|
|
631
1364
|
/**
|
|
632
1365
|
* Standard CEL function library implementation.
|
|
633
1366
|
*
|
|
634
1367
|
* Provides all built-in CEL functions including:
|
|
635
|
-
* - Type conversions: int(), double(), string(), bool()
|
|
1368
|
+
* - Type conversions: int(), uint(), double(), string(), bool(), bytes(), dyn()
|
|
636
1369
|
* - Type checking: type()
|
|
637
1370
|
* - Collection operations: size(), has()
|
|
638
1371
|
* - String operations: contains(), startsWith(), endsWith(), matches()
|
|
1372
|
+
* - Date/time: timestamp(), duration() and the getXxx() accessors
|
|
639
1373
|
* - Math operations: max(), min()
|
|
640
1374
|
*
|
|
641
1375
|
* This class can be extended to add custom functions while retaining
|
|
642
1376
|
* all standard CEL functionality.
|
|
643
1377
|
*/
|
|
644
1378
|
export declare class StandardFunctions implements Functions {
|
|
645
|
-
|
|
646
|
-
|
|
1379
|
+
knows(name: string): boolean;
|
|
1380
|
+
callFunction(name: string, args: unknown[]): unknown;
|
|
1381
|
+
callMethod(target: unknown, method: string, args: unknown[]): unknown;
|
|
1382
|
+
/**
|
|
1383
|
+
* Dispatches a namespaced function such as `math.abs`.
|
|
1384
|
+
*
|
|
1385
|
+
* @throws ArgumentError if the name is unknown
|
|
1386
|
+
*/
|
|
1387
|
+
protected callQualified(name: string, args: unknown[]): unknown;
|
|
647
1388
|
/**
|
|
648
1389
|
* Attempts to call a native JavaScript method on the target object.
|
|
649
1390
|
*
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
* @
|
|
654
|
-
* @throws
|
|
1391
|
+
* This is the last resort after every named method, the analogue of the Java
|
|
1392
|
+
* library's reflective method call.
|
|
1393
|
+
*
|
|
1394
|
+
* @throws ArgumentError if the method doesn't exist
|
|
1395
|
+
* @throws EvaluationError if the call fails
|
|
655
1396
|
*/
|
|
656
1397
|
private callNativeMethod;
|
|
657
1398
|
}
|
|
658
1399
|
|
|
1400
|
+
declare namespace Strings {
|
|
1401
|
+
export {
|
|
1402
|
+
charAt,
|
|
1403
|
+
indexOf,
|
|
1404
|
+
lastIndexOf,
|
|
1405
|
+
lower,
|
|
1406
|
+
upper,
|
|
1407
|
+
substring,
|
|
1408
|
+
reverse,
|
|
1409
|
+
replace,
|
|
1410
|
+
split,
|
|
1411
|
+
join,
|
|
1412
|
+
format,
|
|
1413
|
+
fixed,
|
|
1414
|
+
escape_2 as escape,
|
|
1415
|
+
quote,
|
|
1416
|
+
escapeBytes
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
export { Strings }
|
|
1420
|
+
|
|
659
1421
|
/**
|
|
660
1422
|
* Struct literal expression (Type{field: value}).
|
|
661
1423
|
*/
|
|
@@ -667,14 +1429,162 @@ export declare class Struct implements Expression {
|
|
|
667
1429
|
}
|
|
668
1430
|
|
|
669
1431
|
/**
|
|
670
|
-
* Returns
|
|
1432
|
+
* Returns the substring between the given code point indices, or from the start
|
|
1433
|
+
* index to the end.
|
|
1434
|
+
*
|
|
1435
|
+
* @throws ArgumentError if the range is invalid
|
|
1436
|
+
*/
|
|
1437
|
+
declare function substring(value: string, start: bigint, end?: bigint): string;
|
|
1438
|
+
|
|
1439
|
+
/**
|
|
1440
|
+
* Decodes base64 text into a UTF-8 string.
|
|
1441
|
+
*
|
|
1442
|
+
* @throws ArgumentError if the text is not valid base64
|
|
1443
|
+
*/
|
|
1444
|
+
declare function text(value: string): string;
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* A CEL timestamp: an instant on the UTC time line with nanosecond precision.
|
|
1448
|
+
*
|
|
1449
|
+
* `nanos` is always in `0..999_999_999`; `seconds` counts from
|
|
1450
|
+
* 1970-01-01T00:00:00Z and may be negative.
|
|
1451
|
+
*/
|
|
1452
|
+
export declare class Timestamp {
|
|
1453
|
+
readonly seconds: bigint;
|
|
1454
|
+
readonly nanos: number;
|
|
1455
|
+
/** Epoch second of the smallest supported instant (java.time.Instant.MIN). */
|
|
1456
|
+
static readonly MIN_SECONDS = -31557014167219200n;
|
|
1457
|
+
/** Epoch second of the largest supported instant (java.time.Instant.MAX). */
|
|
1458
|
+
static readonly MAX_SECONDS = 31556889864403199n;
|
|
1459
|
+
private constructor();
|
|
1460
|
+
/**
|
|
1461
|
+
* Creates a timestamp from epoch seconds and a nanosecond adjustment.
|
|
1462
|
+
*
|
|
1463
|
+
* @throws ArgumentError if the instant is outside the supported range
|
|
1464
|
+
*/
|
|
1465
|
+
static ofEpochSeconds(seconds: bigint, nanoAdjustment?: bigint): Timestamp;
|
|
1466
|
+
/** Creates a timestamp from epoch milliseconds. */
|
|
1467
|
+
static ofEpochMillis(millis: bigint): Timestamp;
|
|
1468
|
+
/** Converts a JavaScript Date. */
|
|
1469
|
+
static fromDate(date: Date): Timestamp;
|
|
1470
|
+
/** The current instant, at millisecond resolution. */
|
|
1471
|
+
static now(): Timestamp;
|
|
1472
|
+
/**
|
|
1473
|
+
* Parses an RFC 3339 timestamp such as `2024-01-01T00:00:00Z` or
|
|
1474
|
+
* `2024-01-01T01:00:00.5+01:00`.
|
|
1475
|
+
*
|
|
1476
|
+
* @throws ArgumentError if the text is not a valid timestamp
|
|
1477
|
+
*/
|
|
1478
|
+
static parse(text: string): Timestamp;
|
|
1479
|
+
/** Reports whether the value is a Timestamp. */
|
|
1480
|
+
static isTimestamp(value: unknown): value is Timestamp;
|
|
1481
|
+
/** Converts to a JavaScript Date, truncating to milliseconds. */
|
|
1482
|
+
toDate(): Date;
|
|
1483
|
+
/**
|
|
1484
|
+
* Adds a duration.
|
|
1485
|
+
*
|
|
1486
|
+
* @throws EvaluationError if the result is outside the supported range
|
|
1487
|
+
*/
|
|
1488
|
+
plus(duration: Duration): Timestamp;
|
|
1489
|
+
/**
|
|
1490
|
+
* Subtracts a duration.
|
|
1491
|
+
*
|
|
1492
|
+
* @throws EvaluationError if the result is outside the supported range
|
|
1493
|
+
*/
|
|
1494
|
+
minus(duration: Duration): Timestamp;
|
|
1495
|
+
private shift;
|
|
1496
|
+
/** The duration from this instant to another (`other - this`). */
|
|
1497
|
+
until(other: Timestamp): Duration;
|
|
1498
|
+
compareTo(other: Timestamp): number;
|
|
1499
|
+
equals(other: unknown): boolean;
|
|
1500
|
+
/**
|
|
1501
|
+
* Renders the instant in ISO-8601 form, the way java.time.Instant does:
|
|
1502
|
+
* `2024-03-05T14:30:45.250Z`, with the fraction shown in groups of three
|
|
1503
|
+
* digits only as far as needed.
|
|
1504
|
+
*/
|
|
1505
|
+
toString(): string;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Parses or provides a Timestamp from the given value.
|
|
671
1510
|
*
|
|
672
|
-
*
|
|
1511
|
+
* Accepted inputs: null returns the current time, a string is parsed as RFC 3339,
|
|
1512
|
+
* a bigint is treated as epoch seconds, and a Date or Timestamp is converted.
|
|
673
1513
|
*
|
|
674
|
-
* @
|
|
675
|
-
* @returns The simple type name
|
|
1514
|
+
* @throws ArgumentError if the input type or format is invalid
|
|
676
1515
|
*/
|
|
677
|
-
declare function
|
|
1516
|
+
declare function timestamp(value: unknown): Timestamp;
|
|
1517
|
+
|
|
1518
|
+
/** Truncates toward zero. */
|
|
1519
|
+
declare function trunc(value: unknown): number;
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* Converts a double to a 64-bit integer the way Java's `Number.longValue()` does:
|
|
1523
|
+
* truncation toward zero, NaN becomes zero, and out-of-range values saturate.
|
|
1524
|
+
*/
|
|
1525
|
+
export declare function truncateToInt64(value: number): bigint;
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* A CEL type value, as returned by the `type()` function.
|
|
1529
|
+
*
|
|
1530
|
+
* Type values are interned, compare equal by name and are bound as identifiers,
|
|
1531
|
+
* so the specification form `type(42) == int` holds. They render as their bare
|
|
1532
|
+
* name, so `string(type(42))` is `"int"`.
|
|
1533
|
+
*/
|
|
1534
|
+
export declare class Type {
|
|
1535
|
+
readonly name: string;
|
|
1536
|
+
/** The type of a null value. */
|
|
1537
|
+
static readonly NULL: Type;
|
|
1538
|
+
/** The boolean type. */
|
|
1539
|
+
static readonly BOOL: Type;
|
|
1540
|
+
/** The signed integer type. */
|
|
1541
|
+
static readonly INT: Type;
|
|
1542
|
+
/** The unsigned integer type. */
|
|
1543
|
+
static readonly UINT: Type;
|
|
1544
|
+
/** The double precision floating point type. */
|
|
1545
|
+
static readonly DOUBLE: Type;
|
|
1546
|
+
/** The string type. */
|
|
1547
|
+
static readonly STRING: Type;
|
|
1548
|
+
/** The bytes type. */
|
|
1549
|
+
static readonly BYTES: Type;
|
|
1550
|
+
/** The list type. */
|
|
1551
|
+
static readonly LIST: Type;
|
|
1552
|
+
/** The map type. */
|
|
1553
|
+
static readonly MAP: Type;
|
|
1554
|
+
/** The timestamp type. */
|
|
1555
|
+
static readonly TIMESTAMP: Type;
|
|
1556
|
+
/** The duration type. */
|
|
1557
|
+
static readonly DURATION: Type;
|
|
1558
|
+
/** The type of a type value. */
|
|
1559
|
+
static readonly TYPE: Type;
|
|
1560
|
+
/** The type of a value this library does not recognise. */
|
|
1561
|
+
static readonly UNKNOWN: Type;
|
|
1562
|
+
private static readonly BY_NAME;
|
|
1563
|
+
private constructor();
|
|
1564
|
+
/**
|
|
1565
|
+
* Returns the type with the given name, or null when the name does not denote a CEL type.
|
|
1566
|
+
*
|
|
1567
|
+
* Used to resolve bare type names such as `int` when they appear as identifiers.
|
|
1568
|
+
* `unknown` is deliberately not resolvable.
|
|
1569
|
+
*
|
|
1570
|
+
* @param name The candidate type name
|
|
1571
|
+
* @returns The matching type, or null
|
|
1572
|
+
*/
|
|
1573
|
+
static of(name: string): Type | null;
|
|
1574
|
+
/**
|
|
1575
|
+
* Reports whether the value is a Type.
|
|
1576
|
+
*/
|
|
1577
|
+
static isType(value: unknown): value is Type;
|
|
1578
|
+
equals(other: unknown): boolean;
|
|
1579
|
+
toString(): string;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Returns the CEL type of the given value.
|
|
1584
|
+
*
|
|
1585
|
+
* @returns The type value, or Type.UNKNOWN for a value this library does not recognise
|
|
1586
|
+
*/
|
|
1587
|
+
declare function typeOf(value: unknown): Type;
|
|
678
1588
|
|
|
679
1589
|
/**
|
|
680
1590
|
* Unary operation expression (!, -).
|
|
@@ -696,22 +1606,57 @@ export declare enum UnaryOp {
|
|
|
696
1606
|
NEGATE = "NEGATE"
|
|
697
1607
|
}
|
|
698
1608
|
|
|
1609
|
+
/** Uppercases the ASCII letters of the string, leaving other characters untouched. */
|
|
1610
|
+
declare function upper(value: string): string;
|
|
1611
|
+
|
|
1612
|
+
/** Breaks a count of seconds since the epoch into UTC civil fields. */
|
|
1613
|
+
export declare function utcFields(seconds: bigint): CivilFields;
|
|
1614
|
+
|
|
1615
|
+
/** Decodes UTF-8 bytes into a string, replacing malformed sequences. */
|
|
1616
|
+
export declare function utf8Decode(bytes: Uint8Array): string;
|
|
1617
|
+
|
|
1618
|
+
/** Encodes a string as UTF-8. */
|
|
1619
|
+
export declare function utf8Encode(text: string): Uint8Array;
|
|
1620
|
+
|
|
699
1621
|
declare namespace Utilities {
|
|
700
1622
|
export {
|
|
1623
|
+
limit,
|
|
1624
|
+
isMap,
|
|
1625
|
+
codePointCount,
|
|
1626
|
+
offsetByCodePoints,
|
|
701
1627
|
sizeOf,
|
|
702
1628
|
asInt,
|
|
703
1629
|
asUInt,
|
|
704
1630
|
asDouble,
|
|
705
1631
|
asString,
|
|
1632
|
+
asBytes,
|
|
706
1633
|
asBool,
|
|
707
1634
|
typeOf,
|
|
708
1635
|
has,
|
|
1636
|
+
contains,
|
|
1637
|
+
select,
|
|
709
1638
|
matches,
|
|
1639
|
+
timestamp,
|
|
1640
|
+
duration,
|
|
1641
|
+
asDuration,
|
|
1642
|
+
dateOf,
|
|
1643
|
+
monthOf,
|
|
1644
|
+
yearOf,
|
|
1645
|
+
hoursOf,
|
|
1646
|
+
minutesOf,
|
|
1647
|
+
secondsOf,
|
|
1648
|
+
millisecondsOf,
|
|
1649
|
+
weekdayOf,
|
|
1650
|
+
ordinalOf,
|
|
710
1651
|
max,
|
|
711
1652
|
min,
|
|
1653
|
+
equals,
|
|
712
1654
|
compare,
|
|
713
|
-
|
|
714
|
-
|
|
1655
|
+
containsInArray,
|
|
1656
|
+
order,
|
|
1657
|
+
LIMIT,
|
|
1658
|
+
SPAN,
|
|
1659
|
+
deepEquals
|
|
715
1660
|
}
|
|
716
1661
|
}
|
|
717
1662
|
export { Utilities }
|
|
@@ -737,4 +1682,13 @@ export declare interface Visitor<T> {
|
|
|
737
1682
|
visitConditional(expr: Conditional): T;
|
|
738
1683
|
}
|
|
739
1684
|
|
|
1685
|
+
/** Returns the day of week for the timestamp, where Sunday is 0. */
|
|
1686
|
+
declare function weekdayOf(value: unknown, zone?: unknown): bigint;
|
|
1687
|
+
|
|
1688
|
+
/** Returns the bitwise exclusive OR of two ints. */
|
|
1689
|
+
declare function xor(left: unknown, right: unknown): bigint;
|
|
1690
|
+
|
|
1691
|
+
/** Returns the year for the timestamp, in the zone or UTC. */
|
|
1692
|
+
declare function yearOf(value: unknown, zone?: unknown): bigint;
|
|
1693
|
+
|
|
740
1694
|
export { }
|