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

grpc-ts-health-check

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-ts-health-check - npm Package Compare versions

Comparing version 1.0.14 to 2.0.0-beta.0

16

index.d.ts
import * as grpc from 'grpc';
import { HealthClient, HealthService } from './src/proto/health_grpc_pb';
import { HealthClient, HealthService, IHealthServer } from './src/proto/health_grpc_pb';
import { HealthCheckRequest, HealthCheckResponse } from './src/proto/health_pb';
declare class GrpcHealthCheck {
declare class GrpcHealthCheck implements IHealthServer {
constructor(statusMap: { [key: string]: number });
setStatus(service: string, status: number): void;
check(
private setStatus(service: string, status: HealthCheckResponse.ServingStatus): void;
private sendStatusResponse(
call: grpc.ServerWriteableStream<HealthCheckRequest>,
status: HealthCheckResponse.ServingStatus,
callback?: (error: Error | null | undefined) => void
): void;
public check(
call: grpc.ServerUnaryCall<HealthCheckRequest>,
callback: grpc.sendUnaryData<HealthCheckResponse>
): void;
public watch(
call: grpc.ServerWriteableStream<HealthCheckRequest>
): void;
}
export { GrpcHealthCheck, HealthCheckRequest, HealthCheckResponse, HealthClient, HealthService };
{
"name": "grpc-ts-health-check",
"version": "1.0.14",
"version": "2.0.0-beta.0",
"description": "An implementation of gRPC health checks, written in typescript.",

@@ -11,3 +11,5 @@ "main": "src/index.js",

"tslint": "tslint --fix -c tslint.json -p tsconfig.json",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"ncu": "ncu",
"ncu:u": "ncu -u"
},

@@ -29,15 +31,16 @@ "keywords": [

"dependencies": {
"google-protobuf": "~3.7.1",
"grpc-boom": "~1.0.21"
"google-protobuf": "~3.9.0",
"grpc-boom": "~1.0.23"
},
"devDependencies": {
"@types/google-protobuf": "~3.2.7",
"@types/node": "~12.0.2",
"grpc": "~1.20.3",
"prettier": "~1.17.1",
"@types/google-protobuf": "~3.7.1",
"@types/node": "~12.6.8",
"grpc": "~1.22.2",
"npm-check-updates": "~3.1.20",
"prettier": "~1.18.2",
"protobufjs": "~6.8.8",
"ts-node": "~8.1.0",
"tslint": "~5.16.0",
"typescript": "~3.4.5"
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.5.3"
}
}

@@ -49,3 +49,3 @@ # gRPC Health Check

const grpcHealthCheck = new GrpcHealthCheck(healthCheckStatusMap);
grpcHealthCheck.setStatus(serviceName, HealthCheckResponse.ServingStatus.SERVING);
grpcHealthCheck.watch(serviceName);
server.addService(HealthService, grpcHealthCheck);

@@ -52,0 +52,0 @@

@@ -16,2 +16,4 @@ "use strict";

this.statusMap = statusMap;
this.watchStatusMap = {};
this.watchErrorMap = {};
}

@@ -21,2 +23,7 @@ setStatus(service, status) {

}
sendStatusResponse(call, status, callback) {
const response = new health_pb_1.HealthCheckResponse();
response.setStatus(status);
call.write(response, callback);
}
check(call, callback) {

@@ -26,3 +33,3 @@ const service = call.request.getService();

if (!status) {
callback(grpc_boom_1.default.notFound(`Status not found for service: ${service}`), null);
callback(grpc_boom_1.default.notFound(`Unknown service: ${service}`), null);
}

@@ -35,3 +42,36 @@ else {

}
watch(call) {
const service = call.request.getService();
let updatedStatus = health_pb_1.HealthCheckResponse.ServingStatus.SERVING;
if (!this.statusMap[service]) {
updatedStatus = health_pb_1.HealthCheckResponse.ServingStatus.SERVICE_UNKNOWN;
this.setStatus(service, updatedStatus);
this.sendStatusResponse(call, updatedStatus);
}
else {
updatedStatus = this.statusMap[service];
}
this.watchStatusMap[service] = updatedStatus;
let lastStatus = -1;
if (!this.watchErrorMap[service]) {
console.log('Next Tick');
const callback = () => {
lastStatus = this.statusMap[service];
if (lastStatus !== updatedStatus) {
console.log('Sending Status: ' + updatedStatus);
this.setStatus(service, updatedStatus);
this.sendStatusResponse(call, updatedStatus, (error) => {
if (error) {
this.watchErrorMap[service] = error;
}
});
}
};
process.nextTick(callback);
}
else {
call.end(this.watchErrorMap[service]);
}
}
}
exports.GrpcHealthCheck = GrpcHealthCheck;

@@ -9,3 +9,3 @@ // package: grpc.health.v1

check: IHealthService_ICheck;
setStatus: IHealthService_ISetStatus;
watch: IHealthService_IWatch;
}

@@ -23,10 +23,10 @@

interface IHealthService_ISetStatus {
path: string; // "/grpc.health.v1.Health/SetStatus"
interface IHealthService_IWatch {
path: string; // "/grpc.health.v1.Health/Watch"
requestStream: boolean; // false
responseStream: boolean; // false
requestSerialize: grpc.serialize<health_pb.SetStatusRequest>;
requestDeserialize: grpc.deserialize<health_pb.SetStatusRequest>;
responseSerialize: grpc.serialize<health_pb.SetStatusResponse>;
responseDeserialize: grpc.deserialize<health_pb.SetStatusResponse>;
responseStream: boolean; // true
requestSerialize: grpc.serialize<health_pb.HealthCheckRequest>;
requestDeserialize: grpc.deserialize<health_pb.HealthCheckRequest>;
responseSerialize: grpc.serialize<health_pb.HealthCheckResponse>;
responseDeserialize: grpc.deserialize<health_pb.HealthCheckResponse>;
}

@@ -37,3 +37,3 @@

check: grpc.handleUnaryCall<health_pb.HealthCheckRequest, health_pb.HealthCheckResponse>;
setStatus: grpc.handleUnaryCall<health_pb.SetStatusRequest, health_pb.SetStatusResponse>;
watch: grpc.handleServerStreamingCall<health_pb.HealthCheckRequest, health_pb.HealthCheckResponse>;
}

@@ -44,4 +44,3 @@

check(request: health_pb.HealthCheckRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: health_pb.HealthCheckResponse) => void): grpc.ClientUnaryCall;
setStatus(request: health_pb.SetStatusRequest, callback: (error: Error | null, response: health_pb.SetStatusResponse) => void): grpc.ClientUnaryCall;
setStatus(request: health_pb.SetStatusRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: health_pb.SetStatusResponse) => void): grpc.ClientUnaryCall;
watch(request: health_pb.HealthCheckRequest, metadata?: grpc.Metadata): grpc.ClientReadableStream<health_pb.HealthCheckResponse>;
}

@@ -53,5 +52,4 @@

public check(request: health_pb.HealthCheckRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: health_pb.HealthCheckResponse) => void): grpc.ClientUnaryCall;
public setStatus(request: health_pb.SetStatusRequest, callback: (error: Error | null, response: health_pb.SetStatusResponse) => void): grpc.ClientUnaryCall;
public setStatus(request: health_pb.SetStatusRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: health_pb.SetStatusResponse) => void): grpc.ClientUnaryCall;
public watch(request: health_pb.HealthCheckRequest, metadata?: grpc.Metadata): grpc.ClientReadableStream<health_pb.HealthCheckResponse>;
}

@@ -11,3 +11,3 @@ // GENERATED CODE -- DO NOT EDIT!

}
return new Buffer(arg.serializeBinary());
return Buffer.from(arg.serializeBinary());
}

@@ -23,3 +23,3 @@

}
return new Buffer(arg.serializeBinary());
return Buffer.from(arg.serializeBinary());
}

@@ -31,26 +31,6 @@

function serialize_grpc_health_v1_SetStatusRequest(arg) {
if (!(arg instanceof health_pb.SetStatusRequest)) {
throw new Error('Expected argument of type grpc.health.v1.SetStatusRequest');
}
return new Buffer(arg.serializeBinary());
}
function deserialize_grpc_health_v1_SetStatusRequest(buffer_arg) {
return health_pb.SetStatusRequest.deserializeBinary(new Uint8Array(buffer_arg));
}
function serialize_grpc_health_v1_SetStatusResponse(arg) {
if (!(arg instanceof health_pb.SetStatusResponse)) {
throw new Error('Expected argument of type grpc.health.v1.SetStatusResponse');
}
return new Buffer(arg.serializeBinary());
}
function deserialize_grpc_health_v1_SetStatusResponse(buffer_arg) {
return health_pb.SetStatusResponse.deserializeBinary(new Uint8Array(buffer_arg));
}
var HealthService = exports.HealthService = {
// If the requested service is unknown, the call will fail with status
// NOT_FOUND.
check: {

@@ -67,12 +47,27 @@ path: '/grpc.health.v1.Health/Check',

},
setStatus: {
path: '/grpc.health.v1.Health/SetStatus',
// Performs a watch for the serving status of the requested service.
// The server will immediately send back a message indicating the current
// serving status. It will then subsequently send a new message whenever
// the service's serving status changes.
//
// If the requested service is unknown when the call is received, the
// server will send a message setting the serving status to
// SERVICE_UNKNOWN but will *not* terminate the call. If at some
// future point, the serving status of the service becomes known, the
// server will send a new message with the service's serving status.
//
// If the call terminates with status UNIMPLEMENTED, then clients
// should assume this method is not supported and should not retry the
// call. If the call terminates with any other status (including OK),
// clients should retry the call with appropriate exponential back-off.
watch: {
path: '/grpc.health.v1.Health/Watch',
requestStream: false,
responseStream: false,
requestType: health_pb.SetStatusRequest,
responseType: health_pb.SetStatusResponse,
requestSerialize: serialize_grpc_health_v1_SetStatusRequest,
requestDeserialize: deserialize_grpc_health_v1_SetStatusRequest,
responseSerialize: serialize_grpc_health_v1_SetStatusResponse,
responseDeserialize: deserialize_grpc_health_v1_SetStatusResponse,
responseStream: true,
requestType: health_pb.HealthCheckRequest,
responseType: health_pb.HealthCheckResponse,
requestSerialize: serialize_grpc_health_v1_HealthCheckRequest,
requestDeserialize: deserialize_grpc_health_v1_HealthCheckRequest,
responseSerialize: serialize_grpc_health_v1_HealthCheckResponse,
responseDeserialize: deserialize_grpc_health_v1_HealthCheckResponse,
},

@@ -79,0 +74,0 @@ };

@@ -49,44 +49,5 @@ // package: grpc.health.v1

NOT_SERVING = 2,
SERVICE_UNKNOWN = 3,
}
}
export class SetStatusRequest extends jspb.Message {
getService(): string;
setService(value: string): void;
getStatus(): number;
setStatus(value: number): void;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SetStatusRequest.AsObject;
static toObject(includeInstance: boolean, msg: SetStatusRequest): SetStatusRequest.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: SetStatusRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SetStatusRequest;
static deserializeBinaryFromReader(message: SetStatusRequest, reader: jspb.BinaryReader): SetStatusRequest;
}
export namespace SetStatusRequest {
export type AsObject = {
service: string,
status: number,
}
}
export class SetStatusResponse extends jspb.Message {
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): SetStatusResponse.AsObject;
static toObject(includeInstance: boolean, msg: SetStatusResponse): SetStatusResponse.AsObject;
static extensions: {[key: number]: jspb.ExtensionFieldInfo<jspb.Message>};
static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo<jspb.Message>};
static serializeBinaryToWriter(message: SetStatusResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): SetStatusResponse;
static deserializeBinaryFromReader(message: SetStatusResponse, reader: jspb.BinaryReader): SetStatusResponse;
}
export namespace SetStatusResponse {
export type AsObject = {
}
}

@@ -17,4 +17,2 @@ /**

goog.exportSymbol('proto.grpc.health.v1.HealthCheckResponse.ServingStatus', null, global);
goog.exportSymbol('proto.grpc.health.v1.SetStatusRequest', null, global);
goog.exportSymbol('proto.grpc.health.v1.SetStatusResponse', null, global);

@@ -158,3 +156,3 @@ /**

proto.grpc.health.v1.HealthCheckRequest.prototype.setService = function(value) {
jspb.Message.setField(this, 1, value);
jspb.Message.setProto3StringField(this, 1, value);
};

@@ -296,3 +294,4 @@

SERVING: 1,
NOT_SERVING: 2
NOT_SERVING: 2,
SERVICE_UNKNOWN: 3
};

@@ -311,291 +310,6 @@

proto.grpc.health.v1.HealthCheckResponse.prototype.setStatus = function(value) {
jspb.Message.setField(this, 1, value);
jspb.Message.setProto3EnumField(this, 1, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.grpc.health.v1.SetStatusRequest = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.grpc.health.v1.SetStatusRequest, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.grpc.health.v1.SetStatusRequest.displayName = 'proto.grpc.health.v1.SetStatusRequest';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.grpc.health.v1.SetStatusRequest.prototype.toObject = function(opt_includeInstance) {
return proto.grpc.health.v1.SetStatusRequest.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.grpc.health.v1.SetStatusRequest} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.grpc.health.v1.SetStatusRequest.toObject = function(includeInstance, msg) {
var f, obj = {
service: jspb.Message.getFieldWithDefault(msg, 1, ""),
status: jspb.Message.getFieldWithDefault(msg, 2, 0)
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.grpc.health.v1.SetStatusRequest}
*/
proto.grpc.health.v1.SetStatusRequest.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.grpc.health.v1.SetStatusRequest;
return proto.grpc.health.v1.SetStatusRequest.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.grpc.health.v1.SetStatusRequest} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.grpc.health.v1.SetStatusRequest}
*/
proto.grpc.health.v1.SetStatusRequest.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
case 1:
var value = /** @type {string} */ (reader.readString());
msg.setService(value);
break;
case 2:
var value = /** @type {number} */ (reader.readInt32());
msg.setStatus(value);
break;
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.grpc.health.v1.SetStatusRequest.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.grpc.health.v1.SetStatusRequest.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.grpc.health.v1.SetStatusRequest} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.grpc.health.v1.SetStatusRequest.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
f = message.getService();
if (f.length > 0) {
writer.writeString(
1,
f
);
}
f = message.getStatus();
if (f !== 0) {
writer.writeInt32(
2,
f
);
}
};
/**
* optional string service = 1;
* @return {string}
*/
proto.grpc.health.v1.SetStatusRequest.prototype.getService = function() {
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
};
/** @param {string} value */
proto.grpc.health.v1.SetStatusRequest.prototype.setService = function(value) {
jspb.Message.setField(this, 1, value);
};
/**
* optional int32 status = 2;
* @return {number}
*/
proto.grpc.health.v1.SetStatusRequest.prototype.getStatus = function() {
return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0));
};
/** @param {number} value */
proto.grpc.health.v1.SetStatusRequest.prototype.setStatus = function(value) {
jspb.Message.setField(this, 2, value);
};
/**
* Generated by JsPbCodeGenerator.
* @param {Array=} opt_data Optional initial data array, typically from a
* server response, or constructed directly in Javascript. The array is used
* in place and becomes part of the constructed object. It is not cloned.
* If no data is provided, the constructed object will be empty, but still
* valid.
* @extends {jspb.Message}
* @constructor
*/
proto.grpc.health.v1.SetStatusResponse = function(opt_data) {
jspb.Message.initialize(this, opt_data, 0, -1, null, null);
};
goog.inherits(proto.grpc.health.v1.SetStatusResponse, jspb.Message);
if (goog.DEBUG && !COMPILED) {
proto.grpc.health.v1.SetStatusResponse.displayName = 'proto.grpc.health.v1.SetStatusResponse';
}
if (jspb.Message.GENERATE_TO_OBJECT) {
/**
* Creates an object representation of this proto suitable for use in Soy templates.
* Field names that are reserved in JavaScript and will be renamed to pb_name.
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
* For the list of reserved names please see:
* com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS.
* @param {boolean=} opt_includeInstance Whether to include the JSPB instance
* for transitional soy proto support: http://goto/soy-param-migration
* @return {!Object}
*/
proto.grpc.health.v1.SetStatusResponse.prototype.toObject = function(opt_includeInstance) {
return proto.grpc.health.v1.SetStatusResponse.toObject(opt_includeInstance, this);
};
/**
* Static version of the {@see toObject} method.
* @param {boolean|undefined} includeInstance Whether to include the JSPB
* instance for transitional soy proto support:
* http://goto/soy-param-migration
* @param {!proto.grpc.health.v1.SetStatusResponse} msg The msg instance to transform.
* @return {!Object}
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.grpc.health.v1.SetStatusResponse.toObject = function(includeInstance, msg) {
var f, obj = {
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
}
/**
* Deserializes binary data (in protobuf wire format).
* @param {jspb.ByteSource} bytes The bytes to deserialize.
* @return {!proto.grpc.health.v1.SetStatusResponse}
*/
proto.grpc.health.v1.SetStatusResponse.deserializeBinary = function(bytes) {
var reader = new jspb.BinaryReader(bytes);
var msg = new proto.grpc.health.v1.SetStatusResponse;
return proto.grpc.health.v1.SetStatusResponse.deserializeBinaryFromReader(msg, reader);
};
/**
* Deserializes binary data (in protobuf wire format) from the
* given reader into the given message object.
* @param {!proto.grpc.health.v1.SetStatusResponse} msg The message object to deserialize into.
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
* @return {!proto.grpc.health.v1.SetStatusResponse}
*/
proto.grpc.health.v1.SetStatusResponse.deserializeBinaryFromReader = function(msg, reader) {
while (reader.nextField()) {
if (reader.isEndGroup()) {
break;
}
var field = reader.getFieldNumber();
switch (field) {
default:
reader.skipField();
break;
}
}
return msg;
};
/**
* Serializes the message to binary data (in protobuf wire format).
* @return {!Uint8Array}
*/
proto.grpc.health.v1.SetStatusResponse.prototype.serializeBinary = function() {
var writer = new jspb.BinaryWriter();
proto.grpc.health.v1.SetStatusResponse.serializeBinaryToWriter(this, writer);
return writer.getResultBuffer();
};
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
* @param {!proto.grpc.health.v1.SetStatusResponse} message
* @param {!jspb.BinaryWriter} writer
* @suppress {unusedLocalVariables} f is only used for nested messages
*/
proto.grpc.health.v1.SetStatusResponse.serializeBinaryToWriter = function(message, writer) {
var f = undefined;
};
goog.object.extend(exports, proto.grpc.health.v1);

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