Skip to content

Commit

Permalink
Merge branch 'master' into angular-support
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Oct 9, 2019
2 parents 9d321e8 + c284b15 commit af46816
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
We definitely welcome patches and contribution to gRPC-Web! Here is some guideline
and information about how to do so.

Please read the gRPC
organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md)
and [contribution guidelines](https://github.com/grpc/grpc-community/blob/master/CONTRIBUTING.md) before proceeding.

## Getting started

### Legal requirements
Expand Down
1 change: 1 addition & 0 deletions GOVERNANCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This repository is governed by the gRPC organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md).
51 changes: 51 additions & 0 deletions javascript/net/grpc/web/calloptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @fileoverview grpc.web.CallOptions
*/

goog.module('grpc.web.CallOptions');
goog.module.declareLegacyNamespace();

/**
* The collection of runtime options for a new RPC call.
*
* @constructor
*/
const CallOptions = function() {
/**
* @const {!Object<string, ?>}
* @private
*/
this.properties_ = {};
};

/**
* Add a new CallOption or override an existing one.
*
* @param {string} name name of the CallOption that should be added/overridden.
* @param {?} value value of the CallOption
*/
CallOptions.prototype.setOption = function(name, value) {
this.properties_[name] = value;
};

/**
* Get the value of one CallOption.
*
* @param {string} name name of the CallOption.
* @return {?} value of the CallOption. If name doesn't exist, will return
* 'undefined'.
*/
CallOptions.prototype.get = function(name) {
return this.properties_[name];
};

/**
* Remove a CallOption.
*
* @param {string} name name of the CallOption that shoud be removed.
*/
CallOptions.prototype.removeOption = function(name) {
delete this.properties_[name];
};

exports = CallOptions;
20 changes: 19 additions & 1 deletion javascript/net/grpc/web/genericclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
goog.module('grpc.web.GenericClient');
goog.module.declareLegacyNamespace();

const CallOptions = goog.require('grpc.web.CallOptions');
const Metadata = goog.require('grpc.web.Metadata');
const MethodDescriptor = goog.require('grpc.web.MethodDescriptor');
const UnaryResponse = goog.require('grpc.web.UnaryResponse');
Expand All @@ -20,10 +21,27 @@ const GenericClient = function() {};
* @param {!MethodDescriptor<REQUEST, RESPONSE>} methodDescriptor Information of
* this RPC method
* @param {!Metadata} metadata The user defined request metadata.
* @param {!CallOptions} callOptions
* @return {!Promise<!UnaryResponse<RESPONSE>>} A promise that resolves to the
* response message and metadata
* @template REQUEST, RESPONSE
* @abstract
*/
GenericClient.prototype.unaryCall = function(
request, methodDescriptor, metadata, callOptions) {};

/**
* @param {!REQUEST} request The request proto message
* @param {!MethodDescriptor<REQUEST, RESPONSE>} methodDescriptor Information of
* this RPC method
* @param {!Metadata=} metadata The user defined request metadata.
* @param {!CallOptions=} callOptions
* @return {!Promise<RESPONSE>} A promise that resolves to the
* response message
* @template REQUEST, RESPONSE
* @abstract
*/
GenericClient.prototype.unaryCall = goog.abstractMethod;
GenericClient.prototype.call = function(
request, methodDescriptor, metadata = {}, callOptions) {};

exports = GenericClient;
94 changes: 62 additions & 32 deletions javascript/net/grpc/web/grpc_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ string GetSerializeMethodName(const string& mode_var) {
return "serializeBinary";
}

std::string GetSerializeMethodReturnType(const string& mode_var) {
if (mode_var == GetModeVar(Mode::OPJSPB)) {
return "string";
}
return "!Uint8Array";
}

string LowercaseFirstLetter(string s) {
if (s.empty()) {
return s;
Expand Down Expand Up @@ -504,15 +511,36 @@ string GetRootPath(const string& from_filename, const string& to_filename) {
return result;
}

// Returns the basename of a file.
string GetBasename(string filename)
{
size_t last_slash = filename.find_last_of('/');
if (last_slash != string::npos)
{
return filename.substr(last_slash + 1);
// Splits path immediately following the final slash, separating it into a
// directory and file name component. Directory will contain the last
// slash, if it's not empty.
// If there is no slash in path, Split returns an empty directory and
// basename set to path.
// Output values have the property that path = directory + basename.
void PathSplit(const string& path, string* directory, string* basename) {
string::size_type last_slash = path.rfind('/');
if (last_slash == string::npos) {
if (directory) {
*directory = "";
}
if (basename) {
*basename = path;
}
} else {
if (directory) {
*directory = path.substr(0, last_slash + 1);
}
if (basename) {
*basename = path.substr(last_slash + 1);
}
}
return filename;
}

// Returns the basename of a file.
string GetBasename(string filename) {
string basename;
PathSplit(filename, nullptr, &basename);
return basename;
}

/* Finds all message types used in all services in the file, and returns them
Expand Down Expand Up @@ -1191,11 +1219,16 @@ void PrintMethodDescriptorFile(Printer* printer,
"$in_type$,\n");
printer->Print(vars,
"$out_type$,\n"
"/** @param {!proto.$in$} request */\n"
"/**\n"
" * @param {!proto.$in$} request\n");
printer->Print(
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
.c_str());
printer->Print(" */\n"
"function(request) {\n");
printer->Print(
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
.c_str());
.c_str());
printer->Print("},\n");
printer->Print(
vars, ("$out_type$." + GetDeserializeMethodName(vars["mode"])).c_str());
Expand Down Expand Up @@ -1237,15 +1270,6 @@ void PrintServiceConstructor(Printer* printer,
" * @private @const {string} The hostname\n"
" */\n"
" this.hostname_ = hostname;\n\n"
" /**\n"
" * @private @const {?Object} The credentials to be used to connect\n"
" * to the server\n"
" */\n"
" this.credentials_ = credentials;\n\n"
" /**\n"
" * @private @const {?Object} Options for the client\n"
" */\n"
" this.options_ = options;\n"
"};\n\n\n");
}

Expand Down Expand Up @@ -1276,15 +1300,6 @@ void PrintPromiseServiceConstructor(Printer* printer,
" * @private @const {string} The hostname\n"
" */\n"
" this.hostname_ = hostname;\n\n"
" /**\n"
" * @private @const {?Object} The credentials to be used to connect\n"
" * to the server\n"
" */\n"
" this.credentials_ = credentials;\n\n"
" /**\n"
" * @private @const {?Object} Options for the client\n"
" */\n"
" this.options_ = options;\n"
"};\n\n\n");
}

Expand All @@ -1307,7 +1322,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> vars) {
"$in_type$,\n");
printer->Print(vars,
"$out_type$,\n"
"/** @param {!proto.$in$} request */\n"
"/**\n"
" * @param {!proto.$in$} request\n");
printer->Print(
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
.c_str());
printer->Print(" */\n"
"function(request) {\n");
printer->Print(
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
Expand All @@ -1334,7 +1354,12 @@ void PrintMethodInfo(Printer* printer, std::map<string, string> vars) {

printer->Print(vars,
"$out_type$,\n"
"/** @param {!proto.$in$} request */\n"
"/**\n"
" * @param {!proto.$in$} request\n");
printer->Print(
(" * @return {" + GetSerializeMethodReturnType(vars["mode"]) + "}\n")
.c_str());
printer->Print(" */\n"
"function(request) {\n");
printer->Print(
(" return request." + GetSerializeMethodName(vars["mode"]) + "();\n")
Expand Down Expand Up @@ -1532,8 +1557,13 @@ class GrpcCodeGenerator : public CodeGenerator {
generate_dts = true;
} else if (import_style_str == "typescript") {
import_style = ImportStyle::TYPESCRIPT;
file_name =
UppercaseFirstLetter(StripProto(file->name())) + "ServiceClientPb.ts";

string directory;
string basename;

PathSplit(file->name(), &directory, &basename);
file_name = directory + UppercaseFirstLetter(StripProto(basename)) +
"ServiceClientPb.ts";
} else {
*error = "options: invalid import_style - " + import_style_str;
return false;
Expand Down
2 changes: 1 addition & 1 deletion net/grpc/gateway/docker/closure_client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get -qq update && apt-get -qq install -y \
default-jdk

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

RUN cd /github/grpc-web && \
Expand Down
4 changes: 2 additions & 2 deletions net/grpc/gateway/docker/common/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ RUN apt-get -qq update && apt-get -qq install -y \

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

RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/\
protoc-3.7.1-linux-x86_64.zip -o /tmp/protoc.zip && \
RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/\
protoc-3.8.0-linux-x86_64.zip -o /tmp/protoc.zip && \
cd /tmp && \
unzip -qq protoc.zip && \
cp /tmp/bin/protoc /usr/local/bin/protoc
Expand Down
27 changes: 15 additions & 12 deletions net/grpc/gateway/docker/grpcwebproxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ FROM golang:alpine
RUN apk add --no-cache curl git ca-certificates && \
rm -rf /var/lib/apt/lists/*

ARG VERSION=0.6.2
ARG VERSION=0.11.0

WORKDIR /tmp

RUN curl -sS https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN wget https://github.com/improbable-eng/grpc-web/archive/$VERSION.tar.gz
RUN mkdir -p /go/src/github.com/improbable-eng/
RUN tar -zxf $VERSION.tar.gz -C /go/src/github.com/improbable-eng/
RUN cd /go/src/github.com/improbable-eng && mv grpc-web-$VERSION grpc-web
RUN cd /go/src/github.com/improbable-eng/grpc-web && \
dep ensure --vendor-only && \
RUN wget https://github.com/improbable-eng/grpc-web/archive/v$VERSION.tar.gz

WORKDIR /go/src/github.com/improbable-eng/

RUN tar -zxf /tmp/v$VERSION.tar.gz -C .
RUN mv grpc-web-$VERSION grpc-web

WORKDIR /go/src/github.com/improbable-eng/grpc-web

RUN dep ensure --vendor-only && \
go install ./go/grpcwebproxy

ADD ./etc/localhost.crt /etc
ADD ./etc/localhost.key /etc

ENTRYPOINT [ "/bin/sh", "-c", "exec /go/bin/grpcwebproxy \
--backend_addr=node-server:9090 \
--server_bind_address=0.0.0.0 \
--server_http_debug_port=8080 \
--run_http_server=true \
--server_tls_cert_file=/etc/localhost.crt \
--server_tls_key_file=/etc/localhost.key " ]
--run_tls_server=false \
--allow_all_origins " ]
2 changes: 1 addition & 1 deletion packages/grpc-web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grpc-web",
"version": "1.0.6",
"version": "1.0.7",
"author": "Google Inc.",
"description": "gRPC-Web Client Runtime Library",
"homepage": "https://grpc.io/",
Expand Down
4 changes: 4 additions & 0 deletions src/connector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# grpc-web java connector

## About This Repository
This repo is for Java in-process (jar) code to add support for grpc-web protocol in grpc services.

0 comments on commit af46816

Please sign in to comment.