0.0.32 • Published 2 years ago

@syrflover/grpc-client v0.0.32

Weekly downloads
13
License
MIT
Repository
github
Last release
2 years ago

@syrflover/grpc-client

Installation

npm install @syrflover/grpc-client

Usage

// user.proto
syntax = "proto3";

package User;

service UserService {
    rpc GetUser(GetUserParameters) returns (User) {}
    rpc AddUser(AddUserParameters) returns (User) {}
}

message User {
    required string id = 1;
    required string username = 2;
    required string email = 3;
    required string created_at = 4;
}

message AddUserParameters {
    required string username = 1;
    required string email = 2;
}

message GetUserParameters {
    required string type = 1;
    required string value = 2;
}
// index.ts
import {
    IGRPCClientMapOfMethods,
    GRPCClientCallMethod,
    GRPCClient,
} from '@syrflover/grpc-client';

interface IUserMethods extends IGRPCClientMapOfMethods {
    getUser: GRPCClientCallMethod<
        // RequestType
        { type: 'id' | 'username' | 'email'; value: string },
        // ResponseType
        { id: string; username: string; email: string; created_at: string }
    >;
    addUser: GRPCClientCallMethod<
        // RequestType
        { username: string; email: string },
        // ResponseType
        { id: string; username: string; email: string; created_at: string }
    >;
}

(async () => {
    const client = new GRPCClient<IUserMethods>({
        filepath: './user.proto',
        address: '0.0.0.0:12345',
        package: 'User',
        service: 'UserService',
    });

    await client.call('addUser', {
        username: 'syr',
        email: 'syr@meu.works',
    });

    const user = await client.call('getUser', {
        type: 'email',
        value: 'syr@meu.works',
    });

    user.id;
    user.username;
    user.email;
    user.created_at;
})();
0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.20

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago