Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ADVANCED_OPTIMIZATIONS in Closure Compiler #422

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions javascript/net/grpc/web/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ goog.module.declareLegacyNamespace();



/**
* @typedef {{
* code: (number|undefined),
* message: (string|undefined),
* }}
*/
let Error;
/** @record */
function Error() {}

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

/** @export {(string|undefined)} */
Error.prototype.message;

exports = Error;
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
10 changes: 6 additions & 4 deletions javascript/net/grpc/web/grpcwebclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {
var grpcStatusCode = self.xhr_.getStreamingResponseHeader(GRPC_STATUS);
var grpcStatusMessage = self.xhr_.getStreamingResponseHeader(GRPC_STATUS_MESSAGE);
if (grpcStatusCode && self.onStatusCallback_) {
self.onStatusCallback_({
self.onStatusCallback_(/** @type {!Status} */({
code: Number(grpcStatusCode),
details: grpcStatusMessage || '',
metadata: undefined,
});
}));
}

if (googString.startsWith(contentType, 'application/grpc-web-text')) {
Expand Down Expand Up @@ -174,11 +174,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 @@ -217,6 +217,7 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {

/**
* @override
* @export
*/
GrpcWebClientReadableStream.prototype.on = function(
eventType, callback) {
Expand Down Expand Up @@ -248,6 +249,7 @@ GrpcWebClientReadableStream.prototype.setResponseDeserializeFn =

/**
* @override
* @export
*/
GrpcWebClientReadableStream.prototype.cancel = function() {
this.xhr_.abort();
Expand Down
21 changes: 13 additions & 8 deletions javascript/net/grpc/web/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ goog.module.declareLegacyNamespace();



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

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

/** @export {string} */
Status.prototype.details;

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

exports.Status = Status;
34 changes: 17 additions & 17 deletions javascript/net/grpc/web/statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,51 @@ goog.module.declareLegacyNamespace();
*/
const StatusCode = {
// Not an error; returned on success.
OK: 0,
'OK': 0,

// The operation was cancelled (typically by the caller).
CANCELLED: 1,
'CANCELLED': 1,

// Unknown error. An example of where this error may be returned is if a
// Status value received from another address space belongs to an error-space
// that is not known in this address space. Also errors raised by APIs that
// do not return enough error information may be converted to this error.
UNKNOWN: 2,
'UNKNOWN': 2,

// Client specified an invalid argument. Note that this differs from
// FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
// problematic regardless of the state of the system (e.g., a malformed file
// name).
INVALID_ARGUMENT: 3,
'INVALID_ARGUMENT': 3,

// Deadline expired before operation could complete. For operations that
// change the state of the system, this error may be returned even if the
// operation has completed successfully. For example, a successful response
// from a server could have been delayed long enough for the deadline to
// expire.
DEADLINE_EXCEEDED: 4,
'DEADLINE_EXCEEDED': 4,

// Some requested entity (e.g., file or directory) was not found.
NOT_FOUND: 5,
'NOT_FOUND': 5,

// Some entity that we attempted to create (e.g., file or directory) already
// exists.
ALREADY_EXISTS: 6,
'ALREADY_EXISTS': 6,

// The caller does not have permission to execute the specified operation.
// PERMISSION_DENIED must not be used for rejections caused by exhausting
// some resource (use RESOURCE_EXHAUSTED instead for those errors).
// PERMISSION_DENIED must not be used if the caller can not be identified
// (use UNAUTHENTICATED instead for those errors).
PERMISSION_DENIED: 7,
'PERMISSION_DENIED': 7,

// The request does not have valid authentication credentials for the
// operation.
UNAUTHENTICATED: 16,
'UNAUTHENTICATED': 16,

// Some resource has been exhausted, perhaps a per-user quota, or perhaps the
// entire file system is out of space.
RESOURCE_EXHAUSTED: 8,
'RESOURCE_EXHAUSTED': 8,

// Operation was rejected because the system is not in a state required for
// the operation's execution. For example, directory to be deleted may be
Expand All @@ -99,14 +99,14 @@ const StatusCode = {
// REST Get/Update/Delete on a resource and the resource on the
// server does not match the condition. E.g., conflicting
// read-modify-write on the same resource.
FAILED_PRECONDITION: 9,
'FAILED_PRECONDITION': 9,

// The operation was aborted, typically due to a concurrency issue like
// sequencer check failures, transaction aborts, etc.
//
// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
// and UNAVAILABLE.
ABORTED: 10,
'ABORTED': 10,

// Operation was attempted past the valid range. E.g., seeking or reading
// past end of file.
Expand All @@ -121,24 +121,24 @@ const StatusCode = {
// OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
// when it applies so that callers who are iterating through a space can
// easily look for an OUT_OF_RANGE error to detect when they are done.
OUT_OF_RANGE: 11,
'OUT_OF_RANGE': 11,

// Operation is not implemented or not supported/enabled in this service.
UNIMPLEMENTED: 12,
'UNIMPLEMENTED': 12,

// Internal errors. Means some invariants expected by underlying System has
// been broken. If you see one of these errors, Something is very broken.
INTERNAL: 13,
'INTERNAL': 13,

// The service is currently unavailable. This is a most likely a transient
// condition and may be corrected by retrying with a backoff.
//
// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
// and UNAVAILABLE.
UNAVAILABLE: 14,
'UNAVAILABLE': 14,

// Unrecoverable data loss or corruption.
DATA_LOSS: 15,
'DATA_LOSS': 15,
};


Expand Down
2 changes: 2 additions & 0 deletions javascript/net/grpc/web/streambodyclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const StreamBodyClientReadableStream = function(genericTransportInterface) {

/**
* @override
* @export
*/
StreamBodyClientReadableStream.prototype.on = function(
eventType, callback) {
Expand Down Expand Up @@ -182,6 +183,7 @@ StreamBodyClientReadableStream.prototype.setRpcStatusParseFn = function(rpcStatu

/**
* @override
* @export
*/
StreamBodyClientReadableStream.prototype.cancel = function() {
this.xhr_.abort();
Expand Down
17 changes: 17 additions & 0 deletions packages/grpc-web/exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @fileoverview Export symbols needed by generated code in CommonJS style.
*
* Note that public methods called by generated code are exposed
* using Closure Compiler's @export annotation
*/
goog.module('grpc.web.Exports');

const AbstractClientBase = goog.require('grpc.web.AbstractClientBase');
const GrpcWebClientBase = goog.require('grpc.web.GrpcWebClientBase');
const StatusCode = goog.require('grpc.web.StatusCode');

const exports = module['exports'];

exports['AbstractClientBase'] = {'MethodInfo': AbstractClientBase.MethodInfo};
exports['GrpcWebClientBase'] = GrpcWebClientBase;
exports['StatusCode'] = StatusCode;
1 change: 1 addition & 0 deletions packages/grpc-web/externs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var 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=externs.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
39 changes: 39 additions & 0 deletions packages/grpc-web/test/export_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const assert = require('assert');
const grpc = {};
grpc.web = require('grpc-web');

describe('grpc-web export test', function() {
it('should have AbstractClientBase.MethodInfo exported', function() {
assert.equal(typeof grpc.web.AbstractClientBase.MethodInfo, 'function');
});

it('should have GrpcWebClientBase#rpcCall() exported', function() {
assert.equal(typeof grpc.web.GrpcWebClientBase.prototype.rpcCall, 'function');
});

it('should have GrpcWebClientBase#serverStreaming() exported', function() {
assert.equal(typeof grpc.web.GrpcWebClientBase.prototype.serverStreaming, 'function');
});

it('should have grpc StatusCode exported', function() {
assert.deepEqual(grpc.web.StatusCode, {
ABORTED: 10,
ALREADY_EXISTS: 6,
CANCELLED: 1,
DATA_LOSS: 15,
DEADLINE_EXCEEDED: 4,
FAILED_PRECONDITION: 9,
INTERNAL: 13,
INVALID_ARGUMENT: 3,
NOT_FOUND: 5,
OK: 0,
OUT_OF_RANGE: 11,
PERMISSION_DENIED: 7,
RESOURCE_EXHAUSTED: 8,
UNAUTHENTICATED: 16,
UNAVAILABLE: 14,
UNIMPLEMENTED: 12,
UNKNOWN: 2
});
});
});