@mikro-orm/reflection 7.0.0-dev.1 → 7.0.0-dev.11
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 +23 -26
- package/index.d.ts +1 -1
- package/index.js +1 -17
- package/package.json +6 -14
- package/index.mjs +0 -4
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ts_morph_1 = require("ts-morph");
|
|
5
|
-
const core_1 = require("@mikro-orm/core");
|
|
6
|
-
class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
1
|
+
import { ModuleKind, Project } from 'ts-morph';
|
|
2
|
+
import { MetadataError, MetadataProvider, MetadataStorage, ReferenceKind, Utils, ConfigurationLoader, } from '@mikro-orm/core';
|
|
3
|
+
export class TsMorphMetadataProvider extends MetadataProvider {
|
|
7
4
|
project;
|
|
8
5
|
sources;
|
|
9
6
|
useCache() {
|
|
@@ -33,11 +30,11 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
32
|
extractType(prop) {
|
|
36
|
-
if (
|
|
33
|
+
if (Utils.isString(prop.entity)) {
|
|
37
34
|
return prop.entity;
|
|
38
35
|
}
|
|
39
36
|
if (prop.entity) {
|
|
40
|
-
return
|
|
37
|
+
return Utils.className(prop.entity());
|
|
41
38
|
}
|
|
42
39
|
return prop.type;
|
|
43
40
|
}
|
|
@@ -78,9 +75,9 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
78
75
|
readTypeFromSource(meta, prop) {
|
|
79
76
|
const source = this.getExistingSourceFile(meta.path);
|
|
80
77
|
const cls = source.getClass(meta.className);
|
|
81
|
-
/*
|
|
78
|
+
/* v8 ignore next 3 */
|
|
82
79
|
if (!cls) {
|
|
83
|
-
throw new
|
|
80
|
+
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`);
|
|
84
81
|
}
|
|
85
82
|
const properties = cls.getInstanceProperties();
|
|
86
83
|
const property = properties.find(v => v.getName() === prop.name);
|
|
@@ -94,7 +91,7 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
94
91
|
}
|
|
95
92
|
if (tsType.isArray()) {
|
|
96
93
|
prop.array = true;
|
|
97
|
-
/*
|
|
94
|
+
/* v8 ignore next 3 */
|
|
98
95
|
if (tsType.getArrayElementType().isEnum()) {
|
|
99
96
|
prop.items = tsType.getArrayElementType().getUnionTypes().map(t => t.getLiteralValueOrThrow());
|
|
100
97
|
}
|
|
@@ -112,7 +109,7 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
112
109
|
.replace(/\[]$/, '') // remove array suffix
|
|
113
110
|
.replace(/\((.*)\)/, '$1'); // unwrap union types
|
|
114
111
|
// keep the array suffix in the type, it is needed in few places in discovery and comparator (`prop.array` is used only for enum arrays)
|
|
115
|
-
if (prop.array && !type.includes(' | ') && prop.kind ===
|
|
112
|
+
if (prop.array && !type.includes(' | ') && prop.kind === ReferenceKind.SCALAR) {
|
|
116
113
|
type += '[]';
|
|
117
114
|
}
|
|
118
115
|
return { type, optional };
|
|
@@ -125,13 +122,13 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
125
122
|
const outDir = this.project.getCompilerOptions().outDir;
|
|
126
123
|
let path = tsPath;
|
|
127
124
|
if (outDir != null) {
|
|
128
|
-
const outDirRelative =
|
|
125
|
+
const outDirRelative = Utils.relativePath(outDir, baseDir);
|
|
129
126
|
path = path.replace(new RegExp(`^${outDirRelative}`), '');
|
|
130
127
|
}
|
|
131
|
-
path =
|
|
128
|
+
path = Utils.stripRelativePath(path);
|
|
132
129
|
const source = this.sources.find(s => s.getFilePath().endsWith(path));
|
|
133
130
|
if (!source && validate) {
|
|
134
|
-
throw new
|
|
131
|
+
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`);
|
|
135
132
|
}
|
|
136
133
|
return source;
|
|
137
134
|
}
|
|
@@ -154,24 +151,25 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
153
|
initProject() {
|
|
157
|
-
const settings =
|
|
158
|
-
/*
|
|
154
|
+
const settings = ConfigurationLoader.getSettings();
|
|
155
|
+
/* v8 ignore next */
|
|
159
156
|
const tsConfigFilePath = this.config.get('discovery').tsConfigPath ?? settings.tsConfigPath ?? './tsconfig.json';
|
|
160
157
|
try {
|
|
161
|
-
this.project = new
|
|
162
|
-
tsConfigFilePath:
|
|
158
|
+
this.project = new Project({
|
|
159
|
+
tsConfigFilePath: Utils.normalizePath(process.cwd(), tsConfigFilePath),
|
|
160
|
+
skipAddingFilesFromTsConfig: true,
|
|
163
161
|
compilerOptions: {
|
|
164
162
|
strictNullChecks: true,
|
|
165
|
-
module:
|
|
163
|
+
module: ModuleKind.Node16,
|
|
166
164
|
},
|
|
167
165
|
});
|
|
168
166
|
}
|
|
169
167
|
catch (e) {
|
|
170
168
|
this.config.getLogger().warn('discovery', e.message);
|
|
171
|
-
this.project = new
|
|
169
|
+
this.project = new Project({
|
|
172
170
|
compilerOptions: {
|
|
173
171
|
strictNullChecks: true,
|
|
174
|
-
module:
|
|
172
|
+
module: ModuleKind.Node16,
|
|
175
173
|
},
|
|
176
174
|
});
|
|
177
175
|
}
|
|
@@ -182,11 +180,11 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
182
180
|
}
|
|
183
181
|
this.sources = [];
|
|
184
182
|
// All entity files are first required during the discovery, before we reach here, so it is safe to get the parts from the global
|
|
185
|
-
// metadata storage. We know the path thanks to the decorators being executed. In case we are running
|
|
183
|
+
// metadata storage. We know the path thanks to the decorators being executed. In case we are running the TS code, the extension
|
|
186
184
|
// will be already `.ts`, so no change is needed. `.js` files will get renamed to `.d.ts` files as they will be used as a source for
|
|
187
185
|
// the ts-morph reflection.
|
|
188
|
-
for (const meta of
|
|
189
|
-
/*
|
|
186
|
+
for (const meta of Utils.values(MetadataStorage.getMetadata())) {
|
|
187
|
+
/* v8 ignore next 3 */
|
|
190
188
|
const path = meta.path.match(/\.[jt]s$/)
|
|
191
189
|
? meta.path.replace(/\.js$/, '.d.ts')
|
|
192
190
|
: `${meta.path}.d.ts`; // when entities are bundled, their paths are just their names
|
|
@@ -197,4 +195,3 @@ class TsMorphMetadataProvider extends core_1.MetadataProvider {
|
|
|
197
195
|
}
|
|
198
196
|
}
|
|
199
197
|
}
|
|
200
|
-
exports.TsMorphMetadataProvider = TsMorphMetadataProvider;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
1
|
/**
|
|
18
2
|
* @packageDocumentation
|
|
19
3
|
* @module reflection
|
|
20
4
|
*/
|
|
21
|
-
|
|
5
|
+
export * from './TsMorphMetadataProvider.js';
|
package/package.json
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/reflection",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.0.0-dev.11",
|
|
4
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.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"module": "index.mjs",
|
|
7
|
-
"typings": "index.d.ts",
|
|
8
6
|
"exports": {
|
|
9
7
|
"./package.json": "./package.json",
|
|
10
|
-
".":
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./index.d.ts",
|
|
13
|
-
"default": "./index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"require": "./index.js"
|
|
16
|
-
}
|
|
8
|
+
".": "./index.js"
|
|
17
9
|
},
|
|
18
10
|
"repository": {
|
|
19
11
|
"type": "git",
|
|
@@ -49,7 +41,7 @@
|
|
|
49
41
|
"node": ">= 22.11.0"
|
|
50
42
|
},
|
|
51
43
|
"scripts": {
|
|
52
|
-
"build": "yarn clean && yarn compile && yarn copy
|
|
44
|
+
"build": "yarn clean && yarn compile && yarn copy",
|
|
53
45
|
"clean": "yarn run -T rimraf ./dist",
|
|
54
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
55
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -62,9 +54,9 @@
|
|
|
62
54
|
"ts-morph": "25.0.1"
|
|
63
55
|
},
|
|
64
56
|
"devDependencies": {
|
|
65
|
-
"@mikro-orm/core": "^6.4.
|
|
57
|
+
"@mikro-orm/core": "^6.4.13"
|
|
66
58
|
},
|
|
67
59
|
"peerDependencies": {
|
|
68
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
60
|
+
"@mikro-orm/core": "7.0.0-dev.11"
|
|
69
61
|
}
|
|
70
62
|
}
|
package/index.mjs
DELETED