Socket
Socket
Sign inDemoInstall

@grpc/grpc-js

Package Overview
Dependencies
Maintainers
3
Versions
175
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grpc/grpc-js - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6

LICENSE

26

build/src/call-credentials-filter.js
"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 });

@@ -31,12 +23,10 @@ const filter_1 = require("./filter");

}
sendMetadata(metadata) {
return __awaiter(this, void 0, void 0, function* () {
const channelCredentials = this.channel.credentials._getCallCredentials();
const streamCredentials = this.stream.getCredentials();
const credentials = channelCredentials.compose(streamCredentials);
const credsMetadata = credentials.generateMetadata({ service_url: this.serviceUrl });
const resultMetadata = yield metadata;
resultMetadata.merge(yield credsMetadata);
return resultMetadata;
});
async sendMetadata(metadata) {
const channelCredentials = this.channel.credentials._getCallCredentials();
const streamCredentials = this.stream.getCredentials();
const credentials = channelCredentials.compose(streamCredentials);
const credsMetadata = credentials.generateMetadata({ service_url: this.serviceUrl });
const resultMetadata = await metadata;
resultMetadata.merge(await credsMetadata);
return resultMetadata;
}

@@ -43,0 +33,0 @@ }

"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 });

@@ -37,11 +29,9 @@ const metadata_1 = require("./metadata");

}
generateMetadata(options) {
return __awaiter(this, void 0, void 0, function* () {
const base = new metadata_1.Metadata();
const generated = yield Promise.all(this.creds.map((cred) => cred.generateMetadata(options)));
for (const gen of generated) {
base.merge(gen);
}
return base;
});
async generateMetadata(options) {
const base = new metadata_1.Metadata();
const generated = await Promise.all(this.creds.map((cred) => cred.generateMetadata(options)));
for (const gen of generated) {
base.merge(gen);
}
return base;
}

@@ -48,0 +38,0 @@ compose(other) {

@@ -28,3 +28,3 @@ /// <reference types="node" />

NoCompress = 2,
WriteThrough = 4,
WriteThrough = 4
}

@@ -81,11 +81,11 @@ export interface WriteObject {

*/
private endCall(status);
private handleFilterError(error);
private handleFilteredRead(message);
private filterReceivedMessage(framedMessage);
private tryPush(messageBytes);
private handleTrailers(headers);
private endCall;
private handleFilterError;
private handleFilteredRead;
private filterReceivedMessage;
private tryPush;
private handleTrailers;
attachHttp2Stream(stream: http2.ClientHttp2Stream): void;
sendMetadata(metadata: Metadata): void;
private destroyHttp2Stream();
private destroyHttp2Stream;
cancelWithStatus(status: Status, details: string): void;

@@ -92,0 +92,0 @@ getDeadline(): Deadline;

"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 });

@@ -73,2 +65,7 @@ const http2 = require("http2");

handleFilteredRead(message) {
/* If we the call has already ended, we don't want to do anything with
* this message. Dropping it on the floor is correct behavior */
if (this.finalStatus !== null) {
return;
}
this.isReadFilterPending = false;

@@ -92,2 +89,7 @@ if (this.canPush) {

filterReceivedMessage(framedMessage) {
/* If we the call has already ended, we don't want to do anything with
* this message. Dropping it on the floor is correct behavior */
if (this.finalStatus !== null) {
return;
}
if (framedMessage === null) {

@@ -125,3 +127,3 @@ if (this.canPush) {

const status = { code, details, metadata };
this.handlingTrailers = (() => __awaiter(this, void 0, void 0, function* () {
this.handlingTrailers = (async () => {
let finalStatus;

@@ -131,6 +133,6 @@ try {

finalStatus =
yield this.filterStack.receiveTrailers(Promise.resolve(status));
await this.filterStack.receiveTrailers(Promise.resolve(status));
}
catch (error) {
yield this.handlingHeaders;
await this.handlingHeaders;
// This is a no-op if the call was already ended when handling headers.

@@ -147,6 +149,6 @@ this.endCall({

// if an error occurred.
yield this.handlingHeaders;
await this.handlingHeaders;
// This is a no-op if the call was already ended when handling headers.
this.endCall(finalStatus);
}))();
})();
}

@@ -273,3 +275,3 @@ attachHttp2Stream(stream) {

});
stream.on('close', (errorCode) => __awaiter(this, void 0, void 0, function* () {
stream.on('close', async (errorCode) => {
let code;

@@ -297,3 +299,3 @@ let details = '';

// 'grpc-status' header takes precedence for emitted status data.
yield this.handlingTrailers;
await this.handlingTrailers;
// This is a no-op if trailers were received at all.

@@ -304,3 +306,3 @@ // This is OK, because status codes emitted here correspond to more

this.endCall({ code, details, metadata: new metadata_1.Metadata() });
}));
});
stream.on('error', (err) => {

@@ -341,8 +343,8 @@ this.endCall({

this.destroyHttp2Stream();
(() => __awaiter(this, void 0, void 0, function* () {
(async () => {
// If trailers are currently being processed, the call should be ended
// by handleTrailers instead.
yield this.handlingTrailers;
await this.handlingTrailers;
this.endCall({ code: status, details, metadata: new metadata_1.Metadata() });
}))();
})();
}

@@ -371,2 +373,8 @@ getDeadline() {

_read(size) {
/* If we have already emitted a status, we should not emit any more
* messages and we should communicate that the stream has ended */
if (this.finalStatus !== null) {
this.push(null);
return;
}
this.canPush = true;

@@ -373,0 +381,0 @@ if (this.http2Stream === null) {

@@ -12,3 +12,3 @@ /// <reference types="node" />

IDLE = 3,
SHUTDOWN = 4,
SHUTDOWN = 4
}

@@ -78,5 +78,5 @@ /**

private currentBackoffDeadline;
private handleStateChange(oldState, newState);
private transitionToState(oldStates, newState);
private startConnecting();
private handleStateChange;
private transitionToState;
private startConnecting;
constructor(address: string, credentials: ChannelCredentials, options: Partial<ChannelOptions>);

@@ -89,3 +89,3 @@ _startHttp2Stream(authority: string, methodName: string, stream: Http2CallStream, metadata: Metadata): void;

*/
private connect();
private connect;
getConnectivityState(tryToConnect: boolean): ConnectivityState;

@@ -92,0 +92,0 @@ watchConnectivityState(currentState: ConnectivityState, deadline: Date | number, callback: (error?: Error) => void): void;

@@ -34,4 +34,4 @@ /// <reference types="node" />

waitForReady(deadline: Deadline, callback: (error?: Error) => void): void;
private handleUnaryResponse<ResponseType>(call, deserialize, callback);
private checkOptionalUnaryResponseArguments<ResponseType>(arg1, arg2?, arg3?);
private handleUnaryResponse;
private checkOptionalUnaryResponseArguments;
makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, options: CallOptions, callback: UnaryCallback<ResponseType>): ClientUnaryCall;

@@ -45,3 +45,3 @@ makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, callback: UnaryCallback<ResponseType>): ClientUnaryCall;

makeClientStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, callback: UnaryCallback<ResponseType>): ClientWritableStream<RequestType>;
private checkMetadataAndOptions(arg1?, arg2?);
private checkMetadataAndOptions;
makeServerStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, options?: CallOptions): ClientReadableStream<ResponseType>;

@@ -48,0 +48,0 @@ makeServerStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, options?: CallOptions): ClientReadableStream<ResponseType>;

"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 });

@@ -19,14 +11,12 @@ const zlib = require("zlib");

*/
writeMessage(message, compress) {
return __awaiter(this, void 0, void 0, function* () {
let messageBuffer = message;
if (compress) {
messageBuffer = yield this.compressMessage(messageBuffer);
}
const output = Buffer.allocUnsafe(messageBuffer.length + 5);
output.writeUInt8(compress ? 1 : 0, 0);
output.writeUInt32BE(messageBuffer.length, 1);
messageBuffer.copy(output, 5);
return output;
});
async writeMessage(message, compress) {
let messageBuffer = message;
if (compress) {
messageBuffer = await this.compressMessage(messageBuffer);
}
const output = Buffer.allocUnsafe(messageBuffer.length + 5);
output.writeUInt8(compress ? 1 : 0, 0);
output.writeUInt32BE(messageBuffer.length, 1);
messageBuffer.copy(output, 5);
return output;
}

@@ -37,29 +27,23 @@ /**

*/
readMessage(data) {
return __awaiter(this, void 0, void 0, function* () {
const compressed = data.readUInt8(0) === 1;
let messageBuffer = data.slice(5);
if (compressed) {
messageBuffer = yield this.decompressMessage(messageBuffer);
}
return messageBuffer;
});
async readMessage(data) {
const compressed = data.readUInt8(0) === 1;
let messageBuffer = data.slice(5);
if (compressed) {
messageBuffer = await this.decompressMessage(messageBuffer);
}
return messageBuffer;
}
}
class IdentityHandler extends CompressionHandler {
compressMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
return message;
});
async compressMessage(message) {
return message;
}
writeMessage(message, compress) {
return __awaiter(this, void 0, void 0, function* () {
const output = Buffer.allocUnsafe(message.length + 5);
/* With "identity" compression, messages should always be marked as
* uncompressed */
output.writeUInt8(0, 0);
output.writeUInt32BE(message.length, 1);
message.copy(output, 5);
return output;
});
async writeMessage(message, compress) {
const output = Buffer.allocUnsafe(message.length + 5);
/* With "identity" compression, messages should always be marked as
* uncompressed */
output.writeUInt8(0, 0);
output.writeUInt32BE(message.length, 1);
message.copy(output, 5);
return output;
}

@@ -153,48 +137,40 @@ decompressMessage(message) {

}
sendMetadata(metadata) {
return __awaiter(this, void 0, void 0, function* () {
const headers = yield metadata;
headers.set('grpc-encoding', 'identity');
headers.set('grpc-accept-encoding', 'identity,deflate,gzip');
return headers;
});
async sendMetadata(metadata) {
const headers = await metadata;
headers.set('grpc-encoding', 'identity');
headers.set('grpc-accept-encoding', 'identity,deflate,gzip');
return headers;
}
receiveMetadata(metadata) {
return __awaiter(this, void 0, void 0, function* () {
const headers = yield metadata;
const receiveEncoding = headers.get('grpc-encoding');
if (receiveEncoding.length > 0) {
const encoding = receiveEncoding[0];
if (typeof encoding === 'string') {
this.receiveCompression = getCompressionHandler(encoding);
}
async receiveMetadata(metadata) {
const headers = await metadata;
const receiveEncoding = headers.get('grpc-encoding');
if (receiveEncoding.length > 0) {
const encoding = receiveEncoding[0];
if (typeof encoding === 'string') {
this.receiveCompression = getCompressionHandler(encoding);
}
headers.remove('grpc-encoding');
headers.remove('grpc-accept-encoding');
return headers;
});
}
headers.remove('grpc-encoding');
headers.remove('grpc-accept-encoding');
return headers;
}
sendMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
/* This filter is special. The input message is the bare message bytes,
* and the output is a framed and possibly compressed message. For this
* reason, this filter should be at the bottom of the filter stack */
const resolvedMessage = yield message;
const compress = resolvedMessage.flags === undefined ?
false :
(resolvedMessage.flags & 2 /* NoCompress */) === 0;
return {
message: yield this.sendCompression.writeMessage(resolvedMessage.message, compress),
flags: resolvedMessage.flags
};
});
async sendMessage(message) {
/* This filter is special. The input message is the bare message bytes,
* and the output is a framed and possibly compressed message. For this
* reason, this filter should be at the bottom of the filter stack */
const resolvedMessage = await message;
const compress = resolvedMessage.flags === undefined ?
false :
(resolvedMessage.flags & 2 /* NoCompress */) === 0;
return {
message: await this.sendCompression.writeMessage(resolvedMessage.message, compress),
flags: resolvedMessage.flags
};
}
receiveMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
/* This filter is also special. The input message is framed and possibly
* compressed, and the output message is deframed and uncompressed. So
* this is another reason that this filter should be at the bottom of the
* filter stack. */
return this.receiveCompression.readMessage(yield message);
});
async receiveMessage(message) {
/* This filter is also special. The input message is framed and possibly
* compressed, and the output message is deframed and uncompressed. So
* this is another reason that this filter should be at the bottom of the
* filter stack. */
return this.receiveCompression.readMessage(await message);
}

@@ -201,0 +177,0 @@ }

@@ -18,3 +18,3 @@ export declare enum Status {

DATA_LOSS = 15,
UNAUTHENTICATED = 16,
UNAUTHENTICATED = 16
}

@@ -24,3 +24,3 @@ export declare enum LogVerbosity {

INFO = 1,
ERROR = 2,
ERROR = 2
}

@@ -57,5 +57,11 @@ "use strict";

this.channel.removeListener('connectivityStateChanged', handleStateChange);
this.callStream.removeListener('status', handleStatus);
}
};
const handleStatus = () => {
reject(new Error('Call ended'));
this.channel.removeListener('connectivityStateChanged', handleStateChange);
};
this.channel.on('connectivityStateChanged', handleStateChange);
this.callStream.once('status', handleStatus);
}

@@ -62,0 +68,0 @@ })

@@ -1,10 +0,1 @@

export interface EmitterAugmentation0<Name extends string | symbol> {
addListener(event: Name, listener: () => void): this;
emit(event: Name): boolean;
on(event: Name, listener: () => void): this;
once(event: Name, listener: () => void): this;
prependListener(event: Name, listener: () => void): this;
prependOnceListener(event: Name, listener: () => void): this;
removeListener(event: Name, listener: () => void): this;
}
export interface EmitterAugmentation1<Name extends string | symbol, Arg> {

@@ -19,10 +10,1 @@ addListener(event: Name, listener: (arg1: Arg) => void): this;

}
export interface EmitterAugmentation2<Name extends string | symbol, Arg1, Arg2> {
addListener(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
emit(event: Name, arg1: Arg1, arg2: Arg2): boolean;
on(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
once(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
prependListener(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
prependOnceListener(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
removeListener(event: Name, listener: (arg1: Arg1, arg2: Arg2) => void): this;
}
"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 });
class BaseFilter {
sendMetadata(metadata) {
return __awaiter(this, void 0, void 0, function* () {
return metadata;
});
async sendMetadata(metadata) {
return metadata;
}
receiveMetadata(metadata) {
return __awaiter(this, void 0, void 0, function* () {
return metadata;
});
async receiveMetadata(metadata) {
return metadata;
}
sendMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
return message;
});
async sendMessage(message) {
return message;
}
receiveMessage(message) {
return __awaiter(this, void 0, void 0, function* () {
return message;
});
async receiveMessage(message) {
return message;
}
receiveTrailers(status) {
return __awaiter(this, void 0, void 0, function* () {
return status;
});
async receiveTrailers(status) {
return status;
}

@@ -37,0 +19,0 @@ }

@@ -42,3 +42,3 @@ /// <reference types="node" />

};
export declare const getClientChannel: (client: Client) => any;
export declare const getClientChannel: (client: Client) => Channel;
export { StatusBuilder };

@@ -45,0 +45,0 @@ export declare const ListenerBuilder: () => never;

"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 });

@@ -14,24 +6,22 @@ const constants_1 = require("./constants");

class MetadataStatusFilter extends filter_1.BaseFilter {
receiveTrailers(status) {
return __awaiter(this, void 0, void 0, function* () {
// tslint:disable-next-line:prefer-const
let { code, details, metadata } = yield status;
if (code !== constants_1.Status.UNKNOWN) {
// we already have a known status, so don't assign a new one.
return { code, details, metadata };
async receiveTrailers(status) {
// tslint:disable-next-line:prefer-const
let { code, details, metadata } = await status;
if (code !== constants_1.Status.UNKNOWN) {
// we already have a known status, so don't assign a new one.
return { code, details, metadata };
}
const metadataMap = metadata.getMap();
if (typeof metadataMap['grpc-status'] === 'string') {
const receivedCode = Number(metadataMap['grpc-status']);
if (receivedCode in constants_1.Status) {
code = receivedCode;
}
const metadataMap = metadata.getMap();
if (typeof metadataMap['grpc-status'] === 'string') {
const receivedCode = Number(metadataMap['grpc-status']);
if (receivedCode in constants_1.Status) {
code = receivedCode;
}
metadata.remove('grpc-status');
}
if (typeof metadataMap['grpc-message'] === 'string') {
details = decodeURI(metadataMap['grpc-message']);
metadata.remove('grpc-message');
}
return { code, details, metadata };
});
metadata.remove('grpc-status');
}
if (typeof metadataMap['grpc-message'] === 'string') {
details = decodeURI(metadataMap['grpc-message']);
metadata.remove('grpc-message');
}
return { code, details, metadata };
}

@@ -38,0 +28,0 @@ }

@@ -62,3 +62,3 @@ /// <reference types="node" />

toHttp2Headers(): http2.OutgoingHttpHeaders;
private _getCoreRepresentation();
private _getCoreRepresentation;
/**

@@ -65,0 +65,0 @@ * Returns a new Metadata object based fields in a given IncomingHttpHeaders

@@ -26,9 +26,9 @@ /// <reference types="node" />

constructor(target: url.URL, connectionOptions: http2.SecureClientSessionOptions, userAgent: string, channelArgs: Partial<ChannelOptions>);
private ref();
private unref();
private sendPing();
private startKeepalivePings();
private stopKeepalivePings();
private ref;
private unref;
private sendPing;
private startKeepalivePings;
private stopKeepalivePings;
startCallStream(metadata: Metadata, callStream: Http2CallStream): void;
close(): void;
}

@@ -18,2 +18,3 @@ "use strict";

this.session = http2.connect(target, connectionOptions);
this.session.unref();
this.session.on('connect', () => {

@@ -20,0 +21,0 @@ this.emit('connect');

{
"name": "@grpc/grpc-js",
"version": "0.3.5",
"version": "0.3.6",
"description": "gRPC Library for Node - pure JS implementation",

@@ -24,3 +24,3 @@ "homepage": "https://grpc.io/",

"lodash": "^4.17.4",
"typescript": "~2.7.0"
"typescript": "~3.3.3333"
},

@@ -49,4 +49,5 @@ "contributors": [

"files": [
"build/src/*.{js,d.ts}"
"build/src/*.{js,d.ts}",
"LICENSE"
]
}
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