@ngxs/storage-plugin 20.1.0-dev.master-18598cd → 20.1.0-dev.master-2473470
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/fesm2022/ngxs-storage-plugin.mjs +4 -4
- package/fesm2022/ngxs-storage-plugin.mjs.map +1 -1
- package/package.json +1 -1
- package/schematics/collection.json +12 -0
- package/schematics/src/ng-generate/__snapshots__/keys-migration.spec.ts.snap +125 -0
- package/schematics/src/ng-generate/index.js +90 -0
- package/schematics/src/ng-generate/index.js.map +1 -0
- package/schematics/src/ng-generate/schema.json +7 -0
- package/schematics/src/utils/versions.json +3 -0
- package/schematics/src/utils/visit-files.js +23 -0
- package/schematics/src/utils/visit-files.js.map +1 -0
|
@@ -4,7 +4,7 @@ import { withNgxsPlugin } from '@ngxs/store';
|
|
|
4
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';
|
|
5
5
|
export { STORAGE_ENGINE, StorageOption } from '@ngxs/storage-plugin/internals';
|
|
6
6
|
import { ɵhasOwnProperty as _hasOwnProperty } from '@ngxs/store/internals';
|
|
7
|
-
import {
|
|
7
|
+
import { getActionTypeFromInstance, InitState, UpdateState, getValue, setValue } from '@ngxs/store/plugins';
|
|
8
8
|
import { tap } from 'rxjs';
|
|
9
9
|
|
|
10
10
|
function storageOptionsFactory(options) {
|
|
@@ -84,9 +84,9 @@ class NgxsStoragePlugin {
|
|
|
84
84
|
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
|
|
85
85
|
return next(state, event);
|
|
86
86
|
}
|
|
87
|
-
const
|
|
88
|
-
const isInitAction =
|
|
89
|
-
const isUpdateAction =
|
|
87
|
+
const type = getActionTypeFromInstance(event);
|
|
88
|
+
const isInitAction = type === InitState.type;
|
|
89
|
+
const isUpdateAction = type === UpdateState.type;
|
|
90
90
|
const isInitOrUpdateAction = isInitAction || isUpdateAction;
|
|
91
91
|
let hasMigration = false;
|
|
92
92
|
if (isInitOrUpdateAction) {
|
|
@@ -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} 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 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: ɵ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,cAA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CAAC,OAAO,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 } 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,KA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D,OAAO,6BAA6B,CAAC,MAAK;AACxC,QAAA,MAAM,kBAAkB,GAAG,MAAM,CAACG,qBAAqB,CAAC;QAExD,IAAI,kBAAkB,EAAE;AACtB,YAAA,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,EAAE;gBACjD,MAAM,OAAO,GACX,gFAAgF;oBAChF,qFAAqF;AACrF,oBAAA,kFAAkF;AAEpF,gBAAA,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;;;;;;YAOxB;;QAGF,MAAM,CAAC,6BAA6B,CAAC,CAAC,OAAO,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngxs/storage-plugin",
|
|
3
3
|
"description": "extendable storage plugin for @ngxs/store",
|
|
4
|
-
"version": "20.1.0-dev.master-
|
|
4
|
+
"version": "20.1.0-dev.master-2473470",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"@angular/core": ">=20.0.0 <21.0.0",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["@schematics/angular"],
|
|
3
|
+
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
|
|
4
|
+
"schematics": {
|
|
5
|
+
"keys-migration": {
|
|
6
|
+
"factory": "./src/ng-generate/index#migrateKeys",
|
|
7
|
+
"description": "Migrates from key to keys",
|
|
8
|
+
"aliases": ["ngxs-keys-migration"],
|
|
9
|
+
"schema": "./src/ng-generate/schema.json"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Storage Plugin Migration migrate empty forRoot 1`] = `
|
|
4
|
+
"
|
|
5
|
+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
|
|
6
|
+
import { NgModule } from '@angular/core';
|
|
7
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
8
|
+
|
|
9
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
10
|
+
import { AppComponent } from './app.component';
|
|
11
|
+
|
|
12
|
+
@NgModule({
|
|
13
|
+
declarations: [
|
|
14
|
+
AppComponent
|
|
15
|
+
],
|
|
16
|
+
imports: [
|
|
17
|
+
BrowserModule,
|
|
18
|
+
AppRoutingModule,
|
|
19
|
+
NgxsStoragePluginModule.forRoot({ keys: '*' })
|
|
20
|
+
],
|
|
21
|
+
bootstrap: [AppComponent]
|
|
22
|
+
})
|
|
23
|
+
export class AppModule { }
|
|
24
|
+
"
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
exports[`Storage Plugin Migration migrate forRoot that has the "key" property with a value as a string literal 1`] = `
|
|
28
|
+
"
|
|
29
|
+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
|
|
30
|
+
import { NgModule } from '@angular/core';
|
|
31
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
32
|
+
|
|
33
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
34
|
+
import { AppComponent } from './app.component';
|
|
35
|
+
|
|
36
|
+
@NgModule({
|
|
37
|
+
declarations: [
|
|
38
|
+
AppComponent
|
|
39
|
+
],
|
|
40
|
+
imports: [
|
|
41
|
+
BrowserModule,
|
|
42
|
+
AppRoutingModule,
|
|
43
|
+
NgxsStoragePluginModule.forRoot({proa: 'valuea', prob: 'valueb', keys: ['keep this value']})
|
|
44
|
+
],
|
|
45
|
+
bootstrap: [AppComponent]
|
|
46
|
+
})
|
|
47
|
+
export class AppModule { }
|
|
48
|
+
"
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
exports[`Storage Plugin Migration migrate forRoot that has the "key" property with values as an array literal 1`] = `
|
|
52
|
+
"
|
|
53
|
+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
|
|
54
|
+
import { NgModule } from '@angular/core';
|
|
55
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
56
|
+
|
|
57
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
58
|
+
import { AppComponent } from './app.component';
|
|
59
|
+
|
|
60
|
+
@NgModule({
|
|
61
|
+
declarations: [
|
|
62
|
+
AppComponent
|
|
63
|
+
],
|
|
64
|
+
imports: [
|
|
65
|
+
BrowserModule,
|
|
66
|
+
AppRoutingModule,
|
|
67
|
+
NgxsStoragePluginModule.forRoot({proa: 'valuea', prob: 'valueb', keys: ['keyValue', NovelsState, { key: 'novels', engine: MyEngineX } ]})
|
|
68
|
+
],
|
|
69
|
+
bootstrap: [AppComponent]
|
|
70
|
+
})
|
|
71
|
+
export class AppModule { }
|
|
72
|
+
"
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
exports[`Storage Plugin Migration migrate forRoot that is missing the "key" property 1`] = `
|
|
76
|
+
"
|
|
77
|
+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
|
|
78
|
+
import { NgModule } from '@angular/core';
|
|
79
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
80
|
+
|
|
81
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
82
|
+
import { AppComponent } from './app.component';
|
|
83
|
+
|
|
84
|
+
@NgModule({
|
|
85
|
+
declarations: [
|
|
86
|
+
AppComponent
|
|
87
|
+
],
|
|
88
|
+
imports: [
|
|
89
|
+
BrowserModule,
|
|
90
|
+
AppRoutingModule,
|
|
91
|
+
NgxsStoragePluginModule.forRoot({proa: 'valuea', prob: 'valueb',
|
|
92
|
+
keys: '*'
|
|
93
|
+
})
|
|
94
|
+
],
|
|
95
|
+
bootstrap: [AppComponent]
|
|
96
|
+
})
|
|
97
|
+
export class AppModule { }
|
|
98
|
+
"
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
exports[`Storage Plugin Migration migrate from a constant array 1`] = `
|
|
102
|
+
"
|
|
103
|
+
import { NgxsStoragePluginModule } from '@ngxs/storage-plugin';
|
|
104
|
+
import { NgModule } from '@angular/core';
|
|
105
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
106
|
+
|
|
107
|
+
import { AppRoutingModule } from './app-routing.module';
|
|
108
|
+
import { AppComponent } from './app.component';
|
|
109
|
+
|
|
110
|
+
const imports = [
|
|
111
|
+
BrowserModule,
|
|
112
|
+
AppRoutingModule,
|
|
113
|
+
NgxsStoragePluginModule.forRoot({proa: 'valuea', prob: 'valueb', keys: ['keep this value']})
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
@NgModule({
|
|
117
|
+
declarations: [
|
|
118
|
+
AppComponent
|
|
119
|
+
],
|
|
120
|
+
imports,
|
|
121
|
+
bootstrap: [AppComponent]
|
|
122
|
+
})
|
|
123
|
+
export class AppModule { }
|
|
124
|
+
"
|
|
125
|
+
`;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateKeys = migrateKeys;
|
|
4
|
+
const node_process_1 = require("node:process");
|
|
5
|
+
const ts = require("ts-morph");
|
|
6
|
+
const visit_files_1 = require("../utils/visit-files");
|
|
7
|
+
function migrateEmptyForRoot(callExpression) {
|
|
8
|
+
callExpression.addArgument(`{ keys: '*' }`);
|
|
9
|
+
}
|
|
10
|
+
function migrateForRootWithArgs(arg) {
|
|
11
|
+
const objectLiteral = arg;
|
|
12
|
+
const hasPropertyName = (name) => objectLiteral.getProperties().some(prop => {
|
|
13
|
+
return ts.Node.isPropertyAssignment(prop) && prop.getName() === name;
|
|
14
|
+
});
|
|
15
|
+
const isAlreadyMigrated = hasPropertyName('keys');
|
|
16
|
+
// If the "keys" property is already there, we should not try migrating
|
|
17
|
+
if (isAlreadyMigrated) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const hasKeyProperty = hasPropertyName('key');
|
|
21
|
+
// Add the "keys" property if it's not there
|
|
22
|
+
if (!hasKeyProperty) {
|
|
23
|
+
objectLiteral.addPropertyAssignment({ name: 'keys', initializer: `'*'` });
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// Rename the "key" property to "keys"
|
|
27
|
+
const keyProperty = objectLiteral.getProperty('key');
|
|
28
|
+
const propertyName = keyProperty === null || keyProperty === void 0 ? void 0 : keyProperty.getChildAtIndex(0);
|
|
29
|
+
const propertyValue = keyProperty === null || keyProperty === void 0 ? void 0 : keyProperty.getChildAtIndex(2);
|
|
30
|
+
propertyName === null || propertyName === void 0 ? void 0 : propertyName.replaceWithText('keys');
|
|
31
|
+
// if the property value is a string literal, then we should wrap it in an array
|
|
32
|
+
// We are checking the isStringLiteral to avoid wrapping a value that is already an array
|
|
33
|
+
if (ts.Node.isStringLiteral(propertyValue)) {
|
|
34
|
+
propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.replaceWithText(`[${propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.getText()}]`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function isStoragePluginProvided(callExpression) {
|
|
39
|
+
return (callExpression && callExpression.getText().includes('NgxsStoragePluginModule.forRoot'));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* We do not use the ts.Node.isCallExpression(node) because the underlying implementation
|
|
43
|
+
* uses -> node.getKind() === typescript.SyntaxKind.CallExpression
|
|
44
|
+
* which is an enum that can return different numbers depending on minor typescript package versions
|
|
45
|
+
*/
|
|
46
|
+
function isCallExpression(node) {
|
|
47
|
+
return node.getKindName() === 'CallExpression';
|
|
48
|
+
}
|
|
49
|
+
function migrateKeys() {
|
|
50
|
+
return (tree, _context) => {
|
|
51
|
+
const tsProject = new ts.Project({ useInMemoryFileSystem: true });
|
|
52
|
+
const packageJson = tree.readJson('package.json');
|
|
53
|
+
const storePackage = packageJson['dependencies']['@ngxs/store'];
|
|
54
|
+
if (!storePackage) {
|
|
55
|
+
_context.logger.error(`No @ngxs/store found`);
|
|
56
|
+
return (0, node_process_1.exit)(1);
|
|
57
|
+
}
|
|
58
|
+
(0, visit_files_1.visitTsFiles)(tree, tree.root, path => {
|
|
59
|
+
const fileContent = tree.readText(path);
|
|
60
|
+
const sourceFile = tsProject.createSourceFile(path, fileContent);
|
|
61
|
+
const hasStoragePluginImported = sourceFile.getImportDeclaration(importDecl => importDecl.getModuleSpecifierValue() === '@ngxs/storage-plugin');
|
|
62
|
+
// do not try migrating if the storage plugin is not imported
|
|
63
|
+
if (!hasStoragePluginImported) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
sourceFile.forEachDescendant(node => {
|
|
67
|
+
if (isCallExpression(node) &&
|
|
68
|
+
ts.Node.isPropertyAccessExpression(node.getExpression())) {
|
|
69
|
+
const callExpression = node;
|
|
70
|
+
// If the storage plugin is not provided, we should not try migrating
|
|
71
|
+
if (!isStoragePluginProvided(callExpression)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const args = callExpression.getArguments();
|
|
75
|
+
// If there are no arguments in the forRoot(), then add the `keys` property
|
|
76
|
+
if (!args.length) {
|
|
77
|
+
_context.logger.info(`Migrating empty forRoot in ${path}`);
|
|
78
|
+
migrateEmptyForRoot(callExpression);
|
|
79
|
+
}
|
|
80
|
+
else if (ts.Node.isObjectLiteralExpression(args[0])) {
|
|
81
|
+
_context.logger.info(`Migrating forRoot with args in ${path}`);
|
|
82
|
+
migrateForRootWithArgs(args[0]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
tree.overwrite(path, sourceFile.getFullText());
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/storage-plugin/schematics/src/ng-generate/index.ts"],"names":[],"mappings":";;AA4DA,kCAkDC;AA9GD,+CAAoC;AACpC,+BAA+B;AAG/B,sDAAoD;AAEpD,SAAS,mBAAmB,CAAC,cAAuD;IAClF,cAAc,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;AAC9C,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAwB;IACtD,MAAM,aAAa,GAAG,GAAiC,CAAC;IAExD,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,EAAE,CACvC,aAAa,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QACxC,OAAO,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,CAAC;IACvE,CAAC,CAAC,CAAC;IAEL,MAAM,iBAAiB,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAElD,uEAAuE;IACvE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO;IACT,CAAC;IAED,MAAM,cAAc,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IAE9C,4CAA4C;IAC5C,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,aAAa,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,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AC,CAAC,CAAC,EAAE,CAAC;wBACtD,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC;wBAC/D,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.visitTsFiles = visitTsFiles;
|
|
4
|
+
function visitTsFiles(tree, dirPath = tree.root, visitor) {
|
|
5
|
+
function visit(directory) {
|
|
6
|
+
for (const path of directory.subfiles) {
|
|
7
|
+
if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
|
|
8
|
+
const entry = directory.file(path);
|
|
9
|
+
if (entry) {
|
|
10
|
+
visitor(entry.path);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
for (const path of directory.subdirs) {
|
|
15
|
+
if (path === 'node_modules') {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
visit(directory.dir(path));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
visit(dirPath);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=visit-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visit-files.js","sourceRoot":"","sources":["../../../../../packages/storage-plugin/schematics/src/utils/visit-files.ts"],"names":[],"mappings":";;AAEA,oCAyBC;AAzBD,SAAgB,YAAY,CAC1B,IAAU,EACV,OAAO,GAAG,IAAI,CAAC,IAAI,EACnB,OAA+B;IAE/B,SAAS,KAAK,CAAC,SAAmB;QAChC,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;YACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpD,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACnC,IAAI,KAAK,EAAE,CAAC;oBACV,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,OAAO,EAAE,CAAC;YACrC,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;gBAC5B,SAAS;YACX,CAAC;YAED,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,CAAC;AACjB,CAAC"}
|