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.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * List of commands that are not available in browser environments.
3
+ *
4
+ * These commands are excluded from the browser bundle because they:
5
+ * - Use Node.js-specific APIs that don't have browser equivalents
6
+ * - Have dependencies that don't work in browsers
7
+ *
8
+ * Note: sqlite3 is opt-in (requires `sqlite: true` option) so it's not
9
+ * listed here - it will show "command not found" like any other unknown command.
10
+ *
11
+ * When a user tries to use one of these commands in a browser environment,
12
+ * they should get a helpful error message explaining why the command
13
+ * is not available.
14
+ */
15
+ export declare const BROWSER_EXCLUDED_COMMANDS: readonly string[];
16
+ /**
17
+ * Check if a command is browser-excluded
18
+ */
19
+ export declare function isBrowserExcludedCommand(commandName: string): boolean;
@@ -1,12 +1,14 @@
1
1
  import type { Command } from "../types.js";
2
- /** All available built-in command names (excludes network commands like curl) */
2
+ /** All available built-in command names (excludes network and sqlite commands) */
3
3
  export type CommandName = "echo" | "cat" | "printf" | "ls" | "mkdir" | "touch" | "rm" | "cp" | "mv" | "ln" | "chmod" | "pwd" | "readlink" | "head" | "tail" | "wc" | "stat" | "grep" | "fgrep" | "egrep" | "sed" | "awk" | "sort" | "uniq" | "comm" | "cut" | "paste" | "tr" | "rev" | "nl" | "fold" | "expand" | "unexpand" | "strings" | "split" | "column" | "join" | "tee" | "find" | "basename" | "dirname" | "tree" | "du" | "env" | "printenv" | "alias" | "unalias" | "history" | "xargs" | "true" | "false" | "clear" | "bash" | "sh" | "jq" | "base64" | "diff" | "date" | "sleep" | "timeout" | "seq" | "expr" | "md5sum" | "sha1sum" | "sha256sum" | "file" | "html-to-markdown" | "help" | "which" | "tac" | "hostname" | "od" | "gzip" | "gunzip" | "zcat" | "yq" | "xan";
4
4
  /** Network command names (only available when network is configured) */
5
5
  export type NetworkCommandName = "curl";
6
- /** All command names including network commands */
7
- export type AllCommandName = CommandName | NetworkCommandName;
6
+ /** SQLite command names (only available when sqlite is enabled) */
7
+ export type SqliteCommandName = "sqlite3";
8
+ /** All command names including network and sqlite commands */
9
+ export type AllCommandName = CommandName | NetworkCommandName | SqliteCommandName;
8
10
  /**
9
- * Gets all available command names (excludes network commands)
11
+ * Gets all available command names (excludes network and sqlite commands)
10
12
  */
11
13
  export declare function getCommandNames(): string[];
12
14
  /**
@@ -23,6 +25,15 @@ export declare function createLazyCommands(filter?: CommandName[]): Command[];
23
25
  * These are only registered when network is explicitly configured.
24
26
  */
25
27
  export declare function createNetworkCommands(): Command[];
28
+ /**
29
+ * Gets all sqlite command names
30
+ */
31
+ export declare function getSqliteCommandNames(): string[];
32
+ /**
33
+ * Creates sqlite commands for registration (sqlite3, etc.)
34
+ * These are only registered when sqlite is explicitly enabled.
35
+ */
36
+ export declare function createSqliteCommands(): Command[];
26
37
  /**
27
38
  * Clears the command cache (for testing)
28
39
  */
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Output formatters for sqlite3 command
3
+ */
4
+ export type OutputMode = "list" | "csv" | "json" | "line" | "column" | "table" | "markdown" | "tabs" | "box" | "quote" | "html" | "ascii";
5
+ export interface FormatOptions {
6
+ mode: OutputMode;
7
+ header: boolean;
8
+ separator: string;
9
+ nullValue: string;
10
+ newline: string;
11
+ }
12
+ /**
13
+ * Format query results according to the specified options
14
+ */
15
+ export declare function formatOutput(columns: string[], rows: unknown[][], options: FormatOptions): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * sqlite3 - SQLite database CLI
3
+ *
4
+ * Wraps better-sqlite3 to provide SQLite database access through the virtual filesystem.
5
+ * Databases are loaded from buffers and written back after modifications.
6
+ *
7
+ * Queries run in a worker thread with a timeout to prevent runaway queries
8
+ * (e.g., infinite recursive CTEs) from blocking execution.
9
+ */
10
+ import type { Command } from "../../types.js";
11
+ export declare const sqlite3Command: Command;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Worker thread for sqlite3 query execution.
3
+ *
4
+ * This isolates potentially long-running queries so they can be
5
+ * terminated if they exceed the timeout.
6
+ */
7
+ export interface WorkerInput {
8
+ dbBuffer: Uint8Array | null;
9
+ sql: string;
10
+ options: {
11
+ bail: boolean;
12
+ echo: boolean;
13
+ };
14
+ }
15
+ export interface WorkerSuccess {
16
+ success: true;
17
+ results: StatementResult[];
18
+ hasModifications: boolean;
19
+ dbBuffer: Uint8Array | null;
20
+ }
21
+ export interface StatementResult {
22
+ type: "data" | "error";
23
+ columns?: string[];
24
+ rows?: unknown[][];
25
+ error?: string;
26
+ }
27
+ export interface WorkerError {
28
+ success: false;
29
+ error: string;
30
+ }
31
+ export type WorkerOutput = WorkerSuccess | WorkerError;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { BashLogger, BashOptions, ExecOptions } from "./Bash.js";
2
2
  export { Bash } from "./Bash.js";
3
- export type { AllCommandName, CommandName, NetworkCommandName, } from "./commands/registry.js";
4
- export { getCommandNames, getNetworkCommandNames, } from "./commands/registry.js";
3
+ export type { AllCommandName, CommandName, NetworkCommandName, SqliteCommandName, } from "./commands/registry.js";
4
+ export { getCommandNames, getNetworkCommandNames, getSqliteCommandNames, } from "./commands/registry.js";
5
5
  export type { CustomCommand, LazyCommand } from "./custom-commands.js";
6
6
  export { defineCommand } from "./custom-commands.js";
7
7
  export { InMemoryFs } from "./fs/in-memory-fs/index.js";
package/dist/limits.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface ExecutionLimits {
21
21
  maxSedIterations?: number;
22
22
  /** Maximum iterations for jq loops (until, while, repeat) (default: 10000) */
23
23
  maxJqIterations?: number;
24
+ /** Maximum sqlite3 query execution time in milliseconds (default: 5000) */
25
+ maxSqliteTimeoutMs?: number;
24
26
  }
25
27
  /**
26
28
  * Resolve execution limits by merging user-provided limits with defaults.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,6 +52,7 @@
52
52
  "license": "Apache-2.0",
53
53
  "devDependencies": {
54
54
  "@biomejs/biome": "^2.3.10",
55
+ "@types/better-sqlite3": "^7.6.11",
55
56
  "@types/ini": "^4.1.1",
56
57
  "@types/node": "^25.0.3",
57
58
  "@types/papaparse": "^5.5.2",
@@ -63,6 +64,7 @@
63
64
  "vitest": "^4.0.16"
64
65
  },
65
66
  "dependencies": {
67
+ "better-sqlite3": "^11.9.1",
66
68
  "diff": "^8.0.2",
67
69
  "fast-xml-parser": "^5.3.3",
68
70
  "file-type": "^21.2.0",