@rebasepro/server-postgres 0.24.0 → 0.24.1-canary.gcb918fc

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 (172) hide show
  1. package/README.md +16 -0
  2. package/dist/{BranchService-BRt78gfa.js → BranchService-Bsn2wfaj.js} +3 -2
  3. package/dist/{BranchService-BRt78gfa.js.map → BranchService-Bsn2wfaj.js.map} +1 -1
  4. package/dist/PostgresBackendDriver.d.ts +91 -2
  5. package/dist/PostgresBootstrapper.d.ts +101 -2
  6. package/dist/auth/ensure-tables.d.ts +12 -0
  7. package/dist/auth/services.d.ts +6 -0
  8. package/dist/backup/backup-cli.d.ts +14 -0
  9. package/dist/backup/backup-service.d.ts +2 -2
  10. package/dist/backup/pg-binary.d.ts +5 -0
  11. package/dist/{backup-cli-DW5p9_zv.js → backup-cli-DnpJi6I7.js} +37 -29
  12. package/dist/backup-cli-DnpJi6I7.js.map +1 -0
  13. package/dist/{backup-service-EwcDVG-8.js → backup-service-BTBB7RXn.js} +55 -21
  14. package/dist/backup-service-BTBB7RXn.js.map +1 -0
  15. package/dist/boot-ddl-DVpsFN6r.js +105 -0
  16. package/dist/boot-ddl-DVpsFN6r.js.map +1 -0
  17. package/dist/cli-console-Ca6ZlAVU.js +154 -0
  18. package/dist/cli-console-Ca6ZlAVU.js.map +1 -0
  19. package/dist/cli-console.d.ts +39 -0
  20. package/dist/cli-errors-CaI4ntyD.js +1919 -0
  21. package/dist/cli-errors-CaI4ntyD.js.map +1 -0
  22. package/dist/cli-errors.d.ts +51 -5
  23. package/dist/{cli-flags-BglvpjHv.js → cli-flags-JNI-pwSf.js} +6 -3
  24. package/dist/cli-flags-JNI-pwSf.js.map +1 -0
  25. package/dist/cli-helpers.d.ts +40 -0
  26. package/dist/cli-output.d.ts +16 -28
  27. package/dist/cli-push.d.ts +87 -0
  28. package/dist/cli.js +566 -182
  29. package/dist/cli.js.map +1 -1
  30. package/dist/{column-plan-helpers-1-LQD0yI.js → column-plan-helpers-drZIsSNf.js} +10 -4
  31. package/dist/{column-plan-helpers-1-LQD0yI.js.map → column-plan-helpers-drZIsSNf.js.map} +1 -1
  32. package/dist/{databasePoolManager-Bj5FbeAs.js → connection-C9mT8bgf.js} +24 -112
  33. package/dist/connection-C9mT8bgf.js.map +1 -0
  34. package/dist/connection.d.ts +13 -2
  35. package/dist/databasePoolManager-BIuewidb.js +119 -0
  36. package/dist/databasePoolManager-BIuewidb.js.map +1 -0
  37. package/dist/{ensure-collection-tables-kkkHk8oo.js → deferred-index-build-DP1_SNFo.js} +484 -346
  38. package/dist/deferred-index-build-DP1_SNFo.js.map +1 -0
  39. package/dist/{doctor-C-sYWbmt.js → doctor-C4WiftHm.js} +63 -52
  40. package/dist/doctor-C4WiftHm.js.map +1 -0
  41. package/dist/ensure-collection-policies-CXpbeNag.js +541 -0
  42. package/dist/ensure-collection-policies-CXpbeNag.js.map +1 -0
  43. package/dist/ensure-collection-tables-BhsU6qUE.js +532 -0
  44. package/dist/ensure-collection-tables-BhsU6qUE.js.map +1 -0
  45. package/dist/{ensure-tables-BmI_tRxc.js → ensure-tables-CVm_yvzb.js} +173 -77
  46. package/dist/ensure-tables-CVm_yvzb.js.map +1 -0
  47. package/dist/enum-labels-kept-D8fI1MoX.js +56 -0
  48. package/dist/enum-labels-kept-D8fI1MoX.js.map +1 -0
  49. package/dist/generate-drizzle-schema-Bz52jH2h.js +57 -0
  50. package/dist/generate-drizzle-schema-Bz52jH2h.js.map +1 -0
  51. package/dist/{generate-drizzle-schema-logic-sSFDp6LR.js → generate-drizzle-schema-logic-B74WN37S.js} +5 -5
  52. package/dist/generate-drizzle-schema-logic-B74WN37S.js.map +1 -0
  53. package/dist/generate-files-CdEckX6c.js +199 -0
  54. package/dist/generate-files-CdEckX6c.js.map +1 -0
  55. package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js → generate-postgres-ddl-logic-B64O2oZF.js} +3 -3
  56. package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js.map → generate-postgres-ddl-logic-B64O2oZF.js.map} +1 -1
  57. package/dist/generated-sql.d.ts +8 -2
  58. package/dist/history/HistoryService.d.ts +64 -5
  59. package/dist/history/ensure-history-table.d.ts +63 -4
  60. package/dist/index.d.ts +1 -0
  61. package/dist/index.es.js +139 -19236
  62. package/dist/index.es.js.map +1 -1
  63. package/dist/{introspect-db-logic-kCETE8TY.js → introspect-db-logic-C-Di8dA9.js} +44 -6
  64. package/dist/introspect-db-logic-C-Di8dA9.js.map +1 -0
  65. package/dist/{introspect-db-queries-C_Q5VgQw.js → introspect-db-queries-D6kAqReI.js} +23 -1
  66. package/dist/introspect-db-queries-D6kAqReI.js.map +1 -0
  67. package/dist/open-rebase-CbOur0TU.js +20858 -0
  68. package/dist/open-rebase-CbOur0TU.js.map +1 -0
  69. package/dist/open-rebase.d.ts +86 -0
  70. package/dist/pg-error-utils-vJezlXdI.js +388 -0
  71. package/dist/pg-error-utils-vJezlXdI.js.map +1 -0
  72. package/dist/{plan-schema-DU9exq6C.js → plan-schema-B1YF_tYq.js} +151 -41
  73. package/dist/plan-schema-B1YF_tYq.js.map +1 -0
  74. package/dist/{policy-drift-B-J2hhm0.js → policy-drift-Dm8i-s1J.js} +23 -6
  75. package/dist/policy-drift-Dm8i-s1J.js.map +1 -0
  76. package/dist/push-index-prebuild-Db4AQF4i.js +45 -0
  77. package/dist/push-index-prebuild-Db4AQF4i.js.map +1 -0
  78. package/dist/push-legacy-renames-BK6ilQq2.js +34 -0
  79. package/dist/push-legacy-renames-BK6ilQq2.js.map +1 -0
  80. package/dist/{render-ddl-Ds2t_d9V.js → render-ddl-CtC3y9Ol.js} +8 -4
  81. package/dist/render-ddl-CtC3y9Ol.js.map +1 -0
  82. package/dist/{rls-bootstrap-sql-_KNnjanK.js → rls-bootstrap-sql-RQUljnJ1.js} +125 -1270
  83. package/dist/rls-bootstrap-sql-RQUljnJ1.js.map +1 -0
  84. package/dist/{rls-enforcement-CfXOJJaW.js → rls-enforcement-DvzqlaL1.js} +129 -17
  85. package/dist/rls-enforcement-DvzqlaL1.js.map +1 -0
  86. package/dist/schema/auth-schema.d.ts +2 -2
  87. package/dist/schema/boot-ddl.d.ts +47 -0
  88. package/dist/schema/collection-index.d.ts +45 -0
  89. package/dist/schema/column-plan-helpers.d.ts +5 -0
  90. package/dist/schema/deferred-index-build.d.ts +131 -0
  91. package/dist/schema/destructive-sql.d.ts +7 -0
  92. package/dist/schema/doctor-cli.js +110 -6
  93. package/dist/schema/doctor-cli.js.map +1 -1
  94. package/dist/schema/doctor-search-scale.d.ts +45 -0
  95. package/dist/schema/doctor.d.ts +20 -1
  96. package/dist/schema/ensure-collection-policies.d.ts +73 -35
  97. package/dist/schema/ensure-collection-tables.d.ts +56 -3
  98. package/dist/schema/enum-labels-kept.d.ts +26 -0
  99. package/dist/schema/generate-drizzle-schema.js +1 -1
  100. package/dist/schema/generate-files.d.ts +44 -0
  101. package/dist/schema/generate-next-step.d.ts +0 -13
  102. package/dist/schema/generate-postgres-ddl.js +10 -81
  103. package/dist/schema/generate-postgres-ddl.js.map +1 -1
  104. package/dist/schema/introspect-db-logic.d.ts +12 -0
  105. package/dist/schema/introspect-db-queries.d.ts +11 -1
  106. package/dist/schema/introspect-db-structure.d.ts +10 -0
  107. package/dist/schema/introspect-db.js +4 -5
  108. package/dist/schema/introspect-db.js.map +1 -1
  109. package/dist/schema/migration-post-process.d.ts +34 -0
  110. package/dist/schema/plan/diff-plan.d.ts +126 -0
  111. package/dist/schema/plan/types.d.ts +8 -0
  112. package/dist/schema/push-index-prebuild.d.ts +25 -0
  113. package/dist/schema/push-legacy-renames.d.ts +20 -0
  114. package/dist/schema/rls-bootstrap-sql.d.ts +15 -0
  115. package/dist/security/rls-enforcement.d.ts +32 -4
  116. package/dist/services/FetchService.d.ts +58 -8
  117. package/dist/services/PersistService.d.ts +15 -0
  118. package/dist/services/RelationService.d.ts +88 -3
  119. package/dist/services/cdc/CdcListener.d.ts +17 -6
  120. package/dist/services/cdc/trigger-cdc.d.ts +151 -27
  121. package/dist/services/channel-bus/index.d.ts +1 -1
  122. package/dist/services/channel-history.d.ts +15 -4
  123. package/dist/services/collection-helpers.d.ts +15 -0
  124. package/dist/services/field-viewer.d.ts +15 -1
  125. package/dist/services/pg-notify-listener.d.ts +7 -0
  126. package/dist/services/realtimeService.d.ts +314 -14
  127. package/dist/services/row-pipeline.d.ts +16 -9
  128. package/dist/services/socket-liveness.d.ts +42 -2
  129. package/dist/services/sql-script.d.ts +207 -3
  130. package/dist/services/vector-iterative-scan.d.ts +40 -0
  131. package/dist/services/write-depth.d.ts +6 -0
  132. package/dist/services/write-transaction-scope.d.ts +9 -0
  133. package/dist/socket-opt-ins.d.ts +64 -0
  134. package/dist/source-DBDbBTL4.js +811 -0
  135. package/dist/source-DBDbBTL4.js.map +1 -0
  136. package/dist/tsx-loader.d.ts +14 -0
  137. package/dist/utils/drizzle-conditions.d.ts +21 -1
  138. package/dist/utils/error-cause.d.ts +7 -0
  139. package/dist/utils/pg-error-utils.d.ts +2 -4
  140. package/dist/utils/result-rows.d.ts +10 -0
  141. package/dist/websocket-BLGc5yhs.js +1604 -0
  142. package/dist/websocket-BLGc5yhs.js.map +1 -0
  143. package/dist/websocket.d.ts +13 -0
  144. package/package.json +7 -7
  145. package/dist/backup-cli-DW5p9_zv.js.map +0 -1
  146. package/dist/backup-service-EwcDVG-8.js.map +0 -1
  147. package/dist/cli-errors-DsA-K9uP.js +0 -893
  148. package/dist/cli-errors-DsA-K9uP.js.map +0 -1
  149. package/dist/cli-flags-BglvpjHv.js.map +0 -1
  150. package/dist/cli-output-CNdMql-L.js +0 -47
  151. package/dist/cli-output-CNdMql-L.js.map +0 -1
  152. package/dist/collection-index-DdnsxiJ_.js +0 -286
  153. package/dist/collection-index-DdnsxiJ_.js.map +0 -1
  154. package/dist/databasePoolManager-Bj5FbeAs.js.map +0 -1
  155. package/dist/doctor-C-sYWbmt.js.map +0 -1
  156. package/dist/ensure-collection-policies-B1ureSIV.js +0 -160
  157. package/dist/ensure-collection-policies-B1ureSIV.js.map +0 -1
  158. package/dist/ensure-collection-tables-kkkHk8oo.js.map +0 -1
  159. package/dist/ensure-tables-BmI_tRxc.js.map +0 -1
  160. package/dist/generate-drizzle-schema-93M0lUxK.js +0 -123
  161. package/dist/generate-drizzle-schema-93M0lUxK.js.map +0 -1
  162. package/dist/generate-drizzle-schema-logic-sSFDp6LR.js.map +0 -1
  163. package/dist/introspect-db-logic-kCETE8TY.js.map +0 -1
  164. package/dist/introspect-db-queries-C_Q5VgQw.js.map +0 -1
  165. package/dist/plan-schema-DU9exq6C.js.map +0 -1
  166. package/dist/policy-drift-B-J2hhm0.js.map +0 -1
  167. package/dist/render-ddl-Ds2t_d9V.js.map +0 -1
  168. package/dist/rls-bootstrap-sql-_KNnjanK.js.map +0 -1
  169. package/dist/rls-enforcement-CfXOJJaW.js.map +0 -1
  170. package/dist/source-Br7L7GOI.js +0 -410
  171. package/dist/source-Br7L7GOI.js.map +0 -1
  172. package/dist/utils/sql-redaction.d.ts +0 -21
@@ -6,9 +6,13 @@ import type { RawSqlRunner } from "../../security/rls-enforcement.js";
6
6
  * — like Supabase Realtime — sees *every* commit regardless of how it was made.
7
7
  * When logical replication is unavailable (managed Postgres without
8
8
  * `wal_level=logical`, no replication privilege, no `REPLICA IDENTITY`), this
9
- * trigger-based fallback provides the same guarantee at the row level:
9
+ * trigger-based fallback provides the same guarantee:
10
10
  *
11
- * AFTER INSERT/UPDATE/DELETE trigger → pg_notify('rebase_cdc', payload)
11
+ * AFTER INSERT/UPDATE/DELETE/TRUNCATE statement trigger → pg_notify('rebase_cdc', payload)
12
+ *
13
+ * once per statement, naming the changed rows by key in batches of about a
14
+ * thousand — a 1M-row UPDATE is ~1,000 notifications, where a row trigger sent
15
+ * a million into Postgres's shared notification queue, to every instance.
12
16
  *
13
17
  * A single dedicated LISTEN client per backend instance consumes the channel
14
18
  * (see {@link CdcListener}) and feeds the change into the existing
@@ -21,24 +25,88 @@ import type { RawSqlRunner } from "../../security/rls-enforcement.js";
21
25
  */
22
26
  /** Postgres NOTIFY channel carrying database-level change events. */
23
27
  export declare const CDC_CHANNEL = "rebase_cdc";
24
- /** Schema-qualified name of the generic trigger function. */
28
+ /**
29
+ * Schema-qualified name of the row-level trigger function: one notification
30
+ * per changed row. What every version before statement-level capture attached
31
+ * everywhere, and still what a partitioned or foreign table gets — see
32
+ * {@link levelForRelkind}.
33
+ */
25
34
  export declare const CDC_TRIGGER_FUNCTION = "rebase.rebase_cdc_notify";
26
- /** Name of the per-table trigger (unqualified — triggers are namespaced by table). */
35
+ /**
36
+ * Schema-qualified name of the statement-level trigger function: one
37
+ * notification per ~1,000 changed rows. See {@link buildCdcFunctionSql}.
38
+ *
39
+ * A function of its own rather than a new body for the row function, because
40
+ * an instance of an older version replaces the row function's body every time
41
+ * it boots: a statement trigger calling it would then run a row trigger's body,
42
+ * for every write, until the next boot of this version.
43
+ */
44
+ export declare const CDC_STATEMENT_FUNCTION = "rebase.rebase_cdc_notify_statement";
45
+ /** Name of the per-table row-level trigger (unqualified — triggers are namespaced by table). */
27
46
  export declare const CDC_TRIGGER_NAME = "rebase_cdc_trigger";
47
+ /** How a table is instrumented: one notification per statement's ~1,000 rows, or one per row. */
48
+ export type CdcTriggerLevel = "statement" | "row";
49
+ /** One trigger this module creates, as `pg_trigger` describes it. */
50
+ interface CdcTriggerSpec {
51
+ name: string;
52
+ /** The function it calls. */
53
+ fn: "row" | "statement";
54
+ /** `CREATE TRIGGER` between the name and `ON`. */
55
+ timing: string;
56
+ /** `CREATE TRIGGER` between the table and `EXECUTE`. */
57
+ forEach: string;
58
+ /** `tgtype`: ROW (1), BEFORE (2), INSERT (4), DELETE (8), UPDATE (16), TRUNCATE (32), INSTEAD (64). */
59
+ type: number;
60
+ /** `tgnewtable` / `tgoldtable`: the transition tables it captures. */
61
+ newTable: string | null;
62
+ oldTable: string | null;
63
+ }
64
+ /**
65
+ * The statement-level triggers a plain table gets. One per event, because
66
+ * Postgres refuses transition tables on a trigger with more than one event.
67
+ * The TRUNCATE one is new with them: a row trigger never fires on `TRUNCATE`,
68
+ * so a truncated table used to be announced to nobody.
69
+ */
70
+ export declare const CDC_STATEMENT_TRIGGERS: readonly CdcTriggerSpec[];
71
+ /**
72
+ * The level a table is instrumented at, by `pg_class.relkind`.
73
+ *
74
+ * A plain table gets statement triggers. A partitioned table keeps the row
75
+ * trigger: Postgres clones a row trigger onto every partition, so a write made
76
+ * straight to a partition is still captured, while a statement trigger on the
77
+ * parent fires only for statements against the parent. A foreign table
78
+ * cannot have transition tables at all.
79
+ */
80
+ export declare const levelForRelkind: (relkind: string | null | undefined) => CdcTriggerLevel;
81
+ /**
82
+ * How long after a boot first converts a table from the row trigger, the
83
+ * statement triggers still announce every change one row per notification.
84
+ *
85
+ * The triggers are the database's, and an instance of the previous version
86
+ * still running beside this one — a rolling deploy, a rollback — reads the
87
+ * same channel with a parser that knows one row per notification: given a
88
+ * batch it sees no key, so its lists refetch but its single-row and
89
+ * many-to-many subscribers hear nothing. While any such instance may be up,
90
+ * the statement triggers speak its protocol; after this window they batch.
91
+ * Every version that batches reads both. A boot of the older version re-attaches its row trigger (it
92
+ * creates a missing one), and the next boot of this one converts it back and
93
+ * re-opens the window, so a rollback is covered the same way.
94
+ */
95
+ export declare const CDC_ROW_COMPAT_MS: number;
28
96
  /**
29
- * SQL that (re)creates the generic CDC trigger function. Safe to run repeatedly:
97
+ * SQL that (re)creates both CDC trigger functions. Safe to run repeatedly:
30
98
  * `CREATE OR REPLACE` updates in place without dropping dependent triggers —
31
- * which is also how a database instrumented by an older version gets this body
32
- * on its next boot, for every table at once, re-attached or not.
33
- *
34
- * The function emits `{ schema, table, op, row }`, and `row` is an **identity,
35
- * never the tuple**. Postgres puts no privilege on `LISTEN`: any role that can
36
- * connect can listen on this channel, whatever it may `SELECT`. When `row` was
37
- * `to_jsonb(NEW)`, a login with no grant on anything received every changed row
38
- * of every instrumented table — `password_hash` and verification tokens from
39
- * the auth table included — past RLS and column grants. The consumer never
40
- * read anything but the key: every subscriber re-reads the row under its own
41
- * scope.
99
+ * which is also how a database instrumented by an older version gets these
100
+ * bodies on its next boot, for every table at once, re-attached or not.
101
+ *
102
+ * Both functions emit `{ schema, table, op, ... }`, and the rows are named by
103
+ * **identity, never the tuple**. Postgres puts no privilege on `LISTEN`: any
104
+ * role that can connect can listen on this channel, whatever it may `SELECT`.
105
+ * When `row` was `to_jsonb(NEW)`, a login with no grant on anything received
106
+ * every changed row of every instrumented table — `password_hash` and
107
+ * verification tokens from the auth table included — past RLS and column
108
+ * grants. The consumer never read anything but the key: every subscriber
109
+ * re-reads the row under its own scope.
42
110
  *
43
111
  * The identity is, in order:
44
112
  * - the columns the trigger was attached with (`TG_ARGV`) — the key the
@@ -49,18 +117,26 @@ export declare const CDC_TRIGGER_NAME = "rebase_cdc_trigger";
49
117
  * maps any more;
50
118
  * - otherwise `id`, if the table has one, and else nothing: a change the
51
119
  * consumer can only treat as collection-wide.
120
+ *
121
+ * `compatUntil` is the end of the window in which the statement function
122
+ * still sends one row per notification — see {@link CDC_ROW_COMPAT_MS}. A
123
+ * timestamp, or `-infinity` for none.
52
124
  */
53
- export declare function buildCdcFunctionSql(): string;
125
+ export declare function buildCdcFunctionSql(options?: {
126
+ compatUntil?: string;
127
+ }): string;
54
128
  /**
55
- * SQL that (re)attaches the CDC trigger to a single table. `DROP ... IF EXISTS`
56
- * before `CREATE` keeps it idempotent and picks up any function signature change.
129
+ * SQL that (re)attaches the CDC triggers to a single table, at `level`.
130
+ * Every trigger this module owns is dropped first, whichever level it was
131
+ * created at, so a table moves between levels — a row trigger left by an
132
+ * older version becomes the statement triggers — in one transaction, with no
133
+ * moment at which a write is announced by neither.
57
134
  *
58
- * `identityColumns` are what the payload names the changed row by — see
135
+ * `identityColumns` are what the payload names the changed rows by — see
59
136
  * {@link buildCdcFunctionSql}. Passed as trigger arguments, so one shared
60
- * function serves every table without a catalogue read per row. Empty means
61
- * "the primary key".
137
+ * function serves every table. Empty means "the primary key".
62
138
  */
63
- export declare function buildCdcTriggerSql(schema: string, table: string, identityColumns?: readonly string[]): string;
139
+ export declare function buildCdcTriggerSql(schema: string, table: string, identityColumns?: readonly string[], level?: CdcTriggerLevel): string;
64
140
  export interface CdcTableRef {
65
141
  schema: string;
66
142
  table: string;
@@ -80,7 +156,7 @@ export interface ProvisionResult {
80
156
  }>;
81
157
  }
82
158
  /**
83
- * Replace an already-installed trigger function with the current body, and
159
+ * Replace the already-installed trigger functions with the current bodies, and
84
160
  * install nothing where there is none.
85
161
  *
86
162
  * For a process that owns the schema but is not provisioning capture on this
@@ -88,15 +164,63 @@ export interface ProvisionResult {
88
164
  * earlier boot attached keep firing whether anything consumes them or not, so
89
165
  * a database instrumented by a version whose function put whole rows on the
90
166
  * channel kept doing so, for every login that cares to `LISTEN`, until capture
91
- * was switched back on. Returns whether a function was there to replace.
167
+ * was switched back on. The statement function keeps its compatibility
168
+ * window. Returns whether a function was there to replace.
92
169
  */
93
170
  export declare function refreshInstalledCdcFunction(run: RawSqlRunner): Promise<boolean>;
94
171
  /**
95
- * Idempotently install the CDC trigger function and per-table triggers.
172
+ * Take change capture off the database: detach every capture trigger and drop
173
+ * both functions. Returns how many triggers were attached.
174
+ *
175
+ * For `REALTIME_CDC=off`. Capture switched off used to leave the triggers in
176
+ * place, so every write to every instrumented table still ran one and sent a
177
+ * notification on a channel nothing listened to. Nothing depends on them once
178
+ * capture is off: a process without capture announces its own writes on the
179
+ * cross-instance channel, and the instances that serve realtime listen there.
180
+ *
181
+ * `DROP FUNCTION … CASCADE` takes the triggers with it in one statement. It
182
+ * waits for each table's lock like any trigger DDL, so it runs with the boot's
183
+ * lock budget and is retried on a lock timeout; a database still contended
184
+ * after that keeps its triggers and the caller reports it.
185
+ */
186
+ export declare function removeTriggerCdc(run: RawSqlRunner): Promise<number>;
187
+ /**
188
+ * What a boot that does not provision capture does with capture an earlier
189
+ * boot installed.
190
+ *
191
+ * - `capture: "off"` — `REALTIME_CDC=off` — removes it ({@link removeTriggerCdc}).
192
+ * - `capture: "not-provisioned"` — capture is wanted but this boot could not
193
+ * install it (no direct URL, `auto` fell back) — leaves the triggers and
194
+ * brings the functions up to date ({@link refreshInstalledCdcFunction}),
195
+ * since they keep firing.
196
+ */
197
+ export declare function settleInstalledCapture(run: RawSqlRunner, options: {
198
+ capture: "off" | "not-provisioned";
199
+ }): Promise<{
200
+ removed: number;
201
+ } | {
202
+ refreshed: boolean;
203
+ }>;
204
+ /**
205
+ * Idempotently install the CDC trigger functions and per-table triggers.
206
+ *
207
+ * A plain table gets the statement-level triggers, a partitioned or foreign
208
+ * one the row trigger ({@link levelForRelkind}). A table whose triggers are
209
+ * already exactly the ones this would create — same function, same events,
210
+ * enabled, same identity arguments — is left alone; one with a trigger
211
+ * missing, disabled, attached with different arguments or at the other level
212
+ * is (re-)attached, all of it in one transaction.
213
+ *
214
+ * Converting a table from a row trigger an older version attached opens the
215
+ * statement function's compatibility window ({@link CDC_ROW_COMPAT_MS}): the
216
+ * instances that attached it may still be listening.
96
217
  *
97
218
  * Runs as the owner (server) connection at bootstrap. A table that does not yet
98
219
  * exist in the database (schema drift) is skipped with a warning rather than
99
220
  * aborting the whole install, so one un-migrated collection cannot disable CDC
100
221
  * for the rest.
101
222
  */
102
- export declare function provisionTriggerCdc(run: RawSqlRunner, tables: CdcTableRef[]): Promise<ProvisionResult>;
223
+ export declare function provisionTriggerCdc(run: RawSqlRunner, tables: CdcTableRef[], options?: {
224
+ now?: number;
225
+ }): Promise<ProvisionResult>;
226
+ export {};
@@ -36,7 +36,7 @@ export interface ChannelBusDeps {
36
36
  * transports this package knows how to construct, so honouring it there would
37
37
  * mean silently discarding the object the application handed us.
38
38
  */
39
- export declare function resolveChannelBusSetting(configured?: ChannelBusSetting): ChannelBusSetting;
39
+ export declare function resolveChannelBusSetting(configured?: ChannelBusSetting, env?: NodeJS.ProcessEnv): ChannelBusSetting;
40
40
  /**
41
41
  * Produce the bus a setting asks for.
42
42
  *
@@ -79,10 +79,21 @@ export interface RetainedAnnouncement {
79
79
  export declare class ChannelHistoryStore {
80
80
  private db;
81
81
  private rules;
82
- /** Resolved rule per channel name, so the match runs once per channel. */
83
- private resolved;
84
- /** Channel → timestamp of its last prune, for {@link PRUNE_THROTTLE_MS}. */
82
+ /**
83
+ * Each rule with its retention resolved, once. Matched per call rather
84
+ * than cached per channel name: a cache keyed by the names clients invent
85
+ * grew by every one of them for the life of the process, and matching a
86
+ * handful of prefixes costs less than the hashing a lookup does.
87
+ */
88
+ private resolvedRules;
89
+ /**
90
+ * Channel → timestamp of its last prune, for {@link PRUNE_THROTTLE_MS}.
91
+ * An entry older than the window throttles nothing, so they are swept once
92
+ * a window: the map holds the channels pruned recently, not every channel
93
+ * ever pruned.
94
+ */
85
95
  private lastPruned;
96
+ private nextPruneSweepAt;
86
97
  private tablesReady;
87
98
  constructor(db: NodePgDatabase<Record<string, unknown>>, rules?: ChannelRetentionRule[]);
88
99
  /** Whether any channel retains anything at all. */
@@ -140,6 +151,6 @@ export declare class ChannelHistoryStore {
140
151
  * volume, which is what makes retention affordable on a hot channel.
141
152
  */
142
153
  prune(channel: string, retention: ResolvedRetention): Promise<number>;
143
- /** Forget throttle and match caches. Called on shutdown. */
154
+ /** Forget the prune throttle. Called on shutdown. */
144
155
  clear(): void;
145
156
  }
@@ -143,6 +143,21 @@ export declare function requirePrimaryKeys(collection: CollectionConfig, registr
143
143
  * @param collectionPath named in the error.
144
144
  */
145
145
  export declare function primaryKeyColumns(table: PgTable, primaryKeys: PrimaryKeyInfo[], collectionPath: string): AnyPgColumn[];
146
+ /**
147
+ * The column a `joinPath` step names, on a table that may key it either way.
148
+ *
149
+ * A `JoinStep` is written in database terms — `on: { from: "author_id" }` —
150
+ * because there is no collection to translate through: the step names a raw
151
+ * table. A table the boot reads back out of the catalogue is keyed by the
152
+ * *wire* name, `authorId`, while a hand-written Drizzle schema may key it by
153
+ * the column name. Looking the step's name up as a key therefore found
154
+ * nothing on every booted table, and a `via` relation loaded nothing at all.
155
+ *
156
+ * The key first, as the step may already name one; then the column whose SQL
157
+ * name it is. `undefined` when the table has neither, which the caller turns
158
+ * into an error naming the step.
159
+ */
160
+ export declare function columnNamed(table: PgTable, name: string): AnyPgColumn | undefined;
146
161
  /**
147
162
  * The column on the *source* table that a `hasOne`/`hasMany` link points at.
148
163
  *
@@ -1,4 +1,5 @@
1
- import type { FieldViewer } from "@rebasepro/common";
1
+ import { type FieldViewer } from "@rebasepro/common";
2
+ import type { CollectionConfig } from "@rebasepro/types";
2
3
  /**
3
4
  * Run `fn` with `viewer` as the caller every row strip judges against.
4
5
  *
@@ -17,3 +18,16 @@ export declare function withFieldViewer<T>(viewer: FieldViewer | undefined, fn:
17
18
  * that is what establishes the viewer.
18
19
  */
19
20
  export declare function currentFieldViewer(): FieldViewer | undefined;
21
+ /**
22
+ * The names an API caller's query may not see on `collection`: its
23
+ * `excludeFromApi` fields, in every spelling. Empty on the trusted server plane
24
+ * (no viewer), which may filter and sort on those columns — the auth adapter
25
+ * looks rows up by them — and empty with no collection in hand.
26
+ *
27
+ * A query naming one of these is answered exactly as a query naming a column
28
+ * the table does not have. The REST check passes such a name through to this
29
+ * driver rather than refusing it itself, so the two answers come from one throw
30
+ * and cannot drift: a "not readable" there would confirm a column OpenAPI and
31
+ * `list_collections` hide.
32
+ */
33
+ export declare function namesHiddenFromCaller(collection: CollectionConfig | undefined): ReadonlySet<string>;
@@ -46,6 +46,13 @@ export interface PgNotifyListenerOptions {
46
46
  * rejects, so a caller with a fallback can take it.
47
47
  */
48
48
  retryInitialConnect?: boolean;
49
+ /**
50
+ * The `application_name` the connection reports in `pg_stat_activity`.
51
+ * Visible to every role, which is what lets one instance count the others
52
+ * (see `RealtimeService.warnIfMemoryBusOnMultiplePods`). A connection
53
+ * string that sets its own `application_name` wins.
54
+ */
55
+ applicationName?: string;
49
56
  }
50
57
  /**
51
58
  * What a listener can say about itself — read by `/health`.