@ngx-pwa/local-storage 18.0.0 → 19.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/fesm2022/ngx-pwa-local-storage.mjs +48 -35
- package/fesm2022/ngx-pwa-local-storage.mjs.map +1 -1
- package/package.json +3 -5
- package/schematics/ng-add/index.js +7 -7
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-update/index.js +14 -24
- package/schematics/ng-update/index.js.map +1 -1
- package/schematics/utility/config.js +24 -34
- package/schematics/utility/config.js.map +1 -1
- package/schematics/utility/module.js +3 -3
- package/schematics/utility/module.js.map +1 -1
- package/esm2022/lib/databases/exceptions.mjs +0 -28
- package/esm2022/lib/databases/indexeddb-database.mjs +0 -308
- package/esm2022/lib/databases/local-database.mjs +0 -66
- package/esm2022/lib/databases/localstorage-database.mjs +0 -158
- package/esm2022/lib/databases/memory-database.mjs +0 -84
- package/esm2022/lib/providers.mjs +0 -66
- package/esm2022/lib/storage.module.mjs +0 -34
- package/esm2022/lib/storages/exceptions.mjs +0 -15
- package/esm2022/lib/storages/storage-map.service.mjs +0 -340
- package/esm2022/lib/tokens.mjs +0 -59
- package/esm2022/lib/validation/json-schema.mjs +0 -5
- package/esm2022/lib/validation/json-validator.mjs +0 -244
- package/esm2022/ngx-pwa-local-storage.mjs +0 -5
- package/esm2022/public-api.mjs +0 -9
|
@@ -169,19 +169,23 @@ class StorageModule {
|
|
|
169
169
|
return {
|
|
170
170
|
ngModule: StorageModule,
|
|
171
171
|
providers: [
|
|
172
|
-
|
|
173
|
-
config.
|
|
174
|
-
|
|
175
|
-
config.
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
173
|
+
config.LSPrefix !== undefined ? { provide: LS_PREFIX, useValue: config.LSPrefix } : [],
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
175
|
+
config.IDBDBName !== undefined ? { provide: IDB_DB_NAME, useValue: config.IDBDBName } : [],
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
177
|
+
config.IDBStoreName !== undefined ? { provide: IDB_STORE_NAME, useValue: config.IDBStoreName } : [],
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
179
|
+
config.IDBDBVersion !== undefined ? { provide: IDB_DB_VERSION, useValue: config.IDBDBVersion } : [],
|
|
176
180
|
(config.IDBNoWrap === false) ? { provide: IDB_NO_WRAP, useValue: config.IDBNoWrap } : [],
|
|
177
181
|
],
|
|
178
182
|
};
|
|
179
183
|
}
|
|
180
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
181
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
182
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
184
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
185
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.0", ngImport: i0, type: StorageModule }); }
|
|
186
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageModule }); }
|
|
183
187
|
}
|
|
184
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
188
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageModule, decorators: [{
|
|
185
189
|
type: NgModule
|
|
186
190
|
}] });
|
|
187
191
|
|
|
@@ -203,7 +207,7 @@ class ValidationError extends Error {
|
|
|
203
207
|
class LocalStorageDatabase {
|
|
204
208
|
constructor() {
|
|
205
209
|
/* Prefix if asked, or no prefix otherwise */
|
|
206
|
-
this.prefix = inject(LS_PREFIX)
|
|
210
|
+
this.prefix = inject(LS_PREFIX);
|
|
207
211
|
}
|
|
208
212
|
/**
|
|
209
213
|
* Number of items in `localStorage`
|
|
@@ -229,6 +233,7 @@ class LocalStorageDatabase {
|
|
|
229
233
|
return of(parsedData);
|
|
230
234
|
}
|
|
231
235
|
catch (error) {
|
|
236
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
232
237
|
return throwError(() => error);
|
|
233
238
|
}
|
|
234
239
|
}
|
|
@@ -253,6 +258,7 @@ class LocalStorageDatabase {
|
|
|
253
258
|
serializedData = JSON.stringify(data);
|
|
254
259
|
}
|
|
255
260
|
catch (error) {
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
256
262
|
return throwError(() => error);
|
|
257
263
|
}
|
|
258
264
|
/* Can fail if storage quota is exceeded */
|
|
@@ -260,6 +266,7 @@ class LocalStorageDatabase {
|
|
|
260
266
|
localStorage.setItem(this.prefixKey(key), serializedData);
|
|
261
267
|
}
|
|
262
268
|
catch (error) {
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
263
270
|
return throwError(() => error);
|
|
264
271
|
}
|
|
265
272
|
/* Wrap in a RxJS `Observable` to be consistent with other storages */
|
|
@@ -329,7 +336,7 @@ class LocalStorageDatabase {
|
|
|
329
336
|
const prefixedKey = localStorage.key(index);
|
|
330
337
|
if (prefixedKey !== null) {
|
|
331
338
|
/* If no prefix, the key is already good, otherwrite strip the prefix */
|
|
332
|
-
return
|
|
339
|
+
return this.prefix === "" ? prefixedKey : prefixedKey.substring(this.prefix.length);
|
|
333
340
|
}
|
|
334
341
|
return null;
|
|
335
342
|
}
|
|
@@ -341,10 +348,10 @@ class LocalStorageDatabase {
|
|
|
341
348
|
prefixKey(key) {
|
|
342
349
|
return `${this.prefix}${key}`;
|
|
343
350
|
}
|
|
344
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
345
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
351
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalStorageDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
352
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalStorageDatabase, providedIn: "root" }); }
|
|
346
353
|
}
|
|
347
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
354
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalStorageDatabase, decorators: [{
|
|
348
355
|
type: Injectable,
|
|
349
356
|
args: [{
|
|
350
357
|
providedIn: "root"
|
|
@@ -421,10 +428,10 @@ class MemoryDatabase {
|
|
|
421
428
|
/* Wrap in a RxJS `Observable` to be consistent with other storages */
|
|
422
429
|
return of(this.memoryStorage.has(key));
|
|
423
430
|
}
|
|
424
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
425
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
431
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: MemoryDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
432
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: MemoryDatabase, providedIn: "root" }); }
|
|
426
433
|
}
|
|
427
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
434
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: MemoryDatabase, decorators: [{
|
|
428
435
|
type: Injectable,
|
|
429
436
|
args: [{
|
|
430
437
|
providedIn: "root"
|
|
@@ -479,10 +486,10 @@ function localDatabaseFactory() {
|
|
|
479
486
|
return new MemoryDatabase();
|
|
480
487
|
}
|
|
481
488
|
class LocalDatabase {
|
|
482
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
483
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
489
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
490
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalDatabase, providedIn: "root", useFactory: localDatabaseFactory }); }
|
|
484
491
|
}
|
|
485
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
492
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
|
|
486
493
|
type: Injectable,
|
|
487
494
|
args: [{
|
|
488
495
|
providedIn: "root",
|
|
@@ -642,7 +649,7 @@ class IndexedDBDatabase {
|
|
|
642
649
|
/* Listen to success event */
|
|
643
650
|
const success$ = fromEvent(request, "success").pipe(
|
|
644
651
|
/* Stop the `Observable` when the cursor is `null` */
|
|
645
|
-
// eslint-disable-next-line rxjs/no-ignored-takewhile-value -- Required by indexedDb behavior, getting the result from the event does not always work
|
|
652
|
+
// // eslint-disable-next-line rxjs/no-ignored-takewhile-value -- Required by indexedDb behavior, getting the result from the event does not always work
|
|
646
653
|
takeWhile(() => (request.result !== null)),
|
|
647
654
|
/* This lib only allows string keys, but user could have added other types of keys from outside
|
|
648
655
|
* It's OK to cast as the cursor as been tested in the previous operator */
|
|
@@ -747,6 +754,7 @@ class IndexedDBDatabase {
|
|
|
747
754
|
}
|
|
748
755
|
catch (error) {
|
|
749
756
|
/* The store could have been deleted from outside */
|
|
757
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
750
758
|
return throwError(() => error);
|
|
751
759
|
}
|
|
752
760
|
/* Get the store from the transaction */
|
|
@@ -766,6 +774,7 @@ class IndexedDBDatabase {
|
|
|
766
774
|
/* Throw on error to be able to catch errors in RxJS way.
|
|
767
775
|
* Here `event.target` must be used, as `transactionOrRequest.error` will be `null`
|
|
768
776
|
* if we are on the request and the error is only triggered later by the transaction */
|
|
777
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
769
778
|
mergeMap((event) => throwError(() => event.target?.error)));
|
|
770
779
|
}
|
|
771
780
|
/**
|
|
@@ -781,10 +790,10 @@ class IndexedDBDatabase {
|
|
|
781
790
|
/* Choose the first event to occur */
|
|
782
791
|
return race([complete$, error$]);
|
|
783
792
|
}
|
|
784
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
785
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
793
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: IndexedDBDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
794
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: IndexedDBDatabase, providedIn: "root" }); }
|
|
786
795
|
}
|
|
787
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
796
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: IndexedDBDatabase, decorators: [{
|
|
788
797
|
type: Injectable,
|
|
789
798
|
args: [{
|
|
790
799
|
providedIn: "root"
|
|
@@ -837,7 +846,7 @@ class JSONValidator {
|
|
|
837
846
|
if ((schema.minLength !== undefined) && (data.length < schema.minLength)) {
|
|
838
847
|
return false;
|
|
839
848
|
}
|
|
840
|
-
if (schema.pattern) {
|
|
849
|
+
if (schema.pattern !== undefined) {
|
|
841
850
|
try {
|
|
842
851
|
const regularExpression = new RegExp(schema.pattern);
|
|
843
852
|
if (!regularExpression.test(data)) {
|
|
@@ -870,7 +879,7 @@ class JSONValidator {
|
|
|
870
879
|
return false;
|
|
871
880
|
}
|
|
872
881
|
/* Test is done this way to not divide by 0 */
|
|
873
|
-
if (schema.multipleOf && !Number.isInteger(data / schema.multipleOf)) {
|
|
882
|
+
if (schema.multipleOf !== undefined && schema.multipleOf !== 0 && Number.isFinite(schema.multipleOf) && !Number.isInteger(data / schema.multipleOf)) {
|
|
874
883
|
return false;
|
|
875
884
|
}
|
|
876
885
|
if ((schema.maximum !== undefined) && (data > schema.maximum)) {
|
|
@@ -918,7 +927,7 @@ class JSONValidator {
|
|
|
918
927
|
if ((schema.minItems !== undefined) && (data.length < schema.minItems)) {
|
|
919
928
|
return false;
|
|
920
929
|
}
|
|
921
|
-
if (schema.uniqueItems) {
|
|
930
|
+
if (schema.uniqueItems === true) {
|
|
922
931
|
/* Create a set to eliminate values with multiple occurences */
|
|
923
932
|
const dataSet = new Set(data);
|
|
924
933
|
if (data.length !== dataSet.size) {
|
|
@@ -934,6 +943,7 @@ class JSONValidator {
|
|
|
934
943
|
for (const value of data) {
|
|
935
944
|
// TODO: remove when TypeScript 4.1 is available
|
|
936
945
|
// (currently the narrowed type from `Array.isArray()` is lost on readonly arrays)
|
|
946
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
937
947
|
if (!this.validate(value, schema.items)) {
|
|
938
948
|
return false;
|
|
939
949
|
}
|
|
@@ -990,7 +1000,7 @@ class JSONValidator {
|
|
|
990
1000
|
for (const property in schema.properties) {
|
|
991
1001
|
/* Filter to keep only real properties (no internal JS stuff) and check if the data has the property too */
|
|
992
1002
|
if (Object.hasOwn(schema.properties, property) && Object.hasOwn(data, property)) {
|
|
993
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Ensured by the logic
|
|
1003
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unsafe-type-assertion -- Ensured by the logic
|
|
994
1004
|
if (!this.validate(data[property], schema.properties[property])) {
|
|
995
1005
|
return false;
|
|
996
1006
|
}
|
|
@@ -1005,7 +1015,7 @@ class JSONValidator {
|
|
|
1005
1015
|
* @returns If data is valid: `true`, if it is invalid: `false`
|
|
1006
1016
|
*/
|
|
1007
1017
|
validateConst(data, schema) {
|
|
1008
|
-
if (
|
|
1018
|
+
if (schema.const === undefined) {
|
|
1009
1019
|
return true;
|
|
1010
1020
|
}
|
|
1011
1021
|
return (data === schema.const);
|
|
@@ -1021,12 +1031,13 @@ class JSONValidator {
|
|
|
1021
1031
|
return true;
|
|
1022
1032
|
}
|
|
1023
1033
|
/* Cast as the data can be of multiple types, and so TypeScript is lost */
|
|
1034
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
1024
1035
|
return (schema.enum.includes(data));
|
|
1025
1036
|
}
|
|
1026
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1027
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1037
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: JSONValidator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1038
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: JSONValidator, providedIn: "root" }); }
|
|
1028
1039
|
}
|
|
1029
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1040
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: JSONValidator, decorators: [{
|
|
1030
1041
|
type: Injectable,
|
|
1031
1042
|
args: [{
|
|
1032
1043
|
providedIn: "root"
|
|
@@ -1146,6 +1157,7 @@ class StorageMap {
|
|
|
1146
1157
|
return throwError(() => new ValidationError());
|
|
1147
1158
|
}
|
|
1148
1159
|
/* Data have been checked, so it's OK to cast */
|
|
1160
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
1149
1161
|
return of(data);
|
|
1150
1162
|
}
|
|
1151
1163
|
/* Cast to unknown as the data wasn't checked */
|
|
@@ -1287,6 +1299,7 @@ class StorageMap {
|
|
|
1287
1299
|
});
|
|
1288
1300
|
/* Only the public API of the Observable should be returned */
|
|
1289
1301
|
return (schema ?
|
|
1302
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
1290
1303
|
notifier.asObservable() :
|
|
1291
1304
|
notifier.asObservable());
|
|
1292
1305
|
}
|
|
@@ -1346,15 +1359,15 @@ class StorageMap {
|
|
|
1346
1359
|
* @private
|
|
1347
1360
|
* @ignore
|
|
1348
1361
|
*/
|
|
1349
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1362
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Silence the not used error, it is used in tests
|
|
1350
1363
|
// @ts-ignore
|
|
1351
1364
|
ɵinternalGetDatabase() {
|
|
1352
1365
|
return this.#database;
|
|
1353
1366
|
}
|
|
1354
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1355
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1367
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageMap, deps: [{ token: LocalDatabase }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1368
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageMap, providedIn: "root" }); }
|
|
1356
1369
|
}
|
|
1357
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1370
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageMap, decorators: [{
|
|
1358
1371
|
type: Injectable,
|
|
1359
1372
|
args: [{
|
|
1360
1373
|
providedIn: "root"
|