@open-xchange/fastify-sdk 0.2.1 → 0.2.3

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.
@@ -3,11 +3,14 @@ import * as mariadb from 'mariadb'
3
3
  const defaults = {
4
4
  dateStrings: ['DATE', 'DATETIME'],
5
5
  timezone: '+00:00',
6
- namedPlaceholders: true
6
+ namedPlaceholders: true,
7
+ connectTimeout: 10_000
7
8
  }
8
9
 
9
10
  export function createMariaDBPool (options = {}) {
10
- const pool = mariadb.createPool({ ...defaults, ...options })
11
+ const config = { ...defaults, ...options }
12
+ const pool = mariadb.createPool(config)
13
+ pool._connConfig = config
11
14
  pool.on('connection', (connection) => {
12
15
  connection.query('SET SESSION time_zone="+00:00"')
13
16
  })
@@ -47,15 +50,31 @@ export function createMariaDBPoolFromEnv ({ prefix = 'SQL', names } = {}) {
47
50
  }
48
51
 
49
52
  export async function mariadbReadyCheck (pool, { retries = 12, delay = 10_000, logger } = {}) {
53
+ // Pools created via createMariaDBPool() have _connConfig attached.
54
+ // Use createConnection() directly for these because the pool swallows
55
+ // connection errors and waits the full acquireTimeout (10s) before
56
+ // returning a generic ER_GET_CONNECTION_TIMEOUT. Direct connections
57
+ // fail immediately with the real error (ECONNREFUSED etc.), making
58
+ // retries fast. Falls back to pool.query() for plain mock pools.
59
+ const useDirectConnect = Boolean(pool._connConfig)
60
+ const config = useDirectConnect ? { ...pool._connConfig, connectTimeout: defaults.connectTimeout } : null
50
61
  for (let i = 1; i <= retries; i++) {
62
+ let conn
51
63
  try {
52
- await pool.query('SELECT 1')
64
+ if (useDirectConnect) {
65
+ conn = await mariadb.createConnection(config)
66
+ await conn.query('SELECT 1')
67
+ } else {
68
+ await pool.query('SELECT 1')
69
+ }
53
70
  if (logger) logger.info('Database is ready')
54
71
  return
55
72
  } catch (err) {
56
73
  if (logger) logger.warn(`Database not ready (attempt ${i}/${retries}): ${err.code} ${err.message}`)
57
74
  if (i === retries) throw err
58
75
  await new Promise(resolve => setTimeout(resolve, delay))
76
+ } finally {
77
+ if (conn) await conn.end().catch(() => {})
59
78
  }
60
79
  }
61
80
  }
@@ -76,6 +95,6 @@ export function getMariaDBPools () {
76
95
  }
77
96
 
78
97
  export async function createUUID (pool) {
79
- const [[{ uuid }]] = await pool.query('SELECT uuid() as uuid')
98
+ const [{ uuid }] = await pool.query('SELECT uuid() as uuid')
80
99
  return uuid
81
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/fastify-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
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
+ }