basalt / tenancy/src / TenantSource
Interface: TenantSource
Defined in: tenancy/src/tenant.ts:78
Where tenants are loaded from — the app's database in production.
Methods
create()?
> optional create(tenant): Promise<Tenant>
Defined in: tenancy/src/tenant.ts:95
Persists and returns the new tenant, failing with TenantAlreadyExistsError if the id is already taken — never overwriting it.
Implement it as an insert the store itself refuses on a duplicate (a primary key violation), not as a read followed by a write: tenancy.create() checks with find() first, but two concurrent creates of the same id both pass that check, and only the store can pick exactly one winner. MemoryTenantSource, @basaltkit/tenancy-prisma and @basaltkit/tenancy-sqlite all implement it that way.
Parameters
tenant
Returns
Promise<Tenant>
delete()?
> optional delete(id): Promise<void>
Defined in: tenancy/src/tenant.ts:104
Removes the record. Optional, because not every source can: a read-only directory or a config file has nothing to delete from.
tenancy.destroy() refuses rather than reporting a success it did not perform — a tenant that looks removed and still resolves is worse than one that never left.
Parameters
id
string
Returns
Promise<void>
find()
> find(id): Promise<Tenant | null>
Defined in: tenancy/src/tenant.ts:79
Parameters
id
string
Returns
Promise<Tenant | null>
findByDomain()?
> optional findByDomain(domain): Promise<Tenant | null>
Defined in: tenancy/src/tenant.ts:81
Required by the domain resolver (custom domains).
Parameters
domain
string
Returns
Promise<Tenant | null>
list()?
> optional list(): Promise<Tenant[]>
Defined in: tenancy/src/tenant.ts:83
Required by tenancy.forEach() and basalt tenant:list.
Returns
Promise<Tenant[]>
save()?
> optional save(tenant): Promise<Tenant>
Defined in: tenancy/src/tenant.ts:115
Upsert — inserts a new tenant or replaces an existing record wholesale.
This is the write for an INTENTIONAL update, and the one status transitions go through (provisioning → ready). tenancy.create() prefers create and falls back to save only for a source that has nothing else; it checks with find() before writing either way, so a save-only source still refuses an existing id — just without the store-level guarantee against a concurrent create of the same id.
Parameters
tenant
Returns
Promise<Tenant>