forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostal.d.ts
More file actions
106 lines (79 loc) · 2.88 KB
/
postal.d.ts
File metadata and controls
106 lines (79 loc) · 2.88 KB
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
// Type definitions for Postal v1.0.6
// Project: https://github.com/postaljs/postal.js
// Definitions by: Lokesh Peta <https://github.com/lokeshpeta/>, Paul Jolly <https://github.com/myitcv>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface IConfiguration {
SYSTEM_CHANNEL: string;
DEFAULT_CHANNEL: string;
resolver: IResolver;
}
interface IResolver {
compare(binding: string, topic: string, headerOptions: {}): boolean;
reset(): void;
purge(options?: {topic?: string, binding?: string, compact?: boolean}): void;
}
interface ICallback {
(data: any, envelope: IEnvelope): void
}
interface ISubscriptionDefinition {
channel: string;
topic: string;
callback: ICallback;
// after and before lack documentation
constraint(predicateFn: (data: any, envelope: IEnvelope) => boolean): ISubscriptionDefinition;
constraints(predicateFns: ((data: any, envelope: IEnvelope) => boolean)[]): ISubscriptionDefinition;
context(theContext: any): ISubscriptionDefinition;
debounce(interval: number): ISubscriptionDefinition;
defer(): ISubscriptionDefinition;
delay(waitTime: number): ISubscriptionDefinition;
disposeAfter(maxCalls: number): ISubscriptionDefinition;
distinct(): ISubscriptionDefinition;
distinctUntilChanged(): ISubscriptionDefinition;
logError(): ISubscriptionDefinition;
once(): ISubscriptionDefinition;
throttle(interval: number): ISubscriptionDefinition;
subscribe(callback: ICallback): ISubscriptionDefinition;
unsubscribe(): void;
}
interface IEnvelope {
topic: string;
data?: any;
/*Uses DEFAULT_CHANNEL if no channel is provided*/
channel?: string;
timeStamp?: string;
}
interface IChannelDefinition {
subscribe(topic: string, callback: ICallback): ISubscriptionDefinition;
publish(topic: string, data?: any): void;
channel: string;
}
interface ISourceArg {
topic: string;
channel?: string;
}
interface IDestinationArg {
topic: string | ((topic: string) => string);
channel?: string;
}
interface IPostal {
subscriptions: {};
wiretaps: ICallback[];
addWireTap(callback: ICallback): () => void;
channel(name?: string): IChannelDefinition;
getSubscribersFor(): ISubscriptionDefinition[];
getSubscribersFor(options: {channel?: string, topic?: string, context?: any}): ISubscriptionDefinition[];
getSubscribersFor(predicateFn: (sub: ISubscriptionDefinition) => boolean): ISubscriptionDefinition[];
linkChannels(source: ISourceArg | ISourceArg[], destination: IDestinationArg | IDestinationArg[]): void;
publish(envelope: IEnvelope): void;
reset(): void;
subscribe(options: {channel?: string, topic: string, callback: ICallback}): ISubscriptionDefinition;
unsubscribe(sub: ISubscriptionDefinition): void;
unsubscribeFor(): void;
unsubscribeFor(options: {channel?: string, topic?: string, context?: any}): void;
configuration: IConfiguration;
}
declare var postal: IPostal;
declare module "postal" {
var postal: IPostal;
export = postal;
}