strata-storage 2.4.2 → 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 +208 -0
- package/README.md +427 -181
- 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 +427 -181
- 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/config/support.d.ts +10 -0
- package/dist/config/support.d.ts.map +1 -0
- package/dist/config/support.js +9 -0
- 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 +35 -23
- package/scripts/build.js +16 -5
- package/scripts/configure.js +2 -6
- package/scripts/postinstall.js +2 -2
- package/Readme.md +0 -271
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular integration for Strata Storage
|
|
3
|
+
*/
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
14
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
15
|
+
};
|
|
16
|
+
var StrataModule_1;
|
|
17
|
+
import { Injectable, InjectionToken, Inject, Optional, NgModule, Pipe, Directive, Input, HostListener, } from '@angular/core';
|
|
18
|
+
import { NgControl } from '@angular/forms';
|
|
19
|
+
import { Observable, BehaviorSubject, Subject, from, interval, combineLatest, throwError, } from 'rxjs';
|
|
20
|
+
import { map, switchMap, catchError, takeUntil, distinctUntilChanged, shareReplay, startWith, filter, } from 'rxjs/operators';
|
|
21
|
+
import { Strata } from "../../core/Strata.js";
|
|
22
|
+
import { logger } from "../../utils/logger.js";
|
|
23
|
+
// Configuration / instance injection tokens
|
|
24
|
+
export const STRATA_CONFIG = new InjectionToken('strata.config');
|
|
25
|
+
export const STRATA_INSTANCE = new InjectionToken('strata.instance');
|
|
26
|
+
/**
|
|
27
|
+
* Strata Service - Main service for storage operations
|
|
28
|
+
*/
|
|
29
|
+
let StrataService = class StrataService {
|
|
30
|
+
strata;
|
|
31
|
+
destroy$ = new Subject();
|
|
32
|
+
initialized$ = new BehaviorSubject(false);
|
|
33
|
+
changes$ = new Subject();
|
|
34
|
+
constructor(instance, config) {
|
|
35
|
+
// Prefer a caller-provided instance (provider-free pattern); otherwise build
|
|
36
|
+
// one from the optional config token.
|
|
37
|
+
this.strata = instance ?? new Strata(config);
|
|
38
|
+
this.initialize();
|
|
39
|
+
}
|
|
40
|
+
async initialize() {
|
|
41
|
+
try {
|
|
42
|
+
await this.strata.initialize();
|
|
43
|
+
this.initialized$.next(true);
|
|
44
|
+
// Subscribe to all storage changes
|
|
45
|
+
this.strata.subscribe((change) => {
|
|
46
|
+
this.changes$.next(change);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
logger.error('Failed to initialize Strata:', error);
|
|
51
|
+
this.initialized$.next(false);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Wait for initialization
|
|
56
|
+
*/
|
|
57
|
+
get ready$() {
|
|
58
|
+
return this.initialized$.pipe(filter((initialized) => initialized), startWith(false));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get storage changes observable
|
|
62
|
+
*/
|
|
63
|
+
get changes() {
|
|
64
|
+
return this.changes$.asObservable();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a value from storage
|
|
68
|
+
*/
|
|
69
|
+
get(key, options) {
|
|
70
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.get(key, options))), catchError((error) => {
|
|
71
|
+
logger.error(`Failed to get key ${key}:`, error);
|
|
72
|
+
return throwError(() => error);
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set a value in storage
|
|
77
|
+
*/
|
|
78
|
+
set(key, value, options) {
|
|
79
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.set(key, value, options))), catchError((error) => {
|
|
80
|
+
logger.error(`Failed to set key ${key}:`, error);
|
|
81
|
+
return throwError(() => error);
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Remove a value from storage
|
|
86
|
+
*/
|
|
87
|
+
remove(key, options) {
|
|
88
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.remove(key, options))), catchError((error) => {
|
|
89
|
+
logger.error(`Failed to remove key ${key}:`, error);
|
|
90
|
+
return throwError(() => error);
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if key exists
|
|
95
|
+
*/
|
|
96
|
+
has(key, options) {
|
|
97
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.has(key, options))), catchError(() => from([false])));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Clear storage
|
|
101
|
+
*/
|
|
102
|
+
clear(options) {
|
|
103
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.clear(options))), catchError((error) => {
|
|
104
|
+
logger.error('Failed to clear storage:', error);
|
|
105
|
+
return throwError(() => error);
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get all keys
|
|
110
|
+
*/
|
|
111
|
+
keys(pattern, options) {
|
|
112
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.keys(pattern, options))), catchError(() => from([[]])));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Query storage
|
|
116
|
+
*/
|
|
117
|
+
query(condition, options) {
|
|
118
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.query(condition, options))), catchError(() => from([[]])));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get storage size
|
|
122
|
+
*/
|
|
123
|
+
size(detailed) {
|
|
124
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.size(detailed))), catchError(() => from([{ total: 0, count: 0 }])));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Watch a specific key
|
|
128
|
+
*/
|
|
129
|
+
watch(key, options) {
|
|
130
|
+
return combineLatest([
|
|
131
|
+
this.get(key, options),
|
|
132
|
+
this.changes.pipe(filter((change) => change.key === key), map((change) => change.newValue)),
|
|
133
|
+
]).pipe(map(([initial]) => initial), distinctUntilChanged(), shareReplay(1), takeUntil(this.destroy$));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get TTL for a key
|
|
137
|
+
*/
|
|
138
|
+
getTTL(key, options) {
|
|
139
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.getTTL(key, options))), catchError(() => from([null])));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Extend TTL
|
|
143
|
+
*/
|
|
144
|
+
extendTTL(key, extension, options) {
|
|
145
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.extendTTL(key, extension, options))), catchError((error) => {
|
|
146
|
+
logger.error(`Failed to extend TTL for key ${key}:`, error);
|
|
147
|
+
return throwError(() => error);
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Make key persistent
|
|
152
|
+
*/
|
|
153
|
+
persist(key, options) {
|
|
154
|
+
return this.ready$.pipe(switchMap(() => from(this.strata.persist(key, options))), catchError((error) => {
|
|
155
|
+
logger.error(`Failed to persist key ${key}:`, error);
|
|
156
|
+
return throwError(() => error);
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Generate secure password
|
|
161
|
+
*/
|
|
162
|
+
generatePassword(length) {
|
|
163
|
+
return this.strata.generatePassword(length);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Hash data
|
|
167
|
+
*/
|
|
168
|
+
hash(data) {
|
|
169
|
+
return from(this.strata.hash(data));
|
|
170
|
+
}
|
|
171
|
+
ngOnDestroy() {
|
|
172
|
+
this.destroy$.next();
|
|
173
|
+
this.destroy$.complete();
|
|
174
|
+
this.strata.close();
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
StrataService = __decorate([
|
|
178
|
+
Injectable({
|
|
179
|
+
providedIn: 'root',
|
|
180
|
+
}),
|
|
181
|
+
__param(0, Optional()),
|
|
182
|
+
__param(0, Inject(STRATA_INSTANCE)),
|
|
183
|
+
__param(1, Optional()),
|
|
184
|
+
__param(1, Inject(STRATA_CONFIG)),
|
|
185
|
+
__metadata("design:paramtypes", [Strata, Object])
|
|
186
|
+
], StrataService);
|
|
187
|
+
export { StrataService };
|
|
188
|
+
/**
|
|
189
|
+
* Storage pipe for template usage
|
|
190
|
+
*/
|
|
191
|
+
let StoragePipe = class StoragePipe {
|
|
192
|
+
strata;
|
|
193
|
+
value = null;
|
|
194
|
+
key = null;
|
|
195
|
+
subscription = null;
|
|
196
|
+
constructor(strata) {
|
|
197
|
+
this.strata = strata;
|
|
198
|
+
}
|
|
199
|
+
transform(key, defaultValue) {
|
|
200
|
+
if (this.key !== key) {
|
|
201
|
+
this.key = key;
|
|
202
|
+
this.dispose();
|
|
203
|
+
this.subscription = this.strata
|
|
204
|
+
.watch(key)
|
|
205
|
+
.subscribe((value) => (this.value = value ?? defaultValue));
|
|
206
|
+
}
|
|
207
|
+
return this.value;
|
|
208
|
+
}
|
|
209
|
+
ngOnDestroy() {
|
|
210
|
+
this.dispose();
|
|
211
|
+
}
|
|
212
|
+
dispose() {
|
|
213
|
+
if (this.subscription) {
|
|
214
|
+
this.subscription.unsubscribe();
|
|
215
|
+
this.subscription = null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
StoragePipe = __decorate([
|
|
220
|
+
Pipe({
|
|
221
|
+
name: 'storage',
|
|
222
|
+
pure: false,
|
|
223
|
+
}),
|
|
224
|
+
__metadata("design:paramtypes", [StrataService])
|
|
225
|
+
], StoragePipe);
|
|
226
|
+
export { StoragePipe };
|
|
227
|
+
/**
|
|
228
|
+
* TTL pipe for displaying time to live
|
|
229
|
+
*/
|
|
230
|
+
let TTLPipe = class TTLPipe {
|
|
231
|
+
strata;
|
|
232
|
+
ttl = null;
|
|
233
|
+
key = null;
|
|
234
|
+
subscription = null;
|
|
235
|
+
constructor(strata) {
|
|
236
|
+
this.strata = strata;
|
|
237
|
+
}
|
|
238
|
+
transform(key) {
|
|
239
|
+
if (this.key !== key) {
|
|
240
|
+
this.key = key;
|
|
241
|
+
this.dispose();
|
|
242
|
+
// Update TTL every second
|
|
243
|
+
this.subscription = interval(1000)
|
|
244
|
+
.pipe(startWith(0), switchMap(() => this.strata.getTTL(key)))
|
|
245
|
+
.subscribe((milliseconds) => {
|
|
246
|
+
if (milliseconds === null || milliseconds <= 0) {
|
|
247
|
+
this.ttl = null;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.ttl = this.formatTTL(milliseconds);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return this.ttl;
|
|
255
|
+
}
|
|
256
|
+
ngOnDestroy() {
|
|
257
|
+
this.dispose();
|
|
258
|
+
}
|
|
259
|
+
dispose() {
|
|
260
|
+
if (this.subscription) {
|
|
261
|
+
this.subscription.unsubscribe();
|
|
262
|
+
this.subscription = null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
formatTTL(milliseconds) {
|
|
266
|
+
const seconds = Math.floor(milliseconds / 1000);
|
|
267
|
+
const minutes = Math.floor(seconds / 60);
|
|
268
|
+
const hours = Math.floor(minutes / 60);
|
|
269
|
+
const days = Math.floor(hours / 24);
|
|
270
|
+
if (days > 0) {
|
|
271
|
+
return `${days}d ${hours % 24}h`;
|
|
272
|
+
}
|
|
273
|
+
else if (hours > 0) {
|
|
274
|
+
return `${hours}h ${minutes % 60}m`;
|
|
275
|
+
}
|
|
276
|
+
else if (minutes > 0) {
|
|
277
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return `${seconds}s`;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
TTLPipe = __decorate([
|
|
285
|
+
Pipe({
|
|
286
|
+
name: 'ttl',
|
|
287
|
+
pure: false,
|
|
288
|
+
}),
|
|
289
|
+
__metadata("design:paramtypes", [StrataService])
|
|
290
|
+
], TTLPipe);
|
|
291
|
+
export { TTLPipe };
|
|
292
|
+
/**
|
|
293
|
+
* Storage directive for form inputs
|
|
294
|
+
*/
|
|
295
|
+
let StorageDirective = class StorageDirective {
|
|
296
|
+
control;
|
|
297
|
+
strata;
|
|
298
|
+
key;
|
|
299
|
+
strataOptions;
|
|
300
|
+
strataDebounce = 500;
|
|
301
|
+
subscription = null;
|
|
302
|
+
timeout = null;
|
|
303
|
+
constructor(control, strata) {
|
|
304
|
+
this.control = control;
|
|
305
|
+
this.strata = strata;
|
|
306
|
+
}
|
|
307
|
+
ngOnInit() {
|
|
308
|
+
// Load initial value
|
|
309
|
+
this.subscription = this.strata.get(this.key, this.strataOptions).subscribe((value) => {
|
|
310
|
+
if (value !== null && this.control.control) {
|
|
311
|
+
this.control.control.setValue(value, { emitEvent: false });
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
onValueChange(value) {
|
|
316
|
+
if (this.timeout) {
|
|
317
|
+
clearTimeout(this.timeout);
|
|
318
|
+
}
|
|
319
|
+
this.timeout = setTimeout(() => {
|
|
320
|
+
this.strata.set(this.key, value, this.strataOptions).subscribe();
|
|
321
|
+
}, this.strataDebounce);
|
|
322
|
+
}
|
|
323
|
+
ngOnDestroy() {
|
|
324
|
+
if (this.subscription) {
|
|
325
|
+
this.subscription.unsubscribe();
|
|
326
|
+
}
|
|
327
|
+
if (this.timeout) {
|
|
328
|
+
clearTimeout(this.timeout);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
__decorate([
|
|
333
|
+
Input('strataStorage'),
|
|
334
|
+
__metadata("design:type", String)
|
|
335
|
+
], StorageDirective.prototype, "key", void 0);
|
|
336
|
+
__decorate([
|
|
337
|
+
Input(),
|
|
338
|
+
__metadata("design:type", Object)
|
|
339
|
+
], StorageDirective.prototype, "strataOptions", void 0);
|
|
340
|
+
__decorate([
|
|
341
|
+
Input(),
|
|
342
|
+
__metadata("design:type", Object)
|
|
343
|
+
], StorageDirective.prototype, "strataDebounce", void 0);
|
|
344
|
+
__decorate([
|
|
345
|
+
HostListener('input', ['$event.target.value']),
|
|
346
|
+
HostListener('change', ['$event.target.value']),
|
|
347
|
+
__metadata("design:type", Function),
|
|
348
|
+
__metadata("design:paramtypes", [Object]),
|
|
349
|
+
__metadata("design:returntype", void 0)
|
|
350
|
+
], StorageDirective.prototype, "onValueChange", null);
|
|
351
|
+
StorageDirective = __decorate([
|
|
352
|
+
Directive({
|
|
353
|
+
selector: '[strataStorage]',
|
|
354
|
+
}),
|
|
355
|
+
__metadata("design:paramtypes", [NgControl,
|
|
356
|
+
StrataService])
|
|
357
|
+
], StorageDirective);
|
|
358
|
+
export { StorageDirective };
|
|
359
|
+
/**
|
|
360
|
+
* Strata Module
|
|
361
|
+
*/
|
|
362
|
+
let StrataModule = StrataModule_1 = class StrataModule {
|
|
363
|
+
static forRoot(config) {
|
|
364
|
+
return {
|
|
365
|
+
ngModule: StrataModule_1,
|
|
366
|
+
providers: [{ provide: STRATA_CONFIG, useValue: config }, StrataService],
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
StrataModule = StrataModule_1 = __decorate([
|
|
371
|
+
NgModule({
|
|
372
|
+
declarations: [StoragePipe, TTLPipe, StorageDirective],
|
|
373
|
+
exports: [StoragePipe, TTLPipe, StorageDirective],
|
|
374
|
+
})
|
|
375
|
+
], StrataModule);
|
|
376
|
+
export { StrataModule };
|
|
377
|
+
/**
|
|
378
|
+
* Standalone-Angular provider — supply a pre-created Strata instance (the
|
|
379
|
+
* provider-free, no-NgModule pattern) or a config object. Use it in
|
|
380
|
+
* bootstrapApplication() or a component's `providers`.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* import { defineStorage } from 'strata-storage';
|
|
385
|
+
* import { provideStrata } from 'strata-storage/angular';
|
|
386
|
+
* const storage = defineStorage();
|
|
387
|
+
* bootstrapApplication(AppComponent, { providers: [provideStrata(storage)] });
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
export function provideStrata(instanceOrConfig) {
|
|
391
|
+
if (instanceOrConfig instanceof Strata) {
|
|
392
|
+
return [{ provide: STRATA_INSTANCE, useValue: instanceOrConfig }, StrataService];
|
|
393
|
+
}
|
|
394
|
+
return [{ provide: STRATA_CONFIG, useValue: instanceOrConfig ?? null }, StrataService];
|
|
395
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework integrations for Strata Storage
|
|
3
|
+
*
|
|
4
|
+
* Import the integration for your framework:
|
|
5
|
+
*
|
|
6
|
+
* React:
|
|
7
|
+
* import { StrataProvider, useStrata, useStorage } from 'strata-storage/react';
|
|
8
|
+
*
|
|
9
|
+
* Vue:
|
|
10
|
+
* import { StrataPlugin, useStrata, useStorage } from 'strata-storage/vue';
|
|
11
|
+
*
|
|
12
|
+
* Angular:
|
|
13
|
+
* import { StrataModule, StrataService } from 'strata-storage/angular';
|
|
14
|
+
*/
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Framework integrations for Strata Storage
|
|
4
|
+
*
|
|
5
|
+
* Import the integration for your framework:
|
|
6
|
+
*
|
|
7
|
+
* React:
|
|
8
|
+
* import { StrataProvider, useStrata, useStorage } from 'strata-storage/react';
|
|
9
|
+
*
|
|
10
|
+
* Vue:
|
|
11
|
+
* import { StrataPlugin, useStrata, useStorage } from 'strata-storage/vue';
|
|
12
|
+
*
|
|
13
|
+
* Angular:
|
|
14
|
+
* import { StrataModule, StrataService } from 'strata-storage/angular';
|
|
15
|
+
*/
|
|
16
|
+
// Note: Framework integrations are exported via separate entry points
|
|
17
|
+
// This file is kept for backward compatibility but should not re-export
|
|
18
|
+
// to avoid dependency issues
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React integration for Strata Storage.
|
|
3
|
+
*
|
|
4
|
+
* Two usage styles, both fully supported:
|
|
5
|
+
*
|
|
6
|
+
* 1. No-provider (Zustand-style, recommended): create an instance anywhere and
|
|
7
|
+
* bind hooks to it with `createStrataHooks` — no Provider required.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { defineStorage } from 'strata-storage';
|
|
11
|
+
* import { createStrataHooks } from 'strata-storage/react';
|
|
12
|
+
* const storage = defineStorage();
|
|
13
|
+
* export const { useStorage } = createStrataHooks(storage);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* 2. Provider-based (classic): wrap the tree in <StrataProvider> and call the
|
|
17
|
+
* exported hooks, which read the instance from context.
|
|
18
|
+
*/
|
|
19
|
+
import { Strata } from '@/core/Strata';
|
|
20
|
+
import type { StrataConfig, StorageOptions, QueryCondition } from '@/types';
|
|
21
|
+
/**
|
|
22
|
+
* Bind the Strata hooks to a specific instance — the framework-agnostic,
|
|
23
|
+
* no-Provider pattern (mirrors Zustand's `create`). Call once at module scope
|
|
24
|
+
* and use the returned hooks in any component, no Provider needed.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* const storage = defineStorage();
|
|
29
|
+
* export const { useStorage, useStorageQuery, useStorageTTL } =
|
|
30
|
+
* createStrataHooks(storage);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createStrataHooks(strata: Strata): {
|
|
34
|
+
useStorage: <T = unknown>(key: string, defaultValue?: T, options?: StorageOptions) => [T | null, (value: T | null, options?: StorageOptions) => Promise<void>, boolean];
|
|
35
|
+
useStorageQuery: <T = unknown>(condition: QueryCondition, options?: StorageOptions) => {
|
|
36
|
+
data: {
|
|
37
|
+
key: string;
|
|
38
|
+
value: T;
|
|
39
|
+
}[];
|
|
40
|
+
loading: boolean;
|
|
41
|
+
refetch: () => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
useStorageTTL: (key: string, options?: StorageOptions) => {
|
|
44
|
+
ttl: number | null;
|
|
45
|
+
extendTTL: (extension: number) => Promise<void>;
|
|
46
|
+
persist: () => Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
interface StrataProviderProps {
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
config?: StrataConfig;
|
|
52
|
+
/** Provide an existing instance instead of creating one from `config`. */
|
|
53
|
+
instance?: Strata;
|
|
54
|
+
loadingComponent?: React.ReactNode;
|
|
55
|
+
fallback?: React.ReactNode;
|
|
56
|
+
}
|
|
57
|
+
export declare function StrataProvider({ children, config, instance, loadingComponent, fallback, }: StrataProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
58
|
+
export declare function useStrata(): Strata;
|
|
59
|
+
export declare function useStrataInitialized(): boolean;
|
|
60
|
+
export declare function useStorage<T = unknown>(key: string, defaultValue?: T, options?: StorageOptions): [T | null, (value: T | null, options?: StorageOptions) => Promise<void>, boolean];
|
|
61
|
+
export declare function useStorageQuery<T = unknown>(condition: QueryCondition, options?: StorageOptions): {
|
|
62
|
+
data: {
|
|
63
|
+
key: string;
|
|
64
|
+
value: T;
|
|
65
|
+
}[];
|
|
66
|
+
loading: boolean;
|
|
67
|
+
refetch: () => Promise<void>;
|
|
68
|
+
};
|
|
69
|
+
export declare function useStorageTTL(key: string, options?: StorageOptions): {
|
|
70
|
+
ttl: number | null;
|
|
71
|
+
extendTTL: (extension: number) => Promise<void>;
|
|
72
|
+
persist: () => Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integrations/react/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAiB,cAAc,EAAE,MAAM,SAAS,CAAC;AA2H3F;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;iBAC1B,CAAC,iBAAiB,MAAM,iBAAiB,CAAC,YAAY,cAAc,4CA1HhD,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC;sBA6H/C,CAAC,uBAAuB,cAAc,YAAY,cAAc;;iBAhFnE,MAAM;;;iBAAwB,OAAO;iBAAW,MAAM,OAAO,CAAC,IAAI,CAAC;;yBAmF7D,MAAM,YAAY,cAAc;;+BAtCxC,MAAM;;;EA0C3B;AAgBD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,QAAQ,GACT,EAAE,mBAAmB,2CA+BrB;AAED,wBAAgB,SAAS,IAAI,MAAM,CAalC;AAED,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EACpC,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,CAAC,EAChB,OAAO,CAAC,EAAE,cAAc,GACvB,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAEnF;AAED,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,cAAc;;aAlLxE,MAAM;;;aAAwB,OAAO;aAAW,MAAM,OAAO,CAAC,IAAI,CAAC;EAoL1F;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc;;2BAzI7C,MAAM;;EA2I3B"}
|