@rebasepro/cms 0.30.1 → 0.31.0-canary.g902a0ce

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,339 @@
1
+ import { SplitEditError } from "./split_edit_error.js";
2
+ import { FIRESTORE_COLLECTION_CALLEE } from "./firestore_callee.js";
3
+ import { sameValue } from "./split_edit.js";
4
+ import { nestAdminCollectionKeys, nestAdminPropertyKeys } from "@rebasepro/cms-types";
5
+ //#region src/collection_editor/firestore_edit.ts
6
+ /**
7
+ * One save of the collection editor on a Firestore collection, as
8
+ * {@link FirestoreCollectionPatch} operations — and those operations as the
9
+ * edit the dev server's frontend source editor makes to the collection's
10
+ * `defineFirestoreCollection({...})` call.
11
+ *
12
+ * A Firestore collection has no server schema: what the editor shows is the
13
+ * frontend definition, normalised (`required` → `validation.required`, a
14
+ * reference's `target` → `path`, the `admin` block flattened). A save is
15
+ * therefore entirely an edit of that definition, written back in the
16
+ * definition's own vocabulary, at the smallest path that changed, so every
17
+ * key the person did not touch stays as written — functions and components
18
+ * included, which are never part of an edit.
19
+ *
20
+ * The module is pure.
21
+ *
22
+ * @module
23
+ */
24
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
25
+ var isPlain = (value) => isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
26
+ /** `value` as JSON, `undefined` for absent; code and class instances are refused with where they are. */
27
+ function patchValue(value, where) {
28
+ if (value === void 0) return void 0;
29
+ if (value === null || typeof value === "boolean" || typeof value === "string") return value;
30
+ if (typeof value === "number") {
31
+ if (Number.isFinite(value)) return value;
32
+ } else if (Array.isArray(value)) return value.map((item, index) => patchValue(item, `${where}[${index}]`) ?? null);
33
+ else if (isPlain(value)) {
34
+ const out = {};
35
+ for (const [key, item] of Object.entries(value)) {
36
+ const converted = patchValue(item, `${where}.${key}`);
37
+ if (converted !== void 0) out[key] = converted;
38
+ }
39
+ return out;
40
+ }
41
+ throw new SplitEditError("EDITED_IN_CODE", `\`${where}\` is ${typeof value === "function" ? "a function" : "a value with no literal form"}, which is edited in code: change it in the collection's file.`, where.split(".")[0]);
42
+ }
43
+ var isPatchObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
44
+ /** Walk two values and emit every smallest path at which they differ. */
45
+ function diffInto(path, before, after, emit) {
46
+ if (sameValue(before, after)) return;
47
+ if (isPlain(before) && isPlain(after)) {
48
+ const keys = [...Object.keys(after), ...Object.keys(before).filter((key) => !(key in after))];
49
+ for (const key of keys) diffInto([...path, key], before[key], after[key], emit);
50
+ return;
51
+ }
52
+ emit(path, after);
53
+ }
54
+ /**
55
+ * A property as the field a `defineFirestoreCollection` call writes:
56
+ * presentation keys under `admin`, `validation.required` as `required`, a
57
+ * reference's `path` as `target`, nested fields the same way.
58
+ */
59
+ function firestoreFieldOf(property) {
60
+ return fieldOf({ ...property });
61
+ }
62
+ function fieldOf(property) {
63
+ const field = { ...nestAdminPropertyKeys(property) };
64
+ if (field.type === "reference" && "path" in field) {
65
+ field.target = field.path;
66
+ delete field.path;
67
+ }
68
+ if (isRecord(field.validation)) {
69
+ const { required, ...rest } = field.validation;
70
+ if (required === true) field.required = true;
71
+ if (Object.keys(rest).length > 0) field.validation = rest;
72
+ else delete field.validation;
73
+ }
74
+ if (field.type === "map" && isRecord(field.properties)) field.properties = fieldsOf(field.properties);
75
+ if (field.type === "array") {
76
+ if (Array.isArray(field.of)) field.of = field.of.map((item) => isRecord(item) ? fieldOf(item) : item);
77
+ else if (isRecord(field.of)) field.of = fieldOf(field.of);
78
+ if (isRecord(field.oneOf) && isRecord(field.oneOf.properties)) field.oneOf = {
79
+ ...field.oneOf,
80
+ properties: fieldsOf(field.oneOf.properties)
81
+ };
82
+ }
83
+ return field;
84
+ }
85
+ function fieldsOf(properties) {
86
+ const out = {};
87
+ for (const [key, property] of Object.entries(properties)) out[key] = isRecord(property) ? fieldOf(property) : property;
88
+ return out;
89
+ }
90
+ /** Keys of the editor's view model that are not options of the call. */
91
+ var NOT_OPTIONS = /* @__PURE__ */ new Set([
92
+ "properties",
93
+ "engine",
94
+ "slug",
95
+ "admin"
96
+ ]);
97
+ /** The call's options, nested as written: everything but the fields. */
98
+ function optionsOf(collection) {
99
+ const nested = nestAdminCollectionKeys({ ...collection });
100
+ const out = {};
101
+ for (const [key, value] of Object.entries(nested)) if (!NOT_OPTIONS.has(key)) out[key] = value;
102
+ if (isRecord(nested.admin)) out.admin = nested.admin;
103
+ return out;
104
+ }
105
+ /**
106
+ * The patches that turn the Firestore collection `before` into `after`, as
107
+ * the editor saves it.
108
+ *
109
+ * - Collection options (`name`, `path`, `description`, the `admin` block)
110
+ * are `setOption` / `removeOption` at the path that changed.
111
+ * - A new field is `addField`, a removed one `removeField`; a changed field
112
+ * is `setFieldOption` / `removeFieldOption` at each path that changed
113
+ * inside it.
114
+ * - The field order the editor shows becomes `moveField`s when the file has
115
+ * no `admin.propertiesOrder` of its own (which is set like any option).
116
+ *
117
+ * @throws {@link SplitEditError} `MIGRATION_REQUIRED` for a slug change (it is
118
+ * the collection's URL, its reference target and what the file is found
119
+ * by), `EDITED_IN_CODE` for a changed value that is code.
120
+ */
121
+ function firestoreCollectionPatches(before, after) {
122
+ const collection = before.slug;
123
+ if (after.slug !== before.slug) throw new SplitEditError("MIGRATION_REQUIRED", `The slug of "${before.slug}" is its URL, the target of references to it and what its file is found by: rename it in code, with the references.`, "slug");
124
+ const patches = [];
125
+ const optionsBefore = optionsOf(before);
126
+ const optionsAfter = optionsOf(after);
127
+ const ownOrder = isRecord(optionsBefore.admin) && optionsBefore.admin.propertiesOrder !== void 0;
128
+ const withoutOrder = (options) => {
129
+ if (ownOrder || !isRecord(options.admin) || !("propertiesOrder" in options.admin)) return options;
130
+ const { propertiesOrder: _order, ...admin } = options.admin;
131
+ return Object.keys(admin).length > 0 ? {
132
+ ...options,
133
+ admin
134
+ } : Object.fromEntries(Object.entries(options).filter(([key]) => key !== "admin"));
135
+ };
136
+ diffInto([], withoutOrder(optionsBefore), withoutOrder(optionsAfter), (path, value) => {
137
+ const converted = patchValue(value, path.join("."));
138
+ patches.push(converted === void 0 ? {
139
+ op: "removeOption",
140
+ collection,
141
+ path
142
+ } : {
143
+ op: "setOption",
144
+ collection,
145
+ path,
146
+ value: converted
147
+ });
148
+ });
149
+ const fieldsBefore = { ...before.properties };
150
+ const fieldsAfter = { ...after.properties };
151
+ for (const [key, property] of Object.entries(fieldsAfter)) {
152
+ const previous = fieldsBefore[key];
153
+ if (!previous) {
154
+ const field = patchValue(firestoreFieldOf(property), key);
155
+ if (isPatchObject(field)) patches.push({
156
+ op: "addField",
157
+ collection,
158
+ key,
159
+ field
160
+ });
161
+ continue;
162
+ }
163
+ diffInto([], firestoreFieldOf(previous), firestoreFieldOf(property), (path, value) => {
164
+ const converted = patchValue(value, [key, ...path].join("."));
165
+ patches.push(converted === void 0 ? {
166
+ op: "removeFieldOption",
167
+ collection,
168
+ key,
169
+ path
170
+ } : {
171
+ op: "setFieldOption",
172
+ collection,
173
+ key,
174
+ path,
175
+ value: converted
176
+ });
177
+ });
178
+ }
179
+ for (const key of Object.keys(fieldsBefore)) if (!(key in fieldsAfter)) patches.push({
180
+ op: "removeField",
181
+ collection,
182
+ key
183
+ });
184
+ if (!ownOrder) patches.push(...orderPatches(collection, Object.keys(fieldsBefore), fieldsAfter, after.propertiesOrder));
185
+ return patches;
186
+ }
187
+ /** The `moveField`s that put the fields, as the file will hold them, in the order the editor shows. */
188
+ function orderPatches(collection, beforeKeys, fieldsAfter, order) {
189
+ if (!order) return [];
190
+ const current = [...beforeKeys.filter((key) => key in fieldsAfter), ...Object.keys(fieldsAfter).filter((key) => !beforeKeys.includes(key))];
191
+ const listed = order.filter((key) => current.includes(key));
192
+ const desired = [...listed, ...current.filter((key) => !listed.includes(key))];
193
+ const stays = longestIncreasing(desired.map((key) => current.indexOf(key))).map((index) => desired[index]);
194
+ const patches = [];
195
+ for (let index = desired.length - 1; index >= 0; index--) {
196
+ const key = desired[index];
197
+ if (stays.includes(key)) continue;
198
+ const next = desired[index + 1];
199
+ patches.push({
200
+ op: "moveField",
201
+ collection,
202
+ key,
203
+ ...next !== void 0 ? { before: next } : {}
204
+ });
205
+ }
206
+ return patches;
207
+ }
208
+ /** The indexes of a longest strictly increasing subsequence of `values`. */
209
+ function longestIncreasing(values) {
210
+ const length = values.map(() => 1);
211
+ const previous = values.map(() => -1);
212
+ for (let i = 0; i < values.length; i++) for (let j = 0; j < i; j++) if (values[j] < values[i] && length[j] + 1 > length[i]) {
213
+ length[i] = length[j] + 1;
214
+ previous[i] = j;
215
+ }
216
+ let end = length.indexOf(Math.max(0, ...length));
217
+ const out = [];
218
+ while (end !== -1) {
219
+ out.unshift(end);
220
+ end = previous[end];
221
+ }
222
+ return out;
223
+ }
224
+ /** Whether `path` (inside a field) names a field: the field itself, a map's sub-field, an array's `of`, a block. */
225
+ function isFieldPosition(path) {
226
+ if (path.length === 0) return true;
227
+ if (path[path.length - 1] === "of") return isFieldPosition(path.slice(0, -1));
228
+ if (path.length >= 2 && path[path.length - 2] === "properties") {
229
+ const parent = path.slice(0, -2);
230
+ if (parent.length >= 1 && parent[parent.length - 1] === "oneOf") return isFieldPosition(parent.slice(0, -1));
231
+ return isFieldPosition(parent);
232
+ }
233
+ return false;
234
+ }
235
+ /** `required` is `validation.required` written once: whatever is said of one is said of both. */
236
+ function requiredCompanion(fieldPath) {
237
+ const last = fieldPath[fieldPath.length - 1];
238
+ const owner = fieldPath.slice(0, -1);
239
+ if (last !== "required" || !isFieldPosition(owner.slice(2))) return [];
240
+ return [{
241
+ op: "remove",
242
+ path: [
243
+ ...owner,
244
+ "validation",
245
+ "required"
246
+ ],
247
+ prune: true
248
+ }];
249
+ }
250
+ /**
251
+ * The frontend source edit that writes `patches` into the collection's
252
+ * `defineFirestoreCollection` call, found by its slug.
253
+ */
254
+ function firestoreSourceEdit(slug, patches, version) {
255
+ const operations = [];
256
+ for (const patch of patches) switch (patch.op) {
257
+ case "setOption":
258
+ operations.push({
259
+ op: "set",
260
+ path: [...patch.path],
261
+ value: patch.value
262
+ });
263
+ break;
264
+ case "removeOption":
265
+ operations.push({
266
+ op: "remove",
267
+ path: [...patch.path],
268
+ ...patch.path.length > 1 ? { prune: true } : {}
269
+ });
270
+ break;
271
+ case "addField":
272
+ operations.push({
273
+ op: "set",
274
+ path: ["fields", patch.key],
275
+ value: patch.field,
276
+ ...patch.before !== void 0 ? { before: patch.before } : {}
277
+ });
278
+ break;
279
+ case "setFieldOption": {
280
+ const path = [
281
+ "fields",
282
+ patch.key,
283
+ ...patch.path
284
+ ];
285
+ operations.push(...requiredCompanion(path), {
286
+ op: "set",
287
+ path,
288
+ value: patch.value
289
+ });
290
+ break;
291
+ }
292
+ case "removeFieldOption": {
293
+ const path = [
294
+ "fields",
295
+ patch.key,
296
+ ...patch.path
297
+ ];
298
+ operations.push({
299
+ op: "remove",
300
+ path,
301
+ ...patch.path.length > 1 ? { prune: true } : {}
302
+ }, ...requiredCompanion(path));
303
+ break;
304
+ }
305
+ case "removeField":
306
+ operations.push({
307
+ op: "remove",
308
+ path: ["fields", patch.key]
309
+ });
310
+ break;
311
+ case "renameField":
312
+ operations.push({
313
+ op: "rename",
314
+ path: ["fields", patch.key],
315
+ to: patch.to
316
+ });
317
+ break;
318
+ case "moveField":
319
+ operations.push({
320
+ op: "move",
321
+ path: ["fields", patch.key],
322
+ ...patch.before !== void 0 ? { before: patch.before } : {}
323
+ });
324
+ break;
325
+ }
326
+ return {
327
+ target: {
328
+ callee: FIRESTORE_COLLECTION_CALLEE,
329
+ key: "slug",
330
+ value: slug
331
+ },
332
+ ...version !== void 0 ? { version } : {},
333
+ operations
334
+ };
335
+ }
336
+ //#endregion
337
+ export { firestoreCollectionPatches, firestoreFieldOf, firestoreSourceEdit };
338
+
339
+ //# sourceMappingURL=firestore_edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firestore_edit.js","names":[],"sources":["../../src/collection_editor/firestore_edit.ts"],"sourcesContent":["/**\n * One save of the collection editor on a Firestore collection, as\n * {@link FirestoreCollectionPatch} operations — and those operations as the\n * edit the dev server's frontend source editor makes to the collection's\n * `defineFirestoreCollection({...})` call.\n *\n * A Firestore collection has no server schema: what the editor shows is the\n * frontend definition, normalised (`required` → `validation.required`, a\n * reference's `target` → `path`, the `admin` block flattened). A save is\n * therefore entirely an edit of that definition, written back in the\n * definition's own vocabulary, at the smallest path that changed, so every\n * key the person did not touch stays as written — functions and components\n * included, which are never part of an edit.\n *\n * The module is pure.\n *\n * @module\n */\nimport { nestAdminCollectionKeys, nestAdminPropertyKeys } from \"@rebasepro/cms-types\";\nimport type { AdminCollection, FirestoreCollectionPatch, FirestorePatchValue, Properties, Property } from \"@rebasepro/cms-types\";\nimport { SplitEditError } from \"./split_edit_error\";\nimport { sameValue } from \"./split_edit\";\nimport { FIRESTORE_COLLECTION_CALLEE } from \"./firestore_callee\";\n\n/**\n * The frontend source editor's wire (`POST /admin/schema-editor/frontend/apply`):\n * operations on paths into the object argument of the call `target` names.\n */\nexport interface FrontendSourceEditRequest {\n target: { callee: string; key: string; value: string };\n /** The file's version as the panel read it: a file changed since is refused. */\n version?: string;\n operations: FrontendSourceOperation[];\n}\n\n/** One operation of a {@link FrontendSourceEditRequest}. */\nexport type FrontendSourceOperation =\n | { op: \"set\"; path: string[]; value: FirestorePatchValue; before?: string }\n | { op: \"remove\"; path: string[]; prune?: boolean }\n | { op: \"rename\"; path: string[]; to: string }\n | { op: \"move\"; path: string[]; before?: string };\n\n// ── Values ──────────────────────────────────────────────────────────────────\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst isPlain = (value: unknown): value is Record<string, unknown> =>\n isRecord(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);\n\n/** `value` as JSON, `undefined` for absent; code and class instances are refused with where they are. */\nfunction patchValue(value: unknown, where: string): FirestorePatchValue | undefined {\n if (value === undefined) return undefined;\n if (value === null || typeof value === \"boolean\" || typeof value === \"string\") return value;\n if (typeof value === \"number\") {\n if (Number.isFinite(value)) return value;\n } else if (Array.isArray(value)) {\n return value.map((item, index) => patchValue(item, `${where}[${index}]`) ?? null);\n } else if (isPlain(value)) {\n const out: { [key: string]: FirestorePatchValue } = {};\n for (const [key, item] of Object.entries(value)) {\n const converted = patchValue(item, `${where}.${key}`);\n if (converted !== undefined) out[key] = converted;\n }\n return out;\n }\n throw new SplitEditError(\"EDITED_IN_CODE\",\n `\\`${where}\\` is ${typeof value === \"function\" ? \"a function\" : \"a value with no literal form\"}, which is edited in code: change it in the collection's file.`,\n where.split(\".\")[0]);\n}\n\nconst isPatchObject = (value: FirestorePatchValue | undefined): value is { [key: string]: FirestorePatchValue } =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n/** Walk two values and emit every smallest path at which they differ. */\nfunction diffInto(path: string[], before: unknown, after: unknown, emit: (path: string[], value: unknown) => void): void {\n if (sameValue(before, after)) return;\n if (isPlain(before) && isPlain(after)) {\n const keys = [...Object.keys(after), ...Object.keys(before).filter(key => !(key in after))];\n for (const key of keys) diffInto([...path, key], before[key], after[key], emit);\n return;\n }\n emit(path, after);\n}\n\n// ── The collection's own vocabulary ─────────────────────────────────────────\n\n/**\n * A property as the field a `defineFirestoreCollection` call writes:\n * presentation keys under `admin`, `validation.required` as `required`, a\n * reference's `path` as `target`, nested fields the same way.\n */\nexport function firestoreFieldOf(property: Property): Record<string, unknown> {\n return fieldOf({ ...property });\n}\n\nfunction fieldOf(property: Record<string, unknown>): Record<string, unknown> {\n const field: Record<string, unknown> = { ...nestAdminPropertyKeys(property) };\n if (field.type === \"reference\" && \"path\" in field) {\n field.target = field.path;\n delete field.path;\n }\n if (isRecord(field.validation)) {\n const { required, ...rest } = field.validation;\n if (required === true) field.required = true;\n if (Object.keys(rest).length > 0) field.validation = rest;\n else delete field.validation;\n }\n if (field.type === \"map\" && isRecord(field.properties)) field.properties = fieldsOf(field.properties);\n if (field.type === \"array\") {\n if (Array.isArray(field.of)) field.of = field.of.map(item => (isRecord(item) ? fieldOf(item) : item));\n else if (isRecord(field.of)) field.of = fieldOf(field.of);\n if (isRecord(field.oneOf) && isRecord(field.oneOf.properties)) {\n field.oneOf = { ...field.oneOf, properties: fieldsOf(field.oneOf.properties) };\n }\n }\n return field;\n}\n\nfunction fieldsOf(properties: Record<string, unknown>): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [key, property] of Object.entries(properties)) out[key] = isRecord(property) ? fieldOf(property) : property;\n return out;\n}\n\n/** Keys of the editor's view model that are not options of the call. */\nconst NOT_OPTIONS = new Set([\"properties\", \"engine\", \"slug\", \"admin\"]);\n\n/** The call's options, nested as written: everything but the fields. */\nfunction optionsOf(collection: AdminCollection): Record<string, unknown> {\n const nested = nestAdminCollectionKeys({ ...collection });\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(nested)) if (!NOT_OPTIONS.has(key)) out[key] = value;\n if (isRecord(nested.admin)) out.admin = nested.admin;\n return out;\n}\n\n// ── The patches ─────────────────────────────────────────────────────────────\n\n/**\n * The patches that turn the Firestore collection `before` into `after`, as\n * the editor saves it.\n *\n * - Collection options (`name`, `path`, `description`, the `admin` block)\n * are `setOption` / `removeOption` at the path that changed.\n * - A new field is `addField`, a removed one `removeField`; a changed field\n * is `setFieldOption` / `removeFieldOption` at each path that changed\n * inside it.\n * - The field order the editor shows becomes `moveField`s when the file has\n * no `admin.propertiesOrder` of its own (which is set like any option).\n *\n * @throws {@link SplitEditError} `MIGRATION_REQUIRED` for a slug change (it is\n * the collection's URL, its reference target and what the file is found\n * by), `EDITED_IN_CODE` for a changed value that is code.\n */\nexport function firestoreCollectionPatches(before: AdminCollection, after: AdminCollection): FirestoreCollectionPatch[] {\n const collection = before.slug;\n if (after.slug !== before.slug) {\n throw new SplitEditError(\"MIGRATION_REQUIRED\",\n `The slug of \"${before.slug}\" is its URL, the target of references to it and what its file is found by: rename it in code, with the references.`,\n \"slug\");\n }\n const patches: FirestoreCollectionPatch[] = [];\n\n // Options.\n const optionsBefore = optionsOf(before);\n const optionsAfter = optionsOf(after);\n const ownOrder = isRecord(optionsBefore.admin) && optionsBefore.admin.propertiesOrder !== undefined;\n const withoutOrder = (options: Record<string, unknown>): Record<string, unknown> => {\n if (ownOrder || !isRecord(options.admin) || !(\"propertiesOrder\" in options.admin)) return options;\n const { propertiesOrder: _order, ...admin } = options.admin;\n void _order;\n return Object.keys(admin).length > 0 ? { ...options, admin } : Object.fromEntries(Object.entries(options).filter(([key]) => key !== \"admin\"));\n };\n diffInto([], withoutOrder(optionsBefore), withoutOrder(optionsAfter), (path, value) => {\n const converted = patchValue(value, path.join(\".\"));\n patches.push(converted === undefined\n ? { op: \"removeOption\", collection, path }\n : { op: \"setOption\", collection, path, value: converted });\n });\n\n // Fields.\n const fieldsBefore: Properties = { ...before.properties };\n const fieldsAfter: Properties = { ...after.properties };\n for (const [key, property] of Object.entries(fieldsAfter)) {\n const previous = fieldsBefore[key];\n if (!previous) {\n const field = patchValue(firestoreFieldOf(property), key);\n if (isPatchObject(field)) patches.push({ op: \"addField\", collection, key, field });\n continue;\n }\n diffInto([], firestoreFieldOf(previous), firestoreFieldOf(property), (path, value) => {\n const converted = patchValue(value, [key, ...path].join(\".\"));\n patches.push(converted === undefined\n ? { op: \"removeFieldOption\", collection, key, path }\n : { op: \"setFieldOption\", collection, key, path, value: converted });\n });\n }\n for (const key of Object.keys(fieldsBefore)) {\n if (!(key in fieldsAfter)) patches.push({ op: \"removeField\", collection, key });\n }\n\n // Field order, when the file states none of its own.\n if (!ownOrder) patches.push(...orderPatches(collection, Object.keys(fieldsBefore), fieldsAfter, after.propertiesOrder));\n return patches;\n}\n\n/** The `moveField`s that put the fields, as the file will hold them, in the order the editor shows. */\nfunction orderPatches(collection: string, beforeKeys: string[], fieldsAfter: Properties, order: readonly string[] | undefined): FirestoreCollectionPatch[] {\n if (!order) return [];\n const current = [\n ...beforeKeys.filter(key => key in fieldsAfter),\n ...Object.keys(fieldsAfter).filter(key => !beforeKeys.includes(key))\n ];\n const listed = order.filter(key => current.includes(key));\n const desired = [...listed, ...current.filter(key => !listed.includes(key))];\n // The longest run already in order stays; every other field moves, from\n // the last, to just before the field that follows it.\n const positions = desired.map(key => current.indexOf(key));\n const stays = longestIncreasing(positions).map(index => desired[index]);\n const patches: FirestoreCollectionPatch[] = [];\n for (let index = desired.length - 1; index >= 0; index--) {\n const key = desired[index];\n if (stays.includes(key)) continue;\n const next = desired[index + 1];\n patches.push({ op: \"moveField\", collection, key, ...(next !== undefined ? { before: next } : {}) });\n }\n return patches;\n}\n\n/** The indexes of a longest strictly increasing subsequence of `values`. */\nfunction longestIncreasing(values: readonly number[]): number[] {\n const length = values.map(() => 1);\n const previous = values.map(() => -1);\n for (let i = 0; i < values.length; i++) {\n for (let j = 0; j < i; j++) {\n if (values[j] < values[i] && length[j] + 1 > length[i]) {\n length[i] = length[j] + 1;\n previous[i] = j;\n }\n }\n }\n let end = length.indexOf(Math.max(0, ...length));\n const out: number[] = [];\n while (end !== -1) {\n out.unshift(end);\n end = previous[end];\n }\n return out;\n}\n\n// ── The source edit ─────────────────────────────────────────────────────────\n\n/** Whether `path` (inside a field) names a field: the field itself, a map's sub-field, an array's `of`, a block. */\nfunction isFieldPosition(path: readonly string[]): boolean {\n if (path.length === 0) return true;\n const last = path[path.length - 1];\n if (last === \"of\") return isFieldPosition(path.slice(0, -1));\n if (path.length >= 2 && path[path.length - 2] === \"properties\") {\n const parent = path.slice(0, -2);\n if (parent.length >= 1 && parent[parent.length - 1] === \"oneOf\") return isFieldPosition(parent.slice(0, -1));\n return isFieldPosition(parent);\n }\n return false;\n}\n\n/** `required` is `validation.required` written once: whatever is said of one is said of both. */\nfunction requiredCompanion(fieldPath: readonly string[]): FrontendSourceOperation[] {\n const last = fieldPath[fieldPath.length - 1];\n const owner = fieldPath.slice(0, -1);\n if (last !== \"required\" || !isFieldPosition(owner.slice(2))) return [];\n return [{ op: \"remove\", path: [...owner, \"validation\", \"required\"], prune: true }];\n}\n\n/**\n * The frontend source edit that writes `patches` into the collection's\n * `defineFirestoreCollection` call, found by its slug.\n */\nexport function firestoreSourceEdit(slug: string, patches: readonly FirestoreCollectionPatch[], version?: string): FrontendSourceEditRequest {\n const operations: FrontendSourceOperation[] = [];\n for (const patch of patches) {\n switch (patch.op) {\n case \"setOption\":\n operations.push({ op: \"set\", path: [...patch.path], value: patch.value });\n break;\n case \"removeOption\":\n operations.push({ op: \"remove\", path: [...patch.path], ...(patch.path.length > 1 ? { prune: true } : {}) });\n break;\n case \"addField\":\n operations.push({ op: \"set\", path: [\"fields\", patch.key], value: patch.field, ...(patch.before !== undefined ? { before: patch.before } : {}) });\n break;\n case \"setFieldOption\": {\n const path = [\"fields\", patch.key, ...patch.path];\n operations.push(...requiredCompanion(path), { op: \"set\", path, value: patch.value });\n break;\n }\n case \"removeFieldOption\": {\n const path = [\"fields\", patch.key, ...patch.path];\n operations.push({ op: \"remove\", path, ...(patch.path.length > 1 ? { prune: true } : {}) }, ...requiredCompanion(path));\n break;\n }\n case \"removeField\":\n operations.push({ op: \"remove\", path: [\"fields\", patch.key] });\n break;\n case \"renameField\":\n operations.push({ op: \"rename\", path: [\"fields\", patch.key], to: patch.to });\n break;\n case \"moveField\":\n operations.push({ op: \"move\", path: [\"fields\", patch.key], ...(patch.before !== undefined ? { before: patch.before } : {}) });\n break;\n }\n }\n return {\n target: { callee: FIRESTORE_COLLECTION_CALLEE, key: \"slug\", value: slug },\n ...(version !== undefined ? { version } : {}),\n operations\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,YAAY,UACd,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAEvE,IAAM,WAAW,UACb,SAAS,KAAK,MAAM,OAAO,eAAe,KAAK,MAAM,OAAO,aAAa,OAAO,eAAe,KAAK,MAAM;;AAG9G,SAAS,WAAW,OAAgB,OAAgD;CAChF,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,IAAI,UAAU,QAAQ,OAAO,UAAU,aAAa,OAAO,UAAU,UAAU,OAAO;CACtF,IAAI,OAAO,UAAU;MACb,OAAO,SAAS,KAAK,GAAG,OAAO;CAAA,OAChC,IAAI,MAAM,QAAQ,KAAK,GAC1B,OAAO,MAAM,KAAK,MAAM,UAAU,WAAW,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI;MAC7E,IAAI,QAAQ,KA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EACJ,KAAK;GACD,WAAW,KAAK;IAAE,IAAI;IAAQ,MAAM,CAAC,UAAU,MAAM,GAAG;IAAG,GAAI,MAAM,WAAW,KAAA,IAAY,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;GAAG,CAAC;GAC5H;CACR;CAEJ,OAAO;EACH,QAAQ;GAAE,QAAQ;GAA6B,KAAK;GAAQ,OAAO;EAAK;EACxE,GAAI,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;EAC3C;CACJ;AACJ"}
@@ -1,12 +1,11 @@
1
1
  export { useCollectionEditorController } from "./useCollectionEditorController.js";
2
2
  export { useCollectionsConfigController } from "./useCollectionsConfigController.js";
3
3
  export { useLocalCollectionsConfigController } from "./useLocalCollectionsConfigController.js";
4
- export { useJsonCollectionsConfigController, type UseJsonCollectionsConfigControllerOptions, } from "./useJsonCollectionsConfigController.js";
5
4
  export { toSerializableCollectionConfig, toSerializableProperty, toSerializableProperties, fromSerializableCollectionConfig, fromSerializableCollectionConfigs, fromSerializableProperty, fromSerializableProperties, } from "./serializable_utils.js";
6
- export type { SerializableCollectionConfig, SerializableProperty, SerializableProperties, SerializableBaseProperty, SerializableStringProperty, SerializableNumberProperty, SerializableBooleanProperty, SerializableDateProperty, SerializableGeopointProperty, SerializableReferenceProperty, SerializableRelationProperty, SerializableArrayProperty, SerializableMapProperty, SerializableVectorProperty, SerializableBinaryProperty, SerializableStorageConfig, SerializableStringValidation, SerializableDateValidation, JsonCollectionStore, } from "./serializable_types.js";
5
+ export type { SerializableCollectionConfig, SerializableProperty, SerializableProperties, SerializableBaseProperty, SerializableStringProperty, SerializableNumberProperty, SerializableBooleanProperty, SerializableDateProperty, SerializableGeopointProperty, SerializableReferenceProperty, SerializableRelationProperty, SerializableArrayProperty, SerializableMapProperty, SerializableVectorProperty, SerializableBinaryProperty, SerializableStorageConfig, SerializableStringValidation, SerializableDateValidation, } from "./serializable_types.js";
7
6
  export type { PropertyTypePreset, PropertyType, CollectionEditorTab, CollectionEditorExtensionProps, ExtraPropertyFieldsParams, ExtraCollectionFieldsParams, } from "./extensibility_types.js";
8
7
  export { validateCollectionJson, type CollectionValidationError, type CollectionValidationResult } from "./validateCollectionJson.js";
9
- export type { CollectionsConfigController, DeleteCollectionParams, SaveCollectionParams, UpdateCollectionParams, CollectionsSetupInfo, UpdatePropertiesOrderParams, UpdateKanbanColumnsOrderParams } from "./types/config_controller.js";
8
+ export type { CollectionsConfigController, DeleteCollectionParams, SaveCollectionParams, UpdateCollectionParams, CollectionsSetupInfo, UpdatePropertiesOrderParams, UpdateKanbanColumnsOrderParams, ImportedTable } from "./types/config_controller.js";
10
9
  export type { CollectionEditorController } from "./types/collection_editor_controller.js";
11
10
  export type { CollectionInference } from "./types/collection_inference.js";
12
11
  export { buildCollectionGenerationCallback, CollectionGenerationApiError, DEFAULT_COLLECTION_GENERATION_ENDPOINT } from "./api/generateCollectionApi.js";
@@ -7,17 +7,15 @@
7
7
  * try-and-see would be asking somebody to discover that their change is refused
8
8
  * by pressing a button on a live database.
9
9
  *
10
- * ## A change to an existing collection is a patch
10
+ * ## A change is a list of table edits
11
11
  *
12
- * What the person changed — the difference between the collection the editor
13
- * loaded and the one it is saving, from `diffCollections` in
14
- * `@rebasepro/types` — not the collection. The server applies it to the
15
- * collection as it is to plan the change, and writes only those keys into the
16
- * file. Posting the whole collection had the server write back the panel's
17
- * JSON, which had lost every handler, shared property and imported value.
18
- * A new collection is still sent whole.
12
+ * `{ patches: TablePatch[] }` — the operations `splitEdit` derives from what
13
+ * the person changed (add a column, replace one rule, …), never the whole
14
+ * table. The server applies them to `backend/schema/*.ts`, compiles the
15
+ * result, plans the DDL against it, and writes only what the operations name:
16
+ * comments, hooks and every other rule stay as written.
19
17
  */
20
- import type { CollectionPatch, SchemaChangeVerdict } from "@rebasepro/types";
18
+ import type { SchemaChangeVerdict, TablePatch } from "@rebasepro/types";
21
19
  /** A constraint the change asks for that the statements will not carry. */
22
20
  export interface WithheldConstraint {
23
21
  target: string;
@@ -85,6 +83,18 @@ export interface LiveSchemaResult {
85
83
  summary: string;
86
84
  withheldConstraints: WithheldConstraint[];
87
85
  followUp?: string[];
86
+ /**
87
+ * Whether the running server serves the applied change: `now`, or only
88
+ * once it restarts (a data driver that cannot read its tables back while
89
+ * running) — `summary` then says so and why. Absent when nothing ran or
90
+ * the server did not say.
91
+ */
92
+ serving?: {
93
+ status: "now";
94
+ } | {
95
+ status: "after-restart";
96
+ message: string;
97
+ };
88
98
  }
89
99
  /**
90
100
  * Whether this backend can edit its schema, and what is missing when it cannot.
@@ -120,8 +130,8 @@ export interface LiveSchemaStatus {
120
130
  *
121
131
  * Distinguished from an ordinary failure because both are expected states with
122
132
  * their own explanation, and a UI should say which rather than showing a
123
- * stack: a Mongo backend will never support this, and a bundle deployment has
124
- * no source to edit.
133
+ * stack: a backend whose driver cannot plan a schema change will never support
134
+ * this, and a bundle deployment has no source to edit.
125
135
  */
126
136
  export type LiveSchemaUnavailable = {
127
137
  reason: "unsupported";
@@ -130,10 +140,21 @@ export type LiveSchemaUnavailable = {
130
140
  reason: "no-repository";
131
141
  message: string;
132
142
  };
143
+ /**
144
+ * One problem the server reports with an edit: the table, the column,
145
+ * relation or key when there is one, and what is wrong. What a
146
+ * `SCHEMA_EDIT_DOES_NOT_COMPILE` or `SCHEMA_EDIT_REFUSED` answer lists.
147
+ */
148
+ export interface SchemaEditProblem {
149
+ table: string;
150
+ key?: string;
151
+ message: string;
152
+ }
133
153
  export declare class LiveSchemaError extends Error {
134
154
  readonly code: string | undefined;
135
155
  readonly changes?: LiveSchemaPlan["changes"] | undefined;
136
- constructor(message: string, code: string | undefined, changes?: LiveSchemaPlan["changes"] | undefined);
156
+ readonly problems?: readonly SchemaEditProblem[] | undefined;
157
+ constructor(message: string, code: string | undefined, changes?: LiveSchemaPlan["changes"] | undefined, problems?: readonly SchemaEditProblem[] | undefined);
137
158
  }
138
159
  export interface LiveSchemaClientOptions {
139
160
  /** Base for the routes, e.g. `https://api.example.com/api/schema`. */
@@ -141,14 +162,15 @@ export interface LiveSchemaClientOptions {
141
162
  getAuthToken?: () => Promise<string | null> | string | null;
142
163
  fetchImpl?: typeof fetch;
143
164
  }
144
- export interface ProposedCollectionChange {
145
- collectionId: string;
146
- /** A new collection, whole. */
147
- collection?: Record<string, unknown>;
148
- /** What changed about an existing one. See the module comment. */
149
- patch?: CollectionPatch;
150
- /** Delete the collection's source — its file and its `index.ts` entry. The table stays. */
151
- remove?: true;
165
+ /**
166
+ * One schema change: the table it is about (for the dialog's title) and the
167
+ * operations, as the routes take them.
168
+ */
169
+ export interface ProposedSchemaChange {
170
+ /** The slug of the table the change is about. */
171
+ table: string;
172
+ /** The edits, in the order they apply. See the module comment. */
173
+ patches: TablePatch[];
152
174
  }
153
175
  export declare function createLiveSchemaClient(options: LiveSchemaClientOptions): {
154
176
  /**
@@ -162,12 +184,12 @@ export declare function createLiveSchemaClient(options: LiveSchemaClientOptions)
162
184
  */
163
185
  status: () => Promise<LiveSchemaStatus>;
164
186
  /** What the change would do. No side effects. */
165
- plan: (change: ProposedCollectionChange) => Promise<LiveSchemaPlan>;
187
+ plan: (change: ProposedSchemaChange) => Promise<LiveSchemaPlan>;
166
188
  /**
167
189
  * Commit the change, then apply it — or, with `sourceOnly`, commit it
168
190
  * and run nothing ("Edit source only").
169
191
  */
170
- apply: (change: ProposedCollectionChange & {
192
+ apply: (change: ProposedSchemaChange & {
171
193
  sourceOnly?: boolean;
172
194
  }) => Promise<LiveSchemaResult>;
173
195
  };
@@ -2,10 +2,12 @@
2
2
  var LiveSchemaError = class extends Error {
3
3
  code;
4
4
  changes;
5
- constructor(message, code, changes) {
5
+ problems;
6
+ constructor(message, code, changes, problems) {
6
7
  super(message);
7
8
  this.code = code;
8
9
  this.changes = changes;
10
+ this.problems = problems;
9
11
  this.name = "LiveSchemaError";
10
12
  }
11
13
  };
@@ -16,7 +18,11 @@ var UNAVAILABLE = {
16
18
  function createLiveSchemaClient(options) {
17
19
  const doFetch = options.fetchImpl ?? fetch;
18
20
  const base = options.baseUrl.replace(/\/$/, "");
19
- const post = async (path, body) => {
21
+ const post = async (path, change) => {
22
+ const body = {
23
+ patches: change.patches,
24
+ ...change.sourceOnly ? { sourceOnly: true } : {}
25
+ };
20
26
  const token = await options.getAuthToken?.();
21
27
  const headers = { "Content-Type": "application/json" };
22
28
  if (token) headers.Authorization = `Bearer ${token}`;
@@ -32,7 +38,7 @@ function createLiveSchemaClient(options) {
32
38
  } catch {
33
39
  payload = { error: { message: await response.text().catch(() => "") } };
34
40
  }
35
- throw new LiveSchemaError(payload.error?.message || `Schema request failed with ${response.status}`, payload.error?.code, payload.error?.details?.changes);
41
+ throw new LiveSchemaError(payload.error?.message || `Schema request failed with ${response.status}`, payload.error?.code, payload.error?.details?.changes, payload.error?.details?.problems);
36
42
  };
37
43
  return {
38
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"liveSchemaClient.js","names":[],"sources":["../../src/collection_editor/liveSchemaClient.ts"],"sourcesContent":["/**\n * The panel's client for live schema editing.\n *\n * Three calls, mirroring the routes: ask whether this backend can do it, ask\n * what a change would do, then do it. `plan` and `apply` are deliberately\n * separate here as well as on the server, because a UI that could only\n * try-and-see would be asking somebody to discover that their change is refused\n * by pressing a button on a live database.\n *\n * ## A change to an existing collection is a patch\n *\n * What the person changed — the difference between the collection the editor\n * loaded and the one it is saving, from `diffCollections` in\n * `@rebasepro/types` — not the collection. The server applies it to the\n * collection as it is to plan the change, and writes only those keys into the\n * file. Posting the whole collection had the server write back the panel's\n * JSON, which had lost every handler, shared property and imported value.\n * A new collection is still sent whole.\n */\n\nimport type { CollectionPatch, SchemaChangeVerdict } from \"@rebasepro/types\";\n\n/** A constraint the change asks for that the statements will not carry. */\nexport interface WithheldConstraint {\n target: string;\n kind: \"not-null\";\n reason: string;\n remedy: string;\n}\n\n/** What the server says a change would do. Mirrors `SchemaChangePlan`. */\nexport interface LiveSchemaPlan {\n applicable: boolean;\n verdict: SchemaChangeVerdict;\n changes: Array<{\n kind: string;\n verdict: SchemaChangeVerdict;\n collection: string;\n property?: string;\n detail: string;\n remedy?: string;\n /**\n * What \"Edit source only\" leaves behind for this change. Absent on a\n * change that may not be written to the source alone.\n */\n sourceOnly?: string;\n kept?: string;\n }>;\n statements: string[];\n files: string[];\n message: string;\n /**\n * Applicable, and still not fully enforced.\n *\n * Not a refusal, so it does not belong in `changes` — but it is the one\n * thing on a plan somebody might want to stop and read, so the dialog gives\n * it its own place rather than another bullet in the list.\n */\n withheldConstraints: WithheldConstraint[];\n /**\n * What still has to happen after this lands.\n *\n * Empty almost always. The case it exists for: a project that replays\n * versioned migrations, where applying here changes *this* database and\n * commits the collection, but writes no migration — so the next\n * environment built from migrations would not have the change.\n */\n followUp?: string[];\n}\n\nexport interface LiveSchemaResult {\n applied: boolean;\n /** Committed as \"Edit source only\": nothing was meant to run. */\n sourceOnly?: boolean;\n applyError?: string;\n /**\n * How many statements ran before the one that failed. The statements run\n * one at a time with no transaction around them, so a failure part-way\n * leaves the earlier ones applied. `undefined` when the server could not\n * say.\n */\n appliedStatements?: number;\n committed: { sha: string; branch: string; files: string[] };\n statements: string[];\n summary: string;\n withheldConstraints: WithheldConstraint[];\n followUp?: string[];\n}\n\n/**\n * Whether this backend can edit its schema, and what is missing when it cannot.\n *\n * `canPlan` is separate from `enabled` deliberately: previewing a change needs\n * no repository, so a deployment running from a bundle can still show somebody\n * exactly what their change would do. Greying out the preview as well would be\n * a worse answer than the truth.\n */\nexport interface LiveSchemaStatus {\n enabled: boolean;\n canPlan: boolean;\n /**\n * Whether *this caller* may apply, as opposed to whether the server can.\n *\n * Applying commits to the repository under an author, and a credential is\n * not an author — so an API key or the service key may preview a change and\n * not make one. Reported here so the panel can grey out the button and say\n * why, rather than letting somebody read a plan, decide, press, and only\n * then be refused.\n */\n canApply: boolean;\n applyRefusedBecause?: string;\n applyRefusedCode?: string;\n repository?: string;\n /** The branch a commit would land on. */\n branch?: string;\n code?: string;\n reason?: string;\n}\n\n/**\n * Why live editing is not available here.\n *\n * Distinguished from an ordinary failure because both are expected states with\n * their own explanation, and a UI should say which rather than showing a\n * stack: a Mongo backend will never support this, and a bundle deployment has\n * no source to edit.\n */\nexport type LiveSchemaUnavailable =\n | { reason: \"unsupported\"; message: string }\n | { reason: \"no-repository\"; message: string };\n\nexport class LiveSchemaError extends Error {\n constructor(\n message: string,\n readonly code: string | undefined,\n readonly changes?: LiveSchemaPlan[\"changes\"]\n ) {\n super(message);\n this.name = \"LiveSchemaError\";\n }\n}\n\nconst UNAVAILABLE: Record<string, LiveSchemaUnavailable[\"reason\"]> = {\n SCHEMA_EDITING_UNSUPPORTED: \"unsupported\",\n SCHEMA_EDITING_NO_REPOSITORY: \"no-repository\"\n};\n\nexport interface LiveSchemaClientOptions {\n /** Base for the routes, e.g. `https://api.example.com/api/schema`. */\n baseUrl: string;\n getAuthToken?: () => Promise<string | null> | string | null;\n fetchImpl?: typeof fetch;\n}\n\nexport interface ProposedCollectionChange {\n collectionId: string;\n /** A new collection, whole. */\n collection?: Record<string, unknown>;\n /** What changed about an existing one. See the module comment. */\n patch?: CollectionPatch;\n /** Delete the collection's source — its file and its `index.ts` entry. The table stays. */\n remove?: true;\n}\n\nexport function createLiveSchemaClient(options: LiveSchemaClientOptions) {\n const doFetch = options.fetchImpl ?? fetch;\n const base = options.baseUrl.replace(/\\/$/, \"\");\n\n const post = async <T>(path: string, body: ProposedCollectionChange & { sourceOnly?: boolean }): Promise<T> => {\n const token = await options.getAuthToken?.();\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (token) headers.Authorization = `Bearer ${token}`;\n\n const response = await doFetch(`${base}${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body)\n });\n\n if (response.ok) return await response.json() as T;\n\n // Parsed rather than assumed: the server answers a structured error, and\n // the code is what tells an expected refusal from a broken request.\n let payload: { error?: { code?: string; message?: string; details?: { changes?: LiveSchemaPlan[\"changes\"] } } } = {};\n try {\n payload = await response.json() as typeof payload;\n } catch {\n payload = { error: { message: await response.text().catch(() => \"\") } };\n }\n\n throw new LiveSchemaError(\n payload.error?.message || `Schema request failed with ${response.status}`,\n payload.error?.code,\n payload.error?.details?.changes\n );\n };\n\n return {\n /**\n * Whether this backend can edit its schema.\n *\n * Never throws. Every way of failing to get an answer — a backend too\n * old to have the endpoint, an unreachable one, a session that is not\n * an admin — means the same thing to a caller deciding whether to offer\n * the control, and turning that into an exception each caller has to\n * catch would only produce four copies of this `catch`.\n */\n status: async (): Promise<LiveSchemaStatus> => {\n try {\n const token = await options.getAuthToken?.();\n const response = await doFetch(`${base}/status`, {\n headers: token ? { Authorization: `Bearer ${token}` } : {}\n });\n const body = await response.json().catch(() => ({})) as\n Partial<LiveSchemaStatus> & { error?: { code?: string; message?: string } };\n\n if (response.ok) {\n return {\n enabled: body.enabled === true,\n canPlan: body.canPlan === true,\n // Absent on a backend from before capabilities existed.\n // Read as \"yes\" there, because on that server being\n // through the admin gate *was* the whole permission —\n // defaulting to no would take the feature away from\n // every deployment that has not upgraded.\n canApply: body.canApply ?? body.enabled === true,\n applyRefusedBecause: body.applyRefusedBecause,\n applyRefusedCode: body.applyRefusedCode,\n repository: body.repository,\n branch: body.branch,\n code: body.code,\n reason: body.reason\n };\n }\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n code: body.error?.code,\n reason: body.error?.message\n ?? `The backend refused to say whether its schema is editable (HTTP ${response.status}).`\n };\n } catch (err) {\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n reason: err instanceof Error ? err.message : \"The backend could not be reached.\"\n };\n }\n },\n\n /** What the change would do. No side effects. */\n plan: (change: ProposedCollectionChange) => post<LiveSchemaPlan>(\"/plan\", change),\n\n /**\n * Commit the change, then apply it — or, with `sourceOnly`, commit it\n * and run nothing (\"Edit source only\").\n */\n apply: (change: ProposedCollectionChange & { sourceOnly?: boolean }) => post<LiveSchemaResult>(\"/apply\", change)\n };\n}\n\n/** The client's shape, for the hook and the tests that fake it. */\nexport type LiveSchemaClient = ReturnType<typeof createLiveSchemaClient>;\n\n/**\n * Whether an error means live editing is unavailable here, rather than that the\n * change was wrong.\n *\n * Returns the reason so a caller can say which, and `undefined` for anything\n * else — a refused change is not an unavailable feature, and conflating them\n * would hide the refusal that the user needs to read.\n */\nexport function asUnavailable(err: unknown): LiveSchemaUnavailable | undefined {\n if (!(err instanceof LiveSchemaError) || !err.code) return undefined;\n const reason = UNAVAILABLE[err.code];\n return reason ? { reason, message: err.message } : undefined;\n}\n\n/** The person closed the dialog without applying. Not an error; an answer. */\nexport class SchemaChangeCancelled extends Error {\n constructor() {\n super(\"The schema change was not applied.\");\n this.name = \"SchemaChangeCancelled\";\n }\n}\n\n/**\n * Was this rejection the person saying no?\n *\n * A save has to *reject* when it is cancelled — resolving would leave the form\n * believing it saved. But a caller that treats every rejection as a failure\n * then reports the user's own choice back to them as an error, which is what\n * the collection editor did: a console error and a red snackbar reading \"Error\n * persisting collection: The schema change was not applied.\"\n *\n * Matched by name rather than `instanceof`, which is unreliable the moment two\n * copies of this module end up in one bundle — the class is then a different\n * identity and every check silently answers false.\n */\nexport function isSchemaChangeCancelled(err: unknown): boolean {\n return err instanceof Error && err.name === \"SchemaChangeCancelled\";\n}\n"],"mappings":";AAmIA,IAAa,kBAAb,cAAqC,MAAM;CAG1B;CACA;CAHb,YACI,SACA,MACA,SACF;EACE,MAAM,OAAO;EAHJ,KAAA,OAAA;EACA,KAAA,UAAA;EAGT,KAAK,OAAO;CAChB;AACJ;AAEA,IAAM,cAA+D;CACjE,4BAA4B;CAC5B,8BAA8B;AAClC;AAmBA,SAAgB,uBAAuB,SAAkC;CACrE,MAAM,UAAU,QAAQ,aAAa;CACrC,MAAM,OAAO,QAAQ,QAAQ,QAAQ,OAAO,EAAE;CAE9C,MAAM,OAAO,OAAU,MAAc,SAA0E;EAC3G,MAAM,QAAQ,MAAM,QAAQ,eAAe;EAC3C,MAAM,UAAkC,EAAE,gBAAgB,mBAAmB;EAC7E,IAAI,OAAO,QAAQ,gBAAgB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,WAAqC,KAAqB,SAAS,MAAM;;;;;EAMhF,QAAQ,WAAgE,KAAuB,UAAU,MAAM;CACnH;AACJ;;;;;;;;;AAaA,SAAgB,cAAc,KAAiD;CAC3E,IAAI,EAAE,eAAe,oBAAoB,CAAC,IAAI,MAAM,OAAO,KAAA;CAC3D,MAAM,SAAS,YAAY,IAAI;CAC/B,OAAO,SAAS;EAAE;EAAQ,SAAS,IAAI;CAAQ,IAAI,KAAA;AACvD;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAC7C,cAAc;EACV,MAAM,oCAAoC;EAC1C,KAAK,OAAO;CAChB;AACJ;;;;;;;;;;;;;;AAeA,SAAgB,wBAAwB,KAAuB;CAC3D,OAAO,eAAe,SAAS,IAAI,SAAS;AAChD"}
1
+ {"version":3,"file":"liveSchemaClient.js","names":[],"sources":["../../src/collection_editor/liveSchemaClient.ts"],"sourcesContent":["/**\n * The panel's client for live schema editing.\n *\n * Three calls, mirroring the routes: ask whether this backend can do it, ask\n * what a change would do, then do it. `plan` and `apply` are deliberately\n * separate here as well as on the server, because a UI that could only\n * try-and-see would be asking somebody to discover that their change is refused\n * by pressing a button on a live database.\n *\n * ## A change is a list of table edits\n *\n * `{ patches: TablePatch[] }` — the operations `splitEdit` derives from what\n * the person changed (add a column, replace one rule, …), never the whole\n * table. The server applies them to `backend/schema/*.ts`, compiles the\n * result, plans the DDL against it, and writes only what the operations name:\n * comments, hooks and every other rule stay as written.\n */\n\nimport type { SchemaChangeVerdict, TablePatch } from \"@rebasepro/types\";\n\n/** A constraint the change asks for that the statements will not carry. */\nexport interface WithheldConstraint {\n target: string;\n kind: \"not-null\";\n reason: string;\n remedy: string;\n}\n\n/** What the server says a change would do. Mirrors `SchemaChangePlan`. */\nexport interface LiveSchemaPlan {\n applicable: boolean;\n verdict: SchemaChangeVerdict;\n changes: Array<{\n kind: string;\n verdict: SchemaChangeVerdict;\n collection: string;\n property?: string;\n detail: string;\n remedy?: string;\n /**\n * What \"Edit source only\" leaves behind for this change. Absent on a\n * change that may not be written to the source alone.\n */\n sourceOnly?: string;\n kept?: string;\n }>;\n statements: string[];\n files: string[];\n message: string;\n /**\n * Applicable, and still not fully enforced.\n *\n * Not a refusal, so it does not belong in `changes` — but it is the one\n * thing on a plan somebody might want to stop and read, so the dialog gives\n * it its own place rather than another bullet in the list.\n */\n withheldConstraints: WithheldConstraint[];\n /**\n * What still has to happen after this lands.\n *\n * Empty almost always. The case it exists for: a project that replays\n * versioned migrations, where applying here changes *this* database and\n * commits the collection, but writes no migration — so the next\n * environment built from migrations would not have the change.\n */\n followUp?: string[];\n}\n\nexport interface LiveSchemaResult {\n applied: boolean;\n /** Committed as \"Edit source only\": nothing was meant to run. */\n sourceOnly?: boolean;\n applyError?: string;\n /**\n * How many statements ran before the one that failed. The statements run\n * one at a time with no transaction around them, so a failure part-way\n * leaves the earlier ones applied. `undefined` when the server could not\n * say.\n */\n appliedStatements?: number;\n committed: { sha: string; branch: string; files: string[] };\n statements: string[];\n summary: string;\n withheldConstraints: WithheldConstraint[];\n followUp?: string[];\n /**\n * Whether the running server serves the applied change: `now`, or only\n * once it restarts (a data driver that cannot read its tables back while\n * running) — `summary` then says so and why. Absent when nothing ran or\n * the server did not say.\n */\n serving?: { status: \"now\" } | { status: \"after-restart\"; message: string };\n}\n\n/**\n * Whether this backend can edit its schema, and what is missing when it cannot.\n *\n * `canPlan` is separate from `enabled` deliberately: previewing a change needs\n * no repository, so a deployment running from a bundle can still show somebody\n * exactly what their change would do. Greying out the preview as well would be\n * a worse answer than the truth.\n */\nexport interface LiveSchemaStatus {\n enabled: boolean;\n canPlan: boolean;\n /**\n * Whether *this caller* may apply, as opposed to whether the server can.\n *\n * Applying commits to the repository under an author, and a credential is\n * not an author — so an API key or the service key may preview a change and\n * not make one. Reported here so the panel can grey out the button and say\n * why, rather than letting somebody read a plan, decide, press, and only\n * then be refused.\n */\n canApply: boolean;\n applyRefusedBecause?: string;\n applyRefusedCode?: string;\n repository?: string;\n /** The branch a commit would land on. */\n branch?: string;\n code?: string;\n reason?: string;\n}\n\n/**\n * Why live editing is not available here.\n *\n * Distinguished from an ordinary failure because both are expected states with\n * their own explanation, and a UI should say which rather than showing a\n * stack: a backend whose driver cannot plan a schema change will never support\n * this, and a bundle deployment has no source to edit.\n */\nexport type LiveSchemaUnavailable =\n | { reason: \"unsupported\"; message: string }\n | { reason: \"no-repository\"; message: string };\n\n/**\n * One problem the server reports with an edit: the table, the column,\n * relation or key when there is one, and what is wrong. What a\n * `SCHEMA_EDIT_DOES_NOT_COMPILE` or `SCHEMA_EDIT_REFUSED` answer lists.\n */\nexport interface SchemaEditProblem {\n table: string;\n key?: string;\n message: string;\n}\n\nexport class LiveSchemaError extends Error {\n constructor(\n message: string,\n readonly code: string | undefined,\n readonly changes?: LiveSchemaPlan[\"changes\"],\n readonly problems?: readonly SchemaEditProblem[]\n ) {\n super(message);\n this.name = \"LiveSchemaError\";\n }\n}\n\nconst UNAVAILABLE: Record<string, LiveSchemaUnavailable[\"reason\"]> = {\n SCHEMA_EDITING_UNSUPPORTED: \"unsupported\",\n SCHEMA_EDITING_NO_REPOSITORY: \"no-repository\"\n};\n\nexport interface LiveSchemaClientOptions {\n /** Base for the routes, e.g. `https://api.example.com/api/schema`. */\n baseUrl: string;\n getAuthToken?: () => Promise<string | null> | string | null;\n fetchImpl?: typeof fetch;\n}\n\n/**\n * One schema change: the table it is about (for the dialog's title) and the\n * operations, as the routes take them.\n */\nexport interface ProposedSchemaChange {\n /** The slug of the table the change is about. */\n table: string;\n /** The edits, in the order they apply. See the module comment. */\n patches: TablePatch[];\n}\n\nexport function createLiveSchemaClient(options: LiveSchemaClientOptions) {\n const doFetch = options.fetchImpl ?? fetch;\n const base = options.baseUrl.replace(/\\/$/, \"\");\n\n const post = async <T>(path: string, change: ProposedSchemaChange & { sourceOnly?: boolean }): Promise<T> => {\n const body = { patches: change.patches, ...(change.sourceOnly ? { sourceOnly: true } : {}) };\n const token = await options.getAuthToken?.();\n const headers: Record<string, string> = { \"Content-Type\": \"application/json\" };\n if (token) headers.Authorization = `Bearer ${token}`;\n\n const response = await doFetch(`${base}${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body)\n });\n\n if (response.ok) return await response.json() as T;\n\n // Parsed rather than assumed: the server answers a structured error, and\n // the code is what tells an expected refusal from a broken request.\n let payload: { error?: { code?: string; message?: string; details?: { changes?: LiveSchemaPlan[\"changes\"]; problems?: SchemaEditProblem[] } } } = {};\n try {\n payload = await response.json() as typeof payload;\n } catch {\n payload = { error: { message: await response.text().catch(() => \"\") } };\n }\n\n throw new LiveSchemaError(\n payload.error?.message || `Schema request failed with ${response.status}`,\n payload.error?.code,\n payload.error?.details?.changes,\n payload.error?.details?.problems\n );\n };\n\n return {\n /**\n * Whether this backend can edit its schema.\n *\n * Never throws. Every way of failing to get an answer — a backend too\n * old to have the endpoint, an unreachable one, a session that is not\n * an admin — means the same thing to a caller deciding whether to offer\n * the control, and turning that into an exception each caller has to\n * catch would only produce four copies of this `catch`.\n */\n status: async (): Promise<LiveSchemaStatus> => {\n try {\n const token = await options.getAuthToken?.();\n const response = await doFetch(`${base}/status`, {\n headers: token ? { Authorization: `Bearer ${token}` } : {}\n });\n const body = await response.json().catch(() => ({})) as\n Partial<LiveSchemaStatus> & { error?: { code?: string; message?: string } };\n\n if (response.ok) {\n return {\n enabled: body.enabled === true,\n canPlan: body.canPlan === true,\n // Absent on a backend from before capabilities existed.\n // Read as \"yes\" there, because on that server being\n // through the admin gate *was* the whole permission —\n // defaulting to no would take the feature away from\n // every deployment that has not upgraded.\n canApply: body.canApply ?? body.enabled === true,\n applyRefusedBecause: body.applyRefusedBecause,\n applyRefusedCode: body.applyRefusedCode,\n repository: body.repository,\n branch: body.branch,\n code: body.code,\n reason: body.reason\n };\n }\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n code: body.error?.code,\n reason: body.error?.message\n ?? `The backend refused to say whether its schema is editable (HTTP ${response.status}).`\n };\n } catch (err) {\n return {\n enabled: false,\n canPlan: false,\n canApply: false,\n reason: err instanceof Error ? err.message : \"The backend could not be reached.\"\n };\n }\n },\n\n /** What the change would do. No side effects. */\n plan: (change: ProposedSchemaChange) => post<LiveSchemaPlan>(\"/plan\", change),\n\n /**\n * Commit the change, then apply it — or, with `sourceOnly`, commit it\n * and run nothing (\"Edit source only\").\n */\n apply: (change: ProposedSchemaChange & { sourceOnly?: boolean }) => post<LiveSchemaResult>(\"/apply\", change)\n };\n}\n\n/** The client's shape, for the hook and the tests that fake it. */\nexport type LiveSchemaClient = ReturnType<typeof createLiveSchemaClient>;\n\n/**\n * Whether an error means live editing is unavailable here, rather than that the\n * change was wrong.\n *\n * Returns the reason so a caller can say which, and `undefined` for anything\n * else — a refused change is not an unavailable feature, and conflating them\n * would hide the refusal that the user needs to read.\n */\nexport function asUnavailable(err: unknown): LiveSchemaUnavailable | undefined {\n if (!(err instanceof LiveSchemaError) || !err.code) return undefined;\n const reason = UNAVAILABLE[err.code];\n return reason ? { reason, message: err.message } : undefined;\n}\n\n/** The person closed the dialog without applying. Not an error; an answer. */\nexport class SchemaChangeCancelled extends Error {\n constructor() {\n super(\"The schema change was not applied.\");\n this.name = \"SchemaChangeCancelled\";\n }\n}\n\n/**\n * Was this rejection the person saying no?\n *\n * A save has to *reject* when it is cancelled — resolving would leave the form\n * believing it saved. But a caller that treats every rejection as a failure\n * then reports the user's own choice back to them as an error, which is what\n * the collection editor did: a console error and a red snackbar reading \"Error\n * persisting collection: The schema change was not applied.\"\n *\n * Matched by name rather than `instanceof`, which is unreliable the moment two\n * copies of this module end up in one bundle — the class is then a different\n * identity and every check silently answers false.\n */\nexport function isSchemaChangeCancelled(err: unknown): boolean {\n return err instanceof Error && err.name === \"SchemaChangeCancelled\";\n}\n"],"mappings":";AAmJA,IAAa,kBAAb,cAAqC,MAAM;CAG1B;CACA;CACA;CAJb,YACI,SACA,MACA,SACA,UACF;EACE,MAAM,OAAO;EAJJ,KAAA,OAAA;EACA,KAAA,UAAA;EACA,KAAA,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