Skip to content

Commit

Permalink
feat(@artusx/plugin-grpc): add grpc support
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Mar 25, 2024
1 parent 2f0b176 commit c4a7605
Show file tree
Hide file tree
Showing 33 changed files with 662 additions and 0 deletions.
184 changes: 184 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/apps/artusx-grpc/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
lib
dist
coverage
6 changes: 6 additions & 0 deletions packages/apps/artusx-grpc/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["@artusx/eslint-config"],
"parserOptions": {
"project": "./tsconfig.json"
}
}
1 change: 1 addition & 0 deletions packages/apps/artusx-grpc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
3 changes: 3 additions & 0 deletions packages/apps/artusx-grpc/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
registry=https://registry.npmjs.org/
always-auth=false
strict-ssl=false
1 change: 1 addition & 0 deletions packages/apps/artusx-grpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# artusx-grpc
37 changes: 37 additions & 0 deletions packages/apps/artusx-grpc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "artusx-grpc",
"version": "0.0.0-dev.0",
"description": "grpc app powered by artusx",
"keywords": [
"artusx"
],
"author": "Suyi <[email protected]>",
"main": "dist/index.js",
"scripts": {
"_build": "npm run tsc",
"build": "",
"ci": "npm run lint",
"dev": "ARTUS_SERVER_ENV=development npx nodemon src/index.ts",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"start": "ARTUS_SERVER_ENV=production node dist/index.js",
"tsc": "rm -rf dist && tsc"
},
"dependencies": {
"@artusx/plugin-grpc": "workspace:*",
"@artusx/utils": "workspace:*",
"reflect-metadata": "^0.1.13",
"tslib": "^2.5.0"
},
"devDependencies": {
"@artusx/eslint-config": "workspace:*",
"@artusx/tsconfig": "workspace:*",
"@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "~6.19.1",
"eslint": "~8.56.0",
"eslint-plugin-import": "~2.29.1",
"nodemon": "~3.0.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
}
}
11 changes: 11 additions & 0 deletions packages/apps/artusx-grpc/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import path from 'path';
import { Application } from '@artusx/utils';

export const main = async () => {
const app = await Application.start({
root: path.resolve(__dirname),
configDir: 'config',
});

return app;
};
27 changes: 27 additions & 0 deletions packages/apps/artusx-grpc/src/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import path from 'path';

export default () => {
const grpc = {
protoList: [
{
protoName: 'helloworld',
protoPath: path.resolve(__dirname, '../protos/helloworld.proto'),
serviceMap: {
Greeter: {
sayHello: async (call, callback) => {
callback(null, { message: 'Hello ' + call.request.name });
},
},
},
},
],
server: {
host: '0.0.0.0',
port: '50051',
},
};

return {
grpc,
};
};
1 change: 1 addition & 0 deletions packages/apps/artusx-grpc/src/config/config.development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
1 change: 1 addition & 0 deletions packages/apps/artusx-grpc/src/config/config.production.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default {};
6 changes: 6 additions & 0 deletions packages/apps/artusx-grpc/src/config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
grpc: {
enable: true,
package: '@artusx/plugin-grpc',
},
};
3 changes: 3 additions & 0 deletions packages/apps/artusx-grpc/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { main } from './bootstrap';

main();
45 changes: 45 additions & 0 deletions packages/apps/artusx-grpc/src/protos/echo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

syntax = "proto3";

option go_package = "google.golang.org/grpc/examples/features/proto/echo";

package grpc.examples.echo;

// EchoRequest is the request for echo.
message EchoRequest {
string message = 1;
}

// EchoResponse is the response for echo.
message EchoResponse {
string message = 1;
}

// Echo is the echo service.
service Echo {
// UnaryEcho is unary echo.
rpc UnaryEcho(EchoRequest) returns (EchoResponse) {}
// ServerStreamingEcho is server side streaming.
rpc ServerStreamingEcho(EchoRequest) returns (stream EchoResponse) {}
// ClientStreamingEcho is client side streaming.
rpc ClientStreamingEcho(stream EchoRequest) returns (EchoResponse) {}
// BidirectionalStreamingEcho is bidi streaming.
rpc BidirectionalStreamingEcho(stream EchoRequest) returns (stream EchoResponse) {}
}
Loading

0 comments on commit c4a7605

Please sign in to comment.