Skip to content

Commit

Permalink
Enable ADVANCED_OPTIMIZATIONS in Closure Compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbubudi committed Dec 27, 2018
1 parent 09604c4 commit 20a2d9e
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 35 deletions.
9 changes: 6 additions & 3 deletions javascript/net/grpc/web/abstractclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ const AbstractClientBase = function() {};
* @param {function(new: RESPONSE, ...)} responseType
* @param {function(REQUEST): ?} requestSerializeFn
* @param {function(?): RESPONSE} responseDeserializeFn
* @export
*/
AbstractClientBase.MethodInfo = function(
responseType,
requestSerializeFn,
responseDeserializeFn) {
/** @const */
/** @const @export */
this.responseType = responseType;
/** @const */
/** @const @export */
this.requestSerializeFn = requestSerializeFn;
/** @const */
/** @const @export */
this.responseDeserializeFn = responseDeserializeFn;
};

Expand All @@ -81,6 +82,7 @@ AbstractClientBase.MethodInfo = function(
* callback A callback function which takes (error, response)
* @return {!ClientReadableStream<RESPONSE_LEAN>|undefined}
* The Client Readable Stream
* @export
*/
AbstractClientBase.prototype.rpcCall = goog.abstractMethod;

Expand All @@ -93,6 +95,7 @@ AbstractClientBase.prototype.rpcCall = goog.abstractMethod;
* @param {!AbstractClientBase.MethodInfo<REQUEST, RESPONSE>}
* methodInfo Information of this RPC method
* @return {!ClientReadableStream<RESPONSE>} The Client Readable Stream
* @export
*/
AbstractClientBase.prototype.serverStreaming = goog.abstractMethod;

Expand Down
2 changes: 2 additions & 0 deletions javascript/net/grpc/web/clientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ const ClientReadableStream = function() {};
* @param {function(?)} callback The call back to handle the event with
* an optional input object
* @return {!ClientReadableStream} this object
* @export
*/
ClientReadableStream.prototype.on = goog.abstractMethod;



/**
* Close the stream.
* @export
*/
ClientReadableStream.prototype.cancel = goog.abstractMethod;

Expand Down
13 changes: 6 additions & 7 deletions javascript/net/grpc/web/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ goog.module('grpc.web.Error');

goog.module.declareLegacyNamespace();

/** @record */
function Error() {}

/** @export @type {(number|undefined)} */
Error.prototype.code;

/**
* @typedef {{
* code: (number|undefined),
* message: (string|undefined),
* }}
*/
let Error;
/** @export @type {(string|undefined)} */
Error.prototype.message;

exports = Error;
4 changes: 4 additions & 0 deletions javascript/net/grpc/web/gatewayclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ const {Status} = goog.require('grpc.web.Status');
* @param {?Object=} opt_options
* @constructor
* @implements {AbstractClientBase}
* @export
*/
const GatewayClientBase = function(opt_options) {
};


/**
* @override
* @export
*/
GatewayClientBase.prototype.rpcCall = function(
method, request, metadata, methodInfo, callback) {
Expand Down Expand Up @@ -90,6 +92,7 @@ GatewayClientBase.prototype.rpcCall = function(

/**
* @override
* @export
*/
GatewayClientBase.prototype.serverStreaming = function(
method, request, metadata, methodInfo) {
Expand Down Expand Up @@ -176,6 +179,7 @@ GatewayClientBase.parseRpcStatus_ = function(data) {
pair.getSecond_asU8());
metadata[first] = second;
}
/** @type {!Status} */
var status = {
code: rpcStatus.getCode(),
details: rpcStatus.getMessage(),
Expand Down
2 changes: 2 additions & 0 deletions javascript/net/grpc/web/grpcwebclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const GrpcWebClientBase = function(opt_options) {

/**
* @override
* @export
*/
GrpcWebClientBase.prototype.rpcCall = function(
method, request, metadata, methodInfo, callback) {
Expand Down Expand Up @@ -116,6 +117,7 @@ GrpcWebClientBase.prototype.rpcCall = function(

/**
* @override
* @export
*/
GrpcWebClientBase.prototype.serverStreaming = function(
method, request, metadata, methodInfo) {
Expand Down
9 changes: 6 additions & 3 deletions javascript/net/grpc/web/grpcwebclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const events = goog.require('goog.events');
const googCrypt = goog.require('goog.crypt.base64');
const googString = goog.require('goog.string');
const {GenericTransportInterface} = goog.require('grpc.web.GenericTransportInterface');
const {Status} = goog.require('grpc.web.Status');
const Status = goog.require('grpc.web.Status');



Expand Down Expand Up @@ -164,11 +164,11 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {
grpcStatusMessage = trailers[GRPC_STATUS_MESSAGE];
}
if (self.onStatusCallback_) {
self.onStatusCallback_({
self.onStatusCallback_(/** @type {!Status} */({
code: Number(grpcStatusCode),
details: grpcStatusMessage,
metadata: trailers,
});
}));
}
}
}
Expand Down Expand Up @@ -207,6 +207,7 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {

/**
* @override
* @export
*/
GrpcWebClientReadableStream.prototype.on = function(
eventType, callback) {
Expand All @@ -229,6 +230,7 @@ GrpcWebClientReadableStream.prototype.on = function(
*
* @param {function(?):!RESPONSE} responseDeserializeFn The deserialize
* function for the proto
* @export
*/
GrpcWebClientReadableStream.prototype.setResponseDeserializeFn =
function(responseDeserializeFn) {
Expand All @@ -238,6 +240,7 @@ GrpcWebClientReadableStream.prototype.setResponseDeserializeFn =

/**
* @override
* @export
*/
GrpcWebClientReadableStream.prototype.cancel = function() {
this.xhr_.abort();
Expand Down
1 change: 1 addition & 0 deletions javascript/net/grpc/web/grpcwebstreamparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Parser.State_ = {
/**
* Possible frame byte
* @enum {number}
* @export
*/
GrpcWebStreamParser.FrameType = {
DATA: 0x00, // expecting a data frame
Expand Down
19 changes: 11 additions & 8 deletions javascript/net/grpc/web/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ goog.module('grpc.web.Status');

goog.module.declareLegacyNamespace();

/** @record */
function Status() {}

/** @export @type {number} */
Status.prototype.code;

/**
* @typedef {{
* code: number,
* details: string,
* metadata: (!Object<string, string>|undefined)
* }}
*/
exports.Status;
/** @export @type {string} */
Status.prototype.details;

/** @export @type {(!Object<string, string>|undefined)} */
Status.prototype.metadata;

exports = Status;
1 change: 1 addition & 0 deletions javascript/net/grpc/web/statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const StatusCode = {
* Convert HTTP Status code to gRPC Status code
* @param {number} http_status HTTP Status Code
* @return {number} gRPC Status Code
* @export
*/
StatusCode.fromHttpStatus = function(http_status) {
switch (http_status) {
Expand Down
5 changes: 5 additions & 0 deletions javascript/net/grpc/web/streambodyclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const {Status} = goog.require('grpc.web.Status');
* @final
* @param {!GenericTransportInterface} genericTransportInterface The
* GenericTransportInterface
* @export
*/
const StreamBodyClientReadableStream = function(genericTransportInterface) {
/**
Expand Down Expand Up @@ -139,6 +140,7 @@ const StreamBodyClientReadableStream = function(genericTransportInterface) {

/**
* @override
* @export
*/
StreamBodyClientReadableStream.prototype.on = function(
eventType, callback) {
Expand All @@ -161,6 +163,7 @@ StreamBodyClientReadableStream.prototype.on = function(
*
* @param {function(?): RESPONSE} responseDeserializeFn The deserialize
* function for the proto
* @export
*/
StreamBodyClientReadableStream.prototype.setResponseDeserializeFn =
function(responseDeserializeFn) {
Expand All @@ -174,6 +177,7 @@ StreamBodyClientReadableStream.prototype.setResponseDeserializeFn =
*
* @param {function(?):!Status} rpcStatusParseFn A function to parse
* the RPC status response
* @export
*/
StreamBodyClientReadableStream.prototype.setRpcStatusParseFn = function(rpcStatusParseFn) {
this.rpcStatusParseFn_ = rpcStatusParseFn;
Expand All @@ -182,6 +186,7 @@ StreamBodyClientReadableStream.prototype.setRpcStatusParseFn = function(rpcStatu

/**
* @override
* @export
*/
StreamBodyClientReadableStream.prototype.cancel = function() {
this.xhr_.abort();
Expand Down
3 changes: 3 additions & 0 deletions javascript/net/grpc/web/util/genericpbjsclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var GatewayClientBase = goog.require('grpc.web.GatewayClientBase');
* @constructor
* @struct
* @final
* @export
*/
var GenericPbjsClient = function(hostname) {

Expand All @@ -62,6 +63,7 @@ var GenericPbjsClient = function(hostname) {
*
* @param {!Object} method The method (a Protobuf.js Method object)
* @return {string} The full name of the service containing the method
* @export
*/
function getServiceName(method) {
var fullName = method.parent.fullName;
Expand All @@ -80,6 +82,7 @@ function getServiceName(method) {
* @param {!Object<string, string>} metadata User defined call metadata
* @param {function(?Error, ?Object)} callback A callback function
* which takes (error, response)
* @export
*/
GenericPbjsClient.prototype.rpcCall = function(
method, request, metadata, callback) {
Expand Down
21 changes: 21 additions & 0 deletions packages/grpc-web/exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
goog.module('grpc.web.Exports');

const AbstractClientBase = goog.require('grpc.web.AbstractClientBase');
const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const Error = goog.require('grpc.web.Error');
const GrpcWebClientBase = goog.require('grpc.web.GrpcWebClientBase');
const GrpcWebClientReadableStream = goog.require('grpc.web.GrpcWebClientReadableStream');
const GrpcWebStreamParser = goog.require('grpc.web.GrpcWebStreamParser');
const Status = goog.require('grpc.web.Status');
const StatusCode = goog.require('grpc.web.StatusCode');

const exports = module['exports'];
exports['AbstractClientBase'] = AbstractClientBase;
exports['AbstractClientBase']['MethodInfo'] = AbstractClientBase.MethodInfo;
exports['ClientReadableStream'] = ClientReadableStream;
exports['Error'] = Error;
exports['GrpcWebClientBase'] = GrpcWebClientBase;
exports['GrpcWebClientReadableStream'] = GrpcWebClientReadableStream;
exports['GrpcWebStreamParser'] = GrpcWebStreamParser;
exports['Status'] = Status;
exports['StatusCode'] = StatusCode;
2 changes: 2 additions & 0 deletions packages/grpc-web/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Tells Closure Compiler that "module" is externally defined
let module;
20 changes: 6 additions & 14 deletions packages/grpc-web/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,21 @@ const cwd = process.cwd();
const indexPath = path.relative(cwd, path.resolve(__dirname, "../index.js"));

const jsPaths = [
"../exports.js",
"../../../javascript",
"../../../third_party/closure-library",
"../../../third_party/grpc/third_party/protobuf/js",
].map(jsPath => path.relative(cwd, path.resolve(__dirname, jsPath)));

const grpcWebExports = [
"grpc.web.AbstractClientBase",
"grpc.web.ClientReadableStream",
"grpc.web.Error",
"grpc.web.GrpcWebClientBase",
"grpc.web.GrpcWebClientReadableStream",
"grpc.web.GrpcWebStreamParser",
"grpc.web.Status",
"grpc.web.StatusCode",
];

const closureArgs = [].concat(
jsPaths.map(jsPath => `--js=${jsPath}`),
grpcWebExports.map(grpcWebExport => `--entry_point=${grpcWebExport}`),
[
`--entry_point=grpc.web.Exports`,
`--externs=module.js`,
`--dependency_mode=STRICT`,
`--compilation_level=ADVANCED_OPTIMIZATIONS`,
`--generate_exports`,
`--export_local_property_definitions`,
`--js_output_file=${indexPath}`,
`--output_wrapper="%output%module.exports = grpc.web;"`,
]
);

Expand Down

0 comments on commit 20a2d9e

Please sign in to comment.