Skip to content

Commit

Permalink
Introduce grpc.web.ClientReadableStreamDelegate
Browse files Browse the repository at this point in the history
This CL introduces |grpc.web.ClientReadableStreamDelegate|, a type-safe
alternative to |grpc.web.ClientReadableStream.prototype.on|.
  • Loading branch information
Yannic committed Aug 22, 2018
1 parent caee772 commit ffbedfe
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 119 deletions.
131 changes: 101 additions & 30 deletions javascript/net/grpc/web/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cc_binary(
"grpc_generator.cc",
],
deps = [
"@com_google_protobuf//:protoc_lib"
"@com_google_protobuf//:protoc_lib",
],
)

Expand All @@ -30,6 +30,35 @@ closure_js_library(
srcs = [
"clientreadablestream.js",
],
deps = [
":clientreadablestreamdelegate",
],
)

closure_js_library(
name = "clientreadablestreamdelegate",
srcs = [
"clientreadablestreamdelegate.js",
],
deps = [
":error",
":status",
],
)

closure_js_library(
name = "defaultclientreadablestreamdelegate",
srcs = [
"defaultclientreadablestreamdelegate.js",
],
suppress = [
"reportUnknownTypes",
],
deps = [
":clientreadablestreamdelegate",
":error",
":status",
],
)

closure_js_library(
Expand All @@ -45,8 +74,8 @@ closure_js_library(
"generictransportinterface.js",
],
deps = [
"@io_bazel_rules_closure//closure/library/net/streams:nodereadablestream",
"@io_bazel_rules_closure//closure/library/net:xhrio",
"@io_bazel_rules_closure//closure/library/net/streams:nodereadablestream",
],
)

Expand All @@ -69,28 +98,55 @@ closure_js_library(
],
)

closure_js_test(
name = "grpcwebclientbase_test",
srcs = [
"grpcwebclientbase_test.js",
],
entry_points = [
"goog:grpc.web.GrpcWebClientBaseTest",
],
suppress = [
"visibility",
"checkTypes",
"deprecated",
"reportUnknownTypes",
"strictCheckTypes",
],
deps = [
":grpcwebclientbase",
"@io_bazel_rules_closure//closure/library/crypt:base64",
"@io_bazel_rules_closure//closure/library/events",
"@io_bazel_rules_closure//closure/library/structs:map",
"@io_bazel_rules_closure//closure/library/testing:jsunit",
"@io_bazel_rules_closure//closure/library/testing:testsuite",
],
)

closure_js_library(
name = "grpcwebclientreadablestream",
srcs = [
"grpcwebclientreadablestream.js",
],
suppress = [
"reportUnknownTypes",
],
deps = [
":clientreadablestream",
":clientreadablestreamdelegate",
":defaultclientreadablestreamdelegate",
":generictransportinterface",
":grpcwebstreamparser",
":status",
":statuscode",
"@io_bazel_rules_closure//closure/library/asserts",
"@io_bazel_rules_closure//closure/library/crypt:base64",
"@io_bazel_rules_closure//closure/library/events:events",
"@io_bazel_rules_closure//closure/library/events",
"@io_bazel_rules_closure//closure/library/net:errorcode",
"@io_bazel_rules_closure//closure/library/net:eventtype",
"@io_bazel_rules_closure//closure/library/net:xhrio",
"@io_bazel_rules_closure//closure/library/net:xmlhttp",
"@io_bazel_rules_closure//closure/library/string",
],
suppress = [
"reportUnknownTypes",
],
)

closure_js_library(
Expand All @@ -107,6 +163,24 @@ closure_js_library(
],
)

closure_js_test(
name = "grpcwebstreamparser_test",
srcs = [
"grpcwebstreamparser_test.js",
],
entry_points = [
"goog:grpc.web.GrpcWebStreamParserTest",
],
suppress = [
"reportUnknownTypes",
],
deps = [
":grpcwebstreamparser",
"@io_bazel_rules_closure//closure/library/testing:jsunit",
"@io_bazel_rules_closure//closure/library/testing:testsuite",
],
)

closure_js_library(
name = "status",
srcs = [
Expand All @@ -121,43 +195,40 @@ closure_js_library(
],
)

closure_js_test(
name = "grpcwebclientbase_test",
closure_js_library(
name = "streambodyclientreadablestream",
srcs = [
"grpcwebclientbase_test.js",
],
entry_points = [
"goog:grpc.web.GrpcWebClientBaseTest",
"streambodyclientreadablestream.js",
],
suppress = [
"visibility",
"checkTypes",
"deprecated",
"reportUnknownTypes",
"strictCheckTypes",
],
deps = [
"@io_bazel_rules_closure//closure/library:testing",
"@io_bazel_rules_closure//closure/library/crypt:base64",
"@io_bazel_rules_closure//closure/library/events:events",
"@io_bazel_rules_closure//closure/library/structs:map",
":grpcwebclientbase",
":clientreadablestream",
":clientreadablestreamdelegate",
":defaultclientreadablestreamdelegate",
":generictransportinterface",
":status",
":statuscode",
"@io_bazel_rules_closure//closure/library/asserts",
"@io_bazel_rules_closure//closure/library/net:errorcode",
"@io_bazel_rules_closure//closure/library/net:xhrio",
"@io_bazel_rules_closure//closure/library/net/streams:nodereadablestream",
],
)

closure_js_test(
name = "grpcwebstreamparser_test",
name = "streambodyclientreadablestream_test",
srcs = [
"grpcwebstreamparser_test.js",
"streambodyclientreadablestream_test.js",
],
entry_points = [
"goog:grpc.web.GrpcWebStreamParserTest",
],
suppress = [
"reportUnknownTypes",
"goog:grpc.web.StreamBodyClientReadableStreamTest",
],
deps = [
":grpcwebstreamparser",
"@io_bazel_rules_closure//closure/library:testing",
":streambodyclientreadablestream",
"@io_bazel_rules_closure//closure/library/reflect",
"@io_bazel_rules_closure//closure/library/testing:jsunit",
"@io_bazel_rules_closure//closure/library/testing:testsuite",
],
)
9 changes: 9 additions & 0 deletions javascript/net/grpc/web/clientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ goog.module('grpc.web.ClientReadableStream');

goog.module.declareLegacyNamespace();

const ClientReadableStreamDelegate = goog.require('grpc.web.ClientReadableStreamDelegate');



/**
Expand All @@ -53,6 +55,13 @@ const ClientReadableStream = function() {};
ClientReadableStream.prototype.on = goog.abstractMethod;


/**
* @param {!ClientReadableStreamDelegate} delegate
* @return {!ClientReadableStream}
*/
ClientReadableStream.prototype.setDelegate = goog.abstractMethod;



/**
* Close the stream.
Expand Down
63 changes: 63 additions & 0 deletions javascript/net/grpc/web/clientreadablestreamdelegate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
*
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

goog.module('grpc.web.ClientReadableStreamDelegate');

goog.module.declareLegacyNamespace();

// const Error = goog.require('grpc.web.Error');
const {Status} = goog.require('grpc.web.Status');



/**
* @template RESPONSE
* @interface
*/
const ClientReadableStreamDelegate = function() {};


/**
* @param {!RESPONSE} message
* @return {void}
*/
ClientReadableStreamDelegate.prototype.onData = goog.abstractMethod;


/**
* @return {void}
*/
ClientReadableStreamDelegate.prototype.onEnd = goog.abstractMethod;


/**
* @param {...} message
* @return {void}
*/
ClientReadableStreamDelegate.prototype.onError = goog.abstractMethod;


/**
* @param {!Status} message
* @return {void}
*/
ClientReadableStreamDelegate.prototype.onStatus = goog.abstractMethod;



exports = ClientReadableStreamDelegate;
Loading

0 comments on commit ffbedfe

Please sign in to comment.