Skip to content

Commit f89f7cf

Browse files
committed
feat(nestjs-json-rpc): default transport for rpc
- http transport - validation - explorer need service Closes: #77
1 parent cd0d9d4 commit f89f7cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1526
-28
lines changed

.verdaccio/config.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

apps/json-api-server/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { LoggerModule } from 'nestjs-pino';
33

44
import { DatabaseModule } from 'database';
55
import { ResourcesModule } from './resources/resources.module';
6+
import { RpcModule } from './rpc/rpc.module';
67
import * as process from 'process';
78

89
@Module({
910
imports: [
1011
DatabaseModule,
1112
ResourcesModule,
13+
RpcModule,
1214
LoggerModule.forRoot({
1315
pinoHttp: {
1416
level: process.env['NODE_ENV'] === 'test' ? 'silent' : 'debug',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Module } from '@nestjs/common';
2+
import { NestjsJsonRpcModule, TransportType } from '@klerick/nestjs-json-rpc';
3+
4+
@Module({
5+
imports: [
6+
NestjsJsonRpcModule.forRootAsync({
7+
path: 'rpc',
8+
transport: TransportType.HTTP,
9+
}),
10+
],
11+
// providers: [ContestRpc, ParseIntArrayPipe, LineUpSchemaPipe],
12+
})
13+
export class RpcModule {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"extends": ["../../../.eslintrc.base.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
},
17+
{
18+
"files": ["*.json"],
19+
"parser": "jsonc-eslint-parser",
20+
"rules": {
21+
"@nx/dependency-checks": "error"
22+
}
23+
}
24+
]
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# nestjs-json-rpc
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Building
6+
7+
Run `nx build nestjs-json-rpc` to build the library.
8+
9+
## Running unit tests
10+
11+
Run `nx test nestjs-json-rpc` to execute the unit tests via [Jest](https://jestjs.io).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'nestjs-json-rpc',
4+
preset: '../../../jest.preset.js',
5+
testEnvironment: 'node',
6+
transform: {
7+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8+
},
9+
moduleFileExtensions: ['ts', 'js', 'html'],
10+
coverageDirectory: '../../../coverage/libs/json-rpc/nestjs-json-rpc',
11+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "@klerick/nestjs-json-rpc",
3+
"version": "0.0.1",
4+
"dependencies": {
5+
"tslib": "^2.3.0"
6+
},
7+
"type": "commonjs",
8+
"main": "./src/index.js",
9+
"typings": "./src/index.d.ts"
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nestjs-json-rpc",
3+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/json-rpc/nestjs-json-rpc/src",
5+
"projectType": "library",
6+
"targets": {
7+
"build": {
8+
"executor": "@nx/js:tsc",
9+
"outputs": ["{options.outputPath}"],
10+
"options": {
11+
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc",
12+
"tsConfig": "libs/json-rpc/nestjs-json-rpc/tsconfig.lib.json",
13+
"packageJson": "libs/json-rpc/nestjs-json-rpc/package.json",
14+
"main": "libs/json-rpc/nestjs-json-rpc/src/index.ts",
15+
"assets": ["libs/json-rpc/nestjs-json-rpc/*.md"]
16+
}
17+
},
18+
"publish": {
19+
"command": "node tools/scripts/publish.mjs nestjs-json-rpc {args.ver} {args.tag}",
20+
"dependsOn": ["build"]
21+
}
22+
},
23+
"tags": []
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export * from './lib/nestjs-json-rpc.module';
2+
export { TransportType, CommonRpcConfig, ErrorCodeType } from './lib/types';
3+
export {
4+
fromRpcErrorToRpcErrorObject,
5+
createError,
6+
RpcError,
7+
} from './lib/utils';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ErrorCodeType } from '../types';
2+
3+
export const JsonRpcMetadataKey = '__rpc-metadata__';
4+
export const JsonRpcMetadataKeyParamPipe = '__rpc-metadata-param-pipe__';
5+
6+
export const MAP_HANDLER = Symbol('MAP_HANDLER');
7+
export const RPC_CONTEXT = Symbol('RPC_CONTEXT');
8+
export const ASYNC_ITERATOR_FACTORY = Symbol('ASYNC_ITERATOR_FACTORY');
9+
export const ZOD_INPUT_DATA = Symbol('ZOD_INPUT_DATA');
10+
11+
export const ErrorCode: Record<ErrorCodeType, number> = {
12+
[ErrorCodeType.ParseError]: -32700,
13+
[ErrorCodeType.InvalidRequest]: -32600,
14+
[ErrorCodeType.MethodNotFound]: -32601,
15+
[ErrorCodeType.InvalidParams]: -32602,
16+
[ErrorCodeType.InternalError]: -32603,
17+
[ErrorCodeType.ServerError]: -32000,
18+
} as const;

0 commit comments

Comments
 (0)