Skip to main content
zerotal

Documentation


Documentation / @zerotal/tenancy / TenantContext

Class: TenantContext

Defined in: tenancy/src/TenantContext.ts:19

Constructors

Constructor

new TenantContext(): TenantContext

Returns

TenantContext

Methods

run()

static run<T>(tenant, callback): T

Defined in: tenancy/src/TenantContext.ts:24

Execute callback inside a tenant boundary. Called by TenancyMiddleware before forwarding to the next handler.

Type Parameters

T

T

Parameters

tenant

Tenant

callback

() => T

Returns

T


get()

static get(): Tenant

Defined in: tenancy/src/TenantContext.ts:32

Return the active tenant. Throws if called outside a tenant context (i.e. without TenancyMiddleware).

Returns

Tenant


tryGet()

static tryGet(): Tenant | undefined

Defined in: tenancy/src/TenantContext.ts:43

Return the active tenant, or undefined if called outside a tenant context. Useful in shared code that runs in both tenant and non-tenant contexts (CLI commands, background jobs that process all tenants).

Returns

Tenant | undefined


id()

static id(): number | null

Defined in: tenancy/src/TenantContext.ts:48

Convenience: return the current tenant's id, or null outside a context.

Returns

number | null


slug()

static slug(): string | null

Defined in: tenancy/src/TenantContext.ts:53

Convenience: return the current tenant's slug, or null outside a context.

Returns

string | null