@btravstack/prisma / rls
rls
Type Aliases
ScopedTransaction
type ScopedTransaction = <C, R>(this, fn, options?) => Promise<R>;Defined in: prisma/src/rls.ts:34
The $transaction a tenantScoped client exposes: the callback form only, with this carrying the extended client through to tx.
Type Parameters
| Type Parameter |
|---|
C |
R |
Parameters
| Parameter | Type |
|---|---|
this | C |
fn | (tx) => Promise<R> |
options? | { isolationLevel?: string; maxWait?: number; timeout?: number; } |
options.isolationLevel? | string |
options.maxWait? | number |
options.timeout? | number |
Returns
Promise<R>
Remarks
The generic this is what keeps tx typed. The starter cannot name a generated client, so the receiver is the only place that type can come from. The array form is absent because it cannot be pinned atomically.
ScopedTransactionClient
type ScopedTransactionClient<C> = Omit<C, "$connect" | "$disconnect" | "$extends" | "$on" | "$use">;Defined in: prisma/src/rls.ts:20
The client a pinned $transaction callback receives — the extended client minus what a transaction cannot do, exactly as Prisma's own deny list has it.
Type Parameters
| Type Parameter |
|---|
C |
Remarks
Not @unthrown/prisma's TransactionClient, which denies a longer list; an application applying both extensions imports both names.
TenantScopedOptions
type TenantScopedOptions = object;Defined in: prisma/src/rls.ts:4
Options of tenantScoped.
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
setting? | readonly | string | The PostgreSQL run-time setting the policy reads. Defaults to app.tenant_id, matching current_setting('app.tenant_id', true). | prisma/src/rls.ts:9 |
Functions
tenantScoped()
function tenantScoped(tenant, options?): (client) => PrismaClientExtends<InternalArgs<{
}, {
}, {
}, {
$transaction: ScopedTransaction;
}> & DefaultArgs>;Defined in: prisma/src/rls.ts:58
A Prisma client extension pinning every statement to tenant through a transaction-local set_config, so a row-level-security policy reading current_setting('app.tenant_id', true) sees it.
Parameters
| Parameter | Type |
|---|---|
tenant | string |
options? | TenantScopedOptions |
Returns
(client) => PrismaClientExtends<InternalArgs<{ }, { }, { }, { $transaction: ScopedTransaction; }> & DefaultArgs>
Remarks
Apply it last: the transaction callback's tx comes from the client as it stood when this extension was applied, so an extension added after this one is invisible inside a transaction.
$transaction([...]) is refused — the reasoning is in packages/prisma/CLAUDE.md. Use the callback form.
Example
const db = new PrismaClient({ adapter }).$extends(unthrownPrisma).$extends(tenantScoped(tenant));