@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
|
@@ -11,6 +11,8 @@ exports.description = "replace deprecated pessimistic lock modes";
|
|
|
11
11
|
const findOptionsLockModes = (file, api) => {
|
|
12
12
|
const j = api.jscodeshift;
|
|
13
13
|
const root = j(file.source);
|
|
14
|
+
if (!(0, ast_helpers_1.fileImportsFrom)(root, j, "typeorm"))
|
|
15
|
+
return undefined;
|
|
14
16
|
let hasChanges = false;
|
|
15
17
|
const lockModeMap = {
|
|
16
18
|
pessimistic_partial_write: {
|
|
@@ -36,43 +38,46 @@ const findOptionsLockModes = (file, api) => {
|
|
|
36
38
|
if (!value || !lockModeMap[value])
|
|
37
39
|
return;
|
|
38
40
|
const replacement = lockModeMap[value];
|
|
39
|
-
// Change the lock mode argument
|
|
40
41
|
(0, ast_helpers_1.setStringValue)(arg, replacement.mode);
|
|
41
|
-
// Wrap in .setOnLocked() call
|
|
42
42
|
const setOnLocked = j.callExpression(j.memberExpression(path.node, j.identifier("setOnLocked")), [j.stringLiteral(replacement.onLocked)]);
|
|
43
43
|
j(path).replaceWith(setOnLocked);
|
|
44
44
|
hasChanges = true;
|
|
45
45
|
});
|
|
46
46
|
// Handle find options: { lock: { mode: "pessimistic_partial_write" } }
|
|
47
47
|
// → { lock: { mode: "pessimistic_write", onLocked: "skip_locked" } }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
// Match both Property (Esprima) and ObjectProperty (Babel) node shapes.
|
|
49
|
+
const keyNameOf = (key) => key.type === "Identifier" ? key.name : (0, ast_helpers_1.getStringValue)(key);
|
|
50
|
+
const visitModeProperty = (astPath) => {
|
|
51
|
+
if (keyNameOf(astPath.node.key) !== "mode")
|
|
52
|
+
return;
|
|
53
|
+
const value = (0, ast_helpers_1.getStringValue)(astPath.node.value);
|
|
52
54
|
if (!value || !lockModeMap[value])
|
|
53
55
|
return;
|
|
54
|
-
|
|
55
|
-
if (path.parent.node.type !== "ObjectExpression")
|
|
56
|
+
if (astPath.parent.node.type !== "ObjectExpression")
|
|
56
57
|
return;
|
|
57
|
-
const lockObj =
|
|
58
|
-
const grandparent =
|
|
59
|
-
if (grandparent.
|
|
60
|
-
grandparent.
|
|
61
|
-
grandparent.node.key.name !== "lock") {
|
|
58
|
+
const lockObj = astPath.parent.node;
|
|
59
|
+
const grandparent = astPath.parent.parent.node;
|
|
60
|
+
if (grandparent.type !== "Property" &&
|
|
61
|
+
grandparent.type !== "ObjectProperty") {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
+
if (keyNameOf(grandparent.key) !== "lock")
|
|
65
|
+
return;
|
|
64
66
|
const replacement = lockModeMap[value];
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const hasOnLocked = lockObj.properties.some((p) => p.type === "Property" &&
|
|
69
|
-
p.key.type === "Identifier" &&
|
|
70
|
-
p.key.name === "onLocked");
|
|
67
|
+
(0, ast_helpers_1.setStringValue)(astPath.node.value, replacement.mode);
|
|
68
|
+
const hasOnLocked = lockObj.properties.some((p) => (p.type === "Property" || p.type === "ObjectProperty") &&
|
|
69
|
+
keyNameOf(p.key) === "onLocked");
|
|
71
70
|
if (!hasOnLocked) {
|
|
72
|
-
|
|
71
|
+
// Use `objectProperty` (Babel builder) rather than `property` so
|
|
72
|
+
// the injected node matches the sibling nodes produced by the
|
|
73
|
+
// `tsx` parser — avoids mixing `Property` and `ObjectProperty`
|
|
74
|
+
// inside the same `ObjectExpression.properties` array.
|
|
75
|
+
lockObj.properties.push(j.objectProperty(j.identifier("onLocked"), j.stringLiteral(replacement.onLocked)));
|
|
73
76
|
}
|
|
74
77
|
hasChanges = true;
|
|
75
|
-
}
|
|
78
|
+
};
|
|
79
|
+
root.find(j.Property).forEach(visitModeProperty);
|
|
80
|
+
root.find(j.ObjectProperty).forEach(visitModeProperty);
|
|
76
81
|
return hasChanges ? root.toSource() : undefined;
|
|
77
82
|
};
|
|
78
83
|
exports.findOptionsLockModes = findOptionsLockModes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-options-lock-modes.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-lock-modes.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"find-options-lock-modes.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-lock-modes.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAU5B,gDAAgF;AAEnE,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,oBAAoB,GAAG,CAAC,IAAc,EAAE,GAAQ,EAAE,EAAE;IAC7D,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;IAEtB,MAAM,WAAW,GAAuD;QACpE,yBAAyB,EAAE;YACvB,IAAI,EAAE,mBAAmB;YACzB,QAAQ,EAAE,aAAa;SAC1B;QACD,yBAAyB,EAAE;YACvB,IAAI,EAAE,mBAAmB;YACzB,QAAQ,EAAE,QAAQ;SACrB;KACJ,CAAA;IAED,0GAA0G;IAC1G,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE;QACxB,MAAM,EAAE;YACJ,IAAI,EAAE,kBAAkB;YACxB,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,E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CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAChD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAEtD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AApGY,QAAA,oBAAoB,wBAoGhC;AAEY,QAAA,EAAE,GAAG,4BAAoB,CAAA;AACtC,kBAAe,UAAE,CAAA"}
|
|
@@ -3,11 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fn = exports.findOptionsStringRelations = exports.description = exports.name = void 0;
|
|
6
|
+
exports.fn = exports.findOptionsStringRelations = exports.manual = 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
|
+
const todo_1 = require("../todo");
|
|
10
|
+
const stats_1 = require("../stats");
|
|
9
11
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
10
12
|
exports.description = "replace string-array `relations` with object syntax";
|
|
13
|
+
exports.manual = true;
|
|
14
|
+
// `relations` differs from `select` in one important way: v0 supported
|
|
15
|
+
// dot-paths (`"posts.comments"`) that must become nested objects in v1
|
|
16
|
+
// (`{ posts: { comments: true } }`). For a dynamic expression we can't
|
|
17
|
+
// tell at transform time whether the values contain dots, so we wrap with
|
|
18
|
+
// `Object.fromEntries(...map(r => [r, true]))` AND attach a comment
|
|
19
|
+
// noting that dot-paths need manual nesting.
|
|
20
|
+
const DYNAMIC_RELATIONS_DOT_PATH_NOTE = '`relations` now takes an object. If the dynamic list contains dot-paths like `"posts.comments"`, the wrap below produces `{ "posts.comments": true }` — convert those to nested objects manually: `{ posts: { comments: true } }`.';
|
|
21
|
+
// Bound variables / member-access values may already hold v1 object form
|
|
22
|
+
// instead of `string[]`, so wrapping would crash at runtime. Leave a
|
|
23
|
+
// comment with the conversion snippets so the user picks the right option.
|
|
24
|
+
const BOUND_RELATIONS_MESSAGE = "`relations` no longer accepts a string array. This value references a variable whose shape can't be determined statically — if it holds `string[]`, wrap it: `Object.fromEntries(<expr>?.map(r => [r, true]) ?? [])` (dot-paths need extra nesting handling). If it already holds the v1 object shape, no change needed.";
|
|
11
25
|
/**
|
|
12
26
|
* Convert an array of dot-path strings into a nested object structure.
|
|
13
27
|
*
|
|
@@ -34,24 +48,76 @@ function convertRelationsArrayToObject(values) {
|
|
|
34
48
|
}
|
|
35
49
|
return result;
|
|
36
50
|
}
|
|
51
|
+
// Builds `Object.fromEntries(<expr>?.map(r => [r, true]) ?? [])` — the
|
|
52
|
+
// optional-chain + nullish fallback keeps the migrated code runnable when
|
|
53
|
+
// the dynamic expression evaluates to `undefined`/`null` (e.g.
|
|
54
|
+
// `relations: flag ? ["posts"] : undefined`). v0 would have skipped the
|
|
55
|
+
// property in that case; the wrap here emits an empty object, matching.
|
|
56
|
+
const wrapDynamicStringArray = (j, expr) => {
|
|
57
|
+
const optionalMapCall = j.callExpression(j.optionalMemberExpression(expr, j.identifier("map")), [
|
|
58
|
+
j.arrowFunctionExpression([j.identifier("r")], j.arrayExpression([j.identifier("r"), j.literal(true)])),
|
|
59
|
+
]);
|
|
60
|
+
return j.callExpression(j.memberExpression(j.identifier("Object"), j.identifier("fromEntries")), [j.logicalExpression("??", optionalMapCall, j.arrayExpression([]))]);
|
|
61
|
+
};
|
|
37
62
|
const findOptionsStringRelations = (file, api) => {
|
|
38
63
|
const j = api.jscodeshift;
|
|
39
64
|
const root = j(file.source);
|
|
40
65
|
let hasChanges = false;
|
|
41
|
-
|
|
66
|
+
let hasTodos = false;
|
|
42
67
|
root.find(j.ObjectProperty, {
|
|
43
68
|
key: { name: "relations" },
|
|
44
|
-
}).forEach((
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
}).forEach((propPath) => {
|
|
70
|
+
if (!(0, ast_helpers_1.isFindMethodCallArgument)(propPath))
|
|
71
|
+
return;
|
|
72
|
+
const value = propPath.node.value;
|
|
73
|
+
if (value.type === "ArrayExpression") {
|
|
74
|
+
const strings = value.elements.map((el) => el && (0, ast_helpers_1.getStringValue)(el));
|
|
75
|
+
if (strings.some((s) => s === null || s === undefined))
|
|
76
|
+
return;
|
|
77
|
+
const result = convertRelationsArrayToObject(strings);
|
|
78
|
+
propPath.node.value = buildObjectExpression(j, result);
|
|
79
|
+
hasChanges = true;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Already in v1 object form — nothing to do.
|
|
83
|
+
if (value.type === "ObjectExpression")
|
|
47
84
|
return;
|
|
48
|
-
|
|
49
|
-
|
|
85
|
+
// Already wrapped by a previous pass — don't double-wrap, and don't
|
|
86
|
+
// re-add the dot-path comment (`hasTodoComment` would dedupe it anyway).
|
|
87
|
+
if ((0, ast_helpers_1.isObjectFromEntriesCall)(value))
|
|
50
88
|
return;
|
|
51
|
-
const
|
|
52
|
-
|
|
89
|
+
const walkToStatement = (message) => {
|
|
90
|
+
let current = propPath.parent;
|
|
91
|
+
while (current) {
|
|
92
|
+
const t = current.node.type;
|
|
93
|
+
if (t.endsWith("Statement") || t === "VariableDeclaration") {
|
|
94
|
+
if (!(0, todo_1.hasTodoComment)(current.node, message)) {
|
|
95
|
+
(0, todo_1.addTodoComment)(current.node, message, j);
|
|
96
|
+
hasTodos = true;
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
current = current.parent;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
// Bound variable / member access — value might already be in v1
|
|
104
|
+
// object shape. Leave a comment instead of wrapping.
|
|
105
|
+
if (value.type === "Identifier" ||
|
|
106
|
+
value.type === "MemberExpression" ||
|
|
107
|
+
value.type === "OptionalMemberExpression") {
|
|
108
|
+
walkToStatement(BOUND_RELATIONS_MESSAGE);
|
|
109
|
+
hasChanges = true;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Inline dynamic value (CallExpression, ConditionalExpression, etc.)
|
|
113
|
+
// — wrap with `Object.fromEntries(...)`. Attach the dot-path comment
|
|
114
|
+
// because nesting can't be detected statically.
|
|
115
|
+
propPath.node.value = wrapDynamicStringArray(j, value);
|
|
53
116
|
hasChanges = true;
|
|
117
|
+
walkToStatement(DYNAMIC_RELATIONS_DOT_PATH_NOTE);
|
|
54
118
|
});
|
|
119
|
+
if (hasTodos)
|
|
120
|
+
stats_1.stats.count.todo(api, exports.name, file);
|
|
55
121
|
return hasChanges ? root.toSource() : undefined;
|
|
56
122
|
};
|
|
57
123
|
exports.findOptionsStringRelations = findOptionsStringRelations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-options-string-relations.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-string-relations.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"find-options-string-relations.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-string-relations.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAQ5B,gDAIuB;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,GAAG,qDAAqD,CAAA;AACnE,QAAA,MAAM,GAAG,IAAI,CAAA;AAM1B,uEAAuE;AACvE,uEAAuE;AACvE,uEAAuE;AACvE,0EAA0E;AAC1E,oEAAoE;AACpE,6CAA6C;AAC7C,MAAM,+BAA+B,GACjC,oOAAoO,CAAA;AAExO,yEAAyE;AACzE,qEAAqE;AACrE,2EAA2E;AAC3E,MAAM,uBAAuB,GACzB,0TAA0T,CAAA;AA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5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fn = exports.findOptionsStringSelect = exports.description = exports.name = void 0;
|
|
6
|
+
exports.fn = exports.findOptionsStringSelect = exports.manual = 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
|
+
const todo_1 = require("../todo");
|
|
10
|
+
const stats_1 = require("../stats");
|
|
9
11
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
10
12
|
exports.description = "replace string-array `select` with object syntax";
|
|
13
|
+
exports.manual = true;
|
|
14
|
+
// Bound variables / member-access values may already hold v1 object form
|
|
15
|
+
// (`{ id: true }`) instead of `string[]` — wrapping them with
|
|
16
|
+
// `Object.fromEntries(...)` would crash at runtime. Leave a comment so the
|
|
17
|
+
// user can convert manually based on the actual runtime type.
|
|
18
|
+
const BOUND_SELECT_MESSAGE = "`select` no longer accepts a string array. This value references a variable whose shape can't be determined statically — if it holds `string[]`, wrap it: `Object.fromEntries(<expr>?.map(f => [f, true]) ?? [])`. If it already holds the v1 object shape `{ field: true }`, no change needed.";
|
|
19
|
+
// Builds `Object.fromEntries(<expr>?.map(f => [f, true]) ?? [])` — wraps
|
|
20
|
+
// a `string[]`-returning expression into the v1 `{ [field]: true }` object
|
|
21
|
+
// at runtime. The optional-chain + nullish fallback preserves v0 semantics
|
|
22
|
+
// for patterns like `select: flag ? ["id"] : undefined`, where the original
|
|
23
|
+
// code would simply skip `select` and the post-migration code must do the
|
|
24
|
+
// same (empty object = no explicit selection = all columns).
|
|
25
|
+
const wrapDynamicStringArray = (j, expr) => {
|
|
26
|
+
const optionalMapCall = j.callExpression(j.optionalMemberExpression(expr, j.identifier("map")), [
|
|
27
|
+
j.arrowFunctionExpression([j.identifier("f")], j.arrayExpression([j.identifier("f"), j.literal(true)])),
|
|
28
|
+
]);
|
|
29
|
+
return j.callExpression(j.memberExpression(j.identifier("Object"), j.identifier("fromEntries")), [j.logicalExpression("??", optionalMapCall, j.arrayExpression([]))]);
|
|
30
|
+
};
|
|
31
|
+
// Walks up to the enclosing Statement / VariableDeclaration and attaches
|
|
32
|
+
// the bound-variable comment there (recast drops comments placed on
|
|
33
|
+
// inner expressions). Returns true when a new comment was added.
|
|
34
|
+
const attachBoundTodo = (propPath, j) => {
|
|
35
|
+
let current = propPath.parent;
|
|
36
|
+
while (current) {
|
|
37
|
+
const t = current.node.type;
|
|
38
|
+
if (t.endsWith("Statement") || t === "VariableDeclaration") {
|
|
39
|
+
if ((0, todo_1.hasTodoComment)(current.node, BOUND_SELECT_MESSAGE))
|
|
40
|
+
return false;
|
|
41
|
+
(0, todo_1.addTodoComment)(current.node, BOUND_SELECT_MESSAGE, j);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
current = current.parent;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
11
48
|
const findOptionsStringSelect = (file, api) => {
|
|
12
49
|
const j = api.jscodeshift;
|
|
13
50
|
const root = j(file.source);
|
|
14
51
|
let hasChanges = false;
|
|
15
|
-
|
|
52
|
+
let hasTodos = false;
|
|
16
53
|
root.find(j.ObjectProperty, {
|
|
17
54
|
key: { name: "select" },
|
|
18
|
-
}).forEach((
|
|
19
|
-
|
|
20
|
-
|
|
55
|
+
}).forEach((propPath) => {
|
|
56
|
+
// Gate on call-site shape, not file-level typeorm import, so we still
|
|
57
|
+
// fire in NestJS-style service files that only pull TypeORM types via
|
|
58
|
+
// a wrapper module.
|
|
59
|
+
if (!(0, ast_helpers_1.isFindMethodCallArgument)(propPath))
|
|
60
|
+
return;
|
|
61
|
+
const value = propPath.node.value;
|
|
62
|
+
if (value.type === "ArrayExpression") {
|
|
63
|
+
const strings = value.elements.map((el) => el && (0, ast_helpers_1.getStringValue)(el));
|
|
64
|
+
if (strings.some((s) => s === null || s === undefined))
|
|
65
|
+
return;
|
|
66
|
+
propPath.node.value = j.objectExpression(strings.map((s) => j.property("init", j.identifier(s), j.literal(true))));
|
|
67
|
+
hasChanges = true;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Already in v1 object form — nothing to do.
|
|
71
|
+
if (value.type === "ObjectExpression")
|
|
72
|
+
return;
|
|
73
|
+
// Already wrapped by a previous pass — don't double-wrap.
|
|
74
|
+
if ((0, ast_helpers_1.isObjectFromEntriesCall)(value))
|
|
21
75
|
return;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
76
|
+
// Bound variable / member access — the value might already be in v1
|
|
77
|
+
// object shape (a partially-migrated codebase), so wrapping would
|
|
78
|
+
// crash at runtime. Leave a comment instead.
|
|
79
|
+
if (value.type === "Identifier" ||
|
|
80
|
+
value.type === "MemberExpression" ||
|
|
81
|
+
value.type === "OptionalMemberExpression") {
|
|
82
|
+
if (attachBoundTodo(propPath, j))
|
|
83
|
+
hasTodos = true;
|
|
84
|
+
hasChanges = true;
|
|
25
85
|
return;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
86
|
+
}
|
|
87
|
+
// Inline dynamic value (CallExpression, ConditionalExpression, etc.)
|
|
88
|
+
// — wrap unconditionally; v0 only accepted `string[]` so the runtime
|
|
89
|
+
// shape is known to be the array form.
|
|
90
|
+
propPath.node.value = wrapDynamicStringArray(j, value);
|
|
29
91
|
hasChanges = true;
|
|
30
92
|
});
|
|
93
|
+
if (hasTodos)
|
|
94
|
+
stats_1.stats.count.todo(api, exports.name, file);
|
|
31
95
|
return hasChanges ? root.toSource() : undefined;
|
|
32
96
|
};
|
|
33
97
|
exports.findOptionsStringSelect = findOptionsStringSelect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-options-string-select.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-string-select.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"find-options-string-select.js","sourceRoot":"","sources":["../../../src/transforms/v1/find-options-string-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EF,IAAI,QAAQ;QAAE,aAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,YAAI,EAAE,IAAI,CAAC,CAAA;IAE/C,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC,CAAA;AA7DY,QAAA,uBAAuB,2BA6DnC;AAEY,QAAA,EAAE,GAAG,+BAAuB,CAAA;AACzC,kBAAe,UAAE,CAAA"}
|
|
@@ -11,83 +11,169 @@ const stats_1 = require("../stats");
|
|
|
11
11
|
exports.name = node_path_1.default.basename(__filename, node_path_1.default.extname(__filename));
|
|
12
12
|
exports.description = "flag deprecated global functions for manual migration to `DataSource` methods";
|
|
13
13
|
exports.manual = true;
|
|
14
|
+
const removedGlobals = new Set([
|
|
15
|
+
"createConnection",
|
|
16
|
+
"createConnections",
|
|
17
|
+
"getConnection",
|
|
18
|
+
"getConnectionManager",
|
|
19
|
+
"getConnectionOptions",
|
|
20
|
+
"getManager",
|
|
21
|
+
"getSqljsManager",
|
|
22
|
+
"getRepository",
|
|
23
|
+
"getTreeRepository",
|
|
24
|
+
"createQueryBuilder",
|
|
25
|
+
"getMongoManager",
|
|
26
|
+
"getMongoRepository",
|
|
27
|
+
]);
|
|
28
|
+
// Removed globals that have NO automatic rewrite — each call site gets a
|
|
29
|
+
// comment explaining the manual migration path. Without this, the import
|
|
30
|
+
// is stripped but the call remains, producing a ReferenceError at runtime
|
|
31
|
+
// with no trace in the codemod output.
|
|
32
|
+
const manualRemovedGlobals = {
|
|
33
|
+
createConnection: "`createConnection()` was removed — instantiate a `DataSource` and call `.initialize()` instead: `const dataSource = new DataSource(options); await dataSource.initialize()`",
|
|
34
|
+
createConnections: "`createConnections()` was removed — instantiate one `DataSource` per configuration and call `.initialize()` on each; multi-connection setups must be managed explicitly",
|
|
35
|
+
getConnectionManager: "`getConnectionManager()` was removed — the global `ConnectionManager` singleton no longer exists; hold and share `DataSource` instances directly",
|
|
36
|
+
getConnectionOptions: "`getConnectionOptions()` was removed — load your ormconfig manually and pass the object into `new DataSource(options)`",
|
|
37
|
+
getSqljsManager: "`getSqljsManager()` was removed — access the sql.js-specific API via `(dataSource.driver as SqljsDriver)` on your initialized DataSource",
|
|
38
|
+
};
|
|
39
|
+
// Simple replacements: `getX()` rewrites to either a property access
|
|
40
|
+
// (`getManager()` → `dataSource.manager`) or a method call
|
|
41
|
+
// (`getRepository(User)` → `dataSource.getRepository(User)`); see
|
|
42
|
+
// `rewriteSimpleCall` for the heuristic that picks the right shape.
|
|
43
|
+
const simpleReplacements = {
|
|
44
|
+
getManager: "dataSource.manager",
|
|
45
|
+
getRepository: "dataSource.getRepository",
|
|
46
|
+
getTreeRepository: "dataSource.getTreeRepository",
|
|
47
|
+
createQueryBuilder: "dataSource.createQueryBuilder",
|
|
48
|
+
getMongoManager: "dataSource.mongoManager",
|
|
49
|
+
getMongoRepository: "dataSource.getMongoRepository",
|
|
50
|
+
};
|
|
51
|
+
const todoHostTypes = new Set([
|
|
52
|
+
"ExpressionStatement",
|
|
53
|
+
"VariableDeclaration",
|
|
54
|
+
"ReturnStatement",
|
|
55
|
+
// Class field initializer — `conn = createConnection()` inside a class
|
|
56
|
+
// body has no enclosing Statement/VariableDeclaration, so the walk
|
|
57
|
+
// must recognise the property itself as a host.
|
|
58
|
+
"ClassProperty",
|
|
59
|
+
"PropertyDefinition",
|
|
60
|
+
]);
|
|
61
|
+
const rewriteSimpleCall = (j, astPath, replacement) => {
|
|
62
|
+
const parts = replacement.split(".");
|
|
63
|
+
if (parts.length !== 2 || replacement.includes("("))
|
|
64
|
+
return false;
|
|
65
|
+
const [obj, member] = parts;
|
|
66
|
+
const memberExpr = j.memberExpression(j.identifier(obj), j.identifier(member));
|
|
67
|
+
const shouldUsePropertyAccess = astPath.node.arguments.length === 0 && !replacement.includes("get");
|
|
68
|
+
j(astPath).replaceWith(shouldUsePropertyAccess
|
|
69
|
+
? memberExpr
|
|
70
|
+
: j.callExpression(memberExpr, astPath.node.arguments));
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
const annotateFirstDataSourceUsage = (root, j, hadNamedConnection) => {
|
|
74
|
+
const [firstUsage] = root.find(j.Identifier, { name: "dataSource" }).paths();
|
|
75
|
+
if (!firstUsage)
|
|
76
|
+
return;
|
|
77
|
+
let current = firstUsage;
|
|
78
|
+
while (current.parent) {
|
|
79
|
+
const node = current.parent.node;
|
|
80
|
+
if (todoHostTypes.has(node.type)) {
|
|
81
|
+
const messages = [
|
|
82
|
+
"`dataSource` is not defined — inject or import your DataSource instance",
|
|
83
|
+
];
|
|
84
|
+
if (hadNamedConnection) {
|
|
85
|
+
messages.push('named connections were removed in v1 — if you relied on `getConnection("name")`, wire up a second DataSource and reference it here');
|
|
86
|
+
}
|
|
87
|
+
for (const message of messages)
|
|
88
|
+
(0, todo_1.addTodoComment)(node, message, j);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
current = current.parent;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
14
94
|
const globalFunctions = (file, api) => {
|
|
15
95
|
const j = api.jscodeshift;
|
|
16
96
|
const root = j(file.source);
|
|
17
97
|
let hasChanges = false;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"getConnectionOptions",
|
|
24
|
-
"getManager",
|
|
25
|
-
"getSqljsManager",
|
|
26
|
-
"getRepository",
|
|
27
|
-
"getTreeRepository",
|
|
28
|
-
"createQueryBuilder",
|
|
29
|
-
"getMongoManager",
|
|
30
|
-
"getMongoRepository",
|
|
31
|
-
]);
|
|
32
|
-
// Simple replacements: getX(args) → dataSource.x(args)
|
|
33
|
-
const simpleReplacements = {
|
|
34
|
-
getManager: "dataSource.manager",
|
|
35
|
-
getRepository: "dataSource.getRepository",
|
|
36
|
-
getTreeRepository: "dataSource.getTreeRepository",
|
|
37
|
-
createQueryBuilder: "dataSource.createQueryBuilder",
|
|
38
|
-
getMongoManager: "dataSource.mongoManager",
|
|
39
|
-
getMongoRepository: "dataSource.getMongoRepository",
|
|
40
|
-
};
|
|
41
|
-
// Replace function calls
|
|
98
|
+
// Resolve the local names (including aliases such as
|
|
99
|
+
// `import { getManager as gm } from "typeorm"`) for every function we
|
|
100
|
+
// know how to rewrite, then replace all matching call-sites in a single
|
|
101
|
+
// pass over `CallExpression` nodes.
|
|
102
|
+
const callReplacements = new Map();
|
|
42
103
|
for (const [funcName, replacement] of Object.entries(simpleReplacements)) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
104
|
+
for (const localName of (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", funcName)) {
|
|
105
|
+
callReplacements.set(localName, replacement);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const getConnectionLocals = (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", "getConnection");
|
|
109
|
+
let hasNamedConnection = false;
|
|
110
|
+
// Build lookup: local-name → manual-removal comment message, so aliased
|
|
111
|
+
// imports like `import { createConnection as cc } from "typeorm"` still
|
|
112
|
+
// get their call sites flagged.
|
|
113
|
+
const manualTodos = new Map();
|
|
114
|
+
for (const [funcName, message] of Object.entries(manualRemovedGlobals)) {
|
|
115
|
+
for (const localName of (0, ast_helpers_1.getLocalNamesForImport)(root, j, "typeorm", funcName)) {
|
|
116
|
+
manualTodos.set(localName, message);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Rewrites `getConnection()` → `dataSource`, stripping the argument.
|
|
120
|
+
// Sets `hasNamedConnection` when the call had a named-connection arg.
|
|
121
|
+
const rewriteGetConnection = (astPath) => {
|
|
122
|
+
const hadArg = astPath.node.arguments.length > 0;
|
|
123
|
+
j(astPath).replaceWith(j.identifier("dataSource"));
|
|
124
|
+
if (hadArg)
|
|
125
|
+
hasNamedConnection = true;
|
|
126
|
+
return true;
|
|
127
|
+
};
|
|
128
|
+
// Attaches a manual-migration comment to the enclosing statement of
|
|
129
|
+
// `astPath`. Returns whether anything changed.
|
|
130
|
+
const attachManualTodo = (astPath, manualMessage) => {
|
|
131
|
+
let current = astPath;
|
|
132
|
+
while (current) {
|
|
133
|
+
const node = current.node;
|
|
134
|
+
if (todoHostTypes.has(node.type)) {
|
|
135
|
+
if (!(0, todo_1.hasTodoComment)(node, manualMessage)) {
|
|
136
|
+
(0, todo_1.addTodoComment)(node, manualMessage, j);
|
|
57
137
|
}
|
|
58
|
-
|
|
138
|
+
return true;
|
|
59
139
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
140
|
+
current = current.parent;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
};
|
|
144
|
+
const handleCallSite = (astPath) => {
|
|
145
|
+
const callee = astPath.node.callee;
|
|
146
|
+
if (callee.type !== "Identifier")
|
|
147
|
+
return;
|
|
148
|
+
if (getConnectionLocals.has(callee.name)) {
|
|
149
|
+
if (rewriteGetConnection(astPath))
|
|
150
|
+
hasChanges = true;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const replacement = callReplacements.get(callee.name);
|
|
154
|
+
if (replacement && rewriteSimpleCall(j, astPath, replacement)) {
|
|
155
|
+
hasChanges = true;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const manualMessage = manualTodos.get(callee.name);
|
|
159
|
+
if (manualMessage && attachManualTodo(astPath, manualMessage)) {
|
|
68
160
|
hasChanges = true;
|
|
69
161
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
162
|
+
};
|
|
163
|
+
if (callReplacements.size > 0 ||
|
|
164
|
+
getConnectionLocals.size > 0 ||
|
|
165
|
+
manualTodos.size > 0) {
|
|
166
|
+
root.find(j.CallExpression).forEach(handleCallSite);
|
|
167
|
+
}
|
|
72
168
|
if ((0, ast_helpers_1.removeImportSpecifiers)(root, j, "typeorm", removedGlobals)) {
|
|
73
169
|
hasChanges = true;
|
|
74
170
|
}
|
|
75
|
-
//
|
|
171
|
+
// Remove re-exports of deprecated globals (barrel-file pattern)
|
|
172
|
+
if ((0, ast_helpers_1.removeReExportSpecifiers)(root, j, "typeorm", removedGlobals)) {
|
|
173
|
+
hasChanges = true;
|
|
174
|
+
}
|
|
76
175
|
if (hasChanges) {
|
|
77
|
-
|
|
78
|
-
if (firstUsage.length > 0) {
|
|
79
|
-
let current = firstUsage.paths()[0];
|
|
80
|
-
while (current.parent) {
|
|
81
|
-
const node = current.parent.node;
|
|
82
|
-
if (node.type === "ExpressionStatement" ||
|
|
83
|
-
node.type === "VariableDeclaration" ||
|
|
84
|
-
node.type === "ReturnStatement") {
|
|
85
|
-
(0, todo_1.addTodoComment)(node, "`dataSource` is not defined — inject or import your DataSource instance", j);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
current = current.parent;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
176
|
+
annotateFirstDataSourceUsage(root, j, hasNamedConnection);
|
|
91
177
|
stats_1.stats.count.todo(api, exports.name, file);
|
|
92
178
|
}
|
|
93
179
|
return hasChanges ? root.toSource() : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-functions.js","sourceRoot":"","sources":["../../../src/transforms/v1/global-functions.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;
|
|
1
|
+
{"version":3,"file":"global-functions.js","sourceRoot":"","sources":["../../../src/transforms/v1/global-functions.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA4B;AAU5B,gDAIuB;AACvB,kCAAwD;AACxD,oCAAgC;AAEnB,QAAA,IAAI,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,mBAAI,CAAC,OAAO,CAAC,UAAU,CAA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