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

@pbkit/grpc-web-client

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pbkit/grpc-web-client - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

lib/index.d.ts

@@ -1,2 +0,2 @@

import type { RpcClientImpl } from "pbkit/core/runtime/rpc";
import type { RpcClientImpl } from "@pbkit/runtime/rpc";
export declare type Metadata = Record<string, string>;

@@ -3,0 +3,0 @@ export declare type Header = Metadata;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGrpcClientImpl = void 0;
const event_buffer_1 = require("@pbkit/runtime/async/event-buffer");
const observer_1 = require("@pbkit/runtime/async/observer");
const grpc_web_1 = require("@improbable-eng/grpc-web");

@@ -8,2 +10,11 @@ function createGrpcClientImpl(config) {

return (req, metadata) => {
const headerPromise = (0, observer_1.defer)();
const trailerPromise = (0, observer_1.defer)();
const eventBuffer = (0, event_buffer_1.createEventBuffer)({
onDrainEnd() {
grpcClient.close();
headerPromise.reject();
trailerPromise.reject();
},
});
const grpcClient = grpc_web_1.grpc.client(methodDescriptor, {

@@ -13,24 +24,13 @@ host: config.host,

});
const responseQueue = [];
let resolveResponse = undefined;
grpcClient.onMessage((res) => {
if (resolveResponse) {
resolveResponse({ value: res, done: false });
resolveResponse = undefined;
}
else {
responseQueue.push(res);
}
grpcClient.onHeaders((header) => {
headerPromise.resolve(grpcMetadataToRecord(header));
});
const headerPromise = new Promise((resolve) => {
grpcClient.onHeaders((header) => resolve(grpcMetadataToRecord(header)));
});
const trailerPromise = new Promise((resolve) => {
grpcClient.onEnd(async (status, statusMessage, trailer) => {
resolve({
...grpcMetadataToRecord(trailer),
status: status.toString(),
statusMessage,
});
grpcClient.onMessage(eventBuffer.push);
grpcClient.onEnd((status, statusMessage, trailer) => {
trailerPromise.resolve({
...grpcMetadataToRecord(trailer),
status: status.toString(),
statusMessage,
});
eventBuffer.finish();
});

@@ -56,19 +56,3 @@ (async () => {

})();
const result = {
[Symbol.asyncIterator]: () => result,
next: function () {
if (responseQueue.length > 0) {
return Promise.resolve({
value: responseQueue.shift(),
done: false,
});
}
else {
return new Promise((r) => (resolveResponse = r));
}
},
return: (value) => Promise.resolve({ value, done: true }),
throw: (error) => Promise.reject(error),
};
return [result, headerPromise, trailerPromise];
return [eventBuffer.drain(), headerPromise, trailerPromise];
};

@@ -75,0 +59,0 @@ };

{
"name": "@pbkit/grpc-web-client",
"packageManager": "yarn@3.0.2",
"version": "0.0.1",
"version": "0.0.2",
"description": "pbkit grpc web client",

@@ -21,4 +21,4 @@ "main": "lib/index.js",

"@improbable-eng/grpc-web-node-http-transport": "^0.14.1",
"google-protobuf": "^3.18.0-rc.2",
"pbkit": "0.0.17"
"@pbkit/runtime": "^0.0.19",
"google-protobuf": "^3.18.0-rc.2"
},

@@ -25,0 +25,0 @@ "devDependencies": {

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