@ngxs/storage-plugin 3.8.1-dev.master-5828e37 → 3.8.1-dev.master-98beeea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{esm2015/src/internals/final-options.js → esm2020/src/internals/final-options.mjs} +5 -2
- package/esm2020/src/internals.mjs +35 -0
- package/esm2020/src/public_api.mjs +5 -0
- package/esm2020/src/storage.module.mjs +73 -0
- package/esm2020/src/storage.plugin.mjs +141 -0
- package/fesm2015/ngxs-storage-plugin.mjs +293 -0
- package/fesm2015/ngxs-storage-plugin.mjs.map +1 -0
- package/{fesm2015/ngxs-storage-plugin.js → fesm2020/ngxs-storage-plugin.mjs} +54 -21
- package/fesm2020/ngxs-storage-plugin.mjs.map +1 -0
- package/package.json +22 -10
- package/src/public_api.d.ts +1 -1
- package/src/storage.module.d.ts +2 -1
- package/bundles/ngxs-storage-plugin.umd.js +0 -657
- package/bundles/ngxs-storage-plugin.umd.js.map +0 -1
- package/esm2015/src/internals.js +0 -27
- package/esm2015/src/public_api.js +0 -5
- package/esm2015/src/storage.module.js +0 -49
- package/esm2015/src/storage.plugin.js +0 -143
- package/fesm2015/ngxs-storage-plugin.js.map +0 -1
- package/ngxs-storage-plugin.d.ts +0 -5
- /package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- /package/{esm2015/ngxs-storage-plugin.js → esm2020/ngxs-storage-plugin.mjs} +0 -0
- /package/{esm2015/src/engines.js → esm2020/src/engines.mjs} +0 -0
- /package/{esm2015/src/internals/storage-key.js → esm2020/src/internals/storage-key.mjs} +0 -0
- /package/{esm2015/src/symbols.js → esm2020/src/symbols.mjs} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngxs-storage-plugin.mjs","sources":["../../../packages/storage-plugin/src/symbols.ts","../../../packages/storage-plugin/src/internals.ts","../../../packages/storage-plugin/src/internals/storage-key.ts","../../../packages/storage-plugin/src/internals/final-options.ts","../../../packages/storage-plugin/src/storage.plugin.ts","../../../packages/storage-plugin/src/storage.module.ts","../../../packages/storage-plugin/src/engines.ts","../../../packages/storage-plugin/index.ts","../../../packages/storage-plugin/ngxs-storage-plugin.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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken(\n NG_DEV_MODE ? 'NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n);\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n NG_DEV_MODE ? 'STORAGE_ENGINE' : ''\n);\n\nexport interface StorageEngine {\n getItem(key: string): any;\n setItem(key: string, value: any): 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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const FINAL_NGXS_STORAGE_PLUGIN_OPTIONS =\n new InjectionToken<FinalNgxsStoragePluginOptions>(\n NG_DEV_MODE ? 'FINAL_NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n );\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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\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 NG_DEV_MODE &&\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 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 if (!this._usesDefaultStateKey) {\n state = setValue(state, key, storedValue);\n } else {\n // The `UpdateState` action is dispatched whenever the feature\n // state is added. The condition below is satisfied only when\n // the `UpdateState` action is dispatched. Let's consider two states:\n // `counter` and `@ngxs/router-plugin` state. When we call `NgxsModule.forRoot()`,\n // `CounterState` is provided at the root level, while `@ngxs/router-plugin`\n // is provided as a feature state. Beforehand, the storage plugin may have\n // stored the value of the counter state as `10`. If `CounterState` implements\n // the `ngxsOnInit` hook and calls `ctx.setState(999)`, the storage plugin\n // will rehydrate the entire state when the `RouterState` is registered.\n // Consequently, the `counter` state will revert back to `10` instead of `999`.\n if (storedValue && addedStates && Object.keys(addedStates).length > 0) {\n storedValue = Object.keys(addedStates).reduce((accumulator, addedState) => {\n // The `storedValue` can be equal to the entire state when the default\n // state key is used. However, if `addedStates` only contains the `router` value,\n // we only want to merge the state 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 rehydrated 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 && !hasMigration) {\n return;\n }\n\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: any) {\n if (NG_DEV_MODE) {\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\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n PLATFORM_ID,\n InjectionToken,\n Injector,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { NGXS_PLUGINS, withNgxsPlugin } 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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const USER_OPTIONS = new InjectionToken(NG_DEV_MODE ? '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\nexport function withNgxsStoragePlugin(\n options?: NgxsStoragePluginOptions\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n withNgxsPlugin(NgxsStoragePlugin),\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","import { InjectionToken, PLATFORM_ID, inject } from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\n\nimport { StorageEngine } from './symbols';\n\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const LOCAL_STORAGE_ENGINE = new InjectionToken<StorageEngine | null>(\n NG_DEV_MODE ? 'LOCAL_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? localStorage : null)\n }\n);\n\nexport const SESSION_STORAGE_ENGINE = new InjectionToken<StorageEngine | null>(\n NG_DEV_MODE ? 'SESSION_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? sessionStorage : null)\n }\n);\n","/**\n * The public api for consumers of @ngxs/storage-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["NG_DEV_MODE"],"mappings":";;;;;;AA6EA,MAAMA,aAAW,GAAG,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC;AAErD,MAAA,2BAA2B,GAAG,IAAI,cAAc,CAC3DA,aAAW,GAAG,6BAA6B,GAAG,EAAE,EAChD;AAEW,MAAA,cAAc,GAAG,IAAI,cAAc,CAC9CA,aAAW,GAAG,gBAAgB,GAAG,EAAE;;AChFrC;;;AAGG;AACI,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAErC,SAAU,qBAAqB,CACnC,OAA6C,EAAA;AAE7C,IAAA,OAAA,MAAA,CAAA,MAAA,CAAA,EACE,GAAG,EAAE,CAAC,iBAAiB,CAAC,EACxB,OAAO,EAA4B,CAAA,mCACnC,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,WAAW,EAAE,IAAI,CAAC,KAAK,EACvB,eAAe,EAAE,GAAG,IAAI,GAAG,EAC3B,gBAAgB,EAAE,GAAG,IAAI,GAAG,EAAA,EACzB,OAAO,CACV,CAAA;AACJ,CAAC;AAEe,SAAA,aAAa,CAC3B,OAAiC,EACjC,UAAkB,EAAA;AAElB,IAAA,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE;AAChC,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;AAED,IAAA,IAAI,OAAO,CAAC,OAAO,KAAA,CAAA,mCAAiC;AAClD,QAAA,OAAO,YAAY,CAAC;AACrB,KAAA;AAAM,SAAA,IAAI,OAAO,CAAC,OAAO,KAAA,CAAA,qCAAmC;AAC3D,QAAA,OAAO,cAAc,CAAC;AACvB,KAAA;AAED,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAEe,SAAA,aAAa,CAAC,G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MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC;AAC9E,CAAA,EACD;AAEW,MAAA,sBAAsB,GAAG,IAAI,cAAc,CACtD,WAAW,GAAG,wBAAwB,GAAG,EAAE,EAC3C;AACE,IAAA,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,cAAc,GAAG,IAAI,CAAC;AAChF,CAAA;;ACtBH;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, PLATFORM_ID, Injectable, Inject, Injector, NgModule, inject } from '@angular/core';
|
|
3
|
-
import { StateToken, actionMatcher, InitState, UpdateState, getValue, setValue, NGXS_PLUGINS } from '@ngxs/store';
|
|
2
|
+
import { InjectionToken, PLATFORM_ID, Injectable, Inject, Injector, NgModule, makeEnvironmentProviders, inject } from '@angular/core';
|
|
3
|
+
import { StateToken, actionMatcher, InitState, UpdateState, getValue, setValue, NGXS_PLUGINS, withNgxsPlugin } from '@ngxs/store';
|
|
4
4
|
import { isPlatformServer, isPlatformBrowser } from '@angular/common';
|
|
5
5
|
import { tap } from 'rxjs/operators';
|
|
6
6
|
|
|
@@ -14,16 +14,24 @@ const STORAGE_ENGINE = new InjectionToken(NG_DEV_MODE$4 ? 'STORAGE_ENGINE' : '')
|
|
|
14
14
|
*/
|
|
15
15
|
const DEFAULT_STATE_KEY = '@@STATE';
|
|
16
16
|
function storageOptionsFactory(options) {
|
|
17
|
-
return
|
|
17
|
+
return {
|
|
18
|
+
key: [DEFAULT_STATE_KEY],
|
|
19
|
+
storage: 0 /* StorageOption.LocalStorage */,
|
|
20
|
+
serialize: JSON.stringify,
|
|
21
|
+
deserialize: JSON.parse,
|
|
22
|
+
beforeSerialize: obj => obj,
|
|
23
|
+
afterDeserialize: obj => obj,
|
|
24
|
+
...options
|
|
25
|
+
};
|
|
18
26
|
}
|
|
19
27
|
function engineFactory(options, platformId) {
|
|
20
28
|
if (isPlatformServer(platformId)) {
|
|
21
29
|
return null;
|
|
22
30
|
}
|
|
23
|
-
if (options.storage === 0 /* LocalStorage */) {
|
|
31
|
+
if (options.storage === 0 /* StorageOption.LocalStorage */) {
|
|
24
32
|
return localStorage;
|
|
25
33
|
}
|
|
26
|
-
else if (options.storage === 1 /* SessionStorage */) {
|
|
34
|
+
else if (options.storage === 1 /* StorageOption.SessionStorage */) {
|
|
27
35
|
return sessionStorage;
|
|
28
36
|
}
|
|
29
37
|
return null;
|
|
@@ -65,7 +73,10 @@ function createFinalStoragePluginOptions(injector, options) {
|
|
|
65
73
|
: injector.get(STORAGE_ENGINE);
|
|
66
74
|
return { key, engine };
|
|
67
75
|
});
|
|
68
|
-
return
|
|
76
|
+
return {
|
|
77
|
+
...options,
|
|
78
|
+
keysWithEngines
|
|
79
|
+
};
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
const NG_DEV_MODE$2 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
@@ -78,7 +89,6 @@ class NgxsStoragePlugin {
|
|
|
78
89
|
this._usesDefaultStateKey = this._keysWithEngines.length === 1 && this._keysWithEngines[0].key === DEFAULT_STATE_KEY;
|
|
79
90
|
}
|
|
80
91
|
handle(state, event, next) {
|
|
81
|
-
var _a;
|
|
82
92
|
if (isPlatformServer(this._platformId)) {
|
|
83
93
|
return next(state, event);
|
|
84
94
|
}
|
|
@@ -113,13 +123,12 @@ class NgxsStoragePlugin {
|
|
|
113
123
|
const newVal = this._options.deserialize(storedValue);
|
|
114
124
|
storedValue = this._options.afterDeserialize(newVal, key);
|
|
115
125
|
}
|
|
116
|
-
catch
|
|
117
|
-
|
|
126
|
+
catch {
|
|
127
|
+
NG_DEV_MODE$2 &&
|
|
118
128
|
console.error(`Error ocurred while deserializing the ${storageKey} store value, falling back to empty object, the value obtained from the store: `, storedValue);
|
|
119
|
-
}
|
|
120
129
|
storedValue = {};
|
|
121
130
|
}
|
|
122
|
-
|
|
131
|
+
this._options.migrations?.forEach(strategy => {
|
|
123
132
|
const versionMatch = strategy.version === getValue(storedValue, strategy.versionKey || 'version');
|
|
124
133
|
const keyMatch = (!strategy.key && this._usesDefaultStateKey) || strategy.key === key;
|
|
125
134
|
if (versionMatch && keyMatch) {
|
|
@@ -156,7 +165,7 @@ class NgxsStoragePlugin {
|
|
|
156
165
|
return accumulator;
|
|
157
166
|
}, {});
|
|
158
167
|
}
|
|
159
|
-
state =
|
|
168
|
+
state = { ...state, ...storedValue };
|
|
160
169
|
}
|
|
161
170
|
}
|
|
162
171
|
}
|
|
@@ -191,9 +200,9 @@ class NgxsStoragePlugin {
|
|
|
191
200
|
}));
|
|
192
201
|
}
|
|
193
202
|
}
|
|
194
|
-
/** @nocollapse */ NgxsStoragePlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
195
|
-
/** @nocollapse */ NgxsStoragePlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
196
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
203
|
+
/** @nocollapse */ NgxsStoragePlugin.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePlugin, deps: [{ token: FINAL_NGXS_STORAGE_PLUGIN_OPTIONS }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
204
|
+
/** @nocollapse */ NgxsStoragePlugin.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePlugin });
|
|
205
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePlugin, decorators: [{
|
|
197
206
|
type: Injectable
|
|
198
207
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
199
208
|
type: Inject,
|
|
@@ -239,12 +248,36 @@ class NgxsStoragePluginModule {
|
|
|
239
248
|
};
|
|
240
249
|
}
|
|
241
250
|
}
|
|
242
|
-
/** @nocollapse */ NgxsStoragePluginModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
243
|
-
/** @nocollapse */ NgxsStoragePluginModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
244
|
-
/** @nocollapse */ NgxsStoragePluginModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
245
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
251
|
+
/** @nocollapse */ NgxsStoragePluginModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePluginModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
252
|
+
/** @nocollapse */ NgxsStoragePluginModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePluginModule });
|
|
253
|
+
/** @nocollapse */ NgxsStoragePluginModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePluginModule });
|
|
254
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsStoragePluginModule, decorators: [{
|
|
246
255
|
type: NgModule
|
|
247
256
|
}] });
|
|
257
|
+
function withNgxsStoragePlugin(options) {
|
|
258
|
+
return makeEnvironmentProviders([
|
|
259
|
+
withNgxsPlugin(NgxsStoragePlugin),
|
|
260
|
+
{
|
|
261
|
+
provide: USER_OPTIONS,
|
|
262
|
+
useValue: options
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
266
|
+
useFactory: storageOptionsFactory,
|
|
267
|
+
deps: [USER_OPTIONS]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
provide: STORAGE_ENGINE,
|
|
271
|
+
useFactory: engineFactory,
|
|
272
|
+
deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
provide: FINAL_NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
276
|
+
useFactory: createFinalStoragePluginOptions,
|
|
277
|
+
deps: [Injector, NGXS_STORAGE_PLUGIN_OPTIONS]
|
|
278
|
+
}
|
|
279
|
+
]);
|
|
280
|
+
}
|
|
248
281
|
|
|
249
282
|
const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
250
283
|
const LOCAL_STORAGE_ENGINE = new InjectionToken(NG_DEV_MODE ? 'LOCAL_STORAGE_ENGINE' : '', {
|
|
@@ -264,5 +297,5 @@ const SESSION_STORAGE_ENGINE = new InjectionToken(NG_DEV_MODE ? 'SESSION_STORAGE
|
|
|
264
297
|
* Generated bundle index. Do not edit.
|
|
265
298
|
*/
|
|
266
299
|
|
|
267
|
-
export { LOCAL_STORAGE_ENGINE, NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, SESSION_STORAGE_ENGINE, STORAGE_ENGINE };
|
|
268
|
-
//# sourceMappingURL=ngxs-storage-plugin.
|
|
300
|
+
export { LOCAL_STORAGE_ENGINE, NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, SESSION_STORAGE_ENGINE, STORAGE_ENGINE, withNgxsStoragePlugin };
|
|
301
|
+
//# sourceMappingURL=ngxs-storage-plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ngxs-storage-plugin.mjs","sources":["../../../packages/storage-plugin/src/symbols.ts","../../../packages/storage-plugin/src/internals.ts","../../../packages/storage-plugin/src/internals/storage-key.ts","../../../packages/storage-plugin/src/internals/final-options.ts","../../../packages/storage-plugin/src/storage.plugin.ts","../../../packages/storage-plugin/src/storage.module.ts","../../../packages/storage-plugin/src/engines.ts","../../../packages/storage-plugin/index.ts","../../../packages/storage-plugin/ngxs-storage-plugin.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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken(\n NG_DEV_MODE ? 'NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n);\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n NG_DEV_MODE ? 'STORAGE_ENGINE' : ''\n);\n\nexport interface StorageEngine {\n getItem(key: string): any;\n setItem(key: string, value: any): 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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const FINAL_NGXS_STORAGE_PLUGIN_OPTIONS =\n new InjectionToken<FinalNgxsStoragePluginOptions>(\n NG_DEV_MODE ? 'FINAL_NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n );\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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\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 NG_DEV_MODE &&\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 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 if (!this._usesDefaultStateKey) {\n state = setValue(state, key, storedValue);\n } else {\n // The `UpdateState` action is dispatched whenever the feature\n // state is added. The condition below is satisfied only when\n // the `UpdateState` action is dispatched. Let's consider two states:\n // `counter` and `@ngxs/router-plugin` state. When we call `NgxsModule.forRoot()`,\n // `CounterState` is provided at the root level, while `@ngxs/router-plugin`\n // is provided as a feature state. Beforehand, the storage plugin may have\n // stored the value of the counter state as `10`. If `CounterState` implements\n // the `ngxsOnInit` hook and calls `ctx.setState(999)`, the storage plugin\n // will rehydrate the entire state when the `RouterState` is registered.\n // Consequently, the `counter` state will revert back to `10` instead of `999`.\n if (storedValue && addedStates && Object.keys(addedStates).length > 0) {\n storedValue = Object.keys(addedStates).reduce((accumulator, addedState) => {\n // The `storedValue` can be equal to the entire state when the default\n // state key is used. However, if `addedStates` only contains the `router` value,\n // we only want to merge the state 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 rehydrated 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 && !hasMigration) {\n return;\n }\n\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: any) {\n if (NG_DEV_MODE) {\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\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n PLATFORM_ID,\n InjectionToken,\n Injector,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { NGXS_PLUGINS, withNgxsPlugin } 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\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const USER_OPTIONS = new InjectionToken(NG_DEV_MODE ? '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\nexport function withNgxsStoragePlugin(\n options?: NgxsStoragePluginOptions\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n withNgxsPlugin(NgxsStoragePlugin),\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","import { InjectionToken, PLATFORM_ID, inject } from '@angular/core';\nimport { isPlatformBrowser } from '@angular/common';\n\nimport { StorageEngine } from './symbols';\n\ndeclare const ngDevMode: boolean;\n\nconst NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;\n\nexport const LOCAL_STORAGE_ENGINE = new InjectionToken<StorageEngine | null>(\n NG_DEV_MODE ? 'LOCAL_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? localStorage : null)\n }\n);\n\nexport const SESSION_STORAGE_ENGINE = new InjectionToken<StorageEngine | null>(\n NG_DEV_MODE ? 'SESSION_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? sessionStorage : null)\n }\n);\n","/**\n * The public api for consumers of @ngxs/storage-plugin\n */\nexport * from './src/public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["NG_DEV_MODE"],"mappings":";;;;;;AA6EA,MAAMA,aAAW,GAAG,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC;AAErD,MAAA,2BAA2B,GAAG,IAAI,cAAc,CAC3DA,aAAW,GAAG,6BAA6B,GAAG,EAAE,EAChD;AAEW,MAAA,cAAc,GAAG,IAAI,cAAc,CAC9CA,aAAW,GAAG,gBAAgB,GAAG,EAAE;;AChFrC;;;AAGG;AACI,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAErC,SAAU,qBAAqB,CACnC,OAA6C,EAAA;IAE7C,OAAO;QACL,GAAG,EAAE,CAAC,iBAAiB,CAAC;AACxB,QAAA,OAAO,EAA4B,CAAA;QACnC,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,WAAW,EAAE,IAAI,CAAC,KAAK;AACvB,QAAA,eAAe,EAAE,GAAG,IAAI,GAAG;AAC3B,QAAA,gBAAgB,EAAE,GAAG,IAAI,GAAG;AAC5B,QAAA,GAAG,OAAO;KACX,CAAC;AACJ,CAAC;AAEe,SAAA,aAAa,CAC3B,OAAiC,EACjC,UAAkB,EAAA;AAElB,IAAA,IAAI,gBAAgB,CAAC,UAAU,CAAC,EAAE;AAChC,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;AAED,IAAA,IAAI,OAAO,CAAC,OAAO,KAAA,CAAA,mCAAiC;AAClD,QAAA,OAAO,YAAY,CAAC;AACrB,KAAA;AAAM,SAAA,IAAI,OAAO,CAAC,OAAO,KAAA,CAAA,qCAAmC;AAC3D,QAAA,OAAO,cAAc,CAAC;AACvB,KAAA;AAED,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAEe,SAA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,wBAAwB,GAAG,EAAE,EAC3C;AACE,IAAA,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,OAAO,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,cAAc,GAAG,IAAI,CAAC;AAChF,CAAA;;ACtBH;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "../../node_modules/ng-packagr/package.schema.json",
|
|
3
2
|
"name": "@ngxs/storage-plugin",
|
|
4
3
|
"description": "extendable storage plugin for @ngxs/store",
|
|
5
|
-
"version": "3.8.1-dev.master-
|
|
6
|
-
"sideEffects":
|
|
4
|
+
"version": "3.8.1-dev.master-98beeea",
|
|
5
|
+
"sideEffects": false,
|
|
7
6
|
"peerDependencies": {
|
|
8
7
|
"@angular/core": ">=12.0.0 <17.0.0",
|
|
9
8
|
"@ngxs/store": "^3.8.1 || ^3.8.1-dev",
|
|
10
9
|
"rxjs": ">=6.5.5"
|
|
11
10
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"fesm2015": "fesm2015/ngxs-storage-plugin.
|
|
17
|
-
"typings": "
|
|
11
|
+
"module": "fesm2015/ngxs-storage-plugin.mjs",
|
|
12
|
+
"es2020": "fesm2020/ngxs-storage-plugin.mjs",
|
|
13
|
+
"esm2020": "esm2020/ngxs-storage-plugin.mjs",
|
|
14
|
+
"fesm2020": "fesm2020/ngxs-storage-plugin.mjs",
|
|
15
|
+
"fesm2015": "fesm2015/ngxs-storage-plugin.mjs",
|
|
16
|
+
"typings": "index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": {
|
|
19
|
+
"default": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"esm2020": "./esm2020/ngxs-storage-plugin.mjs",
|
|
24
|
+
"es2020": "./fesm2020/ngxs-storage-plugin.mjs",
|
|
25
|
+
"es2015": "./fesm2015/ngxs-storage-plugin.mjs",
|
|
26
|
+
"node": "./fesm2015/ngxs-storage-plugin.mjs",
|
|
27
|
+
"default": "./fesm2020/ngxs-storage-plugin.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
18
30
|
"dependencies": {
|
|
19
|
-
"tslib": "^2.
|
|
31
|
+
"tslib": "^2.3.0"
|
|
20
32
|
},
|
|
21
33
|
"repository": {
|
|
22
34
|
"type": "git",
|
package/src/public_api.d.ts
CHANGED
package/src/storage.module.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ModuleWithProviders, InjectionToken } from '@angular/core';
|
|
1
|
+
import { ModuleWithProviders, InjectionToken, EnvironmentProviders } from '@angular/core';
|
|
2
2
|
import { NgxsStoragePluginOptions } from './symbols';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export declare const USER_OPTIONS: InjectionToken<unknown>;
|
|
@@ -8,3 +8,4 @@ export declare class NgxsStoragePluginModule {
|
|
|
8
8
|
static ɵmod: i0.ɵɵNgModuleDeclaration<NgxsStoragePluginModule, never, never, never>;
|
|
9
9
|
static ɵinj: i0.ɵɵInjectorDeclaration<NgxsStoragePluginModule>;
|
|
10
10
|
}
|
|
11
|
+
export declare function withNgxsStoragePlugin(options?: NgxsStoragePluginOptions): EnvironmentProviders;
|