@event-driven-io/emmett-expressjs 0.43.0-beta.3 → 0.43.0-beta.30
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/README.md +390 -0
- package/dist/index.cjs +323 -461
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +199 -52
- package/dist/index.d.ts +199 -52
- package/dist/index.js +235 -442
- package/dist/index.js.map +1 -1
- package/package.json +11 -12
package/dist/index.d.cts
CHANGED
|
@@ -1,23 +1,147 @@
|
|
|
1
|
-
import express, {
|
|
2
|
-
import http from
|
|
3
|
-
import { ProblemDocument } from
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import TestAgent from 'supertest/lib/agent';
|
|
1
|
+
import express, { Application, NextFunction, Request, Response, Router } from "express";
|
|
2
|
+
import http from "http";
|
|
3
|
+
import { ProblemDocument } from "http-problem-details";
|
|
4
|
+
import { Brand, Event, EventStore, InMemoryEventStore, TestEventStream } from "@event-driven-io/emmett";
|
|
5
|
+
import supertest, { Response as Response$1, Test } from "supertest";
|
|
6
|
+
import TestAgent from "supertest/lib/agent.js";
|
|
8
7
|
|
|
8
|
+
//#region ../almanac/dist/tracer-DAmwP0uv.d.ts
|
|
9
|
+
//#region src/loggers/logger.d.ts
|
|
10
|
+
type LogLevel = 'silent' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
11
|
+
declare const LogLevel: {
|
|
12
|
+
default: LogLevel;
|
|
13
|
+
silent: LogLevel;
|
|
14
|
+
trace: LogLevel;
|
|
15
|
+
debug: LogLevel;
|
|
16
|
+
info: LogLevel;
|
|
17
|
+
warn: LogLevel;
|
|
18
|
+
error: LogLevel;
|
|
19
|
+
fatal: LogLevel;
|
|
20
|
+
};
|
|
21
|
+
type LogAttributes = Record<string, unknown>;
|
|
22
|
+
type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>> }[keyof T];
|
|
23
|
+
type LogEventData<Attributes extends LogAttributes = LogAttributes> = RequireAtLeastOne<{
|
|
24
|
+
error?: Error;
|
|
25
|
+
body?: string;
|
|
26
|
+
attributes?: Attributes;
|
|
27
|
+
}>;
|
|
28
|
+
type LogEventMetadata = {
|
|
29
|
+
level: LogLevel;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
traceId?: string;
|
|
32
|
+
spanId?: string;
|
|
33
|
+
};
|
|
34
|
+
type LogEventMetadataInput = {
|
|
35
|
+
level: LogLevel;
|
|
36
|
+
timestamp?: number;
|
|
37
|
+
traceId?: string;
|
|
38
|
+
spanId?: string;
|
|
39
|
+
};
|
|
40
|
+
type LogEventMetadataOverrides = Omit<LogEventMetadataInput, 'level'>;
|
|
41
|
+
type LogEvent<EventName extends string = string, Attributes extends LogAttributes = LogAttributes> = Readonly<{
|
|
42
|
+
name: EventName;
|
|
43
|
+
data: LogEventData<Attributes>;
|
|
44
|
+
metadata: LogEventMetadata;
|
|
45
|
+
}>;
|
|
46
|
+
declare const LogEvent: (<Attributes extends LogAttributes = LogAttributes, EventName extends string = string>(eventName: EventName, data: LogEventData<Attributes>, eventMetadata: LogEventMetadataInput) => LogEvent<EventName, Attributes>) & {
|
|
47
|
+
message: <Attributes extends LogAttributes = LogAttributes, EventName extends string = string>(level: LogLevel, body: EventName, data?: Omit<LogEventData<Attributes>, "body">, eventMetadata?: LogEventMetadataOverrides) => LogEvent<EventName, Attributes>;
|
|
48
|
+
fatal: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
49
|
+
error: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
50
|
+
warn: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
51
|
+
info: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
52
|
+
debug: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
53
|
+
trace: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
54
|
+
silent: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
55
|
+
};
|
|
56
|
+
type Logger = (event: LogEvent) => void;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/tracers/span.d.ts
|
|
59
|
+
type SpanContext = {
|
|
60
|
+
traceId: string;
|
|
61
|
+
spanId: string;
|
|
62
|
+
};
|
|
63
|
+
type SpanLink = SpanContext & {
|
|
64
|
+
attributes?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
type ActiveSpan = {
|
|
67
|
+
setAttributes(attrs: Record<string, unknown>): void;
|
|
68
|
+
spanContext(): SpanContext;
|
|
69
|
+
addLink(link: SpanLink): void;
|
|
70
|
+
log: Logger;
|
|
71
|
+
};
|
|
72
|
+
type StartSpanOptions = {
|
|
73
|
+
parent?: SpanContext;
|
|
74
|
+
attributes?: Record<string, unknown>;
|
|
75
|
+
links?: SpanLink[];
|
|
76
|
+
propagation?: TracePropagation;
|
|
77
|
+
sampleRate?: number;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/tracers/tracer.d.ts
|
|
81
|
+
type TracePropagation = 'links' | 'propagate';
|
|
82
|
+
type Tracer = {
|
|
83
|
+
startSpan<T>(name: string, fn: (span: ActiveSpan) => Promise<T>, options?: StartSpanOptions): Promise<T>;
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region ../almanac/dist/observabilityContextGenerator-XpzUVu7X.d.ts
|
|
87
|
+
type ObservabilityContextGenerator = {
|
|
88
|
+
generateTraceId(): string;
|
|
89
|
+
generateSpanId(): string;
|
|
90
|
+
generateMessageId(): string;
|
|
91
|
+
generateCorrelationId(): string;
|
|
92
|
+
generateCausationId(): string;
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../almanac/dist/index-Ct_mW2YQ.d.ts
|
|
96
|
+
type AttributeTarget = 'mainSpan' | 'currentSpan' | 'both'; //#endregion
|
|
97
|
+
//#region src/meters/meter.d.ts
|
|
98
|
+
type Counter = {
|
|
99
|
+
add(value: number, attributes?: Record<string, unknown>): void;
|
|
100
|
+
};
|
|
101
|
+
type Histogram = {
|
|
102
|
+
record(value: number, attributes?: Record<string, unknown>): void;
|
|
103
|
+
};
|
|
104
|
+
type Gauge = {
|
|
105
|
+
record(value: number, attributes?: Record<string, unknown>): void;
|
|
106
|
+
};
|
|
107
|
+
type Meter = {
|
|
108
|
+
counter(name: string): Counter;
|
|
109
|
+
histogram(name: string): Histogram;
|
|
110
|
+
gauge(name: string): Gauge;
|
|
111
|
+
};
|
|
112
|
+
type Sampler = {
|
|
113
|
+
shouldSample(name: string, attributes?: Record<string, unknown>): boolean;
|
|
114
|
+
};
|
|
115
|
+
type Observability<Prefix extends string = 'almanac'> = {
|
|
116
|
+
tracer: Tracer;
|
|
117
|
+
meter: Meter;
|
|
118
|
+
logger: Logger;
|
|
119
|
+
propagation?: TracePropagation;
|
|
120
|
+
contextGenerator?: ObservabilityContextGenerator;
|
|
121
|
+
attributeTarget?: AttributeTarget;
|
|
122
|
+
attributePrefix?: Prefix;
|
|
123
|
+
sampler?: Sampler;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/configuration/defaultObservability.d.ts
|
|
127
|
+
type DefaultObservability = Partial<Observability<string>>;
|
|
128
|
+
declare global {
|
|
129
|
+
var eventDrivenIoAlmanacDefaultObservability: DefaultObservability | undefined;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/etag.d.ts
|
|
9
133
|
declare const HeaderNames: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
134
|
+
IF_MATCH: string;
|
|
135
|
+
IF_NOT_MATCH: string;
|
|
136
|
+
ETag: string;
|
|
13
137
|
};
|
|
14
138
|
type WeakETag = Brand<`W/${string}`, 'ETag'>;
|
|
15
139
|
type ETag = Brand<string, 'ETag'>;
|
|
16
140
|
declare const WeakETagRegex: RegExp;
|
|
17
141
|
declare const enum ETagErrors {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
142
|
+
WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT",
|
|
143
|
+
MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER",
|
|
144
|
+
MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER"
|
|
21
145
|
}
|
|
22
146
|
declare const isWeakETag: (etag: ETag) => etag is WeakETag;
|
|
23
147
|
declare const getWeakETagValue: (etag: ETag) => string;
|
|
@@ -26,60 +150,68 @@ declare const getETagFromIfMatch: (request: Request) => ETag;
|
|
|
26
150
|
declare const getETagFromIfNotMatch: (request: Request) => ETag;
|
|
27
151
|
declare const setETag: (response: Response, etag: ETag) => void;
|
|
28
152
|
declare const getETagValueFromIfMatch: (request: Request) => string;
|
|
29
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/responses.d.ts
|
|
30
155
|
type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
|
|
31
156
|
type HttpResponseOptions = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
157
|
+
body?: unknown;
|
|
158
|
+
location?: string;
|
|
159
|
+
eTag?: ETag;
|
|
35
160
|
};
|
|
36
161
|
declare const DefaultHttpResponseOptions: HttpResponseOptions;
|
|
37
162
|
type HttpProblemResponseOptions = {
|
|
38
|
-
|
|
39
|
-
|
|
163
|
+
location?: string;
|
|
164
|
+
eTag?: ETag;
|
|
40
165
|
} & Omit<HttpResponseOptions, 'body'> & ({
|
|
41
|
-
|
|
166
|
+
problem: ProblemDocument;
|
|
42
167
|
} | {
|
|
43
|
-
|
|
168
|
+
problemDetails: string;
|
|
44
169
|
});
|
|
45
170
|
declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
|
|
46
171
|
type CreatedHttpResponseOptions = ({
|
|
47
|
-
|
|
172
|
+
createdId: string;
|
|
48
173
|
} | {
|
|
49
|
-
|
|
50
|
-
|
|
174
|
+
createdId?: string;
|
|
175
|
+
url: string;
|
|
51
176
|
}) & HttpResponseOptions;
|
|
52
|
-
declare const sendCreated: (response: Response, {
|
|
177
|
+
declare const sendCreated: (response: Response, {
|
|
178
|
+
eTag,
|
|
179
|
+
...options
|
|
180
|
+
}: CreatedHttpResponseOptions) => void;
|
|
53
181
|
type AcceptedHttpResponseOptions = {
|
|
54
|
-
|
|
182
|
+
location: string;
|
|
55
183
|
} & HttpResponseOptions;
|
|
56
184
|
declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
|
|
57
185
|
type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
|
|
186
|
+
declare const sendNoContent: (response: Response, options?: NoContentHttpResponseOptions) => void;
|
|
58
187
|
declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
|
|
59
188
|
declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
|
|
60
|
-
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/application.d.ts
|
|
61
191
|
type WebApiSetup = (router: Router) => void;
|
|
62
192
|
type ApplicationOptions = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
193
|
+
apis: WebApiSetup[];
|
|
194
|
+
mapError?: ErrorToProblemDetailsMapping;
|
|
195
|
+
enableDefaultExpressEtag?: boolean;
|
|
196
|
+
disableJsonMiddleware?: boolean;
|
|
197
|
+
disableUrlEncodingMiddleware?: boolean;
|
|
198
|
+
disableProblemDetailsMiddleware?: boolean;
|
|
199
|
+
observability?: Partial<Observability<string>>;
|
|
69
200
|
};
|
|
70
201
|
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
71
202
|
type StartApiOptions = {
|
|
72
|
-
|
|
203
|
+
port?: number;
|
|
73
204
|
};
|
|
74
205
|
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
75
|
-
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/handler.d.ts
|
|
208
|
+
type HttpResponse = (response: Response) => void;
|
|
76
209
|
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
77
210
|
declare const on: <RequestType extends Request>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
78
211
|
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
79
212
|
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
80
213
|
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
81
214
|
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
82
|
-
type HttpResponse = (response: Response) => void;
|
|
83
215
|
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
84
216
|
declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
85
217
|
declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
@@ -87,7 +219,8 @@ declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
|
87
219
|
declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
88
220
|
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
89
221
|
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
90
|
-
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/testing/apiSpecification.d.ts
|
|
91
224
|
type TestRequest = (request: TestAgent<supertest.Test>) => Test;
|
|
92
225
|
declare const existingStream: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
93
226
|
type ResponseAssert = (response: Response$1) => boolean | void;
|
|
@@ -95,30 +228,44 @@ type ApiSpecificationAssert<EventType extends Event = Event> = TestEventStream<E
|
|
|
95
228
|
declare const expect: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
96
229
|
declare const expectNewEvents: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
97
230
|
declare const expectResponse: <Body = unknown>(statusCode: number, options?: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
231
|
+
body?: Body;
|
|
232
|
+
headers?: {
|
|
233
|
+
[index: string]: string;
|
|
234
|
+
};
|
|
102
235
|
}) => (response: Response$1) => void;
|
|
103
236
|
declare const expectError: (errorCode: number, problemDetails?: Partial<ProblemDocument>) => (response: Response$1) => void;
|
|
104
237
|
type ApiSpecification<EventType extends Event = Event> = (...givenStreams: TestEventStream<EventType>[]) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
238
|
+
when: (setupRequest: TestRequest) => {
|
|
239
|
+
then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
|
|
240
|
+
};
|
|
108
241
|
};
|
|
242
|
+
declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(options: {
|
|
243
|
+
getEventStore: () => Store;
|
|
244
|
+
getApplication: (eventStore: Store) => Application;
|
|
245
|
+
}): ApiSpecification<EventType>;
|
|
246
|
+
/** @deprecated Use `ApiSpecification.for({ getEventStore, getApplication })` instead */
|
|
247
|
+
declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiSpecification<EventType>;
|
|
109
248
|
declare const ApiSpecification: {
|
|
110
|
-
|
|
249
|
+
for: typeof apiSpecificationFor;
|
|
111
250
|
};
|
|
112
|
-
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/testing/apiE2ESpecification.d.ts
|
|
113
253
|
type E2EResponseAssert = (response: Response$1) => boolean | void;
|
|
114
254
|
type ApiE2ESpecificationAssert = [E2EResponseAssert];
|
|
115
255
|
type ApiE2ESpecification = (...givenRequests: TestRequest[]) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
256
|
+
when: (setupRequest: TestRequest) => {
|
|
257
|
+
then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
|
|
258
|
+
};
|
|
119
259
|
};
|
|
260
|
+
declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(options: {
|
|
261
|
+
getEventStore?: () => Store;
|
|
262
|
+
getApplication: (eventStore: Store) => Application;
|
|
263
|
+
}): ApiE2ESpecification;
|
|
264
|
+
/** @deprecated Use `ApiE2ESpecification.for({ getEventStore, getApplication })` instead */
|
|
265
|
+
declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiE2ESpecification;
|
|
120
266
|
declare const ApiE2ESpecification: {
|
|
121
|
-
|
|
267
|
+
for: typeof apiE2ESpecificationFor;
|
|
122
268
|
};
|
|
123
|
-
|
|
124
|
-
export { Accepted,
|
|
269
|
+
//#endregion
|
|
270
|
+
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 };
|
|
271
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,147 @@
|
|
|
1
|
-
import express, {
|
|
2
|
-
import http from
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
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/tracer-DAmwP0uv.d.ts
|
|
9
|
+
//#region src/loggers/logger.d.ts
|
|
10
|
+
type LogLevel = 'silent' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
11
|
+
declare const LogLevel: {
|
|
12
|
+
default: LogLevel;
|
|
13
|
+
silent: LogLevel;
|
|
14
|
+
trace: LogLevel;
|
|
15
|
+
debug: LogLevel;
|
|
16
|
+
info: LogLevel;
|
|
17
|
+
warn: LogLevel;
|
|
18
|
+
error: LogLevel;
|
|
19
|
+
fatal: LogLevel;
|
|
20
|
+
};
|
|
21
|
+
type LogAttributes = Record<string, unknown>;
|
|
22
|
+
type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>> }[keyof T];
|
|
23
|
+
type LogEventData<Attributes extends LogAttributes = LogAttributes> = RequireAtLeastOne<{
|
|
24
|
+
error?: Error;
|
|
25
|
+
body?: string;
|
|
26
|
+
attributes?: Attributes;
|
|
27
|
+
}>;
|
|
28
|
+
type LogEventMetadata = {
|
|
29
|
+
level: LogLevel;
|
|
30
|
+
timestamp: number;
|
|
31
|
+
traceId?: string;
|
|
32
|
+
spanId?: string;
|
|
33
|
+
};
|
|
34
|
+
type LogEventMetadataInput = {
|
|
35
|
+
level: LogLevel;
|
|
36
|
+
timestamp?: number;
|
|
37
|
+
traceId?: string;
|
|
38
|
+
spanId?: string;
|
|
39
|
+
};
|
|
40
|
+
type LogEventMetadataOverrides = Omit<LogEventMetadataInput, 'level'>;
|
|
41
|
+
type LogEvent<EventName extends string = string, Attributes extends LogAttributes = LogAttributes> = Readonly<{
|
|
42
|
+
name: EventName;
|
|
43
|
+
data: LogEventData<Attributes>;
|
|
44
|
+
metadata: LogEventMetadata;
|
|
45
|
+
}>;
|
|
46
|
+
declare const LogEvent: (<Attributes extends LogAttributes = LogAttributes, EventName extends string = string>(eventName: EventName, data: LogEventData<Attributes>, eventMetadata: LogEventMetadataInput) => LogEvent<EventName, Attributes>) & {
|
|
47
|
+
message: <Attributes extends LogAttributes = LogAttributes, EventName extends string = string>(level: LogLevel, body: EventName, data?: Omit<LogEventData<Attributes>, "body">, eventMetadata?: LogEventMetadataOverrides) => LogEvent<EventName, Attributes>;
|
|
48
|
+
fatal: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
49
|
+
error: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
50
|
+
warn: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
51
|
+
info: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
52
|
+
debug: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
53
|
+
trace: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
54
|
+
silent: (msgOrObj: string | LogAttributes | Error, msgOrMetadata?: string | LogEventMetadataOverrides, eventMetadata?: LogEventMetadataOverrides) => LogEvent;
|
|
55
|
+
};
|
|
56
|
+
type Logger = (event: LogEvent) => void;
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/tracers/span.d.ts
|
|
59
|
+
type SpanContext = {
|
|
60
|
+
traceId: string;
|
|
61
|
+
spanId: string;
|
|
62
|
+
};
|
|
63
|
+
type SpanLink = SpanContext & {
|
|
64
|
+
attributes?: Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
type ActiveSpan = {
|
|
67
|
+
setAttributes(attrs: Record<string, unknown>): void;
|
|
68
|
+
spanContext(): SpanContext;
|
|
69
|
+
addLink(link: SpanLink): void;
|
|
70
|
+
log: Logger;
|
|
71
|
+
};
|
|
72
|
+
type StartSpanOptions = {
|
|
73
|
+
parent?: SpanContext;
|
|
74
|
+
attributes?: Record<string, unknown>;
|
|
75
|
+
links?: SpanLink[];
|
|
76
|
+
propagation?: TracePropagation;
|
|
77
|
+
sampleRate?: number;
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/tracers/tracer.d.ts
|
|
81
|
+
type TracePropagation = 'links' | 'propagate';
|
|
82
|
+
type Tracer = {
|
|
83
|
+
startSpan<T>(name: string, fn: (span: ActiveSpan) => Promise<T>, options?: StartSpanOptions): Promise<T>;
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region ../almanac/dist/observabilityContextGenerator-XpzUVu7X.d.ts
|
|
87
|
+
type ObservabilityContextGenerator = {
|
|
88
|
+
generateTraceId(): string;
|
|
89
|
+
generateSpanId(): string;
|
|
90
|
+
generateMessageId(): string;
|
|
91
|
+
generateCorrelationId(): string;
|
|
92
|
+
generateCausationId(): string;
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../almanac/dist/index-Ct_mW2YQ.d.ts
|
|
96
|
+
type AttributeTarget = 'mainSpan' | 'currentSpan' | 'both'; //#endregion
|
|
97
|
+
//#region src/meters/meter.d.ts
|
|
98
|
+
type Counter = {
|
|
99
|
+
add(value: number, attributes?: Record<string, unknown>): void;
|
|
100
|
+
};
|
|
101
|
+
type Histogram = {
|
|
102
|
+
record(value: number, attributes?: Record<string, unknown>): void;
|
|
103
|
+
};
|
|
104
|
+
type Gauge = {
|
|
105
|
+
record(value: number, attributes?: Record<string, unknown>): void;
|
|
106
|
+
};
|
|
107
|
+
type Meter = {
|
|
108
|
+
counter(name: string): Counter;
|
|
109
|
+
histogram(name: string): Histogram;
|
|
110
|
+
gauge(name: string): Gauge;
|
|
111
|
+
};
|
|
112
|
+
type Sampler = {
|
|
113
|
+
shouldSample(name: string, attributes?: Record<string, unknown>): boolean;
|
|
114
|
+
};
|
|
115
|
+
type Observability<Prefix extends string = 'almanac'> = {
|
|
116
|
+
tracer: Tracer;
|
|
117
|
+
meter: Meter;
|
|
118
|
+
logger: Logger;
|
|
119
|
+
propagation?: TracePropagation;
|
|
120
|
+
contextGenerator?: ObservabilityContextGenerator;
|
|
121
|
+
attributeTarget?: AttributeTarget;
|
|
122
|
+
attributePrefix?: Prefix;
|
|
123
|
+
sampler?: Sampler;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/configuration/defaultObservability.d.ts
|
|
127
|
+
type DefaultObservability = Partial<Observability<string>>;
|
|
128
|
+
declare global {
|
|
129
|
+
var eventDrivenIoAlmanacDefaultObservability: DefaultObservability | undefined;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/etag.d.ts
|
|
9
133
|
declare const HeaderNames: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
134
|
+
IF_MATCH: string;
|
|
135
|
+
IF_NOT_MATCH: string;
|
|
136
|
+
ETag: string;
|
|
13
137
|
};
|
|
14
138
|
type WeakETag = Brand<`W/${string}`, 'ETag'>;
|
|
15
139
|
type ETag = Brand<string, 'ETag'>;
|
|
16
140
|
declare const WeakETagRegex: RegExp;
|
|
17
141
|
declare const enum ETagErrors {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
142
|
+
WRONG_WEAK_ETAG_FORMAT = "WRONG_WEAK_ETAG_FORMAT",
|
|
143
|
+
MISSING_IF_MATCH_HEADER = "MISSING_IF_MATCH_HEADER",
|
|
144
|
+
MISSING_IF_NOT_MATCH_HEADER = "MISSING_IF_NOT_MATCH_HEADER"
|
|
21
145
|
}
|
|
22
146
|
declare const isWeakETag: (etag: ETag) => etag is WeakETag;
|
|
23
147
|
declare const getWeakETagValue: (etag: ETag) => string;
|
|
@@ -26,60 +150,68 @@ declare const getETagFromIfMatch: (request: Request) => ETag;
|
|
|
26
150
|
declare const getETagFromIfNotMatch: (request: Request) => ETag;
|
|
27
151
|
declare const setETag: (response: Response, etag: ETag) => void;
|
|
28
152
|
declare const getETagValueFromIfMatch: (request: Request) => string;
|
|
29
|
-
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/responses.d.ts
|
|
30
155
|
type ErrorToProblemDetailsMapping = (error: Error, request: Request) => ProblemDocument | undefined;
|
|
31
156
|
type HttpResponseOptions = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
157
|
+
body?: unknown;
|
|
158
|
+
location?: string;
|
|
159
|
+
eTag?: ETag;
|
|
35
160
|
};
|
|
36
161
|
declare const DefaultHttpResponseOptions: HttpResponseOptions;
|
|
37
162
|
type HttpProblemResponseOptions = {
|
|
38
|
-
|
|
39
|
-
|
|
163
|
+
location?: string;
|
|
164
|
+
eTag?: ETag;
|
|
40
165
|
} & Omit<HttpResponseOptions, 'body'> & ({
|
|
41
|
-
|
|
166
|
+
problem: ProblemDocument;
|
|
42
167
|
} | {
|
|
43
|
-
|
|
168
|
+
problemDetails: string;
|
|
44
169
|
});
|
|
45
170
|
declare const DefaultHttpProblemResponseOptions: HttpProblemResponseOptions;
|
|
46
171
|
type CreatedHttpResponseOptions = ({
|
|
47
|
-
|
|
172
|
+
createdId: string;
|
|
48
173
|
} | {
|
|
49
|
-
|
|
50
|
-
|
|
174
|
+
createdId?: string;
|
|
175
|
+
url: string;
|
|
51
176
|
}) & HttpResponseOptions;
|
|
52
|
-
declare const sendCreated: (response: Response, {
|
|
177
|
+
declare const sendCreated: (response: Response, {
|
|
178
|
+
eTag,
|
|
179
|
+
...options
|
|
180
|
+
}: CreatedHttpResponseOptions) => void;
|
|
53
181
|
type AcceptedHttpResponseOptions = {
|
|
54
|
-
|
|
182
|
+
location: string;
|
|
55
183
|
} & HttpResponseOptions;
|
|
56
184
|
declare const sendAccepted: (response: Response, options: AcceptedHttpResponseOptions) => void;
|
|
57
185
|
type NoContentHttpResponseOptions = Omit<HttpResponseOptions, 'body'>;
|
|
186
|
+
declare const sendNoContent: (response: Response, options?: NoContentHttpResponseOptions) => void;
|
|
58
187
|
declare const send: (response: Response, statusCode: number, options?: HttpResponseOptions) => void;
|
|
59
188
|
declare const sendProblem: (response: Response, statusCode: number, options?: HttpProblemResponseOptions) => void;
|
|
60
|
-
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/application.d.ts
|
|
61
191
|
type WebApiSetup = (router: Router) => void;
|
|
62
192
|
type ApplicationOptions = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
193
|
+
apis: WebApiSetup[];
|
|
194
|
+
mapError?: ErrorToProblemDetailsMapping;
|
|
195
|
+
enableDefaultExpressEtag?: boolean;
|
|
196
|
+
disableJsonMiddleware?: boolean;
|
|
197
|
+
disableUrlEncodingMiddleware?: boolean;
|
|
198
|
+
disableProblemDetailsMiddleware?: boolean;
|
|
199
|
+
observability?: Partial<Observability<string>>;
|
|
69
200
|
};
|
|
70
201
|
declare const getApplication: (options: ApplicationOptions) => express.Application;
|
|
71
202
|
type StartApiOptions = {
|
|
72
|
-
|
|
203
|
+
port?: number;
|
|
73
204
|
};
|
|
74
205
|
declare const startAPI: (app: Application, options?: StartApiOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
75
|
-
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/handler.d.ts
|
|
208
|
+
type HttpResponse = (response: Response) => void;
|
|
76
209
|
type HttpHandler<RequestType extends Request> = (request: RequestType) => Promise<HttpResponse> | HttpResponse;
|
|
77
210
|
declare const on: <RequestType extends Request>(handle: HttpHandler<RequestType>) => (request: RequestType, response: Response, _next: NextFunction) => Promise<void>;
|
|
78
211
|
declare const OK: (options?: HttpResponseOptions) => HttpResponse;
|
|
79
212
|
declare const Created: (options: CreatedHttpResponseOptions) => HttpResponse;
|
|
80
213
|
declare const Accepted: (options: AcceptedHttpResponseOptions) => HttpResponse;
|
|
81
214
|
declare const NoContent: (options?: NoContentHttpResponseOptions) => HttpResponse;
|
|
82
|
-
type HttpResponse = (response: Response) => void;
|
|
83
215
|
declare const HttpResponse: (statusCode: number, options?: HttpResponseOptions) => HttpResponse;
|
|
84
216
|
declare const BadRequest: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
85
217
|
declare const Forbidden: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
@@ -87,7 +219,8 @@ declare const NotFound: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
|
87
219
|
declare const Conflict: (options?: HttpProblemResponseOptions) => HttpResponse;
|
|
88
220
|
declare const PreconditionFailed: (options: HttpProblemResponseOptions) => HttpResponse;
|
|
89
221
|
declare const HttpProblem: (statusCode: number, options?: HttpProblemResponseOptions) => HttpResponse;
|
|
90
|
-
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/testing/apiSpecification.d.ts
|
|
91
224
|
type TestRequest = (request: TestAgent<supertest.Test>) => Test;
|
|
92
225
|
declare const existingStream: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
93
226
|
type ResponseAssert = (response: Response$1) => boolean | void;
|
|
@@ -95,30 +228,44 @@ type ApiSpecificationAssert<EventType extends Event = Event> = TestEventStream<E
|
|
|
95
228
|
declare const expect: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
96
229
|
declare const expectNewEvents: <EventType extends Event = Event>(streamId: string, events: EventType[]) => TestEventStream<EventType>;
|
|
97
230
|
declare const expectResponse: <Body = unknown>(statusCode: number, options?: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
231
|
+
body?: Body;
|
|
232
|
+
headers?: {
|
|
233
|
+
[index: string]: string;
|
|
234
|
+
};
|
|
102
235
|
}) => (response: Response$1) => void;
|
|
103
236
|
declare const expectError: (errorCode: number, problemDetails?: Partial<ProblemDocument>) => (response: Response$1) => void;
|
|
104
237
|
type ApiSpecification<EventType extends Event = Event> = (...givenStreams: TestEventStream<EventType>[]) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
238
|
+
when: (setupRequest: TestRequest) => {
|
|
239
|
+
then: (verify: ApiSpecificationAssert<EventType>) => Promise<void>;
|
|
240
|
+
};
|
|
108
241
|
};
|
|
242
|
+
declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(options: {
|
|
243
|
+
getEventStore: () => Store;
|
|
244
|
+
getApplication: (eventStore: Store) => Application;
|
|
245
|
+
}): ApiSpecification<EventType>;
|
|
246
|
+
/** @deprecated Use `ApiSpecification.for({ getEventStore, getApplication })` instead */
|
|
247
|
+
declare function apiSpecificationFor<EventType extends Event = Event, Store extends EventStore = EventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiSpecification<EventType>;
|
|
109
248
|
declare const ApiSpecification: {
|
|
110
|
-
|
|
249
|
+
for: typeof apiSpecificationFor;
|
|
111
250
|
};
|
|
112
|
-
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/testing/apiE2ESpecification.d.ts
|
|
113
253
|
type E2EResponseAssert = (response: Response$1) => boolean | void;
|
|
114
254
|
type ApiE2ESpecificationAssert = [E2EResponseAssert];
|
|
115
255
|
type ApiE2ESpecification = (...givenRequests: TestRequest[]) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
256
|
+
when: (setupRequest: TestRequest) => {
|
|
257
|
+
then: (verify: ApiE2ESpecificationAssert) => Promise<void>;
|
|
258
|
+
};
|
|
119
259
|
};
|
|
260
|
+
declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(options: {
|
|
261
|
+
getEventStore?: () => Store;
|
|
262
|
+
getApplication: (eventStore: Store) => Application;
|
|
263
|
+
}): ApiE2ESpecification;
|
|
264
|
+
/** @deprecated Use `ApiE2ESpecification.for({ getEventStore, getApplication })` instead */
|
|
265
|
+
declare function apiE2ESpecificationFor<Store extends EventStore = InMemoryEventStore>(getEventStore: () => Store, getApplication: (eventStore: Store) => Application): ApiE2ESpecification;
|
|
120
266
|
declare const ApiE2ESpecification: {
|
|
121
|
-
|
|
267
|
+
for: typeof apiE2ESpecificationFor;
|
|
122
268
|
};
|
|
123
|
-
|
|
124
|
-
export { Accepted,
|
|
269
|
+
//#endregion
|
|
270
|
+
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 };
|
|
271
|
+
//# sourceMappingURL=index.d.ts.map
|