@ngxs/storage-plugin 3.7.4-dev.master-b8320fc → 3.7.4-dev.master-817c422

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-storage-plugin.js","sources":["ng://@ngxs/storage-plugin/src/symbols.ts","ng://@ngxs/storage-plugin/src/internals.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals';\n\nexport const enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Key for the state slice to store in the storage engine.\n */\n key?: undefined | StorageKey;\n\n /**\n * Storage engine to use. Deaults to localStorage but can provide\n *\n * sessionStorage or custom implementation of the StorageEngine interface\n */\n storage?: StorageOption;\n\n /**\n * Migration strategies.\n */\n migrations?: {\n /**\n * Version to key off.\n */\n version: number | string;\n\n /**\n * Method to migrate the previous state.\n */\n migrate: (state: any) => any;\n\n /**\n * Key to migrate.\n */\n key?: string;\n\n /**\n * Key for the version. Defaults to 'version'.\n */\n versionKey?: string;\n }[];\n\n /**\n * Serailizer for the object before its pushed into the engine.\n */\n serialize?(obj: any): string;\n\n /**\n * Deserializer for the object before its pulled out of the engine.\n */\n deserialize?(obj: any): any;\n\n /**\n * Method to alter object before serialization.\n */\n beforeSerialize?(obj: any, key: string): any;\n\n /**\n * Method to alter object after deserialization.\n */\n afterDeserialize?(obj: any, key: string): any;\n}\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');\n\nexport const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');\n\nexport interface StorageEngine {\n readonly length: number;\n getItem(key: string): any;\n setItem(key: string, val: any): void;\n removeItem(key: string): void;\n clear(): void;\n}\n","import { isPlatformServer } from '@angular/common';\nimport { StateClass } from '@ngxs/store/internals';\nimport { StateToken } from '@ngxs/store';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * If the `key` option is not provided then the below constant\n * will be used as a default key\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\n/**\n * Internal type definition for the `key` option provided\n * in the `forRoot` method when importing module\n */\nexport type StorageKey =\n | string\n | StateClass\n | StateToken<any>\n | (string | StateClass | StateToken<any>)[];\n\n/**\n * This key is used to retrieve static metadatas on state classes.\n * This constant is taken from the core codebase\n */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n\nfunction transformKeyOption(key: StorageKey): string[] {\n if (!Array.isArray(key)) {\n key = [key];\n }\n\n return key.map((token: string | StateClass | StateToken<any>) => {\n // If it has the `NGXS_OPTIONS_META` key then it means the developer\n // has provided state class like `key: [AuthState]`.\n if (token.hasOwnProperty(META_OPTIONS_KEY)) {\n // The `name` property will be an actual state name or a `StateToken`.\n token = (token as any)[META_OPTIONS_KEY].name;\n }\n\n return token instanceof StateToken ? token.getName() : (token as string);\n });\n}\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\n if (options !== undefined && options.key) {\n options.key = transformKeyOption(options.key);\n }\n\n return {\n key: [DEFAULT_STATE_KEY],\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options\n };\n}\n\nexport function engineFactory(\n options: NgxsStoragePluginOptions,\n platformId: string\n): StorageEngine | null {\n if (isPlatformServer(platformId)) {\n return null;\n }\n\n if (options.storage === StorageOption.LocalStorage) {\n return localStorage;\n } else if (options.storage === StorageOption.SessionStorage) {\n return sessionStorage;\n }\n\n return null;\n}\n","import { PLATFORM_ID, Inject, Injectable } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n actionMatcher,\n NgxsNextPluginFn\n} from '@ngxs/store';\nimport { tap } from 'rxjs/operators';\n\nimport {\n StorageEngine,\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { DEFAULT_STATE_KEY } from './internals';\n\n/**\n * @description Will be provided through Terser global definitions by Angular CLI\n * during the production build. This is how Angular does tree-shaking internally.\n */\ndeclare const ngDevMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n constructor(\n @Inject(NGXS_STORAGE_PLUGIN_OPTIONS) private _options: NgxsStoragePluginOptions,\n @Inject(STORAGE_ENGINE) private _engine: StorageEngine,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId) && this._engine === null) {\n return next(state, event);\n }\n\n // We cast to `string[]` here as we're sure that this option has been\n // transformed by the `storageOptionsFactory` function that provided token\n const keys = this._options.key as string[];\n const matches = actionMatcher(event);\n const isInitAction = matches(InitState);\n const isUpdateAction = matches(UpdateState);\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n for (const key of keys) {\n // We're checking what states have been added by NGXS and if any of these states should be handled by\n // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added\n // the `user` state, the storage plugin will be rerun and will do redundant deserialization.\n if (isUpdateAction && event.addedStates && !event.addedStates.hasOwnProperty(key)) {\n continue;\n }\n\n const isMaster = key === DEFAULT_STATE_KEY;\n let val: any = this._engine.getItem(key!);\n\n if (val !== 'undefined' && val != null) {\n try {\n const newVal = this._options.deserialize!(val);\n val = this._options.afterDeserialize!(newVal, key);\n } catch (e) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n console.error(\n `Error ocurred while deserializing the ${key} store value, falling back to empty object, the value obtained from the store: `,\n val\n );\n }\n val = {};\n }\n\n if (this._options.migrations) {\n this._options.migrations.forEach(strategy => {\n const versionMatch =\n strategy.version === getValue(val, strategy.versionKey || 'version');\n const keyMatch = (!strategy.key && isMaster) || strategy.key === key;\n if (versionMatch && keyMatch) {\n val = strategy.migrate(val);\n hasMigration = true;\n }\n });\n }\n\n if (!isMaster) {\n state = setValue(state, key!, val);\n } else {\n state = { ...state, ...val };\n }\n }\n }\n }\n\n return next(state, event).pipe(\n tap(nextState => {\n if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {\n for (const key of keys) {\n let val = nextState;\n\n if (key !== DEFAULT_STATE_KEY) {\n val = getValue(nextState, key!);\n }\n\n try {\n const newVal = this._options.beforeSerialize!(val, key);\n this._engine.setItem(key!, this._options.serialize!(newVal));\n } catch (error) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n if (\n error &&\n (error.name === 'QuotaExceededError' ||\n error.name === 'NS_ERROR_DOM_QUOTA_REACHED')\n ) {\n console.error(\n `The ${key} store value exceeds the browser storage quota: `,\n val\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${key} store value, value not updated, the value obtained from the store: `,\n val\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n","import { NgModule, ModuleWithProviders, PLATFORM_ID, InjectionToken } from '@angular/core';\nimport { NGXS_PLUGINS } from '@ngxs/store';\n\nimport {\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { storageOptionsFactory, engineFactory } from './internals';\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsStoragePluginModule {\n static forRoot(\n options?: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\n {\n provide: NGXS_PLUGINS,\n useClass: NgxsStoragePlugin,\n multi: true\n },\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: storageOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: STORAGE_ENGINE,\n useFactory: engineFactory,\n deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]\n }\n ]\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAyDC;;;;;;IArDC,uCAA6B;;;;;;;IAO7B,2CAAwB;;;;;IAKxB,8CAoBI;;;;;;IAKJ,kEAA6B;;;;;;IAK7B,oEAA4B;;;;;;;IAK5B,6EAA6C;;;;;;;IAK7C,8EAA8C;;;AAGhD,MAAa,2BAA2B,GAAG,IAAI,cAAc,CAAC,4BAA4B,CAAC;;AAE3F,MAAa,cAAc,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC;;;;AAElE,4BAMC;;;IALC,+BAAwB;;;;;IACxB,qDAA0B;;;;;;IAC1B,0DAAqC;;;;;IACrC,wDAA8B;;;;IAC9B,gDAAc;;;;;;;AC7EhB;;;;;AAUA,MAAa,iBAAiB,GAAG,SAAS;;;;;;MAgBpC,gBAAgB,GAAG,mBAAmB;;;;;AAE5C,SAAS,kBAAkB,CAAC,GAAe;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;KACb;IAED,OAAO,GAAG,CAAC,GAAG;;;;IAAC,CAAC,KAA4C;;;QAG1D,IAAI,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE;;YAE1C,KAAK,GAAG,oBAAC,KAAK,IAAS,gBAAgB,CAAC,CAAC,IAAI,CAAC;SAC/C;QAED,OAAO,KAAK,YAAY,UAAU,GAAG,KAAK,CAAC,OAAO,E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EAC5D,GAAG,CACJ,CAAC;6BACH;iCAAM;gCACL,OAAO,CAAC,KAAK,CACX,uCAAuC,GAAG,sEAAsE,EAChH,GAAG,CACJ,CAAC;6BACH;yBACF;qBACF;iBACF;aACF;SACF,EAAC,CACH,CAAC;KACH;;;YA7GF,UAAU;;;;4CAGN,MAAM,SAAC,2BAA2B;4CAClC,MAAM,SAAC,cAAc;yCACrB,MAAM,SAAC,WAAW;;;;;;;IAFnB,qCAA+E;;;;;IAC/E,oCAAsD;;;;;IACtD,wCAAgD;;;;;;;AChCpD;AAWA,MAAa,YAAY,GAAG,IAAI,cAAc,CAAC,cAAc,CAAC;AAG9D,MAAa,uBAAuB;;;;;IAClC,OAAO,OAAO,CACZ,OAAkC;QAElC,OAAO;YACL,QAAQ,EAAE,uBAAuB;YACjC,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,iBAAiB;oBAC3B,KAAK,EAAE,IAAI;iBACZ;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,2BAA2B;oBACpC,UAAU,EAAE,qBAAqB;oBACjC,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;gBACD;oBACE,OAAO,EAAE,cAAc;oBACvB,UAAU,EAAE,aAAa;oBACzB,IAAI,EAAE,CAAC,2BAA2B,EAAE,WAAW,CAAC;iBACjD;aACF;SACF,CAAC;KACH;;;YA7BF,QAAQ;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ngxs-storage-plugin.js","sources":["ng://@ngxs/storage-plugin/src/symbols.ts","ng://@ngxs/storage-plugin/src/internals.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals';\n\nexport const enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Key for the state slice to store in the storage engine.\n */\n key?: undefined | StorageKey;\n\n /**\n * Storage engine to use. Deaults to localStorage but can provide\n *\n * sessionStorage or custom implementation of the StorageEngine interface\n */\n storage?: StorageOption;\n\n /**\n * Migration strategies.\n */\n migrations?: {\n /**\n * Version to key off.\n */\n version: number | string;\n\n /**\n * Method to migrate the previous state.\n */\n migrate: (state: any) => any;\n\n /**\n * Key to migrate.\n */\n key?: string;\n\n /**\n * Key for the version. Defaults to 'version'.\n */\n versionKey?: string;\n }[];\n\n /**\n * Serailizer for the object before its pushed into the engine.\n */\n serialize?(obj: any): string;\n\n /**\n * Deserializer for the object before its pulled out of the engine.\n */\n deserialize?(obj: any): any;\n\n /**\n * Method to alter object before serialization.\n */\n beforeSerialize?(obj: any, key: string): any;\n\n /**\n * Method to alter object after deserialization.\n */\n afterDeserialize?(obj: any, key: string): any;\n}\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');\n\nexport const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');\n\nexport interface StorageEngine {\n readonly length: number;\n getItem(key: string): any;\n setItem(key: string, val: any): void;\n removeItem(key: string): void;\n clear(): void;\n}\n","import { isPlatformServer } from '@angular/common';\nimport { StateClass } from '@ngxs/store/internals';\nimport { StateToken } from '@ngxs/store';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * If the `key` option is not provided then the below constant\n * will be used as a default key\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\n/**\n * Internal type definition for the `key` option provided\n * in the `forRoot` method when importing module\n */\nexport type StorageKey =\n | string\n | StateClass\n | StateToken<any>\n | (string | StateClass | StateToken<any>)[];\n\n/**\n * This key is used to retrieve static metadatas on state classes.\n * This constant is taken from the core codebase\n */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n\nfunction transformKeyOption(key: StorageKey): string[] {\n if (!Array.isArray(key)) {\n key = [key];\n }\n\n return key.map((token: string | StateClass | StateToken<any>) => {\n // If it has the `NGXS_OPTIONS_META` key then it means the developer\n // has provided state class like `key: [AuthState]`.\n if (token.hasOwnProperty(META_OPTIONS_KEY)) {\n // The `name` property will be an actual state name or a `StateToken`.\n token = (token as any)[META_OPTIONS_KEY].name;\n }\n\n return token instanceof StateToken ? token.getName() : (token as string);\n });\n}\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\n if (options !== undefined && options.key) {\n options.key = transformKeyOption(options.key);\n }\n\n return {\n key: [DEFAULT_STATE_KEY],\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options\n };\n}\n\nexport function engineFactory(\n options: NgxsStoragePluginOptions,\n platformId: string\n): StorageEngine | null {\n if (isPlatformServer(platformId)) {\n return null;\n }\n\n if (options.storage === StorageOption.LocalStorage) {\n return localStorage;\n } else if (options.storage === StorageOption.SessionStorage) {\n return sessionStorage;\n }\n\n return null;\n}\n","import { PLATFORM_ID, Inject, Injectable } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport { PlainObject } from '@ngxs/store/internals';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n actionMatcher,\n NgxsNextPluginFn\n} from '@ngxs/store';\nimport { tap } from 'rxjs/operators';\n\nimport {\n StorageEngine,\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { DEFAULT_STATE_KEY } from './internals';\n\n/**\n * @description Will be provided through Terser global definitions by Angular CLI\n * during the production build. This is how Angular does tree-shaking internally.\n */\ndeclare const ngDevMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n // We cast to `string[]` here as we're sure that this option has been\n // transformed by the `storageOptionsFactory` function that provided token.\n private _keys = this._options.key as string[];\n // We default to `[DEFAULT_STATE_KEY]` if the user explicitly does not provide the `key` option.\n private _usesDefaultStateKey =\n this._keys.length === 1 && this._keys[0] === DEFAULT_STATE_KEY;\n\n constructor(\n @Inject(NGXS_STORAGE_PLUGIN_OPTIONS) private _options: NgxsStoragePluginOptions,\n @Inject(STORAGE_ENGINE) private _engine: StorageEngine,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId) && this._engine === null) {\n return next(state, event);\n }\n\n const matches = actionMatcher(event);\n const isInitAction = matches(InitState);\n const isUpdateAction = matches(UpdateState);\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n const addedStates = isUpdateAction && event.addedStates;\n\n for (const key of this._keys) {\n // We're checking what states have been added by NGXS and if any of these states should be handled by\n // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added\n // the `user` state, the storage plugin will be rerun and will do redundant deserialization.\n // `usesDefaultStateKey` is necessary to check since `event.addedStates` never contains `@@STATE`.\n if (!this._usesDefaultStateKey && addedStates && !addedStates.hasOwnProperty(key)) {\n continue;\n }\n\n let storedValue: any = this._engine.getItem(key!);\n\n if (storedValue !== 'undefined' && storedValue != null) {\n try {\n const newVal = this._options.deserialize!(storedValue);\n storedValue = this._options.afterDeserialize!(newVal, key);\n } catch {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n console.error(\n `Error ocurred while deserializing the ${key} store value, falling back to empty object, the value obtained from the store: `,\n storedValue\n );\n }\n storedValue = {};\n }\n\n if (this._options.migrations) {\n this._options.migrations.forEach(strategy => {\n const versionMatch =\n strategy.version === getValue(storedValue, strategy.versionKey || 'version');\n const keyMatch =\n (!strategy.key && this._usesDefaultStateKey) || strategy.key === key;\n if (versionMatch && keyMatch) {\n storedValue = strategy.migrate(storedValue);\n hasMigration = true;\n }\n });\n }\n\n if (!this._usesDefaultStateKey) {\n state = setValue(state, key!, storedValue);\n } else {\n // The `UpdateState` action is dispatched whenever the feature state is added.\n // The below condition is met only when the `UpdateState` is dispatched.\n // Let's assume that we have 2 states `counter` and `@ngxs/router-plugin` state.\n // `CounterState` is provided on the root level when calling `NgxsModule.forRoot()`\n // and `@ngxs/router-plugin` is provided as a feature state.\n // The storage plugin may save the `counter` state value as `10` before.\n // The `CounterState` may implement the `ngxsOnInit` hook and call `ctx.setState(999)`.\n // The storage plugin will re-hydrate the whole state when the `RouterState` is registered,\n // and the `counter` state will again equal `10` (not `999`).\n if (storedValue && addedStates && Object.keys(addedStates).length > 0) {\n storedValue = Object.keys(addedStates).reduce((accumulator, addedState) => {\n // The `storedValue` may equal the whole state (when the default state key is used).\n // If `addedStates` contains only `router` then we want to merge the state only\n // with the `router` value.\n // Let's assume that the `storedValue` is an object:\n // `{ counter: 10, router: {...} }`\n // This will pick only the `router` object from the `storedValue` and `counter`\n // state will not be re-hydrated unnecessary.\n if (storedValue.hasOwnProperty(addedState)) {\n accumulator[addedState] = storedValue[addedState];\n }\n return accumulator;\n }, <PlainObject>{});\n }\n\n state = { ...state, ...storedValue };\n }\n }\n }\n }\n\n return next(state, event).pipe(\n tap(nextState => {\n if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {\n for (const key of this._keys) {\n let val = nextState;\n\n if (key !== DEFAULT_STATE_KEY) {\n val = getValue(nextState, key!);\n }\n\n try {\n const newVal = this._options.beforeSerialize!(val, key);\n this._engine.setItem(key!, this._options.serialize!(newVal));\n } catch (error) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n if (\n error &&\n (error.name === 'QuotaExceededError' ||\n error.name === 'NS_ERROR_DOM_QUOTA_REACHED')\n ) {\n console.error(\n `The ${key} store value exceeds the browser storage quota: `,\n val\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${key} store value, value not updated, the value obtained from the store: `,\n val\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n","import { NgModule, ModuleWithProviders, PLATFORM_ID, InjectionToken } from '@angular/core';\nimport { NGXS_PLUGINS } from '@ngxs/store';\n\nimport {\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { storageOptionsFactory, engineFactory } from './internals';\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsStoragePluginModule {\n static forRoot(\n options?: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\n {\n provide: NGXS_PLUGINS,\n useClass: NgxsStoragePlugin,\n multi: true\n },\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: storageOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: STORAGE_ENGINE,\n useFactory: engineFactory,\n deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]\n }\n ]\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAyDC;;;;;;IArDC,uCAA6B;;;;;;;IAO7B,2CAAwB;;;;;IAKxB,8CAoBI;;;;;;IAKJ,kEAA6B;;;;;;IAK7B,oEAA4B;;;;;;;IAK5B,6EAA6C;;;;;;;IAK7C,8EAA8C;;;AAGhD,MAAa,2BAA2B,GAAG,IAAI,cAAc,CAAC,4BAA4B,CAAC;;AAE3F,MAAa,cAAc,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC;;;;AAElE,4BAMC;;;IALC,+BAAwB;;;;;IACxB,qDAA0B;;;;;;IAC1B,0DAAqC;;;;;IACrC,wDAA8B;;;;IAC9B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BACF;aACF;SACF,EAAC,CACH,CAAC;KACH;;;YA7IF,UAAU;;;;4CAUN,MAAM,SAAC,2BAA2B;4CAClC,MAAM,SAAC,cAAc;yCACrB,MAAM,SAAC,WAAW;;;;;;;IARrB,kCAA8C;;;;;IAE9C,iDACiE;;;;;IAG/D,qCAA+E;;;;;IAC/E,oCAAsD;;;;;IACtD,wCAAgD;;;;;;;ACxCpD;AAWA,MAAa,YAAY,GAAG,IAAI,cAAc,CAAC,cAAc,CAAC;AAG9D,MAAa,uBAAuB;;;;;IAClC,OAAO,OAAO,CACZ,OAAkC;QAElC,OAAO;YACL,QAAQ,EAAE,uBAAuB;YACjC,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,iBAAiB;oBAC3B,KAAK,EAAE,IAAI;iBACZ;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,2BAA2B;oBACpC,UAAU,EAAE,qBAAqB;oBACjC,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;gBACD;oBACE,OAAO,EAAE,cAAc;oBACvB,UAAU,EAAE,aAAa;oBACzB,IAAI,EAAE,CAAC,2BAA2B,EAAE,WAAW,CAAC;iBACjD;aACF;SACF,CAAC;KACH;;;YA7BF,QAAQ;;;;;;;;;;;;;;;;;;;;"}
@@ -178,6 +178,11 @@ var NgxsStoragePlugin = /** @class */ (function () {
178
178
  this._options = _options;
179
179
  this._engine = _engine;
180
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;
181
186
  }
182
187
  /**
183
188
  * @param {?} state
@@ -197,10 +202,6 @@ var NgxsStoragePlugin = /** @class */ (function () {
197
202
  if (isPlatformServer(this._platformId) && this._engine === null) {
198
203
  return next(state, event);
199
204
  }
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
205
  /** @type {?} */
205
206
  var matches = actionMatcher(event);
206
207
  /** @type {?} */
@@ -212,30 +213,31 @@ var NgxsStoragePlugin = /** @class */ (function () {
212
213
  /** @type {?} */
213
214
  var hasMigration = false;
214
215
  if (isInitOrUpdateAction) {
216
+ /** @type {?} */
217
+ var addedStates = isUpdateAction && event.addedStates;
215
218
  var _loop_1 = function (key) {
216
219
  // We're checking what states have been added by NGXS and if any of these states should be handled by
217
220
  // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added
218
221
  // the `user` state, the storage plugin will be rerun and will do redundant deserialization.
219
- if (isUpdateAction && event.addedStates && !event.addedStates.hasOwnProperty(key)) {
222
+ // `usesDefaultStateKey` is necessary to check since `event.addedStates` never contains `@@STATE`.
223
+ if (!this_1._usesDefaultStateKey && addedStates && !addedStates.hasOwnProperty(key)) {
220
224
  return "continue";
221
225
  }
222
226
  /** @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
+ var storedValue = this_1._engine.getItem((/** @type {?} */ (key)));
228
+ if (storedValue !== 'undefined' && storedValue != null) {
227
229
  try {
228
230
  /** @type {?} */
229
- var newVal = (/** @type {?} */ (this_1._options.deserialize))(val);
230
- val = (/** @type {?} */ (this_1._options.afterDeserialize))(newVal, key);
231
+ var newVal = (/** @type {?} */ (this_1._options.deserialize))(storedValue);
232
+ storedValue = (/** @type {?} */ (this_1._options.afterDeserialize))(newVal, key);
231
233
  }
232
- catch (e) {
234
+ catch (_a) {
233
235
  // Caretaker note: we have still left the `typeof` condition in order to avoid
234
236
  // creating a breaking change for projects that still use the View Engine.
235
237
  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);
238
+ console.error("Error ocurred while deserializing the " + key + " store value, falling back to empty object, the value obtained from the store: ", storedValue);
237
239
  }
238
- val = {};
240
+ storedValue = {};
239
241
  }
240
242
  if (this_1._options.migrations) {
241
243
  this_1._options.migrations.forEach((/**
@@ -244,34 +246,63 @@ var NgxsStoragePlugin = /** @class */ (function () {
244
246
  */
245
247
  function (strategy) {
246
248
  /** @type {?} */
247
- var versionMatch = strategy.version === getValue(val, strategy.versionKey || 'version');
249
+ var versionMatch = strategy.version === getValue(storedValue, strategy.versionKey || 'version');
248
250
  /** @type {?} */
249
- var keyMatch = (!strategy.key && isMaster) || strategy.key === key;
251
+ var keyMatch = (!strategy.key && _this._usesDefaultStateKey) || strategy.key === key;
250
252
  if (versionMatch && keyMatch) {
251
- val = strategy.migrate(val);
253
+ storedValue = strategy.migrate(storedValue);
252
254
  hasMigration = true;
253
255
  }
254
256
  }));
255
257
  }
256
- if (!isMaster) {
257
- state = setValue(state, (/** @type {?} */ (key)), val);
258
+ if (!this_1._usesDefaultStateKey) {
259
+ state = setValue(state, (/** @type {?} */ (key)), storedValue);
258
260
  }
259
261
  else {
260
- state = __assign({}, state, val);
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);
261
292
  }
262
293
  }
263
294
  };
264
295
  var this_1 = this;
265
296
  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;
297
+ for (var _b = __values(this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
298
+ var key = _c.value;
268
299
  _loop_1(key);
269
300
  }
270
301
  }
271
302
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
272
303
  finally {
273
304
  try {
274
- if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
305
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
275
306
  }
276
307
  finally { if (e_1) throw e_1.error; }
277
308
  }
@@ -284,8 +315,8 @@ var NgxsStoragePlugin = /** @class */ (function () {
284
315
  var e_2, _a;
285
316
  if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
286
317
  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;
318
+ for (var _b = __values(_this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
319
+ var key = _c.value;
289
320
  /** @type {?} */
290
321
  var val = nextState;
291
322
  if (key !== DEFAULT_STATE_KEY) {
@@ -315,7 +346,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
315
346
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
316
347
  finally {
317
348
  try {
318
- if (keys_2_1 && !keys_2_1.done && (_a = keys_2.return)) _a.call(keys_2);
349
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
319
350
  }
320
351
  finally { if (e_2) throw e_2.error; }
321
352
  }
@@ -334,6 +365,16 @@ var NgxsStoragePlugin = /** @class */ (function () {
334
365
  return NgxsStoragePlugin;
335
366
  }());
336
367
  if (false) {
368
+ /**
369
+ * @type {?}
370
+ * @private
371
+ */
372
+ NgxsStoragePlugin.prototype._keys;
373
+ /**
374
+ * @type {?}
375
+ * @private
376
+ */
377
+ NgxsStoragePlugin.prototype._usesDefaultStateKey;
337
378
  /**
338
379
  * @type {?}
339
380
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-storage-plugin.js","sources":["ng://@ngxs/storage-plugin/src/symbols.ts","ng://@ngxs/storage-plugin/src/internals.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals';\n\nexport const enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Key for the state slice to store in the storage engine.\n */\n key?: undefined | StorageKey;\n\n /**\n * Storage engine to use. Deaults to localStorage but can provide\n *\n * sessionStorage or custom implementation of the StorageEngine interface\n */\n storage?: StorageOption;\n\n /**\n * Migration strategies.\n */\n migrations?: {\n /**\n * Version to key off.\n */\n version: number | string;\n\n /**\n * Method to migrate the previous state.\n */\n migrate: (state: any) => any;\n\n /**\n * Key to migrate.\n */\n key?: string;\n\n /**\n * Key for the version. Defaults to 'version'.\n */\n versionKey?: string;\n }[];\n\n /**\n * Serailizer for the object before its pushed into the engine.\n */\n serialize?(obj: any): string;\n\n /**\n * Deserializer for the object before its pulled out of the engine.\n */\n deserialize?(obj: any): any;\n\n /**\n * Method to alter object before serialization.\n */\n beforeSerialize?(obj: any, key: string): any;\n\n /**\n * Method to alter object after deserialization.\n */\n afterDeserialize?(obj: any, key: string): any;\n}\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');\n\nexport const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');\n\nexport interface StorageEngine {\n readonly length: number;\n getItem(key: string): any;\n setItem(key: string, val: any): void;\n removeItem(key: string): void;\n clear(): void;\n}\n","import { isPlatformServer } from '@angular/common';\nimport { StateClass } from '@ngxs/store/internals';\nimport { StateToken } from '@ngxs/store';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * If the `key` option is not provided then the below constant\n * will be used as a default key\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\n/**\n * Internal type definition for the `key` option provided\n * in the `forRoot` method when importing module\n */\nexport type StorageKey =\n | string\n | StateClass\n | StateToken<any>\n | (string | StateClass | StateToken<any>)[];\n\n/**\n * This key is used to retrieve static metadatas on state classes.\n * This constant is taken from the core codebase\n */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n\nfunction transformKeyOption(key: StorageKey): string[] {\n if (!Array.isArray(key)) {\n key = [key];\n }\n\n return key.map((token: string | StateClass | StateToken<any>) => {\n // If it has the `NGXS_OPTIONS_META` key then it means the developer\n // has provided state class like `key: [AuthState]`.\n if (token.hasOwnProperty(META_OPTIONS_KEY)) {\n // The `name` property will be an actual state name or a `StateToken`.\n token = (token as any)[META_OPTIONS_KEY].name;\n }\n\n return token instanceof StateToken ? token.getName() : (token as string);\n });\n}\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\n if (options !== undefined && options.key) {\n options.key = transformKeyOption(options.key);\n }\n\n return {\n key: [DEFAULT_STATE_KEY],\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options\n };\n}\n\nexport function engineFactory(\n options: NgxsStoragePluginOptions,\n platformId: string\n): StorageEngine | null {\n if (isPlatformServer(platformId)) {\n return null;\n }\n\n if (options.storage === StorageOption.LocalStorage) {\n return localStorage;\n } else if (options.storage === StorageOption.SessionStorage) {\n return sessionStorage;\n }\n\n return null;\n}\n","import { PLATFORM_ID, Inject, Injectable } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n actionMatcher,\n NgxsNextPluginFn\n} from '@ngxs/store';\nimport { tap } from 'rxjs/operators';\n\nimport {\n StorageEngine,\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { DEFAULT_STATE_KEY } from './internals';\n\n/**\n * @description Will be provided through Terser global definitions by Angular CLI\n * during the production build. This is how Angular does tree-shaking internally.\n */\ndeclare const ngDevMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n constructor(\n @Inject(NGXS_STORAGE_PLUGIN_OPTIONS) private _options: NgxsStoragePluginOptions,\n @Inject(STORAGE_ENGINE) private _engine: StorageEngine,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId) && this._engine === null) {\n return next(state, event);\n }\n\n // We cast to `string[]` here as we're sure that this option has been\n // transformed by the `storageOptionsFactory` function that provided token\n const keys = this._options.key as string[];\n const matches = actionMatcher(event);\n const isInitAction = matches(InitState);\n const isUpdateAction = matches(UpdateState);\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n for (const key of keys) {\n // We're checking what states have been added by NGXS and if any of these states should be handled by\n // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added\n // the `user` state, the storage plugin will be rerun and will do redundant deserialization.\n if (isUpdateAction && event.addedStates && !event.addedStates.hasOwnProperty(key)) {\n continue;\n }\n\n const isMaster = key === DEFAULT_STATE_KEY;\n let val: any = this._engine.getItem(key!);\n\n if (val !== 'undefined' && val != null) {\n try {\n const newVal = this._options.deserialize!(val);\n val = this._options.afterDeserialize!(newVal, key);\n } catch (e) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n console.error(\n `Error ocurred while deserializing the ${key} store value, falling back to empty object, the value obtained from the store: `,\n val\n );\n }\n val = {};\n }\n\n if (this._options.migrations) {\n this._options.migrations.forEach(strategy => {\n const versionMatch =\n strategy.version === getValue(val, strategy.versionKey || 'version');\n const keyMatch = (!strategy.key && isMaster) || strategy.key === key;\n if (versionMatch && keyMatch) {\n val = strategy.migrate(val);\n hasMigration = true;\n }\n });\n }\n\n if (!isMaster) {\n state = setValue(state, key!, val);\n } else {\n state = { ...state, ...val };\n }\n }\n }\n }\n\n return next(state, event).pipe(\n tap(nextState => {\n if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {\n for (const key of keys) {\n let val = nextState;\n\n if (key !== DEFAULT_STATE_KEY) {\n val = getValue(nextState, key!);\n }\n\n try {\n const newVal = this._options.beforeSerialize!(val, key);\n this._engine.setItem(key!, this._options.serialize!(newVal));\n } catch (error) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n if (\n error &&\n (error.name === 'QuotaExceededError' ||\n error.name === 'NS_ERROR_DOM_QUOTA_REACHED')\n ) {\n console.error(\n `The ${key} store value exceeds the browser storage quota: `,\n val\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${key} store value, value not updated, the value obtained from the store: `,\n val\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n","import { NgModule, ModuleWithProviders, PLATFORM_ID, InjectionToken } from '@angular/core';\nimport { NGXS_PLUGINS } from '@ngxs/store';\n\nimport {\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { storageOptionsFactory, engineFactory } from './internals';\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsStoragePluginModule {\n static forRoot(\n options?: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\n {\n provide: NGXS_PLUGINS,\n useClass: NgxsStoragePlugin,\n multi: true\n },\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: storageOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: STORAGE_ENGINE,\n useFactory: engineFactory,\n deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]\n }\n ]\n };\n }\n}\n"],"names":["tslib_1.__values"],"mappings":";;;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAyDC;;;;;;IArDC,uCAA6B;;;;;;;IAO7B,2CAAwB;;;;;IAKxB,8CAoBI;;;;;;IAKJ,kEAA6B;;;;;;IAK7B,oEAA4B;;;;;;;IAK5B,6EAA6C;;;;;;;IAK7C,8EAA8C;;;AAGhD,IAAa,2BAA2B,GAAG,IAAI,cAAc,CAAC,4BAA4B,CAAC;;AAE3F,IAAa,cAAc,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC;;;;AAElE,4BAMC;;;IALC,+BAAwB;;;;;IACxB,qDAA0B;;;;;;IAC1B,0DAAqC;;;;;IACrC,wDAA8B;;;;IAC9B,gDAAc;;;;;;;;;;;;ACnEhB,IAAa,iBAAiB,GAAG,SAAS;;;;;;IAgBpC,gBAAgB,GAAG,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Q,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,2BAA2B;oBACpC,UAAU,EAAE,qBAAqB;oBACjC,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;gBACD;oBACE,OAAO,EAAE,cAAc;oBACvB,UAAU,EAAE,aAAa;oBACzB,IAAI,EAAE,CAAC,2BAA2B,EAAE,WAAW,CAAC;iBACjD;aACF;SACF,CAAC;KACH;;gBA7BF,QAAQ;;IA8BT,8BAAC;CA9BD;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ngxs-storage-plugin.js","sources":["ng://@ngxs/storage-plugin/src/symbols.ts","ng://@ngxs/storage-plugin/src/internals.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals';\n\nexport const enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Key for the state slice to store in the storage engine.\n */\n key?: undefined | StorageKey;\n\n /**\n * Storage engine to use. Deaults to localStorage but can provide\n *\n * sessionStorage or custom implementation of the StorageEngine interface\n */\n storage?: StorageOption;\n\n /**\n * Migration strategies.\n */\n migrations?: {\n /**\n * Version to key off.\n */\n version: number | string;\n\n /**\n * Method to migrate the previous state.\n */\n migrate: (state: any) => any;\n\n /**\n * Key to migrate.\n */\n key?: string;\n\n /**\n * Key for the version. Defaults to 'version'.\n */\n versionKey?: string;\n }[];\n\n /**\n * Serailizer for the object before its pushed into the engine.\n */\n serialize?(obj: any): string;\n\n /**\n * Deserializer for the object before its pulled out of the engine.\n */\n deserialize?(obj: any): any;\n\n /**\n * Method to alter object before serialization.\n */\n beforeSerialize?(obj: any, key: string): any;\n\n /**\n * Method to alter object after deserialization.\n */\n afterDeserialize?(obj: any, key: string): any;\n}\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');\n\nexport const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');\n\nexport interface StorageEngine {\n readonly length: number;\n getItem(key: string): any;\n setItem(key: string, val: any): void;\n removeItem(key: string): void;\n clear(): void;\n}\n","import { isPlatformServer } from '@angular/common';\nimport { StateClass } from '@ngxs/store/internals';\nimport { StateToken } from '@ngxs/store';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * If the `key` option is not provided then the below constant\n * will be used as a default key\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\n/**\n * Internal type definition for the `key` option provided\n * in the `forRoot` method when importing module\n */\nexport type StorageKey =\n | string\n | StateClass\n | StateToken<any>\n | (string | StateClass | StateToken<any>)[];\n\n/**\n * This key is used to retrieve static metadatas on state classes.\n * This constant is taken from the core codebase\n */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n\nfunction transformKeyOption(key: StorageKey): string[] {\n if (!Array.isArray(key)) {\n key = [key];\n }\n\n return key.map((token: string | StateClass | StateToken<any>) => {\n // If it has the `NGXS_OPTIONS_META` key then it means the developer\n // has provided state class like `key: [AuthState]`.\n if (token.hasOwnProperty(META_OPTIONS_KEY)) {\n // The `name` property will be an actual state name or a `StateToken`.\n token = (token as any)[META_OPTIONS_KEY].name;\n }\n\n return token instanceof StateToken ? token.getName() : (token as string);\n });\n}\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\n if (options !== undefined && options.key) {\n options.key = transformKeyOption(options.key);\n }\n\n return {\n key: [DEFAULT_STATE_KEY],\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options\n };\n}\n\nexport function engineFactory(\n options: NgxsStoragePluginOptions,\n platformId: string\n): StorageEngine | null {\n if (isPlatformServer(platformId)) {\n return null;\n }\n\n if (options.storage === StorageOption.LocalStorage) {\n return localStorage;\n } else if (options.storage === StorageOption.SessionStorage) {\n return sessionStorage;\n }\n\n return null;\n}\n","import { PLATFORM_ID, Inject, Injectable } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport { PlainObject } from '@ngxs/store/internals';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n actionMatcher,\n NgxsNextPluginFn\n} from '@ngxs/store';\nimport { tap } from 'rxjs/operators';\n\nimport {\n StorageEngine,\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { DEFAULT_STATE_KEY } from './internals';\n\n/**\n * @description Will be provided through Terser global definitions by Angular CLI\n * during the production build. This is how Angular does tree-shaking internally.\n */\ndeclare const ngDevMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n // We cast to `string[]` here as we're sure that this option has been\n // transformed by the `storageOptionsFactory` function that provided token.\n private _keys = this._options.key as string[];\n // We default to `[DEFAULT_STATE_KEY]` if the user explicitly does not provide the `key` option.\n private _usesDefaultStateKey =\n this._keys.length === 1 && this._keys[0] === DEFAULT_STATE_KEY;\n\n constructor(\n @Inject(NGXS_STORAGE_PLUGIN_OPTIONS) private _options: NgxsStoragePluginOptions,\n @Inject(STORAGE_ENGINE) private _engine: StorageEngine,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId) && this._engine === null) {\n return next(state, event);\n }\n\n const matches = actionMatcher(event);\n const isInitAction = matches(InitState);\n const isUpdateAction = matches(UpdateState);\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n const addedStates = isUpdateAction && event.addedStates;\n\n for (const key of this._keys) {\n // We're checking what states have been added by NGXS and if any of these states should be handled by\n // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added\n // the `user` state, the storage plugin will be rerun and will do redundant deserialization.\n // `usesDefaultStateKey` is necessary to check since `event.addedStates` never contains `@@STATE`.\n if (!this._usesDefaultStateKey && addedStates && !addedStates.hasOwnProperty(key)) {\n continue;\n }\n\n let storedValue: any = this._engine.getItem(key!);\n\n if (storedValue !== 'undefined' && storedValue != null) {\n try {\n const newVal = this._options.deserialize!(storedValue);\n storedValue = this._options.afterDeserialize!(newVal, key);\n } catch {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n console.error(\n `Error ocurred while deserializing the ${key} store value, falling back to empty object, the value obtained from the store: `,\n storedValue\n );\n }\n storedValue = {};\n }\n\n if (this._options.migrations) {\n this._options.migrations.forEach(strategy => {\n const versionMatch =\n strategy.version === getValue(storedValue, strategy.versionKey || 'version');\n const keyMatch =\n (!strategy.key && this._usesDefaultStateKey) || strategy.key === key;\n if (versionMatch && keyMatch) {\n storedValue = strategy.migrate(storedValue);\n hasMigration = true;\n }\n });\n }\n\n if (!this._usesDefaultStateKey) {\n state = setValue(state, key!, storedValue);\n } else {\n // The `UpdateState` action is dispatched whenever the feature state is added.\n // The below condition is met only when the `UpdateState` is dispatched.\n // Let's assume that we have 2 states `counter` and `@ngxs/router-plugin` state.\n // `CounterState` is provided on the root level when calling `NgxsModule.forRoot()`\n // and `@ngxs/router-plugin` is provided as a feature state.\n // The storage plugin may save the `counter` state value as `10` before.\n // The `CounterState` may implement the `ngxsOnInit` hook and call `ctx.setState(999)`.\n // The storage plugin will re-hydrate the whole state when the `RouterState` is registered,\n // and the `counter` state will again equal `10` (not `999`).\n if (storedValue && addedStates && Object.keys(addedStates).length > 0) {\n storedValue = Object.keys(addedStates).reduce((accumulator, addedState) => {\n // The `storedValue` may equal the whole state (when the default state key is used).\n // If `addedStates` contains only `router` then we want to merge the state only\n // with the `router` value.\n // Let's assume that the `storedValue` is an object:\n // `{ counter: 10, router: {...} }`\n // This will pick only the `router` object from the `storedValue` and `counter`\n // state will not be re-hydrated unnecessary.\n if (storedValue.hasOwnProperty(addedState)) {\n accumulator[addedState] = storedValue[addedState];\n }\n return accumulator;\n }, <PlainObject>{});\n }\n\n state = { ...state, ...storedValue };\n }\n }\n }\n }\n\n return next(state, event).pipe(\n tap(nextState => {\n if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {\n for (const key of this._keys) {\n let val = nextState;\n\n if (key !== DEFAULT_STATE_KEY) {\n val = getValue(nextState, key!);\n }\n\n try {\n const newVal = this._options.beforeSerialize!(val, key);\n this._engine.setItem(key!, this._options.serialize!(newVal));\n } catch (error) {\n // Caretaker note: we have still left the `typeof` condition in order to avoid\n // creating a breaking change for projects that still use the View Engine.\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n if (\n error &&\n (error.name === 'QuotaExceededError' ||\n error.name === 'NS_ERROR_DOM_QUOTA_REACHED')\n ) {\n console.error(\n `The ${key} store value exceeds the browser storage quota: `,\n val\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${key} store value, value not updated, the value obtained from the store: `,\n val\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n","import { NgModule, ModuleWithProviders, PLATFORM_ID, InjectionToken } from '@angular/core';\nimport { NGXS_PLUGINS } from '@ngxs/store';\n\nimport {\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n NGXS_STORAGE_PLUGIN_OPTIONS\n} from './symbols';\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { storageOptionsFactory, engineFactory } from './internals';\n\nexport const USER_OPTIONS = new InjectionToken('USER_OPTIONS');\n\n@NgModule()\nexport class NgxsStoragePluginModule {\n static forRoot(\n options?: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\n {\n provide: NGXS_PLUGINS,\n useClass: NgxsStoragePlugin,\n multi: true\n },\n {\n provide: USER_OPTIONS,\n useValue: options\n },\n {\n provide: NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: storageOptionsFactory,\n deps: [USER_OPTIONS]\n },\n {\n provide: STORAGE_ENGINE,\n useFactory: engineFactory,\n deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]\n }\n ]\n };\n }\n}\n"],"names":["tslib_1.__values"],"mappings":";;;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAyDC;;;;;;IArDC,uCAA6B;;;;;;;IAO7B,2CAAwB;;;;;IAKxB,8CAoBI;;;;;;IAKJ,kEAA6B;;;;;;IAK7B,oEAA4B;;;;;;;IAK5B,6EAA6C;;;;;;;IAK7C,8EAA8C;;;AAGhD,IAAa,2BAA2B,GAAG,IAAI,cAAc,CAAC,4BAA4B,CAAC;;AAE3F,IAAa,cAAc,GAAG,IAAI,cAAc,CAAC,gBAAgB,CAAC;;;;AAElE,4BAMC;;;IALC,+BAAwB;;;;;IACxB,qDAA0B;;;;;;IAC1B,0DAAqC;;;;;IACrC,wDAA8B;;;;IAC9B,gDAAc;;;;;;;;;;;;ACnEhB,IAAa,iBAAiB,GAAG,SAAS;;;;;;IAgBpC,gBAAgB,GAAG,mBAAmB;;;;;AAE5C,SAAS,kBAAkB,CAAC,GAAe;IACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;KACb;IAED,OAAO,GAAG,CAAC,GAAG;;;;IAAC,UAAC,KAA4C;;;QAG1D,IAAI,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE;;YAE1C,KAAK,GAAG,oBAAC,KAAK,IAAS,gBAAgB,CAAC,CAAC,IAAI,CAAC;SAC/C;QAED,OAAO,KAAK,YAAY,UAAU,GAAG,KAAK,CAAC,OAAO,EAAE,uBAAI,KAAK,GAAW,CAAC;KAC1E,EAAC,CAAC;CACJ;;;;;AAED,SAAgB,qBAAqB,CACnC,OAA6C;IAE7C,IAAI,OAAO,KAAK,SAAS,IA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Y;oBACrB,QAAQ,EAAE,iBAAiB;oBAC3B,KAAK,EAAE,IAAI;iBACZ;gBACD;oBACE,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,OAAO;iBAClB;gBACD;oBACE,OAAO,EAAE,2BAA2B;oBACpC,UAAU,EAAE,qBAAqB;oBACjC,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;gBACD;oBACE,OAAO,EAAE,cAAc;oBACvB,UAAU,EAAE,aAAa;oBACzB,IAAI,EAAE,CAAC,2BAA2B,EAAE,WAAW,CAAC;iBACjD;aACF;SACF,CAAC;KACH;;gBA7BF,QAAQ;;IA8BT,8BAAC;CA9BD;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":11,"character":32},"arguments":["USER_OPTIONS"]},"NgxsStoragePluginModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":13,"character":1}}],"members":{},"statics":{"forRoot":{"__symbolic":"function","parameters":["options"],"value":{"ngModule":{"__symbolic":"reference","name":"NgxsStoragePluginModule"},"providers":[{"provide":{"__symbolic":"reference","module":"@ngxs/store","name":"NGXS_PLUGINS","line":22,"character":19},"useClass":{"__symbolic":"reference","name":"NgxsStoragePlugin"},"multi":true},{"provide":{"__symbolic":"reference","name":"ɵa"},"useValue":{"__symbolic":"reference","name":"options"}},{"provide":{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"},"useFactory":{"__symbolic":"reference","name":"ɵb"},"deps":[{"__symbolic":"reference","name":"ɵa"}]},{"provide":{"__symbolic":"reference","name":"STORAGE_ENGINE"},"useFactory":{"__symbolic":"reference","name":"ɵc"},"deps":[{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"},{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":38,"character":46}]}]}}}},"NgxsStoragePlugin":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":27,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":30,"character":5},"arguments":[{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":31,"character":5},"arguments":[{"__symbolic":"reference","name":"STORAGE_ENGINE"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":32,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":32,"character":12}]}]],"parameters":[{"__symbolic":"reference","name":"NgxsStoragePluginOptions"},{"__symbolic":"reference","name":"StorageEngine"},{"__symbolic":"reference","name":"string"}]}],"handle":[{"__symbolic":"method"}]}},"StorageOption":{"LocalStorage":0,"SessionStorage":1},"NgxsStoragePluginOptions":{"__symbolic":"interface"},"NGXS_STORAGE_PLUGIN_OPTIONS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":68,"character":47},"arguments":["NGXS_STORAGE_PLUGIN_OPTION"]},"STORAGE_ENGINE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":70,"character":34},"arguments":["STORAGE_ENGINE"]},"StorageEngine":{"__symbolic":"interface"},"ɵb":{"__symbolic":"function"},"ɵc":{"__symbolic":"function"}},"origins":{"ɵa":"./src/storage.module","NgxsStoragePluginModule":"./src/storage.module","NgxsStoragePlugin":"./src/storage.plugin","StorageOption":"./src/symbols","NgxsStoragePluginOptions":"./src/symbols","NGXS_STORAGE_PLUGIN_OPTIONS":"./src/symbols","STORAGE_ENGINE":"./src/symbols","StorageEngine":"./src/symbols","ɵb":"./src/internals","ɵc":"./src/internals"},"importAs":"@ngxs/storage-plugin"}
1
+ {"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":11,"character":32},"arguments":["USER_OPTIONS"]},"NgxsStoragePluginModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":13,"character":1}}],"members":{},"statics":{"forRoot":{"__symbolic":"function","parameters":["options"],"value":{"ngModule":{"__symbolic":"reference","name":"NgxsStoragePluginModule"},"providers":[{"provide":{"__symbolic":"reference","module":"@ngxs/store","name":"NGXS_PLUGINS","line":22,"character":19},"useClass":{"__symbolic":"reference","name":"NgxsStoragePlugin"},"multi":true},{"provide":{"__symbolic":"reference","name":"ɵa"},"useValue":{"__symbolic":"reference","name":"options"}},{"provide":{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"},"useFactory":{"__symbolic":"reference","name":"ɵb"},"deps":[{"__symbolic":"reference","name":"ɵa"}]},{"provide":{"__symbolic":"reference","name":"STORAGE_ENGINE"},"useFactory":{"__symbolic":"reference","name":"ɵc"},"deps":[{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"},{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":38,"character":46}]}]}}}},"NgxsStoragePlugin":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":28,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":38,"character":5},"arguments":[{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":39,"character":5},"arguments":[{"__symbolic":"reference","name":"STORAGE_ENGINE"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":40,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":40,"character":12}]}]],"parameters":[{"__symbolic":"reference","name":"NgxsStoragePluginOptions"},{"__symbolic":"reference","name":"StorageEngine"},{"__symbolic":"reference","name":"string"}]}],"handle":[{"__symbolic":"method"}]}},"StorageOption":{"LocalStorage":0,"SessionStorage":1},"NgxsStoragePluginOptions":{"__symbolic":"interface"},"NGXS_STORAGE_PLUGIN_OPTIONS":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":68,"character":47},"arguments":["NGXS_STORAGE_PLUGIN_OPTION"]},"STORAGE_ENGINE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":70,"character":34},"arguments":["STORAGE_ENGINE"]},"StorageEngine":{"__symbolic":"interface"},"ɵb":{"__symbolic":"function"},"ɵc":{"__symbolic":"function"}},"origins":{"ɵa":"./src/storage.module","NgxsStoragePluginModule":"./src/storage.module","NgxsStoragePlugin":"./src/storage.plugin","StorageOption":"./src/symbols","NgxsStoragePluginOptions":"./src/symbols","NGXS_STORAGE_PLUGIN_OPTIONS":"./src/symbols","STORAGE_ENGINE":"./src/symbols","StorageEngine":"./src/symbols","ɵb":"./src/internals","ɵc":"./src/internals"},"importAs":"@ngxs/storage-plugin"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../node_modules/ng-packagr/package.schema.json",
3
3
  "name": "@ngxs/storage-plugin",
4
4
  "description": "extendable storage plugin for @ngxs/store",
5
- "version": "3.7.4-dev.master-b8320fc",
5
+ "version": "3.7.4-dev.master-817c422",
6
6
  "sideEffects": true,
7
7
  "peerDependencies": {
8
8
  "@angular/core": ">=6.1.0 <15.0.0",
@@ -4,6 +4,8 @@ export declare class NgxsStoragePlugin implements NgxsPlugin {
4
4
  private _options;
5
5
  private _engine;
6
6
  private _platformId;
7
+ private _keys;
8
+ private _usesDefaultStateKey;
7
9
  constructor(_options: NgxsStoragePluginOptions, _engine: StorageEngine, _platformId: string);
8
10
  handle(state: any, event: any, next: NgxsNextPluginFn): any;
9
11
  }