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

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,89 @@
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 ../almanac/dist/meter-CY9GTIM8.d.ts
9
+ //#region src/meters/meter.d.ts
10
+ type Counter = {
11
+ add(value: number, attributes?: Record<string, unknown>): void;
12
+ };
13
+ type Histogram = {
14
+ record(value: number, attributes?: Record<string, unknown>): void;
15
+ };
16
+ type Gauge = {
17
+ record(value: number, attributes?: Record<string, unknown>): void;
18
+ };
19
+ type Meter = {
20
+ counter(name: string): Counter;
21
+ histogram(name: string): Histogram;
22
+ gauge(name: string): Gauge;
23
+ };
24
+ //#endregion
25
+ //#region ../almanac/dist/tracer-DJWFmYul.d.ts
26
+ //#region src/tracers/span.d.ts
27
+ type SpanEventLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error';
28
+ type SpanContext = {
29
+ traceId: string;
30
+ spanId: string;
31
+ };
32
+ type SpanLink = SpanContext & {
33
+ attributes?: Record<string, unknown>;
34
+ };
35
+ type ActiveSpan = {
36
+ setAttributes(attrs: Record<string, unknown>): void;
37
+ spanContext(): SpanContext;
38
+ addLink(link: SpanLink): void;
39
+ addEvent(name: string, attributes?: Record<string, unknown>, level?: SpanEventLevel): void;
40
+ recordException(error: Error | string): void;
41
+ };
42
+ type StartSpanOptions = {
43
+ parent?: SpanContext;
44
+ attributes?: Record<string, unknown>;
45
+ links?: SpanLink[];
46
+ propagation?: TracePropagation;
47
+ sampleRate?: number;
48
+ };
49
+ //#endregion
50
+ //#region src/tracers/tracer.d.ts
51
+ type TracePropagation = 'links' | 'propagate';
52
+ type Tracer = {
53
+ startSpan<T>(name: string, fn: (span: ActiveSpan) => Promise<T>, options?: StartSpanOptions): Promise<T>;
54
+ };
55
+ //#endregion
56
+ //#region ../almanac/dist/index.d.ts
57
+ type AttributeTarget = 'mainSpan' | 'currentSpan' | 'both'; //#endregion
58
+ //#region src/meters/compositeMeter.d.ts
59
+ //#endregion
60
+ //#region src/configuration/options.d.ts
61
+ declare const defaultPrefix: "almanac";
62
+ type Sampler = {
63
+ shouldSample(name: string, attributes?: Record<string, unknown>): boolean;
64
+ };
65
+ type ObservabilityConfig<Prefix extends string = typeof defaultPrefix> = {
66
+ tracer?: Tracer;
67
+ meter?: Meter;
68
+ propagation?: TracePropagation;
69
+ attributeTarget?: AttributeTarget;
70
+ attributePrefix?: Prefix;
71
+ sampler?: Sampler;
72
+ };
73
+ //#endregion
74
+ //#region src/etag.d.ts
9
75
  declare const HeaderNames: {
10
- IF_MATCH: string;
11
- IF_NOT_MATCH: string;
12
- ETag: string;
76
+ IF_MATCH: string;
77
+ IF_NOT_MATCH: string;
78
+ ETag: string;
13
79
  };
14
80
  type WeakETag = Brand<`W/${string}`, 'ETag'>;
15
81
  type ETag = Brand<string, 'ETag'>;
16
82
  declare const WeakETagRegex: RegExp;
17
83
  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"
84
+ WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT",
85
+ MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER",
86
+ MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER"
21
87
  }
22
88
  declare const isWeakETag: (etag: ETag) => etag is WeakETag;
23
89
  declare const getWeakETagValue: (etag: ETag) => string;
@@ -26,60 +92,68 @@ declare const getETagFromIfMatch: (request: Request) => ETag;
26
92
  declare const getETagFromIfNotMatch: (request: Request) => ETag;
27
93
  declare const setETag: (response: Response, etag: ETag) => void;
28
94
  declare const getETagValueFromIfMatch: (request: Request) => string;
29
-
95
+ //#endregion
96
+ //#region src/responses.d.ts
30
97
  type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
31
98
  type HttpResponseOptions = {
32
- body?: unknown;
33
- location?: string;
34
- eTag?: ETag;
99
+ body?: unknown;
100
+ location?: string;
101
+ eTag?: ETag;
35
102
  };
36
103
  declare const DefaultHttpResponseOptions: HttpResponseOptions;
37
104
  type HttpProblemResponseOptions = {
38
- location?: string;
39
- eTag?: ETag;
105
+ location?: string;
106
+ eTag?: ETag;
40
107
  } & Omit<HttpResponseOptions, 'body'> & ({
41
- problem: ProblemDocument;
108
+ problem: ProblemDocument;
42
109
  } | {
43
- problemDetails: string;
110
+ problemDetails: string;
44
111
  });
45
112
  declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
46
113
  type CreatedHttpResponseOptions = ({
47
- createdId: string;
114
+ createdId: string;
48
115
  } | {
49
- createdId?: string;
50
- url: string;
116
+ createdId?: string;
117
+ url: string;
51
118
  }) & HttpResponseOptions;
52
- declare const sendCreated: (response: Response, { eTag, ...options }: CreatedHttpResponseOptions) => void;
119
+ declare const sendCreated: (response: Response, {
120
+ eTag,
121
+ ...options
122
+ }: CreatedHttpResponseOptions) => void;
53
123
  type AcceptedHttpResponseOptions = {
54
- location: string;
124
+ location: string;
55
125
  } & HttpResponseOptions;
56
126
  declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
57
127
  type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
128
+ declare const sendNoContent: (response: Response, options?: NoContentHttpResponseOptions) => void;
58
129
  declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
59
130
  declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
60
-
131
+ //#endregion
132
+ //#region src/application.d.ts
61
133
  type WebApiSetup = (router: Router) => void;
62
134
  type ApplicationOptions = {
63
- apis: WebApiSetup[];
64
- mapError?: ErrorToProblemDetailsMapping;
65
- enableDefaultExpressEtag?: boolean;
66
- disableJsonMiddleware?: boolean;
67
- disableUrlEncodingMiddleware?: boolean;
68
- disableProblemDetailsMiddleware?: boolean;
135
+ apis: WebApiSetup[];
136
+ mapError?: ErrorToProblemDetailsMapping;
137
+ enableDefaultExpressEtag?: boolean;
138
+ disableJsonMiddleware?: boolean;
139
+ disableUrlEncodingMiddleware?: boolean;
140
+ disableProblemDetailsMiddleware?: boolean;
141
+ observability?: ObservabilityConfig<string>;
69
142
  };
70
143
  declare const getApplication: (options: ApplicationOptions) => express.Application;
71
144
  type StartApiOptions = {
72
- port?: number;
145
+ port?: number;
73
146
  };
74
147
  declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
75
-
148
+ //#endregion
149
+ //#region src/handler.d.ts
150
+ type HttpResponse = (response: Response) => void;
76
151
  type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
77
152
  declare const on: <RequestType extends Request>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
78
153
  declare const OK: (options?: HttpResponseOptions) => HttpResponse;
79
154
  declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
80
155
  declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
81
156
  declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
82
- type HttpResponse = (response: Response) => void;
83
157
  declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
84
158
  declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
85
159
  declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
@@ -87,7 +161,8 @@ declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
87
161
  declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
88
162
  declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
89
163
  declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
90
-
164
+ //#endregion
165
+ //#region src/testing/apiSpecification.d.ts
91
166
  type TestRequest = (request: TestAgent<supertest.Test>) => Test;
92
167
  declare const existingStream: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
93
168
  type ResponseAssert = (response: Response$1) => boolean | void;
@@ -95,30 +170,44 @@ type ApiSpecificationAssert<EventType extends Event = Event> = TestEventStream<E
95
170
  declare const expect: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
96
171
  declare const expectNewEvents: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
97
172
  declare const expectResponse: <Body = unknown>(statusCode: number, options?: {
98
- body?: Body;
99
- headers?: {
100
- [index: string]: string;
101
- };
173
+ body?: Body;
174
+ headers?: {
175
+ [index: string]: string;
176
+ };
102
177
  }) => (response: Response$1) => void;
103
178
  declare const expectError: (errorCode: number, problemDetails?: Partial<ProblemDocument>) => (response: Response$1) => void;
104
179
  type ApiSpecification<EventType extends Event = Event> = (...givenStreams: TestEventStream<EventType>[]) => {
105
- when: (setupRequest: TestRequest) => {
106
- then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
107
- };
180
+ when: (setupRequest: TestRequest) => {
181
+ then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
182
+ };
108
183
  };
184
+ declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(options: {
185
+ getEventStore: () => Store;
186
+ getApplication: (eventStore: Store) => Application;
187
+ }): ApiSpecification<EventType>;
188
+ /** @deprecated Use `ApiSpecification.for({ getEventStore, getApplication })` instead */
189
+ declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiSpecification<EventType>;
109
190
  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>;
191
+ for: typeof apiSpecificationFor;
111
192
  };
112
-
193
+ //#endregion
194
+ //#region src/testing/apiE2ESpecification.d.ts
113
195
  type E2EResponseAssert = (response: Response$1) => boolean | void;
114
196
  type ApiE2ESpecificationAssert = [E2EResponseAssert];
115
197
  type ApiE2ESpecification = (...givenRequests: TestRequest[]) => {
116
- when: (setupRequest: TestRequest) => {
117
- then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
118
- };
198
+ when: (setupRequest: TestRequest) => {
199
+ then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
200
+ };
119
201
  };
202
+ declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(options: {
203
+ getEventStore?: () => Store;
204
+ getApplication: (eventStore: Store) => Application;
205
+ }): ApiE2ESpecification;
206
+ /** @deprecated Use `ApiE2ESpecification.for({ getEventStore, getApplication })` instead */
207
+ declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiE2ESpecification;
120
208
  declare const ApiE2ESpecification: {
121
- for: <Store extends EventStore = EventStore<_event_driven_io_emmett.AnyRecordedMessageMetadata>>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application) => ApiE2ESpecification;
209
+ for: typeof apiE2ESpecificationFor;
122
210
  };
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 };
211
+ //#endregion
212
+ 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 };
213
+ //# sourceMappingURL=index.d.ts.map