@zintrust/db-mysql 1.8.8 → 1.9.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.
package/dist/index.js CHANGED
@@ -158,7 +158,6 @@ async function connect(state, config) {
158
158
  const isWorkersRuntime = Cloudflare.getWorkersEnv() !== null;
159
159
  const tlsEnabled = Boolean(config.ssl);
160
160
  const nodeMysqlSslConfig = getNodeMysqlSslConfig(tlsEnabled);
161
- Logger.info(`[db-mysql] Effective connection params: host=${host}, port=${port}, database=${database}, user=${user}, password_len=${password.length}, ssl=${tlsEnabled}`);
162
161
  const timeoutMs = getSocketTimeoutMs(config);
163
162
  if (isWorkersRuntime) {
164
163
  state.pool = await createWorkersPool({
@@ -214,7 +213,6 @@ async function rawQuery(state, sql, parameters) {
214
213
  }
215
214
  const pool = ensurePool(state);
216
215
  try {
217
- Logger.warn(`Raw SQL Query executed: ${sql}`, Logger.withTraceSkipContext({ sql, parameters }));
218
216
  const [rows] = await pool.execute(sql, parameters ?? []);
219
217
  if (Array.isArray(rows))
220
218
  return rows;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/db-mysql",
3
- "version": "1.8.8",
3
+ "version": "1.9.0",
4
4
  "description": "MySQL and MariaDB database adapter for ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,4 +0,0 @@
1
- import type { IDatabaseAdapter } from './index.js';
2
- export declare const MySqlWorkersDurableObjectAdapter: Readonly<{
3
- create(_config: unknown): IDatabaseAdapter;
4
- }>;
@@ -1,178 +0,0 @@
1
- import { ErrorFactory, Logger } from '@zintrust/core';
2
- import { CREATE_MIGRATIONS_TABLE_SQL, MYSQL_PLACEHOLDER, MYSQL_TYPE } from './common.js';
3
- const getDoTimeoutMs = () => {
4
- const globalEnv = globalThis.env;
5
- const raw = globalEnv?.['MYSQL_DO_TIMEOUT_MS'] ?? globalEnv?.['DO_REQUEST_TIMEOUT_MS'];
6
- const parsed = Number(raw);
7
- return Number.isFinite(parsed) && parsed > 0 ? parsed : 15000;
8
- };
9
- const createTimeoutSignal = (timeoutMs) => {
10
- if (timeoutMs <= 0)
11
- return undefined;
12
- const timeout = AbortSignal.timeout;
13
- return typeof timeout === 'function' ? timeout(timeoutMs) : undefined;
14
- };
15
- const createSendQueryFunction = (getStub, connect) => {
16
- return async (sql, params, method) => {
17
- await connect();
18
- const stub = getStub();
19
- const executePath = 'http://do/execute'; //NOSONAR
20
- const queryPath = 'http://do/query'; //NOSONAR
21
- const payload = JSON.stringify({
22
- command: sql,
23
- sql,
24
- params,
25
- method,
26
- });
27
- const timeoutMs = getDoTimeoutMs();
28
- const send = async (path) => {
29
- const startedAt = Date.now();
30
- try {
31
- const response = await stub.fetch(path, {
32
- method: 'POST',
33
- headers: {
34
- 'Content-Type': 'application/json',
35
- },
36
- body: payload,
37
- signal: createTimeoutSignal(timeoutMs),
38
- });
39
- Logger.debug('[MySqlWorkersDurableObjectAdapter] DO request completed', {
40
- path,
41
- status: response.status,
42
- durationMs: Date.now() - startedAt,
43
- timeoutMs,
44
- sqlPreview: sql.slice(0, 80),
45
- });
46
- return response;
47
- }
48
- catch (error) {
49
- Logger.error('[MySqlWorkersDurableObjectAdapter] DO request failed', {
50
- path,
51
- durationMs: Date.now() - startedAt,
52
- timeoutMs,
53
- error: error instanceof Error ? error.message : String(error),
54
- });
55
- if (error instanceof Error && error.name === 'AbortError') {
56
- throw ErrorFactory.createGeneralError(`MySQL DO request timed out after ${timeoutMs}ms (${path})`, error);
57
- }
58
- throw error;
59
- }
60
- };
61
- let response = await send(executePath);
62
- if (!response.ok && (response.status === 404 || response.status === 405)) {
63
- response = await send(queryPath);
64
- }
65
- if (!response.ok) {
66
- const text = await response.text();
67
- let errDetail;
68
- try {
69
- errDetail = JSON.parse(text);
70
- }
71
- catch {
72
- errDetail = { error: text };
73
- }
74
- const msg = errDetail.error ||
75
- errDetail.message ||
76
- response.statusText;
77
- throw ErrorFactory.createGeneralError(`DO Query Failed: ${msg}`);
78
- }
79
- const json = (await response.json());
80
- if (json !== null && typeof json === 'object' && 'result' in json) {
81
- return json.result;
82
- }
83
- return json;
84
- };
85
- };
86
- const createConnectionManager = (getNamespace) => {
87
- let connected = false;
88
- const getStub = () => {
89
- const namespace = getNamespace();
90
- if (!namespace) {
91
- throw ErrorFactory.createConfigError('MYSQL_POOL binding not found. Cannot connect to Durable Object pool.');
92
- }
93
- const id = namespace.idFromName('default');
94
- return namespace.get(id);
95
- };
96
- const connect = async () => {
97
- if (connected)
98
- return;
99
- try {
100
- const stub = getStub();
101
- const health = 'http://do/health'; //NOSONAR
102
- const timeoutMs = getDoTimeoutMs();
103
- const res = await stub.fetch(health, {
104
- method: 'POST',
105
- signal: createTimeoutSignal(timeoutMs),
106
- });
107
- if (!res.ok) {
108
- throw ErrorFactory.createGeneralError(`DO health check failed: ${res.status}`);
109
- }
110
- const body = (await res.json());
111
- if (!body.connected) {
112
- Logger.info('[MySqlWorkersDurableObjectAdapter] DO not connected yet, will init on first query');
113
- }
114
- connected = true;
115
- }
116
- catch (err) {
117
- Logger.error('[MySqlWorkersDurableObjectAdapter] Connection failed', err);
118
- throw ErrorFactory.createGeneralError('Failed to connect to MySQL DO', err);
119
- }
120
- };
121
- const sendQuery = createSendQueryFunction(getStub, connect);
122
- return {
123
- connect,
124
- sendQuery,
125
- disconnect: () => {
126
- connected = false;
127
- },
128
- isConnected: () => connected,
129
- };
130
- };
131
- export const MySqlWorkersDurableObjectAdapter = Object.freeze({
132
- create(_config) {
133
- const connectionManager = createConnectionManager(() => {
134
- const globalEnv = globalThis.env;
135
- return globalEnv?.['MYSQL_POOL'];
136
- });
137
- return {
138
- async connect() {
139
- return connectionManager.connect();
140
- },
141
- async disconnect() {
142
- connectionManager.disconnect();
143
- },
144
- async query(sql, parameters = []) {
145
- return connectionManager.sendQuery(sql, parameters, 'query');
146
- },
147
- async queryOne(sql, parameters = []) {
148
- const result = await connectionManager.sendQuery(sql, parameters, 'query');
149
- if (result.rows.length === 0)
150
- return null;
151
- return result.rows[0];
152
- },
153
- async rawQuery(sql, parameters) {
154
- const result = await connectionManager.sendQuery(sql, parameters || [], 'query');
155
- return result.rows;
156
- },
157
- async ping() {
158
- await connectionManager.connect();
159
- await connectionManager.sendQuery('SELECT 1', [], 'query');
160
- },
161
- async transaction(_callback) {
162
- throw ErrorFactory.createGeneralError('Transactions are not yet supported in MySqlWorkersDurableObjectAdapter');
163
- },
164
- getType() {
165
- return MYSQL_TYPE;
166
- },
167
- isConnected() {
168
- return connectionManager.isConnected();
169
- },
170
- getPlaceholder(_index) {
171
- return MYSQL_PLACEHOLDER;
172
- },
173
- async ensureMigrationsTable() {
174
- await connectionManager.sendQuery(CREATE_MIGRATIONS_TABLE_SQL, [], 'query');
175
- },
176
- };
177
- },
178
- });
@@ -1,63 +0,0 @@
1
- {
2
- "name": "@zintrust/db-mysql",
3
- "version": "1.6.0",
4
- "buildDate": "2026-05-01T05:25:51.958Z",
5
- "buildEnvironment": {
6
- "node": "v22.22.1",
7
- "platform": "darwin",
8
- "arch": "arm64"
9
- },
10
- "git": {
11
- "commit": "ef4e9bec",
12
- "branch": "release"
13
- },
14
- "package": {
15
- "engines": {
16
- "node": ">=20.0.0"
17
- },
18
- "dependencies": [
19
- "mysql2"
20
- ],
21
- "peerDependencies": [
22
- "@zintrust/core"
23
- ]
24
- },
25
- "files": {
26
- "MySqlWorkersDurableObjectAdapter.d.ts": {
27
- "size": 170,
28
- "sha256": "ed336493205ab6e060ad2ad6737a0aab9a0c41dfcdee8d5cd89f18b8ffb58f7e"
29
- },
30
- "MySqlWorkersDurableObjectAdapter.js": {
31
- "size": 6810,
32
- "sha256": "775b5e5efb6aa58be1a83ea9c54c182a44060f70ab1e293fae20998d35766447"
33
- },
34
- "build-manifest.json": {
35
- "size": 1678,
36
- "sha256": "7e3b42382b430baf50c0278598ec13ebc1fea1091baa9b76207715f684825a22"
37
- },
38
- "common.d.ts": {
39
- "size": 615,
40
- "sha256": "fafe13a87e5239d41b537dcdf23d7fc84c25d7b34207d272f149cbadfebfb417"
41
- },
42
- "common.js": {
43
- "size": 580,
44
- "sha256": "71e659214b8f208ec303756a4ed796f9904a5c2d5f6ba71ae03603be3773851c"
45
- },
46
- "index.d.ts": {
47
- "size": 1460,
48
- "sha256": "e3fee6b22d26a931b8a8254267ad5621b1fcf26c606b7749190ee4ccfed24cd3"
49
- },
50
- "index.js": {
51
- "size": 10003,
52
- "sha256": "877f2f95488505148da95707ccacbf08fa042744ab5255bef016687a220a2c95"
53
- },
54
- "register.d.ts": {
55
- "size": 180,
56
- "sha256": "1ac7cca6cfbda8e5a65153917d4bbb4dd4fbe309dcabf9d9bdfb1eea6e97e52e"
57
- },
58
- "register.js": {
59
- "size": 1066,
60
- "sha256": "776afb1a7728d8448454a5aee172ce123d81ccf0619cf0228578d55e10697b62"
61
- }
62
- }
63
- }