1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Args = void 0;
|
4 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
5 | require("reflect-metadata");
|
6 | const gql_paramtype_enum_1 = require("../enums/gql-paramtype.enum");
|
7 | const lazy_metadata_storage_1 = require("../schema-builder/storages/lazy-metadata.storage");
|
8 | const type_metadata_storage_1 = require("../schema-builder/storages/type-metadata.storage");
|
9 | const is_pipe_util_1 = require("../utils/is-pipe.util");
|
10 | const reflection_utilts_1 = require("../utils/reflection.utilts");
|
11 | const param_utils_1 = require("./param.utils");
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function Args(propertyOrOptionsOrPipe, optionsOrPipe, ...pipes) {
|
18 | const [property, argOptions, argPipes] = getArgsOptions(propertyOrOptionsOrPipe, optionsOrPipe, pipes);
|
19 | return (target, key, index) => {
|
20 | (0, param_utils_1.addPipesMetadata)(gql_paramtype_enum_1.GqlParamtype.ARGS, property, argPipes, target, key, index);
|
21 | lazy_metadata_storage_1.LazyMetadataStorage.store(target.constructor, () => {
|
22 | const { typeFn: reflectedTypeFn, options } = (0, reflection_utilts_1.reflectTypeFromMetadata)({
|
23 | metadataKey: 'design:paramtypes',
|
24 | prototype: target,
|
25 | propertyKey: key,
|
26 | index: index,
|
27 | explicitTypeFn: argOptions.type,
|
28 | typeOptions: argOptions,
|
29 | });
|
30 | const metadata = {
|
31 | target: target.constructor,
|
32 | methodName: key,
|
33 | typeFn: reflectedTypeFn,
|
34 | index,
|
35 | options,
|
36 | };
|
37 | if (property && (0, shared_utils_1.isString)(property)) {
|
38 | type_metadata_storage_1.TypeMetadataStorage.addMethodParamMetadata({
|
39 | kind: 'arg',
|
40 | name: property,
|
41 | description: argOptions.description,
|
42 | ...metadata,
|
43 | });
|
44 | }
|
45 | else {
|
46 | type_metadata_storage_1.TypeMetadataStorage.addMethodParamMetadata({
|
47 | kind: 'args',
|
48 | ...metadata,
|
49 | });
|
50 | }
|
51 | });
|
52 | };
|
53 | }
|
54 | exports.Args = Args;
|
55 | function getArgsOptions(propertyOrOptionsOrPipe, optionsOrPipe, pipes) {
|
56 | if (!propertyOrOptionsOrPipe || (0, shared_utils_1.isString)(propertyOrOptionsOrPipe)) {
|
57 | const propertyKey = propertyOrOptionsOrPipe;
|
58 | let options = {};
|
59 | let argPipes = [];
|
60 | if ((0, is_pipe_util_1.isPipe)(optionsOrPipe)) {
|
61 | argPipes = [optionsOrPipe].concat(pipes);
|
62 | }
|
63 | else {
|
64 | options = optionsOrPipe || {};
|
65 | argPipes = pipes;
|
66 | }
|
67 | return [propertyKey, options, argPipes];
|
68 | }
|
69 | const isArgsOptionsObject = (0, shared_utils_1.isObject)(propertyOrOptionsOrPipe) &&
|
70 | !(0, shared_utils_1.isFunction)(propertyOrOptionsOrPipe.transform);
|
71 | if (isArgsOptionsObject) {
|
72 | const argOptions = propertyOrOptionsOrPipe;
|
73 | const propertyKey = argOptions.name;
|
74 | const argPipes = optionsOrPipe ? [optionsOrPipe].concat(pipes) : pipes;
|
75 | return [
|
76 | propertyKey,
|
77 | argOptions,
|
78 | argPipes,
|
79 | ];
|
80 | }
|
81 |
|
82 | let argPipes = [propertyOrOptionsOrPipe];
|
83 | if (optionsOrPipe) {
|
84 | argPipes = argPipes.concat(optionsOrPipe);
|
85 | }
|
86 | argPipes = argPipes.concat(pipes);
|
87 | return [undefined, {}, argPipes];
|
88 | }
|