MCPcopy
hub / github.com/nestjs/nest / PipesContextCreator

Class PipesContextCreator

packages/core/pipes/pipes-context-creator.ts:11–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import { InstanceWrapper } from '../injector/instance-wrapper';
10
11export class PipesContextCreator extends ContextCreator {
12 private moduleContext: string;
13
14 constructor(
15 private readonly container: NestContainer,
16 private readonly config?: ApplicationConfig,
17 ) {
18 super();
19 }
20
21 public create(
22 instance: Controller,
23 callback: (...args: unknown[]) => unknown,
24 moduleKey: string,
25 contextId = STATIC_CONTEXT,
26 inquirerId?: string,
27 ): PipeTransform[] {
28 this.moduleContext = moduleKey;
29 return this.createContext(
30 instance,
31 callback,
32 PIPES_METADATA,
33 contextId,
34 inquirerId,
35 );
36 }
37
38 public createConcreteContext<T extends any[], R extends any[]>(
39 metadata: T,
40 contextId = STATIC_CONTEXT,
41 inquirerId?: string,
42 ): R {
43 if (isEmpty(metadata)) {
44 return [] as any[] as R;
45 }
46 return iterate(metadata)
47 .filter((pipe: any) => pipe && (pipe.name || pipe.transform))
48 .map(pipe => this.getPipeInstance(pipe, contextId, inquirerId))
49 .filter(pipe => !!pipe && pipe.transform && isFunction(pipe.transform))
50 .toArray() as R;
51 }
52
53 public getPipeInstance(
54 pipe: Function | PipeTransform,
55 contextId = STATIC_CONTEXT,
56 inquirerId?: string,
57 ): PipeTransform | null {
58 const isObject = !!(pipe as PipeTransform).transform;
59 if (isObject) {
60 return pipe as PipeTransform;
61 }
62 const instanceWrapper = this.getInstanceByMetatype(pipe as Type<unknown>);
63 if (!instanceWrapper) {
64 return null;
65 }
66 const instanceHost = instanceWrapper.getInstanceByContextId(
67 this.getContextId(contextId, instanceWrapper),
68 inquirerId,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected