Skip to content

InlineProjection

API reference for InlineProjection

@delta-base/toolkit


An inline projection that runs within the same request as the event append, providing read-after-write consistency.

Extends Projection<TEvent> with optional catch-up capabilities. The SDK automatically handles batch reading and idempotent event delivery — the projection only needs to declare where it left off.

const orderProjection: InlineProjection<OrderEvent> = {
supportedEventTypes: ['order.created', 'order.shipped'],
async processEvents(events) {
await db.transaction(async (tx) => {
for (const e of events) {
await tx.insert(orders).values(toRow(e)).onConflictDoNothing();
}
const last = events.at(-1);
if (last) {
await tx.insert(cursors)
.values({ name: 'orders', position: last.globalPosition })
.onConflictDoUpdate({ set: { position: last.globalPosition } });
}
});
},
async lastProcessedPosition() {
const row = await db.select().from(cursors)
.where(eq(cursors.name, 'orders')).get();
return row?.position ?? 0;
},
};

TEvent extends Event

readonly supportedEventTypes: EventTypeOf<TEvent>[]

List of event types this projection can handle

Projection.supportedEventTypes

optional catchUp(eventStore): Promise<void>

Full custom catch-up logic. When present, the SDK delegates catch-up entirely to this method instead of using the automatic batch-read → processEvents loop.

Use this escape hatch when you need optimised bulk loading (e.g. transactional batch inserts) that processEvents alone cannot express.

EventStore

Promise<void>


optional lastProcessedPosition(): Promise<number>

Return the last globalPosition this projection has processed.

The SDK uses this to:

  1. Catch-up — read historical events starting from (lastProcessedPosition + 1) and feed them through processEvents in batches.
  2. Idempotent handleAppend — skip events whose globalPositionlastProcessedPosition.

The projection owns its own state — the SDK never persists anything. Return 0 to replay from the beginning.

Promise<number>


processEvents(events): Promise<void>

Process events through this projection

ReadEvent<TEvent>[]

Events to process

Promise<void>

Projection.processEvents