@donotdev/crud 0.0.31 → 0.1.1
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/LICENSE.md +3 -3
- package/dist/CrudService.d.ts +13 -4
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.js +2 -2
- package/dist/CrudStore.d.ts +1 -1
- package/dist/CrudStore.d.ts.map +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.d.ts +2 -12
- package/dist/FieldRegistry.d.ts.map +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/adapters/FunctionsAdapter.d.ts +3 -3
- package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/builtinFieldTypes.d.ts +1 -1
- package/dist/components/CrudButton.d.ts +1 -0
- package/dist/components/CrudButton.d.ts.map +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/CrudCard.d.ts +1 -1
- package/dist/components/CrudCard.d.ts.map +1 -1
- package/dist/components/CrudCard.js +1 -1
- package/dist/components/DateFilter.js +1 -1
- package/dist/components/DisplayFieldRenderer.d.ts +2 -1
- package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/DisplayThumbnail.d.ts +1 -9
- package/dist/components/DisplayThumbnail.d.ts.map +1 -1
- package/dist/components/DisplayThumbnail.js +1 -1
- package/dist/components/EntityFilters.d.ts +1 -0
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormFieldRenderer.d.ts +1 -0
- package/dist/components/FormFieldRenderer.d.ts.map +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.d.ts +2 -1
- package/dist/components/FormLayout.d.ts.map +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
- 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/ControlledFieldArrayField.js +1 -1
- package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
- package/dist/components/controlled/complex/ControlledMapField.js +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
- package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
- 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.js +1 -1
- package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/controlled/file/index.js +1 -1
- package/dist/components/controlled/index.js +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
- package/dist/components/controlled/input/ControlledNumberField.js +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.js +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
- package/dist/components/controlled/input/ControlledTextField.d.ts +5 -5
- 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.js +1 -1
- package/dist/components/controlled/input/index.js +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.d.ts +2 -4
- 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 +2 -4
- 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 +2 -4
- 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/ControlledReferenceField.js +1 -1
- package/dist/components/controlled/select/ControlledYearField.js +1 -1
- package/dist/components/controlled/select/index.js +1 -1
- package/dist/components/controlled/types.js +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ButtonFieldDisplay.d.ts +2 -2
- package/dist/components/fields/display/ButtonFieldDisplay.js +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/DateFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/DateFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/DateFieldDisplay.js +1 -1
- package/dist/components/fields/display/DropdownDisplay.d.ts +1 -1
- package/dist/components/fields/display/DropdownDisplay.js +1 -1
- package/dist/components/fields/display/FileFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/FileFieldDisplay.js +1 -1
- package/dist/components/fields/display/GeoPointFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -1
- package/dist/components/fields/display/HiddenFieldDisplay.d.ts +2 -2
- package/dist/components/fields/display/HiddenFieldDisplay.js +1 -1
- package/dist/components/fields/display/ImageFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/ImageFieldDisplay.js +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/MapFieldDisplay.js +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.d.ts +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/PhoneNumberDisplay.d.ts +1 -1
- package/dist/components/fields/display/PhoneNumberDisplay.js +1 -1
- package/dist/components/fields/display/RadioFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/RadioFieldDisplay.js +1 -1
- package/dist/components/fields/display/RangeFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/RangeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
- package/dist/components/fields/display/RichTextDisplay.d.ts +1 -1
- package/dist/components/fields/display/RichTextDisplay.js +2 -2
- package/dist/components/fields/display/TextAreaDisplay.d.ts +1 -1
- package/dist/components/fields/display/TextAreaDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.d.ts +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.js +1 -1
- package/dist/components/fields/display/index.d.ts +1 -1
- package/dist/components/fields/display/index.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.d.ts +2 -2
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.d.ts +2 -2
- 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 +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
- package/dist/components/form/fields/ComboboxComponent.d.ts +1 -1
- package/dist/components/form/fields/ComboboxComponent.js +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.d.ts +3 -3
- package/dist/components/form/fields/DateFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.d.ts +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
- 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.d.ts +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.d.ts +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/PriceFieldComponent.js +1 -1
- package/dist/components/form/fields/RadioFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/RatingFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/RatingFieldComponent.js +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
- package/dist/components/form/fields/RichTextComponent.d.ts +1 -1
- package/dist/components/form/fields/RichTextComponent.js +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.d.ts +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.d.ts +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/components/form/fields/TextFieldComponent.d.ts +4 -4
- package/dist/components/form/fields/TextFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TextFieldComponent.js +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.d.ts +2 -2
- package/dist/components/form/fields/TimestampFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
- package/dist/components/form/fields/index.d.ts +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.js +2 -2
- package/dist/components/form/fields/types.d.ts +1 -1
- package/dist/components/form/index.d.ts +1 -1
- package/dist/components/form/internal/ImageViewerDialog.js +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/contexts/UploadContext.d.ts +1 -0
- 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.map +1 -1
- package/dist/fieldTypeRegistry.js +1 -1
- package/dist/fieldTypeRegistry.store.d.ts.map +1 -1
- package/dist/fieldTypeRegistry.store.js +1 -1
- package/dist/fieldTypeRegistry.types.d.ts +4 -0
- package/dist/fieldTypeRegistry.types.d.ts.map +1 -1
- package/dist/forms/hooks/index.d.ts +1 -1
- package/dist/forms/hooks/index.js +1 -1
- package/dist/forms/hooks/useController.js +1 -1
- package/dist/forms/hooks/useEntityField.d.ts +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 +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/types.d.ts +12 -7
- package/dist/forms/types.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.js +1 -1
- package/dist/forms/utils/getFieldsForOperation.d.ts +2 -2
- package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
- package/dist/forms/utils/getFieldsForOperation.js +1 -1
- package/dist/forms/utils/index.d.ts +1 -1
- package/dist/forms/utils/index.js +1 -1
- package/dist/forms/utils/isFieldEditable.d.ts +8 -2
- package/dist/forms/utils/isFieldEditable.d.ts.map +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/forms/utils/translateFieldLabel.d.ts +3 -3
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/forms/utils/validateEntity.d.ts +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useCrudFilters.d.ts +2 -0
- package/dist/hooks/useCrudFilters.d.ts.map +1 -1
- package/dist/hooks/useCrudFilters.js +1 -1
- package/dist/hooks/useCrudPageSize.d.ts +29 -0
- package/dist/hooks/useCrudPageSize.d.ts.map +1 -0
- package/dist/hooks/useCrudPageSize.js +1 -0
- package/dist/hooks/useEntityFavorites.d.ts +2 -0
- package/dist/hooks/useEntityFavorites.d.ts.map +1 -1
- package/dist/hooks/useEntityFavorites.js +1 -1
- package/dist/hooks/useFieldConditions.js +1 -1
- package/dist/hooks/useFileUpload.d.ts.map +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useReferenceResolver.d.ts +1 -1
- package/dist/hooks/useReferenceResolver.d.ts.map +1 -1
- package/dist/hooks/useReferenceResolver.js +1 -1
- package/dist/hooks/useRelatedItems.d.ts +2 -0
- package/dist/hooks/useRelatedItems.d.ts.map +1 -1
- package/dist/hooks/useRelatedItems.js +1 -1
- package/dist/hooks/useUnsavedChangesWarning.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
- package/dist/registerBuiltinFieldTypes.js +1 -1
- package/dist/stores/FormStore.d.ts +2 -0
- package/dist/stores/FormStore.d.ts.map +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.d.ts +9 -3
- package/dist/stores/UploadStore.d.ts.map +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/stores/index.d.ts +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/symbol-index.json +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +10 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/useBaseCrudList.js +1 -1
- package/dist/useCrud.d.ts +1 -0
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.d.ts +5 -3
- package/dist/useCrudCardList.d.ts.map +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudList.d.ts +5 -3
- package/dist/useCrudList.d.ts.map +1 -1
- package/dist/useCrudList.js +1 -1
- package/dist/utils/clientListProcessing.d.ts +22 -3
- package/dist/utils/clientListProcessing.d.ts.map +1 -1
- package/dist/utils/clientListProcessing.js +1 -1
- package/dist/utils/collections.d.ts +6 -6
- package/dist/utils/collections.js +1 -1
- package/dist/utils/fileStorage.d.ts +2 -0
- package/dist/utils/fileStorage.d.ts.map +1 -1
- package/dist/utils/fileStorage.js +1 -1
- package/dist/utils/imageProcessing.d.ts +1 -1
- package/dist/utils/imageProcessing.d.ts.map +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/imageStorage.d.ts +2 -0
- package/dist/utils/imageStorage.d.ts.map +1 -1
- package/dist/utils/imageStorage.js +1 -1
- package/dist/utils/imageUtils.d.ts +1 -1
- package/dist/utils/imageUtils.js +1 -1
- package/dist/utils/matchesFilter.d.ts.map +1 -1
- package/dist/utils/matchesFilter.js +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/sanitizeHtml.d.ts +0 -5
- package/dist/utils/sanitizeHtml.d.ts.map +1 -1
- package/dist/utils/sanitizeHtml.js +1 -1
- package/dist/utils/scopeUtils.js +1 -1
- package/dist/utils/uploadValidation.d.ts +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/dist/workflows/WorkflowPersistence.d.ts +1 -1
- package/dist/workflows/WorkflowPersistence.js +1 -1
- package/dist/workflows/defineWorkflow.d.ts +1 -1
- package/dist/workflows/index.d.ts +1 -1
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/useEntityWorkflow.js +1 -1
- package/guidelines/COMPONENTS.md +234 -0
- package/guidelines/CRUD.md +340 -0
- package/guidelines/GOTCHAS.md +46 -0
- package/package.json +7 -4
package/LICENSE.md
CHANGED
|
@@ -8,7 +8,7 @@ Copyright © 2025 Ambroise Park Consulting. All rights reserved.
|
|
|
8
8
|
|
|
9
9
|
## 1. DEFINITIONS
|
|
10
10
|
|
|
11
|
-
**1.1 "Framework"** means the DoNotDev commercial software packages (excluding @donotdev/cli and @donotdev/
|
|
11
|
+
**1.1 "Framework"** means the DoNotDev commercial software packages (excluding @donotdev/cli, @donotdev/components, @donotdev/expo, and @donotdev/templates, which are licensed under MIT), including all compiled JavaScript files, TypeScript definition files, and associated documentation.
|
|
12
12
|
|
|
13
13
|
**1.2 "License Key"** means the unique alphanumeric key provided to you upon purchase, required to suppress watermarks and unlock full Framework functionality.
|
|
14
14
|
|
|
@@ -231,12 +231,12 @@ Ambroise Park Consulting has no obligation to provide support, updates, or maint
|
|
|
231
231
|
|
|
232
232
|
Questions about licensing or compliance:
|
|
233
233
|
|
|
234
|
-
**Email:**
|
|
234
|
+
**Email:** contact@donotdev.com
|
|
235
235
|
**Website:** donotdev.com
|
|
236
236
|
|
|
237
237
|
---
|
|
238
238
|
|
|
239
239
|
**END OF LICENSE AGREEMENT**
|
|
240
240
|
|
|
241
|
-
**DoNotDev Framework License
|
|
241
|
+
**DoNotDev Framework License v1.0**
|
|
242
242
|
Ambroise Park Consulting – 2025
|
package/dist/CrudService.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { CacheOptions };
|
|
|
4
4
|
/**
|
|
5
5
|
* Complete CRUD orchestrator with TanStack Query caching
|
|
6
6
|
*
|
|
7
|
-
* @version 0.0
|
|
7
|
+
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
@@ -34,7 +34,7 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
34
34
|
* getCrudService().setSecurity(security);
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
|
-
* @version 0.0
|
|
37
|
+
* @version 0.1.0
|
|
38
38
|
* @since 0.0.1
|
|
39
39
|
*/
|
|
40
40
|
setSecurity(security: SecurityContext): void;
|
|
@@ -46,7 +46,7 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
46
46
|
* onAuthStateChanged((user) => getCrudService().setCurrentUser(user?.id ?? null));
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
|
-
* @version 0.0
|
|
49
|
+
* @version 0.1.0
|
|
50
50
|
* @since 0.0.1
|
|
51
51
|
*/
|
|
52
52
|
setCurrentUser(userId: string | null): void;
|
|
@@ -71,6 +71,15 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
71
71
|
* after auth state changes to enable per-user isolation.
|
|
72
72
|
*/
|
|
73
73
|
private _rateLimitKey;
|
|
74
|
+
/** Tracks in-flight mutations to prevent concurrent writes to the same document */
|
|
75
|
+
private _inflightMutations;
|
|
76
|
+
private _mutationKey;
|
|
77
|
+
/**
|
|
78
|
+
* Execute an adapter call with timeout and 1 retry on transient errors.
|
|
79
|
+
* Transient errors: network errors, timeouts, 5xx status codes.
|
|
80
|
+
*/
|
|
81
|
+
private _withResilience;
|
|
82
|
+
private _isTransientError;
|
|
74
83
|
/** Ensure adapter is initialized from provider registry. */
|
|
75
84
|
private _ensureAdapter;
|
|
76
85
|
/**
|
|
@@ -169,7 +178,7 @@ declare class CrudService implements CrudServiceInterface {
|
|
|
169
178
|
/**
|
|
170
179
|
* Get or create CrudService singleton instance
|
|
171
180
|
*
|
|
172
|
-
* @version 0.0
|
|
181
|
+
* @version 0.1.0
|
|
173
182
|
* @since 0.0.1
|
|
174
183
|
* @author AMBROISE PARK Consulting
|
|
175
184
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"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C5C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,IAAI;IAkCb,uFAAuF;IACvF,OAAO,CAAC,0BAA0B;IA2C5B,aAAa,CAAC,CAAC,SAAS;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,EAC3C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IA6FxB,gBAAgB,CAAC,CAAC,EACtB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,CAAC;IAoHP,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;CAqGjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
|
package/dist/CrudService.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{toast as
|
|
1
|
+
import{toast as _}from"@donotdev/components";import{createSingleton as T,generateUUID as A,handleError as p,getQueryClient as D,getI18nInstance as m,hasProvider as l,getProvider as F,hasRestrictedVisibility as q,DEFAULT_STATUS_VALUE as N,withTimeout as L,DEFAULT_CRUD_TIMEOUT as M}from"@donotdev/core";import{LIST_SCHEMA_TYPE as C}from"@donotdev/core";import{CRUD_OPERATION as o}from"./types";const S=1/0,K=1e3*60*30;class b{adapter=null;store=null;security=null;currentUserId=null;_shouldShowSuccessToast(t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!this.store?.getState().hideSuccessToasts}setStore(t){this.store=t}setSecurity(t){this.security=t}setCurrentUser(t){this.currentUserId=t}_getPiiFields(t){return t?.security?.piiFields??[]}_auditCrud(t,e,s,a){this.security&&this.security.audit({type:t,collection:e,docId:s,userId:a??this.currentUserId??void 0})}_rateLimitKey(t){return this.currentUserId?`${this.currentUserId}:${t}`:t}_inflightMutations=new Map;_mutationKey(t,e){return`${t}:${e}`}async _withResilience(t,e=M){try{return await L(t(),e)}catch(s){if(this._isTransientError(s))return await new Promise(a=>setTimeout(a,2e3)),await L(t(),e);throw s}}_isTransientError(t){if(t instanceof Error){if(t.name==="TimeoutError"||t.message.includes("Failed to fetch")||t.message.includes("NetworkError")||t.message.includes("network"))return!0;const e=t.message.match(/(?:status|code)\s*:?\s*(\d{3})/i);if(e?.[1]&&parseInt(e[1])>=500)return!0}return!1}async _ensureAdapter(){this.adapter||await this.initialize()}_assertCanAccess(t,e){if(this.adapter&&e&&q(e)&&!this.adapter.serverSideOnly&&!this.adapter.dbLevelSecurity)throw new Error(`[dndev] Direct adapter cannot access "${t}": entity has restricted field visibility. Use a server-side adapter (FunctionsAdapter for Firebase, or SupabaseCrudAdapter with RLS enabled) to enforce field-level security (serverSideOnly = true | dbLevelSecurity = true).`)}async initialize(){if(!this.adapter){if(!l("crud"))throw new Error(`[dndev] No CRUD adapter configured. Call configureProviders({ crud: yourAdapter }) at app startup.
|
|
2
2
|
Examples:
|
|
3
3
|
import { FirestoreAdapter } from "@donotdev/firebase";
|
|
4
4
|
import { FunctionsAdapter } from "@donotdev/crud";
|
|
@@ -6,4 +6,4 @@ Examples:
|
|
|
6
6
|
|
|
7
7
|
configureProviders({ crud: new FirestoreAdapter() }) // Firebase direct
|
|
8
8
|
configureProviders({ crud: new FunctionsAdapter() }) // via callable functions
|
|
9
|
-
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);this.adapter=A("crud"),this.store&&this.store.getState().setCrudService(this)}}getQueryClient(){return E()}getListQueryOptions(t,e,i,r,o=S.LIST){const s=this.adapter,a=()=>this._ensureAdapter();return{queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:async()=>{if(s||await a(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,i,o)},staleTime:r?.staleTime??m}}getDocQueryOptions(t,e,i,r){const o=this.adapter,s=()=>this._ensureAdapter();return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(o||await s(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,i)},staleTime:r?.staleTime??m}}_updateGetCache(t,e,i,r){const o=this.getQueryClient(),s=["crud",t,"get",e];r===h.DELETE?o.removeQueries({queryKey:s}):r===h.SET&&i?o.setQueryData(s,i):(r===h.UPDATE||r===h.ADD)&&i&&o.setQueryData(s,a=>a?{...a,...i}:i)}_updateListCaches(t,e,i,r){const o=this.getQueryClient();this._updateGetCache(t,e,i,r),o.setQueriesData({queryKey:["crud",t]},s=>{if(s&&typeof s=="object"&&"items"in s){const a=s;let n=a.items;return r===h.DELETE?(n=a.items.filter(c=>c!=null&&typeof c=="object"&&c.id!==e),{...a,items:n,total:Math.max(0,(a.total??n.length)-1)}):r===h.ADD&&i?(n=[...a.items,{...i,id:e}],{...a,items:n,total:(a.total??a.items.length)+1}):(r===h.UPDATE||r===h.SET)&&i&&a.items.some(c=>c!=null&&typeof c=="object"&&c.id===e)?(n=a.items.map(c=>c==null||typeof c!="object"||c.id!==e?c:r===h.SET?{...i,id:e}:{...c,...i}),{...a,items:n}):s}if(Array.isArray(s)){if(r===h.DELETE)return s.filter(a=>a.id!==e);if(r===h.ADD&&i)return[...s,{...i,id:e}];if((r===h.UPDATE||r===h.SET)&&i)return s.some(a=>a!=null&&typeof a=="object"&&a.id===e)?s.map(a=>a==null||typeof a!="object"||a.id!==e?a:r===h.SET?{...i,id:e}:{...a,...i}):s}return s})}_checkUniquenessFromCache(t,e,i){const r=i.metadata?.uniqueKeys;if(!r||r.length===0)return null;const o=this.getQueryClient().getQueriesData({queryKey:["crud",t]}),s=[];for(const[,n]of o)n&&typeof n=="object"&&"items"in n?s.push(...n.items):Array.isArray(n)&&s.push(...n);if(s.length===0)return null;const a=e;for(const n of r){if(!n.fields.every(u=>a[u]!=null&&a[u]!==""))continue;const c=s.find(u=>n.fields.every(d=>{const g=typeof a[d]=="string"?a[d].toLowerCase():a[d],f=typeof u[d]=="string"?u[d].toLowerCase():u[d];return g===f}));if(c){if(n.findOrCreate)return c.id;const u=n.fields.join(" + ");throw l(new Error(n.errorMessage||`Duplicate ${u}`),{userMessage:n.errorMessage||`A record with this ${u} already exists`,showNotification:!0})}}return null}_getItemFromListCache(t,e){const i=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,r]of i)if(r?.items){const o=r.items.find(s=>s.id===e);if(o)return o}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,i,r){if(await this._ensureAdapter(),r?.noCache)return this._getFromAdapter(t,e,i);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,i,!1),staleTime:r?.staleTime??m})}catch(o){const s=l(o,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,s),s}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,i,r=!0){this.store&&r&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,i);const o=await this.adapter.get(t,e,i);if(o&&this.security){const s=this._getPiiFields(i);if(s.length>0)return this.security.decryptPii(o,s)}return o}catch(o){const s=l(o,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,s),s}finally{this.store&&r&&this.store.getState().setLoading(t,!1)}}async query(t,e,i,r,o=S.LIST){if(await this._ensureAdapter(),r?.noCache)return this._queryFromAdapter(t,e,i,!0,o);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,i,!1,o),staleTime:r?.staleTime??m})}catch(s){const a=l(s,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,i,r=!0,o=S.LIST){this.store&&r&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,i);const s=await this.adapter.query(t,e,i,o);if(this.security&&s.items.length>0){const a=this._getPiiFields(i);a.length>0&&(s.items=s.items.map(n=>this.security.decryptPii(n,a)))}return s}catch(s){const a=l(s,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&r&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=y();let i=`entity-${t}`,r=e.t("name",{ns:i,defaultValue:null});return r&&r!=="name"&&r!==`${i}:name`||t.endsWith("s")&&t.length>1&&(i=`entity-${t.slice(0,-1)}`,r=e.t("name",{ns:i,defaultValue:null}),r&&r!=="name"&&r!==`${i}:name`)?r:t}async set(t,e,i,r,o){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,i,s);try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,r),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const a=this._getPiiFields(r),n=a.length>0&&this.security?this.security.encryptPii(i,a):i;if(await this.adapter.set(t,e,n,r),this._updateListCaches(t,e,i,h.SET),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(o)){const c=y(),u=this._getEntityName(t);p("success",c.t("messages.updateSuccess",{ns:"crud",entity:u}))}}catch(a){s&&this._updateListCaches(t,e,s,h.SET),this.store&&this.store.getState().rejectUpdate(t,e);const n=l(a,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,n),n}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,i,r,o){await this._ensureAdapter(),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),a=s?{...s,...i}:{...i,id:e};this.store&&this.store.getState().updateOptimistic(t,e,a,s??null);try{if(!this.adapter)throw new Error("Adapter not initialized");r&&this._assertCanAccess(t,r),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const n=r?this._getPiiFields(r):[],c=n.length>0&&this.security?this.security.encryptPii(i,n):i;if(await this.adapter.update(t,e,c),this._updateListCaches(t,e,a,h.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(o)){const u=y(),d=this._getEntityName(t);p("success",u.t("messages.updateSuccess",{ns:"crud",entity:d}))}}catch(n){s?this._updateListCaches(t,e,s,h.UPDATE):this.invalidateCollection(t),this.store&&this.store.getState().rejectUpdate(t,e);const c=l(n,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,c),c}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,i){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&r&&this.store.getState().deleteOptimistic(t,e,r);try{if(!this.adapter)throw new Error("Adapter not initialized");if(this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write"),await this.adapter.delete(t,e),this._updateListCaches(t,e,null,h.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(i)){const o=y(),s=this._getEntityName(t);p("success",o.t("messages.deleteSuccess",{ns:"crud",entity:s}))}}catch(o){r&&this._updateListCaches(t,e,r,h.ADD),this.store&&this.store.getState().rejectDelete(t,e);const s=l(o,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,s),s}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,i,r){await this._ensureAdapter();const o=this._checkUniquenessFromCache(t,e,i);if(o)return o;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");this._assertCanAccess(t,i),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const a=this._getPiiFields(i),n=a.length>0&&this.security?this.security.encryptPii(e,a):e,c=n;(c.status===void 0||c.status===null)&&(c.status=T);const u=await this.adapter.add(t,n,i),d=u.id,g=u.data;if(this._updateListCaches(t,s,null,h.DELETE),this._updateListCaches(t,d,g,h.ADD),this.store&&this.store.getState().confirmOptimistic(t,s,d,g),this._auditCrud("crud.create",t,d),this._shouldShowSuccessToast(r)){const f=y(),_=this._getEntityName(t);p("success",f.t("messages.createSuccess",{ns:"crud",entity:_}))}return d}catch(a){this._updateListCaches(t,s,null,h.DELETE),this.store&&this.store.getState().rejectOptimistic(t,s);const n=l(a,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,n),n}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,i,r){if(!this.adapter){let o=!1,s=null;return this._ensureAdapter().then(()=>{o||(s=this._subscribeSync(t,e,i,r))}).catch(a=>{o||i(null,l(a))}),()=>{o=!0,s?.()}}return this._subscribeSync(t,e,i,r)}_subscribeSync(t,e,i,r){try{const o=this.adapter;return o?o.subscribe?(this._assertCanAccess(t,r),o.subscribe(t,e,(s,a)=>{s&&this.getQueryClient().setQueryData(["crud",t,"get",e],s),i(s,a)},r)):()=>{}:(i(null,new Error("Adapter not initialized")),()=>{})}catch(o){return i(null,l(o)),()=>{}}}subscribeToCollection(t,e,i,r){if(!this.adapter){let o=!1,s=null;return this._ensureAdapter().then(()=>{o||(s=this._subscribeToCollectionSync(t,e,i,r))}).catch(a=>{o||i([],l(a))}),()=>{o=!0,s?.()}}return this._subscribeToCollectionSync(t,e,i,r)}_subscribeToCollectionSync(t,e,i,r){try{const o=this.adapter;return o?o.subscribeToCollection?(this._assertCanAccess(t,r),o.subscribeToCollection(t,e,(s,a)=>{s&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],n=>n?{...n,items:s}:{items:s}),i(s,a)},r)):()=>{}:(i([],new Error("Adapter not initialized")),()=>{})}catch(o){return i([],l(o)),()=>{}}}async addOptimistic(t,e,i,r){await this._ensureAdapter();const o=this._checkUniquenessFromCache(t,e,i);if(o)return{...e,id:o};this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const s=`temp_${crypto.randomUUID()}`,a={...e,id:s,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,s,a);try{if(!this.adapter)throw new Error("Adapter not initialized");const n=await this.adapter.add(t,e,i),c=n.id,u=n.data;if(this._updateListCaches(t,s,null,h.DELETE),this._updateListCaches(t,c,u,h.ADD),this.store&&this.store.getState().confirmOptimistic(t,s,c,u),this._auditCrud("crud.create",t,c),this._shouldShowSuccessToast(r)){const d=y(),g=this._getEntityName(t);p("success",d.t("messages.createSuccess",{ns:"crud",entity:g}))}return u}catch(n){throw this._updateListCaches(t,s,null,h.DELETE),this.store&&this.store.getState().rejectOptimistic(t,s),l(n,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,i,r,o){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),a=s?{...s,...i,_optimistic:!0}:{...i,id:e,_optimistic:!0};this.store&&s&&this.store.getState().updateOptimistic(t,e,a,s);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,i);const{_optimistic:n,...c}=a;if(this._updateListCaches(t,e,c,h.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(o)){const u=y(),d=this._getEntityName(t);p("success",u.t("messages.updateSuccess",{ns:"crud",entity:d}))}return c}catch(n){throw s&&this._updateListCaches(t,e,s,h.UPDATE),this.store&&this.store.getState().rejectUpdate(t,e),l(n,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,i){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const r=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&r&&this.store.getState().deleteOptimistic(t,e,r);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,h.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(i)){const o=y(),s=this._getEntityName(t);p("success",o.t("messages.deleteSuccess",{ns:"crud",entity:s}))}}catch(o){throw r&&this._updateListCaches(t,e,r,h.ADD),this.store&&this.store.getState().rejectDelete(t,e),l(o,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const b=w(()=>new D);export{b as getCrudService};
|
|
9
|
+
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);this.adapter=F("crud"),this.store&&this.store.getState().setCrudService(this)}}getQueryClient(){return D()}getListQueryOptions(t,e,s,a,n=C.LIST){const r=this.adapter,i=()=>this._ensureAdapter();return{queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:async()=>{if(r||await i(),!this.adapter)throw new Error("Adapter not initialized");const u=this.adapter;return this._withResilience(()=>u.query(t,e,s,n))},staleTime:a?.staleTime??S}}getDocQueryOptions(t,e,s,a){const n=this.adapter,r=()=>this._ensureAdapter();return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(n||await r(),!this.adapter)throw new Error("Adapter not initialized");const i=this.adapter;return this._withResilience(()=>i.get(t,e,s))},staleTime:a?.staleTime??S}}_updateGetCache(t,e,s,a){const n=this.getQueryClient(),r=["crud",t,"get",e];a===o.DELETE?n.removeQueries({queryKey:r}):a===o.SET&&s?n.setQueryData(r,s):(a===o.UPDATE||a===o.ADD)&&s&&n.setQueryData(r,i=>i?{...i,...s}:s)}_updateListCaches(t,e,s,a){const n=this.getQueryClient();this._updateGetCache(t,e,s,a),n.setQueriesData({queryKey:["crud",t]},r=>{if(r&&typeof r=="object"&&"items"in r){const i=r;let u=i.items;return a===o.DELETE?(u=i.items.filter(d=>d!=null&&typeof d=="object"&&d.id!==e),{...i,items:u,total:Math.max(0,(i.total??u.length)-1)}):a===o.ADD&&s?(u=[...i.items,{...s,id:e}],{...i,items:u,total:(i.total??i.items.length)+1}):(a===o.UPDATE||a===o.SET)&&s&&i.items.some(h=>h!=null&&typeof h=="object"&&h.id===e)?(u=i.items.map(h=>h==null||typeof h!="object"||h.id!==e?h:a===o.SET?{...s,id:e}:{...h,...s}),{...i,items:u}):r}if(Array.isArray(r)){if(a===o.DELETE)return r.filter(i=>i.id!==e);if(a===o.ADD&&s)return[...r,{...s,id:e}];if((a===o.UPDATE||a===o.SET)&&s)return r.some(u=>u!=null&&typeof u=="object"&&u.id===e)?r.map(u=>u==null||typeof u!="object"||u.id!==e?u:a===o.SET?{...s,id:e}:{...u,...s}):r}return r})}_checkUniquenessFromCache(t,e,s){const n=s.metadata?.uniqueKeys;if(!n||n.length===0)return null;const i=this.getQueryClient().getQueriesData({queryKey:["crud",t]}),u=[];for(const[,h]of i)h&&typeof h=="object"&&"items"in h?u.push(...h.items):Array.isArray(h)&&u.push(...h);if(u.length===0)return null;const d=e;for(const h of n){if(!h.fields.every(g=>d[g]!=null&&d[g]!==""))continue;const f=u.find(g=>h.fields.every(c=>{const w=typeof d[c]=="string"?d[c].toLowerCase():d[c],E=typeof g[c]=="string"?g[c].toLowerCase():g[c];return w===E}));if(f){if(h.findOrCreate)return f.id;const g=h.fields.join(" + ");throw p(new Error(h.errorMessage||`Duplicate ${g}`),{userMessage:h.errorMessage||`A record with this ${g} already exists`,showNotification:!0})}}return null}_getItemFromListCache(t,e){const a=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,n]of a)if(n?.items){const r=n.items.find(i=>i.id===e);if(r)return r}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,s,a){if(await this._ensureAdapter(),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??S})}catch(n){const r=p(n,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}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");this._assertCanAccess(t,s);const n=this.adapter,r=await this._withResilience(()=>n.get(t,e,s));if(r&&this.security){const i=this._getPiiFields(s);if(i.length>0)return this.security.decryptPii(r,i)}return r}catch(n){const r=p(n,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,s,a,n=C.LIST){if(await this._ensureAdapter(),a?.noCache)return this._queryFromAdapter(t,e,s,!0,n);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,s,!1,n),staleTime:a?.staleTime??S})}catch(r){const i=p(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,s,a=!0,n=C.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");this._assertCanAccess(t,s);const r=this.adapter,i=await this._withResilience(()=>r.query(t,e,s,n));if(this.security&&i.items.length>0){const u=this._getPiiFields(s);u.length>0&&(i.items=i.items.map(d=>this.security.decryptPii(d,u)))}return i}catch(r){const i=p(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)}}_getEntityName(t){const e=m();let s=`entity-${t}`,a=e.t("name",{ns:s,defaultValue:null});return a&&a!=="name"&&a!==`${s}:name`||t.endsWith("s")&&t.length>1&&(s=`entity-${t.slice(0,-1)}`,a=e.t("name",{ns:s,defaultValue:null}),a&&a!=="name"&&a!==`${s}:name`)?a:t}async set(t,e,s,a,n){await this._ensureAdapter(),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,s,i);try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,a),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const u=this._getPiiFields(a),d=u.length>0&&this.security?this.security.encryptPii(s,u):s,h=this._mutationKey(t,e),y=this._inflightMutations.get(h);y&&await y.catch(()=>{});const f=this.adapter,g=(async()=>{await this._withResilience(()=>f.set(t,e,d,a))})();this._inflightMutations.set(h,g);try{await g}finally{this._inflightMutations.get(h)===g&&this._inflightMutations.delete(h)}if(this._updateListCaches(t,e,s,o.SET),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(n)){const c=m(),w=this._getEntityName(t);_("success",c.t("messages.updateSuccess",{ns:"crud",entity:w}))}}catch(u){i&&this._updateListCaches(t,e,i,o.SET),this.store&&this.store.getState().rejectUpdate(t,e);const d=p(u,{userMessage:`Failed to save ${t}`,showNotification:!0}),h=m(),y=this._getEntityName(t);throw _("error",h.t("messages.updateError",{ns:"crud",entity:y})),this.store&&this.store.getState().setError(t,d),d}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,s,a,n){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),u=i?{...i,...s}:{...s,id:e};this.store&&this.store.getState().updateOptimistic(t,e,u,i??null);try{if(!this.adapter)throw new Error("Adapter not initialized");a&&this._assertCanAccess(t,a),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const d=a?this._getPiiFields(a):[],h=d.length>0&&this.security?this.security.encryptPii(s,d):s,y=this._mutationKey(t,e),f=this._inflightMutations.get(y);f&&await f.catch(()=>{});const g=this.adapter,c=(async()=>{await this._withResilience(()=>g.update(t,e,h))})();this._inflightMutations.set(y,c);try{await c}finally{this._inflightMutations.get(y)===c&&this._inflightMutations.delete(y)}if(this._updateListCaches(t,e,u,o.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(n)){const w=m(),E=this._getEntityName(t);_("success",w.t("messages.updateSuccess",{ns:"crud",entity:E}))}}catch(d){i?this._updateListCaches(t,e,i,o.UPDATE):this.invalidateCollection(t),this.store&&this.store.getState().rejectUpdate(t,e);const h=p(d,{userMessage:`Failed to update ${t}`,showNotification:!0}),y=m(),f=this._getEntityName(t);throw _("error",y.t("messages.updateError",{ns:"crud",entity:f})),this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,s){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const n=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&n&&this.store.getState().deleteOptimistic(t,e,n);try{if(!this.adapter)throw new Error("Adapter not initialized");this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const r=this._mutationKey(t,e),i=this._inflightMutations.get(r);i&&await i.catch(()=>{});const u=this.adapter,d=(async()=>{await this._withResilience(()=>u.delete(t,e))})();this._inflightMutations.set(r,d);try{await d}finally{this._inflightMutations.get(r)===d&&this._inflightMutations.delete(r)}if(this._updateListCaches(t,e,null,o.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const h=m(),y=this._getEntityName(t);_("success",h.t("messages.deleteSuccess",{ns:"crud",entity:y}))}}catch(r){n&&this._updateListCaches(t,e,n,o.ADD),this.store&&this.store.getState().rejectDelete(t,e);const i=p(r,{userMessage:`Failed to delete ${t}`,showNotification:!0}),u=m(),d=this._getEntityName(t);throw _("error",u.t("messages.deleteError",{ns:"crud",entity:d})),this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,s,a){await this._ensureAdapter();const n=this._checkUniquenessFromCache(t,e,s);if(n)return n;this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=`temp_${A()}`;this.store&&this.store.getState().addOptimistic(t,r,{...e,id:r});try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,s),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const i=this._getPiiFields(s),u=i.length>0&&this.security?this.security.encryptPii(e,i):e,d=u;(d.status===void 0||d.status===null)&&(d.status=N);const h=this.adapter,y=await this._withResilience(()=>h.add(t,u,s)),f=y.id,g=y.data;if(this._updateListCaches(t,r,null,o.DELETE),this._updateListCaches(t,f,g,o.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,f,g),this._auditCrud("crud.create",t,f),this._shouldShowSuccessToast(a)){const c=m(),w=this._getEntityName(t);_("success",c.t("messages.createSuccess",{ns:"crud",entity:w}))}return f}catch(i){this._updateListCaches(t,r,null,o.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r);const u=p(i,{userMessage:`Failed to create ${t}`,showNotification:!0}),d=m(),h=this._getEntityName(t);throw _("error",d.t("messages.createError",{ns:"crud",entity:h})),this.store&&this.store.getState().setError(t,u),u}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,s,a){if(!this.adapter){let n=!1,r=null;return this._ensureAdapter().then(()=>{n||(r=this._subscribeSync(t,e,s,a))}).catch(i=>{n||s(null,p(i))}),()=>{n=!0,r?.()}}return this._subscribeSync(t,e,s,a)}_subscribeSync(t,e,s,a){try{const n=this.adapter;return n?n.subscribe?(this._assertCanAccess(t,a),n.subscribe(t,e,(r,i)=>{r&&this.getQueryClient().setQueryData(["crud",t,"get",e],r),s(r,i)},a)):()=>{}:(s(null,new Error("Adapter not initialized")),()=>{})}catch(n){return s(null,p(n)),()=>{}}}subscribeToCollection(t,e,s,a){if(!this.adapter){let n=!1,r=null;return this._ensureAdapter().then(()=>{n||(r=this._subscribeToCollectionSync(t,e,s,a))}).catch(i=>{n||s([],p(i))}),()=>{n=!0,r?.()}}return this._subscribeToCollectionSync(t,e,s,a)}_subscribeToCollectionSync(t,e,s,a){try{const n=this.adapter;return n?n.subscribeToCollection?(this._assertCanAccess(t,a),n.subscribeToCollection(t,e,(r,i)=>{r&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],u=>u?{...u,items:r}:{items:r}),s(r,i)},a)):()=>{}:(s([],new Error("Adapter not initialized")),()=>{})}catch(n){return s([],p(n)),()=>{}}}async addOptimistic(t,e,s,a){await this._ensureAdapter();const n=this._checkUniquenessFromCache(t,e,s);if(n)return{...e,id:n};this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const r=`temp_${A()}`,i={...e,id:r,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,r,i);try{if(!this.adapter)throw new Error("Adapter not initialized");const u=this.adapter,d=await this._withResilience(()=>u.add(t,e,s)),h=d.id,y=d.data;if(this._updateListCaches(t,r,null,o.DELETE),this._updateListCaches(t,h,y,o.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,h,y),this._auditCrud("crud.create",t,h),this._shouldShowSuccessToast(a)){const f=m(),g=this._getEntityName(t);_("success",f.t("messages.createSuccess",{ns:"crud",entity:g}))}return y}catch(u){this._updateListCaches(t,r,null,o.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r);const d=p(u,{userMessage:`Failed to create ${t}`,showNotification:!0}),h=m(),y=this._getEntityName(t);throw _("error",h.t("messages.createError",{ns:"crud",entity:y})),d}}async updateOptimistic(t,e,s,a,n){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),u=i?{...i,...s,_optimistic:!0}:{...s,id:e,_optimistic:!0};this.store&&i&&this.store.getState().updateOptimistic(t,e,u,i);try{if(!this.adapter)throw new Error("Adapter not initialized");const d=this._mutationKey(t,e),h=this._inflightMutations.get(d);h&&await h.catch(()=>{});const y=this.adapter,f=(async()=>{await this._withResilience(()=>y.update(t,e,s))})();this._inflightMutations.set(d,f);try{await f}finally{this._inflightMutations.get(d)===f&&this._inflightMutations.delete(d)}const{_optimistic:g,...c}=u;if(this._updateListCaches(t,e,c,o.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(n)){const w=m(),E=this._getEntityName(t);_("success",w.t("messages.updateSuccess",{ns:"crud",entity:E}))}return c}catch(d){i&&this._updateListCaches(t,e,i,o.UPDATE),this.store&&this.store.getState().rejectUpdate(t,e);const h=p(d,{userMessage:`Failed to update ${t}`,showNotification:!0}),y=m(),f=this._getEntityName(t);throw _("error",y.t("messages.updateError",{ns:"crud",entity:f})),h}}async deleteOptimistic(t,e,s){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const n=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&n&&this.store.getState().deleteOptimistic(t,e,n);try{if(!this.adapter)throw new Error("Adapter not initialized");const r=this._mutationKey(t,e),i=this._inflightMutations.get(r);i&&await i.catch(()=>{});const u=this.adapter,d=(async()=>{await this._withResilience(()=>u.delete(t,e))})();this._inflightMutations.set(r,d);try{await d}finally{this._inflightMutations.get(r)===d&&this._inflightMutations.delete(r)}if(this._updateListCaches(t,e,null,o.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const h=m(),y=this._getEntityName(t);_("success",h.t("messages.deleteSuccess",{ns:"crud",entity:y}))}}catch(r){n&&this._updateListCaches(t,e,n,o.ADD),this.store&&this.store.getState().rejectDelete(t,e);const i=p(r,{userMessage:`Failed to delete ${t}`,showNotification:!0}),u=m(),d=this._getEntityName(t);throw _("error",u.t("messages.deleteError",{ns:"crud",entity:d})),i}}}const R=T(()=>new b);export{R as getCrudService};
|
package/dist/CrudStore.d.ts
CHANGED
package/dist/CrudStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAEV,SAAS,EACT,WAAW,EAIZ,MAAM,SAAS,CAAC;AAyBjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"CrudStore.d.ts","sourceRoot":"","sources":["../src/CrudStore.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAEV,SAAS,EACT,WAAW,EAIZ,MAAM,SAAS,CAAC;AAyBjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,iIA+avB,CAAC"}
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as
|
|
1
|
+
import{createDoNotDevStore as S}from"@donotdev/core";import{OPTIMISTIC_STATUSES as m,CRUD_OPERATION as a}from"./types";const d={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...d}}}const D={crudService:null,hideSuccessToasts:!1,collections:{}},E=S({name:"crud-store",createStore:(n,s)=>({...D,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,loading:c}}}})},setError:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,error:c,loading:!1}}}})},setFilters:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,ui:{...o.ui,filters:c}}}}})},setShowFavoritesOnly:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,ui:{...o.ui,showFavoritesOnly:c}}}}})},getFilters:t=>s().collections[t]?.ui?.filters||{},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,ui:{...o.ui,pageSize:c}}}}})},getPageSize:t=>s().collections[t]?.ui?.pageSize,clearCollection:t=>{n(c=>{const{[t]:i,...o}=c.collections;return{collections:o}})},clearError:t=>{n(c=>{const i=c.collections[t];return i?{collections:{...c.collections,[t]:{...i,error:null}}}:c})},addOptimistic:(t,c,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,optimistic:{...e.optimistic,[c]:{tempId:c,originalData:null,optimisticData:i,status:m.PENDING,operation:a.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,c,i,o)=>{n(e=>{const l=e.collections[t];if(!l)return e;const{[c]:p,...u}=l.optimistic;return{collections:{...e.collections,[t]:{...l,optimistic:u,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,c,i,o)=>{n(e=>{const l=e.collections[t]||r();return{collections:{...e.collections,[t]:{...l,optimistic:{...l.optimistic,[c]:{tempId:c,originalData:o,optimisticData:i,status:m.PENDING,operation:a.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l}}}})},rejectUpdate:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const e=o.optimistic[c];if(!e||e.operation!==a.UPDATE)return i;const{[c]:l,...p}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,c,i)=>{n(o=>{const e=o.collections[t];return e?{collections:{...o.collections,[t]:{...e,optimistic:{...e.optimistic,[c]:{tempId:c,originalData:i,optimisticData:null,status:m.PENDING,operation:a.DELETE}},lastUpdated:Date.now()}}}:o})},confirmDelete:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l}}}})},rejectDelete:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const e=o.optimistic[c];if(!e||e.operation!==a.DELETE)return i;const{[c]:l,...p}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,c)=>s().collections[t]?.optimistic[c]?.status==="pending",getOptimisticStatus:(t,c)=>s().collections[t]?.optimistic[c]?.status??null,getOptimisticData:(t,c)=>s().collections[t]?.optimistic[c]?.optimisticData??null})});export{E as useCrudStore};
|
package/dist/FieldRegistry.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Field Type Registry
|
|
3
|
-
* @description UI component registry for field types. Schemas handled by @donotdev/core.
|
|
4
|
-
*
|
|
5
|
-
* @version 0.0.1
|
|
6
|
-
* @since 0.0.1
|
|
7
|
-
* @author AMBROISE PARK Consulting
|
|
8
|
-
*/
|
|
9
1
|
import type { EntityField, FieldType, ValueTypeForField } from '@donotdev/core';
|
|
10
2
|
import type { ControlledFieldProps } from './components/controlled/types';
|
|
11
3
|
import type { ComponentType, ReactElement } from 'react';
|
|
@@ -103,10 +95,8 @@ declare class FieldRegistry {
|
|
|
103
95
|
clear(): void;
|
|
104
96
|
}
|
|
105
97
|
/**
|
|
106
|
-
* Get the field registry singleton
|
|
107
|
-
*
|
|
108
|
-
* Note: Built-in field types are auto-registered via side-effect import in FormFieldRenderer
|
|
109
|
-
* This ensures they're registered when the registry is first used, without tree-shaking issues
|
|
98
|
+
* Get the field registry singleton.
|
|
99
|
+
* Backed by globalThis to survive Vite pre-bundling chunk splits and HMR.
|
|
110
100
|
*/
|
|
111
101
|
export declare function getFieldRegistry(): FieldRegistry;
|
|
112
102
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldRegistry.d.ts","sourceRoot":"","sources":["../src/FieldRegistry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FieldRegistry.d.ts","sourceRoot":"","sources":["../src/FieldRegistry.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;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;IAI1B;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAI9B;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,SAAS,EACpD,YAAY,EAAE,qBAAqB,CAAC,EAAE,CAAC,GACtC,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
package/dist/FieldRegistry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";class
|
|
1
|
+
"use client";import{getGlobalSingleton as p}from"@donotdev/core";class d{components=new Map;displayFormatters=new Map;filterMetadata=new Map;registerComponent(e,t,n){this.components.set(e,{controlled:t,uncontrolled:n})}register(e){const{type:t,controlledComponent:n,uncontrolledComponent:o,displayFormatter:i,filterable:s,filterType:l}=e;(n||o)&&this.components.set(t,{controlled:n,uncontrolled:o}),i&&this.displayFormatters.set(t,i),(s!==void 0||l!==void 0)&&this.filterMetadata.set(t,{filterable:s??!1,filterType:l})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}getDisplayFormatter(e){return this.displayFormatters.get(e)}getFilterType(e){return this.filterMetadata.get(e)?.filterType}isFilterable(e){return this.filterMetadata.get(e)?.filterable??!1}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear(),this.displayFormatters.clear(),this.filterMetadata.clear()}}function a(){return p("field-registry",()=>new d)}function f(r){a().register(r)}function g(r){return a().has(r)}export{a as getFieldRegistry,g as isFieldTypeRegistered,f as registerFieldType};
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - Audit logs and metadata
|
|
10
10
|
* - Rate limiting
|
|
11
11
|
*
|
|
12
|
-
* @version 0.0
|
|
12
|
+
* @version 0.1.0
|
|
13
13
|
* @since 0.0.1
|
|
14
14
|
* @author AMBROISE PARK Consulting
|
|
15
15
|
*/
|
|
@@ -17,7 +17,7 @@ import type { dndevSchema, ICrudAdapter, ListSchemaType, PaginatedQueryResult }
|
|
|
17
17
|
/**
|
|
18
18
|
* Query options for Functions queries
|
|
19
19
|
*
|
|
20
|
-
* @version 0.0
|
|
20
|
+
* @version 0.1.0
|
|
21
21
|
* @since 0.0.1
|
|
22
22
|
* @author AMBROISE PARK Consulting
|
|
23
23
|
*/
|
|
@@ -43,7 +43,7 @@ export interface FunctionsQueryOptions {
|
|
|
43
43
|
*
|
|
44
44
|
* All backends go through ICallableProvider. If none configured, falls back to FirebaseCallableProvider.
|
|
45
45
|
*
|
|
46
|
-
* @version 0.0
|
|
46
|
+
* @version 0.1.0
|
|
47
47
|
* @since 0.0.1
|
|
48
48
|
* @author AMBROISE PARK Consulting
|
|
49
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FunctionsAdapter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EACZ,cAAc,EACd,oBAAoB,EACrB,MAAM,gBAAgB,CAAC;AAIxB;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,C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AC;IAwBnD,KAAK,CAAC,CAAC,EACX,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,UAAU,GAAE,cAAsC,GACjD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAqEnC,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI;IAS1B,qBAAqB,CAAC,CAAC,KAAK,MAAM,IAAI;CAQvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getProvider as
|
|
1
|
+
import{getProvider as l,wrapCrudError as o,validateWithSchema as c}from"@donotdev/core";import{LIST_SCHEMA_TYPE as u}from"@donotdev/core";class h{serverSideOnly=!0;getCallable(){return l("callable")}async getCallableFn(a){const t=this.getCallable();return async n=>({data:await t.call(a,n)})}async get(a,t,n){const d=`get_${a}`,i=await this.getCallableFn(d);try{const s=(await i({id:t})).data;return n?c(n,s,"FunctionsAdapter.get"):s}catch(r){throw o(r,"FunctionsAdapter","get",a,t)}}async set(a,t,n,d){const i=c(d,n,"FunctionsAdapter.set"),r=`update_${a}`,s=await this.getCallableFn(r);try{await s({id:t,payload:i})}catch(e){throw o(e,"FunctionsAdapter","set",a,t)}}async update(a,t,n){const d=`update_${a}`,i=await this.getCallableFn(d);try{await i({id:t,payload:n})}catch(r){throw o(r,"FunctionsAdapter","update",a,t)}}async delete(a,t){const n=`delete_${a}`,d=await this.getCallableFn(n);try{await d({id:t})}catch(i){throw o(i,"FunctionsAdapter","delete",a,t)}}async add(a,t,n){const d=c(n,t,"FunctionsAdapter.add"),i=`create_${a}`,r=await this.getCallableFn(i);try{const s=await r({payload:d});if(!s.data)throw o(new Error("Create function returned no data"),"FunctionsAdapter","add",a);return{id:s.data.id,data:s.data}}catch(s){throw o(s,"FunctionsAdapter","add",a)}}async query(a,t,n,d=u.LIST){const i=d===u.LIST_CARD?`listCard_${a}`:`list_${a}`,r={};t.where&&(r.where=t.where.map(e=>[e.field,e.operator,e.value])),t.orderBy&&(r.orderBy=t.orderBy.map(e=>[e.field,e.direction||"asc"])),t.limit&&(r.limit=t.limit),t.startAfter&&(r.startAfterId=t.startAfter);const s=await this.getCallableFn(i);try{const e=await s(r);if(!e.data)throw o(new Error("Query function returned no data"),"FunctionsAdapter","query",a);return{items:e.data.items,total:e.data.count,hasMore:e.data.hasMore,lastVisible:e.data.lastVisible}}catch(e){throw o(e,"FunctionsAdapter","query",a)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{h as FunctionsAdapter};
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ActionButtonProps } from '@donotdev/components';
|
|
2
2
|
import type { ReactNode } from 'react';
|
|
3
|
+
/** Props for {@link CrudButton}, an ActionButton variant that auto-checks CRUD availability. */
|
|
3
4
|
export interface CrudButtonProps<T = unknown> extends Omit<ActionButtonProps<T>, 'disabled'> {
|
|
4
5
|
/**
|
|
5
6
|
* Whether user authentication is required for this action.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CACxD,iBAAiB,CAAC,CAAC,CAAC,EACpB,UAAU,CACX;IACC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,EAC/B,YAAmB,EACnB,IAAI,EACJ,QAAgB,EAChB,QAAQ,EACR,GAAG,iBAAiB,EACrB,EAAE,eAAe,CAAC,CAAC,CAAC,2CAYpB;AAED,eAAe,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,gGAAgG;AAChG,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CACxD,iBAAiB,CAAC,CAAC,CAAC,EACpB,UAAU,CACX;IACC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,EAC/B,YAAmB,EACnB,IAAI,EACJ,QAAgB,EAChB,QAAQ,EACR,GAAG,iBAAiB,EACrB,EAAE,eAAe,CAAC,CAAC,CAAC,2CAYpB;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{ActionButton as d}from"@donotdev/components";import{useCrudStore as l}from"../CrudStore";function a({requiresAuth:t=!0,user:e,disabled:r=!1,children:i,...o}){const s=l(u=>!!u.crudService);return n(d,{...o,disabled:r||!s||t&&!e,children:i})}var p=a;export{p as default};
|
|
@@ -3,6 +3,6 @@ import type { CrudCardProps } from '@donotdev/core';
|
|
|
3
3
|
* CrudCard — Presentational card from entity + item + field slots.
|
|
4
4
|
* No routing: use onClick for interaction. Parent wraps with Link if needed.
|
|
5
5
|
*/
|
|
6
|
-
export declare function CrudCard({ item, entity, onClick, titleFields: titleFieldsProp, subtitleFields: subtitleFieldsProp, contentFields: contentFieldsProp, footerFields: footerFieldsProp, showDelete, renderActions, className, }: CrudCardProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare function CrudCard({ item, entity, onClick, titleFields: titleFieldsProp, subtitleFields: subtitleFieldsProp, contentFields: contentFieldsProp, footerFields: footerFieldsProp, showDelete, renderActions, renderOverlay, className, }: CrudCardProps): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export default CrudCard;
|
|
8
8
|
//# sourceMappingURL=CrudCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,SAAS,GACV,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,2CAgNf;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as i,jsxs as
|
|
1
|
+
import{jsx as i,jsxs as B}from"react/jsx-runtime";import{Trash2 as G}from"lucide-react";import{useMemo as v}from"react";import{Card as H,Stack as k,Text as D,ActionButton as J}from"@donotdev/components";import{useTranslation as L,getListCardFieldNames as K}from"@donotdev/core";import{formatValue as x}from"./DisplayFieldRenderer";import{DisplayThumbnail as R}from"./DisplayThumbnail";import{translateFieldLabel as Q}from"../forms/utils/translateFieldLabel";import{useCrud as U}from"../useCrud";function u(t){return t==="image"||t==="images"}function W(t){return v(()=>{const n=t.listCardFields;if(n&&!Array.isArray(n)){const s=n;return{titleFields:s.title??[],subtitleFields:s.subtitle??[],contentFields:s.content??[],footerFields:s.footer??[]}}const g=K(t),m=g.filter(s=>!u(t.fields[s]?.type)),C=g.filter(s=>u(t.fields[s]?.type)),I=m.length>0?[m[0]]:[],S=[...m.slice(1,4),...C];return{titleFields:I,subtitleFields:[],contentFields:S,footerFields:[]}},[t])}function X({item:t,entity:n,onClick:g,titleFields:m,subtitleFields:C,contentFields:I,footerFields:S,showDelete:s=!1,renderActions:w,renderOverlay:y,className:z}){const{t:o}=L([n.namespace,"crud"]),{t:F}=L("crud"),b=W(n),T=m??b.titleFields,j=C??b.subtitleFields,V=I??b.contentFields,h=S??b.footerFields,f=t,A=v(()=>{if(!T?.length)return t.id??"";const c=T.filter(l=>typeof l=="string").filter(l=>!u(n.fields[l]?.type)).map(l=>{const r=n.fields[l],a=t[l],p=r?x(a,r,o,{compact:!0,asString:!0,item:f}):a;return typeof p=="string"?p:String(p??"")}).filter(Boolean),e=!Array.isArray(n.listCardFields)&&n.listCardFields?.titleSeparator!=null?n.listCardFields.titleSeparator:" ";return c.join(e)||String(t.id??"")},[t,n.fields,T,n.listCardFields,o]),E=v(()=>j?.length&&j.filter(e=>typeof e=="string").filter(e=>!u(n.fields[e]?.type)).map(e=>{const l=n.fields[e],r=t[e],a=l?x(r,l,o,{compact:!0,asString:!0,item:f}):r;return typeof a=="string"?a:String(a??"")}).filter(Boolean).join(" ")||void 0,[t,n.fields,j,o]),M=v(()=>{if(!V?.length)return null;const c=V.map(e=>{const l=n.fields[e];if(!l||l.options?.displayValue?.(t[e],f,o)===null)return null;if(u(l.type)){const r=t[e];return r==null?null:i(R,{pictures:r,alt:String(A),aspectRatio:"16/9"},e)}return B("div",{children:[i(D,{level:"small",variant:"muted",children:Q(e,l,o)}),i(D,{children:x(t[e],l,o,{compact:!0,item:f})})]},e)}).filter(Boolean);return c.length>0?i(k,{direction:"column",gap:"tight",children:c}):null},[t,n.fields,V,A,o]),P=v(()=>{if(!h?.length)return;if(h.some(e=>u(n.fields[e]?.type))){const e=h.map(l=>{const r=n.fields[l];if(!r)return null;if(u(r.type)){const p=t[l];return p==null?null:i(R,{pictures:p,alt:"",aspectRatio:"1"},l)}const a=x(t[l],r,o,{compact:!0,item:f});return i("span",{children:a},l)});return i(k,{direction:"row",gap:"tight",align:"center",children:e.filter(Boolean)})}const c=h.map(e=>{const l=n.fields[e];return l?x(t[e],l,o,{compact:!0,item:f}):t[e]});return i(D,{level:"small",children:c.join(" \xB7 ")})},[t,n.fields,h,o]),_=U(n).delete,q=w||s?B("div",{style:{position:"absolute",top:"var(--gap-sm)",insetInlineEnd:"var(--gap-sm)",zIndex:10,display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)"},onClick:d=>d.stopPropagation(),onMouseDown:d=>d.stopPropagation(),children:[w,s&&i(J,{action:async()=>{await _(t.id)},confirmText:F("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:F("delete.title",{defaultValue:"Delete Item"}),loadingText:F("delete.loading",{defaultValue:"Deleting..."}),variant:"destructive",icon:G,"aria-label":F("delete",{defaultValue:"Delete"}),children:F("delete",{defaultValue:"Delete"})})]}):null;return B(H,{title:String(A??""),subtitle:E,content:M??void 0,footer:P,clickable:!0,elevated:!0,onClick:g?()=>g(t.id):void 0,className:z,children:[y&&i("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none",zIndex:5},children:y}),q]})}var rt=X;export{X as CrudCard,rt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as
|
|
1
|
+
"use client";import{jsx as e,jsxs as k,Fragment as ht}from"react/jsx-runtime";import{X as Dt}from"lucide-react";import{useState as T,useMemo as pt}from"react";import{Button as S,Calendar as St,FloatingLabel as yt,Sheet as E,Text as ut}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function Ft({label:y,fieldType:xt,value:s,onChange:u,tCrud:o,locale:N="en"}){const[Y,i]=T(!1),[v,f]=T(null),O=pt(()=>s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},[s]),F=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,N)}catch{return t}},W=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),c=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),d=`${n}-${c}-${r}`,l=new Date(t);l.setDate(l.getDate()-1);const M=l.getFullYear(),x=String(l.getMonth()+1).padStart(2,"0"),C=String(l.getDate()).padStart(2,"0"),R=`${M}-${x}-${C}`,g=new Date(t);g.setDate(g.getDate()+1);const z=g.getFullYear(),A=String(g.getMonth()+1).padStart(2,"0"),B=String(g.getDate()).padStart(2,"0"),H=`${z}-${A}-${B}`,m=new Date(t);m.setDate(m.getDate()-7);const L=m.getFullYear(),P=String(m.getMonth()+1).padStart(2,"0"),X=String(m.getDate()).padStart(2,"0"),q=`${L}-${P}-${X}`,h=new Date(t);h.setDate(h.getDate()-30);const G=h.getFullYear(),I=String(h.getMonth()+1).padStart(2,"0"),J=String(h.getDate()).padStart(2,"0"),K=`${G}-${I}-${J}`,D=new Date(t);D.setDate(D.getDate()+7);const Q=D.getFullYear(),U=String(D.getMonth()+1).padStart(2,"0"),Z=String(D.getDate()).padStart(2,"0"),tt=`${Q}-${U}-${Z}`,p=new Date(t);p.setDate(p.getDate()+30);const et=p.getFullYear(),at=String(p.getMonth()+1).padStart(2,"0"),nt=String(p.getDate()).padStart(2,"0"),rt=`${et}-${at}-${nt}`,$=new Date(t.getFullYear(),t.getMonth(),1),st=$.getFullYear(),ot=String($.getMonth()+1).padStart(2,"0"),it=String($.getDate()).padStart(2,"0"),lt=`${st}-${ot}-${it}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),ct=w.getFullYear(),dt=String(w.getMonth()+1).padStart(2,"0"),gt=String(w.getDate()).padStart(2,"0"),mt=`${ct}-${dt}-${gt}`;return{today:d,yesterday:R,tomorrow:H,last7Days:q,last30Days:K,next7Days:tt,next30Days:rt,thisMonthStart:lt,thisMonthEnd:mt}},a=O,_=W(),b=!!(a?.min||a?.max),V=t=>{const n=t==="start",c=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:k("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const d=_[r];return e(S,{variant:"outline",onClick:()=>{u({min:n?d:a?.min||"",max:n?a?.max||"":d}),i(!1)},children:o(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:c?new Date(c+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const d=r.getFullYear(),l=String(r.getMonth()+1).padStart(2,"0"),M=String(r.getDate()).padStart(2,"0"),x=`${d}-${l}-${M}`;u({min:n?x:a?.min||"",max:n?a?.max||"":x}),i(!1)},defaultMonth:c?new Date(c+"T00:00:00"):new Date}),e(S,{variant:"ghost",display:"compact",onClick:()=>{u({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:o("filter.clear",{defaultValue:"Clear"})})]})})},j=k(ht,{children:[e(E,{trigger:e(S,{variant:"ghost",onClick:()=>{f("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a?.min?F(a.min):o("filter.min",{defaultValue:"Min"})}),title:`${y} - ${o("filter.min",{defaultValue:"Min"})}`,open:Y&&v==="start",onOpenChange:t=>{i(t),t||f(null)},children:V("start")}),e(ut,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(E,{trigger:e(S,{variant:"ghost",onClick:()=>{f("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a?.max?F(a.max):o("filter.max",{defaultValue:"Max"})}),title:`${y} - ${o("filter.max",{defaultValue:"Max"})}`,open:Y&&v==="end",onOpenChange:t=>{i(t),t||f(null)},children:V("end")}),e(S,{variant:"ghost",display:"compact",icon:e(Dt,{size:16}),onClick:()=>{u(void 0)},disabled:!b,"aria-label":o("filter.clear",{defaultValue:"Clear"})})]});return y?e(yt,{label:y,children:e("div",{className:"dndev-range-input",children:j})}):e("div",{className:"dndev-range-input",children:j})}export{Ft as DateFilter};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FieldType, EntityField } from '@donotdev/core';
|
|
2
2
|
import type { DisplayFormatterOptions } from '../fieldTypeRegistry';
|
|
3
3
|
import type { ReactElement } from 'react';
|
|
4
|
+
/** Props for {@link DisplayFieldRenderer}, renders a field value as read-only text. */
|
|
4
5
|
export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
|
|
5
6
|
/** Field identifier */
|
|
6
7
|
name: string;
|
|
@@ -31,7 +32,7 @@ export declare function formatValue(value: any, config: EntityField, t: (key: st
|
|
|
31
32
|
* - editable: 'admin' and viewer is not admin
|
|
32
33
|
* - editable: 'create-only' and viewing existing record
|
|
33
34
|
*
|
|
34
|
-
* @version 0.0
|
|
35
|
+
* @version 0.1.0
|
|
35
36
|
* @since 0.0.1
|
|
36
37
|
* @author AMBROISE PARK Consulting
|
|
37
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
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,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,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,uBAAuB,GAChC,MAAM,GAAG,YAAY,CA+
|
|
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,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,uFAAuF;AACvF,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,uBAAuB,GAChC,MAAM,GAAG,YAAY,CA+FvB;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{Fragment as h,jsx as n,jsxs as p}from"react/jsx-runtime";import{Text as d,Stack as x}from"@donotdev/components";import{handleError as c,getI18nInstance as u}from"@donotdev/core";import{getDisplayFormatter as S}from"../fieldTypeRegistry";import{translateFieldLabel as F}from"../forms/utils";function b(e,r,l,t){t&&!t.locale?t.locale=u()?.language:t||(t={locale:u()?.language});const a=t?.compact??!1,s=t?.asString??!1,f=r.options?.displayValue;if(f&&t?.item){const i=f(e,t.item,l);return i===null?s?"":n(h,{}):i}if(e==null||e==="")return s?"\u2014":a?n("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):n(d,{variant:"muted",children:"\u2014"});const o=S(r.type),m=r.options?.displayKey;if(m){let i=String(e);if(o)try{const y=o(e,r,l,t);i=typeof y=="string"?y:String(e)}catch{}const g=(Array.isArray(m)?m:[m]).map(y=>y.replace("{{value}}",i));return l(g,{value:i})}if(o)try{return o(e,r,l,t)}catch(i){return c(i,{userMessage:`Error formatting field "${r.label||r.name}"`,context:{fieldType:r.type,fieldName:r.label||"unknown",operation:"display_format"},severity:"warning"}),s?String(e):a?n("span",{style:{color:"var(--muted-foreground)"},children:String(e)}):n(d,{variant:"muted",children:String(e)})}return c(new Error(`Display formatter not registered for field type: ${r.type}`),{userMessage:`Field type "${r.type}" is missing display formatter`,context:{fieldType:r.type,fieldName:r.label||"unknown",operation:"display_format",fix:"Add displayFormatter to registerBuiltinFieldType() in registerBuiltinFieldTypes.tsx"},severity:"warning"}),s?String(e):a?n("span",{style:{color:"var(--muted-foreground)"},children:String(e)}):n(d,{variant:"muted",children:String(e)})}function w({name:e,config:r,value:l,t}){const a=b(l,r,t,{compact:!1}),s=F(e,r,t);return p(x,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[p(d,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[s,":"]}),n("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof a=="string"?n(d,{children:a}):a})]})}var V=w;export{w as DisplayFieldRenderer,V as default,b as formatValue};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview DisplayThumbnail component
|
|
3
|
-
* @description Renders the thumbnail of the first picture (pictures[0]) for list cards and list views.
|
|
4
|
-
* Normalizes string (backend-optimized thumbUrl), single Picture, or Picture[].
|
|
5
|
-
*
|
|
6
|
-
* @version 0.0.1
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
* @author AMBROISE PARK Consulting
|
|
9
|
-
*/
|
|
10
1
|
import type { Picture } from '@donotdev/core';
|
|
2
|
+
/** Props for {@link DisplayThumbnail}, renders the first picture thumbnail for list/card views. */
|
|
11
3
|
export interface DisplayThumbnailProps {
|
|
12
4
|
/** Picture(s) from item — string (optimized thumbUrl), single Picture, or Picture[] */
|
|
13
5
|
pictures: Picture[] | Picture | string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayThumbnail.d.ts","sourceRoot":"","sources":["../../src/components/DisplayThumbnail.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DisplayThumbnail.d.ts","sourceRoot":"","sources":["../../src/components/DisplayThumbnail.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,mGAAmG;AACnG,MAAM,WAAW,qBAAqB;IACpC,uFAAuF;IACvF,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9C,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAmBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,GAAQ,EACR,WAAoB,EACpB,SAAS,EACT,KAAK,GACN,EAAE,qBAAqB,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CA8BnD;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as o}from"react/jsx-runtime";import{handleImageError as a}from"@donotdev/components";function u(r){if(r==null)return null;if(typeof r=="string")return r||null;const l=Array.isArray(r)&&r.length>0?r[0]:r;if(!l||typeof l!="object")return null;const t=l.thumbUrl??l.fullUrl;return typeof t=="string"?t:null}function s({pictures:r,alt:l="",aspectRatio:t="16/9",className:e,style:i}){const n=u(r);return n?o("div",{className:e,style:{width:"100%",aspectRatio:t,borderRadius:"var(--radius-md)",overflow:"hidden",backgroundColor:"var(--muted)",position:"relative",...i},children:o("img",{src:n,alt:l,loading:"lazy",onError:a,style:{width:"100%",height:"100%",objectFit:"cover"}})}):null}var m=s;export{s as DisplayThumbnail,m as default};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GridCols } from '@donotdev/components';
|
|
2
2
|
import type { Entity } from '@donotdev/core';
|
|
3
3
|
export { matchesFilter } from '../utils/matchesFilter';
|
|
4
|
+
/** Props for {@link EntityFilters}, auto-generates filter UI based on entity field types. */
|
|
4
5
|
export interface EntityFiltersProps<T extends Record<string, any> & {
|
|
5
6
|
id: string;
|
|
6
7
|
} = Record<string, any> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAqDA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAc7C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,WAAW,kBAAkB,CACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ;IAED,4BAA4B;IAC5B,MAAM,EAAE,MAAM,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