@bytebase/dbhub 1.3.1 → 1.5.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.
@@ -60,7 +60,7 @@ var sqlServerPassThroughPattern = new RegExp(
60
60
  var escapeHatchFunctionKeywords = {
61
61
  mysql: ["load_file", "get_lock", "release_lock", "release_all_locks"],
62
62
  mariadb: ["load_file", "get_lock", "release_lock", "release_all_locks"],
63
- postgres: ["pg_read_file", "pg_read_binary_file", "pg_ls_dir"],
63
+ postgres: ["pg_read_file", "pg_read_binary_file", "pg_ls_dir", "set_config"],
64
64
  sqlserver: sqlServerPassThroughKeywords,
65
65
  // Oracle packages a SELECT can call to reach outside the database, matched
66
66
  // as `package.member(` (see escapeHatchCallSuffix).
@@ -0,0 +1,63 @@
1
+ // src/utils/query-timeout.ts
2
+ var CLIENT_QUERY_TIMEOUT_GRACE_MS = 5e3;
3
+ var CANCEL_QUERY_TIMEOUT_MS = 5e3;
4
+ var MAX_TIMER_MS = 2147483647;
5
+ var MAX_QUERY_TIMEOUT_SECONDS = Math.floor(
6
+ (MAX_TIMER_MS - CLIENT_QUERY_TIMEOUT_GRACE_MS) / 1e3
7
+ );
8
+ function clientQueryTimeoutMs(queryTimeoutMs) {
9
+ const deadlineMs = queryTimeoutMs + CLIENT_QUERY_TIMEOUT_GRACE_MS;
10
+ if (!Number.isFinite(deadlineMs) || deadlineMs > MAX_TIMER_MS) {
11
+ throw new RangeError(
12
+ `query_timeout of ${queryTimeoutMs}ms exceeds the client-side deadline range (at most ${MAX_QUERY_TIMEOUT_SECONDS} seconds)`
13
+ );
14
+ }
15
+ return deadlineMs;
16
+ }
17
+ var CLIENT_QUERY_TIMEOUT_CODE = "DBHUB_CLIENT_QUERY_TIMEOUT";
18
+ var PG_CLIENT_TIMEOUT_MESSAGE = "Query read timeout";
19
+ var MYSQL2_CLIENT_TIMEOUT_CODE = "PROTOCOL_SEQUENCE_TIMEOUT";
20
+ var ClientQueryTimeoutError = class extends Error {
21
+ constructor(timeoutMs) {
22
+ super(`Query timed out on the client after ${timeoutMs}ms`);
23
+ this.code = CLIENT_QUERY_TIMEOUT_CODE;
24
+ this.name = "ClientQueryTimeoutError";
25
+ }
26
+ };
27
+ function isClientSideTimeout(error) {
28
+ if (typeof error !== "object" || error === null) {
29
+ return false;
30
+ }
31
+ const { code, message } = error;
32
+ return code === MYSQL2_CLIENT_TIMEOUT_CODE || code === CLIENT_QUERY_TIMEOUT_CODE || code === void 0 && message === PG_CLIENT_TIMEOUT_MESSAGE;
33
+ }
34
+ function withClientQueryDeadline(query, timeoutMs) {
35
+ if (timeoutMs === void 0) {
36
+ return query;
37
+ }
38
+ return new Promise((resolve, reject) => {
39
+ const timer = setTimeout(() => {
40
+ query.catch(() => {
41
+ });
42
+ reject(new ClientQueryTimeoutError(timeoutMs));
43
+ }, timeoutMs);
44
+ query.then(
45
+ (value) => {
46
+ clearTimeout(timer);
47
+ resolve(value);
48
+ },
49
+ (error) => {
50
+ clearTimeout(timer);
51
+ reject(error);
52
+ }
53
+ );
54
+ });
55
+ }
56
+
57
+ export {
58
+ CANCEL_QUERY_TIMEOUT_MS,
59
+ MAX_QUERY_TIMEOUT_SECONDS,
60
+ clientQueryTimeoutMs,
61
+ isClientSideTimeout,
62
+ withClientQueryDeadline
63
+ };