@ngxs/storage-plugin 3.7.3-dev.master-f88f1ef → 3.7.4
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 +381 -381
- package/bundles/ngxs-storage-plugin.umd.js.map +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 +152 -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 +183 -183
- package/esm5/src/symbols.js +93 -93
- package/fesm2015/ngxs-storage-plugin.js +354 -354
- package/fesm2015/ngxs-storage-plugin.js.map +1 -1
- package/fesm5/ngxs-storage-plugin.js +390 -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/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 +9 -9
- package/src/symbols.d.ts +64 -64
|
@@ -4,408 +4,408 @@ 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
|
-
* @param {?} state
|
|
184
|
-
* @param {?} event
|
|
185
|
-
* @param {?} next
|
|
186
|
-
* @return {?}
|
|
187
|
-
*/
|
|
188
|
-
NgxsStoragePlugin.prototype.handle = /**
|
|
189
|
-
* @param {?} state
|
|
190
|
-
* @param {?} event
|
|
191
|
-
* @param {?} next
|
|
192
|
-
* @return {?}
|
|
193
|
-
*/
|
|
194
|
-
function (state, event, next) {
|
|
195
|
-
var _this = this;
|
|
196
|
-
var e_1, _a;
|
|
197
|
-
if (isPlatformServer(this._platformId) && this._engine === null) {
|
|
198
|
-
return next(state, event);
|
|
199
|
-
}
|
|
200
|
-
// We cast to `string[]` here as we're sure that this option has been
|
|
201
|
-
// transformed by the `storageOptionsFactory` function that provided token
|
|
202
|
-
/** @type {?} */
|
|
203
|
-
var keys = (/** @type {?} */ (this._options.key));
|
|
204
|
-
/** @type {?} */
|
|
205
|
-
var matches = actionMatcher(event);
|
|
206
|
-
/** @type {?} */
|
|
207
|
-
var isInitAction = matches(InitState);
|
|
208
|
-
/** @type {?} */
|
|
209
|
-
var isUpdateAction = matches(UpdateState);
|
|
210
|
-
/** @type {?} */
|
|
211
|
-
var isInitOrUpdateAction = isInitAction || isUpdateAction;
|
|
212
|
-
/** @type {?} */
|
|
213
|
-
var hasMigration = false;
|
|
214
|
-
if (isInitOrUpdateAction) {
|
|
215
|
-
var _loop_1 = function (key) {
|
|
216
|
-
// We're checking what states have been added by NGXS and if any of these states should be handled by
|
|
217
|
-
// the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added
|
|
218
|
-
// the `user` state, the storage plugin will be rerun and will do redundant deserialization.
|
|
219
|
-
if (isUpdateAction && event.addedStates && !event.addedStates.hasOwnProperty(key)) {
|
|
220
|
-
return "continue";
|
|
221
|
-
}
|
|
222
|
-
/** @type {?} */
|
|
223
|
-
var isMaster = key === DEFAULT_STATE_KEY;
|
|
224
|
-
/** @type {?} */
|
|
225
|
-
var val = this_1._engine.getItem((/** @type {?} */ (key)));
|
|
226
|
-
if (val !== 'undefined' && val != null) {
|
|
227
|
-
try {
|
|
228
|
-
/** @type {?} */
|
|
229
|
-
var newVal = (/** @type {?} */ (this_1._options.deserialize))(val);
|
|
230
|
-
val = (/** @type {?} */ (this_1._options.afterDeserialize))(newVal, key);
|
|
231
|
-
}
|
|
232
|
-
catch (e) {
|
|
233
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
234
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
235
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
236
|
-
console.error("Error ocurred while deserializing the " + key + " store value, falling back to empty object, the value obtained from the store: ", val);
|
|
237
|
-
}
|
|
238
|
-
val = {};
|
|
239
|
-
}
|
|
240
|
-
if (this_1._options.migrations) {
|
|
241
|
-
this_1._options.migrations.forEach((/**
|
|
242
|
-
* @param {?} strategy
|
|
243
|
-
* @return {?}
|
|
244
|
-
*/
|
|
245
|
-
function (strategy) {
|
|
246
|
-
/** @type {?} */
|
|
247
|
-
var versionMatch = strategy.version === getValue(val, strategy.versionKey || 'version');
|
|
248
|
-
/** @type {?} */
|
|
249
|
-
var keyMatch = (!strategy.key && isMaster) || strategy.key === key;
|
|
250
|
-
if (versionMatch && keyMatch) {
|
|
251
|
-
val = strategy.migrate(val);
|
|
252
|
-
hasMigration = true;
|
|
253
|
-
}
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
if (!isMaster) {
|
|
257
|
-
state = setValue(state, (/** @type {?} */ (key)), val);
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
state = __assign({}, state, val);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
var this_1 = this;
|
|
265
|
-
try {
|
|
266
|
-
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
267
|
-
var key = keys_1_1.value;
|
|
268
|
-
_loop_1(key);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
272
|
-
finally {
|
|
273
|
-
try {
|
|
274
|
-
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
|
275
|
-
}
|
|
276
|
-
finally { if (e_1) throw e_1.error; }
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return next(state, event).pipe(tap((/**
|
|
280
|
-
* @param {?} nextState
|
|
281
|
-
* @return {?}
|
|
282
|
-
*/
|
|
283
|
-
function (nextState) {
|
|
284
|
-
var e_2, _a;
|
|
285
|
-
if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
|
|
286
|
-
try {
|
|
287
|
-
for (var keys_2 = __values(keys), keys_2_1 = keys_2.next(); !keys_2_1.done; keys_2_1 = keys_2.next()) {
|
|
288
|
-
var key = keys_2_1.value;
|
|
289
|
-
/** @type {?} */
|
|
290
|
-
var val = nextState;
|
|
291
|
-
if (key !== DEFAULT_STATE_KEY) {
|
|
292
|
-
val = getValue(nextState, (/** @type {?} */ (key)));
|
|
293
|
-
}
|
|
294
|
-
try {
|
|
295
|
-
/** @type {?} */
|
|
296
|
-
var newVal = (/** @type {?} */ (_this._options.beforeSerialize))(val, key);
|
|
297
|
-
_this._engine.setItem((/** @type {?} */ (key)), (/** @type {?} */ (_this._options.serialize))(newVal));
|
|
298
|
-
}
|
|
299
|
-
catch (e) {
|
|
300
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
301
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
302
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
303
|
-
console.error("Error ocurred while serializing the " + key + " store value, value not updated, the value obtained from the store: ", val);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
309
|
-
finally {
|
|
310
|
-
try {
|
|
311
|
-
if (keys_2_1 && !keys_2_1.done && (_a = keys_2.return)) _a.call(keys_2);
|
|
312
|
-
}
|
|
313
|
-
finally { if (e_2) throw e_2.error; }
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
})));
|
|
317
|
-
};
|
|
318
|
-
NgxsStoragePlugin.decorators = [
|
|
319
|
-
{ type: Injectable }
|
|
320
|
-
];
|
|
321
|
-
/** @nocollapse */
|
|
322
|
-
NgxsStoragePlugin.ctorParameters = function () { return [
|
|
323
|
-
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
|
|
324
|
-
{ type: undefined, decorators: [{ type: Inject, args: [STORAGE_ENGINE,] }] },
|
|
325
|
-
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
|
326
|
-
]; };
|
|
327
|
-
return NgxsStoragePlugin;
|
|
328
|
-
}());
|
|
329
|
-
if (false) {
|
|
330
|
-
/**
|
|
331
|
-
* @type {?}
|
|
332
|
-
* @private
|
|
333
|
-
*/
|
|
334
|
-
NgxsStoragePlugin.prototype._options;
|
|
335
|
-
/**
|
|
336
|
-
* @type {?}
|
|
337
|
-
* @private
|
|
338
|
-
*/
|
|
339
|
-
NgxsStoragePlugin.prototype._engine;
|
|
340
|
-
/**
|
|
341
|
-
* @type {?}
|
|
342
|
-
* @private
|
|
343
|
-
*/
|
|
344
|
-
NgxsStoragePlugin.prototype._platformId;
|
|
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
|
+
* @param {?} state
|
|
184
|
+
* @param {?} event
|
|
185
|
+
* @param {?} next
|
|
186
|
+
* @return {?}
|
|
187
|
+
*/
|
|
188
|
+
NgxsStoragePlugin.prototype.handle = /**
|
|
189
|
+
* @param {?} state
|
|
190
|
+
* @param {?} event
|
|
191
|
+
* @param {?} next
|
|
192
|
+
* @return {?}
|
|
193
|
+
*/
|
|
194
|
+
function (state, event, next) {
|
|
195
|
+
var _this = this;
|
|
196
|
+
var e_1, _a;
|
|
197
|
+
if (isPlatformServer(this._platformId) && this._engine === null) {
|
|
198
|
+
return next(state, event);
|
|
199
|
+
}
|
|
200
|
+
// We cast to `string[]` here as we're sure that this option has been
|
|
201
|
+
// transformed by the `storageOptionsFactory` function that provided token
|
|
202
|
+
/** @type {?} */
|
|
203
|
+
var keys = (/** @type {?} */ (this._options.key));
|
|
204
|
+
/** @type {?} */
|
|
205
|
+
var matches = actionMatcher(event);
|
|
206
|
+
/** @type {?} */
|
|
207
|
+
var isInitAction = matches(InitState);
|
|
208
|
+
/** @type {?} */
|
|
209
|
+
var isUpdateAction = matches(UpdateState);
|
|
210
|
+
/** @type {?} */
|
|
211
|
+
var isInitOrUpdateAction = isInitAction || isUpdateAction;
|
|
212
|
+
/** @type {?} */
|
|
213
|
+
var hasMigration = false;
|
|
214
|
+
if (isInitOrUpdateAction) {
|
|
215
|
+
var _loop_1 = function (key) {
|
|
216
|
+
// We're checking what states have been added by NGXS and if any of these states should be handled by
|
|
217
|
+
// the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added
|
|
218
|
+
// the `user` state, the storage plugin will be rerun and will do redundant deserialization.
|
|
219
|
+
if (isUpdateAction && event.addedStates && !event.addedStates.hasOwnProperty(key)) {
|
|
220
|
+
return "continue";
|
|
221
|
+
}
|
|
222
|
+
/** @type {?} */
|
|
223
|
+
var isMaster = key === DEFAULT_STATE_KEY;
|
|
224
|
+
/** @type {?} */
|
|
225
|
+
var val = this_1._engine.getItem((/** @type {?} */ (key)));
|
|
226
|
+
if (val !== 'undefined' && val != null) {
|
|
227
|
+
try {
|
|
228
|
+
/** @type {?} */
|
|
229
|
+
var newVal = (/** @type {?} */ (this_1._options.deserialize))(val);
|
|
230
|
+
val = (/** @type {?} */ (this_1._options.afterDeserialize))(newVal, key);
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
234
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
235
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
236
|
+
console.error("Error ocurred while deserializing the " + key + " store value, falling back to empty object, the value obtained from the store: ", val);
|
|
237
|
+
}
|
|
238
|
+
val = {};
|
|
239
|
+
}
|
|
240
|
+
if (this_1._options.migrations) {
|
|
241
|
+
this_1._options.migrations.forEach((/**
|
|
242
|
+
* @param {?} strategy
|
|
243
|
+
* @return {?}
|
|
244
|
+
*/
|
|
245
|
+
function (strategy) {
|
|
246
|
+
/** @type {?} */
|
|
247
|
+
var versionMatch = strategy.version === getValue(val, strategy.versionKey || 'version');
|
|
248
|
+
/** @type {?} */
|
|
249
|
+
var keyMatch = (!strategy.key && isMaster) || strategy.key === key;
|
|
250
|
+
if (versionMatch && keyMatch) {
|
|
251
|
+
val = strategy.migrate(val);
|
|
252
|
+
hasMigration = true;
|
|
253
|
+
}
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
256
|
+
if (!isMaster) {
|
|
257
|
+
state = setValue(state, (/** @type {?} */ (key)), val);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
state = __assign({}, state, val);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var this_1 = this;
|
|
265
|
+
try {
|
|
266
|
+
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
267
|
+
var key = keys_1_1.value;
|
|
268
|
+
_loop_1(key);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
272
|
+
finally {
|
|
273
|
+
try {
|
|
274
|
+
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
|
275
|
+
}
|
|
276
|
+
finally { if (e_1) throw e_1.error; }
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return next(state, event).pipe(tap((/**
|
|
280
|
+
* @param {?} nextState
|
|
281
|
+
* @return {?}
|
|
282
|
+
*/
|
|
283
|
+
function (nextState) {
|
|
284
|
+
var e_2, _a;
|
|
285
|
+
if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
|
|
286
|
+
try {
|
|
287
|
+
for (var keys_2 = __values(keys), keys_2_1 = keys_2.next(); !keys_2_1.done; keys_2_1 = keys_2.next()) {
|
|
288
|
+
var key = keys_2_1.value;
|
|
289
|
+
/** @type {?} */
|
|
290
|
+
var val = nextState;
|
|
291
|
+
if (key !== DEFAULT_STATE_KEY) {
|
|
292
|
+
val = getValue(nextState, (/** @type {?} */ (key)));
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
/** @type {?} */
|
|
296
|
+
var newVal = (/** @type {?} */ (_this._options.beforeSerialize))(val, key);
|
|
297
|
+
_this._engine.setItem((/** @type {?} */ (key)), (/** @type {?} */ (_this._options.serialize))(newVal));
|
|
298
|
+
}
|
|
299
|
+
catch (e) {
|
|
300
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
301
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
302
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
303
|
+
console.error("Error ocurred while serializing the " + key + " store value, value not updated, the value obtained from the store: ", val);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
309
|
+
finally {
|
|
310
|
+
try {
|
|
311
|
+
if (keys_2_1 && !keys_2_1.done && (_a = keys_2.return)) _a.call(keys_2);
|
|
312
|
+
}
|
|
313
|
+
finally { if (e_2) throw e_2.error; }
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
})));
|
|
317
|
+
};
|
|
318
|
+
NgxsStoragePlugin.decorators = [
|
|
319
|
+
{ type: Injectable }
|
|
320
|
+
];
|
|
321
|
+
/** @nocollapse */
|
|
322
|
+
NgxsStoragePlugin.ctorParameters = function () { return [
|
|
323
|
+
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
|
|
324
|
+
{ type: undefined, decorators: [{ type: Inject, args: [STORAGE_ENGINE,] }] },
|
|
325
|
+
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
|
326
|
+
]; };
|
|
327
|
+
return NgxsStoragePlugin;
|
|
328
|
+
}());
|
|
329
|
+
if (false) {
|
|
330
|
+
/**
|
|
331
|
+
* @type {?}
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
NgxsStoragePlugin.prototype._options;
|
|
335
|
+
/**
|
|
336
|
+
* @type {?}
|
|
337
|
+
* @private
|
|
338
|
+
*/
|
|
339
|
+
NgxsStoragePlugin.prototype._engine;
|
|
340
|
+
/**
|
|
341
|
+
* @type {?}
|
|
342
|
+
* @private
|
|
343
|
+
*/
|
|
344
|
+
NgxsStoragePlugin.prototype._platformId;
|
|
345
345
|
}
|
|
346
346
|
|
|
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;
|
|
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;
|
|
394
394
|
}());
|
|
395
395
|
|
|
396
|
-
/**
|
|
397
|
-
* @fileoverview added by tsickle
|
|
398
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
396
|
+
/**
|
|
397
|
+
* @fileoverview added by tsickle
|
|
398
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
399
399
|
*/
|
|
400
400
|
|
|
401
|
-
/**
|
|
402
|
-
* @fileoverview added by tsickle
|
|
403
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
401
|
+
/**
|
|
402
|
+
* @fileoverview added by tsickle
|
|
403
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
404
404
|
*/
|
|
405
405
|
|
|
406
|
-
/**
|
|
407
|
-
* @fileoverview added by tsickle
|
|
408
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
406
|
+
/**
|
|
407
|
+
* @fileoverview added by tsickle
|
|
408
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
409
409
|
*/
|
|
410
410
|
|
|
411
411
|
export { NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, STORAGE_ENGINE, USER_OPTIONS as ɵa, storageOptionsFactory as ɵb, engineFactory as ɵc };
|