-
Notifications
You must be signed in to change notification settings - Fork 0
/
annotations.ts
215 lines (177 loc) · 5.29 KB
/
annotations.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import {UrlTemplate} from "./urlTemplate";
/**
* Metadata that indicates a contract implemented by a service.
* @hidden
*/
export class ContractAnnotation {
/**
* Constructs a contract annotation.
* @param name The name of the contract.
*/
constructor(public name?: string) {
}
}
/**
* Options available for [[Operation]] decorator.
*/
export interface OperationOptions {
/**
* The name of the operation. If not specified, defaults to the name of the method.
*/
name?: string;
/**
* Indicates if the operation is one way. Default is false. One-way operations immediately return to the client
* without waiting for a result.
*/
isOneWay?: boolean;
/**
* Specifies the timeout for the operation. If not specified, defaults to the timeout for the service.
*/
timeout?: number;
/**
* Indicates the name of the target contract for this operation. This is required when the service has more than
* one contract.
*/
contract?: string;
}
/**
* Metadata that describes a method on a service as part of a service contract.
* @hidden
*/
export class OperationAnnotation {
/**
* The name of the operation. If not specified, defaults to the name of the method.
*/
name: string;
/**
* Indicates if the operation is one way. Default is false. One-way operations immediately return to the client
* without waiting for a result.
*/
isOneWay: boolean;
/**
* Specifies the timeout for the operation. If not specified, defaults to the timeout for the service.
*/
timeout: number;
/**
* Indicates the name of the target contract for this operation. This is required when the service has more than
* one contract.
*/
contract: string;
constructor(args: OperationOptions) {
if(args) {
this.name = args.name;
this.isOneWay = args.isOneWay;
this.timeout = args.timeout;
this.contract = args.contract;
}
}
}
/**
* Options for indicating that an operation is callable via a REST api.
*/
export class WebInvokeOptions {
/**
* The http method (e.g. GET, POST, PUT, ...)
*/
method: string;
/**
* The URL template for the operation. For more information, see [[UrlTemplate]].
*/
template: string;
}
/**
* Metadata that indicates an operation is callable via a REST api.
* @hidden
*/
export class WebInvokeAnnotation {
method: string;
template: UrlTemplate;
/**
* Constructs a WebInvokeAnnotation.
* @param options Options for operation that is callable ia a REST api.
*/
constructor(options: WebInvokeOptions) {
if(!options) {
throw new Error("Missing required argument 'options'.");
}
if(!options.method) {
throw new Error("Missing required argument 'options.method'.");
}
if(!options.template) {
throw new Error("Missing required argument 'options.template'.");
}
this.method = options.method.toUpperCase();
this.template = new UrlTemplate(options.template);
}
}
/**
* Metadata that indicates an operation is callable an HTTP GET request.
* @hidden
*/
export class WebGetAnnotation extends WebInvokeAnnotation {
/**
* Constructs a WebGetAnnotation.
* @param template The URL template for the operation. For more information, see [[UrlTemplate]].
*/
constructor(template: string) {
super({ method: "GET", template: template });
}
}
/**
* Metadata that indicates an operation is callable an HTTP PUT request.
* @hidden
*/
export class WebPutAnnotation extends WebInvokeAnnotation {
/**
* Constructs a WebPutAnnotation.
* @param template The URL template for the operation. For more information, see [[UrlTemplate]].
*/
constructor(template: string) {
super({ method: "PUT", template: template });
}
}
/**
* Metadata that indicates an operation is callable an HTTP POST request.
* @hidden
*/
export class WebPostAnnotation extends WebInvokeAnnotation {
/**
* Constructs a WebPostAnnotation.
* @param template The URL template for the operation. For more information, see [[UrlTemplate]].
*/
constructor(template: string) {
super({ method: "POST", template: template });
}
}
/**
* Metadata that indicates an operation is callable an HTTP DELETE request.
* @hidden
*/
export class WebDeleteAnnotation extends WebInvokeAnnotation {
/**
* Constructs a WebDeleteAnnotation.
* @param template The URL template for the operation. For more information, see [[UrlTemplate]].
*/
constructor(template: string) {
super({ method: "DELETE", template: template });
}
}
/**
* Metadata that indicates an operation is callable an HTTP HEAD request.
* @hidden
*/
export class WebHeadAnnotation extends WebInvokeAnnotation {
/**
* Constructs a WebHeadAnnotation.
* @param template The URL template for the operation. For more information, see [[UrlTemplate]].
*/
constructor(template: string) {
super({ method: "HEAD", template: template });
}
}
/**
* Metadata indicates that the body of the message should be mapped to the operation parameter.
* @hidden
*/
export class InjectBodyAnnotation {
}