@rebasepro/server-postgres 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 (126) hide show
  1. package/dist/{BranchService-DNg4txyf.js → BranchService-ClklxyAQ.js} +283 -20
  2. package/dist/BranchService-ClklxyAQ.js.map +1 -0
  3. package/dist/backup/backup-cli.d.ts +70 -1
  4. package/dist/backup/backup-service.d.ts +79 -0
  5. package/dist/backup/pg-binary.d.ts +2 -2
  6. package/dist/backup/pg-tools.d.ts +60 -1
  7. package/dist/backup-cli-gijeXe0u.js +1961 -0
  8. package/dist/backup-cli-gijeXe0u.js.map +1 -0
  9. package/dist/{boot-ddl-Dnvpmm_T.js → boot-ddl-DYH95Qeg.js} +3 -3
  10. package/dist/{boot-ddl-Dnvpmm_T.js.map → boot-ddl-DYH95Qeg.js.map} +1 -1
  11. package/dist/branch-argv.d.ts +15 -0
  12. package/dist/branch-prune.d.ts +18 -0
  13. package/dist/{cli-console-C_ISGwJo.js → cli-console-CQrQ0lAY.js} +19 -13
  14. package/dist/cli-console-CQrQ0lAY.js.map +1 -0
  15. package/dist/cli-console.d.ts +4 -3
  16. package/dist/{cli-errors-mx4sSjB8.js → cli-errors-DiA0XFIS.js} +110 -14
  17. package/dist/{cli-errors-mx4sSjB8.js.map → cli-errors-DiA0XFIS.js.map} +1 -1
  18. package/dist/cli-errors.d.ts +26 -1
  19. package/dist/cli-flags.d.ts +51 -0
  20. package/dist/{cli-prompt-egtNKkZl.js → cli-prompt-DXG0yk-h.js} +39 -4
  21. package/dist/{cli-prompt-egtNKkZl.js.map → cli-prompt-DXG0yk-h.js.map} +1 -1
  22. package/dist/cli.js +120 -184
  23. package/dist/cli.js.map +1 -1
  24. package/dist/collections/validate-relations.d.ts +8 -2
  25. package/dist/{column-plan-helpers-D_V4oaZh.js → column-plan-helpers-IG6uFb1s.js} +2 -2
  26. package/dist/{column-plan-helpers-D_V4oaZh.js.map → column-plan-helpers-IG6uFb1s.js.map} +1 -1
  27. package/dist/{connection-C938nR3E.js → connection-czvI7TZL.js} +57 -10
  28. package/dist/connection-czvI7TZL.js.map +1 -0
  29. package/dist/{databasePoolManager-Yqdw14wY.js → databasePoolManager-3stMNFL-.js} +4 -6
  30. package/dist/databasePoolManager-3stMNFL-.js.map +1 -0
  31. package/dist/db-command-line.d.ts +14 -0
  32. package/dist/{rls-bootstrap-sql-Bd-hJk08.js → db-subcommands-BPoHCxJR.js} +455 -3
  33. package/dist/db-subcommands-BPoHCxJR.js.map +1 -0
  34. package/dist/db-subcommands.d.ts +11 -0
  35. package/dist/{deferred-index-build-Ca6OqKyR.js → deferred-index-build-BE0I6sYU.js} +8 -8
  36. package/dist/{deferred-index-build-Ca6OqKyR.js.map → deferred-index-build-BE0I6sYU.js.map} +1 -1
  37. package/dist/{doctor-CJyuhV1n.js → doctor-BT--1kq3.js} +107 -11
  38. package/dist/doctor-BT--1kq3.js.map +1 -0
  39. package/dist/{ensure-collection-policies-C1ux3V_z.js → ensure-collection-policies-BnGOURpG.js} +60 -11
  40. package/dist/ensure-collection-policies-BnGOURpG.js.map +1 -0
  41. package/dist/{ensure-collection-tables-Do-Bvb64.js → ensure-collection-tables-Cet4650m.js} +9 -9
  42. package/dist/{ensure-collection-tables-Do-Bvb64.js.map → ensure-collection-tables-Cet4650m.js.map} +1 -1
  43. package/dist/{ensure-tables-Dl_Eh9ow.js → ensure-tables-l_OgFQjN.js} +5 -5
  44. package/dist/{ensure-tables-Dl_Eh9ow.js.map → ensure-tables-l_OgFQjN.js.map} +1 -1
  45. package/dist/{enum-labels-kept-D9eTIWCz.js → enum-labels-kept-nheku1pB.js} +3 -3
  46. package/dist/{enum-labels-kept-D9eTIWCz.js.map → enum-labels-kept-nheku1pB.js.map} +1 -1
  47. package/dist/{generate-drizzle-schema-Bf8canaR.js → generate-drizzle-schema-DC0BOUpn.js} +3 -3
  48. package/dist/{generate-drizzle-schema-Bf8canaR.js.map → generate-drizzle-schema-DC0BOUpn.js.map} +1 -1
  49. package/dist/{generate-drizzle-schema-logic-BaT0H7Gq.js → generate-drizzle-schema-logic-CPzCRD-8.js} +4 -4
  50. package/dist/{generate-drizzle-schema-logic-BaT0H7Gq.js.map → generate-drizzle-schema-logic-CPzCRD-8.js.map} +1 -1
  51. package/dist/{generate-files-D50Pxw1G.js → generate-files-BP-4W_gm.js} +6 -6
  52. package/dist/{generate-files-D50Pxw1G.js.map → generate-files-BP-4W_gm.js.map} +1 -1
  53. package/dist/{generate-next-step-DCd7yiJ2.js → generate-next-step-DgK5BlBn.js} +22 -14
  54. package/dist/{generate-next-step-DCd7yiJ2.js.map → generate-next-step-DgK5BlBn.js.map} +1 -1
  55. package/dist/{generate-postgres-ddl-logic-B4k9djAV.js → generate-postgres-ddl-logic-DPl1oH_z.js} +4 -4
  56. package/dist/{generate-postgres-ddl-logic-B4k9djAV.js.map → generate-postgres-ddl-logic-DPl1oH_z.js.map} +1 -1
  57. package/dist/generated-schema-diff-eZCklRZQ.js +1025 -0
  58. package/dist/generated-schema-diff-eZCklRZQ.js.map +1 -0
  59. package/dist/{generated-schema-staleness-FlxM2i4i.js → generated-schema-staleness-BvNF3i-s.js} +2 -2
  60. package/dist/{generated-schema-staleness-FlxM2i4i.js.map → generated-schema-staleness-BvNF3i-s.js.map} +1 -1
  61. package/dist/index.d.ts +1 -0
  62. package/dist/index.es.js +70 -11
  63. package/dist/index.es.js.map +1 -1
  64. package/dist/{introspect-db-logic-j2vYhmdP.js → introspect-db-logic-DgQVzccW.js} +2 -2
  65. package/dist/{introspect-db-logic-j2vYhmdP.js.map → introspect-db-logic-DgQVzccW.js.map} +1 -1
  66. package/dist/migrate-policy-stamps-3eqfhes6.js +89 -0
  67. package/dist/migrate-policy-stamps-3eqfhes6.js.map +1 -0
  68. package/dist/{open-rebase-D8rytTP0.js → open-rebase-EmqVmS14.js} +78 -1027
  69. package/dist/open-rebase-EmqVmS14.js.map +1 -0
  70. package/dist/{pg-error-utils-CdsGYMTm.js → pg-error-utils-CFEnm2m9.js} +11 -4
  71. package/dist/pg-error-utils-CFEnm2m9.js.map +1 -0
  72. package/dist/{plan-schema-CsNgK0qi.js → plan-schema-Czf3q4-Q.js} +4 -4
  73. package/dist/{plan-schema-CsNgK0qi.js.map → plan-schema-Czf3q4-Q.js.map} +1 -1
  74. package/dist/{policy-drift-CY5P1ZRu.js → policy-drift-X4A-xAzv.js} +3 -3
  75. package/dist/{policy-drift-CY5P1ZRu.js.map → policy-drift-X4A-xAzv.js.map} +1 -1
  76. package/dist/pool-disconnects.d.ts +28 -0
  77. package/dist/{push-index-prebuild-BDFcfRPo.js → push-index-prebuild-COd7i6wm.js} +4 -4
  78. package/dist/{push-index-prebuild-BDFcfRPo.js.map → push-index-prebuild-COd7i6wm.js.map} +1 -1
  79. package/dist/{push-legacy-renames-D4bvMWAb.js → push-legacy-renames-CLgYYwPE.js} +4 -4
  80. package/dist/{push-legacy-renames-D4bvMWAb.js.map → push-legacy-renames-CLgYYwPE.js.map} +1 -1
  81. package/dist/{push-policy-plan-DTXE6aVa.js → push-policy-plan-D2gpQsdv.js} +23 -7
  82. package/dist/push-policy-plan-D2gpQsdv.js.map +1 -0
  83. package/dist/{render-ddl-CrfEe__B.js → render-ddl-4v88y-Gv.js} +4 -4
  84. package/dist/{render-ddl-CrfEe__B.js.map → render-ddl-4v88y-Gv.js.map} +1 -1
  85. package/dist/{rls-enforcement-D7P4-ZYX.js → rls-enforcement-DDyNoOSy.js} +2 -2
  86. package/dist/{rls-enforcement-D7P4-ZYX.js.map → rls-enforcement-DDyNoOSy.js.map} +1 -1
  87. package/dist/schema/atlas-argv.d.ts +3 -1
  88. package/dist/schema/doctor-cli.js +5 -5
  89. package/dist/schema/doctor.d.ts +20 -2
  90. package/dist/schema/ensure-collection-policies.d.ts +28 -1
  91. package/dist/schema/generate-drizzle-schema.js +1 -1
  92. package/dist/schema/generate-next-step.d.ts +20 -8
  93. package/dist/schema/generate-postgres-ddl.js +2 -2
  94. package/dist/schema/generated-schema-diff.d.ts +21 -0
  95. package/dist/schema/introspect-db.js +6 -6
  96. package/dist/schema/introspect-db.js.map +1 -1
  97. package/dist/schema/migrate-policy-stamps.d.ts +23 -0
  98. package/dist/schema/push-policy-plan.d.ts +10 -2
  99. package/dist/services/BranchService.d.ts +85 -0
  100. package/dist/services/pg-notify-listener.d.ts +2 -0
  101. package/dist/{source-DB6xJv3p.js → source-fZb92pN8.js} +46 -3
  102. package/dist/source-fZb92pN8.js.map +1 -0
  103. package/dist/{vector-index-BFhyEaiz.js → vector-index-DsQ3V2d2.js} +2 -2
  104. package/dist/{vector-index-BFhyEaiz.js.map → vector-index-DsQ3V2d2.js.map} +1 -1
  105. package/dist/{websocket-DMeXOoyv.js → websocket-BKZwsjmf.js} +18 -5
  106. package/dist/websocket-BKZwsjmf.js.map +1 -0
  107. package/package.json +7 -7
  108. package/dist/BranchService-DNg4txyf.js.map +0 -1
  109. package/dist/backup-cli-HCEkPcQj.js +0 -556
  110. package/dist/backup-cli-HCEkPcQj.js.map +0 -1
  111. package/dist/backup-service-D-UpT7DH.js +0 -857
  112. package/dist/backup-service-D-UpT7DH.js.map +0 -1
  113. package/dist/cli-console-C_ISGwJo.js.map +0 -1
  114. package/dist/cli-flags-DUozBFyK.js +0 -205
  115. package/dist/cli-flags-DUozBFyK.js.map +0 -1
  116. package/dist/connection-C938nR3E.js.map +0 -1
  117. package/dist/databasePoolManager-Yqdw14wY.js.map +0 -1
  118. package/dist/doctor-CJyuhV1n.js.map +0 -1
  119. package/dist/ensure-collection-policies-C1ux3V_z.js.map +0 -1
  120. package/dist/open-rebase-D8rytTP0.js.map +0 -1
  121. package/dist/pg-error-utils-CdsGYMTm.js.map +0 -1
  122. package/dist/push-policy-plan-DTXE6aVa.js.map +0 -1
  123. package/dist/rls-bootstrap-sql-Bd-hJk08.js.map +0 -1
  124. package/dist/rolldown-runtime-V7rFbMRe.js +0 -39
  125. package/dist/source-DB6xJv3p.js.map +0 -1
  126. package/dist/websocket-DMeXOoyv.js.map +0 -1
@@ -1,8 +1,10 @@
1
1
  import { createRequire as __createRequire } from "module";
2
2
  __createRequire(import.meta.url);
3
- import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./rolldown-runtime-V7rFbMRe.js";
3
+ import { a as __require, i as __exportAll, n as require_arg, o as __toESM, r as __commonJSMin } from "./cli-prompt-DXG0yk-h.js";
4
+ import { et as redactConnectionPasswords } from "./cli-errors-DiA0XFIS.js";
4
5
  import { LEGACY_RLS_SCHEMA, REBASE_SCHEMA } from "@rebasepro/types";
5
6
  import { sqlRows } from "@rebasepro/common";
7
+ import { suggestNearMiss } from "@rebasepro/utils";
6
8
  import process$1, { execArgv, execPath, hrtime, platform } from "node:process";
7
9
  import { constants } from "node:os";
8
10
  import tty from "node:tty";
@@ -6518,6 +6520,456 @@ async function dropLegacyAuthSchema(run, report) {
6518
6520
  }
6519
6521
  }
6520
6522
  //#endregion
6521
- export { rls_bootstrap_sql_exports as a, rlsRuntimeIsCurrent as i, RLS_BOOTSTRAP_STATEMENTS as n, execa as o, dropLegacyAuthSchema as r, RLS_BOOTSTRAP_SQL as t };
6523
+ //#region src/cli-flags.ts
6524
+ var import_arg = /* @__PURE__ */ __toESM(require_arg(), 1);
6525
+ /**
6526
+ * Flags that reach this process on a line it did not compose.
6527
+ *
6528
+ * `rebase db …` hands the driver the user's whole line: the CLI *reads*
6529
+ * `--database-url` and `--docker` to resolve the database and then relays them
6530
+ * verbatim, and `--debug` is what `bin/rebase.js` prints after every failure as
6531
+ * the thing to re-run with. Rejecting any of the three would make the driver
6532
+ * refuse commands the CLI documents.
6533
+ */
6534
+ var RELAYED_FLAGS = {
6535
+ "--database-url": String,
6536
+ "--docker": Boolean,
6537
+ "--debug": Boolean,
6538
+ "--help": Boolean,
6539
+ "-h": "--help"
6540
+ };
6541
+ /**
6542
+ * Parse a driver command's line — `["db", "<subcommand>", …]` — with the
6543
+ * relayed flags declared alongside the command's own.
6544
+ *
6545
+ * Every driver parser is permissive, and an undeclared flag in a permissive
6546
+ * parse is a positional. The positionals are what `db migrate` hands
6547
+ * `atlas migrate apply`, what `db generate` names its migration after and
6548
+ * which backup `db restore` restores, so a relayed flag left undeclared was
6549
+ * read as one of those: `rebase db migrate --docker` died on Atlas's
6550
+ * `unknown flag: --docker` after it had already written the auth schema.
6551
+ */
6552
+ function parseDriverLine(spec, args) {
6553
+ return (0, import_arg.default)({
6554
+ ...RELAYED_FLAGS,
6555
+ ...spec
6556
+ }, {
6557
+ argv: args.slice(2),
6558
+ permissive: true
6559
+ });
6560
+ }
6561
+ /** Keyed by `"<domain> <subcommand>"`, the way the user types it. */
6562
+ var DRIVER_FLAG_SPECS = {
6563
+ "db push": {
6564
+ "--collections": String,
6565
+ "-c": "--collections",
6566
+ "--dry-run": Boolean,
6567
+ "--allow-destructive": Boolean,
6568
+ "--yes": Boolean,
6569
+ "-y": "--yes"
6570
+ },
6571
+ "db generate": {
6572
+ "--collections": String,
6573
+ "-c": "--collections"
6574
+ },
6575
+ "db migrate": {
6576
+ "--baseline": String,
6577
+ "--refuse-destructive": Boolean
6578
+ },
6579
+ "schema generate": {
6580
+ "--collections": String,
6581
+ "-c": "--collections",
6582
+ "--output": String,
6583
+ "-o": "--output",
6584
+ "--out": "--output",
6585
+ "--watch": Boolean,
6586
+ "-w": "--watch"
6587
+ },
6588
+ "schema introspect": {
6589
+ "--output": String,
6590
+ "-o": "--output",
6591
+ "--out": "--output",
6592
+ "--collections": String,
6593
+ "-c": "--collections",
6594
+ "--force": Boolean,
6595
+ "-f": "--force",
6596
+ "--schema": String,
6597
+ "--data-inference": Boolean,
6598
+ "--no-data-inference": Boolean
6599
+ },
6600
+ "schema stale": {
6601
+ "--collections": String,
6602
+ "-c": "--collections",
6603
+ "--output": String,
6604
+ "-o": "--output",
6605
+ "--out": "--output",
6606
+ "--fix": Boolean
6607
+ }
6608
+ };
6609
+ /**
6610
+ * The `--collections` path the user typed, or `null` if they typed none.
6611
+ *
6612
+ * Read once, at the entry point, because every command that takes it re-enters
6613
+ * the generators with the same line and each of them resolved it again — which
6614
+ * is how "Collections path not found" came to be printed four times before the
6615
+ * real output, and how a path that does not exist got as far as *writing* an
6616
+ * empty schema.
6617
+ *
6618
+ * Permissive, and it has to be: {@link assertKnownFlags} has already judged the
6619
+ * line, and `db push` carries flags the `--collections` spec does not name.
6620
+ */
6621
+ function collectionsPathIn(args) {
6622
+ try {
6623
+ return (0, import_arg.default)({
6624
+ "--collections": String,
6625
+ "-c": "--collections"
6626
+ }, {
6627
+ argv: args.slice(2),
6628
+ permissive: true
6629
+ })["--collections"] ?? null;
6630
+ } catch {
6631
+ return null;
6632
+ }
6633
+ }
6634
+ /**
6635
+ * Reject a flag the named command does not take.
6636
+ *
6637
+ * `args` is the driver's whole line — `["db", "push", …]` — so the flags are
6638
+ * read from `args.slice(2)`, past the two command words.
6639
+ *
6640
+ * Throws rather than exiting: `runPluginCommand`'s caller already turns a
6641
+ * thrown error into one red line and exit 1, and a thrown error is what the
6642
+ * tests can see.
6643
+ */
6644
+ function assertKnownFlags(domain, subcommand, args) {
6645
+ if (!subcommand) return;
6646
+ const spec = DRIVER_FLAG_SPECS[`${domain} ${subcommand}`];
6647
+ if (!spec) return;
6648
+ const argv = resolveSwitchValues({
6649
+ ...RELAYED_FLAGS,
6650
+ ...spec
6651
+ }, args.slice(2), `${domain} ${subcommand}`, domain);
6652
+ try {
6653
+ (0, import_arg.default)({
6654
+ ...RELAYED_FLAGS,
6655
+ ...spec
6656
+ }, { argv });
6657
+ } catch (err) {
6658
+ const unknown = unknownFlagIn(err, args.slice(2));
6659
+ if (unknown === null) throw err;
6660
+ throw new Error(unknownOptionSentence(`${domain} ${subcommand}`, domain, unknown, spec));
6661
+ }
6662
+ }
6663
+ /**
6664
+ * The sentence an undeclared flag is refused with, in the words the CLI's own
6665
+ * parser uses: "`rebase db push` has no option --dry-rn — did you mean
6666
+ * --dry-run? Nothing was run."
6667
+ *
6668
+ * `token` is the whole argument `arg` refused, which is not always a flag: one
6669
+ * argument holding a flag and its value, quoted together
6670
+ * (`"--from postgres://u:pw@h/db"`), is refused whole. That one is named as
6671
+ * what it is, and what it quotes is password-masked; no other part of an
6672
+ * argument is quoted at all.
6673
+ *
6674
+ * @param command the command as typed: `"db push"`.
6675
+ * @param help the command whose `--help` the sentence names.
6676
+ * @param spec the command's own flags; the relayed ones are offered too.
6677
+ */
6678
+ function unknownOptionSentence(command, help, token, spec) {
6679
+ const full = {
6680
+ ...RELAYED_FLAGS,
6681
+ ...spec
6682
+ };
6683
+ const name = token.split(/[=\s]/)[0];
6684
+ const suggestion = closestWord(name, Object.keys(full).filter((flag) => flag.startsWith("--")));
6685
+ const tail = ` Nothing was run. See \`rebase ${help} --help\`.`;
6686
+ if (/\s/.test(token.trim())) {
6687
+ const flag = name in full ? name : suggestion;
6688
+ const how = flag ? ` Write them as two arguments, ${flag} <value>, or as ${flag}=<value>.` : " Write a flag and its value as two arguments.";
6689
+ return `\`rebase ${command}\` has no option "${redactConnectionPasswords(token)}": that is a flag and a value in one argument, quoted together.${how}${tail}`;
6690
+ }
6691
+ const own = Object.keys(spec).filter((flag) => flag.startsWith("--"));
6692
+ const takes = own.length > 0 ? `it takes ${own.join(", ")}` : "it takes no options of its own";
6693
+ return `\`rebase ${command}\` has no option ${name}` + (suggestion ? ` — did you mean ${suggestion}?` : ` — ${takes}.`) + tail;
6694
+ }
6695
+ /** What a flag resolves to, through its alias (`"-y": "--yes"`). */
6696
+ function handlerOf(spec, flag) {
6697
+ const declared = spec[flag];
6698
+ return typeof declared === "string" ? spec[declared] : declared;
6699
+ }
6700
+ /** A flag that takes no value: on when given, off when left out. */
6701
+ function isSwitch(handler) {
6702
+ return handler === Boolean || Array.isArray(handler) && handler[0] === Boolean;
6703
+ }
6704
+ /** The values a switch reads as on, and as off, after its `=`. */
6705
+ var SWITCH_ON = /^(?:true|1)$/i;
6706
+ var SWITCH_OFF = /^(?:false|0)$/i;
6707
+ /**
6708
+ * A line with every `--switch=value` resolved, before `arg` reads it: `=true`
6709
+ * or `=1` is the switch alone, `=false` or `=0` drops it, and any other value
6710
+ * is refused.
6711
+ *
6712
+ * `arg` drops the value of a flag that takes none and turns the flag on, so
6713
+ * `db push --dry-run=false` was a dry run and `--allow-destructive=false`
6714
+ * allowed the destructive statements it was typed to forbid. `=true` kept
6715
+ * working by the same accident, and scripts write it, so both readings a value
6716
+ * can have are honoured and nothing else is guessed at. Past `--` every word
6717
+ * is a positional, so nothing there is read.
6718
+ *
6719
+ * @param command the command as typed, for the message: `"db push"`.
6720
+ * @param help the command whose `--help` the message names.
6721
+ */
6722
+ function resolveSwitchValues(spec, argv, command, help = command) {
6723
+ const resolved = [];
6724
+ for (let index = 0; index < argv.length; index += 1) {
6725
+ const word = argv[index];
6726
+ if (word === "--") {
6727
+ resolved.push(...argv.slice(index));
6728
+ break;
6729
+ }
6730
+ const flag = word.startsWith("--") && word.includes("=") ? word.slice(0, word.indexOf("=")) : null;
6731
+ if (flag === null || !isSwitch(handlerOf(spec, flag))) {
6732
+ resolved.push(word);
6733
+ continue;
6734
+ }
6735
+ const value = word.slice(flag.length + 1);
6736
+ if (SWITCH_ON.test(value)) resolved.push(flag);
6737
+ else if (!SWITCH_OFF.test(value)) throw new Error(`\`rebase ${command}\` cannot read ${redactConnectionPasswords(word)}: ${flag} is a switch, and after its = it takes true or 1 to turn it on, false or 0 to turn it off. Nothing was run. See \`rebase ${help} --help\`.`);
6738
+ }
6739
+ return resolved;
6740
+ }
6741
+ /**
6742
+ * A driver command's line, `["<domain>", "<subcommand>", …]`, with its
6743
+ * switches' values resolved by {@link resolveSwitchValues} against the
6744
+ * command's spec: what `runPluginCommand` hands every parser after it, so a
6745
+ * permissive one never reads `--allow-destructive=false` as on. A command with
6746
+ * no spec here comes back as it was.
6747
+ */
6748
+ function resolveDriverSwitches(domain, subcommand, args) {
6749
+ const spec = subcommand ? DRIVER_FLAG_SPECS[`${domain} ${subcommand}`] : void 0;
6750
+ if (!spec) return [...args];
6751
+ return [...args.slice(0, 2), ...resolveSwitchValues({
6752
+ ...RELAYED_FLAGS,
6753
+ ...spec
6754
+ }, args.slice(2), `${domain} ${subcommand}`, domain)];
6755
+ }
6756
+ /**
6757
+ * The argument `arg` refused as undeclared, whole, or `null` for any other
6758
+ * failure.
6759
+ *
6760
+ * arg's wording is `unknown or unexpected option: --targt-db`, naming the
6761
+ * argument up to its first `=`. An argument with a space in it is named past
6762
+ * the space too, so the match runs to the end of the message; and the word
6763
+ * in `argv` it came from is returned, `=` and all, so a refusal that quotes it
6764
+ * quotes what was typed.
6765
+ */
6766
+ function unknownFlagIn(err, argv) {
6767
+ if (!(err instanceof Error) || !("code" in err) || err.code !== "ARG_UNKNOWN_OPTION") return null;
6768
+ const named = /option: ([\s\S]+)$/.exec(err.message)?.[1];
6769
+ if (named === void 0) return null;
6770
+ return argv.find((word) => word === named || word.startsWith(`${named}=`)) ?? named;
6771
+ }
6772
+ /**
6773
+ * The word in `known` that `typed` was probably meant to be: one edit away
6774
+ * (`--targt-db`), or two neighbouring letters swapped (`--clena`, `--froce`),
6775
+ * which `suggestNearMiss` counts as two edits and so never offers.
6776
+ */
6777
+ function closestWord(typed, known) {
6778
+ return suggestNearMiss(known, typed) ?? transposedFrom(known, typed);
6779
+ }
6780
+ function transposedFrom(known, typed) {
6781
+ return known.find((candidate) => {
6782
+ if (candidate.length !== typed.length || candidate === typed) return false;
6783
+ const differ = [...candidate].flatMap((letter, index) => letter === typed[index] ? [] : [index]);
6784
+ return differ.length === 2 && differ[1] === differ[0] + 1 && candidate[differ[0]] === typed[differ[1]] && candidate[differ[1]] === typed[differ[0]];
6785
+ });
6786
+ }
6787
+ /**
6788
+ * Parse a command that owns its argument handling, refusing what it does not
6789
+ * declare.
6790
+ *
6791
+ * `db backup`, `db restore` and `db backups list` parsed permissively, so an
6792
+ * undeclared flag became a positional and was ignored: `db restore <dump>
6793
+ * --targt-db x --create-db --yes` dropped the misspelled target and restored
6794
+ * into the live database. A typo is refused here before anything runs, naming
6795
+ * the declared flag it is one edit from, or every flag the command takes when
6796
+ * none is that close.
6797
+ *
6798
+ * @param argv the words after the command, e.g. `rawArgs.slice(2)`.
6799
+ * @param command the command as typed, for the message: `"db restore"`.
6800
+ */
6801
+ function parseCommandFlags(spec, argv, command) {
6802
+ const full = {
6803
+ ...RELAYED_FLAGS,
6804
+ ...spec
6805
+ };
6806
+ try {
6807
+ return (0, import_arg.default)(full, { argv: resolveSwitchValues(full, argv, command) });
6808
+ } catch (err) {
6809
+ const unknown = unknownFlagIn(err, argv);
6810
+ if (unknown === null) throw err;
6811
+ throw new Error(unknownOptionSentence(command, command, unknown, spec));
6812
+ }
6813
+ }
6814
+ //#endregion
6815
+ //#region src/branch-argv.ts
6816
+ /**
6817
+ * Argument shapes for `rebase db branch`, with no runtime dependencies.
6818
+ *
6819
+ * Its own module for the same reason `schema/atlas-argv.ts` is: `cli.ts` pulls
6820
+ * in chalk, execa and the driver runtime, so a unit test that imports it cannot
6821
+ * run. Argv parsing is the part most worth testing and the part least in need
6822
+ * of any of that.
6823
+ */
6824
+ /**
6825
+ * The flags each driver-side `db branch` action takes, besides the ones the CLI
6826
+ * relays on every line (`--database-url`, `--docker`, `--debug`).
6827
+ *
6828
+ * `switch` is absent: the CLI answers it before the driver is ever spawned.
6829
+ * An action not listed here is not checked, so the dispatch can say it does
6830
+ * not exist in its own words.
6831
+ */
6832
+ var BRANCH_ACTION_FLAGS = {
6833
+ create: {
6834
+ "--from": String,
6835
+ "--force": Boolean
6836
+ },
6837
+ list: {},
6838
+ info: {},
6839
+ delete: {
6840
+ "--force": Boolean,
6841
+ "--yes": Boolean,
6842
+ "-y": "--yes"
6843
+ },
6844
+ prune: {
6845
+ "--older-than": String,
6846
+ "--include-dev-diff": Boolean,
6847
+ "--yes": Boolean,
6848
+ "-y": "--yes"
6849
+ }
6850
+ };
6851
+ /**
6852
+ * Refuse a flag `action` does not take, naming the one it was probably meant
6853
+ * to be — the same sentence `db backup` and `db restore` say.
6854
+ *
6855
+ * Throws: the driver's entry turns a thrown error into one red line and exit 1,
6856
+ * and this runs before anything connects.
6857
+ */
6858
+ function assertKnownBranchFlags(action, rest) {
6859
+ const spec = BRANCH_ACTION_FLAGS[action];
6860
+ if (!spec) return;
6861
+ const full = {
6862
+ ...RELAYED_FLAGS,
6863
+ ...spec
6864
+ };
6865
+ const argv = resolveSwitchValues(full, rest, `db branch ${action}`, "db branch");
6866
+ try {
6867
+ (0, import_arg.default)(full, { argv });
6868
+ } catch (error) {
6869
+ const unknown = unknownFlagIn(error, rest);
6870
+ if (unknown === null) throw error;
6871
+ throw new Error(unknownOptionSentence(`db branch ${action}`, "db branch", unknown, spec));
6872
+ }
6873
+ }
6874
+ /**
6875
+ * A `db branch` line, `["db", "branch", <action>, …]`, with its switches'
6876
+ * values resolved against the action's flags (see `resolveSwitchValues`):
6877
+ * what the branch dispatch reads, so `prune --yes=false` is not a yes. An
6878
+ * action the table does not list comes back as it was.
6879
+ */
6880
+ function resolveBranchSwitches(rawArgs) {
6881
+ const action = rawArgs[2];
6882
+ const spec = action === void 0 ? void 0 : BRANCH_ACTION_FLAGS[action];
6883
+ if (!spec) return [...rawArgs];
6884
+ return [...rawArgs.slice(0, 3), ...resolveSwitchValues({
6885
+ ...RELAYED_FLAGS,
6886
+ ...spec
6887
+ }, rawArgs.slice(3), `db branch ${action}`, "db branch")];
6888
+ }
6889
+ /**
6890
+ * Words on a `db branch` command line that no argument accounts for.
6891
+ *
6892
+ * `rebase db branch create alpha beta` created a branch called `alpha` and
6893
+ * threw `beta` away without a word. The shapes that produces are all quiet and
6894
+ * all wrong: an unquoted name (`create my feature` → `my`), a flag written
6895
+ * without its dashes (`create feat from main` → `feat`), a shell that split
6896
+ * something you thought was one token. In each case the command succeeds and
6897
+ * the branch is not the one asked for — and branch names are the thing you
6898
+ * later type to switch, delete, or point a deploy at.
6899
+ *
6900
+ * A flag the action does not take is refused outright, by throwing — see
6901
+ * {@link BRANCH_ACTION_FLAGS}. It was let through on the reasoning that a
6902
+ * subcommand added later might take flags this file had never heard of; what
6903
+ * that bought was every typo running without the flag it meant:
6904
+ * `prune --older-then 1d --yes` pruned by no age, `create x --froce` ran
6905
+ * without --force. A new action gets its line in the table. The value after a
6906
+ * flag that takes one is skipped: it is that flag's argument, not a stray word.
6907
+ *
6908
+ * @param words The command's own arguments: action, name, then the rest.
6909
+ */
6910
+ function unexpectedBranchArgs(words) {
6911
+ if (words[0]) assertKnownBranchFlags(words[0], words.slice(1));
6912
+ const extras = [];
6913
+ let seenName = false;
6914
+ for (let index = 1; index < words.length; index += 1) {
6915
+ const word = words[index];
6916
+ if (word.startsWith("-")) {
6917
+ if (TAKES_A_VALUE.has(word.split("=")[0])) index += 1;
6918
+ continue;
6919
+ }
6920
+ if (!seenName) {
6921
+ seenName = true;
6922
+ continue;
6923
+ }
6924
+ extras.push(word);
6925
+ }
6926
+ return extras;
6927
+ }
6928
+ /**
6929
+ * Branch-line flags whose next word belongs to them.
6930
+ *
6931
+ * `--from` was the only one listed, and `--database-url` is the one that bit:
6932
+ * `rebase db branch list --database-url postgres://…` — which the CLI itself
6933
+ * appends when the checkout is on a branch, so `rebase.branches` is read in the
6934
+ * parent where it lives — answered `✗ Unexpected argument: postgres://…`. The
6935
+ * `=` form carries its value in the same word and needs no skip.
6936
+ */
6937
+ var TAKES_A_VALUE = /* @__PURE__ */ new Set([
6938
+ "--from",
6939
+ "--older-than",
6940
+ "--database-url"
6941
+ ]);
6942
+ //#endregion
6943
+ //#region src/backup-argv.ts
6944
+ /**
6945
+ * @param rawArgs the driver's whole line, `["db", "backup", …]`.
6946
+ */
6947
+ function backupActionOf(rawArgs) {
6948
+ return rawArgs[2] === "list" ? "list" : "create";
6949
+ }
6950
+ //#endregion
6951
+ //#region src/db-subcommands.ts
6952
+ /**
6953
+ * The `db` subcommands this driver dispatches, with no runtime dependencies.
6954
+ *
6955
+ * Its own module so the dispatch in `cli.ts` can name them without loading
6956
+ * what judges their lines (`db-command-line.ts` reaches the backup module,
6957
+ * which `cli.ts` imports only when a backup command runs).
6958
+ */
6959
+ var DRIVER_DB_SUBCOMMANDS = [
6960
+ "push",
6961
+ "generate",
6962
+ "migrate",
6963
+ "branch",
6964
+ "backup",
6965
+ "restore",
6966
+ "backups"
6967
+ ];
6968
+ /** Is `word` a `db` subcommand this driver answers? */
6969
+ function isDriverDbSubcommand(word) {
6970
+ return DRIVER_DB_SUBCOMMANDS.some((subcommand) => subcommand === word);
6971
+ }
6972
+ //#endregion
6973
+ export { rlsRuntimeIsCurrent as _, resolveBranchSwitches as a, assertKnownFlags as c, parseCommandFlags as d, parseDriverLine as f, dropLegacyAuthSchema as g, RLS_BOOTSTRAP_STATEMENTS as h, assertKnownBranchFlags as i, closestWord as l, RLS_BOOTSTRAP_SQL as m, isDriverDbSubcommand as n, unexpectedBranchArgs as o, resolveDriverSwitches as p, backupActionOf as r, RELAYED_FLAGS as s, DRIVER_DB_SUBCOMMANDS as t, collectionsPathIn as u, rls_bootstrap_sql_exports as v, execa as y };
6522
6974
 
6523
- //# sourceMappingURL=rls-bootstrap-sql-Bd-hJk08.js.map
6975
+ //# sourceMappingURL=db-subcommands-BPoHCxJR.js.map