@rebasepro/cms 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 (583) hide show
  1. package/README.md +8 -8
  2. package/dist/collection_editor/ConfigControllerProvider.js +25 -22
  3. package/dist/collection_editor/ConfigControllerProvider.js.map +1 -1
  4. package/dist/collection_editor/firestore_callee.d.ts +10 -0
  5. package/dist/collection_editor/firestore_callee.js +15 -0
  6. package/dist/collection_editor/firestore_callee.js.map +1 -0
  7. package/dist/collection_editor/firestore_edit.d.ts +62 -0
  8. package/dist/collection_editor/firestore_edit.js +339 -0
  9. package/dist/collection_editor/firestore_edit.js.map +1 -0
  10. package/dist/collection_editor/index.d.ts +2 -3
  11. package/dist/collection_editor/liveSchemaClient.d.ts +44 -22
  12. package/dist/collection_editor/liveSchemaClient.js +9 -3
  13. package/dist/collection_editor/liveSchemaClient.js.map +1 -1
  14. package/dist/collection_editor/property_column.d.ts +86 -0
  15. package/dist/collection_editor/property_column.js +719 -0
  16. package/dist/collection_editor/property_column.js.map +1 -0
  17. package/dist/collection_editor/serializable_types.d.ts +2 -24
  18. package/dist/collection_editor/serializable_utils.d.ts +1 -1
  19. package/dist/collection_editor/serializable_utils.js +2 -1
  20. package/dist/collection_editor/serializable_utils.js.map +1 -1
  21. package/dist/collection_editor/split_edit.d.ts +106 -0
  22. package/dist/collection_editor/split_edit.js +564 -0
  23. package/dist/collection_editor/split_edit.js.map +1 -0
  24. package/dist/collection_editor/split_edit_error.d.ts +25 -0
  25. package/dist/collection_editor/split_edit_error.js +35 -0
  26. package/dist/collection_editor/split_edit_error.js.map +1 -0
  27. package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
  28. package/dist/collection_editor/types/config_controller.d.ts +67 -1
  29. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +6 -5
  30. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +44 -12
  31. package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -1
  32. package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +18 -3
  33. package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -1
  34. package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +94 -55
  35. package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -1
  36. package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +2 -1
  37. package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -1
  38. package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +1 -1
  39. package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
  40. package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +3 -3
  41. package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -1
  42. package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -1
  43. package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -3
  44. package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +1 -1
  45. package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -1
  46. package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +1 -1
  47. package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +1 -1
  48. package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -1
  49. package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +7 -4
  50. package/dist/collection_editor/ui/collection_editor/PropertyTree.js +15 -5
  51. package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -1
  52. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +1 -1
  53. package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
  54. package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.d.ts +20 -0
  55. package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js +74 -0
  56. package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js.map +1 -0
  57. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
  58. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
  59. package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -1
  60. package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
  61. package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -1
  62. package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -1
  63. package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
  64. package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +1 -1
  65. package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
  66. package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -1
  67. package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -1
  68. package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -1
  69. package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -1
  70. package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +1 -1
  71. package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +1 -1
  72. package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +1 -1
  73. package/dist/collection_editor/ui/collection_editor/rlsRuleForm.d.ts +34 -0
  74. package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js +50 -0
  75. package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js.map +1 -0
  76. package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -2
  77. package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -1
  78. package/dist/collection_editor/useDetachRulesConfirmation.d.ts +16 -0
  79. package/dist/collection_editor/useDetachRulesConfirmation.js +48 -0
  80. package/dist/collection_editor/useDetachRulesConfirmation.js.map +1 -0
  81. package/dist/collection_editor/useLiveSchemaEditing.d.ts +2 -2
  82. package/dist/collection_editor/useLiveSchemaEditing.js +1 -1
  83. package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
  84. package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +54 -10
  85. package/dist/collection_editor/useLocalCollectionsConfigController.js +394 -122
  86. package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -1
  87. package/dist/collection_editor/validateCollectionJson.js.map +1 -1
  88. package/dist/components/CollectionPanel.d.ts +10 -9
  89. package/dist/components/CollectionPanel.js +5 -2
  90. package/dist/components/CollectionPanel.js.map +1 -1
  91. package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +1 -2
  92. package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
  93. package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
  94. package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +3 -5
  95. package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +2 -2
  96. package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
  97. package/dist/components/CollectionTableBinding/column_utils.d.ts +1 -1
  98. package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
  99. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.d.ts +2 -2
  100. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +1 -2
  101. package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
  102. package/dist/components/CollectionTableBinding/fields/TableReferenceField.d.ts +2 -2
  103. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
  104. package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
  105. package/dist/components/CollectionTableBinding/fields/TableRelationField.d.ts +2 -2
  106. package/dist/components/CollectionTableBinding/fields/TableRelationField.js +1 -2
  107. package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
  108. package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.d.ts +2 -1
  109. package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -1
  110. package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +2 -2
  111. package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
  112. package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.d.ts +1 -1
  113. package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +1 -1
  114. package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -1
  115. package/dist/components/CollectionTableBinding/internal/common.d.ts +1 -2
  116. package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
  117. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
  118. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +2 -2
  119. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
  120. package/dist/components/CollectionTableBinding/table_bindings.d.ts +2 -2
  121. package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -1
  122. package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +1 -1
  123. package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
  124. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +1 -2
  125. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -5
  126. package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
  127. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +1 -2
  128. package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
  129. package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +1 -1
  130. package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -1
  131. package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +1 -2
  132. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +1 -1
  133. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
  134. package/dist/components/CollectionViewBinding/CollectionToolbar.js +1 -1
  135. package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -1
  136. package/dist/components/CollectionViewBinding/CollectionViewActions.js +2 -4
  137. package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
  138. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +6 -6
  139. package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
  140. package/dist/components/CollectionViewBinding/CollectionViewContent.js +1 -2
  141. package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -1
  142. package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +1 -1
  143. package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
  144. package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +1 -2
  145. package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -1
  146. package/dist/components/CollectionViewBinding/EntitiesCount.js +3 -3
  147. package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -1
  148. package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +1 -2
  149. package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
  150. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +1 -1
  151. package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -1
  152. package/dist/components/CollectionViewBinding/FilterPresetsButton.d.ts +1 -2
  153. package/dist/components/CollectionViewBinding/FilterPresetsButton.js +1 -1
  154. package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -1
  155. package/dist/components/CollectionViewBinding/FiltersButton.d.ts +1 -2
  156. package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -1
  157. package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +1 -1
  158. package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
  159. package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +1 -2
  160. package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -1
  161. package/dist/components/CollectionViewBinding/RowActions.d.ts +1 -2
  162. package/dist/components/CollectionViewBinding/RowActions.js.map +1 -1
  163. package/dist/components/CollectionViewBinding/SortButton.d.ts +1 -1
  164. package/dist/components/CollectionViewBinding/SortButton.js.map +1 -1
  165. package/dist/components/CollectionViewBinding/SplitListView.d.ts +1 -2
  166. package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
  167. package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.d.ts +1 -2
  168. package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +1 -1
  169. package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -1
  170. package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -2
  171. package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -1
  172. package/dist/components/CollectionViewBinding/useBoardDataController.d.ts +2 -1
  173. package/dist/components/CollectionViewBinding/useBoardDataController.js +3 -3
  174. package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
  175. package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +2 -4
  176. package/dist/components/CollectionViewBinding/useCollectionViewState.js +14 -19
  177. package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -1
  178. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +1 -3
  179. package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
  180. package/dist/components/CollectionViewBinding/useSelectionController.d.ts +1 -2
  181. package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
  182. package/dist/components/CollectionsProvider.d.ts +23 -8
  183. package/dist/components/CollectionsProvider.js +23 -7
  184. package/dist/components/CollectionsProvider.js.map +1 -1
  185. package/dist/components/DefaultDrawer.js +1 -1
  186. package/dist/components/DeleteEntityDialog.d.ts +1 -1
  187. package/dist/components/DeleteEntityDialog.js +1 -1
  188. package/dist/components/DeleteEntityDialog.js.map +1 -1
  189. package/dist/components/DetailViewBinding.js +3 -3
  190. package/dist/components/DetailViewBinding.js.map +1 -1
  191. package/dist/components/EditFormActions.js.map +1 -1
  192. package/dist/components/EditViewBinding.d.ts +2 -1
  193. package/dist/components/EditViewBinding.js +6 -6
  194. package/dist/components/EditViewBinding.js.map +1 -1
  195. package/dist/components/EntityDisplayHeader.d.ts +1 -2
  196. package/dist/components/EntityDisplayHeader.js.map +1 -1
  197. package/dist/components/EntityInspector.d.ts +1 -2
  198. package/dist/components/EntityInspector.js.map +1 -1
  199. package/dist/components/EntityPreviewBinding.d.ts +1 -1
  200. package/dist/components/EntityPreviewBinding.js +1 -1
  201. package/dist/components/EntityPreviewBinding.js.map +1 -1
  202. package/dist/components/EntityViewBinding.d.ts +1 -1
  203. package/dist/components/EntityViewBinding.js.map +1 -1
  204. package/dist/components/EntityViewBody.d.ts +1 -1
  205. package/dist/components/EntityViewBody.js +3 -4
  206. package/dist/components/EntityViewBody.js.map +1 -1
  207. package/dist/components/FieldValue.js +2 -2
  208. package/dist/components/FieldValue.js.map +1 -1
  209. package/dist/components/HomePage/ContentHomePage.js +12 -3
  210. package/dist/components/HomePage/ContentHomePage.js.map +1 -1
  211. package/dist/components/InlineEntityPreview.d.ts +1 -1
  212. package/dist/components/InlineEntityPreview.js.map +1 -1
  213. package/dist/components/PropertyCollectionView.d.ts +2 -2
  214. package/dist/components/PropertyCollectionView.js.map +1 -1
  215. package/dist/components/PropertyConfigBadge.js.map +1 -1
  216. package/dist/components/RebaseCMS.d.ts +22 -3
  217. package/dist/components/RebaseCMS.js +32 -14
  218. package/dist/components/RebaseCMS.js.map +1 -1
  219. package/dist/components/RebaseNavigation.js +106 -31
  220. package/dist/components/RebaseNavigation.js.map +1 -1
  221. package/dist/components/RecordDetail.js +4 -1
  222. package/dist/components/RecordDetail.js.map +1 -1
  223. package/dist/components/RecordForm.d.ts +5 -5
  224. package/dist/components/RecordForm.js +5 -2
  225. package/dist/components/RecordForm.js.map +1 -1
  226. package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +2 -2
  227. package/dist/components/ReferenceTable/SelectionTableBinding.js +1 -1
  228. package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
  229. package/dist/components/ReferenceWidget.d.ts +2 -1
  230. package/dist/components/ReferenceWidget.js +2 -2
  231. package/dist/components/ReferenceWidget.js.map +1 -1
  232. package/dist/components/RelationSelector.d.ts +2 -1
  233. package/dist/components/RelationSelector.js +2 -3
  234. package/dist/components/RelationSelector.js.map +1 -1
  235. package/dist/components/SelectableTable/SelectableTable.d.ts +2 -2
  236. package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
  237. package/dist/components/SelectableTable/filters/FilterFieldBinding.d.ts +2 -1
  238. package/dist/components/SelectableTable/filters/FilterFieldBinding.js +3 -3
  239. package/dist/components/SelectableTable/filters/FilterFieldBinding.js.map +1 -1
  240. package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
  241. package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
  242. package/dist/components/SelectableTable/filters/RelationFilterField.d.ts +1 -1
  243. package/dist/components/SelectableTable/filters/RelationFilterField.js +1 -1
  244. package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -1
  245. package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +1 -1
  246. package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
  247. package/dist/components/SelectableTable/filters/null_filter.d.ts +1 -3
  248. package/dist/components/SelectableTable/filters/null_filter.js.map +1 -1
  249. package/dist/components/SidePanelBinding.js +1 -1
  250. package/dist/components/SidePanelBinding.js.map +1 -1
  251. package/dist/components/field_configs.d.ts +1 -2
  252. package/dist/components/field_configs.js.map +1 -1
  253. package/dist/components/field_ids.d.ts +1 -1
  254. package/dist/components/field_ids.js +1 -1
  255. package/dist/components/field_ids.js.map +1 -1
  256. package/dist/components/history/EntityHistoryEntry.js.map +1 -1
  257. package/dist/components/history/EntityHistoryView.d.ts +1 -2
  258. package/dist/components/history/EntityHistoryView.js +1 -1
  259. package/dist/components/history/EntityHistoryView.js.map +1 -1
  260. package/dist/data_export/export/BasicExportAction.d.ts +1 -1
  261. package/dist/data_export/export/BasicExportAction.js.map +1 -1
  262. package/dist/data_export/export/ExportCollectionAction.js +2 -2
  263. package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
  264. package/dist/data_export/export/additional_fields.d.ts +1 -1
  265. package/dist/data_export/export/additional_fields.js.map +1 -1
  266. package/dist/data_export/export/export.d.ts +1 -1
  267. package/dist/data_export/export/export.js +1 -1
  268. package/dist/data_export/export/export.js.map +1 -1
  269. package/dist/data_export/export/fetch_export_data.d.ts +3 -2
  270. package/dist/data_export/export/fetch_export_data.js.map +1 -1
  271. package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
  272. package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -1
  273. package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +1 -1
  274. package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -1
  275. package/dist/data_import/hooks/useImportConfig.js.map +1 -1
  276. package/dist/data_import/import/ImportCollectionAction.d.ts +2 -2
  277. package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
  278. package/dist/data_import/types/column_mapping.d.ts +1 -1
  279. package/dist/data_import/utils/data.d.ts +1 -2
  280. package/dist/data_import/utils/data.js +1 -2
  281. package/dist/data_import/utils/data.js.map +1 -1
  282. package/dist/data_import/utils/get_import_inference_type.d.ts +1 -1
  283. package/dist/data_import/utils/get_import_inference_type.js.map +1 -1
  284. package/dist/data_import/utils/id_column.d.ts +1 -1
  285. package/dist/data_import/utils/id_column.js.map +1 -1
  286. package/dist/data_import/utils/import_columns.d.ts +1 -1
  287. package/dist/data_import/utils/import_columns.js.map +1 -1
  288. package/dist/data_import/utils/save_entities.d.ts +3 -3
  289. package/dist/data_import/utils/save_entities.js +1 -1
  290. package/dist/data_import/utils/save_entities.js.map +1 -1
  291. package/dist/form/EntityForm.js +2 -1
  292. package/dist/form/EntityForm.js.map +1 -1
  293. package/dist/form/EntityFormActions.js.map +1 -1
  294. package/dist/form/EntityFormBinding.js +2 -2
  295. package/dist/form/EntityFormBinding.js.map +1 -1
  296. package/dist/form/FormFieldsContext.d.ts +1 -4
  297. package/dist/form/FormFieldsContext.js +1 -1
  298. package/dist/form/FormFieldsContext.js.map +1 -1
  299. package/dist/form/PropertyFieldBinding.js +6 -8
  300. package/dist/form/PropertyFieldBinding.js.map +1 -1
  301. package/dist/form/components/FieldBlock.d.ts +1 -2
  302. package/dist/form/components/FieldBlock.js.map +1 -1
  303. package/dist/form/components/FieldHelperText.d.ts +1 -1
  304. package/dist/form/components/FieldHelperText.js.map +1 -1
  305. package/dist/form/components/FormRail.d.ts +1 -1
  306. package/dist/form/components/FormRail.js.map +1 -1
  307. package/dist/form/components/LocalChangesMenu.d.ts +1 -1
  308. package/dist/form/components/LocalChangesMenu.js.map +1 -1
  309. package/dist/form/components/StorageItemPreview.d.ts +1 -1
  310. package/dist/form/components/StorageItemPreview.js.map +1 -1
  311. package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
  312. package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +1 -1
  313. package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -1
  314. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +2 -2
  315. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
  316. package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
  317. package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
  318. package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -1
  319. package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
  320. package/dist/form/field_bindings/BlockFieldBinding.js +1 -1
  321. package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -1
  322. package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
  323. package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
  324. package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
  325. package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -1
  326. package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
  327. package/dist/form/field_bindings/KeyValueFieldBinding.js +1 -2
  328. package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
  329. package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
  330. package/dist/form/field_bindings/MapFieldBinding.js.map +1 -1
  331. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
  332. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
  333. package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
  334. package/dist/form/field_bindings/MultiSelectFieldBinding.d.ts +1 -1
  335. package/dist/form/field_bindings/MultiSelectFieldBinding.js +1 -1
  336. package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -1
  337. package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +1 -1
  338. package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
  339. package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
  340. package/dist/form/field_bindings/ReadOnlyFieldBinding.d.ts +1 -1
  341. package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
  342. package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +1 -1
  343. package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
  344. package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
  345. package/dist/form/field_bindings/RelationFieldBinding.d.ts +1 -1
  346. package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
  347. package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
  348. package/dist/form/field_bindings/RepeatFieldBinding.d.ts +1 -1
  349. package/dist/form/field_bindings/RepeatFieldBinding.js +1 -1
  350. package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -1
  351. package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
  352. package/dist/form/field_bindings/SelectFieldBinding.js +1 -1
  353. package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
  354. package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -2
  355. package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
  356. package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
  357. package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
  358. package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
  359. package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
  360. package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
  361. package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -1
  362. package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
  363. package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
  364. package/dist/form/form_utils.d.ts +3 -3
  365. package/dist/form/form_utils.js +1 -2
  366. package/dist/form/form_utils.js.map +1 -1
  367. package/dist/form/label_placement.d.ts +1 -2
  368. package/dist/form/label_placement.js.map +1 -1
  369. package/dist/form/resolve_cell_property.d.ts +1 -2
  370. package/dist/form/resolve_cell_property.js +1 -1
  371. package/dist/form/resolve_cell_property.js.map +1 -1
  372. package/dist/form/resolve_form_properties.d.ts +2 -2
  373. package/dist/form/resolve_form_properties.js +1 -1
  374. package/dist/form/resolve_form_properties.js.map +1 -1
  375. package/dist/form/useClearRestoreValue.d.ts +1 -1
  376. package/dist/form/useClearRestoreValue.js.map +1 -1
  377. package/dist/form/validation.d.ts +2 -2
  378. package/dist/form/validation.js +1 -1
  379. package/dist/form/validation.js.map +1 -1
  380. package/dist/hooks/navigation/compose_collections.d.ts +59 -0
  381. package/dist/hooks/navigation/compose_collections.js +48 -0
  382. package/dist/hooks/navigation/compose_collections.js.map +1 -0
  383. package/dist/hooks/navigation/compose_collections_input.d.ts +8 -0
  384. package/dist/hooks/navigation/compose_collections_input.js +17 -0
  385. package/dist/hooks/navigation/compose_collections_input.js.map +1 -0
  386. package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +1 -1
  387. package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -1
  388. package/dist/hooks/navigation/registered_collection.d.ts +15 -0
  389. package/dist/hooks/navigation/registered_collection.js +20 -0
  390. package/dist/hooks/navigation/registered_collection.js.map +1 -0
  391. package/dist/hooks/navigation/ui_preferences.d.ts +47 -0
  392. package/dist/hooks/navigation/ui_preferences.js +179 -0
  393. package/dist/hooks/navigation/ui_preferences.js.map +1 -0
  394. package/dist/hooks/navigation/useAsyncResolver.d.ts +8 -1
  395. package/dist/hooks/navigation/useAsyncResolver.js +9 -3
  396. package/dist/hooks/navigation/useAsyncResolver.js.map +1 -1
  397. package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +1 -3
  398. package/dist/hooks/navigation/useBuildCollectionRegistryController.js +3 -3
  399. package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -1
  400. package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +9 -5
  401. package/dist/hooks/navigation/useBuildNavigationStateController.js +2 -1
  402. package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
  403. package/dist/hooks/navigation/useBuildUrlController.d.ts +1 -1
  404. package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
  405. package/dist/hooks/navigation/useNavigationResolution.js +1 -2
  406. package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
  407. package/dist/hooks/navigation/usePanelTables.d.ts +11 -0
  408. package/dist/hooks/navigation/usePanelTables.js +33 -0
  409. package/dist/hooks/navigation/usePanelTables.js.map +1 -0
  410. package/dist/hooks/navigation/useResolvedCollections.d.ts +8 -3
  411. package/dist/hooks/navigation/useResolvedCollections.js +3 -2
  412. package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
  413. package/dist/hooks/navigation/useResolvedViews.d.ts +1 -2
  414. package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
  415. package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -2
  416. package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -1
  417. package/dist/hooks/navigation/user_preferences_overlay.d.ts +21 -0
  418. package/dist/hooks/navigation/user_preferences_overlay.js +101 -0
  419. package/dist/hooks/navigation/user_preferences_overlay.js.map +1 -0
  420. package/dist/hooks/navigation/utils.js +1 -1
  421. package/dist/hooks/navigation/utils.js.map +1 -1
  422. package/dist/hooks/useAdminContext.d.ts +1 -2
  423. package/dist/hooks/useAdminContext.js.map +1 -1
  424. package/dist/hooks/useBuildSidePanel.d.ts +1 -2
  425. package/dist/hooks/useBuildSidePanel.js +2 -1
  426. package/dist/hooks/useBuildSidePanel.js.map +1 -1
  427. package/dist/hooks/useChildViewSource.d.ts +1 -1
  428. package/dist/hooks/useChildViewSource.js +1 -1
  429. package/dist/hooks/useChildViewSource.js.map +1 -1
  430. package/dist/hooks/useEntityDisplay.d.ts +1 -2
  431. package/dist/hooks/useEntityDisplay.js +1 -1
  432. package/dist/hooks/useEntityDisplay.js.map +1 -1
  433. package/dist/hooks/useEntityDisplayTitle.d.ts +2 -2
  434. package/dist/hooks/useEntityDisplayTitle.js.map +1 -1
  435. package/dist/hooks/useHistory.js +1 -1
  436. package/dist/hooks/useHistory.js.map +1 -1
  437. package/dist/hooks/useRecordActions.d.ts +1 -2
  438. package/dist/hooks/useRecordActions.js.map +1 -1
  439. package/dist/hooks/useReferencePaths.d.ts +21 -7
  440. package/dist/hooks/useReferencePaths.js +23 -6
  441. package/dist/hooks/useReferencePaths.js.map +1 -1
  442. package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
  443. package/dist/hooks/useResolvedNavigationFrom.js +1 -1
  444. package/dist/hooks/useResolvedNavigationFrom.js.map +1 -1
  445. package/dist/index.d.ts +11 -0
  446. package/dist/index.js +8 -2
  447. package/dist/mcp_view/app_modules.d.ts +2 -2
  448. package/dist/mcp_view/app_modules.js +4 -4
  449. package/dist/mcp_view/app_modules.js.map +1 -1
  450. package/dist/mcp_view/index.d.ts +16 -19
  451. package/dist/mcp_view/index.js +43 -62
  452. package/dist/mcp_view/index.js.map +1 -1
  453. package/dist/mcp_view/payload.d.ts +54 -18
  454. package/dist/mcp_view/payload.js +49 -24
  455. package/dist/mcp_view/payload.js.map +1 -1
  456. package/dist/mcp_view/screen.js +11 -11
  457. package/dist/mcp_view/screen.js.map +1 -1
  458. package/dist/mcp_view/tool_driver.d.ts +5 -34
  459. package/dist/mcp_view/tool_driver.js +17 -16
  460. package/dist/mcp_view/tool_driver.js.map +1 -1
  461. package/dist/mcp_view/write_review.d.ts +1 -2
  462. package/dist/mcp_view/write_review.js +1 -1
  463. package/dist/mcp_view/write_review.js.map +1 -1
  464. package/dist/preview/PropertyPreview.d.ts +1 -1
  465. package/dist/preview/PropertyPreview.js +4 -3
  466. package/dist/preview/PropertyPreview.js.map +1 -1
  467. package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
  468. package/dist/preview/components/ArrayEnumPreview.js.map +1 -1
  469. package/dist/preview/components/BooleanPreview.d.ts +1 -1
  470. package/dist/preview/components/BooleanPreview.js.map +1 -1
  471. package/dist/preview/components/EnumValuesChip.d.ts +1 -1
  472. package/dist/preview/components/EnumValuesChip.js +1 -1
  473. package/dist/preview/components/EnumValuesChip.js.map +1 -1
  474. package/dist/preview/components/ReferencePreview.d.ts +1 -1
  475. package/dist/preview/components/ReferencePreview.js.map +1 -1
  476. package/dist/preview/components/RelationPreview.d.ts +1 -1
  477. package/dist/preview/components/RelationPreview.js.map +1 -1
  478. package/dist/preview/components/StorageThumbnail.js +2 -1
  479. package/dist/preview/components/StorageThumbnail.js.map +1 -1
  480. package/dist/preview/components/UserPreview.d.ts +1 -1
  481. package/dist/preview/components/UserPreview.js.map +1 -1
  482. package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
  483. package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -1
  484. package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
  485. package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -1
  486. package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
  487. package/dist/preview/property_previews/ArrayOfRelationsPreview.js +2 -1
  488. package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -1
  489. package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
  490. package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -1
  491. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  492. package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -1
  493. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  494. package/dist/preview/property_previews/ArrayOneOfPreview.js +1 -1
  495. package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -1
  496. package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
  497. package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +1 -1
  498. package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -1
  499. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  500. package/dist/preview/property_previews/ArrayPropertyPreview.js +1 -1
  501. package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -1
  502. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  503. package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -1
  504. package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
  505. package/dist/preview/property_previews/NumberPropertyPreview.js +1 -1
  506. package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -1
  507. package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
  508. package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -1
  509. package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
  510. package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -1
  511. package/dist/preview/util.d.ts +1 -1
  512. package/dist/preview/util.js.map +1 -1
  513. package/dist/routes/RebaseRoute.js +2 -2
  514. package/dist/routes/RebaseRoute.js.map +1 -1
  515. package/dist/saved_apps/SavedAppsView.d.ts +1 -1
  516. package/dist/saved_apps/SavedAppsView.js +1 -1
  517. package/dist/saved_apps/SavedAppsView.js.map +1 -1
  518. package/dist/selection/SelectionMenu.d.ts +1 -1
  519. package/dist/selection/SelectionMenu.js.map +1 -1
  520. package/dist/selection/resolve_selection.d.ts +3 -3
  521. package/dist/selection/resolve_selection.js +3 -2
  522. package/dist/selection/resolve_selection.js.map +1 -1
  523. package/dist/tables/apply_customization.d.ts +65 -0
  524. package/dist/tables/apply_customization.js +644 -0
  525. package/dist/tables/apply_customization.js.map +1 -0
  526. package/dist/tables/column_property.d.ts +64 -0
  527. package/dist/tables/column_property.js +549 -0
  528. package/dist/tables/column_property.js.map +1 -0
  529. package/dist/tables/customize_table.d.ts +39 -0
  530. package/dist/tables/customize_table.js +247 -0
  531. package/dist/tables/customize_table.js.map +1 -0
  532. package/dist/tables/index.d.ts +12 -0
  533. package/dist/tables/labels.d.ts +18 -0
  534. package/dist/tables/labels.js +18 -0
  535. package/dist/tables/labels.js.map +1 -0
  536. package/dist/tables/project_table.d.ts +79 -0
  537. package/dist/tables/project_table.js +148 -0
  538. package/dist/tables/project_table.js.map +1 -0
  539. package/dist/tables/relations.d.ts +47 -0
  540. package/dist/tables/relations.js +112 -0
  541. package/dist/tables/relations.js.map +1 -0
  542. package/dist/tables/rls.d.ts +39 -0
  543. package/dist/tables/rls.js +111 -0
  544. package/dist/tables/rls.js.map +1 -0
  545. package/dist/tables/update_record.d.ts +32 -0
  546. package/dist/tables/update_record.js +40 -0
  547. package/dist/tables/update_record.js.map +1 -0
  548. package/dist/types/components/EntityFormActionsProps.d.ts +1 -1
  549. package/dist/types/components/PropertyPreviewProps.d.ts +2 -2
  550. package/dist/types/fields.d.ts +2 -2
  551. package/dist/util/dataControllerAdapter.js.map +1 -1
  552. package/dist/util/entity_pages.d.ts +2 -1
  553. package/dist/util/entity_pages.js.map +1 -1
  554. package/dist/util/find_entities_by_ids.d.ts +2 -2
  555. package/dist/util/find_entities_by_ids.js +1 -1
  556. package/dist/util/find_entities_by_ids.js.map +1 -1
  557. package/dist/util/format_collection_date.d.ts +1 -1
  558. package/dist/util/format_collection_date.js.map +1 -1
  559. package/dist/util/identity.d.ts +8 -0
  560. package/dist/util/identity.js +16 -0
  561. package/dist/util/identity.js.map +1 -0
  562. package/dist/util/navigation_utils.js +1 -1
  563. package/dist/util/navigation_utils.js.map +1 -1
  564. package/dist/util/previews.js +1 -1
  565. package/dist/util/previews.js.map +1 -1
  566. package/dist/util/propertyConfigMapper.d.ts +1 -1
  567. package/dist/util/propertyConfigMapper.js.map +1 -1
  568. package/dist/util/property_utils.d.ts +1 -3
  569. package/dist/util/property_utils.js +1 -1
  570. package/dist/util/property_utils.js.map +1 -1
  571. package/dist/util/relations.d.ts +18 -0
  572. package/dist/util/relations.js +32 -0
  573. package/dist/util/relations.js.map +1 -0
  574. package/package.json +12 -10
  575. package/recipes/README.md +4 -4
  576. package/recipes/my-preferences.tsx +34 -26
  577. package/recipes/site-settings.tsx +34 -27
  578. package/dist/collection_editor/collection_wire.d.ts +0 -13
  579. package/dist/collection_editor/collection_wire.js +0 -49
  580. package/dist/collection_editor/collection_wire.js.map +0 -1
  581. package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +0 -37
  582. package/dist/collection_editor/useJsonCollectionsConfigController.js +0 -191
  583. package/dist/collection_editor/useJsonCollectionsConfigController.js.map +0 -1
@@ -0,0 +1,247 @@
1
+ import { FIELD_COMPONENT_KEYS, FIELD_CUSTOMIZATION_KEYS, TABLE_CUSTOMIZATION_BRAND, TABLE_CUSTOMIZATION_KEYS } from "@rebasepro/cms-types";
2
+ //#region src/tables/customize_table.ts
3
+ /**
4
+ * `customizeTable`: a frontend file's deltas over the collection a Postgres
5
+ * table projects to (POSTGRES-FIRST.md §6.2).
6
+ *
7
+ * The types do the heavy checking — every key that names a field is checked
8
+ * against `typeof table` — so the runtime half is cheap and exists for the
9
+ * cases the compiler cannot see: a JavaScript caller, the untyped form, and the
10
+ * habits of the old `admin` block (a string component path, a lazy thunk,
11
+ * `propertiesOrder`). Each is refused with a message that says what to write.
12
+ */
13
+ /** Old `admin` names, and what each is called in `customizeTable`. */
14
+ var RENAMED_TABLE_KEYS = {
15
+ admin: "the same options at the top level — `customizeTable` has no `admin` block",
16
+ propertiesOrder: "`fieldOrder`",
17
+ listProperties: "`listFields`",
18
+ previewProperties: "`previewFields`",
19
+ properties: "`fields`",
20
+ orderProperty: "`kanban.orderField`",
21
+ titleProperty: "`display.title`",
22
+ slug: "the first argument of `customizeTable`",
23
+ callbacks: "`hooks` on `defineTable` (server hooks never ship to the browser)",
24
+ securityRules: "`rls` on `defineTable`"
25
+ };
26
+ /** Old property and property-`admin` names, and what each is called in a field customization. */
27
+ var RENAMED_FIELD_KEYS = {
28
+ admin: "the same options directly on the field — a field customization has no `admin` block",
29
+ hideFromCollection: "`hidden`",
30
+ previewProperties: "`previewFields`",
31
+ properties: "`fields`",
32
+ propertiesOrder: "`fieldOrder`",
33
+ enum: "`enumLabels` (the values themselves are the column's, on `defineTable`)",
34
+ validation: "`.validate({ … })` / `.notNull()` on the column",
35
+ storagePath: "`storage.path`",
36
+ type: "the column's builder on `defineTable`",
37
+ relation: "`relations` on `defineTable`",
38
+ userSelect: "`.userId()` on the column in `backend/schema` (who may pick users is a schema fact the server reads)"
39
+ };
40
+ var TABLE_KEYS = new Set(TABLE_CUSTOMIZATION_KEYS);
41
+ var FIELD_KEYS = new Set(FIELD_CUSTOMIZATION_KEYS);
42
+ var COMPONENT_KEYS = new Set(FIELD_COMPONENT_KEYS);
43
+ function isRecord(value) {
44
+ return typeof value === "object" && value !== null && !Array.isArray(value);
45
+ }
46
+ /** Levenshtein distance, for "did you mean". */
47
+ function distance(a, b) {
48
+ const row = Array.from({ length: b.length + 1 }, (_, i) => i);
49
+ for (let i = 1; i <= a.length; i++) {
50
+ let previous = row[0];
51
+ row[0] = i;
52
+ for (let j = 1; j <= b.length; j++) {
53
+ const current = row[j];
54
+ row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1].toLowerCase() === b[j - 1].toLowerCase() ? 0 : 1));
55
+ previous = current;
56
+ }
57
+ }
58
+ return row[b.length];
59
+ }
60
+ function suggestion(key, known, renamed) {
61
+ if (Object.prototype.hasOwnProperty.call(renamed, key)) return ` — it is ${renamed[key]} now`;
62
+ let best;
63
+ let bestDistance = 3;
64
+ for (const candidate of known) {
65
+ const d = distance(key, candidate);
66
+ if (d < bestDistance) {
67
+ best = candidate;
68
+ bestDistance = d;
69
+ }
70
+ }
71
+ return best ? ` — did you mean \`${best}\`?` : "";
72
+ }
73
+ function refuseUnknownKeys(value, known, renamed, where) {
74
+ const unknown = Object.keys(value).filter((key) => !known.has(key));
75
+ if (unknown.length === 0) return;
76
+ const lines = unknown.map((key) => ` - \`${key}\`${suggestion(key, known, renamed)}`);
77
+ throw new Error(`${where}: unknown option${unknown.length > 1 ? "s" : ""}:\n${lines.join("\n")}`);
78
+ }
79
+ /** The source of a function, for telling a lazy `() => import(…)` thunk from a component. */
80
+ function sourceOf(fn) {
81
+ try {
82
+ return Function.prototype.toString.call(fn);
83
+ } catch {
84
+ return "";
85
+ }
86
+ }
87
+ /** A function of no parameters… */
88
+ var NO_PARAMETERS = /^\s*(?:async\s*)?(?:function\s*\w*\s*)?\(\s*\)/;
89
+ /** …that loads a module: `import(…)` as written, or the `require(…)` a CommonJS build turns it into. */
90
+ var LOADS_A_MODULE = /\bimport\s*\(|\brequire\s*\(/;
91
+ function isLazyThunk(fn) {
92
+ const source = sourceOf(fn);
93
+ return NO_PARAMETERS.test(source) && LOADS_A_MODULE.test(source);
94
+ }
95
+ var BY_VALUE = "Components are imported by value now: `import { MyField } from \"./MyField\"`, then pass `MyField` itself. A frontend customization runs only in the browser, so string paths and lazy `() => import(…)` thunks are gone.";
96
+ /**
97
+ * Refuse anything that is not a React component value: a string path, a lazy
98
+ * thunk, or a plain object.
99
+ */
100
+ function assertComponent(value, where) {
101
+ if (value === void 0) return;
102
+ if (typeof value === "string") throw new Error(`${where} is the string ${JSON.stringify(value)}. ${BY_VALUE}`);
103
+ if (typeof value === "function") {
104
+ if (isLazyThunk(value)) throw new Error(`${where} is a lazy import thunk. ${BY_VALUE}`);
105
+ return;
106
+ }
107
+ if (isRecord(value) && "$$typeof" in value) return;
108
+ throw new Error(`${where} is not a React component. ${BY_VALUE}`);
109
+ }
110
+ function validateField(value, where) {
111
+ if (value === void 0) return;
112
+ if (!isRecord(value)) throw new Error(`${where} must be an object of field options, got ${JSON.stringify(value)}.`);
113
+ refuseUnknownKeys(value, FIELD_KEYS, RENAMED_FIELD_KEYS, where);
114
+ for (const key of COMPONENT_KEYS) assertComponent(value[key], `${where}.${key}`);
115
+ if (value.referenceTo !== void 0 && (typeof value.referenceTo !== "string" || value.referenceTo.length === 0)) throw new Error(`${where}.referenceTo must be the slug of the collection the column points at.`);
116
+ if (value.dynamicProps !== void 0 && typeof value.dynamicProps !== "function") throw new Error(`${where}.dynamicProps must be a function of the record's values.`);
117
+ for (const nested of ["fields", "oneOf"]) {
118
+ const map = value[nested];
119
+ if (map === void 0) continue;
120
+ if (!isRecord(map)) throw new Error(`${where}.${nested} must be an object keyed by ${nested === "fields" ? "key" : "variant"}.`);
121
+ for (const [key, field] of Object.entries(map)) validateField(field, `${where}.${nested}.${key}`);
122
+ }
123
+ validateField(value.of, `${where}.of`);
124
+ if (value.overrides !== void 0) validateOptions(value.overrides, `${where}.overrides`, false);
125
+ }
126
+ function validateEntries(value, where, check) {
127
+ if (value === void 0) return;
128
+ if (!Array.isArray(value)) throw new Error(`${where} must be a list.`);
129
+ value.forEach((entry, index) => {
130
+ if (typeof entry === "string") return;
131
+ const at = `${where}[${index}]`;
132
+ if (!isRecord(entry)) throw new Error(`${at} must be an object or the key of one registered app-wide.`);
133
+ check(entry, at);
134
+ });
135
+ }
136
+ function validateOptions(options, where, allowFields) {
137
+ if (!isRecord(options)) throw new Error(`${where} needs an object of options.`);
138
+ refuseUnknownKeys(options, TABLE_KEYS, RENAMED_TABLE_KEYS, where);
139
+ if (!allowFields && options.fields !== void 0) throw new Error(`${where}.fields: a relation's \`overrides\` restyle the tab, not the target's fields. Customize the target table's fields with its own \`customizeTable\`.`);
140
+ const kanban = options.kanban;
141
+ if (kanban !== void 0) {
142
+ if (!isRecord(kanban)) throw new Error(`${where}.kanban must be \`{ columnField, orderField }\`.`);
143
+ refuseUnknownKeys(kanban, /* @__PURE__ */ new Set(["columnField", "orderField"]), {
144
+ columnProperty: "`columnField`",
145
+ orderProperty: "`orderField`"
146
+ }, `${where}.kanban`);
147
+ if (typeof kanban.columnField !== "string") throw new Error(`${where}.kanban.columnField must name the column the board groups by.`);
148
+ }
149
+ validateEntries(options.entityActions, `${where}.entityActions`, (action, at) => {
150
+ if (typeof action.name !== "string") throw new Error(`${at} needs a \`name\`.`);
151
+ if (typeof action.onClick !== "function") throw new Error(`${at} needs an \`onClick\` function.`);
152
+ });
153
+ const resetPassword = options.resetPasswordAction;
154
+ if (resetPassword !== void 0 && resetPassword !== false) {
155
+ if (!isRecord(resetPassword)) throw new Error(`${where}.resetPasswordAction must be \`false\` (no reset-password action) or an action that replaces it.`);
156
+ if (typeof resetPassword.name !== "string") throw new Error(`${where}.resetPasswordAction needs a \`name\`.`);
157
+ if (typeof resetPassword.onClick !== "function") throw new Error(`${where}.resetPasswordAction needs an \`onClick\` function.`);
158
+ }
159
+ validateEntries(options.entityViews, `${where}.entityViews`, (view, at) => assertComponent(view.Builder, `${at}.Builder`));
160
+ validateEntries(options.customViews, `${where}.customViews`, (view, at) => {
161
+ if (view.Builder === void 0) throw new Error(`${at} needs a \`Builder\` component.`);
162
+ assertComponent(view.Builder, `${at}.Builder`);
163
+ });
164
+ const formView = options.formView;
165
+ if (formView !== void 0) {
166
+ if (!isRecord(formView)) throw new Error(`${where}.formView must be \`{ Builder }\`.`);
167
+ assertComponent(formView.Builder, `${where}.formView.Builder`);
168
+ }
169
+ const actions = options.Actions;
170
+ if (actions !== void 0) {
171
+ if (!Array.isArray(actions)) throw new Error(`${where}.Actions must be a list of components.`);
172
+ actions.forEach((component, index) => assertComponent(component, `${where}.Actions[${index}]`));
173
+ }
174
+ const components = options.components;
175
+ if (components !== void 0) {
176
+ if (!isRecord(components)) throw new Error(`${where}.components must be an object keyed by component name.`);
177
+ for (const [name, override] of Object.entries(components)) {
178
+ if (!isRecord(override)) throw new Error(`${where}.components["${name}"] must be \`{ Component, wrap? }\`.`);
179
+ assertComponent(override.Component, `${where}.components["${name}"].Component`);
180
+ }
181
+ }
182
+ const display = options.display;
183
+ if (display !== void 0) {
184
+ if (!isRecord(display)) throw new Error(`${where}.display must be an object of slots.`);
185
+ for (const [slot, source] of Object.entries(display)) if (source !== void 0 && typeof source !== "string" && typeof source !== "function") throw new Error(`${where}.display.${slot} must be a field path or a resolver function.`);
186
+ }
187
+ const fields = options.fields;
188
+ if (fields !== void 0) {
189
+ if (!isRecord(fields)) throw new Error(`${where}.fields must be an object keyed by column or relation.`);
190
+ for (const [key, field] of Object.entries(fields)) validateField(field, `${where}.fields.${key}`);
191
+ }
192
+ }
193
+ /** Freeze a plain object in place; components and functions are left alone. */
194
+ function freezeRecord(value) {
195
+ if (isRecord(value) && !("$$typeof" in value)) Object.freeze(value);
196
+ }
197
+ /**
198
+ * State what a table's default collection should look like in the panel.
199
+ *
200
+ * The first argument is the table's slug — the name it was defined under,
201
+ * unless `defineTable` was given another `slug`. With the type parameter every
202
+ * key that names a field, every enum label and every entity action's `row` is
203
+ * checked against the table:
204
+ *
205
+ * ```tsx
206
+ * export const postsCms = customizeTable<typeof posts>("posts", {
207
+ * icon: "FileText",
208
+ * kanban: { columnField: "status", orderField: "__order" },
209
+ * fields: { content: { Field: CustomMarkdownEditor } },
210
+ * });
211
+ * ```
212
+ *
213
+ * The slug is read from the table's type: for
214
+ * `defineTable("blog_posts", { slug: "posts", … })` the first argument is
215
+ * `"posts"`, still with the one type argument. Without a type argument the
216
+ * slug is any string and the options are accepted loosely typed.
217
+ *
218
+ * The result is frozen; pass it to `<RebaseCMS tableCustomizations>`. Unknown
219
+ * options, legacy `admin` names and components that are not values throw here,
220
+ * with what to write instead.
221
+ *
222
+ * @group Tables
223
+ */
224
+ function customizeTable(slug, options) {
225
+ if (typeof slug !== "string" || slug.length === 0) throw new Error("`customizeTable(slug, options)` needs the slug of the table it customizes as its first argument.");
226
+ validateOptions(options, `customizeTable("${slug}")`, true);
227
+ const fields = options.fields;
228
+ if (isRecord(fields)) {
229
+ for (const field of Object.values(fields)) freezeRecord(field);
230
+ Object.freeze(fields);
231
+ }
232
+ for (const key of [
233
+ "kanban",
234
+ "display",
235
+ "form",
236
+ "components"
237
+ ]) freezeRecord(options[key]);
238
+ return Object.freeze({
239
+ ...options,
240
+ brand: TABLE_CUSTOMIZATION_BRAND,
241
+ table: slug
242
+ });
243
+ }
244
+ //#endregion
245
+ export { customizeTable };
246
+
247
+ //# sourceMappingURL=customize_table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customize_table.js","names":[],"sources":["../../src/tables/customize_table.ts"],"sourcesContent":["/**\n * `customizeTable`: a frontend file's deltas over the collection a Postgres\n * table projects to (POSTGRES-FIRST.md §6.2).\n *\n * The types do the heavy checking — every key that names a field is checked\n * against `typeof table` — so the runtime half is cheap and exists for the\n * cases the compiler cannot see: a JavaScript caller, the untyped form, and the\n * habits of the old `admin` block (a string component path, a lazy thunk,\n * `propertiesOrder`). Each is refused with a message that says what to write.\n */\nimport {\n FIELD_COMPONENT_KEYS,\n FIELD_CUSTOMIZATION_KEYS,\n TABLE_CUSTOMIZATION_BRAND,\n TABLE_CUSTOMIZATION_KEYS,\n type CustomizableTable,\n type TableCustomization,\n type TableCustomizationOptions,\n type TableSlug\n} from \"@rebasepro/cms-types\";\n\n/** Old `admin` names, and what each is called in `customizeTable`. */\nconst RENAMED_TABLE_KEYS: Readonly<Record<string, string>> = {\n admin: \"the same options at the top level — `customizeTable` has no `admin` block\",\n propertiesOrder: \"`fieldOrder`\",\n listProperties: \"`listFields`\",\n previewProperties: \"`previewFields`\",\n properties: \"`fields`\",\n orderProperty: \"`kanban.orderField`\",\n titleProperty: \"`display.title`\",\n slug: \"the first argument of `customizeTable`\",\n callbacks: \"`hooks` on `defineTable` (server hooks never ship to the browser)\",\n securityRules: \"`rls` on `defineTable`\"\n};\n\n/** Old property and property-`admin` names, and what each is called in a field customization. */\nconst RENAMED_FIELD_KEYS: Readonly<Record<string, string>> = {\n admin: \"the same options directly on the field — a field customization has no `admin` block\",\n hideFromCollection: \"`hidden`\",\n previewProperties: \"`previewFields`\",\n properties: \"`fields`\",\n propertiesOrder: \"`fieldOrder`\",\n enum: \"`enumLabels` (the values themselves are the column's, on `defineTable`)\",\n validation: \"`.validate({ … })` / `.notNull()` on the column\",\n storagePath: \"`storage.path`\",\n type: \"the column's builder on `defineTable`\",\n relation: \"`relations` on `defineTable`\",\n userSelect: \"`.userId()` on the column in `backend/schema` (who may pick users is a schema fact the server reads)\"\n};\n\nconst TABLE_KEYS: ReadonlySet<string> = new Set(TABLE_CUSTOMIZATION_KEYS);\nconst FIELD_KEYS: ReadonlySet<string> = new Set(FIELD_CUSTOMIZATION_KEYS);\nconst COMPONENT_KEYS: ReadonlySet<string> = new Set(FIELD_COMPONENT_KEYS);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Levenshtein distance, for \"did you mean\". */\nfunction distance(a: string, b: string): number {\n const row = Array.from({ length: b.length + 1 }, (_, i) => i);\n for (let i = 1; i <= a.length; i++) {\n let previous = row[0];\n row[0] = i;\n for (let j = 1; j <= b.length; j++) {\n const current = row[j];\n row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1].toLowerCase() === b[j - 1].toLowerCase() ? 0 : 1));\n previous = current;\n }\n }\n return row[b.length];\n}\n\nfunction suggestion(key: string, known: ReadonlySet<string>, renamed: Readonly<Record<string, string>>): string {\n if (Object.prototype.hasOwnProperty.call(renamed, key)) return ` — it is ${renamed[key]} now`;\n let best: string | undefined;\n let bestDistance = 3;\n for (const candidate of known) {\n const d = distance(key, candidate);\n if (d < bestDistance) {\n best = candidate;\n bestDistance = d;\n }\n }\n return best ? ` — did you mean \\`${best}\\`?` : \"\";\n}\n\nfunction refuseUnknownKeys(\n value: Record<string, unknown>,\n known: ReadonlySet<string>,\n renamed: Readonly<Record<string, string>>,\n where: string\n): void {\n const unknown = Object.keys(value).filter(key => !known.has(key));\n if (unknown.length === 0) return;\n const lines = unknown.map(key => ` - \\`${key}\\`${suggestion(key, known, renamed)}`);\n throw new Error(`${where}: unknown option${unknown.length > 1 ? \"s\" : \"\"}:\\n${lines.join(\"\\n\")}`);\n}\n\n/** The source of a function, for telling a lazy `() => import(…)` thunk from a component. */\nfunction sourceOf(fn: unknown): string {\n try {\n return Function.prototype.toString.call(fn);\n } catch {\n return \"\";\n }\n}\n\n/** A function of no parameters… */\nconst NO_PARAMETERS = /^\\s*(?:async\\s*)?(?:function\\s*\\w*\\s*)?\\(\\s*\\)/;\n/** …that loads a module: `import(…)` as written, or the `require(…)` a CommonJS build turns it into. */\nconst LOADS_A_MODULE = /\\bimport\\s*\\(|\\brequire\\s*\\(/;\n\nfunction isLazyThunk(fn: unknown): boolean {\n const source = sourceOf(fn);\n return NO_PARAMETERS.test(source) && LOADS_A_MODULE.test(source);\n}\n\nconst BY_VALUE =\n \"Components are imported by value now: `import { MyField } from \\\"./MyField\\\"`, then pass `MyField` itself. \" +\n \"A frontend customization runs only in the browser, so string paths and lazy `() => import(…)` thunks are gone.\";\n\n/**\n * Refuse anything that is not a React component value: a string path, a lazy\n * thunk, or a plain object.\n */\nfunction assertComponent(value: unknown, where: string): void {\n if (value === undefined) return;\n if (typeof value === \"string\") {\n throw new Error(`${where} is the string ${JSON.stringify(value)}. ${BY_VALUE}`);\n }\n if (typeof value === \"function\") {\n if (isLazyThunk(value)) throw new Error(`${where} is a lazy import thunk. ${BY_VALUE}`);\n return;\n }\n // `memo`, `forwardRef` and `lazy` return objects tagged with `$$typeof`.\n if (isRecord(value) && \"$$typeof\" in value) return;\n throw new Error(`${where} is not a React component. ${BY_VALUE}`);\n}\n\nfunction validateField(value: unknown, where: string): void {\n if (value === undefined) return;\n if (!isRecord(value)) throw new Error(`${where} must be an object of field options, got ${JSON.stringify(value)}.`);\n refuseUnknownKeys(value, FIELD_KEYS, RENAMED_FIELD_KEYS, where);\n for (const key of COMPONENT_KEYS) assertComponent(value[key], `${where}.${key}`);\n if (value.referenceTo !== undefined && (typeof value.referenceTo !== \"string\" || value.referenceTo.length === 0)) {\n throw new Error(`${where}.referenceTo must be the slug of the collection the column points at.`);\n }\n if (value.dynamicProps !== undefined && typeof value.dynamicProps !== \"function\") {\n throw new Error(`${where}.dynamicProps must be a function of the record's values.`);\n }\n for (const nested of [\"fields\", \"oneOf\"] as const) {\n const map = value[nested];\n if (map === undefined) continue;\n if (!isRecord(map)) throw new Error(`${where}.${nested} must be an object keyed by ${nested === \"fields\" ? \"key\" : \"variant\"}.`);\n for (const [key, field] of Object.entries(map)) validateField(field, `${where}.${nested}.${key}`);\n }\n validateField(value.of, `${where}.of`);\n if (value.overrides !== undefined) validateOptions(value.overrides, `${where}.overrides`, false);\n}\n\nfunction validateEntries(value: unknown, where: string, check: (entry: Record<string, unknown>, at: string) => void): void {\n if (value === undefined) return;\n if (!Array.isArray(value)) throw new Error(`${where} must be a list.`);\n value.forEach((entry: unknown, index) => {\n if (typeof entry === \"string\") return;\n const at = `${where}[${index}]`;\n if (!isRecord(entry)) throw new Error(`${at} must be an object or the key of one registered app-wide.`);\n check(entry, at);\n });\n}\n\nfunction validateOptions(options: unknown, where: string, allowFields: boolean): void {\n if (!isRecord(options)) throw new Error(`${where} needs an object of options.`);\n refuseUnknownKeys(options, TABLE_KEYS, RENAMED_TABLE_KEYS, where);\n if (!allowFields && options.fields !== undefined) {\n throw new Error(`${where}.fields: a relation's \\`overrides\\` restyle the tab, not the target's fields. Customize the target table's fields with its own \\`customizeTable\\`.`);\n }\n\n const kanban = options.kanban;\n if (kanban !== undefined) {\n if (!isRecord(kanban)) throw new Error(`${where}.kanban must be \\`{ columnField, orderField }\\`.`);\n refuseUnknownKeys(kanban, new Set([\"columnField\", \"orderField\"]), { columnProperty: \"`columnField`\", orderProperty: \"`orderField`\" }, `${where}.kanban`);\n if (typeof kanban.columnField !== \"string\") throw new Error(`${where}.kanban.columnField must name the column the board groups by.`);\n }\n\n validateEntries(options.entityActions, `${where}.entityActions`, (action, at) => {\n if (typeof action.name !== \"string\") throw new Error(`${at} needs a \\`name\\`.`);\n if (typeof action.onClick !== \"function\") throw new Error(`${at} needs an \\`onClick\\` function.`);\n });\n const resetPassword = options.resetPasswordAction;\n if (resetPassword !== undefined && resetPassword !== false) {\n if (!isRecord(resetPassword)) throw new Error(`${where}.resetPasswordAction must be \\`false\\` (no reset-password action) or an action that replaces it.`);\n if (typeof resetPassword.name !== \"string\") throw new Error(`${where}.resetPasswordAction needs a \\`name\\`.`);\n if (typeof resetPassword.onClick !== \"function\") throw new Error(`${where}.resetPasswordAction needs an \\`onClick\\` function.`);\n }\n validateEntries(options.entityViews, `${where}.entityViews`, (view, at) => assertComponent(view.Builder, `${at}.Builder`));\n validateEntries(options.customViews, `${where}.customViews`, (view, at) => {\n if (view.Builder === undefined) throw new Error(`${at} needs a \\`Builder\\` component.`);\n assertComponent(view.Builder, `${at}.Builder`);\n });\n\n const formView = options.formView;\n if (formView !== undefined) {\n if (!isRecord(formView)) throw new Error(`${where}.formView must be \\`{ Builder }\\`.`);\n assertComponent(formView.Builder, `${where}.formView.Builder`);\n }\n\n const actions = options.Actions;\n if (actions !== undefined) {\n if (!Array.isArray(actions)) throw new Error(`${where}.Actions must be a list of components.`);\n actions.forEach((component: unknown, index) => assertComponent(component, `${where}.Actions[${index}]`));\n }\n\n const components = options.components;\n if (components !== undefined) {\n if (!isRecord(components)) throw new Error(`${where}.components must be an object keyed by component name.`);\n for (const [name, override] of Object.entries(components)) {\n if (!isRecord(override)) throw new Error(`${where}.components[\"${name}\"] must be \\`{ Component, wrap? }\\`.`);\n assertComponent(override.Component, `${where}.components[\"${name}\"].Component`);\n }\n }\n\n const display = options.display;\n if (display !== undefined) {\n if (!isRecord(display)) throw new Error(`${where}.display must be an object of slots.`);\n for (const [slot, source] of Object.entries(display)) {\n if (source !== undefined && typeof source !== \"string\" && typeof source !== \"function\") {\n throw new Error(`${where}.display.${slot} must be a field path or a resolver function.`);\n }\n }\n }\n\n const fields = options.fields;\n if (fields !== undefined) {\n if (!isRecord(fields)) throw new Error(`${where}.fields must be an object keyed by column or relation.`);\n for (const [key, field] of Object.entries(fields)) validateField(field, `${where}.fields.${key}`);\n }\n}\n\n/** Freeze a plain object in place; components and functions are left alone. */\nfunction freezeRecord(value: unknown): void {\n if (isRecord(value) && !(\"$$typeof\" in value)) Object.freeze(value);\n}\n\n/**\n * State what a table's default collection should look like in the panel.\n *\n * The first argument is the table's slug — the name it was defined under,\n * unless `defineTable` was given another `slug`. With the type parameter every\n * key that names a field, every enum label and every entity action's `row` is\n * checked against the table:\n *\n * ```tsx\n * export const postsCms = customizeTable<typeof posts>(\"posts\", {\n * icon: \"FileText\",\n * kanban: { columnField: \"status\", orderField: \"__order\" },\n * fields: { content: { Field: CustomMarkdownEditor } },\n * });\n * ```\n *\n * The slug is read from the table's type: for\n * `defineTable(\"blog_posts\", { slug: \"posts\", … })` the first argument is\n * `\"posts\"`, still with the one type argument. Without a type argument the\n * slug is any string and the options are accepted loosely typed.\n *\n * The result is frozen; pass it to `<RebaseCMS tableCustomizations>`. Unknown\n * options, legacy `admin` names and components that are not values throw here,\n * with what to write instead.\n *\n * @group Tables\n */\nexport function customizeTable<T extends CustomizableTable | undefined = undefined>(\n slug: TableSlug<T>,\n options: NoInfer<TableCustomizationOptions<T>>\n): TableCustomization<T> {\n if (typeof slug !== \"string\" || slug.length === 0) {\n throw new Error(\"`customizeTable(slug, options)` needs the slug of the table it customizes as its first argument.\");\n }\n const where = `customizeTable(\"${slug}\")`;\n validateOptions(options, where, true);\n\n const fields: unknown = options.fields;\n if (isRecord(fields)) {\n for (const field of Object.values(fields)) freezeRecord(field);\n Object.freeze(fields);\n }\n for (const key of [\"kanban\", \"display\", \"form\", \"components\"] as const) freezeRecord(options[key]);\n\n return Object.freeze({ ...options, brand: TABLE_CUSTOMIZATION_BRAND, table: slug });\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,IAAM,qBAAuD;CACzD,OAAO;CACP,iBAAiB;CACjB,gBAAgB;CAChB,mBAAmB;CACnB,YAAY;CACZ,eAAe;CACf,eAAe;CACf,MAAM;CACN,WAAW;CACX,eAAe;AACnB;;AAGA,IAAM,qBAAuD;CACzD,OAAO;CACP,oBAAoB;CACpB,mBAAmB;CACnB,YAAY;CACZ,iBAAiB;CACjB,MAAM;CACN,YAAY;CACZ,aAAa;CACb,MAAM;CACN,UAAU;CACV,YAAY;AAChB;AAEA,IAAM,aAAkC,IAAI,IAAI,wBAAwB;AACxE,IAAM,aAAkC,IAAI,IAAI,wBAAwB;AACxE,IAAM,iBAAsC,IAAI,IAAI,oBAAoB;AAExE,SAAS,SAAS,OAAkD;CAChE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC9E;;AAGA,SAAS,SAAS,GAAW,GAAmB;CAC5C,MAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC5D,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,QAAQ,KAAK;EAChC,IAAI,WAAW,IAAI;EACnB,IAAI,KAAK;EACT,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,QAAQ,KAAK;GAChC,MAAM,UAAU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;CAAY,GAAY,aAAa,QAAQ,IAAI;CAEjG,OAAO,OAAO,OAAO;EAAE,GAAG;EAAS,OAAO;EAA2B,OAAO;CAAK,CAAC;AACtF"}
@@ -0,0 +1,12 @@
1
+ export { collectionFromTable, collectionsFromTables } from "./project_table.js";
2
+ export type { ProjectedCollection, TableProjectionContext, TableProjectionOptions } from "./project_table.js";
3
+ export { tableLabels } from "./labels.js";
4
+ export { enumValueColor, enumValuesFrom, jsonNodeProperty, propertyFromColumn, storageConfigFrom } from "./column_property.js";
5
+ export type { ColumnProjectionContext } from "./column_property.js";
6
+ export { projectRelations } from "./relations.js";
7
+ export type { ProjectedRelation, TargetResolver } from "./relations.js";
8
+ export { securityRulesFromRls } from "./rls.js";
9
+ export { customizeTable } from "./customize_table.js";
10
+ export { applyTableCustomization, applyTableCustomizations } from "./apply_customization.js";
11
+ export type { TableCollection } from "./apply_customization.js";
12
+ export { updateRecord } from "./update_record.js";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A projected table's names, derived from the name it was defined under.
3
+ *
4
+ * The rule itself — how an identifier reads — is `labelFromIdentifier` /
5
+ * `singularLabel` in `@rebasepro/utils`, shared with the collections-to-tables
6
+ * codemod so the two never disagree about what a "derived" label is.
7
+ * `customizeTable` replaces any of them.
8
+ */
9
+ import type { TableDescriptor } from "@rebasepro/types";
10
+ /**
11
+ * A table's plural and singular names: `order_items` → "Order Items" /
12
+ * "Order Item". Read from the name the table was defined under, which is the
13
+ * one an author chose; the slug and SQL name are derived from it.
14
+ */
15
+ export declare function tableLabels(table: Pick<TableDescriptor, "name">): {
16
+ name: string;
17
+ singularName: string;
18
+ };
@@ -0,0 +1,18 @@
1
+ import { labelFromIdentifier, singularLabel } from "@rebasepro/utils";
2
+ //#region src/tables/labels.ts
3
+ /**
4
+ * A table's plural and singular names: `order_items` → "Order Items" /
5
+ * "Order Item". Read from the name the table was defined under, which is the
6
+ * one an author chose; the slug and SQL name are derived from it.
7
+ */
8
+ function tableLabels(table) {
9
+ const name = labelFromIdentifier(table.name);
10
+ return {
11
+ name,
12
+ singularName: singularLabel(name)
13
+ };
14
+ }
15
+ //#endregion
16
+ export { tableLabels };
17
+
18
+ //# sourceMappingURL=labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.js","names":[],"sources":["../../src/tables/labels.ts"],"sourcesContent":["/**\n * A projected table's names, derived from the name it was defined under.\n *\n * The rule itself — how an identifier reads — is `labelFromIdentifier` /\n * `singularLabel` in `@rebasepro/utils`, shared with the collections-to-tables\n * codemod so the two never disagree about what a \"derived\" label is.\n * `customizeTable` replaces any of them.\n */\nimport type { TableDescriptor } from \"@rebasepro/types\";\nimport { labelFromIdentifier, singularLabel } from \"@rebasepro/utils\";\n\n/**\n * A table's plural and singular names: `order_items` → \"Order Items\" /\n * \"Order Item\". Read from the name the table was defined under, which is the\n * one an author chose; the slug and SQL name are derived from it.\n */\nexport function tableLabels(table: Pick<TableDescriptor, \"name\">): { name: string; singularName: string } {\n const name = labelFromIdentifier(table.name);\n return { name, singularName: singularLabel(name) };\n}\n"],"mappings":";;;;;;;AAgBA,SAAgB,YAAY,OAA8E;CACtG,MAAM,OAAO,oBAAoB,MAAM,IAAI;CAC3C,OAAO;EAAE;EAAM,cAAc,cAAc,IAAI;CAAE;AACrD"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The projector: a {@link TableDescriptor} from `GET /api/schema/tables`
3
+ * becomes the panel's default collection, with no frontend configuration
4
+ * (POSTGRES-FIRST.md §6.1).
5
+ *
6
+ * The panel keeps its own view model — a flat collection of `Property`s — and
7
+ * every view keeps reading it unchanged; this module is the one place a
8
+ * descriptor is translated into it. Identity is never re-derived: the
9
+ * collection's slug is the descriptor's slug and every property key is a
10
+ * column key or a relation name, because saved layouts, favourites, URLs and
11
+ * API calls are all keyed by them.
12
+ *
13
+ * Presentation is the panel's, not the projector's. A projected collection
14
+ * states a presentation key only where the table states a fact that implies it
15
+ * (a column type, a validation rule, a storage column, a stamp, a relation);
16
+ * everything else — the view mode, how a record opens, the display slots, the
17
+ * columns shown — is left unset, so a table opens exactly as an authored
18
+ * collection that said nothing did, and `customizeTable` is where a project
19
+ * chooses otherwise. The one stated default beyond the facts is POSTGRES-FIRST.md
20
+ * §6.1's: audit stamps (`createdAt`/`updatedAt`) are left out of the default
21
+ * table columns.
22
+ */
23
+ import type { TableDescriptor } from "@rebasepro/types";
24
+ import type { AdminPostgresCollection, AnyCollectionConfig } from "@rebasepro/cms-types";
25
+ /**
26
+ * What a table projects to: the panel's collection view model.
27
+ *
28
+ * @group Tables
29
+ */
30
+ export type ProjectedCollection = AdminPostgresCollection;
31
+ /**
32
+ * What a projection reads besides the table itself.
33
+ *
34
+ * @group Tables
35
+ */
36
+ export interface TableProjectionContext {
37
+ /**
38
+ * Every table the caller was served. Relation targets are resolved among
39
+ * them by slug; a relation to a table not listed here is left out.
40
+ */
41
+ tables: readonly TableDescriptor[];
42
+ }
43
+ /**
44
+ * How {@link collectionsFromTables} resolves relation targets.
45
+ *
46
+ * @group Tables
47
+ */
48
+ export interface TableProjectionOptions {
49
+ /**
50
+ * The collection a relation to the table `slug` opens, when it is not the
51
+ * bare projection: the panel passes the composed collection (projected,
52
+ * customized, with the workspace's preferences), so a relation's picker,
53
+ * preview and tab read the target as the panel shows it — what an authored
54
+ * collection's `target: () => other` handed them. Read lazily, each time a
55
+ * relation's `target()` is called; `undefined` falls back to the
56
+ * projection.
57
+ */
58
+ targetCollection?: (slug: string) => AnyCollectionConfig | undefined;
59
+ }
60
+ /**
61
+ * One table as the panel's default collection.
62
+ *
63
+ * Relation targets are resolved among `context.tables` by slug, lazily, so
64
+ * tables that point at each other project without a cycle. A target the
65
+ * caller was not served degrades: a `belongsTo` keeps its foreign key as a
66
+ * plain field, any other relation is left out.
67
+ *
68
+ * @group Tables
69
+ */
70
+ export declare function collectionFromTable(table: TableDescriptor, context: TableProjectionContext): ProjectedCollection;
71
+ /**
72
+ * Every table as the panel's default collection, in the order served. Tables
73
+ * that relate to each other share one projection, so a relation's target is
74
+ * the very collection listed beside it — or, with
75
+ * `options.targetCollection`, the collection the caller composed from it.
76
+ *
77
+ * @group Tables
78
+ */
79
+ export declare function collectionsFromTables(tables: readonly TableDescriptor[], options?: TableProjectionOptions): ProjectedCollection[];
@@ -0,0 +1,148 @@
1
+ import { tableLabels } from "./labels.js";
2
+ import { enumValuesFrom, propertyFromColumn } from "./column_property.js";
3
+ import { projectRelations } from "./relations.js";
4
+ import { securityRulesFromRls } from "./rls.js";
5
+ //#region src/tables/project_table.ts
6
+ /**
7
+ * The auth table's `roles` column, given the roles the auth table declares as
8
+ * its options — what the scaffolded users collection spelled by hand.
9
+ */
10
+ function withDeclaredRoles(properties, table) {
11
+ const declared = table.auth?.roles ? Object.keys(table.auth.roles) : [];
12
+ const roles = properties.roles;
13
+ if (declared.length === 0 || roles?.type !== "array" || Array.isArray(roles.of)) return;
14
+ const item = roles.of;
15
+ if (item?.type !== "string" || item.enum) return;
16
+ roles.of = {
17
+ ...item,
18
+ enum: enumValuesFrom(declared)
19
+ };
20
+ }
21
+ function authConfig(table) {
22
+ if (!table.auth) return void 0;
23
+ return {
24
+ enabled: true,
25
+ ...table.auth.roles ? { roles: table.auth.roles } : {},
26
+ ...table.auth.scopes ? { scopes: table.auth.scopes } : {},
27
+ ...table.auth.personalKeys !== void 0 ? { personalKeys: table.auth.personalKeys } : {}
28
+ };
29
+ }
30
+ /** Projects tables lazily, once each, resolving relation targets by slug. */
31
+ var Projection = class {
32
+ targetCollection;
33
+ bySlug = /* @__PURE__ */ new Map();
34
+ projected = /* @__PURE__ */ new Map();
35
+ resolveTarget = {
36
+ has: (slug) => this.bySlug.has(slug),
37
+ get: (slug) => {
38
+ const table = this.bySlug.get(slug);
39
+ if (!table) return void 0;
40
+ return this.targetCollection?.(slug) ?? this.project(table);
41
+ }
42
+ };
43
+ constructor(tables, targetCollection) {
44
+ this.targetCollection = targetCollection;
45
+ for (const table of tables) if (!this.bySlug.has(table.slug)) this.bySlug.set(table.slug, table);
46
+ }
47
+ /** Lets a table outside the served list resolve relations to itself. */
48
+ include(table) {
49
+ if (!this.bySlug.has(table.slug)) this.bySlug.set(table.slug, table);
50
+ }
51
+ project(table) {
52
+ const done = this.projected.get(table);
53
+ if (done) return done;
54
+ const collection = build(table, this.resolveTarget);
55
+ this.projected.set(table, collection);
56
+ return collection;
57
+ }
58
+ };
59
+ function build(table, resolveTarget) {
60
+ const relations = projectRelations(table, resolveTarget);
61
+ const replacing = new Map(relations.filter((r) => r.replacesColumn).map((r) => [r.replacesColumn, r]));
62
+ const columnKeys = new Set(table.columns.map((column) => column.key));
63
+ const properties = {};
64
+ for (const column of table.columns) {
65
+ const relation = replacing.get(column.key);
66
+ if (relation) {
67
+ properties[relation.key] = relation.property;
68
+ continue;
69
+ }
70
+ const property = propertyFromColumn(column, {
71
+ primaryKey: table.primaryKey,
72
+ tenantField: table.tenant?.field
73
+ });
74
+ if (!property) continue;
75
+ properties[column.key] = property;
76
+ }
77
+ for (const relation of relations) {
78
+ if (relation.replacesColumn) continue;
79
+ if (columnKeys.has(relation.key)) continue;
80
+ properties[relation.key] = relation.property;
81
+ }
82
+ const tenantRelation = table.tenant ? replacing.get(table.tenant.field) : void 0;
83
+ if (tenantRelation) tenantRelation.property.admin = {
84
+ ...tenantRelation.property.admin,
85
+ filledByServer: true
86
+ };
87
+ withDeclaredRoles(properties, table);
88
+ const { name, singularName } = tableLabels(table);
89
+ const auth = authConfig(table);
90
+ return {
91
+ slug: table.slug,
92
+ name,
93
+ singularName,
94
+ table: table.table,
95
+ schema: table.schema,
96
+ properties,
97
+ securityRules: securityRulesFromRls(table, { properties }),
98
+ ...table.description ? { description: table.description } : {},
99
+ ...table.database ? { dataSource: table.database } : {},
100
+ ...table.history ? { history: true } : {},
101
+ ...table.search ? { search: table.search } : {},
102
+ ...table.softDelete ? { softDelete: { field: table.softDelete.field } } : {},
103
+ ...table.tenant ? { tenant: {
104
+ field: table.tenant.field,
105
+ from: table.tenant.from,
106
+ ...table.tenant.bypassRoles ? { bypassRoles: table.tenant.bypassRoles } : {}
107
+ } } : {},
108
+ ...auth ? { auth } : {},
109
+ ...table.view ? { view: {
110
+ query: table.view.query ?? "",
111
+ materialized: table.view.materialized,
112
+ ...table.view.roles ? { roles: [...table.view.roles] } : {}
113
+ } } : {},
114
+ ...table.strictWrites === false ? { strictWrites: false } : {},
115
+ ...table.metadata ? { metadata: table.metadata } : {}
116
+ };
117
+ }
118
+ /**
119
+ * One table as the panel's default collection.
120
+ *
121
+ * Relation targets are resolved among `context.tables` by slug, lazily, so
122
+ * tables that point at each other project without a cycle. A target the
123
+ * caller was not served degrades: a `belongsTo` keeps its foreign key as a
124
+ * plain field, any other relation is left out.
125
+ *
126
+ * @group Tables
127
+ */
128
+ function collectionFromTable(table, context) {
129
+ const projection = new Projection(context.tables);
130
+ projection.include(table);
131
+ return projection.project(table);
132
+ }
133
+ /**
134
+ * Every table as the panel's default collection, in the order served. Tables
135
+ * that relate to each other share one projection, so a relation's target is
136
+ * the very collection listed beside it — or, with
137
+ * `options.targetCollection`, the collection the caller composed from it.
138
+ *
139
+ * @group Tables
140
+ */
141
+ function collectionsFromTables(tables, options = {}) {
142
+ const projection = new Projection(tables, options.targetCollection);
143
+ return tables.map((table) => projection.project(table));
144
+ }
145
+ //#endregion
146
+ export { collectionFromTable, collectionsFromTables };
147
+
148
+ //# sourceMappingURL=project_table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project_table.js","names":[],"sources":["../../src/tables/project_table.ts"],"sourcesContent":["/**\n * The projector: a {@link TableDescriptor} from `GET /api/schema/tables`\n * becomes the panel's default collection, with no frontend configuration\n * (POSTGRES-FIRST.md §6.1).\n *\n * The panel keeps its own view model — a flat collection of `Property`s — and\n * every view keeps reading it unchanged; this module is the one place a\n * descriptor is translated into it. Identity is never re-derived: the\n * collection's slug is the descriptor's slug and every property key is a\n * column key or a relation name, because saved layouts, favourites, URLs and\n * API calls are all keyed by them.\n *\n * Presentation is the panel's, not the projector's. A projected collection\n * states a presentation key only where the table states a fact that implies it\n * (a column type, a validation rule, a storage column, a stamp, a relation);\n * everything else — the view mode, how a record opens, the display slots, the\n * columns shown — is left unset, so a table opens exactly as an authored\n * collection that said nothing did, and `customizeTable` is where a project\n * chooses otherwise. The one stated default beyond the facts is POSTGRES-FIRST.md\n * §6.1's: audit stamps (`createdAt`/`updatedAt`) are left out of the default\n * table columns.\n */\nimport type {\n TableDescriptor\n} from \"@rebasepro/types\";\nimport type { AdminPostgresCollection, AnyCollectionConfig, AuthCollectionConfig, PostgresProperties } from \"@rebasepro/cms-types\";\nimport { tableLabels } from \"./labels\";\nimport { enumValuesFrom, propertyFromColumn } from \"./column_property\";\nimport { projectRelations, type TargetResolver } from \"./relations\";\nimport { securityRulesFromRls } from \"./rls\";\n\n/**\n * What a table projects to: the panel's collection view model.\n *\n * @group Tables\n */\nexport type ProjectedCollection = AdminPostgresCollection;\n\n/**\n * What a projection reads besides the table itself.\n *\n * @group Tables\n */\nexport interface TableProjectionContext {\n /**\n * Every table the caller was served. Relation targets are resolved among\n * them by slug; a relation to a table not listed here is left out.\n */\n tables: readonly TableDescriptor[];\n}\n\n/**\n * How {@link collectionsFromTables} resolves relation targets.\n *\n * @group Tables\n */\nexport interface TableProjectionOptions {\n /**\n * The collection a relation to the table `slug` opens, when it is not the\n * bare projection: the panel passes the composed collection (projected,\n * customized, with the workspace's preferences), so a relation's picker,\n * preview and tab read the target as the panel shows it — what an authored\n * collection's `target: () => other` handed them. Read lazily, each time a\n * relation's `target()` is called; `undefined` falls back to the\n * projection.\n */\n targetCollection?: (slug: string) => AnyCollectionConfig | undefined;\n}\n\n/**\n * The auth table's `roles` column, given the roles the auth table declares as\n * its options — what the scaffolded users collection spelled by hand.\n */\nfunction withDeclaredRoles(properties: PostgresProperties, table: TableDescriptor): void {\n const declared = table.auth?.roles ? Object.keys(table.auth.roles) : [];\n const roles = properties.roles;\n if (declared.length === 0 || roles?.type !== \"array\" || Array.isArray(roles.of)) return;\n const item = roles.of;\n if (item?.type !== \"string\" || item.enum) return;\n roles.of = { ...item, enum: enumValuesFrom(declared) };\n}\n\nfunction authConfig(table: TableDescriptor): AuthCollectionConfig | undefined {\n if (!table.auth) return undefined;\n return {\n enabled: true,\n ...(table.auth.roles ? { roles: table.auth.roles } : {}),\n ...(table.auth.scopes ? { scopes: table.auth.scopes } : {}),\n ...(table.auth.personalKeys !== undefined ? { personalKeys: table.auth.personalKeys } : {})\n };\n}\n\n/** Projects tables lazily, once each, resolving relation targets by slug. */\nclass Projection {\n private readonly bySlug = new Map<string, TableDescriptor>();\n private readonly projected = new Map<TableDescriptor, ProjectedCollection>();\n private readonly resolveTarget: TargetResolver = {\n has: (slug) => this.bySlug.has(slug),\n get: (slug) => {\n const table = this.bySlug.get(slug);\n if (!table) return undefined;\n return this.targetCollection?.(slug) ?? this.project(table);\n }\n };\n\n constructor(\n tables: readonly TableDescriptor[],\n private readonly targetCollection?: TableProjectionOptions[\"targetCollection\"]\n ) {\n for (const table of tables) {\n if (!this.bySlug.has(table.slug)) this.bySlug.set(table.slug, table);\n }\n }\n\n /** Lets a table outside the served list resolve relations to itself. */\n include(table: TableDescriptor): void {\n if (!this.bySlug.has(table.slug)) this.bySlug.set(table.slug, table);\n }\n\n project(table: TableDescriptor): ProjectedCollection {\n const done = this.projected.get(table);\n if (done) return done;\n const collection = build(table, this.resolveTarget);\n this.projected.set(table, collection);\n return collection;\n }\n}\n\nfunction build(table: TableDescriptor, resolveTarget: TargetResolver): ProjectedCollection {\n const relations = projectRelations(table, resolveTarget);\n const replacing = new Map(relations.filter(r => r.replacesColumn).map(r => [r.replacesColumn, r]));\n const columnKeys = new Set(table.columns.map(column => column.key));\n\n const properties: PostgresProperties = {};\n for (const column of table.columns) {\n const relation = replacing.get(column.key);\n if (relation) {\n properties[relation.key] = relation.property;\n continue;\n }\n const property = propertyFromColumn(column, { primaryKey: table.primaryKey, tenantField: table.tenant?.field });\n if (!property) continue;\n properties[column.key] = property;\n }\n for (const relation of relations) {\n if (relation.replacesColumn) continue;\n // A relation never takes the key of a column: the column's key is what\n // rows and saved layouts already use.\n if (columnKeys.has(relation.key)) continue;\n properties[relation.key] = relation.property;\n }\n\n // The tenant column replaced by its relation is still the tenant column.\n const tenantRelation = table.tenant ? replacing.get(table.tenant.field) : undefined;\n if (tenantRelation) {\n tenantRelation.property.admin = { ...tenantRelation.property.admin, filledByServer: true };\n }\n\n withDeclaredRoles(properties, table);\n\n const { name, singularName } = tableLabels(table);\n const auth = authConfig(table);\n\n const collection: ProjectedCollection = {\n slug: table.slug,\n name,\n singularName,\n table: table.table,\n schema: table.schema,\n properties,\n securityRules: securityRulesFromRls(table, { properties }),\n ...(table.description ? { description: table.description } : {}),\n ...(table.database ? { dataSource: table.database } : {}),\n ...(table.history ? { history: true } : {}),\n ...(table.search ? { search: table.search } : {}),\n ...(table.softDelete ? { softDelete: { field: table.softDelete.field } } : {}),\n ...(table.tenant\n ? {\n tenant: {\n field: table.tenant.field,\n from: table.tenant.from,\n ...(table.tenant.bypassRoles ? { bypassRoles: table.tenant.bypassRoles } : {})\n }\n }\n : {}),\n ...(auth ? { auth } : {}),\n ...(table.view\n ? {\n view: {\n query: table.view.query ?? \"\",\n materialized: table.view.materialized,\n ...(table.view.roles ? { roles: [...table.view.roles] } : {})\n }\n }\n : {}),\n ...(table.strictWrites === false ? { strictWrites: false } : {}),\n ...(table.metadata ? { metadata: table.metadata } : {})\n };\n return collection;\n}\n\n/**\n * One table as the panel's default collection.\n *\n * Relation targets are resolved among `context.tables` by slug, lazily, so\n * tables that point at each other project without a cycle. A target the\n * caller was not served degrades: a `belongsTo` keeps its foreign key as a\n * plain field, any other relation is left out.\n *\n * @group Tables\n */\nexport function collectionFromTable(table: TableDescriptor, context: TableProjectionContext): ProjectedCollection {\n const projection = new Projection(context.tables);\n projection.include(table);\n return projection.project(table);\n}\n\n/**\n * Every table as the panel's default collection, in the order served. Tables\n * that relate to each other share one projection, so a relation's target is\n * the very collection listed beside it — or, with\n * `options.targetCollection`, the collection the caller composed from it.\n *\n * @group Tables\n */\nexport function collectionsFromTables(tables: readonly TableDescriptor[], options: TableProjectionOptions = {}): ProjectedCollection[] {\n const projection = new Projection(tables, options.targetCollection);\n return tables.map(table => projection.project(table));\n}\n"],"mappings":";;;;;;;;;AAyEA,SAAS,kBAAkB,YAAgC,OAA8B;CACrF,MAAM,WAAW,MAAM,MAAM,QAAQ,OAAO,KAAK,MAAM,KAAK,KAAK,IAAI,CAAC;CACtE,MAAM,QAAQ,WAAW;CACzB,IAAI,SAAS,WAAW,KAAK,OAAO,SAAS,WAAW,MAAM,QAAQ,MAAM,EAAE,GAAG;CACjF,MAAM,OAAO,MAAM;CACnB,IAAI,MAAM,SAAS,YAAY,KAAK,MAAM;CAC1C,MAAM,KAAK;EAAE,GAAG;EAAM,MAAM,eAAe,QAAQ;CAAE;AACzD;AAEA,SAAS,WAAW,OAA0D;CAC1E,IAAI,CAAC,MAAM,MAAM,OAAO,KAAA;CACxB,OAAO;EACH,SAAS;EACT,GAAI,MAAM,KAAK,QAAQ,EAAE,OAAO,MAAM,KAAK,MAAM,IAAI,CAAC;EACtD,GAAI,MAAM,KAAK,SAAS,EAAE,QAAQ,MAAM,KAAK,OAAO,IAAI,CAAC;EACzD,GAAI,MAAM,KAAK,iBAAiB,KAAA,IAAY,EAAE,cAAc,MAAM,KAAK,aAAa,IAAI,CAAC;CAC7F;AACJ;;AAGA,IAAM,aAAN,MAAiB;CAcQ;CAbrB,yBAA0B,IAAI,IAA6B;CAC3D,4BAA6B,IAAI,IAA0C;CAC3E,gBAAiD;EAC7C,MAAM,SAAS,KAAK,OAAO,IAAI,IAAI;EACnC,MAAM,SAAS;GACX,MAAM,QAAQ,KAAK,OAAO,IAAI,IAAI;GAClC,IAAI,CAAC,OAAO,OAAO,KAAA;GACnB,OAAO,KAAK,mBAAmB,IAAI,KAAK,KAAK,QAAQ,KAAK;EAC9D;CACJ;CAEA,YACI,QACA,kBACF;EADmB,KAAA,mBAAA;EAE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M,aAAa,IAAI,WAAW,QAAQ,MAAM;CAChD,WAAW,QAAQ,KAAK;CACxB,OAAO,WAAW,QAAQ,KAAK;AACnC;;;;;;;;;AAUA,SAAgB,sBAAsB,QAAoC,UAAkC,CAAC,GAA0B;CACnI,MAAM,aAAa,IAAI,WAAW,QAAQ,QAAQ,gBAAgB;CAClE,OAAO,OAAO,KAAI,UAAS,WAAW,QAAQ,KAAK,CAAC;AACxD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A table's relations as the panel's relation properties.
3
+ *
4
+ * Each relation becomes a `type: "relation"` property keyed by the relation's
5
+ * name — the documented way an authored collection declares one, and the key
6
+ * saved layouts, `include` and the entity tabs address it by. The panel then
7
+ * does what it does for an authored collection: a to-one relation is a
8
+ * reference picker, a to-many one is a tab in the entity view
9
+ * (`getEntityChildViews`), with the redundant picker beside it hidden.
10
+ */
11
+ import type { TableDescriptor } from "@rebasepro/types";
12
+ import type { AnyCollectionConfig, RelationProperty } from "@rebasepro/cms-types";
13
+ /**
14
+ * The tables a relation may point at: whether one was served, and the
15
+ * collection it projects to. `has` must not project anything, so a table can
16
+ * point at itself.
17
+ */
18
+ export interface TargetResolver {
19
+ has(slug: string): boolean;
20
+ get(slug: string): AnyCollectionConfig | undefined;
21
+ }
22
+ /**
23
+ * A relation, projected: its property, and — for a `belongsTo` — the key of
24
+ * the foreign-key column it stands in for.
25
+ */
26
+ export interface ProjectedRelation {
27
+ /** The relation's name: the property key. */
28
+ key: string;
29
+ property: RelationProperty;
30
+ /**
31
+ * The column the relation replaces in the form and the table. Set for a
32
+ * `belongsTo` whose foreign key is not part of the primary key: the picker
33
+ * edits that column, so the raw key is not rendered as a second field.
34
+ */
35
+ replacesColumn?: string;
36
+ }
37
+ /**
38
+ * The relations of a table the caller can follow, as properties.
39
+ *
40
+ * A relation whose target is not among the tables the caller was served is
41
+ * left out: the panel cannot open a table it does not have. A `belongsTo`
42
+ * then leaves its foreign-key column in place as a plain key field, so the
43
+ * value stays visible and editable. A `belongsTo` whose foreign-key column did
44
+ * not arrive (the caller may not read it) is left out too: there is nothing to
45
+ * pick a row into.
46
+ */
47
+ export declare function projectRelations(table: TableDescriptor, resolveTarget: TargetResolver): ProjectedRelation[];