@ngxs/storage-plugin 3.7.5-dev.master-66b90a9 → 3.7.5-dev.master-7ca104f

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.
Files changed (38) hide show
  1. package/bundles/ngxs-storage-plugin.umd.js +162 -66
  2. package/bundles/ngxs-storage-plugin.umd.js.map +1 -1
  3. package/bundles/ngxs-storage-plugin.umd.min.js +1 -1
  4. package/bundles/ngxs-storage-plugin.umd.min.js.map +1 -1
  5. package/esm2015/index.js +2 -2
  6. package/esm2015/ngxs-storage-plugin.js +4 -3
  7. package/esm2015/src/engines.js +22 -0
  8. package/esm2015/src/internals/final-options.js +42 -0
  9. package/esm2015/src/internals/storage-key.js +47 -0
  10. package/esm2015/src/internals.js +13 -35
  11. package/esm2015/src/public_api.js +2 -1
  12. package/esm2015/src/storage.module.js +9 -3
  13. package/esm2015/src/storage.plugin.js +24 -30
  14. package/esm2015/src/symbols.js +9 -2
  15. package/esm5/index.js +2 -2
  16. package/esm5/ngxs-storage-plugin.js +4 -3
  17. package/esm5/src/engines.js +22 -0
  18. package/esm5/src/internals/final-options.js +43 -0
  19. package/esm5/src/internals/storage-key.js +47 -0
  20. package/esm5/src/internals.js +13 -35
  21. package/esm5/src/public_api.js +2 -1
  22. package/esm5/src/storage.module.js +9 -3
  23. package/esm5/src/storage.plugin.js +28 -33
  24. package/esm5/src/symbols.js +9 -2
  25. package/fesm2015/ngxs-storage-plugin.js +154 -63
  26. package/fesm2015/ngxs-storage-plugin.js.map +1 -1
  27. package/fesm5/ngxs-storage-plugin.js +158 -66
  28. package/fesm5/ngxs-storage-plugin.js.map +1 -1
  29. package/ngxs-storage-plugin.d.ts +2 -1
  30. package/ngxs-storage-plugin.metadata.json +1 -1
  31. package/package.json +1 -1
  32. package/src/engines.d.ts +4 -0
  33. package/src/internals/final-options.d.ts +10 -0
  34. package/src/internals/storage-key.d.ts +17 -0
  35. package/src/internals.d.ts +3 -9
  36. package/src/public_api.d.ts +1 -0
  37. package/src/storage.plugin.d.ts +3 -4
  38. package/src/symbols.d.ts +9 -3
@@ -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 { 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) {\n // We support providing keys that can be deeply nested via dot notation, for instance,\n // `keys: ['myState.myProperty']` is a valid key.\n // The state name should always go first. The below code checks if the `key` includes dot\n // notation and extracts the state name out of the key.\n // Given the `key` is `myState.myProperty`, the `addedStates` will only contain `myState`.\n const dotNotationIndex = key.indexOf(DOT);\n const stateName = dotNotationIndex > -1 ? key.slice(0, dotNotationIndex) : key;\n if (!addedStates.hasOwnProperty(stateName)) {\n continue;\n }\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\nconst DOT = '.';\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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,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/internals/storage-key.ts","ng://@ngxs/storage-plugin/src/internals/final-options.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts","ng://@ngxs/storage-plugin/src/engines.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals/storage-key';\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 | StorageKey[];\n\n /**\n * The namespace is used to prefix the key for the state slice. This is\n * necessary when running micro frontend applications which use storage plugin.\n * The namespace will eliminate the conflict between keys that might overlap.\n */\n namespace?: string;\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_OPTIONS');\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>('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';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * The following key is used to store the entire serialized\n * state when there's no specific state provided.\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\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\nexport function getStorageKey(key: string, options?: NgxsStoragePluginOptions): string {\n // Prepends the `namespace` option to any key if it's been provided by a user.\n // So `@@STATE` becomes `my-app:@@STATE`.\n return options && options.namespace ? `${options.namespace}:${key}` : key;\n}\n","import { InjectionToken, Type } from '@angular/core';\nimport { StateToken } from '@ngxs/store';\nimport { StateClass } from '@ngxs/store/internals';\n\nimport { StorageEngine } from '../symbols';\n\n/** This enables the user to provide a storage engine per individual key. */\nexport interface KeyWithExplicitEngine {\n key: string | StateClass | StateToken<any>;\n engine: Type<StorageEngine> | InjectionToken<StorageEngine>;\n}\n\n/** Determines whether the provided key has the following structure. */\nexport function isKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine {\n return key != null && !!key.engine;\n}\n\n/**\n * This tuples all of the possible types allowed in the `key` property.\n * This is not exposed publicly and used internally only.\n */\nexport type StorageKey = string | StateClass | StateToken<any> | KeyWithExplicitEngine;\n\n/** This symbol is used to store the metadata on state classes. */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\nexport function exctractStringKey(storageKey: StorageKey): string {\n // Extract the actual key out of the `{ key, engine }` structure.\n if (isKeyWithExplicitEngine(storageKey)) {\n storageKey = storageKey.key;\n }\n\n // Given the `storageKey` is a class, for instance, `AuthState`.\n // We should retrieve its metadata and the `name` property.\n // The `name` property might be a string (state name) or a state token.\n if (storageKey.hasOwnProperty(META_OPTIONS_KEY)) {\n storageKey = (storageKey as any)[META_OPTIONS_KEY].name;\n }\n\n return storageKey instanceof StateToken ? storageKey.getName() : <string>storageKey;\n}\n","import { InjectionToken, Injector } from '@angular/core';\n\nimport { exctractStringKey, isKeyWithExplicitEngine, StorageKey } from './storage-key';\nimport { NgxsStoragePluginOptions, StorageEngine, STORAGE_ENGINE } from '../symbols';\n\nexport interface FinalNgxsStoragePluginOptions extends NgxsStoragePluginOptions {\n keysWithEngines: {\n key: string;\n engine: StorageEngine;\n }[];\n}\n\nexport const FINAL_NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken<\n FinalNgxsStoragePluginOptions\n>('FINAL_NGXS_STORAGE_PLUGIN_OPTIONS');\n\nexport function createFinalStoragePluginOptions(\n injector: Injector,\n options: NgxsStoragePluginOptions\n): FinalNgxsStoragePluginOptions {\n const storageKeys: StorageKey[] = Array.isArray(options.key) ? options.key : [options.key!];\n\n const keysWithEngines = storageKeys.map((storageKey: StorageKey) => {\n const key = exctractStringKey(storageKey);\n const engine = isKeyWithExplicitEngine(storageKey)\n ? injector.get(storageKey.engine)\n : injector.get(STORAGE_ENGINE);\n return { key, engine };\n });\n\n return {\n ...options,\n keysWithEngines\n };\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 { DEFAULT_STATE_KEY, getStorageKey } from './internals';\nimport {\n FinalNgxsStoragePluginOptions,\n FINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from './internals/final-options';\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 private _keysWithEngines = this._options.keysWithEngines;\n // We default to `[DEFAULT_STATE_KEY]` if the user explicitly does not provide the `key` option.\n private _usesDefaultStateKey =\n this._keysWithEngines.length === 1 && this._keysWithEngines[0].key === DEFAULT_STATE_KEY;\n\n constructor(\n @Inject(FINAL_NGXS_STORAGE_PLUGIN_OPTIONS) private _options: FinalNgxsStoragePluginOptions,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId)) {\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, engine } of this._keysWithEngines) {\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) {\n // We support providing keys that can be deeply nested via dot notation, for instance,\n // `keys: ['myState.myProperty']` is a valid key.\n // The state name should always go first. The below code checks if the `key` includes dot\n // notation and extracts the state name out of the key.\n // Given the `key` is `myState.myProperty`, the `addedStates` will only contain `myState`.\n const dotNotationIndex = key.indexOf(DOT);\n const stateName = dotNotationIndex > -1 ? key.slice(0, dotNotationIndex) : key;\n if (!addedStates.hasOwnProperty(stateName)) {\n continue;\n }\n }\n\n const storageKey = getStorageKey(key, this._options);\n let storedValue: any = engine.getItem(storageKey);\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 ${storageKey} 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, engine } of this._keysWithEngines) {\n let storedValue = nextState;\n\n const storageKey = getStorageKey(key, this._options);\n\n if (key !== DEFAULT_STATE_KEY) {\n storedValue = getValue(nextState, key);\n }\n\n try {\n const newStoredValue = this._options.beforeSerialize!(storedValue, key);\n engine.setItem(storageKey, this._options.serialize!(newStoredValue));\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 ${storageKey} store value exceeds the browser storage quota: `,\n storedValue\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${storageKey} store value, value not updated, the value obtained from the store: `,\n storedValue\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n PLATFORM_ID,\n InjectionToken,\n Injector\n} 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 { engineFactory, storageOptionsFactory } from './internals';\nimport {\n createFinalStoragePluginOptions,\n FINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from './internals/final-options';\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 provide: FINAL_NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: createFinalStoragePluginOptions,\n deps: [Injector, NGXS_STORAGE_PLUGIN_OPTIONS]\n }\n ]\n };\n }\n}\n","import { InjectionToken } from '@angular/core';\n\nimport { StorageEngine } from './symbols';\n\nexport const LOCAL_STORAGE_ENGINE = new InjectionToken<StorageEngine>('LOCAL_STORAGE_ENGINE', {\n providedIn: 'root',\n factory: () => localStorage\n});\n\nexport const SESSION_STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n 'SESSION_STORAGE_ENGINE',\n {\n providedIn: 'root',\n factory: () => sessionStorage\n }\n);\n"],"names":[],"mappings":";;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAgEC;;;;;;IA5DC,uCAA4C;;;;;;;IAO5C,6CAAmB;;;;;;;IAOnB,2CAAwB;;;;;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AAY,CAAA;CAC5B,CAAC;;AAEF,MAAa,sBAAsB,GAAG,IAAI,cAAc,CACtD,wBAAwB,EACxB;IACE,UAAU,EAAE,MAAM;IAClB,OAAO;;;IAAE,MAAM,cAAc,CAAA;CAC9B,CACF;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- import { InjectionToken, Injectable, Inject, PLATFORM_ID, NgModule } from '@angular/core';
1
+ import { InjectionToken, Injectable, Inject, PLATFORM_ID, Injector, NgModule } from '@angular/core';
2
2
  import { StateToken, actionMatcher, InitState, UpdateState, getValue, setValue, NGXS_PLUGINS } from '@ngxs/store';
3
3
  import { __assign, __values } from 'tslib';
4
4
  import { isPlatformServer } from '@angular/common';
@@ -23,6 +23,13 @@ if (false) {
23
23
  * @type {?|undefined}
24
24
  */
25
25
  NgxsStoragePluginOptions.prototype.key;
26
+ /**
27
+ * The namespace is used to prefix the key for the state slice. This is
28
+ * necessary when running micro frontend applications which use storage plugin.
29
+ * The namespace will eliminate the conflict between keys that might overlap.
30
+ * @type {?|undefined}
31
+ */
32
+ NgxsStoragePluginOptions.prototype.namespace;
26
33
  /**
27
34
  * Storage engine to use. Deaults to localStorage but can provide
28
35
  *
@@ -63,7 +70,7 @@ if (false) {
63
70
  NgxsStoragePluginOptions.prototype.afterDeserialize = function (obj, key) { };
64
71
  }
65
72
  /** @type {?} */
66
- var NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');
73
+ var NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTIONS');
67
74
  /** @type {?} */
68
75
  var STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');
69
76
  /**
@@ -100,47 +107,16 @@ if (false) {
100
107
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
101
108
  */
102
109
  /**
103
- * If the `key` option is not provided then the below constant
104
- * will be used as a default key
110
+ * The following key is used to store the entire serialized
111
+ * state when there's no specific state provided.
105
112
  * @type {?}
106
113
  */
107
114
  var DEFAULT_STATE_KEY = '@@STATE';
108
- /**
109
- * This key is used to retrieve static metadatas on state classes.
110
- * This constant is taken from the core codebase
111
- * @type {?}
112
- */
113
- var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
114
- /**
115
- * @param {?} key
116
- * @return {?}
117
- */
118
- function transformKeyOption(key) {
119
- if (!Array.isArray(key)) {
120
- key = [key];
121
- }
122
- return key.map((/**
123
- * @param {?} token
124
- * @return {?}
125
- */
126
- function (token) {
127
- // If it has the `NGXS_OPTIONS_META` key then it means the developer
128
- // has provided state class like `key: [AuthState]`.
129
- if (token.hasOwnProperty(META_OPTIONS_KEY)) {
130
- // The `name` property will be an actual state name or a `StateToken`.
131
- token = ((/** @type {?} */ (token)))[META_OPTIONS_KEY].name;
132
- }
133
- return token instanceof StateToken ? token.getName() : ((/** @type {?} */ (token)));
134
- }));
135
- }
136
115
  /**
137
116
  * @param {?} options
138
117
  * @return {?}
139
118
  */
140
119
  function storageOptionsFactory(options) {
141
- if (options !== undefined && options.key) {
142
- options.key = transformKeyOption(options.key);
143
- }
144
120
  return __assign({ key: [DEFAULT_STATE_KEY], storage: 0 /* LocalStorage */, serialize: JSON.stringify, deserialize: JSON.parse, beforeSerialize: (/**
145
121
  * @param {?} obj
146
122
  * @return {?}
@@ -168,21 +144,113 @@ function engineFactory(options, platformId) {
168
144
  }
169
145
  return null;
170
146
  }
147
+ /**
148
+ * @param {?} key
149
+ * @param {?=} options
150
+ * @return {?}
151
+ */
152
+ function getStorageKey(key, options) {
153
+ // Prepends the `namespace` option to any key if it's been provided by a user.
154
+ // So `@@STATE` becomes `my-app:@@STATE`.
155
+ return options && options.namespace ? options.namespace + ":" + key : key;
156
+ }
157
+
158
+ /**
159
+ * @fileoverview added by tsickle
160
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
161
+ */
162
+ /**
163
+ * This enables the user to provide a storage engine per individual key.
164
+ * @record
165
+ */
166
+ function KeyWithExplicitEngine() { }
167
+ if (false) {
168
+ /** @type {?} */
169
+ KeyWithExplicitEngine.prototype.key;
170
+ /** @type {?} */
171
+ KeyWithExplicitEngine.prototype.engine;
172
+ }
173
+ /**
174
+ * Determines whether the provided key has the following structure.
175
+ * @param {?} key
176
+ * @return {?}
177
+ */
178
+ function isKeyWithExplicitEngine(key) {
179
+ return key != null && !!key.engine;
180
+ }
181
+ /**
182
+ * This symbol is used to store the metadata on state classes.
183
+ * @type {?}
184
+ */
185
+ var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
186
+ /**
187
+ * @param {?} storageKey
188
+ * @return {?}
189
+ */
190
+ function exctractStringKey(storageKey) {
191
+ // Extract the actual key out of the `{ key, engine }` structure.
192
+ if (isKeyWithExplicitEngine(storageKey)) {
193
+ storageKey = storageKey.key;
194
+ }
195
+ // Given the `storageKey` is a class, for instance, `AuthState`.
196
+ // We should retrieve its metadata and the `name` property.
197
+ // The `name` property might be a string (state name) or a state token.
198
+ if (storageKey.hasOwnProperty(META_OPTIONS_KEY)) {
199
+ storageKey = ((/** @type {?} */ (storageKey)))[META_OPTIONS_KEY].name;
200
+ }
201
+ return storageKey instanceof StateToken ? storageKey.getName() : (/** @type {?} */ (storageKey));
202
+ }
203
+
204
+ /**
205
+ * @fileoverview added by tsickle
206
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
207
+ */
208
+ /**
209
+ * @record
210
+ */
211
+ function FinalNgxsStoragePluginOptions() { }
212
+ if (false) {
213
+ /** @type {?} */
214
+ FinalNgxsStoragePluginOptions.prototype.keysWithEngines;
215
+ }
216
+ /** @type {?} */
217
+ var FINAL_NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('FINAL_NGXS_STORAGE_PLUGIN_OPTIONS');
218
+ /**
219
+ * @param {?} injector
220
+ * @param {?} options
221
+ * @return {?}
222
+ */
223
+ function createFinalStoragePluginOptions(injector, options) {
224
+ /** @type {?} */
225
+ var storageKeys = Array.isArray(options.key) ? options.key : [(/** @type {?} */ (options.key))];
226
+ /** @type {?} */
227
+ var keysWithEngines = storageKeys.map((/**
228
+ * @param {?} storageKey
229
+ * @return {?}
230
+ */
231
+ function (storageKey) {
232
+ /** @type {?} */
233
+ var key = exctractStringKey(storageKey);
234
+ /** @type {?} */
235
+ var engine = isKeyWithExplicitEngine(storageKey)
236
+ ? injector.get(storageKey.engine)
237
+ : injector.get(STORAGE_ENGINE);
238
+ return { key: key, engine: engine };
239
+ }));
240
+ return __assign({}, options, { keysWithEngines: keysWithEngines });
241
+ }
171
242
 
172
243
  /**
173
244
  * @fileoverview added by tsickle
174
245
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
175
246
  */
176
247
  var NgxsStoragePlugin = /** @class */ (function () {
177
- function NgxsStoragePlugin(_options, _engine, _platformId) {
248
+ function NgxsStoragePlugin(_options, _platformId) {
178
249
  this._options = _options;
179
- this._engine = _engine;
180
250
  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));
251
+ this._keysWithEngines = this._options.keysWithEngines;
184
252
  // 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;
253
+ this._usesDefaultStateKey = this._keysWithEngines.length === 1 && this._keysWithEngines[0].key === DEFAULT_STATE_KEY;
186
254
  }
187
255
  /**
188
256
  * @param {?} state
@@ -199,7 +267,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
199
267
  function (state, event, next) {
200
268
  var _this = this;
201
269
  var e_1, _a;
202
- if (isPlatformServer(this._platformId) && this._engine === null) {
270
+ if (isPlatformServer(this._platformId)) {
203
271
  return next(state, event);
204
272
  }
205
273
  /** @type {?} */
@@ -215,7 +283,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
215
283
  if (isInitOrUpdateAction) {
216
284
  /** @type {?} */
217
285
  var addedStates = isUpdateAction && event.addedStates;
218
- var _loop_1 = function (key) {
286
+ var _loop_1 = function (key, engine) {
219
287
  // We're checking what states have been added by NGXS and if any of these states should be handled by
220
288
  // the storage plugin. For instance, we only want to deserialize the `auth` state, NGXS has added
221
289
  // the `user` state, the storage plugin will be rerun and will do redundant deserialization.
@@ -235,7 +303,9 @@ var NgxsStoragePlugin = /** @class */ (function () {
235
303
  }
236
304
  }
237
305
  /** @type {?} */
238
- var storedValue = this_1._engine.getItem((/** @type {?} */ (key)));
306
+ var storageKey = getStorageKey(key, this_1._options);
307
+ /** @type {?} */
308
+ var storedValue = engine.getItem(storageKey);
239
309
  if (storedValue !== 'undefined' && storedValue != null) {
240
310
  try {
241
311
  /** @type {?} */
@@ -246,7 +316,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
246
316
  // Caretaker note: we have still left the `typeof` condition in order to avoid
247
317
  // creating a breaking change for projects that still use the View Engine.
248
318
  if (typeof ngDevMode === 'undefined' || ngDevMode) {
249
- console.error("Error ocurred while deserializing the " + key + " store value, falling back to empty object, the value obtained from the store: ", storedValue);
319
+ console.error("Error ocurred while deserializing the " + storageKey + " store value, falling back to empty object, the value obtained from the store: ", storedValue);
250
320
  }
251
321
  storedValue = {};
252
322
  }
@@ -267,7 +337,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
267
337
  }));
268
338
  }
269
339
  if (!this_1._usesDefaultStateKey) {
270
- state = setValue(state, (/** @type {?} */ (key)), storedValue);
340
+ state = setValue(state, key, storedValue);
271
341
  }
272
342
  else {
273
343
  // The `UpdateState` action is dispatched whenever the feature state is added.
@@ -305,9 +375,9 @@ var NgxsStoragePlugin = /** @class */ (function () {
305
375
  };
306
376
  var this_1 = this;
307
377
  try {
308
- for (var _b = __values(this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
309
- var key = _c.value;
310
- _loop_1(key);
378
+ for (var _b = __values(this._keysWithEngines), _c = _b.next(); !_c.done; _c = _b.next()) {
379
+ var _d = _c.value, key = _d.key, engine = _d.engine;
380
+ _loop_1(key, engine);
311
381
  }
312
382
  }
313
383
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -326,17 +396,19 @@ var NgxsStoragePlugin = /** @class */ (function () {
326
396
  var e_2, _a;
327
397
  if (!isInitOrUpdateAction || (isInitOrUpdateAction && hasMigration)) {
328
398
  try {
329
- for (var _b = __values(_this._keys), _c = _b.next(); !_c.done; _c = _b.next()) {
330
- var key = _c.value;
399
+ for (var _b = __values(_this._keysWithEngines), _c = _b.next(); !_c.done; _c = _b.next()) {
400
+ var _d = _c.value, key = _d.key, engine = _d.engine;
401
+ /** @type {?} */
402
+ var storedValue = nextState;
331
403
  /** @type {?} */
332
- var val = nextState;
404
+ var storageKey = getStorageKey(key, _this._options);
333
405
  if (key !== DEFAULT_STATE_KEY) {
334
- val = getValue(nextState, (/** @type {?} */ (key)));
406
+ storedValue = getValue(nextState, key);
335
407
  }
336
408
  try {
337
409
  /** @type {?} */
338
- var newVal = (/** @type {?} */ (_this._options.beforeSerialize))(val, key);
339
- _this._engine.setItem((/** @type {?} */ (key)), (/** @type {?} */ (_this._options.serialize))(newVal));
410
+ var newStoredValue = (/** @type {?} */ (_this._options.beforeSerialize))(storedValue, key);
411
+ engine.setItem(storageKey, (/** @type {?} */ (_this._options.serialize))(newStoredValue));
340
412
  }
341
413
  catch (error) {
342
414
  // Caretaker note: we have still left the `typeof` condition in order to avoid
@@ -345,10 +417,10 @@ var NgxsStoragePlugin = /** @class */ (function () {
345
417
  if (error &&
346
418
  (error.name === 'QuotaExceededError' ||
347
419
  error.name === 'NS_ERROR_DOM_QUOTA_REACHED')) {
348
- console.error("The " + key + " store value exceeds the browser storage quota: ", val);
420
+ console.error("The " + storageKey + " store value exceeds the browser storage quota: ", storedValue);
349
421
  }
350
422
  else {
351
- console.error("Error ocurred while serializing the " + key + " store value, value not updated, the value obtained from the store: ", val);
423
+ console.error("Error ocurred while serializing the " + storageKey + " store value, value not updated, the value obtained from the store: ", storedValue);
352
424
  }
353
425
  }
354
426
  }
@@ -369,8 +441,7 @@ var NgxsStoragePlugin = /** @class */ (function () {
369
441
  ];
370
442
  /** @nocollapse */
371
443
  NgxsStoragePlugin.ctorParameters = function () { return [
372
- { type: undefined, decorators: [{ type: Inject, args: [NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
373
- { type: undefined, decorators: [{ type: Inject, args: [STORAGE_ENGINE,] }] },
444
+ { type: undefined, decorators: [{ type: Inject, args: [FINAL_NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
374
445
  { type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
375
446
  ]; };
376
447
  return NgxsStoragePlugin;
@@ -380,7 +451,7 @@ if (false) {
380
451
  * @type {?}
381
452
  * @private
382
453
  */
383
- NgxsStoragePlugin.prototype._keys;
454
+ NgxsStoragePlugin.prototype._keysWithEngines;
384
455
  /**
385
456
  * @type {?}
386
457
  * @private
@@ -391,11 +462,6 @@ if (false) {
391
462
  * @private
392
463
  */
393
464
  NgxsStoragePlugin.prototype._options;
394
- /**
395
- * @type {?}
396
- * @private
397
- */
398
- NgxsStoragePlugin.prototype._engine;
399
465
  /**
400
466
  * @type {?}
401
467
  * @private
@@ -444,6 +510,11 @@ var NgxsStoragePluginModule = /** @class */ (function () {
444
510
  provide: STORAGE_ENGINE,
445
511
  useFactory: engineFactory,
446
512
  deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
513
+ },
514
+ {
515
+ provide: FINAL_NGXS_STORAGE_PLUGIN_OPTIONS,
516
+ useFactory: createFinalStoragePluginOptions,
517
+ deps: [Injector, NGXS_STORAGE_PLUGIN_OPTIONS]
447
518
  }
448
519
  ]
449
520
  };
@@ -454,6 +525,27 @@ var NgxsStoragePluginModule = /** @class */ (function () {
454
525
  return NgxsStoragePluginModule;
455
526
  }());
456
527
 
528
+ /**
529
+ * @fileoverview added by tsickle
530
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
531
+ */
532
+ /** @type {?} */
533
+ var LOCAL_STORAGE_ENGINE = new InjectionToken('LOCAL_STORAGE_ENGINE', {
534
+ providedIn: 'root',
535
+ factory: (/**
536
+ * @return {?}
537
+ */
538
+ function () { return localStorage; })
539
+ });
540
+ /** @type {?} */
541
+ var SESSION_STORAGE_ENGINE = new InjectionToken('SESSION_STORAGE_ENGINE', {
542
+ providedIn: 'root',
543
+ factory: (/**
544
+ * @return {?}
545
+ */
546
+ function () { return sessionStorage; })
547
+ });
548
+
457
549
  /**
458
550
  * @fileoverview added by tsickle
459
551
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -469,5 +561,5 @@ var NgxsStoragePluginModule = /** @class */ (function () {
469
561
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
470
562
  */
471
563
 
472
- export { NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, STORAGE_ENGINE, USER_OPTIONS as ɵa, storageOptionsFactory as ɵb, engineFactory as ɵc };
564
+ export { LOCAL_STORAGE_ENGINE, NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, SESSION_STORAGE_ENGINE, STORAGE_ENGINE, USER_OPTIONS as ɵa, FINAL_NGXS_STORAGE_PLUGIN_OPTIONS as ɵc, createFinalStoragePluginOptions as ɵd, storageOptionsFactory as ɵe, engineFactory as ɵf };
473
565
  //# sourceMappingURL=ngxs-storage-plugin.js.map
@@ -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 { 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) {\n // We support providing keys that can be deeply nested via dot notation, for instance,\n // `keys: ['myState.myProperty']` is a valid key.\n // The state name should always go first. The below code checks if the `key` includes dot\n // notation and extracts the state name out of the key.\n // Given the `key` is `myState.myProperty`, the `addedStates` will only contain `myState`.\n const dotNotationIndex = key.indexOf(DOT);\n const stateName = dotNotationIndex > -1 ? key.slice(0, dotNotationIndex) : key;\n if (!addedStates.hasOwnProperty(stateName)) {\n continue;\n }\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\nconst DOT = '.';\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;;I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AAE;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;;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/internals/storage-key.ts","ng://@ngxs/storage-plugin/src/internals/final-options.ts","ng://@ngxs/storage-plugin/src/storage.plugin.ts","ng://@ngxs/storage-plugin/src/storage.module.ts","ng://@ngxs/storage-plugin/src/engines.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { StorageKey } from './internals/storage-key';\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 | StorageKey[];\n\n /**\n * The namespace is used to prefix the key for the state slice. This is\n * necessary when running micro frontend applications which use storage plugin.\n * The namespace will eliminate the conflict between keys that might overlap.\n */\n namespace?: string;\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_OPTIONS');\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>('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';\n\nimport { StorageOption, StorageEngine, NgxsStoragePluginOptions } from './symbols';\n\n/**\n * The following key is used to store the entire serialized\n * state when there's no specific state provided.\n */\nexport const DEFAULT_STATE_KEY = '@@STATE';\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions | undefined\n): NgxsStoragePluginOptions {\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\nexport function getStorageKey(key: string, options?: NgxsStoragePluginOptions): string {\n // Prepends the `namespace` option to any key if it's been provided by a user.\n // So `@@STATE` becomes `my-app:@@STATE`.\n return options && options.namespace ? `${options.namespace}:${key}` : key;\n}\n","import { InjectionToken, Type } from '@angular/core';\nimport { StateToken } from '@ngxs/store';\nimport { StateClass } from '@ngxs/store/internals';\n\nimport { StorageEngine } from '../symbols';\n\n/** This enables the user to provide a storage engine per individual key. */\nexport interface KeyWithExplicitEngine {\n key: string | StateClass | StateToken<any>;\n engine: Type<StorageEngine> | InjectionToken<StorageEngine>;\n}\n\n/** Determines whether the provided key has the following structure. */\nexport function isKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine {\n return key != null && !!key.engine;\n}\n\n/**\n * This tuples all of the possible types allowed in the `key` property.\n * This is not exposed publicly and used internally only.\n */\nexport type StorageKey = string | StateClass | StateToken<any> | KeyWithExplicitEngine;\n\n/** This symbol is used to store the metadata on state classes. */\nconst META_OPTIONS_KEY = 'NGXS_OPTIONS_META';\nexport function exctractStringKey(storageKey: StorageKey): string {\n // Extract the actual key out of the `{ key, engine }` structure.\n if (isKeyWithExplicitEngine(storageKey)) {\n storageKey = storageKey.key;\n }\n\n // Given the `storageKey` is a class, for instance, `AuthState`.\n // We should retrieve its metadata and the `name` property.\n // The `name` property might be a string (state name) or a state token.\n if (storageKey.hasOwnProperty(META_OPTIONS_KEY)) {\n storageKey = (storageKey as any)[META_OPTIONS_KEY].name;\n }\n\n return storageKey instanceof StateToken ? storageKey.getName() : <string>storageKey;\n}\n","import { InjectionToken, Injector } from '@angular/core';\n\nimport { exctractStringKey, isKeyWithExplicitEngine, StorageKey } from './storage-key';\nimport { NgxsStoragePluginOptions, StorageEngine, STORAGE_ENGINE } from '../symbols';\n\nexport interface FinalNgxsStoragePluginOptions extends NgxsStoragePluginOptions {\n keysWithEngines: {\n key: string;\n engine: StorageEngine;\n }[];\n}\n\nexport const FINAL_NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken<\n FinalNgxsStoragePluginOptions\n>('FINAL_NGXS_STORAGE_PLUGIN_OPTIONS');\n\nexport function createFinalStoragePluginOptions(\n injector: Injector,\n options: NgxsStoragePluginOptions\n): FinalNgxsStoragePluginOptions {\n const storageKeys: StorageKey[] = Array.isArray(options.key) ? options.key : [options.key!];\n\n const keysWithEngines = storageKeys.map((storageKey: StorageKey) => {\n const key = exctractStringKey(storageKey);\n const engine = isKeyWithExplicitEngine(storageKey)\n ? injector.get(storageKey.engine)\n : injector.get(STORAGE_ENGINE);\n return { key, engine };\n });\n\n return {\n ...options,\n keysWithEngines\n };\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 { DEFAULT_STATE_KEY, getStorageKey } from './internals';\nimport {\n FinalNgxsStoragePluginOptions,\n FINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from './internals/final-options';\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 private _keysWithEngines = this._options.keysWithEngines;\n // We default to `[DEFAULT_STATE_KEY]` if the user explicitly does not provide the `key` option.\n private _usesDefaultStateKey =\n this._keysWithEngines.length === 1 && this._keysWithEngines[0].key === DEFAULT_STATE_KEY;\n\n constructor(\n @Inject(FINAL_NGXS_STORAGE_PLUGIN_OPTIONS) private _options: FinalNgxsStoragePluginOptions,\n @Inject(PLATFORM_ID) private _platformId: string\n ) {}\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (isPlatformServer(this._platformId)) {\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, engine } of this._keysWithEngines) {\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) {\n // We support providing keys that can be deeply nested via dot notation, for instance,\n // `keys: ['myState.myProperty']` is a valid key.\n // The state name should always go first. The below code checks if the `key` includes dot\n // notation and extracts the state name out of the key.\n // Given the `key` is `myState.myProperty`, the `addedStates` will only contain `myState`.\n const dotNotationIndex = key.indexOf(DOT);\n const stateName = dotNotationIndex > -1 ? key.slice(0, dotNotationIndex) : key;\n if (!addedStates.hasOwnProperty(stateName)) {\n continue;\n }\n }\n\n const storageKey = getStorageKey(key, this._options);\n let storedValue: any = engine.getItem(storageKey);\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 ${storageKey} 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, engine } of this._keysWithEngines) {\n let storedValue = nextState;\n\n const storageKey = getStorageKey(key, this._options);\n\n if (key !== DEFAULT_STATE_KEY) {\n storedValue = getValue(nextState, key);\n }\n\n try {\n const newStoredValue = this._options.beforeSerialize!(storedValue, key);\n engine.setItem(storageKey, this._options.serialize!(newStoredValue));\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 ${storageKey} store value exceeds the browser storage quota: `,\n storedValue\n );\n } else {\n console.error(\n `Error ocurred while serializing the ${storageKey} store value, value not updated, the value obtained from the store: `,\n storedValue\n );\n }\n }\n }\n }\n }\n })\n );\n }\n}\n\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n PLATFORM_ID,\n InjectionToken,\n Injector\n} 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 { engineFactory, storageOptionsFactory } from './internals';\nimport {\n createFinalStoragePluginOptions,\n FINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from './internals/final-options';\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 provide: FINAL_NGXS_STORAGE_PLUGIN_OPTIONS,\n useFactory: createFinalStoragePluginOptions,\n deps: [Injector, NGXS_STORAGE_PLUGIN_OPTIONS]\n }\n ]\n };\n }\n}\n","import { InjectionToken } from '@angular/core';\n\nimport { StorageEngine } from './symbols';\n\nexport const LOCAL_STORAGE_ENGINE = new InjectionToken<StorageEngine>('LOCAL_STORAGE_ENGINE', {\n providedIn: 'root',\n factory: () => localStorage\n});\n\nexport const SESSION_STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n 'SESSION_STORAGE_ENGINE',\n {\n providedIn: 'root',\n factory: () => sessionStorage\n }\n);\n"],"names":["tslib_1.__values"],"mappings":";;;;;;;;;;AAAA;;IAKE,eAAY;IACZ,iBAAc;;;;;AAGhB,uCAgEC;;;;;;IA5DC,uCAA4C;;;;;;;IAO5C,6CAAmB;;;;;;;IAOnB,2CAAwB;;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2BAA2B,CAAC;iBAC9C;aACF;SACF,CAAC;KACH;;gBAlCF,QAAQ;;IAmCT,8BAAC;CAnCD;;;;;;ACvBA;AAIA,IAAa,oBAAoB,GAAG,IAAI,cAAc,CAAgB,sBAAsB,EAAE;IAC5F,UAAU,EAAE,MAAM;IAClB,OAAO;;;IAAE,cAAM,OAAA,YAAY,GAAA,CAAA;CAC5B,CAAC;;AAEF,IAAa,sBAAsB,GAAG,IAAI,cAAc,CACtD,wBAAwB,EACxB;IACE,UAAU,EAAE,MAAM;IAClB,OAAO;;;IAAE,cAAM,OAAA,cAAc,GAAA,CAAA;CAC9B,CACF;;;;;;;;;;;;;;;;;;;"}
@@ -2,5 +2,6 @@
2
2
  * Generated bundle index. Do not edit.
3
3
  */
4
4
  export * from './index';
5
- export { engineFactory as ɵc, storageOptionsFactory as ɵb } from './src/internals';
5
+ export { engineFactory as ɵf, storageOptionsFactory as ɵe } from './src/internals';
6
+ export { FINAL_NGXS_STORAGE_PLUGIN_OPTIONS as ɵc, FinalNgxsStoragePluginOptions as ɵb, createFinalStoragePluginOptions as ɵd } from './src/internals/final-options';
6
7
  export { USER_OPTIONS as ɵa } from './src/storage.module';
@@ -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":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"}
1
+ {"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":21,"character":32},"arguments":["USER_OPTIONS"]},"NgxsStoragePluginModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":23,"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":32,"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":"ɵe"},"deps":[{"__symbolic":"reference","name":"ɵa"}]},{"provide":{"__symbolic":"reference","name":"STORAGE_ENGINE"},"useFactory":{"__symbolic":"reference","name":"ɵf"},"deps":[{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"},{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":48,"character":46}]},{"provide":{"__symbolic":"reference","name":"ɵc"},"useFactory":{"__symbolic":"reference","name":"ɵd"},"deps":[{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":53,"character":17},{"__symbolic":"reference","name":"NGXS_STORAGE_PLUGIN_OPTIONS"}]}]}}}},"NgxsStoragePlugin":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":26,"character":1}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":34,"character":5},"arguments":[{"__symbolic":"reference","name":"ɵc"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":35,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":35,"character":12}]}]],"parameters":[{"__symbolic":"reference","name":"ɵb"},{"__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":75,"character":47},"arguments":["NGXS_STORAGE_PLUGIN_OPTIONS"]},"STORAGE_ENGINE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":77,"character":34},"arguments":["STORAGE_ENGINE"]},"StorageEngine":{"__symbolic":"interface"},"LOCAL_STORAGE_ENGINE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":4,"character":40},"arguments":["LOCAL_STORAGE_ENGINE",{"__symbolic":"error","message":"Lambda not supported","line":6,"character":11,"module":"./src/engines"}]},"SESSION_STORAGE_ENGINE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":9,"character":42},"arguments":["SESSION_STORAGE_ENGINE",{"__symbolic":"error","message":"Lambda not supported","line":13,"character":13,"module":"./src/engines"}]},"ɵb":{"__symbolic":"interface"},"ɵc":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":12,"character":53},"arguments":["FINAL_NGXS_STORAGE_PLUGIN_OPTIONS"]},"ɵd":{"__symbolic":"function"},"ɵe":{"__symbolic":"function","parameters":["options"],"value":{"__symbolic":"error","message":"Lambda not supported","line":18,"character":21,"module":"./src/internals"}},"ɵf":{"__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","LOCAL_STORAGE_ENGINE":"./src/engines","SESSION_STORAGE_ENGINE":"./src/engines","ɵb":"./src/internals/final-options","ɵc":"./src/internals/final-options","ɵd":"./src/internals/final-options","ɵe":"./src/internals","ɵf":"./src/internals"},"importAs":"@ngxs/storage-plugin"}