UNPKG

1.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.ExecutionContextHost = void 0;
4class 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 });
47 }
48}
49exports.ExecutionContextHost = ExecutionContextHost;