just-bash 2.2.0 → 2.3.1
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/README.md +23 -3
- package/dist/AGENTS.md +3 -1
- package/dist/Bash.d.ts +6 -0
- package/dist/bin/chunks/sqlite3-6WCINK3O.js +38 -0
- package/dist/bin/just-bash.js +71 -70
- package/dist/bin/shell/chunks/sqlite3-6WCINK3O.js +38 -0
- package/dist/bin/shell/shell.js +89 -88
- package/dist/bundle/browser.js +266 -265
- package/dist/bundle/chunks/sqlite3-GFVRV2TN.js +37 -0
- package/dist/bundle/index.js +60 -59
- package/dist/commands/browser-excluded.d.ts +19 -0
- package/dist/commands/registry.d.ts +15 -4
- package/dist/commands/sqlite3/formatters.d.ts +15 -0
- package/dist/commands/sqlite3/sqlite3.d.ts +11 -0
- package/dist/commands/sqlite3/worker.d.ts +31 -0
- package/dist/index.d.ts +2 -2
- package/dist/limits.d.ts +2 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Designed for AI agents that need a secure, sandboxed bash environment.
|
|
|
6
6
|
|
|
7
7
|
Supports optional network access via `curl` with secure-by-default URL filtering.
|
|
8
8
|
|
|
9
|
-
**Note**: This is
|
|
9
|
+
**Note**: This is beta software. Use at your own risk and please provide feedback.
|
|
10
10
|
|
|
11
11
|
## Table of Contents
|
|
12
12
|
|
|
@@ -31,7 +31,7 @@ Supports optional network access via `curl` with secure-by-default URL filtering
|
|
|
31
31
|
## Security model
|
|
32
32
|
|
|
33
33
|
- The shell only has access to the provided file system.
|
|
34
|
-
- Execution is protected against infinite loops or recursion
|
|
34
|
+
- Execution is protected against infinite loops or recursion. However, Bash is not fully robust against DOS from input. If you need to be robust against this, use process isolation at the OS level.
|
|
35
35
|
- Binaries or even WASM are inherently unsupported (Use [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) or a similar product if a full VM is needed).
|
|
36
36
|
- There is no network access by default.
|
|
37
37
|
- Network access can be enabled, but requests are checked against URL prefix allow-lists and HTTP-method allow-lists. See [network access](#network-access) for details
|
|
@@ -241,7 +241,11 @@ pnpm shell --no-network
|
|
|
241
241
|
|
|
242
242
|
### Text Processing
|
|
243
243
|
|
|
244
|
-
`awk`, `base64`, `column`, `comm`, `cut`, `diff`, `expand`, `fold`, `grep` (+ `egrep`, `fgrep`), `head`, `join`, `
|
|
244
|
+
`awk`, `base64`, `column`, `comm`, `cut`, `diff`, `expand`, `fold`, `grep` (+ `egrep`, `fgrep`), `head`, `join`, `md5sum`, `nl`, `od`, `paste`, `printf`, `rev`, `sed`, `sha1sum`, `sha256sum`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
|
|
245
|
+
|
|
246
|
+
### Data Processing
|
|
247
|
+
|
|
248
|
+
`jq` (JSON), `sqlite3` (SQLite, requires opt-in), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
|
|
245
249
|
|
|
246
250
|
### Compression
|
|
247
251
|
|
|
@@ -318,6 +322,22 @@ const env = new Bash({
|
|
|
318
322
|
|
|
319
323
|
**Note:** The `curl` command only exists when network is configured. Without network configuration, `curl` returns "command not found".
|
|
320
324
|
|
|
325
|
+
## SQLite Support
|
|
326
|
+
|
|
327
|
+
SQLite support (the `sqlite3` command) is opt-in because it requires the `better-sqlite3` native module. To enable it:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
const env = new Bash({ sqlite: true });
|
|
331
|
+
|
|
332
|
+
// Query in-memory database
|
|
333
|
+
await env.exec('sqlite3 :memory: "SELECT 1 + 1"');
|
|
334
|
+
|
|
335
|
+
// Query file-based database
|
|
336
|
+
await env.exec('sqlite3 data.db "SELECT * FROM users"');
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Note:** The `sqlite3` command only exists when `sqlite: true` is set. Without it, `sqlite3` returns "command not found". SQLite is not available in browser environments.
|
|
340
|
+
|
|
321
341
|
### Allow-List Security
|
|
322
342
|
|
|
323
343
|
The allow-list enforces:
|
package/dist/AGENTS.md
CHANGED
|
@@ -64,7 +64,9 @@ const result = await bash.exec("cat input.txt | grep pattern");
|
|
|
64
64
|
|
|
65
65
|
## Available Commands
|
|
66
66
|
|
|
67
|
-
**Text processing**: `awk`, `cat`, `column`, `comm`, `cut`, `egrep`, `expand`, `fgrep`, `fold`, `grep`, `head`, `join`, `
|
|
67
|
+
**Text processing**: `awk`, `cat`, `column`, `comm`, `cut`, `egrep`, `expand`, `fgrep`, `fold`, `grep`, `head`, `join`, `nl`, `paste`, `rev`, `sed`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
|
|
68
|
+
|
|
69
|
+
**Data processing**: `jq` (JSON), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
|
|
68
70
|
|
|
69
71
|
**File operations**: `basename`, `chmod`, `cp`, `dirname`, `du`, `file`, `find`, `ln`, `ls`, `mkdir`, `mv`, `od`, `pwd`, `readlink`, `rm`, `split`, `stat`, `touch`, `tree`
|
|
70
72
|
|
package/dist/Bash.d.ts
CHANGED
|
@@ -51,6 +51,12 @@ export interface BashOptions {
|
|
|
51
51
|
* Network access is disabled by default - you must explicitly configure allowed URLs.
|
|
52
52
|
*/
|
|
53
53
|
network?: NetworkConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Enable SQLite support (sqlite3 command).
|
|
56
|
+
* Disabled by default because it requires the better-sqlite3 native module.
|
|
57
|
+
* Not available in browser environments.
|
|
58
|
+
*/
|
|
59
|
+
sqlite?: boolean;
|
|
54
60
|
/**
|
|
55
61
|
* Optional list of command names to register.
|
|
56
62
|
* If not provided, all built-in commands are available.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as N,b as U}from"./chunk-GTNBSMZR.js";import{a as b,c as h,e as _e}from"./chunk-KGOUQS5A.js";var y=h(q=>{"use strict";q.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};q.cppdb=Symbol();q.inspect=Symbol.for("nodejs.util.inspect.custom")});var D=h((It,W)=>{"use strict";var B={value:"SqliteError",writable:!0,enumerable:!1,configurable:!0};function T(e,t){if(new.target!==T)return new T(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,T),this.code=t}Object.setPrototypeOf(T,Error);Object.setPrototypeOf(T.prototype,Error.prototype);Object.defineProperty(T.prototype,"name",B);W.exports=T});var Q=h((_t,z)=>{var I=b("path").sep||"/";z.exports=ve;function ve(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=I+I+n),i=i.replace(/^(.+)\|/,"$1:"),I=="\\"&&(i=i.replace(/\//g,"\\")),/^.+\:/.test(i)||(i=I+i),n+i}});var K=h((O,G)=>{var k=b("fs"),v=b("path"),Ce=Q(),_=v.join,Le=v.dirname,H=k.accessSync&&function(e){try{k.accessSync(e)}catch{return!1}return!0}||k.existsSync||v.existsSync,J={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 Re(e){typeof e=="string"?e={bindings:e}:e||(e={}),Object.keys(J).map(function(l){l in e||(e[l]=J[l])}),e.module_root||(e.module_root=O.getRoot(O.getFileName())),v.extname(e.bindings)!=".node"&&(e.bindings+=".node");for(var t=typeof __webpack_require__=="function"?__non_webpack_require__:b,r=[],n=0,i=e.try.length,o,a,s;n<i;n++){o=_.apply(null,e.try[n].map(function(l){return e[l]||l})),r.push(o);try{return a=e.path?t.resolve(o):t(o),e.path||(a.path=o),a}catch(l){if(l.code!=="MODULE_NOT_FOUND"&&l.code!=="QUALIFIED_PATH_RESOLUTION_FAILED"&&!/not find/i.test(l.message))throw l}}throw s=new Error(`Could not locate the bindings file. Tried:
|
|
3
|
+
`+r.map(function(l){return e.arrow+l}).join(`
|
|
4
|
+
`)),s.tries=r,s}G.exports=O=Re;O.getFileName=function(t){var r=Error.prepareStackTrace,n=Error.stackTraceLimit,i={},o;Error.stackTraceLimit=10,Error.prepareStackTrace=function(s,l){for(var u=0,c=l.length;u<c;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 a="file://";return o.indexOf(a)===0&&(o=Ce(o)),o};O.getRoot=function(t){for(var r=Le(t),n;;){if(r==="."&&(r=process.cwd()),H(_(r,"package.json"))||H(_(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=_(r,"..")}}});var X=h(E=>{"use strict";var{cppdb:w}=y();E.prepare=function(t){return this[w].prepare(t,this,!1)};E.exec=function(t){return this[w].exec(t),this};E.close=function(){return this[w].close(),this};E.loadExtension=function(...t){return this[w].loadExtension(...t),this};E.defaultSafeIntegers=function(...t){return this[w].defaultSafeIntegers(...t),this};E.unsafeMode=function(...t){return this[w].unsafeMode(...t),this};E.getters={name:{get:function(){return this[w].name},enumerable:!0},open:{get:function(){return this[w].open},enumerable:!0},inTransaction:{get:function(){return this[w].inTransaction},enumerable:!0},readonly:{get:function(){return this[w].readonly},enumerable:!0},memory:{get:function(){return this[w].memory},enumerable:!0}}});var ee=h((Lt,Z)=>{"use strict";var{cppdb:Ae}=y(),Y=new WeakMap;Z.exports=function(t){if(typeof t!="function")throw new TypeError("Expected first argument to be a function");let r=this[Ae],n=Ve(r,this),{apply:i}=Function.prototype,o={default:{value:C(i,t,r,n.default)},deferred:{value:C(i,t,r,n.deferred)},immediate:{value:C(i,t,r,n.immediate)},exclusive:{value:C(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 Ve=(e,t)=>{let r=Y.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)};Y.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},C=(e,t,r,{begin:n,commit:i,rollback:o,savepoint:a,release:s,rollbackTo:l})=>function(){let c,p,j;r.inTransaction?(c=a,p=s,j=l):(c=n,p=i,j=o),c.run();try{let m=e.call(t,this,arguments);if(m&&typeof m.then=="function")throw new TypeError("Transaction function cannot return a promise");return p.run(),m}catch(m){throw r.inTransaction&&(j.run(),j!==o&&p.run()),m}}});var re=h((Rt,te)=>{"use strict";var{getBooleanOption:Be,cppdb:De}=y();te.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=Be(r,"simple"),i=this[De].prepare(`PRAGMA ${t}`,this,!0);return n?i.pluck().get():i.all()}});var ie=h((At,oe)=>{"use strict";var ke=b("fs"),Pe=b("path"),{promisify:Me}=b("util"),{cppdb:Fe}=y(),ne=Me(ke.access);oe.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 ne(Pe.dirname(t)).catch(()=>{throw new TypeError("Cannot save backup because the directory does not exist")});let o=await ne(t).then(()=>!1,()=>!0);return Ne(this[Fe].backup(this,n,t,o),i||null)};var Ne=(e,t)=>{let r=0,n=!0;return new Promise((i,o)=>{setImmediate(function a(){try{let s=e.transfer(r);if(!s.remainingPages){e.close(),i(s);return}if(n&&(n=!1,r=100),t){let l=t(s);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(a)}catch(s){e.close(),o(s)}})})}});var ae=h((Vt,se)=>{"use strict";var{cppdb:Ue}=y();se.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[Ue].serialize(r)}});var ue=h((Bt,le)=>{"use strict";var{getBooleanOption:L,cppdb:We}=y();le.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?+L(r,"safeIntegers"):2,o=L(r,"deterministic"),a=L(r,"directOnly"),s=L(r,"varargs"),l=-1;if(!s){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[We].function(n,t,l,i,o,a),this}});var pe=h((Dt,fe)=>{"use strict";var{getBooleanOption:R,cppdb:ze}=y();fe.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=P(r,"step",!0),o=P(r,"inverse",!1),a=P(r,"result",!1),s="safeIntegers"in r?+R(r,"safeIntegers"):2,l=R(r,"deterministic"),u=R(r,"directOnly"),c=R(r,"varargs"),p=-1;if(!c&&(p=Math.max(ce(i),o?ce(o):0),p>0&&(p-=1),p>100))throw new RangeError("User-defined functions cannot have more than 100 arguments");return this[ze].aggregate(n,i,o,a,t,p,s,l,u),this};var P=(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},ce=({length:e})=>{if(Number.isInteger(e)&&e>=0)return e;throw new TypeError("Expected function.length to be a positive integer")}});var ge=h((kt,me)=>{"use strict";var{cppdb:Qe}=y();me.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=et(he(r,"used",t));else{if(typeof r!="function")throw new TypeError("Expected second argument to be a function or a table definition object");r=He(r)}return this[Qe].table(r,t,n),this};function He(e){return function(r,n,i,...o){let a={module:r,database:n,table:i},s=Ye.call(e,a,o);if(typeof s!="object"||s===null)throw new TypeError(`Virtual table module "${r}" did not return a table definition object`);return he(s,"returned",r)}}function he(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)!==Ze)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=Xe(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 a=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)`);a=+u}let s=!1;if(S.call(e,"directOnly")&&(s=e.directOnly,typeof s!="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(de).map(u=>`${u} HIDDEN`),...i.map(de)].join(", ")});`,Je(n,new Map(i.map((u,c)=>[u,o.length+c])),r),o,a,s]}function Je(e,t,r){return function*(...i){let o=i.map(a=>Buffer.isBuffer(a)?Buffer.from(a):a);for(let a=0;a<t.size;++a)o.push(null);for(let a of e(...i))if(Array.isArray(a))Ge(a,o,t.size,r),yield o;else if(typeof a=="object"&&a!==null)Ke(a,o,t,r),yield o;else throw new TypeError(`Virtual table module "${r}" yielded something that isn't a valid row object`)}}function Ge(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 Ke(e,t,r,n){let i=0;for(let o of Object.keys(e)){let a=r.get(o);if(a===void 0)throw new TypeError(`Virtual table module "${n}" yielded a row with an undeclared column "${o}"`);t[a]=e[o],i+=1}if(i!==r.size)throw new TypeError(`Virtual table module "${n}" yielded a row with missing columns`)}function Xe({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:Ye}=Function.prototype,Ze=Object.getPrototypeOf(function*(){}),de=e=>`"${e.replace(/"/g,'""')}"`,et=e=>()=>e});var we=h((Pt,be)=>{"use strict";var tt=function(){};be.exports=function(t,r){return Object.assign(new tt,this)}});var xe=h((Mt,Te)=>{"use strict";var rt=b("fs"),ye=b("path"),A=y(),nt=D(),Ee;function f(e,t){if(new.target==null)return new f(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=A.getBooleanOption(t,"readonly"),a=A.getBooleanOption(t,"fileMustExist"),s="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(s)||s<0)throw new TypeError('Expected the "timeout" option to be a positive integer');if(s>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 c;if(u==null?c=Ee||(Ee=K()("better_sqlite3.node")):typeof u=="string"?c=(typeof __non_webpack_require__=="function"?__non_webpack_require__:b)(ye.resolve(u).replace(/(\.node)?$/,".node")):c=u,c.isInitialized||(c.setErrorConstructor(nt),c.isInitialized=!0),!i&&!rt.existsSync(ye.dirname(n)))throw new TypeError("Cannot open database because the directory does not exist");Object.defineProperties(this,{[A.cppdb]:{value:new c.Database(n,e,i,o,a,s,l||null,r||null)},...x.getters})}var x=X();f.prototype.prepare=x.prepare;f.prototype.transaction=ee();f.prototype.pragma=re();f.prototype.backup=ie();f.prototype.serialize=ae();f.prototype.function=ue();f.prototype.aggregate=pe();f.prototype.table=ge();f.prototype.loadExtension=x.loadExtension;f.prototype.exec=x.exec;f.prototype.close=x.close;f.prototype.defaultSafeIntegers=x.defaultSafeIntegers;f.prototype.unsafeMode=x.unsafeMode;f.prototype[A.inspect]=we();Te.exports=f});var je=h((Nt,M)=>{"use strict";M.exports=xe();M.exports.SqliteError=D()});var V=_e(je(),1);import{fileURLToPath as bt}from"node:url";import{Worker as wt}from"node:worker_threads";function Se(e,t,r){switch(r.mode){case"list":return ot(e,t,r);case"csv":return it(e,t,r);case"json":return at(e,t);case"line":return lt(e,t,r);case"column":return ut(e,t,r);case"table":return ct(e,t,r);case"markdown":return ft(e,t,r);case"tabs":return pt(e,t,r);case"box":return dt(e,t,r);case"quote":return ht(e,t,r);case"html":return mt(e,t,r);case"ascii":return gt(e,t,r)}}function g(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 ot(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=>g(o,r.nullValue)).join(r.separator));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function it(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.map($e).join(","));for(let i of t)n.push(i.map(o=>$e(g(o,r.nullValue))).join(","));return n.length>0?`${n.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:""}function $e(e){return e.includes(",")||e.includes('"')||e.includes("'")||e.includes(`
|
|
7
|
+
`)?`"${e.replace(/"/g,'""')}"`:e}function qe(e){return e.toPrecision(17).replace(/\.?0+$/,"")}function st(e){return e===null?"null":typeof e=="number"?Number.isInteger(e)?String(e):qe(e):JSON.stringify(e)}function at(e,t){return t.length===0?"":`[${t.map(n=>`{${e.map((o,a)=>`${JSON.stringify(o)}:${st(n[a])}`).join(",")}}`).join(`,
|
|
8
|
+
`)}]
|
|
9
|
+
`}function lt(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 a=0;a<e.length;a++){let s=e[a].padStart(n);i.push(`${s} = ${g(o[a],r.nullValue)}`)}return`${i.join(`
|
|
10
|
+
`)}
|
|
11
|
+
`}function ut(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let a=0;a<o.length;a++){let s=g(o[a],r.nullValue).length;s>n[a]&&(n[a]=s)}let i=[];r.header&&(i.push(e.map((o,a)=>o.padEnd(n[a])).join(" ")),i.push(n.map(o=>"-".repeat(o)).join(" ")));for(let o of t)i.push(o.map((a,s)=>g(a,r.nullValue).padEnd(n[s])).join(" "));return i.length>0?`${i.join(`
|
|
12
|
+
`)}
|
|
13
|
+
`:""}function ct(e,t,r){if(e.length===0)return"";let n=e.map(a=>a.length);for(let a of t)for(let s=0;s<a.length;s++){let l=g(a[s],r.nullValue).length;l>n[s]&&(n[s]=l)}let i=[],o=`+${n.map(a=>"-".repeat(a+2)).join("+")}+`;i.push(o),r.header&&(i.push(`| ${e.map((a,s)=>a.padEnd(n[s])).join(" | ")} |`),i.push(o));for(let a of t)i.push(`| ${a.map((s,l)=>g(s,r.nullValue).padEnd(n[l])).join(" | ")} |`);return i.push(o),`${i.join(`
|
|
14
|
+
`)}
|
|
15
|
+
`}function ft(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=>g(o,r.nullValue)).join(" | ")} |`);return n.length>0?`${n.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`:""}function pt(e,t,r){let n=[];r.header&&e.length>0&&n.push(e.join(" "));for(let i of t)n.push(i.map(o=>g(o,r.nullValue)).join(" "));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function dt(e,t,r){if(e.length===0)return"";let n=e.map(o=>o.length);for(let o of t)for(let a=0;a<o.length;a++){let s=g(o[a],r.nullValue).length;s>n[a]&&(n[a]=s)}let i=[];i.push(`\u250C${n.map(o=>"\u2500".repeat(o+2)).join("\u252C")}\u2510`),i.push(`\u2502 ${e.map((o,a)=>o.padEnd(n[a])).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((a,s)=>g(a,r.nullValue).padEnd(n[s])).join(" \u2502 ")} \u2502`);return i.push(`\u2514${n.map(o=>"\u2500".repeat(o+2)).join("\u2534")}\u2518`),`${i.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`}function ht(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):qe(o):`'${String(o)}'`).join(","));return n.length>0?`${n.join(r.newline)}${r.newline}`:""}function mt(e,t,r){let n=[];r.header&&e.length>0&&(n.push(`<TR>${e.map(i=>`<TH>${Oe(i)}</TH>`).join("")}`),n.push("</TR>"));for(let i of t)n.push(`<TR>${i.map(o=>`<TD>${Oe(g(o,r.nullValue))}</TD>`).join("")}`),n.push("</TR>");return n.length>0?`${n.join(`
|
|
20
|
+
`)}
|
|
21
|
+
`:""}function Oe(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function gt(e,t,r){let o=[];r.header&&e.length>0&&o.push(e.join(""));for(let a of t)o.push(a.map(s=>g(s,r.nullValue)).join(""));return o.length>0?o.join("")+"":""}var yt=5e3,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 a=0;a<e.length;a++){let s=e[a];if(o){r===null?r=s:n===null&&(n=s);continue}if(s==="--")o=!0;else if(s==="-version")i=!0;else if(s==="-list")t.mode="list";else if(s==="-csv")t.mode="csv";else if(s==="-json")t.mode="json";else if(s==="-line")t.mode="line";else if(s==="-column")t.mode="column";else if(s==="-table")t.mode="table";else if(s==="-markdown")t.mode="markdown";else if(s==="-tabs")t.mode="tabs";else if(s==="-box")t.mode="box";else if(s==="-quote")t.mode="quote";else if(s==="-html")t.mode="html";else if(s==="-ascii")t.mode="ascii";else if(s==="-header")t.header=!0;else if(s==="-noheader")t.header=!1;else if(s==="-readonly")t.readonly=!0;else if(s==="-bail")t.bail=!0;else if(s==="-echo")t.echo=!0;else if(s==="-separator"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -separator
|
|
23
|
+
`,exitCode:1};t.separator=e[++a]}else if(s==="-newline"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -newline
|
|
24
|
+
`,exitCode:1};t.newline=e[++a]}else if(s==="-nullvalue"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -nullvalue
|
|
25
|
+
`,exitCode:1};t.nullValue=e[++a]}else if(s==="-cmd"){if(a+1>=e.length)return{stdout:"",stderr:`sqlite3: Error: missing argument to -cmd
|
|
26
|
+
`,exitCode:1};t.cmd=e[++a]}else{if(s.startsWith("-"))return{stdout:"",stderr:`sqlite3: Error: unknown option: ${s.startsWith("--")?s.slice(1):s}
|
|
27
|
+
Use -help for a list of options.
|
|
28
|
+
`,exitCode:1};r===null?r=s:n===null&&(n=s)}}return{options:t,database:r,sql:n,showVersion:i}}function xt(){let e=new V.default(":memory:");try{return e.prepare("SELECT sqlite_version()").get()["sqlite_version()"]}finally{e.close()}}function jt(e){let t;try{e.dbBuffer?t=new V.default(Buffer.from(e.dbBuffer)):t=new V.default(":memory:")}catch(i){return{success:!1,error:i.message}}let r=[],n=!1;try{let i=Ot(e.sql);for(let a of i)try{if($t(a))t.exec(a),n=!0,r.push({type:"data",columns:[],rows:[]});else{let s=t.prepare(a),u=s.columns().map(p=>p.name),c=s.raw(!0).all();r.push({type:"data",columns:u,rows:c})}}catch(s){let l=s.message;if(r.push({type:"error",error:l}),e.options.bail)break}let o=null;return n&&(o=t.serialize()),t.close(),{success:!0,results:r,hasModifications:n,dbBuffer:o}}catch(i){return t.close(),{success:!1,error:i.message}}}function $t(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 Ot(e){let t=[],r="",n=!1,i="";for(let a=0;a<e.length;a++){let s=e[a];if(n)r+=s,s===i&&(e[a+1]===i?r+=e[++a]:n=!1);else if(s==="'"||s==='"')r+=s,n=!0,i=s;else if(s===";"){let l=r.trim();l&&t.push(l),r=""}else r+=s}let o=r.trim();return o&&t.push(o),t}async function St(e,t){try{let r=bt(new URL("./worker.js",import.meta.url));return await new Promise((n,i)=>{let o=new wt(r,{workerData:e}),a=setTimeout(()=>{o.terminate(),n({success:!1,error:`Query timeout: execution exceeded ${t}ms limit`})},t);o.on("message",s=>{clearTimeout(a),n(s)}),o.on("error",s=>{clearTimeout(a),i(s)}),o.on("exit",s=>{clearTimeout(a),s!==0&&n({success:!1,error:`Worker exited with code ${s}`})})})}catch{return jt(e)}}var Jt={name:"sqlite3",async execute(e,t){if(U(e)||e.includes("-help"))return N(Et);let r=Tt(e);if("exitCode"in r)return r;let{options:n,database:i,sql:o,showVersion:a}=r;if(a)return{stdout:`${xt()}
|
|
29
|
+
`,stderr:"",exitCode:0};if(!i)return{stdout:"",stderr:`sqlite3: missing database argument
|
|
30
|
+
`,exitCode:1};let s=o||t.stdin.trim();if(n.cmd&&(s=n.cmd+(s?`; ${s}`:"")),!s)return{stdout:"",stderr:`sqlite3: no SQL provided
|
|
31
|
+
`,exitCode:1};let l=i===":memory:",u="",c=null;try{l||(u=t.fs.resolvePath(t.cwd,i),await t.fs.exists(u)&&(c=await t.fs.readFileBuffer(u)))}catch(d){return{stdout:"",stderr:`sqlite3: unable to open database "${i}": ${d.message}
|
|
32
|
+
`,exitCode:1}}let p=t.limits?.maxSqliteTimeoutMs??yt,j={dbBuffer:c,sql:s,options:{bail:n.bail,echo:n.echo}},m;try{m=await St(j,p)}catch(d){return{stdout:"",stderr:`sqlite3: worker error: ${d.message}
|
|
33
|
+
`,exitCode:1}}if(!m.success)return{stdout:"",stderr:`sqlite3: ${m.error}
|
|
34
|
+
`,exitCode:1};let Ie={mode:n.mode,header:n.header,separator:n.separator,newline:n.newline,nullValue:n.nullValue},$="";n.echo&&($+=`${s}
|
|
35
|
+
`);let F=!1;for(let d of m.results)if(d.type==="error"){if(n.bail)return{stdout:$,stderr:`Error: ${d.error}
|
|
36
|
+
`,exitCode:1};$+=`Error: ${d.error}
|
|
37
|
+
`,F=!0}else d.columns&&d.rows&&(d.rows.length>0||n.header)&&($+=Se(d.columns,d.rows,Ie));if(m.hasModifications&&!n.readonly&&!l&&u&&m.dbBuffer)try{await t.fs.writeFile(u,m.dbBuffer)}catch(d){return{stdout:$,stderr:`sqlite3: failed to write database: ${d.message}
|
|
38
|
+
`,exitCode:1}}return{stdout:$,stderr:"",exitCode:F&&n.bail?1:0}}};export{Jt as sqlite3Command};
|