tenantSource
consttenantSource:object
Defined in: tenant-scope.ts:57
The tenant as a context source, for createPipeline({ sources }) of
@cqrs-ddd/pipeline and registerJobContext of
@cqrs-ddd/pipeline-job-context: pipelines and jobs then take and restore
this tenant.
Type Declaration
Section titled “Type Declaration”current
Section titled “current”
readonlycurrent: () =>string|undefined=currentTenantId
Returns the current tenant: that of the innermost runWithTenant call
or running pipeline, or undefined outside both. A running pipeline’s tenant
is its context.tenantId, which it took from here when it started.
Returns
Section titled “Returns”string | undefined
The current tenant id, or undefined for none.
Example
Section titled “Example”runWithTenant('tenant_a', () => currentTenantId()); // 'tenant_a'
readonlyrun: <T>(tenantId,fn) =>T=runWithTenant
Runs fn with tenantId as the current tenant for everything it calls,
synchronously or asynchronously.
Use it where work enters the application, such as HTTP middleware or a queue
job, or to change the tenant for part of a handler. A pipeline dispatched
inside fn takes this tenant, and nested dispatches inherit it. A nested
call replaces the tenant for its own callback only, and undefined runs fn
with no tenant.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”tenantId
Section titled “tenantId”string | undefined
The tenant for the callback, or undefined for none.
() => T
The work to run.
Returns
Section titled “Returns”T
What fn returns (its promise, for an async callback).
Example
Section titled “Example”await runWithTenant(job.data.tenant, () => processBatch(job.data));Example
Section titled “Example”createPipeline({ sources: { tenantId: tenantSource } });