just-bash 2.9.0 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/{chunk-W2KVOOMM.js → chunk-FJTZ5HFK.js} +2 -2
- package/dist/bin/{shell/chunks/jq-TJPN2INT.js → chunks/jq-BMOLDA72.js} +1 -1
- package/dist/bin/chunks/sqlite3-CUDCXXK3.js +36 -0
- package/dist/bin/{shell/chunks/xan-OR7RSXSZ.js → chunks/xan-EAK3S7KJ.js} +1 -1
- package/dist/bin/chunks/{yq-WS7WDP36.js → yq-WYJ3A4JF.js} +1 -1
- package/dist/bin/just-bash.js +224 -224
- package/dist/bin/shell/chunks/{chunk-W2KVOOMM.js → chunk-FJTZ5HFK.js} +2 -2
- package/dist/bin/{chunks/jq-TJPN2INT.js → shell/chunks/jq-BMOLDA72.js} +1 -1
- package/dist/bin/shell/chunks/sqlite3-CUDCXXK3.js +36 -0
- package/dist/bin/{chunks/xan-OR7RSXSZ.js → shell/chunks/xan-EAK3S7KJ.js} +1 -1
- package/dist/bin/shell/chunks/{yq-WS7WDP36.js → yq-WYJ3A4JF.js} +1 -1
- package/dist/bin/shell/shell.js +230 -230
- package/dist/bundle/browser.js +419 -419
- package/dist/bundle/chunks/{chunk-ZWYFK7P5.js → chunk-IHEPHGKB.js} +2 -2
- package/dist/bundle/chunks/{jq-2LEQ2SZJ.js → jq-GMMYKAEP.js} +1 -1
- package/dist/bundle/chunks/sqlite3-DK5YHTWU.js +35 -0
- package/dist/bundle/chunks/{xan-I4Y5DD3C.js → xan-DYADHWWG.js} +1 -1
- package/dist/bundle/chunks/{yq-6RVO6I5Q.js → yq-5WHXPM6R.js} +1 -1
- package/dist/bundle/index.js +223 -223
- package/package.json +5 -2
- package/dist/bin/chunks/sqlite3-THMDBIGF.js +0 -36
- package/dist/bin/shell/chunks/sqlite3-THMDBIGF.js +0 -36
- package/dist/bundle/chunks/sqlite3-5QVZOGER.js +0 -35
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as Y,c as ct}from"./chunk-4PRVMER6.js";import{k as I}from"./chunk-K5IXNHO5.js";import{a as S}from"./chunk-SE4C7FJY.js";var pt=new Set(["__proto__","constructor","prototype"]),Ct=new Set([...pt,"__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]);function b(t){return!pt.has(t)}function g(t,r,e){b(r)&&(t[r]=e)}function N(t,r){return Object.hasOwn(t,r)}function G(t,r,e,n,p,i,u,c,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,y)=>{let a=p(h,e[0],n)[0],l=p(y,e[0],n)[0];return u(a,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:p(t,e[0],n).map(h=>{let y=0,a=t.length;for(;y<a;){let l=y+a>>>1;u(t[l],h)<0?y=l+1:a=l}return y<t.length&&u(t[y],h)===0?y:-y-1})}case"unique_by":{if(!Array.isArray(t)||e.length===0)return[null];let o=new Map;for(let y of t){let a=p(y,e[0],n)[0],l=JSON.stringify(a);o.has(l)||o.set(l,{item:y,key:a})}let h=[...o.values()];return h.sort((y,a)=>u(y.key,a.key)),[h.map(y=>y.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let o=new Map;for(let h of t){let y=JSON.stringify(p(h,e[0],n)[0]);o.has(y)||o.set(y,[]),o.get(y)?.push(h)}return[[...o.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((o,h)=>u(o,h)>0?o:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((o,h)=>{let y=p(o,e[0],n)[0],a=p(h,e[0],n)[0];return u(y,a)>0?o:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((o,h)=>u(o,h)<0?o:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((o,h)=>{let y=p(o,e[0],n)[0],a=p(h,e[0],n)[0];return u(y,a)<0?o:h})];case"add":{let o=h=>{let y=h.filter(a=>a!==null);return y.length===0?null:y.every(a=>typeof a=="number")?y.reduce((a,l)=>a+l,0):y.every(a=>typeof a=="string")?y.join(""):y.every(a=>Array.isArray(a))?y.flat():y.every(a=>a&&typeof a=="object"&&!Array.isArray(a))?ct(...y):null};if(e.length>=1){let h=p(t,e[0],n);return[o(h)]}return Array.isArray(t)?[o(t)]:[null]}case"any":{if(e.length>=2){try{let o=i(t,e[0],n);for(let h of o)if(p(h,e[1],n).some(c))return[!0]}catch(o){if(o instanceof f)throw o}return[!1]}return e.length===1?Array.isArray(t)?[t.some(o=>c(p(o,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(c)]:[!1]}case"all":{if(e.length>=2){try{let o=i(t,e[0],n);for(let h of o)if(!p(h,e[1],n).some(c))return[!1]}catch(o){if(o instanceof f)throw o}return[!0]}return e.length===1?Array.isArray(t)?[t.every(o=>c(p(o,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(c)]:[!0]}case"select":return e.length===0?[t]:p(t,e[0],n).some(c)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>p(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(o=>p(o,e[0],n))];if(t&&typeof t=="object"){let o=Object.create(null);for(let[h,y]of Object.entries(t)){if(!b(h))continue;let a=p(y,e[0],n);a.length>0&&g(o,h,a[0])}return[o]}return[null]}case"has":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h<t.length]:t&&typeof t=="object"&&typeof h=="string"?[N(t,h)]:[!1]}case"in":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(h)&&typeof t=="number"?[t>=0&&t<h.length]:h&&typeof h=="object"&&typeof t=="string"?[N(h,t)]:[!1]}case"contains":{if(e.length===0)return[!1];let o=p(t,e[0],n);return[s(t,o[0])]}case"inside":{if(e.length===0)return[!1];let o=p(t,e[0],n);return[s(o[0],t)]}default:return null}}function q(t,r,e,n,p,i,u,c){switch(r){case"first":if(e.length>0)try{let s=i(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof c)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=p(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=p(t,e[0],n);if(e.length>1){for(let o of s)if(o<0)throw new Error("nth doesn't support negative indices");let f;try{f=i(t,e[1],n)}catch(o){if(o instanceof c)throw o;f=[]}return s.flatMap(o=>{let h=o;return h<f.length?[f[h]]:[]})}return Array.isArray(t)?s.flatMap(f=>{let o=f;if(o<0)throw new Error("nth doesn't support negative indices");return o<t.length?[t[o]]:[null]}):[null]}case"range":{if(e.length===0)return[];let s=p(t,e[0],n);if(e.length===1){let y=[];for(let a of s){let l=a;for(let m=0;m<l;m++)y.push(m)}return y}let f=p(t,e[1],n);if(e.length===2){let y=[];for(let a of s)for(let l of f){let m=a,A=l;for(let E=m;E<A;E++)y.push(E)}return y}let o=p(t,e[2],n),h=[];for(let y of s)for(let a of f)for(let l of o){let m=y,A=a,E=l;if(E!==0)if(E>0)for(let w=m;w<A;w+=E)h.push(w);else for(let w=m;w>A;w+=E)h.push(w)}return h}case"limit":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let o=f;if(o<0)throw new Error("limit doesn't support negative count");if(o===0)return[];let h;try{h=i(t,e[1],n)}catch(y){if(y instanceof c)throw y;h=[]}return h.slice(0,o)});case"isempty":{if(e.length<1)return[!0];try{return[i(t,e[0],n).length===0]}catch(s){if(s instanceof c)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[p(t,e[0],n).length>0]}catch(s){if(s instanceof c)throw s;return[!1]}}case"skip":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let o=f;if(o<0)throw new Error("skip doesn't support negative count");return p(t,e[1],n).slice(o)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let o=0;o<f;o++){if(p(s,e[0],n).some(u))return[s];let y=p(s,e[1],n);if(y.length===0)return[s];s=y[0]}throw new c(`jq until: too many iterations (${f}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(e.length<2)return[t];let s=[],f=t,o=n.limits.maxIterations;for(let h=0;h<o&&p(f,e[0],n).some(u);h++){s.push(f);let a=p(f,e[1],n);if(a.length===0)break;f=a[0]}if(s.length>=o)throw new c(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,o=n.limits.maxIterations;for(let h=0;h<o;h++){s.push(f);let y=p(f,e[0],n);if(y.length===0)break;f=y[0]}if(s.length>=o)throw new c(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function X(t,r,e,n,p){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let i=new Date(t*1e3),u=i.getUTCFullYear(),c=i.getUTCMonth(),s=i.getUTCDate(),f=i.getUTCHours(),o=i.getUTCMinutes(),h=i.getUTCSeconds(),y=i.getUTCDay(),a=Date.UTC(u,0,1),l=Math.floor((i.getTime()-a)/(1440*60*1e3));return[[u,c,s,f,o,h,y,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[i,u,c,s=0,f=0,o=0]=t;if(typeof i!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(i,u,c??1,s??0,f??0,o??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let c;if(typeof t=="number")c=new Date(t*1e3);else if(Array.isArray(t)){let[y,a,l,m=0,A=0,E=0]=t;if(typeof y!="number"||typeof a!="number")throw new Error("strftime/1 requires parsed datetime inputs");c=new Date(Date.UTC(y,a,l??1,m??0,A??0,E??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],o=(y,a=2)=>String(y).padStart(a,"0");return[u.replace(/%Y/g,String(c.getUTCFullYear())).replace(/%m/g,o(c.getUTCMonth()+1)).replace(/%d/g,o(c.getUTCDate())).replace(/%H/g,o(c.getUTCHours())).replace(/%M/g,o(c.getUTCMinutes())).replace(/%S/g,o(c.getUTCSeconds())).replace(/%A/g,s[c.getUTCDay()]).replace(/%B/g,f[c.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,o,h,y,a,l]=s.map(Number),m=new Date(Date.UTC(f,o-1,h,y,a,l)),A=m.getUTCDay(),E=Date.UTC(f,0,1),w=Math.floor((m.getTime()-E)/(1440*60*1e3));return[[f,o-1,h,y,a,l,A,w]]}}let c=new Date(t);if(!Number.isNaN(c.getTime())){let s=c.getUTCFullYear(),f=c.getUTCMonth(),o=c.getUTCDate(),h=c.getUTCHours(),y=c.getUTCMinutes(),a=c.getUTCSeconds(),l=c.getUTCDay(),m=Date.UTC(s,0,1),A=Math.floor((c.getTime()-m)/(1440*60*1e3));return[[s,f,o,h,y,a,l,A]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let i=new Date(t);if(Number.isNaN(i.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(i.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function k(t){return t!==!1&&t!==null}function R(t,r){return JSON.stringify(t)===JSON.stringify(r)}function P(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function W(t,r){let e={...t};for(let n of Object.keys(r))b(n)&&(N(e,n)&&e[n]&&typeof e[n]=="object"&&!Array.isArray(e[n])&&r[n]&&typeof r[n]=="object"&&!Array.isArray(r[n])?g(e,n,W(e[n],r[n])):g(e,n,r[n]));return e}function M(t,r=3e3){let e=0,n=t;for(;e<r;)if(Array.isArray(n)){if(n.length===0)return e+1;n=n[0],e++}else if(n!==null&&typeof n=="object"){let p=Object.keys(n);if(p.length===0)return e+1;n=n[p[0]],e++}else return e;return e}function _(t,r){let e=i=>i===null?0:typeof i=="boolean"?1:typeof i=="number"?2:typeof i=="string"?3:Array.isArray(i)?4:typeof i=="object"?5:6,n=e(t),p=e(r);if(n!==p)return n-p;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let i=0;i<Math.min(t.length,r.length);i++){let u=_(t[i],r[i]);if(u!==0)return u}return t.length-r.length}if(t&&r&&typeof t=="object"&&typeof r=="object"){let i=t,u=r,c=Object.keys(i).sort(),s=Object.keys(u).sort();for(let f=0;f<Math.min(c.length,s.length);f++){let o=c[f].localeCompare(s[f]);if(o!==0)return o}if(c.length!==s.length)return c.length-s.length;for(let f of c){let o=_(i[f],u[f]);if(o!==0)return o}}return 0}function U(t,r){if(R(t,r))return!0;if(typeof t=="string"&&typeof r=="string")return t.includes(r);if(Array.isArray(t)&&Array.isArray(r))return r.every(e=>t.some(n=>U(n,e)));if(t&&r&&typeof t=="object"&&typeof r=="object"&&!Array.isArray(t)&&!Array.isArray(r)){let e=t,n=r;return Object.keys(n).every(p=>N(e,p)&&U(e[p],n[p]))}return!1}var At=2e3;function Q(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(p=>{if(p===null)return"";if(typeof p=="boolean")return p?"true":"false";if(typeof p=="number")return String(p);let i=String(p);return i.includes(",")||i.includes('"')||i.includes(`
|
|
3
|
-
`)||i.includes("\r")?`"${i.replace(/"/g,'""')}"`:i}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??At;return M(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function Z(t,r,e,n,p,i){switch(r){case"index":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){if(c===""&&t==="")return null;let s=t.indexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let f=0;f<=t.length-c.length;f++){let o=!0;for(let h=0;h<c.length;h++)if(!i(t[f+h],c[h])){o=!1;break}if(o)return f}return null}let s=t.findIndex(f=>i(f,c));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){let s=t.lastIndexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let s=t.length-c.length;s>=0;s--){let f=!0;for(let o=0;o<c.length;o++)if(!i(t[s+o],c[o])){f=!1;break}if(f)return s}return null}for(let s=t.length-1;s>=0;s--)if(i(t[s],c))return s;return null}return null});case"indices":return e.length===0?[[]]:p(t,e[0],n).map(c=>{let s=[];if(typeof t=="string"&&typeof c=="string"){let f=t.indexOf(c);for(;f!==-1;)s.push(f),f=t.indexOf(c,f+1)}else if(Array.isArray(t))if(Array.isArray(c)){let f=c.length;if(f===0)for(let o=0;o<=t.length;o++)s.push(o);else for(let o=0;o<=t.length-f;o++){let h=!0;for(let y=0;y<f;y++)if(!i(t[o+y],c[y])){h=!1;break}h&&s.push(o)}}else for(let f=0;f<t.length;f++)i(t[f],c)&&s.push(f);return s});default:return null}}function z(t,r,e,n,p){switch(r){case"fabs":case"abs":return typeof t=="number"?[Math.abs(t)]:typeof t=="string"?[t]:[null];case"exp10":return typeof t=="number"?[10**t]:[null];case"exp2":return typeof t=="number"?[2**t]:[null];case"pow":{if(e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=i[0],s=u[0];return typeof c!="number"||typeof s!="number"?[null]:[c**s]}case"atan2":{if(e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=i[0],s=u[0];return typeof c!="number"||typeof s!="number"?[null]:[Math.atan2(c,s)]}case"hypot":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.hypot(t,i)]}case"fma":{if(typeof t!="number"||e.length<2)return[null];let i=p(t,e[0],n)[0],u=p(t,e[1],n)[0];return[t*i+u]}case"copysign":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.sign(i)*Math.abs(t)]}case"drem":case"remainder":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t-Math.round(t/i)*i]}case"fdim":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.max(0,t-i)]}case"fmax":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.max(t,i)]}case"fmin":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.min(t,i)]}case"ldexp":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t*2**i]}case"scalbn":case"scalbln":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t*2**i]}case"nearbyint":return typeof t=="number"?[Math.round(t)]:[null];case"logb":return typeof t=="number"?[Math.floor(Math.log2(Math.abs(t)))]:[null];case"significand":if(typeof t=="number"){let i=Math.floor(Math.log2(Math.abs(t)));return[t/2**i]}return[null];case"frexp":if(typeof t=="number"){if(t===0)return[[0,0]];let i=Math.floor(Math.log2(Math.abs(t)))+1;return[[t/2**i,i]]}return[null];case"modf":if(typeof t=="number"){let i=Math.trunc(t);return[[t-i,i]]}return[null];default:return null}}function v(t,r,e,n,p,i,u,c){switch(r){case"recurse":{if(e.length===0){let a=[],l=m=>{if(a.push(m),Array.isArray(m))for(let A of m)l(A);else if(m&&typeof m=="object")for(let A of Object.keys(m))l(m[A])};return l(t),a}let s=[],f=e.length>=2?e[1]:null,o=1e4,h=0,y=a=>{if(h++>o||f&&!p(a,f,n).some(i))return;s.push(a);let l=p(a,e[0],n);for(let m of l)m!=null&&y(m)};return y(t),s}case"recurse_down":return c(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=o=>{if(o&&typeof o=="object"){if(s.has(o))return o;s.add(o)}let h;if(Array.isArray(o))h=o.map(f);else if(o&&typeof o=="object"){let a=Object.create(null);for(let[l,m]of Object.entries(o))b(l)&&g(a,l,f(m));h=a}else h=o;return p(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(o=>Array.isArray(o)?o.length:0)),f=[];for(let o=0;o<s;o++)f.push(t.map(h=>Array.isArray(h)?h[o]:null));return[f]}case"combinations":{if(e.length>0){let h=p(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let y=[],a=(l,m)=>{if(m===h){y.push([...l]);return}for(let A of t)l.push(A),a(l,m+1),l.pop()};return a([],0),y}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let o of t)if(!Array.isArray(o))return[];let s=[],f=(o,h)=>{if(o===t.length){s.push([...h]);return}let y=t[o];for(let a of y)h.push(a),f(o+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?p(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let o=s.slice(0,s.length-f);return[u(n.root,o)]}else{let o=-f-1;if(o>=s.length)return[t];let h=s.slice(0,o);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let o=s.length-1;o>=0;o--)f.push(u(n.root,s.slice(0,o)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var bt=2e3;function tt(t,r,e,n,p){switch(r){case"keys":return Array.isArray(t)?[t.map((i,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((i,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let i=t===null?"null":Array.isArray(t)?"array":typeof t,u=i==="array"||i==="object"?JSON.stringify(t):String(t);throw new Error(`${i} (${u}) only strings have UTF-8 byte length`)}case"to_entries":return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([i,u])=>({key:i,value:u}))]:[null];case"from_entries":if(Array.isArray(t)){let i=Object.create(null);for(let u of t)if(u&&typeof u=="object"){let c=u,s=c.key??c.Key??c.name??c.Name??c.k,f=c.value??c.Value??c.v;if(s!==void 0){let o=String(s);b(o)&&g(i,o,f)}}return[i]}return[null];case"with_entries":{if(e.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let u=Object.entries(t).map(([s,f])=>({key:s,value:f})).flatMap(s=>p(s,e[0],n)),c=Object.create(null);for(let s of u)if(s&&typeof s=="object"){let f=s,o=f.key??f.name??f.k,h=f.value??f.v;if(o!==void 0){let y=String(o);b(y)&&g(c,y,h)}}return[c]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?p(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let c=u;if(c<0)throw new Error("flatten depth must not be negative");return t.flat(c)}):[null];case"unique":if(Array.isArray(t)){let i=new Set,u=[];for(let c of t){let s=JSON.stringify(c);i.has(s)||(i.add(s),u.push(c))}return[u]}return[null];case"tojson":case"tojsonstream":{let i=n.limits.maxDepth??bt;return M(t,i+1)>i?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let i=t.trim().toLowerCase();if(i==="nan")return[Number.NaN];if(i==="inf"||i==="infinity")return[Number.POSITIVE_INFINITY];if(i==="-inf"||i==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[JSON.parse(t)]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let i=Number(t);if(Number.isNaN(i))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[i]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let i=t===null?"null":Array.isArray(t)?"array":typeof t,u=i==="array"||i==="object"?JSON.stringify(t):String(t);throw new Error(`${i} (${u}) cannot be parsed as a boolean`)}case"tostream":{let i=[],u=(c,s)=>{if(c===null||typeof c!="object")i.push([s,c]);else if(Array.isArray(c))if(c.length===0)i.push([s,[]]);else for(let f=0;f<c.length;f++)u(c[f],[...s,f]);else{let f=Object.keys(c);if(f.length===0)i.push([s,{}]);else for(let o of f)u(c[o],[...s,o])}};return u(t,[]),i.push([[]]),i}case"fromstream":{if(e.length===0)return[t];let i=p(t,e[0],n),u=null;for(let c of i){if(!Array.isArray(c)||c.length===1&&Array.isArray(c[0])&&c[0].length===0||c.length!==2)continue;let[s,f]=c;if(!Array.isArray(s))continue;if(s.length===0){u=f;continue}u===null&&(u=typeof s[0]=="number"?[]:{});let o=u;for(let y=0;y<s.length-1;y++){let a=s[y],l=s[y+1];if(Array.isArray(o)&&typeof a=="number"){for(;o.length<=a;)o.push(null);o[a]===null&&(o[a]=typeof l=="number"?[]:{}),o=o[a]}else if(o&&typeof o=="object"&&!Array.isArray(o)){let m=String(a);if(!b(m))continue;let A=o;(A[m]===null||A[m]===void 0)&&g(A,m,typeof l=="number"?[]:{}),o=A[m]}}let h=s[s.length-1];if(Array.isArray(o)&&typeof h=="number"){for(;o.length<=h;)o.push(null);o[h]=f}else if(o&&typeof o=="object"&&!Array.isArray(o)){let y=String(h);b(y)&&g(o,y,f)}}return[u]}case"truncate_stream":{let i=typeof t=="number"?Math.floor(t):0;if(e.length===0)return[];let u=[],c=p(t,e[0],n);for(let s of c)if(Array.isArray(s)){if(s.length===1&&Array.isArray(s[0])){let f=s[0];f.length>i&&u.push([f.slice(i)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],o=s[1];f.length>i&&u.push([f.slice(i),o])}}return u}default:return null}}function et(t,r,e,n,p,i,u,c,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let o=p(t,e[0],n),h=[];for(let y of o){let a=y,l=t;for(let m of a){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof l=="object"&&typeof m=="string")l=l[m];else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=p(t,e[0],n)[0],a=p(t,e[1],n)[0];return[u(t,h,a)]}case"delpaths":{if(e.length===0)return[t];let h=p(t,e[0],n)[0],y=t;for(let a of h.sort((l,m)=>m.length-l.length))y=c(y,a);return[y]}case"path":{if(e.length===0)return[[]];let o=[];return f(t,e[0],n,[],o),o}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let o=[];for(let y of e)f(t,y,n,[],o);let h=null;for(let y of o){for(let l of y)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let a=t;for(let l of y){if(a==null)break;if(Array.isArray(a)&&typeof l=="number")a=a[l];else if(typeof a=="object"&&typeof l=="string")a=a[l];else{a=null;break}}h=u(h,y,a)}return[h]}case"paths":{let o=[],h=(y,a)=>{if(y&&typeof y=="object")if(Array.isArray(y))for(let l=0;l<y.length;l++)o.push([...a,l]),h(y[l],[...a,l]);else for(let l of Object.keys(y))o.push([...a,l]),h(y[l],[...a,l])};return h(t,[]),e.length>0?o.filter(y=>{let a=t;for(let m of y)if(Array.isArray(a)&&typeof m=="number")a=a[m];else if(a&&typeof a=="object"&&typeof m=="string")a=a[m];else return!1;return p(a,e[0],n).some(i)}):o}case"leaf_paths":{let o=[],h=(y,a)=>{if(y===null||typeof y!="object")o.push(a);else if(Array.isArray(y))for(let l=0;l<y.length;l++)h(y[l],[...a,l]);else for(let l of Object.keys(y))h(y[l],[...a,l])};return h(t,[]),o}default:return null}}function rt(t,r,e,n,p,i){switch(r){case"IN":{if(e.length===0)return[!1];if(e.length===1){let f=p(t,e[0],n);for(let o of f)if(i(t,o))return[!0];return[!1]}let u=p(t,e[0],n),c=p(t,e[1],n),s=new Set(c.map(f=>JSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[{}];if(e.length===1){let s=p(t,e[0],n),f=Object.create(null);for(let o of s){let h=String(o);b(h)&&g(f,h,o)}return[f]}if(e.length===2){let s=p(t,e[0],n),f=Object.create(null);for(let o of s){let h=p(o,e[1],n);if(h.length>0){let y=String(h[0]);b(y)&&g(f,y,o)}}return[f]}let u=p(t,e[0],n),c=Object.create(null);for(let s of u){let f=p(s,e[1],n),o=p(s,e[2],n);if(f.length>0&&o.length>0){let h=String(f[0]);b(h)&&g(c,h,o[0])}}return[c]}case"JOIN":{if(e.length<2)return[null];let u=p(t,e[0],n)[0];if(!u||typeof u!="object"||Array.isArray(u))return[null];let c=u;if(!Array.isArray(t))return[null];let s=[];for(let f of t){let o=p(f,e[1],n),h=o.length>0?String(o[0]):"",y=N(c,h)?c[h]:null;s.push([f,y])}return[s]}default:return null}}function nt(t,r,e,n,p){switch(r){case"join":{if(!Array.isArray(t))return[null];let i=e.length>0?p(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return i.map(u=>t.map(c=>c===null?"":typeof c=="string"?c:String(c)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"g";return S(u,c.includes("g")?c:`${c}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[...S(u,c.includes("g")?c:`${c}g`).matchAll(t)].map(o=>o.length>1?o.slice(1):o[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[S(u,c).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=S(u,`${c}d`).exec(t);if(!f)return[];let o=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,y)=>({offset:o?.[y+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=S(u,c).match(t);return!f||!f.groups?[{}]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=String(i[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"";return[S(c,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=String(i[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"g",o=f.includes("g")?f:`${f}g`;return[S(c,o).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,i=>String.fromCharCode(i.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,i=>String.fromCharCode(i.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);if(u==="")return[t];let c=t;return c.startsWith(u)&&(c=c.slice(u.length)),c.endsWith(u)&&(c=c.slice(0,-u.length)),[c]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n);return[t.startsWith(String(i[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n);return[t.endsWith(String(i[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(i=>i.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(c=>{if(typeof c=="string")throw new Error(`string (${JSON.stringify(c)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof c!="number"||Number.isNaN(c))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(c);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function st(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function L(t,r,e){if(r.length===0)return e;let[n,...p]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let s=Array.isArray(t)?[...t]:[];for(;s.length<=n;)s.push(null);return s[n]=L(s[n],p,e),s}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!b(n))return t??{};let i=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{},u=Object.hasOwn(i,n)?i[n]:void 0;return g(i,n,L(u,p,e)),i}function $(t,r){if(r.length===0)return null;if(r.length===1){let p=r[0];if(Array.isArray(t)&&typeof p=="number"){let i=[...t];return i.splice(p,1),i}if(t&&typeof t=="object"&&!Array.isArray(t)){let i=String(p);if(!b(i))return t;let u={...t};return delete u[i],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let p=[...t];return p[e]=$(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!b(p))return t;let i={...t};return Object.hasOwn(i,p)&&g(i,p,$(i[p],n)),i}return t}var j=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},K=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},gt=1e4,yt=2e3,Et=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function wt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??gt,maxDepth:t?.limits?.maxDepth??yt},env:t?.env}}function V(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels}}function D(t,r,e){switch(r.type){case"var":return V(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let p=0;p<r.elements.length;p++){let i=r.elements[p],u=p<e.length?e[p]:null,c=D(n,i,u);if(c===null)return null;n=c}return n}case"object":{if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e,p=t;for(let i of r.fields){let u;if(typeof i.key=="string")u=i.key;else{let f=d(e,i.key,t);if(f.length===0)return null;u=String(f[0])}let c=N(n,u)?n[u]:null;i.keyVar&&(p=V(p,i.keyVar,c));let s=D(p,i.pattern,c);if(s===null)return null;p=s}return p}}}function kt(t,r){let e=t;for(let n of r)if(e&&typeof e=="object")e=e[n];else return;return e}function O(t){if(t.type==="Identity")return[];if(t.type==="Field"){let r=t.base?O(t.base):[];return r===null?null:[...r,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let r=t.base?O(t.base):[];if(r===null)return null;let e=t.index.value;return typeof e=="number"||typeof e=="string"?[...r,e]:null}if(t.type==="Pipe"){let r=O(t.left);return r===null?null:it(r,t.right)}if(t.type==="Call"){if(t.name==="parent"||t.name==="root")return null;if(t.name==="first"&&t.args.length===0)return[0];if(t.name==="last"&&t.args.length===0)return[-1]}return null}function it(t,r){if(r.type==="Call"){if(r.name==="parent"){let e=1;if(r.args.length>0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=O(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=O(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=it(t,r.left);return e===null?null:it(e,r.right)}return r.type==="Identity"?t:null}function ut(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof I)throw p;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(p){if(p instanceof I)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:wt(e);switch(n.root===void 0&&(n={...n,root:t,currentPath:[]}),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(i=>{if(i&&typeof i=="object"&&!Array.isArray(i)){let c=i[r.name];return[c===void 0?null:c]}if(i===null)return[null];let u=Array.isArray(i)?"array":typeof i;throw new Error(`Cannot index ${u} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(i=>d(i,r.index,n).flatMap(c=>{if(typeof c=="number"&&Array.isArray(i)){if(Number.isNaN(c))return[null];let s=Math.trunc(c),f=s<0?i.length+s:s;return f>=0&&f<i.length?[i[f]]:[null]}return typeof c=="string"&&i&&typeof i=="object"&&!Array.isArray(i)?[i[c]]:[null]}));case"Slice":return(r.base?d(t,r.base,n):[t]).flatMap(i=>{if(i===null)return[null];if(!Array.isArray(i)&&typeof i!="string")throw new Error(`Cannot slice ${typeof i} (${JSON.stringify(i)})`);let u=i.length,c=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return c.flatMap(f=>s.map(o=>{let h=f,y=o,a=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(y)?u:Number.isInteger(y)?y:Math.ceil(y),m=ht(a,u),A=ht(l,u);return Array.isArray(i),i.slice(m,A)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(i=>Array.isArray(i)?i:i&&typeof i=="object"?Object.values(i):[]);case"Pipe":{let p=d(t,r.left,n),i=O(r.left),u=[];for(let c of p)try{if(i!==null){let s={...n,currentPath:[...n.currentPath??[],...i]};u.push(...d(c,r.right,s))}else u.push(...d(c,r.right,n))}catch(s){throw s instanceof j?s.withPrependedResults(u):s}return u}case"Comma":{let p=d(t,r.left,n),i=d(t,r.right,n);return[...p,...i]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let p=[{}];for(let i of r.entries){let u=typeof i.key=="string"?[i.key]:d(t,i.key,n),c=d(t,i.value,n),s=[];for(let f of p)for(let o of u){if(typeof o!="string"){let h=o===null?"null":Array.isArray(o)?"array":typeof o;throw new Error(`Cannot use ${h} (${JSON.stringify(o)}) as object key`)}if(!b(o)){for(let h of c)s.push({...f});continue}for(let h of c){let y={...f};g(y,o,h),s.push(y)}}p.length=0,p.push(...s)}return p}case"Paren":return d(t,r.expr,n);case"BinaryOp":return Ot(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(i=>{if(r.op==="-"){if(typeof i=="number")return-i;if(typeof i=="string"){let u=c=>c.length>5?`"${c.slice(0,3)}...`:JSON.stringify(c);throw new Error(`string (${u(i)}) cannot be negated`)}return null}return r.op==="not"?!k(i):null});case"Cond":return d(t,r.cond,n).flatMap(i=>{if(k(i))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(k))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(p){if(r.catch){let i=p instanceof K?p.value:p instanceof Error?p.message:String(p);return d(i,r.catch,n)}return[]}case"Call":return at(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(i=>{let u=null,c=[];r.pattern?c.push(r.pattern):r.name&&c.push({type:"var",name:r.name}),r.alternatives&&c.push(...r.alternatives);for(let s of c)if(u=D(n,s,i),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?Y(n.env):{}];let p=n.vars.get(r.name);return p!==void 0?[p]:[null]}case"Recurse":{let p=[],i=new WeakSet,u=c=>{if(c&&typeof c=="object"){if(i.has(c))return;i.add(c)}if(p.push(c),Array.isArray(c))for(let s of c)u(s);else if(c&&typeof c=="object")for(let s of Object.keys(c))u(c[s])};return u(t),p}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(i=>typeof i=="string"?i:d(t,i,n).map(c=>typeof c=="string"?c:JSON.stringify(c)).join("")).join("")];case"UpdateOp":return[Nt(t,r.path,r.op,r.value,n)];case"Reduce":{let p=d(t,r.expr,n),i=d(t,r.init,n)[0],u=n.limits.maxDepth??yt;for(let c of p){let s;if(r.pattern){if(s=D(n,r.pattern,c),s===null)continue}else s=V(n,r.varName,c);if(i=d(i,r.update,s)[0],M(i,u+1)>u)return[null]}return[i]}case"Foreach":{let p=d(t,r.expr,n),i=d(t,r.init,n)[0],u=[];for(let c of p)try{let s;if(r.pattern){if(s=D(n,r.pattern,c),s===null)continue}else s=V(n,r.varName,c);if(i=d(i,r.update,s)[0],r.extract){let f=d(i,r.extract,s);u.push(...f)}else u.push(i)}catch(s){throw s instanceof j?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(p){if(p instanceof j&&p.label===r.name)return p.partialResults;throw p}case"Break":throw new j(r.name);case"Def":{let p=new Map(n.funcs??[]),i=`${r.name}/${r.params.length}`;p.set(i,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:p};return d(t,r.body,u)}default:{let p=r;throw new Error(`Unknown AST node type: ${p.type}`)}}}function ht(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Nt(t,r,e,n,p){function i(s,f){switch(e){case"=":return f;case"|=":return d(s,n,p)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?{...s,...f}:f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,o){switch(f.type){case"Identity":return o(s);case"Field":{if(!b(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let y={...h},a=Object.hasOwn(y,f.name)?y[f.name]:void 0;return g(y,f.name,o(a)),y}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h={...s},y=Object.hasOwn(h,f.name)?h[f.name]:void 0;return g(h,f.name,o(y)),h}return s}case"Index":{let y=d(t,f.index,p)[0];if(typeof y=="number"&&Number.isNaN(y))throw new Error("Cannot set array element at NaN index");if(typeof y=="number"&&!Number.isInteger(y)&&(y=Math.trunc(y)),f.base)return u(s,f.base,a=>{if(typeof y=="number"&&Array.isArray(a)){let l=[...a],m=y<0?l.length+y:y;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=o(l[m])}return l}if(typeof y=="string"&&a&&typeof a=="object"&&!Array.isArray(a)){if(!b(y))return a;let l={...a},m=Object.hasOwn(l,y)?l[y]:void 0;return g(l,y,o(m)),l}return a});if(typeof y=="number"){if(y>536870911)throw new Error("Array index too large");if(y<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=y<0?l.length+y:y;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=o(l[m])}return l}if(s==null){let l=[];for(;l.length<=y;)l.push(null);return l[y]=o(null),l}return s}if(typeof y=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!b(y))return s;let a={...s},l=Object.hasOwn(a,y)?a[y]:void 0;return g(a,y,o(l)),a}return s}case"Iterate":{let h=y=>{if(Array.isArray(y))return y.map(a=>o(a));if(y&&typeof y=="object"){let a=Object.create(null);for(let[l,m]of Object.entries(y))b(l)&&g(a,l,o(m));return a}return y};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,y=>y);return u(h,f.right,o)}default:return o(s)}}return u(t,r,s=>{if(e==="|=")return i(s,s);let f=d(t,n,p);return i(s,f[0]??null)})}function St(t,r,e){function n(i,u,c){switch(u.type){case"Identity":return c;case"Field":{if(!b(u.name))return i;if(u.base){let s=d(i,u.base,e)[0],f=n(s,{type:"Field",name:u.name},c);return n(i,u.base,f)}if(i&&typeof i=="object"&&!Array.isArray(i)){let s={...i};return g(s,u.name,c),s}return i}case"Index":{if(u.base){let o=d(i,u.base,e)[0],h=n(o,{type:"Index",index:u.index},c);return n(i,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(i)){let o=[...i],h=f<0?o.length+f:f;return h>=0&&h<o.length&&(o[h]=c),o}if(typeof f=="string"&&i&&typeof i=="object"&&!Array.isArray(i)){if(!b(f))return i;let o={...i};return g(o,f,c),o}return i}default:return i}}function p(i,u){switch(u.type){case"Identity":return null;case"Field":{if(!b(u.name))return i;if(u.base){let s=d(i,u.base,e)[0];if(s==null)return i;let f=p(s,{type:"Field",name:u.name});return n(i,u.base,f)}if(i&&typeof i=="object"&&!Array.isArray(i)){if(!b(u.name))return i;let s={...i};return delete s[u.name],s}return i}case"Index":{if(u.base){let o=d(i,u.base,e)[0];if(o==null)return i;let h=p(o,{type:"Index",index:u.index});return n(i,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(i)){let o=[...i],h=f<0?o.length+f:f;return h>=0&&h<o.length&&o.splice(h,1),o}if(typeof f=="string"&&i&&typeof i=="object"&&!Array.isArray(i)){if(!b(f))return i;let o={...i};return delete o[f],o}return i}case"Iterate":return Array.isArray(i)?[]:i&&typeof i=="object"?{}:i;case"Pipe":{let o=function(a,l,m){switch(l.type){case"Identity":return m;case"Field":{if(!b(l.name))return a;if(a&&typeof a=="object"&&!Array.isArray(a)){let A={...a};return g(A,l.name,m),A}return a}case"Index":{let E=d(t,l.index,e)[0];if(typeof E=="number"&&Array.isArray(a)){let w=[...a],x=E<0?w.length+E:E;return x>=0&&x<w.length&&(w[x]=m),w}if(typeof E=="string"&&a&&typeof a=="object"&&!Array.isArray(a)){if(!b(E))return a;let w={...a};return g(w,E,m),w}return a}case"Pipe":{let A=d(a,l.left,e)[0],E=o(A,l.right,m);return o(a,l.left,E)}default:return a}};var c=o;let s=u.left,f=u.right,h=d(i,s,e)[0];if(h==null)return i;let y=p(h,f);return o(i,s,y)}default:return i}}return p(t,r)}function Ot(t,r,e,n,p){if(r==="and")return d(t,e,p).flatMap(s=>k(s)?d(t,n,p).map(o=>k(o)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>k(s)?[!0]:d(t,n,p).map(o=>k(o)));if(r==="//"){let s=d(t,e,p).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,p)}let i=d(t,e,p),u=d(t,n,p);return i.flatMap(c=>u.map(s=>{switch(r){case"+":return c===null?s:s===null?c:typeof c=="number"&&typeof s=="number"||typeof c=="string"&&typeof s=="string"?c+s:Array.isArray(c)&&Array.isArray(s)?[...c,...s]:c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?{...c,...s}:null;case"-":if(typeof c=="number"&&typeof s=="number")return c-s;if(Array.isArray(c)&&Array.isArray(s)){let f=new Set(s.map(o=>JSON.stringify(o)));return c.filter(o=>!f.has(JSON.stringify(o)))}if(typeof c=="string"&&typeof s=="string"){let f=o=>o.length>10?`"${o.slice(0,10)}...`:JSON.stringify(o);throw new Error(`string (${f(c)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":return typeof c=="number"&&typeof s=="number"?c*s:typeof c=="string"&&typeof s=="number"?c.repeat(s):c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?W(c,s):null;case"/":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided because the divisor is zero`);return c/s}return typeof c=="string"&&typeof s=="string"?c.split(s):null;case"%":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(c)&&!Number.isNaN(c)?!Number.isFinite(s)&&!Number.isNaN(s)&&c<0&&s>0?-1:0:c%s}return null;case"==":return R(c,s);case"!=":return!R(c,s);case"<":return P(c,s)<0;case"<=":return P(c,s)<=0;case">":return P(c,s)>0;case">=":return P(c,s)>=0;default:return null}}))}function at(t,r,e,n){let p=Et.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let i=z(t,r,e,n,d);if(i!==null)return i;let u=nt(t,r,e,n,d);if(u!==null)return u;let c=X(t,r,e,n,d);if(c!==null)return c;let s=Q(t,r,n.limits.maxDepth);if(s!==null)return s;let f=st(t,r);if(f!==null)return f;let o=tt(t,r,e,n,d);if(o!==null)return o;let h=G(t,r,e,n,d,ut,_,k,U,I);if(h!==null)return h;let y=et(t,r,e,n,d,k,L,$,St,F);if(y!==null)return y;let a=Z(t,r,e,n,d,R);if(a!==null)return a;let l=q(t,r,e,n,d,ut,k,I);if(l!==null)return l;let m=v(t,r,e,n,d,k,kt,at);if(m!==null)return m;let A=rt(t,r,e,n,d,R);if(A!==null)return A;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let E=e.length>0?d(t,e[0],n)[0]:t;throw new K(E)}case"env":return[n.env?Y(n.env):{}];case"debug":return[t];case"input_line_number":return[1];default:{let E=`${r}/${e.length}`,w=n.funcs?.get(E);if(w){let x=w.closure??n.funcs??new Map,J=new Map(x);J.set(E,w);for(let B=0;B<w.params.length;B++){let dt=w.params[B],ft=e[B];if(ft){let T=d(t,ft,n),C;if(T.length===0)C={type:"Call",name:"empty",args:[]};else if(T.length===1)C={type:"Literal",value:T[0]};else{C={type:"Literal",value:T[T.length-1]};for(let H=T.length-2;H>=0;H--)C={type:"Comma",left:{type:"Literal",value:T[H]},right:C}}J.set(`${dt}/0`,{params:[],body:C})}}let mt={...n,funcs:J};return d(t,w.body,mt)}throw new Error(`Unknown function: ${r}`)}}}function F(t,r,e,n,p){if(r.type==="Comma"){let c=r;F(t,c.left,e,n,p),F(t,c.right,e,n,p);return}let i=O(r);if(i!==null){p.push([...n,...i]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let c=0;c<t.length;c++)p.push([...n,c]);else if(t&&typeof t=="object")for(let c of Object.keys(t))p.push([...n,c]);return}if(r.type==="Recurse"){let c=(s,f)=>{if(p.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let o=0;o<s.length;o++)c(s[o],[...f,o]);else for(let o of Object.keys(s))c(s[o],[...f,o])};c(t,[]);return}if(r.type==="Pipe"){let c=O(r.left);if(c!==null){let s=d(t,r.left,e);for(let f of s)F(f,r.right,e,[...n,...c],p);return}}d(t,r,e).length>0&&p.push(n)}var Tt=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]);function lt(t){let r=[],e=0,n=(f=0)=>t[e+f],p=()=>t[e++],i=()=>e>=t.length,u=f=>f>="0"&&f<="9",c=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>c(f)||u(f);for(;!i();){let f=e,o=p();if(!(o===" "||o===" "||o===`
|
|
2
|
+
import{a as Y,c as ct}from"./chunk-4PRVMER6.js";import{k as I}from"./chunk-K5IXNHO5.js";import{a as N}from"./chunk-SE4C7FJY.js";var pt=new Set(["__proto__","constructor","prototype"]),Ct=new Set([...pt,"__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]);function b(t){return!pt.has(t)}function g(t,r,e){b(r)&&(t[r]=e)}function O(t,r){return Object.hasOwn(t,r)}function G(t,r,e,n,p,i,u,c,s,f){switch(r){case"sort":return Array.isArray(t)?[[...t].sort(u)]:[null];case"sort_by":return!Array.isArray(t)||e.length===0?[null]:[[...t].sort((h,y)=>{let a=p(h,e[0],n)[0],l=p(y,e[0],n)[0];return u(a,l)})];case"bsearch":{if(!Array.isArray(t)){let h=t===null?"null":typeof t=="object"?"object":typeof t;throw new Error(`${h} (${JSON.stringify(t)}) cannot be searched from`)}return e.length===0?[null]:p(t,e[0],n).map(h=>{let y=0,a=t.length;for(;y<a;){let l=y+a>>>1;u(t[l],h)<0?y=l+1:a=l}return y<t.length&&u(t[y],h)===0?y:-y-1})}case"unique_by":{if(!Array.isArray(t)||e.length===0)return[null];let o=new Map;for(let y of t){let a=p(y,e[0],n)[0],l=JSON.stringify(a);o.has(l)||o.set(l,{item:y,key:a})}let h=[...o.values()];return h.sort((y,a)=>u(y.key,a.key)),[h.map(y=>y.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let o=new Map;for(let h of t){let y=JSON.stringify(p(h,e[0],n)[0]);o.has(y)||o.set(y,[]),o.get(y)?.push(h)}return[[...o.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((o,h)=>u(o,h)>0?o:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((o,h)=>{let y=p(o,e[0],n)[0],a=p(h,e[0],n)[0];return u(y,a)>0?o:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((o,h)=>u(o,h)<0?o:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((o,h)=>{let y=p(o,e[0],n)[0],a=p(h,e[0],n)[0];return u(y,a)<0?o:h})];case"add":{let o=h=>{let y=h.filter(a=>a!==null);return y.length===0?null:y.every(a=>typeof a=="number")?y.reduce((a,l)=>a+l,0):y.every(a=>typeof a=="string")?y.join(""):y.every(a=>Array.isArray(a))?y.flat():y.every(a=>a&&typeof a=="object"&&!Array.isArray(a))?ct(...y):null};if(e.length>=1){let h=p(t,e[0],n);return[o(h)]}return Array.isArray(t)?[o(t)]:[null]}case"any":{if(e.length>=2){try{let o=i(t,e[0],n);for(let h of o)if(p(h,e[1],n).some(c))return[!0]}catch(o){if(o instanceof f)throw o}return[!1]}return e.length===1?Array.isArray(t)?[t.some(o=>c(p(o,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(c)]:[!1]}case"all":{if(e.length>=2){try{let o=i(t,e[0],n);for(let h of o)if(!p(h,e[1],n).some(c))return[!1]}catch(o){if(o instanceof f)throw o}return[!0]}return e.length===1?Array.isArray(t)?[t.every(o=>c(p(o,e[0],n)[0]))]:[!0]:Array.isArray(t)?[t.every(c)]:[!0]}case"select":return e.length===0?[t]:p(t,e[0],n).some(c)?[t]:[];case"map":return e.length===0||!Array.isArray(t)?[null]:[t.flatMap(h=>p(h,e[0],n))];case"map_values":{if(e.length===0)return[null];if(Array.isArray(t))return[t.flatMap(o=>p(o,e[0],n))];if(t&&typeof t=="object"){let o=Object.create(null);for(let[h,y]of Object.entries(t)){if(!b(h))continue;let a=p(y,e[0],n);a.length>0&&g(o,h,a[0])}return[o]}return[null]}case"has":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(t)&&typeof h=="number"?[h>=0&&h<t.length]:t&&typeof t=="object"&&typeof h=="string"?[O(t,h)]:[!1]}case"in":{if(e.length===0)return[!1];let h=p(t,e[0],n)[0];return Array.isArray(h)&&typeof t=="number"?[t>=0&&t<h.length]:h&&typeof h=="object"&&typeof t=="string"?[O(h,t)]:[!1]}case"contains":{if(e.length===0)return[!1];let o=p(t,e[0],n);return[s(t,o[0])]}case"inside":{if(e.length===0)return[!1];let o=p(t,e[0],n);return[s(o[0],t)]}default:return null}}function q(t,r,e,n,p,i,u,c){switch(r){case"first":if(e.length>0)try{let s=i(t,e[0],n);return s.length>0?[s[0]]:[]}catch(s){if(s instanceof c)throw s;return[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(e.length>0){let s=p(t,e[0],n);return s.length>0?[s[s.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(e.length<1)return[null];let s=p(t,e[0],n);if(e.length>1){for(let o of s)if(o<0)throw new Error("nth doesn't support negative indices");let f;try{f=i(t,e[1],n)}catch(o){if(o instanceof c)throw o;f=[]}return s.flatMap(o=>{let h=o;return h<f.length?[f[h]]:[]})}return Array.isArray(t)?s.flatMap(f=>{let o=f;if(o<0)throw new Error("nth doesn't support negative indices");return o<t.length?[t[o]]:[null]}):[null]}case"range":{if(e.length===0)return[];let s=p(t,e[0],n);if(e.length===1){let y=[];for(let a of s){let l=a;for(let m=0;m<l;m++)y.push(m)}return y}let f=p(t,e[1],n);if(e.length===2){let y=[];for(let a of s)for(let l of f){let m=a,A=l;for(let E=m;E<A;E++)y.push(E)}return y}let o=p(t,e[2],n),h=[];for(let y of s)for(let a of f)for(let l of o){let m=y,A=a,E=l;if(E!==0)if(E>0)for(let w=m;w<A;w+=E)h.push(w);else for(let w=m;w>A;w+=E)h.push(w)}return h}case"limit":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let o=f;if(o<0)throw new Error("limit doesn't support negative count");if(o===0)return[];let h;try{h=i(t,e[1],n)}catch(y){if(y instanceof c)throw y;h=[]}return h.slice(0,o)});case"isempty":{if(e.length<1)return[!0];try{return[i(t,e[0],n).length===0]}catch(s){if(s instanceof c)throw s;return[!0]}}case"isvalid":{if(e.length<1)return[!0];try{return[p(t,e[0],n).length>0]}catch(s){if(s instanceof c)throw s;return[!1]}}case"skip":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let o=f;if(o<0)throw new Error("skip doesn't support negative count");return p(t,e[1],n).slice(o)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let o=0;o<f;o++){if(p(s,e[0],n).some(u))return[s];let y=p(s,e[1],n);if(y.length===0)return[s];s=y[0]}throw new c(`jq until: too many iterations (${f}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(e.length<2)return[t];let s=[],f=t,o=n.limits.maxIterations;for(let h=0;h<o&&p(f,e[0],n).some(u);h++){s.push(f);let a=p(f,e[1],n);if(a.length===0)break;f=a[0]}if(s.length>=o)throw new c(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,o=n.limits.maxIterations;for(let h=0;h<o;h++){s.push(f);let y=p(f,e[0],n);if(y.length===0)break;f=y[0]}if(s.length>=o)throw new c(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return s}default:return null}}function X(t,r,e,n,p){switch(r){case"now":return[Date.now()/1e3];case"gmtime":{if(typeof t!="number")return[null];let i=new Date(t*1e3),u=i.getUTCFullYear(),c=i.getUTCMonth(),s=i.getUTCDate(),f=i.getUTCHours(),o=i.getUTCMinutes(),h=i.getUTCSeconds(),y=i.getUTCDay(),a=Date.UTC(u,0,1),l=Math.floor((i.getTime()-a)/(1440*60*1e3));return[[u,c,s,f,o,h,y,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[i,u,c,s=0,f=0,o=0]=t;if(typeof i!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(i,u,c??1,s??0,f??0,o??0);return[Math.floor(h/1e3)]}case"strftime":{if(e.length===0)return[null];let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strftime/1 requires a string format");let c;if(typeof t=="number")c=new Date(t*1e3);else if(Array.isArray(t)){let[y,a,l,m=0,A=0,E=0]=t;if(typeof y!="number"||typeof a!="number")throw new Error("strftime/1 requires parsed datetime inputs");c=new Date(Date.UTC(y,a,l??1,m??0,A??0,E??0))}else throw new Error("strftime/1 requires parsed datetime inputs");let s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],f=["January","February","March","April","May","June","July","August","September","October","November","December"],o=(y,a=2)=>String(y).padStart(a,"0");return[u.replace(/%Y/g,String(c.getUTCFullYear())).replace(/%m/g,o(c.getUTCMonth()+1)).replace(/%d/g,o(c.getUTCDate())).replace(/%H/g,o(c.getUTCHours())).replace(/%M/g,o(c.getUTCMinutes())).replace(/%S/g,o(c.getUTCSeconds())).replace(/%A/g,s[c.getUTCDay()]).replace(/%B/g,f[c.getUTCMonth()]).replace(/%Z/g,"UTC").replace(/%%/g,"%")]}case"strptime":{if(e.length===0)return[null];if(typeof t!="string")throw new Error("strptime/1 requires a string input");let u=p(t,e[0],n)[0];if(typeof u!="string")throw new Error("strptime/1 requires a string format");if(u==="%Y-%m-%dT%H:%M:%SZ"){let s=t.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);if(s){let[,f,o,h,y,a,l]=s.map(Number),m=new Date(Date.UTC(f,o-1,h,y,a,l)),A=m.getUTCDay(),E=Date.UTC(f,0,1),w=Math.floor((m.getTime()-E)/(1440*60*1e3));return[[f,o-1,h,y,a,l,A,w]]}}let c=new Date(t);if(!Number.isNaN(c.getTime())){let s=c.getUTCFullYear(),f=c.getUTCMonth(),o=c.getUTCDate(),h=c.getUTCHours(),y=c.getUTCMinutes(),a=c.getUTCSeconds(),l=c.getUTCDay(),m=Date.UTC(s,0,1),A=Math.floor((c.getTime()-m)/(1440*60*1e3));return[[s,f,o,h,y,a,l,A]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let i=new Date(t);if(Number.isNaN(i.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(i.getTime()/1e3)]}case"todate":{if(typeof t!="number")throw new Error("todate requires a number input");return[new Date(t*1e3).toISOString().replace(/\.\d{3}Z$/,"Z")]}default:return null}}function k(t){return t!==!1&&t!==null}function R(t,r){return JSON.stringify(t)===JSON.stringify(r)}function P(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function W(t,r){let e={...t};for(let n of Object.keys(r))b(n)&&(O(e,n)&&e[n]&&typeof e[n]=="object"&&!Array.isArray(e[n])&&r[n]&&typeof r[n]=="object"&&!Array.isArray(r[n])?g(e,n,W(e[n],r[n])):g(e,n,r[n]));return e}function j(t,r=3e3){let e=0,n=t;for(;e<r;)if(Array.isArray(n)){if(n.length===0)return e+1;n=n[0],e++}else if(n!==null&&typeof n=="object"){let p=Object.keys(n);if(p.length===0)return e+1;n=n[p[0]],e++}else return e;return e}function _(t,r){let e=i=>i===null?0:typeof i=="boolean"?1:typeof i=="number"?2:typeof i=="string"?3:Array.isArray(i)?4:typeof i=="object"?5:6,n=e(t),p=e(r);if(n!==p)return n-p;if(typeof t=="number"&&typeof r=="number")return t-r;if(typeof t=="string"&&typeof r=="string")return t.localeCompare(r);if(typeof t=="boolean"&&typeof r=="boolean")return(t?1:0)-(r?1:0);if(Array.isArray(t)&&Array.isArray(r)){for(let i=0;i<Math.min(t.length,r.length);i++){let u=_(t[i],r[i]);if(u!==0)return u}return t.length-r.length}if(t&&r&&typeof t=="object"&&typeof r=="object"){let i=t,u=r,c=Object.keys(i).sort(),s=Object.keys(u).sort();for(let f=0;f<Math.min(c.length,s.length);f++){let o=c[f].localeCompare(s[f]);if(o!==0)return o}if(c.length!==s.length)return c.length-s.length;for(let f of c){let o=_(i[f],u[f]);if(o!==0)return o}}return 0}function U(t,r){if(R(t,r))return!0;if(typeof t=="string"&&typeof r=="string")return t.includes(r);if(Array.isArray(t)&&Array.isArray(r))return r.every(e=>t.some(n=>U(n,e)));if(t&&r&&typeof t=="object"&&typeof r=="object"&&!Array.isArray(t)&&!Array.isArray(r)){let e=t,n=r;return Object.keys(n).every(p=>O(e,p)&&U(e[p],n[p]))}return!1}var At=2e3;function Q(t,r,e){switch(r){case"@base64":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"utf-8").toString("base64")]:[btoa(t)]:[null];case"@base64d":return typeof t=="string"?typeof Buffer<"u"?[Buffer.from(t,"base64").toString("utf-8")]:[atob(t)]:[null];case"@uri":return typeof t=="string"?[encodeURIComponent(t).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A")]:[null];case"@urid":return typeof t=="string"?[decodeURIComponent(t)]:[null];case"@csv":return Array.isArray(t)?[t.map(p=>{if(p===null)return"";if(typeof p=="boolean")return p?"true":"false";if(typeof p=="number")return String(p);let i=String(p);return i.includes(",")||i.includes('"')||i.includes(`
|
|
3
|
+
`)||i.includes("\r")?`"${i.replace(/"/g,'""')}"`:i}).join(",")]:[null];case"@tsv":return Array.isArray(t)?[t.map(n=>String(n??"").replace(/\t/g,"\\t").replace(/\n/g,"\\n")).join(" ")]:[null];case"@json":{let n=e??At;return j(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""")]:[null];case"@sh":return typeof t=="string"?[`'${t.replace(/'/g,"'\\''")}'`]:[null];case"@text":return typeof t=="string"?[t]:t==null?[""]:[String(t)];default:return null}}function Z(t,r,e,n,p,i){switch(r){case"index":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){if(c===""&&t==="")return null;let s=t.indexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let f=0;f<=t.length-c.length;f++){let o=!0;for(let h=0;h<c.length;h++)if(!i(t[f+h],c[h])){o=!1;break}if(o)return f}return null}let s=t.findIndex(f=>i(f,c));return s>=0?s:null}return null});case"rindex":return e.length===0?[null]:p(t,e[0],n).map(c=>{if(typeof t=="string"&&typeof c=="string"){let s=t.lastIndexOf(c);return s>=0?s:null}if(Array.isArray(t)){if(Array.isArray(c)){for(let s=t.length-c.length;s>=0;s--){let f=!0;for(let o=0;o<c.length;o++)if(!i(t[s+o],c[o])){f=!1;break}if(f)return s}return null}for(let s=t.length-1;s>=0;s--)if(i(t[s],c))return s;return null}return null});case"indices":return e.length===0?[[]]:p(t,e[0],n).map(c=>{let s=[];if(typeof t=="string"&&typeof c=="string"){let f=t.indexOf(c);for(;f!==-1;)s.push(f),f=t.indexOf(c,f+1)}else if(Array.isArray(t))if(Array.isArray(c)){let f=c.length;if(f===0)for(let o=0;o<=t.length;o++)s.push(o);else for(let o=0;o<=t.length-f;o++){let h=!0;for(let y=0;y<f;y++)if(!i(t[o+y],c[y])){h=!1;break}h&&s.push(o)}}else for(let f=0;f<t.length;f++)i(t[f],c)&&s.push(f);return s});default:return null}}function z(t,r,e,n,p){switch(r){case"fabs":case"abs":return typeof t=="number"?[Math.abs(t)]:typeof t=="string"?[t]:[null];case"exp10":return typeof t=="number"?[10**t]:[null];case"exp2":return typeof t=="number"?[2**t]:[null];case"pow":{if(e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=i[0],s=u[0];return typeof c!="number"||typeof s!="number"?[null]:[c**s]}case"atan2":{if(e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=i[0],s=u[0];return typeof c!="number"||typeof s!="number"?[null]:[Math.atan2(c,s)]}case"hypot":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.hypot(t,i)]}case"fma":{if(typeof t!="number"||e.length<2)return[null];let i=p(t,e[0],n)[0],u=p(t,e[1],n)[0];return[t*i+u]}case"copysign":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.sign(i)*Math.abs(t)]}case"drem":case"remainder":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t-Math.round(t/i)*i]}case"fdim":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.max(0,t-i)]}case"fmax":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.max(t,i)]}case"fmin":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[Math.min(t,i)]}case"ldexp":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t*2**i]}case"scalbn":case"scalbln":{if(typeof t!="number"||e.length===0)return[null];let i=p(t,e[0],n)[0];return[t*2**i]}case"nearbyint":return typeof t=="number"?[Math.round(t)]:[null];case"logb":return typeof t=="number"?[Math.floor(Math.log2(Math.abs(t)))]:[null];case"significand":if(typeof t=="number"){let i=Math.floor(Math.log2(Math.abs(t)));return[t/2**i]}return[null];case"frexp":if(typeof t=="number"){if(t===0)return[[0,0]];let i=Math.floor(Math.log2(Math.abs(t)))+1;return[[t/2**i,i]]}return[null];case"modf":if(typeof t=="number"){let i=Math.trunc(t);return[[t-i,i]]}return[null];default:return null}}function v(t,r,e,n,p,i,u,c){switch(r){case"recurse":{if(e.length===0){let a=[],l=m=>{if(a.push(m),Array.isArray(m))for(let A of m)l(A);else if(m&&typeof m=="object")for(let A of Object.keys(m))l(m[A])};return l(t),a}let s=[],f=e.length>=2?e[1]:null,o=1e4,h=0,y=a=>{if(h++>o||f&&!p(a,f,n).some(i))return;s.push(a);let l=p(a,e[0],n);for(let m of l)m!=null&&y(m)};return y(t),s}case"recurse_down":return c(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=o=>{if(o&&typeof o=="object"){if(s.has(o))return o;s.add(o)}let h;if(Array.isArray(o))h=o.map(f);else if(o&&typeof o=="object"){let a=Object.create(null);for(let[l,m]of Object.entries(o))b(l)&&g(a,l,f(m));h=a}else h=o;return p(h,e[0],n)[0]};return[f(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let s=Math.max(...t.map(o=>Array.isArray(o)?o.length:0)),f=[];for(let o=0;o<s;o++)f.push(t.map(h=>Array.isArray(h)?h[o]:null));return[f]}case"combinations":{if(e.length>0){let h=p(t,e[0],n)[0];if(!Array.isArray(t)||h<0)return[];if(h===0)return[[]];let y=[],a=(l,m)=>{if(m===h){y.push([...l]);return}for(let A of t)l.push(A),a(l,m+1),l.pop()};return a([],0),y}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let o of t)if(!Array.isArray(o))return[];let s=[],f=(o,h)=>{if(o===t.length){s.push([...h]);return}let y=t[o];for(let a of y)h.push(a),f(o+1,h),h.pop()};return f(0,[]),s}case"parent":{if(n.root===void 0||n.currentPath===void 0)return[];let s=n.currentPath;if(s.length===0)return[];let f=e.length>0?p(t,e[0],n)[0]:1;if(f>=0){if(f>s.length)return[];let o=s.slice(0,s.length-f);return[u(n.root,o)]}else{let o=-f-1;if(o>=s.length)return[t];let h=s.slice(0,o);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let o=s.length-1;o>=0;o--)f.push(u(n.root,s.slice(0,o)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var bt=2e3;function tt(t,r,e,n,p){switch(r){case"keys":return Array.isArray(t)?[t.map((i,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((i,u)=>u)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"length":return typeof t=="string"?[t.length]:Array.isArray(t)?[t.length]:t&&typeof t=="object"?[Object.keys(t).length]:t===null?[0]:typeof t=="number"?[Math.abs(t)]:[null];case"utf8bytelength":{if(typeof t=="string")return[new TextEncoder().encode(t).length];let i=t===null?"null":Array.isArray(t)?"array":typeof t,u=i==="array"||i==="object"?JSON.stringify(t):String(t);throw new Error(`${i} (${u}) only strings have UTF-8 byte length`)}case"to_entries":return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([i,u])=>({key:i,value:u}))]:[null];case"from_entries":if(Array.isArray(t)){let i=Object.create(null);for(let u of t)if(u&&typeof u=="object"){let c=u,s=c.key??c.Key??c.name??c.Name??c.k,f=c.value??c.Value??c.v;if(s!==void 0){let o=String(s);b(o)&&g(i,o,f)}}return[i]}return[null];case"with_entries":{if(e.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let u=Object.entries(t).map(([s,f])=>({key:s,value:f})).flatMap(s=>p(s,e[0],n)),c=Object.create(null);for(let s of u)if(s&&typeof s=="object"){let f=s,o=f.key??f.name??f.k,h=f.value??f.v;if(o!==void 0){let y=String(o);b(y)&&g(c,y,h)}}return[c]}return[null]}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"flatten":return Array.isArray(t)?(e.length>0?p(t,e[0],n):[Number.POSITIVE_INFINITY]).map(u=>{let c=u;if(c<0)throw new Error("flatten depth must not be negative");return t.flat(c)}):[null];case"unique":if(Array.isArray(t)){let i=new Set,u=[];for(let c of t){let s=JSON.stringify(c);i.has(s)||(i.add(s),u.push(c))}return[u]}return[null];case"tojson":case"tojsonstream":{let i=n.limits.maxDepth??bt;return j(t,i+1)>i?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let i=t.trim().toLowerCase();if(i==="nan")return[Number.NaN];if(i==="inf"||i==="infinity")return[Number.POSITIVE_INFINITY];if(i==="-inf"||i==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[JSON.parse(t)]}catch{throw new Error(`Invalid JSON: ${t}`)}}return[t]}case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let i=Number(t);if(Number.isNaN(i))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[i]}throw new Error(`${typeof t} cannot be parsed as a number`);case"toboolean":{if(typeof t=="boolean")return[t];if(typeof t=="string"){if(t==="true")return[!0];if(t==="false")return[!1];throw new Error(`string (${JSON.stringify(t)}) cannot be parsed as a boolean`)}let i=t===null?"null":Array.isArray(t)?"array":typeof t,u=i==="array"||i==="object"?JSON.stringify(t):String(t);throw new Error(`${i} (${u}) cannot be parsed as a boolean`)}case"tostream":{let i=[],u=(c,s)=>{if(c===null||typeof c!="object")i.push([s,c]);else if(Array.isArray(c))if(c.length===0)i.push([s,[]]);else for(let f=0;f<c.length;f++)u(c[f],[...s,f]);else{let f=Object.keys(c);if(f.length===0)i.push([s,{}]);else for(let o of f)u(c[o],[...s,o])}};return u(t,[]),i.push([[]]),i}case"fromstream":{if(e.length===0)return[t];let i=p(t,e[0],n),u=null;for(let c of i){if(!Array.isArray(c)||c.length===1&&Array.isArray(c[0])&&c[0].length===0||c.length!==2)continue;let[s,f]=c;if(!Array.isArray(s))continue;if(s.length===0){u=f;continue}u===null&&(u=typeof s[0]=="number"?[]:{});let o=u;for(let y=0;y<s.length-1;y++){let a=s[y],l=s[y+1];if(Array.isArray(o)&&typeof a=="number"){for(;o.length<=a;)o.push(null);o[a]===null&&(o[a]=typeof l=="number"?[]:{}),o=o[a]}else if(o&&typeof o=="object"&&!Array.isArray(o)){let m=String(a);if(!b(m))continue;let A=o;(A[m]===null||A[m]===void 0)&&g(A,m,typeof l=="number"?[]:{}),o=A[m]}}let h=s[s.length-1];if(Array.isArray(o)&&typeof h=="number"){for(;o.length<=h;)o.push(null);o[h]=f}else if(o&&typeof o=="object"&&!Array.isArray(o)){let y=String(h);b(y)&&g(o,y,f)}}return[u]}case"truncate_stream":{let i=typeof t=="number"?Math.floor(t):0;if(e.length===0)return[];let u=[],c=p(t,e[0],n);for(let s of c)if(Array.isArray(s)){if(s.length===1&&Array.isArray(s[0])){let f=s[0];f.length>i&&u.push([f.slice(i)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],o=s[1];f.length>i&&u.push([f.slice(i),o])}}return u}default:return null}}function et(t,r,e,n,p,i,u,c,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let o=p(t,e[0],n),h=[];for(let y of o){let a=y,l=t;for(let m of a){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof l=="object"&&typeof m=="string"){let A=l;if(!Object.hasOwn(A,m)){l=null;break}l=A[m]}else{l=null;break}}h.push(l)}return h}case"setpath":{if(e.length<2)return[null];let h=p(t,e[0],n)[0],a=p(t,e[1],n)[0];return[u(t,h,a)]}case"delpaths":{if(e.length===0)return[t];let h=p(t,e[0],n)[0],y=t;for(let a of h.sort((l,m)=>m.length-l.length))y=c(y,a);return[y]}case"path":{if(e.length===0)return[[]];let o=[];return f(t,e[0],n,[],o),o}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let o=[];for(let y of e)f(t,y,n,[],o);let h=null;for(let y of o){for(let l of y)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let a=t;for(let l of y){if(a==null)break;if(Array.isArray(a)&&typeof l=="number")a=a[l];else if(typeof a=="object"&&typeof l=="string"){let m=a;if(!Object.hasOwn(m,l)){a=null;break}a=m[l]}else{a=null;break}}h=u(h,y,a)}return[h]}case"paths":{let o=[],h=(y,a)=>{if(y&&typeof y=="object")if(Array.isArray(y))for(let l=0;l<y.length;l++)o.push([...a,l]),h(y[l],[...a,l]);else for(let l of Object.keys(y))o.push([...a,l]),h(y[l],[...a,l])};return h(t,[]),e.length>0?o.filter(y=>{let a=t;for(let m of y)if(Array.isArray(a)&&typeof m=="number")a=a[m];else if(a&&typeof a=="object"&&typeof m=="string"){let A=a;if(!Object.hasOwn(A,m))return!1;a=A[m]}else return!1;return p(a,e[0],n).some(i)}):o}case"leaf_paths":{let o=[],h=(y,a)=>{if(y===null||typeof y!="object")o.push(a);else if(Array.isArray(y))for(let l=0;l<y.length;l++)h(y[l],[...a,l]);else for(let l of Object.keys(y))h(y[l],[...a,l])};return h(t,[]),o}default:return null}}function rt(t,r,e,n,p,i){switch(r){case"IN":{if(e.length===0)return[!1];if(e.length===1){let f=p(t,e[0],n);for(let o of f)if(i(t,o))return[!0];return[!1]}let u=p(t,e[0],n),c=p(t,e[1],n),s=new Set(c.map(f=>JSON.stringify(f)));for(let f of u)if(s.has(JSON.stringify(f)))return[!0];return[!1]}case"INDEX":{if(e.length===0)return[{}];if(e.length===1){let s=p(t,e[0],n),f=Object.create(null);for(let o of s){let h=String(o);b(h)&&g(f,h,o)}return[f]}if(e.length===2){let s=p(t,e[0],n),f=Object.create(null);for(let o of s){let h=p(o,e[1],n);if(h.length>0){let y=String(h[0]);b(y)&&g(f,y,o)}}return[f]}let u=p(t,e[0],n),c=Object.create(null);for(let s of u){let f=p(s,e[1],n),o=p(s,e[2],n);if(f.length>0&&o.length>0){let h=String(f[0]);b(h)&&g(c,h,o[0])}}return[c]}case"JOIN":{if(e.length<2)return[null];let u=p(t,e[0],n)[0];if(!u||typeof u!="object"||Array.isArray(u))return[null];let c=u;if(!Array.isArray(t))return[null];let s=[];for(let f of t){let o=p(f,e[1],n),h=o.length>0?String(o[0]):"",y=O(c,h)?c[h]:null;s.push([f,y])}return[s]}default:return null}}function nt(t,r,e,n,p){switch(r){case"join":{if(!Array.isArray(t))return[null];let i=e.length>0?p(t,e[0],n):[""];for(let u of t)if(Array.isArray(u)||u!==null&&typeof u=="object")throw new Error("cannot join: contains arrays or objects");return i.map(u=>t.map(c=>c===null?"":typeof c=="string"?c:String(c)).join(String(u)))}case"split":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"g";return N(u,c.includes("g")?c:`${c}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[...N(u,c.includes("g")?c:`${c}g`).matchAll(t)].map(o=>o.length>1?o.slice(1):o[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[N(u,c).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=N(u,`${c}d`).exec(t);if(!f)return[];let o=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,y)=>({offset:o?.[y+1]?.[0]??null,length:h?.length??0,string:h??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||e.length===0)return[null];let i=p(t,e[0],n),u=String(i[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=N(u,c).match(t);return!f||!f.groups?[{}]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=String(i[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"";return[N(c,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let i=p(t,e[0],n),u=p(t,e[1],n),c=String(i[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"g",o=f.includes("g")?f:`${f}g`;return[N(c,o).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,i=>String.fromCharCode(i.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,i=>String.fromCharCode(i.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);return u===""?[t]:[t.endsWith(u)?t.slice(0,-u.length):t]}case"trimstr":{if(typeof t!="string"||e.length===0)return[t];let i=p(t,e[0],n),u=String(i[0]);if(u==="")return[t];let c=t;return c.startsWith(u)&&(c=c.slice(u.length)),c.endsWith(u)&&(c=c.slice(0,-u.length)),[c]}case"trim":if(typeof t=="string")return[t.trim()];throw new Error("trim input must be a string");case"ltrim":if(typeof t=="string")return[t.trimStart()];throw new Error("trim input must be a string");case"rtrim":if(typeof t=="string")return[t.trimEnd()];throw new Error("trim input must be a string");case"startswith":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n);return[t.startsWith(String(i[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let i=p(t,e[0],n);return[t.endsWith(String(i[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(i=>i.codePointAt(0))]:[null];case"implode":if(!Array.isArray(t))throw new Error("implode input must be an array");return[t.map(c=>{if(typeof c=="string")throw new Error(`string (${JSON.stringify(c)}) can't be imploded, unicode codepoint needs to be numeric`);if(typeof c!="number"||Number.isNaN(c))throw new Error("number (null) can't be imploded, unicode codepoint needs to be numeric");let s=Math.trunc(c);return s<0||s>1114111||s>=55296&&s<=57343?String.fromCodePoint(65533):String.fromCodePoint(s)}).join("")];default:return null}}function st(t,r){switch(r){case"type":return t===null?["null"]:Array.isArray(t)?["array"]:typeof t=="boolean"?["boolean"]:typeof t=="number"?["number"]:typeof t=="string"?["string"]:typeof t=="object"?["object"]:["null"];case"infinite":return[Number.POSITIVE_INFINITY];case"nan":return[Number.NaN];case"isinfinite":return[typeof t=="number"&&!Number.isFinite(t)];case"isnan":return[typeof t=="number"&&Number.isNaN(t)];case"isnormal":return[typeof t=="number"&&Number.isFinite(t)&&t!==0];case"isfinite":return[typeof t=="number"&&Number.isFinite(t)];case"numbers":return typeof t=="number"?[t]:[];case"strings":return typeof t=="string"?[t]:[];case"booleans":return typeof t=="boolean"?[t]:[];case"nulls":return t===null?[t]:[];case"arrays":return Array.isArray(t)?[t]:[];case"objects":return t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"iterables":return Array.isArray(t)||t&&typeof t=="object"&&!Array.isArray(t)?[t]:[];case"scalars":return!Array.isArray(t)&&!(t&&typeof t=="object")?[t]:[];case"values":return t===null?[]:[t];case"not":return t===!1||t===null?[!0]:[!1];case"null":return[null];case"true":return[!0];case"false":return[!1];case"empty":return[];default:return null}}function L(t,r,e){if(r.length===0)return e;let[n,...p]=r;if(typeof n=="number"){if(t&&typeof t=="object"&&!Array.isArray(t))throw new Error("Cannot index object with number");if(n>536870911)throw new Error("Array index too large");if(n<0)throw new Error("Out of bounds negative array index");let s=Array.isArray(t)?[...t]:[];for(;s.length<=n;)s.push(null);return s[n]=L(s[n],p,e),s}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!b(n))return t??{};let i=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{},u=Object.hasOwn(i,n)?i[n]:void 0;return g(i,n,L(u,p,e)),i}function $(t,r){if(r.length===0)return null;if(r.length===1){let p=r[0];if(Array.isArray(t)&&typeof p=="number"){let i=[...t];return i.splice(p,1),i}if(t&&typeof t=="object"&&!Array.isArray(t)){let i=String(p);if(!b(i))return t;let u={...t};return delete u[i],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let p=[...t];return p[e]=$(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!b(p))return t;let i={...t};return Object.hasOwn(i,p)&&g(i,p,$(i[p],n)),i}return t}var M=class t extends Error{label;partialResults;constructor(r,e=[]){super(`break ${r}`),this.label=r,this.partialResults=e,this.name="BreakError"}withPrependedResults(r){return new t(this.label,[...r,...this.partialResults])}},K=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},gt=1e4,yt=2e3,Et=new Map([["floor",Math.floor],["ceil",Math.ceil],["round",Math.round],["sqrt",Math.sqrt],["log",Math.log],["log10",Math.log10],["log2",Math.log2],["exp",Math.exp],["sin",Math.sin],["cos",Math.cos],["tan",Math.tan],["asin",Math.asin],["acos",Math.acos],["atan",Math.atan],["sinh",Math.sinh],["cosh",Math.cosh],["tanh",Math.tanh],["asinh",Math.asinh],["acosh",Math.acosh],["atanh",Math.atanh],["cbrt",Math.cbrt],["expm1",Math.expm1],["log1p",Math.log1p],["trunc",Math.trunc]]);function wt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??gt,maxDepth:t?.limits?.maxDepth??yt},env:t?.env}}function V(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels}}function D(t,r,e){switch(r.type){case"var":return V(t,r.name,e);case"array":{if(!Array.isArray(e))return null;let n=t;for(let p=0;p<r.elements.length;p++){let i=r.elements[p],u=p<e.length?e[p]:null,c=D(n,i,u);if(c===null)return null;n=c}return n}case"object":{if(e===null||typeof e!="object"||Array.isArray(e))return null;let n=e,p=t;for(let i of r.fields){let u;if(typeof i.key=="string")u=i.key;else{let f=d(e,i.key,t);if(f.length===0)return null;u=String(f[0])}let c=O(n,u)?n[u]:null;i.keyVar&&(p=V(p,i.keyVar,c));let s=D(p,i.pattern,c);if(s===null)return null;p=s}return p}}}function kt(t,r){let e=t;for(let n of r)if(e&&typeof e=="object")if(Array.isArray(e))if(typeof n=="number")e=e[n];else return;else{let p=e;if(typeof n=="string"&&Object.hasOwn(p,n))e=p[n];else return}else return;return e}function S(t){if(t.type==="Identity")return[];if(t.type==="Field"){let r=t.base?S(t.base):[];return r===null?null:[...r,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let r=t.base?S(t.base):[];if(r===null)return null;let e=t.index.value;return typeof e=="number"||typeof e=="string"?[...r,e]:null}if(t.type==="Pipe"){let r=S(t.left);return r===null?null:it(r,t.right)}if(t.type==="Call"){if(t.name==="parent"||t.name==="root")return null;if(t.name==="first"&&t.args.length===0)return[0];if(t.name==="last"&&t.args.length===0)return[-1]}return null}function it(t,r){if(r.type==="Call"){if(r.name==="parent"){let e=1;if(r.args.length>0&&r.args[0].type==="Literal"){let n=r.args[0].value;typeof n=="number"&&(e=n)}if(e>=0)return t.slice(0,Math.max(0,t.length-e));{let n=-e-1;return t.slice(0,Math.min(n,t.length))}}if(r.name==="root")return[]}if(r.type==="Field"){let e=S(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=S(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=it(t,r.left);return e===null?null:it(e,r.right)}return r.type==="Identity"?t:null}function ut(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof I)throw p;if(n.length>0)return n;throw new Error("evaluation failed")}try{n.push(...d(t,r.right,e))}catch(p){if(p instanceof I)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:wt(e);switch(n.root===void 0&&(n={...n,root:t,currentPath:[]}),r.type){case"Identity":return[t];case"Field":return(r.base?d(t,r.base,n):[t]).flatMap(i=>{if(i&&typeof i=="object"&&!Array.isArray(i)){let c=i;if(!Object.hasOwn(c,r.name))return[null];let s=c[r.name];return[s===void 0?null:s]}if(i===null)return[null];let u=Array.isArray(i)?"array":typeof i;throw new Error(`Cannot index ${u} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(i=>d(i,r.index,n).flatMap(c=>{if(typeof c=="number"&&Array.isArray(i)){if(Number.isNaN(c))return[null];let s=Math.trunc(c),f=s<0?i.length+s:s;return f>=0&&f<i.length?[i[f]]:[null]}if(typeof c=="string"&&i&&typeof i=="object"&&!Array.isArray(i)){let s=i;return Object.hasOwn(s,c)?[s[c]]:[null]}return[null]}));case"Slice":return(r.base?d(t,r.base,n):[t]).flatMap(i=>{if(i===null)return[null];if(!Array.isArray(i)&&typeof i!="string")throw new Error(`Cannot slice ${typeof i} (${JSON.stringify(i)})`);let u=i.length,c=r.start?d(t,r.start,n):[0],s=r.end?d(t,r.end,n):[u];return c.flatMap(f=>s.map(o=>{let h=f,y=o,a=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(y)?u:Number.isInteger(y)?y:Math.ceil(y),m=ht(a,u),A=ht(l,u);return Array.isArray(i),i.slice(m,A)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(i=>Array.isArray(i)?i:i&&typeof i=="object"?Object.values(i):[]);case"Pipe":{let p=d(t,r.left,n),i=S(r.left),u=[];for(let c of p)try{if(i!==null){let s={...n,currentPath:[...n.currentPath??[],...i]};u.push(...d(c,r.right,s))}else u.push(...d(c,r.right,n))}catch(s){throw s instanceof M?s.withPrependedResults(u):s}return u}case"Comma":{let p=d(t,r.left,n),i=d(t,r.right,n);return[...p,...i]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let p=[{}];for(let i of r.entries){let u=typeof i.key=="string"?[i.key]:d(t,i.key,n),c=d(t,i.value,n),s=[];for(let f of p)for(let o of u){if(typeof o!="string"){let h=o===null?"null":Array.isArray(o)?"array":typeof o;throw new Error(`Cannot use ${h} (${JSON.stringify(o)}) as object key`)}if(!b(o)){for(let h of c)s.push({...f});continue}for(let h of c){let y={...f};g(y,o,h),s.push(y)}}p.length=0,p.push(...s)}return p}case"Paren":return d(t,r.expr,n);case"BinaryOp":return St(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(i=>{if(r.op==="-"){if(typeof i=="number")return-i;if(typeof i=="string"){let u=c=>c.length>5?`"${c.slice(0,3)}...`:JSON.stringify(c);throw new Error(`string (${u(i)}) cannot be negated`)}return null}return r.op==="not"?!k(i):null});case"Cond":return d(t,r.cond,n).flatMap(i=>{if(k(i))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(k))return d(t,u.then,n);return r.else?d(t,r.else,n):[t]});case"Try":try{return d(t,r.body,n)}catch(p){if(r.catch){let i=p instanceof K?p.value:p instanceof Error?p.message:String(p);return d(i,r.catch,n)}return[]}case"Call":return at(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(i=>{let u=null,c=[];r.pattern?c.push(r.pattern):r.name&&c.push({type:"var",name:r.name}),r.alternatives&&c.push(...r.alternatives);for(let s of c)if(u=D(n,s,i),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?Y(n.env):{}];let p=n.vars.get(r.name);return p!==void 0?[p]:[null]}case"Recurse":{let p=[],i=new WeakSet,u=c=>{if(c&&typeof c=="object"){if(i.has(c))return;i.add(c)}if(p.push(c),Array.isArray(c))for(let s of c)u(s);else if(c&&typeof c=="object")for(let s of Object.keys(c))u(c[s])};return u(t),p}case"Optional":try{return d(t,r.expr,n)}catch{return[]}case"StringInterp":return[r.parts.map(i=>typeof i=="string"?i:d(t,i,n).map(c=>typeof c=="string"?c:JSON.stringify(c)).join("")).join("")];case"UpdateOp":return[Ot(t,r.path,r.op,r.value,n)];case"Reduce":{let p=d(t,r.expr,n),i=d(t,r.init,n)[0],u=n.limits.maxDepth??yt;for(let c of p){let s;if(r.pattern){if(s=D(n,r.pattern,c),s===null)continue}else s=V(n,r.varName,c);if(i=d(i,r.update,s)[0],j(i,u+1)>u)return[null]}return[i]}case"Foreach":{let p=d(t,r.expr,n),i=d(t,r.init,n)[0],u=[];for(let c of p)try{let s;if(r.pattern){if(s=D(n,r.pattern,c),s===null)continue}else s=V(n,r.varName,c);if(i=d(i,r.update,s)[0],r.extract){let f=d(i,r.extract,s);u.push(...f)}else u.push(i)}catch(s){throw s instanceof M?s.withPrependedResults(u):s}return u}case"Label":try{return d(t,r.body,{...n,labels:new Set([...n.labels??[],r.name])})}catch(p){if(p instanceof M&&p.label===r.name)return p.partialResults;throw p}case"Break":throw new M(r.name);case"Def":{let p=new Map(n.funcs??[]),i=`${r.name}/${r.params.length}`;p.set(i,{params:r.params,body:r.funcBody,closure:new Map(n.funcs??[])});let u={...n,funcs:p};return d(t,r.body,u)}default:{let p=r;throw new Error(`Unknown AST node type: ${p.type}`)}}}function ht(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Ot(t,r,e,n,p){function i(s,f){switch(e){case"=":return f;case"|=":return d(s,n,p)[0]??null;case"+=":return typeof s=="number"&&typeof f=="number"||typeof s=="string"&&typeof f=="string"?s+f:Array.isArray(s)&&Array.isArray(f)?[...s,...f]:s&&f&&typeof s=="object"&&typeof f=="object"?{...s,...f}:f;case"-=":return typeof s=="number"&&typeof f=="number"?s-f:s;case"*=":return typeof s=="number"&&typeof f=="number"?s*f:s;case"/=":return typeof s=="number"&&typeof f=="number"?s/f:s;case"%=":return typeof s=="number"&&typeof f=="number"?s%f:s;case"//=":return s===null||s===!1?f:s;default:return f}}function u(s,f,o){switch(f.type){case"Identity":return o(s);case"Field":{if(!b(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let y={...h},a=Object.hasOwn(y,f.name)?y[f.name]:void 0;return g(y,f.name,o(a)),y}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h={...s},y=Object.hasOwn(h,f.name)?h[f.name]:void 0;return g(h,f.name,o(y)),h}return s}case"Index":{let y=d(t,f.index,p)[0];if(typeof y=="number"&&Number.isNaN(y))throw new Error("Cannot set array element at NaN index");if(typeof y=="number"&&!Number.isInteger(y)&&(y=Math.trunc(y)),f.base)return u(s,f.base,a=>{if(typeof y=="number"&&Array.isArray(a)){let l=[...a],m=y<0?l.length+y:y;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=o(l[m])}return l}if(typeof y=="string"&&a&&typeof a=="object"&&!Array.isArray(a)){if(!b(y))return a;let l={...a},m=Object.hasOwn(l,y)?l[y]:void 0;return g(l,y,o(m)),l}return a});if(typeof y=="number"){if(y>536870911)throw new Error("Array index too large");if(y<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=y<0?l.length+y:y;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=o(l[m])}return l}if(s==null){let l=[];for(;l.length<=y;)l.push(null);return l[y]=o(null),l}return s}if(typeof y=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!b(y))return s;let a={...s},l=Object.hasOwn(a,y)?a[y]:void 0;return g(a,y,o(l)),a}return s}case"Iterate":{let h=y=>{if(Array.isArray(y))return y.map(a=>o(a));if(y&&typeof y=="object"){let a=Object.create(null);for(let[l,m]of Object.entries(y))b(l)&&g(a,l,o(m));return a}return y};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,y=>y);return u(h,f.right,o)}default:return o(s)}}return u(t,r,s=>{if(e==="|=")return i(s,s);let f=d(t,n,p);return i(s,f[0]??null)})}function Nt(t,r,e){function n(i,u,c){switch(u.type){case"Identity":return c;case"Field":{if(!b(u.name))return i;if(u.base){let s=d(i,u.base,e)[0],f=n(s,{type:"Field",name:u.name},c);return n(i,u.base,f)}if(i&&typeof i=="object"&&!Array.isArray(i)){let s={...i};return g(s,u.name,c),s}return i}case"Index":{if(u.base){let o=d(i,u.base,e)[0],h=n(o,{type:"Index",index:u.index},c);return n(i,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(i)){let o=[...i],h=f<0?o.length+f:f;return h>=0&&h<o.length&&(o[h]=c),o}if(typeof f=="string"&&i&&typeof i=="object"&&!Array.isArray(i)){if(!b(f))return i;let o={...i};return g(o,f,c),o}return i}default:return i}}function p(i,u){switch(u.type){case"Identity":return null;case"Field":{if(!b(u.name))return i;if(u.base){let s=d(i,u.base,e)[0];if(s==null)return i;let f=p(s,{type:"Field",name:u.name});return n(i,u.base,f)}if(i&&typeof i=="object"&&!Array.isArray(i)){if(!b(u.name))return i;let s={...i};return delete s[u.name],s}return i}case"Index":{if(u.base){let o=d(i,u.base,e)[0];if(o==null)return i;let h=p(o,{type:"Index",index:u.index});return n(i,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(i)){let o=[...i],h=f<0?o.length+f:f;return h>=0&&h<o.length&&o.splice(h,1),o}if(typeof f=="string"&&i&&typeof i=="object"&&!Array.isArray(i)){if(!b(f))return i;let o={...i};return delete o[f],o}return i}case"Iterate":return Array.isArray(i)?[]:i&&typeof i=="object"?{}:i;case"Pipe":{let o=function(a,l,m){switch(l.type){case"Identity":return m;case"Field":{if(!b(l.name))return a;if(a&&typeof a=="object"&&!Array.isArray(a)){let A={...a};return g(A,l.name,m),A}return a}case"Index":{let E=d(t,l.index,e)[0];if(typeof E=="number"&&Array.isArray(a)){let w=[...a],x=E<0?w.length+E:E;return x>=0&&x<w.length&&(w[x]=m),w}if(typeof E=="string"&&a&&typeof a=="object"&&!Array.isArray(a)){if(!b(E))return a;let w={...a};return g(w,E,m),w}return a}case"Pipe":{let A=d(a,l.left,e)[0],E=o(A,l.right,m);return o(a,l.left,E)}default:return a}};var c=o;let s=u.left,f=u.right,h=d(i,s,e)[0];if(h==null)return i;let y=p(h,f);return o(i,s,y)}default:return i}}return p(t,r)}function St(t,r,e,n,p){if(r==="and")return d(t,e,p).flatMap(s=>k(s)?d(t,n,p).map(o=>k(o)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>k(s)?[!0]:d(t,n,p).map(o=>k(o)));if(r==="//"){let s=d(t,e,p).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,p)}let i=d(t,e,p),u=d(t,n,p);return i.flatMap(c=>u.map(s=>{switch(r){case"+":return c===null?s:s===null?c:typeof c=="number"&&typeof s=="number"||typeof c=="string"&&typeof s=="string"?c+s:Array.isArray(c)&&Array.isArray(s)?[...c,...s]:c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?{...c,...s}:null;case"-":if(typeof c=="number"&&typeof s=="number")return c-s;if(Array.isArray(c)&&Array.isArray(s)){let f=new Set(s.map(o=>JSON.stringify(o)));return c.filter(o=>!f.has(JSON.stringify(o)))}if(typeof c=="string"&&typeof s=="string"){let f=o=>o.length>10?`"${o.slice(0,10)}...`:JSON.stringify(o);throw new Error(`string (${f(c)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":return typeof c=="number"&&typeof s=="number"?c*s:typeof c=="string"&&typeof s=="number"?c.repeat(s):c&&s&&typeof c=="object"&&typeof s=="object"&&!Array.isArray(c)&&!Array.isArray(s)?W(c,s):null;case"/":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided because the divisor is zero`);return c/s}return typeof c=="string"&&typeof s=="string"?c.split(s):null;case"%":if(typeof c=="number"&&typeof s=="number"){if(s===0)throw new Error(`number (${c}) and number (${s}) cannot be divided (remainder) because the divisor is zero`);return!Number.isFinite(c)&&!Number.isNaN(c)?!Number.isFinite(s)&&!Number.isNaN(s)&&c<0&&s>0?-1:0:c%s}return null;case"==":return R(c,s);case"!=":return!R(c,s);case"<":return P(c,s)<0;case"<=":return P(c,s)<=0;case">":return P(c,s)>0;case">=":return P(c,s)>=0;default:return null}}))}function at(t,r,e,n){let p=Et.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let i=z(t,r,e,n,d);if(i!==null)return i;let u=nt(t,r,e,n,d);if(u!==null)return u;let c=X(t,r,e,n,d);if(c!==null)return c;let s=Q(t,r,n.limits.maxDepth);if(s!==null)return s;let f=st(t,r);if(f!==null)return f;let o=tt(t,r,e,n,d);if(o!==null)return o;let h=G(t,r,e,n,d,ut,_,k,U,I);if(h!==null)return h;let y=et(t,r,e,n,d,k,L,$,Nt,F);if(y!==null)return y;let a=Z(t,r,e,n,d,R);if(a!==null)return a;let l=q(t,r,e,n,d,ut,k,I);if(l!==null)return l;let m=v(t,r,e,n,d,k,kt,at);if(m!==null)return m;let A=rt(t,r,e,n,d,R);if(A!==null)return A;switch(r){case"builtins":return[["add/0","all/0","all/1","all/2","any/0","any/1","any/2","arrays/0","ascii/0","ascii_downcase/0","ascii_upcase/0","booleans/0","bsearch/1","builtins/0","combinations/0","combinations/1","contains/1","debug/0","del/1","delpaths/1","empty/0","env/0","error/0","error/1","explode/0","first/0","first/1","flatten/0","flatten/1","floor/0","from_entries/0","fromdate/0","fromjson/0","getpath/1","gmtime/0","group_by/1","gsub/2","gsub/3","has/1","implode/0","IN/1","IN/2","INDEX/1","INDEX/2","index/1","indices/1","infinite/0","inside/1","isempty/1","isnan/0","isnormal/0","isvalid/1","iterables/0","join/1","keys/0","keys_unsorted/0","last/0","last/1","length/0","limit/2","ltrimstr/1","map/1","map_values/1","match/1","match/2","max/0","max_by/1","min/0","min_by/1","mktime/0","modulemeta/1","nan/0","not/0","nth/1","nth/2","null/0","nulls/0","numbers/0","objects/0","path/1","paths/0","paths/1","pick/1","range/1","range/2","range/3","recurse/0","recurse/1","recurse_down/0","repeat/1","reverse/0","rindex/1","rtrimstr/1","scalars/0","scan/1","scan/2","select/1","setpath/2","skip/2","sort/0","sort_by/1","split/1","splits/1","splits/2","sqrt/0","startswith/1","strftime/1","strings/0","strptime/1","sub/2","sub/3","test/1","test/2","to_entries/0","toboolean/0","todate/0","tojson/0","tostream/0","fromstream/1","truncate_stream/1","tonumber/0","tostring/0","transpose/0","trim/0","ltrim/0","rtrim/0","type/0","unique/0","unique_by/1","until/2","utf8bytelength/0","values/0","walk/1","while/2","with_entries/1"]];case"error":{let E=e.length>0?d(t,e[0],n)[0]:t;throw new K(E)}case"env":return[n.env?Y(n.env):{}];case"debug":return[t];case"input_line_number":return[1];default:{let E=`${r}/${e.length}`,w=n.funcs?.get(E);if(w){let x=w.closure??n.funcs??new Map,J=new Map(x);J.set(E,w);for(let B=0;B<w.params.length;B++){let dt=w.params[B],ft=e[B];if(ft){let T=d(t,ft,n),C;if(T.length===0)C={type:"Call",name:"empty",args:[]};else if(T.length===1)C={type:"Literal",value:T[0]};else{C={type:"Literal",value:T[T.length-1]};for(let H=T.length-2;H>=0;H--)C={type:"Comma",left:{type:"Literal",value:T[H]},right:C}}J.set(`${dt}/0`,{params:[],body:C})}}let mt={...n,funcs:J};return d(t,w.body,mt)}throw new Error(`Unknown function: ${r}`)}}}function F(t,r,e,n,p){if(r.type==="Comma"){let c=r;F(t,c.left,e,n,p),F(t,c.right,e,n,p);return}let i=S(r);if(i!==null){p.push([...n,...i]);return}if(r.type==="Iterate"){if(Array.isArray(t))for(let c=0;c<t.length;c++)p.push([...n,c]);else if(t&&typeof t=="object")for(let c of Object.keys(t))p.push([...n,c]);return}if(r.type==="Recurse"){let c=(s,f)=>{if(p.push([...n,...f]),s&&typeof s=="object")if(Array.isArray(s))for(let o=0;o<s.length;o++)c(s[o],[...f,o]);else for(let o of Object.keys(s))c(s[o],[...f,o])};c(t,[]);return}if(r.type==="Pipe"){let c=S(r.left);if(c!==null){let s=d(t,r.left,e);for(let f of s)F(f,r.right,e,[...n,...c],p);return}}d(t,r,e).length>0&&p.push(n)}var Tt=new Map([["and","AND"],["or","OR"],["not","NOT"],["if","IF"],["then","THEN"],["elif","ELIF"],["else","ELSE"],["end","END"],["as","AS"],["try","TRY"],["catch","CATCH"],["true","TRUE"],["false","FALSE"],["null","NULL"],["reduce","REDUCE"],["foreach","FOREACH"],["label","LABEL"],["break","BREAK"],["def","DEF"]]);function lt(t){let r=[],e=0,n=(f=0)=>t[e+f],p=()=>t[e++],i=()=>e>=t.length,u=f=>f>="0"&&f<="9",c=f=>f>="a"&&f<="z"||f>="A"&&f<="Z"||f==="_",s=f=>c(f)||u(f);for(;!i();){let f=e,o=p();if(!(o===" "||o===" "||o===`
|
|
4
4
|
`||o==="\r")){if(o==="#"){for(;!i()&&n()!==`
|
|
5
5
|
`;)p();continue}if(o==="."&&n()==="."){p(),r.push({type:"DOTDOT",pos:f});continue}if(o==="="&&n()==="="){p(),r.push({type:"EQ",pos:f});continue}if(o==="!"&&n()==="="){p(),r.push({type:"NE",pos:f});continue}if(o==="<"&&n()==="="){p(),r.push({type:"LE",pos:f});continue}if(o===">"&&n()==="="){p(),r.push({type:"GE",pos:f});continue}if(o==="/"&&n()==="/"){p(),n()==="="?(p(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(o==="+"&&n()==="="){p(),r.push({type:"UPDATE_ADD",pos:f});continue}if(o==="-"&&n()==="="){p(),r.push({type:"UPDATE_SUB",pos:f});continue}if(o==="*"&&n()==="="){p(),r.push({type:"UPDATE_MUL",pos:f});continue}if(o==="/"&&n()==="="){p(),r.push({type:"UPDATE_DIV",pos:f});continue}if(o==="%"&&n()==="="){p(),r.push({type:"UPDATE_MOD",pos:f});continue}if(o==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(o==="."){r.push({type:"DOT",pos:f});continue}if(o==="|"){n()==="="?(p(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(o===","){r.push({type:"COMMA",pos:f});continue}if(o===":"){r.push({type:"COLON",pos:f});continue}if(o===";"){r.push({type:"SEMICOLON",pos:f});continue}if(o==="("){r.push({type:"LPAREN",pos:f});continue}if(o===")"){r.push({type:"RPAREN",pos:f});continue}if(o==="["){r.push({type:"LBRACKET",pos:f});continue}if(o==="]"){r.push({type:"RBRACKET",pos:f});continue}if(o==="{"){r.push({type:"LBRACE",pos:f});continue}if(o==="}"){r.push({type:"RBRACE",pos:f});continue}if(o==="?"){r.push({type:"QUESTION",pos:f});continue}if(o==="+"){r.push({type:"PLUS",pos:f});continue}if(o==="-"){r.push({type:"MINUS",pos:f});continue}if(o==="*"){r.push({type:"STAR",pos:f});continue}if(o==="/"){r.push({type:"SLASH",pos:f});continue}if(o==="%"){r.push({type:"PERCENT",pos:f});continue}if(o==="<"){r.push({type:"LT",pos:f});continue}if(o===">"){r.push({type:"GT",pos:f});continue}if(u(o)){let h=o;for(;!i()&&(u(n())||n()==="."||n()==="e"||n()==="E");)(n()==="e"||n()==="E")&&(t[e+1]==="+"||t[e+1]==="-")&&(h+=p()),h+=p();r.push({type:"NUMBER",value:Number(h),pos:f});continue}if(o==='"'){let h="";for(;!i()&&n()!=='"';)if(n()==="\\"){if(p(),i())break;let y=p();switch(y){case"n":h+=`
|
|
6
6
|
`;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(";break;default:h+=y}}else h+=p();i()||p(),r.push({type:"STRING",value:h,pos:f});continue}if(c(o)||o==="$"||o==="@"){let h=o;for(;!i()&&s(n());)h+=p();let y=Tt.get(h);y?r.push({type:y,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${o}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ot=class t{tokens;pos=0;constructor(r){this.tokens=r}peek(r=0){return this.tokens[this.pos+r]??{type:"EOF",pos:-1}}advance(){return this.tokens[this.pos++]}check(r){return this.peek().type===r}match(...r){for(let e of r)if(this.check(e))return this.advance();return null}expect(r,e){if(!this.check(r))throw new Error(`${e} at position ${this.peek().pos}, got ${this.peek().type}`);return this.advance()}parse(){let r=this.parseExpr();if(!this.check("EOF"))throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`);return r}parseExpr(){return this.parsePipe()}parsePattern(){if(this.match("LBRACKET")){let n=[];if(!this.check("RBRACKET"))for(n.push(this.parsePattern());this.match("COMMA")&&!this.check("RBRACKET");)n.push(this.parsePattern());return this.expect("RBRACKET","Expected ']' after array pattern"),{type:"array",elements:n}}if(this.match("LBRACE")){let n=[];if(!this.check("RBRACE"))for(n.push(this.parsePatternField());this.match("COMMA")&&!this.check("RBRACE");)n.push(this.parsePatternField());return this.expect("RBRACE","Expected '}' after object pattern"),{type:"object",fields:n}}let r=this.expect("IDENT","Expected variable name in pattern"),e=r.value;if(!e.startsWith("$"))throw new Error(`Variable name must start with $ at position ${r.pos}`);return{type:"var",name:e}}parsePatternField(){if(this.match("LPAREN")){let e=this.parseExpr();this.expect("RPAREN","Expected ')' after computed key"),this.expect("COLON","Expected ':' after computed key");let n=this.parsePattern();return{key:e,pattern:n}}let r=this.peek();if(r.type==="IDENT"){let e=r.value;if(e.startsWith("$")){if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e.slice(1),pattern:n,keyVar:e}}return{key:e.slice(1),pattern:{type:"var",name:e}}}if(this.advance(),this.match("COLON")){let n=this.parsePattern();return{key:e,pattern:n}}return{key:e,pattern:{type:"var",name:`$${e}`}}}throw new Error(`Expected field name in object pattern at position ${r.pos}`)}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let e=this.parseComma();r={type:"Pipe",left:r,right:e}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let e=this.parseVarBind();r={type:"Comma",left:r,right:e}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let e=this.parsePattern(),n=[];for(;this.check("QUESTION")&&this.peekAhead(1)?.type==="ALT";)this.advance(),this.advance(),n.push(this.parsePattern());this.expect("PIPE","Expected '|' after variable binding");let p=this.parseExpr();return e.type==="var"&&n.length===0?{type:"VarBind",name:e.name,value:r,body:p}:{type:"VarBind",name:e.type==="var"?e.name:"",value:r,body:p,pattern:e.type!=="var"?e:void 0,alternatives:n.length>0?n:void 0}}return r}peekAhead(r){let e=this.pos+r;return e<this.tokens.length?this.tokens[e]:void 0}parseUpdate(){let r=this.parseAlt(),e=new Map([["ASSIGN","="],["UPDATE_ADD","+="],["UPDATE_SUB","-="],["UPDATE_MUL","*="],["UPDATE_DIV","/="],["UPDATE_MOD","%="],["UPDATE_ALT","//="],["UPDATE_PIPE","|="]]),n=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(n){let p=this.parseVarBind(),i=e.get(n.type);if(i)return{type:"UpdateOp",op:i,path:r,value:p}}return r}parseAlt(){let r=this.parseOr();for(;this.match("ALT");){let e=this.parseOr();r={type:"BinaryOp",op:"//",left:r,right:e}}return r}parseOr(){let r=this.parseAnd();for(;this.match("OR");){let e=this.parseAnd();r={type:"BinaryOp",op:"or",left:r,right:e}}return r}parseAnd(){let r=this.parseNot();for(;this.match("AND");){let e=this.parseNot();r={type:"BinaryOp",op:"and",left:r,right:e}}return r}parseNot(){return this.parseComparison()}parseComparison(){let r=this.parseAddSub(),e=new Map([["EQ","=="],["NE","!="],["LT","<"],["LE","<="],["GT",">"],["GE",">="]]),n=this.match("EQ","NE","LT","LE","GT","GE");if(n){let p=e.get(n.type);if(p){let i=this.parseAddSub();r={type:"BinaryOp",op:p,left:r,right:i}}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:e}}else if(this.match("MINUS")){let e=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:e}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let e=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:e}}else if(this.match("SLASH")){let e=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:e}}else if(this.match("PERCENT")){let e=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:e}}else break;return r}parseUnary(){return this.match("MINUS")?{type:"UnaryOp",op:"-",operand:this.parseUnary()}:this.parsePostfix()}parsePostfix(){let r=this.parsePrimary();for(;;)if(this.match("QUESTION"))r={type:"Optional",expr:r};else if(this.check("DOT")&&(this.peek(1).type==="IDENT"||this.peek(1).type==="STRING"))this.advance(),r={type:"Field",name:this.advance().value,base:r};else if(this.check("LBRACKET"))if(this.advance(),this.match("RBRACKET"))r={type:"Iterate",base:r};else if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:e,base:r}}else{let e=this.parseExpr();if(this.match("COLON")){let n=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:e,end:n,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:e,base:r}}else break;return r}parsePrimary(){if(this.match("DOTDOT"))return{type:"Recurse"};if(this.match("DOT")){if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let e=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:e}}let r=this.parseExpr();if(this.match("COLON")){let e=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:r,end:e}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:r}}return this.check("IDENT")||this.check("STRING")?{type:"Field",name:this.advance().value}:{type:"Identity"}}if(this.match("TRUE"))return{type:"Literal",value:!0};if(this.match("FALSE"))return{type:"Literal",value:!1};if(this.match("NULL"))return{type:"Literal",value:null};if(this.check("NUMBER"))return{type:"Literal",value:this.advance().value};if(this.check("STRING")){let e=this.advance().value;return e.includes("\\(")?this.parseStringInterpolation(e):{type:"Literal",value:e}}if(this.match("LBRACKET")){if(this.match("RBRACKET"))return{type:"Array"};let r=this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Array",elements:r}}if(this.match("LBRACE"))return this.parseObjectConstruction();if(this.match("LPAREN")){let r=this.parseExpr();return this.expect("RPAREN","Expected ')'"),{type:"Paren",expr:r}}if(this.match("IF"))return this.parseIf();if(this.match("TRY")){let r=this.parsePostfix(),e;return this.match("CATCH")&&(e=this.parsePostfix()),{type:"Try",body:r,catch:e}}if(this.match("REDUCE")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after reduce expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr();this.expect("RPAREN","Expected ')' after update expression");let i=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:i,init:n,update:p,pattern:e.type!=="var"?e:void 0}}if(this.match("FOREACH")){let r=this.parseAddSub();this.expect("AS","Expected 'as' after foreach expression");let e=this.parsePattern();this.expect("LPAREN","Expected '(' after variable");let n=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let p=this.parseExpr(),i;this.match("SEMICOLON")&&(i=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions");let u=e.type==="var"?e.name:"";return{type:"Foreach",expr:r,varName:u,init:n,update:p,extract:i,pattern:e.type!=="var"?e:void 0}}if(this.match("LABEL")){let r=this.expect("IDENT","Expected label name (e.g., $out)"),e=r.value;if(!e.startsWith("$"))throw new Error(`Label name must start with $ at position ${r.pos}`);this.expect("PIPE","Expected '|' after label name");let n=this.parseExpr();return{type:"Label",name:e,body:n}}if(this.match("BREAK")){let r=this.expect("IDENT","Expected label name to break to"),e=r.value;if(!e.startsWith("$"))throw new Error(`Break label must start with $ at position ${r.pos}`);return{type:"Break",name:e}}if(this.match("DEF")){let e=this.expect("IDENT","Expected function name after def").value,n=[];if(this.match("LPAREN")){if(!this.check("RPAREN")){let u=this.expect("IDENT","Expected parameter name");for(n.push(u.value);this.match("SEMICOLON");){let c=this.expect("IDENT","Expected parameter name");n.push(c.value)}}this.expect("RPAREN","Expected ')' after parameters")}this.expect("COLON","Expected ':' after function name");let p=this.parseExpr();this.expect("SEMICOLON","Expected ';' after function body");let i=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:p,body:i}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let e=this.advance().value;if(e.startsWith("$"))return{type:"VarRef",name:e};if(this.match("LPAREN")){let n=[];if(!this.check("RPAREN"))for(n.push(this.parseExpr());this.match("SEMICOLON");)n.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:e,args:n}}return{type:"Call",name:e,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let e,n;if(this.match("LPAREN"))e=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else if(this.check("IDENT")){let p=this.advance().value;this.match("COLON")?(e=p,n=this.parseObjectValue()):(e=p,n={type:"Field",name:p})}else if(this.check("STRING"))e=this.advance().value,this.expect("COLON","Expected ':'"),n=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:e,value:n})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let e=this.parseVarBind();r={type:"Pipe",left:r,right:e}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let e=this.parseExpr(),n=[];for(;this.match("ELIF");){let i=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:i,then:u})}let p;return this.match("ELSE")&&(p=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:e,elifs:n,else:p}}parseStringInterpolation(r){let e=[],n="",p=0;for(;p<r.length;)if(r[p]==="\\"&&r[p+1]==="("){n&&(e.push(n),n=""),p+=2;let i=1,u="";for(;p<r.length&&i>0;)r[p]==="("?i++:r[p]===")"&&i--,i>0&&(u+=r[p]),p++;let c=lt(u),s=new t(c);e.push(s.parse())}else n+=r[p],p++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function ge(t){let r=lt(t);return new ot(r).parse()}export{d as a,ge as b};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as w,b as J}from"./chunk-
|
|
2
|
+
import{a as w,b as J}from"./chunk-FJTZ5HFK.js";import"./chunk-4PRVMER6.js";import{k as q}from"./chunk-K5IXNHO5.js";import"./chunk-SE4C7FJY.js";import{a as N}from"./chunk-5WFYIUU2.js";import"./chunk-OBH7XN5N.js";import{a as C,b as E,c as x}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function I(s){let i=[],t=0,o=s.length;for(;t<o;){for(;t<o&&/\s/.test(s[t]);)t++;if(t>=o)break;let a=t,r=s[t];if(r==="{"||r==="["){let n=r,l=r==="{"?"}":"]",c=1,p=!1,d=!1;for(t++;t<o&&c>0;){let h=s[t];d?d=!1:h==="\\"?d=!0:h==='"'?p=!p:p||(h===n?c++:h===l&&c--),t++}if(c!==0)throw new Error(`Unexpected end of JSON input at position ${t} (unclosed ${n})`);i.push(JSON.parse(s.slice(a,t)))}else if(r==='"'){let n=!1;for(t++;t<o;){let l=s[t];if(n)n=!1;else if(l==="\\")n=!0;else if(l==='"'){t++;break}t++}i.push(JSON.parse(s.slice(a,t)))}else if(r==="-"||r>="0"&&r<="9"){for(;t<o&&/[\d.eE+-]/.test(s[t]);)t++;i.push(JSON.parse(s.slice(a,t)))}else if(s.slice(t,t+4)==="true")i.push(!0),t+=4;else if(s.slice(t,t+5)==="false")i.push(!1),t+=5;else if(s.slice(t,t+4)==="null")i.push(null),t+=4;else{let n=s.slice(t,t+10);throw new Error(`Invalid JSON at position ${a}: unexpected '${n.split(/\s/)[0]}'`)}}return i}var H={name:"jq",summary:"command-line JSON processor",usage:"jq [OPTIONS] FILTER [FILE]",options:["-r, --raw-output output strings without quotes","-c, --compact compact output (no pretty printing)","-e, --exit-status set exit status based on output","-s, --slurp read entire input into array","-n, --null-input don't read any input","-j, --join-output don't print newlines after each output","-a, --ascii force ASCII output","-S, --sort-keys sort object keys","-C, --color colorize output (ignored)","-M, --monochrome monochrome output (ignored)"," --tab use tabs for indentation"," --help display this help and exit"]};function g(s,i,t,o,a,r=0){if(s===null||s===void 0)return"null";if(typeof s=="boolean")return String(s);if(typeof s=="number")return Number.isFinite(s)?String(s):"null";if(typeof s=="string")return t?s:JSON.stringify(s);let n=a?" ":" ";if(Array.isArray(s))return s.length===0?"[]":i?`[${s.map(c=>g(c,!0,!1,o,a)).join(",")}]`:`[
|
|
3
3
|
${s.map(c=>n.repeat(r+1)+g(c,!1,!1,o,a,r+1)).join(`,
|
|
4
4
|
`)}
|
|
5
5
|
${n.repeat(r)}]`;if(typeof s=="object"){let l=Object.keys(s);return o&&(l=l.sort()),l.length===0?"{}":i?`{${l.map(p=>`${JSON.stringify(p)}:${g(s[p],!0,!1,o,a)}`).join(",")}}`:`{
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as b,b as $}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{existsSync as h}from"node:fs";import{dirname as F,join as p}from"node:path";import{fileURLToPath as U}from"node:url";import{Worker as D}from"node:worker_threads";import H from"sql.js";function q(e,r,n){switch(n.mode){case"list":return y(e,r,n);case"csv":return L(e,r,n);case"json":return V(e,r);case"line":return O(e,r,n);case"column":return N(e,r,n);case"table":return P(e,r,n);case"markdown":return A(e,r,n);case"tabs":return I(e,r,n);case"box":return M(e,r,n);case"quote":return R(e,r,n);case"html":return Q(e,r,n);case"ascii":return B(e,r,n)}}function u(e,r){return e==null?r:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function y(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(n.separator));for(let l of r)t.push(l.map(i=>u(i,n.nullValue)).join(n.separator));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function L(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(j).join(","));for(let l of r)t.push(l.map(i=>j(u(i,n.nullValue))).join(","));return t.length>0?`${t.join(`
|
|
3
|
+
`)}
|
|
4
|
+
`:""}function j(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
5
|
+
`)?`"${e.replace(/"/g,'""')}"`:e}function E(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function k(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):E(e):JSON.stringify(e)}function V(e,r){return r.length===0?"":`[${r.map(t=>`{${e.map((i,s)=>`${JSON.stringify(i)}:${k(t[s])}`).join(",")}}`).join(`,
|
|
6
|
+
`)}]
|
|
7
|
+
`}function O(e,r,n){if(e.length===0||r.length===0)return"";let t=Math.max(5,...e.map(i=>i.length)),l=[];for(let i of r)for(let s=0;s<e.length;s++){let o=e[s].padStart(t);l.push(`${o} = ${u(i[s],n.nullValue)}`)}return`${l.join(`
|
|
8
|
+
`)}
|
|
9
|
+
`}function N(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let l=[];n.header&&(l.push(e.map((i,s)=>i.padEnd(t[s])).join(" ")),l.push(t.map(i=>"-".repeat(i)).join(" ")));for(let i of r)l.push(i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" "));return l.length>0?`${l.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`:""}function P(e,r,n){if(e.length===0)return"";let t=e.map(s=>s.length);for(let s of r)for(let o=0;o<s.length;o++){let f=u(s[o],n.nullValue).length;f>t[o]&&(t[o]=f)}let l=[],i=`+${t.map(s=>"-".repeat(s+2)).join("+")}+`;l.push(i),n.header&&(l.push(`| ${e.map((s,o)=>s.padEnd(t[o])).join(" | ")} |`),l.push(i));for(let s of r)l.push(`| ${s.map((o,f)=>u(o,n.nullValue).padEnd(t[f])).join(" | ")} |`);return l.push(i),`${l.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`}function A(e,r,n){if(e.length===0)return"";let t=[];n.header&&(t.push(`| ${e.join(" | ")} |`),t.push(`|${e.map(()=>"---").join("|")}|`));for(let l of r)t.push(`| ${l.map(i=>u(i,n.nullValue)).join(" | ")} |`);return t.length>0?`${t.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`:""}function I(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(" "));for(let l of r)t.push(l.map(i=>u(i,n.nullValue)).join(" "));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function M(e,r,n){if(e.length===0)return"";let t=e.map(i=>i.length);for(let i of r)for(let s=0;s<i.length;s++){let o=u(i[s],n.nullValue).length;o>t[s]&&(t[s]=o)}let l=[];l.push(`\u250C${t.map(i=>"\u2500".repeat(i+2)).join("\u252C")}\u2510`),l.push(`\u2502 ${e.map((i,s)=>i.padEnd(t[s])).join(" \u2502 ")} \u2502`),l.push(`\u251C${t.map(i=>"\u2500".repeat(i+2)).join("\u253C")}\u2524`);for(let i of r)l.push(`\u2502 ${i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" \u2502 ")} \u2502`);return l.push(`\u2514${t.map(i=>"\u2500".repeat(i+2)).join("\u2534")}\u2518`),`${l.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`}function R(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(l=>`'${l}'`).join(","));for(let l of r)t.push(l.map(i=>i==null?"NULL":typeof i=="number"?Number.isInteger(i)?String(i):E(i):`'${String(i)}'`).join(","));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function Q(e,r,n){let t=[];n.header&&e.length>0&&(t.push(`<TR>${e.map(l=>`<TH>${S(l)}</TH>`).join("")}`),t.push("</TR>"));for(let l of r)t.push(`<TR>${l.map(i=>`<TD>${S(u(i,n.nullValue))}</TD>`).join("")}`),t.push("</TR>");return t.length>0?`${t.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`:""}function S(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function B(e,r,n){let i=[];n.header&&e.length>0&&i.push(e.join(""));for(let s of r)i.push(s.map(o=>u(o,n.nullValue)).join(""));return i.length>0?i.join("")+"":""}var J=5e3,W={name:"sqlite3",summary:"SQLite database CLI",usage:"sqlite3 [OPTIONS] DATABASE [SQL]",options:["-list output in list mode (default)","-csv output in CSV mode","-json output in JSON mode","-line output in line mode","-column output in column mode","-table output as ASCII table","-markdown output as markdown table","-tabs output in tab-separated mode","-box output in Unicode box mode","-quote output in SQL quote mode","-html output as HTML table","-ascii output in ASCII mode (control chars)","-header show column headers","-noheader hide column headers","-separator SEP field separator for list mode (default: |)","-newline SEP row separator (default: \\n)","-nullvalue TEXT text for NULL values (default: empty)","-readonly open database read-only (no writeback)","-bail stop on first error","-echo print SQL before execution","-cmd COMMAND run SQL command before main SQL","-version show SQLite version","-- end of options","--help show this help"],examples:['sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"','sqlite3 -json data.db "SELECT * FROM users"','sqlite3 -csv -header data.db "SELECT id, name FROM products"','sqlite3 -box data.db "SELECT * FROM users"']};function _(e){let r={mode:"list",header:!1,separator:"|",newline:`
|
|
20
|
+
`,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},n=null,t=null,l=!1,i=!1;for(let s=0;s<e.length;s++){let o=e[s];if(i){n===null?n=o:t===null&&(t=o);continue}if(o==="--")i=!0;else if(o==="-version")l=!0;else if(o==="-list")r.mode="list";else if(o==="-csv")r.mode="csv";else if(o==="-json")r.mode="json";else if(o==="-line")r.mode="line";else if(o==="-column")r.mode="column";else if(o==="-table")r.mode="table";else if(o==="-markdown")r.mode="markdown";else if(o==="-tabs")r.mode="tabs";else if(o==="-box")r.mode="box";else if(o==="-quote")r.mode="quote";else if(o==="-html")r.mode="html";else if(o==="-ascii")r.mode="ascii";else if(o==="-header")r.header=!0;else if(o==="-noheader")r.header=!1;else if(o==="-readonly")r.readonly=!0;else if(o==="-bail")r.bail=!0;else if(o==="-echo")r.echo=!0;else if(o==="-separator"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
|
|
21
|
+
`,exitCode:1};r.separator=e[++s]}else if(o==="-newline"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
|
|
22
|
+
`,exitCode:1};r.newline=e[++s]}else if(o==="-nullvalue"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
|
|
23
|
+
`,exitCode:1};r.nullValue=e[++s]}else if(o==="-cmd"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
|
|
24
|
+
`,exitCode:1};r.cmd=e[++s]}else{if(o.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${o.startsWith("--")?o.slice(1):o}
|
|
25
|
+
Use -help for a list of options.
|
|
26
|
+
`,exitCode:1};n===null?n=o:t===null&&(t=o)}}return{options:r,database:n,sql:t,showVersion:l}}async function X(){let e=await H(),r=new e.Database;try{let n=r.exec("SELECT sqlite_version()");return n.length>0&&n[0].values.length>0?String(n[0].values[0][0]):"unknown"}finally{r.close()}}function Y(){let e=F(U(import.meta.url)),r=p(e,"../../commands/sqlite3/worker.js");if(h(r))return r;let n=p(e,"worker.js");if(h(n))return n;let t=p(e,"../../../dist/commands/sqlite3/worker.js");if(h(t))return t;throw new Error("sqlite3 worker not found. Run 'pnpm build' to compile the worker.")}async function z(e,r){try{let n=Y();return await new Promise((t,l)=>{let i=new D(n,{workerData:e}),s=setTimeout(()=>{i.terminate(),t({success:!1,error:`Query timeout: execution exceeded ${r}ms limit`})},r);i.on("message",o=>{clearTimeout(s),t(o)}),i.on("error",o=>{clearTimeout(s),l(o)}),i.on("exit",o=>{clearTimeout(s),o!==0&&t({success:!1,error:`Worker exited with code ${o}`})})})}catch(n){throw new Error(`sqlite3 worker failed to load: ${n.message}`)}}var oe={name:"sqlite3",async execute(e,r){if($(e)||e.includes("-help"))return b(W);let n=_(e);if("exitCode"in n)return n;let{options:t,database:l,sql:i,showVersion:s}=n;if(s)return{stdout:`${await X()}
|
|
27
|
+
`,stderr:"",exitCode:0};if(!l)return{stdout:"",stderr:`sqlite3: missing database argument
|
|
28
|
+
`,exitCode:1};let o=i||r.stdin.trim();if(t.cmd&&(o=t.cmd+(o?`; ${o}`:"")),!o)return{stdout:"",stderr:`sqlite3: no SQL provided
|
|
29
|
+
`,exitCode:1};let f=l===":memory:",m="",g=null;try{f||(m=r.fs.resolvePath(r.cwd,l),await r.fs.exists(m)&&(g=await r.fs.readFileBuffer(m)))}catch(a){return{stdout:"",stderr:`sqlite3: unable to open database "${l}": ${a.message}
|
|
30
|
+
`,exitCode:1}}let T=r.limits?.maxSqliteTimeoutMs??J,x={dbBuffer:g,sql:o,options:{bail:t.bail,echo:t.echo}},d;try{d=await z(x,T)}catch(a){return{stdout:"",stderr:`sqlite3: worker error: ${a.message}
|
|
31
|
+
`,exitCode:1}}if(!d.success)return{stdout:"",stderr:`sqlite3: ${d.error}
|
|
32
|
+
`,exitCode:1};let C={mode:t.mode,header:t.header,separator:t.separator,newline:t.newline,nullValue:t.nullValue},c="";t.echo&&(c+=`${o}
|
|
33
|
+
`);let w=!1;for(let a of d.results)if(a.type==="error"){if(t.bail)return{stdout:c,stderr:`Error: ${a.error}
|
|
34
|
+
`,exitCode:1};c+=`Error: ${a.error}
|
|
35
|
+
`,w=!0}else a.columns&&a.rows&&(a.rows.length>0||t.header)&&(c+=q(a.columns,a.rows,C));if(d.hasModifications&&!t.readonly&&!f&&m&&d.dbBuffer)try{await r.fs.writeFile(m,d.dbBuffer)}catch(a){return{stdout:c,stderr:`sqlite3: failed to write database: ${a.message}
|
|
36
|
+
`,exitCode:1}}return{stdout:c,stderr:"",exitCode:w&&t.bail?1:0}}};export{oe as sqlite3Command};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as F,b,c as M,d as We,e as w,f as v,g as G,h as X}from"./chunk-GZHFXDDO.js";import{a as Qe}from"./chunk-QSDVMMYI.js";import{a as $}from"./chunk-
|
|
2
|
+
import{a as F,b,c as M,d as We,e as w,f as v,g as G,h as X}from"./chunk-GZHFXDDO.js";import{a as Qe}from"./chunk-QSDVMMYI.js";import{a as $}from"./chunk-FJTZ5HFK.js";import"./chunk-4PRVMER6.js";import"./chunk-K5IXNHO5.js";import{a as H}from"./chunk-SE4C7FJY.js";import{a as Ue}from"./chunk-5WFYIUU2.js";import"./chunk-OBH7XN5N.js";import{a as D,b as K}from"./chunk-GTNBSMZR.js";import{b as Ve,d as Ye,e as Be,f as Ze}from"./chunk-KGOUQS5A.js";var q,qe=Ve(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
|
|
3
3
|
`||n==="\r")this.pos++;else if(n==="#")for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
4
4
|
`;)this.pos++;else break}}nextToken(){let n=this.pos,t=this.input[this.pos];if(t>="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1<this.input.length){let o=this.input[this.pos+1];if(o==='"'||o==="'"||o==="`")return this.pos++,this.readString(o)}if(t==="/"){let o=this.tokens[this.tokens.length-1];return o&&(o.type==="int"||o.type==="float"||o.type==="string"||o.type==="ident"||o.type===")"||o.type==="]")?this.input[this.pos+1]==="/"?(this.pos+=2,{type:"//",value:"//",pos:n}):(this.pos++,{type:"/",value:"/",pos:n}):this.readRegex()}if(this.match("not in"))return{type:"not in",value:"not in",pos:n};if(this.match("=>"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let r=new Map([["(","("],[")",")"],["[","["],["]","]"],["{","{"],["}","}"],[",",","],[":",":"],[";",";"],["+","+"],["-","-"],["*","*"],["%","%"],["<","<"],[">",">"],["!","!"],[".","."],["|","|"],["=","="]]).get(t);if(r!==void 0)return this.pos++,{type:r,value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos<this.input.length;){let o=this.input[this.pos];if(o>="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.pos<this.input.length&&(this.input[this.pos]==="+"||this.input[this.pos]==="-")&&this.pos++;else break}let r=this.input.slice(n,this.pos).replace(/_/g,"");return{type:t?"float":"int",value:r,pos:n}}readString(n){let t=this.pos;this.pos++;let s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===n)return this.pos++,{type:"string",value:s,pos:t};if(r==="\\"){if(this.pos++,this.pos<this.input.length){let o=this.input[this.pos];switch(o){case"n":s+=`
|
|
5
5
|
`;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${t}`)}readRegex(){let n=this.pos;this.pos++;let t="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:t+(s?`/${s}`:""),pos:n}}r==="\\"?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${n}`)}readIdentifier(){let n=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let t=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(t=!0,this.pos++);let s=this.input.slice(n,t?this.pos-1:this.pos);t&&(s+="?");let r=new Map([["true","true"],["false","false"],["null","null"],["and","and"],["or","or"],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["in","in"],["as","as"],["_","_"]]),o=s.replace(/\?$/,""),i=r.get(o);return i!==void 0&&!t?{type:i,value:o,pos:n}:{type:"ident",value:s,pos:n}}}});var _e={};Ye(_e,{parseMoonblade:()=>_,parseNamedExpressions:()=>V});function V(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},i=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){i();continue}let h=[],u=0,p=r;for(;o().type!=="eof";){let a=o();if((a.type===","||a.type==="as")&&u===0)break;(a.type==="("||a.type==="["||a.type==="{")&&u++,(a.type===")"||a.type==="]"||a.type==="}")&&u--,h.push(i())}h.push({type:"eof",value:"",pos:0});let f=new J(h).parse(),c;if(o().type==="as")if(i(),o().type==="("){i();let a=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(a.push(o().value),i()),o().type===","&&i();o().type===")"&&i(),c=a}else if(o().type==="ident"||o().type==="string")c=o().value,i();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),f.type==="identifier"&&(c=f.name);n.push({expr:f,name:c})}return n}function _(e){let t=new q(e).tokenize();return new J(t).parse()}var R,J,U=Ve(()=>{"use strict";qe();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},J=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<n)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let n=this.peek();switch(n.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(n.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(n.value)};case"string":return this.advance(),{type:"string",value:n.value};case"regex":{this.advance();let t=n.value.split("/"),s=t.length>1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=[];if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=this.peek().value;if(this.advance(),this.peek().type===","||this.peek().type===")"){for(t.push(r);this.peek().type===","&&(this.advance(),this.peek().type==="ident");)t.push(this.peek().value),this.advance();if(this.peek().type===")"&&(this.advance(),this.peek().type==="=>")){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:t,body:o},t)}this.pos-=t.length*2,t.length>1&&(this.pos=this.pos)}this.pos--}let s=this.parseExpr(0);return this.expect(")"),this.peek().type,s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,i=this.pos+1;i<this.tokens.length&&this.tokens[i].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);t.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:n.toLowerCase(),args:t}}parseList(){this.expect("[");let n=[];if(this.peek().type!=="]")do n.length>0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let i=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:n},{expr:i}]}}if(s.type==="|"){this.advance();let i=this.parseExpr(t);return this.handlePipe(n,i)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});U();function E(e,n){return n.length===0?k(e,[]):n.length===1?{type:"Pipe",left:n[0],right:k(e,[])}:{type:"Pipe",left:n[0],right:k(e,n.slice(1))}}var Y={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>k("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?k("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?k("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?k("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>k("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>k("select",e),empty:()=>k("empty",[]),count:()=>k("length",[]),sum:e=>e.length===0?k("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:k("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?k("tonumber",[]):k("tonumber",e),tostring:e=>e.length===0?k("tostring",[]):k("tostring",e),if:e=>He(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return He(s,n,t.length===1?t[0]:Y.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>k("now",[]),fmt:e=>k("tostring",e),format:e=>k("tostring",e)};function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function k(e,n){return{type:"Call",name:e,args:n}}var et="then";function He(e,n,t){let s={type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}};return s[et]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function L(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>L(r.expr,n)),s=Object.hasOwn(Y,e.name)?Y[e.name]:void 0;return typeof s=="function"?s(t):k(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=L(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:L(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?L(e.start,n):void 0,end:e.end?L(e.end,n):void 0};case"lambda":return L(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function Z(e){let n=[],t=0;for(;t<e.length;){for(;t<e.length&&(e[t]===" "||e[t]===",");)t++;if(t>=e.length)break;let s=t;for(;t<e.length&&/\w/.test(e[t]);)t++;let r=e.slice(s,t);for(;t<e.length&&e[t]===" ";)t++;if(e[t]!=="(")break;t++;let o=1,i=t;for(;t<e.length&&o>0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let h=e.slice(i,t).trim();for(t++;t<e.length&&e[t]===" ";)t++;let u="";if(e.slice(t,t+3).toLowerCase()==="as "){for(t+=3;t<e.length&&e[t]===" ";)t++;let p=t;for(;t<e.length&&/\w/.test(e[t]);)t++;u=e.slice(p,t)}u||(u=h?`${r}(${h})`:`${r}()`),n.push({func:r,expr:h,alias:u})}return n}function Je(e){return/^\w+$/.test(e)}function B(e,n,t){let s=L(_(n)),r=$(e,s,t);return r.length>0?r[0]:null}function Q(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Je(r)?o=e.map(i=>i[r]).filter(i=>i!=null):o=e.map(i=>B(i,r,t)).filter(i=>i!=null),s){case"count":return Je(r)?o.length:o.filter(i=>!!i).length;case"sum":return o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h))).reduce((h,u)=>h+u,0);case"mean":case"avg":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?i.reduce((h,u)=>h+u,0)/i.length:0}case"min":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.min(...i):null}case"max":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.max(...i):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let i=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(i.length===0)return null;let h=Math.floor(i.length/2);return i.length%2===0?(i[h-1]+i[h])/2:i[h]}case"mode":{let i=new Map;for(let p of o){let l=String(p);i.set(l,(i.get(l)||0)+1)}let h=0,u=null;for(let[p,l]of i)l>h&&(h=l,u=p);return u}case"cardinality":return new Set(o.map(h=>String(h))).size;case"values":return o.map(i=>String(i)).join("|");case"distinct_values":return[...new Set(o.map(h=>String(h)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let i of e)if(!B(i,r,t))return!1;return!0}case"any":{for(let i of e)if(B(i,r,t))return!0;return!1}default:return null}}function ze(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,Q(e,r,t));return s}async function ee(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as Ja}from"./chunk-QSDVMMYI.js";import{a as Le,b as Oi}from"./chunk-
|
|
2
|
+
import{a as Ja}from"./chunk-QSDVMMYI.js";import{a as Le,b as Oi}from"./chunk-FJTZ5HFK.js";import"./chunk-4PRVMER6.js";import{k as Ts}from"./chunk-K5IXNHO5.js";import"./chunk-SE4C7FJY.js";import{a as Ai,b as Ti,c as ae}from"./chunk-GTNBSMZR.js";import{a as bt,c as b,e as As}from"./chunk-KGOUQS5A.js";var Yi=b((rp,Ri)=>{var{hasOwnProperty:Ps}=Object.prototype,Ms=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r
|
|
3
3
|
`:`
|
|
4
4
|
`,n=e.whitespace?" = ":"=",i=[],r=e.sort?Object.keys(s).sort():Object.keys(s),o=0;e.align&&(o=G(r.filter(c=>s[c]===null||Array.isArray(s[c])||typeof s[c]!="object").map(c=>Array.isArray(s[c])?`${c}[]`:c).concat([""]).reduce((c,u)=>G(c).length>=G(u).length?c:u)).length);let a="",l=e.bracketedArray?"[]":"";for(let c of r){let u=s[c];if(u&&Array.isArray(u))for(let f of u)a+=G(`${c}${l}`).padEnd(o," ")+n+G(f)+t;else u&&typeof u=="object"?i.push(c):a+=G(c).padEnd(o," ")+n+G(u)+t}e.section&&a.length&&(a="["+G(e.section)+"]"+(e.newline?t+t:t)+a);for(let c of i){let u=Vi(c,".").join("\\."),f=(e.section?e.section+".":"")+u,d=Ms(s[c],{...e,section:f});a.length&&d.length&&(a+=t),a+=d}return a};function Vi(s,e){var t=0,n=0,i=0,r=[];do if(i=s.indexOf(e,t),i!==-1){if(t=i+e.length,i>0&&s[i-1]==="\\")continue;r.push(s.slice(n,i)),n=i+e.length}while(i!==-1);return r.push(s.slice(n)),r}var ji=(s,e={})=>{e.bracketedArray=e.bracketedArray!==!1;let t=Object.create(null),n=t,i=null,r=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,o=s.split(/[\r\n]+/g),a={};for(let c of o){if(!c||c.match(/^\s*[;#]/)||c.match(/^\s*$/))continue;let u=c.match(r);if(!u)continue;if(u[1]!==void 0){if(i=Nt(u[1]),i==="__proto__"){n=Object.create(null);continue}n=t[i]=t[i]||Object.create(null);continue}let f=Nt(u[2]),d;e.bracketedArray?d=f.length>2&&f.slice(-2)==="[]":(a[f]=(a?.[f]||0)+1,d=a[f]>1);let p=d&&f.endsWith("[]")?f.slice(0,-2):f;if(p==="__proto__")continue;let g=u[3]?Nt(u[4]):!0,h=g==="true"||g==="false"||g==="null"?JSON.parse(g):g;d&&(Ps.call(n,p)?Array.isArray(n[p])||(n[p]=[n[p]]):n[p]=[]),Array.isArray(n[p])?n[p].push(h):n[p]=h}let l=[];for(let c of Object.keys(t)){if(!Ps.call(t,c)||typeof t[c]!="object"||Array.isArray(t[c]))continue;let u=Vi(c,".");n=t;let f=u.pop(),d=f.replace(/\\\./g,".");for(let p of u)p!=="__proto__"&&((!Ps.call(n,p)||typeof n[p]!="object")&&(n[p]=Object.create(null)),n=n[p]);n===t&&d===f||(n[d]=t[c],l.push(c))}for(let c of l)delete t[c];return t},Ki=s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"),G=s=>typeof s!="string"||s.match(/[=\r\n]/)||s.match(/^\[/)||s.length>1&&Ki(s)||s!==s.trim()?JSON.stringify(s):s.split(";").join("\\;").split("#").join("\\#"),Nt=s=>{if(s=(s||"").trim(),Ki(s)){s.charAt(0)==="'"&&(s=s.slice(1,-1));try{s=JSON.parse(s)}catch{}}else{let e=!1,t="";for(let n=0,i=s.length;n<i;n++){let r=s.charAt(n);if(e)"\\;#".indexOf(r)!==-1?t+=r:t+="\\"+r,e=!1;else{if(";#".indexOf(r)!==-1)break;r==="\\"?e=!0:t+=r}}return e&&(t+="\\"),t.trim()}return s};Ri.exports={parse:ji,decode:ji,stringify:Ms,encode:Ms,safe:G,unsafe:Nt}});var O=b($=>{"use strict";var Fs=Symbol.for("yaml.alias"),Di=Symbol.for("yaml.document"),kt=Symbol.for("yaml.map"),Zi=Symbol.for("yaml.pair"),js=Symbol.for("yaml.scalar"),It=Symbol.for("yaml.seq"),X=Symbol.for("yaml.node.type"),Xl=s=>!!s&&typeof s=="object"&&s[X]===Fs,Ql=s=>!!s&&typeof s=="object"&&s[X]===Di,Hl=s=>!!s&&typeof s=="object"&&s[X]===kt,Dl=s=>!!s&&typeof s=="object"&&s[X]===Zi,zi=s=>!!s&&typeof s=="object"&&s[X]===js,Zl=s=>!!s&&typeof s=="object"&&s[X]===It;function er(s){if(s&&typeof s=="object")switch(s[X]){case kt:case It:return!0}return!1}function zl(s){if(s&&typeof s=="object")switch(s[X]){case Fs:case kt:case js:case It:return!0}return!1}var ec=s=>(zi(s)||er(s))&&!!s.anchor;$.ALIAS=Fs;$.DOC=Di;$.MAP=kt;$.NODE_TYPE=X;$.PAIR=Zi;$.SCALAR=js;$.SEQ=It;$.hasAnchor=ec;$.isAlias=Xl;$.isCollection=er;$.isDocument=Ql;$.isMap=Hl;$.isNode=zl;$.isPair=Dl;$.isScalar=zi;$.isSeq=Zl});var Ve=b(Vs=>{"use strict";var M=O(),F=Symbol("break visit"),tr=Symbol("skip children"),J=Symbol("remove node");function qt(s,e){let t=sr(e);M.isDocument(s)?Se(null,s.contents,t,Object.freeze([s]))===J&&(s.contents=null):Se(null,s,t,Object.freeze([]))}qt.BREAK=F;qt.SKIP=tr;qt.REMOVE=J;function Se(s,e,t,n){let i=nr(s,e,t,n);if(M.isNode(i)||M.isPair(i))return ir(s,n,i),Se(s,i,t,n);if(typeof i!="symbol"){if(M.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r<e.items.length;++r){let o=Se(r,e.items[r],t,n);if(typeof o=="number")r=o-1;else{if(o===F)return F;o===J&&(e.items.splice(r,1),r-=1)}}}else if(M.isPair(e)){n=Object.freeze(n.concat(e));let r=Se("key",e.key,t,n);if(r===F)return F;r===J&&(e.key=null);let o=Se("value",e.value,t,n);if(o===F)return F;o===J&&(e.value=null)}}return i}async function Ct(s,e){let t=sr(e);M.isDocument(s)?await Ne(null,s.contents,t,Object.freeze([s]))===J&&(s.contents=null):await Ne(null,s,t,Object.freeze([]))}Ct.BREAK=F;Ct.SKIP=tr;Ct.REMOVE=J;async function Ne(s,e,t,n){let i=await nr(s,e,t,n);if(M.isNode(i)||M.isPair(i))return ir(s,n,i),Ne(s,i,t,n);if(typeof i!="symbol"){if(M.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r<e.items.length;++r){let o=await Ne(r,e.items[r],t,n);if(typeof o=="number")r=o-1;else{if(o===F)return F;o===J&&(e.items.splice(r,1),r-=1)}}}else if(M.isPair(e)){n=Object.freeze(n.concat(e));let r=await Ne("key",e.key,t,n);if(r===F)return F;r===J&&(e.key=null);let o=await Ne("value",e.value,t,n);if(o===F)return F;o===J&&(e.value=null)}}return i}function sr(s){return typeof s=="object"&&(s.Collection||s.Node||s.Value)?Object.assign({Alias:s.Node,Map:s.Node,Scalar:s.Node,Seq:s.Node},s.Value&&{Map:s.Value,Scalar:s.Value,Seq:s.Value},s.Collection&&{Map:s.Collection,Seq:s.Collection},s):s}function nr(s,e,t,n){if(typeof t=="function")return t(s,e,n);if(M.isMap(e))return t.Map?.(s,e,n);if(M.isSeq(e))return t.Seq?.(s,e,n);if(M.isPair(e))return t.Pair?.(s,e,n);if(M.isScalar(e))return t.Scalar?.(s,e,n);if(M.isAlias(e))return t.Alias?.(s,e,n)}function ir(s,e,t){let n=e[e.length-1];if(M.isCollection(n))n.items[s]=t;else if(M.isPair(n))s==="key"?n.key=t:n.value=t;else if(M.isDocument(n))n.contents=t;else{let i=M.isAlias(n)?"alias":"scalar";throw new Error(`Cannot replace node with ${i} parent`)}}Vs.visit=qt;Vs.visitAsync=Ct});var Ks=b(or=>{"use strict";var rr=O(),tc=Ve(),sc={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},nc=s=>s.replace(/[!,[\]{}]/g,e=>sc[e]),Ke=class s{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},s.defaultYaml,e),this.tags=Object.assign({},s.defaultTags,t)}clone(){let e=new s(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new s(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:s.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},s.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:s.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},s.defaultTags),this.atNextDocument=!1);let n=e.trim().split(/[ \t]+/),i=n.shift();switch(i){case"%TAG":{if(n.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;let[r,o]=n;return this.tags[r]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,n.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[r]=n;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{let o=/^\d+\.\d+$/.test(r);return t(6,`Unsupported YAML version ${r}`,o),!1}}default:return t(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let o=e.slice(2,-1);return o==="!"||o==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),o)}let[,n,i]=e.match(/^(.*!)([^!]*)$/s);i||t(`The ${e} tag has no suffix`);let r=this.tags[n];if(r)try{return r+decodeURIComponent(i)}catch(o){return t(String(o)),null}return n==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+nc(e.substring(n.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags),i;if(e&&n.length>0&&rr.isNode(e.contents)){let r={};tc.visit(e.contents,(o,a)=>{rr.isNode(a)&&a.tag&&(r[a.tag]=!0)}),i=Object.keys(r)}else i=[];for(let[r,o]of n)r==="!!"&&o==="tag:yaml.org,2002:"||(!e||i.some(a=>a.startsWith(o)))&&t.push(`%TAG ${r} ${o}`);return t.join(`
|
|
5
5
|
`)}};Ke.defaultYaml={explicit:!1,version:"1.2"};Ke.defaultTags={"!!":"tag:yaml.org,2002:"};or.Directives=Ke});var Lt=b(Re=>{"use strict";var ar=O(),ic=Ve();function rc(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function lr(s){let e=new Set;return ic.visit(s,{Value(t,n){n.anchor&&e.add(n.anchor)}}),e}function cr(s,e){for(let t=1;;++t){let n=`${s}${t}`;if(!e.has(n))return n}}function oc(s,e){let t=[],n=new Map,i=null;return{onAnchor:r=>{t.push(r),i??(i=lr(s));let o=cr(e,i);return i.add(o),o},setAnchors:()=>{for(let r of t){let o=n.get(r);if(typeof o=="object"&&o.anchor&&(ar.isScalar(o.node)||ar.isCollection(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=r,a}}},sourceObjects:n}}Re.anchorIsValid=rc;Re.anchorNames=lr;Re.createNodeAnchors=oc;Re.findNewAnchor=cr});var Rs=b(fr=>{"use strict";function Ye(s,e,t,n){if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0,r=n.length;i<r;++i){let o=n[i],a=Ye(s,n,String(i),o);a===void 0?delete n[i]:a!==o&&(n[i]=a)}else if(n instanceof Map)for(let i of Array.from(n.keys())){let r=n.get(i),o=Ye(s,n,i,r);o===void 0?n.delete(i):o!==r&&n.set(i,o)}else if(n instanceof Set)for(let i of Array.from(n)){let r=Ye(s,n,i,i);r===void 0?n.delete(i):r!==i&&(n.delete(i),n.add(r))}else for(let[i,r]of Object.entries(n)){let o=Ye(s,n,i,r);o===void 0?delete n[i]:o!==r&&(n[i]=o)}return s.call(e,t,n)}fr.applyReviver=Ye});var D=b(dr=>{"use strict";var ac=O();function ur(s,e,t){if(Array.isArray(s))return s.map((n,i)=>ur(n,String(i),t));if(s&&typeof s.toJSON=="function"){if(!t||!ac.hasAnchor(s))return s.toJSON(e,t);let n={aliasCount:0,count:1,res:void 0};t.anchors.set(s,n),t.onCreate=r=>{n.res=r,delete t.onCreate};let i=s.toJSON(e,t);return t.onCreate&&t.onCreate(i),i}return typeof s=="bigint"&&!t?.keep?Number(s):s}dr.toJS=ur});var Pt=b(pr=>{"use strict";var lc=Rs(),hr=O(),cc=D(),Ys=class{constructor(e){Object.defineProperty(this,hr.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:i,reviver:r}={}){if(!hr.isDocument(e))throw new TypeError("A document argument is required");let o={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n=="number"?n:100},a=cc.toJS(this,"",o);if(typeof i=="function")for(let{count:l,res:c}of o.anchors.values())i(c,l);return typeof r=="function"?lc.applyReviver(r,{"":a},"",a):a}};pr.NodeBase=Ys});var Ue=b(mr=>{"use strict";var fc=Lt(),uc=Ve(),Ee=O(),dc=Pt(),hc=D(),Us=class extends dc.NodeBase{constructor(e){super(Ee.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],uc.visit(e,{Node:(r,o)=>{(Ee.isAlias(o)||Ee.hasAnchor(o))&&n.push(o)}}),t&&(t.aliasResolveCache=n));let i;for(let r of n){if(r===this)break;r.anchor===this.source&&(i=r)}return i}toJSON(e,t){if(!t)return{source:this.source};let{anchors:n,doc:i,maxAliasCount:r}=t,o=this.resolve(i,t);if(!o){let l=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(l)}let a=n.get(o);if(a||(hc.toJS(o,null,t),a=n.get(o)),a?.res===void 0){let l="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(l)}if(r>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=Mt(i,o,n)),a.count*a.aliasCount>r)){let l="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(l)}return a.res}toString(e,t,n){let i=`*${this.source}`;if(e){if(fc.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${i} `}return i}};function Mt(s,e,t){if(Ee.isAlias(e)){let n=e.resolve(s),i=t&&n&&t.get(n);return i?i.count*i.aliasCount:0}else if(Ee.isCollection(e)){let n=0;for(let i of e.items){let r=Mt(s,i,t);r>n&&(n=r)}return n}else if(Ee.isPair(e)){let n=Mt(s,e.key,t),i=Mt(s,e.value,t);return Math.max(n,i)}return 1}mr.Alias=Us});var C=b(Js=>{"use strict";var pc=O(),mc=Pt(),gc=D(),yc=s=>!s||typeof s!="function"&&typeof s!="object",Z=class extends mc.NodeBase{constructor(e){super(pc.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:gc.toJS(this.value,e,t)}toString(){return String(this.value)}};Z.BLOCK_FOLDED="BLOCK_FOLDED";Z.BLOCK_LITERAL="BLOCK_LITERAL";Z.PLAIN="PLAIN";Z.QUOTE_DOUBLE="QUOTE_DOUBLE";Z.QUOTE_SINGLE="QUOTE_SINGLE";Js.Scalar=Z;Js.isScalarValue=yc});var Je=b(yr=>{"use strict";var bc=Ue(),fe=O(),gr=C(),wc="tag:yaml.org,2002:";function Sc(s,e,t){if(e){let n=t.filter(r=>r.tag===e),i=n.find(r=>!r.format)??n[0];if(!i)throw new Error(`Tag ${e} not found`);return i}return t.find(n=>n.identify?.(s)&&!n.format)}function Nc(s,e,t){if(fe.isDocument(s)&&(s=s.contents),fe.isNode(s))return s;if(fe.isPair(s)){let f=t.schema[fe.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:n,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=t,l;if(n&&s&&typeof s=="object"){if(l=a.get(s),l)return l.anchor??(l.anchor=i(s)),new bc.Alias(l.anchor);l={anchor:null,node:null},a.set(s,l)}e?.startsWith("!!")&&(e=wc+e.slice(2));let c=Sc(s,e,o.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new gr.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?o[fe.MAP]:Symbol.iterator in Object(s)?o[fe.SEQ]:o[fe.MAP]}r&&(r(c),delete t.onTagObj);let u=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new gr.Scalar(s);return e?u.tag=e:c.default||(u.tag=c.tag),l&&(l.node=u),u}yr.createNode=Nc});var _t=b($t=>{"use strict";var Ec=Je(),W=O(),vc=Pt();function Ws(s,e,t){let n=t;for(let i=e.length-1;i>=0;--i){let r=e[i];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let o=[];o[r]=n,n=o}else n=new Map([[r,n]])}return Ec.createNode(n,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var br=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,Gs=class extends vc.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(n=>W.isNode(n)||W.isPair(n)?n.clone(e):n),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(br(e))this.add(t);else{let[n,...i]=e,r=this.get(n,!0);if(W.isCollection(r))r.addIn(i,t);else if(r===void 0&&this.schema)this.set(n,Ws(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let i=this.get(t,!0);if(W.isCollection(i))return i.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...i]=e,r=this.get(n,!0);return i.length===0?!t&&W.isScalar(r)?r.value:r:W.isCollection(r)?r.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!W.isPair(t))return!1;let n=t.value;return n==null||e&&W.isScalar(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let i=this.get(t,!0);return W.isCollection(i)?i.hasIn(n):!1}setIn(e,t){let[n,...i]=e;if(i.length===0)this.set(n,t);else{let r=this.get(n,!0);if(W.isCollection(r))r.setIn(i,t);else if(r===void 0&&this.schema)this.set(n,Ws(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}};$t.Collection=Gs;$t.collectionFromPath=Ws;$t.isEmptyPath=br});var We=b(xt=>{"use strict";var Ac=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function Xs(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var Tc=(s,e,t)=>s.endsWith(`
|