@pyreon/storage 0.8.0 → 0.10.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 +74 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @pyreon/storage
|
|
2
|
+
|
|
3
|
+
Reactive client-side storage for Pyreon. Signal-backed persistence across localStorage, sessionStorage, cookies, IndexedDB, and custom backends. Same key returns the same signal instance — no drift between components.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/storage
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { useStorage, useCookie, useSessionStorage, useIndexedDB } from '@pyreon/storage'
|
|
15
|
+
|
|
16
|
+
// localStorage — persistent, cross-tab synced
|
|
17
|
+
const theme = useStorage('theme', 'light')
|
|
18
|
+
theme() // read reactively
|
|
19
|
+
theme.set('dark') // updates signal + localStorage
|
|
20
|
+
theme.remove() // remove from storage
|
|
21
|
+
|
|
22
|
+
// Cookie — SSR-readable, configurable expiry
|
|
23
|
+
const locale = useCookie('locale', 'en', { maxAge: 365 * 86400 })
|
|
24
|
+
|
|
25
|
+
// sessionStorage — tab-scoped
|
|
26
|
+
const wizardStep = useSessionStorage('wizard-step', 0)
|
|
27
|
+
|
|
28
|
+
// IndexedDB — large data, debounced writes
|
|
29
|
+
const draft = useIndexedDB('article-draft', { title: '', body: '' })
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Custom Backends
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { createStorage } from '@pyreon/storage'
|
|
36
|
+
|
|
37
|
+
const useEncryptedStorage = createStorage({
|
|
38
|
+
get: (key) => decrypt(localStorage.getItem(key)),
|
|
39
|
+
set: (key, value) => localStorage.setItem(key, encrypt(value)),
|
|
40
|
+
remove: (key) => localStorage.removeItem(key),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const secret = useEncryptedStorage('api-key', '')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### Hooks
|
|
49
|
+
|
|
50
|
+
| Hook | Backend | Description |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `useStorage(key, default, options?)` | localStorage | Persistent, cross-tab synced |
|
|
53
|
+
| `useSessionStorage(key, default, options?)` | sessionStorage | Tab-scoped |
|
|
54
|
+
| `useCookie(key, default, options?)` | document.cookie | SSR-readable, configurable expiry |
|
|
55
|
+
| `useIndexedDB(key, default, options?)` | IndexedDB | Large data, debounced writes |
|
|
56
|
+
| `useMemoryStorage(key, default)` | in-memory | SSR/testing |
|
|
57
|
+
|
|
58
|
+
All hooks return `StorageSignal<T>` — extends `Signal<T>` with `.remove()`.
|
|
59
|
+
|
|
60
|
+
### `createStorage(backend)`
|
|
61
|
+
|
|
62
|
+
Factory for custom storage backends (encrypted, remote, etc.).
|
|
63
|
+
|
|
64
|
+
### `setCookieSource(header)`
|
|
65
|
+
|
|
66
|
+
Set SSR cookie source for server-side rendering.
|
|
67
|
+
|
|
68
|
+
### `removeStorage(key, options?)` / `clearStorage(type?)`
|
|
69
|
+
|
|
70
|
+
Cleanup utilities for removing stored values.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|