Skip to content

@btravstack/outbox


@btravstack/outbox / prisma

prisma ​

Type Aliases ​

OutboxColumns ​

ts
type OutboxColumns = object;

Defined in: outbox/src/prisma.ts:21

The table's physical column names, where they are not the documented model's field names.

Properties ​

PropertyModifierTypeDefined in
id?readonlystringoutbox/src/prisma.ts:22
kind?readonlystringoutbox/src/prisma.ts:24
occurredAt?readonlystringoutbox/src/prisma.ts:27
payload?readonlystringoutbox/src/prisma.ts:26
publishedAt?readonlystringoutbox/src/prisma.ts:28
subjectId?readonlystringoutbox/src/prisma.ts:25
tenantId?readonlystringoutbox/src/prisma.ts:23

OutboxDatabase ​

ts
type OutboxDatabase<Tx> = object;

Defined in: outbox/src/prisma.ts:9

The little of a Prisma 8 client this store needs: the raw lane to build its statements with, and transaction to run them in.

Type Parameters ​

Type Parameter
Tx

Properties ​

PropertyModifierTypeDescriptionDefined in
rawreadonlyobjectRequired to EXIST and not described further, for @btravstack/prisma's reason: the real tag takes the contract's own interpolation and row-spec types, narrower than anything a package that cannot see a contract could name, and a parameter is contravariant.outbox/src/prisma.ts:16
raw.sqlreadonlyunknown-outbox/src/prisma.ts:16
transactionreadonly<R>(fn) => Promise<R>-outbox/src/prisma.ts:17

PrismaOutboxStoreOptions ​

ts
type PrismaOutboxStoreOptions = object;

Defined in: outbox/src/prisma.ts:32

Where the table lives, and what its tenant boundary is called.

Properties ​

PropertyModifierTypeDescriptionDefined in
columns?readonlyOutboxColumnsEach column's physical name, for a table mapped with @map (default: the field names).outbox/src/prisma.ts:38
schema?readonlystringThe namespace the model is declared in (default public).outbox/src/prisma.ts:34
table?readonlystringThe table Prisma maps the model to (default outboxMessage, the table of a model named OutboxMessage).outbox/src/prisma.ts:36
tenantSetting?readonlystringThe run-time setting each tenant's reads and marks are pinned to, which a row-level-security policy on the table reads (default app.tenant_id, as @btravstack/prisma/rls's tenantPinned).outbox/src/prisma.ts:44

Functions ​

prismaOutboxStore() ​

ts
function prismaOutboxStore<Tx>(db, options?): OutboxStoreService;

Defined in: outbox/src/prisma.ts:116

The outbox store over a Prisma 8 client, in raw SQL against the documented table — the model is the application's, declared in its own contract.

The claim is a transaction-scoped advisory lock per tenant, taken with pg_try_advisory_xact_lock before the batch is read: a relay that does not get it skips the tenant, and the lock dies with the transaction, so a relay that crashes mid-batch releases it with its connection. The batch is read, published and marked inside that one transaction, so a mark that never commits leaves its rows pending rather than lost. The cost is a pooled connection held for the length of one batch's publishes.

One relay per tenant holds while its claiming session lives. The claim lifts idle_in_transaction_session_timeout for its own transaction, so a configured timeout cannot end it mid-batch; a session the server ends any other way (a terminated backend, a failover) frees the lock while the relay is still publishing, and another relay may publish the same rows — which is at-least-once delivery, deduplicated on the id.

The table's id is a BigInt — an Int runs out at 2^31 — read through pg/int8@1 and refused, as a defect, past 2^53 rather than rounded. occurredAt is read through to_json, which answers ISO 8601 whatever the column's codec or the server's DateStyle, so the store needs no codec beyond pg/text@1 and pg/int8@1 — both of which the table itself uses.

Type Parameters ​

Type Parameter
Tx

Parameters ​

ParameterType
dbOutboxDatabase<Tx>
optionsPrismaOutboxStoreOptions

Returns ​

OutboxStoreService

Released under the MIT License.