@open-xchange/fastify-sdk 0.2.2 → 0.2.4

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.
@@ -4,11 +4,14 @@ const defaults = {
4
4
  dateStrings: ['DATE', 'DATETIME'],
5
5
  timezone: '+00:00',
6
6
  namedPlaceholders: true,
7
- connectTimeout: 10_000
7
+ connectTimeout: 10_000,
8
+ allowPublicKeyRetrieval: true
8
9
  }
9
10
 
10
11
  export function createMariaDBPool (options = {}) {
11
- const pool = mariadb.createPool({ ...defaults, ...options })
12
+ const config = { ...defaults, ...options }
13
+ const pool = mariadb.createPool(config)
14
+ pool._connConfig = config
12
15
  pool.on('connection', (connection) => {
13
16
  connection.query('SET SESSION time_zone="+00:00"')
14
17
  })
@@ -48,15 +51,31 @@ export function createMariaDBPoolFromEnv ({ prefix = 'SQL', names } = {}) {
48
51
  }
49
52
 
50
53
  export async function mariadbReadyCheck (pool, { retries = 12, delay = 10_000, logger } = {}) {
54
+ // Pools created via createMariaDBPool() have _connConfig attached.
55
+ // Use createConnection() directly for these because the pool swallows
56
+ // connection errors and waits the full acquireTimeout (10s) before
57
+ // returning a generic ER_GET_CONNECTION_TIMEOUT. Direct connections
58
+ // fail immediately with the real error (ECONNREFUSED etc.), making
59
+ // retries fast. Falls back to pool.query() for plain mock pools.
60
+ const useDirectConnect = Boolean(pool._connConfig)
61
+ const config = useDirectConnect ? { ...pool._connConfig, connectTimeout: defaults.connectTimeout } : null
51
62
  for (let i = 1; i <= retries; i++) {
63
+ let conn
52
64
  try {
53
- await pool.query('SELECT 1')
65
+ if (useDirectConnect) {
66
+ conn = await mariadb.createConnection(config)
67
+ await conn.query('SELECT 1')
68
+ } else {
69
+ await pool.query('SELECT 1')
70
+ }
54
71
  if (logger) logger.info('Database is ready')
55
72
  return
56
73
  } catch (err) {
57
74
  if (logger) logger.warn(`Database not ready (attempt ${i}/${retries}): ${err.code} ${err.message}`)
58
75
  if (i === retries) throw err
59
76
  await new Promise(resolve => setTimeout(resolve, delay))
77
+ } finally {
78
+ if (conn) await conn.end().catch(() => {})
60
79
  }
61
80
  }
62
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/fastify-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Shared foundation package for OX App Suite Node.js services",
5
5
  "private": false,
6
6
  "type": "module",
@@ -13,6 +13,11 @@
13
13
  "./redis": "./lib/redis/index.js",
14
14
  "./testing": "./lib/testing/index.js"
15
15
  },
16
+ "scripts": {
17
+ "lint": "eslint . --cache --fix",
18
+ "test": "vitest run",
19
+ "test:coverage": "vitest run --coverage"
20
+ },
16
21
  "author": "Open-Xchange",
17
22
  "license": "AGPL-3.0-or-later",
18
23
  "dependencies": {
@@ -70,9 +75,10 @@
70
75
  "engines": {
71
76
  "node": ">=20"
72
77
  },
73
- "scripts": {
74
- "lint": "eslint . --cache --fix",
75
- "test": "vitest run",
76
- "test:coverage": "vitest run --coverage"
78
+ "packageManager": "pnpm@10.27.0",
79
+ "pnpm": {
80
+ "onlyBuiltDependencies": [
81
+ "unrs-resolver"
82
+ ]
77
83
  }
78
- }
84
+ }