strata-storage 2.4.2 → 2.4.3

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.
@@ -0,0 +1,354 @@
1
+ # AI Integration Guide - strata-storage
2
+
3
+ Quick reference for AI development agents (Claude Code, Cursor, Copilot, etc.) to integrate strata-storage into web and mobile projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ yarn add strata-storage
9
+ # or
10
+ npm install strata-storage
11
+ ```
12
+
13
+ ## Core Concepts
14
+
15
+ strata-storage provides:
16
+ - **Zero Dependencies** - Pure TypeScript, no runtime deps
17
+ - **9 Storage Adapters** - Memory, LocalStorage, SessionStorage, IndexedDB, Cookies, Cache, Preferences, SQLite, Secure, Filesystem
18
+ - **Advanced Features** - Encryption, compression, TTL, queries, cross-tab sync
19
+
20
+ ## Quick Start
21
+
22
+ ### Basic Usage
23
+
24
+ ```typescript
25
+ import { Strata } from 'strata-storage';
26
+
27
+ const storage = new Strata();
28
+ await storage.initialize();
29
+
30
+ // Set data
31
+ await storage.set('username', 'john_doe');
32
+ await storage.set('user', { id: 1, name: 'John' });
33
+
34
+ // Get data
35
+ const username = await storage.get('username');
36
+ const user = await storage.get<{ id: number; name: string }>('user');
37
+
38
+ // Remove data
39
+ await storage.remove('username');
40
+
41
+ // Clear all
42
+ await storage.clear();
43
+ ```
44
+
45
+ ### With Encryption
46
+
47
+ ```typescript
48
+ const storage = new Strata({
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)
61
+
62
+ ```typescript
63
+ const storage = new Strata({
64
+ ttl: {
65
+ enabled: true,
66
+ defaultTTL: 3600000, // 1 hour in ms
67
+ },
68
+ });
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
+ ```
77
+
78
+ ### With Compression
79
+
80
+ ```typescript
81
+ const storage = new Strata({
82
+ compression: {
83
+ enabled: true,
84
+ threshold: 1024, // Compress data > 1KB
85
+ },
86
+ });
87
+ ```
88
+
89
+ ## Storage Adapters
90
+
91
+ ### Web Adapters
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();
107
+ ```
108
+
109
+ ### Capacitor/Mobile Adapters
110
+
111
+ ```typescript
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
127
+
128
+ ```typescript
129
+ // Use specific adapter
130
+ await storage.set('key', 'value', { adapter: 'localStorage' });
131
+ await storage.set('secure', 'secret', { adapter: 'secure' });
132
+
133
+ // Get from specific adapter
134
+ const value = await storage.get('key', { adapter: 'indexedDB' });
135
+ ```
136
+
137
+ ## Framework Integrations
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');
146
+
147
+ if (loading) return <div>Loading...</div>;
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
+ ```
158
+
159
+ ### Vue
160
+
161
+ ```typescript
162
+ import { useStorage } from 'strata-storage/vue';
163
+
164
+ const { value, setValue, remove, loading, error } = useStorage<string>('username');
165
+ ```
166
+
167
+ ### Angular
168
+
169
+ ```typescript
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
+ }
180
+ ```
181
+
182
+ ## API Reference
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` |
197
+
198
+ ### Configuration Options
199
+
200
+ ```typescript
201
+ interface StrataConfig {
202
+ defaultStorages?: StorageType[]; // Preferred adapter order
203
+ autoInitialize?: boolean; // Auto-init on first operation
204
+ encryption?: {
205
+ enabled: boolean;
206
+ password: string;
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
226
+
227
+ ```typescript
228
+ interface StorageOptions {
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
+ }
235
+ ```
236
+
237
+ ## Advanced Features
238
+
239
+ ### Tag-Based Queries
240
+
241
+ ```typescript
242
+ // Store with tags
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
+ });
256
+ ```
257
+
258
+ ### Cross-Tab Sync
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
+ ```
273
+
274
+ ### Observer Pattern
275
+
276
+ ```typescript
277
+ import { StorageObserver } from 'strata-storage';
278
+
279
+ const observer = new StorageObserver(storage);
280
+
281
+ // Watch specific key
282
+ observer.watch('user', (newValue, oldValue) => {
283
+ console.log('User changed:', newValue);
284
+ });
285
+
286
+ // Watch pattern
287
+ observer.watchPattern(/^cache:/, (key, newValue) => {
288
+ console.log(`Cache key ${key} changed:`, newValue);
289
+ });
290
+ ```
291
+
292
+ ## Common Patterns
293
+
294
+ ### Initialize Once in App Entry
295
+
296
+ ```typescript
297
+ // src/storage.ts
298
+ import { Strata } from 'strata-storage';
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
+ });
304
+
305
+ // Initialize early in app lifecycle
306
+ storage.initialize();
307
+
308
+ export default storage;
309
+ ```
310
+
311
+ ### Use in Components
312
+
313
+ ```typescript
314
+ import storage from '@/storage';
315
+
316
+ async function saveSettings(settings: Settings) {
317
+ await storage.set('settings', settings);
318
+ }
319
+
320
+ async function loadSettings(): Promise<Settings | null> {
321
+ return await storage.get<Settings>('settings');
322
+ }
323
+ ```
324
+
325
+ ### Capacitor Mobile Setup
326
+
327
+ ```typescript
328
+ // capacitor.config.ts - register plugin
329
+ import { registerPlugin } from '@capacitor/core';
330
+
331
+ // In your app initialization
332
+ import { Strata } from 'strata-storage';
333
+ import { PreferencesAdapter, SecureStorageAdapter } from 'strata-storage/capacitor';
334
+
335
+ const storage = new Strata();
336
+ storage.registerAdapter(new PreferencesAdapter());
337
+ storage.registerAdapter(new SecureStorageAdapter());
338
+ await storage.initialize();
339
+ ```
340
+
341
+ ## Troubleshooting
342
+
343
+ | Issue | Solution |
344
+ |-------|----------|
345
+ | Data not persisting | Ensure `initialize()` is called before operations |
346
+ | Encryption errors | Check password is consistent, use env vars |
347
+ | Mobile storage not working | Register Capacitor adapters explicitly |
348
+ | Cross-tab not syncing | Enable sync in config, use same channel name |
349
+
350
+ ## Links
351
+
352
+ - [Full Documentation](./README.md)
353
+ - [Changelog](./CHANGELOG.md)
354
+ - [GitHub](https://github.com/aoneahsan/strata-storage)
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Strata Storage
2
2
 
3
+ - **[AI Integration Guide](./AI-INTEGRATION-GUIDE.md)** - Quick reference for AI development agents (Claude, Cursor, Copilot)
4
+
3
5
  > Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms.
4
6
 
5
7
  [![npm version](https://img.shields.io/npm/v/strata-storage.svg)](https://www.npmjs.com/package/strata-storage)
package/dist/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Strata Storage
2
2
 
3
+ - **[AI Integration Guide](./AI-INTEGRATION-GUIDE.md)** - Quick reference for AI development agents (Claude, Cursor, Copilot)
4
+
3
5
  > Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms.
4
6
 
5
7
  [![npm version](https://img.shields.io/npm/v/strata-storage.svg)](https://www.npmjs.com/package/strata-storage)
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Support configuration for strata-storage package
3
+ * Help keep this package free and improving
4
+ */
5
+ export declare const SUPPORT_CONFIG: {
6
+ readonly url: "https://aoneahsan.com/payment?project-id=strata-storage&project-identifier=strata-storage";
7
+ readonly label: "Support the Project";
8
+ readonly description: "Help us keep strata-storage free and improving";
9
+ };
10
+ //# sourceMappingURL=support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../src/config/support.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,cAAc;;;;CAIjB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Support configuration for strata-storage package
3
+ * Help keep this package free and improving
4
+ */
5
+ export const SUPPORT_CONFIG = {
6
+ url: 'https://aoneahsan.com/payment?project-id=strata-storage&project-identifier=strata-storage',
7
+ label: 'Support the Project',
8
+ description: 'Help us keep strata-storage free and improving',
9
+ };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-storage",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-storage",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,7 +10,8 @@
10
10
  "ios/",
11
11
  "android/",
12
12
  "scripts/",
13
- "StrataStorage.podspec"
13
+ "StrataStorage.podspec",
14
+ "AI-INTEGRATION-GUIDE.md"
14
15
  ],
15
16
  "bin": {
16
17
  "strata-storage": "./scripts/cli.js"
@@ -48,7 +49,7 @@
48
49
  "typecheck": "tsc --noEmit",
49
50
  "test": "vitest",
50
51
  "test:coverage": "vitest --coverage",
51
- "prepublishOnly": "pnpm build && pnpm lint && pnpm typecheck",
52
+ "prepublishOnly": "yarn build && yarn lint && yarn typecheck",
52
53
  "postinstall": "node scripts/postinstall.js || true"
53
54
  },
54
55
  "keywords": [
@@ -100,19 +101,19 @@
100
101
  }
101
102
  },
102
103
  "devDependencies": {
103
- "@types/node": "^25.0.3",
104
- "@types/react": "^19.2.7",
105
- "@typescript-eslint/eslint-plugin": "^8.50.1",
106
- "@typescript-eslint/parser": "^8.50.1",
107
- "@vitest/coverage-v8": "^4.0.16",
104
+ "@types/node": "^25.0.9",
105
+ "@types/react": "^19.2.9",
106
+ "@typescript-eslint/eslint-plugin": "^8.53.1",
107
+ "@typescript-eslint/parser": "^8.53.1",
108
+ "@vitest/coverage-v8": "^4.0.17",
108
109
  "eslint": "^9.39.2",
109
110
  "eslint-config-prettier": "^10.1.8",
110
- "eslint-plugin-prettier": "^5.5.4",
111
+ "eslint-plugin-prettier": "^5.5.5",
111
112
  "jsdom": "^27.4.0",
112
- "prettier": "^3.7.4",
113
+ "prettier": "^3.8.0",
113
114
  "typescript": "^5.9.3",
114
- "typescript-eslint": "^8.50.1",
115
- "vitest": "^4.0.16"
115
+ "typescript-eslint": "^8.53.1",
116
+ "vitest": "^4.0.17"
116
117
  },
117
118
  "engines": {
118
119
  "node": ">=18.0.0"