@mikro-orm/mongodb 7.0.0-dev.65 → 7.0.0-dev.67

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,5 +1,5 @@
1
- import { MongoClient, type ClientSession, type Collection, type Db, type MongoClientOptions, type TransactionOptions } from 'mongodb';
2
- import { Connection, type AnyEntity, type Configuration, type ConnectionOptions, type ConnectionType, type EntityData, type EntityName, type FilterQuery, type IsolationLevel, type QueryOrderMap, type QueryResult, type Transaction, type TransactionEventBroadcaster, type UpsertOptions, type UpsertManyOptions, type LoggingOptions } from '@mikro-orm/core';
1
+ import { type ClientSession, type Collection, type Db, MongoClient, type MongoClientOptions, type TransactionOptions } from 'mongodb';
2
+ import { type AnyEntity, type Configuration, Connection, type ConnectionOptions, type ConnectionType, type EntityData, type EntityName, type FilterQuery, type IsolationLevel, type LoggingOptions, type QueryOrderMap, type QueryResult, type Transaction, type TransactionEventBroadcaster, type UpsertManyOptions, type UpsertOptions } from '@mikro-orm/core';
3
3
  export declare class MongoConnection extends Connection {
4
4
  protected client: MongoClient;
5
5
  protected db: Db;
@@ -1,4 +1,4 @@
1
- import { ObjectId, MongoClient, } from 'mongodb';
1
+ import { MongoClient, ObjectId, } from 'mongodb';
2
2
  import { inspect } from 'node:util';
3
3
  import { Connection, EventType, QueryOrder, Utils, ValidationError, } from '@mikro-orm/core';
4
4
  export class MongoConnection extends Connection {
@@ -132,7 +132,7 @@ export class MongoConnection extends Connection {
132
132
  orderBy.forEach(o => {
133
133
  Utils.keys(o).forEach(k => {
134
134
  const direction = o[k];
135
- orderByTuples.push([k.toString(), Utils.isString(direction) ? direction.toUpperCase() === QueryOrder.ASC ? 1 : -1 : direction]);
135
+ orderByTuples.push([k.toString(), typeof direction === 'string' ? direction.toUpperCase() === QueryOrder.ASC ? 1 : -1 : direction]);
136
136
  });
137
137
  });
138
138
  if (orderByTuples.length > 0) {
package/MongoDriver.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ObjectId } from 'mongodb';
2
- import { DatabaseDriver, EntityManagerType, ReferenceKind, Utils, } from '@mikro-orm/core';
2
+ import { DatabaseDriver, EntityManagerType, GroupOperator, ReferenceKind, Utils, } from '@mikro-orm/core';
3
3
  import { MongoConnection } from './MongoConnection.js';
4
4
  import { MongoPlatform } from './MongoPlatform.js';
5
5
  import { MongoEntityManager } from './MongoEntityManager.js';
@@ -237,7 +237,7 @@ export class MongoDriver extends DatabaseDriver {
237
237
  throw new Error('Full text search is only supported on the top level of the query object.');
238
238
  }
239
239
  Utils.keys(copiedData).forEach(k => {
240
- if (Utils.isGroupOperator(k)) {
240
+ if (k in GroupOperator) {
241
241
  /* v8 ignore next 5 */
242
242
  if (Array.isArray(copiedData[k])) {
243
243
  copiedData[k] = copiedData[k].map(v => this.renameFields(entityName, v));
@@ -251,7 +251,7 @@ export class MongoDriver extends DatabaseDriver {
251
251
  const prop = meta.properties[k];
252
252
  let isObjectId = false;
253
253
  if (prop.kind === ReferenceKind.SCALAR) {
254
- isObjectId = prop.type.toLowerCase() === 'objectid';
254
+ isObjectId = prop.type === 'ObjectId';
255
255
  }
256
256
  else if (prop.kind === ReferenceKind.EMBEDDED) {
257
257
  if (copiedData[prop.name] == null) {
@@ -267,7 +267,7 @@ export class MongoDriver extends DatabaseDriver {
267
267
  else {
268
268
  const meta2 = this.metadata.find(prop.type);
269
269
  const pk = meta2.properties[meta2.primaryKeys[0]];
270
- isObjectId = pk.type.toLowerCase() === 'objectid';
270
+ isObjectId = pk.type === 'ObjectId';
271
271
  }
272
272
  if (isObjectId) {
273
273
  copiedData[k] = this.convertObjectIds(copiedData[k]);
@@ -286,7 +286,7 @@ export class MongoDriver extends DatabaseDriver {
286
286
  if (data instanceof ObjectId) {
287
287
  return data;
288
288
  }
289
- if (Utils.isString(data) && data.match(/^[0-9a-f]{24}$/i)) {
289
+ if (typeof data === 'string' && data.match(/^[0-9a-f]{24}$/i)) {
290
290
  return new ObjectId(data);
291
291
  }
292
292
  if (Array.isArray(data)) {
@@ -301,7 +301,7 @@ export class MongoDriver extends DatabaseDriver {
301
301
  }
302
302
  buildFilterById(entityName, id) {
303
303
  const meta = this.metadata.find(entityName);
304
- if (meta.properties[meta.primaryKeys[0]].type.toLowerCase() === 'objectid') {
304
+ if (meta.properties[meta.primaryKeys[0]].type === 'ObjectId') {
305
305
  return { _id: new ObjectId(id) };
306
306
  }
307
307
  return { _id: id };
package/MongoPlatform.js CHANGED
@@ -37,7 +37,7 @@ export class MongoPlatform extends Platform {
37
37
  return new MongoSchemaGenerator(em ?? driver);
38
38
  }
39
39
  normalizePrimaryKey(data) {
40
- if (Utils.isObjectID(data)) {
40
+ if (Utils.isObject(data) && data.constructor?.name === 'ObjectId') {
41
41
  return data.toHexString();
42
42
  }
43
43
  return data;
@@ -193,7 +193,7 @@ export class MongoSchemaGenerator extends AbstractSchemaGenerator {
193
193
  ? prop.embeddedPath.join('.')
194
194
  : prop.fieldNames.reduce((o, i) => { o[i] = 1; return o; }, {});
195
195
  return [[collection.collectionName, this.executeQuery(collection, 'createIndex', fieldOrSpec, {
196
- name: (Utils.isString(prop[type]) ? prop[type] : undefined),
196
+ name: typeof prop[type] === 'string' ? prop[type] : undefined,
197
197
  unique: type === 'unique',
198
198
  sparse: prop.nullable === true,
199
199
  })]];
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.65",
4
+ "version": "7.0.0-dev.67",
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.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.0-dev.65"
59
+ "@mikro-orm/core": "7.0.0-dev.67"
60
60
  }
61
61
  }