@ngxs/storage-plugin 21.0.0 → 22.0.0

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.
@@ -15,7 +15,6 @@ var StorageOption;
15
15
  const ɵUSER_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : '');
16
16
  // Determines whether all states in the NGXS registry should be persisted or not.
17
17
  const ɵALL_STATES_PERSISTED = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ALL_STATES_PERSISTED' : '', {
18
- providedIn: 'root',
19
18
  factory: () => inject(ɵUSER_OPTIONS).keys === '*'
20
19
  });
21
20
  const ɵNGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_STORAGE_PLUGIN_OPTIONS' : '');
@@ -25,6 +24,10 @@ const STORAGE_ENGINE = new InjectionToken(typeof ngDevMode !== 'undefined' && ng
25
24
  function ɵisKeyWithExplicitEngine(key) {
26
25
  return !!key?.engine;
27
26
  }
27
+ /** Determines whether the engine is a factory function rather than a class or InjectionToken. */
28
+ function ɵisEngineFactory(engine) {
29
+ return !(engine instanceof InjectionToken) && !engine.toString().startsWith('class');
30
+ }
28
31
  function ɵextractStringKey(storageKey) {
29
32
  // Extract the actual key out of the `{ key, engine }` structure.
30
33
  if (ɵisKeyWithExplicitEngine(storageKey)) {
@@ -43,5 +46,5 @@ function ɵextractStringKey(storageKey) {
43
46
  * Generated bundle index. Do not edit.
44
47
  */
45
48
 
46
- export { STORAGE_ENGINE, StorageOption, ɵALL_STATES_PERSISTED, ɵDEFAULT_STATE_KEY, ɵNGXS_STORAGE_PLUGIN_OPTIONS, ɵUSER_OPTIONS, ɵextractStringKey, ɵisKeyWithExplicitEngine };
49
+ export { STORAGE_ENGINE, StorageOption, ɵALL_STATES_PERSISTED, ɵDEFAULT_STATE_KEY, ɵNGXS_STORAGE_PLUGIN_OPTIONS, ɵUSER_OPTIONS, ɵextractStringKey, ɵisEngineFactory, ɵisKeyWithExplicitEngine };
47
50
  //# sourceMappingURL=ngxs-storage-plugin-internals.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-storage-plugin-internals.mjs","sources":["../../../packages/storage-plugin/internals/src/symbols.ts","../../../packages/storage-plugin/internals/src/storage-key.ts","../../../packages/storage-plugin/internals/src/ngxs-storage-plugin-internals.ts"],"sourcesContent":["import { InjectionToken, inject } from '@angular/core';\n\nimport { StorageKey } from './storage-key';\n\n/**\n * The following key is used to store the entire serialized\n * state when no specific state is provided.\n */\nexport const ɵDEFAULT_STATE_KEY = '@@STATE';\n\ndeclare const ngDevMode: boolean;\n\nexport enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Keys for the state slice to store in the storage engine.\n */\n keys: '*' | 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 interface ɵNgxsTransformedStoragePluginOptions extends NgxsStoragePluginOptions {\n keys: StorageKey[];\n}\n\nexport const ɵUSER_OPTIONS = new InjectionToken<NgxsStoragePluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : ''\n);\n\n// Determines whether all states in the NGXS registry should be persisted or not.\nexport const ɵALL_STATES_PERSISTED = new InjectionToken<boolean>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ALL_STATES_PERSISTED' : '',\n {\n providedIn: 'root',\n factory: () => inject(ɵUSER_OPTIONS).keys === '*'\n }\n);\n\nexport const ɵNGXS_STORAGE_PLUGIN_OPTIONS =\n new InjectionToken<ɵNgxsTransformedStoragePluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n );\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'STORAGE_ENGINE' : ''\n);\n\nexport interface StorageEngine {\n getItem(key: string): any;\n setItem(key: string, value: any): void;\n}\n","import { InjectionToken, Type } from '@angular/core';\nimport { StateToken } from '@ngxs/store';\nimport { ɵhasOwnProperty, ɵMETA_OPTIONS_KEY, ɵ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?.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\nexport function ɵextractStringKey(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 (ɵhasOwnProperty(storageKey, ɵ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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["ɵhasOwnProperty","ɵMETA_OPTIONS_KEY"],"mappings":";;;;AAIA;;;AAGG;AACI,MAAM,kBAAkB,GAAG;IAItB;AAAZ,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,aAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;AACZ,IAAA,aAAA,CAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,gBAAc;AAChB,CAAC,EAHW,aAAa,KAAb,aAAa,GAGxB,EAAA,CAAA,CAAA;MAwEY,aAAa,GAAG,IAAI,cAAc,CAC7C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,cAAc,GAAG,EAAE;AAGrE;MACa,qBAAqB,GAAG,IAAI,cAAc,CACrD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,sBAAsB,GAAG,EAAE,EAC3E;AACE,IAAA,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,KAAK;AAC/C,CAAA;MAGU,4BAA4B,GACvC,IAAI,cAAc,CAChB,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,6BAA6B,GAAG,EAAE;MAGzE,cAAc,GAAG,IAAI,cAAc,CAC9C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,gBAAgB,GAAG,EAAE;;AC9FvE;AACM,SAAU,wBAAwB,CAAC,GAAQ,EAAA;AAC/C,IAAA,OAAO,CAAC,CAAC,GAAG,EAAE,MAAM;AACtB;AAQM,SAAU,iBAAiB,CAAC,UAAsB,EAAA;;AAEtD,IAAA,IAAI,wBAAwB,CAAC,UAAU,CAAC,EAAE;AACxC,QAAA,UAAU,GAAG,UAAU,CAAC,GAAG;;;;;AAM7B,IAAA,IAAIA,eAAe,CAAC,UAAU,EAAEC,iBAAiB,CAAC,EAAE;AAClD,QAAA,UAAU,GAAI,UAAkB,CAACA,iBAAiB,CAAC,CAAC,IAAI;;AAG1D,IAAA,OAAO,UAAU,YAAY,UAAU,GAAG,UAAU,CAAC,OAAO,EAAE,GAAW,UAAU;AACrF;;ACrCA;;AAEG;;;;"}
1
+ {"version":3,"file":"ngxs-storage-plugin-internals.mjs","sources":["../../../packages/storage-plugin/internals/src/symbols.ts","../../../packages/storage-plugin/internals/src/storage-key.ts","../../../packages/storage-plugin/internals/src/ngxs-storage-plugin-internals.ts"],"sourcesContent":["import { InjectionToken, inject } from '@angular/core';\n\nimport { StorageKey } from './storage-key';\n\n/**\n * The following key is used to store the entire serialized\n * state when no specific state is provided.\n */\nexport const ɵDEFAULT_STATE_KEY = '@@STATE';\n\ndeclare const ngDevMode: boolean;\n\nexport enum StorageOption {\n LocalStorage,\n SessionStorage\n}\n\nexport interface NgxsStoragePluginOptions {\n /**\n * Keys for the state slice to store in the storage engine.\n */\n keys: '*' | 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 interface ɵNgxsTransformedStoragePluginOptions extends NgxsStoragePluginOptions {\n keys: StorageKey[];\n}\n\nexport const ɵUSER_OPTIONS = new InjectionToken<NgxsStoragePluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'USER_OPTIONS' : ''\n);\n\n// Determines whether all states in the NGXS registry should be persisted or not.\nexport const ɵALL_STATES_PERSISTED = new InjectionToken<boolean>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ALL_STATES_PERSISTED' : '',\n {\n factory: () => inject(ɵUSER_OPTIONS).keys === '*'\n }\n);\n\nexport const ɵNGXS_STORAGE_PLUGIN_OPTIONS =\n new InjectionToken<ɵNgxsTransformedStoragePluginOptions>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_STORAGE_PLUGIN_OPTIONS' : ''\n );\n\nexport const STORAGE_ENGINE = new InjectionToken<StorageEngine>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'STORAGE_ENGINE' : ''\n);\n\nexport interface StorageEngine {\n getItem(key: string): any;\n setItem(key: string, value: any): void;\n}\n","import { InjectionToken, Type } from '@angular/core';\nimport { StateToken } from '@ngxs/store';\nimport { ɵhasOwnProperty, ɵMETA_OPTIONS_KEY, ɵ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> | (() => StorageEngine);\n}\n\n/** Determines whether the provided key has the following structure. */\nexport function ɵisKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine {\n return !!key?.engine;\n}\n\n/** Determines whether the engine is a factory function rather than a class or InjectionToken. */\nexport function ɵisEngineFactory(\n engine: Type<StorageEngine> | InjectionToken<StorageEngine> | (() => StorageEngine)\n): engine is () => StorageEngine {\n return !(engine instanceof InjectionToken) && !engine.toString().startsWith('class');\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\nexport function ɵextractStringKey(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 (ɵhasOwnProperty(storageKey, ɵ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","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["ɵhasOwnProperty","ɵMETA_OPTIONS_KEY"],"mappings":";;;;AAIA;;;AAGG;AACI,MAAM,kBAAkB,GAAG;IAItB;AAAZ,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,aAAA,CAAA,cAAA,CAAA,GAAA,CAAA,CAAA,GAAA,cAAY;AACZ,IAAA,aAAA,CAAA,aAAA,CAAA,gBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,gBAAc;AAChB,CAAC,EAHW,aAAa,KAAb,aAAa,GAAA,EAAA,CAAA,CAAA;MA2EZ,aAAa,GAAG,IAAI,cAAc,CAC7C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,cAAc,GAAG,EAAE;AAGrE;MACa,qBAAqB,GAAG,IAAI,cAAc,CACrD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,sBAAsB,GAAG,EAAE,EAC3E;IACE,OAAO,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,KAAK;AAC/C,CAAA;MAGU,4BAA4B,GACvC,IAAI,cAAc,CAChB,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,6BAA6B,GAAG,EAAE;MAGzE,cAAc,GAAG,IAAI,cAAc,CAC9C,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,gBAAgB,GAAG,EAAE;;AC7FvE;AACM,SAAU,wBAAwB,CAAC,GAAQ,EAAA;AAC/C,IAAA,OAAO,CAAC,CAAC,GAAG,EAAE,MAAM;AACtB;AAEA;AACM,SAAU,gBAAgB,CAC9B,MAAmF,EAAA;AAEnF,IAAA,OAAO,EAAE,MAAM,YAAY,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;AACtF;AAQM,SAAU,iBAAiB,CAAC,UAAsB,EAAA;;AAEtD,IAAA,IAAI,wBAAwB,CAAC,UAAU,CAAC,EAAE;AACxC,QAAA,UAAU,GAAG,UAAU,CAAC,GAAG;IAC7B;;;;AAKA,IAAA,IAAIA,eAAe,CAAC,UAAU,EAAEC,iBAAiB,CAAC,EAAE;AAClD,QAAA,UAAU,GAAI,UAAkB,CAACA,iBAAiB,CAAC,CAAC,IAAI;IAC1D;AAEA,IAAA,OAAO,UAAU,YAAY,UAAU,GAAG,UAAU,CAAC,OAAO,EAAE,GAAW,UAAU;AACrF;;AC5CA;;AAEG;;;;"}
@@ -1,8 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, Injector, Injectable, NgModule, makeEnvironmentProviders, provideEnvironmentInitializer, InjectionToken } from '@angular/core';
2
+ import { inject, Injector, runInInjectionContext, Injectable, PLATFORM_ID, NgModule, makeEnvironmentProviders, provideEnvironmentInitializer, InjectionToken } from '@angular/core';
3
3
  import { withNgxsPlugin } from '@ngxs/store';
4
- import { ɵDEFAULT_STATE_KEY as _DEFAULT_STATE_KEY, StorageOption, ɵNGXS_STORAGE_PLUGIN_OPTIONS as _NGXS_STORAGE_PLUGIN_OPTIONS, ɵextractStringKey as _extractStringKey, ɵisKeyWithExplicitEngine as _isKeyWithExplicitEngine, STORAGE_ENGINE, ɵALL_STATES_PERSISTED as _ALL_STATES_PERSISTED, ɵUSER_OPTIONS as _USER_OPTIONS } from '@ngxs/storage-plugin/internals';
4
+ import { ɵDEFAULT_STATE_KEY as _DEFAULT_STATE_KEY, StorageOption, ɵNGXS_STORAGE_PLUGIN_OPTIONS as _NGXS_STORAGE_PLUGIN_OPTIONS, ɵextractStringKey as _extractStringKey, ɵisKeyWithExplicitEngine as _isKeyWithExplicitEngine, ɵisEngineFactory as _isEngineFactory, STORAGE_ENGINE, ɵALL_STATES_PERSISTED as _ALL_STATES_PERSISTED, ɵUSER_OPTIONS as _USER_OPTIONS } from '@ngxs/storage-plugin/internals';
5
5
  export { STORAGE_ENGINE, StorageOption } from '@ngxs/storage-plugin/internals';
6
+ import { isPlatformServer } from '@angular/common';
6
7
  import { ɵhasOwnProperty as _hasOwnProperty } from '@ngxs/store/internals';
7
8
  import { getActionTypeFromInstance, InitState, UpdateState, getValue, setValue } from '@ngxs/store/plugins';
8
9
  import { tap } from 'rxjs';
@@ -63,25 +64,28 @@ class ɵNgxsStoragePluginKeysManager {
63
64
  }
64
65
  this._keys.add(key);
65
66
  const engine = _isKeyWithExplicitEngine(storageKey)
66
- ? this._injector.get(storageKey.engine)
67
+ ? _isEngineFactory(storageKey.engine)
68
+ ? runInInjectionContext(this._injector, storageKey.engine)
69
+ : this._injector.get(storageKey.engine)
67
70
  : this._injector.get(STORAGE_ENGINE);
68
71
  this._keysWithEngines.push({ key, engine });
69
72
  }
70
73
  }
71
- /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNgxsStoragePluginKeysManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
72
- /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNgxsStoragePluginKeysManager, providedIn: 'root' });
74
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: ɵNgxsStoragePluginKeysManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
75
+ /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: ɵNgxsStoragePluginKeysManager });
73
76
  }
74
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNgxsStoragePluginKeysManager, decorators: [{
75
- type: Injectable,
76
- args: [{ providedIn: 'root' }]
77
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: ɵNgxsStoragePluginKeysManager, decorators: [{
78
+ type: Injectable
77
79
  }], ctorParameters: () => [] });
78
80
 
79
81
  class NgxsStoragePlugin {
82
+ _injector = inject(Injector);
80
83
  _keysManager = inject(ɵNgxsStoragePluginKeysManager);
81
84
  _options = inject(_NGXS_STORAGE_PLUGIN_OPTIONS);
82
85
  _allStatesPersisted = inject(_ALL_STATES_PERSISTED);
83
86
  handle(state, event, next) {
84
- if (typeof ngServerMode !== 'undefined' && ngServerMode) {
87
+ if ((typeof ngServerMode !== 'undefined' && ngServerMode) ||
88
+ isPlatformServer(this._injector.get(PLATFORM_ID))) {
85
89
  return next(state, event);
86
90
  }
87
91
  const type = getActionTypeFromInstance(event);
@@ -125,7 +129,8 @@ class NgxsStoragePlugin {
125
129
  storedValue = {};
126
130
  }
127
131
  this._options.migrations?.forEach(strategy => {
128
- const versionMatch = strategy.version === getValue(storedValue, strategy.versionKey || 'version');
132
+ const storedVersion = getValue(storedValue, strategy.versionKey || 'version') ?? 0;
133
+ const versionMatch = strategy.version === storedVersion;
129
134
  const keyMatch = (!strategy.key && this._allStatesPersisted) || strategy.key === key;
130
135
  if (versionMatch && keyMatch) {
131
136
  storedValue = strategy.migrate(storedValue);
@@ -201,19 +206,26 @@ class NgxsStoragePlugin {
201
206
  return accumulator;
202
207
  }, {});
203
208
  }
204
- /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePlugin, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
205
- /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePlugin });
209
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePlugin, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
210
+ /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePlugin });
206
211
  }
207
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePlugin, decorators: [{
212
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePlugin, decorators: [{
208
213
  type: Injectable
209
214
  }] });
210
215
  const DOT = '.';
211
216
 
217
+ /**
218
+ * @deprecated Use `withNgxsStoragePlugin()` instead.
219
+ */
212
220
  class NgxsStoragePluginModule {
221
+ /**
222
+ * @deprecated Use `withNgxsStoragePlugin()` instead.
223
+ */
213
224
  static forRoot(options) {
214
225
  return {
215
226
  ngModule: NgxsStoragePluginModule,
216
227
  providers: [
228
+ ɵNgxsStoragePluginKeysManager,
217
229
  withNgxsPlugin(NgxsStoragePlugin),
218
230
  {
219
231
  provide: _USER_OPTIONS,
@@ -232,15 +244,16 @@ class NgxsStoragePluginModule {
232
244
  ]
233
245
  };
234
246
  }
235
- /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePluginModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
236
- /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePluginModule });
237
- /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePluginModule });
247
+ /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePluginModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
248
+ /** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePluginModule });
249
+ /** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePluginModule });
238
250
  }
239
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: NgxsStoragePluginModule, decorators: [{
251
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: NgxsStoragePluginModule, decorators: [{
240
252
  type: NgModule
241
253
  }] });
242
254
  function withNgxsStoragePlugin(options) {
243
255
  return makeEnvironmentProviders([
256
+ ɵNgxsStoragePluginKeysManager,
244
257
  withNgxsPlugin(NgxsStoragePlugin),
245
258
  {
246
259
  provide: _USER_OPTIONS,
@@ -280,11 +293,9 @@ function withStorageFeature(storageKeys) {
280
293
  }
281
294
 
282
295
  const LOCAL_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'LOCAL_STORAGE_ENGINE' : '', {
283
- providedIn: 'root',
284
296
  factory: () => (typeof ngServerMode !== 'undefined' && ngServerMode ? null : localStorage)
285
297
  });
286
298
  const SESSION_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'SESSION_STORAGE_ENGINE' : '', {
287
- providedIn: 'root',
288
299
  factory: () => typeof ngServerMode !== 'undefined' && ngServerMode ? null : sessionStorage
289
300
  });
290
301
 
@@ -1 +1 @@
1
- {"version":3,"file":"ngxs-storage-plugin.mjs","sources":["../../../packages/storage-plugin/src/internals.ts","../../../packages/storage-plugin/src/keys-manager.ts","../../../packages/storage-plugin/src/storage.plugin.ts","../../../packages/storage-plugin/src/storage.module.ts","../../../packages/storage-plugin/src/with-storage-feature.ts","../../../packages/storage-plugin/src/engines.ts","../../../packages/storage-plugin/index.ts","../../../packages/storage-plugin/ngxs-storage-plugin.ts"],"sourcesContent":["import {\n ɵDEFAULT_STATE_KEY,\n StorageOption,\n StorageEngine,\n NgxsStoragePluginOptions,\n ɵNgxsTransformedStoragePluginOptions\n} from '@ngxs/storage-plugin/internals';\n\ndeclare const ngServerMode: boolean;\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions\n): ɵNgxsTransformedStoragePluginOptions {\n return {\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options,\n keys: options.keys === '*' ? [ɵDEFAULT_STATE_KEY] : options.keys\n };\n}\n\nexport function engineFactory(options: NgxsStoragePluginOptions): StorageEngine | null {\n if (typeof ngServerMode !== 'undefined' && ngServerMode) {\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?.namespace ? `${options.namespace}:${key}` : key;\n}\n","import { Injectable, Injector, inject } from '@angular/core';\nimport {\n STORAGE_ENGINE,\n StorageEngine,\n StorageKey,\n ɵextractStringKey,\n ɵisKeyWithExplicitEngine,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\n\ninterface KeyWithEngine {\n key: string;\n engine: StorageEngine | null;\n}\n\n@Injectable({ providedIn: 'root' })\nexport class ɵNgxsStoragePluginKeysManager {\n /** Store keys separately in a set so we're able to check if the key already exists. */\n private readonly _keys = new Set<string>();\n\n private readonly _injector = inject(Injector);\n\n private readonly _keysWithEngines: KeyWithEngine[] = [];\n\n constructor() {\n const { keys } = inject(ɵNGXS_STORAGE_PLUGIN_OPTIONS);\n this.addKeys(keys);\n }\n\n getKeysWithEngines() {\n // Spread to prevent external code from directly modifying the internal state.\n return [...this._keysWithEngines];\n }\n\n addKeys(storageKeys: StorageKey[]): void {\n for (const storageKey of storageKeys) {\n const key = ɵextractStringKey(storageKey);\n\n // The user may call `withStorageFeature` with the same state multiple times.\n // Let's prevent duplicating state names in the `keysWithEngines` list.\n // Please note that calling provideStates multiple times with the same state is\n // acceptable behavior. This may occur because the state could be necessary at the\n // feature level, and different parts of the application might require its registration.\n // Consequently, `withStorageFeature` may also be called multiple times.\n if (this._keys.has(key)) {\n continue;\n }\n\n this._keys.add(key);\n\n const engine = ɵisKeyWithExplicitEngine(storageKey)\n ? this._injector.get(storageKey.engine)\n : this._injector.get(STORAGE_ENGINE);\n\n this._keysWithEngines.push({ key, engine });\n }\n }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { ɵhasOwnProperty, ɵPlainObject } from '@ngxs/store/internals';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n actionMatcher,\n NgxsNextPluginFn,\n getActionTypeFromInstance\n} from '@ngxs/store/plugins';\nimport {\n ɵDEFAULT_STATE_KEY,\n ɵALL_STATES_PERSISTED,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\nimport { tap } from 'rxjs';\n\nimport { getStorageKey } from './internals';\nimport { ɵNgxsStoragePluginKeysManager } from './keys-manager';\n\ndeclare const ngDevMode: boolean;\ndeclare const ngServerMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n private _keysManager = inject(ɵNgxsStoragePluginKeysManager);\n private _options = inject(ɵNGXS_STORAGE_PLUGIN_OPTIONS);\n private _allStatesPersisted = inject(ɵALL_STATES_PERSISTED);\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (typeof ngServerMode !== 'undefined' && ngServerMode) {\n return next(state, event);\n }\n\n const type = getActionTypeFromInstance(event);\n const isInitAction = type === InitState.type;\n const isUpdateAction = type === UpdateState.type;\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n const addedStates: ɵPlainObject = isUpdateAction && event.addedStates;\n\n for (const { key, engine } of this._keysManager.getKeysWithEngines()) {\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._allStatesPersisted && 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 (!ɵhasOwnProperty(addedStates, stateName)) continue;\n }\n\n // Guard against `engine` being falsy. Since it can be provided via DI,\n // we should assume it may be `null` or `undefined` at runtime and skip it safely.\n if (!engine) continue;\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 typeof ngDevMode !== 'undefined' &&\n 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 this._options.migrations?.forEach(strategy => {\n const versionMatch =\n strategy.version === getValue(storedValue, strategy.versionKey || 'version');\n const keyMatch =\n (!strategy.key && this._allStatesPersisted) || strategy.key === key;\n if (versionMatch && keyMatch) {\n storedValue = strategy.migrate(storedValue);\n hasMigration = true;\n }\n });\n\n if (this._allStatesPersisted) {\n storedValue = this._hydrateSelectivelyOnUpdate(storedValue, addedStates);\n state = { ...state, ...storedValue };\n } else {\n state = setValue(state, key, 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._keysManager.getKeysWithEngines()) {\n if (!engine) continue;\n\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 (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 private _hydrateSelectivelyOnUpdate(storedValue: any, addedStates: ɵPlainObject) {\n // The `UpdateState` action is triggered whenever a feature state is added.\n // The condition below is only satisfied when this action is triggered.\n // Let's consider two states: `counter` and `@ngxs/router-plugin` state.\n // When `provideStore` is called, `CounterState` is provided at the root level,\n // while `@ngxs/router-plugin` is provided as a feature state. Previously, the storage\n // plugin might have stored the value of the counter state as `10`. If `CounterState`\n // implements the `ngxsOnInit` hook and sets the state to `999`, the storage plugin will\n // reset the entire state when the `RouterState` is registered.\n // Consequently, the `counter` state will revert back to `10` instead of `999`.\n\n if (!storedValue || !addedStates || Object.keys(addedStates).length === 0) {\n // Nothing to update if `addedStates` object is empty.\n return storedValue;\n }\n\n // The `storedValue` can be the entire state when the default state key\n // is used. However, if `addedStates` only contains the `router` value,\n // we only want to merge the state with that `router` value.\n // Given the `storedValue` is an object:\n // `{ counter: 10, router: {...} }`\n // This will only select the `router` object from the `storedValue`,\n // avoiding unnecessary rehydration of the `counter` state.\n return Object.keys(addedStates).reduce(\n (accumulator, addedState) => {\n if (ɵhasOwnProperty(storedValue, addedState)) {\n accumulator[addedState] = storedValue[addedState];\n }\n return accumulator;\n },\n <ɵPlainObject>{}\n );\n }\n}\n\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { withNgxsPlugin } from '@ngxs/store';\nimport {\n ɵUSER_OPTIONS,\n STORAGE_ENGINE,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS,\n NgxsStoragePluginOptions\n} from '@ngxs/storage-plugin/internals';\n\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { engineFactory, storageOptionsFactory } from './internals';\n\n@NgModule()\nexport class NgxsStoragePluginModule {\n static forRoot(\n options: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\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]\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]\n }\n ]);\n}\n","import { inject, EnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';\nimport { StorageKey, ɵALL_STATES_PERSISTED } from '@ngxs/storage-plugin/internals';\n\nimport { ɵNgxsStoragePluginKeysManager } from './keys-manager';\n\ndeclare const ngDevMode: boolean;\n\nexport function withStorageFeature(storageKeys: StorageKey[]): EnvironmentProviders {\n return provideEnvironmentInitializer(() => {\n const allStatesPersisted = inject(ɵALL_STATES_PERSISTED);\n\n if (allStatesPersisted) {\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n const message =\n 'The NGXS storage plugin is currently persisting all states because the `keys` ' +\n 'option was explicitly set to `*` at the root level. To selectively persist states, ' +\n 'consider explicitly specifying them, allowing for addition at the feature level.';\n\n console.error(message);\n }\n\n // We should prevent the addition of any feature states to persistence\n // if the `keys` property is set to `*`, as this could disrupt the algorithm\n // used in the storage plugin. Instead, we should log an error in development\n // mode. In production, it should continue to function, but act as a no-op.\n return;\n }\n\n inject(ɵNgxsStoragePluginKeysManager).addKeys(storageKeys);\n });\n}\n","import { InjectionToken } from '@angular/core';\nimport { StorageEngine } from '@ngxs/storage-plugin/internals';\n\ndeclare const ngDevMode: boolean;\ndeclare const ngServerMode: boolean;\n\nexport const LOCAL_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'LOCAL_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () => (typeof ngServerMode !== 'undefined' && ngServerMode ? null : localStorage)\n }\n);\n\nexport const SESSION_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'SESSION_STORAGE_ENGINE' : '',\n {\n providedIn: 'root',\n factory: () =>\n typeof ngServerMode !== 'undefined' && ngServerMode ? null : sessionStorage\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":["ɵDEFAULT_STATE_KEY","ɵNGXS_STORAGE_PLUGIN_OPTIONS","ɵextractStringKey","ɵisKeyWithExplicitEngine","ɵALL_STATES_PERSISTED","ɵhasOwnProperty","ɵUSER_OPTIONS"],"mappings":";;;;;;;;;AAUM,SAAU,qBAAqB,CACnC,OAAiC,EAAA;IAEjC,OAAO;QACL,OAAO,EAAE,aAAa,CAAC,YAAY;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;AACV,QAAA,IAAI,EAAE,OAAO,CAAC,IAAI,KAAK,GAAG,GAAG,CAACA,kBAAkB,CAAC,GAAG,OAAO,CAAC;KAC7D;AACH;AAEM,SAAU,aAAa,CAAC,OAAiC,EAAA;AAC7D,IAAA,IAAI,OAAO,YAAY,KAAK,WAAW,IAAI,YAAY,EAAE;AACvD,QAAA,OAAO,IAAI;;IAGb,IAAI,OAAO,CAAC,OAAO,KAAK,aAAa,CAAC,YAAY,EAAE;AAClD,QAAA,OAAO,YAAY;;SACd,IAAI,OAAO,CAAC,OAAO,KAAK,aAAa,CAAC,cAAc,EAAE;AAC3D,QAAA,OA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AO,CAAC,WAAW,CAAC;AAC5D,KAAC,CAAC;AACJ;;MCxBa,oBAAoB,mBAAmB,IAAI,cAAc,CACpE,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,sBAAsB,GAAG,EAAE,EAC3E;AACE,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,OAAO,OAAO,YAAY,KAAK,WAAW,IAAI,YAAY,GAAG,IAAI,GAAG,YAAY;AAC1F,CAAA;MAGU,sBAAsB,mBAAmB,IAAI,cAAc,CACtE,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,wBAAwB,GAAG,EAAE,EAC7E;AACE,IAAA,UAAU,EAAE,MAAM;AAClB,IAAA,OAAO,EAAE,MACP,OAAO,YAAY,KAAK,WAAW,IAAI,YAAY,GAAG,IAAI,GAAG;AAChE,CAAA;;ACpBH;;AAEG;;ACFH;;AAEG;;;;"}
1
+ {"version":3,"file":"ngxs-storage-plugin.mjs","sources":["../../../packages/storage-plugin/src/internals.ts","../../../packages/storage-plugin/src/keys-manager.ts","../../../packages/storage-plugin/src/storage.plugin.ts","../../../packages/storage-plugin/src/storage.module.ts","../../../packages/storage-plugin/src/with-storage-feature.ts","../../../packages/storage-plugin/src/engines.ts","../../../packages/storage-plugin/index.ts","../../../packages/storage-plugin/ngxs-storage-plugin.ts"],"sourcesContent":["import {\n ɵDEFAULT_STATE_KEY,\n StorageOption,\n StorageEngine,\n NgxsStoragePluginOptions,\n ɵNgxsTransformedStoragePluginOptions\n} from '@ngxs/storage-plugin/internals';\n\ndeclare const ngServerMode: boolean;\n\nexport function storageOptionsFactory(\n options: NgxsStoragePluginOptions\n): ɵNgxsTransformedStoragePluginOptions {\n return {\n storage: StorageOption.LocalStorage,\n serialize: JSON.stringify,\n deserialize: JSON.parse,\n beforeSerialize: obj => obj,\n afterDeserialize: obj => obj,\n ...options,\n keys: options.keys === '*' ? [ɵDEFAULT_STATE_KEY] : options.keys\n };\n}\n\nexport function engineFactory(options: NgxsStoragePluginOptions): StorageEngine | null {\n if (typeof ngServerMode !== 'undefined' && ngServerMode) {\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?.namespace ? `${options.namespace}:${key}` : key;\n}\n","import { Injectable, Injector, inject, runInInjectionContext } from '@angular/core';\nimport {\n STORAGE_ENGINE,\n StorageEngine,\n StorageKey,\n ɵextractStringKey,\n ɵisEngineFactory,\n ɵisKeyWithExplicitEngine,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\n\ninterface KeyWithEngine {\n key: string;\n engine: StorageEngine | null;\n}\n\n@Injectable()\nexport class ɵNgxsStoragePluginKeysManager {\n /** Store keys separately in a set so we're able to check if the key already exists. */\n private readonly _keys = new Set<string>();\n\n private readonly _injector = inject(Injector);\n\n private readonly _keysWithEngines: KeyWithEngine[] = [];\n\n constructor() {\n const { keys } = inject(ɵNGXS_STORAGE_PLUGIN_OPTIONS);\n this.addKeys(keys);\n }\n\n getKeysWithEngines() {\n // Spread to prevent external code from directly modifying the internal state.\n return [...this._keysWithEngines];\n }\n\n addKeys(storageKeys: StorageKey[]): void {\n for (const storageKey of storageKeys) {\n const key = ɵextractStringKey(storageKey);\n\n // The user may call `withStorageFeature` with the same state multiple times.\n // Let's prevent duplicating state names in the `keysWithEngines` list.\n // Please note that calling provideStates multiple times with the same state is\n // acceptable behavior. This may occur because the state could be necessary at the\n // feature level, and different parts of the application might require its registration.\n // Consequently, `withStorageFeature` may also be called multiple times.\n if (this._keys.has(key)) {\n continue;\n }\n\n this._keys.add(key);\n\n const engine = ɵisKeyWithExplicitEngine(storageKey)\n ? ɵisEngineFactory(storageKey.engine)\n ? runInInjectionContext(this._injector, storageKey.engine)\n : this._injector.get(storageKey.engine)\n : this._injector.get(STORAGE_ENGINE);\n\n this._keysWithEngines.push({ key, engine });\n }\n }\n}\n","import { Injectable, Injector, PLATFORM_ID, inject } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport { ɵhasOwnProperty, ɵPlainObject } from '@ngxs/store/internals';\nimport {\n NgxsPlugin,\n setValue,\n getValue,\n InitState,\n UpdateState,\n NgxsNextPluginFn,\n getActionTypeFromInstance\n} from '@ngxs/store/plugins';\nimport {\n ɵDEFAULT_STATE_KEY,\n ɵALL_STATES_PERSISTED,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS\n} from '@ngxs/storage-plugin/internals';\nimport { tap } from 'rxjs';\n\nimport { getStorageKey } from './internals';\nimport { ɵNgxsStoragePluginKeysManager } from './keys-manager';\n\ndeclare const ngDevMode: boolean;\ndeclare const ngServerMode: boolean;\n\n@Injectable()\nexport class NgxsStoragePlugin implements NgxsPlugin {\n private _injector = inject(Injector);\n private _keysManager = inject(ɵNgxsStoragePluginKeysManager);\n private _options = inject(ɵNGXS_STORAGE_PLUGIN_OPTIONS);\n private _allStatesPersisted = inject(ɵALL_STATES_PERSISTED);\n\n handle(state: any, event: any, next: NgxsNextPluginFn) {\n if (\n (typeof ngServerMode !== 'undefined' && ngServerMode) ||\n isPlatformServer(this._injector.get(PLATFORM_ID))\n ) {\n return next(state, event);\n }\n\n const type = getActionTypeFromInstance(event);\n const isInitAction = type === InitState.type;\n const isUpdateAction = type === UpdateState.type;\n const isInitOrUpdateAction = isInitAction || isUpdateAction;\n let hasMigration = false;\n\n if (isInitOrUpdateAction) {\n const addedStates: ɵPlainObject = isUpdateAction && event.addedStates;\n\n for (const { key, engine } of this._keysManager.getKeysWithEngines()) {\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._allStatesPersisted && 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 (!ɵhasOwnProperty(addedStates, stateName)) continue;\n }\n\n // Guard against `engine` being falsy. Since it can be provided via DI,\n // we should assume it may be `null` or `undefined` at runtime and skip it safely.\n if (!engine) continue;\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 typeof ngDevMode !== 'undefined' &&\n 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 this._options.migrations?.forEach(strategy => {\n const storedVersion = getValue(storedValue, strategy.versionKey || 'version') ?? 0;\n const versionMatch = strategy.version === storedVersion;\n const keyMatch =\n (!strategy.key && this._allStatesPersisted) || strategy.key === key;\n if (versionMatch && keyMatch) {\n storedValue = strategy.migrate(storedValue);\n hasMigration = true;\n }\n });\n\n if (this._allStatesPersisted) {\n storedValue = this._hydrateSelectivelyOnUpdate(storedValue, addedStates);\n state = { ...state, ...storedValue };\n } else {\n state = setValue(state, key, 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._keysManager.getKeysWithEngines()) {\n if (!engine) continue;\n\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 (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 private _hydrateSelectivelyOnUpdate(storedValue: any, addedStates: ɵPlainObject) {\n // The `UpdateState` action is triggered whenever a feature state is added.\n // The condition below is only satisfied when this action is triggered.\n // Let's consider two states: `counter` and `@ngxs/router-plugin` state.\n // When `provideStore` is called, `CounterState` is provided at the root level,\n // while `@ngxs/router-plugin` is provided as a feature state. Previously, the storage\n // plugin might have stored the value of the counter state as `10`. If `CounterState`\n // implements the `ngxsOnInit` hook and sets the state to `999`, the storage plugin will\n // reset the entire state when the `RouterState` is registered.\n // Consequently, the `counter` state will revert back to `10` instead of `999`.\n\n if (!storedValue || !addedStates || Object.keys(addedStates).length === 0) {\n // Nothing to update if `addedStates` object is empty.\n return storedValue;\n }\n\n // The `storedValue` can be the entire state when the default state key\n // is used. However, if `addedStates` only contains the `router` value,\n // we only want to merge the state with that `router` value.\n // Given the `storedValue` is an object:\n // `{ counter: 10, router: {...} }`\n // This will only select the `router` object from the `storedValue`,\n // avoiding unnecessary rehydration of the `counter` state.\n return Object.keys(addedStates).reduce(\n (accumulator, addedState) => {\n if (ɵhasOwnProperty(storedValue, addedState)) {\n accumulator[addedState] = storedValue[addedState];\n }\n return accumulator;\n },\n <ɵPlainObject>{}\n );\n }\n}\n\nconst DOT = '.';\n","import {\n NgModule,\n ModuleWithProviders,\n EnvironmentProviders,\n makeEnvironmentProviders\n} from '@angular/core';\nimport { withNgxsPlugin } from '@ngxs/store';\nimport {\n ɵUSER_OPTIONS,\n STORAGE_ENGINE,\n ɵNGXS_STORAGE_PLUGIN_OPTIONS,\n NgxsStoragePluginOptions\n} from '@ngxs/storage-plugin/internals';\n\nimport { NgxsStoragePlugin } from './storage.plugin';\nimport { engineFactory, storageOptionsFactory } from './internals';\nimport { ɵNgxsStoragePluginKeysManager } from './keys-manager';\n\n/**\n * @deprecated Use `withNgxsStoragePlugin()` instead.\n */\n@NgModule()\nexport class NgxsStoragePluginModule {\n /**\n * @deprecated Use `withNgxsStoragePlugin()` instead.\n */\n static forRoot(\n options: NgxsStoragePluginOptions\n ): ModuleWithProviders<NgxsStoragePluginModule> {\n return {\n ngModule: NgxsStoragePluginModule,\n providers: [\n ɵNgxsStoragePluginKeysManager,\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]\n }\n ]\n };\n }\n}\n\nexport function withNgxsStoragePlugin(\n options: NgxsStoragePluginOptions\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n ɵNgxsStoragePluginKeysManager,\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]\n }\n ]);\n}\n","import { inject, EnvironmentProviders, provideEnvironmentInitializer } from '@angular/core';\nimport { StorageKey, ɵALL_STATES_PERSISTED } from '@ngxs/storage-plugin/internals';\n\nimport { ɵNgxsStoragePluginKeysManager } from './keys-manager';\n\ndeclare const ngDevMode: boolean;\n\nexport function withStorageFeature(storageKeys: StorageKey[]): EnvironmentProviders {\n return provideEnvironmentInitializer(() => {\n const allStatesPersisted = inject(ɵALL_STATES_PERSISTED);\n\n if (allStatesPersisted) {\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n const message =\n 'The NGXS storage plugin is currently persisting all states because the `keys` ' +\n 'option was explicitly set to `*` at the root level. To selectively persist states, ' +\n 'consider explicitly specifying them, allowing for addition at the feature level.';\n\n console.error(message);\n }\n\n // We should prevent the addition of any feature states to persistence\n // if the `keys` property is set to `*`, as this could disrupt the algorithm\n // used in the storage plugin. Instead, we should log an error in development\n // mode. In production, it should continue to function, but act as a no-op.\n return;\n }\n\n inject(ɵNgxsStoragePluginKeysManager).addKeys(storageKeys);\n });\n}\n","import { InjectionToken } from '@angular/core';\nimport { StorageEngine } from '@ngxs/storage-plugin/internals';\n\ndeclare const ngDevMode: boolean;\ndeclare const ngServerMode: boolean;\n\nexport const LOCAL_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'LOCAL_STORAGE_ENGINE' : '',\n {\n factory: () => (typeof ngServerMode !== 'undefined' && ngServerMode ? null : localStorage)\n }\n);\n\nexport const SESSION_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'SESSION_STORAGE_ENGINE' : '',\n {\n factory: () =>\n typeof ngServerMode !== 'undefined' && ngServerMode ? null : sessionStorage\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":["ɵDEFAULT_STATE_KEY","ɵNGXS_STORAGE_PLUGIN_OPTIONS","ɵextractStringKey","ɵisKeyWithExplicitEngine","ɵisEngineFactory","ɵALL_STATES_PERSISTED","ɵhasOwnProperty","ɵUSER_OPTIONS"],"mapp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,YAAY;AAC1F,CAAA;MAGU,sBAAsB,mBAAmB,IAAI,cAAc,CACtE,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,GAAG,wBAAwB,GAAG,EAAE,EAC7E;AACE,IAAA,OAAO,EAAE,MACP,OAAO,YAAY,KAAK,WAAW,IAAI,YAAY,GAAG,IAAI,GAAG;AAChE,CAAA;;AClBH;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, ModuleWithProviders, EnvironmentProviders } from '@angular/core';
3
- import { StorageEngine, NgxsStoragePluginOptions, StorageKey } from '@ngxs/storage-plugin/internals';
2
+ import { ModuleWithProviders, EnvironmentProviders, InjectionToken } from '@angular/core';
3
+ import { NgxsStoragePluginOptions, StorageKey, StorageEngine } from '@ngxs/storage-plugin/internals';
4
4
  export { NgxsStoragePluginOptions, STORAGE_ENGINE, StorageEngine, StorageOption } from '@ngxs/storage-plugin/internals';
5
5
  import { NgxsPlugin, NgxsNextPluginFn } from '@ngxs/store/plugins';
6
6
 
7
+ /**
8
+ * @deprecated Use `withNgxsStoragePlugin()` instead.
9
+ */
7
10
  declare class NgxsStoragePluginModule {
11
+ /**
12
+ * @deprecated Use `withNgxsStoragePlugin()` instead.
13
+ */
8
14
  static forRoot(options: NgxsStoragePluginOptions): ModuleWithProviders<NgxsStoragePluginModule>;
9
15
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxsStoragePluginModule, never>;
10
16
  static ɵmod: i0.ɵɵNgModuleDeclaration<NgxsStoragePluginModule, never, never, never>;
@@ -15,6 +21,7 @@ declare function withNgxsStoragePlugin(options: NgxsStoragePluginOptions): Envir
15
21
  declare function withStorageFeature(storageKeys: StorageKey[]): EnvironmentProviders;
16
22
 
17
23
  declare class NgxsStoragePlugin implements NgxsPlugin {
24
+ private _injector;
18
25
  private _keysManager;
19
26
  private _options;
20
27
  private _allStatesPersisted;
@@ -1,14 +1,16 @@
1
- import { InjectionToken, Type } from '@angular/core';
1
+ import { Type, InjectionToken } from '@angular/core';
2
2
  import { StateToken } from '@ngxs/store';
3
3
  import { ɵStateClass as _StateClass } from '@ngxs/store/internals';
4
4
 
5
5
  /** This enables the user to provide a storage engine per individual key. */
6
6
  interface KeyWithExplicitEngine {
7
7
  key: string | _StateClass | StateToken<any>;
8
- engine: Type<StorageEngine> | InjectionToken<StorageEngine>;
8
+ engine: Type<StorageEngine> | InjectionToken<StorageEngine> | (() => StorageEngine);
9
9
  }
10
10
  /** Determines whether the provided key has the following structure. */
11
11
  declare function ɵisKeyWithExplicitEngine(key: any): key is KeyWithExplicitEngine;
12
+ /** Determines whether the engine is a factory function rather than a class or InjectionToken. */
13
+ declare function ɵisEngineFactory(engine: Type<StorageEngine> | InjectionToken<StorageEngine> | (() => StorageEngine)): engine is () => StorageEngine;
12
14
  /**
13
15
  * This tuples all of the possible types allowed in the `key` property.
14
16
  * This is not exposed publicly and used internally only.
@@ -92,5 +94,5 @@ interface StorageEngine {
92
94
  setItem(key: string, value: any): void;
93
95
  }
94
96
 
95
- export { STORAGE_ENGINE, StorageOption, ɵALL_STATES_PERSISTED, ɵDEFAULT_STATE_KEY, ɵNGXS_STORAGE_PLUGIN_OPTIONS, ɵUSER_OPTIONS, ɵextractStringKey, ɵisKeyWithExplicitEngine };
97
+ export { STORAGE_ENGINE, StorageOption, ɵALL_STATES_PERSISTED, ɵDEFAULT_STATE_KEY, ɵNGXS_STORAGE_PLUGIN_OPTIONS, ɵUSER_OPTIONS, ɵextractStringKey, ɵisEngineFactory, ɵisKeyWithExplicitEngine };
96
98
  export type { KeyWithExplicitEngine, NgxsStoragePluginOptions, StorageEngine, StorageKey, ɵNgxsTransformedStoragePluginOptions };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@ngxs/storage-plugin",
3
3
  "description": "extendable storage plugin for @ngxs/store",
4
- "version": "21.0.0",
4
+ "version": "22.0.0",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
- "@ngxs/store": "^21.0.0 || ^21.0.0-dev",
8
- "@angular/core": ">=21.0.0 <22.0.0",
7
+ "@ngxs/store": "^22.0.0 || ^22.0.0-dev",
8
+ "@angular/core": ">=22.0.0 <23.0.0",
9
9
  "rxjs": ">=7.0.0",
10
- "ts-morph": "21.0.1"
10
+ "ts-morph": ">=21.0.0"
11
11
  },
12
12
  "schematics": "./schematics/collection.json",
13
13
  "module": "fesm2022/ngxs-storage-plugin.mjs",
@@ -47,18 +47,9 @@
47
47
  ],
48
48
  "author": "Austin McDaniel",
49
49
  "contributors": [
50
- {
51
- "name": "Danny Blue"
52
- },
53
- {
54
- "name": "Leon Radley"
55
- },
56
50
  {
57
51
  "name": "Mark Whitfeld"
58
52
  },
59
- {
60
- "name": "Maxim Ivanov"
61
- },
62
53
  {
63
54
  "name": "Artur Androsovych"
64
55
  }
@@ -72,4 +63,4 @@
72
63
  "type": "opencollective",
73
64
  "url": "https://opencollective.com/ngxs"
74
65
  }
75
- }
66
+ }