@rebasepro/server-postgres 0.30.1 → 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,7 +1,7 @@
|
|
|
1
1
|
import { PgTable, AnyPgColumn } from "drizzle-orm/pg-core";
|
|
2
2
|
import { type SQL } from "drizzle-orm";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
4
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
5
5
|
import { ApiError } from "@rebasepro/server";
|
|
6
6
|
export { buildCompositeId, parseIdValues, isAddressableId, COMPOSITE_ID_SEPARATOR } from "@rebasepro/common";
|
|
7
7
|
export type { PrimaryKeyInfo } from "@rebasepro/common";
|
|
@@ -11,7 +11,7 @@ import type { PrimaryKeyInfo } from "@rebasepro/common";
|
|
|
11
11
|
* These are used by FetchService, PersistService, and RelationService.
|
|
12
12
|
*
|
|
13
13
|
* All functions that need collection/table lookups require an explicit
|
|
14
|
-
* `
|
|
14
|
+
* `PostgresTableRegistry` instance — there is no global singleton.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* Interface for Drizzle column metadata introspection.
|
|
@@ -27,10 +27,9 @@ export declare function getColumnMeta(col: AnyPgColumn): DrizzleColumnMeta;
|
|
|
27
27
|
/**
|
|
28
28
|
* Whether an address could name a row in this table, judged by the columns.
|
|
29
29
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* is what Postgres will enforce: a `uuid` column meets `/c/products/new` with
|
|
30
|
+
* The descriptor's key type is the declaration — right for deriving
|
|
31
|
+
* addresses, a claim when it comes to refusing a query. Here the Drizzle
|
|
32
|
+
* column type decides, because it is what Postgres will enforce: a `uuid` column meets `/c/products/new` with
|
|
34
33
|
* `22P02`, which aborts the surrounding transaction and turns every later
|
|
35
34
|
* statement into an unrelated-looking `25P02`.
|
|
36
35
|
*/
|
|
@@ -45,7 +44,12 @@ export declare function idCanAddressTable(id: string | number, table: PgTable, i
|
|
|
45
44
|
* the writes have always matched the whole key, so the reads must too.
|
|
46
45
|
*/
|
|
47
46
|
export declare function rowIdentityCondition(table: PgTable, idInfoArray: PrimaryKeyInfo[], id: string | number, collectionPath: string): SQL;
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The runtime table a data path addresses (`registry.tableAt`): a root by
|
|
49
|
+
* slug or SQL name, or the target of a walk through relations. Throws, naming
|
|
50
|
+
* the path and every table this driver serves, when the root names none.
|
|
51
|
+
*/
|
|
52
|
+
export declare function requireTableAt(path: string, registry: PostgresTableRegistry): RuntimeTable;
|
|
49
53
|
/**
|
|
50
54
|
* Reject a write naming something that is not a column of the table.
|
|
51
55
|
*
|
|
@@ -95,44 +99,56 @@ export declare function assertWritableColumns(values: Record<string, unknown>, t
|
|
|
95
99
|
* @param detail what does not resolve, in terms of the schema
|
|
96
100
|
*/
|
|
97
101
|
export declare function relationMisconfigured(label: string, detail: string): ApiError;
|
|
98
|
-
export declare function getTableForCollection(collection: CollectionConfig, registry: PostgresCollectionRegistry): PgTable<any>;
|
|
99
102
|
/**
|
|
100
|
-
* The
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
103
|
+
* The catalogue drizzle table a runtime table's statements are built on.
|
|
104
|
+
* Throws, naming the slug and the SQL name, when this database holds none.
|
|
105
|
+
*/
|
|
106
|
+
export declare function pgTableOf(table: RuntimeTable, registry: PostgresTableRegistry): PgTable<any>;
|
|
107
|
+
/**
|
|
108
|
+
* The key columns a table's rows are addressed by, in key order, in the shape
|
|
109
|
+
* the address helpers read (`buildCompositeId`, `parseIdValues`).
|
|
106
110
|
*
|
|
107
|
-
* The
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
111
|
+
* The descriptor's answer (`RuntimeTable.keys`, from `.primaryKey()` and the
|
|
112
|
+
* column types): a compiled table always states its key, so nothing is
|
|
113
|
+
* inferred — the declared `isId` tier always won over the catalogue, and the
|
|
114
|
+
* declaration still does. The catalogue is consulted where it is the truth:
|
|
115
|
+
* {@link idCanAddressTable} judges an address against the column Postgres
|
|
116
|
+
* will compare it with.
|
|
112
117
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
+
* Only a table introspected from a database whose table declares no primary
|
|
119
|
+
* key has no keys in its descriptor. Its address is then read from the
|
|
120
|
+
* catalogue as it always was: the columns marked primary, the columns of a
|
|
121
|
+
* composite constraint, or a column literally named `id`. Returns `[]` when
|
|
122
|
+
* none of those exists — "this table has no address", which a caller that
|
|
123
|
+
* needs one turns into its own error ({@link requireTableKeys}).
|
|
118
124
|
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
* @param pg The catalogue table a keyless table's address is read from; the
|
|
126
|
+
* runtime table's own by default.
|
|
127
|
+
*/
|
|
128
|
+
export declare function tableKeys(table: RuntimeTable, pg?: PgTable | undefined): PrimaryKeyInfo[];
|
|
129
|
+
/**
|
|
130
|
+
* The key columns of a runtime table ({@link tableKeys}), a keyless table's
|
|
131
|
+
* read from the catalogue table registered under its SQL name. `[]` when it
|
|
132
|
+
* has none.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getPrimaryKeys(table: RuntimeTable, registry: PostgresTableRegistry): PrimaryKeyInfo[];
|
|
135
|
+
/**
|
|
136
|
+
* The key columns, for callers that cannot do their job without one: throws,
|
|
137
|
+
* naming the table, when it has none.
|
|
123
138
|
*/
|
|
124
|
-
export declare function
|
|
139
|
+
export declare function requireTableKeys(table: RuntimeTable, pg?: PgTable | undefined): PrimaryKeyInfo[];
|
|
125
140
|
/**
|
|
126
|
-
*
|
|
141
|
+
* {@link requireTableKeys} over the catalogue table registered under the
|
|
142
|
+
* table's SQL name.
|
|
127
143
|
*
|
|
128
144
|
* {@link getPrimaryKeys} answers "what keys, if any" and returns `[]` for a
|
|
129
|
-
*
|
|
145
|
+
* table with no address. Most of this driver, though, is building a WHERE
|
|
130
146
|
* clause and has no meaning without a key — for those, an empty array is not an
|
|
131
147
|
* answer, and indexing `[0]` into it produces `Cannot read properties of
|
|
132
148
|
* undefined` three frames from where the real problem is. This says what is
|
|
133
149
|
* wrong and which collection it is wrong about.
|
|
134
150
|
*/
|
|
135
|
-
export declare function requirePrimaryKeys(
|
|
151
|
+
export declare function requirePrimaryKeys(table: RuntimeTable, registry: PostgresTableRegistry): PrimaryKeyInfo[];
|
|
136
152
|
/**
|
|
137
153
|
* The table's key columns, in key order.
|
|
138
154
|
*
|
|
@@ -173,66 +189,7 @@ export declare function columnAtKey(table: PgTable<any>, key: string): AnyPgColu
|
|
|
173
189
|
*/
|
|
174
190
|
export declare function columnNamed(table: PgTable, name: string): AnyPgColumn | undefined;
|
|
175
191
|
/**
|
|
176
|
-
* The
|
|
177
|
-
*
|
|
178
|
-
* `sourceKey` is authored when the two sides join on a natural key — an
|
|
179
|
-
* external identity id, a SKU — and left off when they join on the row id,
|
|
180
|
-
* which is the overwhelming majority. That makes `undefined` the only optional
|
|
181
|
-
* field on a resolved relation, so it gets exactly one reader: this function.
|
|
182
|
-
* Every consumer that needs the column asks here, and none of them re-derives
|
|
183
|
-
* "or else the primary key" for itself. That is the whole point — the fallback
|
|
184
|
-
* chains this codebase removed from relation resolution were dangerous because
|
|
185
|
-
* they were *duplicated* and could disagree, not because they existed.
|
|
186
|
-
*/
|
|
187
|
-
export declare function sourceKeyField(relation: ResolvedHasOne | ResolvedHasMany, sourceCollection: CollectionConfig, registry: PostgresCollectionRegistry): string;
|
|
188
|
-
/**
|
|
189
|
-
* Whether this link joins on something other than the source's primary key.
|
|
190
|
-
*
|
|
191
|
-
* Callers that hold a parent *id* — which is most of them, since an id is what
|
|
192
|
-
* a URL carries — must translate it to the source key's value before it can be
|
|
193
|
-
* compared with the target's foreign key. Those that hold the parent *row*, or
|
|
194
|
-
* that build a correlated subquery over the source table, can read the column
|
|
195
|
-
* directly and skip the lookup.
|
|
196
|
-
*/
|
|
197
|
-
export declare function joinsOnNaturalKey(relation: ResolvedHasOne | ResolvedHasMany, sourceCollection: CollectionConfig, registry: PostgresCollectionRegistry): boolean;
|
|
198
|
-
/**
|
|
199
|
-
* Collections whose key the *browser* cannot resolve, and what it will do
|
|
200
|
-
* instead.
|
|
201
|
-
*
|
|
202
|
-
* The two sides resolve keys from different evidence. This driver reads, in
|
|
203
|
-
* order: properties marked `isId`, the primary keys of the Drizzle schema, then
|
|
204
|
-
* a column literally named `id`. The admin shares the `CollectionConfig` — it
|
|
205
|
-
* compiles the same collection files into its bundle — but never the Drizzle
|
|
206
|
-
* schema, so the middle tier is invisible to it.
|
|
207
|
-
*
|
|
208
|
-
* Nothing can normalize this at runtime: the server does not serve the admin
|
|
209
|
-
* its collections, so a key resolved here cannot be handed over there. The
|
|
210
|
-
* config files are the only thing both sides read, so the fix is an edit to
|
|
211
|
-
* them, and the most this can do is say exactly which edit.
|
|
212
|
-
*
|
|
213
|
-
* Two shapes, and the second is the dangerous one:
|
|
214
|
-
*
|
|
215
|
-
* - No `isId`, no `id` property → the admin resolves no address, warns in the
|
|
216
|
-
* console, and rows cannot be opened or linked.
|
|
217
|
-
* - No `isId`, but an `id` property that is *not* the key → the admin addresses
|
|
218
|
-
* rows by `id` while this driver reads the address as the real key. Nothing
|
|
219
|
-
* errors: the addresses look right and route wrong.
|
|
220
|
-
*/
|
|
221
|
-
export declare function findUnresolvableKeyCollections(collections: CollectionConfig[], registry: PostgresCollectionRegistry): {
|
|
222
|
-
collection: CollectionConfig;
|
|
223
|
-
keys: PrimaryKeyInfo[];
|
|
224
|
-
shadowedByIdProperty: boolean;
|
|
225
|
-
}[];
|
|
226
|
-
/**
|
|
227
|
-
* Report the collections from {@link findUnresolvableKeyCollections} at boot,
|
|
228
|
-
* with the edit that fixes each one.
|
|
229
|
-
*
|
|
230
|
-
* Grouped by failure, not by collection: the shadowed case is a routing bug and
|
|
231
|
-
* the silent case is a missing feature, and they deserve different urgency.
|
|
232
|
-
*/
|
|
233
|
-
export declare function warnOnKeysTheAdminCannotResolve(collections: CollectionConfig[], registry: PostgresCollectionRegistry): void;
|
|
234
|
-
/**
|
|
235
|
-
* The address of a row: derived from the collection's primary keys, because a
|
|
192
|
+
* The address of a row: derived from the table's primary keys, because a
|
|
236
193
|
* row does not carry one — it is exactly its columns.
|
|
237
194
|
*
|
|
238
195
|
* Falls back to a literal `id` column, for a row that reached us from somewhere
|
|
@@ -240,6 +197,6 @@ export declare function warnOnKeysTheAdminCannotResolve(collections: CollectionC
|
|
|
240
197
|
* callers decide what that means, since "unaddressable" is a different answer
|
|
241
198
|
* in a notification (broadcast a wildcard) than in a save (fail).
|
|
242
199
|
*/
|
|
243
|
-
export declare function deriveRowAddress(row: Record<string, unknown>,
|
|
244
|
-
/** The
|
|
200
|
+
export declare function deriveRowAddress(row: Record<string, unknown>, table: RuntimeTable, registry: PostgresTableRegistry,
|
|
201
|
+
/** The table's keys, when the caller already has them — a batch derives one address per row. */
|
|
245
202
|
primaryKeys?: PrimaryKeyInfo[]): string;
|
|
@@ -6,8 +6,8 @@ import type { WithDeleted } from "./soft-delete.js";
|
|
|
6
6
|
import { PersistService, type ConflictRule, type PersistSaveOptions } from "./PersistService.js";
|
|
7
7
|
import { RelationService } from "./RelationService.js";
|
|
8
8
|
import { DataRepository, DrizzleClient } from "../interfaces.js";
|
|
9
|
-
import {
|
|
10
|
-
export { sanitizeAndConvertDates, serializeDataToServer
|
|
9
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
10
|
+
export { sanitizeAndConvertDates, serializeDataToServer } from "../data-transformer.js";
|
|
11
11
|
export { FetchService } from "./FetchService.js";
|
|
12
12
|
export { PersistService } from "./PersistService.js";
|
|
13
13
|
export { RelationService } from "./RelationService.js";
|
|
@@ -35,7 +35,7 @@ export declare class DataService implements DataRepository {
|
|
|
35
35
|
private callContext?;
|
|
36
36
|
private fetchService;
|
|
37
37
|
private persistService;
|
|
38
|
-
constructor(db: DrizzleClient, registry:
|
|
38
|
+
constructor(db: DrizzleClient, registry: PostgresTableRegistry,
|
|
39
39
|
/**
|
|
40
40
|
* How this service's reads reach the identity their `beforeQuery` hooks
|
|
41
41
|
* run as. Passed by the driver that constructed it; absent only in a
|
|
@@ -44,24 +44,26 @@ export declare class DataService implements DataRepository {
|
|
|
44
44
|
*/
|
|
45
45
|
callContext?: ReadCallContextProvider | undefined);
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* One row, as REST's `GET /:id` serves it — {@link fetchOneForRest} with no
|
|
48
|
+
* `include`. The `DataRepository` door; there is one read walk.
|
|
48
49
|
*/
|
|
49
50
|
fetchOne<M extends Record<string, unknown>>(collectionPath: string, id: string | number, databaseId?: string,
|
|
50
51
|
/** See `FetchCollectionProps.withDeleted`. */
|
|
51
52
|
withDeleted?: WithDeleted): Promise<Record<string, unknown> | undefined>;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
+
* Rows of a table, as REST serves them — {@link fetchCollectionForRest},
|
|
55
|
+
* with the relations `options.include` names. The `DataRepository` door.
|
|
54
56
|
*/
|
|
55
|
-
fetchCollection<M extends Record<string, unknown>>(collectionPath: string, options?: Parameters<FetchService["
|
|
57
|
+
fetchCollection<M extends Record<string, unknown>>(collectionPath: string, { include, ...options }?: Parameters<FetchService["fetchCollectionForRest"]>[1] & {
|
|
58
|
+
include?: IncludeSpec;
|
|
59
|
+
}): Promise<Record<string, unknown>[]>;
|
|
56
60
|
/**
|
|
57
61
|
* The REST read pipeline: flat rows, with exactly the relations `include`
|
|
58
62
|
* names — see {@link FetchService.fetchCollectionForRest}.
|
|
59
63
|
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* and loaded every relation regardless, so a subscription and a REST list
|
|
64
|
-
* answered the same query with two different row shapes.
|
|
64
|
+
* The one read walk: every read on this facade, the realtime refetch
|
|
65
|
+
* included, comes out of it, so a subscription and a REST list answer
|
|
66
|
+
* the same query with the same row.
|
|
65
67
|
*/
|
|
66
68
|
fetchCollectionForRest<M extends Record<string, unknown>>(collectionPath: string, options?: Parameters<FetchService["fetchCollectionForRest"]>[1], include?: IncludeSpec): Promise<Record<string, unknown>[]>;
|
|
67
69
|
/** One row, through the same pipeline. See {@link FetchService.fetchOneForRest}. */
|
|
@@ -73,7 +75,8 @@ export declare class DataService implements DataRepository {
|
|
|
73
75
|
/** See {@link FetchService.cursorFor}. */
|
|
74
76
|
cursorFor(collectionPath: string, row: Record<string, unknown>, orderBy?: OrderByTuple[]): string | undefined;
|
|
75
77
|
/**
|
|
76
|
-
*
|
|
78
|
+
* Rows matching a text search — {@link fetchCollectionForRest} with
|
|
79
|
+
* `searchString`. The `DataRepository` door.
|
|
77
80
|
*/
|
|
78
81
|
searchRows<M extends Record<string, unknown>>(collectionPath: string, searchString: string, options?: {
|
|
79
82
|
filter?: FilterValues<Extract<keyof M, string>>;
|
|
@@ -2,12 +2,12 @@ import { SQL } from "drizzle-orm";
|
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { ApiError } from "@rebasepro/server";
|
|
4
4
|
import type { ParsedFieldOp } from "@rebasepro/server";
|
|
5
|
-
import type {
|
|
5
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
6
6
|
import type { DrizzleClient } from "../interfaces.js";
|
|
7
7
|
/**
|
|
8
8
|
* The expression one operation compiles to, or a 400 saying why it cannot.
|
|
9
9
|
*
|
|
10
|
-
* `field` is the
|
|
10
|
+
* `field` is the column key; it is already known to be a column of `table`
|
|
11
11
|
* (the caller checks that against the same table it builds the statement from).
|
|
12
12
|
*/
|
|
13
13
|
export declare function compileFieldOp(table: PgTable, field: string, op: ParsedFieldOp, context: {
|
|
@@ -25,7 +25,7 @@ export declare function compileFieldOps(table: PgTable, fieldOps: Record<string,
|
|
|
25
25
|
* `{ stock: -5 }` are refused with one answer.
|
|
26
26
|
*/
|
|
27
27
|
export interface FieldOpBound {
|
|
28
|
-
/** The
|
|
28
|
+
/** The column key. */
|
|
29
29
|
field: string;
|
|
30
30
|
code: "min" | "max" | "more_than" | "less_than" | "positive" | "negative" | "min_items" | "max_items";
|
|
31
31
|
/**
|
|
@@ -41,7 +41,7 @@ export interface FieldOpBound {
|
|
|
41
41
|
* The declared bounds each operation's *result* must satisfy, as conditions
|
|
42
42
|
* for the UPDATE that applies it.
|
|
43
43
|
*
|
|
44
|
-
* `{ stock: -5 }` on `stock: {
|
|
44
|
+
* `{ stock: -5 }` on `stock: col.integer().validate({ min: 0 })` is refused before the
|
|
45
45
|
* statement is built, because the value is in the request. What
|
|
46
46
|
* `{ stock: { $inc: -1000 } }` produces depends on the stored row, which the
|
|
47
47
|
* request never sees, so it can only be judged where the row is: in the WHERE
|
|
@@ -54,12 +54,14 @@ export interface FieldOpBound {
|
|
|
54
54
|
* committed, so the second decrement sees `0 - 1` and matches nothing.
|
|
55
55
|
*
|
|
56
56
|
* The bound is the whole declared range, applied to the result the way it
|
|
57
|
-
* applies to a value: a number's `min`, `max`,
|
|
58
|
-
* `positive` and `negative`,
|
|
59
|
-
*
|
|
60
|
-
*
|
|
57
|
+
* applies to a value (`fieldOperationBounds`): a number's `min`, `max`,
|
|
58
|
+
* `moreThan`, `lessThan`, `positive` and `negative`, a list's `minItems` and
|
|
59
|
+
* `maxItems`. `$merge` has no bounds to hold.
|
|
60
|
+
*
|
|
61
|
+
* @param columns The table the operations write, whose column descriptors
|
|
62
|
+
* state the bounds; `table` is its catalogue table, which the SQL is built on.
|
|
61
63
|
*/
|
|
62
|
-
export declare function compileFieldOpBounds(table: PgTable, fieldOps: Record<string, ParsedFieldOp>,
|
|
64
|
+
export declare function compileFieldOpBounds(table: PgTable, fieldOps: Record<string, ParsedFieldOp>, columns: RuntimeTable, context: {
|
|
63
65
|
collectionPath: string;
|
|
64
66
|
}): FieldOpBound[];
|
|
65
67
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type FieldViewer } from "@rebasepro/common";
|
|
2
|
-
import type {
|
|
1
|
+
import { type FieldViewer, type RelatedTables } from "@rebasepro/common";
|
|
2
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
3
3
|
/**
|
|
4
4
|
* Run `fn` with `viewer` as the caller every row strip judges against.
|
|
5
5
|
*
|
|
@@ -19,15 +19,16 @@ export declare function withFieldViewer<T>(viewer: FieldViewer | undefined, fn:
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function currentFieldViewer(): FieldViewer | undefined;
|
|
21
21
|
/**
|
|
22
|
-
* The names an API caller's query may not see on `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* The names an API caller's query may not see on `table`: its private columns
|
|
23
|
+
* and relations (`.private()`, `{ private: true }`) and the foreign key of a
|
|
24
|
+
* private `belongsTo`, and (with `related`) every relation whose join reads a
|
|
25
|
+
* private column, in every spelling (`apiHiddenKeys`). Empty on the
|
|
26
|
+
* trusted server plane (no viewer), which may filter and sort on those
|
|
27
|
+
* columns — the auth adapter looks rows up by them — and empty with no table
|
|
28
|
+
* in hand.
|
|
26
29
|
*
|
|
27
30
|
* A query naming one of these is answered exactly as a query naming a column
|
|
28
|
-
* the table does not have
|
|
29
|
-
*
|
|
30
|
-
* and cannot drift: a "not readable" there would confirm a column OpenAPI and
|
|
31
|
-
* `list_collections` hide.
|
|
31
|
+
* the table does not have: a "not readable" would confirm a column OpenAPI,
|
|
32
|
+
* `GET /api/schema/tables` and `describe_table` hide.
|
|
32
33
|
*/
|
|
33
|
-
export declare function namesHiddenFromCaller(
|
|
34
|
+
export declare function namesHiddenFromCaller(table: TableDescriptor | undefined, related?: RelatedTables): ReadonlySet<string>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TableDescriptor } from "@rebasepro/types";
|
|
2
|
+
/**
|
|
3
|
+
* Keeping a table's generated search columns out of the rows a read returns.
|
|
4
|
+
*
|
|
5
|
+
* A table's `search` block adds physical columns (the `tsvector`, and the
|
|
6
|
+
* trigram text when fuzzy), so `SELECT *` returns them. They are an index in
|
|
7
|
+
* column form and nothing outside the query planner has any use for them; left
|
|
8
|
+
* in, every list response carries a second, larger copy of the row's text.
|
|
9
|
+
*
|
|
10
|
+
* Read from the table's descriptor (`buildTableSearchColumnSpec`, the same
|
|
11
|
+
* builder the planner creates the columns with), plus any column whose type
|
|
12
|
+
* only ever holds a search index (`isSearchIndexColumn` — an introspected
|
|
13
|
+
* database can carry a `tsvector` this framework never created).
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
/** The generated column names a table's search block adds, if any. */
|
|
18
|
+
export declare function searchColumnNamesOf(table: TableDescriptor): string[];
|
|
19
|
+
/**
|
|
20
|
+
* A drizzle select projection over `tableColumns` with the search columns
|
|
21
|
+
* dropped. `undefined` when nothing needs dropping, so the common case keeps a
|
|
22
|
+
* plain `select()`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function visibleColumnProjection<C extends {
|
|
25
|
+
getSQLType?: () => string;
|
|
26
|
+
}>(tableColumns: Record<string, C> | undefined, table?: TableDescriptor): Record<string, C> | undefined;
|
|
27
|
+
/** The same exclusion as a drizzle `db.query` `columns` denylist. */
|
|
28
|
+
export declare function hiddenColumnsOption(tableColumns: Record<string, {
|
|
29
|
+
getSQLType?: () => string;
|
|
30
|
+
}> | undefined, table?: TableDescriptor): Record<string, false> | undefined;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { FetchService } from "./FetchService.js";
|
|
2
2
|
export { PersistService } from "./PersistService.js";
|
|
3
3
|
export { RelationService } from "./RelationService.js";
|
|
4
|
-
export {
|
|
4
|
+
export { requireTableAt, pgTableOf, getPrimaryKeys, deriveRowAddress, parseIdValues, buildCompositeId } from "./collection-helpers.js";
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { type SQL } from "drizzle-orm";
|
|
2
2
|
import { AnyPgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import { type
|
|
3
|
+
import { type ColumnDescriptor, type JoinStep } from "@rebasepro/types";
|
|
4
|
+
import { type RelationOfKind } from "@rebasepro/common";
|
|
4
5
|
import { DrizzleClient } from "../interfaces.js";
|
|
5
|
-
import {
|
|
6
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
6
7
|
/**
|
|
7
8
|
* Writing a many-to-many means writing rows in a junction table, and doing that
|
|
8
9
|
* needs three things: the table, the column naming the row being written from,
|
|
9
10
|
* and the column naming the far side.
|
|
10
11
|
*
|
|
11
12
|
* Those three used to be re-derived at each of the four call sites — twice for
|
|
12
|
-
* `through`, twice for `
|
|
13
|
-
* and the two
|
|
13
|
+
* `through`, twice for a `via` chain, in the owning and the inverse direction —
|
|
14
|
+
* and the two chain derivations did not agree. The inverse one keyed off
|
|
14
15
|
* `step.table`; the owning one asked `getTableNamesFromColumns` which table a
|
|
15
16
|
* step's columns belonged to, and that answers `""` for an unqualified column
|
|
16
17
|
* name. So for `{ table: "posts_tags", on: { from: "id", to: "tag_id" } }` —
|
|
@@ -38,11 +39,11 @@ export interface JunctionBinding {
|
|
|
38
39
|
/** `<collection>.<relation>`, for error messages. */
|
|
39
40
|
label: string;
|
|
40
41
|
/**
|
|
41
|
-
* The link's own columns — `through.
|
|
42
|
-
* junction that carries nothing but its two keys, and for every
|
|
43
|
-
* relation (a join chain has no declared payload).
|
|
42
|
+
* The link's own columns — the relation's `pivot` (`through.pivot`). Empty
|
|
43
|
+
* for a junction that carries nothing but its two keys, and for every
|
|
44
|
+
* `via` relation (a join chain has no declared payload).
|
|
44
45
|
*/
|
|
45
|
-
payload:
|
|
46
|
+
payload: readonly ColumnDescriptor[];
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* One element of a membership write: a target id, and optionally what the link
|
|
@@ -51,11 +52,11 @@ export interface JunctionBinding {
|
|
|
51
52
|
* The pivot is kept apart from the id rather than merged into a row shape,
|
|
52
53
|
* because the two are answered by different collections: the id is parsed
|
|
53
54
|
* against the *target's* primary key, the payload validated against the
|
|
54
|
-
*
|
|
55
|
+
* relation's `pivot` columns.
|
|
55
56
|
*/
|
|
56
57
|
export interface JunctionLinkWrite {
|
|
57
58
|
id: unknown;
|
|
58
|
-
/** Payload values keyed by
|
|
59
|
+
/** Payload values keyed by pivot column key, already serialized for the driver. */
|
|
59
60
|
pivot?: Record<string, unknown>;
|
|
60
61
|
}
|
|
61
62
|
/**
|
|
@@ -71,13 +72,8 @@ export interface VisibleTargets {
|
|
|
71
72
|
idColumn: AnyPgColumn;
|
|
72
73
|
condition: SQL;
|
|
73
74
|
}
|
|
74
|
-
/** The junction a `manyToMany` names outright. */
|
|
75
|
-
export declare function bindThroughJunction(registry:
|
|
76
|
-
table: string;
|
|
77
|
-
sourceColumn: string;
|
|
78
|
-
targetColumn: string;
|
|
79
|
-
properties?: Properties;
|
|
80
|
-
}, label: string): JunctionBinding;
|
|
75
|
+
/** The junction a `manyToMany` names outright (`through`). */
|
|
76
|
+
export declare function bindThroughJunction(registry: PostgresTableRegistry, relation: RelationOfKind<"manyToMany">, label: string): JunctionBinding;
|
|
81
77
|
/**
|
|
82
78
|
* The junction a `via` relation reaches through, from either end.
|
|
83
79
|
*
|
|
@@ -86,7 +82,7 @@ export declare function bindThroughJunction(registry: PostgresCollectionRegistry
|
|
|
86
82
|
* meaning is what makes the unqualified form work at all, so the walk carries
|
|
87
83
|
* the previous table rather than asking the column names where they live.
|
|
88
84
|
*/
|
|
89
|
-
export declare function bindJoinPathJunction(registry:
|
|
85
|
+
export declare function bindJoinPathJunction(registry: PostgresTableRegistry, joinPath: readonly JoinStep[], parentTableName: string, targetTableName: string, label: string): JunctionBinding;
|
|
90
86
|
/**
|
|
91
87
|
* Remove one link, leaving the row on the far side alone.
|
|
92
88
|
*
|
|
@@ -160,3 +156,26 @@ export declare function updateJunctionPivot(tx: DrizzleClient, binding: Junction
|
|
|
160
156
|
parent: string;
|
|
161
157
|
relation: string;
|
|
162
158
|
}): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* The link's own columns of one junction row, as this caller may read them —
|
|
161
|
+
* what an include serves under `_pivot`.
|
|
162
|
+
*
|
|
163
|
+
* Only the `pivot` columns: the two foreign keys are the link's identity, and
|
|
164
|
+
* the caller already has both. A column the caller may not read
|
|
165
|
+
* (`access.read`, `private`) is left out, as it is on any row; each value is
|
|
166
|
+
* served as REST serves it (`toRestScalar`).
|
|
167
|
+
*
|
|
168
|
+
* @param junctionRow The junction row, keyed as its catalogue table keys it.
|
|
169
|
+
*/
|
|
170
|
+
export declare function readPivotColumns(junctionRow: Record<string, unknown>, pivot: readonly ColumnDescriptor[]): Record<string, unknown>;
|
|
171
|
+
/**
|
|
172
|
+
* A link's `_pivot`, as the junction row's values.
|
|
173
|
+
*
|
|
174
|
+
* Every key must be a `pivot` column of the relation, and is refused
|
|
175
|
+
* otherwise (400) rather than dropped: a dropped `role` answers 200 for a
|
|
176
|
+
* write that changed nothing. A relation with no `pivot` has nothing to write
|
|
177
|
+
* under `_pivot` at all.
|
|
178
|
+
*
|
|
179
|
+
* @param label `<table>.<relation>`, named in the errors.
|
|
180
|
+
*/
|
|
181
|
+
export declare function serializePivot(pivot: Record<string, unknown>, columns: readonly ColumnDescriptor[], label: string): Record<string, unknown>;
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { RelationDescriptor } from "@rebasepro/types";
|
|
2
|
+
import { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
3
|
+
import type { RuntimeTable } from "../model/runtime-table.js";
|
|
3
4
|
/**
|
|
4
5
|
* The last hop of a nested collection path, e.g. `authors/1/posts`.
|
|
5
6
|
*
|
|
6
7
|
* The walk that produces this was written out four separate times — in
|
|
7
8
|
* `FetchService.fetchCollectionFromPath`, `FetchService.countEntitiesFromPath`,
|
|
8
|
-
* `PersistService.save` and
|
|
9
|
+
* `PersistService.save` and the registry's path lookup — and had
|
|
9
10
|
* drifted, so the read path and the write path did not agree on which relation
|
|
10
11
|
* a path named. It lives here once now.
|
|
11
12
|
*/
|
|
12
13
|
export interface NestedPathHop {
|
|
13
|
-
/** The
|
|
14
|
-
|
|
14
|
+
/** The table the final relation is declared on (e.g. `authors`). */
|
|
15
|
+
parent: RuntimeTable;
|
|
15
16
|
/** The parent's id as it appeared in the path, unparsed. */
|
|
16
17
|
parentId: string;
|
|
17
|
-
/** The path segment that named the relation (e.g. `posts`). */
|
|
18
|
+
/** The path segment that named the relation (e.g. `posts`): the relation's name. */
|
|
18
19
|
relationKey: string;
|
|
19
|
-
relation:
|
|
20
|
-
/** `relation.target
|
|
21
|
-
|
|
20
|
+
relation: RelationDescriptor;
|
|
21
|
+
/** The table the relation points at (`registry.requireTable(relation.target)`). */
|
|
22
|
+
target: RuntimeTable;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* True when `path` addresses rows through a relation rather than a root
|
|
@@ -39,13 +40,13 @@ export declare function splitPathSegments(path: string): string[];
|
|
|
39
40
|
* when a segment names a relation that does not exist — the same errors the
|
|
40
41
|
* individual walks used to raise, with the available names attached.
|
|
41
42
|
*/
|
|
42
|
-
export declare function resolveNestedPath(path: string, registry:
|
|
43
|
+
export declare function resolveNestedPath(path: string, registry: PostgresTableRegistry): NestedPathHop | undefined;
|
|
43
44
|
/**
|
|
44
|
-
* A relation reached through a junction table — many-to-many, or a
|
|
45
|
-
*
|
|
45
|
+
* A relation reached through a junction table — many-to-many, or a `via`
|
|
46
|
+
* chain. The target row is shared with other parents, so writing "through"
|
|
46
47
|
* such a path addresses the *link*, not the row.
|
|
47
48
|
*/
|
|
48
|
-
export declare function isJunctionBackedRelation(relation:
|
|
49
|
+
export declare function isJunctionBackedRelation(relation: RelationDescriptor): boolean;
|
|
49
50
|
/**
|
|
50
51
|
* Reject a create or update whose body names a relation Rebase does not write
|
|
51
52
|
* — a multi-hop `via`, or one whose step joins on either of several columns
|
|
@@ -57,12 +58,11 @@ export declare function isJunctionBackedRelation(relation: ResolvedRelation): bo
|
|
|
57
58
|
* RELATION_MISCONFIGURED telling the caller to regenerate a schema that was
|
|
58
59
|
* fine, and a to-one one re-pointed the target at the first step's column.
|
|
59
60
|
*
|
|
60
|
-
* Matched the
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* it — so it is not a write; `null` is, since it would unlink.
|
|
61
|
+
* Matched by the relation's own name, which is the key a body writes it
|
|
62
|
+
* under. An `undefined` value is no value — the transformer skips it — so it
|
|
63
|
+
* is not a write; `null` is, since it would unlink.
|
|
64
64
|
*/
|
|
65
|
-
export declare function assertNoReadOnlyRelationValues(values: Record<string, unknown>,
|
|
65
|
+
export declare function assertNoReadOnlyRelationValues(values: Record<string, unknown>, table: RuntimeTable): void;
|
|
66
66
|
/**
|
|
67
67
|
* Reject a nested write whose final segment is a to-one relation.
|
|
68
68
|
*
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
1
|
+
import type { FetchCollectionProps } from "@rebasepro/types";
|
|
2
|
+
import { type FieldViewer } from "@rebasepro/common";
|
|
3
|
+
import type { PostgresTableRegistry } from "../model/PostgresTableRegistry.js";
|
|
3
4
|
/**
|
|
4
|
-
* Refuse a read that names a
|
|
5
|
-
* take a driver-shaped request rather than a query string: the
|
|
6
|
-
* `FETCH_COLLECTION`, `COUNT` and `CHECK_UNIQUE_FIELD`,
|
|
7
|
-
*
|
|
5
|
+
* Refuse a read that names a column or relation its caller may not read, for
|
|
6
|
+
* the doors that take a driver-shaped request rather than a query string: the
|
|
7
|
+
* socket's `FETCH_COLLECTION`, `COUNT` and `CHECK_UNIQUE_FIELD`,
|
|
8
|
+
* `subscribe_collection`, and the driver's own read entry points for any read
|
|
9
|
+
* made on a caller's behalf (an in-process `context.data` under the caller's
|
|
10
|
+
* scope reaches no REST check). Callers hand it the request itself, not a
|
|
11
|
+
* re-listed copy of some of its keys.
|
|
12
|
+
*
|
|
13
|
+
* Every decision is the table descriptor's, through common's access helpers
|
|
14
|
+
* (the REST check's `assertQueryFieldsReadable`): a `.private()` column or
|
|
15
|
+
* relation is answered as a name the table does not have, an `.access({ read })`
|
|
16
|
+
* one the caller's roles do not satisfy is refused with `FIELD_NOT_READABLE`,
|
|
17
|
+
* and a withheld `belongsTo` takes its foreign key with it.
|
|
8
18
|
*
|
|
9
19
|
* The row strip keeps a withheld value off the wire; this is the other half, and
|
|
10
20
|
* without it the value is still readable one predicate at a time — a `COUNT`
|
|
@@ -16,4 +26,10 @@ import type { FieldViewer } from "@rebasepro/common";
|
|
|
16
26
|
* A malformed `orderBy` or `fields` is not this check's to reject; the entries
|
|
17
27
|
* that name a field are checked and the rest are left for the driver to refuse.
|
|
18
28
|
*/
|
|
19
|
-
export declare function assertReadRequestReadable(request: Pick<FetchCollectionProps, "filter" | "logical" | "orderBy" | "fields" | "include" | "vectorSearch">,
|
|
29
|
+
export declare function assertReadRequestReadable(request: Pick<FetchCollectionProps, "filter" | "logical" | "orderBy" | "fields" | "include" | "vectorSearch">,
|
|
30
|
+
/** The table read, by slug. */
|
|
31
|
+
read: {
|
|
32
|
+
slug: string;
|
|
33
|
+
}, viewer: FieldViewer,
|
|
34
|
+
/** Where the table's descriptor — and its relations' targets' — are read from. */
|
|
35
|
+
registry: Pick<PostgresTableRegistry, "relatedTables" | "requireTable">): void;
|