fig-tree-evaluator 3.0.0-preview.14 → 3.0.0-preview.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{t as e,i as t,c as n,a as r,n as a,b as o,d as s,e as i,v as c,f as u,r as l,g as p,s as m,F as d,h as y,j as f}from"../chunks/engine.js";import{i as h,r as v,W as g,E as b,a as w,F as x,b as k}from"../chunks/shared.js";const j=e=>"demand"in e,O=(t,n)=>({...t,path:n.path,...void 0===t.fragment?{fragment:n.name,fragmentPath:e(t.path)}:{},order:[n.order,...t.order]}),$=(t,n)=>void 0===t.fragmentPath?{...t,path:n.path,fragmentPath:e(t.path)}:{...t,path:n.path},A=t=>{const{code:n,message:r,certainty:a,operator:o,parameter:s,fragment:i,fragmentPath:c}=t;return{path:e(t.path),code:n,message:r,certainty:a,...void 0!==o?{operator:o}:{},...void 0!==s?{parameter:s}:{},...void 0!==i?{fragment:i,fragmentPath:c}:{}}},N=({path:e,code:t,message:n,operator:r,parameter:a})=>({path:[...e],code:t,message:n,certainty:"always",...void 0!==r?{operator:r}:{},...void 0!==a?{parameter:a}:{}}),S=e=>{const t=new Map;for(const{finding:n}of[...e].sort((e,t)=>((e,t)=>{for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e[n]-t[n];return e.length-t.length})(e.order,t.order))){const e=JSON.stringify({...n,message:void 0,certainty:void 0}),r=t.get(e);void 0===r?t.set(e,n):"always"===n.certainty&&(r.certainty="always")}return[...t.values()]},M=e=>({order:e.order,finding:A(e)}),P=(t,n)=>({order:t.order,finding:{...A(t),coveredBy:e(n.path),...void 0!==n.fragmentPath?{coveredByFragmentPath:n.fragmentPath}:{},...n.givesNull?{givesNull:n.givesNull}:{}}}),F=[],E=[{type:"string"},{type:"number"},{type:"boolean"},{type:"null"},{type:"array"},{type:"object"},{type:"opaque"},{type:"nonFinite"}],z=e=>[{exact:void 0===e?null:e}],L=e=>e.length>0&&e.every(e=>"exact"in e)?e.map(e=>e.exact):void 0,q=e=>"exact"in e?null===e.exact:"null"===e.type,D=e=>{if(h(e))return e.literal.map(e=>({exact:e}));const t="string"==typeof e?[e]:e;return t.includes("any")?E:W(t.map(e=>[{type:e}]))},J=new WeakMap;let B=0;const I=e=>"object"==typeof e&&null!==e||"function"==typeof e?`=#${(e=>{let t=J.get(e);return void 0===t&&J.set(e,t=++B),t})(e)}`:`=${typeof e}:${String(e)}`,C=e=>{if("exact"in e)return I(e.exact);if("array"===e.type)return void 0!==e.items?`a[${e.items.map(T).join(";")}]`:`a${e.length??""}+${e.minLength??""}(${void 0===e.element?"*":T(e.element)})`;if("object"===e.type)return void 0===e.keys?"o":`o{${Object.keys(e.keys).sort().map(t=>`${JSON.stringify(t)}:${T(e.keys[t])}`).join(",")}}`;const{type:t,...n}=e;return`${t}${JSON.stringify(n)}`},T=e=>e.map(C).sort().join("|"),R=e=>{if(null===e)return{type:"null"};if(Array.isArray(e))return{type:"array"};switch(typeof e){case"string":return{type:"string"};case"number":return{type:Number.isInteger(e)?"integer":Number.isFinite(e)?"number":"nonFinite"};case"boolean":return{type:"boolean"};case"object":{const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t?{type:"object"}:{type:"opaque"}}default:return{type:"opaque"}}},W=e=>{const t=new Set,n=[];for(const r of e)for(const e of r){const r=C(e);t.has(r)||(t.add(r),n.push(e))}const r=n.filter(e=>"exact"in e).map(e=>e.exact);return r.length<=16?n:H(n.filter(e=>!("exact"in e)),Q(r))},H=(...e)=>W(e),G=e=>"number"==typeof e&&Number.isFinite(e),K=e=>Array.from(e).length,Q=e=>{const t=(e,t)=>{if(0===t.length)return F;const n=t.reduce((e,t)=>Math.min(e,t));return[U({type:e},n)]};return W([...[!0,!1].map(t=>ye(me(e.map(e=>G(e)&&Number.isInteger(e)===t?le(e):void 0)))),t("string",e.filter(e=>"string"==typeof e).map(K)),t("array",e.filter(Array.isArray).map(e=>e.length)),...e.filter(e=>!G(e)&&"string"!=typeof e&&!Array.isArray(e)).map(e=>[R(e)])])},U=(e,t)=>t?{...e,minLength:t}:e,V=e=>e.some(q),X=e=>e.length>0&&e.every(q),Y=e=>e.filter(e=>!q(e)),Z=e=>Oe(e.map(e=>{if("exact"in e){const{exact:n}=e;return(Array.isArray(n)?n:t(n)?Object.values(n):[]).includes(null)?"yes":"no"}return"array"===e.type?0!==e.length&&V(e.element??E)?"maybe":"no":"object"===e.type?"maybe":"no"})),_=(e,t)=>W(e.map(e=>{if("no"===Z([e]))return[e];const n="exact"in e?e.exact:void 0;if(1===t.length&&"exact"in t[0]&&"exact"in e){const e=t[0].exact,r=t=>null===t?e:t;if(Array.isArray(n))return z(n.map(r));const a={};for(const[e,t]of Object.entries(n))a[e]=r(t);return z(a)}if(!(Array.isArray(n)||"type"in e&&"array"===e.type))return[{type:"object"}];const{length:r,minLength:a}=e;return ne([Y(te([e])),t],Array.isArray(n)?{length:n.length}:{length:r,minLength:a})})),ee=e=>e.flatMap(e=>{const t=Z([e]);if("no"===t)return[e];if("yes"===t)return F;if(!("type"in e))return[e];if("array"!==e.type)return[e];const{items:n,...r}=e;if(void 0===n)return[{...r,element:Y(e.element??E)}];const a=n.map(Y);return a.some(e=>0===e.length)?F:re(a)}),te=e=>W(e.map(e=>"exact"in e?Array.isArray(e.exact)?W(Array.from(e.exact,e=>z(e))):F:"array"===e.type?0===e.length?F:e.element??E:F)),ne=(e,t={})=>[{type:"array",element:W(e),...t}],re=e=>[{type:"array",element:W(e),length:e.length,items:e}],ae=e=>H(e.map(e=>"exact"in e?R(e.exact):e)),oe=e=>je(e.map(e=>"exact"in e?"number"!=typeof e.exact||Number.isFinite(e.exact)?"no":"yes":"nonFinite"===e.type?"maybe":"no")),se=e=>[{type:"object",keys:e}],ie=(e,t)=>{if(0===t.length)return{value:e,found:"yes"};const[n,...r]=t;let a;const o=[],s=Oe(e.map(e=>{if("exact"in e){const n=v(e.exact,t);return n.found&&o.push(z(n.value)),n.found?"yes":"no"}const s=(e,t)=>{if("no"===t)return"no";const n=(e=>e===E?a??=ie(E,r):ie(e,r))(e);return o.push(n.value),"yes"===t?n.found:"no"===n.found?"no":"maybe"};if(n===g)return"array"!==e.type?"no":(o.push(0===r.length?[e]:[{type:"array"}]),"yes");switch(e.type){case"array":{const t="number"==typeof n?n:Number(n);if(!Number.isInteger(t)||t<0)return"number"==typeof n?"no":"maybe";const r=void 0!==e.length?t<e.length?"yes":"no":t<(e.minLength??0)?"yes":"maybe";return void 0!==e.items&&"yes"===r?s(e.items[t],"yes"):s(e.element??E,r)}case"object":return void 0===e.keys?s(E,"maybe"):Object.hasOwn(e.keys,String(n))?s(e.keys[String(n)],"yes"):"no";case"opaque":return s(E,"maybe");default:return"no"}}));return{value:W(o),found:0===e.length?"yes":s}},ce={min:0,max:0,integer:!0},ue={min:1,max:1,integer:!0},le=e=>({min:e,max:e,integer:Number.isInteger(e)}),pe=e=>"exact"in e?G(e.exact)?le(e.exact):void 0:"number"===e.type||"integer"===e.type?{min:e.min??-1/0,max:e.max??1/0,integer:"integer"===e.type}:void 0,me=e=>e.reduce((e,t)=>void 0===e||void 0===t?e??t:{min:Math.min(e.min,t.min),max:Math.max(e.max,t.max),integer:e.integer&&t.integer},void 0),de=e=>me(e.map(pe)),ye=e=>{if(void 0===e)return F;const t=e.integer?Math.ceil(e.min):e.min,n=e.integer?Math.floor(e.max):e.max;return t>n?F:[{type:e.integer?"integer":"number",...t>-1/0?{min:t}:{},...n<1/0?{max:n}:{}}]},fe=e=>e.filter(e=>"exact"in e?"number"!=typeof e.exact:!["number","integer","nonFinite"].includes(e.type)),he=e=>te(e).filter(e=>"no"!==oe([e])),ve=(e,t,n)=>W(e.map(e=>"exact"in e?Array.isArray(e.exact)?t(Array.from(e.exact,e=>z(e))):F:"array"!==e.type?F:void 0!==e.items?t(e.items):0===e.length?n(F,0):n(e.element??E,e.length??e.minLength??0))),ge=(e,t,n)=>e.reduce((e,t)=>{const r=de(t);return e&&r&&n(e,r)},t),be=(e,t)=>({min:e.min+t.min,max:e.max+t.max,integer:e.integer&&t.integer}),we=(e,t)=>0===e||0===t?0:e*t,xe=(e,t)=>{const n=[we(e.min,t.min),we(e.min,t.max),we(e.max,t.min),we(e.max,t.max)];return{min:Math.min(...n),max:Math.max(...n),integer:e.integer&&t.integer}},ke=(e,t)=>H(fe(te(e)),he(e),ve(e,e=>{const n=e.map(de);if(e.some(e=>"no"!==oe(e)))return ye(me(n));if(0===n.length||n.includes(void 0))return F;const r="min"===t?Math.min:Math.max;return ye({min:n.map(e=>e.min).reduce((e,t)=>r(e,t)),max:n.map(e=>e.max).reduce((e,t)=>r(e,t)),integer:n.every(e=>e.integer)})},e=>ye(de(e)))),je=e=>e.includes("yes")?"yes":e.includes("maybe")?"maybe":"no",Oe=e=>e.every(e=>"yes"===e)?"yes":e.every(e=>"no"===e)?"no":"maybe",$e=(e,t)=>"no"===e||"no"===t?"no":"yes"===e&&"yes"===t?"yes":"maybe",Ae=(e,t)=>{if("exact"in e)return Ne([e.exact],t);if("object"!==e.type)return"no";if(void 0===e.keys)return"maybe";const n=e.keys;return Oe(Object.entries(t).map(([e,t])=>{if(!Object.hasOwn(n,e))return!1===t.required?"yes":"no";const r=void 0===t.type?"yes":Se(n[e],t.type);return void 0===t.constraints?r:$e(r,Se(n[e],"any",t.constraints))}))},Ne=(e,t)=>r(e,{elementShape:t},!1).ok?"yes":"no",Se=(e,t,a,o=!1)=>Oe(e.map(e=>{if("exact"in e){const s=e.exact;return n(s,t).ok&&(null===s||void 0===a||r(s,a,o).ok)?"yes":"no"}const s=((e,t)=>{if(h(t)){const n=t=>{const n=pe(e);return void 0!==n?"number"==typeof t&&(!n.integer||Number.isInteger(t))&&t>=n.min&&t<=n.max:"string"===e.type?"string"==typeof t&&K(t)>=(e.minLength??0):typeof t===e.type};return t.literal.some(n)?"maybe":"no"}const n="string"==typeof t?[t]:t;if(n.includes("any"))return"yes";switch(e.type){case"number":return n.includes("number")?"yes":n.includes("integer")?"maybe":"no";case"integer":return n.includes("integer")||n.includes("number")?"yes":"no";case"opaque":return n.includes("object")?"maybe":"no";case"nonFinite":return n.includes("number")?"yes":"no";default:return n.includes(e.type)?"yes":"no"}})(e,t);return"no"===s||void 0===a||"null"===e.type?s:$e(s,((e,t,n)=>{if(0===Object.keys(t).filter(e=>void 0!==t[e]).length)return"yes";if("array"!==e.type)return"no";let r="yes";void 0!==t.length&&(r=$e(r,void 0===e.length?"maybe":e.length===t.length?"yes":"no"));const a=0===e.length?F:e.element??E,o=n?Y(a):a;return void 0!==t.homogeneous&&(r=$e(r,0===o.length||t.homogeneous.some(e=>"yes"===Se(o,e))?"yes":"maybe")),void 0!==t.elementShape&&(r=$e(r,o.every(e=>"yes"===Ae(e,t.elementShape))?"yes":"maybe")),r})(e,a,o))})),Me=(e,t)=>"yes"===Se(e,t)?e:W(e.map(e=>"no"===Se([e],t)?F:"exact"in e?[e]:h(t)?t.literal.filter(t=>"no"!==Se([e],{literal:[t]})).map(e=>({exact:e})):"number"===e.type?ye({...pe(e),integer:!0}):[e])),Pe=e=>"string"==typeof e?e:Array.isArray(e)?e.join(" | "):`one of ${e.literal.map(e=>JSON.stringify(e)).join(", ")}`,Fe=(e,t,n)=>{const r=e.entry.hostDefaults;return void 0!==r&&Object.hasOwn(r,t)?z(r[t]):"default"in n?"symbol"==typeof n.default?E:z(n.default):void 0},Ee=(e,t)=>"lazyEntries"===e.evaluation?"entries"===t.kind:"elements"===t.kind,ze=(e,t)=>{const n=e.nullPolicy;if("string"==typeof n)return new Set([n]);const r=t[n.selector]?.known??F,a=r.every(e=>"exact"in e)?n.table.filter(e=>r.some(t=>"exact"in t&&t.exact===e.value)):n.table;return new Set(a.map(e=>e.policy))},Le=(e,t)=>{const{definition:n}=e.entry,{entries:r,whole:s}=n.resolution,i={},c=new Set,u=[],l={},p=new Set,m={},d=new Set;let y,f="no";const h=(t,n,r,a)=>{const o=Se(r,n.type,n.constraints,void 0!==n.elementNullPolicy);if("yes"===o)return;const s={path:e.path,code:"type-check",message:`${e.name} – parameter '${t}': may receive something other than ${Pe(n.type)}${void 0!==n.constraints?", as constrained":""}`,certainty:"no"===o&&a?"always":"may",operator:e.name,parameter:t,order:[e.order]};u.push(s),"no"===o&&a&&(y??=s)};for(const[n,a]of r){const r=e.params[n];switch(a.evaluation){case"eager":void 0!==r&&(l[n]={known:t[n],absent:!1});break;case"structural":"constant"===r?.kind&&(l[n]={known:z(r.value),absent:!1});break;case"lazy":if(void 0!==a.replacesNullAt){const o=void 0!==r?t[n]:Fe(e,n,a);if(void 0!==o)for(const e of a.replacesNullAt)m[e]={name:n,known:o}}else void 0!==r&&(p.add(n),h(n,a,t[n],!1),i[n]=Me(t[n],a.type));break;case"lazyElements":case"lazyEntries":case"race":if(void 0===r)break;Ee(a,r)?(p.add(n),i[n]=t[n]):l[n]={known:t[n],absent:!1}}}for(const[t,n]of s){if(p.has(t))continue;const r=l[t]??{known:F,absent:!0},o=a(n)&&V(r.known);if(!r.absent&&!o)continue;const s=Fe(e,t,n),i=o?Y(r.known):r.known;l[t]={known:void 0===s?i:H(i,s),absent:void 0===s}}for(const[e,t]of s){if(p.has(e))continue;let n=l[e]?.known??F;if(0===n.length)continue;l[e].absent&&c.add(e);const r=m[e];if(void 0!==r){(void 0!==t.elementNullPolicy?"no"!==Z(n):V(n))&&(d.add(r.name),n=void 0!==t.elementNullPolicy?_(n,r.known):H(Y(n),r.known))}const a="eager"!==t.evaluation&&"structural"!==t.evaluation;if(V(n)&&o(t.type)&&!a){const e=ze(t,l);if(e.has("propagate")){const t=1===e.size&&X(n);if(f=t?"yes":"maybe",t){y??="null";break}1===e.size&&(n=Y(n))}}if("propagate"===t.elementNullPolicy){const e=Z(n);if("no"!==e){if(f="yes"===e?"yes":"maybe","yes"===e){y??="null";break}n=ee(n)}}h(e,t,n,!0),i[e]=Je(t,n)}if("no"!==f)for(const e of u)"always"===e.certainty&&(e.certainty="may");return{received:i,absent:c,failures:u,propagates:f,consulted:d,...y?{ends:y}:{}}},qe=e=>{const t="string"==typeof e?[e]:Array.isArray(e)?e:[];return t.length>0&&t.every(e=>"array"===e||"object"===e)},De=(e,n)=>{if(qe(n)){if(Array.isArray(e))return e.map(s);if(t(e)){const t={};for(const[n,r]of Object.entries(e))t[n]=s(r);return t}}return s(e)},Je=(e,t)=>{const n=Me(t,e.type);return e.truthiness?n.length>0&&n.every(e=>"exact"in e)?W(n.map(t=>z(De(t.exact,e.type)))):qe(e.type)?E:D("boolean"):n},Be=(e,t)=>{const n=a(e)&&V(t),r=n?Y(t):t;let o=Se(r,e.type,e.constraints);"yes"===o&&void 0!==e.constraints&&V(r)&&(o="maybe");const s=n?z(e.default??null):F;return{known:H(Me(r,e.type),s),answer:o}},Ie=(e,t,n,r)=>{if("yes"!==Se(r,n.type,n.constraints))return{path:e.path,code:"type-check",message:`${e.name} – parameter '${t}': an element's result may be other than ${Pe(n.type)}`,certainty:"may",operator:e.name,parameter:t,order:[e.order]}},Ce="non-finite-result",Te="empty-aggregate",Re="operator-failure",We={code:Ce,overflow:!0},He=e=>({code:"type-check",parameter:"values",when:{expect:e,values:{some:{not:{type:e}}}}}),Ge={plus:[{code:Te,parameter:"values",when:{values:{empty:!0},expect:{supplied:!1}}},He("number"),He("string"),He("array"),He("object"),We],subtract:[We],multiply:[We],divide:[{code:Ce,parameter:"by",when:{by:0}},We],modulo:[{code:Ce,parameter:"mod",when:{mod:0}},We],power:[{code:Ce,parameter:"base",when:{base:0,exponent:{below:0}}},{code:Ce,parameter:"base",may:!0,when:{base:{below:0},exponent:{not:{type:"integer"}}}},{code:Ce,parameter:"exponent",may:!0,when:{exponent:{not:{below:100}}}},We],round:[{code:Ce,parameter:"decimals",may:!0,when:{decimals:{not:{below:300}}}},We],min:[{code:Te,parameter:"values",when:{values:{empty:!0}}}],max:[{code:Te,parameter:"values",when:{values:{empty:!0}}}],match:[{code:Re,may:!0,when:{default:{supplied:!1}}}],regex:[{code:Re,parameter:"flags",when:{flags:{invalid:!0}}},{code:Re,parameter:"pattern",when:{pattern:{invalid:!0}}}],get:[{code:Re,parameter:"path",when:{path:{invalid:!0}}},{code:"missing-data-path",may:!0,options:{strictDataPaths:!0},when:{default:{supplied:!1}}}],convert:[{code:Re,when:{to:"number",value:{type:["array","object"]}}},{code:Re,may:!0,when:{to:"number",value:{type:"string"}}},{code:Ce,may:!0,when:{to:"number",value:{type:"string"}}},{code:Re,when:{to:"string",value:{type:["array","object"]}}}]};let Ke;const Qe=e=>{const t=e.analysis;return void 0!==t?t.external?"external":t.failures??[]:(Ke??=new Map(i.map(e=>[e,Ge[e.name]??[]])),Ke.get(e)??"external")},Ue=e=>"yes"===e?"no":"no"===e?"yes":"maybe",Ve=(e,n)=>{if(null===e||"object"!=typeof e){if("exact"in n)return n.exact===e?"yes":"no";return"no"===Se([n],null===e?"null":{literal:[e]})?"no":"maybe"}if("type"in e)return Se([n],e.type);if("not"in e)return Ue(Ve(e.not,n));if("below"in e)return"exact"in n?"number"==typeof n.exact&&n.exact<e.below?"yes":"no":"number"===n.type||"integer"===n.type?(n.max??1/0)<e.below?"yes":(n.min??-1/0)>=e.below?"no":"maybe":"nonFinite"===n.type?"maybe":"no";if("empty"in e){if("exact"in n){const{exact:e}=n;return"string"==typeof e||Array.isArray(e)?0===e.length?"yes":"no":t(e)&&0===Object.keys(e).length?"yes":"no"}switch(n.type){case"array":return void 0!==n.length?0===n.length?"yes":"no":n.minLength?"no":"maybe";case"object":return void 0===n.keys?"maybe":0===Object.keys(n.keys).length?"yes":"no";case"string":return n.minLength?"no":"maybe";default:return"no"}}if("some"in e){if("exact"in n){const{exact:r}=n,a=Array.isArray(r)?Array.from(r):t(r)?Object.values(r):[];return je(a.map(t=>Ve(e.some,{exact:t??null})))}if("array"===n.type){if(0===n.length)return"no";const t=Xe(e.some,n.element??E);return"yes"!==t||void 0===n.length&&!n.minLength?"no"===t?"no":"maybe":"yes"}return"object"===n.type?void 0===n.keys?"maybe":je(Object.values(n.keys).map(t=>"no"===Xe(e.some,t)?"no":"maybe")):"no"}return"maybe"},Xe=(e,t)=>0===t.length?"no":Oe(t.map(t=>Ve(e,t))),Ye=e=>void 0!==e&&1===e.length&&"exact"in e[0]?{value:e[0].exact}:void 0,Ze=(e,t,n,r)=>{const a=r.received[t],o=void 0===a?"no":r.absent.has(t)?"maybe":"yes";return null!==n&&"object"==typeof n&&"supplied"in n?n.supplied?o:Ue(o):"no"===o?"no":null!==n&&"object"==typeof n&&"invalid"in n?((e,t,n)=>{const{validate:r}=e.entry.definition;if(void 0===r)return"no";if(void 0===Ye(n.received[t]))return"maybe";const a={};for(const[e,t]of Object.entries(n.received)){const r=Ye(t);void 0===r||n.absent.has(e)||(a[e]=r.value)}return r(a,c).some(e=>"error"===e.severity&&e.parameter===t)?"yes":"no"})(e,t,r):Xe(n,a)},_e=e=>null===e||"object"!=typeof e?JSON.stringify(e):"type"in e?"string"==typeof e.type?`a ${e.type}`:`of type ${JSON.stringify(e.type)}`:"not"in e?`not ${_e(e.not)}`:"below"in e?`below ${e.below}`:"empty"in e?"empty":"supplied"in e?e.supplied?"supplied":"not supplied":"invalid"in e?"refused by its validation":`with some element ${_e(e.some)}`,et=(e,t)=>{const n=Object.entries(t.when??{}).map(([e,t])=>null!==t&&"object"==typeof t&&"some"in t?`some element of '${e}' is ${_e(t.some)}`:`'${e}' is ${_e(t)}`),r=n.length>0?`when ${n.join(" and ")}`:t.overflow?"on extreme numbers":"whatever its inputs";return`${e} – ${t.code} ${t.may?"possible ":""}${r}`},tt=(e,t,n,r)=>{if(t.overflow&&!r.strictNumbers)return"no";for(const[e,n]of Object.entries(t.options??{}))if((r.evaluation[e]??!1)!==n)return"no";const a=Object.entries(t.when??{}).map(([t,r])=>Ze(e,t,r,n));return a.includes("no")?"no":a.every(e=>"yes"===e)?"yes":"maybe"},nt={if:{oneOf:[{param:"then"},{param:"else"}]},match:{oneOf:[{param:"branches"},{param:"default"}]},firstNonNull:{firstNonNull:"values"},find:{oneOf:[{elementOf:"input"},{param:"noMatchDefault"}]},plus:{oneOf:[{sum:"values"},{typeNamedBy:"expect"}]},subtract:{difference:["value","minus"]},multiply:{product:"values"},abs:{abs:"value"},min:{min:"values"},max:{max:"values"},length:{type:"integer",min:0},filter:{arrayOf:{elementOf:"input"}},map:{arrayOf:{param:"each"}},split:{byParam:"delimiter",cases:{"":{arrayOf:"string"}},otherwise:{arrayOf:"string",minLength:1}},convert:{typeNamedBy:"to"},regex:{byParam:"mode",cases:{test:"boolean",extract:{oneOf:["string",{param:"noMatchDefault"}]},match:{arrayOf:"string"}}}};let rt;const at=/*#__PURE__*/new Set(["lazyElements","lazyEntries","race"]),ot=(e,n)=>{const{inputs:r}=n,a=e=>r.received[e]??F;if((e=>"string"==typeof e||Array.isArray(e)||"literal"in e)(e))return D(e);if("type"in e)return(e=>{const{type:t,min:n=-1/0,max:r=1/0}=e;return"number"===t||"integer"===t?ye({min:n,max:r,integer:"integer"===t}):[U({type:t},e.minLength)]})(e);if("sum"in e)return o=a(e.sum),H(ae(fe(te(o))),he(o),ve(o,e=>ye(ge(e,ce,be)),(e,t)=>{const n=de(e);if(void 0===n)return 0===t?ye(ce):F;const r=t>0;return ye({min:n.min>=0?r?n.min:0:-1/0,max:n.max<=0?r?n.max:0:1/0,integer:n.integer})}));var o;if("product"in e)return(e=>H(he(e),ve(e,e=>ye(ge(e,ue,xe)),(e,t)=>{const n=de(e);if(void 0===n)return 0===t?ye(ue):F;const r=n.min>=-1&&n.max<=1;return ye({min:n.min>=1?1:n.min>=0?0:r?-1:-1/0,max:r?1:1/0,integer:n.integer})})))(a(e.product));if("difference"in e)return((e,t)=>{const n=de(e),r=de(t);return ye(n&&r&&{min:n.min-r.max,max:n.max-r.min,integer:n.integer&&r.integer})})(...e.difference.map(a));if("abs"in e)return(e=>{const t=de(e);if(void 0===t)return F;const{min:n,max:r}=t;return ye(n>=0?t:r<=0?{...t,min:-r,max:-n}:{...t,min:0,max:Math.max(-n,r)})})(a(e.abs));if("min"in e)return ke(a(e.min),"min");if("max"in e)return ke(a(e.max),"max");if("param"in e){const r=e.param;if(Object.hasOwn(n.elements,r))return n.elements[r];const o=a(r),s=n.definition.parameters[r]?.evaluation??"eager";return at.has(s)?H(te(o),(e=>W(e.map(e=>"exact"in e?t(e.exact)?W(Object.values(e.exact).map(e=>z(e))):F:"object"!==e.type?F:void 0===e.keys?E:W(Object.values(e.keys)))))(o)):o}if("elementOf"in e)return te(a(e.elementOf));if("kindOf"in e)return ae(te(a(e.kindOf)));if("arrayOf"in e){const{arrayOf:t,minLength:r}=e,a="object"==typeof t&&"param"in t?n.items[t.param]:void 0;return void 0!==a?re(a):ne([ot(t,n)],r?{minLength:r}:{})}if("oneOf"in e)return W(e.oneOf.map(e=>ot(e,n)));if("typeNamedBy"in e){const t=e.typeNamedBy,a=r.received[t];if(void 0===a)return F;const o=L(a)??((e,t)=>{const n=e.definition.parameters[t]?.type;return"object"==typeof n&&"literal"in n?[...n.literal]:void 0})(n,t);return void 0===o?E:W(o.filter(e=>"string"==typeof e).map(e=>D(e)))}if("byParam"in e){const{cases:t,otherwise:a}=e,o=r.received[e.byParam],s=void 0===o?void 0:L(o),i=s?.map(e=>"string"==typeof e&&Object.hasOwn(t,e)?t[e]:a)??[...Object.values(t),a];return W(i.map(e=>void 0===e?F:ot(e,n)))}return(e=>W(e.map(e=>{const t="exact"in e?Array.isArray(e.exact)?Array.from(e.exact,e=>z(e)):void 0:"array"===e.type?e.items:void 0;if(void 0===t)return H(Y(te([e])),z(null));const n=[];for(const e of t)if(n.push(Y(e)),!V(e))return W(n);return W([...n,z(null)])})))(a(e.firstNonNull))},st=[{type:"nonFinite"}],it=(e,t,n,r,a={})=>{if("yes"===t.propagates)return{output:z(null)};const{definition:o}=e.entry,s=(e=>void 0!==e.analysis?e.analysis.output:(rt??=new Map(i.filter(e=>Object.hasOwn(nt,e.name)).map(e=>[e,nt[e.name]])),rt.get(e)))(o);let c=void 0!==s?ot(s,{definition:o,inputs:t,elements:n,items:a}):D(o.returns);return Object.values(t.received).some(e=>"no"!==oe(e))&&"no"!==Se(c,"number")&&(c=H(c,st)),"maybe"===t.propagates&&(c=H(c,z(null))),ct(e,c,r,"no"===t.propagates)},ct=(e,t,n,r)=>{const a=oe(t),o=n?a:oe(ut(t)),s=t.filter(e=>"exact"in e?"number"!=typeof e.exact||Number.isFinite(e.exact):"nonFinite"!==e.type);return"no"===o?{output:s}:{output:s,boundary:{path:e.path,code:"non-finite-result",message:`${e.name} – non-finite-result possible: a NaN or infinite number may reach its result`,certainty:0===s.length&&r?"always":"may",operator:e.name,order:[e.order]}}},ut=e=>e.filter(e=>!("type"in e&&"nonFinite"===e.type)),lt={unknown:!0},pt={fails:!0},mt=async(e,t,n,r,a=new Set)=>{if(a.has(e.entry.definition))return;const{parameters:o}=e.entry.definition,s=new Set(n.map(e=>e.param)),i=[];for(const[e,n]of Object.entries(t)){if(s.has(e))continue;const t=L(n);if(void 0===t)return;i.push({name:e,outcomes:t.map(e=>({value:e}))})}const c=n.map(e=>{const t=o[e.param],n=((e,t)=>{const{verdict:n,output:r}=e.result,a=void 0!==t.replacesNullAt;if("always"===n)return[a?lt:pt];const o=L(r);if(void 0===o)return[lt];const s=o.map(e=>({value:e}));return"no"===n?s:a?[lt]:[...s,pt]})(e,t);return{child:e,outcomes:"perElement"===t.evaluation&&void 0===e.at&&n.length>1?[lt]:n}}),u=()=>[...i,...c].reduce((e,{outcomes:t})=>e*t.length,1);if(u()>16)for(const e of c)e.outcomes.length>1&&(e.outcomes=[lt]);const l=u();if(l>16)return;const p=new Set,m=new Set,d=[];for(let n=0;n<l;n++){let o=n;const s=e=>{const t=e[o%e.length];return o=Math.floor(o/e.length),t},u={};for(const{name:e,outcomes:t}of i)u[e]=s(t).value;const l=new Map(c.map(({child:e,outcomes:t})=>[e,s(t)])),y=await bt(e,t,u,l,r,p,m,a);if(void 0===y)return;d.push(y)}const y=[],f=new Map,h=new Set,v=new Set;let g=0;for(const e of d)if("value"in e)y.push(z(e.value));else if("passed"in e){const{passed:t}=e;v.add(t),h.add(t),y.push(dt(t,o[t.param]))}else if(g++,"escaped"in e)h.add(e.escaped);else{const t=`${e.failure.code}|${e.failure.parameter??""}`,n=f.get(t)??{failure:e.failure,count:0};n.count++,f.set(t,n)}const b=[...f.values()].map(({failure:e,count:t})=>({...e,certainty:t===d.length?"always":"may"}));return{output:W(y),failures:b,reached:p,awaited:m,escaped:h,passed:v,fails:g===d.length}},dt=(e,t)=>void 0===e.at||"perElement"===t.evaluation?Je(t,e.result.output):t.truthiness?D("boolean"):e.result.output,yt=Symbol("stopped"),ft=new Promise(()=>{}),ht=e=>{const t=Promise.reject(e);return t.catch(()=>{}),t},vt={memo:(e,t)=>t()},gt={note:()=>{}},bt=async(e,t,n,r,a,o,i,c)=>{const l=e=>{o.add(e),i.add(e)},{definition:p}=e.entry,{parameters:m}=p,d={...t};for(const[e,t]of Object.entries(n))d[e]=z(t);for(const[e,t]of r)void 0!==m[e.param].replacesNullAt&&"value"in t&&(d[e.param]=z(t.value));const y=Le(e,d);for(const[e,t]of r){if("race"===m[e.param].evaluation&&o.add(e),y.consulted.has(e.param)){if(!("value"in t))return;l(e)}}const f=Qe(p),h=(t,n,r)=>{const o=r??("external"===f?void 0:f.find(n=>n.code===t&&void 0!==n.parameter&&"no"!==tt(e,n,y,a))?.parameter);return{failure:{path:e.path,code:t,message:n,certainty:"always",operator:e.name,...void 0!==o?{parameter:o}:{},order:[e.order]}}};if("null"===y.ends)return{value:null};if(void 0!==y.ends)return{failure:y.ends};const v=new Map,g=new Set,k=new Map,j=new Map;let O=!1,$=()=>{};const A=new Promise(e=>{$=()=>e(yt)});let N=!1;const S=()=>{N?$():O=!0},M=e=>{const t=new x({code:b.operatorFailure,message:"",path:[]});return k.set(t,e),t},P=(t,n)=>r=>{const a=void 0!==n.elementNullPolicy;if("yes"!==Se(z(r),n.type,n.constraints,a)){const n=new x({code:b.typeCheck,message:`${e.name} – parameter '${t}': fails its type check`,path:[]});throw j.set(n,t),n}return n.truthiness?De(r,n.type):r},F=e=>t=>e.truthiness?s(t):t,E=(e,t)=>{void 0!==e&&l(e);const n=void 0===e?lt:r.get(e);if("unknown"in n){const t=new Promise(()=>{});return void 0!==e&&v.set(t,e),S(),t}if("fails"in n)return ht(M(e));try{return Promise.resolve(t(n.value))}catch(e){return ht(e)}},q=e=>{let t;const n={evaluate:()=>t??=e()};return g.add(n),n},D=(e,t)=>{const n=({index:e,child:n,value:a})=>{if(void 0===n)return{index:e,ok:!0,value:t(a)};l(n);const o=r.get(n);if("fails"in o)return{index:e,ok:!1,error:M(n)};try{return{index:e,ok:!0,value:t(o.value)}}catch(t){return{index:e,ok:!1,error:t}}},a=e=>void 0!==e.child&&"unknown"in r.get(e.child),o={length:e.length,async*[Symbol.asyncIterator](){for(const t of e)a(t)||(yield n(t));e.some(a)&&(S(),await ft)}};return g.add(o),o},J=(e,t)=>{const n=F(t);switch(t.evaluation){case"lazyElements":return e.map(e=>q(()=>Promise.resolve(n(e))));case"race":return D(e.map((e,t)=>({index:t,value:e})),n);case"lazyEntries":{const t={};for(const[r,a]of Object.entries(e))t[r]=q(()=>Promise.resolve(n(a)));return t}case"lazy":return q(()=>Promise.resolve(e));default:return e}},B=new Map;for(const e of r.keys())B.set(e.param,[...B.get(e.param)??[],e]);const I={};for(const[e,t]of Object.entries(m)){if("perElement"===t.evaluation||void 0!==t.replacesNullAt)continue;const n=B.get(e);if(void 0!==n){const r=F(t);if("lazy"===t.evaluation)I[e]=q(()=>E(n[0],P(e,t)));else if("race"===t.evaluation)I[e]=D(n.map((e,t)=>({index:t,child:e})),r);else if("lazyElements"===t.evaluation)I[e]=n.map(e=>q(()=>E(e,r)));else{const t={};for(const e of n)t[String(e.at)]=q(()=>E(e,r));I[e]=t}continue}const r=y.received[e];if(void 0===r)continue;const a=L(r);if(void 0===a||1!==a.length)return;I[e]=J(a[0],t)}for(const[t,n]of p.resolution.perElement){if(void 0===e.params[t]||void 0===n.over)continue;const r=B.get(t)??[],a=I[n.over],s=Array.isArray(a)?a:[],i=1===r.length&&void 0===r[0].at;if(!i&&r.length!==s.length)return;const c=e=>r[i?e>=0&&e<s.length?0:-1:e],u=P(t,n),l=new Map,p={evaluate:e=>{let t=l.get(e);return void 0===t&&l.set(e,t=E(c(e),u)),t},settle:()=>{const e=s.map((e,t)=>({index:t,child:c(t)}));for(const{child:t}of e)o.add(t);return D(e,u)}};g.add(p),I[t]=p}const C={options:a.evaluation,get signal(){return(new AbortController).signal},cache:vt,trace:gt},T=t=>{const n=k.get(t);if(void 0!==n)return{escaped:n};if(w(t))return h(t.code,t.message,j.get(t));const r=`${e.name} – ${t instanceof Error?t.message:String(t)}`;return h((u(t)?t.code:void 0)??b.operatorFailure,r)};let R;try{R=p.evaluate(I,C)}catch(e){return T(e)}if(W=R,"function"==typeof W?.then){const e=v.get(R);if(void 0!==e)return{passed:e};if(O)return;N=!0;const t=setTimeout(()=>{c.add(p),$()},100),n=await Promise.race([Promise.resolve(R).then(e=>({value:e}),e=>({error:e})),A]);if(clearTimeout(t),n===yt)return;if("error"in n)return T(n.error);R=n.value}var W;return void 0===R?{value:null}:"number"!=typeof R||Number.isFinite(R)?g.has(R)?h(b.escapedHandle,`${e.name} – returned a lazy handle instead of evaluating it`):{value:R}:h(b.nonFiniteResult,`${e.name} – produced a non-finite number (${String(R)})`)},wt=(e,t)=>void 0===t?e.scope:{vars:t,at:e,known:new Map},xt={verdict:"no",escapes:[],output:F},kt={result:xt,covered:[]},jt=[{type:"integer",min:0}],Ot=z(null),$t=[{type:"object"}],At=se(Object.fromEntries(Object.entries(k).map(([e,t])=>[e,D(t)]))),Nt=e=>{if(0===e.length)return $t;const{value:t,found:n}=ie(At,e);return"yes"===n?t:H(t,Ot)},St=({value:e,reads:t=[]},n=0)=>{if(0===t.length)return z(e);const r=t.find(({at:e})=>e.length===n);if(void 0!==r)return Nt(r.segments);const a=e,o=e=>St({value:a[e],reads:t.filter(({at:t})=>t[n]===e)},n+1);return Array.isArray(e)?re(e.map((e,t)=>o(t))):se(Object.fromEntries(Object.keys(a).map(e=>[e,o(e)])))},Mt=(e,t)=>{for(const n of t)e.push(n)},Pt=(e,t,n)=>{const r=[...e];for(const e of t)Mt(r,e.result.escapes);const a=t.some(e=>e.result.waits);return t.some(e=>e.eager&&"always"===e.result.verdict)||e.some(e=>!j(e)&&"always"===e.certainty)?{verdict:"always",escapes:r,output:F,waits:a}:{verdict:r.length>0?"may":"no",escapes:r,output:n,waits:a}},Ft=e=>`${e.order}|${e.code}|${e.parameter}`,Et=e=>{const t=e.map(e=>new Set([...e.result.escapes,...e.covered.map(({pending:e})=>e)].filter(e=>!j(e)&&"always"===e.certainty).map(e=>Ft(e)))),n=e=>j(e)||"may"===e.certainty||t.every(t=>t.has(Ft(e)))?e:{...e,certainty:"may"};for(const t of e)t.result={...t.result,escapes:t.result.escapes.map(n)},t.covered=t.covered.map(({pending:e,by:t})=>({pending:n(e),by:t}))};class zt{options;bodies=new Map;stalled=new Set;waiting=new Set;strict;constructor(e){this.options=e,this.strict=!0===e.evaluation.strictDataPaths}root(e,t){return this.walk(e,{scope:null,bindings:null,sink:t,frame:{},walks:1})}async walk(e,t){const n=await this.visit(e,t);return n.waits&&this.waiting.add(e),n}async visit(e,t){switch(e.kind){case"constant":return{...xt,output:z(e.value)};case"invalid":throw Lt("an invalid node");case"reference":return this.reference(e,t);case"skeleton":{const n={...t,scope:wt(t,e.vars)},r=[];for(const t of e.holes)r.push({result:await this.walk(t.node,n),eager:!0});const a=((e,t)=>{if(t.every(e=>1===e.length&&"exact"in e[0]))return z(m(e.skeleton,e.holes,t.map(e=>e[0].exact)));const n=e.holes.map((e,n)=>({at:e.at,output:t[n]})),r=(e,t,n)=>{const a=n.find(e=>e.at.length===t);if(void 0!==a)return a.output;if(0===n.length)return z(e);const o=new Map;for(const e of n){const n=o.get(e.at[t]);void 0===n?o.set(e.at[t],[e]):n.push(e)}const s=e=>o.get(e)??[];if(Array.isArray(e))return re(Array.from(e,(e,n)=>r(e,t+1,s(n))));const i=e,c=new Set([...Object.keys(i),...n.map(e=>String(e.at[t]))]),u={};for(const e of c)u[e]=r(i[e],t+1,s(e));return se(u)};return r(e.skeleton,0,n)})(e,r.map(e=>e.result.output));return Pt([],r,a)}case"elements":case"entries":{const n=[],r=await this.container("",e,t,n);for(const e of n)Mt(t.sink,e.covered);const a=n.map(({result:e})=>({result:e,eager:!1}));return Pt([],a,r)}case"operator":return this.operator(e,t);case"fragmentCall":return this.call(e,t)}return e}async operator(e,t){const{definition:n}=e.entry,r={...t,scope:wt(t,e.vars)},a={},o=[],s=[];for(const[t,i]of Object.entries(e.params)){const e=n.parameters[t]?.evaluation;if("perElement"!==e)if("elements"===i.kind||"entries"===i.kind)a[t]=await this.container(t,i,r,s);else if("lazy"===e){const e=await this.apart(t,i,r);a[t]=e.result.output,s.push(e)}else{const e=await this.walk(i,r);a[t]=e.output,o.push({result:e,eager:!0})}}const i=Le(e,a),c=l(e),u={},p={};for(const[a,o]of n.resolution.perElement){const n=e.params[a];if(void 0===n||void 0===o.over)continue;const l=i.received[o.over]??F,m=L(l),d=1===m?.length&&Array.isArray(m[0])?m[0]:void 0,y=t.walks*(d?.length??1/0);if(y<=16){const e=[];for(const[o,i]of Array.from(d).entries()){const u={as:c,element:z(i),index:z(o),parent:t.bindings},l=await this.apart(a,n,{...r,bindings:u,walks:y},o);s.push(l),e.push(l.result.output)}p[a]=e,u[a]=W(e)}else{const e={as:c,element:te(l),index:jt,parent:t.bindings},o=await this.apart(a,n,{...r,bindings:e});s.push(o),u[a]=o.result.output}}const m=o.some(e=>"always"===e.result.verdict)?{output:F,failures:[],reached:new Set(s.filter(e=>"race"===n.parameters[e.param].evaluation)),awaited:new Set,escaped:new Set,passed:new Set,fails:!0}:"external"===Qe(n)?void 0:await mt(e,a,s,this.options,this.stalled);for(const e of Object.keys(p))Et(s.filter(t=>t.param===e&&(m?.reached.has(t)??!0)));const d=[];void 0===m?(Mt(d,i.failures),"yes"!==i.propagates&&Mt(d,((e,t,n)=>{const r=Qe(e.entry.definition),a={path:e.path,operator:e.name,order:[e.order]};if("external"===r)return[{...a,code:Re,message:`${e.name} – may fail whatever its inputs: nothing describes what it fails on`,certainty:"may"}];const o=[];for(const s of r){const r=tt(e,s,t,n);"no"!==r&&o.push({...a,code:s.code,message:et(e.name,s),certainty:"yes"!==r||s.may||s.overflow||"no"!==t.propagates?"may":"always",...void 0!==s.parameter?{parameter:s.parameter}:{}})}return o})(e,i,this.options))):Mt(d,m.failures);for(const t of s){if(void 0!==m&&!m.passed.has(t))continue;const r=n.parameters[t.param];if("perElement"===r.evaluation){const n=Ie(e,t.param,r,t.result.output);void 0!==n&&d.push(n)}else void 0!==m&&void 0===t.at&&Mt(d,i.failures.filter(e=>e.parameter===t.param))}const{output:y,boundary:f}=void 0===m?it(e,i,u,this.options.strictNumbers,p):ct(e,m.output,this.options.strictNumbers,!1);void 0===f||d.some(e=>!j(e)&&e.code===f.code)||d.push(f);for(const e of s){if(void 0!==m&&!m.reached.has(e))continue;Mt(t.sink,e.covered);const n=void 0===m||m.escaped.has(e)?e.result.escapes:e.result.escapes.filter(j),r=e.result.waits&&(m?.awaited.has(e)??!0);o.push({result:{...e.result,escapes:n,waits:r},eager:!1})}const h=Pt(d,o,y);return!0===m?.fails&&Object.assign(h,{verdict:"always",output:F}),(e=>void 0!==e.analysis||"external"===Qe(e))(n)&&(h.waits=!0),this.withFallback(e,h,r)}async apart(e,t,n,r){const a=[];return{param:e,...void 0!==r?{at:r}:{},result:await this.walk(t,{...n,sink:a}),covered:a}}async container(e,t,n,r){if("elements"===t.kind){const a=[];for(const[o,s]of t.nodes.entries()){const t=await this.apart(e,s,n,o);r.push(t),a.push(t.result.output)}return re(a)}const a={...n,scope:wt(n,t.vars)},o={};for(const[n,s]of Object.entries(t.entries)){const t=await this.apart(e,s,a,n);r.push(t),o[n]=t.result.output}return se(o)}async withFallback(e,t,n){if("no"===t.verdict)return t;const r="operator"===e.kind?e.entry.defaultFallback:void 0;if(void 0===e.fallback&&void 0===r)return t;const a={path:e.path};for(const e of t.escapes)n.sink.push({pending:e,by:a});const{waits:o}=t;if(void 0===e.fallback)return{...xt,output:H(t.output,St(r)),waits:o};const s=await this.walk(e.fallback,n);if(e.fallbackReadsError&&"no"!==s.verdict){const r={path:e.path,givesNull:!0};for(const e of s.escapes)n.sink.push({pending:e,by:r});return{...xt,output:H(t.output,s.output,Ot),waits:o||s.waits}}return{verdict:"always"===t.verdict||"always"!==s.verdict?s.verdict:"may",escapes:s.escapes,output:H(t.output,s.output),waits:o||s.waits}}async reference(e,t){const{segments:n,namespace:r}=e;switch(r){case"data":return this.drilled(e,E,n,[],[]);case"element":case"index":for(let a=t.bindings;null!==a;a=a.parent)if(p(a.as,r,e.binding))return"index"===r?{...xt,output:a.index}:this.drilled(e,a.element,n,[],[]);throw Lt(`an unresolved '${e.raw}'`);case"vars":{const r=await this.varDefinition(n[0],t);if(void 0===r)throw Lt(`an unresolved '${e.raw}'`);Mt(t.sink,r.covered);const a=[{result:r.result,eager:!0}];return this.drilled(e,r.result.output,n.slice(1),a,[])}case"params":{const{entry:r,params:a={}}=t.frame;if(void 0===r)throw Lt(`'${e.raw}' outside a fragment body`);const[o,...s]=n;if(void 0===o){const t=Object.keys(r.parameters).map(e=>({demand:e}));return this.drilled(e,se(a),[],[],t)}const i="string"==typeof o?a[o]??E:E;return this.drilled(e,i,s,[],[{demand:String(o)}])}case"error":return{...xt,output:Nt(n)}}return r}drilled(e,t,n,r,a){const{value:o,found:s}=ie(t,n);if("yes"===s)return Pt(a,r,o);if(!this.strict)return Pt(a,r,H(o,Ot));const i={path:e.path,code:"missing-data-path",message:`'${e.raw}' may be absent (strictDataPaths)`,certainty:"no"===s?"always":"may",order:[e.order]};return Pt([...a,i],r,o)}async varDefinition(e,t){for(let n=t.scope;null!==n;n=n.at.scope){if("string"!=typeof e||!Object.hasOwn(n.vars,e))continue;const t=n.known.get(e);if(void 0!==t)return t;n.known.set(e,{result:{...xt,output:E},covered:[]});const r=[],a={result:await this.walk(n.vars[e],{...n.at,scope:n,sink:r}),covered:r};return n.known.set(e,a),a}}async call(e,t){const{entry:n}=e;if(void 0===n)throw Lt(`a call to the unknown fragment '${e.name}'`);const r={...t,scope:wt(t,e.vars)},a=[],o=[],s={},i=new Map;if("static"===e.argumentsMode)for(const[t,a]of Object.entries(n.parameters)){const n=await this.argument(e,t,a,r);i.set(t,n),s[t]=n.result.output}else{const t=e.parameters,i=await this.walk(t,r);o.push({result:i,eager:!0}),Mt(a,Dt(e,n,t,s))}let c=!1;const u=e=>{const n=i.get(e)??kt;return Mt(t.sink,n.covered),c||=!0===n.result.waits,n},l=await this.body(n,s);for(const{pending:n,by:r}of l.covered){const a=$(r,e);if(j(n))for(const e of u(n.demand).result.escapes)t.sink.push({pending:e,by:a});else t.sink.push({pending:O(n,e),by:a})}const p=[];for(const t of l.result.escapes)j(t)?Mt(p,u(t.demand).result.escapes):p.push(O(t,e));return o.push({result:{...l.result,escapes:[]},eager:!0},{result:{...xt,escapes:p,waits:c},eager:!1}),this.withFallback(e,Pt(a,o,l.result.output),r)}async argument(e,t,n,r){const a=e.parameters?.[t];if(void 0===a)return{result:{...xt,output:z(n.default??null)},covered:[]};const o=[],s=await this.walk(a,{...r,sink:o}),{known:i,answer:c}=Be(n,s.output),u="yes"===c?[]:[qt(e,t,a.path,a.order)];return{result:Pt(u,[{result:s,eager:!0}],i),covered:o}}async body(e,t){const n=Object.keys(t).map(e=>`${e}=${T(t[e])}`).join(";");let r=this.bodies.get(e);void 0===r&&this.bodies.set(e,r=new Map);const a=r.get(n);if(void 0!==a)return a;r.set(n,{result:{...xt,output:E},covered:[]});const o=[],s={entry:e,params:t},i={result:await this.walk(e.body,{scope:null,bindings:null,sink:o,frame:s,walks:1}),covered:o};return r.set(n,i),i}}const Lt=e=>new Error(`[fig-tree internal] ${e} reached the coverage walk — the static gate should have refused it`),qt=(e,t,n,r)=>({path:n,code:"type-check",message:`fragment '${e.name}' – parameter '${t}': the argument may not fit the declared type`,certainty:"may",parameter:t,order:[r]}),Dt=(e,t,n,r)=>{const a=(t,r)=>({path:n.path,code:t,message:`fragment '${e.name}' – ${r}`,certainty:"may",order:[n.order]}),o=Object.entries(t.parameters);for(const[e,t]of o)r[e]=Be(t,E).known;const s=[a("type-check","'parameters' may not match the declared parameters")];return o.some(([,e])=>e.required)&&s.push(a("missing-required","'parameters' may omit a required parameter")),s},Jt=async(e,t,n)=>{if(!(e instanceof d))throw new TypeError("fallbackCoverage() takes a FigTree instance");const r=n?.strictNumbers??!1;if("boolean"!=typeof r)throw new x({code:b.invalidOptions,message:`'strictNumbers' must be a boolean, received ${JSON.stringify(r)}`,path:[]});const{artifact:a,options:o}=y(e.compile(t)),s=f(a,o).filter(e=>"error"===e.severity);if(s.length>0)return{uncovered:s.map(N),covered:[]};const i=new zt({strictNumbers:r,evaluation:o}),c=[],{escapes:u,waits:l}=await i.root(a.root,c),p=u.filter(e=>!j(e)).map(M);if(void 0!==o.timeout&&l)for(const{node:e,timeoutFallback:t}of a.holes){const n={path:e.path,code:"timeout",certainty:"may",order:[e.order]};a.timeoutShielded?i.waiting.has(e)&&c.push({pending:{...n,message:"may be cut off by the timeout, which puts its static fallback in its place"},by:{path:e.path}}):void 0===t&&p.push(M({...n,message:"the timeout may reject the evaluation: something in it can wait, and this value has no static fallback to shield it"}))}const m=c.flatMap(({pending:e,by:t})=>j(e)?[]:[P(e,t)]);return{uncovered:S(p),covered:S(m)}};export{Jt as fallbackCoverage};
1
+ import{t as e,i as t,c as n,a as r,n as a,b as s,d as o,N as i,e as c,f as u,v as l,g as m,h as p,j as y,r as d,k as f,s as h,F as v,l as g,m as b}from"../chunks/engine.js";import{i as w,r as x,W as k,E as j,a as O,F as N,b as $}from"../chunks/shared.js";const A=e=>"demand"in e,S=(t,n)=>({...t,path:n.path,...void 0===t.fragment?{fragment:n.name,fragmentPath:e(t.path)}:{},order:[n.order,...t.order]}),M=(t,n)=>void 0===t.fragmentPath?{...t,path:n.path,fragmentPath:e(t.path)}:{...t,path:n.path},P=t=>{const{code:n,message:r,certainty:a,operator:s,parameter:o,fragment:i,fragmentPath:c}=t;return{path:e(t.path),code:n,message:r,certainty:a,...void 0!==s?{operator:s}:{},...void 0!==o?{parameter:o}:{},...void 0!==i?{fragment:i,fragmentPath:c}:{}}},E=({path:e,code:t,message:n,operator:r,parameter:a})=>({path:[...e],code:t,message:n,certainty:"always",...void 0!==r?{operator:r}:{},...void 0!==a?{parameter:a}:{}}),z=e=>{const t=new Map;for(const{finding:n}of[...e].sort((e,t)=>((e,t)=>{for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e[n]-t[n];return e.length-t.length})(e.order,t.order))){const e=JSON.stringify({...n,message:void 0,certainty:void 0}),r=t.get(e);void 0===r?t.set(e,n):"always"===n.certainty&&(r.certainty="always")}return[...t.values()]},F=e=>({order:e.order,finding:P(e)}),L=(t,n)=>({order:t.order,finding:{...P(t),coveredBy:e(n.path),...void 0!==n.fragmentPath?{coveredByFragmentPath:n.fragmentPath}:{},...n.givesNull?{givesNull:n.givesNull}:{}}}),q=[],D=[{type:"string"},{type:"number"},{type:"boolean"},{type:"null"},{type:"array"},{type:"object"},{type:"opaque"},{type:"nan"},{type:"infinite"}],J=e=>[{exact:void 0===e?null:e}],B=e=>e.length>0&&e.every(e=>"exact"in e)?e.map(e=>e.exact):void 0,I=e=>"exact"in e?null===e.exact:"null"===e.type,C=e=>{if(w(e))return e.literal.map(e=>({exact:e}));const t="string"==typeof e?[e]:e;return t.includes("any")?D:Q(t.map(e=>[{type:e}]))},T=new WeakMap;let R=0;const W=e=>"object"==typeof e&&null!==e||"function"==typeof e?`=#${(e=>{let t=T.get(e);return void 0===t&&T.set(e,t=++R),t})(e)}`:`=${typeof e}:${String(e)}`,H=e=>{if("exact"in e)return W(e.exact);if("array"===e.type)return void 0!==e.items?`a[${e.items.map(G).join(";")}]`:`a${e.length??""}+${e.minLength??""}(${void 0===e.element?"*":G(e.element)})`;if("object"===e.type)return void 0===e.keys?"o":`o{${Object.keys(e.keys).sort().map(t=>`${JSON.stringify(t)}:${G(e.keys[t])}`).join(",")}}`;const{type:t,...n}=e;return`${t}${JSON.stringify(n)}`},G=e=>e.map(H).sort().join("|"),K=e=>{if(null===e)return{type:"null"};if(Array.isArray(e))return{type:"array"};switch(typeof e){case"string":return{type:"string"};case"number":return{type:Number.isInteger(e)?"integer":Number.isFinite(e)?"number":Number.isNaN(e)?"nan":"infinite"};case"boolean":return{type:"boolean"};case"object":{const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t?{type:"object"}:{type:"opaque"}}default:return{type:"opaque"}}},Q=e=>{const t=new Set,n=[];for(const r of e)for(const e of r){const r=H(e);t.has(r)||(t.add(r),n.push(e))}const r=n.filter(e=>"exact"in e).map(e=>e.exact);return r.length<=16?n:U(n.filter(e=>!("exact"in e)),Y(r))},U=(...e)=>Q(e),V=e=>"number"==typeof e&&Number.isFinite(e),X=e=>Array.from(e).length,Y=e=>{const t=(e,t)=>{if(0===t.length)return q;const n=t.reduce((e,t)=>Math.min(e,t));return[Z({type:e},n)]};return Q([...[!0,!1].map(t=>be(ve(e.map(e=>V(e)&&Number.isInteger(e)===t?fe(e):void 0)))),t("string",e.filter(e=>"string"==typeof e).map(X)),t("array",e.filter(Array.isArray).map(e=>e.length)),...e.filter(e=>!V(e)&&"string"!=typeof e&&!Array.isArray(e)).map(e=>[K(e)])])},Z=(e,t)=>t?{...e,minLength:t}:e,_=e=>e.some(I),ee=e=>e.length>0&&e.every(I),te=e=>e.filter(e=>!I(e)),ne=e=>Me(e.map(e=>{if("exact"in e){const{exact:n}=e;return(Array.isArray(n)?n:t(n)?Object.values(n):[]).includes(null)?"yes":"no"}return"array"===e.type?0!==e.length&&_(e.element??D)?"maybe":"no":"object"===e.type?"maybe":"no"})),re=(e,t)=>Q(e.map(e=>{if("no"===ne([e]))return[e];const n="exact"in e?e.exact:void 0;if(1===t.length&&"exact"in t[0]&&"exact"in e){const e=t[0].exact,r=t=>null===t?e:t;if(Array.isArray(n))return J(n.map(r));const a={};for(const[e,t]of Object.entries(n))a[e]=r(t);return J(a)}if(!(Array.isArray(n)||"type"in e&&"array"===e.type))return[{type:"object"}];const{length:r,minLength:a}=e;return oe([te(se([e])),t],Array.isArray(n)?{length:n.length}:{length:r,minLength:a})})),ae=e=>e.flatMap(e=>{const t=ne([e]);if("no"===t)return[e];if("yes"===t)return q;if(!("type"in e))return[e];if("array"!==e.type)return[e];const{items:n,...r}=e;if(void 0===n)return[{...r,element:te(e.element??D)}];const a=n.map(te);return a.some(e=>0===e.length)?q:ie(a)}),se=e=>Q(e.map(e=>"exact"in e?Array.isArray(e.exact)?Q(Array.from(e.exact,e=>J(e))):q:"array"===e.type?0===e.length?q:e.element??D:q)),oe=(e,t={})=>[{type:"array",element:Q(e),...t}],ie=e=>[{type:"array",element:Q(e),length:e.length,items:e}],ce=e=>U(e.map(e=>"exact"in e?K(e.exact):e)),ue=e=>Se(e.map(e=>"exact"in e?"number"!=typeof e.exact||Number.isFinite(e.exact)?"no":"yes":"nan"===e.type||"infinite"===e.type?"maybe":"no")),le=e=>Se(e.map(e=>"exact"in e?Number.isNaN(e.exact)?"yes":"no":"nan"===e.type?"maybe":"no")),me=e=>[{type:"object",keys:e}],pe=(e,t)=>{if(0===t.length)return{value:e,found:"yes"};const[n,...r]=t;let a;const s=[],o=Me(e.map(e=>{if("exact"in e){const n=x(e.exact,t);return n.found&&s.push(J(n.value)),n.found?"yes":"no"}const o=(e,t)=>{if("no"===t)return"no";const n=(e=>e===D?a??=pe(D,r):pe(e,r))(e);return s.push(n.value),"yes"===t?n.found:"no"===n.found?"no":"maybe"};if(n===k)return"array"!==e.type?"no":(s.push(0===r.length?[e]:[{type:"array"}]),"yes");switch(e.type){case"array":{const t="number"==typeof n?n:Number(n);if(!Number.isInteger(t)||t<0)return"number"==typeof n?"no":"maybe";const r=void 0!==e.length?t<e.length?"yes":"no":t<(e.minLength??0)?"yes":"maybe";return void 0!==e.items&&"yes"===r?o(e.items[t],"yes"):o(e.element??D,r)}case"object":return void 0===e.keys?o(D,"maybe"):Object.hasOwn(e.keys,String(n))?o(e.keys[String(n)],"yes"):"no";case"opaque":return o(D,"maybe");default:return"no"}}));return{value:Q(s),found:0===e.length?"yes":o}},ye={min:0,max:0,integer:!0},de={min:1,max:1,integer:!0},fe=e=>({min:e,max:e,integer:Number.isInteger(e)}),he=e=>"exact"in e?V(e.exact)?fe(e.exact):void 0:"number"===e.type||"integer"===e.type?{min:e.min??-1/0,max:e.max??1/0,integer:"integer"===e.type}:void 0,ve=e=>e.reduce((e,t)=>void 0===e||void 0===t?e??t:{min:Math.min(e.min,t.min),max:Math.max(e.max,t.max),integer:e.integer&&t.integer},void 0),ge=e=>ve(e.map(he)),be=e=>{if(void 0===e)return q;const t=e.integer?Math.ceil(e.min):e.min,n=e.integer?Math.floor(e.max):e.max;return t>n?q:[{type:e.integer?"integer":"number",...t>-1/0?{min:t}:{},...n<1/0?{max:n}:{}}]},we=e=>e.filter(e=>"exact"in e?"number"!=typeof e.exact:!["number","integer","nan","infinite"].includes(e.type)),xe=e=>se(e).filter(e=>"no"!==ue([e])),ke=(e,t,n)=>Q(e.map(e=>"exact"in e?Array.isArray(e.exact)?t(Array.from(e.exact,e=>J(e))):q:"array"!==e.type?q:void 0!==e.items?t(e.items):0===e.length?n(q,0):n(e.element??D,e.length??e.minLength??0))),je=(e,t,n)=>e.reduce((e,t)=>{const r=ge(t);return e&&r&&n(e,r)},t),Oe=(e,t)=>({min:e.min+t.min,max:e.max+t.max,integer:e.integer&&t.integer}),Ne=(e,t)=>0===e||0===t?0:e*t,$e=(e,t)=>{const n=[Ne(e.min,t.min),Ne(e.min,t.max),Ne(e.max,t.min),Ne(e.max,t.max)];return{min:Math.min(...n),max:Math.max(...n),integer:e.integer&&t.integer}},Ae=(e,t)=>U(we(se(e)),xe(e),ke(e,e=>{const n=e.map(ge);if(e.some(e=>"no"!==ue(e)))return be(ve(n));if(0===n.length||n.includes(void 0))return q;const r="min"===t?Math.min:Math.max;return be({min:n.map(e=>e.min).reduce((e,t)=>r(e,t)),max:n.map(e=>e.max).reduce((e,t)=>r(e,t)),integer:n.every(e=>e.integer)})},e=>be(ge(e)))),Se=e=>e.includes("yes")?"yes":e.includes("maybe")?"maybe":"no",Me=e=>e.every(e=>"yes"===e)?"yes":e.every(e=>"no"===e)?"no":"maybe",Pe=(e,t)=>"no"===e||"no"===t?"no":"yes"===e&&"yes"===t?"yes":"maybe",Ee=(e,t)=>{if("exact"in e)return ze([e.exact],t);if("object"!==e.type)return"no";if(void 0===e.keys)return"maybe";const n=e.keys;return Me(Object.entries(t).map(([e,t])=>{if(!Object.hasOwn(n,e))return!1===t.required?"yes":"no";const r=void 0===t.type?"yes":Fe(n[e],t.type);return void 0===t.constraints?r:Pe(r,Fe(n[e],"any",t.constraints))}))},ze=(e,t)=>r(e,{elementShape:t},!1).ok?"yes":"no",Fe=(e,t,a,s=!1)=>Me(e.map(e=>{if("exact"in e){const o=e.exact;return n(o,t).ok&&(null===o||void 0===a||r(o,a,s).ok)?"yes":"no"}const o=((e,t)=>{if(w(t)){const n=t=>{const n=he(e);return void 0!==n?"number"==typeof t&&(!n.integer||Number.isInteger(t))&&t>=n.min&&t<=n.max:"string"===e.type?"string"==typeof t&&X(t)>=(e.minLength??0):typeof t===e.type};return t.literal.some(n)?"maybe":"no"}const n="string"==typeof t?[t]:t;if(n.includes("any"))return"yes";switch(e.type){case"number":return n.includes("number")?"yes":n.includes("integer")?"maybe":"no";case"integer":return n.includes("integer")||n.includes("number")?"yes":"no";case"opaque":return n.includes("object")?"maybe":"no";case"infinite":return n.includes("number")?"yes":"no";case"nan":return"no";default:return n.includes(e.type)?"yes":"no"}})(e,t);return"no"===o||void 0===a||"null"===e.type?o:Pe(o,((e,t,n)=>{if(0===Object.keys(t).filter(e=>void 0!==t[e]).length)return"yes";if("array"!==e.type)return"no";let r="yes";void 0!==t.length&&(r=Pe(r,void 0===e.length?"maybe":e.length===t.length?"yes":"no"));const a=0===e.length?q:e.element??D,s=n?te(a):a;return void 0!==t.homogeneous&&(r=Pe(r,0===s.length||t.homogeneous.some(e=>"yes"===Fe(s,e))?"yes":"maybe")),void 0!==t.elementShape&&(r=Pe(r,s.every(e=>"yes"===Ee(e,t.elementShape))?"yes":"maybe")),r})(e,a,s))})),Le=(e,t)=>"yes"===Fe(e,t)?e:Q(e.map(e=>"no"===Fe([e],t)?q:"exact"in e?[e]:w(t)?t.literal.filter(t=>"no"!==Fe([e],{literal:[t]})).map(e=>({exact:e})):"number"===e.type?be({...he(e),integer:!0}):[e])),qe=e=>"string"==typeof e?e:Array.isArray(e)?e.join(" | "):`one of ${e.literal.map(e=>JSON.stringify(e)).join(", ")}`,De=(e,t,n)=>{const r=o(e.entry,t,n);if(r!==i)return"symbol"==typeof r?D:J(r)},Je=(e,t)=>"lazyEntries"===e.evaluation?"entries"===t.kind:"elements"===t.kind,Be=(e,t)=>{const n=e.nullPolicy;if("string"==typeof n)return new Set([n]);const r=t[n.selector]?.known??q,a=r.every(e=>"exact"in e)?n.table.filter(e=>r.some(t=>"exact"in t&&t.exact===e.value)):n.table;return new Set(a.map(e=>e.policy))},Ie=(e,t)=>{const{definition:n}=e.entry,{entries:r,whole:o}=n.resolution,i={},c=new Set,u=[],l={},m=new Set,p={},y=new Set;let d,f="no";const h=(t,n,r,a)=>{const s=Fe(r,n.type,n.constraints,void 0!==n.elementNullPolicy);if("yes"===s)return;const o={path:e.path,code:"type-check",message:`${e.name} – parameter '${t}': may receive something other than ${qe(n.type)}${void 0!==n.constraints?", as constrained":""}`,certainty:"no"===s&&a?"always":"may",operator:e.name,parameter:t,order:[e.order]};u.push(o),"no"===s&&a&&(d??=o)};for(const[n,a]of r){const r=e.params[n];switch(a.evaluation){case"eager":void 0!==r&&(l[n]={known:t[n],absent:!1});break;case"structural":"constant"===r?.kind&&(l[n]={known:J(r.value),absent:!1});break;case"lazy":if(void 0!==a.replacesNullAt){const s=void 0!==r?t[n]:De(e,n,a);if(void 0!==s)for(const e of a.replacesNullAt)p[e]={name:n,known:s}}else void 0!==r&&(m.add(n),h(n,a,t[n],!1),i[n]=Le(t[n],a.type));break;case"lazyElements":case"lazyEntries":case"race":if(void 0===r)break;Je(a,r)?(m.add(n),i[n]=t[n]):l[n]={known:t[n],absent:!1}}}for(const[t,n]of o){if(m.has(t))continue;const r=l[t]??{known:q,absent:!0},s=a(n)&&_(r.known);if(!r.absent&&!s)continue;const o=De(e,t,n),i=s?te(r.known):r.known;l[t]={known:void 0===o?i:U(i,o),absent:void 0===o}}for(const[e,t]of o){if(m.has(e))continue;let n=l[e]?.known??q;if(0===n.length)continue;l[e].absent&&c.add(e);const r=p[e];if(void 0!==r){(void 0!==t.elementNullPolicy?"no"!==ne(n):_(n))&&(y.add(r.name),n=void 0!==t.elementNullPolicy?re(n,r.known):U(te(n),r.known))}const a="eager"!==t.evaluation&&"structural"!==t.evaluation;if(_(n)&&s(t.type)&&!a){const e=Be(t,l);if(e.has("propagate")){const t=1===e.size&&ee(n);if(f=t?"yes":"maybe",t){d??="null";break}1===e.size&&(n=te(n))}}if("propagate"===t.elementNullPolicy){const e=ne(n);if("no"!==e){if(f="yes"===e?"yes":"maybe","yes"===e){d??="null";break}n=ae(n)}}h(e,t,n,!0),i[e]=Re(t,n)}if("no"!==f)for(const e of u)"always"===e.certainty&&(e.certainty="may");return{received:i,absent:c,failures:u,propagates:f,consulted:y,...d?{ends:d}:{}}},Ce=e=>{const t="string"==typeof e?[e]:Array.isArray(e)?e:[];return t.length>0&&t.every(e=>"array"===e||"object"===e)},Te=(e,n)=>{if(Ce(n)){if(Array.isArray(e))return e.map(c);if(t(e)){const t={};for(const[n,r]of Object.entries(e))t[n]=c(r);return t}}return c(e)},Re=(e,t)=>{const n=Le(t,e.type);return e.truthiness?n.length>0&&n.every(e=>"exact"in e)?Q(n.map(t=>J(Te(t.exact,e.type)))):Ce(e.type)?D:C("boolean"):n},We=(e,t)=>{const n=a(e)&&_(t),r=n?te(t):t;let s=Fe(r,e.type,e.constraints);"yes"===s&&void 0!==e.constraints&&_(r)&&(s="maybe");const o=n?J(e.default??null):q;return{known:U(Le(r,e.type),o),answer:s}},He=(e,t,n,r)=>{if("yes"!==Fe(r,n.type,n.constraints))return{path:e.path,code:"type-check",message:`${e.name} – parameter '${t}': an element's result may be other than ${qe(n.type)}`,certainty:"may",operator:e.name,parameter:t,order:[e.order]}},Ge="non-finite-result",Ke="empty-aggregate",Qe="operator-failure",Ue={code:Ge,overflow:!0},Ve=e=>({code:"type-check",parameter:"values",when:{expect:e,values:{some:{not:{type:e}}}}}),Xe={plus:[{code:Ke,parameter:"values",when:{values:{empty:!0},expect:{supplied:!1}}},Ve("number"),Ve("string"),Ve("array"),Ve("object"),Ue],subtract:[Ue],multiply:[Ue],divide:[{code:Ge,parameter:"by",when:{by:0}},Ue],modulo:[{code:Ge,parameter:"mod",when:{mod:0}},Ue],power:[{code:Ge,parameter:"base",when:{base:0,exponent:{below:0}}},{code:Ge,parameter:"base",may:!0,when:{base:{below:0},exponent:{not:{type:"integer"}}}},{code:Ge,parameter:"exponent",may:!0,when:{exponent:{not:{below:100}}}},Ue],round:[{code:Ge,parameter:"decimals",may:!0,when:{decimals:{not:{below:300}}}},Ue],min:[{code:Ke,parameter:"values",when:{values:{empty:!0}}}],max:[{code:Ke,parameter:"values",when:{values:{empty:!0}}}],match:[{code:Qe,may:!0,when:{default:{supplied:!1}}}],regex:[{code:Qe,parameter:"flags",when:{flags:{invalid:!0}}},{code:Qe,parameter:"pattern",when:{pattern:{invalid:!0}}}],get:[{code:Qe,parameter:"path",when:{path:{invalid:!0}}},{code:"missing-data-path",may:!0,options:{strictDataPaths:!0},when:{default:{supplied:!1}}}],convert:[{code:Qe,when:{to:"number",value:{type:["array","object"]}}},{code:Qe,may:!0,when:{to:"number",value:{type:"string"}}},{code:Ge,may:!0,when:{to:"number",value:{type:"string"}}},{code:Qe,when:{to:"string",value:{type:["array","object"]}}}]};let Ye;const Ze=e=>{const t=e.analysis;return void 0!==t?t.external?"external":t.failures??[]:(Ye??=new Map(u.map(e=>[e,Xe[e.name]??[]])),Ye.get(e)??"external")},_e=e=>"yes"===e?"no":"no"===e?"yes":"maybe",et=(e,n)=>{if(null===e||"object"!=typeof e){if("exact"in n)return n.exact===e?"yes":"no";return"no"===Fe([n],null===e?"null":{literal:[e]})?"no":"maybe"}if("type"in e)return Fe([n],e.type);if("not"in e)return _e(et(e.not,n));if("below"in e)return"exact"in n?"number"==typeof n.exact&&n.exact<e.below?"yes":"no":"number"===n.type||"integer"===n.type?(n.max??1/0)<e.below?"yes":(n.min??-1/0)>=e.below?"no":"maybe":"infinite"===n.type?"maybe":"no";if("empty"in e){if("exact"in n){const{exact:e}=n;return"string"==typeof e||Array.isArray(e)?0===e.length?"yes":"no":t(e)&&0===Object.keys(e).length?"yes":"no"}switch(n.type){case"array":return void 0!==n.length?0===n.length?"yes":"no":n.minLength?"no":"maybe";case"object":return void 0===n.keys?"maybe":0===Object.keys(n.keys).length?"yes":"no";case"string":return n.minLength?"no":"maybe";default:return"no"}}if("some"in e){if("exact"in n){const{exact:r}=n,a=Array.isArray(r)?Array.from(r):t(r)?Object.values(r):[];return Se(a.map(t=>et(e.some,{exact:t??null})))}if("array"===n.type){if(0===n.length)return"no";const t=tt(e.some,n.element??D);return"yes"!==t||void 0===n.length&&!n.minLength?"no"===t?"no":"maybe":"yes"}return"object"===n.type?void 0===n.keys?"maybe":Se(Object.values(n.keys).map(t=>"no"===tt(e.some,t)?"no":"maybe")):"no"}return"maybe"},tt=(e,t)=>0===t.length?"no":Me(t.map(t=>et(e,t))),nt=e=>void 0!==e&&1===e.length&&"exact"in e[0]?{value:e[0].exact}:void 0,rt=(e,t,n,r)=>{const a=r.received[t],s=void 0===a?"no":r.absent.has(t)?"maybe":"yes";return null!==n&&"object"==typeof n&&"supplied"in n?n.supplied?s:_e(s):"no"===s?"no":null!==n&&"object"==typeof n&&"invalid"in n?((e,t,n)=>{const{validate:r}=e.entry.definition;if(void 0===r)return"no";if(void 0===nt(n.received[t]))return"maybe";const a={};for(const[e,t]of Object.entries(n.received)){const r=nt(t);void 0===r||n.absent.has(e)||(a[e]=r.value)}return r(a,l,m(e)).some(e=>"error"===e.severity&&e.parameter===t)?"yes":"no"})(e,t,r):tt(n,a)},at=e=>null===e||"object"!=typeof e?JSON.stringify(e):"type"in e?"string"==typeof e.type?`a ${e.type}`:`of type ${JSON.stringify(e.type)}`:"not"in e?`not ${at(e.not)}`:"below"in e?`below ${e.below}`:"empty"in e?"empty":"supplied"in e?e.supplied?"supplied":"not supplied":"invalid"in e?"refused by its validation":`with some element ${at(e.some)}`,st=(e,t)=>{const n=Object.entries(t.when??{}).map(([e,t])=>null!==t&&"object"==typeof t&&"some"in t?`some element of '${e}' is ${at(t.some)}`:`'${e}' is ${at(t)}`),r=n.length>0?`when ${n.join(" and ")}`:t.overflow?"on extreme numbers":"whatever its inputs";return`${e} – ${t.code} ${t.may?"possible ":""}${r}`},ot=(e,t)=>Object.values(e.received).some(e=>((e,t)=>[...e,...se(e)].some(e=>{return"exact"in e?(n=e.exact)===1/0||n===-1/0:t&&"infinite"===e.type;var n}))(e,t)),it=(e,t,n,r)=>{if(t.overflow&&!r.strictNumbers&&!ot(n,!1))return"no";for(const[e,n]of Object.entries(t.options??{}))if((r.evaluation[e]??!1)!==n)return"no";const a=Object.entries(t.when??{}).map(([t,r])=>rt(e,t,r,n));return a.includes("no")?"no":a.every(e=>"yes"===e)?"yes":"maybe"},ct={if:{oneOf:[{param:"then"},{param:"else"}]},match:{oneOf:[{param:"branches"},{param:"default"}]},firstNonNull:{firstNonNull:"values"},find:{oneOf:[{elementOf:"input"},{param:"noMatchDefault"}]},plus:{oneOf:[{sum:"values"},{typeNamedBy:"expect"}]},subtract:{difference:["value","minus"]},multiply:{product:"values"},abs:{abs:"value"},min:{min:"values"},max:{max:"values"},length:{type:"integer",min:0},filter:{arrayOf:{elementOf:"input"}},map:{arrayOf:{param:"each"}},split:{byParam:"delimiter",cases:{"":{arrayOf:"string"}},otherwise:{arrayOf:"string",minLength:1}},convert:{typeNamedBy:"to"},regex:{byParam:"mode",cases:{test:"boolean",extract:{oneOf:["string",{param:"noMatchDefault"}]},match:{arrayOf:"string"},replace:"string"}}};let ut;const lt=/*#__PURE__*/new Set(["lazyElements","lazyEntries","race"]),mt=(e,n)=>{const{inputs:r}=n,a=e=>r.received[e]??q;if((e=>"string"==typeof e||Array.isArray(e)||"literal"in e)(e))return C(e);if("type"in e)return(e=>{const{type:t,min:n=-1/0,max:r=1/0}=e;return"number"===t||"integer"===t?be({min:n,max:r,integer:"integer"===t}):[Z({type:t},e.minLength)]})(e);if("sum"in e)return s=a(e.sum),U(ce(we(se(s))),xe(s),ke(s,e=>be(je(e,ye,Oe)),(e,t)=>{const n=ge(e);if(void 0===n)return 0===t?be(ye):q;const r=t>0;return be({min:n.min>=0?r?n.min:0:-1/0,max:n.max<=0?r?n.max:0:1/0,integer:n.integer})}));var s;if("product"in e)return(e=>U(xe(e),ke(e,e=>be(je(e,de,$e)),(e,t)=>{const n=ge(e);if(void 0===n)return 0===t?be(de):q;const r=n.min>=-1&&n.max<=1;return be({min:n.min>=1?1:n.min>=0?0:r?-1:-1/0,max:r?1:1/0,integer:n.integer})})))(a(e.product));if("difference"in e)return((e,t)=>{const n=ge(e),r=ge(t);return be(n&&r&&{min:n.min-r.max,max:n.max-r.min,integer:n.integer&&r.integer})})(...e.difference.map(a));if("abs"in e)return(e=>{const t=ge(e);if(void 0===t)return q;const{min:n,max:r}=t;return be(n>=0?t:r<=0?{...t,min:-r,max:-n}:{...t,min:0,max:Math.max(-n,r)})})(a(e.abs));if("min"in e)return Ae(a(e.min),"min");if("max"in e)return Ae(a(e.max),"max");if("param"in e){const r=e.param;if(Object.hasOwn(n.elements,r))return n.elements[r];const s=a(r),o=n.definition.parameters[r]?.evaluation??"eager";return lt.has(o)?U(se(s),(e=>Q(e.map(e=>"exact"in e?t(e.exact)?Q(Object.values(e.exact).map(e=>J(e))):q:"object"!==e.type?q:void 0===e.keys?D:Q(Object.values(e.keys)))))(s)):s}if("elementOf"in e)return se(a(e.elementOf));if("kindOf"in e)return ce(se(a(e.kindOf)));if("arrayOf"in e){const{arrayOf:t,minLength:r}=e,a="object"==typeof t&&"param"in t?n.items[t.param]:void 0;return void 0!==a?ie(a):oe([mt(t,n)],r?{minLength:r}:{})}if("oneOf"in e)return Q(e.oneOf.map(e=>mt(e,n)));if("typeNamedBy"in e){const t=e.typeNamedBy,a=r.received[t];if(void 0===a)return q;const s=B(a)??((e,t)=>{const n=e.definition.parameters[t]?.type;return"object"==typeof n&&"literal"in n?[...n.literal]:void 0})(n,t);return void 0===s?D:Q(s.filter(e=>"string"==typeof e).map(e=>C(e)))}if("byParam"in e){const{cases:t,otherwise:a}=e,s=r.received[e.byParam],o=void 0===s?void 0:B(s),i=o?.map(e=>"string"==typeof e&&Object.hasOwn(t,e)?t[e]:a)??[...Object.values(t),a];return Q(i.map(e=>void 0===e?q:mt(e,n)))}return(e=>Q(e.map(e=>{const t="exact"in e?Array.isArray(e.exact)?Array.from(e.exact,e=>J(e)):void 0:"array"===e.type?e.items:void 0;if(void 0===t)return U(te(se([e])),J(null));const n=[];for(const e of t)if(n.push(te(e)),!_(e))return Q(n);return Q([...n,J(null)])})))(a(e.firstNonNull))},pt=[{type:"infinite"}],yt=[{type:"nan"}],dt=(e,t,n,r,a={})=>{if("yes"===t.propagates)return{output:J(null)};const{definition:s}=e.entry,o=(e=>void 0!==e.analysis?e.analysis.output:(ut??=new Map(u.filter(e=>Object.hasOwn(ct,e.name)).map(e=>[e,ct[e.name]])),ut.get(e)))(s);let i=void 0!==o?mt(o,{definition:s,inputs:t,elements:n,items:a}):C(s.returns);if("no"!==Fe(i,"number")){const e=Object.values(t.received);e.some(e=>"no"!==ue(e))&&(i=U(i,pt)),e.some(e=>"no"!==le(e))&&(i=U(i,yt))}return"maybe"===t.propagates&&(i=U(i,J(null))),ft(e,i,r,"no"===t.propagates)},ft=(e,t,n,r)=>{if(!p(e.entry.definition.returns))return{output:t};const a=le(n?t:ht(t)),s=t.filter(e=>"exact"in e?!Number.isNaN(e.exact):"nan"!==e.type);return"no"===a?{output:s}:{output:s,boundary:{path:e.path,code:"non-finite-result",message:`${e.name} – non-finite-result possible: NaN may reach its result`,certainty:0===s.length&&r?"always":"may",operator:e.name,order:[e.order]}}},ht=e=>e.filter(e=>"exact"in e),vt={unknown:!0},gt={fails:!0},bt=async(e,t,n,r,a=new Set)=>{if(a.has(e.entry.definition))return;const{parameters:s}=e.entry.definition,o=new Set(n.map(e=>e.param)),i=[];for(const[e,n]of Object.entries(t)){if(o.has(e))continue;const t=B(n);if(void 0===t)return;i.push({name:e,outcomes:t.map(e=>({value:e}))})}const c=n.map(e=>{const t=s[e.param],n=((e,t)=>{const{verdict:n,output:r}=e.result,a=void 0!==t.replacesNullAt;if("always"===n)return[a?vt:gt];const s=B(r);if(void 0===s)return[vt];const o=s.map(e=>({value:e}));return"no"===n?o:a?[vt]:[...o,gt]})(e,t);return{child:e,outcomes:"perElement"===t.evaluation&&void 0===e.at&&n.length>1?[vt]:n}}),u=()=>[...i,...c].reduce((e,{outcomes:t})=>e*t.length,1);if(u()>16)for(const e of c)e.outcomes.length>1&&(e.outcomes=[vt]);const l=u();if(l>16)return;const m=new Set,p=new Set,y=[];for(let n=0;n<l;n++){let s=n;const o=e=>{const t=e[s%e.length];return s=Math.floor(s/e.length),t},u={};for(const{name:e,outcomes:t}of i)u[e]=o(t).value;const l=new Map(c.map(({child:e,outcomes:t})=>[e,o(t)])),d=await $t(e,t,u,l,r,m,p,a);if(void 0===d)return;y.push(d)}const d=[],f=new Map,h=new Set,v=new Set;let g=0;for(const e of y)if("value"in e)d.push(J(e.value));else if("passed"in e){const{passed:t}=e;v.add(t),h.add(t),d.push(wt(t,s[t.param]))}else if(g++,"escaped"in e)h.add(e.escaped);else{const t=`${e.failure.code}|${e.failure.parameter??""}`,n=f.get(t)??{failure:e.failure,count:0};n.count++,f.set(t,n)}const b=[...f.values()].map(({failure:e,count:t})=>({...e,certainty:t===y.length?"always":"may"}));return{output:Q(d),failures:b,reached:m,awaited:p,escaped:h,passed:v,fails:g===y.length}},wt=(e,t)=>void 0===e.at||"perElement"===t.evaluation?Re(t,e.result.output):t.truthiness?C("boolean"):e.result.output,xt=Symbol("stopped"),kt=new Promise(()=>{}),jt=e=>{const t=Promise.reject(e);return t.catch(()=>{}),t},Ot={memo:(e,t)=>t()},Nt={note:()=>{}},$t=async(e,t,n,r,a,s,o,i)=>{const u=e=>{s.add(e),o.add(e)},{definition:l}=e.entry,{parameters:m}=l,d={...t};for(const[e,t]of Object.entries(n))d[e]=J(t);for(const[e,t]of r)void 0!==m[e.param].replacesNullAt&&"value"in t&&(d[e.param]=J(t.value));const f=Ie(e,d);for(const[e,t]of r){if("race"===m[e.param].evaluation&&s.add(e),f.consulted.has(e.param)){if(!("value"in t))return;u(e)}}const h=Ze(l),v=(t,n,r)=>{const s=r??("external"===h?void 0:h.find(n=>n.code===t&&void 0!==n.parameter&&"no"!==it(e,n,f,a))?.parameter);return{failure:{path:e.path,code:t,message:n,certainty:"always",operator:e.name,...void 0!==s?{parameter:s}:{},order:[e.order]}}};if("null"===f.ends)return{value:null};if(void 0!==f.ends)return{failure:f.ends};const g=new Map,b=new Set,w=new Map,x=new Map;let k=!1,$=()=>{};const A=new Promise(e=>{$=()=>e(xt)});let S=!1;const M=()=>{S?$():k=!0},P=e=>{const t=new N({code:j.operatorFailure,message:"",path:[]});return w.set(t,e),t},E=(t,n)=>r=>{const a=void 0!==n.elementNullPolicy;if("yes"!==Fe(J(r),n.type,n.constraints,a)){const n=new N({code:j.typeCheck,message:`${e.name} – parameter '${t}': fails its type check`,path:[]});throw x.set(n,t),n}return n.truthiness?Te(r,n.type):r},z=e=>t=>e.truthiness?c(t):t,F=(e,t)=>{void 0!==e&&u(e);const n=void 0===e?vt:r.get(e);if("unknown"in n){const t=new Promise(()=>{});return void 0!==e&&g.set(t,e),M(),t}if("fails"in n)return jt(P(e));try{return Promise.resolve(t(n.value))}catch(e){return jt(e)}},L=e=>{let t;const n={evaluate:()=>t??=e()};return b.add(n),n},q=(e,t)=>{const n=({index:e,child:n,value:a})=>{if(void 0===n)return{index:e,ok:!0,value:t(a)};u(n);const s=r.get(n);if("fails"in s)return{index:e,ok:!1,error:P(n)};try{return{index:e,ok:!0,value:t(s.value)}}catch(t){return{index:e,ok:!1,error:t}}},a=e=>void 0!==e.child&&"unknown"in r.get(e.child),s={length:e.length,async*[Symbol.asyncIterator](){for(const t of e)a(t)||(yield n(t));e.some(a)&&(M(),await kt)}};return b.add(s),s},D=(e,t)=>{const n=z(t);switch(t.evaluation){case"lazyElements":return e.map(e=>L(()=>Promise.resolve(n(e))));case"race":return q(e.map((e,t)=>({index:t,value:e})),n);case"lazyEntries":{const t={};for(const[r,a]of Object.entries(e))t[r]=L(()=>Promise.resolve(n(a)));return t}case"lazy":return L(()=>Promise.resolve(e));default:return e}},I=new Map;for(const e of r.keys())I.set(e.param,[...I.get(e.param)??[],e]);const C={};for(const[e,t]of Object.entries(m)){if("perElement"===t.evaluation||void 0!==t.replacesNullAt)continue;const n=I.get(e);if(void 0!==n){const r=z(t);if("lazy"===t.evaluation)C[e]=L(()=>F(n[0],E(e,t)));else if("race"===t.evaluation)C[e]=q(n.map((e,t)=>({index:t,child:e})),r);else if("lazyElements"===t.evaluation)C[e]=n.map(e=>L(()=>F(e,r)));else{const t={};for(const e of n)t[String(e.at)]=L(()=>F(e,r));C[e]=t}continue}const r=f.received[e];if(void 0===r)continue;const a=B(r);if(void 0===a||1!==a.length)return;C[e]=D(a[0],t)}for(const[t,n]of l.resolution.perElement){if(void 0===e.params[t]||void 0===n.over)continue;const r=I.get(t)??[],a=C[n.over],o=Array.isArray(a)?a:[],i=1===r.length&&void 0===r[0].at;if(!i&&r.length!==o.length)return;const c=e=>r[i?e>=0&&e<o.length?0:-1:e],u=E(t,n),l=new Map,m={evaluate:e=>{let t=l.get(e);return void 0===t&&l.set(e,t=F(c(e),u)),t},settle:()=>{const e=o.map((e,t)=>({index:t,child:c(t)}));for(const{child:t}of e)s.add(t);return q(e,u)}};b.add(m),C[t]=m}const T={options:a.evaluation,get signal(){return(new AbortController).signal},cache:Ot,trace:Nt},R=t=>{const n=w.get(t);if(void 0!==n)return{escaped:n};if(O(t))return v(t.code,t.message,x.get(t));const r=`${e.name} – ${t instanceof Error?t.message:String(t)}`;return v((y(t)?t.code:void 0)??j.operatorFailure,r)};let W;try{W=l.evaluate(C,T)}catch(e){return R(e)}if(H=W,"function"==typeof H?.then){const e=g.get(W);if(void 0!==e)return{passed:e};if(k)return;S=!0;const t=setTimeout(()=>{i.add(l),$()},100),n=await Promise.race([Promise.resolve(W).then(e=>({value:e}),e=>({error:e})),A]);if(clearTimeout(t),n===xt)return;if("error"in n)return R(n.error);W=n.value}var H;return void 0===W?{value:null}:Number.isNaN(W)&&p(l.returns)?v(j.nonFiniteResult,`${e.name} – produced a non-finite number (${String(W)})`):b.has(W)?v(j.escapedHandle,`${e.name} – returned a lazy handle instead of evaluating it`):{value:W}},At=(e,t)=>void 0===t?e.scope:{vars:t,at:e,known:new Map},St={verdict:"no",escapes:[],output:q},Mt={result:St,covered:[]},Pt=[{type:"integer",min:0}],Et=J(null),zt=[{type:"object"}],Ft=me(Object.fromEntries(Object.entries($).map(([e,t])=>[e,C(t)]))),Lt=e=>{if(0===e.length)return zt;const{value:t,found:n}=pe(Ft,e);return"yes"===n?t:U(t,Et)},qt=({value:e,reads:t=[]},n=0)=>{if(0===t.length)return J(e);const r=t.find(({at:e})=>e.length===n);if(void 0!==r)return Lt(r.segments);const a=e,s=e=>qt({value:a[e],reads:t.filter(({at:t})=>t[n]===e)},n+1);return Array.isArray(e)?ie(e.map((e,t)=>s(t))):me(Object.fromEntries(Object.keys(a).map(e=>[e,s(e)])))},Dt=(e,t)=>{for(const n of t)e.push(n)},Jt=(e,t,n)=>{const r=[...e];for(const e of t)Dt(r,e.result.escapes);const a=t.some(e=>e.result.waits);return t.some(e=>e.eager&&"always"===e.result.verdict)||e.some(e=>!A(e)&&"always"===e.certainty)?{verdict:"always",escapes:r,output:q,waits:a}:{verdict:r.length>0?"may":"no",escapes:r,output:n,waits:a}},Bt=e=>`${e.order}|${e.code}|${e.parameter}`,It=e=>{const t=e.map(e=>new Set([...e.result.escapes,...e.covered.map(({pending:e})=>e)].filter(e=>!A(e)&&"always"===e.certainty).map(e=>Bt(e)))),n=e=>A(e)||"may"===e.certainty||t.every(t=>t.has(Bt(e)))?e:{...e,certainty:"may"};for(const t of e)t.result={...t.result,escapes:t.result.escapes.map(n)},t.covered=t.covered.map(({pending:e,by:t})=>({pending:n(e),by:t}))};class Ct{options;bodies=new Map;stalled=new Set;waiting=new Set;strict;constructor(e){this.options=e,this.strict=!0===e.evaluation.strictDataPaths}root(e,t){return this.walk(e,{scope:null,bindings:null,sink:t,frame:{},walks:1})}async walk(e,t){const n=await this.visit(e,t);return n.waits&&this.waiting.add(e),n}async visit(e,t){switch(e.kind){case"constant":return{...St,output:J(e.value)};case"invalid":throw Tt("an invalid node");case"reference":return this.reference(e,t);case"skeleton":{const n={...t,scope:At(t,e.vars)},r=[];for(const t of e.holes)r.push({result:await this.walk(t.node,n),eager:!0});const a=((e,t)=>{if(t.every(e=>1===e.length&&"exact"in e[0]))return J(h(e.skeleton,e.holes,t.map(e=>e[0].exact)));const n=e.holes.map((e,n)=>({at:e.at,output:t[n]})),r=(e,t,n)=>{const a=n.find(e=>e.at.length===t);if(void 0!==a)return a.output;if(0===n.length)return J(e);const s=new Map;for(const e of n){const n=s.get(e.at[t]);void 0===n?s.set(e.at[t],[e]):n.push(e)}const o=e=>s.get(e)??[];if(Array.isArray(e))return ie(Array.from(e,(e,n)=>r(e,t+1,o(n))));const i=e,c=new Set([...Object.keys(i),...n.map(e=>String(e.at[t]))]),u={};for(const e of c)u[e]=r(i[e],t+1,o(e));return me(u)};return r(e.skeleton,0,n)})(e,r.map(e=>e.result.output));return Jt([],r,a)}case"elements":case"entries":{const n=[],r=await this.container("",e,t,n);for(const e of n)Dt(t.sink,e.covered);const a=n.map(({result:e})=>({result:e,eager:!1}));return Jt([],a,r)}case"operator":return this.operator(e,t);case"fragmentCall":return this.call(e,t)}return e}async operator(e,t){const{definition:n}=e.entry,r={...t,scope:At(t,e.vars)},a={},s=[],o=[];for(const[t,i]of Object.entries(e.params)){const e=n.parameters[t]?.evaluation;if("perElement"!==e)if("elements"===i.kind||"entries"===i.kind)a[t]=await this.container(t,i,r,o);else if("lazy"===e){const e=await this.apart(t,i,r);a[t]=e.result.output,o.push(e)}else{const e=await this.walk(i,r);a[t]=e.output,s.push({result:e,eager:!0})}}const i=Ie(e,a),c=d(e),u={},l={};for(const[a,s]of n.resolution.perElement){const n=e.params[a];if(void 0===n||void 0===s.over)continue;const m=i.received[s.over]??q,p=B(m),y=1===p?.length&&Array.isArray(p[0])?p[0]:void 0,d=t.walks*(y?.length??1/0);if(d<=16){const e=[];for(const[s,i]of Array.from(y).entries()){const u={as:c,element:J(i),index:J(s),parent:t.bindings},l=await this.apart(a,n,{...r,bindings:u,walks:d},s);o.push(l),e.push(l.result.output)}l[a]=e,u[a]=Q(e)}else{const e={as:c,element:se(m),index:Pt,parent:t.bindings},s=await this.apart(a,n,{...r,bindings:e});o.push(s),u[a]=s.result.output}}const m=s.some(e=>"always"===e.result.verdict)?{output:q,failures:[],reached:new Set(o.filter(e=>"race"===n.parameters[e.param].evaluation)),awaited:new Set,escaped:new Set,passed:new Set,fails:!0}:"external"===Ze(n)?void 0:await bt(e,a,o,this.options,this.stalled);for(const e of Object.keys(l))It(o.filter(t=>t.param===e&&(m?.reached.has(t)??!0)));const p=[];void 0===m?(Dt(p,i.failures),"yes"!==i.propagates&&Dt(p,((e,t,n)=>{const r=Ze(e.entry.definition),a={path:e.path,operator:e.name,order:[e.order]};if("external"===r)return[{...a,code:Qe,message:`${e.name} – may fail whatever its inputs: nothing describes what it fails on`,certainty:"may"}];const s=[],o=ot(t,n.strictNumbers);for(const i of r){const r=it(e,i,t,n);"no"!==r&&s.push({...a,code:i.code,message:st(e.name,i),certainty:"yes"!==r||i.may||i.overflow||i.code===Ge&&o||"no"!==t.propagates?"may":"always",...void 0!==i.parameter?{parameter:i.parameter}:{}})}return s})(e,i,this.options))):Dt(p,m.failures);for(const t of o){if(void 0!==m&&!m.passed.has(t))continue;const r=n.parameters[t.param];if("perElement"===r.evaluation){const n=He(e,t.param,r,t.result.output);void 0!==n&&p.push(n)}else void 0!==m&&void 0===t.at&&Dt(p,i.failures.filter(e=>e.parameter===t.param))}const{output:y,boundary:f}=void 0===m?dt(e,i,u,this.options.strictNumbers,l):ft(e,m.output,this.options.strictNumbers,!1);void 0===f||p.some(e=>!A(e)&&e.code===f.code)||p.push(f);for(const e of o){if(void 0!==m&&!m.reached.has(e))continue;Dt(t.sink,e.covered);const n=void 0===m||m.escaped.has(e)?e.result.escapes:e.result.escapes.filter(A),r=e.result.waits&&(m?.awaited.has(e)??!0);s.push({result:{...e.result,escapes:n,waits:r},eager:!1})}const h=Jt(p,s,y);return!0===m?.fails&&Object.assign(h,{verdict:"always",output:q}),(e=>void 0!==e.analysis||"external"===Ze(e))(n)&&(h.waits=!0),this.withFallback(e,h,r)}async apart(e,t,n,r){const a=[];return{param:e,...void 0!==r?{at:r}:{},result:await this.walk(t,{...n,sink:a}),covered:a}}async container(e,t,n,r){if("elements"===t.kind){const a=[];for(const[s,o]of t.nodes.entries()){const t=await this.apart(e,o,n,s);r.push(t),a.push(t.result.output)}return ie(a)}const a={...n,scope:At(n,t.vars)},s={};for(const[n,o]of Object.entries(t.entries)){const t=await this.apart(e,o,a,n);r.push(t),s[n]=t.result.output}return me(s)}async withFallback(e,t,n){if("no"===t.verdict)return t;const r="operator"===e.kind?e.entry.defaultFallback:void 0;if(void 0===e.fallback&&void 0===r)return t;const a={path:e.path};for(const e of t.escapes)n.sink.push({pending:e,by:a});const{waits:s}=t;if(void 0===e.fallback)return{...St,output:U(t.output,qt(r)),waits:s};const o=await this.walk(e.fallback,n);if(e.fallbackReadsError&&"no"!==o.verdict){const r={path:e.path,givesNull:!0};for(const e of o.escapes)n.sink.push({pending:e,by:r});return{...St,output:U(t.output,o.output,Et),waits:s||o.waits}}return{verdict:"always"===t.verdict||"always"!==o.verdict?o.verdict:"may",escapes:o.escapes,output:U(t.output,o.output),waits:s||o.waits}}async reference(e,t){const{segments:n,namespace:r}=e;switch(r){case"data":return this.drilled(e,D,n,[],[]);case"element":case"index":for(let a=t.bindings;null!==a;a=a.parent)if(f(a.as,r,e.binding))return"index"===r?{...St,output:a.index}:this.drilled(e,a.element,n,[],[]);throw Tt(`an unresolved '${e.raw}'`);case"vars":{const r=await this.varDefinition(n[0],t);if(void 0===r)throw Tt(`an unresolved '${e.raw}'`);Dt(t.sink,r.covered);const a=[{result:r.result,eager:!0}];return this.drilled(e,r.result.output,n.slice(1),a,[])}case"params":{const{entry:r,params:a={}}=t.frame;if(void 0===r)throw Tt(`'${e.raw}' outside a fragment body`);const[s,...o]=n;if(void 0===s){const t=Object.keys(r.parameters).map(e=>({demand:e}));return this.drilled(e,me(a),[],[],t)}const i="string"==typeof s?a[s]??D:D;return this.drilled(e,i,o,[],[{demand:String(s)}])}case"error":return{...St,output:Lt(n)}}return r}drilled(e,t,n,r,a){const{value:s,found:o}=pe(t,n);if("yes"===o)return Jt(a,r,s);if(!this.strict)return Jt(a,r,U(s,Et));const i={path:e.path,code:"missing-data-path",message:`'${e.raw}' may be absent (strictDataPaths)`,certainty:"no"===o?"always":"may",order:[e.order]};return Jt([...a,i],r,s)}async varDefinition(e,t){for(let n=t.scope;null!==n;n=n.at.scope){if("string"!=typeof e||!Object.hasOwn(n.vars,e))continue;const t=n.known.get(e);if(void 0!==t)return t;n.known.set(e,{result:{...St,output:D},covered:[]});const r=[],a={result:await this.walk(n.vars[e],{...n.at,scope:n,sink:r}),covered:r};return n.known.set(e,a),a}}async call(e,t){const{entry:n}=e;if(void 0===n)throw Tt(`a call to the unknown fragment '${e.name}'`);const r={...t,scope:At(t,e.vars)},a=[],s=[],o={},i=new Map;if("static"===e.argumentsMode)for(const[t,a]of Object.entries(n.parameters)){const n=await this.argument(e,t,a,r);i.set(t,n),o[t]=n.result.output}else{const t=e.parameters,i=await this.walk(t,r);s.push({result:i,eager:!0}),Dt(a,Wt(e,n,t,o))}let c=!1;const u=e=>{const n=i.get(e)??Mt;return Dt(t.sink,n.covered),c||=!0===n.result.waits,n},l=await this.body(n,o);for(const{pending:n,by:r}of l.covered){const a=M(r,e);if(A(n))for(const e of u(n.demand).result.escapes)t.sink.push({pending:e,by:a});else t.sink.push({pending:S(n,e),by:a})}const m=[];for(const t of l.result.escapes)A(t)?Dt(m,u(t.demand).result.escapes):m.push(S(t,e));return s.push({result:{...l.result,escapes:[]},eager:!0},{result:{...St,escapes:m,waits:c},eager:!1}),this.withFallback(e,Jt(a,s,l.result.output),r)}async argument(e,t,n,r){const a=e.parameters?.[t];if(void 0===a)return{result:{...St,output:J(n.default??null)},covered:[]};const s=[],o=await this.walk(a,{...r,sink:s}),{known:i,answer:c}=We(n,o.output),u="yes"===c?[]:[Rt(e,t,a.path,a.order)];return{result:Jt(u,[{result:o,eager:!0}],i),covered:s}}async body(e,t){const n=Object.keys(t).map(e=>`${e}=${G(t[e])}`).join(";");let r=this.bodies.get(e);void 0===r&&this.bodies.set(e,r=new Map);const a=r.get(n);if(void 0!==a)return a;r.set(n,{result:{...St,output:D},covered:[]});const s=[],o={entry:e,params:t},i={result:await this.walk(e.body,{scope:null,bindings:null,sink:s,frame:o,walks:1}),covered:s};return r.set(n,i),i}}const Tt=e=>new Error(`[fig-tree internal] ${e} reached the coverage walk — the static gate should have refused it`),Rt=(e,t,n,r)=>({path:n,code:"type-check",message:`fragment '${e.name}' – parameter '${t}': the argument may not fit the declared type`,certainty:"may",parameter:t,order:[r]}),Wt=(e,t,n,r)=>{const a=(t,r)=>({path:n.path,code:t,message:`fragment '${e.name}' – ${r}`,certainty:"may",order:[n.order]}),s=Object.entries(t.parameters);for(const[e,t]of s)r[e]=We(t,D).known;const o=[a("type-check","'parameters' may not match the declared parameters")];return s.some(([,e])=>e.required)&&o.push(a("missing-required","'parameters' may omit a required parameter")),o},Ht=async(e,t,n)=>{if(!(e instanceof v))throw new TypeError("fallbackCoverage() takes a FigTree instance");const r=n?.strictNumbers??!1;if("boolean"!=typeof r)throw new N({code:j.invalidOptions,message:`'strictNumbers' must be a boolean, received ${JSON.stringify(r)}`,path:[]});const{artifact:a,options:s}=g(e.compile(t)),o=b(a,s).filter(e=>"error"===e.severity);if(o.length>0)return{uncovered:o.map(E),covered:[]};const i=new Ct({strictNumbers:r,evaluation:s}),c=[],{escapes:u,waits:l}=await i.root(a.root,c),m=u.filter(e=>!A(e)).map(F);if(void 0!==s.timeout&&l)for(const{node:e,timeoutFallback:t}of a.holes){const n={path:e.path,code:"timeout",certainty:"may",order:[e.order]};a.timeoutShielded?i.waiting.has(e)&&c.push({pending:{...n,message:"may be cut off by the timeout, which puts its static fallback in its place"},by:{path:e.path}}):void 0===t&&m.push(F({...n,message:"the timeout may reject the evaluation: something in it can wait, and this value has no static fallback to shield it"}))}const p=c.flatMap(({pending:e,by:t})=>A(e)?[]:[L(e,t)]);return{uncovered:z(m),covered:z(p)}};export{Ht as fallbackCoverage};
@@ -107,7 +107,7 @@ interface Dependencies {
107
107
  interface ParameterInfo extends ValidatedParameter {
108
108
  hostDefault?: unknown;
109
109
  }
110
- interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'parameters'> {
110
+ interface OperatorInfo extends Omit<ValidatedOperatorDefinition, typeof VALIDATED_OPERATOR | 'evaluate' | 'validate' | 'deliversLazily' | 'resolution' | 'fingerprint' | 'analysis' | 'parameters'> {
111
111
  parameters: Record<string, ParameterInfo>;
112
112
  hasValidate: boolean;
113
113
  hostNoCache?: true;
@@ -124,14 +124,16 @@ interface FragmentInfo {
124
124
  caches: boolean;
125
125
  }
126
126
 
127
- declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
127
+ declare class FigTree<Trace extends boolean = false> {
128
128
  private state;
129
129
  private readonly results;
130
- readonly version = "3.0.0-preview.14";
131
- constructor(options?: InstanceOpts);
130
+ readonly version = "3.0.0-preview.15";
131
+ constructor(options?: FigTreeOptions & {
132
+ trace?: Trace;
133
+ });
132
134
  private static fromState;
133
135
  updateOptions(options?: OptionsUpdate): void;
134
- with(update?: OptionsUpdate): FigTree<InstanceOpts>;
136
+ with(update?: OptionsUpdate): FigTree<Trace>;
135
137
  clearCache(): void;
136
138
  getOptions(): EvaluationOptions;
137
139
  getOperators(): OperatorInfo[];
@@ -139,16 +141,20 @@ declare class FigTree<InstanceOpts extends FigTreeOptions = NoOptions> {
139
141
  validate(expression: unknown, options?: ValidateOptions): ValidationResult;
140
142
  getDependencies(expression: unknown): Dependencies;
141
143
  isEvaluable(expression: unknown): boolean;
142
- evaluate<CallOpts extends CallOptions = NoOptions>(expression: unknown, options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
143
- compile(expression: unknown): CompiledExpression<InstanceOpts>;
144
+ evaluate<CallTrace extends boolean = Trace>(expression: unknown, options?: CallOptions & {
145
+ trace?: CallTrace;
146
+ }): Promise<ResultShape<CallTrace>>;
147
+ compile(expression: unknown): CompiledExpression<Trace>;
144
148
  }
145
- declare class CompiledExpression<InstanceOpts extends FigTreeOptions = NoOptions> {
149
+ declare class CompiledExpression<Trace extends boolean = false> {
146
150
  #private;
147
151
  private constructor();
148
152
  get expression(): unknown;
149
153
  get issues(): readonly Issue[];
150
154
  get hasErrors(): boolean;
151
- evaluate<CallOpts extends CallOptions = NoOptions>(options?: OnlyCallOptions<CallOpts>): Promise<ResultShape<Merge<InstanceOpts, CallOpts>>>;
155
+ evaluate<CallTrace extends boolean = Trace>(options?: CallOptions & {
156
+ trace?: CallTrace;
157
+ }): Promise<ResultShape<CallTrace>>;
152
158
  getDependencies(): Dependencies;
153
159
  }
154
160
 
@@ -248,7 +254,7 @@ interface ValidateFinding {
248
254
  message: string;
249
255
  parameter?: string;
250
256
  }
251
- type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers) => ValidateFinding[];
257
+ type OperatorValidate = (literalParams: Record<string, unknown>, helpers: ValidateHelpers, authored: ReadonlySet<string>) => ValidateFinding[];
252
258
  declare const VALIDATED_OPERATOR: unique symbol;
253
259
  interface ValidatedParameter {
254
260
  type: ExpectedType;
@@ -282,6 +288,7 @@ interface ValidatedOperatorDefinition {
282
288
  evaluate: OperatorEvaluate;
283
289
  returns: ExpectedType;
284
290
  }
291
+ type OperatorEntry = ValidatedOperatorDefinition | readonly ValidatedOperatorDefinition[];
285
292
  type DeclarationEntry = readonly [name: string, declared: ValidatedParameter];
286
293
  interface ResolutionPlan {
287
294
  readonly entries: readonly DeclarationEntry[];
@@ -291,16 +298,14 @@ interface ResolutionPlan {
291
298
 
292
299
  type EvaluationOptions = Omit<FigTreeOptions, 'operators' | 'fragments'>;
293
300
  type CallOptions = Pick<FigTreeOptions, 'data' | 'signal' | 'timeout' | 'trace'>;
294
- type OnlyCallOptions<CallOpts> = CallOpts & {
295
- [Key in Exclude<keyof CallOpts, keyof CallOptions>]: never;
296
- };
297
301
  type ValidateOptions = CallOptions & {
298
302
  params?: readonly string[];
299
303
  };
304
+ type HeaderDefaults = Record<string, string | number | boolean | null>;
300
305
  interface FigTreeOptions {
301
306
  data?: Record<string, unknown>;
302
307
  fragments?: Record<string, FragmentDefinition>;
303
- operators?: (ValidatedOperatorDefinition | ValidatedOperatorDefinition[])[];
308
+ operators?: readonly OperatorEntry[];
304
309
  operatorDefaults?: {
305
310
  [operator: string]: {
306
311
  noCache?: true;
@@ -310,11 +315,11 @@ interface FigTreeOptions {
310
315
  };
311
316
  http?: {
312
317
  baseEndpoint?: string;
313
- headers?: Record<string, string>;
318
+ headers?: HeaderDefaults;
314
319
  };
315
320
  graphQL?: {
316
321
  endpoint?: string;
317
- headers?: Record<string, string>;
322
+ headers?: HeaderDefaults;
318
323
  };
319
324
  strictDataPaths?: boolean;
320
325
  maxDepth?: number;
@@ -339,11 +344,7 @@ interface EvaluationResult {
339
344
  result: unknown;
340
345
  trace: TraceNode;
341
346
  }
342
- type NoOptions = Record<never, never>;
343
- type Merge<Instance, Call> = Omit<Instance, keyof Call> & Call;
344
- type ResultShape<O> = O extends {
345
- trace: true;
346
- } ? EvaluationResult : unknown;
347
+ type ResultShape<Trace extends boolean> = Trace extends true ? EvaluationResult : unknown;
347
348
 
348
349
  type TraceEvent = {
349
350
  type: string;
@@ -1 +1 @@
1
- const e={logic:{displayName:"Logic & control",order:0,backgroundColor:"#632fbc",textColor:"#ffffff"},comparison:{displayName:"Comparison",order:1,backgroundColor:"#247f7c",textColor:"#ffffff"},math:{displayName:"Arithmetic & math",order:2,backgroundColor:"#2b8237",textColor:"#ffffff"},string:{displayName:"Strings",order:3,backgroundColor:"#a1660c",textColor:"#ffffff"},array:{displayName:"Arrays & iteration",order:4,backgroundColor:"#236ac7",textColor:"#ffffff"},data:{displayName:"Data & objects",order:5,backgroundColor:"#b93171",textColor:"#ffffff"},io:{displayName:"I/O",order:6,backgroundColor:"#6e7a24",textColor:"#ffffff"},other:{displayName:"Other",order:7,backgroundColor:"#606e8a",textColor:"#ffffff"}},a={any:"Replace me",string:"Replace me",number:1,integer:1,boolean:!0,array:[],object:{},null:null},r="https://github.com/CarlosNZ/fig-tree-evaluator",t={and:{displayName:"Logical AND",description:"True when every value is truthy — operands run in parallel",docUrl:r,backgroundColor:"#d6d0f0",textColor:"#26183f",seeds:{values:[!0,!0]},parameterDescriptions:{values:"Operands, judged by FigTree truthiness; null is falsy"}},or:{displayName:"Logical OR",description:"True when any value is truthy — operands run in parallel",docUrl:r,backgroundColor:"#cabfeb",textColor:"#26183f",seeds:{values:[!0,!1]},parameterDescriptions:{values:"Operands, judged by FigTree truthiness; null is falsy"}},not:{displayName:"Logical NOT (!)",description:"Negate the truthiness of a value",docUrl:r,backgroundColor:"#c0aee5",textColor:"#26183f",seeds:{value:!0},parameterDescriptions:{value:"Judged by FigTree truthiness; null is falsy, so not(null) is true"}},if:{displayName:"Conditional (?)",description:"Choose between two branches — only the chosen branch evaluates",docUrl:r,backgroundColor:"#ddd0f0",textColor:"#26183f",seeds:{condition:!0,then:"The condition is true",else:"The condition is false"},parameterDescriptions:{condition:"Judged by FigTree truthiness; null is falsy",then:"The value when the condition holds",else:"The value when it does not; omitted means null"}},match:{displayName:"Match",description:"Dispatch on a value — only the matching branch evaluates",docUrl:r,backgroundColor:"#d4bfeb",textColor:"#26183f",seeds:{value:"matchMe",branches:{matchMe:"YES",nonMatch:"NO"},default:"No match"},parameterDescriptions:{value:"Matched against branch keys by its canonical string form",branches:"A literal map of branches, or an expression computing one",default:"The branch taken when none matches; absent means failure"}},firstNonNull:{displayName:"First non-null",description:"The first candidate that is not null (SQL COALESCE) — later candidates never evaluate",docUrl:r,backgroundColor:"#ccaee5",textColor:"#26183f",seeds:{values:[null,"The first non-null value"]},parameterDescriptions:{values:"Candidates, tried in order; only null is skipped"}},equal:{displayName:"Equal (=)",description:"Are all the values equal? Deep, structural, key-order-insensitive; a cross-type comparison is false",docUrl:r,backgroundColor:"#d2efe9",textColor:"#183f3e",seeds:{values:["These are equal","These are equal"]},parameterDescriptions:{values:"The values compared; null is comparable (null equals null)",caseInsensitive:"Fold string operands to one case before comparing (shallow)"}},notEqual:{displayName:"Not equal (!=)",description:'Are the values NOT all equal? The exact negation of equal (never "all distinct")',docUrl:r,backgroundColor:"#c1e9e3",textColor:"#183f3e",seeds:{values:["These items","don't match"]},parameterDescriptions:{values:"The values compared; null is comparable (null equals null)",caseInsensitive:"Fold string operands to one case before comparing (shallow)"}},greaterThan:{displayName:"Greater than (>)",description:"Is the first value strictly greater than the second?",docUrl:r,backgroundColor:"#b0e3e0",textColor:"#183f3e",seeds:{values:[10,9]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},greaterThanOrEqual:{displayName:"Greater than or equal (>=)",description:"Is the first value greater than or equal to the second?",docUrl:r,backgroundColor:"#d2efef",textColor:"#183f3e",seeds:{values:[10,10]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},lessThan:{displayName:"Less than (<)",description:"Is the first value strictly less than the second?",docUrl:r,backgroundColor:"#c1e6e9",textColor:"#183f3e",seeds:{values:[9,10]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},lessThanOrEqual:{displayName:"Less than or equal (<=)",description:"Is the first value less than or equal to the second?",docUrl:r,backgroundColor:"#b0dbe3",textColor:"#183f3e",seeds:{values:[9,9]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},plus:{displayName:"Plus (+)",description:"Add numbers, concatenate strings or arrays, or shallow-merge objects — all operands must share one type",docUrl:r,backgroundColor:"#d7edd4",textColor:"#193e1e",seeds:{values:[1,2,3]},parameterDescriptions:{values:"The operands; homogeneous: all numbers, strings, arrays or objects",expect:"Pin the mode: every operand must be this type, and an empty input yields its identity",nullValueDefault:"Replaces any null operand before the addition"}},subtract:{displayName:"Subtract (-)",description:"Subtract one number from another",docUrl:r,backgroundColor:"#bfe4bc",textColor:"#193e1e",seeds:{value:10,minus:5},parameterDescriptions:{value:"The main operand",minus:"The amount subtracted from value"}},multiply:{displayName:"Multiply (*)",description:"Multiply numbers together — an empty input is 1, the empty product",docUrl:r,backgroundColor:"#b4e0b3",textColor:"#193e1e",seeds:{values:[5,5]},parameterDescriptions:{values:"The factors",nullValueDefault:"Replaces any null factor before multiplying"}},divide:{displayName:"Divide (/)",description:"Divide one number by another — true division; zero divisors fail",docUrl:r,backgroundColor:"#cceacd",textColor:"#193e1e",seeds:{value:100,by:10},parameterDescriptions:{value:"The main operand",by:"The divisor"}},modulo:{displayName:"Modulo",description:"The floored remainder: the result takes the sign of mod, so modulo(-7, 3) is 2",docUrl:r,backgroundColor:"#c3e7c6",textColor:"#193e1e",seeds:{value:10,mod:3},parameterDescriptions:{value:"The main operand",mod:"The modulus"}},power:{displayName:"Power (^)",description:"Raise a base to an exponent — overflow and complex results fail",docUrl:r,backgroundColor:"#acddb1",textColor:"#193e1e",seeds:{base:2,exponent:3},parameterDescriptions:{base:"The number to raise",exponent:"The power to raise it to"}},round:{displayName:"Round",description:"Round to a number of decimal places — ties go half away from zero; negative decimals round to tens, hundreds, …",docUrl:r,backgroundColor:"#d4edd8",textColor:"#193e1e",seeds:{value:3.14159,decimals:2},parameterDescriptions:{value:"The number to round",decimals:"Decimal places to keep; negative values round to powers of ten"}},floor:{displayName:"Round down",description:"Round down toward negative infinity",docUrl:r,backgroundColor:"#bce4c4",textColor:"#193e1e",seeds:{value:2.7},parameterDescriptions:{value:"The number to round down"}},ceil:{displayName:"Round up",description:"Round up toward positive infinity",docUrl:r,backgroundColor:"#b3e0be",textColor:"#193e1e",seeds:{value:2.3},parameterDescriptions:{value:"The number to round up"}},abs:{displayName:"Absolute value",description:"The absolute value",docUrl:r,backgroundColor:"#ccead5",textColor:"#193e1e",seeds:{value:-5},parameterDescriptions:{value:"The number"}},min:{displayName:"Minimum",description:"The smallest of the values — numbers numerically, strings in codepoint order",docUrl:r,backgroundColor:"#c3e7cf",textColor:"#193e1e",seeds:{values:[3,1,2]},parameterDescriptions:{values:"The candidates: all numbers, or all strings (codepoint order)",nullValueDefault:"Replaces any null candidate before comparing"}},max:{displayName:"Maximum",description:"The largest of the values — numbers numerically, strings in codepoint order",docUrl:r,backgroundColor:"#acddbf",textColor:"#193e1e",seeds:{values:[3,1,2]},parameterDescriptions:{values:"The candidates: all numbers, or all strings (codepoint order)",nullValueDefault:"Replaces any null candidate before comparing"}},buildString:{displayName:"String builder",description:"Render a template, filling its tokens — the result is always a string",docUrl:r,backgroundColor:"#f8d9c9",textColor:"#3f2f18",seeds:{template:"Hello {{$data.name}}"},parameterDescriptions:{template:"The text, with %N or {{name}} tokens; in a literal template, {{$data.x}} is that reference",substitutions:"An array pairs with %N tokens, an object with {{name}} tokens; the mode dispatches on which arrives",trim:"Trim whitespace from each rendered value, never from the template text",closeGaps:"A value that renders empty also takes one run of adjacent template whitespace",nullValueDefault:'Rendered in place of a null value, instead of ""'}},split:{displayName:"Split text",description:"Divide a string on a delimiter into an array of pieces — empty pieces are kept; an empty delimiter splits into code points",docUrl:r,backgroundColor:"#f5cbab",textColor:"#3f2f18",seeds:{value:"Alpha, Bravo, Charlie",delimiter:",",trim:!1},parameterDescriptions:{value:"The string to divide",delimiter:'Split on each occurrence; "" splits into code points',trim:"Trim whitespace from each piece"}},join:{displayName:"Join text",description:"Render array elements to text and concatenate them with a delimiter",docUrl:r,backgroundColor:"#f3cba0",textColor:"#3f2f18",seeds:{values:["Alpha","Bravo","Charlie"],delimiter:", "},parameterDescriptions:{values:'Elements of any type, rendered by the stringification table; a null renders "" and still occupies its slot',delimiter:"Placed between each adjacent pair — shares its contract with split",nullValueDefault:'Rendered in place of a null element, instead of ""'}},lower:{displayName:"Lower case",description:"Lowercase a string — Unicode default case mapping, locale-independent",docUrl:r,backgroundColor:"#f7e1bf",textColor:"#3f2f18",seeds:{value:"Hello World"},parameterDescriptions:{value:"The string to lowercase"}},upper:{displayName:"Upper case",description:"Uppercase a string — Unicode default case mapping, locale-independent",docUrl:r,backgroundColor:"#f6e1b4",textColor:"#3f2f18",seeds:{value:"Hello World"},parameterDescriptions:{value:"The string to uppercase"}},trim:{displayName:"Trim whitespace",description:"Strip whitespace (the JS trim set) from both ends of a string",docUrl:r,backgroundColor:"#f2dd97",textColor:"#3f2f18",seeds:{value:" Hello World "},parameterDescriptions:{value:"The string to trim"}},regex:{displayName:"Regular expression",description:"Test, extract or match a string against a regular expression",docUrl:r,backgroundColor:"#f8f1c9",textColor:"#3f2f18",seeds:{value:"test-this",pattern:"^[a-z]{4}-[a-z]{4}$",flags:"i"},parameterDescriptions:{value:"The subject string",pattern:"The regular expression source",flags:"The admitted subset: i, m, s, u",mode:"test gives a boolean, extract the first matching substring, match every one of them",noMatchDefault:"The extract answer when nothing matches — a matched empty string still passes through"}},length:{displayName:"Length",description:"An array's element count, or a string's Unicode code-point count",docUrl:r,backgroundColor:"#cde5f3",textColor:"#18293f",seeds:{value:[1,2,3,4,5]},parameterDescriptions:{value:"The array or string measured"}},map:{displayName:"Map each",description:"Transform every element of an array",docUrl:r,backgroundColor:"#bbd7ef",textColor:"#18293f",seeds:{input:[1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"Evaluated per element, with $element and $index bound"}},filter:{displayName:"Filter",description:"Keep the elements of an array whose predicate is truthy",docUrl:r,backgroundColor:"#a8c7eb",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},find:{displayName:"Find first",description:"The first element of an array whose predicate is truthy",docUrl:r,backgroundColor:"#cddcf3",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy",noMatchDefault:"The answer when nothing matches; a found null passes through unchanged"}},some:{displayName:"Any match",description:"True when any element satisfies the predicate",docUrl:r,backgroundColor:"#bbccef",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},every:{displayName:"All match",description:"True when every element satisfies the predicate",docUrl:r,backgroundColor:"#a8b9eb",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},get:{displayName:"Get data",description:"Read a path out of the evaluation data, or out of a supplied object — the dynamic face of a $data reference",docUrl:r,backgroundColor:"#f0d1e5",textColor:"#3f182a",seeds:{path:"path.to.value",from:{path:{to:{value:"Found it"}}},default:"Not found"},parameterDescriptions:{path:"Dot and bracket segments, quoted keys and the [*] projection — or an array of segments, taken verbatim",from:"The source the path reads: a value, or a bare namespace ($data, $vars, $params, $element) whose var or parameter name opens the path — replace, never merge; a null source misses every path",default:"The answer when the path is missing — a stored null passes through unchanged (firstNonNull replaces one); supplying it also opts out of strictDataPaths"}},buildObject:{displayName:"Build object",description:"Assemble an object from computed key/value entries — for keys known only at runtime",docUrl:r,backgroundColor:"#eac0cc",textColor:"#3f182a",seeds:{entries:[{key:"firstKey",value:"firstValue"},{key:"secondKey",value:"secondValue"}]},parameterDescriptions:{entries:'Objects with a "key" and a "value"; a null value keeps its key'}},convert:{displayName:"Convert type",description:"Convert a value to a number, string, boolean or array — strict: a failed conversion is an error, never a guess",docUrl:r,backgroundColor:"#dddfe3",textColor:"#272a30",seeds:{value:"42"},parameterDescriptions:{value:"The value to convert; null propagates except for boolean, where it is false",to:"The target type"}},http:{displayName:"HTTP request",description:"One HTTP request — GET or POST — returning the parsed JSON response",docUrl:r,backgroundColor:"#eeedd2",textColor:"#3a3f18",seeds:{url:"https://restcountries.com/v3.1/name/zealand",returnPath:"[0].name.common",timeout:5e3},parameterDescriptions:{url:"A full http(s) URL is used verbatim; anything else — including an empty string — joins http.baseEndpoint",method:"Lowercase; the mutating verbs are deliberately absent — an expression is a read",query:"Query-string pairs; a null value omits its pair, a composite one is an error",body:"The JSON payload; a whole-null body means NO body, while nulls inside one are JSON nulls",headers:"Merged over the http.headers option per key; a null value removes an inherited pair",returnPath:"Dot/bracket path or segments array applied to the response; a miss is null",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},graphQL:{displayName:"GraphQL query",description:"One GraphQL query — a POST of { query, variables } — returning the data field",docUrl:r,backgroundColor:"#e3e8c2",textColor:"#3a3f18",seeds:{query:'query getCountries {\n countries(filter: { continent: { eq: "OC" } }) {\n name\n }\n}',url:"https://countries.trevorblades.com/",returnPath:"countries[0].name",timeout:5e3},parameterDescriptions:{query:"The GraphQL document — the protocol’s own word, as sql.query is",variables:"Query variables; a null value is CARRIED as JSON null, a nullable argument being meaningful GraphQL",url:"Per-node endpoint override; unset means the graphQL.endpoint option",headers:"Merged over http.headers then graphQL.headers; a null value removes a pair",returnPath:"Dot/bracket path or segments array applied to the response; a miss is null",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},sql:{displayName:"SQL query",description:"One SQL query against the registered connection. Expressions are READS — give the connection a read-only role and run mutations host-side",docUrl:r,backgroundColor:"#d2e2b1",textColor:"#3a3f18",seeds:{query:"SELECT contact_name FROM customers LIMIT 5",timeout:5e3},parameterDescriptions:{query:"SQL text with the driver’s own placeholders — FigTree never parses SQL",values:"Bind values — positional as an array, named as an object; a null binds SQL NULL",shape:"rows: every row object; firstRow: the first; column: one column’s values; firstValue: one scalar",noRowDefault:"The answer when firstRow / firstValue find no row — never for rows / column, never on failure",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},literal:{displayName:"Literal",docUrl:r,backgroundColor:"#d5dae4",textColor:"#272a30",seeds:{value:"No content inside a literal node is evaluated"}}},o=(e,a)=>void 0!==e&&Object.hasOwn(e,a)?e[a]:void 0,s=e=>void 0!==e.backgroundColor&&void 0!==e.textColor?{backgroundColor:e.backgroundColor,textColor:e.textColor}:void 0,n=(e,r,t)=>void 0!==e.seeds&&Object.hasOwn(e.seeds,r)?e.seeds[r]:"string"==typeof t?a[t]:"literal"in t?t.literal[0]:a[t.find(e=>"null"!==e)??"null"],l=(e,a,r)=>{const{type:t,evaluation:o}=a;return a.replacesNullAt?"none":"as"===e&&"structural"===o&&Object.values(r).some(e=>"perElement"===e.evaluation)?"error":[t].flat().some(e=>"null"===e||"any"===e)?"eager"===o||"structural"===o?a.nullPolicy:"value":a.required||"lazy"===o||"perElement"===o?"error":"unset"},i=(e,a)=>{for(const[r,t]of Object.entries(a??{}))void 0!==t&&(e[r]=t)},d=(a,...r)=>({categories:Object.entries(e).map(([e,a])=>({name:e,...a})).sort((e,a)=>e.order-a.order),operators:a.getOperators().map(({name:a,parameters:d,...c})=>{const u=(e=>{const a={seeds:{},parameterDescriptions:{}};for(const n of[t,...r]){const r=o(n,e);if(void 0!==r){for(const e of["displayName","description","docUrl"]){const t=r[e];void 0!==t&&(a[e]=t)}Object.assign(a,s(r)),i(a.seeds,r.seeds),i(a.parameterDescriptions,r.parameterDescriptions)}}return a})(a),p={name:a,displayName:u.displayName??a,...c,...s(u)??s(e[c.category]),parameters:{}};void 0!==u.description&&(p.description=u.description),void 0!==u.docUrl&&(p.docUrl=u.docUrl);for(const[e,a]of Object.entries(d)){const r={...a,nullOutcome:l(e,a,d),seed:n(u,e,a.type)};if(!a.replacesNullAt&&[a.type].flat().every(e=>"array"===e||"object"===e)){const{homogeneous:e,elementShape:t}=a.constraints??{};r.elementNullOutcome=a.elementNullPolicy??(t||e&&!e.includes("any")?"error":"value")}const t=o(u.parameterDescriptions,e);void 0!==t&&(r.description=t),p.parameters[e]=r}return p}),fragments:a.getFragments().map(({name:e,parameters:a,...r})=>{const t=r.metadata??{},o={name:e,displayName:t.displayName??e,...r,...s(t),parameters:{}};void 0!==t.docUrl&&(o.docUrl=t.docUrl);for(const[e,r]of Object.entries(a))o.parameters[e]={...r,seed:n(t,e,r.type)};return o})});export{e as categoryListings,d as getCatalog,t as operatorListings,a as typeSeeds};
1
+ const e={logic:{displayName:"Logic & control",order:0,backgroundColor:"#632fbc",textColor:"#ffffff"},comparison:{displayName:"Comparison",order:1,backgroundColor:"#247f7c",textColor:"#ffffff"},math:{displayName:"Arithmetic & math",order:2,backgroundColor:"#2b8237",textColor:"#ffffff"},string:{displayName:"Strings",order:3,backgroundColor:"#a1660c",textColor:"#ffffff"},array:{displayName:"Arrays & iteration",order:4,backgroundColor:"#236ac7",textColor:"#ffffff"},data:{displayName:"Data & objects",order:5,backgroundColor:"#b93171",textColor:"#ffffff"},io:{displayName:"I/O",order:6,backgroundColor:"#6e7a24",textColor:"#ffffff"},other:{displayName:"Other",order:7,backgroundColor:"#606e8a",textColor:"#ffffff"}},a={any:"Replace me",string:"Replace me",number:1,integer:1,boolean:!0,array:[],object:{},null:null},r="https://github.com/CarlosNZ/fig-tree-evaluator",t={and:{displayName:"Logical AND",description:"True when every value is truthy — operands run in parallel",docUrl:r,backgroundColor:"#d6d0f0",textColor:"#26183f",seeds:{values:[!0,!0]},parameterDescriptions:{values:"Operands, judged by FigTree truthiness; null is falsy"}},or:{displayName:"Logical OR",description:"True when any value is truthy — operands run in parallel",docUrl:r,backgroundColor:"#cabfeb",textColor:"#26183f",seeds:{values:[!0,!1]},parameterDescriptions:{values:"Operands, judged by FigTree truthiness; null is falsy"}},not:{displayName:"Logical NOT (!)",description:"Negate the truthiness of a value",docUrl:r,backgroundColor:"#c0aee5",textColor:"#26183f",seeds:{value:!0},parameterDescriptions:{value:"Judged by FigTree truthiness; null is falsy, so not(null) is true"}},if:{displayName:"Conditional (?)",description:"Choose between two branches — only the chosen branch evaluates",docUrl:r,backgroundColor:"#ddd0f0",textColor:"#26183f",seeds:{condition:!0,then:"The condition is true",else:"The condition is false"},parameterDescriptions:{condition:"Judged by FigTree truthiness; null is falsy",then:"The value when the condition holds",else:"The value when it does not; omitted means null"}},match:{displayName:"Match",description:"Dispatch on a value — only the matching branch evaluates",docUrl:r,backgroundColor:"#d4bfeb",textColor:"#26183f",seeds:{value:"matchMe",branches:{matchMe:"YES",nonMatch:"NO"},default:"No match"},parameterDescriptions:{value:"Matched against branch keys by its canonical string form",branches:"A literal map of branches, or an expression computing one",default:"The branch taken when none matches; absent means failure"}},firstNonNull:{displayName:"First non-null",description:"The first candidate that is not null (SQL COALESCE) — later candidates never evaluate",docUrl:r,backgroundColor:"#ccaee5",textColor:"#26183f",seeds:{values:[null,"The first non-null value"]},parameterDescriptions:{values:"Candidates, tried in order; only null is skipped"}},equal:{displayName:"Equal (=)",description:"Are all the values equal? Deep, structural, key-order-insensitive; a cross-type comparison is false",docUrl:r,backgroundColor:"#d2efe9",textColor:"#183f3e",seeds:{values:["These are equal","These are equal"]},parameterDescriptions:{values:"The values compared; null is comparable (null equals null)",caseInsensitive:"Fold string operands to one case before comparing (shallow)"}},notEqual:{displayName:"Not equal (!=)",description:'Are the values NOT all equal? The exact negation of equal (never "all distinct")',docUrl:r,backgroundColor:"#c1e9e3",textColor:"#183f3e",seeds:{values:["These items","don't match"]},parameterDescriptions:{values:"The values compared; null is comparable (null equals null)",caseInsensitive:"Fold string operands to one case before comparing (shallow)"}},greaterThan:{displayName:"Greater than (>)",description:"Is the first value strictly greater than the second?",docUrl:r,backgroundColor:"#b0e3e0",textColor:"#183f3e",seeds:{values:[10,9]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},greaterThanOrEqual:{displayName:"Greater than or equal (>=)",description:"Is the first value greater than or equal to the second?",docUrl:r,backgroundColor:"#d2efef",textColor:"#183f3e",seeds:{values:[10,10]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},lessThan:{displayName:"Less than (<)",description:"Is the first value strictly less than the second?",docUrl:r,backgroundColor:"#c1e6e9",textColor:"#183f3e",seeds:{values:[9,10]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},lessThanOrEqual:{displayName:"Less than or equal (<=)",description:"Is the first value less than or equal to the second?",docUrl:r,backgroundColor:"#b0dbe3",textColor:"#183f3e",seeds:{values:[9,9]},parameterDescriptions:{values:"Exactly two operands: both numbers, or both strings (codepoint order)",nullValueDefault:"Replaces a null operand before comparing"}},plus:{displayName:"Plus (+)",description:"Add numbers, concatenate strings or arrays, or shallow-merge objects — all operands must share one type",docUrl:r,backgroundColor:"#d7edd4",textColor:"#193e1e",seeds:{values:[1,2,3]},parameterDescriptions:{values:"The operands; homogeneous: all numbers, strings, arrays or objects",expect:"Pin the mode: every operand must be this type, and an empty input yields its identity",nullValueDefault:"Replaces any null operand before the addition"}},subtract:{displayName:"Subtract (-)",description:"Subtract one number from another",docUrl:r,backgroundColor:"#bfe4bc",textColor:"#193e1e",seeds:{value:10,minus:5},parameterDescriptions:{value:"The main operand",minus:"The amount subtracted from value"}},multiply:{displayName:"Multiply (*)",description:"Multiply numbers together — an empty input is 1, the empty product",docUrl:r,backgroundColor:"#b4e0b3",textColor:"#193e1e",seeds:{values:[5,5]},parameterDescriptions:{values:"The factors",nullValueDefault:"Replaces any null factor before multiplying"}},divide:{displayName:"Divide (/)",description:"Divide one number by another — true division; zero divisors fail",docUrl:r,backgroundColor:"#cceacd",textColor:"#193e1e",seeds:{value:100,by:10},parameterDescriptions:{value:"The main operand",by:"The divisor"}},modulo:{displayName:"Modulo",description:"The floored remainder: the result takes the sign of mod, so modulo(-7, 3) is 2",docUrl:r,backgroundColor:"#c3e7c6",textColor:"#193e1e",seeds:{value:10,mod:3},parameterDescriptions:{value:"The main operand",mod:"The modulus"}},power:{displayName:"Power (^)",description:"Raise a base to an exponent — overflow and complex results fail",docUrl:r,backgroundColor:"#acddb1",textColor:"#193e1e",seeds:{base:2,exponent:3},parameterDescriptions:{base:"The number to raise",exponent:"The power to raise it to"}},round:{displayName:"Round",description:"Round to a number of decimal places — ties go half away from zero; negative decimals round to tens, hundreds, …",docUrl:r,backgroundColor:"#d4edd8",textColor:"#193e1e",seeds:{value:3.14159,decimals:2},parameterDescriptions:{value:"The number to round",decimals:"Decimal places to keep; negative values round to powers of ten"}},floor:{displayName:"Round down",description:"Round down toward negative infinity",docUrl:r,backgroundColor:"#bce4c4",textColor:"#193e1e",seeds:{value:2.7},parameterDescriptions:{value:"The number to round down"}},ceiling:{displayName:"Round up",description:"Round up toward positive infinity",docUrl:r,backgroundColor:"#b3e0be",textColor:"#193e1e",seeds:{value:2.3},parameterDescriptions:{value:"The number to round up"}},abs:{displayName:"Absolute value",description:"The absolute value",docUrl:r,backgroundColor:"#ccead5",textColor:"#193e1e",seeds:{value:-5},parameterDescriptions:{value:"The number"}},min:{displayName:"Minimum",description:"The smallest of the values — numbers numerically, strings in codepoint order",docUrl:r,backgroundColor:"#c3e7cf",textColor:"#193e1e",seeds:{values:[3,1,2]},parameterDescriptions:{values:"The candidates: all numbers, or all strings (codepoint order)",nullValueDefault:"Replaces any null candidate before comparing"}},max:{displayName:"Maximum",description:"The largest of the values — numbers numerically, strings in codepoint order",docUrl:r,backgroundColor:"#acddbf",textColor:"#193e1e",seeds:{values:[3,1,2]},parameterDescriptions:{values:"The candidates: all numbers, or all strings (codepoint order)",nullValueDefault:"Replaces any null candidate before comparing"}},buildString:{displayName:"String builder",description:"Render a template, filling its tokens — the result is always a string",docUrl:r,backgroundColor:"#f8d9c9",textColor:"#3f2f18",seeds:{template:"Hello {{$data.name}}"},parameterDescriptions:{template:"The text, with %N or {{name}} tokens; in a literal template, {{$data.x}} is that reference",substitutions:"An array pairs with %N tokens, an object with {{name}} tokens; the mode dispatches on which arrives",trim:"Trim whitespace from each rendered value, never from the template text",closeGaps:"A value that renders empty also takes one run of adjacent template whitespace",nullValueDefault:'Rendered in place of a null value, instead of ""'}},split:{displayName:"Split text",description:"Divide a string on a delimiter into an array of pieces — empty pieces are kept; an empty delimiter splits into code points",docUrl:r,backgroundColor:"#f5cbab",textColor:"#3f2f18",seeds:{value:"Alpha, Bravo, Charlie",delimiter:",",trim:!1},parameterDescriptions:{value:"The string to divide",delimiter:'Split on each occurrence; "" splits into code points',trim:"Trim whitespace from each piece"}},join:{displayName:"Join text",description:"Render array elements to text and concatenate them with a delimiter",docUrl:r,backgroundColor:"#f3cba0",textColor:"#3f2f18",seeds:{values:["Alpha","Bravo","Charlie"],delimiter:", "},parameterDescriptions:{values:'Elements of any type, rendered by the stringification table; a null renders "" and still occupies its slot',delimiter:"Placed between each adjacent pair — shares its contract with split",nullValueDefault:'Rendered in place of a null element, instead of ""'}},lower:{displayName:"Lower case",description:"Lowercase a string — Unicode default case mapping, locale-independent",docUrl:r,backgroundColor:"#f7e1bf",textColor:"#3f2f18",seeds:{value:"Hello World"},parameterDescriptions:{value:"The string to lowercase"}},upper:{displayName:"Upper case",description:"Uppercase a string — Unicode default case mapping, locale-independent",docUrl:r,backgroundColor:"#f6e1b4",textColor:"#3f2f18",seeds:{value:"Hello World"},parameterDescriptions:{value:"The string to uppercase"}},trim:{displayName:"Trim whitespace",description:"Strip whitespace (the JS trim set) from both ends of a string",docUrl:r,backgroundColor:"#f2dd97",textColor:"#3f2f18",seeds:{value:" Hello World "},parameterDescriptions:{value:"The string to trim"}},regex:{displayName:"Regular expression",description:"Test, extract, match or replace in a string with a regular expression",docUrl:r,backgroundColor:"#f8f1c9",textColor:"#3f2f18",seeds:{value:"test-this",pattern:"^[a-z]{4}-[a-z]{4}$",flags:"i"},parameterDescriptions:{value:"The subject string",pattern:"The regular expression source",flags:"The admitted subset: i, m, s, u",mode:"test gives a boolean, extract the first matching substring, match every one of them, replace the string with every match replaced",noMatchDefault:"The extract answer when nothing matches — a matched empty string still passes through",replacement:"What replace puts in place of each match — $1 and $<name> insert a capture group, $& the whole match, $$ a dollar sign; empty removes the matches"}},length:{displayName:"Length",description:"An array's element count, or a string's Unicode code-point count",docUrl:r,backgroundColor:"#cde5f3",textColor:"#18293f",seeds:{value:[1,2,3,4,5]},parameterDescriptions:{value:"The array or string measured"}},map:{displayName:"Map each",description:"Transform every element of an array",docUrl:r,backgroundColor:"#bbd7ef",textColor:"#18293f",seeds:{input:[1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"Evaluated per element, with $element and $index bound"}},filter:{displayName:"Filter",description:"Keep the elements of an array whose predicate is truthy",docUrl:r,backgroundColor:"#a8c7eb",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},find:{displayName:"Find first",description:"The first element of an array whose predicate is truthy",docUrl:r,backgroundColor:"#cddcf3",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy",noMatchDefault:"The answer when nothing matches; a found null passes through unchanged"}},some:{displayName:"Any match",description:"True when any element satisfies the predicate",docUrl:r,backgroundColor:"#bbccef",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},every:{displayName:"All match",description:"True when every element satisfies the predicate",docUrl:r,backgroundColor:"#a8b9eb",textColor:"#18293f",seeds:{input:[0,1,2,3],each:"$element",as:"item"},parameterDescriptions:{input:"The collection iterated over; a null input is a type error",as:"Rename the bindings: as: 'row' binds $row and $rowIndex",nullInputDefault:"Used as the collection when input evaluates to null — typically []",each:"The predicate, per element — a truthiness position, so null is falsy"}},get:{displayName:"Get data",description:"Read a path out of the evaluation data, or out of a supplied object — the dynamic face of a $data reference",docUrl:r,backgroundColor:"#f0d1e5",textColor:"#3f182a",seeds:{path:"path.to.value",from:{path:{to:{value:"Found it"}}},default:"Not found"},parameterDescriptions:{path:"Dot and bracket segments, quoted keys and the [*] projection — or an array of segments, taken verbatim",from:"The source the path reads: a value, or a bare namespace ($data, $vars, $params, $element) whose var or parameter name opens the path — replace, never merge; a null source misses every path",default:"The answer when the path is missing — a stored null passes through unchanged (firstNonNull replaces one); supplying it also opts out of strictDataPaths"}},buildObject:{displayName:"Build object",description:"Assemble an object from computed key/value entries — for keys known only at runtime",docUrl:r,backgroundColor:"#eac0cc",textColor:"#3f182a",seeds:{entries:[{key:"firstKey",value:"firstValue"},{key:"secondKey",value:"secondValue"}]},parameterDescriptions:{entries:'Objects with a "key" and a "value"; a null value keeps its key'}},convert:{displayName:"Convert type",description:"Convert a value to a number, string, boolean or array — strict: a failed conversion is an error, never a guess",docUrl:r,backgroundColor:"#dddfe3",textColor:"#272a30",seeds:{value:"42"},parameterDescriptions:{value:"The value to convert; null propagates except for boolean, where it is false",to:"The target type"}},http:{displayName:"HTTP request",description:"One HTTP request — GET or POST — returning the parsed JSON response",docUrl:r,backgroundColor:"#eeedd2",textColor:"#3a3f18",seeds:{url:"https://restcountries.com/v3.1/name/zealand",returnPath:"[0].name.common",timeout:5e3},parameterDescriptions:{url:"A full http(s) URL is used verbatim; anything else — including an empty string — joins http.baseEndpoint",method:"Lowercase; the mutating verbs are deliberately absent — an expression is a read",query:"Query-string pairs; a null value omits its pair, a composite one is an error",body:"The JSON payload; a whole-null body means NO body, while nulls inside one are JSON nulls",headers:"Merged over the http.headers option per key; a null value removes an inherited pair",returnPath:"Dot/bracket path or segments array applied to the response; a miss is null",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},graphQL:{displayName:"GraphQL query",description:"One GraphQL query — a POST of { query, variables } — returning the data field",docUrl:r,backgroundColor:"#e3e8c2",textColor:"#3a3f18",seeds:{query:'query getCountries {\n countries(filter: { continent: { eq: "OC" } }) {\n name\n }\n}',url:"https://countries.trevorblades.com/",returnPath:"countries[0].name",timeout:5e3},parameterDescriptions:{query:"The GraphQL document — the protocol’s own word, as sql.query is",variables:"Query variables; a null value is CARRIED as JSON null, a nullable argument being meaningful GraphQL",url:"Per-node endpoint override; unset means the graphQL.endpoint option",headers:"Merged over http.headers then graphQL.headers; a null value removes a pair",returnPath:"Dot/bracket path or segments array applied to the response; a miss is null",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},sql:{displayName:"SQL query",description:"One SQL query against the registered connection. Expressions are READS — give the connection a read-only role and run mutations host-side",docUrl:r,backgroundColor:"#d2e2b1",textColor:"#3a3f18",seeds:{query:"SELECT contact_name FROM customers LIMIT 5",timeout:5e3},parameterDescriptions:{query:"SQL text with the driver’s own placeholders — FigTree never parses SQL",values:"Bind values — positional as an array, named as an object; a null binds SQL NULL",shape:"rows: every row object; firstRow: the first; column: one column’s values; firstValue: one scalar",noRowDefault:"The answer when firstRow / firstValue find no row — never for rows / column, never on failure",timeout:"Per-request deadline in ms; expiry is an ordinary failure this node’s fallback catches"}},literal:{displayName:"Literal",docUrl:r,backgroundColor:"#d5dae4",textColor:"#272a30",seeds:{value:"No content inside a literal node is evaluated"}}},o=(e,a)=>void 0!==e&&Object.hasOwn(e,a)?e[a]:void 0,s=e=>void 0!==e.backgroundColor&&void 0!==e.textColor?{backgroundColor:e.backgroundColor,textColor:e.textColor}:void 0,n=(e,r,t)=>void 0!==e.seeds&&Object.hasOwn(e.seeds,r)?e.seeds[r]:"string"==typeof t?a[t]:"literal"in t?t.literal[0]:a[t.find(e=>"null"!==e)??"null"],l=(e,a,r)=>{const{type:t,evaluation:o}=a;return a.replacesNullAt?"none":"as"===e&&"structural"===o&&Object.values(r).some(e=>"perElement"===e.evaluation)?"error":[t].flat().some(e=>"null"===e||"any"===e)?"eager"===o||"structural"===o?a.nullPolicy:"value":a.required||"lazy"===o||"perElement"===o?"error":"unset"},i=(e,a)=>{for(const[r,t]of Object.entries(a??{}))void 0!==t&&(e[r]=t)},d=(a,...r)=>({categories:Object.entries(e).map(([e,a])=>({name:e,...a})).sort((e,a)=>e.order-a.order),operators:a.getOperators().map(({name:a,parameters:d,...c})=>{const u=(e=>{const a={seeds:{},parameterDescriptions:{}};for(const n of[t,...r]){const r=o(n,e);if(void 0!==r){for(const e of["displayName","description","docUrl"]){const t=r[e];void 0!==t&&(a[e]=t)}Object.assign(a,s(r)),i(a.seeds,r.seeds),i(a.parameterDescriptions,r.parameterDescriptions)}}return a})(a),p={name:a,displayName:u.displayName??a,...c,...s(u)??s(e[c.category]),parameters:{}};void 0!==u.description&&(p.description=u.description),void 0!==u.docUrl&&(p.docUrl=u.docUrl);for(const[e,a]of Object.entries(d)){const r={...a,nullOutcome:l(e,a,d),seed:n(u,e,a.type)};if(!a.replacesNullAt&&[a.type].flat().every(e=>"array"===e||"object"===e)){const{homogeneous:e,elementShape:t}=a.constraints??{};r.elementNullOutcome=a.elementNullPolicy??(t||e&&!e.includes("any")?"error":"value")}const t=o(u.parameterDescriptions,e);void 0!==t&&(r.description=t),p.parameters[e]=r}return p}),fragments:a.getFragments().map(({name:e,parameters:a,...r})=>{const t=r.metadata??{},o={name:e,displayName:t.displayName??e,...r,...s(t),parameters:{}};void 0!==t.docUrl&&(o.docUrl=t.docUrl);for(const[e,r]of Object.entries(a))o.parameters[e]={...r,seed:n(t,e,r.type)};return o})});export{e as categoryListings,d as getCatalog,t as operatorListings,a as typeSeeds};