@mikro-orm/mongodb 7.1.16-dev.6 → 7.1.16-dev.8

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.
@@ -25,6 +25,11 @@ export declare class MongoConnection extends Connection {
25
25
  mapOptions(overrides: MongoClientOptions): MongoClientOptions;
26
26
  getDb(): Db;
27
27
  execute(query: string): Promise<any>;
28
+ /**
29
+ * Maps an order direction to mongo's `1`/`-1`, ignoring any `nulls first`/`nulls last` qualifier, which mongo cannot honor.
30
+ * @internal
31
+ */
32
+ static getSortDirection(direction: string | number): 1 | -1;
28
33
  find<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): Promise<EntityData<T>[]>;
29
34
  stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, opts?: MongoFindOptions<T>): AsyncIterableIterator<T>;
30
35
  private _find;
@@ -1,5 +1,5 @@
1
1
  import { MongoClient, ObjectId, } from 'mongodb';
2
- import { Connection, EventType, inspect, QueryOrder, Utils, ValidationError, } from '@mikro-orm/core';
2
+ import { Connection, EventType, inspect, QueryOrderNumeric, Utils, ValidationError, } from '@mikro-orm/core';
3
3
  /** MongoDB database connection using the official `mongodb` driver. */
4
4
  export class MongoConnection extends Connection {
5
5
  #client;
@@ -112,6 +112,16 @@ export class MongoConnection extends Connection {
112
112
  async execute(query) {
113
113
  throw new Error(`${this.constructor.name} does not support generic execute method`);
114
114
  }
115
+ /**
116
+ * Maps an order direction to mongo's `1`/`-1`, ignoring any `nulls first`/`nulls last` qualifier, which mongo cannot honor.
117
+ * @internal
118
+ */
119
+ static getSortDirection(direction) {
120
+ if (typeof direction === 'number') {
121
+ return direction === QueryOrderNumeric.DESC ? -1 : 1;
122
+ }
123
+ return direction.toLowerCase().startsWith('desc') ? -1 : 1;
124
+ }
115
125
  async find(entityName, where, opts = {}) {
116
126
  const { cursor, query } = await this._find(entityName, where, opts);
117
127
  const now = Date.now();
@@ -158,7 +168,7 @@ export class MongoConnection extends Connection {
158
168
  Utils.keys(o).forEach(k => {
159
169
  const direction = o[k];
160
170
  if (typeof direction === 'string') {
161
- orderByTuples.push([k.toString(), direction.toUpperCase() === QueryOrder.ASC ? 1 : -1]);
171
+ orderByTuples.push([k.toString(), MongoConnection.getSortDirection(direction)]);
162
172
  }
163
173
  else {
164
174
  orderByTuples.push([k.toString(), direction]);
package/MongoDriver.js CHANGED
@@ -106,7 +106,8 @@ export class MongoDriver extends DatabaseDriver {
106
106
  const sortSpec = {};
107
107
  for (const order of orderBy) {
108
108
  for (const [key, dir] of Object.entries(order)) {
109
- sortSpec[key] = dir === 'ASC' || dir === 'asc' || dir === 1 ? 1 : -1;
109
+ sortSpec[key] =
110
+ typeof dir === 'string' || typeof dir === 'number' ? MongoConnection.getSortDirection(dir) : dir;
110
111
  }
111
112
  }
112
113
  pipeline.push({ $sort: sortSpec });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mongodb",
3
- "version": "7.1.16-dev.6",
3
+ "version": "7.1.16-dev.8",
4
4
  "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
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.1.15"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.16-dev.6"
56
+ "@mikro-orm/core": "7.1.16-dev.8"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"