Skip to content

layotto/js-sdk

Repository files navigation

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

Clone

git clone --recurse-submodules git@github.com:layotto/js-sdk.git

If forgot to add --recurse-submodules, you can run git submodule update --init --recursive to clone the submodules.

More git submodule commands, please refer to Git submodule.

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 run build:grpc

Run Tests

step 1. Set up the environment

  • Running redis and etcd under Docker
docker-compose up -d
  • Start a echoserver for testing the rpc api
node demo/rpc/http/server.js

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

cd layotto/cmd/layotto
go build

./layotto start -c ../../../demo/config.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

Contributors


fengmk2


seeflood


LZHK1ng


killagu

This project follows the git-contributor spec, auto updated at Thu Oct 13 2022 15:14:41 GMT+0800.