-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.d.ts
94 lines (84 loc) · 2.13 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
93
94
import {MessageProperties} from 'amqplib';
export {ConfirmChannel} from 'amqplib';
type ACK = 'ACK';
type NACK = 'NACK';
type REJECT = 'REJECT';
type Result = ACK | NACK | REJECT;
export type Message = {
ACK: ACK;
NACK: NACK;
REJECT: REJECT;
content: Record<any, any>;
rk: string;
queue: string;
token: string;
consumeAt: number;
originMsg: any;
};
export interface RabQConfig {
username?: string;
password?: string;
protocol?: string;
hostname?: string;
port?: number;
socketOptions?: any;
vhost?: string;
exchange?: string;
queues?: string[] | string;
maxMessages?: number;
nackDelay?: number;
reconnectInterval?: number;
autoAck?: boolean;
autoReconnect?: boolean;
acceptPlainText?: boolean;
validators?: {
consumer: (exchange: string, queue: string, parsedMesage: Message) => boolean;
};
beforeHook?: (message: Message) => void;
afterHook?: (message: Message, subscriberResult: Result) => void;
prePublish?: (routingkey: string, content: Record<any, any>, properties?: Partial<MessageProperties>) => void;
xQueryTokenFallback?: () => string;
}
interface Logger {
debug(
uuid: string | null,
token: string | null,
message: string,
error?: unknown,
): void;
info(
uuid: string | null,
token: string | null,
message: string,
error?: unknown,
): void;
warn(
uuid: string | null,
token: string | null,
message: string,
error?: unknown,
): void;
error(
uuid: string | null,
token: string | null,
message: string,
error?: unknown,
): void;
}
export class RabQ {
start: () => Promise<boolean>;
stop: () => Promise<boolean>;
publish: (routingkey: string, content: Record<any, any>, properties?: Partial<MessageProperties>) => void;
subscribesTo: (patternMatch: RegExp, action: {
do: (message: Message) => Result | Promise<Result>;
}) => void;
constructor(config: RabQConfig, logger: Logger);
on(event: 'log', callback: (log: {
level: 'info' | 'warn' | 'error';
token: 'string';
msg: 'string';
err: any;
}) => void): void;
on(event: 'error', callback: (error: Error) => void): void;
}
export = RabQ;