@ngx-pwa/local-storage 19.0.0 → 20.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/LICENSE +1 -1
- package/fesm2022/ngx-pwa-local-storage.mjs +63 -50
- package/fesm2022/ngx-pwa-local-storage.mjs.map +1 -1
- package/index.d.ts +656 -3
- package/package.json +3 -3
- package/schematics/ng-add/index.js +5 -5
- package/lib/databases/exceptions.d.ts +0 -20
- package/lib/databases/indexeddb-database.d.ts +0 -107
- package/lib/databases/local-database.d.ts +0 -18
- package/lib/databases/localstorage-database.d.ts +0 -64
- package/lib/databases/memory-database.d.ts +0 -50
- package/lib/providers.d.ts +0 -56
- package/lib/storage.module.d.ts +0 -19
- package/lib/storages/exceptions.d.ts +0 -10
- package/lib/storages/storage-map.service.d.ts +0 -254
- package/lib/tokens.d.ts +0 -75
- package/lib/validation/json-schema.d.ts +0 -260
- package/lib/validation/json-validator.d.ts +0 -71
- package/public-api.d.ts +0 -7
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exception message when `indexedDB` is not working
|
|
3
|
-
*/
|
|
4
|
-
export declare const IDB_BROKEN_ERROR = "indexedDB is not working";
|
|
5
|
-
/**
|
|
6
|
-
* Exception raised when `indexedDB` is not working
|
|
7
|
-
*/
|
|
8
|
-
export declare class IDBBrokenError extends Error {
|
|
9
|
-
message: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Exception message when a value cannot be serialized for `localStorage`
|
|
13
|
-
*/
|
|
14
|
-
export declare const SERIALIZATION_ERROR = "The storage is currently localStorage,\nwhere data must be serialized, and the provided data can't be serialized.";
|
|
15
|
-
/**
|
|
16
|
-
* Exception throwned when a value cannot be serialized for `localStorage`
|
|
17
|
-
*/
|
|
18
|
-
export declare class SerializationError extends Error {
|
|
19
|
-
message: string;
|
|
20
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { LocalDatabase } from "./local-database";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export declare class IndexedDBDatabase implements LocalDatabase {
|
|
5
|
-
/**
|
|
6
|
-
* `indexedDB` database name
|
|
7
|
-
*/
|
|
8
|
-
private readonly dbName;
|
|
9
|
-
/**
|
|
10
|
-
* `indexedDB` object store name
|
|
11
|
-
*/
|
|
12
|
-
private readonly storeName;
|
|
13
|
-
/**
|
|
14
|
-
* `indexedDB` database version. Must be an unsigned **integer**
|
|
15
|
-
*/
|
|
16
|
-
private readonly dbVersion;
|
|
17
|
-
/**
|
|
18
|
-
* `indexedDB` database connection, wrapped in a RxJS `ReplaySubject` to be able to access the connection
|
|
19
|
-
* even after the connection success event happened
|
|
20
|
-
*/
|
|
21
|
-
private readonly database;
|
|
22
|
-
/**
|
|
23
|
-
* Flag to not wrap `indexedDB` values for interoperability or to wrap for backward compatibility.
|
|
24
|
-
*/
|
|
25
|
-
private readonly noWrap;
|
|
26
|
-
/**
|
|
27
|
-
* Index used when wrapping value. *For backward compatibility only.*
|
|
28
|
-
*/
|
|
29
|
-
private readonly wrapIndex;
|
|
30
|
-
constructor();
|
|
31
|
-
/**
|
|
32
|
-
* Information about `indexedDB` connection. *Only useful for interoperability.*
|
|
33
|
-
* @returns `indexedDB` database name, store name and database version
|
|
34
|
-
*/
|
|
35
|
-
get backingStore(): {
|
|
36
|
-
database: string;
|
|
37
|
-
store: string;
|
|
38
|
-
version: number;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Number of items in our `indexedDB` database and object store
|
|
42
|
-
*/
|
|
43
|
-
get size(): Observable<number>;
|
|
44
|
-
/**
|
|
45
|
-
* Gets an item value in our `indexedDB` store
|
|
46
|
-
* @param key The item's key
|
|
47
|
-
* @returns The item's value if the key exists, `undefined` otherwise, wrapped in an RxJS `Observable`
|
|
48
|
-
*/
|
|
49
|
-
get(key: string): Observable<unknown>;
|
|
50
|
-
/**
|
|
51
|
-
* Sets an item in our `indexedDB` store
|
|
52
|
-
* @param key The item's key
|
|
53
|
-
* @param data The item's value
|
|
54
|
-
* @returns An RxJS `Observable` to wait the end of the operation
|
|
55
|
-
*/
|
|
56
|
-
set(key: string, data: unknown): Observable<undefined>;
|
|
57
|
-
/**
|
|
58
|
-
* Deletes an item in our `indexedDB` store
|
|
59
|
-
* @param key The item's key
|
|
60
|
-
* @returns An RxJS `Observable` to wait the end of the operation
|
|
61
|
-
*/
|
|
62
|
-
delete(key: string): Observable<undefined>;
|
|
63
|
-
/**
|
|
64
|
-
* Deletes all items from our `indexedDB` objet store
|
|
65
|
-
* @returns An RxJS `Observable` to wait the end of the operation
|
|
66
|
-
*/
|
|
67
|
-
clear(): Observable<undefined>;
|
|
68
|
-
/**
|
|
69
|
-
* Get all the keys in our `indexedDB` store
|
|
70
|
-
* @returns An RxJS `Observable` iterating on each key
|
|
71
|
-
*/
|
|
72
|
-
keys(): Observable<string>;
|
|
73
|
-
/**
|
|
74
|
-
* Check if a key exists in our `indexedDB` store
|
|
75
|
-
* @returns An RxJS `Observable` telling if the key exists or not
|
|
76
|
-
*/
|
|
77
|
-
has(key: string): Observable<boolean>;
|
|
78
|
-
/**
|
|
79
|
-
* Connects to `indexedDB` and creates the object store on first time
|
|
80
|
-
*/
|
|
81
|
-
private connect;
|
|
82
|
-
/**
|
|
83
|
-
* Create store on first use of `indexedDB`
|
|
84
|
-
* @param request `indexedDB` database opening request
|
|
85
|
-
*/
|
|
86
|
-
private createStore;
|
|
87
|
-
/**
|
|
88
|
-
* Open an `indexedDB` transaction and get our store
|
|
89
|
-
* @param mode `readonly` or `readwrite`
|
|
90
|
-
* @returns An `indexedDB` transaction store and events, wrapped in an RxJS `Observable`
|
|
91
|
-
*/
|
|
92
|
-
private transaction;
|
|
93
|
-
/**
|
|
94
|
-
* Listen errors on a transaction or request, and throw if trigerred
|
|
95
|
-
* @param transactionOrRequest `indexedDb` transaction or request to listen
|
|
96
|
-
* @returns An `Observable` listening to errors
|
|
97
|
-
*/
|
|
98
|
-
private listenError;
|
|
99
|
-
/**
|
|
100
|
-
* Listen transaction `complete` and `error` events
|
|
101
|
-
* @param transaction Transaction to listen
|
|
102
|
-
* @returns An `Observable` listening to transaction `complete` and `error` events
|
|
103
|
-
*/
|
|
104
|
-
private listenTransactionEvents;
|
|
105
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<IndexedDBDatabase, never>;
|
|
106
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<IndexedDBDatabase>;
|
|
107
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
/**
|
|
4
|
-
* Factory to create a storage according to browser support
|
|
5
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/BROWSERS_SUPPORT.md}
|
|
6
|
-
*/
|
|
7
|
-
export declare function localDatabaseFactory(): LocalDatabase;
|
|
8
|
-
export declare abstract class LocalDatabase {
|
|
9
|
-
abstract readonly size: Observable<number>;
|
|
10
|
-
abstract get(key: string): Observable<unknown>;
|
|
11
|
-
abstract set(key: string, data: unknown): Observable<undefined>;
|
|
12
|
-
abstract delete(key: string): Observable<undefined>;
|
|
13
|
-
abstract clear(): Observable<undefined>;
|
|
14
|
-
abstract keys(): Observable<string>;
|
|
15
|
-
abstract has(key: string): Observable<boolean>;
|
|
16
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LocalDatabase, never>;
|
|
17
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LocalDatabase>;
|
|
18
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { LocalDatabase } from "./local-database";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export declare class LocalStorageDatabase implements LocalDatabase {
|
|
5
|
-
/**
|
|
6
|
-
* Optional user prefix to avoid collision for multiple apps on the same subdomain
|
|
7
|
-
*/
|
|
8
|
-
readonly prefix: string;
|
|
9
|
-
constructor();
|
|
10
|
-
/**
|
|
11
|
-
* Number of items in `localStorage`
|
|
12
|
-
*/
|
|
13
|
-
get size(): Observable<number>;
|
|
14
|
-
/**
|
|
15
|
-
* Gets an item value in `localStorage`
|
|
16
|
-
* @param key The item's key
|
|
17
|
-
* @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS `Observable`
|
|
18
|
-
*/
|
|
19
|
-
get(key: string): Observable<unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* Store an item in `localStorage`
|
|
22
|
-
* @param key The item's key
|
|
23
|
-
* @param data The item's value
|
|
24
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
25
|
-
*/
|
|
26
|
-
set(key: string, data: unknown): Observable<undefined>;
|
|
27
|
-
/**
|
|
28
|
-
* Deletes an item in `localStorage`
|
|
29
|
-
* @param key The item's key
|
|
30
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
31
|
-
*/
|
|
32
|
-
delete(key: string): Observable<undefined>;
|
|
33
|
-
/**
|
|
34
|
-
* Deletes all items in `localStorage`
|
|
35
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
36
|
-
*/
|
|
37
|
-
clear(): Observable<undefined>;
|
|
38
|
-
/**
|
|
39
|
-
* Get all keys in `localStorage`
|
|
40
|
-
* Note the order of the keys may be inconsistent in Firefox
|
|
41
|
-
* @returns A RxJS `Observable` iterating on keys
|
|
42
|
-
*/
|
|
43
|
-
keys(): Observable<string>;
|
|
44
|
-
/**
|
|
45
|
-
* Check if a key exists in `localStorage`
|
|
46
|
-
* @param key The item's key
|
|
47
|
-
* @returns A RxJS `Observable` telling if the key exists or not
|
|
48
|
-
*/
|
|
49
|
-
has(key: string): Observable<boolean>;
|
|
50
|
-
/**
|
|
51
|
-
* Get an unprefixed key
|
|
52
|
-
* @param index Index of the key
|
|
53
|
-
* @returns The unprefixed key name if exists, `null` otherwise
|
|
54
|
-
*/
|
|
55
|
-
private getUnprefixedKey;
|
|
56
|
-
/**
|
|
57
|
-
* Add the prefix to a key
|
|
58
|
-
* @param key The key name
|
|
59
|
-
* @returns The prefixed key name
|
|
60
|
-
*/
|
|
61
|
-
private prefixKey;
|
|
62
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<LocalStorageDatabase, never>;
|
|
63
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<LocalStorageDatabase>;
|
|
64
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { LocalDatabase } from "./local-database";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export declare class MemoryDatabase implements LocalDatabase {
|
|
5
|
-
/**
|
|
6
|
-
* Memory storage
|
|
7
|
-
*/
|
|
8
|
-
private readonly memoryStorage;
|
|
9
|
-
/**
|
|
10
|
-
* Number of items in memory
|
|
11
|
-
*/
|
|
12
|
-
get size(): Observable<number>;
|
|
13
|
-
/**
|
|
14
|
-
* Gets an item value in memory
|
|
15
|
-
* @param key The item's key
|
|
16
|
-
* @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS `Observable`
|
|
17
|
-
*/
|
|
18
|
-
get(key: string): Observable<unknown>;
|
|
19
|
-
/**
|
|
20
|
-
* Sets an item in memory
|
|
21
|
-
* @param key The item's key
|
|
22
|
-
* @param data The item's value
|
|
23
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
24
|
-
*/
|
|
25
|
-
set(key: string, data: unknown): Observable<undefined>;
|
|
26
|
-
/**
|
|
27
|
-
* Deletes an item in memory
|
|
28
|
-
* @param key The item's key
|
|
29
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
30
|
-
*/
|
|
31
|
-
delete(key: string): Observable<undefined>;
|
|
32
|
-
/**
|
|
33
|
-
* Deletes all items in memory
|
|
34
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
35
|
-
*/
|
|
36
|
-
clear(): Observable<undefined>;
|
|
37
|
-
/**
|
|
38
|
-
* Get all keys in memory
|
|
39
|
-
* @returns A RxJS `Observable` iterating on keys
|
|
40
|
-
*/
|
|
41
|
-
keys(): Observable<string>;
|
|
42
|
-
/**
|
|
43
|
-
* Check if a key exists in memory
|
|
44
|
-
* @param key Key name
|
|
45
|
-
* @returns a RxJS `Observable` telling if the key exists or not
|
|
46
|
-
*/
|
|
47
|
-
has(key: string): Observable<boolean>;
|
|
48
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<MemoryDatabase, never>;
|
|
49
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<MemoryDatabase>;
|
|
50
|
-
}
|
package/lib/providers.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { type EnvironmentProviders } from "@angular/core";
|
|
2
|
-
/**
|
|
3
|
-
* Allows to add a prefix before `localStorage` keys.
|
|
4
|
-
*
|
|
5
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
|
|
6
|
-
*
|
|
7
|
-
* **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* export const appConfig: ApplicationConfig = {
|
|
11
|
-
* providers: [provideLocalStoragePrefix('custom_')]
|
|
12
|
-
* };
|
|
13
|
-
*/
|
|
14
|
-
export declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders;
|
|
15
|
-
/**
|
|
16
|
-
* Allows to change the name used for `indexedDB` database.
|
|
17
|
-
*
|
|
18
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
|
|
19
|
-
*
|
|
20
|
-
* **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* export const appConfig: ApplicationConfig = {
|
|
24
|
-
* providers: [provideIndexedDBDataBaseName('custom')]
|
|
25
|
-
* };
|
|
26
|
-
*/
|
|
27
|
-
export declare function provideIndexedDBDataBaseName(name: string): EnvironmentProviders;
|
|
28
|
-
/**
|
|
29
|
-
* Allows to change the database version used for `indexedDB` database.
|
|
30
|
-
* Must be an unsigned **integer**.
|
|
31
|
-
*
|
|
32
|
-
* **Use with caution as the creation of the store depends on the version.**
|
|
33
|
-
*
|
|
34
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple applications on the same subdomain.
|
|
35
|
-
*
|
|
36
|
-
* **WARNING: do not change this option in an applicattion already deployed in production, as previously stored data would be lost.**
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* export const appConfig: ApplicationConfig = {
|
|
40
|
-
* providers: [provideIndexedDBDataBaseVersion(2)]
|
|
41
|
-
* };
|
|
42
|
-
*/
|
|
43
|
-
export declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentProviders;
|
|
44
|
-
/**
|
|
45
|
-
* Allows to change the name used for `indexedDB` object store.
|
|
46
|
-
*
|
|
47
|
-
* *Use only* for interoperability with other APIs.
|
|
48
|
-
*
|
|
49
|
-
* **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* export const appConfig: ApplicationConfig = {
|
|
53
|
-
* providers: [provideIndexedDBStoreName('custom')]
|
|
54
|
-
* };
|
|
55
|
-
*/
|
|
56
|
-
export declare function provideIndexedDBStoreName(name: string): EnvironmentProviders;
|
package/lib/storage.module.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type ModuleWithProviders } from "@angular/core";
|
|
2
|
-
import { type StorageConfig } from "./tokens";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
/**
|
|
5
|
-
* This module is only here for backward compatibility, **do not add it by yourself**
|
|
6
|
-
*
|
|
7
|
-
* @ignore
|
|
8
|
-
*/
|
|
9
|
-
export declare class StorageModule {
|
|
10
|
-
/**
|
|
11
|
-
* Only useful to provide options, otherwise it does nothing.
|
|
12
|
-
*
|
|
13
|
-
* **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
|
|
14
|
-
*/
|
|
15
|
-
static forRoot(config: StorageConfig): ModuleWithProviders<StorageModule>;
|
|
16
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<StorageModule, never>;
|
|
17
|
-
static ɵmod: i0.ɵɵNgModuleDeclaration<StorageModule, never, never, never>;
|
|
18
|
-
static ɵinj: i0.ɵɵInjectorDeclaration<StorageModule>;
|
|
19
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exception message when a value is not valid against the JSON schema
|
|
3
|
-
*/
|
|
4
|
-
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.";
|
|
5
|
-
/**
|
|
6
|
-
* Exception throwned when a value is not valid against the JSON schema
|
|
7
|
-
*/
|
|
8
|
-
export declare class ValidationError extends Error {
|
|
9
|
-
message: string;
|
|
10
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { LocalDatabase } from "../databases/local-database";
|
|
3
|
-
import type { JSONSchema, JSONSchemaArrayOf, JSONSchemaBoolean, JSONSchemaInteger, JSONSchemaNumber, JSONSchemaString } from "../validation/json-schema";
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
export declare class StorageMap {
|
|
6
|
-
#private;
|
|
7
|
-
/**
|
|
8
|
-
* Constructor params are provided by Angular (but can also be passed manually in tests)
|
|
9
|
-
* @param database Storage to use
|
|
10
|
-
*/
|
|
11
|
-
constructor(database: LocalDatabase);
|
|
12
|
-
/**
|
|
13
|
-
* **Number of items** in storage, wrapped in an Observable.
|
|
14
|
-
*
|
|
15
|
-
* Note you do *not* need to unsubscribe (it is a self-completing Observable).
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* this.storageMap.size.subscribe((size) => {
|
|
19
|
-
* console.log(size);
|
|
20
|
-
* });
|
|
21
|
-
*/
|
|
22
|
-
get size(): Observable<number>;
|
|
23
|
-
/**
|
|
24
|
-
* Tells you which storage engine is used.
|
|
25
|
-
*
|
|
26
|
-
* *Only useful for interoperability.*
|
|
27
|
-
*
|
|
28
|
-
* Note that due to some browsers issues in some special contexts
|
|
29
|
-
* (like Safari cross-origin iframes),
|
|
30
|
-
* **this information may be wrong at initialization,**
|
|
31
|
-
* as the storage could fallback from `indexedDB` to `localStorage`
|
|
32
|
-
* only after a first read or write operation.
|
|
33
|
-
* @returns Storage engine used
|
|
34
|
-
*
|
|
35
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* if (this.storageMap.backingEngine === 'indexedDB') {}
|
|
39
|
-
*/
|
|
40
|
-
get backingEngine(): "indexedDB" | "localStorage" | "memory" | "unknown";
|
|
41
|
-
/**
|
|
42
|
-
* Information about `indexedDB` database.
|
|
43
|
-
*
|
|
44
|
-
* *Only useful for interoperability.*
|
|
45
|
-
*
|
|
46
|
-
* @returns `indexedDB` database name, store name and database version.
|
|
47
|
-
* **Values will be empty if the storage is not `indexedDB`, so it should be used after an engine check**.
|
|
48
|
-
*
|
|
49
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* if (this.storageMap.backingEngine === 'indexedDB') {
|
|
53
|
-
* const { database, store, version } = this.storageMap.backingStore;
|
|
54
|
-
* }
|
|
55
|
-
*/
|
|
56
|
-
get backingStore(): {
|
|
57
|
-
database: string;
|
|
58
|
-
store: string;
|
|
59
|
-
version: number;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Information about `localStorage` fallback storage.
|
|
63
|
-
*
|
|
64
|
-
* *Only useful for interoperability.*
|
|
65
|
-
*
|
|
66
|
-
* @returns `localStorage` prefix.
|
|
67
|
-
* **Values will be empty if the storage is not `localStorage`, so it should be used after an engine check**.
|
|
68
|
-
*
|
|
69
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* if (this.storageMap.backingEngine === 'localStorage') {
|
|
73
|
-
* const { prefix } = this.storageMap.fallbackBackingStore;
|
|
74
|
-
* }
|
|
75
|
-
*/
|
|
76
|
-
get fallbackBackingStore(): {
|
|
77
|
-
prefix: string;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Get an item value in storage.
|
|
81
|
-
*
|
|
82
|
-
* Note that:
|
|
83
|
-
* * not finding an item is not an error, it succeeds but returns `undefined`,
|
|
84
|
-
* * you do *not* need to unsubscribe (it is a self-completing Observable),
|
|
85
|
-
* * 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.
|
|
86
|
-
*
|
|
87
|
-
* Do not forget it is client-side storage: **always check the data**, as it could have been forged.
|
|
88
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
|
|
89
|
-
*
|
|
90
|
-
* @param key The item's key
|
|
91
|
-
* @param schema Optional but recommended JSON schema to validate the data
|
|
92
|
-
* @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS Observable
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* this.storageMap.get('key', { type: 'string' }).subscribe((result) => {
|
|
96
|
-
* result; // string or undefined
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* interface User {
|
|
101
|
-
* firstName: string;
|
|
102
|
-
* lastName?: string;
|
|
103
|
-
* }
|
|
104
|
-
*
|
|
105
|
-
* const schema = {
|
|
106
|
-
* type: 'object',
|
|
107
|
-
* properties: {
|
|
108
|
-
* firstName: { type: 'string' },
|
|
109
|
-
* lastName: { type: 'string' },
|
|
110
|
-
* },
|
|
111
|
-
* required: ['firstName'],
|
|
112
|
-
* } satisfies JSONSchema;
|
|
113
|
-
*
|
|
114
|
-
* this.storageMap.get<User>('user', schema).subscribe((user) => {
|
|
115
|
-
* if (user) {
|
|
116
|
-
* user.firstName;
|
|
117
|
-
* }
|
|
118
|
-
* });
|
|
119
|
-
*/
|
|
120
|
-
get(key: string): Observable<unknown>;
|
|
121
|
-
get<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
|
|
122
|
-
get<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
|
|
123
|
-
get<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
|
|
124
|
-
get<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
|
|
125
|
-
get<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
|
|
126
|
-
get<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
|
|
127
|
-
get<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
|
|
128
|
-
/**
|
|
129
|
-
* Store an item in storage.
|
|
130
|
-
*
|
|
131
|
-
* Note that:
|
|
132
|
-
* * 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),
|
|
133
|
-
* * but you do *not* need to unsubscribe (it is a self-completing Observable),
|
|
134
|
-
* * setting `null` or `undefined` will remove the item to avoid some browsers issues,
|
|
135
|
-
* * 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.
|
|
136
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/SERIALIZATION.md}
|
|
137
|
-
*
|
|
138
|
-
* @param key The item's key
|
|
139
|
-
* @param data The item's value
|
|
140
|
-
* @param schema Optional JSON schema to validate the data
|
|
141
|
-
* @returns A RxJS Observable to wait the end of the operation
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* this.storageMap.set('key', 'value').subscribe(() => {});
|
|
145
|
-
*/
|
|
146
|
-
set(key: string, data: unknown, schema?: JSONSchema): Observable<undefined>;
|
|
147
|
-
/**
|
|
148
|
-
* Delete an item in storage.
|
|
149
|
-
*
|
|
150
|
-
* Note that:
|
|
151
|
-
* * 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),
|
|
152
|
-
* * but you do *not* need to unsubscribe (it is a self-completing Observable).
|
|
153
|
-
*
|
|
154
|
-
* @param key The item's key
|
|
155
|
-
* @returns A RxJS Observable to wait the end of the operation
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* this.storageMap.delete('key').subscribe(() => {});
|
|
159
|
-
*/
|
|
160
|
-
delete(key: string): Observable<undefined>;
|
|
161
|
-
/**
|
|
162
|
-
* Delete all items in storage.
|
|
163
|
-
*
|
|
164
|
-
* Note that:
|
|
165
|
-
* * 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),
|
|
166
|
-
* * but you do *not* need to unsubscribe (it is a self-completing Observable).
|
|
167
|
-
*
|
|
168
|
-
* @returns A RxJS Observable to wait the end of the operation
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* this.storageMap.clear().subscribe(() => {});
|
|
172
|
-
*/
|
|
173
|
-
clear(): Observable<undefined>;
|
|
174
|
-
/**
|
|
175
|
-
* Get all keys stored in storage.
|
|
176
|
-
*
|
|
177
|
-
* Note **this is an *iterating* Observable**:
|
|
178
|
-
* * if there is no key, the `next` callback will not be invoked,
|
|
179
|
-
* * if you need to wait the whole operation to end, be sure to act in the `complete` callback,
|
|
180
|
-
* as this Observable can emit several values and so will invoke the `next` callback several times,
|
|
181
|
-
* * you do *not* need to unsubscribe (it is a self-completing Observable).
|
|
182
|
-
*
|
|
183
|
-
* @returns A list of the keys wrapped in a RxJS Observable
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* this.storageMap.keys().subscribe({
|
|
187
|
-
* next: (key) => { console.log(key); },
|
|
188
|
-
* complete: () => { console.log('Done'); },
|
|
189
|
-
* });
|
|
190
|
-
*/
|
|
191
|
-
keys(): Observable<string>;
|
|
192
|
-
/**
|
|
193
|
-
* Tells if a key exists in storage.
|
|
194
|
-
*
|
|
195
|
-
* Note you do *not* need to unsubscribe (it is a self-completing Observable).
|
|
196
|
-
*
|
|
197
|
-
* @returns A RxJS Observable telling if the key exists
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* this.storageMap.has('key').subscribe((hasKey) => {
|
|
201
|
-
* if (hasKey) {}
|
|
202
|
-
* });
|
|
203
|
-
*/
|
|
204
|
-
has(key: string): Observable<boolean>;
|
|
205
|
-
/**
|
|
206
|
-
* Watch an item value in storage.
|
|
207
|
-
*
|
|
208
|
-
* Note that:
|
|
209
|
-
* * it is an infinite Observable, do not forget to unsubscribe,
|
|
210
|
-
* * only changes done via this library will be watched, external changes in storage cannot be detected.
|
|
211
|
-
*
|
|
212
|
-
* The signature has many overloads due to validation, **please refer to the documentation.**
|
|
213
|
-
* @see https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md
|
|
214
|
-
*
|
|
215
|
-
* @param key The item's key to watch
|
|
216
|
-
* @param schema Optional JSON schema to validate the initial value
|
|
217
|
-
* @returns An infinite Observable giving the current value
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* Component()
|
|
221
|
-
* export class MyComponent implements OnInit, OnDestroy {
|
|
222
|
-
*
|
|
223
|
-
* private storageSubscription?: Subscription;
|
|
224
|
-
*
|
|
225
|
-
* ngOnInit(): void {
|
|
226
|
-
* this.storageSubscription = this.storageMap.watch('key', { type: 'string' }).subscribe((result) => {
|
|
227
|
-
* result; // string or undefined
|
|
228
|
-
* });
|
|
229
|
-
* }
|
|
230
|
-
*
|
|
231
|
-
* ngOnDestroy(): void {
|
|
232
|
-
* this.storageSubscription?.unsubscribe();
|
|
233
|
-
* }
|
|
234
|
-
*
|
|
235
|
-
* }
|
|
236
|
-
*/
|
|
237
|
-
watch(key: string): Observable<unknown>;
|
|
238
|
-
watch<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
|
|
239
|
-
watch<T extends number = number>(key: string, schema: JSONSchemaInteger | JSONSchemaNumber): Observable<T | undefined>;
|
|
240
|
-
watch<T extends boolean = boolean>(key: string, schema: JSONSchemaBoolean): Observable<T | undefined>;
|
|
241
|
-
watch<T extends readonly string[] = string[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaString>): Observable<T | undefined>;
|
|
242
|
-
watch<T extends readonly number[] = number[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaInteger | JSONSchemaNumber>): Observable<T | undefined>;
|
|
243
|
-
watch<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
|
|
244
|
-
watch<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
|
|
245
|
-
/**
|
|
246
|
-
* THIS METHOD IS FOR INTERNAL PURPOSE ONLY AND MUST NOT BE USED,
|
|
247
|
-
* IT CAN BE REMOVED AT ANY TIME AND MESSING WITH IT CAN CAUSE ISSUES
|
|
248
|
-
* @private
|
|
249
|
-
* @ignore
|
|
250
|
-
*/
|
|
251
|
-
private ɵinternalGetDatabase;
|
|
252
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<StorageMap, never>;
|
|
253
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<StorageMap>;
|
|
254
|
-
}
|
package/lib/tokens.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from "@angular/core";
|
|
2
|
-
/**
|
|
3
|
-
* Token to provide a prefix to `localStorage` keys.
|
|
4
|
-
*/
|
|
5
|
-
export declare const LS_PREFIX: InjectionToken<string>;
|
|
6
|
-
/**
|
|
7
|
-
* Default name used for `indexedDB` database.
|
|
8
|
-
*/
|
|
9
|
-
export declare const DEFAULT_IDB_DB_NAME = "ngStorage";
|
|
10
|
-
/**
|
|
11
|
-
* Token to provide `indexedDB` database name.
|
|
12
|
-
*/
|
|
13
|
-
export declare const IDB_DB_NAME: InjectionToken<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Default version used for `indexedDB` database.
|
|
16
|
-
*/
|
|
17
|
-
export declare const DEFAULT_IDB_DB_VERSION = 1;
|
|
18
|
-
/**
|
|
19
|
-
* Token to provide `indexedDB` database version.
|
|
20
|
-
* Must be an unsigned **integer**.
|
|
21
|
-
*/
|
|
22
|
-
export declare const IDB_DB_VERSION: InjectionToken<number>;
|
|
23
|
-
/**
|
|
24
|
-
* Default name used for `indexedDB` object store.
|
|
25
|
-
*/
|
|
26
|
-
export declare const DEFAULT_IDB_STORE_NAME = "localStorage";
|
|
27
|
-
/**
|
|
28
|
-
* Token to provide `indexedDB` store name.
|
|
29
|
-
* For backward compatibility, the default can't be set now, `IndexedDBDatabase` will do it at runtime.
|
|
30
|
-
*/
|
|
31
|
-
export declare const IDB_STORE_NAME: InjectionToken<string>;
|
|
32
|
-
/**
|
|
33
|
-
* Default value for interoperability with native `indexedDB` and other storage libs,
|
|
34
|
-
* by changing how values are stored in `indexedDB` database.
|
|
35
|
-
*/
|
|
36
|
-
export declare const DEFAULT_IDB_NO_WRAP = true;
|
|
37
|
-
/**
|
|
38
|
-
* Token to allow interoperability with native `indexedDB` and other storage libs,
|
|
39
|
-
* by changing how values are stored in `indexedDB` database.
|
|
40
|
-
* Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
|
|
41
|
-
* **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
|
|
42
|
-
*/
|
|
43
|
-
export declare const IDB_NO_WRAP: InjectionToken<boolean>;
|
|
44
|
-
/**
|
|
45
|
-
* This interface is only here for backward compatibility, **do not add it by yourself**
|
|
46
|
-
*
|
|
47
|
-
* @ignore
|
|
48
|
-
*/
|
|
49
|
-
export interface StorageConfig {
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated Use `provideLocalStoragePrefix()` method instead
|
|
52
|
-
*/
|
|
53
|
-
LSPrefix?: string;
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated Use `provideIndexedDBDataBaseName()` method instead
|
|
56
|
-
*/
|
|
57
|
-
IDBDBName?: string;
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated Use `provideIndexedDBStoreName()` method instead
|
|
60
|
-
*/
|
|
61
|
-
IDBStoreName?: string;
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated Use `provideIndexedDBDataBaseVersion()` method instead
|
|
64
|
-
*/
|
|
65
|
-
IDBDBVersion?: number;
|
|
66
|
-
/**
|
|
67
|
-
* Allows interoperability with native `indexedDB` and other storage libs,
|
|
68
|
-
* by changing how values are stored in `indexedDB` database.
|
|
69
|
-
*
|
|
70
|
-
* Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
|
|
71
|
-
*
|
|
72
|
-
* **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
|
|
73
|
-
*/
|
|
74
|
-
IDBNoWrap?: boolean;
|
|
75
|
-
}
|