1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ContextUtils = void 0;
|
4 | const constants_1 = require("@nestjs/common/constants");
|
5 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
6 | const execution_context_host_1 = require("./execution-context-host");
|
7 | class ContextUtils {
|
8 | mapParamType(key) {
|
9 | const keyPair = key.split(':');
|
10 | return keyPair[0];
|
11 | }
|
12 | reflectCallbackParamtypes(instance, methodName) {
|
13 | return Reflect.getMetadata(constants_1.PARAMTYPES_METADATA, instance, methodName);
|
14 | }
|
15 | reflectCallbackMetadata(instance, methodName, metadataKey) {
|
16 | return Reflect.getMetadata(metadataKey, instance.constructor, methodName);
|
17 | }
|
18 | reflectPassthrough(instance, methodName) {
|
19 | return Reflect.getMetadata(constants_1.RESPONSE_PASSTHROUGH_METADATA, instance.constructor, methodName);
|
20 | }
|
21 | getArgumentsLength(keys, metadata) {
|
22 | return keys.length
|
23 | ? Math.max(...keys.map(key => metadata[key].index)) + 1
|
24 | : 0;
|
25 | }
|
26 | createNullArray(length) {
|
27 | const a = new Array(length);
|
28 | for (let i = 0; i < length; ++i)
|
29 | a[i] = undefined;
|
30 | return a;
|
31 | }
|
32 | mergeParamsMetatypes(paramsProperties, paramtypes) {
|
33 | if (!paramtypes) {
|
34 | return paramsProperties;
|
35 | }
|
36 | return paramsProperties.map(param => (Object.assign(Object.assign({}, param), { metatype: paramtypes[param.index] })));
|
37 | }
|
38 | getCustomFactory(factory, data, contextFactory) {
|
39 | return (0, shared_utils_1.isFunction)(factory)
|
40 | ? (...args) => factory(data, contextFactory(args))
|
41 | : () => null;
|
42 | }
|
43 | getContextFactory(contextType, instance, callback) {
|
44 | const contextFactory = (args) => {
|
45 | const ctx = new execution_context_host_1.ExecutionContextHost(args, instance && instance.constructor, callback);
|
46 | ctx.setType(contextType);
|
47 | return ctx;
|
48 | };
|
49 | return contextFactory;
|
50 | }
|
51 | }
|
52 | exports.ContextUtils = ContextUtils;
|