@unvired/react-native-unvired-sdk 0.0.13 → 0.0.15

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.
Files changed (30) hide show
  1. package/BuildNo.txt +1 -1
  2. package/dist/database/DatabaseManager.d.ts +3 -23
  3. package/dist/database/DatabaseManager.js +9 -314
  4. package/dist/database/services/DatabaseNative.d.ts +8 -0
  5. package/dist/database/services/DatabaseNative.js +149 -0
  6. package/dist/database/services/DatabaseWeb.d.ts +13 -0
  7. package/dist/database/services/DatabaseWeb.js +138 -0
  8. package/dist/file-system/FileSystem.d.ts +57 -3
  9. package/dist/file-system/FileSystem.js +158 -5
  10. package/dist/file-system/FileSystem.types.d.ts +31 -1
  11. package/dist/file-system/RNFileEntry.d.ts +26 -0
  12. package/dist/file-system/RNFileEntry.js +114 -0
  13. package/dist/file-system/index.d.ts +1 -1
  14. package/dist/file-system/services/FileSystemNative.d.ts +17 -0
  15. package/dist/file-system/services/FileSystemNative.js +68 -0
  16. package/dist/file-system/services/FileSystemWeb.d.ts +16 -0
  17. package/dist/file-system/services/FileSystemWeb.js +41 -0
  18. package/dist/local-storage/localStorage.d.ts +3 -2
  19. package/dist/local-storage/localStorage.js +16 -11
  20. package/dist/local-storage/services/StorageNative.d.ts +10 -0
  21. package/dist/local-storage/services/StorageNative.js +27 -0
  22. package/dist/local-storage/services/StorageWeb.d.ts +10 -0
  23. package/dist/local-storage/services/StorageWeb.js +26 -0
  24. package/dist/main.d.ts +0 -2
  25. package/dist/main.js +0 -4
  26. package/package.json +4 -2
  27. package/dist/PlatformAdapter.d.ts +0 -57
  28. package/dist/PlatformAdapter.js +0 -116
  29. package/dist/file-system/BaseFileSystem.d.ts +0 -60
  30. package/dist/file-system/BaseFileSystem.js +0 -194
@@ -1,9 +1,63 @@
1
- import { BaseFileSystem } from './BaseFileSystem';
1
+ import { IFileEntry, FileSystemEncoding } from './FileSystem.types';
2
2
  /**
3
3
  * FileSystem class
4
- * Extends BaseFileSystem
4
+ * Handles file system operations for React Native
5
+ * - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
6
+ * - Web: Limited functionality (not supported)
5
7
  */
6
- export declare class FileSystem extends BaseFileSystem {
8
+ export declare class FileSystem {
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?: FileSystemEncoding): Promise<string>;
33
+ /**
34
+ * Write file content
35
+ */
36
+ static writeFile(path: string, content: string, encoding?: FileSystemEncoding): 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>;
7
61
  }
8
62
  export type { IFileEntry } from './FileSystem.types';
9
63
  export default FileSystem;
@@ -1,11 +1,164 @@
1
- // FileSystem.ts
2
- // Main file system export
3
- import { BaseFileSystem } from './BaseFileSystem';
1
+ import { Platform } from 'react-native';
2
+ import { FileSystemNative } from './services/FileSystemNative';
3
+ import { FileSystemWeb } from './services/FileSystemWeb';
4
+ // Select file system implementation based on platform
5
+ const fsImpl = Platform.OS === 'web' ? new FileSystemWeb() : new FileSystemNative();
4
6
  /**
5
7
  * FileSystem class
6
- * Extends BaseFileSystem
8
+ * Handles file system operations for React Native
9
+ * - iOS/Android/Windows: Uses @dr.pogodin/react-native-fs
10
+ * - Web: Limited functionality (not supported)
7
11
  */
8
- export class FileSystem extends BaseFileSystem {
12
+ export class FileSystem {
13
+ /**
14
+ * Get document directory path
15
+ */
16
+ static getDocumentDirectory() {
17
+ return fsImpl.getDocumentDirectory();
18
+ }
19
+ /**
20
+ * Resolve local file system URL
21
+ */
22
+ static async resolveLocalFileSystemURL(url) {
23
+ try {
24
+ return await fsImpl.resolveLocalFileSystemURL(url);
25
+ }
26
+ catch (error) {
27
+ console.error('Error resolving file system URL:', error);
28
+ throw error;
29
+ }
30
+ }
31
+ /**
32
+ * Get folder based on user ID
33
+ */
34
+ static async getFolderBasedOnUserId(userId) {
35
+ try {
36
+ return await fsImpl.getFolderBasedOnUserId(userId);
37
+ }
38
+ catch (error) {
39
+ console.error('Error getting user folder:', error);
40
+ throw error;
41
+ }
42
+ }
43
+ /**
44
+ * Delete user folder
45
+ */
46
+ static async deleteUserFolder(userId) {
47
+ try {
48
+ await fsImpl.deleteUserFolder(userId);
49
+ }
50
+ catch (error) {
51
+ console.error('Error deleting user folder:', error);
52
+ throw error;
53
+ }
54
+ }
55
+ /**
56
+ * Create directory
57
+ */
58
+ static async createDirectory(path) {
59
+ try {
60
+ await fsImpl.createDirectory(path);
61
+ }
62
+ catch (error) {
63
+ console.error('Error creating directory:', error);
64
+ throw error;
65
+ }
66
+ }
67
+ /**
68
+ * Read file content
69
+ */
70
+ static async readFile(path, encoding = 'utf8') {
71
+ try {
72
+ return await fsImpl.readFile(path, encoding);
73
+ }
74
+ catch (error) {
75
+ console.error('Error reading file:', error);
76
+ throw error;
77
+ }
78
+ }
79
+ /**
80
+ * Write file content
81
+ */
82
+ static async writeFile(path, content, encoding = 'utf8') {
83
+ try {
84
+ await fsImpl.writeFile(path, content, encoding);
85
+ }
86
+ catch (error) {
87
+ console.error('Error writing file:', error);
88
+ throw error;
89
+ }
90
+ }
91
+ /**
92
+ * Delete file
93
+ */
94
+ static async deleteFile(path) {
95
+ try {
96
+ await fsImpl.deleteFile(path);
97
+ }
98
+ catch (error) {
99
+ console.error('Error deleting file:', error);
100
+ throw error;
101
+ }
102
+ }
103
+ /**
104
+ * Check if file exists
105
+ */
106
+ static async exists(path) {
107
+ try {
108
+ return await fsImpl.exists(path);
109
+ }
110
+ catch (error) {
111
+ return false;
112
+ }
113
+ }
114
+ /**
115
+ * Get file info
116
+ */
117
+ static async stat(path) {
118
+ try {
119
+ return await fsImpl.stat(path);
120
+ }
121
+ catch (error) {
122
+ console.error('Error getting file stats:', error);
123
+ throw error;
124
+ }
125
+ }
126
+ /**
127
+ * List directory contents
128
+ */
129
+ static async readDir(path) {
130
+ try {
131
+ return await fsImpl.readDir(path);
132
+ }
133
+ catch (error) {
134
+ console.error('Error reading directory:', error);
135
+ throw error;
136
+ }
137
+ }
138
+ /**
139
+ * Copy file
140
+ */
141
+ static async copyFile(source, destination) {
142
+ try {
143
+ await fsImpl.copyFile(source, destination);
144
+ }
145
+ catch (error) {
146
+ console.error('Error copying file:', error);
147
+ throw error;
148
+ }
149
+ }
150
+ /**
151
+ * Move file
152
+ */
153
+ static async moveFile(source, destination) {
154
+ try {
155
+ await fsImpl.moveFile(source, destination);
156
+ }
157
+ catch (error) {
158
+ console.error('Error moving file:', error);
159
+ throw error;
160
+ }
161
+ }
9
162
  }
10
163
  // Default export
11
164
  export default FileSystem;
@@ -1,11 +1,41 @@
1
1
  /**
2
2
  * File entry interface
3
3
  */
4
+ export interface IDirectoryReader {
5
+ readEntries(successCallback: (entries: IFileEntry[]) => void, errorCallback: (error: any) => void): void;
6
+ }
4
7
  export interface IFileEntry {
5
8
  isFile: boolean;
6
9
  isDirectory: boolean;
7
10
  name: string;
8
11
  fullPath: string;
9
12
  filesystem?: any;
10
- nativeURL?: string;
13
+ nativeURL: string;
14
+ remove(callback: () => void, errorCallback: (error: any) => void): void;
15
+ removeRecursively(callback: () => void, errorCallback: (error: any) => void): void;
16
+ createReader(): IDirectoryReader;
17
+ getDirectory?(path: string, options: {
18
+ create: boolean;
19
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
20
+ getFile?(path: string, options: {
21
+ create: boolean;
22
+ }, callback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
23
+ file?(callback: (file: any) => void, errorCallback: (error: any) => void): void;
24
+ createWriter?(callback: (writer: any) => void, errorCallback: (error: any) => void): void;
25
+ }
26
+ export type FileSystemEncoding = 'utf8' | 'ascii' | 'base64';
27
+ export interface IFileSystem {
28
+ getDocumentDirectory(): string;
29
+ resolveLocalFileSystemURL(url: string): Promise<IFileEntry>;
30
+ getFolderBasedOnUserId(userId: string): Promise<string>;
31
+ deleteUserFolder(userId: string): Promise<void>;
32
+ createDirectory(path: string): Promise<void>;
33
+ readFile(path: string, encoding?: FileSystemEncoding): Promise<string>;
34
+ writeFile(path: string, content: string, encoding?: FileSystemEncoding): Promise<void>;
35
+ deleteFile(path: string): Promise<void>;
36
+ exists(path: string): Promise<boolean>;
37
+ stat(path: string): Promise<any>;
38
+ readDir(path: string): Promise<any[]>;
39
+ copyFile(source: string, destination: string): Promise<void>;
40
+ moveFile(source: string, destination: string): Promise<void>;
11
41
  }
@@ -0,0 +1,26 @@
1
+ import { IFileEntry, IDirectoryReader } from './FileSystem.types';
2
+ export declare class RNFileEntry implements IFileEntry {
3
+ isFile: boolean;
4
+ isDirectory: boolean;
5
+ name: string;
6
+ fullPath: string;
7
+ nativeURL: string;
8
+ filesystem: any;
9
+ constructor(isFile: boolean, isDirectory: boolean, name: string, fullPath: string, nativeURL: string, filesystem?: any);
10
+ remove(successCallback: () => void, errorCallback: (error: any) => void): void;
11
+ removeRecursively(successCallback: () => void, errorCallback: (error: any) => void): void;
12
+ createReader(): IDirectoryReader;
13
+ getDirectory(path: string, options: {
14
+ create: boolean;
15
+ }, successCallback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
16
+ getFile(path: string, options: {
17
+ create: boolean;
18
+ }, successCallback: (entry: IFileEntry) => void, errorCallback: (error: any) => void): void;
19
+ file(callback: (file: any) => void, errorCallback: (error: any) => void): void;
20
+ createWriter(callback: (writer: any) => void, errorCallback: (error: any) => void): void;
21
+ }
22
+ export declare class RNDirectoryReader implements IDirectoryReader {
23
+ private localPath;
24
+ constructor(localPath: string);
25
+ readEntries(successCallback: (entries: IFileEntry[]) => void, errorCallback: (error: any) => void): void;
26
+ }
@@ -0,0 +1,114 @@
1
+ import * as RNFS from '@dr.pogodin/react-native-fs';
2
+ export class RNFileEntry {
3
+ constructor(isFile, isDirectory, name, fullPath, nativeURL, filesystem = null) {
4
+ this.isFile = isFile;
5
+ this.isDirectory = isDirectory;
6
+ this.name = name;
7
+ this.fullPath = fullPath;
8
+ this.nativeURL = nativeURL;
9
+ this.filesystem = filesystem;
10
+ }
11
+ remove(successCallback, errorCallback) {
12
+ RNFS.unlink(this.fullPath)
13
+ .then(() => successCallback())
14
+ .catch((err) => errorCallback(err));
15
+ }
16
+ removeRecursively(successCallback, errorCallback) {
17
+ this.remove(successCallback, errorCallback);
18
+ }
19
+ createReader() {
20
+ return new RNDirectoryReader(this.fullPath);
21
+ }
22
+ getDirectory(path, options, successCallback, errorCallback) {
23
+ const newPath = this.fullPath + (this.fullPath.endsWith('/') ? '' : '/') + path;
24
+ const newNativeURL = "file://" + newPath;
25
+ if (options.create) {
26
+ RNFS.mkdir(newPath).then(() => {
27
+ successCallback(new RNFileEntry(false, true, path, newPath, newNativeURL));
28
+ }).catch(errorCallback);
29
+ }
30
+ else {
31
+ RNFS.stat(newPath).then(stat => {
32
+ if (stat.isDirectory()) {
33
+ successCallback(new RNFileEntry(false, true, path, newPath, newNativeURL));
34
+ }
35
+ else {
36
+ errorCallback("Not a directory");
37
+ }
38
+ }).catch(errorCallback);
39
+ }
40
+ }
41
+ getFile(path, options, successCallback, errorCallback) {
42
+ const newPath = this.fullPath + (this.fullPath.endsWith('/') ? '' : '/') + path;
43
+ const newNativeURL = "file://" + newPath;
44
+ if (options.create) {
45
+ RNFS.exists(newPath).then(exists => {
46
+ if (exists) {
47
+ successCallback(new RNFileEntry(true, false, path, newPath, newNativeURL));
48
+ }
49
+ else {
50
+ RNFS.writeFile(newPath, '', 'utf8').then(() => {
51
+ successCallback(new RNFileEntry(true, false, path, newPath, newNativeURL));
52
+ }).catch(errorCallback);
53
+ }
54
+ }).catch(errorCallback);
55
+ }
56
+ else {
57
+ RNFS.stat(newPath).then(stat => {
58
+ if (stat.isFile()) {
59
+ successCallback(new RNFileEntry(true, false, path, newPath, newNativeURL));
60
+ }
61
+ else {
62
+ errorCallback("Not a file");
63
+ }
64
+ }).catch(errorCallback);
65
+ }
66
+ }
67
+ file(callback, errorCallback) {
68
+ RNFS.stat(this.fullPath).then(stat => {
69
+ const file = {
70
+ name: stat.name,
71
+ localURL: "file://" + stat.path,
72
+ type: "",
73
+ lastModified: stat.mtime ? new Date(stat.mtime).getTime() : 0,
74
+ lastModifiedDate: stat.mtime,
75
+ size: stat.size,
76
+ start: 0,
77
+ end: stat.size,
78
+ slice: () => { }
79
+ };
80
+ callback(file);
81
+ }).catch(errorCallback);
82
+ }
83
+ createWriter(callback, errorCallback) {
84
+ const writer = {
85
+ write: (data) => {
86
+ RNFS.writeFile(this.fullPath, data, 'utf8')
87
+ .then(() => { if (writer.onwriteend)
88
+ writer.onwriteend(); })
89
+ .catch((err) => { if (writer.onerror)
90
+ writer.onerror(err); });
91
+ },
92
+ seek: () => { },
93
+ truncate: () => { },
94
+ onwriteend: null,
95
+ onerror: null
96
+ };
97
+ callback(writer);
98
+ }
99
+ }
100
+ export class RNDirectoryReader {
101
+ constructor(localPath) {
102
+ this.localPath = localPath;
103
+ }
104
+ readEntries(successCallback, errorCallback) {
105
+ RNFS.readDir(this.localPath)
106
+ .then((result) => {
107
+ const entries = result.map(fileStat => {
108
+ return new RNFileEntry(fileStat.isFile(), fileStat.isDirectory(), fileStat.name || fileStat.path.split('/').pop() || '', fileStat.path, "file://" + fileStat.path);
109
+ });
110
+ successCallback(entries);
111
+ })
112
+ .catch((err) => errorCallback(err));
113
+ }
114
+ }
@@ -1,3 +1,3 @@
1
1
  export { FileSystem } from './FileSystem';
2
- export type { IFileEntry } from './FileSystem.types';
2
+ export type { IFileEntry, IDirectoryReader } from './FileSystem.types';
3
3
  export { default } from './FileSystem';
@@ -0,0 +1,17 @@
1
+ import * as RNFS from '@dr.pogodin/react-native-fs';
2
+ import { IFileEntry, IFileSystem, FileSystemEncoding } from '../FileSystem.types';
3
+ export declare class FileSystemNative implements IFileSystem {
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?: FileSystemEncoding): Promise<string>;
10
+ writeFile(path: string, content: string, encoding?: FileSystemEncoding): 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,68 @@
1
+ import * as RNFS from '@dr.pogodin/react-native-fs';
2
+ import { RNFileEntry } from '../RNFileEntry';
3
+ export class FileSystemNative {
4
+ getDocumentDirectory() {
5
+ return RNFS.DocumentDirectoryPath;
6
+ }
7
+ async resolveLocalFileSystemURL(url) {
8
+ let normalizedPath = url;
9
+ if (normalizedPath.startsWith('file://')) {
10
+ normalizedPath = normalizedPath.substring(7);
11
+ }
12
+ const exists = await RNFS.exists(normalizedPath);
13
+ if (!exists) {
14
+ throw new Error(`File or directory does not exist: ${normalizedPath}`);
15
+ }
16
+ const stat = await RNFS.stat(normalizedPath);
17
+ const fileName = stat.name || normalizedPath.split('/').pop() || 'unknown';
18
+ return new RNFileEntry(stat.isFile(), stat.isDirectory(), fileName, stat.path, `file://${stat.path}`);
19
+ }
20
+ async getFolderBasedOnUserId(userId) {
21
+ const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
22
+ const exists = await RNFS.exists(userFolder);
23
+ if (!exists) {
24
+ await RNFS.mkdir(userFolder, { NSURLIsExcludedFromBackupKey: true });
25
+ }
26
+ return userFolder;
27
+ }
28
+ async deleteUserFolder(userId) {
29
+ const userFolder = `${RNFS.DocumentDirectoryPath}/users/${userId}`;
30
+ const exists = await RNFS.exists(userFolder);
31
+ if (exists) {
32
+ await RNFS.unlink(userFolder);
33
+ }
34
+ }
35
+ async createDirectory(path) {
36
+ const exists = await RNFS.exists(path);
37
+ if (!exists) {
38
+ await RNFS.mkdir(path);
39
+ }
40
+ }
41
+ async readFile(path, encoding = 'utf8') {
42
+ return await RNFS.readFile(path, encoding);
43
+ }
44
+ async writeFile(path, content, encoding = 'utf8') {
45
+ await RNFS.writeFile(path, content, encoding);
46
+ }
47
+ async deleteFile(path) {
48
+ const exists = await RNFS.exists(path);
49
+ if (exists) {
50
+ await RNFS.unlink(path);
51
+ }
52
+ }
53
+ async exists(path) {
54
+ return await RNFS.exists(path);
55
+ }
56
+ async stat(path) {
57
+ return await RNFS.stat(path);
58
+ }
59
+ async readDir(path) {
60
+ return await RNFS.readDir(path);
61
+ }
62
+ async copyFile(source, destination) {
63
+ await RNFS.copyFile(source, destination);
64
+ }
65
+ async moveFile(source, destination) {
66
+ await RNFS.moveFile(source, destination);
67
+ }
68
+ }
@@ -0,0 +1,16 @@
1
+ import { IFileEntry, IFileSystem, FileSystemEncoding } from '../FileSystem.types';
2
+ export declare class FileSystemWeb implements IFileSystem {
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?: FileSystemEncoding): Promise<string>;
9
+ writeFile(path: string, content: string, encoding?: FileSystemEncoding): 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 React Native AsyncStorage
3
- * with convenient methods for storing and retrieving data.
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 AsyncStorage from '@react-native-async-storage/async-storage';
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 React Native AsyncStorage
4
- * with convenient methods for storing and retrieving data.
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 AsyncStorage.getItem(key);
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 AsyncStorage.setItem(key, jsonValue);
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 AsyncStorage.removeItem(key);
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 AsyncStorage.clear();
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 AsyncStorage.getAllKeys();
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 AsyncStorage.multiGet(keys);
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 AsyncStorage.multiSet(jsonPairs);
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 AsyncStorage.multiRemove(keys);
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
+ }