/
types.ts
81 lines (76 loc) · 1.84 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
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
import type { PoolConfig } from 'pg'
export type OutboxMessage = {
id: string
processed: false
created_at: Date
updated_at: Date
topic: string
key: string | null
value: unknown
partition: number | null
timestamp: string
response: unknown
error: string | null
context_id: number
meta: object | null
headers: Record<string, string> | null
attempts: number
since_at: Date | null
}
export interface StartStop {
start(): Promise<void>
stop(): Promise<void>
}
export interface Send {
send(
messages: readonly OutboxMessage[]
): Promise<((PromiseFulfilledResult<unknown> | PromiseRejectedResult) & { meta?: object })[]>
}
export type Adapter = StartStop & Send
export type Options = {
pgOptions: PoolConfig
adapter: Adapter
outboxOptions?: {
/**
* how often to poll PostgreSQL for new messages, default 5000 milliseconds
*/
pollInterval?: number
/**
* how often to process new messages in 'logical' mode, default 100 milliseconds
*/
logicalBatchInterval?: number
/**
* how often to process responses of messages, default 100 milliseconds
*/
respondInterval?: number
/**
* how much messages send for processing, default 50
*/
limit?: number
mode?: 'short-polling' | 'notify' | 'logical'
/**
* callback for handling uncaught error
*/
onError?: (err: Error) => unknown
/**
* For scaling by partitions, pass partition number 0..n
*/
partition?: number
/**
* Array of topics, which should be handled only
*/
topicFilter?: string[]
/**
* predicate for error retrying
*/
retryError?: (err: Error) => boolean
/**
* retrying delay in seconds, default 5 seconds
*/
retryDelay?: number
/**
* max attempts for retry, default 5
*/
retryMaxAttempts?: number
}
}