@ngx-pwa/local-storage 16.2.0 → 17.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.
@@ -1,8 +1,8 @@
1
- import { isPlatformBrowser } from '@angular/common';
2
1
  import * as i0 from '@angular/core';
3
- import { InjectionToken, inject, Injectable, PLATFORM_ID, makeEnvironmentProviders, NgModule } from '@angular/core';
4
- import { ReplaySubject, fromEvent, race, throwError, of, Observable, asyncScheduler, from } from 'rxjs';
5
- import { mergeMap, map, first, takeWhile, tap, observeOn, catchError } from 'rxjs/operators';
2
+ import { InjectionToken, makeEnvironmentProviders, NgModule, inject, Injectable, PLATFORM_ID } from '@angular/core';
3
+ import { ReplaySubject, fromEvent, race, throwError, of, asyncScheduler, Observable, from } from 'rxjs';
4
+ import { map, mergeMap, first, takeWhile, tap, observeOn, catchError } from 'rxjs/operators';
5
+ import { isPlatformBrowser } from '@angular/common';
6
6
 
7
7
  /**
8
8
  * Exception message when `indexedDB` is not working
@@ -90,6 +90,105 @@ const IDB_NO_WRAP = new InjectionToken("localStorageIDBWrap", {
90
90
  factory: () => DEFAULT_IDB_NO_WRAP
91
91
  });
92
92
 
93
+ /**
94
+ * Allows to add a prefix before `localStorage` keys.
95
+ * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
96
+ * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
97
+ *
98
+ * @example
99
+ * bootstrapApplication(AppComponent, {
100
+ * providers: [provideLocalStoragePrefix('custom_')]
101
+ * });
102
+ */
103
+ function provideLocalStoragePrefix(prefix) {
104
+ return makeEnvironmentProviders([{ provide: LS_PREFIX, useValue: prefix }]);
105
+ }
106
+ /**
107
+ * Allows to change the name used for `indexedDB` database.
108
+ * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
109
+ * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
110
+ *
111
+ * @example
112
+ * bootstrapApplication(AppComponent, {
113
+ * providers: [provideIndexedDBDataBaseName('custom')]
114
+ * });
115
+ */
116
+ function provideIndexedDBDataBaseName(name) {
117
+ return makeEnvironmentProviders([{ provide: IDB_DB_NAME, useValue: name }]);
118
+ }
119
+ /**
120
+ * Allows to change the database version used for `indexedDB` database.
121
+ * Must be an unsigned **integer**.
122
+ * **Use with caution as the creation of the store depends on the version.**
123
+ * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
124
+ * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
125
+ *
126
+ * @example
127
+ * bootstrapApplication(AppComponent, {
128
+ * providers: [provideIndexedDBDataBaseVersion(2)]
129
+ * });
130
+ */
131
+ function provideIndexedDBDataBaseVersion(version) {
132
+ return makeEnvironmentProviders([{ provide: IDB_DB_VERSION, useValue: version }]);
133
+ }
134
+ /**
135
+ * Allows to change the name used for `indexedDB` object store.
136
+ * *Use only* for interoperability with other APIs.
137
+ * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
138
+ *
139
+ * @example
140
+ * bootstrapApplication(AppComponent, {
141
+ * providers: [provideIndexedDBStoreName('custom')]
142
+ * });
143
+ */
144
+ function provideIndexedDBStoreName(name) {
145
+ return makeEnvironmentProviders([{ provide: IDB_STORE_NAME, useValue: name }]);
146
+ }
147
+
148
+ /**
149
+ * This module is only here for backward compatibility, do not add it by yourself
150
+ */
151
+ class StorageModule {
152
+ /**
153
+ * Only useful to provide options, otherwise it does nothing.
154
+ * **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
155
+ *
156
+ */
157
+ static forRoot(config) {
158
+ return {
159
+ ngModule: StorageModule,
160
+ providers: [
161
+ config.LSPrefix ? { provide: LS_PREFIX, useValue: config.LSPrefix } : [],
162
+ config.IDBDBName ? { provide: IDB_DB_NAME, useValue: config.IDBDBName } : [],
163
+ config.IDBStoreName ? { provide: IDB_STORE_NAME, useValue: config.IDBStoreName } : [],
164
+ config.IDBDBVersion ? { provide: IDB_DB_VERSION, useValue: config.IDBDBVersion } : [],
165
+ (config.IDBNoWrap === false) ? { provide: IDB_NO_WRAP, useValue: config.IDBNoWrap } : [],
166
+ ],
167
+ };
168
+ }
169
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
170
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.0", ngImport: i0, type: StorageModule }); }
171
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageModule }); }
172
+ }
173
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageModule, decorators: [{
174
+ type: NgModule
175
+ }] });
176
+
177
+ /**
178
+ * Exception message when a value is not valid against the JSON schema
179
+ */
180
+ const VALIDATION_ERROR = `Data stored is not valid against the provided JSON schema.
181
+ Check your JSON schema, otherwise it means data has been corrupted.`;
182
+ /**
183
+ * Exception raised when a value is not valid against the JSON schema
184
+ */
185
+ class ValidationError extends Error {
186
+ constructor() {
187
+ super(...arguments);
188
+ this.message = VALIDATION_ERROR;
189
+ }
190
+ }
191
+
93
192
  class IndexedDBDatabase {
94
193
  constructor() {
95
194
  /**
@@ -245,7 +344,7 @@ class IndexedDBDatabase {
245
344
  takeWhile(() => (request.result !== null)),
246
345
  /* This lib only allows string keys, but user could have added other types of keys from outside
247
346
  * It's OK to cast as the cursor as been tested in the previous operator */
248
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
347
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-base-to-string
249
348
  map(() => request.result.key.toString()),
250
349
  /* Iterate on the cursor */
251
350
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -380,15 +479,15 @@ class IndexedDBDatabase {
380
479
  /* Choose the first event to occur */
381
480
  return race([complete$, error$]);
382
481
  }
383
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: IndexedDBDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
384
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: IndexedDBDatabase, providedIn: "root" }); }
482
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: IndexedDBDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
483
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: IndexedDBDatabase, providedIn: "root" }); }
385
484
  }
386
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: IndexedDBDatabase, decorators: [{
485
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: IndexedDBDatabase, decorators: [{
387
486
  type: Injectable,
388
487
  args: [{
389
488
  providedIn: "root"
390
489
  }]
391
- }], ctorParameters: function () { return []; } });
490
+ }], ctorParameters: () => [] });
392
491
 
393
492
  class LocalStorageDatabase {
394
493
  constructor() {
@@ -412,7 +511,7 @@ class LocalStorageDatabase {
412
511
  const unparsedData = localStorage.getItem(this.prefixKey(key));
413
512
  let parsedData;
414
513
  /* No need to parse if data is `null` or `undefined` */
415
- if ((unparsedData !== undefined) && (unparsedData !== null)) {
514
+ if (unparsedData !== null) {
416
515
  /* Try to parse */
417
516
  try {
418
517
  parsedData = JSON.parse(unparsedData);
@@ -531,15 +630,15 @@ class LocalStorageDatabase {
531
630
  prefixKey(key) {
532
631
  return `${this.prefix}${key}`;
533
632
  }
534
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorageDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
535
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorageDatabase, providedIn: "root" }); }
633
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalStorageDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
634
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalStorageDatabase, providedIn: "root" }); }
536
635
  }
537
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorageDatabase, decorators: [{
636
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalStorageDatabase, decorators: [{
538
637
  type: Injectable,
539
638
  args: [{
540
639
  providedIn: "root"
541
640
  }]
542
- }], ctorParameters: function () { return []; } });
641
+ }], ctorParameters: () => [] });
543
642
 
544
643
  class MemoryDatabase {
545
644
  constructor() {
@@ -611,199 +710,16 @@ class MemoryDatabase {
611
710
  /* Wrap in a RxJS `Observable` to be consistent with other storages */
612
711
  return of(this.memoryStorage.has(key));
613
712
  }
614
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MemoryDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
615
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MemoryDatabase, providedIn: "root" }); }
713
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: MemoryDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
714
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: MemoryDatabase, providedIn: "root" }); }
616
715
  }
617
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: MemoryDatabase, decorators: [{
716
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: MemoryDatabase, decorators: [{
618
717
  type: Injectable,
619
718
  args: [{
620
719
  providedIn: "root"
621
720
  }]
622
721
  }] });
623
722
 
624
- /**
625
- * Factory to create a storage according to browser support
626
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/BROWSERS_SUPPORT.md}
627
- */
628
- function localDatabaseFactory() {
629
- const platformId = inject(PLATFORM_ID);
630
- /* When storage is fully disabled in browser (via the "Block all cookies" option),
631
- * just trying to check `indexedDB` or `localStorage` variables causes a security exception.
632
- * Prevents https://github.com/cyrilletuzi/angular-async-local-storage/issues/118
633
- */
634
- try {
635
- // Do not explicit `window` here, as the global object is not the same in web workers
636
- if (isPlatformBrowser(platformId) && (indexedDB !== undefined) && (indexedDB !== null) && ("open" in indexedDB)) {
637
- /* Check:
638
- * - if we are in a browser context (issue: server-side rendering)
639
- * - it could exist but be `undefined` or `null`
640
- * - it could exists but not having a working API
641
- * Will be the case for:
642
- * - All other browsers in normal mode
643
- * - Chromium / Safari private mode, but in this case, data will be swiped when the user leaves the app */
644
- return new IndexedDBDatabase();
645
- }
646
- else if (isPlatformBrowser(platformId)
647
- && (localStorage !== undefined) && (localStorage !== null) && ("getItem" in localStorage)) {
648
- /* Check:
649
- * - if we are in a browser context (issue: server-side rendering)
650
- * - if `localStorage` exists (to be sure)
651
- * - it could exists but not having a working API
652
- * Will be the case for:
653
- * - Safari cross-origin iframes, detected later in `IndexedDBDatabase.connect()`
654
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/issues/42}
655
- * - Firefox private mode, but in this case, data will be swiped when the user leaves the app
656
- * For Firefox, can only be detected later in `IndexedDBDatabase.connect()`
657
- * @see {@link https://bugzilla.mozilla.org/show_bug.cgi?id=781982}
658
- */
659
- return new LocalStorageDatabase();
660
- }
661
- }
662
- catch {
663
- // Nothing to do
664
- }
665
- /* Will be the case for:
666
- * - In browsers if storage has been fully disabled (via the "Block all cookies" option)
667
- * - Server-side rendering
668
- * - All other non-browser context
669
- */
670
- return new MemoryDatabase();
671
- }
672
- class LocalDatabase {
673
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
674
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, providedIn: "root", useFactory: localDatabaseFactory }); }
675
- }
676
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
677
- type: Injectable,
678
- args: [{
679
- providedIn: "root",
680
- useFactory: localDatabaseFactory,
681
- }]
682
- }] });
683
-
684
- /**
685
- * Allows to add a prefix before `localStorage` keys.
686
- * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
687
- * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
688
- *
689
- * @example
690
- * bootstrapApplication(AppComponent, {
691
- * providers: [provideLocalStoragePrefix('custom_')]
692
- * });
693
- *
694
- * @example
695
- * NgModule({
696
- * providers: [provideLocalStoragePrefix('custom_')]
697
- * })
698
- * export class AppModule
699
- */
700
- function provideLocalStoragePrefix(prefix) {
701
- return makeEnvironmentProviders([{ provide: LS_PREFIX, useValue: prefix }]);
702
- }
703
- /**
704
- * Allows to change the name used for `indexedDB` database.
705
- * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
706
- * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
707
- *
708
- * @example
709
- * bootstrapApplication(AppComponent, {
710
- * providers: [provideIndexedDBDataBaseName('custom')]
711
- * });
712
- *
713
- * @example
714
- * NgModule({
715
- * providers: [provideIndexedDBDataBaseName('custom')]
716
- * })
717
- * export class AppModule
718
- */
719
- function provideIndexedDBDataBaseName(name) {
720
- return makeEnvironmentProviders([{ provide: IDB_DB_NAME, useValue: name }]);
721
- }
722
- /**
723
- * Allows to change the database version used for `indexedDB` database.
724
- * Must be an unsigned **integer**.
725
- * **Use with caution as the creation of the store depends on the version.**
726
- * *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
727
- * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
728
- *
729
- * @example
730
- * bootstrapApplication(AppComponent, {
731
- * providers: [provideIndexedDBDataBaseVersion(2)]
732
- * });
733
- *
734
- * @example
735
- * NgModule({
736
- * providers: [provideIndexedDBDataBaseVersion(2)]
737
- * })
738
- * export class AppModule
739
- */
740
- function provideIndexedDBDataBaseVersion(version) {
741
- return makeEnvironmentProviders([{ provide: IDB_DB_VERSION, useValue: version }]);
742
- }
743
- /**
744
- * Allows to change the name used for `indexedDB` object store.
745
- * *Use only* for interoperability with other APIs.
746
- * **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
747
- *
748
- * @example
749
- * bootstrapApplication(AppComponent, {
750
- * providers: [provideIndexedDBStoreName('custom')]
751
- * });
752
- *
753
- * @example
754
- * NgModule({
755
- * providers: [provideIndexedDBStoreName('custom')]
756
- * })
757
- * export class AppModule
758
- */
759
- function provideIndexedDBStoreName(name) {
760
- return makeEnvironmentProviders([{ provide: IDB_STORE_NAME, useValue: name }]);
761
- }
762
-
763
- /**
764
- * This module is only here for backward compatibility, do not add it by yourself
765
- */
766
- class StorageModule {
767
- /**
768
- * Only useful to provide options, otherwise it does nothing.
769
- * **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
770
- *
771
- */
772
- static forRoot(config) {
773
- return {
774
- ngModule: StorageModule,
775
- providers: [
776
- config.LSPrefix ? { provide: LS_PREFIX, useValue: config.LSPrefix } : [],
777
- config.IDBDBName ? { provide: IDB_DB_NAME, useValue: config.IDBDBName } : [],
778
- config.IDBStoreName ? { provide: IDB_STORE_NAME, useValue: config.IDBStoreName } : [],
779
- config.IDBDBVersion ? { provide: IDB_DB_VERSION, useValue: config.IDBDBVersion } : [],
780
- (config.IDBNoWrap === false) ? { provide: IDB_NO_WRAP, useValue: config.IDBNoWrap } : [],
781
- ],
782
- };
783
- }
784
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
785
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: StorageModule }); }
786
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule }); }
787
- }
788
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule, decorators: [{
789
- type: NgModule
790
- }] });
791
-
792
- /**
793
- * Exception message when a value is not valid against the JSON schema
794
- */
795
- const VALIDATION_ERROR = `Data stored is not valid against the provided JSON schema.
796
- Check your JSON schema, otherwise it means data has been corrupted.`;
797
- /**
798
- * Exception raised when a value is not valid against the JSON schema
799
- */
800
- class ValidationError extends Error {
801
- constructor() {
802
- super(...arguments);
803
- this.message = VALIDATION_ERROR;
804
- }
805
- }
806
-
807
723
  class JSONValidator {
808
724
  /**
809
725
  * Validate a JSON data against a Jsubset of the JSON Schema standard.
@@ -1038,16 +954,78 @@ class JSONValidator {
1038
954
  /* Cast as the data can be of multiple types, and so TypeScript is lost */
1039
955
  return (schema.enum.includes(data));
1040
956
  }
1041
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: JSONValidator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1042
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: JSONValidator, providedIn: "root" }); }
957
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: JSONValidator, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
958
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: JSONValidator, providedIn: "root" }); }
1043
959
  }
1044
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: JSONValidator, decorators: [{
960
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: JSONValidator, decorators: [{
1045
961
  type: Injectable,
1046
962
  args: [{
1047
963
  providedIn: "root"
1048
964
  }]
1049
965
  }] });
1050
966
 
967
+ /**
968
+ * Factory to create a storage according to browser support
969
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/BROWSERS_SUPPORT.md}
970
+ */
971
+ function localDatabaseFactory() {
972
+ const platformId = inject(PLATFORM_ID);
973
+ /* When storage is fully disabled in browser (via the "Block all cookies" option),
974
+ * just trying to check `indexedDB` or `localStorage` variables causes a security exception.
975
+ * Prevents https://github.com/cyrilletuzi/angular-async-local-storage/issues/118
976
+ */
977
+ try {
978
+ // Do not explicit `window` here, as the global object is not the same in web workers
979
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- They can be undefined in some browsers scenarios
980
+ if (isPlatformBrowser(platformId) && (indexedDB !== undefined) && (indexedDB !== null) && ("open" in indexedDB)) {
981
+ /* Check:
982
+ * - if we are in a browser context (issue: server-side rendering)
983
+ * - it could exist but be `undefined` or `null`
984
+ * - it could exists but not having a working API
985
+ * Will be the case for:
986
+ * - All other browsers in normal mode
987
+ * - Chromium / Safari private mode, but in this case, data will be swiped when the user leaves the app */
988
+ return new IndexedDBDatabase();
989
+ }
990
+ else if (isPlatformBrowser(platformId)
991
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- They can be undefined in some browsers scenarios
992
+ && (localStorage !== undefined) && (localStorage !== null) && ("getItem" in localStorage)) {
993
+ /* Check:
994
+ * - if we are in a browser context (issue: server-side rendering)
995
+ * - if `localStorage` exists (to be sure)
996
+ * - it could exists but not having a working API
997
+ * Will be the case for:
998
+ * - Safari cross-origin iframes, detected later in `IndexedDBDatabase.connect()`
999
+ * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/issues/42}
1000
+ * - Firefox private mode, but in this case, data will be swiped when the user leaves the app
1001
+ * For Firefox, can only be detected later in `IndexedDBDatabase.connect()`
1002
+ * @see {@link https://bugzilla.mozilla.org/show_bug.cgi?id=781982}
1003
+ */
1004
+ return new LocalStorageDatabase();
1005
+ }
1006
+ }
1007
+ catch {
1008
+ // Nothing to do
1009
+ }
1010
+ /* Will be the case for:
1011
+ * - In browsers if storage has been fully disabled (via the "Block all cookies" option)
1012
+ * - Server-side rendering
1013
+ * - All other non-browser context
1014
+ */
1015
+ return new MemoryDatabase();
1016
+ }
1017
+ class LocalDatabase {
1018
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1019
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalDatabase, providedIn: "root", useFactory: localDatabaseFactory }); }
1020
+ }
1021
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
1022
+ type: Injectable,
1023
+ args: [{
1024
+ providedIn: "root",
1025
+ useFactory: localDatabaseFactory,
1026
+ }]
1027
+ }] });
1028
+
1051
1029
  class StorageMap {
1052
1030
  /**
1053
1031
  * Constructor params are provided by Angular (but can also be passed manually in tests)
@@ -1260,8 +1238,12 @@ class StorageMap {
1260
1238
  const notifier = this.notifiers.get(key);
1261
1239
  /* Get the current item value */
1262
1240
  (schema ? this.get(key, schema) : this.get(key)).subscribe({
1263
- next: (result) => notifier.next(result),
1264
- error: (error) => notifier.error(error),
1241
+ next: (result) => {
1242
+ notifier.next(result);
1243
+ },
1244
+ error: (error) => {
1245
+ notifier.error(error);
1246
+ },
1265
1247
  });
1266
1248
  /* Only the public API of the `Observable` should be returned */
1267
1249
  return (schema ?
@@ -1318,95 +1300,15 @@ class StorageMap {
1318
1300
  }
1319
1301
  });
1320
1302
  }
1321
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageMap, deps: [{ token: LocalDatabase }, { token: JSONValidator }], target: i0.ɵɵFactoryTarget.Injectable }); }
1322
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageMap, providedIn: "root" }); }
1323
- }
1324
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageMap, decorators: [{
1325
- type: Injectable,
1326
- args: [{
1327
- providedIn: "root"
1328
- }]
1329
- }], ctorParameters: function () { return [{ type: LocalDatabase }, { type: JSONValidator }]; } });
1330
-
1331
- /**
1332
- * @deprecated Will be removed in v17
1333
- * @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/MIGRATION_TO_V16.md}
1334
- */
1335
- class LocalStorage {
1336
- /**
1337
- * Number of items in storage wrapped in an `Observable`
1338
- *
1339
- * @example
1340
- * this.localStorage.length.subscribe((length) => {
1341
- * console.log(length);
1342
- * });
1343
- */
1344
- get length() {
1345
- return this.storageMap.size;
1346
- }
1347
- /* Use the `StorageMap` service to avoid code duplication */
1348
- constructor(storageMap) {
1349
- this.storageMap = storageMap;
1350
- }
1351
- getItem(key, schema) {
1352
- if (schema) {
1353
- /* Backward compatibility with version <= 7 */
1354
- schema = ("schema" in schema) ? schema.schema : schema;
1355
- }
1356
- return (schema ? this.storageMap.get(key, schema) : this.storageMap.get(key)).pipe(
1357
- /* Transform `undefined` into `null` to align with `localStorage` API */
1358
- map((value) => (value !== undefined) ? value : null));
1359
- }
1360
- /**
1361
- * Set an item in storage.
1362
- * Note that setting `null` or `undefined` will remove the item to avoid some browsers issues.
1363
- * @param key The item's key
1364
- * @param data The item's value
1365
- * @param schema Optional JSON schema to validate the data
1366
- * @returns A RxJS `Observable` to wait the end of the operation
1367
- *
1368
- * @example
1369
- * this.localStorage.set('key', 'value').subscribe(() => {});
1370
- */
1371
- setItem(key, data, schema) {
1372
- return this.storageMap.set(key, data, schema).pipe(
1373
- /* Transform `undefined` into `true` for backward compatibility with v7 */
1374
- map(() => true));
1375
- }
1376
- /**
1377
- * Delete an item in storage
1378
- * @param key The item's key
1379
- * @returns A RxJS `Observable` to wait the end of the operation
1380
- *
1381
- * @example
1382
- * this.localStorage.delete('key').subscribe(() => {});
1383
- */
1384
- removeItem(key) {
1385
- return this.storageMap.delete(key).pipe(
1386
- /* Transform `undefined` into `true` for backward compatibility with v7 */
1387
- map(() => true));
1388
- }
1389
- /**
1390
- * Delete all items in storage
1391
- * @returns A RxJS `Observable` to wait the end of the operation
1392
- *
1393
- * @example
1394
- * this.localStorage.clear().subscribe(() => {});
1395
- */
1396
- clear() {
1397
- return this.storageMap.clear().pipe(
1398
- /* Transform `undefined` into `true` for backward compatibility with v7 */
1399
- map(() => true));
1400
- }
1401
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorage, deps: [{ token: StorageMap }], target: i0.ɵɵFactoryTarget.Injectable }); }
1402
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorage, providedIn: "root" }); }
1303
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageMap, deps: [{ token: LocalDatabase }, { token: JSONValidator }], target: i0.ɵɵFactoryTarget.Injectable }); }
1304
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageMap, providedIn: "root" }); }
1403
1305
  }
1404
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorage, decorators: [{
1306
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageMap, decorators: [{
1405
1307
  type: Injectable,
1406
1308
  args: [{
1407
1309
  providedIn: "root"
1408
1310
  }]
1409
- }], ctorParameters: function () { return [{ type: StorageMap }]; } });
1311
+ }], ctorParameters: () => [{ type: LocalDatabase }, { type: JSONValidator }] });
1410
1312
 
1411
1313
  /*
1412
1314
  * Public API Surface of local-storage
@@ -1416,5 +1318,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImpor
1416
1318
  * Generated bundle index. Do not edit.
1417
1319
  */
1418
1320
 
1419
- export { JSONValidator, LocalDatabase, LocalStorage, SERIALIZATION_ERROR, SerializationError, StorageMap, StorageModule, VALIDATION_ERROR, ValidationError, provideIndexedDBDataBaseName, provideIndexedDBDataBaseVersion, provideIndexedDBStoreName, provideLocalStoragePrefix };
1321
+ export { SERIALIZATION_ERROR, SerializationError, StorageMap, StorageModule, VALIDATION_ERROR, ValidationError, provideIndexedDBDataBaseName, provideIndexedDBDataBaseVersion, provideIndexedDBStoreName, provideLocalStoragePrefix };
1420
1322
  //# sourceMappingURL=ngx-pwa-local-storage.mjs.map