@rebasepro/server-postgres 0.30.0 → 0.31.0-canary.g902a0ce
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `beforeQuery`: the one place a
|
|
3
|
-
*
|
|
2
|
+
* `beforeQuery`: the one place a table hook can change *which* rows a read
|
|
3
|
+
* asks for.
|
|
4
4
|
*
|
|
5
5
|
* `afterRead` runs over rows that have already been fetched, so until this
|
|
6
6
|
* existed an application developer who needed the read itself narrowed — a
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
*/
|
|
50
50
|
import { SQL } from "drizzle-orm";
|
|
51
51
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
52
|
-
import type {
|
|
53
|
-
import type {
|
|
52
|
+
import type { ReadOperation, ReadQuery, RebaseCallContext } from "@rebasepro/types";
|
|
53
|
+
import type { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
54
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
54
55
|
import { type FilterCompilationOptions } from "../utils/drizzle-conditions.js";
|
|
55
56
|
/**
|
|
56
57
|
* How a read path reaches the context its `beforeQuery` hooks run with.
|
|
@@ -61,8 +62,8 @@ import { type FilterCompilationOptions } from "../utils/drizzle-conditions.js";
|
|
|
61
62
|
* object that a collection with no hooks should never pay for.
|
|
62
63
|
*/
|
|
63
64
|
export type ReadCallContextProvider = () => RebaseCallContext;
|
|
64
|
-
/** Whether anything at all would run for this
|
|
65
|
-
export declare function hasBeforeQuery(registry:
|
|
65
|
+
/** Whether anything at all would run for this table. */
|
|
66
|
+
export declare function hasBeforeQuery(registry: PostgresTableRegistry | undefined, table: RuntimeTable | undefined): boolean;
|
|
66
67
|
/**
|
|
67
68
|
* What a read path is about to compile, in the form a hook is shown it.
|
|
68
69
|
*
|
|
@@ -76,7 +77,7 @@ export interface ReadQueryDescription {
|
|
|
76
77
|
}
|
|
77
78
|
/** Everything `beforeQueryConditions` needs that is not about this one read. */
|
|
78
79
|
export interface BeforeQueryEnv {
|
|
79
|
-
registry:
|
|
80
|
+
registry: PostgresTableRegistry | undefined;
|
|
80
81
|
/**
|
|
81
82
|
* The context provider the driver handed down. `undefined` means no driver
|
|
82
83
|
* built this service, which is a refusal rather than a bypass — see the
|
|
@@ -92,9 +93,9 @@ export interface BeforeQueryEnv {
|
|
|
92
93
|
* that array, which is what makes these additive — the hook is not trusted to
|
|
93
94
|
* narrow, it is only ever given a way to.
|
|
94
95
|
*/
|
|
95
|
-
export declare function beforeQueryConditions(env: BeforeQueryEnv,
|
|
96
|
+
export declare function beforeQueryConditions(env: BeforeQueryEnv, runtime: RuntimeTable | undefined, path: string, table: PgTable<never>, description: ReadQueryDescription, filterContext: Omit<FilterCompilationOptions, "unknownFields">): Promise<SQL[]>;
|
|
96
97
|
/**
|
|
97
98
|
* {@link beforeQueryConditions}, pre-combined, for the read paths that hold a
|
|
98
99
|
* single `SQL` rather than a list of them — a single get, a relation loader.
|
|
99
100
|
*/
|
|
100
|
-
export declare function beforeQueryCondition(env: BeforeQueryEnv,
|
|
101
|
+
export declare function beforeQueryCondition(env: BeforeQueryEnv, runtime: RuntimeTable | undefined, path: string, table: PgTable<never>, description: ReadQueryDescription, filterContext: Omit<FilterCompilationOptions, "unknownFields">): Promise<SQL | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
2
|
import { DataDriver, IncludeSpec, WebSocketMessage, LogicalCondition, OrderByTuple } from "@rebasepro/types";
|
|
3
3
|
import { RealtimeProvider, CollectionSubscriptionConfig, SingleSubscriptionConfig, type PgSqlDatabase } from "../interfaces.js";
|
|
4
|
-
import {
|
|
4
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
5
5
|
import type { RequestIdentity } from "../security/rls-settings.js";
|
|
6
6
|
import type { CdcTableRef } from "./cdc/trigger-cdc.js";
|
|
7
7
|
import { ChannelBus } from "./channel-bus/index.js";
|
|
@@ -491,7 +491,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
491
491
|
private cdcTurnRows;
|
|
492
492
|
/** How many changed rows one turn of the event loop routes: ~5–10 ms of work. */
|
|
493
493
|
private static readonly CDC_ROWS_PER_TURN;
|
|
494
|
-
/** Reverse lookup: `schema.table` (and bare `table`) →
|
|
494
|
+
/** Reverse lookup: `schema.table` (and bare `table`) → served table, built when CDC starts. */
|
|
495
495
|
private cdcTableMap?;
|
|
496
496
|
/**
|
|
497
497
|
* Short-lived record of `path/id` keys this instance just fanned out via the
|
|
@@ -516,7 +516,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
516
516
|
* already arrived. An echo later than that costs one more refetch.
|
|
517
517
|
*/
|
|
518
518
|
private static readonly CDC_DEDUP_WINDOW_MS;
|
|
519
|
-
constructor(db: PgSqlDatabase<any>, registry:
|
|
519
|
+
constructor(db: PgSqlDatabase<any>, registry: PostgresTableRegistry);
|
|
520
520
|
/**
|
|
521
521
|
* Restricted role that auth-scoped refetches run as (via `SET LOCAL ROLE`)
|
|
522
522
|
* so RLS `select` policies bind. Set by the bootstrapper alongside
|
|
@@ -776,9 +776,9 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
776
776
|
* papered over ~300 ms later by the debounced refetch — after the bytes had
|
|
777
777
|
* already reached the browser.
|
|
778
778
|
*
|
|
779
|
-
* The same defect was found and fixed on
|
|
780
|
-
*
|
|
781
|
-
*
|
|
779
|
+
* The same defect was found and fixed on another driver in `065e2b615`;
|
|
780
|
+
* this is the Postgres half, stated as one rule rather than three patched
|
|
781
|
+
* branches.
|
|
782
782
|
*
|
|
783
783
|
* The cost is the instant row-level patch that used to precede the refetch:
|
|
784
784
|
* cross-tab feedback now waits for the debounce. That is the price of not
|
|
@@ -847,6 +847,15 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
847
847
|
* against the older body pass over a change it never saw.
|
|
848
848
|
*/
|
|
849
849
|
private fetchEntityFrame;
|
|
850
|
+
/**
|
|
851
|
+
* Refuse a frame the fallback (no driver) would serve past `afterRead`.
|
|
852
|
+
*
|
|
853
|
+
* The hooks run with a context only the driver can build, so without one
|
|
854
|
+
* they cannot run — and a frame that skips a masking `afterRead` hands out
|
|
855
|
+
* what every other read of the same rows withholds. Refused, naming the
|
|
856
|
+
* table, rather than served raw.
|
|
857
|
+
*/
|
|
858
|
+
private refuseReadHooksWithoutDriver;
|
|
850
859
|
/**
|
|
851
860
|
* Fetch a single row with optional RLS auth context.
|
|
852
861
|
*/
|
|
@@ -889,7 +898,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
889
898
|
* columns and no address. The SDK holds no collection config to derive one
|
|
890
899
|
* from, so this is the only place the mapping can come from.
|
|
891
900
|
*/
|
|
892
|
-
/** The key columns of the
|
|
901
|
+
/** The key columns of the table at `path`, if they can be resolved. */
|
|
893
902
|
private primaryKeysForPath;
|
|
894
903
|
/**
|
|
895
904
|
* `channel` addresses the error to the channel frame it is about.
|
|
@@ -1249,6 +1258,13 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1249
1258
|
* subscription's own scope, so this decides only who looks again.
|
|
1250
1259
|
*/
|
|
1251
1260
|
private resyncSubscriptions;
|
|
1261
|
+
/**
|
|
1262
|
+
* Read the served tables again into the maps a captured change is routed
|
|
1263
|
+
* by (table → served table, junction → the lists it links), after the
|
|
1264
|
+
* registry's tables changed (a live schema apply). Nothing to do while
|
|
1265
|
+
* change capture is off: the maps are built when it starts.
|
|
1266
|
+
*/
|
|
1267
|
+
refreshTableMaps(): void;
|
|
1252
1268
|
/** Stop the CDC listener and clear its state. */
|
|
1253
1269
|
stopCdc(): Promise<void>;
|
|
1254
1270
|
/**
|
|
@@ -1258,7 +1274,7 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
|
|
|
1258
1274
|
* works whether or not the collection declares an explicit schema.
|
|
1259
1275
|
*/
|
|
1260
1276
|
private buildCdcTableMap;
|
|
1261
|
-
private
|
|
1277
|
+
private resolveTableForChange;
|
|
1262
1278
|
/**
|
|
1263
1279
|
* Route a captured database change into the realtime pipeline.
|
|
1264
1280
|
*
|
|
@@ -1399,8 +1415,7 @@ export declare function packEntityChanges(sid: string, changes: Array<{
|
|
|
1399
1415
|
db: string | null;
|
|
1400
1416
|
}>): string[];
|
|
1401
1417
|
/**
|
|
1402
|
-
* Alias for RealtimeService
|
|
1403
|
-
* This allows code to use PostgresRealtimeProvider alongside future MongoRealtimeProvider, etc.
|
|
1418
|
+
* Alias for RealtimeService, named after the engine it serves.
|
|
1404
1419
|
*/
|
|
1405
1420
|
export declare const PostgresRealtimeProvider: typeof RealtimeService;
|
|
1406
1421
|
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
2
|
+
import type { OrderByTuple, RelationDescriptor } from "@rebasepro/types";
|
|
3
|
+
import { type PrimaryKeyInfo } from "@rebasepro/common";
|
|
4
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
5
|
+
import type { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
6
|
+
/**
|
|
7
|
+
* The relation half of the driver's table model: every question the relation
|
|
8
|
+
* services ask of a {@link RelationDescriptor} and the {@link RuntimeTable}s
|
|
9
|
+
* at its two ends, answered once.
|
|
10
|
+
*
|
|
11
|
+
* A relation names its target by slug (`relation.target`); the target's SQL
|
|
12
|
+
* table, key and columns are the target runtime table's. Nothing here reads a
|
|
13
|
+
* lowered collection.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/** A relation whose link is a column on the target pointing back here: `hasOne` / `hasMany`. */
|
|
18
|
+
export type PointsBackRelation = Extract<RelationDescriptor, {
|
|
19
|
+
kind: "hasOne" | "hasMany";
|
|
20
|
+
}>;
|
|
21
|
+
/** Whether the link is a column on the target that points back at this table. */
|
|
22
|
+
export declare function pointsBack(relation: RelationDescriptor): relation is PointsBackRelation;
|
|
23
|
+
/**
|
|
24
|
+
* The table a relation points at. Throws, naming the slug, when this driver
|
|
25
|
+
* does not serve it — boot refused such a relation already
|
|
26
|
+
* (`assertRelationsResolve`), so reaching one here is a wiring defect — and
|
|
27
|
+
* 503 `TABLE_WITHHELD` when it, or a table a `via` passes through on the way,
|
|
28
|
+
* is withheld.
|
|
29
|
+
*/
|
|
30
|
+
export declare function relationTarget(registry: PostgresTableRegistry, relation: RelationDescriptor): RuntimeTable;
|
|
31
|
+
/**
|
|
32
|
+
* The drizzle table this database holds for `table`: the catalogue table
|
|
33
|
+
* registered under its SQL name, else the runtime table's own. Throws, naming
|
|
34
|
+
* the slug and the table, when there is none.
|
|
35
|
+
*/
|
|
36
|
+
export declare function catalogueTableOf(registry: PostgresTableRegistry, table: RuntimeTable): PgTable;
|
|
37
|
+
/** The key columns of `table`, for a caller that cannot work without one (`requireTableKeys`). */
|
|
38
|
+
export declare function keysOfTable(registry: PostgresTableRegistry, table: RuntimeTable): PrimaryKeyInfo[];
|
|
39
|
+
/**
|
|
40
|
+
* The row key of the column whose SQL name is `sqlName` on `table` — what the
|
|
41
|
+
* catalogue drizzle table and every row it returns are keyed by.
|
|
42
|
+
*
|
|
43
|
+
* A relation states its links in SQL terms (`localKey`, `foreignKey`,
|
|
44
|
+
* `sourceKey`, `through.*`). A column the descriptor declares answers with
|
|
45
|
+
* its key; a name that already is a key answers with itself; anything else is
|
|
46
|
+
* the column's wire name (`toWireKey`), which is how the catalogue keys a
|
|
47
|
+
* column nobody declared.
|
|
48
|
+
*/
|
|
49
|
+
export declare function columnKeyOf(table: RuntimeTable | undefined, sqlName: string): string;
|
|
50
|
+
/** The catalogue column `pg` holds for the SQL column `sqlName` of `table`, or `undefined`. */
|
|
51
|
+
export declare function columnOfTable(pg: PgTable, table: RuntimeTable | undefined, sqlName: string): AnyPgColumn | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* The row key of the column on the *source* table that a `hasOne`/`hasMany`
|
|
54
|
+
* link points at: its `sourceKey`, else the source's (first) key column.
|
|
55
|
+
*
|
|
56
|
+
* The one reader of `sourceKey`'s absence, so no caller re-derives "or else
|
|
57
|
+
* the primary key" for itself.
|
|
58
|
+
*/
|
|
59
|
+
export declare function sourceKeyField(registry: PostgresTableRegistry, owner: RuntimeTable, relation: PointsBackRelation): string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether this link joins on something other than the source's key — a
|
|
62
|
+
* natural key (`sourceKey` naming another column). A caller holding a parent
|
|
63
|
+
* *id* must then translate it to the source key's value first.
|
|
64
|
+
*/
|
|
65
|
+
export declare function joinsOnNaturalKey(registry: PostgresTableRegistry, owner: RuntimeTable, relation: PointsBackRelation): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Whether a link can be written through the relation. Every kind but `via`
|
|
68
|
+
* is; a `via` is when it is a single hop joining on one condition
|
|
69
|
+
* (`writable`, decided by the compiler).
|
|
70
|
+
*/
|
|
71
|
+
export declare function relationWritable(relation: RelationDescriptor): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* A relation whose target rows are shared with other parents — a
|
|
74
|
+
* `manyToMany`, or any `via` chain — so writing "through" it addresses the
|
|
75
|
+
* link, not the row.
|
|
76
|
+
*/
|
|
77
|
+
export declare function isSharedRelation(relation: RelationDescriptor): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The relation `name` of `table`, or a **404 `UNKNOWN_RELATION`** naming the
|
|
80
|
+
* relations the caller may know of. `hidden` are names this caller must not
|
|
81
|
+
* learn (private relations, relations withheld from their roles): answered
|
|
82
|
+
* as undeclared, and never listed.
|
|
83
|
+
*/
|
|
84
|
+
export declare function requireRelation(table: RuntimeTable, name: string, hidden?: ReadonlySet<string>): RelationDescriptor;
|
|
85
|
+
/**
|
|
86
|
+
* The order a relation's rows come back in: the caller's, when it names one
|
|
87
|
+
* (an include's `orderBy`, a nested listing's `orderBy`), else the order the
|
|
88
|
+
* relation declares (`rel.hasMany(target, { orderBy })`), else none.
|
|
89
|
+
*
|
|
90
|
+
* The caller's order **replaces** the declared one rather than extending it:
|
|
91
|
+
* an include that says `orderBy: [["title", "asc"]]` gets exactly that, as a
|
|
92
|
+
* top-level read does. Whichever applies, the loaders end it with the
|
|
93
|
+
* target's key ascending, so rows that tie come back in a stable order, and a
|
|
94
|
+
* per-parent `limit` (and a nested listing's paging) keeps the first rows of
|
|
95
|
+
* that same order.
|
|
96
|
+
*/
|
|
97
|
+
export declare function relatedRowsOrder(relation: RelationDescriptor, callerOrder?: readonly OrderByTuple[]): OrderByTuple[] | undefined;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { type ColumnDescriptor } from "@rebasepro/types";
|
|
2
|
+
import { type RelatedTables } from "@rebasepro/common";
|
|
3
|
+
import type { RelationDescriptor, TableDescriptor } from "@rebasepro/types";
|
|
4
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
5
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
3
6
|
/**
|
|
4
|
-
* Turning a drizzle result into
|
|
7
|
+
* Turning a drizzle result into the row we serve — the ONE read shape.
|
|
5
8
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* REST, every socket frame, the in-process SDK and the driver's own read SPI
|
|
10
|
+
* serve this row: columns under their own names, a foreign key as a key,
|
|
11
|
+
* temporal columns as RFC 3339, numeric ones as numbers, and a relation only
|
|
12
|
+
* when an `include` names it, as the target's own row. The admin panel's view
|
|
13
|
+
* model (dates as `Date`, relations as `EntityRelation`) is built in the
|
|
14
|
+
* browser from this row and the table descriptor; nothing here produces a
|
|
15
|
+
* `{ __type: … }` envelope.
|
|
10
16
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `rebase.dataAsAdmin` / `context.data` serve too. A developer never sees a ref.
|
|
16
|
-
*
|
|
17
|
-
* They used to be two functions that happened to agree, and the agreement was
|
|
18
|
-
* not enforced by anything: the row-identity bug had to be fixed five times
|
|
19
|
-
* across differently-shaped copies of this walk, and one of the copies was
|
|
20
|
-
* dead code nobody had noticed. Whatever the next cross-cutting change is, it
|
|
21
|
-
* is one edit here.
|
|
17
|
+
* There used to be a second rendering here — a `{ __type: "relation" }` ref
|
|
18
|
+
* carrying the target's values, for the admin — and the two had to be kept in
|
|
19
|
+
* agreement by hand: the row-identity bug was fixed five times across copies of
|
|
20
|
+
* this walk. One rendering cannot disagree with itself.
|
|
22
21
|
*/
|
|
23
|
-
export type RelationStyle = "ref" | "inline";
|
|
24
22
|
/**
|
|
25
23
|
* Whether a many-relation reaches its target through a junction table.
|
|
26
24
|
*
|
|
@@ -28,21 +26,27 @@ export type RelationStyle = "ref" | "inline";
|
|
|
28
26
|
* the query has to nest one level deeper for a junction, and the row walk has
|
|
29
27
|
* to unwrap that same level back out.
|
|
30
28
|
*/
|
|
31
|
-
export declare function isJunctionRelation(relation:
|
|
32
|
-
/**
|
|
29
|
+
export declare function isJunctionRelation(relation: RelationDescriptor): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* One column value, as REST serves it: numeric columns as numbers, temporal
|
|
32
|
+
* ones as RFC 3339, a native array's items as a column of the item type,
|
|
33
|
+
* everything else — and a key the table does not declare — exactly as the
|
|
34
|
+
* database returned it.
|
|
35
|
+
*/
|
|
36
|
+
export declare function toRestScalar(value: unknown, column: ColumnDescriptor | undefined): unknown;
|
|
33
37
|
/**
|
|
34
|
-
* Drop every column this caller may not read.
|
|
38
|
+
* Drop every column this caller may not read, as the table's descriptor says.
|
|
35
39
|
*
|
|
36
40
|
* Password hashes and verification tokens have to be readable server-side but
|
|
37
41
|
* must never reach a client — and "never" has to mean every exit from this
|
|
38
42
|
* pipeline, including relation targets, or a secret leaks through whichever
|
|
39
|
-
* path was overlooked. Keyed by both the
|
|
40
|
-
*
|
|
43
|
+
* path was overlooked. Keyed by both the column key and its SQL name, since a
|
|
44
|
+
* row can arrive keyed either way depending on the caller.
|
|
41
45
|
*
|
|
42
|
-
* `
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
+
* `.private()` is the rule no caller satisfies (`read: []`), so it needs no
|
|
47
|
+
* branch of its own; `.access({ read: ["hr"] })` is the same question asked of
|
|
48
|
+
* {@link currentFieldViewer}. The names are common's `restrictedKeys`, the one
|
|
49
|
+
* answer every enforcement point reads.
|
|
46
50
|
*
|
|
47
51
|
* The field is **deleted**, never nulled. A withheld value that arrives as
|
|
48
52
|
* `null` is indistinguishable from a stored `null`, which turns a permission
|
|
@@ -50,63 +54,40 @@ export declare function isJunctionRelation(relation: ResolvedRelation): boolean;
|
|
|
50
54
|
* an `update` that echoes the row back overwrite the real value with the null it
|
|
51
55
|
* was handed.
|
|
52
56
|
*
|
|
53
|
-
* A withheld
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* nothing.
|
|
57
|
+
* A withheld relation (`rel.*(…, { access })`, `{ private: true }`) is withheld
|
|
58
|
+
* whole, and a withheld `belongsTo` takes its foreign key with it: `bandId: 7`
|
|
59
|
+
* names the salary band exactly as `band: { id: 7 }` does.
|
|
57
60
|
*
|
|
58
61
|
* `_matches` is filtered rather than deleted: it is the list of fields a text
|
|
59
62
|
* search hit, and a field the caller cannot read must not appear in it even
|
|
60
63
|
* though the array itself is theirs to see.
|
|
61
64
|
*/
|
|
62
|
-
export declare function stripUnreadable(row: Record<string, unknown>,
|
|
63
|
-
/**
|
|
64
|
-
* May the current caller be handed the rows of this relation of `collection`?
|
|
65
|
-
*
|
|
66
|
-
* A relation property's value *is* its related rows, so a property the caller
|
|
67
|
-
* may not read withholds the relation whole: an `include` neither loads it nor
|
|
68
|
-
* counts it. {@link stripUnreadable} cannot be the only guard here, because the
|
|
69
|
-
* REST rows are stripped before the include loader runs (`toRestRow`, then
|
|
70
|
-
* `loadIncludes`) — the loader wrote the rows back onto the key the strip had
|
|
71
|
-
* just deleted, and `_count` beside them.
|
|
72
|
-
*
|
|
73
|
-
* Judged by every `type: "relation"` property that names this relation: by its
|
|
74
|
-
* own key (the include key of an inline relation), or by the `relationName` it
|
|
75
|
-
* addresses in the collection's `relations` array. A relation declared only in
|
|
76
|
-
* `relations` has no property, so no field rule, and stays readable.
|
|
77
|
-
*/
|
|
78
|
-
export declare function canReadRelation(collection: CollectionConfig, key: string, relation: ResolvedRelation): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* The address a relation ref points at.
|
|
81
|
-
*
|
|
82
|
-
* The whole key, not its first column: a composite-keyed target addressed by
|
|
83
|
-
* `tenant_id` alone points at every row that shares it. A target whose key
|
|
84
|
-
* cannot be resolved at all used to throw here — reading `[0]` of an empty
|
|
85
|
-
* array — taking down the parent's fetch over a relation it may not even have
|
|
86
|
-
* asked for. The first column is a guess, but a ref that resolves to nothing
|
|
87
|
-
* beats no rows at all.
|
|
88
|
-
*/
|
|
89
|
-
export declare function relationTargetAddress(targetRow: Record<string, unknown>, targetCollection: CollectionConfig, registry: PostgresCollectionRegistry): string;
|
|
65
|
+
export declare function stripUnreadable(row: Record<string, unknown>, table: TableDescriptor): Record<string, unknown>;
|
|
90
66
|
/**
|
|
91
|
-
*
|
|
67
|
+
* May the current caller be handed the rows of this relation?
|
|
92
68
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
69
|
+
* A relation's value *is* its related rows, so a relation the caller may not
|
|
70
|
+
* read (`rel.*(…, { access: { read } })`, `{ private: true }`, or one whose
|
|
71
|
+
* join reads a column it may not read — on this table or, through `related`,
|
|
72
|
+
* on the others) is withheld whole: an `include` neither loads it nor counts
|
|
73
|
+
* it. {@link stripUnreadable}
|
|
74
|
+
* cannot be the only guard here, because the REST rows are stripped before the
|
|
75
|
+
* include loader runs (`toRestRow`, then `loadIncludes`) — the loader wrote the
|
|
76
|
+
* rows back onto the key the strip had just deleted, and `_count` beside them.
|
|
96
77
|
*/
|
|
97
|
-
export declare function
|
|
78
|
+
export declare function canReadRelation(table: TableDescriptor, relation: RelationDescriptor, related?: RelatedTables): boolean;
|
|
98
79
|
/**
|
|
99
80
|
* The row REST serves: every column under its own name, with the value Postgres
|
|
100
81
|
* returned, and relations inlined as the target's columns.
|
|
101
82
|
*
|
|
102
83
|
* Values are the ones the database returned, except where that contradicts the
|
|
103
|
-
*
|
|
104
|
-
* {@link coerceDeclaredNumber}) and a
|
|
105
|
-
* server's own OpenAPI document says a
|
|
84
|
+
* column's type: a numeric column is served as a number (see
|
|
85
|
+
* {@link coerceDeclaredNumber}) and a temporal one as RFC 3339, which is what
|
|
86
|
+
* this server's own OpenAPI document says such a column is (see
|
|
106
87
|
* {@link toRestDate}).
|
|
107
88
|
*
|
|
108
89
|
* Keyed by the row rather than by the relation list — a REST fetch only loads
|
|
109
90
|
* the relations `include` asked for, so the row is the authority on which are
|
|
110
91
|
* actually there.
|
|
111
92
|
*/
|
|
112
|
-
export declare function toRestRow(row: Record<string, unknown>,
|
|
93
|
+
export declare function toRestRow(row: Record<string, unknown>, table: RuntimeTable, registry: PostgresTableRegistry): Record<string, unknown>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SQL } from "drizzle-orm";
|
|
2
2
|
import type { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import type { CollectionConfig } from "@rebasepro/types";
|
|
4
3
|
import { ApiError } from "@rebasepro/server";
|
|
4
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
5
5
|
/**
|
|
6
6
|
* Soft delete, in one place.
|
|
7
7
|
*
|
|
8
|
-
* A
|
|
8
|
+
* A table with `softDelete` records a deletion as a timestamp instead of
|
|
9
9
|
* removing the row, which means two things have to hold everywhere and not
|
|
10
10
|
* almost everywhere:
|
|
11
11
|
*
|
|
@@ -18,58 +18,59 @@ import { ApiError } from "@rebasepro/server";
|
|
|
18
18
|
* exactly one function, here, and the read paths call it — rather than each
|
|
19
19
|
* path growing its own `isNull(...)`, which is how these features rot.
|
|
20
20
|
*
|
|
21
|
-
* The field is a
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
21
|
+
* The field is a timestamp column the table declares itself, named by the
|
|
22
|
+
* table's descriptor (`softDelete.field`). This module resolves it and nothing
|
|
23
|
+
* more: it does not add the column, and a definition that turns the flag on
|
|
24
|
+
* without the column does not compile, so the answer is a schema change at
|
|
25
|
+
* boot rather than a 500 at the first delete.
|
|
26
26
|
*/
|
|
27
27
|
/** How a caller asks about deleted rows. See `FetchCollectionProps.withDeleted`. */
|
|
28
28
|
export type WithDeleted = boolean | "only" | undefined;
|
|
29
29
|
export interface SoftDeleteField {
|
|
30
|
-
/** The
|
|
30
|
+
/** The column key — the wire name, what a `PATCH` sets to `null`. */
|
|
31
31
|
field: string;
|
|
32
|
-
/** The
|
|
32
|
+
/** The SQL column name. */
|
|
33
33
|
columnName: string;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* The soft-delete
|
|
36
|
+
* The soft-delete column of this table, or `undefined` if it has none.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
39
|
-
* is
|
|
40
|
-
* a misconfiguration into "soft delete quietly off", which is the failure mode
|
|
41
|
-
* worth avoiding — deletes would silently start removing rows.
|
|
38
|
+
* Read from the descriptor, which names both the key and the SQL name, so
|
|
39
|
+
* nothing is derived here.
|
|
42
40
|
*/
|
|
43
|
-
export declare function resolveSoftDelete(
|
|
41
|
+
export declare function resolveSoftDelete(table: RuntimeTable | undefined): SoftDeleteField | undefined;
|
|
44
42
|
/**
|
|
45
|
-
* The drizzle column behind the soft-delete field, if the table has
|
|
43
|
+
* The drizzle column behind the soft-delete field, if the catalogue table has
|
|
44
|
+
* one.
|
|
46
45
|
*
|
|
47
|
-
* Matched on the column's own `name
|
|
48
|
-
*
|
|
49
|
-
* may key them by the column — and this has to work for both.
|
|
46
|
+
* Matched on the key first, then on the column's own `name`, because a table
|
|
47
|
+
* read back from the catalogue keys columns by wire name while a hand-written
|
|
48
|
+
* drizzle table may key them by the column — and this has to work for both.
|
|
49
|
+
*
|
|
50
|
+
* @param pg The drizzle table the statement is built on.
|
|
50
51
|
*/
|
|
51
|
-
export declare function softDeleteColumn(
|
|
52
|
+
export declare function softDeleteColumn(table: RuntimeTable | undefined, pg: PgTable): AnyPgColumn | undefined;
|
|
52
53
|
/**
|
|
53
54
|
* `deleted_at IS NULL` — or nothing, when the caller asked for the deleted rows
|
|
54
|
-
* or the
|
|
55
|
+
* or the table has no soft delete at all.
|
|
55
56
|
*
|
|
56
57
|
* The one place the rule is written. Call it from every read; `undefined` means
|
|
57
58
|
* "add no condition", which composes with `and(...)` unchanged.
|
|
58
59
|
*/
|
|
59
|
-
export declare function softDeleteCondition(
|
|
60
|
+
export declare function softDeleteCondition(table: RuntimeTable | undefined, pg: PgTable, withDeleted?: WithDeleted): SQL | undefined;
|
|
60
61
|
/**
|
|
61
62
|
* Fold the soft-delete condition into a list of conditions that is being built.
|
|
62
63
|
*
|
|
63
64
|
* A convenience for the call sites that already collect `SQL[]`, so adding soft
|
|
64
65
|
* delete to one of them is a single line rather than three.
|
|
65
66
|
*/
|
|
66
|
-
export declare function withSoftDelete(conditions: SQL[],
|
|
67
|
+
export declare function withSoftDelete(conditions: SQL[], table: RuntimeTable | undefined, pg: PgTable, withDeleted?: WithDeleted): SQL[];
|
|
67
68
|
/**
|
|
68
69
|
* Combine an existing `where` with the soft-delete condition.
|
|
69
70
|
*
|
|
70
71
|
* For the call sites that hold one composed condition rather than a list.
|
|
71
72
|
*/
|
|
72
|
-
export declare function andSoftDelete(where: SQL | undefined,
|
|
73
|
+
export declare function andSoftDelete(where: SQL | undefined, table: RuntimeTable | undefined, pg: PgTable, withDeleted?: WithDeleted): SQL | undefined;
|
|
73
74
|
/**
|
|
74
75
|
* The refusal of an upsert whose key belongs to a row in the trash.
|
|
75
76
|
*
|