@umituz/react-native-design-system 4.27.18 → 4.27.19
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-design-system",
|
|
3
|
-
"version": "4.27.
|
|
3
|
+
"version": "4.27.19",
|
|
4
4
|
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities - TanStack persistence and expo-image-manipulator now lazy loaded",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
package/src/core/index.ts
CHANGED
|
@@ -21,3 +21,6 @@ export type { PermissionMethod, PermissionStatus, PermissionResult, PermissionHa
|
|
|
21
21
|
export { createRepositoryKeyFactory } from './repositories/domain/RepositoryKeyFactory';
|
|
22
22
|
export { mergeRepositoryOptions, getCacheOptions, normalizeListParams, createRepositoryLogger } from './repositories/domain/RepositoryUtils';
|
|
23
23
|
export type { RepositoryOptions, ListParams, CreateParams, UpdateParams, QueryKeyFactory } from './repositories/domain/types';
|
|
24
|
+
|
|
25
|
+
// Shared utilities (for new code)
|
|
26
|
+
export * from './shared';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Async Service Base - Shared Utilities
|
|
3
|
+
*
|
|
4
|
+
* Base class for services with automatic error handling.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Result } from './Result';
|
|
8
|
+
import { ResultHelper } from './Result';
|
|
9
|
+
|
|
10
|
+
export abstract class AsyncService {
|
|
11
|
+
protected readonly serviceName: string;
|
|
12
|
+
|
|
13
|
+
constructor(serviceName: string) {
|
|
14
|
+
this.serviceName = serviceName;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Execute async operation with automatic error handling
|
|
19
|
+
*/
|
|
20
|
+
protected async execute<T>(
|
|
21
|
+
operation: string,
|
|
22
|
+
fn: () => Promise<T>
|
|
23
|
+
): Promise<Result<T>> {
|
|
24
|
+
try {
|
|
25
|
+
const data = await fn();
|
|
26
|
+
return ResultHelper.ok(data);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
this.logError(operation, error);
|
|
29
|
+
return ResultHelper.fail(error instanceof Error ? error : new Error(String(error)));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Log error in development mode
|
|
35
|
+
*/
|
|
36
|
+
protected logError(operation: string, error: unknown): void {
|
|
37
|
+
if (__DEV__) {
|
|
38
|
+
console.error(`[${this.serviceName}] ${operation}:`, error);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected logWarning(message: string): void {
|
|
43
|
+
if (__DEV__) {
|
|
44
|
+
console.warn(`[${this.serviceName}] ${message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected logInfo(message: string): void {
|
|
49
|
+
if (__DEV__) {
|
|
50
|
+
console.log(`[${this.serviceName}] ${message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Type - Shared Utilities
|
|
3
|
+
*
|
|
4
|
+
* Functional error handling without exceptions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type Result<T, E = Error> =
|
|
8
|
+
| { success: true; data: T; error?: never }
|
|
9
|
+
| { success: false; data?: never; error: E };
|
|
10
|
+
|
|
11
|
+
export const ResultHelper = {
|
|
12
|
+
ok: <T>(data: T): Result<T> => ({ success: true, data }),
|
|
13
|
+
|
|
14
|
+
fail: <E = Error>(error: E): Result<never, E> => ({
|
|
15
|
+
success: false,
|
|
16
|
+
error,
|
|
17
|
+
}),
|
|
18
|
+
|
|
19
|
+
fromAsync: async <T>(
|
|
20
|
+
fn: () => Promise<T>
|
|
21
|
+
): Promise<Result<T, Error>> => {
|
|
22
|
+
try {
|
|
23
|
+
return ResultHelper.ok(await fn());
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return ResultHelper.fail(error instanceof Error ? error : new Error(String(error)));
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
map: <T, U>(
|
|
30
|
+
result: Result<T>,
|
|
31
|
+
fn: (data: T) => U
|
|
32
|
+
): Result<U> =>
|
|
33
|
+
result.success ? ResultHelper.ok(fn(result.data)) : ResultHelper.fail(result.error),
|
|
34
|
+
};
|