@rebasepro/cli 0.25.0-canary.ge06257e → 0.25.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.
Files changed (142) hide show
  1. package/bin/rebase.js +9 -5
  2. package/dist/{agent-setup-C83DXnlx.js → agent-setup-BYb2Tbdz.js} +2 -2
  3. package/dist/{agent-setup-C83DXnlx.js.map → agent-setup-BYb2Tbdz.js.map} +1 -1
  4. package/dist/{api-keys-Bc4FJKYp.js → api-keys-CSMbsmAn.js} +28 -22
  5. package/dist/api-keys-CSMbsmAn.js.map +1 -0
  6. package/dist/{apps-wG-ZTryA.js → apps-iBXNZhVN.js} +6 -7
  7. package/dist/{apps-wG-ZTryA.js.map → apps-iBXNZhVN.js.map} +1 -1
  8. package/dist/{atlas-dev-database-DeK3Sa4h.js → atlas-dev-database-BusbHP6n.js} +4 -4
  9. package/dist/{atlas-dev-database-DeK3Sa4h.js.map → atlas-dev-database-BusbHP6n.js.map} +1 -1
  10. package/dist/{auth-BL7bNQVu.js → auth-DRsTWPky.js} +77 -11
  11. package/dist/auth-DRsTWPky.js.map +1 -0
  12. package/dist/{branch-pointer-DTQNLFtb.js → branch-pointer-Bn_FjNld.js} +1 -1
  13. package/dist/{build-h_7Re-67.js → build-et7Rccxi.js} +6 -7
  14. package/dist/{build-h_7Re-67.js.map → build-et7Rccxi.js.map} +1 -1
  15. package/dist/{bundle-CqURVN-K.js → bundle-DlqkDYSe.js} +6 -21
  16. package/dist/bundle-DlqkDYSe.js.map +1 -0
  17. package/dist/{cloud-DVV_5GPG.js → cloud-B-ZIjHrA.js} +10 -11
  18. package/dist/{cloud-DVV_5GPG.js.map → cloud-B-ZIjHrA.js.map} +1 -1
  19. package/dist/commands/api-keys.d.ts +4 -1
  20. package/dist/commands/auth.d.ts +3 -2
  21. package/dist/commands/dev.d.ts +12 -0
  22. package/dist/commands/generate_sdk.d.ts +4 -2
  23. package/dist/commands/init.d.ts +20 -0
  24. package/dist/commands/start.d.ts +10 -0
  25. package/dist/commands/upgrade.d.ts +12 -0
  26. package/dist/connection-banner-DbLJzWf4.js +128 -0
  27. package/dist/connection-banner-DbLJzWf4.js.map +1 -0
  28. package/dist/{consent-ClRHmcxf.js → consent-BaB-eQKG.js} +2 -2
  29. package/dist/{consent-ClRHmcxf.js.map → consent-BaB-eQKG.js.map} +1 -1
  30. package/dist/{console-Dw3HLdUs.js → console-BlD9kjFW.js} +4 -4
  31. package/dist/{console-Dw3HLdUs.js.map → console-BlD9kjFW.js.map} +1 -1
  32. package/dist/{context-BM-oOMNX.js → context-DHiiiJ5C.js} +3 -4
  33. package/dist/context-DHiiiJ5C.js.map +1 -0
  34. package/dist/{daemon-CknkDjd6.js → daemon-DDMRbz4T.js} +160 -5
  35. package/dist/daemon-DDMRbz4T.js.map +1 -0
  36. package/dist/{daemon-entry-C6pxdily.js → daemon-entry-zOC1revO.js} +204 -5
  37. package/dist/daemon-entry-zOC1revO.js.map +1 -0
  38. package/dist/{db-Dkn9XhT-.js → db-9P6MnmdC.js} +237 -86
  39. package/dist/db-9P6MnmdC.js.map +1 -0
  40. package/dist/{derive-Dl0z2OWi.js → derive-MTdClnkc.js} +29 -14
  41. package/dist/{derive-Dl0z2OWi.js.map → derive-MTdClnkc.js.map} +1 -1
  42. package/dist/{dev-DAcZR4Pp.js → dev-BDN_OKXA.js} +183 -23
  43. package/dist/dev-BDN_OKXA.js.map +1 -0
  44. package/dist/dev-db/connection-banner.d.ts +47 -0
  45. package/dist/dev-db/daemon.d.ts +41 -0
  46. package/dist/dev-db/notification-proxy.d.ts +82 -1
  47. package/dist/dev-db/pull.d.ts +33 -5
  48. package/dist/dev-db/state.d.ts +9 -0
  49. package/dist/{dev-preflight-CorMg7Ub.js → dev-preflight-FT9GbJVj.js} +73 -4
  50. package/dist/dev-preflight-FT9GbJVj.js.map +1 -0
  51. package/dist/{dev-server-B1UYifZJ.js → dev-server-CIZwAfZa.js} +14 -3
  52. package/dist/dev-server-CIZwAfZa.js.map +1 -0
  53. package/dist/{doctor-Ds_lzc9p.js → doctor-D8YXz7df.js} +6 -6
  54. package/dist/doctor-D8YXz7df.js.map +1 -0
  55. package/dist/{eject-CJHkfnat.js → eject-izG2KjMo.js} +3 -4
  56. package/dist/{eject-CJHkfnat.js.map → eject-izG2KjMo.js.map} +1 -1
  57. package/dist/{fold-static-BC9CYicw.js → fold-static-CybSay_W.js} +3 -3
  58. package/dist/{fold-static-BC9CYicw.js.map → fold-static-CybSay_W.js.map} +1 -1
  59. package/dist/{generate_sdk-kfkZmG-d.js → generate_sdk-B4R65oUV.js} +22 -12
  60. package/dist/generate_sdk-B4R65oUV.js.map +1 -0
  61. package/dist/index.es.js +36 -37
  62. package/dist/index.es.js.map +1 -1
  63. package/dist/{init-CjoJoThg.js → init-DYaeppEN.js} +52 -63
  64. package/dist/init-DYaeppEN.js.map +1 -0
  65. package/dist/invoked-command-CG_rIa_o.js +55 -0
  66. package/dist/invoked-command-CG_rIa_o.js.map +1 -0
  67. package/dist/last-dev-database-B_75fxZC.js +2 -0
  68. package/dist/{manifest-DRp0UVTj.js → manifest-nvPdLlJY.js} +2 -2
  69. package/dist/{manifest-DRp0UVTj.js.map → manifest-nvPdLlJY.js.map} +1 -1
  70. package/dist/{normalize-imports-BHxL2d05.js → normalize-imports-BYw8ad87.js} +3 -3
  71. package/dist/{normalize-imports-BHxL2d05.js.map → normalize-imports-BYw8ad87.js.map} +1 -1
  72. package/dist/precompress.d.ts +0 -7
  73. package/dist/{prepare-C1iaiTC4.js → prepare-1rVNd2PF.js} +7 -6
  74. package/dist/prepare-1rVNd2PF.js.map +1 -0
  75. package/dist/project-g4K6kV1t.js +701 -0
  76. package/dist/project-g4K6kV1t.js.map +1 -0
  77. package/dist/{pull-COpNJFzY.js → pull-DDMpsZ5r.js} +143 -63
  78. package/dist/pull-DDMpsZ5r.js.map +1 -0
  79. package/dist/refusal-ReeeGP8a.js +26 -0
  80. package/dist/refusal-ReeeGP8a.js.map +1 -0
  81. package/dist/resolve-BQUAC3Wi.js +2 -0
  82. package/dist/resources/derive.d.ts +9 -0
  83. package/dist/{resources-CLm6g0br.js → resources-CovP8AZ-.js} +4 -5
  84. package/dist/{resources-CLm6g0br.js.map → resources-CovP8AZ-.js.map} +1 -1
  85. package/dist/{schema-BKdh6UoE.js → schema-nuxvvc50.js} +5 -6
  86. package/dist/{schema-BKdh6UoE.js.map → schema-nuxvvc50.js.map} +1 -1
  87. package/dist/{skills-DEhYiPeO.js → skills-DeUIsZcT.js} +3 -4
  88. package/dist/{skills-DEhYiPeO.js.map → skills-DeUIsZcT.js.map} +1 -1
  89. package/dist/{start-BsPJedPQ.js → start-RzZqDroW.js} +20 -7
  90. package/dist/start-RzZqDroW.js.map +1 -0
  91. package/dist/{state-CCB-FAQ9.js → state-CYdBvnwA.js} +3 -2
  92. package/dist/state-CYdBvnwA.js.map +1 -0
  93. package/dist/{status-D_B3tlDy.js → status-D9Zm88NZ.js} +11 -12
  94. package/dist/{status-D_B3tlDy.js.map → status-D9Zm88NZ.js.map} +1 -1
  95. package/dist/{storage-CtB8polS.js → storage-BB3umRfw.js} +3 -4
  96. package/dist/{storage-CtB8polS.js.map → storage-BB3umRfw.js.map} +1 -1
  97. package/dist/{telemetry-EMFRVRQi.js → telemetry-HfU5uAh1.js} +2 -2
  98. package/dist/{telemetry-EMFRVRQi.js.map → telemetry-HfU5uAh1.js.map} +1 -1
  99. package/dist/{telemetry-BYmPU-Ji.js → telemetry-TseNLk6X.js} +4 -4
  100. package/dist/{telemetry-BYmPU-Ji.js.map → telemetry-TseNLk6X.js.map} +1 -1
  101. package/dist/{upgrade-DbuKX9lv.js → upgrade-apiPKKE_.js} +29 -6
  102. package/dist/{upgrade-DbuKX9lv.js.map → upgrade-apiPKKE_.js.map} +1 -1
  103. package/dist/utils/args.d.ts +45 -3
  104. package/dist/utils/boot-retry.d.ts +41 -0
  105. package/dist/utils/dev-preflight.d.ts +34 -1
  106. package/dist/utils/dev-server.d.ts +11 -0
  107. package/dist/utils/project.d.ts +5 -1
  108. package/dist/utils/redact.d.ts +10 -0
  109. package/dist/utils/refusal.d.ts +18 -0
  110. package/dist/utils/unknown-command.d.ts +4 -0
  111. package/package.json +7 -7
  112. package/templates/overlays/baas/README.md +2 -1
  113. package/templates/resource-graphs/blank.json +25 -0
  114. package/templates/resource-graphs/blog.json +28 -0
  115. package/templates/resource-graphs/ecommerce.json +28 -0
  116. package/templates/resource-graphs/headless.json +22 -0
  117. package/templates/template/.env.example +11 -4
  118. package/templates/template/frontend/src/App.tsx +10 -9
  119. package/templates/template/frontend/vite.config.ts +7 -73
  120. package/dist/api-keys-Bc4FJKYp.js.map +0 -1
  121. package/dist/args-CcBphFdj.js +0 -237
  122. package/dist/args-CcBphFdj.js.map +0 -1
  123. package/dist/auth-BL7bNQVu.js.map +0 -1
  124. package/dist/bundle-CqURVN-K.js.map +0 -1
  125. package/dist/context-BM-oOMNX.js.map +0 -1
  126. package/dist/daemon-CknkDjd6.js.map +0 -1
  127. package/dist/daemon-entry-C6pxdily.js.map +0 -1
  128. package/dist/db-Dkn9XhT-.js.map +0 -1
  129. package/dist/dev-DAcZR4Pp.js.map +0 -1
  130. package/dist/dev-preflight-CorMg7Ub.js.map +0 -1
  131. package/dist/dev-server-B1UYifZJ.js.map +0 -1
  132. package/dist/doctor-Ds_lzc9p.js.map +0 -1
  133. package/dist/generate_sdk-kfkZmG-d.js.map +0 -1
  134. package/dist/init-CjoJoThg.js.map +0 -1
  135. package/dist/last-dev-database-BEBPfAMY.js +0 -2
  136. package/dist/prepare-C1iaiTC4.js.map +0 -1
  137. package/dist/project-Wp2zoyeN.js +0 -349
  138. package/dist/project-Wp2zoyeN.js.map +0 -1
  139. package/dist/pull-COpNJFzY.js.map +0 -1
  140. package/dist/resolve-b_p9bmdH.js +0 -2
  141. package/dist/start-BsPJedPQ.js.map +0 -1
  142. package/dist/state-CCB-FAQ9.js.map +0 -1
@@ -1,8 +1,7 @@
1
- import { i as recordEvent } from "./telemetry-EMFRVRQi.js";
2
- import { _ as resolveTsxLoader, f as requireBackendDir, g as resolveTsx, h as resolvePluginCliScript, l as getActiveBackendPlugin, n as dependenciesNotInstalled, o as findEnvFile, p as requireProjectRoot } from "./project-Wp2zoyeN.js";
3
- import { a as unknownCommand, i as suggestCommand, n as parseCommandArgs, t as UsageError } from "./args-CcBphFdj.js";
1
+ import { i as recordEvent } from "./telemetry-HfU5uAh1.js";
2
+ import { D as redactConnectionPasswords, S as switchOn, T as unknownCommand, _ as resolveTsxLoader, b as parseCommandArgs, f as requireBackendDir, g as resolveTsx, h as resolvePluginCliScript, l as getActiveBackendPlugin, n as dependenciesNotInstalled, o as findEnvFile, p as requireProjectRoot, w as suggestCommand, x as resolveSwitchValues, y as UsageError } from "./project-g4K6kV1t.js";
4
3
  import { r as refuseMissingCollectionsPath, t as COLLECTIONS_FLAG_HELP } from "./path-flags-BFgG9V6y.js";
5
- import { DEV_DATABASE_KIND_ENV, devDatabaseKind } from "./prepare-C1iaiTC4.js";
4
+ import { DEV_DATABASE_KIND_ENV, devDatabaseKind } from "./prepare-1rVNd2PF.js";
6
5
  import chalk from "chalk";
7
6
  import fs from "fs";
8
7
  import os from "os";
@@ -116,9 +115,6 @@ function reportSpawnFailure(error) {
116
115
  //#endregion
117
116
  //#region src/commands/db.ts
118
117
  /**
119
- * CLI command: rebase db <action>
120
- */
121
- /**
122
118
  * The connection string a prepared database actually answers on.
123
119
  *
124
120
  * One function, because `db url` and `db pull` disagreed about it and the
@@ -244,6 +240,84 @@ function readFlagValue(rawArgs, flag) {
244
240
  }
245
241
  return null;
246
242
  }
243
+ /** `rebase db pull`'s flags. */
244
+ var PULL_FLAGS = {
245
+ "--from": String,
246
+ "--schema": [String],
247
+ "--anonymize": Boolean,
248
+ "--yes": Boolean,
249
+ "-y": "--yes",
250
+ "--docker": Boolean,
251
+ "--database-url": String
252
+ };
253
+ /** `rebase db url`'s flags. */
254
+ var URL_FLAGS = {
255
+ "--database-url": String,
256
+ "--docker": Boolean
257
+ };
258
+ /** `rebase db reset`'s flags. */
259
+ var RESET_FLAGS = {
260
+ "--yes": Boolean,
261
+ "-y": "--yes"
262
+ };
263
+ /** `rebase db stop` takes none. */
264
+ var STOP_FLAGS = {};
265
+ /** `rebase db pull`'s line, parsed strictly. */
266
+ function parsePullFlags(rawArgs) {
267
+ return parseCommandArgs({
268
+ spec: PULL_FLAGS,
269
+ rawArgs: [...rawArgs],
270
+ commandWords: 2,
271
+ command: "db pull",
272
+ maxPositionals: 0
273
+ }).flags;
274
+ }
275
+ /** `rebase db url`'s line, parsed strictly. */
276
+ function parseUrlFlags(rawArgs) {
277
+ return parseCommandArgs({
278
+ spec: URL_FLAGS,
279
+ rawArgs: [...rawArgs],
280
+ commandWords: 2,
281
+ command: "db url",
282
+ maxPositionals: 0
283
+ }).flags;
284
+ }
285
+ /** `rebase db reset`'s line, parsed strictly. */
286
+ function parseResetFlags(rawArgs) {
287
+ return parseCommandArgs({
288
+ spec: RESET_FLAGS,
289
+ rawArgs: [...rawArgs],
290
+ commandWords: 2,
291
+ command: "db reset",
292
+ maxPositionals: 0
293
+ }).flags;
294
+ }
295
+ /** `rebase db stop`'s line, parsed strictly. */
296
+ function parseStopFlags(rawArgs) {
297
+ return parseCommandArgs({
298
+ spec: STOP_FLAGS,
299
+ rawArgs: [...rawArgs],
300
+ commandWords: 2,
301
+ command: "db stop",
302
+ maxPositionals: 0
303
+ }).flags;
304
+ }
305
+ /**
306
+ * The `db` subcommands this CLI answers itself, each with its strict parse.
307
+ *
308
+ * The driver's `db` commands refuse a flag they do not take; these four never
309
+ * reach the driver, and read their flags out of argv by hand, so they accepted
310
+ * anything. On `pull` that cost personal data: `--anonymise` (or `--anonymiz`,
311
+ * or `--anon`) was dropped and the copy arrived as it was. An undeclared flag,
312
+ * or a word where none is taken, is now a `UsageError` naming the flag it was
313
+ * probably meant to be, raised before anything has run.
314
+ */
315
+ var OWN_SUBCOMMAND_PARSERS = {
316
+ pull: parsePullFlags,
317
+ url: parseUrlFlags,
318
+ reset: parseResetFlags,
319
+ stop: parseStopFlags
320
+ };
247
321
  /**
248
322
  * Run a database subcommand through the active driver's CLI, throwing on
249
323
  * failure instead of exiting.
@@ -313,7 +387,7 @@ var ATLAS_DEV_URL_ENV = "REBASE_ATLAS_DEV_URL";
313
387
  */
314
388
  var INVOCATION_CWD_ENV = "REBASE_INVOCATION_CWD";
315
389
  /** Loaded only when a command needs one: PGlite is 25 MB of WASM. */
316
- var startAtlasDevDatabase = async () => (await import("./atlas-dev-database-DeK3Sa4h.js")).startAtlasDevDatabase();
390
+ var startAtlasDevDatabase = async () => (await import("./atlas-dev-database-BusbHP6n.js")).startAtlasDevDatabase();
317
391
  /**
318
392
  * The empty database an Atlas-backed subcommand plans against, on the managed
319
393
  * development database.
@@ -553,17 +627,17 @@ async function runDriverDbCommand(rawArgs, options = {}) {
553
627
  const env = { ...process.env };
554
628
  if (envFile) env.DOTENV_CONFIG_PATH = envFile;
555
629
  env[DEV_DATABASE_KIND_ENV] = devDatabaseKind(projectRoot) ?? "";
556
- const { resolveProjectDatabase } = await import("./prepare-C1iaiTC4.js");
630
+ const { resolveProjectDatabase } = await import("./prepare-1rVNd2PF.js");
557
631
  const resolvedKind = resolveProjectDatabase(projectRoot, {
558
632
  flagUrl: readFlagValue(rawArgs, "--database-url"),
559
- flagDocker: rawArgs.includes("--docker")
633
+ flagDocker: switchOn(rawArgs, "--docker")
560
634
  }).kind;
561
635
  refuseBranchOnManagedDatabase(rawArgs, resolvedKind);
562
636
  refuseRestoreOnManagedDatabase(rawArgs, resolvedKind);
563
- const { prepareDatabaseEnv, managedNotices } = await import("./prepare-C1iaiTC4.js");
637
+ const { prepareDatabaseEnv, managedNotices } = await import("./prepare-1rVNd2PF.js");
564
638
  const prepared = await prepareDatabaseEnv(projectRoot, {
565
639
  flagUrl: readFlagValue(rawArgs, "--database-url"),
566
- flagDocker: rawArgs.includes("--docker"),
640
+ flagDocker: switchOn(rawArgs, "--docker"),
567
641
  onProgress: (message) => {
568
642
  if (!options.quiet) console.log(chalk.gray(` ${message}`));
569
643
  }
@@ -597,13 +671,13 @@ async function dbCommand(subcommand, rawArgs) {
597
671
  const action = argsFromCommand(rawArgs, "backups")[1];
598
672
  if (action !== void 0 && action !== "list") unknownCommand(action, ["list"], "db backups");
599
673
  }
674
+ OWN_SUBCOMMAND_PARSERS[subcommand]?.(rawArgs);
600
675
  const projectRoot = requireProjectRoot();
601
676
  recordEvent("cli.db", { subcommand: subcommand ?? "none" }, { projectRoot });
602
677
  if (subcommand === "stop" || subcommand === "reset") {
603
678
  await manageLocalDatabase(subcommand, projectRoot, rawArgs);
604
679
  return;
605
680
  }
606
- await ensureDockerDatabase(projectRoot, rawArgs);
607
681
  if (subcommand === "pull") {
608
682
  await pullIntoLocal(projectRoot, rawArgs);
609
683
  return;
@@ -612,6 +686,12 @@ async function dbCommand(subcommand, rawArgs) {
612
686
  await printDatabaseUrl(projectRoot, rawArgs);
613
687
  return;
614
688
  }
689
+ if (subcommand === "branch" && commandWords(rawArgs, "db")[2] === "switch") assertSwitchFlags(rawArgs);
690
+ else {
691
+ await refuseDriverLineBeforeStarting(projectRoot, rawArgs);
692
+ refuseMissingCollectionsPath(rawArgs, process.cwd(), requireBackendDir(projectRoot));
693
+ }
694
+ await ensureDockerDatabase(projectRoot, rawArgs);
615
695
  if (subcommand === "branch" && commandWords(rawArgs, "db")[2] === "switch") {
616
696
  await switchBranch(projectRoot, rawArgs);
617
697
  return;
@@ -620,9 +700,9 @@ async function dbCommand(subcommand, rawArgs) {
620
700
  if (subcommand === "branch") {
621
701
  const action = commandWords(rawArgs, "db")[2];
622
702
  if (action === "delete") await refuseDeletingActiveBranch(projectRoot, rawArgs);
703
+ if (action === "prune" || action === "list") await tellDriverTheActiveBranch(projectRoot);
623
704
  if (action && REGISTRY_ACTIONS.has(action)) driverArgs = await onParentDatabase(projectRoot, rawArgs, action);
624
705
  }
625
- refuseMissingCollectionsPath(driverArgs, process.cwd(), requireBackendDir(projectRoot));
626
706
  try {
627
707
  await runDriverDbCommand(driverArgs);
628
708
  } catch (error) {
@@ -635,6 +715,33 @@ async function dbCommand(subcommand, rawArgs) {
635
715
  }
636
716
  }
637
717
  /**
718
+ * Refuse a driver `db` line the driver would refuse on its flags, before
719
+ * anything is started for it.
720
+ *
721
+ * The driver is spawned with a database already running, because getting one
722
+ * means starting one: the remembered compose container, or the managed PGlite
723
+ * daemon. So `rebase db push --dry-rn` started the database and only then
724
+ * heard that `--dry-rn` does not exist. The check is the driver's own
725
+ * (`assertDbCommandLine`, the same parse each of its commands runs), so this
726
+ * answer and the one the driver gives cannot drift apart.
727
+ *
728
+ * It is this CLI's copy of `@rebasepro/server-postgres`, which ships at the
729
+ * CLI's version, as the project's does. For any other driver the line goes
730
+ * through as it is, and that driver judges it.
731
+ *
732
+ * @throws UsageError with the driver's sentence: nothing ran.
733
+ */
734
+ async function refuseDriverLineBeforeStarting(projectRoot, rawArgs) {
735
+ if (getActiveBackendPlugin(requireBackendDir(projectRoot)) !== "@rebasepro/server-postgres") return;
736
+ const { assertDbCommandLine } = await import("@rebasepro/server-postgres");
737
+ try {
738
+ assertDbCommandLine(argsFromCommand(rawArgs, "db"));
739
+ } catch (error) {
740
+ if (error instanceof Error) throw new UsageError(error.message);
741
+ throw error;
742
+ }
743
+ }
744
+ /**
638
745
  * `rebase db url` — the connection string this project is using, on stdout.
639
746
  *
640
747
  * The managed database is the one case where nothing on disk names it: `.env`
@@ -654,21 +761,13 @@ async function dbCommand(subcommand, rawArgs) {
654
761
  * string for a database nobody is serving is not an answer.
655
762
  */
656
763
  async function printDatabaseUrl(projectRoot, rawArgs) {
657
- parseCommandArgs({
658
- spec: {
659
- "--database-url": String,
660
- "--docker": Boolean
661
- },
662
- rawArgs: [...rawArgs],
663
- commandWords: 2,
664
- command: "db url",
665
- maxPositionals: 0
666
- });
667
- const { prepareDatabaseEnv } = await import("./prepare-C1iaiTC4.js");
668
- const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
764
+ const flags = parseUrlFlags(rawArgs);
765
+ await ensureDockerDatabase(projectRoot, rawArgs);
766
+ const { prepareDatabaseEnv } = await import("./prepare-1rVNd2PF.js");
767
+ const { readEnvFile } = await import("./project-g4K6kV1t.js").then((n) => n.u);
669
768
  const url = databaseUrlOf(await prepareDatabaseEnv(projectRoot, {
670
- flagUrl: readFlagValue(rawArgs, "--database-url"),
671
- flagDocker: rawArgs.includes("--docker"),
769
+ flagUrl: flags["--database-url"] ?? null,
770
+ flagDocker: flags["--docker"] === true,
672
771
  quiet: true,
673
772
  onProgress: (message) => console.error(chalk.gray(` ${message}`))
674
773
  }), readEnvFile(projectRoot));
@@ -687,8 +786,8 @@ async function printDatabaseUrl(projectRoot, rawArgs) {
687
786
  * removing the directory cannot leave a half-dropped schema behind.
688
787
  */
689
788
  async function manageLocalDatabase(subcommand, projectRoot, rawArgs) {
690
- const { resetManagedDatabase, stopManagedDatabase, stoppedManagedDatabaseLines, findRunningDaemon } = await import("./daemon-CknkDjd6.js").then((n) => n.t);
691
- const { dataDir } = await import("./state-CCB-FAQ9.js").then((n) => n.p);
789
+ const { resetManagedDatabase, stopManagedDatabase, stoppedManagedDatabaseLines, findRunningDaemon } = await import("./daemon-DDMRbz4T.js").then((n) => n.t);
790
+ const { dataDir } = await import("./state-CYdBvnwA.js").then((n) => n.p);
692
791
  const nothingHere = () => {
693
792
  const kind = devDatabaseKind(projectRoot);
694
793
  const verb = subcommand === "stop" ? "was not running" : "does not exist";
@@ -712,7 +811,7 @@ async function manageLocalDatabase(subcommand, projectRoot, rawArgs) {
712
811
  console.log(chalk.gray(nothingHere()));
713
812
  return;
714
813
  }
715
- if (!rawArgs.includes("--yes") && !rawArgs.includes("-y")) {
814
+ if (parseResetFlags(rawArgs)["--yes"] !== true) {
716
815
  if (!process.stdin.isTTY) {
717
816
  console.error(chalk.red("✗ `rebase db reset` deletes the local database and cannot prompt here."));
718
817
  console.error(chalk.yellow(" Re-run with --yes if that is what you intend."));
@@ -741,36 +840,47 @@ async function manageLocalDatabase(subcommand, projectRoot, rawArgs) {
741
840
  * and the wrong one here means overwriting production with a laptop.
742
841
  */
743
842
  async function pullIntoLocal(projectRoot, rawArgs) {
744
- const { describeRestoreFailure, describeTarget, dumpSource, findPgTool, restoreCopy } = await import("./pull-COpNJFzY.js");
745
- const { prepareDatabaseEnv } = await import("./prepare-C1iaiTC4.js");
746
- const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
747
- const source = readFlagValue(rawArgs, "--from");
843
+ const { describeRestoreFailure, describeTarget, dumpSource, findPgTool, restoreCopy, sourceProblem } = await import("./pull-DDMpsZ5r.js");
844
+ const { prepareDatabaseEnv } = await import("./prepare-1rVNd2PF.js");
845
+ const { readEnvFile } = await import("./project-g4K6kV1t.js").then((n) => n.u);
846
+ const flags = parsePullFlags(rawArgs);
847
+ const schemas = flags["--schema"] ?? [];
848
+ const anonymize = flags["--anonymize"] === true;
849
+ const targetFlag = flags["--database-url"];
850
+ if (targetFlag !== void 0) {
851
+ console.error(chalk.red("✗ `rebase db pull` does not take --database-url."));
852
+ console.error("");
853
+ console.error(chalk.gray(" The target is always this project's local development database. There is"));
854
+ console.error(chalk.gray(" no flag that makes this write somewhere else, deliberately: a command that"));
855
+ console.error(chalk.gray(" can copy in both directions eventually copies in the wrong one."));
856
+ console.error("");
857
+ const shown = redactConnectionPasswords(targetFlag);
858
+ console.error(chalk.gray(` To read from another database, that is ${chalk.cyan("--from")}:`));
859
+ console.error(chalk.gray(` rebase db pull --from "${shown}"`));
860
+ if (shown !== targetFlag) console.error(chalk.gray(" with the password in place of ***."));
861
+ process.exit(1);
862
+ }
863
+ const source = flags["--from"];
748
864
  if (!source) {
749
865
  console.error(chalk.red("✗ `rebase db pull` needs a source: --from <connection-string>"));
750
866
  console.error(chalk.gray(" Example: rebase db pull --from \"$PRODUCTION_DATABASE_URL\""));
751
867
  process.exit(1);
752
868
  }
753
- const schemas = rawArgs.flatMap((arg, index) => arg === "--schema" && rawArgs[index + 1] ? [rawArgs[index + 1]] : []);
754
- const anonymize = rawArgs.includes("--anonymize");
869
+ const notASource = sourceProblem(source);
870
+ if (notASource !== null) {
871
+ console.error(chalk.red(`✗ The --from value is not a connection string: ${notASource}. Nothing was read or changed.`));
872
+ console.error(chalk.gray(" Pass a URL, postgresql://user:password@host:5432/database, or libpq's"));
873
+ console.error(chalk.gray(" host=… port=… dbname=… user=… pairs, quoted as one argument."));
874
+ process.exit(1);
875
+ }
755
876
  for (const tool of ["pg_dump", "pg_restore"]) if (!await findPgTool(tool)) {
756
877
  console.error(chalk.red(`✗ \`${tool}\` is not on PATH, and this command cannot run without it.`));
757
878
  console.error(chalk.gray(" Install the PostgreSQL client tools, e.g. `brew install libpq`."));
758
879
  process.exit(1);
759
880
  }
760
- const targetFlag = readFlagValue(rawArgs, "--database-url");
761
- if (targetFlag !== null) {
762
- console.error(chalk.red("✗ `rebase db pull` does not take --database-url."));
763
- console.error("");
764
- console.error(chalk.gray(" The target is always this project's local development database. There is"));
765
- console.error(chalk.gray(" no flag that makes this write somewhere else, deliberately: a command that"));
766
- console.error(chalk.gray(" can copy in both directions eventually copies in the wrong one."));
767
- console.error("");
768
- console.error(chalk.gray(` To read from another database, that is ${chalk.cyan("--from")}:`));
769
- console.error(chalk.gray(` rebase db pull --from ${targetFlag}`));
770
- process.exit(1);
771
- }
881
+ await ensureDockerDatabase(projectRoot, rawArgs);
772
882
  const prepared = await prepareDatabaseEnv(projectRoot, {
773
- flagDocker: rawArgs.includes("--docker"),
883
+ flagDocker: flags["--docker"] === true,
774
884
  onProgress: (message) => console.log(chalk.gray(` ${message}`))
775
885
  });
776
886
  const target = databaseUrlOf(prepared, readEnvFile(projectRoot)) ?? "";
@@ -792,7 +902,7 @@ async function pullIntoLocal(projectRoot, rawArgs) {
792
902
  console.log(` ${chalk.gray("Data")} ${anonymize ? "personal-looking columns will be overwritten after the copy" : chalk.yellow("copied as-is, including any personal data")}`);
793
903
  if (schemas.length > 0) console.log(` ${chalk.gray("Schemas")} ${schemas.join(", ")}`);
794
904
  console.log("");
795
- if (!rawArgs.includes("--yes") && !rawArgs.includes("-y")) {
905
+ if (flags["--yes"] !== true) {
796
906
  if (!process.stdin.isTTY) {
797
907
  console.error(chalk.red("✗ This replaces the local database and cannot prompt here."));
798
908
  console.error(chalk.yellow(" Re-run with --yes if that is what you intend."));
@@ -863,7 +973,7 @@ async function pullIntoLocal(projectRoot, rawArgs) {
863
973
  */
864
974
  async function restoreAppRole(target) {
865
975
  const { Client } = await import("pg");
866
- const { provisionableSchemas } = await import("./pull-COpNJFzY.js");
976
+ const { provisionableSchemas } = await import("./pull-DDMpsZ5r.js");
867
977
  const client = new Client({ connectionString: target });
868
978
  client.on("error", () => void 0);
869
979
  try {
@@ -898,7 +1008,7 @@ async function restoreAppRole(target) {
898
1008
  */
899
1009
  async function anonymizeTarget(target, source, kind) {
900
1010
  const { Client } = await import("pg");
901
- const { anonymizeCopy } = await import("./pull-COpNJFzY.js");
1011
+ const { anonymizeCopy } = await import("./pull-DDMpsZ5r.js");
902
1012
  const deleteIt = kind === "managed" ? `Delete it now: ${chalk.cyan("rebase db reset --yes")}` : kind === "docker" ? `Delete it now: ${chalk.cyan("docker compose down -v")}` : "Delete it now: drop the restored tables, or the database, before anything else reads it.";
903
1013
  const holdsRealData = (reason) => [
904
1014
  chalk.red(`✗ The copy could not be anonymized: ${reason}`),
@@ -945,11 +1055,11 @@ async function anonymizeTarget(target, source, kind) {
945
1055
  * own connection error follows, which is the same contract `dev` keeps.
946
1056
  */
947
1057
  async function ensureDockerDatabase(projectRoot, rawArgs) {
948
- const { ensureDevDatabase } = await import("./dev-preflight-CorMg7Ub.js").then((n) => n.n);
949
- const { resolveProjectDatabase } = await import("./prepare-C1iaiTC4.js");
1058
+ const { ensureDevDatabase } = await import("./dev-preflight-FT9GbJVj.js").then((n) => n.n);
1059
+ const { resolveProjectDatabase } = await import("./prepare-1rVNd2PF.js");
950
1060
  const resolved = resolveProjectDatabase(projectRoot, {
951
1061
  flagUrl: readFlagValue(rawArgs, "--database-url"),
952
- flagDocker: rawArgs.includes("--docker")
1062
+ flagDocker: switchOn(rawArgs, "--docker")
953
1063
  });
954
1064
  if (resolved.kind !== "docker") return;
955
1065
  const composeUrl = resolved.url;
@@ -960,7 +1070,7 @@ async function ensureDockerDatabase(projectRoot, rawArgs) {
960
1070
  disabled: false,
961
1071
  hasCollections: false,
962
1072
  pushSchema: async () => void 0,
963
- log: (message) => console.log(message)
1073
+ log: (message) => console.error(message)
964
1074
  });
965
1075
  }
966
1076
  /**
@@ -979,7 +1089,7 @@ async function ensureDockerDatabase(projectRoot, rawArgs) {
979
1089
  async function refuseDeletingActiveBranch(projectRoot, rawArgs) {
980
1090
  const [, , , name] = commandWords(rawArgs, "db");
981
1091
  if (!name) return;
982
- const { readActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1092
+ const { readActiveBranch } = await import("./branch-pointer-Bn_FjNld.js");
983
1093
  const active = readActiveBranch(projectRoot);
984
1094
  if (active?.name !== name) return;
985
1095
  const off = "rebase db branch switch --off";
@@ -997,6 +1107,29 @@ async function refuseDeletingActiveBranch(projectRoot, rawArgs) {
997
1107
  console.error("");
998
1108
  process.exit(1);
999
1109
  }
1110
+ /**
1111
+ * The variable that tells the driver which database this checkout is switched
1112
+ * to. Spelled the same in `packages/server-postgres/src/branch-prune.ts`.
1113
+ */
1114
+ var ACTIVE_BRANCH_DATABASE_ENV = "REBASE_ACTIVE_BRANCH_DATABASE";
1115
+ /**
1116
+ * Tell the driver which branch this checkout is on, for the two actions that
1117
+ * answer differently for it.
1118
+ *
1119
+ * - `prune` keeps it, as `delete` refuses it. `prune --older-than 0d --yes`
1120
+ * dropped it, and the checkout then pointed every command at a database
1121
+ * that no longer existed, with no word of `switch --off`.
1122
+ * - `list` marks it, where every branch had the same bullet.
1123
+ *
1124
+ * The pointer is the CLI's and the driver is a child process, so it is told
1125
+ * the database in its environment.
1126
+ */
1127
+ async function tellDriverTheActiveBranch(projectRoot) {
1128
+ const { readActiveBranch } = await import("./branch-pointer-Bn_FjNld.js");
1129
+ const active = readActiveBranch(projectRoot);
1130
+ if (active) process.env[ACTIVE_BRANCH_DATABASE_ENV] = active.database;
1131
+ else delete process.env[ACTIVE_BRANCH_DATABASE_ENV];
1132
+ }
1000
1133
  /** The `branch` actions that read or write the registry — every one but `switch`. */
1001
1134
  var REGISTRY_ACTIONS = /* @__PURE__ */ new Set([
1002
1135
  "list",
@@ -1033,16 +1166,16 @@ var REGISTRY_ACTIONS = /* @__PURE__ */ new Set([
1033
1166
  */
1034
1167
  async function onParentDatabase(projectRoot, rawArgs, action) {
1035
1168
  if (readFlagValue(rawArgs, "--database-url") !== null) return rawArgs;
1036
- const { readActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1169
+ const { readActiveBranch } = await import("./branch-pointer-Bn_FjNld.js");
1037
1170
  const active = readActiveBranch(projectRoot);
1038
1171
  if (!active) return rawArgs;
1039
- const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
1040
- const { resolveDevDatabase } = await import("./resolve-b_p9bmdH.js");
1041
- const { resolveComposeUrl } = await import("./prepare-C1iaiTC4.js");
1042
- const { readLastDevDocker } = await import("./last-dev-database-BEBPfAMY.js");
1172
+ const { readEnvFile } = await import("./project-g4K6kV1t.js").then((n) => n.u);
1173
+ const { resolveDevDatabase } = await import("./resolve-BQUAC3Wi.js");
1174
+ const { resolveComposeUrl } = await import("./prepare-1rVNd2PF.js");
1175
+ const { readLastDevDocker } = await import("./last-dev-database-B_75fxZC.js");
1043
1176
  const envFile = readEnvFile(projectRoot);
1044
1177
  const parent = resolveDevDatabase({
1045
- flagDocker: rawArgs.includes("--docker"),
1178
+ flagDocker: switchOn(rawArgs, "--docker"),
1046
1179
  lastDevDocker: readLastDevDocker(projectRoot),
1047
1180
  env: process.env,
1048
1181
  envFile,
@@ -1051,7 +1184,7 @@ async function onParentDatabase(projectRoot, rawArgs, action) {
1051
1184
  });
1052
1185
  const url = (parent.kind === "managed" ? null : parent.url)?.trim();
1053
1186
  if (!url) return rawArgs;
1054
- console.log(chalk.gray(` ● On branch ${active.name} — using the main database, where the branch registry lives.`));
1187
+ console.error(chalk.gray(` ● On branch ${active.name} — using the main database, where the branch registry lives.`));
1055
1188
  const from = action === "create" && readFlagValue(rawArgs, "--from") === null ? ["--from", active.database] : [];
1056
1189
  return [
1057
1190
  ...rawArgs,
@@ -1064,13 +1197,15 @@ async function onParentDatabase(projectRoot, rawArgs, action) {
1064
1197
  * The flags `rebase db branch switch` takes, the relayed database flags and
1065
1198
  * `--debug` included.
1066
1199
  */
1067
- var SWITCH_FLAGS = [
1068
- "--off",
1069
- "--main",
1070
- "--database-url",
1071
- "--docker",
1072
- "--debug"
1073
- ];
1200
+ var SWITCH_FLAGS = {
1201
+ "--off": Boolean,
1202
+ "--main": Boolean,
1203
+ "--database-url": String,
1204
+ "--docker": Boolean,
1205
+ "--debug": Boolean
1206
+ };
1207
+ /** The long flags in {@link SWITCH_FLAGS}, for the did-you-mean. */
1208
+ var SWITCH_FLAG_NAMES = Object.keys(SWITCH_FLAGS);
1074
1209
  /**
1075
1210
  * Refuse a flag `switch` does not take, naming the one it was probably meant to be.
1076
1211
  *
@@ -1081,13 +1216,19 @@ var SWITCH_FLAGS = [
1081
1216
  function assertSwitchFlags(rawArgs) {
1082
1217
  for (const word of rawArgs.slice(2)) {
1083
1218
  if (!word.startsWith("-")) continue;
1084
- const flag = word.split("=")[0];
1085
- if (SWITCH_FLAGS.includes(flag)) continue;
1086
- const near = suggestCommand(flag.replace(/^-+/, ""), SWITCH_FLAGS.map((known) => known.slice(2)));
1087
- throw new UsageError(`\`rebase db branch switch\` has no option ${flag}` + (near ? ` — did you mean --${near}?` : " — it takes --off (or --main) and a branch name.") + " Nothing was changed.");
1219
+ const flag = word.split(/[=\s]/)[0];
1220
+ if (SWITCH_FLAG_NAMES.includes(flag)) continue;
1221
+ const near = suggestCommand(flag.replace(/^-+/, ""), SWITCH_FLAG_NAMES.map((known) => known.slice(2)));
1222
+ throw new UsageError(`\`rebase db branch switch\` has no option ${flag}` + (near ? ` — did you mean --${near}?` : " — it takes --off (or --main) and a branch name.") + " Nothing was run. See `rebase db branch --help`.");
1088
1223
  }
1224
+ resolveSwitchValues(SWITCH_FLAGS, rawArgs.slice(2), "db branch switch");
1089
1225
  }
1090
1226
  /**
1227
+ * What `switch` cannot change: a `rebase dev` started before it connected to
1228
+ * the database it was given then, and serves it until it is restarted.
1229
+ */
1230
+ var RUNNING_DEV_KEEPS_ITS_DATABASE = "A `rebase dev` that is already running keeps the database it started on until you restart it.";
1231
+ /**
1091
1232
  * `rebase db branch switch <name>` — point this checkout at a branch.
1092
1233
  *
1093
1234
  * The step branching was missing. `create` copied the database in about a
@@ -1113,17 +1254,17 @@ function assertSwitchFlags(rawArgs) {
1113
1254
  */
1114
1255
  async function switchBranch(projectRoot, rawArgs) {
1115
1256
  assertSwitchFlags(rawArgs);
1116
- const { branchDatabaseName, clearActiveBranch, databaseNameOf, readActiveBranch, writeActiveBranch } = await import("./branch-pointer-DTQNLFtb.js");
1117
- const { readEnvFile } = await import("./project-Wp2zoyeN.js").then((n) => n.u);
1118
- const { resolveDevDatabase } = await import("./resolve-b_p9bmdH.js");
1119
- const { resolveComposeUrl } = await import("./prepare-C1iaiTC4.js");
1120
- const { readLastDevDocker } = await import("./last-dev-database-BEBPfAMY.js");
1121
- const goingOff = rawArgs.includes("--off") || rawArgs.includes("--main");
1257
+ const { branchDatabaseName, clearActiveBranch, databaseNameOf, readActiveBranch, writeActiveBranch } = await import("./branch-pointer-Bn_FjNld.js");
1258
+ const { readEnvFile } = await import("./project-g4K6kV1t.js").then((n) => n.u);
1259
+ const { resolveDevDatabase } = await import("./resolve-BQUAC3Wi.js");
1260
+ const { resolveComposeUrl } = await import("./prepare-1rVNd2PF.js");
1261
+ const { readLastDevDocker } = await import("./last-dev-database-B_75fxZC.js");
1262
+ const goingOff = switchOn(rawArgs, "--off") || switchOn(rawArgs, "--main");
1122
1263
  const name = commandWords(rawArgs, "db")[3];
1123
1264
  const envFile = readEnvFile(projectRoot);
1124
1265
  const resolved = resolveDevDatabase({
1125
1266
  flagUrl: readFlagValue(rawArgs, "--database-url"),
1126
- flagDocker: rawArgs.includes("--docker"),
1267
+ flagDocker: switchOn(rawArgs, "--docker"),
1127
1268
  lastDevDocker: readLastDevDocker(projectRoot),
1128
1269
  env: process.env,
1129
1270
  envFile,
@@ -1150,6 +1291,7 @@ async function switchBranch(projectRoot, rawArgs) {
1150
1291
  clearActiveBranch(projectRoot);
1151
1292
  console.log("");
1152
1293
  console.log(active ? chalk.green(` ✓ Back on the main database${base ? ` (${databaseNameOf(base)})` : ""}.`) : chalk.gray(" Already on the main database."));
1294
+ if (active) console.log(chalk.gray(` ${RUNNING_DEV_KEEPS_ITS_DATABASE}`));
1153
1295
  console.log("");
1154
1296
  return;
1155
1297
  }
@@ -1161,6 +1303,9 @@ async function switchBranch(projectRoot, rawArgs) {
1161
1303
  process.exit(1);
1162
1304
  }
1163
1305
  const database = branchDatabaseName(name);
1306
+ const { reopenClosedDatabases, reopenedDatabasesNotice } = await import("@rebasepro/server-postgres");
1307
+ const healed = await reopenClosedDatabases(base, [readActiveBranch(projectRoot)?.database]);
1308
+ for (const line of reopenedDatabasesNotice(healed)) console.error(chalk.yellow(` ${line}`));
1164
1309
  const { Client } = await import("pg");
1165
1310
  const client = new Client({ connectionString: base });
1166
1311
  try {
@@ -1196,6 +1341,7 @@ async function switchBranch(projectRoot, rawArgs) {
1196
1341
  console.log(chalk.green(` ✓ Switched to branch "${name}".`));
1197
1342
  console.log(chalk.gray(` Database: ${database}`));
1198
1343
  console.log(chalk.gray(" Every rebase command in this checkout now uses it — dev, db push, migrate."));
1344
+ console.log(chalk.gray(` ${RUNNING_DEV_KEEPS_ITS_DATABASE}`));
1199
1345
  console.log(chalk.gray(` Back to the main database: ${chalk.cyan("rebase db branch switch --off")}`));
1200
1346
  console.log("");
1201
1347
  }
@@ -1283,7 +1429,12 @@ var DB_ACTION_HELP = {
1283
1429
  pull: {
1284
1430
  usage: "rebase db pull --from <url> [--schema <name>] [--anonymize] [--yes]",
1285
1431
  summary: "Copy another database into local development. One-directional by design — it can never push.",
1286
- notes: ["The target is not selectable: --database-url is refused, so this can never write to a remote database."]
1432
+ notes: [
1433
+ "--anonymize overwrites personal-looking columns after the copy. A misspelt flag is refused, never ignored.",
1434
+ "--schema <name> copies only that schema; repeat it for more.",
1435
+ "--docker pulls into Postgres in Docker rather than the database `rebase dev` would pick.",
1436
+ "The target is not selectable: --database-url is refused, so this can never write to a remote database."
1437
+ ]
1287
1438
  },
1288
1439
  stop: {
1289
1440
  usage: "rebase db stop",
@@ -1379,6 +1530,6 @@ function dbExamples(kind) {
1379
1530
  `;
1380
1531
  }
1381
1532
  //#endregion
1382
- export { DB_SUBCOMMANDS, absolutizeLocalPathArgs, dbCommand, ensureDockerDatabase, argsFromCommand as n, resolveDriverCli, runDriverDbCommand, runDriverSchemaCommand, spawnDriverCli, reportSpawnFailure as t };
1533
+ export { DATABASE_SOURCE_ENV, DB_SUBCOMMANDS, absolutizeLocalPathArgs, databaseUrlOf, dbCommand, ensureDockerDatabase, argsFromCommand as n, resolveDriverCli, runDriverDbCommand, runDriverSchemaCommand, spawnDriverCli, reportSpawnFailure as t };
1383
1534
 
1384
- //# sourceMappingURL=db-Dkn9XhT-.js.map
1535
+ //# sourceMappingURL=db-9P6MnmdC.js.map