@almadar/evaluator 1.0.0 → 1.0.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.
@@ -1,145 +1,4 @@
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[];
1
+ import { SExpr } from '@almadar/core';
143
2
 
144
3
  /**
145
4
  * Evaluation Context
@@ -495,4 +354,4 @@ declare function evalIncrement(args: SExpr[], evaluate: Evaluator, ctx: Evaluati
495
354
  */
496
355
  declare function evalDecrement(args: SExpr[], evaluate: Evaluator, ctx: EvaluationContext): void;
497
356
 
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 };
357
+ export { evalWhen as $, evalIncludes as A, evalIncrement as B, evalLast as C, evalLessThan as D, type EvaluationContext as E, evalLessThanOrEqual as F, evalLet as G, evalMap as H, evalMatches as I, evalMax as J, evalMin as K, evalModulo as L, evalMultiply as M, evalNavigate as N, evalNot as O, evalNotEqual as P, evalNotify as Q, evalNth as R, evalOr as S, evalPersist as T, evalRenderUI as U, evalRound as V, evalSet as W, evalSetDynamic as X, evalSpawn as Y, evalSubtract as Z, evalSum as _, createEffectContext as a, resolveBinding as a0, createMinimalContext as b, createChildContext as c, evalAdd as d, evalAbs as e, evalAnd as f, evalCallService as g, evalCeil as h, evalClamp as i, evalConcat as j, evalCount as k, evalDecrement as l, evalDespawn as m, evalDivide as n, evalDo as o, evalEmit as p, evalEmpty as q, evalEqual as r, evalFilter as s, evalFind as t, evalFirst as u, evalFloor as v, evalFn as w, evalGreaterThan as x, evalGreaterThanOrEqual as y, evalIf as z };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
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';
1
+ import { SExpr } from '@almadar/core';
2
+ export { CORE_BINDINGS, CoreBinding, Expression, ExpressionSchema, ParsedBinding, SExpr, SExprAtom, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
3
+ import { E as EvaluationContext } from './index-DsM_--K3.js';
4
+ export { c as createChildContext, a as createEffectContext, b as createMinimalContext, e as evalAbs, d as evalAdd, f as evalAnd, g as evalCallService, h as evalCeil, i as evalClamp, j as evalConcat, k as evalCount, l as evalDecrement, m as evalDespawn, n as evalDivide, o as evalDo, p as evalEmit, q as evalEmpty, r as evalEqual, s as evalFilter, t as evalFind, u as evalFirst, v as evalFloor, w as evalFn, x as evalGreaterThan, y as evalGreaterThanOrEqual, z as evalIf, A as evalIncludes, B as evalIncrement, C as evalLast, D as evalLessThan, F as evalLessThanOrEqual, G as evalLet, H as evalMap, I as evalMatches, J as evalMax, K as evalMin, L as evalModulo, M as evalMultiply, N as evalNavigate, O as evalNot, P as evalNotEqual, Q as evalNotify, R as evalNth, S as evalOr, T as evalPersist, U as evalRenderUI, V as evalRound, W as evalSet, X as evalSetDynamic, Y as evalSpawn, Z as evalSubtract, _ as evalSum, $ as evalWhen, a0 as resolveBinding } from './index-DsM_--K3.js';
4
5
 
5
6
  /**
6
7
  * S-Expression Evaluator
@@ -70,4 +71,4 @@ declare function evaluateGuard(expr: SExpr, ctx: EvaluationContext): boolean;
70
71
  declare function executeEffect(expr: SExpr, ctx: EvaluationContext): void;
71
72
  declare function executeEffects(effects: SExpr[], ctx: EvaluationContext): void;
72
73
 
73
- export { EvaluationContext, SExpr, SExpressionEvaluator, evaluate, evaluateGuard, evaluator, executeEffect, executeEffects };
74
+ export { EvaluationContext, SExpressionEvaluator, evaluate, evaluateGuard, evaluator, executeEffect, executeEffects };