0.3.1 • Published 17 days ago

@lx-frontend/grpc-shared v0.3.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
17 days ago

@lx-frontend/grpc-shared

grpc 相关工具函数

Description

  1. object2Request 把 js 对象转换成 grpc request 实例。支持多层对象

Usage

import { GreeterPromiseClient } from './dist/helloworld_grpc_web_pb';
import { HelloRequest, UserInfo, Store } from './dist/helloworld_pb';
import { object2Request } from '@lx-frontend/grpc-shared';

const client = new GreeterPromiseClient('http://localhost:50051')

const helloRequest2 = object2Request(HelloRequest, {
  name: "123",
  userinfo: {
    id: 123,
    name: 'mind',
    age: 20,
    store: {
      sid: 12,
      sname: 'sname'
    }
  }
}, {
  userinfo: UserInfo,
  store: Store,
})

client.sayHello(helloRequest2, {}).then((res) => {
  const result = res.toObject()
  console.log('result', result)
})

filter Query 构建

用与生成后台 gprc filter 参数构建,可以用来控制后台 grpc 服务返回字段,按需使用。

使用说明: 1. 为了简化使用,Filter 函数的值,需要来自于 Eq, Gte, Gt, Has, Lt, Lte, Ne 这些函数的返回值。 2. 更多使用方式,可以查看 测试用例

简单示例代码

import { NewQuery, Eq, Gte, Gt, Has, Lt, Lte, Ne } from "./lib";

async function demo() {
  const query = NewQuery()
    .Filter(Eq('name', "李四"))
    .Filter(Gte('age', 1))
    .Filter(Gt('id', 2))
    .Filter(Has('ddd', "123"))
    .Filter(Lt('pw', 123))
    .Filter(Lte('lll', [222, 33]))
    .Filter(Ne('neKey', "www"))

  const filterStr = query.String()

  console.log(filterStr) // name = "李四" AND age >= 1 AND id > 2 AND ddd:"123" AND pw < 123 AND lll <= (222, 33) AND neKey != www

  // 传递给后台,过滤参数。
  const res = await client.GetCarModelRequest({
    Name: "123",
    Filter: filterStr,
  })
}

sort 构建

构建 sort 字符串

import { SortBy } from "./lib";

// 可以是单个参数,也可以是多个参数
const sort = SortBy({Field: 'timestamp', Direction: "asc"}, {Field: "id", Direction: "desc"})

const sortStr = sort.String() // timestamp asc, id desc
0.3.2-beta.2

17 days ago

0.3.2-beta.1

21 days ago

0.3.2-beta.0

25 days ago

0.3.1

25 days ago

0.2.1-5.beta-0

28 days ago

0.2.14

2 months ago

0.2.14-beta.0

2 months ago

0.2.13

2 months ago

0.2.13-beta.2

2 months ago

0.2.13-beta.1

3 months ago

0.2.13-beta.0

3 months ago

0.2.12

6 months ago

0.2.12-beta.3

6 months ago

0.2.12-beta.2

6 months ago

0.2.12-beta.1

6 months ago

0.2.11

6 months ago

0.2.11-beta.1

6 months ago

0.2.11-beta.0

6 months ago

0.2.10

7 months ago

0.2.9

7 months ago

0.2.9-beta.3

7 months ago

0.2.9-beta.2

7 months ago

0.2.9-beta.1

7 months ago

0.2.9-beta.0

7 months ago

0.2.8

9 months ago

0.2.7

9 months ago

0.2.6

9 months ago

0.2.5

9 months ago

0.2.4

9 months ago

0.2.2

9 months ago

0.2.1

9 months ago

0.2.0

10 months ago

0.1.0

10 months ago