@rebasepro/server-postgres 0.30.0 → 0.31.0-canary.g59cd6fd
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/README.md +11 -8
- package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
- package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
- package/dist/PostgresBackendDriver.d.ts +99 -54
- package/dist/PostgresBootstrapper.d.ts +12 -27
- package/dist/auth/ensure-tables.d.ts +16 -5
- package/dist/auth/schema-version.d.ts +2 -2
- package/dist/auth/services.d.ts +2 -3
- package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
- package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
- package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
- package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
- package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
- package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
- package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
- package/dist/cli-console-DsRgGSBR.js.map +1 -0
- package/dist/cli-console.d.ts +16 -13
- package/dist/cli-flags.d.ts +8 -9
- package/dist/cli-helpers.d.ts +15 -11
- package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
- package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
- package/dist/cli-schema-dir.d.ts +64 -0
- package/dist/cli.js +192 -257
- package/dist/cli.js.map +1 -1
- package/dist/data-transformer.d.ts +50 -19
- package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
- package/dist/database-preflight-bfnIBnjM.js.map +1 -0
- package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
- package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
- package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
- package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
- package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
- package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
- package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
- package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
- package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
- package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
- package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
- package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
- package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
- package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
- package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
- package/dist/generate-files-tlJ9_lGI.js.map +1 -0
- package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
- package/dist/generate-next-step-CO09dovd.js.map +1 -0
- package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
- package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
- package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
- package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
- package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
- package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
- package/dist/history/ensure-history-table.d.ts +22 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.es.js +201 -25
- package/dist/index.es.js.map +1 -1
- package/dist/interfaces.d.ts +3 -4
- package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
- package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
- package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
- package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
- package/dist/load-tables-B1Re74ng.js +92 -0
- package/dist/load-tables-B1Re74ng.js.map +1 -0
- package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
- package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
- package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
- package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
- package/dist/model/PostgresTableRegistry.d.ts +159 -0
- package/dist/model/build-registry.d.ts +25 -0
- package/dist/model/refresh-relational-schema.d.ts +24 -0
- package/dist/model/runtime-table.d.ts +53 -0
- package/dist/{collections → model}/validate-relations.d.ts +15 -21
- package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
- package/dist/open-rebase-4kisUF_k.js.map +1 -0
- package/dist/open-rebase.d.ts +16 -15
- package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
- package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
- package/dist/plan-schema-Hbtjhge3.js +1633 -0
- package/dist/plan-schema-Hbtjhge3.js.map +1 -0
- package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
- package/dist/policy-drift-BVMyqHSa.js.map +1 -0
- package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
- package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
- package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
- package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
- package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
- package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
- package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
- package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
- package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
- package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
- package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
- package/dist/render-ddl-D4n86NHz.js.map +1 -0
- package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
- package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
- package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
- package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
- package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
- package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
- package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
- package/dist/rls-settings-CmGK2U0a.js.map +1 -0
- package/dist/schema/auth-users-columns.d.ts +1 -11
- package/dist/schema/catalogue-schema.d.ts +33 -29
- package/dist/schema/classify-change.d.ts +23 -16
- package/dist/schema/column-type-drift.d.ts +16 -0
- package/dist/schema/config-relations.d.ts +10 -9
- package/dist/schema/deferred-index-build.d.ts +1 -1
- package/dist/schema/doctor-cli.js +1544 -66
- package/dist/schema/doctor-cli.js.map +1 -1
- package/dist/schema/doctor-database.d.ts +7 -7
- package/dist/schema/doctor-policy-checks.d.ts +4 -4
- package/dist/schema/doctor-search-scale.d.ts +14 -14
- package/dist/schema/doctor.d.ts +27 -27
- package/dist/schema/dynamic-tables.d.ts +6 -5
- package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
- package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
- package/dist/schema/enum-labels-kept.d.ts +6 -6
- package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
- package/dist/schema/generate-drizzle-schema.js +1 -1
- package/dist/schema/generate-files.d.ts +6 -6
- package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
- package/dist/schema/generate-postgres-ddl.js +11 -11
- package/dist/schema/generate-postgres-ddl.js.map +1 -1
- package/dist/schema/generate-schema-commit.d.ts +13 -8
- package/dist/schema/generated-schema-diff.d.ts +16 -16
- package/dist/schema/generated-schema-staleness.d.ts +11 -11
- package/dist/schema/index-adoption.d.ts +4 -4
- package/dist/schema/introspect-db-customization.d.ts +47 -0
- package/dist/schema/introspect-db-inference.d.ts +30 -9
- package/dist/schema/introspect-db-logic.d.ts +79 -110
- package/dist/schema/introspect-db-project.d.ts +15 -18
- package/dist/schema/introspect-db-queries.d.ts +1 -1
- package/dist/schema/introspect-db-search.d.ts +25 -4
- package/dist/schema/introspect-db-storage.d.ts +4 -74
- package/dist/schema/introspect-db.js +102 -90
- package/dist/schema/introspect-db.js.map +1 -1
- package/dist/schema/introspect-runtime.d.ts +47 -36
- package/dist/schema/introspect-tables.d.ts +182 -0
- package/dist/schema/load-tables.d.ts +55 -0
- package/dist/schema/migrate-policy-stamps.d.ts +4 -4
- package/dist/schema/migration-freshness.d.ts +13 -13
- package/dist/schema/plan/column-order.d.ts +82 -0
- package/dist/schema/plan/diff-plan.d.ts +9 -3
- package/dist/schema/plan/plan-schema.d.ts +55 -52
- package/dist/schema/plan/render-drizzle.d.ts +1 -1
- package/dist/schema/plan/types.d.ts +24 -15
- package/dist/schema/push-index-adoption.d.ts +3 -3
- package/dist/schema/push-index-prebuild.d.ts +3 -3
- package/dist/schema/push-kept-defaults.d.ts +7 -7
- package/dist/schema/push-legacy-renames.d.ts +3 -3
- package/dist/schema/push-policy-plan.d.ts +5 -5
- package/dist/schema/reconcile-schema.d.ts +5 -5
- package/dist/schema/relation-names.d.ts +15 -20
- package/dist/schema/render-outputs.d.ts +76 -0
- package/dist/schema/search-column.d.ts +11 -43
- package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
- package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
- package/dist/schema/vector-index.d.ts +24 -28
- package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
- package/dist/search-column-BO-WND-B.js.map +1 -0
- package/dist/security/caller-sql-columns.d.ts +9 -6
- package/dist/security/policy-drift.d.ts +14 -14
- package/dist/security/rls-enforcement.d.ts +19 -25
- package/dist/security/rls-settings.d.ts +2 -2
- package/dist/security/served-table-protection.d.ts +125 -0
- package/dist/services/FetchService.d.ts +22 -133
- package/dist/services/PersistService.d.ts +6 -17
- package/dist/services/RelationService.d.ts +57 -106
- package/dist/services/RelationWriteService.d.ts +59 -66
- package/dist/services/cdc/identity-columns.d.ts +7 -5
- package/dist/services/cdc/junction-tables.d.ts +14 -14
- package/dist/services/collection-helpers.d.ts +52 -95
- package/dist/services/dataService.d.ts +15 -12
- package/dist/services/field-op-sql.d.ts +11 -9
- package/dist/services/field-viewer.d.ts +12 -11
- package/dist/services/hidden-columns.d.ts +30 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/junction-writes.d.ts +37 -18
- package/dist/services/nested-path.d.ts +18 -18
- package/dist/services/read-field-access.d.ts +23 -7
- package/dist/services/read-scope.d.ts +10 -9
- package/dist/services/realtimeService.d.ts +25 -10
- package/dist/services/relation-tables.d.ts +97 -0
- package/dist/services/row-pipeline.d.ts +50 -69
- package/dist/services/soft-delete.d.ts +25 -24
- package/dist/services/table-hooks.d.ts +146 -0
- package/dist/services/view-access.d.ts +7 -7
- package/dist/services/write-transaction-scope.d.ts +1 -1
- package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
- package/dist/source-VxbrQojV.js.map +1 -0
- package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
- package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +70 -84
- package/dist/utils/pg-array-null-patch.d.ts +27 -10
- package/dist/utils/pg-error-utils.d.ts +4 -4
- package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
- package/dist/vector-index-VSh3ufTd.js.map +1 -0
- package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
- package/dist/websocket-BevXvwfo.js.map +1 -0
- package/dist/websocket.d.ts +2 -2
- package/package.json +7 -7
- package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
- package/dist/cli-collections-path.d.ts +0 -31
- package/dist/cli-console-DBPw-oAz.js.map +0 -1
- package/dist/cli-errors-DYTxnLbW.js.map +0 -1
- package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
- package/dist/collections/buildRegistry.d.ts +0 -27
- package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
- package/dist/column-plan-helpers-BeSztMor.js +0 -161
- package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
- package/dist/database-preflight-iBpT7-vv.js.map +0 -1
- package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
- package/dist/doctor-Kg1oUK0Q.js +0 -1458
- package/dist/doctor-Kg1oUK0Q.js.map +0 -1
- package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
- package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
- package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
- package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
- package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
- package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
- package/dist/generate-files-CsaVzatS.js.map +0 -1
- package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
- package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
- package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
- package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
- package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
- package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
- package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
- package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
- package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
- package/dist/open-rebase-40paQfVW.js.map +0 -1
- package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
- package/dist/plan-schema-vJd3UEmT.js +0 -1604
- package/dist/plan-schema-vJd3UEmT.js.map +0 -1
- package/dist/policy-drift-C-m0uWHH.js.map +0 -1
- package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
- package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
- package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
- package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
- package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
- package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
- package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
- package/dist/rls-settings-BCGMIig3.js.map +0 -1
- package/dist/schema/column-plan-helpers.d.ts +0 -161
- package/dist/schema/introspect-db-naming.d.ts +0 -10
- package/dist/search-column-BM-GV6vH.js.map +0 -1
- package/dist/source-fZb92pN8.js.map +0 -1
- package/dist/vector-index-DsQ3V2d2.js.map +0 -1
- package/dist/websocket-B7ex6AQM.js.map +0 -1
|
@@ -3,8 +3,8 @@ import { BranchService } from "./services/BranchService.js";
|
|
|
3
3
|
import { RealtimeService, type SubscriptionAuthContext } from "./services/realtimeService.js";
|
|
4
4
|
import { DatabasePoolManager } from "./databasePoolManager.js";
|
|
5
5
|
import { DrizzleClient } from "./interfaces.js";
|
|
6
|
-
import { DatabaseAdmin, DatabaseHealthSample, DatabasePoolStats, SQLAdmin, CallerSqlOptions, DataDriver, DeleteProps,
|
|
7
|
-
import {
|
|
6
|
+
import { DatabaseAdmin, DatabaseHealthSample, DatabasePoolStats, SQLAdmin, CallerSqlOptions, DataDriver, DeleteProps, FetchCollectionProps, FetchOneProps, ListenCollectionProps, ListenOneProps, RebaseCallContext, RebaseServerClient, RebaseSdkData, RestFetchService, BatchWriteProps, SaveManyProps, SaveProps, SqlCursor, SqlScriptResult, UpdateManyProps, UpdateRelationPivotProps, UpdateWhereProps, DeleteManyProps, DeleteWhereProps, TableMetadata, User } from "@rebasepro/types";
|
|
7
|
+
import { PostgresTableRegistry } from "./model/PostgresTableRegistry.js";
|
|
8
8
|
import { HistoryService } from "./history/HistoryService.js";
|
|
9
9
|
import type { RequestIdentity } from "./security/rls-settings.js";
|
|
10
10
|
import { ColumnOrigins } from "./security/caller-sql-columns.js";
|
|
@@ -71,7 +71,7 @@ export declare class RoleSwitchUnavailableError extends Error {
|
|
|
71
71
|
}
|
|
72
72
|
export declare class PostgresBackendDriver implements DataDriver {
|
|
73
73
|
db: DrizzleClient;
|
|
74
|
-
readonly registry:
|
|
74
|
+
readonly registry: PostgresTableRegistry;
|
|
75
75
|
poolManager?: DatabasePoolManager | undefined;
|
|
76
76
|
key: string;
|
|
77
77
|
initialised: boolean;
|
|
@@ -169,14 +169,14 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
169
169
|
row: Record<string, unknown> | null;
|
|
170
170
|
databaseId?: string;
|
|
171
171
|
}>;
|
|
172
|
-
constructor(db: DrizzleClient, realtimeService: RealtimeService, registry:
|
|
172
|
+
constructor(db: DrizzleClient, realtimeService: RealtimeService, registry: PostgresTableRegistry, user?: User, poolManager?: DatabasePoolManager | undefined, historyService?: HistoryService);
|
|
173
173
|
/**
|
|
174
174
|
* Typed admin capabilities (SQLAdmin + SchemaAdmin + BranchAdmin).
|
|
175
175
|
* Implemented as a getter so method references are resolved at call-time,
|
|
176
176
|
* allowing test spies applied after construction to take effect.
|
|
177
177
|
*/
|
|
178
178
|
get admin(): DatabaseAdmin;
|
|
179
|
-
/** The diff with each table named by the
|
|
179
|
+
/** The diff with each table named by the slug it is served at, where it is served. */
|
|
180
180
|
private nameDiffCollections;
|
|
181
181
|
/**
|
|
182
182
|
* `SQLAdmin.listen`: a `LISTEN` on a connection of its own, through the
|
|
@@ -204,8 +204,8 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
204
204
|
/**
|
|
205
205
|
* REST-optimised fetch service (include-aware eager-loading).
|
|
206
206
|
* Delegates to the underlying FetchService (include-aware eager loading),
|
|
207
|
-
* then runs the afterRead pipeline on the results. The raw FetchService
|
|
208
|
-
*
|
|
207
|
+
* then runs the afterRead pipeline on the results. The raw FetchService
|
|
208
|
+
* runs no hooks, so masking must be applied here — otherwise every
|
|
209
209
|
* REST/SDK read leaks unmasked data (see {@link applyAfterReadForRest}).
|
|
210
210
|
*/
|
|
211
211
|
get restFetchService(): RestFetchService;
|
|
@@ -235,40 +235,33 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
235
235
|
* that is attached after construction. The type now leaves `data` off, and
|
|
236
236
|
* a driver that was never given a client refuses by name, at the read.
|
|
237
237
|
*/
|
|
238
|
+
/**
|
|
239
|
+
* The runtime table a data path addresses (`registry.tableAt`: a slug,
|
|
240
|
+
* a table name, or a walk through relations), `undefined` for no path.
|
|
241
|
+
* Every write and read resolves its table here, from the path — never
|
|
242
|
+
* from a `collection` a caller handed in.
|
|
243
|
+
*/
|
|
244
|
+
private tableAt;
|
|
238
245
|
private buildCallContext;
|
|
239
|
-
private resolveCollectionCallbacks;
|
|
240
246
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
247
|
+
* The hooks that run for the table a path addresses — global, the table's
|
|
248
|
+
* own, its columns' transforms — read off the compiled table in the
|
|
249
|
+
* registry, never off a collection (a socket frame's included).
|
|
243
250
|
*/
|
|
244
|
-
private
|
|
245
|
-
private static hasAfterRead;
|
|
251
|
+
private hooksAt;
|
|
246
252
|
/**
|
|
247
253
|
* Refuse an aggregate that would read what `afterRead` hides.
|
|
248
254
|
*
|
|
249
255
|
* An aggregate reads the stored columns and never passes through the
|
|
250
|
-
*
|
|
256
|
+
* hooks, so on a table whose rows one rewrites, `max(email)` or
|
|
251
257
|
* `groupBy=salary` hands back the value the mask exists to withhold, one
|
|
252
|
-
* bucket at a time. What a
|
|
253
|
-
* here, so the rule is closed: on such a
|
|
258
|
+
* bucket at a time. What a hook does to a row cannot be known from
|
|
259
|
+
* here, so the rule is closed: on such a table only `count()` with no
|
|
254
260
|
* `groupBy` is served — the number `GET /count` already gives — and any
|
|
255
|
-
* other aggregate is refused, whichever tier (global,
|
|
256
|
-
*
|
|
261
|
+
* other aggregate is refused, whichever tier (global, the table's, or a
|
|
262
|
+
* column's `.transform()`) the hook sits on.
|
|
257
263
|
*/
|
|
258
264
|
private assertAggregateUnmasked;
|
|
259
|
-
/**
|
|
260
|
-
* Apply afterRead to REST/SDK read results.
|
|
261
|
-
*
|
|
262
|
-
* The REST / `include` path fetches rows through the raw fetch service, which
|
|
263
|
-
* does NOT run callbacks — so without this, `afterRead` transforms (e.g. PII
|
|
264
|
-
* masking) are silently skipped on every SDK/REST read, leaking raw data.
|
|
265
|
-
* This choke point guarantees afterRead runs there too, matching the driver's
|
|
266
|
-
* fetchCollection/fetchOne paths.
|
|
267
|
-
*
|
|
268
|
-
* It also masks embedded relation data one level deep by running the TARGET
|
|
269
|
-
* collection's afterRead (so `post.author.email` is masked by the authors
|
|
270
|
-
* collection, not left raw).
|
|
271
|
-
*/
|
|
272
265
|
/**
|
|
273
266
|
* One stored row as `restFetchService.fetchOneForRest` serves it: through
|
|
274
267
|
* `afterRead`, on a copy, so the row the write itself goes on with (its
|
|
@@ -276,8 +269,38 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
276
269
|
* compares against what the caller was served — an `ETag` is a hash of that.
|
|
277
270
|
*/
|
|
278
271
|
private asRestServes;
|
|
272
|
+
/**
|
|
273
|
+
* Apply `afterRead` to REST/SDK read results.
|
|
274
|
+
*
|
|
275
|
+
* The REST / `include` path fetches rows through the raw fetch service, which
|
|
276
|
+
* runs no hooks — so without this, `afterRead` (PII masking among them) is
|
|
277
|
+
* silently skipped on every SDK/REST read, leaking raw data. This choke
|
|
278
|
+
* point guarantees it runs there too, as on `fetchCollection`/`fetchOne`.
|
|
279
|
+
*
|
|
280
|
+
* It also masks embedded relation data, at every level the include loaded,
|
|
281
|
+
* by running each TARGET table's `afterRead` (so `comment.post.author.email`
|
|
282
|
+
* is masked by the authors table, not left raw).
|
|
283
|
+
*/
|
|
279
284
|
applyAfterReadForRest(rows: Record<string, unknown>[], path: string): Promise<Record<string, unknown>[]>;
|
|
280
|
-
|
|
285
|
+
/**
|
|
286
|
+
* The driver's one `afterRead` chain (see `afterReadOnRows`): global, the
|
|
287
|
+
* table's, its columns' transforms, then each embedded relation masked
|
|
288
|
+
* with the TARGET table's. Every read this driver serves goes through it.
|
|
289
|
+
*/
|
|
290
|
+
private applyAfterRead;
|
|
291
|
+
/**
|
|
292
|
+
* Rows of a table, as REST serves them: the one read walk
|
|
293
|
+
* (`fetchCollectionForRest`) — columns under their own names, a foreign
|
|
294
|
+
* key as a key, dates as RFC 3339, relations only when `include` names
|
|
295
|
+
* them, each as the target's own row — then the one `afterRead` chain.
|
|
296
|
+
*
|
|
297
|
+
* It used to be the admin panel's view-model walk: every date wrapped as
|
|
298
|
+
* `{ __type: "date" }`, every belongsTo turned into a relation ref, so the
|
|
299
|
+
* socket's one-shot read, MCP, plugins and a function's `requireDriver(c)`
|
|
300
|
+
* were handed a second row shape that no write door accepts back. The panel
|
|
301
|
+
* builds its view model in the browser, from this row and the descriptor.
|
|
302
|
+
*/
|
|
303
|
+
fetchCollection<M extends Record<string, unknown>>({ path, startAfter, include, ...query }: FetchCollectionProps<M>): Promise<Record<string, unknown>[]>;
|
|
281
304
|
/**
|
|
282
305
|
* Every stored row of a collection, past every read hook, for a whole-store
|
|
283
306
|
* sweep — see `DataDriver.scanStoredRows`. Only this unscoped driver has
|
|
@@ -286,9 +309,17 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
286
309
|
*/
|
|
287
310
|
scanStoredRows(props: {
|
|
288
311
|
path: string;
|
|
289
|
-
collection: CollectionConfig;
|
|
290
312
|
pageSize?: number;
|
|
291
313
|
}): AsyncIterable<Record<string, unknown>[]>;
|
|
314
|
+
/**
|
|
315
|
+
* Stored rows of a table, served as a read serves them — see
|
|
316
|
+
* {@link DataDriver.serveStoredRows}. The same two steps a REST read takes
|
|
317
|
+
* after the SELECT: the field strip (`stripUnreadable`, for the viewer the
|
|
318
|
+
* caller's transaction set — none on this unscoped driver, which is the
|
|
319
|
+
* trusted server plane), then the one `afterRead` chain. Each row is
|
|
320
|
+
* copied first: the caller's stored values are not rewritten.
|
|
321
|
+
*/
|
|
322
|
+
serveStoredRows(path: string, rows: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
|
|
292
323
|
/**
|
|
293
324
|
* Listen to a collection: the rows now, then again after every change.
|
|
294
325
|
*
|
|
@@ -298,8 +329,13 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
298
329
|
* request's transaction has one). With neither, the reads run as the
|
|
299
330
|
* anonymous user, as the refetches always did.
|
|
300
331
|
*/
|
|
301
|
-
listenCollection<M extends Record<string, unknown>>({ path,
|
|
302
|
-
|
|
332
|
+
listenCollection<M extends Record<string, unknown>>({ path, startAfter, onUpdate, onError, vectorSearch: _vectorSearch, page: _page, withDeleted: _withDeleted, ...query }: ListenCollectionProps<M>, authContext?: SubscriptionAuthContext | undefined): () => void;
|
|
333
|
+
/**
|
|
334
|
+
* One row, as REST's `GET /:id` serves it (`fetchOneForRest`, then
|
|
335
|
+
* `afterRead`): the relations `include` names and no others. It used to
|
|
336
|
+
* load every relation the table declares, eagerly, as relation refs.
|
|
337
|
+
*/
|
|
338
|
+
fetchOne<M extends Record<string, unknown>>({ path, id, databaseId, withDeleted, include }: FetchOneProps<M>): Promise<Record<string, unknown> | undefined>;
|
|
303
339
|
/**
|
|
304
340
|
* Listen to one row: the row now, then again after every change, and
|
|
305
341
|
* `null` when it is not there — deleted, never created, or not readable by
|
|
@@ -318,10 +354,10 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
318
354
|
*/
|
|
319
355
|
private static readonly TENANT_MEMBERSHIP_CAP;
|
|
320
356
|
/**
|
|
321
|
-
* Stamp, or refuse, the tenant on a write to a `tenant`-scoped
|
|
357
|
+
* Stamp, or refuse, the tenant on a write to a `tenant`-scoped table.
|
|
322
358
|
*
|
|
323
|
-
* A no-op for every
|
|
324
|
-
*
|
|
359
|
+
* A no-op for every table that declares no tenancy, which is the common
|
|
360
|
+
* case and costs one descriptor read.
|
|
325
361
|
*/
|
|
326
362
|
private applyTenantScope;
|
|
327
363
|
/**
|
|
@@ -337,7 +373,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
337
373
|
* collection's RLS applies to it — exactly as it does inside the generated
|
|
338
374
|
* policy's subquery. That is deliberate: if the two disagreed, the API
|
|
339
375
|
* would refuse writes the database would have accepted, or accept writes it
|
|
340
|
-
* refuses.
|
|
376
|
+
* refuses. The membership table's own rules are what make sure the membership
|
|
341
377
|
* collection is readable by its own members in the first place.
|
|
342
378
|
*/
|
|
343
379
|
private resolveCallerTenants;
|
|
@@ -396,11 +432,13 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
396
432
|
*/
|
|
397
433
|
private assertWritable;
|
|
398
434
|
/**
|
|
399
|
-
* The stamps a write takes after its hooks:
|
|
400
|
-
*
|
|
401
|
-
*
|
|
435
|
+
* The stamps a write takes after its hooks: the time and the acting user
|
|
436
|
+
* (`.onCreateNow()`, `.onUpdateNow()`, `.onCreateUser()`,
|
|
437
|
+
* `.onUpdateUser()`, on columns and inside JSON documents), and on an
|
|
438
|
+
* update the create-time stamp columns dropped, which record who made the
|
|
439
|
+
* row and when — facts no later write can change.
|
|
402
440
|
*/
|
|
403
|
-
private
|
|
441
|
+
private stampWrite;
|
|
404
442
|
/**
|
|
405
443
|
* What the caller reads of a row it just wrote: the stored row through the
|
|
406
444
|
* `afterRead` hooks, on a copy, so a hook that edits its argument in place
|
|
@@ -409,7 +447,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
409
447
|
*/
|
|
410
448
|
private viewOfSavedRow;
|
|
411
449
|
/**
|
|
412
|
-
* Whether a write to `
|
|
450
|
+
* Whether a write to `table` has to read the stored row before it
|
|
413
451
|
* writes: for the hooks and history that are handed it, the tenancy and
|
|
414
452
|
* per-field rules that judge it, a `beforeQuery` that scopes which rows
|
|
415
453
|
* the caller addresses, the trash an update must not reach, and a nested
|
|
@@ -474,7 +512,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
474
512
|
* the transaction the rows came from.
|
|
475
513
|
*/
|
|
476
514
|
callContextWithin(tx: DrizzleClient, user: User): RebaseCallContext;
|
|
477
|
-
saveMany<M extends Record<string, unknown>>({ path, rows,
|
|
515
|
+
saveMany<M extends Record<string, unknown>>({ path, rows, upsert, onConflict, conflictWhere, ignoreDuplicates }: SaveManyProps<M>): Promise<Record<string, unknown>[]>;
|
|
478
516
|
/**
|
|
479
517
|
* Whether {@link saveMany} may write a collection's rows together
|
|
480
518
|
* ({@link saveRowsTogether}): no `beforeSave`, `afterSave` or
|
|
@@ -486,7 +524,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
486
524
|
/**
|
|
487
525
|
* {@link saveMany}'s rows written together, a few multi-row statements in
|
|
488
526
|
* place of one statement per row (`PersistService.saveRows`), and answered
|
|
489
|
-
* as {@link save} answers each: defaults and
|
|
527
|
+
* as {@link save} answers each: defaults and stamps applied,
|
|
490
528
|
* the stored row through `afterRead`, a realtime event per row.
|
|
491
529
|
*
|
|
492
530
|
* For a collection {@link writesRowsTogether} allows; `undefined`, before
|
|
@@ -496,7 +534,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
496
534
|
private saveRowsTogether;
|
|
497
535
|
/**
|
|
498
536
|
* {@link updateMany}'s updates written together (`PersistService.updateRows`)
|
|
499
|
-
* and answered as {@link save} answers each: the
|
|
537
|
+
* and answered as {@link save} answers each: the update stamps
|
|
500
538
|
* applied, the stored row through `afterRead`, a realtime event per row.
|
|
501
539
|
* For a collection {@link writesRowsTogether} allows; `undefined`, before
|
|
502
540
|
* anything is written, for updates `updateRows` declines.
|
|
@@ -523,7 +561,7 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
523
561
|
* update is the outcome with no good recovery: the caller cannot tell which
|
|
524
562
|
* half landed without re-reading everything.
|
|
525
563
|
*/
|
|
526
|
-
updateMany<M extends Record<string, unknown>>({ path, updates
|
|
564
|
+
updateMany<M extends Record<string, unknown>>({ path, updates }: UpdateManyProps<M>): Promise<Record<string, unknown>[]>;
|
|
527
565
|
/**
|
|
528
566
|
* Delete many rows in one transaction, running the full delete pipeline —
|
|
529
567
|
* `beforeDelete`, the delete, `afterDelete` — for each.
|
|
@@ -535,28 +573,28 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
535
573
|
* dependents would behave differently depending on how many rows the caller
|
|
536
574
|
* happened to delete at once. Same pipeline, one transaction.
|
|
537
575
|
*/
|
|
538
|
-
deleteMany<M extends Record<string, unknown>>({ path, ids,
|
|
576
|
+
deleteMany<M extends Record<string, unknown>>({ path, ids, hard }: DeleteManyProps<M>): Promise<void>;
|
|
539
577
|
/**
|
|
540
578
|
* Update every row a filter matches. One statement (`PersistService.updateWhere`)
|
|
541
579
|
* when nothing needs the rows one by one; otherwise the rows the caller
|
|
542
580
|
* reads through the filter, updated by {@link updateMany} through the full
|
|
543
581
|
* pipeline, in one transaction. A filter matching nothing answers `[]`.
|
|
544
582
|
*/
|
|
545
|
-
updateWhere<M extends Record<string, unknown>>({ path, filter, logical, values
|
|
583
|
+
updateWhere<M extends Record<string, unknown>>({ path, filter, logical, values }: UpdateWhereProps<M>): Promise<Record<string, unknown>[]>;
|
|
546
584
|
/**
|
|
547
585
|
* Delete every row a filter matches, under the rules of {@link updateWhere}:
|
|
548
586
|
* one `DELETE` when nothing needs the rows one by one, else
|
|
549
587
|
* {@link deleteMany} over the rows the caller reads through the filter.
|
|
550
588
|
* Answers how many rows went.
|
|
551
589
|
*/
|
|
552
|
-
deleteWhere<M extends Record<string, unknown>>({ path, filter, logical,
|
|
590
|
+
deleteWhere<M extends Record<string, unknown>>({ path, filter, logical, hard }: DeleteWhereProps<M>): Promise<number>;
|
|
553
591
|
/**
|
|
554
592
|
* A row's address in the spelling a read derives it in — `010` is row
|
|
555
593
|
* `10` — for an event about a row this write did not read.
|
|
556
594
|
*/
|
|
557
595
|
private canonicalAddress;
|
|
558
596
|
/**
|
|
559
|
-
* The
|
|
597
|
+
* The table a filtered write addresses, refused when it cannot be
|
|
560
598
|
* one: a path through a relation (a filter there would reach rows the
|
|
561
599
|
* path does not), or a filter with no condition (every row).
|
|
562
600
|
*/
|
|
@@ -611,8 +649,8 @@ export declare class PostgresBackendDriver implements DataDriver {
|
|
|
611
649
|
}): Promise<void>;
|
|
612
650
|
deleteAll(path: string): Promise<void>;
|
|
613
651
|
updateRelationPivot({ path, targetId, pivot }: UpdateRelationPivotProps): Promise<void>;
|
|
614
|
-
checkUniqueField(path: string, name: string, value: unknown, id?: string
|
|
615
|
-
count<M extends Record<string, unknown>>({ path,
|
|
652
|
+
checkUniqueField(path: string, name: string, value: unknown, id?: string): Promise<boolean>;
|
|
653
|
+
count<M extends Record<string, unknown>>({ path, filter, logical, searchString, vectorSearch, withDeleted }: FetchCollectionProps<M>): Promise<number>;
|
|
616
654
|
/** The answer to {@link appDatabaseName}, once it has been given. */
|
|
617
655
|
private appDatabase?;
|
|
618
656
|
/**
|
|
@@ -773,6 +811,13 @@ export declare class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
773
811
|
*/
|
|
774
812
|
admin: DatabaseAdmin;
|
|
775
813
|
get restFetchService(): RestFetchService;
|
|
814
|
+
/**
|
|
815
|
+
* Stored rows of a table, served to this caller as a read serves them — see
|
|
816
|
+
* {@link DataDriver.serveStoredRows}. In this caller's read-only
|
|
817
|
+
* transaction, as every read here is: that is what sets the field viewer
|
|
818
|
+
* the strip reads, and the identity `afterRead` is told about.
|
|
819
|
+
*/
|
|
820
|
+
serveStoredRows(path: string, rows: Record<string, unknown>[]): Promise<Record<string, unknown>[]>;
|
|
776
821
|
/**
|
|
777
822
|
* Several reads in one read-only transaction — see
|
|
778
823
|
* {@link DataDriver.readTogether}. The same transaction every read on this
|
|
@@ -874,6 +919,6 @@ export declare class AuthenticatedPostgresBackendDriver implements DataDriver {
|
|
|
874
919
|
concurrently?: boolean;
|
|
875
920
|
}): Promise<void>;
|
|
876
921
|
updateRelationPivot(props: UpdateRelationPivotProps): Promise<void>;
|
|
877
|
-
checkUniqueField(path: string, name: string, value: unknown, id?: string
|
|
922
|
+
checkUniqueField(path: string, name: string, value: unknown, id?: string): Promise<boolean>;
|
|
878
923
|
count<M extends Record<string, unknown>>(props: FetchCollectionProps<M>): Promise<number>;
|
|
879
924
|
}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Implements the `BackendBootstrapper` interface for PostgreSQL.
|
|
5
5
|
*/
|
|
6
6
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
7
|
-
import { BackendBootstrapper,
|
|
7
|
+
import { BackendBootstrapper, InitializedDriver, type DatabaseAdapterInitConfig, type RealtimeChannelsConfig } from "@rebasepro/types";
|
|
8
8
|
import { PostgresBackendDriver } from "./PostgresBackendDriver.js";
|
|
9
9
|
import { RealtimeService } from "./services/realtimeService.js";
|
|
10
10
|
import { DatabasePoolManager } from "./databasePoolManager.js";
|
|
11
|
-
import {
|
|
11
|
+
import { PostgresTableRegistry } from "./model/PostgresTableRegistry.js";
|
|
12
12
|
import { type ManagedTable } from "./security/rls-enforcement.js";
|
|
13
13
|
import { type PostgresRlsConfig, type RlsSettings } from "./security/rls-settings.js";
|
|
14
14
|
import { type CdcTableRef } from "./services/cdc/trigger-cdc.js";
|
|
@@ -123,7 +123,7 @@ export interface PostgresDriverConfig {
|
|
|
123
123
|
export interface PostgresDriverInternals {
|
|
124
124
|
db: NodePgDatabase<any>;
|
|
125
125
|
readDb?: NodePgDatabase<any>;
|
|
126
|
-
registry:
|
|
126
|
+
registry: PostgresTableRegistry;
|
|
127
127
|
realtimeService: RealtimeService;
|
|
128
128
|
driver: PostgresBackendDriver;
|
|
129
129
|
poolManager?: DatabasePoolManager;
|
|
@@ -179,31 +179,16 @@ export interface PostgresDriverInternals {
|
|
|
179
179
|
* server's boot refuses on any; a script's `openRebase` only warns.
|
|
180
180
|
*/
|
|
181
181
|
exposedInternalTables?: string[];
|
|
182
|
+
/**
|
|
183
|
+
* Withhold every declared table of this source the database does not
|
|
184
|
+
* protect — RLS off, RLS on without any of its declared policies, or
|
|
185
|
+
* without a restrictive one it declares (see
|
|
186
|
+
* `security/served-table-protection`). A catalogue read; no DDL. The boot
|
|
187
|
+
* runs it once the policies step is over (`finalizeSecurityPosture`),
|
|
188
|
+
* whether this process provisioned or not.
|
|
189
|
+
*/
|
|
190
|
+
withholdUnprotectedTables?: () => Promise<void>;
|
|
182
191
|
}
|
|
183
|
-
/**
|
|
184
|
-
* Which table name the boot-time drift check should look for, for one collection.
|
|
185
|
-
*
|
|
186
|
-
* A declared `table` IS the table name, not a hint to be second-guessed. This
|
|
187
|
-
* used to ask the registry whether it had indexed the declared name and fall
|
|
188
|
-
* back to the SLUG when it had not — but "the registry does not know this table"
|
|
189
|
-
* is exactly the condition the drift check exists to report, so the fallback
|
|
190
|
-
* fired precisely when it was most harmful.
|
|
191
|
-
*
|
|
192
|
-
* A collection with `slug: "usage-daily", table: "usage_daily"` was reported as
|
|
193
|
-
* missing table `usage-daily`: a name that does not exist, should never exist,
|
|
194
|
-
* and that nobody can find by looking. Worse, the remediation the caller prints
|
|
195
|
-
* says to run `rebase db push` — which would then CREATE that invented table
|
|
196
|
-
* beside the correct one, the same "second copy" hazard the misplaced-schema
|
|
197
|
-
* branch further down exists to prevent. Seen in production, where a correctly
|
|
198
|
-
* migrated database reported drift on every boot.
|
|
199
|
-
*
|
|
200
|
-
* The slug is used only when nothing was declared, which is the config shape
|
|
201
|
-
* where the slug genuinely is the table name.
|
|
202
|
-
*
|
|
203
|
-
* Exported for its own test: the caller needs a live pool and a real database,
|
|
204
|
-
* and this is the part that was wrong.
|
|
205
|
-
*/
|
|
206
|
-
export declare function resolveDriftCheckName(col: CollectionConfig, registeredTableNames: string[]): string;
|
|
207
192
|
/**
|
|
208
193
|
* The relations the boot's drift check looks for a collection's table among.
|
|
209
194
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
2
2
|
import type { PgSqlDatabase } from "../interfaces.js";
|
|
3
3
|
/**
|
|
4
4
|
* One statement that drops each named index — but only one that covers a
|
|
@@ -12,11 +12,22 @@ import type { PgSqlDatabase } from "../interfaces.js";
|
|
|
12
12
|
* (`lock_timeout`, transaction-local to this statement — see `boot-ddl`).
|
|
13
13
|
*/
|
|
14
14
|
export declare function dropDuplicateTokenHashIndexesSql(schema: string, names: readonly string[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* The SQL type every auth table's `uid` foreign key is declared with, from the
|
|
17
|
+
* users table's key column: `UUID` for a uuid key, `INTEGER` for the integer
|
|
18
|
+
* family (serials and identities included), `TEXT` for anything else.
|
|
19
|
+
*
|
|
20
|
+
* Read from the key column's type. It used to be read from `isId` on a
|
|
21
|
+
* property named `id` — `"uuid"` or `"increment"` — so a key declared any
|
|
22
|
+
* other way (an integer the caller gives, a key not named `id`) was typed
|
|
23
|
+
* `TEXT` and every `uid` foreign key with it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function authUidSqlType(table: TableDescriptor | undefined): "UUID" | "INTEGER" | "TEXT";
|
|
15
26
|
/**
|
|
16
27
|
* Auto-create auth tables if they don't exist.
|
|
17
28
|
*
|
|
18
|
-
* @param db
|
|
19
|
-
* @param
|
|
20
|
-
*
|
|
29
|
+
* @param db — Drizzle database instance
|
|
30
|
+
* @param table — The descriptor of the table defined with `defineAuthTable`.
|
|
31
|
+
* When omitted, a default `rebase.users` table is created.
|
|
21
32
|
*/
|
|
22
|
-
export declare function ensureAuthTablesExist(db: PgSqlDatabase,
|
|
33
|
+
export declare function ensureAuthTablesExist(db: PgSqlDatabase, table?: TableDescriptor): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
2
2
|
import type { PgSqlDatabase } from "../interfaces.js";
|
|
3
3
|
/**
|
|
4
4
|
* The auth schema version this runtime expects to find in the database.
|
|
@@ -51,7 +51,7 @@ export declare class AuthSchemaVersionError extends Error {
|
|
|
51
51
|
* derives it. Shared so the two cannot drift: a stamp written to one schema and
|
|
52
52
|
* read from another would read as "never stamped" forever.
|
|
53
53
|
*/
|
|
54
|
-
export declare function resolveAuthSchema(
|
|
54
|
+
export declare function resolveAuthSchema(table?: TableDescriptor): string;
|
|
55
55
|
/**
|
|
56
56
|
* Read the stamped version, or `null` when the database has never been stamped.
|
|
57
57
|
*
|
package/dist/auth/services.d.ts
CHANGED
|
@@ -22,9 +22,8 @@ export interface AuthSchemaTables {
|
|
|
22
22
|
* Whitespace goes too: a trailing space survives the fold and reproduces the
|
|
23
23
|
* problem exactly.
|
|
24
24
|
*
|
|
25
|
-
* Re-exported rather than defined here: `@rebasepro/server`
|
|
26
|
-
*
|
|
27
|
-
* rule is the defect it exists to prevent.
|
|
25
|
+
* Re-exported rather than defined here: `@rebasepro/server` writes this column
|
|
26
|
+
* too, and a second copy of this rule is the defect it exists to prevent.
|
|
28
27
|
*/
|
|
29
28
|
import { normalizeEmail } from "@rebasepro/common";
|
|
30
29
|
import type { PgSqlDatabase } from "../interfaces.js";
|
|
@@ -112,21 +112,7 @@ function authUsersColumnDefinition(column) {
|
|
|
112
112
|
const spec = BY_COLUMN.get(column);
|
|
113
113
|
return spec ? authUsersColumnSql(spec) : void 0;
|
|
114
114
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Whether a collection is an auth collection, i.e. whether the definitions in
|
|
117
|
-
* this module apply to its table at all.
|
|
118
|
-
*
|
|
119
|
-
* Duplicated in shape from `@rebasepro/common`'s policy defaults on purpose:
|
|
120
|
-
* that one takes a `CollectionConfig`, this one is called from DDL code paths
|
|
121
|
-
* that hold looser objects, and both spellings must accept `auth: true` as well
|
|
122
|
-
* as `auth: { enabled: true }`.
|
|
123
|
-
*/
|
|
124
|
-
function isAuthCollection(collection) {
|
|
125
|
-
const auth = collection?.auth;
|
|
126
|
-
if (auth === true) return true;
|
|
127
|
-
return typeof auth === "object" && auth !== null && auth.enabled === true;
|
|
128
|
-
}
|
|
129
115
|
//#endregion
|
|
130
|
-
export {
|
|
116
|
+
export { authUsersColumnDefinition as n, authUsersColumnSql as r, AUTH_USERS_COLUMNS as t };
|
|
131
117
|
|
|
132
|
-
//# sourceMappingURL=auth-users-columns-
|
|
118
|
+
//# sourceMappingURL=auth-users-columns-BpfgbkxZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-users-columns-BpfgbkxZ.js","names":[],"sources":["../src/schema/auth-users-columns.ts"],"sourcesContent":["/**\n * The one description of what an auth user table's columns must be.\n *\n * ## Why this exists\n *\n * Three different code paths create `rebase.users`, and before this module they\n * disagreed about it:\n *\n * | column | `db push` (generator) | `ensureAuthTablesExist` | `ensureTables` |\n * |------------------|-----------------------|-------------------------|--------------------------|\n * | `email` | `TEXT UNIQUE NOT NULL`| `TEXT NOT NULL` + CHECK | `TEXT` (nullable) |\n * | `roles` | `TEXT[]` | `NOT NULL DEFAULT '{}'` | nullable, no default |\n * | `email_verified` | `BOOLEAN` | `NOT NULL DEFAULT FALSE`| nullable |\n * | `created_at` | `DEFAULT now()` | `NOT NULL DEFAULT NOW()`| no default |\n *\n * They are all `CREATE TABLE IF NOT EXISTS` / `ADD COLUMN IF NOT EXISTS`, so\n * whichever ran first decided the table and the other two silently no-op'd.\n * Boot order therefore chose the constraints: a managed deploy (collection\n * tables first) got a users table whose `email` was nullable and whose\n * `email_verified` had no default, while the same project pushed from a\n * checkout got the strict one. In the same table, `is_anonymous` came out\n * `NOT NULL DEFAULT false` — because *that* column existed in only one of the\n * three lists, so its owner's definition won by default.\n *\n * A second consequence was drift in the other direction. The scaffold's\n * `users.ts` describes 12 columns; auth needs 14. `db push` is declarative and\n * builds its desired state from the collection alone, so the two columns only\n * auth knows about (`is_anonymous`, `tokens_valid_after`) read as unmanaged\n * drift, and a push run after the server had booted once planned to DROP them.\n *\n * Both problems are the same problem: no single place said what this table is.\n * This is that place. Every creator asks here first and only then falls back to\n * the collection's own property definitions, so a column auth owns has one\n * definition regardless of who gets there first, and a column the developer\n * added to their users collection still behaves like any other field.\n *\n * ## What belongs here\n *\n * Only columns the auth services read or write. A developer's own additions to\n * their users collection (`bio`, `stripe_customer_id`) are ordinary columns and\n * must NOT be listed — they are generated from the collection like every other\n * field, and listing them here would freeze a user's schema.\n *\n * `id` is deliberately absent: its type comes from the collection's id property\n * (uuid / increment / text) and each creator already derives it.\n *\n * Keep in step with {@link AUTH_SCHEMA_VERSION} when a change here makes an\n * older runtime unable to work against a migrated table.\n */\n\n/**\n * A column auth owns.\n *\n * Structured rather than one SQL string because the same facts are needed in\n * three grammars — a `CREATE TABLE` column list, an `ADD COLUMN IF NOT EXISTS`,\n * and a pair of `ALTER COLUMN … SET DEFAULT` / `SET NOT NULL` reconciles for a\n * table that already exists with the wrong shape. Parsing a string back apart\n * for the third of those is how the copies drifted in the first place.\n */\nexport interface AuthUsersColumn {\n /** Physical column name. */\n column: string;\n /** Postgres type. */\n type: string;\n /** Default expression, verbatim, or absent for no default. */\n default?: string;\n /** Whether the column is NOT NULL. */\n notNull?: boolean;\n}\n\n/**\n * `email` is NOT NULL on purpose, and the anonymous sign-in route depends on it\n * — it synthesizes `anon_<32 hex>@anonymous.local` rather than inserting NULL.\n * The 320-char bound (RFC 5321) is a CHECK rather than a `VARCHAR(n)`, added\n * separately by `ensureAuthTablesExist` so it can be `NOT VALID` on an adopted\n * table that already holds a longer row.\n */\nexport const AUTH_USERS_COLUMNS: readonly AuthUsersColumn[] = [\n { column: \"email\", type: \"TEXT\", notNull: true },\n { column: \"display_name\", type: \"TEXT\" },\n { column: \"photo_url\", type: \"TEXT\" },\n { column: \"roles\", type: \"TEXT[]\", default: \"'{}'\", notNull: true },\n { column: \"password_hash\", type: \"TEXT\" },\n { column: \"email_verified\", type: \"BOOLEAN\", default: \"FALSE\", notNull: true },\n { column: \"email_verification_token\", type: \"TEXT\" },\n { column: \"email_verification_sent_at\", type: \"TIMESTAMP WITH TIME ZONE\" },\n { column: \"is_anonymous\", type: \"BOOLEAN\", default: \"FALSE\", notNull: true },\n { column: \"metadata\", type: \"JSONB\", default: \"'{}'\", notNull: true },\n { column: \"tokens_valid_after\", type: \"TIMESTAMP WITH TIME ZONE\" },\n // When an administrator switched the account off; NULL while it is on.\n { column: \"disabled_at\", type: \"TIMESTAMP WITH TIME ZONE\" },\n // A self-service address change waiting for its link: the address, the\n // hash of the token mailed to it, and when (it lives 24 hours).\n { column: \"pending_email\", type: \"TEXT\" },\n { column: \"email_change_token\", type: \"TEXT\" },\n { column: \"email_change_sent_at\", type: \"TIMESTAMP WITH TIME ZONE\" },\n { column: \"created_at\", type: \"TIMESTAMP WITH TIME ZONE\", default: \"NOW()\", notNull: true },\n { column: \"updated_at\", type: \"TIMESTAMP WITH TIME ZONE\", default: \"NOW()\", notNull: true }\n];\n\nconst BY_COLUMN = new Map(AUTH_USERS_COLUMNS.map(c => [c.column, c]));\n\n/** Type + inline constraints, as they appear after the column name. */\nexport function authUsersColumnSql(spec: AuthUsersColumn): string {\n return [\n spec.type,\n spec.default !== undefined ? `DEFAULT ${spec.default}` : \"\",\n spec.notNull ? \"NOT NULL\" : \"\"\n ].filter(Boolean).join(\" \");\n}\n\n/**\n * The auth-owned definition for a physical column name, or `undefined` when\n * auth does not own it.\n *\n * Callers pass the RESOLVED column name (after `columnName` mapping), because\n * that is the only name the three creators agree on: the scaffold's users\n * collection spells the property `displayName` and the column `display_name`.\n */\nexport function authUsersColumnDefinition(column: string): string | undefined {\n const spec = BY_COLUMN.get(column);\n return spec ? authUsersColumnSql(spec) : undefined;\n}\n"],"mappings":";;;;;;;;;;AA6EA,IAAa,qBAAiD;CAC1D;EAAE,QAAQ;EAAS,MAAM;EAAQ,SAAS;CAAK;CAC/C;EAAE,QAAQ;EAAgB,MAAM;CAAO;CACvC;EAAE,QAAQ;EAAa,MAAM;CAAO;CACpC;EAAE,QAAQ;EAAS,MAAM;EAAU,SAAS;EAAQ,SAAS;CAAK;CAClE;EAAE,QAAQ;EAAiB,MAAM;CAAO;CACxC;EAAE,QAAQ;EAAkB,MAAM;EAAW,SAAS;EAAS,SAAS;CAAK;CAC7E;EAAE,QAAQ;EAA4B,MAAM;CAAO;CACnD;EAAE,QAAQ;EAA8B,MAAM;CAA2B;CACzE;EAAE,QAAQ;EAAgB,MAAM;EAAW,SAAS;EAAS,SAAS;CAAK;CAC3E;EAAE,QAAQ;EAAY,MAAM;EAAS,SAAS;EAAQ,SAAS;CAAK;CACpE;EAAE,QAAQ;EAAsB,MAAM;CAA2B;CAEjE;EAAE,QAAQ;EAAe,MAAM;CAA2B;CAG1D;EAAE,QAAQ;EAAiB,MAAM;CAAO;CACxC;EAAE,QAAQ;EAAsB,MAAM;CAAO;CAC7C;EAAE,QAAQ;EAAwB,MAAM;CAA2B;CACnE;EAAE,QAAQ;EAAc,MAAM;EAA4B,SAAS;EAAS,SAAS;CAAK;CAC1F;EAAE,QAAQ;EAAc,MAAM;EAA4B,SAAS;EAAS,SAAS;CAAK;AAC9F;AAEA,IAAM,YAAY,IAAI,IAAI,mBAAmB,KAAI,MAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;;AAGpE,SAAgB,mBAAmB,MAA+B;CAC9D,OAAO;EACH,KAAK;EACL,KAAK,YAAY,KAAA,IAAY,WAAW,KAAK,YAAY;EACzD,KAAK,UAAU,aAAa;CAChC,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AAC9B;;;;;;;;;AAUA,SAAgB,0BAA0B,QAAoC;CAC1E,MAAM,OAAO,UAAU,IAAI,MAAM;CACjC,OAAO,OAAO,mBAAmB,IAAI,IAAI,KAAA;AAC7C"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "module";
|
|
2
2
|
__createRequire(import.meta.url);
|
|
3
3
|
import { i as __exportAll, t as promptConfirm } from "./cli-prompt-DXG0yk-h.js";
|
|
4
|
-
import {
|
|
5
|
-
import { a as outWarn, i as outError, r as out, t as chalk } from "./source-
|
|
6
|
-
import { S as execa, _ as closestWord,
|
|
4
|
+
import { W as resolveLocalBin, at as forLibpq, i as checkDatabaseConnectivity, ot as redactConnectionPasswords, st as splitPassword } from "./cli-schema-dir-CiN0ephV.js";
|
|
5
|
+
import { a as outWarn, i as outError, r as out, t as chalk } from "./source-VxbrQojV.js";
|
|
6
|
+
import { S as execa, _ as closestWord, v as parseCommandFlags } from "./migrate-baseline-DZmekgpD.js";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import fs from "fs";
|
|
9
9
|
import os from "os";
|
|
@@ -2006,4 +2006,4 @@ ${chalk.green.bold("Usage")}
|
|
|
2006
2006
|
//#endregion
|
|
2007
2007
|
export { buildBackupFilename as A, diagnoseRowSecurityDumpFailure as B, restoreDumpReplacing as C, resolvePgBinary as D, pgToolVariable as E, buildPgRestoreScriptArgs as F, parseBackupTimestamp as G, isBackupOfDatabase as H, buildPsqlScriptArgs as I, parsePgToolMajor as J, parseDbNameFromUrl as K, buildRowSecurityPgOptions as L, buildPgDumpallGlobalsArgs as M, buildPgRestoreArgs as N, selectBackupsToPrune as O, buildPgRestoreListArgs as P, withDatabaseName as Q, checkToolServerCompatibility as R, restoreDump as S, validateDump as T, joinStorageKey as U, globalsFileForDump as V, parseBackupDestination as W, serverVersionNumToMajor as X, resolveConnectionString as Y, splitGlobalsStatements as Z, listBackups as _, BackupToolError as a, readDumpObjects as b, backup_service_exports as c, detectToolMajor as d, discardPartialDump as f, getServerVersionMajor as g, findRestoreConflicts as h, parseRestoreLine as i, buildPgDumpArgs as j, CLEAN_LOCK_TIMEOUT as k, createDump as l, findCleanExtras as m, parseBackupLine as n, CleanRestoreFailed as o, ensureDatabaseExists as p, parseDumpObjects as q, parseBackupsListLine as r, applyGlobals as s, backup_cli_exports as t, describeUnreadableDump as u, preflight as v, uploadBackup as w, resetSharedSession as x, pruneBackups as y, cleanRestorePrelude as z };
|
|
2008
2008
|
|
|
2009
|
-
//# sourceMappingURL=backup-cli-
|
|
2009
|
+
//# sourceMappingURL=backup-cli-DbKyEj6c.js.map
|