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

Correct generated client, bidi stream method stubs #131

Merged
merged 1 commit into from
Oct 20, 2018
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

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

10 changes: 5 additions & 5 deletions examples/generated/proto/orphan_pb_service.d.ts

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

14 changes: 7 additions & 7 deletions src/service/grpcweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ function generateTypescriptDefinition(fileDescriptor: FileDescriptorProto, expor
printer.printIndentedLn(`on(type: 'end', handler: () => void): RequestStream<T>;`);
printer.printIndentedLn(`on(type: 'status', handler: (status: Status) => void): RequestStream<T>;`);
printer.printLn(`}`);
printer.printLn(`interface BidirectionalStream<T> {`);
printer.printIndentedLn(`write(message: T): BidirectionalStream<T>;`);
printer.printLn(`interface BidirectionalStream<ReqT, ResT> {`);
printer.printIndentedLn(`write(message: ReqT): BidirectionalStream<ReqT, ResT>;`);
printer.printIndentedLn(`end(): void;`);
printer.printIndentedLn(`cancel(): void;`);
printer.printIndentedLn(`on(type: 'data', handler: (message: T) => void): BidirectionalStream<T>;`);
printer.printIndentedLn(`on(type: 'end', handler: () => void): BidirectionalStream<T>;`);
printer.printIndentedLn(`on(type: 'status', handler: (status: Status) => void): BidirectionalStream<T>;`);
printer.printIndentedLn(`on(type: 'data', handler: (message: ResT) => void): BidirectionalStream<ReqT, ResT>;`);
printer.printIndentedLn(`on(type: 'end', handler: () => void): BidirectionalStream<ReqT, ResT>;`);
printer.printIndentedLn(`on(type: 'status', handler: (status: Status) => void): BidirectionalStream<ReqT, ResT>;`);
printer.printLn(`}`);
printer.printEmptyLn();

Expand Down Expand Up @@ -531,9 +531,9 @@ function printServerStreamStubMethodTypes(printer: CodePrinter, method: RPCMetho
}

function printClientStreamStubMethodTypes(printer: CodePrinter, method: RPCMethodDescriptor) {
printer.printLn(`${method.nameAsCamelCase}(metadata?: grpc.Metadata): RequestStream<${method.responseType}>;`);
printer.printLn(`${method.nameAsCamelCase}(metadata?: grpc.Metadata): RequestStream<${method.requestType}>;`);
}

function printBidirectionalStubMethodTypes(printer: CodePrinter, method: RPCMethodDescriptor) {
printer.printLn(`${method.nameAsCamelCase}(metadata?: grpc.Metadata): BidirectionalStream<${method.responseType}>;`);
printer.printLn(`${method.nameAsCamelCase}(metadata?: grpc.Metadata): BidirectionalStream<${method.requestType}, ${method.responseType}>;`);
}
18 changes: 13 additions & 5 deletions test/integration/service/grpcweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ describe("service/grpc-web", () => {
});

describe("client streaming", () => {
const [ payload ] = makePayloads("some value");
const payload = new StreamRequest();
payload.setSomeString("some value");

it("should route the request to the expected endpoint", (done) => {
let targetUrl = "";
Expand Down Expand Up @@ -389,7 +390,10 @@ describe("service/grpc-web", () => {
});

it("should allow the caller to supply multiple messages", (done) => {
const [ reqMsgOne, reqMsgTwo ] = makePayloads("one", "two");
const reqMsgOne = new StreamRequest();
reqMsgOne.setSomeString("one");
const reqMsgTwo = new StreamRequest();
reqMsgTwo.setSomeString("two");
const sentMessageBytes: ArrayBufferView[] = [];

makeClient(new StubTransportBuilder().withMessageListener(v => { sentMessageBytes.push(v); }))
Expand Down Expand Up @@ -449,7 +453,8 @@ describe("service/grpc-web", () => {
});

describe("bidirectional streaming", () => {
const [ payload ] = makePayloads("some value");
const payload = new StreamRequest();
payload.setSomeString("some value");

it("should route the request to the expected endpoint", (done) => {
let targetUrl = "";
Expand Down Expand Up @@ -503,7 +508,7 @@ describe("service/grpc-web", () => {

it("should handle an error returned ahead of any data by the server", (done) => {
makeClient(new StubTransportBuilder().withPreMessagesError(grpc.Code.Internal, "some error"))
.doClientStream()
.doBidiStream()
.on("status", (status) => {
assert.equal(status.code, grpc.Code.Internal, "expected grpc status code returned");
assert.equal(status.details, "some error", "expected grpc error details returned");
Expand Down Expand Up @@ -531,7 +536,10 @@ describe("service/grpc-web", () => {
});

it("should allow the caller to supply multiple messages", (done) => {
const [ reqMsgOne, reqMsgTwo ] = makePayloads("one", "two");
const reqMsgOne = new StreamRequest();
reqMsgOne.setSomeString("one");
const reqMsgTwo = new StreamRequest();
reqMsgTwo.setSomeString("two");
const sentMessageBytes: ArrayBufferView[] = [];

makeClient(new StubTransportBuilder().withMessageListener(v => { sentMessageBytes.push(v); }))
Expand Down