UNPKG

@deepkit/framework

Version:

109 lines 5.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcKernelWithStopwatch = exports.RpcKernelConnectionWithStopwatch = exports.RpcServerActionWithStopwatch = exports.RpcInjectorContext = exports.RpcControllers = void 0; /*@ts-ignore*/ const { __ΩClassType } = require('@deepkit/core'); /*@ts-ignore*/ const { __ΩrpcActionType } = require('@deepkit/rpc'); /*@ts-ignore*/ const { __ΩRpcControllerAccess } = require('@deepkit/rpc'); /*@ts-ignore*/ const { __ΩTransportConnection } = require('@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. */ const injector_1 = require("@deepkit/injector"); const rpc_1 = require("@deepkit/rpc"); const stopwatch_1 = require("@deepkit/stopwatch"); const app_1 = require("@deepkit/app"); class RpcControllers { constructor() { this.controllers = (Map.Ω = [['&'], [() => __ΩClassType, 'controller', () => app_1.AppModule, 'module', 'Pn!4"P"7#4$M']], new Map()); } } exports.RpcControllers = RpcControllers; RpcControllers.__type = ['controllers', function () { return (Map.Ω = [['&'], [() => __ΩClassType, 'controller', () => app_1.AppModule, 'module', 'Pn!4"P"7#4$M']], new Map()); }, 'RpcControllers', '!3!9>"5w#']; class RpcInjectorContext extends injector_1.InjectorContext { } exports.RpcInjectorContext = RpcInjectorContext; RpcInjectorContext.__type = [() => injector_1.InjectorContext, 'RpcInjectorContext', 'P7!5w"']; class RpcServerActionWithStopwatch extends rpc_1.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 + ']', stopwatch_1.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(); } } } exports.RpcServerActionWithStopwatch = RpcServerActionWithStopwatch; RpcServerActionWithStopwatch.__type = [() => rpc_1.RpcServerAction, () => stopwatch_1.Stopwatch, 'stopwatch', () => __ΩRpcControllerAccess, 'controllerAccess', () => rpc_1.RpcKernelBaseConnection, 'connection', 'hasControllerAccess', () => rpc_1.RpcMessage, 'message', () => rpc_1.RpcMessageBuilder, 'response', 'handleAction', 'RpcServerActionWithStopwatch', 'P7!P7"3#8Pn$2%P7&2\')`0(<PP7)2*P7+2,$`0-5w.']; class RpcKernelConnectionWithStopwatch extends rpc_1.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', stopwatch_1.FrameCategory.rpcAuthenticate, true) : undefined; try { return await super.authenticate(message, response); } finally { if (frame) frame.end(); } } } exports.RpcKernelConnectionWithStopwatch = RpcKernelConnectionWithStopwatch; RpcKernelConnectionWithStopwatch.__type = [() => rpc_1.RpcKernelConnection, 'actionHandler', function () { return new RpcServerActionWithStopwatch(this.stats, this.cache, this, this.controllers, this.injector, this.eventDispatcher, this.security, this.sessionState, this.logger); }, () => stopwatch_1.Stopwatch, 'stopwatch', () => stopwatch_1.Stopwatch, 'setStopwatch', () => rpc_1.RpcMessage, 'message', () => rpc_1.RpcMessageBuilder, 'response', 'authenticate', 'RpcKernelConnectionWithStopwatch', 'P7!!3"<>#P7$3%8PP7&2%"0\'PP7(2)P7*2+$`0,<5w-']; class RpcKernelWithStopwatch extends rpc_1.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; } } exports.RpcKernelWithStopwatch = RpcKernelWithStopwatch; RpcKernelWithStopwatch.__type = [() => rpc_1.RpcKernel, 'RpcKernelConnection', function () { return RpcKernelConnectionWithStopwatch; }, () => stopwatch_1.Stopwatch, 'stopwatch', () => __ΩTransportConnection, 'transport', () => injector_1.InjectorContext, 'injector', () => rpc_1.RpcKernelBaseConnection, 'createConnection', 'RpcKernelWithStopwatch', 'P7!!3"<>#P7$3%8Pn&2\'P7(2)8P7*0+5w,']; //# sourceMappingURL=rpc.js.map