@rebasepro/server-postgres 0.29.0 → 0.29.2
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-JiYJ_n9E.js → BranchService-X9R505mP.js} +3 -3
- package/dist/{BranchService-JiYJ_n9E.js.map → BranchService-X9R505mP.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +90 -12
- package/dist/PostgresBootstrapper.d.ts +34 -0
- package/dist/auth/ensure-tables.d.ts +2 -2
- package/dist/auth/schema-version.d.ts +5 -5
- package/dist/auth/services.d.ts +9 -9
- package/dist/{backup-cli-D_aKXPyX.js → backup-cli-CwiJEp_J.js} +3 -3
- package/dist/{backup-cli-D_aKXPyX.js.map → backup-cli-CwiJEp_J.js.map} +1 -1
- package/dist/{boot-ddl-D4W9o9xE.js → boot-ddl-CbZj9ovZ.js} +2 -2
- package/dist/{boot-ddl-D4W9o9xE.js.map → boot-ddl-CbZj9ovZ.js.map} +1 -1
- package/dist/{cli-console-DPdZCWTi.js → cli-console-DDkNetCz.js} +6 -6
- package/dist/{cli-console-DPdZCWTi.js.map → cli-console-DDkNetCz.js.map} +1 -1
- package/dist/{cli-errors-D8s4z_3g.js → cli-errors-C73Qy7WJ.js} +49 -6
- package/dist/{cli-errors-D8s4z_3g.js.map → cli-errors-C73Qy7WJ.js.map} +1 -1
- package/dist/cli.js +209 -53
- package/dist/cli.js.map +1 -1
- package/dist/{connection-COuS5Fm-.js → connection-C1zXTPJq.js} +7 -3
- package/dist/{connection-COuS5Fm-.js.map → connection-C1zXTPJq.js.map} +1 -1
- package/dist/data-transformer.d.ts +2 -2
- package/dist/database-health.d.ts +2 -1
- package/dist/database-preflight-DIauc8i5.js +184 -0
- package/dist/database-preflight-DIauc8i5.js.map +1 -0
- package/dist/{databasePoolManager-7hXVurmG.js → databasePoolManager-DIjzlTK4.js} +2 -2
- package/dist/{databasePoolManager-7hXVurmG.js.map → databasePoolManager-DIjzlTK4.js.map} +1 -1
- package/dist/db-subcommands.d.ts +1 -1
- package/dist/{deferred-index-build-F2GWu009.js → deferred-index-build-DDdnjaOW.js} +25 -9
- package/dist/deferred-index-build-DDdnjaOW.js.map +1 -0
- package/dist/{doctor-_g2tHRtG.js → doctor-DwMXljiq.js} +11 -11
- package/dist/doctor-DwMXljiq.js.map +1 -0
- package/dist/{ensure-collection-policies-DUpWJb5D.js → ensure-collection-policies-DJsOMpaI.js} +23 -13
- package/dist/ensure-collection-policies-DJsOMpaI.js.map +1 -0
- package/dist/{ensure-collection-tables-BK--gDo6.js → ensure-collection-tables-h1mUO7Uu.js} +18 -10
- package/dist/ensure-collection-tables-h1mUO7Uu.js.map +1 -0
- package/dist/{ensure-tables-Bx1DYarz.js → ensure-tables-CUqYgMvo.js} +4 -4
- package/dist/ensure-tables-CUqYgMvo.js.map +1 -0
- package/dist/{enum-labels-kept-DyFE4Gaq.js → enum-labels-kept-z7ustOl_.js} +3 -3
- package/dist/{enum-labels-kept-DyFE4Gaq.js.map → enum-labels-kept-z7ustOl_.js.map} +1 -1
- package/dist/{generate-drizzle-schema-taNTu3xv.js → generate-drizzle-schema-BIUqhSzh.js} +2 -2
- package/dist/{generate-drizzle-schema-taNTu3xv.js.map → generate-drizzle-schema-BIUqhSzh.js.map} +1 -1
- package/dist/{generate-drizzle-schema-logic-DpFA1UVd.js → generate-drizzle-schema-logic-BBXjxm5z.js} +3 -3
- package/dist/{generate-drizzle-schema-logic-DpFA1UVd.js.map → generate-drizzle-schema-logic-BBXjxm5z.js.map} +1 -1
- package/dist/{generate-files-DbwU8Btx.js → generate-files-BkiRFoV1.js} +3 -3
- package/dist/{generate-files-DbwU8Btx.js.map → generate-files-BkiRFoV1.js.map} +1 -1
- package/dist/{generate-postgres-ddl-logic-ISVgsP34.js → generate-postgres-ddl-logic-G9PvjHrr.js} +10 -5
- package/dist/{generate-postgres-ddl-logic-ISVgsP34.js.map → generate-postgres-ddl-logic-G9PvjHrr.js.map} +1 -1
- package/dist/{generated-schema-diff-4lOC0g1_.js → generated-schema-diff-D2soazQU.js} +18 -7
- package/dist/generated-schema-diff-D2soazQU.js.map +1 -0
- package/dist/history/HistoryService.d.ts +2 -3
- package/dist/history/ensure-history-table.d.ts +8 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +22 -14
- package/dist/index.es.js.map +1 -1
- package/dist/interfaces.d.ts +24 -2
- package/dist/{introspect-db-logic-DgQVzccW.js → introspect-db-logic-DWqAEURB.js} +7 -5
- package/dist/introspect-db-logic-DWqAEURB.js.map +1 -0
- package/dist/{migrate-baseline-BeepEphh.js → migrate-baseline-CveNQli3.js} +166 -460
- package/dist/migrate-baseline-CveNQli3.js.map +1 -0
- package/dist/{migrate-policy-stamps-cYMJ_9Ha.js → migrate-policy-stamps-C4qbQ0jK.js} +42 -13
- package/dist/migrate-policy-stamps-C4qbQ0jK.js.map +1 -0
- package/dist/{open-rebase-CTNBmmH8.js → open-rebase-Cvid3iwR.js} +1813 -689
- package/dist/open-rebase-Cvid3iwR.js.map +1 -0
- package/dist/open-rebase.d.ts +7 -2
- package/dist/{pg-error-utils-BLOVXK67.js → pg-error-utils-80uTIHQs.js} +2 -2
- package/dist/{pg-error-utils-BLOVXK67.js.map → pg-error-utils-80uTIHQs.js.map} +1 -1
- package/dist/pipelined-transaction.d.ts +24 -37
- package/dist/{plan-schema-CMNWvqIa.js → plan-schema-CMhNYEYF.js} +109 -14
- package/dist/plan-schema-CMhNYEYF.js.map +1 -0
- package/dist/{policy-drift-IjD2AUD-.js → policy-drift-Bx6663KD.js} +29 -6
- package/dist/policy-drift-Bx6663KD.js.map +1 -0
- package/dist/push-index-adoption-C-TpM445.js +22 -0
- package/dist/push-index-adoption-C-TpM445.js.map +1 -0
- package/dist/{push-index-prebuild-CIvajIrL.js → push-index-prebuild-xbpgZEJK.js} +4 -4
- package/dist/{push-index-prebuild-CIvajIrL.js.map → push-index-prebuild-xbpgZEJK.js.map} +1 -1
- package/dist/{push-kept-defaults-CLbsuSmo.js → push-kept-defaults-D-JEv0Gn.js} +2 -2
- package/dist/{push-kept-defaults-CLbsuSmo.js.map → push-kept-defaults-D-JEv0Gn.js.map} +1 -1
- package/dist/{push-legacy-renames-DeW_HTLJ.js → push-legacy-renames-7UKspspl.js} +4 -4
- package/dist/{push-legacy-renames-DeW_HTLJ.js.map → push-legacy-renames-7UKspspl.js.map} +1 -1
- package/dist/{push-policy-plan--oRXOj4X.js → push-policy-plan-BOw5PtU8.js} +14 -8
- package/dist/push-policy-plan-BOw5PtU8.js.map +1 -0
- package/dist/read-routing.d.ts +10 -30
- package/dist/{render-ddl-CzVcbbR1.js → render-ddl-Di-fTGti.js} +40 -10
- package/dist/render-ddl-Di-fTGti.js.map +1 -0
- package/dist/request-role-cli-Bxxskru9.js +260 -0
- package/dist/request-role-cli-Bxxskru9.js.map +1 -0
- package/dist/request-role-cli.d.ts +86 -0
- package/dist/request-role-migration-BCW4v0rq.js +150 -0
- package/dist/request-role-migration-BCW4v0rq.js.map +1 -0
- package/dist/rls-bootstrap-sql-CxszeSc7.js +534 -0
- package/dist/rls-bootstrap-sql-CxszeSc7.js.map +1 -0
- package/dist/rls-enforcement-CyUCPDH8.js +1195 -0
- package/dist/rls-enforcement-CyUCPDH8.js.map +1 -0
- package/dist/rls-settings-BCGMIig3.js +231 -0
- package/dist/rls-settings-BCGMIig3.js.map +1 -0
- package/dist/schema/doctor-cli.js +145 -7
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +27 -0
- package/dist/schema/drizzle-ddl.d.ts +2 -2
- package/dist/schema/ensure-collection-policies.d.ts +15 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-postgres-ddl-logic.d.ts +5 -1
- package/dist/schema/generate-postgres-ddl.js +1 -1
- package/dist/schema/index-adoption.d.ts +99 -0
- package/dist/schema/introspect-db-logic.d.ts +2 -1
- package/dist/schema/introspect-db.js +3 -3
- package/dist/schema/migrate-policy-stamps.d.ts +19 -1
- package/dist/schema/plan/diff-plan.d.ts +14 -2
- package/dist/schema/plan/render-ddl.d.ts +17 -3
- package/dist/schema/plan/tenant-keep-trigger.d.ts +9 -0
- package/dist/schema/plan/types.d.ts +17 -0
- package/dist/schema/plan/updated-at-trigger.d.ts +1 -1
- package/dist/schema/plan/view-names.d.ts +6 -0
- package/dist/schema/push-index-adoption.d.ts +10 -0
- package/dist/schema/push-policy-plan.d.ts +5 -1
- package/dist/schema/rls-bootstrap-sql.d.ts +34 -0
- package/dist/schema/search-column.d.ts +2 -2
- package/dist/search-column-BM-GV6vH.js.map +1 -1
- package/dist/security/caller-sql-columns.d.ts +60 -0
- package/dist/security/caller-sql.d.ts +8 -0
- package/dist/security/database-preflight.d.ts +24 -0
- package/dist/security/policy-drift.d.ts +19 -1
- package/dist/security/request-role-migration.d.ts +36 -0
- package/dist/security/rls-enforcement.d.ts +277 -21
- package/dist/security/rls-settings.d.ts +210 -0
- package/dist/services/FetchService.d.ts +33 -8
- package/dist/services/PersistService.d.ts +75 -4
- package/dist/services/RelationService.d.ts +1 -1
- package/dist/services/channel-bus/PostgresChannelBus.d.ts +2 -2
- package/dist/services/channel-bus/index.d.ts +2 -2
- package/dist/services/channel-history.d.ts +2 -2
- package/dist/services/channel-presence.d.ts +3 -3
- package/dist/services/dataService.d.ts +8 -2
- package/dist/services/realtimeService.d.ts +21 -5
- package/dist/services/socket-liveness.d.ts +6 -1
- package/dist/services/view-access.d.ts +2 -2
- package/dist/types.d.ts +1 -1
- package/dist/utils/drizzle-conditions.d.ts +12 -0
- package/dist/utils/positional-params.d.ts +40 -0
- package/dist/view-names-Dscp6--B.js +24 -0
- package/dist/view-names-Dscp6--B.js.map +1 -0
- package/dist/{websocket-D2y88dOa.js → websocket-BSYV_KSw.js} +3 -3
- package/dist/websocket-BSYV_KSw.js.map +1 -0
- package/dist/websocket.d.ts +14 -3
- package/package.json +7 -7
- package/dist/deferred-index-build-F2GWu009.js.map +0 -1
- package/dist/doctor-_g2tHRtG.js.map +0 -1
- package/dist/ensure-collection-policies-DUpWJb5D.js.map +0 -1
- package/dist/ensure-collection-tables-BK--gDo6.js.map +0 -1
- package/dist/ensure-tables-Bx1DYarz.js.map +0 -1
- package/dist/generated-schema-diff-4lOC0g1_.js.map +0 -1
- package/dist/introspect-db-logic-DgQVzccW.js.map +0 -1
- package/dist/migrate-baseline-BeepEphh.js.map +0 -1
- package/dist/migrate-policy-stamps-cYMJ_9Ha.js.map +0 -1
- package/dist/open-rebase-CTNBmmH8.js.map +0 -1
- package/dist/plan-schema-CMNWvqIa.js.map +0 -1
- package/dist/policy-drift-IjD2AUD-.js.map +0 -1
- package/dist/push-policy-plan--oRXOj4X.js.map +0 -1
- package/dist/render-ddl-CzVcbbR1.js.map +0 -1
- package/dist/rls-enforcement-jZTv1yci.js +0 -534
- package/dist/rls-enforcement-jZTv1yci.js.map +0 -1
- package/dist/websocket-D2y88dOa.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Properties } from "@rebasepro/types";
|
|
1
|
+
import { FilterValues, type LogicalCondition, Properties } from "@rebasepro/types";
|
|
2
2
|
import { RelationService } from "./RelationService.js";
|
|
3
3
|
import { type ReadCallContextProvider } from "./read-scope.js";
|
|
4
4
|
import { RelationWriteService } from "./RelationWriteService.js";
|
|
5
5
|
import { FetchService } from "./FetchService.js";
|
|
6
6
|
import { DrizzleClient } from "../interfaces.js";
|
|
7
7
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
8
|
+
import { ApiError } from "@rebasepro/server";
|
|
8
9
|
/**
|
|
9
10
|
* The top-level properties whose value is stamped once, when the row is
|
|
10
11
|
* created: `on_create` dates and `user_on_create` identities.
|
|
@@ -38,12 +39,35 @@ export interface PersistSaveOptions {
|
|
|
38
39
|
* instead of assuming it.
|
|
39
40
|
*/
|
|
40
41
|
unreadRow?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Nothing follows this write in its transaction, so its last statement
|
|
44
|
+
* may carry the `COMMIT` — see `commitWithNextStatement`. Honoured only
|
|
45
|
+
* where the row is the last thing written (no relation or junction
|
|
46
|
+
* write after it).
|
|
47
|
+
*/
|
|
48
|
+
commitsTransaction?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* How an upsert treats a row already on its conflict target, beyond replacing
|
|
52
|
+
* it: leave it as it is (`ignoreDuplicates`), or replace it only when it
|
|
53
|
+
* matches `conflictWhere`. A row left alone is answered as `undefined`.
|
|
54
|
+
*/
|
|
55
|
+
export interface ConflictRule {
|
|
56
|
+
/** `ON CONFLICT DO NOTHING`. */
|
|
57
|
+
ignoreDuplicates?: boolean;
|
|
58
|
+
/** `ON CONFLICT DO UPDATE … WHERE`, over the stored row's columns. */
|
|
59
|
+
conflictWhere?: FilterValues<string>;
|
|
41
60
|
}
|
|
42
61
|
/** One row of a {@link PersistService.saveRows} batch: its values and what its INSERT alone may write. */
|
|
43
62
|
export interface PersistBatchRow {
|
|
44
63
|
values: Record<string, unknown>;
|
|
45
64
|
insertOnlyKeys?: readonly string[];
|
|
46
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* A filtered write whose filter compiled to no condition: it would address
|
|
68
|
+
* every row, and is refused rather than run.
|
|
69
|
+
*/
|
|
70
|
+
export declare function filterRequired(collectionPath: string): ApiError;
|
|
47
71
|
/**
|
|
48
72
|
* Service for handling all row write operations.
|
|
49
73
|
* Handles saving, deleting, and updating rows.
|
|
@@ -103,9 +127,12 @@ export declare class PersistService {
|
|
|
103
127
|
*/
|
|
104
128
|
lockRow(collectionPath: string, id: string | number): Promise<void>;
|
|
105
129
|
/**
|
|
106
|
-
* Delete
|
|
130
|
+
* Delete a row by ID. `options.commitsTransaction`: see
|
|
131
|
+
* {@link PersistSaveOptions.commitsTransaction}.
|
|
107
132
|
*/
|
|
108
|
-
delete(collectionPath: string, id: string | number, _databaseId?: string
|
|
133
|
+
delete(collectionPath: string, id: string | number, _databaseId?: string, options?: {
|
|
134
|
+
commitsTransaction?: boolean;
|
|
135
|
+
}): Promise<void>;
|
|
109
136
|
/**
|
|
110
137
|
* Delete all rows from a collection
|
|
111
138
|
*/
|
|
@@ -149,6 +176,11 @@ export declare class PersistService {
|
|
|
149
176
|
* not have. What they compile to is `field-op-sql.ts`.
|
|
150
177
|
*/
|
|
151
178
|
save<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, id?: string | number, databaseId?: string, options?: PersistSaveOptions): Promise<Record<string, unknown>>;
|
|
179
|
+
/**
|
|
180
|
+
* {@link save}, for an upsert with a {@link ConflictRule}: `undefined`
|
|
181
|
+
* when the rule left the stored row on the conflict target as it was.
|
|
182
|
+
*/
|
|
183
|
+
saveUnlessKept<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, id?: string | number, databaseId?: string, options?: PersistSaveOptions & ConflictRule): Promise<Record<string, unknown> | undefined>;
|
|
152
184
|
/**
|
|
153
185
|
* Write a batch of new rows — inserted, or upserted with `options.upsert` —
|
|
154
186
|
* as multi-row statements, and return each row as {@link save} returns it.
|
|
@@ -177,7 +209,8 @@ export declare class PersistService {
|
|
|
177
209
|
saveRows(collectionPath: string, rows: readonly PersistBatchRow[], options?: {
|
|
178
210
|
upsert?: boolean;
|
|
179
211
|
onConflict?: readonly string[];
|
|
180
|
-
|
|
212
|
+
commitsTransaction?: boolean;
|
|
213
|
+
} & ConflictRule): Promise<(Record<string, unknown> | undefined)[] | undefined>;
|
|
181
214
|
/**
|
|
182
215
|
* Update rows by id, each with its own values, as
|
|
183
216
|
* `UPDATE … FROM (VALUES …) … RETURNING` statements, and return each row as
|
|
@@ -196,6 +229,44 @@ export declare class PersistService {
|
|
|
196
229
|
id: string | number;
|
|
197
230
|
values: Record<string, unknown>;
|
|
198
231
|
}[]): Promise<Record<string, unknown>[] | undefined>;
|
|
232
|
+
/**
|
|
233
|
+
* Update every row the conditions match, in one
|
|
234
|
+
* `UPDATE … SET … WHERE … RETURNING` statement, and return each row as
|
|
235
|
+
* {@link save} returns it. Field operations are compiled as for one row,
|
|
236
|
+
* and their declared bounds are checked by the same statement: a matched
|
|
237
|
+
* row an operation would take out of bounds fails the call.
|
|
238
|
+
*
|
|
239
|
+
* `undefined`, before anything is written, for a write that needs what
|
|
240
|
+
* only the row-by-row update does: a relation in the values, or a
|
|
241
|
+
* collection whose rows the statement cannot return (`beforeQuery`,
|
|
242
|
+
* per-field read access). `options.commitsTransaction`: see
|
|
243
|
+
* {@link PersistSaveOptions.commitsTransaction}; not honoured when bounds
|
|
244
|
+
* are checked, which takes a statement after the update.
|
|
245
|
+
*/
|
|
246
|
+
updateWhere(collectionPath: string, filter: FilterValues<string> | undefined, logical: LogicalCondition | undefined, values: Record<string, unknown>, options?: {
|
|
247
|
+
commitsTransaction?: boolean;
|
|
248
|
+
}): Promise<Record<string, unknown>[] | undefined>;
|
|
249
|
+
/**
|
|
250
|
+
* Delete every row the conditions match, in one `DELETE … WHERE …
|
|
251
|
+
* RETURNING` statement, and return each deleted row's key columns.
|
|
252
|
+
* `options.commitsTransaction`: see {@link PersistSaveOptions.commitsTransaction}.
|
|
253
|
+
*/
|
|
254
|
+
deleteWhere(collectionPath: string, filter: FilterValues<string> | undefined, logical: LogicalCondition | undefined, options?: {
|
|
255
|
+
commitsTransaction?: boolean;
|
|
256
|
+
}): Promise<Record<string, unknown>[]>;
|
|
257
|
+
/**
|
|
258
|
+
* Whether the row `id` addresses matches `filter`, as the caller reads
|
|
259
|
+
* it: for an upsert under a `conflictWhere` that found its row first.
|
|
260
|
+
*/
|
|
261
|
+
rowMatches(collectionPath: string, id: string | number, filter: FilterValues<string>): Promise<boolean>;
|
|
262
|
+
/**
|
|
263
|
+
* Whether the stored row on an upsert's conflict target is one the
|
|
264
|
+
* caller's write may not change at all — outside their `beforeQuery`
|
|
265
|
+
* scope, or in the trash — rather than one a {@link ConflictRule} kept.
|
|
266
|
+
* Asked only when there is a scope or a trash: without either, nothing
|
|
267
|
+
* but the rule can have kept it, and no statement is sent.
|
|
268
|
+
*/
|
|
269
|
+
private storedRowRefusesWrite;
|
|
199
270
|
/**
|
|
200
271
|
* The caller's `beforeQuery` scope over this table, as one condition: what
|
|
201
272
|
* a stored row must satisfy for a write that meets it to change it. The
|
|
@@ -13,7 +13,7 @@ import { type ReadCallContextProvider } from "./read-scope.js";
|
|
|
13
13
|
* the gap with a single confined cast.
|
|
14
14
|
*
|
|
15
15
|
* Exported so `data-transformer` uses this one rather than restating the same
|
|
16
|
-
* fact — it
|
|
16
|
+
* fact — it double-cast `query.innerJoin(...)` to `typeof query`, which is
|
|
17
17
|
* the same claim about the same drizzle behaviour in a second spelling.
|
|
18
18
|
*/
|
|
19
19
|
export declare function applyDynamicJoin<T>(query: T, joinTable: PgTable, condition: SQL): T;
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
* the client's history replay, so a lost frame costs a live update rather
|
|
28
28
|
* than correctness. That is what makes coalescing safe.
|
|
29
29
|
*/
|
|
30
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
31
30
|
import { type PgNotifyListenerStatus } from "../pg-notify-listener.js";
|
|
32
31
|
import { ChannelBus, ChannelBusFrame, ChannelBusHandler } from "./ChannelBus.js";
|
|
32
|
+
import type { PgSqlDatabase } from "../../interfaces.js";
|
|
33
33
|
/** NOTIFY channel carrying channel-bus frames. */
|
|
34
34
|
export declare const CHANNEL_BUS_NOTIFY_CHANNEL = "rebase_channel_bus";
|
|
35
35
|
/**
|
|
@@ -64,7 +64,7 @@ export declare class PostgresChannelBus implements ChannelBus {
|
|
|
64
64
|
private pendingBytes;
|
|
65
65
|
private windowTimer?;
|
|
66
66
|
private stopped;
|
|
67
|
-
constructor(db:
|
|
67
|
+
constructor(db: PgSqlDatabase<Record<string, unknown>>, connectionString: string, options?: {
|
|
68
68
|
batchWindowMs?: number;
|
|
69
69
|
});
|
|
70
70
|
start(handler: ChannelBusHandler): Promise<void>;
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
* without this file learning about it. See `@rebasepro/types` →
|
|
15
15
|
* `types/channel_bus.ts` for the contract such a package implements.
|
|
16
16
|
*/
|
|
17
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
18
17
|
import { type ChannelBus, type ChannelBusSetting } from "@rebasepro/types";
|
|
18
|
+
import type { PgSqlDatabase } from "../../interfaces.js";
|
|
19
19
|
export * from "./ChannelBus.js";
|
|
20
20
|
export { PostgresChannelBus, CHANNEL_BUS_NOTIFY_CHANNEL, PG_NOTIFY_MAX_PAYLOAD_BYTES, DEFAULT_BATCH_WINDOW_MS, parseChannelBusFrame, parseChannelBusPayload } from "./PostgresChannelBus.js";
|
|
21
21
|
export interface ChannelBusDeps {
|
|
22
|
-
db:
|
|
22
|
+
db: PgSqlDatabase<Record<string, unknown>>;
|
|
23
23
|
/**
|
|
24
24
|
* Direct (non-pooled) Postgres URL for the LISTEN client. `LISTEN` is
|
|
25
25
|
* session state, so behind PgBouncer in transaction mode this must be the
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
* return rows and they would look plausible. Cursors are tiny and are kept
|
|
30
30
|
* forever; see {@link prune}, which touches only `channel_messages`.
|
|
31
31
|
*/
|
|
32
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
33
32
|
import type { ChannelHistoryEntry, ChannelRetentionRule } from "@rebasepro/types";
|
|
33
|
+
import type { PgSqlDatabase } from "../interfaces.js";
|
|
34
34
|
/**
|
|
35
35
|
* Parse a retention TTL into milliseconds.
|
|
36
36
|
*
|
|
@@ -95,7 +95,7 @@ export declare class ChannelHistoryStore {
|
|
|
95
95
|
private lastPruned;
|
|
96
96
|
private nextPruneSweepAt;
|
|
97
97
|
private tablesReady;
|
|
98
|
-
constructor(db:
|
|
98
|
+
constructor(db: PgSqlDatabase<Record<string, unknown>>, rules?: ChannelRetentionRule[]);
|
|
99
99
|
/** Whether any channel retains anything at all. */
|
|
100
100
|
get enabled(): boolean;
|
|
101
101
|
/**
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
* is the one that announces the departures, so a stale client produces one
|
|
26
26
|
* `presence_diff` for the cluster rather than one per replica.
|
|
27
27
|
*/
|
|
28
|
-
import {
|
|
29
|
-
/** A tracked client, as
|
|
28
|
+
import type { PgSqlDatabase } from "../interfaces.js";
|
|
29
|
+
/** A tracked client, as every instance sees it. */
|
|
30
30
|
export interface PresenceRow {
|
|
31
31
|
channel: string;
|
|
32
32
|
clientId: string;
|
|
@@ -36,7 +36,7 @@ export declare class ChannelPresenceStore {
|
|
|
36
36
|
private readonly db;
|
|
37
37
|
private readonly instanceId;
|
|
38
38
|
private tablesReady;
|
|
39
|
-
constructor(db:
|
|
39
|
+
constructor(db: PgSqlDatabase<Record<string, unknown>>, instanceId: string);
|
|
40
40
|
/**
|
|
41
41
|
* Create the roster table. Idempotent, and safe to run on every instance at
|
|
42
42
|
* once.
|
|
@@ -3,7 +3,7 @@ import type { VectorSearchParams } from "@rebasepro/types";
|
|
|
3
3
|
import { FetchService } from "./FetchService.js";
|
|
4
4
|
import type { ReadCallContextProvider } from "./read-scope.js";
|
|
5
5
|
import type { WithDeleted } from "./soft-delete.js";
|
|
6
|
-
import { PersistService, type PersistSaveOptions } from "./PersistService.js";
|
|
6
|
+
import { PersistService, type ConflictRule, type PersistSaveOptions } from "./PersistService.js";
|
|
7
7
|
import { RelationService } from "./RelationService.js";
|
|
8
8
|
import { DataRepository, DrizzleClient } from "../interfaces.js";
|
|
9
9
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
@@ -119,10 +119,14 @@ export declare class DataService implements DataRepository {
|
|
|
119
119
|
* Save an row (create or update)
|
|
120
120
|
*/
|
|
121
121
|
save<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, id?: string | number, databaseId?: string, options?: PersistSaveOptions): Promise<Record<string, unknown>>;
|
|
122
|
+
/** See {@link PersistService.saveUnlessKept}. */
|
|
123
|
+
saveUnlessKept<M extends Record<string, unknown>>(collectionPath: string, values: Partial<M>, id?: string | number, databaseId?: string, options?: PersistSaveOptions & ConflictRule): Promise<Record<string, unknown> | undefined>;
|
|
122
124
|
/**
|
|
123
125
|
* Delete an row by ID
|
|
124
126
|
*/
|
|
125
|
-
delete(collectionPath: string, id: string | number, databaseId?: string
|
|
127
|
+
delete(collectionPath: string, id: string | number, databaseId?: string, options?: {
|
|
128
|
+
commitsTransaction?: boolean;
|
|
129
|
+
}): Promise<void>;
|
|
126
130
|
/**
|
|
127
131
|
* Delete all rows from a collection
|
|
128
132
|
*/
|
|
@@ -133,6 +137,8 @@ export declare class DataService implements DataRepository {
|
|
|
133
137
|
* Execute raw SQL
|
|
134
138
|
*/
|
|
135
139
|
executeSql(sqlText: string, params?: unknown[]): Promise<Record<string, unknown>[]>;
|
|
140
|
+
/** {@link executeSql}, answering with the driver's whole result: its rows and its column descriptions. */
|
|
141
|
+
executeSqlResult(sqlText: string, params?: unknown[]): Promise<unknown>;
|
|
136
142
|
/**
|
|
137
143
|
* Get the underlying FetchService for advanced use
|
|
138
144
|
*/
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { WebSocket } from "ws";
|
|
2
1
|
import { EventEmitter } from "events";
|
|
3
2
|
import { DataDriver, IncludeSpec, WebSocketMessage, LogicalCondition, OrderByTuple } from "@rebasepro/types";
|
|
4
|
-
import {
|
|
5
|
-
import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig } from "../interfaces.js";
|
|
3
|
+
import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig, type PgSqlDatabase } from "../interfaces.js";
|
|
6
4
|
import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
|
|
5
|
+
import type { RequestIdentity } from "../security/rls-settings.js";
|
|
7
6
|
import type { CdcTableRef } from "./cdc/trigger-cdc.js";
|
|
8
7
|
import { ChannelBus } from "./channel-bus/index.js";
|
|
9
8
|
import type { ChannelRetentionRule, RealtimeCounts, RealtimeListenerHealth } from "@rebasepro/types";
|
|
@@ -228,6 +227,21 @@ export declare function parseRealtimeTuning(value: unknown, source: string, unit
|
|
|
228
227
|
* than quietly becoming no ceiling.
|
|
229
228
|
*/
|
|
230
229
|
export declare function parseMaxSocketsPerUser(value: unknown, source: string): number;
|
|
230
|
+
/**
|
|
231
|
+
* What the service uses of a client socket: its state, sending a frame, the
|
|
232
|
+
* close and error events, and the two ways of ending it. `ws`'s `WebSocket`
|
|
233
|
+
* satisfies it; so does any socket-shaped stand-in a caller hands over.
|
|
234
|
+
*/
|
|
235
|
+
export interface RealtimeClientSocket {
|
|
236
|
+
readonly readyState: number;
|
|
237
|
+
/** Bytes sent and not yet read: see `terminateIfBacklogged`. */
|
|
238
|
+
readonly bufferedAmount: number;
|
|
239
|
+
send(data: string): void;
|
|
240
|
+
on(event: "close", listener: () => void): unknown;
|
|
241
|
+
on(event: "error", listener: (error: Error) => void): unknown;
|
|
242
|
+
close(code?: number, reason?: string): void;
|
|
243
|
+
terminate(): void;
|
|
244
|
+
}
|
|
231
245
|
/**
|
|
232
246
|
* PostgreSQL-specific realtime service.
|
|
233
247
|
* Handles WebSocket connections and subscriptions for real-time row updates.
|
|
@@ -502,7 +516,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
502
516
|
* already arrived. An echo later than that costs one more refetch.
|
|
503
517
|
*/
|
|
504
518
|
private static readonly CDC_DEDUP_WINDOW_MS;
|
|
505
|
-
constructor(db:
|
|
519
|
+
constructor(db: PgSqlDatabase<any>, registry: PostgresCollectionRegistry);
|
|
506
520
|
/**
|
|
507
521
|
* Restricted role that auth-scoped refetches run as (via `SET LOCAL ROLE`)
|
|
508
522
|
* so RLS `select` policies bind. Set by the bootstrapper alongside
|
|
@@ -511,6 +525,8 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
511
525
|
* would leak rows the initial (isolated) fetch correctly hid.
|
|
512
526
|
*/
|
|
513
527
|
rlsUserRole?: string;
|
|
528
|
+
/** How a request picks its role and identity settings (`rls`), set with {@link rlsUserRole}. */
|
|
529
|
+
rlsRequest?: RequestIdentity;
|
|
514
530
|
/**
|
|
515
531
|
* Verbose subscription tracing.
|
|
516
532
|
*
|
|
@@ -650,7 +666,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
650
666
|
* alone. A socket ends its own through the `unsubscribe` frame.
|
|
651
667
|
*/
|
|
652
668
|
unsubscribe(subscriptionId: string): void;
|
|
653
|
-
addClient(clientId: string, ws:
|
|
669
|
+
addClient(clientId: string, ws: RealtimeClientSocket): void;
|
|
654
670
|
handleClientMessage(clientId: string, message: WebSocketMessage, authContext?: SubscriptionAuthContext): Promise<void>;
|
|
655
671
|
/** Record what a socket opted into when it opened. See `socket-opt-ins.ts`. */
|
|
656
672
|
setClientOptIns(clientId: string, optIns: ReadonlySet<string>): void;
|
|
@@ -74,6 +74,11 @@ export declare function enforceProcessSendBudget(budget?: number): WebSocket[];
|
|
|
74
74
|
* not answer the previous ping. Returns the function that stops it.
|
|
75
75
|
*/
|
|
76
76
|
export declare function reapSilentSockets(wss: WebSocketServer, intervalMs?: number): () => void;
|
|
77
|
+
/** What {@link terminateIfBacklogged} reads of a socket; `ws`'s `WebSocket` satisfies it. */
|
|
78
|
+
export interface BackloggableSocket {
|
|
79
|
+
readonly bufferedAmount: number;
|
|
80
|
+
terminate(): void;
|
|
81
|
+
}
|
|
77
82
|
/**
|
|
78
83
|
* Terminate `ws` if its unsent backlog has passed {@link MAX_SOCKET_BUFFERED_BYTES}.
|
|
79
84
|
* Returns whether it did; the caller then sends nothing.
|
|
@@ -82,4 +87,4 @@ export declare function reapSilentSockets(wss: WebSocketServer, intervalMs?: num
|
|
|
82
87
|
* the process-wide budget is kept, summed at most every
|
|
83
88
|
* {@link PROCESS_BUDGET_CHECK_MS} — see {@link enforceProcessSendBudget}.
|
|
84
89
|
*/
|
|
85
|
-
export declare function terminateIfBacklogged(ws:
|
|
90
|
+
export declare function terminateIfBacklogged(ws: BackloggableSocket, clientId: string): boolean;
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* with no viewer at all.
|
|
12
12
|
*/
|
|
13
13
|
import { type CollectionConfig } from "@rebasepro/types";
|
|
14
|
-
|
|
15
|
-
export
|
|
14
|
+
import { DEFAULT_VIEW_ROLES } from "../schema/plan/view-names.js";
|
|
15
|
+
export { DEFAULT_VIEW_ROLES };
|
|
16
16
|
/** Whether a collection serves a view rather than a table. */
|
|
17
17
|
export declare function isViewCollection(collection: CollectionConfig | undefined): boolean;
|
|
18
18
|
/** Refuse a caller who holds none of a materialized view's roles. A no-op for anything else. */
|
package/dist/types.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type RebasePgTable = PgTable & Record<string, AnyPgColumn>;
|
|
|
14
14
|
* A concrete table does not satisfy it: its columns have specific types and it
|
|
15
15
|
* carries methods and symbols besides, so `Record<string, AnyPgColumn>` is not
|
|
16
16
|
* a supertype and a direct `as` is refused. Written out, that refusal was
|
|
17
|
-
* answered six times with
|
|
17
|
+
* answered six times with a double cast to `RebasePgTable`, which also discarded
|
|
18
18
|
* the check that the thing being converted is a table at all — the parameter
|
|
19
19
|
* below is what restores it.
|
|
20
20
|
*/
|
|
@@ -117,6 +117,11 @@ export interface FilterCompilationOptions {
|
|
|
117
117
|
type FilterTarget = {
|
|
118
118
|
kind: "column";
|
|
119
119
|
column: AnyPgColumn;
|
|
120
|
+
} | {
|
|
121
|
+
/** A text column folded to one case — `lower(artist)`. */
|
|
122
|
+
kind: "text";
|
|
123
|
+
/** The folded expression every operator compares. */
|
|
124
|
+
expression: SQL;
|
|
120
125
|
} | {
|
|
121
126
|
/** A path *inside* a json/jsonb column — `metadata->>country`. */
|
|
122
127
|
kind: "json";
|
|
@@ -305,6 +310,13 @@ export declare class DrizzleConditionBuilder {
|
|
|
305
310
|
* from a query string, and `->>` takes a text parameter perfectly well.
|
|
306
311
|
*/
|
|
307
312
|
private static buildJsonPathCondition;
|
|
313
|
+
/**
|
|
314
|
+
* A comparison against a text expression: a JSON path's leaf, or a column
|
|
315
|
+
* folded to one case. Values compare as text — booleans as `->>` renders
|
|
316
|
+
* them — and the membership operators compile to `= ANY` / `<> ALL` over
|
|
317
|
+
* one array parameter, so a list of any length is one bound value.
|
|
318
|
+
*/
|
|
319
|
+
private static buildTextCondition;
|
|
308
320
|
/**
|
|
309
321
|
* A filter on a relation that owns no column on this row — `EXISTS` over
|
|
310
322
|
* the rows it reaches.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw SQL with `$n` placeholders, as one drizzle statement that binds each
|
|
3
|
+
* parameter once.
|
|
4
|
+
*
|
|
5
|
+
* `rebase.sql(text, { params })` takes the text and parameters `pg` takes, and
|
|
6
|
+
* has to mean what `pg` means by them. It used to split the text on every
|
|
7
|
+
* `/\$(\d+)/` and bind each occurrence as a new parameter, which broke three
|
|
8
|
+
* ways:
|
|
9
|
+
*
|
|
10
|
+
* - A `$1` written N times became N bind parameters. Postgres infers each
|
|
11
|
+
* one's type alone, so an uncast reuse failed with `could not determine data
|
|
12
|
+
* type of parameter $7` where `pg` ran the same text, and the value was sent
|
|
13
|
+
* N times.
|
|
14
|
+
* - A `$1` inside a string literal, a quoted identifier, a comment or a
|
|
15
|
+
* dollar-quoted body was bound as a parameter, changing the statement.
|
|
16
|
+
* - `a$1`, an identifier Postgres allows, was split in two.
|
|
17
|
+
*
|
|
18
|
+
* So the text is scanned the way Postgres's lexer reads it, and only a
|
|
19
|
+
* placeholder outside those spans is a parameter. The first occurrence of
|
|
20
|
+
* each `$n` becomes a `sql.param`; drizzle numbers params in the order they
|
|
21
|
+
* appear, so a later occurrence is written as the number drizzle gave the
|
|
22
|
+
* first. Each value is sent once, and every occurrence is the same parameter.
|
|
23
|
+
*/
|
|
24
|
+
import { type SQL } from "drizzle-orm";
|
|
25
|
+
/** One piece of the statement: SQL text, or a reference to parameter `n` (1-based). */
|
|
26
|
+
export type SqlPiece = {
|
|
27
|
+
text: string;
|
|
28
|
+
} | {
|
|
29
|
+
param: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Split `text` into SQL text and `$n` placeholders, leaving string literals,
|
|
33
|
+
* quoted identifiers, comments and dollar-quoted bodies whole.
|
|
34
|
+
*/
|
|
35
|
+
export declare function splitPlaceholders(text: string): SqlPiece[];
|
|
36
|
+
/**
|
|
37
|
+
* `text` and `params` as one drizzle statement: each `$n` bound once, however
|
|
38
|
+
* often it appears, and nothing inside a literal, identifier or comment bound.
|
|
39
|
+
*/
|
|
40
|
+
export declare function positionalStatement(text: string, params?: readonly unknown[]): SQL;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "module";
|
|
2
|
+
__createRequire(import.meta.url);
|
|
3
|
+
import { toPostgresIdentifier } from "@rebasepro/utils";
|
|
4
|
+
//#region src/schema/plan/view-names.ts
|
|
5
|
+
/**
|
|
6
|
+
* The names a materialized-view collection lives under.
|
|
7
|
+
*
|
|
8
|
+
* Postgres puts no row-level security on a materialized view, and the request
|
|
9
|
+
* role can read anything it holds `SELECT` on. So the stored rows live under
|
|
10
|
+
* {@link viewRowsName}, which only the owner may read, and the collection's
|
|
11
|
+
* own name is a view over them that serves them to the collection's roles
|
|
12
|
+
* (`view.roles`) and to the server itself — a gate in the database, so SQL run
|
|
13
|
+
* as a caller meets it as the SDK does.
|
|
14
|
+
*/
|
|
15
|
+
/** The roles a materialized view is served to when it names none. */
|
|
16
|
+
var DEFAULT_VIEW_ROLES = ["admin"];
|
|
17
|
+
/** Where a materialized view's rows are stored. A frozen derived name. */
|
|
18
|
+
var viewRowsName = (name) => toPostgresIdentifier(`${name}_rebase_rows`);
|
|
19
|
+
/** The comment the stored rows carry, beside the gate's `rebase:view:<hash>`. */
|
|
20
|
+
var VIEW_ROWS_COMMENT_PREFIX = "rebase:view-rows:";
|
|
21
|
+
//#endregion
|
|
22
|
+
export { VIEW_ROWS_COMMENT_PREFIX as n, viewRowsName as r, DEFAULT_VIEW_ROLES as t };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=view-names-Dscp6--B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-names-Dscp6--B.js","names":[],"sources":["../src/schema/plan/view-names.ts"],"sourcesContent":["/**\n * The names a materialized-view collection lives under.\n *\n * Postgres puts no row-level security on a materialized view, and the request\n * role can read anything it holds `SELECT` on. So the stored rows live under\n * {@link viewRowsName}, which only the owner may read, and the collection's\n * own name is a view over them that serves them to the collection's roles\n * (`view.roles`) and to the server itself — a gate in the database, so SQL run\n * as a caller meets it as the SDK does.\n */\nimport { toPostgresIdentifier } from \"@rebasepro/utils\";\n\n/** The roles a materialized view is served to when it names none. */\nexport const DEFAULT_VIEW_ROLES: readonly string[] = [\"admin\"];\n\n/** Where a materialized view's rows are stored. A frozen derived name. */\nexport const viewRowsName = (name: string): string => toPostgresIdentifier(`${name}_rebase_rows`);\n\n/** The comment the stored rows carry, beside the gate's `rebase:view:<hash>`. */\nexport const VIEW_ROWS_COMMENT_PREFIX = \"rebase:view-rows:\";\n"],"mappings":";;;;;;;;;;;;;;;AAaA,IAAa,qBAAwC,CAAC,OAAO;;AAG7D,IAAa,gBAAgB,SAAyB,qBAAqB,GAAG,KAAK,aAAa;;AAGhG,IAAa,2BAA2B"}
|
|
@@ -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-Cvid3iwR.js";
|
|
5
|
+
import { r as BranchingUnsupportedError } from "./BranchService-X9R505mP.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";
|
|
@@ -1698,4 +1698,4 @@ function createPostgresWebSocket(server, realtimeService, driver, authConfig, au
|
|
|
1698
1698
|
//#endregion
|
|
1699
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 };
|
|
1700
1700
|
|
|
1701
|
-
//# sourceMappingURL=websocket-
|
|
1701
|
+
//# sourceMappingURL=websocket-BSYV_KSw.js.map
|