@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.
- package/dist/{index-BBb9Y3Sp.d.ts → index-DsM_--K3.d.ts} +2 -143
- package/dist/index.d.ts +5 -4
- package/dist/index.js +697 -2
- package/dist/index.js.map +1 -1
- package/dist/operators/index.d.ts +2 -2
- package/package.json +3 -2
|
@@ -1,145 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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 {
|
|
2
|
-
export {
|
|
3
|
-
import '
|
|
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,
|
|
74
|
+
export { EvaluationContext, SExpressionEvaluator, evaluate, evaluateGuard, evaluator, executeEffect, executeEffects };
|