@haatlabs-core/db-core 0.10.0 → 0.11.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.
@@ -9,6 +9,13 @@ export interface DatabaseHandle {
9
9
  db: Database;
10
10
  close(): Promise<void>;
11
11
  }
12
+ /** What createDatabase tells when the server closes a connection: a pino logger fits. */
13
+ export interface DatabaseLogger {
14
+ warn(fields: {
15
+ err: Error;
16
+ }, message: string): void;
17
+ }
12
18
  export declare function createDatabase(url: string, options?: {
13
19
  max?: number;
20
+ logger?: DatabaseLogger;
14
21
  }): DatabaseHandle;
@@ -40,6 +40,9 @@ function createDatabase(url, options = {}) {
40
40
  max: options.max ?? DEFAULT_POOL_SIZE,
41
41
  idleTimeoutMillis: IDLE_TIMEOUT_MS
42
42
  });
43
+ pool.on("error", (err) => {
44
+ options.logger?.warn({ err }, "Database connection closed by the server; the next query opens a new one");
45
+ });
43
46
  const open = /* @__PURE__ */ new Set();
44
47
  pool.on("connect", (client) => {
45
48
  open.add(client);
@@ -1,5 +1,5 @@
1
1
  export { createDatabase } from './client.js';
2
- export type { Database, DatabaseHandle, Tx } from './client.js';
2
+ export type { Database, DatabaseHandle, DatabaseLogger, Tx } from './client.js';
3
3
  export { ORGANIZATION_GOES_FIRST_SQL, apiKeyColumns, auditLogColumns, auditLogIndexes, membershipColumns, membershipIndexes, organizationColumns, organizationFeatureColumns, organizationFeatureIndexes, allowanceGrantColumns, allowanceGrantIndexes, organizationOriginEnum, outboxMessageColumns, outboxMessageIndexes, outboxPriorityColumn, paymentEventColumns, paymentEventIndexes, planColumns, planFeatureColumns, planFeatureIndexes, planIndexes, planPriceColumns, planPriceIndexes, platformAdminColumns, roleEnum, shopifyInstallationColumns, subscriptionColumns, subscriptionStatusEnum, timestamps, usageRecordColumns, usageRecordIndexes, userColumns, webhookEventColumns, extensionKeyColumns, extensionKeyIndexes, } from './columns.js';
4
4
  export type { ApiKeysTable, ExtensionKeysTable, AuditLogsTable, MembershipsTable, OrganizationsTable, OrganizationFeaturesTable, AllowanceGrantsTable, OutboxMessagesTable, PaymentEventsTable, PlanFeaturesTable, PlanPricesTable, PlansTable, PlatformAdminsTable, ShopifyInstallationsTable, SubscriptionsTable, UsageRecordsTable, UsersTable, WebhookEventsTable, } from './columns.js';
5
5
  export { isUniqueViolation } from './errors.js';
@@ -1,8 +1,3 @@
1
1
  {
2
- "type": "commonjs",
3
- "publishConfig": {
4
- "access": "public",
5
- "registry": "https://registry.npmjs.org"
6
- },
7
- "platformRegistry": "npm"
2
+ "type": "commonjs"
8
3
  }
package/dist/client.d.ts CHANGED
@@ -9,6 +9,13 @@ export interface DatabaseHandle {
9
9
  db: Database;
10
10
  close(): Promise<void>;
11
11
  }
12
+ /** What createDatabase tells when the server closes a connection: a pino logger fits. */
13
+ export interface DatabaseLogger {
14
+ warn(fields: {
15
+ err: Error;
16
+ }, message: string): void;
17
+ }
12
18
  export declare function createDatabase(url: string, options?: {
13
19
  max?: number;
20
+ logger?: DatabaseLogger;
14
21
  }): DatabaseHandle;
package/dist/client.js CHANGED
@@ -13,6 +13,12 @@ export function createDatabase(url, options = {}) {
13
13
  max: options.max ?? DEFAULT_POOL_SIZE,
14
14
  idleTimeoutMillis: IDLE_TIMEOUT_MS,
15
15
  });
16
+ // PgBouncer or Postgres restarting closes the idle connections, which node-postgres reports
17
+ // as an 'error' on the pool: with nothing listening, the process exits. The pool has already
18
+ // dropped the connection, and the next query opens a new one.
19
+ pool.on('error', (err) => {
20
+ options.logger?.warn({ err }, 'Database connection closed by the server; the next query opens a new one');
21
+ });
16
22
  // pool.end() resolves once it has asked its connections to close, not once they have.
17
23
  // A server that stops in between kills the open ones, and by then nothing listens for
18
24
  // the error, so close() also waits for each connection to end.
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,MAA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IACF,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createDatabase } from './client.js';
2
- export type { Database, DatabaseHandle, Tx } from './client.js';
2
+ export type { Database, DatabaseHandle, DatabaseLogger, Tx } from './client.js';
3
3
  export { ORGANIZATION_GOES_FIRST_SQL, apiKeyColumns, auditLogColumns, auditLogIndexes, membershipColumns, membershipIndexes, organizationColumns, organizationFeatureColumns, organizationFeatureIndexes, allowanceGrantColumns, allowanceGrantIndexes, organizationOriginEnum, outboxMessageColumns, outboxMessageIndexes, outboxPriorityColumn, paymentEventColumns, paymentEventIndexes, planColumns, planFeatureColumns, planFeatureIndexes, planIndexes, planPriceColumns, planPriceIndexes, platformAdminColumns, roleEnum, shopifyInstallationColumns, subscriptionColumns, subscriptionStatusEnum, timestamps, usageRecordColumns, usageRecordIndexes, userColumns, webhookEventColumns, extensionKeyColumns, extensionKeyIndexes, } from './columns.js';
4
4
  export type { ApiKeysTable, ExtensionKeysTable, AuditLogsTable, MembershipsTable, OrganizationsTable, OrganizationFeaturesTable, AllowanceGrantsTable, OutboxMessagesTable, PaymentEventsTable, PlanFeaturesTable, PlanPricesTable, PlansTable, PlatformAdminsTable, ShopifyInstallationsTable, SubscriptionsTable, UsageRecordsTable, UsersTable, WebhookEventsTable, } from './columns.js';
5
5
  export { isUniqueViolation } from './errors.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haatlabs-core/db-core",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
4
4
  "description": "PostgreSQL and drizzle building blocks: shared columns, organizations, row-level security, audit logs.",
5
5
  "keywords": [
6
6
  "haatlabs",
@@ -55,13 +55,13 @@
55
55
  "drizzle-orm": "^0.45.3",
56
56
  "pg": "^8.23.1",
57
57
  "testcontainers": "^12.2.0",
58
- "@haatlabs-core/vitest-config": "0.10.0",
59
- "@haatlabs-core/tsconfig": "0.10.0"
58
+ "@haatlabs-core/tsconfig": "0.11.1",
59
+ "@haatlabs-core/vitest-config": "0.11.1"
60
60
  },
61
61
  "dependencies": {
62
- "@haatlabs-core/observability": "0.10.0",
63
- "@haatlabs-core/errors": "0.10.0",
64
- "@haatlabs-core/queue": "0.10.0"
62
+ "@haatlabs-core/errors": "0.11.1",
63
+ "@haatlabs-core/observability": "0.11.1",
64
+ "@haatlabs-core/queue": "0.11.1"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "drizzle-orm": "^0.45.3",