just-bash 2.12.2 → 2.12.4
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/awk2-RGDNV4HO.js +2 -0
- package/dist/bin/chunks/{base64-YXBFJFHG.js → base64-43M2R3GA.js} +1 -1
- package/dist/bin/{shell/chunks/cat-3J7U3HHI.js → chunks/cat-XZIJZXKP.js} +1 -1
- package/dist/bin/chunks/chunk-4C4F4EKM.js +2 -0
- package/dist/bin/{shell/chunks/chunk-MZKPWGID.js → chunks/chunk-54G6AE72.js} +23 -23
- package/dist/bin/chunks/chunk-55QIFSKH.js +36 -0
- package/dist/bin/chunks/chunk-6MF2IYQX.js +10 -0
- package/dist/bin/{shell/chunks/chunk-NEQEZ32M.js → chunks/chunk-CGE2EHYP.js} +3 -3
- package/dist/bin/chunks/chunk-DGFDVZ4N.js +21 -0
- package/dist/bin/chunks/chunk-EO5AH4U7.js +5 -0
- package/dist/bin/chunks/{chunk-2SIXTZCJ.js → chunk-EZS766DD.js} +4 -4
- package/dist/bin/{shell/chunks/chunk-THLAHQXV.js → chunks/chunk-FA2CHD73.js} +1 -1
- package/dist/bin/chunks/{chunk-BARKRZDC.js → chunk-GOJZHH3L.js} +1 -1
- package/dist/bin/chunks/{chunk-435ZOZCY.js → chunk-J4WYAO5Q.js} +1 -1
- package/dist/bin/chunks/chunk-LHN3LRVT.js +100 -0
- package/dist/bin/chunks/chunk-MRP4ZCD7.js +6 -0
- package/dist/bin/chunks/{chunk-JNPUO56K.js → chunk-NDP6L74Z.js} +1 -1
- package/dist/bin/chunks/chunk-PWZZGTFL.js +13 -0
- package/dist/bin/chunks/{chunk-3NVWSLHI.js → chunk-Q3FNZYGG.js} +99 -99
- package/dist/bin/{shell/chunks/chunk-7SWOLTCR.js → chunks/chunk-Q4WHWGOT.js} +1 -1
- package/dist/bin/chunks/chunk-SY2WM5RM.js +14 -0
- package/dist/bin/chunks/chunk-SYG3IW7P.js +2 -0
- package/dist/bin/chunks/chunk-SYL34GE7.js +21 -0
- package/dist/bin/chunks/{chunk-DREQRXNN.js → chunk-V5YFCVCZ.js} +1 -1
- package/dist/bin/chunks/chunk-V7VIJQD6.js +6 -0
- package/dist/bin/chunks/chunk-WMYKQURM.js +2 -0
- package/dist/bin/chunks/chunk-WO4B7WUT.js +2 -0
- package/dist/bin/{shell/chunks/chunk-5U7Q4GUC.js → chunks/chunk-WWZVR5NN.js} +4 -4
- package/dist/bin/chunks/{cut-HDHQDWRG.js → cut-5EY2XPXX.js} +1 -1
- package/dist/bin/chunks/expr-VEFRBJT4.js +2 -0
- package/dist/bin/chunks/flag-coverage-K6IBGWAC.js +2 -0
- package/dist/bin/chunks/{gzip-RQ5RIFJV.js → gzip-LHOO65AN.js} +1 -1
- package/dist/bin/chunks/jq-VBB2XIZS.js +2 -0
- package/dist/bin/chunks/ln-BEOFQJNP.js +2 -0
- package/dist/bin/chunks/python3-JX5PXXTX.js +17 -0
- package/dist/bin/chunks/sed-BYFYBR4A.js +2 -0
- package/dist/bin/chunks/sleep-E3K6M6BN.js +2 -0
- package/dist/bin/chunks/{sort-NZSEYCI6.js → sort-7GENYU2I.js} +1 -1
- package/dist/bin/chunks/sqlite3-SJHZFBT2.js +2 -0
- package/dist/bin/{shell/chunks/tar-VIYVHMER.js → chunks/tar-W5GBTEDZ.js} +1 -1
- package/dist/bin/chunks/time-AWAKKRSE.js +2 -0
- package/dist/bin/chunks/timeout-OLS72AZG.js +2 -0
- package/dist/bin/chunks/tr-LZF57GYP.js +2 -0
- package/dist/bin/chunks/{uniq-FZWFZEN5.js → uniq-TMSAIZM3.js} +1 -1
- package/dist/bin/chunks/worker.js +92 -29
- package/dist/bin/chunks/xan-BJ66NSYT.js +2 -0
- package/dist/bin/chunks/yq-GPYVGU2N.js +2 -0
- package/dist/bin/just-bash.js +294 -294
- package/dist/bin/shell/chunks/awk2-RGDNV4HO.js +2 -0
- package/dist/bin/shell/chunks/{base64-YXBFJFHG.js → base64-43M2R3GA.js} +1 -1
- package/dist/bin/{chunks/cat-3J7U3HHI.js → shell/chunks/cat-XZIJZXKP.js} +1 -1
- package/dist/bin/shell/chunks/chunk-4C4F4EKM.js +2 -0
- package/dist/bin/{chunks/chunk-MZKPWGID.js → shell/chunks/chunk-54G6AE72.js} +23 -23
- package/dist/bin/shell/chunks/chunk-55QIFSKH.js +36 -0
- package/dist/bin/shell/chunks/chunk-6MF2IYQX.js +10 -0
- package/dist/bin/{chunks/chunk-NEQEZ32M.js → shell/chunks/chunk-CGE2EHYP.js} +3 -3
- package/dist/bin/shell/chunks/chunk-DGFDVZ4N.js +21 -0
- package/dist/bin/shell/chunks/chunk-EO5AH4U7.js +5 -0
- package/dist/bin/shell/chunks/{chunk-2SIXTZCJ.js → chunk-EZS766DD.js} +4 -4
- package/dist/bin/{chunks/chunk-THLAHQXV.js → shell/chunks/chunk-FA2CHD73.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-BARKRZDC.js → chunk-GOJZHH3L.js} +1 -1
- package/dist/bin/shell/chunks/{chunk-435ZOZCY.js → chunk-J4WYAO5Q.js} +1 -1
- package/dist/bin/shell/chunks/chunk-LHN3LRVT.js +100 -0
- package/dist/bin/shell/chunks/chunk-MRP4ZCD7.js +6 -0
- package/dist/bin/shell/chunks/{chunk-JNPUO56K.js → chunk-NDP6L74Z.js} +1 -1
- package/dist/bin/shell/chunks/chunk-PWZZGTFL.js +13 -0
- package/dist/bin/shell/chunks/{chunk-3NVWSLHI.js → chunk-Q3FNZYGG.js} +99 -99
- package/dist/bin/{chunks/chunk-7SWOLTCR.js → shell/chunks/chunk-Q4WHWGOT.js} +1 -1
- package/dist/bin/shell/chunks/chunk-SY2WM5RM.js +14 -0
- package/dist/bin/shell/chunks/chunk-SYG3IW7P.js +2 -0
- package/dist/bin/shell/chunks/chunk-SYL34GE7.js +21 -0
- package/dist/bin/shell/chunks/{chunk-DREQRXNN.js → chunk-V5YFCVCZ.js} +1 -1
- package/dist/bin/shell/chunks/chunk-V7VIJQD6.js +6 -0
- package/dist/bin/shell/chunks/chunk-WMYKQURM.js +2 -0
- package/dist/bin/shell/chunks/chunk-WO4B7WUT.js +2 -0
- package/dist/bin/{chunks/chunk-5U7Q4GUC.js → shell/chunks/chunk-WWZVR5NN.js} +4 -4
- package/dist/bin/shell/chunks/{cut-HDHQDWRG.js → cut-5EY2XPXX.js} +1 -1
- package/dist/bin/shell/chunks/expr-VEFRBJT4.js +2 -0
- package/dist/bin/shell/chunks/flag-coverage-K6IBGWAC.js +2 -0
- package/dist/bin/shell/chunks/{gzip-RQ5RIFJV.js → gzip-LHOO65AN.js} +1 -1
- package/dist/bin/shell/chunks/jq-VBB2XIZS.js +2 -0
- package/dist/bin/shell/chunks/ln-BEOFQJNP.js +2 -0
- package/dist/bin/shell/chunks/python3-JX5PXXTX.js +17 -0
- package/dist/bin/shell/chunks/sed-BYFYBR4A.js +2 -0
- package/dist/bin/shell/chunks/sleep-E3K6M6BN.js +2 -0
- package/dist/bin/shell/chunks/{sort-NZSEYCI6.js → sort-7GENYU2I.js} +1 -1
- package/dist/bin/shell/chunks/sqlite3-SJHZFBT2.js +2 -0
- package/dist/bin/{chunks/tar-VIYVHMER.js → shell/chunks/tar-W5GBTEDZ.js} +1 -1
- package/dist/bin/shell/chunks/time-AWAKKRSE.js +2 -0
- package/dist/bin/shell/chunks/timeout-OLS72AZG.js +2 -0
- package/dist/bin/shell/chunks/tr-LZF57GYP.js +2 -0
- package/dist/bin/shell/chunks/{uniq-FZWFZEN5.js → uniq-TMSAIZM3.js} +1 -1
- package/dist/bin/shell/chunks/xan-BJ66NSYT.js +2 -0
- package/dist/bin/shell/chunks/yq-GPYVGU2N.js +2 -0
- package/dist/bin/shell/shell.js +234 -234
- package/dist/bundle/browser.js +671 -671
- package/dist/bundle/chunks/awk2-XLDR2J4Q.js +1 -0
- package/dist/bundle/chunks/{base64-A3SGWC34.js → base64-4YMZCVJ5.js} +1 -1
- package/dist/bundle/chunks/{cat-C2OBLGHA.js → cat-RDUMLXKC.js} +1 -1
- package/dist/bundle/chunks/chunk-2OHMPZNZ.js +20 -0
- package/dist/bundle/chunks/chunk-3RCXHB4E.js +4 -0
- package/dist/bundle/chunks/chunk-CCNMISUL.js +1 -0
- package/dist/bundle/chunks/chunk-DOTBQEPN.js +5 -0
- package/dist/bundle/chunks/chunk-GENDESYN.js +1 -0
- package/dist/bundle/chunks/chunk-H4QOE4W3.js +99 -0
- package/dist/bundle/chunks/{chunk-C6ZZC5FL.js → chunk-K5BTXJQC.js} +99 -99
- package/dist/bundle/chunks/chunk-KAZYKNBG.js +13 -0
- package/dist/bundle/chunks/{chunk-KAEMRWOH.js → chunk-KMEYNNUA.js} +1 -1
- package/dist/bundle/chunks/{chunk-FO655G4V.js → chunk-LTZRCH7N.js} +23 -23
- package/dist/bundle/chunks/{chunk-XULIVM35.js → chunk-N4QLRJ32.js} +1 -1
- package/dist/bundle/chunks/{chunk-5CJQNRNJ.js → chunk-NTP6TTH5.js} +1 -1
- package/dist/bundle/chunks/{chunk-IBFD7QQD.js → chunk-QJ7O6ZN3.js} +1 -1
- package/dist/bundle/chunks/chunk-QUME7R6S.js +9 -0
- package/dist/bundle/chunks/{chunk-U7QI5ZS5.js → chunk-RVT3MU3A.js} +4 -4
- package/dist/bundle/chunks/{chunk-6NY2AP72.js → chunk-SDNKECQQ.js} +4 -4
- package/dist/bundle/chunks/chunk-T2EHE3CV.js +1 -0
- package/dist/bundle/chunks/chunk-TBAWQWQB.js +12 -0
- package/dist/bundle/chunks/chunk-TXBZCHCQ.js +5 -0
- package/dist/bundle/chunks/chunk-VYV3YE2F.js +35 -0
- package/dist/bundle/chunks/{chunk-UJIR5V54.js → chunk-W42IGK5R.js} +1 -1
- package/dist/bundle/chunks/{chunk-7BQDVPII.js → chunk-WAN3B6E3.js} +1 -1
- package/dist/bundle/chunks/{chunk-7C6RBHP3.js → chunk-WKFATFPP.js} +3 -3
- package/dist/bundle/chunks/chunk-XXZ46GOX.js +20 -0
- package/dist/bundle/chunks/chunk-ZK6J6F7O.js +1 -0
- package/dist/bundle/chunks/{cut-LO6YYY5P.js → cut-OPC3VAGB.js} +1 -1
- package/dist/bundle/chunks/expr-74QHYJL5.js +1 -0
- package/dist/bundle/chunks/flag-coverage-VGF5NAZP.js +1 -0
- package/dist/bundle/chunks/{gzip-Y4N2UKE7.js → gzip-AQXSGOVS.js} +1 -1
- package/dist/bundle/chunks/jq-JQXAVWNT.js +1 -0
- package/dist/bundle/chunks/ln-RI2SJGXU.js +1 -0
- package/dist/bundle/chunks/python3-TSPOVUHX.js +16 -0
- package/dist/bundle/chunks/sed-CJFW7UYO.js +1 -0
- package/dist/bundle/chunks/sleep-TFDNFOXK.js +1 -0
- package/dist/bundle/chunks/{sort-T7TNLWXL.js → sort-DCNRDA7U.js} +1 -1
- package/dist/bundle/chunks/sqlite3-CTI4ZW7L.js +1 -0
- package/dist/bundle/chunks/{tar-E2DVQEWO.js → tar-Y6LP5EBC.js} +1 -1
- package/dist/bundle/chunks/time-WBKSMCJ6.js +1 -0
- package/dist/bundle/chunks/timeout-O7WSXY5H.js +1 -0
- package/dist/bundle/chunks/tr-GVTWMRZB.js +1 -0
- package/dist/bundle/chunks/{uniq-ZXE4O5XB.js → uniq-SUNANL47.js} +1 -1
- package/dist/bundle/chunks/worker.js +92 -29
- package/dist/bundle/chunks/xan-VMLUNIDS.js +1 -0
- package/dist/bundle/chunks/yq-QXIYE3MW.js +1 -0
- package/dist/bundle/index.cjs +852 -852
- package/dist/bundle/index.js +242 -242
- package/dist/commands/awk/interpreter/context.d.ts +2 -0
- package/dist/commands/awk/interpreter/interpreter.d.ts +2 -0
- package/dist/commands/query-engine/evaluator.d.ts +3 -0
- package/dist/interpreter/defense-aware-command-context.d.ts +6 -0
- package/dist/interpreter/interpreter.d.ts +8 -0
- package/dist/interpreter/types.d.ts +5 -0
- package/dist/timers.d.ts +2 -11
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
- package/dist/bin/chunks/awk2-ZE5HJBNV.js +0 -2
- package/dist/bin/chunks/chunk-2FFXXW3F.js +0 -14
- package/dist/bin/chunks/chunk-4E3LY6YK.js +0 -10
- package/dist/bin/chunks/chunk-4FNW6LFM.js +0 -5
- package/dist/bin/chunks/chunk-4PZYIYYG.js +0 -36
- package/dist/bin/chunks/chunk-6L4K3UGO.js +0 -100
- package/dist/bin/chunks/chunk-EPIOK4SY.js +0 -6
- package/dist/bin/chunks/chunk-IYZRLSTQ.js +0 -2
- package/dist/bin/chunks/chunk-JJHAWOIB.js +0 -2
- package/dist/bin/chunks/chunk-K47SEEPI.js +0 -6
- package/dist/bin/chunks/chunk-KPWFKFSD.js +0 -21
- package/dist/bin/chunks/chunk-RYXW3SZQ.js +0 -13
- package/dist/bin/chunks/chunk-VZKEP45B.js +0 -21
- package/dist/bin/chunks/expr-MLHUWFYI.js +0 -2
- package/dist/bin/chunks/flag-coverage-LQ37DA4R.js +0 -2
- package/dist/bin/chunks/jq-CXSPO2J5.js +0 -2
- package/dist/bin/chunks/ln-5TCJXDGY.js +0 -2
- package/dist/bin/chunks/python3-74B25WCY.js +0 -17
- package/dist/bin/chunks/sed-DNLJZZXZ.js +0 -2
- package/dist/bin/chunks/sleep-GUJH2AMQ.js +0 -2
- package/dist/bin/chunks/sqlite3-57UI7HYL.js +0 -2
- package/dist/bin/chunks/time-FAWHHOMA.js +0 -2
- package/dist/bin/chunks/timeout-4O4YYRTS.js +0 -2
- package/dist/bin/chunks/tr-4V5A3V2C.js +0 -2
- package/dist/bin/chunks/xan-7NIVZ3HP.js +0 -2
- package/dist/bin/chunks/yq-L5ZSGLLO.js +0 -2
- package/dist/bin/shell/chunks/awk2-ZE5HJBNV.js +0 -2
- package/dist/bin/shell/chunks/chunk-2FFXXW3F.js +0 -14
- package/dist/bin/shell/chunks/chunk-4E3LY6YK.js +0 -10
- package/dist/bin/shell/chunks/chunk-4FNW6LFM.js +0 -5
- package/dist/bin/shell/chunks/chunk-4PZYIYYG.js +0 -36
- package/dist/bin/shell/chunks/chunk-6L4K3UGO.js +0 -100
- package/dist/bin/shell/chunks/chunk-EPIOK4SY.js +0 -6
- package/dist/bin/shell/chunks/chunk-IYZRLSTQ.js +0 -2
- package/dist/bin/shell/chunks/chunk-JJHAWOIB.js +0 -2
- package/dist/bin/shell/chunks/chunk-K47SEEPI.js +0 -6
- package/dist/bin/shell/chunks/chunk-KPWFKFSD.js +0 -21
- package/dist/bin/shell/chunks/chunk-RYXW3SZQ.js +0 -13
- package/dist/bin/shell/chunks/chunk-VZKEP45B.js +0 -21
- package/dist/bin/shell/chunks/expr-MLHUWFYI.js +0 -2
- package/dist/bin/shell/chunks/flag-coverage-LQ37DA4R.js +0 -2
- package/dist/bin/shell/chunks/jq-CXSPO2J5.js +0 -2
- package/dist/bin/shell/chunks/ln-5TCJXDGY.js +0 -2
- package/dist/bin/shell/chunks/python3-74B25WCY.js +0 -17
- package/dist/bin/shell/chunks/sed-DNLJZZXZ.js +0 -2
- package/dist/bin/shell/chunks/sleep-GUJH2AMQ.js +0 -2
- package/dist/bin/shell/chunks/sqlite3-57UI7HYL.js +0 -2
- package/dist/bin/shell/chunks/time-FAWHHOMA.js +0 -2
- package/dist/bin/shell/chunks/timeout-4O4YYRTS.js +0 -2
- package/dist/bin/shell/chunks/tr-4V5A3V2C.js +0 -2
- package/dist/bin/shell/chunks/xan-7NIVZ3HP.js +0 -2
- package/dist/bin/shell/chunks/yq-L5ZSGLLO.js +0 -2
- package/dist/bundle/chunks/awk2-T6LHPVZE.js +0 -1
- package/dist/bundle/chunks/chunk-5BFLZVGH.js +0 -20
- package/dist/bundle/chunks/chunk-7DBA735O.js +0 -5
- package/dist/bundle/chunks/chunk-7KHLIOOW.js +0 -4
- package/dist/bundle/chunks/chunk-AOFQVUAD.js +0 -99
- package/dist/bundle/chunks/chunk-BAAVD5NO.js +0 -20
- package/dist/bundle/chunks/chunk-BEFDX7IY.js +0 -1
- package/dist/bundle/chunks/chunk-KPFCTJEX.js +0 -12
- package/dist/bundle/chunks/chunk-LN5KAJOV.js +0 -5
- package/dist/bundle/chunks/chunk-NBAARP4B.js +0 -1
- package/dist/bundle/chunks/chunk-RHOPHAL6.js +0 -35
- package/dist/bundle/chunks/chunk-SL4FN3A5.js +0 -9
- package/dist/bundle/chunks/chunk-YIY2RKBW.js +0 -13
- package/dist/bundle/chunks/expr-3572LAOT.js +0 -1
- package/dist/bundle/chunks/flag-coverage-MPLWXQQK.js +0 -1
- package/dist/bundle/chunks/jq-MYSLFARY.js +0 -1
- package/dist/bundle/chunks/ln-YAIFIHCT.js +0 -1
- package/dist/bundle/chunks/python3-6BKA3FYA.js +0 -16
- package/dist/bundle/chunks/sed-3ZCNFRHI.js +0 -1
- package/dist/bundle/chunks/sleep-LB7FI6AB.js +0 -1
- package/dist/bundle/chunks/sqlite3-FVNA4KNF.js +0 -1
- package/dist/bundle/chunks/time-AGNW2ZY6.js +0 -1
- package/dist/bundle/chunks/timeout-VN35D5O7.js +0 -1
- package/dist/bundle/chunks/tr-2N7Q3KKJ.js +0 -1
- package/dist/bundle/chunks/xan-VTO4FP3H.js +0 -1
- package/dist/bundle/chunks/yq-JRZFRYSK.js +0 -1
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as m,b as h}from"./chunk-GTNBSMZR.js";var g={name:"ln",summary:"make links between files",usage:"ln [OPTIONS] TARGET LINK_NAME",options:["-s create a symbolic link instead of a hard link","-f remove existing destination files","-n treat LINK_NAME as a normal file if it is a symbolic link to a directory","-v print name of each linked file"," --help display this help and exit"]},p={name:"ln",async execute(n,s){if(h(n))return m(g);let l=!1,a=!1,f=!1,t=0;for(;t<n.length&&n[t].startsWith("-");){let e=n[t];if(e==="-s"||e==="--symbolic")l=!0,t++;else if(e==="-f"||e==="--force")a=!0,t++;else if(e==="-v"||e==="--verbose")f=!0,t++;else if(e==="-n"||e==="--no-dereference")t++;else if(/^-[sfvn]+$/.test(e))e.includes("s")&&(l=!0),e.includes("f")&&(a=!0),e.includes("v")&&(f=!0),t++;else if(e==="--"){t++;break}else return{stdout:"",stderr:`ln: invalid option -- '${e.slice(1)}'
|
|
3
|
-
`,exitCode:1}}let d=n.slice(t);if(d.length<2)return{stdout:"",stderr:`ln: missing file operand
|
|
4
|
-
`,exitCode:1};let i=d[0],r=d[1],o=s.fs.resolvePath(s.cwd,r);if(await s.fs.exists(o))if(a)try{await s.fs.rm(o,{force:!0})}catch{return{stdout:"",stderr:`ln: cannot remove '${r}': Permission denied
|
|
5
|
-
`,exitCode:1}}else return{stdout:"",stderr:`ln: failed to create ${l?"symbolic ":""}link '${r}': File exists
|
|
6
|
-
`,exitCode:1};try{if(l)await s.fs.symlink(i,o);else{let e=s.fs.resolvePath(s.cwd,i);if(!await s.fs.exists(e))return{stdout:"",stderr:`ln: failed to access '${i}': No such file or directory
|
|
7
|
-
`,exitCode:1};await s.fs.link(e,o)}}catch(e){let u=e;return u.message.includes("EPERM")?{stdout:"",stderr:`ln: '${i}': hard link not allowed for directory
|
|
8
|
-
`,exitCode:1}:{stdout:"",stderr:`ln: ${u.message}
|
|
9
|
-
`,exitCode:1}}let c="";return f&&(c=`'${r}' -> '${i}'
|
|
10
|
-
`),{stdout:c,stderr:"",exitCode:0}}},b={name:"ln",flags:[{flag:"-s",type:"boolean"},{flag:"-f",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-v",type:"boolean"}],needsArgs:!0,minArgs:2};export{p as a,b};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as g}from"./chunk-KGOUQS5A.js";function m(){let c=[{prop:"Function",target:globalThis,violationType:"function_constructor",strategy:"throw",reason:"Function constructor allows arbitrary code execution"},{prop:"eval",target:globalThis,violationType:"eval",strategy:"throw",reason:"eval() allows arbitrary code execution"},{prop:"setTimeout",target:globalThis,violationType:"setTimeout",strategy:"throw",reason:"setTimeout with string argument allows code execution"},{prop:"setInterval",target:globalThis,violationType:"setInterval",strategy:"throw",reason:"setInterval with string argument allows code execution"},{prop:"setImmediate",target:globalThis,violationType:"setImmediate",strategy:"throw",reason:"setImmediate could be used to escape sandbox context"},{prop:"env",target:process,violationType:"process_env",strategy:"throw",reason:"process.env could leak sensitive environment variables",allowedKeys:new Set(["NODE_V8_COVERAGE","NODE_DEBUG","NODE_DEBUG_NATIVE","NODE_COMPILE_CACHE","WATCH_REPORT_DEPENDENCIES","FORCE_COLOR","DEBUG","UNDICI_NO_FG","JEST_WORKER_ID","__MINIMATCH_TESTING_PLATFORM__","LOG_TOKENS","LOG_STREAM"])},{prop:"binding",target:process,violationType:"process_binding",strategy:"throw",reason:"process.binding provides access to native Node.js modules"},{prop:"_linkedBinding",target:process,violationType:"process_binding",strategy:"throw",reason:"process._linkedBinding provides access to native Node.js modules"},{prop:"dlopen",target:process,violationType:"process_dlopen",strategy:"throw",reason:"process.dlopen allows loading native addons"},{prop:"getBuiltinModule",target:process,violationType:"process_get_builtin_module",strategy:"throw",reason:"process.getBuiltinModule allows loading native Node.js modules (fs, child_process, vm)"},{prop:"exit",target:process,violationType:"process_exit",strategy:"throw",reason:"process.exit could terminate the interpreter"},{prop:"abort",target:process,violationType:"process_exit",strategy:"throw",reason:"process.abort could crash the interpreter"},{prop:"kill",target:process,violationType:"process_kill",strategy:"throw",reason:"process.kill could signal other processes"},{prop:"setuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setuid could escalate privileges"},{prop:"setgid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgid could escalate privileges"},{prop:"umask",target:process,violationType:"process_umask",strategy:"throw",reason:"process.umask could modify file creation permissions"},{prop:"argv",target:process,violationType:"process_argv",strategy:"throw",reason:"process.argv may contain secrets in CLI arguments"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"send",target:process,violationType:"process_send",strategy:"throw",reason:"process.send could communicate with parent process in IPC contexts"},{prop:"channel",target:process,violationType:"process_channel",strategy:"throw",reason:"process.channel could access IPC channel to parent process"},{prop:"cpuUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.cpuUsage could enable timing side-channel attacks"},{prop:"memoryUsage",target:process,violationType:"process_timing",strategy:"throw",reason:"process.memoryUsage could enable timing side-channel attacks"},{prop:"hrtime",target:process,violationType:"process_timing",strategy:"throw",reason:"process.hrtime could enable timing side-channel attacks"},{prop:"WeakRef",target:globalThis,violationType:"weak_ref",strategy:"throw",reason:"WeakRef could be used to leak references outside sandbox"},{prop:"FinalizationRegistry",target:globalThis,violationType:"finalization_registry",strategy:"throw",reason:"FinalizationRegistry could be used to leak references outside sandbox"},{prop:"Reflect",target:globalThis,violationType:"reflect",strategy:"freeze",reason:"Reflect provides introspection capabilities"},{prop:"Proxy",target:globalThis,violationType:"proxy",strategy:"throw",reason:"Proxy allows intercepting and modifying object behavior"},{prop:"WebAssembly",target:globalThis,violationType:"webassembly",strategy:"throw",reason:"WebAssembly allows executing arbitrary compiled code"},{prop:"SharedArrayBuffer",target:globalThis,violationType:"shared_array_buffer",strategy:"throw",reason:"SharedArrayBuffer could enable side-channel communication or timing attacks"},{prop:"Atomics",target:globalThis,violationType:"atomics",strategy:"throw",reason:"Atomics could enable side-channel communication or timing attacks"},{prop:"performance",target:globalThis,violationType:"performance_timing",strategy:"throw",reason:"performance.now() provides sub-millisecond timing for side-channel attacks"},{prop:"stdout",target:process,violationType:"process_stdout",strategy:"throw",reason:"process.stdout could bypass interpreter output to write to host stdout"},{prop:"stderr",target:process,violationType:"process_stderr",strategy:"throw",reason:"process.stderr could bypass interpreter output to write to host stderr"},{prop:"__defineGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineGetter__ allows prototype pollution via getter injection"},{prop:"__defineSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__defineSetter__ allows prototype pollution via setter injection"},{prop:"__lookupGetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupGetter__ enables introspection for prototype pollution attacks"},{prop:"__lookupSetter__",target:Object.prototype,violationType:"prototype_mutation",strategy:"throw",reason:"__lookupSetter__ enables introspection for prototype pollution attacks"},{prop:"JSON",target:globalThis,violationType:"json_mutation",strategy:"freeze",reason:"Freeze JSON to prevent mutation of parsing/serialization"},{prop:"Math",target:globalThis,violationType:"math_mutation",strategy:"freeze",reason:"Freeze Math to prevent mutation of math utilities"}];try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(async()=>{}),violationType:"async_function_constructor",strategy:"throw",reason:"AsyncFunction constructor allows arbitrary async code execution"})}catch{}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&c.push({prop:"constructor",target:Object.getPrototypeOf(function*(){}),violationType:"generator_function_constructor",strategy:"throw",reason:"GeneratorFunction constructor allows arbitrary generator code execution"})}catch{}try{let e=Object.getPrototypeOf(async function*(){}).constructor;e&&e!==Function&&e!==Object.getPrototypeOf(async()=>{}).constructor&&c.push({prop:"constructor",target:Object.getPrototypeOf(async function*(){}),violationType:"async_generator_function_constructor",strategy:"throw",reason:"AsyncGeneratorFunction constructor allows arbitrary async generator code execution"})}catch{}return c.filter(e=>{try{return e.target[e.prop]!==void 0}catch{return!1}})}var h=typeof __BROWSER__<"u"&&__BROWSER__;function _(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,c=>{let e=Math.random()*16|0;return(c==="x"?e:e&3|8).toString(16)})}var b=null;if(!h)try{let{AsyncLocalStorage:c}=g("node:async_hooks");b=c}catch{}var w=`
|
|
3
|
-
|
|
4
|
-
This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,p=class extends Error{violation;constructor(e,t){super(e+w),this.violation=t,this.name="SecurityViolationError"}},l=!h&&b?new b:null,T=1e3,y={enabled:!0,auditMode:!1};function k(c){return c===void 0?{...y,enabled:!1}:typeof c=="boolean"?{...y,enabled:c}:{...y,...c}}var x=class c{static instance=null;static importHooksRegistered=!1;config;refCount=0;patchFailures=[];originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(e){this.config=e}static getInstance(e){let t=k(e);if(!c.instance)c.instance=new c(t);else{let r=c.instance.config;if(t.enabled!==r.enabled||t.auditMode!==r.auditMode)throw new Error(`DefenseInDepthBox config conflict: requested {enabled: ${t.enabled}, auditMode: ${t.auditMode}} but singleton already has {enabled: ${r.enabled}, auditMode: ${r.auditMode}}. All Bash instances must use the same defense-in-depth security settings, or call DefenseInDepthBox.resetInstance() between incompatible configurations.`)}return c.instance}static resetInstance(){c.instance&&(c.instance.forceDeactivate(),c.instance=null)}static isInSandboxedContext(){return l?l?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(l)return l?.getStore()?.executionId}isEnabled(){return this.config.enabled===!0&&l!==null&&!h}updateConfig(e){this.config={...this.config,...e}}activate(){if(h||!this.config.enabled||!l){let t=_();return{run:r=>r(),deactivate:()=>{},executionId:t}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let e=_();return{run:t=>l.run({sandboxActive:!0,executionId:e},t),deactivate:()=>{this.refCount--,this.refCount===0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount<0&&(this.refCount=0)},executionId:e}}forceDeactivate(){this.refCount>0&&(this.restorePatches(),this.totalActiveTimeMs+=Date.now()-this.activationTime),this.refCount=0}isActive(){return this.refCount>0}getStats(){return{violationsBlocked:this.violations.length,violations:[...this.violations],activeTimeMs:this.totalActiveTimeMs+(this.refCount>0?Date.now()-this.activationTime:0),refCount:this.refCount}}getPatchFailures(){return[...this.patchFailures]}clearViolations(){this.violations=[]}getPathForTarget(e,t){return e===globalThis?`globalThis.${t}`:e===process?`process.${t}`:e===Error?`Error.${t}`:e===Function.prototype?`Function.prototype.${t}`:e===Object.prototype?`Object.prototype.${t}`:`<object>.${t}`}static runTrusted(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}static async runTrustedAsync(e){if(!l)return e();let t=l.getStore();return t?l.run({...t,trusted:!0},e):e()}shouldBlock(){if(h||this.config.auditMode||!l)return!1;let e=l?.getStore();return!(e?.sandboxActive!==!0||e.trusted)}recordViolation(e,t,r){let s={timestamp:Date.now(),type:e,message:r,path:t,stack:new Error().stack,executionId:l?.getStore()?.executionId};if(this.violations.length<T&&this.violations.push(s),this.config.onViolation)try{this.config.onViolation(s)}catch(o){console.debug("[DefenseInDepthBox] onViolation callback threw:",o instanceof Error?o.message:o)}return s}createBlockingProxy(e,t,r){let s=this;return new Proxy(e,{apply(o,n,i){if(s.shouldBlock()){let a=`${t} is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} called (audit mode)`),Reflect.apply(o,n,i)},construct(o,n,i){if(s.shouldBlock()){let a=`${t} constructor is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} constructor called (audit mode)`),Reflect.construct(o,n,i)}})}createBlockingObjectProxy(e,t,r,s){let o=this;return new Proxy(e,{get(n,i,a){if(o.shouldBlock()){if(s&&typeof i=="string"&&s.has(i))return Reflect.get(n,i,a);let u=`${t}.${String(i)}`,d=`${u} is blocked during script execution`,f=o.recordViolation(r,u,d);throw new p(d,f)}if(o.config.auditMode&&l?.getStore()?.sandboxActive===!0){let u=`${t}.${String(i)}`;o.recordViolation(r,u,`${u} accessed (audit mode)`)}return Reflect.get(n,i,a)},set(n,i,a,u){if(o.shouldBlock()){let d=`${t}.${String(i)}`,f=`${d} modification is blocked during script execution`,v=o.recordViolation(r,d,f);throw new p(f,v)}return Reflect.set(n,i,a,u)},ownKeys(n){if(o.shouldBlock()){let i=`${t} enumeration is blocked during script execution`,a=o.recordViolation(r,t,i);throw new p(i,a)}return Reflect.ownKeys(n)},getOwnPropertyDescriptor(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} descriptor access is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.getOwnPropertyDescriptor(n,i)},has(n,i){if(o.shouldBlock()){let a=`${t}.${String(i)}`,u=`${a} existence check is blocked during script execution`,d=o.recordViolation(r,a,u);throw new p(u,d)}return Reflect.has(n,i)}})}applyPatches(){this.patchFailures=[];let e=m(),t=new Set(["process_send","process_channel","process_stdout","process_stderr"]);for(let o of e)t.has(o.violationType)||this.applyPatch(o);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectDynamicImport(),this.protectModuleLoad(),this.protectModuleResolveFilename(),this.protectProcessMainModule(),this.protectProcessExecPath();let r=["Function.prototype.constructor","Module._load"],s=this.patchFailures.filter(o=>r.includes(o));if(s.length>0)throw this.restorePatches(),new Error(`DefenseInDepthBox: critical patches failed: ${s.join(", ")}`)}protectConstructorChain(){this.patchPrototypeConstructor(Function.prototype,"Function.prototype.constructor","function_constructor");try{let e=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"AsyncFunction.prototype.constructor","async_function_constructor")}catch(e){this.patchFailures.push("AsyncFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(function*(){}).constructor;e&&e!==Function&&this.patchPrototypeConstructor(e.prototype,"GeneratorFunction.prototype.constructor","generator_function_constructor")}catch(e){this.patchFailures.push("GeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch GeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}try{let e=Object.getPrototypeOf(async function*(){}).constructor,t=Object.getPrototypeOf(async()=>{}).constructor;e&&e!==Function&&e!==t&&this.patchPrototypeConstructor(e.prototype,"AsyncGeneratorFunction.prototype.constructor","async_generator_function_constructor")}catch(e){this.patchFailures.push("AsyncGeneratorFunction.prototype.constructor"),console.debug("[DefenseInDepthBox] Could not patch AsyncGeneratorFunction.prototype.constructor:",e instanceof Error?e.message:e)}}protectErrorPrepareStackTrace(){let e=this;try{let t=Object.getOwnPropertyDescriptor(Error,"prepareStackTrace");this.originalDescriptors.push({target:Error,prop:"prepareStackTrace",descriptor:t});let r=t?.value;Object.defineProperty(Error,"prepareStackTrace",{get(){return r},set(s){if(e.shouldBlock()){let o="Error.prepareStackTrace modification is blocked during script execution",n=e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",o);throw new p(o,n)}e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace","Error.prepareStackTrace set (audit mode)"),r=s},configurable:!0})}catch(t){this.patchFailures.push("Error.prepareStackTrace"),console.debug("[DefenseInDepthBox] Could not protect Error.prepareStackTrace:",t instanceof Error?t.message:t)}}patchPrototypeConstructor(e,t,r){let s=this;try{let o=Object.getOwnPropertyDescriptor(e,"constructor");this.originalDescriptors.push({target:e,prop:"constructor",descriptor:o});let n=o?.value;Object.defineProperty(e,"constructor",{get(){if(s.shouldBlock()){let i=`${t} access is blocked during script execution`,a=s.recordViolation(r,t,i);throw new p(i,a)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} accessed (audit mode)`),n},set(i){if(s.shouldBlock()){let a=`${t} modification is blocked during script execution`,u=s.recordViolation(r,t,a);throw new p(a,u)}Object.defineProperty(this,"constructor",{value:i,writable:!0,configurable:!0})},configurable:!0})}catch(o){this.patchFailures.push(t),console.debug(`[DefenseInDepthBox] Could not patch ${t}:`,o instanceof Error?o.message:o)}}protectProcessMainModule(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"mainModule");this.originalDescriptors.push({target:process,prop:"mainModule",descriptor:t});let r=t?.value;r!==void 0&&Object.defineProperty(process,"mainModule",{get(){if(e.shouldBlock()){let s="process.mainModule access is blocked during script execution",o=e.recordViolation("process_main_module","process.mainModule",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_main_module","process.mainModule","process.mainModule accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.mainModule modification is blocked during script execution",n=e.recordViolation("process_main_module","process.mainModule",o);throw new p(o,n)}Object.defineProperty(process,"mainModule",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.mainModule"),console.debug("[DefenseInDepthBox] Could not protect process.mainModule:",t instanceof Error?t.message:t)}}protectProcessExecPath(){if(typeof process>"u")return;let e=this;try{let t=Object.getOwnPropertyDescriptor(process,"execPath");this.originalDescriptors.push({target:process,prop:"execPath",descriptor:t});let r=t?.value??process.execPath;Object.defineProperty(process,"execPath",{get(){if(e.shouldBlock()){let s="process.execPath access is blocked during script execution",o=e.recordViolation("process_exec_path","process.execPath",s);throw new p(s,o)}return e.config.auditMode&&l?.getStore()?.sandboxActive===!0&&e.recordViolation("process_exec_path","process.execPath","process.execPath accessed (audit mode)"),r},set(s){if(e.shouldBlock()){let o="process.execPath modification is blocked during script execution",n=e.recordViolation("process_exec_path","process.execPath",o);throw new p(o,n)}Object.defineProperty(process,"execPath",{value:s,writable:!0,configurable:!0})},configurable:!0})}catch(t){this.patchFailures.push("process.execPath"),console.debug("[DefenseInDepthBox] Could not protect process.execPath:",t instanceof Error?t.message:t)}}protectDynamicImport(){if(!(h||c.importHooksRegistered))try{let e=g("node:module");if(typeof e.registerHooks=="function"){e.registerHooks({resolve(t,r,s){if(t.startsWith("data:")||t.startsWith("blob:"))throw new Error(`dynamic import of ${t.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);return s(t,r)}}),c.importHooksRegistered=!0;return}if(typeof e.register=="function"){let t=["export async function resolve(specifier, context, nextResolve) {",' if (specifier.startsWith("data:") || specifier.startsWith("blob:")) {',' throw new Error("dynamic import of " + (specifier.startsWith("data:") ? "data:" : "blob:") + " URLs is blocked by defense-in-depth");'," }"," return nextResolve(specifier, context);","}"].join(`
|
|
5
|
-
`);e.register(`data:text/javascript,${encodeURIComponent(t)}`),c.importHooksRegistered=!0}}catch(e){console.debug("[DefenseInDepthBox] Could not register import() hooks:",e instanceof Error?e.message:e)}}protectModuleLoad(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._load!="function")return;let t=e._load,r=Object.getOwnPropertyDescriptor(e,"_load");this.originalDescriptors.push({target:e,prop:"_load",descriptor:r});let o=this.createBlockingProxy(t,"Module._load","module_load");Object.defineProperty(e,"_load",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._load"),console.debug("[DefenseInDepthBox] Could not protect Module._load:",e instanceof Error?e.message:e)}}protectModuleResolveFilename(){if(!h)try{let e=null;if(typeof process<"u"){let n=process.mainModule;n&&typeof n=="object"&&(e=n.constructor)}if(!e&&typeof g<"u"&&typeof g.main<"u"&&(e=g.main.constructor),!e||typeof e._resolveFilename!="function")return;let t=e._resolveFilename,r=Object.getOwnPropertyDescriptor(e,"_resolveFilename");this.originalDescriptors.push({target:e,prop:"_resolveFilename",descriptor:r});let o=this.createBlockingProxy(t,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(e,"_resolveFilename",{value:o,writable:!0,configurable:!0})}catch(e){this.patchFailures.push("Module._resolveFilename"),console.debug("[DefenseInDepthBox] Could not protect Module._resolveFilename:",e instanceof Error?e.message:e)}}applyPatch(e){let{target:t,prop:r,violationType:s,strategy:o}=e;try{let n=t[r];if(n===void 0)return;let i=Object.getOwnPropertyDescriptor(t,r);if(this.originalDescriptors.push({target:t,prop:r,descriptor:i}),o==="freeze")typeof n=="object"&&n!==null&&Object.freeze(n);else{let a=this.getPathForTarget(t,r),u=typeof n=="function"?this.createBlockingProxy(n,a,s):this.createBlockingObjectProxy(n,a,s,e.allowedKeys);Object.defineProperty(t,r,{value:u,writable:!0,configurable:!0})}}catch(n){let i=this.getPathForTarget(t,r);this.patchFailures.push(i),console.debug(`[DefenseInDepthBox] Could not patch ${i}:`,n instanceof Error?n.message:n)}}restorePatches(){for(let e=this.originalDescriptors.length-1;e>=0;e--){let{target:t,prop:r,descriptor:s}=this.originalDescriptors[e];try{s?Object.defineProperty(t,r,s):delete t[r]}catch(o){let n=this.getPathForTarget(t,r);console.debug(`[DefenseInDepthBox] Could not restore ${n}:`,o instanceof Error?o.message:o)}}this.originalDescriptors=[]}};export{p as a,x as b};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{b as p}from"./chunk-4FNW6LFM.js";import{a as j,b as h}from"./chunk-JJHAWOIB.js";import{a as S,b as y}from"./chunk-GTNBSMZR.js";import{existsSync as g}from"node:fs";import{dirname as W,join as w}from"node:path";import{fileURLToPath as H}from"node:url";import{Worker as J}from"node:worker_threads";import _ from"sql.js";function E(e,r,n){switch(n.mode){case"list":return M(e,r,n);case"csv":return V(e,r,n);case"json":return B(e,r);case"line":return O(e,r,n);case"column":return I(e,r,n);case"table":return N(e,r,n);case"markdown":return P(e,r,n);case"tabs":return R(e,r,n);case"box":return F(e,r,n);case"quote":return Q(e,r,n);case"html":return D(e,r,n);case"ascii":return U(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 M(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(n.separator));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(n.separator));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function V(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(x).join(","));for(let a of r)t.push(a.map(i=>x(u(i,n.nullValue))).join(","));return t.length>0?`${t.join(`
|
|
3
|
-
`)}
|
|
4
|
-
`:""}function x(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
5
|
-
`)?`"${e.replace(/"/g,'""')}"`:e}function T(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function A(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):T(e):JSON.stringify(e)}function B(e,r){return r.length===0?"":`[${r.map(t=>`{${e.map((i,s)=>`${JSON.stringify(i)}:${A(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)),a=[];for(let i of r)for(let s=0;s<e.length;s++){let o=e[s].padStart(t);a.push(`${o} = ${u(i[s],n.nullValue)}`)}return`${a.join(`
|
|
8
|
-
`)}
|
|
9
|
-
`}function I(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 a=[];n.header&&(a.push(e.map((i,s)=>i.padEnd(t[s])).join(" ")),a.push(t.map(i=>"-".repeat(i)).join(" ")));for(let i of r)a.push(i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" "));return a.length>0?`${a.join(`
|
|
10
|
-
`)}
|
|
11
|
-
`:""}function N(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 a=[],i=`+${t.map(s=>"-".repeat(s+2)).join("+")}+`;a.push(i),n.header&&(a.push(`| ${e.map((s,o)=>s.padEnd(t[o])).join(" | ")} |`),a.push(i));for(let s of r)a.push(`| ${s.map((o,f)=>u(o,n.nullValue).padEnd(t[f])).join(" | ")} |`);return a.push(i),`${a.join(`
|
|
12
|
-
`)}
|
|
13
|
-
`}function P(e,r,n){if(e.length===0)return"";let t=[];n.header&&(t.push(`| ${e.join(" | ")} |`),t.push(`|${e.map(()=>"---").join("|")}|`));for(let a of r)t.push(`| ${a.map(i=>u(i,n.nullValue)).join(" | ")} |`);return t.length>0?`${t.join(`
|
|
14
|
-
`)}
|
|
15
|
-
`:""}function R(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.join(" "));for(let a of r)t.push(a.map(i=>u(i,n.nullValue)).join(" "));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function F(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 a=[];a.push(`\u250C${t.map(i=>"\u2500".repeat(i+2)).join("\u252C")}\u2510`),a.push(`\u2502 ${e.map((i,s)=>i.padEnd(t[s])).join(" \u2502 ")} \u2502`),a.push(`\u251C${t.map(i=>"\u2500".repeat(i+2)).join("\u253C")}\u2524`);for(let i of r)a.push(`\u2502 ${i.map((s,o)=>u(s,n.nullValue).padEnd(t[o])).join(" \u2502 ")} \u2502`);return a.push(`\u2514${t.map(i=>"\u2500".repeat(i+2)).join("\u2534")}\u2518`),`${a.join(`
|
|
16
|
-
`)}
|
|
17
|
-
`}function Q(e,r,n){let t=[];n.header&&e.length>0&&t.push(e.map(a=>`'${a}'`).join(","));for(let a of r)t.push(a.map(i=>i==null?"NULL":typeof i=="number"?Number.isInteger(i)?String(i):T(i):`'${String(i)}'`).join(","));return t.length>0?`${t.join(n.newline)}${n.newline}`:""}function D(e,r,n){let t=[];n.header&&e.length>0&&(t.push(`<TR>${e.map(a=>`<TH>${q(a)}</TH>`).join("")}`),t.push("</TR>"));for(let a of r)t.push(`<TR>${a.map(i=>`<TD>${q(u(i,n.nullValue))}</TD>`).join("")}`),t.push("</TR>");return t.length>0?`${t.join(`
|
|
18
|
-
`)}
|
|
19
|
-
`:""}function q(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function U(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 z=5e3,X={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 Y(e){let r={mode:"list",header:!1,separator:"|",newline:`
|
|
20
|
-
`,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},n=null,t=null,a=!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")a=!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:a}}async function v(){let e=await p.runTrustedAsync(()=>_()),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 G(){let e=W(H(import.meta.url)),r=w(e,"../../commands/sqlite3/worker.js");if(g(r))return r;let n=w(e,"worker.js");if(g(n))return n;let t=w(e,"../../../dist/commands/sqlite3/worker.js");if(g(t))return t;throw new Error("sqlite3 worker not found. Run 'pnpm build' to compile the worker.")}var K={createWorker(e,r){return new J(e,{workerData:r})}};function Z(e){if(!e||typeof e!="object")return{success:!1,error:"Malformed worker response"};let r=e;return r.type==="security-violation"?{success:!1,error:`Security violation: ${typeof r.violation?.type=="string"?r.violation.type:"unknown"}`}:typeof r.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:r.success?Array.isArray(r.results)?typeof r.hasModifications!="boolean"?{success:!1,error:"Malformed worker response: missing hasModifications flag"}:r.dbBuffer!==null&&r.dbBuffer!==void 0&&!(r.dbBuffer instanceof Uint8Array)?{success:!1,error:"Malformed worker response: invalid dbBuffer"}:{success:!0,results:r.results,hasModifications:r.hasModifications,dbBuffer:r.dbBuffer===void 0?null:r.dbBuffer,defenseStats:r.defenseStats}:{success:!1,error:"Malformed worker response: missing results array"}:{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}async function ee(e,r){try{let n=G();return await new Promise((t,a)=>{let i=p.runTrusted(()=>K.createWorker(n,e)),s=j(()=>{i.terminate(),t({success:!1,error:`Query timeout: execution exceeded ${r}ms limit`})},r);i.on("message",o=>{h(s),t(Z(o))}),i.on("error",o=>{h(s),a(o)}),i.on("exit",o=>{h(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 de={name:"sqlite3",async execute(e,r){if(y(e)||e.includes("-help"))return S(X);let n=Y(e);if("exitCode"in n)return n;let{options:t,database:a,sql:i,showVersion:s}=n;if(s)return{stdout:`${await v()}
|
|
27
|
-
`,stderr:"",exitCode:0};if(!a)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=a===":memory:",m="",b=null;try{f||(m=r.fs.resolvePath(r.cwd,a),await r.fs.exists(m)&&(b=await r.fs.readFileBuffer(m)))}catch(l){return{stdout:"",stderr:`sqlite3: unable to open database "${a}": ${l.message}
|
|
30
|
-
`,exitCode:1}}let C=r.limits?.maxSqliteTimeoutMs??z,k={dbBuffer:b,sql:o,options:{bail:t.bail,echo:t.echo}},d;try{d=await ee(k,C)}catch(l){return{stdout:"",stderr:`sqlite3: worker error: ${l.message}
|
|
31
|
-
`,exitCode:1}}if(!d.success)return{stdout:"",stderr:`sqlite3: ${d.error}
|
|
32
|
-
`,exitCode:1};let L={mode:t.mode,header:t.header,separator:t.separator,newline:t.newline,nullValue:t.nullValue},c="";t.echo&&(c+=`${o}
|
|
33
|
-
`);let $=!1;for(let l of d.results)if(l.type==="error"){if(t.bail)return{stdout:c,stderr:`Error: ${l.error}
|
|
34
|
-
`,exitCode:1};c+=`Error: ${l.error}
|
|
35
|
-
`,$=!0}else l.columns&&l.rows&&(l.rows.length>0||t.header)&&(c+=E(l.columns,l.rows,L));if(d.hasModifications&&!t.readonly&&!f&&m&&d.dbBuffer)try{await r.fs.writeFile(m,d.dbBuffer)}catch(l){return{stdout:c,stderr:`sqlite3: failed to write database: ${l.message}
|
|
36
|
-
`,exitCode:1}}return{stdout:c,stderr:"",exitCode:$&&t.bail?1:0}}},ce={name:"sqlite3",flags:[],needsArgs:!0};export{K as a,de as b,ce as c};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as N}from"./chunk-SE4C7FJY.js";import{k as C}from"./chunk-6KZRLMG3.js";import{a as G,b as j,c as T}from"./chunk-GTNBSMZR.js";var B=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function P(n){let e="",t=0,i=!1;for(;t<n.length;){if(n[t]==="["&&!i){if(n[t+1]==="["&&n[t+2]===":"){let s=n.indexOf(":]]",t+3);if(s!==-1){let a=n.slice(t+3,s),r=B.get(a);if(r){e+=`[${r}]`,t=s+3;continue}}}if(n[t+1]==="^"&&n[t+2]==="["&&n[t+3]===":"){let s=n.indexOf(":]]",t+4);if(s!==-1){let a=n.slice(t+4,s),r=B.get(a);if(r){e+=`[^${r}]`,t=s+3;continue}}}e+="[",t++,i=!0,t<n.length&&n[t]==="^"&&(e+="^",t++),t<n.length&&n[t]==="]"&&(e+="\\]",t++);continue}if(i){if(n[t]==="]"){e+="]",t++,i=!1;continue}if(n[t]==="["&&n[t+1]===":"){let s=n.indexOf(":]",t+2);if(s!==-1){let a=n.slice(t+2,s),r=B.get(a);if(r){e+=r,t=s+2;continue}}}if(n[t]==="\\"&&t+1<n.length){e+=n[t]+n[t+1],t+=2;continue}e+=n[t],t++;continue}if(n[t]==="\\"&&t+1<n.length){let s=n[t+1];if(s==="+"||s==="?"||s==="|"){e+=s,t+=2;continue}if(s==="("||s===")"){e+=s,t+=2;continue}if(s==="{"||s==="}"){e+=s,t+=2;continue}if(s==="t"){e+=" ",t+=2;continue}if(s==="n"){e+=`
|
|
3
|
-
`,t+=2;continue}if(s==="r"){e+="\r",t+=2;continue}e+=n[t]+s,t+=2;continue}if(n[t]==="+"||n[t]==="?"||n[t]==="|"||n[t]==="("||n[t]===")"){e+=`\\${n[t]}`,t++;continue}if(n[t]==="^"&&!(e===""||e.endsWith("("))){e+="\\^",t++;continue}if(n[t]==="$"){let s=t===n.length-1,a=t+2<n.length&&n[t+1]==="\\"&&n[t+2]===")";if(!s&&!a){e+="\\$",t++;continue}}e+=n[t],t++}return e}function D(n){let e="",t=!1;for(let i=0;i<n.length;i++)n[i]==="["&&!t?(t=!0,e+="[",i++,i<n.length&&n[i]==="^"&&(e+="^",i++),i<n.length&&n[i]==="]"&&(e+="]",i++),i--):n[i]==="]"&&t?(t=!1,e+="]"):!t&&n[i]==="{"&&n[i+1]===","?(e+="{0,",i++):e+=n[i];return e}function Z(n){let e="";for(let t=0;t<n.length;t++){let i=n[t],s=i.charCodeAt(0);i==="\\"?e+="\\\\":i===" "?e+="\\t":i===`
|
|
4
|
-
`?e+=`$
|
|
5
|
-
`:i==="\r"?e+="\\r":i==="\x07"?e+="\\a":i==="\b"?e+="\\b":i==="\f"?e+="\\f":i==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=i}return`${e}$`}var ce=1e4;function Q(n,e,t){return{patternSpace:"",holdSpace:"",lineNumber:0,totalLines:n,deleted:!1,printed:!1,quit:!1,quitSilent:!1,exitCode:void 0,errorMessage:void 0,appendBuffer:[],substitutionMade:!1,lineNumberOutput:[],nCommandOutput:[],restartCycle:!1,inDRestartedCycle:!1,currentFilename:e,pendingFileReads:[],pendingFileWrites:[],pendingExecute:void 0,rangeStates:t||new Map,linesConsumedInCycle:0}}function le(n){return typeof n=="object"&&"first"in n&&"step"in n}function oe(n){return typeof n=="object"&&"offset"in n}function O(n,e,t,i,s){if(n==="$")return e===t;if(typeof n=="number")return e===n;if(le(n)){let{first:a,step:r}=n;return r===0?e===a:(e-a)%r===0&&e>=a}if(typeof n=="object"&&"pattern"in n)try{let a=n.pattern;a===""&&s?.lastPattern?a=s.lastPattern:a!==""&&s&&(s.lastPattern=a);let r=D(P(a));return N(r).test(i)}catch{return!1}return!1}function W(n){let e=t=>t===void 0?"undefined":t==="$"?"$":typeof t=="number"?String(t):"pattern"in t?`/${t.pattern}/`:"first"in t?`${t.first}~${t.step}`:"unknown";return`${e(n.start)},${e(n.end)}`}function ue(n,e,t,i,s,a){if(!n||!n.start&&!n.end)return!0;let r=n.start,l=n.end;if(r!==void 0&&l===void 0)return O(r,e,t,i,a);if(r!==void 0&&l!==void 0){let o=typeof r=="object"&&"pattern"in r,d=typeof l=="object"&&"pattern"in l,f=oe(l);if(f&&s){let m=W(n),p=s.get(m);if(p||(p={active:!1},s.set(m,p)),p.active){let u=p.startLine||e;return e>=u+l.offset&&(p.active=!1,s.set(m,p)),!0}else return O(r,e,t,i,a)?(p.active=!0,p.startLine=e,s.set(m,p),l.offset===0&&(p.active=!1,s.set(m,p)),!0):!1}if(!o&&!d&&!f){let m=typeof r=="number"?r:r==="$"?t:1,p=typeof l=="number"?l:t;if(m<=p)return e>=m&&e<=p;if(s){let u=W(n),h=s.get(u);return h||(h={active:!1},s.set(u,h)),!h.completed&&e>=m?(h.completed=!0,s.set(u,h),!0):!1}return!1}if(s){let m=W(n),p=s.get(m);if(p||(p={active:!1},s.set(m,p)),p.active)return O(l,e,t,i,a)&&(p.active=!1,typeof r=="number"&&(p.completed=!0),s.set(m,p)),!0;{if(p.completed)return!1;let u=!1;return typeof r=="number"?u=e>=r:u=O(r,e,t,i,a),u?(p.active=!0,p.startLine=e,s.set(m,p),O(l,e,t,i,a)&&(p.active=!1,typeof r=="number"&&(p.completed=!0),s.set(m,p)),!0):!1}}return O(r,e,t,i,a)}return!0}function I(n,e,t,i,s,a){let r=ue(n,e,t,i,s,a);return n?.negated?!r:r}function he(n,e,t,i){let s="",a=0,r=!1;for(;a<=n.length;){e.lastIndex=a;let l=e.exec(n);if(!l){s+=n.slice(a);break}if(l.index!==a){s+=n.slice(a,l.index),a=l.index,r=!1;continue}let o=l[0],d=l.slice(1);if(r&&o.length===0){if(a<n.length)s+=n[a],a++;else break;r=!1;continue}if(s+=i(o,d),r=!1,o.length===0)if(a<n.length)s+=n[a],a++;else break;else a+=o.length,r=!0}return s}function q(n,e,t){let i="",s=0;for(;s<n.length;){if(n[s]==="\\"&&s+1<n.length){let a=n[s+1];if(a==="&"){i+="&",s+=2;continue}if(a==="n"){i+=`
|
|
6
|
-
`,s+=2;continue}if(a==="t"){i+=" ",s+=2;continue}if(a==="r"){i+="\r",s+=2;continue}let r=parseInt(a,10);if(r===0){i+=e,s+=2;continue}if(r>=1&&r<=9){i+=t[r-1]||"",s+=2;continue}i+=a,s+=2;continue}if(n[s]==="&"){i+=e,s++;continue}i+=n[s],s++}return i}function K(n,e,t){if(e>0&&n.length>e)throw new C(`sed: ${t} size limit exceeded (${e} bytes)`,"string_length")}function de(n,e,t){let{lineNumber:i,totalLines:s,patternSpace:a}=e;if(n.type==="label"){e.coverage?.hit(`sed:cmd:${n.type}`);return}if(I(n.address,i,s,a,e.rangeStates,e))switch(e.coverage?.hit(`sed:cmd:${n.type}`),n.type){case"substitute":{let r=n,l="";r.global&&(l+="g"),r.ignoreCase&&(l+="i");let o=r.pattern;o===""&&e.lastPattern?o=e.lastPattern:o!==""&&(e.lastPattern=o);let d=D(r.extendedRegex?o:P(o));try{let f=N(d,l),v=f.test(e.patternSpace);if(f.lastIndex=0,v){if(e.substitutionMade=!0,r.nthOccurrence&&r.nthOccurrence>0&&!r.global){let m=0,p=r.nthOccurrence,u=N(d,`g${r.ignoreCase?"i":""}`);e.patternSpace=u.replace(e.patternSpace,(h,...b)=>{if(m++,m===p){let x=b.slice(0,-2);return q(r.replacement,h,x)}return h})}else if(r.global){let m=N(d,`g${r.ignoreCase?"i":""}`);e.patternSpace=he(e.patternSpace,m,r.replacement,(p,u)=>q(r.replacement,p,u))}else e.patternSpace=f.replace(e.patternSpace,(m,...p)=>{let u=p.slice(0,-2);return q(r.replacement,m,u)});r.printOnMatch&&e.lineNumberOutput.push(e.patternSpace)}}catch{}break}case"print":e.lineNumberOutput.push(e.patternSpace);break;case"printFirstLine":{let r=e.patternSpace.indexOf(`
|
|
7
|
-
`);r!==-1?e.lineNumberOutput.push(e.patternSpace.slice(0,r)):e.lineNumberOutput.push(e.patternSpace);break}case"delete":e.deleted=!0;break;case"deleteFirstLine":{let r=e.patternSpace.indexOf(`
|
|
8
|
-
`);r!==-1?(e.patternSpace=e.patternSpace.slice(r+1),e.restartCycle=!0,e.inDRestartedCycle=!0):e.deleted=!0;break}case"zap":e.patternSpace="";break;case"append":e.appendBuffer.push(n.text);break;case"insert":e.appendBuffer.unshift(`__INSERT__${n.text}`);break;case"change":e.deleted=!0,e.changedText=n.text;break;case"hold":e.holdSpace=e.patternSpace;break;case"holdAppend":e.holdSpace?e.holdSpace+=`
|
|
9
|
-
${e.patternSpace}`:e.holdSpace=e.patternSpace,K(e.holdSpace,t?.maxStringLength??0,"hold space");break;case"get":e.patternSpace=e.holdSpace;break;case"getAppend":e.patternSpace+=`
|
|
10
|
-
${e.holdSpace}`,K(e.patternSpace,t?.maxStringLength??0,"pattern space");break;case"exchange":{let r=e.patternSpace;e.patternSpace=e.holdSpace,e.holdSpace=r;break}case"next":e.printed=!0;break;case"quit":e.quit=!0,n.exitCode!==void 0&&(e.exitCode=n.exitCode);break;case"quitSilent":e.quit=!0,e.quitSilent=!0,n.exitCode!==void 0&&(e.exitCode=n.exitCode);break;case"list":{let r=Z(e.patternSpace);e.lineNumberOutput.push(r);break}case"printFilename":e.currentFilename&&e.lineNumberOutput.push(e.currentFilename);break;case"version":{let r=[4,8,0];if(n.minVersion){let l=n.minVersion.split("."),o=[],d=!1;for(let f of l){let v=parseInt(f,10);if(Number.isNaN(v)||v<0){e.quit=!0,e.exitCode=1,e.errorMessage=`sed: invalid version string: ${n.minVersion}`,d=!0;break}o.push(v)}if(!d){for(;o.length<3;)o.push(0);for(let f=0;f<3;f++){if(o[f]>r[f]){e.quit=!0,e.exitCode=1,e.errorMessage=`sed: this is not GNU sed version ${n.minVersion}`;break}if(o[f]<r[f])break}}}break}case"readFile":e.pendingFileReads.push({filename:n.filename,wholeFile:!0});break;case"readFileLine":e.pendingFileReads.push({filename:n.filename,wholeFile:!1});break;case"writeFile":e.pendingFileWrites.push({filename:n.filename,content:`${e.patternSpace}
|
|
11
|
-
`});break;case"writeFirstLine":{let r=e.patternSpace.indexOf(`
|
|
12
|
-
`),l=r!==-1?e.patternSpace.slice(0,r):e.patternSpace;e.pendingFileWrites.push({filename:n.filename,content:`${l}
|
|
13
|
-
`});break}case"execute":n.command?e.pendingExecute={command:n.command,replacePattern:!1}:e.pendingExecute={command:e.patternSpace,replacePattern:!0};break;case"transliterate":e.patternSpace=fe(e.patternSpace,n);break;case"lineNumber":e.lineNumberOutput.push(String(e.lineNumber));break;case"branch":break;case"branchOnSubst":break;case"branchOnNoSubst":break;case"group":break}}function fe(n,e){let t="";for(let i of n){let s=e.source.indexOf(i);s!==-1?t+=e.dest[s]:t+=i}return t}function U(n,e,t,i){let s=new Map;for(let o=0;o<n.length;o++){let d=n[o];d.type==="label"&&s.set(d.name,o)}let a=i?.maxIterations??ce,r=0,l=0;for(;l<n.length;){if(r++,r>a)throw new C(`sed: command execution exceeded maximum iterations (${a})`,"iterations");if(e.deleted||e.quit||e.quitSilent||e.restartCycle)break;let o=n[l];if(o.type==="next"){if(I(o.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e))if(e.coverage?.hit("sed:cmd:next"),e.nCommandOutput.push(e.patternSpace),t&&t.currentLineIndex+e.linesConsumedInCycle+1<t.lines.length){e.linesConsumedInCycle++;let d=t.lines[t.currentLineIndex+e.linesConsumedInCycle];e.patternSpace=d,e.lineNumber=t.currentLineIndex+e.linesConsumedInCycle+1,e.substitutionMade=!1}else{e.quit=!0,e.deleted=!0;break}l++;continue}if(o.type==="nextAppend"){if(I(o.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e))if(e.coverage?.hit("sed:cmd:nextAppend"),t&&t.currentLineIndex+e.linesConsumedInCycle+1<t.lines.length){e.linesConsumedInCycle++;let d=t.lines[t.currentLineIndex+e.linesConsumedInCycle];e.patternSpace+=`
|
|
14
|
-
${d}`,e.lineNumber=t.currentLineIndex+e.linesConsumedInCycle+1}else{e.quit=!0;break}l++;continue}if(o.type==="branch"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)){if(e.coverage?.hit("sed:cmd:branch"),d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="branchOnSubst"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:branchOnSubst"),e.substitutionMade)){if(e.substitutionMade=!1,d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="branchOnNoSubst"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:branchOnNoSubst"),!e.substitutionMade)){if(d.label){let f=s.get(d.label);if(f!==void 0){l=f;continue}e.branchRequest=d.label;break}break}l++;continue}if(o.type==="group"){let d=o;if(I(d.address,e.lineNumber,e.totalLines,e.patternSpace,e.rangeStates,e)&&(e.coverage?.hit("sed:cmd:group"),U(d.commands,e,t,i),e.branchRequest)){let f=s.get(e.branchRequest);if(f!==void 0){e.branchRequest=void 0,l=f;continue}break}l++;continue}de(o,e,i),l++}return e.linesConsumedInCycle}var c;(function(n){n.NUMBER="NUMBER",n.DOLLAR="DOLLAR",n.PATTERN="PATTERN",n.STEP="STEP",n.RELATIVE_OFFSET="RELATIVE_OFFSET",n.LBRACE="LBRACE",n.RBRACE="RBRACE",n.SEMICOLON="SEMICOLON",n.NEWLINE="NEWLINE",n.COMMA="COMMA",n.NEGATION="NEGATION",n.COMMAND="COMMAND",n.SUBSTITUTE="SUBSTITUTE",n.TRANSLITERATE="TRANSLITERATE",n.LABEL_DEF="LABEL_DEF",n.BRANCH="BRANCH",n.BRANCH_ON_SUBST="BRANCH_ON_SUBST",n.BRANCH_ON_NO_SUBST="BRANCH_ON_NO_SUBST",n.TEXT_CMD="TEXT_CMD",n.FILE_READ="FILE_READ",n.FILE_READ_LINE="FILE_READ_LINE",n.FILE_WRITE="FILE_WRITE",n.FILE_WRITE_LINE="FILE_WRITE_LINE",n.EXECUTE="EXECUTE",n.VERSION="VERSION",n.EOF="EOF",n.ERROR="ERROR"})(c||(c={}));var A=class{input;pos=0;line=1;column=1;constructor(e){this.input=e}tokenize(){let e=[];for(;this.pos<this.input.length;){let t=this.nextToken();t&&e.push(t)}return e.push(this.makeToken(c.EOF,"")),e}makeToken(e,t,i){return{type:e,value:t,line:this.line,column:this.column,...i}}peek(e=0){return this.input[this.pos+e]||""}advance(){let e=this.input[this.pos++]||"";return e===`
|
|
15
|
-
`?(this.line++,this.column=1):this.column++,e}readEscapedString(e){let t="";for(;this.pos<this.input.length&&this.peek()!==e;)if(this.peek()==="\\"){this.advance();let i=this.advance();i==="n"?t+=`
|
|
16
|
-
`:i==="t"?t+=" ":t+=i}else{if(this.peek()===`
|
|
17
|
-
`)return null;t+=this.advance()}return t}skipWhitespace(){for(;this.pos<this.input.length;){let e=this.peek();if(e===" "||e===" "||e==="\r")this.advance();else if(e==="#")for(;this.pos<this.input.length&&this.peek()!==`
|
|
18
|
-
`;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let e=this.line,t=this.column,i=this.peek();return i===`
|
|
19
|
-
`?(this.advance(),{type:c.NEWLINE,value:`
|
|
20
|
-
`,line:e,column:t}):i===";"?(this.advance(),{type:c.SEMICOLON,value:";",line:e,column:t}):i==="{"?(this.advance(),{type:c.LBRACE,value:"{",line:e,column:t}):i==="}"?(this.advance(),{type:c.RBRACE,value:"}",line:e,column:t}):i===","?(this.advance(),{type:c.COMMA,value:",",line:e,column:t}):i==="!"?(this.advance(),{type:c.NEGATION,value:"!",line:e,column:t}):i==="$"?(this.advance(),{type:c.DOLLAR,value:"$",line:e,column:t}):this.isDigit(i)?this.readNumber():i==="+"&&this.isDigit(this.input[this.pos+1]||"")?this.readRelativeOffset():i==="/"?this.readPattern():i===":"?this.readLabelDef():this.readCommand()}readNumber(){let e=this.line,t=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="~"){this.advance();let s="";for(;this.isDigit(this.peek());)s+=this.advance();let a=parseInt(i,10),r=parseInt(s,10)||0;return{type:c.STEP,value:`${a}~${r}`,first:a,step:r,line:e,column:t}}return{type:c.NUMBER,value:parseInt(i,10),line:e,column:t}}readRelativeOffset(){let e=this.line,t=this.column;this.advance();let i="";for(;this.isDigit(this.peek());)i+=this.advance();let s=parseInt(i,10)||0;return{type:c.RELATIVE_OFFSET,value:`+${s}`,offset:s,line:e,column:t}}readPattern(){let e=this.line,t=this.column;this.advance();let i="",s=!1;for(;this.pos<this.input.length;){let a=this.peek();if(a==="/"&&!s)break;if(a==="\\")i+=this.advance(),this.pos<this.input.length&&this.peek()!==`
|
|
21
|
-
`&&(i+=this.advance());else{if(a===`
|
|
22
|
-
`)break;a==="["&&!s?(s=!0,i+=this.advance(),this.peek()==="^"&&(i+=this.advance()),this.peek()==="]"&&(i+=this.advance())):a==="]"&&s?(s=!1,i+=this.advance()):i+=this.advance()}}return this.peek()==="/"&&this.advance(),{type:c.PATTERN,value:i,pattern:i,line:e,column:t}}readLabelDef(){let e=this.line,t=this.column;for(this.advance();this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
|
|
23
|
-
`||s===";"||s==="}"||s==="{")break;i+=this.advance()}return{type:c.LABEL_DEF,value:i,label:i,line:e,column:t}}readCommand(){let e=this.line,t=this.column,i=this.advance();switch(i){case"s":return this.readSubstitute(e,t);case"y":return this.readTransliterate(e,t);case"a":case"i":case"c":return this.readTextCommand(i,e,t);case"b":return this.readBranch(c.BRANCH,"b",e,t);case"t":return this.readBranch(c.BRANCH_ON_SUBST,"t",e,t);case"T":return this.readBranch(c.BRANCH_ON_NO_SUBST,"T",e,t);case"r":return this.readFileCommand(c.FILE_READ,"r",e,t);case"R":return this.readFileCommand(c.FILE_READ_LINE,"R",e,t);case"w":return this.readFileCommand(c.FILE_WRITE,"w",e,t);case"W":return this.readFileCommand(c.FILE_WRITE_LINE,"W",e,t);case"e":return this.readExecute(e,t);case"p":case"P":case"d":case"D":case"h":case"H":case"g":case"G":case"x":case"n":case"N":case"q":case"Q":case"z":case"=":case"l":case"F":return{type:c.COMMAND,value:i,line:e,column:t};case"v":return this.readVersion(e,t);default:return{type:c.ERROR,value:i,line:e,column:t}}}readSubstitute(e,t){let i=this.advance();if(!i||i===`
|
|
24
|
-
`)return{type:c.ERROR,value:"s",line:e,column:t};let s="",a=!1;for(;this.pos<this.input.length;){let o=this.peek();if(o===i&&!a)break;if(o==="\\")this.advance(),this.pos<this.input.length&&this.peek()!==`
|
|
25
|
-
`?this.peek()===i&&!a?s+=this.advance():(s+="\\",s+=this.advance()):s+="\\";else{if(o===`
|
|
26
|
-
`)break;o==="["&&!a?(a=!0,s+=this.advance(),this.peek()==="^"&&(s+=this.advance()),this.peek()==="]"&&(s+=this.advance())):o==="]"&&a?(a=!1,s+=this.advance()):s+=this.advance()}}if(this.peek()!==i)return{type:c.ERROR,value:"unterminated substitution pattern",line:e,column:t};this.advance();let r="";for(;this.pos<this.input.length&&this.peek()!==i;)if(this.peek()==="\\")if(this.advance(),this.pos<this.input.length){let o=this.peek();o==="\\"?(this.advance(),this.pos<this.input.length&&this.peek()===`
|
|
27
|
-
`?(r+=`
|
|
28
|
-
`,this.advance()):r+="\\"):o===`
|
|
29
|
-
`?(r+=`
|
|
30
|
-
`,this.advance()):r+=`\\${this.advance()}`}else r+="\\";else{if(this.peek()===`
|
|
31
|
-
`)break;r+=this.advance()}this.peek()===i&&this.advance();let l="";for(;this.pos<this.input.length;){let o=this.peek();if(o==="g"||o==="i"||o==="p"||o==="I"||this.isDigit(o))l+=this.advance();else break}return{type:c.SUBSTITUTE,value:`s${i}${s}${i}${r}${i}${l}`,pattern:s,replacement:r,flags:l,line:e,column:t}}readTransliterate(e,t){let i=this.advance();if(!i||i===`
|
|
32
|
-
`)return{type:c.ERROR,value:"y",line:e,column:t};let s=this.readEscapedString(i);if(s===null||this.peek()!==i)return{type:c.ERROR,value:"unterminated transliteration source",line:e,column:t};this.advance();let a=this.readEscapedString(i);if(a===null||this.peek()!==i)return{type:c.ERROR,value:"unterminated transliteration dest",line:e,column:t};this.advance();let r=this.peek();for(;r===" "||r===" ";)this.advance(),r=this.peek();return r!==""&&r!==";"&&r!==`
|
|
33
|
-
`&&r!=="}"?{type:c.ERROR,value:"extra text at the end of a transform command",line:e,column:t}:{type:c.TRANSLITERATE,value:`y${i}${s}${i}${a}${i}`,source:s,dest:a,line:e,column:t}}readTextCommand(e,t,i){let s=!1;this.peek()==="\\"&&this.pos+1<this.input.length&&(this.input[this.pos+1]===`
|
|
34
|
-
`||this.input[this.pos+1]===" "||this.input[this.pos+1]===" ")&&(s=!0,this.advance()),(this.peek()===" "||this.peek()===" ")&&this.advance(),this.peek()==="\\"&&this.pos+1<this.input.length&&(this.input[this.pos+1]===" "||this.input[this.pos+1]===" ")&&this.advance(),s&&this.peek()===`
|
|
35
|
-
`&&this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===`
|
|
36
|
-
`){if(a.endsWith("\\")){a=`${a.slice(0,-1)}
|
|
37
|
-
`,this.advance();continue}break}if(r==="\\"&&this.pos+1<this.input.length){let l=this.input[this.pos+1];if(l==="n"){a+=`
|
|
38
|
-
`,this.advance(),this.advance();continue}if(l==="t"){a+=" ",this.advance(),this.advance();continue}if(l==="r"){a+="\r",this.advance(),this.advance();continue}}a+=this.advance()}return{type:c.TEXT_CMD,value:e,text:a,line:t,column:i}}readBranch(e,t,i,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===" "||r===" "||r===`
|
|
39
|
-
`||r===";"||r==="}"||r==="{")break;a+=this.advance()}return{type:e,value:t,label:a||void 0,line:i,column:s}}readVersion(e,t){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===" "||s===" "||s===`
|
|
40
|
-
`||s===";"||s==="}"||s==="{")break;i+=this.advance()}return{type:c.VERSION,value:"v",label:i||void 0,line:e,column:t}}readFileCommand(e,t,i,s){for(;this.peek()===" "||this.peek()===" ";)this.advance();let a="";for(;this.pos<this.input.length;){let r=this.peek();if(r===`
|
|
41
|
-
`||r===";")break;a+=this.advance()}return{type:e,value:t,filename:a.trim(),line:i,column:s}}readExecute(e,t){for(;this.peek()===" "||this.peek()===" ";)this.advance();let i="";for(;this.pos<this.input.length;){let s=this.peek();if(s===`
|
|
42
|
-
`||s===";")break;i+=this.advance()}return{type:c.EXECUTE,value:"e",command:i.trim()||void 0,line:e,column:t}}isDigit(e){return e>="0"&&e<="9"}};var z=class{scripts;tokens=[];pos=0;extendedRegex=!1;constructor(e,t=!1){this.scripts=e,this.extendedRegex=t}parse(){let e=[];for(let t of this.scripts){let i=new A(t);for(this.tokens=i.tokenize(),this.pos=0;!this.isAtEnd();){if(this.check(c.NEWLINE)||this.check(c.SEMICOLON)){this.advance();continue}let s=this.pos,a=this.parseCommand();if(a.error)return{commands:[],error:a.error};if(a.command&&e.push(a.command),this.pos===s&&!this.isAtEnd())return{commands:[],error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}}return{commands:e}}parseCommand(){let e=this.parseAddressRange();if(e?.error)return{command:null,error:e.error};let t=e?.address;for(this.check(c.NEGATION)&&(this.advance(),t&&(t.negated=!0));this.check(c.NEWLINE)||this.check(c.SEMICOLON);)this.advance();if(this.isAtEnd())return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:"command expected"}:{command:null};let i=this.peek();switch(i.type){case c.COMMAND:return this.parseSimpleCommand(i,t);case c.SUBSTITUTE:return this.parseSubstituteFromToken(i,t);case c.TRANSLITERATE:return this.parseTransliterateFromToken(i,t);case c.LABEL_DEF:return this.advance(),{command:{type:"label",name:i.label||""}};case c.BRANCH:return this.advance(),{command:{type:"branch",address:t,label:i.label}};case c.BRANCH_ON_SUBST:return this.advance(),{command:{type:"branchOnSubst",address:t,label:i.label}};case c.BRANCH_ON_NO_SUBST:return this.advance(),{command:{type:"branchOnNoSubst",address:t,label:i.label}};case c.TEXT_CMD:return this.advance(),this.parseTextCommand(i,t);case c.FILE_READ:return this.advance(),{command:{type:"readFile",address:t,filename:i.filename||""}};case c.FILE_READ_LINE:return this.advance(),{command:{type:"readFileLine",address:t,filename:i.filename||""}};case c.FILE_WRITE:return this.advance(),{command:{type:"writeFile",address:t,filename:i.filename||""}};case c.FILE_WRITE_LINE:return this.advance(),{command:{type:"writeFirstLine",address:t,filename:i.filename||""}};case c.EXECUTE:return this.advance(),{command:{type:"execute",address:t,command:i.command}};case c.VERSION:return this.advance(),{command:{type:"version",address:t,minVersion:i.label}};case c.LBRACE:return this.parseGroup(t);case c.RBRACE:return{command:null};case c.ERROR:return{command:null,error:`invalid command: ${i.value}`};default:return t&&(t.start!==void 0||t.end!==void 0)?{command:null,error:"command expected"}:{command:null}}}parseSimpleCommand(e,t){this.advance();let i=e.value;switch(i){case"p":return{command:{type:"print",address:t}};case"P":return{command:{type:"printFirstLine",address:t}};case"d":return{command:{type:"delete",address:t}};case"D":return{command:{type:"deleteFirstLine",address:t}};case"h":return{command:{type:"hold",address:t}};case"H":return{command:{type:"holdAppend",address:t}};case"g":return{command:{type:"get",address:t}};case"G":return{command:{type:"getAppend",address:t}};case"x":return{command:{type:"exchange",address:t}};case"n":return{command:{type:"next",address:t}};case"N":return{command:{type:"nextAppend",address:t}};case"q":return{command:{type:"quit",address:t}};case"Q":return{command:{type:"quitSilent",address:t}};case"z":return{command:{type:"zap",address:t}};case"=":return{command:{type:"lineNumber",address:t}};case"l":return{command:{type:"list",address:t}};case"F":return{command:{type:"printFilename",address:t}};default:return{command:null,error:`unknown command: ${i}`}}}parseSubstituteFromToken(e,t){this.advance();let i=e.flags||"",s,a=i.match(/(\d+)/);return a&&(s=parseInt(a[1],10)),{command:{type:"substitute",address:t,pattern:e.pattern||"",replacement:e.replacement||"",global:i.includes("g"),ignoreCase:i.includes("i")||i.includes("I"),printOnMatch:i.includes("p"),nthOccurrence:s,extendedRegex:this.extendedRegex}}}parseTransliterateFromToken(e,t){this.advance();let i=e.source||"",s=e.dest||"";return i.length!==s.length?{command:null,error:"transliteration sets must have same length"}:{command:{type:"transliterate",address:t,source:i,dest:s}}}parseTextCommand(e,t){let i=e.value,s=e.text||"";switch(i){case"a":return{command:{type:"append",address:t,text:s}};case"i":return{command:{type:"insert",address:t,text:s}};case"c":return{command:{type:"change",address:t,text:s}};default:return{command:null,error:`unknown text command: ${i}`}}}parseGroup(e){this.advance();let t=[];for(;!this.isAtEnd()&&!this.check(c.RBRACE);){if(this.check(c.NEWLINE)||this.check(c.SEMICOLON)){this.advance();continue}let i=this.pos,s=this.parseCommand();if(s.error)return{command:null,error:s.error};if(s.command&&t.push(s.command),this.pos===i&&!this.isAtEnd())return{command:null,error:`unknown command: '${this.peek()?.value??this.peek()?.type}'`}}return this.check(c.RBRACE)?(this.advance(),{command:{type:"group",address:e,commands:t}}):{command:null,error:"unmatched brace in grouped commands"}}parseAddressRange(){if(this.check(c.COMMA))return{error:"expected context address"};let e=this.parseAddress();if(e===void 0)return;let t;if(this.check(c.RELATIVE_OFFSET))t={offset:this.advance().offset||0};else if(this.check(c.COMMA)&&(this.advance(),t=this.parseAddress(),t===void 0))return{error:"expected context address"};return{address:{start:e,end:t}}}parseAddress(){let e=this.peek();switch(e.type){case c.NUMBER:return this.advance(),e.value;case c.DOLLAR:return this.advance(),"$";case c.PATTERN:return this.advance(),{pattern:e.pattern||e.value};case c.STEP:return this.advance(),{first:e.first||0,step:e.step||0};case c.RELATIVE_OFFSET:return this.advance(),{offset:e.offset||0};default:return}}peek(){return this.tokens[this.pos]||{type:c.EOF,value:"",line:0,column:0}}advance(){return this.isAtEnd()||this.pos++,this.tokens[this.pos-1]}check(e){return this.peek().type===e}isAtEnd(){return this.peek().type===c.EOF}};function J(n,e=!1){let t=!1,i=!1,s=[];for(let o=0;o<n.length;o++){let d=n[o];if(s.length===0&&o===0){let f=d.match(/^#([nr]+)\s*(?:\n|$)/i);if(f){let v=f[1].toLowerCase();v.includes("n")&&(t=!0),v.includes("r")&&(i=!0),d=d.slice(f[0].length)}}if(s.length>0&&s[s.length-1].endsWith("\\")){let f=s[s.length-1];s[s.length-1]=`${f}
|
|
43
|
-
${d}`}else s.push(d)}let a=s.join(`
|
|
44
|
-
`),l=new z([a],e||i).parse();if(!l.error&&l.commands.length>0){let o=pe(l.commands);if(o)return{commands:[],error:o,silentMode:t,extendedRegexMode:i}}return{...l,silentMode:t,extendedRegexMode:i}}function pe(n){let e=new Set;Y(n,e);let t=ee(n,e);if(t)return`undefined label '${t}'`}function Y(n,e){for(let t of n)t.type==="label"?e.add(t.name):t.type==="group"&&Y(t.commands,e)}function ee(n,e){for(let t of n){if((t.type==="branch"||t.type==="branchOnSubst"||t.type==="branchOnNoSubst")&&t.label&&!e.has(t.label))return t.label;if(t.type==="group"){let i=ee(t.commands,e);if(i)return i}}}var me={name:"sed",summary:"stream editor for filtering and transforming text",usage:"sed [OPTION]... {script} [input-file]...",options:["-n, --quiet, --silent suppress automatic printing of pattern space","-e script add the script to commands to be executed","-f script-file read script from file","-i, --in-place edit files in place","-E, -r, --regexp-extended use extended regular expressions"," --help display this help and exit"],description:`Commands:
|
|
45
|
-
s/regexp/replacement/[flags] substitute
|
|
46
|
-
d delete pattern space
|
|
47
|
-
p print pattern space
|
|
48
|
-
a\\ text append text after line
|
|
49
|
-
i\\ text insert text before line
|
|
50
|
-
c\\ text change (replace) line with text
|
|
51
|
-
h copy pattern space to hold space
|
|
52
|
-
H append pattern space to hold space
|
|
53
|
-
g copy hold space to pattern space
|
|
54
|
-
G append hold space to pattern space
|
|
55
|
-
x exchange pattern and hold spaces
|
|
56
|
-
n read next line into pattern space
|
|
57
|
-
N append next line to pattern space
|
|
58
|
-
y/source/dest/ transliterate characters
|
|
59
|
-
= print line number
|
|
60
|
-
l list pattern space (escape special chars)
|
|
61
|
-
b [label] branch to label
|
|
62
|
-
t [label] branch on substitution
|
|
63
|
-
T [label] branch if no substitution
|
|
64
|
-
:label define label
|
|
65
|
-
q quit
|
|
66
|
-
Q quit without printing
|
|
67
|
-
|
|
68
|
-
Addresses:
|
|
69
|
-
N line number
|
|
70
|
-
$ last line
|
|
71
|
-
/regexp/ lines matching regexp
|
|
72
|
-
N,M range from line N to M
|
|
73
|
-
first~step every step-th line starting at first`};async function H(n,e,t,i={}){let{limits:s,filename:a,fs:r,cwd:l,coverage:o}=i,d=n.endsWith(`
|
|
74
|
-
`),f=n.split(`
|
|
75
|
-
`);f.length>0&&f[f.length-1]===""&&f.pop();let v=f.length,m="",p,u=!1,h=s?.maxStringLength??0,b=R=>{if(m+=R,h>0&&m.length>h)throw new C(`sed: output size limit exceeded (${h} bytes)`,"string_length")},x="",y,te=new Map,F=new Map,$=new Map,_=new Map,ne=s?{maxIterations:s.maxSedIterations,maxStringLength:h}:void 0;for(let R=0;R<f.length;R++){let g={...Q(v,a,te),patternSpace:f[R],holdSpace:x,lastPattern:y,lineNumber:R+1,totalLines:v,substitutionMade:!1,coverage:o},ie={lines:f,currentLineIndex:R},V=0,se=1e4;g.linesConsumedInCycle=0;do{if(V++,V>se)break;if(g.restartCycle=!1,g.pendingFileReads=[],g.pendingFileWrites=[],U(e,g,ie,ne),r&&l){for(let E of g.pendingFileReads){let k=r.resolvePath(l,E.filename);try{if(E.wholeFile){let S=await r.readFile(k);g.appendBuffer.push(S.replace(/\n$/,""))}else{if(!F.has(k)){let ae=await r.readFile(k);F.set(k,ae.split(`
|
|
76
|
-
`)),$.set(k,0)}let S=F.get(k),w=$.get(k);S&&w!==void 0&&w<S.length&&(g.appendBuffer.push(S[w]),$.set(k,w+1))}}catch{}}for(let E of g.pendingFileWrites){let k=r.resolvePath(l,E.filename),S=_.get(k)||"";_.set(k,S+E.content)}}}while(g.restartCycle&&!g.deleted&&!g.quit&&!g.quitSilent);if(R+=g.linesConsumedInCycle,x=g.holdSpace,y=g.lastPattern,!t)for(let E of g.nCommandOutput)b(`${E}
|
|
77
|
-
`);let re=g.lineNumberOutput.length>0;for(let E of g.lineNumberOutput)b(`${E}
|
|
78
|
-
`);let X=[],M=[];for(let E of g.appendBuffer)E.startsWith("__INSERT__")?X.push(E.slice(10)):M.push(E);for(let E of X)b(`${E}
|
|
79
|
-
`);let L=!1;!g.deleted&&!g.quitSilent?t?g.printed&&(b(`${g.patternSpace}
|
|
80
|
-
`),L=!0):(b(`${g.patternSpace}
|
|
81
|
-
`),L=!0):g.changedText!==void 0&&(b(`${g.changedText}
|
|
82
|
-
`),L=!0);for(let E of M)b(`${E}
|
|
83
|
-
`);if(u=(re||L)&&M.length===0,g.quit||g.quitSilent){if(g.exitCode!==void 0&&(p=g.exitCode),g.errorMessage)return{output:"",exitCode:p||1,errorMessage:g.errorMessage};break}}if(r&&l)for(let[R,g]of _)try{await r.writeFile(R,g)}catch{}return!d&&u&&m.endsWith(`
|
|
84
|
-
`)&&(m=m.slice(0,-1)),{output:m,exitCode:p}}var Le={name:"sed",async execute(n,e){if(j(n))return G(me);let t=[],i=[],s=!1,a=!1,r=!1,l=[];for(let u=0;u<n.length;u++){let h=n[u];if(h==="-n"||h==="--quiet"||h==="--silent")s=!0;else if(h==="-i"||h==="--in-place")a=!0;else if(h.startsWith("-i"))a=!0;else if(h==="-E"||h==="-r"||h==="--regexp-extended")r=!0;else if(h==="-e")u+1<n.length&&t.push(n[++u]);else if(h==="-f")u+1<n.length&&i.push(n[++u]);else{if(h.startsWith("--"))return T("sed",h);if(h==="-")l.push(h);else if(h.startsWith("-")&&h.length>1){for(let b of h.slice(1))if(b!=="n"&&b!=="e"&&b!=="f"&&b!=="i"&&b!=="E"&&b!=="r")return T("sed",`-${b}`);h.includes("n")&&(s=!0),h.includes("i")&&(a=!0),(h.includes("E")||h.includes("r"))&&(r=!0),h.includes("e")&&!h.includes("n")&&!h.includes("i")&&u+1<n.length&&t.push(n[++u]),h.includes("f")&&!h.includes("e")&&u+1<n.length&&i.push(n[++u])}else!h.startsWith("-")&&t.length===0&&i.length===0?t.push(h):h.startsWith("-")||l.push(h)}}for(let u of i){let h=e.fs.resolvePath(e.cwd,u);try{let b=await e.fs.readFile(h);for(let x of b.split(`
|
|
85
|
-
`)){let y=x.trim();y&&!y.startsWith("#")&&t.push(y)}}catch{return{stdout:"",stderr:`sed: couldn't open file ${u}: No such file or directory
|
|
86
|
-
`,exitCode:1}}}if(t.length===0)return{stdout:"",stderr:`sed: no script specified
|
|
87
|
-
`,exitCode:1};let{commands:o,error:d,silentMode:f}=J(t,r);if(d)return{stdout:"",stderr:`sed: ${d}
|
|
88
|
-
`,exitCode:1};let v=!!(s||f);if(a){if(l.length===0)return{stdout:"",stderr:`sed: -i requires at least one file argument
|
|
89
|
-
`,exitCode:1};for(let u of l){if(u==="-")continue;let h=e.fs.resolvePath(e.cwd,u);try{let b=await e.fs.readFile(h),x=await H(b,o,v,{limits:e.limits,filename:u,fs:e.fs,cwd:e.cwd,coverage:e.coverage});if(x.errorMessage)return{stdout:"",stderr:`${x.errorMessage}
|
|
90
|
-
`,exitCode:x.exitCode??1};await e.fs.writeFile(h,x.output)}catch(b){return b instanceof C?{stdout:"",stderr:`sed: ${b.message}
|
|
91
|
-
`,exitCode:C.EXIT_CODE}:{stdout:"",stderr:`sed: ${u}: No such file or directory
|
|
92
|
-
`,exitCode:1}}}return{stdout:"",stderr:"",exitCode:0}}let m="";if(l.length===0){m=e.stdin;try{let u=await H(m,o,v,{limits:e.limits,fs:e.fs,cwd:e.cwd,coverage:e.coverage});return{stdout:u.output,stderr:u.errorMessage?`${u.errorMessage}
|
|
93
|
-
`:"",exitCode:u.exitCode??0}}catch(u){if(u instanceof C)return{stdout:"",stderr:`sed: ${u.message}
|
|
94
|
-
`,exitCode:C.EXIT_CODE};throw u}}let p=!1;for(let u of l){let h;if(u==="-")p?h="":(h=e.stdin,p=!0);else{let b=e.fs.resolvePath(e.cwd,u);try{h=await e.fs.readFile(b)}catch(x){return x instanceof C?{stdout:"",stderr:`sed: ${x.message}
|
|
95
|
-
`,exitCode:C.EXIT_CODE}:{stdout:"",stderr:`sed: ${u}: No such file or directory
|
|
96
|
-
`,exitCode:1}}}m.length>0&&h.length>0&&!m.endsWith(`
|
|
97
|
-
`)&&(m+=`
|
|
98
|
-
`),m+=h}try{let u=await H(m,o,v,{limits:e.limits,filename:l.length===1?l[0]:void 0,fs:e.fs,cwd:e.cwd,coverage:e.coverage});return{stdout:u.output,stderr:u.errorMessage?`${u.errorMessage}
|
|
99
|
-
`:"",exitCode:u.exitCode??0}}catch(u){if(u instanceof C)return{stdout:"",stderr:`sed: ${u.message}
|
|
100
|
-
`,exitCode:C.EXIT_CODE};throw u}}},we={name:"sed",flags:[{flag:"-n",type:"boolean"},{flag:"-i",type:"boolean"},{flag:"-E",type:"boolean"},{flag:"-r",type:"boolean"},{flag:"-e",type:"value",valueHint:"string"}],stdinType:"text",needsArgs:!0};export{Le as a,we as b};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as b,b as g,c as T,d as k,e as X}from"./chunk-UYBH3FNE.js";import{a as G,c as ht}from"./chunk-4PRVMER6.js";import{a as C}from"./chunk-SE4C7FJY.js";import{k as D}from"./chunk-6KZRLMG3.js";function W(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))?ht(...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"?[T(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"?[T(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=Math.max(n.limits.maxIterations*100,1e6),f=l=>l.length>=s,o=p(t,e[0],n);if(e.length===1){let l=[];for(let m of o){let A=m;for(let E=0;E<A;E++)if(l.push(E),f(l))return l}return l}let h=p(t,e[1],n);if(e.length===2){let l=[];for(let m of o)for(let A of h){let E=m,w=A;for(let N=E;N<w;N++)if(l.push(N),f(l))return l}return l}let y=p(t,e[2],n),a=[];for(let l of o)for(let m of h)for(let A of y){let E=l,w=m,N=A;if(N!==0){if(N>0){for(let S=E;S<w;S+=N)if(a.push(S),f(a))return a}else for(let S=E;S>w;S+=N)if(a.push(S),f(a))return a}}return a}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 Z(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 O(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function B(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function z(t,r){let e=k(t);for(let n of Object.keys(r))b(n)&&(T(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,z(e[n],r[n])):g(e,n,r[n]));return e}function x(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 $(t,r){if(I(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=>$(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=>T(e,p)&&$(e[p],n[p]))}return!1}var Et=2e3;function v(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??Et;return x(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 tt(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 et(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 rt(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 wt=2e3;function nt(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??wt;return x(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,Object.create(null)]);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 st(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 it(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=T(c,h)?c[h]:null;s.push([f,y])}return[s]}default:return null}}function ot(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 C(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[...C(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[C(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=C(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=C(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[C(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[C(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 ft(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 F(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]=F(s[n],p,e),s}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!b(n))return t??Object.create(null);let i=t&&typeof t=="object"&&!Array.isArray(t)?k(t):Object.create(null),u=Object.hasOwn(i,n)?i[n]:void 0;return g(i,n,F(u,p,e)),i}function K(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=k(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]=K(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!b(p))return t;let i=k(t);return Object.hasOwn(i,p)&&g(i,p,K(i[p],n)),i}return t}var P=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])}},J=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},kt=1e4,lt=2e3,Nt=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 Ot(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??kt,maxDepth:t?.limits?.maxDepth??lt},env:t?.env,coverage:t?.coverage}}function H(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,coverage:t.coverage}}function U(t,r,e){switch(r.type){case"var":return H(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=U(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=T(n,u)?n[u]:null;i.keyVar&&(p=H(p,i.keyVar,c));let s=U(p,i.pattern,c);if(s===null)return null;p=s}return p}}}function St(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 R(t){if(t.type==="Identity")return[];if(t.type==="Field"){let r=t.base?R(t.base):[];return r===null?null:[...r,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let r=t.base?R(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=R(t.left);return r===null?null:ct(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 ct(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=R(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=R(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=ct(t,r.left);return e===null?null:ct(e,r.right)}return r.type==="Identity"?t:null}function yt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof D)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 D)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Ot(e);switch(n.root===void 0&&(n={...n,root:t,currentPath:[]}),n.coverage?.hit(`jq:node:${r.type}`),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=at(a,u),A=at(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=R(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 P?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=[Object.create(null)];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(k(f));continue}for(let h of c){let y=k(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 Rt(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"?!O(i):null});case"Cond":return d(t,r.cond,n).flatMap(i=>{if(O(i))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(O))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 J?p.value:p instanceof Error?p.message:String(p);return d(i,r.catch,n)}return[]}case"Call":return mt(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=U(n,s,i),u!==null)break;return u===null?[]:d(t,r.body,u)});case"VarRef":{if(r.name==="$ENV")return[n.env?G(n.env):Object.create(null)];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[Tt(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??lt;for(let c of p){let s;if(r.pattern){if(s=U(n,r.pattern,c),s===null)continue}else s=H(n,r.varName,c);if(i=d(i,r.update,s)[0],x(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=U(n,r.pattern,c),s===null)continue}else s=H(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 P?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 P&&p.label===r.name)return p.partialResults;throw p}case"Break":throw new P(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 at(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Tt(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"?X(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=k(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=k(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=k(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=k(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 Ct(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=k(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=k(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=k(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=k(i);return delete o[f],o}return i}case"Iterate":return Array.isArray(i)?[]:i&&typeof i=="object"?Object.create(null):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=k(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],N=E<0?w.length+E:E;return N>=0&&N<w.length&&(w[N]=m),w}if(typeof E=="string"&&a&&typeof a=="object"&&!Array.isArray(a)){if(!b(E))return a;let w=k(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 Rt(t,r,e,n,p){if(r==="and")return d(t,e,p).flatMap(s=>O(s)?d(t,n,p).map(o=>O(o)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>O(s)?[!0]:d(t,n,p).map(o=>O(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)?X(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)?z(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 I(c,s);case"!=":return!I(c,s);case"<":return B(c,s)<0;case"<=":return B(c,s)<=0;case">":return B(c,s)>0;case">=":return B(c,s)>=0;default:return null}}))}function mt(t,r,e,n){let p=Nt.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let i=et(t,r,e,n,d);if(i!==null)return i;let u=ot(t,r,e,n,d);if(u!==null)return u;let c=Z(t,r,e,n,d);if(c!==null)return c;let s=v(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ft(t,r);if(f!==null)return f;let o=nt(t,r,e,n,d);if(o!==null)return o;let h=W(t,r,e,n,d,yt,_,O,$,D);if(h!==null)return h;let y=st(t,r,e,n,d,O,F,K,Ct,V);if(y!==null)return y;let a=tt(t,r,e,n,d,I);if(a!==null)return a;let l=Q(t,r,e,n,d,yt,O,D);if(l!==null)return l;let m=rt(t,r,e,n,d,O,St,mt);if(m!==null)return m;let A=it(t,r,e,n,d,I);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 J(E)}case"env":return[n.env?G(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let E=`${r}/${e.length}`,w=n.funcs?.get(E);if(w){let N=w.closure??n.funcs??new Map,S=new Map(N);S.set(E,w);for(let L=0;L<w.params.length;L++){let gt=w.params[L],ut=e[L];if(ut){let j=d(t,ut,n),M;if(j.length===0)M={type:"Call",name:"empty",args:[]};else if(j.length===1)M={type:"Literal",value:j[0]};else{M={type:"Literal",value:j[j.length-1]};for(let q=j.length-2;q>=0;q--)M={type:"Comma",left:{type:"Literal",value:j[q]},right:M}}S.set(`${gt}/0`,{params:[],body:M})}}let bt={...n,funcs:S};return d(t,w.body,bt)}throw new Error(`Unknown function: ${r}`)}}}function V(t,r,e,n,p){if(r.type==="Comma"){let c=r;V(t,c.left,e,n,p),V(t,c.right,e,n,p);return}let i=R(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=R(r.left);if(c!==null){let s=d(t,r.left,e);for(let f of s)V(f,r.right,e,[...n,...c],p);return}}d(t,r,e).length>0&&p.push(n)}var dt=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"]]),Y=new Set(dt.values());function At(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
|
-
`||o==="\r")){if(o==="#"){for(;!i()&&n()!==`
|
|
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
|
-
`;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=dt.get(h);y?r.push({type:y,value:h,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 pt=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()}isFieldNameAfterDot(r=0){let e=this.peek(r),n=this.peek(r+1);return n.type==="STRING"?!0:n.type==="IDENT"||Y.has(n.type)?n.pos===e.pos+1:!1}isIdentLike(){let r=this.peek().type;return r==="IDENT"||Y.has(r)}consumeFieldNameAfterDot(r){let e=this.peek();return e.type==="STRING"?this.advance().value:(e.type==="IDENT"||Y.has(e.type))&&e.pos===r.pos+1?this.advance().value:null}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"||Y.has(r.type)){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.isFieldNameAfterDot())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.check("DOT")){let r=this.advance();if(this.check("LBRACKET")){if(this.advance(),this.match("RBRACKET"))return{type:"Iterate"};if(this.check("COLON")){this.advance();let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",end:p}}let n=this.parseExpr();if(this.match("COLON")){let p=this.check("RBRACKET")?void 0:this.parseExpr();return this.expect("RBRACKET","Expected ']'"),{type:"Slice",start:n,end:p}}return this.expect("RBRACKET","Expected ']'"),{type:"Index",index:n}}let e=this.consumeFieldNameAfterDot(r);return e!==null?{type:"Field",name:e}:{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.isIdentLike()){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=At(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=At(t);return new pt(r).parse()}export{d as a,ge as b};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
function d(t){if(!t)return t;let e=t.replace(/\n\s+at\s.*/g,"");return e=e.replace(/(?:\/(?:Users|home|private|var|opt|Library|System|usr|etc|tmp|nix|snap))\b[^\s'",)}\]:]*/g,"<path>"),e=e.replace(/node:internal\/[^\s'",)}\]:]+/g,"<internal>"),e=e.replace(/[A-Z]:\\[^\s'",)}\]:]+/g,"<path>"),e}import*as o from"node:fs";import*as r from"node:path";function y(t){if(!t||t==="/")return"/";let e=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;e.startsWith("/")||(e=`/${e}`);let n=e.split("/").filter(i=>i&&i!=="."),s=[];for(let i of n)i===".."?s.pop():s.push(i);return`/${s.join("/")}`||"/"}function f(t,e){return t===e||t.startsWith(`${e}/`)}function a(t,e){try{let n=o.realpathSync(t);return f(n,e)?n:null}catch(n){if(n.code==="ENOENT"){let s=r.dirname(t);if(s===t)return null;let i=a(s,e);if(i===null)return null;try{if(o.lstatSync(t).isSymbolicLink()){let l=o.readlinkSync(t),u=r.isAbsolute(l)?l:r.resolve(r.dirname(t),l);if(a(u,e)===null)return null}}catch{}return r.join(i,r.basename(t))}return null}}function v(t,e,n){let s=a(t,n);if(s===null)return null;let i=r.resolve(t),c=i.slice(e.length),l=s.slice(n.length);if(c!==l)return null;try{if(o.lstatSync(i).isSymbolicLink())return null}catch{}return s}function m(t,e){if(!o.existsSync(t))throw new Error(`${e} root does not exist`);if(!o.statSync(t).isDirectory())throw new Error(`${e} root is not a directory`)}function S(t,e){if(t.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${e} '${t}'`)}function x(t,e){if(!r.isAbsolute(t))return{withinRoot:!0,relativePath:t};let n;try{n=o.realpathSync(t)}catch{n=r.resolve(t)}return f(n,e)?{withinRoot:!0,relativePath:n.slice(e.length)||"/"}:{withinRoot:!1,safeName:r.basename(t)}}export{d as a,y as b,f as c,a as d,v as e,m as f,S as g,x as h};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as d}from"./chunk-5WFYIUU2.js";import{a as p}from"./chunk-JBABAK44.js";import{a as c,b as m}from"./chunk-GTNBSMZR.js";var f={name:"cat",summary:"concatenate files and print on the standard output",usage:"cat [OPTION]... [FILE]...",options:["-n, --number number all output lines"," --help display this help and exit"]},b={number:{short:"n",long:"number",type:"boolean"}},N={name:"cat",async execute(t,o){if(m(t))return c(f);let e=p("cat",t,b);if(!e.ok)return e.error;let r=e.result.flags.number,a=e.result.positional,s=await d(o,a,{cmdName:"cat",allowStdinMarker:!0,stopOnError:!1}),n="",l=1;for(let{content:i}of s.files)if(r){let u=g(i,l);n+=u.content,l=u.nextLineNumber}else n+=i;return{stdout:n,stderr:s.stderr,exitCode:s.exitCode}}};function g(t,o){let e=t.split(`
|
|
3
|
-
`),r=t.endsWith(`
|
|
4
|
-
`),a=r?e.slice(0,-1):e;return{content:a.map((n,l)=>`${String(o+l).padStart(6," ")} ${n}`).join(`
|
|
5
|
-
`)+(r?`
|
|
6
|
-
`:""),nextLineNumber:o+a.length}}var F={name:"cat",flags:[{flag:"-n",type:"boolean"},{flag:"-A",type:"boolean"},{flag:"-b",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-e",type:"boolean"},{flag:"-t",type:"boolean"}],stdinType:"text",needsFiles:!0};export{N as a,F as b};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as C}from"./chunk-JBABAK44.js";import{a as u,b as m}from"./chunk-GTNBSMZR.js";var S={name:"tr",summary:"translate or delete characters",usage:"tr [OPTION]... SET1 [SET2]",options:["-c, -C, --complement use the complement of SET1","-d, --delete delete characters in SET1","-s, --squeeze-repeats squeeze repeated characters"," --help display this help and exit"],description:`SET syntax:
|
|
3
|
-
a-z character range
|
|
4
|
-
[:alnum:] all letters and digits
|
|
5
|
-
[:alpha:] all letters
|
|
6
|
-
[:digit:] all digits
|
|
7
|
-
[:lower:] all lowercase letters
|
|
8
|
-
[:upper:] all uppercase letters
|
|
9
|
-
[:space:] all whitespace
|
|
10
|
-
[:blank:] horizontal whitespace
|
|
11
|
-
[:punct:] all punctuation
|
|
12
|
-
[:print:] all printable characters
|
|
13
|
-
[:graph:] all printable characters except space
|
|
14
|
-
[:cntrl:] all control characters
|
|
15
|
-
[:xdigit:] all hexadecimal digits
|
|
16
|
-
\\n, \\t, \\r escape sequences`},x=new Map([["[:alnum:]","ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"],["[:alpha:]","ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"],["[:blank:]"," "],["[:cntrl:]",Array.from({length:32},(r,o)=>String.fromCharCode(o)).join("").concat("\x7F")],["[:digit:]","0123456789"],["[:graph:]",Array.from({length:94},(r,o)=>String.fromCharCode(33+o)).join("")],["[:lower:]","abcdefghijklmnopqrstuvwxyz"],["[:print:]",Array.from({length:95},(r,o)=>String.fromCharCode(32+o)).join("")],["[:punct:]","!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"],["[:space:]",`
|
|
17
|
-
\r\f\v`],["[:upper:]","ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["[:xdigit:]","0123456789ABCDEFabcdef"]]);function y(r){let o="",e=0;for(;e<r.length;){if(r[e]==="["&&r[e+1]===":"){let l=!1;for(let[c,a]of x)if(r.slice(e).startsWith(c)){o+=a,e+=c.length,l=!0;break}if(l)continue}if(r[e]==="\\"&&e+1<r.length){let l=r[e+1];l==="n"?o+=`
|
|
18
|
-
`:l==="t"?o+=" ":l==="r"?o+="\r":o+=l,e+=2;continue}if(e+2<r.length&&r[e+1]==="-"){let l=r.charCodeAt(e),c=r.charCodeAt(e+2);if(c-l>65536)throw new Error(`tr: character range too large: '${r[e]}-${r[e+2]}'`);for(let a=l;a<=c;a++)o+=String.fromCharCode(a);e+=3;continue}o+=r[e],e++}return o}var b={complement:{short:"c",long:"complement",type:"boolean"},complementUpper:{short:"C",type:"boolean"},delete:{short:"d",long:"delete",type:"boolean"},squeeze:{short:"s",long:"squeeze-repeats",type:"boolean"}},A={name:"tr",async execute(r,o){if(m(r))return u(S);let e=C("tr",r,b);if(!e.ok)return e.error;let l=e.result.flags.complement||e.result.flags.complementUpper,c=e.result.flags.delete,a=e.result.flags.squeeze,p=e.result.positional;if(p.length<1)return{stdout:"",stderr:`tr: missing operand
|
|
19
|
-
`,exitCode:1};if(!c&&!a&&p.length<2)return{stdout:"",stderr:`tr: missing operand after SET1
|
|
20
|
-
`,exitCode:1};let d,s;try{d=y(p[0]),s=p.length>1?y(p[1]):""}catch(n){return{stdout:"",stderr:`${n.message}
|
|
21
|
-
`,exitCode:1}}let h=o.stdin,g=n=>{let t=d.includes(n);return l?!t:t},i="";if(c)for(let n of h)g(n)||(i+=n);else if(a&&p.length===1){let n="";for(let t of h)g(t)&&t===n||(i+=t,n=t)}else{if(l){let n=s.length>0?s[s.length-1]:"";for(let t of h)d.includes(t)?i+=t:i+=n}else{let n=new Map;for(let t=0;t<d.length;t++){let f=t<s.length?s[t]:s[s.length-1];n.set(d[t],f)}for(let t of h)i+=n.get(t)??t}if(a){let n="",t="";for(let f of i)s.includes(f)&&f===t||(n+=f,t=f);i=n}}return{stdout:i,stderr:"",exitCode:0}}},E={name:"tr",flags:[{flag:"-c",type:"boolean"},{flag:"-C",type:"boolean"},{flag:"-d",type:"boolean"},{flag:"-s",type:"boolean"}],stdinType:"text",needsArgs:!0};export{A as a,E as b};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{a as O,b as J}from"./chunk-EPIOK4SY.js";import{a as N}from"./chunk-5WFYIUU2.js";import{k as x}from"./chunk-6KZRLMG3.js";import{a as C,b as E,c as q}from"./chunk-GTNBSMZR.js";function I(s){let r=[],t=0,i=s.length;for(;t<i;){for(;t<i&&/\s/.test(s[t]);)t++;if(t>=i)break;let u=t,n=s[t];if(n==="{"||n==="["){let o=n,l=n==="{"?"}":"]",c=1,p=!1,d=!1;for(t++;t<i&&c>0;){let h=s[t];d?d=!1:h==="\\"?d=!0:h==='"'?p=!p:p||(h===o?c++:h===l&&c--),t++}if(c!==0)throw new Error(`Unexpected end of JSON input at position ${t} (unclosed ${o})`);r.push(JSON.parse(s.slice(u,t)))}else if(n==='"'){let o=!1;for(t++;t<i;){let l=s[t];if(o)o=!1;else if(l==="\\")o=!0;else if(l==='"'){t++;break}t++}r.push(JSON.parse(s.slice(u,t)))}else if(n==="-"||n>="0"&&n<="9"){for(;t<i&&/[\d.eE+-]/.test(s[t]);)t++;r.push(JSON.parse(s.slice(u,t)))}else if(s.slice(t,t+4)==="true")r.push(!0),t+=4;else if(s.slice(t,t+5)==="false")r.push(!1),t+=5;else if(s.slice(t,t+4)==="null")r.push(null),t+=4;else{let o=s.slice(t,t+10);throw new Error(`Invalid JSON at position ${u}: unexpected '${o.split(/\s/)[0]}'`)}}return r}var A={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 j(s,r,t,i,u,n=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 o=u?" ":" ";if(Array.isArray(s))return s.length===0?"[]":r?`[${s.map(c=>j(c,!0,!1,i,u)).join(",")}]`:`[
|
|
3
|
-
${s.map(c=>o.repeat(n+1)+j(c,!1,!1,i,u,n+1)).join(`,
|
|
4
|
-
`)}
|
|
5
|
-
${o.repeat(n)}]`;if(typeof s=="object"){let l=Object.keys(s);return i&&(l=l.sort()),l.length===0?"{}":r?`{${l.map(p=>`${JSON.stringify(p)}:${j(s[p],!0,!1,i,u)}`).join(",")}}`:`{
|
|
6
|
-
${l.map(p=>{let d=j(s[p],!1,!1,i,u,n+1);return`${o.repeat(n+1)}${JSON.stringify(p)}: ${d}`}).join(`,
|
|
7
|
-
`)}
|
|
8
|
-
${o.repeat(n)}}`}return String(s)}var P={name:"jq",async execute(s,r){if(E(s))return C(A);let t=!1,i=!1,u=!1,n=!1,o=!1,l=!1,c=!1,p=!1,d=".",h=!1,g=[];for(let a=0;a<s.length;a++){let e=s[a];if(e==="-r"||e==="--raw-output")t=!0;else if(e==="-c"||e==="--compact-output")i=!0;else if(e==="-e"||e==="--exit-status")u=!0;else if(e==="-s"||e==="--slurp")n=!0;else if(e==="-n"||e==="--null-input")o=!0;else if(e==="-j"||e==="--join-output")l=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")c=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")p=!0;else if(e==="-")g.push("-");else{if(e.startsWith("--"))return q("jq",e);if(e.startsWith("-")){for(let f of e.slice(1))if(f==="r")t=!0;else if(f==="c")i=!0;else if(f==="e")u=!0;else if(f==="s")n=!0;else if(f==="n")o=!0;else if(f==="j")l=!0;else if(f!=="a"){if(f==="S")c=!0;else if(f!=="C"){if(f!=="M")return q("jq",`-${f}`)}}}else h?g.push(e):(d=e,h=!0)}}}}let y=[];if(!o)if(g.length===0||g.length===1&&g[0]==="-")y.push({source:"stdin",content:r.stdin});else{let a=await N(r,g,{cmdName:"jq",stopOnError:!0});if(a.exitCode!==0)return{stdout:"",stderr:a.stderr,exitCode:2};y=a.files.map(e=>({source:e.filename||"stdin",content:e.content}))}try{let a=J(d),e=[],f={limits:r.limits?{maxIterations:r.limits.maxJqIterations}:void 0,env:r.env,coverage:r.coverage};if(o)e=O(null,a,f);else if(n){let m=[];for(let{content:w}of y){let b=w.trim();b&&m.push(...I(b))}e=O(m,a,f)}else for(let{content:m}of y){let w=m.trim();if(!w)continue;let b=I(w);for(let z of b)e.push(...O(z,a,f))}let k=e.map(m=>j(m,i,t,c,p)),F=l?"":`
|
|
9
|
-
`,S=k.join(F),$=r.limits?.maxStringLength;if($!==void 0&&$>0&&S.length>$)throw new x(`jq: output size limit exceeded (${$} bytes)`,"string_length");let L=u&&(e.length===0||e.every(m=>m==null||m===!1))?1:0;return{stdout:S?l?S:`${S}
|
|
10
|
-
`:"",stderr:"",exitCode:L}}catch(a){if(a instanceof x)return{stdout:"",stderr:`jq: ${a.message}
|
|
11
|
-
`,exitCode:x.EXIT_CODE};let e=a.message;return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
|
|
12
|
-
`,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
|
|
13
|
-
`,exitCode:5}}}},U={name:"jq",flags:[{flag:"-r",type:"boolean"},{flag:"-c",type:"boolean"},{flag:"-e",type:"boolean"},{flag:"-s",type:"boolean"},{flag:"-n",type:"boolean"},{flag:"-j",type:"boolean"},{flag:"-S",type:"boolean"},{flag:"--tab",type:"boolean"}],stdinType:"json",needsArgs:!0};export{P as a,U as b};
|