@shwfed/nuxt 0.7.8 → 0.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/runtime/components/app.d.vue.ts +0 -2
- package/dist/runtime/components/app.vue +1 -7
- package/dist/runtime/components/app.vue.d.ts +0 -2
- package/dist/runtime/components/fields.d.vue.ts +155 -0
- package/dist/runtime/components/fields.vue +312 -0
- package/dist/runtime/components/fields.vue.d.ts +155 -0
- package/dist/runtime/components/ui/button-group/ButtonGroupSeparator.vue +1 -1
- package/dist/runtime/components/ui/button-group/ButtonGroupText.vue +1 -1
- package/dist/runtime/components/ui/calendar/Calendar.d.vue.ts +5 -12
- package/dist/runtime/components/ui/calendar/Calendar.vue +77 -92
- package/dist/runtime/components/ui/calendar/Calendar.vue.d.ts +5 -12
- package/dist/runtime/components/ui/calendar/CalendarCellTrigger.vue +1 -1
- package/dist/runtime/components/ui/calendar/index.d.ts +1 -1
- package/dist/runtime/components/ui/command/CommandGroup.vue +4 -0
- package/dist/runtime/components/ui/dialog/DialogOverlay.vue +1 -1
- package/dist/runtime/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +1 -1
- package/dist/runtime/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/dist/runtime/components/ui/field/FieldDescription.vue +1 -1
- package/dist/runtime/components/ui/field/FieldError.vue +1 -1
- package/dist/runtime/components/ui/field/FieldLabel.vue +1 -1
- package/dist/runtime/components/ui/field/FieldSeparator.vue +1 -1
- package/dist/runtime/components/ui/field/index.js +7 -5
- package/dist/runtime/components/ui/input/Input.vue +1 -1
- package/dist/runtime/components/ui/input-group/InputGroup.vue +3 -0
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.d.vue.ts +4 -1
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue +10 -4
- package/dist/runtime/components/ui/input-group/InputGroupCombobox.vue.d.ts +4 -1
- package/dist/runtime/components/ui/input-group/InputGroupComboboxInput.vue +3 -1
- package/dist/runtime/components/ui/input-group/InputGroupInput.vue +1 -1
- package/dist/runtime/components/ui/input-group/InputGroupNumberField.vue +1 -1
- package/dist/runtime/components/ui/input-group/InputGroupText.vue +1 -1
- package/dist/runtime/components/ui/input-group/InputGroupTextarea.vue +1 -1
- package/dist/runtime/components/ui/input-group/index.js +1 -1
- package/dist/runtime/components/ui/label/Label.vue +1 -1
- package/dist/runtime/components/ui/native-select/NativeSelect.vue +3 -3
- package/dist/runtime/components/ui/navigation-menu/NavigationMenuLink.vue +1 -1
- package/dist/runtime/components/ui/navigation-menu/NavigationMenuViewport.vue +1 -1
- package/dist/runtime/components/ui/range-calendar/RangeCalendarCell.vue +1 -1
- package/dist/runtime/components/ui/range-calendar/RangeCalendarCellTrigger.vue +1 -1
- package/dist/runtime/components/ui/sheet/SheetOverlay.vue +1 -1
- package/dist/runtime/components/ui/switch/Switch.d.vue.ts +24 -0
- package/dist/runtime/components/ui/switch/Switch.vue +46 -0
- package/dist/runtime/components/ui/switch/Switch.vue.d.ts +24 -0
- package/dist/runtime/components/ui/switch/index.d.ts +1 -0
- package/dist/runtime/components/ui/switch/index.js +1 -0
- package/dist/runtime/components/ui/textarea/Textarea.vue +1 -1
- package/dist/runtime/plugins/cel/env.d.ts +2 -2
- package/dist/runtime/plugins/cel/env.js +5 -4
- package/dist/runtime/plugins/cel/index.d.ts +3 -3
- package/dist/runtime/plugins/cel/index.js +7 -3
- package/dist/runtime/plugins/markdown/index.d.ts +1 -1
- package/dist/runtime/utils/coders.d.ts +7 -0
- package/dist/runtime/utils/coders.js +39 -0
- package/dist/runtime/vendor/cel/index.d.ts +17 -0
- package/dist/runtime/vendor/cel/index.js +10 -0
- package/dist/runtime/vendor/cel-js/LICENSE +21 -0
- package/dist/runtime/vendor/cel-js/UPSTREAM.md +17 -0
- package/dist/runtime/vendor/cel-js/lib/errors.d.ts +21 -0
- package/dist/runtime/vendor/cel-js/lib/errors.js +97 -0
- package/dist/runtime/vendor/cel-js/lib/evaluator.d.ts +4 -0
- package/dist/runtime/vendor/cel-js/lib/evaluator.js +192 -0
- package/dist/runtime/vendor/cel-js/lib/functions.d.ts +53 -0
- package/dist/runtime/vendor/cel-js/lib/functions.js +513 -0
- package/dist/runtime/vendor/cel-js/lib/globals.d.ts +27 -0
- package/dist/runtime/vendor/cel-js/lib/globals.js +33 -0
- package/dist/runtime/vendor/cel-js/lib/index.d.ts +469 -0
- package/dist/runtime/vendor/cel-js/lib/index.js +18 -0
- package/dist/runtime/vendor/cel-js/lib/macros.d.ts +1 -0
- package/dist/runtime/vendor/cel-js/lib/macros.js +230 -0
- package/dist/runtime/vendor/cel-js/lib/operators.d.ts +117 -0
- package/dist/runtime/vendor/cel-js/lib/operators.js +739 -0
- package/dist/runtime/vendor/cel-js/lib/optional.d.ts +14 -0
- package/dist/runtime/vendor/cel-js/lib/optional.js +161 -0
- package/dist/runtime/vendor/cel-js/lib/options.d.ts +23 -0
- package/dist/runtime/vendor/cel-js/lib/options.js +47 -0
- package/dist/runtime/vendor/cel-js/lib/overloads.d.ts +1 -0
- package/dist/runtime/vendor/cel-js/lib/overloads.js +214 -0
- package/dist/runtime/vendor/cel-js/lib/parser.d.ts +56 -0
- package/dist/runtime/vendor/cel-js/lib/parser.js +827 -0
- package/dist/runtime/vendor/cel-js/lib/registry.d.ts +279 -0
- package/dist/runtime/vendor/cel-js/lib/registry.js +1596 -0
- package/dist/runtime/vendor/cel-js/lib/serialize.d.ts +1 -0
- package/dist/runtime/vendor/cel-js/lib/serialize.js +259 -0
- package/dist/runtime/vendor/cel-js/lib/type-checker.d.ts +26 -0
- package/dist/runtime/vendor/cel-js/lib/type-checker.js +81 -0
- package/package.json +7 -4
- package/dist/runtime/components/locale.d.vue.ts +0 -14
- package/dist/runtime/components/locale.vue +0 -89
- package/dist/runtime/components/locale.vue.d.ts +0 -14
- package/dist/runtime/components/query.d.vue.ts +0 -30
- package/dist/runtime/components/query.vue +0 -266
- package/dist/runtime/components/query.vue.d.ts +0 -30
- package/dist/runtime/utilities/query-config/global.d.ts +0 -4
- package/dist/runtime/utilities/query-config/global.js +0 -18
- package/dist/runtime/utilities/query-config/index.d.ts +0 -3
- package/dist/runtime/utilities/query-config/index.js +0 -14
- package/dist/runtime/utilities/query-config/schema.d.ts +0 -96
- package/dist/runtime/utilities/query-config/schema.js +0 -51
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import type {UnsignedInt} from './functions.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a CEL expression AST node produced by the parser.
|
|
5
|
+
* Each node stores its operator, operands, type metadata, and helpers for
|
|
6
|
+
* evaluation/type-checking.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type BinaryOperator =
|
|
10
|
+
| '!='
|
|
11
|
+
| '=='
|
|
12
|
+
| 'in'
|
|
13
|
+
| '+'
|
|
14
|
+
| '-'
|
|
15
|
+
| '*'
|
|
16
|
+
| '/'
|
|
17
|
+
| '%'
|
|
18
|
+
| '<'
|
|
19
|
+
| '<='
|
|
20
|
+
| '>'
|
|
21
|
+
| '>='
|
|
22
|
+
export type UnaryOperator = '!_' | '-_'
|
|
23
|
+
export type AccessOperator = '.' | '.?' | '[]' | '[?]'
|
|
24
|
+
export type StructuralOperator =
|
|
25
|
+
| 'value'
|
|
26
|
+
| 'id'
|
|
27
|
+
| 'call'
|
|
28
|
+
| 'rcall'
|
|
29
|
+
| 'list'
|
|
30
|
+
| 'map'
|
|
31
|
+
| '?:'
|
|
32
|
+
| '||'
|
|
33
|
+
| '&&'
|
|
34
|
+
|
|
35
|
+
type LiteralValue = string | number | bigint | boolean | null | Uint8Array | UnsignedInt
|
|
36
|
+
type BinaryArgs = [ASTNode, ASTNode]
|
|
37
|
+
type MapEntry = [ASTNode, ASTNode]
|
|
38
|
+
|
|
39
|
+
interface ASTNodeArgsMap {
|
|
40
|
+
value: LiteralValue
|
|
41
|
+
id: string
|
|
42
|
+
'.': [ASTNode, string]
|
|
43
|
+
'.?': [ASTNode, string]
|
|
44
|
+
'[]': BinaryArgs
|
|
45
|
+
'[?]': BinaryArgs
|
|
46
|
+
call: [string, ASTNode[]]
|
|
47
|
+
rcall: [string, ASTNode, ASTNode[]]
|
|
48
|
+
list: ASTNode[]
|
|
49
|
+
map: MapEntry[]
|
|
50
|
+
'?:': [ASTNode, ASTNode, ASTNode]
|
|
51
|
+
'||': BinaryArgs
|
|
52
|
+
'&&': BinaryArgs
|
|
53
|
+
'!_': ASTNode
|
|
54
|
+
'-_': ASTNode
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type ASTNodeArgsMapWithBinary = ASTNodeArgsMap & {[K in BinaryOperator]: BinaryArgs}
|
|
58
|
+
export type ASTOperator = keyof ASTNodeArgsMapWithBinary
|
|
59
|
+
|
|
60
|
+
type ASTNodeArgs<T extends ASTOperator> = ASTNodeArgsMapWithBinary[T]
|
|
61
|
+
type LegacyAstTuple = [string, ...any[]]
|
|
62
|
+
|
|
63
|
+
interface ASTNodeBase<T extends ASTOperator> {
|
|
64
|
+
/** The position in the source string where this node starts */
|
|
65
|
+
readonly pos: number
|
|
66
|
+
/** The original CEL input string */
|
|
67
|
+
readonly input: string
|
|
68
|
+
/** Operator for this node */
|
|
69
|
+
readonly op: T
|
|
70
|
+
/** Operator-specific operand payload */
|
|
71
|
+
readonly args: ASTNodeArgs<T>
|
|
72
|
+
/** Convert back to the historical tuple representation. */
|
|
73
|
+
toOldStructure(): LegacyAstTuple
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type ASTNode = {
|
|
77
|
+
[K in ASTOperator]: ASTNodeBase<K>
|
|
78
|
+
}[ASTOperator]
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Context object for variable resolution during evaluation.
|
|
82
|
+
* Can contain any nested structure of primitive values, arrays, and objects.
|
|
83
|
+
*/
|
|
84
|
+
export interface Context {
|
|
85
|
+
[key: string]: any
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type {RootContext, OverlayContext} from './registry.d'
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Result of type checking an expression.
|
|
92
|
+
*/
|
|
93
|
+
export interface TypeCheckResult {
|
|
94
|
+
/** Whether the expression passed type checking */
|
|
95
|
+
valid: boolean
|
|
96
|
+
/** The inferred type of the expression (only present if valid is true) */
|
|
97
|
+
type?: string
|
|
98
|
+
/** The type error that occurred (only present if valid is false) */
|
|
99
|
+
error?: TypeError
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type ParseResult = {
|
|
103
|
+
(context?: Context): any
|
|
104
|
+
/** The parsed AST */
|
|
105
|
+
ast: ASTNode
|
|
106
|
+
/** Type check the expression without evaluating it */
|
|
107
|
+
check(): TypeCheckResult
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Error thrown during parsing when the CEL expression syntax is invalid.
|
|
112
|
+
*/
|
|
113
|
+
export class ParseError extends Error {
|
|
114
|
+
constructor(message: string)
|
|
115
|
+
readonly name: 'ParseError'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Error thrown during evaluation when an error occurs while executing the CEL expression.
|
|
120
|
+
*/
|
|
121
|
+
export class EvaluationError extends Error {
|
|
122
|
+
constructor(message: string)
|
|
123
|
+
readonly name: 'EvaluationError'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Error thrown during type checking when a type error is detected in the expression.
|
|
128
|
+
* The error message includes source position highlighting.
|
|
129
|
+
*/
|
|
130
|
+
export class TypeError extends Error {
|
|
131
|
+
constructor(message: string)
|
|
132
|
+
readonly name: 'TypeError'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Represents an optional value that may or may not be present.
|
|
137
|
+
* Used with optional chaining (.?/.[]?) and optional.* helpers.
|
|
138
|
+
*/
|
|
139
|
+
export class Optional {
|
|
140
|
+
/**
|
|
141
|
+
* Create a new Optional with a value.
|
|
142
|
+
* @param value - The value to wrap
|
|
143
|
+
* @returns A new Optional instance
|
|
144
|
+
*/
|
|
145
|
+
static of(value: any): Optional
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create an empty Optional.
|
|
149
|
+
* @returns The singleton empty Optional instance
|
|
150
|
+
*/
|
|
151
|
+
static none(): Optional
|
|
152
|
+
|
|
153
|
+
/** Check if a value is present. */
|
|
154
|
+
hasValue(): boolean
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get the wrapped value.
|
|
158
|
+
* @returns The wrapped value
|
|
159
|
+
* @throws EvaluationError if no value is present
|
|
160
|
+
*/
|
|
161
|
+
value(): any
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Return this Optional if it has a value, otherwise return the provided Optional.
|
|
165
|
+
* @param optional - The fallback Optional
|
|
166
|
+
* @returns An Optional instance
|
|
167
|
+
*/
|
|
168
|
+
or(optional: Optional): Optional
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Return the wrapped value if present, otherwise return the default value.
|
|
172
|
+
* @param defaultValue - The fallback value
|
|
173
|
+
* @returns The resulting value
|
|
174
|
+
*/
|
|
175
|
+
orValue(defaultValue: any): any
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Parse a CEL expression string into an evaluable function.
|
|
180
|
+
*
|
|
181
|
+
* @param expression - The CEL expression string to parse
|
|
182
|
+
* @returns A function that can be called with context to evaluate the expression
|
|
183
|
+
* @throws ParseError if the expression is syntactically invalid
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const evalFn = parse('user.name + " is " + user.age + " years old"');
|
|
188
|
+
* const result = evalFn({ user: { name: 'John', age: 30 } });
|
|
189
|
+
* console.log(result); // "John is 30 years old"
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export function parse(expression: string): ParseResult
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Evaluate a CEL expression string directly.
|
|
196
|
+
*
|
|
197
|
+
* @param expression - The CEL expression string to evaluate
|
|
198
|
+
* @param context - Optional context object for variable resolution
|
|
199
|
+
* @returns The result of evaluating the expression
|
|
200
|
+
* @throws ParseError if the expression syntax is invalid
|
|
201
|
+
* @throws EvaluationError if evaluation fails
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const result = evaluate('1 + 2 * 3'); // 7
|
|
206
|
+
* const result2 = evaluate('user.name', { user: { name: 'Alice' } }); // 'Alice'
|
|
207
|
+
*
|
|
208
|
+
* // For custom functions, use Environment instead:
|
|
209
|
+
* const env = new Environment().registerFunction('multByTwo(int): int', (x) => x * 2n)
|
|
210
|
+
* const result3 = env.evaluate('multByTwo(5)'); // 10n
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
export function evaluate(expression: string, context?: Context): any
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Serialize an AST back to a CEL expression string.
|
|
217
|
+
*
|
|
218
|
+
* @param ast - The AST node to serialize
|
|
219
|
+
* @returns The CEL expression string representation
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const evalFn = parse('1 + 2 * 3');
|
|
224
|
+
* const serialized = serialize(evalFn.ast);
|
|
225
|
+
* console.log(serialized); // "1 + 2 * 3"
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export function serialize(ast: ASTNode): string
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Structural limits for parsing and evaluating CEL expressions.
|
|
232
|
+
* All limits default to the minimums required by the CEL specification.
|
|
233
|
+
*/
|
|
234
|
+
export interface Limits {
|
|
235
|
+
/** Maximum number of AST nodes that can be produced while parsing */
|
|
236
|
+
maxAstNodes: number
|
|
237
|
+
/** Maximum nesting depth for recursive grammar elements (calls, selects, indexes, aggregates) */
|
|
238
|
+
maxDepth: number
|
|
239
|
+
/** Maximum number of list literal elements */
|
|
240
|
+
maxListElements: number
|
|
241
|
+
/** Maximum number of map literal entries */
|
|
242
|
+
maxMapEntries: number
|
|
243
|
+
/** Maximum number of function or method call arguments */
|
|
244
|
+
maxCallArguments: number
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Options for creating a new Environment.
|
|
249
|
+
*/
|
|
250
|
+
export interface EnvironmentOptions {
|
|
251
|
+
/**
|
|
252
|
+
* When true, unlisted variables are treated as dynamic (dyn) type.
|
|
253
|
+
* When false, all variables must be explicitly registered.
|
|
254
|
+
*/
|
|
255
|
+
unlistedVariablesAreDyn?: boolean
|
|
256
|
+
/**
|
|
257
|
+
* When true (default), list and map literals must have homogeneous element/key/value types.
|
|
258
|
+
* When false, mixed literals are inferred as list<dyn> or map with dyn components.
|
|
259
|
+
*/
|
|
260
|
+
homogeneousAggregateLiterals?: boolean
|
|
261
|
+
/**
|
|
262
|
+
* Enable experimental optional types (.?/.[]? chaining and optional.* helpers). Disabled by default.
|
|
263
|
+
*/
|
|
264
|
+
enableOptionalTypes?: boolean
|
|
265
|
+
/** Optional overrides for parser/evaluator structural limits */
|
|
266
|
+
limits?: Partial<Limits>
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Environment for CEL expression evaluation with type checking and custom functions.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const env = new Environment()
|
|
275
|
+
* .registerVariable('name', 'string')
|
|
276
|
+
* .registerVariable('age', 'int')
|
|
277
|
+
* .registerFunction('double(int): int', (x) => x * 2n)
|
|
278
|
+
*
|
|
279
|
+
* const result = env.evaluate('double(age)', { age: 21n }) // 42n
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
export class Environment {
|
|
283
|
+
/**
|
|
284
|
+
* Create a new Environment with optional configuration.
|
|
285
|
+
*
|
|
286
|
+
* @param opts - Optional configuration options
|
|
287
|
+
*/
|
|
288
|
+
constructor(opts?: EnvironmentOptions)
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Create a fast, isolated copy that stops the parent from registering more entries.
|
|
292
|
+
*
|
|
293
|
+
* @param opts - Optional configuration options
|
|
294
|
+
* @returns A new environment
|
|
295
|
+
*/
|
|
296
|
+
clone(opts?: EnvironmentOptions): Environment
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Register a custom type for use in expressions.
|
|
300
|
+
*
|
|
301
|
+
* @param typename - The name of the type (e.g., 'Vector', 'Point')
|
|
302
|
+
* @param constructor - The constructor function or class for the type
|
|
303
|
+
* @returns This environment for chaining
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* class Vector { constructor(public x: number, public y: number) {} }
|
|
308
|
+
* env.registerType('Vector', Vector)
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
registerType(typename: string, constructor: any): this
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Register a variable with its expected type.
|
|
315
|
+
*
|
|
316
|
+
* @param name - The variable name
|
|
317
|
+
* @param type - The CEL type name ('string', 'int', 'double', 'bool', 'list', 'map', etc.)
|
|
318
|
+
* @returns This environment for chaining
|
|
319
|
+
* @throws Error if variable is already registered
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* env.registerVariable('username', 'string')
|
|
324
|
+
* .registerVariable('count', 'int')
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
registerVariable(name: string, type: string): this
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Register a constant value that is always available in expressions without providing it via context.
|
|
331
|
+
*
|
|
332
|
+
* @param name - The constant identifier exposed to CEL expressions
|
|
333
|
+
* @param type - The CEL type name of the constant (e.g., 'int', 'string')
|
|
334
|
+
* @param value - The concrete value supplied during registration
|
|
335
|
+
* @returns This environment for chaining further registrations
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* const env = new Environment().registerConstant('timezone', 'string', 'UTC')
|
|
340
|
+
* env.evaluate('timezone == "UTC"') // true
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
registerConstant(name: string, type: string, value: any): this
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Register a custom function or method.
|
|
347
|
+
*
|
|
348
|
+
* @param signature - Function signature in format 'name(type1, type2): returnType' or 'Type.method(args): returnType'
|
|
349
|
+
* @param handlerOrOptions - Either the function implementation or an options object with handler and optional typeCheck
|
|
350
|
+
* @returns This environment for chaining
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* // Standalone function
|
|
355
|
+
* env.registerFunction('double(int): int', (x) => x * 2n)
|
|
356
|
+
*
|
|
357
|
+
* // Instance method
|
|
358
|
+
* env.registerFunction('string.reverse(): string', (str) => str.split('').reverse().join(''))
|
|
359
|
+
*
|
|
360
|
+
* // Macro function with type checker
|
|
361
|
+
* env.registerFunction('list.custom(ast, ast): bool', {
|
|
362
|
+
* handler: (receiver, ast) => { ... },
|
|
363
|
+
* typeCheck: (checker, receiverType, args) => 'bool'
|
|
364
|
+
* })
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
registerFunction(
|
|
368
|
+
signature: string,
|
|
369
|
+
handlerOrOptions:
|
|
370
|
+
| ((...args: any[]) => any)
|
|
371
|
+
| {
|
|
372
|
+
handler: (...args: any[]) => any
|
|
373
|
+
typeCheck?: (checker: any, receiverType: string, args: any[]) => string
|
|
374
|
+
}
|
|
375
|
+
): this
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Register a custom operator overload.
|
|
379
|
+
*
|
|
380
|
+
* @param signature - Operator signature in format 'type1 op type2' (e.g., 'Vector + Vector')
|
|
381
|
+
* @param handler - The operator implementation
|
|
382
|
+
* @returns This environment for chaining
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* env.registerOperator('Vector + Vector', (a, b) => new Vector(a.x + b.x, a.y + b.y))
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
registerOperator(signature: string, handler: (left: any, right: any) => any): this
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Check if a variable is registered in this environment.
|
|
393
|
+
*
|
|
394
|
+
* @param name - The variable name to check
|
|
395
|
+
* @returns True if the variable is registered
|
|
396
|
+
*/
|
|
397
|
+
hasVariable(name: string): boolean
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Parse a CEL expression and return a reusable evaluation function.
|
|
401
|
+
*
|
|
402
|
+
* @param expression - The CEL expression string to parse
|
|
403
|
+
* @returns A function that can be called with context to evaluate the expression
|
|
404
|
+
* @throws ParseError if the expression is syntactically invalid
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```typescript
|
|
408
|
+
* const parsed = env.parse('x + y')
|
|
409
|
+
* const result1 = parsed({ x: 1n, y: 2n }) // 3n
|
|
410
|
+
* const result2 = parsed({ x: 5n, y: 10n }) // 15n
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
parse(expression: string): ParseResult
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Type check a CEL expression without evaluating it.
|
|
417
|
+
*
|
|
418
|
+
* @param expression - The CEL expression string to check
|
|
419
|
+
* @returns An object containing validation result and type information
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* const env = new Environment()
|
|
424
|
+
* .registerVariable('x', 'int')
|
|
425
|
+
* .registerVariable('y', 'string')
|
|
426
|
+
*
|
|
427
|
+
* const result = env.check('x + y')
|
|
428
|
+
* if (!result.valid) {
|
|
429
|
+
* console.error('Type error:', result.error.message)
|
|
430
|
+
* }
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
check(expression: string): TypeCheckResult
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Evaluate a CEL expression with the given context.
|
|
437
|
+
*
|
|
438
|
+
* @param expression - The CEL expression string to evaluate
|
|
439
|
+
* @param context - Optional context object for variable resolution
|
|
440
|
+
* @returns The result of evaluating the expression
|
|
441
|
+
* @throws ParseError if the expression syntax is invalid
|
|
442
|
+
* @throws EvaluationError if evaluation fails
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const result = env.evaluate('name + " is " + string(age)', {
|
|
447
|
+
* name: 'John',
|
|
448
|
+
* age: 30n
|
|
449
|
+
* })
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
evaluate(expression: string, context?: Context): any
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Default export containing all main functions and classes.
|
|
457
|
+
*/
|
|
458
|
+
declare const cel: {
|
|
459
|
+
parse: typeof parse
|
|
460
|
+
evaluate: typeof evaluate
|
|
461
|
+
serialize: typeof serialize
|
|
462
|
+
Environment: typeof Environment
|
|
463
|
+
ParseError: typeof ParseError
|
|
464
|
+
EvaluationError: typeof EvaluationError
|
|
465
|
+
TypeError: typeof TypeError
|
|
466
|
+
Optional: typeof Optional
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export default cel
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {ParseError, EvaluationError, TypeError} from './errors.js'
|
|
2
|
+
import {parse, evaluate, check, Environment} from './evaluator.js'
|
|
3
|
+
import {serialize} from './serialize.js'
|
|
4
|
+
import {Optional} from './optional.js'
|
|
5
|
+
|
|
6
|
+
export {parse, evaluate, check, Environment, ParseError, EvaluationError, TypeError, serialize, Optional}
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
parse,
|
|
10
|
+
evaluate,
|
|
11
|
+
check,
|
|
12
|
+
Environment,
|
|
13
|
+
ParseError,
|
|
14
|
+
EvaluationError,
|
|
15
|
+
TypeError,
|
|
16
|
+
serialize,
|
|
17
|
+
Optional
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function registerMacros(registry: any): void;
|