blob: 470adfe907b0094354ccbb4061cdfbb3635cf1c4 [file] [log] [blame]
Pascal Schweizerada10162014-03-21 17:18:59 +01001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20declare module Thrift {
21 /**
22 * Thrift JavaScript library version.
23 */
24 var Version: string;
25
26 /**
27 * Thrift IDL type string to Id mapping.
28 * @property {number} STOP - End of a set of fields.
29 * @property {number} VOID - No value (only legal for return types).
30 * @property {number} BOOL - True/False integer.
31 * @property {number} BYTE - Signed 8 bit integer.
32 * @property {number} I08 - Signed 8 bit integer.
33 * @property {number} DOUBLE - 64 bit IEEE 854 floating point.
34 * @property {number} I16 - Signed 16 bit integer.
35 * @property {number} I32 - Signed 32 bit integer.
36 * @property {number} I64 - Signed 64 bit integer.
37 * @property {number} STRING - Array of bytes representing a string of characters.
38 * @property {number} UTF7 - Array of bytes representing a string of UTF7 encoded characters.
39 * @property {number} STRUCT - A multifield type.
40 * @property {number} MAP - A collection type (map/associative-array/dictionary).
41 * @property {number} SET - A collection type (unordered and without repeated values).
42 * @property {number} LIST - A collection type (unordered).
43 * @property {number} UTF8 - Array of bytes representing a string of UTF8 encoded characters.
44 * @property {number} UTF16 - Array of bytes representing a string of UTF16 encoded characters.
45 */
46 interface Type {
47 'STOP': number;
48 'VOID': number;
49 'BOOL': number;
50 'BYTE': number;
51 'I08': number;
52 'DOUBLE': number;
53 'I16': number;
54 'I32': number;
55 'I64': number;
56 'STRING': number;
57 'UTF7': number;
58 'STRUCT': number;
59 'MAP': number;
60 'SET': number;
61 'LIST': number;
62 'UTF8': number;
63 'UTF16': number;
64 }
65 var Type: Type;
66
67 /**
68 * Thrift RPC message type string to Id mapping.
69 * @property {number} CALL - RPC call sent from client to server.
70 * @property {number} REPLY - RPC call normal response from server to client.
71 * @property {number} EXCEPTION - RPC call exception response from server to client.
72 * @property {number} ONEWAY - Oneway RPC call from client to server with no response.
73 */
74 interface MessageType {
75 'CALL': number;
76 'REPLY': number;
77 'EXCEPTION': number;
78 'ONEWAY': number;
79 }
80 var MessageType: MessageType;
81
82 /**
83 * Utility function returning the count of an object's own properties.
84 * @param {object} obj - Object to test.
85 * @returns {number} number of object's own properties
86 */
87 function objectLength(obj: any): number;
88
89 /**
90 * Utility function to establish prototype inheritance.
91 * @param {function} constructor - Contstructor function to set as derived.
92 * @param {function} superConstructor - Contstructor function to set as base.
93 * @param {string} [name] - Type name to set as name property in derived prototype.
94 */
95 function inherits(constructor: Function, superConstructor: Function, name?: string): void;
96
97 /**
98 * TException is the base class for all Thrift exceptions types.
99 */
100 class TException implements Error {
101 name: string;
102 message: string;
103
104 /**
105 * Initializes a Thrift TException instance.
106 * @param {string} message - The TException message (distinct from the Error message).
107 */
108 constructor(message: string);
109
110 /**
111 * Returns the message set on the exception.
112 * @returns {string} exception message
113 */
114 getMessage(): string;
115 }
116
117 /**
118 * Thrift Application Exception type string to Id mapping.
119 * @property {number} UNKNOWN - Unknown/undefined.
120 * @property {number} UNKNOWN_METHOD - Client attempted to call a method unknown to the server.
121 * @property {number} INVALID_MESSAGE_TYPE - Client passed an unknown/unsupported MessageType.
122 * @property {number} WRONG_METHOD_NAME - Unused.
123 * @property {number} BAD_SEQUENCE_ID - Unused in Thrift RPC, used to flag proprietary sequence number errors.
124 * @property {number} MISSING_RESULT - Raised by a server processor if a handler fails to supply the required return result.
125 * @property {number} INTERNAL_ERROR - Something bad happened.
126 * @property {number} PROTOCOL_ERROR - The protocol layer failed to serialize or deserialize data.
127 * @property {number} INVALID_TRANSFORM - Unused.
128 * @property {number} INVALID_PROTOCOL - The protocol (or version) is not supported.
129 * @property {number} UNSUPPORTED_CLIENT_TYPE - Unused.
130 */
131 interface TApplicationExceptionType {
132 'UNKNOWN': number;
133 'UNKNOWN_METHOD': number;
134 'INVALID_MESSAGE_TYPE': number;
135 'WRONG_METHOD_NAME': number;
136 'BAD_SEQUENCE_ID': number;
137 'MISSING_RESULT': number;
138 'INTERNAL_ERROR': number;
139 'PROTOCOL_ERROR': number;
140 'INVALID_TRANSFORM': number;
141 'INVALID_PROTOCOL': number;
142 'UNSUPPORTED_CLIENT_TYPE': number;
143 }
144 var TApplicationExceptionType: TApplicationExceptionType;
145
146 /**
147 * TApplicationException is the exception class used to propagate exceptions from an RPC server back to a calling client.
148 */
149 class TApplicationException extends TException {
150 code: number;
151
152 /**
153 * Initializes a Thrift TApplicationException instance.
154 * @param {string} message - The TApplicationException message (distinct from the Error message).
155 * @param {Thrift.TApplicationExceptionType} [code] - The TApplicationExceptionType code.
156 */
157 constructor(message: string, code?: number);
158
159 /**
160 * Read a TApplicationException from the supplied protocol.
161 * @param {object} input - The input protocol to read from.
162 */
163 read(input: any): void;
164
165 /**
166 * Write a TApplicationException to the supplied protocol.
167 * @param {object} output - The output protocol to write to.
168 */
169 write(output: any): void;
170
171 /**
172 * Returns the application exception code set on the exception.
173 * @returns {Thrift.TApplicationExceptionType} exception code
174 */
175 getCode(): number;
176 }
177
178 /**
179 * The Apache Thrift Transport layer performs byte level I/O between RPC
180 * clients and servers. The JavaScript Transport object type uses Http[s]/XHR and is
181 * the sole browser based Thrift transport. Target servers must implement the http[s]
182 * transport (see: node.js example server).
183 */
184 class TXHRTransport {
185 url: string;
186 wpos: number;
187 rpos: number;
188 useCORS: any;
189 send_buf: string;
190 recv_buf: string;
191
192 /**
193 * If you do not specify a url then you must handle XHR operations on
194 * your own. This type can also be constructed using the Transport alias
195 * for backward compatibility.
196 * @param {string} [url] - The URL to connect to.
197 * @param {any} [options] - Options.
198 */
199 constructor(url?: string, options?: any);
200
201 /**
202 * Gets the browser specific XmlHttpRequest Object.
203 * @returns {object} the browser XHR interface object
204 */
205 getXmlHttpRequestObject(): any;
206
207 /**
208 * Sends the current XRH request if the transport was created with a URL and
209 * the async parameter if false. If the transport was not created with a URL
210 * or the async parameter is True or the URL is an empty string, the current
211 * send buffer is returned.
212 * @param {object} async - If true the current send buffer is returned.
213 * @param {object} callback - Optional async completion callback.
214 * @returns {undefined|string} Nothing or the current send buffer.
215 */
216 flush(async: any, callback?: Function): string;
217
218 /**
219 * Creates a jQuery XHR object to be used for a Thrift server call.
220 * @param {object} client - The Thrift Service client object generated by the IDL compiler.
221 * @param {object} postData - The message to send to the server.
222 * @param {function} args - The function to call if the request suceeds.
223 * @param {function} recv_method - The Thrift Service Client receive method for the call.
224 * @returns {object} A new jQuery XHR object.
225 */
226 jqRequest(client: any, postData: any, args: Function, recv_method: Function): any;
227
228 /**
229 * Sets the buffer to use when receiving server responses.
230 * @param {string} buf - The buffer to receive server responses.
231 */
232 setRecvBuffer(buf: string): void;
233
234 /**
235 * Returns true if the transport is open, in browser based JavaScript
236 * this function always returns true.
237 * @returns {boolean} Always True.
238 */
239 isOpen(): boolean;
240
241 /**
242 * Opens the transport connection, in browser based JavaScript
243 * this function is a nop.
244 */
245 open(): void;
246
247 /**
248 * Closes the transport connection, in browser based JavaScript
249 * this function is a nop.
250 */
251 close(): void;
252
253 /**
254 * Returns the specified number of characters from the response
255 * buffer.
256 * @param {number} len - The number of characters to return.
257 * @returns {string} Characters sent by the server.
258 */
259 read(len: number): string;
260
261 /**
262 * Returns the entire response buffer.
263 * @returns {string} Characters sent by the server.
264 */
265 readAll(): string;
266
267 /**
268 * Sets the send buffer to buf.
269 * @param {string} buf - The buffer to send.
270 */
271 write(buf: string): void;
272
273 /**
274 * Returns the send buffer.
275 * @returns {string} The send buffer.
276 */
277 getSendBuffer(): string;
278 }
279
280 /**
281 * Old alias of the TXHRTransport for backwards compatibility.
282 */
283 class Transport extends TXHRTransport { }
284
285 /**
286 * The Apache Thrift Transport layer performs byte level I/O
287 * between RPC clients and servers. The JavaScript TWebSocketTransport object
288 * uses the WebSocket protocol. Target servers must implement WebSocket.
289 */
290 class TWebSocketTransport {
291 url: string; //Where to connect
292 socket: any; //The web socket
293 callbacks: any[]; //Pending callbacks
294 send_pending: any[]; //Buffers/Callback pairs waiting to be sent
295 send_buf: string; //Outbound data, immutable until sent
296 recv_buf: string; //Inbound data
297 rb_wpos: number; //Network write position in receive buffer
298 rb_rpos: number; //Client read position in receive buffer
299
300 /**
301 * Constructor Function for the WebSocket transport.
302 * @param {string } [url] - The URL to connect to.
303 */
304 constructor(url: string);
305
306 __reset(url): void;
307
308 /**
309 * Sends the current WS request and registers callback. The async
310 * parameter is ignored (WS flush is always async) and the callback
311 * function parameter is required.
312 * @param {object} async - Ignored.
313 * @param {object} callback - The client completion callback.
314 * @returns {undefined|string} Nothing (undefined)
315 */
316 flush(async: any, callback: any): string;
317
318 __onOpen(): void;
319
320 __onClose(): void;
321
322 __onMessage(): void;
323
324 __onError(): void;
325
326 /**
327 * Sets the buffer to use when receiving server responses.
328 * @param {string} buf - The buffer to receive server responses.
329 */
330 setRecvBuffer(buf: string): void;
331
332 /**
333 * Returns true if the transport is open
334 * @returns {boolean}
335 */
336 isOpen(): boolean;
337
338 /**
339 * Opens the transport connection
340 */
341 open(): void;
342
343 /**
344 * Closes the transport connection
345 */
346 close(): void;
347
348 /**
349 * Returns the specified number of characters from the response
350 * buffer.
351 * @param {number} len - The number of characters to return.
352 * @returns {string} Characters sent by the server.
353 */
354 read(len: number): string;
355
356 /**
357 * Returns the entire response buffer.
358 * @returns {string} Characters sent by the server.
359 */
360 readAll(): string;
361
362 /**
363 * Sets the send buffer to buf.
364 * @param {string} buf - The buffer to send.
365 */
366 write(buf: string): void;
367
368 /**
369 * Returns the send buffer.
370 * @returns {string} The send buffer.
371 */
372 getSendBuffer(): string;
373 }
374
375 /**
376 * Apache Thrift Protocols perform serialization which enables cross
377 * language RPC. The Protocol type is the JavaScript browser implementation
378 * of the Apache Thrift TJSONProtocol.
379 */
380 class TJSONProtocol {
381 transport: Transport;
382
383 /**
384 * Thrift IDL type Id to string mapping.
385 * The mapping table looks as follows:
386 * Thrift.Type.BOOL -> "tf": True/False integer.
387 * Thrift.Type.BYTE -> "i8": Signed 8 bit integer.
388 * Thrift.Type.I16 -> "i16": Signed 16 bit integer.
389 * Thrift.Type.I32 -> "i32": Signed 32 bit integer.
390 * Thrift.Type.I64 -> "i64": Signed 64 bit integer.
391 * Thrift.Type.DOUBLE -> "dbl": 64 bit IEEE 854 floating point.
392 * Thrift.Type.STRUCT -> "rec": A multifield type.
393 * Thrift.Type.STRING -> "str": Array of bytes representing a string of characters.
394 * Thrift.Type.MAP -> "map": A collection type (map/associative-array/dictionary).
395 * Thrift.Type.LIST -> "lst": A collection type (unordered).
396 * Thrift.Type.SET -> "set": A collection type (unordered and without repeated values).
397 */
398 Type: { [k: number]: string };
399
400 /**
401 * Thrift IDL type string to Id mapping.
402 * The mapping table looks as follows:
403 * "tf" -> Thrift.Type.BOOL
404 * "i8" -> Thrift.Type.BYTE
405 * "i16" -> Thrift.Type.I16
406 * "i32" -> Thrift.Type.I32
407 * "i64" -> Thrift.Type.I64
408 * "dbl" -> Thrift.Type.DOUBLE
409 * "rec" -> Thrift.Type.STRUCT
410 * "str" -> Thrift.Type.STRING
411 * "map" -> Thrift.Type.MAP
412 * "lst" -> Thrift.Type.LIST
413 * "set" -> Thrift.Type.SET
414 */
415 RType: { [k: string]: number };
416
417 /**
418 * The TJSONProtocol version number.
419 */
420 Version: number;
421
422 /**
423 * Initializes a Thrift JSON protocol instance.
424 * @param {Thrift.Transport} transport - The transport to serialize to/from.
425 */
426 constructor(transport: Transport);
427
428 /**
429 * Returns the underlying transport.
430 * @returns {Thrift.Transport} The underlying transport.
431 */
432 getTransport(): Transport;
433
434 /**
435 * Serializes the beginning of a Thrift RPC message.
436 * @param {string} name - The service method to call.
437 * @param {Thrift.MessageType} messageType - The type of method call.
438 * @param {number} seqid - The sequence number of this call (always 0 in Apache Thrift).
439 */
440 writeMessageBegin(name: string, messageType: number, seqid: number): void;
441
442 /**
443 * Serializes the end of a Thrift RPC message.
444 */
445 writeMessageEnd(): void;
446
447 /**
448 * Serializes the beginning of a struct.
449 * @param {string} name - The name of the struct.
450 */
451 writeStructBegin(name?: string): void;
452
453 /**
454 * Serializes the end of a struct.
455 */
456 writeStructEnd(): void;
457
458 /**
459 * Serializes the beginning of a struct field.
460 * @param {string} name - The name of the field.
461 * @param {Thrift.Protocol.Type} fieldType - The data type of the field.
462 * @param {number} fieldId - The field's unique identifier.
463 */
464 writeFieldBegin(name: string, fieldType: string[], fieldId: number): void;
465
466 /**
467 * Serializes the end of a field.
468 */
469 writeFieldEnd(): void;
470
471 /**
472 * Serializes the end of the set of fields for a struct.
473 */
474 writeFieldStop(): void;
475
476 /**
477 * Serializes the beginning of a map collection.
478 * @param {Thrift.Type} keyType - The data type of the key.
479 * @param {Thrift.Type} valType - The data type of the value.
480 * @param {number} [size] - The number of elements in the map (ignored).
481 */
482 writeMapBegin(keyType: number, valType: number, size?: number): void;
483
484 /**
485 * Serializes the end of a map.
486 */
487 writeMapEnd(): void;
488
489 /**
490 * Serializes the beginning of a list collection.
491 * @param {Thrift.Type} elemType - The data type of the elements.
492 * @param {number} size - The number of elements in the list.
493 */
494 writeListBegin(elemType: number, size: number): void;
495
496 /**
497 * Serializes the end of a list.
498 */
499 writeListEnd(): void;
500
501 /**
502 * Serializes the beginning of a set collection.
503 * @param {Thrift.Type} elemType - The data type of the elements.
504 * @param {number} size - The number of elements in the list.
505 */
506 writeSetBegin(elemType: number, size: number): void;
507
508 /**
509 * Serializes the end of a set.
510 */
511 writeSetEnd(): void;
512
513 /** Serializes a boolean */
514 writeBool(value: boolean): void;
515
516 /** Serializes a number */
517 writeByte(i8: number): void;
518
519 /** Serializes a number */
520 writeI16(i16: number): void;
521
522 /** Serializes a number */
523 writeI32(i32: number): void;
524
525 /** Serializes a number */
526 writeI64(i64: number): void;
527
528 /** Serializes a number */
529 writeDouble(dbl: number): void;
530
531 /** Serializes a string */
532 writeString(str: string): void;
533
534 /** Serializes a string */
535 writeBinary(str: string): void;
536
537 /**
538 @class
539 @name AnonReadMessageBeginReturn
540 @property {string} fname - The name of the service method.
541 @property {Thrift.MessageType} mtype - The type of message call.
542 @property {number} rseqid - The sequence number of the message (0 in Thrift RPC).
543 */
544 /**
545 * Deserializes the beginning of a message.
546 * @returns {AnonReadMessageBeginReturn}
547 */
548 readMessageBegin(): { fname: string; mtype: number; rseqid: number };
549
550 /** Deserializes the end of a message. */
551 readMessageEnd(): void;
552
553 /**
554 * Deserializes the beginning of a struct.
555 * @param {string} [name] - The name of the struct (ignored).
556 * @returns {object} - An object with an empty string fname property.
557 */
558 readStructBegin(name?: string): any;
559
560 /** Deserializes the end of a struct. */
561 readStructEnd(): void;
562
563 /**
564 @class
565 @name AnonReadFieldBeginReturn
566 @property {string} fname - The name of the field (always '').
567 @property {Thrift.Type} ftype - The data type of the field.
568 @property {number} fid - The unique identifier of the field.
569 */
570 /**
571 * Deserializes the beginning of a field.
572 * @returns {AnonReadFieldBeginReturn}
573 */
574 readFieldBegin(): { fname: string; ftype: number; fid: number };
575
576 /** Deserializes the end of a field. */
577 readFieldEnd(): void;
578
579 /**
580 @class
581 @name AnonReadMapBeginReturn
582 @property {Thrift.Type} ktype - The data type of the key.
583 @property {Thrift.Type} vtype - The data type of the value.
584 @property {number} size - The number of elements in the map.
585 */
586 /**
587 * Deserializes the beginning of a map.
588 * @returns {AnonReadMapBeginReturn}
589 */
590 readMapBegin(): { ktype: number; vtype: number; size: number };
591
592 /** Deserializes the end of a map. */
593 readMapEnd(): void;
594
595 /**
596 @class
597 @name AnonReadColBeginReturn
598 @property {Thrift.Type} etype - The data type of the element.
599 @property {number} size - The number of elements in the collection.
600 */
601 /**
602 * Deserializes the beginning of a list.
603 * @returns {AnonReadColBeginReturn}
604 */
605 readListBegin(): { etype: number; size: number };
606
607 /** Deserializes the end of a list. */
608 readListEnd(): void;
609
610 /**
611 * Deserializes the beginning of a set.
612 * @param {Thrift.Type} elemType - The data type of the elements (ignored).
613 * @param {number} size - The number of elements in the list (ignored).
614 * @returns {AnonReadColBeginReturn}
615 */
616 readSetBegin(elemType?: number, size?: number): { etype: number; size: number };
617
618 /** Deserializes the end of a set. */
619 readSetEnd(): void;
620
621 /** Returns an object with a value property set to
622 * False unless the next number in the protocol buffer
623 * is 1, in which case the value property is True. */
624 readBool(): Object;
625
626 /** Returns an object with a value property set to the
627 next value found in the protocol buffer. */
628 readByte(): Object;
629
630 /** Returns an object with a value property set to the
631 next value found in the protocol buffer. */
632 readI16(): Object;
633
634 /** Returns an object with a value property set to the
635 next value found in the protocol buffer. */
636 readI32(f?: any): Object;
637
638 /** Returns an object with a value property set to the
639 next value found in the protocol buffer. */
640 readI64(): Object;
641
642 /** Returns an object with a value property set to the
643 next value found in the protocol buffer. */
644 readDouble(): Object;
645
646 /** Returns an object with a value property set to the
647 next value found in the protocol buffer. */
648 readString(): Object;
649
650 /** Returns an object with a value property set to the
651 next value found in the protocol buffer. */
652 readBinary(): Object;
653
654 /**
655 * Method to arbitrarily skip over data (not implemented).
656 */
657 skip(type: any): void;
658 }
659
660 /**
661 * Old alias of the TXHRTransport for backwards compatibility.
662 */
663 class Protocol extends TJSONProtocol { }
664
665 class MultiplexProtocol extends Protocol {
666 serviceName: string;
667
668 /**
669 * Initializes a MutilplexProtocol Implementation as a Wrapper for Thrift.Protocol.
670 * @param {string} srvName
671 * @param {Thrift.Transport} trans
672 * @param {any} [strictRead]
673 * @param {any} [strictWrite]
674 */
675 constructor(srvName: string, trans: Transport, strictRead?: any, strictWrite?: any);
676 }
677
678 class Multiplexer {
679 seqid: number;
680
681 /** Instantiates a multiplexed client for a specific service.
682 * @param {String} serviceName - The transport to serialize to/from.
683 * @param {Thrift.ServiceClient} SCl - The Service Client Class.
684 * @param {Thrift.Transport} transport - Thrift.Transport instance which provides remote host:port.
685 */
686 createClient(serviceName: string, SCl: any, transport: Transport);
687 }
688}