mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
38 lines
884 B
TypeScript
38 lines
884 B
TypeScript
import { BaseRpcContext } from '../ctx-host/base-rpc.context';
|
|
import { RequestContext } from '../interfaces';
|
|
|
|
/**
|
|
* @publicApi
|
|
*/
|
|
export class RequestContextHost<
|
|
TData = any,
|
|
TContext extends BaseRpcContext = any,
|
|
> implements RequestContext<TData> {
|
|
constructor(
|
|
public readonly pattern: string | Record<string, any>,
|
|
public readonly data: TData,
|
|
public readonly context: TContext,
|
|
) {}
|
|
|
|
static create<TData, TContext extends BaseRpcContext>(
|
|
pattern: string | Record<string, any>,
|
|
data: TData,
|
|
context: TContext,
|
|
): RequestContext<TData, TContext> {
|
|
const host = new RequestContextHost(pattern, data, context);
|
|
return host;
|
|
}
|
|
|
|
public getData(): TData {
|
|
return this.data;
|
|
}
|
|
|
|
public getPattern(): string | Record<string, any> {
|
|
return this.pattern;
|
|
}
|
|
|
|
public getContext(): TContext {
|
|
return this.context;
|
|
}
|
|
}
|