just-bash 2.2.0 → 2.3.0

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.
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ import{a as z,b as W}from"./chunk-GTNBSMZR.js";import{a as m,c as p,e as Le}from"./chunk-KGOUQS5A.js";var y=p(_=>{"use strict";_.getBooleanOption=(e,t)=>{let r=!1;if(t in e&&typeof(r=e[t])!="boolean")throw new TypeError(`Expected the "${t}" option to be a boolean`);return r};_.cppdb=Symbol();_.inspect=Symbol.for("nodejs.util.inspect.custom")});var k=p((St,H)=>{"use strict";var B={value:"SqliteError",writable:!0,enumerable:!1,configurable:!0};function x(e,t){if(new.target!==x)return new x(e,t);if(typeof t!="string")throw new TypeError("Expected second argument to be a string");Error.call(this,e),B.value=""+e,Object.defineProperty(this,"message",B),Error.captureStackTrace(this,x),this.code=t}Object.setPrototypeOf(x,Error);Object.setPrototypeOf(x.prototype,Error.prototype);Object.defineProperty(x.prototype,"name",B);H.exports=x});var J=p((qt,Q)=>{var v=m("path").sep||"/";Q.exports=Re;function Re(e){if(typeof e!="string"||e.length<=7||e.substring(0,7)!="file://")throw new TypeError("must pass in a file:// URI to convert to a file path");var t=decodeURI(e.substring(7)),r=t.indexOf("/"),n=t.substring(0,r),i=t.substring(r+1);return n=="localhost"&&(n=""),n&&(n=v+v+n),i=i.replace(/^(.+)\|/,"$1:"),v=="\\"&&(i=i.replace(/\//g,"\\")),/^.+\:/.test(i)||(i=v+i),n+i}});var Y=p((O,X)=>{var M=m("fs"),L=m("path"),Ve=J(),C=L.join,Ae=L.dirname,G=M.accessSync&&function(e){try{M.accessSync(e)}catch{return!1}return!0}||M.existsSync||L.existsSync,K={arrow:process.env.NODE_BINDINGS_ARROW||" \u2192 ",compiled:process.env.NODE_BINDINGS_COMPILED_DIR||"compiled",platform:process.platform,arch:process.arch,nodePreGyp:"node-v"+process.versions.modules+"-"+process.platform+"-"+process.arch,version:process.versions.node,bindings:"bindings.node",try:[["module_root","build","bindings"],["module_root","build","Debug","bindings"],["module_root","build","Release","bindings"],["module_root","out","Debug","bindings"],["module_root","Debug","bindings"],["module_root","out","Release","bindings"],["module_root","Release","bindings"],["module_root","build","default","bindings"],["module_root","compiled","version","platform","arch","bindings"],["module_root","addon-build","release","install-root","bindings"],["module_root","addon-build","debug","install-root","bindings"],["module_root","addon-build","default","install-root","bindings"],["module_root","lib","binding","nodePreGyp","bindings"]]};function De(e){typeof e=="string"?e={bindings:e}:e||(e={}),Object.keys(K).map(function(l){l in e||(e[l]=K[l])}),e.module_root||(e.module_root=O.getRoot(O.getFileName())),L.extname(e.bindings)!=".node"&&(e.bindings+=".node");for(var t=typeof __webpack_require__=="function"?__non_webpack_require__:m,r=[],n=0,i=e.try.length,o,s,a;n<i;n++){o=C.apply(null,e.try[n].map(function(l){return e[l]||l})),r.push(o);try{return s=e.path?t.resolve(o):t(o),e.path||(s.path=o),s}catch(l){if(l.code!=="MODULE_NOT_FOUND"&&l.code!=="QUALIFIED_PATH_RESOLUTION_FAILED"&&!/not find/i.test(l.message))throw l}}throw a=new Error(`Could not locate the bindings file. Tried:
3
+ `+r.map(function(l){return e.arrow+l}).join(`
4
+ `)),a.tries=r,a}X.exports=O=De;O.getFileName=function(t){var r=Error.prepareStackTrace,n=Error.stackTraceLimit,i={},o;Error.stackTraceLimit=10,Error.prepareStackTrace=function(a,l){for(var u=0,f=l.length;u<f;u++)if(o=l[u].getFileName(),o!==__filename)if(t){if(o!==t)return}else return},Error.captureStackTrace(i),i.stack,Error.prepareStackTrace=r,Error.stackTraceLimit=n;var s="file://";return o.indexOf(s)===0&&(o=Ve(o)),o};O.getRoot=function(t){for(var r=Ae(t),n;;){if(r==="."&&(r=process.cwd()),G(C(r,"package.json"))||G(C(r,"node_modules")))return r;if(n===r)throw new Error('Could not find module root given file: "'+t+'". Do you have a `package.json` file? ');n=r,r=C(r,"..")}}});var Z=p(E=>{"use strict";var{cppdb:b}=y();E.prepare=function(t){return this[b].prepare(t,this,!1)};E.exec=function(t){return this[b].exec(t),this};E.close=function(){return this[b].close(),this};E.loadExtension=function(...t){return this[b].loadExtension(...t),this};E.defaultSafeIntegers=function(...t){return this[b].defaultSafeIntegers(...t),this};E.unsafeMode=function(...t){return this[b].unsafeMode(...t),this};E.getters={name:{get:function(){return this[b].name},enumerable:!0},open:{get:function(){return this[b].open},enumerable:!0},inTransaction:{get:function(){return this[b].inTransaction},enumerable:!0},readonly:{get:function(){return this[b].readonly},enumerable:!0},memory:{get:function(){return this[b].memory},enumerable:!0}}});var re=p((vt,te)=>{"use strict";var{cppdb:Pe}=y(),ee=new WeakMap;te.exports=function(t){if(typeof t!="function")throw new TypeError("Expected first argument to be a function");let r=this[Pe],n=Be(r,this),{apply:i}=Function.prototype,o={default:{value:R(i,t,r,n.default)},deferred:{value:R(i,t,r,n.deferred)},immediate:{value:R(i,t,r,n.immediate)},exclusive:{value:R(i,t,r,n.exclusive)},database:{value:this,enumerable:!0}};return Object.defineProperties(o.default.value,o),Object.defineProperties(o.deferred.value,o),Object.defineProperties(o.immediate.value,o),Object.defineProperties(o.exclusive.value,o),o.default.value};var Be=(e,t)=>{let r=ee.get(e);if(!r){let n={commit:e.prepare("COMMIT",t,!1),rollback:e.prepare("ROLLBACK",t,!1),savepoint:e.prepare("SAVEPOINT ` _bs3. `",t,!1),release:e.prepare("RELEASE ` _bs3. `",t,!1),rollbackTo:e.prepare("ROLLBACK TO ` _bs3. `",t,!1)};ee.set(e,r={default:Object.assign({begin:e.prepare("BEGIN",t,!1)},n),deferred:Object.assign({begin:e.prepare("BEGIN DEFERRED",t,!1)},n),immediate:Object.assign({begin:e.prepare("BEGIN IMMEDIATE",t,!1)},n),exclusive:Object.assign({begin:e.prepare("BEGIN EXCLUSIVE",t,!1)},n)})}return r},R=(e,t,r,{begin:n,commit:i,rollback:o,savepoint:s,release:a,rollbackTo:l})=>function(){let f,d,g;r.inTransaction?(f=s,d=a,g=l):(f=n,d=i,g=o),f.run();try{let w=e.call(t,this,arguments);if(w&&typeof w.then=="function")throw new TypeError("Transaction function cannot return a promise");return d.run(),w}catch(w){throw r.inTransaction&&(g.run(),g!==o&&d.run()),w}}});var oe=p((Ct,ne)=>{"use strict";var{getBooleanOption:ke,cppdb:Me}=y();ne.exports=function(t,r){if(r==null&&(r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");let n=ke(r,"simple"),i=this[Me].prepare(`PRAGMA ${t}`,this,!0);return n?i.pluck().get():i.all()}});var se=p((Lt,ae)=>{"use strict";var Fe=m("fs"),Ne=m("path"),{promisify:Ue}=m("util"),{cppdb:ze}=y(),ie=Ue(Fe.access);ae.exports=async function(t,r){if(r==null&&(r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");t=t.trim();let n="attached"in r?r.attached:"main",i="progress"in r?r.progress:null;if(!t)throw new TypeError("Backup filename cannot be an empty string");if(t===":memory:")throw new TypeError('Invalid backup filename ":memory:"');if(typeof n!="string")throw new TypeError('Expected the "attached" option to be a string');if(!n)throw new TypeError('The "attached" option cannot be an empty string');if(i!=null&&typeof i!="function")throw new TypeError('Expected the "progress" option to be a function');await ie(Ne.dirname(t)).catch(()=>{throw new TypeError("Cannot save backup because the directory does not exist")});let o=await ie(t).then(()=>!1,()=>!0);return We(this[ze].backup(this,n,t,o),i||null)};var We=(e,t)=>{let r=0,n=!0;return new Promise((i,o)=>{setImmediate(function s(){try{let a=e.transfer(r);if(!a.remainingPages){e.close(),i(a);return}if(n&&(n=!1,r=100),t){let l=t(a);if(l!==void 0)if(typeof l=="number"&&l===l)r=Math.max(0,Math.min(2147483647,Math.round(l)));else throw new TypeError("Expected progress callback to return a number or undefined")}setImmediate(s)}catch(a){e.close(),o(a)}})})}});var ue=p((Rt,le)=>{"use strict";var{cppdb:He}=y();le.exports=function(t){if(t==null&&(t={}),typeof t!="object")throw new TypeError("Expected first argument to be an options object");let r="attached"in t?t.attached:"main";if(typeof r!="string")throw new TypeError('Expected the "attached" option to be a string');if(!r)throw new TypeError('The "attached" option cannot be an empty string');return this[He].serialize(r)}});var ce=p((Vt,fe)=>{"use strict";var{getBooleanOption:V,cppdb:Qe}=y();fe.exports=function(t,r,n){if(r==null&&(r={}),typeof r=="function"&&(n=r,r={}),typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof n!="function")throw new TypeError("Expected last argument to be a function");if(typeof r!="object")throw new TypeError("Expected second argument to be an options object");if(!t)throw new TypeError("User-defined function name cannot be an empty string");let i="safeIntegers"in r?+V(r,"safeIntegers"):2,o=V(r,"deterministic"),s=V(r,"directOnly"),a=V(r,"varargs"),l=-1;if(!a){if(l=n.length,!Number.isInteger(l)||l<0)throw new TypeError("Expected function.length to be a positive integer");if(l>100)throw new RangeError("User-defined functions cannot have more than 100 arguments")}return this[Qe].function(n,t,l,i,o,s),this}});var he=p((At,de)=>{"use strict";var{getBooleanOption:A,cppdb:Je}=y();de.exports=function(t,r){if(typeof t!="string")throw new TypeError("Expected first argument to be a string");if(typeof r!="object"||r===null)throw new TypeError("Expected second argument to be an options object");if(!t)throw new TypeError("User-defined function name cannot be an empty string");let n="start"in r?r.start:null,i=F(r,"step",!0),o=F(r,"inverse",!1),s=F(r,"result",!1),a="safeIntegers"in r?+A(r,"safeIntegers"):2,l=A(r,"deterministic"),u=A(r,"directOnly"),f=A(r,"varargs"),d=-1;if(!f&&(d=Math.max(pe(i),o?pe(o):0),d>0&&(d-=1),d>100))throw new RangeError("User-defined functions cannot have more than 100 arguments");return this[Je].aggregate(n,i,o,s,t,d,a,l,u),this};var F=(e,t,r)=>{let n=t in e?e[t]:null;if(typeof n=="function")return n;if(n!=null)throw new TypeError(`Expected the "${t}" option to be a function`);if(r)throw new TypeError(`Missing required option "${t}"`);return null},pe=({length:e})=>{if(Number.isInteger(e)&&e>=0)return e;throw new TypeError("Expected function.length to be a positive integer")}});var ye=p((Dt,be)=>{"use strict";var{cppdb:Ge}=y();be.exports=function(t,r){if(typeof t!="string")throw new TypeError("Expected first argument to be a string");if(!t)throw new TypeError("Virtual table module name cannot be an empty string");let n=!1;if(typeof r=="object"&&r!==null)n=!0,r=nt(ge(r,"used",t));else{if(typeof r!="function")throw new TypeError("Expected second argument to be a function or a table definition object");r=Ke(r)}return this[Ge].table(r,t,n),this};function Ke(e){return function(r,n,i,...o){let s={module:r,database:n,table:i},a=tt.call(e,s,o);if(typeof a!="object"||a===null)throw new TypeError(`Virtual table module "${r}" did not return a table definition object`);return ge(a,"returned",r)}}function ge(e,t,r){if(!S.call(e,"rows"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition without a "rows" property`);if(!S.call(e,"columns"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition without a "columns" property`);let n=e.rows;if(typeof n!="function"||Object.getPrototypeOf(n)!==rt)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "rows" property (should be a generator function)`);let i=e.columns;if(!Array.isArray(i)||!(i=[...i]).every(u=>typeof u=="string"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "columns" property (should be an array of strings)`);if(i.length!==new Set(i).size)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with duplicate column names`);if(!i.length)throw new RangeError(`Virtual table module "${r}" ${t} a table definition with zero columns`);let o;if(S.call(e,"parameters")){if(o=e.parameters,!Array.isArray(o)||!(o=[...o]).every(u=>typeof u=="string"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "parameters" property (should be an array of strings)`)}else o=et(n);if(o.length!==new Set(o).size)throw new TypeError(`Virtual table module "${r}" ${t} a table definition with duplicate parameter names`);if(o.length>32)throw new RangeError(`Virtual table module "${r}" ${t} a table definition with more than the maximum number of 32 parameters`);for(let u of o)if(i.includes(u))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with column "${u}" which was ambiguously defined as both a column and parameter`);let s=2;if(S.call(e,"safeIntegers")){let u=e.safeIntegers;if(typeof u!="boolean")throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "safeIntegers" property (should be a boolean)`);s=+u}let a=!1;if(S.call(e,"directOnly")&&(a=e.directOnly,typeof a!="boolean"))throw new TypeError(`Virtual table module "${r}" ${t} a table definition with an invalid "directOnly" property (should be a boolean)`);return[`CREATE TABLE x(${[...o.map(me).map(u=>`${u} HIDDEN`),...i.map(me)].join(", ")});`,Xe(n,new Map(i.map((u,f)=>[u,o.length+f])),r),o,s,a]}function Xe(e,t,r){return function*(...i){let o=i.map(s=>Buffer.isBuffer(s)?Buffer.from(s):s);for(let s=0;s<t.size;++s)o.push(null);for(let s of e(...i))if(Array.isArray(s))Ye(s,o,t.size,r),yield o;else if(typeof s=="object"&&s!==null)Ze(s,o,t,r),yield o;else throw new TypeError(`Virtual table module "${r}" yielded something that isn't a valid row object`)}}function Ye(e,t,r,n){if(e.length!==r)throw new TypeError(`Virtual table module "${n}" yielded a row with an incorrect number of columns`);let i=t.length-r;for(let o=0;o<r;++o)t[o+i]=e[o]}function Ze(e,t,r,n){let i=0;for(let o of Object.keys(e)){let s=r.get(o);if(s===void 0)throw new TypeError(`Virtual table module "${n}" yielded a row with an undeclared column "${o}"`);t[s]=e[o],i+=1}if(i!==r.size)throw new TypeError(`Virtual table module "${n}" yielded a row with missing columns`)}function et({length:e}){if(!Number.isInteger(e)||e<0)throw new TypeError("Expected function.length to be a positive integer");let t=[];for(let r=0;r<e;++r)t.push(`$${r+1}`);return t}var{hasOwnProperty:S}=Object.prototype,{apply:tt}=Function.prototype,rt=Object.getPrototypeOf(function*(){}),me=e=>`"${e.replace(/"/g,'""')}"`,nt=e=>()=>e});var Ee=p((Pt,we)=>{"use strict";var ot=function(){};we.exports=function(t,r){return Object.assign(new ot,this)}});var $e=p((Bt,je)=>{"use strict";var it=m("fs"),Te=m("path"),D=y(),at=k(),xe;function c(e,t){if(new.target==null)return new c(e,t);let r;if(Buffer.isBuffer(e)&&(r=e,e=":memory:"),e==null&&(e=""),t==null&&(t={}),typeof e!="string")throw new TypeError("Expected first argument to be a string");if(typeof t!="object")throw new TypeError("Expected second argument to be an options object");if("readOnly"in t)throw new TypeError('Misspelled option "readOnly" should be "readonly"');if("memory"in t)throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');let n=e.trim(),i=n===""||n===":memory:",o=D.getBooleanOption(t,"readonly"),s=D.getBooleanOption(t,"fileMustExist"),a="timeout"in t?t.timeout:5e3,l="verbose"in t?t.verbose:null,u="nativeBinding"in t?t.nativeBinding:null;if(o&&i&&!r)throw new TypeError("In-memory/temporary databases cannot be readonly");if(!Number.isInteger(a)||a<0)throw new TypeError('Expected the "timeout" option to be a positive integer');if(a>2147483647)throw new RangeError('Option "timeout" cannot be greater than 2147483647');if(l!=null&&typeof l!="function")throw new TypeError('Expected the "verbose" option to be a function');if(u!=null&&typeof u!="string"&&typeof u!="object")throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');let f;if(u==null?f=xe||(xe=Y()("better_sqlite3.node")):typeof u=="string"?f=(typeof __non_webpack_require__=="function"?__non_webpack_require__:m)(Te.resolve(u).replace(/(\.node)?$/,".node")):f=u,f.isInitialized||(f.setErrorConstructor(at),f.isInitialized=!0),!i&&!it.existsSync(Te.dirname(n)))throw new TypeError("Cannot open database because the directory does not exist");Object.defineProperties(this,{[D.cppdb]:{value:new f.Database(n,e,i,o,s,a,l||null,r||null)},...j.getters})}var j=Z();c.prototype.prepare=j.prepare;c.prototype.transaction=re();c.prototype.pragma=oe();c.prototype.backup=se();c.prototype.serialize=ue();c.prototype.function=ce();c.prototype.aggregate=he();c.prototype.table=ye();c.prototype.loadExtension=j.loadExtension;c.prototype.exec=j.exec;c.prototype.close=j.close;c.prototype.defaultSafeIntegers=j.defaultSafeIntegers;c.prototype.unsafeMode=j.unsafeMode;c.prototype[D.inspect]=Ee();je.exports=c});var Oe=p((Mt,N)=>{"use strict";N.exports=$e();N.exports.SqliteError=k()});var q=Le(Oe(),1);function Ie(e,t,r){switch(r.mode){case"list":return st(e,t,r);case"csv":return lt(e,t,r);case"json":return ft(e,t);case"line":return ct(e,t,r);case"column":return pt(e,t,r);case"table":return dt(e,t,r);case"markdown":return ht(e,t,r);case"tabs":return mt(e,t,r);case"box":return gt(e,t,r);case"quote":return bt(e,t,r);case"html":return yt(e,t,r);case"ascii":return wt(e,t,r)}}function h(e,t){return e==null?t:e instanceof Uint8Array||Buffer.isBuffer(e)?Buffer.from(e).toString("utf8"):typeof e=="number"&&!Number.isInteger(e)?e.toPrecision(17).replace(/\.?0+$/,""):String(e)}function st(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(r.separator));for(let i of t)n.push(i.map(o=>h(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function lt(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(Se).join(","));for(let i of t)n.push(i.map(o=>Se(h(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
5
+ `)}
6
+ `:""}function Se(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
7
+ `)?`"${e.replace(/"/g,'""')}"`:e}function _e(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function ut(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):_e(e):JSON.stringify(e)}function ft(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,s)=>`${JSON.stringify(o)}:${ut(n[s])}`).join(",")}}`).join(`,
8
+ `)}]
9
+ `}function ct(e,t,r){if(e.length===0||t.length===0)return"";let n=Math.max(5,...e.map(o=>o.length)),i=[];for(let o of t)for(let s=0;s<e.length;s++){let a=e[s].padStart(n);i.push(`${a} = ${h(o[s],r.nullValue)}`)}return`${i.join(`
10
+ `)}
11
+ `}function pt(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let s=0;s<o.length;s++){let a=h(o[s],r.nullValue).length;a>n[s]&&(n[s]=a)}let i=[];r.header&&(i.push(e.map((o,s)=>o.padEnd(n[s])).join(" ")),i.push(n.map(o=>"-".repeat(o)).join(" ")));for(let o of t)i.push(o.map((s,a)=>h(s,r.nullValue).padEnd(n[a])).join(" "));return i.length>0?`${i.join(`
12
+ `)}
13
+ `:""}function dt(e,t,r){if(e.length===0)return"";let n=e.map(s=>s.length);for(let s of t)for(let a=0;a<s.length;a++){let l=h(s[a],r.nullValue).length;l>n[a]&&(n[a]=l)}let i=[],o=`+${n.map(s=>"-".repeat(s+2)).join("+")}+`;i.push(o),r.header&&(i.push(`| ${e.map((s,a)=>s.padEnd(n[a])).join(" | ")} |`),i.push(o));for(let s of t)i.push(`| ${s.map((a,l)=>h(a,r.nullValue).padEnd(n[l])).join(" | ")} |`);return i.push(o),`${i.join(`
14
+ `)}
15
+ `}function ht(e,t,r){if(e.length===0)return"";let n=[];r.header&&(n.push(`| ${e.join(" | ")} |`),n.push(`|${e.map(()=>"---").join("|")}|`));for(let i of t)n.push(`| ${i.map(o=>h(o,r.nullValue)).join(" | ")} |`);return n.length>0?`${n.join(`
16
+ `)}
17
+ `:""}function mt(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(" "));for(let i of t)n.push(i.map(o=>h(o,r.nullValue)).join(" "));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function gt(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let s=0;s<o.length;s++){let a=h(o[s],r.nullValue).length;a>n[s]&&(n[s]=a)}let i=[];i.push(`\u250C${n.map(o=>"\u2500".repeat(o+2)).join("\u252C")}\u2510`),i.push(`\u2502 ${e.map((o,s)=>o.padEnd(n[s])).join(" \u2502 ")} \u2502`),i.push(`\u251C${n.map(o=>"\u2500".repeat(o+2)).join("\u253C")}\u2524`);for(let o of t)i.push(`\u2502 ${o.map((s,a)=>h(s,r.nullValue).padEnd(n[a])).join(" \u2502 ")} \u2502`);return i.push(`\u2514${n.map(o=>"\u2500".repeat(o+2)).join("\u2534")}\u2518`),`${i.join(`
18
+ `)}
19
+ `}function bt(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map(i=>`'${i}'`).join(","));for(let i of t)n.push(i.map(o=>o==null?"NULL":typeof o=="number"?Number.isInteger(o)?String(o):_e(o):`'${String(o)}'`).join(","));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function yt(e,t,r){let n=[];r.header&&e.length>0&&(n.push(`<TR>${e.map(i=>`<TH>${qe(i)}</TH>`).join("")}`),n.push("</TR>"));for(let i of t)n.push(`<TR>${i.map(o=>`<TD>${qe(h(o,r.nullValue))}</TD>`).join("")}`),n.push("</TR>");return n.length>0?`${n.join(`
20
+ `)}
21
+ `:""}function qe(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function wt(e,t,r){let o=[];r.header&&e.length>0&&o.push(e.join(""));for(let s of t)o.push(s.map(a=>h(a,r.nullValue)).join(""));return o.length>0?o.join("")+"":""}var Et={name:"sqlite3",summary:"SQLite database CLI",usage:"sqlite3 [OPTIONS] DATABASE [SQL]",options:["-list output in list mode (default)","-csv output in CSV mode","-json output in JSON mode","-line output in line mode","-column output in column mode","-table output as ASCII table","-markdown output as markdown table","-tabs output in tab-separated mode","-box output in Unicode box mode","-quote output in SQL quote mode","-html output as HTML table","-ascii output in ASCII mode (control chars)","-header show column headers","-noheader hide column headers","-separator SEP field separator for list mode (default: |)","-newline SEP row separator (default: \\n)","-nullvalue TEXT text for NULL values (default: empty)","-readonly open database read-only (no writeback)","-bail stop on first error","-echo print SQL before execution","-cmd COMMAND run SQL command before main SQL","-version show SQLite version","-- end of options","--help show this help"],examples:['sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1); SELECT * FROM t"','sqlite3 -json data.db "SELECT * FROM users"','sqlite3 -csv -header data.db "SELECT id, name FROM products"','sqlite3 -box data.db "SELECT * FROM users"']};function Tt(e){let t={mode:"list",header:!1,separator:"|",newline:`
22
+ `,nullValue:"",readonly:!1,bail:!1,echo:!1,cmd:null},r=null,n=null,i=!1,o=!1;for(let s=0;s<e.length;s++){let a=e[s];if(o){r===null?r=a:n===null&&(n=a);continue}if(a==="--")o=!0;else if(a==="-version")i=!0;else if(a==="-list")t.mode="list";else if(a==="-csv")t.mode="csv";else if(a==="-json")t.mode="json";else if(a==="-line")t.mode="line";else if(a==="-column")t.mode="column";else if(a==="-table")t.mode="table";else if(a==="-markdown")t.mode="markdown";else if(a==="-tabs")t.mode="tabs";else if(a==="-box")t.mode="box";else if(a==="-quote")t.mode="quote";else if(a==="-html")t.mode="html";else if(a==="-ascii")t.mode="ascii";else if(a==="-header")t.header=!0;else if(a==="-noheader")t.header=!1;else if(a==="-readonly")t.readonly=!0;else if(a==="-bail")t.bail=!0;else if(a==="-echo")t.echo=!0;else if(a==="-separator"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
23
+ `,exitCode:1};t.separator=e[++s]}else if(a==="-newline"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
24
+ `,exitCode:1};t.newline=e[++s]}else if(a==="-nullvalue"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
25
+ `,exitCode:1};t.nullValue=e[++s]}else if(a==="-cmd"){if(s+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
26
+ `,exitCode:1};t.cmd=e[++s]}else{if(a.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${a.startsWith("--")?a.slice(1):a}
27
+ Use -help for a list of options.
28
+ `,exitCode:1};r===null?r=a:n===null&&(n=a)}}return{options:t,database:r,sql:n,showVersion:i}}function xt(e){let t=e.trim().toUpperCase();return t.startsWith("INSERT")||t.startsWith("UPDATE")||t.startsWith("DELETE")||t.startsWith("CREATE")||t.startsWith("DROP")||t.startsWith("ALTER")||t.startsWith("REPLACE")}function jt(e){let t=[],r="",n=!1,i="";for(let s=0;s<e.length;s++){let a=e[s];if(n)r+=a,a===i&&(e[s+1]===i?r+=e[++s]:n=!1);else if(a==="'"||a==='"')r+=a,n=!0,i=a;else if(a===";"){let l=r.trim();l&&t.push(l),r=""}else r+=a}let o=r.trim();return o&&t.push(o),t}function $t(){let e=new q.default(":memory:");try{return e.prepare("SELECT sqlite_version()").get()["sqlite_version()"]}finally{e.close()}}var zt={name:"sqlite3",async execute(e,t){if(W(e)||e.includes("-help"))return z(Et);let r=Tt(e);if("exitCode"in r)return r;let{options:n,database:i,sql:o,showVersion:s}=r;if(s)return{stdout:`${$t()}
29
+ `,stderr:"",exitCode:0};if(!i)return{stdout:"",stderr:`sqlite3: missing database argument
30
+ `,exitCode:1};let a=o||t.stdin.trim();if(n.cmd&&(a=n.cmd+(a?`; ${a}`:"")),!a)return{stdout:"",stderr:`sqlite3: no SQL provided
31
+ `,exitCode:1};let l,u=i===":memory:",f="";try{if(u)l=new q.default(":memory:");else if(f=t.fs.resolvePath(t.cwd,i),await t.fs.exists(f)){let $=await t.fs.readFileBuffer(f);l=new q.default(Buffer.from($))}else l=new q.default(":memory:")}catch($){return{stdout:"",stderr:`sqlite3: unable to open database "${i}": ${$.message}
32
+ `,exitCode:1}}let d={mode:n.mode,header:n.header,separator:n.separator,newline:n.newline,nullValue:n.nullValue},g="",w=!1;n.echo&&(g+=`${a}
33
+ `);try{let $=jt(a);for(let T of $)try{if(xt(T))l.exec(T),w=!0;else{let I=l.prepare(T),ve=I.columns().map(Ce=>Ce.name),U=I.raw(!0).all();(U.length>0||n.header)&&(g+=Ie(ve,U,d))}}catch(I){let P=I.message;if(n.bail)return{stdout:g,stderr:`Error: ${P}
34
+ `,exitCode:1};g+=`Error: ${P}
35
+ `}if(w&&!n.readonly&&!u&&f)try{let T=l.serialize();await t.fs.writeFile(f,T)}catch(T){return{stdout:g,stderr:`sqlite3: failed to write database: ${T.message}
36
+ `,exitCode:1}}return{stdout:g,stderr:"",exitCode:0}}finally{l.close()}}};export{zt as sqlite3Command};