just-bash 2.12.5 → 2.12.6

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.
Files changed (121) hide show
  1. package/dist/banned-patterns-test.d.ts +0 -7
  2. package/dist/bin/chunks/{awk2-4MK3F3NZ.js → awk2-EB5SCHVW.js} +1 -1
  3. package/dist/bin/{shell/chunks/chunk-ZRRNCS7N.js → chunks/chunk-5MUD3WB2.js} +1 -1
  4. package/dist/bin/chunks/{chunk-EMSJEY2U.js → chunk-BBRVF6XE.js} +1 -1
  5. package/dist/bin/chunks/chunk-DHFZMFUW.js +36 -0
  6. package/dist/bin/{shell/chunks/chunk-5ATRLST6.js → chunks/chunk-IRCLOW32.js} +1 -1
  7. package/dist/bin/{shell/chunks/chunk-UT6LUTWP.js → chunks/chunk-JX6YLHDX.js} +1 -1
  8. package/dist/bin/chunks/chunk-NTKUVXEL.js +5 -0
  9. package/dist/bin/chunks/{chunk-RDGXTKIB.js → chunk-OLN6BSO3.js} +1 -1
  10. package/dist/bin/chunks/chunk-PIBXJ3VX.js +13 -0
  11. package/dist/bin/chunks/chunk-PLKGKTIS.js +6 -0
  12. package/dist/bin/{shell/chunks/chunk-WWVVJW3F.js → chunks/chunk-QTII62YM.js} +1 -1
  13. package/dist/bin/chunks/{chunk-RS2PRILS.js → chunk-ROMKUVHI.js} +1 -1
  14. package/dist/bin/chunks/{chunk-2HDH5VPF.js → chunk-VCKKRS7V.js} +1 -1
  15. package/dist/bin/chunks/chunk-ZJGIBTWD.js +2 -0
  16. package/dist/bin/{shell/chunks/chunk-6W7JTG6A.js → chunks/chunk-ZNPXCE5B.js} +99 -99
  17. package/dist/bin/{shell/chunks/curl-GIQ5S66Y.js → chunks/curl-3GMIPMCI.js} +1 -1
  18. package/dist/bin/{shell/chunks/flag-coverage-NDF6MQAO.js → chunks/flag-coverage-7GOZYXJT.js} +1 -1
  19. package/dist/bin/{shell/chunks/jq-F7FJ46VM.js → chunks/jq-P457LMHU.js} +1 -1
  20. package/dist/bin/chunks/{python3-QBGIYRFR.js → python3-45TMCI4M.js} +7 -7
  21. package/dist/bin/{shell/chunks/sed-ENUQOCBB.js → chunks/sed-UV2LTNVK.js} +1 -1
  22. package/dist/bin/chunks/sleep-3WHM7JMW.js +2 -0
  23. package/dist/bin/{shell/chunks/sqlite3-4SBQACEE.js → chunks/sqlite3-B3P3OMPI.js} +1 -1
  24. package/dist/bin/chunks/tar-SO3XDDIW.js +2 -0
  25. package/dist/bin/chunks/timeout-BYB3L2JA.js +2 -0
  26. package/dist/bin/chunks/worker.js +155 -14
  27. package/dist/bin/chunks/xan-FZB7FHX3.js +2 -0
  28. package/dist/bin/chunks/yq-H7D2U3HS.js +2 -0
  29. package/dist/bin/just-bash.js +1 -1
  30. package/dist/bin/shell/chunks/{awk2-4MK3F3NZ.js → awk2-EB5SCHVW.js} +1 -1
  31. package/dist/bin/{chunks/chunk-ZRRNCS7N.js → shell/chunks/chunk-5MUD3WB2.js} +1 -1
  32. package/dist/bin/shell/chunks/{chunk-EMSJEY2U.js → chunk-BBRVF6XE.js} +1 -1
  33. package/dist/bin/shell/chunks/chunk-DHFZMFUW.js +36 -0
  34. package/dist/bin/{chunks/chunk-5ATRLST6.js → shell/chunks/chunk-IRCLOW32.js} +1 -1
  35. package/dist/bin/{chunks/chunk-UT6LUTWP.js → shell/chunks/chunk-JX6YLHDX.js} +1 -1
  36. package/dist/bin/shell/chunks/chunk-NTKUVXEL.js +5 -0
  37. package/dist/bin/shell/chunks/{chunk-RDGXTKIB.js → chunk-OLN6BSO3.js} +1 -1
  38. package/dist/bin/shell/chunks/chunk-PIBXJ3VX.js +13 -0
  39. package/dist/bin/shell/chunks/chunk-PLKGKTIS.js +6 -0
  40. package/dist/bin/{chunks/chunk-WWVVJW3F.js → shell/chunks/chunk-QTII62YM.js} +1 -1
  41. package/dist/bin/shell/chunks/{chunk-RS2PRILS.js → chunk-ROMKUVHI.js} +1 -1
  42. package/dist/bin/shell/chunks/{chunk-2HDH5VPF.js → chunk-VCKKRS7V.js} +1 -1
  43. package/dist/bin/shell/chunks/chunk-ZJGIBTWD.js +2 -0
  44. package/dist/bin/{chunks/chunk-6W7JTG6A.js → shell/chunks/chunk-ZNPXCE5B.js} +99 -99
  45. package/dist/bin/{chunks/curl-GIQ5S66Y.js → shell/chunks/curl-3GMIPMCI.js} +1 -1
  46. package/dist/bin/{chunks/flag-coverage-NDF6MQAO.js → shell/chunks/flag-coverage-7GOZYXJT.js} +1 -1
  47. package/dist/bin/{chunks/jq-F7FJ46VM.js → shell/chunks/jq-P457LMHU.js} +1 -1
  48. package/dist/bin/shell/chunks/{python3-XN7O5X3A.js → python3-IV3DBMHM.js} +7 -7
  49. package/dist/bin/{chunks/sed-ENUQOCBB.js → shell/chunks/sed-UV2LTNVK.js} +1 -1
  50. package/dist/bin/shell/chunks/sleep-3WHM7JMW.js +2 -0
  51. package/dist/bin/{chunks/sqlite3-4SBQACEE.js → shell/chunks/sqlite3-B3P3OMPI.js} +1 -1
  52. package/dist/bin/shell/chunks/tar-SO3XDDIW.js +2 -0
  53. package/dist/bin/shell/chunks/timeout-BYB3L2JA.js +2 -0
  54. package/dist/bin/shell/chunks/xan-FZB7FHX3.js +2 -0
  55. package/dist/bin/shell/chunks/yq-H7D2U3HS.js +2 -0
  56. package/dist/bin/shell/shell.js +1 -1
  57. package/dist/bundle/browser.js +503 -503
  58. package/dist/bundle/chunks/{awk2-ID6QVUYU.js → awk2-VPBKDCSO.js} +1 -1
  59. package/dist/bundle/chunks/{chunk-CBAJ47B3.js → chunk-4YPFHVJJ.js} +1 -1
  60. package/dist/bundle/chunks/{chunk-3ZBKQKTX.js → chunk-6HBBXB3L.js} +1 -1
  61. package/dist/bundle/chunks/chunk-72EQZSVH.js +4 -0
  62. package/dist/bundle/chunks/{chunk-SJ5LXPUH.js → chunk-7YDOWJ75.js} +1 -1
  63. package/dist/bundle/chunks/chunk-AUD37QB3.js +35 -0
  64. package/dist/bundle/chunks/{chunk-TVHAURH5.js → chunk-BED5HSP2.js} +1 -1
  65. package/dist/bundle/chunks/{chunk-3J4BCKUH.js → chunk-C7ZTXK5C.js} +99 -99
  66. package/dist/bundle/chunks/chunk-DZZS6SJP.js +1 -0
  67. package/dist/bundle/chunks/chunk-KZ7BI7TV.js +5 -0
  68. package/dist/bundle/chunks/chunk-U5FWK6IA.js +12 -0
  69. package/dist/bundle/chunks/{chunk-HOFSUCIB.js → chunk-VBF2GWEM.js} +1 -1
  70. package/dist/bundle/chunks/{chunk-AYQ5FKKK.js → chunk-VSWTMNI3.js} +1 -1
  71. package/dist/bundle/chunks/{chunk-L75XCEQX.js → chunk-X36DXRVC.js} +1 -1
  72. package/dist/bundle/chunks/{chunk-2OZNLYX4.js → chunk-X3CVFNQZ.js} +1 -1
  73. package/dist/bundle/chunks/{curl-743M564K.js → curl-KM2ZAUR6.js} +1 -1
  74. package/dist/bundle/chunks/{flag-coverage-4M54QHNZ.js → flag-coverage-NT32EG6Q.js} +1 -1
  75. package/dist/bundle/chunks/{jq-5FRYP6YP.js → jq-NLRWI2Q6.js} +1 -1
  76. package/dist/bundle/chunks/{python3-WANWDR22.js → python3-G2ZUJAQL.js} +7 -7
  77. package/dist/bundle/chunks/{sed-TS7M7I25.js → sed-2BILOGNL.js} +1 -1
  78. package/dist/bundle/chunks/sleep-IUBP5GMH.js +1 -0
  79. package/dist/bundle/chunks/{sqlite3-IH5QMEIK.js → sqlite3-VEDNWJL6.js} +1 -1
  80. package/dist/bundle/chunks/tar-LKO7DKAK.js +1 -0
  81. package/dist/bundle/chunks/timeout-TL4Q5YKZ.js +1 -0
  82. package/dist/bundle/chunks/worker.js +155 -14
  83. package/dist/bundle/chunks/xan-KSDYKKEK.js +1 -0
  84. package/dist/bundle/chunks/yq-HIQ4WMDY.js +1 -0
  85. package/dist/bundle/index.cjs +717 -717
  86. package/dist/bundle/index.js +1 -1
  87. package/dist/commands/python3/worker.d.ts +1 -0
  88. package/dist/commands/query-engine/safe-object.d.ts +13 -0
  89. package/dist/commands/sqlite3/worker.d.ts +1 -0
  90. package/package.json +34 -34
  91. package/vendor/cpython-emscripten/python.wasm +0 -0
  92. package/dist/bin/chunks/chunk-DERQIX2O.js +0 -36
  93. package/dist/bin/chunks/chunk-LWKIHJ5L.js +0 -13
  94. package/dist/bin/chunks/chunk-Q5MYEU7X.js +0 -5
  95. package/dist/bin/chunks/chunk-UYBH3FNE.js +0 -2
  96. package/dist/bin/chunks/chunk-W752QGNZ.js +0 -6
  97. package/dist/bin/chunks/sleep-5T34UFNF.js +0 -2
  98. package/dist/bin/chunks/tar-3UIZ4IRM.js +0 -2
  99. package/dist/bin/chunks/timeout-7ECKKPNP.js +0 -2
  100. package/dist/bin/chunks/xan-5QTBTP4U.js +0 -2
  101. package/dist/bin/chunks/yq-O5RSLLA3.js +0 -2
  102. package/dist/bin/shell/chunks/chunk-DERQIX2O.js +0 -36
  103. package/dist/bin/shell/chunks/chunk-LWKIHJ5L.js +0 -13
  104. package/dist/bin/shell/chunks/chunk-Q5MYEU7X.js +0 -5
  105. package/dist/bin/shell/chunks/chunk-UYBH3FNE.js +0 -2
  106. package/dist/bin/shell/chunks/chunk-W752QGNZ.js +0 -6
  107. package/dist/bin/shell/chunks/sleep-5T34UFNF.js +0 -2
  108. package/dist/bin/shell/chunks/tar-3UIZ4IRM.js +0 -2
  109. package/dist/bin/shell/chunks/timeout-7ECKKPNP.js +0 -2
  110. package/dist/bin/shell/chunks/xan-5QTBTP4U.js +0 -2
  111. package/dist/bin/shell/chunks/yq-O5RSLLA3.js +0 -2
  112. package/dist/bundle/chunks/chunk-7MKBHGLS.js +0 -1
  113. package/dist/bundle/chunks/chunk-C764MECG.js +0 -35
  114. package/dist/bundle/chunks/chunk-FD7SFJNJ.js +0 -4
  115. package/dist/bundle/chunks/chunk-QI4EPYAT.js +0 -5
  116. package/dist/bundle/chunks/chunk-R5XRHEZH.js +0 -12
  117. package/dist/bundle/chunks/sleep-RRZXXEW2.js +0 -1
  118. package/dist/bundle/chunks/tar-JCULQ5J2.js +0 -1
  119. package/dist/bundle/chunks/timeout-DNGO7OHT.js +0 -1
  120. package/dist/bundle/chunks/xan-LAW2EMOM.js +0 -1
  121. package/dist/bundle/chunks/yq-MFJEXB7R.js +0 -1
@@ -1,8 +1 @@
1
- /**
2
- * This file exists solely to test that the banned-patterns lint script
3
- * correctly detects all patterns and that ignore comments work properly.
4
- *
5
- * DO NOT import or use this file anywhere - it's only for lint verification.
6
- * Each pattern below would be flagged without its corresponding ignore comment.
7
- */
8
1
  export {};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a,b}from"./chunk-RDGXTKIB.js";import"./chunk-4PRVMER6.js";import"./chunk-ZRRNCS7N.js";import"./chunk-Q5MYEU7X.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{a as awkCommand2,b as flagsForFuzzing};
2
+ import{a,b}from"./chunk-OLN6BSO3.js";import"./chunk-4PRVMER6.js";import"./chunk-5MUD3WB2.js";import"./chunk-NTKUVXEL.js";import"./chunk-SE4C7FJY.js";import"./chunk-6KZRLMG3.js";import"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";export{a as awkCommand2,b as flagsForFuzzing};
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as s,b as i}from"./chunk-Q5MYEU7X.js";function a(t,e,n){if(!t||i.isInSandboxedContext())return;let r=`${e} ${n} attempted outside defense context`;throw new s(r,{timestamp:Date.now(),type:"missing_defense_context",message:r,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:i.getCurrentExecutionId()})}async function x(t,e,n,r){a(t,e,`${n} (pre-await)`);let o=await r();return a(t,e,`${n} (post-await)`),o}function d(t,e,n,r){let o=((...c)=>(a(t,e,n),r(...c)));return t?i.bindCurrentContext(o):o}export{a,x as b,d as c};
2
+ import{a as s,b as i}from"./chunk-NTKUVXEL.js";function a(t,e,n){if(!t||i.isInSandboxedContext())return;let r=`${e} ${n} attempted outside defense context`;throw new s(r,{timestamp:Date.now(),type:"missing_defense_context",message:r,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:i.getCurrentExecutionId()})}async function x(t,e,n,r){a(t,e,`${n} (pre-await)`);let o=await r();return a(t,e,`${n} (post-await)`),o}function d(t,e,n,r){let o=((...c)=>(a(t,e,n),r(...c)));return t?i.bindCurrentContext(o):o}export{a,x as b,d as c};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as F,b,c as M,d as qe,e as w,f as v,g as X,h as Y}from"./chunk-GZHFXDDO.js";import{a as et}from"./chunk-QSDVMMYI.js";import{a as $}from"./chunk-W752QGNZ.js";import{d as G}from"./chunk-UYBH3FNE.js";import{a as H}from"./chunk-SE4C7FJY.js";import{a as We}from"./chunk-5WFYIUU2.js";import{a as D,b as K}from"./chunk-GTNBSMZR.js";import{b as Ue,d as Be,e as Ze,f as Qe}from"./chunk-KGOUQS5A.js";var q,_e=Ue(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
2
+ import{a as F,b,c as M,d as qe,e as w,f as v,g as X,h as Y}from"./chunk-GZHFXDDO.js";import{a as et}from"./chunk-QSDVMMYI.js";import{a as $}from"./chunk-PLKGKTIS.js";import{f as G}from"./chunk-ZJGIBTWD.js";import{a as H}from"./chunk-SE4C7FJY.js";import{a as We}from"./chunk-5WFYIUU2.js";import{a as D,b as K}from"./chunk-GTNBSMZR.js";import{b as Ue,d as Be,e as Ze,f as Qe}from"./chunk-KGOUQS5A.js";var q,_e=Ue(()=>{"use strict";q=class{input;pos=0;tokens=[];constructor(n){this.input=n}tokenize(){for(;this.pos<this.input.length&&(this.skipWhitespace(),!(this.pos>=this.input.length));){let n=this.nextToken();n&&this.tokens.push(n)}return this.tokens.push({type:"eof",value:"",pos:this.pos}),this.tokens}skipWhitespace(){for(;this.pos<this.input.length;){let n=this.input[this.pos];if(n===" "||n===" "||n===`
3
3
  `||n==="\r")this.pos++;else if(n==="#")for(;this.pos<this.input.length&&this.input[this.pos]!==`
4
4
  `;)this.pos++;else break}}nextToken(){let n=this.pos,t=this.input[this.pos];if(t>="0"&&t<="9")return this.readNumber();if(t==='"'||t==="'"||t==="`")return this.readString(t);if(t==="b"&&this.pos+1<this.input.length){let o=this.input[this.pos+1];if(o==='"'||o==="'"||o==="`")return this.pos++,this.readString(o)}if(t==="/"){let o=this.tokens[this.tokens.length-1];return o&&(o.type==="int"||o.type==="float"||o.type==="string"||o.type==="ident"||o.type===")"||o.type==="]")?this.input[this.pos+1]==="/"?(this.pos+=2,{type:"//",value:"//",pos:n}):(this.pos++,{type:"/",value:"/",pos:n}):this.readRegex()}if(this.match("not in"))return{type:"not in",value:"not in",pos:n};if(this.match("=>"))return{type:"=>",value:"=>",pos:n};if(this.match("**"))return{type:"**",value:"**",pos:n};if(this.match("++"))return{type:"++",value:"++",pos:n};if(this.match("//"))return{type:"//",value:"//",pos:n};if(this.match("=="))return{type:"==",value:"==",pos:n};if(this.match("!="))return{type:"!=",value:"!=",pos:n};if(this.match("<="))return{type:"<=",value:"<=",pos:n};if(this.match(">="))return{type:">=",value:">=",pos:n};if(this.match("&&"))return{type:"&&",value:"&&",pos:n};if(this.match("||"))return{type:"||",value:"||",pos:n};let r=new Map([["(","("],[")",")"],["[","["],["]","]"],["{","{"],["}","}"],[",",","],[":",":"],[";",";"],["+","+"],["-","-"],["*","*"],["%","%"],["<","<"],[">",">"],["!","!"],[".","."],["|","|"],["=","="]]).get(t);if(r!==void 0)return this.pos++,{type:r,value:t,pos:n};if(this.isIdentStart(t))return this.readIdentifier();throw new Error(`Unexpected character '${t}' at position ${this.pos}`)}match(n){if(this.input.slice(this.pos,this.pos+n.length)===n){if(/^[a-zA-Z]/.test(n)){let t=this.input[this.pos+n.length];if(t&&this.isIdentChar(t))return!1}return this.pos+=n.length,!0}return!1}isIdentStart(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}isIdentChar(n){return this.isIdentStart(n)||n>="0"&&n<="9"}readNumber(){let n=this.pos,t=!1,s=!1;for(;this.pos<this.input.length;){let o=this.input[this.pos];if(o>="0"&&o<="9")this.pos++;else if(o==="_")this.pos++;else if(o==="."&&!t&&!s)t=!0,this.pos++;else if((o==="e"||o==="E")&&!s)s=!0,t=!0,this.pos++,this.pos<this.input.length&&(this.input[this.pos]==="+"||this.input[this.pos]==="-")&&this.pos++;else break}let r=this.input.slice(n,this.pos).replace(/_/g,"");return{type:t?"float":"int",value:r,pos:n}}readString(n){let t=this.pos;this.pos++;let s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r===n)return this.pos++,{type:"string",value:s,pos:t};if(r==="\\"){if(this.pos++,this.pos<this.input.length){let o=this.input[this.pos];switch(o){case"n":s+=`
5
5
  `;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${t}`)}readRegex(){let n=this.pos;this.pos++;let t="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:t+(s?`/${s}`:""),pos:n}}r==="\\"?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${n}`)}readIdentifier(){let n=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let t=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(t=!0,this.pos++);let s=this.input.slice(n,t?this.pos-1:this.pos);t&&(s+="?");let r=new Map([["true","true"],["false","false"],["null","null"],["and","and"],["or","or"],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["in","in"],["as","as"],["_","_"]]),o=s.replace(/\?$/,""),i=r.get(o);return i!==void 0&&!t?{type:i,value:o,pos:n}:{type:"ident",value:s,pos:n}}}});var He={};Be(He,{parseMoonblade:()=>_,parseNamedExpressions:()=>V});function V(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},i=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){i();continue}let h=[],u=0,p=r;for(;o().type!=="eof";){let a=o();if((a.type===","||a.type==="as")&&u===0)break;(a.type==="("||a.type==="["||a.type==="{")&&u++,(a.type===")"||a.type==="]"||a.type==="}")&&u--,h.push(i())}h.push({type:"eof",value:"",pos:0});let f=new J(h).parse(),c;if(o().type==="as")if(i(),o().type==="("){i();let a=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(a.push(o().value),i()),o().type===","&&i();o().type===")"&&i(),c=a}else if(o().type==="ident"||o().type==="string")c=o().value,i();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),f.type==="identifier"&&(c=f.name);n.push({expr:f,name:c})}return n}function _(e){let t=new q(e).tokenize();return new J(t).parse()}var R,J,U=Ue(()=>{"use strict";_e();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},J=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<n)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let n=this.peek();switch(n.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(n.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(n.value)};case"string":return this.advance(),{type:"string",value:n.value};case"regex":{this.advance();let t=n.value.split("/"),s=t.length>1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=[];if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=this.peek().value;if(this.advance(),this.peek().type===","||this.peek().type===")"){for(t.push(r);this.peek().type===","&&(this.advance(),this.peek().type==="ident");)t.push(this.peek().value),this.advance();if(this.peek().type===")"&&(this.advance(),this.peek().type==="=>")){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:t,body:o},t)}this.pos-=t.length*2,t.length>1&&(this.pos=this.pos)}this.pos--}let s=this.parseExpr(0);return this.expect(")"),this.peek().type,s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,i=this.pos+1;i<this.tokens.length&&this.tokens[i].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);t.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:n.toLowerCase(),args:t}}parseList(){this.expect("[");let n=[];if(this.peek().type!=="]")do n.length>0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let i=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:n},{expr:i}]}}if(s.type==="|"){this.advance();let i=this.parseExpr(t);return this.handlePipe(n,i)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});U();function E(e,n){return n.length===0?k(e,[]):n.length===1?{type:"Pipe",left:n[0],right:k(e,[])}:{type:"Pipe",left:n[0],right:k(e,n.slice(1))}}var B={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>k("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?k("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?k("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?k("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>k("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>k("select",e),empty:()=>k("empty",[]),count:()=>k("length",[]),sum:e=>e.length===0?k("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:k("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?k("tonumber",[]):k("tonumber",e),tostring:e=>e.length===0?k("tostring",[]):k("tostring",e),if:e=>Je(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return Je(s,n,t.length===1?t[0]:B.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>k("now",[]),fmt:e=>k("tostring",e),format:e=>k("tostring",e)};function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function k(e,n){return{type:"Call",name:e,args:n}}var tt="then";function Je(e,n,t){let s={type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}};return s[tt]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function O(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>O(r.expr,n)),s=Object.hasOwn(B,e.name)?B[e.name]:void 0;return typeof s=="function"?s(t):k(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=O(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:O(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?O(e.start,n):void 0,end:e.end?O(e.end,n):void 0};case"lambda":return O(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function Q(e){let n=[],t=0;for(;t<e.length;){for(;t<e.length&&(e[t]===" "||e[t]===",");)t++;if(t>=e.length)break;let s=t;for(;t<e.length&&/\w/.test(e[t]);)t++;let r=e.slice(s,t);for(;t<e.length&&e[t]===" ";)t++;if(e[t]!=="(")break;t++;let o=1,i=t;for(;t<e.length&&o>0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let h=e.slice(i,t).trim();for(t++;t<e.length&&e[t]===" ";)t++;let u="";if(e.slice(t,t+3).toLowerCase()==="as "){for(t+=3;t<e.length&&e[t]===" ";)t++;let p=t;for(;t<e.length&&/\w/.test(e[t]);)t++;u=e.slice(p,t)}u||(u=h?`${r}(${h})`:`${r}()`),n.push({func:r,expr:h,alias:u})}return n}function ze(e){return/^\w+$/.test(e)}function Z(e,n,t){let s=O(_(n)),r=$(e,s,t);return r.length>0?r[0]:null}function ee(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(ze(r)?o=e.map(i=>i[r]).filter(i=>i!=null):o=e.map(i=>Z(i,r,t)).filter(i=>i!=null),s){case"count":return ze(r)?o.length:o.filter(i=>!!i).length;case"sum":return o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h))).reduce((h,u)=>h+u,0);case"mean":case"avg":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?i.reduce((h,u)=>h+u,0)/i.length:0}case"min":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.min(...i):null}case"max":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.max(...i):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let i=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(i.length===0)return null;let h=Math.floor(i.length/2);return i.length%2===0?(i[h-1]+i[h])/2:i[h]}case"mode":{let i=new Map;for(let p of o){let l=String(p);i.set(l,(i.get(l)||0)+1)}let h=0,u=null;for(let[p,l]of i)l>h&&(h=l,u=p);return u}case"cardinality":return new Set(o.map(h=>String(h))).size;case"values":return o.map(i=>String(i)).join("|");case"distinct_values":return[...new Set(o.map(h=>String(h)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let i of e)if(!Z(i,r,t))return!1;return!0}case"any":{for(let i of e)if(Z(i,r,t))return!0;return!1}default:return null}}function Ke(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,ee(e,r,t));return s}async function te(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import{a as x,b as w}from"./chunk-JX6YLHDX.js";import{c as b}from"./chunk-5MUD3WB2.js";import{b as j}from"./chunk-NTKUVXEL.js";import{a as m}from"./chunk-SYG3IW7P.js";import{a as q,b as C}from"./chunk-GTNBSMZR.js";import{randomBytes as _}from"node:crypto";import{existsSync as E}from"node:fs";import{dirname as z,join as T}from"node:path";import{fileURLToPath as X}from"node:url";import{Worker as Y}from"node:worker_threads";import G from"sql.js";function V(e,t,r){switch(r.mode){case"list":return B(e,t,r);case"csv":return O(e,t,r);case"json":return I(e,t);case"line":return N(e,t,r);case"column":return R(e,t,r);case"table":return F(e,t,r);case"markdown":return Q(e,t,r);case"tabs":return U(e,t,r);case"box":return W(e,t,r);case"quote":return D(e,t,r);case"html":return H(e,t,r);case"ascii":return J(e,t,r)}}function f(e,t){return e==null?t: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 B(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(r.separator));for(let a of t)n.push(a.map(o=>f(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function O(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(L).join(","));for(let a of t)n.push(a.map(o=>L(f(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
3
+ `)}
4
+ `:""}function L(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
5
+ `)?`"${e.replace(/"/g,'""')}"`:e}function A(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function P(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):A(e):JSON.stringify(e)}function I(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,i)=>`${JSON.stringify(o)}:${P(n[i])}`).join(",")}}`).join(`,
6
+ `)}]
7
+ `}function N(e,t,r){if(e.length===0||t.length===0)return"";let n=Math.max(5,...e.map(o=>o.length)),a=[];for(let o of t)for(let i=0;i<e.length;i++){let s=e[i].padStart(n);a.push(`${s} = ${f(o[i],r.nullValue)}`)}return`${a.join(`
8
+ `)}
9
+ `}function R(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let i=0;i<o.length;i++){let s=f(o[i],r.nullValue).length;s>n[i]&&(n[i]=s)}let a=[];r.header&&(a.push(e.map((o,i)=>o.padEnd(n[i])).join(" ")),a.push(n.map(o=>"-".repeat(o)).join(" ")));for(let o of t)a.push(o.map((i,s)=>f(i,r.nullValue).padEnd(n[s])).join(" "));return a.length>0?`${a.join(`
10
+ `)}
11
+ `:""}function F(e,t,r){if(e.length===0)return"";let n=e.map(i=>i.length);for(let i of t)for(let s=0;s<i.length;s++){let p=f(i[s],r.nullValue).length;p>n[s]&&(n[s]=p)}let a=[],o=`+${n.map(i=>"-".repeat(i+2)).join("+")}+`;a.push(o),r.header&&(a.push(`| ${e.map((i,s)=>i.padEnd(n[s])).join(" | ")} |`),a.push(o));for(let i of t)a.push(`| ${i.map((s,p)=>f(s,r.nullValue).padEnd(n[p])).join(" | ")} |`);return a.push(o),`${a.join(`
12
+ `)}
13
+ `}function Q(e,t,r){if(e.length===0)return"";let n=[];r.header&&(n.push(`| ${e.join(" | ")} |`),n.push(`|${e.map(()=>"---").join("|")}|`));for(let a of t)n.push(`| ${a.map(o=>f(o,r.nullValue)).join(" | ")} |`);return n.length>0?`${n.join(`
14
+ `)}
15
+ `:""}function U(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(" "));for(let a of t)n.push(a.map(o=>f(o,r.nullValue)).join(" "));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function W(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let i=0;i<o.length;i++){let s=f(o[i],r.nullValue).length;s>n[i]&&(n[i]=s)}let a=[];a.push(`\u250C${n.map(o=>"\u2500".repeat(o+2)).join("\u252C")}\u2510`),a.push(`\u2502 ${e.map((o,i)=>o.padEnd(n[i])).join(" \u2502 ")} \u2502`),a.push(`\u251C${n.map(o=>"\u2500".repeat(o+2)).join("\u253C")}\u2524`);for(let o of t)a.push(`\u2502 ${o.map((i,s)=>f(i,r.nullValue).padEnd(n[s])).join(" \u2502 ")} \u2502`);return a.push(`\u2514${n.map(o=>"\u2500".repeat(o+2)).join("\u2534")}\u2518`),`${a.join(`
16
+ `)}
17
+ `}function D(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(a=>`'${a}'`).join(","));for(let a of t)n.push(a.map(o=>o==null?"NULL":typeof o=="number"?Number.isInteger(o)?String(o):A(o):`'${String(o)}'`).join(","));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function H(e,t,r){let n=[];r.header&&e.length>0&&(n.push(`<TR>${e.map(a=>`<TH>${M(a)}</TH>`).join("")}`),n.push("</TR>"));for(let a of t)n.push(`<TR>${a.map(o=>`<TD>${M(f(o,r.nullValue))}</TD>`).join("")}`),n.push("</TR>");return n.length>0?`${n.join(`
18
+ `)}
19
+ `:""}function M(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function J(e,t,r){let o=[];r.header&&e.length>0&&o.push(e.join(""));for(let i of t)o.push(i.map(s=>f(s,r.nullValue)).join(""));return o.length>0?o.join("")+"":""}var K=5e3,Z={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 v(e){let t={mode:"list",header:!1,separator:"|",newline:`
20
+ `,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},r=null,n=null,a=!1,o=!1;for(let i=0;i<e.length;i++){let s=e[i];if(o){r===null?r=s:n===null&&(n=s);continue}if(s==="--")o=!0;else if(s==="-version")a=!0;else if(s==="-list")t.mode="list";else if(s==="-csv")t.mode="csv";else if(s==="-json")t.mode="json";else if(s==="-line")t.mode="line";else if(s==="-column")t.mode="column";else if(s==="-table")t.mode="table";else if(s==="-markdown")t.mode="markdown";else if(s==="-tabs")t.mode="tabs";else if(s==="-box")t.mode="box";else if(s==="-quote")t.mode="quote";else if(s==="-html")t.mode="html";else if(s==="-ascii")t.mode="ascii";else if(s==="-header")t.header=!0;else if(s==="-noheader")t.header=!1;else if(s==="-readonly")t.readonly=!0;else if(s==="-bail")t.bail=!0;else if(s==="-echo")t.echo=!0;else if(s==="-separator"){if(i+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
21
+ `,exitCode:1};t.separator=e[++i]}else if(s==="-newline"){if(i+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
22
+ `,exitCode:1};t.newline=e[++i]}else if(s==="-nullvalue"){if(i+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
23
+ `,exitCode:1};t.nullValue=e[++i]}else if(s==="-cmd"){if(i+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
24
+ `,exitCode:1};t.cmd=e[++i]}else{if(s.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${s.startsWith("--")?s.slice(1):s}
25
+ Use -help for a list of options.
26
+ `,exitCode:1};r===null?r=s:n===null&&(n=s)}}return{options:t,database:r,sql:n,showVersion:a}}async function ee(){let e=await j.runTrustedAsync(()=>G()),t=new e.Database;try{let r=t.exec("SELECT sqlite_version()");return r.length>0&&r[0].values.length>0?String(r[0].values[0][0]):"unknown"}finally{t.close()}}function re(){let e=z(X(import.meta.url)),t=T(e,"../../commands/sqlite3/worker.js");if(E(t))return t;let r=T(e,"worker.js");if(E(r))return r;let n=T(e,"../../../dist/commands/sqlite3/worker.js");if(E(n))return n;throw new Error("sqlite3 worker not found. Run 'pnpm build' to compile the worker.")}var te={createWorker(e,t){return new Y(e,{workerData:t})}};function ne(){return _(16).toString("hex")}function oe(e,t){if(!e||typeof e!="object")return{success:!1,error:"Malformed worker response"};let r=e;return typeof r.protocolToken!="string"||r.protocolToken!==t?{success:!1,error:"Malformed worker response: invalid protocol token"}: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 se(e,t,r){try{let n=re();return await new Promise((a,o)=>{let i=j.runTrusted(()=>te.createWorker(n,e)),s=b(r,"sqlite3","worker timeout callback",()=>{i.terminate(),a({success:!1,error:`Query timeout: execution exceeded ${t}ms limit`})}),c=x(()=>{try{s()}catch(u){let l=u instanceof Error?u.message:String(u);a({success:!1,error:m(l)})}},t),S=b(r,"sqlite3","worker message callback",u=>{w(c),a(oe(u,e.protocolToken))}),$=b(r,"sqlite3","worker error callback",u=>{w(c),o(u)}),y=b(r,"sqlite3","worker exit callback",u=>{w(c),u!==0&&a({success:!1,error:`Worker exited with code ${u}`})}),h=u=>{try{S(u)}catch(l){w(c);let d=l instanceof Error?l.message:String(l);a({success:!1,error:m(d)})}},k=u=>{try{$(u)}catch(l){w(c);let d=l instanceof Error?l.message:String(l);o(new Error(m(d)))}},g=u=>{try{y(u)}catch(l){w(c);let d=l instanceof Error?l.message:String(l);a({success:!1,error:m(d)})}};i.on("message",h),i.on("error",k),i.on("exit",g)})}catch(n){let a=m(n.message);throw new Error(`sqlite3 worker failed to load: ${a}`)}}var Se={name:"sqlite3",async execute(e,t){if(C(e)||e.includes("-help"))return q(Z);let r=v(e);if("exitCode"in r)return r;let{options:n,database:a,sql:o,showVersion:i}=r;if(i)return{stdout:`${await ee()}
27
+ `,stderr:"",exitCode:0};if(!a)return{stdout:"",stderr:`sqlite3: missing database argument
28
+ `,exitCode:1};let s=o||t.stdin.trim();if(n.cmd&&(s=n.cmd+(s?`; ${s}`:"")),!s)return{stdout:"",stderr:`sqlite3: no SQL provided
29
+ `,exitCode:1};let p=a===":memory:",c="",S=null;try{p||(c=t.fs.resolvePath(t.cwd,a),await t.fs.exists(c)&&(S=await t.fs.readFileBuffer(c)))}catch(l){let d=m(l.message);return{stdout:"",stderr:`sqlite3: unable to open database "${a}": ${d}
30
+ `,exitCode:1}}let $=t.limits?.maxSqliteTimeoutMs??K,y={protocolToken:ne(),dbBuffer:S,sql:s,options:{bail:n.bail,echo:n.echo}},h;try{h=await se(y,$,t.requireDefenseContext)}catch(l){return{stdout:"",stderr:`sqlite3: worker error: ${m(l.message)}
31
+ `,exitCode:1}}if(!h.success)return{stdout:"",stderr:`sqlite3: ${m(h.error)}
32
+ `,exitCode:1};let k={mode:n.mode,header:n.header,separator:n.separator,newline:n.newline,nullValue:n.nullValue},g="";n.echo&&(g+=`${s}
33
+ `);let u=!1;for(let l of h.results)if(l.type==="error"){if(n.bail)return{stdout:g,stderr:`Error: ${l.error}
34
+ `,exitCode:1};g+=`Error: ${l.error}
35
+ `,u=!0}else l.columns&&l.rows&&(l.rows.length>0||n.header)&&(g+=V(l.columns,l.rows,k));if(h.hasModifications&&!n.readonly&&!p&&c&&h.dbBuffer)try{await t.fs.writeFile(c,h.dbBuffer)}catch(l){let d=m(l.message);return{stdout:g,stderr:`sqlite3: failed to write database: ${d}
36
+ `,exitCode:1}}return{stdout:g,stderr:"",exitCode:u&&n.bail?1:0}}},$e={name:"sqlite3",flags:[],needsArgs:!0};export{te as a,Se as b,$e as c};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as W,b as U}from"./chunk-ZRRNCS7N.js";import{a as I}from"./chunk-Q5MYEU7X.js";import{a as A}from"./chunk-SE4C7FJY.js";import{k}from"./chunk-6KZRLMG3.js";import{a as L}from"./chunk-SYG3IW7P.js";import{a as ee,b as te,c as P}from"./chunk-GTNBSMZR.js";var z=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 H(i){let e="",t=0,n=!1;for(;t<i.length;){if(i[t]==="["&&!n){if(i[t+1]==="["&&i[t+2]===":"){let s=i.indexOf(":]]",t+3);if(s!==-1){let a=i.slice(t+3,s),r=z.get(a);if(r){e+=`[${r}]`,t=s+3;continue}}}if(i[t+1]==="^"&&i[t+2]==="["&&i[t+3]===":"){let s=i.indexOf(":]]",t+4);if(s!==-1){let a=i.slice(t+4,s),r=z.get(a);if(r){e+=`[^${r}]`,t=s+3;continue}}}e+="[",t++,n=!0,t<i.length&&i[t]==="^"&&(e+="^",t++),t<i.length&&i[t]==="]"&&(e+="\\]",t++);continue}if(n){if(i[t]==="]"){e+="]",t++,n=!1;continue}if(i[t]==="["&&i[t+1]===":"){let s=i.indexOf(":]",t+2);if(s!==-1){let a=i.slice(t+2,s),r=z.get(a);if(r){e+=r,t=s+2;continue}}}if(i[t]==="\\"&&t+1<i.length){e+=i[t]+i[t+1],t+=2;continue}e+=i[t],t++;continue}if(i[t]==="\\"&&t+1<i.length){let s=i[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+=`
2
+ import{a as W,b as U}from"./chunk-5MUD3WB2.js";import{a as I}from"./chunk-NTKUVXEL.js";import{a as A}from"./chunk-SE4C7FJY.js";import{k}from"./chunk-6KZRLMG3.js";import{a as L}from"./chunk-SYG3IW7P.js";import{a as ee,b as te,c as P}from"./chunk-GTNBSMZR.js";var z=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 H(i){let e="",t=0,n=!1;for(;t<i.length;){if(i[t]==="["&&!n){if(i[t+1]==="["&&i[t+2]===":"){let s=i.indexOf(":]]",t+3);if(s!==-1){let a=i.slice(t+3,s),r=z.get(a);if(r){e+=`[${r}]`,t=s+3;continue}}}if(i[t+1]==="^"&&i[t+2]==="["&&i[t+3]===":"){let s=i.indexOf(":]]",t+4);if(s!==-1){let a=i.slice(t+4,s),r=z.get(a);if(r){e+=`[^${r}]`,t=s+3;continue}}}e+="[",t++,n=!0,t<i.length&&i[t]==="^"&&(e+="^",t++),t<i.length&&i[t]==="]"&&(e+="\\]",t++);continue}if(n){if(i[t]==="]"){e+="]",t++,n=!1;continue}if(i[t]==="["&&i[t+1]===":"){let s=i.indexOf(":]",t+2);if(s!==-1){let a=i.slice(t+2,s),r=z.get(a);if(r){e+=r,t=s+2;continue}}}if(i[t]==="\\"&&t+1<i.length){e+=i[t]+i[t+1],t+=2;continue}e+=i[t],t++;continue}if(i[t]==="\\"&&t+1<i.length){let s=i[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
3
  `,t+=2;continue}if(s==="r"){e+="\r",t+=2;continue}e+=i[t]+s,t+=2;continue}if(i[t]==="+"||i[t]==="?"||i[t]==="|"||i[t]==="("||i[t]===")"){e+=`\\${i[t]}`,t++;continue}if(i[t]==="^"&&!(e===""||e.endsWith("("))){e+="\\^",t++;continue}if(i[t]==="$"){let s=t===i.length-1,a=t+2<i.length&&i[t+1]==="\\"&&i[t+2]===")";if(!s&&!a){e+="\\$",t++;continue}}e+=i[t],t++}return e}function V(i){let e="",t=!1;for(let n=0;n<i.length;n++)i[n]==="["&&!t?(t=!0,e+="[",n++,n<i.length&&i[n]==="^"&&(e+="^",n++),n<i.length&&i[n]==="]"&&(e+="]",n++),n--):i[n]==="]"&&t?(t=!1,e+="]"):!t&&i[n]==="{"&&i[n+1]===","?(e+="{0,",n++):e+=i[n];return e}function ne(i){let e="";for(let t=0;t<i.length;t++){let n=i[t],s=n.charCodeAt(0);n==="\\"?e+="\\\\":n===" "?e+="\\t":n===`
4
4
  `?e+=`$
5
5
  `:n==="\r"?e+="\\r":n==="\x07"?e+="\\a":n==="\b"?e+="\\b":n==="\f"?e+="\\f":n==="\v"?e+="\\v":s<32||s>=127?e+=`\\${s.toString(8).padStart(3,"0")}`:e+=n}return`${e}$`}var de=1e4;function se(i,e,t){return{patternSpace:"",holdSpace:"",lineNumber:0,totalLines:i,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:[],rangeStates:t||new Map,linesConsumedInCycle:0}}function pe(i){return typeof i=="object"&&"first"in i&&"step"in i}function me(i){return typeof i=="object"&&"offset"in i}function N(i,e,t,n,s){if(i==="$")return e===t;if(typeof i=="number")return e===i;if(pe(i)){let{first:a,step:r}=i;return r===0?e===a:(e-a)%r===0&&e>=a}if(typeof i=="object"&&"pattern"in i)try{let a=i.pattern;a===""&&s?.lastPattern?a=s.lastPattern:a!==""&&s&&(s.lastPattern=a);let r=V(H(a));return A(r).test(n)}catch{return!1}return!1}function X(i){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(i.start)},${e(i.end)}`}function ge(i,e,t,n,s,a){if(!i||!i.start&&!i.end)return!0;let r=i.start,l=i.end;if(r!==void 0&&l===void 0)return N(r,e,t,n,a);if(r!==void 0&&l!==void 0){let c=typeof r=="object"&&"pattern"in r,f=typeof l=="object"&&"pattern"in l,p=me(l);if(p&&s){let g=X(i),d=s.get(g);if(d||(d={active:!1},s.set(g,d)),d.active){let E=d.startLine||e;return e>=E+l.offset&&(d.active=!1,s.set(g,d)),!0}else return N(r,e,t,n,a)?(d.active=!0,d.startLine=e,s.set(g,d),l.offset===0&&(d.active=!1,s.set(g,d)),!0):!1}if(!c&&!f&&!p){let g=typeof r=="number"?r:r==="$"?t:1,d=typeof l=="number"?l:t;if(g<=d)return e>=g&&e<=d;if(s){let E=X(i),u=s.get(E);return u||(u={active:!1},s.set(E,u)),!u.completed&&e>=g?(u.completed=!0,s.set(E,u),!0):!1}return!1}if(s){let g=X(i),d=s.get(g);if(d||(d={active:!1},s.set(g,d)),d.active)return N(l,e,t,n,a)&&(d.active=!1,typeof r=="number"&&(d.completed=!0),s.set(g,d)),!0;{if(d.completed)return!1;let E=!1;return typeof r=="number"?E=e>=r:E=N(r,e,t,n,a),E?(d.active=!0,d.startLine=e,s.set(g,d),N(l,e,t,n,a)&&(d.active=!1,typeof r=="number"&&(d.completed=!0),s.set(g,d)),!0):!1}}return N(r,e,t,n,a)}return!0}function w(i,e,t,n,s,a){let r=ge(i,e,t,n,s,a);return i?.negated?!r:r}function be(i,e,t,n){let s="",a=0,r=!1;for(;a<=i.length;){e.lastIndex=a;let l=e.exec(i);if(!l){s+=i.slice(a);break}if(l.index!==a){s+=i.slice(a,l.index),a=l.index,r=!1;continue}let c=l[0],f=l.slice(1);if(r&&c.length===0){if(a<i.length)s+=i[a],a++;else break;r=!1;continue}if(s+=n(c,f),r=!1,c.length===0)if(a<i.length)s+=i[a],a++;else break;else a+=c.length,r=!0}return s}function G(i,e,t){let n="",s=0;for(;s<i.length;){if(i[s]==="\\"&&s+1<i.length){let a=i[s+1];if(a==="&"){n+="&",s+=2;continue}if(a==="n"){n+=`
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{b as e}from"./chunk-Q5MYEU7X.js";var i=globalThis.setTimeout.bind(globalThis),r=globalThis.clearTimeout.bind(globalThis),s=globalThis.setInterval.bind(globalThis),T=globalThis.clearInterval.bind(globalThis);function l(t){return typeof t!="function"?t:e.bindCurrentContext(t)}var b=((t,n,...o)=>i(l(t),n,...o)),u=r;export{b as a,u as b};
2
+ import{b as e}from"./chunk-NTKUVXEL.js";var i=globalThis.setTimeout.bind(globalThis),r=globalThis.clearTimeout.bind(globalThis),s=globalThis.setInterval.bind(globalThis),T=globalThis.clearInterval.bind(globalThis);function l(t){return typeof t!="function"?t:e.bindCurrentContext(t)}var b=((t,n,...o)=>i(l(t),n,...o)),u=r;export{b as a,u as b};
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import{a as g}from"./chunk-KGOUQS5A.js";function v(){let a=[{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:"seteuid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.seteuid could escalate effective user privileges"},{prop:"setegid",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setegid could escalate effective group privileges"},{prop:"initgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.initgroups could modify supplementary group IDs"},{prop:"setgroups",target:process,violationType:"process_setuid",strategy:"throw",reason:"process.setgroups could modify supplementary group IDs"},{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:"cwd",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.cwd could disclose real host working directory path"},{prop:"chdir",target:process,violationType:"process_chdir",strategy:"throw",reason:"process.chdir could confuse the interpreter's CWD tracking"},{prop:"report",target:process,violationType:"process_report",strategy:"throw",reason:"process.report could disclose full environment, host paths, and system info"},{prop:"loadEnvFile",target:process,violationType:"process_env",strategy:"throw",reason:"process.loadEnvFile could load env files bypassing env proxy"},{prop:"setUncaughtExceptionCaptureCallback",target:process,violationType:"process_exception_handler",strategy:"throw",reason:"setUncaughtExceptionCaptureCallback could intercept security errors"},{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&&a.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&&a.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&&a.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 a.filter(e=>{try{return e.target[e.prop]!==void 0}catch{return!1}})}var f=typeof __BROWSER__<"u"&&__BROWSER__;function w(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{let e=Math.random()*16|0;return(a==="x"?e:e&3|8).toString(16)})}var x=null;if(!f)try{let{AsyncLocalStorage:a}=g("node:async_hooks");x=a}catch{}var k=`
3
+
4
+ This is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com`,d=class extends Error{violation;constructor(e,t){super(e+k),this.violation=t,this.name="SecurityViolationError"}},l=!f&&x?new x:null,T=1e3;function D(a,e,...t){return l.run(a,()=>e(...t))}var m={enabled:!0,auditMode:!1};function E(a){return a===void 0?{...m,enabled:!1}:typeof a=="boolean"?{...m,enabled:a}:{...m,...a}}var _=class a{static instance=null;static importHooksRegistered=!1;static trustedExecutionDepth=new Map;config;refCount=0;patchFailures=[];activeExecutionIds=new Set;contextCache=new Map;originalDescriptors=[];violations=[];activationTime=0;totalActiveTimeMs=0;constructor(e){this.config=e}static getInstance(e){let t=E(e);if(!a.instance)a.instance=new a(t);else{let r=a.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 a.instance}static resetInstance(){a.instance&&(a.instance.forceDeactivate(),a.instance=null),a.trustedExecutionDepth.clear()}static isInSandboxedContext(){return l?l?.getStore()?.sandboxActive===!0:!1}static getCurrentExecutionId(){if(l)return l?.getStore()?.executionId}static enterTrustedScope(e){let t=a.trustedExecutionDepth.get(e)??0;a.trustedExecutionDepth.set(e,t+1)}static leaveTrustedScope(e){let t=a.trustedExecutionDepth.get(e);if(t){if(t===1){a.trustedExecutionDepth.delete(e);return}a.trustedExecutionDepth.set(e,t-1)}}static isTrustedScopeActive(e){return e?(a.trustedExecutionDepth.get(e)??0)>0:!1}isExecutionIdActive(e){return this.activeExecutionIds.has(e)}getCachedContext(e){let t=this.contextCache.get(e);return t||(t={sandboxActive:!0,executionId:e},this.contextCache.set(e,t)),t}getPreferredActiveExecutionId(){if(this.activeExecutionIds.size!==0)for(let e of this.activeExecutionIds)return e}static bindCurrentContext(e){if(!l)return e;let t=a.instance,r=l.getStore(),s=r?.sandboxActive===!0?r.executionId:t?.getPreferredActiveExecutionId();if(!s)return e;let n=t?.getCachedContext(s)??{sandboxActive:!0,executionId:s};return((...o)=>{let i=a.instance;if(!(i&&!i.isExecutionIdActive(s)&&(i.recordViolation("bound_callback_after_deactivate","bound callback","Bound callback blocked after originating execution was deactivated"),!i.config.auditMode)))return D(n,e,...o)})}isEnabled(){return this.config.enabled===!0&&l!==null&&!f}updateConfig(e){this.config={...this.config,...e}}activate(){if(f||!this.config.enabled||!l){let r=w(),s=!1;return{run:n=>s?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):n(),deactivate:()=>{s=!0},executionId:r}}this.refCount++,this.refCount===1&&(this.applyPatches(),this.activationTime=Date.now());let e=w(),t=!1;return{run:r=>t?Promise.reject(new Error("DefenseInDepthBox handle is deactivated and cannot run new work")):(this.activeExecutionIds.add(e),l.run({sandboxActive:!0,executionId:e},r)),deactivate:()=>{t||(t=!0,this.activeExecutionIds.delete(e),this.contextCache.delete(e),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.activeExecutionIds.clear(),this.contextCache.clear(),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();if(!t)return e();let{executionId:r}=t;return l.run({...t,trusted:!0},()=>{a.enterTrustedScope(r);try{let s=e();return typeof s=="object"&&s!==null&&"finally"in s&&typeof s.finally=="function"?s.finally(()=>{a.leaveTrustedScope(r)}):(a.leaveTrustedScope(r),s)}catch(s){throw a.leaveTrustedScope(r),s}})}static async runTrustedAsync(e){if(!l)return e();let t=l.getStore();if(!t)return e();let{executionId:r}=t;return l.run({...t,trusted:!0},async()=>{a.enterTrustedScope(r);try{return await e()}finally{a.leaveTrustedScope(r)}})}shouldBlock(){if(f||this.config.auditMode||!l)return!1;let e=l?.getStore();return!(e?.sandboxActive!==!0||e.trusted||a.isTrustedScopeActive(e.executionId))}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(n){console.debug("[DefenseInDepthBox] onViolation callback threw:",n instanceof Error?n.message:n)}return s}createBlockingProxy(e,t,r){let s=this;return new Proxy(e,{apply(n,o,i){if(s.shouldBlock()){let c=`${t} is blocked during script execution`,u=s.recordViolation(r,t,c);throw new d(c,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} called (audit mode)`),Reflect.apply(n,o,i)},construct(n,o,i){if(s.shouldBlock()){let c=`${t} constructor is blocked during script execution`,u=s.recordViolation(r,t,c);throw new d(c,u)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} constructor called (audit mode)`),Reflect.construct(n,o,i)}})}createBlockingObjectProxy(e,t,r,s){let n=this;return new Proxy(e,{get(o,i,c){if(n.shouldBlock()){if(s&&typeof i=="string"&&s.has(i))return Reflect.get(o,i,c);let u=`${t}.${String(i)}`,p=`${u} is blocked during script execution`,h=n.recordViolation(r,u,p);throw new d(p,h)}if(n.config.auditMode&&l?.getStore()?.sandboxActive===!0){let u=`${t}.${String(i)}`;n.recordViolation(r,u,`${u} accessed (audit mode)`)}return Reflect.get(o,i,c)},set(o,i,c,u){if(n.shouldBlock()){let p=`${t}.${String(i)}`,h=`${p} modification is blocked during script execution`,y=n.recordViolation(r,p,h);throw new d(h,y)}return Reflect.set(o,i,c,u)},ownKeys(o){if(n.shouldBlock()){let i=`${t} enumeration is blocked during script execution`,c=n.recordViolation(r,t,i);throw new d(i,c)}return Reflect.ownKeys(o)},getOwnPropertyDescriptor(o,i){if(n.shouldBlock()){let c=`${t}.${String(i)}`,u=`${c} descriptor access is blocked during script execution`,p=n.recordViolation(r,c,u);throw new d(u,p)}return Reflect.getOwnPropertyDescriptor(o,i)},has(o,i){if(n.shouldBlock()){let c=`${t}.${String(i)}`,u=`${c} existence check is blocked during script execution`,p=n.recordViolation(r,c,u);throw new d(u,p)}return Reflect.has(o,i)},deleteProperty(o,i){if(n.shouldBlock()){let c=`${t}.${String(i)}`,u=`${c} deletion is blocked during script execution`,p=n.recordViolation(r,c,u);throw new d(u,p)}return Reflect.deleteProperty(o,i)},setPrototypeOf(o,i){if(n.shouldBlock()){let c=`${t} setPrototypeOf is blocked during script execution`,u=n.recordViolation(r,t,c);throw new d(c,u)}return Reflect.setPrototypeOf(o,i)},defineProperty(o,i,c){if(n.shouldBlock()){let u=`${t}.${String(i)}`,p=`${u} defineProperty is blocked during script execution`,h=n.recordViolation(r,u,p);throw new d(p,h)}return Reflect.defineProperty(o,i,c)}})}applyPatches(){this.patchFailures=[];let e=v(),t=new Set(["process_send","process_channel","process_stdout","process_stderr"]);for(let n of e)t.has(n.violationType)||this.applyPatch(n);this.protectConstructorChain(),this.protectErrorPrepareStackTrace(),this.protectPromiseThen(),this.protectDynamicImport(),this.protectModuleLoad(),this.protectModuleResolveFilename(),this.protectProcessMainModule(),this.protectProcessExecPath(),this.lockWellKnownSymbols();let r=["Function.prototype.constructor","Module._load"],s=this.patchFailures.filter(n=>r.includes(n));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 n="Error.prepareStackTrace modification is blocked during script execution",o=e.recordViolation("error_prepare_stack_trace","Error.prepareStackTrace",n);throw new d(n,o)}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)}}protectPromiseThen(){let e=this;try{let n=function(...o){return l.run(this.captured,()=>{if(!this.box.isExecutionIdActive(this.executionId)){if(this.box.recordViolation("promise_then_after_deactivate","Promise.then","Promise.then callback is blocked after defense deactivation"),this.box.config.auditMode)return Reflect.apply(this.cb,void 0,o);if(this.kind==="fulfilled")return o[0];throw o[0]}return Reflect.apply(this.cb,void 0,o)})};var t=n;let r=Object.getOwnPropertyDescriptor(Promise.prototype,"then");this.originalDescriptors.push({target:Promise.prototype,prop:"then",descriptor:r});let s=r?.value;if(typeof s!="function")return;Object.defineProperty(Promise.prototype,"then",{value:function(i,c){if(!l)return Reflect.apply(s,this,[i,c]);let u=l.getStore(),p=u?.sandboxActive===!0&&u.trusted!==!0?u.executionId:void 0;if(!p)return Reflect.apply(s,this,[i,c]);let h=e.getCachedContext(p),y=(b,P)=>typeof b!="function"?b:n.bind({box:e,executionId:p,captured:h,cb:b,kind:P});return Reflect.apply(s,this,[y(i,"fulfilled"),y(c,"rejected")])},writable:!0,configurable:!0})}catch(r){this.patchFailures.push("Promise.prototype.then"),console.debug("[DefenseInDepthBox] Could not protect Promise.prototype.then:",r instanceof Error?r.message:r)}}patchPrototypeConstructor(e,t,r){let s=this;try{let n=Object.getOwnPropertyDescriptor(e,"constructor");this.originalDescriptors.push({target:e,prop:"constructor",descriptor:n});let o=n?.value;Object.defineProperty(e,"constructor",{get(){if(s.shouldBlock()){let i=`${t} access is blocked during script execution`,c=s.recordViolation(r,t,i);throw new d(i,c)}return s.config.auditMode&&l?.getStore()?.sandboxActive===!0&&s.recordViolation(r,t,`${t} accessed (audit mode)`),o},set(i){if(s.shouldBlock()){let c=`${t} modification is blocked during script execution`,u=s.recordViolation(r,t,c);throw new d(c,u)}Object.defineProperty(this,"constructor",{value:i,writable:!0,configurable:!0})},configurable:!0})}catch(n){this.patchFailures.push(t),console.debug(`[DefenseInDepthBox] Could not patch ${t}:`,n instanceof Error?n.message:n)}}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",n=e.recordViolation("process_main_module","process.mainModule",s);throw new d(s,n)}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 n="process.mainModule modification is blocked during script execution",o=e.recordViolation("process_main_module","process.mainModule",n);throw new d(n,o)}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",n=e.recordViolation("process_exec_path","process.execPath",s);throw new d(s,n)}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 n="process.execPath modification is blocked during script execution",o=e.recordViolation("process_exec_path","process.execPath",n);throw new d(n,o)}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)}}lockWellKnownSymbols(){let e=(t,r)=>{try{let s=Object.getOwnPropertyDescriptor(t,r);if(s?.configurable){if("value"in s){Object.defineProperty(t,r,{...s,configurable:!1,writable:!1});return}Object.defineProperty(t,r,{...s,configurable:!1})}}catch{}};for(let t of[Array,Map,Set,RegExp,Promise])e(t,Symbol.species);for(let t of[Array.prototype,String.prototype,Map.prototype,Set.prototype])e(t,Symbol.iterator);e(Symbol.prototype,Symbol.toPrimitive),e(Date.prototype,Symbol.toPrimitive)}protectDynamicImport(){if(!(f||a.importHooksRegistered))try{let e=this,t=g("node:module"),r=new Set;for(let o of t.builtinModules??[]){let i=o.startsWith("node:")?o.slice(5):o;r.add(i);let c=i.indexOf("/");c>0&&r.add(i.slice(0,c))}let s=o=>{if(o.startsWith("./")||o.startsWith("../")||o.startsWith("/")||o.startsWith("file:")||o.startsWith("data:")||o.startsWith("blob:")||o.startsWith("http:")||o.startsWith("https:"))return!1;let i=o.startsWith("node:")?o.slice(5):o;if(!i)return!1;if(typeof t.isBuiltin=="function"&&t.isBuiltin(i)||r.has(i))return!0;let c=i.indexOf("/");return c>0&&r.has(i.slice(0,c))},n=()=>{let o=l?.getStore();return e.config.auditMode===!0&&o?.sandboxActive===!0&&o.trusted!==!0&&!a.isTrustedScopeActive(o.executionId)};if(typeof t.registerHooks=="function"){t.registerHooks({resolve(o,i,c){if(o.startsWith("data:")||o.startsWith("blob:"))throw new Error(`dynamic import of ${o.startsWith("data:")?"data:":"blob:"} URLs is blocked by defense-in-depth`);if(s(o)){let u=`import(${o})`,p=`dynamic import of Node.js builtin '${o}' is blocked during script execution`;if(e.shouldBlock()){let h=e.recordViolation("dynamic_import_builtin",u,p);throw new d(p,h)}n()&&e.recordViolation("dynamic_import_builtin",u,`dynamic import of Node.js builtin '${o}' called (audit mode)`)}return c(o,i)}}),a.importHooksRegistered=!0;return}if(typeof t.register=="function"){let o=["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
+ `);t.register(`data:text/javascript,${encodeURIComponent(o)}`),a.importHooksRegistered=!0}}catch(e){console.debug("[DefenseInDepthBox] Could not register import() hooks:",e instanceof Error?e.message:e)}}protectModuleLoad(){if(!f)try{let e=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(e=o.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 n=this.createBlockingProxy(t,"Module._load","module_load");Object.defineProperty(e,"_load",{value:n,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(!f)try{let e=null;if(typeof process<"u"){let o=process.mainModule;o&&typeof o=="object"&&(e=o.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 n=this.createBlockingProxy(t,"Module._resolveFilename","module_resolve_filename");Object.defineProperty(e,"_resolveFilename",{value:n,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:n}=e;try{let o=t[r];if(o===void 0)return;let i=Object.getOwnPropertyDescriptor(t,r);if(this.originalDescriptors.push({target:t,prop:r,descriptor:i}),n==="freeze")typeof o=="object"&&o!==null&&Object.freeze(o);else{let c=this.getPathForTarget(t,r),u=typeof o=="function"?this.createBlockingProxy(o,c,s):this.createBlockingObjectProxy(o,c,s,e.allowedKeys);Object.defineProperty(t,r,{value:u,writable:!0,configurable:!0})}}catch(o){let i=this.getPathForTarget(t,r);this.patchFailures.push(i),console.debug(`[DefenseInDepthBox] Could not patch ${i}:`,o instanceof Error?o.message:o)}}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(n){let o=this.getPathForTarget(t,r);console.debug(`[DefenseInDepthBox] Could not restore ${o}:`,n instanceof Error?n.message:n)}}this.originalDescriptors=[]}};export{d as a,_ as b};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as de}from"./chunk-4PRVMER6.js";import{a as D,b as _}from"./chunk-ZRRNCS7N.js";import{a as x}from"./chunk-Q5MYEU7X.js";import{a as A,b as H}from"./chunk-SE4C7FJY.js";import{k as P}from"./chunk-6KZRLMG3.js";import{a as pe,b as fe,c as re}from"./chunk-GTNBSMZR.js";var Ue=1e4,Be=100,He=new H(/\s+/);function ie(e={}){let{fieldSep:t=He,maxIterations:n=Ue,maxRecursionDepth:i=Be,maxOutputSize:s=0,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}=e;return{FS:" ",OFS:" ",ORS:`
2
+ import{a as de}from"./chunk-4PRVMER6.js";import{a as D,b as _}from"./chunk-5MUD3WB2.js";import{a as x}from"./chunk-NTKUVXEL.js";import{a as A,b as H}from"./chunk-SE4C7FJY.js";import{k as P}from"./chunk-6KZRLMG3.js";import{a as pe,b as fe,c as re}from"./chunk-GTNBSMZR.js";var Ue=1e4,Be=100,He=new H(/\s+/);function ie(e={}){let{fieldSep:t=He,maxIterations:n=Ue,maxRecursionDepth:i=Be,maxOutputSize:s=0,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}=e;return{FS:" ",OFS:" ",ORS:`
3
3
  `,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:Object.create(null),arrays:Object.create(null),arrayAliases:new Map,ARGC:0,ARGV:Object.create(null),ENVIRON:Object.create(null),functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,maxOutputSize:s,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:o,exec:l,coverage:u,requireDefenseContext:N}}function Ee(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function M(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function k(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function z(e,t){if(e.type==="regex")return e.pattern;let n=k(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function ye(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(M(await t.evalExpr(e.index)))}`:"$0":"$0"}function me(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return k(t.vars[e]??"")}function Se(e,t,n){if(e==="$0")n.line=t,n.fields=n.FS===" "?t.trim().split(/\s+/).filter(Boolean):n.fieldSep.split(t),n.NF=n.fields.length;else if(e.startsWith("$")){let i=parseInt(e.slice(1),10)-1;for(;n.fields.length<=i;)n.fields.push("");n.fields[i]=t,n.NF=n.fields.length,n.line=n.fields.join(n.OFS)}else n.vars[e]=t}async function $e(e,t,n){return e.length===0?t.line.length:k(await n.evalExpr(e[0])).length}async function We(e,t,n){if(e.length<2)return"";let i=k(await n.evalExpr(e[0])),s=Math.floor(M(await n.evalExpr(e[1])))-1;if(e.length>=3){let a=Math.floor(M(await n.evalExpr(e[2])));return i.substr(Math.max(0,s),a)}return i.substr(Math.max(0,s))}async function Ve(e,t,n){if(e.length<2)return 0;let i=k(await n.evalExpr(e[0])),s=k(await n.evalExpr(e[1])),a=i.indexOf(s);return a===-1?0:a+1}async function Ke(e,t,n){if(e.length<2)return 0;let i=k(await n.evalExpr(e[0])),s=e[1];if(s.type!=="variable")return 0;let a=s.name,o=t.FS;if(e.length>=3){let u=e[2];if(u.type==="regex")o=A(u.pattern);else{let N=k(await n.evalExpr(u));o=N===" "?A("\\s+"):N}}else t.FS===" "&&(o=A("\\s+"));let l=typeof o=="string"?i.split(o):o.split(i);t.arrays[a]=Object.create(null);for(let u=0;u<l.length;u++)t.arrays[a][String(u+1)]=l[u];return l.length}async function Xe(e,t,n){if(e.length<2)return 0;let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=await ye(e[2],n),o=me(a,t);try{let u=A(i).replace(o,we(s)),N=u!==o?1:0;return Se(a,u,t),N}catch{return 0}}async function qe(e,t,n){if(e.length<2)return 0;let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=await ye(e[2],n),o=me(a,t);try{let l=A(i,"g"),u=l.match(o),N=u?u.length:0,v=l.replace(o,we(s));return Se(a,v,t),N}catch{return 0}}function we(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let s=e[i+1];s==="&"?(n+="&",i+=2):s==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function ze(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=k(await n.evalExpr(e[0])),s=await z(e[1],n);try{let o=A(s).exec(i);if(o)return t.RSTART=o.index+1,t.RLENGTH=o[0].length,t.RSTART}catch{}return t.RSTART=0,t.RLENGTH=-1,0}async function je(e,t,n){if(e.length<3)return"";let i=await z(e[0],n),s=k(await n.evalExpr(e[1])),a=k(await n.evalExpr(e[2])),o=e.length>=4?k(await n.evalExpr(e[3])):t.line;try{let l=a.toLowerCase()==="g",u=l?0:parseInt(a,10)||1;if(l)return A(i,"g").replace(o,(v,...C)=>Ne(s,v,C.slice(0,-2)));{let N=0;return A(i,"g").replace(o,(C,...O)=>(N++,N===u?Ne(s,C,O.slice(0,-2)):C))}}catch{return o}}function Ne(e,t,n){let i="",s=0;for(;s<e.length;)if(e[s]==="\\"&&s+1<e.length){let a=e[s+1];if(a==="&")i+="&",s+=2;else if(a==="0")i+=t,s+=2;else if(a>="1"&&a<="9"){let o=parseInt(a,10)-1;i+=n[o]||"",s+=2}else a==="n"?(i+=`
4
4
  `,s+=2):a==="t"?(i+=" ",s+=2):(i+=a,s+=2)}else e[s]==="&"?(i+=t,s++):(i+=e[s],s++);return i}async function Qe(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toLowerCase()}async function Je(e,t,n){return e.length===0?"":k(await n.evalExpr(e[0])).toUpperCase()}async function Ze(e,t,n){if(e.length===0)return"";let i=k(await n.evalExpr(e[0])),s=[];for(let a=1;a<e.length;a++)s.push(await n.evalExpr(e[a]));return j(i,s)}async function Ye(e,t,n){return e.length===0?0:Math.floor(M(await n.evalExpr(e[0])))}async function et(e,t,n){return e.length===0?0:Math.sqrt(M(await n.evalExpr(e[0])))}async function tt(e,t,n){return e.length===0?0:Math.sin(M(await n.evalExpr(e[0])))}async function nt(e,t,n){return e.length===0?0:Math.cos(M(await n.evalExpr(e[0])))}async function rt(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):0,s=e.length>1?M(await n.evalExpr(e[1])):0;return Math.atan2(i,s)}async function it(e,t,n){return e.length===0?0:Math.log(M(await n.evalExpr(e[0])))}async function st(e,t,n){return e.length===0?1:Math.exp(M(await n.evalExpr(e[0])))}function at(e,t,n){return t.random?t.random():Math.random()}async function ot(e,t,n){let i=e.length>0?M(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function lt(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function se(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}var U=1e4;function j(e,t){let n=0,i="",s=0;for(;s<e.length;)if(e[s]==="%"&&s+1<e.length){let a=s+1,o="",l="",u="",N,v=a;for(;a<e.length&&/\d/.test(e[a]);)a++;a>v&&e[a]==="$"?(N=parseInt(e.substring(v,a),10)-1,a++):a=v;let C=()=>{if(a<e.length){if(a+1<e.length&&(e[a]==="h"&&e[a+1]==="h"||e[a]==="l"&&e[a+1]==="l")){a+=2;return}/[lzjh]/.test(e[a])&&a++}};for(;a<e.length&&/[-+ #0]/.test(e[a]);)o+=e[a++];if(e[a]==="*"){let d=t[n++],R=d!==void 0?Math.floor(Number(d)):0;R<0?(o+="-",l=String(Math.min(-R,U))):l=String(Math.min(R,U)),a++}else for(;a<e.length&&/\d/.test(e[a]);)l+=e[a++];if(l&&parseInt(l,10)>U&&(l=String(U)),e[a]==="."){if(a++,e[a]==="*"){let d=t[n++];u=String(Math.min(d!==void 0?Math.floor(Number(d)):0,U)),a++}else for(;a<e.length&&/\d/.test(e[a]);)u+=e[a++];u&&parseInt(u,10)>U&&(u=String(U))}C();let O=e[a],w=t[N!==void 0?N:n];switch(O){case"s":{let d=w!==void 0?String(w):"";if(u&&(d=d.substring(0,parseInt(u,10))),l){let R=parseInt(l,10);o.includes("-")?d=d.padEnd(R):d=d.padStart(R)}i+=d,N===void 0&&n++;break}case"d":case"i":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=d<0,h=Math.abs(d).toString();if(u){let F=parseInt(u,10);h=h.padStart(F,"0")}let c="";R?c="-":o.includes("+")?c="+":o.includes(" ")&&(c=" ");let E=c+h;if(l){let F=parseInt(l,10);o.includes("-")?E=E.padEnd(F):o.includes("0")&&!u?E=c+h.padStart(F-c.length,"0"):E=E.padStart(F)}i+=E,N===void 0&&n++;break}case"f":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d.toFixed(R);if(l){let c=parseInt(l,10);o.includes("-")?h=h.padEnd(c):h=h.padStart(c)}i+=h,N===void 0&&n++;break}case"e":case"E":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d.toExponential(R);if(O==="E"&&(h=h.toUpperCase()),l){let c=parseInt(l,10);o.includes("-")?h=h.padEnd(c):h=h.padStart(c)}i+=h,N===void 0&&n++;break}case"g":case"G":{let d=w!==void 0?Number(w):0;Number.isNaN(d)&&(d=0);let R=u?parseInt(u,10):6,h=d!==0?Math.floor(Math.log10(Math.abs(d))):0,c;if(d===0?c="0":h<-4||h>=R?(c=d.toExponential(R-1),O==="G"&&(c=c.toUpperCase())):c=d.toPrecision(R),c.includes(".")&&(c=c.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),c.includes("e")&&(c=c.replace(/\.?0+e/,"e")),l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"x":case"X":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=Math.abs(d).toString(16);if(O==="X"&&(R=R.toUpperCase()),u){let E=parseInt(u,10);R=R.padStart(E,"0")}let h=d<0?"-":"",c=h+R;if(l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):o.includes("0")&&!u?c=h+R.padStart(E-h.length,"0"):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"o":{let d=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(d)&&(d=0);let R=Math.abs(d).toString(8);if(u){let E=parseInt(u,10);R=R.padStart(E,"0")}let h=d<0?"-":"",c=h+R;if(l){let E=parseInt(l,10);o.includes("-")?c=c.padEnd(E):o.includes("0")&&!u?c=h+R.padStart(E-h.length,"0"):c=c.padStart(E)}i+=c,N===void 0&&n++;break}case"c":{typeof w=="number"?i+=String.fromCharCode(w):i+=String(w??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(s,a+1)}s=a+1}else if(e[s]==="\\"&&s+1<e.length){let a=e[s+1];switch(a){case"n":i+=`
5
5
  `;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=a}s+=2}else i+=e[s++];return i}var Re=new Map([["length",$e],["substr",We],["index",Ve],["split",Ke],["sub",Xe],["gsub",qe],["match",ze],["gensub",je],["tolower",Qe],["toupper",Je],["sprintf",Ze],["int",Ye],["sqrt",et],["sin",tt],["cos",nt],["atan2",rt],["log",it],["exp",st],["rand",at],["srand",ot],["system",lt("system","shell execution not allowed in sandboxed environment")],["close",()=>0],["fflush",()=>0],["systime",se("systime")],["mktime",se("mktime")],["strftime",se("strftime")]]);function b(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function g(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function S(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function ae(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function K(e,t){try{return A(e).test(t)}catch{return!1}}function ge(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):e.fieldSep.split(t)}function Q(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function oe(e,t,n){if(t===0)e.line=S(n),e.fields=ge(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=S(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function $(e,t){e.line=t,e.fields=ge(e,t),e.NF=e.fields.length}function ve(e,t){if(e.FS=t,t===" ")e.fieldSep=new H(/\s+/);else try{e.fieldSep=A(t)}catch{e.fieldSep=A(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function J(e,t){switch(t){case"FS":return e.FS;case"OFS":return e.OFS;case"ORS":return e.ORS;case"OFMT":return e.OFMT;case"NR":return e.NR;case"NF":return e.NF;case"FNR":return e.FNR;case"FILENAME":return e.FILENAME;case"RSTART":return e.RSTART;case"RLENGTH":return e.RLENGTH;case"SUBSEP":return e.SUBSEP;case"ARGC":return e.ARGC}return e.vars[t]??""}function W(e,t,n){switch(t){case"FS":ve(e,S(n));return;case"OFS":e.OFS=S(n);return;case"ORS":e.ORS=S(n);return;case"OFMT":e.OFMT=S(n);return;case"NR":e.NR=Math.floor(g(n));return;case"NF":{let i=Math.floor(g(n));if(i<e.NF)e.fields=e.fields.slice(0,i),e.line=e.fields.join(e.OFS);else if(i>e.NF){for(;e.fields.length<i;)e.fields.push("");e.line=e.fields.join(e.OFS)}e.NF=i;return}case"FNR":e.FNR=Math.floor(g(n));return;case"FILENAME":e.FILENAME=S(n);return;case"RSTART":e.RSTART=Math.floor(g(n));return;case"RLENGTH":e.RLENGTH=Math.floor(g(n));return;case"SUBSEP":e.SUBSEP=S(n);return}e.vars[t]=n}function X(e,t){let n=t,i=new Set,s=e.arrayAliases.get(n);for(;s!==void 0&&!i.has(n);)i.add(n),n=s,s=e.arrayAliases.get(n);return n}function Z(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=X(e,t);return e.arrays[i]?.[n]??""}function le(e,t,n,i){let s=X(e,t);e.arrays[s]||(e.arrays[s]=Object.create(null)),e.arrays[s][n]=i}function Ae(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=X(e,t);return e.arrays[i]?.[n]!==void 0}function Ie(e,t,n){let i=X(e,t);e.arrays[i]&&delete e.arrays[i][n]}function ke(e,t){let n=X(e,t);delete e.arrays[n]}var Ce=null;function be(e){Ce=e}function L(e,t){D(e.requireDefenseContext,"awk",t)}function m(e,t,n){return _(e.requireDefenseContext,"awk",t,n)}async function f(e,t){switch(L(e,"expression evaluation"),e.coverage?.hit(`awk:expr:${t.type}`),t.type){case"number":return t.value;case"string":return t.value;case"regex":return K(t.pattern,e.line)?1:0;case"field":return ut(e,t);case"variable":return J(e,t.name);case"array_access":return ct(e,t);case"binary":return ht(e,t);case"unary":return dt(e,t);case"ternary":return b(await m(e,"ternary condition evaluation",()=>f(e,t.condition)))?await m(e,"ternary consequent evaluation",()=>f(e,t.consequent)):await m(e,"ternary alternate evaluation",()=>f(e,t.alternate));case"call":return Et(e,t.name,t.args);case"assignment":return yt(e,t);case"pre_increment":return mt(e,t.operand);case"pre_decrement":return St(e,t.operand);case"post_increment":return wt(e,t.operand);case"post_decrement":return Rt(e,t.operand);case"in":return gt(e,t.key,t.array);case"getline":return vt(e,t.variable,t.file,t.command);case"tuple":return kt(e,t.elements);default:return""}}async function ut(e,t){L(e,"field reference evaluation");let n=Math.floor(g(await m(e,"field index evaluation",()=>f(e,t.index))));return Q(e,n)}async function ct(e,t){L(e,"array access evaluation");let n=S(await m(e,"array key evaluation",()=>f(e,t.key)));return Z(e,t.array,n)}async function ht(e,t){L(e,"binary expression evaluation");let n=t.operator;if(n==="||")return b(await m(e,"logical-or left evaluation",()=>f(e,t.left)))||b(await m(e,"logical-or right evaluation",()=>f(e,t.right)))?1:0;if(n==="&&")return b(await m(e,"logical-and left evaluation",()=>f(e,t.left)))&&b(await m(e,"logical-and right evaluation",()=>f(e,t.right)))?1:0;if(n==="~"){let l=await m(e,"regex left evaluation",()=>f(e,t.left));t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:S(await m(e,"regex right evaluation",()=>f(e,t.right)));try{return A(u).test(S(l))?1:0}catch{return 0}}if(n==="!~"){let l=await m(e,"negated-regex left evaluation",()=>f(e,t.left));t.right.type==="regex"&&e.coverage?.hit("awk:expr:regex");let u=t.right.type==="regex"?t.right.pattern:S(await m(e,"negated-regex right evaluation",()=>f(e,t.right)));try{return A(u).test(S(l))?0:1}catch{return 1}}let i=await m(e,"binary left evaluation",()=>f(e,t.left)),s=await m(e,"binary right evaluation",()=>f(e,t.right));if(n===" "){let l=S(i)+S(s);if(e.maxOutputSize>0&&l.length>e.maxOutputSize)throw new P(`awk: string concatenation size limit exceeded (${e.maxOutputSize} bytes)`,"string_length",e.output);return l}if(pt(n))return ft(i,s,n);let a=g(i),o=g(s);return Ee(a,o,n)}function pt(e){return["<","<=",">",">=","==","!="].includes(e)}function ft(e,t,n){let i=ae(e),s=ae(t);if(i&&s){let l=g(e),u=g(t);switch(n){case"<":return l<u?1:0;case"<=":return l<=u?1:0;case">":return l>u?1:0;case">=":return l>=u?1:0;case"==":return l===u?1:0;case"!=":return l!==u?1:0}}let a=S(e),o=S(t);switch(n){case"<":return a<o?1:0;case"<=":return a<=o?1:0;case">":return a>o?1:0;case">=":return a>=o?1:0;case"==":return a===o?1:0;case"!=":return a!==o?1:0}return 0}async function dt(e,t){L(e,"unary expression evaluation");let n=await m(e,"unary operand evaluation",()=>f(e,t.operand));switch(t.operator){case"!":return b(n)?0:1;case"-":return-g(n);case"+":return+g(n);default:return n}}async function Et(e,t,n){L(e,"function call evaluation");let i=Re.get(t);if(i)return i(n,e,{evalExpr:a=>f(e,a)});let s=e.functions.get(t);return s?Nt(e,s,n):""}async function Nt(e,t,n){if(L(e,"user function call"),e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new P(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i=Object.create(null);for(let l of t.params)i[l]=e.vars[l];let s=[];for(let l=0;l<t.params.length;l++){let u=t.params[l];if(l<n.length){let N=n[l];N.type==="variable"&&(e.arrayAliases.set(u,N.name),s.push(u));let v=await m(e,"user function argument evaluation",()=>f(e,N));e.vars[u]=v}else e.vars[u]=""}e.hasReturn=!1,e.returnValue=void 0;let a=Ce;a&&await m(e,"user function body execution",()=>a(e,t.body.statements));let o=e.returnValue??"";for(let l of t.params)i[l]!==void 0?e.vars[l]=i[l]:delete e.vars[l];for(let l of s)e.arrayAliases.delete(l);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,o}async function yt(e,t){L(e,"assignment evaluation");let n=await m(e,"assignment value evaluation",()=>f(e,t.value)),i=t.target,s=t.operator,a;if(s==="=")a=n;else{let o;if(i.type==="field"){let N=Math.floor(g(await m(e,"assignment field index",()=>f(e,i.index))));o=Q(e,N)}else if(i.type==="variable")o=J(e,i.name);else{let N=S(await m(e,"assignment array key",()=>f(e,i.key)));o=Z(e,i.array,N)}let l=g(o),u=g(n);switch(s){case"+=":a=l+u;break;case"-=":a=l-u;break;case"*=":a=l*u;break;case"/=":a=u!==0?l/u:0;break;case"%=":a=u!==0?l%u:0;break;case"^=":a=l**u;break;default:a=n}}if(i.type==="field"){let o=Math.floor(g(await m(e,"assignment target field index",()=>f(e,i.index))));oe(e,o,a)}else if(i.type==="variable")W(e,i.name,a);else{let o=S(await m(e,"assignment target array key",()=>f(e,i.key)));le(e,i.array,o,a)}return a}async function Y(e,t,n,i){L(e,"inc/dec evaluation");let s;if(t.type==="field"){let a=Math.floor(g(await m(e,"inc/dec field index",()=>f(e,t.index))));s=g(Q(e,a)),oe(e,a,s+n)}else if(t.type==="variable")s=g(J(e,t.name)),W(e,t.name,s+n);else{let a=S(await m(e,"inc/dec array key",()=>f(e,t.key)));s=g(Z(e,t.array,a)),le(e,t.array,a,s+n)}return i?s+n:s}async function mt(e,t){return Y(e,t,1,!0)}async function St(e,t){return Y(e,t,-1,!0)}async function wt(e,t){return Y(e,t,1,!1)}async function Rt(e,t){return Y(e,t,-1,!1)}async function gt(e,t,n){L(e,"in-expression evaluation");let i;if(t.type==="tuple"){e.coverage?.hit("awk:expr:tuple");let s=[];for(let a of t.elements)s.push(S(await m(e,"tuple key element evaluation",()=>f(e,a))));i=s.join(e.SUBSEP)}else i=S(await m(e,"in-expression key evaluation",()=>f(e,t)));return Ae(e,n,i)?1:0}async function vt(e,t,n,i){if(L(e,"getline evaluation"),i)return At(e,t,i);if(n)return It(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let s=e.lineIndex+1;if(s>=e.lines.length)return 0;let a=e.lines[s];return t?W(e,t,a):$(e,a),e.NR++,e.lineIndex=s,1}async function At(e,t,n){let i=e.exec;if(!i)return-1;L(e,"getline command source");let s=S(await m(e,"getline command expression",()=>f(e,n))),a=`__cmd_${s}`,o=`__cmdi_${s}`,l,u;if(e.vars[a]===void 0)try{l=(await m(e,"getline command exec",()=>i(s))).stdout.split(`
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import{a as C,b as L}from"./chunk-PLKGKTIS.js";import{d as b}from"./chunk-ZJGIBTWD.js";import{a as F,b as z}from"./chunk-5MUD3WB2.js";import{a as J}from"./chunk-NTKUVXEL.js";import{a as D}from"./chunk-5WFYIUU2.js";import{k as $}from"./chunk-6KZRLMG3.js";import{a as E}from"./chunk-SYG3IW7P.js";import{a as I,b as k,c as O}from"./chunk-GTNBSMZR.js";function A(s){let r=[],t=0,l=s.length;for(;t<l;){for(;t<l&&/\s/.test(s[t]);)t++;if(t>=l)break;let u=t,n=s[t];if(n==="{"||n==="["){let i=n,a=n==="{"?"}":"]",c=1,p=!1,d=!1;for(t++;t<l&&c>0;){let h=s[t];d?d=!1:h==="\\"?d=!0:h==='"'?p=!p:p||(h===i?c++:h===a&&c--),t++}if(c!==0)throw new Error(`Unexpected end of JSON input at position ${t} (unclosed ${i})`);r.push(b(JSON.parse(s.slice(u,t))))}else if(n==='"'){let i=!1;for(t++;t<l;){let a=s[t];if(i)i=!1;else if(a==="\\")i=!0;else if(a==='"'){t++;break}t++}r.push(b(JSON.parse(s.slice(u,t))))}else if(n==="-"||n>="0"&&n<="9"){for(;t<l&&/[\d.eE+-]/.test(s[t]);)t++;r.push(b(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 i=s.slice(t,t+10);throw new Error(`Invalid JSON at position ${u}: unexpected '${i.split(/\s/)[0]}'`)}}return r}var W={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,l,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 i=u?" ":" ";if(Array.isArray(s))return s.length===0?"[]":r?`[${s.map(c=>j(c,!0,!1,l,u)).join(",")}]`:`[
3
+ ${s.map(c=>i.repeat(n+1)+j(c,!1,!1,l,u,n+1)).join(`,
4
+ `)}
5
+ ${i.repeat(n)}]`;if(typeof s=="object"){let a=Object.keys(s);return l&&(a=a.sort()),a.length===0?"{}":r?`{${a.map(p=>`${JSON.stringify(p)}:${j(s[p],!0,!1,l,u)}`).join(",")}}`:`{
6
+ ${a.map(p=>{let d=j(s[p],!1,!1,l,u,n+1);return`${i.repeat(n+1)}${JSON.stringify(p)}: ${d}`}).join(`,
7
+ `)}
8
+ ${i.repeat(n)}}`}return String(s)}var Y={name:"jq",async execute(s,r){F(r.requireDefenseContext,"jq","execution entry");let t=(o,e)=>z(r.requireDefenseContext,"jq",o,e);if(k(s))return I(W);let l=!1,u=!1,n=!1,i=!1,a=!1,c=!1,p=!1,d=!1,h=".",N=!1,g=[];for(let o=0;o<s.length;o++){let e=s[o];if(e==="-r"||e==="--raw-output")l=!0;else if(e==="-c"||e==="--compact-output")u=!0;else if(e==="-e"||e==="--exit-status")n=!0;else if(e==="-s"||e==="--slurp")i=!0;else if(e==="-n"||e==="--null-input")a=!0;else if(e==="-j"||e==="--join-output")c=!0;else if(!(e==="-a"||e==="--ascii")){if(e==="-S"||e==="--sort-keys")p=!0;else if(!(e==="-C"||e==="--color")){if(!(e==="-M"||e==="--monochrome"))if(e==="--tab")d=!0;else if(e==="-")g.push("-");else{if(e.startsWith("--"))return O("jq",e);if(e.startsWith("-")){for(let f of e.slice(1))if(f==="r")l=!0;else if(f==="c")u=!0;else if(f==="e")n=!0;else if(f==="s")i=!0;else if(f==="n")a=!0;else if(f==="j")c=!0;else if(f!=="a"){if(f==="S")p=!0;else if(f!=="C"){if(f!=="M")return O("jq",`-${f}`)}}}else N?g.push(e):(h=e,N=!0)}}}}let y=[];if(!a)if(g.length===0||g.length===1&&g[0]==="-")y.push({source:"stdin",content:r.stdin});else{let o=await t("file read",()=>D(r,g,{cmdName:"jq",stopOnError:!0}));if(o.exitCode!==0)return{stdout:"",stderr:o.stderr,exitCode:2};y=o.files.map(e=>({source:e.filename||"stdin",content:e.content}))}try{let o=L(h),e=[],f={limits:r.limits?{maxIterations:r.limits.maxJqIterations}:void 0,env:r.env,coverage:r.coverage,requireDefenseContext:r.requireDefenseContext};if(a)e=C(null,o,f);else if(i){let m=[];for(let{content:x}of y){let q=x.trim();q&&m.push(...A(q))}e=C(m,o,f)}else for(let{content:m}of y){let x=m.trim();if(!x)continue;let q=A(x);for(let P of q)e.push(...C(P,o,f))}let M=e.map(m=>j(m,u,l,p,d)),V=c?"":`
9
+ `,S=M.join(V),w=r.limits?.maxStringLength;if(w!==void 0&&w>0&&S.length>w)throw new $(`jq: output size limit exceeded (${w} bytes)`,"string_length");let H=n&&(e.length===0||e.every(m=>m==null||m===!1))?1:0;return{stdout:S?c?S:`${S}
10
+ `:"",stderr:"",exitCode:H}}catch(o){if(o instanceof J)throw o;if(o instanceof $)return{stdout:"",stderr:`jq: ${E(o.message)}
11
+ `,exitCode:$.EXIT_CODE};let e=E(o.message);return e.includes("Unknown function")?{stdout:"",stderr:`jq: error: ${e}
12
+ `,exitCode:3}:{stdout:"",stderr:`jq: parse error: ${e}
13
+ `,exitCode:5}}}},Z={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{Y as a,Z as b};
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import{a as g,b as A,c as T,d as lt,e as E,f as O,g as X}from"./chunk-ZJGIBTWD.js";import{a as G,c as yt}from"./chunk-4PRVMER6.js";import{a as at}from"./chunk-5MUD3WB2.js";import{a as R}from"./chunk-SE4C7FJY.js";import{k as B}from"./chunk-6KZRLMG3.js";function W(t,r,e,n,p,o,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,a)=>{let y=p(h,e[0],n)[0],l=p(a,e[0],n)[0];return u(y,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 a=0,y=t.length;for(;a<y;){let l=a+y>>>1;u(t[l],h)<0?a=l+1:y=l}return a<t.length&&u(t[a],h)===0?a:-a-1})}case"unique_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let a of t){let y=p(a,e[0],n)[0],l=JSON.stringify(y);i.has(l)||i.set(l,{item:a,key:y})}let h=[...i.values()];return h.sort((a,y)=>u(a.key,y.key)),[h.map(a=>a.item)]}case"group_by":{if(!Array.isArray(t)||e.length===0)return[null];let i=new Map;for(let h of t){let a=JSON.stringify(p(h,e[0],n)[0]);i.has(a)||i.set(a,[]),i.get(a)?.push(h)}return[[...i.values()]]}case"max":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)>0?i:h)]:[null];case"max_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)>0?i:h})];case"min":return Array.isArray(t)&&t.length>0?[t.reduce((i,h)=>u(i,h)<0?i:h)]:[null];case"min_by":return!Array.isArray(t)||t.length===0||e.length===0?[null]:[t.reduce((i,h)=>{let a=p(i,e[0],n)[0],y=p(h,e[0],n)[0];return u(a,y)<0?i:h})];case"add":{let i=h=>{let a=h.filter(y=>y!==null);return a.length===0?null:a.every(y=>typeof y=="number")?a.reduce((y,l)=>y+l,0):a.every(y=>typeof y=="string")?a.join(""):a.every(y=>Array.isArray(y))?a.flat():a.every(y=>y&&typeof y=="object"&&!Array.isArray(y))?yt(...a):null};if(e.length>=1){let h=p(t,e[0],n);return[i(h)]}return Array.isArray(t)?[i(t)]:[null]}case"any":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(p(h,e[1],n).some(c))return[!0]}catch(i){if(i instanceof f)throw i}return[!1]}return e.length===1?Array.isArray(t)?[t.some(i=>c(p(i,e[0],n)[0]))]:[!1]:Array.isArray(t)?[t.some(c)]:[!1]}case"all":{if(e.length>=2){try{let i=o(t,e[0],n);for(let h of i)if(!p(h,e[1],n).some(c))return[!1]}catch(i){if(i instanceof f)throw i}return[!0]}return e.length===1?Array.isArray(t)?[t.every(i=>c(p(i,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(i=>p(i,e[0],n))];if(t&&typeof t=="object"){let i=Object.create(null);for(let[h,a]of Object.entries(t)){if(!g(h))continue;let y=p(a,e[0],n);y.length>0&&A(i,h,y[0])}return[i]}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 i=p(t,e[0],n);return[s(t,i[0])]}case"inside":{if(e.length===0)return[!1];let i=p(t,e[0],n);return[s(i[0],t)]}default:return null}}function z(t,r,e,n,p,o,u,c){switch(r){case"first":if(e.length>0)try{let s=o(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 i of s)if(i<0)throw new Error("nth doesn't support negative indices");let f;try{f=o(t,e[1],n)}catch(i){if(i instanceof c)throw i;f=[]}return s.flatMap(i=>{let h=i;return h<f.length?[f[h]]:[]})}return Array.isArray(t)?s.flatMap(f=>{let i=f;if(i<0)throw new Error("nth doesn't support negative indices");return i<t.length?[t[i]]:[null]}):[null]}case"range":{if(e.length===0)return[];let s=Math.max(n.limits.maxIterations*100,1e6),f=l=>l.length>=s,i=p(t,e[0],n);if(e.length===1){let l=[];for(let m of i){let b=m;for(let w=0;w<b;w++)if(l.push(w),f(l))return l}return l}let h=p(t,e[1],n);if(e.length===2){let l=[];for(let m of i)for(let b of h){let w=m,k=b;for(let N=w;N<k;N++)if(l.push(N),f(l))return l}return l}let a=p(t,e[2],n),y=[];for(let l of i)for(let m of h)for(let b of a){let w=l,k=m,N=b;if(N!==0){if(N>0){for(let C=w;C<k;C+=N)if(y.push(C),f(y))return y}else for(let C=w;C>k;C+=N)if(y.push(C),f(y))return y}}return y}case"limit":return e.length<2?[]:p(t,e[0],n).flatMap(f=>{let i=f;if(i<0)throw new Error("limit doesn't support negative count");if(i===0)return[];let h;try{h=o(t,e[1],n)}catch(a){if(a instanceof c)throw a;h=[]}return h.slice(0,i)});case"isempty":{if(e.length<1)return[!0];try{return[o(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 i=f;if(i<0)throw new Error("skip doesn't support negative count");return p(t,e[1],n).slice(i)});case"until":{if(e.length<2)return[t];let s=t,f=n.limits.maxIterations;for(let i=0;i<f;i++){if(p(s,e[0],n).some(u))return[s];let a=p(s,e[1],n);if(a.length===0)return[s];s=a[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,i=n.limits.maxIterations;for(let h=0;h<i&&p(f,e[0],n).some(u);h++){s.push(f);let y=p(f,e[1],n);if(y.length===0)break;f=y[0]}if(s.length>=i)throw new c(`jq while: too many iterations (${i}), increase executionLimits.maxJqIterations`,"iterations");return s}case"repeat":{if(e.length===0)return[t];let s=[],f=t,i=n.limits.maxIterations;for(let h=0;h<i;h++){s.push(f);let a=p(f,e[0],n);if(a.length===0)break;f=a[0]}if(s.length>=i)throw new c(`jq repeat: too many iterations (${i}), 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 o=new Date(t*1e3),u=o.getUTCFullYear(),c=o.getUTCMonth(),s=o.getUTCDate(),f=o.getUTCHours(),i=o.getUTCMinutes(),h=o.getUTCSeconds(),a=o.getUTCDay(),y=Date.UTC(u,0,1),l=Math.floor((o.getTime()-y)/(1440*60*1e3));return[[u,c,s,f,i,h,a,l]]}case"mktime":{if(!Array.isArray(t))throw new Error("mktime requires parsed datetime inputs");let[o,u,c,s=0,f=0,i=0]=t;if(typeof o!="number"||typeof u!="number")throw new Error("mktime requires parsed datetime inputs");let h=Date.UTC(o,u,c??1,s??0,f??0,i??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[a,y,l,m=0,b=0,w=0]=t;if(typeof a!="number"||typeof y!="number")throw new Error("strftime/1 requires parsed datetime inputs");c=new Date(Date.UTC(a,y,l??1,m??0,b??0,w??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"],i=(a,y=2)=>String(a).padStart(y,"0");return[u.replace(/%Y/g,String(c.getUTCFullYear())).replace(/%m/g,i(c.getUTCMonth()+1)).replace(/%d/g,i(c.getUTCDate())).replace(/%H/g,i(c.getUTCHours())).replace(/%M/g,i(c.getUTCMinutes())).replace(/%S/g,i(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,i,h,a,y,l]=s.map(Number),m=new Date(Date.UTC(f,i-1,h,a,y,l)),b=m.getUTCDay(),w=Date.UTC(f,0,1),k=Math.floor((m.getTime()-w)/(1440*60*1e3));return[[f,i-1,h,a,y,l,b,k]]}}let c=new Date(t);if(!Number.isNaN(c.getTime())){let s=c.getUTCFullYear(),f=c.getUTCMonth(),i=c.getUTCDate(),h=c.getUTCHours(),a=c.getUTCMinutes(),y=c.getUTCSeconds(),l=c.getUTCDay(),m=Date.UTC(s,0,1),b=Math.floor((c.getTime()-m)/(1440*60*1e3));return[[s,f,i,h,a,y,l,b]]}throw new Error(`Cannot parse date: ${t}`)}case"fromdate":{if(typeof t!="string")throw new Error("fromdate requires a string input");let o=new Date(t);if(Number.isNaN(o.getTime()))throw new Error(`date "${t}" does not match format "%Y-%m-%dT%H:%M:%SZ"`);return[Math.floor(o.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 S(t){return t!==!1&&t!==null}function I(t,r){return JSON.stringify(t)===JSON.stringify(r)}function U(t,r){return typeof t=="number"&&typeof r=="number"?t-r:typeof t=="string"&&typeof r=="string"?t.localeCompare(r):0}function v(t,r){let e=O(t);for(let n of Object.keys(r)){if(!g(n))continue;let p=T(e,n)?E(e[n]):null,o=E(r[n]);p&&o?A(e,n,v(p,o)):A(e,n,r[n])}return e}function D(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=c=>c===null?0:typeof c=="boolean"?1:typeof c=="number"?2:typeof c=="string"?3:Array.isArray(c)?4:typeof c=="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 c=0;c<Math.min(t.length,r.length);c++){let s=$(t[c],r[c]);if(s!==0)return s}return t.length-r.length}let o=E(t),u=E(r);if(o&&u){let c=Object.keys(o).sort(),s=Object.keys(u).sort();for(let f=0;f<Math.min(c.length,s.length);f++){let i=c[f].localeCompare(s[f]);if(i!==0)return i}if(c.length!==s.length)return c.length-s.length;for(let f of c){let i=$(o[f],u[f]);if(i!==0)return i}}return 0}function F(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(p=>t.some(o=>F(o,p)));let e=E(t),n=E(r);return e&&n?Object.keys(n).every(p=>T(e,p)&&F(e[p],n[p])):!1}var Ot=2e3;function tt(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 o=String(p);return o.includes(",")||o.includes('"')||o.includes(`
3
+ `)||o.includes("\r")?`"${o.replace(/"/g,'""')}"`:o}).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??Ot;return D(t,n+1)>n?[null]:[JSON.stringify(t)]}case"@html":return typeof t=="string"?[t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&apos;").replace(/"/g,"&quot;")]:[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 et(t,r,e,n,p,o){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 i=!0;for(let h=0;h<c.length;h++)if(!o(t[f+h],c[h])){i=!1;break}if(i)return f}return null}let s=t.findIndex(f=>o(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 i=0;i<c.length;i++)if(!o(t[s+i],c[i])){f=!1;break}if(f)return s}return null}for(let s=t.length-1;s>=0;s--)if(o(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 i=0;i<=t.length;i++)s.push(i);else for(let i=0;i<=t.length-f;i++){let h=!0;for(let a=0;a<f;a++)if(!o(t[i+a],c[a])){h=!1;break}h&&s.push(i)}}else for(let f=0;f<t.length;f++)o(t[f],c)&&s.push(f);return s});default:return null}}function rt(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 o=p(t,e[0],n),u=p(t,e[1],n),c=o[0],s=u[0];return typeof c!="number"||typeof s!="number"?[null]:[c**s]}case"atan2":{if(e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=o[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 o=p(t,e[0],n)[0];return[Math.hypot(t,o)]}case"fma":{if(typeof t!="number"||e.length<2)return[null];let o=p(t,e[0],n)[0],u=p(t,e[1],n)[0];return[t*o+u]}case"copysign":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[Math.sign(o)*Math.abs(t)]}case"drem":case"remainder":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[t-Math.round(t/o)*o]}case"fdim":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[Math.max(0,t-o)]}case"fmax":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[Math.max(t,o)]}case"fmin":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[Math.min(t,o)]}case"ldexp":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[t*2**o]}case"scalbn":case"scalbln":{if(typeof t!="number"||e.length===0)return[null];let o=p(t,e[0],n)[0];return[t*2**o]}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 o=Math.floor(Math.log2(Math.abs(t)));return[t/2**o]}return[null];case"frexp":if(typeof t=="number"){if(t===0)return[[0,0]];let o=Math.floor(Math.log2(Math.abs(t)))+1;return[[t/2**o,o]]}return[null];case"modf":if(typeof t=="number"){let o=Math.trunc(t);return[[t-o,o]]}return[null];default:return null}}function nt(t,r,e,n,p,o,u,c){switch(r){case"recurse":{if(e.length===0){let y=[],l=m=>{if(y.push(m),Array.isArray(m))for(let b of m)l(b);else if(m&&typeof m=="object")for(let b of Object.keys(m))l(m[b])};return l(t),y}let s=[],f=e.length>=2?e[1]:null,i=1e4,h=0,a=y=>{if(h++>i||f&&!p(y,f,n).some(o))return;s.push(y);let l=p(y,e[0],n);for(let m of l)m!=null&&a(m)};return a(t),s}case"recurse_down":return c(t,"recurse",e,n);case"walk":{if(e.length===0)return[t];let s=new WeakSet,f=i=>{if(i&&typeof i=="object"){if(s.has(i))return i;s.add(i)}let h;if(Array.isArray(i))h=i.map(f);else if(i&&typeof i=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(i))g(l)&&A(y,l,f(m));h=y}else h=i;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(i=>Array.isArray(i)?i.length:0)),f=[];for(let i=0;i<s;i++)f.push(t.map(h=>Array.isArray(h)?h[i]: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 a=[],y=(l,m)=>{if(m===h){a.push([...l]);return}for(let b of t)l.push(b),y(l,m+1),l.pop()};return y([],0),a}if(!Array.isArray(t))return[];if(t.length===0)return[[]];for(let i of t)if(!Array.isArray(i))return[];let s=[],f=(i,h)=>{if(i===t.length){s.push([...h]);return}let a=t[i];for(let y of a)h.push(y),f(i+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 i=s.slice(0,s.length-f);return[u(n.root,i)]}else{let i=-f-1;if(i>=s.length)return[t];let h=s.slice(0,i);return[u(n.root,h)]}}case"parents":{if(n.root===void 0||n.currentPath===void 0)return[[]];let s=n.currentPath,f=[];for(let i=s.length-1;i>=0;i--)f.push(u(n.root,s.slice(0,i)));return[f]}case"root":return n.root!==void 0?[n.root]:[];default:return null}}var Nt=2e3;function st(t,r,e,n,p){switch(r){case"keys":return Array.isArray(t)?[t.map((o,u)=>u)]:t&&typeof t=="object"?[Object.keys(t).sort()]:[null];case"keys_unsorted":return Array.isArray(t)?[t.map((o,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 o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) only strings have UTF-8 byte length`)}case"to_entries":{let o=E(t);return o?[Object.entries(o).map(([u,c])=>({key:u,value:c}))]:[null]}case"from_entries":if(Array.isArray(t)){let o=Object.create(null);for(let u of t){let c=E(u);if(c){let s=c.key??c.Key??c.name??c.Name??c.k,f=c.value??c.Value??c.v;if(s!==void 0){let i=String(s);g(i)&&A(o,i,f)}}}return[o]}return[null];case"with_entries":{if(e.length===0)return[t];let o=E(t);if(o){let c=Object.entries(o).map(([f,i])=>({key:f,value:i})).flatMap(f=>p(f,e[0],n)),s=Object.create(null);for(let f of c){let i=E(f);if(i){let h=i.key??i.name??i.k,a=i.value??i.v;if(h!==void 0){let y=String(h);g(y)&&A(s,y,a)}}}return[s]}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 o=new Set,u=[];for(let c of t){let s=JSON.stringify(c);o.has(s)||(o.add(s),u.push(c))}return[u]}return[null];case"tojson":case"tojsonstream":{let o=n.limits.maxDepth??Nt;return D(t,o+1)>o?[null]:[JSON.stringify(t)]}case"fromjson":{if(typeof t=="string"){let o=t.trim().toLowerCase();if(o==="nan")return[Number.NaN];if(o==="inf"||o==="infinity")return[Number.POSITIVE_INFINITY];if(o==="-inf"||o==="-infinity")return[Number.NEGATIVE_INFINITY];try{return[lt(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 o=Number(t);if(Number.isNaN(o))throw new Error(`${JSON.stringify(t)} cannot be parsed as a number`);return[o]}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 o=t===null?"null":Array.isArray(t)?"array":typeof t,u=o==="array"||o==="object"?JSON.stringify(t):String(t);throw new Error(`${o} (${u}) cannot be parsed as a boolean`)}case"tostream":{let o=[],u=(c,s)=>{if(c===null||typeof c!="object")o.push([s,c]);else if(Array.isArray(c))if(c.length===0)o.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)o.push([s,Object.create(null)]);else for(let i of f)u(c[i],[...s,i])}};return u(t,[]),o.push([[]]),o}case"fromstream":{if(e.length===0)return[t];let o=p(t,e[0],n),u=null;for(let c of o){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"?[]:Object.create(null));let i=u;for(let a=0;a<s.length-1;a++){let y=s[a],l=s[a+1];if(Array.isArray(i)&&typeof y=="number"){for(;i.length<=y;)i.push(null);i[y]===null&&(i[y]=typeof l=="number"?[]:Object.create(null)),i=i[y]}else{let m=E(i);if(m){let b=String(y);if(!g(b))continue;(m[b]===null||m[b]===void 0)&&A(m,b,typeof l=="number"?[]:Object.create(null)),i=m[b]}}}let h=s[s.length-1];if(Array.isArray(i)&&typeof h=="number"){for(;i.length<=h;)i.push(null);i[h]=f}else{let a=E(i);if(a){let y=String(h);g(y)&&A(a,y,f)}}}return[u]}case"truncate_stream":{let o=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>o&&u.push([f.slice(o)]);continue}if(s.length===2&&Array.isArray(s[0])){let f=s[0],i=s[1];f.length>o&&u.push([f.slice(o),i])}}return u}default:return null}}function it(t,r,e,n,p,o,u,c,s,f){switch(r){case"getpath":{if(e.length===0)return[null];let i=p(t,e[0],n),h=[];for(let a of i){let y=a,l=t;for(let m of y){if(l==null){l=null;break}if(Array.isArray(l)&&typeof m=="number")l=l[m];else if(typeof m=="string"){let b=E(l);if(!b||!Object.hasOwn(b,m)){l=null;break}l=b[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],y=p(t,e[1],n)[0];return[u(t,h,y)]}case"delpaths":{if(e.length===0)return[t];let h=p(t,e[0],n)[0],a=t;for(let y of h.sort((l,m)=>m.length-l.length))a=c(a,y);return[a]}case"path":{if(e.length===0)return[[]];let i=[];return f(t,e[0],n,[],i),i}case"del":return e.length===0?[t]:[s(t,e[0],n)];case"pick":{if(e.length===0)return[null];let i=[];for(let a of e)f(t,a,n,[],i);let h=null;for(let a of i){for(let l of a)if(typeof l=="number"&&l<0)throw new Error("Out of bounds negative array index");let y=t;for(let l of a){if(y==null)break;if(Array.isArray(y)&&typeof l=="number")y=y[l];else if(typeof l=="string"){let m=E(y);if(!m||!Object.hasOwn(m,l)){y=null;break}y=m[l]}else{y=null;break}}h=u(h,a,y)}return[h]}case"paths":{let i=[],h=(a,y)=>{if(a&&typeof a=="object")if(Array.isArray(a))for(let l=0;l<a.length;l++)i.push([...y,l]),h(a[l],[...y,l]);else for(let l of Object.keys(a))i.push([...y,l]),h(a[l],[...y,l])};return h(t,[]),e.length>0?i.filter(a=>{let y=t;for(let m of a)if(Array.isArray(y)&&typeof m=="number")y=y[m];else if(typeof m=="string"){let b=E(y);if(!b||!Object.hasOwn(b,m))return!1;y=b[m]}else return!1;return p(y,e[0],n).some(o)}):i}case"leaf_paths":{let i=[],h=(a,y)=>{if(a===null||typeof a!="object")i.push(y);else if(Array.isArray(a))for(let l=0;l<a.length;l++)h(a[l],[...y,l]);else for(let l of Object.keys(a))h(a[l],[...y,l])};return h(t,[]),i}default:return null}}function ot(t,r,e,n,p,o){switch(r){case"IN":{if(e.length===0)return[!1];if(e.length===1){let f=p(t,e[0],n);for(let i of f)if(o(t,i))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[Object.create(null)];if(e.length===1){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=String(i);g(h)&&A(f,h,i)}return[f]}if(e.length===2){let s=p(t,e[0],n),f=Object.create(null);for(let i of s){let h=p(i,e[1],n);if(h.length>0){let a=String(h[0]);g(a)&&A(f,a,i)}}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),i=p(s,e[2],n);if(f.length>0&&i.length>0){let h=String(f[0]);g(h)&&A(c,h,i[0])}}return[c]}case"JOIN":{if(e.length<2)return[null];let u=E(p(t,e[0],n)[0]);if(!u)return[null];if(!Array.isArray(t))return[null];let c=[];for(let s of t){let f=p(s,e[1],n),i=f.length>0?String(f[0]):"",h=T(u,i)?u[i]:null;c.push([s,h])}return[c]}default:return null}}function ft(t,r,e,n,p){switch(r){case"join":{if(!Array.isArray(t))return[null];let o=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 o.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 o=p(t,e[0],n),u=String(o[0]);return[t.split(u)]}case"splits":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"g";return R(u,c.includes("g")?c:`${c}g`).split(t)}catch{return[]}}case"scan":{if(typeof t!="string"||e.length===0)return[];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[...R(u,c.includes("g")?c:`${c}g`).matchAll(t)].map(i=>i.length>1?i.slice(1):i[0])}catch{return[]}}case"test":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"";return[R(u,c).test(t)]}catch{return[!1]}}case"match":{if(typeof t!="string"||e.length===0)return[null];let o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,`${c}d`).exec(t);if(!f)return[];let i=f.indices;return[{offset:f.index,length:f[0].length,string:f[0],captures:f.slice(1).map((h,a)=>({offset:i?.[a+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 o=p(t,e[0],n),u=String(o[0]);try{let c=e.length>1?String(p(t,e[1],n)[0]):"",f=R(u,c).match(t);return!f||!f.groups?[Object.create(null)]:[f.groups]}catch{return[null]}}case"sub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"";return[R(c,f).replace(t,s)]}catch{return[t]}}case"gsub":{if(typeof t!="string"||e.length<2)return[null];let o=p(t,e[0],n),u=p(t,e[1],n),c=String(o[0]),s=String(u[0]);try{let f=e.length>2?String(p(t,e[2],n)[0]):"g",i=f.includes("g")?f:`${f}g`;return[R(c,i).replace(t,s)]}catch{return[t]}}case"ascii_downcase":return typeof t=="string"?[t.replace(/[A-Z]/g,o=>String.fromCharCode(o.charCodeAt(0)+32))]:[null];case"ascii_upcase":return typeof t=="string"?[t.replace(/[a-z]/g,o=>String.fromCharCode(o.charCodeAt(0)-32))]:[null];case"ltrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[0]);return[t.startsWith(u)?t.slice(u.length):t]}case"rtrimstr":{if(typeof t!="string"||e.length===0)return[t];let o=p(t,e[0],n),u=String(o[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 o=p(t,e[0],n),u=String(o[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 o=p(t,e[0],n);return[t.startsWith(String(o[0]))]}case"endswith":{if(typeof t!="string"||e.length===0)return[!1];let o=p(t,e[0],n);return[t.endsWith(String(o[0]))]}case"ascii":return typeof t=="string"&&t.length>0?[t.charCodeAt(0)]:[null];case"explode":return typeof t=="string"?[Array.from(t).map(o=>o.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 ct(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 K(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 f=Array.isArray(t)?[...t]:[];for(;f.length<=n;)f.push(null);return f[n]=K(f[n],p,e),f}if(Array.isArray(t))throw new Error("Cannot index array with string");if(!g(n))return t??Object.create(null);let o=E(t),u=o?O(o):Object.create(null),c=Object.hasOwn(u,n)?u[n]:void 0;return A(u,n,K(c,p,e)),u}function V(t,r){if(r.length===0)return null;if(r.length===1){let p=r[0];if(Array.isArray(t)&&typeof p=="number"){let o=[...t];return o.splice(p,1),o}if(t&&typeof t=="object"&&!Array.isArray(t)){let o=String(p);if(!g(o))return t;let u=O(t);return delete u[o],u}return t}let[e,...n]=r;if(Array.isArray(t)&&typeof e=="number"){let p=[...t];return p[e]=V(p[e],n),p}if(t&&typeof t=="object"&&!Array.isArray(t)){let p=String(e);if(!g(p))return t;let o=O(t);return Object.hasOwn(o,p)&&A(o,p,V(o[p],n)),o}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])}},H=class extends Error{value;constructor(r){super(typeof r=="string"?r:JSON.stringify(r)),this.value=r,this.name="JqError"}},St=1e4,bt=2e3,Ct=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 Tt(t){return{vars:new Map,limits:{maxIterations:t?.limits?.maxIterations??St,maxDepth:t?.limits?.maxDepth??bt},env:t?.env,coverage:t?.coverage,requireDefenseContext:t?.requireDefenseContext,defenseContextChecked:!1}}function q(t,r,e){let n=new Map(t.vars);return n.set(r,e),{vars:n,limits:t.limits,env:t.env,requireDefenseContext:t.requireDefenseContext,defenseContextChecked:t.defenseContextChecked,root:t.root,currentPath:t.currentPath,funcs:t.funcs,labels:t.labels,coverage:t.coverage}}function L(t,r,e){switch(r.type){case"var":return q(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 o=r.elements[p],u=p<e.length?e[p]:null,c=L(n,o,u);if(c===null)return null;n=c}return n}case"object":{let n=E(e);if(!n)return null;let p=t;for(let o of r.fields){let u;if(typeof o.key=="string")u=o.key;else{let f=d(e,o.key,t);if(f.length===0)return null;u=String(f[0])}let c=T(n,u)?n[u]:null;o.keyVar&&(p=q(p,o.keyVar,c));let s=L(p,o.pattern,c);if(s===null)return null;p=s}return p}}}function Rt(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(e);if(p&&typeof n=="string"&&Object.hasOwn(p,n))e=p[n];else return}else return;return e}function M(t){if(t.type==="Identity")return[];if(t.type==="Field"){let r=t.base?M(t.base):[];return r===null?null:[...r,t.name]}if(t.type==="Index"&&t.index.type==="Literal"){let r=t.base?M(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=M(t.left);return r===null?null:pt(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 pt(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=M(r);if(e!==null)return[...t,...e]}if(r.type==="Index"&&r.index.type==="Literal"){let e=M(r);if(e!==null)return[...t,...e]}if(r.type==="Pipe"){let e=pt(t,r.left);return e===null?null:pt(e,r.right)}return r.type==="Identity"?t:null}function mt(t,r,e){if(r.type==="Comma"){let n=[];try{n.push(...d(t,r.left,e))}catch(p){if(p instanceof B)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 B)throw p;return n}return n}return d(t,r,e)}function d(t,r,e){let n=e&&"vars"in e?e:Tt(e);switch(n.defenseContextChecked||(at(n.requireDefenseContext,"query-engine","evaluation"),n={...n,defenseContextChecked:!0}),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(o=>{let u=E(o);if(u){if(!Object.hasOwn(u,r.name))return[null];let s=u[r.name];return[s===void 0?null:s]}if(o===null)return[null];let c=Array.isArray(o)?"array":typeof o;throw new Error(`Cannot index ${c} with string "${r.name}"`)});case"Index":return(r.base?d(t,r.base,n):[t]).flatMap(o=>d(o,r.index,n).flatMap(c=>{if(typeof c=="number"&&Array.isArray(o)){if(Number.isNaN(c))return[null];let s=Math.trunc(c),f=s<0?o.length+s:s;return f>=0&&f<o.length?[o[f]]:[null]}if(typeof c=="string"){let s=E(o);return!s||!Object.hasOwn(s,c)?[null]:[s[c]]}return[null]}));case"Slice":return(r.base?d(t,r.base,n):[t]).flatMap(o=>{if(o===null)return[null];if(!Array.isArray(o)&&typeof o!="string")throw new Error(`Cannot slice ${typeof o} (${JSON.stringify(o)})`);let u=o.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(i=>{let h=f,a=i,y=Number.isNaN(h)?0:Number.isInteger(h)?h:Math.floor(h),l=Number.isNaN(a)?u:Number.isInteger(a)?a:Math.ceil(a),m=dt(y,u),b=dt(l,u);return Array.isArray(o),o.slice(m,b)}))});case"Iterate":return(r.base?d(t,r.base,n):[t]).flatMap(o=>Array.isArray(o)?o:o&&typeof o=="object"?Object.values(o):[]);case"Pipe":{let p=d(t,r.left,n),o=M(r.left),u=[];for(let c of p)try{if(o!==null){let s={...n,currentPath:[...n.currentPath??[],...o]};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),o=d(t,r.right,n);return[...p,...o]}case"Literal":return[r.value];case"Array":return r.elements?[d(t,r.elements,n)]:[[]];case"Object":{let p=[Object.create(null)];for(let o of r.entries){let u=typeof o.key=="string"?[o.key]:d(t,o.key,n),c=d(t,o.value,n),s=[];for(let f of p)for(let i of u){if(typeof i!="string"){let h=i===null?"null":Array.isArray(i)?"array":typeof i;throw new Error(`Cannot use ${h} (${JSON.stringify(i)}) as object key`)}if(!g(i)){for(let h of c)s.push(O(f));continue}for(let h of c){let a=O(f);A(a,i,h),s.push(a)}}p.length=0,p.push(...s)}return p}case"Paren":return d(t,r.expr,n);case"BinaryOp":return xt(t,r.op,r.left,r.right,n);case"UnaryOp":return d(t,r.operand,n).map(o=>{if(r.op==="-"){if(typeof o=="number")return-o;if(typeof o=="string"){let u=c=>c.length>5?`"${c.slice(0,3)}...`:JSON.stringify(c);throw new Error(`string (${u(o)}) cannot be negated`)}return null}return r.op==="not"?!S(o):null});case"Cond":return d(t,r.cond,n).flatMap(o=>{if(S(o))return d(t,r.then,n);for(let u of r.elifs)if(d(t,u.cond,n).some(S))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 o=p instanceof H?p.value:p instanceof Error?p.message:String(p);return d(o,r.catch,n)}return[]}case"Call":return gt(t,r.name,r.args,n);case"VarBind":return d(t,r.value,n).flatMap(o=>{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=L(n,s,o),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=[],o=new WeakSet,u=c=>{if(c&&typeof c=="object"){if(o.has(c))return;o.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(o=>typeof o=="string"?o:d(t,o,n).map(c=>typeof c=="string"?c:JSON.stringify(c)).join("")).join("")];case"UpdateOp":return[Mt(t,r.path,r.op,r.value,n)];case"Reduce":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=n.limits.maxDepth??bt;for(let c of p){let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],D(o,u+1)>u)return[null]}return[o]}case"Foreach":{let p=d(t,r.expr,n),o=d(t,r.init,n)[0],u=[];for(let c of p)try{let s;if(r.pattern){if(s=L(n,r.pattern,c),s===null)continue}else s=q(n,r.varName,c);if(o=d(o,r.update,s)[0],r.extract){let f=d(o,r.extract,s);u.push(...f)}else u.push(o)}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??[]),o=`${r.name}/${r.params.length}`;p.set(o,{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 dt(t,r){return t<0?Math.max(0,r+t):Math.min(t,r)}function Mt(t,r,e,n,p){function o(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,i){switch(f.type){case"Identity":return i(s);case"Field":{if(!g(f.name))return s;if(f.base)return u(s,f.base,h=>{if(h&&typeof h=="object"&&!Array.isArray(h)){let a=O(h),y=Object.hasOwn(a,f.name)?a[f.name]:void 0;return A(a,f.name,i(y)),a}return h});if(s&&typeof s=="object"&&!Array.isArray(s)){let h=O(s),a=Object.hasOwn(h,f.name)?h[f.name]:void 0;return A(h,f.name,i(a)),h}return s}case"Index":{let a=d(t,f.index,p)[0];if(typeof a=="number"&&Number.isNaN(a))throw new Error("Cannot set array element at NaN index");if(typeof a=="number"&&!Number.isInteger(a)&&(a=Math.trunc(a)),f.base)return u(s,f.base,y=>{if(typeof a=="number"&&Array.isArray(y)){let l=[...y],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(typeof a=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(a))return y;let l=O(y),m=Object.hasOwn(l,a)?l[a]:void 0;return A(l,a,i(m)),l}return y});if(typeof a=="number"){if(a>536870911)throw new Error("Array index too large");if(a<0&&(!s||!Array.isArray(s)))throw new Error("Out of bounds negative array index");if(Array.isArray(s)){let l=[...s],m=a<0?l.length+a:a;if(m>=0){for(;l.length<=m;)l.push(null);l[m]=i(l[m])}return l}if(s==null){let l=[];for(;l.length<=a;)l.push(null);return l[a]=i(null),l}return s}if(typeof a=="string"&&s&&typeof s=="object"&&!Array.isArray(s)){if(!g(a))return s;let y=O(s),l=Object.hasOwn(y,a)?y[a]:void 0;return A(y,a,i(l)),y}return s}case"Iterate":{let h=a=>{if(Array.isArray(a))return a.map(y=>i(y));if(a&&typeof a=="object"){let y=Object.create(null);for(let[l,m]of Object.entries(a))g(l)&&A(y,l,i(m));return y}return a};return f.base?u(s,f.base,h):h(s)}case"Pipe":{let h=u(s,f.left,a=>a);return u(h,f.right,i)}default:return i(s)}}return u(t,r,s=>{if(e==="|=")return o(s,s);let f=d(t,n,p);return o(s,f[0]??null)})}function jt(t,r,e){function n(o,u,c){switch(u.type){case"Identity":return c;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0],f=n(s,{type:"Field",name:u.name},c);return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){let s=O(o);return A(s,u.name,c),s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0],h=n(i,{type:"Index",index:u.index},c);return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h<i.length&&(i[h]=c),i}if(typeof f=="string"&&o&&typeof o=="object"&&!Array.isArray(o)){if(!g(f))return o;let i=O(o);return A(i,f,c),i}return o}default:return o}}function p(o,u){switch(u.type){case"Identity":return null;case"Field":{if(!g(u.name))return o;if(u.base){let s=d(o,u.base,e)[0];if(s==null)return o;let f=p(s,{type:"Field",name:u.name});return n(o,u.base,f)}if(o&&typeof o=="object"&&!Array.isArray(o)){if(!g(u.name))return o;let s=O(o);return delete s[u.name],s}return o}case"Index":{if(u.base){let i=d(o,u.base,e)[0];if(i==null)return o;let h=p(i,{type:"Index",index:u.index});return n(o,u.base,h)}let f=d(t,u.index,e)[0];if(typeof f=="number"&&Array.isArray(o)){let i=[...o],h=f<0?i.length+f:f;return h>=0&&h<i.length&&i.splice(h,1),i}if(typeof f=="string"&&o&&typeof o=="object"&&!Array.isArray(o)){if(!g(f))return o;let i=O(o);return delete i[f],i}return o}case"Iterate":return Array.isArray(o)?[]:o&&typeof o=="object"?Object.create(null):o;case"Pipe":{let i=function(y,l,m){switch(l.type){case"Identity":return m;case"Field":{if(!g(l.name))return y;if(y&&typeof y=="object"&&!Array.isArray(y)){let b=O(y);return A(b,l.name,m),b}return y}case"Index":{let w=d(t,l.index,e)[0];if(typeof w=="number"&&Array.isArray(y)){let k=[...y],N=w<0?k.length+w:w;return N>=0&&N<k.length&&(k[N]=m),k}if(typeof w=="string"&&y&&typeof y=="object"&&!Array.isArray(y)){if(!g(w))return y;let k=O(y);return A(k,w,m),k}return y}case"Pipe":{let b=d(y,l.left,e)[0],w=i(b,l.right,m);return i(y,l.left,w)}default:return y}};var c=i;let s=u.left,f=u.right,h=d(o,s,e)[0];if(h==null)return o;let a=p(h,f);return i(o,s,a)}default:return o}}return p(t,r)}function xt(t,r,e,n,p){if(r==="and")return d(t,e,p).flatMap(s=>S(s)?d(t,n,p).map(i=>S(i)):[!1]);if(r==="or")return d(t,e,p).flatMap(s=>S(s)?[!0]:d(t,n,p).map(i=>S(i)));if(r==="//"){let s=d(t,e,p).filter(f=>f!=null&&f!==!1);return s.length>0?s:d(t,n,p)}let o=d(t,e,p),u=d(t,n,p);return o.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(i=>JSON.stringify(i)));return c.filter(i=>!f.has(JSON.stringify(i)))}if(typeof c=="string"&&typeof s=="string"){let f=i=>i.length>10?`"${i.slice(0,10)}...`:JSON.stringify(i);throw new Error(`string (${f(c)}) and string (${f(s)}) cannot be subtracted`)}return null;case"*":if(typeof c=="number"&&typeof s=="number")return c*s;if(typeof c=="string"&&typeof s=="number")return c.repeat(s);{let f=E(c),i=E(s);if(f&&i)return v(f,i)}return 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 U(c,s)<0;case"<=":return U(c,s)<=0;case">":return U(c,s)>0;case">=":return U(c,s)>=0;default:return null}}))}function gt(t,r,e,n){let p=Ct.get(r);if(p)return typeof t=="number"?[p(t)]:[null];let o=rt(t,r,e,n,d);if(o!==null)return o;let u=ft(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=tt(t,r,n.limits.maxDepth);if(s!==null)return s;let f=ct(t,r);if(f!==null)return f;let i=st(t,r,e,n,d);if(i!==null)return i;let h=W(t,r,e,n,d,mt,$,S,F,B);if(h!==null)return h;let a=it(t,r,e,n,d,S,K,V,jt,J);if(a!==null)return a;let y=et(t,r,e,n,d,I);if(y!==null)return y;let l=z(t,r,e,n,d,mt,S,B);if(l!==null)return l;let m=nt(t,r,e,n,d,S,Rt,gt);if(m!==null)return m;let b=ot(t,r,e,n,d,I);if(b!==null)return b;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 w=e.length>0?d(t,e[0],n)[0]:t;throw new H(w)}case"env":return[n.env?G(n.env):Object.create(null)];case"debug":return[t];case"input_line_number":return[1];default:{let w=`${r}/${e.length}`,k=n.funcs?.get(w);if(k){let N=k.closure??n.funcs??new Map,C=new Map(N);C.set(w,k);for(let _=0;_<k.params.length;_++){let kt=k.params[_],ht=e[_];if(ht){let j=d(t,ht,n),x;if(j.length===0)x={type:"Call",name:"empty",args:[]};else if(j.length===1)x={type:"Literal",value:j[0]};else{x={type:"Literal",value:j[j.length-1]};for(let Q=j.length-2;Q>=0;Q--)x={type:"Comma",left:{type:"Literal",value:j[Q]},right:x}}C.set(`${kt}/0`,{params:[],body:x})}}let wt={...n,funcs:C};return d(t,k.body,wt)}throw new Error(`Unknown function: ${r}`)}}}function J(t,r,e,n,p){if(r.type==="Comma"){let c=r;J(t,c.left,e,n,p),J(t,c.right,e,n,p);return}let o=M(r);if(o!==null){p.push([...n,...o]);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 i=0;i<s.length;i++)c(s[i],[...f,i]);else for(let i of Object.keys(s))c(s[i],[...f,i])};c(t,[]);return}if(r.type==="Pipe"){let c=M(r.left);if(c!==null){let s=d(t,r.left,e);for(let f of s)J(f,r.right,e,[...n,...c],p);return}}d(t,r,e).length>0&&p.push(n)}var At=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(At.values());function Et(t){let r=[],e=0,n=(f=0)=>t[e+f],p=()=>t[e++],o=()=>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(;!o();){let f=e,i=p();if(!(i===" "||i===" "||i===`
4
+ `||i==="\r")){if(i==="#"){for(;!o()&&n()!==`
5
+ `;)p();continue}if(i==="."&&n()==="."){p(),r.push({type:"DOTDOT",pos:f});continue}if(i==="="&&n()==="="){p(),r.push({type:"EQ",pos:f});continue}if(i==="!"&&n()==="="){p(),r.push({type:"NE",pos:f});continue}if(i==="<"&&n()==="="){p(),r.push({type:"LE",pos:f});continue}if(i===">"&&n()==="="){p(),r.push({type:"GE",pos:f});continue}if(i==="/"&&n()==="/"){p(),n()==="="?(p(),r.push({type:"UPDATE_ALT",pos:f})):r.push({type:"ALT",pos:f});continue}if(i==="+"&&n()==="="){p(),r.push({type:"UPDATE_ADD",pos:f});continue}if(i==="-"&&n()==="="){p(),r.push({type:"UPDATE_SUB",pos:f});continue}if(i==="*"&&n()==="="){p(),r.push({type:"UPDATE_MUL",pos:f});continue}if(i==="/"&&n()==="="){p(),r.push({type:"UPDATE_DIV",pos:f});continue}if(i==="%"&&n()==="="){p(),r.push({type:"UPDATE_MOD",pos:f});continue}if(i==="="&&n()!=="="){r.push({type:"ASSIGN",pos:f});continue}if(i==="."){r.push({type:"DOT",pos:f});continue}if(i==="|"){n()==="="?(p(),r.push({type:"UPDATE_PIPE",pos:f})):r.push({type:"PIPE",pos:f});continue}if(i===","){r.push({type:"COMMA",pos:f});continue}if(i===":"){r.push({type:"COLON",pos:f});continue}if(i===";"){r.push({type:"SEMICOLON",pos:f});continue}if(i==="("){r.push({type:"LPAREN",pos:f});continue}if(i===")"){r.push({type:"RPAREN",pos:f});continue}if(i==="["){r.push({type:"LBRACKET",pos:f});continue}if(i==="]"){r.push({type:"RBRACKET",pos:f});continue}if(i==="{"){r.push({type:"LBRACE",pos:f});continue}if(i==="}"){r.push({type:"RBRACE",pos:f});continue}if(i==="?"){r.push({type:"QUESTION",pos:f});continue}if(i==="+"){r.push({type:"PLUS",pos:f});continue}if(i==="-"){r.push({type:"MINUS",pos:f});continue}if(i==="*"){r.push({type:"STAR",pos:f});continue}if(i==="/"){r.push({type:"SLASH",pos:f});continue}if(i==="%"){r.push({type:"PERCENT",pos:f});continue}if(i==="<"){r.push({type:"LT",pos:f});continue}if(i===">"){r.push({type:"GT",pos:f});continue}if(u(i)){let h=i;for(;!o()&&(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(i==='"'){let h="";for(;!o()&&n()!=='"';)if(n()==="\\"){if(p(),o())break;let a=p();switch(a){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+=a}}else h+=p();o()||p(),r.push({type:"STRING",value:h,pos:f});continue}if(c(i)||i==="$"||i==="@"){let h=i;for(;!o()&&s(n());)h+=p();let a=At.get(h);a?r.push({type:a,value:h,pos:f}):r.push({type:"IDENT",value:h,pos:f});continue}throw new Error(`Unexpected character '${i}' at position ${f}`)}}return r.push({type:"EOF",pos:e}),r}var ut=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(),o=e.get(n.type);if(o)return{type:"UpdateOp",op:o,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 o=this.parseAddSub();r={type:"BinaryOp",op:p,left:r,right:o}}}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 o=e.type==="var"?e.name:"";return{type:"Reduce",expr:r,varName:o,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(),o;this.match("SEMICOLON")&&(o=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:o,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 o=this.parseExpr();return{type:"Def",name:e,params:n,funcBody:p,body:o}}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 o=this.parseExpr();this.expect("THEN","Expected 'then' after elif");let u=this.parseExpr();n.push({cond:o,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 o=1,u="";for(;p<r.length&&o>0;)r[p]==="("?o++:r[p]===")"&&o--,o>0&&(u+=r[p]),p++;let c=Et(u),s=new t(c);e.push(s.parse())}else n+=r[p],p++;return n&&e.push(n),{type:"StringInterp",parts:e}}};function Ne(t){let r=Et(t);return new ut(r).parse()}export{d as a,Ne as b};