@zvndev/powdb-client 0.5.0 → 0.6.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +51 -3
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.js +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.1 - 2026-06-17
|
|
4
|
+
|
|
5
|
+
- Kept the npm client release in lockstep with PowDB workspace v0.5.1.
|
|
6
|
+
- No TypeScript API changes; this is a dependency/version-alignment release.
|
|
7
|
+
|
|
8
|
+
|
|
3
9
|
All notable changes to `@zvndev/powdb-client`.
|
|
4
10
|
|
|
5
11
|
## Compatibility
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import * as tls from "node:tls";
|
|
|
18
18
|
import { EventEmitter } from "node:events";
|
|
19
19
|
import { type TypedRow, type TypedSchema } from "./typed.js";
|
|
20
20
|
/** Client library version. Compared to the server's reported version. */
|
|
21
|
-
export declare const CLIENT_VERSION = "0.
|
|
21
|
+
export declare const CLIENT_VERSION = "0.6.1";
|
|
22
22
|
export type QueryResult = {
|
|
23
23
|
kind: "rows";
|
|
24
24
|
columns: string[];
|
|
@@ -114,6 +114,13 @@ export declare class Client extends EventEmitter<ClientEvents> {
|
|
|
114
114
|
}, maybeOpts?: {
|
|
115
115
|
signal?: AbortSignal;
|
|
116
116
|
}): Promise<QueryResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Run a SQL statement through the server-side SQL frontend. The plain
|
|
119
|
+
* {@link query} method remains PowQL for wire compatibility.
|
|
120
|
+
*/
|
|
121
|
+
querySql(query: string, opts?: {
|
|
122
|
+
signal?: AbortSignal;
|
|
123
|
+
}): Promise<QueryResult>;
|
|
117
124
|
/**
|
|
118
125
|
* Like {@link query}, but coerces string result columns to typed JS values
|
|
119
126
|
* using the caller-supplied schema. See `./typed.ts` for the coercion
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,10 @@ import { encode, tryDecode, } from "./protocol.js";
|
|
|
21
21
|
import { PowDBError } from "./errors.js";
|
|
22
22
|
import { coerceRows, } from "./typed.js";
|
|
23
23
|
/** Client library version. Compared to the server's reported version. */
|
|
24
|
-
export const CLIENT_VERSION = "0.
|
|
24
|
+
export const CLIENT_VERSION = "0.6.1";
|
|
25
|
+
function socketChunkToBuffer(chunk) {
|
|
26
|
+
return typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
27
|
+
}
|
|
25
28
|
/** Map a JS {@link QueryParam} to its wire encoding. */
|
|
26
29
|
function toWireParam(p) {
|
|
27
30
|
if (p === null)
|
|
@@ -76,7 +79,7 @@ export class Client extends EventEmitter {
|
|
|
76
79
|
super();
|
|
77
80
|
this.socket = socket;
|
|
78
81
|
this.serverVersion = serverVersion;
|
|
79
|
-
this.socket.on("data", (chunk) => this.onData(chunk));
|
|
82
|
+
this.socket.on("data", (chunk) => this.onData(socketChunkToBuffer(chunk)));
|
|
80
83
|
this.socket.on("error", (err) => this.onClose(err));
|
|
81
84
|
this.socket.on("close", () => this.onClose(null));
|
|
82
85
|
}
|
|
@@ -94,7 +97,7 @@ export class Client extends EventEmitter {
|
|
|
94
97
|
socket.removeListener("close", onClose);
|
|
95
98
|
};
|
|
96
99
|
const onData = (chunk) => {
|
|
97
|
-
scratch = Buffer.concat([scratch, chunk]);
|
|
100
|
+
scratch = Buffer.concat([scratch, socketChunkToBuffer(chunk)]);
|
|
98
101
|
let decoded;
|
|
99
102
|
try {
|
|
100
103
|
decoded = tryDecode(scratch);
|
|
@@ -216,6 +219,51 @@ export class Client extends EventEmitter {
|
|
|
216
219
|
throw err;
|
|
217
220
|
}
|
|
218
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Run a SQL statement through the server-side SQL frontend. The plain
|
|
224
|
+
* {@link query} method remains PowQL for wire compatibility.
|
|
225
|
+
*/
|
|
226
|
+
async querySql(query, opts) {
|
|
227
|
+
const start = Date.now();
|
|
228
|
+
try {
|
|
229
|
+
const reply = await this.send({ type: "QuerySql", query }, opts);
|
|
230
|
+
let result;
|
|
231
|
+
switch (reply.type) {
|
|
232
|
+
case "ResultRows":
|
|
233
|
+
result = { kind: "rows", columns: reply.columns, rows: reply.rows };
|
|
234
|
+
break;
|
|
235
|
+
case "ResultScalar":
|
|
236
|
+
result = { kind: "scalar", value: reply.value };
|
|
237
|
+
break;
|
|
238
|
+
case "ResultOk":
|
|
239
|
+
result = { kind: "ok", affected: reply.affected };
|
|
240
|
+
break;
|
|
241
|
+
case "ResultMessage":
|
|
242
|
+
result = { kind: "message", message: reply.message };
|
|
243
|
+
break;
|
|
244
|
+
case "Error":
|
|
245
|
+
throw new PowDBError(`query failed: ${reply.message}`, "query_failed");
|
|
246
|
+
default:
|
|
247
|
+
throw new PowDBError(`unexpected reply: ${reply.type}`, "protocol_error");
|
|
248
|
+
}
|
|
249
|
+
this.emit("query", {
|
|
250
|
+
query,
|
|
251
|
+
durationMs: Date.now() - start,
|
|
252
|
+
ok: true,
|
|
253
|
+
kind: result.kind,
|
|
254
|
+
});
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
this.emit("query", {
|
|
259
|
+
query,
|
|
260
|
+
durationMs: Date.now() - start,
|
|
261
|
+
ok: false,
|
|
262
|
+
error: err,
|
|
263
|
+
});
|
|
264
|
+
throw err;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
219
267
|
/**
|
|
220
268
|
* Like {@link query}, but coerces string result columns to typed JS values
|
|
221
269
|
* using the caller-supplied schema. See `./typed.ts` for the coercion
|
package/dist/protocol.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare const MSG_QUERY = 3;
|
|
|
15
15
|
* plain `MSG_QUERY` frame is unchanged. Requires powdb-server ≥ 0.4.7.
|
|
16
16
|
*/
|
|
17
17
|
export declare const MSG_QUERY_PARAMS = 4;
|
|
18
|
+
/** SQL query frame. Plain Query remains PowQL for backward compatibility. */
|
|
19
|
+
export declare const MSG_QUERY_SQL = 5;
|
|
18
20
|
export declare const MSG_RESULT_ROWS = 7;
|
|
19
21
|
export declare const MSG_RESULT_SCALAR = 8;
|
|
20
22
|
export declare const MSG_RESULT_OK = 9;
|
|
@@ -73,6 +75,9 @@ export type Message = {
|
|
|
73
75
|
} | {
|
|
74
76
|
type: "Query";
|
|
75
77
|
query: string;
|
|
78
|
+
} | {
|
|
79
|
+
type: "QuerySql";
|
|
80
|
+
query: string;
|
|
76
81
|
} | {
|
|
77
82
|
type: "QueryWithParams";
|
|
78
83
|
query: string;
|
package/dist/protocol.js
CHANGED
|
@@ -15,6 +15,8 @@ export const MSG_QUERY = 0x03;
|
|
|
15
15
|
* plain `MSG_QUERY` frame is unchanged. Requires powdb-server ≥ 0.4.7.
|
|
16
16
|
*/
|
|
17
17
|
export const MSG_QUERY_PARAMS = 0x04;
|
|
18
|
+
/** SQL query frame. Plain Query remains PowQL for backward compatibility. */
|
|
19
|
+
export const MSG_QUERY_SQL = 0x05;
|
|
18
20
|
export const MSG_RESULT_ROWS = 0x07;
|
|
19
21
|
export const MSG_RESULT_SCALAR = 0x08;
|
|
20
22
|
export const MSG_RESULT_OK = 0x09;
|
|
@@ -60,6 +62,10 @@ export function encode(msg) {
|
|
|
60
62
|
payload = encodeString(msg.query);
|
|
61
63
|
msgType = MSG_QUERY;
|
|
62
64
|
break;
|
|
65
|
+
case "QuerySql":
|
|
66
|
+
payload = encodeString(msg.query);
|
|
67
|
+
msgType = MSG_QUERY_SQL;
|
|
68
|
+
break;
|
|
63
69
|
case "QueryWithParams": {
|
|
64
70
|
const parts = [encodeString(msg.query)];
|
|
65
71
|
const count = Buffer.alloc(2);
|
|
@@ -194,6 +200,10 @@ function decodePayload(msgType, payload) {
|
|
|
194
200
|
return { type: "ConnectOk", version: decodeString(payload, cursor) };
|
|
195
201
|
case MSG_QUERY:
|
|
196
202
|
return { type: "Query", query: decodeString(payload, cursor) };
|
|
203
|
+
case MSG_QUERY_SQL: {
|
|
204
|
+
const query = decodeString(payload, cursor);
|
|
205
|
+
return { type: "QuerySql", query };
|
|
206
|
+
}
|
|
197
207
|
case MSG_QUERY_PARAMS: {
|
|
198
208
|
const query = decodeString(payload, cursor);
|
|
199
209
|
const count = readU16(payload, cursor, "param count");
|