forked from chilts/mongodb-queue
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mongodb-queue.d.ts
52 lines (44 loc) · 1.97 KB
/
mongodb-queue.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
import { Db, MongoError } from 'mongodb';
declare function mongodbQueue(db: Db, name: string, opts?: mongodbQueue.QueueOptions): mongodbQueue.Queue;
declare namespace mongodbQueue {
class Queue {
constructor(db: Db, name: string, opts?: QueueOptions);
createIndexes(callback: QueueCallback<string>): void;
add(payload: Payload, callback: QueueCallback<string>): void;
add(payload: ArrayPayload, callback: QueueCallback<string[]>): void;
add(payload: Payload, opts: QueueOptions, callback: QueueCallback<string>): void;
add(payload: ArrayPayload, opts: QueueOptions, callback: QueueCallback<string[]>): void;
get(callback: QueueCallback<QueueMessage | undefined>): void;
get(opts: QueueOptions, callback: QueueCallback<QueueMessage | undefined>): void;
ping(ack: string, callback: QueueCallback<string>): void;
ping(ack: string, opts: QueueOptions, callback: QueueCallback<string>): void;
ack(ack: string, callback: QueueCallback<string>): void;
clean(callback: QueueCallback<any>): void;
total(callback: QueueCallback<number>): void;
size(callback: QueueCallback<number>): void;
listWaiting(callback: QueueCallback<QueueMessage[]>): void;
inFlight(callback: QueueCallback<number>): void;
listInFlight(callback: QueueCallback<QueueMessage[]>): void;
incomplete(callback: QueueCallback<number>): void;
listIncomplete(callback: QueueCallback<QueueMessage[]>): void;
done(callback: QueueCallback<number>): void;
}
type Payload = string | Record<string, unknown>;
type ArrayPayload = Array<string | Record<string, unknown>>;
interface QueueOptions {
deadQueue?: Queue | undefined;
delay?: number | undefined;
maxRetries?: number | undefined;
visibility?: number | undefined;
}
interface QueueMessage {
ack: string;
id: string;
payload: Payload | ArrayPayload;
tries: number;
}
interface QueueCallback<T> {
(err: MongoError | Error, result: T): void;
}
}
export = mongodbQueue;