just-bash 1.4.0 → 1.4.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.
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import{a as N}from"./chunk-26Q3PZQ6.js";import{a as L,b as B,c as H}from"./chunk-PM2DS2YW.js";import{a as I,b as O}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let r=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=r>e.days:e.comparison==="less"?t=r<e.days:t=Math.floor(r)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let r;return e.comparison==="more"?r=s.size>n:e.comparison==="less"?r=s.size<n:e.unit==="b"?r=Math.ceil(s.size/512)===e.value:r=s.size===n,{matches:r,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,r=e.mode&511,t;return e.matchType==="exact"?t=n===r:e.matchType==="all"?t=(n&r)===r:t=(n&r)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:n.printed||r.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let r=w(e.right,s);return{matches:r.matches,pruned:n.pruned||r.pruned,printed:r.printed}}}}function G(e){let s=[],n=r=>{r&&(r.type==="newer"?s.push(r.refPath):r.type==="not"?n(r.expr):(r.type==="and"||r.type==="or")&&(n(r.left),n(r.right)))};return n(e),s}function j(e,s){let n=[],r=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let i=e[++t];if(i==="f"||i==="d")n.push({type:"expr",expr:{type:"type",fileType:i}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${i}
3
- `,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let i=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:i}})}else if(a==="-size"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("+")?(c="more",o=i.slice(1)):i.startsWith("-")&&(c="less",o=i.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let i=e[++t],c="exact",o=i;i.startsWith("-")?(c="all",o=i.slice(1)):i.startsWith("/")&&(c="any",o=i.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let i=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)i.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";r.push({type:"exec",command:i,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),r.push({type:"print"});else if(a==="-print0")r.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let i=e[++t];r.push({type:"printf",format:i})}else if(a==="-delete")r.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
4
- `,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:r};let m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:r}:{expr:m.expr,pathIndex:t,actions:r}}function _(e){let s=0;function n(){let i=r();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let o=r();if(!o)return i;i={type:"or",left:i,right:o}}else break}return i}function r(){let i=t();if(!i)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return i;i={type:"and",left:i,right:o}}else break}return i}function t(){if(s<e.length&&e[s].type==="not"){s++;let i=t();return i?{type:"not",expr:i}:null}return m()}function m(){if(s>=e.length)return null;let i=e[s];if(i.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return i.type==="expr"?(s++,i.expr):(i.type==="rparen",null)}return{expr:n()}}var K={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],r=null,t=null,m=!1,a=!1;for(let p=0;p<e.length;p++){let l=e[p];if(l==="-maxdepth"&&p+1<e.length)a=!0,r=parseInt(e[++p],10);else if(l==="-mindepth"&&p+1<e.length)a=!0,t=parseInt(e[++p],10);else if(l==="-depth")a=!0,m=!0;else if(l==="-exec")for(a=!0,p++;p<e.length&&e[p]!==";"&&e[p]!=="+";)p++;else!l.startsWith("-")&&l!==";"&&l!=="+"&&l!=="("&&l!==")"&&l!=="\\("&&l!=="\\)"&&l!=="!"?a||n.push(l):U.has(l)?(a=!0,p++):(l.startsWith("-")||l==="("||l==="\\("||l==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:i,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(p=>p.type==="print"),b=o.length===0,y=[],Y=o.some(p=>p.type==="printf"),F=[],T="",D=0,V=G(i),k=new Map;for(let p of V){let l=s.fs.resolvePath(s.cwd,p);try{let g=await s.fs.stat(l);k.set(p,g.mtime?.getTime()??Date.now())}catch{}}for(let p of n){let l=s.fs.resolvePath(s.cwd,p);try{await s.fs.stat(l)}catch{T+=`find: ${p}: No such file or directory
5
- `,D=1;continue}async function g(u,d){if(r!==null&&d>r)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===l?E=p.split("/").pop()||p:E=u.split("/").pop()||"";let $=u===l?p:p==="."?`./${u.slice(l.length+1)}`:p+u.slice(l.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,v=!1;if(x&&i!==null){let J={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},W=w(i,J);x=W.matches,h?v=W.printed:v=x}else x&&(v=!0);v&&(y.push($),Y&&F.push({path:$,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:p}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},z=!1;if(!m&&i!==null){let P={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};z=w(i,P).pruned}m?(await A(),C()):(C(),z||await A())}await g(l,0)}let S="";if(o.length>0)for(let p of o)switch(p.type){case"print":S+=y.length>0?`${y.join(`
2
+ import{a as N}from"./chunk-26Q3PZQ6.js";import{a as L,b as B,c as H}from"./chunk-PM2DS2YW.js";import{a as I,b as O}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";function w(e,s){switch(e.type){case"name":return{matches:N(s.name,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"path":return{matches:N(s.relativePath,e.pattern,e.ignoreCase),pruned:!1,printed:!1};case"regex":try{let n=e.ignoreCase?"i":"";return{matches:new RegExp(e.pattern,n).test(s.relativePath),pruned:!1,printed:!1}}catch{return{matches:!1,pruned:!1,printed:!1}}case"type":return e.fileType==="f"?{matches:s.isFile,pruned:!1,printed:!1}:e.fileType==="d"?{matches:s.isDirectory,pruned:!1,printed:!1}:{matches:!1,pruned:!1,printed:!1};case"empty":return{matches:s.isEmpty,pruned:!1,printed:!1};case"mtime":{let i=(Date.now()-s.mtime)/(1e3*60*60*24),t;return e.comparison==="more"?t=i>e.days:e.comparison==="less"?t=i<e.days:t=Math.floor(i)===e.days,{matches:t,pruned:!1,printed:!1}}case"newer":{let n=s.newerRefTimes.get(e.refPath);return n===void 0?{matches:!1,pruned:!1,printed:!1}:{matches:s.mtime>n,pruned:!1,printed:!1}}case"size":{let n=e.value;switch(e.unit){case"c":n=e.value;break;case"k":n=e.value*1024;break;case"M":n=e.value*1024*1024;break;case"G":n=e.value*1024*1024*1024;break;case"b":n=e.value*512;break}let i;return e.comparison==="more"?i=s.size>n:e.comparison==="less"?i=s.size<n:e.unit==="b"?i=Math.ceil(s.size/512)===e.value:i=s.size===n,{matches:i,pruned:!1,printed:!1}}case"perm":{let n=s.mode&511,i=e.mode&511,t;return e.matchType==="exact"?t=n===i:e.matchType==="all"?t=(n&i)===i:t=(n&i)!==0,{matches:t,pruned:!1,printed:!1}}case"prune":return{matches:!0,pruned:!0,printed:!1};case"print":return{matches:!0,pruned:!1,printed:!0};case"not":{let n=w(e.expr,s);return{matches:!n.matches,pruned:n.pruned,printed:!1}}case"and":{let n=w(e.left,s);if(!n.matches)return{matches:!1,pruned:n.pruned,printed:!1};let i=w(e.right,s);return{matches:i.matches,pruned:n.pruned||i.pruned,printed:n.printed||i.printed}}case"or":{let n=w(e.left,s);if(n.matches)return n;let i=w(e.right,s);return{matches:i.matches,pruned:n.pruned||i.pruned,printed:i.printed}}}}function G(e){let s=[],n=i=>{i&&(i.type==="newer"?s.push(i.refPath):i.type==="not"?n(i.expr):(i.type==="and"||i.type==="or")&&(n(i.left),n(i.right)))};return n(e),s}function j(e,s){let n=[],i=[],t=s;for(;t<e.length;){let a=e[t];if(a==="("||a==="\\("){n.push({type:"lparen"}),t++;continue}if(a===")"||a==="\\)"){n.push({type:"rparen"}),t++;continue}if(a==="-name"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t]}});else if(a==="-iname"&&t+1<e.length)n.push({type:"expr",expr:{type:"name",pattern:e[++t],ignoreCase:!0}});else if(a==="-path"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t]}});else if(a==="-ipath"&&t+1<e.length)n.push({type:"expr",expr:{type:"path",pattern:e[++t],ignoreCase:!0}});else if(a==="-regex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t]}});else if(a==="-iregex"&&t+1<e.length)n.push({type:"expr",expr:{type:"regex",pattern:e[++t],ignoreCase:!0}});else if(a==="-type"&&t+1<e.length){let r=e[++t];if(r==="f"||r==="d")n.push({type:"expr",expr:{type:"type",fileType:r}});else return{expr:null,pathIndex:t,error:`find: Unknown argument to -type: ${r}
3
+ `,actions:[]}}else if(a==="-empty")n.push({type:"expr",expr:{type:"empty"}});else if(a==="-mtime"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("+")?(c="more",o=r.slice(1)):r.startsWith("-")&&(c="less",o=r.slice(1));let h=parseInt(o,10);Number.isNaN(h)||n.push({type:"expr",expr:{type:"mtime",days:h,comparison:c}})}else if(a==="-newer"&&t+1<e.length){let r=e[++t];n.push({type:"expr",expr:{type:"newer",refPath:r}})}else if(a==="-size"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("+")?(c="more",o=r.slice(1)):r.startsWith("-")&&(c="less",o=r.slice(1));let h=o.match(/^(\d+)([ckMGb])?$/);if(h){let b=parseInt(h[1],10),y=h[2]||"b";n.push({type:"expr",expr:{type:"size",value:b,unit:y,comparison:c}})}}else if(a==="-perm"&&t+1<e.length){let r=e[++t],c="exact",o=r;r.startsWith("-")?(c="all",o=r.slice(1)):r.startsWith("/")&&(c="any",o=r.slice(1));let h=parseInt(o,8);Number.isNaN(h)||n.push({type:"expr",expr:{type:"perm",mode:h,matchType:c}})}else if(a==="-prune")n.push({type:"expr",expr:{type:"prune"}});else if(a==="-not"||a==="!")n.push({type:"not"});else if(a==="-o"||a==="-or")n.push({type:"op",op:"or"});else if(a==="-a"||a==="-and")n.push({type:"op",op:"and"});else if(a==="-maxdepth"||a==="-mindepth")t++;else if(a!=="-depth")if(a==="-exec"){let r=[];for(t++;t<e.length&&e[t]!==";"&&e[t]!=="+";)r.push(e[t]),t++;if(t>=e.length)return{expr:null,pathIndex:t,error:"find: missing argument to `-exec'\n",actions:[]};let c=e[t]==="+";i.push({type:"exec",command:r,batchMode:c})}else if(a==="-print")n.push({type:"expr",expr:{type:"print"}}),i.push({type:"print"});else if(a==="-print0")i.push({type:"print0"});else if(a==="-printf"&&t+1<e.length){let r=e[++t];i.push({type:"printf",format:r})}else if(a==="-delete")i.push({type:"delete"});else{if(a.startsWith("-"))return{expr:null,pathIndex:t,error:`find: unknown predicate '${a}'
4
+ `,actions:[]};if(n.length===0){t++;continue}break}t++}if(n.length===0)return{expr:null,pathIndex:t,actions:i};let m=_(n);return m.error?{expr:null,pathIndex:t,error:m.error,actions:i}:{expr:m.expr,pathIndex:t,actions:i}}function _(e){let s=0;function n(){let r=i();if(!r)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="or"){s++;let o=i();if(!o)return r;r={type:"or",left:r,right:o}}else break}return r}function i(){let r=t();if(!r)return null;for(;s<e.length;){let c=e[s];if(c.type==="op"&&c.op==="and"){s++;let o=t();if(!o)return r;r={type:"and",left:r,right:o}}else if(c.type==="expr"||c.type==="not"||c.type==="lparen"){let o=t();if(!o)return r;r={type:"and",left:r,right:o}}else break}return r}function t(){if(s<e.length&&e[s].type==="not"){s++;let r=t();return r?{type:"not",expr:r}:null}return m()}function m(){if(s>=e.length)return null;let r=e[s];if(r.type==="lparen"){s++;let c=n();return s<e.length&&e[s].type==="rparen"&&s++,c}return r.type==="expr"?(s++,r.expr):(r.type==="rparen",null)}return{expr:n()}}var K={name:"find",summary:"search for files in a directory hierarchy",usage:"find [path...] [expression]",options:["-name PATTERN file name matches shell pattern PATTERN","-iname PATTERN like -name but case insensitive","-path PATTERN file path matches shell pattern PATTERN","-ipath PATTERN like -path but case insensitive","-regex PATTERN file path matches regular expression PATTERN","-iregex PATTERN like -regex but case insensitive","-type TYPE file is of type: f (regular file), d (directory)","-empty file is empty or directory is empty","-mtime N file's data was modified N*24 hours ago","-newer FILE file was modified more recently than FILE","-size N[ckMGb] file uses N units of space (c=bytes, k=KB, M=MB, G=GB, b=512B blocks)","-perm MODE file's permission bits are exactly MODE (octal)","-perm -MODE all permission bits MODE are set","-perm /MODE any permission bits MODE are set","-maxdepth LEVELS descend at most LEVELS directories","-mindepth LEVELS do not apply tests at levels less than LEVELS","-depth process directory contents before directory itself","-prune do not descend into this directory","-not, ! negate the following expression","-a, -and logical AND (default)","-o, -or logical OR","-exec CMD {} ; execute CMD on each file ({} is replaced by filename)","-exec CMD {} + execute CMD with multiple files at once","-print print the full file name (default action)","-print0 print the full file name followed by a null character","-printf FORMAT print FORMAT with directives: %f %h %p %P %s %d %m %M %t","-delete delete found files/directories"," --help display this help and exit"]},U=new Set(["-name","-iname","-path","-ipath","-regex","-iregex","-type","-maxdepth","-mindepth","-mtime","-newer","-size","-perm"]),oe={name:"find",async execute(e,s){if(O(e))return I(K);let n=[],i=null,t=null,m=!1,a=!1;for(let l=0;l<e.length;l++){let p=e[l];if(p==="-maxdepth"&&l+1<e.length)a=!0,i=parseInt(e[++l],10);else if(p==="-mindepth"&&l+1<e.length)a=!0,t=parseInt(e[++l],10);else if(p==="-depth")a=!0,m=!0;else if(p==="-exec")for(a=!0,l++;l<e.length&&e[l]!==";"&&e[l]!=="+";)l++;else!p.startsWith("-")&&p!==";"&&p!=="+"&&p!=="("&&p!==")"&&p!=="\\("&&p!=="\\)"&&p!=="!"?a||n.push(p):U.has(p)?(a=!0,l++):(p.startsWith("-")||p==="("||p==="\\("||p==="!")&&(a=!0)}n.length===0&&n.push(".");let{expr:r,error:c,actions:o}=j(e,0);if(c)return{stdout:"",stderr:c,exitCode:1};let h=o.some(l=>l.type==="print"),b=o.length===0,y=[],Y=o.some(l=>l.type==="printf"),F=[],T="",D=0,V=G(r),k=new Map;for(let l of V){let p=s.fs.resolvePath(s.cwd,l);try{let g=await s.fs.stat(p);k.set(l,g.mtime?.getTime()??Date.now())}catch{}}for(let l of n){l.length>1&&l.endsWith("/")&&(l=l.slice(0,-1));let p=s.fs.resolvePath(s.cwd,l);try{await s.fs.stat(p)}catch{T+=`find: ${l}: No such file or directory
5
+ `,D=1;continue}async function g(u,d){if(i!==null&&d>i)return;let f;try{f=await s.fs.stat(u)}catch{return}if(!f)return;let E;u===p?E=l.split("/").pop()||l:E=u.split("/").pop()||"";let $=u===p?l:l==="."?`./${u.slice(p==="/"?p.length:p.length+1)}`:l+u.slice(p.length),M=null;f.isDirectory&&(M=await s.fs.readdir(u));let R=f.isFile?f.size===0:M!==null&&M.length===0,C=()=>{let x=t===null||d>=t,v=!1;if(x&&r!==null){let J={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k},z=w(r,J);x=z.matches,h?v=z.printed:v=x}else x&&(v=!0);v&&(y.push($),Y&&F.push({path:$,name:E,size:f.size??0,mtime:f.mtime?.getTime()??Date.now(),mode:f.mode??420,isDirectory:f.isDirectory,depth:d,startingPoint:l}))},A=async()=>{if(M!==null)for(let P of M){let x=u==="/"?`/${P}`:`${u}/${P}`;await g(x,d+1)}},W=!1;if(!m&&r!==null){let P={name:E,relativePath:$,isFile:f.isFile,isDirectory:f.isDirectory,isEmpty:R,mtime:f.mtime?.getTime()??Date.now(),size:f.size??0,mode:f.mode??420,newerRefTimes:k};W=w(r,P).pruned}m?(await A(),C()):(C(),W||await A())}await g(p,0)}let S="";if(o.length>0)for(let l of o)switch(l.type){case"print":S+=y.length>0?`${y.join(`
6
6
  `)}
7
- `:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let l=[...y].sort((g,u)=>u.length-g.length);for(let g of l){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
8
- `,D=1}}break}case"printf":for(let l of F)S+=q(p.format,l);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
9
- `,exitCode:1};if(p.batchMode){let l=[];for(let d of p.command)d==="{}"?l.push(...y):l.push(d);let g=l.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let l of y){let u=p.command.map(f=>f==="{}"?l:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
7
+ `:"";break;case"print0":S+=y.length>0?`${y.join("\0")}\0`:"";break;case"delete":{let p=[...y].sort((g,u)=>u.length-g.length);for(let g of p){let u=s.fs.resolvePath(s.cwd,g);try{await s.fs.rm(u,{recursive:!1})}catch(d){let f=d instanceof Error?d.message:String(d);T+=`find: cannot delete '${g}': ${f}
8
+ `,D=1}}break}case"printf":for(let p of F)S+=q(l.format,p);break;case"exec":if(!s.exec)return{stdout:"",stderr:`find: -exec not supported in this context
9
+ `,exitCode:1};if(l.batchMode){let p=[];for(let d of l.command)d==="{}"?p.push(...y):p.push(d);let g=p.map(d=>`"${d}"`).join(" "),u=await s.exec(g,{cwd:s.cwd});S+=u.stdout,T+=u.stderr,u.exitCode!==0&&(D=u.exitCode)}else for(let p of y){let u=l.command.map(f=>f==="{}"?p:f).map(f=>`"${f}"`).join(" "),d=await s.exec(u,{cwd:s.cwd});S+=d.stdout,T+=d.stderr,d.exitCode!==0&&(D=d.exitCode)}break}else b&&(S=y.length>0?`${y.join(`
10
10
  `)}
11
- `:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),r="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){r+="%",t++;continue}let[m,a,i]=B(n,t);if(t+=i,t>=n.length){r+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:r+=`%${m!==0||a!==-1?`${m}.${a}`:""}${c}`,t++;continue}r+=L(o,m,a)}else r+=n[t],t++;return r}function Q(e,s){let n=e&511,r=s?"d":"-";return r+=n&256?"r":"-",r+=n&128?"w":"-",r+=n&64?"x":"-",r+=n&32?"r":"-",r+=n&16?"w":"-",r+=n&8?"x":"-",r+=n&4?"r":"-",r+=n&2?"w":"-",r+=n&1?"x":"-",r}function X(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],r=s[e.getDay()],t=n[e.getMonth()],m=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),o=e.getFullYear();return`${r} ${t} ${m} ${a}:${i}:${c} ${o}`}function Z(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{oe as findCommand};
11
+ `:"");return{stdout:S,stderr:T,exitCode:D}}};function q(e,s){let n=H(e),i="",t=0;for(;t<n.length;)if(n[t]==="%"&&t+1<n.length){if(t++,n[t]==="%"){i+="%",t++;continue}let[m,a,r]=B(n,t);if(t+=r,t>=n.length){i+="%";break}let c=n[t],o;switch(c){case"f":o=s.name,t++;break;case"h":{let h=s.path.lastIndexOf("/");o=h>0?s.path.slice(0,h):".",t++;break}case"p":o=s.path,t++;break;case"P":{let h=s.startingPoint;s.path===h?o="":s.path.startsWith(`${h}/`)?o=s.path.slice(h.length+1):h==="."&&s.path.startsWith("./")?o=s.path.slice(2):o=s.path,t++;break}case"s":o=String(s.size),t++;break;case"d":o=String(s.depth),t++;break;case"m":o=(s.mode&511).toString(8),t++;break;case"M":o=Q(s.mode,s.isDirectory),t++;break;case"t":{let h=new Date(s.mtime);o=X(h),t++;break}case"T":{if(t+1<n.length){let h=n[t+1],b=new Date(s.mtime);o=Z(b,h),t+=2}else o="%T",t++;break}default:i+=`%${m!==0||a!==-1?`${m}.${a}`:""}${c}`,t++;continue}i+=L(o,m,a)}else i+=n[t],t++;return i}function Q(e,s){let n=e&511,i=s?"d":"-";return i+=n&256?"r":"-",i+=n&128?"w":"-",i+=n&64?"x":"-",i+=n&32?"r":"-",i+=n&16?"w":"-",i+=n&8?"x":"-",i+=n&4?"r":"-",i+=n&2?"w":"-",i+=n&1?"x":"-",i}function X(e){let s=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],i=s[e.getDay()],t=n[e.getMonth()],m=String(e.getDate()).padStart(2," "),a=String(e.getHours()).padStart(2,"0"),r=String(e.getMinutes()).padStart(2,"0"),c=String(e.getSeconds()).padStart(2,"0"),o=e.getFullYear();return`${i} ${t} ${m} ${a}:${r}:${c} ${o}`}function Z(e,s){switch(s){case"@":return String(e.getTime()/1e3);case"Y":return String(e.getFullYear());case"m":return String(e.getMonth()+1).padStart(2,"0");case"d":return String(e.getDate()).padStart(2,"0");case"H":return String(e.getHours()).padStart(2,"0");case"M":return String(e.getMinutes()).padStart(2,"0");case"S":return String(e.getSeconds()).padStart(2,"0");case"T":return`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}:${String(e.getSeconds()).padStart(2,"0")}`;case"F":return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`;default:return`%T${s}`}}export{oe as findCommand};
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import{i as g}from"./chunk-NWWB2XRE.js";import{a as L,b as M,c as T}from"./chunk-GTNBSMZR.js";import"./chunk-SJXDWN5X.js";var K=1e4;function W(t){return{vars:new Map,limits:{maxIterations:t?.maxIterations??K}}}function w(t,r,s){let i=new Map(t.vars);return i.set(r,s),{vars:i,limits:t.limits}}function u(t,r,s){let i=s&&"vars"in s?s:W(s?.limits);switch(r.type){case"Identity":return[t];case"Field":return(r.base?u(t,r.base,i):[t]).flatMap(n=>n&&typeof n=="object"&&!Array.isArray(n)?[n[r.name]]:[null]);case"Index":return(r.base?u(t,r.base,i):[t]).flatMap(n=>u(n,r.index,i).flatMap(f=>{if(typeof f=="number"&&Array.isArray(n)){let c=f<0?n.length+f:f;return c>=0&&c<n.length?[n[c]]:[null]}return typeof f=="string"&&n&&typeof n=="object"&&!Array.isArray(n)?[n[f]]:[null]}));case"Slice":return(r.base?u(t,r.base,i):[t]).flatMap(n=>{if(!Array.isArray(n)&&typeof n!="string")return[null];let o=n.length,f=r.start?u(t,r.start,i):[0],c=r.end?u(t,r.end,i):[o];return f.flatMap(p=>c.map(y=>{let h=D(p,o),l=D(y,o);return Array.isArray(n),n.slice(h,l)}))});case"Iterate":return(r.base?u(t,r.base,i):[t]).flatMap(n=>Array.isArray(n)?n:n&&typeof n=="object"?Object.values(n):[]);case"Pipe":return u(t,r.left,i).flatMap(n=>u(n,r.right,i));case"Comma":{let e=u(t,r.left,i),n=u(t,r.right,i);return[...e,...n]}case"Literal":return[r.value];case"Array":return r.elements?[u(t,r.elements,i)]:[[]];case"Object":{let e=[{}];for(let n of r.entries){let o=typeof n.key=="string"?[n.key]:u(t,n.key,i),f=u(t,n.value,i),c=[];for(let p of e)for(let y of o)for(let h of f)c.push({...p,[String(y)]:h});e.length=0,e.push(...c)}return e}case"Paren":return u(t,r.expr,i);case"BinaryOp":return V(t,r.op,r.left,r.right,i);case"UnaryOp":return u(t,r.operand,i).map(n=>r.op==="-"?typeof n=="number"?-n:null:r.op==="not"?!b(n):null);case"Cond":return u(t,r.cond,i).flatMap(n=>{if(b(n))return u(t,r.then,i);for(let o of r.elifs)if(u(t,o.cond,i).some(b))return u(t,o.then,i);return r.else?u(t,r.else,i):[null]});case"Try":try{return u(t,r.body,i)}catch{return r.catch?u(t,r.catch,i):[]}case"Call":return B(t,r.name,r.args,i);case"VarBind":return u(t,r.value,i).flatMap(n=>{let o=w(i,r.name,n);return u(t,r.body,o)});case"VarRef":{let e=i.vars.get(r.name);return e!==void 0?[e]:[null]}case"Recurse":{let e=[],n=new WeakSet,o=f=>{if(f&&typeof f=="object"){if(n.has(f))return;n.add(f)}if(e.push(f),Array.isArray(f))for(let c of f)o(c);else if(f&&typeof f=="object")for(let c of Object.keys(f))o(f[c])};return o(t),e}case"Optional":try{return u(t,r.expr,i)}catch{return[]}case"StringInterp":return[r.parts.map(n=>typeof n=="string"?n:u(t,n,i).map(f=>typeof f=="string"?f:JSON.stringify(f)).join("")).join("")];case"UpdateOp":return[G(t,r.path,r.op,r.value,i)];case"Reduce":{let e=u(t,r.expr,i),n=u(t,r.init,i)[0];for(let o of e){let f=w(i,r.varName,o);n=u(n,r.update,f)[0]}return[n]}case"Foreach":{let e=u(t,r.expr,i),n=u(t,r.init,i)[0],o=[];for(let f of e){let c=w(i,r.varName,f);if(n=u(n,r.update,c)[0],r.extract){let p=u(n,r.extract,c);o.push(...p)}else o.push(n)}return o}default:{let e=r;throw new Error(`Unknown AST node type: ${e.type}`)}}}function D(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function G(t,r,s,i,e){function n(c,p){switch(s){case"=":return p;case"|=":return u(c,i,e)[0]??null;case"+=":return typeof c=="number"&&typeof p=="number"||typeof c=="string"&&typeof p=="string"?c+p:Array.isArray(c)&&Array.isArray(p)?[...c,...p]:c&&p&&typeof c=="object"&&typeof p=="object"?{...c,...p}:p;case"-=":return typeof c=="number"&&typeof p=="number"?c-p:c;case"*=":return typeof c=="number"&&typeof p=="number"?c*p:c;case"/=":return typeof c=="number"&&typeof p=="number"?c/p:c;case"%=":return typeof c=="number"&&typeof p=="number"?c%p:c;case"//=":return c===null||c===!1?p:c;default:return p}}function o(c,p,y){switch(p.type){case"Identity":return y(c);case"Field":{if(p.base)return o(c,p.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let l={...h};return l[p.name]=y(l[p.name]),l}return h});if(c&&typeof c=="object"&&!Array.isArray(c)){let h={...c};return h[p.name]=y(h[p.name]),h}return c}case"Index":{let l=u(t,p.index,e)[0];if(p.base)return o(c,p.base,A=>{if(typeof l=="number"&&Array.isArray(A)){let m=[...A],a=l<0?m.length+l:l;return a>=0&&a<m.length&&(m[a]=y(m[a])),m}if(typeof l=="string"&&A&&typeof A=="object"&&!Array.isArray(A)){let m={...A};return m[l]=y(m[l]),m}return A});if(typeof l=="number"&&Array.isArray(c)){let A=[...c],m=l<0?A.length+l:l;return m>=0&&m<A.length&&(A[m]=y(A[m])),A}if(typeof l=="string"&&c&&typeof c=="object"&&!Array.isArray(c)){let A={...c};return A[l]=y(A[l]),A}return c}case"Iterate":{let h=l=>{if(Array.isArray(l))return l.map(A=>y(A));if(l&&typeof l=="object"){let A={};for(let[m,a]of Object.entries(l))A[m]=y(a);return A}return l};return p.base?o(c,p.base,h):h(c)}case"Pipe":{let h=o(c,p.left,l=>l);return o(h,p.right,y)}default:return y(c)}}return o(t,r,c=>{if(s==="|=")return n(c,c);let p=u(t,i,e);return n(c,p[0]??null)})}function H(t,r,s){function i(e,n){switch(n.type){case"Identity":return null;case"Field":{if(e&&typeof e=="object"&&!Array.isArray(e)){let o={...e};return delete o[n.name],o}return e}case"Index":{let f=u(t,n.index,s)[0];if(typeof f=="number"&&Array.isArray(e)){let c=[...e],p=f<0?c.length+f:f;return p>=0&&p<c.length&&c.splice(p,1),c}if(typeof f=="string"&&e&&typeof e=="object"&&!Array.isArray(e)){let c={...e};return delete c[f],c}return e}case"Iterate":return Array.isArray(e)?[]:e&&typeof e=="object"?{}:e;default:return e}}return i(t,r)}function b(t){return t!==null&&t!==!1}function V(t,r,s,i,e){if(r==="and")return u(t,s,e).flatMap(c=>b(c)?u(t,i,e).map(y=>b(y)):[!1]);if(r==="or")return u(t,s,e).flatMap(c=>b(c)?[!0]:u(t,i,e).map(y=>b(y)));if(r==="//"){let c=u(t,s,e).filter(p=>p!=null&&p!==!1);return c.length>0?c:u(t,i,e)}let n=u(t,s,e),o=u(t,i,e);return n.flatMap(f=>o.map(c=>{switch(r){case"+":return typeof f=="number"&&typeof c=="number"||typeof f=="string"&&typeof c=="string"?f+c:Array.isArray(f)&&Array.isArray(c)?[...f,...c]:f&&c&&typeof f=="object"&&typeof c=="object"&&!Array.isArray(f)&&!Array.isArray(c)?{...f,...c}:null;case"-":if(typeof f=="number"&&typeof c=="number")return f-c;if(Array.isArray(f)&&Array.isArray(c)){let p=new Set(c.map(y=>JSON.stringify(y)));return f.filter(y=>!p.has(JSON.stringify(y)))}return null;case"*":return typeof f=="number"&&typeof c=="number"?f*c:typeof f=="string"&&typeof c=="number"?f.repeat(c):f&&c&&typeof f=="object"&&typeof c=="object"&&!Array.isArray(f)&&!Array.isArray(c)?U(f,c):null;case"/":return typeof f=="number"&&typeof c=="number"?f/c:typeof f=="string"&&typeof c=="string"?f.split(c):null;case"%":return typeof f=="number"&&typeof c=="number"?f%c:null;case"==":return O(f,c);case"!=":return!O(f,c);case"<":return N(f,c)<0;case"<=":return N(f,c)<=0;case">":return N(f,c)>0;case">=":return N(f,c)>=0;default:return null}}))}function O(t,r){return JSON.stringify(t)===JSON.stringify(r)}function N(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function U(t,r){let s={...t};for(let i of Object.keys(r))i in s&&s[i]&&typeof s[i]=="object"&&!Array.isArray(s[i])&&r[i]&&typeof r[i]=="object"&&!Array.isArray(r[i])?s[i]=U(s[i],r[i]):s[i]=r[i];return s}function B(t,r,s,i){switch(r){case"keys":return Array.isArray(t)?[t.map((e,n)=>n)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((e,n)=>n)]:t&&typeof t=="object"?[Object.keys(t)]:[null];case"values":return Array.isArray(t)?[t]:t&&typeof t=="object"?[Object.values(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]:[null];case"utf8bytelength":return typeof t=="string"?[new TextEncoder().encode(t).length]:[null];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"empty":return[];case"error":{let e=s.length>0?u(t,s[0],i)[0]:t;throw new Error(String(e))}case"not":return[!b(t)];case"null":return[null];case"true":return[!0];case"false":return[!1];case"first":if(s.length>0){let e=u(t,s[0],i);return e.length>0?[e[0]]:[]}return Array.isArray(t)&&t.length>0?[t[0]]:[null];case"last":if(s.length>0){let e=u(t,s[0],i);return e.length>0?[e[e.length-1]]:[]}return Array.isArray(t)&&t.length>0?[t[t.length-1]]:[null];case"nth":{if(s.length<1)return[null];let n=u(t,s[0],i)[0];if(s.length>1){let o=u(t,s[1],i);return n>=0&&n<o.length?[o[n]]:[]}return Array.isArray(t)?n>=0&&n<t.length?[t[n]]:[null]:[null]}case"range":{if(s.length===0)return[];let e=u(t,s[0],i);if(s.length===1){let p=e[0];return Array.from({length:p},(y,h)=>h)}let n=u(t,s[1],i),o=e[0],f=n[0],c=[];for(let p=o;p<f;p++)c.push(p);return c}case"reverse":return Array.isArray(t)?[[...t].reverse()]:typeof t=="string"?[t.split("").reverse().join("")]:[null];case"sort":return Array.isArray(t)?[[...t].sort(j)]:[null];case"sort_by":return!Array.isArray(t)||s.length===0?[null]:[[...t].sort((n,o)=>{let f=u(n,s[0],i)[0],c=u(o,s[0],i)[0];return j(f,c)})];case"unique":if(Array.isArray(t)){let e=new Set,n=[];for(let o of t){let f=JSON.stringify(o);e.has(f)||(e.add(f),n.push(o))}return[n]}return[null];case"unique_by":{if(!Array.isArray(t)||s.length===0)return[null];let e=new Set,n=[];for(let o of t){let f=JSON.stringify(u(o,s[0],i)[0]);e.has(f)||(e.add(f),n.push(o))}return[n]}case"group_by":{if(!Array.isArray(t)||s.length===0)return[null];let e=new Map;for(let n of t){let o=JSON.stringify(u(n,s[0],i)[0]);e.has(o)||e.set(o,[]),e.get(o)?.push(n)}return[[...e.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((e,n)=>j(e,n)>0?e:n)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||s.length===0?[null]:[t.reduce((e,n)=>{let o=u(e,s[0],i)[0],f=u(n,s[0],i)[0];return j(o,f)>0?e:n})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((e,n)=>j(e,n)<0?e:n)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||s.length===0?[null]:[t.reduce((e,n)=>{let o=u(e,s[0],i)[0],f=u(n,s[0],i)[0];return j(o,f)<0?e:n})];case"flatten":{if(!Array.isArray(t))return[null];let e=s.length>0?u(t,s[0],i)[0]:Number.POSITIVE_INFINITY;return[t.flat(e)]}case"add":if(Array.isArray(t)){if(t.length===0)return[null];if(t.every(e=>typeof e=="number"))return[t.reduce((e,n)=>e+n,0)];if(t.every(e=>typeof e=="string"))return[t.join("")];if(t.every(e=>Array.isArray(e)))return[t.flat()];if(t.every(e=>e&&typeof e=="object"&&!Array.isArray(e)))return[Object.assign({},...t)]}return[null];case"any":return s.length>0?Array.isArray(t)?[t.some(e=>b(u(e,s[0],i)[0]))]:[!1]:Array.isArray(t)?[t.some(b)]:[!1];case"all":return s.length>0?Array.isArray(t)?[t.every(e=>b(u(e,s[0],i)[0]))]:[!0]:Array.isArray(t)?[t.every(b)]:[!0];case"select":return s.length===0?[t]:u(t,s[0],i).some(b)?[t]:[];case"map":return s.length===0||!Array.isArray(t)?[null]:[t.flatMap(n=>u(n,s[0],i))];case"map_values":{if(s.length===0)return[null];if(Array.isArray(t))return[t.flatMap(e=>u(e,s[0],i))];if(t&&typeof t=="object"){let e={};for(let[n,o]of Object.entries(t)){let f=u(o,s[0],i);f.length>0&&(e[n]=f[0])}return[e]}return[null]}case"has":{if(s.length===0)return[!1];let n=u(t,s[0],i)[0];return Array.isArray(t)&&typeof n=="number"?[n>=0&&n<t.length]:t&&typeof t=="object"&&typeof n=="string"?[n in t]:[!1]}case"in":{if(s.length===0)return[!1];let n=u(t,s[0],i)[0];return Array.isArray(n)&&typeof t=="number"?[t>=0&&t<n.length]:n&&typeof n=="object"&&typeof t=="string"?[t in n]:[!1]}case"contains":{if(s.length===0)return[!1];let e=u(t,s[0],i);return[x(t,e[0])]}case"inside":{if(s.length===0)return[!1];let e=u(t,s[0],i);return[x(e[0],t)]}case"getpath":{if(s.length===0)return[null];let n=u(t,s[0],i)[0],o=t;for(let f of n){if(o==null)return[null];if(Array.isArray(o)&&typeof f=="number")o=o[f];else if(typeof o=="object"&&typeof f=="string")o=o[f];else return[null]}return[o]}case"setpath":{if(s.length<2)return[null];let n=u(t,s[0],i)[0],f=u(t,s[1],i)[0];return[I(t,n,f)]}case"delpaths":{if(s.length===0)return[t];let n=u(t,s[0],i)[0],o=t;for(let f of n.sort((c,p)=>p.length-c.length))o=C(o,f);return[o]}case"path":{if(s.length===0)return[[]];let e=[];return Q(t,s[0],i,[],e),e}case"del":return s.length===0?[t]:[H(t,s[0],i)];case"paths":{let e=[],n=(o,f)=>{if(o&&typeof o=="object")if(Array.isArray(o))for(let c=0;c<o.length;c++)e.push([...f,c]),n(o[c],[...f,c]);else for(let c of Object.keys(o))e.push([...f,c]),n(o[c],[...f,c])};return n(t,[]),s.length>0?e.filter(o=>{let f=t;for(let p of o)if(Array.isArray(f)&&typeof p=="number")f=f[p];else if(f&&typeof f=="object"&&typeof p=="string")f=f[p];else return!1;return u(f,s[0],i).some(b)}):e}case"leaf_paths":{let e=[],n=(o,f)=>{if(o===null||typeof o!="object")e.push(f);else if(Array.isArray(o))for(let c=0;c<o.length;c++)n(o[c],[...f,c]);else for(let c of Object.keys(o))n(o[c],[...f,c])};return n(t,[]),[e]}case"to_entries":return t&&typeof t=="object"&&!Array.isArray(t)?[Object.entries(t).map(([e,n])=>({key:e,value:n}))]:[null];case"from_entries":if(Array.isArray(t)){let e={};for(let n of t)if(n&&typeof n=="object"){let o=n,f=o.key??o.name??o.k,c=o.value??o.v;f!==void 0&&(e[String(f)]=c)}return[e]}return[null];case"with_entries":{if(s.length===0)return[t];if(t&&typeof t=="object"&&!Array.isArray(t)){let n=Object.entries(t).map(([f,c])=>({key:f,value:c})).flatMap(f=>u(f,s[0],i)),o={};for(let f of n)if(f&&typeof f=="object"){let c=f,p=c.key??c.name??c.k,y=c.value??c.v;p!==void 0&&(o[String(p)]=y)}return[o]}return[null]}case"join":{if(!Array.isArray(t))return[null];let e=s.length>0?u(t,s[0],i):[""],n=String(e[0]);return[t.map(o=>typeof o=="string"?o:JSON.stringify(o)).join(n)]}case"split":{if(typeof t!="string"||s.length===0)return[null];let e=u(t,s[0],i),n=String(e[0]);return[t.split(n)]}case"test":{if(typeof t!="string"||s.length===0)return[!1];let e=u(t,s[0],i),n=String(e[0]);try{let o=s.length>1?String(u(t,s[1],i)[0]):"";return[new RegExp(n,o).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||s.length===0)return[null];let e=u(t,s[0],i),n=String(e[0]);try{let o=s.length>1?String(u(t,s[1],i)[0]):"",c=new RegExp(n,`${o}d`).exec(t);if(!c)return[];let p=c.indices;return[{offset:c.index,length:c[0].length,string:c[0],captures:c.slice(1).map((y,h)=>({offset:p?.[h+1]?.[0]??null,length:y?.length??0,string:y??"",name:null}))}]}catch{return[null]}}case"capture":{if(typeof t!="string"||s.length===0)return[null];let e=u(t,s[0],i),n=String(e[0]);try{let o=s.length>1?String(u(t,s[1],i)[0]):"",f=new RegExp(n,o),c=t.match(f);return!c||!c.groups?[{}]:[c.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||s.length<2)return[null];let e=u(t,s[0],i),n=u(t,s[1],i),o=String(e[0]),f=String(n[0]);try{let c=s.length>2?String(u(t,s[2],i)[0]):"";return[t.replace(new RegExp(o,c),f)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||s.length<2)return[null];let e=u(t,s[0],i),n=u(t,s[1],i),o=String(e[0]),f=String(n[0]);try{let c=s.length>2?String(u(t,s[2],i)[0]):"g",p=c.includes("g")?c:`${c}g`;return[t.replace(new RegExp(o,p),f)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.toLowerCase()]:[null];case"ascii_upcase":return typeof t=="string"?[t.toUpperCase()]:[null];case"ltrimstr":{if(typeof t!="string"||s.length===0)return[t];let e=u(t,s[0],i),n=String(e[0]);return[t.startsWith(n)?t.slice(n.length):t]}case"rtrimstr":{if(typeof t!="string"||s.length===0)return[t];let e=u(t,s[0],i),n=String(e[0]);return[t.endsWith(n)?t.slice(0,-n.length):t]}case"startswith":{if(typeof t!="string"||s.length===0)return[!1];let e=u(t,s[0],i);return[t.startsWith(String(e[0]))]}case"endswith":{if(typeof t!="string"||s.length===0)return[!1];let e=u(t,s[0],i);return[t.endsWith(String(e[0]))]}case"index":{if(s.length===0)return[null];let n=u(t,s[0],i)[0];if(typeof t=="string"&&typeof n=="string"){let o=t.indexOf(n);return[o>=0?o:null]}if(Array.isArray(t)){let o=t.findIndex(f=>O(f,n));return[o>=0?o:null]}return[null]}case"rindex":{if(s.length===0)return[null];let n=u(t,s[0],i)[0];if(typeof t=="string"&&typeof n=="string"){let o=t.lastIndexOf(n);return[o>=0?o:null]}if(Array.isArray(t)){for(let o=t.length-1;o>=0;o--)if(O(t[o],n))return[o];return[null]}return[null]}case"indices":{if(s.length===0)return[[]];let n=u(t,s[0],i)[0],o=[];if(typeof t=="string"&&typeof n=="string"){let f=t.indexOf(n);for(;f!==-1;)o.push(f),f=t.indexOf(n,f+1)}else if(Array.isArray(t))for(let f=0;f<t.length;f++)O(t[f],n)&&o.push(f);return[o]}case"floor":return typeof t=="number"?[Math.floor(t)]:[null];case"ceil":return typeof t=="number"?[Math.ceil(t)]:[null];case"round":return typeof t=="number"?[Math.round(t)]:[null];case"sqrt":return typeof t=="number"?[Math.sqrt(t)]:[null];case"fabs":case"abs":return typeof t=="number"?[Math.abs(t)]:[null];case"log":return typeof t=="number"?[Math.log(t)]:[null];case"log10":return typeof t=="number"?[Math.log10(t)]:[null];case"log2":return typeof t=="number"?[Math.log2(t)]:[null];case"exp":return typeof t=="number"?[Math.exp(t)]:[null];case"exp10":return typeof t=="number"?[10**t]:[null];case"exp2":return typeof t=="number"?[2**t]:[null];case"pow":{if(typeof t!="number"||s.length===0)return[null];let n=u(t,s[0],i)[0];return[t**n]}case"sin":return typeof t=="number"?[Math.sin(t)]:[null];case"cos":return typeof t=="number"?[Math.cos(t)]:[null];case"tan":return typeof t=="number"?[Math.tan(t)]:[null];case"asin":return typeof t=="number"?[Math.asin(t)]:[null];case"acos":return typeof t=="number"?[Math.acos(t)]:[null];case"atan":return typeof t=="number"?[Math.atan(t)]:[null];case"tostring":return typeof t=="string"?[t]:[JSON.stringify(t)];case"tonumber":if(typeof t=="number")return[t];if(typeof t=="string"){let e=Number(t);return[Number.isNaN(e)?null:e]}return[null];case"infinite":return[!Number.isFinite(t)];case"nan":return[Number.isNaN(t)];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"now":return[Date.now()/1e3];case"env":return[{}];case"recurse":{if(s.length===0){let f=[],c=p=>{if(f.push(p),Array.isArray(p))for(let y of p)c(y);else if(p&&typeof p=="object")for(let y of Object.keys(p))c(p[y])};return c(t),f}let e=[],n=new Set,o=f=>{let c=JSON.stringify(f);if(n.has(c))return;n.add(c),e.push(f);let p=u(f,s[0],i);for(let y of p)y!=null&&o(y)};return o(t),e}case"recurse_down":return B(t,"recurse",s,i);case"walk":{if(s.length===0)return[t];let e=new WeakSet,n=o=>{if(o&&typeof o=="object"){if(e.has(o))return o;e.add(o)}let f;if(Array.isArray(o))f=o.map(n);else if(o&&typeof o=="object"){let p={};for(let[y,h]of Object.entries(o))p[y]=n(h);f=p}else f=o;return u(f,s[0],i)[0]};return[n(t)]}case"transpose":{if(!Array.isArray(t))return[null];if(t.length===0)return[[]];let e=Math.max(...t.map(o=>Array.isArray(o)?o.length:0)),n=[];for(let o=0;o<e;o++)n.push(t.map(f=>Array.isArray(f)?f[o]:null));return[n]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(e=>e.codePointAt(0))]:[null];case"implode":return Array.isArray(t)?[String.fromCodePoint(...t)]:[null];case"tojson":case"tojsonstream":return[JSON.stringify(t)];case"fromjson":{if(typeof t=="string")try{return[JSON.parse(t)]}catch{return[null]}return[null]}case"limit":{if(s.length<2)return[];let n=u(t,s[0],i)[0];return u(t,s[1],i).slice(0,n)}case"until":{if(s.length<2)return[t];let e=t,n=i.limits.maxIterations;for(let o=0;o<n;o++){if(u(e,s[0],i).some(b))return[e];let c=u(e,s[1],i);if(c.length===0)return[e];e=c[0]}throw new g(`jq until: too many iterations (${n}), increase executionLimits.maxJqIterations`,"iterations")}case"while":{if(s.length<2)return[t];let e=[],n=t,o=i.limits.maxIterations;for(let f=0;f<o&&u(n,s[0],i).some(b);f++){e.push(n);let p=u(n,s[1],i);if(p.length===0)break;n=p[0]}if(e.length>=o)throw new g(`jq while: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return e}case"repeat":{if(s.length===0)return[t];let e=[],n=t,o=i.limits.maxIterations;for(let f=0;f<o;f++){e.push(n);let c=u(n,s[0],i);if(c.length===0)break;n=c[0]}if(e.length>=o)throw new g(`jq repeat: too many iterations (${o}), increase executionLimits.maxJqIterations`,"iterations");return e}case"debug":return[t];case"input_line_number":return[1];default:throw new Error(`Unknown function: ${r}`)}}function j(t,r){let s=n=>n===null?0:typeof n=="boolean"?1:typeof n=="number"?2:typeof n=="string"?3:Array.isArray(n)?4:typeof n=="object"?5:6,i=s(t),e=s(r);if(i!==e)return i-e;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 n=0;n<Math.min(t.length,r.length);n++){let o=j(t[n],r[n]);if(o!==0)return o}return t.length-r.length}return 0}function x(t,r){if(O(t,r))return!0;if(Array.isArray(t)&&Array.isArray(r))return r.every(s=>t.some(i=>x(i,s)));if(t&&r&&typeof t=="object"&&typeof r=="object"&&!Array.isArray(t)&&!Array.isArray(r)){let s=t,i=r;return Object.keys(i).every(e=>e in s&&x(s[e],i[e]))}return!1}function I(t,r,s){if(r.length===0)return s;let[i,...e]=r;if(typeof i=="number"){let o=Array.isArray(t)?[...t]:[];for(;o.length<=i;)o.push(null);return o[i]=I(o[i],e,s),o}let n=t&&typeof t=="object"&&!Array.isArray(t)?{...t}:{};return n[i]=I(n[i],e,s),n}function C(t,r){if(r.length===0)return null;if(r.length===1){let e=r[0];if(Array.isArray(t)&&typeof e=="number"){let n=[...t];return n.splice(e,1),n}if(t&&typeof t=="object"&&!Array.isArray(t)){let n={...t};return delete n[String(e)],n}return t}let[s,...i]=r;if(Array.isArray(t)&&typeof s=="number"){let e=[...t];return e[s]=C(e[s],i),e}if(t&&typeof t=="object"&&!Array.isArray(t)){let e={...t};return e[String(s)]=C(e[String(s)],i),e}return t}function Q(t,r,s,i,e){u(t,r,s).length>0&&e.push(i)}var z={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"};function _(t){let r=[],s=0,i=(p=0)=>t[s+p],e=()=>t[s++],n=()=>s>=t.length,o=p=>p>="0"&&p<="9",f=p=>p>="a"&&p<="z"||p>="A"&&p<="Z"||p==="_",c=p=>f(p)||o(p);for(;!n();){let p=s,y=e();if(!(y===" "||y===" "||y===`
3
+ `||y==="\r")){if(y==="#"){for(;!n()&&i()!==`
4
+ `;)e();continue}if(y==="."&&i()==="."){e(),r.push({type:"DOTDOT",pos:p});continue}if(y==="="&&i()==="="){e(),r.push({type:"EQ",pos:p});continue}if(y==="!"&&i()==="="){e(),r.push({type:"NE",pos:p});continue}if(y==="<"&&i()==="="){e(),r.push({type:"LE",pos:p});continue}if(y===">"&&i()==="="){e(),r.push({type:"GE",pos:p});continue}if(y==="/"&&i()==="/"){e(),i()==="="?(e(),r.push({type:"UPDATE_ALT",pos:p})):r.push({type:"ALT",pos:p});continue}if(y==="+"&&i()==="="){e(),r.push({type:"UPDATE_ADD",pos:p});continue}if(y==="-"&&i()==="="){e(),r.push({type:"UPDATE_SUB",pos:p});continue}if(y==="*"&&i()==="="){e(),r.push({type:"UPDATE_MUL",pos:p});continue}if(y==="/"&&i()==="="){e(),r.push({type:"UPDATE_DIV",pos:p});continue}if(y==="%"&&i()==="="){e(),r.push({type:"UPDATE_MOD",pos:p});continue}if(y==="="&&i()!=="="){r.push({type:"ASSIGN",pos:p});continue}if(y==="."){r.push({type:"DOT",pos:p});continue}if(y==="|"){i()==="="?(e(),r.push({type:"UPDATE_PIPE",pos:p})):r.push({type:"PIPE",pos:p});continue}if(y===","){r.push({type:"COMMA",pos:p});continue}if(y===":"){r.push({type:"COLON",pos:p});continue}if(y===";"){r.push({type:"SEMICOLON",pos:p});continue}if(y==="("){r.push({type:"LPAREN",pos:p});continue}if(y===")"){r.push({type:"RPAREN",pos:p});continue}if(y==="["){r.push({type:"LBRACKET",pos:p});continue}if(y==="]"){r.push({type:"RBRACKET",pos:p});continue}if(y==="{"){r.push({type:"LBRACE",pos:p});continue}if(y==="}"){r.push({type:"RBRACE",pos:p});continue}if(y==="?"){r.push({type:"QUESTION",pos:p});continue}if(y==="+"){r.push({type:"PLUS",pos:p});continue}if(y==="-"){if(o(i())){let h=y;for(;!n()&&(o(i())||i()===".");)h+=e();r.push({type:"NUMBER",value:Number(h),pos:p});continue}r.push({type:"MINUS",pos:p});continue}if(y==="*"){r.push({type:"STAR",pos:p});continue}if(y==="/"){r.push({type:"SLASH",pos:p});continue}if(y==="%"){r.push({type:"PERCENT",pos:p});continue}if(y==="<"){r.push({type:"LT",pos:p});continue}if(y===">"){r.push({type:"GT",pos:p});continue}if(o(y)){let h=y;for(;!n()&&(o(i())||i()==="."||i()==="e"||i()==="E");)(i()==="e"||i()==="E")&&(t[s+1]==="+"||t[s+1]==="-")&&(h+=e()),h+=e();r.push({type:"NUMBER",value:Number(h),pos:p});continue}if(y==='"'){let h="";for(;!n()&&i()!=='"';)if(i()==="\\"){if(e(),n())break;let l=e();switch(l){case"n":h+=`
5
+ `;break;case"r":h+="\r";break;case"t":h+=" ";break;case"\\":h+="\\";break;case'"':h+='"';break;case"(":h+="\\(";break;default:h+=l}}else h+=e();n()||e(),r.push({type:"STRING",value:h,pos:p});continue}if(f(y)||y==="$"||y==="@"){let h=y;for(;!n()&&c(i());)h+=e();let l=z[h];l?r.push({type:l,pos:p}):r.push({type:"IDENT",value:h,pos:p});continue}throw new Error(`Unexpected character '${y}' at position ${p}`)}}return r.push({type:"EOF",pos:s}),r}var P=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 s of r)if(this.check(s))return this.advance();return null}expect(r,s){if(!this.check(r))throw new Error(`${s} 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()}parsePipe(){let r=this.parseComma();for(;this.match("PIPE");){let s=this.parseComma();r={type:"Pipe",left:r,right:s}}return r}parseComma(){let r=this.parseVarBind();for(;this.match("COMMA");){let s=this.parseVarBind();r={type:"Comma",left:r,right:s}}return r}parseVarBind(){let r=this.parseUpdate();if(this.match("AS")){let s=this.expect("IDENT","Expected variable name after 'as'"),i=s.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${s.pos}`);this.expect("PIPE","Expected '|' after variable binding");let e=this.parseExpr();return{type:"VarBind",name:i,value:r,body:e}}return r}parseUpdate(){let r=this.parseAlt(),s={ASSIGN:"=",UPDATE_ADD:"+=",UPDATE_SUB:"-=",UPDATE_MUL:"*=",UPDATE_DIV:"/=",UPDATE_MOD:"%=",UPDATE_ALT:"//=",UPDATE_PIPE:"|="},i=this.match("ASSIGN","UPDATE_ADD","UPDATE_SUB","UPDATE_MUL","UPDATE_DIV","UPDATE_MOD","UPDATE_ALT","UPDATE_PIPE");if(i){let e=this.parseVarBind();return{type:"UpdateOp",op:s[i.type],path:r,value:e}}return r}parseAlt(){let r=this.parseOr();for(;this.match("ALT");){let s=this.parseOr();r={type:"BinaryOp",op:"//",left:r,right:s}}return r}parseOr(){let r=this.parseAnd();for(;this.match("OR");){let s=this.parseAnd();r={type:"BinaryOp",op:"or",left:r,right:s}}return r}parseAnd(){let r=this.parseNot();for(;this.match("AND");){let s=this.parseNot();r={type:"BinaryOp",op:"and",left:r,right:s}}return r}parseNot(){return this.parseComparison()}parseComparison(){let r=this.parseAddSub(),s={EQ:"==",NE:"!=",LT:"<",LE:"<=",GT:">",GE:">="},i=this.match("EQ","NE","LT","LE","GT","GE");if(i){let e=this.parseAddSub();r={type:"BinaryOp",op:s[i.type],left:r,right:e}}return r}parseAddSub(){let r=this.parseMulDiv();for(;;)if(this.match("PLUS")){let s=this.parseMulDiv();r={type:"BinaryOp",op:"+",left:r,right:s}}else if(this.match("MINUS")){let s=this.parseMulDiv();r={type:"BinaryOp",op:"-",left:r,right:s}}else break;return r}parseMulDiv(){let r=this.parseUnary();for(;;)if(this.match("STAR")){let s=this.parseUnary();r={type:"BinaryOp",op:"*",left:r,right:s}}else if(this.match("SLASH")){let s=this.parseUnary();r={type:"BinaryOp",op:"/",left:r,right:s}}else if(this.match("PERCENT")){let s=this.parseUnary();r={type:"BinaryOp",op:"%",left:r,right:s}}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.advance(),r={type:"Field",name:this.expect("IDENT","Expected field name").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 s=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",end:s,base:r}}else{let s=this.parseExpr();if(this.match("COLON")){let i=this.check("RBRACKET")?void 0:this.parseExpr();this.expect("RBRACKET","Expected ']'"),r={type:"Slice",start:s,end:i,base:r}}else this.expect("RBRACKET","Expected ']'"),r={type:"Index",index:s,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 s=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:s}}let r=this.parseExpr();if(this.match("COLON")){let s=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:r,end:s}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:r}}return this.check("IDENT")?{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 s=this.advance().value;return s.includes("\\(")?this.parseStringInterpolation(s):{type:"Literal",value:s}}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(),s;return this.match("CATCH")&&(s=this.parsePostfix()),{type:"Try",body:r,catch:s}}if(this.match("REDUCE")){let r=this.parsePostfix();this.expect("AS","Expected 'as' after reduce expression");let s=this.expect("IDENT","Expected variable name"),i=s.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${s.pos}`);this.expect("LPAREN","Expected '(' after variable");let e=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let n=this.parseExpr();return this.expect("RPAREN","Expected ')' after update expression"),{type:"Reduce",expr:r,varName:i,init:e,update:n}}if(this.match("FOREACH")){let r=this.parsePostfix();this.expect("AS","Expected 'as' after foreach expression");let s=this.expect("IDENT","Expected variable name"),i=s.value;if(!i.startsWith("$"))throw new Error(`Variable name must start with $ at position ${s.pos}`);this.expect("LPAREN","Expected '(' after variable");let e=this.parseExpr();this.expect("SEMICOLON","Expected ';' after init expression");let n=this.parseExpr(),o;return this.match("SEMICOLON")&&(o=this.parseExpr()),this.expect("RPAREN","Expected ')' after expressions"),{type:"Foreach",expr:r,varName:i,init:e,update:n,extract:o}}if(this.match("NOT"))return{type:"Call",name:"not",args:[]};if(this.check("IDENT")){let s=this.advance().value;if(s.startsWith("$"))return{type:"VarRef",name:s};if(this.match("LPAREN")){let i=[];if(!this.check("RPAREN"))for(i.push(this.parseExpr());this.match("SEMICOLON");)i.push(this.parseExpr());return this.expect("RPAREN","Expected ')'"),{type:"Call",name:s,args:i}}return{type:"Call",name:s,args:[]}}throw new Error(`Unexpected token ${this.peek().type} at position ${this.peek().pos}`)}parseObjectConstruction(){let r=[];if(!this.check("RBRACE"))do{let s,i;if(this.match("LPAREN"))s=this.parseExpr(),this.expect("RPAREN","Expected ')'"),this.expect("COLON","Expected ':'"),i=this.parseObjectValue();else if(this.check("IDENT")){let e=this.advance().value;this.match("COLON")?(s=e,i=this.parseObjectValue()):(s=e,i={type:"Field",name:e})}else if(this.check("STRING"))s=this.advance().value,this.expect("COLON","Expected ':'"),i=this.parseObjectValue();else throw new Error(`Expected object key at position ${this.peek().pos}`);r.push({key:s,value:i})}while(this.match("COMMA"));return this.expect("RBRACE","Expected '}'"),{type:"Object",entries:r}}parseObjectValue(){let r=this.parseVarBind();for(;this.match("PIPE");){let s=this.parseVarBind();r={type:"Pipe",left:r,right:s}}return r}parseIf(){let r=this.parseExpr();this.expect("THEN","Expected 'then'");let s=this.parseExpr(),i=[];for(;this.match("ELIF");){let n=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let o=this.parseExpr();i.push({cond:n,then:o})}let e;return this.match("ELSE")&&(e=this.parseExpr()),this.expect("END","Expected 'end'"),{type:"Cond",cond:r,then:s,elifs:i,else:e}}parseStringInterpolation(r){let s=[],i="",e=0;for(;e<r.length;)if(r[e]==="\\"&&r[e+1]==="("){i&&(s.push(i),i=""),e+=2;let n=1,o="";for(;e<r.length&&n>0;)r[e]==="("?n++:r[e]===")"&&n--,n>0&&(o+=r[e]),e++;let f=_(o),c=new t(f);s.push(c.parse())}else i+=r[e],e++;return i&&s.push(i),{type:"StringInterp",parts:s}}};function $(t){let r=_(t);return new P(r).parse()}var Y={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 S(t,r,s,i,e,n=0){if(t===null||t===void 0)return"null";if(typeof t=="boolean")return String(t);if(typeof t=="number")return Number.isFinite(t)?String(t):"null";if(typeof t=="string")return s?t:JSON.stringify(t);let o=e?" ":" ";if(Array.isArray(t))return t.length===0?"[]":r?`[${t.map(c=>S(c,!0,!1,i,e)).join(",")}]`:`[
6
+ ${t.map(c=>o.repeat(n+1)+S(c,!1,!1,i,e,n+1)).join(`,
7
+ `)}
8
+ ${o.repeat(n)}]`;if(typeof t=="object"){let f=Object.keys(t);return i&&(f=f.sort()),f.length===0?"{}":r?`{${f.map(p=>`${JSON.stringify(p)}:${S(t[p],!0,!1,i,e)}`).join(",")}}`:`{
9
+ ${f.map(p=>{let y=S(t[p],!1,!1,i,e,n+1);return`${o.repeat(n+1)}${JSON.stringify(p)}: ${y}`}).join(`,
10
+ `)}
11
+ ${o.repeat(n)}}`}return String(t)}var st={name:"jq",async execute(t,r){if(M(t))return L(Y);let s=!1,i=!1,e=!1,n=!1,o=!1,f=!1,c=!1,p=!1,y=".",h=!1,l=[];for(let m=0;m<t.length;m++){let a=t[m];if(a==="-r"||a==="--raw-output")s=!0;else if(a==="-c"||a==="--compact-output")i=!0;else if(a==="-e"||a==="--exit-status")e=!0;else if(a==="-s"||a==="--slurp")n=!0;else if(a==="-n"||a==="--null-input")o=!0;else if(a==="-j"||a==="--join-output")f=!0;else if(!(a==="-a"||a==="--ascii")){if(a==="-S"||a==="--sort-keys")c=!0;else if(!(a==="-C"||a==="--color")){if(!(a==="-M"||a==="--monochrome"))if(a==="--tab")p=!0;else if(a==="-")l.push("-");else{if(a.startsWith("--"))return T("jq",a);if(a.startsWith("-")){for(let d of a.slice(1))if(d==="r")s=!0;else if(d==="c")i=!0;else if(d==="e")e=!0;else if(d==="s")n=!0;else if(d==="n")o=!0;else if(d==="j")f=!0;else if(d!=="a"){if(d==="S")c=!0;else if(d!=="C"){if(d!=="M")return T("jq",`-${d}`)}}}else h?l.push(a):(y=a,h=!0)}}}}let A;if(o)A="";else if(l.length===0||l.length===1&&l[0]==="-")A=r.stdin;else try{let m=r.fs.resolvePath(r.cwd,l[0]);A=await r.fs.readFile(m)}catch{return{stdout:"",stderr:`jq: ${l[0]}: No such file or directory
12
+ `,exitCode:2}}try{let m=$(y),a,d={limits:r.limits?{maxIterations:r.limits.maxJqIterations}:void 0};if(o)a=u(null,m,d);else if(n){let E=[];for(let k of A.trim().split(`
13
+ `))k.trim()&&E.push(JSON.parse(k));a=u(E,m,d)}else{let E=A.trim();if(E.startsWith("{")||E.startsWith("["))a=u(JSON.parse(E),m,d);else{a=[];for(let k of E.split(`
14
+ `))k.trim()&&a.push(...u(JSON.parse(k),m,d))}}let F=a.map(E=>S(E,i,s,c,p)),J=f?"":`
15
+ `,R=F.join(J),q=e&&(a.length===0||a.every(E=>E==null||E===!1))?1:0;return{stdout:R?f?R:`${R}
16
+ `:"",stderr:"",exitCode:q}}catch(m){if(m instanceof g)return{stdout:"",stderr:`jq: ${m.message}
17
+ `,exitCode:g.EXIT_CODE};let a=m.message;return a.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${a}
18
+ `,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${a}
19
+ `,exitCode:5}}}};export{st as jqCommand};