@rebasepro/server-postgres 0.30.0 → 0.31.0-canary.g59cd6fd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/README.md +11 -8
  2. package/dist/{BranchService-CrXvcES2.js → BranchService-USp1AvZB.js} +3 -3
  3. package/dist/{BranchService-CrXvcES2.js.map → BranchService-USp1AvZB.js.map} +1 -1
  4. package/dist/PostgresBackendDriver.d.ts +99 -54
  5. package/dist/PostgresBootstrapper.d.ts +12 -27
  6. package/dist/auth/ensure-tables.d.ts +16 -5
  7. package/dist/auth/schema-version.d.ts +2 -2
  8. package/dist/auth/services.d.ts +2 -3
  9. package/dist/{auth-users-columns-C72EMoDJ.js → auth-users-columns-BpfgbkxZ.js} +2 -16
  10. package/dist/auth-users-columns-BpfgbkxZ.js.map +1 -0
  11. package/dist/{backup-cli-CTKCOLpX.js → backup-cli-DbKyEj6c.js} +4 -4
  12. package/dist/{backup-cli-CTKCOLpX.js.map → backup-cli-DbKyEj6c.js.map} +1 -1
  13. package/dist/{boot-ddl-CqGIwSYx.js → boot-ddl-5H2bL_80.js} +2 -2
  14. package/dist/{boot-ddl-CqGIwSYx.js.map → boot-ddl-5H2bL_80.js.map} +1 -1
  15. package/dist/{cli-console-DBPw-oAz.js → cli-console-DsRgGSBR.js} +65 -39
  16. package/dist/cli-console-DsRgGSBR.js.map +1 -0
  17. package/dist/cli-console.d.ts +16 -13
  18. package/dist/cli-flags.d.ts +8 -9
  19. package/dist/cli-helpers.d.ts +15 -11
  20. package/dist/{cli-errors-DYTxnLbW.js → cli-schema-dir-CiN0ephV.js} +184 -70
  21. package/dist/cli-schema-dir-CiN0ephV.js.map +1 -0
  22. package/dist/cli-schema-dir.d.ts +64 -0
  23. package/dist/cli.js +192 -257
  24. package/dist/cli.js.map +1 -1
  25. package/dist/data-transformer.d.ts +50 -19
  26. package/dist/{database-preflight-iBpT7-vv.js → database-preflight-bfnIBnjM.js} +5 -5
  27. package/dist/database-preflight-bfnIBnjM.js.map +1 -0
  28. package/dist/{deferred-index-build-BCU9RoHK.js → deferred-index-build-CcSDA7wE.js} +69 -13
  29. package/dist/deferred-index-build-CcSDA7wE.js.map +1 -0
  30. package/dist/{ensure-collection-policies-Bo-_fDAy.js → ensure-policies-rRmXb5bt.js} +31 -31
  31. package/dist/ensure-policies-rRmXb5bt.js.map +1 -0
  32. package/dist/{ensure-collection-tables-DCJINkT_.js → ensure-tables-Bvm-F2wW.js} +44 -37
  33. package/dist/ensure-tables-Bvm-F2wW.js.map +1 -0
  34. package/dist/{ensure-tables-BPGaGh0y.js → ensure-tables-CC8p_AK3.js} +34 -29
  35. package/dist/ensure-tables-CC8p_AK3.js.map +1 -0
  36. package/dist/{enum-labels-kept-YAgOZS4I.js → enum-labels-kept-FlX9SHdf.js} +8 -8
  37. package/dist/enum-labels-kept-FlX9SHdf.js.map +1 -0
  38. package/dist/{generate-drizzle-schema-DcrFr7YX.js → generate-drizzle-schema-SJMXxzPI.js} +12 -12
  39. package/dist/generate-drizzle-schema-SJMXxzPI.js.map +1 -0
  40. package/dist/{generate-drizzle-schema-logic-LTLZvt6r.js → generate-drizzle-schema-logic-DL7R1rAF.js} +15 -8
  41. package/dist/generate-drizzle-schema-logic-DL7R1rAF.js.map +1 -0
  42. package/dist/{generate-files-CsaVzatS.js → generate-files-tlJ9_lGI.js} +23 -30
  43. package/dist/generate-files-tlJ9_lGI.js.map +1 -0
  44. package/dist/{generate-next-step-DgK5BlBn.js → generate-next-step-CO09dovd.js} +3 -3
  45. package/dist/generate-next-step-CO09dovd.js.map +1 -0
  46. package/dist/{generate-postgres-ddl-logic-Dg0bcENZ.js → generate-postgres-ddl-logic-B8huc03c.js} +51 -21
  47. package/dist/generate-postgres-ddl-logic-B8huc03c.js.map +1 -0
  48. package/dist/{generated-schema-diff-By4dxyTH.js → generated-schema-diff-DoT2dYDe.js} +297 -279
  49. package/dist/generated-schema-diff-DoT2dYDe.js.map +1 -0
  50. package/dist/{generated-schema-staleness-BvNF3i-s.js → generated-schema-staleness-YBVq2kTn.js} +21 -29
  51. package/dist/generated-schema-staleness-YBVq2kTn.js.map +1 -0
  52. package/dist/history/ensure-history-table.d.ts +22 -0
  53. package/dist/index.d.ts +8 -2
  54. package/dist/index.es.js +201 -25
  55. package/dist/index.es.js.map +1 -1
  56. package/dist/interfaces.d.ts +3 -4
  57. package/dist/{introspect-db-queries-DevUrzll.js → introspect-db-queries-BgiRQqtR.js} +7 -2
  58. package/dist/introspect-db-queries-BgiRQqtR.js.map +1 -0
  59. package/dist/introspect-tables-Cw_A-kk4.js +2086 -0
  60. package/dist/introspect-tables-Cw_A-kk4.js.map +1 -0
  61. package/dist/load-tables-B1Re74ng.js +92 -0
  62. package/dist/load-tables-B1Re74ng.js.map +1 -0
  63. package/dist/{migrate-baseline-CmWXL7qx.js → migrate-baseline-DZmekgpD.js} +19 -32
  64. package/dist/migrate-baseline-DZmekgpD.js.map +1 -0
  65. package/dist/{migrate-policy-stamps-BN_Qad6c.js → migrate-policy-stamps-B_acrUQB.js} +18 -19
  66. package/dist/migrate-policy-stamps-B_acrUQB.js.map +1 -0
  67. package/dist/model/PostgresTableRegistry.d.ts +159 -0
  68. package/dist/model/build-registry.d.ts +25 -0
  69. package/dist/model/refresh-relational-schema.d.ts +24 -0
  70. package/dist/model/runtime-table.d.ts +53 -0
  71. package/dist/{collections → model}/validate-relations.d.ts +15 -21
  72. package/dist/{open-rebase-40paQfVW.js → open-rebase-4kisUF_k.js} +3946 -3870
  73. package/dist/open-rebase-4kisUF_k.js.map +1 -0
  74. package/dist/open-rebase.d.ts +16 -15
  75. package/dist/{pg-error-utils-DJHjCF7-.js → pg-error-utils-BT5NzGFZ.js} +17 -20
  76. package/dist/pg-error-utils-BT5NzGFZ.js.map +1 -0
  77. package/dist/plan-schema-Hbtjhge3.js +1633 -0
  78. package/dist/plan-schema-Hbtjhge3.js.map +1 -0
  79. package/dist/{policy-drift-C-m0uWHH.js → policy-drift-BVMyqHSa.js} +29 -29
  80. package/dist/policy-drift-BVMyqHSa.js.map +1 -0
  81. package/dist/{push-index-adoption-Cp7oZxSl.js → push-index-adoption-hpHTyXMR.js} +7 -7
  82. package/dist/push-index-adoption-hpHTyXMR.js.map +1 -0
  83. package/dist/{push-index-prebuild-DbwKGtQT.js → push-index-prebuild-Bty9F7bD.js} +6 -6
  84. package/dist/push-index-prebuild-Bty9F7bD.js.map +1 -0
  85. package/dist/{push-kept-defaults-CLcgsEPt.js → push-kept-defaults-Bst4MDup.js} +13 -16
  86. package/dist/push-kept-defaults-Bst4MDup.js.map +1 -0
  87. package/dist/{push-legacy-renames-BthD0E9W.js → push-legacy-renames-bB4bM6br.js} +6 -6
  88. package/dist/push-legacy-renames-bB4bM6br.js.map +1 -0
  89. package/dist/{push-policy-plan-BgcrroxQ.js → push-policy-plan-BI8U4BOD.js} +11 -11
  90. package/dist/push-policy-plan-BI8U4BOD.js.map +1 -0
  91. package/dist/{render-ddl-Ci3S_SoI.js → render-ddl-D4n86NHz.js} +14 -7
  92. package/dist/render-ddl-D4n86NHz.js.map +1 -0
  93. package/dist/{request-role-cli-Dy1EgJU9.js → request-role-cli-BdRzdE87.js} +11 -11
  94. package/dist/{request-role-cli-Dy1EgJU9.js.map → request-role-cli-BdRzdE87.js.map} +1 -1
  95. package/dist/{request-role-migration-GHTJnPMV.js → request-role-migration-C8aq_TO3.js} +2 -2
  96. package/dist/{request-role-migration-GHTJnPMV.js.map → request-role-migration-C8aq_TO3.js.map} +1 -1
  97. package/dist/{rls-enforcement-Cc_UhOxb.js → rls-enforcement-DB5HHj96.js} +19 -19
  98. package/dist/rls-enforcement-DB5HHj96.js.map +1 -0
  99. package/dist/{rls-settings-BCGMIig3.js → rls-settings-CmGK2U0a.js} +2 -2
  100. package/dist/rls-settings-CmGK2U0a.js.map +1 -0
  101. package/dist/schema/auth-users-columns.d.ts +1 -11
  102. package/dist/schema/catalogue-schema.d.ts +33 -29
  103. package/dist/schema/classify-change.d.ts +23 -16
  104. package/dist/schema/column-type-drift.d.ts +16 -0
  105. package/dist/schema/config-relations.d.ts +10 -9
  106. package/dist/schema/deferred-index-build.d.ts +1 -1
  107. package/dist/schema/doctor-cli.js +1544 -66
  108. package/dist/schema/doctor-cli.js.map +1 -1
  109. package/dist/schema/doctor-database.d.ts +7 -7
  110. package/dist/schema/doctor-policy-checks.d.ts +4 -4
  111. package/dist/schema/doctor-search-scale.d.ts +14 -14
  112. package/dist/schema/doctor.d.ts +27 -27
  113. package/dist/schema/dynamic-tables.d.ts +6 -5
  114. package/dist/schema/{ensure-collection-policies.d.ts → ensure-policies.d.ts} +20 -20
  115. package/dist/schema/{ensure-collection-tables.d.ts → ensure-tables.d.ts} +11 -11
  116. package/dist/schema/enum-labels-kept.d.ts +6 -6
  117. package/dist/schema/generate-drizzle-schema-logic.d.ts +3 -3
  118. package/dist/schema/generate-drizzle-schema.js +1 -1
  119. package/dist/schema/generate-files.d.ts +6 -6
  120. package/dist/schema/generate-postgres-ddl-logic.d.ts +23 -20
  121. package/dist/schema/generate-postgres-ddl.js +11 -11
  122. package/dist/schema/generate-postgres-ddl.js.map +1 -1
  123. package/dist/schema/generate-schema-commit.d.ts +13 -8
  124. package/dist/schema/generated-schema-diff.d.ts +16 -16
  125. package/dist/schema/generated-schema-staleness.d.ts +11 -11
  126. package/dist/schema/index-adoption.d.ts +4 -4
  127. package/dist/schema/introspect-db-customization.d.ts +47 -0
  128. package/dist/schema/introspect-db-inference.d.ts +30 -9
  129. package/dist/schema/introspect-db-logic.d.ts +79 -110
  130. package/dist/schema/introspect-db-project.d.ts +15 -18
  131. package/dist/schema/introspect-db-queries.d.ts +1 -1
  132. package/dist/schema/introspect-db-search.d.ts +25 -4
  133. package/dist/schema/introspect-db-storage.d.ts +4 -74
  134. package/dist/schema/introspect-db.js +102 -90
  135. package/dist/schema/introspect-db.js.map +1 -1
  136. package/dist/schema/introspect-runtime.d.ts +47 -36
  137. package/dist/schema/introspect-tables.d.ts +182 -0
  138. package/dist/schema/load-tables.d.ts +55 -0
  139. package/dist/schema/migrate-policy-stamps.d.ts +4 -4
  140. package/dist/schema/migration-freshness.d.ts +13 -13
  141. package/dist/schema/plan/column-order.d.ts +82 -0
  142. package/dist/schema/plan/diff-plan.d.ts +9 -3
  143. package/dist/schema/plan/plan-schema.d.ts +55 -52
  144. package/dist/schema/plan/render-drizzle.d.ts +1 -1
  145. package/dist/schema/plan/types.d.ts +24 -15
  146. package/dist/schema/push-index-adoption.d.ts +3 -3
  147. package/dist/schema/push-index-prebuild.d.ts +3 -3
  148. package/dist/schema/push-kept-defaults.d.ts +7 -7
  149. package/dist/schema/push-legacy-renames.d.ts +3 -3
  150. package/dist/schema/push-policy-plan.d.ts +5 -5
  151. package/dist/schema/reconcile-schema.d.ts +5 -5
  152. package/dist/schema/relation-names.d.ts +15 -20
  153. package/dist/schema/render-outputs.d.ts +76 -0
  154. package/dist/schema/search-column.d.ts +11 -43
  155. package/dist/schema/{collection-index.d.ts → table-index.d.ts} +21 -42
  156. package/dist/schema/{collections-schema-version.d.ts → tables-schema-version.d.ts} +8 -2
  157. package/dist/schema/vector-index.d.ts +24 -28
  158. package/dist/{search-column-BM-GV6vH.js → search-column-BO-WND-B.js} +86 -149
  159. package/dist/search-column-BO-WND-B.js.map +1 -0
  160. package/dist/security/caller-sql-columns.d.ts +9 -6
  161. package/dist/security/policy-drift.d.ts +14 -14
  162. package/dist/security/rls-enforcement.d.ts +19 -25
  163. package/dist/security/rls-settings.d.ts +2 -2
  164. package/dist/security/served-table-protection.d.ts +125 -0
  165. package/dist/services/FetchService.d.ts +22 -133
  166. package/dist/services/PersistService.d.ts +6 -17
  167. package/dist/services/RelationService.d.ts +57 -106
  168. package/dist/services/RelationWriteService.d.ts +59 -66
  169. package/dist/services/cdc/identity-columns.d.ts +7 -5
  170. package/dist/services/cdc/junction-tables.d.ts +14 -14
  171. package/dist/services/collection-helpers.d.ts +52 -95
  172. package/dist/services/dataService.d.ts +15 -12
  173. package/dist/services/field-op-sql.d.ts +11 -9
  174. package/dist/services/field-viewer.d.ts +12 -11
  175. package/dist/services/hidden-columns.d.ts +30 -0
  176. package/dist/services/index.d.ts +1 -1
  177. package/dist/services/junction-writes.d.ts +37 -18
  178. package/dist/services/nested-path.d.ts +18 -18
  179. package/dist/services/read-field-access.d.ts +23 -7
  180. package/dist/services/read-scope.d.ts +10 -9
  181. package/dist/services/realtimeService.d.ts +25 -10
  182. package/dist/services/relation-tables.d.ts +97 -0
  183. package/dist/services/row-pipeline.d.ts +50 -69
  184. package/dist/services/soft-delete.d.ts +25 -24
  185. package/dist/services/table-hooks.d.ts +146 -0
  186. package/dist/services/view-access.d.ts +7 -7
  187. package/dist/services/write-transaction-scope.d.ts +1 -1
  188. package/dist/{source-fZb92pN8.js → source-VxbrQojV.js} +111 -79
  189. package/dist/source-VxbrQojV.js.map +1 -0
  190. package/dist/{collections-schema-version-D7bDI0PJ.js → tables-schema-version-YvZIBlOP.js} +12 -6
  191. package/dist/tables-schema-version-YvZIBlOP.js.map +1 -0
  192. package/dist/utils/drizzle-conditions.d.ts +70 -84
  193. package/dist/utils/pg-array-null-patch.d.ts +27 -10
  194. package/dist/utils/pg-error-utils.d.ts +4 -4
  195. package/dist/{vector-index-DsQ3V2d2.js → vector-index-VSh3ufTd.js} +62 -54
  196. package/dist/vector-index-VSh3ufTd.js.map +1 -0
  197. package/dist/{websocket-B7ex6AQM.js → websocket-BevXvwfo.js} +51 -40
  198. package/dist/websocket-BevXvwfo.js.map +1 -0
  199. package/dist/websocket.d.ts +2 -2
  200. package/package.json +7 -7
  201. package/dist/auth-users-columns-C72EMoDJ.js.map +0 -1
  202. package/dist/cli-collections-path.d.ts +0 -31
  203. package/dist/cli-console-DBPw-oAz.js.map +0 -1
  204. package/dist/cli-errors-DYTxnLbW.js.map +0 -1
  205. package/dist/collections/PostgresCollectionRegistry.d.ts +0 -47
  206. package/dist/collections/buildRegistry.d.ts +0 -27
  207. package/dist/collections-schema-version-D7bDI0PJ.js.map +0 -1
  208. package/dist/column-plan-helpers-BeSztMor.js +0 -161
  209. package/dist/column-plan-helpers-BeSztMor.js.map +0 -1
  210. package/dist/database-preflight-iBpT7-vv.js.map +0 -1
  211. package/dist/deferred-index-build-BCU9RoHK.js.map +0 -1
  212. package/dist/doctor-Kg1oUK0Q.js +0 -1458
  213. package/dist/doctor-Kg1oUK0Q.js.map +0 -1
  214. package/dist/ensure-collection-policies-Bo-_fDAy.js.map +0 -1
  215. package/dist/ensure-collection-tables-DCJINkT_.js.map +0 -1
  216. package/dist/ensure-tables-BPGaGh0y.js.map +0 -1
  217. package/dist/enum-labels-kept-YAgOZS4I.js.map +0 -1
  218. package/dist/generate-drizzle-schema-DcrFr7YX.js.map +0 -1
  219. package/dist/generate-drizzle-schema-logic-LTLZvt6r.js.map +0 -1
  220. package/dist/generate-files-CsaVzatS.js.map +0 -1
  221. package/dist/generate-next-step-DgK5BlBn.js.map +0 -1
  222. package/dist/generate-postgres-ddl-logic-Dg0bcENZ.js.map +0 -1
  223. package/dist/generated-schema-diff-By4dxyTH.js.map +0 -1
  224. package/dist/generated-schema-staleness-BvNF3i-s.js.map +0 -1
  225. package/dist/introspect-db-logic-DWqAEURB.js +0 -2047
  226. package/dist/introspect-db-logic-DWqAEURB.js.map +0 -1
  227. package/dist/introspect-db-queries-DevUrzll.js.map +0 -1
  228. package/dist/migrate-baseline-CmWXL7qx.js.map +0 -1
  229. package/dist/migrate-policy-stamps-BN_Qad6c.js.map +0 -1
  230. package/dist/open-rebase-40paQfVW.js.map +0 -1
  231. package/dist/pg-error-utils-DJHjCF7-.js.map +0 -1
  232. package/dist/plan-schema-vJd3UEmT.js +0 -1604
  233. package/dist/plan-schema-vJd3UEmT.js.map +0 -1
  234. package/dist/policy-drift-C-m0uWHH.js.map +0 -1
  235. package/dist/push-index-adoption-Cp7oZxSl.js.map +0 -1
  236. package/dist/push-index-prebuild-DbwKGtQT.js.map +0 -1
  237. package/dist/push-kept-defaults-CLcgsEPt.js.map +0 -1
  238. package/dist/push-legacy-renames-BthD0E9W.js.map +0 -1
  239. package/dist/push-policy-plan-BgcrroxQ.js.map +0 -1
  240. package/dist/render-ddl-Ci3S_SoI.js.map +0 -1
  241. package/dist/rls-enforcement-Cc_UhOxb.js.map +0 -1
  242. package/dist/rls-settings-BCGMIig3.js.map +0 -1
  243. package/dist/schema/column-plan-helpers.d.ts +0 -161
  244. package/dist/schema/introspect-db-naming.d.ts +0 -10
  245. package/dist/search-column-BM-GV6vH.js.map +0 -1
  246. package/dist/source-fZb92pN8.js.map +0 -1
  247. package/dist/vector-index-DsQ3V2d2.js.map +0 -1
  248. 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 { CollectionConfig, ResolvedHasMany, ResolvedHasOne } from "@rebasepro/types";
4
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
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
- * `PostgresCollectionRegistry` instance — there is no global singleton.
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
- * {@link getPrimaryKeys} lets a config's `isId: "uuid"` win over the schema, so
31
- * its `isUUID` is a claim rather than a fact — right for deriving addresses,
32
- * wrong for refusing a query. Here the Drizzle column type decides, because it
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
- export declare function getCollectionByPath(collectionPath: string, registry: PostgresCollectionRegistry): CollectionConfig;
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 key columns a collection's rows are addressed by.
101
- *
102
- * Three tiers, in order: properties marked `isId`, the primary keys of the
103
- * registered table, and finally a column literally named `id`. Only the first is
104
- * visible to the browser, which is why a key known only to the table is reported
105
- * at boot — see {@link warnOnKeysTheAdminCannotResolve}.
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 second tier reads the table the registry holds, which is built from
108
- * `information_schema` — the database's own primary key, not a generated file's
109
- * claim about it. Composite keys are declared as a table constraint rather than
110
- * on each column (that is the only legal way to say it), so both shapes are
111
- * asked for.
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
- * Returns `[]` when nothing resolves, rather than throwing. It used to open by
114
- * resolving the table, which throws when there is none — so the `isId` tier,
115
- * which needs no table at all, was unreachable for exactly the collections
116
- * most likely to have no table registered. Every caller that wanted "no keys"
117
- * to mean "no keys" had to spell that out in a try/catch.
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
- * Callers that cannot proceed without a key must say so themselves, naming the
120
- * collection: an empty array here means "this collection has no address", which
121
- * is a different answer in a notification (broadcast a wildcard) than in a save
122
- * (fail).
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 getPrimaryKeys(collection: CollectionConfig, registry: PostgresCollectionRegistry): PrimaryKeyInfo[];
139
+ export declare function requireTableKeys(table: RuntimeTable, pg?: PgTable | undefined): PrimaryKeyInfo[];
125
140
  /**
126
- * The key columns, for callers that cannot do their job without one.
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
- * collection with no address. Most of this driver, though, is building a WHERE
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(collection: CollectionConfig, registry: PostgresCollectionRegistry): PrimaryKeyInfo[];
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 column on the *source* table that a `hasOne`/`hasMany` link points at.
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>, collection: CollectionConfig, registry: PostgresCollectionRegistry,
244
- /** The collection's keys, when the caller already has them — a batch derives one address per row. */
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 { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
10
- export { sanitizeAndConvertDates, serializeDataToServer, parseDataFromServer } from "../data-transformer.js";
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: PostgresCollectionRegistry,
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
- * Fetch a single row by ID
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
- * Fetch a collection of rows with optional filtering, ordering, and pagination
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["fetchCollection"]>[1]): Promise<Record<string, unknown>[]>;
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
- * Exposed on the facade because it is what *every* consumer should be
61
- * reading through. The realtime refetch used to go via `fetchCollection`
62
- * above, which nests a relation under a `{ __type: "relation" }` envelope
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
- * Search rows by text
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 { Properties } from "@rebasepro/types";
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 property key; it is already known to be a column of `table`
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 property key. */
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: { validation: { min: 0 } }` is refused before the
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`, `moreThan`, `lessThan`,
58
- * `positive` and `negative`, an array's `min` and `max` items. `integer` is not
59
- * here: a whole increment of a whole number stays whole, and the request
60
- * already refuses a fractional one. `$merge` has no bounds to hold.
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>, properties: Properties, context: {
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 { CollectionConfig } from "@rebasepro/types";
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 `collection`: its
23
- * `excludeFromApi` fields, in every spelling. Empty on the trusted server plane
24
- * (no viewer), which may filter and sort on those columns — the auth adapter
25
- * looks rows up by them — and empty with no collection in hand.
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. The REST check passes such a name through to this
29
- * driver rather than refusing it itself, so the two answers come from one throw
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(collection: CollectionConfig | undefined): ReadonlySet<string>;
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;
@@ -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 { getCollectionByPath, getTableForCollection, getPrimaryKeys, deriveRowAddress, parseIdValues, buildCompositeId } from "./collection-helpers.js";
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 Properties, type ResolvedVia } from "@rebasepro/types";
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 { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
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 `joinPath`, in the owning and the inverse direction —
13
- * and the two `joinPath` derivations did not agree. The inverse one keyed off
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.properties` — as authored. Empty for a
42
- * junction that carries nothing but its two keys, and for every `via`
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: Properties;
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
- * junction's own properties.
55
+ * relation's `pivot` columns.
55
56
  */
56
57
  export interface JunctionLinkWrite {
57
58
  id: unknown;
58
- /** Payload values keyed by property key, already serialized for the driver. */
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: PostgresCollectionRegistry, through: {
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: PostgresCollectionRegistry, joinPath: ResolvedVia["joinPath"], parentTableName: string, targetTableName: string, label: string): JunctionBinding;
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 { CollectionConfig, ResolvedRelation } from "@rebasepro/types";
2
- import { PostgresCollectionRegistry } from "../collections/PostgresCollectionRegistry.js";
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 `CollectionRegistry.getCollectionByPath` — and had
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 collection the final relation is declared on (e.g. `authors`). */
14
- parentCollection: CollectionConfig;
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: ResolvedRelation;
20
- /** `relation.target()`, resolved once. */
21
- targetCollection: CollectionConfig;
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: PostgresCollectionRegistry): NestedPathHop | undefined;
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 multi-hop
45
- * `joinPath`. The target row is shared with other parents, so writing "through"
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: ResolvedRelation): boolean;
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 way the write path matches: a key that is a relation's own name
61
- * (the to-many split), or a `relation` property that resolves to one (the
62
- * to-one transformer). An `undefined` value is no value — the transformer skips
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>, collection: CollectionConfig): void;
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 { CollectionConfig, FetchCollectionProps } from "@rebasepro/types";
2
- import type { FieldViewer } from "@rebasepro/common";
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 field its caller may not read, for the doors that
5
- * take a driver-shaped request rather than a query string: the socket's
6
- * `FETCH_COLLECTION`, `COUNT` and `CHECK_UNIQUE_FIELD`, and `subscribe_collection`.
7
- * Callers hand it the request itself, not a re-listed copy of some of its keys.
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">, collection: CollectionConfig, viewer: FieldViewer): void;
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;