@unvired/react-native-unvired-sdk 0.0.13 → 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/dist/database/DatabaseManager.d.ts +3 -23
- package/dist/database/DatabaseManager.js +9 -314
- 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/file-system/BaseFileSystem.d.ts +6 -5
- package/dist/file-system/BaseFileSystem.js +20 -50
- 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/localStorage.d.ts +3 -2
- package/dist/local-storage/localStorage.js +16 -11
- 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/main.d.ts +0 -2
- package/dist/main.js +0 -4
- package/package.json +4 -2
- package/dist/PlatformAdapter.d.ts +0 -57
- package/dist/PlatformAdapter.js +0 -116
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as RNFS from '@dr.pogodin/react-native-fs';
|
|
2
1
|
import { IFileEntry } from './FileSystem.types';
|
|
3
2
|
/**
|
|
4
3
|
* Base File System Class
|
|
5
4
|
* Handles file system operations for React Native
|
|
5
|
+
* - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
|
|
6
|
+
* - Web: Limited functionality (not supported)
|
|
6
7
|
*/
|
|
7
8
|
export declare class BaseFileSystem {
|
|
8
9
|
/**
|
|
@@ -28,11 +29,11 @@ export declare class BaseFileSystem {
|
|
|
28
29
|
/**
|
|
29
30
|
* Read file content
|
|
30
31
|
*/
|
|
31
|
-
static readFile(path: string, encoding?:
|
|
32
|
+
static readFile(path: string, encoding?: string): Promise<string>;
|
|
32
33
|
/**
|
|
33
34
|
* Write file content
|
|
34
35
|
*/
|
|
35
|
-
static writeFile(path: string, content: string, encoding?:
|
|
36
|
+
static writeFile(path: string, content: string, encoding?: string): Promise<void>;
|
|
36
37
|
/**
|
|
37
38
|
* Delete file
|
|
38
39
|
*/
|
|
@@ -44,11 +45,11 @@ export declare class BaseFileSystem {
|
|
|
44
45
|
/**
|
|
45
46
|
* Get file info
|
|
46
47
|
*/
|
|
47
|
-
static stat(path: string): Promise<
|
|
48
|
+
static stat(path: string): Promise<any>;
|
|
48
49
|
/**
|
|
49
50
|
* List directory contents
|
|
50
51
|
*/
|
|
51
|
-
static readDir(path: string): Promise<
|
|
52
|
+
static readDir(path: string): Promise<any[]>;
|
|
52
53
|
/**
|
|
53
54
|
* Copy file
|
|
54
55
|
*/
|
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
// BaseFileSystem.ts
|
|
2
2
|
// Base file system implementation
|
|
3
|
-
import
|
|
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();
|
|
4
8
|
/**
|
|
5
9
|
* Base File System Class
|
|
6
10
|
* Handles file system operations for React Native
|
|
11
|
+
* - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
|
|
12
|
+
* - Web: Limited functionality (not supported)
|
|
7
13
|
*/
|
|
8
14
|
export class BaseFileSystem {
|
|
9
15
|
/**
|
|
10
16
|
* Get document directory path
|
|
11
17
|
*/
|
|
12
18
|
static getDocumentDirectory() {
|
|
13
|
-
return
|
|
19
|
+
return fsImpl.getDocumentDirectory();
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Resolve local file system URL
|
|
17
23
|
*/
|
|
18
24
|
static async resolveLocalFileSystemURL(url) {
|
|
19
25
|
try {
|
|
20
|
-
|
|
21
|
-
if (normalizedPath.startsWith('file://')) {
|
|
22
|
-
normalizedPath = normalizedPath.substring(7);
|
|
23
|
-
}
|
|
24
|
-
const exists = await RNFS.exists(normalizedPath);
|
|
25
|
-
if (!exists) {
|
|
26
|
-
throw new Error(`File or directory does not exist: ${normalizedPath}`);
|
|
27
|
-
}
|
|
28
|
-
const stat = await RNFS.stat(normalizedPath);
|
|
29
|
-
// Extract filename from path if stat.name is undefined
|
|
30
|
-
const fileName = stat.name || normalizedPath.split('/').pop() || 'unknown';
|
|
31
|
-
const fileEntry = {
|
|
32
|
-
isFile: stat.isFile(),
|
|
33
|
-
isDirectory: stat.isDirectory(),
|
|
34
|
-
name: fileName,
|
|
35
|
-
fullPath: stat.path,
|
|
36
|
-
nativeURL: `file://${stat.path}`,
|
|
37
|
-
};
|
|
38
|
-
return fileEntry;
|
|
26
|
+
return await fsImpl.resolveLocalFileSystemURL(url);
|
|
39
27
|
}
|
|
40
28
|
catch (error) {
|
|
41
29
|
console.error('Error resolving file system URL:', error);
|
|
@@ -47,14 +35,7 @@ export class BaseFileSystem {
|
|
|
47
35
|
*/
|
|
48
36
|
static async getFolderBasedOnUserId(userId) {
|
|
49
37
|
try {
|
|
50
|
-
|
|
51
|
-
const exists = await RNFS.exists(userFolder);
|
|
52
|
-
if (!exists) {
|
|
53
|
-
await RNFS.mkdir(userFolder, {
|
|
54
|
-
NSURLIsExcludedFromBackupKey: true,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return userFolder;
|
|
38
|
+
return await fsImpl.getFolderBasedOnUserId(userId);
|
|
58
39
|
}
|
|
59
40
|
catch (error) {
|
|
60
41
|
console.error('Error getting user folder:', error);
|
|
@@ -66,12 +47,7 @@ export class BaseFileSystem {
|
|
|
66
47
|
*/
|
|
67
48
|
static async deleteUserFolder(userId) {
|
|
68
49
|
try {
|
|
69
|
-
|
|
70
|
-
const exists = await RNFS.exists(userFolder);
|
|
71
|
-
if (exists) {
|
|
72
|
-
await RNFS.unlink(userFolder);
|
|
73
|
-
console.log(`User folder deleted: ${userFolder}`);
|
|
74
|
-
}
|
|
50
|
+
await fsImpl.deleteUserFolder(userId);
|
|
75
51
|
}
|
|
76
52
|
catch (error) {
|
|
77
53
|
console.error('Error deleting user folder:', error);
|
|
@@ -83,10 +59,7 @@ export class BaseFileSystem {
|
|
|
83
59
|
*/
|
|
84
60
|
static async createDirectory(path) {
|
|
85
61
|
try {
|
|
86
|
-
|
|
87
|
-
if (!exists) {
|
|
88
|
-
await RNFS.mkdir(path);
|
|
89
|
-
}
|
|
62
|
+
await fsImpl.createDirectory(path);
|
|
90
63
|
}
|
|
91
64
|
catch (error) {
|
|
92
65
|
console.error('Error creating directory:', error);
|
|
@@ -98,7 +71,7 @@ export class BaseFileSystem {
|
|
|
98
71
|
*/
|
|
99
72
|
static async readFile(path, encoding = 'utf8') {
|
|
100
73
|
try {
|
|
101
|
-
return await
|
|
74
|
+
return await fsImpl.readFile(path, encoding);
|
|
102
75
|
}
|
|
103
76
|
catch (error) {
|
|
104
77
|
console.error('Error reading file:', error);
|
|
@@ -110,7 +83,7 @@ export class BaseFileSystem {
|
|
|
110
83
|
*/
|
|
111
84
|
static async writeFile(path, content, encoding = 'utf8') {
|
|
112
85
|
try {
|
|
113
|
-
await
|
|
86
|
+
await fsImpl.writeFile(path, content, encoding);
|
|
114
87
|
}
|
|
115
88
|
catch (error) {
|
|
116
89
|
console.error('Error writing file:', error);
|
|
@@ -122,10 +95,7 @@ export class BaseFileSystem {
|
|
|
122
95
|
*/
|
|
123
96
|
static async deleteFile(path) {
|
|
124
97
|
try {
|
|
125
|
-
|
|
126
|
-
if (exists) {
|
|
127
|
-
await RNFS.unlink(path);
|
|
128
|
-
}
|
|
98
|
+
await fsImpl.deleteFile(path);
|
|
129
99
|
}
|
|
130
100
|
catch (error) {
|
|
131
101
|
console.error('Error deleting file:', error);
|
|
@@ -137,7 +107,7 @@ export class BaseFileSystem {
|
|
|
137
107
|
*/
|
|
138
108
|
static async exists(path) {
|
|
139
109
|
try {
|
|
140
|
-
return await
|
|
110
|
+
return await fsImpl.exists(path);
|
|
141
111
|
}
|
|
142
112
|
catch (error) {
|
|
143
113
|
return false;
|
|
@@ -148,7 +118,7 @@ export class BaseFileSystem {
|
|
|
148
118
|
*/
|
|
149
119
|
static async stat(path) {
|
|
150
120
|
try {
|
|
151
|
-
return await
|
|
121
|
+
return await fsImpl.stat(path);
|
|
152
122
|
}
|
|
153
123
|
catch (error) {
|
|
154
124
|
console.error('Error getting file stats:', error);
|
|
@@ -160,7 +130,7 @@ export class BaseFileSystem {
|
|
|
160
130
|
*/
|
|
161
131
|
static async readDir(path) {
|
|
162
132
|
try {
|
|
163
|
-
return await
|
|
133
|
+
return await fsImpl.readDir(path);
|
|
164
134
|
}
|
|
165
135
|
catch (error) {
|
|
166
136
|
console.error('Error reading directory:', error);
|
|
@@ -172,7 +142,7 @@ export class BaseFileSystem {
|
|
|
172
142
|
*/
|
|
173
143
|
static async copyFile(source, destination) {
|
|
174
144
|
try {
|
|
175
|
-
await
|
|
145
|
+
await fsImpl.copyFile(source, destination);
|
|
176
146
|
}
|
|
177
147
|
catch (error) {
|
|
178
148
|
console.error('Error copying file:', error);
|
|
@@ -184,7 +154,7 @@ export class BaseFileSystem {
|
|
|
184
154
|
*/
|
|
185
155
|
static async moveFile(source, destination) {
|
|
186
156
|
try {
|
|
187
|
-
await
|
|
157
|
+
await fsImpl.moveFile(source, destination);
|
|
188
158
|
}
|
|
189
159
|
catch (error) {
|
|
190
160
|
console.error('Error moving file:', error);
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* LocalStorage class provides a wrapper around
|
|
3
|
-
*
|
|
2
|
+
* LocalStorage class provides a wrapper around platform-specific storage
|
|
3
|
+
* - Web: Uses browser localStorage
|
|
4
|
+
* - iOS/Android/Windows: Uses AsyncStorage
|
|
4
5
|
*/
|
|
5
6
|
export declare class LocalStorage {
|
|
6
7
|
/**
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import { StorageWeb } from './services/StorageWeb';
|
|
3
|
+
import { StorageNative } from './services/StorageNative';
|
|
4
|
+
// Select storage implementation based on platform
|
|
5
|
+
const storageImpl = Platform.OS === 'web' ? new StorageWeb() : new StorageNative();
|
|
2
6
|
/**
|
|
3
|
-
* LocalStorage class provides a wrapper around
|
|
4
|
-
*
|
|
7
|
+
* LocalStorage class provides a wrapper around platform-specific storage
|
|
8
|
+
* - Web: Uses browser localStorage
|
|
9
|
+
* - iOS/Android/Windows: Uses AsyncStorage
|
|
5
10
|
*/
|
|
6
11
|
export class LocalStorage {
|
|
7
12
|
/**
|
|
@@ -11,7 +16,7 @@ export class LocalStorage {
|
|
|
11
16
|
*/
|
|
12
17
|
static async getItem(key) {
|
|
13
18
|
try {
|
|
14
|
-
const value = await
|
|
19
|
+
const value = await storageImpl.getItem(key);
|
|
15
20
|
return value ? JSON.parse(value) : null;
|
|
16
21
|
}
|
|
17
22
|
catch (error) {
|
|
@@ -27,7 +32,7 @@ export class LocalStorage {
|
|
|
27
32
|
static async setItem(key, value) {
|
|
28
33
|
try {
|
|
29
34
|
const jsonValue = JSON.stringify(value);
|
|
30
|
-
await
|
|
35
|
+
await storageImpl.setItem(key, jsonValue);
|
|
31
36
|
}
|
|
32
37
|
catch (error) {
|
|
33
38
|
console.error(`Error setting item with key "${key}":`, error);
|
|
@@ -40,7 +45,7 @@ export class LocalStorage {
|
|
|
40
45
|
*/
|
|
41
46
|
static async removeItem(key) {
|
|
42
47
|
try {
|
|
43
|
-
await
|
|
48
|
+
await storageImpl.removeItem(key);
|
|
44
49
|
}
|
|
45
50
|
catch (error) {
|
|
46
51
|
console.error(`Error removing item with key "${key}":`, error);
|
|
@@ -52,7 +57,7 @@ export class LocalStorage {
|
|
|
52
57
|
*/
|
|
53
58
|
static async clear() {
|
|
54
59
|
try {
|
|
55
|
-
await
|
|
60
|
+
await storageImpl.clear();
|
|
56
61
|
}
|
|
57
62
|
catch (error) {
|
|
58
63
|
console.error('Error clearing storage:', error);
|
|
@@ -65,7 +70,7 @@ export class LocalStorage {
|
|
|
65
70
|
*/
|
|
66
71
|
static async getAllKeys() {
|
|
67
72
|
try {
|
|
68
|
-
return await
|
|
73
|
+
return await storageImpl.getAllKeys();
|
|
69
74
|
}
|
|
70
75
|
catch (error) {
|
|
71
76
|
console.error('Error getting all keys:', error);
|
|
@@ -79,7 +84,7 @@ export class LocalStorage {
|
|
|
79
84
|
*/
|
|
80
85
|
static async multiGet(keys) {
|
|
81
86
|
try {
|
|
82
|
-
const results = await
|
|
87
|
+
const results = await storageImpl.multiGet(keys);
|
|
83
88
|
return results.map(([key, value]) => [
|
|
84
89
|
key,
|
|
85
90
|
value ? JSON.parse(value) : null
|
|
@@ -100,7 +105,7 @@ export class LocalStorage {
|
|
|
100
105
|
key,
|
|
101
106
|
JSON.stringify(value)
|
|
102
107
|
]);
|
|
103
|
-
await
|
|
108
|
+
await storageImpl.multiSet(jsonPairs);
|
|
104
109
|
}
|
|
105
110
|
catch (error) {
|
|
106
111
|
console.error('Error setting multiple items:', error);
|
|
@@ -113,7 +118,7 @@ export class LocalStorage {
|
|
|
113
118
|
*/
|
|
114
119
|
static async multiRemove(keys) {
|
|
115
120
|
try {
|
|
116
|
-
await
|
|
121
|
+
await storageImpl.multiRemove(keys);
|
|
117
122
|
}
|
|
118
123
|
catch (error) {
|
|
119
124
|
console.error('Error removing multiple items:', error);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class StorageNative {
|
|
2
|
+
getItem(key: string): Promise<string | null>;
|
|
3
|
+
setItem(key: string, value: string): Promise<void>;
|
|
4
|
+
removeItem(key: string): Promise<void>;
|
|
5
|
+
clear(): Promise<void>;
|
|
6
|
+
getAllKeys(): Promise<readonly string[]>;
|
|
7
|
+
multiGet(keys: string[]): Promise<readonly [string, string | null][]>;
|
|
8
|
+
multiSet(keyValuePairs: Array<[string, string]>): Promise<void>;
|
|
9
|
+
multiRemove(keys: string[]): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
2
|
+
export class StorageNative {
|
|
3
|
+
async getItem(key) {
|
|
4
|
+
return await AsyncStorage.getItem(key);
|
|
5
|
+
}
|
|
6
|
+
async setItem(key, value) {
|
|
7
|
+
await AsyncStorage.setItem(key, value);
|
|
8
|
+
}
|
|
9
|
+
async removeItem(key) {
|
|
10
|
+
await AsyncStorage.removeItem(key);
|
|
11
|
+
}
|
|
12
|
+
async clear() {
|
|
13
|
+
await AsyncStorage.clear();
|
|
14
|
+
}
|
|
15
|
+
async getAllKeys() {
|
|
16
|
+
return await AsyncStorage.getAllKeys();
|
|
17
|
+
}
|
|
18
|
+
async multiGet(keys) {
|
|
19
|
+
return await AsyncStorage.multiGet(keys);
|
|
20
|
+
}
|
|
21
|
+
async multiSet(keyValuePairs) {
|
|
22
|
+
await AsyncStorage.multiSet(keyValuePairs);
|
|
23
|
+
}
|
|
24
|
+
async multiRemove(keys) {
|
|
25
|
+
await AsyncStorage.multiRemove(keys);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class StorageWeb {
|
|
2
|
+
getItem(key: string): Promise<string | null>;
|
|
3
|
+
setItem(key: string, value: string): Promise<void>;
|
|
4
|
+
removeItem(key: string): Promise<void>;
|
|
5
|
+
clear(): Promise<void>;
|
|
6
|
+
getAllKeys(): Promise<readonly string[]>;
|
|
7
|
+
multiGet(keys: string[]): Promise<readonly [string, string | null][]>;
|
|
8
|
+
multiSet(keyValuePairs: Array<[string, string]>): Promise<void>;
|
|
9
|
+
multiRemove(keys: string[]): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class StorageWeb {
|
|
2
|
+
async getItem(key) {
|
|
3
|
+
return localStorage.getItem(key);
|
|
4
|
+
}
|
|
5
|
+
async setItem(key, value) {
|
|
6
|
+
localStorage.setItem(key, value);
|
|
7
|
+
}
|
|
8
|
+
async removeItem(key) {
|
|
9
|
+
localStorage.removeItem(key);
|
|
10
|
+
}
|
|
11
|
+
async clear() {
|
|
12
|
+
localStorage.clear();
|
|
13
|
+
}
|
|
14
|
+
async getAllKeys() {
|
|
15
|
+
return Object.keys(localStorage);
|
|
16
|
+
}
|
|
17
|
+
async multiGet(keys) {
|
|
18
|
+
return keys.map(key => [key, localStorage.getItem(key)]);
|
|
19
|
+
}
|
|
20
|
+
async multiSet(keyValuePairs) {
|
|
21
|
+
keyValuePairs.forEach(([key, value]) => localStorage.setItem(key, value));
|
|
22
|
+
}
|
|
23
|
+
async multiRemove(keys) {
|
|
24
|
+
keys.forEach(key => localStorage.removeItem(key));
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/main.d.ts
CHANGED
|
@@ -9,5 +9,3 @@ export { FileSystem } from './file-system';
|
|
|
9
9
|
export type { IFileEntry } from './file-system';
|
|
10
10
|
export { PushNotification } from './push-notification';
|
|
11
11
|
export type { IPushNotificationAdapter } from './push-notification';
|
|
12
|
-
export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter, DatabaseType } from './PlatformAdapter';
|
|
13
|
-
export type { IPlatformAdapter, ILoggerAdapter, IStorageAdapter } from './PlatformAdapter';
|
package/dist/main.js
CHANGED
|
@@ -22,7 +22,3 @@ export { FileSystem } from './file-system';
|
|
|
22
22
|
// Push Notification Module
|
|
23
23
|
// ============================================
|
|
24
24
|
export { PushNotification } from './push-notification';
|
|
25
|
-
// ============================================
|
|
26
|
-
// Platform Adapter
|
|
27
|
-
// ============================================
|
|
28
|
-
export { ReactNativePlatformAdapter, getPlatformAdapter, resetPlatformAdapter, DatabaseType } from './PlatformAdapter';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unvired/react-native-unvired-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Unvired SDK for React Native with logging, database, notifications, and file system support",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@types/react": "^18.0.0",
|
|
42
42
|
"@types/react-native": "^0.72.0",
|
|
43
43
|
"@types/react-native-sqlite-storage": "^6.0.5",
|
|
44
|
+
"@types/sql.js": "^1.4.9",
|
|
44
45
|
"eslint": "^8.0.0",
|
|
45
46
|
"jest": "^29.0.0",
|
|
46
47
|
"prettier": "^3.0.0",
|
|
@@ -49,7 +50,8 @@
|
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
51
52
|
"@types/pako": "^2.0.4",
|
|
52
|
-
"pako": "^2.1.0"
|
|
53
|
+
"pako": "^2.1.0",
|
|
54
|
+
"sql.js": "^1.10.3"
|
|
53
55
|
},
|
|
54
56
|
"repository": {},
|
|
55
57
|
"bugs": {},
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { LogLevel } from './logger';
|
|
2
|
-
import { IDeviceInfo } from './device-info';
|
|
3
|
-
import { IFileEntry } from './file-system';
|
|
4
|
-
import { IDatabaseAdapter } from './database';
|
|
5
|
-
import { IPushNotificationAdapter } from './push-notification';
|
|
6
|
-
export interface ILoggerAdapter {
|
|
7
|
-
logDebug(sourceClass: string, method: string, message: string): void;
|
|
8
|
-
logError(sourceClass: string, method: string, message: string): void;
|
|
9
|
-
logInfo(sourceClass: string, method: string, message: string): void;
|
|
10
|
-
setLogLevel(logLevel: LogLevel): void;
|
|
11
|
-
getLogFileURL(): Promise<string>;
|
|
12
|
-
getLogFileContent(): Promise<string>;
|
|
13
|
-
getBackupLogFileContent(): Promise<string | null>;
|
|
14
|
-
clearLogFile(): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export interface IStorageAdapter {
|
|
17
|
-
getItem<T = any>(key: string): Promise<T | null>;
|
|
18
|
-
setItem(key: string, value: any): Promise<void>;
|
|
19
|
-
removeItem(key: string): Promise<void>;
|
|
20
|
-
clear(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
export declare enum DatabaseType {
|
|
23
|
-
SQLITE = "sqlite",
|
|
24
|
-
WEBSQL = "websql"
|
|
25
|
-
}
|
|
26
|
-
export interface IPlatformAdapter {
|
|
27
|
-
getDeviceInfo(): IDeviceInfo;
|
|
28
|
-
getPlatform(): string;
|
|
29
|
-
getFrontendType(): string;
|
|
30
|
-
getDocumentDirectory(): string;
|
|
31
|
-
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
32
|
-
getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
33
|
-
deleteUserFolder(userId: string): Promise<void>;
|
|
34
|
-
getDatabaseAdapter(): IDatabaseAdapter;
|
|
35
|
-
getPushNotificationAdapter(): IPushNotificationAdapter | null;
|
|
36
|
-
getLoggerAdapter(): ILoggerAdapter;
|
|
37
|
-
getStorageAdapter(): IStorageAdapter;
|
|
38
|
-
}
|
|
39
|
-
export declare class ReactNativePlatformAdapter implements IPlatformAdapter {
|
|
40
|
-
private deviceInfo;
|
|
41
|
-
private pushNotification;
|
|
42
|
-
constructor();
|
|
43
|
-
private initializeDeviceInfo;
|
|
44
|
-
getDeviceInfo(): IDeviceInfo;
|
|
45
|
-
getPlatform(): string;
|
|
46
|
-
getFrontendType(): string;
|
|
47
|
-
getDocumentDirectory(): string;
|
|
48
|
-
resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
|
|
49
|
-
getFolderBasedOnUserId(userId: string): Promise<string>;
|
|
50
|
-
deleteUserFolder(userId: string): Promise<void>;
|
|
51
|
-
getDatabaseAdapter(): IDatabaseAdapter;
|
|
52
|
-
getPushNotificationAdapter(): IPushNotificationAdapter | null;
|
|
53
|
-
getLoggerAdapter(): ILoggerAdapter;
|
|
54
|
-
getStorageAdapter(): IStorageAdapter;
|
|
55
|
-
}
|
|
56
|
-
export declare function getPlatformAdapter(): ReactNativePlatformAdapter;
|
|
57
|
-
export declare function resetPlatformAdapter(): void;
|