killagu / js-sdk

js sdk for layotto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Layotto Node.js SDK

The Layotto Node.js SDK to build your application.

NPM version NPM quality NPM download

Node.js CI Test coverage Known Vulnerabilities

Usage

State

demo/state.ts

import { Client } from 'layotto';

const storeName = 'redis';
const key = 'foo-js-sdk';
const value = `bar, from js-sdk, ${Date()}`;

await client.state.save({
  storeName, 
  states: { key, value },
});
console.log('saveState success, key: %j, value: %j', key, value);

const resValue = await client.state.get({ storeName, key });
console.log('getState success, key: %j, value: %j, toString: %j',
  key, resValue, Buffer.from(resValue).toString('utf8'));

Development

Install dependencies

npm install

Generate gRPC files

Should install grpc-tools first. MacOS M1 follow this issue.

npm install grpc-tools
npm run build:grpc

Run Tests

step 1. Set up the environment

  • Running redis under Docker
docker pull redis:latest
docker run -itd --name redis-test -p 6380:6379 redis
  • Running etcd under Docker
docker pull quay.io/coreos/etcd
docker run -itd -p 2379:2379 --name etcd quay.io/coreos/etcd /usr/local/bin/etcd -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379
  • Start a echoserver for testing the rpc api
go run demo/rpc/http/echoserver/echoserver.go

If you want to know more about this,check https://mosn.io/layotto/#/zh/start/rpc/helloworld

git clone https://github.com/mosn/layotto.git
cd layotto/cmd/layotto
go build

./layotto start -c ../../configs/config_redis.json

step 2: Run the tests

  • Then, run the test script by npm
npm run test:unit

Enable trace debug log for grpc-js:

GRPC_TRACE=compression GRPC_VERBOSITY=debug GRPC_TRACE=all npm run test test/unit/client/Invoker.test.ts

Reference

License

Apache License 2.0

About

js sdk for layotto

License:Apache License 2.0


Languages

Language:JavaScript 82.1%Language:TypeScript 17.4%Language:Shell 0.5%