@staff0rd/assist 0.296.0 → 0.296.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.
Files changed (2) hide show
  1. package/dist/index.js +42 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.296.0",
9
+ version: "0.296.1",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -599,7 +599,19 @@ function getBacklogOrm() {
599
599
  if (_orm) return Promise.resolve(_orm);
600
600
  if (_connecting) return _connecting;
601
601
  _connecting = (async () => {
602
- const pool = new Pool({ connectionString: getDatabaseUrl() });
602
+ const pool = new Pool({
603
+ connectionString: getDatabaseUrl(),
604
+ max: 10,
605
+ // why: retire idle clients before managed Postgres (Supabase/Neon) drops them server-side, so we never check out a dead socket and stall on a timeout.
606
+ idleTimeoutMillis: 3e4,
607
+ // why: bound the wait for a free client so a degraded pool fails fast (500 + log line) rather than hanging for seconds.
608
+ connectionTimeoutMillis: 1e4
609
+ });
610
+ pool.on("error", (err) => {
611
+ console.error(
612
+ `${(/* @__PURE__ */ new Date()).toISOString()} backlog pool error: ${err.message}`
613
+ );
614
+ });
603
615
  _pool = pool;
604
616
  await ensureSchema((sql4) => pool.query(sql4));
605
617
  _orm = makeOrmFromPool(pool);
@@ -4454,6 +4466,33 @@ ${url}`);
4454
4466
  }
4455
4467
  }
4456
4468
 
4469
+ // src/shared/runHandler.ts
4470
+ var SLOW_REQUEST_MS = 1e3;
4471
+ function logRequest(method, url, status2, ms) {
4472
+ const slow = ms >= SLOW_REQUEST_MS;
4473
+ if (!slow && !process.env.ASSIST_WEB_LOG) return;
4474
+ console.log(
4475
+ `${(/* @__PURE__ */ new Date()).toISOString()} ${method} ${url} ${status2} ${ms}ms${slow ? " SLOW" : ""}`
4476
+ );
4477
+ }
4478
+ function runHandler(handler, req, res, port) {
4479
+ const startedAt = Date.now();
4480
+ const method = req.method ?? "GET";
4481
+ const url = req.url ?? "/";
4482
+ res.on("finish", () => {
4483
+ logRequest(method, url, res.statusCode, Date.now() - startedAt);
4484
+ });
4485
+ Promise.resolve(handler(req, res, port)).catch((err) => {
4486
+ console.error(
4487
+ `${(/* @__PURE__ */ new Date()).toISOString()} ${method} ${url} failed: ${err instanceof Error ? err.message : String(err)}`
4488
+ );
4489
+ if (!res.headersSent)
4490
+ res.writeHead(500, { "Content-Type": "application/json" });
4491
+ if (!res.writableEnded)
4492
+ res.end(JSON.stringify({ error: "internal error" }));
4493
+ });
4494
+ }
4495
+
4457
4496
  // src/shared/web.ts
4458
4497
  function respondJson(res, status2, data) {
4459
4498
  res.writeHead(status2, { "Content-Type": "application/json" });
@@ -4488,7 +4527,7 @@ function buildUrl(port, initialPath) {
4488
4527
  function startWebServer(label2, port, handler, initialPath, open = true) {
4489
4528
  const url = buildUrl(port, initialPath);
4490
4529
  const server = createServer((req, res) => {
4491
- handler(req, res, port);
4530
+ runHandler(handler, req, res, port);
4492
4531
  });
4493
4532
  server.listen(port, () => {
4494
4533
  console.log(chalk43.green(`${label2}: ${url}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.296.0",
3
+ "version": "0.296.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {