@esfaenza/preferences 12.2.9 → 13.1.1

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.
Files changed (30) hide show
  1. package/esfaenza-preferences.d.ts +1 -2
  2. package/esm2020/esfaenza-preferences.mjs +5 -0
  3. package/{esm2015/lib/models/PreferencesModuleConfig.js → esm2020/lib/models/PreferencesModuleConfig.mjs} +0 -0
  4. package/{esm2015/lib/persistor/base/BasePreferencesPersistor.js → esm2020/lib/persistor/base/BasePreferencesPersistor.mjs} +1 -1
  5. package/esm2020/lib/persistor/implementation/LocalStoragePersistor.mjs +47 -0
  6. package/esm2020/lib/preferences.module.mjs +28 -0
  7. package/esm2020/lib/preferences.service.mjs +93 -0
  8. package/{esm2015/lib/session/base/BaseSessionRetriever.js → esm2020/lib/session/base/BaseSessionRetriever.mjs} +0 -0
  9. package/esm2020/lib/session/implementation/DefaultSessionRetriever.mjs +28 -0
  10. package/{esm2015/lib/tokens.js → esm2020/lib/tokens.mjs} +0 -0
  11. package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
  12. package/fesm2015/{esfaenza-preferences.js → esfaenza-preferences.mjs} +48 -32
  13. package/fesm2015/esfaenza-preferences.mjs.map +1 -0
  14. package/fesm2020/esfaenza-preferences.mjs +232 -0
  15. package/fesm2020/esfaenza-preferences.mjs.map +1 -0
  16. package/lib/persistor/base/BasePreferencesPersistor.d.ts +2 -2
  17. package/lib/persistor/implementation/LocalStoragePersistor.d.ts +4 -1
  18. package/lib/preferences.module.d.ts +4 -0
  19. package/lib/preferences.service.d.ts +5 -0
  20. package/lib/session/implementation/DefaultSessionRetriever.d.ts +3 -0
  21. package/package.json +21 -9
  22. package/bundles/esfaenza-preferences.umd.js +0 -563
  23. package/bundles/esfaenza-preferences.umd.js.map +0 -1
  24. package/esfaenza-preferences.metadata.json +0 -1
  25. package/esm2015/esfaenza-preferences.js +0 -7
  26. package/esm2015/lib/persistor/implementation/LocalStoragePersistor.js +0 -47
  27. package/esm2015/lib/preferences.module.js +0 -24
  28. package/esm2015/lib/preferences.service.js +0 -83
  29. package/esm2015/lib/session/implementation/DefaultSessionRetriever.js +0 -26
  30. package/fesm2015/esfaenza-preferences.js.map +0 -1
@@ -0,0 +1,232 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, Injectable, Optional, Inject, NgModule } from '@angular/core';
3
+ import { forkJoin, of } from 'rxjs';
4
+ import { map, concatMap, tap, first } from 'rxjs/operators';
5
+
6
+ /**
7
+ * Indica se recuperare autonomamente tutte le configurazioni salvate al bootstrap della libreria o se aspettare le richieste specifiche.
8
+ *
9
+ * Utile se non vengono salvate tante cose, potrebbe creare un momento di irresponsività se le info da recuperare sono molte
10
+ */
11
+ const PREF_FULL_RETRIEVE_AT_START = new InjectionToken('PREF_FULL_RETRIEVE_AT_START');
12
+
13
+ /**
14
+ * Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage
15
+ */
16
+ class BasePreferencesPersistor {
17
+ /** @ignore Costruttore */
18
+ constructor(session) {
19
+ this.session = session;
20
+ }
21
+ /**
22
+ * Effettua il **persist** massivo di una lista di Chiave - Valore
23
+ *
24
+ * @param {{ [key: string]: string }} dictionary Dizionario (lista di Chiave - Valore) da persistere
25
+ */
26
+ persistAll(dictionary) {
27
+ let observables = [];
28
+ for (let key in dictionary)
29
+ observables.push(this.persist(key, dictionary[key]));
30
+ return forkJoin(observables).pipe(map(res => res.reduce((acc, val) => acc && val, true)));
31
+ }
32
+ /**
33
+ * Ottiene la chiave "Reale" da utilizzare per la persistenza di una chiave generica
34
+ *
35
+ * @param {string} key Chiave da storicizzare
36
+ *
37
+ * @returns {string} Unione fra l'identificativo della sessione e la chiave specificata
38
+ */
39
+ getKey(key) {
40
+ return this.session.getSessionKey() + "§" + key + "§";
41
+ }
42
+ }
43
+
44
+ // Angular
45
+ /**
46
+ * Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate
47
+ */
48
+ class PreferencesService {
49
+ /**
50
+ * Costruttore
51
+ *
52
+ * @ignore
53
+ */
54
+ constructor(persistor, PREF_FULL_RETRIEVE_AT_START) {
55
+ this.persistor = persistor;
56
+ this.PREF_FULL_RETRIEVE_AT_START = PREF_FULL_RETRIEVE_AT_START;
57
+ /**
58
+ * Indica se è la prima volta che viene effettuata un'operazione di retrieve. Appena effettuata questa variabile viene impostata a **false** e (in quanto singleton,
59
+ * se configurato bene) mai più modificata
60
+ */
61
+ this.FirstRetrieve = true;
62
+ /**
63
+ * Store in memoria delle preferenze locali che sarà persistito per mezzo della classe che fa le veci del **BasePreferencesPersistor**
64
+ */
65
+ this.LocalPreferences = {};
66
+ }
67
+ /**
68
+ * Ripulisce le impostazioni locali e le impostazioni salvate dal persistor
69
+ */
70
+ clear() {
71
+ this.LocalPreferences = {};
72
+ return this.persistor.clear();
73
+ }
74
+ /**
75
+ * Salva un oggetto sia nella cache locale che nel persistor
76
+ *
77
+ * @param {string} key Chiave di persistenza
78
+ * @param {T} item Oggetto da salvare
79
+ */
80
+ store(key, item) {
81
+ this.LocalPreferences[key] = item;
82
+ return this.persistor.persist(key, item);
83
+ }
84
+ /**
85
+ * Recupera un oggetto in base a una chiave. Permette di accedere alla copia locale o alla copia persistita ed in caso fosse il primo caricamento e l'impostazione
86
+ * **retrieveAllAtStart** della classe di configurazione fosse **true** si occupa anche della prima valorizzazione della cache locale
87
+ *
88
+ * @param {string} key Chiave del valore da recuperare
89
+ * @param {boolean} cacheBust Indica se ignorare il valore della cache locale e recuperare l'oggetto dallo store persistito,
90
+ * in caso fosse stato modificato fuori sistema o da un altro sistema
91
+ *
92
+ * @returns {T} Oggetto richiesto
93
+ */
94
+ retrieve(key, cacheBust = false) {
95
+ // Se è il primo retrieve e sono configurato per recuperare tutta la configurazione all'inizio
96
+ // eseguo, altrimenti prendo l'oggetto se lo trovo e se non lo trovo lo carico prima in cache
97
+ if (this.FirstRetrieve) {
98
+ if (this.PREF_FULL_RETRIEVE_AT_START)
99
+ return this.persistor.recoverAll().pipe(concatMap(res => {
100
+ this.LocalPreferences = res;
101
+ this.FirstRetrieve = false;
102
+ return this.internalRetrieve(key, cacheBust);
103
+ }));
104
+ }
105
+ return this.internalRetrieve(key, cacheBust);
106
+ }
107
+ /** @ignore Vedi **retrieve** */
108
+ internalRetrieve(key, cacheBust = false) {
109
+ if (this.LocalPreferences[key] && !cacheBust)
110
+ return of(this.LocalPreferences[key]);
111
+ else {
112
+ var obj = this.persistor.recover(key);
113
+ if (!obj)
114
+ return of(null);
115
+ obj.pipe(tap(item => { this.LocalPreferences[key] = item; }));
116
+ return obj;
117
+ }
118
+ }
119
+ }
120
+ PreferencesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesService, deps: [{ token: BasePreferencesPersistor }, { token: PREF_FULL_RETRIEVE_AT_START, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
121
+ PreferencesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesService });
122
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesService, decorators: [{
123
+ type: Injectable
124
+ }], ctorParameters: function () { return [{ type: BasePreferencesPersistor }, { type: undefined, decorators: [{
125
+ type: Optional
126
+ }, {
127
+ type: Inject,
128
+ args: [PREF_FULL_RETRIEVE_AT_START]
129
+ }] }]; } });
130
+
131
+ /**
132
+ * Classe di Configurazione per la libreria
133
+ */
134
+ class PreferencesModuleConfig {
135
+ }
136
+
137
+ /**
138
+ * Classe astratta che si occupa di recuperare l'Id sessione univoco per applicazione ed utente collegato
139
+ */
140
+ class BaseSessionRetriever {
141
+ }
142
+
143
+ // Angular
144
+ /** Implementazione di default per la classe **BasePreferencesPersistor** */
145
+ class LocalStoragePersistor extends BasePreferencesPersistor {
146
+ /** @ignore Costruttore */
147
+ constructor(session) { super(session); }
148
+ /** @ignore Vedi classe base */
149
+ persist(key, item) {
150
+ localStorage.setItem(this.getKey(key), JSON.stringify(item));
151
+ return of(true).pipe(first());
152
+ }
153
+ /** @ignore Vedi classe base */
154
+ recover(key) {
155
+ var ret = JSON.parse(localStorage.getItem(this.getKey(key)));
156
+ return of(ret).pipe(first());
157
+ }
158
+ /** @ignore Vedi classe base */
159
+ recoverAll() {
160
+ var ret = {};
161
+ for (var k in localStorage) {
162
+ if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
163
+ ret[k.match(/§(.*)§/)[1]] = JSON.parse(localStorage.getItem(k));
164
+ }
165
+ return of(ret).pipe(first());
166
+ }
167
+ /** @ignore Vedi classe base */
168
+ clear() {
169
+ for (var k in localStorage) {
170
+ if (k.includes("§") && k.startsWith(this.session.getSessionKey()))
171
+ localStorage.removeItem(k);
172
+ }
173
+ return of(true).pipe(first());
174
+ }
175
+ }
176
+ LocalStoragePersistor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LocalStoragePersistor, deps: [{ token: BaseSessionRetriever }], target: i0.ɵɵFactoryTarget.Injectable });
177
+ LocalStoragePersistor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LocalStoragePersistor });
178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: LocalStoragePersistor, decorators: [{
179
+ type: Injectable
180
+ }], ctorParameters: function () { return [{ type: BaseSessionRetriever }]; } });
181
+
182
+ /**
183
+ * Implementazione di default per la classe **BaseSessionRetriever**
184
+ */
185
+ class DefaultSessionRetriever extends BaseSessionRetriever {
186
+ /**
187
+ * Costruttore
188
+ *
189
+ * @ignore
190
+ */
191
+ constructor() { super(); }
192
+ /**
193
+ * Ottiene un ID sessione
194
+ *
195
+ * @returns {string} ID sessione
196
+ */
197
+ getSessionKey() {
198
+ return "DUMMY_SESSION";
199
+ }
200
+ }
201
+ DefaultSessionRetriever.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: DefaultSessionRetriever, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
202
+ DefaultSessionRetriever.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: DefaultSessionRetriever });
203
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: DefaultSessionRetriever, decorators: [{
204
+ type: Injectable
205
+ }], ctorParameters: function () { return []; } });
206
+
207
+ class PreferencesModule {
208
+ static forRoot(config) {
209
+ return {
210
+ ngModule: PreferencesModule,
211
+ providers: [
212
+ PreferencesService,
213
+ { provide: BasePreferencesPersistor, useClass: config?.preferencePersistor || LocalStoragePersistor },
214
+ { provide: BaseSessionRetriever, useClass: config?.sessionRetriever || DefaultSessionRetriever },
215
+ { provide: PREF_FULL_RETRIEVE_AT_START, useValue: config?.retrieveAllAtStart || true }
216
+ ]
217
+ };
218
+ }
219
+ }
220
+ PreferencesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
221
+ PreferencesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesModule });
222
+ PreferencesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesModule });
223
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: PreferencesModule, decorators: [{
224
+ type: NgModule
225
+ }] });
226
+
227
+ /**
228
+ * Generated bundle index. Do not edit.
229
+ */
230
+
231
+ export { BasePreferencesPersistor, BaseSessionRetriever, PREF_FULL_RETRIEVE_AT_START, PreferencesModule, PreferencesModuleConfig, PreferencesService };
232
+ //# sourceMappingURL=esfaenza-preferences.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esfaenza-preferences.mjs","sources":["../../../projects/preferences/src/lib/tokens.ts","../../../projects/preferences/src/lib/persistor/base/BasePreferencesPersistor.ts","../../../projects/preferences/src/lib/preferences.service.ts","../../../projects/preferences/src/lib/models/PreferencesModuleConfig.ts","../../../projects/preferences/src/lib/session/base/BaseSessionRetriever.ts","../../../projects/preferences/src/lib/persistor/implementation/LocalStoragePersistor.ts","../../../projects/preferences/src/lib/session/implementation/DefaultSessionRetriever.ts","../../../projects/preferences/src/lib/preferences.module.ts","../../../projects/preferences/src/esfaenza-preferences.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\r\n\r\n/**\r\n * Indica se recuperare autonomamente tutte le configurazioni salvate al bootstrap della libreria o se aspettare le richieste specifiche.\r\n * \r\n * Utile se non vengono salvate tante cose, potrebbe creare un momento di irresponsività se le info da recuperare sono molte\r\n */\r\nexport const PREF_FULL_RETRIEVE_AT_START: InjectionToken<boolean> = new InjectionToken<boolean>('PREF_FULL_RETRIEVE_AT_START');","import { Observable, forkJoin } from \"rxjs\";\r\nimport { map } from \"rxjs/operators\";\r\nimport { BaseSessionRetriever } from \"../../session/base/BaseSessionRetriever\";\r\n\r\n/**\r\n * Classe astratta che rappresenta lo stato di persistenza fra la libreria e uno storage\r\n */\r\nexport abstract class BasePreferencesPersistor {\r\n\r\n /** @ignore Costruttore */\r\n constructor(protected session: BaseSessionRetriever) {}\r\n\r\n /**\r\n * Salva, per una sessione, una chiave con un valore\r\n * \r\n * @param {string} key Chiave da storicizzare\r\n */\r\n public abstract persist<T>(key: string, item: T): Observable<boolean>;\r\n\r\n /**\r\n * Recupera, per una sessione, il valore assegnato ad una chiave\r\n * \r\n * @param {string} key Chiave da recuperare\r\n * \r\n * @returns {Observable<T>} Valore salvato per la chiave **key**\r\n */\r\n public abstract recover<T>(key?: string): Observable<T>;\r\n\r\n /**\r\n * Per una sessione recupera tutte le coppie Chiave - Valore salvate\r\n * \r\n * @returns {Observable<{ [index: string]: any }>} Dizionario con tutte le preference salvate per la sessione\r\n */\r\n public abstract recoverAll(): Observable<{ [index: string]: any }>;\r\n\r\n /** Ripulisce le preference salvate relative ad una sessione */\r\n public abstract clear(): Observable<boolean>;\r\n\r\n /**\r\n * Effettua il **persist** massivo di una lista di Chiave - Valore\r\n * \r\n * @param {{ [key: string]: string }} dictionary Dizionario (lista di Chiave - Valore) da persistere\r\n */\r\n public persistAll(dictionary: { [key: string]: string }): Observable<boolean> {\r\n let observables: Observable<boolean>[] = [];\r\n for (let key in dictionary)\r\n observables.push(this.persist(key, dictionary[key]));\r\n\r\n return forkJoin(observables).pipe(map(res => res.reduce((acc, val) => acc && val, true)));\r\n }\r\n\r\n /**\r\n * Ottiene la chiave \"Reale\" da utilizzare per la persistenza di una chiave generica\r\n * \r\n * @param {string} key Chiave da storicizzare\r\n * \r\n * @returns {string} Unione fra l'identificativo della sessione e la chiave specificata\r\n */\r\n protected getKey(key: string): string {\r\n return this.session.getSessionKey() + \"§\" + key + \"§\";\r\n }\r\n}","// Angular\r\nimport { Inject, Injectable, Optional } from '@angular/core';\r\nimport { Observable, of } from 'rxjs';\r\nimport { concatMap, tap } from 'rxjs/operators';\r\n\r\n// Modelli\r\nimport { BasePreferencesPersistor } from './persistor/base/BasePreferencesPersistor';\r\nimport { PREF_FULL_RETRIEVE_AT_START } from './tokens';\r\n\r\n/**\r\n * Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate\r\n */\r\n@Injectable()\r\nexport class PreferencesService {\r\n\r\n /**\r\n * Indica se è la prima volta che viene effettuata un'operazione di retrieve. Appena effettuata questa variabile viene impostata a **false** e (in quanto singleton,\r\n * se configurato bene) mai più modificata\r\n */\r\n private FirstRetrieve: boolean = true;\r\n\r\n /**\r\n * Store in memoria delle preferenze locali che sarà persistito per mezzo della classe che fa le veci del **BasePreferencesPersistor**\r\n */\r\n private LocalPreferences: { [index: string]: any } = {};\r\n\r\n /**\r\n * Costruttore\r\n * \r\n * @ignore\r\n */\r\n constructor(private persistor: BasePreferencesPersistor, @Optional() @Inject(PREF_FULL_RETRIEVE_AT_START) private PREF_FULL_RETRIEVE_AT_START: boolean) { }\r\n\r\n /**\r\n * Ripulisce le impostazioni locali e le impostazioni salvate dal persistor\r\n */\r\n clear(): Observable<boolean> {\r\n this.LocalPreferences = {};\r\n return this.persistor.clear();\r\n }\r\n\r\n /**\r\n * Salva un oggetto sia nella cache locale che nel persistor\r\n * \r\n * @param {string} key Chiave di persistenza\r\n * @param {T} item Oggetto da salvare\r\n */\r\n store<T>(key: string, item: T): Observable<boolean> {\r\n this.LocalPreferences[key] = item;\r\n return this.persistor.persist(key, item);\r\n }\r\n\r\n /**\r\n * Recupera un oggetto in base a una chiave. Permette di accedere alla copia locale o alla copia persistita ed in caso fosse il primo caricamento e l'impostazione \r\n * **retrieveAllAtStart** della classe di configurazione fosse **true** si occupa anche della prima valorizzazione della cache locale\r\n * \r\n * @param {string} key Chiave del valore da recuperare\r\n * @param {boolean} cacheBust Indica se ignorare il valore della cache locale e recuperare l'oggetto dallo store persistito, \r\n * in caso fosse stato modificato fuori sistema o da un altro sistema\r\n * \r\n * @returns {T} Oggetto richiesto\r\n */\r\n retrieve<T>(key: string, cacheBust: boolean = false): Observable<T> {\r\n // Se è il primo retrieve e sono configurato per recuperare tutta la configurazione all'inizio\r\n // eseguo, altrimenti prendo l'oggetto se lo trovo e se non lo trovo lo carico prima in cache\r\n if (this.FirstRetrieve) {\r\n if (this.PREF_FULL_RETRIEVE_AT_START)\r\n return this.persistor.recoverAll().pipe(concatMap(res => {\r\n this.LocalPreferences = res;\r\n this.FirstRetrieve = false;\r\n return this.internalRetrieve<T>(key, cacheBust);\r\n }));\r\n }\r\n\r\n return this.internalRetrieve<T>(key, cacheBust);\r\n }\r\n\r\n /** @ignore Vedi **retrieve** */\r\n private internalRetrieve<T>(key: string, cacheBust: boolean = false): Observable<T> {\r\n if (this.LocalPreferences[key] && !cacheBust)\r\n return of(<T>this.LocalPreferences[key]);\r\n else {\r\n var obj = this.persistor.recover<T>(key);\r\n if (!obj)\r\n return of(null);\r\n obj.pipe(tap(item => { this.LocalPreferences[key] = item; }))\r\n return obj;\r\n }\r\n }\r\n}","import { Type } from \"@angular/core\";\r\nimport { BasePreferencesPersistor } from \"../persistor/base/BasePreferencesPersistor\";\r\nimport { BaseSessionRetriever } from \"../session/base/BaseSessionRetriever\";\r\n\r\n/**\r\n * Classe di Configurazione per la libreria\r\n */\r\nexport class PreferencesModuleConfig{\r\n\r\n /**\r\n * Indica se recuperare autonomamente tutte le configurazioni salvate al bootstrap della libreria o se aspettare le richieste specifiche.\r\n * \r\n * Utile se non vengono salvate tante cose, potrebbe creare un momento di irresponsività se le info da recuperare sono molte\r\n */\r\n retrieveAllAtStart?: boolean;\r\n\r\n /**\r\n * Classe che si deve occupare dello store \"Definitivo\" delle preferenze. Di default viene proposto uno store lato localStorage ma si può facilmente \r\n * fornire uno storage che porta le informazioni lato Database\r\n */\r\n preferencePersistor?: Type<BasePreferencesPersistor>;\r\n\r\n /**\r\n * Classe che si deve occupare per generare un ID univoco di sessione in base al quale verranno salvate le preferenze\r\n */\r\n sessionRetriever?: Type<BaseSessionRetriever>;\r\n}","/**\r\n * Classe astratta che si occupa di recuperare l'Id sessione univoco per applicazione ed utente collegato\r\n */\r\nexport abstract class BaseSessionRetriever {\r\n\r\n /**\r\n * Ottiene un ID sessione\r\n * \r\n * @returns {string} ID sessione\r\n */\r\n public abstract getSessionKey(): string;\r\n}","// Angular\r\nimport { Injectable } from \"@angular/core\";\r\n\r\n// Classi\r\nimport { BasePreferencesPersistor } from \"../base/BasePreferencesPersistor\";\r\nimport { BaseSessionRetriever } from \"../../session/base/BaseSessionRetriever\";\r\n\r\n// RXJS\r\nimport { Observable, of } from \"rxjs\";\r\nimport { first } from \"rxjs/operators\";\r\n\r\n/** Implementazione di default per la classe **BasePreferencesPersistor** */\r\n@Injectable()\r\nexport class LocalStoragePersistor extends BasePreferencesPersistor {\r\n\r\n /** @ignore Costruttore */\r\n constructor(session: BaseSessionRetriever) { super(session); }\r\n\r\n /** @ignore Vedi classe base */\r\n public persist<T>(key: string, item: T): Observable<boolean> {\r\n localStorage.setItem(this.getKey(key), JSON.stringify(item));\r\n return of(true).pipe(first());\r\n }\r\n\r\n /** @ignore Vedi classe base */\r\n public recover<T>(key: string): Observable<T> {\r\n var ret = <T>JSON.parse(localStorage.getItem(this.getKey(key)));\r\n return of(ret).pipe(first());\r\n }\r\n\r\n /** @ignore Vedi classe base */\r\n public recoverAll(): Observable<{ [index: string]: any; }> {\r\n var ret: { [index: string]: string; } = {};\r\n for (var k in localStorage) {\r\n if (k.includes(\"§\") && k.startsWith(this.session.getSessionKey()))\r\n ret[k.match(/§(.*)§/)[1]] = JSON.parse(localStorage.getItem(k));\r\n }\r\n\r\n return of(ret).pipe(first());\r\n }\r\n\r\n /** @ignore Vedi classe base */\r\n public clear(): Observable<boolean> {\r\n for (var k in localStorage) {\r\n if (k.includes(\"§\") && k.startsWith(this.session.getSessionKey()))\r\n localStorage.removeItem(k);\r\n }\r\n return of(true).pipe(first());\r\n }\r\n}","import { Injectable } from \"@angular/core\";\r\nimport { BaseSessionRetriever } from \"../base/BaseSessionRetriever\";\r\n\r\n/**\r\n * Implementazione di default per la classe **BaseSessionRetriever**\r\n */\r\n@Injectable()\r\nexport class DefaultSessionRetriever extends BaseSessionRetriever {\r\n\r\n /**\r\n * Costruttore\r\n * \r\n * @ignore\r\n */\r\n constructor() { super(); }\r\n\r\n /**\r\n * Ottiene un ID sessione\r\n * \r\n * @returns {string} ID sessione\r\n */\r\n getSessionKey(): string {\r\n return \"DUMMY_SESSION\";\r\n }\r\n}","// Angular\nimport { ModuleWithProviders } from '@angular/core';\nimport { NgModule } from '@angular/core';\n\n// Modelli\nimport { PreferencesModuleConfig } from './models/PreferencesModuleConfig';\nimport { BasePreferencesPersistor } from './persistor/base/BasePreferencesPersistor';\nimport { LocalStoragePersistor } from './persistor/implementation/LocalStoragePersistor';\nimport { BaseSessionRetriever } from './session/base/BaseSessionRetriever';\nimport { DefaultSessionRetriever } from './session/implementation/DefaultSessionRetriever';\nimport { PreferencesService } from './preferences.service';\nimport { PREF_FULL_RETRIEVE_AT_START } from './tokens';\n\n@NgModule()\nexport class PreferencesModule {\n static forRoot(config?: PreferencesModuleConfig): ModuleWithProviders<PreferencesModule> {\n return {\n ngModule: PreferencesModule,\n providers: [\n PreferencesService,\n { provide: BasePreferencesPersistor, useClass: config?.preferencePersistor || LocalStoragePersistor },\n { provide: BaseSessionRetriever, useClass: config?.sessionRetriever || DefaultSessionRetriever },\n { provide: PREF_FULL_RETRIEVE_AT_START, useValue: config?.retrieveAllAtStart || true }\n ]\n };\n }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAEA;;;;;MAKa,2BAA2B,GAA4B,IAAI,cAAc,CAAU,6BAA6B;;ACH7H;;;MAGsB,wBAAwB;;IAG1C,YAAsB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;KAAI;;;;;;IAiChD,UAAU,CAAC,UAAqC;QACnD,IAAI,WAAW,GAA0B,EAAE,CAAC;QAC5C,KAAK,IAAI,GAAG,IAAI,UAAU;YACtB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEzD,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;KAC7F;;;;;;;;IASS,MAAM,CAAC,GAAW;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACzD;;;AC5DL;AASA;;;MAIa,kBAAkB;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EAAE,kBAAkB,IAAI,IAAI,EAAE;aACvF;SACF,CAAC;KACH;;8GAXU,iBAAiB;+GAAjB,iBAAiB;+GAAjB,iBAAiB;2FAAjB,iBAAiB;kBAD7B,QAAQ;;;ACbT;;;;;;"}
@@ -24,10 +24,10 @@ export declare abstract class BasePreferencesPersistor {
24
24
  /**
25
25
  * Per una sessione recupera tutte le coppie Chiave - Valore salvate
26
26
  *
27
- * @returns {Observable<{ [index: string]: string }>} Dizionario con tutte le preference salvate per la sessione
27
+ * @returns {Observable<{ [index: string]: any }>} Dizionario con tutte le preference salvate per la sessione
28
28
  */
29
29
  abstract recoverAll(): Observable<{
30
- [index: string]: string;
30
+ [index: string]: any;
31
31
  }>;
32
32
  /** Ripulisce le preference salvate relative ad una sessione */
33
33
  abstract clear(): Observable<boolean>;
@@ -1,6 +1,7 @@
1
1
  import { BasePreferencesPersistor } from "../base/BasePreferencesPersistor";
2
2
  import { BaseSessionRetriever } from "../../session/base/BaseSessionRetriever";
3
3
  import { Observable } from "rxjs";
4
+ import * as i0 from "@angular/core";
4
5
  /** Implementazione di default per la classe **BasePreferencesPersistor** */
5
6
  export declare class LocalStoragePersistor extends BasePreferencesPersistor {
6
7
  /** @ignore Costruttore */
@@ -11,8 +12,10 @@ export declare class LocalStoragePersistor extends BasePreferencesPersistor {
11
12
  recover<T>(key: string): Observable<T>;
12
13
  /** @ignore Vedi classe base */
13
14
  recoverAll(): Observable<{
14
- [index: string]: string;
15
+ [index: string]: any;
15
16
  }>;
16
17
  /** @ignore Vedi classe base */
17
18
  clear(): Observable<boolean>;
19
+ static ɵfac: i0.ɵɵFactoryDeclaration<LocalStoragePersistor, never>;
20
+ static ɵprov: i0.ɵɵInjectableDeclaration<LocalStoragePersistor>;
18
21
  }
@@ -1,5 +1,9 @@
1
1
  import { ModuleWithProviders } from '@angular/core';
2
2
  import { PreferencesModuleConfig } from './models/PreferencesModuleConfig';
3
+ import * as i0 from "@angular/core";
3
4
  export declare class PreferencesModule {
4
5
  static forRoot(config?: PreferencesModuleConfig): ModuleWithProviders<PreferencesModule>;
6
+ static ɵfac: i0.ɵɵFactoryDeclaration<PreferencesModule, never>;
7
+ static ɵmod: i0.ɵɵNgModuleDeclaration<PreferencesModule, never, never, never>;
8
+ static ɵinj: i0.ɵɵInjectorDeclaration<PreferencesModule>;
5
9
  }
@@ -1,5 +1,6 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { BasePreferencesPersistor } from './persistor/base/BasePreferencesPersistor';
3
+ import * as i0 from "@angular/core";
3
4
  /**
4
5
  * Service che si occupa di salvare e recuperare le preferenze utente rispetto alle chiavi salvate
5
6
  */
@@ -43,4 +44,8 @@ export declare class PreferencesService {
43
44
  * @returns {T} Oggetto richiesto
44
45
  */
45
46
  retrieve<T>(key: string, cacheBust?: boolean): Observable<T>;
47
+ /** @ignore Vedi **retrieve** */
48
+ private internalRetrieve;
49
+ static ɵfac: i0.ɵɵFactoryDeclaration<PreferencesService, [null, { optional: true; }]>;
50
+ static ɵprov: i0.ɵɵInjectableDeclaration<PreferencesService>;
46
51
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseSessionRetriever } from "../base/BaseSessionRetriever";
2
+ import * as i0 from "@angular/core";
2
3
  /**
3
4
  * Implementazione di default per la classe **BaseSessionRetriever**
4
5
  */
@@ -15,4 +16,6 @@ export declare class DefaultSessionRetriever extends BaseSessionRetriever {
15
16
  * @returns {string} ID sessione
16
17
  */
17
18
  getSessionKey(): string;
19
+ static ɵfac: i0.ɵɵFactoryDeclaration<DefaultSessionRetriever, never>;
20
+ static ɵprov: i0.ɵɵInjectableDeclaration<DefaultSessionRetriever>;
18
21
  }
package/package.json CHANGED
@@ -1,19 +1,31 @@
1
1
  {
2
2
  "name": "@esfaenza/preferences",
3
- "version": "12.2.9",
3
+ "version": "13.1.1",
4
4
  "dependencies": {
5
5
  "tslib": "^2.0.0"
6
6
  },
7
7
  "peerDependencies": {
8
- "@angular/common": "~12.2.15",
9
- "@angular/core": "~12.2.15"
8
+ "@angular/common": "~13.1.1",
9
+ "@angular/core": "~13.1.1"
10
10
  },
11
- "main": "bundles/esfaenza-preferences.umd.js",
12
- "module": "fesm2015/esfaenza-preferences.js",
13
- "es2015": "fesm2015/esfaenza-preferences.js",
14
- "esm2015": "esm2015/esfaenza-preferences.js",
15
- "fesm2015": "fesm2015/esfaenza-preferences.js",
11
+ "module": "fesm2015/esfaenza-preferences.mjs",
12
+ "es2020": "fesm2020/esfaenza-preferences.mjs",
13
+ "esm2020": "esm2020/esfaenza-preferences.mjs",
14
+ "fesm2020": "fesm2020/esfaenza-preferences.mjs",
15
+ "fesm2015": "fesm2015/esfaenza-preferences.mjs",
16
16
  "typings": "esfaenza-preferences.d.ts",
17
- "metadata": "esfaenza-preferences.metadata.json",
17
+ "exports": {
18
+ "./package.json": {
19
+ "default": "./package.json"
20
+ },
21
+ ".": {
22
+ "types": "./esfaenza-preferences.d.ts",
23
+ "esm2020": "./esm2020/esfaenza-preferences.mjs",
24
+ "es2020": "./fesm2020/esfaenza-preferences.mjs",
25
+ "es2015": "./fesm2015/esfaenza-preferences.mjs",
26
+ "node": "./fesm2015/esfaenza-preferences.mjs",
27
+ "default": "./fesm2020/esfaenza-preferences.mjs"
28
+ }
29
+ },
18
30
  "sideEffects": false
19
31
  }