import express, { Request, Response, Router, Application, NextFunction } from 'express'; import http from 'http'; import { ProblemDocument } from 'http-problem-details'; import * as _event_driven_io_emmett from '@event-driven-io/emmett'; import { Brand, Event, TestEventStream, EventStore } from '@event-driven-io/emmett'; import supertest, { Test, Response as Response$1 } from 'supertest'; import TestAgent from 'supertest/lib/agent'; declare const HeaderNames: { IF_MATCH: string; IF_NOT_MATCH: string; ETag: string; }; type WeakETag = Brand<`W/${string}`, 'ETag'>; type ETag = Brand; declare const WeakETagRegex: RegExp; declare const enum ETagErrors { WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT", MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER", MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER" } declare const isWeakETag: (etag: ETag) => etag is WeakETag; declare const getWeakETagValue: (etag: ETag) => string; declare const toWeakETag: (value: number | bigint | string) => WeakETag; declare const getETagFromIfMatch: (request: Request) => ETag; declare const getETagFromIfNotMatch: (request: Request) => ETag; declare const setETag: (response: Response, etag: ETag) => void; declare const getETagValueFromIfMatch: (request: Request) => string; type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined; type HttpResponseOptions = { body?: unknown; location?: string; eTag?: ETag; }; declare const DefaultHttpResponseOptions: HttpResponseOptions; type HttpProblemResponseOptions = { location?: string; eTag?: ETag; } & Omit & ({ problem: ProblemDocument; } | { problemDetails: string; }); declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions; type CreatedHttpResponseOptions = ({ createdId: string; } | { createdId?: string; url: string; }) & HttpResponseOptions; declare const sendCreated: (response: Response, { eTag, ...options }: CreatedHttpResponseOptions) => void; type AcceptedHttpResponseOptions = { location: string; } & HttpResponseOptions; declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void; type NoContentHttpResponseOptions = Omit; declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void; declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void; type WebApiSetup = (router: Router) => void; type ApplicationOptions = { apis: WebApiSetup[]; mapError?: ErrorToProblemDetailsMapping; enableDefaultExpressEtag?: boolean; disableJsonMiddleware?: boolean; disableUrlEncodingMiddleware?: boolean; disableProblemDetailsMiddleware?: boolean; }; declare const getApplication: (options: ApplicationOptions) => express.Application; type StartApiOptions = { port?: number; }; declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server; type HttpHandler = (request: RequestType) => Promise | HttpResponse; declare const on: (handle: HttpHandler) => (request: RequestType, response: Response, _next: NextFunction) => Promise; declare const OK: (options?: HttpResponseOptions) => HttpResponse; declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse; declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse; declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse; type HttpResponse = (response: Response) => void; declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse; declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse; declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse; declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse; declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse; declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse; declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse; type TestRequest = (request: TestAgent) => Test; declare const existingStream: (streamId: string, events: EventType[]) => TestEventStream; type ResponseAssert = (response: Response$1) => boolean | void; type ApiSpecificationAssert = TestEventStream[] | ResponseAssert | [ResponseAssert, ...TestEventStream[]]; declare const expect: (streamId: string, events: EventType[]) => TestEventStream; declare const expectNewEvents: (streamId: string, events: EventType[]) => TestEventStream; declare const expectResponse: (statusCode: number, options?: { body?: Body; headers?: { [index: string]: string; }; }) => (response: Response$1) => void; declare const expectError: (errorCode: number, problemDetails?: Partial) => (response: Response$1) => void; type ApiSpecification = (...givenStreams: TestEventStream[]) => { when: (setupRequest: TestRequest) => { then: (verify: ApiSpecificationAssert) => Promise; }; }; declare const ApiSpecification: { for: >(getEventStore: () => Store, getApplication: (eventStore: Store) => Application) => ApiSpecification; }; type E2EResponseAssert = (response: Response$1) => boolean | void; type ApiE2ESpecificationAssert = [E2EResponseAssert]; type ApiE2ESpecification = (...givenRequests: TestRequest[]) => { when: (setupRequest: TestRequest) => { then: (verify: ApiE2ESpecificationAssert) => Promise; }; }; declare const ApiE2ESpecification: { for: >(getEventStore: () => Store, getApplication: (eventStore: Store) => Application) => ApiE2ESpecification; }; export { Accepted, type AcceptedHttpResponseOptions, ApiE2ESpecification, type ApiE2ESpecificationAssert, ApiSpecification, type ApiSpecificationAssert, type ApplicationOptions, BadRequest, Conflict, Created, type CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, type E2EResponseAssert, type ETag, ETagErrors, type ErrorToProblemDetailsMapping, Forbidden, HeaderNames, type HttpHandler, HttpProblem, type HttpProblemResponseOptions, HttpResponse, type HttpResponseOptions, NoContent, type NoContentHttpResponseOptions, NotFound, OK, PreconditionFailed, type ResponseAssert, type StartApiOptions, type TestRequest, type WeakETag, WeakETagRegex, type WebApiSetup, existingStream, expect, expectError, expectNewEvents, expectResponse, getApplication, getETagFromIfMatch, getETagFromIfNotMatch, getETagValueFromIfMatch, getWeakETagValue, isWeakETag, on, send, sendAccepted, sendCreated, sendProblem, setETag, startAPI, toWeakETag };