import { BinaryToTextEncoding, Hash } from 'node:crypto'; import { IncomingMessage } from 'node:http'; import { Transform } from 'node:stream'; import { LRUCache } from 'lru-cache'; /** * Transform that computes a rolling checksum for a stream while passing * data through unchanged. */ interface RangeChecksum extends Transform { /** Return the current digest in the selected encoding. */ digest: (encoding: BinaryToTextEncoding) => string; hash: Hash; path: string; reset: () => void; } /** * LRU-backed map of rolling hashers keyed by file path. Used to compute * hex/base64 digests and resume hashing from an offset. */ interface RangeHasher extends LRUCache { algorithm: "md5" | "sha1"; base64: (path: string) => string; digester: (path: string) => RangeChecksum; hex: (path: string) => string; init: (path: string, start: number) => Promise; updateFromFs: (path: string, start: number, initial?: Hash) => Promise; } /** * Normalized HTTP error payload returned by handlers and storage backends. */ interface HttpErrorBody { code: string; detail?: Record | string; message: string; name?: string; retryable?: boolean; UploadErrorCode?: string; } /** * Rich HTTP error including status code and optional headers/body. */ interface HttpError extends UploadResponse { statusCode: number; } /** * Node.js IncomingMessage with an optional parsed body attached. */ interface IncomingMessageWithBody extends IncomingMessage { _body?: boolean; body?: T; } type Header = string[] | number | string; type Headers = Record; type ResponseBody = Record | string | Buffer | Uint8Array; type ResponseBodyType = "json" | "text"; /** * Tuple form for quick response definitions: [status, body, headers]. */ type ResponseTuple = [statusCode: number, body?: T, headers?: Headers]; /** * Structured response used across handlers and storage operations. */ interface UploadResponse extends Record { body?: T; headers?: Headers; statusCode?: number; } /** * Declarative validator configuration for a single rule. */ interface ValidatorConfig { isValid?: (t: T) => Promise | boolean; response?: HttpError | ResponseTuple; value?: unknown; } /** Map of rule-name -> validator configuration. */ type Validation = Record>; /** Narrowed error response shape for validation failures. */ interface ValidationError extends HttpError { code: string; } /** * Metrics interface for observability. * Provides counters, timers, and gauges for tracking storage operations. */ interface Metrics { /** * Set a gauge metric value. * @param name Metric name (e.g., "storage.files.size") * @param value Gauge value * @param attributes Optional attributes/labels */ gauge: (name: string, value: number, attributes?: Record) => void; /** * Increment a counter metric. * @param name Metric name (e.g., "storage.operations.create.count") * @param value Increment value (default: 1) * @param attributes Optional attributes/labels (e.g., { storage: "s3", operation: "create" }) */ increment: (name: string, value?: number, attributes?: Record) => void; /** * Record a duration/timing metric in milliseconds. * @param name Metric name (e.g., "storage.operations.write.duration") * @param duration Duration in milliseconds * @param attributes Optional attributes/labels */ timing: (name: string, duration: number, attributes?: Record) => void; } export { Header as H, IncomingMessageWithBody as I, Metrics as M, ResponseBodyType as R, UploadResponse as U, Validation as V, Headers as a, HttpError as b, HttpErrorBody as c, RangeChecksum as d, RangeHasher as e, ResponseBody as f, ResponseTuple as g, ValidationError as h, ValidatorConfig as i };