@umituz/react-native-ai-fal-provider 2.0.11 → 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 +2 -4
- 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/fal-storage.util.ts +3 -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-preprocessor.util.ts +1 -1
- 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,332 +0,0 @@
|
|
|
1
|
-
# Job Metadata Queries
|
|
2
|
-
|
|
3
|
-
Serialization, filtering, sorting, and query operations for job metadata.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/utils/job-metadata/job-metadata-queries.util.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
The job queries module provides utilities for serializing/deserializing job metadata, filtering valid jobs, sorting by creation time, and querying jobs by status.
|
|
10
|
-
|
|
11
|
-
## Functions
|
|
12
|
-
|
|
13
|
-
### serializeJobMetadata
|
|
14
|
-
|
|
15
|
-
Serialize job metadata to JSON string for storage.
|
|
16
|
-
|
|
17
|
-
**Parameters:**
|
|
18
|
-
- `metadata`: Job metadata to serialize
|
|
19
|
-
|
|
20
|
-
**Returns:** `string` - JSON string representation of job metadata
|
|
21
|
-
|
|
22
|
-
**Usage:**
|
|
23
|
-
Use this function when storing job metadata to persistent storage (AsyncStorage, database, file system). Converts job metadata object to JSON string for safe storage.
|
|
24
|
-
|
|
25
|
-
**Related:**
|
|
26
|
-
- Job storage utilities: `src/infrastructure/utils/job-metadata/index.ts`
|
|
27
|
-
|
|
28
|
-
### deserializeJobMetadata
|
|
29
|
-
|
|
30
|
-
Deserialize job metadata from JSON string.
|
|
31
|
-
|
|
32
|
-
**Parameters:**
|
|
33
|
-
- `data`: JSON string to deserialize
|
|
34
|
-
|
|
35
|
-
**Returns:** `FalJobMetadata | null` - Parsed job metadata, or `null` if invalid JSON
|
|
36
|
-
|
|
37
|
-
**Behavior:**
|
|
38
|
-
- Returns `null` if JSON parsing fails
|
|
39
|
-
- Returns parsed `FalJobMetadata` object if successful
|
|
40
|
-
- Handles JSON.parse errors gracefully
|
|
41
|
-
|
|
42
|
-
**Usage:**
|
|
43
|
-
Use this function when loading job metadata from storage. Always check for null return value before using the result.
|
|
44
|
-
|
|
45
|
-
### filterValidJobs
|
|
46
|
-
|
|
47
|
-
Filter out stale jobs from an array.
|
|
48
|
-
|
|
49
|
-
**Parameters:**
|
|
50
|
-
- `jobs`: Array of job metadata to filter
|
|
51
|
-
|
|
52
|
-
**Returns:** `FalJobMetadata[]` - Array of non-stale jobs
|
|
53
|
-
|
|
54
|
-
**Behavior:**
|
|
55
|
-
- Removes jobs older than 60 minutes (default `isJobStale` threshold)
|
|
56
|
-
- Keeps all other jobs regardless of status
|
|
57
|
-
- Creates new array (doesn't modify original)
|
|
58
|
-
|
|
59
|
-
**Usage:**
|
|
60
|
-
Use this function to clean up job lists before display or processing. Removes stale jobs that may be expired or no longer relevant.
|
|
61
|
-
|
|
62
|
-
**Related:**
|
|
63
|
-
- Stale check function: `src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.ts`
|
|
64
|
-
|
|
65
|
-
### sortJobsByCreation
|
|
66
|
-
|
|
67
|
-
Sort jobs by creation time (newest first).
|
|
68
|
-
|
|
69
|
-
**Parameters:**
|
|
70
|
-
- `jobs`: Array of job metadata to sort
|
|
71
|
-
|
|
72
|
-
**Returns:** `FalJobMetadata[]` - New array sorted by creation time (descending)
|
|
73
|
-
|
|
74
|
-
**Behavior:**
|
|
75
|
-
- Creates new array (doesn't modify original)
|
|
76
|
-
- Sorts with newest jobs first
|
|
77
|
-
- Uses `createdAt` timestamp for sorting
|
|
78
|
-
|
|
79
|
-
**Usage:**
|
|
80
|
-
Use this function to display jobs in reverse chronological order. Useful for job lists, dashboards, and history views.
|
|
81
|
-
|
|
82
|
-
### getActiveJobs
|
|
83
|
-
|
|
84
|
-
Get jobs that are actively running or queued.
|
|
85
|
-
|
|
86
|
-
**Parameters:**
|
|
87
|
-
- `jobs`: Array of job metadata to filter
|
|
88
|
-
|
|
89
|
-
**Returns:** `FalJobMetadata[]` - Array of active jobs
|
|
90
|
-
|
|
91
|
-
**Behavior:**
|
|
92
|
-
- Includes jobs with status `IN_QUEUE` or `IN_PROGRESS`
|
|
93
|
-
- Excludes stale jobs (older than 60 minutes)
|
|
94
|
-
- Filters both conditions automatically
|
|
95
|
-
|
|
96
|
-
**Usage:**
|
|
97
|
-
Use this function to get all currently active jobs. Useful for dashboard displays, active job counts, and preventing duplicate submissions.
|
|
98
|
-
|
|
99
|
-
### getCompletedJobs
|
|
100
|
-
|
|
101
|
-
Get jobs that have completed (successfully or failed).
|
|
102
|
-
|
|
103
|
-
**Parameters:**
|
|
104
|
-
- `jobs`: Array of job metadata to filter
|
|
105
|
-
|
|
106
|
-
**Returns:** `FalJobMetadata[]` - Array of completed jobs
|
|
107
|
-
|
|
108
|
-
**Behavior:**
|
|
109
|
-
- Includes jobs with status `COMPLETED` or `FAILED`
|
|
110
|
-
- Includes both successful and failed jobs
|
|
111
|
-
- Doesn't filter by age (includes old completed jobs)
|
|
112
|
-
|
|
113
|
-
**Usage:**
|
|
114
|
-
Use this function to get job history and completed jobs. Useful for analytics, success rate calculations, and job history displays.
|
|
115
|
-
|
|
116
|
-
## Usage Guidelines
|
|
117
|
-
|
|
118
|
-
### For Storage Operations
|
|
119
|
-
|
|
120
|
-
**Saving Jobs:**
|
|
121
|
-
1. Use `serializeJobMetadata()` to convert job to JSON string
|
|
122
|
-
2. Store JSON string in persistent storage
|
|
123
|
-
3. Use consistent key format (e.g., `job:${requestId}`)
|
|
124
|
-
4. Handle storage errors gracefully
|
|
125
|
-
|
|
126
|
-
**Loading Jobs:**
|
|
127
|
-
1. Retrieve JSON string from storage
|
|
128
|
-
2. Use `deserializeJobMetadata()` to convert back to object
|
|
129
|
-
3. Always check for null return value
|
|
130
|
-
4. Handle corrupted data gracefully
|
|
131
|
-
|
|
132
|
-
**Related:**
|
|
133
|
-
- Job storage implementation: `src/infrastructure/utils/job-metadata/index.ts`
|
|
134
|
-
|
|
135
|
-
### For Job Lists
|
|
136
|
-
|
|
137
|
-
**Display Preparation:**
|
|
138
|
-
1. Load all jobs from storage
|
|
139
|
-
2. Use `filterValidJobs()` to remove stale jobs
|
|
140
|
-
3. Use `sortJobsByCreation()` for chronological order
|
|
141
|
-
4. Apply additional filters if needed
|
|
142
|
-
|
|
143
|
-
**Active Job Display:**
|
|
144
|
-
1. Use `getActiveJobs()` to get running jobs
|
|
145
|
-
2. Display in dashboard or job list
|
|
146
|
-
3. Update display on status changes
|
|
147
|
-
4. Show job count to user
|
|
148
|
-
|
|
149
|
-
**Completed Job Display:**
|
|
150
|
-
1. Use `getCompletedJobs()` for job history
|
|
151
|
-
2. Separate successful from failed jobs
|
|
152
|
-
3. Calculate success rates
|
|
153
|
-
4. Show analytics
|
|
154
|
-
|
|
155
|
-
### For Analytics
|
|
156
|
-
|
|
157
|
-
**Job Statistics:**
|
|
158
|
-
1. Filter valid jobs with `filterValidJobs()`
|
|
159
|
-
2. Use `getActiveJobs()` and `getCompletedJobs()` for counts
|
|
160
|
-
3. Calculate success rate from completed jobs
|
|
161
|
-
4. Group by model, status, or time period
|
|
162
|
-
|
|
163
|
-
**Performance Metrics:**
|
|
164
|
-
1. Sort jobs by creation time
|
|
165
|
-
2. Calculate duration for completed jobs
|
|
166
|
-
3. Identify slow or failed jobs
|
|
167
|
-
4. Track patterns over time
|
|
168
|
-
|
|
169
|
-
### For Cleanup Operations
|
|
170
|
-
|
|
171
|
-
**Stale Job Removal:**
|
|
172
|
-
1. Load all jobs from storage
|
|
173
|
-
2. Use `filterValidJobs()` to identify stale jobs
|
|
174
|
-
3. Delete stale jobs from storage
|
|
175
|
-
4. Run periodically (e.g., on app start)
|
|
176
|
-
|
|
177
|
-
**Storage Management:**
|
|
178
|
-
1. Monitor total job count
|
|
179
|
-
2. Remove old completed jobs
|
|
180
|
-
3. Keep recent active jobs
|
|
181
|
-
4. Implement retention policies
|
|
182
|
-
|
|
183
|
-
## Best Practices
|
|
184
|
-
|
|
185
|
-
### 1. Always Handle Deserialization Errors
|
|
186
|
-
|
|
187
|
-
Check for null when deserializing:
|
|
188
|
-
- `deserializeJobMetadata()` returns `null` on failure
|
|
189
|
-
- Always validate return value before using
|
|
190
|
-
- Handle corrupted data gracefully
|
|
191
|
-
- Provide fallback or error message
|
|
192
|
-
|
|
193
|
-
### 2. Validate Before Filtering
|
|
194
|
-
|
|
195
|
-
Validate input arrays before processing:
|
|
196
|
-
- Check if input is actually an array
|
|
197
|
-
- Handle empty arrays
|
|
198
|
-
- Return empty array for invalid input
|
|
199
|
-
- Don't assume valid data structure
|
|
200
|
-
|
|
201
|
-
### 3. Create New Arrays When Sorting
|
|
202
|
-
|
|
203
|
-
Use provided sorting function:
|
|
204
|
-
- `sortJobsByCreation()` creates new array
|
|
205
|
-
- Original array remains unchanged
|
|
206
|
-
- Prevents accidental mutation
|
|
207
|
-
- Maintains data integrity
|
|
208
|
-
|
|
209
|
-
### 4. Filter Before Querying
|
|
210
|
-
|
|
211
|
-
Apply filters before status queries:
|
|
212
|
-
- Use `filterValidJobs()` first to remove stale jobs
|
|
213
|
-
- Then apply `getActiveJobs()` or `getCompletedJobs()`
|
|
214
|
-
- Ensures clean data for queries
|
|
215
|
-
- More accurate results
|
|
216
|
-
|
|
217
|
-
### 5. Chain Operations Appropriately
|
|
218
|
-
|
|
219
|
-
Chain functions in logical order:
|
|
220
|
-
1. Deserialize from storage
|
|
221
|
-
2. Filter valid jobs
|
|
222
|
-
3. Sort by creation time
|
|
223
|
-
4. Apply status filters
|
|
224
|
-
5. Display or analyze results
|
|
225
|
-
|
|
226
|
-
## For AI Agents
|
|
227
|
-
|
|
228
|
-
### When Working with Serialization
|
|
229
|
-
|
|
230
|
-
**DO:**
|
|
231
|
-
- Use `serializeJobMetadata()` before storage
|
|
232
|
-
- Use `deserializeJobMetadata()` after loading
|
|
233
|
-
- Always check for null on deserialization
|
|
234
|
-
- Handle JSON parsing errors gracefully
|
|
235
|
-
- Validate data after deserialization
|
|
236
|
-
|
|
237
|
-
**DON'T:**
|
|
238
|
-
- Store raw objects without serialization
|
|
239
|
-
- Assume deserialization always succeeds
|
|
240
|
-
- Skip null checks on deserialized data
|
|
241
|
-
- Use JSON.stringify/parse directly
|
|
242
|
-
- Ignore corrupted data handling
|
|
243
|
-
|
|
244
|
-
### When Working with Filters
|
|
245
|
-
|
|
246
|
-
**DO:**
|
|
247
|
-
- Filter valid jobs before display
|
|
248
|
-
- Remove stale jobs regularly
|
|
249
|
-
- Use `getActiveJobs()` for active job lists
|
|
250
|
-
- Use `getCompletedJobs()` for job history
|
|
251
|
-
- Combine filters for specific queries
|
|
252
|
-
|
|
253
|
-
**DON'T:**
|
|
254
|
-
- Display stale or invalid jobs
|
|
255
|
-
- Skip validation before filtering
|
|
256
|
-
- Manually implement filter logic
|
|
257
|
-
- Forget to handle empty arrays
|
|
258
|
-
- Query without filtering first
|
|
259
|
-
|
|
260
|
-
### When Working with Sorting
|
|
261
|
-
|
|
262
|
-
**DO:**
|
|
263
|
-
- Use `sortJobsByCreation()` for chronological display
|
|
264
|
-
- Display newest jobs first
|
|
265
|
-
- Use sorted copy for display
|
|
266
|
-
- Keep original array unmodified
|
|
267
|
-
- Sort after filtering
|
|
268
|
-
|
|
269
|
-
**DON'T:**
|
|
270
|
-
- Sort in-place (modifies original)
|
|
271
|
-
- Sort before filtering (inefficient)
|
|
272
|
-
- Assume array is sorted
|
|
273
|
-
- Implement custom sort logic
|
|
274
|
-
- Skip sorting for user displays
|
|
275
|
-
|
|
276
|
-
### When Adding Features
|
|
277
|
-
|
|
278
|
-
**For New Query Functions:**
|
|
279
|
-
1. Add to same file for consistency
|
|
280
|
-
2. Follow existing function patterns
|
|
281
|
-
3. Return new arrays (don't mutate)
|
|
282
|
-
4. Document filtering/sorting logic
|
|
283
|
-
5. Export from index if needed
|
|
284
|
-
|
|
285
|
-
**For New Storage Backends:**
|
|
286
|
-
1. Use serialize/deserialize functions
|
|
287
|
-
2. Implement consistent key format
|
|
288
|
-
3. Handle storage errors gracefully
|
|
289
|
-
4. Add batch operations if needed
|
|
290
|
-
5. Document storage schema
|
|
291
|
-
|
|
292
|
-
## Implementation Notes
|
|
293
|
-
|
|
294
|
-
**Location:** `src/infrastructure/utils/job-metadata/job-metadata-queries.util.ts`
|
|
295
|
-
|
|
296
|
-
**Functions:**
|
|
297
|
-
- `serializeJobMetadata(metadata: FalJobMetadata): string`
|
|
298
|
-
- `deserializeJobMetadata(data: string): FalJobMetadata | null`
|
|
299
|
-
- `filterValidJobs(jobs: FalJobMetadata[]): FalJobMetadata[]`
|
|
300
|
-
- `sortJobsByCreation(jobs: FalJobMetadata[]): FalJobMetadata[]`
|
|
301
|
-
- `getActiveJobs(jobs: FalJobMetadata[]): FalJobMetadata[]`
|
|
302
|
-
- `getCompletedJobs(jobs: FalJobMetadata[]): FalJobMetadata[]`
|
|
303
|
-
|
|
304
|
-
**Dependencies:**
|
|
305
|
-
- Uses `FalJobMetadata` type from `job-metadata.types.ts`
|
|
306
|
-
- Uses `isJobStale()` from `job-metadata-lifecycle.util.ts`
|
|
307
|
-
- Uses JSON.stringify/JSON.parse for serialization
|
|
308
|
-
- No external dependencies
|
|
309
|
-
|
|
310
|
-
**Import:**
|
|
311
|
-
```typescript
|
|
312
|
-
import {
|
|
313
|
-
serializeJobMetadata,
|
|
314
|
-
deserializeJobMetadata,
|
|
315
|
-
filterValidJobs,
|
|
316
|
-
sortJobsByCreation,
|
|
317
|
-
getActiveJobs,
|
|
318
|
-
getCompletedJobs
|
|
319
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
**Related:**
|
|
323
|
-
- Job metadata types: `src/infrastructure/utils/job-metadata/job-metadata.types.ts`
|
|
324
|
-
- Job lifecycle: `src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.ts`
|
|
325
|
-
- Job storage: `src/infrastructure/utils/job-metadata/index.ts`
|
|
326
|
-
|
|
327
|
-
## Related Documentation
|
|
328
|
-
|
|
329
|
-
- [Job Metadata Types](./job-metadata.types.README.md)
|
|
330
|
-
- [Job Lifecycle](./job-metadata-lifecycle.util.README.md)
|
|
331
|
-
- [Job Format](./job-metadata-format.util.README.md)
|
|
332
|
-
- [Job Metadata Index](./index.README.md)
|