-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
53 lines (44 loc) · 1.41 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Notification } from "./notification.ts";
import { Request } from "./request.ts";
export type Message = Request | Notification;
export type Response<TRequest> = TRequest extends Request<infer TResponse>
? TResponse
: never;
export type RequestOrNotification<T> = T extends Request<infer TResponse>
? Request<TResponse>
: T extends Notification ? Notification
: never;
export type RequestHandler<TRequest extends Request = Request<unknown>> = (
request: TRequest,
) => Response<TRequest>;
export type NotificationHandler<
TNotification extends Notification = Notification,
> = (
notification: TNotification,
) => Promise<void> | void;
export type Handler<T> = T extends Request ? RequestHandler<T>
: T extends Notification ? NotificationHandler<T>
: never;
export type RequestConstructor<TRequest extends Request = Request> =
& (new (
// deno-lint-ignore no-explicit-any
...args: any
) => TRequest)
& {
prototype: TRequest;
}
& Pick<typeof Request, "requestTypeId">;
export type NotificationConstructor<
TNotification extends Notification = Notification,
> =
& (new (
// deno-lint-ignore no-explicit-any
...args: any
) => TNotification)
& {
prototype: TNotification;
}
& Pick<typeof Notification, "notificationTypeId">;
export type Constructor<T> = T extends Request ? RequestConstructor<T>
: T extends Notification ? NotificationConstructor<T>
: never;