Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grpc_tools_node_protoc_ts

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc_tools_node_protoc_ts - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

examples/bash/build.sh

133

examples/build/client.js

@@ -0,64 +1,101 @@

#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug = require("debug");
const grpc = require("grpc");
const book_grpc_pb_1 = require("./src/proto/book_grpc_pb");
const book_pb_1 = require("./src/proto/book_pb");
const book_grpc_pb_1 = require("./proto/book_grpc_pb");
const book_pb_1 = require("./proto/book_pb");
const log = debug("SampleClient");
const client = new book_grpc_pb_1.BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());
const fetchBooks = () => {
const stream = client.getBooks();
stream.on("data", (data) => {
console.log(data.getIsbn());
const getBook = (isbn) => __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const request = new book_pb_1.GetBookRequest();
request.setIsbn(isbn);
log(`[getBook] Request: ${JSON.stringify(request.toObject())}`);
client.getBook(request, (err, book) => {
if (err != null) {
debug(`[getBook] err:\nerr.message: ${err.message}\nerr.stack:\n${err.stack}`);
reject(err);
return;
}
log(`[getBook] Book: ${JSON.stringify(book.toObject())}`);
resolve(book);
});
});
stream.on("end", () => {
console.log("getBooks done.");
});
for (let i = 0; i < 10; i++) {
let req = new book_pb_1.GetBookRequest();
req.setIsbn(i);
stream.write(req);
}
stream.end();
};
const fetchBook = (isbn) => {
const request = new book_pb_1.GetBookRequest();
request.setIsbn(isbn);
client.getBook(request, (err, book) => {
if (err != null) {
console.error(err);
});
const getBooks = () => {
return new Promise((resolve) => {
const stream = client.getBooks();
stream.on("data", (data) => {
log(`[getBooks] Book: ${JSON.stringify(data.toObject())}`);
});
stream.on("end", () => {
log("[getBooks] Done.");
resolve();
});
for (let i = 0; i < 10; i++) {
const req = new book_pb_1.GetBookRequest();
req.setIsbn(i);
log(`[getBooks] Request: ${JSON.stringify(req.toObject())}`);
stream.write(req);
}
console.log(`getBook's Title is ${book.getTitle()}`);
stream.end();
});
};
const fetchBooksViaAuthor = (author) => {
const request = new book_pb_1.GetBookViaAuthor();
request.setAuthor(author);
const stream = client.getBooksViaAuthor(request);
stream.on("data", (data) => {
console.log(data.getTitle());
const getBooksViaAuthor = (author) => {
return new Promise((resolve) => {
const request = new book_pb_1.GetBookViaAuthor();
request.setAuthor(author);
log(`[getBooksViaAuthor] Request: ${JSON.stringify(request.toObject())}`);
const stream = client.getBooksViaAuthor(request);
stream.on("data", (data) => {
log(`[getBooksViaAuthor] Book: ${JSON.stringify(data.toObject())}`);
});
stream.on("end", () => {
log("[getBooksViaAuthor] Done.");
resolve();
});
});
stream.on("end", () => {
console.log("fetchBooksViaAuthor done");
});
};
const fetchGreatestBook = () => {
const stream = client.getGreatestBook((err, data) => {
if (err != null) {
console.error(err);
const getGreatestBook = () => {
return new Promise((resolve) => {
const stream = client.getGreatestBook((err, data) => {
if (err != null) {
log(`[getGreatestBook] err:\nerr.message: ${err.message}\nerr.stack:\n${err.stack}`);
}
log(`[getGreatestBook] Book: ${JSON.stringify(data.toObject())}`);
resolve();
});
for (let i = 0; i < 10; i++) {
const req = new book_pb_1.GetBookRequest();
req.setIsbn(i);
log(`[getGreatestBook] Request: ${JSON.stringify(req.toObject())}`);
stream.write(req);
}
console.log(data);
stream.end();
});
for (let i = 0; i < 10; i++) {
const req = new book_pb_1.GetBookRequest();
req.setIsbn(i);
stream.write(req);
}
stream.end();
};
function main() {
fetchBook(1);
// fetchBooksViaAuthor("DefaultAuthor");
// fetchGreatestBook();
// fetchBooks();
return __awaiter(this, void 0, void 0, function* () {
yield getBook(1);
yield getBooks();
yield getBooksViaAuthor("DefaultAuthor");
yield getGreatestBook();
});
}
main();
main().then((_) => _);
process.on("uncaughtException", (err) => {
log(`process on uncaughtException error: ${err}`);
});
process.on("unhandledRejection", (err) => {
log(`process on unhandledRejection error: ${err}`);
});
//# sourceMappingURL=client.js.map
// package: com.book
// file: book.proto
/* tslint:disable */
import * as grpc from "grpc";

@@ -5,0 +7,0 @@ import * as book_pb from "./book_pb";

// package: com.book
// file: book.proto
/* tslint:disable */
import * as jspb from "google-protobuf";

@@ -5,0 +7,0 @@

@@ -0,9 +1,19 @@

#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const debug = require("debug");
const grpc = require("grpc");
const book_grpc_pb_1 = require("./src/proto/book_grpc_pb");
const book_pb_1 = require("./src/proto/book_pb");
const book_grpc_pb_1 = require("./proto/book_grpc_pb");
const book_pb_1 = require("./proto/book_pb");
const log = debug("SampleServer");
function startServer() {
const server = new grpc.Server();
server.addService(book_grpc_pb_1.BookServiceService, {
getBook: (call, callback) => {
const book = new book_pb_1.Book();
book.setTitle("DefaultBook");
book.setAuthor("DefaultAuthor");
log(`[getBook] Done: ${JSON.stringify(book.toObject())}`);
callback(null, book);
},
getBooks: (call) => {

@@ -15,18 +25,13 @@ call.on("data", (request) => {

reply.setIsbn(request.getIsbn());
log(`[getBooks] Write: ${JSON.stringify(reply.toObject())}`);
call.write(reply);
});
call.on("end", () => {
console.log("getBooks done.");
log("[getBooks] Done.");
call.end();
});
},
getBook: (call, callback) => {
const book = new book_pb_1.Book();
book.setTitle("DefaultBook");
book.setAuthor("DefaultAuthor");
callback(null, book);
},
getBooksViaAuthor: (call) => {
const request = call.request;
console.log("getBooksViaAuthor request:", request.toObject());
log(`[getBooksViaAuthor] Request: ${JSON.stringify(request.toObject())}`);
for (let i = 1; i <= 10; i++) {

@@ -37,6 +42,6 @@ const reply = new book_pb_1.Book();

reply.setIsbn(i);
console.log("getBooksViaAuthor write:", reply.toObject());
log(`[getBooksViaAuthor] Write: ${JSON.stringify(reply.toObject())}`);
call.write(reply);
}
console.log("getBooksViaAuthor done.");
log("[getBooksViaAuthor] Done.");
call.end();

@@ -47,3 +52,3 @@ },

call.on("data", (request) => {
console.log("getGreatestBook:", request.toObject());
log(`[getGreatestBook] Request: ${JSON.stringify(request.toObject())}`);
lastOne = request;

@@ -56,11 +61,18 @@ });

reply.setAuthor("LastOne");
console.log("getGreatestBook done:", reply.toObject());
log(`[getGreatestBook] Done: ${JSON.stringify(reply.toObject())}`);
callback(null, reply);
});
}
},
});
server.bind("0.0.0.0:50051", grpc.ServerCredentials.createInsecure());
server.bind("127.0.0.1:50051", grpc.ServerCredentials.createInsecure());
server.start();
log("Server started, listening: 127.0.0.1:50051");
}
startServer();
process.on("uncaughtException", (err) => {
log(`process on uncaughtException error: ${err}`);
});
process.on("unhandledRejection", (err) => {
log(`process on unhandledRejection error: ${err}`);
});
//# sourceMappingURL=server.js.map

@@ -15,6 +15,11 @@ {

"dependencies": {
"@types/node": "^9.4.1",
"debug": "^3.1.0",
"google-protobuf": "^3.5.0",
"grpc": "^1.8.4"
},
"devDependencies": {
"@types/debug": "0.0.30",
"@types/google-protobuf": "^3.2.7",
"@types/node": "^9.4.2"
}
}

@@ -0,1 +1,4 @@

#!/usr/bin/env node
import * as debug from "debug";
import * as grpc from "grpc";

@@ -6,73 +9,99 @@

const log = debug("SampleClient");
const client = new BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());
const fetchBooks = () => {
const stream:grpc.ClientDuplexStream = client.getBooks();
const getBook = async (isbn: number) => {
return new Promise((resolve, reject) => {
const request = new GetBookRequest();
request.setIsbn(isbn);
stream.on("data", (data: Book) => {
console.log(data.getIsbn());
log(`[getBook] Request: ${JSON.stringify(request.toObject())}`);
client.getBook(request, (err, book) => {
if (err != null) {
debug(`[getBook] err:\nerr.message: ${err.message}\nerr.stack:\n${err.stack}`);
reject(err); return;
}
log(`[getBook] Book: ${JSON.stringify(book.toObject())}`);
resolve(book);
});
});
stream.on("end", () => {
console.log("getBooks done.");
});
for (let i = 0; i < 10; i++) {
let req = new GetBookRequest();
req.setIsbn(i);
stream.write(req);
}
stream.end();
};
const fetchBook = (isbn: number) => {
const request = new GetBookRequest();
request.setIsbn(isbn);
const getBooks = () => {
return new Promise((resolve) => {
const stream: grpc.ClientDuplexStream = client.getBooks();
stream.on("data", (data: Book) => {
log(`[getBooks] Book: ${JSON.stringify(data.toObject())}`);
});
stream.on("end", () => {
log("[getBooks] Done.");
resolve();
});
client.getBook(request, (err, book) => {
if (err != null) {
console.error(err);
for (let i = 0; i < 10; i++) {
const req = new GetBookRequest();
req.setIsbn(i);
log(`[getBooks] Request: ${JSON.stringify(req.toObject())}`);
stream.write(req);
}
console.log(`getBook's Title is ${book.getTitle()}`);
stream.end();
});
};
const fetchBooksViaAuthor = (author: string) => {
const request = new GetBookViaAuthor();
request.setAuthor(author);
const getBooksViaAuthor = (author: string) => {
return new Promise((resolve) => {
const request = new GetBookViaAuthor();
request.setAuthor(author);
const stream = client.getBooksViaAuthor(request);
stream.on("data", (data: Book) => {
console.log(data.getTitle());
log(`[getBooksViaAuthor] Request: ${JSON.stringify(request.toObject())}`);
const stream = client.getBooksViaAuthor(request);
stream.on("data", (data: Book) => {
log(`[getBooksViaAuthor] Book: ${JSON.stringify(data.toObject())}`);
});
stream.on("end", () => {
log("[getBooksViaAuthor] Done.");
resolve();
});
});
stream.on("end", () => {
console.log("fetchBooksViaAuthor done");
});
};
const fetchGreatestBook = () => {
const stream = client.getGreatestBook((err, data) => {
if (err != null) {
console.error(err);
const getGreatestBook = () => {
return new Promise((resolve) => {
const stream = client.getGreatestBook((err, data) => {
if (err != null) {
log(`[getGreatestBook] err:\nerr.message: ${err.message}\nerr.stack:\n${err.stack}`);
}
log(`[getGreatestBook] Book: ${JSON.stringify(data.toObject())}`);
resolve();
});
for (let i = 0; i < 10; i++) {
const req = new GetBookRequest();
req.setIsbn(i);
log(`[getGreatestBook] Request: ${JSON.stringify(req.toObject())}`);
stream.write(req);
}
console.log(data);
stream.end();
});
for (let i = 0; i < 10; i++) {
const req = new GetBookRequest();
req.setIsbn(i);
stream.write(req);
}
stream.end();
};
function main() {
fetchBook(1);
// fetchBooksViaAuthor("DefaultAuthor");
// fetchGreatestBook();
// fetchBooks();
async function main() {
await getBook(1);
await getBooks();
await getBooksViaAuthor("DefaultAuthor");
await getGreatestBook();
}
main();
main().then((_) => _);
process.on("uncaughtException", (err) => {
log(`process on uncaughtException error: ${err}`);
});
process.on("unhandledRejection", (err) => {
log(`process on unhandledRejection error: ${err}`);
});
// package: com.book
// file: book.proto
/* tslint:disable */
import * as grpc from "grpc";

@@ -5,0 +7,0 @@ import * as book_pb from "./book_pb";

// package: com.book
// file: book.proto
/* tslint:disable */
import * as jspb from "google-protobuf";

@@ -5,0 +7,0 @@

@@ -0,5 +1,11 @@

#!/usr/bin/env node
import * as debug from "debug";
import * as grpc from "grpc";
import { BookServiceService } from "./proto/book_grpc_pb";
import { Book, GetBookRequest, GetBookViaAuthor } from "./proto/book_pb";
const log = debug("SampleServer");
function startServer() {

@@ -10,2 +16,11 @@

server.addService(BookServiceService, {
getBook: (call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData) => {
const book = new Book();
book.setTitle("DefaultBook");
book.setAuthor("DefaultAuthor");
log(`[getBook] Done: ${JSON.stringify(book.toObject())}`);
callback(null, book);
},
getBooks: (call: grpc.ServerDuplexStream) => {

@@ -17,21 +32,14 @@ call.on("data", (request: GetBookRequest) => {

reply.setIsbn(request.getIsbn());
log(`[getBooks] Write: ${JSON.stringify(reply.toObject())}`);
call.write(reply);
});
call.on("end", () => {
console.log("getBooks done.");
log("[getBooks] Done.");
call.end();
});
},
getBook: (call: grpc.ServerUnaryCall, callback: grpc.sendUnaryData) => {
const book = new Book();
book.setTitle("DefaultBook");
book.setAuthor("DefaultAuthor");
callback(null, book);
},
getBooksViaAuthor: (call: grpc.ServerWriteableStream) => {
const request = call.request as GetBookViaAuthor;
console.log("getBooksViaAuthor request:", request.toObject());
log(`[getBooksViaAuthor] Request: ${JSON.stringify(request.toObject())}`);
for (let i = 1; i <= 10; i++) {

@@ -42,6 +50,6 @@ const reply = new Book();

reply.setIsbn(i);
console.log("getBooksViaAuthor write:", reply.toObject());
log(`[getBooksViaAuthor] Write: ${JSON.stringify(reply.toObject())}`);
call.write(reply);
}
console.log("getBooksViaAuthor done.");
log("[getBooksViaAuthor] Done.");
call.end();

@@ -52,3 +60,3 @@ },

call.on("data", (request: GetBookRequest) => {
console.log("getGreatestBook:", request.toObject());
log(`[getGreatestBook] Request: ${JSON.stringify(request.toObject())}`);
lastOne = request;

@@ -61,13 +69,22 @@ });

reply.setAuthor("LastOne");
console.log("getGreatestBook done:", reply.toObject());
log(`[getGreatestBook] Done: ${JSON.stringify(reply.toObject())}`);
callback(null, reply);
});
}
},
});
server.bind("0.0.0.0:50051", grpc.ServerCredentials.createInsecure());
server.bind("127.0.0.1:50051", grpc.ServerCredentials.createInsecure());
server.start();
server.start();
log("Server started, listening: 127.0.0.1:50051");
}
startServer();
startServer();
process.on("uncaughtException", (err) => {
log(`process on uncaughtException error: ${err}`);
});
process.on("unhandledRejection", (err) => {
log(`process on unhandledRejection error: ${err}`);
});
{
"name": "grpc_tools_node_protoc_ts",
"version": "2.1.0",
"version": "2.1.1",
"description": "Generate d.ts definitions for generated js files from grpc_tools_node_protoc",

@@ -38,3 +38,3 @@ "main": "build/index.js",

"@types/handlebars": "^4.0.36",
"@types/node": "^7.0.52",
"@types/node": "^9.4.2",
"@types/protobufjs": "^6.0.0",

@@ -41,0 +41,0 @@ "protobufjs": "^6.8.4"

@@ -7,6 +7,18 @@ grpc_tools_node_protoc_ts

## Note
This tools is using an unofficial grpc.d.ts definition, see: [grpc-tsd](https://www.npmjs.com/package/grpc-tsd).
If you want to use this tool, you have to use definition mentioned.
More information about grpc_tools_node_protoc:
* [npm](https://www.npmjs.com/package/grpc-tools)
* [source code](https://github.com/grpc/grpc-node/tree/master/packages/grpc-tools)
* [doc how to use](https://github.com/grpc/grpc/blob/master/examples/node/static_codegen/README.md)
## Breaking changes
Since v2.x.x, current project supports the official definition of grpc, see: [index.d.ts](https://github.com/grpc/grpc-node/blob/v1.8.x/packages/grpc-native-core/index.d.ts).
Though the usage of tool, and generated codes shall not been changed, it's good to be double checked in your project when upgrade.
TSLint has been disabled in generated files. Please see the conversation: [#13](https://github.com/agreatfool/grpc_tools_node_protoc_ts/issues/13).
~~## Note~~
~~This tools is using an unofficial grpc.d.ts definition, see: [grpc-tsd](https://www.npmjs.com/package/grpc-tsd).~~
~~If you want to use this tool, you have to use definition mentioned.~~
## How to use

@@ -33,2 +45,34 @@ ```bash

## Sample
There is a complete & runnable sample in folder `examples`.
Dirs:
* proto: sample proto definition
* bash: useful commands
* build.sh: build js & d.ts codes from proto file, and tsc to build/*.js
* server.sh: start the sample server
* client.sh: start the client & send requests
### Note
In current grpc version:
> $ npm view grpc time
...
'1.8.4': '2018-01-18T15:17:25.731Z',
'1.9.0-pre3': '2018-02-02T17:38:06.018Z' }
There is some definition confliction, and affects examples codes.
This possible be the issue of version confliction of protobuf.js in grpc and the newer version used outside.
See: [grpc package.json](https://github.com/grpc/grpc-node/blob/v1.8.x/packages/grpc-native-core/package.json#L35) and [grpc_tools_node_protoc_ts package.json](https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/v2.1.0/package.json#L40)
The result is, when you tsc under examples, there is some error:
> $ cd ./examples
$ ./bash/build.sh
src/server.ts(15,21): error TS2345: Argument of type 'IBookServiceService' is not assignable to parameter of type 'Service'.
Property 'methods' is missing in type 'IBookServiceService'.
Please ignore it, if dir examples is copied to any other place from current project root, it works fine. Anyway even with these errors, js codes from tsc also works fine.
### book.proto

@@ -79,2 +123,4 @@ ```proto

/* tslint:disable */
import * as jspb from "google-protobuf";

@@ -192,6 +238,8 @@

/* tslint:disable */
import * as grpc from "grpc";
import * as book_pb from "./book_pb";
interface IBookServiceService extends grpc.IMethodsMap {
interface IBookServiceService extends grpc.ServiceDefinition {
getBook: IGetBook;

@@ -207,4 +255,4 @@ getBooksViaAuthor: IGetBooksViaAuthor;

responseStream: boolean; // false
requestType: book_pb.GetBookRequest,
responseType: book_pb.Book,
requestType: book_pb.GetBookRequest;
responseType: book_pb.Book;
requestSerialize: (arg: book_pb.GetBookRequest) => Buffer;

@@ -219,4 +267,4 @@ requestDeserialize: (buffer: Uint8Array) => book_pb.GetBookRequest;

responseStream: boolean; // true
requestType: book_pb.GetBookViaAuthor,
responseType: book_pb.Book,
requestType: book_pb.GetBookViaAuthor;
responseType: book_pb.Book;
requestSerialize: (arg: book_pb.GetBookViaAuthor) => Buffer;

@@ -231,4 +279,4 @@ requestDeserialize: (buffer: Uint8Array) => book_pb.GetBookViaAuthor;

responseStream: boolean; // false
requestType: book_pb.GetBookRequest,
responseType: book_pb.Book,
requestType: book_pb.GetBookRequest;
responseType: book_pb.Book;
requestSerialize: (arg: book_pb.GetBookRequest) => Buffer;

@@ -243,4 +291,4 @@ requestDeserialize: (buffer: Uint8Array) => book_pb.GetBookRequest;

responseStream: boolean; // true
requestType: book_pb.GetBookRequest,
responseType: book_pb.Book,
requestType: book_pb.GetBookRequest;
responseType: book_pb.Book;
requestSerialize: (arg: book_pb.GetBookRequest) => Buffer;

@@ -264,3 +312,3 @@ requestDeserialize: (buffer: Uint8Array) => book_pb.GetBookRequest;

export class BookServiceClient extends grpc.Client implements IBookServiceClient {
constructor(address: string, credentials: any, options?: grpc.IClientOptions);
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;

@@ -271,4 +319,3 @@ public getBook(request: book_pb.GetBookRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: book_pb.Book) => void): grpc.ClientUnaryCall;

public getGreatestBook(callback: (error: Error | null, metadata: grpc.Metadata, response: book_pb.Book) => void): grpc.ClientWritableStream;
public getBooks(): grpc.ClientDuplexStream;
public getBooks(metadata: grpc.Metadata): grpc.ClientDuplexStream;
public getBooks(metadata?: grpc.Metadata): grpc.ClientDuplexStream;
}

@@ -280,9 +327,11 @@ ```

node --version
# v8.0.0
# v8.4.0
npm --version
# 5.0.3
# 5.2.0
protoc --version
# libprotoc 3.3.0
grpc_tools_node_protoc --version
# libprotoc 3.3.0
# libprotoc 3.4.0
npm list -g --depth=0 | grep grpc-tools
# grpc-tools@1.6.6
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc