Add jsonrpc services to server(s)
This commit is contained in:
parent
7434c9fb42
commit
2f35b65f48
@ -16,7 +16,7 @@ export interface IJSONRPCReturnType {
|
||||
addService<T, F extends FunctionPropertyNames<T>>(
|
||||
path: string,
|
||||
service: T,
|
||||
methods: F[],
|
||||
methods?: F[],
|
||||
): IJSONRPCReturnType,
|
||||
router(): Router
|
||||
}
|
||||
@ -62,7 +62,7 @@ export function jsonrpc<Context>(
|
||||
addService<T, F extends FunctionPropertyNames<T>>(
|
||||
path: string,
|
||||
service: T,
|
||||
methods: F[],
|
||||
methods?: F[],
|
||||
) {
|
||||
const rpcService = createRpcService(service, methods)
|
||||
|
||||
|
||||
@ -102,9 +102,9 @@ async function validateServiceContext<
|
||||
|
||||
export const createRpcService = <T, M extends FunctionPropertyNames<T>>(
|
||||
service: T,
|
||||
methods: M[],
|
||||
methods?: M[],
|
||||
) => {
|
||||
const rpcService = pick(service, methods)
|
||||
const rpcService = methods ? pick(service, methods) : service
|
||||
return {
|
||||
async invoke<Context>(
|
||||
req: IRequest<M, ArgumentTypes<T[M]>>,
|
||||
@ -127,6 +127,7 @@ export const createRpcService = <T, M extends FunctionPropertyNames<T>>(
|
||||
const isNotification = req.id === null || req.id === undefined
|
||||
|
||||
if (
|
||||
method.startsWith('_') ||
|
||||
!rpcService.hasOwnProperty(method) ||
|
||||
typeof rpcService[method] !== 'function'
|
||||
) {
|
||||
|
||||
@ -60,6 +60,7 @@ export class Application implements IApplication {
|
||||
|
||||
this.configureMiddleware(router)
|
||||
this.configureRouter(router)
|
||||
this.configureRPC(router)
|
||||
this.configureApiErrorHandling(router)
|
||||
this.configureFrontend(router)
|
||||
|
||||
@ -109,17 +110,23 @@ export class Application implements IApplication {
|
||||
this.services.userPermissions,
|
||||
this.createTransactionalRouter(),
|
||||
).handle)
|
||||
}
|
||||
|
||||
router.use(
|
||||
'/rpc',
|
||||
jsonrpc(
|
||||
protected jsonrpc() {
|
||||
return jsonrpc(
|
||||
req => ({user: req.user}),
|
||||
this.getApiLogger(),
|
||||
)
|
||||
.addService('/teamService',
|
||||
}
|
||||
|
||||
protected configureRPC(router: express.Router) {
|
||||
router.use(
|
||||
'/rpc',
|
||||
this.jsonrpc()
|
||||
.addService('/team',
|
||||
new rpc.TeamService(this.database, this.services.userPermissions),
|
||||
keys<rpc.TeamService>())
|
||||
.addService('/userService',
|
||||
.addService('/user',
|
||||
new rpc.UserService(this.database),
|
||||
keys<rpc.UserService>())
|
||||
.router(),
|
||||
|
||||
@ -11,3 +11,6 @@ export * from './session'
|
||||
export * from './user'
|
||||
export * from './team'
|
||||
export * from './validator'
|
||||
|
||||
import * as rpc from './rpc'
|
||||
export {rpc}
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
"semicolon": [true, "never"],
|
||||
"object-literal-sort-keys": false,
|
||||
"ordered-imports": false,
|
||||
"max-line-length": [true, 80],
|
||||
"max-line-length": [true, {"limit":80, "ignore-pattern": "^import .* from "}],
|
||||
"arrow-parens": false,
|
||||
"variable-name": [
|
||||
true,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user