@mikro-orm/reflection 7.0.0-dev.7 → 7.0.0-dev.70
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 +3 -2
- package/TsMorphMetadataProvider.js +35 -21
- 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,10 +1,10 @@
|
|
|
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;
|
|
6
6
|
useCache(): boolean;
|
|
7
|
-
loadEntityMetadata(meta: EntityMetadata
|
|
7
|
+
loadEntityMetadata(meta: EntityMetadata): void;
|
|
8
8
|
getExistingSourceFile(path: string, ext?: string, validate?: boolean): SourceFile;
|
|
9
9
|
protected initProperties(meta: EntityMetadata): void;
|
|
10
10
|
private extractType;
|
|
@@ -12,6 +12,7 @@ export declare class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
12
12
|
private initPropertyType;
|
|
13
13
|
private readTypeFromSource;
|
|
14
14
|
private getSourceFile;
|
|
15
|
+
private stripRelativePath;
|
|
15
16
|
private processWrapper;
|
|
16
17
|
private initProject;
|
|
17
18
|
private initSourceFiles;
|
|
@@ -1,12 +1,12 @@
|
|
|
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 { MetadataError, MetadataProvider, MetadataStorage, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
3
3
|
export class TsMorphMetadataProvider extends MetadataProvider {
|
|
4
4
|
project;
|
|
5
5
|
sources;
|
|
6
6
|
useCache() {
|
|
7
7
|
return this.config.get('metadataCache').enabled ?? true;
|
|
8
8
|
}
|
|
9
|
-
loadEntityMetadata(meta
|
|
9
|
+
loadEntityMetadata(meta) {
|
|
10
10
|
if (!meta.path) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
@@ -23,14 +23,12 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
23
23
|
// load types and column names
|
|
24
24
|
for (const prop of Object.values(meta.properties)) {
|
|
25
25
|
const type = this.extractType(prop);
|
|
26
|
-
|
|
27
|
-
this.initPropertyType(meta, prop);
|
|
28
|
-
}
|
|
26
|
+
this.initPropertyType(meta, prop);
|
|
29
27
|
prop.type = type || prop.type;
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
extractType(prop) {
|
|
33
|
-
if (
|
|
31
|
+
if (typeof prop.entity === 'string') {
|
|
34
32
|
return prop.entity;
|
|
35
33
|
}
|
|
36
34
|
if (prop.entity) {
|
|
@@ -39,12 +37,11 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
39
37
|
return prop.type;
|
|
40
38
|
}
|
|
41
39
|
cleanUpTypeTags(type) {
|
|
42
|
-
const genericTags = [/Opt<(.*?)>/, /Hidden<(.*?)>/];
|
|
40
|
+
const genericTags = [/Opt<(.*?)>/, /Hidden<(.*?)>/, /RequiredNullable<(.*?)>/];
|
|
43
41
|
const intersectionTags = [
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'{ [__hidden]?: 1; }',
|
|
42
|
+
'Opt.Brand',
|
|
43
|
+
'Hidden.Brand',
|
|
44
|
+
'RequiredNullable.Brand',
|
|
48
45
|
];
|
|
49
46
|
for (const tag of genericTags) {
|
|
50
47
|
type = type.replace(tag, '$1');
|
|
@@ -57,17 +54,17 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
57
54
|
}
|
|
58
55
|
initPropertyType(meta, prop) {
|
|
59
56
|
const { type: typeRaw, optional } = this.readTypeFromSource(meta, prop);
|
|
60
|
-
|
|
61
|
-
prop.type = type;
|
|
62
|
-
prop.runtimeType = type;
|
|
57
|
+
prop.type = this.cleanUpTypeTags(typeRaw);
|
|
63
58
|
if (optional) {
|
|
64
59
|
prop.optional = true;
|
|
65
60
|
}
|
|
66
61
|
this.processWrapper(prop, 'Ref');
|
|
67
62
|
this.processWrapper(prop, 'Reference');
|
|
63
|
+
this.processWrapper(prop, 'EntityRef');
|
|
64
|
+
this.processWrapper(prop, 'ScalarRef');
|
|
68
65
|
this.processWrapper(prop, 'ScalarReference');
|
|
69
|
-
this.processWrapper(prop, 'Ref');
|
|
70
66
|
this.processWrapper(prop, 'Collection');
|
|
67
|
+
prop.runtimeType ??= prop.type;
|
|
71
68
|
if (prop.type.replace(/import\(.*\)\./g, '').match(/^(Dictionary|Record)<.*>$/)) {
|
|
72
69
|
prop.type = 'json';
|
|
73
70
|
}
|
|
@@ -80,7 +77,22 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
80
77
|
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
78
|
}
|
|
82
79
|
const properties = cls.getInstanceProperties();
|
|
83
|
-
const property = properties.find(v =>
|
|
80
|
+
const property = properties.find(v => {
|
|
81
|
+
if (v.getName() === prop.name) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const nameNode = v.getNameNode();
|
|
85
|
+
if (nameNode instanceof StringLiteral && nameNode.getLiteralText() === prop.name) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (nameNode instanceof ComputedPropertyName) {
|
|
89
|
+
const expr = nameNode.getExpression();
|
|
90
|
+
if (expr instanceof NoSubstitutionTemplateLiteral && expr.getLiteralText() === prop.name) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
84
96
|
if (!property) {
|
|
85
97
|
return { type: prop.type, optional: prop.nullable };
|
|
86
98
|
}
|
|
@@ -125,13 +137,16 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
125
137
|
const outDirRelative = Utils.relativePath(outDir, baseDir);
|
|
126
138
|
path = path.replace(new RegExp(`^${outDirRelative}`), '');
|
|
127
139
|
}
|
|
128
|
-
path =
|
|
140
|
+
path = this.stripRelativePath(path);
|
|
129
141
|
const source = this.sources.find(s => s.getFilePath().endsWith(path));
|
|
130
142
|
if (!source && validate) {
|
|
131
143
|
throw new MetadataError(`Source file '${tsPath}' not found. Check your 'entitiesTs' option and verify you have 'compilerOptions.declaration' enabled in your 'tsconfig.json'. If you are using webpack, see https://bit.ly/35pPDNn`);
|
|
132
144
|
}
|
|
133
145
|
return source;
|
|
134
146
|
}
|
|
147
|
+
stripRelativePath(str) {
|
|
148
|
+
return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
|
|
149
|
+
}
|
|
135
150
|
processWrapper(prop, wrapper) {
|
|
136
151
|
// type can be sometimes in form of:
|
|
137
152
|
// `'({ object?: Entity | undefined; } & import("...").Reference<Entity>)'`
|
|
@@ -146,14 +161,13 @@ export class TsMorphMetadataProvider extends MetadataProvider {
|
|
|
146
161
|
return;
|
|
147
162
|
}
|
|
148
163
|
prop.type = m[1];
|
|
149
|
-
if (['Ref', 'Reference', '
|
|
164
|
+
if (['Ref', 'Reference', 'EntityRef', 'ScalarRef', 'ScalarReference'].includes(wrapper)) {
|
|
150
165
|
prop.ref = true;
|
|
151
166
|
}
|
|
152
167
|
}
|
|
153
168
|
initProject() {
|
|
154
|
-
const settings = ConfigurationLoader.getSettings();
|
|
155
169
|
/* v8 ignore next */
|
|
156
|
-
const tsConfigFilePath = this.config.get('discovery').tsConfigPath ??
|
|
170
|
+
const tsConfigFilePath = this.config.get('discovery').tsConfigPath ?? './tsconfig.json';
|
|
157
171
|
try {
|
|
158
172
|
this.project = new Project({
|
|
159
173
|
tsConfigFilePath: Utils.normalizePath(process.cwd(), tsConfigFilePath),
|
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.70",
|
|
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.70"
|
|
61
60
|
}
|
|
62
61
|
}
|