@byline/db-postgres 2.2.2 → 2.2.4

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/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface PgAdapter extends IDbAdapter {
24
24
  /** The pg connection pool — exposed for housekeeping and teardown. */
25
25
  pool: pg.Pool;
26
26
  }
27
- export declare const pgAdapter: ({ connectionString, collections, defaultContentLocale, }: {
27
+ export declare const pgAdapter: ({ connectionString, collections, defaultContentLocale, max, idleTimeoutMillis, connectionTimeoutMillis, }: {
28
28
  connectionString: string;
29
29
  collections: CollectionDefinition[];
30
30
  /**
@@ -35,4 +35,21 @@ export declare const pgAdapter: ({ connectionString, collections, defaultContent
35
35
  * functions tag default-locale path rows with this value.
36
36
  */
37
37
  defaultContentLocale: string;
38
+ /**
39
+ * Maximum number of clients in the pg connection pool. Defaults to 20.
40
+ * Tune via `BYLINE_DB_POSTGRES_MAX_POOL` in the host app.
41
+ */
42
+ max?: number;
43
+ /**
44
+ * Milliseconds an idle client remains in the pool before being closed.
45
+ * Defaults to 2000. Tune via `BYLINE_DB_POSTGRES_IDLE_TIMEOUT_MILLIS`.
46
+ */
47
+ idleTimeoutMillis?: number;
48
+ /**
49
+ * Milliseconds to wait for a new connection before erroring. Defaults
50
+ * to 30000 — long enough to absorb cold starts on serverless Postgres
51
+ * providers like Neon. Tune via
52
+ * `BYLINE_DB_POSTGRES_CONNECTION_TIMEOUT_MILLIS`.
53
+ */
54
+ connectionTimeoutMillis?: number;
38
55
  }) => PgAdapter;
package/dist/index.js CHANGED
@@ -11,12 +11,12 @@ import * as schema from './database/schema/index.js';
11
11
  import { createCounterCommands } from './modules/counters/counters-commands.js';
12
12
  import { createCommandBuilders } from './modules/storage/storage-commands.js';
13
13
  import { createQueryBuilders } from './modules/storage/storage-queries.js';
14
- export const pgAdapter = ({ connectionString, collections, defaultContentLocale, }) => {
14
+ export const pgAdapter = ({ connectionString, collections, defaultContentLocale, max = 20, idleTimeoutMillis = 2000, connectionTimeoutMillis = 30000, }) => {
15
15
  const pool = new pg.Pool({
16
16
  connectionString: connectionString,
17
- max: 20,
18
- idleTimeoutMillis: 2000,
19
- connectionTimeoutMillis: 1000,
17
+ max,
18
+ idleTimeoutMillis,
19
+ connectionTimeoutMillis,
20
20
  });
21
21
  const db = drizzle(pool, { schema });
22
22
  const commandBuilders = createCommandBuilders(db, defaultContentLocale);
@@ -33,7 +33,7 @@ const MIGRATIONS_FOLDER = path.resolve(__dirname, '../../src/database/migrations
33
33
  */
34
34
  export function assertTestDatabase(connectionString) {
35
35
  if (!connectionString) {
36
- throw new Error('POSTGRES_CONNECTION_STRING is not set. Copy .env.test.example to .env.test.');
36
+ throw new Error('BYLINE_DB_POSTGRES_CONNECTION_STRING is not set. Copy .env.test.example to .env.test.');
37
37
  }
38
38
  let dbName;
39
39
  try {
@@ -41,12 +41,12 @@ export function assertTestDatabase(connectionString) {
41
41
  dbName = url.pathname.replace(/^\//, '');
42
42
  }
43
43
  catch (err) {
44
- throw new Error(`POSTGRES_CONNECTION_STRING is not a valid URL: ${err.message}`);
44
+ throw new Error(`BYLINE_DB_POSTGRES_CONNECTION_STRING is not a valid URL: ${err.message}`);
45
45
  }
46
46
  if (!dbName.endsWith('_test')) {
47
47
  throw new Error(`Refusing to run tests against database '${dbName}'. ` +
48
48
  `Integration tests require a database whose name ends in '_test'. ` +
49
- `Update POSTGRES_CONNECTION_STRING in .env.test.`);
49
+ `Update BYLINE_DB_POSTGRES_CONNECTION_STRING in .env.test.`);
50
50
  }
51
51
  return dbName;
52
52
  }
@@ -10,9 +10,9 @@ let commandBuilders;
10
10
  let queryBuilders;
11
11
  export function setupTestDB(collections = []) {
12
12
  if (!pool) {
13
- assertTestDatabase(process.env.POSTGRES_CONNECTION_STRING);
13
+ assertTestDatabase(process.env.BYLINE_DB_POSTGRES_CONNECTION_STRING);
14
14
  pool = new pg.Pool({
15
- connectionString: process.env.POSTGRES_CONNECTION_STRING,
15
+ connectionString: process.env.BYLINE_DB_POSTGRES_CONNECTION_STRING,
16
16
  // node:test runs each test file in its own process. Even though
17
17
  // tests target a dedicated `byline_test` database, a pool-per-file
18
18
  // of 20 connections × N files can still pressure Postgres's default
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@byline/db-postgres",
3
3
  "private": false,
4
4
  "license": "MPL-2.0",
5
- "version": "2.2.2",
5
+ "version": "2.2.4",
6
6
  "engines": {
7
7
  "node": ">=20.9.0"
8
8
  },
@@ -57,9 +57,9 @@
57
57
  "pg": "^8.20.0",
58
58
  "uuid": "^14.0.0",
59
59
  "zod": "^4.4.3",
60
- "@byline/admin": "2.2.2",
61
- "@byline/auth": "2.2.2",
62
- "@byline/core": "2.2.2"
60
+ "@byline/auth": "2.2.4",
61
+ "@byline/core": "2.2.4",
62
+ "@byline/admin": "2.2.4"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@biomejs/biome": "2.4.15",