@umituz/react-native-ai-fal-provider 3.1.7 → 3.2.0
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/exports/infrastructure.ts +0 -45
- package/src/exports/presentation.ts +2 -11
- package/src/index.ts +2 -3
- package/src/infrastructure/services/fal-queue-operations.ts +1 -1
- package/src/infrastructure/services/index.ts +0 -2
- package/src/infrastructure/utils/index.ts +7 -53
- package/src/infrastructure/utils/input-validator.util.ts +1 -1
- package/src/infrastructure/utils/parsers/index.ts +1 -4
- package/src/init/createAiProviderInitModule.ts +0 -56
- package/src/init/initializeFalProvider.ts +34 -0
- package/src/presentation/hooks/index.ts +0 -3
- package/src/infrastructure/services/fal-models.service.ts +0 -40
- package/src/infrastructure/utils/base-builders.util.ts +0 -28
- package/src/infrastructure/utils/collections/array-filters.util.ts +0 -63
- package/src/infrastructure/utils/collections/array-sorters.util.ts +0 -94
- package/src/infrastructure/utils/collections/index.ts +0 -7
- package/src/infrastructure/utils/date-format.util.ts +0 -30
- package/src/infrastructure/utils/error-categorizer.ts +0 -9
- package/src/infrastructure/utils/job-metadata/index.ts +0 -26
- package/src/infrastructure/utils/job-metadata/job-metadata-format.util.ts +0 -78
- package/src/infrastructure/utils/job-metadata/job-metadata-lifecycle.util.ts +0 -66
- package/src/infrastructure/utils/job-metadata/job-metadata-queries.util.ts +0 -57
- package/src/infrastructure/utils/job-metadata/job-metadata.types.ts +0 -19
- package/src/infrastructure/utils/job-storage/index.ts +0 -19
- package/src/infrastructure/utils/job-storage/job-storage-crud.util.ts +0 -64
- package/src/infrastructure/utils/job-storage/job-storage-interface.ts +0 -44
- package/src/infrastructure/utils/job-storage/job-storage-queries.util.ts +0 -81
- package/src/infrastructure/utils/number-format.util.ts +0 -86
- package/src/infrastructure/utils/parsers/object-validators.util.ts +0 -38
- package/src/infrastructure/utils/parsers/value-parsers.util.ts +0 -45
- package/src/infrastructure/utils/string-format.util.ts +0 -72
- package/src/infrastructure/validators/README.md +0 -290
- package/src/init/registerWithWizard.ts +0 -28
- package/src/presentation/hooks/README.md +0 -626
- package/src/presentation/hooks/use-models.ts +0 -56
package/package.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
export {
|
|
6
6
|
FalProvider,
|
|
7
7
|
falProvider,
|
|
8
|
-
falModelsService,
|
|
9
8
|
NSFWContentError,
|
|
10
9
|
cleanupRequestStore,
|
|
11
10
|
stopAutomaticCleanup,
|
|
@@ -13,22 +12,17 @@ export {
|
|
|
13
12
|
export type { FalProviderType, ActiveRequest } from "../infrastructure/services";
|
|
14
13
|
|
|
15
14
|
export {
|
|
16
|
-
categorizeFalError,
|
|
17
15
|
mapFalError,
|
|
18
16
|
parseFalError,
|
|
19
17
|
isFalErrorRetryable,
|
|
20
|
-
buildSingleImageInput,
|
|
21
|
-
buildDualImageInput,
|
|
22
18
|
} from "../infrastructure/utils";
|
|
23
19
|
|
|
24
|
-
// Error handling utilities
|
|
25
20
|
export {
|
|
26
21
|
getErrorMessage,
|
|
27
22
|
getErrorMessageOr,
|
|
28
23
|
formatErrorMessage,
|
|
29
24
|
} from "../infrastructure/utils/helpers/error-helpers.util";
|
|
30
25
|
|
|
31
|
-
// Image field constants
|
|
32
26
|
export {
|
|
33
27
|
IMAGE_URL_FIELDS,
|
|
34
28
|
isImageField,
|
|
@@ -37,7 +31,6 @@ export type {
|
|
|
37
31
|
ImageUrlField,
|
|
38
32
|
} from "../infrastructure/utils/constants/image-fields.constants";
|
|
39
33
|
|
|
40
|
-
// Validators
|
|
41
34
|
export {
|
|
42
35
|
isDataUri,
|
|
43
36
|
isBase64DataUri,
|
|
@@ -68,12 +61,6 @@ export {
|
|
|
68
61
|
getDataUriExtension,
|
|
69
62
|
uploadToFalStorage,
|
|
70
63
|
uploadMultipleToFalStorage,
|
|
71
|
-
formatNumber,
|
|
72
|
-
formatBytes,
|
|
73
|
-
formatDuration,
|
|
74
|
-
truncateText,
|
|
75
|
-
truncatePrompt,
|
|
76
|
-
sanitizePrompt,
|
|
77
64
|
buildErrorMessage,
|
|
78
65
|
isDefined,
|
|
79
66
|
removeNullish,
|
|
@@ -81,38 +68,6 @@ export {
|
|
|
81
68
|
sleep,
|
|
82
69
|
} from "../infrastructure/utils";
|
|
83
70
|
|
|
84
|
-
export {
|
|
85
|
-
createJobMetadata,
|
|
86
|
-
updateJobMetadata,
|
|
87
|
-
isJobCompleted,
|
|
88
|
-
isJobRunning,
|
|
89
|
-
isJobStale,
|
|
90
|
-
getJobDuration,
|
|
91
|
-
formatJobDuration,
|
|
92
|
-
calculateJobProgress,
|
|
93
|
-
serializeJobMetadata,
|
|
94
|
-
deserializeJobMetadata,
|
|
95
|
-
filterValidJobs,
|
|
96
|
-
sortJobsByCreation,
|
|
97
|
-
getActiveJobs,
|
|
98
|
-
getCompletedJobs,
|
|
99
|
-
} from "../infrastructure/utils";
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
saveJobMetadata,
|
|
103
|
-
loadJobMetadata,
|
|
104
|
-
deleteJobMetadata,
|
|
105
|
-
loadAllJobs,
|
|
106
|
-
cleanupOldJobs,
|
|
107
|
-
getJobsByModel,
|
|
108
|
-
getJobsByStatus,
|
|
109
|
-
updateJobStatus,
|
|
110
|
-
} from "../infrastructure/utils";
|
|
111
|
-
|
|
112
|
-
export type { FalJobMetadata, IJobStorage } from "../infrastructure/utils";
|
|
113
|
-
export { InMemoryJobStorage } from "../infrastructure/utils";
|
|
114
|
-
|
|
115
|
-
// Pricing Utilities
|
|
116
71
|
export {
|
|
117
72
|
calculateVideoCredits,
|
|
118
73
|
calculateImageCredits,
|
|
@@ -2,18 +2,9 @@
|
|
|
2
2
|
* Presentation Layer Exports
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
useModels,
|
|
8
|
-
} from "../presentation/hooks";
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
UseFalGenerationOptions,
|
|
12
|
-
UseFalGenerationResult,
|
|
13
|
-
UseModelsProps,
|
|
14
|
-
} from "../presentation/hooks";
|
|
5
|
+
export { useFalGeneration } from "../presentation/hooks";
|
|
6
|
+
export type { UseFalGenerationOptions, UseFalGenerationResult } from "../presentation/hooks";
|
|
15
7
|
|
|
16
|
-
// Export state manager for advanced use cases
|
|
17
8
|
export {
|
|
18
9
|
FalGenerationStateManager,
|
|
19
10
|
} from "../infrastructure/utils/fal-generation-state-manager.util";
|
package/src/index.ts
CHANGED
|
@@ -15,9 +15,8 @@ export * from "./exports/presentation";
|
|
|
15
15
|
// Init Module Factory
|
|
16
16
|
export {
|
|
17
17
|
createAiProviderInitModule,
|
|
18
|
-
initializeFalProvider,
|
|
19
18
|
type AiProviderInitModuleConfig,
|
|
20
19
|
} from './init/createAiProviderInitModule';
|
|
21
20
|
|
|
22
|
-
//
|
|
23
|
-
export {
|
|
21
|
+
// Direct Initialization
|
|
22
|
+
export { initializeFalProvider } from './init/initializeFalProvider';
|
|
@@ -46,7 +46,7 @@ export async function getJobStatus(model: string, requestId: string): Promise<Jo
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
const response = raw as Record<string, unknown>;
|
|
49
|
+
const response = raw as unknown as Record<string, unknown>;
|
|
50
50
|
|
|
51
51
|
if (typeof response.status !== "string") {
|
|
52
52
|
throw new Error(
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
export { FalProvider, falProvider } from "./fal-provider";
|
|
6
6
|
export type { FalProvider as FalProviderType } from "./fal-provider";
|
|
7
|
-
export { falModelsService, type FalModelConfig } from "./fal-models.service";
|
|
8
7
|
export { NSFWContentError } from "./nsfw-content-error";
|
|
9
8
|
|
|
10
|
-
// Request store exports for advanced use cases
|
|
11
9
|
export {
|
|
12
10
|
createRequestKey,
|
|
13
11
|
getExistingRequest,
|
|
@@ -2,41 +2,26 @@
|
|
|
2
2
|
* Utils Index
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export {
|
|
6
|
-
filterByProperty,
|
|
7
|
-
filterByPredicate,
|
|
8
|
-
filterByTimeRange,
|
|
9
|
-
filterByAnyProperty,
|
|
10
|
-
sortByDateDescending,
|
|
11
|
-
sortByDateAscending,
|
|
12
|
-
sortByNumberDescending,
|
|
13
|
-
sortByNumberAscending,
|
|
14
|
-
} from "./collections";
|
|
15
|
-
|
|
16
5
|
export {
|
|
17
6
|
safeJsonParse,
|
|
18
7
|
safeJsonParseOrNull,
|
|
19
8
|
safeJsonStringify,
|
|
20
9
|
isValidJson,
|
|
21
|
-
validateObjectStructure,
|
|
22
10
|
} from "./parsers";
|
|
23
11
|
|
|
24
|
-
export {
|
|
12
|
+
export {
|
|
13
|
+
deepClone,
|
|
14
|
+
mergeObjects,
|
|
15
|
+
pickProperties,
|
|
16
|
+
omitProperties,
|
|
17
|
+
} from "./parsers";
|
|
18
|
+
|
|
25
19
|
export {
|
|
26
20
|
mapFalError,
|
|
27
21
|
parseFalError,
|
|
28
22
|
isFalErrorRetryable,
|
|
29
23
|
} from "./fal-error-handler.util";
|
|
30
24
|
|
|
31
|
-
export { formatDate } from "./date-format.util";
|
|
32
|
-
export { formatNumber, formatBytes, formatDuration } from "./number-format.util";
|
|
33
|
-
export { truncateText, truncatePrompt, sanitizePrompt } from "./string-format.util";
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
buildSingleImageInput,
|
|
37
|
-
buildDualImageInput,
|
|
38
|
-
} from "./base-builders.util";
|
|
39
|
-
|
|
40
25
|
export {
|
|
41
26
|
isFalModelType,
|
|
42
27
|
isModelType,
|
|
@@ -71,37 +56,6 @@ export {
|
|
|
71
56
|
export { preprocessInput } from "./input-preprocessor.util";
|
|
72
57
|
export { validateInput } from "./input-validator.util";
|
|
73
58
|
|
|
74
|
-
export type { FalJobMetadata } from "./job-metadata";
|
|
75
|
-
export {
|
|
76
|
-
createJobMetadata,
|
|
77
|
-
updateJobMetadata,
|
|
78
|
-
isJobCompleted,
|
|
79
|
-
isJobRunning,
|
|
80
|
-
isJobStale,
|
|
81
|
-
getJobDuration,
|
|
82
|
-
formatJobDuration,
|
|
83
|
-
calculateJobProgress,
|
|
84
|
-
serializeJobMetadata,
|
|
85
|
-
deserializeJobMetadata,
|
|
86
|
-
filterValidJobs,
|
|
87
|
-
sortJobsByCreation,
|
|
88
|
-
getActiveJobs,
|
|
89
|
-
getCompletedJobs,
|
|
90
|
-
} from "./job-metadata";
|
|
91
|
-
|
|
92
|
-
export type { IJobStorage } from "./job-storage";
|
|
93
|
-
export {
|
|
94
|
-
InMemoryJobStorage,
|
|
95
|
-
saveJobMetadata,
|
|
96
|
-
loadJobMetadata,
|
|
97
|
-
deleteJobMetadata,
|
|
98
|
-
updateJobStatus,
|
|
99
|
-
loadAllJobs,
|
|
100
|
-
cleanupOldJobs,
|
|
101
|
-
getJobsByModel,
|
|
102
|
-
getJobsByStatus,
|
|
103
|
-
} from "./job-storage";
|
|
104
|
-
|
|
105
59
|
export { FalGenerationStateManager } from "./fal-generation-state-manager.util";
|
|
106
60
|
export type { GenerationState } from "./fal-generation-state-manager.util";
|
|
107
61
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Parser Utilities
|
|
3
|
-
* Re-exports all parser utilities from submodules
|
|
2
|
+
* Parser Utilities
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
export * from './json-parsers.util';
|
|
7
|
-
export * from './object-validators.util';
|
|
8
|
-
export * from './value-parsers.util';
|
|
9
6
|
export * from './object-transformers.util';
|
|
@@ -43,22 +43,6 @@ export interface AiProviderInitModuleConfig {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Creates an AI Provider initialization module for use with createAppInitializer
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { createAppInitializer } from "@umituz/react-native-design-system";
|
|
50
|
-
* import { createFirebaseInitModule } from "@umituz/react-native-firebase";
|
|
51
|
-
* import { createAiProviderInitModule } from "@umituz/react-native-ai-fal-provider";
|
|
52
|
-
*
|
|
53
|
-
* export const initializeApp = createAppInitializer({
|
|
54
|
-
* modules: [
|
|
55
|
-
* createFirebaseInitModule(),
|
|
56
|
-
* createAiProviderInitModule({
|
|
57
|
-
* getApiKey: () => getFalApiKey(),
|
|
58
|
-
* }),
|
|
59
|
-
* ],
|
|
60
|
-
* });
|
|
61
|
-
* ```
|
|
62
46
|
*/
|
|
63
47
|
export function createAiProviderInitModule(
|
|
64
48
|
config: AiProviderInitModuleConfig
|
|
@@ -82,10 +66,8 @@ export function createAiProviderInitModule(
|
|
|
82
66
|
return Promise.resolve(false);
|
|
83
67
|
}
|
|
84
68
|
|
|
85
|
-
// Initialize FAL provider
|
|
86
69
|
falProvider.initialize({ apiKey });
|
|
87
70
|
|
|
88
|
-
// Register with providerRegistry automatically
|
|
89
71
|
if (!providerRegistry.hasProvider(falProvider.providerId)) {
|
|
90
72
|
providerRegistry.register(falProvider);
|
|
91
73
|
}
|
|
@@ -102,41 +84,3 @@ export function createAiProviderInitModule(
|
|
|
102
84
|
},
|
|
103
85
|
};
|
|
104
86
|
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Initializes FAL provider and registers it with providerRegistry in one call.
|
|
108
|
-
* Use this for simple synchronous registration at app startup.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* // registerProviders.ts - that's all you need!
|
|
113
|
-
* import { initializeFalProvider } from "@umituz/react-native-ai-fal-provider";
|
|
114
|
-
* import { getFalApiKey } from "@/core/utils/env";
|
|
115
|
-
*
|
|
116
|
-
* export function registerProviders(): void {
|
|
117
|
-
* initializeFalProvider({ apiKey: getFalApiKey() });
|
|
118
|
-
* }
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
export function initializeFalProvider(config: {
|
|
122
|
-
apiKey: string | undefined;
|
|
123
|
-
}): boolean {
|
|
124
|
-
try {
|
|
125
|
-
const { apiKey } = config;
|
|
126
|
-
|
|
127
|
-
if (!apiKey) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
falProvider.initialize({ apiKey });
|
|
132
|
-
|
|
133
|
-
if (!providerRegistry.hasProvider(falProvider.providerId)) {
|
|
134
|
-
providerRegistry.register(falProvider);
|
|
135
|
-
}
|
|
136
|
-
providerRegistry.setActiveProvider(falProvider.providerId);
|
|
137
|
-
|
|
138
|
-
return true;
|
|
139
|
-
} catch {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Direct FAL Provider Initialization
|
|
3
|
+
* Synchronous initialization for simple app startup
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { providerRegistry } from '@umituz/react-native-ai-generation-content';
|
|
7
|
+
import { falProvider } from '../infrastructure/services';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Initializes FAL provider and registers it with providerRegistry in one call.
|
|
11
|
+
* Use this for simple synchronous registration at app startup.
|
|
12
|
+
*/
|
|
13
|
+
export function initializeFalProvider(config: {
|
|
14
|
+
apiKey: string | undefined;
|
|
15
|
+
}): boolean {
|
|
16
|
+
try {
|
|
17
|
+
const { apiKey } = config;
|
|
18
|
+
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
falProvider.initialize({ apiKey });
|
|
24
|
+
|
|
25
|
+
if (!providerRegistry.hasProvider(falProvider.providerId)) {
|
|
26
|
+
providerRegistry.register(falProvider);
|
|
27
|
+
}
|
|
28
|
+
providerRegistry.setActiveProvider(falProvider.providerId);
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -3,7 +3,4 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export { useFalGeneration } from "./use-fal-generation";
|
|
6
|
-
export { useModels } from "./use-models";
|
|
7
|
-
|
|
8
6
|
export type { UseFalGenerationOptions, UseFalGenerationResult } from "./use-fal-generation";
|
|
9
|
-
export type { UseModelsProps, UseModelsReturn } from "./use-models";
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FAL Models Service - Model utilities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { FalModelConfig } from "../../domain/types/fal-model-config.types";
|
|
6
|
-
|
|
7
|
-
export type { FalModelConfig };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Sort models by order and name
|
|
11
|
-
*/
|
|
12
|
-
export function sortModels(models: FalModelConfig[]): FalModelConfig[] {
|
|
13
|
-
return [...models].sort((a, b) => {
|
|
14
|
-
if (a.order !== b.order) {
|
|
15
|
-
return (a.order ?? 0) - (b.order ?? 0);
|
|
16
|
-
}
|
|
17
|
-
return a.name.localeCompare(b.name);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Find model by ID
|
|
23
|
-
*/
|
|
24
|
-
export function findModelById(id: string, models: FalModelConfig[]): FalModelConfig | undefined {
|
|
25
|
-
return models.find((m) => m.id === id);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get default model from a list
|
|
30
|
-
*/
|
|
31
|
-
export function getDefaultModel(models: FalModelConfig[]): FalModelConfig | undefined {
|
|
32
|
-
if (models.length === 0) return undefined;
|
|
33
|
-
return models.find((m) => m.isDefault) ?? models[0];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const falModelsService = {
|
|
37
|
-
sortModels,
|
|
38
|
-
findById: findModelById,
|
|
39
|
-
getDefaultModel,
|
|
40
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base Input Builders
|
|
3
|
-
* Core builder functions for FAL API
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { formatImageDataUri } from "./image-helpers.util";
|
|
7
|
-
|
|
8
|
-
export function buildSingleImageInput(
|
|
9
|
-
base64: string,
|
|
10
|
-
extraParams?: Record<string, unknown>,
|
|
11
|
-
): Record<string, unknown> {
|
|
12
|
-
return {
|
|
13
|
-
image_url: formatImageDataUri(base64),
|
|
14
|
-
...extraParams,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function buildDualImageInput(
|
|
19
|
-
sourceBase64: string,
|
|
20
|
-
targetBase64: string,
|
|
21
|
-
extraParams?: Record<string, unknown>,
|
|
22
|
-
): Record<string, unknown> {
|
|
23
|
-
return {
|
|
24
|
-
image_url: formatImageDataUri(sourceBase64),
|
|
25
|
-
second_image_url: formatImageDataUri(targetBase64),
|
|
26
|
-
...extraParams,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array Filter Utilities
|
|
3
|
-
* Filter operations for arrays of objects
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Filter array by property value
|
|
8
|
-
*/
|
|
9
|
-
export function filterByProperty<T>(
|
|
10
|
-
items: readonly T[],
|
|
11
|
-
property: keyof T,
|
|
12
|
-
value: unknown
|
|
13
|
-
): T[] {
|
|
14
|
-
return items.filter((item) => item[property] === value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Filter array by predicate function
|
|
19
|
-
*/
|
|
20
|
-
export function filterByPredicate<T>(
|
|
21
|
-
items: readonly T[],
|
|
22
|
-
predicate: (item: T) => boolean
|
|
23
|
-
): T[] {
|
|
24
|
-
return items.filter(predicate);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Filter array by time range (timestamp property)
|
|
29
|
-
* Validates that the timestamp property is actually a number before comparison
|
|
30
|
-
*/
|
|
31
|
-
export function filterByTimeRange<T>(
|
|
32
|
-
items: readonly T[],
|
|
33
|
-
timestampProperty: keyof T,
|
|
34
|
-
startTime: number,
|
|
35
|
-
endTime: number
|
|
36
|
-
): T[] {
|
|
37
|
-
return items.filter((item) => {
|
|
38
|
-
const timestamp = item[timestampProperty];
|
|
39
|
-
|
|
40
|
-
// Type guard: ensure timestamp is actually a number
|
|
41
|
-
if (typeof timestamp !== 'number') {
|
|
42
|
-
console.warn(
|
|
43
|
-
`[array-filters] Skipping item with non-numeric timestamp property '${String(timestampProperty)}':`,
|
|
44
|
-
typeof timestamp
|
|
45
|
-
);
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return timestamp >= startTime && timestamp <= endTime;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Filter array by multiple property values (OR logic)
|
|
55
|
-
*/
|
|
56
|
-
export function filterByAnyProperty<T>(
|
|
57
|
-
items: readonly T[],
|
|
58
|
-
property: keyof T,
|
|
59
|
-
values: readonly unknown[]
|
|
60
|
-
): T[] {
|
|
61
|
-
const valueSet = new Set(values);
|
|
62
|
-
return items.filter((item) => valueSet.has(item[property]));
|
|
63
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array Sorter Utilities
|
|
3
|
-
* Sort operations for arrays of objects
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Sort array by date property (descending - newest first)
|
|
8
|
-
* Invalid dates are sorted to the end
|
|
9
|
-
*/
|
|
10
|
-
export function sortByDateDescending<T>(
|
|
11
|
-
items: readonly T[],
|
|
12
|
-
dateProperty: keyof T
|
|
13
|
-
): T[] {
|
|
14
|
-
return [...items].sort((a, b) => {
|
|
15
|
-
const timeA = new Date(a[dateProperty] as unknown as string).getTime();
|
|
16
|
-
const timeB = new Date(b[dateProperty] as unknown as string).getTime();
|
|
17
|
-
|
|
18
|
-
// Handle invalid dates - NaN should sort to end
|
|
19
|
-
if (isNaN(timeA) && isNaN(timeB)) return 0;
|
|
20
|
-
if (isNaN(timeA)) return 1; // a goes to end
|
|
21
|
-
if (isNaN(timeB)) return -1; // b goes to end
|
|
22
|
-
|
|
23
|
-
return timeB - timeA;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Sort array by date property (ascending - oldest first)
|
|
29
|
-
* Invalid dates are sorted to the end
|
|
30
|
-
*/
|
|
31
|
-
export function sortByDateAscending<T>(
|
|
32
|
-
items: readonly T[],
|
|
33
|
-
dateProperty: keyof T
|
|
34
|
-
): T[] {
|
|
35
|
-
return [...items].sort((a, b) => {
|
|
36
|
-
const timeA = new Date(a[dateProperty] as unknown as string).getTime();
|
|
37
|
-
const timeB = new Date(b[dateProperty] as unknown as string).getTime();
|
|
38
|
-
|
|
39
|
-
// Handle invalid dates - NaN should sort to end
|
|
40
|
-
if (isNaN(timeA) && isNaN(timeB)) return 0;
|
|
41
|
-
if (isNaN(timeA)) return 1; // a goes to end
|
|
42
|
-
if (isNaN(timeB)) return -1; // b goes to end
|
|
43
|
-
|
|
44
|
-
return timeA - timeB;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Sort array by number property (descending)
|
|
50
|
-
* NaN and Infinity values are sorted to the end
|
|
51
|
-
*/
|
|
52
|
-
export function sortByNumberDescending<T>(
|
|
53
|
-
items: readonly T[],
|
|
54
|
-
numberProperty: keyof T
|
|
55
|
-
): T[] {
|
|
56
|
-
return [...items].sort((a, b) => {
|
|
57
|
-
const numA = a[numberProperty] as unknown as number;
|
|
58
|
-
const numB = b[numberProperty] as unknown as number;
|
|
59
|
-
|
|
60
|
-
// Handle NaN and Infinity
|
|
61
|
-
const isAValid = isFinite(numA);
|
|
62
|
-
const isBValid = isFinite(numB);
|
|
63
|
-
|
|
64
|
-
if (!isAValid && !isBValid) return 0;
|
|
65
|
-
if (!isAValid) return 1; // a goes to end
|
|
66
|
-
if (!isBValid) return -1; // b goes to end
|
|
67
|
-
|
|
68
|
-
return numB - numA;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Sort array by number property (ascending)
|
|
74
|
-
* NaN and Infinity values are sorted to the end
|
|
75
|
-
*/
|
|
76
|
-
export function sortByNumberAscending<T>(
|
|
77
|
-
items: readonly T[],
|
|
78
|
-
numberProperty: keyof T
|
|
79
|
-
): T[] {
|
|
80
|
-
return [...items].sort((a, b) => {
|
|
81
|
-
const numA = a[numberProperty] as unknown as number;
|
|
82
|
-
const numB = b[numberProperty] as unknown as number;
|
|
83
|
-
|
|
84
|
-
// Handle NaN and Infinity
|
|
85
|
-
const isAValid = isFinite(numA);
|
|
86
|
-
const isBValid = isFinite(numB);
|
|
87
|
-
|
|
88
|
-
if (!isAValid && !isBValid) return 0;
|
|
89
|
-
if (!isAValid) return 1; // a goes to end
|
|
90
|
-
if (!isBValid) return -1; // b goes to end
|
|
91
|
-
|
|
92
|
-
return numA - numB;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Date Formatting Utilities
|
|
3
|
-
* Functions for formatting dates and times
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Validate that a date is valid
|
|
8
|
-
*/
|
|
9
|
-
function isValidDate(date: Date): boolean {
|
|
10
|
-
return date instanceof Date && !isNaN(date.getTime());
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Format date to locale string
|
|
15
|
-
* @throws {Error} if date is invalid
|
|
16
|
-
*/
|
|
17
|
-
export function formatDate(date: Date | string, locale: string = "en-US"): string {
|
|
18
|
-
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
19
|
-
|
|
20
|
-
if (!isValidDate(dateObj)) {
|
|
21
|
-
const dateStr = typeof date === "string" ? date : date.toISOString();
|
|
22
|
-
throw new Error(`Invalid date: ${dateStr}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return dateObj.toLocaleDateString(locale, {
|
|
26
|
-
year: "numeric",
|
|
27
|
-
month: "short",
|
|
28
|
-
day: "numeric",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FAL Error Categorizer - Classifies FAL AI errors
|
|
3
|
-
*
|
|
4
|
-
* This module re-exports error categorization functions from the unified
|
|
5
|
-
* fal-error-handler.util module for backward compatibility.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export { categorizeFalError } from "./fal-error-handler.util";
|
|
9
|
-
export type { FalErrorCategory } from "../../domain/entities/error.types";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Job Metadata Utilities
|
|
3
|
-
* Exports all job metadata functionality
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export type { FalJobMetadata } from "./job-metadata.types";
|
|
7
|
-
export {
|
|
8
|
-
createJobMetadata,
|
|
9
|
-
updateJobMetadata,
|
|
10
|
-
isJobCompleted,
|
|
11
|
-
isJobRunning,
|
|
12
|
-
isJobStale,
|
|
13
|
-
} from "./job-metadata-lifecycle.util";
|
|
14
|
-
export {
|
|
15
|
-
getJobDuration,
|
|
16
|
-
formatJobDuration,
|
|
17
|
-
calculateJobProgress,
|
|
18
|
-
} from "./job-metadata-format.util";
|
|
19
|
-
export {
|
|
20
|
-
serializeJobMetadata,
|
|
21
|
-
deserializeJobMetadata,
|
|
22
|
-
filterValidJobs,
|
|
23
|
-
sortJobsByCreation,
|
|
24
|
-
getActiveJobs,
|
|
25
|
-
getCompletedJobs,
|
|
26
|
-
} from "./job-metadata-queries.util";
|