@ngxs/storage-plugin 3.7.4 → 3.7.5-dev.master-887cc32
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/README.md +3 -3
- package/bundles/ngxs-storage-plugin.umd.js +429 -381
- package/bundles/ngxs-storage-plugin.umd.js.map +1 -1
- package/bundles/ngxs-storage-plugin.umd.min.js +1 -1
- package/bundles/ngxs-storage-plugin.umd.min.js.map +1 -1
- package/esm2015/index.js +9 -9
- package/esm2015/ngxs-storage-plugin.js +10 -10
- package/esm2015/src/internals.js +76 -76
- package/esm2015/src/public_api.js +8 -8
- package/esm2015/src/storage.module.js +47 -47
- package/esm2015/src/storage.plugin.js +200 -152
- package/esm2015/src/symbols.js +93 -93
- package/esm5/index.js +9 -9
- package/esm5/ngxs-storage-plugin.js +10 -10
- package/esm5/src/internals.js +77 -77
- package/esm5/src/public_api.js +8 -8
- package/esm5/src/storage.module.js +55 -55
- package/esm5/src/storage.plugin.js +231 -183
- package/esm5/src/symbols.js +93 -93
- package/fesm2015/ngxs-storage-plugin.js +402 -354
- package/fesm2015/ngxs-storage-plugin.js.map +1 -1
- package/fesm5/ngxs-storage-plugin.js +438 -390
- package/fesm5/ngxs-storage-plugin.js.map +1 -1
- package/index.d.ts +4 -4
- package/ngxs-storage-plugin.d.ts +6 -6
- package/ngxs-storage-plugin.metadata.json +1 -1
- package/package.json +2 -2
- package/src/internals.d.ts +15 -15
- package/src/public_api.d.ts +3 -3
- package/src/storage.module.d.ts +6 -6
- package/src/storage.plugin.d.ts +11 -9
- package/src/symbols.d.ts +64 -64
|
@@ -4,408 +4,456 @@ import { __assign, __values } from 'tslib';
|
|
|
4
4
|
import { isPlatformServer } from '@angular/common';
|
|
5
5
|
import { tap } from 'rxjs/operators';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @fileoverview added by tsickle
|
|
9
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
10
|
-
*/
|
|
11
|
-
/** @enum {number} */
|
|
12
|
-
var StorageOption = {
|
|
13
|
-
LocalStorage: 0,
|
|
14
|
-
SessionStorage: 1,
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* @record
|
|
18
|
-
*/
|
|
19
|
-
function NgxsStoragePluginOptions() { }
|
|
20
|
-
if (false) {
|
|
21
|
-
/**
|
|
22
|
-
* Key for the state slice to store in the storage engine.
|
|
23
|
-
* @type {?|undefined}
|
|
24
|
-
*/
|
|
25
|
-
NgxsStoragePluginOptions.prototype.key;
|
|
26
|
-
/**
|
|
27
|
-
* Storage engine to use. Deaults to localStorage but can provide
|
|
28
|
-
*
|
|
29
|
-
* sessionStorage or custom implementation of the StorageEngine interface
|
|
30
|
-
* @type {?|undefined}
|
|
31
|
-
*/
|
|
32
|
-
NgxsStoragePluginOptions.prototype.storage;
|
|
33
|
-
/**
|
|
34
|
-
* Migration strategies.
|
|
35
|
-
* @type {?|undefined}
|
|
36
|
-
*/
|
|
37
|
-
NgxsStoragePluginOptions.prototype.migrations;
|
|
38
|
-
/**
|
|
39
|
-
* Serailizer for the object before its pushed into the engine.
|
|
40
|
-
* @param {?} obj
|
|
41
|
-
* @return {?}
|
|
42
|
-
*/
|
|
43
|
-
NgxsStoragePluginOptions.prototype.serialize = function (obj) { };
|
|
44
|
-
/**
|
|
45
|
-
* Deserializer for the object before its pulled out of the engine.
|
|
46
|
-
* @param {?} obj
|
|
47
|
-
* @return {?}
|
|
48
|
-
*/
|
|
49
|
-
NgxsStoragePluginOptions.prototype.deserialize = function (obj) { };
|
|
50
|
-
/**
|
|
51
|
-
* Method to alter object before serialization.
|
|
52
|
-
* @param {?} obj
|
|
53
|
-
* @param {?} key
|
|
54
|
-
* @return {?}
|
|
55
|
-
*/
|
|
56
|
-
NgxsStoragePluginOptions.prototype.beforeSerialize = function (obj, key) { };
|
|
57
|
-
/**
|
|
58
|
-
* Method to alter object after deserialization.
|
|
59
|
-
* @param {?} obj
|
|
60
|
-
* @param {?} key
|
|
61
|
-
* @return {?}
|
|
62
|
-
*/
|
|
63
|
-
NgxsStoragePluginOptions.prototype.afterDeserialize = function (obj, key) { };
|
|
64
|
-
}
|
|
65
|
-
/** @type {?} */
|
|
66
|
-
var NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');
|
|
67
|
-
/** @type {?} */
|
|
68
|
-
var STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');
|
|
69
|
-
/**
|
|
70
|
-
* @record
|
|
71
|
-
*/
|
|
72
|
-
function StorageEngine() { }
|
|
73
|
-
if (false) {
|
|
74
|
-
/** @type {?} */
|
|
75
|
-
StorageEngine.prototype.length;
|
|
76
|
-
/**
|
|
77
|
-
* @param {?} key
|
|
78
|
-
* @return {?}
|
|
79
|
-
*/
|
|
80
|
-
StorageEngine.prototype.getItem = function (key) { };
|
|
81
|
-
/**
|
|
82
|
-
* @param {?} key
|
|
83
|
-
* @param {?} val
|
|
84
|
-
* @return {?}
|
|
85
|
-
*/
|
|
86
|
-
StorageEngine.prototype.setItem = function (key, val) { };
|
|
87
|
-
/**
|
|
88
|
-
* @param {?} key
|
|
89
|
-
* @return {?}
|
|
90
|
-
*/
|
|
91
|
-
StorageEngine.prototype.removeItem = function (key) { };
|
|
92
|
-
/**
|
|
93
|
-
* @return {?}
|
|
94
|
-
*/
|
|
95
|
-
StorageEngine.prototype.clear = function () { };
|
|
7
|
+
/**
|
|
8
|
+
* @fileoverview added by tsickle
|
|
9
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
10
|
+
*/
|
|
11
|
+
/** @enum {number} */
|
|
12
|
+
var StorageOption = {
|
|
13
|
+
LocalStorage: 0,
|
|
14
|
+
SessionStorage: 1,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @record
|
|
18
|
+
*/
|
|
19
|
+
function NgxsStoragePluginOptions() { }
|
|
20
|
+
if (false) {
|
|
21
|
+
/**
|
|
22
|
+
* Key for the state slice to store in the storage engine.
|
|
23
|
+
* @type {?|undefined}
|
|
24
|
+
*/
|
|
25
|
+
NgxsStoragePluginOptions.prototype.key;
|
|
26
|
+
/**
|
|
27
|
+
* Storage engine to use. Deaults to localStorage but can provide
|
|
28
|
+
*
|
|
29
|
+
* sessionStorage or custom implementation of the StorageEngine interface
|
|
30
|
+
* @type {?|undefined}
|
|
31
|
+
*/
|
|
32
|
+
NgxsStoragePluginOptions.prototype.storage;
|
|
33
|
+
/**
|
|
34
|
+
* Migration strategies.
|
|
35
|
+
* @type {?|undefined}
|
|
36
|
+
*/
|
|
37
|
+
NgxsStoragePluginOptions.prototype.migrations;
|
|
38
|
+
/**
|
|
39
|
+
* Serailizer for the object before its pushed into the engine.
|
|
40
|
+
* @param {?} obj
|
|
41
|
+
* @return {?}
|
|
42
|
+
*/
|
|
43
|
+
NgxsStoragePluginOptions.prototype.serialize = function (obj) { };
|
|
44
|
+
/**
|
|
45
|
+
* Deserializer for the object before its pulled out of the engine.
|
|
46
|
+
* @param {?} obj
|
|
47
|
+
* @return {?}
|
|
48
|
+
*/
|
|
49
|
+
NgxsStoragePluginOptions.prototype.deserialize = function (obj) { };
|
|
50
|
+
/**
|
|
51
|
+
* Method to alter object before serialization.
|
|
52
|
+
* @param {?} obj
|
|
53
|
+
* @param {?} key
|
|
54
|
+
* @return {?}
|
|
55
|
+
*/
|
|
56
|
+
NgxsStoragePluginOptions.prototype.beforeSerialize = function (obj, key) { };
|
|
57
|
+
/**
|
|
58
|
+
* Method to alter object after deserialization.
|
|
59
|
+
* @param {?} obj
|
|
60
|
+
* @param {?} key
|
|
61
|
+
* @return {?}
|
|
62
|
+
*/
|
|
63
|
+
NgxsStoragePluginOptions.prototype.afterDeserialize = function (obj, key) { };
|
|
64
|
+
}
|
|
65
|
+
/** @type {?} */
|
|
66
|
+
var NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');
|
|
67
|
+
/** @type {?} */
|
|
68
|
+
var STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');
|
|
69
|
+
/**
|
|
70
|
+
* @record
|
|
71
|
+
*/
|
|
72
|
+
function StorageEngine() { }
|
|
73
|
+
if (false) {
|
|
74
|
+
/** @type {?} */
|
|
75
|
+
StorageEngine.prototype.length;
|
|
76
|
+
/**
|
|
77
|
+
* @param {?} key
|
|
78
|
+
* @return {?}
|
|
79
|
+
*/
|
|
80
|
+
StorageEngine.prototype.getItem = function (key) { };
|
|
81
|
+
/**
|
|
82
|
+
* @param {?} key
|
|
83
|
+
* @param {?} val
|
|
84
|
+
* @return {?}
|
|
85
|
+
*/
|
|
86
|
+
StorageEngine.prototype.setItem = function (key, val) { };
|
|
87
|
+
/**
|
|
88
|
+
* @param {?} key
|
|
89
|
+
* @return {?}
|
|
90
|
+
*/
|
|
91
|
+
StorageEngine.prototype.removeItem = function (key) { };
|
|
92
|
+
/**
|
|
93
|
+
* @return {?}
|
|
94
|
+
*/
|
|
95
|
+
StorageEngine.prototype.clear = function () { };
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/**
|
|
99
|
-
* @fileoverview added by tsickle
|
|
100
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
101
|
-
*/
|
|
102
|
-
/**
|
|
103
|
-
* If the `key` option is not provided then the below constant
|
|
104
|
-
* will be used as a default key
|
|
105
|
-
* @type {?}
|
|
106
|
-
*/
|
|
107
|
-
var DEFAULT_STATE_KEY = '@@STATE';
|
|
108
|
-
/**
|
|
109
|
-
* This key is used to retrieve static metadatas on state classes.
|
|
110
|
-
* This constant is taken from the core codebase
|
|
111
|
-
* @type {?}
|
|
112
|
-
*/
|
|
113
|
-
var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
114
|
-
/**
|
|
115
|
-
* @param {?} key
|
|
116
|
-
* @return {?}
|
|
117
|
-
*/
|
|
118
|
-
function transformKeyOption(key) {
|
|
119
|
-
if (!Array.isArray(key)) {
|
|
120
|
-
key = [key];
|
|
121
|
-
}
|
|
122
|
-
return key.map((/**
|
|
123
|
-
* @param {?} token
|
|
124
|
-
* @return {?}
|
|
125
|
-
*/
|
|
126
|
-
function (token) {
|
|
127
|
-
// If it has the `NGXS_OPTIONS_META` key then it means the developer
|
|
128
|
-
// has provided state class like `key: [AuthState]`.
|
|
129
|
-
if (token.hasOwnProperty(META_OPTIONS_KEY)) {
|
|
130
|
-
// The `name` property will be an actual state name or a `StateToken`.
|
|
131
|
-
token = ((/** @type {?} */ (token)))[META_OPTIONS_KEY].name;
|
|
132
|
-
}
|
|
133
|
-
return token instanceof StateToken ? token.getName() : ((/** @type {?} */ (token)));
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* @param {?} options
|
|
138
|
-
* @return {?}
|
|
139
|
-
*/
|
|
140
|
-
function storageOptionsFactory(options) {
|
|
141
|
-
if (options !== undefined && options.key) {
|
|
142
|
-
options.key = transformKeyOption(options.key);
|
|
143
|
-
}
|
|
144
|
-
return __assign({ key: [DEFAULT_STATE_KEY], storage: 0 /* LocalStorage */, serialize: JSON.stringify, deserialize: JSON.parse, beforeSerialize: (/**
|
|
145
|
-
* @param {?} obj
|
|
146
|
-
* @return {?}
|
|
147
|
-
*/
|
|
148
|
-
function (obj) { return obj; }), afterDeserialize: (/**
|
|
149
|
-
* @param {?} obj
|
|
150
|
-
* @return {?}
|
|
151
|
-
*/
|
|
152
|
-
function (obj) { return obj; }) }, options);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @param {?} options
|
|
156
|
-
* @param {?} platformId
|
|
157
|
-
* @return {?}
|
|
158
|
-
*/
|
|
159
|
-
function engineFactory(options, platformId) {
|
|
160
|
-
if (isPlatformServer(platformId)) {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
if (options.storage === 0 /* LocalStorage */) {
|
|
164
|
-
return localStorage;
|
|
165
|
-
}
|
|
166
|
-
else if (options.storage === 1 /* SessionStorage */) {
|
|
167
|
-
return sessionStorage;
|
|
168
|
-
}
|
|
169
|
-
return null;
|
|
98
|
+
/**
|
|
99
|
+
* @fileoverview added by tsickle
|
|
100
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* If the `key` option is not provided then the below constant
|
|
104
|
+
* will be used as a default key
|
|
105
|
+
* @type {?}
|
|
106
|
+
*/
|
|
107
|
+
var DEFAULT_STATE_KEY = '@@STATE';
|
|
108
|
+
/**
|
|
109
|
+
* This key is used to retrieve static metadatas on state classes.
|
|
110
|
+
* This constant is taken from the core codebase
|
|
111
|
+
* @type {?}
|
|
112
|
+
*/
|
|
113
|
+
var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
114
|
+
/**
|
|
115
|
+
* @param {?} key
|
|
116
|
+
* @return {?}
|
|
117
|
+
*/
|
|
118
|
+
function transformKeyOption(key) {
|
|
119
|
+
if (!Array.isArray(key)) {
|
|
120
|
+
key = [key];
|
|
121
|
+
}
|
|
122
|
+
return key.map((/**
|
|
123
|
+
* @param {?} token
|
|
124
|
+
* @return {?}
|
|
125
|
+
*/
|
|
126
|
+
function (token) {
|
|
127
|
+
// If it has the `NGXS_OPTIONS_META` key then it means the developer
|
|
128
|
+
// has provided state class like `key: [AuthState]`.
|
|
129
|
+
if (token.hasOwnProperty(META_OPTIONS_KEY)) {
|
|
130
|
+
// The `name` property will be an actual state name or a `StateToken`.
|
|
131
|
+
token = ((/** @type {?} */ (token)))[META_OPTIONS_KEY].name;
|
|
132
|
+
}
|
|
133
|
+
return token instanceof StateToken ? token.getName() : ((/** @type {?} */ (token)));
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* @param {?} options
|
|
138
|
+
* @return {?}
|
|
139
|
+
*/
|
|
140
|
+
function storageOptionsFactory(options) {
|
|
141
|
+
if (options !== undefined && options.key) {
|
|
142
|
+
options.key = transformKeyOption(options.key);
|
|
143
|
+
}
|
|
144
|
+
return __assign({ key: [DEFAULT_STATE_KEY], storage: 0 /* LocalStorage */, serialize: JSON.stringify, deserialize: JSON.parse, beforeSerialize: (/**
|
|
145
|
+
* @param {?} obj
|
|
146
|
+
* @return {?}
|
|
147
|
+
*/
|
|
148
|
+
function (obj) { return obj; }), afterDeserialize: (/**
|
|
149
|
+
* @param {?} obj
|
|
150
|
+
* @return {?}
|
|
151
|
+
*/
|
|
152
|
+
function (obj) { return obj; }) }, options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @param {?} options
|
|
156
|
+
* @param {?} platformId
|
|
157
|
+
* @return {?}
|
|
158
|
+
*/
|
|
159
|
+
function engineFactory(options, platformId) {
|
|
160
|
+
if (isPlatformServer(platformId)) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
if (options.storage === 0 /* LocalStorage */) {
|
|
164
|
+
return localStorage;
|
|
165
|
+
}
|
|
166
|
+
else if (options.storage === 1 /* SessionStorage */) {
|
|
167
|
+
return sessionStorage;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
/**
|
|
173
|
-
* @fileoverview added by tsickle
|
|
174
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
175
|
-
*/
|
|
176
|
-
var NgxsStoragePlugin = /** @class */ (function () {
|
|
177
|
-
function NgxsStoragePlugin(_options, _engine, _platformId) {
|
|
178
|
-
this._options = _options;
|
|
179
|
-
this._engine = _engine;
|
|
180
|
-
this._platformId = _platformId;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
* @param {?}
|
|
190
|
-
* @param {?}
|
|
191
|
-
* @
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
/** @type {?} */
|
|
249
|
-
var
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}());
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
172
|
+
/**
|
|
173
|
+
* @fileoverview added by tsickle
|
|
174
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
175
|
+
*/
|
|
176
|
+
var NgxsStoragePlugin = /** @class */ (function () {
|
|
177
|
+
function NgxsStoragePlugin(_options, _engine, _platformId) {
|
|
178
|
+
this._options = _options;
|
|
179
|
+
this._engine = _engine;
|
|
180
|
+
this._platformId = _platformId;
|
|
181
|
+
// We cast to `string[]` here as we're sure that this option has been
|
|
182
|
+
// transformed by the `storageOptionsFactory` function that provided token.
|
|
183
|
+
this._keys = (/** @type {?} */ (this._options.key));
|
|
184
|
+
// We default to `[DEFAULT_STATE_KEY]` if the user explicitly does not provide the `key` option.
|
|
185
|
+
this._usesDefaultStateKey = this._keys.length === 1 && this._keys[0] === DEFAULT_STATE_KEY;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @param {?} state
|
|
189
|
+
* @param {?} event
|
|
190
|
+
* @param {?} next
|
|
191
|
+
* @return {?}
|
|
192
|
+
*/
|
|
193
|
+
NgxsStoragePlugin.prototype.handle = /**
|
|
194
|
+
* @param {?} state
|
|
195
|
+
* @param {?} event
|
|
196
|
+
* @param {?} next
|
|
197
|
+
* @return {?}
|
|
198
|
+
*/
|
|
199
|
+
function (state, event, next) {
|
|
200
|
+
var _this = this;
|
|
201
|
+
var e_1, _a;
|
|
202
|
+
if (isPlatformServer(this._platformId) && this._engine === null) {
|
|
203
|
+
return next(state, event);
|
|
204
|
+
}
|
|
205
|
+
/** @type {?} */
|
|
206
|
+
var matches = actionMatcher(event);
|
|
207
|
+
/** @type {?} */
|
|
208
|
+
var isInitAction = matches(InitState);
|
|
209
|
+
/** @type {?} */
|
|
210
|
+
var isUpdateAction = matches(UpdateState);
|
|
211
|
+
/** @type {?} */
|
|
212
|
+
var isInitOrUpdateAction = isInitAction || isUpdateAction;
|
|
213
|
+
/** @type {?} */
|
|
214
|
+
var hasMigration = false;
|
|
215
|
+
if (isInitOrUpdateAction) {
|
|
216
|
+
/** @type {?} */
|
|
217
|
+
var addedStates = isUpdateAction && event.addedStates;
|
|
218
|
+
var _loop_1 = function (key) {
|
|
219
|
+
// We're checking what states have been added by NGXS and if any of these states should be handled by
|
|
220
|
+
// the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added
|
|
221
|
+
// the `user` state, the storage plugin will be rerun and will do redundant deserialization.
|
|
222
|
+
// `usesDefaultStateKey` is necessary to check since `event.addedStates` never contains `@@STATE`.
|
|
223
|
+
if (!this_1._usesDefaultStateKey && addedStates && !addedStates.hasOwnProperty(key)) {
|
|
224
|
+
return "continue";
|
|
225
|
+
}
|
|
226
|
+
/** @type {?} */
|
|
227
|
+
var storedValue = this_1._engine.getItem((/** @type {?} */ (key)));
|
|
228
|
+
if (storedValue !== 'undefined' && storedValue != null) {
|
|
229
|
+
try {
|
|
230
|
+
/** @type {?} */
|
|
231
|
+
var newVal = (/** @type {?} */ (this_1._options.deserialize))(storedValue);
|
|
232
|
+
storedValue = (/** @type {?} */ (this_1._options.afterDeserialize))(newVal, key);
|
|
233
|
+
}
|
|
234
|
+
catch (_a) {
|
|
235
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
236
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
237
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
238
|
+
console.error("Error ocurred while deserializing the " + key + " store value, falling back to empty object, the value obtained from the store: ", storedValue);
|
|
239
|
+
}
|
|
240
|
+
storedValue = {};
|
|
241
|
+
}
|
|
242
|
+
if (this_1._options.migrations) {
|
|
243
|
+
this_1._options.migrations.forEach((/**
|
|
244
|
+
* @param {?} strategy
|
|
245
|
+
* @return {?}
|
|
246
|
+
*/
|
|
247
|
+
function (strategy) {
|
|
248
|
+
/** @type {?} */
|
|
249
|
+
var versionMatch = strategy.version === getValue(storedValue, strategy.versionKey || 'version');
|
|
250
|
+
/** @type {?} */
|
|
251
|
+
var keyMatch = (!strategy.key && _this._usesDefaultStateKey) || strategy.key === key;
|
|
252
|
+
if (versionMatch && keyMatch) {
|
|
253
|
+
storedValue = strategy.migrate(storedValue);
|
|
254
|
+
hasMigration = true;
|
|
255
|
+
}
|
|
256
|
+
}));
|
|
257
|
+
}
|
|
258
|
+
if (!this_1._usesDefaultStateKey) {
|
|
259
|
+
state = setValue(state, (/** @type {?} */ (key)), storedValue);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
// The `UpdateState` action is dispatched whenever the feature state is added.
|
|
263
|
+
// The below condition is met only when the `UpdateState` is dispatched.
|
|
264
|
+
// Let's assume that we have 2 states `counter` and `@ngxs/router-plugin` state.
|
|
265
|
+
// `CounterState` is provided on the root level when calling `NgxsModule.forRoot()`
|
|
266
|
+
// and `@ngxs/router-plugin` is provided as a feature state.
|
|
267
|
+
// The storage plugin may save the `counter` state value as `10` before.
|
|
268
|
+
// The `CounterState` may implement the `ngxsOnInit` hook and call `ctx.setState(999)`.
|
|
269
|
+
// The storage plugin will re-hydrate the whole state when the `RouterState` is registered,
|
|
270
|
+
// and the `counter` state will again equal `10` (not `999`).
|
|
271
|
+
if (storedValue && addedStates && Object.keys(addedStates).length > 0) {
|
|
272
|
+
storedValue = Object.keys(addedStates).reduce((/**
|
|
273
|
+
* @param {?} accumulator
|
|
274
|
+
* @param {?} addedState
|
|
275
|
+
* @return {?}
|
|
276
|
+
*/
|
|
277
|
+
function (accumulator, addedState) {
|
|
278
|
+
// The `storedValue` may equal the whole state (when the default state key is used).
|
|
279
|
+
// If `addedStates` contains only `router` then we want to merge the state only
|
|
280
|
+
// with the `router` value.
|
|
281
|
+
// Let's assume that the `storedValue` is an object:
|
|
282
|
+
// `{ counter: 10, router: {...} }`
|
|
283
|
+
// This will pick only the `router` object from the `storedValue` and `counter`
|
|
284
|
+
// state will not be re-hydrated unnecessary.
|
|
285
|
+
if (storedValue.hasOwnProperty(addedState)) {
|
|
286
|
+
accumulator[addedState] = storedValue[addedState];
|
|
287
|
+
}
|
|
288
|
+
return accumulator;
|
|
289
|
+
}), (/** @type {?} */ ({})));
|
|
290
|
+
}
|
|
291
|
+
state = __assign({}, state, storedValue);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
var this_1 = this;
|
|
296
|
+
try {
|
|
297
|
+
for (var _b = __values(this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
298
|
+
var key = _c.value;
|
|
299
|
+
_loop_1(key);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
303
|
+
finally {
|
|
304
|
+
try {
|
|
305
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
306
|
+
}
|
|
307
|
+
finally { if (e_1) throw e_1.error; }
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return next(state, event).pipe(tap((/**
|
|
311
|
+
* @param {?} nextState
|
|
312
|
+
* @return {?}
|
|
313
|
+
*/
|
|
314
|
+
function (nextState) {
|
|
315
|
+
var e_2, _a;
|
|
316
|
+
if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
|
|
317
|
+
try {
|
|
318
|
+
for (var _b = __values(_this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
319
|
+
var key = _c.value;
|
|
320
|
+
/** @type {?} */
|
|
321
|
+
var val = nextState;
|
|
322
|
+
if (key !== DEFAULT_STATE_KEY) {
|
|
323
|
+
val = getValue(nextState, (/** @type {?} */ (key)));
|
|
324
|
+
}
|
|
325
|
+
try {
|
|
326
|
+
/** @type {?} */
|
|
327
|
+
var newVal = (/** @type {?} */ (_this._options.beforeSerialize))(val, key);
|
|
328
|
+
_this._engine.setItem((/** @type {?} */ (key)), (/** @type {?} */ (_this._options.serialize))(newVal));
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
332
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
333
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
334
|
+
if (error &&
|
|
335
|
+
(error.name === 'QuotaExceededError' ||
|
|
336
|
+
error.name === 'NS_ERROR_DOM_QUOTA_REACHED')) {
|
|
337
|
+
console.error("The " + key + " store value exceeds the browser storage quota: ", val);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
console.error("Error ocurred while serializing the " + key + " store value, value not updated, the value obtained from the store: ", val);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
347
|
+
finally {
|
|
348
|
+
try {
|
|
349
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
350
|
+
}
|
|
351
|
+
finally { if (e_2) throw e_2.error; }
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
})));
|
|
355
|
+
};
|
|
356
|
+
NgxsStoragePlugin.decorators = [
|
|
357
|
+
{ type: Injectable }
|
|
358
|
+
];
|
|
359
|
+
/** @nocollapse */
|
|
360
|
+
NgxsStoragePlugin.ctorParameters = function () { return [
|
|
361
|
+
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
|
|
362
|
+
{ type: undefined, decorators: [{ type: Inject, args: [STORAGE_ENGINE,] }] },
|
|
363
|
+
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
|
364
|
+
]; };
|
|
365
|
+
return NgxsStoragePlugin;
|
|
366
|
+
}());
|
|
367
|
+
if (false) {
|
|
368
|
+
/**
|
|
369
|
+
* @type {?}
|
|
370
|
+
* @private
|
|
371
|
+
*/
|
|
372
|
+
NgxsStoragePlugin.prototype._keys;
|
|
373
|
+
/**
|
|
374
|
+
* @type {?}
|
|
375
|
+
* @private
|
|
376
|
+
*/
|
|
377
|
+
NgxsStoragePlugin.prototype._usesDefaultStateKey;
|
|
378
|
+
/**
|
|
379
|
+
* @type {?}
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
NgxsStoragePlugin.prototype._options;
|
|
383
|
+
/**
|
|
384
|
+
* @type {?}
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
NgxsStoragePlugin.prototype._engine;
|
|
388
|
+
/**
|
|
389
|
+
* @type {?}
|
|
390
|
+
* @private
|
|
391
|
+
*/
|
|
392
|
+
NgxsStoragePlugin.prototype._platformId;
|
|
345
393
|
}
|
|
346
394
|
|
|
347
|
-
/**
|
|
348
|
-
* @fileoverview added by tsickle
|
|
349
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
350
|
-
*/
|
|
351
|
-
/** @type {?} */
|
|
352
|
-
var USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
353
|
-
var NgxsStoragePluginModule = /** @class */ (function () {
|
|
354
|
-
function NgxsStoragePluginModule() {
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* @param {?=} options
|
|
358
|
-
* @return {?}
|
|
359
|
-
*/
|
|
360
|
-
NgxsStoragePluginModule.forRoot = /**
|
|
361
|
-
* @param {?=} options
|
|
362
|
-
* @return {?}
|
|
363
|
-
*/
|
|
364
|
-
function (options) {
|
|
365
|
-
return {
|
|
366
|
-
ngModule: NgxsStoragePluginModule,
|
|
367
|
-
providers: [
|
|
368
|
-
{
|
|
369
|
-
provide: NGXS_PLUGINS,
|
|
370
|
-
useClass: NgxsStoragePlugin,
|
|
371
|
-
multi: true
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
provide: USER_OPTIONS,
|
|
375
|
-
useValue: options
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
379
|
-
useFactory: storageOptionsFactory,
|
|
380
|
-
deps: [USER_OPTIONS]
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
provide: STORAGE_ENGINE,
|
|
384
|
-
useFactory: engineFactory,
|
|
385
|
-
deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
|
|
386
|
-
}
|
|
387
|
-
]
|
|
388
|
-
};
|
|
389
|
-
};
|
|
390
|
-
NgxsStoragePluginModule.decorators = [
|
|
391
|
-
{ type: NgModule }
|
|
392
|
-
];
|
|
393
|
-
return NgxsStoragePluginModule;
|
|
395
|
+
/**
|
|
396
|
+
* @fileoverview added by tsickle
|
|
397
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
398
|
+
*/
|
|
399
|
+
/** @type {?} */
|
|
400
|
+
var USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
401
|
+
var NgxsStoragePluginModule = /** @class */ (function () {
|
|
402
|
+
function NgxsStoragePluginModule() {
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* @param {?=} options
|
|
406
|
+
* @return {?}
|
|
407
|
+
*/
|
|
408
|
+
NgxsStoragePluginModule.forRoot = /**
|
|
409
|
+
* @param {?=} options
|
|
410
|
+
* @return {?}
|
|
411
|
+
*/
|
|
412
|
+
function (options) {
|
|
413
|
+
return {
|
|
414
|
+
ngModule: NgxsStoragePluginModule,
|
|
415
|
+
providers: [
|
|
416
|
+
{
|
|
417
|
+
provide: NGXS_PLUGINS,
|
|
418
|
+
useClass: NgxsStoragePlugin,
|
|
419
|
+
multi: true
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
provide: USER_OPTIONS,
|
|
423
|
+
useValue: options
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
427
|
+
useFactory: storageOptionsFactory,
|
|
428
|
+
deps: [USER_OPTIONS]
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
provide: STORAGE_ENGINE,
|
|
432
|
+
useFactory: engineFactory,
|
|
433
|
+
deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
|
|
434
|
+
}
|
|
435
|
+
]
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
NgxsStoragePluginModule.decorators = [
|
|
439
|
+
{ type: NgModule }
|
|
440
|
+
];
|
|
441
|
+
return NgxsStoragePluginModule;
|
|
394
442
|
}());
|
|
395
443
|
|
|
396
|
-
/**
|
|
397
|
-
* @fileoverview added by tsickle
|
|
398
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
444
|
+
/**
|
|
445
|
+
* @fileoverview added by tsickle
|
|
446
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
399
447
|
*/
|
|
400
448
|
|
|
401
|
-
/**
|
|
402
|
-
* @fileoverview added by tsickle
|
|
403
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
449
|
+
/**
|
|
450
|
+
* @fileoverview added by tsickle
|
|
451
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
404
452
|
*/
|
|
405
453
|
|
|
406
|
-
/**
|
|
407
|
-
* @fileoverview added by tsickle
|
|
408
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
454
|
+
/**
|
|
455
|
+
* @fileoverview added by tsickle
|
|
456
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
409
457
|
*/
|
|
410
458
|
|
|
411
459
|
export { NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, STORAGE_ENGINE, USER_OPTIONS as ɵa, storageOptionsFactory as ɵb, engineFactory as ɵc };
|