@almadar/evaluator 1.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/LICENSE ADDED
@@ -0,0 +1,72 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Almadar FZE
6
+ Licensed Work: KFlow Builder / Almadar
7
+ The Licensed Work is (c) 2025-2026 Almadar FZE.
8
+ Additional Use Grant: You may make production use of the Licensed Work for
9
+ non-commercial purposes and for internal evaluation.
10
+ Production use for commercial purposes requires a
11
+ commercial license from the Licensor.
12
+ Change Date: 2030-02-01
13
+ Change License: Apache License, Version 2.0
14
+
15
+ Terms
16
+
17
+ The Licensor hereby grants you the right to copy, modify, create derivative
18
+ works, redistribute, and make non-production use of the Licensed Work. The
19
+ Licensor may make an Additional Use Grant, above, permitting limited
20
+ production use.
21
+
22
+ Effective on the Change Date, or the fourth anniversary of the first publicly
23
+ available distribution of a specific version of the Licensed Work under this
24
+ License, whichever comes first, the Licensor hereby grants you rights under
25
+ the terms of the Change License, and the rights granted in the paragraph
26
+ above terminate.
27
+
28
+ If your use of the Licensed Work does not comply with the requirements
29
+ currently in effect as described in this License, you must purchase a
30
+ commercial license from the Licensor, its affiliated entities, or authorized
31
+ resellers, or you must refrain from using the Licensed Work.
32
+
33
+ All copies of the original and modified Licensed Work, and derivative works
34
+ of the Licensed Work, are subject to this License. This License applies
35
+ separately for each version of the Licensed Work and the Change Date may vary
36
+ for each version of the Licensed Work released by Licensor.
37
+
38
+ You must conspicuously display this License on each original or modified copy
39
+ of the Licensed Work. If you receive the Licensed Work in original or
40
+ modified form from a third party, the terms and conditions set forth in this
41
+ License apply to your use of that work.
42
+
43
+ Any use of the Licensed Work in violation of this License will automatically
44
+ terminate your rights under this License for the current and all other
45
+ versions of the Licensed Work.
46
+
47
+ This License does not grant you any right in any trademark or logo of
48
+ Licensor or its affiliates (provided that you may use a trademark or logo of
49
+ Licensor as expressly required by this License).
50
+
51
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
52
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
53
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
55
+ TITLE.
56
+
57
+ ---
58
+
59
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
60
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
61
+
62
+ ADDITIONAL TERMS:
63
+
64
+ Documentation (builder/packages/website/docs/) is licensed under CC BY 4.0.
65
+
66
+ TRADEMARKS:
67
+
68
+ "Orbital", "KFlow", "Almadar", and the Almadar logo are trademarks of
69
+ Almadar FZE. You may not use these trademarks without prior written
70
+ permission from Almadar FZE.
71
+
72
+ For licensing inquiries: licensing@almadar.io
@@ -0,0 +1,498 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * S-Expression Types
5
+ *
6
+ * Defines the S-Expression type system for guards, effects, and computed values.
7
+ * S-expressions are JSON arrays where the first element is an operator string.
8
+ *
9
+ * @example
10
+ * // Guard: health > 0
11
+ * [">", "@entity.health", 0]
12
+ *
13
+ * // Effect: set x to x + vx
14
+ * ["set", "@entity.x", ["+", "@entity.x", "@entity.vx"]]
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+
19
+ /**
20
+ * S-Expression type - recursive structure representing expressions.
21
+ *
22
+ * An S-expression is either:
23
+ * - A literal value (string, number, boolean, null)
24
+ * - An object literal (for payload data, props, etc.)
25
+ * - A binding reference (string starting with @)
26
+ * - A call expression (array with operator as first element)
27
+ */
28
+ type SExprAtom = string | number | boolean | null | Record<string, unknown>;
29
+ type SExpr = SExprAtom | SExpr[];
30
+ /**
31
+ * Expression type - S-expressions only.
32
+ * Used for guards, computed values, and effect expressions.
33
+ *
34
+ * NOTE: Legacy string format is no longer supported.
35
+ * All expressions must be S-expression arrays.
36
+ */
37
+ type Expression = SExpr;
38
+ /**
39
+ * Recursive schema for S-expressions.
40
+ * Validates that arrays have at least one element and first element is a string (operator).
41
+ */
42
+ declare const SExprSchema: z.ZodType<SExpr>;
43
+ /**
44
+ * Schema for Expression type - S-expressions only.
45
+ * S-expressions are arrays with operator as first element.
46
+ *
47
+ * NOTE: Legacy string format is no longer supported.
48
+ */
49
+ declare const ExpressionSchema: z.ZodType<Expression>;
50
+ /**
51
+ * Type guard for S-expression detection.
52
+ * 100% reliable - structural check, no regex or keyword matching.
53
+ *
54
+ * @param value - Value to check
55
+ * @returns true if value is an S-expression (array with string operator)
56
+ */
57
+ declare function isSExpr(value: unknown): value is SExpr[];
58
+ /**
59
+ * Type guard for S-expression atoms (non-array values).
60
+ * Includes objects (for payload data, props, etc.)
61
+ */
62
+ declare function isSExprAtom(value: unknown): value is SExprAtom;
63
+ /**
64
+ * Check if a value is a binding reference.
65
+ * Bindings start with @ (e.g., @entity.health, @payload.amount, @now)
66
+ */
67
+ declare function isBinding(value: unknown): value is string;
68
+ /**
69
+ * Check if a value is a valid S-expression call (array with operator).
70
+ * Use this to distinguish between S-expression calls and atom values.
71
+ */
72
+ declare function isSExprCall(value: unknown): value is SExpr[];
73
+ /**
74
+ * Parsed binding reference
75
+ */
76
+ interface ParsedBinding {
77
+ /** Type of binding: core (@entity, @payload, @state, @now) or entity (@EntityName) */
78
+ type: 'core' | 'entity';
79
+ /** The root binding name (entity, payload, state, now, or EntityName) */
80
+ root: string;
81
+ /** Path segments after the root (e.g., ['health'] for @entity.health) */
82
+ path: string[];
83
+ /** Full original binding string */
84
+ original: string;
85
+ }
86
+ /**
87
+ * Core bindings that are always available.
88
+ * Phase 4.5 adds: config, computed, trait (for behavior support)
89
+ */
90
+ declare const CORE_BINDINGS: readonly ["entity", "payload", "state", "now", "config", "computed", "trait"];
91
+ type CoreBinding = (typeof CORE_BINDINGS)[number];
92
+ /**
93
+ * Parse a binding reference into its components.
94
+ * Does NOT use regex - uses structured string operations.
95
+ *
96
+ * @param binding - Binding string starting with @
97
+ * @returns Parsed binding object or null if invalid
98
+ */
99
+ declare function parseBinding(binding: string): ParsedBinding | null;
100
+ /**
101
+ * Validate a binding reference format.
102
+ *
103
+ * @param binding - Binding string to validate
104
+ * @returns true if valid binding format
105
+ */
106
+ declare function isValidBinding(binding: string): boolean;
107
+ /**
108
+ * Get the operator from an S-expression call.
109
+ *
110
+ * @param expr - S-expression array
111
+ * @returns The operator string or null if not a valid call
112
+ */
113
+ declare function getOperator(expr: SExpr): string | null;
114
+ /**
115
+ * Get the arguments from an S-expression call.
116
+ *
117
+ * @param expr - S-expression array
118
+ * @returns Array of arguments (empty if not a valid call)
119
+ */
120
+ declare function getArgs(expr: SExpr): SExpr[];
121
+ /**
122
+ * Create an S-expression call.
123
+ *
124
+ * @param operator - The operator string
125
+ * @param args - Arguments to the operator
126
+ * @returns S-expression array
127
+ */
128
+ declare function sexpr(operator: string, ...args: SExpr[]): SExpr[];
129
+ /**
130
+ * Walk an S-expression tree and apply a visitor function to each node.
131
+ *
132
+ * @param expr - S-expression to walk
133
+ * @param visitor - Function to call on each node
134
+ */
135
+ declare function walkSExpr(expr: SExpr, visitor: (node: SExpr, parent: SExpr[] | null, index: number) => void, parent?: SExpr[] | null, index?: number): void;
136
+ /**
137
+ * Collect all bindings referenced in an S-expression.
138
+ *
139
+ * @param expr - S-expression to analyze
140
+ * @returns Array of binding strings found
141
+ */
142
+ declare function collectBindings(expr: SExpr): string[];
143
+
144
+ /**
145
+ * Evaluation Context
146
+ *
147
+ * Defines the context for evaluating S-expressions at runtime.
148
+ * This context provides access to entity data, payload, state, and effect handlers.
149
+ *
150
+ * @packageDocumentation
151
+ */
152
+ /**
153
+ * User context for @user bindings (role-based UI).
154
+ */
155
+ interface UserContext {
156
+ /** User's unique ID */
157
+ id: string;
158
+ /** User's email */
159
+ email?: string;
160
+ /** User's display name */
161
+ name?: string;
162
+ /** User's role (for RBAC) */
163
+ role?: string;
164
+ /** User's permissions */
165
+ permissions?: string[];
166
+ /** Additional custom profile fields */
167
+ [key: string]: unknown;
168
+ }
169
+ /**
170
+ * Evaluation context for S-expression evaluation.
171
+ * Provides all bindings and effect handlers needed at runtime.
172
+ */
173
+ interface EvaluationContext {
174
+ /** Entity data for @entity bindings */
175
+ entity: Record<string, unknown>;
176
+ /** Payload data for @payload bindings */
177
+ payload: Record<string, unknown>;
178
+ /** Current state for @state binding */
179
+ state: string;
180
+ /** Current timestamp for @now binding (defaults to Date.now()) */
181
+ now: number;
182
+ /** User data for @user bindings (role-based UI) */
183
+ user?: UserContext;
184
+ /** Singleton entities for @EntityName bindings */
185
+ singletons: Map<string, Record<string, unknown>>;
186
+ /** Local variables from 'let' bindings */
187
+ locals?: Map<string, unknown>;
188
+ /** Mutate entity fields */
189
+ mutateEntity?: (changes: Record<string, unknown>) => void;
190
+ /** Emit an event */
191
+ emit?: (event: string, payload?: unknown) => void;
192
+ /** Navigate to a route */
193
+ navigate?: (route: string, params?: Record<string, unknown>) => void;
194
+ /** Persist data (create/update/delete) */
195
+ persist?: (action: 'create' | 'update' | 'delete', data?: Record<string, unknown>) => Promise<void>;
196
+ /** Show a notification */
197
+ notify?: (message: string, type?: 'success' | 'error' | 'warning' | 'info') => void;
198
+ /** Spawn a new entity instance */
199
+ spawn?: (entityType: string, props?: Record<string, unknown>) => void;
200
+ /** Despawn an entity instance */
201
+ despawn?: (entityId?: string) => void;
202
+ /** Call an external service */
203
+ callService?: (service: string, method: string, params?: Record<string, unknown>) => Promise<unknown>;
204
+ /** Render UI to a slot */
205
+ renderUI?: (slot: string, pattern: unknown, props?: Record<string, unknown>, priority?: number) => void;
206
+ }
207
+ /**
208
+ * Create a minimal evaluation context for testing/guards.
209
+ * Only includes bindings, no effect handlers.
210
+ */
211
+ declare function createMinimalContext(entity?: Record<string, unknown>, payload?: Record<string, unknown>, state?: string): EvaluationContext;
212
+ /**
213
+ * Create a context with effect handlers.
214
+ * Used for runtime evaluation where effects need to execute.
215
+ */
216
+ declare function createEffectContext(base: EvaluationContext, handlers: Partial<Pick<EvaluationContext, 'mutateEntity' | 'emit' | 'navigate' | 'persist' | 'notify' | 'spawn' | 'despawn' | 'callService' | 'renderUI'>>): EvaluationContext;
217
+ /**
218
+ * Create a child context with additional local bindings.
219
+ * Used for 'let' expressions.
220
+ */
221
+ declare function createChildContext(parent: EvaluationContext, locals: Map<string, unknown>): EvaluationContext;
222
+ /**
223
+ * Resolve a binding in the context.
224
+ *
225
+ * @param binding - Binding string (e.g., "@entity.health", "@payload.amount")
226
+ * @param ctx - Evaluation context
227
+ * @returns Resolved value or undefined
228
+ */
229
+ declare function resolveBinding(binding: string, ctx: EvaluationContext): unknown;
230
+
231
+ /**
232
+ * Arithmetic Operator Implementations
233
+ *
234
+ * Implements: +, -, *, /, %, abs, min, max, floor, ceil, round, clamp
235
+ */
236
+
237
+ type Evaluator$5 = (expr: SExpr, ctx: EvaluationContext) => unknown;
238
+ /**
239
+ * Evaluate addition: ["+", a, b, ...]
240
+ */
241
+ declare function evalAdd(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
242
+ /**
243
+ * Evaluate subtraction: ["-", a] (negate) or ["-", a, b] (subtract)
244
+ */
245
+ declare function evalSubtract(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
246
+ /**
247
+ * Evaluate multiplication: ["*", a, b, ...]
248
+ */
249
+ declare function evalMultiply(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
250
+ /**
251
+ * Evaluate division: ["/", a, b]
252
+ */
253
+ declare function evalDivide(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
254
+ /**
255
+ * Evaluate modulo: ["%", a, b]
256
+ */
257
+ declare function evalModulo(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
258
+ /**
259
+ * Evaluate absolute value: ["abs", a]
260
+ */
261
+ declare function evalAbs(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
262
+ /**
263
+ * Evaluate minimum: ["min", a, b, ...]
264
+ */
265
+ declare function evalMin(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
266
+ /**
267
+ * Evaluate maximum: ["max", a, b, ...]
268
+ */
269
+ declare function evalMax(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
270
+ /**
271
+ * Evaluate floor: ["floor", a]
272
+ */
273
+ declare function evalFloor(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
274
+ /**
275
+ * Evaluate ceiling: ["ceil", a]
276
+ */
277
+ declare function evalCeil(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
278
+ /**
279
+ * Evaluate round: ["round", a]
280
+ */
281
+ declare function evalRound(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
282
+ /**
283
+ * Evaluate clamp: ["clamp", value, min, max]
284
+ */
285
+ declare function evalClamp(args: SExpr[], evaluate: Evaluator$5, ctx: EvaluationContext): number;
286
+
287
+ /**
288
+ * Comparison Operator Implementations
289
+ *
290
+ * Implements: =, !=, <, >, <=, >=
291
+ */
292
+
293
+ type Evaluator$4 = (expr: SExpr, ctx: EvaluationContext) => unknown;
294
+ /**
295
+ * Evaluate equality: ["=", a, b]
296
+ * Uses strict equality (===) for type safety.
297
+ */
298
+ declare function evalEqual(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
299
+ /**
300
+ * Evaluate not-equal: ["!=", a, b]
301
+ */
302
+ declare function evalNotEqual(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
303
+ /**
304
+ * Evaluate less-than: ["<", a, b]
305
+ */
306
+ declare function evalLessThan(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
307
+ /**
308
+ * Evaluate greater-than: [">", a, b]
309
+ */
310
+ declare function evalGreaterThan(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
311
+ /**
312
+ * Evaluate less-than-or-equal: ["<=", a, b]
313
+ */
314
+ declare function evalLessThanOrEqual(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
315
+ /**
316
+ * Evaluate greater-than-or-equal: [">=", a, b]
317
+ */
318
+ declare function evalGreaterThanOrEqual(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
319
+ /**
320
+ * Evaluate regex match: ["matches", subject, pattern]
321
+ * Returns true if subject matches the regex pattern.
322
+ */
323
+ declare function evalMatches(args: SExpr[], evaluate: Evaluator$4, ctx: EvaluationContext): boolean;
324
+
325
+ /**
326
+ * Logic Operator Implementations
327
+ *
328
+ * Implements: and, or, not, if
329
+ * All logic operators support short-circuit evaluation.
330
+ */
331
+
332
+ type Evaluator$3 = (expr: SExpr, ctx: EvaluationContext) => unknown;
333
+ /**
334
+ * Evaluate logical AND: ["and", a, b, ...]
335
+ * Short-circuits: returns false as soon as any argument is falsy.
336
+ */
337
+ declare function evalAnd(args: SExpr[], evaluate: Evaluator$3, ctx: EvaluationContext): boolean;
338
+ /**
339
+ * Evaluate logical OR: ["or", a, b, ...]
340
+ * Short-circuits: returns true as soon as any argument is truthy.
341
+ */
342
+ declare function evalOr(args: SExpr[], evaluate: Evaluator$3, ctx: EvaluationContext): boolean;
343
+ /**
344
+ * Evaluate logical NOT: ["not", a]
345
+ */
346
+ declare function evalNot(args: SExpr[], evaluate: Evaluator$3, ctx: EvaluationContext): boolean;
347
+ /**
348
+ * Evaluate conditional: ["if", condition, then, else]
349
+ * Only evaluates the branch that matches the condition.
350
+ */
351
+ declare function evalIf(args: SExpr[], evaluate: Evaluator$3, ctx: EvaluationContext): unknown;
352
+
353
+ /**
354
+ * Control Operator Implementations
355
+ *
356
+ * Implements: let, do, when, fn
357
+ */
358
+
359
+ type Evaluator$2 = (expr: SExpr, ctx: EvaluationContext) => unknown;
360
+ /**
361
+ * Evaluate let binding: ["let", [[name, value], ...], body]
362
+ * Creates local bindings for use in body.
363
+ */
364
+ declare function evalLet(args: SExpr[], evaluate: Evaluator$2, ctx: EvaluationContext): unknown;
365
+ /**
366
+ * Evaluate do block: ["do", expr1, expr2, ...]
367
+ * Executes expressions in sequence, returns last result.
368
+ */
369
+ declare function evalDo(args: SExpr[], evaluate: Evaluator$2, ctx: EvaluationContext): unknown;
370
+ /**
371
+ * Evaluate when: ["when", condition, effect]
372
+ * Executes effect only when condition is truthy.
373
+ */
374
+ declare function evalWhen(args: SExpr[], evaluate: Evaluator$2, ctx: EvaluationContext): void;
375
+ /**
376
+ * Evaluate lambda: ["fn", varName, body] or ["fn", [vars], body]
377
+ * Creates a function that can be passed to collection operators.
378
+ */
379
+ declare function evalFn(args: SExpr[], _evaluate: Evaluator$2, _ctx: EvaluationContext): (item: unknown, evaluate: Evaluator$2, ctx: EvaluationContext) => unknown;
380
+
381
+ /**
382
+ * Collection Operator Implementations
383
+ *
384
+ * Implements: map, filter, find, count, sum, first, last, nth, concat, includes, empty
385
+ */
386
+
387
+ type Evaluator$1 = (expr: SExpr, ctx: EvaluationContext) => unknown;
388
+ /**
389
+ * Evaluate map: ["map", collection, ["fn", varName, body]]
390
+ */
391
+ declare function evalMap(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown[];
392
+ /**
393
+ * Evaluate filter: ["filter", collection, ["fn", varName, predicate]]
394
+ */
395
+ declare function evalFilter(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown[];
396
+ /**
397
+ * Evaluate find: ["find", collection, ["fn", varName, predicate]]
398
+ */
399
+ declare function evalFind(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown;
400
+ /**
401
+ * Evaluate count: ["count", collection]
402
+ */
403
+ declare function evalCount(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): number;
404
+ /**
405
+ * Evaluate sum: ["sum", collection] or ["sum", collection, ["fn", varName, mapper]]
406
+ */
407
+ declare function evalSum(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): number;
408
+ /**
409
+ * Evaluate first: ["first", collection]
410
+ */
411
+ declare function evalFirst(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown;
412
+ /**
413
+ * Evaluate last: ["last", collection]
414
+ */
415
+ declare function evalLast(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown;
416
+ /**
417
+ * Evaluate nth: ["nth", collection, index]
418
+ */
419
+ declare function evalNth(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown;
420
+ /**
421
+ * Evaluate concat: ["concat", collection1, collection2, ...]
422
+ */
423
+ declare function evalConcat(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): unknown[];
424
+ /**
425
+ * Evaluate includes: ["includes", collection, element]
426
+ */
427
+ declare function evalIncludes(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): boolean;
428
+ /**
429
+ * Evaluate empty: ["empty", collection]
430
+ */
431
+ declare function evalEmpty(args: SExpr[], evaluate: Evaluator$1, ctx: EvaluationContext): boolean;
432
+
433
+ /**
434
+ * Effect Operator Implementations
435
+ *
436
+ * Implements: set, emit, persist, navigate, notify, spawn, despawn, call-service, render-ui
437
+ *
438
+ * Effect operators have side effects and require effect handlers in the context.
439
+ */
440
+
441
+ type Evaluator = (expr: SExpr, ctx: EvaluationContext) => unknown;
442
+ /**
443
+ * Evaluate set: ["set", "@entity.field", value] or ["set", "@entity.field", value, operation]
444
+ */
445
+ declare function evalSet(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
446
+ /**
447
+ * Evaluate emit: ["emit", eventKey] or ["emit", eventKey, payload]
448
+ */
449
+ declare function evalEmit(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
450
+ /**
451
+ * Evaluate persist: ["persist", action] or ["persist", action, data]
452
+ * Actions: "create", "update", "delete"
453
+ */
454
+ declare function evalPersist(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
455
+ /**
456
+ * Evaluate navigate: ["navigate", route] or ["navigate", route, params]
457
+ */
458
+ declare function evalNavigate(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
459
+ /**
460
+ * Evaluate notify: ["notify", message] or ["notify", message, type]
461
+ */
462
+ declare function evalNotify(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
463
+ /**
464
+ * Evaluate spawn: ["spawn", entityType] or ["spawn", entityType, props]
465
+ */
466
+ declare function evalSpawn(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
467
+ /**
468
+ * Evaluate despawn: ["despawn"] or ["despawn", entityId]
469
+ */
470
+ declare function evalDespawn(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
471
+ /**
472
+ * Evaluate call-service: ["call-service", service, method] or ["call-service", service, method, params]
473
+ */
474
+ declare function evalCallService(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
475
+ /**
476
+ * Evaluate render-ui:
477
+ * - ["render-ui", slot, pattern]
478
+ * - ["render-ui", slot, pattern, props]
479
+ * - ["render-ui", slot, pattern, props, priority]
480
+ * - ["render-ui", slot, null] - clears the slot
481
+ */
482
+ declare function evalRenderUI(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
483
+ /**
484
+ * Evaluate set-dynamic: ["set-dynamic", pathExpr, value]
485
+ * Used for dynamic field paths computed at runtime.
486
+ * The pathExpr should evaluate to a dot-separated path string.
487
+ */
488
+ declare function evalSetDynamic(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
489
+ /**
490
+ * Evaluate increment: ["increment", "@entity.field"] or ["increment", "@entity.field", amount]
491
+ */
492
+ declare function evalIncrement(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
493
+ /**
494
+ * Evaluate decrement: ["decrement", "@entity.field"] or ["decrement", "@entity.field", amount]
495
+ */
496
+ declare function evalDecrement(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
497
+
498
+ export { evalOr as $, evalFirst as A, evalFloor as B, CORE_BINDINGS as C, evalFn as D, type EvaluationContext as E, evalGreaterThan as F, evalGreaterThanOrEqual as G, evalIf as H, evalIncludes as I, evalIncrement as J, evalLast as K, evalLessThan as L, evalLessThanOrEqual as M, evalLet as N, evalMap as O, type ParsedBinding as P, evalMatches as Q, evalMax as R, type SExpr as S, evalMin as T, evalModulo as U, evalMultiply as V, evalNavigate as W, evalNot as X, evalNotEqual as Y, evalNotify as Z, evalNth as _, type CoreBinding as a, evalPersist as a0, evalRenderUI as a1, evalRound as a2, evalSet as a3, evalSetDynamic as a4, evalSpawn as a5, evalSubtract as a6, evalSum as a7, evalWhen as a8, getArgs as a9, getOperator as aa, isBinding as ab, isSExpr as ac, isSExprAtom as ad, isSExprCall as ae, isValidBinding as af, parseBinding as ag, resolveBinding as ah, sexpr as ai, walkSExpr as aj, type Expression as b, ExpressionSchema as c, type SExprAtom as d, SExprSchema as e, collectBindings as f, createChildContext as g, createEffectContext as h, createMinimalContext as i, evalAbs as j, evalAdd as k, evalAnd as l, evalCallService as m, evalCeil as n, evalClamp as o, evalConcat as p, evalCount as q, evalDecrement as r, evalDespawn as s, evalDivide as t, evalDo as u, evalEmit as v, evalEmpty as w, evalEqual as x, evalFilter as y, evalFind as z };
@@ -0,0 +1,73 @@
1
+ import { S as SExpr, E as EvaluationContext } from './index-BBb9Y3Sp.js';
2
+ export { C as CORE_BINDINGS, a as CoreBinding, b as Expression, c as ExpressionSchema, P as ParsedBinding, d as SExprAtom, e as SExprSchema, f as collectBindings, g as createChildContext, h as createEffectContext, i as createMinimalContext, j as evalAbs, k as evalAdd, l as evalAnd, m as evalCallService, n as evalCeil, o as evalClamp, p as evalConcat, q as evalCount, r as evalDecrement, s as evalDespawn, t as evalDivide, u as evalDo, v as evalEmit, w as evalEmpty, x as evalEqual, y as evalFilter, z as evalFind, A as evalFirst, B as evalFloor, D as evalFn, F as evalGreaterThan, G as evalGreaterThanOrEqual, H as evalIf, I as evalIncludes, J as evalIncrement, K as evalLast, L as evalLessThan, M as evalLessThanOrEqual, N as evalLet, O as evalMap, Q as evalMatches, R as evalMax, T as evalMin, U as evalModulo, V as evalMultiply, W as evalNavigate, X as evalNot, Y as evalNotEqual, Z as evalNotify, _ as evalNth, $ as evalOr, a0 as evalPersist, a1 as evalRenderUI, a2 as evalRound, a3 as evalSet, a4 as evalSetDynamic, a5 as evalSpawn, a6 as evalSubtract, a7 as evalSum, a8 as evalWhen, a9 as getArgs, aa as getOperator, ab as isBinding, ac as isSExpr, ad as isSExprAtom, ae as isSExprCall, af as isValidBinding, ag as parseBinding, ah as resolveBinding, ai as sexpr, aj as walkSExpr } from './index-BBb9Y3Sp.js';
3
+ import 'zod';
4
+
5
+ /**
6
+ * S-Expression Evaluator
7
+ *
8
+ * Runtime interpreter for S-expressions.
9
+ * Used for evaluating guards and executing effects in the preview system.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+
14
+ /**
15
+ * S-Expression Evaluator class.
16
+ *
17
+ * Provides runtime interpretation of S-expressions for guards, effects, and computed values.
18
+ */
19
+ declare class SExpressionEvaluator {
20
+ /**
21
+ * Evaluate an S-expression in the given context.
22
+ *
23
+ * @param expr - S-expression to evaluate
24
+ * @param ctx - Evaluation context with bindings and effect handlers
25
+ * @returns Result of evaluation
26
+ */
27
+ evaluate(expr: SExpr, ctx: EvaluationContext): unknown;
28
+ /**
29
+ * Evaluate an S-expression as a guard (returns boolean).
30
+ *
31
+ * @param expr - S-expression guard
32
+ * @param ctx - Evaluation context
33
+ * @returns true if guard passes, false otherwise
34
+ */
35
+ evaluateGuard(expr: SExpr, ctx: EvaluationContext): boolean;
36
+ /**
37
+ * Execute an effect S-expression.
38
+ *
39
+ * @param expr - Effect S-expression (e.g., ["set", "@entity.x", 10])
40
+ * @param ctx - Evaluation context with effect handlers
41
+ */
42
+ executeEffect(expr: SExpr, ctx: EvaluationContext): void;
43
+ /**
44
+ * Execute multiple effects in sequence.
45
+ *
46
+ * @param effects - Array of effect S-expressions
47
+ * @param ctx - Evaluation context with effect handlers
48
+ */
49
+ executeEffects(effects: SExpr[], ctx: EvaluationContext): void;
50
+ /**
51
+ * Compile an S-expression to a function for faster repeated evaluation.
52
+ * Uses a cache to avoid recompilation.
53
+ *
54
+ * @param expr - S-expression to compile
55
+ * @returns Function that evaluates the expression given a context
56
+ */
57
+ compile(expr: SExpr): (ctx: EvaluationContext) => unknown;
58
+ /**
59
+ * Clear the JIT compilation cache.
60
+ */
61
+ clearCache(): void;
62
+ /**
63
+ * Dispatch to the appropriate operator implementation.
64
+ */
65
+ private dispatchOperator;
66
+ }
67
+ declare const evaluator: SExpressionEvaluator;
68
+ declare function evaluate(expr: SExpr, ctx: EvaluationContext): unknown;
69
+ declare function evaluateGuard(expr: SExpr, ctx: EvaluationContext): boolean;
70
+ declare function executeEffect(expr: SExpr, ctx: EvaluationContext): void;
71
+ declare function executeEffects(effects: SExpr[], ctx: EvaluationContext): void;
72
+
73
+ export { EvaluationContext, SExpr, SExpressionEvaluator, evaluate, evaluateGuard, evaluator, executeEffect, executeEffects };