Events API
Generated public TypeScript reference for @relkit/events.
Common APIs
For configuration and examples, read events, domains, organization.
For a complete workflow, follow react to order events.
Public imports
@relkit/events— 44 exports@relkit/events/effect— 39 exports
All exported APIs
Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API’s inline sample, a maintained repository usage, or the shared module walkthrough.
client-errors.ts
EventClientValidationError (class)
Other expected client validation failure.
Example
new EventClientValidationError({ message: "Invalid event options" });
Signature
declare class EventClientValidationError
EventDependencyError (class)
Publication attempted without a declared event dependency.
Example
new EventDependencyError("orders.created");
Signature
declare class EventDependencyError {
constructor(eventId: string);
}
code (property)
Signature
readonly code: "RELKIT_EVENT_DEPENDENCY_UNDECLARED"
EventOperationCancelledError (class)
Publication cancelled through its AbortSignal.
Example
new EventOperationCancelledError();
Signature
declare class EventOperationCancelledError {
constructor();
}
code (property)
Signature
readonly code: "ABORT_ERR"
EventOperationTimeoutError (class)
Publication exceeded its absolute deadline.
Example
new EventOperationTimeoutError();
Signature
declare class EventOperationTimeoutError {
constructor();
}
code (property)
Signature
readonly code: "ETIMEDOUT"
EventPayloadValidationError (class)
Payload rejected by its Standard Schema validator.
Example
new EventPayloadValidationError([{ message: "Required" }]);
Signature
declare class EventPayloadValidationError { constructor(readonly issues: readonly StandardIssue[]) }
code (property)
Signature
readonly code: "RELKIT_EVENT_PAYLOAD_VALIDATION"
EventPayloadValidationFailure (class)
Tagged payload failure used by Effect clients before Promise adaptation.
Example
new EventPayloadValidationFailure([{ message: "Required" }]);
Signature
declare class EventPayloadValidationFailure {
constructor(issues: readonly StandardIssue[]);
}
issues (property)
Signature
readonly issues: ReadonlyArray<StandardIssue>
EventProfileError (class)
Requested provider profile is missing.
Example
new EventProfileError("default");
Signature
declare class EventProfileError {
constructor(profile: string);
}
code (property)
Signature
readonly code: "RELKIT_EVENT_PROFILE_UNKNOWN"
EventProviderError (class)
Selected provider cannot publish events.
Example
new EventProviderError();
Signature
declare class EventProviderError {
constructor();
}
code (property)
Signature
readonly code: "RELKIT_EVENT_PROVIDER_UNAVAILABLE"
client-operation.ts
EventWorkFailed (class)
Typed failure returned by the work callback.
Example
new EventWorkFailed({ cause: new Error("Provider failed") });
Signature
declare class EventWorkFailed
runAbortable
Promise compatibility adapter for abortable event work.
Throws
The established cancellation, timeout, or provider error.
Example
await runAbortable(new AbortController().signal, undefined, async () => 1);
Signature
declare const runAbortable: <A>(
signal: AbortSignal,
deadlineMs: number | undefined,
work: () => Promise<A>,
) => Promise<A>;
runAbortableEffect
Runs callback work with an owned abort listener and deadline timer.
Example
Effect.runPromise(runAbortableEffect(new AbortController().signal, undefined, async () => 1));
Signature
declare const runAbortableEffect: <A>(
signal: AbortSignal,
deadlineMs: number | undefined,
work: (effectSignal: AbortSignal) => Promise<A>,
) => Effect.Effect<
A,
| EventClientValidationError
| EventDependencyError
| EventOperationCancelledError
| EventOperationTimeoutError
| EventPayloadValidationFailure
| EventWorkFailed,
never
>;
client-provider.ts
notify
Invokes an edge hook without allowing telemetry failure to replace publication.
Example
notify(onObservedEdge, edge);
Signature
declare const notify: <T>(
hook: ((value: T) => void) | undefined,
value: T,
enabled?: boolean,
) => void;
notifyEffect
Effect implementation of best-effort edge notification.
Example
Effect.runSync(notifyEffect(onObservedEdge, edge));
Signature
declare const notifyEffect: <T>(
hook: ((value: T) => void) | undefined,
value: T,
enabled?: boolean | undefined,
) => Effect.Effect<void, never, never>;
resolveProvider
Synchronous provider resolution adapter.
Throws
EventProfileError, EventProviderError, or a resolver error.
Example
resolveProvider(provider, "default", undefined);
Signature
declare const resolveProvider: (
source: unknown,
profile: string,
resolveProfile: ((profile: string) => unknown) | undefined,
) => EventProvider;
resolveProviderEffect
Resolves a provider for a named profile.
Example
Effect.runSync(resolveProviderEffect(provider, "default", undefined));
Signature
declare const resolveProviderEffect: (
source: unknown,
profile: string,
resolveProfile: ((profile: string) => unknown) | undefined,
) => Effect.Effect<
EventProvider,
EventClientValidationError | EventProfileError | EventProviderError,
never
>;
resolveValue
Resolves a fixed or lazy correlation ID.
Example
resolveValue(() => "correlation-1");
Signature
declare const resolveValue: (value: EventClientOptions["correlationId"]) => string | undefined;
resolveValueEffect
Effect implementation of lazy correlation ID resolution.
Example
Effect.runSync(resolveValueEffect(() => "correlation-1"));
Signature
declare const resolveValueEffect: (
value: string | (() => string | undefined) | undefined,
) => Effect.Effect<string | undefined, EventClientValidationError, never>;
client-publish.ts
EventPublisher (class)
Substitutable provider boundary for Effect event publication.
Example
Effect.provide(publishEventEffect(setup, payload), eventPublisherLayer(provider));
Signature
declare class EventPublisher
eventPublisherLayer
Adapts a Promise provider into a typed Effect service layer.
Example
eventPublisherLayer(provider);
Signature
declare const eventPublisherLayer: (provider: EventProvider) => Layer.Layer<EventPublisher>;
publishEventEffect
Publishes one event through a supplied provider service.
Example
Effect.runPromise(
publishEventEffect(setup, payload).pipe(Effect.provide(eventPublisherLayer(provider))),
);
Signature
declare const publishEventEffect: <
Id extends string,
Version extends number,
PayloadSchema extends StandardSchemaV1,
>(
setup: EventPublishSetup<Id, Version, PayloadSchema>,
payload: InferInput<PayloadSchema>,
request?: EventPublishOptions,
) => Effect.Effect<
EventPublishResult<Id, Version, InferOutput<PayloadSchema>>,
EventPublishFailure,
EventPublisher
>;
client-publish.types.ts
EventProvider
Signature
declare const EventProvider: EventProvider;
EventPublishFailure (type alias)
Typed failures of an Effect event publication.
Example
Effect.catchTag(publishEventEffect(setup, payload), "EventPayloadValidationFailure", handle);
Signature
type EventPublishFailure =
| EventClientValidationError
| EventDependencyError
| EventOperationCancelledError
| EventOperationTimeoutError
| EventPayloadValidationFailure
| EventWorkFailed;
EventPublishOptions
Signature
declare const EventPublishOptions: EventPublishOptions;
EventPublishResult
Signature
declare const EventPublishResult: EventPublishResult<Id, Version, Payload>;
EventPublishSetup (interface)
Validated state captured by a generated event client.
Example
const setup: EventPublishSetup<"orders.created", 1, typeof schema> = validated;
Signature
export interface EventPublishSetup<
Id extends string,
Version extends number,
PayloadSchema extends StandardSchemaV1,
> {
readonly options: EventClientOptions<Id, Version, PayloadSchema>;
readonly ownerId: string;
readonly eventId: Id;
readonly version: Version;
readonly profile: string;
readonly declared: boolean;
}
EventPublisherService (interface)
Provider operation supplied to an Effect publication.
Example
const publisher: EventPublisherService = { publish: () => Effect.succeed(reply) };
Signature
export interface EventPublisherService {
/** Publishes a validated payload.
* @param payload - Decoded payload.
* @param options - Validated request options.
* @param context - Cancellation and trace context.
* @returns Provider metadata or EventWorkFailed.
* @example yield* publisher.publish(payload, {}, context)
*/
readonly publish: (
payload: unknown,
options: EventPublishOptions,
context: EventOperationContext,
) => Effect.Effect<EventProviderResult, EventWorkFailed>;
}
InferInput
Signature
declare const InferInput: InferInput<S>;
InferOutput
Signature
declare const InferOutput: InferOutput<S>;
StandardSchemaV1
Signature
declare const StandardSchemaV1: StandardSchemaV1<TInput, TOutput>;
client-record.ts
isRecord
Checks a value for a plain record shape.
Example
isRecord({ key: "value" });
Signature
declare const isRecord: (value: unknown) => value is Record<string, unknown>;
isRecordEffect
Effect implementation of the client record predicate.
Example
Effect.runSync(isRecordEffect({ key: "value" }));
Signature
declare const isRecordEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
client-result.ts
EventIdentity (class)
Substitutable time and identifier boundary for event envelopes.
Example
Effect.provide(
normalizeResultEffect(reply, payload, {}, context, undefined, "orders.created", 1),
EventIdentityLive,
);
Signature
declare class EventIdentity
EventIdentityLive
Default wall clock and random UUID source.
Example
Effect.provide(
normalizeResultEffect(reply, payload, {}, context, undefined, "orders.created", 1),
EventIdentityLive,
);
Signature
declare const EventIdentityLive: Layer.Layer<EventIdentity, never, never>;
normalizeResult
Synchronous compatibility adapter for provider result normalization.
Throws
TypeError when provider metadata cannot be normalized.
Example
normalizeResult(reply, input, {}, context, undefined, "orders.created", 1);
Signature
declare const normalizeResult: <Id extends string, Version extends number, Payload>(
value: EventProviderResult | undefined,
payload: Payload,
options: EventPublishOptions,
context: EventOperationContext,
now: (() => Date) | undefined,
eventId: Id,
version: Version,
) => EventPublishResult<Id, Version, Payload>;
normalizeResultEffect
Builds the accepted event envelope from provider metadata.
Example
Effect.runSync(normalizeResultEffect(reply, input, {}, context, undefined, "orders.created", 1));
Signature
declare const normalizeResultEffect: <Id extends string, Version extends number, Payload>(
value: EventProviderResult | undefined,
payload: Payload,
options: EventPublishOptions,
context: EventOperationContext,
now: (() => Date) | undefined,
eventId: Id,
version: Version,
) => Effect.Effect<EventPublishResult<Id, Version, Payload>, EventClientValidationError>;
client-result.types.ts
Substitutable clock and identifier source for event envelopes.
Example
const identity: EventIdentityService = { now: () => new Date(0), nextId: () => "event-1" };
EventIdentityService (interface)
Substitutable clock and identifier source for event envelopes.
Example
const identity: EventIdentityService = { now: () => new Date(0), nextId: () => "event-1" };
Signature
export interface EventIdentityService {
/** Reads the current wall-clock time.
* @returns The current date.
* @example identity.now()
*/
readonly now: () => Date;
/** Generates a unique event instance ID.
* @returns An opaque instance ID.
* @example identity.nextId()
*/
readonly nextId: () => string;
}
EventOperationContext
Signature
declare const EventOperationContext: EventOperationContext;
EventProviderResult
Signature
declare const EventProviderResult: EventProviderResult<Id, Version, Payload>;
EventPublishOptions
Signature
declare const EventPublishOptions: EventPublishOptions;
EventPublishResult
Signature
declare const EventPublishResult: EventPublishResult<Id, Version, Payload>;
client-utils.ts
EventClientValidationError
Signature
declare const EventClientValidationError: typeof EventClientValidationError;
EventDependencyError
Signature
declare const EventDependencyError: typeof EventDependencyError;
EventOperationCancelledError
Signature
declare const EventOperationCancelledError: typeof EventOperationCancelledError;
EventOperationTimeoutError
Signature
declare const EventOperationTimeoutError: typeof EventOperationTimeoutError;
EventPayloadValidationError
Signature
declare const EventPayloadValidationError: typeof EventPayloadValidationError;
EventProfileError
Signature
declare const EventProfileError: typeof EventProfileError;
EventProviderError
Signature
declare const EventProviderError: typeof EventProviderError;
assertOptionalText
Signature
declare const assertOptionalText: (value: unknown, name: string) => void;
assertOptionalTextEffect
Signature
declare const assertOptionalTextEffect: (
value: unknown,
name: string,
) => Effect<void, EventClientValidationError, never>;
assertVersion
Signature
declare const assertVersion: (value: unknown) => asserts value is number;
assertVersionEffect
Signature
declare const assertVersionEffect: (
value: unknown,
) => Effect<number, EventClientValidationError, never>;
normalizeAttributesEffect
Signature
declare const normalizeAttributesEffect: (
value: unknown,
) => Effect<Readonly<Record<string, EventAttributeValue>>, EventClientValidationError, never>;
normalizeOptions
Signature
declare const normalizeOptions: (value: unknown) => EventPublishOptions;
normalizeOptionsEffect
Signature
declare const normalizeOptionsEffect: (
value: unknown,
) => Effect<EventPublishOptions, EventClientValidationError, never>;
normalizeResult
Signature
declare const normalizeResult: <Id extends string, Version extends number, Payload>(
value: EventProviderResult | undefined,
payload: Payload,
options: EventPublishOptions,
context: EventOperationContext,
now: (() => Date) | undefined,
eventId: Id,
version: Version,
) => EventPublishResult<Id, Version, Payload>;
normalizeResultEffect
Signature
declare const normalizeResultEffect: <Id extends string, Version extends number, Payload>(
value: EventProviderResult | undefined,
payload: Payload,
options: EventPublishOptions,
context: EventOperationContext,
now: (() => Date) | undefined,
eventId: Id,
version: Version,
) => Effect<EventPublishResult<Id, Version, Payload>, EventClientValidationError>;
notify
Signature
declare const notify: <T>(
hook: ((value: T) => void) | undefined,
value: T,
enabled?: boolean,
) => void;
notifyEffect
Signature
declare const notifyEffect: <T>(
hook: ((value: T) => void) | undefined,
value: T,
enabled?: boolean | undefined,
) => Effect<void, never, never>;
parsePayload
Signature
declare const parsePayload: (
schema: StandardSchemaV1 | undefined,
payload: unknown,
) => Promise<unknown>;
parsePayloadEffect
Signature
declare const parsePayloadEffect: (
schema: StandardSchemaV1<unknown, unknown> | undefined,
payload: unknown,
) => Effect<unknown, EventClientValidationError | EventPayloadValidationFailure, never>;
resolveProvider
Signature
declare const resolveProvider: (
source: unknown,
profile: string,
resolveProfile: ((profile: string) => unknown) | undefined,
) => EventProvider;
resolveProviderEffect
Signature
declare const resolveProviderEffect: (
source: unknown,
profile: string,
resolveProfile: ((profile: string) => unknown) | undefined,
) => Effect<
EventProvider,
EventClientValidationError | EventProfileError | EventProviderError,
never
>;
resolveValue
Signature
declare const resolveValue: (value: EventClientOptions["correlationId"]) => string | undefined;
resolveValueEffect
Signature
declare const resolveValueEffect: (
value: string | (() => string | undefined) | undefined,
) => Effect<string | undefined, EventClientValidationError, never>;
client-validation.ts
assertOptionalText
Synchronous optional text assertion.
Throws
TypeError for empty or non-text input.
Example
assertOptionalText("key", "key");
Signature
declare const assertOptionalText: (value: unknown, name: string) => void;
assertOptionalTextEffect
Requires optional text to be non-empty when present.
Example
Effect.runSync(assertOptionalTextEffect("key", "key"));
Signature
declare const assertOptionalTextEffect: (
value: unknown,
name: string,
) => Effect.Effect<void, EventClientValidationError, never>;
assertVersion
Synchronous positive version assertion.
Throws
TypeError for an invalid version.
Example
assertVersion(1);
Signature
declare const assertVersion: (value: unknown) => asserts value is number;
assertVersionEffect
Requires a positive safe event version.
Example
Effect.runSync(assertVersionEffect(1));
Signature
declare const assertVersionEffect: (
value: unknown,
) => Effect.Effect<number, EventClientValidationError, never>;
normalizeAttributesEffect
Normalizes and sorts bounded event attributes.
Example
Effect.runSync(normalizeAttributesEffect({ source: "checkout" }));
Signature
declare const normalizeAttributesEffect: (
value: unknown,
) => Effect.Effect<
Readonly<Record<string, EventAttributeValue>>,
EventClientValidationError,
never
>;
normalizeOptions
Synchronous adapter for request option normalization.
Throws
TypeError for malformed options.
Example
normalizeOptions({ key: "order-1" });
Signature
declare const normalizeOptions: (value: unknown) => EventPublishOptions;
normalizeOptionsEffect
Validates and freezes publisher request options.
Example
Effect.runSync(normalizeOptionsEffect({ key: "order-1" }));
Signature
declare const normalizeOptionsEffect: (
value: unknown,
) => Effect.Effect<EventPublishOptions, EventClientValidationError, never>;
parsePayload
Promise adapter for payload validation.
Throws
EventPayloadValidationError or EventClientValidationError.
Example
await parsePayload(schema, payload);
Signature
declare const parsePayload: (
schema: StandardSchemaV1 | undefined,
payload: unknown,
) => Promise<unknown>;
parsePayloadEffect
Validates a publication payload with its Standard Schema contract.
Example
await Effect.runPromise(parsePayloadEffect(schema, payload));
Signature
declare const parsePayloadEffect: (
schema: StandardSchemaV1<unknown, unknown> | undefined,
payload: unknown,
) => Effect.Effect<unknown, EventClientValidationError | EventPayloadValidationFailure, never>;
client.ts
EventAttributeValue
Signature
declare const EventAttributeValue: EventAttributeValue;
EventClient
Signature
declare const EventClient: EventClient<Input, Id, Version, Payload>;
EventClientOptions
Signature
declare const EventClientOptions: EventClientOptions<Id, Version, PayloadSchema>;
EventDeclaredEdge
Signature
declare const EventDeclaredEdge: EventDeclaredEdge;
EventDependencyError
Signature
declare const EventDependencyError: typeof EventDependencyError;
EventInvocationBridge
Signature
declare const EventInvocationBridge: EventInvocationBridge;
EventInvocationBridgeOptions
Signature
declare const EventInvocationBridgeOptions: EventInvocationBridgeOptions;
EventObservedEdge
Signature
declare const EventObservedEdge: EventObservedEdge;
EventOperationCancelledError
Signature
declare const EventOperationCancelledError: typeof EventOperationCancelledError;
EventOperationContext
Signature
declare const EventOperationContext: EventOperationContext;
EventOperationTimeoutError
Signature
declare const EventOperationTimeoutError: typeof EventOperationTimeoutError;
EventPayloadValidationError
Signature
declare const EventPayloadValidationError: typeof EventPayloadValidationError;
EventProfileError
Signature
declare const EventProfileError: typeof EventProfileError;
EventProvider
Signature
declare const EventProvider: EventProvider;
EventProviderError
Signature
declare const EventProviderError: typeof EventProviderError;
EventProviderResult
Signature
declare const EventProviderResult: EventProviderResult<Id, Version, Payload>;
EventPublishOptions
Signature
declare const EventPublishOptions: EventPublishOptions;
EventPublishResult
Signature
declare const EventPublishResult: EventPublishResult<Id, Version, Payload>;
createEventClient
Creates a Promise publisher from a validated event contract.
Throws
TypeError for malformed client configuration, or a provider profile error.
Example
createEventClient({
ownerId: "orders.create",
eventId: "orders.created",
version: 1,
source: provider,
});
Signature
declare const createEventClient: <
const Id extends string,
const Version extends number,
const PayloadSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: EventClientOptions<Id, Version, PayloadSchema>,
) => EventClient<InferInput<PayloadSchema>, Id, Version, InferOutput<PayloadSchema>>;
createEventClientEffect
Creates an Effect-backed event publisher with typed configuration failures.
Example
Effect.runSync(
createEventClientEffect({
ownerId: "orders.create",
eventId: "orders.created",
version: 1,
source: provider,
}),
);
Signature
declare const createEventClientEffect: <
const Id extends string,
const Version extends number,
const PayloadSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: EventClientOptions<Id, Version, PayloadSchema>,
) => Effect.Effect<
EventClient<InferInput<PayloadSchema>, Id, Version, InferOutput<PayloadSchema>>,
EventClientValidationError | EventProfileError | EventProviderError
>;
client.types.ts
EventAttributeValue
Signature
declare const EventAttributeValue: EventAttributeValue;
EventClient (interface)
Promise compatibility interface exposed to application handlers.
Example
await client.publish({ orderId: "one" });
Signature
export interface EventClient<
Input = unknown,
Id extends string = string,
Version extends number = number,
Payload = Input,
> {
/** Publishes a payload and returns the accepted envelope.
* @param payload - Event payload to decode.
* @param options - Optional key and attributes.
* @returns A Promise of the accepted envelope or a rejected domain error.
* @example await client.publish(payload, { key: "order-1" })
*/
readonly publish: (
payload: Input,
options?: EventPublishOptions,
) => Promise<EventPublishResult<Id, Version, Payload>>;
}
EventClientOptions (interface)
Dependencies and policy for a generated event publisher. Provider selection occurs once when the client is created.
Example
const options: EventClientOptions = {
ownerId: "orders.create",
eventId: "orders.created",
version: 1,
source: provider,
};
Signature
export interface EventClientOptions<
Id extends string = string,
Version extends number = number,
PayloadSchema extends StandardSchemaV1 = StandardSchemaV1,
> {
readonly ownerId: string;
readonly eventId: Id;
readonly version: Version;
readonly source: unknown;
readonly payloadSchema?: PayloadSchema;
readonly profile?: string;
readonly resolveProfile?: (profile: string) => unknown;
readonly bridge?: EventInvocationBridge;
readonly signal?: () => AbortSignal;
readonly deadline?: () => number | undefined;
readonly correlationId?: string | (() => string | undefined);
readonly now?: () => Date;
readonly declared?: boolean;
readonly onDeclaredEdge?: (edge: EventDeclaredEdge) => void;
readonly onObservedEdge?: (edge: EventObservedEdge) => void;
}
EventDeclaredEdge (interface)
Static graph edge for a declared publication dependency.
Example
const edge: EventDeclaredEdge = {
kind: "publishes-event",
from: "orders.create",
to: "orders.created",
};
Signature
export interface EventDeclaredEdge {
readonly kind: "publishes-event";
readonly from: string;
readonly to: string;
}
EventInvocationBridge (interface)
Optional invocation bridge that owns a publication span.
Example
await bridge.run(() => provider.publish(payload, {}, context));
Signature
export interface EventInvocationBridge {
/** Runs publication within the invocation context.
* @param operation - Publication callback.
* @param options - Producer span metadata.
* @returns The operation result or rejection.
* @example await bridge.run(() => Promise.resolve(1))
*/
readonly run: <A>(
operation: () => MaybePromise<A>,
options?: EventInvocationBridgeOptions,
) => Promise<A>;
}
EventInvocationBridgeOptions (interface)
Trace bridge metadata for a producer operation.
Example
const name = options.name;
Signature
export interface EventInvocationBridgeOptions {
readonly name?: string;
readonly attributes?: Readonly<Record<string, unknown>>;
readonly signal?: AbortSignal;
readonly kind?: "producer";
readonly input?: unknown;
}
EventObservedEdge (interface)
Runtime graph edge for an attempted publication.
Example
const edge: EventObservedEdge = {
relationship: "publishes-event",
from: "orders.create",
to: "orders.created",
};
Signature
export interface EventObservedEdge {
readonly relationship: "publishes-event";
readonly from: string;
readonly to: string;
}
EventOperationContext (interface)
Context passed to the selected event provider for one publication. The signal remains valid until the publication settles.
Example
const id = context.eventId;
Signature
export interface EventOperationContext {
readonly operation: "publish";
readonly eventId: string;
readonly version: number;
readonly signal: AbortSignal;
readonly profile: string;
readonly deadlineMs?: number;
readonly propagation?: TracePropagation;
}
EventProvider (interface)
Provider interface selected from a profile for publication.
Example
const provider: EventProvider = {
publish: async () => ({ accepted: true, instanceId: "event-1" }),
};
Signature
export interface EventProvider {
/** Publishes one validated payload.
* @param payload - Decoded event payload.
* @param options - Validated publish options.
* @param context - Trace and cancellation context.
* @returns Provider acceptance and metadata, or a rejected Promise.
* @example await provider.publish(payload, {}, context)
*/
readonly publish: (
payload: unknown,
options: EventPublishOptions,
context: EventOperationContext,
) => MaybePromise<EventProviderResult>;
}
EventProviderResult (type alias)
Provider acknowledgement and optional envelope metadata.
Example
const result: EventProviderResult = { accepted: true, instanceId: "event-1" };
Signature
type EventProviderResult<
Id extends string = string,
Version extends number = number,
Payload = unknown,
> = Pick<EventPublishResult<Id, Version, Payload>, "instanceId" | "accepted"> &
Partial<Omit<EventPublishResult<Id, Version, Payload>, "instanceId" | "accepted">>;
EventPublishOptions
Signature
declare const EventPublishOptions: EventPublishOptions;
EventPublishResult
Signature
declare const EventPublishResult: EventPublishResult<Id, Version, Payload>;
InferInput
Signature
declare const InferInput: InferInput<S>;
InferOutput
Signature
declare const InferOutput: InferOutput<S>;
StandardSchemaV1
Signature
declare const StandardSchemaV1: StandardSchemaV1<TInput, TOutput>;
define-event-function.ts
defineEventFunction
Defines an independent event-only consumer with inferred input and void success. Event IDs are supplied by the application’s generated EventRegistry.
Throws
TypeError for malformed options.
Example
import { defineEvent, defineEventFunction } from "@relkit/app/events";
import { z } from "@relkit/app/schema";
const orderCreated = defineEvent({
id: "orders.created",
input: z.object({ orderId: z.string() }),
});
// The application normally generates this declaration with `relkit check`.
declare global {
namespace Relkit {
interface EventRegistry {
"orders.created": typeof orderCreated;
}
}
}
const receipt = defineEventFunction({
id: "receipt.send",
event: "orders.created",
handler: async () => {},
});
Signature
declare const defineEventFunction: <
const Id extends string,
const Event extends EventName,
const Publishes extends readonly EventName[] = readonly [],
const Dependencies extends FunctionDependencies = {},
const Options extends EventFunctionCallOptions<Id, Event, Publishes, Dependencies> =
EventFunctionCallOptions<Id, Event, Publishes, Dependencies>,
>(
options: EventFunctionCallOptions<Id, Event, Publishes, Dependencies> &
Options &
EventFunctionValidation<NoInfer<Options>>,
) => EventFunctionDescriptor<Id, Event, Publishes, Dependencies, ErrorListOf<Options>>;
Since v0.1.0
defineEventFunctionEffect
Defines an event-only function in Effect.
Example
Effect.runSync(
defineEventFunctionEffect({ id: "notify", event: "orders.created", handler: () => {} }),
);
Signature
declare const defineEventFunctionEffect: <
const Id extends string,
const Event extends EventName,
const Publishes extends readonly EventName[] = readonly [],
const Dependencies extends FunctionDependencies = {},
const Options extends EventFunctionCallOptions<Id, Event, Publishes, Dependencies> =
EventFunctionCallOptions<Id, Event, Publishes, Dependencies>,
>(
options: EventFunctionCallOptions<Id, Event, Publishes, Dependencies> &
Options &
EventFunctionValidation<NoInfer<Options>>,
) => Effect.Effect<
EventFunctionDescriptor<Id, Event, Publishes, Dependencies, ErrorListOf<Options>>,
EventDefinitionError
>;
isEventFunctionDescriptor
Checks an event-only function descriptor at a synchronous boundary.
Example
isEventFunctionDescriptor(candidate);
Signature
declare const isEventFunctionDescriptor: (value: unknown) => value is EventFunctionDescriptorAny;
isEventFunctionDescriptorEffect
Checks an unknown value for a valid event-only function descriptor.
Example
Effect.runSync(isEventFunctionDescriptorEffect(candidate));
Signature
declare const isEventFunctionDescriptorEffect: (
value: unknown,
) => Effect.Effect<boolean, never, never>;
define-event-function.types.ts
ErrorDescriptorAny
Signature
declare const ErrorDescriptorAny: ErrorDescriptorAny;
ErrorListOf (type alias)
Error declarations inferred from a function definition.
Example
type Errors = ErrorListOf<typeof options>;
Signature
type ErrorListOf<Options> = Options extends {
readonly errors: infer Errors extends readonly ErrorDescriptorAny[];
}
? Errors
: readonly [];
EventFunctionCallOptions (type alias)
Handler-aware options for an event function definition.
Example
type Options = EventFunctionCallOptions<"receipt.send", "orders.created", [], {}>;
Signature
type EventFunctionCallOptions<
Id extends string,
Event extends EventName,
Publishes extends readonly EventName[],
Dependencies extends FunctionDependencies,
> = Omit<
DefineEventFunctionOptions<Id, Event, Publishes, Dependencies, readonly ErrorDescriptorAny[]>,
"handler"
> & {
readonly handler: (
input: EventInputByName<Event>,
context: EventFunctionContext<Event, Publishes, Dependencies>,
) => unknown;
};
EventFunctionDescriptor
Signature
declare const EventFunctionDescriptor: EventFunctionDescriptor<
Id,
Event,
Publishes,
Dependencies,
Errors
>;
EventFunctionDescriptorAny
Signature
declare const EventFunctionDescriptorAny: EventFunctionDescriptorAny;
EventFunctionValidation (type alias)
Validates a handler’s result against declared errors and void success.
Example
type Validation = EventFunctionValidation<typeof options>;
Signature
type EventFunctionValidation<Options extends { readonly handler: (...args: never[]) => unknown }> =
FunctionHandlerValidation<Awaited<ReturnType<Options["handler"]>>, void, ErrorListOf<Options>>;
EventName
Signature
declare const EventName: never;
FunctionDependencies
Signature
declare const FunctionDependencies: FunctionDependencies;
define-event.ts
defineEvent
Defines a versioned event contract used by publishers and event functions.
Throws
TypeError when the contract is malformed.
Example
import { defineEvent } from "@relkit/app/events";
import { z } from "@relkit/app/schema";
const created = defineEvent({ id: "orders.created", input: z.object({ orderId: z.string() }) });
void created;
Signature
declare const defineEvent: <
const Id extends string,
const Version extends number = 1,
const InputSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: DefineEventOptions<Id, Version, InputSchema>,
) => EventDescriptor<Id, Version, InferOutput<InputSchema>, InputSchema>;
Since v0.1.0
DefineEventOptions
Signature
declare const DefineEventOptions: DefineEventOptions<Id, Version, InputSchema>;
EventDescriptor
Signature
declare const EventDescriptor: EventDescriptor<Id, Version, Input, InputSchema>;
EventDescriptorAny
Signature
declare const EventDescriptorAny: EventDescriptorAny;
EventEnvelope
Signature
declare const EventEnvelope: EventEnvelope<Id, Version, Payload>;
EventEnvelopeFor
Signature
declare const EventEnvelopeFor: EventEnvelopeFor<E>;
UnknownEventEnvelope
Signature
declare const UnknownEventEnvelope: UnknownEventEnvelope;
assertEventDescriptor
Requires a valid event descriptor at a synchronous boundary.
Throws
TypeError when the candidate is invalid.
Example
assertEventDescriptor(value);
Signature
declare const assertEventDescriptor: (value: unknown) => asserts value is EventDescriptorAny;
assertEventDescriptorEffect
Requires a valid event descriptor in an Effect workflow.
Example
Effect.runSync(assertEventDescriptorEffect(candidate));
Signature
declare const assertEventDescriptorEffect: (
value: unknown,
) => Effect.Effect<EventDescriptorAny, EventDefinitionError, never>;
defineEventEffect
Defines an event contract in Effect with typed validation failure.
Example
Effect.runSync(defineEventEffect({ id: "orders.created", input: z.object({}) }));
Signature
declare const defineEventEffect: <
const Id extends string,
const Version extends number = 1,
const InputSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: DefineEventOptions<Id, Version, InputSchema>,
) => Effect.Effect<
EventDescriptor<Id, Version, InferOutput<InputSchema>, InputSchema>,
EventDefinitionError
>;
isEventDescriptor
Checks a candidate against the event descriptor contract.
Example
isEventDescriptor(value);
Signature
declare const isEventDescriptor: (value: unknown) => value is EventDescriptorAny;
isEventDescriptorEffect
Checks whether an unknown value is a valid event descriptor.
Example
Effect.runSync(isEventDescriptorEffect(candidate));
Signature
declare const isEventDescriptorEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
define-event.types.ts
DefineEventOptions (interface)
Input accepted by the event descriptor factory.
Example
const options: DefineEventOptions<"orders.created", 1, typeof schema> = {
id: "orders.created",
input: schema,
};
Signature
export interface DefineEventOptions<
Id extends string,
Version extends number,
InputSchema extends StandardSchemaV1,
> extends DescriptorMetadata {
readonly id: Id;
readonly version?: Version;
readonly input: InputSchema;
readonly profile?: string;
readonly sensitiveFields?: readonly string[];
readonly handler?: never;
readonly output?: never;
}
EventDescriptor (interface)
Immutable, versioned event contract with no handler or output.
Example
const created: EventDescriptor<"orders.created", 1, { orderId: string }> = defineEvent(options);
Signature
export interface EventDescriptor<
Id extends string,
Version extends number,
Input,
InputSchema extends StandardSchemaV1 = StandardSchemaV1,
>
extends DescriptorBase<"event", Id>, EventRef<Id, InputSchema> {
readonly version: Version;
readonly input: InputSchema;
readonly profile?: string;
readonly sensitiveFields?: readonly string[];
readonly handler?: never;
readonly output?: never;
readonly __input?: Input;
}
EventDescriptorAny (type alias)
Event descriptor with erased contract parameters.
Example
const registry: EventDescriptorAny[] = [created];
Signature
type EventDescriptorAny = EventDescriptor<string, number, unknown, StandardSchemaV1>;
EventEnvelope (type alias)
Published event data without the provider acceptance flag.
Example
type Created = EventEnvelope<"orders.created", 1, { orderId: string }>;
Signature
type EventEnvelope<
Id extends string = string,
Version extends number = number,
Payload = unknown,
> = Omit<EventPublishResult<Id, Version, Payload>, "accepted">;
EventEnvelopeFor (type alias)
Resolves the envelope for a specific event descriptor.
Example
type CreatedEnvelope = EventEnvelopeFor<typeof created>;
Signature
type EventEnvelopeFor<E> =
E extends EventDescriptor<infer Id, infer Version, infer Input, StandardSchemaV1>
? EventEnvelope<Id, Version, Input>
: UnknownEventEnvelope;
InferOutput
Signature
declare const InferOutput: InferOutput<S>;
StandardSchemaV1
Signature
declare const StandardSchemaV1: StandardSchemaV1<TInput, TOutput>;
UnknownEventEnvelope (type alias)
Event data when its contract is not known statically.
Example
const envelope: UnknownEventEnvelope = received;
Signature
type UnknownEventEnvelope = EventEnvelope<string, number, unknown>;
effect.ts
EventBindingError
Signature
declare const EventBindingError: typeof EventBindingError;
EventDefinitionError
Signature
declare const EventDefinitionError: typeof EventDefinitionError;
EventIdentity
Signature
declare const EventIdentity: typeof EventIdentity;
EventIdentityLive
Signature
declare const EventIdentityLive: Layer<EventIdentity, never, never>;
EventIdentityService
Signature
declare const EventIdentityService: EventIdentityService;
EventOperation
Signature
declare const EventOperation: EventOperation;
EventPayloadValidationFailure
Signature
declare const EventPayloadValidationFailure: typeof EventPayloadValidationFailure;
EventPublishFailure
Signature
declare const EventPublishFailure: EventPublishFailure;
EventPublishSetup
Signature
declare const EventPublishSetup: EventPublishSetup<Id, Version, PayloadSchema>;
EventPublisher
Signature
declare const EventPublisher: typeof EventPublisher;
EventPublisherService
Signature
declare const EventPublisherService: EventPublisherService;
EventTelemetry
Signature
declare const EventTelemetry: typeof EventTelemetry;
EventTelemetryLive
Signature
declare const EventTelemetryLive: Layer<EventTelemetry, never, never>;
EventTelemetryService
Signature
declare const EventTelemetryService: EventTelemetryService;
EventWorkFailed
Signature
declare const EventWorkFailed: typeof EventWorkFailed;
assertEventDescriptorEffect
Signature
declare const assertEventDescriptorEffect: (
value: unknown,
) => Effect<EventDescriptorAny, EventDefinitionError, never>;
assertOptionalTextEffect
Signature
declare const assertOptionalTextEffect: (
value: unknown,
name: string,
) => Effect<void, EventClientValidationError, never>;
assertVersionEffect
Signature
declare const assertVersionEffect: (
value: unknown,
) => Effect<number, EventClientValidationError, never>;
bindFunctionEventsEffect
Signature
declare const bindFunctionEventsEffect: <T extends FunctionWithEvents>(
descriptor: T,
consumed: EventDescriptorAny | undefined,
published: readonly EventDescriptorAny[],
) => Effect<T, EventBindingError>;
createEventClientEffect
Signature
declare const createEventClientEffect: <
const Id extends string,
const Version extends number,
const PayloadSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: EventClientOptions<Id, Version, PayloadSchema>,
) => Effect<
EventClient<InferInput<PayloadSchema>, Id, Version, InferOutput<PayloadSchema>>,
EventClientValidationError | EventProfileError | EventProviderError
>;
defineEventEffect
Signature
declare const defineEventEffect: <
const Id extends string,
const Version extends number = 1,
const InputSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: DefineEventOptions<Id, Version, InputSchema>,
) => Effect<
EventDescriptor<Id, Version, InferOutput<InputSchema>, InputSchema>,
EventDefinitionError
>;
defineEventFunctionEffect
Signature
declare const defineEventFunctionEffect: <
const Id extends string,
const Event extends EventName,
const Publishes extends readonly EventName[] = readonly [],
const Dependencies extends FunctionDependencies = {},
const Options extends EventFunctionCallOptions<Id, Event, Publishes, Dependencies> =
EventFunctionCallOptions<Id, Event, Publishes, Dependencies>,
>(
options: EventFunctionCallOptions<Id, Event, Publishes, Dependencies> &
Options &
EventFunctionValidation<NoInfer<Options>>,
) => Effect<
EventFunctionDescriptor<Id, Event, Publishes, Dependencies, ErrorListOf<Options>>,
EventDefinitionError
>;
eventDeliveryEffect
Signature
declare const eventDeliveryEffect: (
value: unknown,
) => Effect<EventDelivery, EventDefinitionError, never>;
eventProfileEffect
Signature
declare const eventProfileEffect: (value: unknown) => Effect<string, EventDefinitionError, never>;
eventPublisherLayer
Signature
declare const eventPublisherLayer: (provider: EventProvider) => Layer<EventPublisher>;
eventRetryEffect
Signature
declare const eventRetryEffect: (
value: unknown,
) => Effect<RetryPolicy, EventDefinitionError, never>;
isEventDescriptorEffect
Signature
declare const isEventDescriptorEffect: (value: unknown) => Effect<boolean, never, never>;
isEventFunctionDescriptorEffect
Signature
declare const isEventFunctionDescriptorEffect: (value: unknown) => Effect<boolean, never, never>;
normalizeAttributesEffect
Signature
declare const normalizeAttributesEffect: (
value: unknown,
) => Effect<Readonly<Record<string, EventAttributeValue>>, EventClientValidationError, never>;
normalizeOptionsEffect
Signature
declare const normalizeOptionsEffect: (
value: unknown,
) => Effect<EventPublishOptions, EventClientValidationError, never>;
normalizeResultEffect
Signature
declare const normalizeResultEffect: <Id extends string, Version extends number, Payload>(
value: EventProviderResult | undefined,
payload: Payload,
options: EventPublishOptions,
context: EventOperationContext,
now: (() => Date) | undefined,
eventId: Id,
version: Version,
) => Effect<EventPublishResult<Id, Version, Payload>, EventClientValidationError>;
notifyEffect
Signature
declare const notifyEffect: <T>(
hook: ((value: T) => void) | undefined,
value: T,
enabled?: boolean | undefined,
) => Effect<void, never, never>;
observeEvent
Signature
declare const observeEvent: <A, E, R>(
operation: EventOperation,
effect: Effect<A, E, R>,
) => Effect<A, E, R>;
parsePayloadEffect
Signature
declare const parsePayloadEffect: (
schema: StandardSchemaV1<unknown, unknown> | undefined,
payload: unknown,
) => Effect<unknown, EventClientValidationError | EventPayloadValidationFailure, never>;
publishEventEffect
Signature
declare const publishEventEffect: <
Id extends string,
Version extends number,
PayloadSchema extends StandardSchemaV1,
>(
setup: EventPublishSetup<Id, Version, PayloadSchema>,
payload: InferInput<PayloadSchema>,
request?: EventPublishOptions,
) => Effect<
EventPublishResult<Id, Version, InferOutput<PayloadSchema>>,
EventPublishFailure,
EventPublisher
>;
rejectEventFunctionFieldsEffect
Signature
declare const rejectEventFunctionFieldsEffect: (
options: Record<PropertyKey, unknown>,
) => Effect<void, EventDefinitionError, never>;
resolveProviderEffect
Signature
declare const resolveProviderEffect: (
source: unknown,
profile: string,
resolveProfile: ((profile: string) => unknown) | undefined,
) => Effect<
EventProvider,
EventClientValidationError | EventProfileError | EventProviderError,
never
>;
resolveValueEffect
Signature
declare const resolveValueEffect: (
value: string | (() => string | undefined) | undefined,
) => Effect<string | undefined, EventClientValidationError, never>;
runAbortableEffect
Signature
declare const runAbortableEffect: <A>(
signal: AbortSignal,
deadlineMs: number | undefined,
work: (effectSignal: AbortSignal) => Promise<A>,
) => Effect<
A,
| EventClientValidationError
| EventDependencyError
| EventOperationCancelledError
| EventOperationTimeoutError
| EventPayloadValidationFailure
| EventWorkFailed,
never
>;
event-contract-shape.ts
hasOwn
Checks whether a descriptor owns a named property.
Example
hasOwn({ id: "orders.created" }, "id");
Signature
declare const hasOwn: (value: object, key: PropertyKey) => boolean;
hasOwnEffect
Effect implementation of direct property ownership detection.
Example
Effect.runSync(hasOwnEffect({ id: "orders.created" }, "id"));
Signature
declare const hasOwnEffect: (
value: object,
key: PropertyKey,
) => Effect.Effect<boolean, never, never>;
isPositiveInteger
Checks for a positive safe version number.
Example
isPositiveInteger(1);
Signature
declare const isPositiveInteger: (value: unknown) => value is number;
isPositiveIntegerEffect
Effect implementation of the positive safe integer predicate.
Example
Effect.runSync(isPositiveIntegerEffect(1));
Signature
declare const isPositiveIntegerEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
isRecord
Checks whether a value is a non-array object.
Example
isRecord({ id: "orders.created" });
Signature
declare const isRecord: (value: unknown) => value is Record<PropertyKey, unknown>;
isRecordEffect
Effect implementation of the descriptor record predicate.
Example
Effect.runSync(isRecordEffect({ id: "orders.created" }));
Signature
declare const isRecordEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
isSchema
Checks the Standard Schema v1 runtime contract.
Example
isSchema(schema);
Signature
declare const isSchema: (value: unknown) => value is StandardSchemaV1;
isSchemaEffect
Effect implementation of the Standard Schema predicate.
Example
Effect.runSync(isSchemaEffect(schema));
Signature
declare const isSchemaEffect: (value: unknown) => Effect.Effect<boolean, never, never>;
validateVersion
Requires a positive safe version number.
Throws
TypeError for an invalid version.
Example
validateVersion(1);
Signature
declare const validateVersion: (value: unknown) => asserts value is number;
validateVersionEffect
Requires a positive safe version in the Effect error channel.
Example
Effect.runSync(validateVersionEffect(1));
Signature
declare const validateVersionEffect: (
value: unknown,
) => Effect.Effect<number, EventDefinitionError, never>;
event-errors.ts
EventBindingError (class)
A rejected function-to-event binding with a stable typed tag.
Example
new EventBindingError({ message: "Missing event contract" });
Signature
declare class EventBindingError
EventDefinitionError (class)
A rejected event or event-function descriptor with a stable typed tag.
Example
new EventDefinitionError({ message: "Invalid event descriptor" });
Signature
declare class EventDefinitionError
event-function-target.ts
bindFunctionEvents
Binds validated event contracts into a generated function target.
Throws
TypeError if any declared contract is missing or invalid.
Example
bindFunctionEvents(publisher, undefined, [orderCreated]);
Signature
declare const bindFunctionEvents: <T extends FunctionWithEvents>(
descriptor: T,
consumed: EventDescriptorAny | undefined,
published: readonly EventDescriptorAny[],
) => T;
bindFunctionEventsEffect
Binds event contracts with typed failures in an Effect workflow.
Example
Effect.runSync(bindFunctionEventsEffect(publisher, undefined, [orderCreated]));
Signature
declare const bindFunctionEventsEffect: <T extends FunctionWithEvents>(
descriptor: T,
consumed: EventDescriptorAny | undefined,
published: readonly EventDescriptorAny[],
) => Effect.Effect<T, EventBindingError>;
event-function-target.types.ts
Minimal function descriptor accepted by event contract binding.
Example
const target: FunctionWithEvents = { id: "orders.create", publishes: ["orders.created"] };
EventDescriptorAny
Signature
declare const EventDescriptorAny: EventDescriptorAny;
FunctionWithEvents (interface)
Minimal function descriptor accepted by event contract binding.
Example
const target: FunctionWithEvents = { id: "orders.create", publishes: ["orders.created"] };
Signature
export interface FunctionWithEvents {
readonly id: string;
readonly invocationMode?: "callable" | "event-only";
readonly event?: string;
readonly publishes?: readonly string[];
readonly input?: unknown;
}
event-function-validation.ts
eventDelivery
Normalizes event delivery for synchronous authoring.
Throws
TypeError for an unsupported mode.
Example
eventDelivery("durable");
Signature
declare const eventDelivery: (value: unknown) => EventDelivery;
eventDeliveryEffect
Resolves an event function delivery mode.
Example
Effect.runSync(eventDeliveryEffect("durable"));
Signature
declare const eventDeliveryEffect: (
value: unknown,
) => Effect.Effect<EventDelivery, EventDefinitionError, never>;
eventProfile
Normalizes a synchronous event provider profile.
Throws
TypeError for a malformed profile.
Example
eventProfile("default");
Signature
declare const eventProfile: (value: unknown) => string;
eventProfileEffect
Resolves the configured event provider profile.
Example
Effect.runSync(eventProfileEffect("default"));
Signature
declare const eventProfileEffect: (
value: unknown,
) => Effect.Effect<string, EventDefinitionError, never>;
eventRetry
Normalizes synchronous event retry policy input.
Throws
TypeError for invalid retry values.
Example
eventRetry({ maxAttempts: 3 });
Signature
declare const eventRetry: (value: unknown) => RetryPolicy;
eventRetryEffect
Normalizes an event function retry policy.
Example
Effect.runSync(eventRetryEffect({ maxAttempts: 3 }));
Signature
declare const eventRetryEffect: (
value: unknown,
) => Effect.Effect<RetryPolicy, EventDefinitionError, never>;
rejectEventFunctionFields
Rejects descriptor fields reserved for other function kinds.
Throws
TypeError when a forbidden field is present.
Example
rejectEventFunctionFields({ event: "orders.created" });
Signature
declare const rejectEventFunctionFields: (options: Record<PropertyKey, unknown>) => void;
rejectEventFunctionFieldsEffect
Rejects fields owned by other descriptor kinds.
Example
Effect.runSync(rejectEventFunctionFieldsEffect({ event: "orders.created" }));
Signature
declare const rejectEventFunctionFieldsEffect: (
options: Record<PropertyKey, unknown>,
) => Effect.Effect<void, EventDefinitionError, never>;
event-function.types.ts
DefineEventFunctionOptions (interface)
Definition options for a versioned event consumer.
Example
const options = { id: "receipt.send", event: "orders.created", handler: () => {} };
Signature
export interface DefineEventFunctionOptions<
Id extends string,
Event extends EventName,
Publishes extends readonly EventName[] = readonly [],
Dependencies extends FunctionDependencies = {},
Errors extends readonly ErrorDescriptorAny[] = readonly [],
> extends DescriptorMetadata {
readonly id: Id;
readonly event: Event;
readonly delivery?: EventDelivery;
readonly profile?: string;
readonly retry?: Partial<EventRetryPolicy>;
readonly concurrency?: number;
readonly timeoutMs?: number;
readonly publishes?: Publishes;
readonly dependencies?: Dependencies;
readonly errors?: Errors;
readonly onBefore?: (
input: EventInputByName<Event>,
context: EventFunctionContext<Event, Publishes, Dependencies>,
) => MaybePromise<EventInputByName<Event>>;
readonly onAfter?: (
output: void,
context: EventFunctionContext<Event, Publishes, Dependencies>,
) => MaybePromise<void>;
readonly handler: EventFunctionHandler<Event, Publishes, Dependencies, Errors>;
readonly input?: never;
readonly output?: never;
readonly tool?: never;
readonly trigger?: never;
}
EventDelivery (type alias)
Delivery semantics for an event-only function.
Example
const delivery: EventDelivery = "durable";
Signature
type EventDelivery = "ephemeral" | "durable";
EventFunctionContext (interface)
Handler context with event trigger and declared dependencies.
Example
const eventId = context.trigger.event.id;
Signature
export interface EventFunctionContext<
Event extends EventName,
Publishes extends readonly EventName[] = readonly [],
Dependencies extends FunctionDependencies = {},
> extends FunctionContext<Dependencies, Publishes> {
readonly trigger: EventFunctionTrigger<Event>;
}
EventFunctionDescriptor (interface)
Immutable descriptor emitted by defineEventFunction.
Example
const descriptor = defineEventFunction(options);
Signature
export interface EventFunctionDescriptor<
Id extends string = string,
Event extends EventName = EventName,
Publishes extends readonly EventName[] = readonly [],
Dependencies extends FunctionDependencies = {},
Errors extends readonly ErrorDescriptorAny[] = readonly ErrorDescriptorAny[],
> extends DescriptorBase<"function", Id> {
readonly invocationMode: "event-only";
readonly event: Event;
readonly delivery: EventDelivery;
readonly profile: string;
readonly retry: EventRetryPolicy;
readonly concurrency?: number;
readonly timeoutMs?: number;
readonly publishes?: Publishes;
readonly dependencies?: Dependencies;
readonly errors?: Errors;
readonly handler: EventFunctionHandler<Event, Publishes, Dependencies, Errors>;
readonly invoke?: never;
readonly asTool?: never;
readonly __input?: InferOutput<EventDescriptorByName<Event>["input"]>;
}
EventFunctionDescriptorAny (interface)
Event-only descriptor with erased event and dependency types.
Example
const consumer: EventFunctionDescriptorAny = descriptor;
Signature
export interface EventFunctionDescriptorAny extends DescriptorBase<"function"> {
readonly invocationMode: "event-only";
readonly event: string;
readonly delivery: EventDelivery;
readonly profile: string;
readonly retry: EventRetryPolicy;
readonly concurrency?: number;
readonly timeoutMs?: number;
readonly publishes?: readonly string[];
readonly handler: (...args: never[]) => unknown;
}
EventFunctionHandler (type alias)
Handler contract for event-only functions; successful handlers return void.
Example
const handler: EventFunctionHandler<"orders.created", [], {}, []> = () => {};
Signature
type EventFunctionHandler<
Event extends EventName,
Publishes extends readonly EventName[],
Dependencies extends FunctionDependencies,
Errors extends readonly ErrorDescriptorAny[],
> = (
input: EventInputByName<Event>,
context: EventFunctionContext<Event, Publishes, Dependencies>,
) => MaybePromise<FunctionHandlerResult<void, Errors>>;
EventFunctionTrigger (interface)
Trigger metadata supplied for one event delivery.
Example
const attempt = context.trigger.delivery.attempt;
Signature
export interface EventFunctionTrigger<Event extends EventName = EventName> {
readonly kind: "event";
readonly event: {
readonly id: Event;
readonly version: EventVersionByName<Event>;
readonly instanceId: string;
readonly occurredAt: string;
readonly publishedAt: string;
readonly key?: string;
readonly attributes: Readonly<Record<string, string | number | boolean>>;
};
readonly delivery: { readonly attempt: number; readonly replayed: boolean };
readonly trace: {
readonly traceId: string;
readonly correlationId?: string;
readonly causationInvocationId?: string;
};
}
EventRetryPolicy (type alias)
Bounded retry policy shared with job handlers.
Example
const retry: EventRetryPolicy = {
maxAttempts: 1,
initialDelayMs: 0,
maxDelayMs: 0,
multiplier: 1,
jitter: "none",
};
Signature
type EventRetryPolicy = RetryPolicy;
event-observability.ts
EventTelemetry (class)
Substitutable telemetry for package operations.
Example
Effect.provide(observeEvent("event.define", Effect.void), EventTelemetryLive);
Signature
declare class EventTelemetry
EventTelemetryLive
Default span and metric observer.
Example
Effect.provide(observeEvent("event.define", Effect.void), EventTelemetryLive);
Signature
declare const EventTelemetryLive: Layer.Layer<EventTelemetry, never, never>;
observeEvent
Records a stable span, call count, failure count, and duration.
Example
observeEvent("event.define", Effect.succeed("created"));
Signature
declare const observeEvent: <A, E, R>(
operation: EventOperation,
effect: Effect.Effect<A, E, R>,
) => Effect.Effect<A, E, R>;
runEventSync
Runs a dependency-free compatibility effect and rethrows its typed failure.
Throws
The typed failure or an unexpected defect.
Example
runEventSync(Effect.succeed(1));
Signature
declare const runEventSync: <A, E>(effect: Effect.Effect<A, E>) => A;
event-observability.types.ts
EventOperation (type alias)
Fixed operation labels used by event authoring and publishing metrics.
Example
const operation: EventOperation = "client.publish";
Signature
type EventOperation =
| "event.define"
| "event.isDescriptor"
| "event.assertDescriptor"
| "function.define"
| "function.isDescriptor"
| "function.bindEvents"
| "function.delivery"
| "function.profile"
| "function.retry"
| "function.rejectFields"
| "client.create"
| "client.publish"
| "client.parsePayload"
| "client.normalizeOptions"
| "client.normalizeAttributes"
| "client.normalizeResult"
| "client.resolveProvider"
| "client.notify"
| "client.resolveValue"
| "client.assertOptionalText"
| "client.assertVersion"
| "client.runAbortable";
EventTelemetryService (interface)
Substitutable observer for event operations. Implementations retain the original success and error channels.
Example
const telemetry: EventTelemetryService = { observe: (_name, effect) => effect };
Signature
export interface EventTelemetryService {
/** Observes one event operation.
* @param operation - Fixed bounded operation label.
* @param effect - Operation to observe.
* @returns The same success and error channels.
* @example telemetry.observe("event.define", Effect.void)
*/
readonly observe: <A, E, R>(
operation: EventOperation,
effect: Effect.Effect<A, E, R>,
) => Effect.Effect<A, E, R>;
}
event-registry.ts
EventDescriptorByName (type alias)
Resolves a registered event descriptor from its name.
Example
type Created = EventDescriptorByName<"orders.created">;
Signature
type EventDescriptorByName<Name extends EventName> = EventRegistry[Name] extends EventDescriptorAny
? EventRegistry[Name]
: never;
EventInputByName (type alias)
Decoded payload for a registered event name.
Example
type Payload = EventInputByName<"orders.created">;
Signature
type EventInputByName<Name extends EventName> = InferOutput<EventDescriptorByName<Name>["input"]>;
EventName (type alias)
Event IDs known to the generated application registry.
Example
type Id = EventName;
Signature
type EventName = Extract<keyof EventRegistry, string>;
EventRegistry (type alias)
Application registry augmented by generated event declarations.
Example
type Events = EventRegistry;
Signature
type EventRegistry = Relkit.EventRegistry;
EventVersionByName (type alias)
Version of a registered event contract.
Example
type Version = EventVersionByName<"orders.created">;
Signature
type EventVersionByName<Name extends EventName> = EventDescriptorByName<Name>["version"];
index.ts
“./event-function.types.js” (namespace export)
Re-exports all named exports from the “./event-function.types.js” module.
Signature
export * from "./event-function.types.js";
“./event-registry.js” (namespace export)
Re-exports all named exports from the “./event-registry.js” module.
Signature
export * from "./event-registry.js";
DefineEventOptions
Signature
declare const DefineEventOptions: DefineEventOptions<Id, Version, InputSchema>;
EventAttributeValue
Signature
declare const EventAttributeValue: EventAttributeValue;
EventClient
Signature
declare const EventClient: EventClient<Input, Id, Version, Payload>;
EventClientOptions
Signature
declare const EventClientOptions: EventClientOptions<Id, Version, PayloadSchema>;
EventDeclaredEdge
Signature
declare const EventDeclaredEdge: EventDeclaredEdge;
EventDependencyError
Signature
declare const EventDependencyError: typeof EventDependencyError;
EventDescriptor
Signature
declare const EventDescriptor: EventDescriptor<Id, Version, Input, InputSchema>;
EventDescriptorAny
Signature
declare const EventDescriptorAny: EventDescriptorAny;
EventEnvelope
Signature
declare const EventEnvelope: EventEnvelope<Id, Version, Payload>;
EventEnvelopeFor
Signature
declare const EventEnvelopeFor: EventEnvelopeFor<E>;
EventInvocationBridge
Signature
declare const EventInvocationBridge: EventInvocationBridge;
EventInvocationBridgeOptions
Signature
declare const EventInvocationBridgeOptions: EventInvocationBridgeOptions;
EventObservedEdge
Signature
declare const EventObservedEdge: EventObservedEdge;
EventOperationCancelledError
Signature
declare const EventOperationCancelledError: typeof EventOperationCancelledError;
EventOperationContext
Signature
declare const EventOperationContext: EventOperationContext;
EventOperationTimeoutError
Signature
declare const EventOperationTimeoutError: typeof EventOperationTimeoutError;
EventPayloadValidationError
Signature
declare const EventPayloadValidationError: typeof EventPayloadValidationError;
EventProfileError
Signature
declare const EventProfileError: typeof EventProfileError;
EventProvider
Signature
declare const EventProvider: EventProvider;
EventProviderError
Signature
declare const EventProviderError: typeof EventProviderError;
EventProviderResult
Signature
declare const EventProviderResult: EventProviderResult<Id, Version, Payload>;
EventPublishOptions
Signature
declare const EventPublishOptions: EventPublishOptions;
EventPublishResult
Signature
declare const EventPublishResult: EventPublishResult<Id, Version, Payload>;
UnknownEventEnvelope
Signature
declare const UnknownEventEnvelope: UnknownEventEnvelope;
assertEventDescriptor
Signature
declare const assertEventDescriptor: (value: unknown) => asserts value is EventDescriptorAny;
bindFunctionEvents
Signature
declare const bindFunctionEvents: <T extends FunctionWithEvents>(
descriptor: T,
consumed: EventDescriptorAny | undefined,
published: readonly EventDescriptorAny[],
) => T;
createEventClient
Signature
declare const createEventClient: <
const Id extends string,
const Version extends number,
const PayloadSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: EventClientOptions<Id, Version, PayloadSchema>,
) => EventClient<InferInput<PayloadSchema>, Id, Version, InferOutput<PayloadSchema>>;
defineEvent
Signature
declare const defineEvent: <
const Id extends string,
const Version extends number = 1,
const InputSchema extends StandardSchemaV1 = StandardSchemaV1<unknown, unknown>,
>(
options: DefineEventOptions<Id, Version, InputSchema>,
) => EventDescriptor<Id, Version, InferOutput<InputSchema>, InputSchema>;
defineEventFunction
Signature
declare const defineEventFunction: <
const Id extends string,
const Event extends EventName,
const Publishes extends readonly EventName[] = readonly [],
const Dependencies extends FunctionDependencies = {},
const Options extends EventFunctionCallOptions<Id, Event, Publishes, Dependencies> =
EventFunctionCallOptions<Id, Event, Publishes, Dependencies>,
>(
options: EventFunctionCallOptions<Id, Event, Publishes, Dependencies> &
Options &
EventFunctionValidation<NoInfer<Options>>,
) => EventFunctionDescriptor<Id, Event, Publishes, Dependencies, ErrorListOf<Options>>;
isEventDescriptor
Signature
declare const isEventDescriptor: (value: unknown) => value is EventDescriptorAny;
isEventFunctionDescriptor
Signature
declare const isEventFunctionDescriptor: (value: unknown) => value is EventFunctionDescriptorAny;