@ngxs/logger-plugin 3.7.6 → 3.8.0-dev.master-743a236
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/bundles/ngxs-logger-plugin.umd.js +72 -546
- package/bundles/ngxs-logger-plugin.umd.js.map +1 -1
- package/esm2015/index.js +2 -6
- package/esm2015/ngxs-logger-plugin.js +2 -7
- package/esm2015/src/action-logger.js +3 -65
- package/esm2015/src/internals.js +3 -23
- package/esm2015/src/log-writer.js +2 -60
- package/esm2015/src/logger.module.js +10 -23
- package/esm2015/src/logger.plugin.js +14 -58
- package/esm2015/src/public_api.js +2 -6
- package/esm2015/src/symbols.js +1 -32
- package/fesm2015/ngxs-logger-plugin.js +30 -266
- package/fesm2015/ngxs-logger-plugin.js.map +1 -1
- package/ngxs-logger-plugin.d.ts +1 -1
- package/package.json +5 -8
- package/src/logger.module.d.ts +5 -1
- package/src/logger.plugin.d.ts +3 -0
- package/src/symbols.d.ts +1 -1
- package/bundles/ngxs-logger-plugin.umd.min.js +0 -16
- package/bundles/ngxs-logger-plugin.umd.min.js.map +0 -1
- package/esm5/index.js +0 -9
- package/esm5/ngxs-logger-plugin.js +0 -10
- package/esm5/src/action-logger.js +0 -121
- package/esm5/src/internals.js +0 -34
- package/esm5/src/log-writer.js +0 -147
- package/esm5/src/logger.module.js +0 -67
- package/esm5/src/logger.plugin.js +0 -86
- package/esm5/src/public_api.js +0 -8
- package/esm5/src/symbols.js +0 -34
- package/fesm5/ngxs-logger-plugin.js +0 -492
- package/fesm5/ngxs-logger-plugin.js.map +0 -1
- package/ngxs-logger-plugin.metadata.json +0 -1
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
|
-
import { InjectionToken, Injectable, Inject, Injector, NgModule } from '@angular/core';
|
|
3
|
-
import { getActionTypeFromInstance, Store, NGXS_PLUGINS } from '@ngxs/store';
|
|
4
|
-
import { tap, catchError } from 'rxjs/operators';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @fileoverview added by tsickle
|
|
8
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
9
|
-
*/
|
|
10
|
-
/** @type {?} */
|
|
11
|
-
var repeat = (/**
|
|
12
|
-
* @param {?} str
|
|
13
|
-
* @param {?} times
|
|
14
|
-
* @return {?}
|
|
15
|
-
*/
|
|
16
|
-
function (str, times) { return new Array(times + 1).join(str); });
|
|
17
|
-
/** @type {?} */
|
|
18
|
-
var pad = (/**
|
|
19
|
-
* @param {?} num
|
|
20
|
-
* @param {?} maxLength
|
|
21
|
-
* @return {?}
|
|
22
|
-
*/
|
|
23
|
-
function (num, maxLength) {
|
|
24
|
-
return repeat('0', maxLength - num.toString().length) + num;
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* @param {?} time
|
|
28
|
-
* @return {?}
|
|
29
|
-
*/
|
|
30
|
-
function formatTime(time) {
|
|
31
|
-
return (pad(time.getHours(), 2) +
|
|
32
|
-
":" +
|
|
33
|
-
pad(time.getMinutes(), 2) +
|
|
34
|
-
":" +
|
|
35
|
-
pad(time.getSeconds(), 2) +
|
|
36
|
-
"." +
|
|
37
|
-
pad(time.getMilliseconds(), 3));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @fileoverview added by tsickle
|
|
42
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
43
|
-
*/
|
|
44
|
-
var ActionLogger = /** @class */ (function () {
|
|
45
|
-
function ActionLogger(action, store, logWriter) {
|
|
46
|
-
this.action = action;
|
|
47
|
-
this.store = store;
|
|
48
|
-
this.logWriter = logWriter;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @param {?} state
|
|
52
|
-
* @return {?}
|
|
53
|
-
*/
|
|
54
|
-
ActionLogger.prototype.dispatched = /**
|
|
55
|
-
* @param {?} state
|
|
56
|
-
* @return {?}
|
|
57
|
-
*/
|
|
58
|
-
function (state) {
|
|
59
|
-
/** @type {?} */
|
|
60
|
-
var actionName = getActionTypeFromInstance(this.action);
|
|
61
|
-
/** @type {?} */
|
|
62
|
-
var formattedTime = formatTime(new Date());
|
|
63
|
-
/** @type {?} */
|
|
64
|
-
var message = "action " + actionName + " @ " + formattedTime;
|
|
65
|
-
this.logWriter.startGroup(message);
|
|
66
|
-
// print payload only if at least one property is supplied
|
|
67
|
-
if (this._hasPayload(this.action)) {
|
|
68
|
-
this.logWriter.logGrey('payload', __assign({}, this.action));
|
|
69
|
-
}
|
|
70
|
-
this.logWriter.logGrey('prev state', state);
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* @param {?} nextState
|
|
74
|
-
* @return {?}
|
|
75
|
-
*/
|
|
76
|
-
ActionLogger.prototype.completed = /**
|
|
77
|
-
* @param {?} nextState
|
|
78
|
-
* @return {?}
|
|
79
|
-
*/
|
|
80
|
-
function (nextState) {
|
|
81
|
-
this.logWriter.logGreen('next state', nextState);
|
|
82
|
-
this.logWriter.endGroup();
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* @param {?} error
|
|
86
|
-
* @return {?}
|
|
87
|
-
*/
|
|
88
|
-
ActionLogger.prototype.errored = /**
|
|
89
|
-
* @param {?} error
|
|
90
|
-
* @return {?}
|
|
91
|
-
*/
|
|
92
|
-
function (error) {
|
|
93
|
-
this.logWriter.logRedish('next state after error', this.store.snapshot());
|
|
94
|
-
this.logWriter.logRedish('error', error);
|
|
95
|
-
this.logWriter.endGroup();
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* @private
|
|
99
|
-
* @param {?} event
|
|
100
|
-
* @return {?}
|
|
101
|
-
*/
|
|
102
|
-
ActionLogger.prototype._hasPayload = /**
|
|
103
|
-
* @private
|
|
104
|
-
* @param {?} event
|
|
105
|
-
* @return {?}
|
|
106
|
-
*/
|
|
107
|
-
function (event) {
|
|
108
|
-
/** @type {?} */
|
|
109
|
-
var nonEmptyProperties = this._getNonEmptyProperties(event);
|
|
110
|
-
return nonEmptyProperties.length > 0;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* @private
|
|
114
|
-
* @param {?} event
|
|
115
|
-
* @return {?}
|
|
116
|
-
*/
|
|
117
|
-
ActionLogger.prototype._getNonEmptyProperties = /**
|
|
118
|
-
* @private
|
|
119
|
-
* @param {?} event
|
|
120
|
-
* @return {?}
|
|
121
|
-
*/
|
|
122
|
-
function (event) {
|
|
123
|
-
/** @type {?} */
|
|
124
|
-
var keys = Object.keys(event);
|
|
125
|
-
/** @type {?} */
|
|
126
|
-
var values = keys.map((/**
|
|
127
|
-
* @param {?} key
|
|
128
|
-
* @return {?}
|
|
129
|
-
*/
|
|
130
|
-
function (key) { return event[key]; }));
|
|
131
|
-
return values.filter((/**
|
|
132
|
-
* @param {?} value
|
|
133
|
-
* @return {?}
|
|
134
|
-
*/
|
|
135
|
-
function (value) { return value !== undefined; }));
|
|
136
|
-
};
|
|
137
|
-
return ActionLogger;
|
|
138
|
-
}());
|
|
139
|
-
if (false) {
|
|
140
|
-
/**
|
|
141
|
-
* @type {?}
|
|
142
|
-
* @private
|
|
143
|
-
*/
|
|
144
|
-
ActionLogger.prototype.action;
|
|
145
|
-
/**
|
|
146
|
-
* @type {?}
|
|
147
|
-
* @private
|
|
148
|
-
*/
|
|
149
|
-
ActionLogger.prototype.store;
|
|
150
|
-
/**
|
|
151
|
-
* @type {?}
|
|
152
|
-
* @private
|
|
153
|
-
*/
|
|
154
|
-
ActionLogger.prototype.logWriter;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @fileoverview added by tsickle
|
|
159
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
160
|
-
*/
|
|
161
|
-
var LogWriter = /** @class */ (function () {
|
|
162
|
-
function LogWriter(options) {
|
|
163
|
-
this.options = options;
|
|
164
|
-
this.options = this.options || (/** @type {?} */ ({}));
|
|
165
|
-
this.logger = options.logger || console;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* @param {?} message
|
|
169
|
-
* @return {?}
|
|
170
|
-
*/
|
|
171
|
-
LogWriter.prototype.startGroup = /**
|
|
172
|
-
* @param {?} message
|
|
173
|
-
* @return {?}
|
|
174
|
-
*/
|
|
175
|
-
function (message) {
|
|
176
|
-
/** @type {?} */
|
|
177
|
-
var startGroupFn = this.options.collapsed
|
|
178
|
-
? this.logger.groupCollapsed
|
|
179
|
-
: this.logger.group;
|
|
180
|
-
try {
|
|
181
|
-
startGroupFn.call(this.logger, message);
|
|
182
|
-
}
|
|
183
|
-
catch (e) {
|
|
184
|
-
console.log(message);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* @return {?}
|
|
189
|
-
*/
|
|
190
|
-
LogWriter.prototype.endGroup = /**
|
|
191
|
-
* @return {?}
|
|
192
|
-
*/
|
|
193
|
-
function () {
|
|
194
|
-
try {
|
|
195
|
-
this.logger.groupEnd();
|
|
196
|
-
}
|
|
197
|
-
catch (e) {
|
|
198
|
-
this.logger.log('—— log end ——');
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* @param {?} title
|
|
203
|
-
* @param {?} payload
|
|
204
|
-
* @return {?}
|
|
205
|
-
*/
|
|
206
|
-
LogWriter.prototype.logGrey = /**
|
|
207
|
-
* @param {?} title
|
|
208
|
-
* @param {?} payload
|
|
209
|
-
* @return {?}
|
|
210
|
-
*/
|
|
211
|
-
function (title, payload) {
|
|
212
|
-
/** @type {?} */
|
|
213
|
-
var greyStyle = 'color: #9E9E9E; font-weight: bold';
|
|
214
|
-
this.log(title, greyStyle, payload);
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* @param {?} title
|
|
218
|
-
* @param {?} payload
|
|
219
|
-
* @return {?}
|
|
220
|
-
*/
|
|
221
|
-
LogWriter.prototype.logGreen = /**
|
|
222
|
-
* @param {?} title
|
|
223
|
-
* @param {?} payload
|
|
224
|
-
* @return {?}
|
|
225
|
-
*/
|
|
226
|
-
function (title, payload) {
|
|
227
|
-
/** @type {?} */
|
|
228
|
-
var greenStyle = 'color: #4CAF50; font-weight: bold';
|
|
229
|
-
this.log(title, greenStyle, payload);
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* @param {?} title
|
|
233
|
-
* @param {?} payload
|
|
234
|
-
* @return {?}
|
|
235
|
-
*/
|
|
236
|
-
LogWriter.prototype.logRedish = /**
|
|
237
|
-
* @param {?} title
|
|
238
|
-
* @param {?} payload
|
|
239
|
-
* @return {?}
|
|
240
|
-
*/
|
|
241
|
-
function (title, payload) {
|
|
242
|
-
/** @type {?} */
|
|
243
|
-
var redishStyle = 'color: #FD8182; font-weight: bold';
|
|
244
|
-
this.log(title, redishStyle, payload);
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* @param {?} title
|
|
248
|
-
* @param {?} color
|
|
249
|
-
* @param {?} payload
|
|
250
|
-
* @return {?}
|
|
251
|
-
*/
|
|
252
|
-
LogWriter.prototype.log = /**
|
|
253
|
-
* @param {?} title
|
|
254
|
-
* @param {?} color
|
|
255
|
-
* @param {?} payload
|
|
256
|
-
* @return {?}
|
|
257
|
-
*/
|
|
258
|
-
function (title, color, payload) {
|
|
259
|
-
if (this.isIE()) {
|
|
260
|
-
this.logger.log(title, payload);
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
this.logger.log('%c ' + title, color, payload);
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
/**
|
|
267
|
-
* @return {?}
|
|
268
|
-
*/
|
|
269
|
-
LogWriter.prototype.isIE = /**
|
|
270
|
-
* @return {?}
|
|
271
|
-
*/
|
|
272
|
-
function () {
|
|
273
|
-
/** @type {?} */
|
|
274
|
-
var ua = typeof window !== 'undefined' && window.navigator.userAgent
|
|
275
|
-
? window.navigator.userAgent
|
|
276
|
-
: '';
|
|
277
|
-
/** @type {?} */
|
|
278
|
-
var msIE = false;
|
|
279
|
-
/** @type {?} */
|
|
280
|
-
var oldIE = ua.indexOf('MSIE ');
|
|
281
|
-
/** @type {?} */
|
|
282
|
-
var newIE = ua.indexOf('Trident/');
|
|
283
|
-
if (oldIE > -1 || newIE > -1) {
|
|
284
|
-
msIE = true;
|
|
285
|
-
}
|
|
286
|
-
return msIE;
|
|
287
|
-
};
|
|
288
|
-
return LogWriter;
|
|
289
|
-
}());
|
|
290
|
-
if (false) {
|
|
291
|
-
/**
|
|
292
|
-
* @type {?}
|
|
293
|
-
* @private
|
|
294
|
-
*/
|
|
295
|
-
LogWriter.prototype.logger;
|
|
296
|
-
/**
|
|
297
|
-
* @type {?}
|
|
298
|
-
* @private
|
|
299
|
-
*/
|
|
300
|
-
LogWriter.prototype.options;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* @fileoverview added by tsickle
|
|
305
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
306
|
-
*/
|
|
307
|
-
/**
|
|
308
|
-
* @record
|
|
309
|
-
*/
|
|
310
|
-
function NgxsLoggerPluginOptions() { }
|
|
311
|
-
if (false) {
|
|
312
|
-
/**
|
|
313
|
-
* Auto expand logged actions
|
|
314
|
-
* @type {?|undefined}
|
|
315
|
-
*/
|
|
316
|
-
NgxsLoggerPluginOptions.prototype.collapsed;
|
|
317
|
-
/**
|
|
318
|
-
* Provide alternate console.log implementation
|
|
319
|
-
* @type {?|undefined}
|
|
320
|
-
*/
|
|
321
|
-
NgxsLoggerPluginOptions.prototype.logger;
|
|
322
|
-
/**
|
|
323
|
-
* Disable the logger. Useful for prod mode.
|
|
324
|
-
* @type {?|undefined}
|
|
325
|
-
*/
|
|
326
|
-
NgxsLoggerPluginOptions.prototype.disabled;
|
|
327
|
-
/**
|
|
328
|
-
* Predicate for actions to be the logged. Takes action and state snapshot as parameters
|
|
329
|
-
* @type {?|undefined}
|
|
330
|
-
*/
|
|
331
|
-
NgxsLoggerPluginOptions.prototype.filter;
|
|
332
|
-
}
|
|
333
|
-
/** @type {?} */
|
|
334
|
-
var NGXS_LOGGER_PLUGIN_OPTIONS = new InjectionToken('NGXS_LOGGER_PLUGIN_OPTIONS');
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* @fileoverview added by tsickle
|
|
338
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
339
|
-
*/
|
|
340
|
-
var NgxsLoggerPlugin = /** @class */ (function () {
|
|
341
|
-
function NgxsLoggerPlugin(_options, _injector) {
|
|
342
|
-
this._options = _options;
|
|
343
|
-
this._injector = _injector;
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* @param {?} state
|
|
347
|
-
* @param {?} event
|
|
348
|
-
* @param {?} next
|
|
349
|
-
* @return {?}
|
|
350
|
-
*/
|
|
351
|
-
NgxsLoggerPlugin.prototype.handle = /**
|
|
352
|
-
* @param {?} state
|
|
353
|
-
* @param {?} event
|
|
354
|
-
* @param {?} next
|
|
355
|
-
* @return {?}
|
|
356
|
-
*/
|
|
357
|
-
function (state, event, next) {
|
|
358
|
-
if (this._options.disabled || !(/** @type {?} */ (this._options.filter))(event, state)) {
|
|
359
|
-
return next(state, event);
|
|
360
|
-
}
|
|
361
|
-
this._logWriter = this._logWriter || new LogWriter(this._options);
|
|
362
|
-
// Retrieve lazily to avoid cyclic dependency exception
|
|
363
|
-
this._store = this._store || this._injector.get(Store);
|
|
364
|
-
/** @type {?} */
|
|
365
|
-
var actionLogger = new ActionLogger(event, this._store, this._logWriter);
|
|
366
|
-
actionLogger.dispatched(state);
|
|
367
|
-
return next(state, event).pipe(tap((/**
|
|
368
|
-
* @param {?} nextState
|
|
369
|
-
* @return {?}
|
|
370
|
-
*/
|
|
371
|
-
function (nextState) {
|
|
372
|
-
actionLogger.completed(nextState);
|
|
373
|
-
})), catchError((/**
|
|
374
|
-
* @param {?} error
|
|
375
|
-
* @return {?}
|
|
376
|
-
*/
|
|
377
|
-
function (error) {
|
|
378
|
-
actionLogger.errored(error);
|
|
379
|
-
throw error;
|
|
380
|
-
})));
|
|
381
|
-
};
|
|
382
|
-
NgxsLoggerPlugin.decorators = [
|
|
383
|
-
{ type: Injectable }
|
|
384
|
-
];
|
|
385
|
-
/** @nocollapse */
|
|
386
|
-
NgxsLoggerPlugin.ctorParameters = function () { return [
|
|
387
|
-
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_LOGGER_PLUGIN_OPTIONS,] }] },
|
|
388
|
-
{ type: Injector }
|
|
389
|
-
]; };
|
|
390
|
-
return NgxsLoggerPlugin;
|
|
391
|
-
}());
|
|
392
|
-
if (false) {
|
|
393
|
-
/**
|
|
394
|
-
* @type {?}
|
|
395
|
-
* @private
|
|
396
|
-
*/
|
|
397
|
-
NgxsLoggerPlugin.prototype._store;
|
|
398
|
-
/**
|
|
399
|
-
* @type {?}
|
|
400
|
-
* @private
|
|
401
|
-
*/
|
|
402
|
-
NgxsLoggerPlugin.prototype._logWriter;
|
|
403
|
-
/**
|
|
404
|
-
* @type {?}
|
|
405
|
-
* @private
|
|
406
|
-
*/
|
|
407
|
-
NgxsLoggerPlugin.prototype._options;
|
|
408
|
-
/**
|
|
409
|
-
* @type {?}
|
|
410
|
-
* @private
|
|
411
|
-
*/
|
|
412
|
-
NgxsLoggerPlugin.prototype._injector;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* @fileoverview added by tsickle
|
|
417
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
418
|
-
*/
|
|
419
|
-
/** @type {?} */
|
|
420
|
-
var USER_OPTIONS = new InjectionToken('LOGGER_USER_OPTIONS');
|
|
421
|
-
/**
|
|
422
|
-
* @param {?} options
|
|
423
|
-
* @return {?}
|
|
424
|
-
*/
|
|
425
|
-
function loggerOptionsFactory(options) {
|
|
426
|
-
/** @type {?} */
|
|
427
|
-
var defaultLoggerOptions = {
|
|
428
|
-
logger: console,
|
|
429
|
-
collapsed: false,
|
|
430
|
-
disabled: false,
|
|
431
|
-
filter: (/**
|
|
432
|
-
* @return {?}
|
|
433
|
-
*/
|
|
434
|
-
function () { return true; })
|
|
435
|
-
};
|
|
436
|
-
return __assign({}, defaultLoggerOptions, options);
|
|
437
|
-
}
|
|
438
|
-
var NgxsLoggerPluginModule = /** @class */ (function () {
|
|
439
|
-
function NgxsLoggerPluginModule() {
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* @param {?=} options
|
|
443
|
-
* @return {?}
|
|
444
|
-
*/
|
|
445
|
-
NgxsLoggerPluginModule.forRoot = /**
|
|
446
|
-
* @param {?=} options
|
|
447
|
-
* @return {?}
|
|
448
|
-
*/
|
|
449
|
-
function (options) {
|
|
450
|
-
return {
|
|
451
|
-
ngModule: NgxsLoggerPluginModule,
|
|
452
|
-
providers: [
|
|
453
|
-
{
|
|
454
|
-
provide: NGXS_PLUGINS,
|
|
455
|
-
useClass: NgxsLoggerPlugin,
|
|
456
|
-
multi: true
|
|
457
|
-
},
|
|
458
|
-
{
|
|
459
|
-
provide: USER_OPTIONS,
|
|
460
|
-
useValue: options
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
provide: NGXS_LOGGER_PLUGIN_OPTIONS,
|
|
464
|
-
useFactory: loggerOptionsFactory,
|
|
465
|
-
deps: [USER_OPTIONS]
|
|
466
|
-
}
|
|
467
|
-
]
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
NgxsLoggerPluginModule.decorators = [
|
|
471
|
-
{ type: NgModule }
|
|
472
|
-
];
|
|
473
|
-
return NgxsLoggerPluginModule;
|
|
474
|
-
}());
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* @fileoverview added by tsickle
|
|
478
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
479
|
-
*/
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* @fileoverview added by tsickle
|
|
483
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
484
|
-
*/
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* @fileoverview added by tsickle
|
|
488
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
489
|
-
*/
|
|
490
|
-
|
|
491
|
-
export { NGXS_LOGGER_PLUGIN_OPTIONS, NgxsLoggerPlugin, NgxsLoggerPluginModule, USER_OPTIONS as ɵa, loggerOptionsFactory as ɵb };
|
|
492
|
-
//# sourceMappingURL=ngxs-logger-plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-logger-plugin.js","sources":["ng://@ngxs/logger-plugin/src/internals.ts","ng://@ngxs/logger-plugin/src/action-logger.ts","ng://@ngxs/logger-plugin/src/log-writer.ts","ng://@ngxs/logger-plugin/src/symbols.ts","ng://@ngxs/logger-plugin/src/logger.plugin.ts","ng://@ngxs/logger-plugin/src/logger.module.ts"],"sourcesContent":["export const repeat = (str: string, times: number) => new Array(times + 1).join(str);\n\nexport const pad = (num: number, maxLength: number) =>\n repeat('0', maxLength - num.toString().length) + num;\n\nexport function formatTime(time: Date) {\n return (\n pad(time.getHours(), 2) +\n `:` +\n pad(time.getMinutes(), 2) +\n `:` +\n pad(time.getSeconds(), 2) +\n `.` +\n pad(time.getMilliseconds(), 3)\n );\n}\n","import { getActionTypeFromInstance, Store } from '@ngxs/store';\n\nimport { formatTime } from './internals';\nimport { LogWriter } from './log-writer';\n\nexport class ActionLogger {\n constructor(private action: any, private store: Store, private logWriter: LogWriter) {}\n\n dispatched(state: any) {\n const actionName = getActionTypeFromInstance(this.action);\n const formattedTime = formatTime(new Date());\n\n const message = `action ${actionName} @ ${formattedTime}`;\n this.logWriter.startGroup(message);\n\n // print payload only if at least one property is supplied\n if (this._hasPayload(this.action)) {\n this.logWriter.logGrey('payload', { ...this.action });\n }\n\n this.logWriter.logGrey('prev state', state);\n }\n\n completed(nextState: any) {\n this.logWriter.logGreen('next state', nextState);\n this.logWriter.endGroup();\n }\n\n errored(error: any) {\n this.logWriter.logRedish('next state after error', this.store.snapshot());\n this.logWriter.logRedish('error', error);\n this.logWriter.endGroup();\n }\n\n private _hasPayload(event: any) {\n const nonEmptyProperties = this._getNonEmptyProperties(event);\n return nonEmptyProperties.length > 0;\n }\n\n private _getNonEmptyProperties(event: any) {\n const keys = Object.keys(event);\n const values = keys.map(key => event[key]);\n return values.filter(value => value !== undefined);\n }\n}\n","import { NgxsLoggerPluginOptions } from './symbols';\nexport class LogWriter {\n private logger: any;\n\n constructor(private options: NgxsLoggerPluginOptions) {\n this.options = this.options || <any>{};\n this.logger = options.logger || console;\n }\n\n startGroup(message: string) {\n const startGroupFn = this.options.collapsed\n ? this.logger.groupCollapsed\n : this.logger.group;\n try {\n startGroupFn.call(this.logger, message);\n } catch (e) {\n console.log(message);\n }\n }\n\n endGroup() {\n try {\n this.logger.groupEnd();\n } catch (e) {\n this.logger.log('ââ log end ââ');\n }\n }\n\n logGrey(title: string, payload: any) {\n const greyStyle = 'color: #9E9E9E; font-weight: bold';\n this.log(title, greyStyle, payload);\n }\n\n logGreen(title: string, payload: any) {\n const greenStyle = 'color: #4CAF50; font-weight: bold';\n this.log(title, greenStyle, payload);\n }\n\n logRedish(title: string, payload: any) {\n const redishStyle = 'color: #FD8182; font-weight: bold';\n this.log(title, redishStyle, payload);\n }\n\n log(title: string, color: string, payload: any) {\n if (this.isIE()) {\n this.logger.log(title, payload);\n } else {\n this.logger.log('%c ' + title, color, payload);\n }\n }\n\n isIE(): boolean {\n const ua =\n typeof window !== 'undefined' && window.navigator.userAgent\n ? window.navigator.userAgent\n : '';\n let msIE = false;\n const oldIE = ua.indexOf('MSIE ');\n const newIE = ua.indexOf('Trident/');\n if (oldIE > -1 || newIE > -1) {\n msIE = true;\n }\n return msIE;\n }\n}\n","import { InjectionToken } from '@angular/core';\n\nexport interface NgxsLoggerPluginOptions {\n /** Auto expand logged actions */\n collapsed?: boolean;\n\n /** Provide alternate console.log implementation */\n logger?: any;\n\n /** Disable the logger. Useful for prod mode. */\n disabled?: boolean;\n\n /** Predicate for actions to be the logged. Takes action and state snapshot as parameters */\n filter?: (action: any, state: any) => boolean;\n}\n\nexport const NGXS_LOGGER_PLUGIN_OPTIONS = new InjectionToken('NGXS_LOGGER_PLUGIN_OPTIONS');\n","import { Inject, Injectable, Injector } from '@angular/core';\nimport { NgxsNextPluginFn, NgxsPlugin, Store } from '@ngxs/store';\nimport { catchError, tap } from 'rxjs/operators';\nimport { ActionLogger } from './action-logger';\nimport { LogWriter } from './log-writer';\nimport { NgxsLoggerPluginOptions, NGXS_LOGGER_PLUGIN_OPTIONS } from './symbols';\n\n@Injectable()\nexport class NgxsLoggerPlugin implements NgxsPlugin {\n private _store: Store;\n private _logWriter: LogWriter;\n\n constructor(\n @Inject(NGXS_LOGGER_PLUGIN_OPTIONS) private _options: NgxsLoggerPluginOptions,\n private _injector: Injector\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (this._options.disabled || !this._options.filter!(event, state)) {\n return next(state, event);\n }\n\n this._logWriter = this._logWriter || new LogWriter(this._options);\n // Retrieve lazily to avoid cyclic dependency exception\n this._store = this._store || this._injector.get<Store>(Store);\n\n const actionLogger = new ActionLogger(event, this._store, this._logWriter);\n\n actionLogger.dispatched(state);\n\n return next(state, event).pipe(\n tap(nextState => {\n actionLogger.completed(nextState);\n }),\n catchError(error => {\n actionLogger.errored(error);\n throw error;\n })\n );\n }\n}\n","import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';\nimport { NGXS_PLUGINS } from '@ngxs/store';\nimport { NgxsLoggerPlugin } from './logger.plugin';\nimport { NgxsLoggerPluginOptions, NGXS_LOGGER_PLUGIN_OPTIONS } from './symbols';\n\nexport const USER_OPTIONS = new InjectionToken('LOGGER_USER_OPTIONS');\n\nexport function loggerOptionsFactory(options: NgxsLoggerPluginOptions) {\n const defaultLoggerOptions: NgxsLoggerPluginOptions = {\n logger: console,\n collapsed: false,\n disabled: false,\n filter: () => true\n };\n\n return {\n ...defaultLoggerOptions,\n ...options\n };\n}\n\n@NgModule()\nexport class NgxsLoggerPluginModule {\n static forRoot(\n options?: NgxsLoggerPluginOptions\n ): ModuleWithProviders<NgxsLoggerPluginModule> {\n return {\n ngModule: NgxsLoggerPluginModule,\n providers: [\n {\n provide: NGXS_PLUGINS,\n useClass: NgxsLoggerPlugin,\n multi: true\n },\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_LOGGER_PLUGIN_OPTIONS,\n useFactory: loggerOptionsFactory,\n deps: [USER_OPTIONS]\n }\n ]\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA,IAAa,MAAM;;;;;AAAG,UAAC,GAAW,EAAE,KAAa,IAAK,OAAA,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAA,CAAA;;AAEpF,IAAa,GAAG;;;;;AAAG,UAAC,GAAW,EAAE,SAAiB;IAChD,OAAA,MAAM,CAAC,GAAG,EAAE,SAAS,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,GAAG;CAAA,CAAA;;;;;AAEtD,SAAgB,UAAU,CAAC,IAAU;IACnC,QACE,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACvB,GAAG;QACH,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACzB,GAAG;QACH,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACzB,GAAG;QACH,GA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UAAU;;;;gDAMN,MAAM,SAAC,0BAA0B;gBAbT,QAAQ;;IAwCrC,uBAAC;CAjCD,IAiCC;;;;;;IA/BC,kCAAsB;;;;;IACtB,sCAA8B;;;;;IAG5B,oCAA6E;;;;;IAC7E,qCAA2B;;;;;;;;ACT/B,IAAa,YAAY,GAAG,IAAI,cAAc,CAAC,qBAAqB,CAAC;;;;;AAErE,SAAgB,oBAAoB,CAAC,OAAgC;;QAC7D,oBAAoB,GAA4B;QACpD,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,KAAK;QACf,MAAM;;;QAAE,cAAM,OAAA,IAAI,GAAA,CAAA;KACnB;IAED,oBACK,oBAAoB,EACpB,OAAO,EACV;CACH;AAED;IAAA;KAyBC;;;;;IAvBQ,8BAAO;;;;IAAd,UACE,OAAiC;QAEjC,OAAO;YACL,QAAQ,EAAE,sBAAsB;YAChC,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,gBAAgB;oBAC1B,KAAK,EAAE,IAAI;iBACZ;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,0BAA0B;oBACnC,UAAU,EAAE,oBAAoB;oBAChC,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;aACF;SACF,CAAC;KACH;;gBAxBF,QAAQ;;IAyBT,6BAAC;CAzBD;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":5,"character":32},"arguments":["LOGGER_USER_OPTIONS"]},"ɵb":{"__symbolic":"function"},"NgxsLoggerPluginModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":21,"character":1}}],"members":{},"statics":{"forRoot":{"__symbolic":"function","parameters":["options"],"value":{"ngModule":{"__symbolic":"reference","name":"NgxsLoggerPluginModule"},"providers":[{"provide":{"__symbolic":"reference","module":"@ngxs/store","name":"NGXS_PLUGINS","line":30,"character":19},"useClass":{"__symbolic":"reference","name":"NgxsLoggerPlugin"},"multi":true},{"provide":{"__symbolic":"reference","name":"ɵa"},"useValue":{"__symbolic":"reference","name":"options"}},{"provide":{"__symbolic":"reference","name":"NGXS_LOGGER_PLUGIN_OPTIONS"},"useFactory":{"__symbolic":"reference","name":"ɵb"},"deps":[{"__symbolic":"reference","name":"ɵa"}]}]}}}},"NgxsLoggerPlugin":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":13,"character":5},"arguments":[{"__symbolic":"reference","name":"NGXS_LOGGER_PLUGIN_OPTIONS"}]}],null],"parameters":[{"__symbolic":"reference","name":"NgxsLoggerPluginOptions"},{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":14,"character":23}]}],"handle":[{"__symbolic":"method"}]}},"NgxsLoggerPluginOptions":{"__symbolic":"interface"},"NGXS_LOGGER_PLUGIN_OPTIONS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":16,"character":46},"arguments":["NGXS_LOGGER_PLUGIN_OPTIONS"]}},"origins":{"ɵa":"./src/logger.module","ɵb":"./src/logger.module","NgxsLoggerPluginModule":"./src/logger.module","NgxsLoggerPlugin":"./src/logger.plugin","NgxsLoggerPluginOptions":"./src/symbols","NGXS_LOGGER_PLUGIN_OPTIONS":"./src/symbols"},"importAs":"@ngxs/logger-plugin"}
|