@batadata/cli 0.2.2 → 0.2.4
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/commands/connect.js +7 -1
- package/dist/commands/db.d.ts +1 -1
- package/dist/commands/db.js +28 -5
- package/package.json +1 -1
package/dist/commands/connect.js
CHANGED
|
@@ -79,7 +79,13 @@ export async function connect(args) {
|
|
|
79
79
|
process.exit(1);
|
|
80
80
|
}
|
|
81
81
|
log();
|
|
82
|
-
logInfo(`Connecting to ${colors.cyan(connRes.data.project_name)}`);
|
|
82
|
+
logInfo(`Connecting to ${colors.cyan(connRes.data.project_name)} ${colors.dim(`(${connRes.data.project_id})`)}`);
|
|
83
|
+
if (!projectName || projectName.startsWith("-")) {
|
|
84
|
+
// No explicit project argument — this resolved through the link/config
|
|
85
|
+
// default. Say so loudly: a silently-resolved default once pointed a
|
|
86
|
+
// benchmark harness at an entirely different project.
|
|
87
|
+
log(` ${colors.yellow("!")} resolved from the linked/default project, not an explicit argument`);
|
|
88
|
+
}
|
|
83
89
|
log(` ${colors.dim(connectionUri)}`);
|
|
84
90
|
log();
|
|
85
91
|
// Check if psql is available
|
package/dist/commands/db.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function parseBranchCreateArgs(args: string[]): {
|
|
|
19
19
|
purpose?: string;
|
|
20
20
|
};
|
|
21
21
|
export declare function connect(): Promise<void>;
|
|
22
|
-
export declare function url(): Promise<void>;
|
|
22
|
+
export declare function url(args?: string[]): Promise<void>;
|
|
23
23
|
export declare function branches(): Promise<void>;
|
|
24
24
|
export declare function branchCreate(args?: string[]): Promise<void>;
|
|
25
25
|
export declare function branchDelete(name?: string): Promise<void>;
|
package/dist/commands/db.js
CHANGED
|
@@ -10,6 +10,8 @@ import { resolveProjectId, resolveBranchId, findLinkFile, writeLinkFile } from "
|
|
|
10
10
|
// Share the exact LSN/timestamp discriminator `bata restore` uses so `db query
|
|
11
11
|
// --at` classifies a restore point identically.
|
|
12
12
|
import { classifyRestorePoint } from "./restore.js";
|
|
13
|
+
// Same --project/positional resolution as projects info/delete (0.1.6 fix).
|
|
14
|
+
import { resolveProjectArg } from "./projects.js";
|
|
13
15
|
async function getConnectionInfo(projectId, token) {
|
|
14
16
|
// reveal=true so the returned string is actually usable (the owner is asking).
|
|
15
17
|
const res = await api.get(`/v1/connection-info/${projectId}`, token, { reveal: "true" });
|
|
@@ -27,6 +29,9 @@ async function getConnectionInfo(projectId, token) {
|
|
|
27
29
|
database: c.params?.database,
|
|
28
30
|
user: c.params?.user,
|
|
29
31
|
password: c.params?.password,
|
|
32
|
+
project_id: res.data?.project_id,
|
|
33
|
+
project_name: res.data?.project_name,
|
|
34
|
+
branch_name: c.branch_name,
|
|
30
35
|
};
|
|
31
36
|
}
|
|
32
37
|
function formatDate(iso) {
|
|
@@ -174,10 +179,14 @@ export async function connect() {
|
|
|
174
179
|
process.exit(code || 0);
|
|
175
180
|
});
|
|
176
181
|
}
|
|
177
|
-
export async function url() {
|
|
182
|
+
export async function url(args = []) {
|
|
178
183
|
const token = requireToken();
|
|
179
184
|
const config = loadConfig();
|
|
180
|
-
|
|
185
|
+
// Precedence: --project <id> / positional arg > .batadata link > config
|
|
186
|
+
// default. `db url` used to IGNORE --project and silently serve the linked/
|
|
187
|
+
// default project — the same flag-ignored class as the 0.1.6 projects
|
|
188
|
+
// delete/info fix, and the root of the wrong-target benchmark incident.
|
|
189
|
+
const projectId = resolveProjectArg(args) ?? resolveProjectId().projectId;
|
|
181
190
|
if (!projectId) {
|
|
182
191
|
emitError("NO_PROJECT", "No default project set.", "Set one with: bata projects info <id>");
|
|
183
192
|
}
|
|
@@ -186,10 +195,24 @@ export async function url() {
|
|
|
186
195
|
emitError("NOT_FOUND", "Could not fetch connection string.", "");
|
|
187
196
|
}
|
|
188
197
|
if (isJsonMode()) {
|
|
189
|
-
json({
|
|
198
|
+
json({
|
|
199
|
+
direct: conn.connection_uri,
|
|
200
|
+
pooled: conn.pooled_uri ?? null,
|
|
201
|
+
// Identity of what was resolved (link > config default when no explicit
|
|
202
|
+
// project) — so a script can ASSERT it got the project it meant. A
|
|
203
|
+
// silently-resolved default once handed a benchmark harness another
|
|
204
|
+
// project's URI; the URI alone gives no way to notice.
|
|
205
|
+
project_id: conn.project_id ?? projectId,
|
|
206
|
+
project_name: conn.project_name ?? null,
|
|
207
|
+
branch_name: conn.branch_name ?? null,
|
|
208
|
+
});
|
|
190
209
|
return;
|
|
191
210
|
}
|
|
192
|
-
//
|
|
211
|
+
// Raw URL on stdout for piping; resolved identity on STDERR so pipes stay
|
|
212
|
+
// clean but a human (or a captured log) always sees WHICH project answered.
|
|
213
|
+
process.stderr.write(`# project: ${conn.project_name ?? "?"} (${conn.project_id ?? projectId})` +
|
|
214
|
+
(conn.branch_name ? ` · branch: ${conn.branch_name}` : "") +
|
|
215
|
+
"\n");
|
|
193
216
|
process.stdout.write(conn.connection_uri + "\n");
|
|
194
217
|
}
|
|
195
218
|
export async function branches() {
|
|
@@ -844,7 +867,7 @@ export async function handleDb(args) {
|
|
|
844
867
|
case "connect":
|
|
845
868
|
return connect();
|
|
846
869
|
case "url":
|
|
847
|
-
return url();
|
|
870
|
+
return url(args.slice(1));
|
|
848
871
|
case "branches":
|
|
849
872
|
return branches();
|
|
850
873
|
case "branch": {
|