interface ITenantDataStore

Tenant-scoped data-store port.

Implemented by the shipped MemoryTenantDataStore (zero-dependency default) and by application-provided backends that consume real databases.

Methods

optional
useIsolation(strategy: ITenantIsolationStrategy): void

Receives the resolved isolation strategy once, during register(). Optional so a store may ignore isolation metadata entirely.

findAll<E>(
tenantId: string,
entity: string
): Promise<readonly E[]>

Retrieve all records of an entity for a tenant.

findById<E, Id>(
tenantId: string,
entity: string,
id: Id
): Promise<E | null>

Find a single record by its identifier.

find<E>(
tenantId: string,
entity: string,
filter: Readonly<Record<string, unknown>>
): Promise<readonly E[]>

Find records matching a filter.

create<E>(
tenantId: string,
entity: string,
data: Readonly<Record<string, unknown>>
): Promise<E>

Create a new record; returns the stored entity including its id.

update<E, Id>(
tenantId: string,
entity: string,
id: Id,
data: Readonly<Record<string, unknown>>
): Promise<E | null>

Update an existing record; returns null when the id is unknown.

delete<Id>(
tenantId: string,
entity: string,
id: Id
): Promise<boolean>

Delete a record. Returns true if a record was deleted.

optional
close(): Promise<void>

Gracefully close any connections.

Usage

import { type ITenantDataStore } from "multi-tenancy-plugin/src/index.ts";