-
Notifications
You must be signed in to change notification settings - Fork 6
/
types.ts
139 lines (129 loc) · 3.56 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { CommittedEvent } from "@rotorsoft/eventually";
import { ServiceSpec } from "@rotorsoft/eventually-openapi";
import { RequestHandler } from "express";
import { ChannelResolvers, SubscriptionStore } from "./interfaces";
/**
* Services
* - `id` The service unique id
* - `channel` The service channel - (example: pg://all = postgres "all" stream)
* - `url` The service url - (example: http://localhost:3000)
* - `position` The position in the channel - last trigger id
* - `updated` The last update timestamp
*/
export type Service = {
id: string;
channel: string;
url: string;
position: number;
updated: Date;
status?: string;
label?: string;
} & ServiceSpec;
/**
* Subscriptions connect producer and consumer services using pattern matching rules
* - `id` The subscription unique id
* - `producer` The producer service
* - `consumer` The consumer service
* - `path` The path on the consumer service (appended to url - policy name by convention)
* - `streams`: regex rules to filter by substringeams (aggregates, systems, process managers)
* - `names`: regex rules to filter by event names
* - `position` The position in the stream - last acked id
* - `updated` The last update timestamp
* - `batch_size` The pull batch size (default 100)
* - `retries` The number of retries before pausing (default 3)
* - `retry_timeout_sec` Seconds between retries with exponential backoff (default 10)
* - `endpoint` Calculated field combining consumer url with path
*/
export type Subscription = {
id: string;
active: boolean;
producer: string;
consumer: string;
path: string;
streams: string;
names: string;
position: number;
updated: Date;
batch_size: number;
retries: number;
retry_timeout_secs: number;
endpoint: string;
};
export type Operation =
| "REFRESH"
| "RESTART"
| "INSERT"
| "UPDATE"
| "DELETE"
| "RETRY"
| "MANUAL";
/**
* Trigger payload
* - `id`: trigger id (record id, event name)
* - `operation`: triggering operation
* - `position`: optional position in stream
* - `payload`: optional trigger payload
*/
export type TriggerPayload = {
id: string;
operation: Operation;
position?: number;
payload?: any;
};
/**
* Pull options
* - `operation`: triggering operation
* - `position`: subscription position
* - `limit`: pull limit - # of events in batch
*/
export type PullOptions = {
operation: Operation;
position: number;
limit: number;
};
/**
* Subscription trigger callback to signal integration
*/
export type TriggerCallback = (trigger: TriggerPayload) => void;
/**
* Push response
*/
export type PushResponse = {
statusCode: number;
statusText?: string;
details?: string;
};
/**
* Push event
*/
export type PushEvent = CommittedEvent & {
response?: PushResponse;
};
/**
* App options
*/
export type SecretOptions = {
byService?: Record<string, Record<string, unknown>>;
bySubscription?: Record<string, Record<string, unknown>>;
};
export type AppOptions = {
subscriptionStoreFactory: () => SubscriptionStore;
resolvers?: ChannelResolvers;
port?: number;
middleware?: RequestHandler[];
handlers?: RequestHandler[];
serviceLogLinkTemplate?: string;
secrets?: SecretOptions;
};
//=====================================================================================
// CONTRACTS QUERY LEVEL
//=====================================================================================
/**
* Options to query the all services contracts
* - services? filter by services
* - names? filter by event names
*/
export type AllQuery = {
readonly services?: string[];
readonly names?: string[];
};