Setu-TS
    Preparing search index...

    Interface IMultiTenancyService

    Multi-tenancy service — exposes tenant context, repository creation, and cache-key helpers.

    0.1.0

    interface IMultiTenancyService {
        getCurrentTenant(ctx: IRequestContext): ITenant | undefined;
        getRepository<Entity, Id = string>(
            ctx: IRequestContext,
            entity: string,
        ): ITenantRepository<Entity, Id>;
        getRepositoryFor<Entity, Id = string>(
            tenantId: string,
            entity: string,
        ): ITenantRepository<Entity, Id>;
        prefixCacheKey(tenantId: string, key: string): string;
    }
    Index
    • Create a tenant-scoped repository for the given entity type, scoped to the tenant id GIVEN — no IRequestContext required. This is the entry point for non-HTTP work (an ingress behaviour, a queue processor, a scheduled job), where no request exists to resolve a tenant from; the caller reads the tenant id from the work item's own payload. Modelled on prefixCacheKey — this interface's other ctx-free, id-taking member.

      The id is TRUSTED INPUT: nothing resolves it, so a caller passing a user-controlled value bypasses the resolved tenant. On the HTTP path use getRepository, which reads the middleware-resolved ctx.request.tenant.

      Type Parameters

      • Entity
      • Id = string

      Parameters

      • tenantId: string

        The tenant id to scope the repository to (trusted input)

      • entity: string

        Entity name for scoping

      Returns ITenantRepository<Entity, Id>

      A tenant-scoped repository

      0.4.0

    • Build a cache key that includes the tenant id, joined by the separator the plugin was configured with (cache.separator, default ':'). The separator is deliberately NOT a per-call argument: this method is the single home for separator resolution, so the middleware's ctx.state prefix and a caller's key can never disagree.

      Parameters

      • tenantId: string

        The resolved tenant id

      • key: string

        The base cache key

      Returns string

      The prefixed cache key