drizzle-multitenant 1.0.2 → 1.0.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/README.md +75 -2
- package/dist/cli/index.js +9 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/integrations/nestjs/index.d.ts +159 -3
- package/dist/integrations/nestjs/index.js +177 -29
- package/dist/integrations/nestjs/index.js.map +1 -1
- package/package.json +1 -1
- package/roadmap.md +105 -7
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
2
|
import { ModuleMetadata, Type, InjectionToken, DynamicModule, CanActivate, ExecutionContext, NestInterceptor, CallHandler, Provider } from '@nestjs/common';
|
|
3
3
|
import { Request } from 'express';
|
|
4
|
-
import { C as Config, T as TenantManager } from '../../types-DKVaTaIb.js';
|
|
5
|
-
export { S as SharedDb, a as TenantDb } from '../../types-DKVaTaIb.js';
|
|
4
|
+
import { C as Config, a as TenantDb, T as TenantManager, S as SharedDb } from '../../types-DKVaTaIb.js';
|
|
6
5
|
import { Reflector } from '@nestjs/core';
|
|
7
6
|
import { Observable } from 'rxjs';
|
|
8
7
|
import 'pg';
|
|
@@ -70,6 +69,32 @@ interface TenantRequest extends Request {
|
|
|
70
69
|
tenantContext?: NestTenantContext;
|
|
71
70
|
tenantId?: string;
|
|
72
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Debug information available on TenantDb proxy
|
|
74
|
+
*/
|
|
75
|
+
interface TenantDbDebugInfo$1 {
|
|
76
|
+
/** Current tenant ID (null if not resolved) */
|
|
77
|
+
tenantId: string | null;
|
|
78
|
+
/** Schema name for the tenant (null if not resolved) */
|
|
79
|
+
schemaName: string | null;
|
|
80
|
+
/** Whether this is a proxy object */
|
|
81
|
+
isProxy: boolean;
|
|
82
|
+
/** Number of active connection pools */
|
|
83
|
+
poolCount: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extended TenantDb interface with debug utilities
|
|
87
|
+
*
|
|
88
|
+
* Available when using @InjectTenantDb() - provides debugging helpers
|
|
89
|
+
*/
|
|
90
|
+
interface TenantDbWithDebug<T extends Record<string, unknown> = Record<string, unknown>> extends TenantDb<T> {
|
|
91
|
+
/** Debug information about the current tenant connection */
|
|
92
|
+
__debug: TenantDbDebugInfo$1;
|
|
93
|
+
/** Current tenant ID (null if not resolved) */
|
|
94
|
+
__tenantId: string | null;
|
|
95
|
+
/** Whether this is a proxy object */
|
|
96
|
+
__isProxy: true;
|
|
97
|
+
}
|
|
73
98
|
|
|
74
99
|
/**
|
|
75
100
|
* NestJS module for multi-tenant support
|
|
@@ -127,6 +152,95 @@ declare class TenantModule {
|
|
|
127
152
|
*/
|
|
128
153
|
declare const DrizzleMultitenantModule: typeof TenantModule;
|
|
129
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Debug information for tenant database connections
|
|
157
|
+
*/
|
|
158
|
+
interface TenantDbDebugInfo {
|
|
159
|
+
tenantId: string;
|
|
160
|
+
schemaName: string;
|
|
161
|
+
isProxy: boolean;
|
|
162
|
+
poolCount: number;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Factory for creating tenant database connections
|
|
166
|
+
*
|
|
167
|
+
* Use this when you need to access tenant databases in singleton services
|
|
168
|
+
* (cron jobs, event handlers, background workers, etc.)
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* // Service stays singleton - no scope change needed
|
|
173
|
+
* @Injectable()
|
|
174
|
+
* export class ReportService {
|
|
175
|
+
* constructor(private dbFactory: TenantDbFactory) {}
|
|
176
|
+
*
|
|
177
|
+
* async generateReport(tenantId: string) {
|
|
178
|
+
* const db = this.dbFactory.getDb(tenantId);
|
|
179
|
+
* return db.select().from(reports);
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* // Cron job usage
|
|
187
|
+
* @Injectable()
|
|
188
|
+
* export class DailyReportCron {
|
|
189
|
+
* constructor(private dbFactory: TenantDbFactory) {}
|
|
190
|
+
*
|
|
191
|
+
* @Cron('0 8 * * *')
|
|
192
|
+
* async generateDailyReports() {
|
|
193
|
+
* const tenants = await this.getTenantIds();
|
|
194
|
+
* for (const tenantId of tenants) {
|
|
195
|
+
* const db = this.dbFactory.getDb(tenantId);
|
|
196
|
+
* await this.processReports(db);
|
|
197
|
+
* }
|
|
198
|
+
* }
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare class TenantDbFactory<TTenantSchema extends Record<string, unknown> = Record<string, unknown>, TSharedSchema extends Record<string, unknown> = Record<string, unknown>> {
|
|
203
|
+
private readonly manager;
|
|
204
|
+
constructor(manager: TenantManager<TTenantSchema, TSharedSchema>);
|
|
205
|
+
/**
|
|
206
|
+
* Get a tenant database connection by tenant ID
|
|
207
|
+
*
|
|
208
|
+
* @param tenantId - The tenant identifier
|
|
209
|
+
* @returns The tenant-scoped Drizzle database instance
|
|
210
|
+
*
|
|
211
|
+
* @throws Error if tenantId is empty or invalid
|
|
212
|
+
*/
|
|
213
|
+
getDb(tenantId: string): TenantDb<TTenantSchema>;
|
|
214
|
+
/**
|
|
215
|
+
* Get the shared database connection
|
|
216
|
+
*
|
|
217
|
+
* @returns The shared Drizzle database instance
|
|
218
|
+
*/
|
|
219
|
+
getSharedDb(): SharedDb<TSharedSchema>;
|
|
220
|
+
/**
|
|
221
|
+
* Get the schema name for a tenant
|
|
222
|
+
*
|
|
223
|
+
* @param tenantId - The tenant identifier
|
|
224
|
+
* @returns The schema name for the tenant
|
|
225
|
+
*/
|
|
226
|
+
getSchemaName(tenantId: string): string;
|
|
227
|
+
/**
|
|
228
|
+
* Get debug information for a tenant database
|
|
229
|
+
*
|
|
230
|
+
* @param tenantId - The tenant identifier
|
|
231
|
+
* @returns Debug information including schema name and pool stats
|
|
232
|
+
*/
|
|
233
|
+
getDebugInfo(tenantId: string): TenantDbDebugInfo;
|
|
234
|
+
/**
|
|
235
|
+
* Get the underlying TenantManager instance
|
|
236
|
+
*
|
|
237
|
+
* Use this for advanced operations like pool management
|
|
238
|
+
*
|
|
239
|
+
* @returns The TenantManager instance
|
|
240
|
+
*/
|
|
241
|
+
getManager(): TenantManager<TTenantSchema, TSharedSchema>;
|
|
242
|
+
}
|
|
243
|
+
|
|
130
244
|
/**
|
|
131
245
|
* Inject the tenant database for the current request
|
|
132
246
|
*
|
|
@@ -256,6 +370,46 @@ declare const RequiresTenant: () => ClassDecorator & MethodDecorator;
|
|
|
256
370
|
* ```
|
|
257
371
|
*/
|
|
258
372
|
declare const PublicRoute: () => MethodDecorator;
|
|
373
|
+
/**
|
|
374
|
+
* Inject the TenantDbFactory for singleton services
|
|
375
|
+
*
|
|
376
|
+
* Use this when you need to access tenant databases in singleton services
|
|
377
|
+
* (cron jobs, event handlers, background workers, etc.) without requiring
|
|
378
|
+
* request scope.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* // Service stays singleton - no scope change needed
|
|
383
|
+
* @Injectable()
|
|
384
|
+
* export class ReportService {
|
|
385
|
+
* constructor(@InjectTenantDbFactory() private dbFactory: TenantDbFactory) {}
|
|
386
|
+
*
|
|
387
|
+
* async generateReport(tenantId: string) {
|
|
388
|
+
* const db = this.dbFactory.getDb(tenantId);
|
|
389
|
+
* return db.select().from(reports);
|
|
390
|
+
* }
|
|
391
|
+
* }
|
|
392
|
+
* ```
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* // Cron job usage
|
|
397
|
+
* @Injectable()
|
|
398
|
+
* export class DailyReportCron {
|
|
399
|
+
* constructor(@InjectTenantDbFactory() private dbFactory: TenantDbFactory) {}
|
|
400
|
+
*
|
|
401
|
+
* @Cron('0 8 * * *')
|
|
402
|
+
* async generateDailyReports() {
|
|
403
|
+
* const tenants = await this.getTenantIds();
|
|
404
|
+
* for (const tenantId of tenants) {
|
|
405
|
+
* const db = this.dbFactory.getDb(tenantId);
|
|
406
|
+
* await this.processReports(db);
|
|
407
|
+
* }
|
|
408
|
+
* }
|
|
409
|
+
* }
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
declare const InjectTenantDbFactory: () => ParameterDecorator;
|
|
259
413
|
|
|
260
414
|
/**
|
|
261
415
|
* Guard that extracts and validates tenant ID from requests
|
|
@@ -382,5 +536,7 @@ declare const TENANT_ID_EXTRACTOR: unique symbol;
|
|
|
382
536
|
declare const REQUIRES_TENANT_KEY = "requires_tenant";
|
|
383
537
|
/** Metadata key for public routes (no tenant required) */
|
|
384
538
|
declare const IS_PUBLIC_KEY = "is_public_tenant";
|
|
539
|
+
/** Token for injecting the TenantDbFactory */
|
|
540
|
+
declare const TENANT_DB_FACTORY: unique symbol;
|
|
385
541
|
|
|
386
|
-
export { Config, DrizzleMultitenantModule, IS_PUBLIC_KEY, InjectSharedDb, InjectTenantContext, InjectTenantDb, InjectTenantManager, type NestTenantContext, PublicRoute, REQUIRES_TENANT_KEY, RequireTenantGuard, RequiresTenant, SHARED_DB, TENANT_CONTEXT, TENANT_DB, TENANT_ID_EXTRACTOR, TENANT_MANAGER, TENANT_MODULE_OPTIONS, TenantContextInterceptor, TenantCtx, TenantGuard, TenantId, type TenantIdExtractor, TenantLoggingInterceptor, TenantManager, TenantModule, type TenantModuleAsyncOptions, type TenantModuleOptions, type TenantModuleOptionsFactory, type TenantRequest, type TenantValidator, createAsyncProviders, createTenantProviders };
|
|
542
|
+
export { Config, DrizzleMultitenantModule, IS_PUBLIC_KEY, InjectSharedDb, InjectTenantContext, InjectTenantDb, InjectTenantDbFactory, InjectTenantManager, type NestTenantContext, PublicRoute, REQUIRES_TENANT_KEY, RequireTenantGuard, RequiresTenant, SHARED_DB, SharedDb, TENANT_CONTEXT, TENANT_DB, TENANT_DB_FACTORY, TENANT_ID_EXTRACTOR, TENANT_MANAGER, TENANT_MODULE_OPTIONS, TenantContextInterceptor, TenantCtx, TenantDb, type TenantDbDebugInfo$1 as TenantDbDebugInfo, TenantDbFactory, type TenantDbWithDebug, TenantGuard, TenantId, type TenantIdExtractor, TenantLoggingInterceptor, TenantManager, TenantModule, type TenantModuleAsyncOptions, type TenantModuleOptions, type TenantModuleOptionsFactory, type TenantRequest, type TenantValidator, createAsyncProviders, createTenantProviders };
|
|
@@ -9212,6 +9212,7 @@ var TENANT_MODULE_OPTIONS = /* @__PURE__ */ Symbol("TENANT_MODULE_OPTIONS");
|
|
|
9212
9212
|
var TENANT_ID_EXTRACTOR = /* @__PURE__ */ Symbol("TENANT_ID_EXTRACTOR");
|
|
9213
9213
|
var REQUIRES_TENANT_KEY = "requires_tenant";
|
|
9214
9214
|
var IS_PUBLIC_KEY = "is_public_tenant";
|
|
9215
|
+
var TENANT_DB_FACTORY = /* @__PURE__ */ Symbol("TENANT_DB_FACTORY");
|
|
9215
9216
|
|
|
9216
9217
|
// src/types.ts
|
|
9217
9218
|
var DEFAULT_CONFIG = {
|
|
@@ -9484,24 +9485,54 @@ function createTenantProviders() {
|
|
|
9484
9485
|
provide: TENANT_DB,
|
|
9485
9486
|
scope: Scope.REQUEST,
|
|
9486
9487
|
useFactory: (request, manager, options) => {
|
|
9488
|
+
const resolveTenantId = () => {
|
|
9489
|
+
let tenantId = request.tenantContext?.tenantId ?? request.tenantId;
|
|
9490
|
+
if (!tenantId && options.extractTenantId) {
|
|
9491
|
+
const extracted = options.extractTenantId(request);
|
|
9492
|
+
if (typeof extracted === "string") {
|
|
9493
|
+
tenantId = extracted;
|
|
9494
|
+
}
|
|
9495
|
+
}
|
|
9496
|
+
return tenantId;
|
|
9497
|
+
};
|
|
9498
|
+
const inspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
9499
|
+
const debugProps = ["__debug", "__tenantId", "__isProxy"];
|
|
9487
9500
|
return new Proxy({}, {
|
|
9488
9501
|
get(_target, prop) {
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9502
|
+
if (prop === Symbol.toStringTag) return "TenantDb";
|
|
9503
|
+
const resolvedTenantId = resolveTenantId();
|
|
9504
|
+
if (prop === inspectSymbol || prop === "toString") {
|
|
9505
|
+
return () => {
|
|
9506
|
+
if (resolvedTenantId) {
|
|
9507
|
+
return `[TenantDb] tenant=${resolvedTenantId} schema=${manager.getSchemaName(resolvedTenantId)}`;
|
|
9508
|
+
}
|
|
9509
|
+
return "[TenantDb] (no tenant context)";
|
|
9510
|
+
};
|
|
9495
9511
|
}
|
|
9496
|
-
if (
|
|
9512
|
+
if (prop === "__debug") {
|
|
9513
|
+
return {
|
|
9514
|
+
tenantId: resolvedTenantId ?? null,
|
|
9515
|
+
schemaName: resolvedTenantId ? manager.getSchemaName(resolvedTenantId) : null,
|
|
9516
|
+
isProxy: true,
|
|
9517
|
+
poolCount: manager.getPoolCount()
|
|
9518
|
+
};
|
|
9519
|
+
}
|
|
9520
|
+
if (prop === "__tenantId") {
|
|
9521
|
+
return resolvedTenantId ?? null;
|
|
9522
|
+
}
|
|
9523
|
+
if (prop === "__isProxy") {
|
|
9524
|
+
return true;
|
|
9525
|
+
}
|
|
9526
|
+
if (!resolvedTenantId) {
|
|
9497
9527
|
throw new Error(
|
|
9498
9528
|
"[drizzle-multitenant] No tenant context found. Ensure the route has a tenant ID or use @PublicRoute() decorator."
|
|
9499
9529
|
);
|
|
9500
9530
|
}
|
|
9501
|
-
const db = manager.getDb(
|
|
9531
|
+
const db = manager.getDb(resolvedTenantId);
|
|
9502
9532
|
return db[prop];
|
|
9503
9533
|
},
|
|
9504
9534
|
has(_target, prop) {
|
|
9535
|
+
if (debugProps.includes(prop)) return true;
|
|
9505
9536
|
const tenantId = request.tenantContext?.tenantId ?? request.tenantId;
|
|
9506
9537
|
if (!tenantId) return false;
|
|
9507
9538
|
const db = manager.getDb(tenantId);
|
|
@@ -9509,11 +9540,16 @@ function createTenantProviders() {
|
|
|
9509
9540
|
},
|
|
9510
9541
|
ownKeys() {
|
|
9511
9542
|
const tenantId = request.tenantContext?.tenantId ?? request.tenantId;
|
|
9512
|
-
if (!tenantId)
|
|
9543
|
+
if (!tenantId) {
|
|
9544
|
+
return [...debugProps];
|
|
9545
|
+
}
|
|
9513
9546
|
const db = manager.getDb(tenantId);
|
|
9514
|
-
return Reflect.ownKeys(db);
|
|
9547
|
+
return [.../* @__PURE__ */ new Set([...debugProps, ...Reflect.ownKeys(db)])];
|
|
9515
9548
|
},
|
|
9516
9549
|
getOwnPropertyDescriptor(_target, prop) {
|
|
9550
|
+
if (debugProps.includes(prop)) {
|
|
9551
|
+
return { configurable: true, enumerable: true, writable: false };
|
|
9552
|
+
}
|
|
9517
9553
|
const tenantId = request.tenantContext?.tenantId ?? request.tenantId;
|
|
9518
9554
|
if (!tenantId) return void 0;
|
|
9519
9555
|
const db = manager.getDb(tenantId);
|
|
@@ -9537,40 +9573,80 @@ function createTenantProviders() {
|
|
|
9537
9573
|
provide: TENANT_CONTEXT,
|
|
9538
9574
|
scope: Scope.REQUEST,
|
|
9539
9575
|
useFactory: (request, manager, options) => {
|
|
9576
|
+
const inspectSymbol = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
9577
|
+
const resolveContext = () => {
|
|
9578
|
+
if (request.tenantContext) {
|
|
9579
|
+
return {
|
|
9580
|
+
tenantId: request.tenantContext.tenantId,
|
|
9581
|
+
schemaName: request.tenantContext.schemaName
|
|
9582
|
+
};
|
|
9583
|
+
}
|
|
9584
|
+
let tenantId = request.tenantId;
|
|
9585
|
+
if (!tenantId && options.extractTenantId) {
|
|
9586
|
+
const extracted = options.extractTenantId(request);
|
|
9587
|
+
if (typeof extracted === "string") {
|
|
9588
|
+
tenantId = extracted;
|
|
9589
|
+
}
|
|
9590
|
+
}
|
|
9591
|
+
if (!tenantId) return null;
|
|
9592
|
+
return {
|
|
9593
|
+
tenantId,
|
|
9594
|
+
schemaName: manager.getSchemaName(tenantId)
|
|
9595
|
+
};
|
|
9596
|
+
};
|
|
9540
9597
|
return new Proxy({}, {
|
|
9541
9598
|
get(_target, prop) {
|
|
9542
|
-
if (
|
|
9543
|
-
|
|
9599
|
+
if (prop === Symbol.toStringTag) return "TenantContext";
|
|
9600
|
+
const ctx = resolveContext();
|
|
9601
|
+
if (prop === inspectSymbol || prop === "toString") {
|
|
9602
|
+
return () => {
|
|
9603
|
+
if (ctx) {
|
|
9604
|
+
return `[TenantContext] tenant=${ctx.tenantId} schema=${ctx.schemaName}`;
|
|
9605
|
+
}
|
|
9606
|
+
return "[TenantContext] (no tenant context)";
|
|
9607
|
+
};
|
|
9544
9608
|
}
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9609
|
+
if (prop === "__debug") {
|
|
9610
|
+
return {
|
|
9611
|
+
tenantId: ctx?.tenantId ?? null,
|
|
9612
|
+
schemaName: ctx?.schemaName ?? null,
|
|
9613
|
+
isProxy: true,
|
|
9614
|
+
hasContext: !!request.tenantContext
|
|
9615
|
+
};
|
|
9551
9616
|
}
|
|
9552
|
-
if (
|
|
9617
|
+
if (prop === "__isProxy") {
|
|
9618
|
+
return true;
|
|
9619
|
+
}
|
|
9620
|
+
if (!ctx) {
|
|
9553
9621
|
throw new Error(
|
|
9554
9622
|
"[drizzle-multitenant] No tenant context found. Ensure the route has a tenant ID or use @PublicRoute() decorator."
|
|
9555
9623
|
);
|
|
9556
9624
|
}
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9625
|
+
if (prop === "tenantId") return ctx.tenantId;
|
|
9626
|
+
if (prop === "schemaName") return ctx.schemaName;
|
|
9627
|
+
if (request.tenantContext) {
|
|
9628
|
+
return request.tenantContext[prop];
|
|
9629
|
+
}
|
|
9630
|
+
return void 0;
|
|
9560
9631
|
},
|
|
9561
9632
|
has(_target, prop) {
|
|
9633
|
+
if (prop === "__debug" || prop === "__isProxy") return true;
|
|
9562
9634
|
if (request.tenantContext) {
|
|
9563
9635
|
return prop in request.tenantContext;
|
|
9564
9636
|
}
|
|
9565
9637
|
return prop === "tenantId" || prop === "schemaName";
|
|
9566
9638
|
},
|
|
9567
9639
|
ownKeys() {
|
|
9640
|
+
const baseKeys = ["tenantId", "schemaName", "__debug", "__isProxy"];
|
|
9568
9641
|
if (request.tenantContext) {
|
|
9569
|
-
return Reflect.ownKeys(request.tenantContext);
|
|
9642
|
+
return [.../* @__PURE__ */ new Set([...baseKeys, ...Reflect.ownKeys(request.tenantContext)])];
|
|
9570
9643
|
}
|
|
9571
|
-
return
|
|
9644
|
+
return baseKeys;
|
|
9572
9645
|
},
|
|
9573
9646
|
getOwnPropertyDescriptor(_target, prop) {
|
|
9647
|
+
if (prop === "__debug" || prop === "__isProxy") {
|
|
9648
|
+
return { configurable: true, enumerable: true, writable: false };
|
|
9649
|
+
}
|
|
9574
9650
|
if (request.tenantContext) {
|
|
9575
9651
|
return Object.getOwnPropertyDescriptor(request.tenantContext, prop);
|
|
9576
9652
|
}
|
|
@@ -9788,6 +9864,73 @@ var TenantLoggingInterceptor = class {
|
|
|
9788
9864
|
TenantLoggingInterceptor = __decorateClass([
|
|
9789
9865
|
Injectable()
|
|
9790
9866
|
], TenantLoggingInterceptor);
|
|
9867
|
+
var TenantDbFactory = class {
|
|
9868
|
+
constructor(manager) {
|
|
9869
|
+
this.manager = manager;
|
|
9870
|
+
}
|
|
9871
|
+
/**
|
|
9872
|
+
* Get a tenant database connection by tenant ID
|
|
9873
|
+
*
|
|
9874
|
+
* @param tenantId - The tenant identifier
|
|
9875
|
+
* @returns The tenant-scoped Drizzle database instance
|
|
9876
|
+
*
|
|
9877
|
+
* @throws Error if tenantId is empty or invalid
|
|
9878
|
+
*/
|
|
9879
|
+
getDb(tenantId) {
|
|
9880
|
+
if (!tenantId || typeof tenantId !== "string") {
|
|
9881
|
+
throw new Error(
|
|
9882
|
+
"[drizzle-multitenant] TenantDbFactory.getDb() requires a valid tenantId string."
|
|
9883
|
+
);
|
|
9884
|
+
}
|
|
9885
|
+
return this.manager.getDb(tenantId);
|
|
9886
|
+
}
|
|
9887
|
+
/**
|
|
9888
|
+
* Get the shared database connection
|
|
9889
|
+
*
|
|
9890
|
+
* @returns The shared Drizzle database instance
|
|
9891
|
+
*/
|
|
9892
|
+
getSharedDb() {
|
|
9893
|
+
return this.manager.getSharedDb();
|
|
9894
|
+
}
|
|
9895
|
+
/**
|
|
9896
|
+
* Get the schema name for a tenant
|
|
9897
|
+
*
|
|
9898
|
+
* @param tenantId - The tenant identifier
|
|
9899
|
+
* @returns The schema name for the tenant
|
|
9900
|
+
*/
|
|
9901
|
+
getSchemaName(tenantId) {
|
|
9902
|
+
return this.manager.getSchemaName(tenantId);
|
|
9903
|
+
}
|
|
9904
|
+
/**
|
|
9905
|
+
* Get debug information for a tenant database
|
|
9906
|
+
*
|
|
9907
|
+
* @param tenantId - The tenant identifier
|
|
9908
|
+
* @returns Debug information including schema name and pool stats
|
|
9909
|
+
*/
|
|
9910
|
+
getDebugInfo(tenantId) {
|
|
9911
|
+
return {
|
|
9912
|
+
tenantId,
|
|
9913
|
+
schemaName: this.manager.getSchemaName(tenantId),
|
|
9914
|
+
isProxy: false,
|
|
9915
|
+
// Factory returns direct db, not proxy
|
|
9916
|
+
poolCount: this.manager.getPoolCount()
|
|
9917
|
+
};
|
|
9918
|
+
}
|
|
9919
|
+
/**
|
|
9920
|
+
* Get the underlying TenantManager instance
|
|
9921
|
+
*
|
|
9922
|
+
* Use this for advanced operations like pool management
|
|
9923
|
+
*
|
|
9924
|
+
* @returns The TenantManager instance
|
|
9925
|
+
*/
|
|
9926
|
+
getManager() {
|
|
9927
|
+
return this.manager;
|
|
9928
|
+
}
|
|
9929
|
+
};
|
|
9930
|
+
TenantDbFactory = __decorateClass([
|
|
9931
|
+
Injectable(),
|
|
9932
|
+
__decorateParam(0, Inject(TENANT_MANAGER))
|
|
9933
|
+
], TenantDbFactory);
|
|
9791
9934
|
|
|
9792
9935
|
// src/integrations/nestjs/tenant.module.ts
|
|
9793
9936
|
var TenantModule = class {
|
|
@@ -9803,7 +9946,8 @@ var TenantModule = class {
|
|
|
9803
9946
|
...createTenantProviders(),
|
|
9804
9947
|
Reflector,
|
|
9805
9948
|
TenantGuard,
|
|
9806
|
-
TenantContextInterceptor
|
|
9949
|
+
TenantContextInterceptor,
|
|
9950
|
+
TenantDbFactory
|
|
9807
9951
|
];
|
|
9808
9952
|
if (options.isGlobal) {
|
|
9809
9953
|
providers.push(
|
|
@@ -9824,7 +9968,8 @@ var TenantModule = class {
|
|
|
9824
9968
|
TENANT_MODULE_OPTIONS,
|
|
9825
9969
|
...createTenantProviders(),
|
|
9826
9970
|
TenantGuard,
|
|
9827
|
-
TenantContextInterceptor
|
|
9971
|
+
TenantContextInterceptor,
|
|
9972
|
+
TenantDbFactory
|
|
9828
9973
|
]
|
|
9829
9974
|
};
|
|
9830
9975
|
if (options.isGlobal) {
|
|
@@ -9845,7 +9990,8 @@ var TenantModule = class {
|
|
|
9845
9990
|
...createTenantProviders(),
|
|
9846
9991
|
Reflector,
|
|
9847
9992
|
TenantGuard,
|
|
9848
|
-
TenantContextInterceptor
|
|
9993
|
+
TenantContextInterceptor,
|
|
9994
|
+
TenantDbFactory
|
|
9849
9995
|
];
|
|
9850
9996
|
const module = {
|
|
9851
9997
|
module: TenantModule,
|
|
@@ -9855,7 +10001,8 @@ var TenantModule = class {
|
|
|
9855
10001
|
TENANT_MODULE_OPTIONS,
|
|
9856
10002
|
...createTenantProviders(),
|
|
9857
10003
|
TenantGuard,
|
|
9858
|
-
TenantContextInterceptor
|
|
10004
|
+
TenantContextInterceptor,
|
|
10005
|
+
TenantDbFactory
|
|
9859
10006
|
]
|
|
9860
10007
|
};
|
|
9861
10008
|
if (options.isGlobal) {
|
|
@@ -9897,7 +10044,8 @@ var TenantId = createParamDecorator(
|
|
|
9897
10044
|
);
|
|
9898
10045
|
var RequiresTenant = () => SetMetadata(REQUIRES_TENANT_KEY, true);
|
|
9899
10046
|
var PublicRoute = () => SetMetadata(IS_PUBLIC_KEY, true);
|
|
10047
|
+
var InjectTenantDbFactory = () => Inject(TenantDbFactory);
|
|
9900
10048
|
|
|
9901
|
-
export { DrizzleMultitenantModule, IS_PUBLIC_KEY, InjectSharedDb, InjectTenantContext, InjectTenantDb, InjectTenantManager, PublicRoute, REQUIRES_TENANT_KEY, RequireTenantGuard, RequiresTenant, SHARED_DB, TENANT_CONTEXT, TENANT_DB, TENANT_ID_EXTRACTOR, TENANT_MANAGER, TENANT_MODULE_OPTIONS, TenantContextInterceptor, TenantCtx, TenantGuard, TenantId, TenantLoggingInterceptor, TenantModule, createAsyncProviders, createTenantProviders };
|
|
10049
|
+
export { DrizzleMultitenantModule, IS_PUBLIC_KEY, InjectSharedDb, InjectTenantContext, InjectTenantDb, InjectTenantDbFactory, InjectTenantManager, PublicRoute, REQUIRES_TENANT_KEY, RequireTenantGuard, RequiresTenant, SHARED_DB, TENANT_CONTEXT, TENANT_DB, TENANT_DB_FACTORY, TENANT_ID_EXTRACTOR, TENANT_MANAGER, TENANT_MODULE_OPTIONS, TenantContextInterceptor, TenantCtx, TenantDbFactory, TenantGuard, TenantId, TenantLoggingInterceptor, TenantModule, createAsyncProviders, createTenantProviders };
|
|
9902
10050
|
//# sourceMappingURL=index.js.map
|
|
9903
10051
|
//# sourceMappingURL=index.js.map
|