@steve31415/baselib 3.64.1 → 3.65.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/http.d.ts CHANGED
@@ -25,10 +25,16 @@ export interface StartServerOptions {
25
25
  app: Hono;
26
26
  logger: Logger;
27
27
  port?: number;
28
+ /** Work to finish on SIGTERM before the process exits — work that is not
29
+ * an HTTP request, which closing the server does not wait for (radar's
30
+ * timer-driven held sends, 2026-11-16). Awaited after the server stops
31
+ * accepting; still bounded by the 5 s exit, inside Cloud Run's 10 s
32
+ * grace. A rejection is logged and the exit goes on. */
33
+ beforeExit?: () => Promise<unknown>;
28
34
  }
29
35
  /** Standard entry point: safety check, crash logging (logUncaughtErrors),
30
36
  * serve, graceful SIGTERM shutdown
31
- * (stop accepting, then flush all loggers, then exit). Returns the Node
37
+ * (stop accepting, then `beforeExit`, then flush all loggers, then exit). Returns the Node
32
38
  * server so callers can attach protocol upgrades (e.g. @hono/node-ws's
33
39
  * injectWebSocket). */
34
40
  export declare function startServer(opts: StartServerOptions): ReturnType<typeof serve>;
package/dist/http.js CHANGED
@@ -65,7 +65,7 @@ export function errorHandler(logger) {
65
65
  }
66
66
  /** Standard entry point: safety check, crash logging (logUncaughtErrors),
67
67
  * serve, graceful SIGTERM shutdown
68
- * (stop accepting, then flush all loggers, then exit). Returns the Node
68
+ * (stop accepting, then `beforeExit`, then flush all loggers, then exit). Returns the Node
69
69
  * server so callers can attach protocol upgrades (e.g. @hono/node-ws's
70
70
  * injectWebSocket). */
71
71
  export function startServer(opts) {
@@ -80,11 +80,14 @@ export function startServer(opts) {
80
80
  });
81
81
  process.once('SIGTERM', () => {
82
82
  opts.logger.info('SIGTERM received, shutting down');
83
+ const drained = opts.beforeExit
84
+ ? opts.beforeExit().catch((error) => opts.logger.error('beforeExit failed', { error: error instanceof Error ? error.message : String(error) }))
85
+ : Promise.resolve();
83
86
  // final: last-chance delivery + drop markers, time-boxed. The two racing
84
87
  // callers below join the same single-flight finalFlush, so whichever
85
88
  // fires second waits for the real work instead of exiting under it.
86
89
  server.close(() => {
87
- void flushAllLoggers({ final: true }).finally(() => process.exit(0));
90
+ void drained.finally(() => flushAllLoggers({ final: true }).finally(() => process.exit(0)));
88
91
  });
89
92
  // Cloud Run's grace period is 10s; don't rely on every socket closing.
90
93
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.64.1",
3
+ "version": "3.65.0",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",