@typeorm/codemod 1.0.0 → 1.0.2
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/README.md +13 -10
- package/dist/cli/print-guide.js +2 -2
- package/dist/cli/print-summary.js +3 -2
- package/dist/cli/print-summary.js.map +1 -1
- package/dist/cli/print-usage.js +2 -1
- package/dist/cli/print-usage.js.map +1 -1
- package/dist/cli/run-transforms.js +181 -79
- package/dist/cli/run-transforms.js.map +1 -1
- package/dist/dependencies/v1.js +23 -9
- package/dist/dependencies/v1.js.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/transforms/ast-helpers.js +779 -19
- package/dist/transforms/ast-helpers.js.map +1 -1
- package/dist/transforms/stats.js +11 -0
- package/dist/transforms/stats.js.map +1 -1
- package/dist/transforms/todo.js +42 -2
- package/dist/transforms/todo.js.map +1 -1
- package/dist/transforms/v1/column-readonly.js +28 -13
- package/dist/transforms/v1/column-readonly.js.map +1 -1
- package/dist/transforms/v1/column-unsigned-numeric.js +27 -26
- package/dist/transforms/v1/column-unsigned-numeric.js.map +1 -1
- package/dist/transforms/v1/column-width-zerofill.js +2 -1
- package/dist/transforms/v1/column-width-zerofill.js.map +1 -1
- package/dist/transforms/v1/connection-manager.js +82 -0
- package/dist/transforms/v1/connection-manager.js.map +1 -0
- package/dist/transforms/v1/connection-options-reader.js +214 -0
- package/dist/transforms/v1/connection-options-reader.js.map +1 -0
- package/dist/transforms/v1/connection-to-datasource.js +858 -93
- package/dist/transforms/v1/connection-to-datasource.js.map +1 -1
- package/dist/transforms/v1/datasource-expo.js +79 -0
- package/dist/transforms/v1/datasource-expo.js.map +1 -0
- package/dist/transforms/v1/datasource-mongodb.js +103 -64
- package/dist/transforms/v1/datasource-mongodb.js.map +1 -1
- package/dist/transforms/v1/datasource-mssql.js +88 -46
- package/dist/transforms/v1/datasource-mssql.js.map +1 -1
- package/dist/transforms/v1/datasource-mysql-connector.js +25 -6
- package/dist/transforms/v1/datasource-mysql-connector.js.map +1 -1
- package/dist/transforms/v1/datasource-name.js +19 -14
- package/dist/transforms/v1/datasource-name.js.map +1 -1
- package/dist/transforms/v1/datasource-sap.js +51 -26
- package/dist/transforms/v1/datasource-sap.js.map +1 -1
- package/dist/transforms/v1/datasource-sqlite-options.js +48 -13
- package/dist/transforms/v1/datasource-sqlite-options.js.map +1 -1
- package/dist/transforms/v1/datasource-sqlite-type.js +28 -7
- package/dist/transforms/v1/datasource-sqlite-type.js.map +1 -1
- package/dist/transforms/v1/file-logger.js +163 -0
- package/dist/transforms/v1/file-logger.js.map +1 -0
- package/dist/transforms/v1/find-options-join.js +84 -0
- package/dist/transforms/v1/find-options-join.js.map +1 -0
- package/dist/transforms/v1/find-options-lock-modes.js +26 -21
- package/dist/transforms/v1/find-options-lock-modes.js.map +1 -1
- package/dist/transforms/v1/find-options-string-relations.js +75 -9
- package/dist/transforms/v1/find-options-string-relations.js.map +1 -1
- package/dist/transforms/v1/find-options-string-select.js +75 -11
- package/dist/transforms/v1/find-options-string-select.js.map +1 -1
- package/dist/transforms/v1/global-functions.js +150 -64
- package/dist/transforms/v1/global-functions.js.map +1 -1
- package/dist/transforms/v1/index.js +16 -3
- package/dist/transforms/v1/index.js.map +1 -1
- package/dist/transforms/v1/migrations-get-all.js +25 -9
- package/dist/transforms/v1/migrations-get-all.js.map +1 -1
- package/dist/transforms/v1/mongodb-stats.js +21 -11
- package/dist/transforms/v1/mongodb-stats.js.map +1 -1
- package/dist/transforms/v1/mongodb-types.js +59 -2
- package/dist/transforms/v1/mongodb-types.js.map +1 -1
- package/dist/transforms/v1/query-builder-native-parameters.js +2 -0
- package/dist/transforms/v1/query-builder-native-parameters.js.map +1 -1
- package/dist/transforms/v1/query-builder-on-conflict.js +32 -18
- package/dist/transforms/v1/query-builder-on-conflict.js.map +1 -1
- package/dist/transforms/v1/query-builder-or-update.js +8 -4
- package/dist/transforms/v1/query-builder-or-update.js.map +1 -1
- package/dist/transforms/v1/query-builder-print-sql.js +18 -12
- package/dist/transforms/v1/query-builder-print-sql.js.map +1 -1
- package/dist/transforms/v1/query-builder-replace-property-names.js +16 -12
- package/dist/transforms/v1/query-builder-replace-property-names.js.map +1 -1
- package/dist/transforms/v1/query-builder-where-expression.js +29 -12
- package/dist/transforms/v1/query-builder-where-expression.js.map +1 -1
- package/dist/transforms/v1/query-runner-loaded-tables-views.js +1 -6
- package/dist/transforms/v1/query-runner-loaded-tables-views.js.map +1 -1
- package/dist/transforms/v1/relation-count.js +78 -12
- package/dist/transforms/v1/relation-count.js.map +1 -1
- package/dist/transforms/v1/repository-abstract.js +148 -34
- package/dist/transforms/v1/repository-abstract.js.map +1 -1
- package/dist/transforms/v1/repository-exist.js +20 -1
- package/dist/transforms/v1/repository-exist.js.map +1 -1
- package/dist/transforms/v1/repository-find-by-ids.js +67 -27
- package/dist/transforms/v1/repository-find-by-ids.js.map +1 -1
- package/dist/transforms/v1/repository-find-one-by-id.js +6 -0
- package/dist/transforms/v1/repository-find-one-by-id.js.map +1 -1
- package/dist/transforms/v1/use-container.js +65 -15
- package/dist/transforms/v1/use-container.js.map +1 -1
- package/package.json +3 -1
- package/dist/cli/colors.d.ts +0 -7
- package/dist/cli/colors.js +0 -12
- package/dist/cli/colors.js.map +0 -1
- package/dist/cli/error.d.ts +0 -1
- package/dist/cli/error.js +0 -11
- package/dist/cli/error.js.map +0 -1
- package/dist/cli/list-transforms.d.ts +0 -1
- package/dist/cli/parse-args.d.ts +0 -10
- package/dist/cli/print-guide.d.ts +0 -1
- package/dist/cli/print-summary.d.ts +0 -17
- package/dist/cli/print-todos.d.ts +0 -1
- package/dist/cli/print-usage.d.ts +0 -1
- package/dist/cli/run-dependencies.d.ts +0 -6
- package/dist/cli/run-transforms.d.ts +0 -21
- package/dist/cli/run.d.ts +0 -9
- package/dist/dependencies/config.d.ts +0 -24
- package/dist/dependencies/find-package-json.d.ts +0 -5
- package/dist/dependencies/index.d.ts +0 -5
- package/dist/dependencies/upgrade.d.ts +0 -11
- package/dist/dependencies/v1.d.ts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/lib/colors.d.ts +0 -9
- package/dist/lib/error.d.ts +0 -1
- package/dist/lib/format-time.d.ts +0 -1
- package/dist/lib/highlight.d.ts +0 -1
- package/dist/lib/spinner.d.ts +0 -5
- package/dist/transforms/ast-helpers.d.ts +0 -50
- package/dist/transforms/index.d.ts +0 -7
- package/dist/transforms/resolve.d.ts +0 -1
- package/dist/transforms/scan.d.ts +0 -4
- package/dist/transforms/scan.js +0 -33
- package/dist/transforms/scan.js.map +0 -1
- package/dist/transforms/stats.d.ts +0 -11
- package/dist/transforms/todo.d.ts +0 -2
- package/dist/transforms/transformer.d.ts +0 -8
- package/dist/transforms/v1/column-readonly.d.ts +0 -6
- package/dist/transforms/v1/column-unsigned-numeric.d.ts +0 -6
- package/dist/transforms/v1/column-width-zerofill.d.ts +0 -6
- package/dist/transforms/v1/connection-to-datasource.d.ts +0 -6
- package/dist/transforms/v1/datasource-mongodb.d.ts +0 -7
- package/dist/transforms/v1/datasource-mssql-domain.d.ts +0 -7
- package/dist/transforms/v1/datasource-mssql-domain.js +0 -35
- package/dist/transforms/v1/datasource-mssql-domain.js.map +0 -1
- package/dist/transforms/v1/datasource-mssql.d.ts +0 -7
- package/dist/transforms/v1/datasource-mysql-connector.d.ts +0 -6
- package/dist/transforms/v1/datasource-name.d.ts +0 -6
- package/dist/transforms/v1/datasource-sap.d.ts +0 -6
- package/dist/transforms/v1/datasource-sqlite-options.d.ts +0 -6
- package/dist/transforms/v1/datasource-sqlite-type.d.ts +0 -6
- package/dist/transforms/v1/find-options-lock-modes.d.ts +0 -6
- package/dist/transforms/v1/find-options-string-relations.d.ts +0 -6
- package/dist/transforms/v1/find-options-string-select.d.ts +0 -6
- package/dist/transforms/v1/global-functions.d.ts +0 -7
- package/dist/transforms/v1/index.d.ts +0 -40
- package/dist/transforms/v1/migrations-get-all.d.ts +0 -7
- package/dist/transforms/v1/mongodb-stats.d.ts +0 -7
- package/dist/transforms/v1/mongodb-types.d.ts +0 -6
- package/dist/transforms/v1/query-builder-native-parameters.d.ts +0 -6
- package/dist/transforms/v1/query-builder-on-conflict.d.ts +0 -7
- package/dist/transforms/v1/query-builder-or-update.d.ts +0 -6
- package/dist/transforms/v1/query-builder-print-sql.d.ts +0 -7
- package/dist/transforms/v1/query-builder-replace-property-names.d.ts +0 -7
- package/dist/transforms/v1/query-builder-where-expression.d.ts +0 -6
- package/dist/transforms/v1/query-runner-loaded-tables-views.d.ts +0 -7
- package/dist/transforms/v1/relation-count.d.ts +0 -7
- package/dist/transforms/v1/remove-abstract-repository.d.ts +0 -5
- package/dist/transforms/v1/remove-abstract-repository.js +0 -93
- package/dist/transforms/v1/remove-abstract-repository.js.map +0 -1
- package/dist/transforms/v1/remove-connector-package.d.ts +0 -4
- package/dist/transforms/v1/remove-connector-package.js +0 -19
- package/dist/transforms/v1/remove-connector-package.js.map +0 -1
- package/dist/transforms/v1/remove-datasource-name.d.ts +0 -4
- package/dist/transforms/v1/remove-datasource-name.js +0 -56
- package/dist/transforms/v1/remove-datasource-name.js.map +0 -1
- package/dist/transforms/v1/remove-mongodb-options.d.ts +0 -5
- package/dist/transforms/v1/remove-mongodb-options.js +0 -86
- package/dist/transforms/v1/remove-mongodb-options.js.map +0 -1
- package/dist/transforms/v1/remove-relation-count.d.ts +0 -5
- package/dist/transforms/v1/remove-relation-count.js +0 -49
- package/dist/transforms/v1/remove-relation-count.js.map +0 -1
- package/dist/transforms/v1/remove-replace-property-names.d.ts +0 -5
- package/dist/transforms/v1/remove-replace-property-names.js +0 -35
- package/dist/transforms/v1/remove-replace-property-names.js.map +0 -1
- package/dist/transforms/v1/remove-sap-options.d.ts +0 -4
- package/dist/transforms/v1/remove-sap-options.js +0 -54
- package/dist/transforms/v1/remove-sap-options.js.map +0 -1
- package/dist/transforms/v1/remove-unsigned-numeric.d.ts +0 -4
- package/dist/transforms/v1/remove-unsigned-numeric.js +0 -76
- package/dist/transforms/v1/remove-unsigned-numeric.js.map +0 -1
- package/dist/transforms/v1/remove-use-container.d.ts +0 -5
- package/dist/transforms/v1/remove-use-container.js +0 -63
- package/dist/transforms/v1/remove-use-container.js.map +0 -1
- package/dist/transforms/v1/remove-width-zerofill.d.ts +0 -4
- package/dist/transforms/v1/remove-width-zerofill.js +0 -29
- package/dist/transforms/v1/remove-width-zerofill.js.map +0 -1
- package/dist/transforms/v1/rename-connection-to-datasource.d.ts +0 -4
- package/dist/transforms/v1/rename-connection-to-datasource.js +0 -111
- package/dist/transforms/v1/rename-connection-to-datasource.js.map +0 -1
- package/dist/transforms/v1/rename-exist-to-exists.d.ts +0 -4
- package/dist/transforms/v1/rename-exist-to-exists.js +0 -25
- package/dist/transforms/v1/rename-exist-to-exists.js.map +0 -1
- package/dist/transforms/v1/rename-find-by-ids.d.ts +0 -4
- package/dist/transforms/v1/rename-find-by-ids.js +0 -64
- package/dist/transforms/v1/rename-find-by-ids.js.map +0 -1
- package/dist/transforms/v1/rename-get-all-migrations.d.ts +0 -5
- package/dist/transforms/v1/rename-get-all-migrations.js +0 -32
- package/dist/transforms/v1/rename-get-all-migrations.js.map +0 -1
- package/dist/transforms/v1/rename-loaded-tables-views.d.ts +0 -5
- package/dist/transforms/v1/rename-loaded-tables-views.js +0 -48
- package/dist/transforms/v1/rename-loaded-tables-views.js.map +0 -1
- package/dist/transforms/v1/rename-or-update-overload.d.ts +0 -4
- package/dist/transforms/v1/rename-or-update-overload.js +0 -46
- package/dist/transforms/v1/rename-or-update-overload.js.map +0 -1
- package/dist/transforms/v1/rename-print-sql-to-log-query.d.ts +0 -4
- package/dist/transforms/v1/rename-print-sql-to-log-query.js +0 -25
- package/dist/transforms/v1/rename-print-sql-to-log-query.js.map +0 -1
- package/dist/transforms/v1/replace-global-functions.d.ts +0 -5
- package/dist/transforms/v1/replace-global-functions.js +0 -92
- package/dist/transforms/v1/replace-global-functions.js.map +0 -1
- package/dist/transforms/v1/replace-lock-modes.d.ts +0 -4
- package/dist/transforms/v1/replace-lock-modes.js +0 -75
- package/dist/transforms/v1/replace-lock-modes.js.map +0 -1
- package/dist/transforms/v1/replace-mongodb-stats.d.ts +0 -5
- package/dist/transforms/v1/replace-mongodb-stats.js +0 -54
- package/dist/transforms/v1/replace-mongodb-stats.js.map +0 -1
- package/dist/transforms/v1/replace-mongodb-types.d.ts +0 -4
- package/dist/transforms/v1/replace-mongodb-types.js +0 -72
- package/dist/transforms/v1/replace-mongodb-types.js.map +0 -1
- package/dist/transforms/v1/replace-mssql-domain.d.ts +0 -5
- package/dist/transforms/v1/replace-mssql-domain.js +0 -25
- package/dist/transforms/v1/replace-mssql-domain.js.map +0 -1
- package/dist/transforms/v1/replace-on-conflict.d.ts +0 -5
- package/dist/transforms/v1/replace-on-conflict.js +0 -49
- package/dist/transforms/v1/replace-on-conflict.js.map +0 -1
- package/dist/transforms/v1/replace-readonly-column.d.ts +0 -4
- package/dist/transforms/v1/replace-readonly-column.js +0 -28
- package/dist/transforms/v1/replace-readonly-column.js.map +0 -1
- package/dist/transforms/v1/replace-set-native-parameters.d.ts +0 -4
- package/dist/transforms/v1/replace-set-native-parameters.js +0 -25
- package/dist/transforms/v1/replace-set-native-parameters.js.map +0 -1
- package/dist/transforms/v1/replace-sqlite-options.d.ts +0 -4
- package/dist/transforms/v1/replace-sqlite-options.js +0 -29
- package/dist/transforms/v1/replace-sqlite-options.js.map +0 -1
- package/dist/transforms/v1/replace-sqlite-type.d.ts +0 -4
- package/dist/transforms/v1/replace-sqlite-type.js +0 -22
- package/dist/transforms/v1/replace-sqlite-type.js.map +0 -1
- package/dist/transforms/v1/replace-where-expression-type.d.ts +0 -4
- package/dist/transforms/v1/replace-where-expression-type.js +0 -41
- package/dist/transforms/v1/replace-where-expression-type.js.map +0 -1
- package/dist/transforms/v1/repository-abstract.d.ts +0 -7
- package/dist/transforms/v1/repository-exist.d.ts +0 -6
- package/dist/transforms/v1/repository-find-by-ids.d.ts +0 -6
- package/dist/transforms/v1/repository-find-one-by-id.d.ts +0 -6
- package/dist/transforms/v1/upgrade-dependencies.d.ts +0 -15
- package/dist/transforms/v1/upgrade-dependencies.js +0 -163
- package/dist/transforms/v1/upgrade-dependencies.js.map +0 -1
- package/dist/transforms/v1/use-container.d.ts +0 -7
|
@@ -5,31 +5,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fn = exports.queryBuilderWhereExpression = exports.description = exports.name = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const ast_helpers_1 = require("../ast-helpers");
|
|
8
9
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
9
10
|
exports.description = "rename `WhereExpression` to `WhereExpressionBuilder`";
|
|
10
11
|
const queryBuilderWhereExpression = (file, api) => {
|
|
11
12
|
const j = api.jscodeshift;
|
|
12
13
|
const root = j(file.source);
|
|
13
14
|
let hasChanges = false;
|
|
14
|
-
|
|
15
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
16
|
+
return undefined;
|
|
17
|
+
// Only rename TS type references that resolve to a TypeORM import —
|
|
18
|
+
// a local `interface WhereExpression {}` or an import from another
|
|
19
|
+
// package must not be rewritten.
|
|
20
|
+
const whereExpressionLocalNames = (0, ast_helpers_1.expandLocalNamesForImports)(root, j, "typeorm", new Set(["WhereExpression"]));
|
|
15
21
|
root.find(j.ImportSpecifier, {
|
|
16
22
|
imported: { name: "WhereExpression" },
|
|
17
|
-
}).forEach((
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
}).forEach((importPath) => {
|
|
24
|
+
const parent = importPath.parent.node;
|
|
25
|
+
if (parent.type !== "ImportDeclaration" ||
|
|
26
|
+
parent.source.value !== "typeorm") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
importPath.node.imported.name = "WhereExpressionBuilder";
|
|
30
|
+
if (importPath.node.local?.type === "Identifier" &&
|
|
31
|
+
importPath.node.local?.name === "WhereExpression") {
|
|
32
|
+
importPath.node.local.name = "WhereExpressionBuilder";
|
|
22
33
|
}
|
|
23
34
|
hasChanges = true;
|
|
24
35
|
});
|
|
25
|
-
|
|
36
|
+
if ((0, ast_helpers_1.renameReExportSpecifiers)(root, j, "typeorm", {
|
|
37
|
+
WhereExpression: "WhereExpressionBuilder",
|
|
38
|
+
})) {
|
|
39
|
+
hasChanges = true;
|
|
40
|
+
}
|
|
26
41
|
root.find(j.TSTypeReference, {
|
|
27
42
|
typeName: { name: "WhereExpression" },
|
|
28
|
-
}).forEach((
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
}).forEach((refPath) => {
|
|
44
|
+
if (refPath.node.typeName.type !== "Identifier")
|
|
45
|
+
return;
|
|
46
|
+
if (!whereExpressionLocalNames.has(refPath.node.typeName.name))
|
|
47
|
+
return;
|
|
48
|
+
refPath.node.typeName.name = "WhereExpressionBuilder";
|
|
49
|
+
hasChanges = true;
|
|
33
50
|
});
|
|
34
51
|
return hasChanges ? root.toSource() : undefined;
|
|
35
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-builder-where-expression.js","sourceRoot":"","sources":["../../../src/transforms/v1/query-builder-where-expression.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"query-builder-where-expression.js","sourceRoot":"","sources":["../../../src/transforms/v1/query-builder-where-expression.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAIuB;AAEV,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,sDAAsD,CAAA;AAEnD,MAAM,2BAA2B,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,E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ACJ,CAAC;QACC,UAAU,GAAG,IAAI,CAAA;IACrB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,EAAE;QACzB,QAAQ,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE;KACxC,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACnB,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;YAAE,OAAM;QACvD,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAM;QACtE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,wBAAwB,CAAA;QACrD,UAAU,GAAG,IAAI,CAAA;IACrB,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AAvDY,QAAA,2BAA2B,+BAuDvC;AAEY,QAAA,EAAE,GAAG,mCAA2B,CAAA;AAC7C,kBAAe,UAAE,CAAA"}
|
|
@@ -22,7 +22,6 @@ const queryRunnerLoadedTablesViews = (file, api) => {
|
|
|
22
22
|
if (!removedProps.has(path.node.property.name))
|
|
23
23
|
return;
|
|
24
24
|
const propName = path.node.property.name;
|
|
25
|
-
// Find the containing statement to add a comment
|
|
26
25
|
let current = path;
|
|
27
26
|
while (current.parent && current.parent.node.type !== "Program") {
|
|
28
27
|
if (current.parent.node.type === "ExpressionStatement" ||
|
|
@@ -30,11 +29,7 @@ const queryRunnerLoadedTablesViews = (file, api) => {
|
|
|
30
29
|
current.parent.node.type === "ReturnStatement") {
|
|
31
30
|
const stmt = current.parent.node;
|
|
32
31
|
const message = `\`${propName}\` was removed — use \`getTables()\` / \`getViews()\` instead`;
|
|
33
|
-
|
|
34
|
-
const commentValue = ` TODO(typeorm-v1): ${message}`;
|
|
35
|
-
const comments = (stmt.comments = stmt.comments || []);
|
|
36
|
-
const hasSameComment = comments.some((c) => c.value === commentValue);
|
|
37
|
-
if (!hasSameComment) {
|
|
32
|
+
if (!(0, todo_1.hasTodoComment)(stmt, message)) {
|
|
38
33
|
(0, todo_1.addTodoComment)(stmt, message, j);
|
|
39
34
|
hasTodos = true;
|
|
40
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-runner-loaded-tables-views.js","sourceRoot":"","sources":["../../../src/transforms/v1/query-runner-loaded-tables-views.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"query-runner-loaded-tables-views.js","sourceRoot":"","sources":["../../../src/transforms/v1/query-runner-loaded-tables-views.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,kCAAwD;AACxD,oCAAgC;AAEnB,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,oGAAoG,CAAA;AAC3F,QAAA,MAAM,GAAG,IAAI,CAAA;AAWnB,MAAM,4BAA4B,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,EAAE;IACrE,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAA;IACzB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3B,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,QAAQ,GAAG,KAAK,CAAA;IAEpB,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAAA;IAE7D,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3C,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI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AEY,QAAA,EAAE,GAAG,oCAA4B,CAAA;AAC9C,kBAAe,UAAE,CAAA"}
|
|
@@ -9,28 +9,94 @@ const ast_helpers_1 = require("../ast-helpers");
|
|
|
9
9
|
const todo_1 = require("../todo");
|
|
10
10
|
const stats_1 = require("../stats");
|
|
11
11
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
12
|
-
exports.description = "flag removed `@RelationCount` decorator for manual migration";
|
|
12
|
+
exports.description = "flag removed `@RelationCount` decorator and `loadRelationCountAndMap()` for manual migration";
|
|
13
13
|
exports.manual = true;
|
|
14
|
+
const MIGRATION_HINT = "use `@VirtualColumn` with a sub-query instead";
|
|
15
|
+
// Node types on which a leading line-comment survives jscodeshift/recast
|
|
16
|
+
// printing — walking up to one of these keeps the comment visible above
|
|
17
|
+
// the enclosing statement or declaration.
|
|
18
|
+
const isTodoHost = (type) => type.endsWith("Statement") ||
|
|
19
|
+
type === "VariableDeclaration" ||
|
|
20
|
+
type === "ExportDefaultDeclaration" ||
|
|
21
|
+
type === "ExportNamedDeclaration" ||
|
|
22
|
+
type === "ClassProperty" ||
|
|
23
|
+
type === "PropertyDefinition";
|
|
14
24
|
const relationCount = (file, api) => {
|
|
15
25
|
const j = api.jscodeshift;
|
|
16
26
|
const root = j(file.source);
|
|
27
|
+
// No `fileImportsFrom` guard at the top: `.loadRelationCountAndMap()` call
|
|
28
|
+
// sites can appear in files that only receive a `QueryBuilder` via a helper
|
|
29
|
+
// and never import from "typeorm" directly. The decorator and import-
|
|
30
|
+
// removal blocks below self-gate via `getLocalNamesForImport` /
|
|
31
|
+
// `removeImportSpecifiers`, which are no-ops when typeorm is absent.
|
|
17
32
|
let hasChanges = false;
|
|
18
33
|
let hasTodos = false;
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
// Collect local names bound to `RelationCount` from typeorm — including aliases:
|
|
35
|
+
// import { RelationCount } from "typeorm" → "RelationCount"
|
|
36
|
+
// import { RelationCount as RC } from "typeorm" → "RC"
|
|
37
|
+
const localNames = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "RelationCount");
|
|
38
|
+
if (localNames.size > 0) {
|
|
39
|
+
// Decorators live on `ClassProperty.decorators` but jscodeshift's
|
|
40
|
+
// default visitor does not descend into that array, so
|
|
41
|
+
// `root.find(j.Decorator)` is a no-op with the `tsx` parser. Walk the
|
|
42
|
+
// class properties explicitly instead and attach the comment to the
|
|
43
|
+
// property itself (decorator-attached comments are dropped by recast).
|
|
44
|
+
const message = `\`@RelationCount\` was removed — ${MIGRATION_HINT}`;
|
|
45
|
+
root.find(j.ClassProperty).forEach((propertyPath) => {
|
|
46
|
+
const node = propertyPath.node;
|
|
47
|
+
const matches = node.decorators?.some((decorator) => {
|
|
48
|
+
const expr = decorator.expression;
|
|
49
|
+
return (expr.type === "CallExpression" &&
|
|
50
|
+
expr.callee.type === "Identifier" &&
|
|
51
|
+
localNames.has(expr.callee.name));
|
|
52
|
+
});
|
|
53
|
+
if (!matches)
|
|
54
|
+
return;
|
|
55
|
+
if ((0, todo_1.hasTodoComment)(node, message))
|
|
56
|
+
return;
|
|
57
|
+
(0, todo_1.addTodoComment)(node, message, j);
|
|
58
|
+
hasChanges = true;
|
|
59
|
+
hasTodos = true;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// Find .loadRelationCountAndMap() call sites — attach the comment above the enclosing statement.
|
|
63
|
+
// Multiple chained calls on one statement resolve to the same host, so the
|
|
64
|
+
// `hasTodoComment` guard keeps the transform idempotent.
|
|
65
|
+
const callMessage = `\`loadRelationCountAndMap()\` was removed — ${MIGRATION_HINT}`;
|
|
66
|
+
// Match both dot access (`qb.loadRelationCountAndMap()`) and computed
|
|
67
|
+
// access (`qb["loadRelationCountAndMap"]()`). Use a post-filter rather
|
|
68
|
+
// than a find-pattern so the computed-key branch is visited too.
|
|
69
|
+
root.find(j.CallExpression).forEach((callPath) => {
|
|
70
|
+
const callee = callPath.node.callee;
|
|
71
|
+
if (callee.type !== "MemberExpression")
|
|
72
|
+
return;
|
|
73
|
+
const prop = callee.property;
|
|
74
|
+
const matches = (prop.type === "Identifier" &&
|
|
75
|
+
prop.name === "loadRelationCountAndMap") ||
|
|
76
|
+
(callee.computed &&
|
|
77
|
+
(0, ast_helpers_1.getStringValue)(prop) === "loadRelationCountAndMap");
|
|
78
|
+
if (!matches)
|
|
79
|
+
return;
|
|
80
|
+
let current = callPath.parent;
|
|
81
|
+
while (current) {
|
|
82
|
+
const node = current.node;
|
|
83
|
+
if (isTodoHost(node.type)) {
|
|
84
|
+
if (!(0, todo_1.hasTodoComment)(node, callMessage)) {
|
|
85
|
+
(0, todo_1.addTodoComment)(node, callMessage, j);
|
|
86
|
+
hasChanges = true;
|
|
87
|
+
hasTodos = true;
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
current = current.parent;
|
|
92
|
+
}
|
|
29
93
|
});
|
|
30
|
-
// Remove RelationCount import from typeorm
|
|
31
94
|
if ((0, ast_helpers_1.removeImportSpecifiers)(root, j, "typeorm", new Set(["RelationCount"]))) {
|
|
32
95
|
hasChanges = true;
|
|
33
96
|
}
|
|
97
|
+
if ((0, ast_helpers_1.removeReExportSpecifiers)(root, j, "typeorm", new Set(["RelationCount"]))) {
|
|
98
|
+
hasChanges = true;
|
|
99
|
+
}
|
|
34
100
|
if (hasTodos)
|
|
35
101
|
stats_1.stats.count.todo(api, exports.name, file);
|
|
36
102
|
return hasChanges ? root.toSource() : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation-count.js","sourceRoot":"","sources":["../../../src/transforms/v1/relation-count.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"relation-count.js","sourceRoot":"","sources":["../../../src/transforms/v1/relation-count.ts"],"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,iBAiGzB;AAEY,QAAA,EAAE,GAAG,qBAAa,CAAA;AAC/B,kBAAe,UAAE,CAAA"}
|
|
@@ -14,63 +14,177 @@ exports.manual = true;
|
|
|
14
14
|
const repositoryAbstract = (file, api) => {
|
|
15
15
|
const j = api.jscodeshift;
|
|
16
16
|
const root = j(file.source);
|
|
17
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
18
|
+
return undefined;
|
|
17
19
|
let hasChanges = false;
|
|
18
20
|
let hasTodos = false;
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
// Resolve alias-aware local names so aliased imports like
|
|
22
|
+
// `import { getCustomRepository as gcr } from "typeorm"` still get
|
|
23
|
+
// their call-sites flagged before the import is removed.
|
|
24
|
+
const entityRepositoryNames = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "EntityRepository");
|
|
25
|
+
const abstractRepositoryNames = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "AbstractRepository");
|
|
26
|
+
const getCustomRepositoryNames = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "getCustomRepository");
|
|
27
|
+
// Track which symbols were successfully flagged; we only strip imports
|
|
28
|
+
// for symbols whose usages got a comment — dropping an import while a
|
|
29
|
+
// type reference or conditional use survives would leave the user with
|
|
30
|
+
// a dangling reference and no signal.
|
|
31
|
+
const flaggedSymbols = new Set();
|
|
32
|
+
// Namespace bindings for `import * as typeorm from "typeorm"` and the
|
|
33
|
+
// matching CommonJS form — used below to match `typeorm.AbstractRepository`
|
|
34
|
+
// / `typeorm.EntityRepository` / `typeorm.getCustomRepository` references.
|
|
35
|
+
const typeormNamespaces = (0, ast_helpers_1.getNamespaceLocalNames)(root, j, "typeorm");
|
|
36
|
+
const isTypeormNamespaceMember = (expr, memberName) => {
|
|
37
|
+
if (expr.type !== "MemberExpression")
|
|
38
|
+
return false;
|
|
39
|
+
const member = expr;
|
|
40
|
+
return (member.object.type === "Identifier" &&
|
|
41
|
+
typeormNamespaces.has(member.object.name) &&
|
|
42
|
+
member.property.type === "Identifier" &&
|
|
43
|
+
member.property.name === memberName);
|
|
44
|
+
};
|
|
45
|
+
// Find @EntityRepository decorators (including aliased names and
|
|
46
|
+
// `@typeorm.EntityRepository()` namespace-access form)
|
|
47
|
+
root.find(j.ClassDeclaration)
|
|
48
|
+
.filter((classPath) => {
|
|
49
|
+
const decorators = classPath.node
|
|
50
|
+
.decorators;
|
|
51
|
+
if (!decorators)
|
|
52
|
+
return false;
|
|
53
|
+
for (const decorator of decorators) {
|
|
54
|
+
const expr = decorator.expression;
|
|
55
|
+
if (expr.type !== "CallExpression")
|
|
56
|
+
continue;
|
|
57
|
+
if (expr.callee.type === "Identifier" &&
|
|
58
|
+
entityRepositoryNames.has(expr.callee.name)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (isTypeormNamespaceMember(expr.callee, "EntityRepository")) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
})
|
|
67
|
+
.forEach((classPath) => {
|
|
68
|
+
const message = "`@EntityRepository` was removed — use a custom service class with `dataSource.getRepository()`";
|
|
69
|
+
if (!(0, todo_1.hasTodoComment)(classPath.node, message)) {
|
|
70
|
+
(0, todo_1.addTodoComment)(classPath.node, message, j);
|
|
71
|
+
}
|
|
27
72
|
hasChanges = true;
|
|
28
73
|
hasTodos = true;
|
|
74
|
+
flaggedSymbols.add("EntityRepository");
|
|
29
75
|
});
|
|
30
|
-
// Find classes extending AbstractRepository
|
|
31
|
-
|
|
32
|
-
|
|
76
|
+
// Find classes extending AbstractRepository — covers:
|
|
77
|
+
// class X extends AbstractRepository {} (named/aliased import)
|
|
78
|
+
// class X extends typeorm.AbstractRepository {} (namespace import)
|
|
79
|
+
root.find(j.ClassDeclaration).forEach((classPath) => {
|
|
80
|
+
const superClass = classPath.node.superClass;
|
|
33
81
|
if (!superClass)
|
|
34
82
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else if (superClass.type === "MemberExpression" &&
|
|
40
|
-
superClass.property.type === "Identifier") {
|
|
41
|
-
name = superClass.property.name;
|
|
42
|
-
}
|
|
43
|
-
if (name !== "AbstractRepository")
|
|
83
|
+
const matches = (superClass.type === "Identifier" &&
|
|
84
|
+
abstractRepositoryNames.has(superClass.name)) ||
|
|
85
|
+
isTypeormNamespaceMember(superClass, "AbstractRepository");
|
|
86
|
+
if (!matches)
|
|
44
87
|
return;
|
|
45
|
-
|
|
88
|
+
const message = "`AbstractRepository` was removed — use a custom service class with `dataSource.getRepository()`";
|
|
89
|
+
if (!(0, todo_1.hasTodoComment)(classPath.node, message)) {
|
|
90
|
+
(0, todo_1.addTodoComment)(classPath.node, message, j);
|
|
91
|
+
}
|
|
46
92
|
hasChanges = true;
|
|
47
93
|
hasTodos = true;
|
|
94
|
+
flaggedSymbols.add("AbstractRepository");
|
|
48
95
|
});
|
|
49
|
-
//
|
|
50
|
-
|
|
96
|
+
// TS type-reference usages (e.g. `extends AbstractRepository<User>` in
|
|
97
|
+
// a generic signature, or `T extends EntityRepository`). Without this,
|
|
98
|
+
// a file that only uses the symbol as a type would have its import
|
|
99
|
+
// silently stripped and be left with a dangling reference.
|
|
100
|
+
const flagTypeReference = (names, symbolName, message) => {
|
|
101
|
+
root.find(j.TSTypeReference)
|
|
102
|
+
.filter((p) => {
|
|
103
|
+
const typeName = p.node.typeName;
|
|
104
|
+
return (typeName.type === "Identifier" &&
|
|
105
|
+
names.has(typeName.name));
|
|
106
|
+
})
|
|
107
|
+
.forEach((p) => {
|
|
108
|
+
let current = p.parent;
|
|
109
|
+
while (current) {
|
|
110
|
+
const node = current.node;
|
|
111
|
+
if (node.type.endsWith("Statement") ||
|
|
112
|
+
node.type === "VariableDeclaration" ||
|
|
113
|
+
node.type === "ClassDeclaration" ||
|
|
114
|
+
node.type === "ClassExpression" ||
|
|
115
|
+
node.type === "ExportDefaultDeclaration" ||
|
|
116
|
+
node.type === "ExportNamedDeclaration") {
|
|
117
|
+
if (!(0, todo_1.hasTodoComment)(node, message)) {
|
|
118
|
+
(0, todo_1.addTodoComment)(node, message, j);
|
|
119
|
+
}
|
|
120
|
+
hasChanges = true;
|
|
121
|
+
hasTodos = true;
|
|
122
|
+
flaggedSymbols.add(symbolName);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
current = current.parent;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
flagTypeReference(entityRepositoryNames, "EntityRepository", "`@EntityRepository` was removed — use a custom service class with `dataSource.getRepository()`");
|
|
130
|
+
flagTypeReference(abstractRepositoryNames, "AbstractRepository", "`AbstractRepository` was removed — use a custom service class with `dataSource.getRepository()`");
|
|
131
|
+
const addGetCustomRepoTodo = (callPath) => {
|
|
51
132
|
const message = "`getCustomRepository()` was removed — use a custom service class with `dataSource.getRepository()`";
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
133
|
+
// Walk up to the enclosing statement — comments attached to a bare
|
|
134
|
+
// `CallExpression` are commonly dropped by recast during printing.
|
|
135
|
+
let current = callPath;
|
|
136
|
+
let host = null;
|
|
137
|
+
while (current) {
|
|
138
|
+
const t = current.node.type;
|
|
139
|
+
if (t.endsWith("Statement") || t === "VariableDeclaration") {
|
|
140
|
+
host = current.node;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
current = current.parent;
|
|
55
144
|
}
|
|
56
|
-
|
|
57
|
-
|
|
145
|
+
if (!host)
|
|
146
|
+
return;
|
|
147
|
+
if (!(0, todo_1.hasTodoComment)(host, message)) {
|
|
148
|
+
(0, todo_1.addTodoComment)(host, message, j);
|
|
58
149
|
}
|
|
59
150
|
hasChanges = true;
|
|
60
151
|
hasTodos = true;
|
|
152
|
+
flaggedSymbols.add("getCustomRepository");
|
|
61
153
|
};
|
|
154
|
+
// Member-expression form: `something.getCustomRepository(...)` — not
|
|
155
|
+
// alias-dependent, matches property name directly. This also covers the
|
|
156
|
+
// namespace-access form `typeorm.getCustomRepository(...)` since the
|
|
157
|
+
// property name is the same.
|
|
62
158
|
root.find(j.CallExpression, {
|
|
63
159
|
callee: {
|
|
64
160
|
type: "MemberExpression",
|
|
65
161
|
property: { type: "Identifier", name: "getCustomRepository" },
|
|
66
162
|
},
|
|
67
163
|
}).forEach(addGetCustomRepoTodo);
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
164
|
+
// Standalone form: `getCustomRepository(...)` — also handles aliased
|
|
165
|
+
// imports by looking up local names against the import scan.
|
|
166
|
+
root.find(j.CallExpression)
|
|
167
|
+
.filter((callPath) => {
|
|
168
|
+
const callee = callPath.node.callee;
|
|
169
|
+
return (callee.type === "Identifier" &&
|
|
170
|
+
getCustomRepositoryNames.has(callee.name));
|
|
171
|
+
})
|
|
172
|
+
.forEach(addGetCustomRepoTodo);
|
|
173
|
+
// Only strip imports/re-exports of symbols whose usages we successfully
|
|
174
|
+
// flagged. A surviving reference (e.g. inside a conditional type or a
|
|
175
|
+
// generic signature we didn't walk) + missing import = silently broken
|
|
176
|
+
// file. Re-exports are always safe to strip since no runtime usage
|
|
177
|
+
// depends on them.
|
|
178
|
+
if (flaggedSymbols.size > 0) {
|
|
179
|
+
if ((0, ast_helpers_1.removeImportSpecifiers)(root, j, "typeorm", flaggedSymbols)) {
|
|
180
|
+
hasChanges = true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if ((0, ast_helpers_1.removeReExportSpecifiers)(root, j, "typeorm", new Set([
|
|
184
|
+
"EntityRepository",
|
|
185
|
+
"AbstractRepository",
|
|
186
|
+
"getCustomRepository",
|
|
187
|
+
]))) {
|
|
74
188
|
hasChanges = true;
|
|
75
189
|
}
|
|
76
190
|
if (hasTodos)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-abstract.js","sourceRoot":"","sources":["../../../src/transforms/v1/repository-abstract.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"repository-abstract.js","sourceRoot":"","sources":["../../../src/transforms/v1/repository-abstract.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAS5B,gDAMuB;AACvB,kCAAwD;AACxD,oCAAgC;AAEnB,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GACpB,gFAAgF,CAAA;AACvE,QAAA,MAAM,GAAG,IAAI,CAAA;AAEnB,MAAM,kBAAkB,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,EAAE;IAC3D,MAAM,CAAC,GAAG,GAAG,CAAC,WAAW,CAAA;IACzB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAE3B,IAAI,CAAC,IAAA,6BAAe,EAAC,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC;QAAE,OAAO,SAAS,CAAA;IAE1D,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,QAAQ,GAAG,KAAK,CAAA;IAEpB,0DAA0D;IAC1D,mEAAmE;IACnE,yDAAyD;IACzD,MAAM,qBAAqB,GAAG,IAAA,oCAAsB,EAChD,IAAI,EACJ,CAAC,EACD,SAAS,EACT,kBAAkB,CACrB,CAAA;IACD,MAAM,uBAAuB,GAAG,IAAA,oCAAsB,EAClD,IAAI,EACJ,CAAC,EACD,SAAS,EACT,oBAAoB,CACvB,CAAA;IACD,MAAM,wBAAwB,GAAG,IAAA,oCAAsB,EACnD,IAAI,EACJ,CAAC,EACD,SAAS,EACT,qBAAqB,CACxB,CAAA;IAED,uEAAuE;IACvE,sEAAsE;IACtE,uEAAuE;IACvE,sCAAsC;IACtC,M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
@@ -11,7 +11,26 @@ exports.description = "rename `Repository.exist()` to `exists()`";
|
|
|
11
11
|
const repositoryExist = (file, api) => {
|
|
12
12
|
const j = api.jscodeshift;
|
|
13
13
|
const root = j(file.source);
|
|
14
|
-
|
|
14
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
15
|
+
return undefined;
|
|
16
|
+
const bindings = (0, ast_helpers_1.collectRepositoryBindings)(root, j);
|
|
17
|
+
let hasChanges = false;
|
|
18
|
+
root.find(j.CallExpression, {
|
|
19
|
+
callee: {
|
|
20
|
+
type: "MemberExpression",
|
|
21
|
+
property: { type: "Identifier", name: "exist" },
|
|
22
|
+
},
|
|
23
|
+
}).forEach((callPath) => {
|
|
24
|
+
const callee = callPath.node.callee;
|
|
25
|
+
if (callee.type !== "MemberExpression")
|
|
26
|
+
return;
|
|
27
|
+
if (callee.property.type !== "Identifier")
|
|
28
|
+
return;
|
|
29
|
+
if (!(0, ast_helpers_1.isRepositoryReceiver)(callee.object, bindings))
|
|
30
|
+
return;
|
|
31
|
+
callee.property.name = "exists";
|
|
32
|
+
hasChanges = true;
|
|
33
|
+
});
|
|
15
34
|
return hasChanges ? root.toSource() : undefined;
|
|
16
35
|
};
|
|
17
36
|
exports.repositoryExist = repositoryExist;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-exist.js","sourceRoot":"","sources":["../../../src/transforms/v1/repository-exist.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"repository-exist.js","sourceRoot":"","sources":["../../../src/transforms/v1/repository-exist.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,gDAIuB;AAEV,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;AAC1D,QAAA,WAAW,GAAG,2CAA2C,CAAA;AAE/D,MAAM,eAAe,G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, "__esModule", { value: true });
|
|
|
6
6
|
exports.fn = exports.repositoryFindByIds = exports.description = exports.name = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const ast_helpers_1 = require("../ast-helpers");
|
|
9
|
+
// A typeorm import declaration that we can safely augment with a new named
|
|
10
|
+
// value specifier. Rejects:
|
|
11
|
+
// - `import type { ... } from "typeorm"` (declaration-level type-only)
|
|
12
|
+
// - `import "typeorm"` (side-effect only, no specifiers)
|
|
13
|
+
// - `import * as typeorm from "typeorm"` (namespace only — pushing a named
|
|
14
|
+
// specifier would produce `import * as typeorm, { In }` which is invalid)
|
|
15
|
+
// - `import typeorm from "typeorm"` (default only — same issue)
|
|
16
|
+
// Only a decl that already carries at least one value-level ImportSpecifier
|
|
17
|
+
// (named import) is considered augmentable.
|
|
18
|
+
const canAcceptNamedValueSpecifier = (node) => {
|
|
19
|
+
if (node.importKind === "type")
|
|
20
|
+
return false;
|
|
21
|
+
const specifiers = node.specifiers ?? [];
|
|
22
|
+
if (specifiers.length === 0)
|
|
23
|
+
return false;
|
|
24
|
+
return specifiers.some((s) => s.type === "ImportSpecifier" && s.importKind !== "type");
|
|
25
|
+
};
|
|
26
|
+
// `In` is used as a VALUE (`In([...])`) — it must not be added to a
|
|
27
|
+
// `import type { ... } from "typeorm"` declaration, and the per-specifier
|
|
28
|
+
// form `import { type In }` is equally unusable. Find the first existing
|
|
29
|
+
// value-level `In` binding or an augmentable value-level typeorm import;
|
|
30
|
+
// fall back to emitting a fresh `import { In } from "typeorm"` line.
|
|
31
|
+
const ensureInValueImport = (root, j) => {
|
|
32
|
+
const typeormImports = root.find(j.ImportDeclaration, {
|
|
33
|
+
source: { value: "typeorm" },
|
|
34
|
+
});
|
|
35
|
+
let hasInValueImport = false;
|
|
36
|
+
typeormImports.forEach((p) => {
|
|
37
|
+
const declTypeOnly = p.node.importKind === "type";
|
|
38
|
+
p.node.specifiers?.forEach((spec) => {
|
|
39
|
+
if (spec.type === "ImportSpecifier" &&
|
|
40
|
+
spec.imported.type === "Identifier" &&
|
|
41
|
+
spec.imported.name === "In") {
|
|
42
|
+
const specTypeOnly = spec.importKind === "type";
|
|
43
|
+
if (!declTypeOnly && !specTypeOnly)
|
|
44
|
+
hasInValueImport = true;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
if (hasInValueImport)
|
|
49
|
+
return;
|
|
50
|
+
let augmented = false;
|
|
51
|
+
typeormImports.forEach((p) => {
|
|
52
|
+
if (augmented)
|
|
53
|
+
return;
|
|
54
|
+
if (!canAcceptNamedValueSpecifier(p.node))
|
|
55
|
+
return;
|
|
56
|
+
p.node.specifiers?.push(j.importSpecifier(j.identifier("In")));
|
|
57
|
+
augmented = true;
|
|
58
|
+
});
|
|
59
|
+
if (augmented)
|
|
60
|
+
return;
|
|
61
|
+
const newImport = j.importDeclaration([j.importSpecifier(j.identifier("In"))], j.literal("typeorm"));
|
|
62
|
+
const allImports = root.find(j.ImportDeclaration);
|
|
63
|
+
if (allImports.length > 0) {
|
|
64
|
+
allImports.at(-1).insertAfter(newImport);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
root.find(j.Program).forEach((p) => {
|
|
68
|
+
p.node.body.unshift(newImport);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
9
72
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
10
73
|
exports.description = "replace `findByIds()` with `findBy()` and `In` operator";
|
|
11
74
|
const repositoryFindByIds = (file, api) => {
|
|
@@ -16,6 +79,7 @@ const repositoryFindByIds = (file, api) => {
|
|
|
16
79
|
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm")) {
|
|
17
80
|
return undefined;
|
|
18
81
|
}
|
|
82
|
+
const bindings = (0, ast_helpers_1.collectRepositoryBindings)(root, j);
|
|
19
83
|
root.find(j.CallExpression, {
|
|
20
84
|
callee: {
|
|
21
85
|
type: "MemberExpression",
|
|
@@ -26,6 +90,8 @@ const repositoryFindByIds = (file, api) => {
|
|
|
26
90
|
path.node.arguments.length !== 1) {
|
|
27
91
|
return;
|
|
28
92
|
}
|
|
93
|
+
if (!(0, ast_helpers_1.isRepositoryReceiver)(path.node.callee.object, bindings))
|
|
94
|
+
return;
|
|
29
95
|
const idsArg = path.node.arguments[0];
|
|
30
96
|
// Replace .findByIds(ids) with .findBy({ id: In(ids) })
|
|
31
97
|
path.node.callee.property = j.identifier("findBy");
|
|
@@ -37,34 +103,8 @@ const repositoryFindByIds = (file, api) => {
|
|
|
37
103
|
hasChanges = true;
|
|
38
104
|
needsInImport = true;
|
|
39
105
|
});
|
|
40
|
-
// Add In import if needed
|
|
41
106
|
if (needsInImport) {
|
|
42
|
-
|
|
43
|
-
source: { value: "typeorm" },
|
|
44
|
-
});
|
|
45
|
-
let hasInImport = false;
|
|
46
|
-
typeormImports.forEach((path) => {
|
|
47
|
-
path.node.specifiers?.forEach((spec) => {
|
|
48
|
-
if (spec.type === "ImportSpecifier" &&
|
|
49
|
-
spec.imported.type === "Identifier" &&
|
|
50
|
-
spec.imported.name === "In") {
|
|
51
|
-
hasInImport = true;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
if (!hasInImport) {
|
|
56
|
-
if (typeormImports.length > 0) {
|
|
57
|
-
// Add to existing typeorm import
|
|
58
|
-
typeormImports.at(0).forEach((path) => {
|
|
59
|
-
path.node.specifiers?.push(j.importSpecifier(j.identifier("In")));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// Create new import
|
|
64
|
-
const newImport = j.importDeclaration([j.importSpecifier(j.identifier("In"))], j.literal("typeorm"));
|
|
65
|
-
root.find(j.ImportDeclaration).at(-1).insertAfter(newImport);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
107
|
+
ensureInValueImport(root, j);
|
|
68
108
|
}
|
|
69
109
|
return hasChanges ? root.toSource() : undefined;
|
|
70
110
|
};
|