@pyreon/storage 0.6.0 → 0.7.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/lib/types/index.d.ts +210 -530
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +1 -6
- package/lib/types/index2.d.ts +0 -220
- package/lib/types/index2.d.ts.map +0 -1
package/lib/types/index.d.ts
CHANGED
|
@@ -1,540 +1,220 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Signal } from "@pyreon/reactivity";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A signal backed by a storage backend. Behaves like a normal signal
|
|
6
|
+
* but persists writes to the underlying storage mechanism.
|
|
7
|
+
*/
|
|
8
|
+
interface StorageSignal<T> extends Signal<T> {
|
|
9
|
+
/** Remove the value from storage and reset to the default value */
|
|
10
|
+
remove(): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Base options shared by all storage hooks.
|
|
14
|
+
*/
|
|
15
|
+
interface StorageOptions<T> {
|
|
16
|
+
/** Custom serializer — default: JSON.stringify */
|
|
17
|
+
serializer?: (value: T) => string;
|
|
18
|
+
/** Custom deserializer — default: JSON.parse */
|
|
19
|
+
deserializer?: (raw: string) => T;
|
|
20
|
+
/** Called when deserialization fails — returns fallback or void for default */
|
|
21
|
+
onError?: (error: Error) => T | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options for the useCookie hook.
|
|
25
|
+
*/
|
|
26
|
+
interface CookieOptions<T> extends StorageOptions<T> {
|
|
27
|
+
/** Max age in seconds */
|
|
28
|
+
maxAge?: number;
|
|
29
|
+
/** Expiry date (alternative to maxAge) */
|
|
30
|
+
expires?: Date;
|
|
31
|
+
/** Cookie path — default: '/' */
|
|
32
|
+
path?: string;
|
|
33
|
+
/** Cookie domain */
|
|
34
|
+
domain?: string;
|
|
35
|
+
/** HTTPS only — default: false */
|
|
36
|
+
secure?: boolean;
|
|
37
|
+
/** SameSite policy — default: 'lax' */
|
|
38
|
+
sameSite?: 'strict' | 'lax' | 'none';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for the useIndexedDB hook.
|
|
42
|
+
*/
|
|
43
|
+
interface IndexedDBOptions<T> extends StorageOptions<T> {
|
|
44
|
+
/** Database name — default: 'pyreon-storage' */
|
|
45
|
+
dbName?: string;
|
|
46
|
+
/** Object store name — default: 'kv' */
|
|
47
|
+
storeName?: string;
|
|
48
|
+
/** Write debounce in ms — default: 100 */
|
|
49
|
+
debounceMs?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Interface for a custom storage backend used with createStorage.
|
|
53
|
+
*/
|
|
54
|
+
interface StorageBackend {
|
|
55
|
+
/** Read a raw string value by key. Return null if not found. */
|
|
56
|
+
get(key: string): string | null;
|
|
57
|
+
/** Write a raw string value by key */
|
|
58
|
+
set(key: string, value: string): void;
|
|
59
|
+
/** Remove a value by key */
|
|
60
|
+
remove(key: string): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Async variant for backends like IndexedDB.
|
|
64
|
+
*/
|
|
65
|
+
interface AsyncStorageBackend {
|
|
66
|
+
/** Read a raw string value by key */
|
|
67
|
+
get(key: string): Promise<string | null>;
|
|
68
|
+
/** Write a raw string value by key */
|
|
69
|
+
set(key: string, value: string): Promise<void>;
|
|
70
|
+
/** Remove a value by key */
|
|
71
|
+
remove(key: string): Promise<void>;
|
|
33
72
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Get all entries for a specific backend.
|
|
36
|
-
*/
|
|
37
|
-
function getEntriesByBackend(backend) {
|
|
38
|
-
const entries = [];
|
|
39
|
-
for (const entry of registry.values()) if (entry.backend === backend) entries.push(entry);
|
|
40
|
-
return entries;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Clear all entries from the registry. Used for testing.
|
|
44
|
-
*/
|
|
45
|
-
function _resetRegistry() {
|
|
46
|
-
registry.clear();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
73
|
//#endregion
|
|
50
|
-
//#region src/
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Safely get a Web Storage instance (localStorage or sessionStorage).
|
|
82
|
-
* Returns null if not available (SSR, security restrictions, etc.).
|
|
83
|
-
*/
|
|
84
|
-
function getWebStorage(type) {
|
|
85
|
-
if (!isBrowser()) return null;
|
|
86
|
-
try {
|
|
87
|
-
const storage = type === "local" ? window.localStorage : window.sessionStorage;
|
|
88
|
-
const testKey = "__pyreon_storage_test__";
|
|
89
|
-
storage.setItem(testKey, "1");
|
|
90
|
-
storage.removeItem(testKey);
|
|
91
|
-
return storage;
|
|
92
|
-
} catch {
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
74
|
+
//#region src/cookie.d.ts
|
|
75
|
+
/**
|
|
76
|
+
* Set the cookie source string for SSR. Call this once per request
|
|
77
|
+
* with the raw Cookie header value.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* // In your SSR request handler
|
|
82
|
+
* setCookieSource(request.headers.get('cookie') ?? '')
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function setCookieSource(cookieHeader: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* Reactive signal backed by a browser cookie. SSR-compatible when
|
|
88
|
+
* used with setCookieSource().
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const locale = useCookie('locale', 'en', {
|
|
93
|
+
* maxAge: 60 * 60 * 24 * 365, // 1 year
|
|
94
|
+
* path: '/',
|
|
95
|
+
* sameSite: 'lax',
|
|
96
|
+
* })
|
|
97
|
+
* locale() // 'en'
|
|
98
|
+
* locale.set('de') // sets cookie + updates signal
|
|
99
|
+
* locale.remove() // deletes cookie, resets to default
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare function useCookie<T>(key: string, defaultValue: T, options?: CookieOptions<T>): StorageSignal<T>;
|
|
97
103
|
//#endregion
|
|
98
|
-
//#region src/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return serverCookieString;
|
|
128
|
-
}
|
|
129
|
-
function readCookie(key) {
|
|
130
|
-
return parseCookies(getCookieString()).get(key) ?? null;
|
|
131
|
-
}
|
|
132
|
-
function writeCookie(key, value, options) {
|
|
133
|
-
if (!isBrowser()) return;
|
|
134
|
-
const serialized = serialize(value, options.serializer);
|
|
135
|
-
let cookie = `${encodeURIComponent(key)}=${encodeURIComponent(serialized)}`;
|
|
136
|
-
if (options.maxAge !== void 0) cookie += `; max-age=${options.maxAge}`;
|
|
137
|
-
if (options.expires) cookie += `; expires=${options.expires.toUTCString()}`;
|
|
138
|
-
cookie += `; path=${options.path ?? "/"}`;
|
|
139
|
-
if (options.domain) cookie += `; domain=${options.domain}`;
|
|
140
|
-
if (options.secure) cookie += "; secure";
|
|
141
|
-
cookie += `; samesite=${options.sameSite ?? "lax"}`;
|
|
142
|
-
document.cookie = cookie;
|
|
143
|
-
}
|
|
144
|
-
function deleteCookie(key, options) {
|
|
145
|
-
if (!isBrowser()) return;
|
|
146
|
-
let cookie = `${encodeURIComponent(key)}=; max-age=0`;
|
|
147
|
-
cookie += `; path=${options.path ?? "/"}`;
|
|
148
|
-
if (options.domain) cookie += `; domain=${options.domain}`;
|
|
149
|
-
document.cookie = cookie;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Reactive signal backed by a browser cookie. SSR-compatible when
|
|
153
|
-
* used with setCookieSource().
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* const locale = useCookie('locale', 'en', {
|
|
158
|
-
* maxAge: 60 * 60 * 24 * 365, // 1 year
|
|
159
|
-
* path: '/',
|
|
160
|
-
* sameSite: 'lax',
|
|
161
|
-
* })
|
|
162
|
-
* locale() // 'en'
|
|
163
|
-
* locale.set('de') // sets cookie + updates signal
|
|
164
|
-
* locale.remove() // deletes cookie, resets to default
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
function useCookie(key, defaultValue, options = {}) {
|
|
168
|
-
const existing = getEntry("cookie", key);
|
|
169
|
-
if (existing) return existing.signal;
|
|
170
|
-
const raw = readCookie(key);
|
|
171
|
-
const sig = signal(raw !== null ? deserialize(raw, defaultValue, options.deserializer, options.onError) : defaultValue);
|
|
172
|
-
const storageSig = () => sig();
|
|
173
|
-
storageSig.peek = () => sig.peek();
|
|
174
|
-
storageSig.subscribe = listener => sig.subscribe(listener);
|
|
175
|
-
storageSig.direct = updater => sig.direct(updater);
|
|
176
|
-
storageSig.debug = () => sig.debug();
|
|
177
|
-
Object.defineProperty(storageSig, "label", {
|
|
178
|
-
get: () => sig.label,
|
|
179
|
-
set: v => {
|
|
180
|
-
sig.label = v;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
storageSig.set = value => {
|
|
184
|
-
sig.set(value);
|
|
185
|
-
writeCookie(key, value, options);
|
|
186
|
-
};
|
|
187
|
-
storageSig.update = fn => {
|
|
188
|
-
const newValue = fn(sig.peek());
|
|
189
|
-
storageSig.set(newValue);
|
|
190
|
-
};
|
|
191
|
-
storageSig.remove = () => {
|
|
192
|
-
sig.set(defaultValue);
|
|
193
|
-
deleteCookie(key, options);
|
|
194
|
-
removeEntry("cookie", key);
|
|
195
|
-
};
|
|
196
|
-
setEntry("cookie", key, storageSig, defaultValue);
|
|
197
|
-
return storageSig;
|
|
198
|
-
}
|
|
199
|
-
|
|
104
|
+
//#region src/custom.d.ts
|
|
105
|
+
/**
|
|
106
|
+
* Create a custom storage hook backed by any synchronous storage backend.
|
|
107
|
+
* Useful for encrypted storage, in-memory storage, or custom adapters.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* const useEncrypted = createStorage({
|
|
112
|
+
* get: (key) => decrypt(localStorage.getItem(key)),
|
|
113
|
+
* set: (key, value) => localStorage.setItem(key, encrypt(value)),
|
|
114
|
+
* remove: (key) => localStorage.removeItem(key),
|
|
115
|
+
* })
|
|
116
|
+
*
|
|
117
|
+
* const secret = useEncrypted('api-key', '')
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
declare function createStorage(backend: StorageBackend, backendName?: string): <T>(key: string, defaultValue: T, options?: StorageOptions<T>) => StorageSignal<T>;
|
|
121
|
+
/**
|
|
122
|
+
* In-memory storage backend. Useful for SSR, testing, or ephemeral state.
|
|
123
|
+
* Values are lost on page unload.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { useMemoryStorage } from '@pyreon/storage'
|
|
128
|
+
*
|
|
129
|
+
* const temp = useMemoryStorage('key', 'default')
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare const useMemoryStorage: <T>(key: string, defaultValue: T, options?: StorageOptions<T>) => StorageSignal<T>;
|
|
200
133
|
//#endregion
|
|
201
|
-
//#region src/
|
|
202
|
-
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* }
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (existing) return existing.signal;
|
|
222
|
-
let initialValue = defaultValue;
|
|
223
|
-
try {
|
|
224
|
-
const raw = backend.get(key);
|
|
225
|
-
if (raw !== null) initialValue = deserialize(raw, defaultValue, options?.deserializer, options?.onError);
|
|
226
|
-
} catch {}
|
|
227
|
-
const sig = signal(initialValue);
|
|
228
|
-
const storageSig = () => sig();
|
|
229
|
-
storageSig.peek = () => sig.peek();
|
|
230
|
-
storageSig.subscribe = listener => sig.subscribe(listener);
|
|
231
|
-
storageSig.direct = updater => sig.direct(updater);
|
|
232
|
-
storageSig.debug = () => sig.debug();
|
|
233
|
-
Object.defineProperty(storageSig, "label", {
|
|
234
|
-
get: () => sig.label,
|
|
235
|
-
set: v => {
|
|
236
|
-
sig.label = v;
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
storageSig.set = value => {
|
|
240
|
-
sig.set(value);
|
|
241
|
-
try {
|
|
242
|
-
backend.set(key, serialize(value, options?.serializer));
|
|
243
|
-
} catch {}
|
|
244
|
-
};
|
|
245
|
-
storageSig.update = fn => {
|
|
246
|
-
const newValue = fn(sig.peek());
|
|
247
|
-
storageSig.set(newValue);
|
|
248
|
-
};
|
|
249
|
-
storageSig.remove = () => {
|
|
250
|
-
sig.set(defaultValue);
|
|
251
|
-
try {
|
|
252
|
-
backend.remove(key);
|
|
253
|
-
} catch {}
|
|
254
|
-
removeEntry(name, key);
|
|
255
|
-
};
|
|
256
|
-
setEntry(name, key, storageSig, defaultValue);
|
|
257
|
-
return storageSig;
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* In-memory storage backend. Useful for SSR, testing, or ephemeral state.
|
|
262
|
-
* Values are lost on page unload.
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```ts
|
|
266
|
-
* import { useMemoryStorage } from '@pyreon/storage'
|
|
267
|
-
*
|
|
268
|
-
* const temp = useMemoryStorage('key', 'default')
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
|
|
272
|
-
function openDB(dbName, storeName) {
|
|
273
|
-
const cacheKey = `${dbName}:${storeName}`;
|
|
274
|
-
const cached = dbCache.get(cacheKey);
|
|
275
|
-
if (cached) return cached;
|
|
276
|
-
const promise = new Promise((resolve, reject) => {
|
|
277
|
-
const request = indexedDB.open(dbName, 1);
|
|
278
|
-
request.onupgradeneeded = () => {
|
|
279
|
-
const db = request.result;
|
|
280
|
-
if (!db.objectStoreNames.contains(storeName)) db.createObjectStore(storeName);
|
|
281
|
-
};
|
|
282
|
-
request.onsuccess = () => resolve(request.result);
|
|
283
|
-
request.onerror = () => reject(request.error);
|
|
284
|
-
});
|
|
285
|
-
dbCache.set(cacheKey, promise);
|
|
286
|
-
return promise;
|
|
287
|
-
}
|
|
288
|
-
function idbGet(db, storeName, key) {
|
|
289
|
-
return new Promise((resolve, reject) => {
|
|
290
|
-
const request = db.transaction(storeName, "readonly").objectStore(storeName).get(key);
|
|
291
|
-
request.onsuccess = () => resolve(request.result !== void 0 ? request.result : null);
|
|
292
|
-
request.onerror = () => reject(request.error);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
function idbSet(db, storeName, key, value) {
|
|
296
|
-
return new Promise((resolve, reject) => {
|
|
297
|
-
const request = db.transaction(storeName, "readwrite").objectStore(storeName).put(value, key);
|
|
298
|
-
request.onsuccess = () => resolve();
|
|
299
|
-
request.onerror = () => reject(request.error);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function idbDelete(db, storeName, key) {
|
|
303
|
-
return new Promise((resolve, reject) => {
|
|
304
|
-
const request = db.transaction(storeName, "readwrite").objectStore(storeName).delete(key);
|
|
305
|
-
request.onsuccess = () => resolve();
|
|
306
|
-
request.onerror = () => reject(request.error);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Reactive signal backed by IndexedDB. Suitable for large or structured
|
|
311
|
-
* data that exceeds localStorage limits. Writes are debounced.
|
|
312
|
-
*
|
|
313
|
-
* The signal starts with `defaultValue` and updates asynchronously
|
|
314
|
-
* when the stored value is read from IndexedDB.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* ```ts
|
|
318
|
-
* const draft = useIndexedDB('article-draft', { title: '', body: '' })
|
|
319
|
-
* draft() // { title: '', body: '' } initially, then stored value
|
|
320
|
-
* draft.set({ title: 'My Post', body: '...' }) // signal updates immediately, IDB write is debounced
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
function useIndexedDB(key, defaultValue, options = {}) {
|
|
324
|
-
const existing = getEntry("indexeddb", key);
|
|
325
|
-
if (existing) return existing.signal;
|
|
326
|
-
const dbName = options.dbName ?? "pyreon-storage";
|
|
327
|
-
const storeName = options.storeName ?? "kv";
|
|
328
|
-
const debounceMs = options.debounceMs ?? 100;
|
|
329
|
-
const sig = signal(defaultValue);
|
|
330
|
-
if (isBrowser() && typeof indexedDB !== "undefined") openDB(dbName, storeName).then(db => idbGet(db, storeName, key)).then(raw => {
|
|
331
|
-
if (raw !== null) {
|
|
332
|
-
const value = deserialize(raw, defaultValue, options.deserializer, options.onError);
|
|
333
|
-
sig.set(value);
|
|
334
|
-
}
|
|
335
|
-
}).catch(() => {});
|
|
336
|
-
let writeTimer = null;
|
|
337
|
-
let pendingValue;
|
|
338
|
-
function flushWrite() {
|
|
339
|
-
if (pendingValue === void 0) return;
|
|
340
|
-
const value = pendingValue;
|
|
341
|
-
pendingValue = void 0;
|
|
342
|
-
if (!isBrowser() || typeof indexedDB === "undefined") return;
|
|
343
|
-
openDB(dbName, storeName).then(db => idbSet(db, storeName, key, serialize(value, options.serializer))).catch(() => {});
|
|
344
|
-
}
|
|
345
|
-
function scheduleWrite(value) {
|
|
346
|
-
pendingValue = value;
|
|
347
|
-
if (writeTimer !== null) clearTimeout(writeTimer);
|
|
348
|
-
writeTimer = setTimeout(flushWrite, debounceMs);
|
|
349
|
-
}
|
|
350
|
-
const storageSig = () => sig();
|
|
351
|
-
storageSig.peek = () => sig.peek();
|
|
352
|
-
storageSig.subscribe = listener => sig.subscribe(listener);
|
|
353
|
-
storageSig.direct = updater => sig.direct(updater);
|
|
354
|
-
storageSig.debug = () => sig.debug();
|
|
355
|
-
Object.defineProperty(storageSig, "label", {
|
|
356
|
-
get: () => sig.label,
|
|
357
|
-
set: v => {
|
|
358
|
-
sig.label = v;
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
storageSig.set = value => {
|
|
362
|
-
sig.set(value);
|
|
363
|
-
scheduleWrite(value);
|
|
364
|
-
};
|
|
365
|
-
storageSig.update = fn => {
|
|
366
|
-
const newValue = fn(sig.peek());
|
|
367
|
-
storageSig.set(newValue);
|
|
368
|
-
};
|
|
369
|
-
storageSig.remove = () => {
|
|
370
|
-
sig.set(defaultValue);
|
|
371
|
-
pendingValue = void 0;
|
|
372
|
-
if (writeTimer !== null) clearTimeout(writeTimer);
|
|
373
|
-
if (isBrowser() && typeof indexedDB !== "undefined") openDB(dbName, storeName).then(db => idbDelete(db, storeName, key)).catch(() => {});
|
|
374
|
-
removeEntry("indexeddb", key);
|
|
375
|
-
};
|
|
376
|
-
setEntry("indexeddb", key, storageSig, defaultValue);
|
|
377
|
-
return storageSig;
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Reset the database cache. For testing only.
|
|
381
|
-
*/
|
|
382
|
-
function _resetDBCache() {
|
|
383
|
-
dbCache.clear();
|
|
384
|
-
}
|
|
385
|
-
|
|
134
|
+
//#region src/indexed-db.d.ts
|
|
135
|
+
/**
|
|
136
|
+
* Reactive signal backed by IndexedDB. Suitable for large or structured
|
|
137
|
+
* data that exceeds localStorage limits. Writes are debounced.
|
|
138
|
+
*
|
|
139
|
+
* The signal starts with `defaultValue` and updates asynchronously
|
|
140
|
+
* when the stored value is read from IndexedDB.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* const draft = useIndexedDB('article-draft', { title: '', body: '' })
|
|
145
|
+
* draft() // { title: '', body: '' } initially, then stored value
|
|
146
|
+
* draft.set({ title: 'My Post', body: '...' }) // signal updates immediately, IDB write is debounced
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
declare function useIndexedDB<T>(key: string, defaultValue: T, options?: IndexedDBOptions<T>): StorageSignal<T>;
|
|
150
|
+
/**
|
|
151
|
+
* Reset the database cache. For testing only.
|
|
152
|
+
*/
|
|
153
|
+
declare function _resetDBCache(): void;
|
|
386
154
|
//#endregion
|
|
387
|
-
//#region src/local.ts
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* Reactive signal backed by localStorage. Automatically syncs across
|
|
402
|
-
* browser tabs via the native `storage` event.
|
|
403
|
-
*
|
|
404
|
-
* @example
|
|
405
|
-
* ```ts
|
|
406
|
-
* const theme = useStorage('theme', 'light')
|
|
407
|
-
* theme() // 'light' (or stored value)
|
|
408
|
-
* theme.set('dark') // updates signal + localStorage
|
|
409
|
-
* theme.remove() // clears storage, resets to default
|
|
410
|
-
* ```
|
|
411
|
-
*/
|
|
412
|
-
function useStorage(key, defaultValue, options) {
|
|
413
|
-
const existing = getEntry("local", key);
|
|
414
|
-
if (existing) return existing.signal;
|
|
415
|
-
const storage = getWebStorage("local");
|
|
416
|
-
let initialValue = defaultValue;
|
|
417
|
-
if (storage) {
|
|
418
|
-
const raw = storage.getItem(key);
|
|
419
|
-
if (raw !== null) initialValue = deserialize(raw, defaultValue, options?.deserializer, options?.onError);
|
|
420
|
-
}
|
|
421
|
-
const storageSig = createStorageSignal(signal(initialValue), key, defaultValue, "local", options);
|
|
422
|
-
setEntry("local", key, storageSig, defaultValue);
|
|
423
|
-
attachStorageListener();
|
|
424
|
-
return storageSig;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Wraps a base signal with storage persistence behavior.
|
|
428
|
-
* Used by both useStorage and useSessionStorage.
|
|
429
|
-
*/
|
|
430
|
-
function createStorageSignal(sig, key, defaultValue, backend, options) {
|
|
431
|
-
const storage = getWebStorage(backend);
|
|
432
|
-
const storageSig = () => sig();
|
|
433
|
-
storageSig.peek = () => sig.peek();
|
|
434
|
-
storageSig.subscribe = listener => sig.subscribe(listener);
|
|
435
|
-
storageSig.direct = updater => sig.direct(updater);
|
|
436
|
-
storageSig.debug = () => sig.debug();
|
|
437
|
-
Object.defineProperty(storageSig, "label", {
|
|
438
|
-
get: () => sig.label,
|
|
439
|
-
set: v => {
|
|
440
|
-
sig.label = v;
|
|
441
|
-
}
|
|
442
|
-
});
|
|
443
|
-
storageSig.set = value => {
|
|
444
|
-
sig.set(value);
|
|
445
|
-
if (storage) try {
|
|
446
|
-
storage.setItem(key, serialize(value, options?.serializer));
|
|
447
|
-
} catch {}
|
|
448
|
-
};
|
|
449
|
-
storageSig.update = fn => {
|
|
450
|
-
const newValue = fn(sig.peek());
|
|
451
|
-
storageSig.set(newValue);
|
|
452
|
-
};
|
|
453
|
-
storageSig.remove = () => {
|
|
454
|
-
sig.set(defaultValue);
|
|
455
|
-
if (storage) storage.removeItem(key);
|
|
456
|
-
removeEntry(backend, key);
|
|
457
|
-
};
|
|
458
|
-
return storageSig;
|
|
459
|
-
}
|
|
460
|
-
|
|
155
|
+
//#region src/local.d.ts
|
|
156
|
+
/**
|
|
157
|
+
* Reactive signal backed by localStorage. Automatically syncs across
|
|
158
|
+
* browser tabs via the native `storage` event.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* const theme = useStorage('theme', 'light')
|
|
163
|
+
* theme() // 'light' (or stored value)
|
|
164
|
+
* theme.set('dark') // updates signal + localStorage
|
|
165
|
+
* theme.remove() // clears storage, resets to default
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
declare function useStorage<T>(key: string, defaultValue: T, options?: StorageOptions<T>): StorageSignal<T>;
|
|
461
169
|
//#endregion
|
|
462
|
-
//#region src/session.ts
|
|
463
|
-
/**
|
|
464
|
-
* Reactive signal backed by sessionStorage. Scoped to the current
|
|
465
|
-
* browser tab — does not sync across tabs.
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* const step = useSessionStorage('wizard-step', 0)
|
|
470
|
-
* step() // 0 (or stored value)
|
|
471
|
-
* step.set(3) // updates signal + sessionStorage
|
|
472
|
-
* step.remove() // clears storage, resets to default
|
|
473
|
-
* ```
|
|
474
|
-
*/
|
|
475
|
-
function useSessionStorage(key, defaultValue, options)
|
|
476
|
-
const existing = getEntry("session", key);
|
|
477
|
-
if (existing) return existing.signal;
|
|
478
|
-
const storage = getWebStorage("session");
|
|
479
|
-
let initialValue = defaultValue;
|
|
480
|
-
if (storage) {
|
|
481
|
-
const raw = storage.getItem(key);
|
|
482
|
-
if (raw !== null) initialValue = deserialize(raw, defaultValue, options?.deserializer, options?.onError);
|
|
483
|
-
}
|
|
484
|
-
const storageSig = createStorageSignal(signal(initialValue), key, defaultValue, "session", options);
|
|
485
|
-
setEntry("session", key, storageSig, defaultValue);
|
|
486
|
-
return storageSig;
|
|
487
|
-
}
|
|
488
|
-
|
|
170
|
+
//#region src/session.d.ts
|
|
171
|
+
/**
|
|
172
|
+
* Reactive signal backed by sessionStorage. Scoped to the current
|
|
173
|
+
* browser tab — does not sync across tabs.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const step = useSessionStorage('wizard-step', 0)
|
|
178
|
+
* step() // 0 (or stored value)
|
|
179
|
+
* step.set(3) // updates signal + sessionStorage
|
|
180
|
+
* step.remove() // clears storage, resets to default
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function useSessionStorage<T>(key: string, defaultValue: T, options?: StorageOptions<T>): StorageSignal<T>;
|
|
489
184
|
//#endregion
|
|
490
|
-
//#region src/clear.ts
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
* removeStorage('
|
|
498
|
-
* removeStorage('
|
|
499
|
-
*
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
185
|
+
//#region src/clear.d.ts
|
|
186
|
+
type StorageType = 'local' | 'session' | 'cookie' | 'indexeddb' | 'all';
|
|
187
|
+
/**
|
|
188
|
+
* Remove a specific key from storage and reset its signal to the default value.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* removeStorage('theme') // from localStorage
|
|
193
|
+
* removeStorage('step', { type: 'session' }) // from sessionStorage
|
|
194
|
+
* removeStorage('locale', { type: 'cookie' }) // deletes cookie
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare function removeStorage(key: string, options?: {
|
|
198
|
+
type?: 'local' | 'session' | 'cookie' | 'indexeddb';
|
|
199
|
+
}): void;
|
|
200
|
+
/**
|
|
201
|
+
* Clear all managed storage entries for a specific backend, or all backends.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* clearStorage() // clear all localStorage entries managed by @pyreon/storage
|
|
206
|
+
* clearStorage('session') // clear all sessionStorage entries
|
|
207
|
+
* clearStorage('cookie') // clear all managed cookies
|
|
208
|
+
* clearStorage('all') // clear everything
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function clearStorage(type?: StorageType): void;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/registry.d.ts
|
|
512
214
|
/**
|
|
513
|
-
* Clear all
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
* ```ts
|
|
517
|
-
* clearStorage() // clear all localStorage entries managed by @pyreon/storage
|
|
518
|
-
* clearStorage('session') // clear all sessionStorage entries
|
|
519
|
-
* clearStorage('cookie') // clear all managed cookies
|
|
520
|
-
* clearStorage('all') // clear everything
|
|
521
|
-
* ```
|
|
522
|
-
*/
|
|
523
|
-
function clearStorage(type = "local") {
|
|
524
|
-
if (type === "all") {
|
|
525
|
-
clearBackend("local");
|
|
526
|
-
clearBackend("session");
|
|
527
|
-
clearBackend("cookie");
|
|
528
|
-
clearBackend("indexeddb");
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
clearBackend(type);
|
|
532
|
-
}
|
|
533
|
-
function clearBackend(type) {
|
|
534
|
-
const entries = getEntriesByBackend(type);
|
|
535
|
-
for (const entry of entries) entry.signal.remove();
|
|
536
|
-
}
|
|
537
|
-
|
|
215
|
+
* Clear all entries from the registry. Used for testing.
|
|
216
|
+
*/
|
|
217
|
+
declare function _resetRegistry(): void;
|
|
538
218
|
//#endregion
|
|
539
|
-
export { _resetDBCache, _resetRegistry, clearStorage, createStorage, removeStorage, setCookieSource, useCookie, useIndexedDB, useMemoryStorage, useSessionStorage, useStorage };
|
|
540
|
-
//# sourceMappingURL=
|
|
219
|
+
export { type AsyncStorageBackend, type CookieOptions, type IndexedDBOptions, type StorageBackend, type StorageOptions, type StorageSignal, _resetDBCache, _resetRegistry, clearStorage, createStorage, removeStorage, setCookieSource, useCookie, useIndexedDB, useMemoryStorage, useSessionStorage, useStorage };
|
|
220
|
+
//# sourceMappingURL=index2.d.ts.map
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/registry.ts","../../src/utils.ts","../../src/cookie.ts","../../src/custom.ts","../../src/indexed-db.ts","../../src/local.ts","../../src/session.ts","../../src/clear.ts"],"mappings":";;;;;;;;AAgBA,SAAS,WAAA,CAAY,OAAA,EAAiB,GAAA,EAAqB;EACzD,OAAO,GAAG,OAAA,IAAW,GAAA,EAAA;;;;;AAMvB,SAAgB,QAAA,CACd,OAAA,EACA,GAAA,EAC8B;EAC9B,OAAO,QAAA,CAAS,GAAA,CAAI,WAAA,CAAY,OAAA,EAAS,GAAA,CAAI,CAAC;;;;;AAMhD,SAAgB,QAAA,CACd,OAAA,EACA,GAAA,EACA,MAAA,EACA,YAAA,EACM;EACN,QAAA,CAAS,GAAA,CAAI,WAAA,CAAY,OAAA,EAAS,GAAA,CAAI,EAAE;IAAE,MAAA;IAAQ,YAAA;IAAc;GAAS,CAAC;;;;;AAM5E,SAAgB,WAAA,CAAY,OAAA,EAAiB,GAAA,EAAmB;EAC9D,QAAA,CAAS,MAAA,CAAO,WAAA,CAAY,OAAA,EAAS,GAAA,CAAI,CAAC;;;;;AAM5C,SAAgB,mBAAA,CAAo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,EAAK,UAAA,EAAY,YAAA,CAAa;EAElD,OAAO,UAAA;;;;;;;;;;;;;;;ACrCT,SAAgB,aAAA,CACd,GAAA,EACA,OAAA,EACM;EACN,MAAM,IAAA,GAAO,OAAA,EAAS,IAAA,IAAQ,OAAA;EAC9B,MAAM,KAAA,GAAQ,QAAA,CAAS,IAAA,EAAM,GAAA,CAAI;EAEjC,IAAI,KAAA,EACF,KAAA,CAAM,MAAA,CAAO,MAAA,CAAA,CAAQ,CAAA,KAChB;IAEL,IAAI,IAAA,KAAS,OAAA,IAAW,IAAA,KAAS,SAAA,EAAW;MAC1C,MAAM,OAAA,GAAU,aAAA,CAAc,IAAA,CAAK;MACnC,IAAI,OAAA,EAAS,OAAA,CAAQ,UAAA,CAAW,GAAA,CAAI;eAC3B,IAAA,KAAS,QAAA,IAAY,SAAA,CAAA,CAAW,EAEzC,QAAA,CAAS,MAAA,GAAS,GAAG,kBAAA,CAAmB,GAAA,CAAI,sBAAC;IAE/C,WAAA,CAAY,IAAA,EAAM,GAAA,CAAI;;;;;;;;;;;;;;AAiB1B,SAAgB,YAAA,CAAa,IAAA,GAAoB,OAAA,EAAe;EAC9D,IAAI,IAAA,KAAS,KAAA,EAAO;IAClB,YAAA,CAAa,OAAA,CAAQ;IACrB,YAAA,CAAa,SAAA,CAAU;IACvB,YAAA,CAAa,QAAA,CAAS;IACtB,YAAA,CAAa,WAAA,CAAY;IACzB;;EAGF,YAAA,CAAa,IAAA,CAAK;;AAGpB,SAAS,YAAA,CAAa,IAAA,EAAoB;EACxC,MAAM,OAAA,GAAU,mBAAA,CAAoB,IAAA,CAAK;EACzC,KAAK,MAAM,KAAA,IAAS,OAAA,EAClB,KAAA,CAAM,MAAA,CAAO,MAAA,CAAA,CAAQ"}
|
|
1
|
+
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../../src/types.ts","../../../src/cookie.ts","../../../src/custom.ts","../../../src/indexed-db.ts","../../../src/local.ts","../../../src/session.ts","../../../src/clear.ts","../../../src/regist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;;;;;;;cAwFN,gBAAA,MA5FR,GAAA,UACQ,YAAA,EACG,CAAA,EAAC,OAAA,GACL,cAAA,CAAe,CAAA,MACtB,aAAA,CAAc,CAAA;;;;;AFrBnB;;;;;;;;;;AAUA;;iBG0EgB,YAAA,GAAA,CACd,GAAA,UACA,YAAA,EAAc,CAAA,EACd,OAAA,GAAS,gBAAA,CAAiB,CAAA,IACzB,aAAA,CAAc,CAAA;;;;iBA0GD,aAAA,CAAA;;;;AHlMhB;;;;;;;;;;AAUA;iBIuBgB,UAAA,GAAA,CACd,GAAA,UACA,YAAA,EAAc,CAAA,EACd,OAAA,GAAU,cAAA,CAAe,CAAA,IACxB,aAAA,CAAc,CAAA;;;;;AJrCjB;;;;;;;;;;iBKYgB,iBAAA,GAAA,CACd,GAAA,UACA,YAAA,EAAc,CAAA,EACd,OAAA,GAAU,cAAA,CAAe,CAAA,IACxB,aAAA,CAAc,CAAA;;;KCnBZ,WAAA;;;ANGL;;;;;;;;iBMWgB,aAAA,CACd,GAAA,UACA,OAAA;EAAY,IAAA;AAAA;;;;;;;;;;;;iBAiCE,YAAA,CAAa,IAAA,GAAM,WAAA;;;;;;iBCSnB,cAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Reactive client-side storage for Pyreon — localStorage, sessionStorage, cookies, IndexedDB",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,10 +41,5 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@pyreon/reactivity": ">=0.5.0 <1.0.0"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@happy-dom/global-registrator": "^20.8.3",
|
|
47
|
-
"@pyreon/reactivity": ">=0.5.0 <1.0.0",
|
|
48
|
-
"@vitus-labs/tools-lint": "^1.11.0"
|
|
49
44
|
}
|
|
50
45
|
}
|
package/lib/types/index2.d.ts
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import { Signal, signal } from "@pyreon/reactivity";
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* A signal backed by a storage backend. Behaves like a normal signal
|
|
6
|
-
* but persists writes to the underlying storage mechanism.
|
|
7
|
-
*/
|
|
8
|
-
interface StorageSignal<T> extends Signal<T> {
|
|
9
|
-
/** Remove the value from storage and reset to the default value */
|
|
10
|
-
remove(): void;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Base options shared by all storage hooks.
|
|
14
|
-
*/
|
|
15
|
-
interface StorageOptions<T> {
|
|
16
|
-
/** Custom serializer — default: JSON.stringify */
|
|
17
|
-
serializer?: (value: T) => string;
|
|
18
|
-
/** Custom deserializer — default: JSON.parse */
|
|
19
|
-
deserializer?: (raw: string) => T;
|
|
20
|
-
/** Called when deserialization fails — returns fallback or void for default */
|
|
21
|
-
onError?: (error: Error) => T | undefined;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Options for the useCookie hook.
|
|
25
|
-
*/
|
|
26
|
-
interface CookieOptions<T> extends StorageOptions<T> {
|
|
27
|
-
/** Max age in seconds */
|
|
28
|
-
maxAge?: number;
|
|
29
|
-
/** Expiry date (alternative to maxAge) */
|
|
30
|
-
expires?: Date;
|
|
31
|
-
/** Cookie path — default: '/' */
|
|
32
|
-
path?: string;
|
|
33
|
-
/** Cookie domain */
|
|
34
|
-
domain?: string;
|
|
35
|
-
/** HTTPS only — default: false */
|
|
36
|
-
secure?: boolean;
|
|
37
|
-
/** SameSite policy — default: 'lax' */
|
|
38
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Options for the useIndexedDB hook.
|
|
42
|
-
*/
|
|
43
|
-
interface IndexedDBOptions<T> extends StorageOptions<T> {
|
|
44
|
-
/** Database name — default: 'pyreon-storage' */
|
|
45
|
-
dbName?: string;
|
|
46
|
-
/** Object store name — default: 'kv' */
|
|
47
|
-
storeName?: string;
|
|
48
|
-
/** Write debounce in ms — default: 100 */
|
|
49
|
-
debounceMs?: number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Interface for a custom storage backend used with createStorage.
|
|
53
|
-
*/
|
|
54
|
-
interface StorageBackend {
|
|
55
|
-
/** Read a raw string value by key. Return null if not found. */
|
|
56
|
-
get(key: string): string | null;
|
|
57
|
-
/** Write a raw string value by key */
|
|
58
|
-
set(key: string, value: string): void;
|
|
59
|
-
/** Remove a value by key */
|
|
60
|
-
remove(key: string): void;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Async variant for backends like IndexedDB.
|
|
64
|
-
*/
|
|
65
|
-
interface AsyncStorageBackend {
|
|
66
|
-
/** Read a raw string value by key */
|
|
67
|
-
get(key: string): Promise<string | null>;
|
|
68
|
-
/** Write a raw string value by key */
|
|
69
|
-
set(key: string, value: string): Promise<void>;
|
|
70
|
-
/** Remove a value by key */
|
|
71
|
-
remove(key: string): Promise<void>;
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/cookie.d.ts
|
|
75
|
-
/**
|
|
76
|
-
* Set the cookie source string for SSR. Call this once per request
|
|
77
|
-
* with the raw Cookie header value.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* // In your SSR request handler
|
|
82
|
-
* setCookieSource(request.headers.get('cookie') ?? '')
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function setCookieSource(cookieHeader: string): void;
|
|
86
|
-
/**
|
|
87
|
-
* Reactive signal backed by a browser cookie. SSR-compatible when
|
|
88
|
-
* used with setCookieSource().
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* const locale = useCookie('locale', 'en', {
|
|
93
|
-
* maxAge: 60 * 60 * 24 * 365, // 1 year
|
|
94
|
-
* path: '/',
|
|
95
|
-
* sameSite: 'lax',
|
|
96
|
-
* })
|
|
97
|
-
* locale() // 'en'
|
|
98
|
-
* locale.set('de') // sets cookie + updates signal
|
|
99
|
-
* locale.remove() // deletes cookie, resets to default
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
declare function useCookie<T>(key: string, defaultValue: T, options?: CookieOptions<T>): StorageSignal<T>;
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/custom.d.ts
|
|
105
|
-
/**
|
|
106
|
-
* Create a custom storage hook backed by any synchronous storage backend.
|
|
107
|
-
* Useful for encrypted storage, in-memory storage, or custom adapters.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const useEncrypted = createStorage({
|
|
112
|
-
* get: (key) => decrypt(localStorage.getItem(key)),
|
|
113
|
-
* set: (key, value) => localStorage.setItem(key, encrypt(value)),
|
|
114
|
-
* remove: (key) => localStorage.removeItem(key),
|
|
115
|
-
* })
|
|
116
|
-
*
|
|
117
|
-
* const secret = useEncrypted('api-key', '')
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
declare function createStorage(backend: StorageBackend, backendName?: string): <T>(key: string, defaultValue: T, options?: StorageOptions<T>) => StorageSignal<T>;
|
|
121
|
-
/**
|
|
122
|
-
* In-memory storage backend. Useful for SSR, testing, or ephemeral state.
|
|
123
|
-
* Values are lost on page unload.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* import { useMemoryStorage } from '@pyreon/storage'
|
|
128
|
-
*
|
|
129
|
-
* const temp = useMemoryStorage('key', 'default')
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
declare const useMemoryStorage: <T>(key: string, defaultValue: T, options?: StorageOptions<T>) => StorageSignal<T>;
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/indexed-db.d.ts
|
|
135
|
-
/**
|
|
136
|
-
* Reactive signal backed by IndexedDB. Suitable for large or structured
|
|
137
|
-
* data that exceeds localStorage limits. Writes are debounced.
|
|
138
|
-
*
|
|
139
|
-
* The signal starts with `defaultValue` and updates asynchronously
|
|
140
|
-
* when the stored value is read from IndexedDB.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* const draft = useIndexedDB('article-draft', { title: '', body: '' })
|
|
145
|
-
* draft() // { title: '', body: '' } initially, then stored value
|
|
146
|
-
* draft.set({ title: 'My Post', body: '...' }) // signal updates immediately, IDB write is debounced
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
declare function useIndexedDB<T>(key: string, defaultValue: T, options?: IndexedDBOptions<T>): StorageSignal<T>;
|
|
150
|
-
/**
|
|
151
|
-
* Reset the database cache. For testing only.
|
|
152
|
-
*/
|
|
153
|
-
declare function _resetDBCache(): void;
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/local.d.ts
|
|
156
|
-
/**
|
|
157
|
-
* Reactive signal backed by localStorage. Automatically syncs across
|
|
158
|
-
* browser tabs via the native `storage` event.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* const theme = useStorage('theme', 'light')
|
|
163
|
-
* theme() // 'light' (or stored value)
|
|
164
|
-
* theme.set('dark') // updates signal + localStorage
|
|
165
|
-
* theme.remove() // clears storage, resets to default
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
declare function useStorage<T>(key: string, defaultValue: T, options?: StorageOptions<T>): StorageSignal<T>;
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region src/session.d.ts
|
|
171
|
-
/**
|
|
172
|
-
* Reactive signal backed by sessionStorage. Scoped to the current
|
|
173
|
-
* browser tab — does not sync across tabs.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```ts
|
|
177
|
-
* const step = useSessionStorage('wizard-step', 0)
|
|
178
|
-
* step() // 0 (or stored value)
|
|
179
|
-
* step.set(3) // updates signal + sessionStorage
|
|
180
|
-
* step.remove() // clears storage, resets to default
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
declare function useSessionStorage<T>(key: string, defaultValue: T, options?: StorageOptions<T>): StorageSignal<T>;
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region src/clear.d.ts
|
|
186
|
-
type StorageType = 'local' | 'session' | 'cookie' | 'indexeddb' | 'all';
|
|
187
|
-
/**
|
|
188
|
-
* Remove a specific key from storage and reset its signal to the default value.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* ```ts
|
|
192
|
-
* removeStorage('theme') // from localStorage
|
|
193
|
-
* removeStorage('step', { type: 'session' }) // from sessionStorage
|
|
194
|
-
* removeStorage('locale', { type: 'cookie' }) // deletes cookie
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
declare function removeStorage(key: string, options?: {
|
|
198
|
-
type?: 'local' | 'session' | 'cookie' | 'indexeddb';
|
|
199
|
-
}): void;
|
|
200
|
-
/**
|
|
201
|
-
* Clear all managed storage entries for a specific backend, or all backends.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* clearStorage() // clear all localStorage entries managed by @pyreon/storage
|
|
206
|
-
* clearStorage('session') // clear all sessionStorage entries
|
|
207
|
-
* clearStorage('cookie') // clear all managed cookies
|
|
208
|
-
* clearStorage('all') // clear everything
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
declare function clearStorage(type?: StorageType): void;
|
|
212
|
-
//#endregion
|
|
213
|
-
//#region src/registry.d.ts
|
|
214
|
-
/**
|
|
215
|
-
* Clear all entries from the registry. Used for testing.
|
|
216
|
-
*/
|
|
217
|
-
declare function _resetRegistry(): void;
|
|
218
|
-
//#endregion
|
|
219
|
-
export { type AsyncStorageBackend, type CookieOptions, type IndexedDBOptions, type StorageBackend, type StorageOptions, type StorageSignal, _resetDBCache, _resetRegistry, clearStorage, createStorage, removeStorage, setCookieSource, useCookie, useIndexedDB, useMemoryStorage, useSessionStorage, useStorage };
|
|
220
|
-
//# sourceMappingURL=index2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index2.d.ts","names":[],"sources":["../../src/types.ts","../../src/cookie.ts","../../src/custom.ts","../../src/indexed-db.ts","../../src/local.ts","../../src/session.ts","../../src/clear.ts","../../src/registry.ts"],"mappings":";;;;;AAQA;;UAAiB,aAAA,YAAyB,MAAA,CAAO,CAAA;EAAD;EAE9C,MAAA;AAAA;;;;UAQe,cAAA;EAAA;EAEf,UAAA,IAAc,KAAA,EAAO,CAAA;EAFQ;EAI7B,YAAA,IAAgB,GAAA,aAAgB,CAAA;EAAA;EAEhC,OAAA,IAAW,KAAA,EAAO,KAAA,KAAU,CAAA;AAAA;;;;UAQb,aAAA,YAAyB,cAAA,CAAe,CAAA;EAZlC;EAcrB,MAAA;EAZA;EAcA,OAAA,GAAU,IAAA;EAdsB;EAgBhC,IAAA;EAdkB;EAgBlB,MAAA;EAhB4B;EAkB5B,MAAA;EAlB6B;EAoB7B,QAAA;AAAA;;;;UAQe,gBAAA,YAA4B,cAAA,CAAe,CAAA;EApBJ;EAsBtD,MAAA;EAtB6B;EAwB7B,SAAA;EAxBuD;EA0BvD,UAAA;AAAA;;;;UAQe,cAAA;EAtBf;EAwBA,GAAA,CAAI,GAAA;EAxBI;EA0BR,GAAA,CAAI,GAAA,UAAa,KAAA;EAlBc;EAoB/B,MAAA,CAAO,GAAA;AAAA;;;;UAMQ,mBAAA;EAtBf;EAwBA,GAAA,CAAI,GAAA,WAAc,OAAA;EAtBR;EAwBV,GAAA,CAAI,GAAA,UAAa,KAAA,WAAgB,OAAA;EAhBlB;EAkBf,MAAA,CAAO,GAAA,WAAc,OAAA;AAAA;;;;;AA5EvB;;;;;;;;iBCWgB,eAAA,CAAgB,YAAA;;ADDhC;;;;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