grpc-promise
Advanced tools
Comparing version 1.3.0 to 1.3.1
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('../lib/index'); // require('grpc-promise') | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -11,3 +25,4 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
grpc_promise.promisifyAll(client, {timeout: 100, metadata: meta}); // Optional timeout definition, defaults = 50 | ||
// Optional timeout definition, defaults = 50 | ||
grpc_promise.promisifyAll(client, { timeout: 100, metadata: meta, deadline: Date.now() + 1000 }); | ||
@@ -14,0 +29,0 @@ let t = client.testStreamStream(); |
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('../lib/index'); // require('grpc-promise') | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -11,3 +25,3 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
grpc_promise.promisifyAll(client, {metadata: meta}); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
@@ -14,0 +28,0 @@ client.testStreamSimple(meta) |
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('../lib/index'); // require('grpc-promise') | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -11,3 +25,3 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
grpc_promise.promisify(client, ['testSimpleSimple'], {metadata: meta}); | ||
grpc_promise.promisify(client, ['testSimpleSimple'], { metadata: meta, deadline: Date.now() + 1000 }); | ||
@@ -14,0 +28,0 @@ client.testSimpleSimple() |
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('../lib/index'); // require('grpc-promise') | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -11,3 +25,3 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
grpc_promise.promisifyAll(client, {metadata: meta}); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
@@ -14,0 +28,0 @@ client.testSimpleStream() |
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('../lib/index'); // require('grpc-promise') | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -11,3 +25,3 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
grpc_promise.promisifyAll(client, {metadata: meta}); | ||
grpc_promise.promisifyAll(client, { metadata: meta, deadline: Date.now() + 1000 }); | ||
@@ -14,0 +28,0 @@ client.testSimpleSimple() |
const grpc = require('grpc'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
const testSimpleSimple = function (call, callback) { | ||
@@ -5,0 +19,0 @@ console.log('Server: Simple Message Received = ', call.request); // Server: Simple Message Received = {id: 1} |
@@ -13,3 +13,3 @@ | ||
this.timeout = options.timeout || 50; | ||
this.stream = original_function.call(client, options.metadata); | ||
this.stream = original_function.call(client, options.metadata, { deadline: options.deadline }); | ||
@@ -16,0 +16,0 @@ this.stream.on('error', () => {}); |
@@ -7,3 +7,3 @@ | ||
this.promise = new Promise((resolve, reject) => { | ||
this.stream = original_function.call(client, options.metadata, function (error, response) { | ||
this.stream = original_function.call(client, options.metadata, { deadline: options.deadline }, function (error, response) { | ||
if (error) { | ||
@@ -10,0 +10,0 @@ reject(error); |
@@ -9,2 +9,3 @@ | ||
this.metadata = options.metadata; | ||
this.deadline = options.deadline || undefined; | ||
this.original_function = original_function; | ||
@@ -15,3 +16,3 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.stream = this.original_function.call(this.client, content, this.metadata); | ||
this.stream = this.original_function.call(this.client, content, this.metadata, { deadline: this.deadline }); | ||
this.stream.on('error', error => { | ||
@@ -18,0 +19,0 @@ reject(error); |
@@ -8,2 +8,3 @@ | ||
this.metadata = options.metadata; | ||
this.deadline = options.deadline || undefined; | ||
this.original_function = original_function; | ||
@@ -14,9 +15,11 @@ } | ||
return new Promise((resolve, reject) => { | ||
this.original_function.call(this.client, content, this.metadata, function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
this.original_function.call(this.client, content, this.metadata, { deadline: this.deadline }, | ||
function (error, response) { | ||
if (error) { | ||
reject(error); | ||
} else { | ||
resolve(response); | ||
} | ||
} | ||
}); | ||
); | ||
}); | ||
@@ -28,2 +31,3 @@ } | ||
const makeUnaryRequest = function (client, originalFunction, options) { | ||
// console.log(options); | ||
return function () { | ||
@@ -30,0 +34,0 @@ return new UnaryRequest(client, originalFunction, options); |
{ | ||
"name": "grpc-promise", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "GRPC promisify module for all Request/Response types: standard and stream", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
156
README.md
@@ -21,2 +21,3 @@ # grpc-promise | ||
- [Request with Metadata](#request-with-metadata) | ||
- [Using Deadline](#using-deadline) | ||
- [Promisify single function](#promisify-single-function) | ||
@@ -107,4 +108,18 @@ - [MIT License](#mit-license) | ||
const grpc = require('grpc'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
const testSimpleSimple = function (call, callback) { | ||
@@ -132,5 +147,19 @@ console.log('Server: Simple Message Received = ', call.request); // Server: Simple Message Received = {id: 1} | ||
const grpc = require('grpc'); | ||
const grpc_promise = require('grpc-promise'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('grpc-promise');; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -161,4 +190,18 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
const grpc = require('grpc'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
const testStreamSimple = function (call, callback) { | ||
@@ -192,5 +235,19 @@ var messages = []; | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('grpc-promise'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -224,4 +281,18 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
const grpc = require('grpc'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
const testSimpleStream = function (call) { | ||
@@ -251,5 +322,19 @@ console.log('Server: Simple Message Received = ', call.request); // Server: Simple Message Received = {id: 1} | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('grpc-promise'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -283,4 +368,18 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
const grpc = require('grpc'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
const testStreamStream = function (call) { | ||
@@ -318,5 +417,19 @@ call.on('data', function (message) { | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('grpc-promise'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -352,5 +465,19 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
const grpc = require('grpc'); | ||
const protoLoader = require('@grpc/proto-loader'); | ||
const grpc_promise = require('grpc-promise'); | ||
const test_proto = grpc.load(__dirname + '/protobuf/test.proto').test; | ||
const packageDefinition = protoLoader.loadSync( | ||
__dirname + '/protobuf/test.proto', | ||
{ | ||
keepCase: true, | ||
longs: String, | ||
enums: String, | ||
defaults: true, | ||
oneofs: true | ||
} | ||
); | ||
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition); | ||
const test_proto = protoDescriptor.test; | ||
function main() { | ||
@@ -376,2 +503,11 @@ const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure()); | ||
### Using Deadline | ||
The deadline parameter is used to to set a timestamp in millisenconds for the entire call to complete: | ||
```js | ||
// We give a deadline of 1 second (= 1000ms) | ||
grpc_promise.promisifyAll(client, deadline: Date.now() + 1000); | ||
``` | ||
### Promisify single function | ||
@@ -378,0 +514,0 @@ |
@@ -10,3 +10,3 @@ const ClientStreamMock = require('../../tools/grpc-mock/ClientStreamMock'); | ||
const client = {}; | ||
const makeClientStreamRequest = function (metadata, callback) { | ||
const makeClientStreamRequest = function (metadata, options, callback) { | ||
return new ClientStreamMock({callback: callback}); | ||
@@ -33,3 +33,3 @@ }; | ||
const client = {}; | ||
const makeClientStreamRequest = function (metadata, callback) { | ||
const makeClientStreamRequest = function (metadata, options, callback) { | ||
var stream = new ClientStreamMock(); | ||
@@ -65,3 +65,3 @@ stream.on('finish', function () { | ||
const client = {}; | ||
const makeClientStreamRequest = function (metadata, callback) { | ||
const makeClientStreamRequest = function (metadata, options, callback) { | ||
return new ClientStreamMock({callback: callback}); | ||
@@ -68,0 +68,0 @@ }; |
@@ -9,3 +9,3 @@ const grpc_promise = require('../../../lib/index'); | ||
const client = {}; | ||
const makeUnaryRequest = function (request, metadata, callback) { | ||
const makeUnaryRequest = function (request, metadata, options, callback) { | ||
callback(null, request); | ||
@@ -28,3 +28,3 @@ }; | ||
const client = {}; | ||
const makeUnaryRequest = function (request, metadata, callback) { | ||
const makeUnaryRequest = function (request, metadata, options, callback) { | ||
callback('timeout'); | ||
@@ -53,3 +53,3 @@ }; | ||
const client = {}; | ||
const makeUnaryRequest = function (request, metadata, callback) { | ||
const makeUnaryRequest = function (request, metadata, options, callback) { | ||
callback(null, request); | ||
@@ -56,0 +56,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48341
957
552