@ngx-pwa/local-storage 22.0.0 → 22.0.1

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.
@@ -1,18 +1,26 @@
1
- import * as i0 from '@angular/core';
2
- import { EnvironmentProviders, ModuleWithProviders } from '@angular/core';
3
- import { Observable } from 'rxjs';
4
-
1
+ import * as i0 from "@angular/core";
2
+ import { EnvironmentProviders, InjectionToken, ModuleWithProviders } from "@angular/core";
3
+ import { Observable } from "rxjs";
4
+ /**
5
+ * Exception message when `indexedDB` is not working
6
+ */
7
+ declare const IDB_BROKEN_ERROR = "indexedDB is not working";
8
+ /**
9
+ * Exception raised when `indexedDB` is not working
10
+ */
11
+ declare class IDBBrokenError extends Error {
12
+ message: string;
13
+ }
5
14
  /**
6
15
  * Exception message when a value cannot be serialized for `localStorage`
7
16
  */
8
- declare const SERIALIZATION_ERROR = "The storage is currently localStorage,\nwhere data must be serialized, and the provided data can't be serialized.";
17
+ export declare const SERIALIZATION_ERROR = "The storage is currently localStorage,\nwhere data must be serialized, and the provided data can't be serialized.";
9
18
  /**
10
19
  * Exception throwned when a value cannot be serialized for `localStorage`
11
20
  */
12
- declare class SerializationError extends Error {
13
- message: string;
21
+ export declare class SerializationError extends Error {
22
+ message: string;
14
23
  }
15
-
16
24
  /**
17
25
  * Allows to add a prefix before `localStorage` keys.
18
26
  *
@@ -25,7 +33,7 @@ declare class SerializationError extends Error {
25
33
  * providers: [provideLocalStoragePrefix('custom_')]
26
34
  * };
27
35
  */
28
- declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders;
36
+ export declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders;
29
37
  /**
30
38
  * Allows to change the name used for `indexedDB` database.
31
39
  *
@@ -38,7 +46,7 @@ declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders
38
46
  * providers: [provideIndexedDBDataBaseName('custom')]
39
47
  * };
40
48
  */
41
- declare function provideIndexedDBDataBaseName(name: string): EnvironmentProviders;
49
+ export declare function provideIndexedDBDataBaseName(name: string): EnvironmentProviders;
42
50
  /**
43
51
  * Allows to change the database version used for `indexedDB` database.
44
52
  * Must be an unsigned **integer**.
@@ -54,7 +62,7 @@ declare function provideIndexedDBDataBaseName(name: string): EnvironmentProvider
54
62
  * providers: [provideIndexedDBDataBaseVersion(2)]
55
63
  * };
56
64
  */
57
- declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentProviders;
65
+ export declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentProviders;
58
66
  /**
59
67
  * Allows to change the name used for `indexedDB` object store.
60
68
  *
@@ -67,228 +75,270 @@ declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentPr
67
75
  * providers: [provideIndexedDBStoreName('custom')]
68
76
  * };
69
77
  */
70
- declare function provideIndexedDBStoreName(name: string): EnvironmentProviders;
71
-
78
+ export declare function provideIndexedDBStoreName(name: string): EnvironmentProviders;
79
+ /**
80
+ * Token to provide a prefix to `localStorage` keys.
81
+ */
82
+ declare const LS_PREFIX: InjectionToken<string>;
83
+ /**
84
+ * Default name used for `indexedDB` database.
85
+ */
86
+ declare const DEFAULT_IDB_DB_NAME = "ngStorage";
87
+ /**
88
+ * Token to provide `indexedDB` database name.
89
+ */
90
+ declare const IDB_DB_NAME: InjectionToken<string>;
91
+ /**
92
+ * Default version used for `indexedDB` database.
93
+ */
94
+ declare const DEFAULT_IDB_DB_VERSION = 1;
95
+ /**
96
+ * Token to provide `indexedDB` database version.
97
+ * Must be an unsigned **integer**.
98
+ */
99
+ declare const IDB_DB_VERSION: InjectionToken<number>;
100
+ /**
101
+ * Default name used for `indexedDB` object store.
102
+ */
103
+ declare const DEFAULT_IDB_STORE_NAME = "localStorage";
104
+ /**
105
+ * Token to provide `indexedDB` store name.
106
+ * For backward compatibility, the default can't be set now, `IndexedDBDatabase` will do it at runtime.
107
+ */
108
+ declare const IDB_STORE_NAME: InjectionToken<string>;
109
+ /**
110
+ * Default value for interoperability with native `indexedDB` and other storage libs,
111
+ * by changing how values are stored in `indexedDB` database.
112
+ */
113
+ declare const DEFAULT_IDB_NO_WRAP = true;
114
+ /**
115
+ * Token to allow interoperability with native `indexedDB` and other storage libs,
116
+ * by changing how values are stored in `indexedDB` database.
117
+ * Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
118
+ * **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
119
+ */
120
+ declare const IDB_NO_WRAP: InjectionToken<boolean>;
72
121
  /**
73
122
  * This interface is only here for backward compatibility, **do not add it by yourself**
74
123
  *
75
124
  * @ignore
76
125
  */
77
126
  interface StorageConfig {
78
- /**
79
- * @deprecated Use `provideLocalStoragePrefix()` method instead
80
- */
81
- readonly LSPrefix?: string;
82
- /**
83
- * @deprecated Use `provideIndexedDBDataBaseName()` method instead
84
- */
85
- readonly IDBDBName?: string;
86
- /**
87
- * @deprecated Use `provideIndexedDBStoreName()` method instead
88
- */
89
- readonly IDBStoreName?: string;
90
- /**
91
- * @deprecated Use `provideIndexedDBDataBaseVersion()` method instead
92
- */
93
- readonly IDBDBVersion?: number;
94
- /**
95
- * Allows interoperability with native `indexedDB` and other storage libs,
96
- * by changing how values are stored in `indexedDB` database.
97
- *
98
- * Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
99
- *
100
- * **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
101
- */
102
- readonly IDBNoWrap?: boolean;
127
+ /**
128
+ * @deprecated Use `provideLocalStoragePrefix()` method instead
129
+ */
130
+ readonly LSPrefix?: string;
131
+ /**
132
+ * @deprecated Use `provideIndexedDBDataBaseName()` method instead
133
+ */
134
+ readonly IDBDBName?: string;
135
+ /**
136
+ * @deprecated Use `provideIndexedDBStoreName()` method instead
137
+ */
138
+ readonly IDBStoreName?: string;
139
+ /**
140
+ * @deprecated Use `provideIndexedDBDataBaseVersion()` method instead
141
+ */
142
+ readonly IDBDBVersion?: number;
143
+ /**
144
+ * Allows interoperability with native `indexedDB` and other storage libs,
145
+ * by changing how values are stored in `indexedDB` database.
146
+ *
147
+ * Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
148
+ *
149
+ * **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
150
+ */
151
+ readonly IDBNoWrap?: boolean;
103
152
  }
104
-
105
153
  /**
106
154
  * This module is only here for backward compatibility, **do not add it by yourself**
107
155
  *
108
156
  * @ignore
109
157
  */
110
- declare class StorageModule {
111
- /**
112
- * Only useful to provide options, otherwise it does nothing.
113
- *
114
- * **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
115
- */
116
- static forRoot(config: StorageConfig): ModuleWithProviders<StorageModule>;
117
- static ɵfac: i0.ɵɵFactoryDeclaration<StorageModule, never>;
118
- static ɵmod: i0.ɵɵNgModuleDeclaration<StorageModule, never, never, never>;
119
- static ɵinj: i0.ɵɵInjectorDeclaration<StorageModule>;
158
+ export declare class StorageModule {
159
+ /**
160
+ * Only useful to provide options, otherwise it does nothing.
161
+ *
162
+ * **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
163
+ */
164
+ static forRoot(config: StorageConfig): ModuleWithProviders<StorageModule>;
165
+ static ɵfac: i0.ɵɵFactoryDeclaration<StorageModule, never>;
166
+ static ɵmod: i0.ɵɵNgModuleDeclaration<StorageModule, never, never, never>;
167
+ static ɵinj: i0.ɵɵInjectorDeclaration<StorageModule>;
120
168
  }
121
-
122
169
  /**
123
170
  * Exception message when a value is not valid against the JSON schema
124
171
  */
125
- declare const VALIDATION_ERROR = "Data stored is not valid against the provided JSON schema.\nCheck your JSON schema, otherwise it means data has been corrupted.";
172
+ export declare const VALIDATION_ERROR = "Data stored is not valid against the provided JSON schema.\nCheck your JSON schema, otherwise it means data has been corrupted.";
126
173
  /**
127
174
  * Exception throwned when a value is not valid against the JSON schema
128
175
  */
129
- declare class ValidationError extends Error {
130
- message: string;
176
+ export declare class ValidationError extends Error {
177
+ message: string;
131
178
  }
132
-
179
+ /**
180
+ * Factory to create a storage according to browser support
181
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/BROWSERS_SUPPORT.md}
182
+ */
183
+ declare function localDatabaseFactory(): LocalDatabase;
133
184
  declare abstract class LocalDatabase {
134
- abstract readonly size: Observable<number>;
135
- abstract get(key: string): Observable<unknown>;
136
- abstract set(key: string, data: unknown): Observable<undefined>;
137
- abstract delete(key: string): Observable<undefined>;
138
- abstract clear(): Observable<undefined>;
139
- abstract keys(): Observable<string>;
140
- abstract has(key: string): Observable<boolean>;
141
- static ɵfac: i0.ɵɵFactoryDeclaration<LocalDatabase, never>;
142
- static ɵprov: i0.ɵɵInjectableDeclaration<LocalDatabase>;
185
+ abstract readonly size: Observable<number>;
186
+ abstract get(key: string): Observable<unknown>;
187
+ abstract set(key: string, data: unknown): Observable<undefined>;
188
+ abstract delete(key: string): Observable<undefined>;
189
+ abstract clear(): Observable<undefined>;
190
+ abstract keys(): Observable<string>;
191
+ abstract has(key: string): Observable<boolean>;
192
+ static ɵfac: i0.ɵɵFactoryDeclaration<LocalDatabase, never>;
193
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
143
194
  }
144
-
145
195
  /**
146
196
  * JSON Schema to describe a boolean value.
147
197
  */
148
198
  interface JSONSchemaBoolean {
149
- /**
150
- * Type for a boolean value.
151
- */
152
- readonly type: "boolean";
153
- /**
154
- * Checks if a value is strictly equal to this.
155
- */
156
- readonly const?: boolean;
199
+ /**
200
+ * Type for a boolean value.
201
+ */
202
+ readonly type: "boolean";
203
+ /**
204
+ * Checks if a value is strictly equal to this.
205
+ */
206
+ readonly const?: boolean;
157
207
  }
158
208
  /**
159
209
  * JSON Schema to describe a number value.
160
210
  */
161
211
  interface JSONSchemaNumber {
162
- /**
163
- * Type for a numeric value.
164
- */
165
- readonly type: "number";
166
- /**
167
- * Checks if a value is strictly equal to this.
168
- */
169
- readonly const?: number;
170
- /**
171
- * Checks if a value is strictly equal to one of the value of enum.
172
- */
173
- readonly enum?: readonly number[];
174
- /**
175
- * Check if a number is a multiple of x.
176
- * Must be strictly greater than 0.
177
- */
178
- readonly multipleOf?: number;
179
- /**
180
- * Check if a number is lower or equal than this maximum.
181
- */
182
- readonly maximum?: number;
183
- /**
184
- * Check if a number is strictly lower than this maximum.
185
- */
186
- readonly exclusiveMaximum?: number;
187
- /**
188
- * Check if a number is greater or equal than this minimum.
189
- */
190
- readonly minimum?: number;
191
- /**
192
- * Check if a number is strictly greater than this minimum.
193
- */
194
- readonly exclusiveMinimum?: number;
212
+ /**
213
+ * Type for a numeric value.
214
+ */
215
+ readonly type: "number";
216
+ /**
217
+ * Checks if a value is strictly equal to this.
218
+ */
219
+ readonly const?: number;
220
+ /**
221
+ * Checks if a value is strictly equal to one of the value of enum.
222
+ */
223
+ readonly enum?: readonly number[];
224
+ /**
225
+ * Check if a number is a multiple of x.
226
+ * Must be strictly greater than 0.
227
+ */
228
+ readonly multipleOf?: number;
229
+ /**
230
+ * Check if a number is lower or equal than this maximum.
231
+ */
232
+ readonly maximum?: number;
233
+ /**
234
+ * Check if a number is strictly lower than this maximum.
235
+ */
236
+ readonly exclusiveMaximum?: number;
237
+ /**
238
+ * Check if a number is greater or equal than this minimum.
239
+ */
240
+ readonly minimum?: number;
241
+ /**
242
+ * Check if a number is strictly greater than this minimum.
243
+ */
244
+ readonly exclusiveMinimum?: number;
195
245
  }
196
246
  /**
197
247
  * JSON Schema to describe an integer value.
198
248
  */
199
249
  interface JSONSchemaInteger {
200
- /**
201
- * Type for an integer value.
202
- */
203
- readonly type: "integer";
204
- /**
205
- * Checks if a value is strictly equal to this.
206
- */
207
- readonly const?: number;
208
- /**
209
- * Checks if a value is strictly equal to one of the value of enum.
210
- */
211
- readonly enum?: readonly number[];
212
- /**
213
- * Check if a number is a multiple of x.
214
- * Must be strictly greater than 0.
215
- */
216
- readonly multipleOf?: number;
217
- /**
218
- * Check if a number is lower or equal than this maximum.
219
- */
220
- readonly maximum?: number;
221
- /**
222
- * Check if a number is strictly lower than this maximum.
223
- */
224
- readonly exclusiveMaximum?: number;
225
- /**
226
- * Check if a number is greater or equal than this minimum.
227
- */
228
- readonly minimum?: number;
229
- /**
230
- * Check if a number is strictly greater than this minimum.
231
- */
232
- readonly exclusiveMinimum?: number;
250
+ /**
251
+ * Type for an integer value.
252
+ */
253
+ readonly type: "integer";
254
+ /**
255
+ * Checks if a value is strictly equal to this.
256
+ */
257
+ readonly const?: number;
258
+ /**
259
+ * Checks if a value is strictly equal to one of the value of enum.
260
+ */
261
+ readonly enum?: readonly number[];
262
+ /**
263
+ * Check if a number is a multiple of x.
264
+ * Must be strictly greater than 0.
265
+ */
266
+ readonly multipleOf?: number;
267
+ /**
268
+ * Check if a number is lower or equal than this maximum.
269
+ */
270
+ readonly maximum?: number;
271
+ /**
272
+ * Check if a number is strictly lower than this maximum.
273
+ */
274
+ readonly exclusiveMaximum?: number;
275
+ /**
276
+ * Check if a number is greater or equal than this minimum.
277
+ */
278
+ readonly minimum?: number;
279
+ /**
280
+ * Check if a number is strictly greater than this minimum.
281
+ */
282
+ readonly exclusiveMinimum?: number;
233
283
  }
234
284
  /**
235
285
  * JSON Schema to describe a string value.
236
286
  */
237
287
  interface JSONSchemaString {
238
- /**
239
- * Type for a string value.
240
- */
241
- readonly type: "string";
242
- /**
243
- * Checks if a value is strictly equal to this.
244
- */
245
- readonly const?: string;
246
- /**
247
- * Checks if a value is strictly equal to one of the value of enum.
248
- */
249
- readonly enum?: readonly string[];
250
- /**
251
- * Maxium length for a string.
252
- * Must be a non-negative integer.
253
- */
254
- readonly maxLength?: number;
255
- /**
256
- * Minimum length for a string.
257
- * Must be a non-negative integer.
258
- */
259
- readonly minLength?: number;
260
- /**
261
- * Pattern to match for a string.
262
- * Must be a valid regular expression, *without* the `/` delimiters.
263
- */
264
- readonly pattern?: string;
288
+ /**
289
+ * Type for a string value.
290
+ */
291
+ readonly type: "string";
292
+ /**
293
+ * Checks if a value is strictly equal to this.
294
+ */
295
+ readonly const?: string;
296
+ /**
297
+ * Checks if a value is strictly equal to one of the value of enum.
298
+ */
299
+ readonly enum?: readonly string[];
300
+ /**
301
+ * Maxium length for a string.
302
+ * Must be a non-negative integer.
303
+ */
304
+ readonly maxLength?: number;
305
+ /**
306
+ * Minimum length for a string.
307
+ * Must be a non-negative integer.
308
+ */
309
+ readonly minLength?: number;
310
+ /**
311
+ * Pattern to match for a string.
312
+ * Must be a valid regular expression, *without* the `/` delimiters.
313
+ */
314
+ readonly pattern?: string;
265
315
  }
266
316
  /**
267
317
  * JSON schema to describe an array of values.
268
318
  */
269
319
  interface JSONSchemaArray {
270
- /**
271
- * Type for an array of values.
272
- */
273
- readonly type: "array";
274
- /**
275
- * Schema for the values of the array.
276
- */
277
- readonly items: JSONSchema;
278
- /**
279
- * Check if an array length is lower or equal to this value.
280
- * Must be a non negative integer.
281
- */
282
- readonly maxItems?: number;
283
- /**
284
- * Check if an array length is greater or equal to this value.
285
- * Must be a non negative integer.
286
- */
287
- readonly minItems?: number;
288
- /**
289
- * Check if an array only have unique values.
290
- */
291
- readonly uniqueItems?: boolean;
320
+ /**
321
+ * Type for an array of values.
322
+ */
323
+ readonly type: "array";
324
+ /**
325
+ * Schema for the values of the array.
326
+ */
327
+ readonly items: JSONSchema;
328
+ /**
329
+ * Check if an array length is lower or equal to this value.
330
+ * Must be a non negative integer.
331
+ */
332
+ readonly maxItems?: number;
333
+ /**
334
+ * Check if an array length is greater or equal to this value.
335
+ * Must be a non negative integer.
336
+ */
337
+ readonly minItems?: number;
338
+ /**
339
+ * Check if an array only have unique values.
340
+ */
341
+ readonly uniqueItems?: boolean;
292
342
  }
293
343
  /**
294
344
  * JSON Schema to describe an array of primitive values:
@@ -298,73 +348,73 @@ interface JSONSchemaArray {
298
348
  * - array of strings: `JSONSchemaArrayOf<JSONSchemaString>`.
299
349
  */
300
350
  interface JSONSchemaArrayOf<T extends JSONSchemaBoolean | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaString> {
301
- /**
302
- * Type for an array of values.
303
- */
304
- readonly type: "array";
305
- /**
306
- * Schema for the values of an array.
307
- */
308
- readonly items: T;
309
- /**
310
- * Check if an array length is lower or equal to this value.
311
- * Must be a non negative integer.
312
- */
313
- readonly maxItems?: number;
314
- /**
315
- * Check if an array length is greater or equal to this value.
316
- * Must be a non negative integer.
317
- */
318
- readonly minItems?: number;
319
- /**
320
- * Check if an array only have unique values.
321
- */
322
- readonly uniqueItems?: boolean;
351
+ /**
352
+ * Type for an array of values.
353
+ */
354
+ readonly type: "array";
355
+ /**
356
+ * Schema for the values of an array.
357
+ */
358
+ readonly items: T;
359
+ /**
360
+ * Check if an array length is lower or equal to this value.
361
+ * Must be a non negative integer.
362
+ */
363
+ readonly maxItems?: number;
364
+ /**
365
+ * Check if an array length is greater or equal to this value.
366
+ * Must be a non negative integer.
367
+ */
368
+ readonly minItems?: number;
369
+ /**
370
+ * Check if an array only have unique values.
371
+ */
372
+ readonly uniqueItems?: boolean;
323
373
  }
324
374
  /**
325
375
  * JSON schema to describe a tuple.
326
376
  */
327
377
  interface JSONSchemaTuple {
328
- /**
329
- * Type for an array of values.
330
- */
331
- readonly type: "array";
332
- /**
333
- * Schema for the values of the tuple.
334
- */
335
- readonly items?: readonly JSONSchema[];
336
- /**
337
- * Check if an array length is lower or equal to this value.
338
- * Must be a non negative integer.
339
- */
340
- readonly maxItems?: number;
341
- /**
342
- * Check if an array length is greater or equal to this value.
343
- * Must be a non negative integer.
344
- */
345
- readonly minItems?: number;
346
- /**
347
- * Check if an array only have unique values.
348
- */
349
- readonly uniqueItems?: boolean;
378
+ /**
379
+ * Type for an array of values.
380
+ */
381
+ readonly type: "array";
382
+ /**
383
+ * Schema for the values of the tuple.
384
+ */
385
+ readonly items?: readonly JSONSchema[];
386
+ /**
387
+ * Check if an array length is lower or equal to this value.
388
+ * Must be a non negative integer.
389
+ */
390
+ readonly maxItems?: number;
391
+ /**
392
+ * Check if an array length is greater or equal to this value.
393
+ * Must be a non negative integer.
394
+ */
395
+ readonly minItems?: number;
396
+ /**
397
+ * Check if an array only have unique values.
398
+ */
399
+ readonly uniqueItems?: boolean;
350
400
  }
351
401
  /**
352
402
  * JSON schema to describe an object.
353
403
  */
354
404
  interface JSONSchemaObject {
355
- /**
356
- * Type for an object.
357
- */
358
- readonly type: "object";
359
- /**
360
- * List of properties of the object and their associated JSON schemas.
361
- */
362
- readonly properties: Readonly<Record<string, JSONSchema>>;
363
- /**
364
- * Array of names of the required properties for an object.
365
- * Properties set as required should be present in `properties` too.
366
- */
367
- readonly required?: readonly string[];
405
+ /**
406
+ * Type for an object.
407
+ */
408
+ readonly type: "object";
409
+ /**
410
+ * List of properties of the object and their associated JSON schemas.
411
+ */
412
+ readonly properties: Readonly<Record<string, JSONSchema>>;
413
+ /**
414
+ * Array of names of the required properties for an object.
415
+ * Properties set as required should be present in `properties` too.
416
+ */
417
+ readonly required?: readonly string[];
368
418
  }
369
419
  /**
370
420
  * Subset of the JSON Schema standard.
@@ -402,257 +452,256 @@ interface JSONSchemaObject {
402
452
  * } satisfies JSONSchema;
403
453
  */
404
454
  type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaBoolean | JSONSchemaArray | JSONSchemaTuple | JSONSchemaObject;
405
-
406
- declare class StorageMap {
407
- #private;
408
- /**
409
- * Constructor params are provided by Angular (but can also be passed manually in tests)
410
- * @param database Storage to use
411
- */
412
- constructor(database: LocalDatabase);
413
- /**
414
- * **Number of items** in storage, wrapped in an Observable.
415
- *
416
- * Note you do *not* need to unsubscribe (it is a self-completing Observable).
417
- *
418
- * @example
419
- * this.storageMap.size.subscribe((size) => {
420
- * console.log(size);
421
- * });
422
- */
423
- get size(): Observable<number>;
424
- /**
425
- * Tells you which storage engine is used.
426
- *
427
- * *Only useful for interoperability.*
428
- *
429
- * Note that due to some browsers issues in some special contexts
430
- * (like Safari cross-origin iframes),
431
- * **this information may be wrong at initialization,**
432
- * as the storage could fallback from `indexedDB` to `localStorage`
433
- * only after a first read or write operation.
434
- * @returns Storage engine used
435
- *
436
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
437
- *
438
- * @example
439
- * if (this.storageMap.backingEngine === 'indexedDB') {}
440
- */
441
- get backingEngine(): "indexedDB" | "localStorage" | "memory" | "unknown";
442
- /**
443
- * Information about `indexedDB` database.
444
- *
445
- * *Only useful for interoperability.*
446
- *
447
- * @returns `indexedDB` database name, store name and database version.
448
- * **Values will be empty if the storage is not `indexedDB`, so it should be used after an engine check**.
449
- *
450
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
451
- *
452
- * @example
453
- * if (this.storageMap.backingEngine === 'indexedDB') {
454
- * const { database, store, version } = this.storageMap.backingStore;
455
- * }
456
- */
457
- get backingStore(): {
458
- database: string;
459
- store: string;
460
- version: number;
461
- };
462
- /**
463
- * Information about `localStorage` fallback storage.
464
- *
465
- * *Only useful for interoperability.*
466
- *
467
- * @returns `localStorage` prefix.
468
- * **Values will be empty if the storage is not `localStorage`, so it should be used after an engine check**.
469
- *
470
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
471
- *
472
- * @example
473
- * if (this.storageMap.backingEngine === 'localStorage') {
474
- * const { prefix } = this.storageMap.fallbackBackingStore;
475
- * }
476
- */
477
- get fallbackBackingStore(): {
478
- prefix: string;
479
- };
480
- /**
481
- * Get an item value in storage.
482
- *
483
- * Note that:
484
- * * not finding an item is not an error, it succeeds but returns `undefined`,
485
- * * you do *not* need to unsubscribe (it is a self-completing Observable),
486
- * * you will only get *one* value: the Observable is here for asynchrony but is *not* meant to emit again when the stored data is changed. If you need to watch the value, see the `watch` method.
487
- *
488
- * Do not forget it is client-side storage: **always check the data**, as it could have been forged.
489
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
490
- *
491
- * @param key The item's key
492
- * @param schema Optional but recommended JSON schema to validate the data
493
- * @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS Observable
494
- *
495
- * @example
496
- * this.storageMap.get('key', { type: 'string' }).subscribe((result) => {
497
- * result; // string or undefined
498
- * });
499
- *
500
- * @example
501
- * interface User {
502
- * firstName: string;
503
- * lastName?: string;
504
- * }
505
- *
506
- * const schema = {
507
- * type: 'object',
508
- * properties: {
509
- * firstName: { type: 'string' },
510
- * lastName: { type: 'string' },
511
- * },
512
- * required: ['firstName'],
513
- * } satisfies JSONSchema;
514
- *
515
- * this.storageMap.get<User>('user', schema).subscribe((user) => {
516
- * if (user) {
517
- * user.firstName;
518
- * }
519
- * });
520
- */
521
- get(key: string): Observable<unknown>;
522
- get<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
523
- get<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
524
- get<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
525
- get<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
526
- get<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
527
- get<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
528
- get<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
529
- /**
530
- * Store an item in storage.
531
- *
532
- * Note that:
533
- * * you *do* need to subscribe, even if you do not have something specific to do after writing in storage, otherwise nothing happens (because it is how RxJS Observables work),
534
- * * but you do *not* need to unsubscribe (it is a self-completing Observable),
535
- * * setting `null` or `undefined` will remove the item to avoid some browsers issues,
536
- * * you should stick to serializable JSON data, meaning primitive types, arrays and literal objects. Date, Map, Set, Blob and other special structures can cause issues in some scenarios.
537
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/SERIALIZATION.md}
538
- *
539
- * @param key The item's key
540
- * @param data The item's value
541
- * @param schema Optional JSON schema to validate the data
542
- * @returns A RxJS Observable to wait the end of the operation
543
- *
544
- * @example
545
- * this.storageMap.set('key', 'value').subscribe(() => {});
546
- */
547
- set(key: string, data: unknown, schema?: JSONSchema): Observable<undefined>;
548
- /**
549
- * Delete an item in storage.
550
- *
551
- * Note that:
552
- * * you *do* need to subscribe, even if you do not have something specific to do after deleting, otherwise nothing happens (because it is how RxJS Observables work),
553
- * * but you do *not* need to unsubscribe (it is a self-completing Observable).
554
- *
555
- * @param key The item's key
556
- * @returns A RxJS Observable to wait the end of the operation
557
- *
558
- * @example
559
- * this.storageMap.delete('key').subscribe(() => {});
560
- */
561
- delete(key: string): Observable<undefined>;
562
- /**
563
- * Delete all items in storage.
564
- *
565
- * Note that:
566
- * * you *do* need to subscribe, even if you do not have something specific to do after clearing, otherwise nothing happens (because it is how RxJS Observables work),
567
- * * but you do *not* need to unsubscribe (it is a self-completing Observable).
568
- *
569
- * @returns A RxJS Observable to wait the end of the operation
570
- *
571
- * @example
572
- * this.storageMap.clear().subscribe(() => {});
573
- */
574
- clear(): Observable<undefined>;
575
- /**
576
- * Get all keys stored in storage.
577
- *
578
- * Note **this is an *iterating* Observable**:
579
- * * if there is no key, the `next` callback will not be invoked,
580
- * * if you need to wait the whole operation to end, be sure to act in the `complete` callback,
581
- * as this Observable can emit several values and so will invoke the `next` callback several times,
582
- * * you do *not* need to unsubscribe (it is a self-completing Observable).
583
- *
584
- * @returns A list of the keys wrapped in a RxJS Observable
585
- *
586
- * @example
587
- * this.storageMap.keys().subscribe({
588
- * next: (key) => { console.log(key); },
589
- * complete: () => { console.log('Done'); },
590
- * });
591
- */
592
- keys(): Observable<string>;
593
- /**
594
- * Tells if a key exists in storage.
595
- *
596
- * Note you do *not* need to unsubscribe (it is a self-completing Observable).
597
- *
598
- * @returns A RxJS Observable telling if the key exists
599
- *
600
- * @example
601
- * this.storageMap.has('key').subscribe((hasKey) => {
602
- * if (hasKey) {}
603
- * });
604
- */
605
- has(key: string): Observable<boolean>;
606
- /**
607
- * Watch an item value in storage.
608
- *
609
- * Note that:
610
- * * it is an infinite Observable, do not forget to unsubscribe,
611
- * * only changes done via this library will be watched, external changes in storage cannot be detected.
612
- *
613
- * The signature has many overloads due to validation, **please refer to the documentation.**
614
- * @see https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md
615
- *
616
- * @param key The item's key to watch
617
- * @param schema Optional JSON schema to validate the initial value
618
- * @returns An infinite Observable giving the current value
619
- *
620
- * @example
621
- * Component()
622
- * export class MyComponent implements OnInit, OnDestroy {
623
- *
624
- * private storageSubscription?: Subscription;
625
- *
626
- * ngOnInit(): void {
627
- * this.storageSubscription = this.storageMap.watch('key', { type: 'string' }).subscribe((result) => {
628
- * result; // string or undefined
629
- * });
630
- * }
631
- *
632
- * ngOnDestroy(): void {
633
- * this.storageSubscription?.unsubscribe();
634
- * }
635
- *
636
- * }
637
- */
638
- watch(key: string): Observable<unknown>;
639
- watch<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
640
- watch<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
641
- watch<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
642
- watch<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
643
- watch<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
644
- watch<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
645
- watch<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
646
- /**
647
- * THIS METHOD IS FOR INTERNAL PURPOSE ONLY AND MUST NOT BE USED,
648
- * IT CAN BE REMOVED AT ANY TIME AND MESSING WITH IT CAN CAUSE ISSUES
649
- * @private
650
- * @ignore
651
- */
652
- private ɵinternalGetDatabase;
653
- static ɵfac: i0.ɵɵFactoryDeclaration<StorageMap, never>;
654
- static ɵprov: i0.ɵɵInjectableDeclaration<StorageMap>;
455
+ export declare class StorageMap {
456
+ #private;
457
+ /**
458
+ * Constructor params are provided by Angular (but can also be passed manually in tests)
459
+ * @param database Storage to use
460
+ */
461
+ constructor(
462
+ // eslint-disable-line eslint-plugin-angular-modern/no-constructor-injection -- Used in tests for inject
463
+ database: LocalDatabase);
464
+ /**
465
+ * **Number of items** in storage, wrapped in an Observable.
466
+ *
467
+ * Note you do *not* need to unsubscribe (it is a self-completing Observable).
468
+ *
469
+ * @example
470
+ * this.storageMap.size.subscribe((size) => {
471
+ * console.log(size);
472
+ * });
473
+ */
474
+ get size(): Observable<number>;
475
+ /**
476
+ * Tells you which storage engine is used.
477
+ *
478
+ * *Only useful for interoperability.*
479
+ *
480
+ * Note that due to some browsers issues in some special contexts
481
+ * (like Safari cross-origin iframes),
482
+ * **this information may be wrong at initialization,**
483
+ * as the storage could fallback from `indexedDB` to `localStorage`
484
+ * only after a first read or write operation.
485
+ * @returns Storage engine used
486
+ *
487
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
488
+ *
489
+ * @example
490
+ * if (this.storageMap.backingEngine === 'indexedDB') {}
491
+ */
492
+ get backingEngine(): "indexedDB" | "localStorage" | "memory" | "unknown";
493
+ /**
494
+ * Information about `indexedDB` database.
495
+ *
496
+ * *Only useful for interoperability.*
497
+ *
498
+ * @returns `indexedDB` database name, store name and database version.
499
+ * **Values will be empty if the storage is not `indexedDB`, so it should be used after an engine check**.
500
+ *
501
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
502
+ *
503
+ * @example
504
+ * if (this.storageMap.backingEngine === 'indexedDB') {
505
+ * const { database, store, version } = this.storageMap.backingStore;
506
+ * }
507
+ */
508
+ get backingStore(): {
509
+ database: string;
510
+ store: string;
511
+ version: number;
512
+ };
513
+ /**
514
+ * Information about `localStorage` fallback storage.
515
+ *
516
+ * *Only useful for interoperability.*
517
+ *
518
+ * @returns `localStorage` prefix.
519
+ * **Values will be empty if the storage is not `localStorage`, so it should be used after an engine check**.
520
+ *
521
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
522
+ *
523
+ * @example
524
+ * if (this.storageMap.backingEngine === 'localStorage') {
525
+ * const { prefix } = this.storageMap.fallbackBackingStore;
526
+ * }
527
+ */
528
+ get fallbackBackingStore(): {
529
+ prefix: string;
530
+ };
531
+ /**
532
+ * Get an item value in storage.
533
+ *
534
+ * Note that:
535
+ * * not finding an item is not an error, it succeeds but returns `undefined`,
536
+ * * you do *not* need to unsubscribe (it is a self-completing Observable),
537
+ * * you will only get *one* value: the Observable is here for asynchrony but is *not* meant to emit again when the stored data is changed. If you need to watch the value, see the `watch` method.
538
+ *
539
+ * Do not forget it is client-side storage: **always check the data**, as it could have been forged.
540
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
541
+ *
542
+ * @param key The item's key
543
+ * @param schema Optional but recommended JSON schema to validate the data
544
+ * @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS Observable
545
+ *
546
+ * @example
547
+ * this.storageMap.get('key', { type: 'string' }).subscribe((result) => {
548
+ * result; // string or undefined
549
+ * });
550
+ *
551
+ * @example
552
+ * interface User {
553
+ * firstName: string;
554
+ * lastName?: string;
555
+ * }
556
+ *
557
+ * const schema = {
558
+ * type: 'object',
559
+ * properties: {
560
+ * firstName: { type: 'string' },
561
+ * lastName: { type: 'string' },
562
+ * },
563
+ * required: ['firstName'],
564
+ * } satisfies JSONSchema;
565
+ *
566
+ * this.storageMap.get<User>('user', schema).subscribe((user) => {
567
+ * if (user) {
568
+ * user.firstName;
569
+ * }
570
+ * });
571
+ */
572
+ get(key: string): Observable<unknown>;
573
+ get<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
574
+ get<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
575
+ get<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
576
+ get<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
577
+ get<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
578
+ get<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
579
+ get<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
580
+ /**
581
+ * Store an item in storage.
582
+ *
583
+ * Note that:
584
+ * * you *do* need to subscribe, even if you do not have something specific to do after writing in storage, otherwise nothing happens (because it is how RxJS Observables work),
585
+ * * but you do *not* need to unsubscribe (it is a self-completing Observable),
586
+ * * setting `null` or `undefined` will remove the item to avoid some browsers issues,
587
+ * * you should stick to serializable JSON data, meaning primitive types, arrays and literal objects. Date, Map, Set, Blob and other special structures can cause issues in some scenarios.
588
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/SERIALIZATION.md}
589
+ *
590
+ * @param key The item's key
591
+ * @param data The item's value
592
+ * @param schema Optional JSON schema to validate the data
593
+ * @returns A RxJS Observable to wait the end of the operation
594
+ *
595
+ * @example
596
+ * this.storageMap.set('key', 'value').subscribe(() => {});
597
+ */
598
+ set(key: string, data: unknown, schema?: JSONSchema): Observable<undefined>;
599
+ /**
600
+ * Delete an item in storage.
601
+ *
602
+ * Note that:
603
+ * * you *do* need to subscribe, even if you do not have something specific to do after deleting, otherwise nothing happens (because it is how RxJS Observables work),
604
+ * * but you do *not* need to unsubscribe (it is a self-completing Observable).
605
+ *
606
+ * @param key The item's key
607
+ * @returns A RxJS Observable to wait the end of the operation
608
+ *
609
+ * @example
610
+ * this.storageMap.delete('key').subscribe(() => {});
611
+ */
612
+ delete(key: string): Observable<undefined>;
613
+ /**
614
+ * Delete all items in storage.
615
+ *
616
+ * Note that:
617
+ * * you *do* need to subscribe, even if you do not have something specific to do after clearing, otherwise nothing happens (because it is how RxJS Observables work),
618
+ * * but you do *not* need to unsubscribe (it is a self-completing Observable).
619
+ *
620
+ * @returns A RxJS Observable to wait the end of the operation
621
+ *
622
+ * @example
623
+ * this.storageMap.clear().subscribe(() => {});
624
+ */
625
+ clear(): Observable<undefined>;
626
+ /**
627
+ * Get all keys stored in storage.
628
+ *
629
+ * Note **this is an *iterating* Observable**:
630
+ * * if there is no key, the `next` callback will not be invoked,
631
+ * * if you need to wait the whole operation to end, be sure to act in the `complete` callback,
632
+ * as this Observable can emit several values and so will invoke the `next` callback several times,
633
+ * * you do *not* need to unsubscribe (it is a self-completing Observable).
634
+ *
635
+ * @returns A list of the keys wrapped in a RxJS Observable
636
+ *
637
+ * @example
638
+ * this.storageMap.keys().subscribe({
639
+ * next: (key) => { console.log(key); },
640
+ * complete: () => { console.log('Done'); },
641
+ * });
642
+ */
643
+ keys(): Observable<string>;
644
+ /**
645
+ * Tells if a key exists in storage.
646
+ *
647
+ * Note you do *not* need to unsubscribe (it is a self-completing Observable).
648
+ *
649
+ * @returns A RxJS Observable telling if the key exists
650
+ *
651
+ * @example
652
+ * this.storageMap.has('key').subscribe((hasKey) => {
653
+ * if (hasKey) {}
654
+ * });
655
+ */
656
+ has(key: string): Observable<boolean>;
657
+ /**
658
+ * Watch an item value in storage.
659
+ *
660
+ * Note that:
661
+ * * it is an infinite Observable, do not forget to unsubscribe,
662
+ * * only changes done via this library will be watched, external changes in storage cannot be detected.
663
+ *
664
+ * The signature has many overloads due to validation, **please refer to the documentation.**
665
+ * @see https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md
666
+ *
667
+ * @param key The item's key to watch
668
+ * @param schema Optional JSON schema to validate the initial value
669
+ * @returns An infinite Observable giving the current value
670
+ *
671
+ * @example
672
+ * Service()
673
+ * export class MyService {
674
+ *
675
+ * #storageSubscription?: Subscription;
676
+ *
677
+ * start(): void {
678
+ * this.#storageSubscription = this.storageMap.watch('key', { type: 'string' }).subscribe((result) => {
679
+ * result; // string or undefined
680
+ * });
681
+ * }
682
+ *
683
+ * stop(): void {
684
+ * this.#storageSubscription?.unsubscribe();
685
+ * }
686
+ *
687
+ * }
688
+ */
689
+ watch(key: string): Observable<unknown>;
690
+ watch<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
691
+ watch<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
692
+ watch<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
693
+ watch<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
694
+ watch<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
695
+ watch<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
696
+ watch<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
697
+ /**
698
+ * THIS METHOD IS FOR INTERNAL PURPOSE ONLY AND MUST NOT BE USED,
699
+ * IT CAN BE REMOVED AT ANY TIME AND MESSING WITH IT CAN CAUSE ISSUES
700
+ * @private
701
+ * @ignore
702
+ */
703
+ private ɵinternalGetDatabase;
704
+ static ɵfac: i0.ɵɵFactoryDeclaration<StorageMap, never>;
705
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
655
706
  }
656
-
657
- export { SERIALIZATION_ERROR, SerializationError, StorageMap, StorageModule, VALIDATION_ERROR, ValidationError, provideIndexedDBDataBaseName, provideIndexedDBDataBaseVersion, provideIndexedDBStoreName, provideLocalStoragePrefix };
658
- export type { JSONSchema, StorageConfig };
707
+ export type { JSONSchema, StorageConfig };