Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rewrite-to-ts #1

Merged
merged 12 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 2
32 changes: 17 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: build

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

permissions:
contents: read
Expand All @@ -20,16 +20,18 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: ${{ matrix.node-version }}
# Use separate run commands so command status handled correctly on Windows
- name: npm install
run: npm ci
- name: npm test
run: npm test
- name: npm run lint
run: npm run lint
- name: Checkout master
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install Dependencies
run: pnpm i
- name: Test
run: pnpm test
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm exec lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"standard.enable": true,
"standard.autoFixOnSave": true,
"eslint.enable": false
}
}
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
# gRPCity ![build-status](https://github.com/chakhsu/grpcity/actions/workflows/tests.yml/badge.svg) ![npm](https://img.shields.io/npm/v/grpcity) ![license](https://img.shields.io/npm/l/grpcity) ![code-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg)
# gRPCity ![build-status](https://github.com/chakhsu/grpcity/actions/workflows/tests.yml/badge.svg) ![npm](https://img.shields.io/npm/v/grpcity) ![license](https://img.shields.io/npm/l/grpcity) ![code-style](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)

[English](./README.md) | [简体中文](./README_CN.md)

## Introduction

`gRPCity` is a gRPC microservices library running on Node.js. It combines `proto-loader` and `grpc-js` to offer an exceptionally easy way to load proto files. It simplifies many complex technical concepts, allowing clients and servers to be implemented with just a few functions. Additionally, it provides numerous advanced features to meet the needs of most development scenarios.
`gRPCity` is a gRPC microservices library running on Node.js. It combines
`proto-loader` and `grpc-js` to offer an exceptionally easy way to load proto
files. It simplifies many complex technical concepts, allowing clients and
servers to be implemented with just a few functions. Additionally, it provides
numerous advanced features to meet the needs of most development scenarios.

> The name is derived from "gRPC + City = gRPCity", symbolizing the author's hope that this library can support the development of business cities. Taking a technological perspective as the foundation, it enables everyone to focus on business and better support delivery.
> The name is derived from "gRPC + City = gRPCity", symbolizing the author's
> hope that this library can support the development of business cities. Taking
> a technological perspective as the foundation, it enables everyone to focus on
> business and better support delivery.

Here is the feature:

- **API**: The communication protocol is based on gRPC and defined using Protobuf.
- **Protobuf**: Supports only dynamic loading of pb, simplifying the loading process of pb files.
- **Client**: Configured once and can be called anytime, anywhere, supporting multi-server invocation.
- **Server**: Simplifies the initialization process, starting the server in three steps, supporting multi-server startup.
- **API**: The communication protocol is based on gRPC and defined using
Protobuf.
- **Protobuf**: Supports only dynamic loading of pb, simplifying the loading
process of pb files.
- **Client**: Configured once and can be called anytime, anywhere, supporting
multi-server invocation.
- **Server**: Simplifies the initialization process, starting the server in
three steps, supporting multi-server startup.
- **No-Route**: No routing, RPC is inherently bound to methods.
- **Middleware**: Integrates middleware mechanism similar to Koa, providing pre and post-processing capabilities for RPC.
- **Middleware**: Integrates middleware mechanism similar to Koa, providing pre
and post-processing capabilities for RPC.
- **Metadata**: Standardizes the transmission and retrieval of metadata.
- **Error**: Provides dedicated Error objects to ensure targeted handling of exceptions after catching.
- **Promise**: Supports promisify internally in RPC methods while also preserving callbackify.
- **Config**: Aligned with official configurations, supports pb load configuration and gRPC channel configuration.
- **Error**: Provides dedicated Error objects to ensure targeted handling of
exceptions after catching.
- **Promise**: Supports promisify internally in RPC methods while also
preserving callbackify.
- **Config**: Aligned with official configurations, supports pb load
configuration and gRPC channel configuration.
- **Pattern**: Singleton pattern ensures the uniqueness of instance objects.
- **Typescript**: Supported, ensuring compatibility between TS and JS.

...and a lot more.

---

View full documentation and examples on [grpcity.js.org](https://grpcity.js.org).
View full documentation and examples on
[grpcity.js.org](https://grpcity.js.org).

## Quick Start

Expand Down Expand Up @@ -67,9 +83,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))

export default new GrpcLoader({
location: path.join(__dirname, './'),
files: [
'greeter.proto'
]
files: ['greeter.proto']
})
```

Expand All @@ -89,7 +103,7 @@ class Greeter {
}
}

const start = async (addr) => {
const start = async addr => {
await loader.init()

const server = loader.initServer()
Expand All @@ -107,9 +121,9 @@ start('127.0.0.1:9099')
Finally, create `client.js` and write the following code in it:

```js
import loader from "./loader.js"
import loader from './loader.js'

const start = async (addr) => {
const start = async addr => {
await loader.init()

await loader.initClients({
Expand All @@ -135,7 +149,8 @@ node ./client.js

---

View full documentation and examples on [grpcity.js.org](https://grpcity.js.org).
View full documentation and examples on
[grpcity.js.org](https://grpcity.js.org).

## License

Expand Down
21 changes: 11 additions & 10 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# gRPCity ![build-status](https://github.com/chakhsu/grpcity/actions/workflows/tests.yml/badge.svg) ![npm](https://img.shields.io/npm/v/grpcity) ![license](https://img.shields.io/npm/l/grpcity) ![code-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg)
# gRPCity ![build-status](https://github.com/chakhsu/grpcity/actions/workflows/tests.yml/badge.svg) ![npm](https://img.shields.io/npm/v/grpcity) ![license](https://img.shields.io/npm/l/grpcity) ![code-style](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)

[English](./README.md) | [简体中文](./README_CN.md)

## 介绍

`gRPCity` 是一个运行在 Node.js 的 gRPC 微服务库,结合了 `proto-loader` 和 `grpc-js`,提供了非常简易的方式去加载 proto 文件,简化了很多难以理解的技术概念,只需要几个函数就可以轻松实现客户端和服务端,同时也提供非常多高级的功能满足大多数开发场景。
`gRPCity` 是一个运行在 Node.js 的 gRPC 微服务库,结合了 `proto-loader` 和
`grpc-js`,提供了非常简易的方式去加载 proto 文件,简化了很多难以理解的技术概念,
只需要几个函数就可以轻松实现客户端和服务端,同时也提供非常多高级的功能满足大多数
开发场景。

> 名字来源于: gRPC + City = gRPCity,寄托了作者希望这个库能支撑了业务城市的建设,以技术底座的视角,让大家聚焦业务,更好地支撑交付。
> 名字来源于: gRPC + City = gRPCity,寄托了作者希望这个库能支撑了业务城市的建
> 设,以技术底座的视角,让大家聚焦业务,更好地支撑交付。

特性如下:

Expand Down Expand Up @@ -67,9 +71,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))

export default new GrpcLoader({
location: path.join(__dirname, './'),
files: [
'greeter.proto'
]
files: ['greeter.proto']
})
```

Expand All @@ -89,7 +91,7 @@ class Greeter {
}
}

const start = async (addr) => {
const start = async addr => {
await loader.init()

const server = loader.initServer()
Expand All @@ -107,9 +109,9 @@ start('127.0.0.1:9099')
最后,创建`client.js`, 编写下面的代码到其中:

```js
import loader from "./loader.js"
import loader from './loader.js'

const start = async (addr) => {
const start = async addr => {
await loader.init()

await loader.initClients({
Expand Down Expand Up @@ -137,7 +139,6 @@ node ./client.js

可通过访问 [grpcity.js.org](https://grpcity.js.org) 查看完整的文档和示例。


## License

Released under the MIT License.
32 changes: 0 additions & 32 deletions lib/config/defaultChannelOptions.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/config/defaultLoadOptions.js

This file was deleted.

Loading