@mikro-orm/mongodb 7.0.0-dev.42 → 7.0.0-dev.44
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/MongoConnection.d.ts +3 -2
- package/MongoConnection.js +6 -9
- package/MongoMikroORM.d.ts +5 -6
- package/MongoMikroORM.js +6 -8
- package/package.json +2 -2
package/MongoConnection.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export declare class MongoConnection extends Connection {
|
|
|
4
4
|
protected client: MongoClient;
|
|
5
5
|
protected db: Db;
|
|
6
6
|
constructor(config: Configuration, options?: ConnectionOptions, type?: ConnectionType);
|
|
7
|
-
connect(
|
|
7
|
+
connect(options?: {
|
|
8
|
+
skipOnConnect?: boolean;
|
|
9
|
+
}): Promise<void>;
|
|
8
10
|
close(force?: boolean): Promise<void>;
|
|
9
11
|
isConnected(): Promise<boolean>;
|
|
10
12
|
checkConnection(): Promise<{
|
|
@@ -20,7 +22,6 @@ export declare class MongoConnection extends Connection {
|
|
|
20
22
|
listCollections(): Promise<string[]>;
|
|
21
23
|
dropCollection(name: EntityName<AnyEntity>): Promise<boolean>;
|
|
22
24
|
mapOptions(overrides: MongoClientOptions): MongoClientOptions;
|
|
23
|
-
getClientUrl(): string;
|
|
24
25
|
getDb(): Db;
|
|
25
26
|
execute(query: string): Promise<any>;
|
|
26
27
|
find<T extends object>(collection: string, where: FilterQuery<T>, orderBy?: QueryOrderMap<T> | QueryOrderMap<T>[], limit?: number, offset?: number, fields?: string[], ctx?: Transaction<ClientSession>, loggerContext?: LoggingOptions): Promise<EntityData<T>[]>;
|
package/MongoConnection.js
CHANGED
|
@@ -15,7 +15,7 @@ export class MongoConnection extends Connection {
|
|
|
15
15
|
return `ISODate('${this.toISOString()}')`;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
async connect() {
|
|
18
|
+
async connect(options) {
|
|
19
19
|
let driverOptions = this.options.driverOptions ?? this.config.get('driverOptions');
|
|
20
20
|
if (typeof driverOptions === 'function') {
|
|
21
21
|
driverOptions = await driverOptions();
|
|
@@ -25,7 +25,7 @@ export class MongoConnection extends Connection {
|
|
|
25
25
|
this.client = driverOptions;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
this.client = new MongoClient(this.config.
|
|
28
|
+
this.client = new MongoClient(this.config.get('clientUrl'), this.mapOptions(driverOptions));
|
|
29
29
|
await this.client.connect();
|
|
30
30
|
const onCreateConnection = this.options.onCreateConnection ?? this.config.get('onCreateConnection');
|
|
31
31
|
/* v8 ignore next 3 */
|
|
@@ -35,9 +35,12 @@ export class MongoConnection extends Connection {
|
|
|
35
35
|
}
|
|
36
36
|
this.db = this.client.db(this.config.get('dbName'));
|
|
37
37
|
this.connected = true;
|
|
38
|
+
if (options?.skipOnConnect !== true) {
|
|
39
|
+
await this.onConnect();
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
async close(force) {
|
|
40
|
-
await this.client?.close(
|
|
43
|
+
await this.client?.close(force);
|
|
41
44
|
this.connected = false;
|
|
42
45
|
}
|
|
43
46
|
async isConnected() {
|
|
@@ -96,12 +99,6 @@ export class MongoConnection extends Connection {
|
|
|
96
99
|
};
|
|
97
100
|
return Utils.mergeConfig(ret, overrides);
|
|
98
101
|
}
|
|
99
|
-
getClientUrl() {
|
|
100
|
-
const options = this.mapOptions(this.options.driverOptions ?? {});
|
|
101
|
-
const clientUrl = this.config.getClientUrl(true);
|
|
102
|
-
const match = clientUrl.match(/^(\w+):\/\/((.*@.+)|.+)$/);
|
|
103
|
-
return match ? `${match[1]}://${options.auth ? options.auth.username + ':*****@' : ''}${match[2]}` : clientUrl;
|
|
104
|
-
}
|
|
105
102
|
getDb() {
|
|
106
103
|
return this.db;
|
|
107
104
|
}
|
package/MongoMikroORM.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { type AnyEntity, type EntityClass, type EntityClassGroup, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
2
2
|
import { MongoDriver } from './MongoDriver.js';
|
|
3
3
|
import type { MongoEntityManager } from './MongoEntityManager.js';
|
|
4
|
+
export type MongoOptions<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]> = Options<MongoDriver, EM, Entities>;
|
|
5
|
+
export declare function defineMongoConfig<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options: MongoOptions<EM, Entities>): Options<MongoDriver, EM, Entities>;
|
|
4
6
|
/**
|
|
5
7
|
* @inheritDoc
|
|
6
8
|
*/
|
|
7
|
-
export declare class MongoMikroORM<EM extends
|
|
8
|
-
private static DRIVER;
|
|
9
|
+
export declare class MongoMikroORM<EM extends MongoEntityManager = MongoEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]> extends MikroORM<MongoDriver, EM, any> {
|
|
9
10
|
/**
|
|
10
11
|
* @inheritDoc
|
|
11
12
|
*/
|
|
12
|
-
static init<D extends IDatabaseDriver = MongoDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options
|
|
13
|
+
static init<D extends IDatabaseDriver = MongoDriver, 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>>;
|
|
13
14
|
/**
|
|
14
15
|
* @inheritDoc
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
constructor(options: MongoOptions<EM, Entities>);
|
|
17
18
|
}
|
|
18
|
-
export type MongoOptions = Options<MongoDriver>;
|
|
19
|
-
export declare function defineMongoConfig(options: MongoOptions): Options<MongoDriver, MongoEntityManager<MongoDriver> & EntityManager<IDatabaseDriver<import("@mikro-orm/core").Connection>>, (string | EntityClass<Partial<any>> | EntityClassGroup<Partial<any>> | EntitySchema<any, never>)[]>;
|
package/MongoMikroORM.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { defineConfig, MikroORM, } from '@mikro-orm/core';
|
|
2
2
|
import { MongoDriver } from './MongoDriver.js';
|
|
3
|
+
export function defineMongoConfig(options) {
|
|
4
|
+
return defineConfig({ driver: MongoDriver, ...options });
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* @inheritDoc
|
|
5
8
|
*/
|
|
6
9
|
export class MongoMikroORM extends MikroORM {
|
|
7
|
-
static DRIVER = MongoDriver;
|
|
8
10
|
/**
|
|
9
11
|
* @inheritDoc
|
|
10
12
|
*/
|
|
11
13
|
static async init(options) {
|
|
12
|
-
return super.init(options);
|
|
14
|
+
return super.init(defineMongoConfig(options));
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* @inheritDoc
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super(defineMongoConfig(options));
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
/* v8 ignore next 3 */
|
|
22
|
-
export function defineMongoConfig(options) {
|
|
23
|
-
return defineConfig({ driver: MongoDriver, ...options });
|
|
24
|
-
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mongodb",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.44",
|
|
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",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"@mikro-orm/core": "^6.6.0"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-dev.44"
|
|
60
60
|
}
|
|
61
61
|
}
|