-
Notifications
You must be signed in to change notification settings - Fork 6
/
interfaces.ts
150 lines (130 loc) · 3.28 KB
/
interfaces.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
140
141
142
143
144
145
146
147
148
149
150
import { CommittedEvent, Disposable } from "@rotorsoft/eventually";
import {
PullOptions,
PushEvent,
Service,
Subscription,
TriggerCallback
} from "./types";
/**
* Listens for changes in streams
*/
export interface StreamListener {
listen: (callback: TriggerCallback) => Promise<void>;
close: () => Promise<void>;
}
/**
* Pull channels pull events from streams
*/
export interface PullChannel extends Disposable {
label: string;
listen: (callback: TriggerCallback) => Promise<void>;
pull: (options: PullOptions) => Promise<CommittedEvent[]>;
}
/**
* Push channels push events to consumer endpoints
*/
export interface PushChannel {
label: string;
init: () => Promise<void>;
push: (events: PushEvent[]) => Promise<number>;
}
/**
* Maps protocols to channel factories
*/
export interface ChannelResolvers {
pull: Record<string, (url: URL, id: string) => PullChannel>;
push: Record<
string,
(
url: URL,
id: string,
source: string,
headers?: Record<string, unknown>
) => PushChannel
>;
}
/**
* Implements subscription store
*/
export interface SubscriptionStore extends Disposable {
/**
* Store initializer
* @returns a stream listener factory for this store
*/
seed: () => Promise<void>;
/**
* Starts listening for changes in services and subscriptions
*/
listen: (
servicesCallback: TriggerCallback,
subscriptionsCallback: TriggerCallback
) => void;
/**
* Loads services from store
* @param id optional service id
*/
loadServices: (id?: string) => Promise<Service[]>;
/**
* Creates a new service
* @param service the service
*/
createService: (service: Service) => Promise<void>;
/**
* Updates a service
* @param service the service
*/
updateService: (service: Service) => Promise<void>;
/**
* Deletes a service
* @param id the service id
*/
deleteService: (id: string) => Promise<void>;
/**
* Commits a new channel position
* @param id service id
* @param position new position
*/
commitServicePosition: (id: string, position: number) => Promise<void>;
/**
* Loads subscriptions from store
* @param id optional subscription id
*/
loadSubscriptions: (id?: string) => Promise<Subscription[]>;
/**
* Loads subscriptions by producer
* @param producer the producer name
*/
loadSubscriptionsByProducer: (producer: string) => Promise<Subscription[]>;
/**
* Searches subscriptions from store
* @param pattern search pattern
*/
searchSubscriptions: (pattern: string) => Promise<Subscription[]>;
/**
* Creates a new subscription
* @param sub the subscription
*/
createSubscription: (sub: Subscription) => Promise<void>;
/**
* Updates a subscription
* @param sub the subscription
*/
updateSubscription: (sub: Subscription) => Promise<void>;
/**
* Deletes a subscription
* @param id the subscription id
*/
deleteSubscription: (id: string) => Promise<void>;
/**
* Toggles a subscription (activation)
* @param id the subscription id
*/
toggleSubscription: (id: string) => Promise<void>;
/**
* Commits a new subscription position
* @param id subscription id
* @param position new position
*/
commitSubscriptionPosition: (id: string, position: number) => Promise<void>;
}