strata-storage 1.5.0 → 2.0.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 +66 -20
- package/dist/README.md +162 -0
- package/dist/adapters/capacitor/FilesystemAdapter.js +4 -4
- package/dist/adapters/capacitor/PreferencesAdapter.js +4 -4
- package/dist/adapters/capacitor/SecureAdapter.js +4 -4
- package/dist/adapters/capacitor/SqliteAdapter.js +4 -4
- package/dist/adapters/capacitor/index.js +4 -4
- package/dist/adapters/web/CacheAdapter.js +3 -3
- package/dist/adapters/web/CookieAdapter.js +2 -2
- package/dist/adapters/web/IndexedDBAdapter.js +3 -3
- package/dist/adapters/web/LocalStorageAdapter.js +3 -3
- package/dist/adapters/web/MemoryAdapter.js +3 -3
- package/dist/adapters/web/SessionStorageAdapter.js +1 -1
- package/dist/adapters/web/index.js +6 -6
- package/dist/android/src/main/java/com/strata/storage/EncryptedStorage.java +65 -0
- package/dist/android/src/main/java/com/strata/storage/SQLiteStorage.java +147 -0
- package/dist/android/src/main/java/com/strata/storage/SharedPreferencesStorage.java +74 -0
- package/dist/android/src/main/java/com/stratastorage/StrataStoragePlugin.java +256 -0
- package/dist/capacitor.d.ts +20 -0
- package/dist/capacitor.d.ts.map +1 -0
- package/dist/capacitor.js +48 -0
- package/dist/core/AdapterRegistry.js +1 -1
- package/dist/core/BaseAdapter.js +3 -3
- package/dist/core/StorageStrategy.js +1 -0
- package/dist/core/Strata.d.ts +28 -3
- package/dist/core/Strata.d.ts.map +1 -1
- package/dist/core/Strata.js +57 -58
- package/dist/features/compression/index.d.ts +2 -0
- package/dist/features/compression/index.d.ts.map +1 -0
- package/dist/features/compression/index.js +1 -0
- package/dist/features/compression.js +1 -1
- package/dist/features/encryption/index.d.ts +2 -0
- package/dist/features/encryption/index.d.ts.map +1 -0
- package/dist/features/encryption/index.js +1 -0
- package/dist/features/encryption.d.ts.map +1 -1
- package/dist/features/encryption.js +6 -5
- package/dist/features/observer/index.d.ts +2 -0
- package/dist/features/observer/index.d.ts.map +1 -0
- package/dist/features/observer/index.js +1 -0
- package/dist/features/observer.d.ts +20 -0
- package/dist/features/observer.d.ts.map +1 -0
- package/dist/features/observer.js +32 -0
- package/dist/features/query/index.d.ts +2 -0
- package/dist/features/query/index.d.ts.map +1 -0
- package/dist/features/query/index.js +1 -0
- package/dist/features/query.d.ts.map +1 -1
- package/dist/features/query.js +8 -1
- package/dist/features/sync/index.d.ts +2 -0
- package/dist/features/sync/index.d.ts.map +1 -0
- package/dist/features/sync/index.js +1 -0
- package/dist/features/sync.js +1 -1
- package/dist/features/ttl/index.d.ts +2 -0
- package/dist/features/ttl/index.d.ts.map +1 -0
- package/dist/features/ttl/index.js +1 -0
- package/dist/features/ttl.js +1 -1
- package/dist/firebase.d.ts +26 -0
- package/dist/firebase.d.ts.map +1 -0
- package/dist/firebase.js +147 -0
- package/dist/index.d.ts +13 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -58
- package/dist/ios/Plugin/KeychainStorage.swift +87 -0
- package/dist/ios/Plugin/SQLiteStorage.swift +167 -0
- package/dist/ios/Plugin/StrataStoragePlugin.swift +204 -0
- package/dist/ios/Plugin/UserDefaultsStorage.swift +44 -0
- package/dist/package.json +22 -4
- package/dist/plugin/definitions.d.ts +2 -2
- package/dist/plugin/definitions.d.ts.map +1 -1
- package/dist/plugin/index.d.ts +2 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +77 -11
- package/dist/types/index.d.ts +190 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +13 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +34 -0
- package/package.json +15 -24
- package/scripts/build.js +127 -14
- package/scripts/cli.js +6 -2
- package/scripts/configure.js +7 -3
- package/scripts/postinstall.js +21 -10
package/Readme.md
CHANGED
|
@@ -23,21 +23,56 @@ Zero-dependency universal storage plugin providing a unified API for all storage
|
|
|
23
23
|
npm install strata-storage
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
### Provider-less Usage (Zero Setup)
|
|
26
27
|
```typescript
|
|
27
|
-
import {
|
|
28
|
+
import { storage } from 'strata-storage';
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
await storage.initialize();
|
|
31
|
-
|
|
32
|
-
// Works everywhere - web, iOS, Android
|
|
30
|
+
// Works immediately - no setup, no providers, no initialization!
|
|
33
31
|
await storage.set('user', { name: 'John', age: 30 });
|
|
34
32
|
const user = await storage.get('user');
|
|
35
33
|
```
|
|
36
34
|
|
|
35
|
+
### With Capacitor (Optional)
|
|
36
|
+
```typescript
|
|
37
|
+
import { storage } from 'strata-storage';
|
|
38
|
+
import { registerCapacitorAdapters } from 'strata-storage/capacitor';
|
|
39
|
+
|
|
40
|
+
// Only if you need native features
|
|
41
|
+
if (window.Capacitor) {
|
|
42
|
+
await registerCapacitorAdapters(storage);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Use native storage when available
|
|
46
|
+
await storage.set('secure-data', 'secret', { storage: 'secure' });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With Firebase (Optional)
|
|
50
|
+
```typescript
|
|
51
|
+
import { storage } from 'strata-storage';
|
|
52
|
+
import { enableFirebaseSync } from 'strata-storage/firebase';
|
|
53
|
+
|
|
54
|
+
// Only if you need cloud sync
|
|
55
|
+
if (needCloudSync) {
|
|
56
|
+
await enableFirebaseSync(storage, {
|
|
57
|
+
apiKey: 'your-api-key',
|
|
58
|
+
projectId: 'your-project-id',
|
|
59
|
+
firestore: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Works offline-first, syncs when online
|
|
64
|
+
await storage.set('data', value, { storage: 'firestore' });
|
|
65
|
+
```
|
|
66
|
+
|
|
37
67
|
## ✨ Features
|
|
38
68
|
|
|
39
69
|
### Core Features
|
|
40
|
-
- ✅ **Zero Dependencies** - No
|
|
70
|
+
- ✅ **Zero Dependencies** - No runtime dependencies, pure implementation
|
|
71
|
+
- ✅ **Provider-less Architecture** - No providers, contexts, or wrappers needed (like zustand)
|
|
72
|
+
- ✅ **Works Everywhere** - React, Vue, Angular, Vanilla JS, Node.js - same API
|
|
73
|
+
- ✅ **Zero Configuration** - Import and use immediately, no setup required
|
|
74
|
+
- ✅ **Opt-in Complexity** - Start simple, add features only when needed
|
|
75
|
+
- ✅ **Dynamic Provider Loading** - Providers load only when used, keeping bundle small
|
|
41
76
|
- ✅ **Universal API** - Single interface for all storage types
|
|
42
77
|
- ✅ **Cross-Platform** - Web, iOS, Android support
|
|
43
78
|
- ✅ **TypeScript** - Full type safety and IntelliSense
|
|
@@ -67,22 +102,23 @@ const user = await storage.get('user');
|
|
|
67
102
|
## 📖 Basic Usage
|
|
68
103
|
|
|
69
104
|
```typescript
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
encryption: { enabled: true },
|
|
74
|
-
compression: { enabled: true },
|
|
75
|
-
ttl: { defaultTTL: 3600000 } // 1 hour
|
|
76
|
-
});
|
|
105
|
+
import { storage } from 'strata-storage';
|
|
106
|
+
|
|
107
|
+
// No initialization needed - works immediately!
|
|
77
108
|
|
|
78
|
-
|
|
109
|
+
// Simple usage
|
|
110
|
+
await storage.set('key', 'value');
|
|
111
|
+
const value = await storage.get('key');
|
|
112
|
+
await storage.remove('key');
|
|
113
|
+
await storage.clear();
|
|
79
114
|
|
|
80
|
-
//
|
|
115
|
+
// Advanced options
|
|
81
116
|
await storage.set('key', value, {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
117
|
+
storage: 'indexedDB', // Choose specific storage
|
|
118
|
+
ttl: 3600000, // Expire in 1 hour
|
|
119
|
+
encrypt: true, // Encrypt this value
|
|
120
|
+
compress: true, // Compress if beneficial
|
|
121
|
+
tags: ['user-data'] // Tag for grouping
|
|
86
122
|
});
|
|
87
123
|
|
|
88
124
|
// Query data
|
|
@@ -97,13 +133,23 @@ storage.subscribe((change) => {
|
|
|
97
133
|
});
|
|
98
134
|
```
|
|
99
135
|
|
|
136
|
+
## 🎯 Provider-less Architecture
|
|
137
|
+
|
|
138
|
+
Strata Storage follows a provider-less architecture similar to Zustand. The core library works everywhere with zero dependencies, and platform-specific features (like Capacitor) are completely optional.
|
|
139
|
+
|
|
140
|
+
- **Minimal by default** - Only includes web storage adapters
|
|
141
|
+
- **Opt-in native features** - Explicitly add Capacitor support when needed
|
|
142
|
+
- **Better tree-shaking** - Unused adapters are eliminated by bundlers
|
|
143
|
+
- **Smaller bundle size** - Web-only projects don't include native code
|
|
144
|
+
|
|
100
145
|
## 🏗 Project Status
|
|
101
146
|
|
|
102
147
|
Currently in active development. Phase 1-5 completed:
|
|
103
148
|
- ✅ Project setup and core architecture
|
|
104
149
|
- ✅ Memory and web storage adapters
|
|
105
|
-
- ✅ Capacitor plugin structure
|
|
150
|
+
- ✅ Capacitor plugin structure (now optional)
|
|
106
151
|
- ✅ Advanced features (encryption, compression, sync, query, TTL)
|
|
152
|
+
- ✅ Provider-less architecture
|
|
107
153
|
- 🚧 Native implementations (iOS/Android)
|
|
108
154
|
- 🚧 Testing and documentation
|
|
109
155
|
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Strata Storage
|
|
2
|
+
|
|
3
|
+
## 📚 Documentation
|
|
4
|
+
|
|
5
|
+
- **[Getting Started](./docs/getting-started/installation.md)** - Installation and setup
|
|
6
|
+
- **[Quick Start Guide](./docs/getting-started/quick-start.md)** - Get running in minutes
|
|
7
|
+
- **[API Reference](./docs/api/README.md)** - Complete API documentation
|
|
8
|
+
- **[Configuration](./docs/getting-started/configuration.md)** - Configuration options
|
|
9
|
+
- **[Platform Guides](./docs/guides/platforms/web.md)** - Platform-specific guides
|
|
10
|
+
- **[Examples](./docs/examples/README.md)** - Code examples and recipes
|
|
11
|
+
- **[GitHub](https://github.com/aoneahsan/strata-storage)** - Source code
|
|
12
|
+
- **[NPM](https://www.npmjs.com/package/strata-storage)** - Package registry
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
**One API. Every Storage. Everywhere.**
|
|
17
|
+
|
|
18
|
+
Zero-dependency universal storage plugin providing a unified API for all storage operations across web, Android, and iOS platforms.
|
|
19
|
+
|
|
20
|
+
## 🚀 Quick Start
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install strata-storage
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Provider-less Usage (Zero Setup)
|
|
27
|
+
```typescript
|
|
28
|
+
import { storage } from 'strata-storage';
|
|
29
|
+
|
|
30
|
+
// Works immediately - no setup, no providers, no initialization!
|
|
31
|
+
await storage.set('user', { name: 'John', age: 30 });
|
|
32
|
+
const user = await storage.get('user');
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### With Capacitor (Optional)
|
|
36
|
+
```typescript
|
|
37
|
+
import { storage } from 'strata-storage';
|
|
38
|
+
import { registerCapacitorAdapters } from 'strata-storage/capacitor';
|
|
39
|
+
|
|
40
|
+
// Only if you need native features
|
|
41
|
+
if (window.Capacitor) {
|
|
42
|
+
await registerCapacitorAdapters(storage);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Use native storage when available
|
|
46
|
+
await storage.set('secure-data', 'secret', { storage: 'secure' });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### With Firebase (Optional)
|
|
50
|
+
```typescript
|
|
51
|
+
import { storage } from 'strata-storage';
|
|
52
|
+
import { enableFirebaseSync } from 'strata-storage/firebase';
|
|
53
|
+
|
|
54
|
+
// Only if you need cloud sync
|
|
55
|
+
if (needCloudSync) {
|
|
56
|
+
await enableFirebaseSync(storage, {
|
|
57
|
+
apiKey: 'your-api-key',
|
|
58
|
+
projectId: 'your-project-id',
|
|
59
|
+
firestore: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Works offline-first, syncs when online
|
|
64
|
+
await storage.set('data', value, { storage: 'firestore' });
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## ✨ Features
|
|
68
|
+
|
|
69
|
+
### Core Features
|
|
70
|
+
- ✅ **Zero Dependencies** - No runtime dependencies, pure implementation
|
|
71
|
+
- ✅ **Provider-less Architecture** - No providers, contexts, or wrappers needed (like zustand)
|
|
72
|
+
- ✅ **Works Everywhere** - React, Vue, Angular, Vanilla JS, Node.js - same API
|
|
73
|
+
- ✅ **Zero Configuration** - Import and use immediately, no setup required
|
|
74
|
+
- ✅ **Opt-in Complexity** - Start simple, add features only when needed
|
|
75
|
+
- ✅ **Dynamic Provider Loading** - Providers load only when used, keeping bundle small
|
|
76
|
+
- ✅ **Universal API** - Single interface for all storage types
|
|
77
|
+
- ✅ **Cross-Platform** - Web, iOS, Android support
|
|
78
|
+
- ✅ **TypeScript** - Full type safety and IntelliSense
|
|
79
|
+
- ✅ **Auto Fallback** - Intelligent storage selection
|
|
80
|
+
|
|
81
|
+
### Storage Adapters
|
|
82
|
+
- ✅ **Memory** - Fast in-memory storage
|
|
83
|
+
- ✅ **LocalStorage** - Persistent browser storage
|
|
84
|
+
- ✅ **SessionStorage** - Session-based browser storage
|
|
85
|
+
- ✅ **IndexedDB** - Large-scale browser database
|
|
86
|
+
- ✅ **Cookies** - HTTP cookie storage
|
|
87
|
+
- ✅ **Cache API** - Service worker cache storage
|
|
88
|
+
- ✅ **Capacitor Preferences** - Native mobile preferences
|
|
89
|
+
- ✅ **SQLite** - Mobile SQL database
|
|
90
|
+
- ✅ **Secure Storage** - Keychain (iOS) / Encrypted SharedPreferences (Android)
|
|
91
|
+
- ✅ **Filesystem** - File-based storage
|
|
92
|
+
|
|
93
|
+
### Advanced Features
|
|
94
|
+
- ✅ **Encryption** - AES-GCM encryption with Web Crypto API
|
|
95
|
+
- ✅ **Compression** - LZ-string compression algorithm
|
|
96
|
+
- ✅ **Cross-Tab Sync** - Real-time synchronization across tabs
|
|
97
|
+
- ✅ **Query Engine** - MongoDB-like queries for filtering data
|
|
98
|
+
- ✅ **TTL Support** - Automatic expiration with sliding TTL
|
|
99
|
+
- ✅ **Migration System** - Version-based data migrations
|
|
100
|
+
- 🚧 **Framework Integrations** - React, Vue, Angular (coming soon)
|
|
101
|
+
|
|
102
|
+
## 📖 Basic Usage
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { storage } from 'strata-storage';
|
|
106
|
+
|
|
107
|
+
// No initialization needed - works immediately!
|
|
108
|
+
|
|
109
|
+
// Simple usage
|
|
110
|
+
await storage.set('key', 'value');
|
|
111
|
+
const value = await storage.get('key');
|
|
112
|
+
await storage.remove('key');
|
|
113
|
+
await storage.clear();
|
|
114
|
+
|
|
115
|
+
// Advanced options
|
|
116
|
+
await storage.set('key', value, {
|
|
117
|
+
storage: 'indexedDB', // Choose specific storage
|
|
118
|
+
ttl: 3600000, // Expire in 1 hour
|
|
119
|
+
encrypt: true, // Encrypt this value
|
|
120
|
+
compress: true, // Compress if beneficial
|
|
121
|
+
tags: ['user-data'] // Tag for grouping
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Query data
|
|
125
|
+
const results = await storage.query({
|
|
126
|
+
tags: { $in: ['user-data'] },
|
|
127
|
+
'value.age': { $gte: 18 }
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Subscribe to changes
|
|
131
|
+
storage.subscribe((change) => {
|
|
132
|
+
console.log(`${change.key} changed from ${change.oldValue} to ${change.newValue}`);
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 🎯 Provider-less Architecture
|
|
137
|
+
|
|
138
|
+
Strata Storage follows a provider-less architecture similar to Zustand. The core library works everywhere with zero dependencies, and platform-specific features (like Capacitor) are completely optional.
|
|
139
|
+
|
|
140
|
+
- **Minimal by default** - Only includes web storage adapters
|
|
141
|
+
- **Opt-in native features** - Explicitly add Capacitor support when needed
|
|
142
|
+
- **Better tree-shaking** - Unused adapters are eliminated by bundlers
|
|
143
|
+
- **Smaller bundle size** - Web-only projects don't include native code
|
|
144
|
+
|
|
145
|
+
## 🏗 Project Status
|
|
146
|
+
|
|
147
|
+
Currently in active development. Phase 1-5 completed:
|
|
148
|
+
- ✅ Project setup and core architecture
|
|
149
|
+
- ✅ Memory and web storage adapters
|
|
150
|
+
- ✅ Capacitor plugin structure (now optional)
|
|
151
|
+
- ✅ Advanced features (encryption, compression, sync, query, TTL)
|
|
152
|
+
- ✅ Provider-less architecture
|
|
153
|
+
- 🚧 Native implementations (iOS/Android)
|
|
154
|
+
- 🚧 Testing and documentation
|
|
155
|
+
|
|
156
|
+
## 📄 License
|
|
157
|
+
|
|
158
|
+
MIT
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
Created by Ahsan Mahmood
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Filesystem Adapter - Native file system storage
|
|
3
3
|
* Direct file access on iOS and Android
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { StrataStorage } from
|
|
7
|
-
import { StorageError } from
|
|
8
|
-
import { isCapacitor } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { StrataStorage } from "../../plugin/index.js";
|
|
7
|
+
import { StorageError } from "../../utils/errors.js";
|
|
8
|
+
import { isCapacitor } from "../../utils/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Native filesystem adapter using Capacitor plugin
|
|
11
11
|
*/
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Preferences Adapter - Native preferences storage
|
|
3
3
|
* iOS: UserDefaults, Android: SharedPreferences
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { StrataStorage } from
|
|
7
|
-
import { StorageError } from
|
|
8
|
-
import { isCapacitor } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { StrataStorage } from "../../plugin/index.js";
|
|
7
|
+
import { StorageError } from "../../utils/errors.js";
|
|
8
|
+
import { isCapacitor } from "../../utils/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Native preferences adapter using Capacitor plugin
|
|
11
11
|
*/
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Secure Adapter - Native secure storage
|
|
3
3
|
* iOS: Keychain, Android: EncryptedSharedPreferences
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { StrataStorage } from
|
|
7
|
-
import { StorageError } from
|
|
8
|
-
import { isCapacitor } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { StrataStorage } from "../../plugin/index.js";
|
|
7
|
+
import { StorageError } from "../../utils/errors.js";
|
|
8
|
+
import { isCapacitor } from "../../utils/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Native secure storage adapter using Capacitor plugin
|
|
11
11
|
*/
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* SQLite Adapter - Native SQLite database storage
|
|
3
3
|
* Available on iOS and Android
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { StrataStorage } from
|
|
7
|
-
import { StorageError, TransactionError } from
|
|
8
|
-
import { isCapacitor } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { StrataStorage } from "../../plugin/index.js";
|
|
7
|
+
import { StorageError, TransactionError } from "../../utils/errors.js";
|
|
8
|
+
import { isCapacitor } from "../../utils/index.js";
|
|
9
9
|
/**
|
|
10
10
|
* Native SQLite adapter using Capacitor plugin
|
|
11
11
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Capacitor Native Storage Adapters
|
|
3
3
|
* Export all native platform storage implementations
|
|
4
4
|
*/
|
|
5
|
-
export { PreferencesAdapter } from
|
|
6
|
-
export { SqliteAdapter } from
|
|
7
|
-
export { SecureAdapter } from
|
|
8
|
-
export { FilesystemAdapter } from
|
|
5
|
+
export { PreferencesAdapter } from "./PreferencesAdapter.js";
|
|
6
|
+
export { SqliteAdapter } from "./SqliteAdapter.js";
|
|
7
|
+
export { SecureAdapter } from "./SecureAdapter.js";
|
|
8
|
+
export { FilesystemAdapter } from "./FilesystemAdapter.js";
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Cache Adapter - Service Worker Cache API implementation
|
|
3
3
|
* Provides network-aware storage for offline support
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { getObjectSize } from
|
|
7
|
-
import { StorageError, QuotaExceededError, NotSupportedError } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { getObjectSize } from "../../utils/index.js";
|
|
7
|
+
import { StorageError, QuotaExceededError, NotSupportedError } from "../../utils/errors.js";
|
|
8
8
|
/**
|
|
9
9
|
* Cache API adapter for Service Worker environments
|
|
10
10
|
*/
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Cookie Adapter - Browser cookie implementation
|
|
3
3
|
* Provides limited storage with 4KB per cookie limit
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { StorageError, QuotaExceededError } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { StorageError, QuotaExceededError } from "../../utils/errors.js";
|
|
7
7
|
/**
|
|
8
8
|
* Browser cookie adapter
|
|
9
9
|
*/
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* IndexedDB Adapter - Browser IndexedDB implementation
|
|
3
3
|
* Provides large-scale persistent storage with advanced features
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { createDeferred, getObjectSize } from
|
|
7
|
-
import { StorageError, QuotaExceededError, TransactionError } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { createDeferred, getObjectSize } from "../../utils/index.js";
|
|
7
|
+
import { StorageError, QuotaExceededError, TransactionError } from "../../utils/errors.js";
|
|
8
8
|
/**
|
|
9
9
|
* Browser IndexedDB adapter
|
|
10
10
|
*/
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* LocalStorage Adapter - Browser localStorage implementation
|
|
3
3
|
* Provides persistent storage with 5-10MB limit
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { serialize, deserialize, getObjectSize } from
|
|
7
|
-
import { QuotaExceededError, SerializationError } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { serialize, deserialize, getObjectSize } from "../../utils/index.js";
|
|
7
|
+
import { QuotaExceededError, SerializationError } from "../../utils/errors.js";
|
|
8
8
|
/**
|
|
9
9
|
* Browser localStorage adapter
|
|
10
10
|
*/
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Memory Adapter - In-memory storage implementation
|
|
3
3
|
* Provides fast, non-persistent storage using Map
|
|
4
4
|
*/
|
|
5
|
-
import { BaseAdapter } from
|
|
6
|
-
import { deepClone } from
|
|
5
|
+
import { BaseAdapter } from "../../core/BaseAdapter.js";
|
|
6
|
+
import { deepClone } from "../../utils/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* In-memory storage adapter using Map
|
|
9
9
|
*/
|
|
@@ -134,7 +134,7 @@ export class MemoryAdapter extends BaseAdapter {
|
|
|
134
134
|
async query(condition) {
|
|
135
135
|
const results = [];
|
|
136
136
|
for (const [key, item] of this.storage.entries()) {
|
|
137
|
-
if (!this.isExpired(item) && this.queryEngine.matches(item
|
|
137
|
+
if (!this.isExpired(item) && this.queryEngine.matches(item, condition)) {
|
|
138
138
|
results.push({
|
|
139
139
|
key,
|
|
140
140
|
value: deepClone(item.value),
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* SessionStorage Adapter - Browser sessionStorage implementation
|
|
3
3
|
* Provides session-scoped storage with 5-10MB limit
|
|
4
4
|
*/
|
|
5
|
-
import { LocalStorageAdapter } from
|
|
5
|
+
import { LocalStorageAdapter } from "./LocalStorageAdapter.js";
|
|
6
6
|
/**
|
|
7
7
|
* Browser sessionStorage adapter
|
|
8
8
|
* Extends LocalStorageAdapter as the API is identical
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Web storage adapters
|
|
3
3
|
*/
|
|
4
|
-
export { MemoryAdapter } from
|
|
5
|
-
export { LocalStorageAdapter } from
|
|
6
|
-
export { SessionStorageAdapter } from
|
|
7
|
-
export { IndexedDBAdapter } from
|
|
8
|
-
export { CookieAdapter } from
|
|
9
|
-
export { CacheAdapter } from
|
|
4
|
+
export { MemoryAdapter } from "./MemoryAdapter.js";
|
|
5
|
+
export { LocalStorageAdapter } from "./LocalStorageAdapter.js";
|
|
6
|
+
export { SessionStorageAdapter } from "./SessionStorageAdapter.js";
|
|
7
|
+
export { IndexedDBAdapter } from "./IndexedDBAdapter.js";
|
|
8
|
+
export { CookieAdapter } from "./CookieAdapter.js";
|
|
9
|
+
export { CacheAdapter } from "./CacheAdapter.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package com.strata.storage;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.content.SharedPreferences;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
7
|
+
import androidx.security.crypto.MasterKey;
|
|
8
|
+
import java.util.Set;
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
|
|
11
|
+
public class EncryptedStorage {
|
|
12
|
+
private SharedPreferences encryptedPrefs;
|
|
13
|
+
private SharedPreferences.Editor editor;
|
|
14
|
+
|
|
15
|
+
public EncryptedStorage(Context context, String name) throws Exception {
|
|
16
|
+
String fileName = name != null ? name : "StrataSecureStorage";
|
|
17
|
+
|
|
18
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
19
|
+
MasterKey masterKey = new MasterKey.Builder(context)
|
|
20
|
+
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
21
|
+
.build();
|
|
22
|
+
|
|
23
|
+
encryptedPrefs = EncryptedSharedPreferences.create(
|
|
24
|
+
context,
|
|
25
|
+
fileName,
|
|
26
|
+
masterKey,
|
|
27
|
+
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
|
28
|
+
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
editor = encryptedPrefs.edit();
|
|
32
|
+
} else {
|
|
33
|
+
// Fallback to regular SharedPreferences for older devices
|
|
34
|
+
encryptedPrefs = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
|
|
35
|
+
editor = encryptedPrefs.edit();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public boolean set(String key, String value) {
|
|
40
|
+
editor.putString(key, value);
|
|
41
|
+
return editor.commit();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public String get(String key) {
|
|
45
|
+
return encryptedPrefs.getString(key, null);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public boolean remove(String key) {
|
|
49
|
+
editor.remove(key);
|
|
50
|
+
return editor.commit();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public boolean clear() {
|
|
54
|
+
editor.clear();
|
|
55
|
+
return editor.commit();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public Set<String> keys() {
|
|
59
|
+
return encryptedPrefs.getAll().keySet();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public boolean has(String key) {
|
|
63
|
+
return encryptedPrefs.contains(key);
|
|
64
|
+
}
|
|
65
|
+
}
|