@unvired/react-native-unvired-sdk 0.0.12 → 0.0.14
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/BuildNo.txt +1 -1
- package/README.md +884 -255
- package/dist/database/Database.d.ts +71 -0
- package/dist/database/Database.js +156 -0
- package/dist/database/DatabaseManager.d.ts +12 -0
- package/dist/database/DatabaseManager.js +18 -0
- package/dist/database/index.d.ts +6 -0
- package/dist/database/index.js +5 -0
- package/dist/database/services/DatabaseNative.d.ts +8 -0
- package/dist/database/services/DatabaseNative.js +149 -0
- package/dist/database/services/DatabaseWeb.d.ts +13 -0
- package/dist/database/services/DatabaseWeb.js +138 -0
- package/dist/database/types.d.ts +94 -0
- package/dist/database/types.js +4 -0
- package/dist/device-info/BaseDeviceInfo.d.ts +39 -0
- package/dist/device-info/BaseDeviceInfo.js +116 -0
- package/dist/device-info/DeviceInfo.d.ts +9 -0
- package/dist/device-info/DeviceInfo.js +11 -0
- package/dist/device-info/DeviceInfo.types.d.ts +11 -0
- package/dist/device-info/DeviceInfo.types.js +3 -0
- package/dist/device-info/index.d.ts +3 -0
- package/dist/device-info/index.js +3 -0
- package/dist/file-system/BaseFileSystem.d.ts +61 -0
- package/dist/file-system/BaseFileSystem.js +164 -0
- package/dist/file-system/FileSystem.d.ts +9 -0
- package/dist/file-system/FileSystem.js +11 -0
- package/dist/file-system/FileSystem.types.d.ts +11 -0
- package/dist/file-system/FileSystem.types.js +3 -0
- package/dist/file-system/index.d.ts +3 -0
- package/dist/file-system/index.js +3 -0
- package/dist/file-system/services/FileSystemNative.d.ts +17 -0
- package/dist/file-system/services/FileSystemNative.js +73 -0
- package/dist/file-system/services/FileSystemWeb.d.ts +16 -0
- package/dist/file-system/services/FileSystemWeb.js +41 -0
- package/dist/local-storage/index.d.ts +1 -0
- package/dist/local-storage/index.js +2 -0
- package/dist/local-storage/localStorage.d.ts +49 -0
- package/dist/local-storage/localStorage.js +128 -0
- package/dist/local-storage/services/StorageNative.d.ts +10 -0
- package/dist/local-storage/services/StorageNative.js +27 -0
- package/dist/local-storage/services/StorageWeb.d.ts +10 -0
- package/dist/local-storage/services/StorageWeb.js +26 -0
- package/dist/logger/{Logger.js → index.js} +1 -4
- package/dist/main.d.ts +11 -0
- package/dist/main.js +24 -0
- package/dist/push-notification/BasePushNotification.d.ts +52 -0
- package/dist/push-notification/BasePushNotification.js +180 -0
- package/dist/push-notification/PushNotification.d.ts +9 -0
- package/dist/push-notification/PushNotification.js +11 -0
- package/dist/push-notification/PushNotification.types.d.ts +12 -0
- package/dist/push-notification/PushNotification.types.js +3 -0
- package/dist/push-notification/index.d.ts +3 -0
- package/dist/push-notification/index.js +3 -0
- package/example/USAGE_EXAMPLE.ts +167 -0
- package/package.json +17 -6
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- /package/dist/logger/{Logger.d.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IDeviceInfo } from './DeviceInfo.types';
|
|
2
|
+
/**
|
|
3
|
+
* Base Device Information Class
|
|
4
|
+
* Handles device information retrieval for React Native
|
|
5
|
+
*/
|
|
6
|
+
export declare class BaseDeviceInfo {
|
|
7
|
+
private static cachedDeviceInfo;
|
|
8
|
+
/**
|
|
9
|
+
* Get comprehensive device information (async)
|
|
10
|
+
* Call this once during app initialization to populate cache
|
|
11
|
+
*/
|
|
12
|
+
static getDeviceInfo(): Promise<IDeviceInfo>;
|
|
13
|
+
/**
|
|
14
|
+
* Get device information synchronously (returns cached data)
|
|
15
|
+
* Returns loading state if not yet initialized
|
|
16
|
+
* Call getDeviceInfo() first to populate cache
|
|
17
|
+
*/
|
|
18
|
+
static getDeviceInfoSync(): IDeviceInfo;
|
|
19
|
+
/**
|
|
20
|
+
* Get platform name
|
|
21
|
+
*/
|
|
22
|
+
static getPlatform(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get frontend type
|
|
25
|
+
*/
|
|
26
|
+
static getFrontendType(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Check if device is a tablet
|
|
29
|
+
*/
|
|
30
|
+
static isTablet(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Get app version
|
|
33
|
+
*/
|
|
34
|
+
static getAppVersion(): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Get build number
|
|
37
|
+
*/
|
|
38
|
+
static getBuildNumber(): Promise<string>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// BaseDeviceInfo.ts
|
|
2
|
+
// Base device information implementation
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import DeviceInfo from 'react-native-device-info';
|
|
5
|
+
/**
|
|
6
|
+
* Base Device Information Class
|
|
7
|
+
* Handles device information retrieval for React Native
|
|
8
|
+
*/
|
|
9
|
+
export class BaseDeviceInfo {
|
|
10
|
+
/**
|
|
11
|
+
* Get comprehensive device information (async)
|
|
12
|
+
* Call this once during app initialization to populate cache
|
|
13
|
+
*/
|
|
14
|
+
static async getDeviceInfo() {
|
|
15
|
+
if (this.cachedDeviceInfo) {
|
|
16
|
+
return this.cachedDeviceInfo;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const deviceInfo = {
|
|
20
|
+
platform: Platform.OS,
|
|
21
|
+
model: await DeviceInfo.getModel(),
|
|
22
|
+
version: Platform.Version.toString(),
|
|
23
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
24
|
+
manufacturer: await DeviceInfo.getManufacturer(),
|
|
25
|
+
uuid: await DeviceInfo.getUniqueId(),
|
|
26
|
+
};
|
|
27
|
+
this.cachedDeviceInfo = deviceInfo;
|
|
28
|
+
return deviceInfo;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Error getting device info:', error);
|
|
32
|
+
const fallback = {
|
|
33
|
+
platform: Platform.OS,
|
|
34
|
+
model: 'Unknown',
|
|
35
|
+
version: Platform.Version.toString(),
|
|
36
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
37
|
+
};
|
|
38
|
+
this.cachedDeviceInfo = fallback;
|
|
39
|
+
return fallback;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get device information synchronously (returns cached data)
|
|
44
|
+
* Returns loading state if not yet initialized
|
|
45
|
+
* Call getDeviceInfo() first to populate cache
|
|
46
|
+
*/
|
|
47
|
+
static getDeviceInfoSync() {
|
|
48
|
+
if (this.cachedDeviceInfo) {
|
|
49
|
+
return this.cachedDeviceInfo;
|
|
50
|
+
}
|
|
51
|
+
// Return immediate fallback while async initialization happens
|
|
52
|
+
return {
|
|
53
|
+
platform: Platform.OS,
|
|
54
|
+
model: 'Loading...',
|
|
55
|
+
version: Platform.Version.toString(),
|
|
56
|
+
isMobile: Platform.OS === 'ios' || Platform.OS === 'android',
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get platform name
|
|
61
|
+
*/
|
|
62
|
+
static getPlatform() {
|
|
63
|
+
return Platform.OS;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get frontend type
|
|
67
|
+
*/
|
|
68
|
+
static getFrontendType() {
|
|
69
|
+
if (Platform.OS === 'ios') {
|
|
70
|
+
return 'APPLE_PHONE';
|
|
71
|
+
}
|
|
72
|
+
else if (Platform.OS === 'android') {
|
|
73
|
+
return 'ANDROID_PHONE';
|
|
74
|
+
}
|
|
75
|
+
else if (Platform.OS === 'windows') {
|
|
76
|
+
return 'WINDOWS_PHONE';
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return 'UNKNOWN';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if device is a tablet
|
|
84
|
+
*/
|
|
85
|
+
static async isTablet() {
|
|
86
|
+
try {
|
|
87
|
+
return await DeviceInfo.isTablet();
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get app version
|
|
95
|
+
*/
|
|
96
|
+
static async getAppVersion() {
|
|
97
|
+
try {
|
|
98
|
+
return await DeviceInfo.getVersion();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return '1.0.0';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get build number
|
|
106
|
+
*/
|
|
107
|
+
static async getBuildNumber() {
|
|
108
|
+
try {
|
|
109
|
+
return await DeviceInfo.getBuildNumber();
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
return '1';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
BaseDeviceInfo.cachedDeviceInfo = null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// DeviceInfo.ts
|
|
2
|
+
// Main device info export
|
|
3
|
+
import { BaseDeviceInfo } from './BaseDeviceInfo';
|
|
4
|
+
/**
|
|
5
|
+
* DeviceInfo class
|
|
6
|
+
* Extends BaseDeviceInfo
|
|
7
|
+
*/
|
|
8
|
+
export class DeviceInfo extends BaseDeviceInfo {
|
|
9
|
+
}
|
|
10
|
+
// Default export
|
|
11
|
+
export default DeviceInfo;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IFileEntry } from './FileSystem.types';
|
|
2
|
+
/**
|
|
3
|
+
* Base File System Class
|
|
4
|
+
* Handles file system operations for React Native
|
|
5
|
+
* - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
|
|
6
|
+
* - Web: Limited functionality (not supported)
|
|
7
|
+
*/
|
|
8
|
+
export declare class BaseFileSystem {
|
|
9
|
+
/**
|
|
10
|
+
* Get document directory path
|
|
11
|
+
*/
|
|
12
|
+
static getDocumentDirectory(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve local file system URL
|
|
15
|
+
*/
|
|
16
|
+
static resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
17
|
+
/**
|
|
18
|
+
* Get folder based on user ID
|
|
19
|
+
*/
|
|
20
|
+
static getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Delete user folder
|
|
23
|
+
*/
|
|
24
|
+
static deleteUserFolder(userId: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Create directory
|
|
27
|
+
*/
|
|
28
|
+
static createDirectory(path: string): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Read file content
|
|
31
|
+
*/
|
|
32
|
+
static readFile(path: string, encoding?: string): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Write file content
|
|
35
|
+
*/
|
|
36
|
+
static writeFile(path: string, content: string, encoding?: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Delete file
|
|
39
|
+
*/
|
|
40
|
+
static deleteFile(path: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if file exists
|
|
43
|
+
*/
|
|
44
|
+
static exists(path: string): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Get file info
|
|
47
|
+
*/
|
|
48
|
+
static stat(path: string): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* List directory contents
|
|
51
|
+
*/
|
|
52
|
+
static readDir(path: string): Promise<any[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Copy file
|
|
55
|
+
*/
|
|
56
|
+
static copyFile(source: string, destination: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Move file
|
|
59
|
+
*/
|
|
60
|
+
static moveFile(source: string, destination: string): Promise<void>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// BaseFileSystem.ts
|
|
2
|
+
// Base file system implementation
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { FileSystemNative } from './services/FileSystemNative';
|
|
5
|
+
import { FileSystemWeb } from './services/FileSystemWeb';
|
|
6
|
+
// Select file system implementation based on platform
|
|
7
|
+
const fsImpl = Platform.OS === 'web' ? new FileSystemWeb() : new FileSystemNative();
|
|
8
|
+
/**
|
|
9
|
+
* Base File System Class
|
|
10
|
+
* Handles file system operations for React Native
|
|
11
|
+
* - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
|
|
12
|
+
* - Web: Limited functionality (not supported)
|
|
13
|
+
*/
|
|
14
|
+
export class BaseFileSystem {
|
|
15
|
+
/**
|
|
16
|
+
* Get document directory path
|
|
17
|
+
*/
|
|
18
|
+
static getDocumentDirectory() {
|
|
19
|
+
return fsImpl.getDocumentDirectory();
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolve local file system URL
|
|
23
|
+
*/
|
|
24
|
+
static async resolveLocalFileSystemURL(url) {
|
|
25
|
+
try {
|
|
26
|
+
return await fsImpl.resolveLocalFileSystemURL(url);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error('Error resolving file system URL:', error);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get folder based on user ID
|
|
35
|
+
*/
|
|
36
|
+
static async getFolderBasedOnUserId(userId) {
|
|
37
|
+
try {
|
|
38
|
+
return await fsImpl.getFolderBasedOnUserId(userId);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error('Error getting user folder:', error);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Delete user folder
|
|
47
|
+
*/
|
|
48
|
+
static async deleteUserFolder(userId) {
|
|
49
|
+
try {
|
|
50
|
+
await fsImpl.deleteUserFolder(userId);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('Error deleting user folder:', error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create directory
|
|
59
|
+
*/
|
|
60
|
+
static async createDirectory(path) {
|
|
61
|
+
try {
|
|
62
|
+
await fsImpl.createDirectory(path);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('Error creating directory:', error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read file content
|
|
71
|
+
*/
|
|
72
|
+
static async readFile(path, encoding = 'utf8') {
|
|
73
|
+
try {
|
|
74
|
+
return await fsImpl.readFile(path, encoding);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('Error reading file:', error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Write file content
|
|
83
|
+
*/
|
|
84
|
+
static async writeFile(path, content, encoding = 'utf8') {
|
|
85
|
+
try {
|
|
86
|
+
await fsImpl.writeFile(path, content, encoding);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error('Error writing file:', error);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Delete file
|
|
95
|
+
*/
|
|
96
|
+
static async deleteFile(path) {
|
|
97
|
+
try {
|
|
98
|
+
await fsImpl.deleteFile(path);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.error('Error deleting file:', error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if file exists
|
|
107
|
+
*/
|
|
108
|
+
static async exists(path) {
|
|
109
|
+
try {
|
|
110
|
+
return await fsImpl.exists(path);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get file info
|
|
118
|
+
*/
|
|
119
|
+
static async stat(path) {
|
|
120
|
+
try {
|
|
121
|
+
return await fsImpl.stat(path);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error('Error getting file stats:', error);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* List directory contents
|
|
130
|
+
*/
|
|
131
|
+
static async readDir(path) {
|
|
132
|
+
try {
|
|
133
|
+
return await fsImpl.readDir(path);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.error('Error reading directory:', error);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Copy file
|
|
142
|
+
*/
|
|
143
|
+
static async copyFile(source, destination) {
|
|
144
|
+
try {
|
|
145
|
+
await fsImpl.copyFile(source, destination);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error('Error copying file:', error);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Move file
|
|
154
|
+
*/
|
|
155
|
+
static async moveFile(source, destination) {
|
|
156
|
+
try {
|
|
157
|
+
await fsImpl.moveFile(source, destination);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error('Error moving file:', error);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// FileSystem.ts
|
|
2
|
+
// Main file system export
|
|
3
|
+
import { BaseFileSystem } from './BaseFileSystem';
|
|
4
|
+
/**
|
|
5
|
+
* FileSystem class
|
|
6
|
+
* Extends BaseFileSystem
|
|
7
|
+
*/
|
|
8
|
+
export class FileSystem extends BaseFileSystem {
|
|
9
|
+
}
|
|
10
|
+
// Default export
|
|
11
|
+
export default FileSystem;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as RNFS from '@dr.pogodin/react-native-fs';
|
|
2
|
+
import { IFileEntry } from '../FileSystem.types';
|
|
3
|
+
export declare class FileSystemNative {
|
|
4
|
+
getDocumentDirectory(): string;
|
|
5
|
+
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
6
|
+
getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
7
|
+
deleteUserFolder(userId: string): Promise<void>;
|
|
8
|
+
createDirectory(path: string): Promise<void>;
|
|
9
|
+
readFile(path: string, encoding?: RNFS.EncodingT): Promise<string>;
|
|
10
|
+
writeFile(path: string, content: string, encoding?: RNFS.EncodingT): Promise<void>;
|
|
11
|
+
deleteFile(path: string): Promise<void>;
|
|
12
|
+
exists(path: string): Promise<boolean>;
|
|
13
|
+
stat(path: string): Promise<RNFS.StatResultT>;
|
|
14
|
+
readDir(path: string): Promise<RNFS.ReadDirResItemT[]>;
|
|
15
|
+
copyFile(source: string, destination: string): Promise<void>;
|
|
16
|
+
moveFile(source: string, destination: string): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as RNFS from '@dr.pogodin/react-native-fs';
|
|
2
|
+
export class FileSystemNative {
|
|
3
|
+
getDocumentDirectory() {
|
|
4
|
+
return RNFS.DocumentDirectoryPath;
|
|
5
|
+
}
|
|
6
|
+
async resolveLocalFileSystemURL(url) {
|
|
7
|
+
let normalizedPath = url;
|
|
8
|
+
if (normalizedPath.startsWith('file://')) {
|
|
9
|
+
normalizedPath = normalizedPath.substring(7);
|
|
10
|
+
}
|
|
11
|
+
const exists = await RNFS.exists(normalizedPath);
|
|
12
|
+
if (!exists) {
|
|
13
|
+
throw new Error(`File or directory does not exist: ${normalizedPath}`);
|
|
14
|
+
}
|
|
15
|
+
const stat = await RNFS.stat(normalizedPath);
|
|
16
|
+
const fileName = stat.name || normalizedPath.split('/').pop() || 'unknown';
|
|
17
|
+
return {
|
|
18
|
+
isFile: stat.isFile(),
|
|
19
|
+
isDirectory: stat.isDirectory(),
|
|
20
|
+
name: fileName,
|
|
21
|
+
fullPath: stat.path,
|
|
22
|
+
nativeURL: `file://${stat.path}`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async getFolderBasedOnUserId(userId) {
|
|
26
|
+
const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
|
|
27
|
+
const exists = await RNFS.exists(userFolder);
|
|
28
|
+
if (!exists) {
|
|
29
|
+
await RNFS.mkdir(userFolder, { NSURLIsExcludedFromBackupKey: true });
|
|
30
|
+
}
|
|
31
|
+
return userFolder;
|
|
32
|
+
}
|
|
33
|
+
async deleteUserFolder(userId) {
|
|
34
|
+
const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
|
|
35
|
+
const exists = await RNFS.exists(userFolder);
|
|
36
|
+
if (exists) {
|
|
37
|
+
await RNFS.unlink(userFolder);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async createDirectory(path) {
|
|
41
|
+
const exists = await RNFS.exists(path);
|
|
42
|
+
if (!exists) {
|
|
43
|
+
await RNFS.mkdir(path);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async readFile(path, encoding = 'utf8') {
|
|
47
|
+
return await RNFS.readFile(path, encoding);
|
|
48
|
+
}
|
|
49
|
+
async writeFile(path, content, encoding = 'utf8') {
|
|
50
|
+
await RNFS.writeFile(path, content, encoding);
|
|
51
|
+
}
|
|
52
|
+
async deleteFile(path) {
|
|
53
|
+
const exists = await RNFS.exists(path);
|
|
54
|
+
if (exists) {
|
|
55
|
+
await RNFS.unlink(path);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async exists(path) {
|
|
59
|
+
return await RNFS.exists(path);
|
|
60
|
+
}
|
|
61
|
+
async stat(path) {
|
|
62
|
+
return await RNFS.stat(path);
|
|
63
|
+
}
|
|
64
|
+
async readDir(path) {
|
|
65
|
+
return await RNFS.readDir(path);
|
|
66
|
+
}
|
|
67
|
+
async copyFile(source, destination) {
|
|
68
|
+
await RNFS.copyFile(source, destination);
|
|
69
|
+
}
|
|
70
|
+
async moveFile(source, destination) {
|
|
71
|
+
await RNFS.moveFile(source, destination);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IFileEntry } from '../FileSystem.types';
|
|
2
|
+
export declare class FileSystemWeb {
|
|
3
|
+
getDocumentDirectory(): string;
|
|
4
|
+
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
5
|
+
getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
6
|
+
deleteUserFolder(userId: string): Promise<void>;
|
|
7
|
+
createDirectory(path: string): Promise<void>;
|
|
8
|
+
readFile(path: string, encoding?: string): Promise<string>;
|
|
9
|
+
writeFile(path: string, content: string, encoding?: string): Promise<void>;
|
|
10
|
+
deleteFile(path: string): Promise<void>;
|
|
11
|
+
exists(path: string): Promise<boolean>;
|
|
12
|
+
stat(path: string): Promise<any>;
|
|
13
|
+
readDir(path: string): Promise<any[]>;
|
|
14
|
+
copyFile(source: string, destination: string): Promise<void>;
|
|
15
|
+
moveFile(source: string, destination: string): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export class FileSystemWeb {
|
|
2
|
+
getDocumentDirectory() {
|
|
3
|
+
return '/virtual-fs';
|
|
4
|
+
}
|
|
5
|
+
async resolveLocalFileSystemURL(url) {
|
|
6
|
+
throw new Error('File system operations not supported on web');
|
|
7
|
+
}
|
|
8
|
+
async getFolderBasedOnUserId(userId) {
|
|
9
|
+
return `/virtual-fs/users/${userId}`;
|
|
10
|
+
}
|
|
11
|
+
async deleteUserFolder(userId) {
|
|
12
|
+
console.warn('deleteUserFolder not supported on web');
|
|
13
|
+
}
|
|
14
|
+
async createDirectory(path) {
|
|
15
|
+
console.warn('createDirectory not supported on web');
|
|
16
|
+
}
|
|
17
|
+
async readFile(path, encoding) {
|
|
18
|
+
throw new Error('readFile not supported on web');
|
|
19
|
+
}
|
|
20
|
+
async writeFile(path, content, encoding) {
|
|
21
|
+
throw new Error('writeFile not supported on web');
|
|
22
|
+
}
|
|
23
|
+
async deleteFile(path) {
|
|
24
|
+
console.warn('deleteFile not supported on web');
|
|
25
|
+
}
|
|
26
|
+
async exists(path) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
async stat(path) {
|
|
30
|
+
throw new Error('stat not supported on web');
|
|
31
|
+
}
|
|
32
|
+
async readDir(path) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
async copyFile(source, destination) {
|
|
36
|
+
throw new Error('copyFile not supported on web');
|
|
37
|
+
}
|
|
38
|
+
async moveFile(source, destination) {
|
|
39
|
+
throw new Error('moveFile not supported on web');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LocalStorage } from './localStorage';
|