@rebasepro/cms 0.28.1 → 0.29.0-canary.g0e3a0e7
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.
- package/README.md +3 -3
- package/dist/collection_editor/_cms_internals.d.ts +0 -1
- package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
- package/dist/components/AdditionalFieldValue.d.ts +9 -3
- package/dist/components/AdditionalFieldValue.js +7 -4
- package/dist/components/AdditionalFieldValue.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +117 -18
- package/dist/components/CollectionPanel.js +115 -37
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
- package/dist/components/CollectionTableBinding/column_utils.js +6 -3
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
- package/dist/components/CollectionTableBinding/internal/common.js +88 -4
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
- package/dist/components/CollectionViewBinding/RowActions.js +60 -0
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
- package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
- package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
- package/dist/components/CollectionViewBinding/fields.js +47 -0
- package/dist/components/CollectionViewBinding/fields.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
- package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +3 -3
- package/dist/components/CollectionsProvider.js +4 -4
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/CollectionsScopeContext.d.ts +1 -1
- package/dist/components/CollectionsScopeContext.js +1 -1
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +2 -2
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +32 -68
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js +5 -4
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -2
- package/dist/components/EditViewBinding.js +25 -15
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.js +8 -5
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +8 -1
- package/dist/components/EntityViewBinding.js +43 -14
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +40 -0
- package/dist/components/EntityViewBody.js +90 -0
- package/dist/components/EntityViewBody.js.map +1 -0
- package/dist/components/FieldValue.d.ts +50 -0
- package/dist/components/FieldValue.js +81 -0
- package/dist/components/FieldValue.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PanelNotFound.d.ts +5 -0
- package/dist/components/PanelNotFound.js +21 -0
- package/dist/components/PanelNotFound.js.map +1 -0
- package/dist/components/RebaseCMS.d.ts +1 -1
- package/dist/components/RebaseCMS.js +11 -3
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +9 -3
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RebaseShell.js +10 -5
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/RecordDetail.d.ts +61 -0
- package/dist/components/RecordDetail.js +123 -0
- package/dist/components/RecordDetail.js.map +1 -0
- package/dist/components/RecordForm.d.ts +126 -0
- package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
- package/dist/components/RecordForm.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
- package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +5 -3
- package/dist/components/ReferenceWidget.js +10 -7
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.js +4 -4
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +2 -3
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
- package/dist/components/SelectableTable/SelectionStore.js +1 -1
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SidePanelBinding.js +13 -12
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/collection_prop.d.ts +18 -0
- package/dist/components/collection_prop.js +23 -0
- package/dist/components/collection_prop.js.map +1 -0
- package/dist/components/common/default_entity_actions.js +54 -54
- package/dist/components/common/default_entity_actions.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +4 -1
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
- package/dist/data_export/export/ExportCollectionAction.js +4 -3
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +6 -3
- package/dist/data_export/export/additional_fields.js +8 -4
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.js +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +252 -150
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js +3 -2
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +22 -11
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormField.d.ts +36 -0
- package/dist/form/FormField.js +41 -0
- package/dist/form/FormField.js.map +1 -0
- package/dist/form/FormFieldsContext.d.ts +69 -0
- package/dist/form/FormFieldsContext.js +143 -0
- package/dist/form/FormFieldsContext.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +4 -4
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/collection_showing.d.ts +8 -0
- package/dist/form/collection_showing.js +29 -0
- package/dist/form/collection_showing.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +2 -1
- package/dist/form/components/ErrorFocus.js.map +1 -1
- package/dist/form/components/FieldBlock.js +3 -1
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +5 -1
- package/dist/form/components/FormRail.js +5 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/FormSections.d.ts +5 -1
- package/dist/form/components/FormSections.js +11 -4
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/form_dom_ids.d.ts +25 -0
- package/dist/form/form_dom_ids.js +42 -0
- package/dist/form/form_dom_ids.js.map +1 -0
- package/dist/form/index.d.ts +3 -1
- package/dist/form/resolve_cell_property.d.ts +5 -0
- package/dist/form/resolve_cell_property.js +22 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.js +9 -9
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useEntityDisplay.js +6 -4
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useRecordActions.js +2 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useSelectionDialog.d.ts +20 -7
- package/dist/hooks/useSelectionDialog.js +29 -8
- package/dist/hooks/useSelectionDialog.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -9
- package/dist/mcp-view.d.ts +9 -0
- package/dist/mcp-view.js +2 -0
- package/dist/mcp_view/app_modules.d.ts +29 -0
- package/dist/mcp_view/app_modules.js +163 -0
- package/dist/mcp_view/app_modules.js.map +1 -0
- package/dist/mcp_view/bridge.d.ts +90 -0
- package/dist/mcp_view/bridge.js +205 -0
- package/dist/mcp_view/bridge.js.map +1 -0
- package/dist/mcp_view/code_app.d.ts +65 -0
- package/dist/mcp_view/code_app.js +139 -0
- package/dist/mcp_view/code_app.js.map +1 -0
- package/dist/mcp_view/index.d.ts +48 -0
- package/dist/mcp_view/index.js +235 -0
- package/dist/mcp_view/index.js.map +1 -0
- package/dist/mcp_view/payload.d.ts +78 -0
- package/dist/mcp_view/payload.js +155 -0
- package/dist/mcp_view/payload.js.map +1 -0
- package/dist/mcp_view/screen.d.ts +28 -0
- package/dist/mcp_view/screen.js +223 -0
- package/dist/mcp_view/screen.js.map +1 -0
- package/dist/mcp_view/storage_source.d.ts +14 -0
- package/dist/mcp_view/storage_source.js +29 -0
- package/dist/mcp_view/storage_source.js.map +1 -0
- package/dist/mcp_view/store.d.ts +9 -0
- package/dist/mcp_view/store.js +27 -0
- package/dist/mcp_view/store.js.map +1 -0
- package/dist/mcp_view/tool_driver.d.ts +135 -0
- package/dist/mcp_view/tool_driver.js +527 -0
- package/dist/mcp_view/tool_driver.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +34 -1
- package/dist/preview/components/DatePreview.js +72 -37
- package/dist/preview/components/DatePreview.js.map +1 -1
- package/dist/routes/RebaseRoute.js +1 -1
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +5 -3
- package/dist/selection/SelectionMenu.js +16 -9
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/resolve_selection.d.ts +61 -7
- package/dist/selection/resolve_selection.js +93 -11
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +60 -10
- package/dist/types/fields.d.ts +2 -65
- package/dist/util/dataControllerAdapter.d.ts +8 -0
- package/dist/util/dataControllerAdapter.js +11 -0
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/navigation_utils.d.ts +5 -4
- package/dist/util/navigation_utils.js +6 -6
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +8 -0
- package/dist/util/propertyConfigMapper.js +16 -2
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/package.json +15 -9
- package/recipes/README.md +79 -26
- package/recipes/approval-queue.tsx +79 -0
- package/recipes/bulk-set-status.tsx +23 -17
- package/recipes/calendar-view.tsx +28 -23
- package/recipes/master-detail.tsx +75 -0
- package/recipes/my-preferences.tsx +3 -3
- package/recipes/orders-dashboard.tsx +58 -84
- package/recipes/site-settings.tsx +4 -4
- package/dist/components/EntityFormPanel.d.ts +0 -63
- package/dist/components/EntityFormPanel.js.map +0 -1
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { isRecord } from "./bridge.js";
|
|
2
|
+
import { buildCompositeId, fieldKeyForColumn, getDeclaredPrimaryKeys, resolveCollectionRelations, resolvePrimaryKeys } from "@rebasepro/common";
|
|
3
|
+
import { toWireRow } from "@rebasepro/app";
|
|
4
|
+
import { DEFAULT_DATA_SOURCE_KEY } from "@rebasepro/types";
|
|
5
|
+
//#region src/mcp_view/tool_driver.ts
|
|
6
|
+
/**
|
|
7
|
+
* The admin panel's data layer, over the MCP tools of the server that served
|
|
8
|
+
* this view.
|
|
9
|
+
*
|
|
10
|
+
* `<Rebase>` reads and writes through a `DataDriver`; this one turns each read
|
|
11
|
+
* and write into a `tools/call` the host relays to the server — the same
|
|
12
|
+
* tools, the same person, the same RLS as the model's own calls. Rows go and
|
|
13
|
+
* come in the REST shape those tools speak (dates as ISO text, a belongsTo as
|
|
14
|
+
* its foreign key); `<Rebase>` turns them into the admin panel's view model
|
|
15
|
+
* and back, as it does for any driver.
|
|
16
|
+
*
|
|
17
|
+
* An app's row hooks (`useRows`, `useAggregate`, …) read the same driver
|
|
18
|
+
* through the flat data layer (`buildRebaseData`), which keeps the wire's
|
|
19
|
+
* rows and takes aggregates from `restFetchService`: here, the aggregate tool.
|
|
20
|
+
*
|
|
21
|
+
* A write the server answers with a plan (the hosted connector's two-step
|
|
22
|
+
* `write`) is held: the person is shown the plan and the write is sent again
|
|
23
|
+
* with its token only if they confirm. The row hooks write through
|
|
24
|
+
* `confirmingDriver`, which asks the person before any other write too: code
|
|
25
|
+
* can write without a click, while a save made with the admin's own controls
|
|
26
|
+
* was the person's click. Either way the admin panel sees one save that took
|
|
27
|
+
* a moment longer, or one that failed with "Not saved".
|
|
28
|
+
*
|
|
29
|
+
* The driver does not subscribe (no `listenCollection`/`listenOne`): every
|
|
30
|
+
* write it makes comes through `<Rebase>`'s data layers, which say so on the
|
|
31
|
+
* `<Rebase>`'s change signal, and each view of the collection reads again on
|
|
32
|
+
* it. It learns of no change it did not make — the host relays no other
|
|
33
|
+
* tool's calls — so it has nothing to announce either
|
|
34
|
+
* (`subscribeToExternalChanges`).
|
|
35
|
+
*/
|
|
36
|
+
var DEFAULT_ACTIONS = {
|
|
37
|
+
page: {
|
|
38
|
+
tool: "query_collection",
|
|
39
|
+
arguments: {}
|
|
40
|
+
},
|
|
41
|
+
get: {
|
|
42
|
+
tool: "get_document",
|
|
43
|
+
arguments: {}
|
|
44
|
+
},
|
|
45
|
+
count: {
|
|
46
|
+
tool: "count_documents",
|
|
47
|
+
arguments: {}
|
|
48
|
+
},
|
|
49
|
+
create: {
|
|
50
|
+
tool: "create_document",
|
|
51
|
+
arguments: {}
|
|
52
|
+
},
|
|
53
|
+
update: {
|
|
54
|
+
tool: "update_document",
|
|
55
|
+
arguments: {}
|
|
56
|
+
},
|
|
57
|
+
delete: {
|
|
58
|
+
tool: "delete_document",
|
|
59
|
+
arguments: {}
|
|
60
|
+
},
|
|
61
|
+
aggregate: {
|
|
62
|
+
tool: "aggregate_documents",
|
|
63
|
+
arguments: {}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/** A save the person declined at the plan. The form shows it as the save's error. */
|
|
67
|
+
var SaveCancelledError = class extends Error {
|
|
68
|
+
constructor() {
|
|
69
|
+
super("Not saved: the change was not confirmed.");
|
|
70
|
+
this.name = "SaveCancelledError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** The ceiling every read tool takes for `limit` (`MAX_LIST_LIMIT`). */
|
|
74
|
+
var MAX_LIMIT = 1e3;
|
|
75
|
+
/**
|
|
76
|
+
* How long a row read, or the seeded page, answers in place of the server.
|
|
77
|
+
* Long enough for one render's relation previews and concurrent reads to
|
|
78
|
+
* share a call, and for a row the person picks off the page they are looking
|
|
79
|
+
* at to open with none; short enough that a row the model changed with its
|
|
80
|
+
* own tools — which takes the person's message and the model's turn — is
|
|
81
|
+
* read afresh when it is refreshed or opened again.
|
|
82
|
+
*/
|
|
83
|
+
var READ_TTL_MS = 3e4;
|
|
84
|
+
function createToolDriver(options) {
|
|
85
|
+
const { callTool, actions, confirm, onChange } = options;
|
|
86
|
+
const configOf = options.collection ?? (() => void 0);
|
|
87
|
+
const canonical = (collection) => configOf(collection)?.slug ?? collection;
|
|
88
|
+
let seeds = [...options.seed ? [options.seed] : [], ...options.seeds ?? []].map((page) => ({
|
|
89
|
+
page,
|
|
90
|
+
pageTaken: false,
|
|
91
|
+
countTaken: page.total === void 0
|
|
92
|
+
}));
|
|
93
|
+
const seededAt = Date.now();
|
|
94
|
+
const changes = [];
|
|
95
|
+
const rows = /* @__PURE__ */ new Map();
|
|
96
|
+
const queued = /* @__PURE__ */ new Map();
|
|
97
|
+
let readsQueued = false;
|
|
98
|
+
const call = async (action, args) => {
|
|
99
|
+
const result = await callTool(action.tool, {
|
|
100
|
+
...action.arguments,
|
|
101
|
+
...args
|
|
102
|
+
});
|
|
103
|
+
if (result.isError) throw new Error(textOf(result) ?? "The server refused this call.");
|
|
104
|
+
return result.structuredContent ?? parseText(result);
|
|
105
|
+
};
|
|
106
|
+
/** A write, through its plan where the server asks for one. */
|
|
107
|
+
const write = async (action, args) => {
|
|
108
|
+
const first = await call(action, args);
|
|
109
|
+
const plan = planOf(first);
|
|
110
|
+
if (!plan) return first;
|
|
111
|
+
if (!await confirm(plan.plan)) throw new SaveCancelledError();
|
|
112
|
+
const second = await call(action, {
|
|
113
|
+
...args,
|
|
114
|
+
confirm: plan.token
|
|
115
|
+
});
|
|
116
|
+
if (planOf(second)) throw new Error("The server asked for confirmation again; nothing was saved.");
|
|
117
|
+
return second;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* What a write changed: what was read of its collection is dropped (the
|
|
121
|
+
* seeded page, the rows), and the model is told. The views read again on
|
|
122
|
+
* `<Rebase>`'s change signal, which the write's data layer emits.
|
|
123
|
+
*/
|
|
124
|
+
const changed = (change) => {
|
|
125
|
+
seeds = [];
|
|
126
|
+
const key = canonical(change.collection);
|
|
127
|
+
for (const row of rows.keys()) if (canonical(row.slice(0, row.lastIndexOf("/"))) === key) rows.delete(row);
|
|
128
|
+
changes.push(change);
|
|
129
|
+
onChange?.(changes);
|
|
130
|
+
};
|
|
131
|
+
/** A save's values as the write tools take them, by the collection's config where it is known. */
|
|
132
|
+
const wireValues = (props, collection) => {
|
|
133
|
+
return toWireRow(Object.fromEntries(Object.entries(props.values).filter(([, value]) => value !== void 0)), props.collection ?? configOf(collection) ?? NO_CONFIG, { included: false });
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* A page's rows into the row cache, keyed as {@link fetchOne} asks for
|
|
137
|
+
* them: the row a view lists is the row its record opens with, and a row
|
|
138
|
+
* an app was just shown opens with no call of its own. By the
|
|
139
|
+
* collection's key where its config is known, by `id` otherwise; a write
|
|
140
|
+
* to the collection drops them, as it drops every row read. Not a page
|
|
141
|
+
* that lists deleted rows: `get` answers none for those.
|
|
142
|
+
*/
|
|
143
|
+
const remember = (collection, page, config) => {
|
|
144
|
+
const keys = config ? getDeclaredPrimaryKeys(config) : [];
|
|
145
|
+
for (const row of page) {
|
|
146
|
+
const id = keys.length > 1 ? buildCompositeId(row, keys) : row[keys[0]?.fieldName ?? "id"];
|
|
147
|
+
if (typeof id !== "string" && typeof id !== "number") continue;
|
|
148
|
+
rows.set(`${collection}/${String(id)}`, {
|
|
149
|
+
read: Promise.resolve(row),
|
|
150
|
+
at: Date.now()
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
for (const { page } of seeds) remember(page.collection, page.rows, configOf(page.collection));
|
|
155
|
+
/**
|
|
156
|
+
* The seeded page, once, to a read asking for exactly it — or for more
|
|
157
|
+
* of the same rows where the seed already holds every one: a view asks
|
|
158
|
+
* one row past its page to learn whether there are more, and a page
|
|
159
|
+
* shorter than its limit has answered that.
|
|
160
|
+
*/
|
|
161
|
+
const takeSeed = (collection, args) => {
|
|
162
|
+
if (Date.now() - seededAt > READ_TTL_MS) seeds = [];
|
|
163
|
+
const seed = seeds.find((candidate) => !candidate.pageTaken && canonical(candidate.page.collection) === canonical(collection) && readKey(candidate.page.args) === readKey(args));
|
|
164
|
+
if (!seed) return void 0;
|
|
165
|
+
const seedLimit = limitOf(seed.page.args);
|
|
166
|
+
const readLimit = limitOf(args);
|
|
167
|
+
const complete = seedLimit === void 0 || seed.page.rows.length < seedLimit;
|
|
168
|
+
if (!(readLimit === seedLimit || complete && (readLimit === void 0 || seedLimit === void 0 || readLimit > seedLimit))) return void 0;
|
|
169
|
+
seed.pageTaken = true;
|
|
170
|
+
return seed.page.rows;
|
|
171
|
+
};
|
|
172
|
+
/** The count a seed's `total` answers — the collection's rows, unfiltered — once. */
|
|
173
|
+
const takeSeedCount = (collection, args) => {
|
|
174
|
+
if (Date.now() - seededAt > READ_TTL_MS) seeds = [];
|
|
175
|
+
if (args.where !== void 0 || args.searchString !== void 0 || args.deleted !== void 0) return void 0;
|
|
176
|
+
const seed = seeds.find((candidate) => !candidate.countTaken && canonical(candidate.page.collection) === canonical(collection) && candidate.page.args.where === void 0 && candidate.page.args.searchString === void 0);
|
|
177
|
+
if (!seed || seed.page.total === void 0) return void 0;
|
|
178
|
+
seed.countTaken = true;
|
|
179
|
+
return seed.page.total;
|
|
180
|
+
};
|
|
181
|
+
const fetchCollection = async (props) => {
|
|
182
|
+
const collection = collectionArg(props.path);
|
|
183
|
+
const args = readArgs(props);
|
|
184
|
+
let found = takeSeed(collection, args);
|
|
185
|
+
if (!found) {
|
|
186
|
+
const page = await call(actions.page, {
|
|
187
|
+
collection,
|
|
188
|
+
...args
|
|
189
|
+
});
|
|
190
|
+
if (!isRecord(page) || !Array.isArray(page.data)) throw new Error("The read returned no rows.");
|
|
191
|
+
found = page.data.filter(isRecord);
|
|
192
|
+
}
|
|
193
|
+
if (!props.withDeleted) remember(collection, found, props.collection);
|
|
194
|
+
return found;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* The rows asked for by key in one tick, read together: one page call per
|
|
198
|
+
* collection, `where <key> in [ids]`, however many relation previews a
|
|
199
|
+
* render draws — as the admin's `useBatchedFetch` reads them, chunked at
|
|
200
|
+
* the read tools' ceiling. A row the page does not carry is absent or not
|
|
201
|
+
* visible to the person: one answer for both, as the get tool gives.
|
|
202
|
+
*/
|
|
203
|
+
const readQueued = () => {
|
|
204
|
+
readsQueued = false;
|
|
205
|
+
const batches = [...queued];
|
|
206
|
+
queued.clear();
|
|
207
|
+
for (const [collection, { key, reads }] of batches) {
|
|
208
|
+
const ids = [...reads.keys()];
|
|
209
|
+
for (let i = 0; i < ids.length; i += MAX_LIMIT) {
|
|
210
|
+
const chunk = ids.slice(i, i + MAX_LIMIT);
|
|
211
|
+
const values = chunk.map((id) => key.type === "number" && id.trim() !== "" && !Number.isNaN(Number(id)) ? Number(id) : id);
|
|
212
|
+
call(actions.page, {
|
|
213
|
+
collection,
|
|
214
|
+
where: { [key.fieldName]: ["in", values] },
|
|
215
|
+
limit: chunk.length
|
|
216
|
+
}).then((page) => {
|
|
217
|
+
if (!isRecord(page) || !Array.isArray(page.data)) throw new Error("The read returned no rows.");
|
|
218
|
+
const byId = new Map(page.data.filter(isRecord).map((row) => [String(row[key.fieldName]), row]));
|
|
219
|
+
for (const id of chunk) reads.get(id)?.resolve(byId.get(id));
|
|
220
|
+
}).catch((error) => {
|
|
221
|
+
for (const id of chunk) reads.get(id)?.reject(error);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const readByKey = (collection, id, key) => new Promise((resolve, reject) => {
|
|
227
|
+
let batch = queued.get(collection);
|
|
228
|
+
if (!batch) {
|
|
229
|
+
batch = {
|
|
230
|
+
key,
|
|
231
|
+
reads: /* @__PURE__ */ new Map()
|
|
232
|
+
};
|
|
233
|
+
queued.set(collection, batch);
|
|
234
|
+
}
|
|
235
|
+
batch.reads.set(id, {
|
|
236
|
+
resolve,
|
|
237
|
+
reject
|
|
238
|
+
});
|
|
239
|
+
if (!readsQueued) {
|
|
240
|
+
readsQueued = true;
|
|
241
|
+
queueMicrotask(readQueued);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
/** A row of a collection with no single key column to put an `in` on, or none known: by the get tool. */
|
|
245
|
+
const readById = (collection, id) => call(actions.get, {
|
|
246
|
+
collection,
|
|
247
|
+
id
|
|
248
|
+
}).then((row) => isRecord(row) ? row : void 0).catch((error) => {
|
|
249
|
+
if (error instanceof Error && /^No row with id/.test(error.message)) return void 0;
|
|
250
|
+
throw error;
|
|
251
|
+
});
|
|
252
|
+
/**
|
|
253
|
+
* A row: by the page tool wherever its collection has one key column — a
|
|
254
|
+
* lone row as well as a crowd of previews. One rule, so a row is read the
|
|
255
|
+
* same way however many are drawn beside it; and the page tool is the one
|
|
256
|
+
* every server names (a hosted result may name no `get`), whose answer
|
|
257
|
+
* for an absent row is an empty page rather than an error told apart by
|
|
258
|
+
* its text.
|
|
259
|
+
*/
|
|
260
|
+
const fetchOne = (props) => {
|
|
261
|
+
const collection = collectionArg(props.path);
|
|
262
|
+
const key = `${collection}/${String(props.id)}`;
|
|
263
|
+
const cached = rows.get(key);
|
|
264
|
+
if (cached && Date.now() - cached.at <= READ_TTL_MS) return cached.read;
|
|
265
|
+
const config = props.collection ?? configOf(collection);
|
|
266
|
+
const keys = config ? resolvePrimaryKeys(config) : [];
|
|
267
|
+
const read = (keys.length === 1 ? readByKey(collection, String(props.id), keys[0]) : readById(collection, String(props.id))).catch((error) => {
|
|
268
|
+
if (rows.get(key)?.read === read) rows.delete(key);
|
|
269
|
+
throw error;
|
|
270
|
+
});
|
|
271
|
+
rows.set(key, {
|
|
272
|
+
read,
|
|
273
|
+
at: Date.now()
|
|
274
|
+
});
|
|
275
|
+
return read;
|
|
276
|
+
};
|
|
277
|
+
const driver = {
|
|
278
|
+
key: DEFAULT_DATA_SOURCE_KEY,
|
|
279
|
+
initialised: true,
|
|
280
|
+
fetchCollection,
|
|
281
|
+
fetchOne,
|
|
282
|
+
restFetchService: {
|
|
283
|
+
fetchCollectionForRest(path, options = {}) {
|
|
284
|
+
refuseUnsupported(options);
|
|
285
|
+
return fetchCollection({
|
|
286
|
+
path,
|
|
287
|
+
...options.filter && { filter: options.filter },
|
|
288
|
+
...options.orderBy !== void 0 && { orderBy: options.orderBy },
|
|
289
|
+
...options.order && { order: options.order },
|
|
290
|
+
...options.limit !== void 0 && { limit: options.limit },
|
|
291
|
+
...options.offset !== void 0 && { offset: options.offset },
|
|
292
|
+
...options.searchString && { searchString: options.searchString },
|
|
293
|
+
...options.withDeleted !== void 0 && { withDeleted: options.withDeleted }
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
async fetchOneForRest(path, id) {
|
|
297
|
+
return await fetchOne({
|
|
298
|
+
path,
|
|
299
|
+
id
|
|
300
|
+
}) ?? null;
|
|
301
|
+
},
|
|
302
|
+
async aggregate(path, options) {
|
|
303
|
+
refuseUnsupported(options);
|
|
304
|
+
const where = options.filter ? wireFilter(options.filter, void 0) : void 0;
|
|
305
|
+
const answer = await call(actions.aggregate, {
|
|
306
|
+
collection: collectionArg(path),
|
|
307
|
+
select: options.aggregates.map((aggregate) => `${aggregate.fn}(${aggregate.field ?? ""})`),
|
|
308
|
+
...options.groupBy && options.groupBy.length > 0 && { groupBy: options.groupBy },
|
|
309
|
+
...where && Object.keys(where).length > 0 && { where },
|
|
310
|
+
...options.searchString && { searchString: options.searchString },
|
|
311
|
+
...options.orderBy && options.orderBy.length > 0 && { orderBy: options.orderBy },
|
|
312
|
+
...options.limit !== void 0 && { limit: Math.min(options.limit, MAX_LIMIT) },
|
|
313
|
+
...options.offset && { offset: options.offset },
|
|
314
|
+
...options.withDeleted && { deleted: options.withDeleted === "only" ? "only" : "include" }
|
|
315
|
+
});
|
|
316
|
+
if (!isRecord(answer) || !Array.isArray(answer.data)) throw new Error("The aggregate returned no rows.");
|
|
317
|
+
return answer.data.filter(isRecord);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
async save(props) {
|
|
321
|
+
const collection = collectionArg(props.path);
|
|
322
|
+
const data = wireValues(props, collection);
|
|
323
|
+
const creating = props.status !== "existing";
|
|
324
|
+
const action = creating ? actions.create : actions.update;
|
|
325
|
+
const saved = creating ? await write(action, {
|
|
326
|
+
collection,
|
|
327
|
+
data,
|
|
328
|
+
...props.id !== void 0 && { id: String(props.id) }
|
|
329
|
+
}) : await write(action, {
|
|
330
|
+
collection,
|
|
331
|
+
id: String(props.id),
|
|
332
|
+
data
|
|
333
|
+
});
|
|
334
|
+
const row = isRecord(saved) ? saved : { ...data };
|
|
335
|
+
const id = String(row.id ?? props.id ?? "");
|
|
336
|
+
changed({
|
|
337
|
+
action: creating ? "created" : "updated",
|
|
338
|
+
collection,
|
|
339
|
+
id,
|
|
340
|
+
fields: Object.keys(data)
|
|
341
|
+
});
|
|
342
|
+
return row;
|
|
343
|
+
},
|
|
344
|
+
async delete(props) {
|
|
345
|
+
const collection = collectionArg(props.row.path);
|
|
346
|
+
await write(actions.delete, {
|
|
347
|
+
collection,
|
|
348
|
+
id: String(props.row.id)
|
|
349
|
+
});
|
|
350
|
+
changed({
|
|
351
|
+
action: "deleted",
|
|
352
|
+
collection,
|
|
353
|
+
id: String(props.row.id)
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
async count(props) {
|
|
357
|
+
const collection = collectionArg(props.path);
|
|
358
|
+
const args = pickRead(readArgs(props), [
|
|
359
|
+
"where",
|
|
360
|
+
"searchString",
|
|
361
|
+
"deleted"
|
|
362
|
+
]);
|
|
363
|
+
const seeded = takeSeedCount(collection, args);
|
|
364
|
+
if (seeded !== void 0) return seeded;
|
|
365
|
+
const answer = await call(actions.count, {
|
|
366
|
+
collection,
|
|
367
|
+
...args
|
|
368
|
+
});
|
|
369
|
+
if (isRecord(answer) && typeof answer.count === "number") return answer.count;
|
|
370
|
+
throw new Error("The count returned no number.");
|
|
371
|
+
},
|
|
372
|
+
async checkUniqueField() {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
/** The person's yes before a write the tool does not plan; their no rejects, and nothing is sent. */
|
|
377
|
+
const confirmFirst = async (action, plan) => {
|
|
378
|
+
if (!action.plans && !await confirm(plan)) throw new SaveCancelledError();
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
driver,
|
|
382
|
+
confirmingDriver: {
|
|
383
|
+
...driver,
|
|
384
|
+
async save(props) {
|
|
385
|
+
const collection = collectionArg(props.path);
|
|
386
|
+
const creating = props.status !== "existing";
|
|
387
|
+
await confirmFirst(creating ? actions.create : actions.update, creating ? { summary: `Create a row in ${collection}.` } : { summary: `Change ${Object.keys(wireValues(props, collection)).join(", ")} on row ${String(props.id)} of ${collection}.` });
|
|
388
|
+
return driver.save(props);
|
|
389
|
+
},
|
|
390
|
+
async delete(props) {
|
|
391
|
+
const collection = collectionArg(props.row.path);
|
|
392
|
+
await confirmFirst(actions.delete, { summary: `Delete row ${String(props.row.id)} of ${collection}.` });
|
|
393
|
+
return driver.delete(props);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* The collection a driver path names. The views open top-level collections
|
|
400
|
+
* only; a subcollection path has no tool to read it.
|
|
401
|
+
*/
|
|
402
|
+
function collectionArg(path) {
|
|
403
|
+
if (path.includes("/")) throw new Error(`"${path}" is a subcollection, which this view cannot open.`);
|
|
404
|
+
return path;
|
|
405
|
+
}
|
|
406
|
+
/** A read's arguments, as the read tools take them. */
|
|
407
|
+
function readArgs(props) {
|
|
408
|
+
const where = props.filter ? wireFilter(props.filter, props.collection) : void 0;
|
|
409
|
+
const orderBy = wireOrderBy(props, props.collection);
|
|
410
|
+
return {
|
|
411
|
+
...where && Object.keys(where).length > 0 && { where },
|
|
412
|
+
...orderBy && { orderBy },
|
|
413
|
+
...props.searchString && { searchString: props.searchString },
|
|
414
|
+
...props.limit !== void 0 && { limit: Math.min(props.limit, MAX_LIMIT) },
|
|
415
|
+
...props.offset && { offset: props.offset },
|
|
416
|
+
...props.withDeleted !== void 0 && props.withDeleted !== false && { deleted: props.withDeleted === "only" ? "only" : "include" }
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/** What the read tools cannot express, refused rather than read wider than asked. */
|
|
420
|
+
function refuseUnsupported(options) {
|
|
421
|
+
if (options.logical) throw new Error("This view's tools cannot filter by an or()/and() group.");
|
|
422
|
+
if (options.vectorSearch) throw new Error("This view's tools cannot run a vector search.");
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Which rows a read asks for, as one comparable string: the same rows however
|
|
426
|
+
* the read was written — a sort as `"field:desc"` or `[["field", "desc"]]`, a
|
|
427
|
+
* filter's fields in any order, no offset or offset 0. How many is
|
|
428
|
+
* {@link limitOf}'s.
|
|
429
|
+
*/
|
|
430
|
+
function readKey(args) {
|
|
431
|
+
const where = isRecord(args.where) ? args.where : {};
|
|
432
|
+
return JSON.stringify([
|
|
433
|
+
Object.keys(where).sort().map((key) => [key, where[key]]),
|
|
434
|
+
sortOf(args.orderBy),
|
|
435
|
+
typeof args.searchString === "string" ? args.searchString : "",
|
|
436
|
+
typeof args.offset === "number" ? args.offset : 0,
|
|
437
|
+
typeof args.deleted === "string" ? args.deleted : null
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
function limitOf(args) {
|
|
441
|
+
return typeof args.limit === "number" ? args.limit : void 0;
|
|
442
|
+
}
|
|
443
|
+
function sortOf(orderBy) {
|
|
444
|
+
if (typeof orderBy === "string" && orderBy !== "") {
|
|
445
|
+
const [field, direction] = orderBy.split(":");
|
|
446
|
+
return [[field, direction === "desc" ? "desc" : "asc"]];
|
|
447
|
+
}
|
|
448
|
+
if (!Array.isArray(orderBy) || orderBy.length === 0) return [];
|
|
449
|
+
return (Array.isArray(orderBy[0]) ? orderBy : [orderBy]).map((entry) => Array.isArray(entry) ? [entry[0], entry[1] === "desc" ? "desc" : "asc"] : entry);
|
|
450
|
+
}
|
|
451
|
+
function pickRead(args, names) {
|
|
452
|
+
return Object.fromEntries(Object.entries(args).filter(([name]) => names.includes(name)));
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The admin panel's filter as the read tools' `where`: a belongsTo is
|
|
456
|
+
* filtered by its foreign key there, and a value is the wire's — a relation
|
|
457
|
+
* its id, a date its ISO text.
|
|
458
|
+
*/
|
|
459
|
+
function wireFilter(filter, collection) {
|
|
460
|
+
const keys = foreignKeys(collection);
|
|
461
|
+
const where = {};
|
|
462
|
+
for (const [key, condition] of Object.entries(filter)) {
|
|
463
|
+
if (condition === void 0) continue;
|
|
464
|
+
where[keys.get(key) ?? key] = toWireRow({ condition }, NO_CONFIG).condition;
|
|
465
|
+
}
|
|
466
|
+
return where;
|
|
467
|
+
}
|
|
468
|
+
/** No properties, so {@link toWireRow} converts each value by what it is: a relation to its id, a date to ISO text. */
|
|
469
|
+
var NO_CONFIG = {
|
|
470
|
+
slug: "",
|
|
471
|
+
name: "",
|
|
472
|
+
properties: {}
|
|
473
|
+
};
|
|
474
|
+
function wireOrderBy(props, collection) {
|
|
475
|
+
const keys = foreignKeys(collection);
|
|
476
|
+
if (typeof props.orderBy === "string") {
|
|
477
|
+
const field = keys.get(props.orderBy) ?? props.orderBy;
|
|
478
|
+
return props.order ? `${field}:${props.order}` : field;
|
|
479
|
+
}
|
|
480
|
+
if (Array.isArray(props.orderBy) && props.orderBy.length > 0) return props.orderBy.map((entry) => Array.isArray(entry) && typeof entry[0] === "string" ? [keys.get(entry[0]) ?? entry[0], ...entry.slice(1)] : entry);
|
|
481
|
+
}
|
|
482
|
+
/** A collection's belongsTo relations, by name → the foreign key its rows carry. */
|
|
483
|
+
function foreignKeys(collection) {
|
|
484
|
+
const keys = /* @__PURE__ */ new Map();
|
|
485
|
+
if (!collection) return keys;
|
|
486
|
+
try {
|
|
487
|
+
for (const [name, relation] of Object.entries(resolveCollectionRelations(collection))) if (relation.kind === "belongsTo" && relation.localKey) keys.set(name, fieldKeyForColumn(collection, relation.localKey));
|
|
488
|
+
} catch {}
|
|
489
|
+
return keys;
|
|
490
|
+
}
|
|
491
|
+
/** A write's plan and token, where its first call answered one (the server's `confirmation.ts`). */
|
|
492
|
+
function planOf(answer) {
|
|
493
|
+
if (!isRecord(answer) || answer.status !== "confirmation_required" || typeof answer.confirm !== "string") return void 0;
|
|
494
|
+
const plan = isRecord(answer.plan) ? answer.plan : {};
|
|
495
|
+
return {
|
|
496
|
+
token: answer.confirm,
|
|
497
|
+
plan: {
|
|
498
|
+
summary: typeof plan.summary === "string" ? plan.summary : "Save this change?",
|
|
499
|
+
...Array.isArray(plan.effects) && { effects: plan.effects.filter((line) => typeof line === "string") },
|
|
500
|
+
...typeof plan.reversible === "string" && { reversible: plan.reversible }
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
/** A result with no `structuredContent`: its text, as JSON where it is JSON. */
|
|
505
|
+
function parseText(result) {
|
|
506
|
+
const text = textOf(result);
|
|
507
|
+
if (text === void 0) return void 0;
|
|
508
|
+
const start = text.indexOf("{");
|
|
509
|
+
const end = text.lastIndexOf("}");
|
|
510
|
+
if (start < 0 || end < start) return void 0;
|
|
511
|
+
try {
|
|
512
|
+
return JSON.parse(text.slice(start, end + 1));
|
|
513
|
+
} catch {
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function textOf(result) {
|
|
518
|
+
return result.content?.find((block) => typeof block.text === "string")?.text;
|
|
519
|
+
}
|
|
520
|
+
/** What the model is told the person changed here, sent with their next message. */
|
|
521
|
+
function describeChanges(changes) {
|
|
522
|
+
return `In the Rebase view, the user saved these changes: ${changes.map((change) => change.action === "updated" ? `updated ${change.fields?.join(", ") || "fields"} on row ${change.id} of ${change.collection}` : `${change.action} row ${change.id} of ${change.collection}`).join("; ")}. Rows you read before them may be out of date.`;
|
|
523
|
+
}
|
|
524
|
+
//#endregion
|
|
525
|
+
export { DEFAULT_ACTIONS, SaveCancelledError, createToolDriver, describeChanges, textOf };
|
|
526
|
+
|
|
527
|
+
//# sourceMappingURL=tool_driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool_driver.js","names":[],"sources":["../../src/mcp_view/tool_driver.ts"],"sourcesContent":["/**\n * The admin panel's data layer, over the MCP tools of the server that served\n * this view.\n *\n * `<Rebase>` reads and writes through a `DataDriver`; this one turns each read\n * and write into a `tools/call` the host relays to the server — the same\n * tools, the same person, the same RLS as the model's own calls. Rows go and\n * come in the REST shape those tools speak (dates as ISO text, a belongsTo as\n * its foreign key); `<Rebase>` turns them into the admin panel's view model\n * and back, as it does for any driver.\n *\n * An app's row hooks (`useRows`, `useAggregate`, …) read the same driver\n * through the flat data layer (`buildRebaseData`), which keeps the wire's\n * rows and takes aggregates from `restFetchService`: here, the aggregate tool.\n *\n * A write the server answers with a plan (the hosted connector's two-step\n * `write`) is held: the person is shown the plan and the write is sent again\n * with its token only if they confirm. The row hooks write through\n * `confirmingDriver`, which asks the person before any other write too: code\n * can write without a click, while a save made with the admin's own controls\n * was the person's click. Either way the admin panel sees one save that took\n * a moment longer, or one that failed with \"Not saved\".\n *\n * The driver does not subscribe (no `listenCollection`/`listenOne`): every\n * write it makes comes through `<Rebase>`'s data layers, which say so on the\n * `<Rebase>`'s change signal, and each view of the collection reads again on\n * it. It learns of no change it did not make — the host relays no other\n * tool's calls — so it has nothing to announce either\n * (`subscribeToExternalChanges`).\n */\nimport {\n DEFAULT_DATA_SOURCE_KEY,\n type CollectionConfig,\n type DataDriver,\n type DeleteProps,\n type FetchCollectionProps,\n type FetchOneProps,\n type RestFetchService,\n type SaveProps\n} from \"@rebasepro/types\";\nimport {\n buildCompositeId,\n fieldKeyForColumn,\n getDeclaredPrimaryKeys,\n resolveCollectionRelations,\n resolvePrimaryKeys,\n type PrimaryKeyInfo\n} from \"@rebasepro/common\";\nimport { toWireRow } from \"@rebasepro/app\";\nimport { isRecord, type ToolResult } from \"./bridge\";\n\n/** A tool the view calls, and the arguments it always sends to it. */\nexport interface ToolAction {\n tool: string;\n arguments: Record<string, unknown>;\n /**\n * The tool answers a plan before it changes anything (the hosted\n * connector's `write`), so the person confirms there. Not set, a change\n * the row hooks make is confirmed in the view before it is sent.\n */\n plans?: boolean;\n}\n\n/**\n * The tools the view reads and writes with. The server that served it may\n * name its own (`actions` in a show_* result): the hosted Rebase connector\n * reads with `query` and writes with `write`, each with the project. Absent,\n * they are an app's own `/mcp` tools.\n */\nexport interface ViewActions {\n page: ToolAction;\n get: ToolAction;\n count: ToolAction;\n create: ToolAction;\n update: ToolAction;\n delete: ToolAction;\n /** `count`/`sum`/`avg`/`min`/`max` over the matching rows, grouped or not, as REST's `select` and `groupBy`. */\n aggregate: ToolAction;\n}\n\nexport const DEFAULT_ACTIONS: ViewActions = {\n page: { tool: \"query_collection\", arguments: {} },\n get: { tool: \"get_document\", arguments: {} },\n count: { tool: \"count_documents\", arguments: {} },\n create: { tool: \"create_document\", arguments: {} },\n update: { tool: \"update_document\", arguments: {} },\n delete: { tool: \"delete_document\", arguments: {} },\n aggregate: { tool: \"aggregate_documents\", arguments: {} }\n};\n\n/** What a write's first call answered instead of running: what it will do, for the person to confirm. */\nexport interface WritePlan {\n summary: string;\n effects?: string[];\n reversible?: string;\n}\n\n/** One change the person made here, as the model is told about it. */\nexport interface ViewChange {\n action: \"created\" | \"updated\" | \"deleted\";\n collection: string;\n id: string;\n fields?: string[];\n}\n\n/** The calls the driver makes: the bridge's `callTool`, as a function so a test can stand in for the host. */\nexport type CallTool = (name: string, args: Record<string, unknown>) => Promise<ToolResult>;\n\n/**\n * A page a result already carries: the rows the server read — for the model\n * (show_collection), or ahead of an app's first render (show_app) — and the\n * arguments it read them with.\n */\nexport interface SeedPage {\n collection: string;\n /** As the read tools take them: `where`, `orderBy`, `searchString`, `limit`, `offset`. */\n args: Record<string, unknown>;\n rows: Record<string, unknown>[];\n /** How many rows the read's filter matches, where the server counted them: answers that count, once. */\n total?: number;\n}\n\nexport interface ToolDriverOptions {\n callTool: CallTool;\n actions: ViewActions;\n /** Show the person a write's plan; true when they confirm it. */\n confirm: (plan: WritePlan) => Promise<boolean>;\n /**\n * A page already read: served once in place of the read tool's call, to\n * a read asking for exactly it, and dropped by any write or once it is\n * older than the driver's read cache keeps a row.\n */\n seed?: SeedPage;\n /**\n * Pages read ahead of an app's first render, one per collection it\n * names: each served once as {@link seed} is, its rows answering a read\n * by key, and its `total` the count of the collection's rows.\n */\n seeds?: SeedPage[];\n /** Every change made through this driver, in order, after each one. */\n onChange?: (changes: readonly ViewChange[]) => void;\n /**\n * The collection a name the tools take names — its slug or its data\n * path: an app names collections as the model wrote them, the admin\n * panel by slug. A write's values are sent by its config (a date-only\n * column as its day, a belongsTo under its foreign key), and drop what\n * was read of it under either name.\n */\n collection?: (name: string) => CollectionConfig | undefined;\n}\n\ntype Row = Record<string, unknown>;\n\nexport interface ToolDriver {\n /** For `<Rebase>`: the admin panel's reads and saves. */\n driver: DataDriver;\n /**\n * The same driver, asking the person before each write the tool does not\n * plan itself: for the row hooks (`useRowWrites`), since code can write\n * without a click. A declined write rejects with {@link SaveCancelledError}\n * and nothing is sent.\n */\n confirmingDriver: DataDriver;\n}\n\n/** A row asked for by key, waiting on its batch's page. */\ninterface QueuedRead {\n resolve: (row: Record<string, unknown> | undefined) => void;\n reject: (error: unknown) => void;\n}\n\n/** A save the person declined at the plan. The form shows it as the save's error. */\nexport class SaveCancelledError extends Error {\n constructor() {\n super(\"Not saved: the change was not confirmed.\");\n this.name = \"SaveCancelledError\";\n }\n}\n\n/** The ceiling every read tool takes for `limit` (`MAX_LIST_LIMIT`). */\nconst MAX_LIMIT = 1000;\n\n/**\n * How long a row read, or the seeded page, answers in place of the server.\n * Long enough for one render's relation previews and concurrent reads to\n * share a call, and for a row the person picks off the page they are looking\n * at to open with none; short enough that a row the model changed with its\n * own tools — which takes the person's message and the model's turn — is\n * read afresh when it is refreshed or opened again.\n */\nconst READ_TTL_MS = 30_000;\n\nexport function createToolDriver(options: ToolDriverOptions): ToolDriver {\n const { callTool, actions, confirm, onChange } = options;\n const configOf = options.collection ?? (() => undefined);\n const canonical = (collection: string) => configOf(collection)?.slug ?? collection;\n // Each seed answers its page once and its count once.\n let seeds = [...(options.seed ? [options.seed] : []), ...(options.seeds ?? [])]\n .map(page => ({ page, pageTaken: false, countTaken: page.total === undefined }));\n const seededAt = Date.now();\n const changes: ViewChange[] = [];\n // A table draws each row's relations by reading the related row, so a\n // page of orders asks for the same customer many times over. Each read is\n // a round trip through the host: one per row is shared until a write, or\n // until it is older than `READ_TTL_MS`, since the model can change a row\n // with its own tools and this driver never hears of it.\n const rows = new Map<string, { read: Promise<Record<string, unknown> | undefined>; at: number }>();\n // The rows asked for by key in this tick and not yet read, by collection:\n // each collection's are read by one page call (`readQueued`).\n const queued = new Map<string, { key: PrimaryKeyInfo; reads: Map<string, QueuedRead> }>();\n let readsQueued = false;\n\n const call = async (action: ToolAction, args: Record<string, unknown>): Promise<unknown> => {\n const result = await callTool(action.tool, { ...action.arguments, ...args });\n if (result.isError) throw new Error(textOf(result) ?? \"The server refused this call.\");\n return result.structuredContent ?? parseText(result);\n };\n\n /** A write, through its plan where the server asks for one. */\n const write = async (action: ToolAction, args: Record<string, unknown>): Promise<unknown> => {\n const first = await call(action, args);\n const plan = planOf(first);\n if (!plan) return first;\n if (!await confirm(plan.plan)) throw new SaveCancelledError();\n const second = await call(action, { ...args, confirm: plan.token });\n if (planOf(second)) throw new Error(\"The server asked for confirmation again; nothing was saved.\");\n return second;\n };\n\n /**\n * What a write changed: what was read of its collection is dropped (the\n * seeded page, the rows), and the model is told. The views read again on\n * `<Rebase>`'s change signal, which the write's data layer emits.\n */\n const changed = (change: ViewChange) => {\n // Every seed, not only this collection's: a page carries the related\n // rows it includes, and a write to those changes it too.\n seeds = [];\n const key = canonical(change.collection);\n for (const row of rows.keys()) if (canonical(row.slice(0, row.lastIndexOf(\"/\"))) === key) rows.delete(row);\n changes.push(change);\n onChange?.(changes);\n };\n\n /** A save's values as the write tools take them, by the collection's config where it is known. */\n const wireValues = (props: SaveProps, collection: string): Record<string, unknown> => {\n const defined = Object.fromEntries(Object.entries(props.values).filter(([, value]) => value !== undefined));\n return toWireRow(defined, props.collection ?? configOf(collection) ?? NO_CONFIG, { included: false });\n };\n\n /**\n * A page's rows into the row cache, keyed as {@link fetchOne} asks for\n * them: the row a view lists is the row its record opens with, and a row\n * an app was just shown opens with no call of its own. By the\n * collection's key where its config is known, by `id` otherwise; a write\n * to the collection drops them, as it drops every row read. Not a page\n * that lists deleted rows: `get` answers none for those.\n */\n const remember = (collection: string, page: Row[], config?: FetchCollectionProps[\"collection\"]) => {\n const keys = config ? getDeclaredPrimaryKeys(config) : [];\n for (const row of page) {\n const id = keys.length > 1 ? buildCompositeId(row, keys) : row[keys[0]?.fieldName ?? \"id\"];\n if (typeof id !== \"string\" && typeof id !== \"number\") continue;\n rows.set(`${collection}/${String(id)}`, { read: Promise.resolve(row), at: Date.now() });\n }\n };\n // A seeded row opens with no call of its own — a record form, a detail,\n // a relation's title — even where no read asks for the page it came in.\n for (const { page } of seeds) remember(page.collection, page.rows, configOf(page.collection));\n\n /**\n * The seeded page, once, to a read asking for exactly it — or for more\n * of the same rows where the seed already holds every one: a view asks\n * one row past its page to learn whether there are more, and a page\n * shorter than its limit has answered that.\n */\n const takeSeed = (collection: string, args: Record<string, unknown>): Row[] | undefined => {\n if (Date.now() - seededAt > READ_TTL_MS) seeds = [];\n const seed = seeds.find(candidate => !candidate.pageTaken\n && canonical(candidate.page.collection) === canonical(collection) && readKey(candidate.page.args) === readKey(args));\n if (!seed) return undefined;\n const seedLimit = limitOf(seed.page.args);\n const readLimit = limitOf(args);\n const complete = seedLimit === undefined || seed.page.rows.length < seedLimit;\n const answers = readLimit === seedLimit || (complete && (readLimit === undefined || seedLimit === undefined || readLimit > seedLimit));\n if (!answers) return undefined;\n seed.pageTaken = true;\n return seed.page.rows;\n };\n\n /** The count a seed's `total` answers — the collection's rows, unfiltered — once. */\n const takeSeedCount = (collection: string, args: Record<string, unknown>): number | undefined => {\n if (Date.now() - seededAt > READ_TTL_MS) seeds = [];\n if (args.where !== undefined || args.searchString !== undefined || args.deleted !== undefined) return undefined;\n const seed = seeds.find(candidate => !candidate.countTaken && canonical(candidate.page.collection) === canonical(collection)\n && candidate.page.args.where === undefined && candidate.page.args.searchString === undefined);\n if (!seed || seed.page.total === undefined) return undefined;\n seed.countTaken = true;\n return seed.page.total;\n };\n\n const fetchCollection = async (props: FetchCollectionProps): Promise<Record<string, unknown>[]> => {\n const collection = collectionArg(props.path);\n const args = readArgs(props);\n let found = takeSeed(collection, args);\n if (!found) {\n const page = await call(actions.page, { collection, ...args });\n if (!isRecord(page) || !Array.isArray(page.data)) throw new Error(\"The read returned no rows.\");\n found = page.data.filter(isRecord);\n }\n if (!props.withDeleted) remember(collection, found, props.collection);\n return found;\n };\n\n /**\n * The rows asked for by key in one tick, read together: one page call per\n * collection, `where <key> in [ids]`, however many relation previews a\n * render draws — as the admin's `useBatchedFetch` reads them, chunked at\n * the read tools' ceiling. A row the page does not carry is absent or not\n * visible to the person: one answer for both, as the get tool gives.\n */\n const readQueued = () => {\n readsQueued = false;\n const batches = [...queued];\n queued.clear();\n for (const [collection, { key, reads }] of batches) {\n const ids = [...reads.keys()];\n for (let i = 0; i < ids.length; i += MAX_LIMIT) {\n const chunk = ids.slice(i, i + MAX_LIMIT);\n const values = chunk.map(id => key.type === \"number\" && id.trim() !== \"\" && !Number.isNaN(Number(id)) ? Number(id) : id);\n call(actions.page, { collection, where: { [key.fieldName]: [\"in\", values] }, limit: chunk.length })\n .then(page => {\n if (!isRecord(page) || !Array.isArray(page.data)) throw new Error(\"The read returned no rows.\");\n const byId = new Map(page.data.filter(isRecord).map(row => [String(row[key.fieldName]), row]));\n for (const id of chunk) reads.get(id)?.resolve(byId.get(id));\n })\n .catch((error: unknown) => {\n for (const id of chunk) reads.get(id)?.reject(error);\n });\n }\n }\n };\n\n const readByKey = (collection: string, id: string, key: PrimaryKeyInfo): Promise<Row | undefined> =>\n new Promise((resolve, reject) => {\n let batch = queued.get(collection);\n if (!batch) {\n batch = { key, reads: new Map() };\n queued.set(collection, batch);\n }\n batch.reads.set(id, { resolve, reject });\n if (!readsQueued) {\n readsQueued = true;\n queueMicrotask(readQueued);\n }\n });\n\n /** A row of a collection with no single key column to put an `in` on, or none known: by the get tool. */\n const readById = (collection: string, id: string): Promise<Row | undefined> =>\n call(actions.get, { collection, id })\n .then(row => isRecord(row) ? row : undefined)\n .catch((error: unknown) => {\n // One answer for \"absent\" and \"not visible to you\", by design.\n if (error instanceof Error && /^No row with id/.test(error.message)) return undefined;\n throw error;\n });\n\n /**\n * A row: by the page tool wherever its collection has one key column — a\n * lone row as well as a crowd of previews. One rule, so a row is read the\n * same way however many are drawn beside it; and the page tool is the one\n * every server names (a hosted result may name no `get`), whose answer\n * for an absent row is an empty page rather than an error told apart by\n * its text.\n */\n const fetchOne = (props: FetchOneProps): Promise<Record<string, unknown> | undefined> => {\n const collection = collectionArg(props.path);\n const key = `${collection}/${String(props.id)}`;\n const cached = rows.get(key);\n if (cached && Date.now() - cached.at <= READ_TTL_MS) return cached.read;\n const config = props.collection ?? configOf(collection);\n const keys = config ? resolvePrimaryKeys(config) : [];\n const read: Promise<Row | undefined> = (keys.length === 1\n ? readByKey(collection, String(props.id), keys[0])\n : readById(collection, String(props.id)))\n .catch((error: unknown) => {\n if (rows.get(key)?.read === read) rows.delete(key);\n throw error;\n });\n rows.set(key, { read, at: Date.now() });\n return read;\n };\n\n /**\n * The flat data layer's reads: the same tools and the same rows as the\n * admin panel's, and the aggregate tool.\n */\n const restFetchService: RestFetchService = {\n fetchCollectionForRest(path, options = {}) {\n refuseUnsupported(options);\n return fetchCollection({\n path,\n ...(options.filter && { filter: options.filter }),\n ...(options.orderBy !== undefined && { orderBy: options.orderBy }),\n ...(options.order && { order: options.order }),\n ...(options.limit !== undefined && { limit: options.limit }),\n ...(options.offset !== undefined && { offset: options.offset }),\n ...(options.searchString && { searchString: options.searchString }),\n ...(options.withDeleted !== undefined && { withDeleted: options.withDeleted })\n });\n },\n async fetchOneForRest(path, id) {\n return await fetchOne({ path, id }) ?? null;\n },\n async aggregate(path, options) {\n refuseUnsupported(options);\n const where = options.filter ? wireFilter(options.filter, undefined) : undefined;\n const answer = await call(actions.aggregate, {\n collection: collectionArg(path),\n select: options.aggregates.map(aggregate => `${aggregate.fn}(${aggregate.field ?? \"\"})`),\n ...(options.groupBy && options.groupBy.length > 0 && { groupBy: options.groupBy }),\n ...(where && Object.keys(where).length > 0 && { where }),\n ...(options.searchString && { searchString: options.searchString }),\n ...(options.orderBy && options.orderBy.length > 0 && { orderBy: options.orderBy }),\n ...(options.limit !== undefined && { limit: Math.min(options.limit, MAX_LIMIT) }),\n ...(options.offset && { offset: options.offset }),\n ...(options.withDeleted && { deleted: options.withDeleted === \"only\" ? \"only\" : \"include\" })\n });\n if (!isRecord(answer) || !Array.isArray(answer.data)) throw new Error(\"The aggregate returned no rows.\");\n return answer.data.filter(isRecord);\n }\n };\n\n const driver: DataDriver = {\n key: DEFAULT_DATA_SOURCE_KEY,\n initialised: true,\n\n fetchCollection,\n fetchOne,\n restFetchService,\n\n async save(props: SaveProps): Promise<Record<string, unknown>> {\n const collection = collectionArg(props.path);\n const data = wireValues(props, collection);\n const creating = props.status !== \"existing\";\n const action = creating ? actions.create : actions.update;\n const saved = creating\n ? await write(action, { collection, data, ...(props.id !== undefined && { id: String(props.id) }) })\n : await write(action, { collection, id: String(props.id), data });\n const row = isRecord(saved) ? saved : { ...data };\n const id = String(row.id ?? props.id ?? \"\");\n changed({ action: creating ? \"created\" : \"updated\", collection, id, fields: Object.keys(data) });\n return row;\n },\n\n async delete(props: DeleteProps): Promise<void> {\n const collection = collectionArg(props.row.path);\n await write(actions.delete, { collection, id: String(props.row.id) });\n changed({ action: \"deleted\", collection, id: String(props.row.id) });\n },\n\n async count(props: FetchCollectionProps): Promise<number> {\n const collection = collectionArg(props.path);\n const args = pickRead(readArgs(props), [\"where\", \"searchString\", \"deleted\"]);\n const seeded = takeSeedCount(collection, args);\n if (seeded !== undefined) return seeded;\n const answer = await call(actions.count, { collection, ...args });\n if (isRecord(answer) && typeof answer.count === \"number\") return answer.count;\n throw new Error(\"The count returned no number.\");\n },\n\n // The server checks a unique field when the row is written; a check\n // here would be one more round trip through the host for each keystroke.\n async checkUniqueField(): Promise<boolean> {\n return true;\n }\n };\n\n /** The person's yes before a write the tool does not plan; their no rejects, and nothing is sent. */\n const confirmFirst = async (action: ToolAction, plan: WritePlan): Promise<void> => {\n if (!action.plans && !await confirm(plan)) throw new SaveCancelledError();\n };\n\n const confirmingDriver: DataDriver = {\n ...driver,\n async save(props: SaveProps): Promise<Record<string, unknown>> {\n const collection = collectionArg(props.path);\n const creating = props.status !== \"existing\";\n await confirmFirst(creating ? actions.create : actions.update, creating\n ? { summary: `Create a row in ${collection}.` }\n : { summary: `Change ${Object.keys(wireValues(props, collection)).join(\", \")} on row ${String(props.id)} of ${collection}.` });\n return driver.save(props);\n },\n async delete(props: DeleteProps): Promise<void> {\n const collection = collectionArg(props.row.path);\n await confirmFirst(actions.delete, { summary: `Delete row ${String(props.row.id)} of ${collection}.` });\n return driver.delete(props);\n }\n };\n\n return { driver, confirmingDriver };\n}\n\n/**\n * The collection a driver path names. The views open top-level collections\n * only; a subcollection path has no tool to read it.\n */\nfunction collectionArg(path: string): string {\n if (path.includes(\"/\")) throw new Error(`\"${path}\" is a subcollection, which this view cannot open.`);\n return path;\n}\n\n/** A read's arguments, as the read tools take them. */\nfunction readArgs(props: FetchCollectionProps): Record<string, unknown> {\n const where = props.filter ? wireFilter(props.filter, props.collection) : undefined;\n const orderBy = wireOrderBy(props, props.collection);\n return {\n ...(where && Object.keys(where).length > 0 && { where }),\n ...(orderBy && { orderBy }),\n ...(props.searchString && { searchString: props.searchString }),\n ...(props.limit !== undefined && { limit: Math.min(props.limit, MAX_LIMIT) }),\n ...(props.offset && { offset: props.offset }),\n ...(props.withDeleted !== undefined && props.withDeleted !== false && {\n deleted: props.withDeleted === \"only\" ? \"only\" : \"include\"\n })\n };\n}\n\n/** What the read tools cannot express, refused rather than read wider than asked. */\nfunction refuseUnsupported(options: { logical?: unknown; vectorSearch?: unknown }): void {\n if (options.logical) throw new Error(\"This view's tools cannot filter by an or()/and() group.\");\n if (options.vectorSearch) throw new Error(\"This view's tools cannot run a vector search.\");\n}\n\n/**\n * Which rows a read asks for, as one comparable string: the same rows however\n * the read was written — a sort as `\"field:desc\"` or `[[\"field\", \"desc\"]]`, a\n * filter's fields in any order, no offset or offset 0. How many is\n * {@link limitOf}'s.\n */\nfunction readKey(args: Record<string, unknown>): string {\n const where = isRecord(args.where) ? args.where : {};\n return JSON.stringify([\n Object.keys(where).sort().map(key => [key, where[key]]),\n sortOf(args.orderBy),\n typeof args.searchString === \"string\" ? args.searchString : \"\",\n typeof args.offset === \"number\" ? args.offset : 0,\n typeof args.deleted === \"string\" ? args.deleted : null\n ]);\n}\n\nfunction limitOf(args: Record<string, unknown>): number | undefined {\n return typeof args.limit === \"number\" ? args.limit : undefined;\n}\n\nfunction sortOf(orderBy: unknown): unknown[] {\n if (typeof orderBy === \"string\" && orderBy !== \"\") {\n const [field, direction] = orderBy.split(\":\");\n return [[field, direction === \"desc\" ? \"desc\" : \"asc\"]];\n }\n if (!Array.isArray(orderBy) || orderBy.length === 0) return [];\n const entries: unknown[] = Array.isArray(orderBy[0]) ? orderBy : [orderBy];\n return entries.map(entry => Array.isArray(entry) ? [entry[0], entry[1] === \"desc\" ? \"desc\" : \"asc\"] : entry);\n}\n\nfunction pickRead(args: Record<string, unknown>, names: readonly string[]): Record<string, unknown> {\n return Object.fromEntries(Object.entries(args).filter(([name]) => names.includes(name)));\n}\n\n/**\n * The admin panel's filter as the read tools' `where`: a belongsTo is\n * filtered by its foreign key there, and a value is the wire's — a relation\n * its id, a date its ISO text.\n */\nfunction wireFilter(filter: Record<string, unknown>, collection: CollectionConfig | undefined): Record<string, unknown> {\n const keys = foreignKeys(collection);\n const where: Record<string, unknown> = {};\n for (const [key, condition] of Object.entries(filter)) {\n if (condition === undefined) continue;\n // A condition is `[op, value]`, each part converted as a row's value is.\n where[keys.get(key) ?? key] = toWireRow({ condition }, NO_CONFIG).condition;\n }\n return where;\n}\n\n/** No properties, so {@link toWireRow} converts each value by what it is: a relation to its id, a date to ISO text. */\nconst NO_CONFIG: CollectionConfig = { slug: \"\", name: \"\", properties: {} };\n\nfunction wireOrderBy(props: FetchCollectionProps, collection: CollectionConfig | undefined): string | unknown[] | undefined {\n const keys = foreignKeys(collection);\n if (typeof props.orderBy === \"string\") {\n const field = keys.get(props.orderBy) ?? props.orderBy;\n return props.order ? `${field}:${props.order}` : field;\n }\n if (Array.isArray(props.orderBy) && props.orderBy.length > 0) {\n return props.orderBy.map(entry => Array.isArray(entry) && typeof entry[0] === \"string\"\n ? [keys.get(entry[0]) ?? entry[0], ...entry.slice(1)]\n : entry);\n }\n return undefined;\n}\n\n/** A collection's belongsTo relations, by name → the foreign key its rows carry. */\nfunction foreignKeys(collection: CollectionConfig | undefined): Map<string, string> {\n const keys = new Map<string, string>();\n if (!collection) return keys;\n try {\n for (const [name, relation] of Object.entries(resolveCollectionRelations(collection))) {\n if (relation.kind === \"belongsTo\" && relation.localKey) {\n keys.set(name, fieldKeyForColumn(collection, relation.localKey));\n }\n }\n } catch {\n // A relation whose target is not in this view: no key to rename.\n }\n return keys;\n}\n\n/** A write's plan and token, where its first call answered one (the server's `confirmation.ts`). */\nfunction planOf(answer: unknown): { token: string; plan: WritePlan } | undefined {\n if (!isRecord(answer) || answer.status !== \"confirmation_required\" || typeof answer.confirm !== \"string\") return undefined;\n const plan = isRecord(answer.plan) ? answer.plan : {};\n return {\n token: answer.confirm,\n plan: {\n summary: typeof plan.summary === \"string\" ? plan.summary : \"Save this change?\",\n ...(Array.isArray(plan.effects) && { effects: plan.effects.filter((line): line is string => typeof line === \"string\") }),\n ...(typeof plan.reversible === \"string\" && { reversible: plan.reversible })\n }\n };\n}\n\n/** A result with no `structuredContent`: its text, as JSON where it is JSON. */\nfunction parseText(result: ToolResult): unknown {\n const text = textOf(result);\n if (text === undefined) return undefined;\n // The server fences rows as untrusted data; the JSON is inside the fence.\n const start = text.indexOf(\"{\");\n const end = text.lastIndexOf(\"}\");\n if (start < 0 || end < start) return undefined;\n try {\n return JSON.parse(text.slice(start, end + 1));\n } catch {\n return undefined;\n }\n}\n\nexport function textOf(result: ToolResult): string | undefined {\n return result.content?.find(block => typeof block.text === \"string\")?.text;\n}\n\n/** What the model is told the person changed here, sent with their next message. */\nexport function describeChanges(changes: readonly ViewChange[]): string {\n const lines = changes.map(change => change.action === \"updated\"\n ? `updated ${change.fields?.join(\", \") || \"fields\"} on row ${change.id} of ${change.collection}`\n : `${change.action} row ${change.id} of ${change.collection}`);\n return `In the Rebase view, the user saved these changes: ${lines.join(\"; \")}. `\n + \"Rows you read before them may be out of date.\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgFA,IAAa,kBAA+B;CACxC,MAAM;EAAE,MAAM;EAAoB,WAAW,CAAC;CAAE;CAChD,KAAK;EAAE,MAAM;EAAgB,WAAW,CAAC;CAAE;CAC3C,OAAO;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CAChD,QAAQ;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CACjD,QAAQ;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CACjD,QAAQ;EAAE,MAAM;EAAmB,WAAW,CAAC;CAAE;CACjD,WAAW;EAAE,MAAM;EAAuB,WAAW,CAAC;CAAE;AAC5D;;AAoFA,IAAa,qBAAb,cAAwC,MAAM;CAC1C,cAAc;EACV,MAAM,0CAA0C;EAChD,KAAK,OAAO;CAChB;AACJ;;AAGA,IAAM,YAAY;;;;;;;;;AAUlB,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,SAAwC;CACrE,MAAM,EAAE,UAAU,SAAS,SAAS,aAAa;CACjD,MAAM,WAAW,QAAQ,qBAAqB,KAAA;CAC9C,MAAM,aAAa,eAAuB,SAAS,UAAU,CAAC,EAAE,QAAQ;CAExE,IAAI,QAAQ,CAAC,GAAI,QAAQ,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