@mikro-orm/core 7.0.0-dev.45 → 7.0.0-dev.47
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/MikroORM.d.ts +0 -1
- package/MikroORM.js +14 -16
- package/metadata/MetadataDiscovery.js +1 -4
- package/package.json +2 -2
- package/utils/ConfigurationLoader.d.ts +0 -1
- package/utils/ConfigurationLoader.js +4 -6
package/MikroORM.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
27
27
|
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
|
28
28
|
* - no loading of the `config` file, `options` parameter is mandatory
|
|
29
29
|
* - no support for folder based discovery
|
|
30
|
-
* - no check for mismatched package versions
|
|
31
30
|
*/
|
|
32
31
|
constructor(options: Options<Driver, EM>);
|
|
33
32
|
/**
|
package/MikroORM.js
CHANGED
|
@@ -27,17 +27,10 @@ export class MikroORM {
|
|
|
27
27
|
if (!options) {
|
|
28
28
|
throw new Error(`options parameter is required`);
|
|
29
29
|
}
|
|
30
|
-
const coreVersion = ConfigurationLoader.checkPackageVersion();
|
|
31
30
|
options.discovery ??= {};
|
|
32
31
|
options.discovery.skipSyncDiscovery ??= true;
|
|
33
32
|
const orm = new this(options);
|
|
34
|
-
orm.logger.log('info', `MikroORM version: ${colors.green(coreVersion)}`);
|
|
35
|
-
// we need to allow global context here as we are not in a scope of requests yet
|
|
36
|
-
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
37
|
-
orm.config.set('allowGlobalContext', true);
|
|
38
33
|
await orm.discoverEntities();
|
|
39
|
-
orm.config.set('allowGlobalContext', allowGlobalContext);
|
|
40
|
-
orm.driver.getPlatform().init(orm);
|
|
41
34
|
return orm;
|
|
42
35
|
}
|
|
43
36
|
/**
|
|
@@ -45,11 +38,11 @@ export class MikroORM {
|
|
|
45
38
|
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
|
46
39
|
* - no loading of the `config` file, `options` parameter is mandatory
|
|
47
40
|
* - no support for folder based discovery
|
|
48
|
-
* - no check for mismatched package versions
|
|
49
41
|
*/
|
|
50
42
|
constructor(options) {
|
|
51
43
|
ConfigurationLoader.registerDotenv(options);
|
|
52
44
|
const env = ConfigurationLoader.loadEnvironmentVarsSync();
|
|
45
|
+
const coreVersion = ConfigurationLoader.checkPackageVersion();
|
|
53
46
|
options = Utils.merge(options, env);
|
|
54
47
|
this.config = new Configuration(options);
|
|
55
48
|
const discovery = this.config.get('discovery');
|
|
@@ -60,18 +53,15 @@ export class MikroORM {
|
|
|
60
53
|
}
|
|
61
54
|
this.driver = this.config.getDriver();
|
|
62
55
|
this.logger = this.config.getLogger();
|
|
56
|
+
this.logger.log('info', `MikroORM version: ${colors.green(coreVersion)}`);
|
|
63
57
|
this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
|
|
64
|
-
|
|
65
|
-
// we need to allow global context here as we are not in a scope of requests yet
|
|
66
|
-
const allowGlobalContext = this.config.get('allowGlobalContext');
|
|
67
|
-
this.config.set('allowGlobalContext', true);
|
|
68
|
-
this.discoverEntitiesSync();
|
|
69
|
-
this.config.set('allowGlobalContext', allowGlobalContext);
|
|
70
|
-
this.driver.getPlatform().init(this);
|
|
71
|
-
}
|
|
58
|
+
this.driver.getPlatform().init(this);
|
|
72
59
|
for (const extension of this.config.get('extensions')) {
|
|
73
60
|
extension.register(this);
|
|
74
61
|
}
|
|
62
|
+
if (!discovery.skipSyncDiscovery) {
|
|
63
|
+
this.discoverEntitiesSync();
|
|
64
|
+
}
|
|
75
65
|
}
|
|
76
66
|
/**
|
|
77
67
|
* Connects to the database.
|
|
@@ -125,12 +115,20 @@ export class MikroORM {
|
|
|
125
115
|
return this.metadata;
|
|
126
116
|
}
|
|
127
117
|
async discoverEntities() {
|
|
118
|
+
// we need to allow global context here as we are not in a scope of requests yet
|
|
119
|
+
const allowGlobalContext = this.config.get('allowGlobalContext');
|
|
120
|
+
this.config.set('allowGlobalContext', true);
|
|
128
121
|
this.metadata = await this.discovery.discover(this.config.get('preferTs'));
|
|
129
122
|
this.createEntityManager();
|
|
123
|
+
this.config.set('allowGlobalContext', allowGlobalContext);
|
|
130
124
|
}
|
|
131
125
|
discoverEntitiesSync() {
|
|
126
|
+
// we need to allow global context here as we are not in a scope of requests yet
|
|
127
|
+
const allowGlobalContext = this.config.get('allowGlobalContext');
|
|
128
|
+
this.config.set('allowGlobalContext', true);
|
|
132
129
|
this.metadata = this.discovery.discoverSync();
|
|
133
130
|
this.createEntityManager();
|
|
131
|
+
this.config.set('allowGlobalContext', allowGlobalContext);
|
|
134
132
|
}
|
|
135
133
|
createEntityManager() {
|
|
136
134
|
this.driver.setMetadata(this.metadata);
|
|
@@ -367,11 +367,8 @@ export class MetadataDiscovery {
|
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
369
|
initNullability(prop) {
|
|
370
|
-
if (prop.kind === ReferenceKind.MANY_TO_ONE) {
|
|
371
|
-
return Utils.defaultValue(prop, 'nullable', prop.optional || prop.cascade.includes(Cascade.REMOVE) || prop.cascade.includes(Cascade.ALL));
|
|
372
|
-
}
|
|
373
370
|
if (prop.kind === ReferenceKind.ONE_TO_ONE) {
|
|
374
|
-
return Utils.defaultValue(prop, 'nullable', prop.optional || !prop.owner
|
|
371
|
+
return Utils.defaultValue(prop, 'nullable', prop.optional || !prop.owner);
|
|
375
372
|
}
|
|
376
373
|
return Utils.defaultValue(prop, 'nullable', prop.optional);
|
|
377
374
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.47",
|
|
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"dataloader": "2.2.3",
|
|
55
55
|
"dotenv": "17.2.3",
|
|
56
56
|
"esprima": "4.0.1",
|
|
57
|
-
"mikro-orm": "7.0.0-dev.
|
|
57
|
+
"mikro-orm": "7.0.0-dev.47",
|
|
58
58
|
"reflect-metadata": "0.2.2",
|
|
59
59
|
"tinyglobby": "0.2.13"
|
|
60
60
|
}
|
|
@@ -112,7 +112,6 @@ export class ConfigurationLoader {
|
|
|
112
112
|
settings.preferTs = process.env.MIKRO_ORM_CLI_PREFER_TS != null ? bool(process.env.MIKRO_ORM_CLI_PREFER_TS) : settings.preferTs;
|
|
113
113
|
settings.tsLoader = process.env.MIKRO_ORM_CLI_TS_LOADER ?? settings.tsLoader;
|
|
114
114
|
settings.tsConfigPath = process.env.MIKRO_ORM_CLI_TS_CONFIG_PATH ?? settings.tsConfigPath;
|
|
115
|
-
settings.alwaysAllowTs = process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS != null ? bool(process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS) : settings.alwaysAllowTs;
|
|
116
115
|
settings.verbose = process.env.MIKRO_ORM_CLI_VERBOSE != null ? bool(process.env.MIKRO_ORM_CLI_VERBOSE) : settings.verbose;
|
|
117
116
|
if (process.env.MIKRO_ORM_CLI_CONFIG?.endsWith('.ts')) {
|
|
118
117
|
settings.preferTs = true;
|
|
@@ -120,14 +119,14 @@ export class ConfigurationLoader {
|
|
|
120
119
|
return settings;
|
|
121
120
|
}
|
|
122
121
|
static getConfigPaths() {
|
|
123
|
-
const paths = [];
|
|
124
122
|
const settings = ConfigurationLoader.getSettings();
|
|
123
|
+
const typeScriptSupport = settings.preferTs ?? Utils.detectTypeScriptSupport();
|
|
124
|
+
const paths = [];
|
|
125
125
|
if (process.env.MIKRO_ORM_CLI_CONFIG) {
|
|
126
126
|
paths.push(process.env.MIKRO_ORM_CLI_CONFIG);
|
|
127
127
|
}
|
|
128
128
|
paths.push(...(settings.configPaths || []));
|
|
129
|
-
|
|
130
|
-
if (settings.preferTs !== false || alwaysAllowTs) {
|
|
129
|
+
if (typeScriptSupport) {
|
|
131
130
|
paths.push('./src/mikro-orm.config.ts');
|
|
132
131
|
paths.push('./mikro-orm.config.ts');
|
|
133
132
|
}
|
|
@@ -137,9 +136,8 @@ export class ConfigurationLoader {
|
|
|
137
136
|
const path = distDir ? 'dist' : (buildDir ? 'build' : 'src');
|
|
138
137
|
paths.push(`./${path}/mikro-orm.config.js`);
|
|
139
138
|
paths.push('./mikro-orm.config.js');
|
|
140
|
-
const typeScriptSupport = Utils.detectTypeScriptSupport();
|
|
141
139
|
/* v8 ignore next */
|
|
142
|
-
return Utils.unique(paths).filter(p => p.
|
|
140
|
+
return Utils.unique(paths).filter(p => !p.match(/\.[mc]?ts$/) || typeScriptSupport);
|
|
143
141
|
}
|
|
144
142
|
static isESM() {
|
|
145
143
|
const config = ConfigurationLoader.getPackageConfig();
|