@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2016-2024 Cyrille Tuzi
3
+ Copyright (c) 2016-2025 Cyrille Tuzi
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -12,10 +12,7 @@ const IDB_BROKEN_ERROR = "indexedDB is not working";
12
12
  * Exception raised when `indexedDB` is not working
13
13
  */
14
14
  class IDBBrokenError extends Error {
15
- constructor() {
16
- super(...arguments);
17
- this.message = IDB_BROKEN_ERROR;
18
- }
15
+ message = IDB_BROKEN_ERROR;
19
16
  }
20
17
  /**
21
18
  * Exception message when a value cannot be serialized for `localStorage`
@@ -26,10 +23,7 @@ where data must be serialized, and the provided data can't be serialized.`;
26
23
  * Exception throwned when a value cannot be serialized for `localStorage`
27
24
  */
28
25
  class SerializationError extends Error {
29
- constructor() {
30
- super(...arguments);
31
- this.message = SERIALIZATION_ERROR;
32
- }
26
+ message = SERIALIZATION_ERROR;
33
27
  }
34
28
 
35
29
  /**
@@ -181,11 +175,11 @@ class StorageModule {
181
175
  ],
182
176
  };
183
177
  }
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 }); }
178
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
179
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.0", ngImport: i0, type: StorageModule });
180
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageModule });
187
181
  }
188
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageModule, decorators: [{
182
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageModule, decorators: [{
189
183
  type: NgModule
190
184
  }] });
191
185
 
@@ -198,13 +192,14 @@ Check your JSON schema, otherwise it means data has been corrupted.`;
198
192
  * Exception throwned when a value is not valid against the JSON schema
199
193
  */
200
194
  class ValidationError extends Error {
201
- constructor() {
202
- super(...arguments);
203
- this.message = VALIDATION_ERROR;
204
- }
195
+ message = VALIDATION_ERROR;
205
196
  }
206
197
 
207
198
  class LocalStorageDatabase {
199
+ /**
200
+ * Optional user prefix to avoid collision for multiple apps on the same subdomain
201
+ */
202
+ prefix;
208
203
  constructor() {
209
204
  /* Prefix if asked, or no prefix otherwise */
210
205
  this.prefix = inject(LS_PREFIX);
@@ -249,13 +244,16 @@ class LocalStorageDatabase {
249
244
  let serializedData = null;
250
245
  /* Check if data can be serialized */
251
246
  const dataPrototype = Object.getPrototypeOf(data);
252
- if ((typeof data === "object") && (data !== null) && !Array.isArray(data) &&
247
+ if ((typeof data === "object") && !Array.isArray(data) &&
253
248
  !((dataPrototype === Object.prototype) || (dataPrototype === null))) {
254
249
  return throwError(() => new SerializationError());
255
250
  }
256
251
  /* Try to stringify (can fail on circular references) */
257
252
  try {
258
253
  serializedData = JSON.stringify(data);
254
+ if (serializedData === undefined) {
255
+ throw new Error();
256
+ }
259
257
  }
260
258
  catch (error) {
261
259
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
@@ -348,10 +346,10 @@ class LocalStorageDatabase {
348
346
  prefixKey(key) {
349
347
  return `${this.prefix}${key}`;
350
348
  }
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" }); }
349
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalStorageDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
350
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalStorageDatabase, providedIn: "root" });
353
351
  }
354
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalStorageDatabase, decorators: [{
352
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalStorageDatabase, decorators: [{
355
353
  type: Injectable,
356
354
  args: [{
357
355
  providedIn: "root"
@@ -359,12 +357,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
359
357
  }], ctorParameters: () => [] });
360
358
 
361
359
  class MemoryDatabase {
362
- constructor() {
363
- /**
364
- * Memory storage
365
- */
366
- this.memoryStorage = new Map();
367
- }
360
+ /**
361
+ * Memory storage
362
+ */
363
+ memoryStorage = new Map();
368
364
  /**
369
365
  * Number of items in memory
370
366
  */
@@ -428,10 +424,10 @@ class MemoryDatabase {
428
424
  /* Wrap in a RxJS `Observable` to be consistent with other storages */
429
425
  return of(this.memoryStorage.has(key));
430
426
  }
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" }); }
427
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: MemoryDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
428
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: MemoryDatabase, providedIn: "root" });
433
429
  }
434
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: MemoryDatabase, decorators: [{
430
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: MemoryDatabase, decorators: [{
435
431
  type: Injectable,
436
432
  args: [{
437
433
  providedIn: "root"
@@ -486,10 +482,10 @@ function localDatabaseFactory() {
486
482
  return new MemoryDatabase();
487
483
  }
488
484
  class LocalDatabase {
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 }); }
485
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
486
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalDatabase, providedIn: "root", useFactory: localDatabaseFactory });
491
487
  }
492
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
488
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
493
489
  type: Injectable,
494
490
  args: [{
495
491
  providedIn: "root",
@@ -498,16 +494,32 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
498
494
  }] });
499
495
 
500
496
  class IndexedDBDatabase {
497
+ /**
498
+ * `indexedDB` database name
499
+ */
500
+ dbName;
501
+ /**
502
+ * `indexedDB` object store name
503
+ */
504
+ storeName;
505
+ /**
506
+ * `indexedDB` database version. Must be an unsigned **integer**
507
+ */
508
+ dbVersion;
509
+ /**
510
+ * `indexedDB` database connection, wrapped in a RxJS `ReplaySubject` to be able to access the connection
511
+ * even after the connection success event happened
512
+ */
513
+ database = new ReplaySubject(1);
514
+ /**
515
+ * Flag to not wrap `indexedDB` values for interoperability or to wrap for backward compatibility.
516
+ */
517
+ noWrap;
518
+ /**
519
+ * Index used when wrapping value. *For backward compatibility only.*
520
+ */
521
+ wrapIndex = "value";
501
522
  constructor() {
502
- /**
503
- * `indexedDB` database connection, wrapped in a RxJS `ReplaySubject` to be able to access the connection
504
- * even after the connection success event happened
505
- */
506
- this.database = new ReplaySubject(1);
507
- /**
508
- * Index used when wrapping value. *For backward compatibility only.*
509
- */
510
- this.wrapIndex = "value";
511
523
  this.dbName = inject(IDB_DB_NAME);
512
524
  this.storeName = inject(IDB_STORE_NAME);
513
525
  this.dbVersion = inject(IDB_DB_VERSION);
@@ -790,10 +802,10 @@ class IndexedDBDatabase {
790
802
  /* Choose the first event to occur */
791
803
  return race([complete$, error$]);
792
804
  }
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" }); }
805
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: IndexedDBDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
806
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: IndexedDBDatabase, providedIn: "root" });
795
807
  }
796
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: IndexedDBDatabase, decorators: [{
808
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: IndexedDBDatabase, decorators: [{
797
809
  type: Injectable,
798
810
  args: [{
799
811
  providedIn: "root"
@@ -937,6 +949,7 @@ class JSONValidator {
937
949
  /* Specific test for tuples */
938
950
  if (Array.isArray(schema.items) || schema.items === undefined) {
939
951
  // TODO: cast should not be needed here
952
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
940
953
  return this.validateTuple(data, schema.items);
941
954
  }
942
955
  /* Validate all the values in array */
@@ -1034,10 +1047,10 @@ class JSONValidator {
1034
1047
  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
1035
1048
  return (schema.enum.includes(data));
1036
1049
  }
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" }); }
1050
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: JSONValidator, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1051
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: JSONValidator, providedIn: "root" });
1039
1052
  }
1040
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: JSONValidator, decorators: [{
1053
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: JSONValidator, decorators: [{
1041
1054
  type: Injectable,
1042
1055
  args: [{
1043
1056
  providedIn: "root"
@@ -1364,10 +1377,10 @@ class StorageMap {
1364
1377
  ɵinternalGetDatabase() {
1365
1378
  return this.#database;
1366
1379
  }
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" }); }
1380
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageMap, deps: [{ token: LocalDatabase }], target: i0.ɵɵFactoryTarget.Injectable });
1381
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageMap, providedIn: "root" });
1369
1382
  }
1370
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StorageMap, decorators: [{
1383
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImport: i0, type: StorageMap, decorators: [{
1371
1384
  type: Injectable,
1372
1385
  args: [{
1373
1386
  providedIn: "root"