@lowdefy/connection-knex 5.5.1 → 5.6.0

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.
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */ import knex from 'knex';
16
16
  import { ConfigError } from '@lowdefy/errors';
17
+ import normalizeConnectionPort from './normalizeConnectionPort.js';
17
18
  function createKnex(connection) {
18
19
  if (connection.client === 'sqlite3') {
19
20
  throw new ConfigError('Knex connection "client: sqlite3" is no longer supported. Use "client: better-sqlite3" or "client: sqlite" instead.');
@@ -22,11 +23,11 @@ function createKnex(connection) {
22
23
  throw new ConfigError('Knex connection "client: mysql" is no longer supported. Use "client: mysql2" instead.');
23
24
  }
24
25
  if (connection.client === 'sqlite') {
25
- return knex({
26
+ return normalizeConnectionPort(knex({
26
27
  ...connection,
27
28
  client: 'better-sqlite3'
28
- });
29
+ }));
29
30
  }
30
- return knex(connection);
31
+ return normalizeConnectionPort(knex(connection));
31
32
  }
32
33
  export default createKnex;
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ConfigError } from '@lowdefy/errors';
16
+ import { type } from '@lowdefy/helpers';
17
+ // knex hands connectionSettings.port to the driver as it received it, and a port
18
+ // parsed from a connection string or read from a _secret arrives as a string.
19
+ // tedious (mssql) refuses a string port, so coerce it once for every client.
20
+ function normalizeConnectionPort(knexClient) {
21
+ const settings = knexClient.client?.connectionSettings;
22
+ if (!type.isObject(settings) || !type.isString(settings.port)) {
23
+ return knexClient;
24
+ }
25
+ const port = Number(settings.port);
26
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
27
+ throw new ConfigError(`Knex connection port is not a valid port number. Received ${JSON.stringify(settings.port)}.`);
28
+ }
29
+ settings.port = port;
30
+ return knexClient;
31
+ }
32
+ export default normalizeConnectionPort;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/connection-knex",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -35,8 +35,8 @@
35
35
  "dist/*"
36
36
  ],
37
37
  "dependencies": {
38
- "@lowdefy/errors": "5.5.1",
39
- "@lowdefy/helpers": "5.5.1",
38
+ "@lowdefy/errors": "5.6.0",
39
+ "@lowdefy/helpers": "5.6.0",
40
40
  "better-sqlite3": "12.9.0",
41
41
  "knex": "3.2.9",
42
42
  "mysql2": "3.22.3",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@jest/globals": "28.1.3",
48
- "@lowdefy/ajv": "5.5.1",
48
+ "@lowdefy/ajv": "5.6.0",
49
49
  "@swc/cli": "0.8.0",
50
50
  "@swc/core": "1.15.18",
51
51
  "@swc/jest": "0.2.39",