1.0.0 • Published 1 year ago

@pfc/grpc-adapter v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

gRPC Adapter

Requirements

  • Typescript

Setup

How to Use

  • Proto file example (my.proto):
syntax = "proto3";

service MainService {
    rpc list (Empty) returns (TodoList);
    rpc insert (NewItem) returns (TodoList);
    rpc mark (TodoItemId) returns (TodoList);
};
message Empty {};

message TodoItemId {
    int32 id = 1;
    bool checked = 2;
};

message NewItem {
    string task = 1;
};

message TodoItem {
    int32 id = 1;
    bool done = 2;
    string task = 3;
};

message TodoList {
    repeated TodoItem todoItem = 1;
};
  • Mapper for handlers:
const path = require('node:path');

import {Request} from '../grpc-adapter';
import {MyService} from '../services/myService';

const myService = MyService();

const protoPath = path.join(__dirname, '..', 'proto', 'my.proto');

export const mappers = [
    Request(`${protoPath}`, {
        insert: myService.insertTask,
        list: myService.listTask,
        mark: myService.markTask,
    }),
];