Skip to content
API reference

post-d1

Import
import * as api from "@fungi.computer/carrier/post-d1";
Kind Export Description
type alias SqlPostOptions SQL native Carrier runtime configuration; route decisions remain in Post.
type alias SqlPostRuntime Async inspection and Watchdog executor shared by D1 and PostgreSQL.
type alias D1PostSource Trusted SELECT yielding post_key, envelope_json, queue_name, next_attempt_at and job_id.
type alias D1Post Post admission statements; callers commit them with the originating D1 fact.
type alias D1PostErasureStatement Native erasure statement; its values remain bound by the caller’s D1 driver.
constant postD1Schema Carrier-owned D1 schema, applied by the deployment migration owner.
function createD1Post() Bind the Post registry to D1; route deadlines are rejected with PostError.
function prepareD1PostAdmission() Prepare conditional envelopes and their jobs inside the producer’s D1 batch.
function purgeD1Post() Remove selected recipient queues, including every envelope and attempt, atomically. The trusted SELECT yields queue_name from producer/envelope facts, not job state.

SqlPostOptionstype alias

Section titled “SqlPostOptions”
Signature
type SqlPostOptions<R> = Readonly<{
routes: R;
failureDetail?: (cause) => string;
retry?: Readonly<{
maxAttempts: number;
baseDelayMs: number;
maxDelayMs: number;
}>;
now: () => number;
scheduleWake: (at) => Promise<void>;
}>;

SQL native Carrier runtime configuration; route decisions remain in Post.

Type Parameter
R extends Record<string, PostRegistryRoute>

SqlPostRuntimetype alias

Section titled “SqlPostRuntime”
Signature
type SqlPostRuntime = Readonly<{
execute: (
job,
signal?,
) => Promise<
Readonly<{
kind: "completed";
}>
>;
enqueueDue: (limit?, afterKey?) => Promise<string | undefined>;
read: (key) => Promise<PostRow | undefined>;
}>;

Async inspection and Watchdog executor shared by D1 and PostgreSQL.


D1PostSourcetype alias

Section titled “D1PostSource”
Signature
type D1PostSource = Readonly<{
text: string;
values: readonly (string | number | null)[];
}>;

Trusted SELECT yielding post_key, envelope_json, queue_name, next_attempt_at and job_id.


Signature
type D1Post = SqlPostRuntime &
Readonly<{
send: (envelope) => readonly D1PreparedStatement[];
sendFromSelect: (source) => readonly D1PreparedStatement[];
}>;

Post admission statements; callers commit them with the originating D1 fact.


D1PostErasureStatementtype alias

Section titled “D1PostErasureStatement”
Signature
type D1PostErasureStatement = Readonly<{
text: string;
values: readonly (string | number | null)[];
}>;

Native erasure statement; its values remain bound by the caller’s D1 driver.

postD1Schemaconstant

Section titled “postD1Schema”
Signature
const postD1Schema: readonly string[];

Carrier-owned D1 schema, applied by the deployment migration owner.

createD1Post()function

Section titled “createD1Post()”
Signature
function createD1Post<R>(options): D1Post;

Bind the Post registry to D1; route deadlines are rejected with PostError.

Type Parameter
R extends Record<string, Readonly<{ addressKind: string; deadlineMs?: number; address: Codec<unknown, unknown>; event: Codec<unknown, unknown>; encodeEnvelope: (envelope) => object; parseDelivery: (envelope) => object; prepareEnvelope?: (envelope, signal) => Promise<{ key: string; kind: string; address: unknown; event: unknown; }>; recordDelivered?: (envelope) => void; nameOf: (envelope) => string; namespace: Readonly<{ getByName: (name) => Readonly<{ deliver: (envelope) => Promise<PostDeliveryResult>; }>; }>; recordCursor?: (envelope, cursor) => void; recordRefused?: (envelope) => void; }>>
Parameter Type
options Readonly<{ routes: R; failureDetail?: (cause) => string; retry?: Readonly<{ maxAttempts: number; baseDelayMs: number; maxDelayMs: number; }>; now: () => number; scheduleWake: (at) => Promise<void>; }> & Readonly<{ database: D1Database; watchdog: D1Watchdog; }>

D1Post


prepareD1PostAdmission()function

Section titled “prepareD1PostAdmission()”
Signature
function prepareD1PostAdmission(
database,
source,
): readonly D1PreparedStatement[];

Prepare conditional envelopes and their jobs inside the producer’s D1 batch.

Parameter Type
database D1Database
source D1PostSource

readonly D1PreparedStatement[]


purgeD1Post()function

Section titled “purgeD1Post()”
Signature
function purgeD1Post(source): readonly Readonly<{
text: string;
values: readonly (string | number | null)[];
}>[];

Remove selected recipient queues, including every envelope and attempt, atomically. The trusted SELECT yields queue_name from producer/envelope facts, not job state.

Parameter Type
source D1PostErasureStatement

readonly Readonly<{ text: string; values: readonly (string | number | null)[]; }>[]