@kafitra/lynx-async-storage 0.1.0
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/README.md +282 -0
- package/dist/index.cjs +348 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +226 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +333 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @kafitra/lynx-async-storage
|
|
3
|
+
*
|
|
4
|
+
* Public type definitions.
|
|
5
|
+
*/
|
|
6
|
+
/** A key-value pair used for multi-set and multi-merge operations. */
|
|
7
|
+
type KeyValuePair = [key: string, value: string];
|
|
8
|
+
/** A key-result pair returned by multi-get. Value is null when the key is absent. */
|
|
9
|
+
type KeyValueResult = [key: string, value: string | null];
|
|
10
|
+
/**
|
|
11
|
+
* Synchronous low-level storage contract.
|
|
12
|
+
*
|
|
13
|
+
* Implementations wrap the underlying platform storage (e.g., Lynx runtime
|
|
14
|
+
* key-value store, localStorage-compatible API) and expose a uniform surface.
|
|
15
|
+
* All methods are intentionally synchronous; async scheduling is handled by
|
|
16
|
+
* the AsyncStorage layer above.
|
|
17
|
+
*/
|
|
18
|
+
interface StorageBackend {
|
|
19
|
+
/** Returns the stored string, or null when the key is absent. */
|
|
20
|
+
getItem(key: string): string | null;
|
|
21
|
+
/** Stores a string value. */
|
|
22
|
+
setItem(key: string, value: string): void;
|
|
23
|
+
/** Removes a single key. */
|
|
24
|
+
removeItem(key: string): void;
|
|
25
|
+
/** Removes every key managed by this backend. */
|
|
26
|
+
clear(): void;
|
|
27
|
+
/** Returns every currently stored key in an unspecified order. */
|
|
28
|
+
getAllKeys(): string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Full async API surface – mirrors React Native AsyncStorage.
|
|
32
|
+
*/
|
|
33
|
+
interface AsyncStorageInterface {
|
|
34
|
+
getItem(key: string): Promise<string | null>;
|
|
35
|
+
setItem(key: string, value: string): Promise<void>;
|
|
36
|
+
removeItem(key: string): Promise<void>;
|
|
37
|
+
clear(): Promise<void>;
|
|
38
|
+
getAllKeys(): Promise<string[]>;
|
|
39
|
+
multiGet(keys: readonly string[]): Promise<KeyValueResult[]>;
|
|
40
|
+
multiSet(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
41
|
+
multiRemove(keys: readonly string[]): Promise<void>;
|
|
42
|
+
mergeItem(key: string, value: string): Promise<void>;
|
|
43
|
+
multiMerge(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Swaps the current backend for a new one.
|
|
46
|
+
* Useful for testing or runtime adapter injection.
|
|
47
|
+
*/
|
|
48
|
+
useBackend(backend: StorageBackend): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @kafitra/lynx-async-storage
|
|
53
|
+
*
|
|
54
|
+
* Core AsyncStorage implementation.
|
|
55
|
+
*
|
|
56
|
+
* Design notes
|
|
57
|
+
* ────────────
|
|
58
|
+
* • Every public method wraps its synchronous backend call inside a microtask
|
|
59
|
+
* (Promise.resolve().then(...)) so callers always receive a Promise, even when
|
|
60
|
+
* the underlying operation completes instantaneously.
|
|
61
|
+
*
|
|
62
|
+
* • Validation (key/value type checks) is performed *inside* the microtask so
|
|
63
|
+
* that no method ever throws synchronously.
|
|
64
|
+
*
|
|
65
|
+
* • mergeItem implements a shallow JSON Object merge as specified: parse both
|
|
66
|
+
* values, spread-merge, stringify, and persist.
|
|
67
|
+
*
|
|
68
|
+
* • getAllKeys returns keys sorted lexicographically for deterministic output.
|
|
69
|
+
*
|
|
70
|
+
* • multiGet preserves the order of the input `keys` array.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
declare class AsyncStorage implements AsyncStorageInterface {
|
|
74
|
+
private backend;
|
|
75
|
+
constructor(backend?: StorageBackend);
|
|
76
|
+
useBackend(backend: StorageBackend): void;
|
|
77
|
+
getItem(key: string): Promise<string | null>;
|
|
78
|
+
setItem(key: string, value: string): Promise<void>;
|
|
79
|
+
removeItem(key: string): Promise<void>;
|
|
80
|
+
clear(): Promise<void>;
|
|
81
|
+
getAllKeys(): Promise<string[]>;
|
|
82
|
+
multiGet(keys: readonly string[]): Promise<KeyValueResult[]>;
|
|
83
|
+
multiSet(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
84
|
+
multiRemove(keys: readonly string[]): Promise<void>;
|
|
85
|
+
mergeItem(key: string, value: string): Promise<void>;
|
|
86
|
+
multiMerge(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @kafitra/lynx-async-storage
|
|
91
|
+
*
|
|
92
|
+
* StorageBackend implementations.
|
|
93
|
+
*
|
|
94
|
+
* Resolution order (createDefaultBackend):
|
|
95
|
+
* 1. NativeStorageBackend — NativeModules.LynxStorage (disk-backed, persists across restarts)
|
|
96
|
+
* 2. LocalStorageBackend — globalThis.localStorage (browser / some WebView runtimes)
|
|
97
|
+
* 3. MemoryBackend — in-memory Map fallback (tests / unknown environments)
|
|
98
|
+
*
|
|
99
|
+
* Swap the backend at any time via AsyncStorage.useBackend().
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
interface LynxNativeStorage {
|
|
103
|
+
getString(key: string): string | null;
|
|
104
|
+
setString(key: string, value: string): void;
|
|
105
|
+
remove(key: string): void;
|
|
106
|
+
clear(): void;
|
|
107
|
+
/** Returns a JSON array string, e.g. '["a","b"]' */
|
|
108
|
+
getAllKeys(): string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Simple Map-backed store.
|
|
112
|
+
*
|
|
113
|
+
* Used as the built-in fallback when no runtime storage is detected, and as a
|
|
114
|
+
* convenient injectable backend for unit tests.
|
|
115
|
+
*/
|
|
116
|
+
declare class MemoryBackend implements StorageBackend {
|
|
117
|
+
private readonly store;
|
|
118
|
+
getItem(key: string): string | null;
|
|
119
|
+
setItem(key: string, value: string): void;
|
|
120
|
+
removeItem(key: string): void;
|
|
121
|
+
clear(): void;
|
|
122
|
+
getAllKeys(): string[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Wraps the `NativeModules.LynxStorage` Lynx native module.
|
|
126
|
+
*
|
|
127
|
+
* This backend provides **disk-persistent** storage that survives app restarts,
|
|
128
|
+
* backed by Android SharedPreferences and iOS NSUserDefaults.
|
|
129
|
+
*
|
|
130
|
+
* Requires `@kafitra/lynx-storage` to be installed and registered in the
|
|
131
|
+
* host Android/iOS app:
|
|
132
|
+
*
|
|
133
|
+
* Android: LynxEnv.inst().registerModule("LynxStorage", LynxStorageModule.class)
|
|
134
|
+
* iOS: [globalConfig registerModule:LynxStorageModule.class]
|
|
135
|
+
*/
|
|
136
|
+
declare class NativeStorageBackend implements StorageBackend {
|
|
137
|
+
private readonly native;
|
|
138
|
+
constructor(native: LynxNativeStorage);
|
|
139
|
+
getItem(key: string): string | null;
|
|
140
|
+
setItem(key: string, value: string): void;
|
|
141
|
+
removeItem(key: string): void;
|
|
142
|
+
clear(): void;
|
|
143
|
+
getAllKeys(): string[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Wraps any object that matches the Web Storage / Lynx localStorage API.
|
|
147
|
+
*/
|
|
148
|
+
declare class LocalStorageBackend implements StorageBackend {
|
|
149
|
+
private readonly ls;
|
|
150
|
+
constructor(ls: Storage);
|
|
151
|
+
getItem(key: string): string | null;
|
|
152
|
+
setItem(key: string, value: string): void;
|
|
153
|
+
removeItem(key: string): void;
|
|
154
|
+
clear(): void;
|
|
155
|
+
getAllKeys(): string[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates and returns the best available backend for the current runtime.
|
|
159
|
+
*
|
|
160
|
+
* Resolution order:
|
|
161
|
+
* 1. NativeModules.LynxStorage (Lynx runtime with @kafitra/lynx-storage linked)
|
|
162
|
+
* 2. globalThis.localStorage (browser / jsdom)
|
|
163
|
+
* 3. MemoryBackend (fallback)
|
|
164
|
+
*/
|
|
165
|
+
declare function createDefaultBackend(): StorageBackend;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @kafitra/lynx-async-storage
|
|
169
|
+
*
|
|
170
|
+
* Typed error classes used across the module.
|
|
171
|
+
* All errors extend the built-in Error so they are instanceof-compatible.
|
|
172
|
+
*/
|
|
173
|
+
declare const ErrorCodes: {
|
|
174
|
+
readonly INVALID_KEY: "ERR_ASYNC_STORAGE_INVALID_KEY";
|
|
175
|
+
readonly INVALID_VALUE: "ERR_ASYNC_STORAGE_INVALID_VALUE";
|
|
176
|
+
readonly INVALID_JSON: "ERR_ASYNC_STORAGE_INVALID_JSON";
|
|
177
|
+
readonly BACKEND_FAILURE: "ERR_ASYNC_STORAGE_BACKEND_FAILURE";
|
|
178
|
+
};
|
|
179
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
180
|
+
declare class AsyncStorageError extends Error {
|
|
181
|
+
readonly code: ErrorCode;
|
|
182
|
+
readonly cause?: unknown;
|
|
183
|
+
constructor(code: ErrorCode, message: string, cause?: unknown);
|
|
184
|
+
}
|
|
185
|
+
/** Thrown when a key is not a non-empty string. */
|
|
186
|
+
declare class InvalidKeyError extends AsyncStorageError {
|
|
187
|
+
constructor(key: unknown);
|
|
188
|
+
}
|
|
189
|
+
/** Thrown when a value is not a string. */
|
|
190
|
+
declare class InvalidValueError extends AsyncStorageError {
|
|
191
|
+
constructor(value: unknown);
|
|
192
|
+
}
|
|
193
|
+
/** Thrown when JSON parsing fails during a merge operation. */
|
|
194
|
+
declare class InvalidJsonError extends AsyncStorageError {
|
|
195
|
+
constructor(context: "existing" | "incoming", cause?: unknown);
|
|
196
|
+
}
|
|
197
|
+
/** Thrown when the underlying storage backend raises an exception. */
|
|
198
|
+
declare class BackendError extends AsyncStorageError {
|
|
199
|
+
constructor(operation: string, cause?: unknown);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @kafitra/lynx-async-storage
|
|
204
|
+
*
|
|
205
|
+
* Public barrel export.
|
|
206
|
+
*
|
|
207
|
+
* Default export: shared singleton (mirrors React Native AsyncStorage usage).
|
|
208
|
+
* Named exports: class and types for consumers who need custom instances.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Shared singleton instance – drop-in replacement for React Native AsyncStorage.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import AsyncStorage from '@kafitra/lynx-async-storage';
|
|
217
|
+
*
|
|
218
|
+
* await AsyncStorage.setItem('token', 'abc123');
|
|
219
|
+
* const token = await AsyncStorage.getItem('token'); // 'abc123'
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare const instance: AsyncStorage;
|
|
223
|
+
|
|
224
|
+
// @ts-ignore
|
|
225
|
+
export = instance;
|
|
226
|
+
export { AsyncStorage, AsyncStorageError, type AsyncStorageInterface, BackendError, ErrorCodes, InvalidJsonError, InvalidKeyError, InvalidValueError, type KeyValuePair, type KeyValueResult, LocalStorageBackend, MemoryBackend, NativeStorageBackend, type StorageBackend, createDefaultBackend };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @kafitra/lynx-async-storage
|
|
3
|
+
*
|
|
4
|
+
* Public type definitions.
|
|
5
|
+
*/
|
|
6
|
+
/** A key-value pair used for multi-set and multi-merge operations. */
|
|
7
|
+
type KeyValuePair = [key: string, value: string];
|
|
8
|
+
/** A key-result pair returned by multi-get. Value is null when the key is absent. */
|
|
9
|
+
type KeyValueResult = [key: string, value: string | null];
|
|
10
|
+
/**
|
|
11
|
+
* Synchronous low-level storage contract.
|
|
12
|
+
*
|
|
13
|
+
* Implementations wrap the underlying platform storage (e.g., Lynx runtime
|
|
14
|
+
* key-value store, localStorage-compatible API) and expose a uniform surface.
|
|
15
|
+
* All methods are intentionally synchronous; async scheduling is handled by
|
|
16
|
+
* the AsyncStorage layer above.
|
|
17
|
+
*/
|
|
18
|
+
interface StorageBackend {
|
|
19
|
+
/** Returns the stored string, or null when the key is absent. */
|
|
20
|
+
getItem(key: string): string | null;
|
|
21
|
+
/** Stores a string value. */
|
|
22
|
+
setItem(key: string, value: string): void;
|
|
23
|
+
/** Removes a single key. */
|
|
24
|
+
removeItem(key: string): void;
|
|
25
|
+
/** Removes every key managed by this backend. */
|
|
26
|
+
clear(): void;
|
|
27
|
+
/** Returns every currently stored key in an unspecified order. */
|
|
28
|
+
getAllKeys(): string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Full async API surface – mirrors React Native AsyncStorage.
|
|
32
|
+
*/
|
|
33
|
+
interface AsyncStorageInterface {
|
|
34
|
+
getItem(key: string): Promise<string | null>;
|
|
35
|
+
setItem(key: string, value: string): Promise<void>;
|
|
36
|
+
removeItem(key: string): Promise<void>;
|
|
37
|
+
clear(): Promise<void>;
|
|
38
|
+
getAllKeys(): Promise<string[]>;
|
|
39
|
+
multiGet(keys: readonly string[]): Promise<KeyValueResult[]>;
|
|
40
|
+
multiSet(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
41
|
+
multiRemove(keys: readonly string[]): Promise<void>;
|
|
42
|
+
mergeItem(key: string, value: string): Promise<void>;
|
|
43
|
+
multiMerge(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Swaps the current backend for a new one.
|
|
46
|
+
* Useful for testing or runtime adapter injection.
|
|
47
|
+
*/
|
|
48
|
+
useBackend(backend: StorageBackend): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @kafitra/lynx-async-storage
|
|
53
|
+
*
|
|
54
|
+
* Core AsyncStorage implementation.
|
|
55
|
+
*
|
|
56
|
+
* Design notes
|
|
57
|
+
* ────────────
|
|
58
|
+
* • Every public method wraps its synchronous backend call inside a microtask
|
|
59
|
+
* (Promise.resolve().then(...)) so callers always receive a Promise, even when
|
|
60
|
+
* the underlying operation completes instantaneously.
|
|
61
|
+
*
|
|
62
|
+
* • Validation (key/value type checks) is performed *inside* the microtask so
|
|
63
|
+
* that no method ever throws synchronously.
|
|
64
|
+
*
|
|
65
|
+
* • mergeItem implements a shallow JSON Object merge as specified: parse both
|
|
66
|
+
* values, spread-merge, stringify, and persist.
|
|
67
|
+
*
|
|
68
|
+
* • getAllKeys returns keys sorted lexicographically for deterministic output.
|
|
69
|
+
*
|
|
70
|
+
* • multiGet preserves the order of the input `keys` array.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
declare class AsyncStorage implements AsyncStorageInterface {
|
|
74
|
+
private backend;
|
|
75
|
+
constructor(backend?: StorageBackend);
|
|
76
|
+
useBackend(backend: StorageBackend): void;
|
|
77
|
+
getItem(key: string): Promise<string | null>;
|
|
78
|
+
setItem(key: string, value: string): Promise<void>;
|
|
79
|
+
removeItem(key: string): Promise<void>;
|
|
80
|
+
clear(): Promise<void>;
|
|
81
|
+
getAllKeys(): Promise<string[]>;
|
|
82
|
+
multiGet(keys: readonly string[]): Promise<KeyValueResult[]>;
|
|
83
|
+
multiSet(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
84
|
+
multiRemove(keys: readonly string[]): Promise<void>;
|
|
85
|
+
mergeItem(key: string, value: string): Promise<void>;
|
|
86
|
+
multiMerge(keyValuePairs: readonly KeyValuePair[]): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @kafitra/lynx-async-storage
|
|
91
|
+
*
|
|
92
|
+
* StorageBackend implementations.
|
|
93
|
+
*
|
|
94
|
+
* Resolution order (createDefaultBackend):
|
|
95
|
+
* 1. NativeStorageBackend — NativeModules.LynxStorage (disk-backed, persists across restarts)
|
|
96
|
+
* 2. LocalStorageBackend — globalThis.localStorage (browser / some WebView runtimes)
|
|
97
|
+
* 3. MemoryBackend — in-memory Map fallback (tests / unknown environments)
|
|
98
|
+
*
|
|
99
|
+
* Swap the backend at any time via AsyncStorage.useBackend().
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
interface LynxNativeStorage {
|
|
103
|
+
getString(key: string): string | null;
|
|
104
|
+
setString(key: string, value: string): void;
|
|
105
|
+
remove(key: string): void;
|
|
106
|
+
clear(): void;
|
|
107
|
+
/** Returns a JSON array string, e.g. '["a","b"]' */
|
|
108
|
+
getAllKeys(): string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Simple Map-backed store.
|
|
112
|
+
*
|
|
113
|
+
* Used as the built-in fallback when no runtime storage is detected, and as a
|
|
114
|
+
* convenient injectable backend for unit tests.
|
|
115
|
+
*/
|
|
116
|
+
declare class MemoryBackend implements StorageBackend {
|
|
117
|
+
private readonly store;
|
|
118
|
+
getItem(key: string): string | null;
|
|
119
|
+
setItem(key: string, value: string): void;
|
|
120
|
+
removeItem(key: string): void;
|
|
121
|
+
clear(): void;
|
|
122
|
+
getAllKeys(): string[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Wraps the `NativeModules.LynxStorage` Lynx native module.
|
|
126
|
+
*
|
|
127
|
+
* This backend provides **disk-persistent** storage that survives app restarts,
|
|
128
|
+
* backed by Android SharedPreferences and iOS NSUserDefaults.
|
|
129
|
+
*
|
|
130
|
+
* Requires `@kafitra/lynx-storage` to be installed and registered in the
|
|
131
|
+
* host Android/iOS app:
|
|
132
|
+
*
|
|
133
|
+
* Android: LynxEnv.inst().registerModule("LynxStorage", LynxStorageModule.class)
|
|
134
|
+
* iOS: [globalConfig registerModule:LynxStorageModule.class]
|
|
135
|
+
*/
|
|
136
|
+
declare class NativeStorageBackend implements StorageBackend {
|
|
137
|
+
private readonly native;
|
|
138
|
+
constructor(native: LynxNativeStorage);
|
|
139
|
+
getItem(key: string): string | null;
|
|
140
|
+
setItem(key: string, value: string): void;
|
|
141
|
+
removeItem(key: string): void;
|
|
142
|
+
clear(): void;
|
|
143
|
+
getAllKeys(): string[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Wraps any object that matches the Web Storage / Lynx localStorage API.
|
|
147
|
+
*/
|
|
148
|
+
declare class LocalStorageBackend implements StorageBackend {
|
|
149
|
+
private readonly ls;
|
|
150
|
+
constructor(ls: Storage);
|
|
151
|
+
getItem(key: string): string | null;
|
|
152
|
+
setItem(key: string, value: string): void;
|
|
153
|
+
removeItem(key: string): void;
|
|
154
|
+
clear(): void;
|
|
155
|
+
getAllKeys(): string[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates and returns the best available backend for the current runtime.
|
|
159
|
+
*
|
|
160
|
+
* Resolution order:
|
|
161
|
+
* 1. NativeModules.LynxStorage (Lynx runtime with @kafitra/lynx-storage linked)
|
|
162
|
+
* 2. globalThis.localStorage (browser / jsdom)
|
|
163
|
+
* 3. MemoryBackend (fallback)
|
|
164
|
+
*/
|
|
165
|
+
declare function createDefaultBackend(): StorageBackend;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @kafitra/lynx-async-storage
|
|
169
|
+
*
|
|
170
|
+
* Typed error classes used across the module.
|
|
171
|
+
* All errors extend the built-in Error so they are instanceof-compatible.
|
|
172
|
+
*/
|
|
173
|
+
declare const ErrorCodes: {
|
|
174
|
+
readonly INVALID_KEY: "ERR_ASYNC_STORAGE_INVALID_KEY";
|
|
175
|
+
readonly INVALID_VALUE: "ERR_ASYNC_STORAGE_INVALID_VALUE";
|
|
176
|
+
readonly INVALID_JSON: "ERR_ASYNC_STORAGE_INVALID_JSON";
|
|
177
|
+
readonly BACKEND_FAILURE: "ERR_ASYNC_STORAGE_BACKEND_FAILURE";
|
|
178
|
+
};
|
|
179
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
180
|
+
declare class AsyncStorageError extends Error {
|
|
181
|
+
readonly code: ErrorCode;
|
|
182
|
+
readonly cause?: unknown;
|
|
183
|
+
constructor(code: ErrorCode, message: string, cause?: unknown);
|
|
184
|
+
}
|
|
185
|
+
/** Thrown when a key is not a non-empty string. */
|
|
186
|
+
declare class InvalidKeyError extends AsyncStorageError {
|
|
187
|
+
constructor(key: unknown);
|
|
188
|
+
}
|
|
189
|
+
/** Thrown when a value is not a string. */
|
|
190
|
+
declare class InvalidValueError extends AsyncStorageError {
|
|
191
|
+
constructor(value: unknown);
|
|
192
|
+
}
|
|
193
|
+
/** Thrown when JSON parsing fails during a merge operation. */
|
|
194
|
+
declare class InvalidJsonError extends AsyncStorageError {
|
|
195
|
+
constructor(context: "existing" | "incoming", cause?: unknown);
|
|
196
|
+
}
|
|
197
|
+
/** Thrown when the underlying storage backend raises an exception. */
|
|
198
|
+
declare class BackendError extends AsyncStorageError {
|
|
199
|
+
constructor(operation: string, cause?: unknown);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @kafitra/lynx-async-storage
|
|
204
|
+
*
|
|
205
|
+
* Public barrel export.
|
|
206
|
+
*
|
|
207
|
+
* Default export: shared singleton (mirrors React Native AsyncStorage usage).
|
|
208
|
+
* Named exports: class and types for consumers who need custom instances.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Shared singleton instance – drop-in replacement for React Native AsyncStorage.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import AsyncStorage from '@kafitra/lynx-async-storage';
|
|
217
|
+
*
|
|
218
|
+
* await AsyncStorage.setItem('token', 'abc123');
|
|
219
|
+
* const token = await AsyncStorage.getItem('token'); // 'abc123'
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare const instance: AsyncStorage;
|
|
223
|
+
|
|
224
|
+
export { AsyncStorage, AsyncStorageError, type AsyncStorageInterface, BackendError, ErrorCodes, InvalidJsonError, InvalidKeyError, InvalidValueError, type KeyValuePair, type KeyValueResult, LocalStorageBackend, MemoryBackend, NativeStorageBackend, type StorageBackend, createDefaultBackend, instance as default };
|