grpc-client-promise-wrapper
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    grpc-client-promise-wrapper

    Documentation

    Use async/await for @grpc/grpc-js package

    Installation

    $ npm install grpc-client-promise-wrapper

    Javascript

    const promiseWrapper = require('grpc-client-promise-wrapper');

    Typescript

    import * as promiseWrapper from 'grpc-client-promise-wrapper';

    Example

    • test.proto
    syntax = "proto3";
    
    package test;
    
    service TestService {
      rpc GetTestFn (inputParam) returns (returnValue);
    }
    
    message InputParam {
      string inputParam = 1;
    }
    
    message ReturnValue {
      string returnValue = 1;
    }
    • app.js
    const grpc = require('@grpc/grpc-js');
    const protoLoader = require('@grpc/proto-loader');
    const promiseWrapper = require('grpc-client-promise-wrapper');
    
    const testStub = () => {
      const packageDefinition = protoLoader.loadSync(path.join(__dirname, './test.proto'));
      const testService = grpc.loadPackageDefinition(packageDefinition).test;
      return promiseWrapper(new testService.TestService('localhost:3001', grpc.credentials.createInsecure()));
    };
    
    const getTestFn = async (params) => {
      return testStub().getTestFn(params);
    };

    License

    MIT License

    Install

    npm i grpc-client-promise-wrapper

    DownloadsWeekly Downloads

    34

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    5.13 kB

    Total Files

    10

    Last publish

    Collaborators

    • beoum