@rebasepro/server-postgres 0.24.0 → 0.24.1-canary.g56af4a4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BranchService-BRt78gfa.js → BranchService-Bsn2wfaj.js} +3 -2
- package/dist/{BranchService-BRt78gfa.js.map → BranchService-Bsn2wfaj.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +83 -2
- package/dist/auth/ensure-tables.d.ts +12 -0
- package/dist/auth/services.d.ts +6 -0
- package/dist/backup/backup-cli.d.ts +14 -0
- package/dist/backup/backup-service.d.ts +2 -2
- package/dist/backup/pg-binary.d.ts +5 -0
- package/dist/{backup-cli-DW5p9_zv.js → backup-cli-aUfRv16h.js} +37 -29
- package/dist/backup-cli-aUfRv16h.js.map +1 -0
- package/dist/{backup-service-EwcDVG-8.js → backup-service-BTBB7RXn.js} +55 -21
- package/dist/backup-service-BTBB7RXn.js.map +1 -0
- package/dist/boot-ddl-DVpsFN6r.js +105 -0
- package/dist/boot-ddl-DVpsFN6r.js.map +1 -0
- package/dist/cli-errors-CaI4ntyD.js +1919 -0
- package/dist/cli-errors-CaI4ntyD.js.map +1 -0
- package/dist/cli-errors.d.ts +51 -5
- package/dist/{cli-flags-BglvpjHv.js → cli-flags-B-Dawocl.js} +5 -2
- package/dist/cli-flags-B-Dawocl.js.map +1 -0
- package/dist/cli-helpers.d.ts +40 -0
- package/dist/cli-output.d.ts +16 -28
- package/dist/cli-push.d.ts +87 -0
- package/dist/cli.js +563 -182
- package/dist/cli.js.map +1 -1
- package/dist/{column-plan-helpers-1-LQD0yI.js → column-plan-helpers-drZIsSNf.js} +10 -4
- package/dist/{column-plan-helpers-1-LQD0yI.js.map → column-plan-helpers-drZIsSNf.js.map} +1 -1
- package/dist/{databasePoolManager-Bj5FbeAs.js → connection-BPoNILnD.js} +19 -110
- package/dist/connection-BPoNILnD.js.map +1 -0
- package/dist/connection.d.ts +9 -1
- package/dist/databasePoolManager-BkEy2w18.js +119 -0
- package/dist/databasePoolManager-BkEy2w18.js.map +1 -0
- package/dist/{ensure-collection-tables-kkkHk8oo.js → deferred-index-build-DP1_SNFo.js} +484 -346
- package/dist/deferred-index-build-DP1_SNFo.js.map +1 -0
- package/dist/{doctor-C-sYWbmt.js → doctor-C4WiftHm.js} +63 -52
- package/dist/doctor-C4WiftHm.js.map +1 -0
- package/dist/ensure-collection-policies-CXpbeNag.js +541 -0
- package/dist/ensure-collection-policies-CXpbeNag.js.map +1 -0
- package/dist/ensure-collection-tables-BhsU6qUE.js +532 -0
- package/dist/ensure-collection-tables-BhsU6qUE.js.map +1 -0
- package/dist/{ensure-tables-BmI_tRxc.js → ensure-tables-CHsgyLqg.js} +172 -76
- package/dist/ensure-tables-CHsgyLqg.js.map +1 -0
- package/dist/enum-labels-kept-D8fI1MoX.js +56 -0
- package/dist/enum-labels-kept-D8fI1MoX.js.map +1 -0
- package/dist/generate-drizzle-schema-Bz52jH2h.js +57 -0
- package/dist/generate-drizzle-schema-Bz52jH2h.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-sSFDp6LR.js → generate-drizzle-schema-logic-B74WN37S.js} +5 -5
- package/dist/generate-drizzle-schema-logic-B74WN37S.js.map +1 -0
- package/dist/generate-files-CdEckX6c.js +199 -0
- package/dist/generate-files-CdEckX6c.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js → generate-postgres-ddl-logic-B64O2oZF.js} +3 -3
- package/dist/{generate-postgres-ddl-logic-BJsLaVNX.js.map → generate-postgres-ddl-logic-B64O2oZF.js.map} +1 -1
- package/dist/generated-sql.d.ts +8 -2
- package/dist/history/HistoryService.d.ts +38 -6
- package/dist/history/ensure-history-table.d.ts +42 -4
- package/dist/index.es.js +2922 -7475
- package/dist/index.es.js.map +1 -1
- package/dist/{introspect-db-logic-kCETE8TY.js → introspect-db-logic-C-Di8dA9.js} +44 -6
- package/dist/introspect-db-logic-C-Di8dA9.js.map +1 -0
- package/dist/{introspect-db-queries-C_Q5VgQw.js → introspect-db-queries-D6kAqReI.js} +23 -1
- package/dist/introspect-db-queries-D6kAqReI.js.map +1 -0
- package/dist/pg-error-utils-vJezlXdI.js +388 -0
- package/dist/pg-error-utils-vJezlXdI.js.map +1 -0
- package/dist/{plan-schema-DU9exq6C.js → plan-schema-B1YF_tYq.js} +151 -41
- package/dist/plan-schema-B1YF_tYq.js.map +1 -0
- package/dist/{policy-drift-B-J2hhm0.js → policy-drift-Dm8i-s1J.js} +23 -6
- package/dist/policy-drift-Dm8i-s1J.js.map +1 -0
- package/dist/push-index-prebuild-Db4AQF4i.js +45 -0
- package/dist/push-index-prebuild-Db4AQF4i.js.map +1 -0
- package/dist/push-legacy-renames-BK6ilQq2.js +34 -0
- package/dist/push-legacy-renames-BK6ilQq2.js.map +1 -0
- package/dist/{render-ddl-Ds2t_d9V.js → render-ddl-CtC3y9Ol.js} +8 -4
- package/dist/render-ddl-CtC3y9Ol.js.map +1 -0
- package/dist/{rls-bootstrap-sql-_KNnjanK.js → rls-bootstrap-sql-RQUljnJ1.js} +125 -1270
- package/dist/rls-bootstrap-sql-RQUljnJ1.js.map +1 -0
- package/dist/{rls-enforcement-CfXOJJaW.js → rls-enforcement-DvzqlaL1.js} +129 -17
- package/dist/rls-enforcement-DvzqlaL1.js.map +1 -0
- package/dist/schema/auth-schema.d.ts +2 -2
- package/dist/schema/boot-ddl.d.ts +47 -0
- package/dist/schema/collection-index.d.ts +45 -0
- package/dist/schema/column-plan-helpers.d.ts +5 -0
- package/dist/schema/deferred-index-build.d.ts +131 -0
- package/dist/schema/destructive-sql.d.ts +7 -0
- package/dist/schema/doctor-cli.js +110 -6
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-search-scale.d.ts +45 -0
- package/dist/schema/doctor.d.ts +20 -1
- package/dist/schema/ensure-collection-policies.d.ts +73 -35
- package/dist/schema/ensure-collection-tables.d.ts +56 -3
- package/dist/schema/enum-labels-kept.d.ts +26 -0
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +44 -0
- package/dist/schema/generate-next-step.d.ts +0 -13
- package/dist/schema/generate-postgres-ddl.js +10 -81
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/introspect-db-logic.d.ts +12 -0
- package/dist/schema/introspect-db-queries.d.ts +11 -1
- package/dist/schema/introspect-db-structure.d.ts +10 -0
- package/dist/schema/introspect-db.js +4 -5
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/migration-post-process.d.ts +34 -0
- package/dist/schema/plan/diff-plan.d.ts +126 -0
- package/dist/schema/plan/types.d.ts +8 -0
- package/dist/schema/push-index-prebuild.d.ts +25 -0
- package/dist/schema/push-legacy-renames.d.ts +20 -0
- package/dist/schema/rls-bootstrap-sql.d.ts +15 -0
- package/dist/security/rls-enforcement.d.ts +32 -4
- package/dist/services/FetchService.d.ts +58 -8
- package/dist/services/PersistService.d.ts +15 -0
- package/dist/services/RelationService.d.ts +88 -3
- package/dist/services/cdc/CdcListener.d.ts +17 -6
- package/dist/services/cdc/trigger-cdc.d.ts +151 -27
- package/dist/services/channel-history.d.ts +15 -4
- package/dist/services/collection-helpers.d.ts +15 -0
- package/dist/services/field-viewer.d.ts +15 -1
- package/dist/services/pg-notify-listener.d.ts +7 -0
- package/dist/services/realtimeService.d.ts +314 -14
- package/dist/services/row-pipeline.d.ts +16 -9
- package/dist/services/socket-liveness.d.ts +42 -2
- package/dist/services/sql-script.d.ts +207 -3
- package/dist/services/vector-iterative-scan.d.ts +40 -0
- package/dist/services/write-depth.d.ts +6 -0
- package/dist/services/write-transaction-scope.d.ts +9 -0
- package/dist/socket-liveness-D3UD5_BW.js +7570 -0
- package/dist/socket-liveness-D3UD5_BW.js.map +1 -0
- package/dist/socket-opt-ins.d.ts +64 -0
- package/dist/source-DBDbBTL4.js +811 -0
- package/dist/source-DBDbBTL4.js.map +1 -0
- package/dist/tsx-loader.d.ts +14 -0
- package/dist/utils/drizzle-conditions.d.ts +21 -1
- package/dist/utils/error-cause.d.ts +7 -0
- package/dist/utils/pg-error-utils.d.ts +2 -4
- package/dist/utils/result-rows.d.ts +10 -0
- package/dist/websocket.d.ts +13 -0
- package/package.json +7 -7
- package/dist/backup-cli-DW5p9_zv.js.map +0 -1
- package/dist/backup-service-EwcDVG-8.js.map +0 -1
- package/dist/cli-errors-DsA-K9uP.js +0 -893
- package/dist/cli-errors-DsA-K9uP.js.map +0 -1
- package/dist/cli-flags-BglvpjHv.js.map +0 -1
- package/dist/cli-output-CNdMql-L.js +0 -47
- package/dist/cli-output-CNdMql-L.js.map +0 -1
- package/dist/collection-index-DdnsxiJ_.js +0 -286
- package/dist/collection-index-DdnsxiJ_.js.map +0 -1
- package/dist/databasePoolManager-Bj5FbeAs.js.map +0 -1
- package/dist/doctor-C-sYWbmt.js.map +0 -1
- package/dist/ensure-collection-policies-B1ureSIV.js +0 -160
- package/dist/ensure-collection-policies-B1ureSIV.js.map +0 -1
- package/dist/ensure-collection-tables-kkkHk8oo.js.map +0 -1
- package/dist/ensure-tables-BmI_tRxc.js.map +0 -1
- package/dist/generate-drizzle-schema-93M0lUxK.js +0 -123
- package/dist/generate-drizzle-schema-93M0lUxK.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-sSFDp6LR.js.map +0 -1
- package/dist/introspect-db-logic-kCETE8TY.js.map +0 -1
- package/dist/introspect-db-queries-C_Q5VgQw.js.map +0 -1
- package/dist/plan-schema-DU9exq6C.js.map +0 -1
- package/dist/policy-drift-B-J2hhm0.js.map +0 -1
- package/dist/render-ddl-Ds2t_d9V.js.map +0 -1
- package/dist/rls-bootstrap-sql-_KNnjanK.js.map +0 -1
- package/dist/rls-enforcement-CfXOJJaW.js.map +0 -1
- package/dist/source-Br7L7GOI.js +0 -410
- package/dist/source-Br7L7GOI.js.map +0 -1
- 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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
32
|
-
* on its next boot, for every table at once, re-attached or not.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* never the tuple**. Postgres puts no privilege on `LISTEN`: any
|
|
36
|
-
* connect can listen on this channel, whatever it may `SELECT`.
|
|
37
|
-
* `to_jsonb(NEW)`, a login with no grant on anything received
|
|
38
|
-
* of every instrumented table — `password_hash` and
|
|
39
|
-
* the auth table included — past RLS and column
|
|
40
|
-
* read anything but the key: every subscriber
|
|
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(
|
|
125
|
+
export declare function buildCdcFunctionSql(options?: {
|
|
126
|
+
compatUntil?: string;
|
|
127
|
+
}): string;
|
|
54
128
|
/**
|
|
55
|
-
* SQL that (re)attaches the CDC
|
|
56
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
*
|
|
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[]
|
|
223
|
+
export declare function provisionTriggerCdc(run: RawSqlRunner, tables: CdcTableRef[], options?: {
|
|
224
|
+
now?: number;
|
|
225
|
+
}): Promise<ProvisionResult>;
|
|
226
|
+
export {};
|
|
@@ -79,10 +79,21 @@ export interface RetainedAnnouncement {
|
|
|
79
79
|
export declare class ChannelHistoryStore {
|
|
80
80
|
private db;
|
|
81
81
|
private rules;
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
|
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`.
|