@event-driven-io/emmett-expressjs 0.43.0-beta.2 → 0.43.0-beta.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,23 +1,23 @@
1
- import express, { Request, Response, Router, Application, NextFunction } from 'express';
2
- import http from 'http';
3
- import { ProblemDocument } from 'http-problem-details';
4
- import * as _event_driven_io_emmett from '@event-driven-io/emmett';
5
- import { Brand, Event, TestEventStream, EventStore } from '@event-driven-io/emmett';
6
- import supertest, { Test, Response as Response$1 } from 'supertest';
7
- import TestAgent from 'supertest/lib/agent';
1
+ import express, { Application, NextFunction, Request, Response, Router } from "express";
2
+ import http from "http";
3
+ import { Brand, Event, EventStore, InMemoryEventStore, TestEventStream } from "@event-driven-io/emmett";
4
+ import { ProblemDocument } from "http-problem-details";
5
+ import supertest, { Response as Response$1, Test } from "supertest";
6
+ import TestAgent from "supertest/lib/agent.js";
8
7
 
8
+ //#region src/etag.d.ts
9
9
  declare const HeaderNames: {
10
- IF_MATCH: string;
11
- IF_NOT_MATCH: string;
12
- ETag: string;
10
+ IF_MATCH: string;
11
+ IF_NOT_MATCH: string;
12
+ ETag: string;
13
13
  };
14
14
  type WeakETag = Brand<`W/${string}`, 'ETag'>;
15
15
  type ETag = Brand<string, 'ETag'>;
16
16
  declare const WeakETagRegex: RegExp;
17
17
  declare const enum ETagErrors {
18
- WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT",
19
- MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER",
20
- MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER"
18
+ WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT",
19
+ MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER",
20
+ MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER"
21
21
  }
22
22
  declare const isWeakETag: (etag: ETag) => etag is WeakETag;
23
23
  declare const getWeakETagValue: (etag: ETag) => string;
@@ -26,60 +26,67 @@ declare const getETagFromIfMatch: (request: Request) => ETag;
26
26
  declare const getETagFromIfNotMatch: (request: Request) => ETag;
27
27
  declare const setETag: (response: Response, etag: ETag) => void;
28
28
  declare const getETagValueFromIfMatch: (request: Request) => string;
29
-
29
+ //#endregion
30
+ //#region src/responses.d.ts
30
31
  type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
31
32
  type HttpResponseOptions = {
32
- body?: unknown;
33
- location?: string;
34
- eTag?: ETag;
33
+ body?: unknown;
34
+ location?: string;
35
+ eTag?: ETag;
35
36
  };
36
37
  declare const DefaultHttpResponseOptions: HttpResponseOptions;
37
38
  type HttpProblemResponseOptions = {
38
- location?: string;
39
- eTag?: ETag;
39
+ location?: string;
40
+ eTag?: ETag;
40
41
  } & Omit<HttpResponseOptions, 'body'> & ({
41
- problem: ProblemDocument;
42
+ problem: ProblemDocument;
42
43
  } | {
43
- problemDetails: string;
44
+ problemDetails: string;
44
45
  });
45
46
  declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
46
47
  type CreatedHttpResponseOptions = ({
47
- createdId: string;
48
+ createdId: string;
48
49
  } | {
49
- createdId?: string;
50
- url: string;
50
+ createdId?: string;
51
+ url: string;
51
52
  }) & HttpResponseOptions;
52
- declare const sendCreated: (response: Response, { eTag, ...options }: CreatedHttpResponseOptions) => void;
53
+ declare const sendCreated: (response: Response, {
54
+ eTag,
55
+ ...options
56
+ }: CreatedHttpResponseOptions) => void;
53
57
  type AcceptedHttpResponseOptions = {
54
- location: string;
58
+ location: string;
55
59
  } & HttpResponseOptions;
56
60
  declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
57
61
  type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
62
+ declare const sendNoContent: (response: Response, options?: NoContentHttpResponseOptions) => void;
58
63
  declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
59
64
  declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
60
-
65
+ //#endregion
66
+ //#region src/application.d.ts
61
67
  type WebApiSetup = (router: Router) => void;
62
68
  type ApplicationOptions = {
63
- apis: WebApiSetup[];
64
- mapError?: ErrorToProblemDetailsMapping;
65
- enableDefaultExpressEtag?: boolean;
66
- disableJsonMiddleware?: boolean;
67
- disableUrlEncodingMiddleware?: boolean;
68
- disableProblemDetailsMiddleware?: boolean;
69
+ apis: WebApiSetup[];
70
+ mapError?: ErrorToProblemDetailsMapping;
71
+ enableDefaultExpressEtag?: boolean;
72
+ disableJsonMiddleware?: boolean;
73
+ disableUrlEncodingMiddleware?: boolean;
74
+ disableProblemDetailsMiddleware?: boolean;
69
75
  };
70
76
  declare const getApplication: (options: ApplicationOptions) => express.Application;
71
77
  type StartApiOptions = {
72
- port?: number;
78
+ port?: number;
73
79
  };
74
80
  declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
75
-
81
+ //#endregion
82
+ //#region src/handler.d.ts
83
+ type HttpResponse = (response: Response) => void;
76
84
  type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
77
85
  declare const on: <RequestType extends Request>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
78
86
  declare const OK: (options?: HttpResponseOptions) => HttpResponse;
79
87
  declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
80
88
  declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
81
89
  declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
82
- type HttpResponse = (response: Response) => void;
83
90
  declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
84
91
  declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
85
92
  declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
@@ -87,7 +94,8 @@ declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
87
94
  declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
88
95
  declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
89
96
  declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
90
-
97
+ //#endregion
98
+ //#region src/testing/apiSpecification.d.ts
91
99
  type TestRequest = (request: TestAgent<supertest.Test>) => Test;
92
100
  declare const existingStream: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
93
101
  type ResponseAssert = (response: Response$1) => boolean | void;
@@ -95,30 +103,44 @@ type ApiSpecificationAssert<EventType extends Event = Event> = TestEventStream<E
95
103
  declare const expect: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
96
104
  declare const expectNewEvents: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
97
105
  declare const expectResponse: <Body = unknown>(statusCode: number, options?: {
98
- body?: Body;
99
- headers?: {
100
- [index: string]: string;
101
- };
106
+ body?: Body;
107
+ headers?: {
108
+ [index: string]: string;
109
+ };
102
110
  }) => (response: Response$1) => void;
103
111
  declare const expectError: (errorCode: number, problemDetails?: Partial<ProblemDocument>) => (response: Response$1) => void;
104
112
  type ApiSpecification<EventType extends Event = Event> = (...givenStreams: TestEventStream<EventType>[]) => {
105
- when: (setupRequest: TestRequest) => {
106
- then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
107
- };
113
+ when: (setupRequest: TestRequest) => {
114
+ then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
115
+ };
108
116
  };
117
+ declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(options: {
118
+ getEventStore: () => Store;
119
+ getApplication: (eventStore: Store) => Application;
120
+ }): ApiSpecification<EventType>;
121
+ /** @deprecated Use `ApiSpecification.for({ getEventStore, getApplication })` instead */
122
+ declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiSpecification<EventType>;
109
123
  declare const ApiSpecification: {
110
- for: <EventType extends Event = Event, Store extends EventStore = EventStore<_event_driven_io_emmett.AnyRecordedMessageMetadata>>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application) => ApiSpecification<EventType>;
124
+ for: typeof apiSpecificationFor;
111
125
  };
112
-
126
+ //#endregion
127
+ //#region src/testing/apiE2ESpecification.d.ts
113
128
  type E2EResponseAssert = (response: Response$1) => boolean | void;
114
129
  type ApiE2ESpecificationAssert = [E2EResponseAssert];
115
130
  type ApiE2ESpecification = (...givenRequests: TestRequest[]) => {
116
- when: (setupRequest: TestRequest) => {
117
- then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
118
- };
131
+ when: (setupRequest: TestRequest) => {
132
+ then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
133
+ };
119
134
  };
135
+ declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(options: {
136
+ getEventStore?: () => Store;
137
+ getApplication: (eventStore: Store) => Application;
138
+ }): ApiE2ESpecification;
139
+ /** @deprecated Use `ApiE2ESpecification.for({ getEventStore, getApplication })` instead */
140
+ declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiE2ESpecification;
120
141
  declare const ApiE2ESpecification: {
121
- for: <Store extends EventStore = EventStore<_event_driven_io_emmett.AnyRecordedMessageMetadata>>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application) => ApiE2ESpecification;
142
+ for: typeof apiE2ESpecificationFor;
122
143
  };
123
-
124
- 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 };
144
+ //#endregion
145
+ export { Accepted, AcceptedHttpResponseOptions, ApiE2ESpecification, ApiE2ESpecificationAssert, ApiSpecification, ApiSpecificationAssert, ApplicationOptions, BadRequest, Conflict, Created, CreatedHttpResponseOptions, DefaultHttpProblemResponseOptions, DefaultHttpResponseOptions, E2EResponseAssert, ETag, ETagErrors, ErrorToProblemDetailsMapping, Forbidden, HeaderNames, HttpHandler, HttpProblem, HttpProblemResponseOptions, HttpResponse, HttpResponseOptions, NoContent, NoContentHttpResponseOptions, NotFound, OK, PreconditionFailed, ResponseAssert, StartApiOptions, TestRequest, WeakETag, WeakETagRegex, WebApiSetup, existingStream, expect, expectError, expectNewEvents, expectResponse, getApplication, getETagFromIfMatch, getETagFromIfNotMatch, getETagValueFromIfMatch, getWeakETagValue, isWeakETag, on, send, sendAccepted, sendCreated, sendNoContent, sendProblem, setETag, startAPI, toWeakETag };
146
+ //# sourceMappingURL=index.d.ts.map