just-bash 2.9.2 → 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/chunk-HSNUCOOQ.js +6 -0
- package/dist/bin/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/{shell/chunks/curl-7IUASLUJ.js → chunks/curl-RWQO3SBN.js} +18 -18
- package/dist/bin/{shell/chunks/jq-BMOLDA72.js → chunks/jq-EIPK4SZA.js} +1 -1
- package/dist/bin/chunks/worker.js +746 -2
- package/dist/bin/{shell/chunks/xan-EAK3S7KJ.js → chunks/xan-QLNZCWIG.js} +35 -35
- package/dist/bin/chunks/{yq-WYJ3A4JF.js → yq-XD7UYY5C.js} +1 -1
- package/dist/bin/just-bash.js +2 -2
- package/dist/bin/shell/chunks/chunk-HSNUCOOQ.js +6 -0
- package/dist/bin/shell/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/{chunks/curl-7IUASLUJ.js → shell/chunks/curl-RWQO3SBN.js} +18 -18
- package/dist/bin/{chunks/jq-BMOLDA72.js → shell/chunks/jq-EIPK4SZA.js} +1 -1
- package/dist/bin/{chunks/xan-EAK3S7KJ.js → shell/chunks/xan-QLNZCWIG.js} +35 -35
- package/dist/bin/shell/chunks/{yq-WYJ3A4JF.js → yq-XD7UYY5C.js} +1 -1
- package/dist/bin/shell/shell.js +2 -2
- package/dist/bundle/browser.js +464 -464
- package/dist/bundle/chunks/chunk-7MKBHGLS.js +1 -0
- package/dist/bundle/chunks/chunk-WQCJYUEW.js +5 -0
- package/dist/bundle/chunks/{curl-QDCXHQMX.js → curl-6L7YZUIH.js} +18 -18
- package/dist/bundle/chunks/{jq-GMMYKAEP.js → jq-6U2TPE6U.js} +1 -1
- package/dist/bundle/chunks/worker.js +746 -2
- package/dist/bundle/chunks/{xan-DYADHWWG.js → xan-EN6JZQ3T.js} +35 -35
- package/dist/bundle/chunks/{yq-5WHXPM6R.js → yq-JD6M7T5A.js} +1 -1
- package/dist/bundle/index.js +193 -193
- package/dist/commands/python3/worker.d.ts +6 -0
- package/dist/commands/query-engine/safe-object.d.ts +10 -0
- package/dist/commands/query-engine/value-operations.d.ts +1 -0
- package/dist/commands/sqlite3/worker.d.ts +10 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +4 -1
- package/package.json +1 -1
- package/dist/bin/chunks/chunk-FJTZ5HFK.js +0 -6
- package/dist/bin/shell/chunks/chunk-FJTZ5HFK.js +0 -6
- package/dist/bundle/chunks/chunk-IHEPHGKB.js +0 -5
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as O,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-HSNUCOOQ.js";import{d as G}from"./chunk-UYBH3FNE.js";import"./chunk-4PRVMER6.js";import"./chunk-K5IXNHO5.js";import{a as H}from"./chunk-SE4C7FJY.js";import{a as We}from"./chunk-5WFYIUU2.js";import"./chunk-OBH7XN5N.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
|
-
`;break;case"r":s+="\r";break;case"t":s+=" ";break;case"\\":s+="\\";break;case'"':s+='"';break;case"'":s+="'";break;case"`":s+="`";break;case"0":s+="\0";break;default:s+=o}this.pos++}}else s+=r,this.pos++}throw new Error(`Unterminated string starting at position ${t}`)}readRegex(){let n=this.pos;this.pos++;let t="",s="";for(;this.pos<this.input.length;){let r=this.input[this.pos];if(r==="/"){for(this.pos++;this.pos<this.input.length&&this.input[this.pos]==="i";)s+=this.input[this.pos],this.pos++;return{type:"regex",value:t+(s?`/${s}`:""),pos:n}}r==="\\"?(t+=r,this.pos++,this.pos<this.input.length&&(t+=this.input[this.pos],this.pos++)):(t+=r,this.pos++)}throw new Error(`Unterminated regex starting at position ${n}`)}readIdentifier(){let n=this.pos;for(;this.pos<this.input.length&&this.isIdentChar(this.input[this.pos]);)this.pos++;let t=!1;this.pos<this.input.length&&this.input[this.pos]==="?"&&(t=!0,this.pos++);let s=this.input.slice(n,t?this.pos-1:this.pos);t&&(s+="?");let r=new Map([["true","true"],["false","false"],["null","null"],["and","and"],["or","or"],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["in","in"],["as","as"],["_","_"]]),o=s.replace(/\?$/,""),i=r.get(o);return i!==void 0&&!t?{type:i,value:o,pos:n}:{type:"ident",value:s,pos:n}}}});var _e={};Ye(_e,{parseMoonblade:()=>_,parseNamedExpressions:()=>V});function V(e){let n=[],s=new q(e).tokenize(),r=0,o=()=>s[r]||{type:"eof",value:"",pos:0},i=()=>s[r++];for(;o().type!=="eof";){if(o().type===","&&n.length>0){i();continue}let h=[],u=0,p=r;for(;o().type!=="eof";){let a=o();if((a.type===","||a.type==="as")&&u===0)break;(a.type==="("||a.type==="["||a.type==="{")&&u++,(a.type===")"||a.type==="]"||a.type==="}")&&u--,h.push(i())}h.push({type:"eof",value:"",pos:0});let f=new J(h).parse(),c;if(o().type==="as")if(i(),o().type==="("){i();let a=[];for(;o().type!==")"&&o().type!=="eof";)(o().type==="ident"||o().type==="string")&&(a.push(o().value),i()),o().type===","&&i();o().type===")"&&i(),c=a}else if(o().type==="ident"||o().type==="string")c=o().value,i();else throw new Error(`Expected name after 'as', got ${o().type}`);else c=e.slice(s[p].pos,s[r-1]?.pos||e.length).trim(),f.type==="identifier"&&(c=f.name);n.push({expr:f,name:c})}return n}function _(e){let t=new q(e).tokenize();return new J(t).parse()}var R,J,U=Ve(()=>{"use strict";qe();R={PIPE:1,OR:2,AND:3,EQUALITY:4,COMPARISON:5,ADDITIVE:6,MULTIPLICATIVE:7,POWER:8,UNARY:9,POSTFIX:10},J=class{pos=0;tokens;constructor(n){this.tokens=n}parse(){let n=this.parseExpr(0);if(this.peek().type!=="eof")throw new Error(`Unexpected token: ${this.peek().value}`);return n}parseExpr(n){let t=this.parsePrefix();for(;;){let s=this.peek(),r=this.getInfixPrec(s.type);if(r<n)break;t=this.parseInfix(t,r)}return t}parsePrefix(){let n=this.peek();switch(n.type){case"int":return this.advance(),{type:"int",value:Number.parseInt(n.value,10)};case"float":return this.advance(),{type:"float",value:Number.parseFloat(n.value)};case"string":return this.advance(),{type:"string",value:n.value};case"regex":{this.advance();let t=n.value.split("/"),s=t.length>1?t[t.length-1]:"";return{type:"regex",pattern:t.slice(0,-1).join("/")||n.value,caseInsensitive:s.includes("i")}}case"true":return this.advance(),{type:"bool",value:!0};case"false":return this.advance(),{type:"bool",value:!1};case"null":return this.advance(),{type:"null"};case"_":return this.advance(),{type:"underscore"};case"ident":{let t=n.value,s=t.endsWith("?"),r=s?t.slice(0,-1):t;if(this.advance(),this.peek().type==="(")return this.parseFunctionCall(r);if(this.peek().type==="=>"){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:[r],body:o},[r])}return{type:"identifier",name:r,unsure:s}}case"(":{this.advance();let t=[];if(this.peek().type===")"){if(this.advance(),this.peek().type==="=>"){this.advance();let r=this.parseExpr(0);return{type:"lambda",params:[],body:r}}throw new Error("Empty parentheses not allowed")}if(this.peek().type==="ident"){let r=this.peek().value;if(this.advance(),this.peek().type===","||this.peek().type===")"){for(t.push(r);this.peek().type===","&&(this.advance(),this.peek().type==="ident");)t.push(this.peek().value),this.advance();if(this.peek().type===")"&&(this.advance(),this.peek().type==="=>")){this.advance();let o=this.parseExpr(0);return this.bindLambdaArgs({type:"lambda",params:t,body:o},t)}this.pos-=t.length*2,t.length>1&&(this.pos=this.pos)}this.pos--}let s=this.parseExpr(0);return this.expect(")"),this.peek().type,s}case"[":return this.parseList();case"{":return this.parseMap();case"-":{this.advance();let t=this.parseExpr(R.UNARY);return t.type==="int"?{type:"int",value:-t.value}:t.type==="float"?{type:"float",value:-t.value}:{type:"func",name:"neg",args:[{expr:t}]}}case"!":return this.advance(),{type:"func",name:"not",args:[{expr:this.parseExpr(R.UNARY)}]};default:throw new Error(`Unexpected token: ${n.type} (${n.value})`)}}parseFunctionCall(n){this.expect("(");let t=[];if(this.peek().type!==")")do{t.length>0&&this.peek().type===","&&this.advance();let s;if(this.peek().type==="ident"){let o=this.peek().value,i=this.pos+1;i<this.tokens.length&&this.tokens[i].type==="="&&(s=o,this.advance(),this.advance())}let r=this.parseExpr(0);t.push({name:s,expr:r})}while(this.peek().type===",");return this.expect(")"),{type:"func",name:n.toLowerCase(),args:t}}parseList(){this.expect("[");let n=[];if(this.peek().type!=="]")do n.length>0&&this.peek().type===","&&this.advance(),n.push(this.parseExpr(0));while(this.peek().type===",");return this.expect("]"),{type:"list",elements:n}}parseMap(){this.expect("{");let n=[];if(this.peek().type!=="}")do{n.length>0&&this.peek().type===","&&this.advance();let t;if(this.peek().type==="ident")t=this.peek().value,this.advance();else if(this.peek().type==="string")t=this.peek().value,this.advance();else throw new Error(`Expected map key, got ${this.peek().type}`);this.expect(":");let s=this.parseExpr(0);n.push({key:t,value:s})}while(this.peek().type===",");return this.expect("}"),{type:"map",entries:n}}parseInfix(n,t){let s=this.peek(),o=new Map([["+","add"],["-","sub"],["*","mul"],["/","div"],["//","idiv"],["%","mod"],["**","pow"],["++","concat"],["==","=="],["!=","!="],["<","<"],["<=","<="],[">",">"],[">=",">="],["eq","eq"],["ne","ne"],["lt","lt"],["le","le"],["gt","gt"],["ge","ge"],["&&","and"],["and","and"],["||","or"],["or","or"]]).get(s.type);if(o!==void 0){this.advance();let i=this.parseExpr(t+(this.isRightAssoc(s.type)?0:1));return{type:"func",name:o,args:[{expr:n},{expr:i}]}}if(s.type==="|"){this.advance();let i=this.parseExpr(t);return this.handlePipe(n,i)}if(s.type===".")return this.advance(),this.handleDot(n);if(s.type==="[")return this.advance(),this.handleIndexing(n);if(s.type==="in")return this.advance(),{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]};if(s.type==="not in")return this.advance(),{type:"func",name:"not",args:[{expr:{type:"func",name:"contains",args:[{expr:this.parseExpr(t+1)},{expr:n}]}}]};throw new Error(`Unexpected infix token: ${s.type}`)}handlePipe(n,t){if(t.type==="identifier")return{type:"func",name:t.name,args:[{expr:n}]};if(t.type==="func"){let s=this.countUnderscores(t);return s===0?t:s===1?this.fillUnderscore(t,n):{type:"pipeline",exprs:[n,t]}}return this.countUnderscores(t)===1?this.fillUnderscore(t,n):t}handleDot(n){let t=this.peek();if(t.type==="ident"){let s=t.value;if(this.advance(),this.peek().type==="("){let r=this.parseFunctionCall(s);return r.type==="func"&&r.args.unshift({expr:n}),r}return{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}if(t.type==="int"){let s=Number.parseInt(t.value,10);return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"int",value:s}}]}}if(t.type==="string"){let s=t.value;return this.advance(),{type:"func",name:"get",args:[{expr:n},{expr:{type:"string",value:s}}]}}throw new Error(`Expected identifier, number, or string after dot, got ${t.type}`)}handleIndexing(n){if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:{type:"int",value:0}},{expr:s}]}}let t=this.parseExpr(0);if(this.peek().type===":"){if(this.advance(),this.peek().type==="]")return this.advance(),{type:"func",name:"slice",args:[{expr:n},{expr:t}]};let s=this.parseExpr(0);return this.expect("]"),{type:"func",name:"slice",args:[{expr:n},{expr:t},{expr:s}]}}return this.expect("]"),{type:"func",name:"get",args:[{expr:n},{expr:t}]}}countUnderscores(n){return n.type==="underscore"?1:n.type==="func"?n.args.reduce((t,s)=>t+this.countUnderscores(s.expr),0):n.type==="list"?n.elements.reduce((t,s)=>t+this.countUnderscores(s),0):n.type==="map"?n.entries.reduce((t,s)=>t+this.countUnderscores(s.value),0):0}fillUnderscore(n,t){return n.type==="underscore"?t:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.fillUnderscore(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.fillUnderscore(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.fillUnderscore(s.value,t)}))}:n}bindLambdaArgs(n,t){return{...n,body:this.bindLambdaArgsInExpr(n.body,t)}}bindLambdaArgsInExpr(n,t){return n.type==="identifier"&&t.includes(n.name)?{type:"lambdaBinding",name:n.name}:n.type==="func"?{...n,args:n.args.map(s=>({...s,expr:this.bindLambdaArgsInExpr(s.expr,t)}))}:n.type==="list"?{...n,elements:n.elements.map(s=>this.bindLambdaArgsInExpr(s,t))}:n.type==="map"?{...n,entries:n.entries.map(s=>({...s,value:this.bindLambdaArgsInExpr(s.value,t)}))}:n}getInfixPrec(n){switch(n){case"|":return R.PIPE;case"||":case"or":return R.OR;case"&&":case"and":return R.AND;case"==":case"!=":case"eq":case"ne":return R.EQUALITY;case"<":case"<=":case">":case">=":case"lt":case"le":case"gt":case"ge":case"in":case"not in":return R.COMPARISON;case"+":case"-":case"++":return R.ADDITIVE;case"*":case"/":case"//":case"%":return R.MULTIPLICATIVE;case"**":return R.POWER;case".":case"[":return R.POSTFIX;default:return-1}}isRightAssoc(n){return n==="**"}peek(){return this.tokens[this.pos]||{type:"eof",value:"",pos:0}}advance(){return this.tokens[this.pos++]}expect(n){let t=this.peek();if(t.type!==n)throw new Error(`Expected ${n}, got ${t.type}`);return this.advance()}}});U();function E(e,n){return n.length===0?k(e,[]):n.length===1?{type:"Pipe",left:n[0],right:k(e,[])}:{type:"Pipe",left:n[0],right:k(e,n.slice(1))}}var Y={add:e=>S("+",e[0],e[1]),sub:e=>S("-",e[0],e[1]),mul:e=>S("*",e[0],e[1]),div:e=>S("/",e[0],e[1]),mod:e=>S("%",e[0],e[1]),idiv:e=>k("floor",[S("/",e[0],e[1])]),pow:e=>E("pow",e),neg:e=>({type:"UnaryOp",op:"-",operand:e[0]}),"==":e=>S("==",e[0],e[1]),"!=":e=>S("!=",e[0],e[1]),"<":e=>S("<",e[0],e[1]),"<=":e=>S("<=",e[0],e[1]),">":e=>S(">",e[0],e[1]),">=":e=>S(">=",e[0],e[1]),eq:e=>S("==",P(e[0]),P(e[1])),ne:e=>S("!=",P(e[0]),P(e[1])),lt:e=>S("<",P(e[0]),P(e[1])),le:e=>S("<=",P(e[0]),P(e[1])),gt:e=>S(">",P(e[0]),P(e[1])),ge:e=>S(">=",P(e[0]),P(e[1])),and:e=>S("and",e[0],e[1]),or:e=>S("or",e[0],e[1]),not:e=>({type:"UnaryOp",op:"not",operand:e[0]}),len:e=>E("length",e),length:e=>E("length",e),upper:e=>E("ascii_upcase",e),lower:e=>E("ascii_downcase",e),trim:e=>E("trim",e),ltrim:e=>e.length===0?k("ltrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("ltrimstr",[{type:"Literal",value:" "}])},rtrim:e=>e.length===0?k("rtrimstr",[{type:"Literal",value:" "}]):{type:"Pipe",left:e[0],right:k("rtrimstr",[{type:"Literal",value:" "}])},split:e=>E("split",e),join:e=>e.length===1?k("join",[{type:"Literal",value:""}]):E("join",e),concat:e=>S("+",e[0],e[1]),startswith:e=>E("startswith",e),endswith:e=>E("endswith",e),contains:e=>E("contains",e),replace:e=>E("gsub",e),substr:e=>e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:S("+",e[1],e[2])},abs:e=>E("fabs",e),floor:e=>E("floor",e),ceil:e=>E("ceil",e),round:e=>E("round",e),sqrt:e=>E("sqrt",e),log:e=>E("log",e),log10:e=>E("log10",e),log2:e=>E("log2",e),exp:e=>E("exp",e),sin:e=>E("sin",e),cos:e=>E("cos",e),tan:e=>E("tan",e),asin:e=>E("asin",e),acos:e=>E("acos",e),atan:e=>E("atan",e),min:e=>E("min",e),max:e=>E("max",e),first:e=>e.length===0?{type:"Index",index:{type:"Literal",value:0}}:{type:"Index",index:{type:"Literal",value:0},base:e[0]},last:e=>e.length===0?{type:"Index",index:{type:"Literal",value:-1}}:{type:"Index",index:{type:"Literal",value:-1},base:e[0]},get:e=>e.length===1?{type:"Index",index:e[0]}:{type:"Index",index:e[1],base:e[0]},slice:e=>e.length===1?{type:"Slice",base:e[0]}:e.length===2?{type:"Slice",base:e[0],start:e[1]}:{type:"Slice",base:e[0],start:e[1],end:e[2]},keys:"keys",values:"values",entries:e=>k("to_entries",e),from_entries:"from_entries",reverse:"reverse",sort:"sort",sort_by:"sort_by",group_by:"group_by",unique:"unique",unique_by:"unique_by",flatten:"flatten",map:e=>({type:"Pipe",left:e[0],right:{type:"Array",elements:e[1]}}),select:e=>k("select",e),empty:()=>k("empty",[]),count:()=>k("length",[]),sum:e=>e.length===0?k("add",[]):{type:"Pipe",left:{type:"Array",elements:e[0]},right:k("add",[])},mean:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},avg:e=>e.length===0?{type:"Pipe",left:{type:"Identity"},right:S("/",k("add",[]),k("length",[]))}:{type:"Pipe",left:{type:"Array",elements:e[0]},right:S("/",k("add",[]),k("length",[]))},type:"type",isnull:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:null}):S("==",e[0],{type:"Literal",value:null}),isempty:e=>e.length===0?S("==",{type:"Identity"},{type:"Literal",value:""}):S("==",e[0],{type:"Literal",value:""}),tonumber:e=>e.length===0?k("tonumber",[]):k("tonumber",e),tostring:e=>e.length===0?k("tostring",[]):k("tostring",e),if:e=>He(e[0],e[1],e[2]),coalesce:e=>{if(e.length===0)return{type:"Literal",value:null};if(e.length===1)return e[0];let[n,...t]=e,s=S("and",S("!=",n,{type:"Literal",value:null}),S("!=",n,{type:"Literal",value:""}));return He(s,n,t.length===1?t[0]:Y.coalesce(t))},index:()=>({type:"Field",name:"_row_index"}),now:()=>k("now",[]),fmt:e=>k("tostring",e),format:e=>k("tostring",e)};function S(e,n,t){return{type:"BinaryOp",op:e,left:n,right:t}}function k(e,n){return{type:"Call",name:e,args:n}}var et="then";function He(e,n,t){let s={type:"Cond",cond:e,elifs:[],else:t||{type:"Literal",value:null}};return s[et]=n,s}function P(e){return{type:"Pipe",left:e,right:{type:"Call",name:"tostring",args:[]}}}function L(e,n=!0){switch(e.type){case"int":case"float":return{type:"Literal",value:e.value};case"string":return{type:"Literal",value:e.value};case"bool":return{type:"Literal",value:e.value};case"null":return{type:"Literal",value:null};case"underscore":return{type:"Index",base:{type:"Identity"},index:{type:"Literal",value:"_"}};case"identifier":return n?{type:"Field",name:e.name}:{type:"VarRef",name:e.name};case"lambdaBinding":return{type:"VarRef",name:e.name};case"func":{let t=e.args.map(r=>L(r.expr,n)),s=Object.hasOwn(Y,e.name)?Y[e.name]:void 0;return typeof s=="function"?s(t):k(typeof s=="string"?s:e.name,t)}case"list":return e.elements.length===0?{type:"Array"}:{type:"Array",elements:e.elements.reduce((t,s,r)=>{let o=L(s,n);return r===0?o:{type:"Comma",left:t,right:o}},null)};case"map":return{type:"Object",entries:e.entries.map(t=>({key:t.key,value:L(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?L(e.start,n):void 0,end:e.end?L(e.end,n):void 0};case"lambda":return L(e.body,n);case"pipeline":return{type:"Identity"};default:throw new Error(`Unknown moonblade expression type: ${e.type}`)}}function Z(e){let n=[],t=0;for(;t<e.length;){for(;t<e.length&&(e[t]===" "||e[t]===",");)t++;if(t>=e.length)break;let s=t;for(;t<e.length&&/\w/.test(e[t]);)t++;let r=e.slice(s,t);for(;t<e.length&&e[t]===" ";)t++;if(e[t]!=="(")break;t++;let o=1,i=t;for(;t<e.length&&o>0;)e[t]==="("?o++:e[t]===")"&&o--,o>0&&t++;let h=e.slice(i,t).trim();for(t++;t<e.length&&e[t]===" ";)t++;let u="";if(e.slice(t,t+3).toLowerCase()==="as "){for(t+=3;t<e.length&&e[t]===" ";)t++;let p=t;for(;t<e.length&&/\w/.test(e[t]);)t++;u=e.slice(p,t)}u||(u=h?`${r}(${h})`:`${r}()`),n.push({func:r,expr:h,alias:u})}return n}function Je(e){return/^\w+$/.test(e)}function B(e,n,t){let s=L(_(n)),r=$(e,s,t);return r.length>0?r[0]:null}function Q(e,n,t={}){let{func:s,expr:r}=n;if(s==="count"&&!r)return e.length;let o;switch(Je(r)?o=e.map(i=>i[r]).filter(i=>i!=null):o=e.map(i=>B(i,r,t)).filter(i=>i!=null),s){case"count":return Je(r)?o.length:o.filter(i=>!!i).length;case"sum":return o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h))).reduce((h,u)=>h+u,0);case"mean":case"avg":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?i.reduce((h,u)=>h+u,0)/i.length:0}case"min":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.min(...i):null}case"max":{let i=o.map(h=>typeof h=="number"?h:Number.parseFloat(String(h)));return i.length>0?Math.max(...i):null}case"first":return o.length>0?o[0]:null;case"last":return o.length>0?o[o.length-1]:null;case"median":{let i=o.map(u=>typeof u=="number"?u:Number.parseFloat(String(u))).filter(u=>!Number.isNaN(u)).sort((u,p)=>u-p);if(i.length===0)return null;let h=Math.floor(i.length/2);return i.length%2===0?(i[h-1]+i[h])/2:i[h]}case"mode":{let i=new Map;for(let p of o){let l=String(p);i.set(l,(i.get(l)||0)+1)}let h=0,u=null;for(let[p,l]of i)l>h&&(h=l,u=p);return u}case"cardinality":return new Set(o.map(h=>String(h))).size;case"values":return o.map(i=>String(i)).join("|");case"distinct_values":return[...new Set(o.map(h=>String(h)))].sort().join("|");case"all":{if(e.length===0)return!0;for(let i of e)if(!B(i,r,t))return!1;return!0}case"any":{for(let i of e)if(B(i,r,t))return!0;return!1}default:return null}}function ze(e,n,t={}){let s=F();for(let r of n)b(s,r.alias,Q(e,r,t));return s}async function ee(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan agg: no aggregation expression
|
|
6
|
-
`,exitCode:1};let{data:r,error:o}=await v(s,n);if(o)return o;let i={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},h=
|
|
7
|
-
`,exitCode:1};let{data:o,error:i}=await v(r,n);if(i)return i;let h={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},u=t.split(","),p=
|
|
8
|
-
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=z(t,r),u=o.map(p=>{let l=
|
|
9
|
-
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=new Set(z(t,r)),u=r.filter(l=>!h.has(l)),p=o.map(l=>{let f=
|
|
10
|
-
`,exitCode:1};let{headers:o,data:i,error:h}=await v(r,n);if(h)return h;let u;if(s){let l=s.split(","),f=t.split(","),c=new Map;for(let a=0;a<l.length&&a<f.length;a++)c.set(l[a],f[a]);u=o.map(a=>c.get(a)||a)}else{let l=t.split(",");u=o.map((f,c)=>c<l.length?l[c]:f)}let p=i.map(l=>{let f=
|
|
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 F(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=>F(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=F(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:F(t.value,n)}))};case"regex":return{type:"Literal",value:e.pattern};case"slice":return{type:"Slice",start:e.start?F(e.start,n):void 0,end:e.end?F(e.end,n):void 0};case"lambda":return F(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=F(_(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=O();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
|
|
6
|
+
`,exitCode:1};let{data:r,error:o}=await v(s,n);if(o)return o;let i={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},h=Q(t),u=h.map(l=>l.alias),p=Ke(r,h,i);return{stdout:w(u,[p]),stderr:"",exitCode:0}}async function ne(e,n){let t="",s="",r=[];for(let d=0;d<e.length;d++){let m=e[d];m==="--sorted"||m.startsWith("-")||(t?s?r.push(m):s=m:t=m)}if(!t||!s)return{stdout:"",stderr:`xan groupby: usage: xan groupby COLS EXPR [FILE]
|
|
7
|
+
`,exitCode:1};let{data:o,error:i}=await v(r,n);if(i)return i;let h={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},u=t.split(","),p=Q(s),l=[],f=new Map;for(let d of o){let m=u.map(g=>String(d[g])).join("\0");f.has(m)||(f.set(m,[]),l.push(m)),f.get(m)?.push(d)}let c=[...u,...p.map(d=>d.alias)],a=[];for(let d of l){let m=f.get(d);if(!m)continue;let g=O();for(let y of u)b(g,y,m[0][y]);for(let y of p)b(g,y.alias,ee(m,y,h));a.push(g)}return{stdout:w(c,a),stderr:"",exitCode:0}}async function se(e,n){let t=[],s="",r=10,o=!1,i=[];for(let a=0;a<e.length;a++){let d=e[a];(d==="-s"||d==="--select")&&a+1<e.length?t=e[++a].split(","):(d==="-g"||d==="--groupby")&&a+1<e.length?s=e[++a]:(d==="-l"||d==="--limit")&&a+1<e.length?r=Number.parseInt(e[++a],10):d==="--no-extra"?o=!0:d==="-A"||d==="--all"?r=0:d.startsWith("-")||i.push(d)}let{headers:h,data:u,error:p}=await v(i,n);if(p)return p;let l=t.length>0?t:h.filter(a=>a!==s);s&&t.length===0&&(l=h.filter(a=>a!==s));let f=[],c=s?["field",s,"value","count"]:["field","value","count"];if(s){let a=new Map;for(let d of u){let m=String(d[s]??"");a.has(m)||a.set(m,[]),a.get(m)?.push(d)}for(let d of l)for(let[m,g]of a){let y=new Map;for(let I of g){let N=I[d],C=N===""||N===null||N===void 0?"":String(N);y.set(C,(y.get(C)||0)+1)}let x=[...y.entries()].sort((I,N)=>N[1]!==I[1]?N[1]-I[1]:I[0].localeCompare(N[0]));o&&(x=x.filter(([I])=>I!=="")),r>0&&(x=x.slice(0,r));for(let[I,N]of x)f.push({field:d,[s]:m,value:I===""?"<empty>":I,count:N})}}else for(let a of l){let d=new Map;for(let g of u){let y=g[a],x=y===""||y===null||y===void 0?"":String(y);d.set(x,(d.get(x)||0)+1)}let m=[...d.entries()].sort((g,y)=>y[1]!==g[1]?y[1]-g[1]:g[0].localeCompare(y[0]));o&&(m=m.filter(([g])=>g!=="")),r>0&&(m=m.slice(0,r));for(let[g,y]of m)f.push({field:a,value:g===""?"<empty>":g,count:y})}return{stdout:w(c,f),stderr:"",exitCode:0}}async function re(e,n){let t=[],s=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-s"&&l+1<e.length?t=e[++l].split(","):f.startsWith("-")||s.push(f)}let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=t.length>0?t:r,u=["field","type","count","min","max","mean"],p=[];for(let l of h){let f=o.map(d=>d[l]).filter(d=>d!=null),c=f.map(d=>typeof d=="number"?d:Number.parseFloat(String(d))).filter(d=>!Number.isNaN(d)),a=c.length===f.length&&c.length>0;p.push({field:l,type:a?"Number":"String",count:f.length,min:a?Math.min(...c):"",max:a?Math.max(...c):"",mean:a?Math.round(c.reduce((d,m)=>d+m,0)/c.length*1e10)/1e10:""})}return{stdout:w(u,p),stderr:"",exitCode:0}}U();function Ge(e){let n=_(e);return F(n)}function nt(e){let t=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return H(`^${t}$`)}function z(e,n){let t=[],s=new Set;for(let r of e.split(",")){let o=r.trim();if(o.startsWith("!")){let p=o.slice(1),l=z(p,n);for(let f of l)s.add(f);continue}if(o==="*"){for(let p of n)t.includes(p)||t.push(p);continue}if(o.includes("*")){let p=nt(o);for(let l of n)p.test(l)&&!t.includes(l)&&t.push(l);continue}let i=o.match(/^([^:]*):([^:]*)$/);if(i&&(i[1]||i[2])){let p=i[1],l=i[2],f=p?n.indexOf(p):0,c=l?n.indexOf(l):n.length-1;if(f!==-1&&c!==-1){let a=f<=c?1:-1;for(let d=f;a>0?d<=c:d>=c;d+=a)t.includes(n[d])||t.push(n[d])}continue}let h=o.match(/^(\d+)-(\d+)$/);if(h){let p=Number.parseInt(h[1],10),l=Number.parseInt(h[2],10);for(let f=p;f<=l&&f<n.length;f++)t.push(n[f]);continue}let u=Number.parseInt(o,10);if(!Number.isNaN(u)&&u>=0&&u<n.length){t.push(n[u]);continue}n.includes(o)&&t.push(o)}return s.size>0?t.filter(r=>!s.has(r)):t}async function oe(e,n){let t="",s=[];for(let p of e)p.startsWith("-")||(t?s.push(p):t=p);if(!t)return{stdout:"",stderr:`xan select: no columns specified
|
|
8
|
+
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=z(t,r),u=o.map(p=>{let l=O();for(let f of h)b(l,f,p[f]);return l});return{stdout:w(h,u),stderr:"",exitCode:0}}async function ie(e,n){let t="",s=[];for(let l of e)l.startsWith("-")||(t?s.push(l):t=l);if(!t)return{stdout:"",stderr:`xan drop: no columns specified
|
|
9
|
+
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=new Set(z(t,r)),u=r.filter(l=>!h.has(l)),p=o.map(l=>{let f=O();for(let c of u)b(f,c,l[c]);return f});return{stdout:w(u,p),stderr:"",exitCode:0}}async function ae(e,n){let t="",s="",r=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-s"&&l+1<e.length?s=e[++l]:f.startsWith("-")||(t?r.push(f):t=f)}if(!t)return{stdout:"",stderr:`xan rename: no new name(s) specified
|
|
10
|
+
`,exitCode:1};let{headers:o,data:i,error:h}=await v(r,n);if(h)return h;let u;if(s){let l=s.split(","),f=t.split(","),c=new Map;for(let a=0;a<l.length&&a<f.length;a++)c.set(l[a],f[a]);u=o.map(a=>c.get(a)||a)}else{let l=t.split(",");u=o.map((f,c)=>c<l.length?l[c]:f)}let p=i.map(l=>{let f=O();for(let c=0;c<o.length;c++)b(f,u[c],l[o[c]]);return f});return{stdout:w(u,p),stderr:"",exitCode:0}}async function le(e,n){let t="index",s=[];for(let p=0;p<e.length;p++)e[p]==="-c"&&p+1<e.length?t=e[++p]:s.push(e[p]);let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=[t,...r],u=o.map((p,l)=>{let f=O();b(f,t,l);for(let c of r)b(f,c,p[c]);return f});return{stdout:w(h,u),stderr:"",exitCode:0}}async function ue(e,n){let t=e.includes("-j")||e.includes("--just-names"),{headers:s,error:r}=await v(e.filter(i=>i!=="-j"&&i!=="--just-names"),n);return r||{stdout:t?`${s.map(i=>i).join(`
|
|
11
11
|
`)}
|
|
12
12
|
`:`${s.map((i,h)=>`${h} ${i}`).join(`
|
|
13
13
|
`)}
|
|
14
|
-
`,stderr:"",exitCode:0}}async function
|
|
15
|
-
`,stderr:"",exitCode:0}}async function
|
|
16
|
-
`,exitCode:1}}let u=
|
|
14
|
+
`,stderr:"",exitCode:0}}async function ce(e,n){let{data:t,error:s}=await v(e,n);return s||{stdout:`${t.length}
|
|
15
|
+
`,stderr:"",exitCode:0}}async function pe(e,n){let t=10,s=[];for(let u=0;u<e.length;u++)(e[u]==="-l"||e[u]==="-n")&&u+1<e.length?t=Number.parseInt(e[++u],10):s.push(e[u]);let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=o.slice(0,t);return{stdout:w(r,h),stderr:"",exitCode:0}}async function fe(e,n){let t=10,s=[];for(let u=0;u<e.length;u++)(e[u]==="-l"||e[u]==="-n")&&u+1<e.length?t=Number.parseInt(e[++u],10):s.push(e[u]);let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=o.slice(-t);return{stdout:w(r,h),stderr:"",exitCode:0}}async function de(e,n){let t,s,r,o=[];for(let c=0;c<e.length;c++){let a=e[c];(a==="-s"||a==="--start")&&c+1<e.length?t=Number.parseInt(e[++c],10):(a==="-e"||a==="--end")&&c+1<e.length?s=Number.parseInt(e[++c],10):(a==="-l"||a==="--len")&&c+1<e.length?r=Number.parseInt(e[++c],10):a.startsWith("-")||o.push(a)}let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let p=t??0,l;r!==void 0?l=p+r:s!==void 0?l=s:l=h.length;let f=h.slice(p,l);return{stdout:w(i,f),stderr:"",exitCode:0}}async function he(e,n){let{headers:t,data:s,error:r}=await v(e,n);if(r)return r;let o=[...s].reverse();return{stdout:w(t,o),stderr:"",exitCode:0}}var me=Ze(et(),1);async function ge(e,n){let t=e.filter(p=>!p.startsWith("-")),{headers:s,data:r,error:o}=await v(t,n);if(o)return o;if(r.length===0){let p=["column"],l=s.map(f=>({column:f}));return{stdout:w(p,l),stderr:"",exitCode:0}}let i=s[0],h=[i,...r.map((p,l)=>String(p[i]??`row_${l}`))],u=[];for(let p=1;p<s.length;p++){let l=s[p],f=O();b(f,i,l);for(let c=0;c<r.length;c++)b(f,h[c+1],r[c][l]);u.push(f)}return{stdout:w(h,u),stderr:"",exitCode:0}}async function ye(e,n){let t=null,s=[];for(let l=0;l<e.length;l++){let f=e[l];f==="--seed"&&l+1<e.length?t=Number.parseInt(e[++l],10):f.startsWith("-")||s.push(f)}let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=t!==null?t:Date.now(),u=()=>(h=h*1103515245+12345&2147483647,h/2147483647),p=[...o];for(let l=p.length-1;l>0;l--){let f=Math.floor(u()*(l+1));[p[l],p[f]]=[p[f],p[l]]}return{stdout:w(r,p),stderr:"",exitCode:0}}async function xe(e,n){let t=null,s="",r=[];for(let a=0;a<e.length;a++){let d=e[a];(d==="-l"||d==="--length")&&a+1<e.length?t=Number.parseInt(e[++a],10):(d==="-d"||d==="--default")&&a+1<e.length?s=e[++a]:d.startsWith("-")||r.push(d)}let o=r[0],i;if(!o||o==="-")i=n.stdin;else try{let a=n.fs.resolvePath(n.cwd,o);i=await n.fs.readFile(a)}catch{return{stdout:"",stderr:`xan fixlengths: ${o}: No such file or directory
|
|
16
|
+
`,exitCode:1}}let u=me.default.parse(i.trim(),{header:!1,skipEmptyLines:!0}).data;if(u.length===0)return{stdout:"",stderr:"",exitCode:0};let p=Math.max(...u.map(a=>a.length)),l=t??p,f=u.map(a=>a.length===l?a:a.length<l?[...a,...Array(l-a.length).fill(s)]:a.slice(0,l));return{stdout:`${me.default.unparse(f).replace(/\r\n/g,`
|
|
17
17
|
`)}
|
|
18
|
-
`,stderr:"",exitCode:0}}async function
|
|
18
|
+
`,stderr:"",exitCode:0}}async function we(e,n){let t=null,s=null,r=".",o=[];for(let c=0;c<e.length;c++){let a=e[c];(a==="-c"||a==="--chunks")&&c+1<e.length?t=Number.parseInt(e[++c],10):(a==="-S"||a==="--size")&&c+1<e.length?s=Number.parseInt(e[++c],10):(a==="-o"||a==="--output")&&c+1<e.length?r=e[++c]:a.startsWith("-")||o.push(a)}if(!t&&!s)return{stdout:"",stderr:`xan split: must specify -c or -S
|
|
19
19
|
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let p=[];if(t){let c=Math.ceil(h.length/t);for(let a=0;a<t;a++)p.push(h.slice(a*c,(a+1)*c))}else if(s)for(let c=0;c<h.length;c+=s)p.push(h.slice(c,c+s));let l=p.filter(c=>c.length>0),f=o[0]?.replace(/\.csv$/,"")||"part";try{let c=n.fs.resolvePath(n.cwd,r);for(let a=0;a<l.length;a++){let d=`${f}_${String(a+1).padStart(3,"0")}.csv`,m=n.fs.resolvePath(c,d);await n.fs.writeFile(m,w(i,l[a]))}return{stdout:`Split into ${l.length} parts
|
|
20
20
|
`,stderr:"",exitCode:0}}catch{return{stdout:`${l.map((a,d)=>`Part ${d+1}: ${a.length} rows`).join(`
|
|
21
21
|
`)}
|
|
22
|
-
`,stderr:"",exitCode:0}}}async function
|
|
22
|
+
`,stderr:"",exitCode:0}}}async function ve(e,n){let t="",s=".",r=[];for(let p=0;p<e.length;p++){let l=e[p];(l==="-o"||l==="--output")&&p+1<e.length?s=e[++p]:l.startsWith("-")||(t?r.push(l):t=l)}if(!t)return{stdout:"",stderr:`xan partition: usage: xan partition COLUMN [FILE]
|
|
23
23
|
`,exitCode:1};let{headers:o,data:i,error:h}=await v(r,n);if(h)return h;if(!o.includes(t))return{stdout:"",stderr:`xan partition: column '${t}' not found
|
|
24
24
|
`,exitCode:1};let u=new Map;for(let p of i){let l=String(p[t]??"");u.has(l)||u.set(l,[]),u.get(l)?.push(p)}try{let p=n.fs.resolvePath(n.cwd,s);for(let[l,f]of u){let a=`${l.replace(/[^a-zA-Z0-9_-]/g,"_")||"empty"}.csv`,d=n.fs.resolvePath(p,a);await n.fs.writeFile(d,w(o,f))}return{stdout:`Partitioned into ${u.size} files by '${t}'
|
|
25
25
|
`,stderr:"",exitCode:0}}catch{return{stdout:`${Array.from(u.entries()).map(([l,f])=>`${l}: ${f.length} rows`).join(`
|
|
26
26
|
`)}
|
|
27
|
-
`,stderr:"",exitCode:0}}}async function
|
|
28
|
-
`,exitCode:1};let t=e[0],s=e.slice(1);return t==="json"?
|
|
29
|
-
`,exitCode:1}}async function
|
|
30
|
-
`,stderr:"",exitCode:0}}async function
|
|
27
|
+
`,stderr:"",exitCode:0}}}async function Ce(e,n){if(e.length===0)return{stdout:"",stderr:`xan to: usage: xan to <format> [FILE]
|
|
28
|
+
`,exitCode:1};let t=e[0],s=e.slice(1);return t==="json"?st(s,n):{stdout:"",stderr:`xan to: unsupported format '${t}'
|
|
29
|
+
`,exitCode:1}}async function st(e,n){let t=e.filter(i=>!i.startsWith("-")),{data:s,error:r}=await v(t,n);return r||{stdout:`${JSON.stringify(s,null,2)}
|
|
30
|
+
`,stderr:"",exitCode:0}}async function be(e,n){let t="",s=[];for(let r=0;r<e.length;r++){let o=e[r];(o==="-f"||o==="--format")&&r+1<e.length?t=e[++r]:o.startsWith("-")||s.push(o)}return t?t==="json"?rt(s,n):{stdout:"",stderr:`xan from: unsupported format '${t}'
|
|
31
31
|
`,exitCode:1}:{stdout:"",stderr:`xan from: usage: xan from -f <format> [FILE]
|
|
32
|
-
`,exitCode:1}}async function
|
|
32
|
+
`,exitCode:1}}async function rt(e,n){let t=e[0],s;if(!t||t==="-")s=n.stdin;else try{let r=n.fs.resolvePath(n.cwd,t);s=await n.fs.readFile(r)}catch{return{stdout:"",stderr:`xan from: ${t}: No such file or directory
|
|
33
33
|
`,exitCode:1}}try{let r=JSON.parse(s.trim());if(!Array.isArray(r))return{stdout:"",stderr:`xan from: JSON input must be an array
|
|
34
34
|
`,exitCode:1};if(r.length===0)return{stdout:`
|
|
35
|
-
`,stderr:"",exitCode:0};if(Array.isArray(r[0])){let[i,...h]=r,u=h.map(p=>{let l=
|
|
36
|
-
`,exitCode:1}}}async function
|
|
37
|
-
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let p={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},l=
|
|
38
|
-
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let l=V(t).map(({expr:d,name:m})=>({alias:typeof m=="string"?m:m[0],ast:
|
|
35
|
+
`,stderr:"",exitCode:0};if(Array.isArray(r[0])){let[i,...h]=r,u=h.map(p=>{let l=O();for(let f=0;f<i.length;f++)b(l,i[f],p[f]);return l});return{stdout:w(i,u),stderr:"",exitCode:0}}let o=Object.keys(r[0]).sort();return{stdout:w(o,r),stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`xan from: invalid JSON input
|
|
36
|
+
`,exitCode:1}}}async function Se(e,n){let t=!1,s=0,r="",o=[];for(let c=0;c<e.length;c++){let a=e[c];if(a==="-v"||a==="--invert")t=!0;else if((a==="-l"||a==="--limit")&&c+1<e.length)s=Number.parseInt(e[++c],10);else{if(a==="--help")return D({name:"xan filter",summary:"Filter rows by expression",usage:"xan filter [OPTIONS] EXPR [FILE]",description:"Filter CSV rows using moonblade expressions.",options:["-v, --invert invert match","-l, --limit N limit output to N rows"," --help display help"]});a.startsWith("-")||(r?o.push(a):r=a)}}if(!r)return{stdout:"",stderr:`xan filter: no expression specified
|
|
37
|
+
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let p={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},l=Ge(r),f=[];for(let c of h){if(s>0&&f.length>=s)break;let a=$(c,l,p),d=a.length>0&&a.some(m=>!!m);(t?!d:d)&&f.push(c)}return{stdout:w(i,f),stderr:"",exitCode:0}}async function Ie(e,n){let t="",s=!1,r=!1,o=[];for(let l=0;l<e.length;l++){let f=e[l];f==="-N"||f==="--numeric"?s=!0:f==="-R"||f==="-r"||f==="--reverse"?r=!0:f==="-s"&&l+1<e.length?t=e[++l]:f.startsWith("-")||o.push(f)}let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;!t&&i.length>0&&(t=i[0]);let p=[...h].sort((l,f)=>{let c=l[t],a=f[t],d;if(s){let m=typeof c=="number"?c:Number.parseFloat(String(c)),g=typeof a=="number"?a:Number.parseFloat(String(a));d=m-g}else d=String(c).localeCompare(String(a));return r?-d:d});return{stdout:w(i,p),stderr:"",exitCode:0}}async function ke(e,n){let t="",s=[];for(let p=0;p<e.length;p++){let l=e[p];l==="-s"&&p+1<e.length?t=e[++p]:l.startsWith("-")||s.push(l)}let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let h=new Set,u=o.filter(p=>{let l=t?String(p[t]):JSON.stringify(p);return h.has(l)?!1:(h.add(l),!0)});return{stdout:w(r,u),stderr:"",exitCode:0}}async function Ne(e,n){let t=10,s="",r=!1,o=[];for(let f=0;f<e.length;f++){let c=e[f];(c==="-l"||c==="-n")&&f+1<e.length?t=Number.parseInt(e[++f],10):c==="-R"||c==="-r"||c==="--reverse"?r=!0:c.startsWith("-")||(s?o.push(c):s=c)}let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;!s&&i.length>0&&(s=i[0]);let l=[...h].sort((f,c)=>{let a=f[s],d=c[s],m=typeof a=="number"?a:Number.parseFloat(String(a)),g=typeof d=="number"?d:Number.parseFloat(String(d));return r?m-g:g-m}).slice(0,t);return{stdout:w(i,l),stderr:"",exitCode:0}}U();async function Ee(e,n){let t="",s=!1,r=!1,o=[];for(let d=0;d<e.length;d++){let m=e[d];m==="-O"||m==="--overwrite"?s=!0:m==="--filter"?r=!0:m.startsWith("-")||(t?o.push(m):t=m)}if(!t)return{stdout:"",stderr:`xan map: no expression specified
|
|
38
|
+
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let l=V(t).map(({expr:d,name:m})=>({alias:typeof m=="string"?m:m[0],ast:F(d)})),f={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},c;if(s){c=[...i];for(let d of l)i.includes(d.alias)||c.push(d.alias)}else c=[...i,...l.map(d=>d.alias)];let a=[];for(let d=0;d<h.length;d++){let m=h[d],g=M(m),y=!1,x=Object.assign(G(m),{_row_index:d});for(let I of l){let N=$(x,I.ast,f),C=N.length>0?N[0]:null;if(r&&C==null){y=!0;break}b(g,I.alias,C)}y||a.push(g)}return{stdout:w(c,a),stderr:"",exitCode:0}}async function Ae(e,n){let t="",s="",r="",o=[];for(let m=0;m<e.length;m++){let g=e[m];(g==="-r"||g==="--rename")&&m+1<e.length?r=e[++m]:g.startsWith("-")||(t?s?o.push(g):s=g:t=g)}if(!t||!s)return{stdout:"",stderr:`xan transform: usage: xan transform COLUMN EXPR [FILE]
|
|
39
39
|
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;let p=t.split(",").map(m=>m.trim()),l=r?r.split(",").map(m=>m.trim()):[];for(let m of p)if(!i.includes(m))return{stdout:"",stderr:`xan transform: column '${m}' not found
|
|
40
|
-
`,exitCode:1};let f=
|
|
40
|
+
`,exitCode:1};let f=F(V(s)[0]?.expr||(U(),Qe(He)).parseMoonblade(s)),c={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},a=i.map(m=>{let g=p.indexOf(m);return g!==-1&&l[g]?l[g]:m}),d=[];for(let m of h){let g=M(m);for(let y=0;y<p.length;y++){let x=p[y],I=Object.assign(G(m),{_:m[x]}),N=$(I,f,c),C=N.length>0?N[0]:null,A=l[y]||x;A!==x&&delete g[x],b(g,A,C)}d.push(g)}return{stdout:w(a,d),stderr:"",exitCode:0}}async function Oe(e,n){let t="",s="|",r=!1,o="",i=[];for(let a=0;a<e.length;a++){let d=e[a];(d==="-s"||d==="--separator")&&a+1<e.length?s=e[++a]:d==="--drop-empty"?r=!0:(d==="-r"||d==="--rename")&&a+1<e.length?o=e[++a]:d.startsWith("-")||(t?i.push(d):t=d)}if(!t)return{stdout:"",stderr:`xan explode: usage: xan explode COLUMN [FILE]
|
|
41
41
|
`,exitCode:1};let{headers:h,data:u,error:p}=await v(i,n);if(p)return p;if(!h.includes(t))return{stdout:"",stderr:`xan explode: column '${t}' not found
|
|
42
42
|
`,exitCode:1};let l=o?h.map(a=>a===t?o:a):h,f=o||t,c=[];for(let a of u){let d=a[t],m=d==null?"":String(d);if(m===""){if(!r){let g=M(a);o&&(delete g[t],b(g,f,"")),c.push(g)}}else{let g=m.split(s);for(let y of g){let x=M(a);o&&delete x[t],b(x,f,y),c.push(x)}}}return{stdout:w(l,c),stderr:"",exitCode:0}}async function Fe(e,n){let t="",s="|",r="",o=[];for(let g=0;g<e.length;g++){let y=e[g];(y==="-s"||y==="--sep")&&g+1<e.length?s=e[++g]:(y==="-r"||y==="--rename")&&g+1<e.length?r=e[++g]:y.startsWith("-")||(t?o.push(y):t=y)}if(!t)return{stdout:"",stderr:`xan implode: usage: xan implode COLUMN [FILE]
|
|
43
43
|
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;if(!i.includes(t))return{stdout:"",stderr:`xan implode: column '${t}' not found
|
|
44
44
|
`,exitCode:1};let p=i.filter(g=>g!==t),l=r?i.map(g=>g===t?r:g):i,f=r||t,c=[],a=null,d=[],m=null;for(let g of h){let y=p.map(N=>String(g[N]??"")).join("\0"),x=g[t],I=x==null?"":String(x);if(y!==a){if(m!==null){let N=M(m);r&&delete N[t],b(N,f,d.join(s)),c.push(N)}a=y,d=[I],m=g}else d.push(I)}if(m!==null){let g=M(m);r&&delete g[t],b(g,f,d.join(s)),c.push(g)}return{stdout:w(l,c),stderr:"",exitCode:0}}async function Le(e,n){let t="",s="",r="",o="",i="inner",h="",u=0;for(let C=0;C<e.length;C++){let A=e[C];A==="--left"?i="left":A==="--right"?i="right":A==="--full"?i="full":(A==="-D"||A==="--default")&&C+1<e.length?h=e[++C]:A.startsWith("-")||(u++,u===1?t=A:u===2?s=A:u===3?r=A:u===4&&(o=A))}if(!t||!s||!r||!o)return{stdout:"",stderr:`xan join: usage: xan join KEY1 FILE1 KEY2 FILE2 [OPTIONS]
|
|
45
45
|
`,exitCode:1};let p=await v([s],n);if(p.error)return p.error;let l=await v([o],n);if(l.error)return l.error;let{headers:f,data:c}=p,{headers:a,data:d}=l;if(!f.includes(t))return{stdout:"",stderr:`xan join: column '${t}' not found in first file
|
|
46
46
|
`,exitCode:1};if(!a.includes(r))return{stdout:"",stderr:`xan join: column '${r}' not found in second file
|
|
47
|
-
`,exitCode:1};let m=new Map;for(let C of d){let A=String(C[r]??"");m.has(A)||m.set(A,[]),m.get(A)?.push(C)}let g=new Set(f),y=a.filter(C=>!g.has(C)),x=[...f,...y],I=[],N=new Set;for(let C of c){let A=String(C[t]??""),j=m.get(A);if(j&&j.length>0){N.add(A);for(let
|
|
47
|
+
`,exitCode:1};let m=new Map;for(let C of d){let A=String(C[r]??"");m.has(A)||m.set(A,[]),m.get(A)?.push(C)}let g=new Set(f),y=a.filter(C=>!g.has(C)),x=[...f,...y],I=[],N=new Set;for(let C of c){let A=String(C[t]??""),j=m.get(A);if(j&&j.length>0){N.add(A);for(let L of j){let T=O();for(let W of f)b(T,W,C[W]);for(let W of y)b(T,W,L[W]);I.push(T)}}else if(i==="left"||i==="full"){let L=O();for(let T of f)b(L,T,C[T]);for(let T of y)b(L,T,h);I.push(L)}}if(i==="right"||i==="full")for(let C of d){let A=String(C[r]??"");if(!N.has(A)){let j=O();for(let L of f)b(j,L,a.includes(L)?C[L]:h);for(let L of y)b(j,L,C[L]);I.push(j)}}return{stdout:w(x,I),stderr:"",exitCode:0}}async function Pe(e,n){let t="",s="",r=[],o=[];for(let y=0;y<e.length;y++){let x=e[y];(x==="-g"||x==="--groupby")&&y+1<e.length?r=e[++y].split(",").map(I=>I.trim()):x.startsWith("-")||(t?s?o.push(x):s=x:t=x)}if(!t||!s)return{stdout:"",stderr:`xan pivot: usage: xan pivot COLUMN AGG_EXPR [OPTIONS] [FILE]
|
|
48
48
|
`,exitCode:1};let{headers:i,data:h,error:u}=await v(o,n);if(u)return u;if(!i.includes(t))return{stdout:"",stderr:`xan pivot: column '${t}' not found
|
|
49
49
|
`,exitCode:1};let p=s.match(/^(\w+)\((\w+)\)$/);if(!p)return{stdout:"",stderr:`xan pivot: invalid aggregation expression '${s}'
|
|
50
|
-
`,exitCode:1};let[,l,f]=p;r.length===0&&(r=i.filter(y=>y!==t&&y!==f));let c=[];for(let y of h){let x=String(y[t]??"");c.includes(x)||c.push(x)}let a=new Map,d=[];for(let y of h){let x=r.map(A=>String(y[A]??"")).join("\0"),I=String(y[t]??""),N=y[f];a.has(x)||(a.set(x,new Map),d.push(x));let C=a.get(x);C&&(C.has(I)||C.set(I,[]),C.get(I)?.push(N))}let m=[...r,...c],g=[];for(let y of d){let x=y.split("\0"),I=a.get(y);if(!I)continue;let N=
|
|
50
|
+
`,exitCode:1};let[,l,f]=p;r.length===0&&(r=i.filter(y=>y!==t&&y!==f));let c=[];for(let y of h){let x=String(y[t]??"");c.includes(x)||c.push(x)}let a=new Map,d=[];for(let y of h){let x=r.map(A=>String(y[A]??"")).join("\0"),I=String(y[t]??""),N=y[f];a.has(x)||(a.set(x,new Map),d.push(x));let C=a.get(x);C&&(C.has(I)||C.set(I,[]),C.get(I)?.push(N))}let m=[...r,...c],g=[];for(let y of d){let x=y.split("\0"),I=a.get(y);if(!I)continue;let N=O();for(let C=0;C<r.length;C++)b(N,r[C],x[C]);for(let C of c){let A=I.get(C)||[];b(N,C,ot(l,A))}g.push(N)}return{stdout:w(m,g),stderr:"",exitCode:0}}function ot(e,n){let t=n.filter(s=>s!=null).map(s=>typeof s=="number"?s:Number.parseFloat(String(s))).filter(s=>!Number.isNaN(s));switch(e){case"count":return n.length;case"sum":return t.reduce((s,r)=>s+r,0);case"mean":case"avg":return t.length>0?t.reduce((s,r)=>s+r,0)/t.length:null;case"min":return t.length>0?Math.min(...t):null;case"max":return t.length>0?Math.max(...t):null;case"first":return n.length>0?String(n[0]??""):null;case"last":return n.length>0?String(n[n.length-1]??""):null;default:return null}}async function Re(e,n){let t="",s=[];for(let h=0;h<e.length;h++){let u=e[h];(u==="-s"||u==="--sort")&&h+1<e.length?t=e[++h]:u.startsWith("-")||s.push(u)}if(s.length<2)return{stdout:"",stderr:`xan merge: usage: xan merge [OPTIONS] FILE1 FILE2 ...
|
|
51
51
|
`,exitCode:1};let r=[],o=null;for(let h of s){let u=await v([h],n);if(u.error)return u.error;if(o===null)o=u.headers;else if(JSON.stringify(o)!==JSON.stringify(u.headers))return{stdout:"",stderr:`xan merge: all files must have the same headers
|
|
52
52
|
`,exitCode:1};r.push({headers:u.headers,data:u.data})}if(!o)return{stdout:"",stderr:"",exitCode:0};let i=[];for(let{data:h}of r)i=i.concat(h);if(t){if(!o.includes(t))return{stdout:"",stderr:`xan merge: column '${t}' not found
|
|
53
|
-
`,exitCode:1};i.sort((h,u)=>{let p=h[t],l=u[t],f=typeof p=="number"?p:Number.parseFloat(String(p)),c=typeof l=="number"?l:Number.parseFloat(String(l));return!Number.isNaN(f)&&!Number.isNaN(c)?f-c:String(p??"").localeCompare(String(l??""))})}return{stdout:w(o,i),stderr:"",exitCode:0}}U();async function
|
|
53
|
+
`,exitCode:1};i.sort((h,u)=>{let p=h[t],l=u[t],f=typeof p=="number"?p:Number.parseFloat(String(p)),c=typeof l=="number"?l:Number.parseFloat(String(l));return!Number.isNaN(f)&&!Number.isNaN(c)?f-c:String(p??"").localeCompare(String(l??""))})}return{stdout:w(o,i),stderr:"",exitCode:0}}U();async function Me(e,n){let t=e.filter(u=>!u.startsWith("-")),{headers:s,data:r,error:o}=await v(t,n);return o||(r.length===0?{stdout:"",stderr:"",exitCode:0}:{stdout:r.map(u=>s.map(p=>u[p])).map(u=>u.map(p=>it(p)).join(",")).join(`
|
|
54
54
|
`)+`
|
|
55
|
-
`,stderr:"",exitCode:0})}function
|
|
56
|
-
`)?`"${n.replace(/"/g,'""')}"`:n}async function
|
|
57
|
-
`,exitCode:1};let{headers:o,data:i,error:h}=await v(r,n);if(h)return h;if(i.length<=t)return{stdout:w(o,i),stderr:"",exitCode:0};let u=s!==null?s:Date.now(),p=()=>(u=u*1103515245+12345&2147483647,u/2147483647),l=i.map((c,a)=>a);for(let c=l.length-1;c>0;c--){let a=Math.floor(p()*(c+1));[l[c],l[a]]=[l[a],l[c]]}let f=l.slice(0,t).sort((c,a)=>c-a).map(c=>i[c]);return{stdout:w(o,f),stderr:"",exitCode:0}}async function
|
|
58
|
-
`,exitCode:1};let r=await
|
|
59
|
-
`,exitCode:1};i=o[0].headers}let h=[];for(let{headers:u,data:p}of o)for(let l of p){let f=
|
|
55
|
+
`,stderr:"",exitCode:0})}function it(e){if(e==null)return"";let n=String(e);return n.includes(",")||n.includes('"')||n.includes(`
|
|
56
|
+
`)?`"${n.replace(/"/g,'""')}"`:n}async function $e(e,n){let t=null,s=null,r=[];for(let c=0;c<e.length;c++){let a=e[c];if(a==="--seed"&&c+1<e.length)s=Number.parseInt(e[++c],10);else if(!a.startsWith("-")){let d=Number.parseInt(a,10);t===null&&!Number.isNaN(d)&&d>0?t=d:r.push(a)}}if(t===null)return{stdout:"",stderr:`xan sample: usage: xan sample <sample-size> [FILE]
|
|
57
|
+
`,exitCode:1};let{headers:o,data:i,error:h}=await v(r,n);if(h)return h;if(i.length<=t)return{stdout:w(o,i),stderr:"",exitCode:0};let u=s!==null?s:Date.now(),p=()=>(u=u*1103515245+12345&2147483647,u/2147483647),l=i.map((c,a)=>a);for(let c=l.length-1;c>0;c--){let a=Math.floor(p()*(c+1));[l[c],l[a]]=[l[a],l[c]]}let f=l.slice(0,t).sort((c,a)=>c-a).map(c=>i[c]);return{stdout:w(o,f),stderr:"",exitCode:0}}async function Te(e,n){let t=!1,s=[];for(let u=0;u<e.length;u++){let p=e[u];p==="-p"||p==="--pad"?t=!0:p.startsWith("-")||s.push(p)}if(s.length===0)return{stdout:"",stderr:`xan cat: no files specified
|
|
58
|
+
`,exitCode:1};let r=await We(n,s,{cmdName:"xan cat",stopOnError:!0});if(r.exitCode!==0)return{stdout:"",stderr:r.stderr,exitCode:r.exitCode};let o=[],i=[];for(let{content:u}of r.files){let{headers:p,data:l}=qe(u);o.push({headers:p,data:l});for(let f of p)i.includes(f)||i.push(f)}if(!t){let u=JSON.stringify(o[0].headers);for(let p=1;p<o.length;p++)if(JSON.stringify(o[p].headers)!==u)return{stdout:"",stderr:`xan cat: headers do not match (use -p to pad)
|
|
59
|
+
`,exitCode:1};i=o[0].headers}let h=[];for(let{headers:u,data:p}of o)for(let l of p){let f=O();for(let c of i)b(f,c,u.includes(c)?l[c]:"");h.push(f)}return{stdout:w(i,h),stderr:"",exitCode:0}}async function je(e,n){let t="",s=[],r=!1,o=!1,i=[];for(let a=0;a<e.length;a++){let d=e[a];(d==="-s"||d==="--select")&&a+1<e.length?s=e[++a].split(","):d==="-v"||d==="--invert"?r=!0:d==="-i"||d==="--ignore-case"?o=!0:d==="-r"||d==="--regex"||d.startsWith("-")||(t?i.push(d):t=d)}if(!t)return{stdout:"",stderr:`xan search: no pattern specified
|
|
60
60
|
`,exitCode:1};let{headers:h,data:u,error:p}=await v(i,n);if(p)return p;let l=s.length>0?s:h,f;try{f=H(t,o?"i":"")}catch{return{stdout:"",stderr:`xan search: invalid regex pattern '${t}'
|
|
61
|
-
`,exitCode:1}}let c=u.filter(a=>{let d=l.some(m=>{let g=a[m];return g!=null&&f.test(String(g))});return r?!d:d});return{stdout:w(h,c),stderr:"",exitCode:0}}async function
|
|
62
|
-
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let u=V(t).map(({expr:c,name:a})=>({alias:typeof a=="string"?a:a[0],ast:
|
|
61
|
+
`,exitCode:1}}let c=u.filter(a=>{let d=l.some(m=>{let g=a[m];return g!=null&&f.test(String(g))});return r?!d:d});return{stdout:w(h,c),stderr:"",exitCode:0}}async function De(e,n){let t="",s=[];for(let c of e)c.startsWith("-")||(t?s.push(c):t=c);if(!t)return{stdout:"",stderr:`xan flatmap: no expression specified
|
|
62
|
+
`,exitCode:1};let{headers:r,data:o,error:i}=await v(s,n);if(i)return i;let u=V(t).map(({expr:c,name:a})=>({alias:typeof a=="string"?a:a[0],ast:F(c)})),p={limits:n.limits?{maxIterations:n.limits.maxJqIterations}:void 0},l=[...r,...u.map(c=>c.alias)],f=[];for(let c of o){let a=[],d=1;for(let m of u){let g=$(c,m.ast,p),y=g.length>0&&Array.isArray(g[0])?g[0]:g;a.push(y),d=Math.max(d,y.length)}for(let m=0;m<d;m++){let g=M(c);for(let y=0;y<u.length;y++){let x=a[y][m]??null;b(g,u[y].alias,x)}f.push(g)}}return{stdout:w(l,f),stderr:"",exitCode:0}}async function Ve(e,n){let{cmdView:t}=await import("./xan-view-5SZBYPLG.js");return t(e,n)}var Ye=new Set(["fuzzy-join","glob","hist","input","parallel","plot","progress","range","scrape","tokenize","union-find"]),at=new Set(["agg","behead","cat","count","dedup","drop","enum","explode","f","filter","fixlengths","flatmap","flatten","fmt","frequency","freq","from","groupby","head","headers","implode","join","map","merge","partition","pivot","rename","reverse","sample","search","select","shuffle","slice","sort","split","stats","tail","to","top","transform","transpose","view",...Ye]),Xe={name:"xan",summary:"CSV toolkit for data manipulation",usage:"xan <COMMAND> [OPTIONS] [FILE]",description:`xan is a collection of commands for working with CSV data.
|
|
63
63
|
It provides a simple, ergonomic interface for common data operations.
|
|
64
64
|
|
|
65
65
|
COMMANDS:
|
|
@@ -133,8 +133,8 @@ EXAMPLES:
|
|
|
133
133
|
xan groupby region 'count() as n' data.csv
|
|
134
134
|
xan explode tags data.csv
|
|
135
135
|
xan join id file1.csv id file2.csv
|
|
136
|
-
xan pivot year 'sum(sales)' data.csv`,options:[" --help display this help and exit"]},
|
|
137
|
-
`,exitCode:1};switch(t){case"headers":return
|
|
136
|
+
xan pivot year 'sum(sales)' data.csv`,options:[" --help display this help and exit"]},lt={headers:{name:"xan headers",summary:"Show column names",usage:"xan headers [OPTIONS] [FILE]",description:"Display column names from a CSV file.",options:["-j, --just-names show names only (no index)"]},count:{name:"xan count",summary:"Count rows",usage:"xan count [FILE]",description:"Count the number of data rows (excluding header).",options:[]},filter:{name:"xan filter",summary:"Filter rows by expression",usage:"xan filter [OPTIONS] EXPR [FILE]",description:"Filter CSV rows using moonblade expressions.",options:["-v, --invert invert match","-l, --limit N limit output rows"]},search:{name:"xan search",summary:"Filter rows by regex",usage:"xan search [OPTIONS] PATTERN [FILE]",description:"Filter CSV rows by regex match on columns.",options:["-s, --select COLS search only these columns","-v, --invert invert match","-i, --ignore-case case insensitive"]},select:{name:"xan select",summary:"Select columns",usage:"xan select COLS [FILE]",description:"Select columns by name, index, glob, or range.",options:["Supports: col names, indices (0,1), ranges (a:c), globs (vec_*), negation (!col)"]},explode:{name:"xan explode",summary:"Split column into rows",usage:"xan explode COLUMN [OPTIONS] [FILE]",description:"Split delimited column values into multiple rows.",options:["-s, --separator SEP separator (default: |)","--drop-empty drop empty values","-r, --rename NAME rename column"]},implode:{name:"xan implode",summary:"Combine rows",usage:"xan implode COLUMN [OPTIONS] [FILE]",description:"Combine consecutive rows, joining column values.",options:["-s, --sep SEP separator (default: |)","-r, --rename NAME rename column"]},join:{name:"xan join",summary:"Join CSV files",usage:"xan join KEY1 FILE1 KEY2 FILE2 [OPTIONS]",description:"Join two CSV files on key columns.",options:["--left left outer join","--right right outer join","--full full outer join","-D, --default VAL default for missing"]},pivot:{name:"xan pivot",summary:"Reshape to columns",usage:"xan pivot COLUMN AGG_EXPR [OPTIONS] [FILE]",description:"Turn row values into columns.",options:["-g, --groupby COLS group by columns"]}},cn={name:"xan",async execute(e,n){if(e.length===0||K(e))return D(Xe);let t=e[0],s=e.slice(1);if(K(s)){let r=lt[t];return r?D(r):D(Xe)}if(Ye.has(t))return{stdout:"",stderr:`xan ${t}: not yet implemented
|
|
137
|
+
`,exitCode:1};switch(t){case"headers":return ue(s,n);case"count":return ce(s,n);case"head":return pe(s,n);case"tail":return fe(s,n);case"slice":return de(s,n);case"reverse":return he(s,n);case"behead":return Me(s,n);case"sample":return $e(s,n);case"select":return oe(s,n);case"drop":return ie(s,n);case"rename":return ae(s,n);case"enum":return le(s,n);case"filter":return Se(s,n);case"search":return je(s,n);case"sort":return Ie(s,n);case"dedup":return ke(s,n);case"top":return Ne(s,n);case"map":return Ee(s,n);case"transform":return Ae(s,n);case"explode":return Oe(s,n);case"implode":return Fe(s,n);case"flatmap":return De(s,n);case"pivot":return Pe(s,n);case"agg":return te(s,n);case"groupby":return ne(s,n);case"frequency":case"freq":return se(s,n);case"stats":return re(s,n);case"cat":return Te(s,n);case"join":return Le(s,n);case"merge":return Re(s,n);case"split":return we(s,n);case"partition":return ve(s,n);case"to":return Ce(s,n);case"from":return be(s,n);case"transpose":return ge(s,n);case"shuffle":return ye(s,n);case"fixlengths":return xe(s,n);case"view":return Y(s,n);case"flatten":case"f":return X(s,n);case"fmt":return Ve(s,n);default:return at.has(t)?{stdout:"",stderr:`xan ${t}: not yet implemented
|
|
138
138
|
`,exitCode:1}:{stdout:"",stderr:`xan: unknown command '${t}'
|
|
139
139
|
Run 'xan --help' for usage.
|
|
140
|
-
`,exitCode:1}}}};export{
|
|
140
|
+
`,exitCode:1}}}};export{cn as xanCommand};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as Ja}from"./chunk-QSDVMMYI.js";import{a as Le,b as Oi}from"./chunk-
|
|
2
|
+
import{a as Ja}from"./chunk-QSDVMMYI.js";import{a as Le,b as Oi}from"./chunk-HSNUCOOQ.js";import"./chunk-UYBH3FNE.js";import"./chunk-4PRVMER6.js";import{k as Ts}from"./chunk-K5IXNHO5.js";import"./chunk-SE4C7FJY.js";import{a as Ai,b as Ti,c as ae}from"./chunk-GTNBSMZR.js";import{a as bt,c as b,e as As}from"./chunk-KGOUQS5A.js";var Yi=b((rp,Ri)=>{var{hasOwnProperty:Ps}=Object.prototype,Ms=(s,e={})=>{typeof e=="string"&&(e={section:e}),e.align=e.align===!0,e.newline=e.newline===!0,e.sort=e.sort===!0,e.whitespace=e.whitespace===!0||e.align===!0,e.platform=e.platform||typeof process<"u"&&process.platform,e.bracketedArray=e.bracketedArray!==!1;let t=e.platform==="win32"?`\r
|
|
3
3
|
`:`
|
|
4
4
|
`,n=e.whitespace?" = ":"=",i=[],r=e.sort?Object.keys(s).sort():Object.keys(s),o=0;e.align&&(o=G(r.filter(c=>s[c]===null||Array.isArray(s[c])||typeof s[c]!="object").map(c=>Array.isArray(s[c])?`${c}[]`:c).concat([""]).reduce((c,u)=>G(c).length>=G(u).length?c:u)).length);let a="",l=e.bracketedArray?"[]":"";for(let c of r){let u=s[c];if(u&&Array.isArray(u))for(let f of u)a+=G(`${c}${l}`).padEnd(o," ")+n+G(f)+t;else u&&typeof u=="object"?i.push(c):a+=G(c).padEnd(o," ")+n+G(u)+t}e.section&&a.length&&(a="["+G(e.section)+"]"+(e.newline?t+t:t)+a);for(let c of i){let u=Vi(c,".").join("\\."),f=(e.section?e.section+".":"")+u,d=Ms(s[c],{...e,section:f});a.length&&d.length&&(a+=t),a+=d}return a};function Vi(s,e){var t=0,n=0,i=0,r=[];do if(i=s.indexOf(e,t),i!==-1){if(t=i+e.length,i>0&&s[i-1]==="\\")continue;r.push(s.slice(n,i)),n=i+e.length}while(i!==-1);return r.push(s.slice(n)),r}var ji=(s,e={})=>{e.bracketedArray=e.bracketedArray!==!1;let t=Object.create(null),n=t,i=null,r=/^\[([^\]]*)\]\s*$|^([^=]+)(=(.*))?$/i,o=s.split(/[\r\n]+/g),a={};for(let c of o){if(!c||c.match(/^\s*[;#]/)||c.match(/^\s*$/))continue;let u=c.match(r);if(!u)continue;if(u[1]!==void 0){if(i=Nt(u[1]),i==="__proto__"){n=Object.create(null);continue}n=t[i]=t[i]||Object.create(null);continue}let f=Nt(u[2]),d;e.bracketedArray?d=f.length>2&&f.slice(-2)==="[]":(a[f]=(a?.[f]||0)+1,d=a[f]>1);let p=d&&f.endsWith("[]")?f.slice(0,-2):f;if(p==="__proto__")continue;let g=u[3]?Nt(u[4]):!0,h=g==="true"||g==="false"||g==="null"?JSON.parse(g):g;d&&(Ps.call(n,p)?Array.isArray(n[p])||(n[p]=[n[p]]):n[p]=[]),Array.isArray(n[p])?n[p].push(h):n[p]=h}let l=[];for(let c of Object.keys(t)){if(!Ps.call(t,c)||typeof t[c]!="object"||Array.isArray(t[c]))continue;let u=Vi(c,".");n=t;let f=u.pop(),d=f.replace(/\\\./g,".");for(let p of u)p!=="__proto__"&&((!Ps.call(n,p)||typeof n[p]!="object")&&(n[p]=Object.create(null)),n=n[p]);n===t&&d===f||(n[d]=t[c],l.push(c))}for(let c of l)delete t[c];return t},Ki=s=>s.startsWith('"')&&s.endsWith('"')||s.startsWith("'")&&s.endsWith("'"),G=s=>typeof s!="string"||s.match(/[=\r\n]/)||s.match(/^\[/)||s.length>1&&Ki(s)||s!==s.trim()?JSON.stringify(s):s.split(";").join("\\;").split("#").join("\\#"),Nt=s=>{if(s=(s||"").trim(),Ki(s)){s.charAt(0)==="'"&&(s=s.slice(1,-1));try{s=JSON.parse(s)}catch{}}else{let e=!1,t="";for(let n=0,i=s.length;n<i;n++){let r=s.charAt(n);if(e)"\\;#".indexOf(r)!==-1?t+=r:t+="\\"+r,e=!1;else{if(";#".indexOf(r)!==-1)break;r==="\\"?e=!0:t+=r}}return e&&(t+="\\"),t.trim()}return s};Ri.exports={parse:ji,decode:ji,stringify:Ms,encode:Ms,safe:G,unsafe:Nt}});var O=b($=>{"use strict";var Fs=Symbol.for("yaml.alias"),Di=Symbol.for("yaml.document"),kt=Symbol.for("yaml.map"),Zi=Symbol.for("yaml.pair"),js=Symbol.for("yaml.scalar"),It=Symbol.for("yaml.seq"),X=Symbol.for("yaml.node.type"),Xl=s=>!!s&&typeof s=="object"&&s[X]===Fs,Ql=s=>!!s&&typeof s=="object"&&s[X]===Di,Hl=s=>!!s&&typeof s=="object"&&s[X]===kt,Dl=s=>!!s&&typeof s=="object"&&s[X]===Zi,zi=s=>!!s&&typeof s=="object"&&s[X]===js,Zl=s=>!!s&&typeof s=="object"&&s[X]===It;function er(s){if(s&&typeof s=="object")switch(s[X]){case kt:case It:return!0}return!1}function zl(s){if(s&&typeof s=="object")switch(s[X]){case Fs:case kt:case js:case It:return!0}return!1}var ec=s=>(zi(s)||er(s))&&!!s.anchor;$.ALIAS=Fs;$.DOC=Di;$.MAP=kt;$.NODE_TYPE=X;$.PAIR=Zi;$.SCALAR=js;$.SEQ=It;$.hasAnchor=ec;$.isAlias=Xl;$.isCollection=er;$.isDocument=Ql;$.isMap=Hl;$.isNode=zl;$.isPair=Dl;$.isScalar=zi;$.isSeq=Zl});var Ve=b(Vs=>{"use strict";var M=O(),F=Symbol("break visit"),tr=Symbol("skip children"),J=Symbol("remove node");function qt(s,e){let t=sr(e);M.isDocument(s)?Se(null,s.contents,t,Object.freeze([s]))===J&&(s.contents=null):Se(null,s,t,Object.freeze([]))}qt.BREAK=F;qt.SKIP=tr;qt.REMOVE=J;function Se(s,e,t,n){let i=nr(s,e,t,n);if(M.isNode(i)||M.isPair(i))return ir(s,n,i),Se(s,i,t,n);if(typeof i!="symbol"){if(M.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r<e.items.length;++r){let o=Se(r,e.items[r],t,n);if(typeof o=="number")r=o-1;else{if(o===F)return F;o===J&&(e.items.splice(r,1),r-=1)}}}else if(M.isPair(e)){n=Object.freeze(n.concat(e));let r=Se("key",e.key,t,n);if(r===F)return F;r===J&&(e.key=null);let o=Se("value",e.value,t,n);if(o===F)return F;o===J&&(e.value=null)}}return i}async function Ct(s,e){let t=sr(e);M.isDocument(s)?await Ne(null,s.contents,t,Object.freeze([s]))===J&&(s.contents=null):await Ne(null,s,t,Object.freeze([]))}Ct.BREAK=F;Ct.SKIP=tr;Ct.REMOVE=J;async function Ne(s,e,t,n){let i=await nr(s,e,t,n);if(M.isNode(i)||M.isPair(i))return ir(s,n,i),Ne(s,i,t,n);if(typeof i!="symbol"){if(M.isCollection(e)){n=Object.freeze(n.concat(e));for(let r=0;r<e.items.length;++r){let o=await Ne(r,e.items[r],t,n);if(typeof o=="number")r=o-1;else{if(o===F)return F;o===J&&(e.items.splice(r,1),r-=1)}}}else if(M.isPair(e)){n=Object.freeze(n.concat(e));let r=await Ne("key",e.key,t,n);if(r===F)return F;r===J&&(e.key=null);let o=await Ne("value",e.value,t,n);if(o===F)return F;o===J&&(e.value=null)}}return i}function sr(s){return typeof s=="object"&&(s.Collection||s.Node||s.Value)?Object.assign({Alias:s.Node,Map:s.Node,Scalar:s.Node,Seq:s.Node},s.Value&&{Map:s.Value,Scalar:s.Value,Seq:s.Value},s.Collection&&{Map:s.Collection,Seq:s.Collection},s):s}function nr(s,e,t,n){if(typeof t=="function")return t(s,e,n);if(M.isMap(e))return t.Map?.(s,e,n);if(M.isSeq(e))return t.Seq?.(s,e,n);if(M.isPair(e))return t.Pair?.(s,e,n);if(M.isScalar(e))return t.Scalar?.(s,e,n);if(M.isAlias(e))return t.Alias?.(s,e,n)}function ir(s,e,t){let n=e[e.length-1];if(M.isCollection(n))n.items[s]=t;else if(M.isPair(n))s==="key"?n.key=t:n.value=t;else if(M.isDocument(n))n.contents=t;else{let i=M.isAlias(n)?"alias":"scalar";throw new Error(`Cannot replace node with ${i} parent`)}}Vs.visit=qt;Vs.visitAsync=Ct});var Ks=b(or=>{"use strict";var rr=O(),tc=Ve(),sc={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},nc=s=>s.replace(/[!,[\]{}]/g,e=>sc[e]),Ke=class s{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},s.defaultYaml,e),this.tags=Object.assign({},s.defaultTags,t)}clone(){let e=new s(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new s(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:s.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},s.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:s.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},s.defaultTags),this.atNextDocument=!1);let n=e.trim().split(/[ \t]+/),i=n.shift();switch(i){case"%TAG":{if(n.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),n.length<2))return!1;let[r,o]=n;return this.tags[r]=o,!0}case"%YAML":{if(this.yaml.explicit=!0,n.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[r]=n;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{let o=/^\d+\.\d+$/.test(r);return t(6,`Unsupported YAML version ${r}`,o),!1}}default:return t(0,`Unknown directive ${i}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let o=e.slice(2,-1);return o==="!"||o==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),o)}let[,n,i]=e.match(/^(.*!)([^!]*)$/s);i||t(`The ${e} tag has no suffix`);let r=this.tags[n];if(r)try{return r+decodeURIComponent(i)}catch(o){return t(String(o)),null}return n==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,n]of Object.entries(this.tags))if(e.startsWith(n))return t+nc(e.substring(n.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],n=Object.entries(this.tags),i;if(e&&n.length>0&&rr.isNode(e.contents)){let r={};tc.visit(e.contents,(o,a)=>{rr.isNode(a)&&a.tag&&(r[a.tag]=!0)}),i=Object.keys(r)}else i=[];for(let[r,o]of n)r==="!!"&&o==="tag:yaml.org,2002:"||(!e||i.some(a=>a.startsWith(o)))&&t.push(`%TAG ${r} ${o}`);return t.join(`
|
|
5
5
|
`)}};Ke.defaultYaml={explicit:!1,version:"1.2"};Ke.defaultTags={"!!":"tag:yaml.org,2002:"};or.Directives=Ke});var Lt=b(Re=>{"use strict";var ar=O(),ic=Ve();function rc(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function lr(s){let e=new Set;return ic.visit(s,{Value(t,n){n.anchor&&e.add(n.anchor)}}),e}function cr(s,e){for(let t=1;;++t){let n=`${s}${t}`;if(!e.has(n))return n}}function oc(s,e){let t=[],n=new Map,i=null;return{onAnchor:r=>{t.push(r),i??(i=lr(s));let o=cr(e,i);return i.add(o),o},setAnchors:()=>{for(let r of t){let o=n.get(r);if(typeof o=="object"&&o.anchor&&(ar.isScalar(o.node)||ar.isCollection(o.node)))o.node.anchor=o.anchor;else{let a=new Error("Failed to resolve repeated object (this should not happen)");throw a.source=r,a}}},sourceObjects:n}}Re.anchorIsValid=rc;Re.anchorNames=lr;Re.createNodeAnchors=oc;Re.findNewAnchor=cr});var Rs=b(fr=>{"use strict";function Ye(s,e,t,n){if(n&&typeof n=="object")if(Array.isArray(n))for(let i=0,r=n.length;i<r;++i){let o=n[i],a=Ye(s,n,String(i),o);a===void 0?delete n[i]:a!==o&&(n[i]=a)}else if(n instanceof Map)for(let i of Array.from(n.keys())){let r=n.get(i),o=Ye(s,n,i,r);o===void 0?n.delete(i):o!==r&&n.set(i,o)}else if(n instanceof Set)for(let i of Array.from(n)){let r=Ye(s,n,i,i);r===void 0?n.delete(i):r!==i&&(n.delete(i),n.add(r))}else for(let[i,r]of Object.entries(n)){let o=Ye(s,n,i,r);o===void 0?delete n[i]:o!==r&&(n[i]=o)}return s.call(e,t,n)}fr.applyReviver=Ye});var D=b(dr=>{"use strict";var ac=O();function ur(s,e,t){if(Array.isArray(s))return s.map((n,i)=>ur(n,String(i),t));if(s&&typeof s.toJSON=="function"){if(!t||!ac.hasAnchor(s))return s.toJSON(e,t);let n={aliasCount:0,count:1,res:void 0};t.anchors.set(s,n),t.onCreate=r=>{n.res=r,delete t.onCreate};let i=s.toJSON(e,t);return t.onCreate&&t.onCreate(i),i}return typeof s=="bigint"&&!t?.keep?Number(s):s}dr.toJS=ur});var Pt=b(pr=>{"use strict";var lc=Rs(),hr=O(),cc=D(),Ys=class{constructor(e){Object.defineProperty(this,hr.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:n,onAnchor:i,reviver:r}={}){if(!hr.isDocument(e))throw new TypeError("A document argument is required");let o={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof n=="number"?n:100},a=cc.toJS(this,"",o);if(typeof i=="function")for(let{count:l,res:c}of o.anchors.values())i(c,l);return typeof r=="function"?lc.applyReviver(r,{"":a},"",a):a}};pr.NodeBase=Ys});var Ue=b(mr=>{"use strict";var fc=Lt(),uc=Ve(),Ee=O(),dc=Pt(),hc=D(),Us=class extends dc.NodeBase{constructor(e){super(Ee.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){let n;t?.aliasResolveCache?n=t.aliasResolveCache:(n=[],uc.visit(e,{Node:(r,o)=>{(Ee.isAlias(o)||Ee.hasAnchor(o))&&n.push(o)}}),t&&(t.aliasResolveCache=n));let i;for(let r of n){if(r===this)break;r.anchor===this.source&&(i=r)}return i}toJSON(e,t){if(!t)return{source:this.source};let{anchors:n,doc:i,maxAliasCount:r}=t,o=this.resolve(i,t);if(!o){let l=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(l)}let a=n.get(o);if(a||(hc.toJS(o,null,t),a=n.get(o)),a?.res===void 0){let l="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(l)}if(r>=0&&(a.count+=1,a.aliasCount===0&&(a.aliasCount=Mt(i,o,n)),a.count*a.aliasCount>r)){let l="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(l)}return a.res}toString(e,t,n){let i=`*${this.source}`;if(e){if(fc.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${i} `}return i}};function Mt(s,e,t){if(Ee.isAlias(e)){let n=e.resolve(s),i=t&&n&&t.get(n);return i?i.count*i.aliasCount:0}else if(Ee.isCollection(e)){let n=0;for(let i of e.items){let r=Mt(s,i,t);r>n&&(n=r)}return n}else if(Ee.isPair(e)){let n=Mt(s,e.key,t),i=Mt(s,e.value,t);return Math.max(n,i)}return 1}mr.Alias=Us});var C=b(Js=>{"use strict";var pc=O(),mc=Pt(),gc=D(),yc=s=>!s||typeof s!="function"&&typeof s!="object",Z=class extends mc.NodeBase{constructor(e){super(pc.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:gc.toJS(this.value,e,t)}toString(){return String(this.value)}};Z.BLOCK_FOLDED="BLOCK_FOLDED";Z.BLOCK_LITERAL="BLOCK_LITERAL";Z.PLAIN="PLAIN";Z.QUOTE_DOUBLE="QUOTE_DOUBLE";Z.QUOTE_SINGLE="QUOTE_SINGLE";Js.Scalar=Z;Js.isScalarValue=yc});var Je=b(yr=>{"use strict";var bc=Ue(),fe=O(),gr=C(),wc="tag:yaml.org,2002:";function Sc(s,e,t){if(e){let n=t.filter(r=>r.tag===e),i=n.find(r=>!r.format)??n[0];if(!i)throw new Error(`Tag ${e} not found`);return i}return t.find(n=>n.identify?.(s)&&!n.format)}function Nc(s,e,t){if(fe.isDocument(s)&&(s=s.contents),fe.isNode(s))return s;if(fe.isPair(s)){let f=t.schema[fe.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:n,onAnchor:i,onTagObj:r,schema:o,sourceObjects:a}=t,l;if(n&&s&&typeof s=="object"){if(l=a.get(s),l)return l.anchor??(l.anchor=i(s)),new bc.Alias(l.anchor);l={anchor:null,node:null},a.set(s,l)}e?.startsWith("!!")&&(e=wc+e.slice(2));let c=Sc(s,e,o.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new gr.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?o[fe.MAP]:Symbol.iterator in Object(s)?o[fe.SEQ]:o[fe.MAP]}r&&(r(c),delete t.onTagObj);let u=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new gr.Scalar(s);return e?u.tag=e:c.default||(u.tag=c.tag),l&&(l.node=u),u}yr.createNode=Nc});var _t=b($t=>{"use strict";var Ec=Je(),W=O(),vc=Pt();function Ws(s,e,t){let n=t;for(let i=e.length-1;i>=0;--i){let r=e[i];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let o=[];o[r]=n,n=o}else n=new Map([[r,n]])}return Ec.createNode(n,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var br=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,Gs=class extends vc.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(n=>W.isNode(n)||W.isPair(n)?n.clone(e):n),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(br(e))this.add(t);else{let[n,...i]=e,r=this.get(n,!0);if(W.isCollection(r))r.addIn(i,t);else if(r===void 0&&this.schema)this.set(n,Ws(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}deleteIn(e){let[t,...n]=e;if(n.length===0)return this.delete(t);let i=this.get(t,!0);if(W.isCollection(i))return i.deleteIn(n);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`)}getIn(e,t){let[n,...i]=e,r=this.get(n,!0);return i.length===0?!t&&W.isScalar(r)?r.value:r:W.isCollection(r)?r.getIn(i,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!W.isPair(t))return!1;let n=t.value;return n==null||e&&W.isScalar(n)&&n.value==null&&!n.commentBefore&&!n.comment&&!n.tag})}hasIn(e){let[t,...n]=e;if(n.length===0)return this.has(t);let i=this.get(t,!0);return W.isCollection(i)?i.hasIn(n):!1}setIn(e,t){let[n,...i]=e;if(i.length===0)this.set(n,t);else{let r=this.get(n,!0);if(W.isCollection(r))r.setIn(i,t);else if(r===void 0&&this.schema)this.set(n,Ws(this.schema,i,t));else throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`)}}};$t.Collection=Gs;$t.collectionFromPath=Ws;$t.isEmptyPath=br});var We=b(xt=>{"use strict";var Ac=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function Xs(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var Tc=(s,e,t)=>s.endsWith(`
|
package/dist/bin/just-bash.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{B as on,C as an,D as ne,E as De,F as K,G as me,H as ut,I as ln,J as T,K as cn,L as un,M as we,N as qt,O as ft,P as z,a as Xs,b as Ys,c as Qs,d as lt,e as q,f as M,g as ye,h as Y,i as ge,j as Ce,k as zt,l as ct,m as Js,n as Bt,o as en,p as fe,q as $e,r as tn,s as sn,t as jt,u as Ht,v as Pe,w as nn,x as rn,y as pe,z as Ut}from"./chunks/chunk-2ODUA7YH.js";import{a as _e,b as he}from"./chunks/chunk-4PRVMER6.js";import{a as ae,b as le,c as se,d as ue,e as Gs,f as V,g as xe,h as it,i as ot,j as Ks,k as te,l as Ae,m as at,n as de}from"./chunks/chunk-K5IXNHO5.js";import{a as qe}from"./chunks/chunk-SE4C7FJY.js";import"./chunks/chunk-OBH7XN5N.js";import{a as Ee}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import{resolve as Vr}from"node:path";var Le=[{name:"echo",load:async()=>(await import("./chunks/echo-7I42V66Q.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-HNXE2ES2.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-4W7NDLLV.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5LN47VHU.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XMSNS6S5.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-OEMA5ZTD.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-IBPHJBM3.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-S7ASVG34.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-VFXCUKXO.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-P4KHB27X.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TYLTHXFR.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-L26WH2K4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TJHLLIMR.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YAUIERGN.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-CZ2TD6T6.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-ZZVPXHLF.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-IZR5557M.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-E4QAUCYQ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-OKD2P6CM.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-QF3YLXRW.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-NNXAFO6D.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-UCH462KK.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-IAUNBQKH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-7UP7EATZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-HQ4AK5DM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-XSKPK43X.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-KHOYETRP.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-WC3AXFHC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-PECPOFQT.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-56DL6SXU.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-BMOLDA72.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-43KPK6TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZGXLP3DN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-F4NVQOJH.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-433HIVAI.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-VHPDBIVV.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-4SVNPPXZ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-BM3AFTIE.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-MWSA2WYI.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-L43ENI4H.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-5QEJAXNR.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-JVLUNKSG.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-KRKGC2U3.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Le.push({name:"tar",load:async()=>(await import("./chunks/tar-CLEBMI4R.js")).tarCommand}),Le.push({name:"yq",load:async()=>(await import("./chunks/yq-WYJ3A4JF.js")).yqCommand}),Le.push({name:"xan",load:async()=>(await import("./chunks/xan-EAK3S7KJ.js")).xanCommand}),Le.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-CUDCXXK3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).pythonCommand}));var Ur=[{name:"curl",load:async()=>(await import("./chunks/curl-7IUASLUJ.js")).curlCommand}],fn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let n=fn.get(e.name);return n||(n=await e.load(),fn.set(e.name,n)),n.execute(t,s)}}}function dn(e){return(e?Le.filter(s=>e.includes(s.name)):Le).map(Gt)}function hn(){return Ur.map(Gt)}function pn(){return Zt.map(Gt)}function mn(e){return"load"in e&&typeof e.load=="function"}function yn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var qr=new TextEncoder,Zr=new TextDecoder;function Fe(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):qr.encode(e)}function dt(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Zr.decode(e)}function ke(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ht=new TextEncoder;function Gr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function ee(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Ze=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))Gr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){ee(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=ke(n),a=Fe(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=ke(s);return dt(n,r)}async readFileBuffer(t){ee(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:ht.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){ee(t,"append");let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ke(n),a=Fe(s,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:ht.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(r,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){ee(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ht.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){ee(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ht.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let l=this.data.get(r),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){ee(t,"mkdir");let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){ee(t,"scandir");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){ee(t,"rm");let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){ee(t,"cp"),ee(s,"cp");let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let l of a){let c=r==="/"?`/${l}`:`${r}/${l}`,u=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,u,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){ee(t,"chmod");let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){ee(s,"symlink");let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){ee(t,"link"),ee(s,"link");let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){ee(t,"readlink");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){ee(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){ee(t,"utimes");let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Kr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Xr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Yr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Qr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Xs}
|
|
2
|
+
import{B as on,C as an,D as ne,E as De,F as K,G as me,H as ut,I as ln,J as T,K as cn,L as un,M as we,N as qt,O as ft,P as z,a as Xs,b as Ys,c as Qs,d as lt,e as q,f as M,g as ye,h as Y,i as ge,j as Ce,k as zt,l as ct,m as Js,n as Bt,o as en,p as fe,q as $e,r as tn,s as sn,t as jt,u as Ht,v as Pe,w as nn,x as rn,y as pe,z as Ut}from"./chunks/chunk-2ODUA7YH.js";import{a as _e,b as he}from"./chunks/chunk-4PRVMER6.js";import{a as ae,b as le,c as se,d as ue,e as Gs,f as V,g as xe,h as it,i as ot,j as Ks,k as te,l as Ae,m as at,n as de}from"./chunks/chunk-K5IXNHO5.js";import{a as qe}from"./chunks/chunk-SE4C7FJY.js";import"./chunks/chunk-OBH7XN5N.js";import{a as Ee}from"./chunks/chunk-4VDEBYW7.js";import"./chunks/chunk-KGOUQS5A.js";import{resolve as Vr}from"node:path";var Le=[{name:"echo",load:async()=>(await import("./chunks/echo-7I42V66Q.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-HNXE2ES2.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-4W7NDLLV.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-5LN47VHU.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-XMSNS6S5.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-OEMA5ZTD.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-IBPHJBM3.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-S7ASVG34.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-VFXCUKXO.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-P4KHB27X.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-EFFNQ3RY.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-TYLTHXFR.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-L26WH2K4.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-VL3R4LAM.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TJHLLIMR.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-YAUIERGN.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-CZ2TD6T6.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-ZZVPXHLF.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-BD56656Z.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-IZR5557M.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-E4QAUCYQ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-OKD2P6CM.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-QF3YLXRW.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-NNXAFO6D.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-CPIFQTKY.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-IHF6BEOO.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-UCH462KK.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-IAUNBQKH.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-VP42N2JN.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-DSM3NUGM.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-452R4I2C.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-77K5HH2M.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-BFVYAPOU.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-ZEKN6D4Q.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-7UP7EATZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-HQ4AK5DM.js")).column},{name:"join",load:async()=>(await import("./chunks/join-3IXMEGNA.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-XSKPK43X.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-KHOYETRP.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-SO5MVUEX.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-EES7TR26.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-WC3AXFHC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-PECPOFQT.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-W6IMQ43Y.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-MGDOL4KG.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-56DL6SXU.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-IWT2HHEA.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-OVATH2SQ.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-CI7A5IXQ.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-OAUBNRSG.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-EIPK4SZA.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-43KPK6TL.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-ZGXLP3DN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-IQLPMFYI.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-O5BOTJGJ.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-JED4EKFH.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-F4NVQOJH.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-AVK43XM2.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-433HIVAI.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-VHPDBIVV.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-4SVNPPXZ.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-BM3AFTIE.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-MWSA2WYI.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-EPEXKI4B.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-L43ENI4H.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-5QEJAXNR.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-KNRFDAY7.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-WXDKRL2Z.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-JVLUNKSG.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-KRKGC2U3.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-5ILPB46W.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Le.push({name:"tar",load:async()=>(await import("./chunks/tar-CLEBMI4R.js")).tarCommand}),Le.push({name:"yq",load:async()=>(await import("./chunks/yq-XD7UYY5C.js")).yqCommand}),Le.push({name:"xan",load:async()=>(await import("./chunks/xan-QLNZCWIG.js")).xanCommand}),Le.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-CUDCXXK3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-ZWX5SFJ3.js")).pythonCommand}));var Ur=[{name:"curl",load:async()=>(await import("./chunks/curl-RWQO3SBN.js")).curlCommand}],fn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let n=fn.get(e.name);return n||(n=await e.load(),fn.set(e.name,n)),n.execute(t,s)}}}function dn(e){return(e?Le.filter(s=>e.includes(s.name)):Le).map(Gt)}function hn(){return Ur.map(Gt)}function pn(){return Zt.map(Gt)}function mn(e){return"load"in e&&typeof e.load=="function"}function yn(e){let t=null;return{name:e.name,async execute(s,n){return t||(t=await e.load()),t.execute(s,n)}}}var qr=new TextEncoder,Zr=new TextDecoder;function Fe(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)s[n/2]=parseInt(e.slice(n,n+2),16);return s}return t==="binary"||t==="latin1"?Uint8Array.from(e,s=>s.charCodeAt(0)):qr.encode(e)}function dt(e,t){return t==="base64"?btoa(String.fromCharCode(...e)):t==="hex"?Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join(""):t==="binary"||t==="latin1"?String.fromCharCode(...e):Zr.decode(e)}function ke(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ht=new TextEncoder;function Gr(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}function ee(e,t){if(e.includes("\0"))throw new Error(`ENOENT: path contains null byte, ${t} '${e}'`)}var Ze=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,n]of Object.entries(t))Gr(n)?this.writeFileSync(s,n.content,void 0,{mode:n.mode,mtime:n.mtime}):this.writeFileSync(s,n)}normalizePath(t){if(!t||t==="/")return"/";let s=t.endsWith("/")&&t!=="/"?t.slice(0,-1):t;s.startsWith("/")||(s=`/${s}`);let n=s.split("/").filter(i=>i&&i!=="."),r=[];for(let i of n)i===".."?r.pop():r.push(i);return`/${r.join("/")}`||"/"}dirname(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.lastIndexOf("/");return n===0?"/":s.slice(0,n)}ensureParentDirs(t){let s=this.dirname(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,n,r){ee(t,"write");let i=this.normalizePath(t);this.ensureParentDirs(i);let o=ke(n),a=Fe(s,o);this.data.set(i,{type:"file",content:a,mode:r?.mode??420,mtime:r?.mtime??new Date})}async readFile(t,s){let n=await this.readFileBuffer(t),r=ke(s);return dt(n,r)}async readFileBuffer(t){ee(t,"open");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(n.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);return n.content instanceof Uint8Array?n.content:ht.encode(n.content)}async writeFile(t,s,n){this.writeFileSync(t,s,n)}async appendFile(t,s,n){ee(t,"append");let r=this.normalizePath(t),i=this.data.get(r);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=ke(n),a=Fe(s,o);if(i?.type==="file"){let l=i.content instanceof Uint8Array?i.content:ht.encode(i.content),c=new Uint8Array(l.length+a.length);c.set(l),c.set(a,l.length),this.data.set(r,{type:"file",content:c,mode:i.mode,mtime:new Date})}else this.writeFileSync(t,s,n)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){ee(t,"stat");let s=this.resolvePathWithSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ht.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}async lstat(t){ee(t,"lstat");let s=this.resolveIntermediateSymlinks(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(n.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:n.mode,size:n.target.length,mtime:n.mtime||new Date};let r=0;return n.type==="file"&&n.content&&(n.content instanceof Uint8Array?r=n.content.length:r=ht.encode(n.content).length),{isFile:n.type==="file",isDirectory:n.type==="directory",isSymbolicLink:!1,mode:n.mode,size:r,mtime:n.mtime||new Date}}resolveSymlink(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=this.dirname(t);return this.normalizePath(n==="/"?`/${s}`:`${n}/${s}`)}resolveIntermediateSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/");if(n.length<=1)return s;let r="",i=new Set;for(let o=0;o<n.length-1;o++){let a=n[o];r=`${r}/${a}`;let l=this.data.get(r),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(r),r=this.resolveSymlink(r,l.target),l=this.data.get(r),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${r}/${n[n.length-1]}`}resolvePathWithSymlinks(t){let s=this.normalizePath(t);if(s==="/")return"/";let n=s.slice(1).split("/"),r="",i=new Set;for(let o of n){r=`${r}/${o}`;let a=this.data.get(r),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(r),r=this.resolveSymlink(r,a.target),a=this.data.get(r),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return r}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){ee(t,"mkdir");let n=this.normalizePath(t);if(this.data.has(n)){if(this.data.get(n)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let r=this.dirname(n);if(r!=="/"&&!this.data.has(r))if(s?.recursive)this.mkdirSync(r,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(n,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(n=>n.name)}async readdirWithFileTypes(t){ee(t,"scandir");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Set;for(;n&&n.type==="symlink";){if(r.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);r.add(s),s=this.resolveSymlink(s,n.target),n=this.data.get(s)}if(!n)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(n.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){ee(t,"rm");let n=this.normalizePath(t),r=this.data.get(n);if(!r){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(r.type==="directory"){let i=await this.readdir(n);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=n==="/"?`/${o}`:`${n}/${o}`;await this.rm(a,s)}}}this.data.delete(n)}async cp(t,s,n){ee(t,"cp"),ee(s,"cp");let r=this.normalizePath(t),i=this.normalizePath(s),o=this.data.get(r);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!n?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(r);for(let l of a){let c=r==="/"?`/${l}`:`${r}/${l}`,u=i==="/"?`/${l}`:`${i}/${l}`;await this.cp(c,u,n)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){if(s.startsWith("/"))return this.normalizePath(s);let n=t==="/"?`/${s}`:`${t}/${s}`;return this.normalizePath(n)}async chmod(t,s){ee(t,"chmod");let n=this.normalizePath(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);r.mode=s}async symlink(t,s){ee(s,"symlink");let n=this.normalizePath(s);if(this.data.has(n))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(n),this.data.set(n,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){ee(t,"link"),ee(s,"link");let n=this.normalizePath(t),r=this.normalizePath(s),i=this.data.get(n);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(r))throw new Error(`EEXIST: file already exists, link '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"file",content:i.content,mode:i.mode,mtime:i.mtime})}async readlink(t){ee(t,"readlink");let s=this.normalizePath(t),n=this.data.get(s);if(!n)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(n.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return n.target}async realpath(t){ee(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,n){ee(t,"utimes");let r=this.normalizePath(t),i=this.resolvePathWithSymlinks(r),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=n}};function Kr(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Xr(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Yr(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Qr(e){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Xs}
|
|
3
3
|
`),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
|
|
4
4
|
`),e.writeFileSync("/proc/self/status",Ys()),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function gn(e,t){Kr(e)&&(Xr(e,t),Yr(e),Qr(e))}var Jr=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],ei=["braceexpand","hashall","interactive-comments"];function Kt(e){let t=[],s=[...ei.map(n=>({name:n,enabled:!0})),...Jr.map(n=>({name:n,enabled:e[n]}))].sort((n,r)=>n.name.localeCompare(r.name));for(let n of s)n.enabled&&t.push(n.name);return t.join(":")}function We(e){e.state.env.set("SHELLOPTS",Kt(e.state.options))}var ti=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Xt(e){let t=[];for(let s of ti)e[s]&&t.push(s);return t.join(":")}function Yt(e){e.state.env.set("BASHOPTS",Xt(e.state.shoptOptions))}var si="BASH_ALIAS_";function wn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function vn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function bn(e,t){return e.env.get(`${si}${t}`)}function Qt(e,t,s){if(!t.name||!wn(t.name))return t;let n=vn(t.name);if(!n)return t;let r=bn(e,n);if(!r||s.has(n))return t;try{s.add(n);let i=new M,o=r,a=r.endsWith(" ");if(!a)for(let f of t.args){let d=$n(f);o+=` ${d}`}let l;try{l=i.parse(o)}catch(f){if(f instanceof lt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return En(t,r);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return En(t,r);let u={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(wn(f)){let d=vn(f);if(d&&bn(e,d)){let h={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},m=Qt(e,h,s);m!==h&&(u={...u,name:m.name,args:[...m.args]})}}}return u}catch(i){throw s.delete(n),i}}function En(e,t){let s=t;for(let o of e.args){let a=$n(o);s+=` ${a}`}let n=new M,r=n.parseWordFromString("eval",!1,!1),i=n.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:r,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function $n(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(n=>n.type==="Literal"?n.value:`$${n.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function Sn(e,t){let s=t.parts.map(u=>u.type==="Literal"?u.value:"\0").join(""),n=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!n||!s.endsWith(")"))return null;let r=n[1],i=[],o=!1,a="",l=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let h of d)/^\s+$/.test(h)?(a||l)&&(i.push(a),a="",l=!1):h&&(a+=h)}}else if(o)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=ct({type:"Word",parts:[u]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await we(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(l=!0);let f=await T(e,{type:"Word",parts:[u]});a+=f}(a||l)&&i.push(a);let c=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${r}=(${c.join(" ")})`}async function An(e,t){let s=-1,n=-1,r=!1;for(let p=0;p<t.parts.length;p++){let g=t.parts[p];if(g.type==="Literal"){let S=g.value.indexOf("+=");if(S!==-1){let P=g.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)){s=p,n=S,r=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=S,r=!0;break}}let v=g.value.indexOf("=");if(v!==-1&&(v===0||g.value[v-1]!=="+")){let P=g.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(P)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(P)){s=p,n=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=r?2:1,l=o.value.slice(0,n),c=o.value.slice(n+a),u=t.parts.slice(s+1),f="";for(let p of i)f+=await T(e,{type:"Word",parts:[p]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},h=d.parts.length>0?await T(e,d):"";return`${f}${r?"+=":"="}${h}`}var ni=["tar","yq","xan","sqlite3","python3","python"];function _n(e){return ni.includes(e)}var L=Object.freeze({stdout:"",stderr:"",exitCode:0});function F(e=""){return{stdout:e,stderr:"",exitCode:0}}function A(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function C(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function U(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Se(e,t,s="",n=""){throw new te(e,t,s,n)}function Jt(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Ae;return L}if(t.length>1)throw new V(1,"",`bash: break: too many arguments
|
|
5
5
|
`);let s=1;if(t.length>0){let n=Number.parseInt(t[0],10);if(Number.isNaN(n)||n<1)throw new V(128,"",`bash: break: ${t[0]}: numeric argument required
|
|
@@ -61,7 +61,7 @@ import{B as on,C as an,D as ne,E as De,F as K,G as me,H as ut,I as ln,J as T,K a
|
|
|
61
61
|
`,2)}else if(d==="-S"){if(f++,f>=t.length)return A(`complete: -S: option requires an argument
|
|
62
62
|
`,2)}else if(d==="-X"){if(f++,f>=t.length)return A(`complete: -X: option requires an argument
|
|
63
63
|
`,2)}else if(d==="--"){u.push(...t.slice(f+1));break}else d.startsWith("-")||u.push(d)}if(n){if(u.length===0)return e.state.completionSpecs.clear(),F("");for(let f of u)e.state.completionSpecs.delete(f);return F("")}if(s)return u.length===0?cs(e):cs(e,u);if(t.length===0||u.length===0&&!i&&!o&&!a&&l.length===0&&c.length===0&&!r)return cs(e);if(o&&u.length===0&&!r)return A(`complete: -F: option requires a command name
|
|
64
|
-
`,2);if(r){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.completionSpecs.set("__default__",f),F("")}for(let f of u){let d=
|
|
64
|
+
`,2);if(r){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),c.length>0&&(f.actions=c),e.state.completionSpecs.set("__default__",f),F("")}for(let f of u){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),c.length>0&&(d.actions=c),e.state.completionSpecs.set(f,d)}return F("")}function cs(e,t){let s=e.state.completionSpecs;if(!s||s.size===0){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
|
|
65
65
|
`;return C("",i,1)}return F("")}let n=[],r=t||Array.from(s.keys());for(let i of r){if(i==="__default__")continue;let o=s.get(i);if(!o){if(t)return C(n.join(`
|
|
66
66
|
`)+(n.length>0?`
|
|
67
67
|
`:""),`complete: ${i}: no completion specification
|