@ngx-pwa/local-storage 16.3.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.
- package/esm2022/lib/databases/indexeddb-database.mjs +7 -8
- package/esm2022/lib/databases/local-database.mjs +7 -7
- package/esm2022/lib/databases/localstorage-database.mjs +7 -8
- package/esm2022/lib/databases/memory-database.mjs +5 -6
- package/esm2022/lib/providers.mjs +1 -25
- package/esm2022/lib/storage.module.mjs +6 -7
- package/esm2022/lib/storages/storage-map.service.mjs +12 -9
- package/esm2022/lib/validation/json-schema.mjs +1 -1
- package/esm2022/lib/validation/json-validator.mjs +5 -7
- package/esm2022/public-api.mjs +1 -4
- package/fesm2022/ngx-pwa-local-storage.mjs +192 -292
- package/fesm2022/ngx-pwa-local-storage.mjs.map +1 -1
- package/lib/databases/indexeddb-database.d.ts +1 -1
- package/lib/databases/local-database.d.ts +1 -2
- package/lib/databases/localstorage-database.d.ts +1 -1
- package/lib/databases/memory-database.d.ts +1 -1
- package/lib/providers.d.ts +0 -24
- package/lib/validation/json-schema.d.ts +1 -10
- package/lib/validation/json-validator.d.ts +0 -1
- package/package.json +3 -3
- package/public-api.d.ts +1 -4
- package/schematics/ng-add/index.js +4 -9
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/utility/module.js +1 -0
- package/schematics/utility/module.js.map +1 -1
- package/esm2022/lib/storages/local-storage.service.mjs +0 -85
- package/lib/storages/local-storage.service.d.ts +0 -99
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isPlatformBrowser } from '@angular/common';
|
|
2
1
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { InjectionToken,
|
|
4
|
-
import { ReplaySubject, fromEvent, race, throwError, of,
|
|
5
|
-
import {
|
|
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: "
|
|
384
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
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: "
|
|
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:
|
|
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 (
|
|
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: "
|
|
535
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
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: "
|
|
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:
|
|
641
|
+
}], ctorParameters: () => [] });
|
|
543
642
|
|
|
544
643
|
class MemoryDatabase {
|
|
545
644
|
constructor() {
|
|
@@ -611,201 +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: "
|
|
615
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
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: "
|
|
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
|
-
/** @deprecated Will be removed in v17 */
|
|
673
|
-
class LocalDatabase {
|
|
674
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
675
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, providedIn: "root", useFactory: localDatabaseFactory }); }
|
|
676
|
-
}
|
|
677
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalDatabase, decorators: [{
|
|
678
|
-
type: Injectable,
|
|
679
|
-
args: [{
|
|
680
|
-
providedIn: "root",
|
|
681
|
-
useFactory: localDatabaseFactory,
|
|
682
|
-
}]
|
|
683
|
-
}] });
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Allows to add a prefix before `localStorage` keys.
|
|
687
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
|
|
688
|
-
* **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
|
|
689
|
-
*
|
|
690
|
-
* @example
|
|
691
|
-
* bootstrapApplication(AppComponent, {
|
|
692
|
-
* providers: [provideLocalStoragePrefix('custom_')]
|
|
693
|
-
* });
|
|
694
|
-
*
|
|
695
|
-
* @example
|
|
696
|
-
* NgModule({
|
|
697
|
-
* providers: [provideLocalStoragePrefix('custom_')]
|
|
698
|
-
* })
|
|
699
|
-
* export class AppModule
|
|
700
|
-
*/
|
|
701
|
-
function provideLocalStoragePrefix(prefix) {
|
|
702
|
-
return makeEnvironmentProviders([{ provide: LS_PREFIX, useValue: prefix }]);
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Allows to change the name used for `indexedDB` database.
|
|
706
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
|
|
707
|
-
* **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
|
|
708
|
-
*
|
|
709
|
-
* @example
|
|
710
|
-
* bootstrapApplication(AppComponent, {
|
|
711
|
-
* providers: [provideIndexedDBDataBaseName('custom')]
|
|
712
|
-
* });
|
|
713
|
-
*
|
|
714
|
-
* @example
|
|
715
|
-
* NgModule({
|
|
716
|
-
* providers: [provideIndexedDBDataBaseName('custom')]
|
|
717
|
-
* })
|
|
718
|
-
* export class AppModule
|
|
719
|
-
*/
|
|
720
|
-
function provideIndexedDBDataBaseName(name) {
|
|
721
|
-
return makeEnvironmentProviders([{ provide: IDB_DB_NAME, useValue: name }]);
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Allows to change the database version used for `indexedDB` database.
|
|
725
|
-
* Must be an unsigned **integer**.
|
|
726
|
-
* **Use with caution as the creation of the store depends on the version.**
|
|
727
|
-
* *Use only* for interoperability with other APIs or to avoid collision for multiple apps on the same subdomain.
|
|
728
|
-
* **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
|
|
729
|
-
*
|
|
730
|
-
* @example
|
|
731
|
-
* bootstrapApplication(AppComponent, {
|
|
732
|
-
* providers: [provideIndexedDBDataBaseVersion(2)]
|
|
733
|
-
* });
|
|
734
|
-
*
|
|
735
|
-
* @example
|
|
736
|
-
* NgModule({
|
|
737
|
-
* providers: [provideIndexedDBDataBaseVersion(2)]
|
|
738
|
-
* })
|
|
739
|
-
* export class AppModule
|
|
740
|
-
*/
|
|
741
|
-
function provideIndexedDBDataBaseVersion(version) {
|
|
742
|
-
return makeEnvironmentProviders([{ provide: IDB_DB_VERSION, useValue: version }]);
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Allows to change the name used for `indexedDB` object store.
|
|
746
|
-
* *Use only* for interoperability with other APIs.
|
|
747
|
-
* **WARNING: do not change this option in an app already deployed in production, as previously stored data would be lost.**
|
|
748
|
-
*
|
|
749
|
-
* @example
|
|
750
|
-
* bootstrapApplication(AppComponent, {
|
|
751
|
-
* providers: [provideIndexedDBStoreName('custom')]
|
|
752
|
-
* });
|
|
753
|
-
*
|
|
754
|
-
* @example
|
|
755
|
-
* NgModule({
|
|
756
|
-
* providers: [provideIndexedDBStoreName('custom')]
|
|
757
|
-
* })
|
|
758
|
-
* export class AppModule
|
|
759
|
-
*/
|
|
760
|
-
function provideIndexedDBStoreName(name) {
|
|
761
|
-
return makeEnvironmentProviders([{ provide: IDB_STORE_NAME, useValue: name }]);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
/**
|
|
765
|
-
* This module is only here for backward compatibility, do not add it by yourself
|
|
766
|
-
*/
|
|
767
|
-
class StorageModule {
|
|
768
|
-
/**
|
|
769
|
-
* Only useful to provide options, otherwise it does nothing.
|
|
770
|
-
* **Must be used at initialization, ie. in `AppModule`, and must not be loaded again in another module.**
|
|
771
|
-
*
|
|
772
|
-
*/
|
|
773
|
-
static forRoot(config) {
|
|
774
|
-
return {
|
|
775
|
-
ngModule: StorageModule,
|
|
776
|
-
providers: [
|
|
777
|
-
config.LSPrefix ? { provide: LS_PREFIX, useValue: config.LSPrefix } : [],
|
|
778
|
-
config.IDBDBName ? { provide: IDB_DB_NAME, useValue: config.IDBDBName } : [],
|
|
779
|
-
config.IDBStoreName ? { provide: IDB_STORE_NAME, useValue: config.IDBStoreName } : [],
|
|
780
|
-
config.IDBDBVersion ? { provide: IDB_DB_VERSION, useValue: config.IDBDBVersion } : [],
|
|
781
|
-
(config.IDBNoWrap === false) ? { provide: IDB_NO_WRAP, useValue: config.IDBNoWrap } : [],
|
|
782
|
-
],
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
786
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.0.0", ngImport: i0, type: StorageModule }); }
|
|
787
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule }); }
|
|
788
|
-
}
|
|
789
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageModule, decorators: [{
|
|
790
|
-
type: NgModule
|
|
791
|
-
}] });
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Exception message when a value is not valid against the JSON schema
|
|
795
|
-
*/
|
|
796
|
-
const VALIDATION_ERROR = `Data stored is not valid against the provided JSON schema.
|
|
797
|
-
Check your JSON schema, otherwise it means data has been corrupted.`;
|
|
798
|
-
/**
|
|
799
|
-
* Exception raised when a value is not valid against the JSON schema
|
|
800
|
-
*/
|
|
801
|
-
class ValidationError extends Error {
|
|
802
|
-
constructor() {
|
|
803
|
-
super(...arguments);
|
|
804
|
-
this.message = VALIDATION_ERROR;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/** @deprecated Will be removed in v17 */
|
|
809
723
|
class JSONValidator {
|
|
810
724
|
/**
|
|
811
725
|
* Validate a JSON data against a Jsubset of the JSON Schema standard.
|
|
@@ -1040,16 +954,78 @@ class JSONValidator {
|
|
|
1040
954
|
/* Cast as the data can be of multiple types, and so TypeScript is lost */
|
|
1041
955
|
return (schema.enum.includes(data));
|
|
1042
956
|
}
|
|
1043
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1044
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
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" }); }
|
|
1045
959
|
}
|
|
1046
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
960
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: JSONValidator, decorators: [{
|
|
1047
961
|
type: Injectable,
|
|
1048
962
|
args: [{
|
|
1049
963
|
providedIn: "root"
|
|
1050
964
|
}]
|
|
1051
965
|
}] });
|
|
1052
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
|
+
|
|
1053
1029
|
class StorageMap {
|
|
1054
1030
|
/**
|
|
1055
1031
|
* Constructor params are provided by Angular (but can also be passed manually in tests)
|
|
@@ -1262,8 +1238,12 @@ class StorageMap {
|
|
|
1262
1238
|
const notifier = this.notifiers.get(key);
|
|
1263
1239
|
/* Get the current item value */
|
|
1264
1240
|
(schema ? this.get(key, schema) : this.get(key)).subscribe({
|
|
1265
|
-
next: (result) =>
|
|
1266
|
-
|
|
1241
|
+
next: (result) => {
|
|
1242
|
+
notifier.next(result);
|
|
1243
|
+
},
|
|
1244
|
+
error: (error) => {
|
|
1245
|
+
notifier.error(error);
|
|
1246
|
+
},
|
|
1267
1247
|
});
|
|
1268
1248
|
/* Only the public API of the `Observable` should be returned */
|
|
1269
1249
|
return (schema ?
|
|
@@ -1320,95 +1300,15 @@ class StorageMap {
|
|
|
1320
1300
|
}
|
|
1321
1301
|
});
|
|
1322
1302
|
}
|
|
1323
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1324
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1325
|
-
}
|
|
1326
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: StorageMap, decorators: [{
|
|
1327
|
-
type: Injectable,
|
|
1328
|
-
args: [{
|
|
1329
|
-
providedIn: "root"
|
|
1330
|
-
}]
|
|
1331
|
-
}], ctorParameters: function () { return [{ type: LocalDatabase }, { type: JSONValidator }]; } });
|
|
1332
|
-
|
|
1333
|
-
/**
|
|
1334
|
-
* @deprecated Will be removed in v17, use `StorageMap`
|
|
1335
|
-
* @see {@link https://github.com/cyrilletuzi/angular-async-local-storage/blob/main/docs/MIGRATION_TO_V16.md}
|
|
1336
|
-
*/
|
|
1337
|
-
class LocalStorage {
|
|
1338
|
-
/**
|
|
1339
|
-
* Number of items in storage wrapped in an `Observable`
|
|
1340
|
-
*
|
|
1341
|
-
* @example
|
|
1342
|
-
* this.localStorage.length.subscribe((length) => {
|
|
1343
|
-
* console.log(length);
|
|
1344
|
-
* });
|
|
1345
|
-
*/
|
|
1346
|
-
get length() {
|
|
1347
|
-
return this.storageMap.size;
|
|
1348
|
-
}
|
|
1349
|
-
/* Use the `StorageMap` service to avoid code duplication */
|
|
1350
|
-
constructor(storageMap) {
|
|
1351
|
-
this.storageMap = storageMap;
|
|
1352
|
-
}
|
|
1353
|
-
getItem(key, schema) {
|
|
1354
|
-
if (schema) {
|
|
1355
|
-
/* Backward compatibility with version <= 7 */
|
|
1356
|
-
schema = ("schema" in schema) ? schema.schema : schema;
|
|
1357
|
-
}
|
|
1358
|
-
return (schema ? this.storageMap.get(key, schema) : this.storageMap.get(key)).pipe(
|
|
1359
|
-
/* Transform `undefined` into `null` to align with `localStorage` API */
|
|
1360
|
-
map((value) => (value !== undefined) ? value : null));
|
|
1361
|
-
}
|
|
1362
|
-
/**
|
|
1363
|
-
* Set an item in storage.
|
|
1364
|
-
* Note that setting `null` or `undefined` will remove the item to avoid some browsers issues.
|
|
1365
|
-
* @param key The item's key
|
|
1366
|
-
* @param data The item's value
|
|
1367
|
-
* @param schema Optional JSON schema to validate the data
|
|
1368
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
1369
|
-
*
|
|
1370
|
-
* @example
|
|
1371
|
-
* this.localStorage.set('key', 'value').subscribe(() => {});
|
|
1372
|
-
*/
|
|
1373
|
-
setItem(key, data, schema) {
|
|
1374
|
-
return this.storageMap.set(key, data, schema).pipe(
|
|
1375
|
-
/* Transform `undefined` into `true` for backward compatibility with v7 */
|
|
1376
|
-
map(() => true));
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Delete an item in storage
|
|
1380
|
-
* @param key The item's key
|
|
1381
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
1382
|
-
*
|
|
1383
|
-
* @example
|
|
1384
|
-
* this.localStorage.delete('key').subscribe(() => {});
|
|
1385
|
-
*/
|
|
1386
|
-
removeItem(key) {
|
|
1387
|
-
return this.storageMap.delete(key).pipe(
|
|
1388
|
-
/* Transform `undefined` into `true` for backward compatibility with v7 */
|
|
1389
|
-
map(() => true));
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Delete all items in storage
|
|
1393
|
-
* @returns A RxJS `Observable` to wait the end of the operation
|
|
1394
|
-
*
|
|
1395
|
-
* @example
|
|
1396
|
-
* this.localStorage.clear().subscribe(() => {});
|
|
1397
|
-
*/
|
|
1398
|
-
clear() {
|
|
1399
|
-
return this.storageMap.clear().pipe(
|
|
1400
|
-
/* Transform `undefined` into `true` for backward compatibility with v7 */
|
|
1401
|
-
map(() => true));
|
|
1402
|
-
}
|
|
1403
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: LocalStorage, deps: [{ token: StorageMap }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
1404
|
-
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" }); }
|
|
1405
1305
|
}
|
|
1406
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1306
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0", ngImport: i0, type: StorageMap, decorators: [{
|
|
1407
1307
|
type: Injectable,
|
|
1408
1308
|
args: [{
|
|
1409
1309
|
providedIn: "root"
|
|
1410
1310
|
}]
|
|
1411
|
-
}], ctorParameters:
|
|
1311
|
+
}], ctorParameters: () => [{ type: LocalDatabase }, { type: JSONValidator }] });
|
|
1412
1312
|
|
|
1413
1313
|
/*
|
|
1414
1314
|
* Public API Surface of local-storage
|
|
@@ -1418,5 +1318,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImpor
|
|
|
1418
1318
|
* Generated bundle index. Do not edit.
|
|
1419
1319
|
*/
|
|
1420
1320
|
|
|
1421
|
-
export {
|
|
1321
|
+
export { SERIALIZATION_ERROR, SerializationError, StorageMap, StorageModule, VALIDATION_ERROR, ValidationError, provideIndexedDBDataBaseName, provideIndexedDBDataBaseVersion, provideIndexedDBStoreName, provideLocalStoragePrefix };
|
|
1422
1322
|
//# sourceMappingURL=ngx-pwa-local-storage.mjs.map
|