@ngrx/signals 20.1.0 → 21.0.0-beta.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.
- package/fesm2022/ngrx-signals-entities.mjs.map +1 -1
- package/fesm2022/ngrx-signals-events.mjs +219 -57
- package/fesm2022/ngrx-signals-events.mjs.map +1 -1
- package/fesm2022/ngrx-signals-rxjs-interop.mjs +4 -4
- package/fesm2022/ngrx-signals-rxjs-interop.mjs.map +1 -1
- package/fesm2022/ngrx-signals.mjs +11 -8
- package/fesm2022/ngrx-signals.mjs.map +1 -1
- package/migrations/18_0_0-rc_3-protected-state/index.js +54 -23
- package/migrations/18_0_0-rc_3-protected-state/index.js.map +1 -1
- package/migrations/18_0_0-rc_3-writablestatesource/index.js +45 -12
- package/migrations/18_0_0-rc_3-writablestatesource/index.js.map +1 -1
- package/migrations/19_0_0-rc_0-props/index.js +72 -83
- package/migrations/19_0_0-rc_0-props/index.js.map +1 -1
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js +103 -0
- package/migrations/21_0_0-beta_0-rename-withEffects-to-withEventHandlers/index.js.map +1 -0
- package/migrations/migration.json +5 -0
- package/package.json +8 -8
- package/schematics/ng-add/index.js +5 -5
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics-core/index.js +1 -1
- package/schematics-core/index.js.map +1 -1
- package/schematics-core/utility/ast-utils.js +198 -240
- package/schematics-core/utility/ast-utils.js.map +1 -1
- package/schematics-core/utility/change.js +68 -85
- package/schematics-core/utility/change.js.map +1 -1
- package/schematics-core/utility/config.js +7 -7
- package/schematics-core/utility/config.js.map +1 -1
- package/schematics-core/utility/find-component.js +20 -20
- package/schematics-core/utility/find-component.js.map +1 -1
- package/schematics-core/utility/find-module.js +21 -21
- package/schematics-core/utility/find-module.js.map +1 -1
- package/schematics-core/utility/json-utilts.js +4 -26
- package/schematics-core/utility/json-utilts.js.map +1 -1
- package/schematics-core/utility/libs-version.js +1 -1
- package/schematics-core/utility/libs-version.js.map +1 -1
- package/schematics-core/utility/ngrx-utils.js +110 -141
- package/schematics-core/utility/ngrx-utils.js.map +1 -1
- package/schematics-core/utility/package.js +2 -3
- package/schematics-core/utility/package.js.map +1 -1
- package/schematics-core/utility/parse-name.js +3 -3
- package/schematics-core/utility/parse-name.js.map +1 -1
- package/schematics-core/utility/project.js +13 -13
- package/schematics-core/utility/project.js.map +1 -1
- package/schematics-core/utility/strings.js +12 -12
- package/schematics-core/utility/strings.js.map +1 -1
- package/schematics-core/utility/update.js +12 -12
- package/schematics-core/utility/update.js.map +1 -1
- package/schematics-core/utility/visitors.js +78 -180
- package/schematics-core/utility/visitors.js.map +1 -1
- package/types/ngrx-signals-entities.d.ts +324 -0
- package/types/ngrx-signals-events.d.ts +360 -0
- package/types/ngrx-signals-rxjs-interop.d.ts +15 -0
- package/{testing/src/unprotected.d.ts → types/ngrx-signals-testing.d.ts} +5 -3
- package/types/ngrx-signals.d.ts +332 -0
- package/entities/index.d.ts +0 -1
- package/entities/src/entity-config.d.ts +0 -17
- package/entities/src/helpers.d.ts +0 -25
- package/entities/src/index.d.ts +0 -18
- package/entities/src/models.d.ts +0 -24
- package/entities/src/updaters/add-entities.d.ts +0 -17
- package/entities/src/updaters/add-entity.d.ts +0 -17
- package/entities/src/updaters/prepend-entities.d.ts +0 -17
- package/entities/src/updaters/prepend-entity.d.ts +0 -17
- package/entities/src/updaters/remove-all-entities.d.ts +0 -6
- package/entities/src/updaters/remove-entities.d.ts +0 -10
- package/entities/src/updaters/remove-entity.d.ts +0 -6
- package/entities/src/updaters/set-all-entities.d.ts +0 -17
- package/entities/src/updaters/set-entities.d.ts +0 -17
- package/entities/src/updaters/set-entity.d.ts +0 -17
- package/entities/src/updaters/update-all-entities.d.ts +0 -17
- package/entities/src/updaters/update-entities.d.ts +0 -56
- package/entities/src/updaters/update-entity.d.ts +0 -29
- package/entities/src/updaters/upsert-entities.d.ts +0 -17
- package/entities/src/updaters/upsert-entity.d.ts +0 -17
- package/entities/src/with-entities.d.ts +0 -22
- package/events/index.d.ts +0 -1
- package/events/src/case-reducer.d.ts +0 -20
- package/events/src/dispatcher.d.ts +0 -33
- package/events/src/event-creator-group.d.ts +0 -33
- package/events/src/event-creator.d.ts +0 -9
- package/events/src/event-instance.d.ts +0 -8
- package/events/src/events-service.d.ts +0 -47
- package/events/src/index.d.ts +0 -9
- package/events/src/inject-dispatch.d.ts +0 -46
- package/events/src/with-effects.d.ts +0 -28
- package/events/src/with-reducer.d.ts +0 -30
- package/index.d.ts +0 -1
- package/rxjs-interop/index.d.ts +0 -1
- package/rxjs-interop/src/index.d.ts +0 -1
- package/rxjs-interop/src/rx-method.d.ts +0 -12
- package/src/deep-computed.d.ts +0 -2
- package/src/deep-signal.d.ts +0 -6
- package/src/index.d.ts +0 -16
- package/src/signal-method.d.ts +0 -7
- package/src/signal-state.d.ts +0 -4
- package/src/signal-store-assertions.d.ts +0 -2
- package/src/signal-store-feature.d.ts +0 -29
- package/src/signal-store-models.d.ts +0 -30
- package/src/signal-store.d.ts +0 -115
- package/src/state-source.d.ts +0 -23
- package/src/ts-helpers.d.ts +0 -11
- package/src/with-computed.d.ts +0 -12
- package/src/with-feature.d.ts +0 -26
- package/src/with-hooks.d.ts +0 -14
- package/src/with-linked-state.d.ts +0 -52
- package/src/with-methods.d.ts +0 -8
- package/src/with-props.d.ts +0 -8
- package/src/with-state.d.ts +0 -11
- package/testing/index.d.ts +0 -1
- package/testing/src/index.d.ts +0 -1
|
@@ -1,43 +1,75 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.default = migrateWritableStateSource;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var visitors_1 = require("../../schematics-core/utility/visitors");
|
|
37
|
+
const schematics_core_1 = require("../../schematics-core");
|
|
38
|
+
const ts = __importStar(require("typescript"));
|
|
39
|
+
const visitors_1 = require("../../schematics-core/utility/visitors");
|
|
8
40
|
function migrateWritableStateSource() {
|
|
9
|
-
return
|
|
10
|
-
(0, schematics_core_1.visitTSSourceFiles)(tree,
|
|
11
|
-
|
|
41
|
+
return (tree, ctx) => {
|
|
42
|
+
(0, schematics_core_1.visitTSSourceFiles)(tree, (sourceFile) => {
|
|
43
|
+
const signalStoreImportedName = findImportedName(sourceFile);
|
|
12
44
|
if (!signalStoreImportedName) {
|
|
13
45
|
return;
|
|
14
46
|
}
|
|
15
|
-
|
|
16
|
-
visitCallExpression(sourceFile, signalStoreImportedName,
|
|
47
|
+
const changes = [];
|
|
48
|
+
visitCallExpression(sourceFile, signalStoreImportedName, (node) => {
|
|
17
49
|
if (node.arguments.length > 0) {
|
|
18
50
|
if (ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
19
51
|
// signalStore({ providedIn: 'root' })
|
|
20
|
-
|
|
52
|
+
const providedInProperty = node.arguments[0].properties[0];
|
|
21
53
|
if (ts.isPropertyAssignment(providedInProperty) &&
|
|
22
54
|
ts.isIdentifier(providedInProperty.name) &&
|
|
23
55
|
providedInProperty.name.text === 'providedIn') {
|
|
24
|
-
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, providedInProperty, providedInProperty.getText(),
|
|
56
|
+
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, providedInProperty, providedInProperty.getText(), `${providedInProperty.getText()}, protectedState: false`));
|
|
25
57
|
}
|
|
26
58
|
}
|
|
27
59
|
else {
|
|
28
60
|
// signalStore(withState({}))
|
|
29
|
-
|
|
30
|
-
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, firstFeature, firstFeature.getText(),
|
|
61
|
+
const firstFeature = node.arguments[0];
|
|
62
|
+
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, firstFeature, firstFeature.getText(), `{ protectedState: false }, ${firstFeature.getText()}`));
|
|
31
63
|
}
|
|
32
64
|
}
|
|
33
65
|
else {
|
|
34
66
|
// signalStore()
|
|
35
|
-
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, node, node.getText(),
|
|
67
|
+
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, node, node.getText(), `${signalStoreImportedName}({ protectedState: false })`));
|
|
36
68
|
}
|
|
37
69
|
});
|
|
38
70
|
if (changes.length) {
|
|
39
|
-
(0,
|
|
40
|
-
ctx.logger.info(
|
|
71
|
+
(0, schematics_core_1.commitChanges)(tree, sourceFile.fileName, changes);
|
|
72
|
+
ctx.logger.info(`[@ngrx/signals] Disable protected state in ${sourceFile.fileName}`);
|
|
41
73
|
}
|
|
42
74
|
});
|
|
43
75
|
};
|
|
@@ -48,22 +80,21 @@ function visitCallExpression(node, name, callback) {
|
|
|
48
80
|
node.expression.text === name) {
|
|
49
81
|
callback(node);
|
|
50
82
|
}
|
|
51
|
-
ts.forEachChild(node,
|
|
83
|
+
ts.forEachChild(node, (child) => {
|
|
52
84
|
visitCallExpression(child, name, callback);
|
|
53
85
|
});
|
|
54
86
|
}
|
|
55
87
|
function findImportedName(source) {
|
|
56
|
-
|
|
57
|
-
(0, visitors_1.visitImportDeclaration)(source,
|
|
58
|
-
var _a;
|
|
88
|
+
let importedName = '';
|
|
89
|
+
(0, visitors_1.visitImportDeclaration)(source, (importDeclaration) => {
|
|
59
90
|
if (importDeclaration.moduleSpecifier.getText().includes('@ngrx/signals')) {
|
|
60
91
|
if (importedName) {
|
|
61
92
|
return;
|
|
62
93
|
}
|
|
63
|
-
|
|
94
|
+
const namedBindings = importDeclaration.importClause?.namedBindings;
|
|
64
95
|
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
65
|
-
|
|
66
|
-
.map(
|
|
96
|
+
const foundImportedName = namedBindings.elements
|
|
97
|
+
.map((importSpecifier) => {
|
|
67
98
|
if (importSpecifier.propertyName &&
|
|
68
99
|
importSpecifier.propertyName.text === 'signalStore') {
|
|
69
100
|
return importSpecifier.name.text;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/18_0_0-rc_3-protected-state/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/18_0_0-rc_3-protected-state/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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,OAAO,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1E,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO;YACT,CAAC;YAED,MAAM,aAAa,GAAG,iBAAiB,CAAC,YAAY,EAAE,aAAa,CAAC;YACpE,IAAI,aAAa,IAAI,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,CAAC;gBACtD,MAAM,iBAAiB,GAAG,aAAa,CAAC,QAAQ;qBAC7C,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE;oBACvB,IACE,eAAe,CAAC,YAAY;wBAC5B,eAAe,CAAC,YAAY,CAAC,IAAI,KAAK,aAAa,EACnD,CAAC;wBACD,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;oBACnC,CAAC;yBAAM,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;wBACvD,OAAO,aAAa,CAAC;oBACvB,CAAC;oBACD,OAAO,SAAS,CAAC;gBACnB,CAAC,CAAC;qBACD,IAAI,CAAC,OAAO,CAAC,CAAC;gBAEjB,IAAI,iBAAiB,EAAE,CAAC;oBACtB,YAAY,GAAG,iBAAiB,CAAC;oBACjC,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import {\n Change,\n createReplaceChange,\n visitTSSourceFiles,\n commitChanges,\n} from '../../schematics-core';\nimport { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport * as ts from 'typescript';\nimport { visitImportDeclaration } from '../../schematics-core/utility/visitors';\n\nexport default function migrateWritableStateSource(): Rule {\n return (tree: Tree, ctx: SchematicContext) => {\n visitTSSourceFiles(tree, (sourceFile) => {\n const signalStoreImportedName = findImportedName(sourceFile);\n if (!signalStoreImportedName) {\n return;\n }\n\n const changes: Change[] = [];\n visitCallExpression(sourceFile, signalStoreImportedName, (node) => {\n if (node.arguments.length > 0) {\n if (ts.isObjectLiteralExpression(node.arguments[0])) {\n // signalStore({ providedIn: 'root' })\n const providedInProperty = node.arguments[0].properties[0];\n\n if (\n ts.isPropertyAssignment(providedInProperty) &&\n ts.isIdentifier(providedInProperty.name) &&\n providedInProperty.name.text === 'providedIn'\n ) {\n changes.push(\n createReplaceChange(\n sourceFile,\n providedInProperty,\n providedInProperty.getText(),\n `${providedInProperty.getText()}, protectedState: false`\n )\n );\n }\n } else {\n // signalStore(withState({}))\n const firstFeature = node.arguments[0];\n changes.push(\n createReplaceChange(\n sourceFile,\n firstFeature,\n firstFeature.getText(),\n `{ protectedState: false }, ${firstFeature.getText()}`\n )\n );\n }\n } else {\n // signalStore()\n changes.push(\n createReplaceChange(\n sourceFile,\n node,\n node.getText(),\n `${signalStoreImportedName}({ protectedState: false })`\n )\n );\n }\n });\n\n if (changes.length) {\n commitChanges(tree, sourceFile.fileName, changes);\n ctx.logger.info(\n `[@ngrx/signals] Disable protected state in ${sourceFile.fileName}`\n );\n }\n });\n };\n}\n\nfunction visitCallExpression(\n node: ts.Node,\n name: string,\n callback: (callExpression: ts.CallExpression) => void\n) {\n if (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n node.expression.text === name\n ) {\n callback(node);\n }\n\n ts.forEachChild(node, (child) => {\n visitCallExpression(child, name, callback);\n });\n}\n\nfunction findImportedName(source: ts.SourceFile) {\n let importedName = '';\n visitImportDeclaration(source, (importDeclaration) => {\n if (importDeclaration.moduleSpecifier.getText().includes('@ngrx/signals')) {\n if (importedName) {\n return;\n }\n\n const namedBindings = importDeclaration.importClause?.namedBindings;\n if (namedBindings && ts.isNamedImports(namedBindings)) {\n const foundImportedName = namedBindings.elements\n .map((importSpecifier) => {\n if (\n importSpecifier.propertyName &&\n importSpecifier.propertyName.text === 'signalStore'\n ) {\n return importSpecifier.name.text;\n } else if (importSpecifier.name.text === 'signalStore') {\n return 'signalStore';\n }\n return undefined;\n })\n .find(Boolean);\n\n if (foundImportedName) {\n importedName = foundImportedName;\n return;\n }\n }\n }\n });\n\n return importedName;\n}\n"]}
|
|
@@ -1,18 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.migrateWritableStateSource = migrateWritableStateSource;
|
|
4
37
|
exports.default = default_1;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
38
|
+
const ts = __importStar(require("typescript"));
|
|
39
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
40
|
+
const schematics_core_1 = require("../../schematics-core");
|
|
8
41
|
function migrateWritableStateSource() {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
ctx.logger.info(
|
|
12
|
-
(0, schematics_core_1.visitTSSourceFiles)(tree,
|
|
13
|
-
|
|
42
|
+
return (tree, ctx) => {
|
|
43
|
+
let updateCounter = 0;
|
|
44
|
+
ctx.logger.info(`[@ngrx/signals] Migrating 'StateSignal' to 'WritableStateSource'`);
|
|
45
|
+
(0, schematics_core_1.visitTSSourceFiles)(tree, (sourceFile) => {
|
|
46
|
+
const changes = (0, schematics_core_1.replaceImport)(sourceFile, sourceFile.fileName, '@ngrx/signals', 'StateSignal', 'WritableStateSource');
|
|
14
47
|
if (changes.length) {
|
|
15
|
-
visitIdentifiers(sourceFile,
|
|
48
|
+
visitIdentifiers(sourceFile, (node) => {
|
|
16
49
|
if (node.getText() === 'StateSignal' &&
|
|
17
50
|
!ts.isImportSpecifier(node.parent)) {
|
|
18
51
|
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, node, 'StateSignal', 'WritableStateSource'));
|
|
@@ -23,10 +56,10 @@ function migrateWritableStateSource() {
|
|
|
23
56
|
(0, schematics_core_1.commitChanges)(tree, sourceFile.fileName, changes);
|
|
24
57
|
});
|
|
25
58
|
if (updateCounter) {
|
|
26
|
-
ctx.logger.info(
|
|
59
|
+
ctx.logger.info(`[@ngrx/signals] Updated ${updateCounter} references from 'StateSignal' to 'WritableStateSource'`);
|
|
27
60
|
}
|
|
28
61
|
else {
|
|
29
|
-
ctx.logger.info(
|
|
62
|
+
ctx.logger.info(`[@ngrx/signals] No 'StateSignal' refences found to, skipping the migration`);
|
|
30
63
|
}
|
|
31
64
|
};
|
|
32
65
|
}
|
|
@@ -34,7 +67,7 @@ function visitIdentifiers(node, visitor) {
|
|
|
34
67
|
if (ts.isIdentifier(node)) {
|
|
35
68
|
visitor(node);
|
|
36
69
|
}
|
|
37
|
-
ts.forEachChild(node,
|
|
70
|
+
ts.forEachChild(node, (childNode) => visitIdentifiers(childNode, visitor));
|
|
38
71
|
}
|
|
39
72
|
function default_1() {
|
|
40
73
|
return (0, schematics_1.chain)([migrateWritableStateSource()]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/18_0_0-rc_3-writablestatesource/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/18_0_0-rc_3-writablestatesource/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,gEAgDC;AAaD,4BAEC;AA9ED,+CAAiC;AACjC,2DAKoC;AACpC,2DAK+B;AAG/B,SAAgB,0BAA0B;IACxC,OAAO,CAAC,IAAU,EAAE,GAAqB,EAAE,EAAE;QAC3C,IAAI,aAAa,GAAG,CAAC,CAAC;QACtB,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,kEAAkE,CACnE,CAAC;QAEF,IAAA,oCAAkB,EAAC,IAAI,EAAE,CAAC,UAAU,EAAE,EAAE;YACtC,MAAM,OAAO,GAAG,IAAA,+BAAa,EAC3B,UAAU,EACV,UAAU,CAAC,QAAgB,EAC3B,eAAe,EACf,aAAa,EACb,qBAAqB,CACtB,CAAC;YAEF,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACnB,gBAAgB,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;oBACpC,IACE,IAAI,CAAC,OAAO,EAAE,KAAK,aAAa;wBAChC,CAAC,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,EAClC,CAAC;wBACD,OAAO,CAAC,IAAI,CACV,IAAA,qCAAmB,EACjB,UAAU,EACV,IAAI,EACJ,aAAa,EACb,qBAAqB,CACtB,CACF,CAAC;wBACF,aAAa,EAAE,CAAC;oBAClB,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YAED,IAAA,+BAAa,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,IAAI,aAAa,EAAE,CAAC;YAClB,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,2BAA2B,aAAa,yDAAyD,CAClG,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,4EAA4E,CAC7E,CAAC;QACJ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,IAAa,EACb,OAAsC;IAEtC,IAAI,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;IACE,OAAO,IAAA,kBAAK,EAAC,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport {\n Tree,\n Rule,\n chain,\n SchematicContext,\n} from '@angular-devkit/schematics';\nimport {\n commitChanges,\n createReplaceChange,\n replaceImport,\n visitTSSourceFiles,\n} from '../../schematics-core';\nimport { Path } from '@angular-devkit/core';\n\nexport function migrateWritableStateSource(): Rule {\n return (tree: Tree, ctx: SchematicContext) => {\n let updateCounter = 0;\n ctx.logger.info(\n `[@ngrx/signals] Migrating 'StateSignal' to 'WritableStateSource'`\n );\n\n visitTSSourceFiles(tree, (sourceFile) => {\n const changes = replaceImport(\n sourceFile,\n sourceFile.fileName as Path,\n '@ngrx/signals',\n 'StateSignal',\n 'WritableStateSource'\n );\n\n if (changes.length) {\n visitIdentifiers(sourceFile, (node) => {\n if (\n node.getText() === 'StateSignal' &&\n !ts.isImportSpecifier(node.parent)\n ) {\n changes.push(\n createReplaceChange(\n sourceFile,\n node,\n 'StateSignal',\n 'WritableStateSource'\n )\n );\n updateCounter++;\n }\n });\n }\n\n commitChanges(tree, sourceFile.fileName, changes);\n });\n\n if (updateCounter) {\n ctx.logger.info(\n `[@ngrx/signals] Updated ${updateCounter} references from 'StateSignal' to 'WritableStateSource'`\n );\n } else {\n ctx.logger.info(\n `[@ngrx/signals] No 'StateSignal' refences found to, skipping the migration`\n );\n }\n };\n}\n\nfunction visitIdentifiers(\n node: ts.Node,\n visitor: (node: ts.Identifier) => void\n) {\n if (ts.isIdentifier(node)) {\n visitor(node);\n }\n\n ts.forEachChild(node, (childNode) => visitIdentifiers(childNode, visitor));\n}\n\nexport default function (): Rule {\n return chain([migrateWritableStateSource()]);\n}\n"]}
|
|
@@ -1,57 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
7
|
}
|
|
36
|
-
|
|
37
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.migrate = migrate;
|
|
40
37
|
exports.default = default_1;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
39
|
+
const schematics_core_1 = require("../../schematics-core");
|
|
40
|
+
const visitors_1 = require("../../schematics-core/utility/visitors");
|
|
41
|
+
const ts = __importStar(require("typescript"));
|
|
45
42
|
function migratedToEntityProps(sourceFile) {
|
|
46
|
-
|
|
47
|
-
(0, visitors_1.visitImportDeclaration)(sourceFile,
|
|
43
|
+
const changes = [];
|
|
44
|
+
(0, visitors_1.visitImportDeclaration)(sourceFile, (importDeclaration, moduleName) => {
|
|
48
45
|
if (moduleName !== '@ngrx/signals/entities') {
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
|
-
(0, visitors_1.visitImportSpecifier)(importDeclaration,
|
|
48
|
+
(0, visitors_1.visitImportSpecifier)(importDeclaration, (importSpecifier) => {
|
|
52
49
|
if (importSpecifier.name.getText() === 'EntityComputed') {
|
|
53
50
|
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, importSpecifier, importSpecifier.getText(), 'EntityProps'));
|
|
54
|
-
(0, visitors_1.visitTypeReference)(sourceFile,
|
|
51
|
+
(0, visitors_1.visitTypeReference)(sourceFile, (type) => {
|
|
55
52
|
if (type.typeName.getText() === 'EntityComputed') {
|
|
56
53
|
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, type, type.typeName.getText(), 'EntityProps'));
|
|
57
54
|
}
|
|
@@ -59,7 +56,7 @@ function migratedToEntityProps(sourceFile) {
|
|
|
59
56
|
}
|
|
60
57
|
if (importSpecifier.name.getText() === 'NamedEntityComputed') {
|
|
61
58
|
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, importSpecifier, importSpecifier.getText(), 'NamedEntityProps'));
|
|
62
|
-
(0, visitors_1.visitTypeReference)(sourceFile,
|
|
59
|
+
(0, visitors_1.visitTypeReference)(sourceFile, (typeReference) => {
|
|
63
60
|
if (typeReference.typeName.getText() === 'NamedEntityComputed') {
|
|
64
61
|
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, typeReference.typeName, typeReference.typeName.getText(), 'NamedEntityProps'));
|
|
65
62
|
}
|
|
@@ -70,52 +67,40 @@ function migratedToEntityProps(sourceFile) {
|
|
|
70
67
|
return changes;
|
|
71
68
|
}
|
|
72
69
|
function migrateToPropsInSignalStoreFeatureType(sourceFile) {
|
|
73
|
-
|
|
74
|
-
(0, visitors_1.visitTypeReference)(sourceFile,
|
|
70
|
+
const changes = [];
|
|
71
|
+
(0, visitors_1.visitTypeReference)(sourceFile, (typeReference) => {
|
|
75
72
|
if (typeReference.typeName.getText() !== 'SignalStoreFeature') {
|
|
76
73
|
return;
|
|
77
74
|
}
|
|
78
|
-
(0, visitors_1.visitTypeLiteral)(typeReference,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (ts.isPropertySignature(propertySignature)) {
|
|
85
|
-
if (propertySignature.name.getText() === 'computed') {
|
|
86
|
-
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, propertySignature.name, 'computed', 'props'));
|
|
87
|
-
}
|
|
75
|
+
(0, visitors_1.visitTypeLiteral)(typeReference, (typeLiteral) => {
|
|
76
|
+
const typeLiteralChildren = typeLiteral.members;
|
|
77
|
+
for (const propertySignature of typeLiteralChildren) {
|
|
78
|
+
if (ts.isPropertySignature(propertySignature)) {
|
|
79
|
+
if (propertySignature.name.getText() === 'computed') {
|
|
80
|
+
changes.push((0, schematics_core_1.createReplaceChange)(sourceFile, propertySignature.name, 'computed', 'props'));
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
92
|
-
finally {
|
|
93
|
-
try {
|
|
94
|
-
if (typeLiteralChildren_1_1 && !typeLiteralChildren_1_1.done && (_a = typeLiteralChildren_1.return)) _a.call(typeLiteralChildren_1);
|
|
95
|
-
}
|
|
96
|
-
finally { if (e_1) throw e_1.error; }
|
|
97
|
-
}
|
|
98
84
|
});
|
|
99
85
|
});
|
|
100
86
|
return changes;
|
|
101
87
|
}
|
|
102
88
|
function migrateToPropsInSignalStoreFeatureWithObjectLiteral(objectLiteral, sourceFile) {
|
|
103
|
-
|
|
89
|
+
const computedKey = objectLiteral.properties
|
|
104
90
|
.filter(ts.isPropertyAssignment)
|
|
105
|
-
.find(
|
|
91
|
+
.find((property) => property.name.getText() === 'computed');
|
|
106
92
|
if (computedKey) {
|
|
107
93
|
return [(0, schematics_core_1.createReplaceChange)(sourceFile, computedKey, 'computed', 'props')];
|
|
108
94
|
}
|
|
109
95
|
return [];
|
|
110
96
|
}
|
|
111
97
|
function migrateToPropsInSignalStoreFeatureWithCallExpression(callExpression, sourceFile) {
|
|
112
|
-
var _a;
|
|
113
98
|
if (callExpression.expression.getText() === 'type') {
|
|
114
|
-
|
|
99
|
+
const typeArgument = callExpression.typeArguments?.at(0);
|
|
115
100
|
if (typeArgument && ts.isTypeLiteralNode(typeArgument)) {
|
|
116
|
-
|
|
101
|
+
const computedKey = typeArgument.members
|
|
117
102
|
.filter(ts.isPropertySignature)
|
|
118
|
-
.find(
|
|
103
|
+
.find((propertySignature) => propertySignature.name.getText() === 'computed');
|
|
119
104
|
if (computedKey) {
|
|
120
105
|
return [
|
|
121
106
|
(0, schematics_core_1.createReplaceChange)(sourceFile, computedKey, 'computed', 'props'),
|
|
@@ -126,40 +111,44 @@ function migrateToPropsInSignalStoreFeatureWithCallExpression(callExpression, so
|
|
|
126
111
|
return [];
|
|
127
112
|
}
|
|
128
113
|
function migrateToPropsInSignalStoreFeatureFunction(sourceFile) {
|
|
129
|
-
|
|
130
|
-
(0, visitors_1.visitCallExpression)(sourceFile,
|
|
114
|
+
const changes = [];
|
|
115
|
+
(0, visitors_1.visitCallExpression)(sourceFile, (callExpression) => {
|
|
131
116
|
if (callExpression.expression.getText() !== 'signalStoreFeature') {
|
|
132
117
|
return;
|
|
133
118
|
}
|
|
134
|
-
|
|
119
|
+
const objectLiteralOrCallExpression = callExpression.arguments[0];
|
|
135
120
|
if (!objectLiteralOrCallExpression) {
|
|
136
121
|
return;
|
|
137
122
|
}
|
|
138
123
|
if (ts.isObjectLiteralExpression(objectLiteralOrCallExpression)) {
|
|
139
|
-
changes.push
|
|
124
|
+
changes.push(...migrateToPropsInSignalStoreFeatureWithObjectLiteral(objectLiteralOrCallExpression, sourceFile));
|
|
140
125
|
}
|
|
141
126
|
else if (ts.isCallExpression(objectLiteralOrCallExpression)) {
|
|
142
|
-
changes.push
|
|
127
|
+
changes.push(...migrateToPropsInSignalStoreFeatureWithCallExpression(objectLiteralOrCallExpression, sourceFile));
|
|
143
128
|
}
|
|
144
129
|
});
|
|
145
130
|
return changes;
|
|
146
131
|
}
|
|
147
132
|
function migrate() {
|
|
148
|
-
return
|
|
149
|
-
(0, schematics_core_1.visitTSSourceFiles)(tree,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
133
|
+
return (tree, ctx) => {
|
|
134
|
+
(0, schematics_core_1.visitTSSourceFiles)(tree, (sourceFile) => {
|
|
135
|
+
const entityPropsChanges = migratedToEntityProps(sourceFile);
|
|
136
|
+
const propsInSignalStoreFeatureTypeChanges = migrateToPropsInSignalStoreFeatureType(sourceFile);
|
|
137
|
+
const propsInSignalStoreFeatureFunctionChanges = migrateToPropsInSignalStoreFeatureFunction(sourceFile);
|
|
138
|
+
const changes = [
|
|
139
|
+
...entityPropsChanges,
|
|
140
|
+
...propsInSignalStoreFeatureTypeChanges,
|
|
141
|
+
...propsInSignalStoreFeatureFunctionChanges,
|
|
142
|
+
];
|
|
154
143
|
(0, schematics_core_1.commitChanges)(tree, sourceFile.fileName, changes);
|
|
155
144
|
if (entityPropsChanges.length) {
|
|
156
|
-
ctx.logger.info(
|
|
145
|
+
ctx.logger.info(`[@ngrx/signals] Renamed '(Named)EntityComputed' to '(Named)EntityProps' in ${sourceFile.fileName}`);
|
|
157
146
|
}
|
|
158
147
|
if (propsInSignalStoreFeatureTypeChanges.length) {
|
|
159
|
-
ctx.logger.info(
|
|
148
|
+
ctx.logger.info(`[@ngrx/signals] Renamed 'computed' to 'props' in SignalStoreFeature<> in ${sourceFile.fileName}`);
|
|
160
149
|
}
|
|
161
150
|
if (propsInSignalStoreFeatureFunctionChanges.length) {
|
|
162
|
-
ctx.logger.info(
|
|
151
|
+
ctx.logger.info(`[@ngrx/signals] Renamed 'computed' to 'props' in signalStoreFeature() in ${sourceFile.fileName}`);
|
|
163
152
|
}
|
|
164
153
|
});
|
|
165
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/19_0_0-rc_0-props/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0LA,0BAiCC;AAED,4BAEC;AA/ND,yDAKoC;AACpC,yDAK+B;AAC/B,mEAMgD;AAChD,+BAAiC;AAEjC,SAAS,qBAAqB,CAAC,UAAyB;IACtD,IAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAA,iCAAsB,EAAC,UAAU,EAAE,UAAC,iBAAiB,EAAE,UAAU;QAC/D,IAAI,UAAU,KAAK,wBAAwB,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,IAAA,+BAAoB,EAAC,iBAAiB,EAAE,UAAC,eAAe;YACtD,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,gBAAgB,EAAE,CAAC;gBACxD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CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,OAAO;IACrB,OAAO,UAAC,IAAU,EAAE,GAAqB;QACvC,IAAA,oCAAkB,EAAC,IAAI,EAAE,UAAC,UAAU;YAClC,IAAM,kBAAkB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAC7D,IAAM,oCAAoC,GACxC,sCAAsC,CAAC,UAAU,CAAC,CAAC;YACrD,IAAM,wCAAwC,GAC5C,0CAA0C,CAAC,UAAU,CAAC,CAAC;YACzD,IAAM,OAAO,wDACR,kBAAkB,kBAClB,oCAAoC,kBACpC,wCAAwC,SAC5C,CAAC;YAEF,IAAA,+BAAa,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,IAAI,kBAAkB,CAAC,MAAM,EAAE,CAAC;gBAC9B,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,qFAA8E,UAAU,CAAC,QAAQ,CAAE,CACpG,CAAC;YACJ,CAAC;YACD,IAAI,oCAAoC,CAAC,MAAM,EAAE,CAAC;gBAChD,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,mFAA4E,UAAU,CAAC,QAAQ,CAAE,CAClG,CAAC;YACJ,CAAC;YACD,IAAI,wCAAwC,CAAC,MAAM,EAAE,CAAC;gBACpD,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,mFAA4E,UAAU,CAAC,QAAQ,CAAE,CAClG,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;IACE,OAAO,IAAA,kBAAK,EAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import {\n chain,\n Rule,\n SchematicContext,\n Tree,\n} from '@angular-devkit/schematics';\nimport {\n Change,\n commitChanges,\n createReplaceChange,\n visitTSSourceFiles,\n} from '../../schematics-core';\nimport {\n visitCallExpression,\n visitImportDeclaration,\n visitImportSpecifier,\n visitTypeLiteral,\n visitTypeReference,\n} from '../../schematics-core/utility/visitors';\nimport * as ts from 'typescript';\n\nfunction migratedToEntityProps(sourceFile: ts.SourceFile) {\n const changes: Change[] = [];\n visitImportDeclaration(sourceFile, (importDeclaration, moduleName) => {\n if (moduleName !== '@ngrx/signals/entities') {\n return;\n }\n\n visitImportSpecifier(importDeclaration, (importSpecifier) => {\n if (importSpecifier.name.getText() === 'EntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n importSpecifier,\n importSpecifier.getText(),\n 'EntityProps'\n )\n );\n\n visitTypeReference(sourceFile, (type) => {\n if (type.typeName.getText() === 'EntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n type,\n type.typeName.getText(),\n 'EntityProps'\n )\n );\n }\n });\n }\n\n if (importSpecifier.name.getText() === 'NamedEntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n importSpecifier,\n importSpecifier.getText(),\n 'NamedEntityProps'\n )\n );\n\n visitTypeReference(sourceFile, (typeReference) => {\n if (typeReference.typeName.getText() === 'NamedEntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n typeReference.typeName,\n typeReference.typeName.getText(),\n 'NamedEntityProps'\n )\n );\n }\n });\n }\n });\n });\n\n return changes;\n}\n\nfunction migrateToPropsInSignalStoreFeatureType(\n sourceFile: ts.SourceFile\n): Change[] {\n const changes: Change[] = [];\n visitTypeReference(sourceFile, (typeReference) => {\n if (typeReference.typeName.getText() !== 'SignalStoreFeature') {\n return;\n }\n\n visitTypeLiteral(typeReference, (typeLiteral) => {\n const typeLiteralChildren = typeLiteral.members;\n for (const propertySignature of typeLiteralChildren) {\n if (ts.isPropertySignature(propertySignature)) {\n if (propertySignature.name.getText() === 'computed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n propertySignature.name,\n 'computed',\n 'props'\n )\n );\n }\n }\n }\n });\n });\n\n return changes;\n}\n\nfunction migrateToPropsInSignalStoreFeatureWithObjectLiteral(\n objectLiteral: ts.ObjectLiteralExpression,\n sourceFile: ts.SourceFile\n): Change[] {\n const computedKey = objectLiteral.properties\n .filter(ts.isPropertyAssignment)\n .find((property) => property.name.getText() === 'computed');\n if (computedKey) {\n return [createReplaceChange(sourceFile, computedKey, 'computed', 'props')];\n }\n\n return [];\n}\n\nfunction migrateToPropsInSignalStoreFeatureWithCallExpression(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile\n): Change[] {\n if (callExpression.expression.getText() === 'type') {\n const typeArgument = callExpression.typeArguments?.at(0);\n\n if (typeArgument && ts.isTypeLiteralNode(typeArgument)) {\n const computedKey = typeArgument.members\n .filter(ts.isPropertySignature)\n .find(\n (propertySignature) => propertySignature.name.getText() === 'computed'\n );\n\n if (computedKey) {\n return [\n createReplaceChange(sourceFile, computedKey, 'computed', 'props'),\n ];\n }\n }\n }\n\n return [];\n}\n\nfunction migrateToPropsInSignalStoreFeatureFunction(\n sourceFile: ts.SourceFile\n): Change[] {\n const changes: Change[] = [];\n visitCallExpression(sourceFile, (callExpression) => {\n if (callExpression.expression.getText() !== 'signalStoreFeature') {\n return;\n }\n\n const objectLiteralOrCallExpression = callExpression.arguments[0];\n if (!objectLiteralOrCallExpression) {\n return;\n }\n\n if (ts.isObjectLiteralExpression(objectLiteralOrCallExpression)) {\n changes.push(\n ...migrateToPropsInSignalStoreFeatureWithObjectLiteral(\n objectLiteralOrCallExpression,\n sourceFile\n )\n );\n } else if (ts.isCallExpression(objectLiteralOrCallExpression)) {\n changes.push(\n ...migrateToPropsInSignalStoreFeatureWithCallExpression(\n objectLiteralOrCallExpression,\n sourceFile\n )\n );\n }\n });\n\n return changes;\n}\n\nexport function migrate(): Rule {\n return (tree: Tree, ctx: SchematicContext) => {\n visitTSSourceFiles(tree, (sourceFile) => {\n const entityPropsChanges = migratedToEntityProps(sourceFile);\n const propsInSignalStoreFeatureTypeChanges =\n migrateToPropsInSignalStoreFeatureType(sourceFile);\n const propsInSignalStoreFeatureFunctionChanges =\n migrateToPropsInSignalStoreFeatureFunction(sourceFile);\n const changes = [\n ...entityPropsChanges,\n ...propsInSignalStoreFeatureTypeChanges,\n ...propsInSignalStoreFeatureFunctionChanges,\n ];\n\n commitChanges(tree, sourceFile.fileName, changes);\n\n if (entityPropsChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed '(Named)EntityComputed' to '(Named)EntityProps' in ${sourceFile.fileName}`\n );\n }\n if (propsInSignalStoreFeatureTypeChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed 'computed' to 'props' in SignalStoreFeature<> in ${sourceFile.fileName}`\n );\n }\n if (propsInSignalStoreFeatureFunctionChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed 'computed' to 'props' in signalStoreFeature() in ${sourceFile.fileName}`\n );\n }\n });\n };\n}\n\nexport default function (): Rule {\n return chain([migrate()]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/signals/migrations/19_0_0-rc_0-props/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0LA,0BAiCC;AAED,4BAEC;AA/ND,2DAKoC;AACpC,2DAK+B;AAC/B,qEAMgD;AAChD,+CAAiC;AAEjC,SAAS,qBAAqB,CAAC,UAAyB;IACtD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAA,iCAAsB,EAAC,UAAU,EAAE,CAAC,iBAAiB,EAAE,UAAU,EAAE,EAAE;QACnE,IAAI,UAAU,KAAK,wBAAwB,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,IAAA,+BAAoB,EAAC,iBAAiB,EAAE,CAAC,eAAe,EAAE,EAAE;YAC1D,IAAI,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,gBAAgB,EAAE,CAAC;gBACxD,OAAO,CAAC,IAAI,CACV,IAAA,qCAAmB,EACjB,UAAU,EACV,eAAe,EACf,eAAe,CAAC,OAAO,EAAE,EACzB,aAAa,CACd,CACF,CAA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E,CAAC,UAAU,EAAE,EAAE;YACtC,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;YAC7D,MAAM,oCAAoC,GACxC,sCAAsC,CAAC,UAAU,CAAC,CAAC;YACrD,MAAM,wCAAwC,GAC5C,0CAA0C,CAAC,UAAU,CAAC,CAAC;YACzD,MAAM,OAAO,GAAG;gBACd,GAAG,kBAAkB;gBACrB,GAAG,oCAAoC;gBACvC,GAAG,wCAAwC;aAC5C,CAAC;YAEF,IAAA,+BAAa,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAElD,IAAI,kBAAkB,CAAC,MAAM,EAAE,CAAC;gBAC9B,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,8EAA8E,UAAU,CAAC,QAAQ,EAAE,CACpG,CAAC;YACJ,CAAC;YACD,IAAI,oCAAoC,CAAC,MAAM,EAAE,CAAC;gBAChD,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,4EAA4E,UAAU,CAAC,QAAQ,EAAE,CAClG,CAAC;YACJ,CAAC;YACD,IAAI,wCAAwC,CAAC,MAAM,EAAE,CAAC;gBACpD,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,4EAA4E,UAAU,CAAC,QAAQ,EAAE,CAClG,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;IACE,OAAO,IAAA,kBAAK,EAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import {\n chain,\n Rule,\n SchematicContext,\n Tree,\n} from '@angular-devkit/schematics';\nimport {\n Change,\n commitChanges,\n createReplaceChange,\n visitTSSourceFiles,\n} from '../../schematics-core';\nimport {\n visitCallExpression,\n visitImportDeclaration,\n visitImportSpecifier,\n visitTypeLiteral,\n visitTypeReference,\n} from '../../schematics-core/utility/visitors';\nimport * as ts from 'typescript';\n\nfunction migratedToEntityProps(sourceFile: ts.SourceFile) {\n const changes: Change[] = [];\n visitImportDeclaration(sourceFile, (importDeclaration, moduleName) => {\n if (moduleName !== '@ngrx/signals/entities') {\n return;\n }\n\n visitImportSpecifier(importDeclaration, (importSpecifier) => {\n if (importSpecifier.name.getText() === 'EntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n importSpecifier,\n importSpecifier.getText(),\n 'EntityProps'\n )\n );\n\n visitTypeReference(sourceFile, (type) => {\n if (type.typeName.getText() === 'EntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n type,\n type.typeName.getText(),\n 'EntityProps'\n )\n );\n }\n });\n }\n\n if (importSpecifier.name.getText() === 'NamedEntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n importSpecifier,\n importSpecifier.getText(),\n 'NamedEntityProps'\n )\n );\n\n visitTypeReference(sourceFile, (typeReference) => {\n if (typeReference.typeName.getText() === 'NamedEntityComputed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n typeReference.typeName,\n typeReference.typeName.getText(),\n 'NamedEntityProps'\n )\n );\n }\n });\n }\n });\n });\n\n return changes;\n}\n\nfunction migrateToPropsInSignalStoreFeatureType(\n sourceFile: ts.SourceFile\n): Change[] {\n const changes: Change[] = [];\n visitTypeReference(sourceFile, (typeReference) => {\n if (typeReference.typeName.getText() !== 'SignalStoreFeature') {\n return;\n }\n\n visitTypeLiteral(typeReference, (typeLiteral) => {\n const typeLiteralChildren = typeLiteral.members;\n for (const propertySignature of typeLiteralChildren) {\n if (ts.isPropertySignature(propertySignature)) {\n if (propertySignature.name.getText() === 'computed') {\n changes.push(\n createReplaceChange(\n sourceFile,\n propertySignature.name,\n 'computed',\n 'props'\n )\n );\n }\n }\n }\n });\n });\n\n return changes;\n}\n\nfunction migrateToPropsInSignalStoreFeatureWithObjectLiteral(\n objectLiteral: ts.ObjectLiteralExpression,\n sourceFile: ts.SourceFile\n): Change[] {\n const computedKey = objectLiteral.properties\n .filter(ts.isPropertyAssignment)\n .find((property) => property.name.getText() === 'computed');\n if (computedKey) {\n return [createReplaceChange(sourceFile, computedKey, 'computed', 'props')];\n }\n\n return [];\n}\n\nfunction migrateToPropsInSignalStoreFeatureWithCallExpression(\n callExpression: ts.CallExpression,\n sourceFile: ts.SourceFile\n): Change[] {\n if (callExpression.expression.getText() === 'type') {\n const typeArgument = callExpression.typeArguments?.at(0);\n\n if (typeArgument && ts.isTypeLiteralNode(typeArgument)) {\n const computedKey = typeArgument.members\n .filter(ts.isPropertySignature)\n .find(\n (propertySignature) => propertySignature.name.getText() === 'computed'\n );\n\n if (computedKey) {\n return [\n createReplaceChange(sourceFile, computedKey, 'computed', 'props'),\n ];\n }\n }\n }\n\n return [];\n}\n\nfunction migrateToPropsInSignalStoreFeatureFunction(\n sourceFile: ts.SourceFile\n): Change[] {\n const changes: Change[] = [];\n visitCallExpression(sourceFile, (callExpression) => {\n if (callExpression.expression.getText() !== 'signalStoreFeature') {\n return;\n }\n\n const objectLiteralOrCallExpression = callExpression.arguments[0];\n if (!objectLiteralOrCallExpression) {\n return;\n }\n\n if (ts.isObjectLiteralExpression(objectLiteralOrCallExpression)) {\n changes.push(\n ...migrateToPropsInSignalStoreFeatureWithObjectLiteral(\n objectLiteralOrCallExpression,\n sourceFile\n )\n );\n } else if (ts.isCallExpression(objectLiteralOrCallExpression)) {\n changes.push(\n ...migrateToPropsInSignalStoreFeatureWithCallExpression(\n objectLiteralOrCallExpression,\n sourceFile\n )\n );\n }\n });\n\n return changes;\n}\n\nexport function migrate(): Rule {\n return (tree: Tree, ctx: SchematicContext) => {\n visitTSSourceFiles(tree, (sourceFile) => {\n const entityPropsChanges = migratedToEntityProps(sourceFile);\n const propsInSignalStoreFeatureTypeChanges =\n migrateToPropsInSignalStoreFeatureType(sourceFile);\n const propsInSignalStoreFeatureFunctionChanges =\n migrateToPropsInSignalStoreFeatureFunction(sourceFile);\n const changes = [\n ...entityPropsChanges,\n ...propsInSignalStoreFeatureTypeChanges,\n ...propsInSignalStoreFeatureFunctionChanges,\n ];\n\n commitChanges(tree, sourceFile.fileName, changes);\n\n if (entityPropsChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed '(Named)EntityComputed' to '(Named)EntityProps' in ${sourceFile.fileName}`\n );\n }\n if (propsInSignalStoreFeatureTypeChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed 'computed' to 'props' in SignalStoreFeature<> in ${sourceFile.fileName}`\n );\n }\n if (propsInSignalStoreFeatureFunctionChanges.length) {\n ctx.logger.info(\n `[@ngrx/signals] Renamed 'computed' to 'props' in signalStoreFeature() in ${sourceFile.fileName}`\n );\n }\n });\n };\n}\n\nexport default function (): Rule {\n return chain([migrate()]);\n}\n"]}
|