grpc-helper
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -10,5 +10,18 @@ /// <reference types="node" /> | ||
export interface GRPCHelperSslOpts { | ||
/** | ||
* Whether enable ssl | ||
* Default: false | ||
*/ | ||
enable: boolean; | ||
/** | ||
* CA cert in buffer | ||
*/ | ||
cacert?: Buffer; | ||
/** | ||
* cert in buffer | ||
*/ | ||
cert?: Buffer; | ||
/** | ||
* key in buffer | ||
*/ | ||
key?: Buffer; | ||
@@ -25,3 +38,11 @@ } | ||
export interface GRPCHelperCheck { | ||
/** | ||
* Whether enable health check | ||
* Default: true | ||
*/ | ||
enable: boolean; | ||
/** | ||
* Timeout for health check call | ||
* Default: 5000 | ||
*/ | ||
timeoutInMS?: number; | ||
@@ -173,2 +194,3 @@ } | ||
* If set to 0, timeout is disabled | ||
* Default: 5000 | ||
*/ | ||
@@ -175,0 +197,0 @@ timeoutInMS?: number; |
@@ -22,2 +22,9 @@ /// <reference types="node" /> | ||
export declare class DNSResolver implements Resolver { | ||
parseUrl(target: string): any; | ||
/** | ||
* Resolve the dns src records | ||
* #### Curreny available query params: | ||
* - [intervalMs=5000] number, determines how frequent the dns resolver lookup the srv records | ||
* @param {string} target In the format of _grpc._tcp.service-name[?intervalMs=5000] | ||
*/ | ||
resolve(target: string): Watcher; | ||
@@ -29,7 +36,7 @@ } | ||
export declare class DNSWatcher extends EventEmitter implements Watcher { | ||
private interval; | ||
private intervalMs; | ||
private addrMap; | ||
private resolveAddrs; | ||
private updates; | ||
constructor(resolveAddrs: () => Promise<Address[]>); | ||
constructor(resolveAddrs: () => Promise<Address[]>, intervalMs?: number); | ||
private update; | ||
@@ -36,0 +43,0 @@ next(): Promise<Update[]>; |
@@ -52,2 +52,4 @@ "use strict"; | ||
var dns = require("dns"); | ||
var url = require("url"); | ||
var qs = require("qs"); | ||
var events_1 = require("events"); | ||
@@ -57,2 +59,3 @@ var Bluebird = require("bluebird"); | ||
var _ = require("lodash"); | ||
var common_1 = require("./common"); | ||
Promise = Bluebird; | ||
@@ -68,3 +71,17 @@ var log = debug('grpcHelper:naming'); | ||
} | ||
DNSResolver.prototype.parseUrl = function (target) { | ||
var _a = url.parse(target), query = _a.query, pathname = _a.pathname; | ||
if (!pathname) | ||
throw new common_1.GRPCHelperError('invalid pathname'); | ||
return { pathname: pathname, query: qs.parse(query) }; | ||
}; | ||
/** | ||
* Resolve the dns src records | ||
* #### Curreny available query params: | ||
* - [intervalMs=5000] number, determines how frequent the dns resolver lookup the srv records | ||
* @param {string} target In the format of _grpc._tcp.service-name[?intervalMs=5000] | ||
*/ | ||
DNSResolver.prototype.resolve = function (target) { | ||
var _a = this.parseUrl(target), pathname = _a.pathname, query = _a.query; | ||
log('parse target into basename %s, query %j', pathname, query); | ||
return new DNSWatcher(function () { | ||
@@ -77,3 +94,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
resolveSrv = Promise.promisify(dns.resolveSrv); | ||
return [4 /*yield*/, resolveSrv(target)]; | ||
return [4 /*yield*/, resolveSrv(pathname)]; | ||
case 1: | ||
@@ -89,3 +106,3 @@ recoreds = _a.sent(); | ||
}); | ||
}); | ||
}, query.intervalMs); | ||
}; | ||
@@ -118,7 +135,8 @@ return DNSResolver; | ||
__extends(DNSWatcher, _super); | ||
function DNSWatcher(resolveAddrs) { | ||
function DNSWatcher(resolveAddrs, intervalMs) { | ||
if (intervalMs === void 0) { intervalMs = 5000; } | ||
var _this = _super.call(this) || this; | ||
_this.addrMap = {}; | ||
_this.updates = []; | ||
_this.interval = 100; | ||
_this.intervalMs = intervalMs; | ||
_this.resolveAddrs = resolveAddrs; | ||
@@ -158,3 +176,3 @@ _this.update(); | ||
this.addrMap = newAddrMap; | ||
setTimeout(this.update.bind(this), this.interval); | ||
setTimeout(this.update.bind(this), this.intervalMs); | ||
return [2 /*return*/]; | ||
@@ -167,10 +185,4 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var copy; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
if (this.updates.length) { | ||
copy = this.updates.slice(); | ||
this.updates = []; | ||
return [2 /*return*/, copy]; | ||
} | ||
log('wait for updates'); | ||
@@ -229,10 +241,4 @@ return [2 /*return*/, new Promise(function (resolve) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var copy; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
if (this.updates.length) { | ||
copy = this.updates.slice(); | ||
this.updates = []; | ||
return [2 /*return*/, copy]; | ||
} | ||
return [2 /*return*/, new Promise(function (resolve) { | ||
@@ -239,0 +245,0 @@ _this.once('updates', function () { |
{ | ||
"name": "grpc-helper", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "gRPC helper, an improved gRPC client for grpc-node", | ||
@@ -65,3 +65,3 @@ "main": "dist/src/index.js", | ||
"debug": "^3.1.0", | ||
"grpc": "^1.14.1", | ||
"grpc": "^1.14.2", | ||
"lodash": "^4.17.10", | ||
@@ -68,0 +68,0 @@ "prom-client": "^10.2.3" |
@@ -43,3 +43,4 @@ # gRPC helper | ||
protoPath: path.resolve(__dirname, './hello.proto'), | ||
sdUri: 'dns://_grpc._tcp.greeter', | ||
// intervalMs will determine how frequent the resolver lookup the records | ||
sdUri: 'dns://_grpc._tcp.greeter?intervalMs=5000', | ||
}); | ||
@@ -46,0 +47,0 @@ |
Sorry, the diff of this file is not supported yet
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
79165
1296
152
+ Added@types/node@22.9.1(transitive)
- Removed@types/node@22.9.3(transitive)
Updatedgrpc@^1.14.2