@mikro-orm/reflection 7.0.0-dev.6 → 7.0.0-dev.61
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 +3 -2
- package/TsMorphMetadataProvider.d.ts +1 -1
- package/TsMorphMetadataProvider.js +27 -13
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
12
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
|
-
[](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
|
|
15
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
16
15
|
|
|
17
16
|
## 🤔 Unit of What?
|
|
@@ -141,7 +140,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
141
140
|
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
142
141
|
- [Filters](https://mikro-orm.io/docs/filters)
|
|
143
142
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
|
-
- [
|
|
143
|
+
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
145
144
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
145
|
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
146
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
@@ -382,6 +381,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
382
381
|
|
|
383
382
|
Please ⭐️ this repository if this project helped you!
|
|
384
383
|
|
|
384
|
+
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
385
|
+
|
|
385
386
|
## 📝 License
|
|
386
387
|
|
|
387
388
|
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SourceFile } from 'ts-morph';
|
|
2
|
-
import {
|
|
2
|
+
import { type EntityMetadata, MetadataProvider } from '@mikro-orm/core';
|
|
3
3
|
export declare class TsMorphMetadataProvider extends MetadataProvider {
|
|
4
4
|
private project;
|
|
5
5
|
private sources;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ModuleKind, Project } from 'ts-morph';
|
|
2
|
-
import { MetadataError, MetadataProvider, MetadataStorage, ReferenceKind, Utils,
|
|
1
|
+
import { ComputedPropertyName, ModuleKind, NoSubstitutionTemplateLiteral, Project, StringLiteral } from 'ts-morph';
|
|
2
|
+
import { ConfigurationLoader, MetadataError, MetadataProvider, MetadataStorage, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
3
3
|
export class TsMorphMetadataProvider extends MetadataProvider {
|
|
4
4
|
project;
|
|
5
5
|
sources;
|
|
@@ -39,12 +39,11 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
39
39
|
return prop.type;
|
|
40
40
|
}
|
|
41
41
|
cleanUpTypeTags(type) {
|
|
42
|
-
const genericTags = [/Opt<(.*?)>/, /Hidden<(.*?)>/];
|
|
42
|
+
const genericTags = [/Opt<(.*?)>/, /Hidden<(.*?)>/, /RequiredNullable<(.*?)>/];
|
|
43
43
|
const intersectionTags = [
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'{ [__hidden]?: 1; }',
|
|
44
|
+
'Opt.Brand',
|
|
45
|
+
'Hidden.Brand',
|
|
46
|
+
'RequiredNullable.Brand',
|
|
48
47
|
];
|
|
49
48
|
for (const tag of genericTags) {
|
|
50
49
|
type = type.replace(tag, '$1');
|
|
@@ -57,17 +56,17 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
57
56
|
}
|
|
58
57
|
initPropertyType(meta, prop) {
|
|
59
58
|
const { type: typeRaw, optional } = this.readTypeFromSource(meta, prop);
|
|
60
|
-
|
|
61
|
-
prop.type = type;
|
|
62
|
-
prop.runtimeType = type;
|
|
59
|
+
prop.type = this.cleanUpTypeTags(typeRaw);
|
|
63
60
|
if (optional) {
|
|
64
61
|
prop.optional = true;
|
|
65
62
|
}
|
|
66
63
|
this.processWrapper(prop, 'Ref');
|
|
67
64
|
this.processWrapper(prop, 'Reference');
|
|
65
|
+
this.processWrapper(prop, 'EntityRef');
|
|
66
|
+
this.processWrapper(prop, 'ScalarRef');
|
|
68
67
|
this.processWrapper(prop, 'ScalarReference');
|
|
69
|
-
this.processWrapper(prop, 'Ref');
|
|
70
68
|
this.processWrapper(prop, 'Collection');
|
|
69
|
+
prop.runtimeType ??= prop.type;
|
|
71
70
|
if (prop.type.replace(/import\(.*\)\./g, '').match(/^(Dictionary|Record)<.*>$/)) {
|
|
72
71
|
prop.type = 'json';
|
|
73
72
|
}
|
|
@@ -80,7 +79,22 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
80
79
|
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`);
|
|
81
80
|
}
|
|
82
81
|
const properties = cls.getInstanceProperties();
|
|
83
|
-
const property = properties.find(v =>
|
|
82
|
+
const property = properties.find(v => {
|
|
83
|
+
if (v.getName() === prop.name) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
const nameNode = v.getNameNode();
|
|
87
|
+
if (nameNode instanceof StringLiteral && nameNode.getLiteralText() === prop.name) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (nameNode instanceof ComputedPropertyName) {
|
|
91
|
+
const expr = nameNode.getExpression();
|
|
92
|
+
if (expr instanceof NoSubstitutionTemplateLiteral && expr.getLiteralText() === prop.name) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
});
|
|
84
98
|
if (!property) {
|
|
85
99
|
return { type: prop.type, optional: prop.nullable };
|
|
86
100
|
}
|
|
@@ -146,7 +160,7 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
146
160
|
return;
|
|
147
161
|
}
|
|
148
162
|
prop.type = m[1];
|
|
149
|
-
if (['Ref', 'Reference', '
|
|
163
|
+
if (['Ref', 'Reference', 'EntityRef', 'ScalarRef', 'ScalarReference'].includes(wrapper)) {
|
|
150
164
|
prop.ref = true;
|
|
151
165
|
}
|
|
152
166
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/reflection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.61",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mikro-orm.io",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">= 22.
|
|
41
|
+
"node": ">= 22.17.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "yarn clean && yarn compile && yarn copy",
|
|
@@ -50,13 +50,12 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"
|
|
54
|
-
"ts-morph": "25.0.1"
|
|
53
|
+
"ts-morph": "27.0.2"
|
|
55
54
|
},
|
|
56
55
|
"devDependencies": {
|
|
57
|
-
"@mikro-orm/core": "^6.
|
|
56
|
+
"@mikro-orm/core": "^6.6.1"
|
|
58
57
|
},
|
|
59
58
|
"peerDependencies": {
|
|
60
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-dev.61"
|
|
61
60
|
}
|
|
62
61
|
}
|