1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ExecutionContextHost = void 0;
|
4 | class ExecutionContextHost {
|
5 | constructor(args, constructorRef = null, handler = null) {
|
6 | this.args = args;
|
7 | this.constructorRef = constructorRef;
|
8 | this.handler = handler;
|
9 | this.contextType = 'http';
|
10 | }
|
11 | setType(type) {
|
12 | type && (this.contextType = type);
|
13 | }
|
14 | getType() {
|
15 | return this.contextType;
|
16 | }
|
17 | getClass() {
|
18 | return this.constructorRef;
|
19 | }
|
20 | getHandler() {
|
21 | return this.handler;
|
22 | }
|
23 | getArgs() {
|
24 | return this.args;
|
25 | }
|
26 | getArgByIndex(index) {
|
27 | return this.args[index];
|
28 | }
|
29 | switchToRpc() {
|
30 | return Object.assign(this, {
|
31 | getData: () => this.getArgByIndex(0),
|
32 | getContext: () => this.getArgByIndex(1),
|
33 | });
|
34 | }
|
35 | switchToHttp() {
|
36 | return Object.assign(this, {
|
37 | getRequest: () => this.getArgByIndex(0),
|
38 | getResponse: () => this.getArgByIndex(1),
|
39 | getNext: () => this.getArgByIndex(2),
|
40 | });
|
41 | }
|
42 | switchToWs() {
|
43 | return Object.assign(this, {
|
44 | getClient: () => this.getArgByIndex(0),
|
45 | getData: () => this.getArgByIndex(1),
|
46 | getPattern: () => this.getArgByIndex(this.getArgs().length - 1),
|
47 | });
|
48 | }
|
49 | }
|
50 | exports.ExecutionContextHost = ExecutionContextHost;
|