@rebasepro/studio 0.0.1-canary.000dc36

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 (363) hide show
  1. package/LICENSE +114 -0
  2. package/README.md +159 -0
  3. package/dist/ApiExplorer-DHVmWYfK.js +1053 -0
  4. package/dist/ApiExplorer-DHVmWYfK.js.map +1 -0
  5. package/dist/AuthSimulationSelector-CM488Eei.js +106 -0
  6. package/dist/AuthSimulationSelector-CM488Eei.js.map +1 -0
  7. package/dist/BranchesView-DcHZtvXo.js +292 -0
  8. package/dist/BranchesView-DcHZtvXo.js.map +1 -0
  9. package/dist/CronJobsView-CijCToeK.js +456 -0
  10. package/dist/CronJobsView-CijCToeK.js.map +1 -0
  11. package/dist/JSEditor-CSHA0t_O.js +1308 -0
  12. package/dist/JSEditor-CSHA0t_O.js.map +1 -0
  13. package/dist/MonacoEditor-CMYEjiRf.js +161 -0
  14. package/dist/MonacoEditor-CMYEjiRf.js.map +1 -0
  15. package/dist/RLSEditor-BzDjqo6w.js +1872 -0
  16. package/dist/RLSEditor-BzDjqo6w.js.map +1 -0
  17. package/dist/SQLEditor-Cr9Kg_Qg.js +1780 -0
  18. package/dist/SQLEditor-Cr9Kg_Qg.js.map +1 -0
  19. package/dist/SchemaVisualizer-BGpmzyXT.js +1069 -0
  20. package/dist/SchemaVisualizer-BGpmzyXT.js.map +1 -0
  21. package/dist/StorageView-DG9tJZG1.js +811 -0
  22. package/dist/StorageView-DG9tJZG1.js.map +1 -0
  23. package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
  24. package/dist/common/src/collections/index.d.ts +1 -0
  25. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  26. package/dist/common/src/index.d.ts +3 -0
  27. package/dist/common/src/util/builders.d.ts +57 -0
  28. package/dist/common/src/util/callbacks.d.ts +6 -0
  29. package/dist/common/src/util/collections.d.ts +11 -0
  30. package/dist/common/src/util/common.d.ts +2 -0
  31. package/dist/common/src/util/conditions.d.ts +26 -0
  32. package/dist/common/src/util/entities.d.ts +58 -0
  33. package/dist/common/src/util/enums.d.ts +3 -0
  34. package/dist/common/src/util/index.d.ts +16 -0
  35. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  36. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  37. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  38. package/dist/common/src/util/paths.d.ts +14 -0
  39. package/dist/common/src/util/permissions.d.ts +5 -0
  40. package/dist/common/src/util/references.d.ts +2 -0
  41. package/dist/common/src/util/relations.d.ts +22 -0
  42. package/dist/common/src/util/resolutions.d.ts +72 -0
  43. package/dist/common/src/util/storage.d.ts +24 -0
  44. package/dist/core/src/components/AIIcon.d.ts +16 -0
  45. package/dist/core/src/components/ConfirmationDialog.d.ts +9 -0
  46. package/dist/core/src/components/Debug/UIReferenceView.d.ts +1 -0
  47. package/dist/core/src/components/Debug/UIStyleGuide.d.ts +1 -0
  48. package/dist/core/src/components/ErrorTooltip.d.ts +2 -0
  49. package/dist/core/src/components/ErrorView.d.ts +21 -0
  50. package/dist/core/src/components/LanguageToggle.d.ts +1 -0
  51. package/dist/core/src/components/LoginView/LoginView.d.ts +68 -0
  52. package/dist/core/src/components/LoginView/index.d.ts +2 -0
  53. package/dist/core/src/components/NotFoundPage.d.ts +1 -0
  54. package/dist/core/src/components/RebaseAuth.d.ts +10 -0
  55. package/dist/core/src/components/RebaseLogo.d.ts +7 -0
  56. package/dist/core/src/components/UnsavedChangesDialog.d.ts +9 -0
  57. package/dist/core/src/components/UserDisplay.d.ts +7 -0
  58. package/dist/core/src/components/UserSelectPopover.d.ts +62 -0
  59. package/dist/core/src/components/UserSettingsView.d.ts +1 -0
  60. package/dist/core/src/components/common/index.d.ts +6 -0
  61. package/dist/core/src/components/common/table_height.d.ts +5 -0
  62. package/dist/core/src/components/common/types.d.ts +63 -0
  63. package/dist/core/src/components/common/useColumnsIds.d.ts +9 -0
  64. package/dist/core/src/components/common/useDataTableController.d.ts +45 -0
  65. package/dist/core/src/components/common/useDebouncedData.d.ts +9 -0
  66. package/dist/core/src/components/common/useScrollRestoration.d.ts +14 -0
  67. package/dist/core/src/components/index.d.ts +16 -0
  68. package/dist/core/src/contexts/AdminModeController.d.ts +4 -0
  69. package/dist/core/src/contexts/AnalyticsContext.d.ts +3 -0
  70. package/dist/core/src/contexts/AuthControllerContext.d.ts +3 -0
  71. package/dist/core/src/contexts/CustomizationControllerContext.d.ts +3 -0
  72. package/dist/core/src/contexts/DataDriverContext.d.ts +3 -0
  73. package/dist/core/src/contexts/DatabaseAdminContext.d.ts +3 -0
  74. package/dist/core/src/contexts/DialogsProvider.d.ts +4 -0
  75. package/dist/core/src/contexts/EffectiveRoleController.d.ts +4 -0
  76. package/dist/core/src/contexts/InternalUserManagementContext.d.ts +3 -0
  77. package/dist/core/src/contexts/ModeController.d.ts +4 -0
  78. package/dist/core/src/contexts/RebaseClientInstanceContext.d.ts +6 -0
  79. package/dist/core/src/contexts/RebaseDataContext.d.ts +3 -0
  80. package/dist/core/src/contexts/SnackbarProvider.d.ts +2 -0
  81. package/dist/core/src/contexts/StorageSourceContext.d.ts +3 -0
  82. package/dist/core/src/contexts/UserConfigurationPersistenceContext.d.ts +3 -0
  83. package/dist/core/src/contexts/index.d.ts +13 -0
  84. package/dist/core/src/core/PluginLifecycleManager.d.ts +17 -0
  85. package/dist/core/src/core/PluginProviderStack.d.ts +21 -0
  86. package/dist/core/src/core/Rebase.d.ts +14 -0
  87. package/dist/core/src/core/RebaseProps.d.ts +136 -0
  88. package/dist/core/src/core/RebaseRouter.d.ts +4 -0
  89. package/dist/core/src/core/RebaseRoutes.d.ts +17 -0
  90. package/dist/core/src/core/index.d.ts +4 -0
  91. package/dist/core/src/hooks/ApiConfigContext.d.ts +24 -0
  92. package/dist/core/src/hooks/data/delete.d.ts +31 -0
  93. package/dist/core/src/hooks/data/save.d.ts +34 -0
  94. package/dist/core/src/hooks/data/useCollectionFetch.d.ts +51 -0
  95. package/dist/core/src/hooks/data/useData.d.ts +13 -0
  96. package/dist/core/src/hooks/data/useDataOrder.d.ts +12 -0
  97. package/dist/core/src/hooks/data/useEntityFetch.d.ts +38 -0
  98. package/dist/core/src/hooks/data/useRelationSelector.d.ts +52 -0
  99. package/dist/core/src/hooks/data/useUserSelector.d.ts +31 -0
  100. package/dist/core/src/hooks/index.d.ts +37 -0
  101. package/dist/core/src/hooks/useAdminModeController.d.ts +19 -0
  102. package/dist/core/src/hooks/useAnalyticsController.d.ts +5 -0
  103. package/dist/core/src/hooks/useAuthController.d.ts +11 -0
  104. package/dist/core/src/hooks/useAuthSubscription.d.ts +2 -0
  105. package/dist/core/src/hooks/useBackendStorageSource.d.ts +30 -0
  106. package/dist/core/src/hooks/useBridgeRegistration.d.ts +18 -0
  107. package/dist/core/src/hooks/useBrowserTitleAndIcon.d.ts +6 -0
  108. package/dist/core/src/hooks/useBuildAdminModeController.d.ts +6 -0
  109. package/dist/core/src/hooks/useBuildEffectiveRoleController.d.ts +8 -0
  110. package/dist/core/src/hooks/useBuildLocalConfigurationPersistence.d.ts +2 -0
  111. package/dist/core/src/hooks/useBuildModeController.d.ts +6 -0
  112. package/dist/core/src/hooks/useClipboard.d.ts +57 -0
  113. package/dist/core/src/hooks/useCollapsedGroups.d.ts +12 -0
  114. package/dist/core/src/hooks/useCustomizationController.d.ts +11 -0
  115. package/dist/core/src/hooks/useDialogsController.d.ts +11 -0
  116. package/dist/core/src/hooks/useEffectiveRoleController.d.ts +7 -0
  117. package/dist/core/src/hooks/useInternalUserManagementController.d.ts +12 -0
  118. package/dist/core/src/hooks/useLargeLayout.d.ts +1 -0
  119. package/dist/core/src/hooks/useModeController.d.ts +19 -0
  120. package/dist/core/src/hooks/usePermissions.d.ts +12 -0
  121. package/dist/core/src/hooks/useRebaseClient.d.ts +5 -0
  122. package/dist/core/src/hooks/useRebaseContext.d.ts +11 -0
  123. package/dist/core/src/hooks/useRebaseRegistry.d.ts +34 -0
  124. package/dist/core/src/hooks/useSlot.d.ts +18 -0
  125. package/dist/core/src/hooks/useSnackbarController.d.ts +20 -0
  126. package/dist/core/src/hooks/useStorageSource.d.ts +7 -0
  127. package/dist/core/src/hooks/useStudioBridge.d.ts +91 -0
  128. package/dist/core/src/hooks/useTranslation.d.ts +17 -0
  129. package/dist/core/src/hooks/useUnsavedChangesDialog.d.ts +12 -0
  130. package/dist/core/src/hooks/useUserConfigurationPersistence.d.ts +8 -0
  131. package/dist/core/src/hooks/useValidateAuthenticator.d.ts +21 -0
  132. package/dist/core/src/i18n/RebaseI18nProvider.d.ts +33 -0
  133. package/dist/core/src/index.d.ts +15 -0
  134. package/dist/core/src/internal/common.d.ts +3 -0
  135. package/dist/core/src/internal/useRestoreScroll.d.ts +6 -0
  136. package/dist/core/src/locales/de.d.ts +2 -0
  137. package/dist/core/src/locales/en.d.ts +10 -0
  138. package/dist/core/src/locales/es.d.ts +10 -0
  139. package/dist/core/src/locales/fr.d.ts +2 -0
  140. package/dist/core/src/locales/hi.d.ts +2 -0
  141. package/dist/core/src/locales/it.d.ts +2 -0
  142. package/dist/core/src/locales/pt.d.ts +7 -0
  143. package/dist/core/src/util/constants.d.ts +1 -0
  144. package/dist/core/src/util/createFormexStub.d.ts +2 -0
  145. package/dist/core/src/util/entity_cache.d.ts +27 -0
  146. package/dist/core/src/util/enums.d.ts +5 -0
  147. package/dist/core/src/util/icon_list.d.ts +5 -0
  148. package/dist/core/src/util/icon_synonyms.d.ts +1 -0
  149. package/dist/core/src/util/icons.d.ts +20 -0
  150. package/dist/core/src/util/index.d.ts +10 -0
  151. package/dist/core/src/util/previews.d.ts +4 -0
  152. package/dist/core/src/util/useStorageUploadController.d.ts +38 -0
  153. package/dist/core/src/util/useTraceUpdate.d.ts +2 -0
  154. package/dist/formex/src/Field.d.ts +52 -0
  155. package/dist/formex/src/Formex.d.ts +7 -0
  156. package/dist/formex/src/index.d.ts +5 -0
  157. package/dist/formex/src/types.d.ts +40 -0
  158. package/dist/formex/src/useCreateFormex.d.ts +14 -0
  159. package/dist/formex/src/utils.d.ts +16 -0
  160. package/dist/index.es.js +726 -0
  161. package/dist/index.es.js.map +1 -0
  162. package/dist/index.umd.js +9567 -0
  163. package/dist/index.umd.js.map +1 -0
  164. package/dist/studio/src/components/ApiExplorer/ApiExplorer.d.ts +9 -0
  165. package/dist/studio/src/components/ApiExplorer/EndpointDetail.d.ts +9 -0
  166. package/dist/studio/src/components/ApiExplorer/TryItPanel.d.ts +15 -0
  167. package/dist/studio/src/components/ApiExplorer/parseSpec.d.ts +16 -0
  168. package/dist/studio/src/components/ApiExplorer/types.d.ts +90 -0
  169. package/dist/studio/src/components/AuthSimulationSelector.d.ts +11 -0
  170. package/dist/studio/src/components/Branches/BranchesView.d.ts +1 -0
  171. package/dist/studio/src/components/CronJobs/CronJobsView.d.ts +1 -0
  172. package/dist/studio/src/components/JSEditor/JSEditor.d.ts +1 -0
  173. package/dist/studio/src/components/JSEditor/JSEditorSidebar.d.ts +21 -0
  174. package/dist/studio/src/components/JSEditor/JSMonacoEditor.d.ts +18 -0
  175. package/dist/studio/src/components/RLSEditor/PolicyEditor.d.ts +9 -0
  176. package/dist/studio/src/components/RLSEditor/RLSEditor.d.ts +19 -0
  177. package/dist/studio/src/components/RLSEditor/index.d.ts +1 -0
  178. package/dist/studio/src/components/RebaseStudio.d.ts +2 -0
  179. package/dist/studio/src/components/SQLEditor/ExplainVisualizer.d.ts +24 -0
  180. package/dist/studio/src/components/SQLEditor/MonacoEditor.d.ts +17 -0
  181. package/dist/studio/src/components/SQLEditor/SQLEditor.d.ts +11 -0
  182. package/dist/studio/src/components/SQLEditor/SQLEditorSidebar.d.ts +21 -0
  183. package/dist/studio/src/components/SQLEditor/SchemaBrowser.d.ts +8 -0
  184. package/dist/studio/src/components/SchemaVisualizer/RelationEdge.d.ts +3 -0
  185. package/dist/studio/src/components/SchemaVisualizer/SchemaVisualizer.d.ts +2 -0
  186. package/dist/studio/src/components/SchemaVisualizer/TableNode.d.ts +3 -0
  187. package/dist/studio/src/components/SchemaVisualizer/index.d.ts +5 -0
  188. package/dist/studio/src/components/SchemaVisualizer/schema-visualizer.utils.d.ts +42 -0
  189. package/dist/studio/src/components/SchemaVisualizer/useSchemaGraph.d.ts +37 -0
  190. package/dist/studio/src/components/StorageView/StorageView.d.ts +1 -0
  191. package/dist/studio/src/components/StudioHomePage.d.ts +9 -0
  192. package/dist/studio/src/index.d.ts +4 -0
  193. package/dist/studio/src/utils/entities.d.ts +0 -0
  194. package/dist/studio/src/utils/pgColumnToProperty.d.ts +6 -0
  195. package/dist/studio/src/utils/sql_utils.d.ts +52 -0
  196. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  197. package/dist/types/src/controllers/auth.d.ts +119 -0
  198. package/dist/types/src/controllers/client.d.ts +170 -0
  199. package/dist/types/src/controllers/collection_registry.d.ts +46 -0
  200. package/dist/types/src/controllers/customization_controller.d.ts +60 -0
  201. package/dist/types/src/controllers/data.d.ts +168 -0
  202. package/dist/types/src/controllers/data_driver.d.ts +195 -0
  203. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  204. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  205. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  206. package/dist/types/src/controllers/email.d.ts +34 -0
  207. package/dist/types/src/controllers/index.d.ts +18 -0
  208. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  209. package/dist/types/src/controllers/navigation.d.ts +213 -0
  210. package/dist/types/src/controllers/registry.d.ts +54 -0
  211. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  212. package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
  213. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  214. package/dist/types/src/controllers/storage.d.ts +171 -0
  215. package/dist/types/src/index.d.ts +4 -0
  216. package/dist/types/src/rebase_context.d.ts +105 -0
  217. package/dist/types/src/types/backend.d.ts +536 -0
  218. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  219. package/dist/types/src/types/builders.d.ts +15 -0
  220. package/dist/types/src/types/chips.d.ts +5 -0
  221. package/dist/types/src/types/collections.d.ts +857 -0
  222. package/dist/types/src/types/cron.d.ts +102 -0
  223. package/dist/types/src/types/data_source.d.ts +64 -0
  224. package/dist/types/src/types/entities.d.ts +145 -0
  225. package/dist/types/src/types/entity_actions.d.ts +98 -0
  226. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  227. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  228. package/dist/types/src/types/entity_overrides.d.ts +10 -0
  229. package/dist/types/src/types/entity_views.d.ts +59 -0
  230. package/dist/types/src/types/export_import.d.ts +21 -0
  231. package/dist/types/src/types/formex.d.ts +40 -0
  232. package/dist/types/src/types/index.d.ts +25 -0
  233. package/dist/types/src/types/locales.d.ts +4 -0
  234. package/dist/types/src/types/modify_collections.d.ts +5 -0
  235. package/dist/types/src/types/plugins.d.ts +282 -0
  236. package/dist/types/src/types/properties.d.ts +1148 -0
  237. package/dist/types/src/types/property_config.d.ts +70 -0
  238. package/dist/types/src/types/relations.d.ts +336 -0
  239. package/dist/types/src/types/slots.d.ts +262 -0
  240. package/dist/types/src/types/translations.d.ts +874 -0
  241. package/dist/types/src/types/user_management_delegate.d.ts +121 -0
  242. package/dist/types/src/types/websockets.d.ts +78 -0
  243. package/dist/types/src/users/index.d.ts +2 -0
  244. package/dist/types/src/users/roles.d.ts +22 -0
  245. package/dist/types/src/users/user.d.ts +46 -0
  246. package/dist/ui/src/components/Alert.d.ts +12 -0
  247. package/dist/ui/src/components/Autocomplete.d.ts +21 -0
  248. package/dist/ui/src/components/Avatar.d.ts +11 -0
  249. package/dist/ui/src/components/Badge.d.ts +8 -0
  250. package/dist/ui/src/components/BooleanSwitch.d.ts +14 -0
  251. package/dist/ui/src/components/BooleanSwitchWithLabel.d.ts +17 -0
  252. package/dist/ui/src/components/Button.d.ts +14 -0
  253. package/dist/ui/src/components/Card.d.ts +9 -0
  254. package/dist/ui/src/components/CenteredView.d.ts +9 -0
  255. package/dist/ui/src/components/Checkbox.d.ts +13 -0
  256. package/dist/ui/src/components/Chip.d.ts +26 -0
  257. package/dist/ui/src/components/CircularProgress.d.ts +5 -0
  258. package/dist/ui/src/components/CircularProgressCenter.d.ts +11 -0
  259. package/dist/ui/src/components/Collapse.d.ts +9 -0
  260. package/dist/ui/src/components/ColorPicker.d.ts +30 -0
  261. package/dist/ui/src/components/Container.d.ts +8 -0
  262. package/dist/ui/src/components/DateTimeField.d.ts +24 -0
  263. package/dist/ui/src/components/DebouncedTextField.d.ts +2 -0
  264. package/dist/ui/src/components/Dialog.d.ts +39 -0
  265. package/dist/ui/src/components/DialogActions.d.ts +7 -0
  266. package/dist/ui/src/components/DialogContent.d.ts +7 -0
  267. package/dist/ui/src/components/DialogTitle.d.ts +10 -0
  268. package/dist/ui/src/components/ErrorBoundary.d.ts +11 -0
  269. package/dist/ui/src/components/ExpandablePanel.d.ts +12 -0
  270. package/dist/ui/src/components/FileUpload.d.ts +23 -0
  271. package/dist/ui/src/components/IconButton.d.ts +12 -0
  272. package/dist/ui/src/components/InfoLabel.d.ts +5 -0
  273. package/dist/ui/src/components/InputLabel.d.ts +11 -0
  274. package/dist/ui/src/components/Label.d.ts +7 -0
  275. package/dist/ui/src/components/LoadingButton.d.ts +7 -0
  276. package/dist/ui/src/components/Markdown.d.ts +10 -0
  277. package/dist/ui/src/components/Menu.d.ts +23 -0
  278. package/dist/ui/src/components/Menubar.d.ts +80 -0
  279. package/dist/ui/src/components/MultiSelect.d.ts +48 -0
  280. package/dist/ui/src/components/Paper.d.ts +6 -0
  281. package/dist/ui/src/components/Popover.d.ts +24 -0
  282. package/dist/ui/src/components/RadioGroup.d.ts +28 -0
  283. package/dist/ui/src/components/ResizablePanels.d.ts +18 -0
  284. package/dist/ui/src/components/SearchBar.d.ts +22 -0
  285. package/dist/ui/src/components/Select.d.ts +43 -0
  286. package/dist/ui/src/components/Separator.d.ts +5 -0
  287. package/dist/ui/src/components/Sheet.d.ts +22 -0
  288. package/dist/ui/src/components/Skeleton.d.ts +6 -0
  289. package/dist/ui/src/components/Slider.d.ts +21 -0
  290. package/dist/ui/src/components/Table.d.ts +34 -0
  291. package/dist/ui/src/components/Tabs.d.ts +19 -0
  292. package/dist/ui/src/components/TextField.d.ts +58 -0
  293. package/dist/ui/src/components/TextareaAutosize.d.ts +43 -0
  294. package/dist/ui/src/components/ToggleButtonGroup.d.ts +30 -0
  295. package/dist/ui/src/components/Tooltip.d.ts +19 -0
  296. package/dist/ui/src/components/Typography.d.ts +36 -0
  297. package/dist/ui/src/components/VirtualTable/VirtualTable.d.ts +11 -0
  298. package/dist/ui/src/components/VirtualTable/VirtualTableCell.d.ts +21 -0
  299. package/dist/ui/src/components/VirtualTable/VirtualTableHeader.d.ts +29 -0
  300. package/dist/ui/src/components/VirtualTable/VirtualTableHeaderRow.d.ts +2 -0
  301. package/dist/ui/src/components/VirtualTable/VirtualTableProps.d.ts +243 -0
  302. package/dist/ui/src/components/VirtualTable/VirtualTableRow.d.ts +3 -0
  303. package/dist/ui/src/components/VirtualTable/index.d.ts +3 -0
  304. package/dist/ui/src/components/VirtualTable/types.d.ts +38 -0
  305. package/dist/ui/src/components/common/SelectInputLabel.d.ts +5 -0
  306. package/dist/ui/src/components/index.d.ts +53 -0
  307. package/dist/ui/src/hooks/PortalContainerContext.d.ts +31 -0
  308. package/dist/ui/src/hooks/index.d.ts +6 -0
  309. package/dist/ui/src/hooks/useDebounceCallback.d.ts +1 -0
  310. package/dist/ui/src/hooks/useDebounceValue.d.ts +1 -0
  311. package/dist/ui/src/hooks/useDebouncedCallback.d.ts +1 -0
  312. package/dist/ui/src/hooks/useInjectStyles.d.ts +7 -0
  313. package/dist/ui/src/hooks/useOutsideAlerter.d.ts +5 -0
  314. package/dist/ui/src/icons/GitHubIcon.d.ts +2 -0
  315. package/dist/ui/src/icons/HandleIcon.d.ts +1 -0
  316. package/dist/ui/src/icons/Icon.d.ts +20 -0
  317. package/dist/ui/src/icons/cool_icon_keys.d.ts +1 -0
  318. package/dist/ui/src/icons/icon_keys.d.ts +1 -0
  319. package/dist/ui/src/icons/index.d.ts +6 -0
  320. package/dist/ui/src/index.d.ts +5 -0
  321. package/dist/ui/src/styles.d.ts +12 -0
  322. package/dist/ui/src/util/chip_colors.d.ts +4 -0
  323. package/dist/ui/src/util/cls.d.ts +2 -0
  324. package/dist/ui/src/util/debounce.d.ts +10 -0
  325. package/dist/ui/src/util/hash.d.ts +1 -0
  326. package/dist/ui/src/util/index.d.ts +4 -0
  327. package/dist/ui/src/util/key_to_icon_component.d.ts +1 -0
  328. package/package.json +84 -0
  329. package/src/components/ApiExplorer/ApiExplorer.tsx +292 -0
  330. package/src/components/ApiExplorer/EndpointDetail.tsx +271 -0
  331. package/src/components/ApiExplorer/TryItPanel.tsx +486 -0
  332. package/src/components/ApiExplorer/parseSpec.ts +104 -0
  333. package/src/components/ApiExplorer/types.ts +84 -0
  334. package/src/components/AuthSimulationSelector.tsx +73 -0
  335. package/src/components/Branches/BranchesView.tsx +370 -0
  336. package/src/components/CronJobs/CronJobsView.tsx +346 -0
  337. package/src/components/JSEditor/JSEditor.tsx +1033 -0
  338. package/src/components/JSEditor/JSEditorSidebar.tsx +340 -0
  339. package/src/components/JSEditor/JSMonacoEditor.tsx +390 -0
  340. package/src/components/RLSEditor/PolicyEditor.tsx +444 -0
  341. package/src/components/RLSEditor/RLSEditor.tsx +771 -0
  342. package/src/components/RLSEditor/index.ts +1 -0
  343. package/src/components/RebaseStudio.tsx +121 -0
  344. package/src/components/SQLEditor/ExplainVisualizer.tsx +128 -0
  345. package/src/components/SQLEditor/MonacoEditor.tsx +203 -0
  346. package/src/components/SQLEditor/SQLEditor.tsx +1417 -0
  347. package/src/components/SQLEditor/SQLEditorSidebar.tsx +174 -0
  348. package/src/components/SQLEditor/SchemaBrowser.tsx +156 -0
  349. package/src/components/SchemaVisualizer/RelationEdge.tsx +102 -0
  350. package/src/components/SchemaVisualizer/SchemaVisualizer.tsx +663 -0
  351. package/src/components/SchemaVisualizer/TableNode.tsx +257 -0
  352. package/src/components/SchemaVisualizer/index.ts +5 -0
  353. package/src/components/SchemaVisualizer/schema-visualizer.utils.ts +140 -0
  354. package/src/components/SchemaVisualizer/useSchemaGraph.ts +397 -0
  355. package/src/components/StorageView/StorageView.tsx +938 -0
  356. package/src/components/StudioHomePage.tsx +357 -0
  357. package/src/index.ts +31 -0
  358. package/src/utils/entities.ts +2 -0
  359. package/src/utils/pgColumnToProperty.test.ts +401 -0
  360. package/src/utils/pgColumnToProperty.ts +275 -0
  361. package/src/utils/sql_utils.test.ts +265 -0
  362. package/src/utils/sql_utils.ts +291 -0
  363. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,771 @@
1
+
2
+ import { useStudioCollectionRegistry } from "@rebasepro/core";
3
+ import React, { useState, useEffect, useCallback, useMemo } from "react";
4
+ import { Paper, Typography, CircularProgress, cls, Alert, defaultBorderMixin, Card, Chip, Button, Tooltip, ResizablePanels, IconButton, Tabs, Tab , iconSize } from "@rebasepro/ui";
5
+ import { ShieldIcon, RefreshCwIcon, AlertTriangleIcon, KeyIcon, Trash2Icon } from "lucide-react";
6
+ import { useRebaseContext, useSnackbarController, ErrorView, useTranslation } from "@rebasepro/core";
7
+ import { isPostgresCollection } from "@rebasepro/types";
8
+ import { PolicyEditor } from "./PolicyEditor";
9
+
10
+ /**
11
+ * Validates and double-quotes a SQL identifier to prevent injection.
12
+ * Only allows safe Postgres identifiers (letters, digits, underscores).
13
+ * Throws if the identifier contains unsafe characters.
14
+ */
15
+ function sanitizeSqlIdentifier(name: string): string {
16
+ if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
17
+ throw new Error(`Invalid SQL identifier: "${name}". Only letters, digits, and underscores are allowed.`);
18
+ }
19
+ return `"${name}"`;
20
+ }
21
+
22
+ export interface PostgresPolicy {
23
+ policyname: string;
24
+ tablename: string;
25
+ permissive: "PERMISSIVE" | "RESTRICTIVE";
26
+ roles: string[];
27
+ cmd: "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "ALL";
28
+ qual: string | null; // USING clause
29
+ with_check: string | null; // WITH CHECK clause
30
+ status?: "live" | "code_only" | "both";
31
+ }
32
+
33
+ export interface TableRLSStatus {
34
+ schemaName: string;
35
+ tableName: string;
36
+ rlsEnabled: boolean;
37
+ policies: PostgresPolicy[];
38
+ }
39
+
40
+ export const RLSEditor = ({ apiUrl = "" }: { apiUrl?: string }) => {
41
+ const { databaseAdmin } = useRebaseContext();
42
+ const snackbarController = useSnackbarController();
43
+ const collectionRegistry = useStudioCollectionRegistry();
44
+ const { t } = useTranslation();
45
+
46
+ const [isLoading, setIsLoading] = useState(true);
47
+ const [error, setError] = useState<string | null>(null);
48
+ const [tables, setTables] = useState<TableRLSStatus[]>([]);
49
+ const [selectedTable, setSelectedTable] = useState<string | null>(null);
50
+ const [activeTab, setActiveTab] = useState(0);
51
+
52
+ const [editingPolicy, setEditingPolicy] = useState<PostgresPolicy | "new" | null>(null);
53
+
54
+ const [sidebarSize, setSidebarSize] = useState(() => {
55
+ try {
56
+ const saved = localStorage.getItem("rebase_rls_editor_sidebar_size");
57
+ return saved !== null ? parseFloat(saved) : 20;
58
+ } catch (e) {
59
+ return 20;
60
+ }
61
+ });
62
+
63
+ const [expandedSchemas, setExpandedSchemas] = useState<Record<string, boolean>>({ public: true });
64
+
65
+ // Sidebar tab: "tables" or "info"
66
+ const [sidebarTab, setSidebarTab] = useState<"tables" | "info">("tables");
67
+
68
+ useEffect(() => {
69
+ try {
70
+ localStorage.setItem("rebase_rls_editor_sidebar_size", sidebarSize.toString());
71
+ } catch (e) { /* ignore */ }
72
+ }, [sidebarSize]);
73
+
74
+ const fetchRLSData = useCallback(async () => {
75
+ if (!databaseAdmin?.executeSql) {
76
+ setError(t("studio_sql_sql_not_supported"));
77
+ setIsLoading(false);
78
+ return;
79
+ }
80
+
81
+ setIsLoading(true);
82
+ setError(null);
83
+ try {
84
+ // 1. Fetch tables and whether RLS is enabled
85
+ const tablesSql = `
86
+ SELECT
87
+ schemaname,
88
+ tablename,
89
+ rowsecurity
90
+ FROM pg_tables
91
+ WHERE schemaname NOT IN ('information_schema', 'pg_catalog')
92
+ ORDER BY schemaname, tablename;
93
+ `;
94
+ const tablesResult = await databaseAdmin!.executeSql!(tablesSql);
95
+
96
+ // 2. Fetch all policies
97
+ const policiesSql = `
98
+ SELECT
99
+ schemaname,
100
+ tablename,
101
+ policyname,
102
+ permissive,
103
+ roles,
104
+ cmd,
105
+ qual,
106
+ with_check
107
+ FROM pg_policies
108
+ WHERE schemaname NOT IN ('information_schema', 'pg_catalog');
109
+ `;
110
+ const policiesResult = await databaseAdmin!.executeSql!(policiesSql);
111
+
112
+ const extractRows = (result: unknown): Record<string, unknown>[] => {
113
+ if (result && typeof result === "object" && "rows" in result && Array.isArray((result as { rows: Record<string, unknown>[] }).rows)) {
114
+ return (result as { rows: Record<string, unknown>[] }).rows;
115
+ }
116
+ if (Array.isArray(result)) return result as Record<string, unknown>[];
117
+ return [];
118
+ };
119
+
120
+ const tRows = extractRows(tablesResult);
121
+ const pRows = extractRows(policiesResult);
122
+
123
+ const tableMap: Record<string, TableRLSStatus> = {};
124
+
125
+ tRows.forEach((tRow: Record<string, unknown>) => {
126
+ const t = tRow as { schemaname?: string, SCHEMANAME?: string, tablename?: string, TABLENAME?: string, rowsecurity?: boolean, ROWSECURITY?: boolean };
127
+ const schema = t.schemaname || t.SCHEMANAME || "public";
128
+ const table = t.tablename || t.TABLENAME || "";
129
+ const rlsEnabled = t.rowsecurity || t.ROWSECURITY || false;
130
+
131
+ const key = `${schema}.${table}`;
132
+ tableMap[key] = {
133
+ schemaName: schema,
134
+ tableName: table,
135
+ rlsEnabled: rlsEnabled,
136
+ policies: []
137
+ };
138
+ });
139
+
140
+ pRows.forEach((pRow: Record<string, unknown>) => {
141
+ const p = pRow as { schemaname?: string, SCHEMANAME?: string, tablename?: string, TABLENAME?: string, roles?: string | string[], ROLES?: string | string[], policyname?: string, POLICYNAME?: string, permissive?: "PERMISSIVE" | "RESTRICTIVE", PERMISSIVE?: "PERMISSIVE" | "RESTRICTIVE", cmd?: "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "ALL", CMD?: "SELECT" | "INSERT" | "UPDATE" | "DELETE" | "ALL", qual?: string | null, QUAL?: string | null, with_check?: string | null, WITH_CHECK?: string | null };
142
+ const schema = p.schemaname || p.SCHEMANAME || "public";
143
+ const table = p.tablename || p.TABLENAME || "";
144
+ const key = `${schema}.${table}`;
145
+
146
+ if (tableMap[key]) {
147
+ // Postgres roles come back as an array string like "{public}" or literal array
148
+ let parsedRoles: string[] = [];
149
+ const r = p.roles || p.ROLES;
150
+ if (Array.isArray(r)) {
151
+ parsedRoles = r;
152
+ } else if (typeof r === "string") {
153
+ parsedRoles = r.replace(/^{|}$/g, "").split(",").map(s => s.trim());
154
+ }
155
+
156
+ tableMap[key].policies.push({
157
+ policyname: p.policyname || p.POLICYNAME || "",
158
+ tablename: table,
159
+ permissive: p.permissive || p.PERMISSIVE || "PERMISSIVE",
160
+ roles: parsedRoles,
161
+ cmd: p.cmd || p.CMD || "ALL",
162
+ qual: p.qual || p.QUAL || null,
163
+ with_check: p.with_check || p.WITH_CHECK || null
164
+ });
165
+ }
166
+ });
167
+
168
+ const sortedTables = Object.values(tableMap).sort((a, b) => a.tableName.localeCompare(b.tableName));
169
+ setTables(sortedTables);
170
+
171
+ if (sortedTables.length > 0 && !selectedTable) {
172
+ setSelectedTable(`${sortedTables[0].schemaName}.${sortedTables[0].tableName}`);
173
+ }
174
+
175
+ } catch (e: unknown) {
176
+ console.error("RLS fetch error:", e);
177
+ setError("Failed to fetch RLS policies: " + (e instanceof Error ? e.message : String(e)));
178
+ } finally {
179
+ setIsLoading(false);
180
+ }
181
+ }, [databaseAdmin, selectedTable]);
182
+
183
+ useEffect(() => {
184
+ setEditingPolicy(null);
185
+ }, [selectedTable]);
186
+
187
+ useEffect(() => {
188
+ fetchRLSData();
189
+ }, [fetchRLSData]);
190
+
191
+ const activeTableData = useMemo(() => {
192
+ if (!selectedTable) return null;
193
+ return tables.find(t => `${t.schemaName}.${t.tableName}` === selectedTable) || null;
194
+ }, [selectedTable, tables]);
195
+
196
+ const groupedTables = useMemo(() => {
197
+ const groups: Record<string, TableRLSStatus[]> = {};
198
+ tables.forEach(table => {
199
+ if (!groups[table.schemaName]) {
200
+ groups[table.schemaName] = [];
201
+ }
202
+ groups[table.schemaName].push(table);
203
+ });
204
+ return groups;
205
+ }, [tables]);
206
+
207
+ const activeCollection = useMemo(() => {
208
+ if (!activeTableData) return null;
209
+ return collectionRegistry.collections?.find((c: { id?: string, path?: string, table?: string, slug?: string, collectionId?: string }) =>
210
+ c.id === activeTableData.tableName ||
211
+ c.path === activeTableData.tableName ||
212
+ c.table === activeTableData.tableName ||
213
+ c.slug === activeTableData.tableName ||
214
+ c.collectionId === activeTableData.tableName
215
+ ) || null;
216
+ }, [activeTableData, collectionRegistry.collections]);
217
+
218
+ const mergedPolicies = useMemo(() => {
219
+ if (!activeTableData) return [];
220
+
221
+ const policiesMap: Record<string, PostgresPolicy> = {};
222
+
223
+ // Load live policies
224
+ (activeTableData.policies || []).forEach(p => {
225
+ policiesMap[p.policyname] = { ...p,
226
+ status: "live" };
227
+ });
228
+
229
+ // Merge code-based policies
230
+ if (activeCollection && isPostgresCollection(activeCollection) && activeCollection.securityRules) {
231
+ activeCollection.securityRules.forEach((rule: { name?: string, mode?: string, operation?: string, roles?: string[], using?: string, withCheck?: string }) => {
232
+ const ruleName = rule.name;
233
+ if (!ruleName) return;
234
+
235
+ if (policiesMap[ruleName]) {
236
+ // It exists in Postgres, but we have a code definition (potentially edited)
237
+ policiesMap[ruleName] = {
238
+ policyname: ruleName,
239
+ tablename: activeTableData.tableName,
240
+ permissive: (rule.mode || "permissive").toUpperCase() as PostgresPolicy["permissive"],
241
+ cmd: (rule.operation || "ALL").toUpperCase() as PostgresPolicy["cmd"],
242
+ roles: rule.roles || ["public"],
243
+ qual: rule.using || null,
244
+ with_check: rule.withCheck || null,
245
+ status: "both"
246
+ };
247
+ } else {
248
+ policiesMap[ruleName] = {
249
+ policyname: ruleName,
250
+ tablename: activeTableData.tableName,
251
+ permissive: (rule.mode || "permissive").toUpperCase() as PostgresPolicy["permissive"],
252
+ cmd: (rule.operation || "ALL").toUpperCase() as PostgresPolicy["cmd"],
253
+ roles: rule.roles || ["public"],
254
+ qual: rule.using || null,
255
+ with_check: rule.withCheck || null,
256
+ status: "code_only"
257
+ };
258
+ }
259
+ });
260
+ }
261
+
262
+ return Object.values(policiesMap).sort((a, b) => a.policyname.localeCompare(b.policyname));
263
+ }, [activeTableData, activeCollection]);
264
+
265
+ // Stats for the info tab
266
+ const rlsStats = useMemo(() => {
267
+ const total = tables.length;
268
+ const enabled = tables.filter(t => t.rlsEnabled).length;
269
+ const withPolicies = tables.filter(t => t.policies.length > 0).length;
270
+ const totalPolicies = tables.reduce((sum, t) => sum + t.policies.length, 0);
271
+ return { total,
272
+ enabled,
273
+ withPolicies,
274
+ totalPolicies };
275
+ }, [tables]);
276
+
277
+ const renderPolicyTag = (label: string, value: string) => {
278
+ return (
279
+ <div className="flex items-center gap-1.5 px-2 py-1 rounded-md bg-surface-100 dark:bg-surface-950 border border-surface-200 dark:border-surface-700/50">
280
+ <span className="text-[10px] uppercase text-text-secondary dark:text-text-secondary-dark font-medium tracking-wider">
281
+ {label}:
282
+ </span>
283
+ <span className="font-mono text-xs text-text-primary dark:text-text-primary-dark break-all">
284
+ {value}
285
+ </span>
286
+ </div>
287
+ );
288
+ };
289
+
290
+ return (
291
+ <div className="flex h-full w-full bg-white dark:bg-surface-950 overflow-hidden text-text-primary dark:text-text-primary-dark">
292
+ <ResizablePanels
293
+ orientation="horizontal"
294
+ panelSizePercent={sidebarSize}
295
+ onPanelSizeChange={setSidebarSize}
296
+ minPanelSizePx={220}
297
+ firstPanel={
298
+ <div className={cls("flex flex-col h-full w-full bg-white dark:bg-surface-950 border-r", defaultBorderMixin)}>
299
+ <Tabs value={sidebarTab} onValueChange={(v) => setSidebarTab(v as "tables" | "info")} variant="boxy" className="border-b border-surface-200 dark:border-surface-950">
300
+ <Tab value="tables">Tables</Tab>
301
+ <Tab value="info">Info</Tab>
302
+ </Tabs>
303
+
304
+ <div className="flex-grow overflow-hidden relative">
305
+ {sidebarTab === "tables" && (
306
+ <div className="flex flex-col h-full">
307
+ <div className={cls("flex items-center justify-between px-3 py-2 border-b bg-surface-50 dark:bg-surface-900 min-h-[48px]", defaultBorderMixin)}>
308
+ <Typography variant="caption" className="font-bold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark">
309
+ {t("studio_schema_tables")}
310
+ </Typography>
311
+ <IconButton size="small" onClick={fetchRLSData} title="Refresh">
312
+ <RefreshCwIcon size={iconSize.smallest}/>
313
+ </IconButton>
314
+ </div>
315
+ <div className="flex-grow overflow-y-auto no-scrollbar p-1">
316
+ {isLoading && tables.length === 0 ? (
317
+ <div className="flex justify-center p-4"><CircularProgress size="small"/></div>
318
+ ) : Object.keys(groupedTables).length === 0 ? (
319
+ <div className="p-4 text-center">
320
+ <Typography variant="caption" className="text-text-disabled dark:text-text-disabled-dark italic">{t("studio_rls_no_tables")}</Typography>
321
+ </div>
322
+ ) : (
323
+ Object.entries(groupedTables).map(([schemaName, schemaTables]) => (
324
+ <div key={schemaName} className="mb-2">
325
+ <div
326
+ className="flex items-center p-1 cursor-pointer hover:bg-surface-100 dark:hover:bg-surface-950 rounded transition-colors"
327
+ onClick={() => setExpandedSchemas(prev => ({ ...prev,
328
+ [schemaName]: !prev[schemaName] }))}
329
+ >
330
+ <svg className={cls("w-3 h-3 mr-1 transition-transform", expandedSchemas[schemaName] ? "rotate-90" : "")} fill="currentColor" viewBox="0 0 20 20"><path d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"/></svg>
331
+ <Typography variant="body2" className="text-text-primary dark:text-text-primary-dark font-medium text-xs truncate flex-grow">{schemaName}</Typography>
332
+ </div>
333
+
334
+ {expandedSchemas[schemaName] && (
335
+ <div className="ml-3 mt-1 space-y-0.5">
336
+ {schemaTables.map(table => {
337
+ const key = `${table.schemaName}.${table.tableName}`;
338
+ const isSelected = selectedTable === key;
339
+ return (
340
+ <div
341
+ key={key}
342
+ onClick={() => setSelectedTable(key)}
343
+ className={cls(
344
+ "flex items-center p-1 cursor-pointer rounded transition-colors group relative",
345
+ isSelected
346
+ ? "bg-primary/10 text-primary dark:bg-primary/20 dark:text-primary-light"
347
+ : "hover:bg-surface-100 dark:hover:bg-surface-950 text-text-secondary dark:text-text-secondary-dark"
348
+ )}
349
+ >
350
+ <svg className="w-3.5 h-3.5 mr-1 shrink-0 text-text-disabled dark:text-text-disabled-dark" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 10h18M3 14h18m-9-4v8m-7 0h14a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
351
+ <Typography variant="body2" className="text-xs truncate flex-1 min-w-0">{table.tableName}</Typography>
352
+ <div className="flex items-center gap-1.5 shrink-0 ml-2">
353
+ {table.rlsEnabled ? (
354
+ <Tooltip title={t("studio_rls_enabled")}>
355
+ <div className="w-1.5 h-1.5 rounded-full bg-green-500"/>
356
+ </Tooltip>
357
+ ) : (
358
+ <Tooltip title={t("studio_rls_disabled")}>
359
+ <div className="w-1.5 h-1.5 rounded-full bg-orange-400 opacity-50"/>
360
+ </Tooltip>
361
+ )}
362
+ <span className="text-[10px] opacity-40 group-hover:opacity-100 min-w-[1.2rem] text-right font-medium">
363
+ {table.policies.length}
364
+ </span>
365
+ </div>
366
+ </div>
367
+ );
368
+ })}
369
+ </div>
370
+ )}
371
+ </div>
372
+ ))
373
+ )}
374
+ </div>
375
+ </div>
376
+ )}
377
+
378
+ {sidebarTab === "info" && (
379
+ <div className="flex flex-col h-full">
380
+ <div className={cls("flex items-center justify-between px-3 py-2 border-b bg-surface-50 dark:bg-surface-900 min-h-[48px]", defaultBorderMixin)}>
381
+ <Typography variant="caption" className="font-bold uppercase tracking-wider text-text-disabled dark:text-text-disabled-dark">
382
+ Overview
383
+ </Typography>
384
+ </div>
385
+ <div className="flex-grow overflow-y-auto p-3 space-y-3 no-scrollbar">
386
+ <div className={cls("p-3 rounded-lg border bg-white dark:bg-surface-900", defaultBorderMixin)}>
387
+ <div className="flex items-center gap-2 mb-2">
388
+ <ShieldIcon size={iconSize.smallest} className="text-primary"/>
389
+ <Typography variant="body2" className="font-semibold text-[13px]">RLS Studio</Typography>
390
+ </div>
391
+ <Typography variant="caption" className="text-text-secondary dark:text-text-secondary-dark text-[11px] leading-relaxed block">
392
+ Manage Row Level Security policies for your PostgreSQL tables. Enable RLS and create fine-grained access policies.
393
+ </Typography>
394
+ </div>
395
+
396
+ <div className="space-y-2">
397
+ <div className={cls("p-2.5 rounded border bg-white dark:bg-surface-900 flex items-center justify-between", defaultBorderMixin)}>
398
+ <Typography variant="caption" className="text-text-secondary dark:text-text-secondary-dark text-[11px]">Total tables</Typography>
399
+ <Typography variant="body2" className="font-mono text-[13px] font-medium">{rlsStats.total}</Typography>
400
+ </div>
401
+ <div className={cls("p-2.5 rounded border bg-white dark:bg-surface-900 flex items-center justify-between", defaultBorderMixin)}>
402
+ <Typography variant="caption" className="text-text-secondary dark:text-text-secondary-dark text-[11px]">RLS enabled</Typography>
403
+ <div className="flex items-center gap-1.5">
404
+ <div className="w-1.5 h-1.5 rounded-full bg-green-500"/>
405
+ <Typography variant="body2" className="font-mono text-[13px] font-medium">{rlsStats.enabled}</Typography>
406
+ </div>
407
+ </div>
408
+ <div className={cls("p-2.5 rounded border bg-white dark:bg-surface-900 flex items-center justify-between", defaultBorderMixin)}>
409
+ <Typography variant="caption" className="text-text-secondary dark:text-text-secondary-dark text-[11px]">Tables with policies</Typography>
410
+ <Typography variant="body2" className="font-mono text-[13px] font-medium">{rlsStats.withPolicies}</Typography>
411
+ </div>
412
+ <div className={cls("p-2.5 rounded border bg-white dark:bg-surface-900 flex items-center justify-between", defaultBorderMixin)}>
413
+ <Typography variant="caption" className="text-text-secondary dark:text-text-secondary-dark text-[11px]">Total policies</Typography>
414
+ <Typography variant="body2" className="font-mono text-[13px] font-medium">{rlsStats.totalPolicies}</Typography>
415
+ </div>
416
+ </div>
417
+
418
+ {/* Security health indicators */}
419
+ {rlsStats.total - rlsStats.enabled > 0 && (
420
+ <div className={cls("p-2.5 rounded border border-yellow-200 dark:border-yellow-900/50 bg-yellow-50 dark:bg-yellow-900/20 flex items-start gap-2", defaultBorderMixin)}>
421
+ <AlertTriangleIcon size={14} className="text-yellow-600 dark:text-yellow-500 mt-0.5 shrink-0"/>
422
+ <div>
423
+ <Typography variant="caption" className="text-yellow-800 dark:text-yellow-400 text-[11px] font-semibold block">
424
+ {rlsStats.total - rlsStats.enabled} table{rlsStats.total - rlsStats.enabled > 1 ? "s" : ""} without RLS
425
+ </Typography>
426
+ <Typography variant="caption" className="text-yellow-700 dark:text-yellow-600 text-[10px] block mt-0.5">
427
+ These tables have no row-level access control. If auth enforcement is disabled, data may be publicly accessible.
428
+ </Typography>
429
+ </div>
430
+ </div>
431
+ )}
432
+
433
+ {rlsStats.enabled > 0 && rlsStats.enabled - rlsStats.withPolicies > 0 && (
434
+ <div className={cls("p-2.5 rounded border border-blue-200 dark:border-blue-900/50 bg-blue-50 dark:bg-blue-900/20 flex items-start gap-2", defaultBorderMixin)}>
435
+ <ShieldIcon size={14} className="text-blue-600 dark:text-blue-400 mt-0.5 shrink-0"/>
436
+ <div>
437
+ <Typography variant="caption" className="text-blue-800 dark:text-blue-300 text-[11px] font-semibold block">
438
+ {rlsStats.enabled - rlsStats.withPolicies} table{rlsStats.enabled - rlsStats.withPolicies > 1 ? "s" : ""} with RLS but no policies
439
+ </Typography>
440
+ <Typography variant="caption" className="text-blue-700 dark:text-blue-500 text-[10px] block mt-0.5">
441
+ RLS is enabled but no permissive policies exist. All access is denied by default (Postgres deny-all).
442
+ </Typography>
443
+ </div>
444
+ </div>
445
+ )}
446
+ </div>
447
+ </div>
448
+ )}
449
+ </div>
450
+ </div>
451
+ }
452
+ secondPanel={
453
+ <div className="flex-grow flex flex-col min-w-0 h-full w-full bg-white dark:bg-surface-950">
454
+ {/* Toolbar Header matching SQL/JS Editor style */}
455
+ <div className={cls("flex items-center justify-between pr-2 border-b bg-white dark:bg-surface-950 min-h-[46px]", defaultBorderMixin)}>
456
+ <div className="flex items-center flex-grow overflow-hidden px-4">
457
+ <Typography variant="subtitle2" className="font-mono text-text-secondary dark:text-text-secondary-dark truncate">
458
+ {activeTableData ? `${activeTableData.schemaName}.${activeTableData.tableName}` : t("studio_rls_select_table")}
459
+ </Typography>
460
+ {activeTableData && (
461
+ <div className="ml-3">
462
+ {activeTableData.rlsEnabled ? (
463
+ <Chip size="smallest" className="bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400 border-green-200 dark:border-green-800">{t("studio_rls_enabled")}</Chip>
464
+ ) : (
465
+ <Chip size="smallest" className="bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400 border-yellow-200 dark:border-yellow-800">{t("studio_rls_disabled")}</Chip>
466
+ )}
467
+ </div>
468
+ )}
469
+ </div>
470
+ <div className="flex shrink-0 items-center justify-end gap-1.5">
471
+ {activeTableData && (
472
+ <>
473
+ <Button
474
+ variant="text"
475
+ size="small"
476
+ onClick={async () => {
477
+ const table = activeTableData.tableName;
478
+ const action = activeTableData.rlsEnabled ? "DISABLE" : "ENABLE";
479
+ if (!confirm(`Are you sure you want to ${action.toLowerCase()} Row Level Security on "${table}"?`)) return;
480
+ try {
481
+ await databaseAdmin!.executeSql!(`ALTER TABLE ${sanitizeSqlIdentifier(table)} ${action} ROW LEVEL SECURITY`);
482
+ snackbarController.open({ type: "success",
483
+ message: `RLS ${action.toLowerCase()}d on ${table}` });
484
+ fetchRLSData();
485
+ } catch (e: unknown) {
486
+ snackbarController.open({ type: "error",
487
+ message: e instanceof Error ? e.message : String(e) });
488
+ }
489
+ }}
490
+ >
491
+ {activeTableData.rlsEnabled ? t("studio_rls_disable_rls") : t("studio_rls_enable_rls")}
492
+ </Button>
493
+
494
+ <div className="h-4 w-px bg-surface-200 dark:bg-surface-950 mx-1"/>
495
+
496
+ <Button
497
+ variant="text"
498
+ size="small"
499
+ onClick={fetchRLSData}
500
+ startIcon={<RefreshCwIcon size={iconSize.smallest}/>}
501
+ >
502
+ Refresh
503
+ </Button>
504
+
505
+ <div className="h-4 w-px bg-surface-200 dark:bg-surface-950 mx-1"/>
506
+
507
+ <Button
508
+ size="small"
509
+ color="primary"
510
+ disabled={!activeCollection}
511
+ onClick={() => setEditingPolicy("new")}
512
+ >
513
+ {t("studio_rls_create_policy")}
514
+ </Button>
515
+ </>
516
+ )}
517
+ </div>
518
+ </div>
519
+
520
+ {isLoading && !activeTableData ? (
521
+ <div className="flex-grow flex items-center justify-center h-full">
522
+ <CircularProgress size="small"/>
523
+ </div>
524
+ ) : error ? (
525
+ <div className="p-6 h-full flex items-center justify-center">
526
+ <ErrorView title={t("studio_rls_error")} error={error} onRetry={fetchRLSData}/>
527
+ </div>
528
+ ) : !activeTableData ? (
529
+ <div className="flex-grow flex items-center justify-center text-text-disabled h-full">
530
+ <div className="text-center">
531
+ <svg className="w-12 h-12 mx-auto mb-4 opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={1} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>
532
+ <Typography variant="body2">{t("studio_rls_select_table")}</Typography>
533
+ </div>
534
+ </div>
535
+ ) : editingPolicy ? (
536
+ <PolicyEditor
537
+ policy={editingPolicy === "new" ? undefined : editingPolicy}
538
+ schema={activeTableData.schemaName}
539
+ table={activeTableData.tableName}
540
+ onSave={async (newPolicy) => {
541
+ if (!activeCollection) return;
542
+ const rule: Record<string, unknown> = {
543
+ name: newPolicy.policyname,
544
+ operation: newPolicy.cmd?.toLowerCase(),
545
+ mode: newPolicy.permissive?.toLowerCase(),
546
+ using: newPolicy.qual || undefined,
547
+ withCheck: newPolicy.with_check || undefined,
548
+ roles: newPolicy.roles
549
+ };
550
+
551
+ const existingRules = (isPostgresCollection(activeCollection) ? activeCollection.securityRules : undefined) || [];
552
+ let newRules;
553
+ if (editingPolicy === "new") {
554
+ newRules = [...existingRules, rule];
555
+ } else {
556
+ newRules = existingRules.map((r: { name?: string }) => r.name === editingPolicy.policyname ? rule : r);
557
+ }
558
+
559
+ try {
560
+ const response = await fetch(`${apiUrl}/api/schema-editor/collection/save`, {
561
+ method: "POST",
562
+ headers: { "Content-Type": "application/json" },
563
+ body: JSON.stringify({
564
+ collectionId: (activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData.tableName,
565
+ collectionData: { securityRules: newRules }
566
+ })
567
+ });
568
+ if (!response.ok) throw new Error("Failed to save policy");
569
+
570
+ snackbarController.open({ type: "success",
571
+ message: "Policy saved successfully" });
572
+ setEditingPolicy(null);
573
+ fetchRLSData();
574
+ } catch (e: unknown) {
575
+ snackbarController.open({ type: "error",
576
+ message: e instanceof Error ? e.message : String(e) });
577
+ }
578
+ }}
579
+ onCancel={() => setEditingPolicy(null)}
580
+ />
581
+ ) : (
582
+ <div className="flex-grow flex flex-col overflow-hidden">
583
+ <div className="p-6 pt-4 flex-grow overflow-auto bg-surface-50 dark:bg-surface-900">
584
+ <div className="max-w-4xl mx-auto flex flex-col gap-6">
585
+ {activeTableData && !activeCollection && (
586
+ <Alert
587
+ color="warning"
588
+ >
589
+ <Typography variant="body2" className="mb-1">
590
+ Table not managed by Rebase
591
+ </Typography>
592
+ <Typography variant="caption" className="opacity-80">
593
+ This table is not mapped to a Rebase Schema via code. To edit security policies visually, you must first import this table into a Schema configuration file.
594
+ </Typography>
595
+ </Alert>
596
+ )}
597
+
598
+ {activeTableData && !activeTableData.rlsEnabled && (
599
+ <div className={cls("p-4 sm:p-5 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-900/50 rounded-lg flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between", defaultBorderMixin)}>
600
+ <div className="flex gap-3 items-start">
601
+ <div className="mt-1 bg-yellow-100 dark:bg-yellow-900/50 p-1.5 rounded-md shrink-0 flex items-center justify-center">
602
+ <AlertTriangleIcon size={iconSize.smallest}/>
603
+ </div>
604
+ <div>
605
+ <Typography variant="subtitle2" className="text-yellow-800 dark:text-yellow-500">
606
+ Row Level Security (RLS) is disabled
607
+ </Typography>
608
+ <Typography variant="body2" className="text-yellow-700 dark:text-yellow-600/90 mt-1 max-w-2xl">
609
+ Your table is completely readable and writable by anyone with access privileges. Enable RLS to create policies that restrict access to specific rows.
610
+ </Typography>
611
+ </div>
612
+ </div>
613
+ <Button
614
+ size="medium"
615
+ variant="filled"
616
+ color="neutral"
617
+ onClick={() => setEditingPolicy("new")}
618
+ className="shrink-0 whitespace-nowrap"
619
+ disabled={!activeCollection}
620
+ >
621
+ {t("studio_rls_create_policy")}
622
+ </Button>
623
+ </div>
624
+ )}
625
+
626
+ {activeTableData && mergedPolicies && mergedPolicies.length > 0 && (
627
+ <div className="flex flex-col gap-3">
628
+ <Typography variant="subtitle2" className="text-text-secondary dark:text-text-secondary-dark uppercase tracking-wider mb-1">{t("studio_rls_policies")}</Typography>
629
+ {mergedPolicies.map(policy => (
630
+ <Paper key={policy.policyname} className={cls("p-3 sm:px-4 sm:py-3 flex flex-col sm:flex-row sm:items-center justify-between gap-4 border rounded-lg", defaultBorderMixin)}>
631
+ <div className="flex flex-col gap-2 min-w-0">
632
+ <div className="flex items-center gap-2">
633
+ <KeyIcon size={iconSize.smallest} className="text-text-secondary dark:text-text-secondary-dark shrink-0"/>
634
+ <Typography variant="body2" className="truncate">{policy.policyname}</Typography>
635
+ {policy.status === "code_only" && (
636
+ <Tooltip title="This policy is defined in your code but hasn't been applied to the database yet.">
637
+ <div className="px-1.5 py-0.5 rounded text-[10px] uppercase bg-primary/10 text-primary border border-primary/20 shrink-0">
638
+ Unapplied
639
+ </div>
640
+ </Tooltip>
641
+ )}
642
+ {policy.status === "live" && (
643
+ <Tooltip title="This policy is live in the database but missing from your codebase schema.">
644
+ <div className="px-1.5 py-0.5 rounded text-[10px] uppercase bg-orange-500/10 text-orange-600 border border-orange-500/20 shrink-0">
645
+ DB Only
646
+ </div>
647
+ </Tooltip>
648
+ )}
649
+ </div>
650
+ <div className="flex flex-wrap gap-1.5 text-sm">
651
+ {renderPolicyTag("Action", policy.cmd)}
652
+ {renderPolicyTag("Roles", Array.isArray(policy.roles) ? policy.roles.join(", ") : policy.roles)}
653
+ </div>
654
+ </div>
655
+ <div className="flex gap-2 shrink-0 items-center">
656
+ {policy.status === "live" && activeCollection && (
657
+ <Button
658
+ size="small"
659
+ variant="outlined"
660
+ color="primary"
661
+ onClick={async () => {
662
+ const rule: Record<string, unknown> = {
663
+ name: policy.policyname,
664
+ operation: policy.cmd?.toLowerCase(),
665
+ mode: policy.permissive?.toLowerCase(),
666
+ using: policy.qual || undefined,
667
+ withCheck: policy.with_check || undefined,
668
+ roles: policy.roles
669
+ };
670
+
671
+ const existingRules = (isPostgresCollection(activeCollection) ? activeCollection.securityRules : undefined) || [];
672
+ const newRules = [...existingRules, rule];
673
+
674
+ try {
675
+ const response = await fetch(`${apiUrl}/api/schema-editor/collection/save`, {
676
+ method: "POST",
677
+ headers: { "Content-Type": "application/json" },
678
+ body: JSON.stringify({
679
+ collectionId: (activeCollection as { id?: string, path?: string, alias?: string }).id || (activeCollection as { id?: string, path?: string, alias?: string }).path || (activeCollection as { id?: string, path?: string, alias?: string }).alias || activeTableData!.tableName,
680
+ collectionData: { securityRules: newRules }
681
+ })
682
+ });
683
+ if (!response.ok) throw new Error("Failed to save policy");
684
+
685
+ snackbarController.open({ type: "success",
686
+ message: "Policy imported successfully" });
687
+ fetchRLSData();
688
+ } catch (e: unknown) {
689
+ snackbarController.open({ type: "error",
690
+ message: e instanceof Error ? e.message : String(e) });
691
+ }
692
+ }}
693
+ >
694
+ Import to codebase
695
+ </Button>
696
+ )}
697
+ <Button size="small" variant="text" color="primary" onClick={() => setEditingPolicy(policy)} disabled={!activeCollection}>
698
+ {t("studio_rls_edit")}
699
+ </Button>
700
+ {policy.status !== "code_only" && (
701
+ <Tooltip title={t("studio_rls_delete")} asChild={true}>
702
+ <IconButton
703
+ size="small"
704
+ onClick={async () => {
705
+ const table = activeTableData!.tableName;
706
+ if (!confirm(`Drop policy "${policy.policyname}" from table "${table}"?`)) return;
707
+ try {
708
+ await databaseAdmin!.executeSql!(`DROP POLICY ${sanitizeSqlIdentifier(policy.policyname)} ON ${sanitizeSqlIdentifier(table)}`);
709
+ snackbarController.open({ type: "success",
710
+ message: `Policy "${policy.policyname}" dropped` });
711
+ fetchRLSData();
712
+ } catch (e: unknown) {
713
+ snackbarController.open({ type: "error",
714
+ message: e instanceof Error ? e.message : String(e) });
715
+ }
716
+ }}
717
+ >
718
+ <Trash2Icon size={iconSize.smallest}/>
719
+ </IconButton>
720
+ </Tooltip>
721
+ )}
722
+ </div>
723
+ </Paper>
724
+ ))}
725
+ </div>
726
+ )}
727
+
728
+ {activeTableData && mergedPolicies.length === 0 && activeTableData.rlsEnabled && (
729
+ <div className="flex flex-col items-center justify-center py-12 text-center">
730
+ <ShieldIcon size={40} className="text-surface-300 dark:text-surface-600 mb-4"/>
731
+ <Typography variant="subtitle2" className="text-text-secondary dark:text-text-secondary-dark mb-2">
732
+ No policies defined
733
+ </Typography>
734
+ <Typography variant="caption" className="text-text-disabled dark:text-text-disabled-dark max-w-sm mb-4">
735
+ RLS is enabled on this table but no policies exist. All access is denied by default (Postgres deny-all). Create a policy to allow specific access.
736
+ </Typography>
737
+ {activeCollection && (
738
+ <Button
739
+ size="small"
740
+ variant="filled"
741
+ color="primary"
742
+ onClick={() => setEditingPolicy("new")}
743
+ >
744
+ {t("studio_rls_create_policy")}
745
+ </Button>
746
+ )}
747
+ </div>
748
+ )}
749
+
750
+ {activeTableData && mergedPolicies.length === 0 && !activeTableData.rlsEnabled && activeCollection && (
751
+ <div className="flex flex-col items-center justify-center py-12 text-center">
752
+ <AlertTriangleIcon size={40} className="text-yellow-400 dark:text-yellow-600 mb-4"/>
753
+ <Typography variant="subtitle2" className="text-text-secondary dark:text-text-secondary-dark mb-2">
754
+ No access control
755
+ </Typography>
756
+ <Typography variant="caption" className="text-text-disabled dark:text-text-disabled-dark max-w-sm">
757
+ This table has neither RLS nor policies. Enable RLS and create policies to restrict row-level access.
758
+ </Typography>
759
+ </div>
760
+ )}
761
+
762
+ </div>
763
+ </div>
764
+ </div>
765
+ )}
766
+ </div>
767
+ }
768
+ />
769
+ </div>
770
+ );
771
+ };