https://github.com/layotto/js-sdk
js sdk for layotto
https://github.com/layotto/js-sdk
dapr grpc layotto nodejs
Last synced: 3 months ago
JSON representation
js sdk for layotto
- Host: GitHub
- URL: https://github.com/layotto/js-sdk
- Owner: layotto
- License: apache-2.0
- Created: 2021-11-10T09:27:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-20T08:25:09.000Z (over 1 year ago)
- Last Synced: 2024-05-21T09:05:59.472Z (over 1 year ago)
- Topics: dapr, grpc, layotto, nodejs
- Language: TypeScript
- Homepage:
- Size: 189 KB
- Stars: 3
- Watchers: 4
- Forks: 4
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: LICENSE
Awesome Lists containing this project
README
# Layotto Node.js SDK
The Layotto Node.js SDK to build your application.
[](https://npmjs.org/package/layotto)
[](https://packagequality.com/#?package=layotto)
[](https://npmjs.org/package/layotto)[](https://github.com/layotto/js-sdk/actions/workflows/nodejs.yml)
[](https://codecov.io/gh/layotto/js-sdk)
[](https://snyk.io/test/npm/layotto)## Clone
```bash
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](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
## Usage
### State
`demo/state.ts`
```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
```bash
npm install
```### Generate gRPC files
Should install [grpc-tools](https://github.com/grpc/grpc-node) first.
MacOS M1 follow [this issue](https://github.com/grpc/grpc-node/issues/1405).```bash
npm run build:grpc
```### Run Tests
### step 1. Set up the environment
- Running redis and etcd under Docker
```bash
docker-compose up -d
```- Start a echoserver for testing the rpc api
```bash
node demo/rpc/http/server.js
```If you want to know more about this, check https://mosn.io/layotto/#/zh/start/rpc/helloworld
- Start Layotto, see [How to run layotto](https://mosn.io/layotto/#/zh/start/state/start?id=%e7%ac%ac%e4%ba%8c%e6%ad%a5%ef%bc%9a%e8%bf%90%e8%a1%8clayotto)
```bash
cd layotto/cmd/layotto
go build./layotto start -c ../../../demo/config.json
```### step 2: Run the tests
- Then, run the test script by npm
```bash
npm run test:unit
```Enable trace debug log for grpc-js:
```bash
GRPC_TRACE=compression GRPC_VERBOSITY=debug GRPC_TRACE=all npm run test test/unit/client/Invoker.test.ts
```## Reference
- [Core concepts, architecture and lifecycle](https://grpc.io/docs/what-is-grpc/core-concepts/)
- [Get Start with gRPC on Node.js](https://grpc.io/docs/languages/node/quickstart/)
- [Node.js gRPC Library](https://grpc.github.io/grpc/node/)
- [Understanding Streams in Node.js](https://nodesource.com/blog/understanding-streams-in-nodejs/)
- [Go Proxy in China](https://learnku.com/go/wikis/38122)
- [How to build a bi-directional streaming gRPC service with Node.js and Java](https://medium.com/@Mark.io/bi-directional-streaming-grpc-with-node-js-and-java-7cbe0f1e0693)## License
[Apache License 2.0](LICENSE)
## Contributors
|[
fengmk2](https://github.com/fengmk2)
|[
seeflood](https://github.com/seeflood)
|[
LZHK1ng](https://github.com/LZHK1ng)
|[
killagu](https://github.com/killagu)
|
| :---: | :---: | :---: | :---: |This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Thu Oct 13 2022 15:14:41 GMT+0800`.