import type { Transform } from 'node:stream'; import type { MessageCodecHandler, MessageCodecRegistration } from './messageCodec.ts'; /** * Default upper bound on the decompressed size of a single message, in bytes (100 MiB). * * Protects consumers from decompression-bomb inputs: a tiny compressed envelope can * otherwise expand to gigabytes of highly-repetitive data and exhaust process memory. * 100 MiB is far above any realistic queue message (SQS/SNS cap bodies at 256 KiB, and * even offloaded payloads are typically single-digit MiB) while still bounding the blast * radius of a malicious or corrupt frame. Override via the {@link ZstdCodecHandler} * constructor if you legitimately handle larger messages. */ export declare const DEFAULT_MAX_DECOMPRESSED_BYTES: number; export declare class ZstdCodecHandler implements MessageCodecHandler { private readonly maxDecompressedBytes; /** * @param maxDecompressedBytes upper bound on a single decompressed message, in bytes. * Defaults to {@link DEFAULT_MAX_DECOMPRESSED_BYTES} (100 MiB). Decompression of an * input that would exceed this limit is rejected before the full payload is buffered. */ constructor(maxDecompressedBytes?: number); compress(data: Buffer): Promise; decompress(data: Buffer): Promise; createCompressStream(): Transform; } /** * Returns the name string that will be written into the `__mqtCodec` field of every envelope. * Throws for custom (object-form) registrations whose name contains characters that would * produce invalid JSON when interpolated raw into the envelope string. */ export declare function getCodecName(codec: MessageCodecRegistration): string; /** * Resolves the {@link MessageCodecHandler} for the given codec registration. * * - String form (`MessageCodec`): returns the built-in handler for that codec. * - Object form (`{ name, handler }`): returns the provided handler directly. */ export declare function resolveCodecHandler(codec: MessageCodecRegistration): MessageCodecHandler; /** * Wraps an already-compressed buffer in a codec envelope string. * Use this when you have pre-compressed bytes and want to avoid compressing twice. * * `preservedFields`, when provided, are emitted as plaintext siblings of the codec * fields (`{ ...preserved, __mqtCodec, __mqtData }`). Publishers use this to keep * identity/routing fields (`id`, `type`, …) visible on the wire so broker-side * filtering (e.g. SNS body-scoped FilterPolicy) still works on compressed messages — * the same fields an offloaded-payload pointer carries. The codec fields are written * last, so a colliding preserved key can never corrupt the envelope; consumers ignore * the preserved siblings and decode `__mqtData` only. * * Without `preservedFields` the fast path uses string concatenation instead of * JSON.stringify, avoiding an intermediate object — the base64 string and the * envelope string are the only two allocations on the inline path. * * `codecName` must already be a JSON-safe identifier (see {@link getCodecName}, * which is enforced for every registration before it reaches this function). */ export declare function buildCodecEnvelope(compressed: Buffer, codecName: string, preservedFields?: Record): string;