@uploadista/react-native-bare 0.0.3
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/LICENSE +21 -0
- package/README.md +440 -0
- package/package.json +31 -0
- package/src/index.ts +16 -0
- package/src/services/abort-controller-factory.ts +33 -0
- package/src/services/base64-service.ts +29 -0
- package/src/services/create-react-native-services.ts +76 -0
- package/src/services/file-reader-service.ts +144 -0
- package/src/services/http-client.ts +242 -0
- package/src/services/id-generation-service.ts +14 -0
- package/src/services/index.ts +15 -0
- package/src/services/native-file-system-provider.ts +247 -0
- package/src/services/platform-service.ts +71 -0
- package/src/services/storage-service.ts +62 -0
- package/src/services/websocket-factory.ts +62 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PlatformService, Timeout } from "@uploadista/client-core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React Native implementation of PlatformService
|
|
5
|
+
*/
|
|
6
|
+
export function createReactNativePlatformService(): PlatformService {
|
|
7
|
+
return {
|
|
8
|
+
setTimeout: (callback: () => void, ms: number | undefined) => {
|
|
9
|
+
return globalThis.setTimeout(callback, ms);
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
clearTimeout: (id: Timeout) => {
|
|
13
|
+
globalThis.clearTimeout(id as number);
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
isBrowser: () => {
|
|
17
|
+
return false;
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
isOnline: () => {
|
|
21
|
+
// React Native NetInfo would need to be imported separately
|
|
22
|
+
// For now, assume online
|
|
23
|
+
return true;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
isFileLike: (value: unknown) => {
|
|
27
|
+
// Check for blob-like interface or File-like object
|
|
28
|
+
return (
|
|
29
|
+
value !== null &&
|
|
30
|
+
typeof value === "object" &&
|
|
31
|
+
("uri" in value || "name" in value)
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
getFileName: (file: unknown) => {
|
|
36
|
+
if (file !== null && typeof file === "object" && "name" in file) {
|
|
37
|
+
return (file as Record<string, unknown>).name as string | undefined;
|
|
38
|
+
}
|
|
39
|
+
if (file !== null && typeof file === "object" && "uri" in file) {
|
|
40
|
+
const uri = (file as Record<string, unknown>).uri as string | undefined;
|
|
41
|
+
if (uri) {
|
|
42
|
+
return uri.split("/").pop();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
getFileType: (file: unknown) => {
|
|
49
|
+
if (file !== null && typeof file === "object" && "type" in file) {
|
|
50
|
+
return (file as Record<string, unknown>).type as string | undefined;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
getFileSize: (file: unknown) => {
|
|
56
|
+
if (file !== null && typeof file === "object" && "size" in file) {
|
|
57
|
+
return (file as Record<string, unknown>).size as number | undefined;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
getFileLastModified: (file: unknown) => {
|
|
63
|
+
if (file !== null && typeof file === "object" && "lastModified" in file) {
|
|
64
|
+
return (file as Record<string, unknown>).lastModified as
|
|
65
|
+
| number
|
|
66
|
+
| undefined;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
import type { StorageService } from "@uploadista/client-core";
|
|
3
|
+
/**
|
|
4
|
+
* Expo-specific implementation of StorageService using AsyncStorage
|
|
5
|
+
* AsyncStorage is provided as an optional peer dependency and must be installed separately
|
|
6
|
+
*/
|
|
7
|
+
export function createAsyncStorageService(): StorageService {
|
|
8
|
+
const findEntries = async (
|
|
9
|
+
prefix: string,
|
|
10
|
+
): Promise<Record<string, string>> => {
|
|
11
|
+
const results: Record<string, string> = {};
|
|
12
|
+
|
|
13
|
+
const keys = await AsyncStorage.getAllKeys();
|
|
14
|
+
for (const key in keys) {
|
|
15
|
+
if (key.startsWith(prefix)) {
|
|
16
|
+
const item = await AsyncStorage.getItem(key);
|
|
17
|
+
if (item) {
|
|
18
|
+
results[key] = item;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return results;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
async getItem(key: string): Promise<string | null> {
|
|
28
|
+
try {
|
|
29
|
+
return await AsyncStorage.getItem(key);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(`AsyncStorage getItem error for key ${key}:`, error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
async setItem(key: string, value: string): Promise<void> {
|
|
37
|
+
try {
|
|
38
|
+
await AsyncStorage.setItem(key, value);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error(`AsyncStorage setItem error for key ${key}:`, error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
async removeItem(key: string): Promise<void> {
|
|
46
|
+
try {
|
|
47
|
+
await AsyncStorage.removeItem(key);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`AsyncStorage removeItem error for key ${key}:`, error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async findAll(): Promise<Record<string, string>> {
|
|
55
|
+
return findEntries("");
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
async find(prefix: string): Promise<Record<string, string>> {
|
|
59
|
+
return findEntries(prefix);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WebSocketFactory,
|
|
3
|
+
WebSocketLike,
|
|
4
|
+
} from "@uploadista/client-core";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* React Native WebSocket implementation that wraps native WebSocket
|
|
8
|
+
* React Native provides a WebSocket API that is compatible with the browser WebSocket API
|
|
9
|
+
*/
|
|
10
|
+
class ReactNativeWebSocket implements WebSocketLike {
|
|
11
|
+
readonly CONNECTING = 0;
|
|
12
|
+
readonly OPEN = 1;
|
|
13
|
+
readonly CLOSING = 2;
|
|
14
|
+
readonly CLOSED = 3;
|
|
15
|
+
|
|
16
|
+
readonly readyState: number;
|
|
17
|
+
onopen: ((event: unknown) => void) | null = null;
|
|
18
|
+
onclose: ((event: unknown) => void) | null = null;
|
|
19
|
+
onerror: ((event: unknown) => void) | null = null;
|
|
20
|
+
onmessage: ((event: unknown) => void) | null = null;
|
|
21
|
+
|
|
22
|
+
private native: WebSocket;
|
|
23
|
+
|
|
24
|
+
constructor(url: string) {
|
|
25
|
+
this.native = new WebSocket(url);
|
|
26
|
+
this.readyState = this.native.readyState;
|
|
27
|
+
|
|
28
|
+
// Proxy event handlers
|
|
29
|
+
this.native.onopen = (event) => {
|
|
30
|
+
this.readyState = this.native.readyState;
|
|
31
|
+
this.onopen?.(event);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.native.onclose = (event) => {
|
|
35
|
+
this.readyState = this.native.readyState;
|
|
36
|
+
this.onclose?.(event);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.native.onerror = (event) => {
|
|
40
|
+
this.onerror?.(event);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.native.onmessage = (event) => {
|
|
44
|
+
this.onmessage?.(event);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
send(data: string | Uint8Array): void {
|
|
49
|
+
this.native.send(data);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
close(code?: number, reason?: string): void {
|
|
53
|
+
this.native.close(code, reason);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Factory for creating React Native WebSocket connections
|
|
59
|
+
*/
|
|
60
|
+
export const createReactNativeWebSocketFactory = (): WebSocketFactory => ({
|
|
61
|
+
create: (url: string): WebSocketLike => new ReactNativeWebSocket(url),
|
|
62
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@uploadista/typescript-config/react-library.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": "./",
|
|
5
|
+
"paths": {
|
|
6
|
+
"@/*": ["./src/*"]
|
|
7
|
+
},
|
|
8
|
+
"typeRoots": ["../../node_modules/@types"],
|
|
9
|
+
"types": [],
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts"],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"node_modules",
|
|
16
|
+
"dist",
|
|
17
|
+
"**/__tests__/**",
|
|
18
|
+
"**/*.test.ts",
|
|
19
|
+
"**/*.spec.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|