@statedelta-libs/expressions 3.0.0 → 3.2.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/README.md CHANGED
@@ -40,9 +40,12 @@ const compiled = compiler.compile({
40
40
  ]
41
41
  });
42
42
 
43
+ // Bind ao contexto → BoundFn callable
44
+ const fn = compiled.bind();
45
+
43
46
  // Executa milhões de vezes
44
- compiled.fn({ items: [{ active: true, price: 10 }, { active: false, price: 20 }] });
45
- compiled.deps; // ["items"]
47
+ fn({ items: [{ active: true, price: 10 }, { active: false, price: 20 }] });
48
+ fn.deps; // ["items"]
46
49
  ```
47
50
 
48
51
  ## Os 5 Primitivos
@@ -68,6 +71,70 @@ compiler.jit(expr); // JIT — compilação lenta, ~25-27M ops/s de exec
68
71
 
69
72
  **JIT** gera código JavaScript via AST e `new Function()`. Ideal para hot paths executados muitas vezes. Break-even em ~8 execuções.
70
73
 
74
+ ## 3 Fases: Compile → Bind → Run
75
+
76
+ Compilação e contexto são independentes. Compile uma vez, bind N vezes com contextos diferentes — zero recompilação.
77
+
78
+ ```typescript
79
+ const compiler = new ExpressionCompiler({ scope });
80
+
81
+ // Fase 1: Compile (pesado — uma vez) → Artifact
82
+ const artifact = compiler.jit(expr);
83
+
84
+ // Fase 2: Bind (barato — só DI) → BoundFn callable
85
+ const forTenant1 = artifact.bind({ scope, accessor: tenant1Accessor });
86
+ const forTenant2 = artifact.bind({ scope, accessor: tenant2Accessor });
87
+
88
+ // Fase 3: Run
89
+ forTenant1(data); // usa accessor do tenant 1
90
+ forTenant2(data); // usa accessor do tenant 2
91
+ ```
92
+
93
+ `BoundFn` é callable direto — sem `.fn`. Funciona com `.map()`, `.filter()` e qualquer API que espera funções. Metadata como propriedades:
94
+
95
+ ```typescript
96
+ const fn = compiler.compile(expr).bind();
97
+ fn(data); // executa
98
+ fn.deps; // paths observados
99
+ fn.hash; // hash estrutural
100
+ ```
101
+
102
+ ### DI-first — construtor sem contexto
103
+
104
+ O compilador funciona sem contexto no construtor. Contexto é injetado via `bind()`:
105
+
106
+ ```typescript
107
+ const compiler = new ExpressionCompiler(); // sem scope/accessor/handlers
108
+
109
+ const artifact = compiler.compile(expr);
110
+ const fn = artifact.bind({ scope, accessor });
111
+ fn(data);
112
+ ```
113
+
114
+ ### Compile cache compartilhável
115
+
116
+ `CompileCache` armazena artefatos context-free compartilháveis entre instâncias:
117
+
118
+ ```typescript
119
+ import { ExpressionCompiler, CompileCache } from '@statedelta-libs/expressions';
120
+
121
+ const sharedCache = new CompileCache(5000);
122
+
123
+ const tenantA = new ExpressionCompiler({ scope: scopeA, compileCache: sharedCache });
124
+ const tenantB = new ExpressionCompiler({ scope: scopeB, compileCache: sharedCache });
125
+
126
+ // Mesma expressão compilada uma vez, bind por tenant
127
+ tenantA.jit(expr).bind()(data); // compile cache miss → compile + bind
128
+ tenantB.jit(expr).bind()(data); // compile cache hit → só bind
129
+ ```
130
+
131
+ **Cenários habilitados:**
132
+
133
+ - **Multi-tenant** — `CompileCache` compartilhado, bind por tenant
134
+ - **Hot-swap de accessor por tick** — compile uma vez, bind a cada tick
135
+ - **Testing** — mesmo artifact, scope mockado via bind
136
+ - **Lazy bind** — compile no boot, bind sob demanda
137
+
71
138
  ## Extensibilidade
72
139
 
73
140
  ### Scope — funções disponíveis
@@ -100,7 +167,7 @@ compiler.compile(pure);
100
167
 
101
168
  ### Boundaries — compiladores externos
102
169
 
103
- Intercepta nós **durante** a compilação e terceiriza para outro algoritmo. Para quando o nó precisa de um compilador completamente diferente.
170
+ Intercepta nós **durante** a compilação e terceiriza para outro algoritmo. Para quando o nó precisa de um compilador completamente diferente. Boundaries são **compile-time** — ficam fixos entre `bind()` calls.
104
171
 
105
172
  ```typescript
106
173
  import type { BoundaryDef } from '@statedelta-libs/expressions';
@@ -139,13 +206,91 @@ O handler é uma closure auto-suficiente — captura o que precisa (outros compi
139
206
  | **Quando roda** | Antes da compilação | Durante a compilação (no walk) |
140
207
  | **Retorno** | `Expression` (DSL puro) | `CompiledFn` (função pronta) |
141
208
  | **Uso típico** | Sugar syntax | DSL estrangeiro, `$raw`, rule engines |
209
+ | **bind()** | N/A | Fixo (compile-time) |
210
+
211
+ ### Handlers — services com contexto
212
+
213
+ O `scope` é para funções puras e stateless. Quando o consumer precisa de **services inteligentes** que acessam o sistema (accessor, outros handlers, o compilador, o scope), usa `handlers`.
214
+
215
+ ```typescript
216
+ import type { HandlerContext } from '@statedelta-libs/expressions';
217
+
218
+ const compiler = new ExpressionCompiler({
219
+ scope: { add: (a, b) => a + b },
220
+ handlers: {
221
+ query: {
222
+ find(key: string) {
223
+ return db.find(key);
224
+ },
225
+ findAll() {
226
+ // chamar outro handler
227
+ const valid = this.handlers.validation.check("all");
228
+ return valid ? db.findAll() : [];
229
+ },
230
+ },
231
+ validation: {
232
+ check(value: unknown) {
233
+ // chamar scope fn
234
+ return this.scope.add(value != null ? 1 : 0, 0) > 0;
235
+ },
236
+ },
237
+ },
238
+ });
239
+ ```
240
+
241
+ Handlers são invocados via `$fn` com sintaxe `"namespace:method"`:
242
+
243
+ ```json
244
+ { "$fn": "query:find", "args": [{ "$": "userId" }] }
245
+ { "$fn": "validation:check", "args": [{ "$": "value" }] }
246
+ ```
247
+
248
+ O contexto é acessado via `this`, injetado automaticamente via `.bind()` no construtor. O `HandlerContext` é criado **uma vez** — zero alocação por chamada:
249
+
250
+ | Campo | O que contém |
251
+ |-------|-------------|
252
+ | `this.accessor` | Resolver de paths customizado |
253
+ | `this.handlers` | Todos os handlers (wrapped) — permite composição entre handlers |
254
+ | `this.compiler` | Instância do compilador — permite compilar sub-expressões |
255
+ | `this.scope` | Funções puras do scope |
256
+
257
+ Handlers **devem** ser regular functions ou method shorthand (arrow functions ignoram `.bind()`):
258
+
259
+ ```typescript
260
+ // method shorthand — funciona
261
+ handlers: { query: { find(key) { this.scope... } } }
262
+
263
+ // regular function — funciona
264
+ handlers: { query: { find: function(key) { this.scope... } } }
265
+
266
+ // arrow function — NÃO funciona (this é undefined)
267
+ handlers: { query: { find: (key) => { this.scope... } } }
268
+ ```
269
+
270
+ | | `scope` | `handlers` |
271
+ |---|---|---|
272
+ | **Natureza** | Funções puras (Ramda-style) | Services com contexto |
273
+ | **Acessa** | Apenas args compilados | `this` (HandlerContext) + args |
274
+ | **DSL** | `{ $fn: "add", args: [...] }` | `{ $fn: "query:find", args: [...] }` |
275
+ | **Binding** | Nenhum | `.bind(ctx)` uma vez no construtor |
276
+ | **Overhead** | Zero | Zero (ctx e bindings criados uma vez) |
277
+ | **bind()** | Trocável via `ctx.scope` | Trocável via `ctx.handlers` |
278
+
279
+ Zero overhead quando nenhum handler é registrado.
142
280
 
143
281
  ### Accessor — objetos inteligentes
144
282
 
145
283
  ```typescript
146
284
  const compiler = new ExpressionCompiler({
147
285
  scope,
148
- accessor: (path, ctx) => ctx.get(path), // ex: TickContext, reactive store
286
+ accessor: (path) => tickContext.get(path), // closure auto-suficiente
287
+ });
288
+
289
+ // Hot-swap por tick via bind()
290
+ const artifact = compiler.jit(expr, { useAccessor: true });
291
+ const fn = artifact.bind({
292
+ scope,
293
+ accessor: (path) => newTickContext.get(path),
149
294
  });
150
295
  ```
151
296
 
@@ -153,10 +298,9 @@ const compiler = new ExpressionCompiler({
153
298
 
154
299
  | Doc | Conteúdo |
155
300
  |-----|----------|
156
- | [docs/EXPRESSIONS-API.md](docs/EXPRESSIONS-API.md) | Referência completa da API pública |
157
- | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Visão geral da infraestrutura |
158
- | [docs/COMPILE.md](docs/COMPILE.md) | Internals do pipeline closures |
159
- | [docs/JIT.md](docs/JIT.md) | Internals do pipeline JIT |
301
+ | [EXPRESSIONS-API.md](EXPRESSIONS-API.md) | Referência completa da API pública |
302
+ | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | Arquitetura interna (IR, backends, cache) |
303
+ | [docs/TEMPLATE.md](docs/TEMPLATE.md) | Template compiler (compileDefinition) |
160
304
 
161
305
  ## Licença
162
306
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var omniAst=require('omni-ast');var xn=Object.defineProperty;var Fn=(n,e)=>{for(var i in e)xn(n,i,{get:e[i],enumerable:true});};var _=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),y=n=>n!==null&&typeof n=="object"&&"$"in n&&typeof n.$=="string"&&Object.keys(n).length===1,T=n=>n!==null&&typeof n=="object"&&"$if"in n&&"then"in n,C=n=>n!==null&&typeof n=="object"&&"$fn"in n&&typeof n.$fn=="string",b=n=>n!==null&&typeof n=="object"&&"$pipe"in n&&Array.isArray(n.$pipe),$=n=>n!==null&&typeof n=="object"&&"$arrow"in n,E=n=>n!==null&&typeof n=="object"&&"left"in n&&"op"in n&&_.has(n.op)&&!("$"in n)&&!("$if"in n)&&!("$fn"in n),h=n=>n!==null&&typeof n=="object"&&"logic"in n&&"conditions"in n,Rn=n=>E(n)||h(n),J=n=>{if(n===null)return true;let e=typeof n;if(e==="string"||e==="number"||e==="boolean"||Array.isArray(n))return true;if(e==="object"&&n!==null){let i=n,r="left"in i&&"op"in i&&_.has(i.op);return !("$"in i)&&!("$if"in i)&&!("$fn"in i)&&!("$pipe"in i)&&!("$arrow"in i)&&!r&&!("logic"in i)}return false};var U=new Map;function N(n){let e=[],i=n.length,r=0,o="";for(;r<i;){let s=n[r];if(s===".")o&&(e.push({type:"key",value:o}),o=""),r++;else if(s==="["){o&&(e.push({type:"key",value:o}),o=""),r++;let t=r;for(;r<i&&n[r]!=="]";)r++;let f=n.slice(t,r);if(r++,f==="*")e.push({type:"wildcard",value:"*"});else {let c=parseInt(f,10);e.push({type:"index",value:isNaN(c)?f:c});}}else o+=s,r++;}return o&&e.push({type:"key",value:o}),e}function X(n){return n.includes("[*]")}function G(n){let e=U.get(n);return e||(e=X(n)?jn(n):On(n),U.set(n,e),e)}function On(n){if(!n.includes(".")&&!n.includes("["))return o=>o?.[n];let e=N(n),i=e.length;if(i===2){let[o,s]=e,t=o.value,f=s.value;return c=>c?.[t]?.[f]}if(i===3){let[o,s,t]=e,f=o.value,c=s.value,l=t.value;return a=>a?.[f]?.[c]?.[l]}let r=e.map(o=>o.value);return o=>{let s=o;for(let t=0;t<i&&s!=null;t++)s=s[r[t]];return s}}function jn(n){let e=N(n),i=[];for(let r=0;r<e.length;r++)e[r].type==="wildcard"&&i.push(r);return i.length===1?Nn(e,i[0]):vn(e,i)}function Nn(n,e){let i=n.slice(0,e).map(t=>t.value),r=n.slice(e+1).map(t=>t.value),o=i.length,s=r.length;if(s===0){if(o===1){let t=i[0];return f=>f?.[t]}return t=>{let f=t;for(let c=0;c<o&&f!=null;c++)f=f[i[c]];return f}}if(s===1){let t=r[0];if(o===1){let f=i[0];return c=>{let l=c?.[f];if(Array.isArray(l))return l.map(a=>a?.[t])}}return f=>{let c=f;for(let l=0;l<o&&c!=null;l++)c=c[i[l]];if(Array.isArray(c))return c.map(l=>l?.[t])}}return t=>{let f=t;for(let c=0;c<o&&f!=null;c++)f=f[i[c]];if(Array.isArray(f))return f.map(c=>{let l=c;for(let a=0;a<s&&l!=null;a++)l=l[r[a]];return l})}}function vn(n,e){let i=[],r=0;for(let s=0;s<e.length;s++){let t=e[s],f=s===e.length-1,c=n.slice(r,t).map(l=>l.value);c.length>0&&i.push({type:"access",keys:c}),i.push({type:f?"map":"flatMap",keys:[]}),r=t+1;}let o=n.slice(r).map(s=>s.value);return s=>{let t=s;for(let f of i){if(t==null)return;if(f.type==="access")for(let c of f.keys){if(t==null)return;t=t[c];}else if(f.type==="flatMap"){if(!Array.isArray(t))return;t=t.flatMap(c=>{let l=c;return Array.isArray(l)?l:[l]});}else if(f.type==="map"){if(!Array.isArray(t))return;o.length>0&&(t=t.map(c=>{let l=c;for(let a of o){if(l==null)return;l=l[a];}return l}));}}return t}}function Dn(n,e){return G(e)(n)}function W(n){let e=n.indexOf("[*]");return e===-1?n:n.slice(0,e)}function R(n){let e=new Set;return A(n,e),Array.from(e)}function A(n,e){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let o=0;o<n.length;o++)A(n[o],e);return}if(y(n)){e.add(W(n.$));return}if(T(n)){if(typeof n.$if=="string"){let o=n.$if.startsWith("!")?n.$if.slice(1):n.$if;e.add(W(o));}else A(n.$if,e);A(n.then,e),n.else!==void 0&&A(n.else,e);return}if(b(n)){for(let o=0;o<n.$pipe.length;o++)A(n.$pipe[o],e);return}if(C(n)){if(n.args)for(let o=0;o<n.args.length;o++)A(n.args[o],e);return}if($(n)){let o=new Set;A(n.$arrow,o);let s=new Set(n.args??[]);for(let t of o){let f=t.split(".")[0].split("[")[0];s.has(f)||e.add(t);}return}if(E(n)){A(n.left,e),n.right!==void 0&&A(n.right,e);return}if(h(n)){for(let o=0;o<n.conditions.length;o++)A(n.conditions[o],e);return}let i=n,r=Object.keys(i);for(let o=0;o<r.length;o++)A(i[r[o]],e);}function In(n){return R(n).length>0}function Bn(n){return R(n).length===0}var Z;function P(n){Z=n;}function O(n,e,i,r){return Z(n,e,i,r)}function nn(n,e){return e?i=>e(n,i):G(n)}function en(n,e){return nn(n.$,e)}function tn(n,e,i,r){let o;if(typeof n.$if=="string"){let f=n.$if.startsWith("!")?n.$if.slice(1):n.$if,c=nn(f,i);o=n.$if.startsWith("!")?a=>!c(a):a=>!!c(a);}else {let f=O(n.$if,e,i,r);o=c=>!!f(c);}let s=O(n.then,e,i,r),t=n.else!==void 0?O(n.else,e,i,r):()=>{};return f=>o(f)?s(f):t(f)}function on(n,e,i,r){let o=n.$pipe;if(o.length===0)return ()=>{};if(o.length===1)return O(o[0],e,i,r);let s=O(o[0],e,i,r),t=o.slice(1).map(c=>O(c,e,i,r)),f=t.length;if(f===1){let[c]=t;return l=>{let a=s(l),p=c(l);return typeof p=="function"?p(a):p}}if(f===2){let[c,l]=t;return a=>{let p=s(a),d=c(a);return p=typeof d=="function"?d(p):d,d=l(a),typeof d=="function"?d(p):d}}if(f===3){let[c,l,a]=t;return p=>{let d=s(p),m=c(p);return d=typeof m=="function"?m(d):m,m=l(p),d=typeof m=="function"?m(d):m,m=a(p),typeof m=="function"?m(d):m}}return c=>{let l=s(c);for(let a=0;a<f;a++){let p=t[a](c);l=typeof p=="function"?p(l):p;}return l}}function rn(n,e,i,r){let o=n.$fn,s=n.args;if(s===void 0)return ()=>{let c=e[o];if(!c)throw new Error(`Function not found in scope: ${o}`);return c};let t=s.map(c=>O(c,e,i,r)),f=t.length;if(f===0)return ()=>{let c=e[o];if(!c)throw new Error(`Function not found in scope: ${o}`);return c()};if(f===1){let[c]=t;return l=>{let a=e[o];if(!a)throw new Error(`Function not found in scope: ${o}`);return a(c(l))}}if(f===2){let[c,l]=t;return a=>{let p=e[o];if(!p)throw new Error(`Function not found in scope: ${o}`);return p(c(a),l(a))}}if(f===3){let[c,l,a]=t;return p=>{let d=e[o];if(!d)throw new Error(`Function not found in scope: ${o}`);return d(c(p),l(p),a(p))}}return c=>{let l=e[o];if(!l)throw new Error(`Function not found in scope: ${o}`);return l(...t.map(a=>a(c)))}}function sn(n,e,i,r){let o=n.args??[];if(o.length===0){let t=O(n.$arrow,e,i,r);return f=>()=>t(f)}let s=O(n.$arrow,e,i,r);return t=>(...f)=>{let c={};for(let a=0;a<o.length;a++)c[o[a]]=f[a];let l={...t,...c};return s(l)}}var fn;function cn(n){fn=n;}function L(n,e,i,r){return fn(n,e,i,r)}function un(n,e,i,r){let o=L(n.left,e,i,r),s=n.right!==void 0?L(n.right,e,i,r):()=>{};switch(n.op){case "eq":return t=>o(t)===s(t);case "neq":return t=>o(t)!==s(t);case "gt":return t=>o(t)>s(t);case "gte":return t=>o(t)>=s(t);case "lt":return t=>o(t)<s(t);case "lte":return t=>o(t)<=s(t);case "in":return t=>{let f=s(t);return Array.isArray(f)&&f.includes(o(t))};case "notIn":return t=>{let f=s(t);return !Array.isArray(f)||!f.includes(o(t))};case "contains":return t=>{let f=o(t);return Array.isArray(f)&&f.includes(s(t))};case "notContains":return t=>{let f=o(t);return !Array.isArray(f)||!f.includes(s(t))};case "exists":return t=>o(t)!==void 0;case "notExists":return t=>o(t)===void 0;case "matches":return t=>{let f=o(t),c=s(t);return typeof f!="string"||typeof c!="string"?false:new RegExp(c).test(f)};case "notMatches":return t=>{let f=o(t),c=s(t);return typeof f!="string"||typeof c!="string"?true:!new RegExp(c).test(f)};case "startsWith":return t=>{let f=o(t),c=s(t);return typeof f=="string"&&typeof c=="string"&&f.startsWith(c)};case "endsWith":return t=>{let f=o(t),c=s(t);return typeof f=="string"&&typeof c=="string"&&f.endsWith(c)}}}function ln(n,e,i,r){let o=n.conditions.map(t=>L(t,e,i,r)),s=o.length;if(s===1)return t=>!!o[0](t);if(s===2){let[t,f]=o;return n.logic==="AND"?c=>!!t(c)&&!!f(c):c=>!!t(c)||!!f(c)}if(s===3){let[t,f,c]=o;return n.logic==="AND"?l=>!!t(l)&&!!f(l)&&!!c(l):l=>!!t(l)||!!f(l)||!!c(l)}return n.logic==="AND"?t=>{for(let f=0;f<s;f++)if(!o[f](t))return false;return true}:t=>{for(let f=0;f<s;f++)if(o[f](t))return true;return false}}function zn(n){return JSON.stringify(n)}function an(n,e={}){let i=e.scope??{},r=e.accessor,o=e.boundaries,s=I(n,i,r,o),t=R(n),f=zn(n);return {fn:s,deps:t,hash:f}}function I(n,e,i,r){if(n===null)return ()=>null;if(typeof n!="object")return ()=>n;if(Array.isArray(n)){let o=n.map(s=>I(s,e,i,r));return s=>o.map(t=>t(s))}if(y(n))return en(n,i);if(T(n))return tn(n,e,i,r);if(b(n))return on(n,e,i,r);if(C(n))return rn(n,e,i,r);if($(n))return sn(n,e,i,r);if(E(n))return un(n,e,i,r);if(h(n))return ln(n,e,i,r);if(r?.length){let o=n;for(let s of r)if(s.check(o))return s.handle(o)}if(J(n)){let o=n,s=Object.keys(o),t=s.map(f=>I(o[f],e,i,r));return f=>{let c={};for(let l=0;l<s.length;l++)c[s[l]]=t[l](f);return c}}return ()=>n}P(I);cn(I);function pn(n){let e=new Set;return w(n,e),e}function w(n,e){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)w(r,e);return}if(y(n))return;if(T(n)){w(n.$if,e),w(n.then,e),n.else!==void 0&&w(n.else,e);return}if(b(n)){for(let r of n.$pipe)w(r,e);return}if(C(n)){if(e.add(n.$fn),n.args)for(let r of n.args)w(r,e);return}if($(n)){w(n.$arrow,e);return}if(E(n)){n.left!==void 0&&typeof n.left=="object"&&w(n.left,e),n.right!==void 0&&typeof n.right=="object"&&w(n.right,e);return}if(h(n)){for(let r of n.conditions)w(r,e);return}let i=n;for(let r of Object.keys(i))w(i[r],e);}function dn(n){let e=new Set;for(let i of n){let r=i.indexOf("."),o=i.indexOf("["),s=i.length;r!==-1&&(s=Math.min(s,r)),o!==-1&&(s=Math.min(s,o));let t=i.slice(0,s);t&&e.add(t);}return e}var _n="data",Gn="scope",B="__",Wn={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function gn(n,e={}){let{dataParam:i=_n,scopeParam:r=Gn,noPrefixes:o=false,useAccessor:s=false,lexicalPrefix:t}=e;return g(n,i,r,o,s,t)}function g(n,e,i,r,o,s,t){if(n===null)return omniAst.builders.literal(null);if(typeof n=="string")return omniAst.builders.literal(n);if(typeof n=="number")return omniAst.builders.literal(n);if(typeof n=="boolean")return omniAst.builders.literal(n);if(Array.isArray(n))return omniAst.builders.arrayExpression(n.map(f=>g(f,e,i,r,o,s,t)));if(y(n))return Mn(n.$,e,r,o,s,t);if(T(n))return Vn(n,e,i,r,o,s,t);if(b(n))return Kn(n.$pipe,e,i,r,o,s,t);if(C(n))return qn(n,e,i,r,o,s,t);if($(n))return Ln(n,e,i,r,o,s,t);if(E(n))return Yn(n,e,i,r,o,s,t);if(h(n))return Hn(n,e,i,r,o,s,t);if(typeof n=="object"&&"$__b"in n){let f=n.$__b;return omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.memberExpression(omniAst.builders.identifier(B),omniAst.builders.identifier("b")),omniAst.builders.literal(f),true,false),[omniAst.builders.identifier(e)])}if(typeof n=="object"){let c=Object.entries(n).map(([l,a])=>omniAst.builders.property(omniAst.builders.identifier(l),g(a,e,i,r,o,s,t)));return omniAst.builders.objectExpression(c)}return omniAst.builders.literal(null)}var V="accessor";function q(n,e){return e?n===e||n.startsWith(e+"."):false}function K(n){let e=n.indexOf("."),i=n.indexOf("["),r=n.length;return e!==-1&&(r=Math.min(r,e)),i!==-1&&(r=Math.min(r,i)),n.slice(0,r)}function Mn(n,e,i,r,o,s){return s&&s.has(K(n))?x(n,e,true):r?q(n,o)?x(n,e,true):omniAst.builders.callExpression(omniAst.builders.identifier(V),[omniAst.builders.literal(n),omniAst.builders.identifier(e)]):n.includes("[*]")?Jn(n,e,i):x(n,e,i)}function x(n,e,i){let r=N(n);if(r.length===0)return i?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(e);let o;if(i){let s=r[0];o=omniAst.builders.identifier(s.value);for(let t=1;t<r.length;t++){let f=r[t];f.type==="key"?o=omniAst.builders.memberExpression(o,omniAst.builders.identifier(f.value),false,true):o=omniAst.builders.memberExpression(o,omniAst.builders.literal(f.value),true,true);}}else {o=omniAst.builders.identifier(e);for(let s of r)s.type==="key"?o=omniAst.builders.memberExpression(o,omniAst.builders.identifier(s.value),false,true):o=omniAst.builders.memberExpression(o,omniAst.builders.literal(s.value),true,true);}return o}function Jn(n,e,i){let r=n.indexOf("[*]"),o=n.slice(0,r),s=n.slice(r+3),t;if(o?t=x(o,e,i):t=i?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(e),!s||s==="")return t;if(s.includes("[*]"))return yn(t,s);let f="_i",c=s.startsWith(".")?s.slice(1):s,l=omniAst.builders.identifier(f);if(c){let a=N(c);for(let p of a)p.type==="key"?l=omniAst.builders.memberExpression(l,omniAst.builders.identifier(p.value),false,true):l=omniAst.builders.memberExpression(l,omniAst.builders.literal(p.value),true,true);}return omniAst.builders.callExpression(omniAst.builders.memberExpression(t,omniAst.builders.identifier("map"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(f)],l)])}function yn(n,e){let i=e.indexOf("[*]"),r=e.slice(0,i),o=e.slice(i+3),s="_i",t=r.startsWith(".")?r.slice(1):r,f=omniAst.builders.identifier(s);if(t){let l=N(t);for(let a of l)a.type==="key"&&(f=omniAst.builders.memberExpression(f,omniAst.builders.identifier(a.value),false,true));}if(o.includes("[*]")){let l=yn(f,o);return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(s)],l)])}let c=o.startsWith(".")?o.slice(1):o;if(c){let l=N(c);for(let a of l)a.type==="key"&&(f=omniAst.builders.memberExpression(f,omniAst.builders.identifier(a.value),false,true));}return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(s)],f)])}function Ln(n,e,i,r,o,s,t){let f=n.args??[],c=new Set(t);for(let p of f)c.add(p);let l=g(n.$arrow,e,i,r,o,s,c),a=f.map(p=>omniAst.builders.identifier(p));return omniAst.builders.arrowFunctionExpression(a,l)}function Vn(n,e,i,r,o,s,t){let f;if(typeof n.$if=="string"){let a=n.$if.startsWith("!"),p=a?n.$if.slice(1):n.$if,d;t&&t.has(K(p))?d=x(p,e,true):o?q(p,s)?d=x(p,e,true):d=omniAst.builders.callExpression(omniAst.builders.identifier(V),[omniAst.builders.literal(p),omniAst.builders.identifier(e)]):d=x(p,e,r),f=a?omniAst.builders.unaryExpression("!",d):d;}else f=g(n.$if,e,i,r,o,s,t);let c=g(n.then,e,i,r,o,s,t),l=n.else!==void 0?g(n.else,e,i,r,o,s,t):omniAst.builders.identifier("undefined");return omniAst.builders.conditionalExpression(f,c,l)}function qn(n,e,i,r,o,s,t){let f=r?omniAst.builders.identifier(n.$fn):omniAst.builders.memberExpression(omniAst.builders.identifier(i),omniAst.builders.identifier(n.$fn),false,false);if(n.args===void 0)return f;let c=n.args.map(l=>g(l,e,i,r,o,s,t));return omniAst.builders.callExpression(f,c)}function Kn(n,e,i,r,o,s,t){if(n.length===0)return omniAst.builders.identifier("undefined");if(n.length===1)return g(n[0],e,i,r,o,s,t);let f=g(n[0],e,i,r,o,s,t);for(let c=1;c<n.length;c++){let l=g(n[c],e,i,r,o,s,t);f=omniAst.builders.callExpression(l,[f]);}return f}function mn(n,e,i,r,o,s,t){if(y(n)){let f=n.$;return t&&t.has(K(f))?x(f,e,true):o?q(f,s)?x(f,e,true):omniAst.builders.callExpression(omniAst.builders.identifier(V),[omniAst.builders.literal(f),omniAst.builders.identifier(e)]):x(f,e,r)}return g(n,e,i,r,o,s,t)}function Yn(n,e,i,r,o,s,t){let f=mn(n.left,e,i,r,o,s,t),c=n.right!==void 0?mn(n.right,e,i,r,o,s,t):omniAst.builders.literal(null),l=Wn[n.op];if(l)return omniAst.builders.binaryExpression(l,f,c);switch(n.op){case "in":return omniAst.builders.callExpression(omniAst.builders.memberExpression(c,omniAst.builders.identifier("includes")),[f]);case "notIn":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(c,omniAst.builders.identifier("includes")),[f]));case "contains":return omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("includes"),false,true),[c]);case "notContains":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("includes"),false,true),[c]));case "exists":return omniAst.builders.binaryExpression("!=",f,omniAst.builders.literal(null));case "notExists":return omniAst.builders.binaryExpression("==",f,omniAst.builders.literal(null));case "matches":return omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[c]),omniAst.builders.identifier("test")),[f]);case "notMatches":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[c]),omniAst.builders.identifier("test")),[f]));case "startsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("startsWith"),false,true),[c]);case "endsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("endsWith"),false,true),[c]);default:return omniAst.builders.binaryExpression("===",f,c)}}function Hn(n,e,i,r,o,s,t){let{logic:f,conditions:c}=n,l=f==="AND"?"&&":"||";if(c.length===0)return omniAst.builders.literal(f==="AND");if(c.length===1)return g(c[0],e,i,r,o,s,t);let a=g(c[0],e,i,r,o,s,t);for(let p=1;p<c.length;p++){let d=g(c[p],e,i,r,o,s,t);a=omniAst.builders.logicalExpression(l,a,d);}return a}function En(n,e,i,r,o,s=0){let t=gn(n,{noPrefixes:true,useAccessor:r,lexicalPrefix:o}),f=omniAst.generate(t),c="";r?o&&(c=`const{${o}}=data??{};`):e.size>0&&(c=`const{${[...e].join(",")}}=data??{};`);let l=i.size>0?`const{${[...i].join(",")}}=scope;`:"",a=r||s>0,p="";if(a){let D=[];r&&D.push("accessor"),s>0&&D.push("b"),p=`const{${D.join(",")}}=${B};`;}let d=i.size>0,m;d&&a?m=`scope,${B}`:d?m="scope":a?m=`_,${B}`:m="";let v=`${c}return ${f}`,j;return m?j=`(function(${m}){${l}${p}return function(data){${v}}})`:j=`(function(){return function(data){${v}}})`,j}function Un(n){return JSON.stringify(n)}function S(n,e,i){if(n===null||typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>S(s,e,i));if(y(n))return n;if(T(n))return {$if:typeof n.$if=="string"?n.$if:S(n.$if,e,i),then:S(n.then,e,i),...n.else!==void 0?{else:S(n.else,e,i)}:{}};if(b(n))return {$pipe:n.$pipe.map(s=>S(s,e,i))};if(C(n))return {$fn:n.$fn,...n.args!==void 0?{args:n.args.map(s=>S(s,e,i))}:{}};if($(n))return {$arrow:S(n.$arrow,e,i),...n.args?{args:n.args}:{},...n.schema?{schema:n.schema}:{}};if(E(n))return {left:S(n.left,e,i),op:n.op,...n.right!==void 0?{right:S(n.right,e,i)}:{}};if(h(n))return {logic:n.logic,conditions:n.conditions.map(s=>S(s,e,i))};let r=n;for(let s of e)if(s.check(r)){let t=i.length;return i.push(s.handle(r)),{$__b:t}}let o={};for(let s of Object.keys(r))o[s]=S(r[s],e,i);return o}function hn(n,e={}){let{scope:i={},accessor:r,returnCode:o=false,useAccessor:s=false,lexicalPrefix:t,boundaries:f}=e,c=n,l=[];if(f?.length){let F=[];c=S(n,f,F),l=F;}let a=R(c),p=dn(a),d=pn(c),m=Un(n),v=En(c,p,d,s,t,l.length);if(o)return {code:v,deps:a,hash:m,dataRoots:[...p],scopeFns:[...d]};let j={};s&&r&&(j.accessor=r),l.length>0&&(j.b=l);let D=Object.keys(j).length>0,Q;try{let F=new Function(`return ${v}`)();Q=D?F(i,j):F(i);}catch(F){throw new Error(`AST compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${F instanceof Error?F.message:String(F)}`)}return {fn:Q,deps:a,hash:m}}function Tn(n,e){return M(n,e)}function M(n,e){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>M(s,e));let i=n,r=Object.keys(i);for(let s of r)if(s in e){let t=e[s](i);if(typeof t=="object"&&t!==null&&s in t)throw new Error(`Transform "${s}" returned object with same key \u2014 infinite loop`);return M(t,e)}let o={};for(let s of r)o[s]=M(i[s],e);return o}var z=class{constructor(e=1e3){this.cache=new Map,this._maxSize=e;}getOrCompile(e,i){let r=JSON.stringify(e),o=this.cache.get(r);if(o)return this.cache.delete(r),this.cache.set(r,o),o;let s=i();if(this.cache.size>=this._maxSize){let t=this.cache.keys().next().value;t&&this.cache.delete(t);}return this.cache.set(r,s),s}has(e){return this.cache.has(JSON.stringify(e))}delete(e){return this.cache.delete(JSON.stringify(e))}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(e){for(this._maxSize=e;this.cache.size>this._maxSize;){let i=this.cache.keys().next().value;i&&this.cache.delete(i);}}};var Y=class{constructor(e={}){this.scope=e.scope??{},this.accessor=e.accessor,this.boundaries=e.boundaries,this.cacheClosures=new z(e.cacheSize??1e3),this.cacheJIT=new z(e.cacheSize??1e3);}compile(e){return this.cacheClosures.getOrCompile(e,()=>an(e,{scope:this.scope,accessor:this.accessor,boundaries:this.boundaries}))}jit(e,i){return this.cacheJIT.getOrCompile(e,()=>hn(e,{scope:this.scope,accessor:this.accessor,useAccessor:i?.useAccessor,lexicalPrefix:i?.lexicalPrefix,boundaries:this.boundaries}))}evaluate(e,i){return this.compile(e).fn(i)}evaluateJIT(e,i,r){return this.jit(e,r).fn(i)}normalize(e,i){return Tn(e,i)}extractDeps(e){return R(e)}get cacheSize(){return {closures:this.cacheClosures.size,jit:this.cacheJIT.size}}clearCache(){this.cacheClosures.clear(),this.cacheJIT.clear();}getScope(){return this.scope}};var kn={};Fn(kn,{$:()=>Cn,$arrow:()=>wn,$call:()=>Sn,$cond:()=>An,$fn:()=>bn,$if:()=>Pn,$pipe:()=>$n,arrow:()=>te,call:()=>ie,cond:()=>ee,fn:()=>Zn,pipe:()=>ne,ref:()=>Xn});function Cn(n){return {$:n}}var Xn=Cn;function bn(n,e){return e===void 0?{$fn:n}:{$fn:n,args:e}}var Zn=bn;function Pn(n,e,i){return i===void 0?{$if:n,then:e}:{$if:n,then:e,else:i}}function $n(...n){return {$pipe:n}}var ne=$n;function An(n,e,i){return i===void 0?{left:n,op:e}:{left:n,op:e,right:i}}var ee=An;function wn(n,e){return e===void 0||e.length===0?{$arrow:n}:{$arrow:n,args:e}}var te=wn;function Sn(n,e=[]){return {$fn:n,args:e}}var ie=Sn;function H(n,e="root",i={}){let r=[];return k(n,e,r,i),{valid:r.length===0,errors:r}}function k(n,e,i,r){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let t=0;t<n.length;t++)k(n[t],`${e}[${t}]`,i,r);return}if(y(n)){(!n.$||typeof n.$!="string")&&i.push(`${e}: invalid reference, $ must be non-empty string`);return}if(T(n)){typeof n.$if=="string"?(n.$if.startsWith("!")?n.$if.slice(1):n.$if)||i.push(`${e}.$if: empty path in string shorthand`):k(n.$if,`${e}.$if`,i,r),k(n.then,`${e}.then`,i,r),n.else!==void 0&&k(n.else,`${e}.else`,i,r);return}if(b(n)){if(!Array.isArray(n.$pipe)){i.push(`${e}.$pipe: must be an array`);return}if(n.$pipe.length===0){i.push(`${e}.$pipe: must have at least one element`);return}for(let t=0;t<n.$pipe.length;t++)k(n.$pipe[t],`${e}.$pipe[${t}]`,i,r);return}if(C(n)){if(!n.$fn||typeof n.$fn!="string"){i.push(`${e}: invalid function, $fn must be non-empty string`);return}if(r.scope&&!(n.$fn in r.scope)&&i.push(`${e}: function "${n.$fn}" not found in scope`),n.args!==void 0)if(!Array.isArray(n.args))i.push(`${e}.args: must be an array`);else for(let t=0;t<n.args.length;t++)k(n.args[t],`${e}.args[${t}]`,i,r);return}if($(n)){if(k(n.$arrow,`${e}.$arrow`,i,r),n.args!==void 0)if(!Array.isArray(n.args))i.push(`${e}.args: must be an array of strings`);else for(let t of n.args)(typeof t!="string"||!t)&&i.push(`${e}.args: each arg must be a non-empty string`);return}if(E(n)){_.has(n.op)||i.push(`${e}: invalid operator "${n.op}"`),k(n.left,`${e}.left`,i,r),n.right!==void 0&&k(n.right,`${e}.right`,i,r);return}if(h(n)){if(n.logic!=="AND"&&n.logic!=="OR"&&i.push(`${e}: invalid logic "${n.logic}", must be "AND" or "OR"`),!Array.isArray(n.conditions)){i.push(`${e}.conditions: must be an array`);return}for(let t=0;t<n.conditions.length;t++)k(n.conditions[t],`${e}.conditions[${t}]`,i,r);return}if(r.boundaries?.length){let t=n;for(let f of r.boundaries)if(f.check(t))return}let o=n,s=Object.keys(o);for(let t=0;t<s.length;t++){let f=s[t];k(o[f],`${e}.${f}`,i,r);}}function oe(n,e={}){let i=H(n,"root",e);if(!i.valid)throw new Error(`Invalid expression: ${i.errors.join("; ")}`)}function re(n,e={}){return H(n,"root",e).valid}var Ve="3.0.0";exports.ExpressionCompiler=Y;exports.VERSION=Ve;exports.assertValid=oe;exports.builders=kn;exports.compilePath=G;exports.extractDeps=R;exports.get=Dn;exports.hasDeps=In;exports.hasWildcard=X;exports.isArrow=$;exports.isCondition=E;exports.isConditionExpr=Rn;exports.isConditionGroup=h;exports.isConditional=T;exports.isFn=C;exports.isLiteral=J;exports.isPipe=b;exports.isPure=Bn;exports.isRef=y;exports.isValid=re;exports.normalizePath=W;exports.validate=H;
1
+ 'use strict';var omniAst=require('omni-ast');var be=Object.defineProperty;var Te=(e,n)=>{for(var t in n)be(e,t,{get:n[t],enumerable:true});};function j(e,n,t){let i=e;return Object.defineProperty(i,"deps",{value:n,enumerable:true,configurable:true}),Object.defineProperty(i,"hash",{value:t,enumerable:true,configurable:true}),i}var K=Symbol("$");function P(e){return e!==null&&typeof e=="object"&&e[K]===true}function y(e,n){if(e===null||typeof e!="object")return n.rawPrimitive(e);if(P(e))return Ae(e,n);if(Array.isArray(e)){let o=e.map(r=>y(r,n));return n.rawArray(e,o)}let t=e,i=Object.keys(t),s=new Array(i.length);for(let o=0;o<i.length;o++){let r=i[o];s[o]=[r,y(t[r],n)];}return n.rawObject(t,s)}function Ae(e,n){switch(e.t){case "d":return n.data(e);case "a":return n.arg(e);case "x":return n.accessor(e);case "c":{let t=e,i=t.a.map(s=>y(s,n));return n.call(t,i)}case "r":return n.ref(e);case "ch":{let t=e,i=t.a.map(s=>y(s,n));return n.callH(t,i)}case "rh":return n.refH(e);case "?":{let t=e;return n.cond(t,y(t.test,n),y(t.then,n),y(t.else,n))}case "|":{let t=e;return n.pipe(t,y(t.head,n),t.steps.map(i=>y(i,n)))}case "=>":{let t=e;return n.arrow(t,y(t.body,n))}case "!":{let t=e;return n.not(t,y(t.v,n))}case "cmp":{let t=e;return n.compare(t,y(t.l,n),y(t.r,n))}case "lg":{let t=e;return n.logic(t,t.c.map(i=>y(i,n)))}case "v":return n.literal(e);case "s":return n.static_(e);case "b":return n.boundary(e);default:throw new Error(`Unknown IR node type: ${e.t}`)}}function ne(e,n){return {data:()=>e,arg:()=>e,accessor:()=>e,call:()=>e,ref:()=>e,callH:()=>e,refH:()=>e,cond:()=>e,pipe:()=>e,arrow:()=>e,not:()=>e,compare:()=>e,logic:()=>e,literal:()=>e,static_:()=>e,boundary:()=>e,rawPrimitive:()=>e,rawObject:()=>e,rawArray:()=>e,...n}}var te=new Map;function S(e){let n=[],t=e.length,i=0,s="";for(;i<t;){let o=e[i];if(o===".")s&&(n.push({type:"key",value:s}),s=""),i++;else if(o==="["){s&&(n.push({type:"key",value:s}),s=""),i++;let r=i;for(;i<t&&e[i]!=="]";)i++;let a=e.slice(r,i);if(i++,a==="*")n.push({type:"wildcard",value:"*"});else {let l=parseInt(a,10);n.push({type:"index",value:isNaN(l)?a:l});}}else s+=o,i++;}return s&&n.push({type:"key",value:s}),n}function N(e){return e.includes("[*]")}function H(e){let n=te.get(e);return n||(n=N(e)?Ie(e):we(e),te.set(e,n),n)}function we(e){if(!e.includes(".")&&!e.includes("["))return s=>s?.[e];let n=S(e),t=n.length;if(t===2){let[s,o]=n,r=s.value,a=o.value;return l=>l?.[r]?.[a]}if(t===3){let[s,o,r]=n,a=s.value,l=o.value,c=r.value;return u=>u?.[a]?.[l]?.[c]}let i=n.map(s=>s.value);return s=>{let o=s;for(let r=0;r<t&&o!=null;r++)o=o[i[r]];return o}}function Ie(e){let n=S(e),t=[];for(let i=0;i<n.length;i++)n[i].type==="wildcard"&&t.push(i);return t.length===1?Ee(n,t[0]):$e(n,t)}function Ee(e,n){let t=e.slice(0,n).map(r=>r.value),i=e.slice(n+1).map(r=>r.value),s=t.length,o=i.length;if(o===0){if(s===1){let r=t[0];return a=>a?.[r]}return r=>{let a=r;for(let l=0;l<s&&a!=null;l++)a=a[t[l]];return a}}if(o===1){let r=i[0];if(s===1){let a=t[0];return l=>{let c=l?.[a];if(Array.isArray(c))return c.map(u=>u?.[r])}}return a=>{let l=a;for(let c=0;c<s&&l!=null;c++)l=l[t[c]];if(Array.isArray(l))return l.map(c=>c?.[r])}}return r=>{let a=r;for(let l=0;l<s&&a!=null;l++)a=a[t[l]];if(Array.isArray(a))return a.map(l=>{let c=l;for(let u=0;u<o&&c!=null;u++)c=c[i[u]];return c})}}function $e(e,n){let t=[],i=0;for(let o=0;o<n.length;o++){let r=n[o],a=o===n.length-1,l=e.slice(i,r).map(c=>c.value);l.length>0&&t.push({type:"access",keys:l}),t.push({type:a?"map":"flatMap",keys:[]}),i=r+1;}let s=e.slice(i).map(o=>o.value);return o=>{let r=o;for(let a of t){if(r==null)return;if(a.type==="access")for(let l of a.keys){if(r==null)return;r=r[l];}else if(a.type==="flatMap"){if(!Array.isArray(r))return;r=r.flatMap(l=>{let c=l;return Array.isArray(c)?c:[c]});}else if(a.type==="map"){if(!Array.isArray(r))return;s.length>0&&(r=r.map(l=>{let c=l;for(let u of s){if(c==null)return;c=c[u];}return c}));}}return r}}function Fe(e,n){return H(n)(e)}function A(e){let n=e.indexOf("[*]");return n===-1?e:e.slice(0,n)}function re(e){let{scope:n,accessor:t,handlers:i,boundaryFns:s}=e;return {data(o){return H(o.p)},arg(o){return H(o.p)},accessor(o){let r=t,a=o.p;return ()=>r(a)},call(o,r){let a=n[o.n];if(!a){let c=o.n;return ()=>{throw new Error(`Function not found in scope: ${c}`)}}let l=r.length;if(l===0)return ()=>a();if(l===1){let[c]=r;return u=>a(c(u))}if(l===2){let[c,u]=r;return f=>a(c(f),u(f))}if(l===3){let[c,u,f]=r;return d=>a(c(d),u(d),f(d))}return c=>a(...r.map(u=>u(c)))},ref(o){let r=n[o.n];if(!r){let a=o.n;return ()=>{throw new Error(`Function not found in scope: ${a}`)}}return ()=>r},callH(o,r){let a=i?.[o.ns]?.[o.m];if(!a)throw new Error(`Handler not found: ${o.ns}:${o.m}`);let l=r.length;if(l===0)return ()=>a();if(l===1){let[c]=r;return u=>a(c(u))}if(l===2){let[c,u]=r;return f=>a(c(f),u(f))}if(l===3){let[c,u,f]=r;return d=>a(c(d),u(d),f(d))}return c=>a(...r.map(u=>u(c)))},refH(o){let r=i?.[o.ns]?.[o.m];if(!r)throw new Error(`Handler not found: ${o.ns}:${o.m}`);return ()=>r},cond(o,r,a,l){return c=>r(c)?a(c):l(c)},pipe(o,r,a){let l=a.length;if(l===1){let[c]=a;return u=>{let f=r(u),d=c(u);return typeof d=="function"?d(f):d}}if(l===2){let[c,u]=a;return f=>{let d=r(f),m=c(f);return d=typeof m=="function"?m(d):m,m=u(f),typeof m=="function"?m(d):m}}if(l===3){let[c,u,f]=a;return d=>{let m=r(d),h=c(d);return m=typeof h=="function"?h(m):h,h=u(d),m=typeof h=="function"?h(m):h,h=f(d),typeof h=="function"?h(m):h}}return c=>{let u=r(c);for(let f=0;f<l;f++){let d=a[f](c);u=typeof d=="function"?d(u):d;}return u}},arrow(o,r){let a=o.params;if(a.length===0)return c=>()=>r(c);let l=a.length;return c=>(...u)=>{let f={...c};for(let d=0;d<l;d++)f[a[d]]=u[d];return r(f)}},not(o,r){return a=>!r(a)},compare(o,r,a){switch(o.op){case "eq":return l=>r(l)===a(l);case "neq":return l=>r(l)!==a(l);case "gt":return l=>r(l)>a(l);case "gte":return l=>r(l)>=a(l);case "lt":return l=>r(l)<a(l);case "lte":return l=>r(l)<=a(l);case "in":return l=>{let c=a(l);return Array.isArray(c)&&c.includes(r(l))};case "notIn":return l=>{let c=a(l);return !Array.isArray(c)||!c.includes(r(l))};case "contains":return l=>{let c=r(l);return Array.isArray(c)&&c.includes(a(l))};case "notContains":return l=>{let c=r(l);return !Array.isArray(c)||!c.includes(a(l))};case "exists":return l=>r(l)!==void 0;case "notExists":return l=>r(l)===void 0;case "matches":return l=>{let c=r(l),u=a(l);return typeof c!="string"||typeof u!="string"?false:new RegExp(u).test(c)};case "notMatches":return l=>{let c=r(l),u=a(l);return typeof c!="string"||typeof u!="string"?true:!new RegExp(u).test(c)};case "startsWith":return l=>{let c=r(l),u=a(l);return typeof c=="string"&&typeof u=="string"&&c.startsWith(u)};case "endsWith":return l=>{let c=r(l),u=a(l);return typeof c=="string"&&typeof u=="string"&&c.endsWith(u)};default:return l=>r(l)===a(l)}},logic(o,r){let a=r.length;if(a===0)return ()=>o.op==="AND";if(a===1)return l=>!!r[0](l);if(a===2){let[l,c]=r;return o.op==="AND"?u=>!!l(u)&&!!c(u):u=>!!l(u)||!!c(u)}if(a===3){let[l,c,u]=r;return o.op==="AND"?f=>!!l(f)&&!!c(f)&&!!u(f):f=>!!l(f)||!!c(f)||!!u(f)}return o.op==="AND"?l=>{for(let c=0;c<a;c++)if(!r[c](l))return false;return true}:l=>{for(let c=0;c<a;c++)if(r[c](l))return true;return false}},literal(o){let r=o.v;return ()=>r},static_(o){let r=o.v;return ()=>r},boundary(o){return s[o.i]},rawPrimitive(o){return ()=>o},rawObject(o,r){let a=r.length;return l=>{let c={};for(let u=0;u<a;u++)c[r[u][0]]=r[u][1](l);return c}},rawArray(o,r){return a=>r.map(l=>l(a))}}}function ie(e,n,t,i){return {deps:n,hash:i,bind:o=>{let r=re({scope:o?.scope??{},accessor:o?.accessor,handlers:o?.handlers,boundaryFns:t}),a=y(e,r);return j(a,n,i)}}}var Se="data",ke="accessor",Oe={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function q(e){let n=S(e);if(n.length===0)return omniAst.builders.identifier("undefined");let t=n[0],i=omniAst.builders.identifier(t.value);for(let s=1;s<n.length;s++){let o=n[s];o.type==="key"?i=omniAst.builders.memberExpression(i,omniAst.builders.identifier(o.value),false,true):i=omniAst.builders.memberExpression(i,omniAst.builders.literal(o.value),true,true);}return i}function De(e){let n=e.indexOf("[*]"),t=e.slice(0,n),i=e.slice(n+3),s;if(t)s=q(t);else return omniAst.builders.identifier("undefined");if(!i||i==="")return s;if(i.includes("[*]"))return oe(s,i);let o="_i",r=i.startsWith(".")?i.slice(1):i,a=omniAst.builders.identifier(o);if(r){let l=S(r);for(let c of l)c.type==="key"?a=omniAst.builders.memberExpression(a,omniAst.builders.identifier(c.value),false,true):a=omniAst.builders.memberExpression(a,omniAst.builders.literal(c.value),true,true);}return omniAst.builders.callExpression(omniAst.builders.memberExpression(s,omniAst.builders.identifier("map"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(o)],a)])}function oe(e,n){let t=n.indexOf("[*]"),i=n.slice(0,t),s=n.slice(t+3),o="_i",r=i.startsWith(".")?i.slice(1):i,a=omniAst.builders.identifier(o);if(r){let c=S(r);for(let u of c)u.type==="key"&&(a=omniAst.builders.memberExpression(a,omniAst.builders.identifier(u.value),false,true));}if(s.includes("[*]")){let c=oe(a,s);return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(o)],c)])}let l=s.startsWith(".")?s.slice(1):s;if(l){let c=S(l);for(let u of c)u.type==="key"&&(a=omniAst.builders.memberExpression(a,omniAst.builders.identifier(u.value),false,true));}return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(o)],a)])}function z(e){if(e===void 0)return omniAst.builders.identifier("undefined");if(e===null)return omniAst.builders.literal(null);if(typeof e!="object")return omniAst.builders.literal(e);if(Array.isArray(e))return omniAst.builders.arrayExpression(e.map(z));let t=Object.entries(e).map(([i,s])=>omniAst.builders.property(omniAst.builders.identifier(i),z(s)));return omniAst.builders.objectExpression(t)}function se(){return {data(e){return e.w?De(e.p):q(e.p)},arg(e){return q(e.p)},accessor(e){return omniAst.builders.callExpression(omniAst.builders.identifier(ke),[omniAst.builders.literal(e.p)])},call(e,n){let t=omniAst.builders.identifier(e.n);return omniAst.builders.callExpression(t,n)},ref(e){return omniAst.builders.identifier(e.n)},callH(e,n){return omniAst.builders.callExpression(omniAst.builders.identifier(`h_${e.ns}_${e.m}`),n)},refH(e){return omniAst.builders.identifier(`h_${e.ns}_${e.m}`)},cond(e,n,t,i){return omniAst.builders.conditionalExpression(n,t,i)},pipe(e,n,t){let i=n;for(let s of t)i=omniAst.builders.callExpression(s,[i]);return i},arrow(e,n){let t=e.params.map(i=>omniAst.builders.identifier(i));return omniAst.builders.arrowFunctionExpression(t,n)},not(e,n){return omniAst.builders.unaryExpression("!",n)},compare(e,n,t){let i=Oe[e.op];if(i)return omniAst.builders.binaryExpression(i,n,t);switch(e.op){case "in":return omniAst.builders.callExpression(omniAst.builders.memberExpression(t,omniAst.builders.identifier("includes")),[n]);case "notIn":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(t,omniAst.builders.identifier("includes")),[n]));case "contains":return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("includes"),false,true),[t]);case "notContains":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("includes"),false,true),[t]));case "exists":return omniAst.builders.binaryExpression("!=",n,omniAst.builders.literal(null));case "notExists":return omniAst.builders.binaryExpression("==",n,omniAst.builders.literal(null));case "matches":return omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[t]),omniAst.builders.identifier("test")),[n]);case "notMatches":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[t]),omniAst.builders.identifier("test")),[n]));case "startsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("startsWith"),false,true),[t]);case "endsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("endsWith"),false,true),[t]);default:return omniAst.builders.binaryExpression("===",n,t)}},logic(e,n){let t=e.op==="AND"?"&&":"||";if(n.length===0)return omniAst.builders.literal(e.op==="AND");if(n.length===1)return n[0];let i=n[0];for(let s=1;s<n.length;s++)i=omniAst.builders.logicalExpression(t,i,n[s]);return i},literal(e){return z(e.v)},static_(e){return z(e.v)},boundary(e){return omniAst.builders.callExpression(omniAst.builders.identifier(`b${e.i}`),[omniAst.builders.identifier(Se)])},rawPrimitive(e){return e===void 0?omniAst.builders.identifier("undefined"):e===null?omniAst.builders.literal(null):omniAst.builders.literal(e)},rawObject(e,n){let t=n.map(([i,s])=>omniAst.builders.property(omniAst.builders.identifier(i),s));return omniAst.builders.objectExpression(t)},rawArray(e,n){return omniAst.builders.arrayExpression(n)}}}function je(e){let n=e.indexOf("."),t=e.indexOf("["),i=e.length;return n!==-1&&(i=Math.min(i,n)),t!==-1&&(i=Math.min(i,t)),e.slice(0,i)}function ae(e,n){let t=new Set,i=new Set,s=new Set,o=false;return y(e,ne(void 0,{data(r){let a=je(r.p);a&&i.add(a);},accessor(){o=true;},call(r){t.add(r.n);},ref(r){t.add(r.n);},callH(r){s.add(`${r.ns}:${r.m}`);},refH(r){s.add(`${r.ns}:${r.m}`);}})),{scopeFns:t,dataRoots:i,hasAccessor:o,handlerRefs:s,boundaryCount:n}}function le(e){let n=[],t=[];for(let i of e.scopeFns)n.push({kind:"scope",name:i}),t.push(i);e.hasAccessor&&(n.push({kind:"accessor"}),t.push("accessor"));for(let i of e.handlerRefs){let[s,o]=i.split(":");n.push({kind:"handler",ns:s,m:o}),t.push(`h_${s}_${o}`);}for(let i=0;i<e.boundaryCount;i++)n.push({kind:"boundary",index:i}),t.push(`b${i}`);return {params:n,paramNames:t}}function ce(e,n,t){let i=omniAst.generate(e),s="";n.dataRoots.size>0&&(s=`const{${[...n.dataRoots].join(",")}}=data??{};`);let o=`${s}return ${i}`;return t.length>0?`(function(${t.join(",")}){return function(data){${o}}})`:`(function(){return function(data){${o}}})`}function Ne(e,n,t){let i=new Array(e.length);for(let s=0;s<e.length;s++){let o=e[s];switch(o.kind){case "scope":i[s]=n.scope?.[o.name];break;case "accessor":i[s]=n.accessor;break;case "handler":i[s]=n.handlers?.[o.ns]?.[o.m];break;case "boundary":i[s]=t[o.index];break}}return i}function U(e,n,t,i){let{hash:s,returnCode:o=false}=i,r=ae(e,t.length),a=y(e,se()),{params:l,paramNames:c}=le(r),u=ce(a,r,c);if(o)return {code:u,deps:n,hash:s,dataRoots:[...r.dataRoots],scopeFns:[...r.scopeFns],paramNames:c};let f;try{f=new Function(`return ${u}`)();}catch(m){throw new Error(`JIT compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${m instanceof Error?m.message:String(m)}`)}return {deps:n,hash:s,bind:m=>{let h=Ne(l,m??{},t),J=f(...h);return j(J,n,s)}}}var V=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),w=e=>e!==null&&typeof e=="object"&&"$"in e&&typeof e.$=="string"&&Object.keys(e).length===1,I=e=>e!==null&&typeof e=="object"&&"$if"in e&&"then"in e,E=e=>e!==null&&typeof e=="object"&&"$fn"in e&&typeof e.$fn=="string",$=e=>e!==null&&typeof e=="object"&&"$pipe"in e&&Array.isArray(e.$pipe),F=e=>e!==null&&typeof e=="object"&&"$arrow"in e,b=e=>e!==null&&typeof e=="object"&&"left"in e&&"op"in e&&V.has(e.op)&&!("$"in e)&&!("$if"in e)&&!("$fn"in e),T=e=>e!==null&&typeof e=="object"&&"logic"in e&&"conditions"in e,He=e=>b(e)||T(e),Be=e=>e!==null&&typeof e=="object"&&(w(e)||E(e)||I(e)||$(e)||F(e)||b(e)||T(e)),ze=e=>{if(e===null)return true;let n=typeof e;if(n==="string"||n==="number"||n==="boolean"||Array.isArray(e))return true;if(n==="object"&&e!==null){let t=e,i="left"in t&&"op"in t&&V.has(t.op);return !("$"in t)&&!("$if"in t)&&!("$fn"in t)&&!("$pipe"in t)&&!("$arrow"in t)&&!i&&!("logic"in t)}return false};function v(e,n){return _(e,n)}function _(e,n){if(e===null)return null;if(typeof e!="object")return e;if(Array.isArray(e))return e.map(o=>_(o,n));let t=e,i=Object.keys(t);for(let o of i)if(o in n){let r=n[o](t);if(typeof r=="object"&&r!==null&&o in r)throw new Error(`Transform "${o}" returned object with same key \u2014 infinite loop`);return _(r,n)}let s={};for(let o of i)s[o]=_(t[o],n);return s}function Ve(e){let n=e.indexOf("."),t=e.indexOf("["),i=e.length;return n!==-1&&(i=Math.min(i,n)),t!==-1&&(i=Math.min(i,t)),e.slice(0,i)}function g(e,n,t){return e[K]=true,t&&n&&(e.loc=n),e}function Q(e,n={}){let t=n.transforms?v(e,n.transforms):e,i=new Set,s=[],o=n.trackLocations===true;return {ir:C(t,n,new Set,i,s,o,o?"root":void 0),deps:Array.from(i),boundaryFns:s}}function C(e,n,t,i,s,o,r){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return Ue(e,n,t,i,s,o,r);let a=e;if(n.boundaries){for(let l of n.boundaries)if(l.check(a)){let c=l.handle(a),u=s.length;return s.push(c),g({t:"b",i:u},r,o)}}return w(e)?pe(e.$,n,t,i,o,r):I(e)?ve(e,n,t,i,s,o,r):$(e)?We(e,n,t,i,s,o,r):E(e)?Me(e,n,t,i,s,o,r):F(e)?Ge(e,n,t,i,s,o,r):b(e)?Je(e,n,t,i,s,o,r):T(e)?Ke(e,n,t,i,s,o,r):qe(a,n,t,i,s,o,r)}function _e(e,n){return n?e===n||e.startsWith(n+"."):false}function pe(e,n,t,i,s,o){let r=Ve(e);if(t.has(r))return g({t:"a",n:r,p:e},o,s);if(n.accessor){if(_e(e,n.lexicalPrefix)){i.add(A(e));let l={t:"d",p:e};return N(e)&&(l.w=true),g(l,o,s)}return i.add(A(e)),g({t:"x",p:e},o,s)}i.add(A(e));let a={t:"d",p:e};return N(e)&&(a.w=true),g(a,o,s)}function ve(e,n,t,i,s,o,r){let a;if(typeof e.$if=="string"){let u=e.$if.startsWith("!"),f=u?e.$if.slice(1):e.$if,d=pe(f,n,t,i,o,o?`${r}.$if`:void 0);a=u?g({t:"!",v:d},r,o):d;}else a=C(e.$if,n,t,i,s,o,o?`${r}.$if`:void 0);let l=C(e.then,n,t,i,s,o,o?`${r}.then`:void 0),c=e.else!==void 0?C(e.else,n,t,i,s,o,o?`${r}.else`:void 0):void 0;return g({t:"?",test:a,then:l,else:c},r,o)}function We(e,n,t,i,s,o,r){let a=e.$pipe;if(a.length===0)return;if(a.length===1)return C(a[0],n,t,i,s,o,o?`${r}.$pipe[0]`:void 0);let l=C(a[0],n,t,i,s,o,o?`${r}.$pipe[0]`:void 0),c=[];for(let u=1;u<a.length;u++)c.push(C(a[u],n,t,i,s,o,o?`${r}.$pipe[${u}]`:void 0));return g({t:"|",head:l,steps:c},r,o)}function Me(e,n,t,i,s,o,r){let a=e.$fn,l=a.indexOf(":"),c=e.args!==void 0;if(l!==-1){let f=a.slice(0,l),d=a.slice(l+1);if(!c)return g({t:"rh",ns:f,m:d},r,o);let m=e.args.map((h,J)=>C(h,n,t,i,s,o,o?`${r}.$fn.args[${J}]`:void 0));return g({t:"ch",ns:f,m:d,a:m},r,o)}if(!c)return g({t:"r",n:a},r,o);let u=e.args.map((f,d)=>C(f,n,t,i,s,o,o?`${r}.$fn.args[${d}]`:void 0));return g({t:"c",n:a,a:u},r,o)}function Ge(e,n,t,i,s,o,r){let a=e.args??[],l;if(a.length===0)l=t;else {l=new Set(t);for(let u of a)l.add(u);}let c=C(e.$arrow,n,l,i,s,o,o?`${r}.$arrow`:void 0);return g({t:"=>",params:a,body:c},r,o)}function Je(e,n,t,i,s,o,r){let a=C(e.left,n,t,i,s,o,o?`${r}.left`:void 0),l=e.right!==void 0?C(e.right,n,t,i,s,o,o?`${r}.right`:void 0):void 0;return g({t:"cmp",op:e.op,l:a,r:l},r,o)}function Ke(e,n,t,i,s,o,r){let a=e.conditions.map((l,c)=>C(l,n,t,i,s,o,o?`${r}.conditions[${c}]`:void 0));return g({t:"lg",op:e.logic,c:a},r,o)}function qe(e,n,t,i,s,o,r){let a=Object.keys(e);if(a.length===0)return g({t:"s",v:e},r,o);let l=false,c={};for(let u of a){let f=C(e[u],n,t,i,s,o,o?`${r}.${u}`:void 0);c[u]=f,l||(l=ue(f));}return l?c:g({t:"s",v:e},r,o)}function Ue(e,n,t,i,s,o,r){if(e.length===0)return g({t:"s",v:e},r,o);let a=false,l=[];for(let c=0;c<e.length;c++){let u=C(e[c],n,t,i,s,o,o?`${r}[${c}]`:void 0);l[c]=u,a||(a=ue(u));}return a?l:g({t:"s",v:e},r,o)}function ue(e){return e===null||typeof e!="object"?false:P(e)?true:Y(e)}function Y(e){if(P(e))return true;if(Array.isArray(e)){for(let n=0;n<e.length;n++)if(Y(e[n]))return true;return false}if(typeof e=="object"&&e!==null){let n=Object.keys(e);for(let t=0;t<n.length;t++)if(Y(e[n[t]]))return true}return false}function B(e){let n=new Set;return R(e,n),Array.from(n)}function R(e,n){if(e===null||typeof e!="object")return;if(Array.isArray(e)){for(let s=0;s<e.length;s++)R(e[s],n);return}if(w(e)){n.add(A(e.$));return}if(I(e)){if(typeof e.$if=="string"){let s=e.$if.startsWith("!")?e.$if.slice(1):e.$if;n.add(A(s));}else R(e.$if,n);R(e.then,n),e.else!==void 0&&R(e.else,n);return}if($(e)){for(let s=0;s<e.$pipe.length;s++)R(e.$pipe[s],n);return}if(E(e)){if(e.args)for(let s=0;s<e.args.length;s++)R(e.args[s],n);return}if(F(e)){let s=new Set;R(e.$arrow,s);let o=new Set(e.args??[]);for(let r of s){let a=r.split(".")[0].split("[")[0];o.has(a)||n.add(r);}return}if(b(e)){R(e.left,n),e.right!==void 0&&R(e.right,n);return}if(T(e)){for(let s=0;s<e.conditions.length;s++)R(e.conditions[s],n);return}let t=e,i=Object.keys(t);for(let s=0;s<i.length;s++)R(t[i[s]],n);}function Ye(e){return B(e).length>0}function Qe(e){return B(e).length===0}var k=class{constructor(n=1e3){this.cache=new Map,this._maxSize=n;}getOrCompile(n,t){let i=this.cache.get(n);if(i!==void 0)return this.cache.delete(n),this.cache.set(n,i),i;let s=t();if(this.cache.size>=this._maxSize){let o=this.cache.keys().next().value;o&&this.cache.delete(o);}return this.cache.set(n,s),s}has(n){return this.cache.has(n)}delete(n){return this.cache.delete(n)}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(n){for(this._maxSize=n;this.cache.size>this._maxSize;){let t=this.cache.keys().next().value;t&&this.cache.delete(t);}}},X=class{constructor(n=1e3){this.closures=new k(n),this.jit=new k(n);}getOrCompile(n,t,i){return (t==="closures"?this.closures:this.jit).getOrCompile(n,i)}get size(){return {closures:this.closures.size,jit:this.jit.size}}clear(){this.closures.clear(),this.jit.clear();}};function Z(e){return JSON.stringify(e)}var L=class{constructor(n={}){this.scope=n.scope??{},this.accessor=n.accessor,this.boundaries=n.boundaries,this.compileCache=n.compileCache,this.cacheClosures=new k(n.cacheSize??1e3),this.cacheJIT=new k(n.cacheSize??1e3),n.handlers&&(this.wrappedHandlers=this.wrapHandlers(n.handlers));}compile(n,t){let i=Z(n),s=t?.useAccessor??!!this.accessor,o=this.compileCacheKey(i,s);return this.cacheClosures.getOrCompile(o,()=>{let r=this.getArtifact(n,i,s,"closures"),a=this.defaultCtx(s);return {deps:r.deps,hash:r.hash,bind:l=>r.bind(l??a)}})}jit(n,t){let i=Z(n),s=t?.useAccessor??false,o=this.compileCacheKey(i,s,t?.lexicalPrefix);return this.cacheJIT.getOrCompile(o,()=>{let r=this.getArtifact(n,i,s,"jit",t?.lexicalPrefix),a=this.defaultCtx(s);return {deps:r.deps,hash:r.hash,bind:l=>r.bind(l??a)}})}jitCode(n,t){let s=t?.useAccessor??false?this.accessor??(()=>{}):void 0,{ir:o,deps:r,boundaryFns:a}=Q(n,{accessor:s,boundaries:this.boundaries,handlers:this.wrappedHandlers,lexicalPrefix:t?.lexicalPrefix});return U(o,r,a,{hash:JSON.stringify(n),returnCode:true})}eval(n,t,i){return i?.mode==="jit"?this.jit(n,{useAccessor:i?.useAccessor}).bind()(t):this.compile(n,{useAccessor:i?.useAccessor}).bind()(t)}wrapHandlers(n){let t={},i={};for(let s of Object.keys(n)){i[s]={};for(let o of Object.keys(n[s]))i[s][o]=n[s][o].bind(t);}return t.accessor=this.accessor,t.handlers=i,t.compiler=this,t.scope=this.scope,i}normalize(n,t){return v(n,t)}extractDeps(n){return B(n)}get cacheSize(){return {closures:this.cacheClosures.size,jit:this.cacheJIT.size}}clearCache(){this.cacheClosures.clear(),this.cacheJIT.clear();}getScope(){return this.scope}getArtifact(n,t,i,s,o){let r=this.compileCacheKey(t,i,o);return this.compileCache?this.compileCache.getOrCompile(r,s,()=>this.doCompile(n,i,s,o)):this.doCompile(n,i,s,o)}doCompile(n,t,i,s){let o=t?this.accessor??(()=>{}):void 0,{ir:r,deps:a,boundaryFns:l}=Q(n,{accessor:o,boundaries:this.boundaries,handlers:this.wrappedHandlers,lexicalPrefix:s}),c=JSON.stringify(n);return i==="jit"?U(r,a,l,{hash:c}):ie(r,a,l,c)}defaultCtx(n){return {scope:this.scope,accessor:n?this.accessor:void 0,handlers:this.wrappedHandlers}}compileCacheKey(n,t,i){return i?`${t?"a":"n"}:${i}:${n}`:t?`a:${n}`:n}};var Ce={};Te(Ce,{$:()=>fe,$arrow:()=>ge,$call:()=>he,$cond:()=>ye,$fn:()=>de,$if:()=>Le,$pipe:()=>me,arrow:()=>tn,call:()=>rn,cond:()=>nn,fn:()=>Ze,pipe:()=>en,ref:()=>Xe});function fe(e){return {$:e}}var Xe=fe;function de(e,n){return n===void 0?{$fn:e}:{$fn:e,args:n}}var Ze=de;function Le(e,n,t){return t===void 0?{$if:e,then:n}:{$if:e,then:n,else:t}}function me(...e){return {$pipe:e}}var en=me;function ye(e,n,t){return t===void 0?{left:e,op:n}:{left:e,op:n,right:t}}var nn=ye;function ge(e,n){return n===void 0||n.length===0?{$arrow:e}:{$arrow:e,args:n}}var tn=ge;function he(e,n=[]){return {$fn:e,args:n}}var rn=he;function ee(e,n="root",t={}){let i=[];return x(e,n,i,t),{valid:i.length===0,errors:i}}function x(e,n,t,i){if(e===null||typeof e!="object")return;if(Array.isArray(e)){for(let r=0;r<e.length;r++)x(e[r],`${n}[${r}]`,t,i);return}if(w(e)){(!e.$||typeof e.$!="string")&&t.push(`${n}: invalid reference, $ must be non-empty string`);return}if(I(e)){typeof e.$if=="string"?(e.$if.startsWith("!")?e.$if.slice(1):e.$if)||t.push(`${n}.$if: empty path in string shorthand`):x(e.$if,`${n}.$if`,t,i),x(e.then,`${n}.then`,t,i),e.else!==void 0&&x(e.else,`${n}.else`,t,i);return}if($(e)){if(!Array.isArray(e.$pipe)){t.push(`${n}.$pipe: must be an array`);return}if(e.$pipe.length===0){t.push(`${n}.$pipe: must have at least one element`);return}for(let r=0;r<e.$pipe.length;r++)x(e.$pipe[r],`${n}.$pipe[${r}]`,t,i);return}if(E(e)){if(!e.$fn||typeof e.$fn!="string"){t.push(`${n}: invalid function, $fn must be non-empty string`);return}let r=e.$fn.indexOf(":");if(r!==-1){let a=e.$fn.slice(0,r),l=e.$fn.slice(r+1);!a||!l||l.includes(":")?t.push(`${n}: invalid handler format "${e.$fn}", expected "namespace:method"`):i.handlers&&!i.handlers[a]?.[l]&&t.push(`${n}: handler "${e.$fn}" not found`);}else i.scope&&!(e.$fn in i.scope)&&t.push(`${n}: function "${e.$fn}" not found in scope`);if(e.args!==void 0)if(!Array.isArray(e.args))t.push(`${n}.args: must be an array`);else for(let a=0;a<e.args.length;a++)x(e.args[a],`${n}.args[${a}]`,t,i);return}if(F(e)){if(x(e.$arrow,`${n}.$arrow`,t,i),e.args!==void 0)if(!Array.isArray(e.args))t.push(`${n}.args: must be an array of strings`);else for(let r of e.args)(typeof r!="string"||!r)&&t.push(`${n}.args: each arg must be a non-empty string`);return}if(b(e)){V.has(e.op)||t.push(`${n}: invalid operator "${e.op}"`),x(e.left,`${n}.left`,t,i),e.right!==void 0&&x(e.right,`${n}.right`,t,i);return}if(T(e)){if(e.logic!=="AND"&&e.logic!=="OR"&&t.push(`${n}: invalid logic "${e.logic}", must be "AND" or "OR"`),!Array.isArray(e.conditions)){t.push(`${n}.conditions: must be an array`);return}for(let r=0;r<e.conditions.length;r++)x(e.conditions[r],`${n}.conditions[${r}]`,t,i);return}if(i.boundaries?.length){let r=e;for(let a of i.boundaries)if(a.check(r))return}let s=e,o=Object.keys(s);for(let r=0;r<o.length;r++){let a=o[r];x(s[a],`${n}.${a}`,t,i);}}function on(e,n={}){let t=ee(e,"root",n);if(!t.valid)throw new Error(`Invalid expression: ${t.errors.join("; ")}`)}function sn(e,n={}){return ee(e,"root",n).valid}function D(e){return "compile"in e}function O(e){return "type"in e&&!("compile"in e)}function Re(e){return typeof e.compile=="string"}function W(e){return typeof e.compile=="function"}function G(e,n){let t=[];for(let i of Object.keys(e))i in n||t.push({field:i,message:`Unknown field "${i}"`,type:"unknown_field"});for(let[i,s]of Object.entries(n)){let o=e[i],r=i in e&&o!==void 0;if(O(s)){if(s.required&&!r&&s.default===void 0){t.push({field:i,message:`Missing required field "${i}"`,type:"missing_required"});continue}if(r){let a=an(i,o,s);a&&t.push(a);}}}return {valid:t.length===0,errors:t}}function an(e,n,t){switch(t.type){case "string":if(typeof n!="string")return {field:e,message:`Field "${e}" expected string, got ${typeof n}`,type:"type_mismatch"};break;case "number":if(typeof n!="number")return {field:e,message:`Field "${e}" expected number, got ${typeof n}`,type:"type_mismatch"};break;case "boolean":if(typeof n!="boolean")return {field:e,message:`Field "${e}" expected boolean, got ${typeof n}`,type:"type_mismatch"};break;case "string[]":if(!Array.isArray(n)||!n.every(i=>typeof i=="string"))return {field:e,message:`Field "${e}" expected string[], got ${M(n)}`,type:"type_mismatch"};break;case "number[]":if(!Array.isArray(n)||!n.every(i=>typeof i=="number"))return {field:e,message:`Field "${e}" expected number[], got ${M(n)}`,type:"type_mismatch"};break;case "enum":if(!t.values||!t.values.includes(n))return {field:e,message:`Field "${e}" expected one of [${t.values?.join(", ")}], got "${String(n)}"`,type:"invalid_enum"};break;case "object":if(typeof n!="object"||n===null||Array.isArray(n))return {field:e,message:`Field "${e}" expected object, got ${M(n)}`,type:"type_mismatch"};break;case "schema":if(typeof n!="object"||n===null||Array.isArray(n))return {field:e,message:`Field "${e}" expected schema object, got ${M(n)}`,type:"type_mismatch"};break;}return null}function M(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function xe(e,n,t,i){if(i?.validate!==false){let l=G(e,n);if(!l.valid){let c=l.errors.map(u=>u.message).join("; ");throw new Error(`Template validation failed: ${c}`)}}let s=ln(e,n),o={},r={},a=new Set;for(let[l,c]of Object.entries(n)){let u=s[l];if(D(c)){if(u===void 0)continue;let f=cn(l,u,c,t,i);o[l]=f.value,f.artifact&&(r[l]=f.artifact),f.isCondition&&a.add(l);}else O(c)&&u!==void 0&&(o[l]=u);}return pn(o,r,a)}function ln(e,n){let t={...e};for(let[i,s]of Object.entries(n))O(s)&&!(i in t)&&s.default!==void 0&&(t[i]=s.default);return t}function cn(e,n,t,i,s){if(W(t)){let a={allow:t.allow,deny:t.deny,transforms:s?.transforms,mode:s?.mode};return {value:t.compile(n,i,a),artifact:null,isCondition:false}}let o=s?.mode??"closures";if(t.compile==="condition"){let l={$arrow:typeof n=="string"?{$if:n,then:true,else:false}:n},c=o==="jit"?i.jit(l,{useAccessor:true}):i.compile(l,{useAccessor:true});return {value:c.bind()({}),artifact:c,isCondition:true}}if(t.compile==="expression"){let a=o==="jit"?i.jit(n,{useAccessor:true}):i.compile(n,{useAccessor:true});return {value:a.bind(),artifact:a,isCondition:false}}let r=s?.handlers?.[t.compile];if(r){let a={allow:t.allow,deny:t.deny,transforms:s?.transforms,mode:s?.mode};return {value:r(n,i,a),artifact:null,isCondition:false}}throw new Error(`Unknown compile type: ${String(t.compile)}`)}function pn(e,n,t){let i={...e},s=o=>{let r={...e};for(let[a,l]of Object.entries(n)){let c=l.bind(o);r[a]=t.has(a)?c({}):c;}for(let[a,l]of Object.entries(e))a in n||l!=null&&typeof l.bind=="function"&&(r[a]=l.bind(o));return r.bind=s,r};return i.bind=s,i}var dt="3.0.0";exports.CompileCache=X;exports.ExpressionCompiler=L;exports.VERSION=dt;exports.assertValid=on;exports.builders=Ce;exports.compileDefinition=xe;exports.compilePath=H;exports.createBoundFn=j;exports.extractDeps=B;exports.get=Fe;exports.hasDeps=Ye;exports.hasWildcard=N;exports.isArrow=F;exports.isCompileField=D;exports.isCondition=b;exports.isConditionExpr=He;exports.isConditionGroup=T;exports.isConditional=I;exports.isExpression=Be;exports.isFn=E;exports.isHandlerCompile=W;exports.isLiteral=ze;exports.isNativeCompile=Re;exports.isPipe=$;exports.isPure=Qe;exports.isRef=w;exports.isSchemaField=O;exports.isValid=sn;exports.normalizePath=A;exports.validate=ee;exports.validateDefinition=G;