@mikro-orm/mongodb 7.0.0-dev.1 → 7.0.0-dev.3

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.
@@ -1,21 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoConnection = void 0;
4
- const mongodb_1 = require("mongodb");
5
- const bson_1 = require("bson");
6
- const node_util_1 = require("node:util");
7
- const core_1 = require("@mikro-orm/core");
8
- class MongoConnection extends core_1.Connection {
1
+ import { ObjectId, MongoClient, } from 'mongodb';
2
+ import { inspect } from 'node:util';
3
+ import { Connection, EventType, QueryOrder, Utils, ValidationError, } from '@mikro-orm/core';
4
+ export class MongoConnection extends Connection {
9
5
  client;
10
6
  db;
11
7
  constructor(config, options, type = 'write') {
12
8
  super(config, options, type);
13
9
  // @ts-ignore
14
- bson_1.ObjectId.prototype[node_util_1.inspect.custom] = function () {
10
+ ObjectId.prototype[inspect.custom] = function () {
15
11
  return `ObjectId('${this.toHexString()}')`;
16
12
  };
17
13
  // @ts-ignore
18
- Date.prototype[node_util_1.inspect.custom] = function () {
14
+ Date.prototype[inspect.custom] = function () {
19
15
  return `ISODate('${this.toISOString()}')`;
20
16
  };
21
17
  }
@@ -24,15 +20,15 @@ class MongoConnection extends core_1.Connection {
24
20
  if (typeof driverOptions === 'function') {
25
21
  driverOptions = await driverOptions();
26
22
  }
27
- if (driverOptions instanceof mongodb_1.MongoClient) {
23
+ if (driverOptions instanceof MongoClient) {
28
24
  this.logger.log('info', 'Reusing MongoClient provided via `driverOptions`');
29
25
  this.client = driverOptions;
30
26
  }
31
27
  else {
32
- this.client = new mongodb_1.MongoClient(this.config.getClientUrl(), this.mapOptions(driverOptions));
28
+ this.client = new MongoClient(this.config.getClientUrl(), this.mapOptions(driverOptions));
33
29
  await this.client.connect();
34
30
  const onCreateConnection = this.options.onCreateConnection ?? this.config.get('onCreateConnection');
35
- /* istanbul ignore next */
31
+ /* v8 ignore next 3 */
36
32
  this.client.on('connectionCreated', () => {
37
33
  void onCreateConnection?.(this.client);
38
34
  });
@@ -86,22 +82,19 @@ class MongoConnection extends core_1.Connection {
86
82
  const username = this.config.get('user');
87
83
  const password = this.config.get('password');
88
84
  if (this.config.get('host')) {
89
- throw new core_1.ValidationError('Mongo driver does not support `host` options, use `clientUrl` instead!');
85
+ throw new ValidationError('Mongo driver does not support `host` options, use `clientUrl` instead!');
90
86
  }
91
87
  if (username && password) {
92
88
  ret.auth = { username, password };
93
89
  }
94
- if (pool.min) {
95
- ret.minPoolSize = pool.min;
96
- }
97
- if (pool.max) {
98
- ret.maxPoolSize = pool.max;
99
- }
90
+ ret.minPoolSize = pool.min;
91
+ ret.maxPoolSize = pool.max;
92
+ ret.waitQueueTimeoutMS = pool.idleTimeoutMillis;
100
93
  ret.driverInfo = {
101
94
  name: 'MikroORM',
102
- version: core_1.Utils.getORMVersion(),
95
+ version: Utils.getORMVersion(),
103
96
  };
104
- return core_1.Utils.mergeConfig(ret, overrides);
97
+ return Utils.mergeConfig(ret, overrides);
105
98
  }
106
99
  getClientUrl() {
107
100
  const options = this.mapOptions(this.options.driverOptions ?? {});
@@ -124,13 +117,13 @@ class MongoConnection extends core_1.Connection {
124
117
  }
125
118
  const resultSet = this.getCollection(collection).find(where, options);
126
119
  let query = `db.getCollection('${collection}').find(${this.logObject(where)}, ${this.logObject(options)})`;
127
- orderBy = core_1.Utils.asArray(orderBy);
120
+ orderBy = Utils.asArray(orderBy);
128
121
  if (Array.isArray(orderBy) && orderBy.length > 0) {
129
122
  const orderByTuples = [];
130
123
  orderBy.forEach(o => {
131
- core_1.Utils.keys(o).forEach(k => {
124
+ Utils.keys(o).forEach(k => {
132
125
  const direction = o[k];
133
- orderByTuples.push([k.toString(), core_1.Utils.isString(direction) ? direction.toUpperCase() === core_1.QueryOrder.ASC ? 1 : -1 : direction]);
126
+ orderByTuples.push([k.toString(), Utils.isString(direction) ? direction.toUpperCase() === QueryOrder.ASC ? 1 : -1 : direction]);
134
127
  });
135
128
  });
136
129
  if (orderByTuples.length > 0) {
@@ -170,7 +163,7 @@ class MongoConnection extends core_1.Connection {
170
163
  async aggregate(collection, pipeline, ctx, loggerContext) {
171
164
  await this.ensureConnection();
172
165
  collection = this.getCollectionName(collection);
173
- /* istanbul ignore next */
166
+ /* v8 ignore next */
174
167
  const options = ctx ? { session: ctx } : {};
175
168
  const query = `db.getCollection('${collection}').aggregate(${this.logObject(pipeline)}, ${this.logObject(options)}).toArray();`;
176
169
  const now = Date.now();
@@ -201,27 +194,27 @@ class MongoConnection extends core_1.Connection {
201
194
  await this.ensureConnection();
202
195
  const { ctx, isolationLevel, eventBroadcaster, ...txOptions } = options;
203
196
  if (!ctx) {
204
- await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionStart);
197
+ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionStart);
205
198
  }
206
199
  const session = ctx || this.client.startSession();
207
200
  session.startTransaction(txOptions);
208
201
  this.logQuery('db.begin();');
209
- await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionStart, session);
202
+ await eventBroadcaster?.dispatchEvent(EventType.afterTransactionStart, session);
210
203
  return session;
211
204
  }
212
205
  async commit(ctx, eventBroadcaster) {
213
206
  await this.ensureConnection();
214
- await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionCommit, ctx);
207
+ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionCommit, ctx);
215
208
  await ctx.commitTransaction();
216
209
  this.logQuery('db.commit();');
217
- await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionCommit, ctx);
210
+ await eventBroadcaster?.dispatchEvent(EventType.afterTransactionCommit, ctx);
218
211
  }
219
212
  async rollback(ctx, eventBroadcaster) {
220
213
  await this.ensureConnection();
221
- await eventBroadcaster?.dispatchEvent(core_1.EventType.beforeTransactionRollback, ctx);
214
+ await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
222
215
  await ctx.abortTransaction();
223
216
  this.logQuery('db.rollback();');
224
- await eventBroadcaster?.dispatchEvent(core_1.EventType.afterTransactionRollback, ctx);
217
+ await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
225
218
  }
226
219
  async runQuery(method, collection, data, where, ctx, upsert, upsertOptions, loggerContext) {
227
220
  await this.ensureConnection();
@@ -257,10 +250,10 @@ class MongoConnection extends core_1.Connection {
257
250
  const bulk = this.getCollection(collection).initializeUnorderedBulkOp(options);
258
251
  data.forEach((row, idx) => {
259
252
  const id = where[idx];
260
- const cond = core_1.Utils.isPlainObject(id) ? id : { _id: id };
253
+ const cond = Utils.isPlainObject(id) ? id : { _id: id };
261
254
  const doc = this.createUpdatePayload(row, upsertOptions);
262
255
  if (upsert) {
263
- if (core_1.Utils.isEmpty(cond)) {
256
+ if (Utils.isEmpty(cond)) {
264
257
  query += log(() => `bulk.insert(${this.logObject(row)});\n`);
265
258
  bulk.insert(row);
266
259
  }
@@ -299,7 +292,7 @@ class MongoConnection extends core_1.Connection {
299
292
  createUpdatePayload(row, upsertOptions) {
300
293
  const doc = { $set: row };
301
294
  const $unset = {};
302
- core_1.Utils.keys(row)
295
+ Utils.keys(row)
303
296
  .filter(k => typeof row[k] === 'undefined')
304
297
  .forEach(k => {
305
298
  $unset[k] = '';
@@ -328,9 +321,9 @@ class MongoConnection extends core_1.Connection {
328
321
  });
329
322
  }
330
323
  }
331
- if (core_1.Utils.hasObjectKeys($unset)) {
324
+ if (Utils.hasObjectKeys($unset)) {
332
325
  doc.$unset = $unset;
333
- if (!core_1.Utils.hasObjectKeys(doc.$set)) {
326
+ if (!Utils.hasObjectKeys(doc.$set)) {
334
327
  delete doc.$set;
335
328
  }
336
329
  }
@@ -344,7 +337,7 @@ class MongoConnection extends core_1.Connection {
344
337
  };
345
338
  }
346
339
  getCollectionName(name) {
347
- name = core_1.Utils.className(name);
340
+ name = Utils.className(name);
348
341
  const meta = this.metadata.find(name);
349
342
  return meta ? meta.collection : name;
350
343
  }
@@ -352,7 +345,6 @@ class MongoConnection extends core_1.Connection {
352
345
  if (o.session) {
353
346
  o = { ...o, session: `[ClientSession]` };
354
347
  }
355
- return (0, node_util_1.inspect)(o, { depth: 5, compact: true, breakLength: 300 });
348
+ return inspect(o, { depth: 5, compact: true, breakLength: 300 });
356
349
  }
357
350
  }
358
- exports.MongoConnection = MongoConnection;
package/MongoDriver.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import type { ClientSession } from 'mongodb';
2
- import { type Configuration, type CountOptions, DatabaseDriver, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type FilterQuery, type FindOneOptions, type FindOptions, type IDatabaseDriver, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type PopulateOptions, type PopulatePath, type QueryResult, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
3
- import { MongoConnection } from './MongoConnection';
4
- import { MongoPlatform } from './MongoPlatform';
5
- import { MongoEntityManager } from './MongoEntityManager';
1
+ import { type ClientSession } from 'mongodb';
2
+ import { type Configuration, type CountOptions, DatabaseDriver, type EntityData, type EntityDictionary, type EntityField, EntityManagerType, type FilterQuery, type FindOneOptions, type FindOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type PopulateOptions, type PopulatePath, type QueryResult, type Transaction, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
3
+ import { MongoConnection } from './MongoConnection.js';
4
+ import { MongoPlatform } from './MongoPlatform.js';
5
+ import { MongoEntityManager } from './MongoEntityManager.js';
6
6
  export declare class MongoDriver extends DatabaseDriver<MongoConnection> {
7
7
  [EntityManagerType]: MongoEntityManager<this>;
8
8
  protected readonly connection: MongoConnection;
9
9
  protected readonly platform: MongoPlatform;
10
10
  constructor(config: Configuration);
11
- createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
11
+ createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
12
12
  find<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P, F, E>): Promise<EntityData<T>[]>;
13
13
  findOne<T extends object, P extends string = never, F extends string = PopulatePath.ALL, E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
14
14
  findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
package/MongoDriver.js CHANGED
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoDriver = void 0;
4
- const bson_1 = require("bson");
5
- const core_1 = require("@mikro-orm/core");
6
- const MongoConnection_1 = require("./MongoConnection");
7
- const MongoPlatform_1 = require("./MongoPlatform");
8
- const MongoEntityManager_1 = require("./MongoEntityManager");
9
- class MongoDriver extends core_1.DatabaseDriver {
10
- [core_1.EntityManagerType];
11
- connection = new MongoConnection_1.MongoConnection(this.config);
12
- platform = new MongoPlatform_1.MongoPlatform();
1
+ import { ObjectId } from 'mongodb';
2
+ import { DatabaseDriver, EntityManagerType, ReferenceKind, Utils, } from '@mikro-orm/core';
3
+ import { MongoConnection } from './MongoConnection.js';
4
+ import { MongoPlatform } from './MongoPlatform.js';
5
+ import { MongoEntityManager } from './MongoEntityManager.js';
6
+ export class MongoDriver extends DatabaseDriver {
7
+ [EntityManagerType];
8
+ connection = new MongoConnection(this.config);
9
+ platform = new MongoPlatform();
13
10
  constructor(config) {
14
11
  super(config, ['mongodb']);
15
12
  }
16
13
  createEntityManager(useContext) {
17
- const EntityManagerClass = this.config.get('entityManager', MongoEntityManager_1.MongoEntityManager);
14
+ const EntityManagerClass = this.config.get('entityManager', MongoEntityManager);
18
15
  return new EntityManagerClass(this.config, this, this.metadata, useContext);
19
16
  }
20
17
  async find(entityName, where, options = {}) {
@@ -27,10 +24,10 @@ class MongoDriver extends core_1.DatabaseDriver {
27
24
  const isCursorPagination = [first, last, before, after].some(v => v != null);
28
25
  if (isCursorPagination) {
29
26
  const andWhere = (cond1, cond2) => {
30
- if (core_1.Utils.isEmpty(cond1)) {
27
+ if (Utils.isEmpty(cond1)) {
31
28
  return cond2;
32
29
  }
33
- if (core_1.Utils.isEmpty(cond2)) {
30
+ if (Utils.isEmpty(cond2)) {
34
31
  return cond1;
35
32
  }
36
33
  return { $and: [cond1, cond2] };
@@ -38,29 +35,29 @@ class MongoDriver extends core_1.DatabaseDriver {
38
35
  const meta = this.metadata.find(entityName);
39
36
  const { orderBy: newOrderBy, where: newWhere } = this.processCursorOptions(meta, options, options.orderBy);
40
37
  const newWhereConverted = this.renameFields(entityName, newWhere, true);
41
- const orderBy = core_1.Utils.asArray(newOrderBy).map(order => this.renameFields(entityName, order, true));
38
+ const orderBy = Utils.asArray(newOrderBy).map(order => this.renameFields(entityName, order, true));
42
39
  const res = await this.rethrow(this.getConnection('read').find(entityName, andWhere(where, newWhereConverted), orderBy, options.limit, options.offset, fields, options.ctx, options.logging));
43
40
  if (isCursorPagination && !first && !!last) {
44
41
  res.reverse();
45
42
  }
46
43
  return res.map(r => this.mapResult(r, this.metadata.find(entityName)));
47
44
  }
48
- const orderBy = core_1.Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy, true));
45
+ const orderBy = Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy, true));
49
46
  const res = await this.rethrow(this.getConnection('read').find(entityName, where, orderBy, options.limit, options.offset, fields, options.ctx));
50
47
  return res.map(r => this.mapResult(r, this.metadata.find(entityName)));
51
48
  }
52
49
  async findOne(entityName, where, options = { populate: [], orderBy: {} }) {
53
50
  if (this.metadata.find(entityName)?.virtual) {
54
51
  const [item] = await this.findVirtual(entityName, where, options);
55
- /* istanbul ignore next */
52
+ /* v8 ignore next */
56
53
  return item ?? null;
57
54
  }
58
- if (core_1.Utils.isPrimaryKey(where)) {
55
+ if (Utils.isPrimaryKey(where)) {
59
56
  where = this.buildFilterById(entityName, where);
60
57
  }
61
58
  const fields = this.buildFields(entityName, options.populate || [], options.fields, options.exclude);
62
59
  where = this.renameFields(entityName, where, true);
63
- const orderBy = core_1.Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy, true));
60
+ const orderBy = Utils.asArray(options.orderBy).map(orderBy => this.renameFields(entityName, orderBy, true));
64
61
  const res = await this.rethrow(this.getConnection('read').find(entityName, where, orderBy, 1, undefined, fields, options.ctx, options.logging));
65
62
  return this.mapResult(res[0], this.metadata.find(entityName));
66
63
  }
@@ -70,11 +67,11 @@ class MongoDriver extends core_1.DatabaseDriver {
70
67
  const em = this.createEntityManager();
71
68
  return meta.expression(em, where, options);
72
69
  }
73
- /* istanbul ignore next */
70
+ /* v8 ignore next */
74
71
  return super.findVirtual(entityName, where, options);
75
72
  }
76
73
  async count(entityName, where, options = {}, ctx) {
77
- /* istanbul ignore next */
74
+ /* v8 ignore next 3 */
78
75
  if (this.metadata.find(entityName)?.virtual) {
79
76
  return this.countVirtual(entityName, where, options);
80
77
  }
@@ -88,21 +85,21 @@ class MongoDriver extends core_1.DatabaseDriver {
88
85
  async nativeInsertMany(entityName, data, options = {}) {
89
86
  data = data.map(d => this.renameFields(entityName, d));
90
87
  const meta = this.metadata.find(entityName);
91
- /* istanbul ignore next */
88
+ /* v8 ignore next */
92
89
  const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
93
90
  const res = await this.rethrow(this.getConnection('write').insertMany(entityName, data, options.ctx));
94
91
  res.rows = res.insertedIds.map(id => ({ [pk]: id }));
95
92
  return res;
96
93
  }
97
94
  async nativeUpdate(entityName, where, data, options = {}) {
98
- if (core_1.Utils.isPrimaryKey(where)) {
95
+ if (Utils.isPrimaryKey(where)) {
99
96
  where = this.buildFilterById(entityName, where);
100
97
  }
101
98
  where = this.renameFields(entityName, where, true);
102
99
  data = this.renameFields(entityName, data);
103
100
  options = { ...options };
104
101
  const meta = this.metadata.find(entityName);
105
- /* istanbul ignore next */
102
+ /* v8 ignore next */
106
103
  const rename = (field) => meta ? (meta.properties[field]?.fieldNames[0] ?? field) : field;
107
104
  if (options.onConflictFields && Array.isArray(options.onConflictFields)) {
108
105
  options.onConflictFields = options.onConflictFields.map(rename);
@@ -117,7 +114,7 @@ class MongoDriver extends core_1.DatabaseDriver {
117
114
  }
118
115
  async nativeUpdateMany(entityName, where, data, options = {}) {
119
116
  where = where.map(row => {
120
- if (core_1.Utils.isPlainObject(row)) {
117
+ if (Utils.isPlainObject(row)) {
121
118
  return this.renameFields(entityName, row, true);
122
119
  }
123
120
  return row;
@@ -125,7 +122,7 @@ class MongoDriver extends core_1.DatabaseDriver {
125
122
  data = data.map(row => this.renameFields(entityName, row));
126
123
  options = { ...options };
127
124
  const meta = this.metadata.find(entityName);
128
- /* istanbul ignore next */
125
+ /* v8 ignore next */
129
126
  const rename = (field) => meta ? (meta.properties[field]?.fieldNames[0] ?? field) : field;
130
127
  if (options.onConflictFields && Array.isArray(options.onConflictFields)) {
131
128
  options.onConflictFields = options.onConflictFields.map(rename);
@@ -136,13 +133,13 @@ class MongoDriver extends core_1.DatabaseDriver {
136
133
  if (options.onConflictExcludeFields) {
137
134
  options.onConflictExcludeFields = options.onConflictExcludeFields.map(rename);
138
135
  }
139
- /* istanbul ignore next */
136
+ /* v8 ignore next */
140
137
  const pk = meta?.getPrimaryProps()[0].fieldNames[0] ?? '_id';
141
138
  const res = await this.rethrow(this.getConnection('write').bulkUpdateMany(entityName, where, data, options.ctx, options.upsert, options));
142
139
  if (res.insertedIds) {
143
140
  let i = 0;
144
141
  res.rows = where.map(cond => {
145
- if (core_1.Utils.isEmpty(cond)) {
142
+ if (Utils.isEmpty(cond)) {
146
143
  return { [pk]: res.insertedIds[i++] };
147
144
  }
148
145
  return { [pk]: cond[pk] };
@@ -151,7 +148,7 @@ class MongoDriver extends core_1.DatabaseDriver {
151
148
  return res;
152
149
  }
153
150
  async nativeDelete(entityName, where, options = {}) {
154
- if (core_1.Utils.isPrimaryKey(where)) {
151
+ if (Utils.isPrimaryKey(where)) {
155
152
  where = this.buildFilterById(entityName, where);
156
153
  }
157
154
  where = this.renameFields(entityName, where, true);
@@ -168,7 +165,7 @@ class MongoDriver extends core_1.DatabaseDriver {
168
165
  const copiedData = Object.assign({}, data); // copy first
169
166
  const meta = this.metadata.find(entityName);
170
167
  if (meta?.serializedPrimaryKey && !meta.embeddable && meta.serializedPrimaryKey !== meta.primaryKeys[0]) {
171
- core_1.Utils.renameKey(copiedData, meta.serializedPrimaryKey, meta.primaryKeys[0]);
168
+ Utils.renameKey(copiedData, meta.serializedPrimaryKey, meta.primaryKeys[0]);
172
169
  }
173
170
  if (meta && !meta.embeddable) {
174
171
  this.inlineEmbeddables(meta, copiedData, dotPaths);
@@ -179,7 +176,7 @@ class MongoDriver extends core_1.DatabaseDriver {
179
176
  for (let i = 0; i < copiedData.$and.length; i++) {
180
177
  const and = copiedData.$and[i];
181
178
  if ('$fulltext' in and) {
182
- /* istanbul ignore next */
179
+ /* v8 ignore next 3 */
183
180
  if ('$fulltext' in copiedData) {
184
181
  throw new Error('Cannot merge multiple $fulltext conditions to top level of the query object.');
185
182
  }
@@ -195,12 +192,12 @@ class MongoDriver extends core_1.DatabaseDriver {
195
192
  }
196
193
  // mongo only allows the $text operator in the root of the object and will
197
194
  // search all documents where the field has a text index.
198
- if (core_1.Utils.hasNestedKey(copiedData, '$fulltext')) {
195
+ if (Utils.hasNestedKey(copiedData, '$fulltext')) {
199
196
  throw new Error('Full text search is only supported on the top level of the query object.');
200
197
  }
201
- core_1.Utils.keys(copiedData).forEach(k => {
202
- if (core_1.Utils.isGroupOperator(k)) {
203
- /* istanbul ignore else */
198
+ Utils.keys(copiedData).forEach(k => {
199
+ if (Utils.isGroupOperator(k)) {
200
+ /* v8 ignore next 5 */
204
201
  if (Array.isArray(copiedData[k])) {
205
202
  copiedData[k] = copiedData[k].map(v => this.renameFields(entityName, v));
206
203
  }
@@ -212,10 +209,10 @@ class MongoDriver extends core_1.DatabaseDriver {
212
209
  if (meta?.properties[k]) {
213
210
  const prop = meta.properties[k];
214
211
  let isObjectId = false;
215
- if (prop.kind === core_1.ReferenceKind.SCALAR) {
212
+ if (prop.kind === ReferenceKind.SCALAR) {
216
213
  isObjectId = prop.type.toLowerCase() === 'objectid';
217
214
  }
218
- else if (prop.kind === core_1.ReferenceKind.EMBEDDED) {
215
+ else if (prop.kind === ReferenceKind.EMBEDDED) {
219
216
  if (copiedData[prop.name] == null) {
220
217
  return;
221
218
  }
@@ -235,26 +232,26 @@ class MongoDriver extends core_1.DatabaseDriver {
235
232
  copiedData[k] = this.convertObjectIds(copiedData[k]);
236
233
  }
237
234
  if (prop.fieldNames) {
238
- core_1.Utils.renameKey(copiedData, k, prop.fieldNames[0]);
235
+ Utils.renameKey(copiedData, k, prop.fieldNames[0]);
239
236
  }
240
237
  }
241
- if (core_1.Utils.isPlainObject(copiedData[k]) && '$re' in copiedData[k]) {
238
+ if (Utils.isPlainObject(copiedData[k]) && '$re' in copiedData[k]) {
242
239
  copiedData[k] = new RegExp(copiedData[k].$re);
243
240
  }
244
241
  });
245
242
  return copiedData;
246
243
  }
247
244
  convertObjectIds(data) {
248
- if (data instanceof bson_1.ObjectId) {
245
+ if (data instanceof ObjectId) {
249
246
  return data;
250
247
  }
251
- if (core_1.Utils.isString(data) && data.match(/^[0-9a-f]{24}$/i)) {
252
- return new bson_1.ObjectId(data);
248
+ if (Utils.isString(data) && data.match(/^[0-9a-f]{24}$/i)) {
249
+ return new ObjectId(data);
253
250
  }
254
251
  if (Array.isArray(data)) {
255
252
  return data.map((item) => this.convertObjectIds(item));
256
253
  }
257
- if (core_1.Utils.isObject(data)) {
254
+ if (Utils.isObject(data)) {
258
255
  Object.keys(data).forEach(k => {
259
256
  data[k] = this.convertObjectIds(data[k]);
260
257
  });
@@ -264,7 +261,7 @@ class MongoDriver extends core_1.DatabaseDriver {
264
261
  buildFilterById(entityName, id) {
265
262
  const meta = this.metadata.find(entityName);
266
263
  if (meta.properties[meta.primaryKeys[0]].type.toLowerCase() === 'objectid') {
267
- return { _id: new bson_1.ObjectId(id) };
264
+ return { _id: new ObjectId(id) };
268
265
  }
269
266
  return { _id: id };
270
267
  }
@@ -277,15 +274,15 @@ class MongoDriver extends core_1.DatabaseDriver {
277
274
  const ret = [];
278
275
  if (fields) {
279
276
  for (let field of fields) {
280
- /* istanbul ignore next */
281
- if (core_1.Utils.isPlainObject(field)) {
277
+ /* v8 ignore next 3 */
278
+ if (Utils.isPlainObject(field)) {
282
279
  continue;
283
280
  }
284
281
  if (field.toString().includes('.')) {
285
282
  field = field.toString().substring(0, field.toString().indexOf('.'));
286
283
  }
287
284
  let prop = meta.properties[field];
288
- /* istanbul ignore else */
285
+ /* v8 ignore start */
289
286
  if (prop) {
290
287
  if (!prop.fieldNames) {
291
288
  continue;
@@ -295,19 +292,19 @@ class MongoDriver extends core_1.DatabaseDriver {
295
292
  }
296
293
  else if (field === '*') {
297
294
  const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate));
298
- ret.push(...core_1.Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames)));
295
+ ret.push(...Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames)));
299
296
  }
300
297
  else {
301
298
  ret.push(field);
302
299
  }
300
+ /* v8 ignore stop */
303
301
  }
304
302
  ret.unshift(...meta.primaryKeys.filter(pk => !fields.includes(pk)));
305
303
  }
306
- else if (!core_1.Utils.isEmpty(exclude) || lazyProps.some(p => !p.formula)) {
304
+ else if (!Utils.isEmpty(exclude) || lazyProps.some(p => !p.formula)) {
307
305
  const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, exclude));
308
- ret.push(...core_1.Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames)));
306
+ ret.push(...Utils.flatten(props.filter(p => !lazyProps.includes(p)).map(p => p.fieldNames)));
309
307
  }
310
308
  return ret.length > 0 ? ret : undefined;
311
309
  }
312
310
  }
313
- exports.MongoDriver = MongoDriver;
@@ -1,7 +1,7 @@
1
1
  import { EntityManager, type EntityName, type EntityRepository, type GetRepository, type TransactionOptions } from '@mikro-orm/core';
2
2
  import type { Collection, Document, TransactionOptions as MongoTransactionOptions } from 'mongodb';
3
- import type { MongoDriver } from './MongoDriver';
4
- import type { MongoEntityRepository } from './MongoEntityRepository';
3
+ import type { MongoDriver } from './MongoDriver.js';
4
+ import type { MongoEntityRepository } from './MongoEntityRepository.js';
5
5
  /**
6
6
  * @inheritDoc
7
7
  */
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoEntityManager = void 0;
4
- const core_1 = require("@mikro-orm/core");
1
+ import { EntityManager, Utils } from '@mikro-orm/core';
5
2
  /**
6
3
  * @inheritDoc
7
4
  */
8
- class MongoEntityManager extends core_1.EntityManager {
5
+ export class MongoEntityManager extends EntityManager {
9
6
  /**
10
7
  * Shortcut to driver's aggregate method. Available in MongoDriver only.
11
8
  */
12
9
  async aggregate(entityName, pipeline) {
13
- entityName = core_1.Utils.className(entityName);
10
+ entityName = Utils.className(entityName);
14
11
  return this.getDriver().aggregate(entityName, pipeline);
15
12
  }
16
13
  getCollection(entityName) {
@@ -35,4 +32,3 @@ class MongoEntityManager extends core_1.EntityManager {
35
32
  return super.transactional(cb, options);
36
33
  }
37
34
  }
38
- exports.MongoEntityManager = MongoEntityManager;
@@ -1,6 +1,6 @@
1
1
  import { EntityRepository, type EntityName } from '@mikro-orm/core';
2
2
  import type { Collection } from 'mongodb';
3
- import type { MongoEntityManager } from './MongoEntityManager';
3
+ import type { MongoEntityManager } from './MongoEntityManager.js';
4
4
  export declare class MongoEntityRepository<T extends object> extends EntityRepository<T> {
5
5
  protected readonly em: MongoEntityManager;
6
6
  constructor(em: MongoEntityManager, entityName: EntityName<T>);
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoEntityRepository = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- class MongoEntityRepository extends core_1.EntityRepository {
1
+ import { EntityRepository } from '@mikro-orm/core';
2
+ export class MongoEntityRepository extends EntityRepository {
6
3
  em;
7
4
  constructor(em, entityName) {
8
5
  super(em, entityName);
@@ -24,4 +21,3 @@ class MongoEntityRepository extends core_1.EntityRepository {
24
21
  return this.em;
25
22
  }
26
23
  }
27
- exports.MongoEntityRepository = MongoEntityRepository;
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoExceptionConverter = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- class MongoExceptionConverter extends core_1.ExceptionConverter {
6
- /* istanbul ignore next */
1
+ import { UniqueConstraintViolationException, ExceptionConverter, TableExistsException } from '@mikro-orm/core';
2
+ /* v8 ignore start */
3
+ export class MongoExceptionConverter extends ExceptionConverter {
7
4
  /**
8
5
  * @link https://gist.github.com/rluvaton/a97a8da46ab6541a3e5702e83b9d357b
9
6
  */
10
7
  convertException(exception) {
11
8
  switch (exception.code) {
12
9
  case 48:
13
- return new core_1.TableExistsException(exception);
10
+ return new TableExistsException(exception);
14
11
  case 11000:
15
- return new core_1.UniqueConstraintViolationException(exception);
12
+ return new UniqueConstraintViolationException(exception);
16
13
  }
17
14
  return super.convertException(exception);
18
15
  }
19
16
  }
20
- exports.MongoExceptionConverter = MongoExceptionConverter;
17
+ /* v8 ignore stop */
@@ -1,6 +1,6 @@
1
1
  import { MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
2
- import { MongoDriver } from './MongoDriver';
3
- import type { MongoEntityManager } from './MongoEntityManager';
2
+ import { MongoDriver } from './MongoDriver.js';
3
+ import type { MongoEntityManager } from './MongoEntityManager.js';
4
4
  /**
5
5
  * @inheritDoc
6
6
  */
package/MongoMikroORM.js CHANGED
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoMikroORM = void 0;
4
- exports.defineMongoConfig = defineMongoConfig;
5
- const core_1 = require("@mikro-orm/core");
6
- const MongoDriver_1 = require("./MongoDriver");
1
+ import { defineConfig, MikroORM, } from '@mikro-orm/core';
2
+ import { MongoDriver } from './MongoDriver.js';
7
3
  /**
8
4
  * @inheritDoc
9
5
  */
10
- class MongoMikroORM extends core_1.MikroORM {
11
- static DRIVER = MongoDriver_1.MongoDriver;
6
+ export class MongoMikroORM extends MikroORM {
7
+ static DRIVER = MongoDriver;
12
8
  /**
13
9
  * @inheritDoc
14
10
  */
@@ -22,8 +18,7 @@ class MongoMikroORM extends core_1.MikroORM {
22
18
  return super.initSync(options);
23
19
  }
24
20
  }
25
- exports.MongoMikroORM = MongoMikroORM;
26
- /* istanbul ignore next */
27
- function defineMongoConfig(options) {
28
- return (0, core_1.defineConfig)({ driver: MongoDriver_1.MongoDriver, ...options });
21
+ /* v8 ignore next 3 */
22
+ export function defineMongoConfig(options) {
23
+ return defineConfig({ driver: MongoDriver, ...options });
29
24
  }
@@ -1,7 +1,7 @@
1
- import { ObjectId } from 'bson';
1
+ import { ObjectId } from 'mongodb';
2
2
  import { Platform, type IPrimaryKey, type Primary, type NamingStrategy, type Constructor, type EntityRepository, type EntityProperty, type PopulateOptions, type EntityMetadata, type IDatabaseDriver, type EntityManager, type Configuration, type MikroORM } from '@mikro-orm/core';
3
- import { MongoExceptionConverter } from './MongoExceptionConverter';
4
- import { MongoSchemaGenerator } from './MongoSchemaGenerator';
3
+ import { MongoExceptionConverter } from './MongoExceptionConverter.js';
4
+ import { MongoSchemaGenerator } from './MongoSchemaGenerator.js';
5
5
  export declare class MongoPlatform extends Platform {
6
6
  protected readonly exceptionConverter: MongoExceptionConverter;
7
7
  setConfig(config: Configuration): void;
package/MongoPlatform.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoPlatform = void 0;
4
- const bson_1 = require("bson");
5
- const core_1 = require("@mikro-orm/core");
6
- const MongoExceptionConverter_1 = require("./MongoExceptionConverter");
7
- const MongoEntityRepository_1 = require("./MongoEntityRepository");
8
- const MongoSchemaGenerator_1 = require("./MongoSchemaGenerator");
9
- class MongoPlatform extends core_1.Platform {
10
- exceptionConverter = new MongoExceptionConverter_1.MongoExceptionConverter();
1
+ import { ObjectId } from 'mongodb';
2
+ import { Platform, MongoNamingStrategy, Utils, ReferenceKind, MetadataError, } from '@mikro-orm/core';
3
+ import { MongoExceptionConverter } from './MongoExceptionConverter.js';
4
+ import { MongoEntityRepository } from './MongoEntityRepository.js';
5
+ import { MongoSchemaGenerator } from './MongoSchemaGenerator.js';
6
+ export class MongoPlatform extends Platform {
7
+ exceptionConverter = new MongoExceptionConverter();
11
8
  setConfig(config) {
12
9
  config.set('autoJoinOneToOneOwner', false);
13
10
  config.set('loadStrategy', 'select-in');
@@ -15,14 +12,14 @@ class MongoPlatform extends core_1.Platform {
15
12
  super.setConfig(config);
16
13
  }
17
14
  getNamingStrategy() {
18
- return core_1.MongoNamingStrategy;
15
+ return MongoNamingStrategy;
19
16
  }
20
17
  getRepositoryClass() {
21
- return MongoEntityRepository_1.MongoEntityRepository;
18
+ return MongoEntityRepository;
22
19
  }
23
20
  /** @inheritDoc */
24
21
  lookupExtensions(orm) {
25
- MongoSchemaGenerator_1.MongoSchemaGenerator.register(orm);
22
+ MongoSchemaGenerator.register(orm);
26
23
  }
27
24
  /** @inheritDoc */
28
25
  getExtension(extensionName, extensionKey, moduleName, em) {
@@ -32,21 +29,21 @@ class MongoPlatform extends core_1.Platform {
32
29
  if (extensionName === 'Migrator') {
33
30
  return super.getExtension('Migrator', '@mikro-orm/migrator', '@mikro-orm/migrations-mongodb', em);
34
31
  }
35
- /* istanbul ignore next */
32
+ /* v8 ignore next */
36
33
  return super.getExtension(extensionName, extensionKey, moduleName, em);
37
34
  }
38
- /* istanbul ignore next: kept for type inference only */
35
+ /* v8 ignore next 3: kept for type inference only */
39
36
  getSchemaGenerator(driver, em) {
40
- return new MongoSchemaGenerator_1.MongoSchemaGenerator(em ?? driver);
37
+ return new MongoSchemaGenerator(em ?? driver);
41
38
  }
42
39
  normalizePrimaryKey(data) {
43
- if (data instanceof bson_1.ObjectId) {
40
+ if (Utils.isObjectID(data)) {
44
41
  return data.toHexString();
45
42
  }
46
43
  return data;
47
44
  }
48
45
  denormalizePrimaryKey(data) {
49
- return new bson_1.ObjectId(data);
46
+ return new ObjectId(data);
50
47
  }
51
48
  getSerializedPrimaryKeyField(field) {
52
49
  return 'id';
@@ -61,7 +58,7 @@ class MongoPlatform extends core_1.Platform {
61
58
  return true;
62
59
  }
63
60
  convertJsonToDatabaseValue(value) {
64
- return core_1.Utils.copy(value);
61
+ return Utils.copy(value);
65
62
  }
66
63
  convertJsonToJSValue(value, prop) {
67
64
  return value;
@@ -71,19 +68,19 @@ class MongoPlatform extends core_1.Platform {
71
68
  }
72
69
  cloneEmbeddable(data) {
73
70
  const ret = super.cloneEmbeddable(data);
74
- core_1.Utils.dropUndefinedProperties(ret);
71
+ Utils.dropUndefinedProperties(ret);
75
72
  return ret;
76
73
  }
77
74
  shouldHaveColumn(prop, populate, exclude) {
78
75
  if (super.shouldHaveColumn(prop, populate, exclude)) {
79
76
  return true;
80
77
  }
81
- return prop.kind === core_1.ReferenceKind.MANY_TO_MANY && prop.owner;
78
+ return prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner;
82
79
  }
83
80
  validateMetadata(meta) {
84
81
  const pk = meta.getPrimaryProps()[0];
85
82
  if (pk && pk.fieldNames?.[0] !== '_id') {
86
- throw core_1.MetadataError.invalidPrimaryKey(meta, pk, '_id');
83
+ throw MetadataError.invalidPrimaryKey(meta, pk, '_id');
87
84
  }
88
85
  }
89
86
  isAllowedTopLevelOperator(operator) {
@@ -93,4 +90,3 @@ class MongoPlatform extends core_1.Platform {
93
90
  return 'mongodb://127.0.0.1:27017';
94
91
  }
95
92
  }
96
- exports.MongoPlatform = MongoPlatform;
@@ -1,5 +1,5 @@
1
1
  import { AbstractSchemaGenerator, type CreateSchemaOptions, type MikroORM } from '@mikro-orm/core';
2
- import type { MongoDriver } from './MongoDriver';
2
+ import type { MongoDriver } from './MongoDriver.js';
3
3
  export declare class MongoSchemaGenerator extends AbstractSchemaGenerator<MongoDriver> {
4
4
  static register(orm: MikroORM): void;
5
5
  createSchema(options?: MongoCreateSchemaOptions): Promise<void>;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoSchemaGenerator = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
1
+ import { AbstractSchemaGenerator, Utils, } from '@mikro-orm/core';
2
+ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
6
3
  static register(orm) {
7
4
  orm.config.registerExtension('@mikro-orm/schema-generator', () => new MongoSchemaGenerator(orm.em));
8
5
  }
@@ -11,7 +8,7 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
11
8
  const existing = await this.connection.listCollections();
12
9
  const metadata = this.getOrderedMetadata();
13
10
  metadata.push({ collection: this.config.get('migrations').tableName });
14
- /* istanbul ignore next */
11
+ /* v8 ignore start */
15
12
  const promises = metadata
16
13
  .filter(meta => !existing.includes(meta.collection))
17
14
  .map(meta => this.connection.createCollection(meta.collection).catch(err => {
@@ -21,6 +18,7 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
21
18
  throw err;
22
19
  }
23
20
  }));
21
+ /* v8 ignore stop */
24
22
  if (options.ensureIndexes) {
25
23
  await this.ensureIndexes({ ensureCollections: false });
26
24
  }
@@ -60,8 +58,8 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
60
58
  }
61
59
  const indexes = await db.collection(collection.name).listIndexes().toArray();
62
60
  for (const index of indexes) {
63
- const isIdIndex = index.key._id === 1 && core_1.Utils.getObjectKeysSize(index.key) === 1;
64
- /* istanbul ignore next */
61
+ const isIdIndex = index.key._id === 1 && Utils.getObjectKeysSize(index.key) === 1;
62
+ /* v8 ignore next 3 */
65
63
  if (!isIdIndex && !options?.skipIndexes?.find(idx => idx.collection === collection.name && idx.indexName === index.name)) {
66
64
  promises.push(db.collection(collection.name).dropIndex(index.name));
67
65
  }
@@ -118,7 +116,7 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
118
116
  const res = [];
119
117
  meta.indexes.forEach(index => {
120
118
  let fieldOrSpec;
121
- const properties = core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => meta.properties[prop].fieldNames));
119
+ const properties = Utils.flatten(Utils.asArray(index.properties).map(prop => meta.properties[prop].fieldNames));
122
120
  const collection = this.connection.getCollection(meta.className);
123
121
  if (Array.isArray(index.options) && index.options.length === 2 && properties.length === 0) {
124
122
  res.push([collection.collectionName, collection.createIndex(index.options[0], index.options[1])]);
@@ -150,7 +148,7 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
150
148
  createUniqueIndexes(meta) {
151
149
  const res = [];
152
150
  meta.uniques.forEach(index => {
153
- const properties = core_1.Utils.flatten(core_1.Utils.asArray(index.properties).map(prop => meta.properties[prop].fieldNames));
151
+ const properties = Utils.flatten(Utils.asArray(index.properties).map(prop => meta.properties[prop].fieldNames));
154
152
  const fieldOrSpec = properties.reduce((o, i) => { o[i] = 1; return o; }, {});
155
153
  const collection = this.connection.getCollection(meta.className);
156
154
  res.push([collection.collectionName, collection.createIndex(fieldOrSpec, {
@@ -170,10 +168,9 @@ class MongoSchemaGenerator extends core_1.AbstractSchemaGenerator {
170
168
  ? prop.embeddedPath.join('.')
171
169
  : prop.fieldNames.reduce((o, i) => { o[i] = 1; return o; }, {});
172
170
  return [[collection.collectionName, collection.createIndex(fieldOrSpec, {
173
- name: (core_1.Utils.isString(prop[type]) ? prop[type] : undefined),
171
+ name: (Utils.isString(prop[type]) ? prop[type] : undefined),
174
172
  unique: type === 'unique',
175
173
  sparse: prop.nullable === true,
176
174
  })]];
177
175
  }
178
176
  }
179
- exports.MongoSchemaGenerator = MongoSchemaGenerator;
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export * from './MongoConnection';
2
- export * from './MongoDriver';
3
- export * from './MongoPlatform';
4
- export * from './MongoEntityManager';
5
- export * from './MongoEntityRepository';
6
- export * from './MongoSchemaGenerator';
7
- export { MongoEntityManager as EntityManager } from './MongoEntityManager';
8
- export { MongoEntityRepository as EntityRepository } from './MongoEntityRepository';
9
- export { MongoMikroORM as MikroORM, MongoOptions as Options, defineMongoConfig as defineConfig, } from './MongoMikroORM';
10
- export { ObjectId } from 'bson';
11
1
  export * from '@mikro-orm/core';
2
+ export { ObjectId } from 'mongodb';
3
+ export * from './MongoConnection.js';
4
+ export * from './MongoDriver.js';
5
+ export * from './MongoPlatform.js';
6
+ export * from './MongoEntityManager.js';
7
+ export * from './MongoEntityRepository.js';
8
+ export * from './MongoSchemaGenerator.js';
9
+ export { MongoEntityManager as EntityManager } from './MongoEntityManager.js';
10
+ export { MongoEntityRepository as EntityRepository } from './MongoEntityRepository.js';
11
+ export { MongoMikroORM as MikroORM, MongoOptions as Options, defineMongoConfig as defineConfig, } from './MongoMikroORM.js';
package/index.js CHANGED
@@ -1,34 +1,11 @@
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
- exports.ObjectId = exports.defineConfig = exports.MikroORM = exports.EntityRepository = exports.EntityManager = void 0;
18
- /* istanbul ignore file */
19
- __exportStar(require("./MongoConnection"), exports);
20
- __exportStar(require("./MongoDriver"), exports);
21
- __exportStar(require("./MongoPlatform"), exports);
22
- __exportStar(require("./MongoEntityManager"), exports);
23
- __exportStar(require("./MongoEntityRepository"), exports);
24
- __exportStar(require("./MongoSchemaGenerator"), exports);
25
- var MongoEntityManager_1 = require("./MongoEntityManager");
26
- Object.defineProperty(exports, "EntityManager", { enumerable: true, get: function () { return MongoEntityManager_1.MongoEntityManager; } });
27
- var MongoEntityRepository_1 = require("./MongoEntityRepository");
28
- Object.defineProperty(exports, "EntityRepository", { enumerable: true, get: function () { return MongoEntityRepository_1.MongoEntityRepository; } });
29
- var MongoMikroORM_1 = require("./MongoMikroORM");
30
- Object.defineProperty(exports, "MikroORM", { enumerable: true, get: function () { return MongoMikroORM_1.MongoMikroORM; } });
31
- Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return MongoMikroORM_1.defineMongoConfig; } });
32
- var bson_1 = require("bson");
33
- Object.defineProperty(exports, "ObjectId", { enumerable: true, get: function () { return bson_1.ObjectId; } });
34
- __exportStar(require("@mikro-orm/core"), exports);
1
+ export * from '@mikro-orm/core';
2
+ export { ObjectId } from 'mongodb';
3
+ export * from './MongoConnection.js';
4
+ export * from './MongoDriver.js';
5
+ export * from './MongoPlatform.js';
6
+ export * from './MongoEntityManager.js';
7
+ export * from './MongoEntityRepository.js';
8
+ export * from './MongoSchemaGenerator.js';
9
+ export { MongoEntityManager as EntityManager } from './MongoEntityManager.js';
10
+ export { MongoEntityRepository as EntityRepository } from './MongoEntityRepository.js';
11
+ export { MongoMikroORM as MikroORM, defineMongoConfig as defineConfig, } from './MongoMikroORM.js';
package/package.json CHANGED
@@ -1,19 +1,11 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "7.0.0-dev.1",
3
+ "type": "module",
4
+ "version": "7.0.0-dev.3",
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 && yarn run -T gen-esm-wrapper index.js index.mjs",
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"
@@ -58,13 +50,12 @@
58
50
  "access": "public"
59
51
  },
60
52
  "dependencies": {
61
- "bson": "^6.10.1",
62
53
  "mongodb": "6.13.0"
63
54
  },
64
55
  "devDependencies": {
65
56
  "@mikro-orm/core": "^6.4.5"
66
57
  },
67
58
  "peerDependencies": {
68
- "@mikro-orm/core": "7.0.0-dev.1"
59
+ "@mikro-orm/core": "7.0.0-dev.3"
69
60
  }
70
61
  }
package/index.mjs DELETED
@@ -1,206 +0,0 @@
1
- import mod from "./index.js";
2
-
3
- export default mod;
4
- export const ALIAS_REPLACEMENT = mod.ALIAS_REPLACEMENT;
5
- export const ALIAS_REPLACEMENT_RE = mod.ALIAS_REPLACEMENT_RE;
6
- export const ARRAY_OPERATORS = mod.ARRAY_OPERATORS;
7
- export const AbstractNamingStrategy = mod.AbstractNamingStrategy;
8
- export const AbstractSchemaGenerator = mod.AbstractSchemaGenerator;
9
- export const AfterCreate = mod.AfterCreate;
10
- export const AfterDelete = mod.AfterDelete;
11
- export const AfterUpdate = mod.AfterUpdate;
12
- export const AfterUpsert = mod.AfterUpsert;
13
- export const ArrayCollection = mod.ArrayCollection;
14
- export const ArrayType = mod.ArrayType;
15
- export const BaseEntity = mod.BaseEntity;
16
- export const BeforeCreate = mod.BeforeCreate;
17
- export const BeforeDelete = mod.BeforeDelete;
18
- export const BeforeUpdate = mod.BeforeUpdate;
19
- export const BeforeUpsert = mod.BeforeUpsert;
20
- export const BigIntType = mod.BigIntType;
21
- export const BlobType = mod.BlobType;
22
- export const BooleanType = mod.BooleanType;
23
- export const Cascade = mod.Cascade;
24
- export const ChangeSet = mod.ChangeSet;
25
- export const ChangeSetComputer = mod.ChangeSetComputer;
26
- export const ChangeSetPersister = mod.ChangeSetPersister;
27
- export const ChangeSetType = mod.ChangeSetType;
28
- export const CharacterType = mod.CharacterType;
29
- export const Check = mod.Check;
30
- export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
31
- export const Collection = mod.Collection;
32
- export const CommitOrderCalculator = mod.CommitOrderCalculator;
33
- export const Config = mod.Config;
34
- export const Configuration = mod.Configuration;
35
- export const ConfigurationLoader = mod.ConfigurationLoader;
36
- export const Connection = mod.Connection;
37
- export const ConnectionException = mod.ConnectionException;
38
- export const ConstraintViolationException = mod.ConstraintViolationException;
39
- export const CreateRequestContext = mod.CreateRequestContext;
40
- export const Cursor = mod.Cursor;
41
- export const CursorError = mod.CursorError;
42
- export const DatabaseDriver = mod.DatabaseDriver;
43
- export const DatabaseObjectExistsException = mod.DatabaseObjectExistsException;
44
- export const DatabaseObjectNotFoundException = mod.DatabaseObjectNotFoundException;
45
- export const DataloaderType = mod.DataloaderType;
46
- export const DataloaderUtils = mod.DataloaderUtils;
47
- export const DateTimeType = mod.DateTimeType;
48
- export const DateType = mod.DateType;
49
- export const DeadlockException = mod.DeadlockException;
50
- export const DecimalType = mod.DecimalType;
51
- export const DefaultLogger = mod.DefaultLogger;
52
- export const DeferMode = mod.DeferMode;
53
- export const DoubleType = mod.DoubleType;
54
- export const DriverException = mod.DriverException;
55
- export const EagerProps = mod.EagerProps;
56
- export const Embeddable = mod.Embeddable;
57
- export const Embedded = mod.Embedded;
58
- export const EnsureRequestContext = mod.EnsureRequestContext;
59
- export const Entity = mod.Entity;
60
- export const EntityAssigner = mod.EntityAssigner;
61
- export const EntityCaseNamingStrategy = mod.EntityCaseNamingStrategy;
62
- export const EntityComparator = mod.EntityComparator;
63
- export const EntityFactory = mod.EntityFactory;
64
- export const EntityHelper = mod.EntityHelper;
65
- export const EntityIdentifier = mod.EntityIdentifier;
66
- export const EntityLoader = mod.EntityLoader;
67
- export const EntityManager = mod.EntityManager;
68
- export const EntityManagerType = mod.EntityManagerType;
69
- export const EntityMetadata = mod.EntityMetadata;
70
- export const EntityRepository = mod.EntityRepository;
71
- export const EntityRepositoryType = mod.EntityRepositoryType;
72
- export const EntitySchema = mod.EntitySchema;
73
- export const EntitySerializer = mod.EntitySerializer;
74
- export const EntityTransformer = mod.EntityTransformer;
75
- export const EntityValidator = mod.EntityValidator;
76
- export const Enum = mod.Enum;
77
- export const EnumArrayType = mod.EnumArrayType;
78
- export const EnumType = mod.EnumType;
79
- export const EventManager = mod.EventManager;
80
- export const EventType = mod.EventType;
81
- export const EventTypeMap = mod.EventTypeMap;
82
- export const ExceptionConverter = mod.ExceptionConverter;
83
- export const FileCacheAdapter = mod.FileCacheAdapter;
84
- export const Filter = mod.Filter;
85
- export const FloatType = mod.FloatType;
86
- export const FlushMode = mod.FlushMode;
87
- export const ForeignKeyConstraintViolationException = mod.ForeignKeyConstraintViolationException;
88
- export const Formula = mod.Formula;
89
- export const GeneratedCacheAdapter = mod.GeneratedCacheAdapter;
90
- export const GroupOperator = mod.GroupOperator;
91
- export const HiddenProps = mod.HiddenProps;
92
- export const Hydrator = mod.Hydrator;
93
- export const IdentityMap = mod.IdentityMap;
94
- export const Index = mod.Index;
95
- export const IntegerType = mod.IntegerType;
96
- export const IntervalType = mod.IntervalType;
97
- export const InvalidFieldNameException = mod.InvalidFieldNameException;
98
- export const IsolationLevel = mod.IsolationLevel;
99
- export const JSON_KEY_OPERATORS = mod.JSON_KEY_OPERATORS;
100
- export const JsonProperty = mod.JsonProperty;
101
- export const JsonType = mod.JsonType;
102
- export const LoadStrategy = mod.LoadStrategy;
103
- export const LockMode = mod.LockMode;
104
- export const LockWaitTimeoutException = mod.LockWaitTimeoutException;
105
- export const ManyToMany = mod.ManyToMany;
106
- export const ManyToOne = mod.ManyToOne;
107
- export const MediumIntType = mod.MediumIntType;
108
- export const MemoryCacheAdapter = mod.MemoryCacheAdapter;
109
- export const MetadataDiscovery = mod.MetadataDiscovery;
110
- export const MetadataError = mod.MetadataError;
111
- export const MetadataProvider = mod.MetadataProvider;
112
- export const MetadataStorage = mod.MetadataStorage;
113
- export const MetadataValidator = mod.MetadataValidator;
114
- export const MikroORM = mod.MikroORM;
115
- export const MongoConnection = mod.MongoConnection;
116
- export const MongoDriver = mod.MongoDriver;
117
- export const MongoEntityManager = mod.MongoEntityManager;
118
- export const MongoEntityRepository = mod.MongoEntityRepository;
119
- export const MongoNamingStrategy = mod.MongoNamingStrategy;
120
- export const MongoPlatform = mod.MongoPlatform;
121
- export const MongoSchemaGenerator = mod.MongoSchemaGenerator;
122
- export const NodeState = mod.NodeState;
123
- export const NonUniqueFieldNameException = mod.NonUniqueFieldNameException;
124
- export const NotFoundError = mod.NotFoundError;
125
- export const NotNullConstraintViolationException = mod.NotNullConstraintViolationException;
126
- export const NullCacheAdapter = mod.NullCacheAdapter;
127
- export const NullHighlighter = mod.NullHighlighter;
128
- export const ObjectBindingPattern = mod.ObjectBindingPattern;
129
- export const ObjectHydrator = mod.ObjectHydrator;
130
- export const ObjectId = mod.ObjectId;
131
- export const OnInit = mod.OnInit;
132
- export const OnLoad = mod.OnLoad;
133
- export const OneToMany = mod.OneToMany;
134
- export const OneToOne = mod.OneToOne;
135
- export const OptimisticLockError = mod.OptimisticLockError;
136
- export const OptionalProps = mod.OptionalProps;
137
- export const PlainObject = mod.PlainObject;
138
- export const Platform = mod.Platform;
139
- export const PopulateHint = mod.PopulateHint;
140
- export const PopulatePath = mod.PopulatePath;
141
- export const PrimaryKey = mod.PrimaryKey;
142
- export const PrimaryKeyProp = mod.PrimaryKeyProp;
143
- export const Property = mod.Property;
144
- export const QueryFlag = mod.QueryFlag;
145
- export const QueryHelper = mod.QueryHelper;
146
- export const QueryOperator = mod.QueryOperator;
147
- export const QueryOrder = mod.QueryOrder;
148
- export const QueryOrderNumeric = mod.QueryOrderNumeric;
149
- export const Raw = mod.Raw;
150
- export const RawQueryFragment = mod.RawQueryFragment;
151
- export const ReadOnlyException = mod.ReadOnlyException;
152
- export const Ref = mod.Ref;
153
- export const Reference = mod.Reference;
154
- export const ReferenceKind = mod.ReferenceKind;
155
- export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
156
- export const RequestContext = mod.RequestContext;
157
- export const SCALAR_TYPES = mod.SCALAR_TYPES;
158
- export const ScalarReference = mod.ScalarReference;
159
- export const SerializationContext = mod.SerializationContext;
160
- export const SerializedPrimaryKey = mod.SerializedPrimaryKey;
161
- export const ServerException = mod.ServerException;
162
- export const SimpleLogger = mod.SimpleLogger;
163
- export const SmallIntType = mod.SmallIntType;
164
- export const StringType = mod.StringType;
165
- export const SyntaxErrorException = mod.SyntaxErrorException;
166
- export const TableExistsException = mod.TableExistsException;
167
- export const TableNotFoundException = mod.TableNotFoundException;
168
- export const TextType = mod.TextType;
169
- export const TimeType = mod.TimeType;
170
- export const TinyIntType = mod.TinyIntType;
171
- export const TransactionContext = mod.TransactionContext;
172
- export const TransactionEventBroadcaster = mod.TransactionEventBroadcaster;
173
- export const Transactional = mod.Transactional;
174
- export const Type = mod.Type;
175
- export const Uint8ArrayType = mod.Uint8ArrayType;
176
- export const UnderscoreNamingStrategy = mod.UnderscoreNamingStrategy;
177
- export const Unique = mod.Unique;
178
- export const UniqueConstraintViolationException = mod.UniqueConstraintViolationException;
179
- export const UnitOfWork = mod.UnitOfWork;
180
- export const UnknownType = mod.UnknownType;
181
- export const Utils = mod.Utils;
182
- export const UuidType = mod.UuidType;
183
- export const ValidationError = mod.ValidationError;
184
- export const WrappedEntity = mod.WrappedEntity;
185
- export const assign = mod.assign;
186
- export const colors = mod.colors;
187
- export const compareArrays = mod.compareArrays;
188
- export const compareBooleans = mod.compareBooleans;
189
- export const compareBuffers = mod.compareBuffers;
190
- export const compareObjects = mod.compareObjects;
191
- export const createSqlFunction = mod.createSqlFunction;
192
- export const defineConfig = mod.defineConfig;
193
- export const equals = mod.equals;
194
- export const getOnConflictFields = mod.getOnConflictFields;
195
- export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
196
- export const helper = mod.helper;
197
- export const isRaw = mod.isRaw;
198
- export const parseJsonSafe = mod.parseJsonSafe;
199
- export const raw = mod.raw;
200
- export const ref = mod.ref;
201
- export const rel = mod.rel;
202
- export const serialize = mod.serialize;
203
- export const sql = mod.sql;
204
- export const t = mod.t;
205
- export const types = mod.types;
206
- export const wrap = mod.wrap;