@steve31415/baselib 2.2.0 → 2.2.2

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.
@@ -1,5 +1,4 @@
1
1
  import type { Logger } from '../log-browser.js';
2
- import type { ReloadSafety } from './reload-safety.js';
3
2
  export type BuildUpdateState = {
4
3
  kind: 'current';
5
4
  } | {
@@ -9,9 +8,13 @@ export type BuildUpdateState = {
9
8
  kind: 'reloading';
10
9
  buildId: string;
11
10
  };
11
+ export interface ReloadSafetyState {
12
+ readonly isSafe: () => boolean;
13
+ readonly subscribe: (listener: () => void) => () => void;
14
+ }
12
15
  export interface BuildUpdateDeps {
13
16
  currentBuildId: string;
14
- safety: ReloadSafety;
17
+ safety: ReloadSafetyState;
15
18
  logger: Pick<Logger, 'info' | 'warn'>;
16
19
  fetchFn?: (input: string, init?: RequestInit) => Promise<Response>;
17
20
  reload?: () => void;
package/dist/db.d.ts CHANGED
@@ -6,6 +6,14 @@ export interface PoolOptions {
6
6
  max?: number;
7
7
  }
8
8
  export declare function createPool(opts?: PoolOptions): Promise<pg.Pool>;
9
+ /** End a pool and resolve only once every client's connection has actually
10
+ * closed. pg-pool's own `end()` resolves as soon as it has *asked* its idle
11
+ * clients to close — their sockets are still open — so a caller that then
12
+ * drops the database `with (force)` can kill a backend mid-goodbye, and the
13
+ * FATAL it sends back surfaces as an unhandled pool 'error' (it took down a
14
+ * todo2 deploy with every test green, 2026-08-20). pg-pool emits 'remove' for
15
+ * each client once its socket has closed; wait for all of them. */
16
+ export declare function endPool(pool: pg.Pool): Promise<void>;
9
17
  export declare function migrate(pool: pg.Pool, migrationsDir: string, logger?: Logger): Promise<{
10
18
  applied: string[];
11
19
  }>;
package/dist/db.js CHANGED
@@ -35,6 +35,26 @@ export async function createPool(opts = {}) {
35
35
  url.pathname = `/${opts.database}`;
36
36
  return new pg.Pool({ connectionString: url.toString(), max: opts.max ?? 5 });
37
37
  }
38
+ /** End a pool and resolve only once every client's connection has actually
39
+ * closed. pg-pool's own `end()` resolves as soon as it has *asked* its idle
40
+ * clients to close — their sockets are still open — so a caller that then
41
+ * drops the database `with (force)` can kill a backend mid-goodbye, and the
42
+ * FATAL it sends back surfaces as an unhandled pool 'error' (it took down a
43
+ * todo2 deploy with every test green, 2026-08-20). pg-pool emits 'remove' for
44
+ * each client once its socket has closed; wait for all of them. */
45
+ export async function endPool(pool) {
46
+ let open = pool.totalCount;
47
+ const allClosed = new Promise((resolve) => {
48
+ if (open === 0)
49
+ return resolve();
50
+ pool.on('remove', () => {
51
+ if (--open === 0)
52
+ resolve();
53
+ });
54
+ });
55
+ await pool.end();
56
+ await allClosed;
57
+ }
38
58
  // Plain-SQL migrations: numbered files (001-*.sql, 002-*.sql, …) applied in
39
59
  // order, recorded in schema_migrations, each inside a transaction, guarded by
40
60
  // an advisory lock so concurrent boots can't race. Applied at service boot.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
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",