-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Handler.ts
59 lines (48 loc) 路 1.65 KB
/
Handler.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
54
55
56
57
58
59
import type { Operator } from "./Operator.ts";
import type { CtxLike, NonPostableEvtLike } from "../types/interfaces/index.ts";
/** https://docs.evt.land/api/handler */
export type Handler<T, U, CtxProp extends CtxLike<any> | undefined = CtxLike<any> | undefined> =
Handler.PropsFromArgs<T, U, CtxProp> &
Handler.PropsFromMethodName & Readonly<{
detach(): boolean;
promise: Promise<U>;
}>
;
export namespace Handler {
/** Handlers params that come from the arguments passed to the method invoked */
export type PropsFromArgs<T, U, CtxProp extends CtxLike<any> | undefined = CtxLike<any> | undefined> = {
ctx: CtxProp;
timeout: number | undefined;
op: Operator<T, U>;
callback: ((transformedData: U) => void) | undefined;
};
/**
* Handlers params that are implicitly specified by the method used:
* attachOnce => once
* attachOncePrepend => once + prepend
* waitFor => once + async
* ...
*/
export type PropsFromMethodName = PropsFromMethodName.Sync | PropsFromMethodName.Async;
export namespace PropsFromMethodName {
type Common = Readonly<{
prepend: true;
extract: true;
} | {
prepend: boolean;
extract: false;
}>;
export type Sync = Common & Readonly<{
async: false;
once: boolean;
}>;
export type Async = Common & Readonly<{
async: true;
once: true;
}>;
}
export type WithEvt<T,CtxResult> = {
handler: Handler<T, any, CtxLike<CtxResult>>;
evt: NonPostableEvtLike<T>;
};
}