@statedelta-libs/expressions 2.2.0 → 2.3.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 +109 -20
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +37 -13
- package/dist/index.d.ts +37 -13
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
- **Alta performance** - ~25-30M ops/s após compilação
|
|
13
13
|
- **Scope externo** - Funções puras vêm via scope, não hardcoded
|
|
14
14
|
- **Context externo** - HOCs de continuidade via context (`tryCatch`, `transaction`, etc.)
|
|
15
|
+
- **RuntimeCtx unificado** - Contexto de runtime limpo com `{ data, get }`
|
|
15
16
|
- **Accessor customizado** - Suporte a `ctx.get(path)` para objetos especiais
|
|
16
17
|
- **$pipe** - Composição com valor inicial (sintaxe DSL)
|
|
17
18
|
- **$cb** - Callback expressions para HOCs de continuidade
|
|
@@ -323,23 +324,49 @@ HOC de continuidade - executa body dentro de um context function.
|
|
|
323
324
|
|
|
324
325
|
## Context
|
|
325
326
|
|
|
326
|
-
O context define HOCs disponíveis para `$cb`. Diferente de scope (funções puras), context functions controlam a execução do body
|
|
327
|
+
O context define HOCs disponíveis para `$cb`. Diferente de scope (funções puras), context functions controlam a execução do body.
|
|
328
|
+
|
|
329
|
+
### RuntimeCtx
|
|
330
|
+
|
|
331
|
+
O context recebe um `RuntimeCtx` unificado com `{ data, get }`:
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
interface RuntimeCtx<T> {
|
|
335
|
+
data: T; // Dados do runtime
|
|
336
|
+
get: (path: string) => unknown; // Accessor de paths
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### ContextFn
|
|
327
341
|
|
|
328
342
|
```typescript
|
|
329
|
-
|
|
343
|
+
type ContextFn<T, R> = (
|
|
344
|
+
cb: (ctx: RuntimeCtx<T>) => R, // Body compilado
|
|
345
|
+
ctx: RuntimeCtx<T>, // Contexto de runtime
|
|
346
|
+
params?: unknown // Parâmetros do $cb (opcional)
|
|
347
|
+
) => R;
|
|
348
|
+
```
|
|
330
349
|
|
|
331
|
-
|
|
350
|
+
### Exemplos
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import type { Context, ContextFn, RuntimeCtx } from '@statedelta-libs/expressions';
|
|
354
|
+
|
|
355
|
+
// tryCatch - captura erros
|
|
356
|
+
const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
332
357
|
try {
|
|
333
|
-
return cb(
|
|
358
|
+
return cb(ctx);
|
|
334
359
|
} catch {
|
|
335
|
-
return params?.fallback ?? null;
|
|
360
|
+
return (params as { fallback?: unknown })?.fallback ?? null;
|
|
336
361
|
}
|
|
337
362
|
};
|
|
338
363
|
|
|
339
|
-
|
|
364
|
+
// transaction - modifica data para o body
|
|
365
|
+
const transaction: ContextFn = (cb, ctx, params) => {
|
|
340
366
|
const tx = db.beginTransaction(params);
|
|
341
367
|
try {
|
|
342
|
-
|
|
368
|
+
// Cria novo ctx com tx no data
|
|
369
|
+
const result = cb({ ...ctx, data: { ...ctx.data, tx } });
|
|
343
370
|
tx.commit();
|
|
344
371
|
return result;
|
|
345
372
|
} catch (e) {
|
|
@@ -348,27 +375,40 @@ const transaction: ContextFn = (cb, data, get, params) => {
|
|
|
348
375
|
}
|
|
349
376
|
};
|
|
350
377
|
|
|
351
|
-
//
|
|
352
|
-
const cached: ContextFn = (cb,
|
|
353
|
-
|
|
354
|
-
|
|
378
|
+
// cached - pode ignorar o cb e retornar outro valor
|
|
379
|
+
const cached: ContextFn = (cb, ctx, params) => {
|
|
380
|
+
const key = (params as { key: string })?.key;
|
|
381
|
+
if (cache.has(key)) {
|
|
382
|
+
return cache.get(key); // Não executa cb
|
|
355
383
|
}
|
|
356
|
-
|
|
384
|
+
const result = cb(ctx);
|
|
385
|
+
cache.set(key, result);
|
|
386
|
+
return result;
|
|
357
387
|
};
|
|
358
388
|
|
|
359
|
-
|
|
389
|
+
// simulate - injeta accessor customizado
|
|
390
|
+
const simulate: ContextFn = (cb, ctx, params) => {
|
|
391
|
+
// Cria get que lê de store simulado
|
|
392
|
+
const simulatedGet = (path: string) => store.getSimulated(path);
|
|
393
|
+
// Body usa simulatedGet ao invés do get padrão
|
|
394
|
+
return cb({ ...ctx, get: simulatedGet });
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const context: Context = { tryCatch, transaction, cached, simulate };
|
|
360
398
|
|
|
361
399
|
compile(expression, { scope, context });
|
|
362
400
|
```
|
|
363
401
|
|
|
364
|
-
|
|
402
|
+
### O que o Context pode fazer
|
|
365
403
|
|
|
366
|
-
|
|
|
367
|
-
|
|
368
|
-
|
|
|
369
|
-
|
|
|
370
|
-
|
|
|
371
|
-
|
|
|
404
|
+
| Ação | Exemplo |
|
|
405
|
+
|------|---------|
|
|
406
|
+
| **Executar normalmente** | `return cb(ctx)` |
|
|
407
|
+
| **Modificar data** | `return cb({ ...ctx, data: { ...ctx.data, extra } })` |
|
|
408
|
+
| **Injetar accessor** | `return cb({ ...ctx, get: customGet })` |
|
|
409
|
+
| **Ignorar body** | `return cachedValue` (não chama cb) |
|
|
410
|
+
| **Capturar erros** | `try { cb(ctx) } catch { ... }` |
|
|
411
|
+
| **Usar ctx.get** | `const val = ctx.get("user.name")` |
|
|
372
412
|
|
|
373
413
|
## Scope
|
|
374
414
|
|
|
@@ -667,6 +707,7 @@ import type {
|
|
|
667
707
|
Scope,
|
|
668
708
|
Context,
|
|
669
709
|
ContextFn,
|
|
710
|
+
RuntimeCtx,
|
|
670
711
|
PathGetterFn,
|
|
671
712
|
CompileOptions,
|
|
672
713
|
AccessorFn,
|
|
@@ -779,6 +820,54 @@ Funções só são acessíveis se existirem no `scope` fornecido pelo desenvolve
|
|
|
779
820
|
|
|
780
821
|
8. **Novos tipos**: `BoundaryResolver`, `BoundaryResolvers`, `ResolverContext`, `ResolverResult`, `ResolveBoundariesOptions`, `ResolveBoundariesResult`, `IdGenerator`
|
|
781
822
|
|
|
823
|
+
### v2.0 → v2.1
|
|
824
|
+
|
|
825
|
+
1. **Nova API do ContextFn**: Agora usa `RuntimeCtx` unificado ao invés de parâmetros separados:
|
|
826
|
+
```typescript
|
|
827
|
+
// Antes (v2.0)
|
|
828
|
+
const tryCatch: ContextFn = (cb, data, get, params) => {
|
|
829
|
+
try {
|
|
830
|
+
return cb(data, get);
|
|
831
|
+
} catch {
|
|
832
|
+
return params?.fallback;
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
// Depois (v2.1)
|
|
837
|
+
const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
838
|
+
try {
|
|
839
|
+
return cb(ctx);
|
|
840
|
+
} catch {
|
|
841
|
+
return params?.fallback;
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
2. **RuntimeCtx**: Novo tipo que agrupa `data` e `get`:
|
|
847
|
+
```typescript
|
|
848
|
+
interface RuntimeCtx<T> {
|
|
849
|
+
data: T;
|
|
850
|
+
get: (path: string) => unknown;
|
|
851
|
+
}
|
|
852
|
+
```
|
|
853
|
+
|
|
854
|
+
3. **Injeção de accessor**: Context pode injetar `get` customizado:
|
|
855
|
+
```typescript
|
|
856
|
+
const simulate: ContextFn = (cb, ctx) => {
|
|
857
|
+
const customGet = (path) => store.getSimulated(path);
|
|
858
|
+
return cb({ ...ctx, get: customGet });
|
|
859
|
+
};
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
4. **Modificar data**: Agora via spread do ctx:
|
|
863
|
+
```typescript
|
|
864
|
+
// Antes
|
|
865
|
+
cb({ ...data, tx }, get)
|
|
866
|
+
|
|
867
|
+
// Depois
|
|
868
|
+
cb({ ...ctx, data: { ...ctx.data, tx } })
|
|
869
|
+
```
|
|
870
|
+
|
|
782
871
|
## Licença
|
|
783
872
|
|
|
784
873
|
MIT © Anderson D. Rosa
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var omniAst=require('omni-ast');var mn=Object.defineProperty;var En=(n,t)=>{for(var o in t)mn(n,o,{get:t[o],enumerable:true});};var E=n=>n!==null&&typeof n=="object"&&"$"in n&&typeof n.$=="string"&&Object.keys(n).length===1,S=n=>n!==null&&typeof n=="object"&&"$if"in n&&"then"in n,k=n=>n!==null&&typeof n=="object"&&"$fn"in n&&typeof n.$fn=="string",x=n=>n!==null&&typeof n=="object"&&"$pipe"in n&&Array.isArray(n.$pipe),R=n=>n!==null&&typeof n=="object"&&"$cb"in n&&typeof n.$cb=="string"&&"body"in n,G=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),h=n=>n!==null&&typeof n=="object"&&"left"in n&&"op"in n&&G.has(n.op)&&!("$"in n)&&!("$if"in n)&&!("$fn"in n),b=n=>n!==null&&typeof n=="object"&&"logic"in n&&"conditions"in n,hn=n=>h(n)||b(n),q=n=>{if(n===null)return true;let t=typeof n;if(t==="string"||t==="number"||t==="boolean"||Array.isArray(n))return true;if(t==="object"&&n!==null){let o=n,r="left"in o&&"op"in o&&G.has(o.op);return !("$"in o)&&!("$if"in o)&&!("$fn"in o)&&!("$pipe"in o)&&!("$cb"in o)&&!r&&!("logic"in o)}return false};var I=new Map;function Q(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let f=n.slice(e,r);if(r++,f==="*")t.push({type:"wildcard",value:"*"});else {let u=parseInt(f,10);t.push({type:"index",value:isNaN(u)?f:u});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function U(n){return n.includes("[*]")}function N(n){let t=I.get(n);return t||(t=U(n)?Cn(n):bn(n),I.set(n,t),t)}function bn(n){if(!n.includes(".")&&!n.includes("["))return i=>i?.[n];let t=Q(n),o=t.length;if(o===2){let[i,s]=t,e=i.value,f=s.value;return u=>u?.[e]?.[f]}if(o===3){let[i,s,e]=t,f=i.value,u=s.value,l=e.value;return a=>a?.[f]?.[u]?.[l]}let r=t.map(i=>i.value);return i=>{let s=i;for(let e=0;e<o&&s!=null;e++)s=s[r[e]];return s}}function Cn(n){let t=Q(n),o=[];for(let r=0;r<t.length;r++)t[r].type==="wildcard"&&o.push(r);return o.length===1?Tn(t,o[0]):$n(t,o)}function Tn(n,t){let o=n.slice(0,t).map(e=>e.value),r=n.slice(t+1).map(e=>e.value),i=o.length,s=r.length;if(s===0){if(i===1){let e=o[0];return f=>f?.[e]}return e=>{let f=e;for(let u=0;u<i&&f!=null;u++)f=f[o[u]];return f}}if(s===1){let e=r[0];if(i===1){let f=o[0];return u=>{let l=u?.[f];if(Array.isArray(l))return l.map(a=>a?.[e])}}return f=>{let u=f;for(let l=0;l<i&&u!=null;l++)u=u[o[l]];if(Array.isArray(u))return u.map(l=>l?.[e])}}return e=>{let f=e;for(let u=0;u<i&&f!=null;u++)f=f[o[u]];if(Array.isArray(f))return f.map(u=>{let l=u;for(let a=0;a<s&&l!=null;a++)l=l[r[a]];return l})}}function $n(n,t){let o=[],r=0;for(let s=0;s<t.length;s++){let e=t[s],f=s===t.length-1,u=n.slice(r,e).map(l=>l.value);u.length>0&&o.push({type:"access",keys:u}),o.push({type:f?"map":"flatMap",keys:[]}),r=e+1;}let i=n.slice(r).map(s=>s.value);return s=>{let e=s;for(let f of o){if(e==null)return;if(f.type==="access")for(let u of f.keys){if(e==null)return;e=e[u];}else if(f.type==="flatMap"){if(!Array.isArray(e))return;e=e.flatMap(u=>{let l=u;return Array.isArray(l)?l:[l]});}else if(f.type==="map"){if(!Array.isArray(e))return;i.length>0&&(e=e.map(u=>{let l=u;for(let a of i){if(l==null)return;l=l[a];}return l}));}}return e}}function An(n,t){return N(t)(n)}function W(n){let t=n.indexOf("[*]");return t===-1?n:n.slice(0,t)}function Sn(){I.clear();}function kn(){return I.size}function F(n){let t=new Set;return C(n,t),Array.from(t)}function C(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let i=0;i<n.length;i++)C(n[i],t);return}if(E(n)){t.add(W(n.$));return}if(S(n)){if(typeof n.$if=="string"){let i=n.$if.startsWith("!")?n.$if.slice(1):n.$if;t.add(W(i));}else C(n.$if,t);C(n.then,t),n.else!==void 0&&C(n.else,t);return}if(x(n)){for(let i=0;i<n.$pipe.length;i++)C(n.$pipe[i],t);return}if(k(n)){if(n.args)for(let i=0;i<n.args.length;i++)C(n.args[i],t);return}if(R(n)){C(n.body,t),n.params!==void 0&&C(n.params,t);return}if(h(n)){C(n.left,t),n.right!==void 0&&C(n.right,t);return}if(b(n)){for(let i=0;i<n.conditions.length;i++)C(n.conditions[i],t);return}let o=n,r=Object.keys(o);for(let i=0;i<r.length;i++)C(o[r[i]],t);}function xn(n){return F(n).length>0}function Rn(n){return F(n).length===0}function wn(n){return JSON.stringify(n)}function j(n,t={}){let o=t.scope??{},r=t.accessor,i=t.context??{},s=m(n,o,r,i),e=F(n),f=wn(n);return {fn:s,deps:e,hash:f}}function m(n,t,o,r){if(n===null)return ()=>null;if(typeof n!="object")return ()=>n;if(Array.isArray(n)){let i=n.map(s=>m(s,t,o,r));return s=>i.map(e=>e(s))}if(E(n))return Fn(n,o);if(S(n))return On(n,t,o,r);if(x(n))return vn(n,t,o,r);if(k(n))return jn(n,t,o,r);if(R(n))return Nn(n,t,o,r);if(h(n))return Gn(n,t,o,r);if(b(n))return In(n,t,o,r);if(q(n)){let i=n,s=Object.keys(i),e=s.map(f=>m(i[f],t,o,r));return f=>{let u={};for(let l=0;l<s.length;l++)u[s[l]]=e[l](f);return u}}return ()=>n}function Z(n,t){return t?o=>t(n,o):N(n)}function Fn(n,t){return Z(n.$,t)}function On(n,t,o,r){let i;if(typeof n.$if=="string"){let f=n.$if.startsWith("!")?n.$if.slice(1):n.$if,u=Z(f,o);i=n.$if.startsWith("!")?a=>!u(a):a=>!!u(a);}else {let f=m(n.$if,t,o,r);i=u=>!!f(u);}let s=m(n.then,t,o,r),e=n.else!==void 0?m(n.else,t,o,r):()=>{};return f=>i(f)?s(f):e(f)}function vn(n,t,o,r){let i=n.$pipe;if(i.length===0)return ()=>{};if(i.length===1)return m(i[0],t,o,r);let s=m(i[0],t,o,r),e=i.slice(1).map(u=>m(u,t,o,r)),f=e.length;if(f===1){let[u]=e;return l=>{let a=s(l),p=u(l);return typeof p=="function"?p(a):p}}if(f===2){let[u,l]=e;return a=>{let p=s(a),d=u(a);return p=typeof d=="function"?d(p):d,d=l(a),typeof d=="function"?d(p):d}}if(f===3){let[u,l,a]=e;return p=>{let d=s(p),g=u(p);return d=typeof g=="function"?g(d):g,g=l(p),d=typeof g=="function"?g(d):g,g=a(p),typeof g=="function"?g(d):g}}return u=>{let l=s(u);for(let a=0;a<f;a++){let p=e[a](u);l=typeof p=="function"?p(l):p;}return l}}function jn(n,t,o,r){let i=n.$fn,s=n.args;if(s===void 0)return ()=>{let u=t[i];if(!u)throw new Error(`Function not found in scope: ${i}`);return u};let e=s.map(u=>m(u,t,o,r)),f=e.length;if(f===0)return ()=>{let u=t[i];if(!u)throw new Error(`Function not found in scope: ${i}`);return u()};if(f===1){let[u]=e;return l=>{let a=t[i];if(!a)throw new Error(`Function not found in scope: ${i}`);return a(u(l))}}if(f===2){let[u,l]=e;return a=>{let p=t[i];if(!p)throw new Error(`Function not found in scope: ${i}`);return p(u(a),l(a))}}if(f===3){let[u,l,a]=e;return p=>{let d=t[i];if(!d)throw new Error(`Function not found in scope: ${i}`);return d(u(p),l(p),a(p))}}return u=>{let l=t[i];if(!l)throw new Error(`Function not found in scope: ${i}`);return l(...e.map(a=>a(u)))}}function Nn(n,t,o,r){let i=n.$cb,s=m(n.body,t,o,r),e=n.params?m(n.params,t,o,r):void 0,f=u=>o?l=>o(l,u):l=>N(l)(u);return u=>{let l=r?.[i];if(!l)throw new Error(`Context function not found: ${i}`);let a=(g,w)=>s(g),p=f(u),d=e?e(u):void 0;return l(a,u,p,d)}}function Gn(n,t,o,r){let i=m(n.left,t,o,r),s=n.right!==void 0?m(n.right,t,o,r):()=>{};switch(n.op){case "eq":return e=>i(e)===s(e);case "neq":return e=>i(e)!==s(e);case "gt":return e=>i(e)>s(e);case "gte":return e=>i(e)>=s(e);case "lt":return e=>i(e)<s(e);case "lte":return e=>i(e)<=s(e);case "in":return e=>{let f=s(e);return Array.isArray(f)&&f.includes(i(e))};case "notIn":return e=>{let f=s(e);return !Array.isArray(f)||!f.includes(i(e))};case "contains":return e=>{let f=i(e);return Array.isArray(f)&&f.includes(s(e))};case "notContains":return e=>{let f=i(e);return !Array.isArray(f)||!f.includes(s(e))};case "exists":return e=>i(e)!==void 0;case "notExists":return e=>i(e)===void 0;case "matches":return e=>{let f=i(e),u=s(e);return typeof f!="string"||typeof u!="string"?false:new RegExp(u).test(f)};case "notMatches":return e=>{let f=i(e),u=s(e);return typeof f!="string"||typeof u!="string"?true:!new RegExp(u).test(f)};case "startsWith":return e=>{let f=i(e),u=s(e);return typeof f=="string"&&typeof u=="string"&&f.startsWith(u)};case "endsWith":return e=>{let f=i(e),u=s(e);return typeof f=="string"&&typeof u=="string"&&f.endsWith(u)}}}function In(n,t,o,r){let i=n.conditions.map(e=>m(e,t,o,r)),s=i.length;if(s===1)return e=>!!i[0](e);if(s===2){let[e,f]=i;return n.logic==="AND"?u=>!!e(u)&&!!f(u):u=>!!e(u)||!!f(u)}if(s===3){let[e,f,u]=i;return n.logic==="AND"?l=>!!e(l)&&!!f(l)&&!!u(l):l=>!!e(l)||!!f(l)||!!u(l)}return n.logic==="AND"?e=>{for(let f=0;f<s;f++)if(!i[f](e))return false;return true}:e=>{for(let f=0;f<s;f++)if(i[f](e))return true;return false}}function Wn(n,t,o={}){return j(n,o).fn(t)}var z=class{constructor(t=1e3){this.cache=new Map,this._maxSize=t;}get(t,o={}){let r=JSON.stringify(t),i=this.cache.get(r);if(i)return this.cache.delete(r),this.cache.set(r,i),i;let s=j(t,o);if(this.cache.size>=this._maxSize){let e=this.cache.keys().next().value;e&&this.cache.delete(e);}return this.cache.set(r,s),s}has(t){return this.cache.has(JSON.stringify(t))}delete(t){return this.cache.delete(JSON.stringify(t))}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(t){for(this._maxSize=t;this.cache.size>this._maxSize;){let o=this.cache.keys().next().value;o&&this.cache.delete(o);}}},nn=new z;function zn(n,t={}){return nn.get(n,t)}function J(n,t="root",o={}){let r=[];return T(n,t,r,o),{valid:r.length===0,errors:r}}function T(n,t,o,r){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let e=0;e<n.length;e++)T(n[e],`${t}[${e}]`,o,r);return}if(E(n)){(!n.$||typeof n.$!="string")&&o.push(`${t}: invalid reference, $ must be non-empty string`);return}if(S(n)){typeof n.$if=="string"?(n.$if.startsWith("!")?n.$if.slice(1):n.$if)||o.push(`${t}.$if: empty path in string shorthand`):T(n.$if,`${t}.$if`,o,r),T(n.then,`${t}.then`,o,r),n.else!==void 0&&T(n.else,`${t}.else`,o,r);return}if(x(n)){if(!Array.isArray(n.$pipe)){o.push(`${t}.$pipe: must be an array`);return}if(n.$pipe.length===0){o.push(`${t}.$pipe: must have at least one element`);return}for(let e=0;e<n.$pipe.length;e++)T(n.$pipe[e],`${t}.$pipe[${e}]`,o,r);return}if(k(n)){if(!n.$fn||typeof n.$fn!="string"){o.push(`${t}: invalid function, $fn must be non-empty string`);return}if(r.scope&&!(n.$fn in r.scope)&&o.push(`${t}: function "${n.$fn}" not found in scope`),n.args!==void 0)if(!Array.isArray(n.args))o.push(`${t}.args: must be an array`);else for(let e=0;e<n.args.length;e++)T(n.args[e],`${t}.args[${e}]`,o,r);return}if(R(n)){if(!n.$cb||typeof n.$cb!="string"){o.push(`${t}: invalid callback, $cb must be non-empty string`);return}r.context&&!(n.$cb in r.context)&&o.push(`${t}: context function "${n.$cb}" not found`),T(n.body,`${t}.body`,o,r),n.params!==void 0&&T(n.params,`${t}.params`,o,r);return}if(h(n)){G.has(n.op)||o.push(`${t}: invalid operator "${n.op}"`),T(n.left,`${t}.left`,o,r),n.right!==void 0&&T(n.right,`${t}.right`,o,r);return}if(b(n)){if(n.logic!=="AND"&&n.logic!=="OR"&&o.push(`${t}: invalid logic "${n.logic}", must be "AND" or "OR"`),!Array.isArray(n.conditions)){o.push(`${t}.conditions: must be an array`);return}for(let e=0;e<n.conditions.length;e++)T(n.conditions[e],`${t}.conditions[${e}]`,o,r);return}let i=n,s=Object.keys(i);for(let e=0;e<s.length;e++){let f=s[e];T(i[f],`${t}.${f}`,o,r);}}function Dn(n,t={}){let o=J(n,"root",t);if(!o.valid)throw new Error(`Invalid expression: ${o.errors.join("; ")}`)}function Mn(n,t={}){return J(n,"root",t).valid}var un={};En(un,{$:()=>tn,$call:()=>fn,$cb:()=>sn,$cond:()=>rn,$fn:()=>en,$if:()=>Vn,$pipe:()=>on,call:()=>Kn,cb:()=>Jn,cond:()=>qn,fn:()=>_n,pipe:()=>Ln,ref:()=>Bn});function tn(n){return {$:n}}var Bn=tn;function en(n,t){return t===void 0||t.length===0?{$fn:n}:{$fn:n,args:t}}var _n=en;function Vn(n,t,o){return o===void 0?{$if:n,then:t}:{$if:n,then:t,else:o}}function on(...n){return {$pipe:n}}var Ln=on;function rn(n,t,o){return o===void 0?{left:n,op:t}:{left:n,op:t,right:o}}var qn=rn;function sn(n,t,o){return o===void 0?{$cb:n,body:t}:{$cb:n,body:t,params:o}}var Jn=sn;function fn(n,t=[]){return {$fn:n,args:t}}var Kn=fn;var K="data",ln="scope",Xn={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function M(n,t={}){let{dataParam:o=K,scopeParam:r=ln,noPrefixes:i=false,useAccessor:s=false,lexicalPrefix:e}=t;return y(n,o,r,i,s,e)}function y(n,t,o,r,i,s){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(e=>y(e,t,o,r,i,s)));if(E(n))return Yn(n.$,t,r,i,s);if(S(n))return Pn(n,t,o,r,i,s);if(x(n))return nt(n.$pipe,t,o,r,i,s);if(k(n))return Qn(n,t,o,r,i,s);if(R(n))return Zn(n,t,o,r,i,s);if(h(n))return tt(n,t,o,r,i,s);if(b(n))return et(n,t,o,r,i,s);if(typeof n=="object"){let f=Object.entries(n).map(([u,l])=>omniAst.builders.property(omniAst.builders.identifier(u),y(l,t,o,r,i,s)));return omniAst.builders.objectExpression(f)}return omniAst.builders.literal(null)}var X="accessor";function Y(n,t){return t?n===t||n.startsWith(t+"."):false}function Yn(n,t,o,r,i){return r?Y(n,i)?O(n,t,true):omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(n),omniAst.builders.identifier(t)]):n.includes("[*]")?Hn(n,t,o):O(n,t,o)}function O(n,t,o){let r=D(n);if(r.length===0)return o?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(t);let i;if(o){let s=r[0];i=omniAst.builders.identifier(s.value);for(let e=1;e<r.length;e++){let f=r[e];f.type==="key"?i=omniAst.builders.memberExpression(i,omniAst.builders.identifier(f.value),false,true):i=omniAst.builders.memberExpression(i,omniAst.builders.literal(f.value),true,true);}}else {i=omniAst.builders.identifier(t);for(let s of r)s.type==="key"?i=omniAst.builders.memberExpression(i,omniAst.builders.identifier(s.value),false,true):i=omniAst.builders.memberExpression(i,omniAst.builders.literal(s.value),true,true);}return i}function Hn(n,t,o){let r=n.indexOf("[*]"),i=n.slice(0,r),s=n.slice(r+3),e;if(i?e=O(i,t,o):e=o?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(t),!s||s==="")return e;if(s.includes("[*]"))return an(e,s);let f="_i",u=s.startsWith(".")?s.slice(1):s,l=omniAst.builders.identifier(f);if(u){let a=D(u);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(e,omniAst.builders.identifier("map"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(f)],l)])}function an(n,t){let o=t.indexOf("[*]"),r=t.slice(0,o),i=t.slice(o+3),s="_i",e=r.startsWith(".")?r.slice(1):r,f=omniAst.builders.identifier(s);if(e){let l=D(e);for(let a of l)a.type==="key"&&(f=omniAst.builders.memberExpression(f,omniAst.builders.identifier(a.value),false,true));}if(i.includes("[*]")){let l=an(f,i);return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(s)],l)])}let u=i.startsWith(".")?i.slice(1):i;if(u){let l=D(u);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 Pn(n,t,o,r,i,s){let e;if(typeof n.$if=="string"){let l=n.$if.startsWith("!"),a=l?n.$if.slice(1):n.$if,p;i?Y(a,s)?p=O(a,t,true):p=omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(a),omniAst.builders.identifier(t)]):p=O(a,t,r),e=l?omniAst.builders.unaryExpression("!",p):p;}else e=y(n.$if,t,o,r,i,s);let f=y(n.then,t,o,r,i,s),u=n.else!==void 0?y(n.else,t,o,r,i,s):omniAst.builders.identifier("undefined");return omniAst.builders.conditionalExpression(e,f,u)}function Qn(n,t,o,r,i,s){let e=r?omniAst.builders.identifier(n.$fn):omniAst.builders.memberExpression(omniAst.builders.identifier(o),omniAst.builders.identifier(n.$fn),false,false);if(n.args===void 0)return e;let f=n.args.map(u=>y(u,t,o,r,i,s));return omniAst.builders.callExpression(e,f)}var Un="context";function Zn(n,t,o,r,i,s){let e=r?omniAst.builders.identifier(n.$cb):omniAst.builders.memberExpression(omniAst.builders.identifier(Un),omniAst.builders.identifier(n.$cb),false,false),f=y(n.body,t,o,r,i,s),l=[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(t),omniAst.builders.identifier("get")],f),omniAst.builders.identifier(t),omniAst.builders.identifier("get")];if(n.params!==void 0){let a=y(n.params,t,o,r,i,s);l.push(a);}return omniAst.builders.callExpression(e,l)}function nt(n,t,o,r,i,s){if(n.length===0)return omniAst.builders.identifier("undefined");if(n.length===1)return y(n[0],t,o,r,i,s);let e=y(n[0],t,o,r,i,s);for(let f=1;f<n.length;f++){let u=y(n[f],t,o,r,i,s);e=omniAst.builders.callExpression(u,[e]);}return e}function cn(n,t,o,r,i,s){if(E(n)){let e=n.$;return i?Y(e,s)?O(e,t,true):omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(e),omniAst.builders.identifier(t)]):O(e,t,r)}return y(n,t,o,r,i,s)}function tt(n,t,o,r,i,s){let e=cn(n.left,t,o,r,i,s),f=n.right!==void 0?cn(n.right,t,o,r,i,s):omniAst.builders.literal(null),u=Xn[n.op];if(u)return omniAst.builders.binaryExpression(u,e,f);switch(n.op){case "in":return omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("includes")),[e]);case "notIn":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(f,omniAst.builders.identifier("includes")),[e]));case "contains":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("includes"),false,true),[f]);case "notContains":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("includes"),false,true),[f]));case "exists":return omniAst.builders.binaryExpression("!=",e,omniAst.builders.literal(null));case "notExists":return omniAst.builders.binaryExpression("==",e,omniAst.builders.literal(null));case "matches":return omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[f]),omniAst.builders.identifier("test")),[e]);case "notMatches":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[f]),omniAst.builders.identifier("test")),[e]));case "startsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("startsWith"),false,true),[f]);case "endsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("endsWith"),false,true),[f]);default:return omniAst.builders.binaryExpression("===",e,f)}}function et(n,t,o,r,i,s){let{logic:e,conditions:f}=n,u=e==="AND"?"&&":"||";if(f.length===0)return omniAst.builders.literal(e==="AND");if(f.length===1)return y(f[0],t,o,r,i,s);let l=y(f[0],t,o,r,i,s);for(let a=1;a<f.length;a++){let p=y(f[a],t,o,r,i,s);l=omniAst.builders.logicalExpression(u,l,p);}return l}function D(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let f=n.slice(e,r);if(r++,f!=="*"){let u=parseInt(f,10);t.push({type:"index",value:isNaN(u)?f:u});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function pn(n,t=[K]){return omniAst.builders.arrowFunctionExpression(t.map(o=>omniAst.builders.identifier(o)),n)}function B(n){let t=new Set;return $(n,t),t}function $(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)$(r,t);return}if(E(n))return;if(S(n)){$(n.$if,t),$(n.then,t),n.else!==void 0&&$(n.else,t);return}if(x(n)){for(let r of n.$pipe)$(r,t);return}if(k(n)){if(t.add(n.$fn),n.args)for(let r of n.args)$(r,t);return}if(R(n)){$(n.body,t),n.params!==void 0&&$(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&$(n.left,t),n.right!==void 0&&typeof n.right=="object"&&$(n.right,t);return}if(b(n)){for(let r of n.conditions)$(r,t);return}let o=n;for(let r of Object.keys(o))$(o[r],t);}function _(n){let t=new Set;return A(n,t),t}function A(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)A(r,t);return}if(E(n))return;if(S(n)){A(n.$if,t),A(n.then,t),n.else!==void 0&&A(n.else,t);return}if(x(n)){for(let r of n.$pipe)A(r,t);return}if(k(n)){if(n.args)for(let r of n.args)A(r,t);return}if(R(n)){t.add(n.$cb),A(n.body,t),n.params!==void 0&&A(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&A(n.left,t),n.right!==void 0&&typeof n.right=="object"&&A(n.right,t);return}if(b(n)){for(let r of n.conditions)A(r,t);return}let o=n;for(let r of Object.keys(o))A(o[r],t);}function V(n){let t=new Set;for(let o of n){let r=o.indexOf("."),i=o.indexOf("["),s=o.length;r!==-1&&(s=Math.min(s,r)),i!==-1&&(s=Math.min(s,i));let e=o.slice(0,s);e&&t.add(e);}return t}function ot(n){return JSON.stringify(n)}function rt(n,t,o,r,i,s){let e=M(n,{noPrefixes:true,useAccessor:i,lexicalPrefix:s}),f=omniAst.generate(e),u="";i?s&&(u=`const{${s}}=data??{};`):t.size>0&&(u=`const{${[...t].join(",")}}=data??{};`);let l=i?new Set([...o,"accessor"]):o,a=l.size>0?`const{${[...l].join(",")}}=scope;`:"",p=r.size>0?`const{${[...r].join(",")}}=context;`:"",d=r.size>0,g="";d&&(i?g="const get=(path)=>accessor(path,data);":g="const get=(path)=>path.split('.').reduce((o,k)=>o?.[k],data);");let w=l.size>0,v;if(w||d){let gn=d?"scope,context":"scope",yn=`${u}${g}return ${f}`;v=`(function(${gn}){${a}${p}return function(data){${yn}}})`;}else v=`(function(){return function(data){${u}return ${f}}})`;return v}function H(n,t={}){let{scope:o={},context:r={},returnCode:i=false,useAccessor:s=false,lexicalPrefix:e}=t,f=F(n),u=V(f),l=B(n),a=_(n),p=ot(n),d=rt(n,u,l,a,s,e);if(i)return {code:d,deps:f,hash:p,dataRoots:[...u],scopeFns:[...l],contextFns:[...a]};let g;try{let w=a.size>0,v=new Function(`return ${d}`)();g=w?v(o,r):v(o);}catch(w){throw new Error(`AST compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${w instanceof Error?w.message:String(w)}`)}return {fn:g,deps:f,hash:p}}function dn(n,t,o={}){let{fn:r}=H(n,o);return r(t)}function st(n,t){return L(n,t)}function L(n,t){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>L(s,t));let o=n,r=Object.keys(o);for(let s of r)if(s in t){let e=t[s](o);if(typeof e=="object"&&e!==null&&s in e)throw new Error(`Transform "${s}" returned object with same key \u2014 infinite loop`);return L(e,t)}let i={};for(let s of r)i[s]=L(o[s],t);return i}var ft=new Set(["$","$if","$fn","$pipe","$cb"]);function ut(){let n=0;return ()=>String(n++)}function ct(n,t){let{resolvers:o,scope:r={},genId:i,...s}=t,e=Object.keys(o);if(e.length===0)return {expr:n,scope:r};let f=new Set(e),u=[],l={compile:j,genId:i??ut(),scope:r,options:s},a=P(n,f,o,l,u),p={...r};for(let d=0;d<u.length;d++){let[g,w]=u[d];p[g]=w;}return {expr:a,scope:p}}function P(n,t,o,r,i){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n)){let l=n.length,a=new Array(l);for(let p=0;p<l;p++)a[p]=P(n[p],t,o,r,i);return a}let s=n,e=Object.keys(s),f=e.length;for(let l=0;l<f;l++){let a=e[l];if(a[0]==="$"&&!ft.has(a)&&t.has(a)){let p=o[a],d=p(s,r);return d.scopeEntry&&i.push(d.scopeEntry),d.expr}}let u={};for(let l=0;l<f;l++){let a=e[l];u[a]=P(s[a],t,o,r,i);}return u}var _t="2.0.0";exports.ExpressionCache=z;exports.VERSION=_t;exports.assertValid=Dn;exports.builders=un;exports.cache=nn;exports.cached=zn;exports.clearPathCache=Sn;exports.compile=j;exports.compileAST=H;exports.compilePath=N;exports.dslToAST=M;exports.evaluate=Wn;exports.evaluateAST=dn;exports.extractContextFns=_;exports.extractDataRoots=V;exports.extractDeps=F;exports.extractScopeFns=B;exports.get=An;exports.getPathCacheSize=kn;exports.hasDeps=xn;exports.hasWildcard=U;exports.isCb=R;exports.isCondition=h;exports.isConditionExpr=hn;exports.isConditionGroup=b;exports.isConditional=S;exports.isFn=k;exports.isLiteral=q;exports.isPipe=x;exports.isPure=Rn;exports.isRef=E;exports.isValid=Mn;exports.normalize=st;exports.normalizePath=W;exports.resolveBoundaries=ct;exports.validate=J;exports.wrapInFunction=pn;
|
|
1
|
+
'use strict';var omniAst=require('omni-ast');var yn=Object.defineProperty;var En=(n,t)=>{for(var o in t)yn(n,o,{get:t[o],enumerable:true});};var E=n=>n!==null&&typeof n=="object"&&"$"in n&&typeof n.$=="string"&&Object.keys(n).length===1,x=n=>n!==null&&typeof n=="object"&&"$if"in n&&"then"in n,S=n=>n!==null&&typeof n=="object"&&"$fn"in n&&typeof n.$fn=="string",R=n=>n!==null&&typeof n=="object"&&"$pipe"in n&&Array.isArray(n.$pipe),k=n=>n!==null&&typeof n=="object"&&"$cb"in n&&typeof n.$cb=="string"&&"body"in n,I=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),h=n=>n!==null&&typeof n=="object"&&"left"in n&&"op"in n&&I.has(n.op)&&!("$"in n)&&!("$if"in n)&&!("$fn"in n),b=n=>n!==null&&typeof n=="object"&&"logic"in n&&"conditions"in n,hn=n=>h(n)||b(n),J=n=>{if(n===null)return true;let t=typeof n;if(t==="string"||t==="number"||t==="boolean"||Array.isArray(n))return true;if(t==="object"&&n!==null){let o=n,r="left"in o&&"op"in o&&I.has(o.op);return !("$"in o)&&!("$if"in o)&&!("$fn"in o)&&!("$pipe"in o)&&!("$cb"in o)&&!r&&!("logic"in o)}return false};var W=new Map;function U(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let u=n.slice(e,r);if(r++,u==="*")t.push({type:"wildcard",value:"*"});else {let f=parseInt(u,10);t.push({type:"index",value:isNaN(f)?u:f});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function Z(n){return n.includes("[*]")}function j(n){let t=W.get(n);return t||(t=Z(n)?Cn(n):bn(n),W.set(n,t),t)}function bn(n){if(!n.includes(".")&&!n.includes("["))return i=>i?.[n];let t=U(n),o=t.length;if(o===2){let[i,s]=t,e=i.value,u=s.value;return f=>f?.[e]?.[u]}if(o===3){let[i,s,e]=t,u=i.value,f=s.value,l=e.value;return a=>a?.[u]?.[f]?.[l]}let r=t.map(i=>i.value);return i=>{let s=i;for(let e=0;e<o&&s!=null;e++)s=s[r[e]];return s}}function Cn(n){let t=U(n),o=[];for(let r=0;r<t.length;r++)t[r].type==="wildcard"&&o.push(r);return o.length===1?Tn(t,o[0]):$n(t,o)}function Tn(n,t){let o=n.slice(0,t).map(e=>e.value),r=n.slice(t+1).map(e=>e.value),i=o.length,s=r.length;if(s===0){if(i===1){let e=o[0];return u=>u?.[e]}return e=>{let u=e;for(let f=0;f<i&&u!=null;f++)u=u[o[f]];return u}}if(s===1){let e=r[0];if(i===1){let u=o[0];return f=>{let l=f?.[u];if(Array.isArray(l))return l.map(a=>a?.[e])}}return u=>{let f=u;for(let l=0;l<i&&f!=null;l++)f=f[o[l]];if(Array.isArray(f))return f.map(l=>l?.[e])}}return e=>{let u=e;for(let f=0;f<i&&u!=null;f++)u=u[o[f]];if(Array.isArray(u))return u.map(f=>{let l=f;for(let a=0;a<s&&l!=null;a++)l=l[r[a]];return l})}}function $n(n,t){let o=[],r=0;for(let s=0;s<t.length;s++){let e=t[s],u=s===t.length-1,f=n.slice(r,e).map(l=>l.value);f.length>0&&o.push({type:"access",keys:f}),o.push({type:u?"map":"flatMap",keys:[]}),r=e+1;}let i=n.slice(r).map(s=>s.value);return s=>{let e=s;for(let u of o){if(e==null)return;if(u.type==="access")for(let f of u.keys){if(e==null)return;e=e[f];}else if(u.type==="flatMap"){if(!Array.isArray(e))return;e=e.flatMap(f=>{let l=f;return Array.isArray(l)?l:[l]});}else if(u.type==="map"){if(!Array.isArray(e))return;i.length>0&&(e=e.map(f=>{let l=f;for(let a of i){if(l==null)return;l=l[a];}return l}));}}return e}}function An(n,t){return j(t)(n)}function z(n){let t=n.indexOf("[*]");return t===-1?n:n.slice(0,t)}function xn(){W.clear();}function Sn(){return W.size}function O(n){let t=new Set;return C(n,t),Array.from(t)}function C(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let i=0;i<n.length;i++)C(n[i],t);return}if(E(n)){t.add(z(n.$));return}if(x(n)){if(typeof n.$if=="string"){let i=n.$if.startsWith("!")?n.$if.slice(1):n.$if;t.add(z(i));}else C(n.$if,t);C(n.then,t),n.else!==void 0&&C(n.else,t);return}if(R(n)){for(let i=0;i<n.$pipe.length;i++)C(n.$pipe[i],t);return}if(S(n)){if(n.args)for(let i=0;i<n.args.length;i++)C(n.args[i],t);return}if(k(n)){C(n.body,t),n.params!==void 0&&C(n.params,t);return}if(h(n)){C(n.left,t),n.right!==void 0&&C(n.right,t);return}if(b(n)){for(let i=0;i<n.conditions.length;i++)C(n.conditions[i],t);return}let o=n,r=Object.keys(o);for(let i=0;i<r.length;i++)C(o[r[i]],t);}function Rn(n){return O(n).length>0}function kn(n){return O(n).length===0}function wn(n){return JSON.stringify(n)}function N(n,t={}){let o=t.scope??{},r=t.accessor,i=t.context??{},s=y(n,o,r,i),e=O(n),u=wn(n);return {fn:s,deps:e,hash:u}}function y(n,t,o,r){if(n===null)return ()=>null;if(typeof n!="object")return ()=>n;if(Array.isArray(n)){let i=n.map(s=>y(s,t,o,r));return s=>i.map(e=>e(s))}if(E(n))return Fn(n,o);if(x(n))return On(n,t,o,r);if(R(n))return vn(n,t,o,r);if(S(n))return jn(n,t,o,r);if(k(n))return Nn(n,t,o,r);if(h(n))return Gn(n,t,o,r);if(b(n))return In(n,t,o,r);if(J(n)){let i=n,s=Object.keys(i),e=s.map(u=>y(i[u],t,o,r));return u=>{let f={};for(let l=0;l<s.length;l++)f[s[l]]=e[l](u);return f}}return ()=>n}function nn(n,t){return t?o=>t(n,o):j(n)}function Fn(n,t){return nn(n.$,t)}function On(n,t,o,r){let i;if(typeof n.$if=="string"){let u=n.$if.startsWith("!")?n.$if.slice(1):n.$if,f=nn(u,o);i=n.$if.startsWith("!")?a=>!f(a):a=>!!f(a);}else {let u=y(n.$if,t,o,r);i=f=>!!u(f);}let s=y(n.then,t,o,r),e=n.else!==void 0?y(n.else,t,o,r):()=>{};return u=>i(u)?s(u):e(u)}function vn(n,t,o,r){let i=n.$pipe;if(i.length===0)return ()=>{};if(i.length===1)return y(i[0],t,o,r);let s=y(i[0],t,o,r),e=i.slice(1).map(f=>y(f,t,o,r)),u=e.length;if(u===1){let[f]=e;return l=>{let a=s(l),p=f(l);return typeof p=="function"?p(a):p}}if(u===2){let[f,l]=e;return a=>{let p=s(a),d=f(a);return p=typeof d=="function"?d(p):d,d=l(a),typeof d=="function"?d(p):d}}if(u===3){let[f,l,a]=e;return p=>{let d=s(p),g=f(p);return d=typeof g=="function"?g(d):g,g=l(p),d=typeof g=="function"?g(d):g,g=a(p),typeof g=="function"?g(d):g}}return f=>{let l=s(f);for(let a=0;a<u;a++){let p=e[a](f);l=typeof p=="function"?p(l):p;}return l}}function jn(n,t,o,r){let i=n.$fn,s=n.args;if(s===void 0)return ()=>{let f=t[i];if(!f)throw new Error(`Function not found in scope: ${i}`);return f};let e=s.map(f=>y(f,t,o,r)),u=e.length;if(u===0)return ()=>{let f=t[i];if(!f)throw new Error(`Function not found in scope: ${i}`);return f()};if(u===1){let[f]=e;return l=>{let a=t[i];if(!a)throw new Error(`Function not found in scope: ${i}`);return a(f(l))}}if(u===2){let[f,l]=e;return a=>{let p=t[i];if(!p)throw new Error(`Function not found in scope: ${i}`);return p(f(a),l(a))}}if(u===3){let[f,l,a]=e;return p=>{let d=t[i];if(!d)throw new Error(`Function not found in scope: ${i}`);return d(f(p),l(p),a(p))}}return f=>{let l=t[i];if(!l)throw new Error(`Function not found in scope: ${i}`);return l(...e.map(a=>a(f)))}}function Nn(n,t,o,r){let i=n.$cb,s,e=(a,p)=>s?s(a):o?o(a,p):j(a)(p),u=y(n.body,t,e,r),f=n.params?y(n.params,t,o,r):void 0,l=a=>o?p=>o(p,a):p=>j(p)(a);return a=>{let p=r?.[i];if(!p)throw new Error(`Context function not found: ${i}`);let d=l(a),g={data:a,get:d},w=G=>{G.get!==d&&(s=G.get);try{return u(G.data)}finally{s=void 0;}},F=f?f(a):void 0;return p(w,g,F)}}function Gn(n,t,o,r){let i=y(n.left,t,o,r),s=n.right!==void 0?y(n.right,t,o,r):()=>{};switch(n.op){case "eq":return e=>i(e)===s(e);case "neq":return e=>i(e)!==s(e);case "gt":return e=>i(e)>s(e);case "gte":return e=>i(e)>=s(e);case "lt":return e=>i(e)<s(e);case "lte":return e=>i(e)<=s(e);case "in":return e=>{let u=s(e);return Array.isArray(u)&&u.includes(i(e))};case "notIn":return e=>{let u=s(e);return !Array.isArray(u)||!u.includes(i(e))};case "contains":return e=>{let u=i(e);return Array.isArray(u)&&u.includes(s(e))};case "notContains":return e=>{let u=i(e);return !Array.isArray(u)||!u.includes(s(e))};case "exists":return e=>i(e)!==void 0;case "notExists":return e=>i(e)===void 0;case "matches":return e=>{let u=i(e),f=s(e);return typeof u!="string"||typeof f!="string"?false:new RegExp(f).test(u)};case "notMatches":return e=>{let u=i(e),f=s(e);return typeof u!="string"||typeof f!="string"?true:!new RegExp(f).test(u)};case "startsWith":return e=>{let u=i(e),f=s(e);return typeof u=="string"&&typeof f=="string"&&u.startsWith(f)};case "endsWith":return e=>{let u=i(e),f=s(e);return typeof u=="string"&&typeof f=="string"&&u.endsWith(f)}}}function In(n,t,o,r){let i=n.conditions.map(e=>y(e,t,o,r)),s=i.length;if(s===1)return e=>!!i[0](e);if(s===2){let[e,u]=i;return n.logic==="AND"?f=>!!e(f)&&!!u(f):f=>!!e(f)||!!u(f)}if(s===3){let[e,u,f]=i;return n.logic==="AND"?l=>!!e(l)&&!!u(l)&&!!f(l):l=>!!e(l)||!!u(l)||!!f(l)}return n.logic==="AND"?e=>{for(let u=0;u<s;u++)if(!i[u](e))return false;return true}:e=>{for(let u=0;u<s;u++)if(i[u](e))return true;return false}}function Wn(n,t,o={}){return N(n,o).fn(t)}var D=class{constructor(t=1e3){this.cache=new Map,this._maxSize=t;}get(t,o={}){let r=JSON.stringify(t),i=this.cache.get(r);if(i)return this.cache.delete(r),this.cache.set(r,i),i;let s=N(t,o);if(this.cache.size>=this._maxSize){let e=this.cache.keys().next().value;e&&this.cache.delete(e);}return this.cache.set(r,s),s}has(t){return this.cache.has(JSON.stringify(t))}delete(t){return this.cache.delete(JSON.stringify(t))}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(t){for(this._maxSize=t;this.cache.size>this._maxSize;){let o=this.cache.keys().next().value;o&&this.cache.delete(o);}}},tn=new D;function zn(n,t={}){return tn.get(n,t)}function K(n,t="root",o={}){let r=[];return T(n,t,r,o),{valid:r.length===0,errors:r}}function T(n,t,o,r){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let e=0;e<n.length;e++)T(n[e],`${t}[${e}]`,o,r);return}if(E(n)){(!n.$||typeof n.$!="string")&&o.push(`${t}: invalid reference, $ must be non-empty string`);return}if(x(n)){typeof n.$if=="string"?(n.$if.startsWith("!")?n.$if.slice(1):n.$if)||o.push(`${t}.$if: empty path in string shorthand`):T(n.$if,`${t}.$if`,o,r),T(n.then,`${t}.then`,o,r),n.else!==void 0&&T(n.else,`${t}.else`,o,r);return}if(R(n)){if(!Array.isArray(n.$pipe)){o.push(`${t}.$pipe: must be an array`);return}if(n.$pipe.length===0){o.push(`${t}.$pipe: must have at least one element`);return}for(let e=0;e<n.$pipe.length;e++)T(n.$pipe[e],`${t}.$pipe[${e}]`,o,r);return}if(S(n)){if(!n.$fn||typeof n.$fn!="string"){o.push(`${t}: invalid function, $fn must be non-empty string`);return}if(r.scope&&!(n.$fn in r.scope)&&o.push(`${t}: function "${n.$fn}" not found in scope`),n.args!==void 0)if(!Array.isArray(n.args))o.push(`${t}.args: must be an array`);else for(let e=0;e<n.args.length;e++)T(n.args[e],`${t}.args[${e}]`,o,r);return}if(k(n)){if(!n.$cb||typeof n.$cb!="string"){o.push(`${t}: invalid callback, $cb must be non-empty string`);return}r.context&&!(n.$cb in r.context)&&o.push(`${t}: context function "${n.$cb}" not found`),T(n.body,`${t}.body`,o,r),n.params!==void 0&&T(n.params,`${t}.params`,o,r);return}if(h(n)){I.has(n.op)||o.push(`${t}: invalid operator "${n.op}"`),T(n.left,`${t}.left`,o,r),n.right!==void 0&&T(n.right,`${t}.right`,o,r);return}if(b(n)){if(n.logic!=="AND"&&n.logic!=="OR"&&o.push(`${t}: invalid logic "${n.logic}", must be "AND" or "OR"`),!Array.isArray(n.conditions)){o.push(`${t}.conditions: must be an array`);return}for(let e=0;e<n.conditions.length;e++)T(n.conditions[e],`${t}.conditions[${e}]`,o,r);return}let i=n,s=Object.keys(i);for(let e=0;e<s.length;e++){let u=s[e];T(i[u],`${t}.${u}`,o,r);}}function Dn(n,t={}){let o=K(n,"root",t);if(!o.valid)throw new Error(`Invalid expression: ${o.errors.join("; ")}`)}function Mn(n,t={}){return K(n,"root",t).valid}var cn={};En(cn,{$:()=>en,$call:()=>fn,$cb:()=>un,$cond:()=>sn,$fn:()=>on,$if:()=>_n,$pipe:()=>rn,call:()=>Kn,cb:()=>Jn,cond:()=>qn,fn:()=>Vn,pipe:()=>Ln,ref:()=>Bn});function en(n){return {$:n}}var Bn=en;function on(n,t){return t===void 0||t.length===0?{$fn:n}:{$fn:n,args:t}}var Vn=on;function _n(n,t,o){return o===void 0?{$if:n,then:t}:{$if:n,then:t,else:o}}function rn(...n){return {$pipe:n}}var Ln=rn;function sn(n,t,o){return o===void 0?{left:n,op:t}:{left:n,op:t,right:o}}var qn=sn;function un(n,t,o){return o===void 0?{$cb:n,body:t}:{$cb:n,body:t,params:o}}var Jn=un;function fn(n,t=[]){return {$fn:n,args:t}}var Kn=fn;var P="data",an="scope",Pn={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function B(n,t={}){let{dataParam:o=P,scopeParam:r=an,noPrefixes:i=false,useAccessor:s=false,lexicalPrefix:e}=t;return m(n,o,r,i,s,e)}function m(n,t,o,r,i,s){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(e=>m(e,t,o,r,i,s)));if(E(n))return Xn(n.$,t,r,i,s);if(x(n))return Hn(n,t,o,r,i,s);if(R(n))return nt(n.$pipe,t,o,r,i,s);if(S(n))return Qn(n,t,o,r,i,s);if(k(n))return Zn(n,t,o,r,i,s);if(h(n))return tt(n,t,o,r,i,s);if(b(n))return et(n,t,o,r,i,s);if(typeof n=="object"){let u=Object.entries(n).map(([f,l])=>omniAst.builders.property(omniAst.builders.identifier(f),m(l,t,o,r,i,s)));return omniAst.builders.objectExpression(u)}return omniAst.builders.literal(null)}var X="accessor";function Y(n,t){return t?n===t||n.startsWith(t+"."):false}function Xn(n,t,o,r,i){return r?Y(n,i)?v(n,t,true):omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(n),omniAst.builders.identifier(t)]):n.includes("[*]")?Yn(n,t,o):v(n,t,o)}function v(n,t,o){let r=M(n);if(r.length===0)return o?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(t);let i;if(o){let s=r[0];i=omniAst.builders.identifier(s.value);for(let e=1;e<r.length;e++){let u=r[e];u.type==="key"?i=omniAst.builders.memberExpression(i,omniAst.builders.identifier(u.value),false,true):i=omniAst.builders.memberExpression(i,omniAst.builders.literal(u.value),true,true);}}else {i=omniAst.builders.identifier(t);for(let s of r)s.type==="key"?i=omniAst.builders.memberExpression(i,omniAst.builders.identifier(s.value),false,true):i=omniAst.builders.memberExpression(i,omniAst.builders.literal(s.value),true,true);}return i}function Yn(n,t,o){let r=n.indexOf("[*]"),i=n.slice(0,r),s=n.slice(r+3),e;if(i?e=v(i,t,o):e=o?omniAst.builders.identifier("undefined"):omniAst.builders.identifier(t),!s||s==="")return e;if(s.includes("[*]"))return pn(e,s);let u="_i",f=s.startsWith(".")?s.slice(1):s,l=omniAst.builders.identifier(u);if(f){let a=M(f);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(e,omniAst.builders.identifier("map"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(u)],l)])}function pn(n,t){let o=t.indexOf("[*]"),r=t.slice(0,o),i=t.slice(o+3),s="_i",e=r.startsWith(".")?r.slice(1):r,u=omniAst.builders.identifier(s);if(e){let l=M(e);for(let a of l)a.type==="key"&&(u=omniAst.builders.memberExpression(u,omniAst.builders.identifier(a.value),false,true));}if(i.includes("[*]")){let l=pn(u,i);return omniAst.builders.callExpression(omniAst.builders.memberExpression(n,omniAst.builders.identifier("flatMap"),false,true),[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier(s)],l)])}let f=i.startsWith(".")?i.slice(1):i;if(f){let l=M(f);for(let a of l)a.type==="key"&&(u=omniAst.builders.memberExpression(u,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)],u)])}function Hn(n,t,o,r,i,s){let e;if(typeof n.$if=="string"){let l=n.$if.startsWith("!"),a=l?n.$if.slice(1):n.$if,p;i?Y(a,s)?p=v(a,t,true):p=omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(a),omniAst.builders.identifier(t)]):p=v(a,t,r),e=l?omniAst.builders.unaryExpression("!",p):p;}else e=m(n.$if,t,o,r,i,s);let u=m(n.then,t,o,r,i,s),f=n.else!==void 0?m(n.else,t,o,r,i,s):omniAst.builders.identifier("undefined");return omniAst.builders.conditionalExpression(e,u,f)}function Qn(n,t,o,r,i,s){let e=r?omniAst.builders.identifier(n.$fn):omniAst.builders.memberExpression(omniAst.builders.identifier(o),omniAst.builders.identifier(n.$fn),false,false);if(n.args===void 0)return e;let u=n.args.map(f=>m(f,t,o,r,i,s));return omniAst.builders.callExpression(e,u)}var Un="context";function Zn(n,t,o,r,i,s){let e=r?omniAst.builders.identifier(n.$cb):omniAst.builders.memberExpression(omniAst.builders.identifier(Un),omniAst.builders.identifier(n.$cb),false,false),u=m(n.body,t,o,r,i,s),l=[omniAst.builders.arrowFunctionExpression([omniAst.builders.identifier("ctx")],u),omniAst.builders.identifier("ctx")];if(n.params!==void 0){let a=m(n.params,t,o,r,i,s);l.push(a);}return omniAst.builders.callExpression(e,l)}function nt(n,t,o,r,i,s){if(n.length===0)return omniAst.builders.identifier("undefined");if(n.length===1)return m(n[0],t,o,r,i,s);let e=m(n[0],t,o,r,i,s);for(let u=1;u<n.length;u++){let f=m(n[u],t,o,r,i,s);e=omniAst.builders.callExpression(f,[e]);}return e}function ln(n,t,o,r,i,s){if(E(n)){let e=n.$;return i?Y(e,s)?v(e,t,true):omniAst.builders.callExpression(omniAst.builders.identifier(X),[omniAst.builders.literal(e),omniAst.builders.identifier(t)]):v(e,t,r)}return m(n,t,o,r,i,s)}function tt(n,t,o,r,i,s){let e=ln(n.left,t,o,r,i,s),u=n.right!==void 0?ln(n.right,t,o,r,i,s):omniAst.builders.literal(null),f=Pn[n.op];if(f)return omniAst.builders.binaryExpression(f,e,u);switch(n.op){case "in":return omniAst.builders.callExpression(omniAst.builders.memberExpression(u,omniAst.builders.identifier("includes")),[e]);case "notIn":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(u,omniAst.builders.identifier("includes")),[e]));case "contains":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("includes"),false,true),[u]);case "notContains":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("includes"),false,true),[u]));case "exists":return omniAst.builders.binaryExpression("!=",e,omniAst.builders.literal(null));case "notExists":return omniAst.builders.binaryExpression("==",e,omniAst.builders.literal(null));case "matches":return omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[u]),omniAst.builders.identifier("test")),[e]);case "notMatches":return omniAst.builders.unaryExpression("!",omniAst.builders.callExpression(omniAst.builders.memberExpression(omniAst.builders.newExpression(omniAst.builders.identifier("RegExp"),[u]),omniAst.builders.identifier("test")),[e]));case "startsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("startsWith"),false,true),[u]);case "endsWith":return omniAst.builders.callExpression(omniAst.builders.memberExpression(e,omniAst.builders.identifier("endsWith"),false,true),[u]);default:return omniAst.builders.binaryExpression("===",e,u)}}function et(n,t,o,r,i,s){let{logic:e,conditions:u}=n,f=e==="AND"?"&&":"||";if(u.length===0)return omniAst.builders.literal(e==="AND");if(u.length===1)return m(u[0],t,o,r,i,s);let l=m(u[0],t,o,r,i,s);for(let a=1;a<u.length;a++){let p=m(u[a],t,o,r,i,s);l=omniAst.builders.logicalExpression(f,l,p);}return l}function M(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let u=n.slice(e,r);if(r++,u!=="*"){let f=parseInt(u,10);t.push({type:"index",value:isNaN(f)?u:f});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function dn(n,t=[P]){return omniAst.builders.arrowFunctionExpression(t.map(o=>omniAst.builders.identifier(o)),n)}function V(n){let t=new Set;return $(n,t),t}function $(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)$(r,t);return}if(E(n))return;if(x(n)){$(n.$if,t),$(n.then,t),n.else!==void 0&&$(n.else,t);return}if(R(n)){for(let r of n.$pipe)$(r,t);return}if(S(n)){if(t.add(n.$fn),n.args)for(let r of n.args)$(r,t);return}if(k(n)){$(n.body,t),n.params!==void 0&&$(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&$(n.left,t),n.right!==void 0&&typeof n.right=="object"&&$(n.right,t);return}if(b(n)){for(let r of n.conditions)$(r,t);return}let o=n;for(let r of Object.keys(o))$(o[r],t);}function _(n){let t=new Set;return A(n,t),t}function A(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)A(r,t);return}if(E(n))return;if(x(n)){A(n.$if,t),A(n.then,t),n.else!==void 0&&A(n.else,t);return}if(R(n)){for(let r of n.$pipe)A(r,t);return}if(S(n)){if(n.args)for(let r of n.args)A(r,t);return}if(k(n)){t.add(n.$cb),A(n.body,t),n.params!==void 0&&A(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&A(n.left,t),n.right!==void 0&&typeof n.right=="object"&&A(n.right,t);return}if(b(n)){for(let r of n.conditions)A(r,t);return}let o=n;for(let r of Object.keys(o))A(o[r],t);}function L(n){let t=new Set;for(let o of n){let r=o.indexOf("."),i=o.indexOf("["),s=o.length;r!==-1&&(s=Math.min(s,r)),i!==-1&&(s=Math.min(s,i));let e=o.slice(0,s);e&&t.add(e);}return t}function ot(n){return JSON.stringify(n)}function rt(n,t,o,r,i,s){let e=B(n,{noPrefixes:true,useAccessor:i,lexicalPrefix:s}),u=omniAst.generate(e),f="";i?s&&(f=`const{${s}}=data??{};`):t.size>0&&(f=`const{${[...t].join(",")}}=data??{};`);let l=i?new Set([...o,"accessor"]):o,a=l.size>0?`const{${[...l].join(",")}}=scope;`:"",p=r.size>0?`const{${[...r].join(",")}}=context;`:"",d=r.size>0,g="";d&&(i?g="const get=(path)=>accessor(path,data);const ctx={data,get};":g="const get=(path)=>path.split('.').reduce((o,k)=>o?.[k],data);const ctx={data,get};");let w=l.size>0,F;if(w||d){let G=d?"scope,context":"scope",mn=`${f}${g}return ${u}`;F=`(function(${G}){${a}${p}return function(data){${mn}}})`;}else F=`(function(){return function(data){${f}return ${u}}})`;return F}function H(n,t={}){let{scope:o={},context:r={},returnCode:i=false,useAccessor:s=false,lexicalPrefix:e}=t,u=O(n),f=L(u),l=V(n),a=_(n),p=ot(n),d=rt(n,f,l,a,s,e);if(i)return {code:d,deps:u,hash:p,dataRoots:[...f],scopeFns:[...l],contextFns:[...a]};let g;try{let w=a.size>0,F=new Function(`return ${d}`)();g=w?F(o,r):F(o);}catch(w){throw new Error(`AST compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${w instanceof Error?w.message:String(w)}`)}return {fn:g,deps:u,hash:p}}function gn(n,t,o={}){let{fn:r}=H(n,o);return r(t)}function st(n,t){return q(n,t)}function q(n,t){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>q(s,t));let o=n,r=Object.keys(o);for(let s of r)if(s in t){let e=t[s](o);if(typeof e=="object"&&e!==null&&s in e)throw new Error(`Transform "${s}" returned object with same key \u2014 infinite loop`);return q(e,t)}let i={};for(let s of r)i[s]=q(o[s],t);return i}var ut=new Set(["$","$if","$fn","$pipe","$cb"]);function ft(){let n=0;return ()=>String(n++)}function ct(n,t){let{resolvers:o,scope:r={},genId:i,...s}=t,e=Object.keys(o);if(e.length===0)return {expr:n,scope:r};let u=new Set(e),f=[],l={compile:N,genId:i??ft(),scope:r,options:s},a=Q(n,u,o,l,f),p={...r};for(let d=0;d<f.length;d++){let[g,w]=f[d];p[g]=w;}return {expr:a,scope:p}}function Q(n,t,o,r,i){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n)){let l=n.length,a=new Array(l);for(let p=0;p<l;p++)a[p]=Q(n[p],t,o,r,i);return a}let s=n,e=Object.keys(s),u=e.length;for(let l=0;l<u;l++){let a=e[l];if(a[0]==="$"&&!ut.has(a)&&t.has(a)){let p=o[a],d=p(s,r);return d.scopeEntry&&i.push(d.scopeEntry),d.expr}}let f={};for(let l=0;l<u;l++){let a=e[l];f[a]=Q(s[a],t,o,r,i);}return f}var Vt="2.0.0";exports.ExpressionCache=D;exports.VERSION=Vt;exports.assertValid=Dn;exports.builders=cn;exports.cache=tn;exports.cached=zn;exports.clearPathCache=xn;exports.compile=N;exports.compileAST=H;exports.compilePath=j;exports.dslToAST=B;exports.evaluate=Wn;exports.evaluateAST=gn;exports.extractContextFns=_;exports.extractDataRoots=L;exports.extractDeps=O;exports.extractScopeFns=V;exports.get=An;exports.getPathCacheSize=Sn;exports.hasDeps=Rn;exports.hasWildcard=Z;exports.isCb=k;exports.isCondition=h;exports.isConditionExpr=hn;exports.isConditionGroup=b;exports.isConditional=x;exports.isFn=S;exports.isLiteral=J;exports.isPipe=R;exports.isPure=kn;exports.isRef=E;exports.isValid=Mn;exports.normalize=st;exports.normalizePath=z;exports.resolveBoundaries=ct;exports.validate=K;exports.wrapInFunction=dn;
|
package/dist/index.d.cts
CHANGED
|
@@ -134,32 +134,51 @@ interface ValidationResult {
|
|
|
134
134
|
*/
|
|
135
135
|
type Scope = Record<string, (...args: any[]) => any>;
|
|
136
136
|
/**
|
|
137
|
-
* Path getter function
|
|
137
|
+
* Path getter function - accessor de paths.
|
|
138
138
|
*/
|
|
139
139
|
type PathGetterFn = (path: string) => unknown;
|
|
140
|
+
/**
|
|
141
|
+
* Runtime context - contexto unificado passado para ContextFn.
|
|
142
|
+
* Agrupa dados e utilitários da lib em um único objeto imutável.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // No ContextFn
|
|
147
|
+
* const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
148
|
+
* console.log(ctx.data); // dados do usuário
|
|
149
|
+
* console.log(ctx.get("path")); // accessor
|
|
150
|
+
* };
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
interface RuntimeCtx<T = unknown> {
|
|
154
|
+
/** Dados do runtime (passados pelo usuário) */
|
|
155
|
+
data: T;
|
|
156
|
+
/** Accessor de paths - resolve { $: "path" } */
|
|
157
|
+
get: PathGetterFn;
|
|
158
|
+
}
|
|
140
159
|
/**
|
|
141
160
|
* Context function - HOC que controla execução do body.
|
|
142
161
|
* Recebe o body como callback e decide quando/se executá-lo.
|
|
143
162
|
*
|
|
144
|
-
* @param cb - Body compilado
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
* @param params - Parâmetros extras para o context (opcional)
|
|
163
|
+
* @param cb - Body compilado (recebe ctx)
|
|
164
|
+
* @param ctx - Contexto de runtime (data + get)
|
|
165
|
+
* @param params - Parâmetros específicos deste $cb (opcional)
|
|
148
166
|
*
|
|
149
167
|
* @example
|
|
150
168
|
* ```ts
|
|
151
|
-
* const tryCatch: ContextFn = (cb,
|
|
169
|
+
* const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
152
170
|
* try {
|
|
153
|
-
* return cb(
|
|
171
|
+
* return cb(ctx);
|
|
154
172
|
* } catch (e) {
|
|
155
173
|
* return params?.fallback ?? null;
|
|
156
174
|
* }
|
|
157
175
|
* };
|
|
158
176
|
*
|
|
159
|
-
* const transaction: ContextFn = (cb,
|
|
177
|
+
* const transaction: ContextFn = (cb, ctx, params) => {
|
|
160
178
|
* const tx = db.beginTransaction(params);
|
|
161
179
|
* try {
|
|
162
|
-
*
|
|
180
|
+
* // Pode criar novo ctx com dados extras
|
|
181
|
+
* const result = cb({ ...ctx, data: { ...ctx.data, tx } });
|
|
163
182
|
* tx.commit();
|
|
164
183
|
* return result;
|
|
165
184
|
* } catch (e) {
|
|
@@ -167,14 +186,19 @@ type PathGetterFn = (path: string) => unknown;
|
|
|
167
186
|
* throw e;
|
|
168
187
|
* }
|
|
169
188
|
* };
|
|
189
|
+
*
|
|
190
|
+
* // Context pode injetar accessor customizado
|
|
191
|
+
* const simulate: ContextFn = (cb, ctx, params) => {
|
|
192
|
+
* const simulatedGet = (path) => store.getSimulated(path);
|
|
193
|
+
* return cb({ ...ctx, get: simulatedGet });
|
|
194
|
+
* };
|
|
170
195
|
* ```
|
|
171
196
|
*/
|
|
172
|
-
type ContextFn<T = any, R = any> = (cb: (
|
|
197
|
+
type ContextFn<T = any, R = any> = (cb: (ctx: RuntimeCtx<T>) => R, ctx: RuntimeCtx<T>, params?: unknown) => R;
|
|
173
198
|
/**
|
|
174
199
|
* Context registry - HOC functions available to $cb expressions.
|
|
175
|
-
* Separate from scope because context functions have different signature.
|
|
176
200
|
*
|
|
177
|
-
* @example { tryCatch, transaction,
|
|
201
|
+
* @example { tryCatch, transaction, simulate }
|
|
178
202
|
*/
|
|
179
203
|
type Context = Record<string, ContextFn>;
|
|
180
204
|
/**
|
|
@@ -1018,4 +1042,4 @@ declare function resolveBoundaries(expr: unknown, options: ResolveBoundariesOpti
|
|
|
1018
1042
|
*/
|
|
1019
1043
|
declare const VERSION = "2.0.0";
|
|
1020
1044
|
|
|
1021
|
-
export { type AccessorFn, type BoundaryResolver, type BoundaryResolvers, type CbExpr, type CompileASTCodeResult, type CompileASTOptions, type CompileOptions, type CompiledExpression, type CompiledFn, type Condition, type ConditionExpr, type ConditionGroup, type ConditionOp, type ConditionalExpr, type Context, type ContextFn, type Expression, ExpressionCache, type FnExpr, type IdGenerator, type Literal, type PathGetter, type PathGetterFn, type PipeExpr, type RefExpr, type ResolveBoundariesOptions, type ResolveBoundariesResult, type ResolverContext, type ResolverResult, type Scope, type TransformFn, type TransformOptions, type Transforms, VERSION, type ValidateOptions, type ValidationResult, assertValid, builders, cache, cached, clearPathCache, compile, compileAST, compilePath, dslToAST, evaluate, evaluateAST, extractContextFns, extractDataRoots, extractDeps, extractScopeFns, get, getPathCacheSize, hasDeps, hasWildcard, isCb, isCondition, isConditionExpr, isConditionGroup, isConditional, isFn, isLiteral, isPipe, isPure, isRef, isValid, normalize, normalizePath, resolveBoundaries, validate, wrapInFunction };
|
|
1045
|
+
export { type AccessorFn, type BoundaryResolver, type BoundaryResolvers, type CbExpr, type CompileASTCodeResult, type CompileASTOptions, type CompileOptions, type CompiledExpression, type CompiledFn, type Condition, type ConditionExpr, type ConditionGroup, type ConditionOp, type ConditionalExpr, type Context, type ContextFn, type Expression, ExpressionCache, type FnExpr, type IdGenerator, type Literal, type PathGetter, type PathGetterFn, type PipeExpr, type RefExpr, type ResolveBoundariesOptions, type ResolveBoundariesResult, type ResolverContext, type ResolverResult, type RuntimeCtx, type Scope, type TransformFn, type TransformOptions, type Transforms, VERSION, type ValidateOptions, type ValidationResult, assertValid, builders, cache, cached, clearPathCache, compile, compileAST, compilePath, dslToAST, evaluate, evaluateAST, extractContextFns, extractDataRoots, extractDeps, extractScopeFns, get, getPathCacheSize, hasDeps, hasWildcard, isCb, isCondition, isConditionExpr, isConditionGroup, isConditional, isFn, isLiteral, isPipe, isPure, isRef, isValid, normalize, normalizePath, resolveBoundaries, validate, wrapInFunction };
|
package/dist/index.d.ts
CHANGED
|
@@ -134,32 +134,51 @@ interface ValidationResult {
|
|
|
134
134
|
*/
|
|
135
135
|
type Scope = Record<string, (...args: any[]) => any>;
|
|
136
136
|
/**
|
|
137
|
-
* Path getter function
|
|
137
|
+
* Path getter function - accessor de paths.
|
|
138
138
|
*/
|
|
139
139
|
type PathGetterFn = (path: string) => unknown;
|
|
140
|
+
/**
|
|
141
|
+
* Runtime context - contexto unificado passado para ContextFn.
|
|
142
|
+
* Agrupa dados e utilitários da lib em um único objeto imutável.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // No ContextFn
|
|
147
|
+
* const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
148
|
+
* console.log(ctx.data); // dados do usuário
|
|
149
|
+
* console.log(ctx.get("path")); // accessor
|
|
150
|
+
* };
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
interface RuntimeCtx<T = unknown> {
|
|
154
|
+
/** Dados do runtime (passados pelo usuário) */
|
|
155
|
+
data: T;
|
|
156
|
+
/** Accessor de paths - resolve { $: "path" } */
|
|
157
|
+
get: PathGetterFn;
|
|
158
|
+
}
|
|
140
159
|
/**
|
|
141
160
|
* Context function - HOC que controla execução do body.
|
|
142
161
|
* Recebe o body como callback e decide quando/se executá-lo.
|
|
143
162
|
*
|
|
144
|
-
* @param cb - Body compilado
|
|
145
|
-
* @param
|
|
146
|
-
* @param
|
|
147
|
-
* @param params - Parâmetros extras para o context (opcional)
|
|
163
|
+
* @param cb - Body compilado (recebe ctx)
|
|
164
|
+
* @param ctx - Contexto de runtime (data + get)
|
|
165
|
+
* @param params - Parâmetros específicos deste $cb (opcional)
|
|
148
166
|
*
|
|
149
167
|
* @example
|
|
150
168
|
* ```ts
|
|
151
|
-
* const tryCatch: ContextFn = (cb,
|
|
169
|
+
* const tryCatch: ContextFn = (cb, ctx, params) => {
|
|
152
170
|
* try {
|
|
153
|
-
* return cb(
|
|
171
|
+
* return cb(ctx);
|
|
154
172
|
* } catch (e) {
|
|
155
173
|
* return params?.fallback ?? null;
|
|
156
174
|
* }
|
|
157
175
|
* };
|
|
158
176
|
*
|
|
159
|
-
* const transaction: ContextFn = (cb,
|
|
177
|
+
* const transaction: ContextFn = (cb, ctx, params) => {
|
|
160
178
|
* const tx = db.beginTransaction(params);
|
|
161
179
|
* try {
|
|
162
|
-
*
|
|
180
|
+
* // Pode criar novo ctx com dados extras
|
|
181
|
+
* const result = cb({ ...ctx, data: { ...ctx.data, tx } });
|
|
163
182
|
* tx.commit();
|
|
164
183
|
* return result;
|
|
165
184
|
* } catch (e) {
|
|
@@ -167,14 +186,19 @@ type PathGetterFn = (path: string) => unknown;
|
|
|
167
186
|
* throw e;
|
|
168
187
|
* }
|
|
169
188
|
* };
|
|
189
|
+
*
|
|
190
|
+
* // Context pode injetar accessor customizado
|
|
191
|
+
* const simulate: ContextFn = (cb, ctx, params) => {
|
|
192
|
+
* const simulatedGet = (path) => store.getSimulated(path);
|
|
193
|
+
* return cb({ ...ctx, get: simulatedGet });
|
|
194
|
+
* };
|
|
170
195
|
* ```
|
|
171
196
|
*/
|
|
172
|
-
type ContextFn<T = any, R = any> = (cb: (
|
|
197
|
+
type ContextFn<T = any, R = any> = (cb: (ctx: RuntimeCtx<T>) => R, ctx: RuntimeCtx<T>, params?: unknown) => R;
|
|
173
198
|
/**
|
|
174
199
|
* Context registry - HOC functions available to $cb expressions.
|
|
175
|
-
* Separate from scope because context functions have different signature.
|
|
176
200
|
*
|
|
177
|
-
* @example { tryCatch, transaction,
|
|
201
|
+
* @example { tryCatch, transaction, simulate }
|
|
178
202
|
*/
|
|
179
203
|
type Context = Record<string, ContextFn>;
|
|
180
204
|
/**
|
|
@@ -1018,4 +1042,4 @@ declare function resolveBoundaries(expr: unknown, options: ResolveBoundariesOpti
|
|
|
1018
1042
|
*/
|
|
1019
1043
|
declare const VERSION = "2.0.0";
|
|
1020
1044
|
|
|
1021
|
-
export { type AccessorFn, type BoundaryResolver, type BoundaryResolvers, type CbExpr, type CompileASTCodeResult, type CompileASTOptions, type CompileOptions, type CompiledExpression, type CompiledFn, type Condition, type ConditionExpr, type ConditionGroup, type ConditionOp, type ConditionalExpr, type Context, type ContextFn, type Expression, ExpressionCache, type FnExpr, type IdGenerator, type Literal, type PathGetter, type PathGetterFn, type PipeExpr, type RefExpr, type ResolveBoundariesOptions, type ResolveBoundariesResult, type ResolverContext, type ResolverResult, type Scope, type TransformFn, type TransformOptions, type Transforms, VERSION, type ValidateOptions, type ValidationResult, assertValid, builders, cache, cached, clearPathCache, compile, compileAST, compilePath, dslToAST, evaluate, evaluateAST, extractContextFns, extractDataRoots, extractDeps, extractScopeFns, get, getPathCacheSize, hasDeps, hasWildcard, isCb, isCondition, isConditionExpr, isConditionGroup, isConditional, isFn, isLiteral, isPipe, isPure, isRef, isValid, normalize, normalizePath, resolveBoundaries, validate, wrapInFunction };
|
|
1045
|
+
export { type AccessorFn, type BoundaryResolver, type BoundaryResolvers, type CbExpr, type CompileASTCodeResult, type CompileASTOptions, type CompileOptions, type CompiledExpression, type CompiledFn, type Condition, type ConditionExpr, type ConditionGroup, type ConditionOp, type ConditionalExpr, type Context, type ContextFn, type Expression, ExpressionCache, type FnExpr, type IdGenerator, type Literal, type PathGetter, type PathGetterFn, type PipeExpr, type RefExpr, type ResolveBoundariesOptions, type ResolveBoundariesResult, type ResolverContext, type ResolverResult, type RuntimeCtx, type Scope, type TransformFn, type TransformOptions, type Transforms, VERSION, type ValidateOptions, type ValidationResult, assertValid, builders, cache, cached, clearPathCache, compile, compileAST, compilePath, dslToAST, evaluate, evaluateAST, extractContextFns, extractDataRoots, extractDeps, extractScopeFns, get, getPathCacheSize, hasDeps, hasWildcard, isCb, isCondition, isConditionExpr, isConditionGroup, isConditional, isFn, isLiteral, isPipe, isPure, isRef, isValid, normalize, normalizePath, resolveBoundaries, validate, wrapInFunction };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {builders,generate}from'omni-ast';var mn=Object.defineProperty;var En=(n,t)=>{for(var o in t)mn(n,o,{get:t[o],enumerable:true});};var E=n=>n!==null&&typeof n=="object"&&"$"in n&&typeof n.$=="string"&&Object.keys(n).length===1,S=n=>n!==null&&typeof n=="object"&&"$if"in n&&"then"in n,k=n=>n!==null&&typeof n=="object"&&"$fn"in n&&typeof n.$fn=="string",x=n=>n!==null&&typeof n=="object"&&"$pipe"in n&&Array.isArray(n.$pipe),R=n=>n!==null&&typeof n=="object"&&"$cb"in n&&typeof n.$cb=="string"&&"body"in n,G=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),h=n=>n!==null&&typeof n=="object"&&"left"in n&&"op"in n&&G.has(n.op)&&!("$"in n)&&!("$if"in n)&&!("$fn"in n),b=n=>n!==null&&typeof n=="object"&&"logic"in n&&"conditions"in n,hn=n=>h(n)||b(n),q=n=>{if(n===null)return true;let t=typeof n;if(t==="string"||t==="number"||t==="boolean"||Array.isArray(n))return true;if(t==="object"&&n!==null){let o=n,r="left"in o&&"op"in o&&G.has(o.op);return !("$"in o)&&!("$if"in o)&&!("$fn"in o)&&!("$pipe"in o)&&!("$cb"in o)&&!r&&!("logic"in o)}return false};var I=new Map;function Q(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let f=n.slice(e,r);if(r++,f==="*")t.push({type:"wildcard",value:"*"});else {let u=parseInt(f,10);t.push({type:"index",value:isNaN(u)?f:u});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function U(n){return n.includes("[*]")}function N(n){let t=I.get(n);return t||(t=U(n)?Cn(n):bn(n),I.set(n,t),t)}function bn(n){if(!n.includes(".")&&!n.includes("["))return i=>i?.[n];let t=Q(n),o=t.length;if(o===2){let[i,s]=t,e=i.value,f=s.value;return u=>u?.[e]?.[f]}if(o===3){let[i,s,e]=t,f=i.value,u=s.value,l=e.value;return a=>a?.[f]?.[u]?.[l]}let r=t.map(i=>i.value);return i=>{let s=i;for(let e=0;e<o&&s!=null;e++)s=s[r[e]];return s}}function Cn(n){let t=Q(n),o=[];for(let r=0;r<t.length;r++)t[r].type==="wildcard"&&o.push(r);return o.length===1?Tn(t,o[0]):$n(t,o)}function Tn(n,t){let o=n.slice(0,t).map(e=>e.value),r=n.slice(t+1).map(e=>e.value),i=o.length,s=r.length;if(s===0){if(i===1){let e=o[0];return f=>f?.[e]}return e=>{let f=e;for(let u=0;u<i&&f!=null;u++)f=f[o[u]];return f}}if(s===1){let e=r[0];if(i===1){let f=o[0];return u=>{let l=u?.[f];if(Array.isArray(l))return l.map(a=>a?.[e])}}return f=>{let u=f;for(let l=0;l<i&&u!=null;l++)u=u[o[l]];if(Array.isArray(u))return u.map(l=>l?.[e])}}return e=>{let f=e;for(let u=0;u<i&&f!=null;u++)f=f[o[u]];if(Array.isArray(f))return f.map(u=>{let l=u;for(let a=0;a<s&&l!=null;a++)l=l[r[a]];return l})}}function $n(n,t){let o=[],r=0;for(let s=0;s<t.length;s++){let e=t[s],f=s===t.length-1,u=n.slice(r,e).map(l=>l.value);u.length>0&&o.push({type:"access",keys:u}),o.push({type:f?"map":"flatMap",keys:[]}),r=e+1;}let i=n.slice(r).map(s=>s.value);return s=>{let e=s;for(let f of o){if(e==null)return;if(f.type==="access")for(let u of f.keys){if(e==null)return;e=e[u];}else if(f.type==="flatMap"){if(!Array.isArray(e))return;e=e.flatMap(u=>{let l=u;return Array.isArray(l)?l:[l]});}else if(f.type==="map"){if(!Array.isArray(e))return;i.length>0&&(e=e.map(u=>{let l=u;for(let a of i){if(l==null)return;l=l[a];}return l}));}}return e}}function An(n,t){return N(t)(n)}function W(n){let t=n.indexOf("[*]");return t===-1?n:n.slice(0,t)}function Sn(){I.clear();}function kn(){return I.size}function F(n){let t=new Set;return C(n,t),Array.from(t)}function C(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let i=0;i<n.length;i++)C(n[i],t);return}if(E(n)){t.add(W(n.$));return}if(S(n)){if(typeof n.$if=="string"){let i=n.$if.startsWith("!")?n.$if.slice(1):n.$if;t.add(W(i));}else C(n.$if,t);C(n.then,t),n.else!==void 0&&C(n.else,t);return}if(x(n)){for(let i=0;i<n.$pipe.length;i++)C(n.$pipe[i],t);return}if(k(n)){if(n.args)for(let i=0;i<n.args.length;i++)C(n.args[i],t);return}if(R(n)){C(n.body,t),n.params!==void 0&&C(n.params,t);return}if(h(n)){C(n.left,t),n.right!==void 0&&C(n.right,t);return}if(b(n)){for(let i=0;i<n.conditions.length;i++)C(n.conditions[i],t);return}let o=n,r=Object.keys(o);for(let i=0;i<r.length;i++)C(o[r[i]],t);}function xn(n){return F(n).length>0}function Rn(n){return F(n).length===0}function wn(n){return JSON.stringify(n)}function j(n,t={}){let o=t.scope??{},r=t.accessor,i=t.context??{},s=m(n,o,r,i),e=F(n),f=wn(n);return {fn:s,deps:e,hash:f}}function m(n,t,o,r){if(n===null)return ()=>null;if(typeof n!="object")return ()=>n;if(Array.isArray(n)){let i=n.map(s=>m(s,t,o,r));return s=>i.map(e=>e(s))}if(E(n))return Fn(n,o);if(S(n))return On(n,t,o,r);if(x(n))return vn(n,t,o,r);if(k(n))return jn(n,t,o,r);if(R(n))return Nn(n,t,o,r);if(h(n))return Gn(n,t,o,r);if(b(n))return In(n,t,o,r);if(q(n)){let i=n,s=Object.keys(i),e=s.map(f=>m(i[f],t,o,r));return f=>{let u={};for(let l=0;l<s.length;l++)u[s[l]]=e[l](f);return u}}return ()=>n}function Z(n,t){return t?o=>t(n,o):N(n)}function Fn(n,t){return Z(n.$,t)}function On(n,t,o,r){let i;if(typeof n.$if=="string"){let f=n.$if.startsWith("!")?n.$if.slice(1):n.$if,u=Z(f,o);i=n.$if.startsWith("!")?a=>!u(a):a=>!!u(a);}else {let f=m(n.$if,t,o,r);i=u=>!!f(u);}let s=m(n.then,t,o,r),e=n.else!==void 0?m(n.else,t,o,r):()=>{};return f=>i(f)?s(f):e(f)}function vn(n,t,o,r){let i=n.$pipe;if(i.length===0)return ()=>{};if(i.length===1)return m(i[0],t,o,r);let s=m(i[0],t,o,r),e=i.slice(1).map(u=>m(u,t,o,r)),f=e.length;if(f===1){let[u]=e;return l=>{let a=s(l),p=u(l);return typeof p=="function"?p(a):p}}if(f===2){let[u,l]=e;return a=>{let p=s(a),d=u(a);return p=typeof d=="function"?d(p):d,d=l(a),typeof d=="function"?d(p):d}}if(f===3){let[u,l,a]=e;return p=>{let d=s(p),g=u(p);return d=typeof g=="function"?g(d):g,g=l(p),d=typeof g=="function"?g(d):g,g=a(p),typeof g=="function"?g(d):g}}return u=>{let l=s(u);for(let a=0;a<f;a++){let p=e[a](u);l=typeof p=="function"?p(l):p;}return l}}function jn(n,t,o,r){let i=n.$fn,s=n.args;if(s===void 0)return ()=>{let u=t[i];if(!u)throw new Error(`Function not found in scope: ${i}`);return u};let e=s.map(u=>m(u,t,o,r)),f=e.length;if(f===0)return ()=>{let u=t[i];if(!u)throw new Error(`Function not found in scope: ${i}`);return u()};if(f===1){let[u]=e;return l=>{let a=t[i];if(!a)throw new Error(`Function not found in scope: ${i}`);return a(u(l))}}if(f===2){let[u,l]=e;return a=>{let p=t[i];if(!p)throw new Error(`Function not found in scope: ${i}`);return p(u(a),l(a))}}if(f===3){let[u,l,a]=e;return p=>{let d=t[i];if(!d)throw new Error(`Function not found in scope: ${i}`);return d(u(p),l(p),a(p))}}return u=>{let l=t[i];if(!l)throw new Error(`Function not found in scope: ${i}`);return l(...e.map(a=>a(u)))}}function Nn(n,t,o,r){let i=n.$cb,s=m(n.body,t,o,r),e=n.params?m(n.params,t,o,r):void 0,f=u=>o?l=>o(l,u):l=>N(l)(u);return u=>{let l=r?.[i];if(!l)throw new Error(`Context function not found: ${i}`);let a=(g,w)=>s(g),p=f(u),d=e?e(u):void 0;return l(a,u,p,d)}}function Gn(n,t,o,r){let i=m(n.left,t,o,r),s=n.right!==void 0?m(n.right,t,o,r):()=>{};switch(n.op){case "eq":return e=>i(e)===s(e);case "neq":return e=>i(e)!==s(e);case "gt":return e=>i(e)>s(e);case "gte":return e=>i(e)>=s(e);case "lt":return e=>i(e)<s(e);case "lte":return e=>i(e)<=s(e);case "in":return e=>{let f=s(e);return Array.isArray(f)&&f.includes(i(e))};case "notIn":return e=>{let f=s(e);return !Array.isArray(f)||!f.includes(i(e))};case "contains":return e=>{let f=i(e);return Array.isArray(f)&&f.includes(s(e))};case "notContains":return e=>{let f=i(e);return !Array.isArray(f)||!f.includes(s(e))};case "exists":return e=>i(e)!==void 0;case "notExists":return e=>i(e)===void 0;case "matches":return e=>{let f=i(e),u=s(e);return typeof f!="string"||typeof u!="string"?false:new RegExp(u).test(f)};case "notMatches":return e=>{let f=i(e),u=s(e);return typeof f!="string"||typeof u!="string"?true:!new RegExp(u).test(f)};case "startsWith":return e=>{let f=i(e),u=s(e);return typeof f=="string"&&typeof u=="string"&&f.startsWith(u)};case "endsWith":return e=>{let f=i(e),u=s(e);return typeof f=="string"&&typeof u=="string"&&f.endsWith(u)}}}function In(n,t,o,r){let i=n.conditions.map(e=>m(e,t,o,r)),s=i.length;if(s===1)return e=>!!i[0](e);if(s===2){let[e,f]=i;return n.logic==="AND"?u=>!!e(u)&&!!f(u):u=>!!e(u)||!!f(u)}if(s===3){let[e,f,u]=i;return n.logic==="AND"?l=>!!e(l)&&!!f(l)&&!!u(l):l=>!!e(l)||!!f(l)||!!u(l)}return n.logic==="AND"?e=>{for(let f=0;f<s;f++)if(!i[f](e))return false;return true}:e=>{for(let f=0;f<s;f++)if(i[f](e))return true;return false}}function Wn(n,t,o={}){return j(n,o).fn(t)}var z=class{constructor(t=1e3){this.cache=new Map,this._maxSize=t;}get(t,o={}){let r=JSON.stringify(t),i=this.cache.get(r);if(i)return this.cache.delete(r),this.cache.set(r,i),i;let s=j(t,o);if(this.cache.size>=this._maxSize){let e=this.cache.keys().next().value;e&&this.cache.delete(e);}return this.cache.set(r,s),s}has(t){return this.cache.has(JSON.stringify(t))}delete(t){return this.cache.delete(JSON.stringify(t))}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(t){for(this._maxSize=t;this.cache.size>this._maxSize;){let o=this.cache.keys().next().value;o&&this.cache.delete(o);}}},nn=new z;function zn(n,t={}){return nn.get(n,t)}function J(n,t="root",o={}){let r=[];return T(n,t,r,o),{valid:r.length===0,errors:r}}function T(n,t,o,r){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let e=0;e<n.length;e++)T(n[e],`${t}[${e}]`,o,r);return}if(E(n)){(!n.$||typeof n.$!="string")&&o.push(`${t}: invalid reference, $ must be non-empty string`);return}if(S(n)){typeof n.$if=="string"?(n.$if.startsWith("!")?n.$if.slice(1):n.$if)||o.push(`${t}.$if: empty path in string shorthand`):T(n.$if,`${t}.$if`,o,r),T(n.then,`${t}.then`,o,r),n.else!==void 0&&T(n.else,`${t}.else`,o,r);return}if(x(n)){if(!Array.isArray(n.$pipe)){o.push(`${t}.$pipe: must be an array`);return}if(n.$pipe.length===0){o.push(`${t}.$pipe: must have at least one element`);return}for(let e=0;e<n.$pipe.length;e++)T(n.$pipe[e],`${t}.$pipe[${e}]`,o,r);return}if(k(n)){if(!n.$fn||typeof n.$fn!="string"){o.push(`${t}: invalid function, $fn must be non-empty string`);return}if(r.scope&&!(n.$fn in r.scope)&&o.push(`${t}: function "${n.$fn}" not found in scope`),n.args!==void 0)if(!Array.isArray(n.args))o.push(`${t}.args: must be an array`);else for(let e=0;e<n.args.length;e++)T(n.args[e],`${t}.args[${e}]`,o,r);return}if(R(n)){if(!n.$cb||typeof n.$cb!="string"){o.push(`${t}: invalid callback, $cb must be non-empty string`);return}r.context&&!(n.$cb in r.context)&&o.push(`${t}: context function "${n.$cb}" not found`),T(n.body,`${t}.body`,o,r),n.params!==void 0&&T(n.params,`${t}.params`,o,r);return}if(h(n)){G.has(n.op)||o.push(`${t}: invalid operator "${n.op}"`),T(n.left,`${t}.left`,o,r),n.right!==void 0&&T(n.right,`${t}.right`,o,r);return}if(b(n)){if(n.logic!=="AND"&&n.logic!=="OR"&&o.push(`${t}: invalid logic "${n.logic}", must be "AND" or "OR"`),!Array.isArray(n.conditions)){o.push(`${t}.conditions: must be an array`);return}for(let e=0;e<n.conditions.length;e++)T(n.conditions[e],`${t}.conditions[${e}]`,o,r);return}let i=n,s=Object.keys(i);for(let e=0;e<s.length;e++){let f=s[e];T(i[f],`${t}.${f}`,o,r);}}function Dn(n,t={}){let o=J(n,"root",t);if(!o.valid)throw new Error(`Invalid expression: ${o.errors.join("; ")}`)}function Mn(n,t={}){return J(n,"root",t).valid}var un={};En(un,{$:()=>tn,$call:()=>fn,$cb:()=>sn,$cond:()=>rn,$fn:()=>en,$if:()=>Vn,$pipe:()=>on,call:()=>Kn,cb:()=>Jn,cond:()=>qn,fn:()=>_n,pipe:()=>Ln,ref:()=>Bn});function tn(n){return {$:n}}var Bn=tn;function en(n,t){return t===void 0||t.length===0?{$fn:n}:{$fn:n,args:t}}var _n=en;function Vn(n,t,o){return o===void 0?{$if:n,then:t}:{$if:n,then:t,else:o}}function on(...n){return {$pipe:n}}var Ln=on;function rn(n,t,o){return o===void 0?{left:n,op:t}:{left:n,op:t,right:o}}var qn=rn;function sn(n,t,o){return o===void 0?{$cb:n,body:t}:{$cb:n,body:t,params:o}}var Jn=sn;function fn(n,t=[]){return {$fn:n,args:t}}var Kn=fn;var K="data",ln="scope",Xn={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function M(n,t={}){let{dataParam:o=K,scopeParam:r=ln,noPrefixes:i=false,useAccessor:s=false,lexicalPrefix:e}=t;return y(n,o,r,i,s,e)}function y(n,t,o,r,i,s){if(n===null)return builders.literal(null);if(typeof n=="string")return builders.literal(n);if(typeof n=="number")return builders.literal(n);if(typeof n=="boolean")return builders.literal(n);if(Array.isArray(n))return builders.arrayExpression(n.map(e=>y(e,t,o,r,i,s)));if(E(n))return Yn(n.$,t,r,i,s);if(S(n))return Pn(n,t,o,r,i,s);if(x(n))return nt(n.$pipe,t,o,r,i,s);if(k(n))return Qn(n,t,o,r,i,s);if(R(n))return Zn(n,t,o,r,i,s);if(h(n))return tt(n,t,o,r,i,s);if(b(n))return et(n,t,o,r,i,s);if(typeof n=="object"){let f=Object.entries(n).map(([u,l])=>builders.property(builders.identifier(u),y(l,t,o,r,i,s)));return builders.objectExpression(f)}return builders.literal(null)}var X="accessor";function Y(n,t){return t?n===t||n.startsWith(t+"."):false}function Yn(n,t,o,r,i){return r?Y(n,i)?O(n,t,true):builders.callExpression(builders.identifier(X),[builders.literal(n),builders.identifier(t)]):n.includes("[*]")?Hn(n,t,o):O(n,t,o)}function O(n,t,o){let r=D(n);if(r.length===0)return o?builders.identifier("undefined"):builders.identifier(t);let i;if(o){let s=r[0];i=builders.identifier(s.value);for(let e=1;e<r.length;e++){let f=r[e];f.type==="key"?i=builders.memberExpression(i,builders.identifier(f.value),false,true):i=builders.memberExpression(i,builders.literal(f.value),true,true);}}else {i=builders.identifier(t);for(let s of r)s.type==="key"?i=builders.memberExpression(i,builders.identifier(s.value),false,true):i=builders.memberExpression(i,builders.literal(s.value),true,true);}return i}function Hn(n,t,o){let r=n.indexOf("[*]"),i=n.slice(0,r),s=n.slice(r+3),e;if(i?e=O(i,t,o):e=o?builders.identifier("undefined"):builders.identifier(t),!s||s==="")return e;if(s.includes("[*]"))return an(e,s);let f="_i",u=s.startsWith(".")?s.slice(1):s,l=builders.identifier(f);if(u){let a=D(u);for(let p of a)p.type==="key"?l=builders.memberExpression(l,builders.identifier(p.value),false,true):l=builders.memberExpression(l,builders.literal(p.value),true,true);}return builders.callExpression(builders.memberExpression(e,builders.identifier("map"),false,true),[builders.arrowFunctionExpression([builders.identifier(f)],l)])}function an(n,t){let o=t.indexOf("[*]"),r=t.slice(0,o),i=t.slice(o+3),s="_i",e=r.startsWith(".")?r.slice(1):r,f=builders.identifier(s);if(e){let l=D(e);for(let a of l)a.type==="key"&&(f=builders.memberExpression(f,builders.identifier(a.value),false,true));}if(i.includes("[*]")){let l=an(f,i);return builders.callExpression(builders.memberExpression(n,builders.identifier("flatMap"),false,true),[builders.arrowFunctionExpression([builders.identifier(s)],l)])}let u=i.startsWith(".")?i.slice(1):i;if(u){let l=D(u);for(let a of l)a.type==="key"&&(f=builders.memberExpression(f,builders.identifier(a.value),false,true));}return builders.callExpression(builders.memberExpression(n,builders.identifier("flatMap"),false,true),[builders.arrowFunctionExpression([builders.identifier(s)],f)])}function Pn(n,t,o,r,i,s){let e;if(typeof n.$if=="string"){let l=n.$if.startsWith("!"),a=l?n.$if.slice(1):n.$if,p;i?Y(a,s)?p=O(a,t,true):p=builders.callExpression(builders.identifier(X),[builders.literal(a),builders.identifier(t)]):p=O(a,t,r),e=l?builders.unaryExpression("!",p):p;}else e=y(n.$if,t,o,r,i,s);let f=y(n.then,t,o,r,i,s),u=n.else!==void 0?y(n.else,t,o,r,i,s):builders.identifier("undefined");return builders.conditionalExpression(e,f,u)}function Qn(n,t,o,r,i,s){let e=r?builders.identifier(n.$fn):builders.memberExpression(builders.identifier(o),builders.identifier(n.$fn),false,false);if(n.args===void 0)return e;let f=n.args.map(u=>y(u,t,o,r,i,s));return builders.callExpression(e,f)}var Un="context";function Zn(n,t,o,r,i,s){let e=r?builders.identifier(n.$cb):builders.memberExpression(builders.identifier(Un),builders.identifier(n.$cb),false,false),f=y(n.body,t,o,r,i,s),l=[builders.arrowFunctionExpression([builders.identifier(t),builders.identifier("get")],f),builders.identifier(t),builders.identifier("get")];if(n.params!==void 0){let a=y(n.params,t,o,r,i,s);l.push(a);}return builders.callExpression(e,l)}function nt(n,t,o,r,i,s){if(n.length===0)return builders.identifier("undefined");if(n.length===1)return y(n[0],t,o,r,i,s);let e=y(n[0],t,o,r,i,s);for(let f=1;f<n.length;f++){let u=y(n[f],t,o,r,i,s);e=builders.callExpression(u,[e]);}return e}function cn(n,t,o,r,i,s){if(E(n)){let e=n.$;return i?Y(e,s)?O(e,t,true):builders.callExpression(builders.identifier(X),[builders.literal(e),builders.identifier(t)]):O(e,t,r)}return y(n,t,o,r,i,s)}function tt(n,t,o,r,i,s){let e=cn(n.left,t,o,r,i,s),f=n.right!==void 0?cn(n.right,t,o,r,i,s):builders.literal(null),u=Xn[n.op];if(u)return builders.binaryExpression(u,e,f);switch(n.op){case "in":return builders.callExpression(builders.memberExpression(f,builders.identifier("includes")),[e]);case "notIn":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(f,builders.identifier("includes")),[e]));case "contains":return builders.callExpression(builders.memberExpression(e,builders.identifier("includes"),false,true),[f]);case "notContains":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(e,builders.identifier("includes"),false,true),[f]));case "exists":return builders.binaryExpression("!=",e,builders.literal(null));case "notExists":return builders.binaryExpression("==",e,builders.literal(null));case "matches":return builders.callExpression(builders.memberExpression(builders.newExpression(builders.identifier("RegExp"),[f]),builders.identifier("test")),[e]);case "notMatches":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(builders.newExpression(builders.identifier("RegExp"),[f]),builders.identifier("test")),[e]));case "startsWith":return builders.callExpression(builders.memberExpression(e,builders.identifier("startsWith"),false,true),[f]);case "endsWith":return builders.callExpression(builders.memberExpression(e,builders.identifier("endsWith"),false,true),[f]);default:return builders.binaryExpression("===",e,f)}}function et(n,t,o,r,i,s){let{logic:e,conditions:f}=n,u=e==="AND"?"&&":"||";if(f.length===0)return builders.literal(e==="AND");if(f.length===1)return y(f[0],t,o,r,i,s);let l=y(f[0],t,o,r,i,s);for(let a=1;a<f.length;a++){let p=y(f[a],t,o,r,i,s);l=builders.logicalExpression(u,l,p);}return l}function D(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let f=n.slice(e,r);if(r++,f!=="*"){let u=parseInt(f,10);t.push({type:"index",value:isNaN(u)?f:u});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function pn(n,t=[K]){return builders.arrowFunctionExpression(t.map(o=>builders.identifier(o)),n)}function B(n){let t=new Set;return $(n,t),t}function $(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)$(r,t);return}if(E(n))return;if(S(n)){$(n.$if,t),$(n.then,t),n.else!==void 0&&$(n.else,t);return}if(x(n)){for(let r of n.$pipe)$(r,t);return}if(k(n)){if(t.add(n.$fn),n.args)for(let r of n.args)$(r,t);return}if(R(n)){$(n.body,t),n.params!==void 0&&$(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&$(n.left,t),n.right!==void 0&&typeof n.right=="object"&&$(n.right,t);return}if(b(n)){for(let r of n.conditions)$(r,t);return}let o=n;for(let r of Object.keys(o))$(o[r],t);}function _(n){let t=new Set;return A(n,t),t}function A(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)A(r,t);return}if(E(n))return;if(S(n)){A(n.$if,t),A(n.then,t),n.else!==void 0&&A(n.else,t);return}if(x(n)){for(let r of n.$pipe)A(r,t);return}if(k(n)){if(n.args)for(let r of n.args)A(r,t);return}if(R(n)){t.add(n.$cb),A(n.body,t),n.params!==void 0&&A(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&A(n.left,t),n.right!==void 0&&typeof n.right=="object"&&A(n.right,t);return}if(b(n)){for(let r of n.conditions)A(r,t);return}let o=n;for(let r of Object.keys(o))A(o[r],t);}function V(n){let t=new Set;for(let o of n){let r=o.indexOf("."),i=o.indexOf("["),s=o.length;r!==-1&&(s=Math.min(s,r)),i!==-1&&(s=Math.min(s,i));let e=o.slice(0,s);e&&t.add(e);}return t}function ot(n){return JSON.stringify(n)}function rt(n,t,o,r,i,s){let e=M(n,{noPrefixes:true,useAccessor:i,lexicalPrefix:s}),f=generate(e),u="";i?s&&(u=`const{${s}}=data??{};`):t.size>0&&(u=`const{${[...t].join(",")}}=data??{};`);let l=i?new Set([...o,"accessor"]):o,a=l.size>0?`const{${[...l].join(",")}}=scope;`:"",p=r.size>0?`const{${[...r].join(",")}}=context;`:"",d=r.size>0,g="";d&&(i?g="const get=(path)=>accessor(path,data);":g="const get=(path)=>path.split('.').reduce((o,k)=>o?.[k],data);");let w=l.size>0,v;if(w||d){let gn=d?"scope,context":"scope",yn=`${u}${g}return ${f}`;v=`(function(${gn}){${a}${p}return function(data){${yn}}})`;}else v=`(function(){return function(data){${u}return ${f}}})`;return v}function H(n,t={}){let{scope:o={},context:r={},returnCode:i=false,useAccessor:s=false,lexicalPrefix:e}=t,f=F(n),u=V(f),l=B(n),a=_(n),p=ot(n),d=rt(n,u,l,a,s,e);if(i)return {code:d,deps:f,hash:p,dataRoots:[...u],scopeFns:[...l],contextFns:[...a]};let g;try{let w=a.size>0,v=new Function(`return ${d}`)();g=w?v(o,r):v(o);}catch(w){throw new Error(`AST compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${w instanceof Error?w.message:String(w)}`)}return {fn:g,deps:f,hash:p}}function dn(n,t,o={}){let{fn:r}=H(n,o);return r(t)}function st(n,t){return L(n,t)}function L(n,t){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>L(s,t));let o=n,r=Object.keys(o);for(let s of r)if(s in t){let e=t[s](o);if(typeof e=="object"&&e!==null&&s in e)throw new Error(`Transform "${s}" returned object with same key \u2014 infinite loop`);return L(e,t)}let i={};for(let s of r)i[s]=L(o[s],t);return i}var ft=new Set(["$","$if","$fn","$pipe","$cb"]);function ut(){let n=0;return ()=>String(n++)}function ct(n,t){let{resolvers:o,scope:r={},genId:i,...s}=t,e=Object.keys(o);if(e.length===0)return {expr:n,scope:r};let f=new Set(e),u=[],l={compile:j,genId:i??ut(),scope:r,options:s},a=P(n,f,o,l,u),p={...r};for(let d=0;d<u.length;d++){let[g,w]=u[d];p[g]=w;}return {expr:a,scope:p}}function P(n,t,o,r,i){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n)){let l=n.length,a=new Array(l);for(let p=0;p<l;p++)a[p]=P(n[p],t,o,r,i);return a}let s=n,e=Object.keys(s),f=e.length;for(let l=0;l<f;l++){let a=e[l];if(a[0]==="$"&&!ft.has(a)&&t.has(a)){let p=o[a],d=p(s,r);return d.scopeEntry&&i.push(d.scopeEntry),d.expr}}let u={};for(let l=0;l<f;l++){let a=e[l];u[a]=P(s[a],t,o,r,i);}return u}var _t="2.0.0";export{z as ExpressionCache,_t as VERSION,Dn as assertValid,un as builders,nn as cache,zn as cached,Sn as clearPathCache,j as compile,H as compileAST,N as compilePath,M as dslToAST,Wn as evaluate,dn as evaluateAST,_ as extractContextFns,V as extractDataRoots,F as extractDeps,B as extractScopeFns,An as get,kn as getPathCacheSize,xn as hasDeps,U as hasWildcard,R as isCb,h as isCondition,hn as isConditionExpr,b as isConditionGroup,S as isConditional,k as isFn,q as isLiteral,x as isPipe,Rn as isPure,E as isRef,Mn as isValid,st as normalize,W as normalizePath,ct as resolveBoundaries,J as validate,pn as wrapInFunction};
|
|
1
|
+
import {builders,generate}from'omni-ast';var yn=Object.defineProperty;var En=(n,t)=>{for(var o in t)yn(n,o,{get:t[o],enumerable:true});};var E=n=>n!==null&&typeof n=="object"&&"$"in n&&typeof n.$=="string"&&Object.keys(n).length===1,x=n=>n!==null&&typeof n=="object"&&"$if"in n&&"then"in n,S=n=>n!==null&&typeof n=="object"&&"$fn"in n&&typeof n.$fn=="string",R=n=>n!==null&&typeof n=="object"&&"$pipe"in n&&Array.isArray(n.$pipe),k=n=>n!==null&&typeof n=="object"&&"$cb"in n&&typeof n.$cb=="string"&&"body"in n,I=new Set(["eq","neq","gt","gte","lt","lte","in","notIn","contains","notContains","exists","notExists","matches","notMatches","startsWith","endsWith"]),h=n=>n!==null&&typeof n=="object"&&"left"in n&&"op"in n&&I.has(n.op)&&!("$"in n)&&!("$if"in n)&&!("$fn"in n),b=n=>n!==null&&typeof n=="object"&&"logic"in n&&"conditions"in n,hn=n=>h(n)||b(n),J=n=>{if(n===null)return true;let t=typeof n;if(t==="string"||t==="number"||t==="boolean"||Array.isArray(n))return true;if(t==="object"&&n!==null){let o=n,r="left"in o&&"op"in o&&I.has(o.op);return !("$"in o)&&!("$if"in o)&&!("$fn"in o)&&!("$pipe"in o)&&!("$cb"in o)&&!r&&!("logic"in o)}return false};var W=new Map;function U(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let u=n.slice(e,r);if(r++,u==="*")t.push({type:"wildcard",value:"*"});else {let f=parseInt(u,10);t.push({type:"index",value:isNaN(f)?u:f});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function Z(n){return n.includes("[*]")}function j(n){let t=W.get(n);return t||(t=Z(n)?Cn(n):bn(n),W.set(n,t),t)}function bn(n){if(!n.includes(".")&&!n.includes("["))return i=>i?.[n];let t=U(n),o=t.length;if(o===2){let[i,s]=t,e=i.value,u=s.value;return f=>f?.[e]?.[u]}if(o===3){let[i,s,e]=t,u=i.value,f=s.value,l=e.value;return a=>a?.[u]?.[f]?.[l]}let r=t.map(i=>i.value);return i=>{let s=i;for(let e=0;e<o&&s!=null;e++)s=s[r[e]];return s}}function Cn(n){let t=U(n),o=[];for(let r=0;r<t.length;r++)t[r].type==="wildcard"&&o.push(r);return o.length===1?Tn(t,o[0]):$n(t,o)}function Tn(n,t){let o=n.slice(0,t).map(e=>e.value),r=n.slice(t+1).map(e=>e.value),i=o.length,s=r.length;if(s===0){if(i===1){let e=o[0];return u=>u?.[e]}return e=>{let u=e;for(let f=0;f<i&&u!=null;f++)u=u[o[f]];return u}}if(s===1){let e=r[0];if(i===1){let u=o[0];return f=>{let l=f?.[u];if(Array.isArray(l))return l.map(a=>a?.[e])}}return u=>{let f=u;for(let l=0;l<i&&f!=null;l++)f=f[o[l]];if(Array.isArray(f))return f.map(l=>l?.[e])}}return e=>{let u=e;for(let f=0;f<i&&u!=null;f++)u=u[o[f]];if(Array.isArray(u))return u.map(f=>{let l=f;for(let a=0;a<s&&l!=null;a++)l=l[r[a]];return l})}}function $n(n,t){let o=[],r=0;for(let s=0;s<t.length;s++){let e=t[s],u=s===t.length-1,f=n.slice(r,e).map(l=>l.value);f.length>0&&o.push({type:"access",keys:f}),o.push({type:u?"map":"flatMap",keys:[]}),r=e+1;}let i=n.slice(r).map(s=>s.value);return s=>{let e=s;for(let u of o){if(e==null)return;if(u.type==="access")for(let f of u.keys){if(e==null)return;e=e[f];}else if(u.type==="flatMap"){if(!Array.isArray(e))return;e=e.flatMap(f=>{let l=f;return Array.isArray(l)?l:[l]});}else if(u.type==="map"){if(!Array.isArray(e))return;i.length>0&&(e=e.map(f=>{let l=f;for(let a of i){if(l==null)return;l=l[a];}return l}));}}return e}}function An(n,t){return j(t)(n)}function z(n){let t=n.indexOf("[*]");return t===-1?n:n.slice(0,t)}function xn(){W.clear();}function Sn(){return W.size}function O(n){let t=new Set;return C(n,t),Array.from(t)}function C(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let i=0;i<n.length;i++)C(n[i],t);return}if(E(n)){t.add(z(n.$));return}if(x(n)){if(typeof n.$if=="string"){let i=n.$if.startsWith("!")?n.$if.slice(1):n.$if;t.add(z(i));}else C(n.$if,t);C(n.then,t),n.else!==void 0&&C(n.else,t);return}if(R(n)){for(let i=0;i<n.$pipe.length;i++)C(n.$pipe[i],t);return}if(S(n)){if(n.args)for(let i=0;i<n.args.length;i++)C(n.args[i],t);return}if(k(n)){C(n.body,t),n.params!==void 0&&C(n.params,t);return}if(h(n)){C(n.left,t),n.right!==void 0&&C(n.right,t);return}if(b(n)){for(let i=0;i<n.conditions.length;i++)C(n.conditions[i],t);return}let o=n,r=Object.keys(o);for(let i=0;i<r.length;i++)C(o[r[i]],t);}function Rn(n){return O(n).length>0}function kn(n){return O(n).length===0}function wn(n){return JSON.stringify(n)}function N(n,t={}){let o=t.scope??{},r=t.accessor,i=t.context??{},s=y(n,o,r,i),e=O(n),u=wn(n);return {fn:s,deps:e,hash:u}}function y(n,t,o,r){if(n===null)return ()=>null;if(typeof n!="object")return ()=>n;if(Array.isArray(n)){let i=n.map(s=>y(s,t,o,r));return s=>i.map(e=>e(s))}if(E(n))return Fn(n,o);if(x(n))return On(n,t,o,r);if(R(n))return vn(n,t,o,r);if(S(n))return jn(n,t,o,r);if(k(n))return Nn(n,t,o,r);if(h(n))return Gn(n,t,o,r);if(b(n))return In(n,t,o,r);if(J(n)){let i=n,s=Object.keys(i),e=s.map(u=>y(i[u],t,o,r));return u=>{let f={};for(let l=0;l<s.length;l++)f[s[l]]=e[l](u);return f}}return ()=>n}function nn(n,t){return t?o=>t(n,o):j(n)}function Fn(n,t){return nn(n.$,t)}function On(n,t,o,r){let i;if(typeof n.$if=="string"){let u=n.$if.startsWith("!")?n.$if.slice(1):n.$if,f=nn(u,o);i=n.$if.startsWith("!")?a=>!f(a):a=>!!f(a);}else {let u=y(n.$if,t,o,r);i=f=>!!u(f);}let s=y(n.then,t,o,r),e=n.else!==void 0?y(n.else,t,o,r):()=>{};return u=>i(u)?s(u):e(u)}function vn(n,t,o,r){let i=n.$pipe;if(i.length===0)return ()=>{};if(i.length===1)return y(i[0],t,o,r);let s=y(i[0],t,o,r),e=i.slice(1).map(f=>y(f,t,o,r)),u=e.length;if(u===1){let[f]=e;return l=>{let a=s(l),p=f(l);return typeof p=="function"?p(a):p}}if(u===2){let[f,l]=e;return a=>{let p=s(a),d=f(a);return p=typeof d=="function"?d(p):d,d=l(a),typeof d=="function"?d(p):d}}if(u===3){let[f,l,a]=e;return p=>{let d=s(p),g=f(p);return d=typeof g=="function"?g(d):g,g=l(p),d=typeof g=="function"?g(d):g,g=a(p),typeof g=="function"?g(d):g}}return f=>{let l=s(f);for(let a=0;a<u;a++){let p=e[a](f);l=typeof p=="function"?p(l):p;}return l}}function jn(n,t,o,r){let i=n.$fn,s=n.args;if(s===void 0)return ()=>{let f=t[i];if(!f)throw new Error(`Function not found in scope: ${i}`);return f};let e=s.map(f=>y(f,t,o,r)),u=e.length;if(u===0)return ()=>{let f=t[i];if(!f)throw new Error(`Function not found in scope: ${i}`);return f()};if(u===1){let[f]=e;return l=>{let a=t[i];if(!a)throw new Error(`Function not found in scope: ${i}`);return a(f(l))}}if(u===2){let[f,l]=e;return a=>{let p=t[i];if(!p)throw new Error(`Function not found in scope: ${i}`);return p(f(a),l(a))}}if(u===3){let[f,l,a]=e;return p=>{let d=t[i];if(!d)throw new Error(`Function not found in scope: ${i}`);return d(f(p),l(p),a(p))}}return f=>{let l=t[i];if(!l)throw new Error(`Function not found in scope: ${i}`);return l(...e.map(a=>a(f)))}}function Nn(n,t,o,r){let i=n.$cb,s,e=(a,p)=>s?s(a):o?o(a,p):j(a)(p),u=y(n.body,t,e,r),f=n.params?y(n.params,t,o,r):void 0,l=a=>o?p=>o(p,a):p=>j(p)(a);return a=>{let p=r?.[i];if(!p)throw new Error(`Context function not found: ${i}`);let d=l(a),g={data:a,get:d},w=G=>{G.get!==d&&(s=G.get);try{return u(G.data)}finally{s=void 0;}},F=f?f(a):void 0;return p(w,g,F)}}function Gn(n,t,o,r){let i=y(n.left,t,o,r),s=n.right!==void 0?y(n.right,t,o,r):()=>{};switch(n.op){case "eq":return e=>i(e)===s(e);case "neq":return e=>i(e)!==s(e);case "gt":return e=>i(e)>s(e);case "gte":return e=>i(e)>=s(e);case "lt":return e=>i(e)<s(e);case "lte":return e=>i(e)<=s(e);case "in":return e=>{let u=s(e);return Array.isArray(u)&&u.includes(i(e))};case "notIn":return e=>{let u=s(e);return !Array.isArray(u)||!u.includes(i(e))};case "contains":return e=>{let u=i(e);return Array.isArray(u)&&u.includes(s(e))};case "notContains":return e=>{let u=i(e);return !Array.isArray(u)||!u.includes(s(e))};case "exists":return e=>i(e)!==void 0;case "notExists":return e=>i(e)===void 0;case "matches":return e=>{let u=i(e),f=s(e);return typeof u!="string"||typeof f!="string"?false:new RegExp(f).test(u)};case "notMatches":return e=>{let u=i(e),f=s(e);return typeof u!="string"||typeof f!="string"?true:!new RegExp(f).test(u)};case "startsWith":return e=>{let u=i(e),f=s(e);return typeof u=="string"&&typeof f=="string"&&u.startsWith(f)};case "endsWith":return e=>{let u=i(e),f=s(e);return typeof u=="string"&&typeof f=="string"&&u.endsWith(f)}}}function In(n,t,o,r){let i=n.conditions.map(e=>y(e,t,o,r)),s=i.length;if(s===1)return e=>!!i[0](e);if(s===2){let[e,u]=i;return n.logic==="AND"?f=>!!e(f)&&!!u(f):f=>!!e(f)||!!u(f)}if(s===3){let[e,u,f]=i;return n.logic==="AND"?l=>!!e(l)&&!!u(l)&&!!f(l):l=>!!e(l)||!!u(l)||!!f(l)}return n.logic==="AND"?e=>{for(let u=0;u<s;u++)if(!i[u](e))return false;return true}:e=>{for(let u=0;u<s;u++)if(i[u](e))return true;return false}}function Wn(n,t,o={}){return N(n,o).fn(t)}var D=class{constructor(t=1e3){this.cache=new Map,this._maxSize=t;}get(t,o={}){let r=JSON.stringify(t),i=this.cache.get(r);if(i)return this.cache.delete(r),this.cache.set(r,i),i;let s=N(t,o);if(this.cache.size>=this._maxSize){let e=this.cache.keys().next().value;e&&this.cache.delete(e);}return this.cache.set(r,s),s}has(t){return this.cache.has(JSON.stringify(t))}delete(t){return this.cache.delete(JSON.stringify(t))}clear(){this.cache.clear();}get size(){return this.cache.size}get maxSize(){return this._maxSize}set maxSize(t){for(this._maxSize=t;this.cache.size>this._maxSize;){let o=this.cache.keys().next().value;o&&this.cache.delete(o);}}},tn=new D;function zn(n,t={}){return tn.get(n,t)}function K(n,t="root",o={}){let r=[];return T(n,t,r,o),{valid:r.length===0,errors:r}}function T(n,t,o,r){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let e=0;e<n.length;e++)T(n[e],`${t}[${e}]`,o,r);return}if(E(n)){(!n.$||typeof n.$!="string")&&o.push(`${t}: invalid reference, $ must be non-empty string`);return}if(x(n)){typeof n.$if=="string"?(n.$if.startsWith("!")?n.$if.slice(1):n.$if)||o.push(`${t}.$if: empty path in string shorthand`):T(n.$if,`${t}.$if`,o,r),T(n.then,`${t}.then`,o,r),n.else!==void 0&&T(n.else,`${t}.else`,o,r);return}if(R(n)){if(!Array.isArray(n.$pipe)){o.push(`${t}.$pipe: must be an array`);return}if(n.$pipe.length===0){o.push(`${t}.$pipe: must have at least one element`);return}for(let e=0;e<n.$pipe.length;e++)T(n.$pipe[e],`${t}.$pipe[${e}]`,o,r);return}if(S(n)){if(!n.$fn||typeof n.$fn!="string"){o.push(`${t}: invalid function, $fn must be non-empty string`);return}if(r.scope&&!(n.$fn in r.scope)&&o.push(`${t}: function "${n.$fn}" not found in scope`),n.args!==void 0)if(!Array.isArray(n.args))o.push(`${t}.args: must be an array`);else for(let e=0;e<n.args.length;e++)T(n.args[e],`${t}.args[${e}]`,o,r);return}if(k(n)){if(!n.$cb||typeof n.$cb!="string"){o.push(`${t}: invalid callback, $cb must be non-empty string`);return}r.context&&!(n.$cb in r.context)&&o.push(`${t}: context function "${n.$cb}" not found`),T(n.body,`${t}.body`,o,r),n.params!==void 0&&T(n.params,`${t}.params`,o,r);return}if(h(n)){I.has(n.op)||o.push(`${t}: invalid operator "${n.op}"`),T(n.left,`${t}.left`,o,r),n.right!==void 0&&T(n.right,`${t}.right`,o,r);return}if(b(n)){if(n.logic!=="AND"&&n.logic!=="OR"&&o.push(`${t}: invalid logic "${n.logic}", must be "AND" or "OR"`),!Array.isArray(n.conditions)){o.push(`${t}.conditions: must be an array`);return}for(let e=0;e<n.conditions.length;e++)T(n.conditions[e],`${t}.conditions[${e}]`,o,r);return}let i=n,s=Object.keys(i);for(let e=0;e<s.length;e++){let u=s[e];T(i[u],`${t}.${u}`,o,r);}}function Dn(n,t={}){let o=K(n,"root",t);if(!o.valid)throw new Error(`Invalid expression: ${o.errors.join("; ")}`)}function Mn(n,t={}){return K(n,"root",t).valid}var cn={};En(cn,{$:()=>en,$call:()=>fn,$cb:()=>un,$cond:()=>sn,$fn:()=>on,$if:()=>_n,$pipe:()=>rn,call:()=>Kn,cb:()=>Jn,cond:()=>qn,fn:()=>Vn,pipe:()=>Ln,ref:()=>Bn});function en(n){return {$:n}}var Bn=en;function on(n,t){return t===void 0||t.length===0?{$fn:n}:{$fn:n,args:t}}var Vn=on;function _n(n,t,o){return o===void 0?{$if:n,then:t}:{$if:n,then:t,else:o}}function rn(...n){return {$pipe:n}}var Ln=rn;function sn(n,t,o){return o===void 0?{left:n,op:t}:{left:n,op:t,right:o}}var qn=sn;function un(n,t,o){return o===void 0?{$cb:n,body:t}:{$cb:n,body:t,params:o}}var Jn=un;function fn(n,t=[]){return {$fn:n,args:t}}var Kn=fn;var P="data",an="scope",Pn={eq:"===",neq:"!==",gt:">",gte:">=",lt:"<",lte:"<="};function B(n,t={}){let{dataParam:o=P,scopeParam:r=an,noPrefixes:i=false,useAccessor:s=false,lexicalPrefix:e}=t;return m(n,o,r,i,s,e)}function m(n,t,o,r,i,s){if(n===null)return builders.literal(null);if(typeof n=="string")return builders.literal(n);if(typeof n=="number")return builders.literal(n);if(typeof n=="boolean")return builders.literal(n);if(Array.isArray(n))return builders.arrayExpression(n.map(e=>m(e,t,o,r,i,s)));if(E(n))return Xn(n.$,t,r,i,s);if(x(n))return Hn(n,t,o,r,i,s);if(R(n))return nt(n.$pipe,t,o,r,i,s);if(S(n))return Qn(n,t,o,r,i,s);if(k(n))return Zn(n,t,o,r,i,s);if(h(n))return tt(n,t,o,r,i,s);if(b(n))return et(n,t,o,r,i,s);if(typeof n=="object"){let u=Object.entries(n).map(([f,l])=>builders.property(builders.identifier(f),m(l,t,o,r,i,s)));return builders.objectExpression(u)}return builders.literal(null)}var X="accessor";function Y(n,t){return t?n===t||n.startsWith(t+"."):false}function Xn(n,t,o,r,i){return r?Y(n,i)?v(n,t,true):builders.callExpression(builders.identifier(X),[builders.literal(n),builders.identifier(t)]):n.includes("[*]")?Yn(n,t,o):v(n,t,o)}function v(n,t,o){let r=M(n);if(r.length===0)return o?builders.identifier("undefined"):builders.identifier(t);let i;if(o){let s=r[0];i=builders.identifier(s.value);for(let e=1;e<r.length;e++){let u=r[e];u.type==="key"?i=builders.memberExpression(i,builders.identifier(u.value),false,true):i=builders.memberExpression(i,builders.literal(u.value),true,true);}}else {i=builders.identifier(t);for(let s of r)s.type==="key"?i=builders.memberExpression(i,builders.identifier(s.value),false,true):i=builders.memberExpression(i,builders.literal(s.value),true,true);}return i}function Yn(n,t,o){let r=n.indexOf("[*]"),i=n.slice(0,r),s=n.slice(r+3),e;if(i?e=v(i,t,o):e=o?builders.identifier("undefined"):builders.identifier(t),!s||s==="")return e;if(s.includes("[*]"))return pn(e,s);let u="_i",f=s.startsWith(".")?s.slice(1):s,l=builders.identifier(u);if(f){let a=M(f);for(let p of a)p.type==="key"?l=builders.memberExpression(l,builders.identifier(p.value),false,true):l=builders.memberExpression(l,builders.literal(p.value),true,true);}return builders.callExpression(builders.memberExpression(e,builders.identifier("map"),false,true),[builders.arrowFunctionExpression([builders.identifier(u)],l)])}function pn(n,t){let o=t.indexOf("[*]"),r=t.slice(0,o),i=t.slice(o+3),s="_i",e=r.startsWith(".")?r.slice(1):r,u=builders.identifier(s);if(e){let l=M(e);for(let a of l)a.type==="key"&&(u=builders.memberExpression(u,builders.identifier(a.value),false,true));}if(i.includes("[*]")){let l=pn(u,i);return builders.callExpression(builders.memberExpression(n,builders.identifier("flatMap"),false,true),[builders.arrowFunctionExpression([builders.identifier(s)],l)])}let f=i.startsWith(".")?i.slice(1):i;if(f){let l=M(f);for(let a of l)a.type==="key"&&(u=builders.memberExpression(u,builders.identifier(a.value),false,true));}return builders.callExpression(builders.memberExpression(n,builders.identifier("flatMap"),false,true),[builders.arrowFunctionExpression([builders.identifier(s)],u)])}function Hn(n,t,o,r,i,s){let e;if(typeof n.$if=="string"){let l=n.$if.startsWith("!"),a=l?n.$if.slice(1):n.$if,p;i?Y(a,s)?p=v(a,t,true):p=builders.callExpression(builders.identifier(X),[builders.literal(a),builders.identifier(t)]):p=v(a,t,r),e=l?builders.unaryExpression("!",p):p;}else e=m(n.$if,t,o,r,i,s);let u=m(n.then,t,o,r,i,s),f=n.else!==void 0?m(n.else,t,o,r,i,s):builders.identifier("undefined");return builders.conditionalExpression(e,u,f)}function Qn(n,t,o,r,i,s){let e=r?builders.identifier(n.$fn):builders.memberExpression(builders.identifier(o),builders.identifier(n.$fn),false,false);if(n.args===void 0)return e;let u=n.args.map(f=>m(f,t,o,r,i,s));return builders.callExpression(e,u)}var Un="context";function Zn(n,t,o,r,i,s){let e=r?builders.identifier(n.$cb):builders.memberExpression(builders.identifier(Un),builders.identifier(n.$cb),false,false),u=m(n.body,t,o,r,i,s),l=[builders.arrowFunctionExpression([builders.identifier("ctx")],u),builders.identifier("ctx")];if(n.params!==void 0){let a=m(n.params,t,o,r,i,s);l.push(a);}return builders.callExpression(e,l)}function nt(n,t,o,r,i,s){if(n.length===0)return builders.identifier("undefined");if(n.length===1)return m(n[0],t,o,r,i,s);let e=m(n[0],t,o,r,i,s);for(let u=1;u<n.length;u++){let f=m(n[u],t,o,r,i,s);e=builders.callExpression(f,[e]);}return e}function ln(n,t,o,r,i,s){if(E(n)){let e=n.$;return i?Y(e,s)?v(e,t,true):builders.callExpression(builders.identifier(X),[builders.literal(e),builders.identifier(t)]):v(e,t,r)}return m(n,t,o,r,i,s)}function tt(n,t,o,r,i,s){let e=ln(n.left,t,o,r,i,s),u=n.right!==void 0?ln(n.right,t,o,r,i,s):builders.literal(null),f=Pn[n.op];if(f)return builders.binaryExpression(f,e,u);switch(n.op){case "in":return builders.callExpression(builders.memberExpression(u,builders.identifier("includes")),[e]);case "notIn":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(u,builders.identifier("includes")),[e]));case "contains":return builders.callExpression(builders.memberExpression(e,builders.identifier("includes"),false,true),[u]);case "notContains":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(e,builders.identifier("includes"),false,true),[u]));case "exists":return builders.binaryExpression("!=",e,builders.literal(null));case "notExists":return builders.binaryExpression("==",e,builders.literal(null));case "matches":return builders.callExpression(builders.memberExpression(builders.newExpression(builders.identifier("RegExp"),[u]),builders.identifier("test")),[e]);case "notMatches":return builders.unaryExpression("!",builders.callExpression(builders.memberExpression(builders.newExpression(builders.identifier("RegExp"),[u]),builders.identifier("test")),[e]));case "startsWith":return builders.callExpression(builders.memberExpression(e,builders.identifier("startsWith"),false,true),[u]);case "endsWith":return builders.callExpression(builders.memberExpression(e,builders.identifier("endsWith"),false,true),[u]);default:return builders.binaryExpression("===",e,u)}}function et(n,t,o,r,i,s){let{logic:e,conditions:u}=n,f=e==="AND"?"&&":"||";if(u.length===0)return builders.literal(e==="AND");if(u.length===1)return m(u[0],t,o,r,i,s);let l=m(u[0],t,o,r,i,s);for(let a=1;a<u.length;a++){let p=m(u[a],t,o,r,i,s);l=builders.logicalExpression(f,l,p);}return l}function M(n){let t=[],o=n.length,r=0,i="";for(;r<o;){let s=n[r];if(s===".")i&&(t.push({type:"key",value:i}),i=""),r++;else if(s==="["){i&&(t.push({type:"key",value:i}),i=""),r++;let e=r;for(;r<o&&n[r]!=="]";)r++;let u=n.slice(e,r);if(r++,u!=="*"){let f=parseInt(u,10);t.push({type:"index",value:isNaN(f)?u:f});}}else i+=s,r++;}return i&&t.push({type:"key",value:i}),t}function dn(n,t=[P]){return builders.arrowFunctionExpression(t.map(o=>builders.identifier(o)),n)}function V(n){let t=new Set;return $(n,t),t}function $(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)$(r,t);return}if(E(n))return;if(x(n)){$(n.$if,t),$(n.then,t),n.else!==void 0&&$(n.else,t);return}if(R(n)){for(let r of n.$pipe)$(r,t);return}if(S(n)){if(t.add(n.$fn),n.args)for(let r of n.args)$(r,t);return}if(k(n)){$(n.body,t),n.params!==void 0&&$(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&$(n.left,t),n.right!==void 0&&typeof n.right=="object"&&$(n.right,t);return}if(b(n)){for(let r of n.conditions)$(r,t);return}let o=n;for(let r of Object.keys(o))$(o[r],t);}function _(n){let t=new Set;return A(n,t),t}function A(n,t){if(n===null||typeof n!="object")return;if(Array.isArray(n)){for(let r of n)A(r,t);return}if(E(n))return;if(x(n)){A(n.$if,t),A(n.then,t),n.else!==void 0&&A(n.else,t);return}if(R(n)){for(let r of n.$pipe)A(r,t);return}if(S(n)){if(n.args)for(let r of n.args)A(r,t);return}if(k(n)){t.add(n.$cb),A(n.body,t),n.params!==void 0&&A(n.params,t);return}if(h(n)){n.left!==void 0&&typeof n.left=="object"&&A(n.left,t),n.right!==void 0&&typeof n.right=="object"&&A(n.right,t);return}if(b(n)){for(let r of n.conditions)A(r,t);return}let o=n;for(let r of Object.keys(o))A(o[r],t);}function L(n){let t=new Set;for(let o of n){let r=o.indexOf("."),i=o.indexOf("["),s=o.length;r!==-1&&(s=Math.min(s,r)),i!==-1&&(s=Math.min(s,i));let e=o.slice(0,s);e&&t.add(e);}return t}function ot(n){return JSON.stringify(n)}function rt(n,t,o,r,i,s){let e=B(n,{noPrefixes:true,useAccessor:i,lexicalPrefix:s}),u=generate(e),f="";i?s&&(f=`const{${s}}=data??{};`):t.size>0&&(f=`const{${[...t].join(",")}}=data??{};`);let l=i?new Set([...o,"accessor"]):o,a=l.size>0?`const{${[...l].join(",")}}=scope;`:"",p=r.size>0?`const{${[...r].join(",")}}=context;`:"",d=r.size>0,g="";d&&(i?g="const get=(path)=>accessor(path,data);const ctx={data,get};":g="const get=(path)=>path.split('.').reduce((o,k)=>o?.[k],data);const ctx={data,get};");let w=l.size>0,F;if(w||d){let G=d?"scope,context":"scope",mn=`${f}${g}return ${u}`;F=`(function(${G}){${a}${p}return function(data){${mn}}})`;}else F=`(function(){return function(data){${f}return ${u}}})`;return F}function H(n,t={}){let{scope:o={},context:r={},returnCode:i=false,useAccessor:s=false,lexicalPrefix:e}=t,u=O(n),f=L(u),l=V(n),a=_(n),p=ot(n),d=rt(n,f,l,a,s,e);if(i)return {code:d,deps:u,hash:p,dataRoots:[...f],scopeFns:[...l],contextFns:[...a]};let g;try{let w=a.size>0,F=new Function(`return ${d}`)();g=w?F(o,r):F(o);}catch(w){throw new Error(`AST compilation failed. If this is due to CSP, use the standard compile() function instead. Error: ${w instanceof Error?w.message:String(w)}`)}return {fn:g,deps:u,hash:p}}function gn(n,t,o={}){let{fn:r}=H(n,o);return r(t)}function st(n,t){return q(n,t)}function q(n,t){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n))return n.map(s=>q(s,t));let o=n,r=Object.keys(o);for(let s of r)if(s in t){let e=t[s](o);if(typeof e=="object"&&e!==null&&s in e)throw new Error(`Transform "${s}" returned object with same key \u2014 infinite loop`);return q(e,t)}let i={};for(let s of r)i[s]=q(o[s],t);return i}var ut=new Set(["$","$if","$fn","$pipe","$cb"]);function ft(){let n=0;return ()=>String(n++)}function ct(n,t){let{resolvers:o,scope:r={},genId:i,...s}=t,e=Object.keys(o);if(e.length===0)return {expr:n,scope:r};let u=new Set(e),f=[],l={compile:N,genId:i??ft(),scope:r,options:s},a=Q(n,u,o,l,f),p={...r};for(let d=0;d<f.length;d++){let[g,w]=f[d];p[g]=w;}return {expr:a,scope:p}}function Q(n,t,o,r,i){if(n===null)return null;if(typeof n!="object")return n;if(Array.isArray(n)){let l=n.length,a=new Array(l);for(let p=0;p<l;p++)a[p]=Q(n[p],t,o,r,i);return a}let s=n,e=Object.keys(s),u=e.length;for(let l=0;l<u;l++){let a=e[l];if(a[0]==="$"&&!ut.has(a)&&t.has(a)){let p=o[a],d=p(s,r);return d.scopeEntry&&i.push(d.scopeEntry),d.expr}}let f={};for(let l=0;l<u;l++){let a=e[l];f[a]=Q(s[a],t,o,r,i);}return f}var Vt="2.0.0";export{D as ExpressionCache,Vt as VERSION,Dn as assertValid,cn as builders,tn as cache,zn as cached,xn as clearPathCache,N as compile,H as compileAST,j as compilePath,B as dslToAST,Wn as evaluate,gn as evaluateAST,_ as extractContextFns,L as extractDataRoots,O as extractDeps,V as extractScopeFns,An as get,Sn as getPathCacheSize,Rn as hasDeps,Z as hasWildcard,k as isCb,h as isCondition,hn as isConditionExpr,b as isConditionGroup,x as isConditional,S as isFn,J as isLiteral,R as isPipe,kn as isPure,E as isRef,Mn as isValid,st as normalize,z as normalizePath,ct as resolveBoundaries,K as validate,dn as wrapInFunction};
|