THRIFT-2901 Fix for generated TypeScript functions + indentation of JavaScript maps
diff --git a/compiler/cpp/src/generate/t_js_generator.cc b/compiler/cpp/src/generate/t_js_generator.cc
index 0fdde4d..755e7ae 100644
--- a/compiler/cpp/src/generate/t_js_generator.cc
+++ b/compiler/cpp/src/generate/t_js_generator.cc
@@ -539,7 +539,8 @@
t_type* ktype = ((t_map*)type)->get_key_type();
t_type* vtype = ((t_map*)type)->get_val_type();
- out << "{";
+ out << "{" << endl;
+ indent_up();
const map<t_const_value*, t_const_value*>& val = value->get_map();
map<t_const_value*, t_const_value*>::const_iterator v_iter;
@@ -547,12 +548,13 @@
if (v_iter != val.begin())
out << "," << endl;
- out << render_const_value(ktype, v_iter->first);
+ out << indent() << render_const_value(ktype, v_iter->first);
out << " : ";
out << render_const_value(vtype, v_iter->second);
}
+ indent_down();
out << endl << "}";
} else if (type->is_list() || type->is_set()) {
t_type* etype;
@@ -2024,13 +2026,13 @@
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
str += (*f_iter)->get_name() + ts_get_req(*f_iter) + ": " + ts_get_type((*f_iter)->get_type());
- if (f_iter + 1 != fields.end()) {
+ if (f_iter + 1 != fields.end() || include_callback) {
str += ", ";
}
}
if (include_callback) {
- str += ", callback: Function): ";
+ str += "callback: Function): ";
if (gen_jquery_) {
str += "JQueryXHR;";
diff --git a/lib/ts/thrift.d.ts b/lib/ts/thrift.d.ts
index 25ee5b0..7c5b9e4 100644
--- a/lib/ts/thrift.d.ts
+++ b/lib/ts/thrift.d.ts
@@ -84,7 +84,7 @@
* @param {object} obj - Object to test.
* @returns {number} number of object's own properties
*/
- function objectLength(obj: any): number;
+ function objectLength(obj: Object): number;
/**
* Utility function to establish prototype inheritance.
@@ -147,6 +147,7 @@
* TApplicationException is the exception class used to propagate exceptions from an RPC server back to a calling client.
*/
class TApplicationException extends TException {
+ message: string;
code: number;
/**
@@ -160,13 +161,13 @@
* Read a TApplicationException from the supplied protocol.
* @param {object} input - The input protocol to read from.
*/
- read(input: any): void;
+ read(input: Object): void;
/**
* Write a TApplicationException to the supplied protocol.
* @param {object} output - The output protocol to write to.
*/
- write(output: any): void;
+ write(output: Object): void;
/**
* Returns the application exception code set on the exception.
@@ -194,15 +195,15 @@
* your own. This type can also be constructed using the Transport alias
* for backward compatibility.
* @param {string} [url] - The URL to connect to.
- * @param {any} [options] - Options.
+ * @param {object} [options] - Options.
*/
- constructor(url?: string, options?: any);
+ constructor(url?: string, options?: Object);
/**
* Gets the browser specific XmlHttpRequest Object.
* @returns {object} the browser XHR interface object
*/
- getXmlHttpRequestObject(): any;
+ getXmlHttpRequestObject(): Object;
/**
* Sends the current XRH request if the transport was created with a URL and
@@ -210,7 +211,7 @@
* or the async parameter is True or the URL is an empty string, the current
* send buffer is returned.
* @param {object} async - If true the current send buffer is returned.
- * @param {object} callback - Optional async completion callback.
+ * @param {function} callback - Optional async completion callback.
* @returns {undefined|string} Nothing or the current send buffer.
*/
flush(async: any, callback?: Function): string;
@@ -223,7 +224,7 @@
* @param {function} recv_method - The Thrift Service Client receive method for the call.
* @returns {object} A new jQuery XHR object.
*/
- jqRequest(client: any, postData: any, args: Function, recv_method: Function): any;
+ jqRequest(client: Object, postData: any, args: Function, recv_method: Function): Object;
/**
* Sets the buffer to use when receiving server responses.
@@ -290,7 +291,7 @@
class TWebSocketTransport {
url: string; //Where to connect
socket: any; //The web socket
- callbacks: any[]; //Pending callbacks
+ callbacks: Function[]; //Pending callbacks
send_pending: any[]; //Buffers/Callback pairs waiting to be sent
send_buf: string; //Outbound data, immutable until sent
recv_buf: string; //Inbound data
@@ -310,10 +311,10 @@
* parameter is ignored (WS flush is always async) and the callback
* function parameter is required.
* @param {object} async - Ignored.
- * @param {object} callback - The client completion callback.
+ * @param {function} callback - The client completion callback.
* @returns {undefined|string} Nothing (undefined)
*/
- flush(async: any, callback: any): string;
+ flush(async: any, callback: Function): string;
__onOpen(): void;
@@ -378,7 +379,7 @@
* of the Apache Thrift TJSONProtocol.
*/
class TJSONProtocol {
- transport: Transport;
+ transport: Object;
/**
* Thrift IDL type Id to string mapping.
@@ -423,13 +424,13 @@
* Initializes a Thrift JSON protocol instance.
* @param {Thrift.Transport} transport - The transport to serialize to/from.
*/
- constructor(transport: Transport);
+ constructor(transport: Object);
/**
* Returns the underlying transport.
* @returns {Thrift.Transport} The underlying transport.
*/
- getTransport(): Transport;
+ getTransport(): Object;
/**
* Serializes the beginning of a Thrift RPC message.
@@ -461,7 +462,7 @@
* @param {Thrift.Protocol.Type} fieldType - The data type of the field.
* @param {number} fieldId - The field's unique identifier.
*/
- writeFieldBegin(name: string, fieldType: string[], fieldId: number): void;
+ writeFieldBegin(name: string, fieldType: number, fieldId: number): void;
/**
* Serializes the end of a field.
@@ -555,7 +556,7 @@
* @param {string} [name] - The name of the struct (ignored).
* @returns {object} - An object with an empty string fname property.
*/
- readStructBegin(name?: string): any;
+ readStructBegin(name?: string): { fname: string };
/** Deserializes the end of a struct. */
readStructEnd(): void;
@@ -654,7 +655,7 @@
/**
* Method to arbitrarily skip over data (not implemented).
*/
- skip(type: any): void;
+ skip(type: number): void;
}
/**
@@ -662,7 +663,7 @@
*/
class Protocol extends TJSONProtocol { }
- class MultiplexProtocol extends Protocol {
+ class MultiplexProtocol extends TJSONProtocol {
serviceName: string;
/**
@@ -672,17 +673,27 @@
* @param {any} [strictRead]
* @param {any} [strictWrite]
*/
- constructor(srvName: string, trans: Transport, strictRead?: any, strictWrite?: any);
+ constructor(srvName: string, trans: Object, strictRead?: any, strictWrite?: any);
+
+ /**
+ * Override writeMessageBegin method of prototype
+ * Serializes the beginning of a Thrift RPC message.
+ * @param {string} name - The service method to call.
+ * @param {Thrift.MessageType} messageType - The type of method call.
+ * @param {number} seqid - The sequence number of this call (always 0 in Apache Thrift).
+ */
+ writeMessageBegin(name: string, type: number, seqid: number): void;
}
class Multiplexer {
seqid: number;
- /** Instantiates a multiplexed client for a specific service.
+ /**
+ * Instantiates a multiplexed client for a specific service.
* @param {String} serviceName - The transport to serialize to/from.
* @param {Thrift.ServiceClient} SCl - The Service Client Class.
* @param {Thrift.Transport} transport - Thrift.Transport instance which provides remote host:port.
- */
- createClient(serviceName: string, SCl: any, transport: Transport);
+ */
+ createClient(serviceName: string, SCl: any, transport: Object);
}
}
\ No newline at end of file