@umituz/react-native-design-system 2.8.7 → 2.8.9
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/package.json +10 -6
- package/src/device/infrastructure/repositories/LegacyDeviceIdRepository.ts +1 -1
- package/src/device/infrastructure/services/DeviceFeatureService.ts +1 -1
- package/src/exception/infrastructure/services/ExceptionLogger.ts +1 -1
- package/src/exception/infrastructure/storage/ExceptionStore.ts +1 -1
- package/src/exports/filesystem.ts +1 -0
- package/src/exports/media.ts +1 -0
- package/src/exports/storage.ts +1 -0
- package/src/filesystem/domain/constants/FileConstants.ts +20 -0
- package/src/filesystem/domain/entities/File.ts +20 -0
- package/src/filesystem/domain/types/FileTypes.ts +43 -0
- package/src/filesystem/domain/utils/FileUtils.ts +86 -0
- package/src/filesystem/index.ts +23 -0
- package/src/filesystem/infrastructure/services/FileSystemService.ts +45 -0
- package/src/filesystem/infrastructure/services/cache.service.ts +48 -0
- package/src/filesystem/infrastructure/services/directory.service.ts +66 -0
- package/src/filesystem/infrastructure/services/download.constants.ts +6 -0
- package/src/filesystem/infrastructure/services/download.service.ts +74 -0
- package/src/filesystem/infrastructure/services/download.types.ts +7 -0
- package/src/filesystem/infrastructure/services/encoding.service.ts +25 -0
- package/src/filesystem/infrastructure/services/file-info.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-manager.service.ts +81 -0
- package/src/filesystem/infrastructure/services/file-path.service.ts +22 -0
- package/src/filesystem/infrastructure/services/file-reader.service.ts +52 -0
- package/src/filesystem/infrastructure/services/file-writer.service.ts +32 -0
- package/src/filesystem/infrastructure/utils/blob.utils.ts +20 -0
- package/src/image/infrastructure/services/ImageStorageService.ts +1 -1
- package/src/index.ts +14 -0
- package/src/media/domain/entities/CardMultimedia.types.README.md +129 -0
- package/src/media/domain/entities/CardMultimedia.types.ts +105 -0
- package/src/media/domain/entities/Media.README.md +80 -0
- package/src/media/domain/entities/Media.ts +139 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +144 -0
- package/src/media/domain/entities/MultimediaFlashcardTypes.ts +105 -0
- package/src/media/domain/utils/MediaUtils.README.md +178 -0
- package/src/media/domain/utils/MediaUtils.ts +82 -0
- package/src/media/index.ts +70 -0
- package/src/media/index.ts.README.md +191 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.README.md +99 -0
- package/src/media/infrastructure/services/CardMediaGenerationService.ts +101 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.README.md +167 -0
- package/src/media/infrastructure/services/CardMediaOptimizerService.ts +36 -0
- package/src/media/infrastructure/services/CardMediaUploadService.README.md +123 -0
- package/src/media/infrastructure/services/CardMediaUploadService.ts +67 -0
- package/src/media/infrastructure/services/CardMediaValidationService.README.md +134 -0
- package/src/media/infrastructure/services/CardMediaValidationService.ts +81 -0
- package/src/media/infrastructure/services/CardMultimediaService.README.md +176 -0
- package/src/media/infrastructure/services/CardMultimediaService.ts +97 -0
- package/src/media/infrastructure/services/MediaGenerationService.README.md +142 -0
- package/src/media/infrastructure/services/MediaGenerationService.ts +80 -0
- package/src/media/infrastructure/services/MediaOptimizerService.README.md +145 -0
- package/src/media/infrastructure/services/MediaOptimizerService.ts +32 -0
- package/src/media/infrastructure/services/MediaPickerService.README.md +106 -0
- package/src/media/infrastructure/services/MediaPickerService.ts +173 -0
- package/src/media/infrastructure/services/MediaSaveService.README.md +120 -0
- package/src/media/infrastructure/services/MediaSaveService.ts +154 -0
- package/src/media/infrastructure/services/MediaUploadService.README.md +135 -0
- package/src/media/infrastructure/services/MediaUploadService.ts +62 -0
- package/src/media/infrastructure/services/MediaValidationService.README.md +135 -0
- package/src/media/infrastructure/services/MediaValidationService.ts +61 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +142 -0
- package/src/media/infrastructure/services/MultimediaFlashcardService.ts +95 -0
- package/src/media/infrastructure/utils/mediaHelpers.README.md +96 -0
- package/src/media/infrastructure/utils/mediaHelpers.ts +82 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.README.md +129 -0
- package/src/media/infrastructure/utils/mediaPickerMappers.ts +76 -0
- package/src/media/presentation/hooks/card-multimedia.types.README.md +177 -0
- package/src/media/presentation/hooks/card-multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/multimedia.types.README.md +201 -0
- package/src/media/presentation/hooks/multimedia.types.ts +51 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.README.md +164 -0
- package/src/media/presentation/hooks/useCardMediaGeneration.ts +124 -0
- package/src/media/presentation/hooks/useCardMediaUpload.README.md +153 -0
- package/src/media/presentation/hooks/useCardMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useCardMediaValidation.README.md +176 -0
- package/src/media/presentation/hooks/useCardMediaValidation.ts +101 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +158 -0
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +104 -0
- package/src/media/presentation/hooks/useMedia.README.md +94 -0
- package/src/media/presentation/hooks/useMedia.ts +186 -0
- package/src/media/presentation/hooks/useMediaGeneration.README.md +118 -0
- package/src/media/presentation/hooks/useMediaGeneration.ts +101 -0
- package/src/media/presentation/hooks/useMediaUpload.README.md +108 -0
- package/src/media/presentation/hooks/useMediaUpload.ts +86 -0
- package/src/media/presentation/hooks/useMediaValidation.README.md +134 -0
- package/src/media/presentation/hooks/useMediaValidation.ts +93 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +141 -0
- package/src/media/presentation/hooks/useMultimediaFlashcard.ts +103 -0
- package/src/molecules/alerts/AlertStore.ts +1 -1
- package/src/molecules/calendar/infrastructure/storage/EventActions.ts +1 -1
- package/src/molecules/calendar/infrastructure/stores/storageAdapter.ts +1 -1
- package/src/offline/infrastructure/storage/OfflineStore.ts +1 -1
- package/src/onboarding/infrastructure/storage/OnboardingStore.ts +2 -2
- package/src/onboarding/infrastructure/storage/__tests__/OnboardingStore.test.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/answerActions.ts +1 -1
- package/src/onboarding/infrastructure/storage/actions/storageHelpers.ts +1 -1
- package/src/storage/README.md +185 -0
- package/src/storage/__tests__/integration.test.ts +391 -0
- package/src/storage/__tests__/mocks/asyncStorage.mock.ts +52 -0
- package/src/storage/__tests__/performance.test.tsx +352 -0
- package/src/storage/__tests__/setup.ts +63 -0
- package/src/storage/application/README.md +158 -0
- package/src/storage/application/ports/IStorageRepository.ts +61 -0
- package/src/storage/application/ports/README.md +127 -0
- package/src/storage/cache/README.md +154 -0
- package/src/storage/cache/__tests__/PerformanceAndMemory.test.ts +387 -0
- package/src/storage/cache/__tests__/setup.ts +19 -0
- package/src/storage/cache/domain/Cache.ts +146 -0
- package/src/storage/cache/domain/CacheManager.md +83 -0
- package/src/storage/cache/domain/CacheManager.ts +48 -0
- package/src/storage/cache/domain/CacheStatsTracker.md +169 -0
- package/src/storage/cache/domain/CacheStatsTracker.ts +49 -0
- package/src/storage/cache/domain/CachedValue.md +97 -0
- package/src/storage/cache/domain/ErrorHandler.md +99 -0
- package/src/storage/cache/domain/ErrorHandler.ts +42 -0
- package/src/storage/cache/domain/PatternMatcher.md +122 -0
- package/src/storage/cache/domain/PatternMatcher.ts +30 -0
- package/src/storage/cache/domain/README.md +118 -0
- package/src/storage/cache/domain/__tests__/Cache.test.ts +293 -0
- package/src/storage/cache/domain/__tests__/CacheManager.test.ts +276 -0
- package/src/storage/cache/domain/__tests__/ErrorHandler.test.ts +303 -0
- package/src/storage/cache/domain/__tests__/PatternMatcher.test.ts +261 -0
- package/src/storage/cache/domain/strategies/EvictionStrategy.ts +9 -0
- package/src/storage/cache/domain/strategies/FIFOStrategy.ts +12 -0
- package/src/storage/cache/domain/strategies/LFUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/LRUStrategy.ts +22 -0
- package/src/storage/cache/domain/strategies/README.md +117 -0
- package/src/storage/cache/domain/strategies/TTLStrategy.ts +23 -0
- package/src/storage/cache/domain/strategies/__tests__/EvictionStrategies.test.ts +293 -0
- package/src/storage/cache/domain/types/Cache.ts +28 -0
- package/src/storage/cache/domain/types/README.md +107 -0
- package/src/storage/cache/index.ts +28 -0
- package/src/storage/cache/infrastructure/README.md +126 -0
- package/src/storage/cache/infrastructure/TTLCache.ts +103 -0
- package/src/storage/cache/infrastructure/__tests__/TTLCache.test.ts +303 -0
- package/src/storage/cache/presentation/README.md +123 -0
- package/src/storage/cache/presentation/__tests__/ReactHooks.test.ts +514 -0
- package/src/storage/cache/presentation/useCache.ts +76 -0
- package/src/storage/cache/presentation/useCachedValue.ts +88 -0
- package/src/storage/cache/types.d.ts +3 -0
- package/src/storage/domain/README.md +128 -0
- package/src/storage/domain/constants/CacheDefaults.ts +64 -0
- package/src/storage/domain/constants/README.md +105 -0
- package/src/storage/domain/entities/CachedValue.ts +86 -0
- package/src/storage/domain/entities/README.md +109 -0
- package/src/storage/domain/entities/StorageResult.ts +75 -0
- package/src/storage/domain/entities/__tests__/CachedValue.test.ts +149 -0
- package/src/storage/domain/entities/__tests__/StorageResult.test.ts +122 -0
- package/src/storage/domain/errors/README.md +126 -0
- package/src/storage/domain/errors/StorageError.ts +81 -0
- package/src/storage/domain/errors/__tests__/StorageError.test.ts +127 -0
- package/src/storage/domain/factories/README.md +138 -0
- package/src/storage/domain/factories/StoreFactory.ts +59 -0
- package/src/storage/domain/types/README.md +522 -0
- package/src/storage/domain/types/Store.ts +44 -0
- package/src/storage/domain/utils/CacheKeyGenerator.ts +66 -0
- package/src/storage/domain/utils/README.md +127 -0
- package/src/storage/domain/utils/__tests__/devUtils.test.ts +97 -0
- package/src/storage/domain/utils/devUtils.ts +37 -0
- package/src/storage/domain/value-objects/README.md +120 -0
- package/src/storage/domain/value-objects/StorageKey.ts +60 -0
- package/src/storage/index.ts +175 -0
- package/src/storage/infrastructure/README.md +165 -0
- package/src/storage/infrastructure/adapters/README.md +175 -0
- package/src/storage/infrastructure/adapters/StorageService.md +103 -0
- package/src/storage/infrastructure/adapters/StorageService.ts +49 -0
- package/src/storage/infrastructure/repositories/AsyncStorageRepository.ts +98 -0
- package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +100 -0
- package/src/storage/infrastructure/repositories/BatchStorageOperations.ts +42 -0
- package/src/storage/infrastructure/repositories/README.md +121 -0
- package/src/storage/infrastructure/repositories/StringStorageOperations.ts +44 -0
- package/src/storage/infrastructure/repositories/__tests__/AsyncStorageRepository.test.ts +170 -0
- package/src/storage/infrastructure/repositories/__tests__/BaseStorageOperations.test.ts +201 -0
- package/src/storage/presentation/README.md +181 -0
- package/src/storage/presentation/hooks/CacheStorageOperations.ts +94 -0
- package/src/storage/presentation/hooks/README.md +128 -0
- package/src/storage/presentation/hooks/__tests__/usePersistentCache.test.ts +405 -0
- package/src/storage/presentation/hooks/__tests__/useStorage.test.ts +247 -0
- package/src/storage/presentation/hooks/__tests__/useStorageState.test.ts +293 -0
- package/src/storage/presentation/hooks/useCacheState.ts +53 -0
- package/src/storage/presentation/hooks/usePersistentCache.ts +154 -0
- package/src/storage/presentation/hooks/useStorage.ts +102 -0
- package/src/storage/presentation/hooks/useStorageState.ts +71 -0
- package/src/storage/presentation/hooks/useStore.ts +15 -0
- package/src/storage/types/README.md +103 -0
- package/src/theme/infrastructure/globalThemeStore.ts +1 -1
- package/src/theme/infrastructure/storage/ThemeStorage.ts +1 -1
- package/src/theme/infrastructure/stores/themeStore.ts +1 -1
- package/src/utilities/sharing/infrastructure/services/SharingService.ts +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Card Multimedia Hook Types
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
TypeScript return type interfaces for card-specific multimedia hooks in the presentation layer.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`src/presentation/hooks/card-multimedia.types.ts`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Define contracts for card multimedia hook implementations
|
|
11
|
+
- Ensure type safety across card media operations
|
|
12
|
+
- Provide consistent return types for upload, generation, and validation
|
|
13
|
+
- Support card-specific media operations (including image search)
|
|
14
|
+
- Enable proper error handling and loading states
|
|
15
|
+
- Maintain separation between card and general multimedia types
|
|
16
|
+
|
|
17
|
+
## Forbidden
|
|
18
|
+
- **DO NOT** import implementation details or hooks in type files
|
|
19
|
+
- **DO NOT** mix CardMediaAttachment and MediaAttachment types
|
|
20
|
+
- **DO NOT** add business logic to type definitions
|
|
21
|
+
- **DO NOT** use `any` type for function parameters or returns
|
|
22
|
+
- **DO NOT** create circular dependencies with domain types
|
|
23
|
+
- **DO NOT** export implementation-specific types
|
|
24
|
+
- **DO NOT** modify these types without updating all hook implementations
|
|
25
|
+
|
|
26
|
+
## Rules
|
|
27
|
+
1. All hook returns must include loading state, error state, and operation function
|
|
28
|
+
2. Async operations must return Promise with appropriate type
|
|
29
|
+
3. Error states must be string | null (not Error objects)
|
|
30
|
+
4. Progress/results must be null when not active
|
|
31
|
+
5. Boolean states must clearly indicate operation in progress
|
|
32
|
+
6. All interfaces must be exported and public
|
|
33
|
+
7. Type names must follow Use*Result pattern
|
|
34
|
+
8. Functions must accept domain types, not external types
|
|
35
|
+
9. Optional parameters must be clearly marked
|
|
36
|
+
10. Return types must match hook implementations exactly
|
|
37
|
+
|
|
38
|
+
## AI Agent Guidelines
|
|
39
|
+
|
|
40
|
+
When working with card multimedia hook types:
|
|
41
|
+
|
|
42
|
+
1. **Type Imports**: Always import types from this file for card multimedia hooks
|
|
43
|
+
2. **Hook Implementation**: Implement hooks that return these exact interfaces
|
|
44
|
+
3. **Card vs General**: Use Card* types for card-specific operations, Media* for general
|
|
45
|
+
4. **Error Handling**: Always check error state before using results
|
|
46
|
+
5. **Loading States**: Respect loading states to prevent race conditions
|
|
47
|
+
6. **Progress Tracking**: Use progress objects for upload operations
|
|
48
|
+
7. **Type Safety**: Use these types for all card multimedia hook return values
|
|
49
|
+
8. **Testing**: Mock these interfaces when testing card media operations
|
|
50
|
+
|
|
51
|
+
### Hook Return Type Structure
|
|
52
|
+
|
|
53
|
+
All card multimedia hook returns follow this consistent pattern:
|
|
54
|
+
|
|
55
|
+
**Core Components**:
|
|
56
|
+
- **operationFunction**: An async function that accepts parameters and returns a Promise with the result type
|
|
57
|
+
- **isOperationInProgress**: A boolean flag indicating whether the operation is currently running
|
|
58
|
+
- **operationResult**: The result object or null when no operation is active
|
|
59
|
+
- **error**: A string containing error messages or null when no error exists
|
|
60
|
+
|
|
61
|
+
### UseCardMediaUploadResult
|
|
62
|
+
|
|
63
|
+
**Purpose**: Card media upload operations with compression options
|
|
64
|
+
|
|
65
|
+
**Key Features**:
|
|
66
|
+
- Upload function accepts file and compression options
|
|
67
|
+
- Tracks upload progress
|
|
68
|
+
- Returns CardMediaAttachment
|
|
69
|
+
- Handles upload errors
|
|
70
|
+
|
|
71
|
+
**Usage Pattern**:
|
|
72
|
+
1. Check `isUploading` before calling
|
|
73
|
+
2. Call `uploadMedia()` with file and optional compression
|
|
74
|
+
3. Monitor `uploadProgress` during upload
|
|
75
|
+
4. Check `error` state on completion
|
|
76
|
+
5. Use returned CardMediaAttachment on success
|
|
77
|
+
|
|
78
|
+
### UseCardMediaGenerationResult
|
|
79
|
+
|
|
80
|
+
**Purpose**: Card media generation (AI-based generation, image search)
|
|
81
|
+
|
|
82
|
+
**Key Features**:
|
|
83
|
+
- Generation function accepts request parameters
|
|
84
|
+
- Tracks generation status
|
|
85
|
+
- Returns CardMediaGenerationResult
|
|
86
|
+
- Supports multiple generation methods
|
|
87
|
+
|
|
88
|
+
**Usage Pattern**:
|
|
89
|
+
1. Prepare CardMediaGenerationRequest
|
|
90
|
+
2. Check `isGenerating` before calling
|
|
91
|
+
3. Call `generateMedia()` with request
|
|
92
|
+
4. Access `generationResult` when complete
|
|
93
|
+
5. Handle `error` if generation fails
|
|
94
|
+
|
|
95
|
+
### UseCardMediaValidationResult
|
|
96
|
+
|
|
97
|
+
**Purpose**: Card media validation before upload or processing
|
|
98
|
+
|
|
99
|
+
**Key Features**:
|
|
100
|
+
- Validation function accepts file
|
|
101
|
+
- Tracks validation status
|
|
102
|
+
- Returns CardMediaValidation result
|
|
103
|
+
- Provides detailed validation errors
|
|
104
|
+
|
|
105
|
+
**Usage Pattern**:
|
|
106
|
+
1. Check `isValidating` before calling
|
|
107
|
+
2. Call `validateMedia()` with file
|
|
108
|
+
3. Access `validation` result for validity check
|
|
109
|
+
4. Use `validation.errors` array for error details
|
|
110
|
+
5. Check `error` state for validation failures
|
|
111
|
+
|
|
112
|
+
### UseCardMultimediaFlashcardResult
|
|
113
|
+
|
|
114
|
+
**Purpose**: Card flashcard CRUD operations
|
|
115
|
+
|
|
116
|
+
**Key Features**:
|
|
117
|
+
- Create card with multimedia
|
|
118
|
+
- Update card media
|
|
119
|
+
- Delete specific media attachment
|
|
120
|
+
- Tracks processing state
|
|
121
|
+
- Returns CardMultimediaFlashcard
|
|
122
|
+
|
|
123
|
+
**Usage Pattern**:
|
|
124
|
+
1. Create: Call `createCardMultimedia()` with card data
|
|
125
|
+
2. Update: Call `updateCardMedia()` with cardId and media array
|
|
126
|
+
3. Delete: Call `deleteCardMedia()` with attachmentId
|
|
127
|
+
4. Check `isProcessing` before operations
|
|
128
|
+
5. Handle `error` state for failures
|
|
129
|
+
|
|
130
|
+
### Card vs General Multimedia Types
|
|
131
|
+
|
|
132
|
+
| Operation | Card Types | General Types | Key Difference |
|
|
133
|
+
|-----------|-----------|---------------|----------------|
|
|
134
|
+
| Upload | CardMediaAttachment | MediaAttachment | Card-specific metadata |
|
|
135
|
+
| Generation | CardMediaGenerationRequest | MediaGenerationRequest | Cards include image search |
|
|
136
|
+
| Validation | CardMediaValidation | MediaValidation | Card-specific rules |
|
|
137
|
+
| Flashcard | CardMultimediaFlashcard | MultimediaFlashcard | Different entity types |
|
|
138
|
+
|
|
139
|
+
### Type Guards and Validation
|
|
140
|
+
|
|
141
|
+
1. **Upload Hook**: Check for `uploadMedia` function and `isUploading` boolean
|
|
142
|
+
2. **Generation Hook**: Check for `generateMedia` function and `isGenerating` boolean
|
|
143
|
+
3. **Validation Hook**: Check for `validateMedia` function and `isValidating` boolean
|
|
144
|
+
4. **Flashcard Hook**: Check for all three CRUD functions and `isProcessing` boolean
|
|
145
|
+
|
|
146
|
+
### Error Handling Patterns
|
|
147
|
+
|
|
148
|
+
1. Always check if `error !== null` before using results
|
|
149
|
+
2. Errors are strings, not Error objects
|
|
150
|
+
3. Clear error before starting new operation
|
|
151
|
+
4. Show user-friendly error messages
|
|
152
|
+
5. Handle null states for progress/results
|
|
153
|
+
|
|
154
|
+
### Async Operation Patterns
|
|
155
|
+
|
|
156
|
+
1. **Before Call**: Check loading state to prevent concurrent calls
|
|
157
|
+
2. **During Call**: Show loading indicator based on boolean state
|
|
158
|
+
3. **After Call**: Check error state, then use result
|
|
159
|
+
4. **Error Case**: Display error, reset loading state
|
|
160
|
+
5. **Success Case**: Use result, clear error
|
|
161
|
+
|
|
162
|
+
### Related Domain Types
|
|
163
|
+
|
|
164
|
+
These interfaces use domain types:
|
|
165
|
+
- CardMediaAttachment
|
|
166
|
+
- CardMediaGenerationRequest
|
|
167
|
+
- CardMediaGenerationResult
|
|
168
|
+
- CardMediaCompressionOptions
|
|
169
|
+
- CardMediaValidation
|
|
170
|
+
- CardMediaUploadProgress
|
|
171
|
+
- CardMultimediaFlashcard
|
|
172
|
+
|
|
173
|
+
## Dependencies
|
|
174
|
+
|
|
175
|
+
- Domain layer types (Card* entities)
|
|
176
|
+
- Presentation layer hooks
|
|
177
|
+
- No external dependencies
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Card Multimedia Flashcard Hook Types
|
|
3
|
+
* Type definitions for card multimedia hooks
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
CardMediaAttachment,
|
|
8
|
+
CardMediaGenerationRequest,
|
|
9
|
+
CardMediaGenerationResult,
|
|
10
|
+
CardMediaCompressionOptions,
|
|
11
|
+
CardMediaValidation,
|
|
12
|
+
CardMediaUploadProgress,
|
|
13
|
+
CardMultimediaFlashcard,
|
|
14
|
+
} from "../../domain/entities/CardMultimedia.types";
|
|
15
|
+
|
|
16
|
+
export interface UseCardMediaUploadResult {
|
|
17
|
+
uploadMedia: (
|
|
18
|
+
file: any,
|
|
19
|
+
options?: CardMediaCompressionOptions,
|
|
20
|
+
) => Promise<CardMediaAttachment>;
|
|
21
|
+
isUploading: boolean;
|
|
22
|
+
uploadProgress: CardMediaUploadProgress | null;
|
|
23
|
+
error: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface UseCardMediaGenerationResult {
|
|
27
|
+
generateMedia: (
|
|
28
|
+
request: CardMediaGenerationRequest,
|
|
29
|
+
) => Promise<CardMediaGenerationResult>;
|
|
30
|
+
isGenerating: boolean;
|
|
31
|
+
generationResult: CardMediaGenerationResult | null;
|
|
32
|
+
error: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface UseCardMediaValidationResult {
|
|
36
|
+
validateMedia: (file: any) => Promise<CardMediaValidation>;
|
|
37
|
+
isValidating: boolean;
|
|
38
|
+
validation: CardMediaValidation | null;
|
|
39
|
+
error: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UseCardMultimediaFlashcardResult {
|
|
43
|
+
createCardMultimedia: (cardData: any) => Promise<CardMultimediaFlashcard>;
|
|
44
|
+
updateCardMedia: (
|
|
45
|
+
cardId: string,
|
|
46
|
+
media: CardMediaAttachment[],
|
|
47
|
+
) => Promise<CardMultimediaFlashcard>;
|
|
48
|
+
deleteCardMedia: (attachmentId: string) => Promise<void>;
|
|
49
|
+
isProcessing: boolean;
|
|
50
|
+
error: string | null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Multimedia Hook Types
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
TypeScript return type interfaces for general multimedia hooks in the presentation layer.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`src/presentation/hooks/multimedia.types.ts`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Define contracts for general multimedia hook implementations
|
|
11
|
+
- Ensure type safety across media operations
|
|
12
|
+
- Provide consistent return types for upload, generation, and validation
|
|
13
|
+
- Support general-purpose media operations
|
|
14
|
+
- Enable proper error handling and loading states
|
|
15
|
+
- Maintain separation from card-specific multimedia types
|
|
16
|
+
|
|
17
|
+
## Forbidden
|
|
18
|
+
- **DO NOT** import implementation details or hooks in type files
|
|
19
|
+
- **DO NOT** mix MediaAttachment and CardMediaAttachment types
|
|
20
|
+
- **DO NOT** add business logic to type definitions
|
|
21
|
+
- **DO NOT** use `any` type for function parameters or returns
|
|
22
|
+
- **DO NOT** create circular dependencies with domain types
|
|
23
|
+
- **DO NOT** export implementation-specific types
|
|
24
|
+
- **DO NOT** modify these types without updating all hook implementations
|
|
25
|
+
|
|
26
|
+
## Rules
|
|
27
|
+
1. All hook returns must include loading state, error state, and operation function
|
|
28
|
+
2. Async operations must return Promise with appropriate type
|
|
29
|
+
3. Error states must be string | null (not Error objects)
|
|
30
|
+
4. Progress/results must be null when not active
|
|
31
|
+
5. Boolean states must clearly indicate operation in progress
|
|
32
|
+
6. All interfaces must be exported and public
|
|
33
|
+
7. Type names must follow Use*Result pattern
|
|
34
|
+
8. Functions must accept domain types, not external types
|
|
35
|
+
9. Optional parameters must be clearly marked
|
|
36
|
+
10. Return types must match hook implementations exactly
|
|
37
|
+
|
|
38
|
+
## AI Agent Guidelines
|
|
39
|
+
|
|
40
|
+
When working with multimedia hook types:
|
|
41
|
+
|
|
42
|
+
1. **Type Imports**: Always import types from this file for general multimedia hooks
|
|
43
|
+
2. **Hook Implementation**: Implement hooks that return these exact interfaces
|
|
44
|
+
3. **General vs Card**: Use Media* types for general operations, Card* for card-specific
|
|
45
|
+
4. **Error Handling**: Always check error state before using results
|
|
46
|
+
5. **Loading States**: Respect loading states to prevent race conditions
|
|
47
|
+
6. **Progress Tracking**: Use progress objects for upload operations
|
|
48
|
+
7. **Type Safety**: Use these types for all general multimedia hook return values
|
|
49
|
+
8. **Testing**: Mock these interfaces when testing media operations
|
|
50
|
+
|
|
51
|
+
### Hook Return Type Structure
|
|
52
|
+
|
|
53
|
+
All multimedia hook returns follow this consistent pattern:
|
|
54
|
+
|
|
55
|
+
**Core Components**:
|
|
56
|
+
- **operationFunction**: An async function that accepts parameters and returns a Promise with the result type
|
|
57
|
+
- **isOperationInProgress**: A boolean flag indicating whether the operation is currently running
|
|
58
|
+
- **operationResult**: The result object or null when no operation is active
|
|
59
|
+
- **error**: A string containing error messages or null when no error exists
|
|
60
|
+
|
|
61
|
+
### UseMediaUploadResult
|
|
62
|
+
|
|
63
|
+
**Purpose**: General media upload operations with compression options
|
|
64
|
+
|
|
65
|
+
**Key Features**:
|
|
66
|
+
- Upload function accepts file and compression options
|
|
67
|
+
- Tracks upload progress
|
|
68
|
+
- Returns MediaAttachment
|
|
69
|
+
- Handles upload errors
|
|
70
|
+
|
|
71
|
+
**Usage Pattern**:
|
|
72
|
+
1. Check `isUploading` before calling
|
|
73
|
+
2. Call `uploadMedia()` with file and optional compression
|
|
74
|
+
3. Monitor `uploadProgress` during upload
|
|
75
|
+
4. Check `error` state on completion
|
|
76
|
+
5. Use returned MediaAttachment on success
|
|
77
|
+
|
|
78
|
+
### UseMediaGenerationResult
|
|
79
|
+
|
|
80
|
+
**Purpose**: General media generation (AI-based generation without image search)
|
|
81
|
+
|
|
82
|
+
**Key Features**:
|
|
83
|
+
- Generation function accepts request parameters
|
|
84
|
+
- Tracks generation status
|
|
85
|
+
- Returns MediaGenerationResult
|
|
86
|
+
- Supports core generation methods
|
|
87
|
+
|
|
88
|
+
**Usage Pattern**:
|
|
89
|
+
1. Prepare MediaGenerationRequest
|
|
90
|
+
2. Check `isGenerating` before calling
|
|
91
|
+
3. Call `generateMedia()` with request
|
|
92
|
+
4. Access `generationResult` when complete
|
|
93
|
+
5. Handle `error` if generation fails
|
|
94
|
+
|
|
95
|
+
### UseMediaValidationResult
|
|
96
|
+
|
|
97
|
+
**Purpose**: General media validation before upload or processing
|
|
98
|
+
|
|
99
|
+
**Key Features**:
|
|
100
|
+
- Validation function accepts file
|
|
101
|
+
- Tracks validation status
|
|
102
|
+
- Returns MediaValidation result
|
|
103
|
+
- Provides detailed validation errors
|
|
104
|
+
|
|
105
|
+
**Usage Pattern**:
|
|
106
|
+
1. Check `isValidating` before calling
|
|
107
|
+
2. Call `validateMedia()` with file
|
|
108
|
+
3. Access `validation` result for validity check
|
|
109
|
+
4. Use `validation.errors` array for error details
|
|
110
|
+
5. Check `error` state for validation failures
|
|
111
|
+
|
|
112
|
+
### UseMultimediaFlashcardResult
|
|
113
|
+
|
|
114
|
+
**Purpose**: General flashcard CRUD operations
|
|
115
|
+
|
|
116
|
+
**Key Features**:
|
|
117
|
+
- Create flashcard with multimedia
|
|
118
|
+
- Update flashcard media
|
|
119
|
+
- Delete specific media attachment
|
|
120
|
+
- Tracks processing state
|
|
121
|
+
- Returns MultimediaFlashcard
|
|
122
|
+
|
|
123
|
+
**Usage Pattern**:
|
|
124
|
+
1. Create: Call `createMultimediaCard()` with card data
|
|
125
|
+
2. Update: Call `updateMedia()` with cardId and media array
|
|
126
|
+
3. Delete: Call `deleteMedia()` with attachmentId
|
|
127
|
+
4. Check `isProcessing` before operations
|
|
128
|
+
5. Handle `error` state for failures
|
|
129
|
+
|
|
130
|
+
### General vs Card Multimedia Types
|
|
131
|
+
|
|
132
|
+
| Operation | General Types | Card Types | Key Difference |
|
|
133
|
+
|-----------|--------------|------------|----------------|
|
|
134
|
+
| Upload | MediaAttachment | CardMediaAttachment | Different entity structures |
|
|
135
|
+
| Generation | MediaGenerationRequest | CardMediaGenerationRequest | Cards include image search |
|
|
136
|
+
| Validation | MediaValidation | CardMediaValidation | Different validation rules |
|
|
137
|
+
| Flashcard | MultimediaFlashcard | CardMultimediaFlashcard | Different entity types |
|
|
138
|
+
| Features | Core operations | Core + image search | Card has extended features |
|
|
139
|
+
|
|
140
|
+
### When to Use Which Types
|
|
141
|
+
|
|
142
|
+
**Use Media* Types (General)**:
|
|
143
|
+
- Generic media handling
|
|
144
|
+
- Non-card-specific operations
|
|
145
|
+
- Reusable media components
|
|
146
|
+
- General-purpose flashcards
|
|
147
|
+
|
|
148
|
+
**Use Card* Types (Card-Specific)**:
|
|
149
|
+
- Card-specific operations
|
|
150
|
+
- Image search functionality
|
|
151
|
+
- Card entity management
|
|
152
|
+
- Card-specific validation rules
|
|
153
|
+
|
|
154
|
+
### Type Guards and Validation
|
|
155
|
+
|
|
156
|
+
1. **Upload Hook**: Check for `uploadMedia` function and `isUploading` boolean
|
|
157
|
+
2. **Generation Hook**: Check for `generateMedia` function and `isGenerating` boolean
|
|
158
|
+
3. **Validation Hook**: Check for `validateMedia` function and `isValidating` boolean
|
|
159
|
+
4. **Flashcard Hook**: Check for all three CRUD functions and `isProcessing` boolean
|
|
160
|
+
|
|
161
|
+
### Error Handling Patterns
|
|
162
|
+
|
|
163
|
+
1. Always check if `error !== null` before using results
|
|
164
|
+
2. Errors are strings, not Error objects
|
|
165
|
+
3. Clear error before starting new operation
|
|
166
|
+
4. Show user-friendly error messages
|
|
167
|
+
5. Handle null states for progress/results
|
|
168
|
+
|
|
169
|
+
### Async Operation Patterns
|
|
170
|
+
|
|
171
|
+
1. **Before Call**: Check loading state to prevent concurrent calls
|
|
172
|
+
2. **During Call**: Show loading indicator based on boolean state
|
|
173
|
+
3. **After Call**: Check error state, then use result
|
|
174
|
+
4. **Error Case**: Display error, reset loading state
|
|
175
|
+
5. **Success Case**: Use result, clear error
|
|
176
|
+
|
|
177
|
+
### Composable Hooks Pattern
|
|
178
|
+
|
|
179
|
+
Combine multiple hook types for complex workflows:
|
|
180
|
+
|
|
181
|
+
1. **Validate Then Upload**: Use validation result before calling upload
|
|
182
|
+
2. **Generate Then Upload**: Chain generation and upload operations
|
|
183
|
+
3. **Upload Then Create Card**: Use upload result to create flashcard
|
|
184
|
+
4. **Parallel Operations**: Use multiple hooks independently
|
|
185
|
+
|
|
186
|
+
### Related Domain Types
|
|
187
|
+
|
|
188
|
+
These interfaces use domain types:
|
|
189
|
+
- MediaAttachment
|
|
190
|
+
- MediaGenerationRequest
|
|
191
|
+
- MediaGenerationResult
|
|
192
|
+
- MediaCompressionOptions
|
|
193
|
+
- MediaValidation
|
|
194
|
+
- MediaUploadProgress
|
|
195
|
+
- MultimediaFlashcard
|
|
196
|
+
|
|
197
|
+
## Dependencies
|
|
198
|
+
|
|
199
|
+
- Domain layer types (Media* entities)
|
|
200
|
+
- Presentation layer hooks
|
|
201
|
+
- No external dependencies
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multimedia Flashcard Hook Types
|
|
3
|
+
* Type definitions for multimedia hooks
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
MediaAttachment,
|
|
8
|
+
MediaGenerationRequest,
|
|
9
|
+
MediaGenerationResult,
|
|
10
|
+
MediaCompressionOptions,
|
|
11
|
+
MediaValidation,
|
|
12
|
+
MediaUploadProgress,
|
|
13
|
+
MultimediaFlashcard,
|
|
14
|
+
} from "../../domain/entities/MultimediaFlashcardTypes";
|
|
15
|
+
|
|
16
|
+
export interface UseMediaUploadResult {
|
|
17
|
+
uploadMedia: (
|
|
18
|
+
file: any,
|
|
19
|
+
options?: MediaCompressionOptions,
|
|
20
|
+
) => Promise<MediaAttachment>;
|
|
21
|
+
isUploading: boolean;
|
|
22
|
+
uploadProgress: MediaUploadProgress | null;
|
|
23
|
+
error: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface UseMediaGenerationResult {
|
|
27
|
+
generateMedia: (
|
|
28
|
+
request: MediaGenerationRequest,
|
|
29
|
+
) => Promise<MediaGenerationResult>;
|
|
30
|
+
isGenerating: boolean;
|
|
31
|
+
generationResult: MediaGenerationResult | null;
|
|
32
|
+
error: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface UseMediaValidationResult {
|
|
36
|
+
validateMedia: (file: any) => Promise<MediaValidation>;
|
|
37
|
+
isValidating: boolean;
|
|
38
|
+
validation: MediaValidation | null;
|
|
39
|
+
error: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UseMultimediaFlashcardResult {
|
|
43
|
+
createMultimediaCard: (cardData: any) => Promise<MultimediaFlashcard>;
|
|
44
|
+
updateMedia: (
|
|
45
|
+
cardId: string,
|
|
46
|
+
media: MediaAttachment[],
|
|
47
|
+
) => Promise<MultimediaFlashcard>;
|
|
48
|
+
deleteMedia: (attachmentId: string) => Promise<void>;
|
|
49
|
+
isProcessing: boolean;
|
|
50
|
+
error: string | null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# useCardMediaGeneration
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
Card-specific React hook for AI-powered media generation (text-to-image, text-to-audio, image-search) for flashcards.
|
|
5
|
+
|
|
6
|
+
## File Location
|
|
7
|
+
`src/presentation/hooks/useCardMediaGeneration.ts`
|
|
8
|
+
|
|
9
|
+
## Strategy
|
|
10
|
+
- Provide card-specific interface for AI media generation
|
|
11
|
+
- Support text-to-image, text-to-audio, and image-search operations
|
|
12
|
+
- Return CardMediaAttachment with position property
|
|
13
|
+
- Track generation status and metadata
|
|
14
|
+
- Manage credit costs for card media generation
|
|
15
|
+
- Handle generation errors with proper feedback
|
|
16
|
+
- Support card-specific generation options
|
|
17
|
+
|
|
18
|
+
## Forbidden
|
|
19
|
+
- **DO NOT** start generation while previous is in progress
|
|
20
|
+
- **DO NOT** ignore credit costs before generation
|
|
21
|
+
- **DO NOT** mock generation in production without AI API
|
|
22
|
+
- **DO NOT** assume generation will succeed - check result.success
|
|
23
|
+
- **DO NOT** expose API keys or AI implementation details
|
|
24
|
+
- **DO NOT** allow unlimited concurrent generations
|
|
25
|
+
- **DO NOT** bypass timeout handling for long generations
|
|
26
|
+
- **DO NOT** store large results permanently in hook state
|
|
27
|
+
- **DO NOT** use empty or invalid prompts
|
|
28
|
+
- **DO NOT** mix with MediaAttachment (must use CardMediaAttachment)
|
|
29
|
+
|
|
30
|
+
## Rules
|
|
31
|
+
1. Always validate prompt text before generation
|
|
32
|
+
2. Check credit availability before operations
|
|
33
|
+
3. Track processing time for each request
|
|
34
|
+
4. Return CardMediaAttachment with position property
|
|
35
|
+
5. Return unique requestId for tracking
|
|
36
|
+
6. Include creditsUsed in result metadata
|
|
37
|
+
7. Support maxResults for multiple outputs
|
|
38
|
+
8. Clear generation state on new operations
|
|
39
|
+
9. Handle both success and failure gracefully
|
|
40
|
+
10. Support language, voice, speed options for audio
|
|
41
|
+
|
|
42
|
+
## AI Agent Guidelines
|
|
43
|
+
|
|
44
|
+
When working with useCardMediaGeneration hook:
|
|
45
|
+
|
|
46
|
+
1. **Type Specificity**: Use CardMediaAttachment (not MediaAttachment)
|
|
47
|
+
2. **Position Awareness**: Generated media has position property
|
|
48
|
+
3. **Prompt Quality**: Use descriptive prompts for better results
|
|
49
|
+
4. **Credit Tracking**: Monitor credit costs and balance
|
|
50
|
+
5. **Error Handling**: Always check result.success field
|
|
51
|
+
|
|
52
|
+
### Generation Types
|
|
53
|
+
|
|
54
|
+
**Text-to-Image** (type: 'text_to_image')
|
|
55
|
+
- Generates images from text descriptions
|
|
56
|
+
- Credit cost: 5 per generation
|
|
57
|
+
- Default maxResults: 1
|
|
58
|
+
- Returns CardMediaAttachment with position: 'both'
|
|
59
|
+
- Supports style customization
|
|
60
|
+
|
|
61
|
+
**Text-to-Audio** (type: 'text_to_audio')
|
|
62
|
+
- Generates audio from text (TTS)
|
|
63
|
+
- Credit cost: 3 per generation
|
|
64
|
+
- Default duration: 10 seconds
|
|
65
|
+
- Returns CardMediaAttachment with position: 'back'
|
|
66
|
+
- Supports voice, language, speed options
|
|
67
|
+
|
|
68
|
+
**Image Search** (type: 'image_search')
|
|
69
|
+
- Searches for existing images
|
|
70
|
+
- Credit cost: 2 per search
|
|
71
|
+
- Default maxResults: 5
|
|
72
|
+
- Returns CardMediaAttachment with position: 'both'
|
|
73
|
+
- Finds relevant images from database
|
|
74
|
+
|
|
75
|
+
### Generation Workflow
|
|
76
|
+
|
|
77
|
+
1. Validate prompt text quality
|
|
78
|
+
2. Check credit balance
|
|
79
|
+
3. Select generation type
|
|
80
|
+
4. Configure options (maxResults, voice, language, etc.)
|
|
81
|
+
5. Call generateMedia with request
|
|
82
|
+
6. Monitor isGenerating state
|
|
83
|
+
7. Process CardMediaGenerationResult
|
|
84
|
+
8. Handle success or error
|
|
85
|
+
|
|
86
|
+
### Result Structure
|
|
87
|
+
|
|
88
|
+
CardMediaGenerationResult includes:
|
|
89
|
+
- success: Boolean success/failure
|
|
90
|
+
- attachments: Array of CardMediaAttachment (with position)
|
|
91
|
+
- creditsUsed: Credits consumed
|
|
92
|
+
- processingTime: Duration in milliseconds
|
|
93
|
+
- requestId: Unique identifier
|
|
94
|
+
- error: Error message if failed
|
|
95
|
+
|
|
96
|
+
### CardMediaAttachment Features
|
|
97
|
+
|
|
98
|
+
Generated attachments include:
|
|
99
|
+
- id: Unique ID with card_media_ prefix
|
|
100
|
+
- type: CardMediaType (IMAGE, VIDEO, AUDIO)
|
|
101
|
+
- position: CardMediaPosition (front, back, or both)
|
|
102
|
+
- url: Generated media URL
|
|
103
|
+
- filename: Generated filename
|
|
104
|
+
- fileSize: Size in bytes
|
|
105
|
+
- mimeType: MIME type
|
|
106
|
+
- duration: Audio/video duration
|
|
107
|
+
- thumbnailUrl: Thumbnail for visual media
|
|
108
|
+
- isDownloaded: Download status
|
|
109
|
+
- createdAt: ISO timestamp
|
|
110
|
+
|
|
111
|
+
### Generation Options
|
|
112
|
+
|
|
113
|
+
**Image Options:**
|
|
114
|
+
- maxResults: Number of images (default: 1)
|
|
115
|
+
- style: Image style preset
|
|
116
|
+
|
|
117
|
+
**Audio Options:**
|
|
118
|
+
- voice: Voice type (male/female)
|
|
119
|
+
- language: Language code ('tr-TR', 'en-US')
|
|
120
|
+
- speed: Playback speed (default: 1.0)
|
|
121
|
+
|
|
122
|
+
**Image Search Options:**
|
|
123
|
+
- maxResults: Number of results (default: 5)
|
|
124
|
+
|
|
125
|
+
### Integration with Card Creation
|
|
126
|
+
|
|
127
|
+
Typical workflow:
|
|
128
|
+
1. Generate media with useCardMediaGeneration
|
|
129
|
+
2. Receive CardMediaAttachment objects
|
|
130
|
+
3. Use in createCardMultimedia call
|
|
131
|
+
4. Position is automatically assigned by generation type
|
|
132
|
+
5. Complete card with generated media
|
|
133
|
+
|
|
134
|
+
### Credit Costs
|
|
135
|
+
|
|
136
|
+
| Operation | Credits |
|
|
137
|
+
|-----------|---------|
|
|
138
|
+
| Text-to-Image | 5 |
|
|
139
|
+
| Text-to-Audio | 3 |
|
|
140
|
+
| Image Search | 2 |
|
|
141
|
+
|
|
142
|
+
### Error Scenarios
|
|
143
|
+
|
|
144
|
+
- Insufficient credits: Check balance before generation
|
|
145
|
+
- Invalid prompt: Validate text quality
|
|
146
|
+
- API timeout: Implement retry logic
|
|
147
|
+
- Content policy: Filter prompts appropriately
|
|
148
|
+
- Service unavailable: Graceful error handling
|
|
149
|
+
|
|
150
|
+
### Integration Requirements
|
|
151
|
+
|
|
152
|
+
- Configure AI service endpoints
|
|
153
|
+
- Implement authentication for AI APIs
|
|
154
|
+
- Handle rate limiting and quotas
|
|
155
|
+
- Implement retry logic for failures
|
|
156
|
+
- Cache results when appropriate
|
|
157
|
+
- Monitor credit usage
|
|
158
|
+
|
|
159
|
+
## Dependencies
|
|
160
|
+
|
|
161
|
+
- CardMediaGenerationService (infrastructure layer)
|
|
162
|
+
- Domain types: CardMediaGenerationRequest, CardMediaGenerationResult, CardMediaAttachment
|
|
163
|
+
- Credit tracking system
|
|
164
|
+
- AI service APIs (text-to-image, TTS, image search)
|