UNPKG

2.14 kBTypeScriptView Raw
1export type ContextType = 'http' | 'ws' | 'rpc';
2/**
3 * Methods to obtain request and response objects.
4 *
5 * @publicApi
6 */
7export interface HttpArgumentsHost {
8 /**
9 * Returns the in-flight `request` object.
10 */
11 getRequest<T = any>(): T;
12 /**
13 * Returns the in-flight `response` object.
14 */
15 getResponse<T = any>(): T;
16 getNext<T = any>(): T;
17}
18/**
19 * Methods to obtain WebSocket data and client objects.
20 *
21 * @publicApi
22 */
23export interface WsArgumentsHost {
24 /**
25 * Returns the data object.
26 */
27 getData<T = any>(): T;
28 /**
29 * Returns the client object.
30 */
31 getClient<T = any>(): T;
32 /**
33 * Returns the pattern for the event
34 */
35 getPattern(): string;
36}
37/**
38 * Methods to obtain RPC data object.
39 *
40 * @publicApi
41 */
42export interface RpcArgumentsHost {
43 /**
44 * Returns the data object.
45 */
46 getData<T = any>(): T;
47 /**
48 * Returns the context object.
49 */
50 getContext<T = any>(): T;
51}
52/**
53 * Provides methods for retrieving the arguments being passed to a handler.
54 * Allows choosing the appropriate execution context (e.g., Http, RPC, or
55 * WebSockets) to retrieve the arguments from.
56 *
57 * @publicApi
58 */
59export interface ArgumentsHost {
60 /**
61 * Returns the array of arguments being passed to the handler.
62 */
63 getArgs<T extends Array<any> = any[]>(): T;
64 /**
65 * Returns a particular argument by index.
66 * @param index index of argument to retrieve
67 */
68 getArgByIndex<T = any>(index: number): T;
69 /**
70 * Switch context to RPC.
71 * @returns interface with methods to retrieve RPC arguments
72 */
73 switchToRpc(): RpcArgumentsHost;
74 /**
75 * Switch context to HTTP.
76 * @returns interface with methods to retrieve HTTP arguments
77 */
78 switchToHttp(): HttpArgumentsHost;
79 /**
80 * Switch context to WebSockets.
81 * @returns interface with methods to retrieve WebSockets arguments
82 */
83 switchToWs(): WsArgumentsHost;
84 /**
85 * Returns the current execution context type (string)
86 */
87 getType<TContext extends string = ContextType>(): TContext;
88}