How to use the @grpc/proto-loader.loadSync function in @grpc/proto-loader

To help you get started, we’ve selected a few @grpc/proto-loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benjsicam / node-graphql-microservices / graphql-gateway / src / services / posts / post.client.js View on Github external
import path from 'path'

import * as grpc from 'grpc'
import * as protoLoader from '@grpc/proto-loader'

const proto = protoLoader.loadSync(path.resolve(__dirname, '../../_proto/post.proto'), {
  enums: String,
  objects: true,
  arrays: true
})
const PostServiceClient = grpc.loadPackageDefinition(proto).post.PostService

export default PostServiceClient
github lightninglabs / lightning-app / public / grpc-client.js View on Github external
ipcMain.on('unlockInit', async event => {
    credentials = await getCredentials(lndSettingsDir);
    protoPath = path.join(__dirname, '..', 'assets', 'rpc.proto');
    const options = {
      keepCase: false,
      longs: Number,
      enums: String,
      defaults: true,
      oneofs: true,
    };
    const packageDef = protoLoader.loadSync(protoPath, options);
    lnrpc = grpc.loadPackageDefinition(packageDef).lnrpc;
    unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
    grpc.waitForClientReady(unlocker, Infinity, err => {
      event.sender.send('unlockReady', { err });
    });
  });
github angular / universal / modules / grpc-engine / spec / index.spec.ts View on Github external
function createClient() {
  const packageDefinition = loadSync('modules/grpc-engine/grpc-engine.proto', {});
  const grpcEngineProto = loadPackageDefinition(packageDefinition).grpcengine;

  const client = new grpcEngineProto.SSR('localhost:9090', credentials.createInsecure());
  return client;
}
github prisma / photonjs / examples / javascript / grpc / server / server.js View on Github external
const chalk = require('chalk')
const PROTO_PATH = __dirname + '/../service.proto'

const Photon = require('@generated/photon')
const photon = new Photon()

const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
})
const { blog } = grpc.loadPackageDefinition(packageDefinition)

async function post(call, callback) {
  const { id } = call.request
  const post = await photon.posts.findOne({
    where: {
      id,
    },
  })
  callback(null, post)
github YoshiyukiKato / grpc-kit / index.js View on Github external
function createClient({ protoPath, packageName, serviceName, options }, address, creds=grpc.credentials.createInsecure()){
  const pkgDef = grpc.loadPackageDefinition(protoLoader.loadSync(protoPath, options));
  const proto = getProtoFromPackageDefinition(pkgDef, packageName);
  return new proto[serviceName](address, creds);
}
github nguyenkha / forest.network / lib / server.js View on Github external
}
    } catch (err) {
      return { code: 1, log: err.toString() };
    }
  }
};

const options = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
};

const protoDefinition = protoLoader.loadSync(PROTO_PATH, options)['types.ABCIApplication'];

const server = new grpc.Server();

const services = {};

Object.keys(protoDefinition).forEach((k) => {
  const method = _.lowerFirst(k);
  if (app[method]) {
    services[method] = (call, callback) => {
      app[method](call.request).then(res => callback(null, res)).catch(callback);
    };
  } else {
    services[method] = (_call, callback) => {
      callback(null, {});
    };
  }
github viz-centric / flair-notifications / app / grpc / client.js View on Github external
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const discovery = require('../discovery');
const logger = require('../logger');
const PROTO_PATH = './app/grpc/QueryService.proto';

let grpcClientInstance;

const queryproto = grpc.loadPackageDefinition(
   protoLoader.loadSync(PROTO_PATH, {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
   })
);

const grpcClient = {
   getRecords: async function (query) {
     logger.info(`Get records for query ${query}`);
     let client = grpcClientInstance;
     logger.info(`Get records obtained client`, client);
     return new Promise((resolve, reject) => {
       logger.info(`Get records promise`, query);
       client.GetData(query, (error, response) => {
github prisma / prisma-examples / node / grpc / client / feed.js View on Github external
const PROTO_PATH = __dirname + '/../service.proto'

const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
})
const blog = grpc.loadPackageDefinition(packageDefinition).blog

function main() {
  const client = new blog.Blog(
    'localhost:50051',
    grpc.credentials.createInsecure(),
  )

  client.feed({}, (err, response) => {
    if (err) {

@grpc/proto-loader

gRPC utility library for loading .proto files

Apache-2.0
Latest version published 8 months ago

Package Health Score

98 / 100
Full package analysis

Popular @grpc/proto-loader functions

Similar packages