Skip to content

Commit

Permalink
Merge pull request #14 from ShenYiQian/master
Browse files Browse the repository at this point in the history
upgrade grpc to 1.9.0 & update example code
  • Loading branch information
agreatfool authored Feb 12, 2018
2 parents f769462 + 8c9f1bc commit 524cc52
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 257 deletions.
20 changes: 10 additions & 10 deletions build/lib/template/svc_tsd.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{/each}}
{{#each services}}

interface I{{{serviceName}}}Service extends grpc.ServiceDefinition {
interface I{{{serviceName}}}Service extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
{{#each methods}}
{{lcFirst methodName}}: I{{{methodName}}};
{{/each}}
Expand All @@ -35,15 +35,15 @@ export interface I{{{serviceName}}}Client {
{{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata: grpc.Metadata, callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientUnaryCall;
{{/eq}}
{{#eq type "ClientWritableStream"}}
{{lcFirst methodName}}(callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream;
{{lcFirst methodName}}(callback: (error: Error | null, metadata: grpc.Metadata, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream;
{{lcFirst methodName}}(callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream<{{{requestTypeName}}}>;
{{lcFirst methodName}}(callback: (error: Error | null, metadata: grpc.Metadata, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream<{{{requestTypeName}}}>;
{{/eq}}
{{#eq type "ClientReadableStream"}}
{{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata?: grpc.Metadata): grpc.ClientReadableStream;
{{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata?: grpc.Metadata): grpc.ClientReadableStream<{{{requestTypeName}}}>;
{{/eq}}
{{#eq type "ClientDuplexStream"}}
{{lcFirst methodName}}(): grpc.ClientDuplexStream;
{{lcFirst methodName}}(metadata: grpc.Metadata): grpc.ClientDuplexStream;
{{lcFirst methodName}}(): grpc.ClientDuplexStream<{{{requestTypeName}}}, {{{responseTypeName}}}>;
{{lcFirst methodName}}(metadata: grpc.Metadata): grpc.ClientDuplexStream<{{{requestTypeName}}}, {{{responseTypeName}}}>;
{{/eq}}
{{/each}}
}
Expand All @@ -57,14 +57,14 @@ export class {{{serviceName}}}Client extends grpc.Client implements I{{{serviceN
public {{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata: grpc.Metadata, callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientUnaryCall;
{{/eq}}
{{#eq type "ClientWritableStream"}}
public {{lcFirst methodName}}(callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream;
public {{lcFirst methodName}}(callback: (error: Error | null, metadata: grpc.Metadata, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream;
public {{lcFirst methodName}}(callback: (error: Error | null, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream<{{{requestTypeName}}}>;
public {{lcFirst methodName}}(callback: (error: Error | null, metadata: grpc.Metadata, response: {{{responseTypeName}}}) => void): grpc.ClientWritableStream<{{{requestTypeName}}}>;
{{/eq}}
{{#eq type "ClientReadableStream"}}
public {{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata?: grpc.Metadata): grpc.ClientReadableStream;
public {{lcFirst methodName}}(request: {{{requestTypeName}}}, metadata?: grpc.Metadata): grpc.ClientReadableStream<{{{requestTypeName}}}>;
{{/eq}}
{{#eq type "ClientDuplexStream"}}
public {{lcFirst methodName}}(metadata?: grpc.Metadata): grpc.ClientDuplexStream;
public {{lcFirst methodName}}(metadata?: grpc.Metadata): grpc.ClientDuplexStream<{{{requestTypeName}}}, {{{responseTypeName}}}>;
{{/eq}}
{{/each}}
}
Expand Down
20 changes: 10 additions & 10 deletions examples/build/proto/book_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as grpc from "grpc";
import * as book_pb from "./book_pb";

interface IBookServiceService extends grpc.ServiceDefinition {
interface IBookServiceService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
getBook: IGetBook;
getBooksViaAuthor: IGetBooksViaAuthor;
getGreatestBook: IGetGreatestBook;
Expand Down Expand Up @@ -61,20 +61,20 @@ interface IGetBooks {
export interface IBookServiceClient {
getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream;
getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream;
getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream;
getBooks(): grpc.ClientDuplexStream;
getBooks(metadata: grpc.Metadata): grpc.ClientDuplexStream;
getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.GetBookViaAuthor>;
getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
getBooks(): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
getBooks(metadata: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}

export const BookServiceService: IBookServiceService;
export class BookServiceClient extends grpc.Client implements IBookServiceClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
public getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
public getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
public getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream;
public getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream;
public getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream;
public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream;
public getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.GetBookViaAuthor>;
public getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
public getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}
42 changes: 18 additions & 24 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"debug": "^3.1.0",
"google-protobuf": "^3.5.0",
"grpc": "^1.8.4"
"grpc": "^1.9.0"
},
"devDependencies": {
"@types/debug": "0.0.30",
Expand Down
2 changes: 1 addition & 1 deletion examples/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getBook = async (isbn: number) => {

const getBooks = () => {
return new Promise((resolve) => {
const stream: grpc.ClientDuplexStream = client.getBooks();
const stream: grpc.ClientDuplexStream<GetBookRequest, Book> = client.getBooks();

stream.on("data", (data: Book) => {
log(`[getBooks] Book: ${JSON.stringify(data.toObject())}`);
Expand Down
20 changes: 10 additions & 10 deletions examples/src/proto/book_grpc_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import * as grpc from "grpc";
import * as book_pb from "./book_pb";

interface IBookServiceService extends grpc.ServiceDefinition {
interface IBookServiceService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
getBook: IGetBook;
getBooksViaAuthor: IGetBooksViaAuthor;
getGreatestBook: IGetGreatestBook;
Expand Down Expand Up @@ -61,20 +61,20 @@ interface IGetBooks {
export interface IBookServiceClient {
getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream;
getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream;
getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream;
getBooks(): grpc.ClientDuplexStream;
getBooks(metadata: grpc.Metadata): grpc.ClientDuplexStream;
getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.GetBookViaAuthor>;
getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
getBooks(): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
getBooks(metadata: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}

export const BookServiceService: IBookServiceService;
export class BookServiceClient extends grpc.Client implements IBookServiceClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
public getBook(request: book_pb.GetBookRequest, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
public getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;
public getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream;
public getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream;
public getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream;
public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream;
public getBooksViaAuthor(request: book_pb.GetBookViaAuthor, metadata?: grpc.Metadata): grpc.ClientReadableStream<book_pb.GetBookViaAuthor>;
public getGreatestBook(callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
public getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream<book_pb.GetBookRequest>;
public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream<book_pb.GetBookRequest, book_pb.Book>;
}
8 changes: 4 additions & 4 deletions examples/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function startServer() {
const server = new grpc.Server();

server.addService(BookServiceService, {
getBook: (call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData) => {
getBook: (call: grpc.ServerUnaryCall<GetBookRequest>, callback: grpc.sendUnaryData<Book>) => {
const book = new Book();

book.setTitle("DefaultBook");
Expand All @@ -22,7 +22,7 @@ function startServer() {
log(`[getBook] Done: ${JSON.stringify(book.toObject())}`);
callback(null, book);
},
getBooks: (call: grpc.ServerDuplexStream) => {
getBooks: (call: grpc.ServerDuplexStream<GetBookRequest, Book>) => {
call.on("data", (request: GetBookRequest) => {
const reply = new Book();
reply.setTitle(`Book${request.getIsbn()}`);
Expand All @@ -36,7 +36,7 @@ function startServer() {
call.end();
});
},
getBooksViaAuthor: (call: grpc.ServerWriteableStream) => {
getBooksViaAuthor: (call: grpc.ServerWriteableStream<GetBookViaAuthor>) => {
const request = call.request as GetBookViaAuthor;

log(`[getBooksViaAuthor] Request: ${JSON.stringify(request.toObject())}`);
Expand All @@ -51,7 +51,7 @@ function startServer() {
log("[getBooksViaAuthor] Done.");
call.end();
},
getGreatestBook: (call: grpc.ServerReadableStream, callback: grpc.sendUnaryData) => {
getGreatestBook: (call: grpc.ServerReadableStream<GetBookRequest>, callback: grpc.sendUnaryData<Book>) => {
let lastOne: GetBookRequest;
call.on("data", (request: GetBookRequest) => {
log(`[getGreatestBook] Request: ${JSON.stringify(request.toObject())}`);
Expand Down
Loading

0 comments on commit 524cc52

Please sign in to comment.