Skip to content

Commit af46816

Browse files
Merge branch 'master' into angular-support
2 parents 9d321e8 + c284b15 commit af46816

File tree

10 files changed

+160
-49
lines changed

10 files changed

+160
-49
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
We definitely welcome patches and contribution to gRPC-Web! Here is some guideline
44
and information about how to do so.
55

6+
Please read the gRPC
7+
organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md)
8+
and [contribution guidelines](https://github.com/grpc/grpc-community/blob/master/CONTRIBUTING.md) before proceeding.
9+
610
## Getting started
711

812
### Legal requirements

GOVERNANCE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This repository is governed by the gRPC organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md).
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @fileoverview grpc.web.CallOptions
3+
*/
4+
5+
goog.module('grpc.web.CallOptions');
6+
goog.module.declareLegacyNamespace();
7+
8+
/**
9+
* The collection of runtime options for a new RPC call.
10+
*
11+
* @constructor
12+
*/
13+
const CallOptions = function() {
14+
/**
15+
* @const {!Object<string, ?>}
16+
* @private
17+
*/
18+
this.properties_ = {};
19+
};
20+
21+
/**
22+
* Add a new CallOption or override an existing one.
23+
*
24+
* @param {string} name name of the CallOption that should be added/overridden.
25+
* @param {?} value value of the CallOption
26+
*/
27+
CallOptions.prototype.setOption = function(name, value) {
28+
this.properties_[name] = value;
29+
};
30+
31+
/**
32+
* Get the value of one CallOption.
33+
*
34+
* @param {string} name name of the CallOption.
35+
* @return {?} value of the CallOption. If name doesn't exist, will return
36+
* 'undefined'.
37+
*/
38+
CallOptions.prototype.get = function(name) {
39+
return this.properties_[name];
40+
};
41+
42+
/**
43+
* Remove a CallOption.
44+
*
45+
* @param {string} name name of the CallOption that shoud be removed.
46+
*/
47+
CallOptions.prototype.removeOption = function(name) {
48+
delete this.properties_[name];
49+
};
50+
51+
exports = CallOptions;

javascript/net/grpc/web/genericclient.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
goog.module('grpc.web.GenericClient');
66
goog.module.declareLegacyNamespace();
77

8+
const CallOptions = goog.require('grpc.web.CallOptions');
89
const Metadata = goog.require('grpc.web.Metadata');
910
const MethodDescriptor = goog.require('grpc.web.MethodDescriptor');
1011
const UnaryResponse = goog.require('grpc.web.UnaryResponse');
@@ -20,10 +21,27 @@ const GenericClient = function() {};
2021
* @param {!MethodDescriptor<REQUEST, RESPONSE>} methodDescriptor Information of
2122
* this RPC method
2223
* @param {!Metadata} metadata The user defined request metadata.
24+
* @param {!CallOptions} callOptions
2325
* @return {!Promise<!UnaryResponse<RESPONSE>>} A promise that resolves to the
26+
* response message and metadata
27+
* @template REQUEST, RESPONSE
28+
* @abstract
29+
*/
30+
GenericClient.prototype.unaryCall = function(
31+
request, methodDescriptor, metadata, callOptions) {};
32+
33+
/**
34+
* @param {!REQUEST} request The request proto message
35+
* @param {!MethodDescriptor<REQUEST, RESPONSE>} methodDescriptor Information of
36+
* this RPC method
37+
* @param {!Metadata=} metadata The user defined request metadata.
38+
* @param {!CallOptions=} callOptions
39+
* @return {!Promise<RESPONSE>} A promise that resolves to the
2440
* response message
2541
* @template REQUEST, RESPONSE
42+
* @abstract
2643
*/
27-
GenericClient.prototype.unaryCall = goog.abstractMethod;
44+
GenericClient.prototype.call = function(
45+
request, methodDescriptor, metadata = {}, callOptions) {};
2846

2947
exports = GenericClient;

javascript/net/grpc/web/grpc_generator.cc

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ string GetSerializeMethodName(const string& mode_var) {
159159
return "serializeBinary";
160160
}
161161

162+
std::string GetSerializeMethodReturnType(const string& mode_var) {
163+
if (mode_var == GetModeVar(Mode::OPJSPB)) {
164+
return "string";
165+
}
166+
return "!Uint8Array";
167+
}
168+
162169
string LowercaseFirstLetter(string s) {
163170
if (s.empty()) {
164171
return s;
@@ -504,15 +511,36 @@ string GetRootPath(const string& from_filename, const string& to_filename) {
504511
return result;
505512
}
506513

507-
// Returns the basename of a file.
508-
string GetBasename(string filename)
509-
{
510-
size_t last_slash = filename.find_last_of('/');
511-
if (last_slash != string::npos)
512-
{
513-
return filename.substr(last_slash + 1);
514+
// Splits path immediately following the final slash, separating it into a
515+
// directory and file name component. Directory will contain the last
516+
// slash, if it's not empty.
517+
// If there is no slash in path, Split returns an empty directory and
518+
// basename set to path.
519+
// Output values have the property that path = directory + basename.
520+
void PathSplit(const string& path, string* directory, string* basename) {
521+
string::size_type last_slash = path.rfind('/');
522+
if (last_slash == string::npos) {
523+
if (directory) {
524+
*directory = "";
525+
}
526+
if (basename) {
527+
*basename = path;
528+
}
529+
} else {
530+
if (directory) {
531+
*directory = path.substr(0, last_slash + 1);
532+
}
533+
if (basename) {
534+
*basename = path.substr(last_slash + 1);
535+
}
514536
}
515-
return filename;
537+
}
538+
539+
// Returns the basename of a file.
540+
string GetBasename(string filename) {
541+
string basename;
542+
PathSplit(filename, nullptr, &basename);
543+
return basename;
516544
}
517545

518546
/* Finds all message types used in all services in the file, and returns them
@@ -1191,11 +1219,16 @@ void PrintMethodDescriptorFile(Printer* printer,
11911219
"$in_type$,\n");
11921220
printer->Print(vars,
11931221
"$out_type$,\n"
1194-
"/** @param {!proto.$in$} request */\n"
1222+
"/**\n"
1223+
" * @param {!proto.$in$} request\n");
1224+
printer->Print(
1225+
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
1226+
.c_str());
1227+
printer->Print(" */\n"
11951228
"function(request) {\n");
11961229
printer->Print(
11971230
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
1198-
.c_str());
1231+
.c_str());
11991232
printer->Print("},\n");
12001233
printer->Print(
12011234
vars, ("$out_type$." + GetDeserializeMethodName(vars["mode"])).c_str());
@@ -1237,15 +1270,6 @@ void PrintServiceConstructor(Printer* printer,
12371270
" * @private @const {string} The hostname\n"
12381271
" */\n"
12391272
" this.hostname_ = hostname;\n\n"
1240-
" /**\n"
1241-
" * @private @const {?Object} The credentials to be used to connect\n"
1242-
" * to the server\n"
1243-
" */\n"
1244-
" this.credentials_ = credentials;\n\n"
1245-
" /**\n"
1246-
" * @private @const {?Object} Options for the client\n"
1247-
" */\n"
1248-
" this.options_ = options;\n"
12491273
"};\n\n\n");
12501274
}
12511275

@@ -1276,15 +1300,6 @@ void PrintPromiseServiceConstructor(Printer* printer,
12761300
" * @private @const {string} The hostname\n"
12771301
" */\n"
12781302
" this.hostname_ = hostname;\n\n"
1279-
" /**\n"
1280-
" * @private @const {?Object} The credentials to be used to connect\n"
1281-
" * to the server\n"
1282-
" */\n"
1283-
" this.credentials_ = credentials;\n\n"
1284-
" /**\n"
1285-
" * @private @const {?Object} Options for the client\n"
1286-
" */\n"
1287-
" this.options_ = options;\n"
12881303
"};\n\n\n");
12891304
}
12901305

@@ -1307,7 +1322,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> vars) {
13071322
"$in_type$,\n");
13081323
printer->Print(vars,
13091324
"$out_type$,\n"
1310-
"/** @param {!proto.$in$} request */\n"
1325+
"/**\n"
1326+
" * @param {!proto.$in$} request\n");
1327+
printer->Print(
1328+
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
1329+
.c_str());
1330+
printer->Print(" */\n"
13111331
"function(request) {\n");
13121332
printer->Print(
13131333
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
@@ -1334,7 +1354,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> vars) {
13341354

13351355
printer->Print(vars,
13361356
"$out_type$,\n"
1337-
"/** @param {!proto.$in$} request */\n"
1357+
"/**\n"
1358+
" * @param {!proto.$in$} request\n");
1359+
printer->Print(
1360+
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
1361+
.c_str());
1362+
printer->Print(" */\n"
13381363
"function(request) {\n");
13391364
printer->Print(
13401365
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
@@ -1532,8 +1557,13 @@ class GrpcCodeGenerator : public CodeGenerator {
15321557
generate_dts = true;
15331558
} else if (import_style_str == "typescript") {
15341559
import_style = ImportStyle::TYPESCRIPT;
1535-
file_name =
1536-
UppercaseFirstLetter(StripProto(file->name())) + "ServiceClientPb.ts";
1560+
1561+
string directory;
1562+
string basename;
1563+
1564+
PathSplit(file->name(), &directory, &basename);
1565+
file_name = directory + UppercaseFirstLetter(StripProto(basename)) +
1566+
"ServiceClientPb.ts";
15371567
} else {
15381568
*error = "options: invalid import_style - " + import_style_str;
15391569
return false;

net/grpc/gateway/docker/closure_client/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN apt-get -qq update && apt-get -qq install -y \
1818
default-jdk
1919

2020
RUN cd /github/grpc-web && \
21-
curl -sS https://dl.google.com/closure-compiler/compiler-latest.zip \
21+
curl -sS https://dl.google.com/closure-compiler/compiler-20190909.zip \
2222
-o /github/grpc-web/compiler-latest.zip
2323

2424
RUN cd /github/grpc-web && \

net/grpc/gateway/docker/common/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ RUN apt-get -qq update && apt-get -qq install -y \
1919

2020
RUN git clone https://github.com/grpc/grpc-web /github/grpc-web
2121

22-
RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/\
23-
protoc-3.7.1-linux-x86_64.zip -o /tmp/protoc.zip && \
22+
RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/\
23+
protoc-3.8.0-linux-x86_64.zip -o /tmp/protoc.zip && \
2424
cd /tmp && \
2525
unzip -qq protoc.zip && \
2626
cp /tmp/bin/protoc /usr/local/bin/protoc

net/grpc/gateway/docker/grpcwebproxy/Dockerfile

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,27 @@ FROM golang:alpine
1717
RUN apk add --no-cache curl git ca-certificates && \
1818
rm -rf /var/lib/apt/lists/*
1919

20-
ARG VERSION=0.6.2
20+
ARG VERSION=0.11.0
21+
22+
WORKDIR /tmp
2123

2224
RUN curl -sS https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
23-
RUN wget https://github.com/improbable-eng/grpc-web/archive/$VERSION.tar.gz
24-
RUN mkdir -p /go/src/github.com/improbable-eng/
25-
RUN tar -zxf $VERSION.tar.gz -C /go/src/github.com/improbable-eng/
26-
RUN cd /go/src/github.com/improbable-eng && mv grpc-web-$VERSION grpc-web
27-
RUN cd /go/src/github.com/improbable-eng/grpc-web && \
28-
dep ensure --vendor-only && \
25+
RUN wget https://github.com/improbable-eng/grpc-web/archive/v$VERSION.tar.gz
26+
27+
WORKDIR /go/src/github.com/improbable-eng/
28+
29+
RUN tar -zxf /tmp/v$VERSION.tar.gz -C .
30+
RUN mv grpc-web-$VERSION grpc-web
31+
32+
WORKDIR /go/src/github.com/improbable-eng/grpc-web
33+
34+
RUN dep ensure --vendor-only && \
2935
go install ./go/grpcwebproxy
3036

3137
ADD ./etc/localhost.crt /etc
3238
ADD ./etc/localhost.key /etc
3339

3440
ENTRYPOINT [ "/bin/sh", "-c", "exec /go/bin/grpcwebproxy \
3541
--backend_addr=node-server:9090 \
36-
--server_bind_address=0.0.0.0 \
37-
--server_http_debug_port=8080 \
38-
--run_http_server=true \
39-
--server_tls_cert_file=/etc/localhost.crt \
40-
--server_tls_key_file=/etc/localhost.key " ]
42+
--run_tls_server=false \
43+
--allow_all_origins " ]

packages/grpc-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "grpc-web",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"author": "Google Inc.",
55
"description": "gRPC-Web Client Runtime Library",
66
"homepage": "https://grpc.io/",

src/connector/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# grpc-web java connector
2+
3+
## About This Repository
4+
This repo is for Java in-process (jar) code to add support for grpc-web protocol in grpc services.

0 commit comments

Comments
 (0)