@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,9 +1,11 @@
|
|
|
1
1
|
import { SQL } from "drizzle-orm";
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { DrizzleClient } from "../interfaces.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { FilterValues, OrderByTuple, RelationDescriptor } from "@rebasepro/types";
|
|
5
5
|
import { type JoinStep } from "@rebasepro/types";
|
|
6
|
-
import {
|
|
6
|
+
import { type PointsBackRelation } from "./relation-tables.js";
|
|
7
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
8
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
7
9
|
import type { NestedPathHop } from "./nested-path.js";
|
|
8
10
|
import { type ReadCallContextProvider } from "./read-scope.js";
|
|
9
11
|
/**
|
|
@@ -53,18 +55,6 @@ export interface RelatedRowWindow {
|
|
|
53
55
|
*/
|
|
54
56
|
totals?: Map<string, number>;
|
|
55
57
|
}
|
|
56
|
-
/**
|
|
57
|
-
* How the batch loaders render a target row.
|
|
58
|
-
*
|
|
59
|
-
* - `"admin"` — the view model the admin panel reads: declared types parsed
|
|
60
|
-
* (`parseDataFromServer`), the target's own to-one relations as
|
|
61
|
-
* `{ __type: "relation" }` refs, undeclared columns dropped.
|
|
62
|
-
* - `"rest"` — the row the target's own route serves (`toRestRow`): what an
|
|
63
|
-
* `include` embeds. The REST contract is that a developer never sees a ref,
|
|
64
|
-
* and an included row is rendered exactly as the same row is at the top
|
|
65
|
-
* level.
|
|
66
|
-
*/
|
|
67
|
-
export type RelatedRowStyle = "admin" | "rest";
|
|
68
58
|
/**
|
|
69
59
|
* The order one parent's related rows come in: the include's own keys, then
|
|
70
60
|
* the target's key ascending.
|
|
@@ -80,13 +70,9 @@ export type RelatedRowStyle = "admin" | "rest";
|
|
|
80
70
|
* Postgres's own (last ascending, first descending).
|
|
81
71
|
*/
|
|
82
72
|
export declare function relatedRowOrder(targetTable: PgTable, targetKeys: AnyPgColumn[], orderBy: OrderByTuple[] | undefined): SQL[];
|
|
83
|
-
/**
|
|
84
|
-
* Service for handling all relation-related operations.
|
|
85
|
-
* Handles fetching, updating, and managing row relations.
|
|
86
|
-
*/
|
|
87
73
|
/**
|
|
88
74
|
* A related record resolved by {@link RelationService}: the target row's
|
|
89
|
-
* values plus the identity (`id`) and originating
|
|
75
|
+
* values plus the identity (`id`) and originating table (`path`, its slug)
|
|
90
76
|
* needed to build relation references. Internal to the postgres driver —
|
|
91
77
|
* flattened to plain rows at the fetch-service boundary.
|
|
92
78
|
*/
|
|
@@ -95,9 +81,9 @@ export interface RelatedRow<M extends Record<string, unknown> = Record<string, u
|
|
|
95
81
|
path: string;
|
|
96
82
|
values: M;
|
|
97
83
|
/**
|
|
98
|
-
* The
|
|
99
|
-
*
|
|
100
|
-
*
|
|
84
|
+
* The link's own columns, for a `manyToMany` that declares a `pivot`.
|
|
85
|
+
* Absent for every other relation kind and for a junction that carries
|
|
86
|
+
* nothing but its two keys.
|
|
101
87
|
*
|
|
102
88
|
* Kept beside `values` rather than merged into them, because it is not the
|
|
103
89
|
* target's data: two posts sharing a tag see the same tag row and different
|
|
@@ -116,7 +102,7 @@ export declare class RelationService {
|
|
|
116
102
|
* read unnarrowed. See `read-scope.ts`.
|
|
117
103
|
*/
|
|
118
104
|
private callContext?;
|
|
119
|
-
constructor(db: DrizzleClient, registry:
|
|
105
|
+
constructor(db: DrizzleClient, registry: PostgresTableRegistry,
|
|
120
106
|
/**
|
|
121
107
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
122
108
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
@@ -124,14 +110,22 @@ export declare class RelationService {
|
|
|
124
110
|
* read unnarrowed. See `read-scope.ts`.
|
|
125
111
|
*/
|
|
126
112
|
callContext?: ReadCallContextProvider | undefined);
|
|
113
|
+
/** The runtime table a parent path names (`requireTableAt` resolves aliases and reports unknown paths). */
|
|
114
|
+
private tableAt;
|
|
115
|
+
private ends;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve a `via` relation's steps from `parentTable`, aliasing every
|
|
118
|
+
* table a step may revisit. See {@link ViaJoinPath}.
|
|
119
|
+
*/
|
|
120
|
+
private viaJoinPath;
|
|
127
121
|
/**
|
|
128
|
-
* The **target**
|
|
122
|
+
* The **target** table's `beforeQuery` narrowing, for rows reached
|
|
129
123
|
* through a relation.
|
|
130
124
|
*
|
|
131
125
|
* The target's, not the parent's, because these are the target's rows: a
|
|
132
126
|
* scope on `comments` has to hold whether they are listed at
|
|
133
127
|
* `/comments` or loaded as `post.comments`. Without this an `include` is a
|
|
134
|
-
* way around every row filter a
|
|
128
|
+
* way around every row filter a table declares — the exact hole
|
|
135
129
|
* `stripUnreadable` was once missing from the relation-ref branch.
|
|
136
130
|
*
|
|
137
131
|
* Folded into the `narrow` condition the loaders already thread through
|
|
@@ -149,85 +143,41 @@ export declare class RelationService {
|
|
|
149
143
|
* has to diff against what the caller could have read — otherwise saving
|
|
150
144
|
* back the list they were shown unlinks every row they were not.
|
|
151
145
|
*/
|
|
152
|
-
visibleTargetCondition(
|
|
146
|
+
visibleTargetCondition(parent: RuntimeTable, relation: RelationDescriptor, parentId?: string | number): Promise<SQL | undefined>;
|
|
153
147
|
/**
|
|
154
|
-
* One target row, as the {@link RelatedRow} everything here returns
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* target's first key column in all eight — one edit, eight places to miss.
|
|
158
|
-
*
|
|
159
|
-
* `resolveNested` is the one thing they did not agree on, and the
|
|
160
|
-
* disagreement was invisible: the single-parent fetches pass `db` and
|
|
161
|
-
* `registry` to `parseDataFromServer`, so the target's *own* relations get
|
|
162
|
-
* resolved too, while the batch paths deliberately do not — a query per
|
|
163
|
-
* target row is the N+1 the batching exists to avoid. Naming the parameter
|
|
164
|
-
* makes that a decision rather than a difference between two call sites
|
|
165
|
-
* nobody was comparing.
|
|
148
|
+
* One target row, as the {@link RelatedRow} everything here returns: its
|
|
149
|
+
* values rendered by `render` (see {@link restRendering}) — the row the
|
|
150
|
+
* target's own REST route serves, its field access applied.
|
|
166
151
|
*/
|
|
167
152
|
private toRelatedRow;
|
|
168
153
|
/**
|
|
169
|
-
* A target row as its own REST route serves it
|
|
154
|
+
* A target row as its own REST route serves it — what an `include` embeds,
|
|
155
|
+
* rendered exactly as the same row is at the top level.
|
|
170
156
|
*
|
|
171
157
|
* The loaders read the target with `SELECT *`, so the columns a REST read
|
|
172
158
|
* never selects — a generated search vector — are dropped first; then
|
|
173
159
|
* `toRestRow` renders the rest, which applies the target's field access.
|
|
174
160
|
* Built once per batch: the hidden set is a property of the table.
|
|
175
|
-
*
|
|
176
|
-
* It replaces a second pass. An include used to render each target row as
|
|
177
|
-
* the admin's view model (`parseDataFromServer`, which also minted a
|
|
178
|
-
* `{ __type: "relation" }` ref for the target's own to-one relations) and
|
|
179
|
-
* then re-render that for REST: 3.4 µs a row against 1.4 µs for the row
|
|
180
|
-
* itself, and an envelope in a response whose contract has none.
|
|
181
161
|
*/
|
|
182
162
|
private restRendering;
|
|
183
|
-
/**
|
|
184
|
-
* The junction row's own columns, as the caller may see them.
|
|
185
|
-
*
|
|
186
|
-
* Read through the same two steps the target's columns go through:
|
|
187
|
-
* `parseDataFromServer` gives the declared type (a `date` is a Date, a
|
|
188
|
-
* NUMERIC is a number) and `stripUnreadable` drops what this caller may not
|
|
189
|
-
* read. The second is the point — `access.read: ["hr"]` on a payload
|
|
190
|
-
* property has to mean the same thing it means on a collection's, and the
|
|
191
|
-
* synthetic junction config carries the property verbatim, so the same
|
|
192
|
-
* `effectiveAccess` answers both.
|
|
193
|
-
*
|
|
194
|
-
* Only the payload keys: the two foreign keys are the link's identity, and
|
|
195
|
-
* the caller already has both — one is the row they asked from, the other
|
|
196
|
-
* is the target's own id.
|
|
197
|
-
*/
|
|
198
|
-
private readPivot;
|
|
199
163
|
/**
|
|
200
164
|
* A WHERE matching any of `parentIds`, by the whole key.
|
|
201
165
|
*
|
|
202
166
|
* A single key is an `IN (…)`. A composite one cannot be: matching
|
|
203
167
|
* `tenant_id IN (1, 1)` collects every row of tenant 1, so two parents that
|
|
204
168
|
* share their first column each receive the other's relations. It becomes
|
|
205
|
-
* an OR of ANDs — one exact address per parent
|
|
206
|
-
* same way it would a multi-column key lookup.
|
|
169
|
+
* an OR of ANDs — one exact address per parent.
|
|
207
170
|
*/
|
|
208
171
|
private parentKeyCondition;
|
|
209
172
|
/**
|
|
210
173
|
* Reject a relation that cannot express a composite-keyed parent.
|
|
211
174
|
*
|
|
212
|
-
* `localKey` and `
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
175
|
+
* `localKey` and `foreignKey` are single column names: one column cannot
|
|
176
|
+
* reference a two-column key, so such a relation has no correct reading.
|
|
177
|
+
* Left alone it would silently match on the first key column and hand a
|
|
178
|
+
* tenant's rows to its neighbour — say so instead.
|
|
216
179
|
*/
|
|
217
180
|
private assertSingleKeyAddressable;
|
|
218
|
-
/**
|
|
219
|
-
* What the target's foreign key holds, for each of these parent rows.
|
|
220
|
-
*
|
|
221
|
-
* Ordinarily the parent's id, and then this is free. When the relation
|
|
222
|
-
* declares a `sourceKey` the two are different values, and the mapping
|
|
223
|
-
* between them lives in the source table — so it costs one SELECT, issued
|
|
224
|
-
* once for the whole batch rather than per parent.
|
|
225
|
-
*
|
|
226
|
-
* Both directions come back because both are needed and deriving one from
|
|
227
|
-
* the other by hand is how a batch loader ends up attributing a child to the
|
|
228
|
-
* wrong parent: reads translate id → key to build the WHERE, and then
|
|
229
|
-
* translate key → id to attribute each row that comes back.
|
|
230
|
-
*/
|
|
231
181
|
/**
|
|
232
182
|
* The value a related row's foreign key must hold to belong to this parent.
|
|
233
183
|
*
|
|
@@ -236,17 +186,27 @@ export declare class RelationService {
|
|
|
236
186
|
* {@link PersistService}, which stamps this onto a child created under a
|
|
237
187
|
* nested path and would otherwise write the id and lose the row.
|
|
238
188
|
*/
|
|
239
|
-
parentKeyValue(
|
|
189
|
+
parentKeyValue(parent: RuntimeTable, relation: PointsBackRelation, parentId: string | number, db?: DrizzleClient): Promise<string | number | undefined>;
|
|
240
190
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
191
|
+
* What the target's foreign key holds, for each of these parent rows.
|
|
192
|
+
*
|
|
193
|
+
* Ordinarily the parent's id, and then this is free. When the relation
|
|
194
|
+
* declares a `sourceKey` the two are different values, and the mapping
|
|
195
|
+
* between them lives in the source table — so it costs one SELECT, issued
|
|
196
|
+
* once for the whole batch rather than per parent.
|
|
197
|
+
*
|
|
198
|
+
* Both directions come back because both are needed: reads translate id →
|
|
199
|
+
* key to build the WHERE, and then key → id to attribute each row that
|
|
200
|
+
* comes back. Shared with {@link RelationWriteService}: a write needs the
|
|
201
|
+
* same source key a read does.
|
|
243
202
|
*/
|
|
244
|
-
resolveSourceKeys(
|
|
203
|
+
resolveSourceKeys(parent: RuntimeTable, relation: PointsBackRelation, parentIds: (string | number)[], db?: DrizzleClient): Promise<{
|
|
245
204
|
keyByParentId: Map<string, string | number>;
|
|
246
205
|
parentIdByKey: Map<string, string | number>;
|
|
247
206
|
}>;
|
|
248
207
|
/**
|
|
249
|
-
* Fetch rows related to a parent row through a specific relation
|
|
208
|
+
* Fetch rows related to a parent row through a specific relation.
|
|
209
|
+
* A relation the table does not declare is a 404 `UNKNOWN_RELATION`.
|
|
250
210
|
*/
|
|
251
211
|
fetchRelatedEntities<M extends Record<string, unknown>>(parentCollectionPath: string, parentId: string | number, relationKey: string, options?: {
|
|
252
212
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
@@ -258,9 +218,9 @@ export declare class RelationService {
|
|
|
258
218
|
databaseId?: string;
|
|
259
219
|
}): Promise<RelatedRow<M>[]>;
|
|
260
220
|
/**
|
|
261
|
-
* Fetch rows
|
|
221
|
+
* Fetch the rows one parent reaches through `relation`.
|
|
262
222
|
*/
|
|
263
|
-
fetchEntitiesUsingJoins<M extends Record<string, unknown>>(
|
|
223
|
+
fetchEntitiesUsingJoins<M extends Record<string, unknown>>(parent: RuntimeTable, parentId: string | number, relation: RelationDescriptor, options?: {
|
|
264
224
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
265
225
|
orderBy?: string | OrderByTuple[];
|
|
266
226
|
order?: "desc" | "asc";
|
|
@@ -270,9 +230,10 @@ export declare class RelationService {
|
|
|
270
230
|
databaseId?: string;
|
|
271
231
|
}): Promise<RelatedRow<M>[]>;
|
|
272
232
|
/**
|
|
273
|
-
* Count related rows for a parent row
|
|
233
|
+
* Count related rows for a parent row.
|
|
234
|
+
* A relation the table does not declare is a 404 `UNKNOWN_RELATION`.
|
|
274
235
|
*/
|
|
275
|
-
countRelatedEntities<M extends Record<string, unknown>>(parentCollectionPath: string, parentId: string | number, relationKey: string,
|
|
236
|
+
countRelatedEntities<M extends Record<string, unknown>>(parentCollectionPath: string, parentId: string | number, relationKey: string, _options?: {
|
|
276
237
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
277
238
|
databaseId?: string;
|
|
278
239
|
}): Promise<number>;
|
|
@@ -290,9 +251,8 @@ export declare class RelationService {
|
|
|
290
251
|
* Whether `targetId` is actually reachable from the parent named in `hop`.
|
|
291
252
|
*
|
|
292
253
|
* A nested address like `authors/1/posts/43` used to resolve to the target
|
|
293
|
-
*
|
|
294
|
-
* decided nothing
|
|
295
|
-
* belonged to. Reads, updates and deletes now all gate on this.
|
|
254
|
+
* table and then match on the primary key alone, so the parent segment
|
|
255
|
+
* decided nothing. Reads, updates and deletes now all gate on this.
|
|
296
256
|
*/
|
|
297
257
|
isRelated(hop: NestedPathHop, targetId: string | number): Promise<boolean>;
|
|
298
258
|
/**
|
|
@@ -303,9 +263,7 @@ export declare class RelationService {
|
|
|
303
263
|
* the rows that come back, because filtering afterwards reads every related
|
|
304
264
|
* row of every parent in order to discard most of them.
|
|
305
265
|
*/
|
|
306
|
-
batchFetchRelatedEntities(parentCollectionPath: string, parentIds: (string | number)[], _relationKey: string, relation:
|
|
307
|
-
/** How each target row is rendered; see {@link RelatedRowStyle}. */
|
|
308
|
-
style?: RelatedRowStyle;
|
|
266
|
+
batchFetchRelatedEntities(parentCollectionPath: string, parentIds: (string | number)[], _relationKey: string, relation: RelationDescriptor, narrow?: SQL, options?: {
|
|
309
267
|
/**
|
|
310
268
|
* The parent rows themselves, in `parentIds` order, when the caller
|
|
311
269
|
* holds them. A `belongsTo` reads each one's foreign key off its
|
|
@@ -323,17 +281,10 @@ export declare class RelationService {
|
|
|
323
281
|
* parent's rows rather than a `LIMIT`: a subquery ranks the keys of every
|
|
324
282
|
* matching row — under the same relation condition, `narrow`, soft delete
|
|
325
283
|
* and `beforeQuery` the unlimited read applies — and the read joins back to
|
|
326
|
-
* the ones ranked within the limit.
|
|
327
|
-
*
|
|
328
|
-
* 200,000 read, parsed and rendered for `{ messages: { limit: 2 } }` on a
|
|
329
|
-
* page of 100 threads. Rows come back in the window's order, so the
|
|
330
|
-
* per-parent lists are already sorted.
|
|
284
|
+
* the ones ranked within the limit. Rows come back in the window's order,
|
|
285
|
+
* so the per-parent lists are already sorted.
|
|
331
286
|
*/
|
|
332
|
-
batchFetchRelatedEntitiesMany(parentCollectionPath: string, parentIds: (string | number)[], _relationKey: string, relation:
|
|
287
|
+
batchFetchRelatedEntitiesMany(parentCollectionPath: string, parentIds: (string | number)[], _relationKey: string, relation: RelationDescriptor,
|
|
333
288
|
/** An extra condition on the target — see {@link batchFetchRelatedEntities}. */
|
|
334
|
-
narrow?: SQL, window?: RelatedRowWindow,
|
|
335
|
-
/** `style` — how each target row is rendered; see {@link RelatedRowStyle}. */
|
|
336
|
-
options?: {
|
|
337
|
-
style?: RelatedRowStyle;
|
|
338
|
-
}): Promise<Map<string, RelatedRow<Record<string, unknown>>[]>>;
|
|
289
|
+
narrow?: SQL, window?: RelatedRowWindow): Promise<Map<string, RelatedRow<Record<string, unknown>>[]>>;
|
|
339
290
|
}
|
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RelationOfKind } from "@rebasepro/common";
|
|
2
2
|
import { DrizzleClient } from "../interfaces.js";
|
|
3
|
-
import {
|
|
3
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
4
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
4
5
|
import type { NestedPathHop } from "./nested-path.js";
|
|
5
6
|
import type { ReadCallContextProvider } from "./read-scope.js";
|
|
6
|
-
/**
|
|
7
|
-
* A `_pivot` as the junction table's columns.
|
|
8
|
-
*
|
|
9
|
-
* Exported because the payload route needs the identical reading — one function
|
|
10
|
-
* so a value written through `PATCH posts/1 { tags: [{ id, _pivot }] }` and the
|
|
11
|
-
* same value written through `PATCH posts/1/tags/5 { _pivot }` cannot be
|
|
12
|
-
* serialized two ways.
|
|
13
|
-
*/
|
|
14
|
-
export declare function serializePivot(pivot: Record<string, unknown>, payload: Properties, label: string): Record<string, unknown>;
|
|
15
7
|
/**
|
|
16
8
|
* Writing relations: junction membership, foreign-key stamping, and the links a
|
|
17
9
|
* nested path creates or removes.
|
|
18
10
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* as an empty list on the read side and as a successful save on the write side.
|
|
23
|
-
* Separating them is what made that visible as one class of defect rather than
|
|
24
|
-
* eighteen scattered log lines.
|
|
25
|
-
*
|
|
26
|
-
* The reads it still needs — the source key a link joins on — it asks
|
|
11
|
+
* Every relation fact comes from the owning table's relation descriptor; the
|
|
12
|
+
* target is looked up by slug. The reads it needs — the source key a link
|
|
13
|
+
* joins on, the target rows the caller may see — it asks
|
|
27
14
|
* {@link RelationService} for rather than reimplementing.
|
|
28
15
|
*/
|
|
29
16
|
export declare class RelationWriteService {
|
|
@@ -32,103 +19,109 @@ export declare class RelationWriteService {
|
|
|
32
19
|
/**
|
|
33
20
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
34
21
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
35
|
-
* test, where a
|
|
36
|
-
*
|
|
22
|
+
* test, where a table declaring the hook is refused rather than read
|
|
23
|
+
* unnarrowed. See `read-scope.ts`.
|
|
37
24
|
*/
|
|
38
25
|
private callContext?;
|
|
39
26
|
private reads;
|
|
40
|
-
constructor(db: DrizzleClient, registry:
|
|
27
|
+
constructor(db: DrizzleClient, registry: PostgresTableRegistry,
|
|
41
28
|
/**
|
|
42
29
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
43
30
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
44
|
-
* test, where a
|
|
45
|
-
*
|
|
31
|
+
* test, where a table declaring the hook is refused rather than read
|
|
32
|
+
* unnarrowed. See `read-scope.ts`.
|
|
46
33
|
*/
|
|
47
34
|
callContext?: ReadCallContextProvider | undefined);
|
|
35
|
+
/**
|
|
36
|
+
* The relation `name` of `owner`, for a write that names it. A write the
|
|
37
|
+
* caller split off as a relation value names a declared relation, so a
|
|
38
|
+
* miss is a wiring defect and is refused rather than skipped.
|
|
39
|
+
*/
|
|
40
|
+
private relationNamed;
|
|
48
41
|
/**
|
|
49
42
|
* Remove the junction row linking a parent to `targetId`, leaving the target
|
|
50
43
|
* row itself alone.
|
|
51
44
|
*
|
|
52
45
|
* This is what `DELETE authors/1/tags/5` has to mean for a many-to-many: the
|
|
53
46
|
* target is shared, so deleting the row would remove the tag from every other
|
|
54
|
-
* post that uses it.
|
|
55
|
-
* `tags` table and delete by primary key.
|
|
47
|
+
* post that uses it.
|
|
56
48
|
*/
|
|
57
49
|
unlinkRelatedEntity(tx: DrizzleClient, hop: NestedPathHop, targetId: string | number): Promise<void>;
|
|
58
50
|
/**
|
|
59
|
-
* Set the columns of one existing link
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* membership array cannot say this: one element would unlink everything
|
|
63
|
-
* else, and re-sending the whole set to change one `role` reintroduces the
|
|
64
|
-
* lost update the membership diff exists to avoid.
|
|
51
|
+
* Set the link's own columns of one existing link — `PATCH
|
|
52
|
+
* …/:relation/:targetId` with a `_pivot` body. Only a `manyToMany` that
|
|
53
|
+
* declares a `pivot` has them.
|
|
65
54
|
*/
|
|
66
55
|
updateRelationPivot(tx: DrizzleClient, hop: NestedPathHop, targetId: string | number, pivot: Record<string, unknown>): Promise<void>;
|
|
67
56
|
/**
|
|
68
|
-
* The target rows
|
|
69
|
-
*
|
|
70
|
-
* {@link RelationService.visibleTargetCondition}.
|
|
57
|
+
* The target rows a membership write diffs against, when that is not all
|
|
58
|
+
* of them: the target's `beforeQuery` scope and soft delete.
|
|
71
59
|
*/
|
|
72
60
|
private visibleTargets;
|
|
73
|
-
/**
|
|
61
|
+
/** An id as the first key column of `table` holds it. */
|
|
74
62
|
private parsedId;
|
|
75
|
-
/** The same, for the membership list a to-many write names. */
|
|
76
|
-
private parsedIds;
|
|
77
63
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* The values go through `serializePropertyToServer` — the same function
|
|
82
|
-
* every collection column's value goes through on a save — so a `date`
|
|
83
|
-
* arrives as a Date and a `map` as JSON, keyed by the property key, which is
|
|
84
|
-
* what the drizzle junction table is keyed by. A key the junction does not
|
|
85
|
-
* declare is **refused**, not dropped: drizzle leaves an unknown key out of
|
|
86
|
-
* the statement, so dropping it is a write that reports success having
|
|
87
|
-
* stored nothing.
|
|
64
|
+
* Each element's id parsed against the target's key, and its `_pivot`
|
|
65
|
+
* checked against the relation's `pivot` columns.
|
|
88
66
|
*/
|
|
89
67
|
private parsedLinks;
|
|
90
68
|
/**
|
|
91
|
-
*
|
|
69
|
+
* Write the to-many relations named in `relationValues` — junction
|
|
70
|
+
* membership for a `manyToMany` or a single-hop `via`, foreign keys on the
|
|
71
|
+
* target for a `hasMany`.
|
|
72
|
+
*/
|
|
73
|
+
updateRelationsUsingJoins<M extends Record<string, unknown>>(tx: DrizzleClient, owner: RuntimeTable, id: string | number, relationValues: Partial<M>): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* A `hasMany` membership write: point the named target rows at this
|
|
76
|
+
* parent's source key, and unpoint the ones no longer named — both
|
|
77
|
+
* narrowed to the target rows the caller may see.
|
|
92
78
|
*/
|
|
93
|
-
|
|
79
|
+
private writeForeignKeys;
|
|
94
80
|
/**
|
|
95
|
-
*
|
|
81
|
+
* Write the relations whose link lives away from the source row — a
|
|
82
|
+
* `hasOne` (the target's foreign key), a `manyToMany` or a `via` — named
|
|
83
|
+
* by a create or update of the source.
|
|
96
84
|
*/
|
|
97
|
-
updateInverseRelations(tx: DrizzleClient,
|
|
85
|
+
updateInverseRelations(tx: DrizzleClient, owner: RuntimeTable, sourceEntityId: string | number, inverseRelationUpdates: Array<{
|
|
86
|
+
/** The relation's name. */
|
|
98
87
|
relationKey: string;
|
|
99
|
-
relation: ResolvedRelation;
|
|
100
88
|
newValue: unknown;
|
|
101
89
|
}>): Promise<void>;
|
|
102
90
|
/**
|
|
103
|
-
*
|
|
91
|
+
* A to-many `via` write through its one junction table. A chain with more
|
|
92
|
+
* than one table between the ends, or a to-one chain, writes nothing here.
|
|
104
93
|
*/
|
|
105
94
|
private updateInverseJoinPathRelation;
|
|
106
95
|
/**
|
|
107
|
-
*
|
|
96
|
+
* Write to-one `via` relations: copy the parent's column the chain joins
|
|
97
|
+
* on into the target row's column, clearing it from the row that held it.
|
|
108
98
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* Update one-to-one relations that use joinPath
|
|
112
|
-
*/
|
|
113
|
-
updateJoinPathOneToOneRelations(tx: DrizzleClient, parentCollection: CollectionConfig, parentId: string | number, updates: Array<{
|
|
99
|
+
updateJoinPathOneToOneRelations(tx: DrizzleClient, parent: RuntimeTable, parentId: string | number, updates: Array<{
|
|
100
|
+
/** The relation's name. */
|
|
114
101
|
relationKey: string;
|
|
115
|
-
relation: ResolvedVia;
|
|
116
102
|
newTargetId: string | number | null;
|
|
117
103
|
}>): Promise<void>;
|
|
118
104
|
/**
|
|
119
|
-
*
|
|
105
|
+
* Which parent column a to-one `via` write copies into which target
|
|
106
|
+
* column: the last step's `to`, and — walking back by position (or by a
|
|
107
|
+
* `table.column` spelling) — the first step's `from`.
|
|
108
|
+
*
|
|
109
|
+
* @param parentTableName The parent's SQL table name.
|
|
120
110
|
*/
|
|
121
|
-
resolveJoinPathWriteMapping(
|
|
111
|
+
resolveJoinPathWriteMapping(parentTableName: string, relation: RelationOfKind<"via">): {
|
|
122
112
|
targetFKColName: string;
|
|
123
113
|
parentSourceColName: string;
|
|
124
114
|
};
|
|
125
115
|
/**
|
|
126
|
-
*
|
|
116
|
+
* Link a row created under a many-to-many path (`POST posts/1/tags`) to its
|
|
117
|
+
* parent: one junction row, idempotently.
|
|
127
118
|
*/
|
|
128
119
|
handleJunctionTableCreation(tx: DrizzleClient, newEntityId: string | number, junctionTableInfo: {
|
|
129
|
-
|
|
120
|
+
/** The parent table. */
|
|
121
|
+
parent: RuntimeTable;
|
|
122
|
+
/** The parent's id, parsed against its key. */
|
|
130
123
|
parentId: string | number;
|
|
131
|
-
relation:
|
|
124
|
+
relation: RelationOfKind<"manyToMany">;
|
|
132
125
|
relationKey: string;
|
|
133
126
|
}): Promise<void>;
|
|
134
127
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
/** One key field of a collection, and the column it is stored in. */
|
|
1
|
+
import type { RuntimeTable } from "../../model/runtime-table.js";
|
|
2
|
+
/** One key column of a table, by key and by SQL name. */
|
|
4
3
|
export interface KeyColumn {
|
|
5
4
|
fieldName: string;
|
|
6
5
|
columnName: string;
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
|
-
* The columns a
|
|
8
|
+
* The columns a table's rows are addressed by.
|
|
10
9
|
*
|
|
11
10
|
* A change notification names its row by column — that is all a trigger sees —
|
|
12
11
|
* and an address is built from the key's *field* names. Both ends read the
|
|
@@ -15,5 +14,8 @@ export interface KeyColumn {
|
|
|
15
14
|
* captured columns back into an address. A key declared as `userId` over
|
|
16
15
|
* `user_id` used to be looked up by field name on the captured row, never
|
|
17
16
|
* found, and every external write reached no single-row subscriber.
|
|
17
|
+
*
|
|
18
|
+
* The SQL name is the descriptor's; for a keyless introspected table addressed
|
|
19
|
+
* through its catalogue, the catalogue column's.
|
|
18
20
|
*/
|
|
19
|
-
export declare function
|
|
21
|
+
export declare function tableKeyColumns(table: RuntimeTable): KeyColumn[];
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PostgresCollectionRegistry } from "../../collections/PostgresCollectionRegistry.js";
|
|
1
|
+
import { PostgresTableRegistry } from "../../model/PostgresTableRegistry.js";
|
|
3
2
|
/**
|
|
4
3
|
* One end of a many-to-many, as seen from the junction table.
|
|
5
4
|
*
|
|
6
|
-
* A junction table is not a
|
|
7
|
-
* one — which is why a change to it was invisible to change
|
|
8
|
-
* rows are exactly the contents of a parent's child list, so
|
|
9
|
-
* change to `<parentSlug>/<sourceId>/<relationKey>` and to
|
|
5
|
+
* A junction table is not a table anybody declared, so nothing in the registry
|
|
6
|
+
* maps it to one — which is why a change to it was invisible to change
|
|
7
|
+
* capture. But its rows are exactly the contents of a parent's child list, so
|
|
8
|
+
* a write to it is a change to `<parentSlug>/<sourceId>/<relationKey>` and to
|
|
9
|
+
* nothing else.
|
|
10
10
|
*/
|
|
11
11
|
export interface JunctionLink {
|
|
12
12
|
schema: string;
|
|
13
13
|
/** The junction table itself, e.g. `posts_tags`. */
|
|
14
14
|
table: string;
|
|
15
|
-
/** The
|
|
16
|
-
|
|
17
|
-
/** The relation's
|
|
15
|
+
/** The slug of the table whose relation this is, e.g. `posts`. */
|
|
16
|
+
parentSlug: string;
|
|
17
|
+
/** The relation's name — the path segment a child list is addressed by. */
|
|
18
18
|
relationKey: string;
|
|
19
19
|
/** Junction column holding the parent's id. */
|
|
20
20
|
sourceColumn: string;
|
|
@@ -22,17 +22,17 @@ export interface JunctionLink {
|
|
|
22
22
|
targetColumn: string;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Every junction table reachable from a
|
|
26
|
-
*
|
|
25
|
+
* Every junction table reachable from a served table, once per `manyToMany`
|
|
26
|
+
* that uses it — read from each table's relation descriptors.
|
|
27
27
|
*
|
|
28
28
|
* A junction is listed once per *direction* when both sides declare it, because
|
|
29
29
|
* each direction addresses a different child list: `posts/1/tags` and
|
|
30
30
|
* `tags/t/posts` both change when one link is written.
|
|
31
31
|
*/
|
|
32
|
-
export declare function collectJunctionLinks(registry:
|
|
32
|
+
export declare function collectJunctionLinks(registry: PostgresTableRegistry): JunctionLink[];
|
|
33
33
|
/**
|
|
34
34
|
* Index {@link collectJunctionLinks} by table, under both the qualified and the
|
|
35
35
|
* bare name — a change event carries whatever the trigger reports, and a
|
|
36
|
-
*
|
|
36
|
+
* table need not declare a schema.
|
|
37
37
|
*/
|
|
38
|
-
export declare function buildJunctionLinkMap(registry:
|
|
38
|
+
export declare function buildJunctionLinkMap(registry: PostgresTableRegistry): Map<string, JunctionLink[]>;
|