@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,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Timing Helper Utilities
|
|
3
|
-
* Functions for timing, debouncing, and throttling
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Calculate timeout with jitter to avoid thundering herd
|
|
8
|
-
*/
|
|
9
|
-
export function calculateTimeoutWithJitter(
|
|
10
|
-
baseTimeout: number,
|
|
11
|
-
jitterPercent: number = 0.1
|
|
12
|
-
): number {
|
|
13
|
-
const jitter = baseTimeout * jitterPercent;
|
|
14
|
-
const randomJitter = Math.random() * jitter - jitter / 2;
|
|
15
|
-
return Math.max(1000, baseTimeout + randomJitter);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Debounce function (for rate limiting)
|
|
20
|
-
*/
|
|
21
|
-
export function debounce<T extends (...args: never[]) => unknown>(
|
|
22
|
-
func: T,
|
|
23
|
-
wait: number
|
|
24
|
-
): (...args: Parameters<T>) => void {
|
|
25
|
-
let timeout: ReturnType<typeof setTimeout> | null = null;
|
|
26
|
-
|
|
27
|
-
return function executedFunction(...args: Parameters<T>) {
|
|
28
|
-
const later = () => {
|
|
29
|
-
timeout = null;
|
|
30
|
-
func(...args);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (timeout) {
|
|
34
|
-
clearTimeout(timeout);
|
|
35
|
-
}
|
|
36
|
-
timeout = setTimeout(later, wait);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Simple throttle function
|
|
42
|
-
*/
|
|
43
|
-
export function throttle<T extends (...args: never[]) => unknown>(
|
|
44
|
-
func: T,
|
|
45
|
-
limit: number
|
|
46
|
-
): (...args: Parameters<T>) => void {
|
|
47
|
-
let inThrottle = false;
|
|
48
|
-
|
|
49
|
-
return function executedFunction(...args: Parameters<T>) {
|
|
50
|
-
if (!inThrottle) {
|
|
51
|
-
func(...args);
|
|
52
|
-
inThrottle = true;
|
|
53
|
-
setTimeout(() => (inThrottle = false), limit);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
# Type Guards & Validators
|
|
2
|
-
|
|
3
|
-
Runtime type checking and validation helper functions for FAL AI operations.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/utils/type-guards.util.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This module provides runtime type checking and validation functions. It brings TypeScript type system to runtime, enabling detection of invalid data and type-safe operations.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Enhances type safety by:
|
|
14
|
-
- Providing runtime type guards for enums
|
|
15
|
-
- Validating data structures
|
|
16
|
-
- Checking image data validity
|
|
17
|
-
- Validating API keys
|
|
18
|
-
- Ensuring prompt safety
|
|
19
|
-
- Preventing invalid data from reaching APIs
|
|
20
|
-
|
|
21
|
-
## Import
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
import {
|
|
25
|
-
isFalModelType,
|
|
26
|
-
isModelType,
|
|
27
|
-
isFalErrorType,
|
|
28
|
-
isValidBase64Image,
|
|
29
|
-
isValidApiKey,
|
|
30
|
-
isValidPrompt
|
|
31
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Type Guard Functions
|
|
35
|
-
|
|
36
|
-
### isFalModelType
|
|
37
|
-
|
|
38
|
-
Check if value is valid FAL model type.
|
|
39
|
-
|
|
40
|
-
**Parameters:**
|
|
41
|
-
- `value`: Unknown value to check
|
|
42
|
-
|
|
43
|
-
**Returns:** `boolean` - True if value is valid `FalModelType`
|
|
44
|
-
|
|
45
|
-
**Valid Values:**
|
|
46
|
-
- `text-to-image`
|
|
47
|
-
- `text-to-video`
|
|
48
|
-
- `text-to-voice`
|
|
49
|
-
- `image-to-video`
|
|
50
|
-
- `image-to-image`
|
|
51
|
-
- `text-to-text`
|
|
52
|
-
|
|
53
|
-
**Usage:**
|
|
54
|
-
Use before processing model type values. Enables type narrowing in TypeScript. Use in validation logic and user input processing.
|
|
55
|
-
|
|
56
|
-
**Implementation:** See complete validation in `src/infrastructure/utils/type-guards.util.ts`
|
|
57
|
-
|
|
58
|
-
### isModelType
|
|
59
|
-
|
|
60
|
-
Check if value is valid model type for hooks.
|
|
61
|
-
|
|
62
|
-
**Parameters:**
|
|
63
|
-
- `value`: Unknown value to check
|
|
64
|
-
|
|
65
|
-
**Returns:** `boolean` - True if value is valid `ModelType`
|
|
66
|
-
|
|
67
|
-
**Valid Values:**
|
|
68
|
-
- `text-to-image`
|
|
69
|
-
- `text-to-video`
|
|
70
|
-
- `image-to-video`
|
|
71
|
-
- `text-to-voice`
|
|
72
|
-
|
|
73
|
-
**Usage:**
|
|
74
|
-
Use when validating model type for `useModels` hook. Subset of `FalModelType` for user-facing model selection. Enables type-safe model filtering.
|
|
75
|
-
|
|
76
|
-
**Related:**
|
|
77
|
-
- Model types: `src/domain/types/model-selection.types.ts`
|
|
78
|
-
- useModels hook: `src/presentation/hooks/use-models.ts`
|
|
79
|
-
|
|
80
|
-
### isFalErrorType
|
|
81
|
-
|
|
82
|
-
Check if value is valid FAL error type.
|
|
83
|
-
|
|
84
|
-
**Parameters:**
|
|
85
|
-
- `value`: Unknown value to check
|
|
86
|
-
|
|
87
|
-
**Returns:** `boolean` - True if value is valid `FalErrorType`
|
|
88
|
-
|
|
89
|
-
**Valid Values:**
|
|
90
|
-
- `network`
|
|
91
|
-
- `timeout`
|
|
92
|
-
- `authentication`
|
|
93
|
-
- `quota_exceeded`
|
|
94
|
-
- `rate_limit`
|
|
95
|
-
- `invalid_input`
|
|
96
|
-
- `model_unavailable`
|
|
97
|
-
- `nsfw_content`
|
|
98
|
-
- `validation`
|
|
99
|
-
- `content_policy`
|
|
100
|
-
- `unknown`
|
|
101
|
-
|
|
102
|
-
**Usage:**
|
|
103
|
-
Use when validating error type values. Enables type-safe error handling. Use in error categorization and user error display.
|
|
104
|
-
|
|
105
|
-
**Related:**
|
|
106
|
-
- Error types: `src/domain/entities/error.types.ts`
|
|
107
|
-
- Error categorizer: `src/infrastructure/utils/error-categorizer.ts`
|
|
108
|
-
|
|
109
|
-
## Validation Functions
|
|
110
|
-
|
|
111
|
-
### isValidBase64Image
|
|
112
|
-
|
|
113
|
-
Check if base64 image data is valid.
|
|
114
|
-
|
|
115
|
-
**Parameters:**
|
|
116
|
-
- `data`: Unknown value to check
|
|
117
|
-
|
|
118
|
-
**Returns:** `boolean` - True if valid base64 image
|
|
119
|
-
|
|
120
|
-
**Validation Rules:**
|
|
121
|
-
- Checks if string
|
|
122
|
-
- Validates base64 format
|
|
123
|
-
- Checks for valid image headers
|
|
124
|
-
- Ensures non-empty data
|
|
125
|
-
|
|
126
|
-
**Usage:**
|
|
127
|
-
Use this function before sending image data to FAL API. Validates that image data is properly formatted base64. Prevents API errors from invalid image data.
|
|
128
|
-
|
|
129
|
-
**Related:**
|
|
130
|
-
- Helper functions: `src/infrastructure/utils/helpers.util.ts`
|
|
131
|
-
|
|
132
|
-
### isValidApiKey
|
|
133
|
-
|
|
134
|
-
Check if API key is valid format.
|
|
135
|
-
|
|
136
|
-
**Parameters:**
|
|
137
|
-
- `key`: API key string to validate
|
|
138
|
-
|
|
139
|
-
**Returns:** `boolean` - True if API key format is valid
|
|
140
|
-
|
|
141
|
-
**Validation Rules:**
|
|
142
|
-
- Checks if string
|
|
143
|
-
- Validates minimum length
|
|
144
|
-
- Checks for valid characters
|
|
145
|
-
- Ensures not empty
|
|
146
|
-
|
|
147
|
-
**Usage:**
|
|
148
|
-
Use this function before setting API key. Validates FAL API key format. Prevents errors from invalid keys.
|
|
149
|
-
|
|
150
|
-
**Implementation:** See validation logic in `src/infrastructure/utils/type-guards.util.ts`
|
|
151
|
-
|
|
152
|
-
### isValidPrompt
|
|
153
|
-
|
|
154
|
-
Check if prompt text is valid.
|
|
155
|
-
|
|
156
|
-
**Parameters:**
|
|
157
|
-
- `prompt`: Prompt text to validate
|
|
158
|
-
|
|
159
|
-
**Returns:** `boolean` - True if prompt is valid
|
|
160
|
-
|
|
161
|
-
**Validation Rules:**
|
|
162
|
-
- Checks if string
|
|
163
|
-
- Ensures not empty
|
|
164
|
-
- Validates length limits
|
|
165
|
-
- Checks for prohibited content
|
|
166
|
-
|
|
167
|
-
**Usage:**
|
|
168
|
-
Use this function before sending prompt to FAL API. Validates prompt is safe and within limits. Prevents errors from invalid prompts.
|
|
169
|
-
|
|
170
|
-
**Related:**
|
|
171
|
-
- Helper functions: `src/infrastructure/utils/helpers.util.ts`
|
|
172
|
-
|
|
173
|
-
## Usage Guidelines
|
|
174
|
-
|
|
175
|
-
### For Type Safety
|
|
176
|
-
|
|
177
|
-
**Type Narrowing Pattern:**
|
|
178
|
-
1. Receive unknown value from external source
|
|
179
|
-
2. Use appropriate type guard function
|
|
180
|
-
3. TypeScript narrows type in conditional block
|
|
181
|
-
4. Safely use value with correct type
|
|
182
|
-
|
|
183
|
-
**Benefits:**
|
|
184
|
-
- Runtime type safety
|
|
185
|
-
- Compile-time type narrowing
|
|
186
|
-
- Prevents type errors
|
|
187
|
-
- Catches invalid data early
|
|
188
|
-
|
|
189
|
-
### For Data Validation
|
|
190
|
-
|
|
191
|
-
**Validation Pattern:**
|
|
192
|
-
1. Receive data from user input or API
|
|
193
|
-
2. Use validation function appropriate to data type
|
|
194
|
-
3. Check return value
|
|
195
|
-
4. Handle invalid data appropriately
|
|
196
|
-
|
|
197
|
-
**Best Practices:**
|
|
198
|
-
- Always validate external data
|
|
199
|
-
- Validate user input before processing
|
|
200
|
-
- Check API responses before use
|
|
201
|
-
- Provide clear error messages for invalid data
|
|
202
|
-
|
|
203
|
-
### For Image Data
|
|
204
|
-
|
|
205
|
-
**Image Validation Pattern:**
|
|
206
|
-
1. Receive image data from source
|
|
207
|
-
2. Use `isValidBase64Image()` to validate
|
|
208
|
-
3. Use `formatImageDataUri()` if needed
|
|
209
|
-
4. Pass to FAL API only if valid
|
|
210
|
-
|
|
211
|
-
**Related:**
|
|
212
|
-
- Helper functions: `src/infrastructure/utils/helpers.util.ts`
|
|
213
|
-
- Image feature builders: `src/infrastructure/utils/image-feature-builders.util.ts`
|
|
214
|
-
|
|
215
|
-
### For Error Handling
|
|
216
|
-
|
|
217
|
-
**Error Type Validation:**
|
|
218
|
-
1. Receive error type from unknown source
|
|
219
|
-
2. Use `isFalErrorType()` to validate
|
|
220
|
-
3. Use in switch statement for type-safe handling
|
|
221
|
-
4. Handle all error types
|
|
222
|
-
|
|
223
|
-
**Related:**
|
|
224
|
-
- Error types: `src/domain/entities/error.types.ts`
|
|
225
|
-
|
|
226
|
-
## Best Practices
|
|
227
|
-
|
|
228
|
-
### 1. Always Validate External Data
|
|
229
|
-
|
|
230
|
-
Validate all data from external sources:
|
|
231
|
-
- User input
|
|
232
|
-
- API responses
|
|
233
|
-
- File uploads
|
|
234
|
-
- Configuration data
|
|
235
|
-
|
|
236
|
-
### 2. Use Type Guards for Type Safety
|
|
237
|
-
|
|
238
|
-
Leverage TypeScript type narrowing:
|
|
239
|
-
- Use before processing unknown values
|
|
240
|
-
- Combine with conditional types
|
|
241
|
-
- Enable type-safe operations
|
|
242
|
-
- Prevent type errors
|
|
243
|
-
|
|
244
|
-
### 3. Validate Before API Calls
|
|
245
|
-
|
|
246
|
-
Check data before sending to FAL API:
|
|
247
|
-
- Validate image data format
|
|
248
|
-
- Check prompt validity
|
|
249
|
-
- Verify API key format
|
|
250
|
-
- Prevent unnecessary API errors
|
|
251
|
-
|
|
252
|
-
### 4. Provide Clear Error Messages
|
|
253
|
-
|
|
254
|
-
Give useful feedback for invalid data:
|
|
255
|
-
- Indicate what failed validation
|
|
256
|
-
- Provide guidance for correction
|
|
257
|
-
- Show format requirements
|
|
258
|
-
- Suggest valid examples
|
|
259
|
-
|
|
260
|
-
### 5. Handle Invalid Data Gracefully
|
|
261
|
-
|
|
262
|
-
Respond appropriately to invalid data:
|
|
263
|
-
- Return error to user
|
|
264
|
-
- Log validation failures
|
|
265
|
-
- Don't crash application
|
|
266
|
-
- Provide recovery options
|
|
267
|
-
|
|
268
|
-
## For AI Agents
|
|
269
|
-
|
|
270
|
-
### When Using Type Guards
|
|
271
|
-
|
|
272
|
-
**DO:**
|
|
273
|
-
- Import from package root
|
|
274
|
-
- Use type guards before processing
|
|
275
|
-
- Validate all external data
|
|
276
|
-
- Leverage type narrowing
|
|
277
|
-
- Handle invalid data
|
|
278
|
-
- Provide clear errors
|
|
279
|
-
- Use appropriate guard for data type
|
|
280
|
-
|
|
281
|
-
**DON'T:**
|
|
282
|
-
- Assume data types
|
|
283
|
-
- Skip type checking
|
|
284
|
-
- Process invalid data
|
|
285
|
-
- Ignore type safety
|
|
286
|
-
- Create duplicate guards
|
|
287
|
-
- Use wrong guard for data
|
|
288
|
-
- Assume validation passes
|
|
289
|
-
|
|
290
|
-
### When Validating Data
|
|
291
|
-
|
|
292
|
-
**DO:**
|
|
293
|
-
- Validate user input
|
|
294
|
-
- Check API responses
|
|
295
|
-
- Verify file uploads
|
|
296
|
-
- Validate configuration
|
|
297
|
-
- Use specific validation functions
|
|
298
|
-
- Handle invalid data appropriately
|
|
299
|
-
- Log validation failures
|
|
300
|
-
|
|
301
|
-
**DON'T:**
|
|
302
|
-
- Skip validation
|
|
303
|
-
- Assume data format
|
|
304
|
-
- Process invalid data
|
|
305
|
-
- Ignore validation results
|
|
306
|
-
- Use generic checks only
|
|
307
|
-
- Allow invalid data through
|
|
308
|
-
- Hide validation errors
|
|
309
|
-
|
|
310
|
-
### When Adding Guards
|
|
311
|
-
|
|
312
|
-
**For New Type Guards:**
|
|
313
|
-
1. Add to type guards file
|
|
314
|
-
2. Follow naming convention (`isXxx`)
|
|
315
|
-
3. Return boolean for simple checks
|
|
316
|
-
4. Return detailed info if needed
|
|
317
|
-
5. Update exports
|
|
318
|
-
6. Document in this README
|
|
319
|
-
|
|
320
|
-
**For New Validators:**
|
|
321
|
-
1. Add validation function
|
|
322
|
-
2. Follow naming convention (`isValidXxx`)
|
|
323
|
-
3. Check all relevant conditions
|
|
324
|
-
4. Provide clear return values
|
|
325
|
-
5. Handle edge cases
|
|
326
|
-
6. Document validation rules
|
|
327
|
-
|
|
328
|
-
**For Enhanced Validation:**
|
|
329
|
-
1. Review existing validation logic
|
|
330
|
-
2. Add stricter checks if needed
|
|
331
|
-
3. Improve error messages
|
|
332
|
-
4. Update documentation
|
|
333
|
-
5. Test with edge cases
|
|
334
|
-
|
|
335
|
-
## Implementation Notes
|
|
336
|
-
|
|
337
|
-
**Location:** `src/infrastructure/utils/type-guards.util.ts`
|
|
338
|
-
|
|
339
|
-
**Dependencies:**
|
|
340
|
-
- No external dependencies
|
|
341
|
-
- Pure validation functions
|
|
342
|
-
- Used throughout the provider
|
|
343
|
-
|
|
344
|
-
**Function Categories:**
|
|
345
|
-
- Type guards for enum validation
|
|
346
|
-
- Data validation functions
|
|
347
|
-
- Format validation functions
|
|
348
|
-
- Safety checks
|
|
349
|
-
|
|
350
|
-
**Import:**
|
|
351
|
-
```typescript
|
|
352
|
-
import {
|
|
353
|
-
isFalModelType,
|
|
354
|
-
isModelType,
|
|
355
|
-
isFalErrorType,
|
|
356
|
-
isValidBase64Image,
|
|
357
|
-
isValidApiKey,
|
|
358
|
-
isValidPrompt
|
|
359
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
**Related:**
|
|
363
|
-
- Helper functions: `src/infrastructure/utils/helpers.util.ts`
|
|
364
|
-
- Error types: `src/domain/entities/error.types.ts`
|
|
365
|
-
- Model types: `src/domain/types/model-selection.types.ts`
|
|
366
|
-
|
|
367
|
-
## Related Documentation
|
|
368
|
-
|
|
369
|
-
- [Helper Utilities](./helpers.util.README.md)
|
|
370
|
-
- [Error Types](../../domain/entities/error.types.README.md)
|
|
371
|
-
- [Model Selection Types](../../domain/types/model-selection.types.README.md)
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
# Validators Module
|
|
2
|
-
|
|
3
|
-
Central export point for all validator functions.
|
|
4
|
-
|
|
5
|
-
**Location:** `src/infrastructure/validators/index.ts`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
The validators module provides content validation utilities to ensure AI-generated content meets safety and quality standards. Currently, it focuses on NSFW (Not Safe For Work) content detection.
|
|
10
|
-
|
|
11
|
-
## Purpose
|
|
12
|
-
|
|
13
|
-
Provides validation by:
|
|
14
|
-
- Checking content safety
|
|
15
|
-
- Preventing inappropriate content
|
|
16
|
-
- Enforcing content policies
|
|
17
|
-
- Supporting custom validators
|
|
18
|
-
- Enabling content filtering
|
|
19
|
-
|
|
20
|
-
## Import
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import {
|
|
24
|
-
validateNSFWContent
|
|
25
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Exports
|
|
29
|
-
|
|
30
|
-
### validateNSFWContent
|
|
31
|
-
|
|
32
|
-
Validates AI-generated content for NSFW material.
|
|
33
|
-
|
|
34
|
-
**Path:** `src/infrastructure/validators/nsfw-validator.ts`
|
|
35
|
-
|
|
36
|
-
**Documentation:** See `nsfw-validator.README.md`
|
|
37
|
-
|
|
38
|
-
**Usage:**
|
|
39
|
-
Validate content immediately after generation. Throw NSFWContentError if violation detected. Handle error specifically in UI.
|
|
40
|
-
|
|
41
|
-
## Usage Guidelines
|
|
42
|
-
|
|
43
|
-
### For Content Validation
|
|
44
|
-
|
|
45
|
-
**Validation Pattern:**
|
|
46
|
-
1. Receive generation result
|
|
47
|
-
2. Call validateNSFWContent
|
|
48
|
-
3. Catch NSFWContentError
|
|
49
|
-
4. Display user-friendly message
|
|
50
|
-
5. Block inappropriate content
|
|
51
|
-
|
|
52
|
-
**Best Practices:**
|
|
53
|
-
- Always validate user-facing content
|
|
54
|
-
- Validate immediately after generation
|
|
55
|
-
- Handle NSFW errors specifically
|
|
56
|
-
- Don't retry NSFW requests
|
|
57
|
-
- Track NSFW occurrences
|
|
58
|
-
- Enforce content policies
|
|
59
|
-
|
|
60
|
-
### For Error Handling
|
|
61
|
-
|
|
62
|
-
**Error Pattern:**
|
|
63
|
-
1. Catch NSFWContentError specifically
|
|
64
|
-
2. Display clear error messages
|
|
65
|
-
3. Guide users to acceptable content
|
|
66
|
-
4. Block retry attempts
|
|
67
|
-
5. Log violations appropriately
|
|
68
|
-
|
|
69
|
-
**Best Practices:**
|
|
70
|
-
- Check instanceof NSFWContentError
|
|
71
|
-
- Show specific error messages
|
|
72
|
-
- Prevent content display
|
|
73
|
-
- Inform users clearly
|
|
74
|
-
- Track violation patterns
|
|
75
|
-
|
|
76
|
-
## Best Practices
|
|
77
|
-
|
|
78
|
-
### 1. Always Validate User-Facing Content
|
|
79
|
-
|
|
80
|
-
Validate all generated content before displaying:
|
|
81
|
-
- Call validateNSFWContent after generation
|
|
82
|
-
- Validate before saving to storage
|
|
83
|
-
- Check before displaying in UI
|
|
84
|
-
- Prevent NSFW content display
|
|
85
|
-
- Enforce content policies
|
|
86
|
-
|
|
87
|
-
### 2. Handle Validation Errors
|
|
88
|
-
|
|
89
|
-
Process NSFW content errors:
|
|
90
|
-
- Catch NSFWContentError specifically
|
|
91
|
-
- Display user-friendly messages
|
|
92
|
-
- Block inappropriate content display
|
|
93
|
-
- Guide users to corrections
|
|
94
|
-
- Track violation occurrences
|
|
95
|
-
|
|
96
|
-
### 3. Validate Early
|
|
97
|
-
|
|
98
|
-
Validate content as early as possible:
|
|
99
|
-
- Validate immediately after generation
|
|
100
|
-
- Check before saving to storage
|
|
101
|
-
- Validate before displaying
|
|
102
|
-
- Prevent NSFW content spread
|
|
103
|
-
- Minimize exposure time
|
|
104
|
-
|
|
105
|
-
### 4. Provide Context
|
|
106
|
-
|
|
107
|
-
Track validation with context:
|
|
108
|
-
- Log violation with user ID
|
|
109
|
-
- Include prompt that caused violation
|
|
110
|
-
- Timestamp the occurrence
|
|
111
|
-
- Track violation patterns
|
|
112
|
-
- Enforce rate limiting
|
|
113
|
-
|
|
114
|
-
### 5. Enforce Consistently
|
|
115
|
-
|
|
116
|
-
Apply validation uniformly:
|
|
117
|
-
- Validate all user-generated content
|
|
118
|
-
- Don't skip validation for any users
|
|
119
|
-
- Apply same rules consistently
|
|
120
|
-
- Update validation rules regularly
|
|
121
|
-
- Monitor validation effectiveness
|
|
122
|
-
|
|
123
|
-
## For AI Agents
|
|
124
|
-
|
|
125
|
-
### When Using Validators
|
|
126
|
-
|
|
127
|
-
**DO:**
|
|
128
|
-
- Import from package root
|
|
129
|
-
- Validate all user-facing content
|
|
130
|
-
- Handle NSFW errors specifically
|
|
131
|
-
- Display clear error messages
|
|
132
|
-
- Track violation occurrences
|
|
133
|
-
- Enforce content policies
|
|
134
|
-
- Update validation rules
|
|
135
|
-
|
|
136
|
-
**DON'T:**
|
|
137
|
-
- Skip content validation
|
|
138
|
-
- Display NSFW content
|
|
139
|
-
- Ignore validation errors
|
|
140
|
-
- Hide violation details
|
|
141
|
-
- Allow inappropriate content
|
|
142
|
-
- Forget policy enforcement
|
|
143
|
-
- Create security issues
|
|
144
|
-
|
|
145
|
-
### When Validating Content
|
|
146
|
-
|
|
147
|
-
**DO:**
|
|
148
|
-
- Validate immediately after generation
|
|
149
|
-
- Check for NSFW concepts array
|
|
150
|
-
- Throw NSFWContentError for violations
|
|
151
|
-
- Handle validation errors gracefully
|
|
152
|
-
- Log violations appropriately
|
|
153
|
-
- Guide users to corrections
|
|
154
|
-
|
|
155
|
-
**DON'T:**
|
|
156
|
-
- Skip validation
|
|
157
|
-
- Ignore NSFW concepts
|
|
158
|
-
- Allow violations through
|
|
159
|
-
- Display inappropriate content
|
|
160
|
-
- Forget logging
|
|
161
|
-
- Leave users uninformed
|
|
162
|
-
- Create liability issues
|
|
163
|
-
|
|
164
|
-
### When Handling Violations
|
|
165
|
-
|
|
166
|
-
**DO:**
|
|
167
|
-
- Check instanceof NSFWContentError
|
|
168
|
-
- Display user-friendly messages
|
|
169
|
-
- Block inappropriate content
|
|
170
|
-
- Track violation patterns
|
|
171
|
-
- Implement rate limiting
|
|
172
|
-
- Suggest corrections
|
|
173
|
-
|
|
174
|
-
**DON'T:**
|
|
175
|
-
- Handle like other errors
|
|
176
|
-
- Show technical details
|
|
177
|
-
- Allow content display
|
|
178
|
-
- Skip tracking
|
|
179
|
-
- Enable retry attempts
|
|
180
|
-
- Create policy violations
|
|
181
|
-
|
|
182
|
-
## Implementation Notes
|
|
183
|
-
|
|
184
|
-
**Location:** `src/infrastructure/validators/index.ts`
|
|
185
|
-
|
|
186
|
-
**Dependencies:**
|
|
187
|
-
- NSFW validator: `src/infrastructure/validators/nsfw-validator.ts`
|
|
188
|
-
- NSFW error: `src/infrastructure/services/nsfw-content-error.ts`
|
|
189
|
-
|
|
190
|
-
**Validation Categories:**
|
|
191
|
-
- Content safety validation
|
|
192
|
-
- Policy enforcement
|
|
193
|
-
- User-facing content checks
|
|
194
|
-
|
|
195
|
-
**Import:**
|
|
196
|
-
```typescript
|
|
197
|
-
import {
|
|
198
|
-
validateNSFWContent
|
|
199
|
-
} from '@umituz/react-native-ai-fal-provider';
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
**Related:**
|
|
203
|
-
- NSFW validator: `src/infrastructure/validators/nsfw-validator.ts`
|
|
204
|
-
- NSFW error: `src/infrastructure/services/nsfw-content-error.ts`
|
|
205
|
-
- Error mapper: `src/infrastructure/utils/error-mapper.ts`
|