import type { DeadLetterPublisher } from "./dead-letter.js"; import type { IdempotencyStore } from "./idempotency.js"; import type { Telemetry } from "./telemetry.js"; import type { AvroCodec } from "./schema/avro-codec.js"; import type { CloudEventContext, IncomingMessage } from "./types.js"; /** What the transport should do with a message once the pipeline has run. */ export type Outcome = "ack" | "nack" | "dead-letter"; /** Policy for a message the pipeline refuses to process. */ export type RejectionPolicy = "dead-letter" | "nack" | "ack"; export type EventHandler = (data: unknown, ctx: CloudEventContext) => unknown; /** A handler plus the registered pattern that selected it. */ export interface ResolvedRoute { readonly handler: EventHandler; /** * The pattern this consumer registered, not the `ce-type` that matched it. Bounded by * registration, which is why telemetry labels on it: `ce-type` is producer-controlled, and a * wildcard route matches an open-ended set of them. */ readonly pattern: string; } export interface ValidationOptions { /** Default 'dead-letter'. */ onInvalidEnvelope?: RejectionPolicy; /** * A body this consumer cannot read: not valid JSON, not decodable against its schema, or a * reader type it does not have. Default 'dead-letter' — the bytes will not become readable on * redelivery, so retrying only burns the budget. */ onDecodeFailure?: RejectionPolicy; /** * The writer schema could not be *fetched* — a Schema Service outage, a revision that has not * propagated, a client without schema support. Default 'nack'. * * Deliberately separate from `onDecodeFailure`, and deliberately not defaulted to it: nothing is * known to be wrong with the message, so the next delivery will very likely decode it. Dead- * lettering here turns a blip into a manual redrive of every in-flight message, which * is the same reasoning that makes an unreadable idempotency store nack rather than reprocess. * * Only reachable with `schemaRegistry.strict` left on: with it off the codec has already fallen * back to plain JSON for exactly this failure and decode never fails. */ onSchemaUnavailable?: RejectionPolicy; /** Default false. */ requireDataschema?: boolean; } export interface MessagePipelineOptions { readonly subscription: string; /** * Resolves the route for a `ce-type`, or null when this consumer has none. The transport supplies * a `PatternRouter`, which prefers an exact pattern over a wildcard one. */ readonly resolveRoute: (type: string) => ResolvedRoute | null; readonly deadLetterPublisher?: DeadLetterPublisher; /** Avro schema resolution and decode. Without it, bodies are parsed as plain JSON. */ readonly codec?: Pick; /** Duplicate suppression. Defaults to a no-op store that warns loudly at startup. */ readonly idempotencyStore?: IdempotencyStore; /** Identifies this consumer in the idempotency key. Required for a shared store to be correct. */ readonly consumer?: string; /** How long a processed marker is retained. Default 7 days. */ readonly idempotencyTtlMs?: number; readonly validation?: ValidationOptions; /** Default 'ack' — a subscription legitimately carries types this consumer ignores. */ readonly onUnhandledPattern?: RejectionPolicy; readonly now?: () => Date; readonly telemetry?: Telemetry; readonly logger?: Pick & Partial>; } export declare class MessagePipeline { private readonly options; /** * Keys currently being handled in this process. Pub/Sub can deliver the same message twice * concurrently, and has()-then-tryRecord() leaves a window where both deliveries pass the check. * This collapses that window in-process; across replicas the store is still the only guard, which * is why handlers must remain idempotent regardless. */ private readonly inProcess; constructor(options: MessagePipelineOptions); handle(message: IncomingMessage): Promise; private keyFor; private run; private dispatch; /** Avro when a codec is configured and the topic carries a schema, plain JSON otherwise. */ private decode; /** * Recorded only after the handler succeeded and before the ack. Recording earlier risks silently * dropping a message that then failed; recording after the ack risks a crash in between. Neither * is eliminable — this is at-least-once — which is why handlers must still be idempotent. */ private record; private reject; } //# sourceMappingURL=pipeline.d.ts.map