@kaynooo/cli-db 0.12.0 → 0.12.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/dist/cli.js +22 -18
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -9,6 +9,7 @@ import { parseArgs } from "util";
|
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
|
+
|
|
12
13
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
14
|
var N = new Map;
|
|
14
15
|
var Nt = /\s+\S*$/;
|
|
@@ -26,6 +27,7 @@ function ko(t, e, r = "...") {
|
|
|
26
27
|
}
|
|
27
28
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
28
29
|
var z = new Map;
|
|
30
|
+
|
|
29
31
|
// ../kit/src/mode.ts
|
|
30
32
|
import process2 from "process";
|
|
31
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -71,7 +73,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
71
73
|
return false;
|
|
72
74
|
return r?.isTTY === true;
|
|
73
75
|
}
|
|
74
|
-
function
|
|
76
|
+
function f(r, e = []) {
|
|
75
77
|
let l = "", n = "";
|
|
76
78
|
for (let t = 0, i = e.length;t < i; t++)
|
|
77
79
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -81,7 +83,7 @@ function f2(r, e = []) {
|
|
|
81
83
|
if (Array.isArray(a)) {
|
|
82
84
|
let s = g.get(i);
|
|
83
85
|
if (s === undefined)
|
|
84
|
-
s =
|
|
86
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
85
87
|
return s;
|
|
86
88
|
}
|
|
87
89
|
if (typeof a === "function")
|
|
@@ -90,20 +92,20 @@ function f2(r, e = []) {
|
|
|
90
92
|
if (u === undefined) {
|
|
91
93
|
if (g.size >= 64)
|
|
92
94
|
g.clear();
|
|
93
|
-
u =
|
|
95
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
94
96
|
}
|
|
95
97
|
return u;
|
|
96
98
|
};
|
|
97
99
|
throw Error(`Unknown style: ${String(i)}`);
|
|
98
100
|
} });
|
|
99
101
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
102
|
+
function Fe(r = {}) {
|
|
103
|
+
return f(r);
|
|
102
104
|
}
|
|
103
|
-
var
|
|
105
|
+
var o = Fe();
|
|
104
106
|
|
|
105
107
|
// ../kit/src/theme.ts
|
|
106
|
-
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
108
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
107
109
|
import { homedir as homedir2 } from "os";
|
|
108
110
|
import { join as join3, resolve as resolve2 } from "path";
|
|
109
111
|
import process5 from "process";
|
|
@@ -124,7 +126,7 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
// ../kit/src/user-config.ts
|
|
127
|
-
import { existsSync as existsSync2 } from "fs";
|
|
129
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
128
130
|
import { homedir } from "os";
|
|
129
131
|
import { join as join2 } from "path";
|
|
130
132
|
import process4 from "process";
|
|
@@ -208,7 +210,7 @@ function readThemeFile(path, warn) {
|
|
|
208
210
|
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
209
211
|
return;
|
|
210
212
|
}
|
|
211
|
-
const parsed = JSON.parse(
|
|
213
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
212
214
|
if (isRecord(parsed))
|
|
213
215
|
return parsed;
|
|
214
216
|
warn(`${path} is not a JSON object, theme ignored`);
|
|
@@ -330,7 +332,7 @@ function takesControlCodes(stream, env = process6.env) {
|
|
|
330
332
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
331
333
|
}
|
|
332
334
|
function paint(stream, env = process6.env) {
|
|
333
|
-
return
|
|
335
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
334
336
|
}
|
|
335
337
|
function marked(mark, text, stream, detail, env = process6.env) {
|
|
336
338
|
const colors = paint(stream, env);
|
|
@@ -344,6 +346,9 @@ function marked(mark, text, stream, detail, env = process6.env) {
|
|
|
344
346
|
function warn(text, detail) {
|
|
345
347
|
console.error(marked("warn", text, process6.stderr, detail));
|
|
346
348
|
}
|
|
349
|
+
function problem(text, detail) {
|
|
350
|
+
console.error(marked("problem", text, process6.stderr, detail));
|
|
351
|
+
}
|
|
347
352
|
var STATUS_WORDS = {
|
|
348
353
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
349
354
|
failed: ["failed", "failure", "error", "errored"],
|
|
@@ -821,7 +826,7 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
821
826
|
var RESET_STYLE = `${ESC}[0m`;
|
|
822
827
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
823
828
|
// ../kit/src/cli.ts
|
|
824
|
-
import { readFileSync as
|
|
829
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
825
830
|
import { dirname as dirname3, join as join5 } from "path";
|
|
826
831
|
import process13 from "process";
|
|
827
832
|
|
|
@@ -1122,7 +1127,7 @@ async function printCandidates(found) {
|
|
|
1122
1127
|
function packageVersion(entry = Bun.main) {
|
|
1123
1128
|
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1124
1129
|
try {
|
|
1125
|
-
const { version } = JSON.parse(
|
|
1130
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1126
1131
|
if (typeof version === "string")
|
|
1127
1132
|
return version;
|
|
1128
1133
|
} catch {}
|
|
@@ -1160,7 +1165,7 @@ function commandPath(scope, argv) {
|
|
|
1160
1165
|
// ../kit/src/compose.ts
|
|
1161
1166
|
async function captureOutput(argv, { cwd, env } = {}) {
|
|
1162
1167
|
const run = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, env: { ...process.env, ...env }, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
|
|
1163
|
-
const [stdout, stderr, code] = await Promise.all([run.stdout.text(), run.stderr.text(), run.exited]);
|
|
1168
|
+
const [stdout, stderr, code] = await Promise.all([new Response(run.stdout).text(), new Response(run.stderr).text(), run.exited]);
|
|
1164
1169
|
return { code, stdout, stderr };
|
|
1165
1170
|
}
|
|
1166
1171
|
async function compose(args, { flags = [], ...options } = {}) {
|
|
@@ -1190,6 +1195,7 @@ var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
|
1190
1195
|
var DEFAULT_ENV = "DATABASE_URL";
|
|
1191
1196
|
var DEFAULT_LIMIT = 20;
|
|
1192
1197
|
var ALL_LIMIT = 100;
|
|
1198
|
+
var WRITE_EXIT = 1;
|
|
1193
1199
|
var EXITS = [[0, "it ran"], [1, "the database refused it, was unreachable, or the statement would write and was not run"], [2, "a usage error or a host that is not allowed"]];
|
|
1194
1200
|
var HOSTS_NOTE = 'db connects to a local host (localhost, 127.0.0.1, ::1) or a compose service only: any other host is refused (exit 2) unless it is listed under "allowedHosts" in ~/.config/kaynooo-cli/db.json.';
|
|
1195
1201
|
var WRITE_NOTE = "A write runs only when the database actually connected to has a name ending in _test (checked on the server, and a statement that names another database, or uses USE, SET, files or server objects, is not run); any other write is printed for you to run.";
|
|
@@ -1966,7 +1972,7 @@ async function closeQuietly(session, url) {
|
|
|
1966
1972
|
try {
|
|
1967
1973
|
await session.close();
|
|
1968
1974
|
} catch (error) {
|
|
1969
|
-
|
|
1975
|
+
warn(messageOf(error, url));
|
|
1970
1976
|
}
|
|
1971
1977
|
}
|
|
1972
1978
|
|
|
@@ -1982,7 +1988,6 @@ ${WRITE_NOTE}
|
|
|
1982
1988
|
|
|
1983
1989
|
${HOSTS_NOTE}`;
|
|
1984
1990
|
var options = { ...connectionOptions, ...outputOptions };
|
|
1985
|
-
var WRITE_EXIT = 1;
|
|
1986
1991
|
var NO_SQL = "no SQL given: pass it as an argument or on stdin";
|
|
1987
1992
|
async function readSql(positionals) {
|
|
1988
1993
|
const sql = positionals.length === 0 ? await readInput("-", { noStdin: NO_SQL }) : positionals.join(" ");
|
|
@@ -1991,9 +1996,8 @@ async function readSql(positionals) {
|
|
|
1991
1996
|
return sql;
|
|
1992
1997
|
}
|
|
1993
1998
|
function handBack(sql, reasons, note = "") {
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
\`\`\`sql
|
|
1999
|
+
problem(`db: not run, this statement would write or cannot be shown to only read (${reasons.join("; ")})${note}. Run it yourself:`);
|
|
2000
|
+
console.log(`\`\`\`sql
|
|
1997
2001
|
${sql.trim()}
|
|
1998
2002
|
\`\`\``);
|
|
1999
2003
|
return WRITE_EXIT;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-db",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.1",
|
|
5
5
|
"description": "db: run read-only SQL against Postgres, MySQL and MariaDB from the terminal without ever showing the connection credentials.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"db": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.37.0"
|
|
32
32
|
}
|
|
33
33
|
}
|