@mikro-orm/core 7.0.0-dev.41 → 7.0.0-dev.43
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 +1 -2
- package/MikroORM.js +21 -58
- package/connections/Connection.d.ts +5 -3
- package/connections/Connection.js +14 -11
- package/drivers/DatabaseDriver.d.ts +6 -2
- package/drivers/DatabaseDriver.js +4 -4
- package/drivers/IDatabaseDriver.d.ts +6 -2
- package/metadata/MetadataDiscovery.d.ts +1 -1
- package/metadata/MetadataDiscovery.js +2 -2
- package/package.json +2 -2
- package/typings.d.ts +1 -0
- package/utils/AbstractSchemaGenerator.js +3 -1
- package/utils/Configuration.d.ts +2 -7
- package/utils/Configuration.js +2 -12
- package/utils/ConfigurationLoader.d.ts +2 -18
- package/utils/ConfigurationLoader.js +8 -32
- package/utils/Utils.d.ts +0 -4
- package/utils/Utils.js +0 -20
package/MikroORM.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
21
21
|
* Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
|
|
22
22
|
* If you omit the `options` parameter, your CLI config will be used.
|
|
23
23
|
*/
|
|
24
|
-
static init<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options
|
|
24
|
+
static init<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): Promise<MikroORM<D, EM, Entities>>;
|
|
25
25
|
/**
|
|
26
26
|
* Synchronous variant of the `init` method with some limitations:
|
|
27
27
|
* - database connection will be established when you first interact with the database (or you can use `orm.connect()` explicitly)
|
|
@@ -29,7 +29,6 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
29
29
|
* - no support for folder based discovery
|
|
30
30
|
* - no check for mismatched package versions
|
|
31
31
|
*/
|
|
32
|
-
static initSync<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): MikroORM<D, EM, Entities>;
|
|
33
32
|
constructor(options: Options<Driver, EM>);
|
|
34
33
|
/**
|
|
35
34
|
* Connects to the database.
|
package/MikroORM.js
CHANGED
|
@@ -23,22 +23,14 @@ export class MikroORM {
|
|
|
23
23
|
* If you omit the `options` parameter, your CLI config will be used.
|
|
24
24
|
*/
|
|
25
25
|
static async init(options) {
|
|
26
|
-
|
|
27
|
-
const coreVersion = ConfigurationLoader.checkPackageVersion();
|
|
28
|
-
const env = await ConfigurationLoader.loadEnvironmentVars();
|
|
26
|
+
/* v8 ignore next 3 */
|
|
29
27
|
if (!options) {
|
|
30
|
-
|
|
31
|
-
const config = (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPathFromArg ?? ConfigurationLoader.getConfigPaths()));
|
|
32
|
-
options = config.getAll();
|
|
33
|
-
if (configPathFromArg) {
|
|
34
|
-
config.getLogger().warn('deprecated', 'Path for config file was inferred from the command line arguments. Instead, you should set the MIKRO_ORM_CLI_CONFIG environment variable to specify the path, or if you really must use the command line arguments, import the config manually based on them, and pass it to init.', { label: 'D0001' });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
options = Utils.mergeConfig(options, env);
|
|
38
|
-
if ('DRIVER' in this && !options.driver) {
|
|
39
|
-
options.driver = this.DRIVER;
|
|
28
|
+
throw new Error(`options parameter is required`);
|
|
40
29
|
}
|
|
41
|
-
const
|
|
30
|
+
const coreVersion = ConfigurationLoader.checkPackageVersion();
|
|
31
|
+
options.discovery ??= {};
|
|
32
|
+
options.discovery.skipSyncDiscovery ??= true;
|
|
33
|
+
const orm = new this(options);
|
|
42
34
|
orm.logger.log('info', `MikroORM version: ${colors.green(coreVersion)}`);
|
|
43
35
|
// we need to allow global context here as we are not in a scope of requests yet
|
|
44
36
|
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
@@ -46,15 +38,6 @@ export class MikroORM {
|
|
|
46
38
|
await orm.discoverEntities();
|
|
47
39
|
orm.config.set('allowGlobalContext', allowGlobalContext);
|
|
48
40
|
orm.driver.getPlatform().init(orm);
|
|
49
|
-
if (orm.config.get('connect')) {
|
|
50
|
-
await orm.connect();
|
|
51
|
-
}
|
|
52
|
-
for (const extension of orm.config.get('extensions')) {
|
|
53
|
-
extension.register(orm);
|
|
54
|
-
}
|
|
55
|
-
if (orm.config.get('connect') && orm.config.get('ensureIndexes')) {
|
|
56
|
-
await orm.getSchemaGenerator().ensureIndexes();
|
|
57
|
-
}
|
|
58
41
|
return orm;
|
|
59
42
|
}
|
|
60
43
|
/**
|
|
@@ -64,26 +47,10 @@ export class MikroORM {
|
|
|
64
47
|
* - no support for folder based discovery
|
|
65
48
|
* - no check for mismatched package versions
|
|
66
49
|
*/
|
|
67
|
-
|
|
50
|
+
constructor(options) {
|
|
68
51
|
ConfigurationLoader.registerDotenv(options);
|
|
69
52
|
const env = ConfigurationLoader.loadEnvironmentVarsSync();
|
|
70
53
|
options = Utils.merge(options, env);
|
|
71
|
-
if ('DRIVER' in this && !options.driver) {
|
|
72
|
-
options.driver = this.DRIVER;
|
|
73
|
-
}
|
|
74
|
-
const orm = new MikroORM(options);
|
|
75
|
-
// we need to allow global context here as we are not in a scope of requests yet
|
|
76
|
-
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
77
|
-
orm.config.set('allowGlobalContext', true);
|
|
78
|
-
orm.discoverEntitiesSync();
|
|
79
|
-
orm.config.set('allowGlobalContext', allowGlobalContext);
|
|
80
|
-
orm.driver.getPlatform().init(orm);
|
|
81
|
-
for (const extension of orm.config.get('extensions')) {
|
|
82
|
-
extension.register(orm);
|
|
83
|
-
}
|
|
84
|
-
return orm;
|
|
85
|
-
}
|
|
86
|
-
constructor(options) {
|
|
87
54
|
this.config = new Configuration(options);
|
|
88
55
|
const discovery = this.config.get('discovery');
|
|
89
56
|
if (discovery.disableDynamicFileAccess) {
|
|
@@ -94,25 +61,23 @@ export class MikroORM {
|
|
|
94
61
|
this.driver = this.config.getDriver();
|
|
95
62
|
this.logger = this.config.getLogger();
|
|
96
63
|
this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
|
|
64
|
+
if (!discovery.skipSyncDiscovery) {
|
|
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
|
+
}
|
|
72
|
+
for (const extension of this.config.get('extensions')) {
|
|
73
|
+
extension.register(this);
|
|
74
|
+
}
|
|
97
75
|
}
|
|
98
76
|
/**
|
|
99
77
|
* Connects to the database.
|
|
100
78
|
*/
|
|
101
79
|
async connect() {
|
|
102
|
-
|
|
103
|
-
const clientUrl = connection.getClientUrl();
|
|
104
|
-
const dbName = this.config.get('dbName');
|
|
105
|
-
const db = dbName + (clientUrl ? ' on ' + clientUrl : '');
|
|
106
|
-
if (this.config.get('ensureDatabase')) {
|
|
107
|
-
const options = this.config.get('ensureDatabase');
|
|
108
|
-
await this.schema.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
|
|
109
|
-
}
|
|
110
|
-
if (await this.isConnected()) {
|
|
111
|
-
this.logger.log('info', `MikroORM successfully connected to database ${colors.green(db)}`);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.logger.error('info', `MikroORM failed to connect to database ${db}`);
|
|
115
|
-
}
|
|
80
|
+
await this.driver.connect();
|
|
116
81
|
return this.driver;
|
|
117
82
|
}
|
|
118
83
|
/**
|
|
@@ -141,9 +106,7 @@ export class MikroORM {
|
|
|
141
106
|
* Closes the database connection.
|
|
142
107
|
*/
|
|
143
108
|
async close(force = false) {
|
|
144
|
-
|
|
145
|
-
await this.driver.close(force);
|
|
146
|
-
}
|
|
109
|
+
await this.driver.close(force);
|
|
147
110
|
if (this.config.getMetadataCacheAdapter()?.close) {
|
|
148
111
|
await this.config.getMetadataCacheAdapter().close();
|
|
149
112
|
}
|
|
@@ -166,7 +129,7 @@ export class MikroORM {
|
|
|
166
129
|
this.createEntityManager();
|
|
167
130
|
}
|
|
168
131
|
discoverEntitiesSync() {
|
|
169
|
-
this.metadata = this.discovery.discoverSync(
|
|
132
|
+
this.metadata = this.discovery.discoverSync();
|
|
170
133
|
this.createEntityManager();
|
|
171
134
|
}
|
|
172
135
|
createEntityManager() {
|
|
@@ -17,7 +17,9 @@ export declare abstract class Connection {
|
|
|
17
17
|
/**
|
|
18
18
|
* Establishes connection to database
|
|
19
19
|
*/
|
|
20
|
-
abstract connect(
|
|
20
|
+
abstract connect(options?: {
|
|
21
|
+
skipOnConnect?: boolean;
|
|
22
|
+
}): void | Promise<void>;
|
|
21
23
|
/**
|
|
22
24
|
* Are we connected to the database
|
|
23
25
|
*/
|
|
@@ -37,9 +39,10 @@ export declare abstract class Connection {
|
|
|
37
39
|
*/
|
|
38
40
|
close(force?: boolean): Promise<void>;
|
|
39
41
|
/**
|
|
40
|
-
* Ensure the connection exists, this is used to support lazy connect when using `MikroORM
|
|
42
|
+
* Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
|
|
41
43
|
*/
|
|
42
44
|
ensureConnection(): Promise<void>;
|
|
45
|
+
protected onConnect(): Promise<void>;
|
|
43
46
|
transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
|
|
44
47
|
isolationLevel?: IsolationLevel;
|
|
45
48
|
readOnly?: boolean;
|
|
@@ -58,7 +61,6 @@ export declare abstract class Connection {
|
|
|
58
61
|
rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
59
62
|
abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
|
|
60
63
|
getConnectionOptions(): ConnectionConfig;
|
|
61
|
-
getClientUrl(): string;
|
|
62
64
|
setMetadata(metadata: MetadataStorage): void;
|
|
63
65
|
setPlatform(platform: Platform): void;
|
|
64
66
|
getPlatform(): Platform;
|
|
@@ -33,13 +33,25 @@ export class Connection {
|
|
|
33
33
|
.forEach(k => delete this.options[k]);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* Ensure the connection exists, this is used to support lazy connect when using `MikroORM
|
|
36
|
+
* Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
|
|
37
37
|
*/
|
|
38
38
|
async ensureConnection() {
|
|
39
39
|
if (!this.connected) {
|
|
40
40
|
await this.connect();
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
async onConnect() {
|
|
44
|
+
const schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
|
|
45
|
+
if (this.type === 'write' && schemaGenerator) {
|
|
46
|
+
if (this.config.get('ensureDatabase')) {
|
|
47
|
+
const options = this.config.get('ensureDatabase');
|
|
48
|
+
await schemaGenerator.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
|
|
49
|
+
}
|
|
50
|
+
if (this.config.get('ensureIndexes')) {
|
|
51
|
+
await schemaGenerator.ensureIndexes();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
43
55
|
async transactional(cb, options) {
|
|
44
56
|
throw new Error(`Transactions are not supported by current driver`);
|
|
45
57
|
}
|
|
@@ -67,7 +79,7 @@ export class Connection {
|
|
|
67
79
|
}
|
|
68
80
|
}
|
|
69
81
|
else {
|
|
70
|
-
const url = new URL(this.config.
|
|
82
|
+
const url = new URL(this.config.get('clientUrl'));
|
|
71
83
|
this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
|
|
72
84
|
this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
|
|
73
85
|
this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
|
|
@@ -76,15 +88,6 @@ export class Connection {
|
|
|
76
88
|
}
|
|
77
89
|
return ret;
|
|
78
90
|
}
|
|
79
|
-
getClientUrl() {
|
|
80
|
-
const options = this.getConnectionOptions();
|
|
81
|
-
const url = new URL(this.config.getClientUrl(true));
|
|
82
|
-
const password = options.password ? ':*****' : '';
|
|
83
|
-
const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
|
|
84
|
-
? `?schema=${options.schema}`
|
|
85
|
-
: '';
|
|
86
|
-
return `${url.protocol}//${options.user}${password}@${options.host}:${options.port}${schema}`;
|
|
87
|
-
}
|
|
88
91
|
setMetadata(metadata) {
|
|
89
92
|
this.metadata = metadata;
|
|
90
93
|
}
|
|
@@ -36,8 +36,12 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
|
|
|
36
36
|
loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
|
|
37
37
|
syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
|
|
38
38
|
mapResult<T extends object>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
|
|
39
|
-
connect(
|
|
40
|
-
|
|
39
|
+
connect(options?: {
|
|
40
|
+
skipOnConnect?: boolean;
|
|
41
|
+
}): Promise<C>;
|
|
42
|
+
reconnect(options?: {
|
|
43
|
+
skipOnConnect?: boolean;
|
|
44
|
+
}): Promise<C>;
|
|
41
45
|
getConnection(type?: ConnectionType): C;
|
|
42
46
|
close(force?: boolean): Promise<void>;
|
|
43
47
|
getPlatform(): Platform;
|
|
@@ -65,14 +65,14 @@ export class DatabaseDriver {
|
|
|
65
65
|
}
|
|
66
66
|
return this.comparator.mapResult(meta.className, result);
|
|
67
67
|
}
|
|
68
|
-
async connect() {
|
|
69
|
-
await this.connection.connect();
|
|
68
|
+
async connect(options) {
|
|
69
|
+
await this.connection.connect(options);
|
|
70
70
|
await Promise.all(this.replicas.map(replica => replica.connect()));
|
|
71
71
|
return this.connection;
|
|
72
72
|
}
|
|
73
|
-
async reconnect() {
|
|
73
|
+
async reconnect(options) {
|
|
74
74
|
await this.close(true);
|
|
75
|
-
await this.connect();
|
|
75
|
+
await this.connect(options);
|
|
76
76
|
return this.connection;
|
|
77
77
|
}
|
|
78
78
|
getConnection(type = 'write') {
|
|
@@ -14,9 +14,13 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
|
14
14
|
[EntityManagerType]: EntityManager<this>;
|
|
15
15
|
readonly config: Configuration;
|
|
16
16
|
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
17
|
-
connect(
|
|
17
|
+
connect(options?: {
|
|
18
|
+
skipOnConnect?: boolean;
|
|
19
|
+
}): Promise<C>;
|
|
18
20
|
close(force?: boolean): Promise<void>;
|
|
19
|
-
reconnect(
|
|
21
|
+
reconnect(options?: {
|
|
22
|
+
skipOnConnect?: boolean;
|
|
23
|
+
}): Promise<C>;
|
|
20
24
|
getConnection(type?: ConnectionType): C;
|
|
21
25
|
/**
|
|
22
26
|
* Finds selection of entities
|
|
@@ -16,7 +16,7 @@ export declare class MetadataDiscovery {
|
|
|
16
16
|
private readonly discovered;
|
|
17
17
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
18
18
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
19
|
-
discoverSync(
|
|
19
|
+
discoverSync(): MetadataStorage;
|
|
20
20
|
private mapDiscoveredEntities;
|
|
21
21
|
private initAccessors;
|
|
22
22
|
processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
|
|
@@ -47,10 +47,10 @@ export class MetadataDiscovery {
|
|
|
47
47
|
await this.config.get('discovery').afterDiscovered?.(storage, this.platform);
|
|
48
48
|
return storage;
|
|
49
49
|
}
|
|
50
|
-
discoverSync(
|
|
50
|
+
discoverSync() {
|
|
51
51
|
const startTime = Date.now();
|
|
52
52
|
this.logger.log('discovery', `ORM entity discovery started, using ${colors.cyan(this.metadataProvider.constructor.name)} in sync mode`);
|
|
53
|
-
this.findEntities(
|
|
53
|
+
this.findEntities();
|
|
54
54
|
for (const meta of this.discovered) {
|
|
55
55
|
/* v8 ignore next */
|
|
56
56
|
void this.config.get('discovery').onMetadata?.(meta, this.platform);
|
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.43",
|
|
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.43",
|
|
58
58
|
"reflect-metadata": "0.2.2",
|
|
59
59
|
"tinyglobby": "0.2.13"
|
|
60
60
|
}
|
package/typings.d.ts
CHANGED
|
@@ -527,6 +527,7 @@ export interface CreateSchemaOptions {
|
|
|
527
527
|
export interface ClearDatabaseOptions {
|
|
528
528
|
schema?: string;
|
|
529
529
|
truncate?: boolean;
|
|
530
|
+
clearIdentityMap?: boolean;
|
|
530
531
|
}
|
|
531
532
|
export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
|
|
532
533
|
clear?: boolean;
|
|
@@ -42,7 +42,9 @@ export class AbstractSchemaGenerator {
|
|
|
42
42
|
for (const meta of this.getOrderedMetadata(options?.schema).reverse()) {
|
|
43
43
|
await this.driver.nativeDelete(meta.className, {}, options);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
if (options?.clearIdentityMap ?? true) {
|
|
46
|
+
this.clearIdentityMap();
|
|
47
|
+
}
|
|
46
48
|
}
|
|
47
49
|
clearIdentityMap() {
|
|
48
50
|
/* v8 ignore next 3 */
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -57,7 +57,6 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
57
57
|
loadStrategy: LoadStrategy.BALANCED;
|
|
58
58
|
dataloader: DataloaderType.NONE;
|
|
59
59
|
populateWhere: PopulateHint.ALL;
|
|
60
|
-
connect: true;
|
|
61
60
|
ignoreUndefinedInQuery: false;
|
|
62
61
|
onQuery: (sql: string) => string;
|
|
63
62
|
autoJoinOneToOneOwner: true;
|
|
@@ -177,10 +176,6 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
177
176
|
*/
|
|
178
177
|
getLogger(): Logger;
|
|
179
178
|
getDataloaderType(): DataloaderType;
|
|
180
|
-
/**
|
|
181
|
-
* Gets current client URL (connection string).
|
|
182
|
-
*/
|
|
183
|
-
getClientUrl(hidePassword?: boolean): string;
|
|
184
179
|
getSchema(skipDefaultSchema?: boolean): string | undefined;
|
|
185
180
|
/**
|
|
186
181
|
* Gets current database driver instance.
|
|
@@ -239,7 +234,7 @@ export declare class Configuration<D extends IDatabaseDriver = IDatabaseDriver,
|
|
|
239
234
|
/**
|
|
240
235
|
* Type helper to make it easier to use `mikro-orm.config.js`.
|
|
241
236
|
*/
|
|
242
|
-
export declare function defineConfig<D extends IDatabaseDriver
|
|
237
|
+
export declare function defineConfig<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager<D> = EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): Options<D, EM, Entities>;
|
|
243
238
|
export interface ConnectionOptions {
|
|
244
239
|
dbName?: string;
|
|
245
240
|
schema?: string;
|
|
@@ -301,6 +296,7 @@ export interface MetadataDiscoveryOptions {
|
|
|
301
296
|
onMetadata?: (meta: EntityMetadata, platform: Platform) => MaybePromise<void>;
|
|
302
297
|
afterDiscovered?: (storage: MetadataStorage, platform: Platform) => MaybePromise<void>;
|
|
303
298
|
tsConfigPath?: string;
|
|
299
|
+
skipSyncDiscovery?: boolean;
|
|
304
300
|
}
|
|
305
301
|
export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = EntityManager> extends ConnectionOptions {
|
|
306
302
|
entities: (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[];
|
|
@@ -321,7 +317,6 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
|
|
|
321
317
|
};
|
|
322
318
|
implicitTransactions?: boolean;
|
|
323
319
|
disableTransactions?: boolean;
|
|
324
|
-
connect: boolean;
|
|
325
320
|
verbose: boolean;
|
|
326
321
|
ignoreUndefinedInQuery?: boolean;
|
|
327
322
|
onQuery: (sql: string, params: readonly unknown[]) => string;
|
package/utils/Configuration.js
CHANGED
|
@@ -47,7 +47,6 @@ export class Configuration {
|
|
|
47
47
|
loadStrategy: LoadStrategy.BALANCED,
|
|
48
48
|
dataloader: DataloaderType.NONE,
|
|
49
49
|
populateWhere: PopulateHint.ALL,
|
|
50
|
-
connect: true,
|
|
51
50
|
ignoreUndefinedInQuery: false,
|
|
52
51
|
onQuery: sql => sql,
|
|
53
52
|
autoJoinOneToOneOwner: true,
|
|
@@ -211,15 +210,6 @@ export class Configuration {
|
|
|
211
210
|
}
|
|
212
211
|
return this.options.dataloader;
|
|
213
212
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Gets current client URL (connection string).
|
|
216
|
-
*/
|
|
217
|
-
getClientUrl(hidePassword = false) {
|
|
218
|
-
if (hidePassword) {
|
|
219
|
-
return this.options.clientUrl.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
|
|
220
|
-
}
|
|
221
|
-
return this.options.clientUrl;
|
|
222
|
-
}
|
|
223
213
|
getSchema(skipDefaultSchema = false) {
|
|
224
214
|
if (skipDefaultSchema && this.options.schema === this.platform.getDefaultSchemaName()) {
|
|
225
215
|
return undefined;
|
|
@@ -322,13 +312,13 @@ export class Configuration {
|
|
|
322
312
|
this.options.implicitTransactions = this.platform.usesImplicitTransactions();
|
|
323
313
|
}
|
|
324
314
|
try {
|
|
325
|
-
const url = new URL(this.
|
|
315
|
+
const url = new URL(this.options.clientUrl);
|
|
326
316
|
if (url.pathname) {
|
|
327
317
|
this.options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
|
|
328
318
|
}
|
|
329
319
|
}
|
|
330
320
|
catch {
|
|
331
|
-
const url = this.
|
|
321
|
+
const url = this.options.clientUrl.match(/:\/\/.*\/([^?]+)/);
|
|
332
322
|
if (url) {
|
|
333
323
|
this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
334
324
|
}
|
|
@@ -13,30 +13,14 @@ export declare class ConfigurationLoader {
|
|
|
13
13
|
* @param paths Array of possible paths for a configuration file. Files will be checked in order, and the first existing one will be used. Defaults to the output of {@link ConfigurationLoader.getConfigPaths}.
|
|
14
14
|
* @param options Additional options to augment the final configuration with.
|
|
15
15
|
*/
|
|
16
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(contextName
|
|
17
|
-
/**
|
|
18
|
-
* Gets the default config from the default paths
|
|
19
|
-
*
|
|
20
|
-
* @deprecated Prefer to explicitly set the `contextName` at the first argument. This signature is available for backwards compatibility, and may be removed in v7.
|
|
21
|
-
*/
|
|
22
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(): Promise<Configuration<D, EM>>;
|
|
23
|
-
/**
|
|
24
|
-
* Gets default configuration out of the default paths, and possibly from `process.argv`
|
|
25
|
-
*
|
|
26
|
-
* @param validate Whether to validate the final configuration.
|
|
27
|
-
* @param options Additional options to augment the final configuration with (just before validation).
|
|
28
|
-
*
|
|
29
|
-
* @deprecated Use the other overloads of this method. This signature will be removed in v7.
|
|
30
|
-
*/
|
|
31
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(validate: boolean, options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
16
|
+
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(contextName?: string, paths?: string[], options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
32
17
|
static getConfigFile(paths: string[]): Promise<[string, unknown] | []>;
|
|
33
18
|
static getPackageConfig(basePath?: string): Dictionary;
|
|
34
19
|
static getSettings(): Settings;
|
|
35
|
-
static configPathsFromArg(): string[] | undefined;
|
|
36
20
|
static getConfigPaths(): string[];
|
|
37
21
|
static isESM(): boolean;
|
|
38
22
|
static registerTypeScriptSupport(configPath?: string): Promise<boolean>;
|
|
39
|
-
static registerDotenv<D extends IDatabaseDriver>(options
|
|
23
|
+
static registerDotenv<D extends IDatabaseDriver>(options: Options<D>): void;
|
|
40
24
|
static loadEnvironmentVars<D extends IDatabaseDriver>(): Promise<Partial<Options<D>>>;
|
|
41
25
|
static loadEnvironmentVarsSync<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
42
26
|
static getORMPackages(): Set<string>;
|
|
@@ -7,30 +7,14 @@ import { Utils } from './Utils.js';
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export class ConfigurationLoader {
|
|
10
|
+
/**
|
|
11
|
+
* Gets a named configuration
|
|
12
|
+
*
|
|
13
|
+
* @param contextName Load a config with the given `contextName` value. Used when config file exports array or factory function. Setting it to "default" matches also config objects without `contextName` set.
|
|
14
|
+
* @param paths Array of possible paths for a configuration file. Files will be checked in order, and the first existing one will be used. Defaults to the output of {@link ConfigurationLoader.getConfigPaths}.
|
|
15
|
+
* @param options Additional options to augment the final configuration with.
|
|
16
|
+
*/
|
|
10
17
|
static async getConfiguration(contextName = 'default', paths = ConfigurationLoader.getConfigPaths(), options = {}) {
|
|
11
|
-
// Backwards compatibility layer
|
|
12
|
-
if (typeof contextName === 'boolean' || !Array.isArray(paths)) {
|
|
13
|
-
this.registerDotenv(options);
|
|
14
|
-
const configPathFromArg = ConfigurationLoader.configPathsFromArg();
|
|
15
|
-
const configPaths = configPathFromArg ?? (Array.isArray(paths) ? paths : ConfigurationLoader.getConfigPaths());
|
|
16
|
-
const config = contextName
|
|
17
|
-
? (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPaths, Array.isArray(paths) ? {} : paths))
|
|
18
|
-
: await (async () => {
|
|
19
|
-
const env = await this.loadEnvironmentVars();
|
|
20
|
-
const [path, tmp] = await this.getConfigFile(configPaths);
|
|
21
|
-
if (!path) {
|
|
22
|
-
if (Utils.hasObjectKeys(env)) {
|
|
23
|
-
return new Configuration(Utils.mergeConfig({}, options, env), false);
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`MikroORM config file not found in ['${configPaths.join(`', '`)}']`);
|
|
26
|
-
}
|
|
27
|
-
return new Configuration(Utils.mergeConfig(tmp, options, env), false);
|
|
28
|
-
})();
|
|
29
|
-
if (configPathFromArg) {
|
|
30
|
-
config.getLogger().warn('deprecated', 'Path for config file was inferred from the command line arguments. Instead, you should set the MIKRO_ORM_CLI_CONFIG environment variable to specify the path, or if you really must use the command line arguments, import the config manually based on them, and pass it to init.', { label: 'D0001' });
|
|
31
|
-
}
|
|
32
|
-
return config;
|
|
33
|
-
}
|
|
34
18
|
const env = await this.loadEnvironmentVars();
|
|
35
19
|
const configFinder = (cfg) => {
|
|
36
20
|
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : (contextName === 'default'));
|
|
@@ -134,14 +118,6 @@ export class ConfigurationLoader {
|
|
|
134
118
|
}
|
|
135
119
|
return settings;
|
|
136
120
|
}
|
|
137
|
-
static configPathsFromArg() {
|
|
138
|
-
const options = Utils.parseArgs();
|
|
139
|
-
const configArgName = process.env.MIKRO_ORM_CONFIG_ARG_NAME ?? 'config';
|
|
140
|
-
if (options[configArgName]) {
|
|
141
|
-
return [options[configArgName]];
|
|
142
|
-
}
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
121
|
static getConfigPaths() {
|
|
146
122
|
const paths = [];
|
|
147
123
|
const settings = ConfigurationLoader.getSettings();
|
|
@@ -187,7 +163,7 @@ export class ConfigurationLoader {
|
|
|
187
163
|
return !!supported;
|
|
188
164
|
}
|
|
189
165
|
static registerDotenv(options) {
|
|
190
|
-
const path = process.env.MIKRO_ORM_ENV ?? ((options
|
|
166
|
+
const path = process.env.MIKRO_ORM_ENV ?? ((options.baseDir ?? process.cwd()) + '/.env');
|
|
191
167
|
const env = {};
|
|
192
168
|
dotenv.config({ path, processEnv: env, quiet: true });
|
|
193
169
|
// only propagate known env vars
|
package/utils/Utils.d.ts
CHANGED
|
@@ -261,10 +261,6 @@ export declare class Utils {
|
|
|
261
261
|
warning: string;
|
|
262
262
|
}): Promise<T | undefined>;
|
|
263
263
|
static stripRelativePath(str: string): string;
|
|
264
|
-
/**
|
|
265
|
-
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
266
|
-
*/
|
|
267
|
-
static parseArgs<T extends Dictionary = Dictionary>(): T;
|
|
268
264
|
static xor(a: boolean, b: boolean): boolean;
|
|
269
265
|
static keys<T extends object>(obj: T): (keyof T)[];
|
|
270
266
|
static values<T extends object>(obj: T): T[keyof T][];
|
package/utils/Utils.js
CHANGED
|
@@ -1098,26 +1098,6 @@ export class Utils {
|
|
|
1098
1098
|
static stripRelativePath(str) {
|
|
1099
1099
|
return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
|
|
1100
1100
|
}
|
|
1101
|
-
/**
|
|
1102
|
-
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
1103
|
-
*/
|
|
1104
|
-
static parseArgs() {
|
|
1105
|
-
let lastKey;
|
|
1106
|
-
return process.argv.slice(2).reduce((args, arg) => {
|
|
1107
|
-
if (arg.includes('=')) {
|
|
1108
|
-
const [key, value] = arg.split('=');
|
|
1109
|
-
args[key.substring(2)] = value;
|
|
1110
|
-
}
|
|
1111
|
-
else if (lastKey) {
|
|
1112
|
-
args[lastKey] = arg;
|
|
1113
|
-
lastKey = undefined;
|
|
1114
|
-
}
|
|
1115
|
-
else if (arg.startsWith('--')) {
|
|
1116
|
-
lastKey = arg.substring(2);
|
|
1117
|
-
}
|
|
1118
|
-
return args;
|
|
1119
|
-
}, {});
|
|
1120
|
-
}
|
|
1121
1101
|
static xor(a, b) {
|
|
1122
1102
|
return (a || b) && !(a && b);
|
|
1123
1103
|
}
|