@rebasepro/plugin-data-enhancement 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 (318) hide show
  1. package/LICENSE +114 -0
  2. package/README.md +89 -0
  3. package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
  4. package/dist/common/src/collections/index.d.ts +1 -0
  5. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  6. package/dist/common/src/index.d.ts +3 -0
  7. package/dist/common/src/util/builders.d.ts +57 -0
  8. package/dist/common/src/util/callbacks.d.ts +6 -0
  9. package/dist/common/src/util/collections.d.ts +11 -0
  10. package/dist/common/src/util/common.d.ts +2 -0
  11. package/dist/common/src/util/conditions.d.ts +26 -0
  12. package/dist/common/src/util/entities.d.ts +58 -0
  13. package/dist/common/src/util/enums.d.ts +3 -0
  14. package/dist/common/src/util/index.d.ts +16 -0
  15. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  16. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  17. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  18. package/dist/common/src/util/paths.d.ts +14 -0
  19. package/dist/common/src/util/permissions.d.ts +5 -0
  20. package/dist/common/src/util/references.d.ts +2 -0
  21. package/dist/common/src/util/relations.d.ts +22 -0
  22. package/dist/common/src/util/resolutions.d.ts +72 -0
  23. package/dist/common/src/util/storage.d.ts +24 -0
  24. package/dist/core/src/components/AIIcon.d.ts +16 -0
  25. package/dist/core/src/components/ConfirmationDialog.d.ts +9 -0
  26. package/dist/core/src/components/Debug/UIReferenceView.d.ts +1 -0
  27. package/dist/core/src/components/Debug/UIStyleGuide.d.ts +1 -0
  28. package/dist/core/src/components/ErrorTooltip.d.ts +2 -0
  29. package/dist/core/src/components/ErrorView.d.ts +21 -0
  30. package/dist/core/src/components/LanguageToggle.d.ts +1 -0
  31. package/dist/core/src/components/LoginView/LoginView.d.ts +68 -0
  32. package/dist/core/src/components/LoginView/index.d.ts +2 -0
  33. package/dist/core/src/components/NotFoundPage.d.ts +1 -0
  34. package/dist/core/src/components/RebaseAuth.d.ts +10 -0
  35. package/dist/core/src/components/RebaseLogo.d.ts +7 -0
  36. package/dist/core/src/components/UnsavedChangesDialog.d.ts +9 -0
  37. package/dist/core/src/components/UserDisplay.d.ts +7 -0
  38. package/dist/core/src/components/UserSelectPopover.d.ts +62 -0
  39. package/dist/core/src/components/UserSettingsView.d.ts +1 -0
  40. package/dist/core/src/components/common/index.d.ts +6 -0
  41. package/dist/core/src/components/common/table_height.d.ts +5 -0
  42. package/dist/core/src/components/common/types.d.ts +63 -0
  43. package/dist/core/src/components/common/useColumnsIds.d.ts +9 -0
  44. package/dist/core/src/components/common/useDataTableController.d.ts +45 -0
  45. package/dist/core/src/components/common/useDebouncedData.d.ts +9 -0
  46. package/dist/core/src/components/common/useScrollRestoration.d.ts +14 -0
  47. package/dist/core/src/components/index.d.ts +16 -0
  48. package/dist/core/src/contexts/AdminModeController.d.ts +4 -0
  49. package/dist/core/src/contexts/AnalyticsContext.d.ts +3 -0
  50. package/dist/core/src/contexts/AuthControllerContext.d.ts +3 -0
  51. package/dist/core/src/contexts/CustomizationControllerContext.d.ts +3 -0
  52. package/dist/core/src/contexts/DataDriverContext.d.ts +3 -0
  53. package/dist/core/src/contexts/DatabaseAdminContext.d.ts +3 -0
  54. package/dist/core/src/contexts/DialogsProvider.d.ts +4 -0
  55. package/dist/core/src/contexts/EffectiveRoleController.d.ts +4 -0
  56. package/dist/core/src/contexts/InternalUserManagementContext.d.ts +3 -0
  57. package/dist/core/src/contexts/ModeController.d.ts +4 -0
  58. package/dist/core/src/contexts/RebaseClientInstanceContext.d.ts +6 -0
  59. package/dist/core/src/contexts/RebaseDataContext.d.ts +3 -0
  60. package/dist/core/src/contexts/SnackbarProvider.d.ts +2 -0
  61. package/dist/core/src/contexts/StorageSourceContext.d.ts +3 -0
  62. package/dist/core/src/contexts/UserConfigurationPersistenceContext.d.ts +3 -0
  63. package/dist/core/src/contexts/index.d.ts +13 -0
  64. package/dist/core/src/core/PluginLifecycleManager.d.ts +17 -0
  65. package/dist/core/src/core/PluginProviderStack.d.ts +21 -0
  66. package/dist/core/src/core/Rebase.d.ts +14 -0
  67. package/dist/core/src/core/RebaseProps.d.ts +136 -0
  68. package/dist/core/src/core/RebaseRouter.d.ts +4 -0
  69. package/dist/core/src/core/RebaseRoutes.d.ts +17 -0
  70. package/dist/core/src/core/index.d.ts +4 -0
  71. package/dist/core/src/hooks/ApiConfigContext.d.ts +24 -0
  72. package/dist/core/src/hooks/data/delete.d.ts +31 -0
  73. package/dist/core/src/hooks/data/save.d.ts +34 -0
  74. package/dist/core/src/hooks/data/useCollectionFetch.d.ts +51 -0
  75. package/dist/core/src/hooks/data/useData.d.ts +13 -0
  76. package/dist/core/src/hooks/data/useDataOrder.d.ts +12 -0
  77. package/dist/core/src/hooks/data/useEntityFetch.d.ts +38 -0
  78. package/dist/core/src/hooks/data/useRelationSelector.d.ts +52 -0
  79. package/dist/core/src/hooks/data/useUserSelector.d.ts +31 -0
  80. package/dist/core/src/hooks/index.d.ts +37 -0
  81. package/dist/core/src/hooks/useAdminModeController.d.ts +19 -0
  82. package/dist/core/src/hooks/useAnalyticsController.d.ts +5 -0
  83. package/dist/core/src/hooks/useAuthController.d.ts +11 -0
  84. package/dist/core/src/hooks/useAuthSubscription.d.ts +2 -0
  85. package/dist/core/src/hooks/useBackendStorageSource.d.ts +30 -0
  86. package/dist/core/src/hooks/useBridgeRegistration.d.ts +18 -0
  87. package/dist/core/src/hooks/useBrowserTitleAndIcon.d.ts +6 -0
  88. package/dist/core/src/hooks/useBuildAdminModeController.d.ts +6 -0
  89. package/dist/core/src/hooks/useBuildEffectiveRoleController.d.ts +8 -0
  90. package/dist/core/src/hooks/useBuildLocalConfigurationPersistence.d.ts +2 -0
  91. package/dist/core/src/hooks/useBuildModeController.d.ts +6 -0
  92. package/dist/core/src/hooks/useClipboard.d.ts +57 -0
  93. package/dist/core/src/hooks/useCollapsedGroups.d.ts +12 -0
  94. package/dist/core/src/hooks/useCustomizationController.d.ts +11 -0
  95. package/dist/core/src/hooks/useDialogsController.d.ts +11 -0
  96. package/dist/core/src/hooks/useEffectiveRoleController.d.ts +7 -0
  97. package/dist/core/src/hooks/useInternalUserManagementController.d.ts +12 -0
  98. package/dist/core/src/hooks/useLargeLayout.d.ts +1 -0
  99. package/dist/core/src/hooks/useModeController.d.ts +19 -0
  100. package/dist/core/src/hooks/usePermissions.d.ts +12 -0
  101. package/dist/core/src/hooks/useRebaseClient.d.ts +5 -0
  102. package/dist/core/src/hooks/useRebaseContext.d.ts +11 -0
  103. package/dist/core/src/hooks/useRebaseRegistry.d.ts +34 -0
  104. package/dist/core/src/hooks/useSlot.d.ts +18 -0
  105. package/dist/core/src/hooks/useSnackbarController.d.ts +20 -0
  106. package/dist/core/src/hooks/useStorageSource.d.ts +7 -0
  107. package/dist/core/src/hooks/useStudioBridge.d.ts +91 -0
  108. package/dist/core/src/hooks/useTranslation.d.ts +17 -0
  109. package/dist/core/src/hooks/useUnsavedChangesDialog.d.ts +12 -0
  110. package/dist/core/src/hooks/useUserConfigurationPersistence.d.ts +8 -0
  111. package/dist/core/src/hooks/useValidateAuthenticator.d.ts +21 -0
  112. package/dist/core/src/i18n/RebaseI18nProvider.d.ts +33 -0
  113. package/dist/core/src/index.d.ts +15 -0
  114. package/dist/core/src/internal/common.d.ts +3 -0
  115. package/dist/core/src/internal/useRestoreScroll.d.ts +6 -0
  116. package/dist/core/src/locales/de.d.ts +2 -0
  117. package/dist/core/src/locales/en.d.ts +10 -0
  118. package/dist/core/src/locales/es.d.ts +10 -0
  119. package/dist/core/src/locales/fr.d.ts +2 -0
  120. package/dist/core/src/locales/hi.d.ts +2 -0
  121. package/dist/core/src/locales/it.d.ts +2 -0
  122. package/dist/core/src/locales/pt.d.ts +7 -0
  123. package/dist/core/src/util/constants.d.ts +1 -0
  124. package/dist/core/src/util/createFormexStub.d.ts +2 -0
  125. package/dist/core/src/util/entity_cache.d.ts +27 -0
  126. package/dist/core/src/util/enums.d.ts +5 -0
  127. package/dist/core/src/util/icon_list.d.ts +5 -0
  128. package/dist/core/src/util/icon_synonyms.d.ts +1 -0
  129. package/dist/core/src/util/icons.d.ts +20 -0
  130. package/dist/core/src/util/index.d.ts +10 -0
  131. package/dist/core/src/util/previews.d.ts +4 -0
  132. package/dist/core/src/util/useStorageUploadController.d.ts +38 -0
  133. package/dist/core/src/util/useTraceUpdate.d.ts +2 -0
  134. package/dist/formex/src/Field.d.ts +52 -0
  135. package/dist/formex/src/Formex.d.ts +7 -0
  136. package/dist/formex/src/index.d.ts +5 -0
  137. package/dist/formex/src/types.d.ts +40 -0
  138. package/dist/formex/src/useCreateFormex.d.ts +14 -0
  139. package/dist/formex/src/utils.d.ts +16 -0
  140. package/dist/index.es.js +751 -0
  141. package/dist/index.es.js.map +1 -0
  142. package/dist/index.umd.js +746 -0
  143. package/dist/index.umd.js.map +1 -0
  144. package/dist/plugin-data-enhancement/src/api.d.ts +34 -0
  145. package/dist/plugin-data-enhancement/src/components/DataEnhancementControllerProvider.d.ts +14 -0
  146. package/dist/plugin-data-enhancement/src/components/FormEnhanceAction.d.ts +10 -0
  147. package/dist/plugin-data-enhancement/src/editor/useEditorAIController.d.ts +4 -0
  148. package/dist/plugin-data-enhancement/src/index.d.ts +4 -0
  149. package/dist/plugin-data-enhancement/src/locales/de.d.ts +21 -0
  150. package/dist/plugin-data-enhancement/src/locales/en.d.ts +21 -0
  151. package/dist/plugin-data-enhancement/src/locales/es.d.ts +21 -0
  152. package/dist/plugin-data-enhancement/src/locales/fr.d.ts +21 -0
  153. package/dist/plugin-data-enhancement/src/locales/hi.d.ts +21 -0
  154. package/dist/plugin-data-enhancement/src/locales/it.d.ts +21 -0
  155. package/dist/plugin-data-enhancement/src/locales/pt.d.ts +21 -0
  156. package/dist/plugin-data-enhancement/src/types/data_enhancement_controller.d.ts +71 -0
  157. package/dist/plugin-data-enhancement/src/types/subscriptions_message_props.d.ts +3 -0
  158. package/dist/plugin-data-enhancement/src/useDataEnhancementPlugin.d.ts +29 -0
  159. package/dist/plugin-data-enhancement/src/utils/diffStrings.d.ts +7 -0
  160. package/dist/plugin-data-enhancement/src/utils/properties.d.ts +3 -0
  161. package/dist/plugin-data-enhancement/src/utils/strings_counter.d.ts +2 -0
  162. package/dist/plugin-data-enhancement/src/utils/suggestions.d.ts +1 -0
  163. package/dist/plugin-data-enhancement/src/utils/values.d.ts +1 -0
  164. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  165. package/dist/types/src/controllers/auth.d.ts +119 -0
  166. package/dist/types/src/controllers/client.d.ts +170 -0
  167. package/dist/types/src/controllers/collection_registry.d.ts +46 -0
  168. package/dist/types/src/controllers/customization_controller.d.ts +60 -0
  169. package/dist/types/src/controllers/data.d.ts +168 -0
  170. package/dist/types/src/controllers/data_driver.d.ts +195 -0
  171. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  172. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  173. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  174. package/dist/types/src/controllers/email.d.ts +34 -0
  175. package/dist/types/src/controllers/index.d.ts +18 -0
  176. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  177. package/dist/types/src/controllers/navigation.d.ts +213 -0
  178. package/dist/types/src/controllers/registry.d.ts +54 -0
  179. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  180. package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
  181. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  182. package/dist/types/src/controllers/storage.d.ts +171 -0
  183. package/dist/types/src/index.d.ts +4 -0
  184. package/dist/types/src/rebase_context.d.ts +105 -0
  185. package/dist/types/src/types/backend.d.ts +536 -0
  186. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  187. package/dist/types/src/types/builders.d.ts +15 -0
  188. package/dist/types/src/types/chips.d.ts +5 -0
  189. package/dist/types/src/types/collections.d.ts +857 -0
  190. package/dist/types/src/types/cron.d.ts +102 -0
  191. package/dist/types/src/types/data_source.d.ts +64 -0
  192. package/dist/types/src/types/entities.d.ts +145 -0
  193. package/dist/types/src/types/entity_actions.d.ts +98 -0
  194. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  195. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  196. package/dist/types/src/types/entity_overrides.d.ts +10 -0
  197. package/dist/types/src/types/entity_views.d.ts +59 -0
  198. package/dist/types/src/types/export_import.d.ts +21 -0
  199. package/dist/types/src/types/formex.d.ts +40 -0
  200. package/dist/types/src/types/index.d.ts +25 -0
  201. package/dist/types/src/types/locales.d.ts +4 -0
  202. package/dist/types/src/types/modify_collections.d.ts +5 -0
  203. package/dist/types/src/types/plugins.d.ts +282 -0
  204. package/dist/types/src/types/properties.d.ts +1148 -0
  205. package/dist/types/src/types/property_config.d.ts +70 -0
  206. package/dist/types/src/types/relations.d.ts +336 -0
  207. package/dist/types/src/types/slots.d.ts +262 -0
  208. package/dist/types/src/types/translations.d.ts +874 -0
  209. package/dist/types/src/types/user_management_delegate.d.ts +121 -0
  210. package/dist/types/src/types/websockets.d.ts +78 -0
  211. package/dist/types/src/users/index.d.ts +2 -0
  212. package/dist/types/src/users/roles.d.ts +22 -0
  213. package/dist/types/src/users/user.d.ts +46 -0
  214. package/dist/ui/src/components/Alert.d.ts +12 -0
  215. package/dist/ui/src/components/Autocomplete.d.ts +21 -0
  216. package/dist/ui/src/components/Avatar.d.ts +11 -0
  217. package/dist/ui/src/components/Badge.d.ts +8 -0
  218. package/dist/ui/src/components/BooleanSwitch.d.ts +14 -0
  219. package/dist/ui/src/components/BooleanSwitchWithLabel.d.ts +17 -0
  220. package/dist/ui/src/components/Button.d.ts +14 -0
  221. package/dist/ui/src/components/Card.d.ts +9 -0
  222. package/dist/ui/src/components/CenteredView.d.ts +9 -0
  223. package/dist/ui/src/components/Checkbox.d.ts +13 -0
  224. package/dist/ui/src/components/Chip.d.ts +26 -0
  225. package/dist/ui/src/components/CircularProgress.d.ts +5 -0
  226. package/dist/ui/src/components/CircularProgressCenter.d.ts +11 -0
  227. package/dist/ui/src/components/Collapse.d.ts +9 -0
  228. package/dist/ui/src/components/ColorPicker.d.ts +30 -0
  229. package/dist/ui/src/components/Container.d.ts +8 -0
  230. package/dist/ui/src/components/DateTimeField.d.ts +24 -0
  231. package/dist/ui/src/components/DebouncedTextField.d.ts +2 -0
  232. package/dist/ui/src/components/Dialog.d.ts +39 -0
  233. package/dist/ui/src/components/DialogActions.d.ts +7 -0
  234. package/dist/ui/src/components/DialogContent.d.ts +7 -0
  235. package/dist/ui/src/components/DialogTitle.d.ts +10 -0
  236. package/dist/ui/src/components/ErrorBoundary.d.ts +11 -0
  237. package/dist/ui/src/components/ExpandablePanel.d.ts +12 -0
  238. package/dist/ui/src/components/FileUpload.d.ts +23 -0
  239. package/dist/ui/src/components/IconButton.d.ts +12 -0
  240. package/dist/ui/src/components/InfoLabel.d.ts +5 -0
  241. package/dist/ui/src/components/InputLabel.d.ts +11 -0
  242. package/dist/ui/src/components/Label.d.ts +7 -0
  243. package/dist/ui/src/components/LoadingButton.d.ts +7 -0
  244. package/dist/ui/src/components/Markdown.d.ts +10 -0
  245. package/dist/ui/src/components/Menu.d.ts +23 -0
  246. package/dist/ui/src/components/Menubar.d.ts +80 -0
  247. package/dist/ui/src/components/MultiSelect.d.ts +48 -0
  248. package/dist/ui/src/components/Paper.d.ts +6 -0
  249. package/dist/ui/src/components/Popover.d.ts +24 -0
  250. package/dist/ui/src/components/RadioGroup.d.ts +28 -0
  251. package/dist/ui/src/components/ResizablePanels.d.ts +18 -0
  252. package/dist/ui/src/components/SearchBar.d.ts +22 -0
  253. package/dist/ui/src/components/Select.d.ts +43 -0
  254. package/dist/ui/src/components/Separator.d.ts +5 -0
  255. package/dist/ui/src/components/Sheet.d.ts +22 -0
  256. package/dist/ui/src/components/Skeleton.d.ts +6 -0
  257. package/dist/ui/src/components/Slider.d.ts +21 -0
  258. package/dist/ui/src/components/Table.d.ts +34 -0
  259. package/dist/ui/src/components/Tabs.d.ts +19 -0
  260. package/dist/ui/src/components/TextField.d.ts +58 -0
  261. package/dist/ui/src/components/TextareaAutosize.d.ts +43 -0
  262. package/dist/ui/src/components/ToggleButtonGroup.d.ts +30 -0
  263. package/dist/ui/src/components/Tooltip.d.ts +19 -0
  264. package/dist/ui/src/components/Typography.d.ts +36 -0
  265. package/dist/ui/src/components/VirtualTable/VirtualTable.d.ts +11 -0
  266. package/dist/ui/src/components/VirtualTable/VirtualTableCell.d.ts +21 -0
  267. package/dist/ui/src/components/VirtualTable/VirtualTableHeader.d.ts +29 -0
  268. package/dist/ui/src/components/VirtualTable/VirtualTableHeaderRow.d.ts +2 -0
  269. package/dist/ui/src/components/VirtualTable/VirtualTableProps.d.ts +243 -0
  270. package/dist/ui/src/components/VirtualTable/VirtualTableRow.d.ts +3 -0
  271. package/dist/ui/src/components/VirtualTable/index.d.ts +3 -0
  272. package/dist/ui/src/components/VirtualTable/types.d.ts +38 -0
  273. package/dist/ui/src/components/common/SelectInputLabel.d.ts +5 -0
  274. package/dist/ui/src/components/index.d.ts +53 -0
  275. package/dist/ui/src/hooks/PortalContainerContext.d.ts +31 -0
  276. package/dist/ui/src/hooks/index.d.ts +6 -0
  277. package/dist/ui/src/hooks/useDebounceCallback.d.ts +1 -0
  278. package/dist/ui/src/hooks/useDebounceValue.d.ts +1 -0
  279. package/dist/ui/src/hooks/useDebouncedCallback.d.ts +1 -0
  280. package/dist/ui/src/hooks/useInjectStyles.d.ts +7 -0
  281. package/dist/ui/src/hooks/useOutsideAlerter.d.ts +5 -0
  282. package/dist/ui/src/icons/GitHubIcon.d.ts +2 -0
  283. package/dist/ui/src/icons/HandleIcon.d.ts +1 -0
  284. package/dist/ui/src/icons/Icon.d.ts +20 -0
  285. package/dist/ui/src/icons/cool_icon_keys.d.ts +1 -0
  286. package/dist/ui/src/icons/icon_keys.d.ts +1 -0
  287. package/dist/ui/src/icons/index.d.ts +6 -0
  288. package/dist/ui/src/index.d.ts +5 -0
  289. package/dist/ui/src/styles.d.ts +12 -0
  290. package/dist/ui/src/util/chip_colors.d.ts +4 -0
  291. package/dist/ui/src/util/cls.d.ts +2 -0
  292. package/dist/ui/src/util/debounce.d.ts +10 -0
  293. package/dist/ui/src/util/hash.d.ts +1 -0
  294. package/dist/ui/src/util/index.d.ts +4 -0
  295. package/dist/ui/src/util/key_to_icon_component.d.ts +1 -0
  296. package/package.json +86 -0
  297. package/src/api.ts +198 -0
  298. package/src/components/DataEnhancementControllerProvider.tsx +339 -0
  299. package/src/components/FormEnhanceAction.tsx +273 -0
  300. package/src/editor/useEditorAIController.tsx +37 -0
  301. package/src/index.ts +10 -0
  302. package/src/locales/de.ts +21 -0
  303. package/src/locales/en.ts +21 -0
  304. package/src/locales/es.ts +21 -0
  305. package/src/locales/fr.ts +21 -0
  306. package/src/locales/hi.ts +21 -0
  307. package/src/locales/it.ts +21 -0
  308. package/src/locales/pt.ts +21 -0
  309. package/src/tests/diffStrings.test.ts +128 -0
  310. package/src/types/data_enhancement_controller.tsx +75 -0
  311. package/src/types/subscriptions_message_props.tsx +1 -0
  312. package/src/useDataEnhancementPlugin.tsx +66 -0
  313. package/src/utils/diffStrings.ts +70 -0
  314. package/src/utils/properties.ts +168 -0
  315. package/src/utils/strings_counter.ts +22 -0
  316. package/src/utils/suggestions.ts +6 -0
  317. package/src/utils/values.ts +12 -0
  318. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,75 @@
1
+ import { EntityValues } from "@rebasepro/types";
2
+ import { EditorAIController } from "@rebasepro/admin";
3
+
4
+ export type EnhanceParams<M extends Record<string, unknown>> = {
5
+ entityId?: string | number;
6
+ propertyKey?: string;
7
+ propertyInstructions?: string;
8
+ values: EntityValues<M>;
9
+ instructions?: string;
10
+ replaceValues: boolean;
11
+ };
12
+
13
+ export type DataEnhancementController = {
14
+ /**
15
+ * Whether the data enhancement is enabled for the current path
16
+ */
17
+ enabled: boolean;
18
+ suggestions: Record<string, string | number>;
19
+ enhance: <M extends Record<string, unknown>>(props: EnhanceParams<M>) => Promise<EnhancedDataResult | null>;
20
+ clearSuggestion: (key: string, suggestion: string | number) => void;
21
+ allowReferenceDataSelection: boolean;
22
+ clearAllSuggestions: () => void;
23
+ getSamplePrompts: (entityName: string, input?: string) => Promise<SamplePromptsResult>;
24
+ loadingSuggestions: string[],
25
+ editorAIController?: EditorAIController;
26
+ }
27
+
28
+ export type EnhancedDataResult = {
29
+ entityId?: string | number;
30
+ suggestions: {
31
+ [key: string]: string[];
32
+ };
33
+ errors: string[];
34
+ usage: { promptTokens?: number, completionTokens?: number, totalTokens?: number }
35
+ }
36
+
37
+ export type SamplePrompt = {
38
+ prompt: string;
39
+ type: "recent" | "sample";
40
+ }
41
+
42
+ export type SamplePromptsResult = {
43
+ prompts: SamplePrompt[];
44
+ host?: string;
45
+ };
46
+
47
+ export type DataEnhancementRequest = {
48
+ entityName: string;
49
+ entityDescription?: string;
50
+ inputEntity: InputEntity;
51
+ properties: Record<string, InputProperty>;
52
+ propertyKey?: string;
53
+ propertyInstructions?: string,
54
+ instructions?: string;
55
+ };
56
+
57
+ export type InputEntity = {
58
+ entityId?: string | number;
59
+ values: Record<string, any>;
60
+ };
61
+
62
+ export type InputProperty = {
63
+ name?: string;
64
+ description?: string;
65
+ type: string;
66
+ fieldConfigId: string;
67
+ enum?: string[];
68
+ disabled?: boolean;
69
+ of?: InputProperty;
70
+ oneOf?: {
71
+ properties: Record<string, InputProperty>;
72
+ typeField?: string;
73
+ valueField?: string;
74
+ };
75
+ }
@@ -0,0 +1 @@
1
+ export type SubscriptionMessageProps = { projectId: string };
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+
3
+ import { EntityCollection, RebasePlugin, User } from "@rebasepro/types";
4
+ import { DataEnhancementControllerProvider } from "./components/DataEnhancementControllerProvider";
5
+ import { FormEnhanceAction } from "./components/FormEnhanceAction";
6
+
7
+ const DEFAULT_API_KEY = "fcms-U9jdDii0xXWSDC34asfrf54lbkFJBfKfRWcEDEwdc4V5wDWEDF";
8
+
9
+ export interface DataEnhancementPluginProps {
10
+
11
+ apiKey?: string;
12
+
13
+ /**
14
+ * Use this function to determine if the data enhancement plugin should be enabled for a given path.
15
+ * If this function is not provided, the plugin will be enabled for all paths.
16
+ * If the function returns false, the plugin will be disabled for the given path.
17
+ * You can also return a configuration object to override the default configuration.
18
+ *
19
+ * @param path
20
+ * @param collection
21
+ */
22
+ getConfigForPath?: (props: {
23
+ path: string,
24
+ collection: EntityCollection,
25
+ user: User | null
26
+ }) => boolean;
27
+
28
+ /**
29
+ * Host to use for the data enhancement API.
30
+ * This prop is only use in development mode.
31
+ */
32
+ host?: string;
33
+ }
34
+
35
+ /**
36
+ * Use this hook to initialise the data enhancement plugin.
37
+ * This is likely the only hook you will need to use.
38
+ * @param props
39
+ */
40
+ export function useDataEnhancementPlugin(props?: DataEnhancementPluginProps): RebasePlugin {
41
+
42
+ const apiKey = props?.apiKey ?? DEFAULT_API_KEY;
43
+ const getConfigForPath = props?.getConfigForPath;
44
+
45
+ return React.useMemo(() => ({
46
+ key: "data_enhancement",
47
+ slots: [
48
+ {
49
+ slot: "form.actions",
50
+ Component: FormEnhanceAction,
51
+ order: 40
52
+ }
53
+ ],
54
+ providers: [
55
+ {
56
+ scope: "form" as const,
57
+ Component: DataEnhancementControllerProvider as React.ComponentType<any>,
58
+ props: {
59
+ apiKey,
60
+ getConfigForPath,
61
+ host: props?.host
62
+ }
63
+ }
64
+ ]
65
+ }), [apiKey, getConfigForPath, props?.host]);
66
+ }
@@ -0,0 +1,70 @@
1
+ type ChangeType = "equal" | "delete" | "insert";
2
+
3
+ export interface Change {
4
+ type: ChangeType;
5
+ value: string;
6
+ }
7
+
8
+ export function diffStrings(oldStr: string, newStr: string): Change[] {
9
+ // Find the longest common substring
10
+ function longestCommonSubstring(s1: string, s2: string): string {
11
+ const longest = { start: 0,
12
+ length: 0 };
13
+ const matrix = new Array(s1.length + 1).fill(null).map(() => new Array(s2.length + 1).fill(0));
14
+
15
+ for (let i = 1; i <= s1.length; i++) {
16
+ for (let j = 1; j <= s2.length; j++) {
17
+ if (s1[i - 1] === s2[j - 1]) {
18
+ matrix[i][j] = matrix[i - 1][j - 1] + 1;
19
+ if (matrix[i][j] > longest.length) {
20
+ longest.start = i - matrix[i][j];
21
+ longest.length = matrix[i][j];
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ return s1.slice(longest.start, longest.start + longest.length);
28
+ }
29
+
30
+ // Recursively find changes and create Change objects
31
+ function findChanges(s1: string, s2: string): Change[] {
32
+ if (s1 === s2) return s1.length > 0 ? [{
33
+ type: "equal",
34
+ value: s1
35
+ }] : [];
36
+
37
+ const common = longestCommonSubstring(s1, s2);
38
+
39
+ if (common.length === 0) {
40
+ const changes: Change[] = [];
41
+ if (s1.length > 0) {
42
+ changes.push({ type: "delete",
43
+ value: s1 });
44
+ }
45
+ if (s2.length > 0) {
46
+ changes.push({ type: "insert",
47
+ value: s2 });
48
+ }
49
+ return changes;
50
+ }
51
+
52
+ const s1Before = s1.slice(0, s1.indexOf(common));
53
+ const s1After = s1.slice(s1.indexOf(common) + common.length);
54
+ const s2Before = s2.slice(0, s2.indexOf(common));
55
+ const s2After = s2.slice(s2.indexOf(common) + common.length);
56
+
57
+ const changesBefore = findChanges(s1Before, s2Before);
58
+ const changesAfter = findChanges(s1After, s2After);
59
+
60
+ return [
61
+ ...changesBefore,
62
+ { type: "equal",
63
+ value: common },
64
+ ...changesAfter
65
+ ];
66
+ }
67
+
68
+ return findChanges(oldStr, newStr);
69
+ }
70
+
@@ -0,0 +1,168 @@
1
+ import { getFieldId } from "@rebasepro/admin";
2
+ import { EnumValues, Properties, Property } from "@rebasepro/types";
3
+ import { isPropertyBuilder } from "@rebasepro/common";
4
+ import { InputProperty } from "../types/data_enhancement_controller";
5
+ import { getValueInPath } from "@rebasepro/utils";
6
+
7
+ export function getSimplifiedProperties<M extends Record<string, any>>(properties: Properties, values: M, path = ""): Record<string, InputProperty> {
8
+ if (!properties) return {};
9
+ return Object.entries(properties)
10
+ .map(([key, property]) => {
11
+ if (isPropertyBuilder(property)) return {};
12
+ const fullKey = path ? `${path}.${key}` : key;
13
+ const valueInPath = getValueInPath(values, fullKey);
14
+ return getSimplifiedProperty(property, fullKey, valueInPath)
15
+ })
16
+ .reduce((a, b) => ({ ...a,
17
+ ...b }), {});
18
+ }
19
+
20
+ function getSimpleProperty(property: Property): InputProperty {
21
+ const fieldId = getFieldId(property);
22
+ if (!fieldId) {
23
+ console.error("No fieldId found for property", property);
24
+ throw new Error("Field id not found");
25
+ }
26
+ return {
27
+ name: property.name,
28
+ description: property.description,
29
+ type: property.type,
30
+ fieldConfigId: fieldId,
31
+ enum: "enum" in property && property.enum
32
+ ? getSimpleEnumValues(property.enum)
33
+ : undefined,
34
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly)
35
+ };
36
+ }
37
+
38
+ function getSimplifiedProperty(property: Property, path: string, value?: any): Record<string, InputProperty> {
39
+ if (isPropertyBuilder(property)) return {};
40
+ if (property.type === "array") {
41
+
42
+ if (property.of && !Array.isArray(property.of) && !isPropertyBuilder(property.of)) {
43
+ const arrayParentProperty: InputProperty = {
44
+ name: property.name,
45
+ description: property.description,
46
+ type: property.type,
47
+ fieldConfigId: "repeat",
48
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly),
49
+ of: getSimpleProperty(property.of as Property)
50
+ };
51
+
52
+ const result = { [path]: arrayParentProperty };
53
+ // if (Array.isArray(value)) {
54
+ // result = {
55
+ // ...result,
56
+ // ...value
57
+ // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i}`, v))
58
+ // .reduce((a, b) => ({ ...a, ...b }), {})
59
+ // };
60
+ // }
61
+ //
62
+ // const existingValuesCount = Array.isArray(value) ? value.length : 0;
63
+ //
64
+ // const newValuesCount = property.of && !isPropertyBuilder<any, any>(property.of) && (property.of as Property).type === "map" ? 1 : 3;
65
+ // result = {
66
+ // ...result,
67
+ // // ...Array.from(Array(newValuesCount))
68
+ // // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i + existingValuesCount}`, v))
69
+ // // .reduce((a, b) => ({ ...a, ...b }), {})
70
+ // }
71
+
72
+ return result;
73
+ } else if (property.oneOf) {
74
+
75
+ const arrayParentProperty: InputProperty = {
76
+ name: property.name,
77
+ description: property.description,
78
+ type: property.type,
79
+ fieldConfigId: "block",
80
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly),
81
+ oneOf: {
82
+ typeField: property.oneOf.typeField,
83
+ valueField: property.oneOf.valueField,
84
+ properties: Object.entries(property.oneOf.properties)
85
+ .map(([key, prop]) => ({ [key]: getSimpleProperty(prop) }))
86
+ .reduce((a, b) => ({ ...a,
87
+ ...b }), {})
88
+ }
89
+ };
90
+
91
+ if (!Array.isArray(value)) {
92
+ return { [path]: arrayParentProperty };
93
+ }
94
+
95
+ return value.map((v, i) => {
96
+ if (v == null) return {};
97
+ const typeKey = property.oneOf!.typeField ?? "type";
98
+ const oneOfType = v[typeKey];
99
+ const valueKey = property.oneOf!.valueField ?? "value";
100
+ const oneOfValue = v[valueKey];
101
+ const childProperty = property.oneOf!.properties[oneOfType];
102
+ if (childProperty === undefined) {
103
+ console.error(`No property found for type ${oneOfType}`, property.oneOf!.properties);
104
+ return {};
105
+ }
106
+ const simplifiedProperty = getSimplifiedProperty(childProperty, `${path}.${i}.${valueKey}`, oneOfValue);
107
+ return {
108
+ [`${path}.${i}.${typeKey}`]: oneOfType,
109
+ ...simplifiedProperty
110
+ };
111
+ }).reduce((a, b) => ({ ...a,
112
+ ...b }), { [path]: arrayParentProperty });
113
+ }
114
+ } else if (property.type === "map") {
115
+ if (property.properties) {
116
+ const mapProperties: Record<string, InputProperty> = Object.entries(property.properties)
117
+ .map(([key, childProperty]) => {
118
+ const childValue = value?.[key];
119
+ return getSimplifiedProperty(childProperty, key, childValue);
120
+ })
121
+ .map(o => attachPathToKeys(o, path))
122
+ .reduce((a, b) => ({ ...a,
123
+ ...b }), {});
124
+
125
+ if (Object.keys(mapProperties).length === 0) return {};
126
+ const mapParentProperty: InputProperty = {
127
+ name: property.name,
128
+ description: property.description,
129
+ type: property.type,
130
+ fieldConfigId: "group",
131
+ disabled: Boolean(property.ui?.disabled || property.ui?.readOnly)
132
+ };
133
+ return {
134
+ [path]: mapParentProperty,
135
+ ...mapProperties
136
+ } as Record<string, InputProperty>;
137
+ }
138
+ } else {
139
+ const fieldId = getFieldId(property);
140
+ if (!fieldId) {
141
+ console.warn(`No fieldId found for property ${path} with type ${property.type}`);
142
+ return {};
143
+ }
144
+ return {
145
+ [path]: getSimpleProperty(property)
146
+ };
147
+ }
148
+ return {};
149
+ }
150
+
151
+ // attach a path to every key in an object
152
+ function attachPathToKeys(obj: Record<string, any>, path = ""): Record<string, any> {
153
+ return Object.entries(obj)
154
+ .map(([key, value]) => {
155
+ const fullKey = path ? `${path}.${key}` : key;
156
+ return { [fullKey]: value };
157
+ })
158
+ .reduce((a, b) => ({ ...a,
159
+ ...b }), {});
160
+ }
161
+
162
+ function getSimpleEnumValues(enumValues: EnumValues): string[] {
163
+ if (Array.isArray(enumValues))
164
+ return enumValues.map(v => String(v.id));
165
+ if (typeof enumValues === "object")
166
+ return Object.keys(enumValues);
167
+ throw Error("getSimpleEnumValues: Invalid enumValues");
168
+ }
@@ -0,0 +1,22 @@
1
+ import { EntityValues, Properties, Property } from "@rebasepro/types";
2
+
3
+ export function countStringCharacters(values: EntityValues<any>, properties: Properties) {
4
+ let count = 0;
5
+
6
+ for (const key in values) {
7
+ const value = values[key];
8
+ const property: Property = properties[key];
9
+
10
+ if (property && !property.ui?.disabled) {
11
+ if (property.type === "string" || property.type === "number") {
12
+ count += String(value).length;
13
+ } else if (property.type === "array" && Array.isArray(value) && property.of && !Array.isArray(property.of) && property.of.type === "string") {
14
+ count += (value as string[]).reduce((acc, curr) => acc + (curr?.length ?? 0), 0);
15
+ } else if (property.type === "map" && property.properties && typeof value === "object") {
16
+ count += countStringCharacters(value, property.properties);
17
+ }
18
+ }
19
+ }
20
+
21
+ return count;
22
+ }
@@ -0,0 +1,6 @@
1
+ export function getAppendableSuggestion(suggestion: string | number | undefined, value: any): string | undefined {
2
+ const suggestionIncludesValue = typeof suggestion === "string" && typeof value === "string" && suggestion.toLowerCase().trim().startsWith(value.toLowerCase().trim());
3
+ return (typeof value === "string" && suggestionIncludesValue)
4
+ ? suggestion.substring(suggestion.toLowerCase().trim().indexOf(value.toLowerCase().trim()) + value.trim().length)
5
+ : undefined;
6
+ }
@@ -0,0 +1,12 @@
1
+ export function flatMapEntityValues<M extends object>(values: M, path = ""): object {
2
+ if (!values) return {};
3
+ return Object.entries(values).flatMap(([key, value]) => {
4
+ const currentPath = path ? `${path}.${key}` : key;
5
+ if (typeof value === "object") {
6
+ return flatMapEntityValues(value, currentPath);
7
+ } else {
8
+ return { [currentPath]: value };
9
+ }
10
+ }).reduce((acc, curr) => ({ ...acc,
11
+ ...curr }), {})
12
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />