@ngx-pwa/local-storage 17.0.0 → 18.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 +14 -15
- package/esm2022/lib/databases/exceptions.mjs +3 -3
- package/esm2022/lib/databases/indexeddb-database.mjs +14 -12
- package/esm2022/lib/databases/local-database.mjs +6 -8
- package/esm2022/lib/databases/localstorage-database.mjs +10 -9
- package/esm2022/lib/databases/memory-database.mjs +6 -5
- package/esm2022/lib/providers.mjs +25 -16
- package/esm2022/lib/storage.module.mjs +9 -7
- package/esm2022/lib/storages/exceptions.mjs +2 -2
- package/esm2022/lib/storages/storage-map.service.mjs +117 -73
- package/esm2022/lib/tokens.mjs +1 -1
- package/esm2022/lib/validation/json-schema.mjs +1 -1
- package/esm2022/lib/validation/json-validator.mjs +13 -15
- package/esm2022/ngx-pwa-local-storage.mjs +1 -1
- package/esm2022/public-api.mjs +1 -1
- package/fesm2022/ngx-pwa-local-storage.mjs +616 -565
- package/fesm2022/ngx-pwa-local-storage.mjs.map +1 -1
- package/lib/databases/exceptions.d.ts +2 -2
- package/lib/databases/indexeddb-database.d.ts +12 -15
- package/lib/databases/localstorage-database.d.ts +2 -2
- package/lib/databases/memory-database.d.ts +1 -1
- package/lib/providers.d.ts +25 -16
- package/lib/storage.module.d.ts +6 -4
- package/lib/storages/exceptions.d.ts +1 -1
- package/lib/storages/storage-map.service.d.ts +100 -46
- package/lib/tokens.d.ts +7 -0
- package/lib/validation/json-schema.d.ts +10 -8
- package/lib/validation/json-validator.d.ts +9 -9
- package/package.json +4 -4
- package/public-api.d.ts +2 -2
- package/schematics/collection.json +1 -1
- package/schematics/migration.json +1 -1
- package/schematics/ng-add/index.d.ts +1 -1
- package/schematics/ng-add/index.js +2 -3
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-update/index.d.ts +1 -1
- package/schematics/ng-update/index.js +1 -2
- package/schematics/ng-update/index.js.map +1 -1
- package/schematics/utility/config.js +2 -1
- package/schematics/utility/config.js.map +1 -1
- package/schematics/utility/module.d.ts +1 -1
- package/schematics/utility/module.js +0 -1
- package/schematics/utility/module.js.map +1 -1
package/lib/providers.d.ts
CHANGED
|
@@ -1,47 +1,56 @@
|
|
|
1
|
-
import { EnvironmentProviders } from "@angular/core";
|
|
1
|
+
import { type EnvironmentProviders } from "@angular/core";
|
|
2
2
|
/**
|
|
3
3
|
* Allows to add a prefix before `localStorage` keys.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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.**
|
|
6
8
|
*
|
|
7
9
|
* @example
|
|
8
|
-
*
|
|
10
|
+
* export const appConfig: ApplicationConfig = {
|
|
9
11
|
* providers: [provideLocalStoragePrefix('custom_')]
|
|
10
|
-
* }
|
|
12
|
+
* };
|
|
11
13
|
*/
|
|
12
14
|
export declare function provideLocalStoragePrefix(prefix: string): EnvironmentProviders;
|
|
13
15
|
/**
|
|
14
16
|
* Allows to change the name used for `indexedDB` database.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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.**
|
|
17
21
|
*
|
|
18
22
|
* @example
|
|
19
|
-
*
|
|
23
|
+
* export const appConfig: ApplicationConfig = {
|
|
20
24
|
* providers: [provideIndexedDBDataBaseName('custom')]
|
|
21
|
-
* }
|
|
25
|
+
* };
|
|
22
26
|
*/
|
|
23
27
|
export declare function provideIndexedDBDataBaseName(name: string): EnvironmentProviders;
|
|
24
28
|
/**
|
|
25
29
|
* Allows to change the database version used for `indexedDB` database.
|
|
26
30
|
* Must be an unsigned **integer**.
|
|
31
|
+
*
|
|
27
32
|
* **Use with caution as the creation of the store depends on the version.**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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.**
|
|
30
37
|
*
|
|
31
38
|
* @example
|
|
32
|
-
*
|
|
39
|
+
* export const appConfig: ApplicationConfig = {
|
|
33
40
|
* providers: [provideIndexedDBDataBaseVersion(2)]
|
|
34
|
-
* }
|
|
41
|
+
* };
|
|
35
42
|
*/
|
|
36
43
|
export declare function provideIndexedDBDataBaseVersion(version: number): EnvironmentProviders;
|
|
37
44
|
/**
|
|
38
45
|
* Allows to change the name used for `indexedDB` object store.
|
|
46
|
+
*
|
|
39
47
|
* *Use only* for interoperability with other APIs.
|
|
40
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* **WARNING: do not change this option in an application already deployed in production, as previously stored data would be lost.**
|
|
41
50
|
*
|
|
42
51
|
* @example
|
|
43
|
-
*
|
|
52
|
+
* export const appConfig: ApplicationConfig = {
|
|
44
53
|
* providers: [provideIndexedDBStoreName('custom')]
|
|
45
|
-
* }
|
|
54
|
+
* };
|
|
46
55
|
*/
|
|
47
56
|
export declare function provideIndexedDBStoreName(name: string): EnvironmentProviders;
|
package/lib/storage.module.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ModuleWithProviders } from "@angular/core";
|
|
2
|
-
import { StorageConfig } from "./tokens";
|
|
1
|
+
import { type ModuleWithProviders } from "@angular/core";
|
|
2
|
+
import { type StorageConfig } from "./tokens";
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
/**
|
|
5
|
-
* This module is only here for backward compatibility, do not add it by yourself
|
|
5
|
+
* This module is only here for backward compatibility, **do not add it by yourself**
|
|
6
|
+
*
|
|
7
|
+
* @ignore
|
|
6
8
|
*/
|
|
7
9
|
export declare class StorageModule {
|
|
8
10
|
/**
|
|
9
11
|
* Only useful to provide options, otherwise it does nothing.
|
|
10
|
-
* **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
|
|
11
12
|
*
|
|
13
|
+
* **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
|
|
12
14
|
*/
|
|
13
15
|
static forRoot(config: StorageConfig): ModuleWithProviders<StorageModule>;
|
|
14
16
|
static ɵfac: i0.ɵɵFactoryDeclaration<StorageModule, never>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
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
5
|
/**
|
|
6
|
-
* Exception
|
|
6
|
+
* Exception throwned when a value is not valid against the JSON schema
|
|
7
7
|
*/
|
|
8
8
|
export declare class ValidationError extends Error {
|
|
9
9
|
message: string;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { Observable
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
2
|
import { LocalDatabase } from "../databases/local-database";
|
|
3
|
-
import { JSONSchema, JSONSchemaArrayOf, JSONSchemaBoolean, JSONSchemaInteger, JSONSchemaNumber, JSONSchemaString } from "../validation/json-schema";
|
|
4
|
-
import { JSONValidator } from "../validation/json-validator";
|
|
3
|
+
import type { JSONSchema, JSONSchemaArrayOf, JSONSchemaBoolean, JSONSchemaInteger, JSONSchemaNumber, JSONSchemaString } from "../validation/json-schema";
|
|
5
4
|
import * as i0 from "@angular/core";
|
|
6
5
|
export declare class StorageMap {
|
|
7
|
-
|
|
8
|
-
protected readonly jsonValidator: JSONValidator;
|
|
9
|
-
protected readonly notifiers: Map<string, ReplaySubject<unknown>>;
|
|
6
|
+
#private;
|
|
10
7
|
/**
|
|
11
8
|
* Constructor params are provided by Angular (but can also be passed manually in tests)
|
|
12
9
|
* @param database Storage to use
|
|
13
|
-
* @param jsonValidator Validator service
|
|
14
|
-
* @param LSPrefix Prefix for `localStorage` keys to avoid collision for multiple apps on the same subdomain or for interoperability
|
|
15
10
|
*/
|
|
16
|
-
constructor(database: LocalDatabase
|
|
11
|
+
constructor(database: LocalDatabase);
|
|
17
12
|
/**
|
|
18
|
-
* **Number of items** in storage, wrapped in an
|
|
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).
|
|
19
16
|
*
|
|
20
17
|
* @example
|
|
21
18
|
* this.storageMap.size.subscribe((size) => {
|
|
@@ -24,9 +21,12 @@ export declare class StorageMap {
|
|
|
24
21
|
*/
|
|
25
22
|
get size(): Observable<number>;
|
|
26
23
|
/**
|
|
27
|
-
* Tells you which storage engine is used.
|
|
24
|
+
* Tells you which storage engine is used.
|
|
25
|
+
*
|
|
26
|
+
* *Only useful for interoperability.*
|
|
27
|
+
*
|
|
28
28
|
* Note that due to some browsers issues in some special contexts
|
|
29
|
-
* (
|
|
29
|
+
* (like Safari cross-origin iframes),
|
|
30
30
|
* **this information may be wrong at initialization,**
|
|
31
31
|
* as the storage could fallback from `indexedDB` to `localStorage`
|
|
32
32
|
* only after a first read or write operation.
|
|
@@ -39,10 +39,12 @@ export declare class StorageMap {
|
|
|
39
39
|
*/
|
|
40
40
|
get backingEngine(): "indexedDB" | "localStorage" | "memory" | "unknown";
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Information about `indexedDB` database.
|
|
43
|
+
*
|
|
44
|
+
* *Only useful for interoperability.*
|
|
45
|
+
*
|
|
43
46
|
* @returns `indexedDB` database name, store name and database version.
|
|
44
|
-
* **Values will be empty if the storage is not `indexedDB
|
|
45
|
-
* **so it should be used after an engine check**.
|
|
47
|
+
* **Values will be empty if the storage is not `indexedDB`, so it should be used after an engine check**.
|
|
46
48
|
*
|
|
47
49
|
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
|
|
48
50
|
*
|
|
@@ -57,10 +59,12 @@ export declare class StorageMap {
|
|
|
57
59
|
version: number;
|
|
58
60
|
};
|
|
59
61
|
/**
|
|
60
|
-
*
|
|
62
|
+
* Information about `localStorage` fallback storage.
|
|
63
|
+
*
|
|
64
|
+
* *Only useful for interoperability.*
|
|
65
|
+
*
|
|
61
66
|
* @returns `localStorage` prefix.
|
|
62
|
-
* **Values will be empty if the storage is not `localStorage
|
|
63
|
-
* **so it should be used after an engine check**.
|
|
67
|
+
* **Values will be empty if the storage is not `localStorage`, so it should be used after an engine check**.
|
|
64
68
|
*
|
|
65
69
|
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/INTEROPERABILITY.md}
|
|
66
70
|
*
|
|
@@ -74,11 +78,18 @@ export declare class StorageMap {
|
|
|
74
78
|
};
|
|
75
79
|
/**
|
|
76
80
|
* Get an item value in storage.
|
|
77
|
-
*
|
|
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.
|
|
78
88
|
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
|
|
89
|
+
*
|
|
79
90
|
* @param key The item's key
|
|
80
|
-
* @param schema Optional JSON schema to validate the data
|
|
81
|
-
* @returns The item's value if the key exists, `undefined` otherwise, wrapped in a RxJS
|
|
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
|
|
82
93
|
*
|
|
83
94
|
* @example
|
|
84
95
|
* this.storageMap.get('key', { type: 'string' }).subscribe((result) => {
|
|
@@ -97,8 +108,8 @@ export declare class StorageMap {
|
|
|
97
108
|
* firstName: { type: 'string' },
|
|
98
109
|
* lastName: { type: 'string' },
|
|
99
110
|
* },
|
|
100
|
-
* required: ['firstName']
|
|
101
|
-
* };
|
|
111
|
+
* required: ['firstName'],
|
|
112
|
+
* } satisfies JSONSchema;
|
|
102
113
|
*
|
|
103
114
|
* this.storageMap.get<User>('user', schema).subscribe((user) => {
|
|
104
115
|
* if (user) {
|
|
@@ -115,40 +126,61 @@ export declare class StorageMap {
|
|
|
115
126
|
get<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
|
|
116
127
|
get<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
|
|
117
128
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
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
|
+
*
|
|
120
138
|
* @param key The item's key
|
|
121
139
|
* @param data The item's value
|
|
122
140
|
* @param schema Optional JSON schema to validate the data
|
|
123
|
-
* @returns A RxJS
|
|
141
|
+
* @returns A RxJS Observable to wait the end of the operation
|
|
124
142
|
*
|
|
125
143
|
* @example
|
|
126
144
|
* this.storageMap.set('key', 'value').subscribe(() => {});
|
|
127
145
|
*/
|
|
128
146
|
set(key: string, data: unknown, schema?: JSONSchema): Observable<undefined>;
|
|
129
147
|
/**
|
|
130
|
-
* Delete an item in storage
|
|
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
|
+
*
|
|
131
154
|
* @param key The item's key
|
|
132
|
-
* @returns A RxJS
|
|
155
|
+
* @returns A RxJS Observable to wait the end of the operation
|
|
133
156
|
*
|
|
134
157
|
* @example
|
|
135
158
|
* this.storageMap.delete('key').subscribe(() => {});
|
|
136
159
|
*/
|
|
137
160
|
delete(key: string): Observable<undefined>;
|
|
138
161
|
/**
|
|
139
|
-
* Delete all items in storage
|
|
140
|
-
*
|
|
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
|
|
141
169
|
*
|
|
142
170
|
* @example
|
|
143
171
|
* this.storageMap.clear().subscribe(() => {});
|
|
144
172
|
*/
|
|
145
173
|
clear(): Observable<undefined>;
|
|
146
174
|
/**
|
|
147
|
-
* Get all keys stored in storage.
|
|
175
|
+
* Get all keys stored in storage.
|
|
176
|
+
*
|
|
177
|
+
* Note **this is an *iterating* Observable**:
|
|
148
178
|
* * if there is no key, the `next` callback will not be invoked,
|
|
149
179
|
* * if you need to wait the whole operation to end, be sure to act in the `complete` callback,
|
|
150
|
-
* as this
|
|
151
|
-
*
|
|
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
|
|
152
184
|
*
|
|
153
185
|
* @example
|
|
154
186
|
* this.storageMap.keys().subscribe({
|
|
@@ -158,8 +190,11 @@ export declare class StorageMap {
|
|
|
158
190
|
*/
|
|
159
191
|
keys(): Observable<string>;
|
|
160
192
|
/**
|
|
161
|
-
* Tells if a key exists in storage
|
|
162
|
-
*
|
|
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
|
|
163
198
|
*
|
|
164
199
|
* @example
|
|
165
200
|
* this.storageMap.has('key').subscribe((hasKey) => {
|
|
@@ -169,12 +204,35 @@ export declare class StorageMap {
|
|
|
169
204
|
has(key: string): Observable<boolean>;
|
|
170
205
|
/**
|
|
171
206
|
* Watch an item value in storage.
|
|
172
|
-
*
|
|
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
|
+
*
|
|
173
212
|
* The signature has many overloads due to validation, **please refer to the documentation.**
|
|
174
213
|
* @see https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md
|
|
214
|
+
*
|
|
175
215
|
* @param key The item's key to watch
|
|
176
216
|
* @param schema Optional JSON schema to validate the initial value
|
|
177
|
-
* @returns An infinite
|
|
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
|
+
* }
|
|
178
236
|
*/
|
|
179
237
|
watch(key: string): Observable<unknown>;
|
|
180
238
|
watch<T extends string = string>(key: string, schema: JSONSchemaString): Observable<T | undefined>;
|
|
@@ -185,16 +243,12 @@ export declare class StorageMap {
|
|
|
185
243
|
watch<T extends readonly boolean[] = boolean[]>(key: string, schema: JSONSchemaArrayOf<JSONSchemaBoolean>): Observable<T | undefined>;
|
|
186
244
|
watch<T>(key: string, schema: JSONSchema): Observable<T | undefined>;
|
|
187
245
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @
|
|
191
|
-
|
|
192
|
-
protected notify(key: string, value: unknown): void;
|
|
193
|
-
/**
|
|
194
|
-
* RxJS operator to catch if `indexedDB` is broken
|
|
195
|
-
* @param operationCallback Callback with the operation to redo
|
|
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
|
|
196
250
|
*/
|
|
197
|
-
|
|
251
|
+
private ɵinternalGetDatabase;
|
|
198
252
|
static ɵfac: i0.ɵɵFactoryDeclaration<StorageMap, never>;
|
|
199
253
|
static ɵprov: i0.ɵɵInjectableDeclaration<StorageMap>;
|
|
200
254
|
}
|
package/lib/tokens.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ export declare const DEFAULT_IDB_NO_WRAP = true;
|
|
|
41
41
|
* **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
|
|
42
42
|
*/
|
|
43
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
|
+
*/
|
|
44
49
|
export interface StorageConfig {
|
|
45
50
|
/**
|
|
46
51
|
* @deprecated Use `provideLocalStoragePrefix()` method instead
|
|
@@ -61,7 +66,9 @@ export interface StorageConfig {
|
|
|
61
66
|
/**
|
|
62
67
|
* Allows interoperability with native `indexedDB` and other storage libs,
|
|
63
68
|
* by changing how values are stored in `indexedDB` database.
|
|
69
|
+
*
|
|
64
70
|
* Defaults to `true`. Change to `false` for backward compatiblity in existing applications.
|
|
71
|
+
*
|
|
65
72
|
* **DO NOT CHANGE THIS BEHAVIOR ONCE IN PRODUCTION**, as it would break with existing data.
|
|
66
73
|
*/
|
|
67
74
|
IDBNoWrap?: boolean;
|
|
@@ -224,35 +224,37 @@ export interface JSONSchemaObject {
|
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* Subset of the JSON Schema standard.
|
|
227
|
+
*
|
|
227
228
|
* Types are enforced to validate everything: each value **must** have a `type`.
|
|
229
|
+
*
|
|
228
230
|
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/VALIDATION.md}
|
|
229
231
|
*
|
|
230
232
|
* @example
|
|
231
|
-
* const schema
|
|
233
|
+
* const schema = { type: 'string' } satisfies JSONSchema;
|
|
232
234
|
*
|
|
233
235
|
* @example
|
|
234
|
-
* const schema
|
|
236
|
+
* const schema = { type: 'number' } satisfies JSONSchema;
|
|
235
237
|
*
|
|
236
238
|
* @example
|
|
237
|
-
* const schema
|
|
239
|
+
* const schema = { type: 'integer' } satisfies JSONSchema;
|
|
238
240
|
*
|
|
239
241
|
* @example
|
|
240
|
-
* const schema
|
|
242
|
+
* const schema = { type: 'boolean' } satisfies JSONSchema;
|
|
241
243
|
*
|
|
242
244
|
* @example
|
|
243
|
-
* const schema
|
|
245
|
+
* const schema = {
|
|
244
246
|
* type: 'array',
|
|
245
247
|
* items: { type: 'string' },
|
|
246
|
-
* };
|
|
248
|
+
* } satisfies JSONSchema;
|
|
247
249
|
*
|
|
248
250
|
* @example
|
|
249
|
-
* const schema
|
|
251
|
+
* const schema = {
|
|
250
252
|
* type: 'object',
|
|
251
253
|
* properties: {
|
|
252
254
|
* firstName: { type: 'string' },
|
|
253
255
|
* lastName: { type: 'string' },
|
|
254
256
|
* },
|
|
255
257
|
* required: ['firstName'],
|
|
256
|
-
* };
|
|
258
|
+
* } satisfies JSONSchema;
|
|
257
259
|
*/
|
|
258
260
|
export type JSONSchema = JSONSchemaString | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaBoolean | JSONSchemaArray | JSONSchemaTuple | JSONSchemaObject;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONSchema
|
|
1
|
+
import type { JSONSchema } from "./json-schema";
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
export declare class JSONValidator {
|
|
4
4
|
/**
|
|
@@ -16,56 +16,56 @@ export declare class JSONValidator {
|
|
|
16
16
|
* @param schema Schema describing the string
|
|
17
17
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
private validateString;
|
|
20
20
|
/**
|
|
21
21
|
* Validate a number or an integer
|
|
22
22
|
* @param data Data to validate
|
|
23
23
|
* @param schema Schema describing the number or integer
|
|
24
24
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
private validateNumber;
|
|
27
27
|
/**
|
|
28
28
|
* Validate a boolean
|
|
29
29
|
* @param data Data to validate
|
|
30
30
|
* @param schema Schema describing the boolean
|
|
31
31
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
private validateBoolean;
|
|
34
34
|
/**
|
|
35
35
|
* Validate an array
|
|
36
36
|
* @param data Data to validate
|
|
37
37
|
* @param schema Schema describing the array
|
|
38
38
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
private validateArray;
|
|
41
41
|
/**
|
|
42
42
|
* Validate a tuple (array with fixed length and multiple types)
|
|
43
43
|
* @param data Data to validate
|
|
44
44
|
* @param schemas Schemas describing the tuple
|
|
45
45
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
private validateTuple;
|
|
48
48
|
/**
|
|
49
49
|
* Validate an object
|
|
50
50
|
* @param data Data to validate
|
|
51
51
|
* @param schema JSON schema describing the object
|
|
52
52
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
private validateObject;
|
|
55
55
|
/**
|
|
56
56
|
* Validate a constant
|
|
57
57
|
* @param data Data ta validate
|
|
58
58
|
* @param schema JSON schema describing the constant
|
|
59
59
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
private validateConst;
|
|
62
62
|
/**
|
|
63
63
|
* Validate an enum
|
|
64
64
|
* @param data Data ta validate
|
|
65
65
|
* @param schema JSON schema describing the enum
|
|
66
66
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
private validateEnum;
|
|
69
69
|
static ɵfac: i0.ɵɵFactoryDeclaration<JSONValidator, never>;
|
|
70
70
|
static ɵprov: i0.ɵɵInjectableDeclaration<JSONValidator>;
|
|
71
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngx-pwa/local-storage",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "18.0.0",
|
|
4
4
|
"funding": {
|
|
5
5
|
"type": "github",
|
|
6
6
|
"url": "https://github.com/sponsors/cyrilletuzi"
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"tslib": "^2.5.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@angular/common": "^
|
|
24
|
-
"@angular/core": "^
|
|
25
|
-
"rxjs": "^7.
|
|
23
|
+
"@angular/common": "^18.0.0",
|
|
24
|
+
"@angular/core": "^18.0.0",
|
|
25
|
+
"rxjs": "^7.6.0"
|
|
26
26
|
},
|
|
27
27
|
"schematics": "./schematics/collection.json",
|
|
28
28
|
"ng-update": {
|
package/public-api.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { provideIndexedDBDataBaseName, provideIndexedDBDataBaseVersion, provideI
|
|
|
3
3
|
export { StorageModule } from "./lib/storage.module";
|
|
4
4
|
export { VALIDATION_ERROR, ValidationError } from "./lib/storages/exceptions";
|
|
5
5
|
export { StorageMap } from "./lib/storages/storage-map.service";
|
|
6
|
-
export { StorageConfig } from "./lib/tokens";
|
|
7
|
-
export { JSONSchema } from "./lib/validation/json-schema";
|
|
6
|
+
export type { StorageConfig } from "./lib/tokens";
|
|
7
|
+
export type { JSONSchema } from "./lib/validation/json-schema";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
3
3
|
"schematics": {
|
|
4
4
|
"ng-add": {
|
|
5
5
|
"description": "Add @ngx-pwa/local-storage library to the project.",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Rule } from "@angular-devkit/schematics";
|
|
1
|
+
import { type Rule } from "@angular-devkit/schematics";
|
|
2
2
|
export default function (): Rule;
|
|
@@ -10,12 +10,11 @@ function default_1() {
|
|
|
10
10
|
if (!angularMajorVersion) {
|
|
11
11
|
context.logger.warn(`Not able to detect @angular/core version. Be aware that Angular versions <= 14 are no longer supported.`);
|
|
12
12
|
}
|
|
13
|
-
if (angularMajorVersion && (angularMajorVersion <=
|
|
14
|
-
throw new schematics_1.SchematicsException("Angular versions <=
|
|
13
|
+
if (angularMajorVersion && (angularMajorVersion <= 15)) {
|
|
14
|
+
throw new schematics_1.SchematicsException("Angular versions <= 15 are no longer supported.");
|
|
15
15
|
}
|
|
16
16
|
const rxjsMajorVersion = (0, config_1.getDependencyMajorVersion)("rxjs", host);
|
|
17
17
|
if (!rxjsMajorVersion) {
|
|
18
|
-
// eslint-disable-next-line max-len
|
|
19
18
|
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is recommended for Angular 14 and required for Angular >= 15.`);
|
|
20
19
|
}
|
|
21
20
|
if (rxjsMajorVersion && (rxjsMajorVersion < 7)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/schematics/ng-add/index.ts"],"names":[],"mappings":";;AAAA,2DAAgH;AAChH,4DAA0E;AAC1E,8CAA8D;AAE9D;IACE,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAE/C,gBAAgB;QAChB,MAAM,mBAAmB,GAAG,IAAA,kCAAyB,EAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAE7E,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,yGAAyG,CAAC,CAAC;QACjI,CAAC;QAED,IAAI,mBAAmB,IAAI,CAAC,mBAAmB,IAAI,EAAE,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,gCAAmB,CAAC,iDAAiD,CAAC,CAAC;QACnF,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAA,kCAAyB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEjE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,kIAAkI,CAAC,CAAC;QAC1J,CAAC;QAED,IAAI,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,gCAAmB,CAAC,gEAAgE,CAAC,CAAC;QAClG,CAAC;QAED,yDAAyD;QACzD,OAAO,CAAC,OAAO,CAAC,IAAI,8BAAsB,EAAE,CAAC,CAAC;QAE9C,OAAO,IAAA,kBAAK,EAAC,EAAE,CAAC,CAAC;IAEnB,CAAC,CAAC;AACJ,CAAC;AA9BD,4BA8BC"}
|
|
@@ -35,7 +35,7 @@ function updateToV13() {
|
|
|
35
35
|
return (host, context) => {
|
|
36
36
|
const rxjsMajorVersion = (0, config_1.getDependencyMajorVersion)("rxjs", host);
|
|
37
37
|
if (!rxjsMajorVersion) {
|
|
38
|
-
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is recommended for version 13 of this
|
|
38
|
+
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is recommended for version 13 of this library.`);
|
|
39
39
|
}
|
|
40
40
|
if (rxjsMajorVersion && (rxjsMajorVersion < 7)) {
|
|
41
41
|
context.logger.warn(`rxjs should be updated to version >= 7.4. Support for rxjs version 6 is not guaranteed.`);
|
|
@@ -48,7 +48,6 @@ function updateToV15() {
|
|
|
48
48
|
return (host, context) => {
|
|
49
49
|
const rxjsMajorVersion = (0, config_1.getDependencyMajorVersion)("rxjs", host);
|
|
50
50
|
if (!rxjsMajorVersion) {
|
|
51
|
-
// eslint-disable-next-line max-len
|
|
52
51
|
context.logger.warn(`Not able to detect rxjs version. Be aware that rxjs version >= 7.4 is required for version 15 of this lib, rxjs 6 is not supported.`);
|
|
53
52
|
}
|
|
54
53
|
if (rxjsMajorVersion && (rxjsMajorVersion < 7)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/schematics/ng-update/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAgH;AAChH,8CAA+E;AAC/E,8CAAiD;AAEjD,SAAgB,UAAU;IACxB,OAAO,CAAO,IAAU,EAAE,EAAE;QAE1B,gBAAgB;QAChB,MAAM,SAAS,GAAG,MAAM,IAAA,wBAAe,EAAC,IAAI,CAAC,CAAC;QAE9C,wCAAwC;QACxC,OAAO,IAAA,kBAAK,EAAC,SAAS,C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AAI,gBAAgB,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,gCAAmB,CAAC,gEAAgE,CAAC,CAAC;QAClG,CAAC;QAED,OAAO,IAAI,CAAC;IAEd,CAAC,CAAC;AACJ,CAAC;AAhBD,kCAgBC"}
|
|
@@ -31,13 +31,14 @@ function getAllMainPaths(host) {
|
|
|
31
31
|
const workspace = yield (0, workspace_1.getWorkspace)(host);
|
|
32
32
|
/* Loop on all projects configured in angular.json */
|
|
33
33
|
workspace.projects.forEach((project) => {
|
|
34
|
+
var _a;
|
|
34
35
|
/* The schematic only work with applications (not librairies) */
|
|
35
36
|
if (project.extensions["projectType"] === "application") {
|
|
36
37
|
/* Get `main` option in angular.json project config */
|
|
37
38
|
const buildTarget = project.targets.get("build");
|
|
38
39
|
const e2eTarget = project.targets.get("e2e");
|
|
39
40
|
if (buildTarget) {
|
|
40
|
-
if (!buildTarget.options ||
|
|
41
|
+
if (!((_a = buildTarget.options) === null || _a === void 0 ? void 0 : _a["main"])) {
|
|
41
42
|
throw new schematics_1.SchematicsException(`angular.json config is broken, can't find 'architect.build.options.main' in one or more projects`);
|
|
42
43
|
}
|
|
43
44
|
mainPaths.push(buildTarget.options["main"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../lib/schematics/utility/config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuE;AACvE,2EAAoF;AACpF,qEAAqE;AAExD,QAAA,WAAW,GAAG,wBAAwB,CAAC;AAEpD,SAAgB,yBAAyB,CAAC,IAAY,EAAE,IAAU;IAEhE,MAAM,UAAU,GAAG,IAAA,uCAAwB,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAExD,uCAAuC;IACvC,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,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