@rebasepro/cli 0.25.0-canary.ge06257e → 0.25.0
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/bin/rebase.js +9 -5
- package/dist/{agent-setup-C83DXnlx.js → agent-setup-B5AKHOgt.js} +2 -2
- package/dist/{agent-setup-C83DXnlx.js.map → agent-setup-B5AKHOgt.js.map} +1 -1
- package/dist/{api-keys-Bc4FJKYp.js → api-keys-Tm7zvAPe.js} +27 -20
- package/dist/api-keys-Tm7zvAPe.js.map +1 -0
- package/dist/{apps-wG-ZTryA.js → apps-BsU_ILbP.js} +4 -4
- package/dist/{apps-wG-ZTryA.js.map → apps-BsU_ILbP.js.map} +1 -1
- package/dist/{args-CcBphFdj.js → args-BX0YD14a.js} +45 -16
- package/dist/args-BX0YD14a.js.map +1 -0
- package/dist/{atlas-dev-database-DeK3Sa4h.js → atlas-dev-database-OWtqnG7W.js} +2 -2
- package/dist/{atlas-dev-database-DeK3Sa4h.js.map → atlas-dev-database-OWtqnG7W.js.map} +1 -1
- package/dist/{auth-BL7bNQVu.js → auth-Vl2hFKXP.js} +77 -10
- package/dist/auth-Vl2hFKXP.js.map +1 -0
- package/dist/{branch-pointer-DTQNLFtb.js → branch-pointer-9DnwkFJJ.js} +1 -1
- package/dist/{build-h_7Re-67.js → build-BBgT8EJZ.js} +5 -5
- package/dist/{build-h_7Re-67.js.map → build-BBgT8EJZ.js.map} +1 -1
- package/dist/{bundle-CqURVN-K.js → bundle-DtCCCr4w.js} +4 -19
- package/dist/bundle-DtCCCr4w.js.map +1 -0
- package/dist/{cloud-DVV_5GPG.js → cloud-BpH0_bmV.js} +7 -7
- package/dist/{cloud-DVV_5GPG.js.map → cloud-BpH0_bmV.js.map} +1 -1
- package/dist/commands/api-keys.d.ts +4 -1
- package/dist/commands/auth.d.ts +3 -2
- package/dist/connection-banner-DbLJzWf4.js +128 -0
- package/dist/connection-banner-DbLJzWf4.js.map +1 -0
- package/dist/{console-Dw3HLdUs.js → console-CEGm0XNc.js} +4 -4
- package/dist/{console-Dw3HLdUs.js.map → console-CEGm0XNc.js.map} +1 -1
- package/dist/{context-BM-oOMNX.js → context-CyflUrKg.js} +2 -2
- package/dist/{context-BM-oOMNX.js.map → context-CyflUrKg.js.map} +1 -1
- package/dist/{daemon-entry-C6pxdily.js → daemon-entry-CbLRrgzy.js} +199 -3
- package/dist/daemon-entry-CbLRrgzy.js.map +1 -0
- package/dist/{db-Dkn9XhT-.js → db-CRNpA5mH.js} +171 -60
- package/dist/db-CRNpA5mH.js.map +1 -0
- package/dist/{derive-Dl0z2OWi.js → derive-CsoFGAnK.js} +28 -13
- package/dist/{derive-Dl0z2OWi.js.map → derive-CsoFGAnK.js.map} +1 -1
- package/dist/{dev-DAcZR4Pp.js → dev-C0pbMmhS.js} +6 -6
- package/dist/{dev-DAcZR4Pp.js.map → dev-C0pbMmhS.js.map} +1 -1
- package/dist/dev-db/connection-banner.d.ts +47 -0
- package/dist/dev-db/notification-proxy.d.ts +82 -1
- package/dist/{dev-preflight-CorMg7Ub.js → dev-preflight-unHpiYO1.js} +26 -3
- package/dist/dev-preflight-unHpiYO1.js.map +1 -0
- package/dist/{doctor-Ds_lzc9p.js → doctor-CATRdWm6.js} +4 -4
- package/dist/{doctor-Ds_lzc9p.js.map → doctor-CATRdWm6.js.map} +1 -1
- package/dist/{eject-CJHkfnat.js → eject-DuasTr-F.js} +2 -2
- package/dist/{eject-CJHkfnat.js.map → eject-DuasTr-F.js.map} +1 -1
- package/dist/{fold-static-BC9CYicw.js → fold-static-hDHtDfTq.js} +2 -2
- package/dist/{fold-static-BC9CYicw.js.map → fold-static-hDHtDfTq.js.map} +1 -1
- package/dist/{generate_sdk-kfkZmG-d.js → generate_sdk-Cvg5jjJF.js} +3 -3
- package/dist/{generate_sdk-kfkZmG-d.js.map → generate_sdk-Cvg5jjJF.js.map} +1 -1
- package/dist/index.es.js +34 -34
- package/dist/{init-CjoJoThg.js → init-BWAwHPtz.js} +8 -7
- package/dist/init-BWAwHPtz.js.map +1 -0
- package/dist/last-dev-database-c_dKz1S3.js +2 -0
- package/dist/{normalize-imports-BHxL2d05.js → normalize-imports-BoBVh5tU.js} +3 -3
- package/dist/{normalize-imports-BHxL2d05.js.map → normalize-imports-BoBVh5tU.js.map} +1 -1
- package/dist/precompress.d.ts +0 -7
- package/dist/{prepare-C1iaiTC4.js → prepare-DdnU70z8.js} +4 -4
- package/dist/prepare-DdnU70z8.js.map +1 -0
- package/dist/{pull-COpNJFzY.js → pull-C3PXduzl.js} +13 -40
- package/dist/pull-C3PXduzl.js.map +1 -0
- package/dist/resolve-CNQjsatH.js +2 -0
- package/dist/resources/derive.d.ts +9 -0
- package/dist/{resources-CLm6g0br.js → resources-BdNRDEAy.js} +3 -3
- package/dist/{resources-CLm6g0br.js.map → resources-BdNRDEAy.js.map} +1 -1
- package/dist/{schema-BKdh6UoE.js → schema-B0-p6T1O.js} +4 -4
- package/dist/{schema-BKdh6UoE.js.map → schema-B0-p6T1O.js.map} +1 -1
- package/dist/{skills-DEhYiPeO.js → skills-DfnTeyRz.js} +3 -3
- package/dist/{skills-DEhYiPeO.js.map → skills-DfnTeyRz.js.map} +1 -1
- package/dist/{start-BsPJedPQ.js → start-BmEZkS0n.js} +4 -4
- package/dist/{start-BsPJedPQ.js.map → start-BmEZkS0n.js.map} +1 -1
- package/dist/{status-D_B3tlDy.js → status-BJ26yZOo.js} +9 -9
- package/dist/{status-D_B3tlDy.js.map → status-BJ26yZOo.js.map} +1 -1
- package/dist/{storage-CtB8polS.js → storage-DKPUBTWG.js} +3 -3
- package/dist/{storage-CtB8polS.js.map → storage-DKPUBTWG.js.map} +1 -1
- package/dist/{telemetry-BYmPU-Ji.js → telemetry-m9czTNGR.js} +2 -2
- package/dist/{telemetry-BYmPU-Ji.js.map → telemetry-m9czTNGR.js.map} +1 -1
- package/dist/{upgrade-DbuKX9lv.js → upgrade-DjihWuZL.js} +5 -4
- package/dist/{upgrade-DbuKX9lv.js.map → upgrade-DjihWuZL.js.map} +1 -1
- package/dist/utils/args.d.ts +13 -0
- package/dist/utils/redact.d.ts +10 -0
- package/dist/utils/refusal.d.ts +18 -0
- package/package.json +7 -7
- package/templates/overlays/baas/README.md +2 -1
- package/templates/template/.env.example +6 -0
- package/templates/template/frontend/vite.config.ts +7 -73
- package/dist/api-keys-Bc4FJKYp.js.map +0 -1
- package/dist/args-CcBphFdj.js.map +0 -1
- package/dist/auth-BL7bNQVu.js.map +0 -1
- package/dist/bundle-CqURVN-K.js.map +0 -1
- package/dist/daemon-entry-C6pxdily.js.map +0 -1
- package/dist/db-Dkn9XhT-.js.map +0 -1
- package/dist/dev-preflight-CorMg7Ub.js.map +0 -1
- package/dist/init-CjoJoThg.js.map +0 -1
- package/dist/last-dev-database-BEBPfAMY.js +0 -2
- package/dist/prepare-C1iaiTC4.js.map +0 -1
- package/dist/pull-COpNJFzY.js.map +0 -1
- package/dist/resolve-b_p9bmdH.js +0 -2
|
@@ -41,6 +41,8 @@ export declare function resolveBackendAddress(env: Record<string, string>, proje
|
|
|
41
41
|
* Exits before any request is made: the refusal is the point.
|
|
42
42
|
*/
|
|
43
43
|
export declare function requireBackendUrl(env: Record<string, string>, projectRoot: string): string;
|
|
44
|
+
/** Where a service key is read from: the name a scaffold writes, or the older one. */
|
|
45
|
+
type ServiceKeyVariable = "REBASE_SERVICE_KEY" | "SERVICE_KEY";
|
|
44
46
|
/**
|
|
45
47
|
* What to print when a request fails: the server's error code and message,
|
|
46
48
|
* which is what says why — `SCOPE_EXCEEDS_CREATOR`, `INVALID_SCOPES`,
|
|
@@ -48,7 +50,7 @@ export declare function requireBackendUrl(env: Record<string, string>, projectRo
|
|
|
48
50
|
*
|
|
49
51
|
* Exported so its tests can read the lines without a server.
|
|
50
52
|
*/
|
|
51
|
-
export declare function describeFailure(action: string, error: unknown, baseUrl: string): string[];
|
|
53
|
+
export declare function describeFailure(action: string, error: unknown, baseUrl: string, keyVariable?: ServiceKeyVariable): string[];
|
|
52
54
|
export declare function apiKeysCommand(subcommand: string | undefined, rawArgs: string[]): Promise<void>;
|
|
53
55
|
/**
|
|
54
56
|
* The lines that describe one key: what it is, what it may do and whom it
|
|
@@ -153,3 +155,4 @@ export declare const SCOPES_LIST_FLAGS: {};
|
|
|
153
155
|
* Exported so its tests can read the lines without a server.
|
|
154
156
|
*/
|
|
155
157
|
export declare function describeScopes(scopes: readonly ScopeSummary[], held: readonly string[]): string[];
|
|
158
|
+
export {};
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -88,8 +88,9 @@ export declare function generatePassword(): string;
|
|
|
88
88
|
* attacker's refresh token minting access tokens did not recover anything.
|
|
89
89
|
*
|
|
90
90
|
* It exits 0 only when a row was updated: a missing user and a thrown error are
|
|
91
|
-
* both exit 1. `echoPassword` prints the new password, for a generated one
|
|
91
|
+
* both exit 1. `echoPassword` prints the new password, for a generated one;
|
|
92
|
+
* `showStack` prints a failure's stack rather than its sentence (`--debug`).
|
|
92
93
|
*
|
|
93
94
|
* Exported so its tests can run it.
|
|
94
95
|
*/
|
|
95
|
-
export declare function resetPasswordScript(echoPassword: boolean): string;
|
|
96
|
+
export declare function resetPasswordScript(echoPassword: boolean, showStack?: boolean): string;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
//#region src/dev-db/connection-banner.ts
|
|
3
|
+
var connection_banner_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
banner: () => banner,
|
|
5
|
+
connectionErrorText: () => connectionErrorText,
|
|
6
|
+
connectionFailureBanner: () => connectionFailureBanner,
|
|
7
|
+
connectionRefusedFixes: () => connectionRefusedFixes,
|
|
8
|
+
hostOf: () => hostOf
|
|
9
|
+
});
|
|
10
|
+
var RULE = "━".repeat(60);
|
|
11
|
+
/** The banner, as lines: a title, what the driver or tool said, then the body. */
|
|
12
|
+
function banner(title, said, body) {
|
|
13
|
+
return [
|
|
14
|
+
"",
|
|
15
|
+
RULE,
|
|
16
|
+
` ❌ ${title}`,
|
|
17
|
+
RULE,
|
|
18
|
+
"",
|
|
19
|
+
...said ? [` ${said}`, ""] : [],
|
|
20
|
+
...body.map((line) => ` ${line}`),
|
|
21
|
+
"",
|
|
22
|
+
RULE
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
/** `host:port` of a connection string, for a message: never the string, which carries the password. */
|
|
26
|
+
function hostOf(connectionString) {
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(connectionString);
|
|
29
|
+
return `${url.hostname || "localhost"}:${url.port || "5432"}`;
|
|
30
|
+
} catch {
|
|
31
|
+
return "(unparseable connection string)";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A connection error's own sentence. A refused connection on a dual-stack
|
|
36
|
+
* host is an `AggregateError` with an empty message, and its sentence —
|
|
37
|
+
* `connect ECONNREFUSED 127.0.0.1:5432` — is in the attempts it holds.
|
|
38
|
+
*/
|
|
39
|
+
function connectionErrorText(error) {
|
|
40
|
+
if (error instanceof AggregateError && error.errors.length > 0 && !error.message) return connectionErrorText(error.errors[0]);
|
|
41
|
+
return error instanceof Error && error.message ? error.message : String(error);
|
|
42
|
+
}
|
|
43
|
+
/** The `code` a `pg` or `net` error carries, looking inside an `AggregateError`'s attempts. */
|
|
44
|
+
function codeOf(error) {
|
|
45
|
+
if (error instanceof AggregateError && error.errors.length > 0) for (const inner of error.errors) {
|
|
46
|
+
const code = codeOf(inner);
|
|
47
|
+
if (code) return code;
|
|
48
|
+
}
|
|
49
|
+
if (error && typeof error === "object" && "code" in error && typeof error.code === "string") return error.code;
|
|
50
|
+
}
|
|
51
|
+
/** A server that is not there, or not reachable from here. */
|
|
52
|
+
var UNREACHABLE = /* @__PURE__ */ new Set([
|
|
53
|
+
"ECONNREFUSED",
|
|
54
|
+
"ENOTFOUND",
|
|
55
|
+
"EAI_AGAIN",
|
|
56
|
+
"ETIMEDOUT",
|
|
57
|
+
"EHOSTUNREACH",
|
|
58
|
+
"ENETUNREACH",
|
|
59
|
+
"ECONNRESET"
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* What to print when opening `url` failed with `error`: the banner, in the
|
|
63
|
+
* case it is — the server not answering, credentials refused, a database
|
|
64
|
+
* closed to new connections, or a database of that name not there — or `null`
|
|
65
|
+
* when it is none of those four.
|
|
66
|
+
*
|
|
67
|
+
* `consequence` is the line saying what did not happen ("The password was not
|
|
68
|
+
* reset."); `fixes` is what to do about a server that does not answer, which
|
|
69
|
+
* depends on what named the database.
|
|
70
|
+
*/
|
|
71
|
+
function connectionFailureBanner(url, error, options) {
|
|
72
|
+
const code = codeOf(error);
|
|
73
|
+
const text = connectionErrorText(error);
|
|
74
|
+
const said = `The driver said: ${text}${code && !text.includes(code) ? ` (${code})` : ""}`;
|
|
75
|
+
const host = hostOf(url);
|
|
76
|
+
if (code && UNREACHABLE.has(code) || /timeout expired|Connection terminated due to connection timeout/i.test(text)) return banner(`Cannot connect to PostgreSQL at ${host}`, said, [
|
|
77
|
+
"The database server is not running or is not accepting connections.",
|
|
78
|
+
options.consequence,
|
|
79
|
+
"",
|
|
80
|
+
...options.fixes.map((fix) => ` • ${fix}`)
|
|
81
|
+
]);
|
|
82
|
+
if (code === "28P01" || code === "28000") {
|
|
83
|
+
let user = "unknown";
|
|
84
|
+
try {
|
|
85
|
+
user = decodeURIComponent(new URL(url).username) || "unknown";
|
|
86
|
+
} catch {}
|
|
87
|
+
return banner(`Authentication failed for user "${user}" at ${host}`, said, ["PostgreSQL rejected the credentials in the connection string.", options.consequence]);
|
|
88
|
+
}
|
|
89
|
+
const closed = /database "(.+)" is not currently accepting connections/.exec(text)?.[1];
|
|
90
|
+
if (closed) return banner(`Database "${closed}" at ${host} is closed to new connections`, said, [
|
|
91
|
+
"It is set to refuse every new connection (ALLOW_CONNECTIONS false).",
|
|
92
|
+
"`rebase db branch create --force` closes its source for the copy, and one",
|
|
93
|
+
"stopped before it finished (a closed terminal, a kill) leaves it closed.",
|
|
94
|
+
options.consequence,
|
|
95
|
+
"",
|
|
96
|
+
"Nothing in it is lost. Open it again with:",
|
|
97
|
+
" rebase db branch list (every rebase db branch command opens it first)",
|
|
98
|
+
"or run this, connected to the server's postgres database:",
|
|
99
|
+
` ALTER DATABASE "${closed.replace(/"/g, "\"\"")}" ALLOW_CONNECTIONS true;`
|
|
100
|
+
]);
|
|
101
|
+
if (code === "3D000") {
|
|
102
|
+
let database = "(default)";
|
|
103
|
+
try {
|
|
104
|
+
database = decodeURIComponent(new URL(url).pathname.replace(/^\//, "")) || database;
|
|
105
|
+
} catch {}
|
|
106
|
+
return banner(`Database "${database}" does not exist at ${host}`, said, ["The server answered, and has no database of that name.", options.consequence]);
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* What to do about a database that does not answer, for what named it — the
|
|
112
|
+
* list the driver's banner gives for the same `REBASE_DATABASE_SOURCE`.
|
|
113
|
+
*/
|
|
114
|
+
function connectionRefusedFixes(source) {
|
|
115
|
+
switch (source) {
|
|
116
|
+
case "flag": return ["Check the URL passed with --database-url, and that its server is running"];
|
|
117
|
+
case "environment": return ["Check DATABASE_URL in this shell's environment, and that its server is running"];
|
|
118
|
+
case "env-file": return ["Check DATABASE_URL in .env, and that its server is running"];
|
|
119
|
+
case "branch": return ["The branch's database is on the server DATABASE_URL names: start that server", "Or leave the branch: rebase db branch switch --off"];
|
|
120
|
+
case "docker":
|
|
121
|
+
case "last-dev": return ["docker compose up -d db (the project's Postgres in Docker)"];
|
|
122
|
+
case "managed": return ["Restart the managed development database: rebase db stop, then run the command again"];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { hostOf as i, connectionErrorText as n, connection_banner_exports as r, banner as t };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=connection-banner-DbLJzWf4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-banner-DbLJzWf4.js","names":[],"sources":["../src/dev-db/connection-banner.ts"],"sourcesContent":["/**\n * The boxed banner the database commands print when a connection fails.\n *\n * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n * ❌ Cannot connect to PostgreSQL at 127.0.0.1:5508\n * ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n *\n * The driver said: connect ECONNREFUSED 127.0.0.1:5508\n * …\n *\n * The driver prints it for the commands it runs (`cli-errors.ts` in\n * `@rebasepro/server-postgres`, which its entry does not export); this is the\n * same box for the commands the CLI answers in its own process — `db pull`\n * and `auth reset-password`'s database fallback — as plain lines for the\n * caller to print. Never with the connection string in it: it carries the\n * password.\n */\nimport type { DevDatabaseSource } from \"./resolve\";\n\nconst RULE = \"━\".repeat(60);\n\n/** The banner, as lines: a title, what the driver or tool said, then the body. */\nexport function banner(title: string, said: string | null, body: readonly string[]): string[] {\n return [\"\", RULE, ` ❌ ${title}`, RULE, \"\", ...(said ? [` ${said}`, \"\"] : []), ...body.map(line => ` ${line}`), \"\", RULE];\n}\n\n/** `host:port` of a connection string, for a message: never the string, which carries the password. */\nexport function hostOf(connectionString: string): string {\n try {\n const url = new URL(connectionString);\n\n return `${url.hostname || \"localhost\"}:${url.port || \"5432\"}`;\n } catch {\n return \"(unparseable connection string)\";\n }\n}\n\n/**\n * A connection error's own sentence. A refused connection on a dual-stack\n * host is an `AggregateError` with an empty message, and its sentence —\n * `connect ECONNREFUSED 127.0.0.1:5432` — is in the attempts it holds.\n */\nexport function connectionErrorText(error: unknown): string {\n if (error instanceof AggregateError && error.errors.length > 0 && !error.message) {\n return connectionErrorText(error.errors[0]);\n }\n\n return error instanceof Error && error.message ? error.message : String(error);\n}\n\n/** The `code` a `pg` or `net` error carries, looking inside an `AggregateError`'s attempts. */\nfunction codeOf(error: unknown): string | undefined {\n if (error instanceof AggregateError && error.errors.length > 0) {\n for (const inner of error.errors) {\n const code = codeOf(inner);\n if (code) return code;\n }\n }\n if (error && typeof error === \"object\" && \"code\" in error && typeof error.code === \"string\") return error.code;\n\n return undefined;\n}\n\n/** A server that is not there, or not reachable from here. */\nconst UNREACHABLE = new Set([\"ECONNREFUSED\", \"ENOTFOUND\", \"EAI_AGAIN\", \"ETIMEDOUT\", \"EHOSTUNREACH\", \"ENETUNREACH\", \"ECONNRESET\"]);\n\n/**\n * What to print when opening `url` failed with `error`: the banner, in the\n * case it is — the server not answering, credentials refused, a database\n * closed to new connections, or a database of that name not there — or `null`\n * when it is none of those four.\n *\n * `consequence` is the line saying what did not happen (\"The password was not\n * reset.\"); `fixes` is what to do about a server that does not answer, which\n * depends on what named the database.\n */\nexport function connectionFailureBanner(\n url: string,\n error: unknown,\n options: { consequence: string; fixes: readonly string[] }\n): string[] | null {\n const code = codeOf(error);\n const text = connectionErrorText(error);\n const said = `The driver said: ${text}${code && !text.includes(code) ? ` (${code})` : \"\"}`;\n const host = hostOf(url);\n\n if ((code && UNREACHABLE.has(code)) || /timeout expired|Connection terminated due to connection timeout/i.test(text)) {\n return banner(`Cannot connect to PostgreSQL at ${host}`, said, [\n \"The database server is not running or is not accepting connections.\",\n options.consequence,\n \"\",\n ...options.fixes.map(fix => ` • ${fix}`)\n ]);\n }\n if (code === \"28P01\" || code === \"28000\") {\n let user = \"unknown\";\n try {\n user = decodeURIComponent(new URL(url).username) || \"unknown\";\n } catch { /* named as unknown */ }\n return banner(`Authentication failed for user \"${user}\" at ${host}`, said, [\n \"PostgreSQL rejected the credentials in the connection string.\",\n options.consequence\n ]);\n }\n // 55000 covers more than this, so the sentence is matched — as the driver's banner does.\n const closed = /database \"(.+)\" is not currently accepting connections/.exec(text)?.[1];\n if (closed) {\n return banner(`Database \"${closed}\" at ${host} is closed to new connections`, said, [\n \"It is set to refuse every new connection (ALLOW_CONNECTIONS false).\",\n \"`rebase db branch create --force` closes its source for the copy, and one\",\n \"stopped before it finished (a closed terminal, a kill) leaves it closed.\",\n options.consequence,\n \"\",\n \"Nothing in it is lost. Open it again with:\",\n \" rebase db branch list (every rebase db branch command opens it first)\",\n \"or run this, connected to the server's postgres database:\",\n ` ALTER DATABASE \"${closed.replace(/\"/g, '\"\"')}\" ALLOW_CONNECTIONS true;`\n ]);\n }\n if (code === \"3D000\") {\n let database = \"(default)\";\n try {\n database = decodeURIComponent(new URL(url).pathname.replace(/^\\//, \"\")) || database;\n } catch { /* named as the default */ }\n return banner(`Database \"${database}\" does not exist at ${host}`, said, [\n \"The server answered, and has no database of that name.\",\n options.consequence\n ]);\n }\n\n return null;\n}\n\n/**\n * What to do about a database that does not answer, for what named it — the\n * list the driver's banner gives for the same `REBASE_DATABASE_SOURCE`.\n */\nexport function connectionRefusedFixes(source: DevDatabaseSource): string[] {\n switch (source) {\n case \"flag\": return [\"Check the URL passed with --database-url, and that its server is running\"];\n case \"environment\": return [\"Check DATABASE_URL in this shell's environment, and that its server is running\"];\n case \"env-file\": return [\"Check DATABASE_URL in .env, and that its server is running\"];\n case \"branch\": return [\n \"The branch's database is on the server DATABASE_URL names: start that server\",\n \"Or leave the branch: rebase db branch switch --off\"\n ];\n case \"docker\":\n case \"last-dev\": return [\"docker compose up -d db (the project's Postgres in Docker)\"];\n case \"managed\": return [\"Restart the managed development database: rebase db stop, then run the command again\"];\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,IAAM,OAAO,IAAI,OAAO,EAAE;;AAG1B,SAAgB,OAAO,OAAe,MAAqB,MAAmC;CAC1F,OAAO;EAAC;EAAI;EAAM,QAAQ;EAAS;EAAM;EAAI,GAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,IAAI,CAAC;EAAI,GAAG,KAAK,KAAI,SAAQ,KAAK,MAAM;EAAG;EAAI;CAAI;AAC/H;;AAGA,SAAgB,OAAO,kBAAkC;CACrD,IAAI;EACA,MAAM,MAAM,IAAI,IAAI,gBAAgB;EAEpC,OAAO,GAAG,IAAI,YAAY,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Q,MAAM,CACvE,iEACA,QAAQ,WACZ,CAAC;CACL;CAEA,MAAM,SAAS,yDAAyD,KAAK,IAAI,CAAC,GAAG;CACrF,IAAI,QACA,OAAO,OAAO,aAAa,OAAO,OAAO,KAAK,gCAAgC,MAAM;EAChF;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA,qBAAqB,OAAO,QAAQ,MAAM,MAAI,EAAE;CACpD,CAAC;CAEL,IAAI,SAAS,SAAS;EAClB,IAAI,WAAW;EACf,IAAI;GACA,WAAW,mBAAmB,IAAI,IAAI,GAAG,CAAC,CAAC,SAAS,QAAQ,OAAO,EAAE,CAAC,KAAK;EAC/E,QAAQ,CAA6B;EACrC,OAAO,OAAO,aAAa,SAAS,sBAAsB,QAAQ,MAAM,CACpE,0DACA,QAAQ,WACZ,CAAC;CACL;CAEA,OAAO;AACX;;;;;AAMA,SAAgB,uBAAuB,QAAqC;CACxE,QAAQ,QAAR;EACI,KAAK,QAAQ,OAAO,CAAC,0EAA0E;EAC/F,KAAK,eAAe,OAAO,CAAC,gFAAgF;EAC5G,KAAK,YAAY,OAAO,CAAC,4DAA4D;EACrF,KAAK,UAAU,OAAO,CAClB,gFACA,oDACJ;EACA,KAAK;EACL,KAAK,YAAY,OAAO,CAAC,qEAAqE;EAC9F,KAAK,WAAW,OAAO,CAAC,sFAAsF;CAClH;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as parseCommandArgs, r as wantsHelp } from "./args-
|
|
1
|
+
import { n as parseCommandArgs, r as wantsHelp } from "./args-BX0YD14a.js";
|
|
2
2
|
import { r as refuseMissingCollectionsPath, t as COLLECTIONS_FLAG_HELP } from "./path-flags-BFgG9V6y.js";
|
|
3
|
-
import { DEV_DATABASE_KIND_ENV, managedNotices, prepareDatabaseEnv } from "./prepare-
|
|
4
|
-
import { absolutizeLocalPathArgs, ensureDockerDatabase, n as argsFromCommand, resolveDriverCli, spawnDriverCli, t as reportSpawnFailure } from "./db-
|
|
3
|
+
import { DEV_DATABASE_KIND_ENV, managedNotices, prepareDatabaseEnv } from "./prepare-DdnU70z8.js";
|
|
4
|
+
import { absolutizeLocalPathArgs, ensureDockerDatabase, n as argsFromCommand, resolveDriverCli, spawnDriverCli, t as reportSpawnFailure } from "./db-CRNpA5mH.js";
|
|
5
5
|
import chalk from "chalk";
|
|
6
6
|
import path from "path";
|
|
7
7
|
//#region src/commands/console.ts
|
|
@@ -100,4 +100,4 @@ async function consoleCommand(rawArgs) {
|
|
|
100
100
|
//#endregion
|
|
101
101
|
export { consoleCommand };
|
|
102
102
|
|
|
103
|
-
//# sourceMappingURL=console-
|
|
103
|
+
//# sourceMappingURL=console-CEGm0XNc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-
|
|
1
|
+
{"version":3,"file":"console-CEGm0XNc.js","names":[],"sources":["../src/commands/console.ts"],"sourcesContent":["/**\n * CLI command: rebase console\n *\n * A Node REPL with the project open — `rebase` (what `openRebase` from\n * `@rebasepro/server-postgres` returns: `dataAsAdmin`, `sql`, `withAuth`) and\n * `collections` in scope — or, with `--eval`, one piece of code run and its\n * result printed as JSON.\n *\n * Resolved like `rebase db push`: the same project and `.env`, the same\n * database (the managed one started if that is what the project uses), the\n * same `--collections` loader — the driver's, spawned in `backend/`. Opening\n * the database changes nothing in it.\n */\nimport chalk from \"chalk\";\nimport path from \"path\";\nimport { parseCommandArgs, wantsHelp } from \"../utils/args\";\nimport { argsFromCommand } from \"../utils/command-words\";\nimport { COLLECTIONS_FLAG_HELP, refuseMissingCollectionsPath } from \"../utils/path-flags\";\nimport { reportSpawnFailure } from \"../utils/spawn-error\";\nimport { DEV_DATABASE_KIND_ENV, managedNotices, prepareDatabaseEnv } from \"../dev-db/prepare\";\nimport { absolutizeLocalPathArgs, ensureDockerDatabase, resolveDriverCli, spawnDriverCli } from \"./db\";\n\nexport const CONSOLE_FLAGS = {\n \"--eval\": String,\n \"-e\": \"--eval\",\n \"--collections\": String,\n \"-c\": \"--collections\",\n \"--database-url\": String,\n \"--docker\": Boolean\n} as const;\n\n/** What each long flag above does, for the Options block. */\nconst CONSOLE_FLAG_HELP: Record<string, string> = {\n \"--eval\": \"Run this code instead of the REPL, print its awaited result as JSON, and exit 1 if it throws\",\n \"--collections\": COLLECTIONS_FLAG_HELP,\n \"--database-url\": \"Open this database instead of the project's\",\n \"--docker\": \"Use the database from docker compose, starting it if needed\"\n};\n\n/** Where the REPL keeps its history: the project's own `.rebase/`, which the scaffold ignores. */\nexport function consoleHistoryPath(projectRoot: string): string {\n return path.join(projectRoot, \".rebase\", \"console_history\");\n}\n\nfunction flagLabel(flag: string): string {\n const aliases = Object.entries(CONSOLE_FLAGS)\n .filter(([, target]) => target === flag)\n .map(([alias]) => alias);\n return [flag, ...aliases].join(\", \");\n}\n\nexport function printConsoleHelp(): void {\n console.log(`\n${chalk.bold(\"rebase console\")} — Explore the project's data from a REPL\n\n${chalk.green.bold(\"Usage\")}\n rebase console [options]\n\n${chalk.green.bold(\"Options\")}\n${Object.keys(CONSOLE_FLAG_HELP)\n .map(flag => ` ${chalk.blue(flagLabel(flag).padEnd(22))} ${CONSOLE_FLAG_HELP[flag]}`)\n .join(\"\\n\")}\n\nIn scope:\n rebase dataAsAdmin, sql(query, { params }), withAuth(user) → { data }, close()\n collections the project's collections\n\nTop-level await works. Opening the database changes nothing in it: no table,\nrole or trigger is created. withAuth runs as the user under row-level security.\n\n${chalk.green.bold(\"Examples\")}\n rebase console\n rebase console -e \"rebase.dataAsAdmin.posts.find({ limit: 5 })\"\n rebase console -e \"(await rebase.withAuth({ uid: 'u1', roles: ['user'] })).data.posts.find()\"\n rebase console -e \"rebase.sql('select count(*) from posts')\"\n`);\n}\n\nexport async function consoleCommand(rawArgs: string[]): Promise<void> {\n if (wantsHelp(rawArgs)) {\n printConsoleHelp();\n return;\n }\n\n // Strictly, before the line is relayed: the driver would otherwise be the\n // first to see a mistyped flag, after a database had been started for it.\n const { flags } = parseCommandArgs({\n spec: CONSOLE_FLAGS,\n rawArgs,\n commandWords: 1,\n command: \"console\",\n maxPositionals: 0\n });\n\n const resolved = await resolveDriverCli();\n const { projectRoot, backendDir } = resolved;\n refuseMissingCollectionsPath(rawArgs, process.cwd(), backendDir, \"console\");\n await ensureDockerDatabase(projectRoot, rawArgs);\n\n // With --eval, stdout is the result and nothing else, so it can be piped\n // into `jq`; piped into the REPL, it is the REPL's answers. Either way what\n // the database resolution has to say goes to stderr.\n const say = flags[\"--eval\"] === undefined && process.stdin.isTTY\n ? (line: string) => console.log(chalk.gray(` ${line}`))\n : (line: string) => console.error(chalk.gray(` ${line}`));\n const prepared = await prepareDatabaseEnv(projectRoot, {\n flagUrl: flags[\"--database-url\"] ?? null,\n flagDocker: flags[\"--docker\"] === true,\n onProgress: say\n });\n Object.assign(resolved.env, prepared.env);\n // The database this run resolved, flags included, so the driver words a\n // failure to open it for that one — a managed database that has no free\n // connection is not \"is your Postgres running?\".\n resolved.env[DEV_DATABASE_KIND_ENV] = prepared.database.kind;\n for (const line of managedNotices(prepared)) say(line);\n\n const childArgs = [\n ...absolutizeLocalPathArgs(argsFromCommand(rawArgs, \"console\"), process.cwd()),\n `--history=${consoleHistoryPath(projectRoot)}`\n ];\n\n try {\n await spawnDriverCli(resolved, childArgs);\n } catch (error) {\n // A child that exited non-zero has already said why, on the terminal it\n // shares — an `--eval` that threw, a database that refused.\n reportSpawnFailure(error);\n process.exit(1);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,IAAa,gBAAgB;CACzB,UAAU;CACV,MAAM;CACN,iBAAiB;CACjB,MAAM;CACN,kBAAkB;CAClB,YAAY;AAChB;;AAGA,IAAM,oBAA4C;CAC9C,UAAU;CACV,iBAAiB;CACjB,kBAAkB;CAClB,YAAY;AAChB;;AAGA,SAAgB,mBAAmB,aAA6B;CAC5D,OAAO,KAAK,KAAK,aAAa,WAAW,iBAAiB;AAC9D;AAEA,SAAS,UAAU,MAAsB;CAIrC,OAAO,CAAC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AK,MAAM,QAAQ,eAAe,QAAQ,GAAG,IAAI,IAAI;CAErD,MAAM,YAAY,CACd,GAAG,wBAAwB,gBAAgB,SAAS,SAAS,GAAG,QAAQ,IAAI,CAAC,GAC7E,aAAa,mBAAmB,WAAW,GAC/C;CAEA,IAAI;EACA,MAAM,eAAe,UAAU,SAAS;CAC5C,SAAS,OAAO;EAGZ,mBAAmB,KAAK;EACxB,QAAQ,KAAK,CAAC;CAClB;AACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as findProjectRoot } from "./project-Wp2zoyeN.js";
|
|
2
|
-
import { n as parseCommandArgs } from "./args-
|
|
2
|
+
import { n as parseCommandArgs } from "./args-BX0YD14a.js";
|
|
3
3
|
import { t as cliUserAgent } from "./version-Buyyo1ut.js";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import arg from "arg";
|
|
@@ -1231,4 +1231,4 @@ function requireCloudRow(row, what) {
|
|
|
1231
1231
|
//#endregion
|
|
1232
1232
|
export { projectHost as A, requireProject as B, lookupProjectId as C, parseCloudArgs as D, openUrl as E, reportError as F, resolveProjectRef as G, requireSessionClient as H, requireClient as I, setCurrentContext as J, resolveTimeoutMs as K, requireCloudRow as L, readLink as M, refuseDirectLink as N, printGroupHelp as O, removeLink as P, wantsRawError as Q, requireInteractive as R, keyValues as S, noteBlank as T, resolveCloudTarget as U, requireProjectRef as V, resolveCloudUrl as W, warn as X, success as Y, writeLink as Z, freshAccessToken as _, cloudRow as a, isJsonMode as b, confirmDestructive as c, emit as d, emitHelp as f, fetchTenantBaseDomain as g, fetchDeployTargets as h, billingAccountIdOf as i, projectLinkPath as j, printJson as k, createCloudClient as l, fail as m, GLOBAL_HELP_FLAGS as n, cloudRows as o, envToken as p, setContextOrg as q, TOKEN_ENV as r, colorStatus as s, GLOBAL_CLOUD_FLAGS as t, displayProjectRef as u, getContextOrg as v, note as w, isKnownControlPlane as x, initOutputMode as y, requireKnownAction as z };
|
|
1233
1233
|
|
|
1234
|
-
//# sourceMappingURL=context-
|
|
1234
|
+
//# sourceMappingURL=context-CyflUrKg.js.map
|