postgresai 0.12.0-beta.7 → 0.14.0-dev.7
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 +33 -0
- package/bin/postgres-ai.ts +119 -0
- package/dist/bin/postgres-ai.js +104 -0
- package/dist/bin/postgres-ai.js.map +1 -1
- package/dist/lib/init.d.ts +61 -0
- package/dist/lib/init.d.ts.map +1 -0
- package/dist/lib/init.js +359 -0
- package/dist/lib/init.js.map +1 -0
- package/dist/package.json +3 -2
- package/lib/init.ts +404 -0
- package/package.json +3 -2
- package/test/init.integration.test.cjs +269 -0
- package/test/init.test.cjs +69 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const test = require("node:test");
|
|
2
|
+
const assert = require("node:assert/strict");
|
|
3
|
+
|
|
4
|
+
// These tests intentionally import the compiled JS output.
|
|
5
|
+
// Run via: npm --prefix cli test
|
|
6
|
+
const init = require("../dist/lib/init.js");
|
|
7
|
+
|
|
8
|
+
test("maskConnectionString hides password when present", () => {
|
|
9
|
+
const masked = init.maskConnectionString("postgresql://user:secret@localhost:5432/mydb");
|
|
10
|
+
assert.match(masked, /postgresql:\/\/user:\*{5}@localhost:5432\/mydb/);
|
|
11
|
+
assert.doesNotMatch(masked, /secret/);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("parseLibpqConninfo parses basic host/dbname/user/port/password", () => {
|
|
15
|
+
const cfg = init.parseLibpqConninfo("dbname=mydb host=localhost user=alice port=5432 password=secret");
|
|
16
|
+
assert.equal(cfg.database, "mydb");
|
|
17
|
+
assert.equal(cfg.host, "localhost");
|
|
18
|
+
assert.equal(cfg.user, "alice");
|
|
19
|
+
assert.equal(cfg.port, 5432);
|
|
20
|
+
assert.equal(cfg.password, "secret");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("parseLibpqConninfo supports quoted values", () => {
|
|
24
|
+
const cfg = init.parseLibpqConninfo("dbname='my db' host='local host'");
|
|
25
|
+
assert.equal(cfg.database, "my db");
|
|
26
|
+
assert.equal(cfg.host, "local host");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("buildInitPlan includes create user when role does not exist", async () => {
|
|
30
|
+
const plan = await init.buildInitPlan({
|
|
31
|
+
database: "mydb",
|
|
32
|
+
monitoringUser: "postgres_ai_mon",
|
|
33
|
+
monitoringPassword: "pw",
|
|
34
|
+
includeOptionalPermissions: false,
|
|
35
|
+
roleExists: false,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
assert.equal(plan.database, "mydb");
|
|
39
|
+
assert.ok(plan.steps.some((s) => s.name === "create monitoring user"));
|
|
40
|
+
assert.ok(!plan.steps.some((s) => s.optional));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("buildInitPlan includes alter user when role exists", async () => {
|
|
44
|
+
const plan = await init.buildInitPlan({
|
|
45
|
+
database: "mydb",
|
|
46
|
+
monitoringUser: "postgres_ai_mon",
|
|
47
|
+
monitoringPassword: "pw",
|
|
48
|
+
includeOptionalPermissions: true,
|
|
49
|
+
roleExists: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
assert.ok(plan.steps.some((s) => s.name === "update monitoring user password"));
|
|
53
|
+
assert.ok(plan.steps.some((s) => s.optional));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("resolveAdminConnection accepts positional URI", () => {
|
|
57
|
+
const r = init.resolveAdminConnection({ conn: "postgresql://u:p@h:5432/d" });
|
|
58
|
+
assert.ok(r.clientConfig.connectionString);
|
|
59
|
+
assert.doesNotMatch(r.display, /:p@/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("resolveAdminConnection accepts positional conninfo", () => {
|
|
63
|
+
const r = init.resolveAdminConnection({ conn: "dbname=mydb host=localhost user=alice" });
|
|
64
|
+
assert.equal(r.clientConfig.database, "mydb");
|
|
65
|
+
assert.equal(r.clientConfig.host, "localhost");
|
|
66
|
+
assert.equal(r.clientConfig.user, "alice");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
|