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

@protobuf-ts/grpc-backend

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@protobuf-ts/grpc-backend - npm Package Compare versions

Comparing version 2.0.0-alpha.9 to 2.0.0-alpha.10

build/commonjs/util.js

98

build/commonjs/grpc-adapter.js

@@ -15,4 +15,4 @@ "use strict";

const grpc = require("@grpc/grpc-js");
const runtime_rpc_2 = require("@protobuf-ts/runtime-rpc");
const runtime_1 = require("@protobuf-ts/runtime");
const util_1 = require("./util");
/**

@@ -56,13 +56,14 @@ * Create a grpc service definition and an implementation for @grpc/grpc-js.

runtime_1.assert(typeof service[mi.localName] == "function", `implementation is missing method ${mi.localName}()`);
const fn = service[mi.localName].bind(service);
if (mi.serverStreaming && mi.clientStreaming) {
grpcImp[mi.localName] = mapBidi(mi, service[mi.localName]);
grpcImp[mi.localName] = mapBidi(mi, fn);
}
else if (mi.serverStreaming) {
grpcImp[mi.localName] = mapServerStreaming(mi, service[mi.localName]);
grpcImp[mi.localName] = mapServerStreaming(mi, fn);
}
else if (mi.clientStreaming) {
grpcImp[mi.localName] = mapClientStreaming(mi, service[mi.localName]);
grpcImp[mi.localName] = mapClientStreaming(mi, fn);
}
else {
grpcImp[mi.localName] = mapUnary(mi, service[mi.localName]);
grpcImp[mi.localName] = mapUnary(mi, fn);
}

@@ -76,15 +77,6 @@ }

const deadlineDate = typeof deadlineGrpc === 'number' ? new Date(deadlineGrpc) : deadlineGrpc;
return {
method: methodInfo,
headers: grpcMetaToRpc(call.metadata),
sendResponseHeaders(data) {
call.sendMetadata(rpcMetaToGrpc(data));
},
status: {
code: grpc.status[grpc.status.OK],
detail: ''
},
trailers: {},
deadline: deadlineDate,
};
const sendHeaders = (data) => call.sendMetadata(util_1.metadataToGrpc(data));
const ctx = new runtime_rpc_1.ServerCallContextController(methodInfo, util_1.metadataFromGrpc(call.metadata), deadlineDate, sendHeaders);
call.on('cancelled', () => ctx.notifyCancelled());
return ctx;
}

@@ -100,3 +92,3 @@ function mapUnary(methodInfo, method) {

if (e instanceof runtime_rpc_1.RpcError) {
const grpcStatusCode = rpcCodeToGrpc(e.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(e.code);
if (grpcStatusCode === undefined) {

@@ -107,3 +99,3 @@ return callback({

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: util_1.metadataToGrpc(e.meta),
});

@@ -114,3 +106,3 @@ }

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: util_1.metadataToGrpc(e.meta),
});

@@ -125,3 +117,3 @@ }

}
const grpcStatusCode = rpcCodeToGrpc(context.status.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(context.status.code);
if (grpcStatusCode === undefined) {

@@ -140,3 +132,3 @@ return callback({

}
callback(null, response, rpcMetaToGrpc(context.trailers));
callback(null, response, util_1.metadataToGrpc(context.trailers));
});

@@ -162,3 +154,3 @@ }

if (e instanceof runtime_rpc_1.RpcError) {
const grpcStatusCode = rpcCodeToGrpc(e.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(e.code);
if (grpcStatusCode === undefined) {

@@ -174,3 +166,3 @@ let d = new Error(`invalid grpc status code ${e.code}`);

}
const grpcStatusCode = rpcCodeToGrpc(context.status.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(context.status.code);
if (grpcStatusCode === undefined) {

@@ -188,3 +180,3 @@ let d = new Error(`invalid grpc status code ${context.status.code}`);

}
call.end(rpcMetaToGrpc(context.trailers));
call.end(util_1.metadataToGrpc(context.trailers));
});

@@ -195,3 +187,3 @@ }

const context = createContext(methodInfo, call);
const requestStream = new runtime_rpc_2.RpcOutputStreamController();
const requestStream = new runtime_rpc_1.RpcOutputStreamController();
call.on('data', args => {

@@ -213,3 +205,3 @@ runtime_1.assert(methodInfo.I.is(args));

if (e instanceof runtime_rpc_1.RpcError) {
const grpcStatusCode = rpcCodeToGrpc(e.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(e.code);
if (grpcStatusCode === undefined) {

@@ -220,3 +212,3 @@ return callback({

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: util_1.metadataToGrpc(e.meta),
});

@@ -227,3 +219,3 @@ }

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: util_1.metadataToGrpc(e.meta),
});

@@ -238,3 +230,3 @@ }

}
const grpcStatusCode = rpcCodeToGrpc(context.status.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(context.status.code);
if (grpcStatusCode === undefined) {

@@ -253,3 +245,3 @@ return callback({

}
callback(null, response, rpcMetaToGrpc(context.trailers));
callback(null, response, util_1.metadataToGrpc(context.trailers));
});

@@ -260,3 +252,3 @@ }

const context = createContext(methodInfo, call);
const requestStream = new runtime_rpc_2.RpcOutputStreamController();
const requestStream = new runtime_rpc_1.RpcOutputStreamController();
call.on('data', args => {

@@ -293,3 +285,3 @@ runtime_1.assert(methodInfo.I.is(args));

if (e instanceof runtime_rpc_1.RpcError) {
const grpcStatusCode = rpcCodeToGrpc(e.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(e.code);
if (grpcStatusCode === undefined) {

@@ -305,3 +297,3 @@ let d = new Error(`invalid grpc status code ${e.code}`);

}
const grpcStatusCode = rpcCodeToGrpc(context.status.code);
const grpcStatusCode = util_1.rpcCodeToGrpc(context.status.code);
if (grpcStatusCode === undefined) {

@@ -319,38 +311,4 @@ let d = new Error(`invalid grpc status code ${context.status.code}`);

}
call.end(rpcMetaToGrpc(context.trailers));
call.end(util_1.metadataToGrpc(context.trailers));
});
}
function rpcCodeToGrpc(from) {
let v = runtime_1.listEnumValues(grpc.status).find(v => v.name === from);
return v ? v.number : undefined;
}
function rpcMetaToGrpc(from, base) {
const to = base !== null && base !== void 0 ? base : new grpc.Metadata();
for (let k of Object.keys(from)) {
let v = from[k];
if (typeof v == 'string') {
to.add(k, v);
}
else {
for (let vv of v) {
to.add(k, vv);
}
}
}
return to;
}
function grpcMetaToRpc(from) {
const meta = {};
const h2 = from.toHttp2Headers();
for (let k of Object.keys(h2)) {
let v = h2[k];
if (v === undefined) {
continue;
}
if (typeof v === "number") {
v = v.toString();
}
meta[k] = v;
}
return meta;
}

@@ -10,6 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { RpcError } from "@protobuf-ts/runtime-rpc";
import { RpcError, RpcOutputStreamController, ServerCallContextController } from "@protobuf-ts/runtime-rpc";
import * as grpc from "@grpc/grpc-js";
import { RpcOutputStreamController } from "@protobuf-ts/runtime-rpc";
import { assert, listEnumValues } from "@protobuf-ts/runtime";
import { assert } from "@protobuf-ts/runtime";
import { metadataFromGrpc, metadataToGrpc, rpcCodeToGrpc } from "./util";
/**

@@ -51,13 +51,14 @@ * Create a grpc service definition and an implementation for @grpc/grpc-js.

assert(typeof service[mi.localName] == "function", `implementation is missing method ${mi.localName}()`);
const fn = service[mi.localName].bind(service);
if (mi.serverStreaming && mi.clientStreaming) {
grpcImp[mi.localName] = mapBidi(mi, service[mi.localName]);
grpcImp[mi.localName] = mapBidi(mi, fn);
}
else if (mi.serverStreaming) {
grpcImp[mi.localName] = mapServerStreaming(mi, service[mi.localName]);
grpcImp[mi.localName] = mapServerStreaming(mi, fn);
}
else if (mi.clientStreaming) {
grpcImp[mi.localName] = mapClientStreaming(mi, service[mi.localName]);
grpcImp[mi.localName] = mapClientStreaming(mi, fn);
}
else {
grpcImp[mi.localName] = mapUnary(mi, service[mi.localName]);
grpcImp[mi.localName] = mapUnary(mi, fn);
}

@@ -70,15 +71,6 @@ }

const deadlineDate = typeof deadlineGrpc === 'number' ? new Date(deadlineGrpc) : deadlineGrpc;
return {
method: methodInfo,
headers: grpcMetaToRpc(call.metadata),
sendResponseHeaders(data) {
call.sendMetadata(rpcMetaToGrpc(data));
},
status: {
code: grpc.status[grpc.status.OK],
detail: ''
},
trailers: {},
deadline: deadlineDate,
};
const sendHeaders = (data) => call.sendMetadata(metadataToGrpc(data));
const ctx = new ServerCallContextController(methodInfo, metadataFromGrpc(call.metadata), deadlineDate, sendHeaders);
call.on('cancelled', () => ctx.notifyCancelled());
return ctx;
}

@@ -100,3 +92,3 @@ function mapUnary(methodInfo, method) {

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: metadataToGrpc(e.meta),
});

@@ -107,3 +99,3 @@ }

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: metadataToGrpc(e.meta),
});

@@ -132,3 +124,3 @@ }

}
callback(null, response, rpcMetaToGrpc(context.trailers));
callback(null, response, metadataToGrpc(context.trailers));
});

@@ -178,3 +170,3 @@ }

}
call.end(rpcMetaToGrpc(context.trailers));
call.end(metadataToGrpc(context.trailers));
});

@@ -208,3 +200,3 @@ }

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: metadataToGrpc(e.meta),
});

@@ -215,3 +207,3 @@ }

details: e.message,
metadata: rpcMetaToGrpc(e.meta),
metadata: metadataToGrpc(e.meta),
});

@@ -240,3 +232,3 @@ }

}
callback(null, response, rpcMetaToGrpc(context.trailers));
callback(null, response, metadataToGrpc(context.trailers));
});

@@ -303,38 +295,4 @@ }

}
call.end(rpcMetaToGrpc(context.trailers));
call.end(metadataToGrpc(context.trailers));
});
}
function rpcCodeToGrpc(from) {
let v = listEnumValues(grpc.status).find(v => v.name === from);
return v ? v.number : undefined;
}
function rpcMetaToGrpc(from, base) {
const to = base !== null && base !== void 0 ? base : new grpc.Metadata();
for (let k of Object.keys(from)) {
let v = from[k];
if (typeof v == 'string') {
to.add(k, v);
}
else {
for (let vv of v) {
to.add(k, vv);
}
}
}
return to;
}
function grpcMetaToRpc(from) {
const meta = {};
const h2 = from.toHttp2Headers();
for (let k of Object.keys(h2)) {
let v = h2[k];
if (v === undefined) {
continue;
}
if (typeof v === "number") {
v = v.toString();
}
meta[k] = v;
}
return meta;
}

@@ -0,3 +1,3 @@

import { ServiceInfo } from "@protobuf-ts/runtime-rpc";
import * as grpc from "@grpc/grpc-js";
import { ServiceInfo } from "@protobuf-ts/runtime-rpc";
/**

@@ -4,0 +4,0 @@ * Create a grpc service definition and an implementation for @grpc/grpc-js.

{
"name": "@protobuf-ts/grpc-backend",
"version": "2.0.0-alpha.9",
"version": "2.0.0-alpha.10",
"description": "gRPC backend for servers generated by the protoc plugin \"protobuf-ts\"",

@@ -27,4 +27,4 @@ "license": "Apache-2.0",

"devDependencies": {
"@protobuf-ts/plugin": "^2.0.0-alpha.9",
"@protobuf-ts/protoc": "^2.0.0-alpha.9",
"@protobuf-ts/plugin": "^2.0.0-alpha.10",
"@protobuf-ts/protoc": "^2.0.0-alpha.10",
"@types/jasmine": "^3.5.10",

@@ -39,6 +39,6 @@ "jasmine": "^3.5.0",

"@grpc/grpc-js": "^1.2.2",
"@protobuf-ts/runtime": "^2.0.0-alpha.9",
"@protobuf-ts/runtime-rpc": "^2.0.0-alpha.9"
"@protobuf-ts/runtime": "^2.0.0-alpha.10",
"@protobuf-ts/runtime-rpc": "^2.0.0-alpha.10"
},
"gitHead": "06e3cda6dfc68a0a294924c96cdc9c63838a79bd"
"gitHead": "61510335d1892e5488377b6f521c48f7000df6c1"
}
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