@rebasepro/cli 0.28.2 → 0.29.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.
Files changed (39) hide show
  1. package/dist/{apps-BpYRGOaM.js → apps-Dg0NnmmJ.js} +3 -3
  2. package/dist/{apps-BpYRGOaM.js.map → apps-Dg0NnmmJ.js.map} +1 -1
  3. package/dist/{build-CS-Z75eK.js → build-1Zo35L6a.js} +3 -3
  4. package/dist/{build-CS-Z75eK.js.map → build-1Zo35L6a.js.map} +1 -1
  5. package/dist/{bundle-C0IBCVpV.js → bundle-CTkzO2WG.js} +2 -2
  6. package/dist/{bundle-C0IBCVpV.js.map → bundle-CTkzO2WG.js.map} +1 -1
  7. package/dist/{cloud-CXyZobBh.js → cloud-CFotGK2-.js} +511 -21
  8. package/dist/cloud-CFotGK2-.js.map +1 -0
  9. package/dist/commands/cloud/databases.d.ts +1 -0
  10. package/dist/commands/cloud/db-access.d.ts +25 -0
  11. package/dist/commands/cloud/index.d.ts +8 -0
  12. package/dist/commands/cloud/maintenance.d.ts +44 -0
  13. package/dist/commands/cloud/resources.d.ts +1 -1
  14. package/dist/{context-DvIUbE-b.js → context-DN1b9pCR.js} +2 -1
  15. package/dist/context-DN1b9pCR.js.map +1 -0
  16. package/dist/{fold-static-BMO8LC01.js → fold-static-vbZJeo37.js} +2 -2
  17. package/dist/{fold-static-BMO8LC01.js.map → fold-static-vbZJeo37.js.map} +1 -1
  18. package/dist/{generate_sdk-_SQuSbJW.js → generate_sdk-DCUUogIP.js} +2 -2
  19. package/dist/{generate_sdk-_SQuSbJW.js.map → generate_sdk-DCUUogIP.js.map} +1 -1
  20. package/dist/index.es.js +13 -13
  21. package/dist/{init-CHtpYLlh.js → init-YzfyEffT.js} +2 -2
  22. package/dist/{init-CHtpYLlh.js.map → init-YzfyEffT.js.map} +1 -1
  23. package/dist/{normalize-imports-BN0fzZS8.js → normalize-imports-xpSL_GuU.js} +2 -2
  24. package/dist/{normalize-imports-BN0fzZS8.js.map → normalize-imports-xpSL_GuU.js.map} +1 -1
  25. package/dist/{schema-2A0dd-Bv.js → schema-CApM25cs.js} +10 -9
  26. package/dist/schema-CApM25cs.js.map +1 -0
  27. package/dist/schema-reconcile-CX1_6Xqm.js +2 -0
  28. package/dist/{start-21GRsZKc.js → start-28EztR4R.js} +2 -2
  29. package/dist/{start-21GRsZKc.js.map → start-28EztR4R.js.map} +1 -1
  30. package/package.json +8 -8
  31. package/templates/overlays/baas/ai-instructions.md +1 -1
  32. package/templates/template/ai-instructions.md +2 -2
  33. package/templates/template/frontend/vite.config.ts +5 -2
  34. package/templates/views/AppView.tsx.tmpl +19 -32
  35. package/templates/views/EntityView.tsx.tmpl +8 -7
  36. package/dist/cloud-CXyZobBh.js.map +0 -1
  37. package/dist/context-DvIUbE-b.js.map +0 -1
  38. package/dist/schema-2A0dd-Bv.js.map +0 -1
  39. package/dist/schema-reconcile-C3ToVnHr.js +0 -2
@@ -2,11 +2,11 @@ import { i as recordEvent, l as durationBucket } from "./telemetry-CgwJPVMO.js";
2
2
  import { C as switchOn, D as unknownCommandMessage, c as findProjectRoot, p as requireProjectRoot } from "./project-CasK56vN.js";
3
3
  import { t as cliUserAgent } from "./version-Buyyo1ut.js";
4
4
  import { _ as selectDeployApp, d as findBackendApp, f as formatAppAddress, l as cmsMountOf, p as loadManifest } from "./manifest-BtzDy7KQ.js";
5
- import { C as toolStdio, n as UNVENDORED_COST, s as buildBundle, x as unvendoredReason } from "./bundle-C0IBCVpV.js";
6
- import { $ as resolveCloudUrl, A as lookupProjectId, B as projectLinkPath, C as grantForLink, D as isKnownControlPlane, E as isJsonMode, F as printGroupHelp, G as requireClient, H as refuseDirectLink, I as printJson, J as requireKnownAction, K as requireCloudRow, L as probeToken, M as noteBlank, N as openUrl, O as keyValues, P as parseCloudArgs, Q as resolveCloudTarget, R as projectDotenvSetsAppKey, S as getContextOrg, T as initOutputMode, U as removeLink, V as readLink, W as reportError, X as requireProjectRef, Y as requireProject, Z as requireSessionClient, _ as fail, _t as orgCapabilitiesInScopes, a as billingAccountIdOf, at as storedGrantForLink, b as forgetEphemeralGrant, bt as wantsRawError, c as colorStatus, ct as writeLink, d as displayProjectRef, dt as ORG_CAPABILITY_NAMES, et as resolveProjectRef, f as dotenvSets, ft as TOKEN_CAPABILITIES, g as ephemeralGrantFor, gt as isTokenCapability, h as envToken, ht as isOrgCapability, i as appKeyExpiryNote, it as setCurrentContext, j as note, k as linkedEphemeralGrant, l as confirmDestructive, lt as ALWAYS_SCOPES, m as emitHelp, mt as capabilitiesInScopes, n as GLOBAL_HELP_FLAGS, nt as saveEphemeralGrant, o as cloudRow, ot as success, p as emit, pt as TOKEN_CAPABILITY_NAMES, q as requireInteractive, r as TOKEN_ENV, rt as setContextOrg, s as cloudRows, st as warn, t as GLOBAL_CLOUD_FLAGS, tt as resolveTimeoutMs, u as createCloudClient, ut as ORG_CAPABILITIES, v as fetchDeployTargets, vt as scopesForCapabilities, w as grantProjectOf, x as freshAccessToken, y as fetchTenantBaseDomain, yt as scopesForOrgCapabilities, z as projectHost } from "./context-DvIUbE-b.js";
7
- import { n as foldFrontendIntoBundle, r as foldableApps } from "./fold-static-BMO8LC01.js";
5
+ import { C as toolStdio, n as UNVENDORED_COST, s as buildBundle, x as unvendoredReason } from "./bundle-CTkzO2WG.js";
6
+ import { $ as resolveCloudUrl, A as lookupProjectId, B as projectLinkPath, C as grantForLink, D as isKnownControlPlane, E as isJsonMode, F as printGroupHelp, G as requireClient, H as refuseDirectLink, I as printJson, J as requireKnownAction, K as requireCloudRow, L as probeToken, M as noteBlank, N as openUrl, O as keyValues, P as parseCloudArgs, Q as resolveCloudTarget, R as projectDotenvSetsAppKey, S as getContextOrg, T as initOutputMode, U as removeLink, V as readLink, W as reportError, X as requireProjectRef, Y as requireProject, Z as requireSessionClient, _ as fail, _t as orgCapabilitiesInScopes, a as billingAccountIdOf, at as storedGrantForLink, b as forgetEphemeralGrant, bt as wantsRawError, c as colorStatus, ct as writeLink, d as displayProjectRef, dt as ORG_CAPABILITY_NAMES, et as resolveProjectRef, f as dotenvSets, ft as TOKEN_CAPABILITIES, g as ephemeralGrantFor, gt as isTokenCapability, h as envToken, ht as isOrgCapability, i as appKeyExpiryNote, it as setCurrentContext, j as note, k as linkedEphemeralGrant, l as confirmDestructive, lt as ALWAYS_SCOPES, m as emitHelp, mt as capabilitiesInScopes, n as GLOBAL_HELP_FLAGS, nt as saveEphemeralGrant, o as cloudRow, ot as success, p as emit, pt as TOKEN_CAPABILITY_NAMES, q as requireInteractive, r as TOKEN_ENV, rt as setContextOrg, s as cloudRows, st as warn, t as GLOBAL_CLOUD_FLAGS, tt as resolveTimeoutMs, u as createCloudClient, ut as ORG_CAPABILITIES, v as fetchDeployTargets, vt as scopesForCapabilities, w as grantProjectOf, x as freshAccessToken, y as fetchTenantBaseDomain, yt as scopesForOrgCapabilities, z as projectHost } from "./context-DN1b9pCR.js";
7
+ import { n as foldFrontendIntoBundle, r as foldableApps } from "./fold-static-vbZJeo37.js";
8
8
  import { n as deriveOptionsFor, r as deriveResourceGraph } from "./derive-ae9UOoOB.js";
9
- import { t as buildAssetApp } from "./build-CS-Z75eK.js";
9
+ import { t as buildAssetApp } from "./build-1Zo35L6a.js";
10
10
  import chalk from "chalk";
11
11
  import arg from "arg";
12
12
  import fs from "fs";
@@ -18,7 +18,211 @@ import { DEFAULT_STORAGE_SOURCE_KEY } from "@rebasepro/types";
18
18
  import inquirer from "inquirer";
19
19
  import { RebaseApiError, createRebaseClient } from "@rebasepro/client";
20
20
  import net from "node:net";
21
+ import fs$1 from "node:fs";
21
22
  import { parse } from "acorn";
23
+ //#region src/commands/cloud/maintenance.ts
24
+ /**
25
+ * A project's maintenance window, what its database is waiting on, and its
26
+ * events — from the terminal.
27
+ *
28
+ * rebase cloud compute apply [--yes] restart the database at its new size now
29
+ * rebase cloud compute window show the weekly window
30
+ * rebase cloud compute window --day sun --hour 3 move it (UTC)
31
+ * rebase cloud events [--limit 20] what happened to the backend, newest first
32
+ *
33
+ * All of it is the control plane's `maintenance` function
34
+ * (`saas/backend/functions/maintenance.ts`). A database change that restarts
35
+ * Postgres never happens on `compute set`: it waits for the window, and
36
+ * `compute apply` is how someone who would rather take the restart now says so.
37
+ */
38
+ var COMPUTE_WINDOW_FLAGS = {
39
+ "--day": String,
40
+ "--hour": Number
41
+ };
42
+ var EVENTS_FLAGS = { "--limit": Number };
43
+ var DAYS = [
44
+ "sun",
45
+ "mon",
46
+ "tue",
47
+ "wed",
48
+ "thu",
49
+ "fri",
50
+ "sat"
51
+ ];
52
+ var DAY_NAMES = [
53
+ "sunday",
54
+ "monday",
55
+ "tuesday",
56
+ "wednesday",
57
+ "thursday",
58
+ "friday",
59
+ "saturday"
60
+ ];
61
+ /** `sun`, `sunday`, `0` → 0. Undefined for anything else, including the ambiguous `t` and `s`. */
62
+ function parseDay(value) {
63
+ const v = value.trim().toLowerCase();
64
+ if (/^[0-6]$/.test(v)) return Number(v);
65
+ if (v.length < 2) return void 0;
66
+ const i = DAY_NAMES.findIndex((d) => d.startsWith(v));
67
+ return i >= 0 ? i : void 0;
68
+ }
69
+ /** The project's maintenance status, or undefined from a control plane that has no maintenance function yet. */
70
+ async function fetchMaintenance(client, projectId) {
71
+ try {
72
+ return await client.functions.invoke("maintenance", void 0, {
73
+ method: "GET",
74
+ path: `projects/${encodeURIComponent(projectId)}`
75
+ });
76
+ } catch {
77
+ return;
78
+ }
79
+ }
80
+ /** One line for a waiting batch: "Database 0.16 → 0.5 vCPU — applies Sunday 9 November, 03:00 UTC". */
81
+ function describePending(open) {
82
+ if (!open) return void 0;
83
+ if (open.state === "applying") return `${open.summary} — ${chalk.yellow("applying now")}`;
84
+ const when = open.scheduledLabel ?? (open.scheduledFor ? new Date(open.scheduledFor).toUTCString() : "when the project starts");
85
+ return `${open.summary} — applies ${when}`;
86
+ }
87
+ async function computeApplyCommand(rawArgs) {
88
+ const { flags } = parseCloudArgs({
89
+ spec: {},
90
+ rawArgs,
91
+ commandWords: 3,
92
+ command: "cloud compute apply",
93
+ maxPositionals: 0
94
+ });
95
+ const { client } = await requireClient(rawArgs);
96
+ const projectId = await requireProject(rawArgs, client);
97
+ const ref = displayProjectRef(rawArgs);
98
+ const status = await fetchMaintenance(client, projectId);
99
+ if (!status) fail("This control plane does not schedule database changes yet.", void 0, "unsupported");
100
+ const open = status.open;
101
+ if (!open || open.state !== "pending" && open.state !== "notified") {
102
+ if (open?.state === "applying") {
103
+ emit(() => note(`${open.summary} is being applied now.`), {
104
+ status: "applying",
105
+ maintenance: open
106
+ });
107
+ return;
108
+ }
109
+ emit(() => success(`Nothing is waiting: ${ref}'s database already matches its settings.`), {
110
+ status: "nothing",
111
+ maintenance: null
112
+ });
113
+ return;
114
+ }
115
+ await confirmDestructive({
116
+ yes: Boolean(flags["--yes"]),
117
+ prompt: `Apply "${open.summary}" to ${ref} now? ${open.expectedImpact ?? "The database restarts."}`
118
+ });
119
+ try {
120
+ await client.functions.invoke("maintenance", {}, { path: `projects/${encodeURIComponent(projectId)}/apply` });
121
+ } catch (error) {
122
+ reportError(error, "Could not apply the database change");
123
+ }
124
+ emit(() => {
125
+ success(`Applying ${open.summary}.`);
126
+ note("The database restarts first, then the app. Follow it with `rebase cloud events`.");
127
+ }, {
128
+ status: "applying",
129
+ maintenance: open
130
+ });
131
+ }
132
+ async function computeWindowCommand(rawArgs) {
133
+ const { flags } = parseCloudArgs({
134
+ spec: COMPUTE_WINDOW_FLAGS,
135
+ rawArgs,
136
+ commandWords: 3,
137
+ command: "cloud compute window",
138
+ maxPositionals: 0
139
+ });
140
+ const { client } = await requireClient(rawArgs);
141
+ const projectId = await requireProject(rawArgs, client);
142
+ const dayFlag = flags["--day"];
143
+ const hourFlag = flags["--hour"];
144
+ if (dayFlag === void 0 && hourFlag === void 0) {
145
+ const status = await fetchMaintenance(client, projectId);
146
+ if (!status) fail("This control plane does not schedule database changes yet.", void 0, "unsupported");
147
+ emit(() => {
148
+ console.log("");
149
+ keyValues([
150
+ ["Window", status.window.label],
151
+ ["Next", new Date(status.window.nextAt).toUTCString()],
152
+ ["Waiting", describePending(status.open) ?? chalk.gray("nothing")]
153
+ ]);
154
+ console.log("");
155
+ noteBlank();
156
+ note("Move it with:");
157
+ note(chalk.cyan(" rebase cloud compute window --day sun --hour 3"));
158
+ console.log("");
159
+ }, {
160
+ window: status.window,
161
+ open: status.open
162
+ });
163
+ return;
164
+ }
165
+ if (dayFlag === void 0 || hourFlag === void 0) fail("Give both --day and --hour.", "e.g. `rebase cloud compute window --day sun --hour 3` (UTC)", "bad_request");
166
+ const day = parseDay(dayFlag);
167
+ if (day === void 0) fail(`--day ${dayFlag} is not a day.`, "Use sun, mon, … sat, or 0 (Sunday) to 6.", "bad_request");
168
+ if (!Number.isInteger(hourFlag) || hourFlag < 0 || hourFlag > 23) fail(`--hour ${String(hourFlag)} is not an hour.`, "Use 0 to 23, in UTC.", "bad_request");
169
+ let res;
170
+ try {
171
+ res = await client.functions.invoke("maintenance", {
172
+ day,
173
+ hour: hourFlag
174
+ }, {
175
+ method: "PUT",
176
+ path: `projects/${encodeURIComponent(projectId)}/window`
177
+ });
178
+ } catch (error) {
179
+ reportError(error, "Could not move the maintenance window");
180
+ }
181
+ emit(() => success(`Maintenance window: ${res?.window?.label ?? `${DAYS[day]} ${hourFlag}:00 UTC`}.`), { window: res?.window ?? {
182
+ day,
183
+ hour: hourFlag
184
+ } });
185
+ }
186
+ var SEVERITY_DOT = {
187
+ warning: chalk.yellow("●"),
188
+ notice: chalk.blue("●"),
189
+ info: chalk.gray("●")
190
+ };
191
+ async function eventsCommand(rawArgs) {
192
+ const { flags } = parseCloudArgs({
193
+ spec: EVENTS_FLAGS,
194
+ rawArgs,
195
+ commandWords: 2,
196
+ command: "cloud events",
197
+ maxPositionals: 0
198
+ });
199
+ const { client } = await requireClient(rawArgs);
200
+ const projectId = await requireProject(rawArgs, client);
201
+ const limit = Math.min(200, Math.max(1, flags["--limit"] ?? 20));
202
+ let events = [];
203
+ try {
204
+ events = (await client.functions.invoke("maintenance", void 0, {
205
+ method: "GET",
206
+ path: `projects/${encodeURIComponent(projectId)}/events?limit=${limit}`
207
+ })).events ?? [];
208
+ } catch (error) {
209
+ reportError(error, "Could not read the project's events");
210
+ }
211
+ emit(() => {
212
+ console.log("");
213
+ if (events.length === 0) {
214
+ note("Nothing has happened yet. Scaling, database changes and failovers appear here.");
215
+ console.log("");
216
+ return;
217
+ }
218
+ for (const e of events) {
219
+ const when = new Date(e.at).toLocaleString();
220
+ console.log(` ${SEVERITY_DOT[e.severity] ?? SEVERITY_DOT.info} ${chalk.bold(e.title)} ${chalk.gray(when)}${e.emailed ? chalk.gray(" · emailed") : ""}`);
221
+ if (e.body) note(` ${e.body}`);
222
+ }
223
+ console.log("");
224
+ }, { events });
225
+ }
22
226
  /**
23
227
  * The remedy for a step that needs a terminal when there is none: a token,
24
228
  * which needs neither a password nor a code. Minted in the console because a
@@ -1215,14 +1419,15 @@ async function statusCommand(rawArgs) {
1215
1419
  try {
1216
1420
  const project = await client.data.collection("projects").findById(projectId);
1217
1421
  if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
1218
- const [db, storage, deploy, baseDomain] = await Promise.all([
1422
+ const [db, storage, deploy, baseDomain, maintenance] = await Promise.all([
1219
1423
  firstRow(client, "databases", projectId),
1220
1424
  client.functions.invoke("storage-provision", void 0, {
1221
1425
  method: "GET",
1222
1426
  path: projectId
1223
1427
  }).catch(() => void 0),
1224
1428
  latestDeployment(client, projectId),
1225
- fetchTenantBaseDomain(client, url)
1429
+ fetchTenantBaseDomain(client, url),
1430
+ fetchMaintenance(client, projectId)
1226
1431
  ]);
1227
1432
  const storageLine = describeStorageState(storage);
1228
1433
  const databaseLine = describeDatabaseState(db);
@@ -1245,6 +1450,7 @@ async function statusCommand(rawArgs) {
1245
1450
  ["Runtime", describeRuntime(project)],
1246
1451
  ["Database", databaseLine],
1247
1452
  ["Storage", storageLine],
1453
+ ["Maintenance", describePending(maintenance?.open)],
1248
1454
  ["Claim URL", grant ? chalk.bold(grant.claimUrl) : void 0],
1249
1455
  ["Expires", grant ? `${new Date(grant.expiresAt).toLocaleString()} unless claimed, then deleted` : void 0]
1250
1456
  ]);
@@ -1285,6 +1491,10 @@ async function statusCommand(rawArgs) {
1285
1491
  connectionStatus: db.connectionStatus ?? null
1286
1492
  } : null,
1287
1493
  storage: storage ?? null,
1494
+ maintenance: maintenance ? {
1495
+ window: maintenance.window,
1496
+ pending: maintenance.open
1497
+ } : null,
1288
1498
  unclaimed: grant ? {
1289
1499
  claimUrl: grant.claimUrl,
1290
1500
  expiresAt: grant.expiresAt,
@@ -2165,7 +2375,12 @@ async function billingCommand(rawArgs) {
2165
2375
  * The action words `rebase cloud compute` dispatches. No word, or `show`,
2166
2376
  * prints the dials and the quote.
2167
2377
  */
2168
- var COMPUTE_ACTIONS = ["show", "set"];
2378
+ var COMPUTE_ACTIONS = [
2379
+ "show",
2380
+ "set",
2381
+ "apply",
2382
+ "window"
2383
+ ];
2169
2384
  /** The dials, and the flag that sets each. */
2170
2385
  var DIAL_FLAGS = {
2171
2386
  "--cpu": "cpu",
@@ -2177,7 +2392,9 @@ var DIAL_FLAGS = {
2177
2392
  "--db-memory": "databaseMemory",
2178
2393
  "--storage": "storageMode",
2179
2394
  "--autoscale-max": "autoscaleMaxReplicas",
2180
- "--autoscale-cpu-target": "autoscaleTargetCpuPercent"
2395
+ "--autoscale-cpu-target": "autoscaleTargetCpuPercent",
2396
+ "--db-autoscale-max-cpu": "dbAutoscaleMaxCpu",
2397
+ "--db-autoscale-max-memory": "dbAutoscaleMaxMemory"
2181
2398
  };
2182
2399
  /**
2183
2400
  * The flags `resources set` accepts, in the shape a spec is written in.
@@ -2193,7 +2410,8 @@ var DIAL_FLAGS = {
2193
2410
  */
2194
2411
  var COMPUTE_SET_FLAGS = {
2195
2412
  ...Object.fromEntries(Object.keys(DIAL_FLAGS).map((flag) => [flag, String])),
2196
- "--no-autoscale": Boolean
2413
+ "--no-autoscale": Boolean,
2414
+ "--no-db-autoscale": Boolean
2197
2415
  };
2198
2416
  /**
2199
2417
  * The flag that used to set `scaleToZero`. Still parsed, so a script that passes
@@ -2236,6 +2454,8 @@ var BOOLEAN_DIALS = /* @__PURE__ */ new Set(["preemptible"]);
2236
2454
  */
2237
2455
  async function computeCommand(action, rawArgs) {
2238
2456
  requireKnownAction("compute", action, COMPUTE_ACTIONS);
2457
+ if (action === "apply") return computeApplyCommand(rawArgs);
2458
+ if (action === "window") return computeWindowCommand(rawArgs);
2239
2459
  parseCloudArgs({
2240
2460
  spec: action === "set" ? {
2241
2461
  ...COMPUTE_SET_FLAGS,
@@ -2252,6 +2472,7 @@ async function computeCommand(action, rawArgs) {
2252
2472
  if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`, void 0, "not_found");
2253
2473
  if (action !== "set") {
2254
2474
  let quote;
2475
+ const maintenance = await fetchMaintenance(client, projectId);
2255
2476
  try {
2256
2477
  quote = await client.functions.invoke("pricing", project, {
2257
2478
  method: "POST",
@@ -2277,8 +2498,11 @@ async function computeCommand(action, rawArgs) {
2277
2498
  ["Database instances", dialLine(project.databaseInstances)],
2278
2499
  ["Database CPU", dialLine(project.databaseCpu)],
2279
2500
  ["Database memory", dialLine(project.databaseMemory)],
2501
+ ["Database autoscaling", project.dbAutoscaleMaxCpu || project.dbAutoscaleMaxMemory ? `up to ${[project.dbAutoscaleMaxCpu ? `${String(project.dbAutoscaleMaxCpu)} CPU` : null, project.dbAutoscaleMaxMemory ? `${String(project.dbAutoscaleMaxMemory)} memory` : null].filter(Boolean).join(", ")}` : chalk.gray("off")],
2280
2502
  ["Object storage", dialLine(project.storageMode)],
2281
- ["Per month", quote ? `€${quote.totalEur.toFixed(2)}` : void 0]
2503
+ ["Per month", quote ? `€${quote.totalEur.toFixed(2)}` : void 0],
2504
+ ["Waiting", describePending(maintenance?.open)],
2505
+ ["Maintenance window", maintenance?.window.label]
2282
2506
  ]);
2283
2507
  if (quote) {
2284
2508
  console.log("");
@@ -2305,7 +2529,13 @@ async function computeCommand(action, rawArgs) {
2305
2529
  databaseInstances: project.databaseInstances ?? null,
2306
2530
  databaseCpu: project.databaseCpu ?? null,
2307
2531
  databaseMemory: project.databaseMemory ?? null,
2308
- storageMode: project.storageMode ?? null
2532
+ dbAutoscaleMaxCpu: project.dbAutoscaleMaxCpu ?? null,
2533
+ dbAutoscaleMaxMemory: project.dbAutoscaleMaxMemory ?? null,
2534
+ storageMode: project.storageMode ?? null,
2535
+ maintenance: maintenance ? {
2536
+ window: maintenance.window,
2537
+ pending: maintenance.open
2538
+ } : null
2309
2539
  });
2310
2540
  return;
2311
2541
  }
@@ -2318,14 +2548,23 @@ async function computeCommand(action, rawArgs) {
2318
2548
  reportError(error, "Could not change resources");
2319
2549
  return;
2320
2550
  }
2551
+ const maintenance = await fetchMaintenance(client, projectId);
2321
2552
  emit(() => {
2322
2553
  success("Resources updated.");
2323
2554
  noteBlank();
2324
2555
  for (const [field, value] of Object.entries(patch)) note(` ${field} → ${String(value)}`);
2325
2556
  noteBlank();
2326
2557
  note("Applied now: the app rolls its pods and your subscription is prorated from today.");
2327
- note("A change that restarts the database waits for a maintenance window.");
2328
- }, { updated: patch });
2558
+ const pending = describePending(maintenance?.open);
2559
+ if (pending) {
2560
+ note(`Scheduled: ${pending}.`);
2561
+ if (maintenance?.open?.expectedImpact) note(` ${maintenance.open.expectedImpact}. Billed at the current size until then.`);
2562
+ note(` Apply it sooner with ${chalk.cyan("rebase cloud compute apply")}, or move the window with ${chalk.cyan("rebase cloud compute window")}.`);
2563
+ }
2564
+ }, {
2565
+ updated: patch,
2566
+ maintenance: maintenance?.open ?? null
2567
+ });
2329
2568
  }
2330
2569
  /**
2331
2570
  * A dial's value, or a marker that the platform default decides it.
@@ -2353,6 +2592,10 @@ function buildDialPatch(rawArgs, opts) {
2353
2592
  patch.autoscaleMaxReplicas = null;
2354
2593
  patch.autoscaleTargetCpuPercent = null;
2355
2594
  }
2595
+ if (switchOn(rawArgs, "--no-db-autoscale")) {
2596
+ patch.dbAutoscaleMaxCpu = null;
2597
+ patch.dbAutoscaleMaxMemory = null;
2598
+ }
2356
2599
  const retired = rawArgs.indexOf(RETIRED_SCALE_TO_ZERO);
2357
2600
  if (retired !== -1) {
2358
2601
  const value = rawArgs[retired + 1];
@@ -2391,7 +2634,7 @@ function buildDialPatch(rawArgs, opts) {
2391
2634
  }
2392
2635
  if (opts?.requireOne !== false && Object.keys(patch).length === 0) return {
2393
2636
  patch: {},
2394
- error: `Nothing to set. Pass one of: ${Object.keys(DIAL_FLAGS).join(", ")}, --no-autoscale.`
2637
+ error: `Nothing to set. Pass one of: ${Object.keys(DIAL_FLAGS).join(", ")}, --no-autoscale, --no-db-autoscale.`
2395
2638
  };
2396
2639
  return { patch };
2397
2640
  }
@@ -2638,6 +2881,164 @@ function pipeThroughTunnel(socket, endpoint, token) {
2638
2881
  socket.on("error", () => closeBoth());
2639
2882
  }
2640
2883
  //#endregion
2884
+ //#region src/commands/cloud/db-access.ts
2885
+ /**
2886
+ * `rebase cloud db access` — read-only access to the managed database from
2887
+ * named addresses outside the platform, for a tool that cannot run a tunnel: a
2888
+ * hosted BI dashboard, a notebook service, a warehouse loader.
2889
+ *
2890
+ * db access What is open, to whom, and how to connect
2891
+ * db access enable --allow … Open it (or change who and what): the whole desired state
2892
+ * db access disable Close it, and drop the role
2893
+ * db access reveal The read-only role's password and a connection URL
2894
+ *
2895
+ * The control plane's `db-access` function does the work; how it keeps this
2896
+ * read-only and to the named addresses is documented there.
2897
+ */
2898
+ var DB_ACCESS_ACTIONS = [
2899
+ "status",
2900
+ "enable",
2901
+ "disable",
2902
+ "reveal"
2903
+ ];
2904
+ var DB_ACCESS_FLAGS = {
2905
+ "--allow": [String],
2906
+ "--schemas": [String],
2907
+ "--tables": [String],
2908
+ "--ca-out": String
2909
+ };
2910
+ /** Repeated or comma-separated, either way. */
2911
+ function list(values) {
2912
+ if (!values) return void 0;
2913
+ const out = values.flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
2914
+ return out.length > 0 ? out : void 0;
2915
+ }
2916
+ function writeCa(path, pem) {
2917
+ if (!path) return void 0;
2918
+ if (!pem) fail("The database's CA certificate is not available yet.", "Try again in a minute.", "ca_unavailable");
2919
+ fs$1.writeFileSync(path, pem);
2920
+ return path;
2921
+ }
2922
+ function printStatus$1(status, projectRef, caPath) {
2923
+ console.log("");
2924
+ console.log(chalk.bold(` 🔓 External database access — project ${projectRef}`));
2925
+ console.log("");
2926
+ if (!status.enabled) {
2927
+ console.log(chalk.gray(" Off. The database is reachable only from inside the platform and through"));
2928
+ console.log(chalk.gray(" `rebase cloud db connect`. To let a tool connect from its own address:"));
2929
+ console.log("");
2930
+ console.log(` ${chalk.cyan("rebase cloud db access enable --allow <ip>")}`);
2931
+ console.log("");
2932
+ return;
2933
+ }
2934
+ keyValues([
2935
+ ["Host", status.host ?? chalk.yellow("allocating…")],
2936
+ ["Port", String(status.port)],
2937
+ ["Database", status.database],
2938
+ ["Username", status.username],
2939
+ ["Password", chalk.gray("hidden — `rebase cloud db access reveal`")],
2940
+ ["TLS", `required (${status.sslmode} with the cluster CA)`],
2941
+ ["Allowed from", status.allow.join(", ")],
2942
+ ["Reads", [...status.schemas.map((s) => `${s}.*`), ...status.tables].join(", ")],
2943
+ ["Connections", status.connectionLimit === void 0 ? void 0 : `up to ${status.connectionLimit} at once`],
2944
+ ["CA written to", caPath]
2945
+ ]);
2946
+ if (status.pending) {
2947
+ console.log("");
2948
+ console.log(chalk.yellow(` ${status.pending}`));
2949
+ }
2950
+ console.log("");
2951
+ }
2952
+ async function dbAccessCommand(rawArgs) {
2953
+ const { flags, positionals } = parseCloudArgs({
2954
+ spec: DB_ACCESS_FLAGS,
2955
+ rawArgs,
2956
+ commandWords: 3,
2957
+ command: "cloud db access",
2958
+ maxPositionals: 1
2959
+ });
2960
+ const action = positionals[0] || "status";
2961
+ requireKnownAction("db access", action, DB_ACCESS_ACTIONS);
2962
+ if (action !== "enable" && (flags["--allow"] || flags["--schemas"] || flags["--tables"])) fail("--allow, --schemas and --tables go with `enable`.", "Run `rebase cloud db access --help`.", "invalid_flags");
2963
+ const { client } = await requireClient(rawArgs);
2964
+ const projectId = await requireProject(rawArgs, client);
2965
+ const projectRef = displayProjectRef(rawArgs);
2966
+ try {
2967
+ if (action === "status") {
2968
+ const status = await client.functions.invoke("db-access", void 0, {
2969
+ method: "GET",
2970
+ path: projectId
2971
+ });
2972
+ const caPath = status.enabled ? writeCa(flags["--ca-out"], status.caCertificate) : void 0;
2973
+ emit(() => printStatus$1(status, projectRef, caPath), {
2974
+ projectId,
2975
+ ...status
2976
+ });
2977
+ return;
2978
+ }
2979
+ if (action === "enable") {
2980
+ const allow = list(flags["--allow"]);
2981
+ if (!allow) fail("Name the addresses the database may be reached from.", "e.g. --allow 34.89.253.13 (repeat it, or separate with commas).", "missing_allow");
2982
+ const status = await client.functions.invoke("db-access", {
2983
+ allow,
2984
+ schemas: list(flags["--schemas"]),
2985
+ tables: list(flags["--tables"])
2986
+ }, {
2987
+ method: "PUT",
2988
+ path: projectId
2989
+ });
2990
+ const caPath = writeCa(flags["--ca-out"], status.caCertificate);
2991
+ emit(() => {
2992
+ success(`External read-only access is on for ${status.allow.join(", ")}.`);
2993
+ printStatus$1(status, projectRef, caPath);
2994
+ console.log(chalk.gray(" Get the password and a ready connection URL with `rebase cloud db access reveal`."));
2995
+ console.log("");
2996
+ }, {
2997
+ projectId,
2998
+ ...status
2999
+ });
3000
+ return;
3001
+ }
3002
+ if (action === "disable") {
3003
+ await confirmDestructive({
3004
+ yes: Boolean(flags["--yes"]),
3005
+ prompt: "Close external access? Tools connected with the read-only role will stop working, and its password is deleted."
3006
+ });
3007
+ emit(() => success("External access is off, and the read-only role is dropped."), {
3008
+ projectId,
3009
+ ...await client.functions.invoke("db-access", void 0, {
3010
+ method: "DELETE",
3011
+ path: projectId
3012
+ })
3013
+ });
3014
+ return;
3015
+ }
3016
+ const revealed = await client.functions.invoke("db-access", void 0, {
3017
+ method: "POST",
3018
+ path: `${projectId}/reveal`
3019
+ });
3020
+ const caPath = writeCa(flags["--ca-out"], revealed.caCertificate);
3021
+ emit(() => {
3022
+ console.log("");
3023
+ keyValues([
3024
+ ["Host", revealed.host ?? chalk.yellow("allocating…")],
3025
+ ["Username", revealed.username],
3026
+ ["Password", revealed.password],
3027
+ ["Connection", revealed.connectionString ?? void 0],
3028
+ ["CA written to", caPath]
3029
+ ]);
3030
+ console.log("");
3031
+ if (!caPath) console.log(chalk.gray(" For sslmode=verify-ca, save the CA with --ca-out <file> and pass it as sslrootcert."));
3032
+ console.log("");
3033
+ }, {
3034
+ projectId,
3035
+ ...revealed
3036
+ });
3037
+ } catch (e) {
3038
+ reportError(e, `Failed to ${action === "status" ? "read" : action} external database access`);
3039
+ }
3040
+ }
3041
+ //#endregion
2641
3042
  //#region src/commands/cloud/databases.ts
2642
3043
  /** The filename a backup is restored and downloaded by. */
2643
3044
  function backupName(row) {
@@ -2663,6 +3064,9 @@ async function dbCommand(subcommand, rawArgs) {
2663
3064
  case "connect":
2664
3065
  await dbConnect(rawArgs);
2665
3066
  break;
3067
+ case "access":
3068
+ await dbAccessCommand(rawArgs);
3069
+ break;
2666
3070
  case "test":
2667
3071
  await testDatabase(rawArgs);
2668
3072
  break;
@@ -3264,6 +3668,17 @@ function printDbHelp() {
3264
3668
  section: "Database",
3265
3669
  description: "Test database connectivity"
3266
3670
  },
3671
+ {
3672
+ action: "access",
3673
+ section: "Database",
3674
+ description: "Read-only access from named addresses, for a BI or analytics tool (status|enable|disable|reveal)",
3675
+ flags: [
3676
+ ["--allow <ip|cidr>", "With enable: an address the database may be reached from. Repeatable"],
3677
+ ["--schemas <name>", "With enable: schemas to read whole. Default: public"],
3678
+ ["--tables <schema.table>", "With enable: single tables to read as well. Repeatable"],
3679
+ ["--ca-out <file>", "Write the cluster's CA certificate, for sslmode=verify-ca"]
3680
+ ]
3681
+ },
3267
3682
  {
3268
3683
  action: "backup list",
3269
3684
  section: "Backups",
@@ -13380,6 +13795,30 @@ var ACTION_HELP = {
13380
13795
  ],
13381
13796
  notes: ["`restore` replaces the live database. Nothing about it is undoable from here — `--yes`, the global flag listed below, is what skips that confirmation.", "Backups are the project's own: a base backup on a schedule, plus continuous WAL archiving for point-in-time recovery."]
13382
13797
  },
13798
+ "db access": {
13799
+ command: "cloud db access",
13800
+ usage: "cloud db access [status|enable|disable|reveal] [--allow <ip|cidr>]... [--schemas <name>]... [--tables <schema.table>]... [--ca-out <file>] [--yes]",
13801
+ summary: "Let a tool that cannot run a tunnel — a hosted BI dashboard, a notebook, a warehouse loader — read the managed database from its own address. `enable` creates a read-only role, a load balancer that admits only the addresses you name, and requires TLS; the role reads the schemas and tables you choose and nothing else. `enable` takes the whole desired state, so running it again with other addresses replaces them. `reveal` prints the role's password and a connection URL. `status` is the default.",
13802
+ flags: [
13803
+ ["--allow <ip|cidr>", "An IPv4 address or range the database may be reached from (at most a /16). Repeatable, or comma-separated"],
13804
+ ["--schemas <name>", "Schemas the role reads whole, tables created later included. Default: public"],
13805
+ ["--tables <schema.table>", "Single tables the role reads as well, e.g. rebase.cron_logs. Repeatable"],
13806
+ ["--ca-out <file>", "Write the cluster's CA certificate here, to verify the server with sslmode=verify-ca"]
13807
+ ],
13808
+ examples: [
13809
+ "rebase cloud db access enable --allow 34.89.253.13",
13810
+ "rebase cloud db access enable --allow 34.89.253.13 --tables rebase.metric_samples,rebase.cron_logs",
13811
+ "rebase cloud db access reveal --ca-out db-ca.pem",
13812
+ "rebase cloud db access disable --yes"
13813
+ ],
13814
+ notes: [
13815
+ "Owner or admin only, as for the database password. Every change and every reveal is in `rebase cloud activity`.",
13816
+ "The `rebase` schema holds users, password hashes and session tokens: it is never granted whole, and its credential tables never at all.",
13817
+ "Managed databases on GCP capacity only for now. Each project with access on has its own network load balancer, which is billed.",
13818
+ "The role holds up to 25 connections at once — enough for a dashboard that loads its widgets in parallel, one connection per query — and the app keeps the rest. A tool that opens more is refused the extra ones.",
13819
+ "`disable` closes the address, drops the role and deletes its password. `--yes`, the global flag listed below, skips the confirmation."
13820
+ ]
13821
+ },
13383
13822
  "db pitr": {
13384
13823
  command: "cloud db pitr",
13385
13824
  usage: "cloud db pitr <status|restore|cutover|discard> [--target <timestamp>] [--yes]",
@@ -13658,15 +14097,46 @@ var ACTION_HELP = {
13658
14097
  },
13659
14098
  compute: {
13660
14099
  command: "cloud compute",
13661
- usage: "cloud compute [set] [options]",
14100
+ usage: "cloud compute [set|apply|window] [options]",
13662
14101
  summary: "What this project reserves, and what the control plane would invoice for it. Bare, it prints every dial and an itemised €/month; `set` changes one. An empty dial means the platform default, which moves when the default moves — a dial pinned to the same number does not.",
13663
14102
  flags: [],
13664
14103
  examples: [
13665
14104
  "rebase cloud compute",
13666
14105
  "rebase cloud compute --json",
13667
- "rebase cloud compute set --help"
14106
+ "rebase cloud compute set --help",
14107
+ "rebase cloud compute apply",
14108
+ "rebase cloud compute window --day sun --hour 3"
13668
14109
  ],
13669
- notes: ["The price is the control plane's own quote for these dials, itemised line by line — not a tier, and not a number this CLI computes."]
14110
+ notes: ["The price is the control plane's own quote for these dials, itemised line by line — not a tier, and not a number this CLI computes.", "`Waiting` is a database change a `set` scheduled for the maintenance window and has not applied yet; the project is billed at the size it runs until then."]
14111
+ },
14112
+ "compute apply": {
14113
+ command: "cloud compute apply",
14114
+ usage: "cloud compute apply [--yes]",
14115
+ summary: "Apply the database change this project is waiting on now, instead of in its maintenance window. The database restarts first and the app after it; with one database instance it is unavailable for about one to three minutes, with a standby for a few seconds.",
14116
+ flags: [],
14117
+ examples: ["rebase cloud compute apply", "rebase cloud compute apply --yes --json"],
14118
+ notes: [
14119
+ "Asks before restarting anything; `--yes` skips the question, and is required off a terminal.",
14120
+ "Needs the organization's owner or admin role.",
14121
+ "Nothing waiting is not an error: it says so and exits 0.",
14122
+ "Follow it with `rebase cloud events`."
14123
+ ]
14124
+ },
14125
+ "compute window": {
14126
+ command: "cloud compute window",
14127
+ usage: "cloud compute window [--day <day> --hour <0-23>]",
14128
+ summary: "The weekly hour in which changes that restart the database are applied, in UTC. Bare, it prints the window and what is waiting for it; with both flags it moves the window, and anything waiting moves with it.",
14129
+ flags: [["--day <day>", "sun, mon, … sat, or 0 (Sunday) to 6"], ["--hour <0-23>", "The hour it opens, in UTC"]],
14130
+ examples: ["rebase cloud compute window", "rebase cloud compute window --day sat --hour 2"],
14131
+ notes: ["The default is Sunday at 03:00 UTC. You are emailed 24 hours before anything is applied in it."]
14132
+ },
14133
+ events: {
14134
+ command: "cloud events",
14135
+ usage: "cloud events [--limit <n>]",
14136
+ summary: "What happened to this project's backend, newest first: the app scaling, database changes scheduled and applied, a standby taking over, the disk growing. Problems are alerts; this is the record.",
14137
+ flags: [["--limit <n>", "How many, 1–200. Default: 20"]],
14138
+ examples: ["rebase cloud events", "rebase cloud events --limit 100 --json"],
14139
+ notes: ["Lines that were also emailed to the organization say so."]
13670
14140
  },
13671
14141
  "compute set": {
13672
14142
  command: "cloud compute set",
@@ -13683,16 +14153,20 @@ var ACTION_HELP = {
13683
14153
  ["--storage <mode>", "Object storage: shared-prefix or dedicated-bucket"],
13684
14154
  ["--autoscale-max <n>", "1–16. The ceiling the app may reach, and the worst case it may be billed"],
13685
14155
  ["--autoscale-cpu-target <pct>", "10–95. CPU utilisation the autoscaler holds, against the request. Default: 70"],
13686
- ["--no-autoscale", "Turn autoscaling off. The only way to: a ceiling at or below --replicas is refused"]
14156
+ ["--no-autoscale", "Turn autoscaling off. The only way to: a ceiling at or below --replicas is refused"],
14157
+ ["--db-autoscale-max-cpu <n>", "Let the database grow its CPU on its own under sustained load, up to this, e.g. 2. Unset: off"],
14158
+ ["--db-autoscale-max-memory <size>", "Let it grow its memory under load or connection pressure, up to this, e.g. 8Gi. Unset: off"],
14159
+ ["--no-db-autoscale", "Turn database autoscaling off"]
13687
14160
  ],
13688
14161
  examples: [
13689
14162
  "rebase cloud compute set --cpu 500m --memory 2Gi",
13690
14163
  "rebase cloud compute set --replicas 2 --autoscale-max 6",
13691
- "rebase cloud compute set --db-instances 2 --db-memory 4Gi"
14164
+ "rebase cloud compute set --db-instances 2 --db-memory 4Gi",
14165
+ "rebase cloud compute set --db-autoscale-max-cpu 2 --db-autoscale-max-memory 8Gi"
13692
14166
  ],
13693
14167
  notes: [
13694
14168
  "Run `rebase cloud compute` first — it prints the current dials and the €/month this project is quoted.",
13695
- "Applied immediately: the app rolls its pods and the subscription is prorated from today. A change that restarts the database waits for a maintenance window.",
14169
+ "Applied immediately: the app rolls its pods and the subscription is prorated from today. A change that restarts the database is scheduled for the project's maintenance window, billed from when it is applied; apply it sooner with `rebase cloud compute apply`.",
13696
14170
  "The valid ranges are the target cluster's, not this CLI's — GKE Autopilot bills a 250m/512Mi floor and rewrites a memory:CPU ratio outside 1:1–6.5:1, a Hetzner node has neither constraint. The control plane refuses what it cannot honour and names the field."
13697
14171
  ]
13698
14172
  },
@@ -13998,6 +14472,7 @@ var CLOUD_VALUE_FLAGS = {
13998
14472
  "--access-key-id": String,
13999
14473
  "--action": String,
14000
14474
  "--actor": String,
14475
+ "--allow": String,
14001
14476
  "--autoscale-cpu-target": String,
14002
14477
  "--autoscale-max": String,
14003
14478
  "--backup-access-key-id": String,
@@ -14009,11 +14484,15 @@ var CLOUD_VALUE_FLAGS = {
14009
14484
  "--branch": String,
14010
14485
  "--bucket": String,
14011
14486
  "--bundle-dir": String,
14487
+ "--ca-out": String,
14012
14488
  "--can": String,
14013
14489
  "--collection": String,
14014
14490
  "--connection-string": String,
14015
14491
  "--cpu": String,
14492
+ "--day": String,
14016
14493
  "--db": String,
14494
+ "--db-autoscale-max-cpu": String,
14495
+ "--db-autoscale-max-memory": String,
14017
14496
  "--db-cpu": String,
14018
14497
  "--db-instances": String,
14019
14498
  "--db-memory": String,
@@ -14025,6 +14504,7 @@ var CLOUD_VALUE_FLAGS = {
14025
14504
  "--function": String,
14026
14505
  "--grep": String,
14027
14506
  "--host": String,
14507
+ "--hour": String,
14028
14508
  "--ingress-address": String,
14029
14509
  "--kubeconfig": String,
14030
14510
  "--level": String,
@@ -14051,6 +14531,7 @@ var CLOUD_VALUE_FLAGS = {
14051
14531
  "--repository": String,
14052
14532
  "--role": String,
14053
14533
  "--scale-to-zero": String,
14534
+ "--schemas": String,
14054
14535
  "--secret-access-key": String,
14055
14536
  "--since": String,
14056
14537
  "--slug": String,
@@ -14059,6 +14540,7 @@ var CLOUD_VALUE_FLAGS = {
14059
14540
  "--storage": String,
14060
14541
  "--subdomain": String,
14061
14542
  "--tail": String,
14543
+ "--tables": String,
14062
14544
  "--target": String,
14063
14545
  "--timeout": String,
14064
14546
  "--type": String,
@@ -14278,6 +14760,9 @@ async function cloudCommand(subcommand, rawArgs) {
14278
14760
  case "compute":
14279
14761
  await computeCommand(action, rawArgs);
14280
14762
  break;
14763
+ case "events":
14764
+ await eventsCommand(rawArgs);
14765
+ break;
14281
14766
  case "resources":
14282
14767
  if (action === "set") fail("`rebase cloud resources set` is now `rebase cloud compute set` — CPU, memory, replicas and cost.", "`rebase cloud resources` lists what this project declares against what the platform provisioned.", "renamed");
14283
14768
  await declaredResourcesCommand(action, rawArgs);
@@ -14568,6 +15053,11 @@ var CLOUD_GROUPS = [
14568
15053
  section: "Other resources",
14569
15054
  description: "What this project reserves, what it costs, and how to change it"
14570
15055
  },
15056
+ {
15057
+ action: "events",
15058
+ section: "Other resources",
15059
+ description: "What happened to the backend: scaling, database changes, failovers"
15060
+ },
14571
15061
  {
14572
15062
  action: "clusters",
14573
15063
  section: "Other resources",
@@ -14603,4 +15093,4 @@ function printCloudHelp() {
14603
15093
  //#endregion
14604
15094
  export { CLOUD_GROUP_NAMES, GROUP_ALIASES, cloudCommand };
14605
15095
 
14606
- //# sourceMappingURL=cloud-CXyZobBh.js.map
15096
+ //# sourceMappingURL=cloud-CFotGK2-.js.map