@compforge/harness-toolbox 0.3.5 → 0.3.8

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.
@@ -0,0 +1,11 @@
1
+ // src/mysql/connection.ts
2
+ function destroyMysqlConnection(connection) {
3
+ const native = connection.connection;
4
+ try {
5
+ connection.destroy();
6
+ } finally {
7
+ native.stream.destroy();
8
+ }
9
+ }
10
+
11
+ export { destroyMysqlConnection };
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-6fnhzhdb.js";
9
9
  import {
10
10
  PortForwardScope
11
- } from "./chunk-xh3zwhjh.js";
11
+ } from "./chunk-631vce5z.js";
12
12
 
13
13
  // src/kubernetes/service-port-forward.ts
14
14
  class ServicePortForwarder {
@@ -2,7 +2,6 @@ import {
2
2
  buildKubectlArgs
3
3
  } from "./chunk-hmah9t8e.js";
4
4
  import {
5
- sleep,
6
5
  spawnProcess
7
6
  } from "./chunk-mn6dwsvh.js";
8
7
 
@@ -34,11 +33,16 @@ async function startPortForward(opts) {
34
33
  const remain = deadline - Date.now();
35
34
  if (remain <= 0)
36
35
  break;
36
+ let timer;
37
37
  const chunk = await Promise.race([
38
38
  reader.read(),
39
- sleep(remain).then(() => "timeout"),
39
+ new Promise((resolve) => {
40
+ timer = setTimeout(() => resolve("timeout"), remain);
41
+ }),
40
42
  proc.exited.then(() => "exited").catch((error) => ({ error }))
41
- ]);
43
+ ]).finally(() => {
44
+ clearTimeout(timer);
45
+ });
42
46
  if (chunk === "timeout")
43
47
  break;
44
48
  if (typeof chunk === "object" && "error" in chunk) {
@@ -1,3 +1,7 @@
1
+ import {
2
+ destroyMysqlConnection
3
+ } from "./chunk-136egyff.js";
4
+
1
5
  // src/mysql/readonly.ts
2
6
  function validateQueryLimits(limits) {
3
7
  for (const name of ["timeoutMs", "maxRows", "maxBytes"]) {
@@ -23,7 +27,7 @@ async function queryReadonlySession(connection, sql, values, limits, signal) {
23
27
  })(),
24
28
  new Promise((_resolve, reject) => {
25
29
  const fail = (reason) => {
26
- connection.destroy();
30
+ destroyMysqlConnection(connection);
27
31
  reject(reason);
28
32
  };
29
33
  abort = () => fail(signal?.reason ?? new Error("MySQL query cancelled"));
@@ -38,7 +42,7 @@ async function queryReadonlySession(connection, sql, values, limits, signal) {
38
42
  clearTimeout(timer);
39
43
  if (abort)
40
44
  signal?.removeEventListener("abort", abort);
41
- connection.destroy();
45
+ destroyMysqlConnection(connection);
42
46
  }
43
47
  }
44
48
  function collectRows(connection, sql, values, limits) {
@@ -64,21 +68,21 @@ function collectRows(connection, sql, values, limits) {
64
68
  return;
65
69
  if (result.rows.length >= limits.maxRows) {
66
70
  finish("rows");
67
- connection.destroy();
71
+ destroyMysqlConnection(connection);
68
72
  return;
69
73
  }
70
74
  try {
71
75
  const bytes = Buffer.byteLength(JSON.stringify(row));
72
76
  if (result.bytes + bytes > limits.maxBytes) {
73
77
  finish("bytes");
74
- connection.destroy();
78
+ destroyMysqlConnection(connection);
75
79
  return;
76
80
  }
77
81
  result.rows.push(row);
78
82
  result.bytes += bytes;
79
83
  } catch (error) {
80
84
  settled = true;
81
- connection.destroy();
85
+ destroyMysqlConnection(connection);
82
86
  reject(error);
83
87
  }
84
88
  });
@@ -2,7 +2,7 @@ import {
2
2
  KubernetesError,
3
3
  ToolboxError,
4
4
  kubernetesHttpError
5
- } from "./chunk-ntfm5e85.js";
5
+ } from "./chunk-zhkrydeg.js";
6
6
  import {
7
7
  ConcurrencyPool
8
8
  } from "./chunk-v3hxvnrc.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  KubernetesError
3
- } from "./chunk-ntfm5e85.js";
3
+ } from "./chunk-zhkrydeg.js";
4
4
 
5
5
  // src/kubernetes/workload.ts
6
6
  function failure(message, kind) {
@@ -1,11 +1,14 @@
1
+ import {
2
+ queryReadonlySession,
3
+ validateQueryLimits
4
+ } from "./chunk-age65q4n.js";
5
+ import {
6
+ destroyMysqlConnection
7
+ } from "./chunk-136egyff.js";
1
8
  import {
2
9
  queryMysqlViaPod,
3
10
  queryMysqlViaPodBatch
4
11
  } from "./chunk-m91t44jh.js";
5
- import {
6
- queryReadonlySession,
7
- validateQueryLimits
8
- } from "./chunk-kbewz29a.js";
9
12
  import {
10
13
  ConcurrencyPool
11
14
  } from "./chunk-v3hxvnrc.js";
@@ -54,7 +57,7 @@ class MysqlDatabase {
54
57
  try {
55
58
  return await queryReadonlySession(session.connection, sql, values, limits, this.options.signal);
56
59
  } finally {
57
- session.connection.destroy();
60
+ destroyMysqlConnection(session.connection);
58
61
  }
59
62
  }, this.options.signal);
60
63
  }
@@ -90,7 +93,7 @@ class MysqlDatabase {
90
93
  if (this.#connections.get(key) === pending)
91
94
  this.#connections.delete(key);
92
95
  if (session?.kind === "tcp")
93
- session.connection.destroy();
96
+ destroyMysqlConnection(session.connection);
94
97
  throw error;
95
98
  }
96
99
  }
@@ -143,7 +146,7 @@ class MysqlDatabase {
143
146
  this.#connections.clear();
144
147
  for (const result of await Promise.allSettled(pending)) {
145
148
  if (result.status === "fulfilled" && result.value.kind === "tcp")
146
- result.value.connection.destroy();
149
+ destroyMysqlConnection(result.value.connection);
147
150
  }
148
151
  });
149
152
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  startPortForward
3
- } from "./chunk-xh3zwhjh.js";
3
+ } from "./chunk-631vce5z.js";
4
4
  import {
5
5
  KubectlExecutor
6
6
  } from "./chunk-hmah9t8e.js";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  ServicePortForwarder
3
- } from "./chunk-qhpqse1y.js";
3
+ } from "./chunk-2171tajs.js";
4
4
  import {
5
5
  resourceAccess
6
- } from "./chunk-2m0mh09h.js";
6
+ } from "./chunk-fhtbvj0s.js";
7
7
  import {
8
8
  resolveWorkload
9
- } from "./chunk-y3dx8jh6.js";
9
+ } from "./chunk-p6k59m3q.js";
10
10
  import {
11
11
  KubernetesError
12
- } from "./chunk-ntfm5e85.js";
12
+ } from "./chunk-zhkrydeg.js";
13
13
  import {
14
14
  KubectlExecutor
15
15
  } from "./chunk-hmah9t8e.js";
@@ -0,0 +1,41 @@
1
+ // src/errors.ts
2
+ class ToolboxError extends Error {
3
+ kind;
4
+ code;
5
+ constructor(message, options) {
6
+ super(message, { cause: options.cause });
7
+ this.name = new.target.name;
8
+ this.kind = options.kind;
9
+ this.code = options.code;
10
+ }
11
+ }
12
+
13
+ class KubernetesError extends ToolboxError {
14
+ }
15
+ function kubernetesHttpError(status) {
16
+ const kind = {
17
+ 401: "authentication_failed",
18
+ 403: "permission_denied",
19
+ 404: "resource_not_found",
20
+ 408: "timeout",
21
+ 429: "limit_exceeded",
22
+ 504: "timeout"
23
+ }[status] ?? "operation_failed";
24
+ return new KubernetesError("Kubernetes resource request failed", { kind, code: status });
25
+ }
26
+ function kubernetesCommandError(result) {
27
+ if (result.timedOut)
28
+ return new KubernetesError("Kubernetes resource request timed out", { kind: "timeout" });
29
+ const reason = /^Error from server \(([^)]+)\):/m.exec(result.stderr)?.[1];
30
+ const status = reason ? {
31
+ Unauthorized: 401,
32
+ Forbidden: 403,
33
+ NotFound: 404,
34
+ Timeout: 408,
35
+ TooManyRequests: 429,
36
+ ServerTimeout: 504
37
+ }[reason] : undefined;
38
+ return status ? kubernetesHttpError(status) : new KubernetesError("Kubernetes resource request failed", { kind: "operation_failed" });
39
+ }
40
+
41
+ export { ToolboxError, KubernetesError, kubernetesHttpError, kubernetesCommandError };
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  KubernetesError,
8
8
  ToolboxError
9
- } from "./chunk-ntfm5e85.js";
9
+ } from "./chunk-zhkrydeg.js";
10
10
  export {
11
11
  clientKey,
12
12
  ToolboxError,
package/dist/errors.d.ts CHANGED
@@ -12,3 +12,13 @@ export declare class ToolboxError extends Error {
12
12
  export declare class KubernetesError extends ToolboxError {
13
13
  }
14
14
  export declare function kubernetesHttpError(status: number): KubernetesError;
15
+ /**
16
+ * Normalize a failed kubectl resource request at the transport boundary.
17
+ * Only the server's Status reason is authoritative; arbitrary stderr containing
18
+ * "not found" (including a missing kubectl binary) does not prove resource absence.
19
+ * Do not apply this to a command executed inside a container.
20
+ */
21
+ export declare function kubernetesCommandError(result: {
22
+ stderr: string;
23
+ timedOut: boolean;
24
+ }): KubernetesError;
package/dist/errors.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  KubernetesError,
3
3
  ToolboxError,
4
+ kubernetesCommandError,
4
5
  kubernetesHttpError
5
- } from "./chunk-ntfm5e85.js";
6
+ } from "./chunk-zhkrydeg.js";
6
7
  export {
7
8
  kubernetesHttpError,
9
+ kubernetesCommandError,
8
10
  ToolboxError,
9
11
  KubernetesError
10
12
  };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  KubernetesClient
3
- } from "../chunk-bg1syayb.js";
4
- import"../chunk-qhpqse1y.js";
3
+ } from "../chunk-y94xq8b4.js";
4
+ import"../chunk-2171tajs.js";
5
5
  import"../chunk-j46x7j7c.js";
6
6
  import"../chunk-6fnhzhdb.js";
7
- import"../chunk-2m0mh09h.js";
8
- import"../chunk-y3dx8jh6.js";
9
- import"../chunk-ntfm5e85.js";
7
+ import"../chunk-fhtbvj0s.js";
8
+ import"../chunk-p6k59m3q.js";
9
+ import"../chunk-zhkrydeg.js";
10
10
  import"../chunk-v3hxvnrc.js";
11
- import"../chunk-xh3zwhjh.js";
11
+ import"../chunk-631vce5z.js";
12
12
  import"../chunk-hmah9t8e.js";
13
13
  import"../chunk-mn6dwsvh.js";
14
14
  export {
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  KubernetesClient
3
- } from "../chunk-bg1syayb.js";
4
- import"../chunk-qhpqse1y.js";
3
+ } from "../chunk-y94xq8b4.js";
4
+ import"../chunk-2171tajs.js";
5
5
  import"../chunk-j46x7j7c.js";
6
6
  import"../chunk-6fnhzhdb.js";
7
- import"../chunk-2m0mh09h.js";
8
- import"../chunk-y3dx8jh6.js";
7
+ import"../chunk-fhtbvj0s.js";
8
+ import"../chunk-p6k59m3q.js";
9
9
  import {
10
10
  clientKey
11
11
  } from "../chunk-a9htb6cr.js";
12
- import"../chunk-ntfm5e85.js";
12
+ import"../chunk-zhkrydeg.js";
13
13
  import"../chunk-v3hxvnrc.js";
14
- import"../chunk-xh3zwhjh.js";
14
+ import"../chunk-631vce5z.js";
15
15
  import"../chunk-hmah9t8e.js";
16
16
  import"../chunk-mn6dwsvh.js";
17
17
 
@@ -8,7 +8,7 @@ import"../chunk-a9htb6cr.js";
8
8
  import {
9
9
  clientKey
10
10
  } from "../chunk-z5pm2emz.js";
11
- import"../chunk-ntfm5e85.js";
11
+ import"../chunk-zhkrydeg.js";
12
12
  import"../chunk-v3hxvnrc.js";
13
13
 
14
14
  // src/kubernetes/pod-log-datasource.ts
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PortForwardScope,
3
3
  startPortForward
4
- } from "../chunk-xh3zwhjh.js";
4
+ } from "../chunk-631vce5z.js";
5
5
  import"../chunk-hmah9t8e.js";
6
6
  import"../chunk-mn6dwsvh.js";
7
7
  export {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  resourceAccess
3
- } from "../chunk-2m0mh09h.js";
4
- import"../chunk-ntfm5e85.js";
3
+ } from "../chunk-fhtbvj0s.js";
4
+ import"../chunk-zhkrydeg.js";
5
5
  import"../chunk-v3hxvnrc.js";
6
6
  export {
7
7
  resourceAccess
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  ServicePortForwarder
3
- } from "../chunk-qhpqse1y.js";
3
+ } from "../chunk-2171tajs.js";
4
4
  import"../chunk-j46x7j7c.js";
5
5
  import"../chunk-6fnhzhdb.js";
6
- import"../chunk-xh3zwhjh.js";
6
+ import"../chunk-631vce5z.js";
7
7
  import"../chunk-hmah9t8e.js";
8
8
  import"../chunk-mn6dwsvh.js";
9
9
  export {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  resolveWorkload
3
- } from "../chunk-y3dx8jh6.js";
4
- import"../chunk-ntfm5e85.js";
3
+ } from "../chunk-p6k59m3q.js";
4
+ import"../chunk-zhkrydeg.js";
5
5
  export {
6
6
  resolveWorkload
7
7
  };
@@ -2,13 +2,14 @@ import {
2
2
  MysqlClient,
3
3
  MysqlDatabase,
4
4
  openMysql
5
- } from "../chunk-56t4qyp7.js";
5
+ } from "../chunk-qqntng20.js";
6
+ import"../chunk-age65q4n.js";
7
+ import"../chunk-136egyff.js";
6
8
  import"../chunk-m91t44jh.js";
7
- import"../chunk-kbewz29a.js";
8
9
  import"../chunk-v3hxvnrc.js";
9
10
  import"../chunk-h8fwx0k7.js";
10
- import"../chunk-5fgbhx2r.js";
11
- import"../chunk-xh3zwhjh.js";
11
+ import"../chunk-wv4jwhvj.js";
12
+ import"../chunk-631vce5z.js";
12
13
  import"../chunk-hmah9t8e.js";
13
14
  import"../chunk-mn6dwsvh.js";
14
15
  import"../chunk-ssj93brx.js";
@@ -0,0 +1,3 @@
1
+ import type { Connection } from "mysql2/promise";
2
+ /** @why Disposal must release the socket even when the peer never finishes its TCP half-close. */
3
+ export declare function destroyMysqlConnection(connection: Connection): void;
@@ -0,0 +1,6 @@
1
+ import {
2
+ destroyMysqlConnection
3
+ } from "../chunk-136egyff.js";
4
+ export {
5
+ destroyMysqlConnection
6
+ };
@@ -14,13 +14,14 @@ import {
14
14
  MysqlClient,
15
15
  MysqlDatabase,
16
16
  openMysql
17
- } from "../chunk-56t4qyp7.js";
17
+ } from "../chunk-qqntng20.js";
18
+ import"../chunk-age65q4n.js";
19
+ import"../chunk-136egyff.js";
18
20
  import"../chunk-m91t44jh.js";
19
- import"../chunk-kbewz29a.js";
20
21
  import"../chunk-v3hxvnrc.js";
21
22
  import"../chunk-h8fwx0k7.js";
22
- import"../chunk-5fgbhx2r.js";
23
- import"../chunk-xh3zwhjh.js";
23
+ import"../chunk-wv4jwhvj.js";
24
+ import"../chunk-631vce5z.js";
24
25
  import"../chunk-hmah9t8e.js";
25
26
  import"../chunk-mn6dwsvh.js";
26
27
  import"../chunk-ssj93brx.js";
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  queryReadonlySession,
3
3
  validateQueryLimits
4
- } from "../chunk-kbewz29a.js";
4
+ } from "../chunk-age65q4n.js";
5
+ import"../chunk-136egyff.js";
5
6
  export {
6
7
  validateQueryLimits,
7
8
  queryReadonlySession
@@ -2,13 +2,13 @@ import {
2
2
  S3DataSource
3
3
  } from "../chunk-35cjec9z.js";
4
4
  import"../chunk-z5pm2emz.js";
5
- import"../chunk-ntfm5e85.js";
5
+ import"../chunk-zhkrydeg.js";
6
6
  import"../chunk-zp1s833x.js";
7
7
  import"../chunk-v3hxvnrc.js";
8
8
  import"../chunk-x4ntb898.js";
9
9
  import"../chunk-h8fwx0k7.js";
10
- import"../chunk-5fgbhx2r.js";
11
- import"../chunk-xh3zwhjh.js";
10
+ import"../chunk-wv4jwhvj.js";
11
+ import"../chunk-631vce5z.js";
12
12
  import"../chunk-hmah9t8e.js";
13
13
  import"../chunk-mn6dwsvh.js";
14
14
  import"../chunk-ssj93brx.js";
package/dist/s3/index.js CHANGED
@@ -2,15 +2,15 @@ import {
2
2
  S3DataSource
3
3
  } from "../chunk-35cjec9z.js";
4
4
  import"../chunk-z5pm2emz.js";
5
- import"../chunk-ntfm5e85.js";
5
+ import"../chunk-zhkrydeg.js";
6
6
  import {
7
7
  S3Client
8
8
  } from "../chunk-zp1s833x.js";
9
9
  import"../chunk-v3hxvnrc.js";
10
10
  import"../chunk-x4ntb898.js";
11
11
  import"../chunk-h8fwx0k7.js";
12
- import"../chunk-5fgbhx2r.js";
13
- import"../chunk-xh3zwhjh.js";
12
+ import"../chunk-wv4jwhvj.js";
13
+ import"../chunk-631vce5z.js";
14
14
  import"../chunk-hmah9t8e.js";
15
15
  import"../chunk-mn6dwsvh.js";
16
16
  import"../chunk-ssj93brx.js";
@@ -1,4 +1,10 @@
1
1
  export interface S3Target {
2
+ /**
3
+ * Complete endpoint URL, including the scheme, host and any non-default port.
4
+ * A Kubernetes Service host includes its namespace (for example, http://s3.storage:9000).
5
+ * The source resolves the full address; downstream clients and transports use it as-is,
6
+ * without appending host suffixes or inferring a namespace from the consuming Service.
7
+ */
2
8
  endpoint: string;
3
9
  region: string;
4
10
  credentials: {
@@ -6,8 +6,8 @@ import {
6
6
  } from "../chunk-h8fwx0k7.js";
7
7
  import {
8
8
  PodRelayTransport
9
- } from "../chunk-5fgbhx2r.js";
10
- import"../chunk-xh3zwhjh.js";
9
+ } from "../chunk-wv4jwhvj.js";
10
+ import"../chunk-631vce5z.js";
11
11
  import"../chunk-hmah9t8e.js";
12
12
  import"../chunk-mn6dwsvh.js";
13
13
  import"../chunk-ssj93brx.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PodRelayTransport
3
- } from "../chunk-5fgbhx2r.js";
4
- import"../chunk-xh3zwhjh.js";
3
+ } from "../chunk-wv4jwhvj.js";
4
+ import"../chunk-631vce5z.js";
5
5
  import"../chunk-hmah9t8e.js";
6
6
  import"../chunk-mn6dwsvh.js";
7
7
  import"../chunk-ssj93brx.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compforge/harness-toolbox",
3
- "version": "0.3.5",
3
+ "version": "0.3.8",
4
4
  "description": "Shared infrastructure clients, transports and bounded data capture",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,27 +0,0 @@
1
- // src/errors.ts
2
- class ToolboxError extends Error {
3
- kind;
4
- code;
5
- constructor(message, options) {
6
- super(message, { cause: options.cause });
7
- this.name = new.target.name;
8
- this.kind = options.kind;
9
- this.code = options.code;
10
- }
11
- }
12
-
13
- class KubernetesError extends ToolboxError {
14
- }
15
- function kubernetesHttpError(status) {
16
- const kind = {
17
- 401: "authentication_failed",
18
- 403: "permission_denied",
19
- 404: "resource_not_found",
20
- 408: "timeout",
21
- 429: "limit_exceeded",
22
- 504: "timeout"
23
- }[status] ?? "operation_failed";
24
- return new KubernetesError("Kubernetes resource request failed", { kind, code: status });
25
- }
26
-
27
- export { ToolboxError, KubernetesError, kubernetesHttpError };