@ngxs/logger-plugin 21.0.0-dev.master-cc2731d → 21.0.0-dev.master-416d6de
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.
|
@@ -150,7 +150,13 @@ function loggerOptionsFactory(options) {
|
|
|
150
150
|
...options
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* @deprecated Use `withNgxsLoggerPlugin()` instead.
|
|
155
|
+
*/
|
|
153
156
|
class NgxsLoggerPluginModule {
|
|
157
|
+
/**
|
|
158
|
+
* @deprecated Use `withNgxsLoggerPlugin()` instead.
|
|
159
|
+
*/
|
|
154
160
|
static forRoot(options) {
|
|
155
161
|
return {
|
|
156
162
|
ngModule: NgxsLoggerPluginModule,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-logger-plugin.mjs","sources":["../../../packages/logger-plugin/src/log-writer.ts","../../../packages/logger-plugin/src/internals.ts","../../../packages/logger-plugin/src/action-logger.ts","../../../packages/logger-plugin/src/symbols.ts","../../../packages/logger-plugin/src/logger.plugin.ts","../../../packages/logger-plugin/src/logger.module.ts","../../../packages/logger-plugin/index.ts","../../../packages/logger-plugin/ngxs-logger-plugin.ts"],"sourcesContent":["import { NgxsLoggerPluginOptions } from './symbols';\n\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 this.logger.log('%c ' + title, color, payload);\n }\n}\n","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 { Store } from '@ngxs/store';\nimport { getActionTypeFromInstance } from '@ngxs/store/plugins';\n\nimport { formatTime } from './internals';\nimport { LogWriter } from './log-writer';\n\nexport class ActionLogger {\n constructor(\n private action: any,\n private store: Store,\n private logWriter: LogWriter\n ) {}\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 { 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<NgxsLoggerPluginOptions>(\n 'NGXS_LOGGER_PLUGIN_OPTIONS'\n);\n","import { inject, Injectable, Injector, runInInjectionContext } from '@angular/core';\nimport { Store } from '@ngxs/store';\nimport { NgxsNextPluginFn, NgxsPlugin } from '@ngxs/store/plugins';\nimport { catchError, tap } from 'rxjs';\n\nimport { LogWriter } from './log-writer';\nimport { ActionLogger } from './action-logger';\nimport { NGXS_LOGGER_PLUGIN_OPTIONS } from './symbols';\n\n@Injectable()\nexport class NgxsLoggerPlugin implements NgxsPlugin {\n private _store!: Store;\n private _logWriter!: LogWriter;\n\n private _options = inject(NGXS_LOGGER_PLUGIN_OPTIONS);\n private _injector = inject(Injector);\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (this._options.disabled || this._skipLogging(state, event)) {\n return next(state, event);\n }\n\n this._logWriter ||= new LogWriter(this._options);\n // Retrieve lazily to avoid cyclic dependency exception\n this._store ||= this._injector.get(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 private _skipLogging(state: any, event: any) {\n // Run the `filter: () => ...` function within the injection context so\n // that the user can access the dependency injection and inject services\n // to retrieve properties. This will help determine whether or not to log the action.\n const allowLogging = runInInjectionContext(this._injector, () =>\n this._options.filter!(event, state)\n );\n\n return !allowLogging;\n }\n}\n","import {\n EnvironmentProviders,\n InjectionToken,\n ModuleWithProviders,\n NgModule,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { withNgxsPlugin } from '@ngxs/store';\n\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 withNgxsPlugin(NgxsLoggerPlugin),\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\nexport function withNgxsLoggerPlugin(options?: NgxsLoggerPluginOptions): EnvironmentProviders {\n return makeEnvironmentProviders([\n withNgxsPlugin(NgxsLoggerPlugin),\n { provide: USER_OPTIONS, useValue: options },\n {\n provide: NGXS_LOGGER_PLUGIN_OPTIONS,\n useFactory: loggerOptionsFactory,\n deps: [USER_OPTIONS]\n }\n ]);\n}\n","/**\n * The public api for consumers of @ngxs/logger-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAEa,SAAS,CAAA;AAGA,IAAA,OAAA;AAFZ,IAAA,MAAM;AAEd,IAAA,WAAA,CAAoB,OAAgC,EAAA;QAAhC,IAAO,CAAA,OAAA,GAAP,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAS,EAAE;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO;;AAGzC,IAAA,UAAU,CAAC,OAAe,EAAA;AACxB,QAAA,MAAM,YAAY,G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AAE,KAAK;AAChB,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,MAAM,EAAE,MAAM;KACf;IAED,OAAO;AACL,QAAA,GAAG,oBAAoB;AACvB,QAAA,GAAG;KACJ;AACH;MAGa,sBAAsB,CAAA;IACjC,OAAO,OAAO,CACZ,OAAiC,EAAA;QAEjC,OAAO;AACL,YAAA,QAAQ,EAAE,sBAAsB;AAChC,YAAA,SAAS,EAAE;gBACT,cAAc,CAAC,gBAAgB,CAAC;AAChC,gBAAA;AACE,oBAAA,OAAO,EAAE,YAAY;AACrB,oBAAA,QAAQ,EAAE;AACX,iBAAA;AACD,gBAAA;AACE,oBAAA,OAAO,EAAE,0BAA0B;AACnC,oBAAA,UAAU,EAAE,oBAAoB;oBAChC,IAAI,EAAE,CAAC,YAAY;AACpB;AACF;SACF;;0HAlBQ,sBAAsB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA;2HAAtB,sBAAsB,EAAA,CAAA;2HAAtB,sBAAsB,EAAA,CAAA;;2FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC;;AAuBK,SAAU,oBAAoB,CAAC,OAAiC,EAAA;AACpE,IAAA,OAAO,wBAAwB,CAAC;QAC9B,cAAc,CAAC,gBAAgB,CAAC;AAChC,QAAA,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC5C,QAAA;AACE,YAAA,OAAO,EAAE,0BAA0B;AACnC,YAAA,UAAU,EAAE,oBAAoB;YAChC,IAAI,EAAE,CAAC,YAAY;AACpB;AACF,KAAA,CAAC;AACJ;;AC7DA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngxs-logger-plugin.mjs","sources":["../../../packages/logger-plugin/src/log-writer.ts","../../../packages/logger-plugin/src/internals.ts","../../../packages/logger-plugin/src/action-logger.ts","../../../packages/logger-plugin/src/symbols.ts","../../../packages/logger-plugin/src/logger.plugin.ts","../../../packages/logger-plugin/src/logger.module.ts","../../../packages/logger-plugin/index.ts","../../../packages/logger-plugin/ngxs-logger-plugin.ts"],"sourcesContent":["import { NgxsLoggerPluginOptions } from './symbols';\n\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 this.logger.log('%c ' + title, color, payload);\n }\n}\n","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 { Store } from '@ngxs/store';\nimport { getActionTypeFromInstance } from '@ngxs/store/plugins';\n\nimport { formatTime } from './internals';\nimport { LogWriter } from './log-writer';\n\nexport class ActionLogger {\n constructor(\n private action: any,\n private store: Store,\n private logWriter: LogWriter\n ) {}\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 { 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<NgxsLoggerPluginOptions>(\n 'NGXS_LOGGER_PLUGIN_OPTIONS'\n);\n","import { inject, Injectable, Injector, runInInjectionContext } from '@angular/core';\nimport { Store } from '@ngxs/store';\nimport { NgxsNextPluginFn, NgxsPlugin } from '@ngxs/store/plugins';\nimport { catchError, tap } from 'rxjs';\n\nimport { LogWriter } from './log-writer';\nimport { ActionLogger } from './action-logger';\nimport { NGXS_LOGGER_PLUGIN_OPTIONS } from './symbols';\n\n@Injectable()\nexport class NgxsLoggerPlugin implements NgxsPlugin {\n private _store!: Store;\n private _logWriter!: LogWriter;\n\n private _options = inject(NGXS_LOGGER_PLUGIN_OPTIONS);\n private _injector = inject(Injector);\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (this._options.disabled || this._skipLogging(state, event)) {\n return next(state, event);\n }\n\n this._logWriter ||= new LogWriter(this._options);\n // Retrieve lazily to avoid cyclic dependency exception\n this._store ||= this._injector.get(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 private _skipLogging(state: any, event: any) {\n // Run the `filter: () => ...` function within the injection context so\n // that the user can access the dependency injection and inject services\n // to retrieve properties. This will help determine whether or not to log the action.\n const allowLogging = runInInjectionContext(this._injector, () =>\n this._options.filter!(event, state)\n );\n\n return !allowLogging;\n }\n}\n","import {\n EnvironmentProviders,\n InjectionToken,\n ModuleWithProviders,\n NgModule,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { withNgxsPlugin } from '@ngxs/store';\n\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/**\n * @deprecated Use `withNgxsLoggerPlugin()` instead.\n */\n@NgModule()\nexport class NgxsLoggerPluginModule {\n /**\n * @deprecated Use `withNgxsLoggerPlugin()` instead.\n */\n static forRoot(\n options?: NgxsLoggerPluginOptions\n ): ModuleWithProviders<NgxsLoggerPluginModule> {\n return {\n ngModule: NgxsLoggerPluginModule,\n providers: [\n withNgxsPlugin(NgxsLoggerPlugin),\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\nexport function withNgxsLoggerPlugin(options?: NgxsLoggerPluginOptions): EnvironmentProviders {\n return makeEnvironmentProviders([\n withNgxsPlugin(NgxsLoggerPlugin),\n { provide: USER_OPTIONS, useValue: options },\n {\n provide: NGXS_LOGGER_PLUGIN_OPTIONS,\n useFactory: loggerOptionsFactory,\n deps: [USER_OPTIONS]\n }\n ]);\n}\n","/**\n * The public api for consumers of @ngxs/logger-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAEa,SAAS,CAAA;AAGA,IAAA,OAAA;AAFZ,IAAA,MAAM;AAEd,IAAA,WAAA,CAAoB,OAAgC,EAAA;QAAhC,IAAO,CAAA,OAAA,GAAP,OAAO;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAS,EAAE;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO;;AAGzC,IAAA,UAAU,CAAC,OAAe,EAAA;AACxB,QAAA,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC;AAChC,cAAE,IAAI,CAAC,MAAM,CAAC;AACd,cAAE,IAAI,CAAC,MAAM,CAAC,KAAK;AACrB,QAAA,IAAI;YACF,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;;QACvC,OAAO,CAAC,EAAE;AACV,YAAA,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;;;IAIxB,QAAQ,GAAA;AACN,QAAA,IAAI;AACF,YAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;;QACtB,OAAO,CAAC,EAAE;AACV,YAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC;;;IAIpC,OAAO,CAAC,KAAa,EAAE,OAAY,EAAA;QACjC,MAAM,SAAS,GAAG,mCAAmC;QACrD,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;;IAGrC,QA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AAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA;2HAAtB,sBAAsB,EAAA,CAAA;2HAAtB,sBAAsB,EAAA,CAAA;;2FAAtB,sBAAsB,EAAA,UAAA,EAAA,CAAA;kBADlC;;AA0BK,SAAU,oBAAoB,CAAC,OAAiC,EAAA;AACpE,IAAA,OAAO,wBAAwB,CAAC;QAC9B,cAAc,CAAC,gBAAgB,CAAC;AAChC,QAAA,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;AAC5C,QAAA;AACE,YAAA,OAAO,EAAE,0BAA0B;AACnC,YAAA,UAAU,EAAE,oBAAoB;YAChC,IAAI,EAAE,CAAC,YAAY;AACpB;AACF,KAAA,CAAC;AACJ;;ACnEA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -14,7 +14,13 @@ interface NgxsLoggerPluginOptions {
|
|
|
14
14
|
}
|
|
15
15
|
declare const NGXS_LOGGER_PLUGIN_OPTIONS: InjectionToken<NgxsLoggerPluginOptions>;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use `withNgxsLoggerPlugin()` instead.
|
|
19
|
+
*/
|
|
17
20
|
declare class NgxsLoggerPluginModule {
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `withNgxsLoggerPlugin()` instead.
|
|
23
|
+
*/
|
|
18
24
|
static forRoot(options?: NgxsLoggerPluginOptions): ModuleWithProviders<NgxsLoggerPluginModule>;
|
|
19
25
|
static ɵfac: i0.ɵɵFactoryDeclaration<NgxsLoggerPluginModule, never>;
|
|
20
26
|
static ɵmod: i0.ɵɵNgModuleDeclaration<NgxsLoggerPluginModule, never, never, never>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngxs/logger-plugin",
|
|
3
3
|
"description": "logger plugin for @ngxs/store",
|
|
4
|
-
"version": "21.0.0-dev.master-
|
|
4
|
+
"version": "21.0.0-dev.master-416d6de",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@angular/core": ">=21.0.0 <22.0.0",
|
|
8
7
|
"@ngxs/store": "^21.0.0 || ^21.0.0-dev",
|
|
8
|
+
"@angular/core": ">=21.0.0 <22.0.0",
|
|
9
9
|
"rxjs": ">=7.0.0"
|
|
10
10
|
},
|
|
11
11
|
"module": "fesm2022/ngxs-logger-plugin.mjs",
|