@donotdev/crud 0.0.8 → 0.0.10
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/dist/CrudService.d.ts +30 -60
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.js +1 -1
- package/dist/CrudStore.d.ts +1 -94
- package/dist/CrudStore.d.ts.map +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/adapters/FirestoreAdapter.d.ts +3 -1
- package/dist/adapters/FirestoreAdapter.d.ts.map +1 -1
- package/dist/adapters/FirestoreAdapter.js +1 -1
- package/dist/adapters/FunctionsAdapter.d.ts +8 -1
- package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/builtinFieldTypes.d.ts +17 -4
- package/dist/builtinFieldTypes.d.ts.map +1 -1
- package/dist/builtinFieldTypes.js +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/DisplayFieldRenderer.d.ts +2 -0
- package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/EntityDisplayRenderer.d.ts +3 -3
- package/dist/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/components/EntityDisplayRenderer.js +1 -1
- package/dist/components/EntityFilters.d.ts +61 -0
- package/dist/components/EntityFilters.d.ts.map +1 -0
- package/dist/components/EntityFilters.js +1 -0
- package/dist/components/EntityFormRenderer.d.ts +22 -1
- package/dist/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/components/EntityFormRenderer.js +1 -1
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
- package/dist/components/controlled/complex/ControlledDateField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledDateField.js +1 -1
- package/dist/components/controlled/complex/ControlledGeoPointField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledGeoPointField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
- package/dist/components/controlled/complex/ControlledMapField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledMapField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledMapField.js +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
- package/dist/components/controlled/complex/ControlledRichTextField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledRichTextField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.d.ts +3 -0
- package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
- package/dist/components/controlled/complex/index.d.ts.map +1 -1
- package/dist/components/controlled/complex/index.js +1 -1
- package/dist/components/controlled/file/ControlledDocumentField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledDocumentField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledFileField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledImageField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledMultiFileField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.d.ts +3 -0
- package/dist/components/controlled/file/ControlledMultiImageField.d.ts.map +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/controlled/file/index.d.ts.map +1 -1
- package/dist/components/controlled/file/index.js +1 -1
- package/dist/components/controlled/index.d.ts +4 -0
- package/dist/components/controlled/index.d.ts.map +1 -1
- package/dist/components/controlled/index.js +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledCheckboxField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.d.ts +8 -0
- package/dist/components/controlled/input/ControlledCurrencyField.d.ts.map +1 -0
- package/dist/components/controlled/input/ControlledCurrencyField.js +1 -0
- package/dist/components/controlled/input/ControlledGdprConsentField.d.ts +8 -0
- package/dist/components/controlled/input/ControlledGdprConsentField.d.ts.map +1 -0
- package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -0
- package/dist/components/controlled/input/ControlledNumberField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledNumberField.js +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.d.ts +8 -0
- package/dist/components/controlled/input/ControlledPriceField.d.ts.map +1 -0
- package/dist/components/controlled/input/ControlledPriceField.js +1 -0
- package/dist/components/controlled/input/ControlledRangeField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledRangeField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.d.ts +8 -0
- package/dist/components/controlled/input/ControlledRatingField.d.ts.map +1 -0
- package/dist/components/controlled/input/ControlledRatingField.js +1 -0
- package/dist/components/controlled/input/ControlledSwitchField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledSwitchField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
- package/dist/components/controlled/input/ControlledTextField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledTextField.js +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.d.ts +3 -0
- package/dist/components/controlled/input/ControlledTextareaField.d.ts.map +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
- package/dist/components/controlled/input/index.d.ts +4 -0
- package/dist/components/controlled/input/index.d.ts.map +1 -1
- package/dist/components/controlled/input/index.js +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.d.ts +4 -0
- package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.d.ts +4 -0
- package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts +4 -0
- package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledRadioField.d.ts +4 -0
- package/dist/components/controlled/select/ControlledRadioField.d.ts.map +1 -1
- package/dist/components/controlled/select/ControlledRadioField.js +1 -1
- package/dist/components/controlled/select/ControlledYearField.d.ts +9 -0
- package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -0
- package/dist/components/controlled/select/ControlledYearField.js +1 -0
- package/dist/components/controlled/select/index.d.ts +1 -0
- package/dist/components/controlled/select/index.d.ts.map +1 -1
- package/dist/components/controlled/select/index.js +1 -1
- package/dist/components/controlled/types.d.ts +6 -0
- package/dist/components/controlled/types.d.ts.map +1 -1
- package/dist/components/controlled/types.js +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.d.ts +23 -0
- package/dist/components/fields/display/AvatarFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/AvatarFieldDisplay.js +1 -0
- package/dist/components/fields/display/BadgeFieldDisplay.d.ts +21 -0
- package/dist/components/fields/display/BadgeFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -0
- package/dist/components/fields/display/ButtonFieldDisplay.d.ts +29 -0
- package/dist/components/fields/display/ButtonFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/ButtonFieldDisplay.js +1 -0
- package/dist/components/fields/display/CheckboxFieldDisplay.d.ts +21 -0
- package/dist/components/fields/display/CheckboxFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -0
- package/dist/components/fields/display/DateFieldDisplay.d.ts +24 -0
- package/dist/components/fields/display/DateFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/DateFieldDisplay.js +1 -0
- package/dist/components/fields/display/DropdownDisplay.d.ts +21 -0
- package/dist/components/fields/display/DropdownDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/DropdownDisplay.js +1 -0
- package/dist/components/fields/display/FileFieldDisplay.d.ts +21 -0
- package/dist/components/fields/display/FileFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/FileFieldDisplay.js +1 -0
- package/dist/components/fields/display/GeoPointFieldDisplay.d.ts +25 -0
- package/dist/components/fields/display/GeoPointFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -0
- package/dist/components/fields/display/HiddenFieldDisplay.d.ts +30 -0
- package/dist/components/fields/display/HiddenFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/HiddenFieldDisplay.js +1 -0
- package/dist/components/fields/display/ImageFieldDisplay.d.ts +24 -0
- package/dist/components/fields/display/ImageFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/ImageFieldDisplay.js +1 -0
- package/dist/components/fields/display/LinkFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/LinkFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/LinkFieldDisplay.js +1 -0
- package/dist/components/fields/display/MapFieldDisplay.d.ts +25 -0
- package/dist/components/fields/display/MapFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/MapFieldDisplay.js +1 -0
- package/dist/components/fields/display/MultiDropdownDisplay.d.ts +22 -0
- package/dist/components/fields/display/MultiDropdownDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/MultiDropdownDisplay.js +1 -0
- package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -0
- package/dist/components/fields/display/NumberFieldDisplay.d.ts +24 -0
- package/dist/components/fields/display/NumberFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -0
- package/dist/components/fields/display/PasswordFieldDisplay.d.ts +24 -0
- package/dist/components/fields/display/PasswordFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -0
- package/dist/components/fields/display/PhoneNumberDisplay.d.ts +22 -0
- package/dist/components/fields/display/PhoneNumberDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/PhoneNumberDisplay.js +1 -0
- package/dist/components/fields/display/RadioFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/RadioFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/RadioFieldDisplay.js +1 -0
- package/dist/components/fields/display/RangeFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/RangeFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/RangeFieldDisplay.js +1 -0
- package/dist/components/fields/display/ReferenceFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/ReferenceFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -0
- package/dist/components/fields/display/RichTextDisplay.d.ts +25 -0
- package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/RichTextDisplay.js +61 -0
- package/dist/components/fields/display/TextAreaDisplay.d.ts +22 -0
- package/dist/components/fields/display/TextAreaDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/TextAreaDisplay.js +1 -0
- package/dist/components/fields/display/TextFieldDisplay.d.ts +42 -0
- package/dist/components/fields/display/TextFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/TextFieldDisplay.js +1 -0
- package/dist/components/fields/display/TimestampFieldDisplay.d.ts +22 -0
- package/dist/components/fields/display/TimestampFieldDisplay.d.ts.map +1 -0
- package/dist/components/fields/display/TimestampFieldDisplay.js +1 -0
- package/dist/components/fields/display/index.d.ts +32 -0
- package/dist/components/fields/display/index.d.ts.map +1 -0
- package/dist/components/fields/display/index.js +1 -0
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.d.ts +3 -3
- package/dist/components/form/fields/CheckboxFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
- package/dist/components/form/fields/ComboboxComponent.d.ts +6 -0
- package/dist/components/form/fields/ComboboxComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ComboboxComponent.js +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.d.ts +26 -0
- package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -0
- package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -0
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.d.ts +3 -2
- package/dist/components/form/fields/ImageFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MapFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/PriceFieldComponent.d.ts +34 -0
- package/dist/components/form/fields/PriceFieldComponent.d.ts.map +1 -0
- package/dist/components/form/fields/PriceFieldComponent.js +1 -0
- package/dist/components/form/fields/RadioFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/RatingFieldComponent.d.ts +37 -0
- package/dist/components/form/fields/RatingFieldComponent.d.ts.map +1 -0
- package/dist/components/form/fields/RatingFieldComponent.js +1 -0
- package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
- package/dist/components/form/fields/RichTextComponent.d.ts +2 -21
- package/dist/components/form/fields/RichTextComponent.d.ts.map +1 -1
- package/dist/components/form/fields/RichTextComponent.js +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/components/form/fields/TextFieldComponent.js +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
- package/dist/components/form/fields/index.d.ts +7 -1
- package/dist/components/form/fields/index.d.ts.map +1 -1
- package/dist/components/form/fields/index.js +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.d.ts +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
- package/dist/components/form/fields/types.d.ts +33 -0
- package/dist/components/form/fields/types.d.ts.map +1 -0
- package/dist/components/form/fields/types.js +0 -0
- package/dist/components/form/internal/ImageViewerDialog.d.ts +2 -1
- package/dist/components/form/internal/ImageViewerDialog.d.ts.map +1 -1
- package/dist/components/form/internal/ImageViewerDialog.js +1 -1
- package/dist/components/index.d.ts +4 -8
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/contexts/UploadContext.d.ts.map +1 -1
- package/dist/contexts/UploadContext.js +1 -1
- package/dist/contexts/index.js +1 -1
- package/dist/fieldTypeRegistry.d.ts +92 -0
- package/dist/fieldTypeRegistry.d.ts.map +1 -0
- package/dist/fieldTypeRegistry.js +1 -0
- package/dist/forms/hooks/index.js +1 -1
- package/dist/forms/hooks/useController.js +1 -1
- package/dist/forms/hooks/useEntityField.js +1 -1
- package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/index.d.ts +2 -2
- package/dist/forms/index.d.ts.map +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/types.d.ts +15 -0
- package/dist/forms/types.d.ts.map +1 -1
- package/dist/forms/utils/getFieldsForOperation.js +1 -1
- package/dist/forms/utils/index.d.ts +0 -2
- package/dist/forms/utils/index.d.ts.map +1 -1
- package/dist/forms/utils/index.js +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEntityFavorites.d.ts +53 -0
- package/dist/hooks/useEntityFavorites.d.ts.map +1 -0
- package/dist/hooks/useEntityFavorites.js +1 -0
- package/dist/hooks/useFileUpload.d.ts.map +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useFormNavigationGuard.d.ts +34 -0
- package/dist/hooks/useFormNavigationGuard.d.ts.map +1 -0
- package/dist/hooks/useFormNavigationGuard.js +1 -0
- package/dist/hooks/useRelatedItems.d.ts +37 -0
- package/dist/hooks/useRelatedItems.d.ts.map +1 -0
- package/dist/hooks/useRelatedItems.js +1 -0
- package/dist/hooks/useUnsavedChangesWarning.d.ts +51 -0
- package/dist/hooks/useUnsavedChangesWarning.d.ts.map +1 -0
- package/dist/hooks/useUnsavedChangesWarning.js +1 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts +6 -0
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -0
- package/dist/registerBuiltinFieldTypes.js +1 -0
- package/dist/stores/FormStore.d.ts +17 -0
- package/dist/stores/FormStore.d.ts.map +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.d.ts.map +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +202 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/dist/useBaseCrudList.d.ts +53 -0
- package/dist/useBaseCrudList.d.ts.map +1 -0
- package/dist/useBaseCrudList.js +1 -0
- package/dist/useCrud.d.ts +4 -8
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.d.ts +10 -4
- package/dist/useCrudCardList.d.ts.map +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudList.d.ts +19 -5
- package/dist/useCrudList.d.ts.map +1 -1
- package/dist/useCrudList.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/fileStorage.js +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/imageStorage.js +1 -1
- package/dist/utils/imageUtils.js +1 -1
- package/dist/utils/mergeWithOptimistic.d.ts +5 -6
- package/dist/utils/mergeWithOptimistic.d.ts.map +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/scopeUtils.d.ts +38 -0
- package/dist/utils/scopeUtils.d.ts.map +1 -0
- package/dist/utils/scopeUtils.js +1 -0
- package/dist/utils/uploadValidation.d.ts.map +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +24 -17
- package/dist/components/EntityCardList.d.ts +0 -27
- package/dist/components/EntityCardList.d.ts.map +0 -1
- package/dist/components/EntityCardList.js +0 -1
- package/dist/components/EntityList.d.ts +0 -24
- package/dist/components/EntityList.d.ts.map +0 -1
- package/dist/components/EntityList.js +0 -1
- package/dist/forms/utils/optionHelpers.d.ts +0 -54
- package/dist/forms/utils/optionHelpers.d.ts.map +0 -1
- package/dist/forms/utils/optionHelpers.js +0 -1
package/dist/CrudService.d.ts
CHANGED
|
@@ -1,56 +1,8 @@
|
|
|
1
1
|
import type { dndevSchema, QueryClient } from '@donotdev/core';
|
|
2
|
+
import type { BackendType, CrudStoreApi, CrudServiceInterface, CacheOptions, MutationOptions } from './types';
|
|
2
3
|
import type { QueryOptions } from './adapters/FirestoreAdapter';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
type CrudStoreApi = {
|
|
6
|
-
getState: () => CrudState & CrudActions;
|
|
7
|
-
};
|
|
8
|
-
/** Cache options for read operations */
|
|
9
|
-
export interface CacheOptions {
|
|
10
|
-
/** Bypass cache and fetch directly from adapter */
|
|
11
|
-
noCache?: boolean;
|
|
12
|
-
/** Custom stale time in ms (default: Infinity) */
|
|
13
|
-
staleTime?: number;
|
|
14
|
-
}
|
|
15
|
-
export type { QueryOptions };
|
|
16
|
-
export interface CrudServiceInterface {
|
|
17
|
-
initialize(backend: BackendType): Promise<void>;
|
|
18
|
-
setStore(store: CrudStoreApi): void;
|
|
19
|
-
/** Schema accepts unknown since OperationSchemas stores dndevSchema<unknown>. T is for return type. */
|
|
20
|
-
getListQueryOptions<T>(collection: string, queryOptions: QueryOptions, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): {
|
|
21
|
-
queryKey: readonly string[];
|
|
22
|
-
queryFn: () => Promise<T[]>;
|
|
23
|
-
staleTime: number;
|
|
24
|
-
};
|
|
25
|
-
/** Schema accepts unknown since OperationSchemas stores dndevSchema<unknown>. T is for return type. */
|
|
26
|
-
getDocQueryOptions<T>(collection: string, id: string, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions): {
|
|
27
|
-
queryKey: readonly string[];
|
|
28
|
-
queryFn: () => Promise<T | null>;
|
|
29
|
-
staleTime: number;
|
|
30
|
-
};
|
|
31
|
-
get<T>(collection: string, id: string, schema: dndevSchema<T>, options?: CacheOptions): Promise<T | null>;
|
|
32
|
-
query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<T[]>;
|
|
33
|
-
set<T>(collection: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
|
|
34
|
-
update<T>(collection: string, id: string, data: Partial<T>): Promise<void>;
|
|
35
|
-
delete(collection: string, id: string): Promise<void>;
|
|
36
|
-
add<T>(collection: string, data: T, schema: dndevSchema<T>): Promise<string>;
|
|
37
|
-
subscribe<T>(collection: string, id: string, callback: (data: T | null, error?: Error) => void, schema: dndevSchema<T>): () => void;
|
|
38
|
-
subscribeToCollection<T>(collection: string, options: QueryOptions, callback: (data: T[], error?: Error) => void, schema: dndevSchema<T>): () => void;
|
|
39
|
-
/** Add with optimistic update - shows item immediately, confirms/rolls back after server */
|
|
40
|
-
addOptimistic<T extends {
|
|
41
|
-
id?: string;
|
|
42
|
-
}>(collection: string, data: T, schema: dndevSchema<T>): Promise<T & {
|
|
43
|
-
id: string;
|
|
44
|
-
}>;
|
|
45
|
-
/** Update with optimistic update - shows change immediately, confirms/rolls back after server */
|
|
46
|
-
updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T>): Promise<T>;
|
|
47
|
-
/** Delete with optimistic update - hides item immediately, confirms/restores after server */
|
|
48
|
-
deleteOptimistic(collection: string, id: string): Promise<void>;
|
|
49
|
-
/** Invalidate all cached queries for a collection */
|
|
50
|
-
invalidateCollection(collection: string): Promise<void>;
|
|
51
|
-
/** Get the shared QueryClient instance from @donotdev/core */
|
|
52
|
-
getQueryClient(): QueryClient;
|
|
53
|
-
}
|
|
4
|
+
import type { PaginatedQueryResult } from './adapters/FunctionsAdapter';
|
|
5
|
+
export type { QueryOptions, CacheOptions };
|
|
54
6
|
/**
|
|
55
7
|
* Complete CRUD orchestrator with TanStack Query caching
|
|
56
8
|
*
|
|
@@ -62,6 +14,13 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
62
14
|
private adapter;
|
|
63
15
|
private backend;
|
|
64
16
|
private store;
|
|
17
|
+
/**
|
|
18
|
+
* Determine if success toast should be shown based on per-call options and global setting
|
|
19
|
+
* - options.showSuccessToast=true → always show
|
|
20
|
+
* - options.showSuccessToast=false → never show
|
|
21
|
+
* - options.showSuccessToast=undefined → use global !hideSuccessToasts
|
|
22
|
+
*/
|
|
23
|
+
private _shouldShowSuccessToast;
|
|
65
24
|
setStore(store: CrudStoreApi): void;
|
|
66
25
|
initialize(backend: BackendType): Promise<void>;
|
|
67
26
|
/**
|
|
@@ -76,7 +35,7 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
76
35
|
*/
|
|
77
36
|
getListQueryOptions<T>(collection: string, queryOptions: QueryOptions, schema: dndevSchema<unknown>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): {
|
|
78
37
|
queryKey: readonly ["crud", string, "query", "list" | "listCard", string];
|
|
79
|
-
queryFn: () => Promise<T
|
|
38
|
+
queryFn: () => Promise<PaginatedQueryResult<T>>;
|
|
80
39
|
staleTime: number;
|
|
81
40
|
};
|
|
82
41
|
/**
|
|
@@ -99,6 +58,11 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
99
58
|
* Automatically syncs both list and document caches for consistency.
|
|
100
59
|
*/
|
|
101
60
|
private _updateListCaches;
|
|
61
|
+
/**
|
|
62
|
+
* Get an item from any list cache for this collection.
|
|
63
|
+
* Used to get previous data for optimistic operations when individual GET cache is empty.
|
|
64
|
+
*/
|
|
65
|
+
private _getItemFromListCache;
|
|
102
66
|
/**
|
|
103
67
|
* Invalidate all cached queries for a collection
|
|
104
68
|
*/
|
|
@@ -106,22 +70,28 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
106
70
|
get<T>(collection: string, id: string, schema: dndevSchema<T>, options?: CacheOptions): Promise<T | null>;
|
|
107
71
|
/** Internal: fetch from adapter with store updates */
|
|
108
72
|
private _getFromAdapter;
|
|
109
|
-
query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<T
|
|
73
|
+
query<T>(collection: string, options: QueryOptions, schema: dndevSchema<T>, cacheOptions?: CacheOptions, schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
|
|
110
74
|
/** Internal: query from adapter with store updates */
|
|
111
75
|
private _queryFromAdapter;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Helper to get translated entity name from collection
|
|
78
|
+
* Tries entity-{collection}:name and entity-{singular}:name patterns
|
|
79
|
+
* Falls back to collection name if translation not found
|
|
80
|
+
*/
|
|
81
|
+
private _getEntityName;
|
|
82
|
+
set<T>(collection: string, id: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<void>;
|
|
83
|
+
update<T>(collection: string, id: string, data: Partial<T>, options?: MutationOptions): Promise<void>;
|
|
84
|
+
delete(collection: string, id: string, options?: MutationOptions): Promise<void>;
|
|
85
|
+
add<T>(collection: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<string>;
|
|
116
86
|
subscribe<T>(collection: string, id: string, callback: (data: T | null, error?: Error) => void, schema: dndevSchema<T>): () => void;
|
|
117
87
|
subscribeToCollection<T>(collection: string, options: QueryOptions, callback: (data: T[], error?: Error) => void, schema: dndevSchema<T>): () => void;
|
|
118
88
|
addOptimistic<T extends {
|
|
119
89
|
id?: string;
|
|
120
|
-
}>(collection: string, data: T, schema: dndevSchema<T
|
|
90
|
+
}>(collection: string, data: T, schema: dndevSchema<T>, options?: MutationOptions): Promise<T & {
|
|
121
91
|
id: string;
|
|
122
92
|
}>;
|
|
123
|
-
updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T
|
|
124
|
-
deleteOptimistic(collection: string, id: string): Promise<void>;
|
|
93
|
+
updateOptimistic<T>(collection: string, id: string, data: Partial<T>, schema: dndevSchema<T>, options?: MutationOptions): Promise<T>;
|
|
94
|
+
deleteOptimistic(collection: string, id: string, options?: MutationOptions): Promise<void>;
|
|
125
95
|
}
|
|
126
96
|
/**
|
|
127
97
|
* Get or create CrudService singleton instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":"
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;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
|
package/dist/CrudService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as f}from"@donotdev/components";import{createSingleton as p,handleError as u,getQueryClient as g}from"@donotdev/core";import{FirestoreAdapter as y}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as w}from"./adapters/FunctionsAdapter";const d=1/0,z=1e3*60*30;class S{adapter=null;backend=null;store=null;setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new w;else if(t==="firestore")this.adapter=new y;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return g()}getListQueryOptions(t,e,s,a,r="list"){const i=this.adapter,h=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",r,JSON.stringify(e)],queryFn:async()=>{if(i||await h(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,s)},staleTime:a?.staleTime??d}}getDocQueryOptions(t,e,s,a){const r=this.adapter,i=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(r||await i(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,s)},staleTime:a?.staleTime??d}}_updateGetCache(t,e,s,a){const r=this.getQueryClient(),i=["crud",t,"get",e];a==="delete"?r.removeQueries({queryKey:i}):(a==="update"||a==="add")&&s&&r.setQueryData(i,h=>h?{...h,...s}:s)}_updateListCaches(t,e,s,a){const r=this.getQueryClient();this._updateGetCache(t,e,s,a),r.setQueriesData({queryKey:["crud",t]},i=>Array.isArray(i)?a==="delete"?i.filter(h=>h.id!==e):a==="add"&&s?[...i,{...s,id:e}]:a==="update"&&s&&i.some(o=>o.id===e)?i.map(o=>o.id===e?{...o,...s}:o):i:i)}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,s,a){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._getFromAdapter(t,e,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,s,!1),staleTime:a?.staleTime??d})}catch(r){const i=u(r,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,s,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.get(t,e,s);return this.store&&r&&this.store.getState().setData(t,e,r),r}catch(r){const i=u(r,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,s,a,r="list"){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._queryFromAdapter(t,e,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",r,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,s,!1),staleTime:a?.staleTime??d})}catch(i){const h=u(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,s,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.query(t,e,s);if(this.store){const i=[];for(const h of r){const o=h;o.id&&i.push({id:o.id,data:h})}i.length>0&&this.store.getState().setDataBatch(t,i)}return r}catch(r){const i=u(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async set(t,e,s,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=this.store?.getState().getData(t,e);this.store&&this.store.getState().updateOptimistic(t,e,s,r);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.set(t,e,s,a),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,s)),this._updateListCaches(t,e,s,"update"),f("success",`${t} saved successfully`)}catch(i){this.store&&this.store.getState().rejectUpdate(t,e);const h=u(i,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));let a=null;this.store&&(a=this.store.getState().getData(t,e));const r=a?{...a,...s}:{...s,id:e};this.store&&a&&this.store.getState().updateOptimistic(t,e,r,a);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,s),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,r)),this._updateListCaches(t,e,r,"update"),f("success",`${t} updated successfully`)}catch(i){this.store&&this.store.getState().rejectUpdate(t,e);const h=u(i,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.store?.getState().getData(t,e);this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.delete(t,e),this.store&&this.store.getState().confirmDelete(t,e),this._updateListCaches(t,e,null,"delete"),f("success",`${t} deleted successfully`)}catch(a){this.store&&this.store.getState().rejectDelete(t,e);const r=u(a,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,a,{...e,id:a});try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.add(t,e,s);return this.store&&this.store.getState().confirmOptimistic(t,a,r,{...e,id:r}),this._updateListCaches(t,r,{...e,id:r},"add"),f("success",`${t} created successfully`),r}catch(r){this.store&&this.store.getState().rejectOptimistic(t,a);const i=u(r,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,s,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(r,i)=>{r&&this.store&&this.store.getState().setData(t,e,r),r&&this.getQueryClient().setQueryData(["crud",t,"get",e],r),s(r,i)},a):(s(null,new Error("Adapter not initialized")),()=>{})}catch(r){return s(null,u(r)),()=>{}}}subscribeToCollection(t,e,s,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(r,i)=>{if(r&&this.store){const h=[];for(const o of r){const n=o;n.id&&h.push({id:n.id,data:o})}h.length>0&&this.store.getState().setDataBatch(t,h)}r&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],r),s(r,i)},a):(s([],new Error("Adapter not initialized")),()=>{})}catch(r){return s([],u(r)),()=>{}}}async addOptimistic(t,e,s){this.adapter||await this.initialize("firestore");const a=`temp_${crypto.randomUUID()}`,r={...e,id:a,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,a,r);try{if(!this.adapter)throw new Error("Adapter not initialized");const i=await this.adapter.add(t,e,s),h={...e,id:i};return this.store&&this.store.getState().confirmOptimistic(t,a,i,h),this._updateListCaches(t,i,h,"add"),f("success",`${t} created successfully`),h}catch(i){throw this.store&&this.store.getState().rejectOptimistic(t,a),u(i,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,s,a){this.adapter||await this.initialize("firestore");let r=null;this.store&&(r=this.store.getState().getData(t,e));const i=r?{...r,...s,_optimistic:!0}:{...s,id:e,_optimistic:!0};this.store&&r&&this.store.getState().updateOptimistic(t,e,i,r);try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.update(t,e,s),this.store&&(this.store.getState().confirmUpdate(t,e),this.store.getState().setData(t,e,{...i,_optimistic:void 0})),this._updateListCaches(t,e,i,"update"),f("success",`${t} updated successfully`),i}catch(h){throw this.store&&this.store.getState().rejectUpdate(t,e),u(h,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e){this.adapter||await this.initialize("firestore");let s=null;this.store&&(s=this.store.getState().getData(t,e)),this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.delete(t,e),this.store&&this.store.getState().confirmDelete(t,e),this._updateListCaches(t,e,null,"delete"),f("success",`${t} deleted successfully`)}catch(a){throw this.store&&this.store.getState().rejectDelete(t,e),u(a,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const A=p(()=>new S);export{A as getCrudService};
|
|
1
|
+
import{toast as u}from"@donotdev/components";import{createSingleton as p,handleError as n,getQueryClient as y,getI18nInstance as c}from"@donotdev/core";import{FirestoreAdapter as m}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as f}from"./adapters/FunctionsAdapter";const l=1/0,F=1e3*60*30;class S{adapter=null;backend=null;store=null;_shouldShowSuccessToast(t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!this.store?.getState().hideSuccessToasts}setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new f;else if(t==="firestore")this.adapter=new m;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return y()}getListQueryOptions(t,e,r,a,s="list"){const i=this.adapter,o=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:async()=>{if(i||await o(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,r,s)},staleTime:a?.staleTime??l}}getDocQueryOptions(t,e,r,a){const s=this.adapter,i=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(s||await i(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,r)},staleTime:a?.staleTime??l}}_updateGetCache(t,e,r,a){const s=this.getQueryClient(),i=["crud",t,"get",e];a==="delete"?s.removeQueries({queryKey:i}):(a==="update"||a==="add")&&r&&s.setQueryData(i,o=>o?{...o,...r}:r)}_updateListCaches(t,e,r,a){const s=this.getQueryClient();this._updateGetCache(t,e,r,a),s.setQueriesData({queryKey:["crud",t]},i=>{if(i&&typeof i=="object"&&"items"in i){const o=i;let h=o.items;return a==="delete"?(h=o.items.filter(d=>d.id!==e),{...o,items:h,total:(o.total??h.length)-1}):a==="add"&&r?(h=[...o.items,{...r,id:e}],{...o,items:h,total:(o.total??o.items.length)+1}):a==="update"&&r&&o.items.some(d=>d.id===e)?(h=o.items.map(d=>d.id===e?{...d,...r}:d),{...o,items:h}):i}if(Array.isArray(i)){if(a==="delete")return i.filter(o=>o.id!==e);if(a==="add"&&r)return[...i,{...r,id:e}];if(a==="update"&&r)return i.some(o=>o.id===e)?i.map(o=>o.id===e?{...o,...r}:o):i}return i})}_getItemFromListCache(t,e){const r=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,a]of r)if(a?.items){const s=a.items.find(i=>i.id===e);if(s)return s}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,r,a){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._getFromAdapter(t,e,r);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,r,!1),staleTime:a?.staleTime??l})}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,r,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.get(t,e,r)}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,r,a,s="list"){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._queryFromAdapter(t,e,r,!0,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,r,!1,s),staleTime:a?.staleTime??l})}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,r,a=!0,s="list"){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.query(t,e,r,s)}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=c();let r=`entity-${t}`,a=e.t("name",{ns:r,defaultValue:null});return a&&a!=="name"&&a!==`${r}:name`||t.endsWith("s")&&t.length>1&&(r=`entity-${t.slice(0,-1)}`,a=e.t("name",{ns:r,defaultValue:null}),a&&a!=="name"&&a!==`${r}:name`)?a:t}async set(t,e,r,a,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,r,i);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.set(t,e,r,a),this._updateListCaches(t,e,r,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),i=s?{...s,...r}:{...r,id:e};this.store&&s&&this.store.getState().updateOptimistic(t,e,i,s);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.update(t,e,r),this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){s&&this._updateListCaches(t,e,s,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,r){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e);const i=n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,s,{...e,id:s});try{if(!this.adapter)throw new Error("Adapter not initialized");const i=await this.adapter.add(t,e,r);if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,i,{...e,id:i},"add"),this.store&&this.store.getState().confirmOptimistic(t,s,i,{...e,id:i}),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.createSuccess",{ns:"crud",entity:h}))}return i}catch(i){this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s);const o=n(i,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"get",e],s),r(s,i)},a):(r(null,new Error("Adapter not initialized")),()=>{})}catch(s){return r(null,n(s)),()=>{}}}subscribeToCollection(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],{items:s}),r(s,i)},a):(r([],new Error("Adapter not initialized")),()=>{})}catch(s){return r([],n(s)),()=>{}}}async addOptimistic(t,e,r,a){this.adapter||await this.initialize("firestore");const s=`temp_${crypto.randomUUID()}`,i={...e,id:s,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,s,i);try{if(!this.adapter)throw new Error("Adapter not initialized");const o=await this.adapter.add(t,e,r),h={...e,id:o};if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,o,h,"add"),this.store&&this.store.getState().confirmOptimistic(t,s,o,h),this._shouldShowSuccessToast(a)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.createSuccess",{ns:"crud",entity:g}))}return h}catch(o){throw this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s),n(o,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,r,a,s){this.adapter||await this.initialize("firestore");const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),o=i?{...i,...r,_optimistic:!0}:{...r,id:e,_optimistic:!0};this.store&&i&&this.store.getState().updateOptimistic(t,e,o,i);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,r);const h={...o,_optimistic:void 0};if(this._updateListCaches(t,e,h,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.updateSuccess",{ns:"crud",entity:g}))}return h}catch(h){throw i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e),n(h,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,r){this.adapter||await this.initialize("firestore");const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){throw a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e),n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const w=p(()=>new S);export{w as getCrudService};
|
package/dist/CrudStore.d.ts
CHANGED
|
@@ -1,97 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
/**
|
|
3
|
-
* Backend type for CRUD operations
|
|
4
|
-
*
|
|
5
|
-
* @version 0.0.1
|
|
6
|
-
* @since 0.0.1
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
|
-
export type BackendType = 'functions' | 'firestore';
|
|
10
|
-
/**
|
|
11
|
-
* Optimistic operation status
|
|
12
|
-
*/
|
|
13
|
-
export type OptimisticStatus = 'pending' | 'confirmed' | 'failed';
|
|
14
|
-
/**
|
|
15
|
-
* Optimistic operation metadata
|
|
16
|
-
*/
|
|
17
|
-
export interface OptimisticMeta {
|
|
18
|
-
tempId: string;
|
|
19
|
-
originalData: unknown | null;
|
|
20
|
-
status: OptimisticStatus;
|
|
21
|
-
operation: 'add' | 'update' | 'delete';
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* CRUD store state interface
|
|
25
|
-
*
|
|
26
|
-
* @version 0.0.2
|
|
27
|
-
* @since 0.0.1
|
|
28
|
-
* @author AMBROISE PARK Consulting
|
|
29
|
-
*/
|
|
30
|
-
export interface CrudState {
|
|
31
|
-
backend: BackendType | null;
|
|
32
|
-
crudService: CrudServiceInterface | null;
|
|
33
|
-
collections: Record<string, {
|
|
34
|
-
loading: boolean;
|
|
35
|
-
error: Error | null;
|
|
36
|
-
data: Record<string, unknown>;
|
|
37
|
-
lastUpdated: number;
|
|
38
|
-
/** Optimistic operation metadata keyed by document id */
|
|
39
|
-
optimistic: Record<string, OptimisticMeta>;
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* CRUD store actions interface
|
|
44
|
-
*
|
|
45
|
-
* @version 0.0.2
|
|
46
|
-
* @since 0.0.1
|
|
47
|
-
* @author AMBROISE PARK Consulting
|
|
48
|
-
*/
|
|
49
|
-
export interface CrudActions {
|
|
50
|
-
setCrudService: (service: CrudServiceInterface) => void;
|
|
51
|
-
setBackend: (backend: BackendType) => void;
|
|
52
|
-
setLoading: (collection: string, loading: boolean) => void;
|
|
53
|
-
setError: (collection: string, error: Error | null) => void;
|
|
54
|
-
setData: (collection: string, id: string, data: unknown) => void;
|
|
55
|
-
/** Batch update multiple documents in a single state update (performance) */
|
|
56
|
-
setDataBatch: (collection: string, items: Array<{
|
|
57
|
-
id: string;
|
|
58
|
-
data: unknown;
|
|
59
|
-
}>) => void;
|
|
60
|
-
removeData: (collection: string, id: string) => void;
|
|
61
|
-
clearCollection: (collection: string) => void;
|
|
62
|
-
clearError: (collection: string) => void;
|
|
63
|
-
/** Add item optimistically (before server confirms) */
|
|
64
|
-
addOptimistic: (collection: string, tempId: string, data: unknown) => void;
|
|
65
|
-
/** Confirm optimistic add - replace temp item with real item */
|
|
66
|
-
confirmOptimistic: (collection: string, tempId: string, realId: string, realData: unknown) => void;
|
|
67
|
-
/** Reject optimistic add - remove temp item */
|
|
68
|
-
rejectOptimistic: (collection: string, tempId: string) => void;
|
|
69
|
-
/** Update item optimistically */
|
|
70
|
-
updateOptimistic: (collection: string, id: string, data: unknown, originalData: unknown) => void;
|
|
71
|
-
/** Confirm optimistic update */
|
|
72
|
-
confirmUpdate: (collection: string, id: string) => void;
|
|
73
|
-
/** Reject optimistic update - restore original data */
|
|
74
|
-
rejectUpdate: (collection: string, id: string) => void;
|
|
75
|
-
/** Delete item optimistically (hide but keep for rollback) */
|
|
76
|
-
deleteOptimistic: (collection: string, id: string, originalData: unknown) => void;
|
|
77
|
-
/** Confirm optimistic delete - remove completely */
|
|
78
|
-
confirmDelete: (collection: string, id: string) => void;
|
|
79
|
-
/** Reject optimistic delete - restore item */
|
|
80
|
-
rejectDelete: (collection: string, id: string) => void;
|
|
81
|
-
getLoading: (collection: string) => boolean;
|
|
82
|
-
getError: (collection: string) => Error | null;
|
|
83
|
-
getData: (collection: string, id: string) => unknown | null;
|
|
84
|
-
/** Check if item is optimistic (not yet confirmed by server) */
|
|
85
|
-
isOptimistic: (collection: string, id: string) => boolean;
|
|
86
|
-
/** Get optimistic status for an item */
|
|
87
|
-
getOptimisticStatus: (collection: string, id: string) => OptimisticStatus | null;
|
|
88
|
-
/** Get all items in collection (including optimistic, excluding deleted) */
|
|
89
|
-
getCollectionData: (collection: string) => Array<{
|
|
90
|
-
id: string;
|
|
91
|
-
data: unknown;
|
|
92
|
-
isOptimistic: boolean;
|
|
93
|
-
}>;
|
|
94
|
-
}
|
|
1
|
+
import type { CrudState, CrudActions } from './types';
|
|
95
2
|
/**
|
|
96
3
|
* CRUD store hook for accessing CRUD state and actions
|
|
97
4
|
*
|
package/dist/CrudStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAGV,SAAS,EACT,WAAW,EAIZ,MAAM,SAAS,CAAC;AA0BjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iIAqZvB,CAAC"}
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as
|
|
1
|
+
import{createDoNotDevStore as u}from"@donotdev/core";const d={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...d}}}const m={backend:null,crudService:null,hideSuccessToasts:!1,collections:{}},g=u({name:"crud-store",createStore:(l,n)=>({...m,setCrudService:t=>{l({crudService:t})},setBackend:t=>{l({backend:t})},setHideSuccessToasts:t=>{l({hideSuccessToasts:t})},setLoading:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,loading:e}}}})},setError:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,error:e,loading:!1}}}})},setFilters:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,filters:e}}}}})},setShowFavoritesOnly:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,showFavoritesOnly:e}}}}})},getFilters:t=>n().collections[t]?.ui?.filters||{},getShowFavoritesOnly:t=>n().collections[t]?.ui?.showFavoritesOnly||!1,clearCollection:t=>{l(e=>{const{[t]:o,...i}=e.collections;return{collections:i}})},clearError:t=>{l(e=>{const o=e.collections[t];return o?{collections:{...e.collections,[t]:{...o,error:null}}}:e})},addOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t]||r();return{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:null,optimisticData:o,status:"pending",operation:"add"}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t];if(!s)return c;const{[e]:a,...p}=s.optimistic;return{collections:{...c.collections,[t]:{...s,optimistic:p,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s,lastUpdated:Date.now()}}}})},updateOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t]||r();return{collections:{...c.collections,[t]:{...s,optimistic:{...s.optimistic,[e]:{tempId:e,originalData:i,optimisticData:o,status:"pending",operation:"update"}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="update")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t];return c?{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:o,optimisticData:null,status:"pending",operation:"delete"}},lastUpdated:Date.now()}}}:i})},confirmDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="delete")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},getLoading:t=>n().collections[t]?.loading||!1,getError:t=>n().collections[t]?.error||null,isOptimistic:(t,e)=>n().collections[t]?.optimistic[e]?.status==="pending",getOptimisticStatus:(t,e)=>n().collections[t]?.optimistic[e]?.status??null,getOptimisticData:(t,e)=>n().collections[t]?.optimistic[e]?.optimisticData??null})});export{g as useCrudStore};
|
package/dist/FieldRegistry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";class
|
|
1
|
+
"use client";class c{components=new Map;registerComponent(e,t,o){this.components.set(e,{controlled:t,uncontrolled:o})}register(e){const{type:t,controlledComponent:o,uncontrolledComponent:l}=e;this.components.set(t,{controlled:o,uncontrolled:l})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear()}}let r=null;function s(){return r||(r=new c),r}function i(n){s().register(n)}function p(n){return s().has(n)}export{s as getFieldRegistry,p as isFieldTypeRegistered,i as registerFieldType};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { dndevSchema } from '@donotdev/core';
|
|
2
2
|
import { type Unsubscribe, type FirestoreError } from '@donotdev/firebase';
|
|
3
|
+
import type { PaginatedQueryResult } from './FunctionsAdapter';
|
|
3
4
|
/**
|
|
4
5
|
* Firestore query operators
|
|
5
6
|
*/
|
|
@@ -22,6 +23,7 @@ export interface QueryOptions {
|
|
|
22
23
|
direction?: 'asc' | 'desc';
|
|
23
24
|
}>;
|
|
24
25
|
limit?: number;
|
|
26
|
+
startAfterId?: string;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Subscription callback for document subscriptions
|
|
@@ -56,7 +58,7 @@ export declare class FirestoreAdapter {
|
|
|
56
58
|
update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
|
|
57
59
|
delete(collectionName: string, id: string): Promise<void>;
|
|
58
60
|
add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<string>;
|
|
59
|
-
query<T>(collectionName: string, options: QueryOptions, schema: dndevSchema<unknown
|
|
61
|
+
query<T>(collectionName: string, options: QueryOptions, schema: dndevSchema<unknown>, _schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
|
|
60
62
|
subscribe<T>(collectionName: string, id: string, callback: SubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
|
|
61
63
|
subscribeToCollection<T>(collectionName: string, options: QueryOptions, callback: CollectionSubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
|
|
62
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FirestoreAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FirestoreAdapter.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,
|
|
1
|
+
{"version":3,"file":"FirestoreAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FirestoreAdapter.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAA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/core";import{getFirestore as b,getFirebaseSDK as v,doc as p,getDoc as g,getDocs as q,setDoc as R,updateDoc as S,deleteDoc as E,addDoc as M,collection as V,query as A,where as D,orderBy as x,limit as B,startAfter as z,onSnapshot as I}from"@donotdev/firebase";import{transformFirestoreData as m,prepareForFirestore as F}from"@donotdev/firebase";class K{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=b(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:V(this.firestore,s)}async get(s,t,e){if(!this.ensureFirestore()||!this.firestore)return null;try{const o=p(this.firestore,s,t),i=await g(o);if(!i.exists())return null;let r=i.data();return r=m(r),{...d.parse(e,r),id:t}}catch(o){return w(o,{context:{operation:"FirestoreAdapter.get",collection:s,docId:t},severity:"warning"}),null}}async set(s,t,e,o){if(!(!this.ensureFirestore()||!this.firestore))try{d.parse(o,e);const i=p(this.firestore,s,t),r=F(e);await R(i,r)}catch(i){throw i}}async update(s,t,e){if(!(!this.ensureFirestore()||!this.firestore))try{const o=p(this.firestore,s,t),i=F(e);await S(o,i)}catch(o){throw o}}async delete(s,t){if(!(!this.ensureFirestore()||!this.firestore))try{const e=p(this.firestore,s,t);await E(e)}catch(e){throw e}}async add(s,t,e){if(!this.ensureFirestore())return"";try{d.parse(e,t);const o=this.getCollectionRef(s);if(!o)return"";const i=new Date().toISOString(),r=v().getCurrentUser()?.uid||"anonymous",c={...t,createdAt:i,updatedAt:i,createdById:r,updatedById:r},a=F(c);return(await M(o,a)).id}catch(o){throw o}}async query(s,t,e,o="list"){if(!this.ensureFirestore())return{items:[]};const i=this.getCollectionRef(s);if(!i)return{items:[]};try{const r=[];if(t.where)for(const n of t.where)r.push(D(n.field,n.operator,n.value));if(t.orderBy)for(const n of t.orderBy)r.push(x(n.field,n.direction||"asc"));if(t.startAfterId){const n=await g(p(i,t.startAfterId));n.exists()&&r.push(z(n))}const c=t.limit?t.limit+1:void 0;c&&r.push(B(c));const a=A(i,...r),h=await q(a),u=[];let l=null;h.forEach(n=>{try{let f=n.data();if(!f)return;f=m(f);const C=d.parse(e,f);u.push({...C,id:n.id}),l=n.id}catch(f){w(f,{context:{operation:"FirestoreAdapter.query.parse",docId:n.id,collection:s},showNotification:!1})}});const y=c?u.length>(t.limit||0):!1;return{items:y?u.slice(0,t.limit):u,hasMore:y,lastVisible:l,total:void 0}}catch(r){throw w(r,{context:{operation:"FirestoreAdapter.query",collection:s,options:t}}),r}}subscribe(s,t,e,o){if(!this.ensureFirestore()||!this.firestore)return()=>{};const i=p(this.firestore,s,t);return I(i,r=>{try{if(!r.exists()){e(null);return}let c=r.data();c=m(c);const a=d.parse(o,c);e({...a,id:t})}catch(c){e(null,c)}},r=>{e(null,r)})}subscribeToCollection(s,t,e,o){if(!this.ensureFirestore())return()=>{};const i=this.getCollectionRef(s);if(!i)return()=>{};try{const r=[];if(t.where)for(const a of t.where)r.push(D(a.field,a.operator,a.value));if(t.orderBy)for(const a of t.orderBy)r.push(x(a.field,a.direction||"asc"));t.limit&&r.push(B(t.limit));const c=A(i,...r);return I(c,a=>{try{const h=[];a.forEach(u=>{let l=u.data();l=m(l);const y=d.parse(o,l);h.push({...y,id:u.id})}),e(h)}catch(h){e([],h)}},a=>{e([],a)})}catch(r){return e([],r),()=>{}}}}export{K as FirestoreAdapter};
|
|
@@ -17,6 +17,13 @@ export interface FunctionsQueryOptions {
|
|
|
17
17
|
direction?: 'asc' | 'desc';
|
|
18
18
|
}>;
|
|
19
19
|
limit?: number;
|
|
20
|
+
startAfterId?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PaginatedQueryResult<T> {
|
|
23
|
+
items: T[];
|
|
24
|
+
total?: number;
|
|
25
|
+
hasMore?: boolean;
|
|
26
|
+
lastVisible?: string | null;
|
|
20
27
|
}
|
|
21
28
|
/**
|
|
22
29
|
* Functions backend adapter
|
|
@@ -37,7 +44,7 @@ export declare class FunctionsAdapter {
|
|
|
37
44
|
update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
|
|
38
45
|
delete(collectionName: string, id: string): Promise<void>;
|
|
39
46
|
add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<string>;
|
|
40
|
-
query<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<unknown
|
|
47
|
+
query<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<unknown>, schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
|
|
41
48
|
listCard<T>(collectionName: string, options: FunctionsQueryOptions, schema: dndevSchema<T>): Promise<T[]>;
|
|
42
49
|
subscribe<T>(): () => void;
|
|
43
50
|
subscribeToCollection<T>(): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,GAAG,CAA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C,CAAC,GACrB,OAAO,CAAC,MAAM,CAAC;IAgBZ,KAAK,CAAC,CAAC,EACX,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,UAAU,GAAE,MAAM,GAAG,UAAmB,GACvC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA2D7B,QAAQ,CAAC,CAAC,EACd,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,EAAE,CAAC;IAgDf,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI;IAM1B,qBAAqB,CAAC,CAAC,KAAK,MAAM,IAAI;CAKvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{httpsCallable as
|
|
1
|
+
import{httpsCallable as n}from"firebase/functions";import*as u from"valibot";import{getPlatformEnvVar as d}from"@donotdev/core";import{getFirebaseFunctions as h}from"@donotdev/firebase";class l{functions;region;constructor(){this.region=d("FIREBASE_FUNCTIONS_REGION")||"europe-west1"}async ensureFunctions(){if(this.functions)return!0;try{return this.functions=await h(this.region),!0}catch{return!1}}async get(i,t,a){if(!await this.ensureFunctions())return null;try{const r=`get_${i}`;return(await n(this.functions,r)({id:t})).data}catch(r){throw r}}async set(i,t,a,r){if(await this.ensureFunctions())try{u.parse(r,a);const e=`update_${i}`;await n(this.functions,e)({id:t,payload:a})}catch(e){throw e}}async update(i,t,a){if(await this.ensureFunctions())try{const r=`update_${i}`;await n(this.functions,r)({id:t,payload:a})}catch(r){throw r}}async delete(i,t){if(await this.ensureFunctions())try{const a=`delete_${i}`;await n(this.functions,a)({id:t})}catch(a){throw a}}async add(i,t,a){if(!await this.ensureFunctions())return"";try{u.parse(a,t);const r=`create_${i}`;return(await n(this.functions,r)({payload:t})).data.id}catch(r){throw r}}async query(i,t,a,r="list"){if(!await this.ensureFunctions())return{items:[]};try{const e=r==="listCard"?`listCard_${i}`:`list_${i}`,s={};t.where&&(s.where=t.where.map(o=>[o.field,o.operator,o.value])),t.orderBy&&(s.orderBy=t.orderBy.map(o=>[o.field,o.direction||"asc"])),t.limit&&(s.limit=t.limit),t.startAfterId&&(s.startAfterId=t.startAfterId);const c=await n(this.functions,e)(s);return{items:c.data.items,total:c.data.count,hasMore:c.data.hasMore,lastVisible:c.data.lastVisible}}catch(e){throw e}}async listCard(i,t,a){if(!await this.ensureFunctions())return[];try{const r=`listCard_${i}`,e={};return t.where&&(e.where=t.where.map(s=>[s.field,s.operator,s.value])),t.orderBy&&(e.orderBy=t.orderBy.map(s=>[s.field,s.direction||"asc"])),t.limit&&(e.limit=t.limit),(await n(this.functions,r)(e)).data.items}catch(r){throw r}}subscribe(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}subscribeToCollection(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}}export{l as FunctionsAdapter};
|
package/dist/adapters/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./FirestoreAdapter";import{FunctionsAdapter as
|
|
1
|
+
export*from"./FirestoreAdapter";import{FunctionsAdapter as o}from"./FunctionsAdapter";export{o as FunctionsAdapter};
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @fileoverview Built-in Field Type Registrations
|
|
3
|
+
* @description Legacy wrapper - now delegates to unified registry.
|
|
3
4
|
*
|
|
4
|
-
* **
|
|
5
|
-
* This
|
|
6
|
-
*
|
|
5
|
+
* **For Framework Consumers:**
|
|
6
|
+
* This file is kept for backward compatibility. The actual registration happens
|
|
7
|
+
* in registerBuiltinFieldTypes.ts via the unified field type registry.
|
|
8
|
+
*
|
|
9
|
+
* For your own custom field types, use `registerFieldType()` from `@donotdev/crud`.
|
|
10
|
+
* See SETUP_CRUD.md for examples.
|
|
11
|
+
*
|
|
12
|
+
* @version 0.0.2
|
|
13
|
+
* @since 0.0.1
|
|
14
|
+
* @author AMBROISE PARK Consulting
|
|
15
|
+
*/
|
|
16
|
+
import './registerBuiltinFieldTypes';
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Registration now handled by unified registry
|
|
19
|
+
* Kept for backward compatibility
|
|
7
20
|
*/
|
|
8
21
|
export declare function registerBuiltinFieldTypes(): void;
|
|
9
22
|
//# sourceMappingURL=builtinFieldTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtinFieldTypes.d.ts","sourceRoot":"","sources":["../src/builtinFieldTypes.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builtinFieldTypes.d.ts","sourceRoot":"","sources":["../src/builtinFieldTypes.tsx"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,6BAA6B,CAAC;AAErC;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,IAAI,CAGhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import
|
|
1
|
+
"use client";import"./registerBuiltinFieldTypes";function i(){}export{i as registerBuiltinFieldTypes};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:s,...i}){const o=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!o||r&&!e,children:s})}var l=c;export{l as default};
|
|
@@ -18,10 +18,12 @@ export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
|
|
|
18
18
|
* @param t - Translation function
|
|
19
19
|
* @param options - Formatting options
|
|
20
20
|
* @param options.compact - Use compact formatting (smaller images, plain spans for empty)
|
|
21
|
+
* @param options.asString - Prefer string output when possible (e.g. for price in text placeholders)
|
|
21
22
|
* @returns Formatted value as string or ReactElement
|
|
22
23
|
*/
|
|
23
24
|
export declare function formatValue(value: any, config: EntityField, t: (key: string, options?: Record<string, any>) => string, options?: {
|
|
24
25
|
compact?: boolean;
|
|
26
|
+
asString?: boolean;
|
|
25
27
|
}): string | ReactElement;
|
|
26
28
|
/**
|
|
27
29
|
* DisplayFieldRenderer - Renders a field value as read-only display
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAK7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IACxE,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,0BAA0B;IAC1B,KAAK,EAAE,GAAG,CAAC;IACX,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EACzD,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAClD,MAAM,GAAG,YAAY,CA0DvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,EACpE,IAAI,EACJ,MAAM,EACN,KAAK,EACL,CAAC,GACF,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,YAAY,CAyC7C;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as r,jsxs as s}from"react/jsx-runtime";import{Text as a,Stack as c}from"@donotdev/components";import{handleError as d}from"@donotdev/core";import{translateFieldLabel as u}from"../forms/utils";import{getDisplayFormatter as y}from"../fieldTypeRegistry";function m(t,e,o,n){const i=n?.compact??!1;if(t==null||t==="")return i?r("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):r(a,{variant:"muted",children:"\u2014"});const l=y(e.type);if(l)try{return l(t,e,o,n)}catch(f){return d(f,{userMessage:`Error formatting field "${e.label||e.name}"`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format"},severity:"warning"}),i?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}return d(new Error(`Display formatter not registered for field type: ${e.type}`),{userMessage:`Field type "${e.type}" is missing display formatter`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format",fix:"Add displayFormatter to registerBuiltinFieldType() in registerBuiltinFieldTypes.tsx"},severity:"warning"}),i?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}function p({name:t,config:e,value:o,t:n}){const i=m(o,e,n,{compact:!1}),l=u(t,e,n);return s(c,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[s(a,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[l,":"]}),r("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof i=="string"?r(a,{children:i}):i})]})}var g=p;export{p as DisplayFieldRenderer,g as default,m as formatValue};
|