@rebasepro/server-postgres 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BranchService-USp1AvZB.js → BranchService-Bdin0Wxh.js} +3 -3
- package/dist/{BranchService-USp1AvZB.js.map → BranchService-Bdin0Wxh.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +3 -0
- package/dist/{backup-cli-DbKyEj6c.js → backup-cli-BEAMPWMs.js} +3 -3
- package/dist/{backup-cli-DbKyEj6c.js.map → backup-cli-BEAMPWMs.js.map} +1 -1
- package/dist/{boot-ddl-5H2bL_80.js → boot-ddl-Bu6gAY-2.js} +2 -2
- package/dist/{boot-ddl-5H2bL_80.js.map → boot-ddl-Bu6gAY-2.js.map} +1 -1
- package/dist/{cli-console-DsRgGSBR.js → cli-console-DjFiYlSe.js} +4 -4
- package/dist/{cli-console-DsRgGSBR.js.map → cli-console-DjFiYlSe.js.map} +1 -1
- package/dist/cli-errors.d.ts +12 -0
- package/dist/cli-helpers.d.ts +20 -0
- package/dist/{cli-schema-dir-CiN0ephV.js → cli-schema-dir-CjDH_31U.js} +115 -9
- package/dist/cli-schema-dir-CjDH_31U.js.map +1 -0
- package/dist/cli.js +129 -36
- package/dist/cli.js.map +1 -1
- package/dist/{database-preflight-bfnIBnjM.js → database-preflight-DKzsGnc4.js} +2 -2
- package/dist/{database-preflight-bfnIBnjM.js.map → database-preflight-DKzsGnc4.js.map} +1 -1
- package/dist/{deferred-index-build-CcSDA7wE.js → deferred-index-build-88bWtYgx.js} +4 -4
- package/dist/{deferred-index-build-CcSDA7wE.js.map → deferred-index-build-88bWtYgx.js.map} +1 -1
- package/dist/{ensure-policies-rRmXb5bt.js → ensure-policies-nIITKxud.js} +7 -7
- package/dist/{ensure-policies-rRmXb5bt.js.map → ensure-policies-nIITKxud.js.map} +1 -1
- package/dist/{ensure-tables-Bvm-F2wW.js → ensure-tables-Lm-77eM5.js} +7 -7
- package/dist/{ensure-tables-Bvm-F2wW.js.map → ensure-tables-Lm-77eM5.js.map} +1 -1
- package/dist/{ensure-tables-CC8p_AK3.js → ensure-tables-hQ5oAK_j.js} +3 -3
- package/dist/{ensure-tables-CC8p_AK3.js.map → ensure-tables-hQ5oAK_j.js.map} +1 -1
- package/dist/{enum-labels-kept-FlX9SHdf.js → enum-labels-kept-mesgEJWH.js} +2 -2
- package/dist/{enum-labels-kept-FlX9SHdf.js.map → enum-labels-kept-mesgEJWH.js.map} +1 -1
- package/dist/{generate-drizzle-schema-SJMXxzPI.js → generate-drizzle-schema-B-Mkf8UI.js} +2 -2
- package/dist/{generate-drizzle-schema-SJMXxzPI.js.map → generate-drizzle-schema-B-Mkf8UI.js.map} +1 -1
- package/dist/{generate-files-tlJ9_lGI.js → generate-files-8MUP8UHC.js} +2 -2
- package/dist/{generate-files-tlJ9_lGI.js.map → generate-files-8MUP8UHC.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-B8huc03c.js → generate-postgres-ddl-logic-CQof4iFH.js} +89 -45
- package/dist/generate-postgres-ddl-logic-CQof4iFH.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +14 -14
- package/dist/{migrate-baseline-DZmekgpD.js → migrate-baseline-Bzj5gSCM.js} +9 -2
- package/dist/{migrate-baseline-DZmekgpD.js.map → migrate-baseline-Bzj5gSCM.js.map} +1 -1
- package/dist/{migrate-policy-stamps-B_acrUQB.js → migrate-policy-stamps-C2WaOEsB.js} +5 -5
- package/dist/{migrate-policy-stamps-B_acrUQB.js.map → migrate-policy-stamps-C2WaOEsB.js.map} +1 -1
- package/dist/{open-rebase-4kisUF_k.js → open-rebase-OB4hhQuk.js} +549 -54
- package/dist/open-rebase-OB4hhQuk.js.map +1 -0
- package/dist/{pg-error-utils-BT5NzGFZ.js → pg-error-utils-CWopxboq.js} +2 -2
- package/dist/{pg-error-utils-BT5NzGFZ.js.map → pg-error-utils-CWopxboq.js.map} +1 -1
- package/dist/{policy-drift-BVMyqHSa.js → policy-drift-rVLKS2AG.js} +4 -4
- package/dist/{policy-drift-BVMyqHSa.js.map → policy-drift-rVLKS2AG.js.map} +1 -1
- package/dist/{push-index-adoption-hpHTyXMR.js → push-index-adoption-EcamXfW2.js} +2 -2
- package/dist/{push-index-adoption-hpHTyXMR.js.map → push-index-adoption-EcamXfW2.js.map} +1 -1
- package/dist/{push-index-prebuild-Bty9F7bD.js → push-index-prebuild-BPIns6wA.js} +3 -3
- package/dist/{push-index-prebuild-Bty9F7bD.js.map → push-index-prebuild-BPIns6wA.js.map} +1 -1
- package/dist/{push-legacy-renames-bB4bM6br.js → push-legacy-renames-lmYkb41I.js} +3 -3
- package/dist/{push-legacy-renames-bB4bM6br.js.map → push-legacy-renames-lmYkb41I.js.map} +1 -1
- package/dist/{push-policy-plan-BI8U4BOD.js → push-policy-plan-Dqu4FKWh.js} +3 -3
- package/dist/{push-policy-plan-BI8U4BOD.js.map → push-policy-plan-Dqu4FKWh.js.map} +1 -1
- package/dist/{request-role-cli-BdRzdE87.js → request-role-cli-Ay0v9oYZ.js} +8 -8
- package/dist/{request-role-cli-BdRzdE87.js.map → request-role-cli-Ay0v9oYZ.js.map} +1 -1
- package/dist/{request-role-migration-C8aq_TO3.js → request-role-migration-DTE3Owsh.js} +2 -2
- package/dist/{request-role-migration-C8aq_TO3.js.map → request-role-migration-DTE3Owsh.js.map} +1 -1
- package/dist/{rls-enforcement-DB5HHj96.js → rls-enforcement-Ck-d8zdJ.js} +2 -2
- package/dist/{rls-enforcement-DB5HHj96.js.map → rls-enforcement-Ck-d8zdJ.js.map} +1 -1
- package/dist/schema/doctor-cli.js +5 -5
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +51 -8
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/introspect-db.js +1 -1
- package/dist/services/cdc/CdcListener.d.ts +12 -0
- package/dist/services/cdc/capture-consumers.d.ts +65 -0
- package/dist/services/cdc/pgoutput.d.ts +6 -0
- package/dist/services/cdc/wal-cdc.d.ts +13 -0
- package/dist/services/realtime-prefilter.d.ts +90 -0
- package/dist/services/realtimeService.d.ts +57 -3
- package/dist/utils/connection-string.d.ts +9 -1
- package/dist/{websocket-BevXvwfo.js → websocket-kZixcOXt.js} +3 -3
- package/dist/{websocket-BevXvwfo.js.map → websocket-kZixcOXt.js.map} +1 -1
- package/package.json +7 -7
- package/dist/cli-schema-dir-CiN0ephV.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +0 -1
- package/dist/open-rebase-4kisUF_k.js.map +0 -1
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
import { createRequire as __createRequire } from "module";
|
|
3
3
|
__createRequire(import.meta.url);
|
|
4
4
|
import { i as buildTableSearchColumnSpec } from "../search-column-BO-WND-B.js";
|
|
5
|
-
import { c as diagnoseDbError,
|
|
6
|
-
import { C as warnOnAnonymousGrants, S as validatePolicyPgRoles } from "../rls-enforcement-
|
|
5
|
+
import { c as diagnoseDbError, m as parseHostInfo, o as deepestErrorMessage } from "../cli-schema-dir-CjDH_31U.js";
|
|
6
|
+
import { C as warnOnAnonymousGrants, S as validatePolicyPgRoles } from "../rls-enforcement-Ck-d8zdJ.js";
|
|
7
7
|
import { i as outError, n as describeFailure, r as out, t as chalk } from "../source-VxbrQojV.js";
|
|
8
8
|
import { n as planSchema, t as pgTypeOf } from "../plan-schema-Hbtjhge3.js";
|
|
9
9
|
import { t as generateSchema } from "../generate-drizzle-schema-logic-DL7R1rAF.js";
|
|
10
10
|
import { i as renderPgType } from "../render-ddl-D4n86NHz.js";
|
|
11
11
|
import { n as loadTableSchema, r as loadTables, t as defaultDatabaseSchemaVersion } from "../load-tables-B1Re74ng.js";
|
|
12
12
|
import { r as readGeneratedSchemaDrift, t as describeSchemaDifference } from "../generated-schema-diff-DoT2dYDe.js";
|
|
13
|
-
import { i as hasDrift, r as formatPolicyDrift, t as checkPolicyDrift } from "../policy-drift-
|
|
13
|
+
import { i as hasDrift, r as formatPolicyDrift, t as checkPolicyDrift } from "../policy-drift-rVLKS2AG.js";
|
|
14
14
|
import { n as describeDeclarationDifferences, t as compareGeneratedDeclarations } from "../generated-schema-staleness-YBVq2kTn.js";
|
|
15
15
|
import { describeMismatch } from "@rebasepro/server";
|
|
16
16
|
import { DEFAULT_DATA_SOURCE_KEY, LEGACY_SCHEMA_VERSION_PREFIX, isNumericColumnType, isTemporalColumnType } from "@rebasepro/types";
|
|
@@ -1763,8 +1763,8 @@ async function runDatabasePreflight(schemaDir, databaseUrl) {
|
|
|
1763
1763
|
return "unchecked";
|
|
1764
1764
|
}
|
|
1765
1765
|
const { loadTables } = await import("../load-tables-B1Re74ng.js").then((n) => n.i);
|
|
1766
|
-
const { preflightDatabase } = await import("../database-preflight-
|
|
1767
|
-
const { readRecordedRequestRoles } = await import("../rls-enforcement-
|
|
1766
|
+
const { preflightDatabase } = await import("../database-preflight-DKzsGnc4.js");
|
|
1767
|
+
const { readRecordedRequestRoles } = await import("../rls-enforcement-Ck-d8zdJ.js").then((n) => n.y);
|
|
1768
1768
|
const { cliRlsSettings } = await import("../rls-settings-CmGK2U0a.js").then((n) => n.a);
|
|
1769
1769
|
const { Pool } = await import("pg");
|
|
1770
1770
|
const pool = new Pool({ connectionString: databaseUrl });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
|
-
import { t as main } from "../generate-drizzle-schema-
|
|
3
|
+
import { t as main } from "../generate-drizzle-schema-B-Mkf8UI.js";
|
|
4
4
|
//#region src/schema/bin/generate-drizzle-schema.ts
|
|
5
5
|
/**
|
|
6
6
|
* The built entry point for `generate-drizzle-schema`.
|
|
@@ -193,6 +193,21 @@ export interface PolicyApplyPlan {
|
|
|
193
193
|
/** For a restrictive policy, the statements that make it deny every row instead. */
|
|
194
194
|
denying?: string[];
|
|
195
195
|
}
|
|
196
|
+
/** What the database a boot writes the policies into can hold. */
|
|
197
|
+
export interface PolicyPlanOptions {
|
|
198
|
+
/**
|
|
199
|
+
* Whether `rebase_admin` exists. Where it cannot, a policy the compiler
|
|
200
|
+
* put `TO rebase_admin` is written `TO public`. Assumed when unset.
|
|
201
|
+
*/
|
|
202
|
+
adminRoleAvailable?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* The boot made `rebase_admin_request`, granted it to the admin request
|
|
205
|
+
* roles alone, and checked the connection does not hold its
|
|
206
|
+
* privileges. Only then are the companions planned; otherwise they
|
|
207
|
+
* are left out, and the boot drops any left in the database.
|
|
208
|
+
*/
|
|
209
|
+
adminRequestRoleAvailable?: boolean;
|
|
210
|
+
}
|
|
196
211
|
/**
|
|
197
212
|
* The per-table RLS plan for the declared collections and their junctions, as
|
|
198
213
|
* executable statements — what the managed runtime applies at boot so a freshly
|
|
@@ -201,16 +216,44 @@ export interface PolicyApplyPlan {
|
|
|
201
216
|
* The same policies `policies.sql` carries, from the same plan, so boot and
|
|
202
217
|
* `db push` produce identical RLS from identical collections.
|
|
203
218
|
*/
|
|
204
|
-
export declare const planTablePolicies: (tables: readonly CompiledTable[], options?:
|
|
205
|
-
|
|
219
|
+
export declare const planTablePolicies: (tables: readonly CompiledTable[], options?: PolicyPlanOptions) => TablePolicyPlan[];
|
|
220
|
+
/**
|
|
221
|
+
* One policy as a boot writes it, as data rather than DDL: the row
|
|
222
|
+
* `pg_policies` holds for it once it is applied, plus the rule it came from.
|
|
223
|
+
*/
|
|
224
|
+
export interface PlannedPolicy {
|
|
225
|
+
schema: string;
|
|
226
|
+
table: string;
|
|
227
|
+
name: string;
|
|
228
|
+
/** `FOR …`, upper-case as `pg_policies.cmd` spells it. */
|
|
229
|
+
command: "ALL" | "SELECT" | "INSERT" | "UPDATE" | "DELETE";
|
|
230
|
+
/** PERMISSIVE policies OR together; RESTRICTIVE ones AND. */
|
|
231
|
+
permissive: boolean;
|
|
232
|
+
/** The `TO` list; `["public"]` for every role. */
|
|
233
|
+
roles: string[];
|
|
234
|
+
/** The compiled `USING` clause, or null when the policy has none. */
|
|
235
|
+
using: string | null;
|
|
236
|
+
/** The compiled `WITH CHECK` clause, or null when the policy has none. */
|
|
237
|
+
withCheck: string | null;
|
|
206
238
|
/**
|
|
207
|
-
* The
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
* are left out, and the boot drops any left in the database.
|
|
239
|
+
* The rule it compiles from: the rule's `name`, or `#<index>` into the
|
|
240
|
+
* table's rules — its declared ones first, then the ones Rebase injects.
|
|
241
|
+
* An admin-request companion carries its base policy's.
|
|
211
242
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
243
|
+
ruleKey: string;
|
|
244
|
+
/** Rebase added the rule (the admin baseline, the auth table's, the tenant scope), not the author. */
|
|
245
|
+
injected: boolean;
|
|
246
|
+
/** A junction table the planner derives for a many-to-many relation, not a declared table. */
|
|
247
|
+
junction: boolean;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Every policy a boot writes for the tables and their junctions, as data:
|
|
251
|
+
* the same policies, in the same order, as {@link planTablePolicies} renders
|
|
252
|
+
* to statements. For a caller that reasons about the policies rather than
|
|
253
|
+
* applying them — `rebase verify` reads them to find a policy Postgres would
|
|
254
|
+
* refuse to expand (42P17, "infinite recursion detected in policy").
|
|
255
|
+
*/
|
|
256
|
+
export declare const planPolicyDefinitions: (tables: readonly CompiledTable[], options?: PolicyPlanOptions) => PlannedPolicy[];
|
|
214
257
|
/**
|
|
215
258
|
* The `generated column → column it reads` edges a project's `search` blocks
|
|
216
259
|
* imply, derived from the collections alone.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { r as out } from "../source-VxbrQojV.js";
|
|
4
|
-
import { r as writePostgresDdl } from "../generate-files-
|
|
4
|
+
import { r as writePostgresDdl } from "../generate-files-8MUP8UHC.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
//#region src/schema/generate-postgres-ddl.ts
|
|
7
7
|
/**
|
|
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from "module";
|
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { n as require_arg, o as __toESM, t as promptConfirm } from "../cli-prompt-DXG0yk-h.js";
|
|
4
4
|
import { u as pinSearchPath } from "../connection-C1zXTPJq.js";
|
|
5
|
-
import { c as diagnoseDbError } from "../cli-schema-dir-
|
|
5
|
+
import { c as diagnoseDbError } from "../cli-schema-dir-CjDH_31U.js";
|
|
6
6
|
import { a as outWarn, i as outError, r as out, t as chalk } from "../source-VxbrQojV.js";
|
|
7
7
|
import { i as readSchemaMetadata, n as isUsableFileName, r as quoteRelation, t as countRowsUpTo } from "../introspect-db-queries-BgiRQqtR.js";
|
|
8
8
|
import { a as describeRlsOffTables, c as mergeIndexModule, d as lookupCandidates, i as buildTablesMap, l as safeHostFromUrl, o as generateSchemaModules, u as classifyTables } from "../introspect-tables-Cw_A-kk4.js";
|
|
@@ -17,6 +17,18 @@ export interface CdcChangeEvent {
|
|
|
17
17
|
row: Record<string, unknown>;
|
|
18
18
|
/** True when even the key was too large to notify, so `row` is empty. */
|
|
19
19
|
truncated?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The row's column values by SQL name, before and after the change, as
|
|
22
|
+
* far as the source knows them — only ever from the WAL stream, which this
|
|
23
|
+
* server reads on its own replication connection, and never from a
|
|
24
|
+
* NOTIFY payload (see `row`). `null` is "no such version" (before an
|
|
25
|
+
* insert, after a delete); an absent version or column is unknown. Decides
|
|
26
|
+
* which list subscriptions refetch; never delivered to any of them.
|
|
27
|
+
*/
|
|
28
|
+
values?: {
|
|
29
|
+
before?: Record<string, string | null> | null;
|
|
30
|
+
after?: Record<string, string | null> | null;
|
|
31
|
+
};
|
|
20
32
|
}
|
|
21
33
|
/**
|
|
22
34
|
* Where committed changes come from: this listener (capture triggers and
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who still depends on the change-capture triggers.
|
|
3
|
+
*
|
|
4
|
+
* A process that streams changes from the WAL takes the capture triggers off
|
|
5
|
+
* the tables, so writes pay for no trigger and no NOTIFY. That is only safe
|
|
6
|
+
* when nobody else is still hearing changes through them: a replica that fell
|
|
7
|
+
* back to trigger capture (it found no free replication slot, say) or an older
|
|
8
|
+
* version mid-rollout is LISTENing on `rebase_cdc`, and taking the triggers
|
|
9
|
+
* away leaves it deaf — writes made anywhere else never reach its subscribers.
|
|
10
|
+
*
|
|
11
|
+
* Every realtime LISTEN connection names itself in `application_name`
|
|
12
|
+
* (`rebase-realtime:<instance id>`, then the role of the connection), which
|
|
13
|
+
* `pg_stat_activity` shows to any role, so the question is one query:
|
|
14
|
+
*
|
|
15
|
+
* - `…:cdc` — a trigger-capture LISTEN. A consumer.
|
|
16
|
+
* - `…:entity` / `…:wal` — the legacy cross-instance channel, or a WAL stream.
|
|
17
|
+
* Not a consumer.
|
|
18
|
+
* - the bare name — a version from before the connections said which they
|
|
19
|
+
* are. It may be a trigger LISTEN, so it counts as one.
|
|
20
|
+
*
|
|
21
|
+
* Anything uncertain keeps the triggers: an extra trigger costs throughput, a
|
|
22
|
+
* missing one costs correctness.
|
|
23
|
+
*/
|
|
24
|
+
import type { RawSqlRunner } from "../../security/rls-enforcement.js";
|
|
25
|
+
/** How every realtime LISTEN connection's `application_name` starts. */
|
|
26
|
+
export declare const REALTIME_LISTENER_APPLICATION_PREFIX = "rebase-realtime:";
|
|
27
|
+
/** What a realtime connection is for — the suffix after its instance's name. */
|
|
28
|
+
export type RealtimeListenerRole = "cdc" | "entity" | "wal";
|
|
29
|
+
/** The `application_name` of one of an instance's realtime connections. */
|
|
30
|
+
export declare function realtimeListenerApplicationName(instanceName: string, role: RealtimeListenerRole): string;
|
|
31
|
+
export interface ListenerSession {
|
|
32
|
+
applicationName: string | null;
|
|
33
|
+
/** `pg_stat_activity.backend_type`, when the role may see it. */
|
|
34
|
+
backendType: string | null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a session may be hearing changes through the capture triggers.
|
|
38
|
+
*
|
|
39
|
+
* @param ownInstanceName This process's `rebase-realtime:<instance id>`; its
|
|
40
|
+
* own connections never count.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isTriggerCaptureConsumer(session: ListenerSession, ownInstanceName: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* How many other sessions on this database may depend on the capture
|
|
45
|
+
* triggers. A failed query answers `undefined` — the caller keeps the triggers.
|
|
46
|
+
*/
|
|
47
|
+
export declare function countTriggerCaptureConsumers(run: RawSqlRunner, ownInstanceName: string): Promise<number | undefined>;
|
|
48
|
+
/** How often a WAL-streaming instance that kept the triggers for another one checks whether it is gone. */
|
|
49
|
+
export declare const TRIGGER_RETIREMENT_INTERVAL_MS: number;
|
|
50
|
+
export type TriggerRetirement = {
|
|
51
|
+
removed: number;
|
|
52
|
+
}
|
|
53
|
+
/** Kept: `consumers` other sessions may depend on them, or `undefined` when that could not be read. */
|
|
54
|
+
| {
|
|
55
|
+
kept: true;
|
|
56
|
+
consumers: number | undefined;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Take the capture triggers off the tables — unless another session may still
|
|
60
|
+
* be hearing changes through them ({@link countTriggerCaptureConsumers}).
|
|
61
|
+
*
|
|
62
|
+
* For a process that streams changes from the WAL: it does not need them, and
|
|
63
|
+
* every write pays a trigger and a NOTIFY while they stay.
|
|
64
|
+
*/
|
|
65
|
+
export declare function retireTriggerCaptureIfUnused(run: RawSqlRunner, ownInstanceName: string): Promise<TriggerRetirement>;
|
|
@@ -117,5 +117,11 @@ export declare class PgoutputChanges {
|
|
|
117
117
|
constructor(identityColumns: (schema: string, table: string) => readonly string[] | undefined);
|
|
118
118
|
/** The changes one message describes — none for anything but a row change. */
|
|
119
119
|
apply(message: PgoutputMessage): CdcChangeEvent[];
|
|
120
|
+
/**
|
|
121
|
+
* Put the column values of the row's two versions on the first event: see
|
|
122
|
+
* `CdcChangeEvent.values`. `before` is read for its key columns alone when
|
|
123
|
+
* `beforeKeyOnly`, which is all a default replica identity sends.
|
|
124
|
+
*/
|
|
125
|
+
private withValues;
|
|
120
126
|
private change;
|
|
121
127
|
}
|
|
@@ -9,6 +9,19 @@ export declare const CDC_PUBLICATION = "rebase_cdc";
|
|
|
9
9
|
* (`rds_replication`, `cloudsqlsuperuser`) that no attribute shows.
|
|
10
10
|
*/
|
|
11
11
|
export declare function walCaptureBlocker(run: RawSqlRunner): Promise<string | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* What a boot says when it tried WAL capture and could not use it, before it
|
|
14
|
+
* falls back to the capture triggers.
|
|
15
|
+
*
|
|
16
|
+
* `REALTIME_CDC=wal` asked for the WAL, so not getting it is a warning.
|
|
17
|
+
* `auto` — the default — tries the WAL wherever it might work, and most
|
|
18
|
+
* databases are not set up for logical decoding: there, falling back is the
|
|
19
|
+
* expected outcome and an info line.
|
|
20
|
+
*/
|
|
21
|
+
export declare function walFallbackNotice(mode: "auto" | "wal"): {
|
|
22
|
+
level: "info" | "warn";
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
12
25
|
export interface WalPublicationResult {
|
|
13
26
|
/** Tables in the publication, including ones an earlier boot added. */
|
|
14
27
|
published: CdcTableRef[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ColumnType, IncludeSpec } from "@rebasepro/types";
|
|
2
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
3
|
+
/**
|
|
4
|
+
* Which list subscriptions a row change can reach, decided before any of them
|
|
5
|
+
* refetches.
|
|
6
|
+
*
|
|
7
|
+
* A write to a table used to schedule a refetch for every list group on it,
|
|
8
|
+
* so a table open as a thousand different principals cost a thousand
|
|
9
|
+
* RLS-scoped reads per write — even when every one of those lists was
|
|
10
|
+
* `where owner_id == <me>` and the row belonged to one of them. A change can
|
|
11
|
+
* only alter a list whose filter matched the row before the change or matches
|
|
12
|
+
* it after, so a group whose filter provably matches neither is skipped.
|
|
13
|
+
*
|
|
14
|
+
* This decides only *whether* a group refetches, never *what* it receives:
|
|
15
|
+
* every frame is still a read under the subscriber's own scope. A wrong "may
|
|
16
|
+
* match" costs one refetch; a wrong "cannot match" would leave a list stale,
|
|
17
|
+
* so every rule here answers "may match" whenever it cannot be sure:
|
|
18
|
+
*
|
|
19
|
+
* - Only `==` and `in` on a plain column of a type whose equality is plain
|
|
20
|
+
* (text, varchar, uuid, enum, the integer types, boolean) are judged. Every
|
|
21
|
+
* other condition — a range, a pattern, a JSON path, a relation, a
|
|
22
|
+
* `logical` group, a search — is left out, and since the conditions of a
|
|
23
|
+
* read are ANDed, leaving one out only widens what the judge admits.
|
|
24
|
+
* - A column with a field-level hook (`.transform()`) is never judged: the
|
|
25
|
+
* values a write hands over may be its transformed view, not what Postgres
|
|
26
|
+
* compares.
|
|
27
|
+
* - A list that loads relations, or a table with an `afterRead` hook, is never
|
|
28
|
+
* pre-filtered: either can make a list depend on rows its filter excludes.
|
|
29
|
+
* - A value the change does not carry (a column the WAL left out, a key-only
|
|
30
|
+
* old tuple, a capture trigger that sends the key alone, an 8 KB overflow)
|
|
31
|
+
* is unknown, and unknown means refetch.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* The two versions of a changed row, by column key, as far as they are known.
|
|
35
|
+
* `null` is "no such version" (the row before an insert, after a delete);
|
|
36
|
+
* `undefined` is "not known", and a key missing from a version is unknown too.
|
|
37
|
+
*/
|
|
38
|
+
export interface RowChangeImage {
|
|
39
|
+
before?: Record<string, unknown> | null;
|
|
40
|
+
after?: Record<string, unknown> | null;
|
|
41
|
+
}
|
|
42
|
+
/** One `==`/`in` condition the judge can evaluate: the canonical values it admits. */
|
|
43
|
+
interface EqualityConjunct {
|
|
44
|
+
field: string;
|
|
45
|
+
/** Canonical values (see {@link canonicalValue}); {@link NULL_KEY} stands for `IS NULL`. */
|
|
46
|
+
accepts: ReadonlySet<string>;
|
|
47
|
+
kind: ColumnType["kind"];
|
|
48
|
+
}
|
|
49
|
+
/** A list group's pre-filter: the judged conditions, and the one it is indexed by. */
|
|
50
|
+
export interface ListPrefilter {
|
|
51
|
+
conjuncts: readonly EqualityConjunct[];
|
|
52
|
+
/** The condition the group is found by: its field and every value it admits. */
|
|
53
|
+
index: EqualityConjunct;
|
|
54
|
+
}
|
|
55
|
+
/** The canonical spelling of SQL `NULL` in an index. */
|
|
56
|
+
export declare const NULL_KEY = "\0null";
|
|
57
|
+
/** Longer values are left out of an image: unknown, never compared, and not held in memory. */
|
|
58
|
+
export declare const MAX_IMAGE_VALUE_LENGTH = 256;
|
|
59
|
+
/**
|
|
60
|
+
* A value as Postgres would compare it in a column of `kind`, as one string,
|
|
61
|
+
* or `undefined` when that cannot be said with certainty — the caller then
|
|
62
|
+
* treats the comparison as unknown. Accepts both a filter's JSON value and a
|
|
63
|
+
* change's value (a JS value from the write path, or the text the WAL sends).
|
|
64
|
+
*/
|
|
65
|
+
export declare function canonicalValue(kind: ColumnType["kind"], value: unknown): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The pre-filter for a list read of `table`, or `undefined` when the list
|
|
68
|
+
* must refetch on every change to the table.
|
|
69
|
+
*/
|
|
70
|
+
export declare function compileListPrefilter(table: RuntimeTable, request: {
|
|
71
|
+
filter?: Record<string, unknown>;
|
|
72
|
+
include?: IncludeSpec;
|
|
73
|
+
}, tableHasReadHooks: boolean): ListPrefilter | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Whether one version of a row matches the judged conditions: `false` only
|
|
76
|
+
* when a condition is known to fail, `undefined` when one cannot be read.
|
|
77
|
+
*/
|
|
78
|
+
export declare function prefilterMatches(prefilter: ListPrefilter, values: Record<string, unknown>): boolean | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Whether a change may alter a list with this pre-filter: unless both
|
|
81
|
+
* versions of the row are known not to match it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function changeMayReach(prefilter: ListPrefilter, image: RowChangeImage): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The index keys a version of a row is found under for `field`, or
|
|
86
|
+
* `undefined` when the version cannot say — then every group indexed by the
|
|
87
|
+
* field may be reached.
|
|
88
|
+
*/
|
|
89
|
+
export declare function imageIndexKey(version: Record<string, unknown>, field: string, kind: ColumnType["kind"]): string | undefined;
|
|
90
|
+
export {};
|
|
@@ -4,6 +4,7 @@ import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfi
|
|
|
4
4
|
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
5
5
|
import type { RequestIdentity } from "../security/rls-settings.js";
|
|
6
6
|
import type { CdcTableRef } from "./cdc/trigger-cdc.js";
|
|
7
|
+
import { type RowChangeImage } from "./realtime-prefilter.js";
|
|
7
8
|
import { ChannelBus } from "./channel-bus/index.js";
|
|
8
9
|
import type { ChannelRetentionRule, RealtimeCounts, RealtimeListenerHealth } from "@rebasepro/types";
|
|
9
10
|
/**
|
|
@@ -427,6 +428,13 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
427
428
|
* keep waiting — the clock above does that.
|
|
428
429
|
*/
|
|
429
430
|
private unscheduledListGroups;
|
|
431
|
+
/**
|
|
432
|
+
* The subset of {@link unscheduledListGroups} with no pre-filter: what a
|
|
433
|
+
* change that can be judged still schedules wholesale.
|
|
434
|
+
*/
|
|
435
|
+
private unscheduledPlainListGroups;
|
|
436
|
+
/** The pre-filtered list groups on each path. See {@link groupsReachedBy}. */
|
|
437
|
+
private prefilterIndex;
|
|
430
438
|
/**
|
|
431
439
|
* Every path a subscription holds, with the collection it lands on and how
|
|
432
440
|
* many hold it — the candidates `aliasPaths` considers, resolved once.
|
|
@@ -455,8 +463,16 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
455
463
|
private driver?;
|
|
456
464
|
/** Unique identifier for this process instance, used to skip own notifications. */
|
|
457
465
|
private readonly instanceId;
|
|
458
|
-
/**
|
|
459
|
-
|
|
466
|
+
/**
|
|
467
|
+
* The name this instance's realtime connections report in
|
|
468
|
+
* `pg_stat_activity` (`application_name`), each followed by what the
|
|
469
|
+
* connection is for — see {@link realtimeListenerApplicationName}. Other
|
|
470
|
+
* instances count these, and a WAL-streaming one reads them to tell
|
|
471
|
+
* whether anybody still LISTENs on the capture triggers.
|
|
472
|
+
*/
|
|
473
|
+
readonly listenerInstanceName: string;
|
|
474
|
+
/** While the capture triggers are kept for another instance, the timer that retires them once it is gone. */
|
|
475
|
+
private triggerRetirementTimer?;
|
|
460
476
|
/** The LISTEN connection on {@link PG_NOTIFY_CHANNEL}, outside the Drizzle pool. */
|
|
461
477
|
private crossInstanceListener?;
|
|
462
478
|
/** Whether cross-instance broadcasting is active. */
|
|
@@ -574,6 +590,20 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
574
590
|
private dropSubscription;
|
|
575
591
|
/** Take `subscription` out of its group and path count; a group left empty goes, timer and all. */
|
|
576
592
|
private leaveGroup;
|
|
593
|
+
/**
|
|
594
|
+
* Compile `group`'s pre-filter and index it under its narrowest
|
|
595
|
+
* condition. Only for a list on a table's own path: a nested list's rows
|
|
596
|
+
* are chosen by its parent, which a change to the row does not describe.
|
|
597
|
+
*/
|
|
598
|
+
private indexPrefilter;
|
|
599
|
+
private unindexPrefilter;
|
|
600
|
+
/**
|
|
601
|
+
* The pre-filtered list groups on `path` that `image` may reach, or
|
|
602
|
+
* `undefined` when the change cannot say which value it had in a field
|
|
603
|
+
* groups are indexed by — then every group on the path is asked, as for
|
|
604
|
+
* a change with no image at all.
|
|
605
|
+
*/
|
|
606
|
+
private groupsReachedBy;
|
|
577
607
|
/** See {@link unscheduledListGroups}. */
|
|
578
608
|
private markListGroupUnscheduled;
|
|
579
609
|
/**
|
|
@@ -749,7 +779,12 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
749
779
|
* records the change so this instance can suppress the matching
|
|
750
780
|
* CDC echo, while an unmatched CDC event is delivered normally.
|
|
751
781
|
*/
|
|
752
|
-
|
|
782
|
+
/**
|
|
783
|
+
* @param image What the change is known to have done to the row, by column
|
|
784
|
+
* key — see `realtime-prefilter.ts`. It narrows which list groups on
|
|
785
|
+
* `path` refetch, never what any of them receives. Absent, all of them do.
|
|
786
|
+
*/
|
|
787
|
+
notifyUpdate(path: string, id: string, row: Record<string, unknown> | null, databaseId?: string, broadcast?: boolean, origin?: "app" | "cdc", image?: RowChangeImage): Promise<void>;
|
|
753
788
|
/**
|
|
754
789
|
* Notify subscriptions for a specific path.
|
|
755
790
|
*
|
|
@@ -1265,6 +1300,14 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1265
1300
|
* change capture is off: the maps are built when it starts.
|
|
1266
1301
|
*/
|
|
1267
1302
|
refreshTableMaps(): void;
|
|
1303
|
+
/**
|
|
1304
|
+
* Try `retire` every `intervalMs` until it answers true — how a
|
|
1305
|
+
* WAL-streaming instance takes the capture triggers off once the last
|
|
1306
|
+
* instance still listening on them is gone. Replaces any earlier schedule;
|
|
1307
|
+
* stopped with the CDC listener.
|
|
1308
|
+
*/
|
|
1309
|
+
scheduleTriggerCaptureRetirement(retire: () => Promise<boolean>, intervalMs: number): void;
|
|
1310
|
+
private cancelTriggerCaptureRetirement;
|
|
1268
1311
|
/** Stop the CDC listener and clear its state. */
|
|
1269
1312
|
stopCdc(): Promise<void>;
|
|
1270
1313
|
/**
|
|
@@ -1299,6 +1342,17 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1299
1342
|
private handleCdcEvents;
|
|
1300
1343
|
private drainCdcBacklog;
|
|
1301
1344
|
private handleCdcEvent;
|
|
1345
|
+
/**
|
|
1346
|
+
* What a captured change says about the row's two versions, by column
|
|
1347
|
+
* key — which list groups it can reach, never what they receive.
|
|
1348
|
+
*
|
|
1349
|
+
* From the WAL, the values it streamed (`CdcChangeEvent.values`). From the
|
|
1350
|
+
* capture trigger, the key alone, and only where the op pins the other
|
|
1351
|
+
* version: an insert had no row before, a delete has none after. A
|
|
1352
|
+
* trigger's update names the new key only — the old one may differ — and
|
|
1353
|
+
* a key too large to send names nothing: both are unknown.
|
|
1354
|
+
*/
|
|
1355
|
+
private cdcChangeImage;
|
|
1302
1356
|
/**
|
|
1303
1357
|
* Deliver a change on a many-to-many junction table as a change to the child
|
|
1304
1358
|
* lists it belongs to.
|
|
@@ -22,7 +22,15 @@
|
|
|
22
22
|
* Nothing is relaxed by the rewrite — `verify-ca` and `verify-full` are left
|
|
23
23
|
* alone, so a connection string that asked for verification still gets it.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* `uselibpqcompat` is node-postgres's too. It is what node-postgres's own
|
|
26
|
+
* warning tells people to add (`uselibpqcompat=true&sslmode=require`), because
|
|
27
|
+
* node-postgres reads a bare `sslmode=require` as `verify-full`. libpq reports
|
|
28
|
+
* any parameter it does not know as a server setting, so Atlas fails with
|
|
29
|
+
* `unrecognized configuration parameter "uselibpqcompat"`. It only changes how
|
|
30
|
+
* node-postgres reads `sslmode`, and libpq already reads it the standard way,
|
|
31
|
+
* so it is dropped.
|
|
32
|
+
*
|
|
33
|
+
* Only these two are touched, and only when libpq would reject them.
|
|
26
34
|
* Anything unparseable is returned as given: a connection that works
|
|
27
35
|
* unverified beats one this corrupted.
|
|
28
36
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { i as __exportAll } from "./cli-prompt-DXG0yk-h.js";
|
|
4
|
-
import { A as reapSilentSockets, at as SQL_RESULT_BYTE_BUDGET, ct as resolveNestedPath, it as sqlRoleRanAs, j as terminateIfBacklogged, k as budgetSendBuffers, lt as assertReadRequestReadable, nt as effectiveSqlRole, ot as SqlResultTooLargeError, st as isNestedPath } from "./open-rebase-
|
|
5
|
-
import { r as BranchingUnsupportedError } from "./BranchService-
|
|
4
|
+
import { A as reapSilentSockets, at as SQL_RESULT_BYTE_BUDGET, ct as resolveNestedPath, it as sqlRoleRanAs, j as terminateIfBacklogged, k as budgetSendBuffers, lt as assertReadRequestReadable, nt as effectiveSqlRole, ot as SqlResultTooLargeError, st as isNestedPath } from "./open-rebase-OB4hhQuk.js";
|
|
5
|
+
import { r as BranchingUnsupportedError } from "./BranchService-Bdin0Wxh.js";
|
|
6
6
|
import { ApiError, DATABASE_UNAVAILABLE_MESSAGE, RUNTIME_DEFAULT_MAX_BODY_SIZE, assertFieldOpsValid, assertNestedWriteAllowed, assertNoFieldOpsOnCreate, assertNoUserUpsert, assertUserCreationBodyValid, assertWriteRequestValid, createUserThroughAuthTable, decideImpersonation, declaredErrorAnswer, extractUserFromToken, getAccessModel, isAuthTable, isDatabaseUnreachable, logger, resolveConflictTarget, resolveRequireAuth, safeCompare } from "@rebasepro/server";
|
|
7
7
|
import { ANONYMOUS_USER_ID, ListLimitError, hasAdminRole, isSQLAdmin, isSchemaAdmin, resolveClientListLimit, scopeGrants, scopesForRoles } from "@rebasepro/types";
|
|
8
8
|
import { UnknownFilterOperatorError, deserializeFilter, redactSqlLiterals, relationOf } from "@rebasepro/common";
|
|
@@ -1709,4 +1709,4 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig, au
|
|
|
1709
1709
|
//#endregion
|
|
1710
1710
|
export { createPostgresWebSocket as a, websocket_exports as c, TOO_MANY_SOCKETS_CLOSE_CODE as i, PUBLIC_TYPES as n, isSocketRealtimeService as o, SESSION_ENDED_CLOSE_CODE as r, socketRealtimeMissing as s, ADMIN_PLANE_TYPES as t };
|
|
1711
1711
|
|
|
1712
|
-
//# sourceMappingURL=websocket-
|
|
1712
|
+
//# sourceMappingURL=websocket-kZixcOXt.js.map
|