@almadar/evaluator 2.31.0 → 2.32.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/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isSExpr, isBinding, getOperator, getArgs, isFieldValue, isEventPayloadValue, isSessionHistoryEntry, isPlanSnapshot, OrbitalZodSchema, safeParseOrbitalSchema } from '@almadar/core';
2
2
  export { CORE_BINDINGS, ExpressionSchema, SExprSchema, collectBindings, getArgs, getOperator, isBinding, isSExpr, isSExprAtom, isSExprCall, isValidBinding, parseBinding, sexpr, walkSExpr } from '@almadar/core';
3
+ import { createRequire } from 'module';
3
4
 
4
5
  // types/expression.ts
5
6
 
@@ -103,6 +104,27 @@ function resolveBinding(binding, ctx) {
103
104
  }
104
105
  return value;
105
106
  }
107
+ var require2 = createRequire(import.meta.url);
108
+ var canonicalOperators = require2("@almadar/std/canonical-operators.json");
109
+ var ARITY = new Map(
110
+ Object.entries(canonicalOperators.operators).map(
111
+ ([name, meta]) => [
112
+ name,
113
+ { min: meta.minArity ?? 0, max: meta.maxArity === void 0 ? null : meta.maxArity }
114
+ ]
115
+ )
116
+ );
117
+ function assertOperatorArity(op, argCount) {
118
+ const bounds = ARITY.get(op);
119
+ if (!bounds) return;
120
+ const { min, max } = bounds;
121
+ if (argCount < min || max !== null && argCount > max) {
122
+ const range = max === null ? `at least ${min}` : min === max ? `${min}` : `${min}..${max}`;
123
+ throw new Error(
124
+ `(${op} \u2026): expected ${range} argument(s), got ${argCount} \u2014 same bounds the compiled path enforces (canonical-operators.json)`
125
+ );
126
+ }
127
+ }
106
128
 
107
129
  // operators/arithmetic.ts
108
130
  function evalAdd(args, evaluate2, ctx) {
@@ -3813,6 +3835,7 @@ var SExpressionEvaluator = class {
3813
3835
  * Dispatch to the appropriate operator implementation.
3814
3836
  */
3815
3837
  dispatchOperator(op, args, ctx) {
3838
+ assertOperatorArity(op, args.length);
3816
3839
  const evaluate2 = (expr, c) => this.evaluate(expr, c);
3817
3840
  switch (op) {
3818
3841
  // Arithmetic