@mikro-orm/knex 6.6.16-dev.0 → 6.6.16-dev.1

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.
@@ -32,4 +32,10 @@ export declare abstract class AbstractSqlPlatform extends Platform {
32
32
  * @internal
33
33
  */
34
34
  getOrderByExpression(column: string, direction: string): string[];
35
+ /**
36
+ * `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric`
37
+ * values) onto the six allow-listed directions, so only unknown values are rejected.
38
+ * @internal
39
+ */
40
+ validateOrderByDirection(direction: string): string;
35
41
  }
@@ -5,6 +5,14 @@ const sqlstring_1 = require("sqlstring");
5
5
  const core_1 = require("@mikro-orm/core");
6
6
  const SqlEntityRepository_1 = require("./SqlEntityRepository");
7
7
  const schema_1 = require("./schema");
8
+ const ORDER_BY_DIRECTIONS = new Set([
9
+ 'asc',
10
+ 'desc',
11
+ 'asc nulls first',
12
+ 'asc nulls last',
13
+ 'desc nulls first',
14
+ 'desc nulls last',
15
+ ]);
8
16
  class AbstractSqlPlatform extends core_1.Platform {
9
17
  schemaHelper;
10
18
  usesPivotTable() {
@@ -105,7 +113,19 @@ class AbstractSqlPlatform extends core_1.Platform {
105
113
  * @internal
106
114
  */
107
115
  getOrderByExpression(column, direction) {
108
- return [`${column} ${direction.toLowerCase()}`];
116
+ return [`${column} ${this.validateOrderByDirection(direction)}`];
117
+ }
118
+ /**
119
+ * `toLowerCase()` folds every `QueryOrder` enum member (and the normalized `QueryOrderNumeric`
120
+ * values) onto the six allow-listed directions, so only unknown values are rejected.
121
+ * @internal
122
+ */
123
+ validateOrderByDirection(direction) {
124
+ const dir = ('' + direction).toLowerCase().trim();
125
+ if (!ORDER_BY_DIRECTIONS.has(dir)) {
126
+ throw new Error(`Invalid order direction: '${direction}'`);
127
+ }
128
+ return dir;
109
129
  }
110
130
  }
111
131
  exports.AbstractSqlPlatform = AbstractSqlPlatform;
@@ -102,7 +102,7 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
102
102
  }
103
103
  getOrderByExpression(column, direction) {
104
104
  const ret = [];
105
- const dir = direction.toLowerCase();
105
+ const dir = this.validateOrderByDirection(direction);
106
106
  if (dir in this.ORDER_BY_NULLS_TRANSLATE) {
107
107
  ret.push(`${column} ${this.ORDER_BY_NULLS_TRANSLATE[dir]}`);
108
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.6.16-dev.0",
3
+ "version": "6.6.16-dev.1",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.6.15"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.6.16-dev.0",
69
+ "@mikro-orm/core": "6.6.16-dev.1",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"