@rebasepro/cms 0.30.1 → 0.31.0-canary.g902a0ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/collection_editor/ConfigControllerProvider.js +25 -22
- package/dist/collection_editor/ConfigControllerProvider.js.map +1 -1
- package/dist/collection_editor/firestore_callee.d.ts +10 -0
- package/dist/collection_editor/firestore_callee.js +15 -0
- package/dist/collection_editor/firestore_callee.js.map +1 -0
- package/dist/collection_editor/firestore_edit.d.ts +62 -0
- package/dist/collection_editor/firestore_edit.js +339 -0
- package/dist/collection_editor/firestore_edit.js.map +1 -0
- package/dist/collection_editor/index.d.ts +2 -3
- package/dist/collection_editor/liveSchemaClient.d.ts +44 -22
- package/dist/collection_editor/liveSchemaClient.js +9 -3
- package/dist/collection_editor/liveSchemaClient.js.map +1 -1
- package/dist/collection_editor/property_column.d.ts +86 -0
- package/dist/collection_editor/property_column.js +719 -0
- package/dist/collection_editor/property_column.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +2 -24
- package/dist/collection_editor/serializable_utils.d.ts +1 -1
- package/dist/collection_editor/serializable_utils.js +2 -1
- package/dist/collection_editor/serializable_utils.js.map +1 -1
- package/dist/collection_editor/split_edit.d.ts +106 -0
- package/dist/collection_editor/split_edit.js +564 -0
- package/dist/collection_editor/split_edit.js.map +1 -0
- package/dist/collection_editor/split_edit_error.d.ts +25 -0
- package/dist/collection_editor/split_edit_error.js +35 -0
- package/dist/collection_editor/split_edit_error.js.map +1 -0
- package/dist/collection_editor/types/collection_editor_controller.d.ts +1 -1
- package/dist/collection_editor/types/config_controller.d.ts +67 -1
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.d.ts +6 -5
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js +44 -12
- package/dist/collection_editor/ui/collection_editor/CollectionEditorDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js +18 -3
- package/dist/collection_editor/ui/collection_editor/CollectionPropertiesEditorForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js +94 -55
- package/dist/collection_editor/ui/collection_editor/CollectionRLSTab.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/CollectionRelationsTab.d.ts +2 -1
- package/dist/collection_editor/ui/collection_editor/DisplaySettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js +3 -3
- package/dist/collection_editor/ui/collection_editor/GeneralSettingsForm.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/KanbanConfigSection.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.d.ts +2 -3
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyEditView.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyFieldPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/PropertyTree.d.ts +7 -4
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js +15 -5
- package/dist/collection_editor/ui/collection_editor/PropertyTree.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaChangeDialog.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.d.ts +20 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js +74 -0
- package/dist/collection_editor/ui/collection_editor/SchemaEditRefusalView.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportMapping.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/import/clean_import_data.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/BlockPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/DateTimePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MapPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/ReferencePropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RelationPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/RepeatPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/ConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/EnumConditionsEditor.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/conditions/property_paths.d.ts +1 -1
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.d.ts +34 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js +50 -0
- package/dist/collection_editor/ui/collection_editor/rlsRuleForm.js.map +1 -0
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.d.ts +1 -2
- package/dist/collection_editor/ui/collection_editor/utils/update_property_for_widget.js.map +1 -1
- package/dist/collection_editor/useDetachRulesConfirmation.d.ts +16 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js +48 -0
- package/dist/collection_editor/useDetachRulesConfirmation.js.map +1 -0
- package/dist/collection_editor/useLiveSchemaEditing.d.ts +2 -2
- package/dist/collection_editor/useLiveSchemaEditing.js +1 -1
- package/dist/collection_editor/useLiveSchemaEditing.js.map +1 -1
- package/dist/collection_editor/useLocalCollectionsConfigController.d.ts +54 -10
- package/dist/collection_editor/useLocalCollectionsConfigController.js +394 -122
- package/dist/collection_editor/useLocalCollectionsConfigController.js.map +1 -1
- package/dist/collection_editor/validateCollectionJson.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +10 -9
- package/dist/components/CollectionPanel.js +5 -2
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +1 -2
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +3 -5
- package/dist/components/CollectionTableBinding/PropertyTableCell.d.ts +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +1 -1
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.d.ts +2 -2
- 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.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +1 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.d.ts +2 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationSelectorField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.d.ts +2 -2
- package/dist/components/CollectionTableBinding/fields/TableStorageUpload.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.d.ts +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js +1 -1
- package/dist/components/CollectionTableBinding/fields/VirtualTableSelect.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +1 -2
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.d.ts +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +2 -2
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionTableBinding/table_bindings.d.ts +2 -2
- package/dist/components/CollectionTableBinding/table_bindings.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -5
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +2 -4
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +6 -6
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +1 -2
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +1 -2
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntitiesCount.js +3 -3
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +1 -2
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js +1 -1
- package/dist/components/CollectionViewBinding/FilterPresetsButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +1 -2
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.d.ts +1 -1
- package/dist/components/CollectionViewBinding/FiltersDialog.js.map +1 -1
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +1 -2
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/RowActions.d.ts +1 -2
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/SortButton.d.ts +1 -1
- package/dist/components/CollectionViewBinding/SortButton.js.map +1 -1
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +1 -2
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js +1 -1
- package/dist/components/CollectionViewBinding/hooks/useCollectionInlineEditor.js.map +1 -1
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.d.ts +1 -2
- package/dist/components/CollectionViewBinding/hooks/useKanbanDragAndDrop.js.map +1 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.d.ts +2 -1
- package/dist/components/CollectionViewBinding/useBoardDataController.js +3 -3
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +2 -4
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +14 -19
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -1
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +1 -3
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +1 -2
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +23 -8
- package/dist/components/CollectionsProvider.js +23 -7
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/DefaultDrawer.js +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +1 -1
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +3 -3
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -1
- package/dist/components/EditViewBinding.js +6 -6
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.d.ts +1 -2
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityInspector.d.ts +1 -2
- package/dist/components/EntityInspector.js.map +1 -1
- package/dist/components/EntityPreviewBinding.d.ts +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +1 -1
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +1 -1
- package/dist/components/EntityViewBody.js +3 -4
- package/dist/components/EntityViewBody.js.map +1 -1
- package/dist/components/FieldValue.js +2 -2
- package/dist/components/FieldValue.js.map +1 -1
- package/dist/components/HomePage/ContentHomePage.js +12 -3
- package/dist/components/HomePage/ContentHomePage.js.map +1 -1
- package/dist/components/InlineEntityPreview.d.ts +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PropertyCollectionView.d.ts +2 -2
- package/dist/components/PropertyCollectionView.js.map +1 -1
- package/dist/components/PropertyConfigBadge.js.map +1 -1
- package/dist/components/RebaseCMS.d.ts +22 -3
- package/dist/components/RebaseCMS.js +32 -14
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +106 -31
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RecordDetail.js +4 -1
- package/dist/components/RecordDetail.js.map +1 -1
- package/dist/components/RecordForm.d.ts +5 -5
- package/dist/components/RecordForm.js +5 -2
- package/dist/components/RecordForm.js.map +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +2 -2
- package/dist/components/ReferenceTable/SelectionTableBinding.js +1 -1
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +2 -1
- package/dist/components/ReferenceWidget.js +2 -2
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.d.ts +2 -1
- package/dist/components/RelationSelector.js +2 -3
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.d.ts +2 -2
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.d.ts +2 -1
- package/dist/components/SelectableTable/filters/FilterFieldBinding.js +3 -3
- package/dist/components/SelectableTable/filters/FilterFieldBinding.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/SelectableTable/filters/RelationFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js +1 -1
- package/dist/components/SelectableTable/filters/RelationFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.d.ts +1 -1
- package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
- package/dist/components/SelectableTable/filters/null_filter.d.ts +1 -3
- package/dist/components/SelectableTable/filters/null_filter.js.map +1 -1
- package/dist/components/SidePanelBinding.js +1 -1
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/field_configs.d.ts +1 -2
- package/dist/components/field_configs.js.map +1 -1
- package/dist/components/field_ids.d.ts +1 -1
- package/dist/components/field_ids.js +1 -1
- package/dist/components/field_ids.js.map +1 -1
- package/dist/components/history/EntityHistoryEntry.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +1 -2
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/data_export/export/BasicExportAction.d.ts +1 -1
- package/dist/data_export/export/BasicExportAction.js.map +1 -1
- package/dist/data_export/export/ExportCollectionAction.js +2 -2
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +1 -1
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_export/export/export.d.ts +1 -1
- package/dist/data_export/export/export.js +1 -1
- package/dist/data_export/export/export.js.map +1 -1
- package/dist/data_export/export/fetch_export_data.d.ts +3 -2
- package/dist/data_export/export/fetch_export_data.js.map +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.d.ts +1 -1
- package/dist/data_import/components/DataNewPropertiesMapping.js.map +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.d.ts +1 -1
- package/dist/data_import/components/ImportNewPropertyFieldPreview.js.map +1 -1
- package/dist/data_import/hooks/useImportConfig.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.d.ts +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/data_import/types/column_mapping.d.ts +1 -1
- package/dist/data_import/utils/data.d.ts +1 -2
- package/dist/data_import/utils/data.js +1 -2
- package/dist/data_import/utils/data.js.map +1 -1
- package/dist/data_import/utils/get_import_inference_type.d.ts +1 -1
- package/dist/data_import/utils/get_import_inference_type.js.map +1 -1
- package/dist/data_import/utils/id_column.d.ts +1 -1
- package/dist/data_import/utils/id_column.js.map +1 -1
- package/dist/data_import/utils/import_columns.d.ts +1 -1
- package/dist/data_import/utils/import_columns.js.map +1 -1
- package/dist/data_import/utils/save_entities.d.ts +3 -3
- package/dist/data_import/utils/save_entities.js +1 -1
- package/dist/data_import/utils/save_entities.js.map +1 -1
- package/dist/form/EntityForm.js +2 -1
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.js +2 -2
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormFieldsContext.d.ts +1 -4
- package/dist/form/FormFieldsContext.js +1 -1
- package/dist/form/FormFieldsContext.js.map +1 -1
- package/dist/form/PropertyFieldBinding.js +6 -8
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/components/FieldBlock.d.ts +1 -2
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FieldHelperText.d.ts +1 -1
- package/dist/form/components/FieldHelperText.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +1 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/LocalChangesMenu.d.ts +1 -1
- package/dist/form/components/LocalChangesMenu.js.map +1 -1
- package/dist/form/components/StorageItemPreview.d.ts +1 -1
- package/dist/form/components/StorageItemPreview.js.map +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js +1 -1
- package/dist/form/field_bindings/ArrayCustomShapedFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BinaryFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js +1 -1
- package/dist/form/field_bindings/BlockFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/DateTimeFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/GeopointFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/KeyValueFieldBinding.js +1 -2
- package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MapFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +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/MultiSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/MultiSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.d.ts +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.d.ts +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.d.ts +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.d.ts +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/RepeatFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js +1 -1
- package/dist/form/field_bindings/RepeatFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js +1 -1
- package/dist/form/field_bindings/SelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +2 -2
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/SwitchFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/TextFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/UserSelectFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/VectorFieldBinding.js.map +1 -1
- package/dist/form/form_utils.d.ts +3 -3
- package/dist/form/form_utils.js +1 -2
- package/dist/form/form_utils.js.map +1 -1
- package/dist/form/label_placement.d.ts +1 -2
- package/dist/form/label_placement.js.map +1 -1
- package/dist/form/resolve_cell_property.d.ts +1 -2
- package/dist/form/resolve_cell_property.js +1 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/form/resolve_form_properties.d.ts +2 -2
- package/dist/form/resolve_form_properties.js +1 -1
- package/dist/form/resolve_form_properties.js.map +1 -1
- package/dist/form/useClearRestoreValue.d.ts +1 -1
- package/dist/form/useClearRestoreValue.js.map +1 -1
- package/dist/form/validation.d.ts +2 -2
- package/dist/form/validation.js +1 -1
- package/dist/form/validation.js.map +1 -1
- package/dist/hooks/navigation/compose_collections.d.ts +59 -0
- package/dist/hooks/navigation/compose_collections.js +48 -0
- package/dist/hooks/navigation/compose_collections.js.map +1 -0
- package/dist/hooks/navigation/compose_collections_input.d.ts +8 -0
- package/dist/hooks/navigation/compose_collections_input.js +17 -0
- package/dist/hooks/navigation/compose_collections_input.js.map +1 -0
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.d.ts +1 -1
- package/dist/hooks/navigation/contexts/CollectionRegistryContext.js.map +1 -1
- package/dist/hooks/navigation/registered_collection.d.ts +15 -0
- package/dist/hooks/navigation/registered_collection.js +20 -0
- package/dist/hooks/navigation/registered_collection.js.map +1 -0
- package/dist/hooks/navigation/ui_preferences.d.ts +47 -0
- package/dist/hooks/navigation/ui_preferences.js +179 -0
- package/dist/hooks/navigation/ui_preferences.js.map +1 -0
- package/dist/hooks/navigation/useAsyncResolver.d.ts +8 -1
- package/dist/hooks/navigation/useAsyncResolver.js +9 -3
- package/dist/hooks/navigation/useAsyncResolver.js.map +1 -1
- package/dist/hooks/navigation/useBuildCollectionRegistryController.d.ts +1 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js +3 -3
- package/dist/hooks/navigation/useBuildCollectionRegistryController.js.map +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +9 -5
- package/dist/hooks/navigation/useBuildNavigationStateController.js +2 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useBuildUrlController.d.ts +1 -1
- package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.js +1 -2
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/usePanelTables.d.ts +11 -0
- package/dist/hooks/navigation/usePanelTables.js +33 -0
- package/dist/hooks/navigation/usePanelTables.js.map +1 -0
- package/dist/hooks/navigation/useResolvedCollections.d.ts +8 -3
- package/dist/hooks/navigation/useResolvedCollections.js +3 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +1 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/navigation/useTopLevelNavigation.d.ts +1 -2
- package/dist/hooks/navigation/useTopLevelNavigation.js.map +1 -1
- package/dist/hooks/navigation/user_preferences_overlay.d.ts +21 -0
- package/dist/hooks/navigation/user_preferences_overlay.js +101 -0
- package/dist/hooks/navigation/user_preferences_overlay.js.map +1 -0
- package/dist/hooks/navigation/utils.js +1 -1
- package/dist/hooks/navigation/utils.js.map +1 -1
- package/dist/hooks/useAdminContext.d.ts +1 -2
- package/dist/hooks/useAdminContext.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.d.ts +1 -2
- package/dist/hooks/useBuildSidePanel.js +2 -1
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useChildViewSource.d.ts +1 -1
- package/dist/hooks/useChildViewSource.js +1 -1
- package/dist/hooks/useChildViewSource.js.map +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +1 -2
- package/dist/hooks/useEntityDisplay.js +1 -1
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useEntityDisplayTitle.d.ts +2 -2
- package/dist/hooks/useEntityDisplayTitle.js.map +1 -1
- package/dist/hooks/useHistory.js +1 -1
- package/dist/hooks/useHistory.js.map +1 -1
- package/dist/hooks/useRecordActions.d.ts +1 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useReferencePaths.d.ts +21 -7
- package/dist/hooks/useReferencePaths.js +23 -6
- package/dist/hooks/useReferencePaths.js.map +1 -1
- package/dist/hooks/useResolvedNavigationFrom.d.ts +3 -3
- package/dist/hooks/useResolvedNavigationFrom.js +1 -1
- package/dist/hooks/useResolvedNavigationFrom.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -2
- package/dist/mcp_view/app_modules.d.ts +2 -2
- package/dist/mcp_view/app_modules.js +4 -4
- package/dist/mcp_view/app_modules.js.map +1 -1
- package/dist/mcp_view/index.d.ts +16 -19
- package/dist/mcp_view/index.js +43 -62
- package/dist/mcp_view/index.js.map +1 -1
- package/dist/mcp_view/payload.d.ts +54 -18
- package/dist/mcp_view/payload.js +49 -24
- package/dist/mcp_view/payload.js.map +1 -1
- package/dist/mcp_view/screen.js +11 -11
- package/dist/mcp_view/screen.js.map +1 -1
- package/dist/mcp_view/tool_driver.d.ts +5 -34
- package/dist/mcp_view/tool_driver.js +17 -16
- package/dist/mcp_view/tool_driver.js.map +1 -1
- package/dist/mcp_view/write_review.d.ts +1 -2
- package/dist/mcp_view/write_review.js +1 -1
- package/dist/mcp_view/write_review.js.map +1 -1
- package/dist/preview/PropertyPreview.d.ts +1 -1
- package/dist/preview/PropertyPreview.js +4 -3
- package/dist/preview/PropertyPreview.js.map +1 -1
- package/dist/preview/components/ArrayEnumPreview.d.ts +1 -1
- package/dist/preview/components/ArrayEnumPreview.js.map +1 -1
- package/dist/preview/components/BooleanPreview.d.ts +1 -1
- package/dist/preview/components/BooleanPreview.js.map +1 -1
- package/dist/preview/components/EnumValuesChip.d.ts +1 -1
- package/dist/preview/components/EnumValuesChip.js +1 -1
- package/dist/preview/components/EnumValuesChip.js.map +1 -1
- package/dist/preview/components/ReferencePreview.d.ts +1 -1
- package/dist/preview/components/ReferencePreview.js.map +1 -1
- package/dist/preview/components/RelationPreview.d.ts +1 -1
- package/dist/preview/components/RelationPreview.js.map +1 -1
- package/dist/preview/components/StorageThumbnail.js +2 -1
- package/dist/preview/components/StorageThumbnail.js.map +1 -1
- package/dist/preview/components/UserPreview.d.ts +1 -1
- package/dist/preview/components/UserPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfMapsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfReferencesPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js +2 -1
- package/dist/preview/property_previews/ArrayOfRelationsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStorageComponentsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyEnumPreview.js.map +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js +1 -1
- package/dist/preview/property_previews/NumberPropertyPreview.js.map +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.d.ts +1 -1
- package/dist/preview/property_previews/SkeletonPropertyComponent.js.map +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.js.map +1 -1
- package/dist/preview/util.d.ts +1 -1
- package/dist/preview/util.js.map +1 -1
- package/dist/routes/RebaseRoute.js +2 -2
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/saved_apps/SavedAppsView.d.ts +1 -1
- package/dist/saved_apps/SavedAppsView.js +1 -1
- package/dist/saved_apps/SavedAppsView.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +1 -1
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/resolve_selection.d.ts +3 -3
- package/dist/selection/resolve_selection.js +3 -2
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/tables/apply_customization.d.ts +65 -0
- package/dist/tables/apply_customization.js +644 -0
- package/dist/tables/apply_customization.js.map +1 -0
- package/dist/tables/column_property.d.ts +64 -0
- package/dist/tables/column_property.js +549 -0
- package/dist/tables/column_property.js.map +1 -0
- package/dist/tables/customize_table.d.ts +39 -0
- package/dist/tables/customize_table.js +247 -0
- package/dist/tables/customize_table.js.map +1 -0
- package/dist/tables/index.d.ts +12 -0
- package/dist/tables/labels.d.ts +18 -0
- package/dist/tables/labels.js +18 -0
- package/dist/tables/labels.js.map +1 -0
- package/dist/tables/project_table.d.ts +79 -0
- package/dist/tables/project_table.js +148 -0
- package/dist/tables/project_table.js.map +1 -0
- package/dist/tables/relations.d.ts +47 -0
- package/dist/tables/relations.js +112 -0
- package/dist/tables/relations.js.map +1 -0
- package/dist/tables/rls.d.ts +39 -0
- package/dist/tables/rls.js +111 -0
- package/dist/tables/rls.js.map +1 -0
- package/dist/tables/update_record.d.ts +32 -0
- package/dist/tables/update_record.js +40 -0
- package/dist/tables/update_record.js.map +1 -0
- package/dist/types/components/EntityFormActionsProps.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +2 -2
- package/dist/types/fields.d.ts +2 -2
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/entity_pages.d.ts +2 -1
- package/dist/util/entity_pages.js.map +1 -1
- package/dist/util/find_entities_by_ids.d.ts +2 -2
- package/dist/util/find_entities_by_ids.js +1 -1
- package/dist/util/find_entities_by_ids.js.map +1 -1
- package/dist/util/format_collection_date.d.ts +1 -1
- package/dist/util/format_collection_date.js.map +1 -1
- package/dist/util/identity.d.ts +8 -0
- package/dist/util/identity.js +16 -0
- package/dist/util/identity.js.map +1 -0
- package/dist/util/navigation_utils.js +1 -1
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/previews.js +1 -1
- package/dist/util/previews.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +1 -1
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/dist/util/property_utils.d.ts +1 -3
- package/dist/util/property_utils.js +1 -1
- package/dist/util/property_utils.js.map +1 -1
- package/dist/util/relations.d.ts +18 -0
- package/dist/util/relations.js +32 -0
- package/dist/util/relations.js.map +1 -0
- package/package.json +12 -10
- package/recipes/README.md +4 -4
- package/recipes/my-preferences.tsx +34 -26
- package/recipes/site-settings.tsx +34 -27
- package/dist/collection_editor/collection_wire.d.ts +0 -13
- package/dist/collection_editor/collection_wire.js +0 -49
- package/dist/collection_editor/collection_wire.js.map +0 -1
- package/dist/collection_editor/useJsonCollectionsConfigController.d.ts +0 -37
- package/dist/collection_editor/useJsonCollectionsConfigController.js +0 -191
- package/dist/collection_editor/useJsonCollectionsConfigController.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","names":[],"sources":["../../../src/data_import/utils/data.ts"],"sourcesContent":["import { getPropertyInPath } from \"../../util\";\nimport { ArrayProperty, DataType, Entity, EntityReference, CollectionRegistryController, GeoPoint, Properties, Property, Vector } from \"@rebasepro/types\";\nimport { AuthController, AdminCollection } from \"@rebasepro/cms-types\";\nimport { isPropertyBuilder } from \"@rebasepro/common\";\nimport { unflattenObject } from \"./transforms\";\nimport { ColumnTarget, importColumns } from \"./import_columns\";\nimport { inferTypeFromValue, readNumberExactly } from \"@rebasepro/inference\";\nimport { mergeDeep } from \"@rebasepro/utils\";\n\n/** What the conversion asks of the collection registry: the collection a reference points into. */\nexport type ImportCollectionLookup = Pick<CollectionRegistryController, \"getCollection\">;\n\n/**\n * Why a cell could not be converted to its property's type. Each one is a\n * translation key under `import_problem_`.\n */\nexport type ImportProblemReason =\n | \"not_a_number\"\n | \"number_leading_zero\"\n | \"number_too_precise\"\n | \"not_a_boolean\"\n | \"not_a_date\"\n | \"ambiguous_date\"\n | \"not_a_vector\"\n | \"not_a_map\"\n | \"not_a_geopoint\";\n\n/**\n * A cell the import could not convert to the type of the property it maps\n * to. It is left out of the row — the property's default applies — and shown\n * to the person importing before anything is written.\n */\nexport type ImportConversionProblem = {\n /** The row's index among the file's data rows, from 0. */\n row: number;\n /** The column, as the file names it. */\n column: string;\n /** The property the column maps to. */\n property: string;\n /** The type that property holds. */\n expected: DataType;\n /** The cell, as it was read from the file. */\n value: unknown;\n reason: ImportProblemReason;\n};\n\n/** Reports one cell that did not convert; the cell is then left out. */\nexport type ImportProblemListener = (problem: { reason: ImportProblemReason }) => void;\n\n/**\n * How a column writes the dates whose day and month are both numbers\n * (`05/01/2024`): day first, month first, or — when the column holds both —\n * each date by the only order that can read it.\n */\nexport type SlashDateOrder = \"dmy\" | \"mdy\" | \"each\";\n\n/**\n * Convert every row of an imported file, and list each cell that did not\n * convert. The previews call this, so the list is in front of the person\n * importing before the first row is written.\n */\nexport function convertImportData(authController: AuthController,\n navigation: ImportCollectionLookup,\n data: object[],\n idColumn: string | undefined,\n headersMapping: Record<string, string | null>,\n properties: Properties,\n path: string,\n defaultValues: Record<string, any>): { entities: Entity<any>[], problems: ImportConversionProblem[] } {\n const problems: ImportConversionProblem[] = [];\n const dateOrders = slashDateOrdersByColumn(data, properties, mappedColumnTarget(headersMapping));\n const entities = data.map((row, index) => convertDataToEntity(authController, navigation,\n row as Record<string, unknown>, idColumn, headersMapping, properties, path, defaultValues,\n (problem) => problems.push({ row: index, ...problem }),\n dateOrders));\n return { entities, problems };\n}\n\nexport function convertDataToEntity(authController: AuthController,\n navigation: ImportCollectionLookup,\n data: Record<any, any>,\n idColumn: string | undefined,\n headersMapping: Record<string, string | null>,\n properties: Properties,\n path: string,\n defaultValues: Record<string, any>,\n onProblem?: (problem: Omit<ImportConversionProblem, \"row\">) => void,\n dateOrders?: Record<string, SlashDateOrder | undefined>): Entity<any> {\n const flatObject = flattenEntry(data, properties, mappedColumnTarget(headersMapping));\n if (idColumn)\n delete flatObject[idColumn];\n // One accumulator, written in place: spreading it once per column made\n // converting a row quadratic in its column count. No prototype, so a\n // `__proto__` key is a key here; `unflattenObject` refuses it below.\n const mappedKeysObject: Record<string, unknown> = Object.create(null);\n for (const [key, value] of Object.entries(flatObject)) {\n // The mapping is keyed by the column's flat name — `address.street`\n // is one key, not a path — and `null` is \"Do not import this\n // property\". A column the mapping does not mention keeps its name.\n const mappedKey = Object.prototype.hasOwnProperty.call(headersMapping, key)\n ? headersMapping[key]\n : key;\n if (mappedKey === null) {\n continue;\n }\n // A blank cell is a value nobody filled in, not an empty one: it\n // sets nothing, so the default chosen for the property applies. An\n // empty spreadsheet cell already arrives without a key.\n if (value === \"\") {\n continue;\n }\n\n const mappedProperty = getPropertyInPath(properties, mappedKey);\n // `getPropertyInPath` answers `in`, so a `toString` column finds\n // `Object.prototype.toString`: a declared property is an object.\n if (!mappedProperty || typeof mappedProperty !== \"object\") {\n continue;\n }\n let reason: ImportProblemReason | undefined;\n const processedValue = processValueMapping(authController, value, navigation, mappedProperty,\n (problem) => { reason ??= problem.reason; },\n dateOrders && Object.hasOwn(dateOrders, key) ? dateOrders[key] : undefined);\n // A cell that did not convert is not imported as `null`, `0` or\n // `false` in its place: it is left out, and reported.\n if (reason !== undefined) {\n onProblem?.({ column: key, property: mappedKey, expected: mappedProperty.type, value, reason });\n continue;\n }\n mappedKeysObject[mappedKey] = processedValue;\n }\n\n const values = mergeDeep(defaultValues ?? {}, unflattenObject(mappedKeysObject));\n let id = idColumn ? data[idColumn] : undefined;\n if (typeof id === \"string\") {\n id = id.trim();\n } else if (typeof id === \"number\") {\n id = id.toString();\n } else if (typeof id === \"boolean\") {\n id = id.toString();\n } else if (id instanceof Date) {\n id = id.toISOString();\n } else if (id && \"toString\" in id) {\n id = id.toString();\n }\n\n return {\n id,\n values,\n path: path\n };\n}\n\n/**\n * Where a column lands under the import's mapping: the property the mapping\n * names for it, `null` for \"Do not import this property\", and the property\n * with the column's own name when the mapping does not mention the column.\n */\nexport function mappedColumnTarget(headersMapping: Record<string, string | null>): ColumnTarget {\n return (column) => Object.hasOwn(headersMapping, column) ? headersMapping[column] : column;\n}\n\n/**\n * The cells of one imported row by column name (`address.street`): each\n * value that is not split into columns of its own (see `importColumns`).\n * Without `properties`, every object is split.\n */\nexport function flattenEntry(obj: Record<string, unknown>,\n properties?: Properties,\n targetOf: ColumnTarget = (column) => column): Record<string, unknown> {\n const cells: Record<string, unknown> = {};\n for (const { column, value, split } of importColumns(obj, properties, targetOf)) {\n if (!split) cells[column] = value;\n }\n return cells;\n}\n\n/**\n * Convert one cell to the type of the property it lands in.\n *\n * A cell is converted only when the property's type can hold what it says:\n * text becomes a number when it spells one exactly (`readNumberExactly`, the\n * same answer the inference uses), a boolean when it says yes or no, a date\n * when it names a day. Anything else is reported to `onProblem`, and the\n * result is `null` — the caller leaves such a cell out rather than writing\n * that `null`, a `0` or a `false` in its place.\n *\n * @param dateOrder how the cell's column writes day/month dates, when it\n * writes them with numbers only (see `slashDateOrdersByColumn`).\n */\nexport function processValueMapping(authController: AuthController,\n value: any,\n navigation: ImportCollectionLookup,\n property?: Property,\n onProblem?: ImportProblemListener,\n dateOrder?: SlashDateOrder): any {\n if (value === null) return null;\n\n if (property === undefined) return value;\n const usedProperty: Property | null = property;\n if (usedProperty === null) return value;\n const from = inferTypeFromValue(value);\n const to = usedProperty.type;\n const refuse = (reason: ImportProblemReason) => {\n onProblem?.({ reason });\n return null;\n };\n\n if (to === \"vector\") {\n let items: unknown[] | undefined;\n if (Array.isArray(value)) {\n items = value;\n } else if (isObjectValue(value)) {\n // A JSON file holds the vector as the object the export wrote.\n if (!Array.isArray(value.value)) return refuse(\"not_a_vector\");\n items = value.value;\n } else if (typeof value === \"string\") {\n let cleaned = value.trim();\n if (cleaned.startsWith(\"{\")) {\n // A CSV cell holds it as that object's JSON, `{\"value\":[…]}`.\n const object = readJsonObjectCell(cleaned);\n if (!object || !Array.isArray(object.value)) return refuse(\"not_a_vector\");\n items = object.value;\n } else {\n if (cleaned.startsWith(\"[\") && cleaned.endsWith(\"]\")) {\n cleaned = cleaned.slice(1, -1);\n }\n if (cleaned === \"\") return null;\n items = cleaned.split(\",\");\n }\n }\n if (items === undefined) return value;\n const numbers = items.map(item => typeof item === \"number\"\n ? item\n : typeof item === \"string\" ? readNumberExactly(item) : undefined);\n // An item that is not a number used to become 0 (or NaN): a vector\n // with a made-up coordinate.\n if (numbers.some(item => item === undefined || !Number.isFinite(item))) return refuse(\"not_a_vector\");\n return new Vector(numbers as number[]);\n }\n\n if (to === \"map\" || to === \"geopoint\") {\n // The export writes a map and a geopoint as the JSON of the object in\n // a CSV cell — and each item of an array of maps the same way — and\n // as the object itself in a JSON file; that is what either reads as.\n // Kept as text, a map was stored as a JSON string and a geopoint\n // refused the whole batch at the server.\n if (typeof value === \"string\" && value.trim() === \"\") return null;\n const object = typeof value === \"string\" ? readJsonObjectCell(value) : isObjectValue(value) ? value : undefined;\n if (usedProperty.type === \"geopoint\") {\n const { latitude, longitude } = object ?? {};\n return typeof latitude === \"number\" && typeof longitude === \"number\"\n && Math.abs(latitude) <= 90 && Math.abs(longitude) <= 180\n ? new GeoPoint(latitude, longitude)\n : refuse(\"not_a_geopoint\");\n }\n if (!object) return refuse(\"not_a_map\");\n if (usedProperty.type !== \"map\" || !usedProperty.properties) return object;\n // A map that arrives whole — an item of an array of maps — has its\n // declared fields converted like the columns of a row: its dates\n // were left as the text or epoch number the export wrote.\n const fields: Record<string, unknown> = { ...object };\n for (const [key, fieldProperty] of Object.entries(usedProperty.properties)) {\n if (!Object.hasOwn(object, key) || isPropertyBuilder(fieldProperty)) continue;\n fields[key] = processValueMapping(authController, object[key], navigation, fieldProperty, onProblem, dateOrder);\n }\n return fields;\n }\n\n if (from === \"string\" && to === \"array\" && typeof value === \"string\") {\n return processValueMapping(authController, splitListCell(value), navigation, usedProperty, onProblem, dateOrder);\n } else if (from === \"string\" && to === \"boolean\" && typeof value === \"string\") {\n // A blank cell is no value; anything else unreadable is reported.\n if (value.trim() === \"\") return null;\n const read = readBooleanCell(value);\n return read === undefined ? refuse(\"not_a_boolean\") : read;\n } else if (from === \"array\" && to === \"string\") {\n // A CSV cell only arrives as an array when its text was the canonical\n // JSON of one (`mapJsonParse`), so this is that text again.\n return JSON.stringify(value);\n }\n\n if (from === \"array\" && Array.isArray(value) && usedProperty.type === \"array\") {\n const of = usedProperty.of;\n if (usedProperty.oneOf) {\n const oneOf = usedProperty.oneOf;\n return value.map(item => convertBlock(item, oneOf,\n (blockValue, blockProperty) => processValueMapping(authController, blockValue, navigation, blockProperty, onProblem, dateOrder)));\n }\n if (Array.isArray(of)) {\n // A fixed list: each position has a property of its own.\n return value.map((item, index) => index < of.length && !isPropertyBuilder(of[index])\n ? processValueMapping(authController, item, navigation, of[index], onProblem, dateOrder)\n : item);\n }\n if (of && !isPropertyBuilder(of)) {\n return value.map(item => processValueMapping(authController, item, navigation, of, onProblem, dateOrder));\n }\n }\n\n if (from === \"string\" && to === \"number\" && typeof value === \"string\") {\n // A blank cell is no value — not a real zero, which `Number(\"\")` is.\n const trimmed = value.trim();\n if (trimmed === \"\") return null;\n const read = readNumberExactly(trimmed);\n if (read !== undefined) return read;\n return refuse(whyNotANumber(trimmed));\n } else if (from === \"number\" && to === \"boolean\") {\n if (value === 1) return true;\n if (value === 0) return false;\n return refuse(\"not_a_boolean\");\n } else if (from === \"boolean\" && to === \"number\") {\n return value ? 1 : 0;\n } else if (from === \"boolean\" && to === \"string\") {\n return value ? \"true\" : \"false\";\n } else if (from === \"number\" && to === \"string\" && typeof value === \"number\") {\n return value.toString();\n } else if (from === \"string\" && to === \"date\" && typeof value === \"string\") {\n const read = readDateCell(value, dateOrder, isTimeOfDay(usedProperty));\n return read instanceof Date ? read : refuse(read);\n } else if (value instanceof Date && to === \"string\") {\n return value.toISOString();\n } else if (from === \"number\" && to === \"date\" && typeof value === \"number\") {\n const read = dateFromEpoch(value, isTimeOfDay(usedProperty));\n return read ?? refuse(\"not_a_date\");\n } else if (from === \"string\" && to === \"reference\" && typeof value === \"string\") {\n // Parse optional database name in format: database_name:::path/to/entity\n // or simple format: path/to/entity\n let databaseId: string | undefined = undefined;\n let referencePath = value;\n\n if (value.includes(\":::\")) {\n const [dbName, pathPart] = value.split(\":::\");\n if (dbName && dbName !== \"(default)\") {\n databaseId = dbName;\n }\n referencePath = pathPart;\n }\n\n // split value into path and entityId (entityId is the last part of the path, after the last /)\n const path = referencePath.split(\"/\").slice(0, -1).join(\"/\");\n const entityId = referencePath.split(\"/\").slice(-1)[0];\n\n // If no explicit database was provided in the string, try to get it from the collection\n if (databaseId === undefined) {\n const targetCollection: AdminCollection<any> | undefined = navigation.getCollection(path);\n databaseId = targetCollection?.databaseId;\n }\n\n return new EntityReference({ id: entityId,\npath,\ndatabaseId });\n\n } else if (from === to) {\n return value;\n }\n\n return value;\n}\n\n/** An object read from a file, as opposed to a list, a date or a primitive. */\nfunction isObjectValue(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) && !(value instanceof Date);\n}\n\n/**\n * One item of a block list (`oneOf`): the object the export wrote — or, in a\n * CSV whose lists were written one cell per item, that object's JSON — with\n * its value converted to the property its type names.\n */\nfunction convertBlock(item: unknown,\n oneOf: NonNullable<ArrayProperty[\"oneOf\"]>,\n convert: (value: unknown, property: Property) => unknown): unknown {\n const block = typeof item === \"string\" ? readJsonObjectCell(item) : isObjectValue(item) ? item : undefined;\n if (!block) return item;\n const typeField = oneOf.typeField ?? \"type\";\n const valueField = oneOf.valueField ?? \"value\";\n const type = block[typeField];\n const blockProperty = typeof type === \"string\" && Object.hasOwn(oneOf.properties, type) ? oneOf.properties[type] : undefined;\n if (!blockProperty || isPropertyBuilder(blockProperty) || !Object.hasOwn(block, valueField)) return block;\n return { ...block, [valueField]: convert(block[valueField], blockProperty) };\n}\n\n/** A cell holding the JSON of an object, read; `undefined` for anything else. */\nfunction readJsonObjectCell(cell: string): Record<string, unknown> | undefined {\n const trimmed = cell.trim();\n if (!trimmed.startsWith(\"{\")) return undefined;\n try {\n const parsed: unknown = JSON.parse(trimmed);\n return parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? parsed as Record<string, unknown>\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The items of a list cell: a JSON array as written (the export writes lists\n * that way), otherwise the text split on commas. Each item is trimmed and an\n * empty one dropped, so `news, sports` is two tags rather than one with a\n * leading space, and a blank cell is no tags rather than one empty tag.\n */\nfunction splitListCell(cell: string): unknown[] {\n const trimmed = cell.trim();\n if (trimmed.startsWith(\"[\")) {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n if (Array.isArray(parsed)) return parsed;\n } catch (e) {\n // Not JSON after all: a list that happens to start with a bracket.\n }\n }\n return trimmed.split(\",\")\n .map(item => item.trim())\n .filter(item => item !== \"\");\n}\n\n/**\n * A boolean cell as spreadsheets and people write it: Excel and Sheets export\n * `TRUE`/`FALSE`, and `yes`/`no` and `1`/`0` are common by hand. Anything\n * unreadable is absent — `null`, as a number cell is — rather than a confident\n * `false`.\n */\nfunction readBooleanCell(cell: string): boolean | undefined {\n const normalised = cell.trim().toLowerCase();\n if ([\"true\", \"1\", \"yes\", \"y\"].includes(normalised)) return true;\n if ([\"false\", \"0\", \"no\", \"n\"].includes(normalised)) return false;\n return undefined;\n}\n\n/** Why a text is not a number `readNumberExactly` accepts. */\nfunction whyNotANumber(text: string): ImportProblemReason {\n // A leading zero is an identifier — a zip code, a product code — and\n // more than 15 significant digits is more than a double holds: `Number()`\n // would read both, and change them.\n if (/^-?0\\d/.test(text) && Number.isFinite(Number(text))) return \"number_leading_zero\";\n if (/^-?\\d+(\\.\\d+)?$/.test(text)) return \"number_too_precise\";\n return \"not_a_number\";\n}\n\n/**\n * Below this, an epoch number is in seconds: 1e11 seconds is the year 5138,\n * and 1e11 milliseconds is March 1973.\n */\nconst EPOCH_SECONDS_BELOW = 1e11;\n\n/** One day, in milliseconds. */\nconst DAY_MS = 86_400_000;\n\n/** Whether a property holds a time of day — a time on 1970-01-01, in UTC. */\nfunction isTimeOfDay(property: Property): boolean {\n return property.type === \"date\" && property.columnType === \"time\";\n}\n\n/**\n * @param timeOfDay the number lands in a time-of-day property. The export\n * writes such a time as the milliseconds since that midnight, a number below\n * one day; read as epoch seconds, 12:30 was a day in 1971 at 20:00.\n */\nfunction dateFromEpoch(epoch: number, timeOfDay = false): Date | undefined {\n if (!Number.isFinite(epoch)) return undefined;\n const inMilliseconds = (timeOfDay && epoch >= 0 && epoch < DAY_MS) || Math.abs(epoch) >= EPOCH_SECONDS_BELOW;\n const date = new Date(inMilliseconds ? epoch : epoch * 1000);\n return isNaN(date.getTime()) ? undefined : date;\n}\n\n/** `05/01/2024`, `5.1.2024`, `05-01-2024`: day and month as numbers, year last. */\nconst SLASH_DATE = /^(\\d{1,2})([/.-])(\\d{1,2})\\2(\\d{4})$/;\n\n/**\n * Whether a date that names no time is the day it names in UTC — as an ISO\n * `2024-01-05` already is — rather than local midnight, which `new Date()`\n * makes of `5 Jan 2024`.\n */\nfunction utcDay(date: Date): Date {\n return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));\n}\n\nfunction validUtcDate(year: number, month: number, day: number): Date | undefined {\n const date = new Date(Date.UTC(year, month - 1, day));\n return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day\n ? date\n : undefined;\n}\n\n/**\n * Read a date cell. `new Date()` never throws, so its failures used to import\n * as an Invalid Date (sent as `null`); it reads `05/01/2024` month first\n * wherever the file came from, an epoch in seconds as milliseconds (1970), and\n * `5 Jan 2024` at local midnight where `2024-01-05` is UTC midnight.\n */\nfunction readDateCell(cell: string, order: SlashDateOrder | undefined, timeOfDay = false): Date | ImportProblemReason {\n const text = cell.trim();\n if (/^-?\\d+$/.test(text)) {\n return dateFromEpoch(Number(text), timeOfDay) ?? \"not_a_date\";\n }\n const slash = SLASH_DATE.exec(text);\n if (slash) {\n const first = Number(slash[1]);\n const second = Number(slash[3]);\n const year = Number(slash[4]);\n let dayFirst: boolean;\n if (order === \"dmy\" || order === \"mdy\") {\n dayFirst = order === \"dmy\";\n } else if (order === \"each\") {\n // The column writes both orders; only a date that just one order\n // can read is placed.\n if (first > 12 === second > 12) return \"ambiguous_date\";\n dayFirst = first > 12;\n } else {\n dayFirst = first > 12 || (second <= 12 && localeWritesDayFirst());\n }\n const date = dayFirst ? validUtcDate(year, second, first) : validUtcDate(year, first, second);\n return date ?? \"not_a_date\";\n }\n const date = new Date(text);\n if (isNaN(date.getTime())) return \"not_a_date\";\n const namesATime = /\\d:\\d/.test(text);\n return namesATime || /^\\d{4}-\\d{2}-\\d{2}$/.test(text) ? date : utcDay(date);\n}\n\n/** Whether this browser's locale writes the day before the month. */\nfunction localeWritesDayFirst(): boolean {\n const parts = new Intl.DateTimeFormat().formatToParts(new Date(2000, 10, 22));\n const day = parts.findIndex(part => part.type === \"day\");\n const month = parts.findIndex(part => part.type === \"month\");\n return day >= 0 && month >= 0 && day < month;\n}\n\n/**\n * For each column of the file, how it writes day/month dates with numbers\n * only, when its values say: a first number past 12 is a day, so the column\n * is day first; a second number past 12, month first; both, and each date\n * is read by the only order that fits it. A column that never says is read\n * in the order of the browser's locale.\n */\nexport function slashDateOrdersByColumn(data: object[],\n properties?: Properties,\n targetOf?: ColumnTarget): Record<string, SlashDateOrder | undefined> {\n const seen: Record<string, { dayFirst: boolean, monthFirst: boolean }> = {};\n for (const row of data) {\n for (const [column, value] of Object.entries(flattenEntry(row as Record<string, unknown>, properties, targetOf))) {\n if (typeof value !== \"string\") continue;\n const slash = SLASH_DATE.exec(value.trim());\n if (!slash) continue;\n const entry = Object.hasOwn(seen, column) ? seen[column] : (seen[column] = { dayFirst: false, monthFirst: false });\n if (Number(slash[1]) > 12) entry.dayFirst = true;\n if (Number(slash[3]) > 12) entry.monthFirst = true;\n }\n }\n const orders: Record<string, SlashDateOrder | undefined> = {};\n for (const [column, { dayFirst, monthFirst }] of Object.entries(seen)) {\n orders[column] = dayFirst && monthFirst ? \"each\" : dayFirst ? \"dmy\" : monthFirst ? \"mdy\" : undefined;\n }\n return orders;\n}\n"],"mappings":";;;;;;;;;;;;;AA6DA,SAAgB,kBAAkB,gBAC9B,YACA,MACA,UACA,gBACA,YACA,MACA,eAAsG;CACtG,MAAM,WAAsC,CAAC;CAC7C,MAAM,aAAa,wBAAwB,MAAM,YAAY,mBAAmB,cAAc,CAAC;CAK/F,OAAO;EAAE,UAJQ,KAAK,KAAK,KAAK,UAAU,oBAAoB,gBAAgB,YAC1E,KAAgC,UAAU,gBAAgB,YAAY,MAAM,gBAC3E,YAAY,SAAS,KAAK;GAAE,KAAK;GAAO,GAAG;EAAQ,CAAC,GACrD,UAAU,CACL;EAAU;CAAS;AAChC;AAEA,SAAgB,oBAAoB,gBAChC,YACA,MACA,UACA,gBACA,YACA,MACA,eACA,WACA,YAAsE;CACtE,MAAM,aAAa,aAAa,MAAM,YAAY,mBAAmB,cAAc,CAAC;CACpF,IAAI,UACA,OAAO,WAAW;CAItB,MAAM,mBAA4C,OAAO,OAAO,IAAI;CACpE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAAG;EAInD,MAAM,YAAY,OAAO,UAAU,eAAe,KAAK,gBAAgB,GAAG,IACpE,eAAe,OACf;EACN,IAAI,cAAc,MACd;EAKJ,IAAI,UAAU,IACV;EAGJ,MAAM,iBAAiB,kBAAkB,YAAY,SAAS;EAG9D,IAAI,CAAC,kBAAkB,OAAO,mBAAmB,UAC7C;EAEJ,IAAI;EACJ,MAAM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AAO,IAAI;AAC9E;;AAGA,SAAS,uBAAgC;CACrC,MAAM,QAAQ,IAAI,KAAK,eAAe,CAAC,CAAC,cAAc,IAAI,KAAK,KAAM,IAAI,EAAE,CAAC;CAC5E,MAAM,MAAM,MAAM,WAAU,SAAQ,KAAK,SAAS,KAAK;CACvD,MAAM,QAAQ,MAAM,WAAU,SAAQ,KAAK,SAAS,OAAO;CAC3D,OAAO,OAAO,KAAK,SAAS,KAAK,MAAM;AAC3C;;;;;;;;AASA,SAAgB,wBAAwB,MACpC,YACA,UAAqE;CACrE,MAAM,OAAmE,CAAC;CAC1E,KAAK,MAAM,OAAO,MACd,KAAK,MAAM,CAAC,QAAQ,UAAU,OAAO,QAAQ,aAAa,KAAgC,YAAY,QAAQ,CAAC,GAAG;EAC9G,IAAI,OAAO,UAAU,UAAU;EAC/B,MAAM,QAAQ,WAAW,KAAK,MAAM,KAAK,CAAC;EAC1C,IAAI,CAAC,OAAO;EACZ,MAAM,QAAQ,OAAO,OAAO,MAAM,MAAM,IAAI,KAAK,UAAW,KAAK,UAAU;GAAE,UAAU;GAAO,YAAY;EAAM;EAChH,IAAI,OAAO,MAAM,EAAE,IAAI,IAAI,MAAM,WAAW;EAC5C,IAAI,OAAO,MAAM,EAAE,IAAI,IAAI,MAAM,aAAa;CAClD;CAEJ,MAAM,SAAqD,CAAC;CAC5D,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,iBAAiB,OAAO,QAAQ,IAAI,GAChE,OAAO,UAAU,YAAY,aAAa,SAAS,WAAW,QAAQ,aAAa,QAAQ,KAAA;CAE/F,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../../src/data_import/utils/data.ts"],"sourcesContent":["import { getPropertyInPath } from \"../../util\";\nimport { AuthController, AdminCollection, CollectionRegistryController, isPropertyBuilder, ArrayProperty, DataType, Properties, Property, EntityReference, GeoPoint, Vector, Entity } from \"@rebasepro/cms-types\";\nimport { unflattenObject } from \"./transforms\";\nimport { ColumnTarget, importColumns } from \"./import_columns\";\nimport { inferTypeFromValue, readNumberExactly } from \"@rebasepro/inference\";\nimport { mergeDeep } from \"@rebasepro/utils\";\n\n/** What the conversion asks of the collection registry: the collection a reference points into. */\nexport type ImportCollectionLookup = Pick<CollectionRegistryController, \"getCollection\">;\n\n/**\n * Why a cell could not be converted to its property's type. Each one is a\n * translation key under `import_problem_`.\n */\nexport type ImportProblemReason =\n | \"not_a_number\"\n | \"number_leading_zero\"\n | \"number_too_precise\"\n | \"not_a_boolean\"\n | \"not_a_date\"\n | \"ambiguous_date\"\n | \"not_a_vector\"\n | \"not_a_map\"\n | \"not_a_geopoint\";\n\n/**\n * A cell the import could not convert to the type of the property it maps\n * to. It is left out of the row — the property's default applies — and shown\n * to the person importing before anything is written.\n */\nexport type ImportConversionProblem = {\n /** The row's index among the file's data rows, from 0. */\n row: number;\n /** The column, as the file names it. */\n column: string;\n /** The property the column maps to. */\n property: string;\n /** The type that property holds. */\n expected: DataType;\n /** The cell, as it was read from the file. */\n value: unknown;\n reason: ImportProblemReason;\n};\n\n/** Reports one cell that did not convert; the cell is then left out. */\nexport type ImportProblemListener = (problem: { reason: ImportProblemReason }) => void;\n\n/**\n * How a column writes the dates whose day and month are both numbers\n * (`05/01/2024`): day first, month first, or — when the column holds both —\n * each date by the only order that can read it.\n */\nexport type SlashDateOrder = \"dmy\" | \"mdy\" | \"each\";\n\n/**\n * Convert every row of an imported file, and list each cell that did not\n * convert. The previews call this, so the list is in front of the person\n * importing before the first row is written.\n */\nexport function convertImportData(authController: AuthController,\n navigation: ImportCollectionLookup,\n data: object[],\n idColumn: string | undefined,\n headersMapping: Record<string, string | null>,\n properties: Properties,\n path: string,\n defaultValues: Record<string, any>): { entities: Entity<any>[], problems: ImportConversionProblem[] } {\n const problems: ImportConversionProblem[] = [];\n const dateOrders = slashDateOrdersByColumn(data, properties, mappedColumnTarget(headersMapping));\n const entities = data.map((row, index) => convertDataToEntity(authController, navigation,\n row as Record<string, unknown>, idColumn, headersMapping, properties, path, defaultValues,\n (problem) => problems.push({ row: index, ...problem }),\n dateOrders));\n return { entities, problems };\n}\n\nexport function convertDataToEntity(authController: AuthController,\n navigation: ImportCollectionLookup,\n data: Record<any, any>,\n idColumn: string | undefined,\n headersMapping: Record<string, string | null>,\n properties: Properties,\n path: string,\n defaultValues: Record<string, any>,\n onProblem?: (problem: Omit<ImportConversionProblem, \"row\">) => void,\n dateOrders?: Record<string, SlashDateOrder | undefined>): Entity<any> {\n const flatObject = flattenEntry(data, properties, mappedColumnTarget(headersMapping));\n if (idColumn)\n delete flatObject[idColumn];\n // One accumulator, written in place: spreading it once per column made\n // converting a row quadratic in its column count. No prototype, so a\n // `__proto__` key is a key here; `unflattenObject` refuses it below.\n const mappedKeysObject: Record<string, unknown> = Object.create(null);\n for (const [key, value] of Object.entries(flatObject)) {\n // The mapping is keyed by the column's flat name — `address.street`\n // is one key, not a path — and `null` is \"Do not import this\n // property\". A column the mapping does not mention keeps its name.\n const mappedKey = Object.prototype.hasOwnProperty.call(headersMapping, key)\n ? headersMapping[key]\n : key;\n if (mappedKey === null) {\n continue;\n }\n // A blank cell is a value nobody filled in, not an empty one: it\n // sets nothing, so the default chosen for the property applies. An\n // empty spreadsheet cell already arrives without a key.\n if (value === \"\") {\n continue;\n }\n\n const mappedProperty = getPropertyInPath(properties, mappedKey);\n // `getPropertyInPath` answers `in`, so a `toString` column finds\n // `Object.prototype.toString`: a declared property is an object.\n if (!mappedProperty || typeof mappedProperty !== \"object\") {\n continue;\n }\n let reason: ImportProblemReason | undefined;\n const processedValue = processValueMapping(authController, value, navigation, mappedProperty,\n (problem) => { reason ??= problem.reason; },\n dateOrders && Object.hasOwn(dateOrders, key) ? dateOrders[key] : undefined);\n // A cell that did not convert is not imported as `null`, `0` or\n // `false` in its place: it is left out, and reported.\n if (reason !== undefined) {\n onProblem?.({ column: key, property: mappedKey, expected: mappedProperty.type, value, reason });\n continue;\n }\n mappedKeysObject[mappedKey] = processedValue;\n }\n\n const values = mergeDeep(defaultValues ?? {}, unflattenObject(mappedKeysObject));\n let id = idColumn ? data[idColumn] : undefined;\n if (typeof id === \"string\") {\n id = id.trim();\n } else if (typeof id === \"number\") {\n id = id.toString();\n } else if (typeof id === \"boolean\") {\n id = id.toString();\n } else if (id instanceof Date) {\n id = id.toISOString();\n } else if (id && \"toString\" in id) {\n id = id.toString();\n }\n\n return {\n id,\n values,\n path: path\n };\n}\n\n/**\n * Where a column lands under the import's mapping: the property the mapping\n * names for it, `null` for \"Do not import this property\", and the property\n * with the column's own name when the mapping does not mention the column.\n */\nexport function mappedColumnTarget(headersMapping: Record<string, string | null>): ColumnTarget {\n return (column) => Object.hasOwn(headersMapping, column) ? headersMapping[column] : column;\n}\n\n/**\n * The cells of one imported row by column name (`address.street`): each\n * value that is not split into columns of its own (see `importColumns`).\n * Without `properties`, every object is split.\n */\nexport function flattenEntry(obj: Record<string, unknown>,\n properties?: Properties,\n targetOf: ColumnTarget = (column) => column): Record<string, unknown> {\n const cells: Record<string, unknown> = {};\n for (const { column, value, split } of importColumns(obj, properties, targetOf)) {\n if (!split) cells[column] = value;\n }\n return cells;\n}\n\n/**\n * Convert one cell to the type of the property it lands in.\n *\n * A cell is converted only when the property's type can hold what it says:\n * text becomes a number when it spells one exactly (`readNumberExactly`, the\n * same answer the inference uses), a boolean when it says yes or no, a date\n * when it names a day. Anything else is reported to `onProblem`, and the\n * result is `null` — the caller leaves such a cell out rather than writing\n * that `null`, a `0` or a `false` in its place.\n *\n * @param dateOrder how the cell's column writes day/month dates, when it\n * writes them with numbers only (see `slashDateOrdersByColumn`).\n */\nexport function processValueMapping(authController: AuthController,\n value: any,\n navigation: ImportCollectionLookup,\n property?: Property,\n onProblem?: ImportProblemListener,\n dateOrder?: SlashDateOrder): any {\n if (value === null) return null;\n\n if (property === undefined) return value;\n const usedProperty: Property | null = property;\n if (usedProperty === null) return value;\n const from = inferTypeFromValue(value);\n const to = usedProperty.type;\n const refuse = (reason: ImportProblemReason) => {\n onProblem?.({ reason });\n return null;\n };\n\n if (to === \"vector\") {\n let items: unknown[] | undefined;\n if (Array.isArray(value)) {\n items = value;\n } else if (isObjectValue(value)) {\n // A JSON file holds the vector as the object the export wrote.\n if (!Array.isArray(value.value)) return refuse(\"not_a_vector\");\n items = value.value;\n } else if (typeof value === \"string\") {\n let cleaned = value.trim();\n if (cleaned.startsWith(\"{\")) {\n // A CSV cell holds it as that object's JSON, `{\"value\":[…]}`.\n const object = readJsonObjectCell(cleaned);\n if (!object || !Array.isArray(object.value)) return refuse(\"not_a_vector\");\n items = object.value;\n } else {\n if (cleaned.startsWith(\"[\") && cleaned.endsWith(\"]\")) {\n cleaned = cleaned.slice(1, -1);\n }\n if (cleaned === \"\") return null;\n items = cleaned.split(\",\");\n }\n }\n if (items === undefined) return value;\n const numbers = items.map(item => typeof item === \"number\"\n ? item\n : typeof item === \"string\" ? readNumberExactly(item) : undefined);\n // An item that is not a number used to become 0 (or NaN): a vector\n // with a made-up coordinate.\n if (numbers.some(item => item === undefined || !Number.isFinite(item))) return refuse(\"not_a_vector\");\n return new Vector(numbers as number[]);\n }\n\n if (to === \"map\" || to === \"geopoint\") {\n // The export writes a map and a geopoint as the JSON of the object in\n // a CSV cell — and each item of an array of maps the same way — and\n // as the object itself in a JSON file; that is what either reads as.\n // Kept as text, a map was stored as a JSON string and a geopoint\n // refused the whole batch at the server.\n if (typeof value === \"string\" && value.trim() === \"\") return null;\n const object = typeof value === \"string\" ? readJsonObjectCell(value) : isObjectValue(value) ? value : undefined;\n if (usedProperty.type === \"geopoint\") {\n const { latitude, longitude } = object ?? {};\n return typeof latitude === \"number\" && typeof longitude === \"number\"\n && Math.abs(latitude) <= 90 && Math.abs(longitude) <= 180\n ? new GeoPoint(latitude, longitude)\n : refuse(\"not_a_geopoint\");\n }\n if (!object) return refuse(\"not_a_map\");\n if (usedProperty.type !== \"map\" || !usedProperty.properties) return object;\n // A map that arrives whole — an item of an array of maps — has its\n // declared fields converted like the columns of a row: its dates\n // were left as the text or epoch number the export wrote.\n const fields: Record<string, unknown> = { ...object };\n for (const [key, fieldProperty] of Object.entries(usedProperty.properties)) {\n if (!Object.hasOwn(object, key) || isPropertyBuilder(fieldProperty)) continue;\n fields[key] = processValueMapping(authController, object[key], navigation, fieldProperty, onProblem, dateOrder);\n }\n return fields;\n }\n\n if (from === \"string\" && to === \"array\" && typeof value === \"string\") {\n return processValueMapping(authController, splitListCell(value), navigation, usedProperty, onProblem, dateOrder);\n } else if (from === \"string\" && to === \"boolean\" && typeof value === \"string\") {\n // A blank cell is no value; anything else unreadable is reported.\n if (value.trim() === \"\") return null;\n const read = readBooleanCell(value);\n return read === undefined ? refuse(\"not_a_boolean\") : read;\n } else if (from === \"array\" && to === \"string\") {\n // A CSV cell only arrives as an array when its text was the canonical\n // JSON of one (`mapJsonParse`), so this is that text again.\n return JSON.stringify(value);\n }\n\n if (from === \"array\" && Array.isArray(value) && usedProperty.type === \"array\") {\n const of = usedProperty.of;\n if (usedProperty.oneOf) {\n const oneOf = usedProperty.oneOf;\n return value.map(item => convertBlock(item, oneOf,\n (blockValue, blockProperty) => processValueMapping(authController, blockValue, navigation, blockProperty, onProblem, dateOrder)));\n }\n if (Array.isArray(of)) {\n // A fixed list: each position has a property of its own.\n return value.map((item, index) => index < of.length && !isPropertyBuilder(of[index])\n ? processValueMapping(authController, item, navigation, of[index], onProblem, dateOrder)\n : item);\n }\n if (of && !isPropertyBuilder(of)) {\n return value.map(item => processValueMapping(authController, item, navigation, of, onProblem, dateOrder));\n }\n }\n\n if (from === \"string\" && to === \"number\" && typeof value === \"string\") {\n // A blank cell is no value — not a real zero, which `Number(\"\")` is.\n const trimmed = value.trim();\n if (trimmed === \"\") return null;\n const read = readNumberExactly(trimmed);\n if (read !== undefined) return read;\n return refuse(whyNotANumber(trimmed));\n } else if (from === \"number\" && to === \"boolean\") {\n if (value === 1) return true;\n if (value === 0) return false;\n return refuse(\"not_a_boolean\");\n } else if (from === \"boolean\" && to === \"number\") {\n return value ? 1 : 0;\n } else if (from === \"boolean\" && to === \"string\") {\n return value ? \"true\" : \"false\";\n } else if (from === \"number\" && to === \"string\" && typeof value === \"number\") {\n return value.toString();\n } else if (from === \"string\" && to === \"date\" && typeof value === \"string\") {\n const read = readDateCell(value, dateOrder, isTimeOfDay(usedProperty));\n return read instanceof Date ? read : refuse(read);\n } else if (value instanceof Date && to === \"string\") {\n return value.toISOString();\n } else if (from === \"number\" && to === \"date\" && typeof value === \"number\") {\n const read = dateFromEpoch(value, isTimeOfDay(usedProperty));\n return read ?? refuse(\"not_a_date\");\n } else if (from === \"string\" && to === \"reference\" && typeof value === \"string\") {\n // Parse optional database name in format: database_name:::path/to/entity\n // or simple format: path/to/entity\n let databaseId: string | undefined = undefined;\n let referencePath = value;\n\n if (value.includes(\":::\")) {\n const [dbName, pathPart] = value.split(\":::\");\n if (dbName && dbName !== \"(default)\") {\n databaseId = dbName;\n }\n referencePath = pathPart;\n }\n\n // split value into path and entityId (entityId is the last part of the path, after the last /)\n const path = referencePath.split(\"/\").slice(0, -1).join(\"/\");\n const entityId = referencePath.split(\"/\").slice(-1)[0];\n\n // If no explicit database was provided in the string, try to get it from the collection\n if (databaseId === undefined) {\n const targetCollection: AdminCollection<any> | undefined = navigation.getCollection(path);\n databaseId = targetCollection?.databaseId;\n }\n\n return new EntityReference({ id: entityId,\npath,\ndatabaseId });\n\n } else if (from === to) {\n return value;\n }\n\n return value;\n}\n\n/** An object read from a file, as opposed to a list, a date or a primitive. */\nfunction isObjectValue(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) && !(value instanceof Date);\n}\n\n/**\n * One item of a block list (`oneOf`): the object the export wrote — or, in a\n * CSV whose lists were written one cell per item, that object's JSON — with\n * its value converted to the property its type names.\n */\nfunction convertBlock(item: unknown,\n oneOf: NonNullable<ArrayProperty[\"oneOf\"]>,\n convert: (value: unknown, property: Property) => unknown): unknown {\n const block = typeof item === \"string\" ? readJsonObjectCell(item) : isObjectValue(item) ? item : undefined;\n if (!block) return item;\n const typeField = oneOf.typeField ?? \"type\";\n const valueField = oneOf.valueField ?? \"value\";\n const type = block[typeField];\n const blockProperty = typeof type === \"string\" && Object.hasOwn(oneOf.properties, type) ? oneOf.properties[type] : undefined;\n if (!blockProperty || isPropertyBuilder(blockProperty) || !Object.hasOwn(block, valueField)) return block;\n return { ...block, [valueField]: convert(block[valueField], blockProperty) };\n}\n\n/** A cell holding the JSON of an object, read; `undefined` for anything else. */\nfunction readJsonObjectCell(cell: string): Record<string, unknown> | undefined {\n const trimmed = cell.trim();\n if (!trimmed.startsWith(\"{\")) return undefined;\n try {\n const parsed: unknown = JSON.parse(trimmed);\n return parsed && typeof parsed === \"object\" && !Array.isArray(parsed)\n ? parsed as Record<string, unknown>\n : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The items of a list cell: a JSON array as written (the export writes lists\n * that way), otherwise the text split on commas. Each item is trimmed and an\n * empty one dropped, so `news, sports` is two tags rather than one with a\n * leading space, and a blank cell is no tags rather than one empty tag.\n */\nfunction splitListCell(cell: string): unknown[] {\n const trimmed = cell.trim();\n if (trimmed.startsWith(\"[\")) {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n if (Array.isArray(parsed)) return parsed;\n } catch (e) {\n // Not JSON after all: a list that happens to start with a bracket.\n }\n }\n return trimmed.split(\",\")\n .map(item => item.trim())\n .filter(item => item !== \"\");\n}\n\n/**\n * A boolean cell as spreadsheets and people write it: Excel and Sheets export\n * `TRUE`/`FALSE`, and `yes`/`no` and `1`/`0` are common by hand. Anything\n * unreadable is absent — `null`, as a number cell is — rather than a confident\n * `false`.\n */\nfunction readBooleanCell(cell: string): boolean | undefined {\n const normalised = cell.trim().toLowerCase();\n if ([\"true\", \"1\", \"yes\", \"y\"].includes(normalised)) return true;\n if ([\"false\", \"0\", \"no\", \"n\"].includes(normalised)) return false;\n return undefined;\n}\n\n/** Why a text is not a number `readNumberExactly` accepts. */\nfunction whyNotANumber(text: string): ImportProblemReason {\n // A leading zero is an identifier — a zip code, a product code — and\n // more than 15 significant digits is more than a double holds: `Number()`\n // would read both, and change them.\n if (/^-?0\\d/.test(text) && Number.isFinite(Number(text))) return \"number_leading_zero\";\n if (/^-?\\d+(\\.\\d+)?$/.test(text)) return \"number_too_precise\";\n return \"not_a_number\";\n}\n\n/**\n * Below this, an epoch number is in seconds: 1e11 seconds is the year 5138,\n * and 1e11 milliseconds is March 1973.\n */\nconst EPOCH_SECONDS_BELOW = 1e11;\n\n/** One day, in milliseconds. */\nconst DAY_MS = 86_400_000;\n\n/** Whether a property holds a time of day — a time on 1970-01-01, in UTC. */\nfunction isTimeOfDay(property: Property): boolean {\n return property.type === \"date\" && property.columnType === \"time\";\n}\n\n/**\n * @param timeOfDay the number lands in a time-of-day property. The export\n * writes such a time as the milliseconds since that midnight, a number below\n * one day; read as epoch seconds, 12:30 was a day in 1971 at 20:00.\n */\nfunction dateFromEpoch(epoch: number, timeOfDay = false): Date | undefined {\n if (!Number.isFinite(epoch)) return undefined;\n const inMilliseconds = (timeOfDay && epoch >= 0 && epoch < DAY_MS) || Math.abs(epoch) >= EPOCH_SECONDS_BELOW;\n const date = new Date(inMilliseconds ? epoch : epoch * 1000);\n return isNaN(date.getTime()) ? undefined : date;\n}\n\n/** `05/01/2024`, `5.1.2024`, `05-01-2024`: day and month as numbers, year last. */\nconst SLASH_DATE = /^(\\d{1,2})([/.-])(\\d{1,2})\\2(\\d{4})$/;\n\n/**\n * Whether a date that names no time is the day it names in UTC — as an ISO\n * `2024-01-05` already is — rather than local midnight, which `new Date()`\n * makes of `5 Jan 2024`.\n */\nfunction utcDay(date: Date): Date {\n return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));\n}\n\nfunction validUtcDate(year: number, month: number, day: number): Date | undefined {\n const date = new Date(Date.UTC(year, month - 1, day));\n return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day\n ? date\n : undefined;\n}\n\n/**\n * Read a date cell. `new Date()` never throws, so its failures used to import\n * as an Invalid Date (sent as `null`); it reads `05/01/2024` month first\n * wherever the file came from, an epoch in seconds as milliseconds (1970), and\n * `5 Jan 2024` at local midnight where `2024-01-05` is UTC midnight.\n */\nfunction readDateCell(cell: string, order: SlashDateOrder | undefined, timeOfDay = false): Date | ImportProblemReason {\n const text = cell.trim();\n if (/^-?\\d+$/.test(text)) {\n return dateFromEpoch(Number(text), timeOfDay) ?? \"not_a_date\";\n }\n const slash = SLASH_DATE.exec(text);\n if (slash) {\n const first = Number(slash[1]);\n const second = Number(slash[3]);\n const year = Number(slash[4]);\n let dayFirst: boolean;\n if (order === \"dmy\" || order === \"mdy\") {\n dayFirst = order === \"dmy\";\n } else if (order === \"each\") {\n // The column writes both orders; only a date that just one order\n // can read is placed.\n if (first > 12 === second > 12) return \"ambiguous_date\";\n dayFirst = first > 12;\n } else {\n dayFirst = first > 12 || (second <= 12 && localeWritesDayFirst());\n }\n const date = dayFirst ? validUtcDate(year, second, first) : validUtcDate(year, first, second);\n return date ?? \"not_a_date\";\n }\n const date = new Date(text);\n if (isNaN(date.getTime())) return \"not_a_date\";\n const namesATime = /\\d:\\d/.test(text);\n return namesATime || /^\\d{4}-\\d{2}-\\d{2}$/.test(text) ? date : utcDay(date);\n}\n\n/** Whether this browser's locale writes the day before the month. */\nfunction localeWritesDayFirst(): boolean {\n const parts = new Intl.DateTimeFormat().formatToParts(new Date(2000, 10, 22));\n const day = parts.findIndex(part => part.type === \"day\");\n const month = parts.findIndex(part => part.type === \"month\");\n return day >= 0 && month >= 0 && day < month;\n}\n\n/**\n * For each column of the file, how it writes day/month dates with numbers\n * only, when its values say: a first number past 12 is a day, so the column\n * is day first; a second number past 12, month first; both, and each date\n * is read by the only order that fits it. A column that never says is read\n * in the order of the browser's locale.\n */\nexport function slashDateOrdersByColumn(data: object[],\n properties?: Properties,\n targetOf?: ColumnTarget): Record<string, SlashDateOrder | undefined> {\n const seen: Record<string, { dayFirst: boolean, monthFirst: boolean }> = {};\n for (const row of data) {\n for (const [column, value] of Object.entries(flattenEntry(row as Record<string, unknown>, properties, targetOf))) {\n if (typeof value !== \"string\") continue;\n const slash = SLASH_DATE.exec(value.trim());\n if (!slash) continue;\n const entry = Object.hasOwn(seen, column) ? seen[column] : (seen[column] = { dayFirst: false, monthFirst: false });\n if (Number(slash[1]) > 12) entry.dayFirst = true;\n if (Number(slash[3]) > 12) entry.monthFirst = true;\n }\n }\n const orders: Record<string, SlashDateOrder | undefined> = {};\n for (const [column, { dayFirst, monthFirst }] of Object.entries(seen)) {\n orders[column] = dayFirst && monthFirst ? \"each\" : dayFirst ? \"dmy\" : monthFirst ? \"mdy\" : undefined;\n }\n return orders;\n}\n"],"mappings":";;;;;;;;;;;;AA2DA,SAAgB,kBAAkB,gBAC9B,YACA,MACA,UACA,gBACA,YACA,MACA,eAAsG;CACtG,MAAM,WAAsC,CAAC;CAC7C,MAAM,aAAa,wBAAwB,MAAM,YAAY,mBAAmB,cAAc,CAAC;CAK/F,OAAO;EAAE,UAJQ,KAAK,KAAK,KAAK,UAAU,oBAAoB,gBAAgB,YAC1E,KAAgC,UAAU,gBAAgB,YAAY,MAAM,gBAC3E,YAAY,SAAS,KAAK;GAAE,KAAK;GAAO,GAAG;EAAQ,CAAC,GACrD,UAAU,CACL;EAAU;CAAS;AAChC;AAEA,SAAgB,oBAAoB,gBAChC,YACA,MACA,UACA,gBACA,YACA,MACA,eACA,WACA,YAAsE;CACtE,MAAM,aAAa,aAAa,MAAM,YAAY,mBAAmB,cAAc,CAAC;CACpF,IAAI,UACA,OAAO,WAAW;CAItB,MAAM,mBAA4C,OAAO,OAAO,IAAI;CACpE,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,GAAG;EAInD,MAAM,YAAY,OAAO,UAAU,eAAe,KAAK,gBAAgB,GAAG,IACpE,eAAe,OACf;EACN,IAAI,cAAc,MACd;EAKJ,IAAI,UAAU,IACV;EAGJ,MAAM,iBAAiB,kBAAkB,YAAY,SAA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|
-
{"version":3,"file":"get_import_inference_type.js","names":[],"sources":["../../../src/data_import/utils/get_import_inference_type.ts"],"sourcesContent":["import { DataType } from \"@rebasepro/types\";\n\nexport function getInferenceType(value: any): DataType {\n // `typeof null === \"object\"`, so a null or empty CSV cell used to fall past\n // every check and land on \"map\" — an empty cell described as a nested object.\n // `inferTypeFromValue` in @rebasepro/inference already answers \"string\" here;\n // the two entry points into inference have to agree.\n if (value === null || value === undefined)\n return \"string\";\n if (typeof value === \"number\")\n return \"number\";\n else if (typeof value === \"string\")\n return \"string\";\n else if (typeof value === \"boolean\")\n return \"boolean\";\n else if (value instanceof Date)\n return \"date\";\n else if (Array.isArray(value))\n return \"array\";\n return \"map\";\n}\n\n"],"mappings":";AAEA,SAAgB,iBAAiB,OAAsB;CAKnD,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC5B,OAAO;CACX,IAAI,OAAO,UAAU,UACjB,OAAO;MACN,IAAI,OAAO,UAAU,UACtB,OAAO;MACN,IAAI,OAAO,UAAU,WACtB,OAAO;MACN,IAAI,iBAAiB,MACtB,OAAO;MACN,IAAI,MAAM,QAAQ,KAAK,GACxB,OAAO;CACX,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"get_import_inference_type.js","names":[],"sources":["../../../src/data_import/utils/get_import_inference_type.ts"],"sourcesContent":["import { DataType } from \"@rebasepro/cms-types\";\n\nexport function getInferenceType(value: any): DataType {\n // `typeof null === \"object\"`, so a null or empty CSV cell used to fall past\n // every check and land on \"map\" — an empty cell described as a nested object.\n // `inferTypeFromValue` in @rebasepro/inference already answers \"string\" here;\n // the two entry points into inference have to agree.\n if (value === null || value === undefined)\n return \"string\";\n if (typeof value === \"number\")\n return \"number\";\n else if (typeof value === \"string\")\n return \"string\";\n else if (typeof value === \"boolean\")\n return \"boolean\";\n else if (value instanceof Date)\n return \"date\";\n else if (Array.isArray(value))\n return \"array\";\n return \"map\";\n}\n\n"],"mappings":";AAEA,SAAgB,iBAAiB,OAAsB;CAKnD,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC5B,OAAO;CACX,IAAI,OAAO,UAAU,UACjB,OAAO;MACN,IAAI,OAAO,UAAU,UACtB,OAAO;MACN,IAAI,OAAO,UAAU,WACtB,OAAO;MACN,IAAI,iBAAiB,MACtB,OAAO;MACN,IAAI,MAAM,QAAQ,KAAK,GACxB,OAAO;CACX,OAAO;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id_column.js","names":[],"sources":["../../../src/data_import/utils/id_column.ts"],"sourcesContent":["import { Properties } from \"@rebasepro/types\";\n\n/**\n * The column an import uses as the row id before the user touches the mapping.\n *\n * The guess decides something destructive: the chosen column is taken out of\n * the values and sent as the id of an upsert, so every row overwrites the record\n * that already has that id. A header that merely *contained* \"id\" or \"key\" used\n * to qualify, so a file starting with `width`, `video` or `provider` wrote its\n * widths over the records whose ids they happened to equal.\n *\n * Only the first column is a candidate — the one the export writes the id to —\n * and only when its name says it is the id: the header is `id` (in any case),\n * or it maps onto a property the collection declares with `isId`. Anything else\n * is left for the user to choose in the mapping step.\n */\nexport function guessIdColumn(headers: string[],\n headersMapping: Record<string, string | null>,\n properties?: Properties): string | undefined {\n const firstKey = headers[0];\n if (firstKey === undefined) return undefined;\n\n if (firstKey.trim().toLowerCase() === \"id\") return firstKey;\n\n const mappedKey = headersMapping[firstKey];\n const mappedProperty = mappedKey ? properties?.[mappedKey] : undefined;\n if (mappedProperty && \"isId\" in mappedProperty && mappedProperty.isId) return firstKey;\n\n return undefined;\n}\n\n/**\n * The mapping and id column after the person importing picks where one column\n * goes, in that column's row of the mapping step: a property (`targetKey`), or\n * nothing (`null`, \"Do not import this property\").\n *\n * A property holds one column, so a column that held `targetKey` before lets\n * it go. And a column picked for a property, or for nothing, is no longer the\n * id: the row's select shows \"Use this column as ID\" while it is, and the\n * conversion takes the id column out of the values, so the pick was dropped.\n */\nexport function remapImportColumn({\n headersMapping,\n idColumn,\n column,\n targetKey\n}: {\n headersMapping: Record<string, string | null>;\n idColumn: string | undefined;\n column: string;\n targetKey: string | null;\n}): { headersMapping: Record<string, string | null>; idColumn: string | undefined } {\n const remapped: Record<string, string | null> = {};\n for (const [currentColumn, currentKey] of Object.entries(headersMapping)) {\n remapped[currentColumn] = currentColumn === column\n ? targetKey\n : targetKey !== null && currentKey === targetKey ? null : currentKey;\n }\n return {\n headersMapping: remapped,\n idColumn: idColumn === column ? undefined : idColumn\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,SAC1B,gBACA,YAA6C;CAC7C,MAAM,WAAW,QAAQ;CACzB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAEnC,IAAI,SAAS,KAAK,CAAC,CAAC,YAAY,MAAM,MAAM,OAAO;CAEnD,MAAM,YAAY,eAAe;CACjC,MAAM,iBAAiB,YAAY,aAAa,aAAa,KAAA;CAC7D,IAAI,kBAAkB,UAAU,kBAAkB,eAAe,MAAM,OAAO;AAGlF;;;;;;;;;;;AAYA,SAAgB,kBAAkB,EAC9B,gBACA,UACA,QACA,aAMgF;CAChF,MAAM,WAA0C,CAAC;CACjD,KAAK,MAAM,CAAC,eAAe,eAAe,OAAO,QAAQ,cAAc,GACnE,SAAS,iBAAiB,kBAAkB,SACtC,YACA,cAAc,QAAQ,eAAe,YAAY,OAAO;CAElE,OAAO;EACH,gBAAgB;EAChB,UAAU,aAAa,SAAS,KAAA,IAAY;CAChD;AACJ"}
|
|
1
|
+
{"version":3,"file":"id_column.js","names":[],"sources":["../../../src/data_import/utils/id_column.ts"],"sourcesContent":["import { Properties } from \"@rebasepro/cms-types\";\n\n/**\n * The column an import uses as the row id before the user touches the mapping.\n *\n * The guess decides something destructive: the chosen column is taken out of\n * the values and sent as the id of an upsert, so every row overwrites the record\n * that already has that id. A header that merely *contained* \"id\" or \"key\" used\n * to qualify, so a file starting with `width`, `video` or `provider` wrote its\n * widths over the records whose ids they happened to equal.\n *\n * Only the first column is a candidate — the one the export writes the id to —\n * and only when its name says it is the id: the header is `id` (in any case),\n * or it maps onto a property the collection declares with `isId`. Anything else\n * is left for the user to choose in the mapping step.\n */\nexport function guessIdColumn(headers: string[],\n headersMapping: Record<string, string | null>,\n properties?: Properties): string | undefined {\n const firstKey = headers[0];\n if (firstKey === undefined) return undefined;\n\n if (firstKey.trim().toLowerCase() === \"id\") return firstKey;\n\n const mappedKey = headersMapping[firstKey];\n const mappedProperty = mappedKey ? properties?.[mappedKey] : undefined;\n if (mappedProperty && \"isId\" in mappedProperty && mappedProperty.isId) return firstKey;\n\n return undefined;\n}\n\n/**\n * The mapping and id column after the person importing picks where one column\n * goes, in that column's row of the mapping step: a property (`targetKey`), or\n * nothing (`null`, \"Do not import this property\").\n *\n * A property holds one column, so a column that held `targetKey` before lets\n * it go. And a column picked for a property, or for nothing, is no longer the\n * id: the row's select shows \"Use this column as ID\" while it is, and the\n * conversion takes the id column out of the values, so the pick was dropped.\n */\nexport function remapImportColumn({\n headersMapping,\n idColumn,\n column,\n targetKey\n}: {\n headersMapping: Record<string, string | null>;\n idColumn: string | undefined;\n column: string;\n targetKey: string | null;\n}): { headersMapping: Record<string, string | null>; idColumn: string | undefined } {\n const remapped: Record<string, string | null> = {};\n for (const [currentColumn, currentKey] of Object.entries(headersMapping)) {\n remapped[currentColumn] = currentColumn === column\n ? targetKey\n : targetKey !== null && currentKey === targetKey ? null : currentKey;\n }\n return {\n headersMapping: remapped,\n idColumn: idColumn === column ? undefined : idColumn\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,SAC1B,gBACA,YAA6C;CAC7C,MAAM,WAAW,QAAQ;CACzB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAEnC,IAAI,SAAS,KAAK,CAAC,CAAC,YAAY,MAAM,MAAM,OAAO;CAEnD,MAAM,YAAY,eAAe;CACjC,MAAM,iBAAiB,YAAY,aAAa,aAAa,KAAA;CAC7D,IAAI,kBAAkB,UAAU,kBAAkB,eAAe,MAAM,OAAO;AAGlF;;;;;;;;;;;AAYA,SAAgB,kBAAkB,EAC9B,gBACA,UACA,QACA,aAMgF;CAChF,MAAM,WAA0C,CAAC;CACjD,KAAK,MAAM,CAAC,eAAe,eAAe,OAAO,QAAQ,cAAc,GACnE,SAAS,iBAAiB,kBAAkB,SACtC,YACA,cAAc,QAAQ,eAAe,YAAY,OAAO;CAElE,OAAO;EACH,gBAAgB;EAChB,UAAU,aAAa,SAAS,KAAA,IAAY;CAChD;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Properties, Property } from "@rebasepro/types";
|
|
1
|
+
import { Properties, Property } from "@rebasepro/cms-types";
|
|
2
2
|
/**
|
|
3
3
|
* Whether a property's value is an object the import takes whole, from one
|
|
4
4
|
* column: a geopoint, a vector, or a map that declares no fields (a key-value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import_columns.js","names":[],"sources":["../../../src/data_import/utils/import_columns.ts"],"sourcesContent":["import { Properties, Property } from \"@rebasepro/types\";\nimport { isPrototypePollutingKey, slugify } from \"@rebasepro/utils\";\nimport { getPropertyInPath } from \"../../util\";\n\n/**\n * Whether a property's value is an object the import takes whole, from one\n * column: a geopoint, a vector, or a map that declares no fields (a key-value\n * map). These are the values the export writes as objects — in a JSON file\n * as the object, in a CSV cell as its JSON — and splitting one into\n * `location.latitude` columns left it in columns no property holds: it was\n * dropped without a word.\n *\n * Any other object is read one column per key: a map with declared fields\n * field by field, as the export writes it, and an object no property takes\n * so that its keys can be mapped one by one.\n */\nexport function takesObjectWhole(property: Property): boolean {\n return property.type === \"geopoint\"\n || property.type === \"vector\"\n || (property.type === \"map\" && property.properties === undefined);\n}\n\n/** One column of an imported row, as the mapping step lists it. */\nexport type ImportColumn = {\n /** The column's name: a key of the row, or `parent.key` below one. */\n column: string;\n value: unknown;\n /** The property path it lands in, or `null` for none. */\n target: string | null;\n /** Its value is an object that is read as one column per key, listed after it. */\n split: boolean;\n};\n\n/**\n * Where a column lands: the property path for it, or `null` for none. A\n * column below another is given that parent; a top-level one is not.\n */\nexport type ColumnTarget = (column: string, key: string, parent?: Pick<ImportColumn, \"column\" | \"target\">) => string | null;\n\nfunction isObjectCell(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) && !(value instanceof Date);\n}\n\n/** The declared property at a path, and nothing inherited (`toString`). */\nfunction propertyAt(properties: Properties | undefined, path: string | null): Property | undefined {\n if (!properties || path === null) return undefined;\n const property = getPropertyInPath(properties, path);\n return property !== null && typeof property === \"object\" ? property : undefined;\n}\n\n/**\n * The columns of one imported row, parents before their children.\n *\n * Each key of the row is a column. A key whose value is an object is also\n * read as one column per key of that object (`address.street`) — unless the\n * property it lands in takes the object whole (see {@link takesObjectWhole}).\n *\n * The mapping step lists these columns and the conversion reads them, so both\n * get them from here: a list built one way and rows read another is a mapping\n * whose keys match nothing.\n */\nexport function importColumns(row: Record<string, unknown>,\n properties: Properties | undefined,\n targetOf: ColumnTarget): ImportColumn[] {\n const columns: ImportColumn[] = [];\n const walk = (object: Record<string, unknown>, parent?: Pick<ImportColumn, \"column\" | \"target\">) => {\n for (const key of Object.keys(object)) {\n // Keys come from the uploaded file, so a `__proto__` key would be\n // the prototype setter wherever it is used as one (class 22).\n if (isPrototypePollutingKey(key)) {\n console.warn(`Skipping column \"${key}\": a header may not reach the prototype chain`);\n continue;\n }\n const column = parent === undefined ? key : `${parent.column}.${key}`;\n const value = object[key];\n const target = targetOf(column, key, parent);\n const property = propertyAt(properties, target);\n const splitValue = isObjectCell(value) && !(property && takesObjectWhole(property))\n ? value\n : undefined;\n columns.push({ column, value, target, split: splitValue !== undefined });\n if (splitValue) walk(splitValue, { column, target });\n }\n };\n walk(row);\n return columns;\n}\n\n/**\n * The mapping the import starts from: each column of the file onto the\n * property with its name, or with its name slugged (`First Name` →\n * `first_name`); a column below a map onto that map's field. A column that\n * matches nothing keeps its own name, for the person importing to map.\n */\nexport function buildHeadersMappingFromData(rows: object[], properties?: Properties): Record<string, string> {\n const headersMapping: Record<string, string> = {};\n const targetOf: ColumnTarget = (column, key, parent) => {\n if (Object.hasOwn(headersMapping, column)) return headersMapping[column];\n const parentProperty = parent && propertyAt(properties, parent.target);\n const siblings = parent === undefined\n ? properties\n : parentProperty?.type === \"map\" ? parentProperty.properties : undefined;\n const slug = slugify(key);\n const name = siblings && !Object.hasOwn(siblings, key) && Object.hasOwn(siblings, slug) ? slug : key;\n return parent === undefined ? name : `${parent.target ?? parent.column}.${name}`;\n };\n for (const row of rows) {\n if (!row) continue;\n for (const { column, target } of importColumns(row as Record<string, unknown>, properties, targetOf)) {\n headersMapping[column] ??= target ?? column;\n }\n }\n return headersMapping;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,iBAAiB,UAA6B;CAC1D,OAAO,SAAS,SAAS,cAClB,SAAS,SAAS,YACjB,SAAS,SAAS,SAAS,SAAS,eAAe,KAAA;AAC/D;AAmBA,SAAS,aAAa,OAAkD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,KAAK,EAAE,iBAAiB;AACtG;;AAGA,SAAS,WAAW,YAAoC,MAA2C;CAC/F,IAAI,CAAC,cAAc,SAAS,MAAM,OAAO,KAAA;CACzC,MAAM,WAAW,kBAAkB,YAAY,IAAI;CACnD,OAAO,aAAa,QAAQ,OAAO,aAAa,WAAW,WAAW,KAAA;AAC1E;;;;;;;;;;;;AAaA,SAAgB,cAAc,KAC1B,YACA,UAAwC;CACxC,MAAM,UAA0B,CAAC;CACjC,MAAM,QAAQ,QAAiC,WAAqD;EAChG,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,GAAG;GAGnC,IAAI,wBAAwB,GAAG,GAAG;IAC9B,QAAQ,KAAK,oBAAoB,IAAI,8CAA8C;IACnF;GACJ;GACA,MAAM,SAAS,WAAW,KAAA,IAAY,MAAM,GAAG,OAAO,OAAO,GAAG;GAChE,MAAM,QAAQ,OAAO;GACrB,MAAM,SAAS,SAAS,QAAQ,KAAK,MAAM;GAC3C,MAAM,WAAW,WAAW,YAAY,MAAM;GAC9C,MAAM,aAAa,aAAa,KAAK,KAAK,EAAE,YAAY,iBAAiB,QAAQ,KAC3E,QACA,KAAA;GACN,QAAQ,KAAK;IAAE;IAAQ;IAAO;IAAQ,OAAO,eAAe,KAAA;GAAU,CAAC;GACvE,IAAI,YAAY,KAAK,YAAY;IAAE;IAAQ;GAAO,CAAC;EACvD;CACJ;CACA,KAAK,GAAG;CACR,OAAO;AACX;;;;;;;AAQA,SAAgB,4BAA4B,MAAgB,YAAiD;CACzG,MAAM,iBAAyC,CAAC;CAChD,MAAM,YAA0B,QAAQ,KAAK,WAAW;EACpD,IAAI,OAAO,OAAO,gBAAgB,MAAM,GAAG,OAAO,eAAe;EACjE,MAAM,iBAAiB,UAAU,WAAW,YAAY,OAAO,MAAM;EACrE,MAAM,WAAW,WAAW,KAAA,IACtB,aACA,gBAAgB,SAAS,QAAQ,eAAe,aAAa,KAAA;EACnE,MAAM,OAAO,QAAQ,GAAG;EACxB,MAAM,OAAO,YAAY,CAAC,OAAO,OAAO,UAAU,GAAG,KAAK,OAAO,OAAO,UAAU,IAAI,IAAI,OAAO;EACjG,OAAO,WAAW,KAAA,IAAY,OAAO,GAAG,OAAO,UAAU,OAAO,OAAO,GAAG;CAC9E;CACA,KAAK,MAAM,OAAO,MAAM;EACpB,IAAI,CAAC,KAAK;EACV,KAAK,MAAM,EAAE,QAAQ,YAAY,cAAc,KAAgC,YAAY,QAAQ,GAC/F,eAAe,YAAY,UAAU;CAE7C;CACA,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"import_columns.js","names":[],"sources":["../../../src/data_import/utils/import_columns.ts"],"sourcesContent":["import { Properties, Property } from \"@rebasepro/cms-types\";\nimport { isPrototypePollutingKey, slugify } from \"@rebasepro/utils\";\nimport { getPropertyInPath } from \"../../util\";\n\n/**\n * Whether a property's value is an object the import takes whole, from one\n * column: a geopoint, a vector, or a map that declares no fields (a key-value\n * map). These are the values the export writes as objects — in a JSON file\n * as the object, in a CSV cell as its JSON — and splitting one into\n * `location.latitude` columns left it in columns no property holds: it was\n * dropped without a word.\n *\n * Any other object is read one column per key: a map with declared fields\n * field by field, as the export writes it, and an object no property takes\n * so that its keys can be mapped one by one.\n */\nexport function takesObjectWhole(property: Property): boolean {\n return property.type === \"geopoint\"\n || property.type === \"vector\"\n || (property.type === \"map\" && property.properties === undefined);\n}\n\n/** One column of an imported row, as the mapping step lists it. */\nexport type ImportColumn = {\n /** The column's name: a key of the row, or `parent.key` below one. */\n column: string;\n value: unknown;\n /** The property path it lands in, or `null` for none. */\n target: string | null;\n /** Its value is an object that is read as one column per key, listed after it. */\n split: boolean;\n};\n\n/**\n * Where a column lands: the property path for it, or `null` for none. A\n * column below another is given that parent; a top-level one is not.\n */\nexport type ColumnTarget = (column: string, key: string, parent?: Pick<ImportColumn, \"column\" | \"target\">) => string | null;\n\nfunction isObjectCell(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) && !(value instanceof Date);\n}\n\n/** The declared property at a path, and nothing inherited (`toString`). */\nfunction propertyAt(properties: Properties | undefined, path: string | null): Property | undefined {\n if (!properties || path === null) return undefined;\n const property = getPropertyInPath(properties, path);\n return property !== null && typeof property === \"object\" ? property : undefined;\n}\n\n/**\n * The columns of one imported row, parents before their children.\n *\n * Each key of the row is a column. A key whose value is an object is also\n * read as one column per key of that object (`address.street`) — unless the\n * property it lands in takes the object whole (see {@link takesObjectWhole}).\n *\n * The mapping step lists these columns and the conversion reads them, so both\n * get them from here: a list built one way and rows read another is a mapping\n * whose keys match nothing.\n */\nexport function importColumns(row: Record<string, unknown>,\n properties: Properties | undefined,\n targetOf: ColumnTarget): ImportColumn[] {\n const columns: ImportColumn[] = [];\n const walk = (object: Record<string, unknown>, parent?: Pick<ImportColumn, \"column\" | \"target\">) => {\n for (const key of Object.keys(object)) {\n // Keys come from the uploaded file, so a `__proto__` key would be\n // the prototype setter wherever it is used as one (class 22).\n if (isPrototypePollutingKey(key)) {\n console.warn(`Skipping column \"${key}\": a header may not reach the prototype chain`);\n continue;\n }\n const column = parent === undefined ? key : `${parent.column}.${key}`;\n const value = object[key];\n const target = targetOf(column, key, parent);\n const property = propertyAt(properties, target);\n const splitValue = isObjectCell(value) && !(property && takesObjectWhole(property))\n ? value\n : undefined;\n columns.push({ column, value, target, split: splitValue !== undefined });\n if (splitValue) walk(splitValue, { column, target });\n }\n };\n walk(row);\n return columns;\n}\n\n/**\n * The mapping the import starts from: each column of the file onto the\n * property with its name, or with its name slugged (`First Name` →\n * `first_name`); a column below a map onto that map's field. A column that\n * matches nothing keeps its own name, for the person importing to map.\n */\nexport function buildHeadersMappingFromData(rows: object[], properties?: Properties): Record<string, string> {\n const headersMapping: Record<string, string> = {};\n const targetOf: ColumnTarget = (column, key, parent) => {\n if (Object.hasOwn(headersMapping, column)) return headersMapping[column];\n const parentProperty = parent && propertyAt(properties, parent.target);\n const siblings = parent === undefined\n ? properties\n : parentProperty?.type === \"map\" ? parentProperty.properties : undefined;\n const slug = slugify(key);\n const name = siblings && !Object.hasOwn(siblings, key) && Object.hasOwn(siblings, slug) ? slug : key;\n return parent === undefined ? name : `${parent.target ?? parent.column}.${name}`;\n };\n for (const row of rows) {\n if (!row) continue;\n for (const { column, target } of importColumns(row as Record<string, unknown>, properties, targetOf)) {\n headersMapping[column] ??= target ?? column;\n }\n }\n return headersMapping;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAAgB,iBAAiB,UAA6B;CAC1D,OAAO,SAAS,SAAS,cAClB,SAAS,SAAS,YACjB,SAAS,SAAS,SAAS,SAAS,eAAe,KAAA;AAC/D;AAmBA,SAAS,aAAa,OAAkD;CACpE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,KAAK,EAAE,iBAAiB;AACtG;;AAGA,SAAS,WAAW,YAAoC,MAA2C;CAC/F,IAAI,CAAC,cAAc,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AAO,WAAW,KAAA,IAAY,OAAO,GAAG,OAAO,UAAU,OAAO,OAAO,GAAG;CAC9E;CACA,KAAK,MAAM,OAAO,MAAM;EACpB,IAAI,CAAC,KAAK;EACV,KAAK,MAAM,EAAE,QAAQ,YAAY,cAAc,KAAgC,YAAY,QAAQ,GAC/F,eAAe,YAAY,UAAU;CAE7C;CACA,OAAO;AACX"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CollectionConfig, TableAccessor, Entity } from "@rebasepro/cms-types";
|
|
2
2
|
/**
|
|
3
3
|
* The reads and writes an import makes through a collection accessor. A
|
|
4
4
|
* `RebaseData` accessor is one, and so is any source that can find rows by id
|
|
5
5
|
* and create and update them.
|
|
6
6
|
*/
|
|
7
|
-
export type ImportAccessor = Pick<
|
|
7
|
+
export type ImportAccessor = Pick<TableAccessor, "find" | "findById" | "create" | "update" | "createMany" | "updateMany">;
|
|
8
8
|
/**
|
|
9
9
|
* Rows written per request, and per transaction where the data source has one.
|
|
10
10
|
*
|
|
@@ -56,7 +56,7 @@ export interface ImportSaveError extends Error {
|
|
|
56
56
|
* @throws {ImportSaveError} naming the rows that were not written.
|
|
57
57
|
*/
|
|
58
58
|
export declare function saveImportedEntities(dataClient: {
|
|
59
|
-
|
|
59
|
+
table(slug: string): ImportAccessor;
|
|
60
60
|
}, path: string, data: Partial<Entity<any>>[], { offset, batchSize, maxBatchBytes, onBatchCommitted, bulkUnsupported, collection }?: {
|
|
61
61
|
offset?: number;
|
|
62
62
|
batchSize?: number;
|
|
@@ -209,7 +209,7 @@ async function writeBatch(accessor, batch, bulkUnsupported, written, collection)
|
|
|
209
209
|
*/
|
|
210
210
|
async function saveImportedEntities(dataClient, path, data, { offset = 0, batchSize = 500, maxBatchBytes = IMPORT_BATCH_MAX_BYTES, onBatchCommitted = () => void 0, bulkUnsupported = { current: false }, collection } = {}) {
|
|
211
211
|
console.debug("Saving imported data", offset, batchSize);
|
|
212
|
-
const accessor = dataClient.
|
|
212
|
+
const accessor = dataClient.table(path);
|
|
213
213
|
let maxRows = Math.max(1, batchSize);
|
|
214
214
|
let start = offset;
|
|
215
215
|
while (start < data.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"save_entities.js","names":[],"sources":["../../../src/data_import/utils/save_entities.ts"],"sourcesContent":["import type { CollectionAccessor, CollectionConfig, Entity } from \"@rebasepro/types\";\nimport { findEntitiesByIds } from \"../../util/find_entities_by_ids\";\n\n/**\n * The reads and writes an import makes through a collection accessor. A\n * `RebaseData` accessor is one, and so is any source that can find rows by id\n * and create and update them.\n */\nexport type ImportAccessor = Pick<CollectionAccessor, \"find\" | \"findById\" | \"create\" | \"update\" | \"createMany\" | \"updateMany\">;\n\n/**\n * Rows written per request, and per transaction where the data source has one.\n *\n * It was 25, which made a 10,000-row import 400 sequential round trips. The\n * server takes up to 1,000 rows per `POST /bulk`; 500 keeps a failed batch's\n * rollback small enough to retry, and the byte cap below bounds the body.\n */\nexport const IMPORT_BATCH_SIZE = 500;\n\n/**\n * The most JSON one batch carries, in UTF-8 bytes. ~1 MB: a tenth of the\n * server's default body limit (10 MB, `maxBodySize`), and under the 1 MiB a\n * reverse proxy commonly allows by default (nginx's `client_max_body_size`),\n * so wide rows shrink the batch instead of failing it with a 413. A row larger\n * than this still goes, alone.\n */\nexport const IMPORT_BATCH_MAX_BYTES = 1_000_000;\n\n/**\n * An import failure that says where it stopped.\n *\n * \"Error saving data / null value in column \"sku\" violates not-null constraint\"\n * on a ten-thousand-row import named no row, and the Retry button restarted at\n * zero — where the rows already written now conflicted, so it could never\n * succeed. Both halves of that are what this carries.\n */\nexport interface ImportSaveError extends Error {\n /** Rows written and confirmed before the failure. Where a retry resumes. */\n committed: number;\n /** Index of the first row that was not written, 0-based. */\n failedFrom: number;\n /** Index after the last row of the batch that was not written. */\n failedTo: number;\n /**\n * Index of the row the server named as the cause, 0-based, when it named\n * one (`Row 37: …` — every server message about one row of a bulk write\n * starts that way, counted within the batch). The message is rewritten to\n * name it the way the file does: from 1, counted from the first row.\n */\n failedRow?: number;\n}\n\n/** The row a bulk write takes: the values, with the chosen id as a column. */\nfunction toBulkRow(entity: Partial<Entity<any>>): Record<string, unknown> {\n const values = { ...(entity.values ?? {}) } as Record<string, unknown>;\n if (entity.id !== undefined && entity.id !== null && entity.id !== \"\") {\n // Exactly what single-row `create(values, id)` puts on the wire.\n values.id = entity.id;\n }\n return values;\n}\n\nfunction isBulkUnsupported(error: unknown): boolean {\n if ((error as { code?: string })?.code === \"BULK_UNSUPPORTED\") return true;\n const message = (error as Error)?.message ?? \"\";\n return /bulk writes are not supported|does not support bulk/i.test(message);\n}\n\n/** The body was refused for its size: a proxy's or the server's 413, or too many rows. */\nfunction isTooLarge(error: unknown): boolean {\n const status = (error as { status?: number; statusCode?: number })?.status\n ?? (error as { statusCode?: number })?.statusCode;\n if (status === 413) return true;\n const code = (error as { code?: string })?.code;\n return code === \"PAYLOAD_TOO_LARGE\" || code === \"BULK_TOO_LARGE\";\n}\n\n/** The length of a string in UTF-8 bytes, which is what a body limit counts. */\nfunction utf8Length(text: string): number {\n let bytes = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code < 0x80) bytes += 1;\n else if (code < 0x800) bytes += 2;\n else if (code >= 0xD800 && code <= 0xDBFF) {\n bytes += 4;\n i++;\n } else bytes += 3;\n }\n return bytes;\n}\n\n/** `{\"rows\":[`, `],\"upsert\":true}` and some slack. */\nconst BULK_ENVELOPE_BYTES = 64;\n\n/**\n * Where the batch starting at `start` ends: at `maxRows` rows, or before the\n * row that would take the body past `maxBytes` — never before one row.\n */\nfunction batchEnd(data: Partial<Entity<any>>[], start: number, maxRows: number, maxBytes: number): number {\n let bytes = BULK_ENVELOPE_BYTES;\n let end = start;\n while (end < data.length && end - start < maxRows) {\n const rowBytes = utf8Length(JSON.stringify(toBulkRow(data[end]))) + 1;\n if (end > start && bytes + rowBytes > maxBytes) break;\n bytes += rowBytes;\n end++;\n }\n return end;\n}\n\n/**\n * The row a server message names, counted within the batch, and the message\n * with that row counted the way the user's file counts it.\n */\nfunction locateFailedRow(error: unknown, start: number): { row: number, message: string } | undefined {\n const message = (error as Error)?.message;\n if (typeof message !== \"string\") return undefined;\n const match = /^Row (\\d+)(?: of \\d+)?/.exec(message);\n if (!match) return undefined;\n const row = start + Number(match[1]);\n return { row, message: `Row ${row + 1}` + message.slice(match[0].length) };\n}\n\nfunction isConflict(error: unknown): boolean {\n const status = (error as { status?: number; statusCode?: number })?.status\n ?? (error as { statusCode?: number })?.statusCode;\n if (status === 409) return true;\n const code = (error as { code?: string })?.code;\n return code === \"CONFLICT\" || code === \"23505\";\n}\n\n/**\n * The server refused a row only for the required columns it leaves out.\n *\n * `POST /bulk` with `upsert: true` judges each row as a create, since it may\n * insert, so a row meant to update a stored record with some of its columns\n * (`id,price`) is refused as `'name' is required`.\n */\nfunction isMissingRequiredOnly(error: unknown): boolean {\n const violations = (error as { details?: { violations?: unknown } })?.details?.violations;\n return Array.isArray(violations) && violations.length > 0\n && violations.every(v => (v as { code?: unknown })?.code === \"required\");\n}\n\n/**\n * Whether the collection's rows are the users, read the way the server reads it\n * (`collection.auth`, `true` or `{ enabled: true }`).\n *\n * The server refuses an upsert there: a create hashes the password and runs\n * `onCreateUser`, an update may not demote the last administrator, and an\n * upsert decides between the two too late to follow either rule.\n */\nfunction isAuthCollection(collection: CollectionConfig | undefined): boolean {\n const auth = collection?.auth;\n return auth === true || (!!auth && typeof auth === \"object\" && auth.enabled === true);\n}\n\n/**\n * The row a user creation takes. A row that carries a `password` asks the\n * server to waive its password policy (`skipPasswordPolicy`): the accounts in\n * an import had their passwords set under another system's rules. The server\n * honours it only for an administrator.\n */\nfunction toUserCreationRow(entity: Partial<Entity<any>>): Record<string, unknown> {\n const row = toBulkRow(entity);\n return typeof row.password === \"string\" && row.password !== \"\" ? { ...row, skipPasswordPolicy: true } : row;\n}\n\n/**\n * A batch split by whether each row's id is stored: the rows whose id is\n * stored are updates — the given columns are written, the rest keep their\n * values, as the per-row path and the preview's \"overwritten\" say — and the\n * others are created, where a new row still needs every required column. A\n * refusal of one of those names its row in `batch`.\n *\n * Used when the bulk upsert refused a batch for missing required columns\n * (the creates then go back as an upsert), and for every batch of the auth\n * collection, which takes no upsert (the creates go as a plain bulk create,\n * which the server runs through user creation).\n */\nasync function writeUpdatesAndCreates(accessor: ImportAccessor,\n batch: Partial<Entity<any>>[],\n collection: CollectionConfig,\n createMany: NonNullable<CollectionAccessor[\"createMany\"]>,\n upsert: boolean): Promise<void> {\n\n const ids = batch.map(entity => entity.id).filter((id): id is string | number => id !== undefined && id !== null && id !== \"\");\n const stored = await findEntitiesByIds(accessor, collection, ids);\n const isUpdate = (entity: Partial<Entity<any>>) => entity.id !== undefined && entity.id !== null && stored.has(String(entity.id));\n\n const updates = batch.filter(isUpdate);\n if (updates.length > 0) {\n if (accessor.updateMany) {\n await accessor.updateMany(updates.map(entity => ({ id: entity.id as string | number, data: entity.values ?? {} })));\n } else {\n for (const entity of updates) await accessor.update(entity.id as string | number, entity.values ?? {});\n }\n }\n\n const creates = batch.map((entity, index) => ({ entity, index })).filter(({ entity }) => !isUpdate(entity));\n if (creates.length === 0) return;\n try {\n const rows = creates.map(({ entity }) => isAuthCollection(collection) ? toUserCreationRow(entity) : toBulkRow(entity));\n await (upsert ? createMany(rows, { upsert: true }) : createMany(rows));\n } catch (e) {\n // \"Row 1\" of the rows sent is \"Row <n>\" of the batch.\n const message = (e as Error)?.message;\n const match = typeof message === \"string\" ? /^Row (\\d+)/.exec(message) : null;\n if (match && creates[Number(match[1])]) {\n (e as Error).message = `Row ${creates[Number(match[1])].index}` + message.slice(match[0].length);\n }\n throw e;\n }\n}\n\n/**\n * Write one batch, all-or-nothing wherever the data source can.\n *\n * `POST /<collection>/bulk` validates every row before the transaction opens,\n * names a failure by row index, and takes the `upsert` flag the preview screen\n * promises — none of which one `create` per row inside a `Promise.all` could\n * offer, since `Promise.all` does not cancel its siblings and every request was\n * its own transaction.\n */\nasync function writeBatch(accessor: ImportAccessor,\n batch: Partial<Entity<any>>[],\n bulkUnsupported: { current: boolean },\n written: { count: number },\n collection: CollectionConfig | undefined): Promise<void> {\n\n if (accessor.createMany && !bulkUnsupported.current) {\n try {\n if (collection && isAuthCollection(collection)) {\n // Not one transaction: the updates are written before the\n // creates, and a retry of the batch writes them again, to the\n // same values — while a stored id among the creates is a\n // conflict, never an overwrite of a user's password.\n await writeUpdatesAndCreates(accessor, batch, collection, accessor.createMany.bind(accessor), false);\n written.count = batch.length;\n return;\n }\n await accessor.createMany(batch.map(toBulkRow), { upsert: true });\n written.count = batch.length;\n return;\n } catch (e) {\n if (collection && !isAuthCollection(collection) && isMissingRequiredOnly(e) && batch.some(entity => entity.id !== undefined && entity.id !== null && entity.id !== \"\")) {\n // Not one transaction any more: a refused create leaves the\n // updates before it written, and a retry of the batch writes\n // them again, to the same values.\n await writeUpdatesAndCreates(accessor, batch, collection, accessor.createMany.bind(accessor), true);\n written.count = batch.length;\n return;\n }\n if (!isBulkUnsupported(e)) throw e;\n // A data source without bulk writes: remember it, so the failed\n // round trip is not paid again on every later batch.\n bulkUnsupported.current = true;\n }\n }\n\n // Sequential, not `Promise.all`: a rejected write does not cancel its\n // siblings, so a parallel batch commits an indeterminate subset of itself\n // and nobody can say which rows landed.\n const usersCollection = !!collection && isAuthCollection(collection);\n for (const entity of batch) {\n try {\n const values = usersCollection\n ? toUserCreationRow({ values: entity.values })\n : entity.values ?? {};\n await accessor.create(values, entity.id);\n } catch (e) {\n // Without `/bulk` there is no upsert, so the preview's promise is\n // honoured the only way left: a row that collided on an id the user\n // supplied is overwritten. A row with no id had nothing to collide\n // on, and every other failure is still a failure.\n if (entity.id === undefined || !isConflict(e)) throw e;\n await accessor.update(entity.id, entity.values ?? {});\n }\n written.count++;\n }\n}\n\n/**\n * Write imported entities in batches, reporting what was committed.\n *\n * Resumable on purpose: a failure at row 4 000 leaves rows 1–3 999 in the table\n * whatever this does, so the only useful thing to report is where to carry on\n * from. `offset` is that point — the Retry button passes back the `committed`\n * count of the error it is retrying, instead of starting from zero and\n * conflicting on every row that already exists.\n *\n * @throws {ImportSaveError} naming the rows that were not written.\n */\nexport async function saveImportedEntities(dataClient: { collection(slug: string): ImportAccessor },\n path: string,\n data: Partial<Entity<any>>[],\n {\n offset = 0,\n batchSize = IMPORT_BATCH_SIZE,\n maxBatchBytes = IMPORT_BATCH_MAX_BYTES,\n onBatchCommitted = () => undefined,\n bulkUnsupported = { current: false },\n collection\n }: {\n offset?: number;\n batchSize?: number;\n /** See {@link IMPORT_BATCH_MAX_BYTES}. */\n maxBatchBytes?: number;\n onBatchCommitted?: (rowsWritten: number) => void;\n bulkUnsupported?: { current: boolean };\n /**\n * The collection written to. With it, a row that updates a stored\n * record with some of its columns is written as an update rather\n * than refused for the required columns it leaves out.\n */\n collection?: CollectionConfig;\n } = {}): Promise<void> {\n\n console.debug(\"Saving imported data\", offset, batchSize);\n\n const accessor = dataClient.collection(path);\n\n // Lowered for the rest of the import when a batch is refused for its\n // size — a server or proxy configured below the byte cap — so an import\n // that worked in small batches does not fail in large ones.\n let maxRows = Math.max(1, batchSize);\n let start = offset;\n while (start < data.length) {\n const batch = data.slice(start, batchEnd(data, start, maxRows, maxBatchBytes));\n const written = { count: 0 };\n try {\n await writeBatch(accessor, batch, bulkUnsupported, written, collection);\n } catch (e) {\n if (written.count === 0 && batch.length > 1 && isTooLarge(e)) {\n maxRows = Math.max(1, Math.floor(batch.length / 2));\n continue;\n }\n const located = locateFailedRow(e, start + written.count);\n throw Object.assign(e as Error, {\n committed: start + written.count,\n failedFrom: start + written.count,\n failedTo: start + batch.length,\n ...(located ? { failedRow: located.row, message: located.message } : {})\n }) as ImportSaveError;\n }\n start += batch.length;\n onBatchCommitted(start);\n }\n\n onBatchCommitted(data.length);\n}\n"],"mappings":";;;;;;;;;AAiBA,IAAa,oBAAoB;;;;;;;;AASjC,IAAa,yBAAyB;;AA2BtC,SAAS,UAAU,QAA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SAAS,KAAK,WAAW,CAAC,GAAG;IAC1D,UAAU,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,SAAS,CAAC,CAAC;IAClD;GACJ;GACA,MAAM,UAAU,gBAAgB,GAAG,QAAQ,QAAQ,KAAK;GACxD,MAAM,OAAO,OAAO,GAAY;IAC5B,WAAW,QAAQ,QAAQ;IAC3B,YAAY,QAAQ,QAAQ;IAC5B,UAAU,QAAQ,MAAM;IACxB,GAAI,UAAU;KAAE,WAAW,QAAQ;KAAK,SAAS,QAAQ;IAAQ,IAAI,CAAC;GAC1E,CAAC;EACL;EACA,SAAS,MAAM;EACf,iBAAiB,KAAK;CAC1B;CAEA,iBAAiB,KAAK,MAAM;AAChC"}
|
|
1
|
+
{"version":3,"file":"save_entities.js","names":[],"sources":["../../../src/data_import/utils/save_entities.ts"],"sourcesContent":["import type { CollectionConfig, TableAccessor, Entity } from \"@rebasepro/cms-types\";\nimport { findEntitiesByIds } from \"../../util/find_entities_by_ids\";\n\n/**\n * The reads and writes an import makes through a collection accessor. A\n * `RebaseData` accessor is one, and so is any source that can find rows by id\n * and create and update them.\n */\nexport type ImportAccessor = Pick<TableAccessor, \"find\" | \"findById\" | \"create\" | \"update\" | \"createMany\" | \"updateMany\">;\n\n/**\n * Rows written per request, and per transaction where the data source has one.\n *\n * It was 25, which made a 10,000-row import 400 sequential round trips. The\n * server takes up to 1,000 rows per `POST /bulk`; 500 keeps a failed batch's\n * rollback small enough to retry, and the byte cap below bounds the body.\n */\nexport const IMPORT_BATCH_SIZE = 500;\n\n/**\n * The most JSON one batch carries, in UTF-8 bytes. ~1 MB: a tenth of the\n * server's default body limit (10 MB, `maxBodySize`), and under the 1 MiB a\n * reverse proxy commonly allows by default (nginx's `client_max_body_size`),\n * so wide rows shrink the batch instead of failing it with a 413. A row larger\n * than this still goes, alone.\n */\nexport const IMPORT_BATCH_MAX_BYTES = 1_000_000;\n\n/**\n * An import failure that says where it stopped.\n *\n * \"Error saving data / null value in column \"sku\" violates not-null constraint\"\n * on a ten-thousand-row import named no row, and the Retry button restarted at\n * zero — where the rows already written now conflicted, so it could never\n * succeed. Both halves of that are what this carries.\n */\nexport interface ImportSaveError extends Error {\n /** Rows written and confirmed before the failure. Where a retry resumes. */\n committed: number;\n /** Index of the first row that was not written, 0-based. */\n failedFrom: number;\n /** Index after the last row of the batch that was not written. */\n failedTo: number;\n /**\n * Index of the row the server named as the cause, 0-based, when it named\n * one (`Row 37: …` — every server message about one row of a bulk write\n * starts that way, counted within the batch). The message is rewritten to\n * name it the way the file does: from 1, counted from the first row.\n */\n failedRow?: number;\n}\n\n/** The row a bulk write takes: the values, with the chosen id as a column. */\nfunction toBulkRow(entity: Partial<Entity<any>>): Record<string, unknown> {\n const values = { ...(entity.values ?? {}) } as Record<string, unknown>;\n if (entity.id !== undefined && entity.id !== null && entity.id !== \"\") {\n // Exactly what single-row `create(values, id)` puts on the wire.\n values.id = entity.id;\n }\n return values;\n}\n\nfunction isBulkUnsupported(error: unknown): boolean {\n if ((error as { code?: string })?.code === \"BULK_UNSUPPORTED\") return true;\n const message = (error as Error)?.message ?? \"\";\n return /bulk writes are not supported|does not support bulk/i.test(message);\n}\n\n/** The body was refused for its size: a proxy's or the server's 413, or too many rows. */\nfunction isTooLarge(error: unknown): boolean {\n const status = (error as { status?: number; statusCode?: number })?.status\n ?? (error as { statusCode?: number })?.statusCode;\n if (status === 413) return true;\n const code = (error as { code?: string })?.code;\n return code === \"PAYLOAD_TOO_LARGE\" || code === \"BULK_TOO_LARGE\";\n}\n\n/** The length of a string in UTF-8 bytes, which is what a body limit counts. */\nfunction utf8Length(text: string): number {\n let bytes = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code < 0x80) bytes += 1;\n else if (code < 0x800) bytes += 2;\n else if (code >= 0xD800 && code <= 0xDBFF) {\n bytes += 4;\n i++;\n } else bytes += 3;\n }\n return bytes;\n}\n\n/** `{\"rows\":[`, `],\"upsert\":true}` and some slack. */\nconst BULK_ENVELOPE_BYTES = 64;\n\n/**\n * Where the batch starting at `start` ends: at `maxRows` rows, or before the\n * row that would take the body past `maxBytes` — never before one row.\n */\nfunction batchEnd(data: Partial<Entity<any>>[], start: number, maxRows: number, maxBytes: number): number {\n let bytes = BULK_ENVELOPE_BYTES;\n let end = start;\n while (end < data.length && end - start < maxRows) {\n const rowBytes = utf8Length(JSON.stringify(toBulkRow(data[end]))) + 1;\n if (end > start && bytes + rowBytes > maxBytes) break;\n bytes += rowBytes;\n end++;\n }\n return end;\n}\n\n/**\n * The row a server message names, counted within the batch, and the message\n * with that row counted the way the user's file counts it.\n */\nfunction locateFailedRow(error: unknown, start: number): { row: number, message: string } | undefined {\n const message = (error as Error)?.message;\n if (typeof message !== \"string\") return undefined;\n const match = /^Row (\\d+)(?: of \\d+)?/.exec(message);\n if (!match) return undefined;\n const row = start + Number(match[1]);\n return { row, message: `Row ${row + 1}` + message.slice(match[0].length) };\n}\n\nfunction isConflict(error: unknown): boolean {\n const status = (error as { status?: number; statusCode?: number })?.status\n ?? (error as { statusCode?: number })?.statusCode;\n if (status === 409) return true;\n const code = (error as { code?: string })?.code;\n return code === \"CONFLICT\" || code === \"23505\";\n}\n\n/**\n * The server refused a row only for the required columns it leaves out.\n *\n * `POST /bulk` with `upsert: true` judges each row as a create, since it may\n * insert, so a row meant to update a stored record with some of its columns\n * (`id,price`) is refused as `'name' is required`.\n */\nfunction isMissingRequiredOnly(error: unknown): boolean {\n const violations = (error as { details?: { violations?: unknown } })?.details?.violations;\n return Array.isArray(violations) && violations.length > 0\n && violations.every(v => (v as { code?: unknown })?.code === \"required\");\n}\n\n/**\n * Whether the collection's rows are the users, read the way the server reads it\n * (`collection.auth`, `true` or `{ enabled: true }`).\n *\n * The server refuses an upsert there: a create hashes the password and runs\n * `onCreateUser`, an update may not demote the last administrator, and an\n * upsert decides between the two too late to follow either rule.\n */\nfunction isAuthCollection(collection: CollectionConfig | undefined): boolean {\n const auth = collection?.auth;\n return auth === true || (!!auth && typeof auth === \"object\" && auth.enabled === true);\n}\n\n/**\n * The row a user creation takes. A row that carries a `password` asks the\n * server to waive its password policy (`skipPasswordPolicy`): the accounts in\n * an import had their passwords set under another system's rules. The server\n * honours it only for an administrator.\n */\nfunction toUserCreationRow(entity: Partial<Entity<any>>): Record<string, unknown> {\n const row = toBulkRow(entity);\n return typeof row.password === \"string\" && row.password !== \"\" ? { ...row, skipPasswordPolicy: true } : row;\n}\n\n/**\n * A batch split by whether each row's id is stored: the rows whose id is\n * stored are updates — the given columns are written, the rest keep their\n * values, as the per-row path and the preview's \"overwritten\" say — and the\n * others are created, where a new row still needs every required column. A\n * refusal of one of those names its row in `batch`.\n *\n * Used when the bulk upsert refused a batch for missing required columns\n * (the creates then go back as an upsert), and for every batch of the auth\n * collection, which takes no upsert (the creates go as a plain bulk create,\n * which the server runs through user creation).\n */\nasync function writeUpdatesAndCreates(accessor: ImportAccessor,\n batch: Partial<Entity<any>>[],\n collection: CollectionConfig,\n createMany: NonNullable<TableAccessor[\"createMany\"]>,\n upsert: boolean): Promise<void> {\n\n const ids = batch.map(entity => entity.id).filter((id): id is string | number => id !== undefined && id !== null && id !== \"\");\n const stored = await findEntitiesByIds(accessor, collection, ids);\n const isUpdate = (entity: Partial<Entity<any>>) => entity.id !== undefined && entity.id !== null && stored.has(String(entity.id));\n\n const updates = batch.filter(isUpdate);\n if (updates.length > 0) {\n if (accessor.updateMany) {\n await accessor.updateMany(updates.map(entity => ({ id: entity.id as string | number, data: entity.values ?? {} })));\n } else {\n for (const entity of updates) await accessor.update(entity.id as string | number, entity.values ?? {});\n }\n }\n\n const creates = batch.map((entity, index) => ({ entity, index })).filter(({ entity }) => !isUpdate(entity));\n if (creates.length === 0) return;\n try {\n const rows = creates.map(({ entity }) => isAuthCollection(collection) ? toUserCreationRow(entity) : toBulkRow(entity));\n await (upsert ? createMany(rows, { upsert: true }) : createMany(rows));\n } catch (e) {\n // \"Row 1\" of the rows sent is \"Row <n>\" of the batch.\n const message = (e as Error)?.message;\n const match = typeof message === \"string\" ? /^Row (\\d+)/.exec(message) : null;\n if (match && creates[Number(match[1])]) {\n (e as Error).message = `Row ${creates[Number(match[1])].index}` + message.slice(match[0].length);\n }\n throw e;\n }\n}\n\n/**\n * Write one batch, all-or-nothing wherever the data source can.\n *\n * `POST /<collection>/bulk` validates every row before the transaction opens,\n * names a failure by row index, and takes the `upsert` flag the preview screen\n * promises — none of which one `create` per row inside a `Promise.all` could\n * offer, since `Promise.all` does not cancel its siblings and every request was\n * its own transaction.\n */\nasync function writeBatch(accessor: ImportAccessor,\n batch: Partial<Entity<any>>[],\n bulkUnsupported: { current: boolean },\n written: { count: number },\n collection: CollectionConfig | undefined): Promise<void> {\n\n if (accessor.createMany && !bulkUnsupported.current) {\n try {\n if (collection && isAuthCollection(collection)) {\n // Not one transaction: the updates are written before the\n // creates, and a retry of the batch writes them again, to the\n // same values — while a stored id among the creates is a\n // conflict, never an overwrite of a user's password.\n await writeUpdatesAndCreates(accessor, batch, collection, accessor.createMany.bind(accessor), false);\n written.count = batch.length;\n return;\n }\n await accessor.createMany(batch.map(toBulkRow), { upsert: true });\n written.count = batch.length;\n return;\n } catch (e) {\n if (collection && !isAuthCollection(collection) && isMissingRequiredOnly(e) && batch.some(entity => entity.id !== undefined && entity.id !== null && entity.id !== \"\")) {\n // Not one transaction any more: a refused create leaves the\n // updates before it written, and a retry of the batch writes\n // them again, to the same values.\n await writeUpdatesAndCreates(accessor, batch, collection, accessor.createMany.bind(accessor), true);\n written.count = batch.length;\n return;\n }\n if (!isBulkUnsupported(e)) throw e;\n // A data source without bulk writes: remember it, so the failed\n // round trip is not paid again on every later batch.\n bulkUnsupported.current = true;\n }\n }\n\n // Sequential, not `Promise.all`: a rejected write does not cancel its\n // siblings, so a parallel batch commits an indeterminate subset of itself\n // and nobody can say which rows landed.\n const usersCollection = !!collection && isAuthCollection(collection);\n for (const entity of batch) {\n try {\n const values = usersCollection\n ? toUserCreationRow({ values: entity.values })\n : entity.values ?? {};\n await accessor.create(values, entity.id);\n } catch (e) {\n // Without `/bulk` there is no upsert, so the preview's promise is\n // honoured the only way left: a row that collided on an id the user\n // supplied is overwritten. A row with no id had nothing to collide\n // on, and every other failure is still a failure.\n if (entity.id === undefined || !isConflict(e)) throw e;\n await accessor.update(entity.id, entity.values ?? {});\n }\n written.count++;\n }\n}\n\n/**\n * Write imported entities in batches, reporting what was committed.\n *\n * Resumable on purpose: a failure at row 4 000 leaves rows 1–3 999 in the table\n * whatever this does, so the only useful thing to report is where to carry on\n * from. `offset` is that point — the Retry button passes back the `committed`\n * count of the error it is retrying, instead of starting from zero and\n * conflicting on every row that already exists.\n *\n * @throws {ImportSaveError} naming the rows that were not written.\n */\nexport async function saveImportedEntities(dataClient: { table(slug: string): ImportAccessor },\n path: string,\n data: Partial<Entity<any>>[],\n {\n offset = 0,\n batchSize = IMPORT_BATCH_SIZE,\n maxBatchBytes = IMPORT_BATCH_MAX_BYTES,\n onBatchCommitted = () => undefined,\n bulkUnsupported = { current: false },\n collection\n }: {\n offset?: number;\n batchSize?: number;\n /** See {@link IMPORT_BATCH_MAX_BYTES}. */\n maxBatchBytes?: number;\n onBatchCommitted?: (rowsWritten: number) => void;\n bulkUnsupported?: { current: boolean };\n /**\n * The collection written to. With it, a row that updates a stored\n * record with some of its columns is written as an update rather\n * than refused for the required columns it leaves out.\n */\n collection?: CollectionConfig;\n } = {}): Promise<void> {\n\n console.debug(\"Saving imported data\", offset, batchSize);\n\n const accessor = dataClient.table(path);\n\n // Lowered for the rest of the import when a batch is refused for its\n // size — a server or proxy configured below the byte cap — so an import\n // that worked in small batches does not fail in large ones.\n let maxRows = Math.max(1, batchSize);\n let start = offset;\n while (start < data.length) {\n const batch = data.slice(start, batchEnd(data, start, maxRows, maxBatchBytes));\n const written = { count: 0 };\n try {\n await writeBatch(accessor, batch, bulkUnsupported, written, collection);\n } catch (e) {\n if (written.count === 0 && batch.length > 1 && isTooLarge(e)) {\n maxRows = Math.max(1, Math.floor(batch.length / 2));\n continue;\n }\n const located = locateFailedRow(e, start + written.count);\n throw Object.assign(e as Error, {\n committed: start + written.count,\n failedFrom: start + written.count,\n failedTo: start + batch.length,\n ...(located ? { failedRow: located.row, message: located.message } : {})\n }) as ImportSaveError;\n }\n start += batch.length;\n onBatchCommitted(start);\n }\n\n onBatchCommitted(data.length);\n}\n"],"mappings":";;;;;;;;;AAiBA,IAAa,oBAAoB;;;;;;;;AASjC,IAAa,yBAAyB;;AA2BtC,SAAS,UAAU,QAAuD;CACtE,MAAM,SAAS,EAAE,GAAI,OAAO,UAAU,CAAC,EAAG;CAC1C,IAAI,OAAO,OAAO,KAAA,KAAa,OAAO,OAAO,QAAQ,OAAO,OAAO,IAE/D,OAAO,KAAK,OAAO;CAEvB,OAAO;AACX;AAEA,SAAS,kBAAkB,OAAyB;CAChD,IAAK,OAA6B,SAAS,oBAAoB,OAAO;CACtE,MAAM,UAAW,OAAiB,WAAW;CAC7C,OAAO,uDAAuD,KAAK,OAAO;AAC9E;;AAGA,SAAS,WAAW,OAAyB;CAGzC,KAFgB,OAAoD,UAC5D,OAAmC,gBAC5B,KAAK,OAAO;CAC3B,MAAM,OAAQ,OAA6B;CAC3C,OAAO,SAAS,uBAAuB,SAAS;AACpD;;AAGA,SAAS,WAAW,MAAsB;CACtC,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EAClC,MAAM,OAAO,KAAK,WAAW,CAAC;EAC9B,IAAI,OAAO,KAAM,SAAS;OACrB,IAAI,OAAO,MAAO,SAAS;OAC3B,IAAI,QAAQ,SAAU,QAAQ,OAAQ;GACvC,SAAS;GACT;EACJ,OAAO,SAAS;CACpB;CACA,OAAO;AACX;;AAGA,IAAM,sBAAsB;;;;;AAM5B,SAAS,SAAS,MAA8B,OAAe,SAAiB,UAA0B;CACtG,IAAI,QAAQ;CACZ,IAAI,MAAM;CACV,OAAO,MAAM,KAAK,UAAU,MAAM,QAAQ,SAAS;EAC/C,MAAM,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KAAK,IAAI,GAAG,SAAS;CACnC,IAAI,QAAQ;CACZ,OAAO,QAAQ,KAAK,QAAQ;EACxB,MAAM,QAAQ,KAAK,MAAM,OAAO,SAAS,MAAM,OAAO,SAAS,aAAa,CAAC;EAC7E,MAAM,UAAU,EAAE,OAAO,EAAE;EAC3B,IAAI;GACA,MAAM,WAAW,UAAU,OAAO,iBAAiB,SAAS,UAAU;EAC1E,SAAS,GAAG;GACR,IAAI,QAAQ,UAAU,KAAK,MAAM,SAAS,KAAK,WAAW,CAAC,GAAG;IAC1D,UAAU,KAAK,IAAI,GAAG,KAAK,MAAM,MAAM,SAAS,CAAC,CAAC;IAClD;GACJ;GACA,MAAM,UAAU,gBAAgB,GAAG,QAAQ,QAAQ,KAAK;GACxD,MAAM,OAAO,OAAO,GAAY;IAC5B,WAAW,QAAQ,QAAQ;IAC3B,YAAY,QAAQ,QAAQ;IAC5B,UAAU,QAAQ,MAAM;IACxB,GAAI,UAAU;KAAE,WAAW,QAAQ;KAAK,SAAS,QAAQ;IAAQ,IAAI,CAAC;GAC1E,CAAC;EACL;EACA,SAAS,MAAM;EACf,iBAAiB,KAAK;CAC1B;CAEA,iBAAiB,KAAK,MAAM;AAChC"}
|
package/dist/form/EntityForm.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasEntityId } from "../util/identity.js";
|
|
1
2
|
import { FormDomScopeContext, domScopeFromId } from "./form_dom_ids.js";
|
|
2
3
|
import { formViewer, resolvePropertiesForValidation, withoutUnwritableDefaults } from "./resolve_form_properties.js";
|
|
3
4
|
import { FormUploadsContext, createFormUploadTracker } from "./form_uploads.js";
|
|
@@ -18,7 +19,7 @@ import { Suspense, useCallback, useEffect, useId, useMemo, useRef, useState } fr
|
|
|
18
19
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
20
|
import { deepEqual } from "fast-equals";
|
|
20
21
|
import { Alert, Button, CircularProgressCenter, Dialog, DialogActions, DialogContent, DialogTitle, ErrorBoundary, Typography, cls, defaultBorderMixin, isKeyHandled, useDebouncedCallback } from "@rebasepro/ui";
|
|
21
|
-
import { getCopyValues, getDefaultValuesFor
|
|
22
|
+
import { getCopyValues, getDefaultValuesFor } from "@rebasepro/cms-types";
|
|
22
23
|
import { entityOfRow, flattenKeys, getFormFieldKeys, idOfRow, isDisabled, isReadOnly, resolveFormLayout, rowOfEntity, useAuthController, useCustomizationController, useTranslation } from "@rebasepro/app";
|
|
23
24
|
import { Formex, useCreateFormex } from "@rebasepro/forms";
|
|
24
25
|
//#region src/form/EntityForm.tsx
|