@rebasepro/server-postgres 0.27.0 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BranchService-B9Lu8e-P.js → BranchService-BPssiD8_.js} +37 -11
- package/dist/BranchService-BPssiD8_.js.map +1 -0
- package/dist/auth/services.d.ts +19 -7
- package/dist/backup/pg-tools.d.ts +14 -0
- package/dist/backup/retention.d.ts +14 -1
- package/dist/{backup-cli-BZM2Fj1I.js → backup-cli-C1wcj-rc.js} +59 -11
- package/dist/backup-cli-C1wcj-rc.js.map +1 -0
- package/dist/{boot-ddl-yukSebLA.js → boot-ddl-CIGoIGcC.js} +2 -2
- package/dist/{boot-ddl-yukSebLA.js.map → boot-ddl-CIGoIGcC.js.map} +1 -1
- package/dist/branch-argv.d.ts +20 -0
- package/dist/{cli-console-BtzxzzvU.js → cli-console-C0FYkICX.js} +5 -5
- package/dist/{cli-console-BtzxzzvU.js.map → cli-console-C0FYkICX.js.map} +1 -1
- package/dist/{cli-errors-BBSJqlYX.js → cli-errors-DYets7cp.js} +5 -5
- package/dist/{cli-errors-BBSJqlYX.js.map → cli-errors-DYets7cp.js.map} +1 -1
- package/dist/cli.js +43 -41
- package/dist/cli.js.map +1 -1
- package/dist/data-transformer.d.ts +11 -1
- package/dist/{databasePoolManager-3stMNFL-.js → databasePoolManager-BjoVvuAq.js} +2 -2
- package/dist/databasePoolManager-BjoVvuAq.js.map +1 -0
- package/dist/{deferred-index-build-DRnoMq-O.js → deferred-index-build-BcJ_oulu.js} +5 -5
- package/dist/{deferred-index-build-DRnoMq-O.js.map → deferred-index-build-BcJ_oulu.js.map} +1 -1
- package/dist/{doctor-Cs6AtizY.js → doctor-TJApVglQ.js} +6 -6
- package/dist/{doctor-Cs6AtizY.js.map → doctor-TJApVglQ.js.map} +1 -1
- package/dist/{ensure-collection-policies-H8HN1Gbd.js → ensure-collection-policies-BNwSQfVx.js} +63 -25
- package/dist/ensure-collection-policies-BNwSQfVx.js.map +1 -0
- package/dist/{ensure-collection-tables-BeF1lArf.js → ensure-collection-tables-CSbgkTBx.js} +8 -9
- package/dist/{ensure-collection-tables-BeF1lArf.js.map → ensure-collection-tables-CSbgkTBx.js.map} +1 -1
- package/dist/{ensure-tables-DDkNaPN2.js → ensure-tables-CF-8zgYA.js} +3 -3
- package/dist/{ensure-tables-DDkNaPN2.js.map → ensure-tables-CF-8zgYA.js.map} +1 -1
- package/dist/{enum-labels-kept-B6loB2U_.js → enum-labels-kept-BCgFGAbJ.js} +3 -3
- package/dist/{enum-labels-kept-B6loB2U_.js.map → enum-labels-kept-BCgFGAbJ.js.map} +1 -1
- package/dist/{generate-drizzle-schema-D_O8_iyT.js → generate-drizzle-schema-BAIp9nKT.js} +2 -2
- package/dist/{generate-drizzle-schema-D_O8_iyT.js.map → generate-drizzle-schema-BAIp9nKT.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-D0E64iwx.js → generate-drizzle-schema-logic-CVRmZjP3.js} +2 -2
- package/dist/{generate-drizzle-schema-logic-D0E64iwx.js.map → generate-drizzle-schema-logic-CVRmZjP3.js.map} +1 -1
- package/dist/{generate-files-BpgyRwhU.js → generate-files-DutUrsSS.js} +3 -3
- package/dist/{generate-files-BpgyRwhU.js.map → generate-files-DutUrsSS.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-CogQBrzs.js → generate-postgres-ddl-logic-0rbAqwYT.js} +22 -10
- package/dist/generate-postgres-ddl-logic-0rbAqwYT.js.map +1 -0
- package/dist/{generated-schema-diff-X9NA2Vig.js → generated-schema-diff-ChFg6UxI.js} +13 -4
- package/dist/{generated-schema-diff-X9NA2Vig.js.map → generated-schema-diff-ChFg6UxI.js.map} +1 -1
- package/dist/history/HistoryService.d.ts +5 -0
- package/dist/index.es.js +14 -13
- package/dist/index.es.js.map +1 -1
- package/dist/{migrate-baseline-Bfk1LGC6.js → migrate-baseline-DPawvckr.js} +54 -11
- package/dist/{migrate-baseline-Bfk1LGC6.js.map → migrate-baseline-DPawvckr.js.map} +1 -1
- package/dist/{migrate-policy-stamps-DHxwcawC.js → migrate-policy-stamps-B-8vTSIm.js} +6 -6
- package/dist/{migrate-policy-stamps-DHxwcawC.js.map → migrate-policy-stamps-B-8vTSIm.js.map} +1 -1
- package/dist/{open-rebase-DZ5JbZpg.js → open-rebase-D9n8idex.js} +1436 -200
- package/dist/open-rebase-D9n8idex.js.map +1 -0
- package/dist/{pg-error-utils-BueZEJ0S.js → pg-error-utils-BIHfsGZL.js} +2 -2
- package/dist/{pg-error-utils-BueZEJ0S.js.map → pg-error-utils-BIHfsGZL.js.map} +1 -1
- package/dist/{plan-schema-YagMlmNE.js → plan-schema-DMVh77yb.js} +28 -1
- package/dist/plan-schema-DMVh77yb.js.map +1 -0
- package/dist/{policy-drift-Dqp_yFeE.js → policy-drift-0Cp4Lc0x.js} +13 -4
- package/dist/policy-drift-0Cp4Lc0x.js.map +1 -0
- package/dist/{push-index-prebuild-hVRrfTi-.js → push-index-prebuild-DR3P4yOw.js} +4 -4
- package/dist/{push-index-prebuild-hVRrfTi-.js.map → push-index-prebuild-DR3P4yOw.js.map} +1 -1
- package/dist/{push-kept-defaults-M_ZCcXuy.js → push-kept-defaults-BSqPzp0T.js} +2 -2
- package/dist/{push-kept-defaults-M_ZCcXuy.js.map → push-kept-defaults-BSqPzp0T.js.map} +1 -1
- package/dist/{push-legacy-renames-DcoAWmGt.js → push-legacy-renames-BIxBmVLl.js} +4 -4
- package/dist/{push-legacy-renames-DcoAWmGt.js.map → push-legacy-renames-BIxBmVLl.js.map} +1 -1
- package/dist/{push-policy-plan-Bq1bcb3Y.js → push-policy-plan-BHsasXa7.js} +4 -4
- package/dist/{push-policy-plan-Bq1bcb3Y.js.map → push-policy-plan-BHsasXa7.js.map} +1 -1
- package/dist/{render-ddl-D5jeXKR-.js → render-ddl-NpPPDACz.js} +20 -3
- package/dist/render-ddl-NpPPDACz.js.map +1 -0
- package/dist/schema/doctor-cli.js +3 -3
- package/dist/schema/ensure-collection-policies.d.ts +6 -4
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +16 -0
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/generated-schema-diff.d.ts +6 -0
- package/dist/schema/introspect-db.js +1 -1
- package/dist/schema/plan/render-ddl.d.ts +11 -0
- package/dist/schema/reconcile-schema.d.ts +21 -0
- package/dist/security/policy-drift.d.ts +9 -1
- package/dist/services/BranchService.d.ts +6 -0
- package/dist/services/RelationService.d.ts +6 -6
- package/dist/services/cdc/CdcListener.d.ts +12 -0
- package/dist/services/cdc/WalCdcListener.d.ts +92 -0
- package/dist/services/cdc/pgoutput.d.ts +121 -0
- package/dist/services/cdc/wal-cdc.d.ts +29 -0
- package/dist/services/collection-helpers.d.ts +14 -0
- package/dist/services/junction-writes.d.ts +9 -1
- package/dist/services/nested-path.d.ts +2 -1
- package/dist/services/realtimeService.d.ts +47 -2
- package/dist/utils/drizzle-conditions.d.ts +11 -0
- package/dist/{websocket-C9Fx7iSx.js → websocket-D4wrzF3b.js} +6 -5
- package/dist/websocket-D4wrzF3b.js.map +1 -0
- package/package.json +7 -7
- package/dist/BranchService-B9Lu8e-P.js.map +0 -1
- package/dist/backup-cli-BZM2Fj1I.js.map +0 -1
- package/dist/databasePoolManager-3stMNFL-.js.map +0 -1
- package/dist/ensure-collection-policies-H8HN1Gbd.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-CogQBrzs.js.map +0 -1
- package/dist/open-rebase-DZ5JbZpg.js.map +0 -1
- package/dist/plan-schema-YagMlmNE.js.map +0 -1
- package/dist/policy-drift-Dqp_yFeE.js.map +0 -1
- package/dist/render-ddl-D5jeXKR-.js.map +0 -1
- package/dist/websocket-C9Fx7iSx.js.map +0 -1
|
@@ -216,6 +216,12 @@ export declare class BranchService {
|
|
|
216
216
|
* so the *disagreements* between the two are visible — a row whose database
|
|
217
217
|
* is gone and a database with no row are the two things prune exists to
|
|
218
218
|
* find, and a join hides both.
|
|
219
|
+
*
|
|
220
|
+
* A database whose comment marks it as another main database's branch
|
|
221
|
+
* (see {@link BRANCH_HOME_COMMENT_PREFIX}) is left out, unless this
|
|
222
|
+
* registry names it: it is another project's branch on the same server,
|
|
223
|
+
* which has no row here because it is registered there, and dropping it as
|
|
224
|
+
* an orphan would destroy that project's work.
|
|
219
225
|
*/
|
|
220
226
|
pruneCandidates(): Promise<{
|
|
221
227
|
rows: BranchRow[];
|
|
@@ -2,6 +2,7 @@ import { SQL } from "drizzle-orm";
|
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { DrizzleClient } from "../interfaces.js";
|
|
4
4
|
import { CollectionConfig, FilterValues, OrderByTuple, ResolvedRelation, ResolvedHasMany, ResolvedHasOne } from "@rebasepro/types";
|
|
5
|
+
import { type JoinStep } from "@rebasepro/types";
|
|
5
6
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
6
7
|
import type { NestedPathHop } from "./nested-path.js";
|
|
7
8
|
import { type ReadCallContextProvider } from "./read-scope.js";
|
|
@@ -23,13 +24,12 @@ export declare function applyDynamicJoin<T>(query: T, joinTable: PgTable, condit
|
|
|
23
24
|
* `on.from`/`on.to` are a column or a tuple, and a tuple is how a step joins on
|
|
24
25
|
* a composite key. Comparing the first pair alone joined each row to every row
|
|
25
26
|
* sharing that column — every locale of a translation, not the one addressed.
|
|
27
|
+
*
|
|
28
|
+
* A step listing several conditions joins on any one of them, OR-ed: a row
|
|
29
|
+
* that meets two of them is still one row of an inner join, so a link held in
|
|
30
|
+
* either of two columns is read once either way.
|
|
26
31
|
*/
|
|
27
|
-
export declare function joinStepCondition(currentTable: PgTable, joinTable: PgTable, step: {
|
|
28
|
-
on: {
|
|
29
|
-
from: string | string[];
|
|
30
|
-
to: string | string[];
|
|
31
|
-
};
|
|
32
|
-
}): {
|
|
32
|
+
export declare function joinStepCondition(currentTable: PgTable, joinTable: PgTable, step: Pick<JoinStep, "on">): {
|
|
33
33
|
condition: SQL;
|
|
34
34
|
} | {
|
|
35
35
|
missing: string;
|
|
@@ -18,6 +18,18 @@ export interface CdcChangeEvent {
|
|
|
18
18
|
/** True when even the key was too large to notify, so `row` is empty. */
|
|
19
19
|
truncated?: boolean;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Where committed changes come from: this listener (capture triggers and
|
|
23
|
+
* NOTIFY) or `WalCdcListener` (logical replication). `RealtimeService` reads
|
|
24
|
+
* the same events from either.
|
|
25
|
+
*/
|
|
26
|
+
export interface CdcSource {
|
|
27
|
+
/** Rejects when the first connection cannot be made, so the caller can fall back. */
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
stop(): Promise<void>;
|
|
30
|
+
readonly connected: boolean;
|
|
31
|
+
status(): PgNotifyListenerStatus;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Parse a `rebase_cdc` NOTIFY payload into the changes it names, one per row.
|
|
23
35
|
* Returns `null` for anything malformed so a single bad message can never
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { CdcChangeEvent } from "./CdcListener.js";
|
|
2
|
+
import type { PgNotifyListenerStatus } from "../pg-notify-listener.js";
|
|
3
|
+
export interface WalCdcListenerOptions {
|
|
4
|
+
/** Direct Postgres connection string. Not a pooler: it carries the replication protocol. */
|
|
5
|
+
connectionString: string;
|
|
6
|
+
/** The publication to stream. Must be a plain identifier — it is interpolated. */
|
|
7
|
+
publication: string;
|
|
8
|
+
onEvents: (events: CdcChangeEvent[]) => void | Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Called once the stream is open again after a drop — never after the
|
|
11
|
+
* first connect. The new slot starts from the present: what committed
|
|
12
|
+
* while the connection was down is gone, so subscribers resync here.
|
|
13
|
+
*/
|
|
14
|
+
onReconnect?: () => void;
|
|
15
|
+
/** The columns a table's rows are addressed by; `undefined` for its replica identity. */
|
|
16
|
+
identityColumns: (schema: string, table: string) => readonly string[] | undefined;
|
|
17
|
+
applicationName?: string;
|
|
18
|
+
reconnectDelayMs?: number;
|
|
19
|
+
/** How often the stream must prove it is alive. `0` turns the check off. */
|
|
20
|
+
heartbeatIntervalMs?: number;
|
|
21
|
+
/** How long the server may take to answer a heartbeat. */
|
|
22
|
+
heartbeatTimeoutMs?: number;
|
|
23
|
+
/** How often the position read so far is reported, so the server can recycle WAL. */
|
|
24
|
+
statusIntervalMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* How long creating the slot may take. It waits for every transaction
|
|
27
|
+
* already running to finish, so one long transaction holds it up.
|
|
28
|
+
*/
|
|
29
|
+
slotTimeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A logical replication consumer that repairs itself, shaped like
|
|
33
|
+
* {@link PgNotifyListener}: the first connect is validated and rethrown, so a
|
|
34
|
+
* caller can fall back to the trigger listener; every later drop is repaired in
|
|
35
|
+
* the background.
|
|
36
|
+
*/
|
|
37
|
+
export declare class WalCdcListener {
|
|
38
|
+
private readonly options;
|
|
39
|
+
private client?;
|
|
40
|
+
/** The connection being opened: its frames count before it is adopted, an abandoned one's never do. */
|
|
41
|
+
private connecting?;
|
|
42
|
+
private stream?;
|
|
43
|
+
private running;
|
|
44
|
+
private reconnectTimer?;
|
|
45
|
+
private heartbeatTimer?;
|
|
46
|
+
private heartbeatDeadline?;
|
|
47
|
+
private statusTimer?;
|
|
48
|
+
private downSince?;
|
|
49
|
+
private lastHeartbeatAt?;
|
|
50
|
+
private lastFrameAt;
|
|
51
|
+
private outageWarned;
|
|
52
|
+
/** The end of the last transaction handed on: what is reported as read. */
|
|
53
|
+
private confirmedLsn;
|
|
54
|
+
private inTransaction;
|
|
55
|
+
private pending;
|
|
56
|
+
private slotName?;
|
|
57
|
+
constructor(options: WalCdcListenerOptions);
|
|
58
|
+
get active(): boolean;
|
|
59
|
+
/** Streaming on a connection that answered its last heartbeat. */
|
|
60
|
+
get connected(): boolean;
|
|
61
|
+
status(): PgNotifyListenerStatus;
|
|
62
|
+
/**
|
|
63
|
+
* Open the stream. Rejects if the first connection, the slot or
|
|
64
|
+
* `START_REPLICATION` fails — `wal_level` is not `logical`, the role may
|
|
65
|
+
* not replicate, the publication is missing, no slot is free — leaving
|
|
66
|
+
* the listener stopped so the caller can use triggers instead.
|
|
67
|
+
*/
|
|
68
|
+
start(): Promise<void>;
|
|
69
|
+
/** Close the stream; the server drops the temporary slot with it. Idempotent. */
|
|
70
|
+
stop(): Promise<void>;
|
|
71
|
+
private connect;
|
|
72
|
+
private onFrame;
|
|
73
|
+
/** Hand on what has been read. Every change in the stream is committed, so this needs no commit to wait for. */
|
|
74
|
+
private flush;
|
|
75
|
+
private abandon;
|
|
76
|
+
private startTimers;
|
|
77
|
+
/**
|
|
78
|
+
* Ask the server to answer at once. A half-open connection — packets
|
|
79
|
+
* stopped, no FIN, no RST — fires no error, so a stream that went quiet
|
|
80
|
+
* this way would look idle forever while every change went unseen.
|
|
81
|
+
*/
|
|
82
|
+
private heartbeat;
|
|
83
|
+
private clearHeartbeatDeadline;
|
|
84
|
+
private stopTimers;
|
|
85
|
+
private scheduleReconnect;
|
|
86
|
+
private withTimeout;
|
|
87
|
+
/** For logs and tests: the slot of the current stream, and how far it has read. */
|
|
88
|
+
position(): {
|
|
89
|
+
slot?: string;
|
|
90
|
+
confirmedLsn: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The logical replication wire format, as far as change capture needs it.
|
|
3
|
+
*
|
|
4
|
+
* A `START_REPLICATION … LOGICAL` stream is a COPY in both directions. The
|
|
5
|
+
* server sends CopyData frames that are either a keepalive or a chunk of WAL;
|
|
6
|
+
* with the built-in `pgoutput` plugin each WAL chunk is one message — a
|
|
7
|
+
* transaction's begin and commit, a table's description, a row inserted,
|
|
8
|
+
* updated or deleted, a truncate. The client answers with standby status
|
|
9
|
+
* updates naming how far it has read, which is what lets the server recycle
|
|
10
|
+
* the WAL behind it.
|
|
11
|
+
*
|
|
12
|
+
* Everything here is a pure function of bytes, so it is tested against frames
|
|
13
|
+
* built by hand; the connection that carries them is `WalCdcListener`.
|
|
14
|
+
*
|
|
15
|
+
* Formats: https://www.postgresql.org/docs/current/protocol-replication.html
|
|
16
|
+
* and https://www.postgresql.org/docs/current/protocol-logicalrep-message-formats.html
|
|
17
|
+
* (protocol version 1, the only one this asks for).
|
|
18
|
+
*/
|
|
19
|
+
import type { CdcChangeEvent } from "./CdcListener.js";
|
|
20
|
+
/** A column of a table as `pgoutput` describes it. */
|
|
21
|
+
export interface PgoutputColumn {
|
|
22
|
+
name: string;
|
|
23
|
+
/** Part of the replica identity: present in the old tuple of an update or delete. */
|
|
24
|
+
isKey: boolean;
|
|
25
|
+
typeOid: number;
|
|
26
|
+
}
|
|
27
|
+
export interface PgoutputRelation {
|
|
28
|
+
id: number;
|
|
29
|
+
schema: string;
|
|
30
|
+
table: string;
|
|
31
|
+
/** `d` default (the primary key), `n` nothing, `f` full, `i` index. */
|
|
32
|
+
replicaIdentity: string;
|
|
33
|
+
columns: PgoutputColumn[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One column of a row. `undefined` is an unchanged TOASTed value: the server
|
|
37
|
+
* did not send it because the update did not touch it.
|
|
38
|
+
*/
|
|
39
|
+
export type TupleValue = string | null | undefined;
|
|
40
|
+
export type PgoutputMessage = {
|
|
41
|
+
tag: "begin";
|
|
42
|
+
finalLsn: bigint;
|
|
43
|
+
xid: number;
|
|
44
|
+
} | {
|
|
45
|
+
tag: "commit";
|
|
46
|
+
commitLsn: bigint;
|
|
47
|
+
endLsn: bigint;
|
|
48
|
+
} | {
|
|
49
|
+
tag: "relation";
|
|
50
|
+
relation: PgoutputRelation;
|
|
51
|
+
} | {
|
|
52
|
+
tag: "insert";
|
|
53
|
+
relationId: number;
|
|
54
|
+
newTuple: TupleValue[];
|
|
55
|
+
} | {
|
|
56
|
+
tag: "update";
|
|
57
|
+
relationId: number;
|
|
58
|
+
oldTuple?: TupleValue[];
|
|
59
|
+
oldIsKeyOnly?: boolean;
|
|
60
|
+
newTuple: TupleValue[];
|
|
61
|
+
} | {
|
|
62
|
+
tag: "delete";
|
|
63
|
+
relationId: number;
|
|
64
|
+
oldTuple: TupleValue[];
|
|
65
|
+
oldIsKeyOnly: boolean;
|
|
66
|
+
} | {
|
|
67
|
+
tag: "truncate";
|
|
68
|
+
relationIds: number[];
|
|
69
|
+
}
|
|
70
|
+
/** Origin, type and logical messages: nothing capture acts on. */
|
|
71
|
+
| {
|
|
72
|
+
tag: "other";
|
|
73
|
+
type: string;
|
|
74
|
+
};
|
|
75
|
+
export type ReplicationFrame = {
|
|
76
|
+
kind: "xlog";
|
|
77
|
+
walStart: bigint;
|
|
78
|
+
walEnd: bigint;
|
|
79
|
+
data: Buffer;
|
|
80
|
+
} | {
|
|
81
|
+
kind: "keepalive";
|
|
82
|
+
walEnd: bigint;
|
|
83
|
+
replyRequested: boolean;
|
|
84
|
+
};
|
|
85
|
+
/** The payload of one CopyData frame from a replication stream. */
|
|
86
|
+
export declare function parseReplicationFrame(payload: Buffer): ReplicationFrame;
|
|
87
|
+
/** One `pgoutput` message: the data of an `xlog` frame. */
|
|
88
|
+
export declare function parsePgoutputMessage(data: Buffer): PgoutputMessage;
|
|
89
|
+
/**
|
|
90
|
+
* A standby status update: everything up to `lsn` is written, flushed and
|
|
91
|
+
* applied. Capture keeps nothing, so the three positions are the same — the
|
|
92
|
+
* end of the last transaction handed on.
|
|
93
|
+
*
|
|
94
|
+
* @param replyRequested Ask the server to answer at once with a keepalive,
|
|
95
|
+
* which is how the connection proves it is still alive.
|
|
96
|
+
*/
|
|
97
|
+
export declare function encodeStandbyStatus(lsn: bigint, replyRequested: boolean, nowMs?: number): Buffer;
|
|
98
|
+
/** A frontend CopyData message around `payload`: `d`, a length that counts itself, the bytes. */
|
|
99
|
+
export declare function copyDataFrame(payload: Buffer): Buffer;
|
|
100
|
+
/** `16/B374D848`, the way Postgres writes an LSN. */
|
|
101
|
+
export declare function formatLsn(lsn: bigint): string;
|
|
102
|
+
/**
|
|
103
|
+
* Turns a `pgoutput` stream into the change events the trigger listener emits,
|
|
104
|
+
* so `RealtimeService` cannot tell which one it is reading.
|
|
105
|
+
*
|
|
106
|
+
* Holds the relation descriptions the stream sends ahead of a table's first
|
|
107
|
+
* row (and again after its schema changes). The stream only ever carries
|
|
108
|
+
* committed transactions, so a change can be handed on as soon as it arrives.
|
|
109
|
+
*/
|
|
110
|
+
export declare class PgoutputChanges {
|
|
111
|
+
private readonly identityColumns;
|
|
112
|
+
private readonly relations;
|
|
113
|
+
/**
|
|
114
|
+
* @param identityColumns The columns a table's rows are addressed by, as
|
|
115
|
+
* provisioning attaches them; `undefined` for the replica identity.
|
|
116
|
+
*/
|
|
117
|
+
constructor(identityColumns: (schema: string, table: string) => readonly string[] | undefined);
|
|
118
|
+
/** The changes one message describes — none for anything but a row change. */
|
|
119
|
+
apply(message: PgoutputMessage): CdcChangeEvent[];
|
|
120
|
+
private change;
|
|
121
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RawSqlRunner } from "../../security/rls-enforcement.js";
|
|
2
|
+
import type { CdcTableRef } from "./trigger-cdc.js";
|
|
3
|
+
/** The publication WAL capture streams. A plain identifier: it is interpolated into replication commands. */
|
|
4
|
+
export declare const CDC_PUBLICATION = "rebase_cdc";
|
|
5
|
+
/**
|
|
6
|
+
* Why this database cannot do WAL capture, or `undefined` when it can as far
|
|
7
|
+
* as the server's settings go. Whether the streaming role may replicate is
|
|
8
|
+
* only known when it tries — a host can grant it through role membership
|
|
9
|
+
* (`rds_replication`, `cloudsqlsuperuser`) that no attribute shows.
|
|
10
|
+
*/
|
|
11
|
+
export declare function walCaptureBlocker(run: RawSqlRunner): Promise<string | undefined>;
|
|
12
|
+
export interface WalPublicationResult {
|
|
13
|
+
/** Tables in the publication, including ones an earlier boot added. */
|
|
14
|
+
published: CdcTableRef[];
|
|
15
|
+
skipped: Array<CdcTableRef & {
|
|
16
|
+
reason: string;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create the publication if it is missing and add every table it lacks.
|
|
21
|
+
*
|
|
22
|
+
* Throws when the publication cannot be created or read at all (no
|
|
23
|
+
* privilege), which the caller treats as "WAL capture is unavailable". A
|
|
24
|
+
* single table that cannot be added is reported in `skipped` instead, so one
|
|
25
|
+
* of them cannot turn capture off for the rest.
|
|
26
|
+
*/
|
|
27
|
+
export declare function provisionWalPublication(run: RawSqlRunner, tables: CdcTableRef[]): Promise<WalPublicationResult>;
|
|
28
|
+
/** One line per table the publication could not take: its writes reach realtime only through this server. */
|
|
29
|
+
export declare function reportUnpublishedTables(result: WalPublicationResult): void;
|
|
@@ -143,6 +143,20 @@ 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 table holds under the property key `key`, or `undefined`.
|
|
148
|
+
*
|
|
149
|
+
* A Drizzle table is an object whose own properties are its columns — and
|
|
150
|
+
* also everything any object answers to. `key in table` is true of
|
|
151
|
+
* `constructor`, `toString` and `hasOwnProperty`, inherited from the
|
|
152
|
+
* prototype, and of `enableRLS`, a method Drizzle sets on the table itself;
|
|
153
|
+
* reading one of those as a column put a function into the statement as a
|
|
154
|
+
* bound parameter. A filter on `constructor` then compiled to a comparison
|
|
155
|
+
* between two parameters — "a filter that names nothing" without the 400 —
|
|
156
|
+
* and `__proto__` crashed the builder into a 500. Only an own, object-valued
|
|
157
|
+
* property is a column.
|
|
158
|
+
*/
|
|
159
|
+
export declare function columnAtKey(table: PgTable<any>, key: string): AnyPgColumn | undefined;
|
|
146
160
|
/**
|
|
147
161
|
* The column a `joinPath` step names, on a table that may key it either way.
|
|
148
162
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type SQL } from "drizzle-orm";
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import type
|
|
3
|
+
import { type Properties, type ResolvedVia } from "@rebasepro/types";
|
|
4
4
|
import { DrizzleClient } from "../interfaces.js";
|
|
5
5
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
6
6
|
/**
|
|
@@ -27,6 +27,14 @@ export interface JunctionBinding {
|
|
|
27
27
|
parentColumn: AnyPgColumn;
|
|
28
28
|
/** The junction column holding the id of the row on the far side. */
|
|
29
29
|
targetColumn: AnyPgColumn;
|
|
30
|
+
/**
|
|
31
|
+
* The keys the junction's drizzle table holds those two columns under —
|
|
32
|
+
* what an insert's values are keyed by. A table may key a column by
|
|
33
|
+
* another name than the column's own (`postId: integer("post_id")`), and
|
|
34
|
+
* drizzle leaves a value under any other key out of the statement.
|
|
35
|
+
*/
|
|
36
|
+
parentKey: string;
|
|
37
|
+
targetKey: string;
|
|
30
38
|
/** `<collection>.<relation>`, for error messages. */
|
|
31
39
|
label: string;
|
|
32
40
|
/**
|
|
@@ -48,7 +48,8 @@ export declare function resolveNestedPath(path: string, registry: PostgresCollec
|
|
|
48
48
|
export declare function isJunctionBackedRelation(relation: ResolvedRelation): boolean;
|
|
49
49
|
/**
|
|
50
50
|
* Reject a create or update whose body names a relation Rebase does not write
|
|
51
|
-
* — a multi-hop `via
|
|
51
|
+
* — a multi-hop `via`, or one whose step joins on either of several columns
|
|
52
|
+
* (`writable: false`) — before anything is read or written.
|
|
52
53
|
*
|
|
53
54
|
* A single-hop `via` is written through this door as it shipped (to-one: the
|
|
54
55
|
* target's key; to-many: one junction's rows). A longer chain used to get as
|
|
@@ -4,6 +4,7 @@ import { DataDriver, IncludeSpec, WebSocketMessage, LogicalCondition, OrderByTup
|
|
|
4
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig } from "../interfaces.js";
|
|
6
6
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
7
|
+
import type { CdcTableRef } from "./cdc/trigger-cdc.js";
|
|
7
8
|
import { ChannelBus } from "./channel-bus/index.js";
|
|
8
9
|
import type { ChannelRetentionRule, RealtimeCounts, RealtimeListenerHealth } from "@rebasepro/types";
|
|
9
10
|
/**
|
|
@@ -313,6 +314,8 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
313
314
|
* never track presence, and each of their closes was a `DELETE` too.
|
|
314
315
|
*/
|
|
315
316
|
private presenceTrackers;
|
|
317
|
+
/** Each client's roster writes still running, chained in order — see {@link presenceStoreOp}. */
|
|
318
|
+
private presenceStoreQueues;
|
|
316
319
|
/**
|
|
317
320
|
* Channels whose oversized ephemeral broadcasts have already been reported,
|
|
318
321
|
* so a hot channel logs the problem once rather than once per message.
|
|
@@ -462,7 +465,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
462
465
|
* refetches once per this interval, which is the whole cost.
|
|
463
466
|
*/
|
|
464
467
|
private static readonly REFETCH_MAX_WAIT_MS;
|
|
465
|
-
/**
|
|
468
|
+
/** Where DB-level change events come from — capture triggers or the WAL (undefined unless CDC is enabled). */
|
|
466
469
|
private cdcListener?;
|
|
467
470
|
/** Whether database-level CDC is the active cross-instance change source. */
|
|
468
471
|
private cdcActive;
|
|
@@ -656,6 +659,19 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
656
659
|
private indexClientChannel;
|
|
657
660
|
private unindexClientChannel;
|
|
658
661
|
private handleMessage;
|
|
662
|
+
/**
|
|
663
|
+
* Whether `clientId` is a socket this service still holds.
|
|
664
|
+
*
|
|
665
|
+
* A frame reaches this service after the socket door has awaited — the
|
|
666
|
+
* identity recheck, the data rate limiter — and a channel frame may await
|
|
667
|
+
* again for its authorizer. A client that closed inside one of those awaits
|
|
668
|
+
* was already removed by `removeClient`, which runs on `close`, so whatever
|
|
669
|
+
* its frame registers now is never cleaned up: a subscription that keeps
|
|
670
|
+
* its group and its refetches for the life of the process, or a membership
|
|
671
|
+
* that keeps a channel alive with nobody in it. Checked synchronously
|
|
672
|
+
* before the registration, so nothing can close the socket in between.
|
|
673
|
+
*/
|
|
674
|
+
private socketIsOpen;
|
|
659
675
|
/**
|
|
660
676
|
* Refuse a new subscription past the socket's ceiling, and say so.
|
|
661
677
|
*
|
|
@@ -1121,7 +1137,17 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1121
1137
|
private readPeerChannels;
|
|
1122
1138
|
/** Start gossiping on a bus that publishes on demand. */
|
|
1123
1139
|
private startBusGossip;
|
|
1124
|
-
/**
|
|
1140
|
+
/**
|
|
1141
|
+
* Run one of `clientId`'s roster writes when there is a roster, after the
|
|
1142
|
+
* ones it made before, and never let it throw.
|
|
1143
|
+
*
|
|
1144
|
+
* In order, because each is its own statement on the pool: a removal sent
|
|
1145
|
+
* while the client's upsert was still on its way could run first, and the
|
|
1146
|
+
* upsert then put the row back. That row is this instance's, so the
|
|
1147
|
+
* stale-roster sweep leaves it alone, and the in-process sweep no longer
|
|
1148
|
+
* knows the client — the departed client stayed in every roster for as
|
|
1149
|
+
* long as the instance ran.
|
|
1150
|
+
*/
|
|
1125
1151
|
private presenceStoreOp;
|
|
1126
1152
|
/** Periodic cleanup for stale presences */
|
|
1127
1153
|
private ensurePresenceCleanup;
|
|
@@ -1182,6 +1208,19 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1182
1208
|
* (bypass PgBouncer — LISTEN needs a session connection).
|
|
1183
1209
|
*/
|
|
1184
1210
|
enableCdc(connectionString: string): Promise<void>;
|
|
1211
|
+
/**
|
|
1212
|
+
* Enable change capture read from the write-ahead log instead of NOTIFY —
|
|
1213
|
+
* `REALTIME_CDC=wal`. Same events, same pipeline as {@link enableCdc};
|
|
1214
|
+
* writers pay for no trigger and no NOTIFY. Rejects when the stream cannot
|
|
1215
|
+
* be opened (see {@link WalCdcListener.start}), leaving CDC inactive so the
|
|
1216
|
+
* caller can enable the trigger listener instead.
|
|
1217
|
+
*
|
|
1218
|
+
* @param tables What provisioning captures, with the columns each table's
|
|
1219
|
+
* rows are addressed by. A table it does not name is addressed by
|
|
1220
|
+
* its replica identity.
|
|
1221
|
+
*/
|
|
1222
|
+
enableWalCdc(connectionString: string, tables: readonly CdcTableRef[]): Promise<void>;
|
|
1223
|
+
private activateCdc;
|
|
1185
1224
|
/**
|
|
1186
1225
|
* Refetch every live subscription, as a change to its path would.
|
|
1187
1226
|
*
|
|
@@ -1245,6 +1284,12 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1245
1284
|
* Returns whether the table was recognised as a junction.
|
|
1246
1285
|
*/
|
|
1247
1286
|
private handleJunctionCdcEvent;
|
|
1287
|
+
/**
|
|
1288
|
+
* Notify every subscribed child list of one many-to-many relation,
|
|
1289
|
+
* whichever parent it belongs to — for a junction change that names no
|
|
1290
|
+
* single list.
|
|
1291
|
+
*/
|
|
1292
|
+
private notifyEveryListOf;
|
|
1248
1293
|
/**
|
|
1249
1294
|
* Compute the canonical (possibly composite) id string from a captured row,
|
|
1250
1295
|
* or {@link ANY_ROW} when it names none — a key too large to notify, a
|
|
@@ -519,6 +519,17 @@ export declare class DrizzleConditionBuilder {
|
|
|
519
519
|
* Build conditions for join path relations
|
|
520
520
|
*/
|
|
521
521
|
private static buildJoinPathConditions;
|
|
522
|
+
/**
|
|
523
|
+
* One step of a join path walked target → parent: the table it brings in
|
|
524
|
+
* and the condition it joins on.
|
|
525
|
+
*
|
|
526
|
+
* A step listing alternatives joins on any of them, OR-ed. Each alternative
|
|
527
|
+
* is built the way a plain step is, and they must all bring in the same
|
|
528
|
+
* table — they are several ways to match one pair of tables, not several
|
|
529
|
+
* paths. The junction fallback is only tried for a plain step: guessing a
|
|
530
|
+
* junction for one alternative of several is guessing twice.
|
|
531
|
+
*/
|
|
532
|
+
private static buildReverseJoinStep;
|
|
522
533
|
/**
|
|
523
534
|
* Build a single join condition between tables
|
|
524
535
|
*/
|
|
@@ -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 budgetSendBuffers, M as terminateIfBacklogged, N as assertReadRequestReadable, ct as SqlResultTooLargeError, it as effectiveSqlRole, j as reapSilentSockets, lt as isNestedPath, ot as sqlRoleRanAs, st as SQL_RESULT_BYTE_BUDGET, ut as resolveNestedPath } from "./open-rebase-
|
|
5
|
-
import { r as BranchingUnsupportedError } from "./BranchService-
|
|
4
|
+
import { A as budgetSendBuffers, M as terminateIfBacklogged, N as assertReadRequestReadable, ct as SqlResultTooLargeError, it as effectiveSqlRole, j as reapSilentSockets, lt as isNestedPath, ot as sqlRoleRanAs, st as SQL_RESULT_BYTE_BUDGET, ut as resolveNestedPath } from "./open-rebase-D9n8idex.js";
|
|
5
|
+
import { r as BranchingUnsupportedError } from "./BranchService-BPssiD8_.js";
|
|
6
6
|
import { ApiError, DATABASE_UNAVAILABLE_MESSAGE, RUNTIME_DEFAULT_MAX_BODY_SIZE, assertFieldOpsValid, assertNestedWriteAllowed, assertNoFieldOpsOnCreate, assertNoUserUpsert, assertUserCreationBodyValid, assertWriteRequestValid, createUserThroughAuthCollection, decideImpersonation, declaredErrorAnswer, extractUserFromToken, getAccessModel, 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 } from "@rebasepro/common";
|
|
@@ -766,13 +766,14 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig, au
|
|
|
766
766
|
const session = clientSessions.get(clientId);
|
|
767
767
|
const credential = session?.credential;
|
|
768
768
|
if (!session?.user || !credential) return "live";
|
|
769
|
+
const impersonate = session.impersonate;
|
|
769
770
|
let outcome;
|
|
770
771
|
try {
|
|
771
|
-
outcome = await resolve(credential,
|
|
772
|
+
outcome = await resolve(credential, impersonate);
|
|
772
773
|
} catch (error) {
|
|
773
774
|
return { unavailable: storeUnavailableAnswer(error) };
|
|
774
775
|
}
|
|
775
|
-
if (session.credential !== credential || !session.user) return session.user ? "live" : "ended";
|
|
776
|
+
if (session.credential !== credential || session.impersonate !== impersonate || !session.user) return session.user ? "live" : "ended";
|
|
776
777
|
session.checkedAt = Date.now();
|
|
777
778
|
if (!("user" in outcome)) {
|
|
778
779
|
if (outcome.code) endSession(clientId, outcome.code, outcome.refused);
|
|
@@ -1697,4 +1698,4 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig, au
|
|
|
1697
1698
|
//#endregion
|
|
1698
1699
|
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 };
|
|
1699
1700
|
|
|
1700
|
-
//# sourceMappingURL=websocket-
|
|
1701
|
+
//# sourceMappingURL=websocket-D4wrzF3b.js.map
|