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

Add grpc.web.ClientOptions to better document options and add type restrictions #971

Merged
merged 1 commit into from
Oct 12, 2020
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
12 changes: 12 additions & 0 deletions javascript/net/grpc/web/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ closure_js_library(
visibility = ["//visibility:public"],
)

closure_js_library(
name = "clientoptions",
srcs = [
"clientoptions.js",
],
visibility = ["//visibility:public"],
deps = [
":interceptor",
],
)

closure_js_library(
name = "clientreadablestream",
srcs = [
Expand Down Expand Up @@ -106,6 +117,7 @@ closure_js_library(
visibility = ["//visibility:public"],
deps = [
":abstractclientbase",
":clientoptions",
":clientreadablestream",
":clientunarycallimpl",
":error",
Expand Down
50 changes: 50 additions & 0 deletions javascript/net/grpc/web/clientoptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
goog.module('grpc.web.ClientOptions');
goog.module.declareLegacyNamespace();

const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor');


/**
* Options that are availavle during the client construction.
* @record
*/
class ClientOptions {
constructor() {
/**
* Whether to use the HttpCors library to pack http headers into a special
* url query param $httpHeaders= so that browsers can bypass CORS OPTIONS
* requests.
* @type {boolean|undefined}
*/
this.suppressCorsPreflight;

/**
* Whether to turn on XMLHttpRequest's withCredentials flag.
* @type {boolean|undefined}
*/
this.withCredentials;

/**
* Unary interceptors. Note that they are only available in grpcweb and
* grpcwebtext mode
* @type {!Array<!UnaryInterceptor>|undefined}
*/
this.unaryInterceptors;

/**
* Stream interceptors. Note that they are only available in grpcweb and
* grpcwebtext mode
* @type {!Array<!StreamInterceptor>|undefined}
*/
this.streamInterceptors;

/**
* Protocol buffer format for open source gRPC-Web. This attribute should be
* specified by the gRPC-Web build rule by default.
* @type {string|undefined}
*/
this.format;
}
}

exports = ClientOptions;
5 changes: 3 additions & 2 deletions javascript/net/grpc/web/grpcwebclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ goog.module.declareLegacyNamespace();


const AbstractClientBase = goog.require('grpc.web.AbstractClientBase');
const ClientOptions = goog.requireType('grpc.web.ClientOptions');
const ClientReadableStream = goog.require('grpc.web.ClientReadableStream');
const ClientUnaryCallImpl = goog.require('grpc.web.ClientUnaryCallImpl');
const Error = goog.require('grpc.web.Error');
Expand All @@ -52,9 +53,9 @@ const {StreamInterceptor, UnaryInterceptor} = goog.require('grpc.web.Interceptor
*/
class GrpcWebClientBase {
/**
* @param {?Object=} options
* @param {!ClientOptions=} options
*/
constructor(options) {
constructor(options = {}) {
/**
* @const
* @private {string}
Expand Down
6 changes: 3 additions & 3 deletions javascript/net/grpc/web/streambodyclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ class StreamBodyClientReadableStream {
if (grpcStatus == StatusCode.OK) {
this.sendDataCallbacks_(responseMessage);
} else {
callback(
this.sendErrorCallbacks_(
/** @type {!GrpcWebError} */ ({
code: grpcStatus,
}),
responseMessage);
message: response,
}));
}
} else {
let rawResponse;
Expand Down