@umituz/react-native-ai-fal-provider 2.0.14 → 2.0.15
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 +1 -1
- package/src/domain/entities/error.types.ts +2 -0
- package/src/domain/types/provider.types.ts +1 -0
- package/src/exports/infrastructure.ts +0 -3
- package/src/exports/presentation.ts +0 -9
- package/src/index.ts +0 -3
- package/src/infrastructure/services/fal-feature-models.ts +3 -1
- package/src/infrastructure/services/fal-provider-subscription.ts +35 -13
- package/src/infrastructure/services/fal-provider.ts +6 -0
- package/src/infrastructure/services/fal-queue-operations.ts +30 -1
- package/src/infrastructure/services/fal-status-mapper.ts +2 -0
- package/src/infrastructure/services/request-store.ts +30 -2
- package/src/infrastructure/utils/cost-tracker.ts +34 -8
- package/src/infrastructure/utils/error-mapper.ts +17 -3
- package/src/infrastructure/utils/image-feature-builders.util.ts +10 -5
- package/src/infrastructure/utils/index.ts +7 -6
- package/src/infrastructure/utils/input-validator.util.ts +92 -0
- package/src/infrastructure/utils/type-guards.util.ts +7 -3
- package/src/infrastructure/utils/video-feature-builders.util.ts +6 -3
- package/src/infrastructure/validators/nsfw-validator.ts +62 -4
- package/src/presentation/hooks/index.ts +3 -21
- package/src/presentation/hooks/use-fal-generation.ts +5 -4
- package/src/domain/constants/default-models.constants.README.md +0 -378
- package/src/domain/constants/models/image-to-video.README.md +0 -266
- package/src/domain/constants/models/index.README.md +0 -269
- package/src/domain/constants/models/text-to-image.README.md +0 -237
- package/src/domain/constants/models/text-to-text.README.md +0 -249
- package/src/domain/constants/models/text-to-video.README.md +0 -259
- package/src/domain/constants/models/text-to-voice.README.md +0 -264
- package/src/domain/entities/error.types.README.md +0 -292
- package/src/domain/entities/fal.types.README.md +0 -460
- package/src/domain/types/index.README.md +0 -229
- package/src/domain/types/model-selection.types.README.md +0 -311
- package/src/exports/registry.ts +0 -39
- package/src/index.README.md +0 -420
- package/src/infrastructure/builders/image-feature-builder.README.md +0 -435
- package/src/infrastructure/builders/index.ts +0 -7
- package/src/infrastructure/services/fal-models-service.README.md +0 -293
- package/src/infrastructure/services/fal-provider-subscription.README.md +0 -257
- package/src/infrastructure/services/fal-provider.README.md +0 -474
- package/src/infrastructure/services/fal-status-mapper.README.md +0 -246
- package/src/infrastructure/services/nsfw-content-error.README.md +0 -215
- package/src/infrastructure/utils/base-builders.util.README.md +0 -313
- package/src/infrastructure/utils/cost-tracker-queries.ts +0 -67
- package/src/infrastructure/utils/error-categorizer.README.md +0 -395
- package/src/infrastructure/utils/error-mapper.README.md +0 -367
- package/src/infrastructure/utils/helpers.util.README.md +0 -395
- package/src/infrastructure/utils/image-feature-builders.util.README.md +0 -411
- package/src/infrastructure/utils/index.README.md +0 -338
- package/src/infrastructure/utils/job-metadata/index.README.md +0 -267
- package/src/infrastructure/utils/job-metadata/job-metadata-format.util.README.md +0 -209
- package/src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.README.md +0 -311
- package/src/infrastructure/utils/job-metadata/job-metadata-queries.util.README.md +0 -332
- package/src/infrastructure/utils/job-metadata/job-metadata.types.README.md +0 -446
- package/src/infrastructure/utils/job-metadata.README.md +0 -268
- package/src/infrastructure/utils/timing-helpers.util.ts +0 -56
- package/src/infrastructure/utils/type-guards.util.README.md +0 -371
- package/src/infrastructure/validators/index.README.md +0 -205
- package/src/infrastructure/validators/nsfw-validator.README.md +0 -309
- package/src/presentation/hooks/index.README.md +0 -224
- package/src/presentation/hooks/use-fal-generation.README.md +0 -398
- package/src/presentation/hooks/use-model-capabilities.ts +0 -99
- package/src/presentation/hooks/use-models.README.md +0 -318
- package/src/registry/global-capabilities.ts +0 -75
- package/src/registry/index.ts +0 -50
- package/src/registry/model-registry.service.ts +0 -93
- package/src/registry/model-registry.types.ts +0 -106
- package/src/registry/models/index.ts +0 -6
- package/src/registry/models/sora-2.config.ts +0 -95
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
# Utils Index
|
|
2
|
-
|
|
3
|
-
Central export point for all utility functions and helpers.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/utils/index.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
The utils module provides a comprehensive collection of utility functions organized into several categories: error handling, input builders, type guards, helpers, and job metadata management.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Provides utilities by:
|
|
14
|
-
- Centralizing utility exports
|
|
15
|
-
- Organizing functions by category
|
|
16
|
-
- Enabling easy imports
|
|
17
|
-
- Maintaining consistency
|
|
18
|
-
- Facilitating code reuse
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import {
|
|
24
|
-
categorizeFalError,
|
|
25
|
-
mapFalError,
|
|
26
|
-
isFalErrorRetryable,
|
|
27
|
-
buildUpscaleInput,
|
|
28
|
-
isValidBase64Image,
|
|
29
|
-
formatImageDataUri,
|
|
30
|
-
createJobMetadata,
|
|
31
|
-
isJobCompleted
|
|
32
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Export Categories
|
|
36
|
-
|
|
37
|
-
### Error Handling
|
|
38
|
-
|
|
39
|
-
Utilities for categorizing, mapping, and handling errors.
|
|
40
|
-
|
|
41
|
-
**Path:** `src/infrastructure/utils/error-categorizer.ts`, `src/infrastructure/utils/error-mapper.ts`
|
|
42
|
-
|
|
43
|
-
**Functions:**
|
|
44
|
-
- `categorizeFalError` - Categorizes errors by type
|
|
45
|
-
- `falErrorMapper` - Maps errors to user-friendly messages
|
|
46
|
-
- `mapFalError` - Converts FAL errors to standard format
|
|
47
|
-
- `isFalErrorRetryable` - Determines if an error is retryable
|
|
48
|
-
|
|
49
|
-
### Input Builders
|
|
50
|
-
|
|
51
|
-
Functions for constructing API-compatible input objects.
|
|
52
|
-
|
|
53
|
-
**Path:** `src/infrastructure/utils/image-feature-builders.util.ts`, `src/infrastructure/utils/video-feature-builders.util.ts`, `src/infrastructure/utils/base-builders.util.ts`
|
|
54
|
-
|
|
55
|
-
**Functions:**
|
|
56
|
-
- `buildSingleImageInput` - Build input with one image
|
|
57
|
-
- `buildDualImageInput` - Build input with two images
|
|
58
|
-
- `buildUpscaleInput` - Build upscale operation input
|
|
59
|
-
- `buildPhotoRestoreInput` - Build photo restore input
|
|
60
|
-
- `buildVideoFromImageInput` - Build video generation input
|
|
61
|
-
- `buildFaceSwapInput` - Build face swap input
|
|
62
|
-
- `buildImageToImageInput` - Build image-to-image input
|
|
63
|
-
- `buildRemoveBackgroundInput` - Build background removal input
|
|
64
|
-
- `buildRemoveObjectInput` - Build object removal input
|
|
65
|
-
- `buildReplaceBackgroundInput` - Build background replacement input
|
|
66
|
-
- `buildHDTouchUpInput` - Build HD enhancement input
|
|
67
|
-
|
|
68
|
-
### Type Guards
|
|
69
|
-
|
|
70
|
-
Runtime type validation and checking utilities.
|
|
71
|
-
|
|
72
|
-
**Path:** `src/infrastructure/utils/type-guards.util.ts`
|
|
73
|
-
|
|
74
|
-
**Functions:**
|
|
75
|
-
- `isFalModelType` - Check if value is a valid FAL model type
|
|
76
|
-
- `isModelType` - Check if value is a valid model type
|
|
77
|
-
- `isFalErrorType` - Check if value is a valid FAL error type
|
|
78
|
-
- `isValidBase64Image` - Validate base64 image data
|
|
79
|
-
- `isValidApiKey` - Validate API key format
|
|
80
|
-
- `isValidModelId` - Validate model ID format
|
|
81
|
-
- `isValidPrompt` - Validate prompt text
|
|
82
|
-
- `isValidTimeout` - Validate timeout value
|
|
83
|
-
- `isValidRetryCount` - Validate retry count
|
|
84
|
-
|
|
85
|
-
### Helpers
|
|
86
|
-
|
|
87
|
-
General-purpose helper functions.
|
|
88
|
-
|
|
89
|
-
**Path:** `src/infrastructure/utils/helpers.util.ts`
|
|
90
|
-
|
|
91
|
-
**Functions:**
|
|
92
|
-
- `formatImageDataUri` - Format data URI for image
|
|
93
|
-
- `extractBase64` - Extract base64 from data URI
|
|
94
|
-
- `getDataUriExtension` - Get file extension from data URI
|
|
95
|
-
- `isImageDataUri` - Check if string is image data URI
|
|
96
|
-
- `calculateTimeoutWithJitter` - Calculate timeout with random jitter
|
|
97
|
-
- `formatCreditCost` - Format credit cost for display
|
|
98
|
-
- `truncatePrompt` - Truncate prompt to max length
|
|
99
|
-
- `sanitizePrompt` - Sanitize prompt text
|
|
100
|
-
- `buildErrorMessage` - Build formatted error message
|
|
101
|
-
- `isDefined` - Type guard for defined values
|
|
102
|
-
- `removeNullish` - Remove null/undefined values
|
|
103
|
-
- `debounce` - Debounce function calls
|
|
104
|
-
- `throttle` - Throttle function calls
|
|
105
|
-
|
|
106
|
-
### Job Metadata
|
|
107
|
-
|
|
108
|
-
Job lifecycle and metadata management functions.
|
|
109
|
-
|
|
110
|
-
**Path:** `src/infrastructure/utils/job-metadata/index.ts`
|
|
111
|
-
|
|
112
|
-
**Types:**
|
|
113
|
-
- `FalJobMetadata` - Job metadata interface
|
|
114
|
-
|
|
115
|
-
**Functions:**
|
|
116
|
-
- `createJobMetadata` - Create new job metadata
|
|
117
|
-
- `updateJobMetadata` - Update existing job metadata
|
|
118
|
-
- `isJobCompleted` - Check if job is completed
|
|
119
|
-
- `isJobRunning` - Check if job is running
|
|
120
|
-
- `isJobStale` - Check if job is stale
|
|
121
|
-
- `getJobDuration` - Get job duration in milliseconds
|
|
122
|
-
- `formatJobDuration` - Format duration for display
|
|
123
|
-
- `calculateJobProgress` - Calculate job progress percentage
|
|
124
|
-
- `serializeJobMetadata` - Serialize job to JSON
|
|
125
|
-
- `deserializeJobMetadata` - Deserialize JSON to job
|
|
126
|
-
- `filterValidJobs` - Filter valid jobs
|
|
127
|
-
- `sortJobsByCreation` - Sort jobs by creation time
|
|
128
|
-
- `getActiveJobs` - Get active jobs
|
|
129
|
-
- `getCompletedJobs` - Get completed jobs
|
|
130
|
-
|
|
131
|
-
## Usage Guidelines
|
|
132
|
-
|
|
133
|
-
### For Error Handling
|
|
134
|
-
|
|
135
|
-
**Error Pattern:**
|
|
136
|
-
1. Catch errors from API calls
|
|
137
|
-
2. Categorize error with categorizeFalError
|
|
138
|
-
3. Map error with mapFalError
|
|
139
|
-
4. Check retryability with isFalErrorRetryable
|
|
140
|
-
5. Display appropriate message
|
|
141
|
-
|
|
142
|
-
**Best Practices:**
|
|
143
|
-
- Always validate error types
|
|
144
|
-
- Show user-friendly messages
|
|
145
|
-
- Check retryability before retry
|
|
146
|
-
- Log technical details
|
|
147
|
-
- Handle NSFW content errors
|
|
148
|
-
|
|
149
|
-
### For Input Building
|
|
150
|
-
|
|
151
|
-
**Builder Pattern:**
|
|
152
|
-
1. Import appropriate builder function
|
|
153
|
-
2. Validate inputs (images, parameters)
|
|
154
|
-
3. Build input with correct options
|
|
155
|
-
4. Use result with provider
|
|
156
|
-
5. Handle errors
|
|
157
|
-
|
|
158
|
-
**Best Practices:**
|
|
159
|
-
- Validate all inputs before building
|
|
160
|
-
- Use correct builder for feature
|
|
161
|
-
- Set appropriate option values
|
|
162
|
-
- Handle required parameters
|
|
163
|
-
- Reference feature documentation
|
|
164
|
-
|
|
165
|
-
### For Validation
|
|
166
|
-
|
|
167
|
-
**Validation Pattern:**
|
|
168
|
-
1. Use type guards for runtime checks
|
|
169
|
-
2. Validate API keys, images, prompts
|
|
170
|
-
3. Check parameter constraints
|
|
171
|
-
4. Provide helpful error messages
|
|
172
|
-
5. Fail fast on invalid input
|
|
173
|
-
|
|
174
|
-
**Best Practices:**
|
|
175
|
-
- Validate all external inputs
|
|
176
|
-
- Use specific validation functions
|
|
177
|
-
- Check formats and ranges
|
|
178
|
-
- Provide clear error messages
|
|
179
|
-
- Prevent invalid API calls
|
|
180
|
-
|
|
181
|
-
### For Job Management
|
|
182
|
-
|
|
183
|
-
**Job Pattern:**
|
|
184
|
-
1. Create job metadata with createJobMetadata
|
|
185
|
-
2. Save to storage
|
|
186
|
-
3. Update job status as it progresses
|
|
187
|
-
4. Check completion with isJobCompleted
|
|
188
|
-
5. Calculate duration and progress
|
|
189
|
-
|
|
190
|
-
**Best Practices:**
|
|
191
|
-
- Always save job updates
|
|
192
|
-
- Track status changes
|
|
193
|
-
- Calculate durations and progress
|
|
194
|
-
- Clean up old jobs
|
|
195
|
-
- Handle missing jobs
|
|
196
|
-
|
|
197
|
-
## Best Practices
|
|
198
|
-
|
|
199
|
-
### 1. Validate Inputs
|
|
200
|
-
|
|
201
|
-
Check all inputs before use:
|
|
202
|
-
- Use type guards for validation
|
|
203
|
-
- Check API key format
|
|
204
|
-
- Validate image data
|
|
205
|
-
- Verify prompt text
|
|
206
|
-
- Check model IDs
|
|
207
|
-
|
|
208
|
-
### 2. Handle Errors Properly
|
|
209
|
-
|
|
210
|
-
Process errors correctly:
|
|
211
|
-
- Categorize errors by type
|
|
212
|
-
- Map to user-friendly messages
|
|
213
|
-
- Check retryability
|
|
214
|
-
- Display appropriate messages
|
|
215
|
-
- Log technical details
|
|
216
|
-
|
|
217
|
-
### 3. Build Inputs Correctly
|
|
218
|
-
|
|
219
|
-
Construct valid inputs:
|
|
220
|
-
- Use appropriate builder functions
|
|
221
|
-
- Set correct options
|
|
222
|
-
- Handle required parameters
|
|
223
|
-
- Validate before building
|
|
224
|
-
- Test with provider
|
|
225
|
-
|
|
226
|
-
### 4. Track Jobs
|
|
227
|
-
|
|
228
|
-
Manage job lifecycle:
|
|
229
|
-
- Create metadata for all jobs
|
|
230
|
-
- Update status as jobs progress
|
|
231
|
-
- Calculate durations and progress
|
|
232
|
-
- Clean up old jobs
|
|
233
|
-
- Query job status
|
|
234
|
-
|
|
235
|
-
### 5. Clean Up Resources
|
|
236
|
-
|
|
237
|
-
Manage resource lifecycle:
|
|
238
|
-
- Clean up old job metadata
|
|
239
|
-
- Release references
|
|
240
|
-
- Prevent memory leaks
|
|
241
|
-
- Handle edge cases
|
|
242
|
-
- Schedule cleanup
|
|
243
|
-
|
|
244
|
-
## For AI Agents
|
|
245
|
-
|
|
246
|
-
### When Using Utilities
|
|
247
|
-
|
|
248
|
-
**DO:**
|
|
249
|
-
- Import from package root
|
|
250
|
-
- Validate inputs before use
|
|
251
|
-
- Handle errors appropriately
|
|
252
|
-
- Track job lifecycle
|
|
253
|
-
- Clean up resources
|
|
254
|
-
- Use specific validators
|
|
255
|
-
- Follow best practices
|
|
256
|
-
|
|
257
|
-
**DON'T:**
|
|
258
|
-
- Import from internal paths
|
|
259
|
-
- Skip input validation
|
|
260
|
-
- Ignore error handling
|
|
261
|
-
- Forget job tracking
|
|
262
|
-
- Leave resources allocated
|
|
263
|
-
- Use generic validators
|
|
264
|
-
- Create utilities
|
|
265
|
-
|
|
266
|
-
### When Validating Inputs
|
|
267
|
-
|
|
268
|
-
**DO:**
|
|
269
|
-
- Use specific validation functions
|
|
270
|
-
- Check all external inputs
|
|
271
|
-
- Validate format and ranges
|
|
272
|
-
- Provide clear error messages
|
|
273
|
-
- Fail fast on invalid input
|
|
274
|
-
- Use type guards
|
|
275
|
-
|
|
276
|
-
**DON'T:**
|
|
277
|
-
- Skip validation
|
|
278
|
-
- Accept invalid inputs
|
|
279
|
-
- Provide vague errors
|
|
280
|
-
- Continue with bad data
|
|
281
|
-
- Create security issues
|
|
282
|
-
- Assume valid inputs
|
|
283
|
-
|
|
284
|
-
### When Managing Jobs
|
|
285
|
-
|
|
286
|
-
**DO:**
|
|
287
|
-
- Create job metadata
|
|
288
|
-
- Update job status
|
|
289
|
-
- Track progress
|
|
290
|
-
- Calculate durations
|
|
291
|
-
- Clean up old jobs
|
|
292
|
-
- Handle errors
|
|
293
|
-
|
|
294
|
-
**DON'T:**
|
|
295
|
-
- Skip job tracking
|
|
296
|
-
- Forget status updates
|
|
297
|
-
- Lose job information
|
|
298
|
-
- Create stale data
|
|
299
|
-
- Ignore cleanup
|
|
300
|
-
- Handle jobs poorly
|
|
301
|
-
|
|
302
|
-
## Implementation Notes
|
|
303
|
-
|
|
304
|
-
**Location:** `src/infrastructure/utils/index.ts`
|
|
305
|
-
|
|
306
|
-
**Dependencies:**
|
|
307
|
-
- Re-exports from all util modules
|
|
308
|
-
- No external dependencies (except React Native utilities)
|
|
309
|
-
|
|
310
|
-
**Utility Categories:**
|
|
311
|
-
- Error handling utilities
|
|
312
|
-
- Input builder utilities
|
|
313
|
-
- Type guard utilities
|
|
314
|
-
- Helper utilities
|
|
315
|
-
- Job metadata utilities
|
|
316
|
-
|
|
317
|
-
**Import:**
|
|
318
|
-
```typescript
|
|
319
|
-
import {
|
|
320
|
-
categorizeFalError,
|
|
321
|
-
mapFalError,
|
|
322
|
-
isFalErrorRetryable,
|
|
323
|
-
buildUpscaleInput,
|
|
324
|
-
isValidBase64Image,
|
|
325
|
-
formatImageDataUri,
|
|
326
|
-
createJobMetadata,
|
|
327
|
-
isJobCompleted
|
|
328
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
**Related:**
|
|
332
|
-
- Error categorizer: `src/infrastructure/utils/error-categorizer.ts`
|
|
333
|
-
- Error mapper: `src/infrastructure/utils/error-mapper.ts`
|
|
334
|
-
- Image builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
335
|
-
- Video builders: `src/infrastructure/utils/video-feature-builders.util.ts`
|
|
336
|
-
- Type guards: `src/infrastructure/utils/type-guards.util.ts`
|
|
337
|
-
- Helpers: `src/infrastructure/utils/helpers.util.ts`
|
|
338
|
-
- Job metadata: `src/infrastructure/utils/job-metadata/`
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
# Job Metadata Utilities
|
|
2
|
-
|
|
3
|
-
Comprehensive job lifecycle management and metadata tracking utilities.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/utils/job-metadata/index.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
The job metadata module provides a complete toolkit for creating, updating, querying, and managing FAL AI generation jobs throughout their lifecycle. This enables robust job tracking, persistence, and monitoring capabilities.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Provides job management by:
|
|
14
|
-
- Creating job metadata
|
|
15
|
-
- Updating job status
|
|
16
|
-
- Tracking job lifecycle
|
|
17
|
-
- Calculating durations and progress
|
|
18
|
-
- Querying job states
|
|
19
|
-
- Serializing/deserializing jobs
|
|
20
|
-
|
|
21
|
-
## Import
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import {
|
|
25
|
-
createJobMetadata,
|
|
26
|
-
updateJobMetadata,
|
|
27
|
-
isJobCompleted,
|
|
28
|
-
isJobRunning,
|
|
29
|
-
getJobDuration,
|
|
30
|
-
formatJobDuration,
|
|
31
|
-
calculateJobProgress
|
|
32
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Export Categories
|
|
36
|
-
|
|
37
|
-
### Types
|
|
38
|
-
|
|
39
|
-
**FalJobMetadata** - Job metadata interface
|
|
40
|
-
**Path:** `src/infrastructure/utils/job-metadata/job-metadata.types.ts`
|
|
41
|
-
|
|
42
|
-
### Lifecycle Management
|
|
43
|
-
|
|
44
|
-
**Functions:**
|
|
45
|
-
- `createJobMetadata` - Create new job metadata
|
|
46
|
-
- `updateJobMetadata` - Update existing job metadata
|
|
47
|
-
- `isJobCompleted` - Check if job is completed
|
|
48
|
-
- `isJobRunning` - Check if job is running
|
|
49
|
-
- `isJobStale` - Check if job is stale
|
|
50
|
-
|
|
51
|
-
**Path:** `src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.ts`
|
|
52
|
-
|
|
53
|
-
### Formatting & Calculation
|
|
54
|
-
|
|
55
|
-
**Functions:**
|
|
56
|
-
- `getJobDuration` - Get job duration in milliseconds
|
|
57
|
-
- `formatJobDuration` - Format duration for display
|
|
58
|
-
- `calculateJobProgress` - Calculate job progress percentage
|
|
59
|
-
|
|
60
|
-
**Path:** `src/infrastructure/utils/job-metadata/job-metadata-format.util.ts`
|
|
61
|
-
|
|
62
|
-
### Queries & Serialization
|
|
63
|
-
|
|
64
|
-
**Functions:**
|
|
65
|
-
- `serializeJobMetadata` - Serialize job to JSON
|
|
66
|
-
- `deserializeJobMetadata` - Deserialize JSON to job
|
|
67
|
-
- `filterValidJobs` - Filter valid jobs
|
|
68
|
-
- `sortJobsByCreation` - Sort jobs by creation time
|
|
69
|
-
- `getActiveJobs` - Get active (running/queued) jobs
|
|
70
|
-
- `getCompletedJobs` - Get completed jobs
|
|
71
|
-
|
|
72
|
-
**Path:** `src/infrastructure/utils/job-metadata/job-metadata-queries.util.ts`
|
|
73
|
-
|
|
74
|
-
## Usage Guidelines
|
|
75
|
-
|
|
76
|
-
### For Job Creation
|
|
77
|
-
|
|
78
|
-
**Creation Pattern:**
|
|
79
|
-
1. Call createJobMetadata with model and input
|
|
80
|
-
2. Receive FalJobMetadata object
|
|
81
|
-
3. Save to storage
|
|
82
|
-
4. Track throughout lifecycle
|
|
83
|
-
5. Update as status changes
|
|
84
|
-
|
|
85
|
-
**Best Practices:**
|
|
86
|
-
- Create jobs before API calls
|
|
87
|
-
- Save immediately to storage
|
|
88
|
-
- Track all status changes
|
|
89
|
-
- Update timestamps appropriately
|
|
90
|
-
- Calculate durations on completion
|
|
91
|
-
|
|
92
|
-
### For Status Tracking
|
|
93
|
-
|
|
94
|
-
**Tracking Pattern:**
|
|
95
|
-
1. Create job with initial status
|
|
96
|
-
2. Update status as job progresses
|
|
97
|
-
3. Check completion with isJobCompleted
|
|
98
|
-
4. Calculate durations and progress
|
|
99
|
-
5. Update final state
|
|
100
|
-
|
|
101
|
-
**Best Practices:**
|
|
102
|
-
- Update status on all changes
|
|
103
|
-
- Save updates to storage
|
|
104
|
-
- Calculate metrics on completion
|
|
105
|
-
- Track timestamps accurately
|
|
106
|
-
- Query job states efficiently
|
|
107
|
-
|
|
108
|
-
### For Job Queries
|
|
109
|
-
|
|
110
|
-
**Query Pattern:**
|
|
111
|
-
1. Load jobs from storage
|
|
112
|
-
2. Filter valid jobs with filterValidJobs
|
|
113
|
-
3. Sort by creation time
|
|
114
|
-
4. Query active/completed jobs
|
|
115
|
-
5. Calculate statistics
|
|
116
|
-
|
|
117
|
-
**Best Practices:**
|
|
118
|
-
- Always filter before querying
|
|
119
|
-
- Sort for consistent ordering
|
|
120
|
-
- Use specific query functions
|
|
121
|
-
- Handle missing jobs gracefully
|
|
122
|
-
- Aggregate job statistics
|
|
123
|
-
|
|
124
|
-
## Best Practices
|
|
125
|
-
|
|
126
|
-
### 1. Always Save Updates
|
|
127
|
-
|
|
128
|
-
Persist job changes:
|
|
129
|
-
- Save after every update
|
|
130
|
-
- Maintain storage consistency
|
|
131
|
-
- Update timestamps correctly
|
|
132
|
-
- Handle save failures
|
|
133
|
-
- Verify persistence
|
|
134
|
-
|
|
135
|
-
### 2. Handle Missing Jobs
|
|
136
|
-
|
|
137
|
-
Manage job lifecycle:
|
|
138
|
-
- Check if job exists before operations
|
|
139
|
-
- Handle missing job errors
|
|
140
|
-
- Provide default values
|
|
141
|
-
- Log missing job warnings
|
|
142
|
-
- Create error handlers
|
|
143
|
-
|
|
144
|
-
### 3. Clean Up Old Jobs
|
|
145
|
-
|
|
146
|
-
Maintain storage efficiency:
|
|
147
|
-
- Remove stale jobs regularly
|
|
148
|
-
- Implement cleanup schedules
|
|
149
|
-
- Check job age before cleanup
|
|
150
|
-
- Log cleanup operations
|
|
151
|
-
- Balance retention vs cleanup
|
|
152
|
-
|
|
153
|
-
### 4. Use Type Guards
|
|
154
|
-
|
|
155
|
-
Ensure type safety:
|
|
156
|
-
- Use isJobCompleted for completion checks
|
|
157
|
-
- Use isJobRunning for active checks
|
|
158
|
-
- Leverage type narrowing
|
|
159
|
-
- Check job states explicitly
|
|
160
|
-
- Enable autocomplete
|
|
161
|
-
|
|
162
|
-
### 5. Calculate Metrics
|
|
163
|
-
|
|
164
|
-
Track job performance:
|
|
165
|
-
- Calculate durations accurately
|
|
166
|
-
- Compute progress percentages
|
|
167
|
-
- Aggregate job statistics
|
|
168
|
-
- Monitor success rates
|
|
169
|
-
- Track model performance
|
|
170
|
-
|
|
171
|
-
## For AI Agents
|
|
172
|
-
|
|
173
|
-
### When Managing Jobs
|
|
174
|
-
|
|
175
|
-
**DO:**
|
|
176
|
-
- Create jobs before operations
|
|
177
|
-
- Update status on changes
|
|
178
|
-
- Save all updates to storage
|
|
179
|
-
- Calculate durations and progress
|
|
180
|
-
- Clean up old jobs regularly
|
|
181
|
-
- Handle missing jobs gracefully
|
|
182
|
-
- Track job lifecycle
|
|
183
|
-
|
|
184
|
-
**DON'T:**
|
|
185
|
-
- Skip job creation
|
|
186
|
-
- Forget status updates
|
|
187
|
-
- Lose job information
|
|
188
|
-
- Create stale data
|
|
189
|
-
- Ignore cleanup
|
|
190
|
-
- Handle jobs inconsistently
|
|
191
|
-
- Create memory leaks
|
|
192
|
-
|
|
193
|
-
### When Tracking Status
|
|
194
|
-
|
|
195
|
-
**DO:**
|
|
196
|
-
- Update status on all changes
|
|
197
|
-
- Check completion status
|
|
198
|
-
- Calculate durations accurately
|
|
199
|
-
- Compute progress percentages
|
|
200
|
-
- Query job states efficiently
|
|
201
|
-
- Use type guard functions
|
|
202
|
-
- Monitor job lifecycle
|
|
203
|
-
|
|
204
|
-
**DON'T:**
|
|
205
|
-
- Skip status updates
|
|
206
|
-
- Forget completion checks
|
|
207
|
-
- Calculate durations incorrectly
|
|
208
|
-
- Compute wrong progress
|
|
209
|
-
- Query jobs inefficiently
|
|
210
|
-
- Use unsafe type operations
|
|
211
|
-
- Create tracking bugs
|
|
212
|
-
|
|
213
|
-
### When Querying Jobs
|
|
214
|
-
|
|
215
|
-
**DO:**
|
|
216
|
-
- Filter jobs before querying
|
|
217
|
-
- Sort jobs by creation
|
|
218
|
-
- Use specific query functions
|
|
219
|
-
- Handle missing jobs
|
|
220
|
-
- Calculate statistics
|
|
221
|
-
- Aggregate job data
|
|
222
|
-
- Handle empty results
|
|
223
|
-
|
|
224
|
-
**DON'T:**
|
|
225
|
-
- Skip filtering
|
|
226
|
-
- Use inconsistent ordering
|
|
227
|
-
- Use generic queries
|
|
228
|
-
- Crash on missing jobs
|
|
229
|
-
- Create inefficient queries
|
|
230
|
-
- Forget aggregation
|
|
231
|
-
- Handle errors poorly
|
|
232
|
-
|
|
233
|
-
## Implementation Notes
|
|
234
|
-
|
|
235
|
-
**Location:** `src/infrastructure/utils/job-metadata/index.ts`
|
|
236
|
-
|
|
237
|
-
**Dependencies:**
|
|
238
|
-
- Job types: `src/infrastructure/utils/job-metadata/job-metadata.types.ts`
|
|
239
|
-
- Lifecycle utilities: `src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.ts`
|
|
240
|
-
- Format utilities: `src/infrastructure/utils/job-metadata/job-metadata-format.util.ts`
|
|
241
|
-
- Query utilities: `src/infrastructure/utils/job-metadata/job-metadata-queries.util.ts`
|
|
242
|
-
|
|
243
|
-
**Function Categories:**
|
|
244
|
-
- Lifecycle management
|
|
245
|
-
- Formatting and calculation
|
|
246
|
-
- Queries and serialization
|
|
247
|
-
- Type definitions
|
|
248
|
-
- Storage operations
|
|
249
|
-
|
|
250
|
-
**Import:**
|
|
251
|
-
```typescript
|
|
252
|
-
import {
|
|
253
|
-
createJobMetadata,
|
|
254
|
-
updateJobMetadata,
|
|
255
|
-
isJobCompleted,
|
|
256
|
-
isJobRunning,
|
|
257
|
-
getJobDuration,
|
|
258
|
-
formatJobDuration,
|
|
259
|
-
calculateJobProgress
|
|
260
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
**Related:**
|
|
264
|
-
- Job types: `src/infrastructure/utils/job-metadata/job-metadata.types.README.md`
|
|
265
|
-
- Job lifecycle: `src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.README.md`
|
|
266
|
-
- Job format: `src/infrastructure/utils/job-metadata/job-metadata-format.util.README.md`
|
|
267
|
-
- Job queries: `src/infrastructure/utils/job-metadata/job-metadata-queries.util.README.md`
|