-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.d.ts
92 lines (75 loc) · 2.17 KB
/
index.d.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { EventEmitter } from 'events'
declare function avvio (done?: Function): avvio.Avvio<null>
declare function avvio<I> (
instance: I,
options?: avvio.Options,
done?: Function
): avvio.Avvio<I>
/**
* Typescript cannot manage changes related to options "expose"
* because undefined before runtime
*/
declare namespace avvio {
type context<I> = I extends null ? Avvio<I> : mixedInstance<I>
type mixedInstance<I> = I & Server<I>
interface Options {
expose?: {
use?: string;
after?: string;
ready?: string;
close?: string;
onClose?: string;
};
autostart?: boolean;
timeout?: number;
}
interface Plugin<O, I> {
(server: context<I>, options: O, done: (err?: Error) => void): unknown;
}
interface Server<I> {
use: Use<I>;
after: After<I>;
ready: Ready<I>;
close: Close<I>;
onClose: OnClose<I>;
}
interface Avvio<I> extends EventEmitter, Server<I> {
on(event: 'start', listener: () => void): this;
on(event: 'preReady', listener: () => void): this;
on(event: 'close', listener: () => void): this;
start(): this;
toJSON(): Object;
prettyPrint(): string;
override: (
server: context<I>,
fn: Plugin<any, I>,
options: any
) => context<I>;
started: boolean;
booted: boolean;
}
// Avvio methods
interface After<I, C = context<I>> {
(fn: (err: Error) => void): C;
(fn: (err: Error, done: Function) => void): C;
(fn: (err: Error, context: C, done: Function) => void): C;
}
interface Use<I, C = context<I>> {
<O>(fn: avvio.Plugin<O, I>, options?: O | ((server: C) => O)): C;
}
interface Ready<I, C = context<I>> {
(): Promise<C>;
(callback: (err?: Error) => void): void;
(callback: (err: Error, done: Function) => void): void;
(callback: (err: Error, context: C, done: Function) => void): void;
}
interface Close<I, C = context<I>> {
(fn: (err: Error) => void): void;
(fn: (err: Error, done: Function) => void): void;
(fn: (err: Error, context: C, done: Function) => void): void;
}
interface OnClose<I, C = context<I>> {
(fn: (context: C, done: Function) => void): C;
}
}
export = avvio