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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +1 @@
1
- {"version":3,"file":"generate-postgres-ddl.js","names":[],"sources":["../../src/schema/generate-postgres-ddl.ts","../../src/schema/bin/generate-postgres-ddl.ts"],"sourcesContent":["import path from \"path\";\nimport { out } from \"../cli-output\";\nimport { writePostgresDdl } from \"./generate-files\";\n\n/**\n * The generator as its own process — what `--watch` runs, because a watch has\n * to re-import the collections on every save and Node's module cache would\n * serve it the first version forever. One-shot generation runs in the driver's\n * own process instead; see `generate-files.ts`.\n */\nconst runGeneration = async (collectionsFilePath?: string, outputPath?: string) => {\n if (!collectionsFilePath) {\n throw new Error(\"No collections file path provided.\");\n }\n try {\n await writePostgresDdl({ collectionsPath: path.resolve(collectionsFilePath), outputPath });\n } catch (error) {\n // A caller that reads nothing but this process's exit code must not\n // see 0 after an error was printed — see `writePostgresDdl`.\n process.exitCode = 1;\n throw error;\n }\n};\n\nexport const main = async () => {\n const collectionsFilePathArg = process.argv.find(arg => arg.startsWith(\"--collections=\"));\n const collectionsFilePath = collectionsFilePathArg ? collectionsFilePathArg.split(\"=\")[1] : process.argv[2];\n\n const outputPathArg = process.argv.find(arg => arg.startsWith(\"--output=\"));\n const outputPath = outputPathArg ? outputPathArg.split(\"=\")[1] : undefined;\n\n const watch = process.argv.includes(\"--watch\");\n\n if (!collectionsFilePath) {\n out(\"Usage: ts-node generate-postgres-ddl.ts <path-to-collections-file> [--output <path-to-output-file>] [--watch]\");\n return;\n }\n\n const resolvedPath = path.resolve(process.cwd(), collectionsFilePath);\n const resolvedOutputPath = outputPath ? path.resolve(process.cwd(), outputPath) : undefined;\n\n if (watch) {\n out(`Watching for changes in ${resolvedPath}...`);\n // Imported here rather than at module scope, and this is not a style\n // choice: chokidar is needed only by `--watch`, which is a\n // schema-authoring path that never runs inside the runtime image. A\n // top-level import puts it on the boot path of the published driver\n // bundle, and the image installs a hand-listed set of runtime\n // dependencies that does not include it — so the whole driver failed to\n // load with \"Cannot find package 'chokidar'\", and every self-hosted\n // container answered 500 with a stack trace about a file watcher.\n //\n // Same reasoning the image already applies to @ariga/atlas: an\n // authoring-only dependency does not belong on a boot path.\n const { default: chokidar } = await import(\"chokidar\");\n const watcher = chokidar.watch(resolvedPath, {\n persistent: true,\n ignoreInitial: false\n });\n\n watcher.on(\"all\", (event, filePath) => {\n out(`[${event}] ${filePath}. Regenerating DDL schema...`);\n // A watch session outlives a bad edit: the cause is already on\n // stderr, and the next save is the retry. Only the one-shot run\n // below turns a failure into an exit code.\n void runGeneration(resolvedPath, resolvedOutputPath).catch(() => undefined);\n });\n } else {\n await runGeneration(resolvedPath, resolvedOutputPath);\n }\n};\n\n// This check ensures the script only runs when executed directly\nif (import.meta.url.endsWith(process.argv[1])) {\n // `runGeneration` has already printed the cause and set the exit code; the\n // handler is here so the last thing on the terminal is that message rather\n // than Node's unhandled-rejection dump of the same stack.\n main().catch(() => {\n process.exitCode = 1;\n });\n}\n","/**\n * The built entry point for `generate-postgres-ddl`.\n *\n * `generate-postgres-ddl.ts` guards its own `main()` with\n * `import.meta.url.endsWith(process.argv[1])`, because `src/index.ts` re-exports\n * the module and importing the driver must not run the generator. That guard is\n * correct when the file IS the process entry — which is how it runs from source\n * under tsx — and silently false once the module is bundled: the executed file\n * is a stub, the code lives in a shared chunk, and the chunk's `import.meta.url`\n * is not the stub's path. The generator then did nothing, exited 0, and the\n * caller reported success over an unwritten schema.\n *\n * So the built path gets an entry that says what it means.\n */\nimport { main } from \"../generate-postgres-ddl\";\n\nmain().catch(() => {\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;;;AAUA,IAAM,gBAAgB,OAAO,qBAA8B,eAAwB;CAC/E,IAAI,CAAC,qBACD,MAAM,IAAI,MAAM,oCAAoC;CAExD,IAAI;EACA,MAAM,iBAAiB;GAAE,iBAAiB,KAAK,QAAQ,mBAAmB;GAAG;EAAW,CAAC;CAC7F,SAAS,OAAO;EAGZ,QAAQ,WAAW;EACnB,MAAM;CACV;AACJ;AAEA,IAAa,OAAO,YAAY;CAC5B,MAAM,yBAAyB,QAAQ,KAAK,MAAK,QAAO,IAAI,WAAW,gBAAgB,CAAC;CACxF,MAAM,sBAAsB,yBAAyB,uBAAuB,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,KAAK;CAEzG,MAAM,gBAAgB,QAAQ,KAAK,MAAK,QAAO,IAAI,WAAW,WAAW,CAAC;CAC1E,MAAM,aAAa,gBAAgB,cAAc,MAAM,GAAG,CAAC,CAAC,KAAK,KAAA;CAEjE,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS;CAE7C,IAAI,CAAC,qBAAqB;EACtB,IAAI,+GAA+G;EACnH;CACJ;CAEA,MAAM,eAAe,KAAK,QAAQ,QAAQ,IAAI,GAAG,mBAAmB;CACpE,MAAM,qBAAqB,aAAa,KAAK,QAAQ,QAAQ,IAAI,GAAG,UAAU,IAAI,KAAA;CAElF,IAAI,OAAO;EACP,IAAI,2BAA2B,aAAa,IAAI;EAYhD,MAAM,EAAE,SAAS,aAAa,MAAM,OAAO;EAM3C,SALyB,MAAM,cAAc;GACzC,YAAY;GACZ,eAAe;EACnB,CAEA,CAAA,CAAQ,GAAG,QAAQ,OAAO,aAAa;GACnC,IAAI,IAAI,MAAM,IAAI,SAAS,6BAA6B;GAIxD,cAAmB,cAAc,kBAAkB,CAAC,CAAC,YAAY,KAAA,CAAS;EAC9E,CAAC;CACL,OACI,MAAM,cAAc,cAAc,kBAAkB;AAE5D;AAGA,IAAI,OAAO,KAAK,IAAI,SAAS,QAAQ,KAAK,EAAE,GAIxC,KAAK,CAAC,CAAC,YAAY;CACf,QAAQ,WAAW;AACvB,CAAC;;;;;;;;;;;;;;;;;AC/DL,KAAK,CAAC,CAAC,YAAY;CACf,QAAQ,WAAW;AACvB,CAAC"}
1
+ {"version":3,"file":"generate-postgres-ddl.js","names":[],"sources":["../../src/schema/generate-postgres-ddl.ts","../../src/schema/bin/generate-postgres-ddl.ts"],"sourcesContent":["import path from \"path\";\nimport { out } from \"../cli-output\";\nimport { writePostgresDdl } from \"./generate-files\";\n\n/**\n * The generator as its own process — what `--watch` runs, because a watch has\n * to re-import the tables on every save and Node's module cache would\n * serve it the first version forever. One-shot generation runs in the driver's\n * own process instead; see `generate-files.ts`.\n */\nconst runGeneration = async (schemaDir?: string, outputPath?: string) => {\n if (!schemaDir) {\n throw new Error(\"No schema directory provided.\");\n }\n try {\n await writePostgresDdl({ schemaDir: path.resolve(schemaDir), outputPath });\n } catch (error) {\n // A caller that reads nothing but this process's exit code must not\n // see 0 after an error was printed — see `writePostgresDdl`.\n process.exitCode = 1;\n throw error;\n }\n};\n\nexport const main = async () => {\n const schemaDirArg = process.argv.find(arg => arg.startsWith(\"--schema-dir=\"));\n const schemaDir = schemaDirArg ? schemaDirArg.split(\"=\")[1] : process.argv[2];\n\n const outputPathArg = process.argv.find(arg => arg.startsWith(\"--output=\"));\n const outputPath = outputPathArg ? outputPathArg.split(\"=\")[1] : undefined;\n\n const watch = process.argv.includes(\"--watch\");\n\n if (!schemaDir) {\n out(\"Usage: ts-node generate-postgres-ddl.ts --schema-dir=<backend/schema> [--output=<path-to-output-file>] [--watch]\");\n return;\n }\n\n const resolvedPath = path.resolve(process.cwd(), schemaDir);\n const resolvedOutputPath = outputPath ? path.resolve(process.cwd(), outputPath) : undefined;\n\n if (watch) {\n out(`Watching for changes in ${resolvedPath}...`);\n // Imported here rather than at module scope, and this is not a style\n // choice: chokidar is needed only by `--watch`, which is a\n // schema-authoring path that never runs inside the runtime image. A\n // top-level import puts it on the boot path of the published driver\n // bundle, and the image installs a hand-listed set of runtime\n // dependencies that does not include it — so the whole driver failed to\n // load with \"Cannot find package 'chokidar'\", and every self-hosted\n // container answered 500 with a stack trace about a file watcher.\n //\n // Same reasoning the image already applies to @ariga/atlas: an\n // authoring-only dependency does not belong on a boot path.\n const { default: chokidar } = await import(\"chokidar\");\n const watcher = chokidar.watch(resolvedPath, {\n persistent: true,\n ignoreInitial: false\n });\n\n watcher.on(\"all\", (event, filePath) => {\n out(`[${event}] ${filePath}. Regenerating DDL schema...`);\n // A watch session outlives a bad edit: the cause is already on\n // stderr, and the next save is the retry. Only the one-shot run\n // below turns a failure into an exit code.\n void runGeneration(resolvedPath, resolvedOutputPath).catch(() => undefined);\n });\n } else {\n await runGeneration(resolvedPath, resolvedOutputPath);\n }\n};\n\n// This check ensures the script only runs when executed directly\nif (import.meta.url.endsWith(process.argv[1])) {\n // `runGeneration` has already printed the cause and set the exit code; the\n // handler is here so the last thing on the terminal is that message rather\n // than Node's unhandled-rejection dump of the same stack.\n main().catch(() => {\n process.exitCode = 1;\n });\n}\n","/**\n * The built entry point for `generate-postgres-ddl`.\n *\n * `generate-postgres-ddl.ts` guards its own `main()` with\n * `import.meta.url.endsWith(process.argv[1])`, because `src/index.ts` re-exports\n * the module and importing the driver must not run the generator. That guard is\n * correct when the file IS the process entry — which is how it runs from source\n * under tsx — and silently false once the module is bundled: the executed file\n * is a stub, the code lives in a shared chunk, and the chunk's `import.meta.url`\n * is not the stub's path. The generator then did nothing, exited 0, and the\n * caller reported success over an unwritten schema.\n *\n * So the built path gets an entry that says what it means.\n */\nimport { main } from \"../generate-postgres-ddl\";\n\nmain().catch(() => {\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;;;AAUA,IAAM,gBAAgB,OAAO,WAAoB,eAAwB;CACrE,IAAI,CAAC,WACD,MAAM,IAAI,MAAM,+BAA+B;CAEnD,IAAI;EACA,MAAM,iBAAiB;GAAE,WAAW,KAAK,QAAQ,SAAS;GAAG;EAAW,CAAC;CAC7E,SAAS,OAAO;EAGZ,QAAQ,WAAW;EACnB,MAAM;CACV;AACJ;AAEA,IAAa,OAAO,YAAY;CAC5B,MAAM,eAAe,QAAQ,KAAK,MAAK,QAAO,IAAI,WAAW,eAAe,CAAC;CAC7E,MAAM,YAAY,eAAe,aAAa,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,KAAK;CAE3E,MAAM,gBAAgB,QAAQ,KAAK,MAAK,QAAO,IAAI,WAAW,WAAW,CAAC;CAC1E,MAAM,aAAa,gBAAgB,cAAc,MAAM,GAAG,CAAC,CAAC,KAAK,KAAA;CAEjE,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS;CAE7C,IAAI,CAAC,WAAW;EACZ,IAAI,kHAAkH;EACtH;CACJ;CAEA,MAAM,eAAe,KAAK,QAAQ,QAAQ,IAAI,GAAG,SAAS;CAC1D,MAAM,qBAAqB,aAAa,KAAK,QAAQ,QAAQ,IAAI,GAAG,UAAU,IAAI,KAAA;CAElF,IAAI,OAAO;EACP,IAAI,2BAA2B,aAAa,IAAI;EAYhD,MAAM,EAAE,SAAS,aAAa,MAAM,OAAO;EAM3C,SALyB,MAAM,cAAc;GACzC,YAAY;GACZ,eAAe;EACnB,CAEA,CAAA,CAAQ,GAAG,QAAQ,OAAO,aAAa;GACnC,IAAI,IAAI,MAAM,IAAI,SAAS,6BAA6B;GAIxD,cAAmB,cAAc,kBAAkB,CAAC,CAAC,YAAY,KAAA,CAAS;EAC9E,CAAC;CACL,OACI,MAAM,cAAc,cAAc,kBAAkB;AAE5D;AAGA,IAAI,OAAO,KAAK,IAAI,SAAS,QAAQ,KAAK,EAAE,GAIxC,KAAK,CAAC,CAAC,YAAY;CACf,QAAQ,WAAW;AACvB,CAAC;;;;;;;;;;;;;;;;;AC/DL,KAAK,CAAC,CAAC,YAAY;CACf,QAAQ,WAAW;AACvB,CAAC"}
@@ -37,9 +37,9 @@
37
37
  * migration this module cannot make valid would be worse than handing the
38
38
  * statements to a caller who knows which kind of project it is.
39
39
  */
40
- import { type CollectionConfig, type SchemaCommitPaths } from "@rebasepro/types";
41
- import { type EnsureOptions, type ExistingSchema, type WithheldConstraint } from "./ensure-collection-tables.js";
42
- import { type ClassifiedChanges } from "./classify-change.js";
40
+ import { type CompiledTable, type SchemaCommitPaths } from "@rebasepro/types";
41
+ import { type EnsureOptions, type ExistingSchema, type WithheldConstraint } from "./ensure-tables.js";
42
+ import { type ClassifiedChanges, type SchemaFacts } from "./classify-change.js";
43
43
  /**
44
44
  * Re-exported from the shared kernel. `@rebasepro/server` derives these for a
45
45
  * project in a subdirectory and cannot import a driver to do it, so the shape
@@ -51,10 +51,10 @@ export interface SchemaCommitFile {
51
51
  contents: string;
52
52
  }
53
53
  export interface SchemaCommitInput {
54
- /** What the running database was built from. */
55
- before: CollectionConfig[];
56
- /** What the editor is proposing. */
57
- after: CollectionConfig[];
54
+ /** What the running database was built from, compiled. */
55
+ before: readonly CompiledTable[];
56
+ /** What the editor is proposing, compiled (`compileSchemaDefs` over the edited definitions). */
57
+ after: readonly CompiledTable[];
58
58
  /**
59
59
  * Files the caller has already produced — in practice the rewritten
60
60
  * collection source from the AST editor. Carried through unchanged so the
@@ -128,7 +128,7 @@ export declare class SchemaCommitError extends Error {
128
128
  * generating a commit for inspection, and the tests that compare two plans —
129
129
  * where there is no database to describe.
130
130
  */
131
- export declare function additiveStatements(before: CollectionConfig[], after: CollectionConfig[], existing?: ExistingSchema, options?: EnsureOptions): string[];
131
+ export declare function additiveStatements(before: readonly CompiledTable[], after: readonly CompiledTable[], existing?: ExistingSchema, options?: EnsureOptions): string[];
132
132
  /**
133
133
  * The commit of an "Edit source only": what changed in the source, and what
134
134
  * the database keeps — `chore(schema): remove sku from products (source only —
@@ -146,3 +146,8 @@ export declare function commitMessage(classified: ClassifiedChanges): string;
146
146
  * exactly which change was the problem.
147
147
  */
148
148
  export declare function generateSchemaCommit(input: SchemaCommitInput): Promise<SchemaCommit>;
149
+ /**
150
+ * Classify an edit as the live editor hands it: both sides compiled
151
+ * ({@link classifyTableChanges}).
152
+ */
153
+ export declare function classifyEditedTables(before: readonly CompiledTable[], after: readonly CompiledTable[], facts?: SchemaFacts): ClassifiedChanges;
@@ -1,4 +1,4 @@
1
- import { CollectionConfig } from "@rebasepro/types";
1
+ import type { TableDescriptor } from "@rebasepro/types";
2
2
  import type { TableMeta } from "./introspect-db-logic.js";
3
3
  import type { Queryable } from "./introspect-runtime.js";
4
4
  export type SchemaDifferenceKind = "missing-table" | "missing-column" | "extra-column" | "type" | "nullability";
@@ -6,12 +6,12 @@ export interface SchemaDifference {
6
6
  kind: SchemaDifferenceKind;
7
7
  /** Bare table name, as both sides spell it. */
8
8
  table: string;
9
- /** The collection backed by that table, when one is. */
10
- collection?: string;
9
+ /** The slug of the declared table backed by that table, when one is. */
10
+ slug?: string;
11
11
  /** The column, in database terms. */
12
12
  column?: string;
13
- /** The field it is served under — the property key, where there is one. */
14
- property?: string;
13
+ /** The key it is served under, where the table declares it. */
14
+ key?: string;
15
15
  /** What `schema.generated.ts` says. */
16
16
  generated?: string;
17
17
  /** What the database says. */
@@ -35,15 +35,15 @@ export declare function typeFamily(sqlType: string | undefined): string;
35
35
  * One-directional in one respect only: a table the module has and the database
36
36
  * does not is reported (that is the stale-file case), while a table the database
37
37
  * has and the module does not is left alone — a database may hold anything, and
38
- * the collections-vs-file question is `generated-schema-staleness`'s.
38
+ * the declared-tables-vs-file question is `generated-schema-staleness`'s.
39
39
  */
40
40
  export declare function diffGeneratedSchemaAgainstCatalogue(options: {
41
41
  /** The `tables` export of the bundle's schema module. */
42
42
  generated: Record<string, unknown> | undefined;
43
43
  /** What was introspected for this data source, keyed by bare table name. */
44
44
  catalogue: Map<string, TableMeta>;
45
- /** Collections of this source, so a column can be named as a property. */
46
- collections: CollectionConfig[];
45
+ /** The declared tables of this source, so a column can be named by its key. */
46
+ tables: readonly TableDescriptor[];
47
47
  }): SchemaDifference[];
48
48
  /**
49
49
  * Boot's drift question, asked of a database from outside a boot.
@@ -56,21 +56,21 @@ export declare function diffGeneratedSchemaAgainstCatalogue(options: {
56
56
  * doctor compared on its own terms, it answered "In sync" over a NOT NULL and a
57
57
  * left-behind column that boot had just warned about.
58
58
  *
59
- * `collections` are the data source's own, as boot filters them.
59
+ * `tables` are the data source's own, as boot filters them.
60
60
  */
61
61
  export declare function readGeneratedSchemaDrift(options: {
62
62
  client: Queryable;
63
63
  /** The `tables` export of `schema.generated.ts`. */
64
64
  generated: Record<string, unknown> | undefined;
65
- collections: CollectionConfig[];
65
+ tables: readonly TableDescriptor[];
66
66
  defaultSchema: string;
67
67
  }): Promise<SchemaDifference[]>;
68
- /** One line, in the terms the reader has: collection, property, column. */
68
+ /** One line, in the terms the reader has: table slug, column key, column. */
69
69
  export declare function describeSchemaDifference(difference: SchemaDifference): string;
70
70
  /**
71
71
  * The `rebase schema reconcile` line for a difference it can apply: a column
72
- * the database requires and the collection made optional, or one the
73
- * collection no longer declares. Undefined for the rest.
72
+ * the database requires and the table made nullable, or one the table no
73
+ * longer declares. Undefined for the rest.
74
74
  */
75
75
  export declare function reconcileFix(difference: SchemaDifference): string | undefined;
76
76
  /**
@@ -78,13 +78,13 @@ export declare function reconcileFix(difference: SchemaDifference): string | und
78
78
  *
79
79
  * Per difference rather than one summary block on purpose: these are read out of
80
80
  * a log aggregator as often as a terminal, and a single multi-line message
81
- * cannot be filtered down to the one collection somebody is looking at.
81
+ * cannot be filtered down to the one table somebody is looking at.
82
82
  *
83
83
  * The fix it names is `rebase db push`. `rebase dev` rewrites
84
- * schema.generated.ts from the collections on every change, and boot applies
84
+ * schema.generated.ts from the tables on every change, and boot applies
85
85
  * only additive changes, so what is still different at boot is the database
86
86
  * behind the file: a rename, a dropped column, a narrowed type, a NOT NULL.
87
87
  * `rebase schema generate` rewrites the file and leaves the database as it is,
88
- * so it is named only for collections that changed since the file was written.
88
+ * so it is named only for tables that changed since the file was written.
89
89
  */
90
90
  export declare function warnOnGeneratedSchemaDrift(differences: SchemaDifference[]): void;
@@ -1,11 +1,11 @@
1
- import { CollectionConfig } from "@rebasepro/types";
1
+ import type { TableDescriptor } from "@rebasepro/types";
2
2
  /**
3
3
  * Notice a generated Drizzle schema that a *library upgrade* invalidated.
4
4
  *
5
- * `rebase dev` already watches `config/collections` and warns when a collection
6
- * file changes. That covers drift the developer caused. It cannot cover this one,
5
+ * `rebase dev` already watches `backend/schema` and warns when a table file
6
+ * changes. That covers drift the developer caused. It cannot cover this one,
7
7
  * because nothing the developer owns changed: 0.13 derives `category_id` where
8
- * 0.12 derived `categorie_id`, from the same unedited collection. The watcher
8
+ * 0.12 derived `categorie_id`, from the same unedited table. The watcher
9
9
  * never fires, and `backend/src/schema.generated.ts` quietly stops describing the
10
10
  * schema the runtime expects.
11
11
  *
@@ -32,28 +32,28 @@ export interface LegacyForeignKeyName {
32
32
  }
33
33
  /**
34
34
  * @param generatedSource contents of `backend/src/schema.generated.ts`
35
- * @param collections the project's collections, as this release reads them
35
+ * @param tables the project's compiled tables
36
36
  */
37
- export declare function findLegacyForeignKeyNames(generatedSource: string, collections: CollectionConfig[]): LegacyForeignKeyName[];
37
+ export declare function findLegacyForeignKeyNames(generatedSource: string, tables: readonly TableDescriptor[]): LegacyForeignKeyName[];
38
38
  /** One-line summary for a log or a CLI notice. */
39
39
  export declare function describeLegacyForeignKeyNames(found: LegacyForeignKeyName[]): string;
40
- /** Something the collections derive that the generated schema does not declare. */
40
+ /** Something the tables derive that the generated schema does not declare. */
41
41
  export interface MissingGeneratedName {
42
42
  /** The table it belongs to, or is. */
43
43
  table: string;
44
44
  /** The column, when a column is what is missing. */
45
45
  column?: string;
46
- /** `<collection>` or `<collection>.<relation>`, for the message. */
46
+ /** `<table>` or `<table>.<relation>`, for the message. */
47
47
  source: string;
48
48
  }
49
49
  /**
50
- * Tables and derived foreign-key columns the collections name and the generated
50
+ * Tables and derived foreign-key columns the tables name and the generated
51
51
  * schema does not.
52
52
  *
53
53
  * @param generatedSource contents of `backend/src/schema.generated.ts`
54
- * @param collections the project's collections, as this release reads them
54
+ * @param tables the project's compiled tables
55
55
  */
56
- export declare function findMissingGeneratedNames(generatedSource: string, collections: CollectionConfig[]): MissingGeneratedName[];
56
+ export declare function findMissingGeneratedNames(generatedSource: string, tables: readonly TableDescriptor[]): MissingGeneratedName[];
57
57
  /** One-line summary for a log or a CLI notice. */
58
58
  export declare function describeMissingGeneratedNames(missing: MissingGeneratedName[]): string;
59
59
  /** What `rebase schema stale` found, and what that costs. */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Adopting an index the database already has, instead of building a twin.
3
3
  *
4
- * A declared index is found by its derived name (`collection-index.ts`), so an
4
+ * A declared index is found by its derived name (`table-index.ts`), so an
5
5
  * index someone made by hand — or one an introspected database arrived with —
6
6
  * is invisible to it however exactly it matches the declaration: boot and
7
7
  * `db push` built the same index again under the derived name, and every write
@@ -29,7 +29,7 @@
29
29
  * answering a narrower question than the one declared, so a predicate this
30
30
  * cannot read as the same is not adopted.
31
31
  */
32
- import { type CollectionIndexSpec } from "./collection-index.js";
32
+ import { type TableIndexSpec } from "./table-index.js";
33
33
  /** What the catalogue says about one existing index. */
34
34
  export interface ExistingIndexShape {
35
35
  schema: string;
@@ -75,7 +75,7 @@ export interface ShapeQueryable {
75
75
  /** Read the {@link ExistingIndexShape}s of the given schemas. */
76
76
  export declare function readIndexShapes(client: ShapeQueryable, schemas: readonly string[]): Promise<ExistingIndexShape[]>;
77
77
  /** Whether `shape` is `spec` under another name. */
78
- export declare function indexMatchesSpec(spec: CollectionIndexSpec, shape: ExistingIndexShape): boolean;
78
+ export declare function indexMatchesSpec(spec: TableIndexSpec, shape: ExistingIndexShape): boolean;
79
79
  /**
80
80
  * The renames that make existing indexes the declared ones: for each spec
81
81
  * whose derived name the catalogue does not hold, the first existing index on
@@ -83,7 +83,7 @@ export declare function indexMatchesSpec(spec: CollectionIndexSpec, shape: Exist
83
83
  * some declaration's, or one a removed declaration left for push to drop), and
84
84
  * never the same one twice.
85
85
  */
86
- export declare function planIndexAdoptions(specs: readonly CollectionIndexSpec[], shapes: readonly ExistingIndexShape[]): IndexAdoption[];
86
+ export declare function planIndexAdoptions(specs: readonly TableIndexSpec[], shapes: readonly ExistingIndexShape[]): IndexAdoption[];
87
87
  /** The `ALTER INDEX … RENAME TO …` for one adoption. */
88
88
  export declare function indexAdoptionStatement(adoption: IndexAdoption): string;
89
89
  /**
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The `frontend/src/cms/<table>.tsx` introspection writes beside a table whose
3
+ * structure suggested how the panel should show it: a `customizeTable(…)` of
4
+ * plain data (an icon, a group, a title field, a board, a sort, the list and
5
+ * form order, field options).
6
+ *
7
+ * A minimal emitter on purpose. Its values are strings, booleans, arrays and
8
+ * nested objects — never code — so it needs none of the CLI codemod's
9
+ * customization printer (which handles functions and JSX, and which this
10
+ * package must not depend on).
11
+ *
12
+ * @module
13
+ */
14
+ /** A value this emitter prints: data only. */
15
+ export type CustomizationValue = string | number | boolean | readonly CustomizationValue[] | {
16
+ readonly [key: string]: CustomizationValue | undefined;
17
+ };
18
+ /** The package `customizeTable` is imported from. */
19
+ export declare const CMS_PACKAGE = "@rebasepro/cms";
20
+ /** One value as source, four-space indented, `depth` levels in. Short scalar arrays stay on one line. */
21
+ export declare function printCustomizationValue(value: CustomizationValue, depth?: number): string;
22
+ /** What {@link printCustomizationModule} prints. */
23
+ export interface CustomizationModule {
24
+ /** The table's slug, `customizeTable`'s first argument. */
25
+ slug: string;
26
+ /** The identifier the table is exported as from its schema module. */
27
+ tableIdentifier: string;
28
+ /** The schema module, relative to the customization file, without extension: `../../../backend/schema/film`. */
29
+ tableImport: string;
30
+ /** The options: plain data. */
31
+ options: {
32
+ readonly [key: string]: CustomizationValue | undefined;
33
+ };
34
+ /** Comment lines written above the export. */
35
+ comments?: readonly string[];
36
+ }
37
+ /**
38
+ * The whole module:
39
+ *
40
+ * ```ts
41
+ * import { customizeTable } from "@rebasepro/cms";
42
+ * import type { film } from "../../../backend/schema/film";
43
+ *
44
+ * export const filmCms = customizeTable<typeof film>("film", { … });
45
+ * ```
46
+ */
47
+ export declare function printCustomizationModule(module: CustomizationModule): string;
@@ -1,12 +1,33 @@
1
- export interface InferenceResult {
2
- propType?: string;
3
- extra?: string;
1
+ import type { ColumnType, ColumnValidation } from "@rebasepro/types";
2
+ /**
3
+ * What sampled rows suggest about a column (`schema introspect
4
+ * --data-inference`).
5
+ *
6
+ * The column's type is the catalogue's and is never second-guessed from data:
7
+ * a `smallint` holding only 0s and 1s is still a `smallint`, a `text` of ISO
8
+ * dates is still `text`, and declaring otherwise would plan a type change on
9
+ * the first push. What the rows can add is what the type does not say — a
10
+ * bound the API may check, and how the panel should edit the value.
11
+ */
12
+ export interface ColumnHints {
13
+ /** Rules the API checks before a write, merged into the column's `.validate()`. */
14
+ validate?: ColumnValidation;
15
+ /** Field options for the panel, written into the table's `customizeTable`. */
16
+ field?: {
17
+ multiline?: true;
18
+ markdown?: true;
19
+ urlPreview?: "image";
20
+ };
4
21
  }
5
- export declare function inferPropertyFromData(columnName: string, pgDataType: string, currentPropType: string, sampleValues: unknown[], isPk: boolean,
6
22
  /**
7
- * False when generating for a project without `@rebasepro/cms-types`, where
8
- * `BaseProperty` declares no `admin` field and the block below would not
9
- * compile. The type-level inferences (`propType`, `url`, `storage`) are
10
- * unaffected — only the form-widget hints are dropped.
23
+ * Read a column's sampled values for what they add to its declared type.
24
+ *
25
+ * - a number column named like a percentage (`*percent*`, `*rate*`, `*score*`)
26
+ * whose values lie in 0–100 is validated to that range; one named like a
27
+ * quantity (`*count*`, `*total*`, `*amount*`) with no negative value, to `min: 0`;
28
+ * - a text column whose every value is an absolute URL is validated as one,
29
+ * and previewed as an image when the values (or the name) say so;
30
+ * - a text column holding markdown is edited as markdown, one holding line
31
+ * breaks or long values in a multi-line box.
11
32
  */
12
- emitAdmin?: boolean): InferenceResult;
33
+ export declare function inferColumnHints(columnName: string, type: ColumnType, sampleValues: readonly unknown[]): ColumnHints;
@@ -30,6 +30,12 @@ export interface TableColumn {
30
30
  character_maximum_length?: number | null;
31
31
  numeric_precision?: number | null;
32
32
  numeric_scale?: number | null;
33
+ /**
34
+ * `format_type(atttypid, atttypmod)`: the type as Postgres spells it in
35
+ * full, modifiers included (`timestamp(3) without time zone`,
36
+ * `geometry(Point,4326)`) — what a `col.custom()` column is declared as.
37
+ */
38
+ formatted_type?: string | null;
33
39
  }
34
40
  export interface EnumValue {
35
41
  enum_name: string;
@@ -129,37 +135,16 @@ export interface SchemaMetadata {
129
135
  */
130
136
  rowCounts: Record<string, number>;
131
137
  }
132
- /**
133
- * Why a table keyed on several columns is not generated as a collection, or
134
- * `undefined` when it is.
135
- *
136
- * Several `isId` properties are one composite key, and the planner builds that
137
- * table under the same `PRIMARY KEY (a, b)` — so such a table round-trips when
138
- * two things hold:
139
- *
140
- * - **Every key column can carry `isId`,** which exists on string and number
141
- * properties, and on a date property over a `date` column (a calendar day).
142
- * Read from the column's SQL type, not a data sample: a
143
- * `line_no` holding only 1s is not a boolean. A key with a column of another
144
- * type — pagila's `payment` is keyed on a timestamp too — can be marked on
145
- * some of its columns only, and those would be read as the whole key.
146
- * - **Nothing points at it.** A foreign key into it, or a junction, is a link
147
- * into a composite key, which the planner refuses: the relation has one
148
- * column to point with.
149
- */
150
- export declare function compositeKeySkipReason(meta: TableMeta, allFks: ForeignKeyRow[]): string | undefined;
151
138
  export interface TableMeta {
152
139
  name: string;
153
140
  columns: TableColumn[];
154
141
  pks: string[];
155
142
  fks: ForeignKeyRow[];
156
143
  }
157
- export declare function singularize(word: string): string;
158
144
  /**
159
- * Convert a snake_case table name to a camelCase + "Collection" variable name.
160
- * e.g. "company_token" -> "companyTokenCollection"
145
+ * The icon a table's name suggests, for its panel customization: `Database`
146
+ * when the name suggests none (and then no icon is written).
161
147
  */
162
- export declare function toCollectionVarName(tableName: string): string;
163
148
  export declare function getIconForTable(tableName: string): string;
164
149
  export { mapPgType };
165
150
  export declare function buildEnumMap(enumValues: EnumValue[]): Map<string, string[]>;
@@ -174,9 +159,10 @@ export declare function buildTablesMap(tables: TableRow[], columns: TableColumn[
174
159
  * quantity and discount — because it recognises `id`, `created_at` and
175
160
  * `updated_at` by name and calls everything else a foreign key.
176
161
  *
177
- * Still used by `./introspect-runtime`, which builds collections in memory from
178
- * a narrower set of catalog queries and has no unique-constraint or row-count
179
- * data to reason with.
162
+ * Still the runtime's rule (`describeTables(…, { purpose: "serve" })`): what a
163
+ * backend with no `backend/schema` has always folded away, kept so the set of
164
+ * tables it serves does not move. Row counts, which `classifyTables` needs,
165
+ * are not read at boot.
180
166
  */
181
167
  export declare function identifyJoinTables(tablesMap: Map<string, TableMeta>): Set<string>;
182
168
  /**
@@ -222,106 +208,89 @@ export interface PropertyOrderEntry {
222
208
  ctx: PropertyOrderingContext;
223
209
  }
224
210
  export declare function sortPropertiesOrder(entries: PropertyOrderEntry[]): string[];
225
- export interface GeneratedFile {
226
- tableName: string;
227
- fileName: string;
228
- content: string;
229
- }
230
- /**
231
- * The structural analysis a run can hand the generator.
232
- *
233
- * Optional in full, and the generator degrades to exactly its previous output
234
- * without it. That is not politeness towards old callers: three existing test
235
- * suites and the `rebase init` scaffold path build a `TableMeta` by hand and
236
- * have no database to read constraints or row counts from, and they must keep
237
- * producing a valid collection.
238
- */
239
- /**
240
- * Which `defineCollection` — if any — the project being generated into can import.
241
- *
242
- * A bare `const x: PostgresCollectionConfig = { … }` annotation widens `properties`
243
- * to `Record<string, …>`, and every key-shaped field in the admin block —
244
- * `titleProperty`, `sort`, `propertiesOrder`, `listProperties`, `fixedFilter` — is
245
- * derived from those keys. Annotated, they accept any string: introspection was
246
- * emitting a `propertiesOrder` array that nothing checked, so renaming a column and
247
- * re-introspecting left a stale key that compiled silently. `defineCollection` is
248
- * the identity function whose `const P` type parameter keeps the keys literal, which
249
- * is what turns that checking on.
250
- *
251
- * There are two of them and they are not interchangeable:
252
- *
253
- * - `admin-types` — `@rebasepro/cms-types`. Its index side-effect-imports
254
- * `augment.ts`, so importing it is also what *declares* the `admin` block. Only a
255
- * project that depends on the package can resolve it.
256
- * - `common` — `@rebasepro/common`. Same key inference, no admin surface, no React
257
- * anywhere in its graph (`scripts/headless-guard` lists it as core). This is the
258
- * headless flavour.
259
- * - `annotation` — neither package is declared, so neither import would resolve and
260
- * the old annotation is the only honest thing to emit. Projects scaffolded before
261
- * `@rebasepro/common` joined the headless config package land here.
262
- *
263
- * The last two emit **no admin block, on the collection or on any property**. That is
264
- * not a downgrade: `@rebasepro/types` declares no `admin` field at all, so the block
265
- * introspection used to emit was a type error in every headless project it was
266
- * written into. See `packages/cms-types/src/augment.ts`.
267
- */
268
- export type CollectionBuilder = "admin-types" | "common" | "annotation";
269
211
  /**
270
- * The package specifiers the generated files name, spelled once.
212
+ * What one `schema introspect` run hands the generator.
271
213
  *
272
- * Written as constants rather than inline in the import templates below because
273
- * `scripts/headless-guard/check-types.mjs` scans core sources for `from
274
- * "@rebasepro/cms-types"` and cannot tell a real import from one this module
275
- * *writes*. It is right to be that blunt — the guard's whole value is that it
276
- * cannot be reasoned around — so the string simply never appears in that shape
277
- * here. Inlining them back into the templates re-breaks `check:types-headless`.
214
+ * Everything but `metadata` is optional, and the generator degrades without
215
+ * it: no classification is no table roles and no presentation heuristics, no
216
+ * CHECK facts is no bounds, no samples is no data hints, no `cms` is no
217
+ * `customizeTable` files.
278
218
  */
279
- export declare const ADMIN_TYPES_PACKAGE = "@rebasepro/cms-types";
280
- export declare const COMMON_PACKAGE = "@rebasepro/common";
281
- export declare const TYPES_PACKAGE = "@rebasepro/types";
282
- export interface GenerationContext {
283
- metadata?: SchemaMetadata;
219
+ export interface SchemaGenerationInput {
220
+ metadata: SchemaMetadata;
221
+ /** Each table's role (`classifyTables`): junctions fold into `manyToMany`, the rest steer the panel. */
284
222
  classifications?: Map<string, TableClassification>;
223
+ /** The CHECK constraints, parsed (`parseCheckConstraints`). */
285
224
  checkFacts?: CheckFactsByTable;
225
+ /** Sampled rows by table (`--data-inference`). */
226
+ samples?: ReadonlyMap<string, readonly Record<string, unknown>[]>;
227
+ /** Tables not to generate, which nothing may then point at (a name that is no file name). */
228
+ leaveOut?: ReadonlySet<string>;
286
229
  /**
287
- * Defaults to `admin-types`, which is what the generator has always emitted.
288
- * The CLI never relies on the default — `introspect-db.ts` detects the flavour
289
- * from the target project and passes it. See `detectCollectionBuilder`.
230
+ * Present when the project has a frontend that imports `@rebasepro/cms`:
231
+ * the import path from a `frontend/src/cms/<table>.tsx` to the table's
232
+ * schema module. Absent, no customization is written.
290
233
  */
291
- builder?: CollectionBuilder;
292
- /**
293
- * Collects one line per column the planner will not reproduce exactly —
294
- * what `rebase db push` would do to it, and how to avoid that when there is
295
- * a way. The CLI prints them; the same lines are written at the top of the
296
- * generated file.
297
- */
298
- notes?: string[];
299
- /**
300
- * Tables this run does not generate a collection for, so nothing may point
301
- * at them: a relation whose target file does not exist is an import that
302
- * does not resolve.
303
- */
304
- skippedTables?: ReadonlySet<string>;
234
+ cms?: {
235
+ tableImport: (table: string) => string;
236
+ };
237
+ /** Where the builders are imported from. `@rebasepro/server/schema` when omitted. */
238
+ specifier?: string;
305
239
  }
306
240
  /**
307
- * What `rebase db push` does to tables whose row-level security is off, for
308
- * the introspection to say once — or `undefined` when there are none.
241
+ * The source written for one table.
309
242
  */
310
- export declare function describeRlsOffTables(tableNames: readonly string[]): string | undefined;
243
+ export interface GeneratedTable {
244
+ table: string;
245
+ /** What `backend/schema/<table>.ts` exports, and `index.ts` re-exports. */
246
+ identifier: string;
247
+ /** `backend/schema/<table>.ts`. */
248
+ schemaModule: string;
249
+ /** `frontend/src/cms/<table>.tsx`, when a presentation heuristic fired and the project has a frontend. */
250
+ customization?: string;
251
+ /** What `rebase db push` would not reproduce exactly, each also at the top of the module. */
252
+ notes: string[];
253
+ /** Decisions the module states that the reader may want to undo (`index: false`, …), each also at its top. */
254
+ remarks: string[];
255
+ }
311
256
  /**
312
- * Generate the full TypeScript file content for a single collection.
313
- * Pure function — no I/O.
257
+ * What {@link generateSchemaModules} returns.
314
258
  */
315
- export declare function generateCollectionFile(tableName: string, meta: TableMeta, allFks: ForeignKeyRow[], joinTables: Set<string>, tablesMap: Map<string, TableMeta>, enumMap: Map<string, string[]>, sampleData?: Record<string, unknown>[], context?: GenerationContext): string;
259
+ export interface SchemaGeneration {
260
+ tables: GeneratedTable[];
261
+ /** Tables whose descriptor could not be printed, each with why. */
262
+ failed: {
263
+ table: string;
264
+ reason: string;
265
+ }[];
266
+ /** The generated tables whose row-level security is off: the first push switches it on. */
267
+ rlsOff: string[];
268
+ }
316
269
  /**
317
- * Generate the content for an index.ts file that re-exports all collections.
270
+ * The source `rebase schema introspect` writes for a database: one
271
+ * `backend/schema/<table>.ts` per table through the one table printer
272
+ * (`printTableModule`), and a `frontend/src/cms/<table>.tsx` beside a table
273
+ * whose structure suggested how the panel should show it.
274
+ *
275
+ * The tables are described with `describeTables(…, { purpose: "generate" })`:
276
+ * columns as their Postgres types, foreign keys as `belongsTo` with the column
277
+ * declared, the reverse `hasMany`, a junction as `manyToMany`, the policies as
278
+ * `rls` (or `"admin-only"` when the table holds only the admin baseline). Pure.
318
279
  */
319
- export declare function generateIndexContent(fileNames: string[]): string;
280
+ export declare function generateSchemaModules(input: SchemaGenerationInput): SchemaGeneration;
320
281
  /**
321
- * Merge new exports into existing index.ts content.
322
- * Returns the merged content string.
282
+ * `backend/schema/index.ts` with an export line added for each table it does
283
+ * not export yet — what a run without `--force` does to an index that exists.
323
284
  */
324
- export declare function mergeIndexContent(existingContent: string, newFileNames: string[]): string;
285
+ export declare function mergeIndexModule(existing: string, tables: readonly {
286
+ identifier: string;
287
+ importPath: string;
288
+ }[]): string;
289
+ /**
290
+ * What `rebase db push` does to tables whose row-level security is off, for
291
+ * the introspection to say once — or `undefined` when there are none.
292
+ */
293
+ export declare function describeRlsOffTables(tableNames: readonly string[]): string | undefined;
325
294
  /**
326
295
  * Safely extract the host portion of a database URL for logging.
327
296
  */
@@ -1,21 +1,18 @@
1
- import { type CollectionBuilder } from "./introspect-db-logic.js";
2
1
  /**
3
- * Which `defineCollection` to generate against, for collections written to `outDir`.
4
- *
5
- * **The detection is the package manifests above the output directory**, unioned from
6
- * `outDir` up to and including the project root — the first ancestor holding a
7
- * `rebase.json`, or `MAX_LEVELS` up if there is none.
8
- *
9
- * That is the rule Node itself applies: a file in `config/collections` resolves a bare
10
- * specifier through `config/node_modules`, then `<project>/node_modules`, and so on up.
11
- * Reading the manifests along that same path answers the only question that matters —
12
- * *will this import resolve in the project I am writing into* — from the state on disk
13
- * at the moment of generation. The alternatives are all proxies for it: `rebase.json`'s
14
- * `apps` block says a CMS scaffold declared an admin app, and a `frontend/` directory
15
- * says one was scaffolded, but neither is what the compiler consults, and either can be
16
- * true of a project whose `config` package does not depend on `@rebasepro/cms-types`.
2
+ * The project root above a directory: the first ancestor holding a
3
+ * `rebase.json`, or `undefined` when none does within reach.
4
+ */
5
+ export declare function findProjectRoot(from: string): string | undefined;
6
+ /**
7
+ * The `frontend/src/cms` directory introspection writes `customizeTable`
8
+ * files into, or `undefined` when the project has no frontend that can import
9
+ * `@rebasepro/cms`.
17
10
  *
18
- * Ambiguity resolves towards the admin panel: a project that declares both packages has
19
- * a panel, and `@rebasepro/cms-types` is the flavour that keeps the `admin` block.
11
+ * The project root is the one above the schema directory (`rebase.json`), or —
12
+ * in a layout without one — the parent of `backend/`. The frontend is
13
+ * `<root>/frontend`, and it counts only when a manifest on the path a
14
+ * `frontend/src/cms/<table>.tsx` resolves bare specifiers along (the frontend's
15
+ * own `package.json`, then the root's) declares `@rebasepro/cms`: that is the
16
+ * import the file opens with, and a headless project could not resolve it.
20
17
  */
21
- export declare function detectCollectionBuilder(outDir: string): CollectionBuilder;
18
+ export declare function detectCmsDir(schemaDir: string): string | undefined;