@deepkit/framework
Version:
101 lines • 5.29 kB
JavaScript
/*@ts-ignore*/
import { __ΩClassType } from '@deepkit/core';
/*@ts-ignore*/
import { __ΩrpcActionType } from '@deepkit/rpc';
/*@ts-ignore*/
import { __ΩRpcControllerAccess } from '@deepkit/rpc';
/*@ts-ignore*/
import { __ΩTransportConnection } from '@deepkit/rpc';
/*
* Deepkit Framework
* Copyright (C) 2021 Deepkit UG, Marc J. Schmidt
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the MIT License.
*
* You should have received a copy of the MIT License along with this program.
*/
import { InjectorContext } from '@deepkit/injector';
import { RpcKernel, RpcKernelBaseConnection, RpcKernelConnection, RpcMessage, RpcMessageBuilder, RpcServerAction, } from '@deepkit/rpc';
import { FrameCategory, Stopwatch } from '@deepkit/stopwatch';
import { AppModule } from '@deepkit/app';
export class RpcControllers {
constructor() {
this.controllers = (Map.Ω = [['&'], [() => __ΩClassType, 'controller', () => AppModule, 'module', 'Pn!4"P"7#4$M']], new Map());
}
}
RpcControllers.__type = ['controllers', function () { return (Map.Ω = [['&'], [() => __ΩClassType, 'controller', () => AppModule, 'module', 'Pn!4"P"7#4$M']], new Map()); }, 'RpcControllers', '!3!9>"5w#'];
export class RpcInjectorContext extends InjectorContext {
}
RpcInjectorContext.__type = [() => InjectorContext, 'RpcInjectorContext', 'P7!5w"'];
export class RpcServerActionWithStopwatch extends RpcServerAction {
async hasControllerAccess(controllerAccess, connection) {
const frame = this.stopwatch ? this.stopwatch.start('RPC/controllerAccess') : undefined;
try {
return await super.hasControllerAccess(controllerAccess, connection);
}
finally {
if (frame)
frame.end();
}
}
async handleAction(message, response) {
const body = (message.parseBody.Ω = [[() => __ΩrpcActionType, 'n!']], message.parseBody());
const frame = this.stopwatch ? this.stopwatch.start(body.method + '() [' + body.controller + ']', FrameCategory.rpc, true) : undefined;
if (frame) {
try {
const types = await this.loadTypes(body.controller, body.method);
const value = message.parseBody(types.actionCallSchema);
frame.data({ method: body.method, controller: body.controller, arguments: value.args });
}
catch {
}
}
try {
if (frame)
return await frame.run(() => super.handleAction(message, response));
return await super.handleAction(message, response);
}
finally {
if (frame)
frame.end();
}
}
}
RpcServerActionWithStopwatch.__type = [() => RpcServerAction, () => Stopwatch, 'stopwatch', () => __ΩRpcControllerAccess, 'controllerAccess', () => RpcKernelBaseConnection, 'connection', 'hasControllerAccess', () => RpcMessage, 'message', () => RpcMessageBuilder, 'response', 'handleAction', 'RpcServerActionWithStopwatch', 'P7!P7"3#8Pn$2%P7&2\')`0(<PP7)2*P7+2,$`0-5w.'];
export class RpcKernelConnectionWithStopwatch extends RpcKernelConnection {
constructor() {
super(...arguments);
this.actionHandler = new RpcServerActionWithStopwatch(this.stats, this.cache, this, this.controllers, this.injector, this.eventDispatcher, this.security, this.sessionState, this.logger);
}
setStopwatch(stopwatch) {
this.stopwatch = stopwatch;
this.actionHandler.stopwatch = stopwatch;
}
async authenticate(message, response) {
const frame = this.stopwatch ? this.stopwatch.start('RPC/authenticate', FrameCategory.rpcAuthenticate, true) : undefined;
try {
return await super.authenticate(message, response);
}
finally {
if (frame)
frame.end();
}
}
}
RpcKernelConnectionWithStopwatch.__type = [() => RpcKernelConnection, 'actionHandler', function () { return new RpcServerActionWithStopwatch(this.stats, this.cache, this, this.controllers, this.injector, this.eventDispatcher, this.security, this.sessionState, this.logger); }, () => Stopwatch, 'stopwatch', () => Stopwatch, 'setStopwatch', () => RpcMessage, 'message', () => RpcMessageBuilder, 'response', 'authenticate', 'RpcKernelConnectionWithStopwatch', 'P7!!3"<>#P7$3%8PP7&2%"0\'PP7(2)P7*2+$`0,<5w-'];
export class RpcKernelWithStopwatch extends RpcKernel {
constructor() {
super(...arguments);
this.RpcKernelConnection = RpcKernelConnectionWithStopwatch;
}
createConnection(transport, injector) {
const connection = super.createConnection(transport, injector);
if (this.stopwatch && connection instanceof RpcKernelConnectionWithStopwatch) {
connection.setStopwatch(this.stopwatch);
}
return connection;
}
}
RpcKernelWithStopwatch.__type = [() => RpcKernel, 'RpcKernelConnection', function () { return RpcKernelConnectionWithStopwatch; }, () => Stopwatch, 'stopwatch', () => __ΩTransportConnection, 'transport', () => InjectorContext, 'injector', () => RpcKernelBaseConnection, 'createConnection', 'RpcKernelWithStopwatch', 'P7!!3"<>#P7$3%8Pn&2\'P7(2)8P7*0+5w,'];
//# sourceMappingURL=rpc.js.map