@mikro-orm/reflection 7.0.6-dev.1 → 7.0.6-dev.3
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/TsMorphMetadataProvider.js +7 -19
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { extname } from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { ModuleKind, Project } from 'ts-morph';
|
|
3
3
|
import { EntitySchema, MetadataError, MetadataProvider, MetadataStorage, RawQueryFragment, ReferenceKind, Type, Utils, } from '@mikro-orm/core';
|
|
4
4
|
import { fs } from '@mikro-orm/core/fs-utils';
|
|
5
5
|
/** Metadata provider that uses ts-morph to infer property types from TypeScript source files or declaration files. */
|
|
@@ -61,7 +61,9 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
61
61
|
}
|
|
62
62
|
initPropertyType(meta, prop) {
|
|
63
63
|
const { type: typeRaw, optional } = this.readTypeFromSource(meta, prop);
|
|
64
|
-
|
|
64
|
+
if (typeRaw != null) {
|
|
65
|
+
prop.type = this.cleanUpTypeTags(typeRaw);
|
|
66
|
+
}
|
|
65
67
|
if (optional) {
|
|
66
68
|
prop.optional = true;
|
|
67
69
|
}
|
|
@@ -83,23 +85,9 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
83
85
|
if (!cls) {
|
|
84
86
|
throw new MetadataError(`Source class for entity ${meta.className} not found. Verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
|
|
85
87
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
const nameNode = v.getNameNode();
|
|
92
|
-
if (nameNode instanceof StringLiteral && nameNode.getLiteralText() === prop.name) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (nameNode instanceof ComputedPropertyName) {
|
|
96
|
-
const expr = nameNode.getExpression();
|
|
97
|
-
if (expr instanceof NoSubstitutionTemplateLiteral && expr.getLiteralText() === prop.name) {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
});
|
|
88
|
+
const property = (cls.getInstanceProperty(prop.name) ??
|
|
89
|
+
// fallback to the type checker for inherited properties (e.g. with TC39/ES decorators)
|
|
90
|
+
cls.getType().getProperty(prop.name)?.getDeclarations()?.[0]);
|
|
103
91
|
if (!property) {
|
|
104
92
|
return { type: prop.type, optional: prop.nullable };
|
|
105
93
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/reflection",
|
|
3
|
-
"version": "7.0.6-dev.
|
|
3
|
+
"version": "7.0.6-dev.3",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.0.5"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.0.6-dev.
|
|
56
|
+
"@mikro-orm/core": "7.0.6-dev.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|