drizzle-multitenant 1.0.10 → 1.1.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.
@@ -1,4 +1,4 @@
1
- import { C as Config } from '../types-B5eSRLFW.js';
1
+ import { C as Config } from '../types-BhK96FPC.js';
2
2
  import { Pool } from 'pg';
3
3
  import 'drizzle-orm/node-postgres';
4
4
 
@@ -182,6 +182,116 @@ interface WarmupResult {
182
182
  durationMs: number;
183
183
  details: TenantWarmupResult[];
184
184
  }
185
+ /**
186
+ * Health status for a pool
187
+ */
188
+ type PoolHealthStatus = 'ok' | 'degraded' | 'unhealthy';
189
+ /**
190
+ * Health information for a single pool
191
+ */
192
+ interface PoolHealth {
193
+ /** Tenant ID */
194
+ tenantId: string;
195
+ /** Schema name */
196
+ schemaName: string;
197
+ /** Health status */
198
+ status: PoolHealthStatus;
199
+ /** Total connections in pool */
200
+ totalConnections: number;
201
+ /** Idle connections available */
202
+ idleConnections: number;
203
+ /** Waiting requests in queue */
204
+ waitingRequests: number;
205
+ /** Response time of health ping in ms */
206
+ responseTimeMs?: number;
207
+ /** Error message if unhealthy */
208
+ error?: string;
209
+ }
210
+ /**
211
+ * Options for health check
212
+ */
213
+ interface HealthCheckOptions {
214
+ /** Execute ping query to verify connection (default: true) */
215
+ ping?: boolean;
216
+ /** Timeout for ping query in ms (default: 5000) */
217
+ pingTimeoutMs?: number;
218
+ /** Include shared database in check (default: true) */
219
+ includeShared?: boolean;
220
+ /** Check specific tenant IDs only */
221
+ tenantIds?: string[];
222
+ }
223
+ /**
224
+ * Connection metrics for a pool
225
+ */
226
+ interface ConnectionMetrics {
227
+ /** Total connections in pool */
228
+ total: number;
229
+ /** Idle connections available */
230
+ idle: number;
231
+ /** Waiting requests in queue */
232
+ waiting: number;
233
+ }
234
+ /**
235
+ * Metrics for a single tenant pool
236
+ */
237
+ interface TenantPoolMetrics {
238
+ /** Tenant ID */
239
+ tenantId: string;
240
+ /** Schema name */
241
+ schemaName: string;
242
+ /** Connection metrics */
243
+ connections: ConnectionMetrics;
244
+ /** Last access timestamp */
245
+ lastAccessedAt: string;
246
+ }
247
+ /**
248
+ * Aggregate metrics result
249
+ */
250
+ interface MetricsResult {
251
+ /** Pool metrics */
252
+ pools: {
253
+ /** Total active pools */
254
+ total: number;
255
+ /** Maximum pools allowed */
256
+ maxPools: number;
257
+ /** Individual tenant pool metrics */
258
+ tenants: TenantPoolMetrics[];
259
+ };
260
+ /** Shared database metrics (if initialized) */
261
+ shared: {
262
+ /** Whether shared pool is initialized */
263
+ initialized: boolean;
264
+ /** Connection metrics */
265
+ connections: ConnectionMetrics | null;
266
+ };
267
+ /** Timestamp of metrics collection */
268
+ timestamp: string;
269
+ }
270
+ /**
271
+ * Health check result
272
+ */
273
+ interface HealthCheckResult {
274
+ /** Overall health status */
275
+ healthy: boolean;
276
+ /** Health of tenant pools */
277
+ pools: PoolHealth[];
278
+ /** Health status of shared database */
279
+ sharedDb: PoolHealthStatus;
280
+ /** Response time of shared db ping in ms */
281
+ sharedDbResponseTimeMs?: number;
282
+ /** Error on shared db if any */
283
+ sharedDbError?: string;
284
+ /** Total active pools */
285
+ totalPools: number;
286
+ /** Pools with degraded status */
287
+ degradedPools: number;
288
+ /** Pools with unhealthy status */
289
+ unhealthyPools: number;
290
+ /** Timestamp of health check */
291
+ timestamp: string;
292
+ /** Total duration of health check in ms */
293
+ durationMs: number;
294
+ }
185
295
  /**
186
296
  * Tenant manager interface
187
297
  */
@@ -208,6 +318,10 @@ interface TenantManager<TTenantSchema extends Record<string, unknown> = Record<s
208
318
  evictPool(tenantId: string): Promise<void>;
209
319
  /** Pre-warm pools for specified tenants to reduce cold start latency */
210
320
  warmup(tenantIds: string[], options?: WarmupOptions): Promise<WarmupResult>;
321
+ /** Check health of all pools and connections */
322
+ healthCheck(options?: HealthCheckOptions): Promise<HealthCheckResult>;
323
+ /** Get current metrics for all pools (zero overhead, collected on demand) */
324
+ getMetrics(): MetricsResult;
211
325
  /** Dispose all pools and cleanup */
212
326
  dispose(): Promise<void>;
213
327
  }
@@ -232,4 +346,4 @@ declare const DEFAULT_CONFIG: {
232
346
  };
233
347
  };
234
348
 
235
- export { type Config as C, type DebugConfig as D, type Hooks as H, type IsolationConfig as I, type MetricsConfig as M, type PoolEntry as P, type RetryConfig as R, type SharedDb as S, type TenantManager as T, type WarmupOptions as W, type TenantDb as a, type ConnectionConfig as b, type IsolationStrategy as c, type SchemasConfig as d, type DebugContext as e, type WarmupResult as f, type TenantWarmupResult as g, DEFAULT_CONFIG as h };
349
+ export { type Config as C, type DebugConfig as D, type Hooks as H, type IsolationConfig as I, type MetricsConfig as M, type PoolEntry as P, type RetryConfig as R, type SharedDb as S, type TenantManager as T, type WarmupOptions as W, type TenantDb as a, type ConnectionConfig as b, type IsolationStrategy as c, type SchemasConfig as d, type DebugContext as e, type WarmupResult as f, type TenantWarmupResult as g, type HealthCheckOptions as h, type HealthCheckResult as i, type PoolHealth as j, type PoolHealthStatus as k, type MetricsResult as l, type TenantPoolMetrics as m, type ConnectionMetrics as n, DEFAULT_CONFIG as o };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-multitenant",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "description": "Multi-tenancy toolkit for Drizzle ORM with schema isolation, tenant context, and parallel migrations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",