@ngxs/storage-plugin 19.0.0-dev.master-d141408 → 19.0.0-dev.master-a8d8453

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.
@@ -23,7 +23,7 @@ const STORAGE_ENGINE = new InjectionToken(typeof ngDevMode !== 'undefined' && ng
23
23
 
24
24
  /** Determines whether the provided key has the following structure. */
25
25
  function ɵisKeyWithExplicitEngine(key) {
26
- return key != null && !!key.engine;
26
+ return !!key?.engine;
27
27
  }
28
28
  function ɵextractStringKey(storageKey) {
29
29
  // Extract the actual key out of the `{ key, engine }` structure.
@@ -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 != null && !!key.engine;\n}\n\n/**\n * This tuples all of the possible types allowed in the `key` property.\n * This is not exposed publicly and used internally only.\n */\nexport type StorageKey = string | ɵStateClass | StateToken<any> | KeyWithExplicitEngine;\n\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;IAC/C,OAAO,GAAG,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACpC;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 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;;;;"}
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": "19.0.0-dev.master-d141408",
4
+ "version": "19.0.0-dev.master-a8d8453",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
7
7
  "@angular/core": ">=19.0.0 <20.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,98 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.migrateKeys = migrateKeys;
13
+ const node_process_1 = require("node:process");
14
+ const ts = require("ts-morph");
15
+ const visit_files_1 = require("../utils/visit-files");
16
+ function migrateEmptyForRoot(callExpression) {
17
+ callExpression.addArgument(`{ keys: '*' }`);
18
+ }
19
+ function migrateForRootWithArgs(arg) {
20
+ const objectLiteral = arg;
21
+ const hasPropertyName = (name) => objectLiteral.getProperties().some(prop => {
22
+ return ts.Node.isPropertyAssignment(prop) && prop.getName() === name;
23
+ });
24
+ const isAlreadyMigrated = hasPropertyName('keys');
25
+ // If the "keys" property is already there, we should not try migrating
26
+ if (isAlreadyMigrated) {
27
+ return;
28
+ }
29
+ const hasKeyProperty = hasPropertyName('key');
30
+ // Add the "keys" property if it's not there
31
+ if (!hasKeyProperty) {
32
+ objectLiteral.addPropertyAssignment({ name: 'keys', initializer: `'*'` });
33
+ }
34
+ else {
35
+ // Rename the "key" property to "keys"
36
+ const keyProperty = objectLiteral.getProperty('key');
37
+ const propertyName = keyProperty === null || keyProperty === void 0 ? void 0 : keyProperty.getChildAtIndex(0);
38
+ const propertyValue = keyProperty === null || keyProperty === void 0 ? void 0 : keyProperty.getChildAtIndex(2);
39
+ propertyName === null || propertyName === void 0 ? void 0 : propertyName.replaceWithText('keys');
40
+ // if the property value is a string literal, then we should wrap it in an array
41
+ // We are checking the isStringLiteral to avoid wrapping a value that is already an array
42
+ if (ts.Node.isStringLiteral(propertyValue)) {
43
+ propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.replaceWithText(`[${propertyValue === null || propertyValue === void 0 ? void 0 : propertyValue.getText()}]`);
44
+ }
45
+ }
46
+ }
47
+ function isStoragePluginProvided(callExpression) {
48
+ return (callExpression && callExpression.getText().includes('NgxsStoragePluginModule.forRoot'));
49
+ }
50
+ /**
51
+ * We do not use the ts.Node.isCallExpression(node) because the underlying implementation
52
+ * uses -> node.getKind() === typescript.SyntaxKind.CallExpression
53
+ * which is an enum that can return different numbers depending on minor typescript package versions
54
+ */
55
+ function isCallExpression(node) {
56
+ return node.getKindName() === 'CallExpression';
57
+ }
58
+ function migrateKeys() {
59
+ return (tree, _context) => {
60
+ const tsProject = new ts.Project({ useInMemoryFileSystem: true });
61
+ const packageJson = tree.readJson('package.json');
62
+ const storePackage = packageJson['dependencies']['@ngxs/store'];
63
+ if (!storePackage) {
64
+ _context.logger.error(`No @ngxs/store found`);
65
+ return (0, node_process_1.exit)(1);
66
+ }
67
+ (0, visit_files_1.visitTsFiles)(tree, tree.root, (path) => __awaiter(this, void 0, void 0, function* () {
68
+ const fileContent = tree.readText(path);
69
+ const sourceFile = tsProject.createSourceFile(path, fileContent);
70
+ const hasStoragePluginImported = sourceFile.getImportDeclaration(importDecl => importDecl.getModuleSpecifierValue() === '@ngxs/storage-plugin');
71
+ // do not try migrating if the storage plugin is not imported
72
+ if (hasStoragePluginImported) {
73
+ sourceFile.forEachDescendant(node => {
74
+ if (isCallExpression(node) &&
75
+ ts.Node.isPropertyAccessExpression(node.getExpression())) {
76
+ const callExpression = node;
77
+ // If the storage plugin is not provided, we should not try migrating
78
+ if (!isStoragePluginProvided(callExpression)) {
79
+ return;
80
+ }
81
+ const args = callExpression.getArguments();
82
+ // If there are no arguments in the forRoot(), then add the `keys` property
83
+ if (!args.length) {
84
+ _context.logger.info(`Migrating empty forRoot in ${path}`);
85
+ migrateEmptyForRoot(callExpression);
86
+ }
87
+ else if (ts.Node.isObjectLiteralExpression(args[0])) {
88
+ _context.logger.info(`Migrating forRoot with args in ${path}`);
89
+ migrateForRootWithArgs(args[0]);
90
+ }
91
+ }
92
+ });
93
+ tree.overwrite(path, sourceFile.getFullText());
94
+ }
95
+ }));
96
+ };
97
+ }
98
+ //# 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,kCAgDC;AA5GD,+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,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,CAAC;SAAM,CAAC;QACN,sCAAsC;QACtC,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC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C,CAAC,CAAC,CAAC;wBAClC,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;YACjD,CAAC;QACH,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SchematicsNgxsStoragePlugin",
4
+ "title": "Ngxs Storage Plugin Options Schema",
5
+ "type": "object",
6
+ "properties": {}
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "@ngxs/store": "19.0.0"
3
+ }
@@ -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"}