strata-storage 2.4.3 → 2.5.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/AI-INTEGRATION-GUIDE.md +115 -261
- package/README.md +426 -182
- package/android/AGENTS.md +34 -0
- package/android/CLAUDE.md +51 -0
- package/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -0
- package/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +191 -27
- package/dist/README.md +426 -182
- package/dist/adapters/capacitor/FilesystemAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/FilesystemAdapter.js +2 -1
- package/dist/adapters/capacitor/PreferencesAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/PreferencesAdapter.js +2 -1
- package/dist/adapters/capacitor/SecureAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/SecureAdapter.js +2 -1
- package/dist/adapters/capacitor/SqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitor/SqliteAdapter.js +2 -1
- package/dist/adapters/web/CacheAdapter.d.ts.map +1 -1
- package/dist/adapters/web/CacheAdapter.js +11 -3
- package/dist/adapters/web/CookieAdapter.d.ts +37 -1
- package/dist/adapters/web/CookieAdapter.d.ts.map +1 -1
- package/dist/adapters/web/CookieAdapter.js +89 -9
- package/dist/adapters/web/IndexedDBAdapter.d.ts.map +1 -1
- package/dist/adapters/web/IndexedDBAdapter.js +10 -2
- package/dist/adapters/web/LocalStorageAdapter.d.ts +31 -0
- package/dist/adapters/web/LocalStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/web/LocalStorageAdapter.js +92 -19
- package/dist/adapters/web/MemoryAdapter.d.ts +24 -0
- package/dist/adapters/web/MemoryAdapter.d.ts.map +1 -1
- package/dist/adapters/web/MemoryAdapter.js +69 -18
- package/dist/adapters/web/SessionStorageAdapter.d.ts +24 -0
- package/dist/adapters/web/SessionStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/web/SessionStorageAdapter.js +71 -9
- package/dist/adapters/web/URLAdapter.d.ts +59 -0
- package/dist/adapters/web/URLAdapter.d.ts.map +1 -0
- package/dist/adapters/web/URLAdapter.js +234 -0
- package/dist/adapters/web/index.d.ts +1 -0
- package/dist/adapters/web/index.d.ts.map +1 -1
- package/dist/adapters/web/index.js +1 -0
- package/dist/android/AGENTS.md +34 -0
- package/dist/android/CLAUDE.md +51 -0
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +35 -0
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +191 -27
- package/dist/capacitor.d.ts.map +1 -1
- package/dist/capacitor.js +2 -1
- package/dist/core/BaseAdapter.d.ts +8 -0
- package/dist/core/BaseAdapter.d.ts.map +1 -1
- package/dist/core/BaseAdapter.js +34 -14
- package/dist/core/Strata.d.ts +56 -2
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +501 -53
- package/dist/features/encryption.d.ts.map +1 -1
- package/dist/features/encryption.js +3 -2
- package/dist/features/integrity.d.ts +16 -0
- package/dist/features/integrity.d.ts.map +1 -0
- package/dist/features/integrity.js +28 -0
- package/dist/features/observer.d.ts.map +1 -1
- package/dist/features/observer.js +2 -1
- package/dist/features/query.d.ts +7 -1
- package/dist/features/query.d.ts.map +1 -1
- package/dist/features/query.js +9 -2
- package/dist/features/sync.d.ts.map +1 -1
- package/dist/features/sync.js +4 -3
- package/dist/index.d.ts +35 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -30
- package/dist/integrations/angular/index.d.ts +158 -0
- package/dist/integrations/angular/index.d.ts.map +1 -0
- package/dist/integrations/angular/index.js +395 -0
- package/dist/integrations/index.d.ts +15 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +18 -0
- package/dist/integrations/react/index.d.ts +75 -0
- package/dist/integrations/react/index.d.ts.map +1 -0
- package/dist/integrations/react/index.js +191 -0
- package/dist/integrations/vue/index.d.ts +103 -0
- package/dist/integrations/vue/index.d.ts.map +1 -0
- package/dist/integrations/vue/index.js +274 -0
- package/dist/ios/AGENTS.md +33 -0
- package/dist/ios/CLAUDE.md +49 -0
- package/dist/ios/Plugin/KeychainStorage.swift +139 -50
- package/dist/ios/Plugin/SQLiteStorage.swift +40 -0
- package/dist/ios/Plugin/StrataStoragePlugin.m +23 -0
- package/dist/ios/Plugin/StrataStoragePlugin.swift +201 -52
- package/dist/package.json +21 -5
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +2 -1
- package/dist/types/index.d.ts +58 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -13
- package/dist/utils/errors.d.ts +7 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +15 -3
- package/dist/utils/index.d.ts +63 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +109 -16
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +63 -0
- package/ios/AGENTS.md +33 -0
- package/ios/CLAUDE.md +49 -0
- package/ios/Plugin/KeychainStorage.swift +139 -50
- package/ios/Plugin/SQLiteStorage.swift +40 -0
- package/ios/Plugin/StrataStoragePlugin.m +23 -0
- package/ios/Plugin/StrataStoragePlugin.swift +201 -52
- package/package.json +31 -20
- package/scripts/build.js +16 -5
- package/scripts/configure.js +2 -6
- package/scripts/postinstall.js +2 -2
- package/Readme.md +0 -271
package/AI-INTEGRATION-GUIDE.md
CHANGED
|
@@ -1,354 +1,208 @@
|
|
|
1
1
|
# AI Integration Guide - strata-storage
|
|
2
2
|
|
|
3
|
-
Quick reference for AI development agents (Claude Code, Cursor, Copilot, etc.) to integrate strata-storage into web and mobile projects.
|
|
3
|
+
Quick reference for AI development agents (Claude Code, Cursor, Copilot, etc.) to integrate `strata-storage` into web and mobile projects. Current version: **2.5.0**.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
yarn add strata-storage
|
|
9
|
-
# or
|
|
10
|
-
npm install strata-storage
|
|
11
9
|
```
|
|
12
10
|
|
|
11
|
+
Zero runtime dependencies. React, Vue, Angular, and `@capacitor/core` are optional peer dependencies — install only what the project uses.
|
|
12
|
+
|
|
13
13
|
## Core Concepts
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
- **
|
|
15
|
+
- **Zero dependencies** — pure TypeScript core.
|
|
16
|
+
- **Provider-free** — `defineStorage()` returns a ready-to-use instance; no React context / Vue plugin / Angular module required.
|
|
17
|
+
- **Lazy init** — importing the package does no I/O; instances initialize on first operation. You rarely call `initialize()`.
|
|
18
|
+
- **One API, many backends** — `storage` types: `memory`, `localStorage`, `sessionStorage`, `indexedDB`, `cookies`, `cache`, `url`, plus native `preferences`, `secure`, `sqlite`, `filesystem` (Capacitor).
|
|
19
|
+
- **Opt-in features** — encryption, compression, TTL, queries, cross-tab sync, integrity, durable writes, mirroring, snapshots. All off by default.
|
|
19
20
|
|
|
20
21
|
## Quick Start
|
|
21
22
|
|
|
22
|
-
###
|
|
23
|
+
### Default instance (simplest)
|
|
23
24
|
|
|
24
25
|
```typescript
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
const storage = new Strata();
|
|
28
|
-
await storage.initialize();
|
|
26
|
+
import { storage } from 'strata-storage';
|
|
29
27
|
|
|
30
|
-
// Set data
|
|
31
|
-
await storage.set('username', 'john_doe');
|
|
32
28
|
await storage.set('user', { id: 1, name: 'John' });
|
|
33
|
-
|
|
34
|
-
// Get data
|
|
35
|
-
const username = await storage.get('username');
|
|
36
29
|
const user = await storage.get<{ id: number; name: string }>('user');
|
|
37
|
-
|
|
38
|
-
// Remove data
|
|
39
|
-
await storage.remove('username');
|
|
40
|
-
|
|
41
|
-
// Clear all
|
|
30
|
+
await storage.remove('user');
|
|
42
31
|
await storage.clear();
|
|
43
32
|
```
|
|
44
33
|
|
|
45
|
-
###
|
|
34
|
+
### Your own configured instance
|
|
46
35
|
|
|
47
36
|
```typescript
|
|
48
|
-
|
|
49
|
-
encryption: {
|
|
50
|
-
enabled: true,
|
|
51
|
-
password: 'your-secure-password',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
await storage.initialize();
|
|
55
|
-
|
|
56
|
-
// Data is automatically encrypted
|
|
57
|
-
await storage.set('secret', { token: 'abc123' });
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### With TTL (Time-To-Live)
|
|
37
|
+
import { defineStorage } from 'strata-storage';
|
|
61
38
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ttl: {
|
|
65
|
-
enabled: true,
|
|
66
|
-
defaultTTL: 3600000, // 1 hour in ms
|
|
67
|
-
},
|
|
39
|
+
export const storage = defineStorage({
|
|
40
|
+
defaultStorages: ['indexedDB', 'localStorage'],
|
|
68
41
|
});
|
|
69
|
-
await storage.initialize();
|
|
70
|
-
|
|
71
|
-
// Expires after 1 hour (default)
|
|
72
|
-
await storage.set('session', { token: '...' });
|
|
73
|
-
|
|
74
|
-
// Custom TTL: expires in 5 minutes
|
|
75
|
-
await storage.set('cache', data, { ttl: 300000 });
|
|
76
42
|
```
|
|
77
43
|
|
|
78
|
-
|
|
44
|
+
`defineStorage()` pre-registers memory, localStorage, sessionStorage, IndexedDB, cookies, and the Cache API. Use `new Strata(config)` + `registerWebAdapters(instance)` only when you need full control.
|
|
45
|
+
|
|
46
|
+
## Storage Options (per operation)
|
|
79
47
|
|
|
80
48
|
```typescript
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
await storage.set('key', value, {
|
|
50
|
+
storage: 'indexedDB', // pick a specific backend (NOTE: option name is `storage`, not `adapter`)
|
|
51
|
+
ttl: 3_600_000, // expire in 1 hour (ms)
|
|
52
|
+
encrypt: true, // async only — requires encryption config + password
|
|
53
|
+
compress: true, // async only
|
|
54
|
+
tags: ['user-data'], // for queries
|
|
55
|
+
metadata: { version: 1 },
|
|
56
|
+
verify: true, // store + check an integrity checksum (2.5.0)
|
|
57
|
+
durable: true, // read back and verify the write (2.5.0)
|
|
86
58
|
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Storage Adapters
|
|
90
59
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
import {
|
|
95
|
-
MemoryAdapter,
|
|
96
|
-
LocalStorageAdapter,
|
|
97
|
-
SessionStorageAdapter,
|
|
98
|
-
IndexedDBAdapter,
|
|
99
|
-
CookieAdapter,
|
|
100
|
-
CacheAdapter,
|
|
101
|
-
} from 'strata-storage';
|
|
102
|
-
|
|
103
|
-
const storage = new Strata();
|
|
104
|
-
storage.registerAdapter(new LocalStorageAdapter());
|
|
105
|
-
storage.registerAdapter(new IndexedDBAdapter());
|
|
106
|
-
await storage.initialize();
|
|
60
|
+
const value = await storage.get('key', { storage: 'indexedDB' });
|
|
107
61
|
```
|
|
108
62
|
|
|
109
|
-
|
|
63
|
+
## Synchronous API (2.5.0)
|
|
110
64
|
|
|
111
|
-
|
|
112
|
-
import { Strata } from 'strata-storage';
|
|
113
|
-
import {
|
|
114
|
-
PreferencesAdapter,
|
|
115
|
-
SQLiteAdapter,
|
|
116
|
-
SecureStorageAdapter,
|
|
117
|
-
FilesystemAdapter,
|
|
118
|
-
} from 'strata-storage/capacitor';
|
|
119
|
-
|
|
120
|
-
const storage = new Strata();
|
|
121
|
-
storage.registerAdapter(new PreferencesAdapter());
|
|
122
|
-
storage.registerAdapter(new SecureStorageAdapter()); // For sensitive data
|
|
123
|
-
await storage.initialize();
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Adapter Selection
|
|
65
|
+
No `await`. Works only on sync-capable adapters: `memory`, `localStorage`, `sessionStorage`, `cookies`, `url`.
|
|
127
66
|
|
|
128
67
|
```typescript
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
68
|
+
storage.setSync('lastTab', 'inbox');
|
|
69
|
+
const tab = storage.getSync<string>('lastTab');
|
|
70
|
+
storage.hasSync('lastTab');
|
|
71
|
+
storage.keysSync(); // aggregates across sync-capable adapters
|
|
72
|
+
storage.removeSync('lastTab');
|
|
73
|
+
storage.clearSync();
|
|
135
74
|
```
|
|
136
75
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
### React
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
import { useStorage } from 'strata-storage/react';
|
|
143
|
-
|
|
144
|
-
function MyComponent() {
|
|
145
|
-
const { value, setValue, remove, loading, error } = useStorage<string>('username');
|
|
76
|
+
Constraints: targeting an async-only adapter (indexedDB, cache, sqlite, filesystem, secure, preferences) throws; `setSync` with `encrypt`/`compress` throws; `getSync` on an encrypted/compressed value throws. Use the async API in those cases.
|
|
146
77
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<div>
|
|
151
|
-
<p>Username: {value}</p>
|
|
152
|
-
<button onClick={() => setValue('new_user')}>Update</button>
|
|
153
|
-
<button onClick={remove}>Remove</button>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
```
|
|
78
|
+
## URL Adapter (2.5.0)
|
|
158
79
|
|
|
159
|
-
|
|
80
|
+
Persist small UI state (tab, filters, pagination) in the URL — survives reload, shareable.
|
|
160
81
|
|
|
161
82
|
```typescript
|
|
162
|
-
import {
|
|
83
|
+
import { defineStorage, URLAdapter } from 'strata-storage';
|
|
163
84
|
|
|
164
|
-
const
|
|
165
|
-
|
|
85
|
+
const storage = defineStorage();
|
|
86
|
+
storage.registerAdapter(new URLAdapter()); // config: { mode: 'query'|'hash', prefix, history, maxLength }
|
|
166
87
|
|
|
167
|
-
|
|
88
|
+
storage.setSync('tab', 'pending', { storage: 'url' });
|
|
89
|
+
const tab = storage.getSync<string>('tab', { storage: 'url' });
|
|
168
90
|
|
|
169
|
-
|
|
170
|
-
import { StorageService } from 'strata-storage/angular';
|
|
171
|
-
|
|
172
|
-
@Component({ ... })
|
|
173
|
-
export class MyComponent {
|
|
174
|
-
constructor(private storage: StorageService) {}
|
|
175
|
-
|
|
176
|
-
async ngOnInit() {
|
|
177
|
-
const value = await this.storage.get('key');
|
|
178
|
-
}
|
|
179
|
-
}
|
|
91
|
+
storage.subscribe((c) => { if (c.key === 'tab') applyTab(c.newValue); }, { storage: 'url' });
|
|
180
92
|
```
|
|
181
93
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
### Strata Class
|
|
185
|
-
|
|
186
|
-
| Method | Description | Returns |
|
|
187
|
-
|--------|-------------|---------|
|
|
188
|
-
| `initialize()` | Initialize storage and adapters | `Promise<void>` |
|
|
189
|
-
| `set(key, value, options?)` | Store a value | `Promise<void>` |
|
|
190
|
-
| `get<T>(key, options?)` | Retrieve a value | `Promise<T \| null>` |
|
|
191
|
-
| `remove(key, options?)` | Remove a value | `Promise<void>` |
|
|
192
|
-
| `clear(options?)` | Clear all values | `Promise<void>` |
|
|
193
|
-
| `has(key, options?)` | Check if key exists | `Promise<boolean>` |
|
|
194
|
-
| `keys(options?)` | Get all keys | `Promise<string[]>` |
|
|
195
|
-
| `registerAdapter(adapter)` | Register storage adapter | `void` |
|
|
196
|
-
| `subscribe(callback)` | Subscribe to changes | `UnsubscribeFunction` |
|
|
94
|
+
Limits: ~2 KB practical URL length; query mode is sent to the server (use `hash` for client-only); browser-only; not durable. Never put secrets in the URL.
|
|
197
95
|
|
|
198
|
-
|
|
96
|
+
## Disaster Recovery (2.5.0, opt-in)
|
|
199
97
|
|
|
200
98
|
```typescript
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
algorithm?: 'AES-GCM';
|
|
208
|
-
};
|
|
209
|
-
compression?: {
|
|
210
|
-
enabled: boolean;
|
|
211
|
-
threshold?: number; // Min bytes to compress
|
|
212
|
-
};
|
|
213
|
-
ttl?: {
|
|
214
|
-
enabled: boolean;
|
|
215
|
-
defaultTTL?: number; // Default expiration in ms
|
|
216
|
-
cleanupInterval?: number;
|
|
217
|
-
};
|
|
218
|
-
sync?: {
|
|
219
|
-
enabled: boolean;
|
|
220
|
-
channel?: string; // BroadcastChannel name
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Storage Options
|
|
99
|
+
const storage = defineStorage({
|
|
100
|
+
integrity: true, // FNV-1a checksum per value, verified on read
|
|
101
|
+
durableWrites: true, // read back + retry each write
|
|
102
|
+
mirror: ['indexedDB'], // copy writes to backups; read-repair on corruption
|
|
103
|
+
autoBackup: { interval: 300_000, storage: 'indexedDB' }, // scheduled snapshots
|
|
104
|
+
});
|
|
226
105
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
adapter?: string; // Specific adapter to use
|
|
230
|
-
ttl?: number; // Custom TTL for this operation
|
|
231
|
-
tags?: string[]; // Tags for querying
|
|
232
|
-
encrypt?: boolean; // Override encryption setting
|
|
233
|
-
compress?: boolean; // Override compression setting
|
|
234
|
-
}
|
|
106
|
+
const backup = await storage.snapshot(); // checksum-verified backup string
|
|
107
|
+
await storage.restore(backup); // throws IntegrityError if corrupted
|
|
235
108
|
```
|
|
236
109
|
|
|
237
|
-
## Advanced Features
|
|
238
|
-
|
|
239
|
-
### Tag-Based Queries
|
|
240
|
-
|
|
241
110
|
```typescript
|
|
242
|
-
|
|
243
|
-
await storage.set('user:1', userData, { tags: ['users', 'active'] });
|
|
244
|
-
await storage.set('user:2', userData, { tags: ['users', 'inactive'] });
|
|
245
|
-
|
|
246
|
-
// Query by tag
|
|
247
|
-
const activeUsers = await storage.query({ tags: ['active'] });
|
|
248
|
-
|
|
249
|
-
// Query with operators
|
|
250
|
-
const results = await storage.query({
|
|
251
|
-
where: {
|
|
252
|
-
age: { $gte: 18 },
|
|
253
|
-
status: 'active',
|
|
254
|
-
},
|
|
255
|
-
});
|
|
111
|
+
import { computeChecksum, verifyChecksum, IntegrityError } from 'strata-storage';
|
|
256
112
|
```
|
|
257
113
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
```typescript
|
|
261
|
-
const storage = new Strata({
|
|
262
|
-
sync: {
|
|
263
|
-
enabled: true,
|
|
264
|
-
channel: 'my-app-storage',
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
// Subscribe to changes (including from other tabs)
|
|
269
|
-
storage.subscribe((event) => {
|
|
270
|
-
console.log('Storage changed:', event.key, event.newValue);
|
|
271
|
-
});
|
|
272
|
-
```
|
|
114
|
+
Honest note: checksums are **non-cryptographic (FNV-1a)** — they detect accidental corruption, not tampering. Use encryption for tamper resistance.
|
|
273
115
|
|
|
274
|
-
|
|
116
|
+
## Framework Integrations (provider-free, 2.5.0)
|
|
275
117
|
|
|
276
|
-
|
|
277
|
-
import { StorageObserver } from 'strata-storage';
|
|
118
|
+
### React
|
|
278
119
|
|
|
279
|
-
|
|
120
|
+
```tsx
|
|
121
|
+
import { defineStorage } from 'strata-storage';
|
|
122
|
+
import { createStrataHooks } from 'strata-storage/react';
|
|
280
123
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
console.log('User changed:', newValue);
|
|
284
|
-
});
|
|
124
|
+
export const storage = defineStorage();
|
|
125
|
+
export const { useStorage, useStorageQuery, useStorageTTL } = createStrataHooks(storage);
|
|
285
126
|
|
|
286
|
-
//
|
|
287
|
-
observer.watchPattern(/^cache:/, (key, newValue) => {
|
|
288
|
-
console.log(`Cache key ${key} changed:`, newValue);
|
|
289
|
-
});
|
|
127
|
+
// in a component: const [value, setValue, loading] = useStorage<string>('key', 'default');
|
|
290
128
|
```
|
|
291
129
|
|
|
292
|
-
|
|
130
|
+
`<StrataProvider instance={storage}>` (or `config={...}`) + the same hooks via context is still supported.
|
|
293
131
|
|
|
294
|
-
###
|
|
132
|
+
### Vue
|
|
295
133
|
|
|
296
134
|
```typescript
|
|
297
|
-
|
|
298
|
-
import {
|
|
299
|
-
|
|
300
|
-
export const storage = new Strata({
|
|
301
|
-
encryption: { enabled: true, password: import.meta.env.VITE_STORAGE_KEY },
|
|
302
|
-
ttl: { enabled: true, defaultTTL: 86400000 }, // 24 hours
|
|
303
|
-
});
|
|
135
|
+
import { defineStorage } from 'strata-storage';
|
|
136
|
+
import { createStrataComposables } from 'strata-storage/vue';
|
|
304
137
|
|
|
305
|
-
|
|
306
|
-
storage
|
|
138
|
+
export const storage = defineStorage();
|
|
139
|
+
export const { useStorage } = createStrataComposables(storage);
|
|
307
140
|
|
|
308
|
-
|
|
141
|
+
// in setup(): const { value, update, loading } = useStorage<string>('key', 'default');
|
|
309
142
|
```
|
|
310
143
|
|
|
311
|
-
|
|
144
|
+
`StrataPlugin` (via `app.use`) is still supported; composables accept an optional instance argument.
|
|
312
145
|
|
|
313
|
-
|
|
314
|
-
import storage from '@/storage';
|
|
146
|
+
### Angular
|
|
315
147
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
148
|
+
```typescript
|
|
149
|
+
import { defineStorage } from 'strata-storage';
|
|
150
|
+
import { provideStrata } from 'strata-storage/angular';
|
|
319
151
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
152
|
+
const storage = defineStorage();
|
|
153
|
+
// bootstrapApplication(App, { providers: [provideStrata(storage)] });
|
|
154
|
+
// inject StrataService — methods return RxJS Observables: this.storage.get('key').subscribe(...)
|
|
323
155
|
```
|
|
324
156
|
|
|
325
|
-
|
|
157
|
+
`StrataModule.forRoot(config)` + `StrataService` is still supported. `STRATA_INSTANCE` token holds the instance.
|
|
326
158
|
|
|
327
|
-
|
|
328
|
-
// capacitor.config.ts - register plugin
|
|
329
|
-
import { registerPlugin } from '@capacitor/core';
|
|
159
|
+
### Capacitor (native)
|
|
330
160
|
|
|
331
|
-
|
|
332
|
-
import {
|
|
161
|
+
```typescript
|
|
162
|
+
import { defineStorage } from 'strata-storage';
|
|
333
163
|
import { PreferencesAdapter, SecureStorageAdapter } from 'strata-storage/capacitor';
|
|
334
164
|
|
|
335
|
-
const storage =
|
|
165
|
+
const storage = defineStorage();
|
|
336
166
|
storage.registerAdapter(new PreferencesAdapter());
|
|
337
167
|
storage.registerAdapter(new SecureStorageAdapter());
|
|
338
|
-
await storage.
|
|
168
|
+
await storage.set('secret', token, { storage: 'secure' });
|
|
339
169
|
```
|
|
340
170
|
|
|
171
|
+
Native adapters depend on the downstream Capacitor project setup; verify behavior on-device.
|
|
172
|
+
|
|
173
|
+
## Strata API (most-used methods)
|
|
174
|
+
|
|
175
|
+
| Method | Returns |
|
|
176
|
+
|--------|---------|
|
|
177
|
+
| `get<T>(key, options?)` | `Promise<T \| null>` |
|
|
178
|
+
| `set<T>(key, value, options?)` | `Promise<void>` |
|
|
179
|
+
| `remove(key, options?)` | `Promise<void>` |
|
|
180
|
+
| `has(key, options?)` | `Promise<boolean>` |
|
|
181
|
+
| `keys(pattern?, options?)` | `Promise<string[]>` |
|
|
182
|
+
| `clear(options?)` | `Promise<void>` |
|
|
183
|
+
| `query<T>(condition, options?)` | `Promise<Array<{ key, value }>>` |
|
|
184
|
+
| `subscribe(cb, options?)` | `UnsubscribeFunction` |
|
|
185
|
+
| `getSync`/`setSync`/`removeSync`/`hasSync`/`keysSync`/`clearSync` | sync equivalents (2.5.0) |
|
|
186
|
+
| `snapshot(options?)` / `restore(snapshot, options?)` | `Promise<string>` / `Promise<void>` (2.5.0) |
|
|
187
|
+
| `getTTL`/`extendTTL`/`persist` | TTL management |
|
|
188
|
+
| `registerAdapter(adapter)` | `void` |
|
|
189
|
+
|
|
341
190
|
## Troubleshooting
|
|
342
191
|
|
|
343
192
|
| Issue | Solution |
|
|
344
193
|
|-------|----------|
|
|
345
|
-
|
|
|
346
|
-
|
|
|
347
|
-
|
|
|
348
|
-
|
|
|
194
|
+
| Framework import fails | Ensure `strata-storage >= 2.5.0` (earlier versions never shipped the built entry points). |
|
|
195
|
+
| "does not support synchronous operations" | The targeted adapter is async-only; use the async API or a sync-capable adapter. |
|
|
196
|
+
| Sync set throws on encrypt/compress | Encryption/compression are async — use `await storage.set(...)`. |
|
|
197
|
+
| `useStrata must be used within <StrataProvider>` | Use `createStrataHooks(instance)` for provider-free code. |
|
|
198
|
+
| Native storage not working | Register Capacitor adapters explicitly; verify on a real device. |
|
|
199
|
+
| URL too long warning | URL adapter is for small state; move bulk data to indexedDB/localStorage. |
|
|
349
200
|
|
|
350
201
|
## Links
|
|
351
202
|
|
|
352
|
-
- [
|
|
203
|
+
- [README](./README.md)
|
|
353
204
|
- [Changelog](./CHANGELOG.md)
|
|
205
|
+
- [Core API](./docs/api/core/strata.md)
|
|
206
|
+
- [URL Adapter](./docs/api/adapters/web/url.md)
|
|
207
|
+
- [Recovery & Integrity](./docs/api/features/recovery.md)
|
|
354
208
|
- [GitHub](https://github.com/aoneahsan/strata-storage)
|