@ngxs/storage-plugin 3.8.1 → 3.8.2-dev.master-a75608e

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 (44) hide show
  1. package/esm2020/internals/final-options.mjs +20 -0
  2. package/esm2020/internals/index.mjs +4 -0
  3. package/esm2020/internals/ngxs-storage-plugin-internals.mjs +5 -0
  4. package/esm2020/internals/storage-key.mjs +20 -0
  5. package/esm2020/internals/symbols.mjs +10 -0
  6. package/esm2020/src/engines.mjs +12 -0
  7. package/esm2020/src/internals.mjs +31 -0
  8. package/esm2020/src/public_api.mjs +5 -0
  9. package/esm2020/src/storage.module.mjs +72 -0
  10. package/esm2020/src/storage.plugin.mjs +141 -0
  11. package/fesm2015/ngxs-storage-plugin-internals.mjs +51 -0
  12. package/fesm2015/ngxs-storage-plugin-internals.mjs.map +1 -0
  13. package/fesm2015/ngxs-storage-plugin.mjs +252 -0
  14. package/fesm2015/ngxs-storage-plugin.mjs.map +1 -0
  15. package/fesm2020/ngxs-storage-plugin-internals.mjs +54 -0
  16. package/fesm2020/ngxs-storage-plugin-internals.mjs.map +1 -0
  17. package/fesm2020/ngxs-storage-plugin.mjs +257 -0
  18. package/fesm2020/ngxs-storage-plugin.mjs.map +1 -0
  19. package/internals/final-options.d.ts +10 -0
  20. package/internals/index.d.ts +3 -0
  21. package/{src/internals → internals}/storage-key.d.ts +6 -6
  22. package/{src → internals}/symbols.d.ts +8 -6
  23. package/package.json +33 -13
  24. package/src/engines.d.ts +3 -3
  25. package/src/internals.d.ts +1 -6
  26. package/src/public_api.d.ts +2 -2
  27. package/src/storage.module.d.ts +3 -2
  28. package/src/storage.plugin.d.ts +2 -2
  29. package/bundles/ngxs-storage-plugin.umd.js +0 -655
  30. package/bundles/ngxs-storage-plugin.umd.js.map +0 -1
  31. package/esm2015/src/engines.js +0 -10
  32. package/esm2015/src/internals/final-options.js +0 -16
  33. package/esm2015/src/internals/storage-key.js +0 -21
  34. package/esm2015/src/internals.js +0 -27
  35. package/esm2015/src/public_api.js +0 -5
  36. package/esm2015/src/storage.module.js +0 -48
  37. package/esm2015/src/storage.plugin.js +0 -145
  38. package/esm2015/src/symbols.js +0 -4
  39. package/fesm2015/ngxs-storage-plugin.js +0 -266
  40. package/fesm2015/ngxs-storage-plugin.js.map +0 -1
  41. package/ngxs-storage-plugin.d.ts +0 -5
  42. package/src/internals/final-options.d.ts +0 -10
  43. /package/{esm2015/index.js → esm2020/index.mjs} +0 -0
  44. /package/{esm2015/ngxs-storage-plugin.js → esm2020/ngxs-storage-plugin.mjs} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngxs-storage-plugin.mjs","sources":["../../../packages/storage-plugin/src/internals.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 { isPlatformServer } from '@angular/common';\nimport {\n ɵDEFAULT_STATE_KEY,\n StorageOption,\n StorageEngine,\n NgxsStoragePluginOptions\n} from '@ngxs/storage-plugin/internals';\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 { 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 {\n ɵDEFAULT_STATE_KEY,\n ɵFinalNgxsStoragePluginOptions,\n ɵFINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\nimport { tap } from 'rxjs/operators';\n\nimport { getStorageKey } from './internals';\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)\n 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';\nimport {\n NgxsStoragePluginOptions,\n STORAGE_ENGINE,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS,\n ɵcreateFinalStoragePluginOptions,\n ɵFINAL_NGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\n\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { engineFactory, storageOptionsFactory } from './internals';\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';\nimport { StorageEngine } from '@ngxs/storage-plugin/internals';\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":";;;;;;;;AAQM,SAAU,qBAAqB,CACnC,OAA6C,EAAA;IAE7C,OAAO;QACL,GAAG,EAAE,CAAC,kBAAkB,CAAC;AACzB,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,IA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MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,cAAc,GAAG,IAAI,CAAC;AAChF,CAAA;;ACrBH;;AAEG;;ACFH;;AAEG;;;;"}
@@ -0,0 +1,10 @@
1
+ import { InjectionToken, Injector } from '@angular/core';
2
+ import { NgxsStoragePluginOptions, StorageEngine } from './symbols';
3
+ export interface ɵFinalNgxsStoragePluginOptions extends NgxsStoragePluginOptions {
4
+ keysWithEngines: {
5
+ key: string;
6
+ engine: StorageEngine;
7
+ }[];
8
+ }
9
+ export declare const ɵFINAL_NGXS_STORAGE_PLUGIN_OPTIONS: InjectionToken<unknown>;
10
+ export declare function ɵcreateFinalStoragePluginOptions(injector: Injector, options: NgxsStoragePluginOptions): ɵFinalNgxsStoragePluginOptions;
@@ -0,0 +1,3 @@
1
+ export * from './symbols';
2
+ export * from './final-options';
3
+ export * from './storage-key';
@@ -1,17 +1,17 @@
1
1
  import { InjectionToken, Type } from '@angular/core';
2
2
  import { StateToken } from '@ngxs/store';
3
- import { StateClass } from '@ngxs/store/internals';
4
- import { StorageEngine } from '../symbols';
3
+ import { ɵStateClass } from '@ngxs/store/internals';
4
+ import { StorageEngine } from './symbols';
5
5
  /** This enables the user to provide a storage engine per individual key. */
6
6
  export interface KeyWithExplicitEngine {
7
- key: string | StateClass | StateToken<any>;
7
+ key: string | ɵStateClass | StateToken<any>;
8
8
  engine: Type<StorageEngine> | InjectionToken<StorageEngine>;
9
9
  }
10
10
  /** Determines whether the provided key has the following structure. */
11
- export declare function isKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine;
11
+ export declare function ɵisKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine;
12
12
  /**
13
13
  * This tuples all of the possible types allowed in the `key` property.
14
14
  * This is not exposed publicly and used internally only.
15
15
  */
16
- export declare type StorageKey = string | StateClass | StateToken<any> | KeyWithExplicitEngine;
17
- export declare function exctractStringKey(storageKey: StorageKey): string;
16
+ export declare type StorageKey = string | ɵStateClass | StateToken<any> | KeyWithExplicitEngine;
17
+ export declare function ɵextractStringKey(storageKey: StorageKey): string;
@@ -1,5 +1,10 @@
1
1
  import { InjectionToken } from '@angular/core';
2
- import { StorageKey } from './internals/storage-key';
2
+ import { StorageKey } from './storage-key';
3
+ /**
4
+ * The following key is used to store the entire serialized
5
+ * state when no specific state is provided.
6
+ */
7
+ export declare const ɵDEFAULT_STATE_KEY = "@@STATE";
3
8
  export declare const enum StorageOption {
4
9
  LocalStorage = 0,
5
10
  SessionStorage = 1
@@ -59,12 +64,9 @@ export interface NgxsStoragePluginOptions {
59
64
  */
60
65
  afterDeserialize?(obj: any, key: string): any;
61
66
  }
62
- export declare const NGXS_STORAGE_PLUGIN_OPTIONS: InjectionToken<unknown>;
67
+ export declare const ɵNGXS_STORAGE_PLUGIN_OPTIONS: InjectionToken<unknown>;
63
68
  export declare const STORAGE_ENGINE: InjectionToken<StorageEngine>;
64
69
  export interface StorageEngine {
65
- readonly length: number;
66
70
  getItem(key: string): any;
67
- setItem(key: string, val: any): void;
68
- removeItem(key: string): void;
69
- clear(): void;
71
+ setItem(key: string, value: any): void;
70
72
  }
package/package.json CHANGED
@@ -1,22 +1,42 @@
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",
6
- "sideEffects": true,
4
+ "version": "3.8.2-dev.master-a75608e",
5
+ "sideEffects": false,
7
6
  "peerDependencies": {
8
- "@ngxs/store": "^3.8.1 || ^3.8.1-dev",
9
- "@angular/core": ">=12.0.0 <17.0.0",
7
+ "@angular/core": ">=12.0.0 <18.0.0",
8
+ "@ngxs/store": "^3.8.2 || ^3.8.2-dev",
10
9
  "rxjs": ">=6.5.5"
11
10
  },
12
- "main": "bundles/ngxs-storage-plugin.umd.js",
13
- "module": "fesm2015/ngxs-storage-plugin.js",
14
- "es2015": "fesm2015/ngxs-storage-plugin.js",
15
- "esm2015": "esm2015/ngxs-storage-plugin.js",
16
- "fesm2015": "fesm2015/ngxs-storage-plugin.js",
17
- "typings": "ngxs-storage-plugin.d.ts",
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
+ "./internals": {
30
+ "types": "./internals/index.d.ts",
31
+ "esm2020": "./esm2020/internals/ngxs-storage-plugin-internals.mjs",
32
+ "es2020": "./fesm2020/ngxs-storage-plugin-internals.mjs",
33
+ "es2015": "./fesm2015/ngxs-storage-plugin-internals.mjs",
34
+ "node": "./fesm2015/ngxs-storage-plugin-internals.mjs",
35
+ "default": "./fesm2020/ngxs-storage-plugin-internals.mjs"
36
+ }
37
+ },
18
38
  "dependencies": {
19
- "tslib": "^2.2.0"
39
+ "tslib": "^2.3.0"
20
40
  },
21
41
  "repository": {
22
42
  "type": "git",
@@ -62,4 +82,4 @@
62
82
  "type": "opencollective",
63
83
  "url": "https://opencollective.com/ngxs"
64
84
  }
65
- }
85
+ }
package/src/engines.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { InjectionToken } from '@angular/core';
2
- import { StorageEngine } from './symbols';
3
- export declare const LOCAL_STORAGE_ENGINE: InjectionToken<StorageEngine>;
4
- export declare const SESSION_STORAGE_ENGINE: InjectionToken<StorageEngine>;
2
+ import { StorageEngine } from '@ngxs/storage-plugin/internals';
3
+ export declare const LOCAL_STORAGE_ENGINE: InjectionToken<StorageEngine | null>;
4
+ export declare const SESSION_STORAGE_ENGINE: InjectionToken<StorageEngine | null>;
@@ -1,9 +1,4 @@
1
- import { StorageEngine, NgxsStoragePluginOptions } from './symbols';
2
- /**
3
- * The following key is used to store the entire serialized
4
- * state when there's no specific state provided.
5
- */
6
- export declare const DEFAULT_STATE_KEY = "@@STATE";
1
+ import { StorageEngine, NgxsStoragePluginOptions } from '@ngxs/storage-plugin/internals';
7
2
  export declare function storageOptionsFactory(options: NgxsStoragePluginOptions | undefined): NgxsStoragePluginOptions;
8
3
  export declare function engineFactory(options: NgxsStoragePluginOptions, platformId: string): StorageEngine | null;
9
4
  export declare function getStorageKey(key: string, options?: NgxsStoragePluginOptions): string;
@@ -1,4 +1,4 @@
1
- export { NgxsStoragePluginModule } from './storage.module';
1
+ export { NgxsStoragePluginModule, withNgxsStoragePlugin } from './storage.module';
2
2
  export { NgxsStoragePlugin } from './storage.plugin';
3
- export * from './symbols';
4
3
  export * from './engines';
4
+ export { StorageOption, NgxsStoragePluginOptions, STORAGE_ENGINE, StorageEngine } from '@ngxs/storage-plugin/internals';
@@ -1,5 +1,5 @@
1
- import { ModuleWithProviders, InjectionToken } from '@angular/core';
2
- import { NgxsStoragePluginOptions } from './symbols';
1
+ import { ModuleWithProviders, InjectionToken, EnvironmentProviders } from '@angular/core';
2
+ import { NgxsStoragePluginOptions } from '@ngxs/storage-plugin/internals';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare const USER_OPTIONS: InjectionToken<unknown>;
5
5
  export declare class NgxsStoragePluginModule {
@@ -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;
@@ -1,12 +1,12 @@
1
1
  import { NgxsPlugin, NgxsNextPluginFn } from '@ngxs/store';
2
- import { FinalNgxsStoragePluginOptions } from './internals/final-options';
2
+ import { ɵFinalNgxsStoragePluginOptions } from '@ngxs/storage-plugin/internals';
3
3
  import * as i0 from "@angular/core";
4
4
  export declare class NgxsStoragePlugin implements NgxsPlugin {
5
5
  private _options;
6
6
  private _platformId;
7
7
  private _keysWithEngines;
8
8
  private _usesDefaultStateKey;
9
- constructor(_options: FinalNgxsStoragePluginOptions, _platformId: string);
9
+ constructor(_options: ɵFinalNgxsStoragePluginOptions, _platformId: string);
10
10
  handle(state: any, event: any, next: NgxsNextPluginFn): any;
11
11
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxsStoragePlugin, never>;
12
12
  static ɵprov: i0.ɵɵInjectableDeclaration<NgxsStoragePlugin>;