bun-query-builder 0.2.57 → 0.2.59
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/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{Aa as l6,D as V6,E as W6,F as D6,G as L6,H as M6,I as w6,J as P6,K as N6,L as O6,M as T6,N as x6,O as B6,P as E6,Q as b6,R as I6,S as A6,T as R6,X as C6,Y as k6,ea as l,fa as r,ga as a,ka as h6,la as v6,ma as y6,n as K6,na as S6,oa as g6,pa as _6,qa as f6,ra as m6,sa as s,ta as t,ua as d6,va as u6,wa as i6,xa as c6,ya as n6,za as p6}from"../chunk-
|
|
3
|
+
import{Aa as l6,D as V6,E as W6,F as D6,G as L6,H as M6,I as w6,J as P6,K as N6,L as O6,M as T6,N as x6,O as B6,P as E6,Q as b6,R as I6,S as A6,T as R6,X as C6,Y as k6,ea as l,fa as r,ga as a,ka as h6,la as v6,ma as y6,n as K6,na as S6,oa as g6,pa as _6,qa as f6,ra as m6,sa as s,ta as t,ua as d6,va as u6,wa as i6,xa as c6,ya as n6,za as p6}from"../chunk-4q37wh0k.js";import"../chunk-asdkg5va.js";import"../chunk-j9778t8e.js";import{sc as K}from"../chunk-739qq8wk.js";import{existsSync as r6}from"fs";import S from"fs/promises";import e from"os";import g from"path";import T from"process";import{EventEmitter as a6}from"events";import N from"process";import z6 from"process";import d from"process";import k from"process";import E from"process";import Z6 from"tty";import S4,{stdin as Dz,stdout as Lz}from"process";import Q6,{stdin as f4,stdout as m4}from"process";import d4 from"readline";class j6{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let z=e.homedir(),q=g.join(z,".config","clapp");this.configPath=g.join(q,"telemetry.json")}async isEnabled(){if(T.env.DO_NOT_TRACK==="1"||T.env.DO_NOT_TRACK==="true")return!1;if(T.env.NO_TELEMETRY==="1"||T.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let z=await this.loadConfig();if(z.enabled=!0,!z.userId)z.userId=this.generateUserId();await this.saveConfig(z)}async disable(){let z=await this.loadConfig();z.enabled=!1,await this.saveConfig(z)}async track(z,q){if(!await this.isEnabled())return;let Z={event:z,...q,timestamp:Date.now(),platform:e.platform(),nodeVersion:T.version};if(this.events.push(Z),this.events.length>=10)await this.send()}async trackCommand(z,q){await this.track("command",{command:z,duration:q})}async trackError(z,q){await this.track("error",{error:z,command:q})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let q=await this.loadConfig();return q.lastSent=Date.now(),await this.saveConfig(q),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let q=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(q),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(z){return new Promise((q)=>setTimeout(q,z))}async status(){let z=await this.loadConfig();return{enabled:z.enabled,doNotTrack:T.env.DO_NOT_TRACK==="1"||T.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:z.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(r6(this.configPath)){let z=await S.readFile(this.configPath,"utf-8");return this.config=JSON.parse(z),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(z){this.config=z;try{let q=g.dirname(this.configPath);await S.mkdir(q,{recursive:!0}),await S.writeFile(this.configPath,JSON.stringify(z,null,2),"utf-8")}catch{}}generateUserId(){let z=Math.random().toString(36).substring(2,15),q=Date.now().toString(36);return`${z}-${q}`}}var $z=new j6;function m(z){return z.replace(/[<[].+/,"").trim()}function s6(z){let q=/<([^>]+)>/g,J=/\[([^\]]+)\]/g,Z=[],$=(X)=>{let Q=!1,j=X[1];if(j.startsWith("..."))j=j.slice(3),Q=!0;return{required:X[0].startsWith("<"),value:j,variadic:Q}},Y;while(Y=q.exec(z))Z.push($(Y));let F;while(F=J.exec(z))Z.push($(F));return Z}function t6(z){let q={alias:{},boolean:[]};for(let[J,Z]of z.entries()){if(Z.names.length>1)q.alias[Z.names[0]]=Z.names.slice(1);if(Z.isBoolean)if(Z.negated){if(!z.some((Y,F)=>{return F!==J&&Y.names.some((X)=>Z.names.includes(X))&&typeof Y.required==="boolean"}))q.boolean.push(Z.names[0])}else q.boolean.push(Z.names[0])}return q}function q6(z){return z.reduce((q,J)=>q.length>=J.length?q:J,"")}function _(z,q){return z.length>=q?z:`${z}${" ".repeat(q-z.length)}`}function C(z){return z.replace(/([a-z])-([a-z])/g,(q,J,Z)=>{return J+Z.toUpperCase()})}function o6(z,q,J){let Z=0,$=q.length,Y=z,F;for(;Z<$;++Z)F=Y[q[Z]],Y=Y[q[Z]]=Z===$-1?J:F!=null?F:!!~q[Z+1].indexOf(".")||!(+q[Z+1]>-1)?{}:[]}function e6(z,q){for(let J of Object.keys(q)){let Z=q[J];if(Z.shouldTransform){if(z[J]=Array.prototype.concat.call([],z[J]),typeof Z.transformFunction==="function")z[J]=z[J].map(Z.transformFunction)}}}function z4(z){let q=/([^\\/]+)$/.exec(z);return q?q[1]:""}function b(z){return z.split(".").map((q,J)=>{return J===0?C(q):q}).join(".")}class I extends Error{exitCode=2;isUsageError=!0;usage;constructor(z,q){super(z);if(this.name=this.constructor.name,q!==void 0)this.usage=q;if(typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(z).stack}format(z=!1){if(z&&this.stack)return`${this.message}
|
|
4
4
|
|
|
5
5
|
Stack trace:
|
|
6
6
|
${this.stack}`;return this.message}}function q4(z){if(z instanceof I)return!0;return!!z&&typeof z==="object"&&z.name==="ClappError"&&typeof z.message==="string"}function J4(){let{env:z}=z6,{TERM:q,TERM_PROGRAM:J}=z;if(z6.platform!=="win32")return q!=="linux";return Boolean(z.WT_SESSION)||Boolean(z.TERMINUS_SUBLIME)||z.ConEmuTask==="{cmd::Cmder}"||J==="Terminus-Sublime"||J==="vscode"||q==="xterm-256color"||q==="alacritty"||q==="rxvt-unicode"||q==="rxvt-unicode-256color"||z.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var y="\x1B",L=`${y}[`;var P={to(z,q){if(!q)return`${L}${z+1}G`;return`${L}${q+1};${z+1}H`},move(z,q){let J="";if(z<0)J+=`${L}${-z}D`;else if(z>0)J+=`${L}${z}C`;if(q<0)J+=`${L}${-q}A`;else if(q>0)J+=`${L}${q}B`;return J},up:(z=1)=>`${L}${z}A`,down:(z=1)=>`${L}${z}B`,forward:(z=1)=>`${L}${z}C`,backward:(z=1)=>`${L}${z}D`,nextLine:(z=1)=>`${L}E`.repeat(z),prevLine:(z=1)=>`${L}F`.repeat(z),left:`${L}G`,hide:`${L}?25l`,show:`${L}?25h`,save:`${y}7`,restore:`${y}8`};var f={screen:`${L}2J`,up:(z=1)=>`${L}1J`.repeat(z),down:(z=1)=>`${L}J`.repeat(z),line:`${L}2K`,lineEnd:`${L}K`,lineStart:`${L}1K`,lines(z){let q="";for(let J=0;J<z;J++)q+=this.line+(J<z-1?P.up():"");if(z)q+=P.left;return q}},Xz={screen:`${y}c`};function Z4(z,q){let J=[];for(let Z=0;Z<=q.length;Z++)J[Z]=[Z];for(let Z=0;Z<=z.length;Z++)J[0][Z]=Z;for(let Z=1;Z<=q.length;Z++)for(let $=1;$<=z.length;$++)if(q.charAt(Z-1)===z.charAt($-1))J[Z][$]=J[Z-1][$-1];else J[Z][$]=Math.min(J[Z-1][$-1]+1,J[Z][$-1]+1,J[Z-1][$]+1);return J[q.length][z.length]}function X6(z,q,J=2,Z=3){return q.map(($)=>({cmd:$,distance:Z4(z,$)})).filter(({distance:$})=>$<=J).sort(($,Y)=>$.distance-Y.distance).slice(0,Z).map(({cmd:$})=>$)}function $4(z,q={}){let J={_:[]},Z=q.alias||{},$=new Set(q.boolean||[]),Y={};for(let X of Object.keys(Z))for(let Q of Z[X])Y[Q]=X;for(let X of $)if(Z[X])for(let Q of Z[X])$.add(Q);function F(X,Q){let j=Y[X]||X;if(J[j]=Q,Z[j])for(let U of Z[j])J[U]=Q;if(Y[X]&&Z[Y[X]])for(let U of Z[Y[X]])J[U]=Q;J[X]=Q}for(let X=0;X<z.length;X++){let Q=z[X];if(Q==="--"){J._.push(...z.slice(X+1));break}if(Q.startsWith("--")){let j=Q.indexOf("=");if(j!==-1){let U=C(Q.slice(2,j)),H=Q.slice(j+1);F(U,H)}else{let U=Q.slice(2);if(U.startsWith("no-")){let w=C(U.slice(3));F(w,!1);continue}let H=C(U),V=Y[H]||H;if($.has(V)||$.has(H))F(H,!0);else{let w=z[X+1];if(w!==void 0&&!w.startsWith("-"))F(H,w),X++;else F(H,!0)}}}else if(Q.startsWith("-")&&Q.length>1){let j=Q.slice(1);for(let U=0;U<j.length;U++){let H=j[U],V=Y[H]||H;if(U===j.length-1&&!$.has(V)&&!$.has(H)){let w=z[X+1];if(w!==void 0&&!w.startsWith("-"))F(H,w),X++;else F(H,!0)}else F(H,!0)}}else J._.push(Q)}return J}class U6{rawName;description;name;names;isBoolean;required;config;negated;constructor(z,q,J){if(this.rawName=z,this.description=q,this.config=Object.assign({},J),z=z.replace(/\.\*/g,""),this.negated=!1,this.names=m(z).split(",").map((Z)=>{let $=Z.trim().replace(/^-{1,2}/,"");if($.startsWith("no-"))this.negated=!0,$=$.replace(/^no-/,"");return b($)}).sort((Z,$)=>Z.length>$.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(z.includes("<"))this.required=!0;else if(z.includes("["))this.required=!1;else this.isBoolean=!0}}var Fz=d.argv,Q4=`${d.platform}-${d.arch} bun-v${typeof Bun<"u"?Bun.version:"unknown"}`,J6=k.argv,Y4=`${k.platform}-${k.arch} node-${k.version}`;class u{rawName;description;config;cli;options;aliasNames;name;namespace;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;beforeHooks;afterHooks;middleware;constructor(z,q,J,Z){this.rawName=z,this.description=q,this.config=J,this.cli=Z,this.options=[],this.aliasNames=[],this.name=m(z);let $=m(z),Y=$.indexOf(":");if(Y>0)this.namespace=$.substring(0,Y),this.name=$.substring(Y+1);if(this.args=s6(z),this.examples=[],this.beforeHooks=[],this.afterHooks=[],this.middleware=[],!J)this.config={}}usage(z){return this.usageText=z,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(z,q="-v, --version"){return this.versionNumber=z,this.option(q,"Display version number"),this}example(z){return this.examples.push(z),this}option(z,q,J){let Z=new U6(z,q,J);return this.options.push(Z),this}alias(z){return this.aliasNames.push(z),this}action(z){return this.commandAction=z,this}before(z){return this.beforeHooks.push(z),this}after(z){return this.afterHooks.push(z),this}use(z){return this.middleware.push(z),this}isMatched(z){if(this.aliasNames.includes(z))return!0;if(this.namespace)return`${this.namespace}:${this.name}`===z;return this.name===z}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof i}get displayName(){return this.namespace?`${this.namespace}:${this.name}`:this.name}hasOption(z){let q=b(z.split(".")[0]);return!!this.options.find((J)=>{return J.names.some((Z)=>b(Z)===q)})}outputHelp(){let{name:z,commands:q}=this.cli,{versionNumber:J,options:Z,helpCallback:$}=this.cli.globalCommand,Y=[{body:`${z}${J?`/${J}`:""}`}];if(Y.push({title:"Usage",body:` $ ${z} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&q.length>0){let j=q6(q.map((M)=>M.rawName)),U=new Map,H=[];for(let M of q)if(M.namespace){if(!U.has(M.namespace))U.set(M.namespace,[]);U.get(M.namespace).push(M)}else H.push(M);let V="";if(H.sort((M,A)=>M.rawName<A.rawName?-1:M.rawName>A.rawName?1:0),H.length>0)V+=H.map((M)=>{return` ${_(M.rawName,j.length)} ${M.description}`}).join(`
|
|
@@ -38,7 +38,7 @@ Run \`${this.name??"cli"} --help\` for usage.`;N.stderr.write(`${J}${q}${Z}
|
|
|
38
38
|
`).length-1;this.output.write(P.move(-999,z*-1))}render(){let z=Y6(this._render(this)??"",Q6.stdout.columns,{hard:!0,trim:!1});if(z===this._prevFrame)return;if(this.state==="initial")this.output.write(P.hide);else{let q=_4(this._prevFrame,z);if(this.restoreCursor(),q&&q?.length===1){let J=q[0];this.output.write(P.move(0,J)),this.output.write(f.lines(1));let Z=z.split(`
|
|
39
39
|
`);this.output.write(Z[J]),this._prevFrame=z,this.output.write(P.move(0,Z.length-J-1));return}if(q&&q?.length>1){let J=q[0];this.output.write(P.move(0,J)),this.output.write(f.down());let $=z.split(`
|
|
40
40
|
`).slice(J);this.output.write($.join(`
|
|
41
|
-
`)),this._prevFrame=z;return}this.output.write(f.down())}if(this.output.write(z),this.state==="initial")this.state="active";this._prevFrame=z}}function c4(z,q){if(z===void 0)return 0;if(q.length===0)return 0;let Z=q.findIndex(($)=>$.value===z);return Z!==-1?Z:0}function n4(z,q){return(q.label??String(q.value)).toLowerCase().includes(z.toLowerCase())}function p4(z,q){if(!q)return;if(z)return q;return q[0]}class l4 extends n{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#z=0;#J="";#Z;#q;get cursor(){return this.#z}get userInputWithCursor(){if(!this.userInput)return h.inverse(h.hidden("_"));if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let z=this.userInput.slice(0,this._cursor),[q,...J]=this.userInput.slice(this._cursor);return`${z}${h.inverse(q)}${J.join("")}`}get options(){if(typeof this.#q==="function")return this.#q();return this.#q}constructor(z){super(z);this.#q=z.options;let q=this.options;this.filteredOptions=[...q],this.multiple=z.multiple===!0,this.#Z=z.filter??n4;let J;if(z.initialValue&&Array.isArray(z.initialValue))if(this.multiple)J=z.initialValue;else J=z.initialValue.slice(0,1);else if(!this.multiple&&this.options.length>0)J=[this.options[0].value];if(J)for(let Z of J){let $=q.findIndex((Y)=>Y.value===Z);if($!==-1)this.toggleSelected(Z),this.#z=$}this.focusedValue=this.options[this.#z]?.value,this.on("key",(Z,$)=>this.#$(Z,$)),this.on("userInput",(Z)=>this.#Q(Z))}_isActionKey(z,q){return z==="\t"||this.multiple&&this.isNavigating&&q.name==="space"&&z!==void 0&&z!==""}#$(z,q){let J=q.name==="up",Z=q.name==="down",$=q.name==="return";if(J||Z){if(this.#z=Math.max(0,Math.min(this.#z+(J?-1:1),this.filteredOptions.length-1)),this.focusedValue=this.filteredOptions[this.#z]?.value,!this.multiple)this.selectedValues=[this.focusedValue];this.isNavigating=!0}else if($)this.value=p4(this.multiple,this.selectedValues);else if(this.multiple)if(this.focusedValue!==void 0&&(q.name==="tab"||this.isNavigating&&q.name==="space"))this.toggleSelected(this.focusedValue);else this.isNavigating=!1;else{if(this.focusedValue)this.selectedValues=[this.focusedValue];this.isNavigating=!1}}deselectAll(){this.selectedValues=[]}toggleSelected(z){if(this.filteredOptions.length===0)return;if(this.multiple)if(this.selectedValues.includes(z))this.selectedValues=this.selectedValues.filter((q)=>q!==z);else this.selectedValues=[...this.selectedValues,z];else this.selectedValues=[z]}#Q(z){if(z!==this.#J){this.#J=z;let q=this.options;if(z)this.filteredOptions=q.filter((J)=>this.#Z(z,J));else this.filteredOptions=[...q];if(this.#z=c4(this.focusedValue,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#z]?.value,!this.multiple)if(this.focusedValue!==void 0)this.toggleSelected(this.focusedValue);else this.deselectAll()}}}class r4 extends n{options;cursor=0;#z;getGroupItems(z){return this.options.filter((q)=>q.group===z)}isGroupSelected(z){let q=this.getGroupItems(z),J=this.value;if(J===void 0)return!1;return q.every((Z)=>J.includes(Z.value))}toggleValue(){let z=this.options[this.cursor];if(this.value===void 0)this.value=[];if(z.group===!0){let q=String(z.value),J=this.getGroupItems(q);if(this.isGroupSelected(q))this.value=this.value.filter((Z)=>J.findIndex(($)=>$.value===Z)===-1);else this.value=[...this.value,...J.map((Z)=>Z.value)];this.value=Array.from(new Set(this.value))}else{let q=this.value.includes(z.value);this.value=q?this.value.filter((J)=>J!==z.value):[...this.value,z.value]}}constructor(z){super(z,!1);let{options:q}=z;this.#z=z.selectableGroups!==!1,this.options=Object.entries(q).flatMap(([J,Z])=>[{value:J,group:!0,label:J},...Z.map(($)=>({...$,group:J}))]),this.value=[...z.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:J})=>J===z.cursorAt),this.#z?0:1),this.on("cursor",(J)=>{switch(J){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let Z=this.options[this.cursor]?.group===!0;if(!this.#z&&Z)this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let Z=this.options[this.cursor]?.group===!0;if(!this.#z&&Z)this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}case"space":this.toggleValue();break}})}}var a4=J4();var W=(z,q)=>a4?z:q,Nz=W("\u25C6","*"),Oz=W("\u25A0","x"),Tz=W("\u25B2","x"),xz=W("\u25C7","o"),Bz=W("\u250C","T"),s4=W("\u2502","|"),Ez=W("\u2514","\u2014"),bz=W("\u25CF",">"),Iz=W("\u25CB"," "),Az=W("\u25FB","[\u2022]"),Rz=W("\u25FC","[+]"),Cz=W("\u25FB","[ ]"),kz=W("\u25AA","\u2022"),hz=W("\u2500","-"),vz=W("\u256E","+"),yz=W("\u251C","+"),Sz=W("\u256F","+"),gz=W("\u25CF","\u2022"),_z=W("\u25C6","*"),fz=W("\u25B2","!"),mz=W("\u25A0","x");var dz={light:W("\u2500","-"),heavy:W("\u2501","="),block:W("\u2588","#")};function t4(){return`${h.gray(s4)} `}var uz=t4();var p="0.2.
|
|
41
|
+
`)),this._prevFrame=z;return}this.output.write(f.down())}if(this.output.write(z),this.state==="initial")this.state="active";this._prevFrame=z}}function c4(z,q){if(z===void 0)return 0;if(q.length===0)return 0;let Z=q.findIndex(($)=>$.value===z);return Z!==-1?Z:0}function n4(z,q){return(q.label??String(q.value)).toLowerCase().includes(z.toLowerCase())}function p4(z,q){if(!q)return;if(z)return q;return q[0]}class l4 extends n{filteredOptions;multiple;isNavigating=!1;selectedValues=[];focusedValue;#z=0;#J="";#Z;#q;get cursor(){return this.#z}get userInputWithCursor(){if(!this.userInput)return h.inverse(h.hidden("_"));if(this._cursor>=this.userInput.length)return`${this.userInput}\u2588`;let z=this.userInput.slice(0,this._cursor),[q,...J]=this.userInput.slice(this._cursor);return`${z}${h.inverse(q)}${J.join("")}`}get options(){if(typeof this.#q==="function")return this.#q();return this.#q}constructor(z){super(z);this.#q=z.options;let q=this.options;this.filteredOptions=[...q],this.multiple=z.multiple===!0,this.#Z=z.filter??n4;let J;if(z.initialValue&&Array.isArray(z.initialValue))if(this.multiple)J=z.initialValue;else J=z.initialValue.slice(0,1);else if(!this.multiple&&this.options.length>0)J=[this.options[0].value];if(J)for(let Z of J){let $=q.findIndex((Y)=>Y.value===Z);if($!==-1)this.toggleSelected(Z),this.#z=$}this.focusedValue=this.options[this.#z]?.value,this.on("key",(Z,$)=>this.#$(Z,$)),this.on("userInput",(Z)=>this.#Q(Z))}_isActionKey(z,q){return z==="\t"||this.multiple&&this.isNavigating&&q.name==="space"&&z!==void 0&&z!==""}#$(z,q){let J=q.name==="up",Z=q.name==="down",$=q.name==="return";if(J||Z){if(this.#z=Math.max(0,Math.min(this.#z+(J?-1:1),this.filteredOptions.length-1)),this.focusedValue=this.filteredOptions[this.#z]?.value,!this.multiple)this.selectedValues=[this.focusedValue];this.isNavigating=!0}else if($)this.value=p4(this.multiple,this.selectedValues);else if(this.multiple)if(this.focusedValue!==void 0&&(q.name==="tab"||this.isNavigating&&q.name==="space"))this.toggleSelected(this.focusedValue);else this.isNavigating=!1;else{if(this.focusedValue)this.selectedValues=[this.focusedValue];this.isNavigating=!1}}deselectAll(){this.selectedValues=[]}toggleSelected(z){if(this.filteredOptions.length===0)return;if(this.multiple)if(this.selectedValues.includes(z))this.selectedValues=this.selectedValues.filter((q)=>q!==z);else this.selectedValues=[...this.selectedValues,z];else this.selectedValues=[z]}#Q(z){if(z!==this.#J){this.#J=z;let q=this.options;if(z)this.filteredOptions=q.filter((J)=>this.#Z(z,J));else this.filteredOptions=[...q];if(this.#z=c4(this.focusedValue,this.filteredOptions),this.focusedValue=this.filteredOptions[this.#z]?.value,!this.multiple)if(this.focusedValue!==void 0)this.toggleSelected(this.focusedValue);else this.deselectAll()}}}class r4 extends n{options;cursor=0;#z;getGroupItems(z){return this.options.filter((q)=>q.group===z)}isGroupSelected(z){let q=this.getGroupItems(z),J=this.value;if(J===void 0)return!1;return q.every((Z)=>J.includes(Z.value))}toggleValue(){let z=this.options[this.cursor];if(this.value===void 0)this.value=[];if(z.group===!0){let q=String(z.value),J=this.getGroupItems(q);if(this.isGroupSelected(q))this.value=this.value.filter((Z)=>J.findIndex(($)=>$.value===Z)===-1);else this.value=[...this.value,...J.map((Z)=>Z.value)];this.value=Array.from(new Set(this.value))}else{let q=this.value.includes(z.value);this.value=q?this.value.filter((J)=>J!==z.value):[...this.value,z.value]}}constructor(z){super(z,!1);let{options:q}=z;this.#z=z.selectableGroups!==!1,this.options=Object.entries(q).flatMap(([J,Z])=>[{value:J,group:!0,label:J},...Z.map(($)=>({...$,group:J}))]),this.value=[...z.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:J})=>J===z.cursorAt),this.#z?0:1),this.on("cursor",(J)=>{switch(J){case"left":case"up":{this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;let Z=this.options[this.cursor]?.group===!0;if(!this.#z&&Z)this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break}case"down":case"right":{this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;let Z=this.options[this.cursor]?.group===!0;if(!this.#z&&Z)this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}case"space":this.toggleValue();break}})}}var a4=J4();var W=(z,q)=>a4?z:q,Nz=W("\u25C6","*"),Oz=W("\u25A0","x"),Tz=W("\u25B2","x"),xz=W("\u25C7","o"),Bz=W("\u250C","T"),s4=W("\u2502","|"),Ez=W("\u2514","\u2014"),bz=W("\u25CF",">"),Iz=W("\u25CB"," "),Az=W("\u25FB","[\u2022]"),Rz=W("\u25FC","[+]"),Cz=W("\u25FB","[ ]"),kz=W("\u25AA","\u2022"),hz=W("\u2500","-"),vz=W("\u256E","+"),yz=W("\u251C","+"),Sz=W("\u256F","+"),gz=W("\u25CF","\u2022"),_z=W("\u25C6","*"),fz=W("\u25B2","!"),mz=W("\u25A0","x");var dz={light:W("\u2500","-"),heavy:W("\u2501","="),block:W("\u2588","#")};function t4(){return`${h.gray(s4)} `}var uz=t4();var p="0.2.59";var G=new c("query-builder");G.command("introspect <dir>","Load models and print inferred schema").option("--verbose","Enable verbose logging").example("query-builder introspect ./app/Models --verbose").action(async(z,q)=>{await R6(z,q)});G.command("introspect:db","Reverse-introspect the live database into defineModel() source (#1047)").option("--table <table>","Limit to a single table (repeatable)").example("query-builder introspect:db > app/Models/generated.ts").action(async(z)=>{let q=z?.table,J=q?Array.isArray(q)?q:[q]:void 0,Z=await C6({tables:J});console.log(`import { defineModel } from 'bun-query-builder'
|
|
42
42
|
|
|
43
43
|
${Z.map(($)=>$.source).join(`
|
|
44
44
|
`)}`)});G.command("sql <dir> <table>","Build a sample query for a table").option("--limit <n>","Limit rows",{default:10}).example("query-builder sql ./app/Models users --limit 5").action(async(z,q,J)=>{await i6(z,q,J)});G.command("ping","Test database connectivity (uses environment variables)").example("query-builder ping").action(async()=>{await _6()});G.command("wait-ready","Wait for database to become ready").option("--attempts <n>","Number of attempts",{default:10}).option("--delay <ms>","Delay between attempts",{default:100}).example("query-builder wait-ready --attempts 30 --delay 250").action(async(z)=>{try{await l6(z)}catch{let q=await import("process");q.default.exitCode=1}});G.command("unsafe <sql>","Execute an unsafe SQL string (one statement with params)").option("--params <json>","JSON array of parameters").example('query-builder unsafe "SELECT * FROM users WHERE id = $1" --params "[1]"').action(async(z,q)=>{await c6(z,q)});G.command("file <path>","Execute a SQL file (supports $1, $2 params)").option("--params <json>","JSON array of parameters").example("query-builder file ./migrations/seed.sql").example('query-builder file ./reports/top.sql --params "[30]"').action(async(z,q)=>{await b6(z,q)});G.command("migrate <dir>","Generate SQL migrations from models").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--state <path>","Path to migration state file (defaults to <dir>/.qb-migrations.<dialect>.json)").option("--apply","Execute the generated SQL against the database").option("--full","Force full migration SQL instead of incremental diff").example("query-builder migrate ./app/Models --dialect postgres").action(async(z,q)=>{try{await l(z,{dialect:q.dialect,state:q.state,apply:q.apply,full:q.full}),await r()}catch(J){console.error("-- Migration failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("explain <sql>","Explain a query").example('query-builder explain "SELECT * FROM users WHERE active = true"').action(async(z)=>{await E6(z)});G.command("query:explain-all <path>","Run EXPLAIN on all SQL files in a directory").option("--verbose","Enable verbose output").option("--json","Output as JSON").example("query-builder query:explain-all ./queries").example("query-builder query:explain-all ./queries/users.sql").action(async(z,q)=>{try{await f6(z,{verbose:q.verbose,json:q.json})}catch(J){console.error("-- Explain all failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("relation:diagram","Generate relationship diagram from models").option("--dir <path>","Models directory (defaults to app/Models)").option("--format <fmt>","Output format (mermaid|dot)",{default:"mermaid"}).option("--output <path>","Output file path").option("--verbose","Enable verbose output").example("query-builder relation:diagram").example("query-builder relation:diagram --format dot --output schema.dot").example("query-builder relation:diagram --output schema.mmd").action(async(z)=>{try{await m6({dir:z.dir,format:z.format,output:z.output,verbose:z.verbose})}catch(q){console.error("-- Diagram generation failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("migrate:fresh <dir>","Reset database and run all migrations").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--state <path>","Path to migration state file (defaults to <dir>/.qb-migrations.<dialect>.json)").option("--full","Force full migration SQL instead of incremental diff").example("query-builder migrate:fresh ./app/Models --dialect postgres").action(async(z,q)=>{try{console.log("-- Resetting database..."),await a(z,{dialect:q.dialect,state:q.state}),console.log("-- Generating fresh migrations..."),await l(z,{dialect:q.dialect,state:q.state,full:q.full}),console.log("-- Executing migrations..."),await r()}catch(J){console.error("-- Migrate fresh failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("reset <dir>","Drop all tables and reset database").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--state <path>","Path to migration state file (defaults to <dir>/.qb-migrations.<dialect>.json)").example("query-builder reset ./app/Models --dialect postgres").action(async(z,q)=>{try{await a(z,{dialect:q.dialect,state:q.state})}catch(J){console.error("-- Reset failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("seed","Run database seeders").option("--dir <path>","Path to seeders directory (defaults to database/seeders)").option("--class <name>","Run a specific seeder class").option("--verbose","Enable verbose logging").example("query-builder seed").example("query-builder seed --class UserSeeder").example("query-builder seed --dir ./database/seeders").action(async(z)=>{try{if(z.class)await t(z.class,{verbose:z.verbose});else await s({seedersDir:z.dir,verbose:z.verbose})}catch(q){console.error("-- Seeding failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("db:seed","Run database seeders (alias for seed)").option("--dir <path>","Path to seeders directory (defaults to database/seeders)").option("--class <name>","Run a specific seeder class").option("--verbose","Enable verbose logging").example("query-builder db:seed").example("query-builder db:seed --class UserSeeder").action(async(z)=>{try{if(z.class)await t(z.class,{verbose:z.verbose});else await s({seedersDir:z.dir,verbose:z.verbose})}catch(q){console.error("-- Seeding failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("make:seeder <name>","Create a new seeder file").example("query-builder make:seeder User").example("query-builder make:seeder UserSeeder").action(async(z)=>{try{await d6(z)}catch(q){console.error("-- Failed to create seeder:",q);let J=await import("process");J.default.exitCode=1}});G.command("db:fresh","Drop all tables, re-run migrations and seed the database").option("--models <path>","Path to models directory (defaults to app/Models)").option("--seeders <path>","Path to seeders directory (defaults to database/seeders)").option("--verbose","Enable verbose logging").example("query-builder db:fresh").example("query-builder db:fresh --models ./app/Models --seeders ./database/seeders").action(async(z)=>{try{await u6({modelsDir:z.models,seedersDir:z.seeders,verbose:z.verbose})}catch(q){console.error("-- Database fresh failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("make:model <name>","Create a new model file").option("--table <name>","Table name (defaults to plural of model name)").option("--dir <path>","Models directory (defaults to app/Models)").option("--timestamps","Include timestamp fields (default: true)").example("query-builder make:model User").example("query-builder make:model Post --table=blog_posts").action(async(z,q)=>{try{await k6(z,{table:q.table,dir:q.dir,timestamps:q.timestamps})}catch(J){console.error("-- Failed to create model:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("model:show <name>","Show detailed model information").option("--dir <path>","Models directory (defaults to app/Models)").option("--json","Output as JSON").option("--verbose","Enable verbose output").example("query-builder model:show User").example("query-builder model:show Post --json").action(async(z,q)=>{try{await g6(z,{dir:q.dir,json:q.json,verbose:q.verbose})}catch(J){console.error("-- Failed to show model:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("migrate:status","Show migration status").example("query-builder migrate:status").action(async()=>{try{await y6()}catch(z){console.error("-- Failed to get migration status:",z);let q=await import("process");q.default.exitCode=1}});G.command("migrate:list","List all migrations (alias for migrate:status)").example("query-builder migrate:list").action(async()=>{try{await S6()}catch(z){console.error("-- Failed to list migrations:",z);let q=await import("process");q.default.exitCode=1}});G.command("migrate:rollback","Rollback migrations").option("--steps <n>","Number of migrations to rollback",{default:1}).option("--no-reverse-schema","Only remove the migration records; leave the schema alone").option("--delete-files","Also delete the rolled-back migration files from disk").example("query-builder migrate:rollback").example("query-builder migrate:rollback --steps 2").example("query-builder migrate:rollback --no-reverse-schema").action(async(z)=>{try{await v6({steps:Number(z.steps),reverseSchema:z.reverseSchema,deleteFiles:Boolean(z.deleteFiles)})}catch(q){console.error("-- Rollback failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("migrate:generate [dir]","Generate migration from model changes").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--state <path>","Path to migration state file").option("--apply","Execute the generated SQL").option("--full","Force full migration SQL").example("query-builder migrate:generate").example("query-builder migrate:generate ./app/Models --dialect postgres").action(async(z,q)=>{try{await h6(z,{dialect:q?.dialect,state:q?.state,apply:q?.apply,full:q?.full})}catch(J){console.error("-- Generate migration failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("db:info","Show database information and statistics").example("query-builder db:info").action(async()=>{try{await O6()}catch(z){console.error("-- Failed to get database info:",z);let q=await import("process");q.default.exitCode=1}});G.command("db:stats","Show database statistics (alias for db:info)").example("query-builder db:stats").action(async()=>{try{await T6()}catch(z){console.error("-- Failed to get database stats:",z);let q=await import("process");q.default.exitCode=1}});G.command("db:wipe","Drop all tables from the database").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--force","Skip confirmation prompt").option("--verbose","Enable verbose output").example("query-builder db:wipe").example("query-builder db:wipe --force").action(async(z)=>{try{await B6({dialect:z.dialect,force:z.force,verbose:z.verbose})}catch(q){console.error("-- Wipe failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("db:optimize","Optimize database tables (VACUUM, ANALYZE, OPTIMIZE)").option("--dialect <d>","Dialect (postgres|mysql|sqlite) \u2014 defaults to the configured dialect").option("--aggressive","Use aggressive optimization (VACUUM FULL for postgres)").option("--tables <tables>","Comma-separated list of tables to optimize").option("--verbose","Enable verbose output").example("query-builder db:optimize").example("query-builder db:optimize --aggressive").example("query-builder db:optimize --tables users,posts").action(async(z)=>{try{await x6({dialect:z.dialect,aggressive:z.aggressive,tables:z.tables?z.tables.split(","):void 0,verbose:z.verbose})}catch(q){console.error("-- Optimize failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("console","Start interactive query console").example("query-builder console").action(async()=>{try{await L6()}catch(z){console.error("-- Console failed:",z);let q=await import("process");q.default.exitCode=1}});G.command("tinker","Start interactive query console (alias for console)").example("query-builder tinker").action(async()=>{try{await M6()}catch(z){console.error("-- Tinker failed:",z);let q=await import("process");q.default.exitCode=1}});G.command("inspect <table>","Inspect a table structure").option("--verbose","Enable verbose output",{default:!0}).example("query-builder inspect users").action(async(z,q)=>{try{await I6(z,{verbose:q.verbose})}catch(J){console.error("-- Failed to inspect table:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("table:info <table>","Show table information (alias for inspect)").option("--verbose","Enable verbose output",{default:!0}).example("query-builder table:info users").action(async(z,q)=>{try{await A6(z,{verbose:q.verbose})}catch(J){console.error("-- Failed to get table info:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("cache:clear","Clear the query cache").example("query-builder cache:clear").action(async()=>{try{await V6()}catch(z){console.error("-- Failed to clear cache:",z);let q=await import("process");q.default.exitCode=1}});G.command("cache:stats","Show cache statistics").example("query-builder cache:stats").action(async()=>{try{await W6()}catch(z){console.error("-- Failed to get cache stats:",z);let q=await import("process");q.default.exitCode=1}});G.command("cache:config","Configure cache settings").option("--size <n>","Set maximum cache size").example("query-builder cache:config --size 500").action(async(z)=>{try{await D6({size:z.size})}catch(q){console.error("-- Failed to configure cache:",q);let J=await import("process");J.default.exitCode=1}});G.command("benchmark","Run performance benchmarks").option("--operations <ops>","Comma-separated list of operations (select,insert,update,delete,count)").option("--iterations <n>","Number of iterations per operation",{default:1000}).example("query-builder benchmark").example("query-builder benchmark --operations select,insert --iterations 5000").action(async(z)=>{try{await K6({operations:z.operations,iterations:z.iterations?Number(z.iterations):void 0})}catch(q){console.error("-- Benchmark failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("validate:schema [dir]","Validate models against database schema").example("query-builder validate:schema").example("query-builder validate:schema ./app/Models").action(async(z)=>{try{await n6(z)}catch(q){console.error("-- Validation failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("check [dir]","Validate schema (alias for validate:schema)").example("query-builder check").action(async(z)=>{try{await p6(z)}catch(q){console.error("-- Check failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("export <table>","Export data from a table").option("--format <fmt>","Export format (json|csv|sql)",{default:"json"}).option("--output <path>","Output file path").option("--limit <n>","Limit number of rows").example("query-builder export users").example("query-builder export users --format csv --output users.csv").example("query-builder export users --format sql --limit 100").action(async(z,q)=>{try{await w6(z,{format:q.format,output:q.output,limit:q.limit?Number(q.limit):void 0})}catch(J){console.error("-- Export failed:",J);let Z=await import("process");Z.default.exitCode=1}});G.command("import <table> <file>","Import data into a table").option("--format <fmt>","Import format (json|csv)").option("--truncate","Truncate table before import").example("query-builder import users users.json").example("query-builder import users users.csv --truncate").action(async(z,q,J)=>{try{await P6(z,q,{format:J.format,truncate:J.truncate})}catch(Z){console.error("-- Import failed:",Z);let $=await import("process");$.default.exitCode=1}});G.command("dump","Dump database to SQL file").option("--tables <tables>","Comma-separated list of tables to dump").option("--output <path>","Output file path").example("query-builder dump").example("query-builder dump --tables users,posts").example("query-builder dump --output backup.sql").action(async(z)=>{try{await N6({tables:z.tables,output:z.output})}catch(q){console.error("-- Dump failed:",q);let J=await import("process");J.default.exitCode=1}});G.command("version","Show the version of the CLI").action(()=>{console.log(p)});G.version(p);G.help();G.parse();
|