@pbkit/grpc-web-client
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -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": { |
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
4286
86
+ Added@pbkit/runtime@^0.0.19
+ Added@pbkit/runtime@0.0.19(transitive)
- Removedpbkit@0.0.17
- Removedpbkit@0.0.17(transitive)