@mikro-orm/core 7.0.0-dev.44 → 7.0.0-dev.46
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/package.json +2 -2
- package/typings.d.ts +0 -2
- package/utils/Configuration.d.ts +4 -4
- package/utils/Configuration.js +4 -9
- package/utils/ConfigurationLoader.d.ts +7 -1
- package/utils/ConfigurationLoader.js +35 -10
- package/utils/Utils.d.ts +2 -2
- package/utils/Utils.js +8 -4
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);
|
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.46",
|
|
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.46",
|
|
58
58
|
"reflect-metadata": "0.2.2",
|
|
59
59
|
"tinyglobby": "0.2.13"
|
|
60
60
|
}
|
package/typings.d.ts
CHANGED
|
@@ -604,8 +604,6 @@ export interface GenerateOptions {
|
|
|
604
604
|
coreImportsPrefix?: string;
|
|
605
605
|
onInitialMetadata?: MetadataProcessor;
|
|
606
606
|
onProcessedMetadata?: MetadataProcessor;
|
|
607
|
-
/** @deprecated use `entityDefinition: 'entitySchema'` instead */
|
|
608
|
-
entitySchema?: boolean;
|
|
609
607
|
}
|
|
610
608
|
export interface IEntityGenerator {
|
|
611
609
|
generate(options?: GenerateOptions): Promise<string[]>;
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -114,12 +114,12 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
114
114
|
entityGenerator: {
|
|
115
115
|
forceUndefined: true;
|
|
116
116
|
undefinedDefaults: false;
|
|
117
|
-
bidirectionalRelations: false;
|
|
118
|
-
identifiedReferences: false;
|
|
119
117
|
scalarTypeInDecorator: false;
|
|
118
|
+
bidirectionalRelations: true;
|
|
119
|
+
identifiedReferences: true;
|
|
120
120
|
scalarPropertiesForRelations: "never";
|
|
121
|
-
entityDefinition: "
|
|
122
|
-
enumMode: "
|
|
121
|
+
entityDefinition: "defineEntity";
|
|
122
|
+
enumMode: "dictionary";
|
|
123
123
|
fileName: (className: string) => string;
|
|
124
124
|
onlyPurePivotTables: false;
|
|
125
125
|
outputPurePivotTables: false;
|
package/utils/Configuration.js
CHANGED
|
@@ -104,12 +104,12 @@ export class Configuration {
|
|
|
104
104
|
entityGenerator: {
|
|
105
105
|
forceUndefined: true,
|
|
106
106
|
undefinedDefaults: false,
|
|
107
|
-
bidirectionalRelations: false,
|
|
108
|
-
identifiedReferences: false,
|
|
109
107
|
scalarTypeInDecorator: false,
|
|
108
|
+
bidirectionalRelations: true,
|
|
109
|
+
identifiedReferences: true,
|
|
110
110
|
scalarPropertiesForRelations: 'never',
|
|
111
|
-
entityDefinition: '
|
|
112
|
-
enumMode: '
|
|
111
|
+
entityDefinition: 'defineEntity',
|
|
112
|
+
enumMode: 'dictionary',
|
|
113
113
|
fileName: (className) => className,
|
|
114
114
|
onlyPurePivotTables: false,
|
|
115
115
|
outputPurePivotTables: false,
|
|
@@ -150,7 +150,6 @@ export class Configuration {
|
|
|
150
150
|
}
|
|
151
151
|
this.options = Utils.mergeConfig({}, Configuration.DEFAULTS, options);
|
|
152
152
|
this.options.baseDir = Utils.absolutePath(this.options.baseDir);
|
|
153
|
-
this.options.preferTs ??= options.preferTs;
|
|
154
153
|
if (validate) {
|
|
155
154
|
this.validateOptions();
|
|
156
155
|
}
|
|
@@ -348,10 +347,6 @@ export class Configuration {
|
|
|
348
347
|
}
|
|
349
348
|
sync() {
|
|
350
349
|
process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
|
|
351
|
-
// FIXME remove `entityGenerator.entitySchema` option
|
|
352
|
-
if (this.options.entityGenerator.entitySchema) {
|
|
353
|
-
this.options.entityGenerator.entityDefinition = 'entitySchema';
|
|
354
|
-
}
|
|
355
350
|
this.logger.setDebugMode(this.options.debug);
|
|
356
351
|
}
|
|
357
352
|
/**
|
|
@@ -19,7 +19,12 @@ export declare class ConfigurationLoader {
|
|
|
19
19
|
static getSettings(): Settings;
|
|
20
20
|
static getConfigPaths(): string[];
|
|
21
21
|
static isESM(): boolean;
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Tries to register TS support in the following order: swc, tsx, jiti, tsimp
|
|
24
|
+
* Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
|
|
25
|
+
* This method is used only in CLI context.
|
|
26
|
+
*/
|
|
27
|
+
static registerTypeScriptSupport(configPath?: string, tsLoader?: 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto'): Promise<boolean>;
|
|
23
28
|
static registerDotenv<D extends IDatabaseDriver>(options: Options<D>): void;
|
|
24
29
|
static loadEnvironmentVars<D extends IDatabaseDriver>(): Promise<Partial<Options<D>>>;
|
|
25
30
|
static loadEnvironmentVarsSync<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
@@ -31,6 +36,7 @@ export interface Settings {
|
|
|
31
36
|
alwaysAllowTs?: boolean;
|
|
32
37
|
verbose?: boolean;
|
|
33
38
|
preferTs?: boolean;
|
|
39
|
+
tsLoader?: 'swc' | 'tsx' | 'jiti' | 'tsimp' | 'auto';
|
|
34
40
|
tsConfigPath?: string;
|
|
35
41
|
configPaths?: string[];
|
|
36
42
|
}
|
|
@@ -110,6 +110,7 @@ export class ConfigurationLoader {
|
|
|
110
110
|
const settings = { ...config['mikro-orm'] };
|
|
111
111
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
112
112
|
settings.preferTs = process.env.MIKRO_ORM_CLI_PREFER_TS != null ? bool(process.env.MIKRO_ORM_CLI_PREFER_TS) : settings.preferTs;
|
|
113
|
+
settings.tsLoader = process.env.MIKRO_ORM_CLI_TS_LOADER ?? settings.tsLoader;
|
|
113
114
|
settings.tsConfigPath = process.env.MIKRO_ORM_CLI_TS_CONFIG_PATH ?? settings.tsConfigPath;
|
|
114
115
|
settings.alwaysAllowTs = process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS != null ? bool(process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS) : settings.alwaysAllowTs;
|
|
115
116
|
settings.verbose = process.env.MIKRO_ORM_CLI_VERBOSE != null ? bool(process.env.MIKRO_ORM_CLI_VERBOSE) : settings.verbose;
|
|
@@ -145,22 +146,46 @@ export class ConfigurationLoader {
|
|
|
145
146
|
const type = config?.type ?? '';
|
|
146
147
|
return type === 'module';
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Tries to register TS support in the following order: swc, tsx, jiti, tsimp
|
|
151
|
+
* Use `MIKRO_ORM_CLI_TS_LOADER` env var to set the loader explicitly.
|
|
152
|
+
* This method is used only in CLI context.
|
|
153
|
+
*/
|
|
154
|
+
static async registerTypeScriptSupport(configPath = 'tsconfig.json', tsLoader) {
|
|
149
155
|
/* v8 ignore next 3 */
|
|
150
156
|
if (process.versions.bun) {
|
|
151
157
|
return true;
|
|
152
158
|
}
|
|
153
159
|
process.env.SWC_NODE_PROJECT ??= configPath;
|
|
160
|
+
process.env.TSIMP_PROJECT ??= configPath;
|
|
154
161
|
process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
|
|
155
|
-
const
|
|
156
|
-
/* v8 ignore next
|
|
157
|
-
const importMethod =
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
const isEsm = this.isESM();
|
|
163
|
+
/* v8 ignore next */
|
|
164
|
+
const importMethod = isEsm ? 'tryImport' : 'tryRequire';
|
|
165
|
+
const explicitLoader = tsLoader ?? process.env.MIKRO_ORM_CLI_TS_LOADER ?? 'auto';
|
|
166
|
+
const loaders = {
|
|
167
|
+
swc: { esm: '@swc-node/register/esm-register', cjs: '@swc-node/register' },
|
|
168
|
+
tsx: { esm: 'tsx/esm/api', cjs: 'tsx/cjs/api', cb: (tsx) => tsx.register({ tsconfig: configPath }) },
|
|
169
|
+
jiti: { esm: 'jiti/register', cjs: 'jiti/register', cb: () => Utils.setDynamicImportProvider(id => import(id).then(mod => mod?.default ?? mod)) },
|
|
170
|
+
tsimp: { esm: 'tsimp/import', cjs: 'tsimp/import' },
|
|
171
|
+
};
|
|
172
|
+
for (const loader of Utils.keys(loaders)) {
|
|
173
|
+
if (explicitLoader !== 'auto' && loader !== explicitLoader) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const { esm, cjs, cb } = loaders[loader];
|
|
177
|
+
/* v8 ignore next */
|
|
178
|
+
const module = isEsm ? esm : cjs;
|
|
179
|
+
const mod = await Utils[importMethod]({ module });
|
|
180
|
+
if (mod) {
|
|
181
|
+
cb?.(mod);
|
|
182
|
+
process.env.MIKRO_ORM_CLI_TS_LOADER = loader;
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// eslint-disable-next-line no-console
|
|
187
|
+
console.warn('Neither `swc`, `tsx`, `jiti` nor `tsimp` found in the project dependencies, support for working with TypeScript files might not work. To use `swc`, you need to install both `@swc-node/register` and `@swc/core`.');
|
|
188
|
+
return false;
|
|
164
189
|
}
|
|
165
190
|
static registerDotenv(options) {
|
|
166
191
|
const path = process.env.MIKRO_ORM_ENV ?? ((options.baseDir ?? process.cwd()) + '/.env');
|
package/utils/Utils.d.ts
CHANGED
|
@@ -252,13 +252,13 @@ export declare class Utils {
|
|
|
252
252
|
static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
|
|
253
253
|
static tryRequire<T extends Dictionary = any>({ module, from, allowError, warning }: {
|
|
254
254
|
module: string;
|
|
255
|
-
warning
|
|
255
|
+
warning?: string;
|
|
256
256
|
from?: string;
|
|
257
257
|
allowError?: string;
|
|
258
258
|
}): T | undefined;
|
|
259
259
|
static tryImport<T extends Dictionary = any>({ module, warning }: {
|
|
260
260
|
module: string;
|
|
261
|
-
warning
|
|
261
|
+
warning?: string;
|
|
262
262
|
}): Promise<T | undefined>;
|
|
263
263
|
static stripRelativePath(str: string): string;
|
|
264
264
|
static xor(a: boolean, b: boolean): boolean;
|
package/utils/Utils.js
CHANGED
|
@@ -1075,8 +1075,10 @@ export class Utils {
|
|
|
1075
1075
|
}
|
|
1076
1076
|
catch (err) {
|
|
1077
1077
|
if (err.message.includes(allowError)) {
|
|
1078
|
-
|
|
1079
|
-
|
|
1078
|
+
if (warning) {
|
|
1079
|
+
// eslint-disable-next-line no-console
|
|
1080
|
+
console.warn(warning);
|
|
1081
|
+
}
|
|
1080
1082
|
return undefined;
|
|
1081
1083
|
}
|
|
1082
1084
|
throw err;
|
|
@@ -1088,8 +1090,10 @@ export class Utils {
|
|
|
1088
1090
|
}
|
|
1089
1091
|
catch (err) {
|
|
1090
1092
|
if (err.code === 'ERR_MODULE_NOT_FOUND') {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
+
if (warning) {
|
|
1094
|
+
// eslint-disable-next-line no-console
|
|
1095
|
+
console.warn(warning);
|
|
1096
|
+
}
|
|
1093
1097
|
return undefined;
|
|
1094
1098
|
}
|
|
1095
1099
|
throw err;
|