1/*
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: Object): 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    message: string;
151    code: number;
152
153    /**
154     * Initializes a Thrift TApplicationException instance.
155     * @param {string} message - The TApplicationException message (distinct from the Error message).
156     * @param {Thrift.TApplicationExceptionType} [code] - The TApplicationExceptionType code.
157     */
158    constructor(message: string, code?: number);
159
160    /**
161     * Read a TApplicationException from the supplied protocol.
162     * @param {object} input - The input protocol to read from.
163     */
164    read(input: Object): void;
165
166    /**
167     * Write a TApplicationException to the supplied protocol.
168     * @param {object} output - The output protocol to write to.
169     */
170    write(output: Object): void;
171
172    /**
173     * Returns the application exception code set on the exception.
174     * @returns {Thrift.TApplicationExceptionType} exception code
175     */
176    getCode(): number;
177  }
178
179  /**
180   * The Apache Thrift Transport layer performs byte level I/O between RPC
181   * clients and servers. The JavaScript Transport object type uses Http[s]/XHR and is
182   * the sole browser based Thrift transport. Target servers must implement the http[s]
183   * transport (see: node.js example server).
184   */
185  class TXHRTransport {
186    url: string;
187    wpos: number;
188    rpos: number;
189    useCORS: any;
190    send_buf: string;
191    recv_buf: string;
192
193    /**
194     * If you do not specify a url then you must handle XHR operations on
195     * your own. This type can also be constructed using the Transport alias
196     * for backward compatibility.
197     * @param {string} [url] - The URL to connect to.
198     * @param {object} [options] - Options.
199     */
200    constructor(url?: string, options?: Object);
201
202    /**
203     * Gets the browser specific XmlHttpRequest Object.
204     * @returns {object} the browser XHR interface object
205     */
206    getXmlHttpRequestObject(): Object;
207
208    /**
209     * Sends the current XRH request if the transport was created with a URL and
210     * the async parameter if false. If the transport was not created with a URL
211     * or the async parameter is True or the URL is an empty string, the current
212     * send buffer is returned.
213     * @param {object} async - If true the current send buffer is returned.
214     * @param {function} callback - Optional async completion callback.
215     * @returns {undefined|string} Nothing or the current send buffer.
216     */
217    flush(async: any, callback?: Function): string;
218
219    /**
220     * Creates a jQuery XHR object to be used for a Thrift server call.
221     * @param {object} client - The Thrift Service client object generated by the IDL compiler.
222     * @param {object} postData - The message to send to the server.
223     * @param {function} args - The function to call if the request succeeds.
224     * @param {function} recv_method - The Thrift Service Client receive method for the call.
225     * @returns {object} A new jQuery XHR object.
226     */
227    jqRequest(client: Object, postData: any, args: Function, recv_method: Function): Object;
228
229    /**
230     * Sets the buffer to use when receiving server responses.
231     * @param {string} buf - The buffer to receive server responses.
232     */
233    setRecvBuffer(buf: string): void;
234
235    /**
236     * Returns true if the transport is open, in browser based JavaScript
237     * this function always returns true.
238     * @returns {boolean} Always True.
239     */
240    isOpen(): boolean;
241
242    /**
243     * Opens the transport connection, in browser based JavaScript
244     * this function is a nop.
245     */
246    open(): void;
247
248    /**
249     * Closes the transport connection, in browser based JavaScript
250     * this function is a nop.
251     */
252    close(): void;
253
254    /**
255     * Returns the specified number of characters from the response
256     * buffer.
257     * @param {number} len - The number of characters to return.
258     * @returns {string} Characters sent by the server.
259     */
260    read(len: number): string;
261
262    /**
263     * Returns the entire response buffer.
264     * @returns {string} Characters sent by the server.
265     */
266    readAll(): string;
267
268    /**
269     * Sets the send buffer to buf.
270     * @param {string} buf - The buffer to send.
271     */
272    write(buf: string): void;
273
274    /**
275     * Returns the send buffer.
276     * @returns {string} The send buffer.
277     */
278    getSendBuffer(): string;
279  }
280
281  /**
282   * Old alias of the TXHRTransport for backwards compatibility.
283   */
284  class Transport extends TXHRTransport { }
285
286  /**
287   * The Apache Thrift Transport layer performs byte level I/O
288   * between RPC clients and servers. The JavaScript TWebSocketTransport object
289   * uses the WebSocket protocol. Target servers must implement WebSocket.
290   */
291  class TWebSocketTransport {
292    url: string;           //Where to connect
293    socket: any;           //The web socket
294    callbacks: Function[]; //Pending callbacks
295    send_pending: any[];   //Buffers/Callback pairs waiting to be sent
296    send_buf: string;      //Outbound data, immutable until sent
297    recv_buf: string;      //Inbound data
298    rb_wpos: number;       //Network write position in receive buffer
299    rb_rpos: number;       //Client read position in receive buffer
300
301    /**
302     * Constructor Function for the WebSocket transport.
303     * @param {string } [url] - The URL to connect to.
304     */
305    constructor(url: string);
306
307    __reset(url: string): void;
308
309    /**
310     * Sends the current WS request and registers callback. The async
311     * parameter is ignored (WS flush is always async) and the callback
312     * function parameter is required.
313     * @param {object} async - Ignored.
314     * @param {function} callback - The client completion callback.
315     * @returns {undefined|string} Nothing (undefined)
316     */
317    flush(async: any, callback: Function): string;
318
319    __onOpen(): void;
320
321    __onClose(): void;
322
323    __onMessage(): void;
324
325    __onError(): void;
326
327    /**
328     * Sets the buffer to use when receiving server responses.
329     * @param {string} buf - The buffer to receive server responses.
330     */
331    setRecvBuffer(buf: string): void;
332
333    /**
334     * Returns true if the transport is open
335     * @returns {boolean}
336     */
337    isOpen(): boolean;
338
339    /**
340     * Opens the transport connection
341     */
342    open(): void;
343
344    /**
345     * Closes the transport connection
346     */
347    close(): void;
348
349    /**
350     * Returns the specified number of characters from the response
351     * buffer.
352     * @param {number} len - The number of characters to return.
353     * @returns {string} Characters sent by the server.
354     */
355    read(len: number): string;
356
357    /**
358     * Returns the entire response buffer.
359     * @returns {string} Characters sent by the server.
360     */
361    readAll(): string;
362
363    /**
364     * Sets the send buffer to buf.
365     * @param {string} buf - The buffer to send.
366     */
367    write(buf: string): void;
368
369    /**
370     * Returns the send buffer.
371     * @returns {string} The send buffer.
372     */
373    getSendBuffer(): string;
374  }
375
376  /**
377   * Apache Thrift Protocols perform serialization which enables cross
378   * language RPC. The Protocol type is the JavaScript browser implementation
379   * of the Apache Thrift TJSONProtocol.
380   */
381  class TJSONProtocol {
382    transport: Object;
383
384    /**
385     * Thrift IDL type Id to string mapping.
386     * The mapping table looks as follows:
387     * Thrift.Type.BOOL   -> "tf": True/False integer.
388     * Thrift.Type.BYTE   -> "i8": Signed 8 bit integer.
389     * Thrift.Type.I16    -> "i16": Signed 16 bit integer.
390     * Thrift.Type.I32    -> "i32": Signed 32 bit integer.
391     * Thrift.Type.I64    -> "i64": Signed 64 bit integer.
392     * Thrift.Type.DOUBLE -> "dbl": 64 bit IEEE 854 floating point.
393     * Thrift.Type.STRUCT -> "rec": A multifield type.
394     * Thrift.Type.STRING -> "str": Array of bytes representing a string of characters.
395     * Thrift.Type.MAP    -> "map": A collection type (map/associative-array/dictionary).
396     * Thrift.Type.LIST   -> "lst": A collection type (unordered).
397     * Thrift.Type.SET    -> "set": A collection type (unordered and without repeated values).
398     */
399    Type: { [k: number]: string };
400
401    /**
402     * Thrift IDL type string to Id mapping.
403     * The mapping table looks as follows:
404     * "tf"  -> Thrift.Type.BOOL
405     * "i8"  -> Thrift.Type.BYTE
406     * "i16" -> Thrift.Type.I16
407     * "i32" -> Thrift.Type.I32
408     * "i64" -> Thrift.Type.I64
409     * "dbl" -> Thrift.Type.DOUBLE
410     * "rec" -> Thrift.Type.STRUCT
411     * "str" -> Thrift.Type.STRING
412     * "map" -> Thrift.Type.MAP
413     * "lst" -> Thrift.Type.LIST
414     * "set" -> Thrift.Type.SET
415     */
416    RType: { [k: string]: number };
417
418    /**
419     * The TJSONProtocol version number.
420     */
421    Version: number;
422
423    /**
424     * Initializes a Thrift JSON protocol instance.
425     * @param {Thrift.Transport} transport - The transport to serialize to/from.
426     */
427    constructor(transport: Object);
428
429    /**
430     * Returns the underlying transport.
431     * @returns {Thrift.Transport} The underlying transport.
432     */
433    getTransport(): Object;
434
435    /**
436     * Serializes the beginning of a Thrift RPC message.
437     * @param {string} name - The service method to call.
438     * @param {Thrift.MessageType} messageType - The type of method call.
439     * @param {number} seqid - The sequence number of this call (always 0 in Apache Thrift).
440     */
441    writeMessageBegin(name: string, messageType: number, seqid: number): void;
442
443    /**
444     * Serializes the end of a Thrift RPC message.
445     */
446    writeMessageEnd(): void;
447
448    /**
449     * Serializes the beginning of a struct.
450     * @param {string} name - The name of the struct.
451     */
452    writeStructBegin(name?: string): void;
453
454    /**
455     * Serializes the end of a struct.
456     */
457    writeStructEnd(): void;
458
459    /**
460     * Serializes the beginning of a struct field.
461     * @param {string} name - The name of the field.
462     * @param {Thrift.Protocol.Type} fieldType - The data type of the field.
463     * @param {number} fieldId - The field's unique identifier.
464     */
465    writeFieldBegin(name: string, fieldType: number, fieldId: number): void;
466
467    /**
468     * Serializes the end of a field.
469     */
470    writeFieldEnd(): void;
471
472    /**
473     * Serializes the end of the set of fields for a struct.
474     */
475    writeFieldStop(): void;
476
477    /**
478     * Serializes the beginning of a map collection.
479     * @param {Thrift.Type} keyType - The data type of the key.
480     * @param {Thrift.Type} valType - The data type of the value.
481     * @param {number} [size] - The number of elements in the map (ignored).
482     */
483    writeMapBegin(keyType: number, valType: number, size?: number): void;
484
485    /**
486     * Serializes the end of a map.
487     */
488    writeMapEnd(): void;
489
490    /**
491     * Serializes the beginning of a list collection.
492     * @param {Thrift.Type} elemType - The data type of the elements.
493     * @param {number} size - The number of elements in the list.
494     */
495    writeListBegin(elemType: number, size: number): void;
496
497    /**
498     * Serializes the end of a list.
499     */
500    writeListEnd(): void;
501
502    /**
503     * Serializes the beginning of a set collection.
504     * @param {Thrift.Type} elemType - The data type of the elements.
505     * @param {number} size - The number of elements in the list.
506     */
507    writeSetBegin(elemType: number, size: number): void;
508
509    /**
510     * Serializes the end of a set.
511     */
512    writeSetEnd(): void;
513
514    /** Serializes a boolean */
515    writeBool(value: boolean): void;
516
517    /** Serializes a number */
518    writeByte(i8: number): void;
519
520    /** Serializes a number */
521    writeI16(i16: number): void;
522
523    /** Serializes a number */
524    writeI32(i32: number): void;
525
526    /** Serializes a number */
527    writeI64(i64: number): void;
528
529    /** Serializes a number */
530    writeDouble(dbl: number): void;
531
532    /** Serializes a string */
533    writeString(str: string): void;
534
535    /** Serializes a string */
536    writeBinary(str: string): void;
537
538    /**
539       @class
540       @name AnonReadMessageBeginReturn
541       @property {string} fname - The name of the service method.
542       @property {Thrift.MessageType} mtype - The type of message call.
543       @property {number} rseqid - The sequence number of the message (0 in Thrift RPC).
544     */
545    /**
546     * Deserializes the beginning of a message.
547     * @returns {AnonReadMessageBeginReturn}
548     */
549    readMessageBegin(): { fname: string; mtype: number; rseqid: number };
550
551    /** Deserializes the end of a message. */
552    readMessageEnd(): void;
553
554    /**
555     * Deserializes the beginning of a struct.
556     * @param {string} [name] - The name of the struct (ignored).
557     * @returns {object} - An object with an empty string fname property.
558     */
559    readStructBegin(name?: string): { fname: string };
560
561    /** Deserializes the end of a struct. */
562    readStructEnd(): void;
563
564    /**
565       @class
566       @name AnonReadFieldBeginReturn
567       @property {string} fname - The name of the field (always '').
568       @property {Thrift.Type} ftype - The data type of the field.
569       @property {number} fid - The unique identifier of the field.
570     */
571    /**
572     * Deserializes the beginning of a field.
573     * @returns {AnonReadFieldBeginReturn}
574     */
575    readFieldBegin(): { fname: string; ftype: number; fid: number };
576
577    /** Deserializes the end of a field. */
578    readFieldEnd(): void;
579
580    /**
581       @class
582       @name AnonReadMapBeginReturn
583       @property {Thrift.Type} ktype - The data type of the key.
584       @property {Thrift.Type} vtype - The data type of the value.
585       @property {number} size - The number of elements in the map.
586     */
587    /**
588     * Deserializes the beginning of a map.
589     * @returns {AnonReadMapBeginReturn}
590     */
591    readMapBegin(): { ktype: number; vtype: number; size: number };
592
593    /** Deserializes the end of a map. */
594    readMapEnd(): void;
595
596    /**
597       @class
598       @name AnonReadColBeginReturn
599       @property {Thrift.Type} etype - The data type of the element.
600       @property {number} size - The number of elements in the collection.
601     */
602    /**
603     * Deserializes the beginning of a list.
604     * @returns {AnonReadColBeginReturn}
605     */
606    readListBegin(): { etype: number; size: number };
607
608    /** Deserializes the end of a list. */
609    readListEnd(): void;
610
611    /**
612     * Deserializes the beginning of a set.
613     * @param {Thrift.Type} elemType - The data type of the elements (ignored).
614     * @param {number} size - The number of elements in the list (ignored).
615     * @returns {AnonReadColBeginReturn}
616     */
617    readSetBegin(elemType?: number, size?: number): { etype: number; size: number };
618
619    /** Deserializes the end of a set. */
620    readSetEnd(): void;
621
622    /** Returns an object with a value property set to
623     *  False unless the next number in the protocol buffer
624     *  is 1, in which case the value property is True. */
625    readBool(): Object;
626
627    /** Returns an object with a value property set to the
628        next value found in the protocol buffer. */
629    readByte(): Object;
630
631    /** Returns an object with a value property set to the
632        next value found in the protocol buffer. */
633    readI16(): Object;
634
635    /** Returns an object with a value property set to the
636        next value found in the protocol buffer. */
637    readI32(f?: any): Object;
638
639    /** Returns an object with a value property set to the
640        next value found in the protocol buffer. */
641    readI64(): Object;
642
643    /** Returns an object with a value property set to the
644        next value found in the protocol buffer. */
645    readDouble(): Object;
646
647    /** Returns an object with a value property set to the
648        next value found in the protocol buffer. */
649    readString(): Object;
650
651    /** Returns an object with a value property set to the
652        next value found in the protocol buffer. */
653    readBinary(): Object;
654
655    /**
656     * Method to arbitrarily skip over data (not implemented).
657     */
658    skip(type: number): void;
659  }
660
661  /**
662   * Old alias of the TXHRTransport for backwards compatibility.
663   */
664  class Protocol extends TJSONProtocol { }
665
666  class MultiplexProtocol extends TJSONProtocol {
667    serviceName: string;
668
669    /**
670     * Initializes a MutilplexProtocol Implementation as a Wrapper for Thrift.Protocol.
671     * @param {string} srvName
672     * @param {Thrift.Transport} trans
673     * @param {any} [strictRead]
674     * @param {any} [strictWrite]
675     */
676    constructor(srvName: string, trans: Object, strictRead?: any, strictWrite?: any);
677
678    /**
679     * Override writeMessageBegin method of prototype
680     * Serializes the beginning of a Thrift RPC message.
681     * @param {string} name - The service method to call.
682     * @param {Thrift.MessageType} messageType - The type of method call.
683     * @param {number} seqid - The sequence number of this call (always 0 in Apache Thrift).
684     */
685    writeMessageBegin(name: string, type: number, seqid: number): void;
686  }
687
688  class Multiplexer {
689    seqid: number;
690
691    /**
692     * Instantiates a multiplexed client for a specific service.
693     * @param {String} serviceName - The transport to serialize to/from.
694     * @param {Thrift.ServiceClient} SCl - The Service Client Class.
695     * @param {Thrift.Transport} transport - Thrift.Transport instance which provides remote host:port.
696     */
697    createClient(serviceName: string, SCl: any, transport: Object): any;
698  }
699}
700