|
1 | 1 | import type { AsyncStorage } from "./AsyncStorage"; |
2 | | -import NativeAsyncStorage, { |
3 | | - type Spec as NativeAsyncStorageSpec, |
4 | | -} from "./native-module/NativeAsyncStorage"; |
5 | 2 | import { AsyncStorageError } from "./AsyncStorageError"; |
6 | 3 |
|
7 | | -class AsyncStorageImpl implements AsyncStorage { |
| 4 | +class AsyncStorageWebImpl implements AsyncStorage { |
8 | 5 | constructor(private readonly dbName: string) {} |
9 | 6 |
|
10 | | - private get db(): NativeAsyncStorageSpec { |
11 | | - const mod = NativeAsyncStorage; |
12 | | - if (!mod) { |
13 | | - throw AsyncStorageError.jsError( |
14 | | - `Native module is null, cannot create db`, |
15 | | - AsyncStorageError.Type.NativeModuleError |
16 | | - ); |
17 | | - } |
18 | | - return mod; |
19 | | - } |
20 | | - |
21 | 7 | getItem = async (key: string): Promise<string | null> => { |
22 | 8 | try { |
23 | | - const result = await this.db.getValues(this.dbName, [key]); |
24 | | - const value = result[0] ?? null; |
25 | | - return value?.value ?? null; |
| 9 | + // todo: |
| 10 | + return null; |
26 | 11 | } catch (e) { |
27 | 12 | throw AsyncStorageError.nativeError(e); |
28 | 13 | } |
29 | 14 | }; |
30 | 15 |
|
31 | 16 | setItem = async (key: string, value: string): Promise<void> => { |
32 | 17 | try { |
33 | | - await this.db.setValues(this.dbName, [{ key, value }]); |
| 18 | + // todo |
34 | 19 | } catch (e) { |
35 | 20 | throw AsyncStorageError.nativeError(e); |
36 | 21 | } |
37 | 22 | }; |
38 | 23 |
|
39 | 24 | removeItem = async (key: string): Promise<void> => { |
40 | 25 | try { |
41 | | - await this.db.removeValues(this.dbName, [key]); |
| 26 | + // todo |
42 | 27 | } catch (e) { |
43 | 28 | throw AsyncStorageError.nativeError(e); |
44 | 29 | } |
45 | 30 | }; |
46 | 31 |
|
47 | 32 | getMany = async (keys: string[]): Promise<Record<string, string | null>> => { |
48 | 33 | try { |
49 | | - return await this.db.getValues(this.dbName, keys).then((entries) => |
50 | | - entries.reduce<Record<string, string | null>>((values, current) => { |
51 | | - values[current.key] = current.value; |
52 | | - return values; |
53 | | - }, {}) |
54 | | - ); |
| 34 | + // todo |
| 35 | + return {}; |
55 | 36 | } catch (e) { |
56 | 37 | throw AsyncStorageError.nativeError(e); |
57 | 38 | } |
58 | 39 | }; |
59 | 40 |
|
60 | 41 | setMany = async (entries: Record<string, string>): Promise<void> => { |
61 | 42 | try { |
62 | | - await this.db.setValues( |
63 | | - this.dbName, |
64 | | - Object.entries(entries).map(([key, value]) => ({ key, value })) |
65 | | - ); |
| 43 | + // todo |
66 | 44 | } catch (e) { |
67 | 45 | throw AsyncStorageError.nativeError(e); |
68 | 46 | } |
69 | 47 | }; |
70 | 48 |
|
71 | 49 | removeMany = async (keys: string[]): Promise<void> => { |
72 | 50 | try { |
73 | | - await this.db.removeValues(this.dbName, keys); |
| 51 | + // todo |
74 | 52 | } catch (e) { |
75 | 53 | throw AsyncStorageError.nativeError(e); |
76 | 54 | } |
77 | 55 | }; |
78 | 56 |
|
79 | 57 | getAllKeys = async (): Promise<string[]> => { |
80 | 58 | try { |
81 | | - return await this.db.getKeys(this.dbName); |
| 59 | + // todo |
| 60 | + return []; |
82 | 61 | } catch (e) { |
83 | 62 | throw AsyncStorageError.nativeError(e); |
84 | 63 | } |
85 | 64 | }; |
86 | 65 |
|
87 | 66 | clear = async (): Promise<void> => { |
88 | 67 | try { |
89 | | - return await this.db.clearStorage(this.dbName); |
| 68 | + // return await this.db.clearStorage(this.dbName); |
| 69 | + // todo |
90 | 70 | } catch (e) { |
91 | 71 | throw AsyncStorageError.nativeError(e); |
92 | 72 | } |
93 | 73 | }; |
94 | 74 | } |
95 | 75 |
|
96 | 76 | export function createAsyncStorage(databaseName: string): AsyncStorage { |
97 | | - return new AsyncStorageImpl(databaseName); |
| 77 | + return new AsyncStorageWebImpl(databaseName); |
98 | 78 | } |
0 commit comments