@nestia/sdk 11.0.0-dev.20260316 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/executable/internal/NestiaConfigLoader.js +5 -5
  15. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  16. package/package.json +8 -8
  17. package/src/INestiaConfig.ts +267 -267
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +143 -143
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/DtoAnalyzer.ts +260 -260
  22. package/src/analyses/ImportAnalyzer.ts +126 -126
  23. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  24. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -72
  25. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  26. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -126
  27. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -208
  28. package/src/executable/internal/NestiaConfigLoader.ts +85 -85
  29. package/src/executable/internal/NestiaSdkCommand.ts +107 -107
  30. package/src/generates/SwaggerGenerator.ts +291 -291
  31. package/src/generates/internal/E2eFileProgrammer.ts +196 -196
  32. package/src/generates/internal/FilePrinter.ts +64 -64
  33. package/src/generates/internal/ImportDictionary.ts +192 -192
  34. package/src/generates/internal/SdkAliasCollection.ts +260 -260
  35. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  36. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  37. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  38. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -278
  39. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -502
  40. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  41. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -312
  42. package/src/generates/internal/SdkImportWizard.ts +62 -62
  43. package/src/generates/internal/SdkTypeProgrammer.ts +388 -388
  44. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  45. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -379
  46. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  47. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  48. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -161
  49. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  50. package/src/module.ts +4 -4
  51. package/src/structures/IReflectHttpOperationException.ts +18 -18
  52. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  53. package/src/structures/IReflectHttpOperationSuccess.ts +21 -21
  54. package/src/structures/ITypedApplication.ts +11 -11
  55. package/src/structures/ITypedHttpRouteException.ts +15 -15
  56. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  57. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  58. package/src/transformers/IOperationMetadata.ts +46 -46
  59. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  60. package/src/transformers/SdkOperationProgrammer.ts +240 -240
  61. package/src/transformers/SdkOperationTransformer.ts +248 -248
  62. package/src/transformers/TextPlainValidator.ts +17 -17
  63. package/src/utils/MetadataUtil.ts +26 -26
  64. package/src/validators/HttpHeadersValidator.ts +40 -40
  65. package/src/validators/HttpQueryValidator.ts +40 -40
@@ -1,46 +1,46 @@
1
- import {
2
- IMetadataComponents,
3
- IMetadataSchema,
4
- ValidationPipe,
5
- } from "@typia/interface";
6
- import { IJsDocTagInfo } from "typia";
7
-
8
- import { IReflectImport } from "../structures/IReflectImport";
9
- import { IReflectType } from "../structures/IReflectType";
10
-
11
- export interface IOperationMetadata {
12
- parameters: IOperationMetadata.IParameter[];
13
- success: IOperationMetadata.IResponse;
14
- exceptions: IOperationMetadata.IResponse[];
15
- description: string | null;
16
- jsDocTags: IJsDocTagInfo[];
17
- }
18
- export namespace IOperationMetadata {
19
- export interface IParameter extends IResponse {
20
- name: string;
21
- index: number;
22
- description: string | null;
23
- jsDocTags: IJsDocTagInfo[];
24
- }
25
- export interface IResponse {
26
- type: IReflectType | null;
27
- imports: IReflectImport[];
28
- primitive: ValidationPipe<ISchema, IError>;
29
- resolved: ValidationPipe<ISchema, IError>;
30
- }
31
- export interface IException {
32
- type: IReflectType | null;
33
- imports: IReflectImport[];
34
- primitive: ValidationPipe<ISchema, IError>;
35
- }
36
-
37
- export interface ISchema {
38
- components: IMetadataComponents;
39
- metadata: IMetadataSchema;
40
- }
41
- export interface IError {
42
- name: string;
43
- accessor: string | null;
44
- messages: string[];
45
- }
46
- }
1
+ import {
2
+ IMetadataComponents,
3
+ IMetadataSchema,
4
+ ValidationPipe,
5
+ } from "@typia/interface";
6
+ import { IJsDocTagInfo } from "typia";
7
+
8
+ import { IReflectImport } from "../structures/IReflectImport";
9
+ import { IReflectType } from "../structures/IReflectType";
10
+
11
+ export interface IOperationMetadata {
12
+ parameters: IOperationMetadata.IParameter[];
13
+ success: IOperationMetadata.IResponse;
14
+ exceptions: IOperationMetadata.IResponse[];
15
+ description: string | null;
16
+ jsDocTags: IJsDocTagInfo[];
17
+ }
18
+ export namespace IOperationMetadata {
19
+ export interface IParameter extends IResponse {
20
+ name: string;
21
+ index: number;
22
+ description: string | null;
23
+ jsDocTags: IJsDocTagInfo[];
24
+ }
25
+ export interface IResponse {
26
+ type: IReflectType | null;
27
+ imports: IReflectImport[];
28
+ primitive: ValidationPipe<ISchema, IError>;
29
+ resolved: ValidationPipe<ISchema, IError>;
30
+ }
31
+ export interface IException {
32
+ type: IReflectType | null;
33
+ imports: IReflectImport[];
34
+ primitive: ValidationPipe<ISchema, IError>;
35
+ }
36
+
37
+ export interface ISchema {
38
+ components: IMetadataComponents;
39
+ metadata: IMetadataSchema;
40
+ }
41
+ export interface IError {
42
+ name: string;
43
+ accessor: string | null;
44
+ messages: string[];
45
+ }
46
+ }
@@ -1,8 +1,8 @@
1
- import { MetadataCollection } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- export interface ISdkOperationTransformerContext {
5
- checker: ts.TypeChecker;
6
- transformer: ts.TransformationContext;
7
- collection: MetadataCollection;
8
- }
1
+ import { MetadataCollection } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ export interface ISdkOperationTransformerContext {
5
+ checker: ts.TypeChecker;
6
+ transformer: ts.TransformationContext;
7
+ collection: MetadataCollection;
8
+ }
@@ -1,240 +1,240 @@
1
- import {
2
- CommentFactory,
3
- MetadataCollection,
4
- MetadataFactory,
5
- MetadataObjectType,
6
- MetadataSchema,
7
- TypeFactory,
8
- } from "@typia/core";
9
- import { ValidationPipe } from "@typia/interface";
10
- import { NamingConvention } from "@typia/utils";
11
- import { Singleton } from "tstl";
12
- import ts from "typescript";
13
-
14
- import { DtoAnalyzer } from "../analyses/DtoAnalyzer";
15
- import { IReflectImport } from "../structures/IReflectImport";
16
- import { MetadataUtil } from "../utils/MetadataUtil";
17
- import { IOperationMetadata } from "./IOperationMetadata";
18
- import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
19
-
20
- export namespace SdkOperationProgrammer {
21
- export interface IProps {
22
- context: ISdkOperationTransformerContext;
23
- imports: Singleton<IReflectImport[]>;
24
- node: ts.MethodDeclaration;
25
- symbol: ts.Symbol | undefined;
26
- exceptions: ts.TypeNode[];
27
- }
28
- export const write = (p: IProps): IOperationMetadata => {
29
- return {
30
- parameters: p.node.parameters.map((parameter, index) =>
31
- writeParameter({
32
- context: p.context,
33
- imports: p.imports,
34
- parameter,
35
- index,
36
- }),
37
- ),
38
- success: writeResponse({
39
- context: p.context,
40
- imports: p.imports,
41
- typeNode: p.node.type ? getReturnTypeNode(p.node.type) : null,
42
- type: getReturnType({
43
- checker: p.context.checker,
44
- signature: p.context.checker.getSignatureFromDeclaration(p.node),
45
- }),
46
- }),
47
- exceptions: p.exceptions.map((e) =>
48
- writeResponse({
49
- context: p.context,
50
- imports: p.imports,
51
- typeNode: e,
52
- type: p.context.checker.getTypeFromTypeNode(e),
53
- }),
54
- ),
55
- jsDocTags: p.symbol?.getJsDocTags() ?? [],
56
- description: p.symbol
57
- ? (CommentFactory.description(p.symbol) ?? null)
58
- : null,
59
- };
60
- };
61
-
62
- const writeParameter = (props: {
63
- context: ISdkOperationTransformerContext;
64
- imports: Singleton<IReflectImport[]>;
65
- parameter: ts.ParameterDeclaration;
66
- index: number;
67
- }): IOperationMetadata.IParameter => {
68
- const symbol: ts.Symbol | undefined =
69
- props.context.checker.getSymbolAtLocation(props.parameter);
70
- const common: IOperationMetadata.IResponse = writeResponse({
71
- context: props.context,
72
- imports: props.imports,
73
- typeNode: props.parameter.type ?? null,
74
- type:
75
- props.context.checker.getTypeFromTypeNode(
76
- props.parameter.type ?? TypeFactory.keyword("any"),
77
- ) ?? null,
78
- });
79
- const optional: boolean = props.parameter.questionToken !== undefined;
80
- if (common.primitive.success)
81
- common.primitive.data.metadata.optional = optional;
82
- if (common.resolved.success)
83
- common.resolved.data.metadata.optional = optional;
84
-
85
- return {
86
- ...common,
87
- name: props.parameter.name.getText(),
88
- index: props.index,
89
- description: (symbol && CommentFactory.description(symbol)) ?? null,
90
- jsDocTags: symbol?.getJsDocTags() ?? [],
91
- };
92
- };
93
-
94
- const writeResponse = (p: {
95
- context: ISdkOperationTransformerContext;
96
- imports: Singleton<IReflectImport[]>;
97
- typeNode: ts.TypeNode | null;
98
- type: ts.Type | null;
99
- }): IOperationMetadata.IResponse => {
100
- const analyzed: DtoAnalyzer.IOutput | null = p.typeNode
101
- ? DtoAnalyzer.analyzeNode({
102
- checker: p.context.checker,
103
- imports: p.imports.get(),
104
- typeNode: p.typeNode,
105
- })
106
- : p.type
107
- ? DtoAnalyzer.analyzeType({
108
- checker: p.context.checker,
109
- imports: p.imports.get(),
110
- type: p.type,
111
- })
112
- : {
113
- type: { name: "any" },
114
- imports: [],
115
- };
116
- const [primitive, resolved] = [true, false].map((escape) =>
117
- MetadataFactory.analyze({
118
- checker: p.context.checker,
119
- transformer: p.context.transformer,
120
- options: {
121
- escape,
122
- constant: true,
123
- absorb: true,
124
- },
125
- components: p.context.collection,
126
- type: p.type,
127
- }),
128
- );
129
- return {
130
- ...(analyzed
131
- ? analyzed
132
- : {
133
- imports: [],
134
- type: null,
135
- }),
136
- primitive: writeSchema({
137
- collection: p.context.collection,
138
- result: primitive!,
139
- }),
140
- resolved: writeSchema({
141
- collection: p.context.collection,
142
- result: resolved!,
143
- }),
144
- };
145
- };
146
-
147
- const writeSchema = (p: {
148
- collection: MetadataCollection;
149
- result: ValidationPipe<MetadataSchema, MetadataFactory.IError>;
150
- }): ValidationPipe<IOperationMetadata.ISchema, IOperationMetadata.IError> => {
151
- if (p.result.success === false)
152
- return {
153
- success: false,
154
- errors: p.result.errors.map((e) => ({
155
- name: e.name,
156
- accessor:
157
- e.explore.object !== null
158
- ? join({
159
- object: e.explore.object,
160
- key: e.explore.property,
161
- })
162
- : null,
163
- messages: e.messages,
164
- })),
165
- };
166
- const visited: Set<string> = iterateVisited(p.result.data);
167
- return {
168
- success: true,
169
- data: {
170
- components: {
171
- objects: p.collection
172
- .objects()
173
- .filter((o) => visited.has(o.name))
174
- .map((o) => o.toJSON()),
175
- aliases: p.collection
176
- .aliases()
177
- .filter((a) => visited.has(a.name))
178
- .map((a) => a.toJSON()),
179
- arrays: p.collection
180
- .arrays()
181
- .filter((a) => visited.has(a.name))
182
- .map((a) => a.toJSON()),
183
- tuples: p.collection
184
- .tuples()
185
- .filter((t) => visited.has(t.name))
186
- .map((t) => t.toJSON()),
187
- },
188
- metadata: p.result.data.toJSON(),
189
- },
190
- };
191
- };
192
- }
193
-
194
- const iterateVisited = (metadata: MetadataSchema): Set<string> => {
195
- const names: Set<string> = new Set();
196
- MetadataUtil.visit((m) => {
197
- for (const alias of m.aliases) names.add(alias.type.name);
198
- for (const array of m.arrays) names.add(array.type.name);
199
- for (const tuple of m.tuples) names.add(tuple.type.name);
200
- for (const object of m.objects) names.add(object.type.name);
201
- })(metadata);
202
- return names;
203
- };
204
-
205
- const join = ({
206
- object,
207
- key,
208
- }: {
209
- object: MetadataObjectType;
210
- key: string | object | null;
211
- }) => {
212
- if (key === null) return object.name;
213
- else if (typeof key === "object") return `${object.name}[key]`;
214
- else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
215
- return `${object.name}[${JSON.stringify(key)}]`;
216
- };
217
-
218
- const getReturnTypeNode = (node: ts.TypeNode): ts.TypeNode | null => {
219
- if (ts.isTypeReferenceNode(node)) {
220
- const typeName: string = node.typeName.getText();
221
- if (typeName === "Promise") return node.typeArguments?.[0] ?? null;
222
- }
223
- return node;
224
- };
225
-
226
- const getReturnType = (p: {
227
- checker: ts.TypeChecker;
228
- signature: ts.Signature | undefined;
229
- }): ts.Type | null => {
230
- const type: ts.Type | null =
231
- (p.signature && p.checker.getReturnTypeOfSignature(p.signature)) ?? null;
232
- if (type === null) return null;
233
- else if (type.symbol?.name === "Promise") {
234
- const generic: readonly ts.Type[] = p.checker.getTypeArguments(
235
- type as ts.TypeReference,
236
- );
237
- return generic[0] ?? null;
238
- }
239
- return type;
240
- };
1
+ import {
2
+ CommentFactory,
3
+ MetadataCollection,
4
+ MetadataFactory,
5
+ MetadataObjectType,
6
+ MetadataSchema,
7
+ TypeFactory,
8
+ } from "@typia/core";
9
+ import { ValidationPipe } from "@typia/interface";
10
+ import { NamingConvention } from "@typia/utils";
11
+ import { Singleton } from "tstl";
12
+ import ts from "typescript";
13
+
14
+ import { DtoAnalyzer } from "../analyses/DtoAnalyzer";
15
+ import { IReflectImport } from "../structures/IReflectImport";
16
+ import { MetadataUtil } from "../utils/MetadataUtil";
17
+ import { IOperationMetadata } from "./IOperationMetadata";
18
+ import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
19
+
20
+ export namespace SdkOperationProgrammer {
21
+ export interface IProps {
22
+ context: ISdkOperationTransformerContext;
23
+ imports: Singleton<IReflectImport[]>;
24
+ node: ts.MethodDeclaration;
25
+ symbol: ts.Symbol | undefined;
26
+ exceptions: ts.TypeNode[];
27
+ }
28
+ export const write = (p: IProps): IOperationMetadata => {
29
+ return {
30
+ parameters: p.node.parameters.map((parameter, index) =>
31
+ writeParameter({
32
+ context: p.context,
33
+ imports: p.imports,
34
+ parameter,
35
+ index,
36
+ }),
37
+ ),
38
+ success: writeResponse({
39
+ context: p.context,
40
+ imports: p.imports,
41
+ typeNode: p.node.type ? getReturnTypeNode(p.node.type) : null,
42
+ type: getReturnType({
43
+ checker: p.context.checker,
44
+ signature: p.context.checker.getSignatureFromDeclaration(p.node),
45
+ }),
46
+ }),
47
+ exceptions: p.exceptions.map((e) =>
48
+ writeResponse({
49
+ context: p.context,
50
+ imports: p.imports,
51
+ typeNode: e,
52
+ type: p.context.checker.getTypeFromTypeNode(e),
53
+ }),
54
+ ),
55
+ jsDocTags: p.symbol?.getJsDocTags() ?? [],
56
+ description: p.symbol
57
+ ? (CommentFactory.description(p.symbol) ?? null)
58
+ : null,
59
+ };
60
+ };
61
+
62
+ const writeParameter = (props: {
63
+ context: ISdkOperationTransformerContext;
64
+ imports: Singleton<IReflectImport[]>;
65
+ parameter: ts.ParameterDeclaration;
66
+ index: number;
67
+ }): IOperationMetadata.IParameter => {
68
+ const symbol: ts.Symbol | undefined =
69
+ props.context.checker.getSymbolAtLocation(props.parameter);
70
+ const common: IOperationMetadata.IResponse = writeResponse({
71
+ context: props.context,
72
+ imports: props.imports,
73
+ typeNode: props.parameter.type ?? null,
74
+ type:
75
+ props.context.checker.getTypeFromTypeNode(
76
+ props.parameter.type ?? TypeFactory.keyword("any"),
77
+ ) ?? null,
78
+ });
79
+ const optional: boolean = props.parameter.questionToken !== undefined;
80
+ if (common.primitive.success)
81
+ common.primitive.data.metadata.optional = optional;
82
+ if (common.resolved.success)
83
+ common.resolved.data.metadata.optional = optional;
84
+
85
+ return {
86
+ ...common,
87
+ name: props.parameter.name.getText(),
88
+ index: props.index,
89
+ description: (symbol && CommentFactory.description(symbol)) ?? null,
90
+ jsDocTags: symbol?.getJsDocTags() ?? [],
91
+ };
92
+ };
93
+
94
+ const writeResponse = (p: {
95
+ context: ISdkOperationTransformerContext;
96
+ imports: Singleton<IReflectImport[]>;
97
+ typeNode: ts.TypeNode | null;
98
+ type: ts.Type | null;
99
+ }): IOperationMetadata.IResponse => {
100
+ const analyzed: DtoAnalyzer.IOutput | null = p.typeNode
101
+ ? DtoAnalyzer.analyzeNode({
102
+ checker: p.context.checker,
103
+ imports: p.imports.get(),
104
+ typeNode: p.typeNode,
105
+ })
106
+ : p.type
107
+ ? DtoAnalyzer.analyzeType({
108
+ checker: p.context.checker,
109
+ imports: p.imports.get(),
110
+ type: p.type,
111
+ })
112
+ : {
113
+ type: { name: "any" },
114
+ imports: [],
115
+ };
116
+ const [primitive, resolved] = [true, false].map((escape) =>
117
+ MetadataFactory.analyze({
118
+ checker: p.context.checker,
119
+ transformer: p.context.transformer,
120
+ options: {
121
+ escape,
122
+ constant: true,
123
+ absorb: true,
124
+ },
125
+ components: p.context.collection,
126
+ type: p.type,
127
+ }),
128
+ );
129
+ return {
130
+ ...(analyzed
131
+ ? analyzed
132
+ : {
133
+ imports: [],
134
+ type: null,
135
+ }),
136
+ primitive: writeSchema({
137
+ collection: p.context.collection,
138
+ result: primitive!,
139
+ }),
140
+ resolved: writeSchema({
141
+ collection: p.context.collection,
142
+ result: resolved!,
143
+ }),
144
+ };
145
+ };
146
+
147
+ const writeSchema = (p: {
148
+ collection: MetadataCollection;
149
+ result: ValidationPipe<MetadataSchema, MetadataFactory.IError>;
150
+ }): ValidationPipe<IOperationMetadata.ISchema, IOperationMetadata.IError> => {
151
+ if (p.result.success === false)
152
+ return {
153
+ success: false,
154
+ errors: p.result.errors.map((e) => ({
155
+ name: e.name,
156
+ accessor:
157
+ e.explore.object !== null
158
+ ? join({
159
+ object: e.explore.object,
160
+ key: e.explore.property,
161
+ })
162
+ : null,
163
+ messages: e.messages,
164
+ })),
165
+ };
166
+ const visited: Set<string> = iterateVisited(p.result.data);
167
+ return {
168
+ success: true,
169
+ data: {
170
+ components: {
171
+ objects: p.collection
172
+ .objects()
173
+ .filter((o) => visited.has(o.name))
174
+ .map((o) => o.toJSON()),
175
+ aliases: p.collection
176
+ .aliases()
177
+ .filter((a) => visited.has(a.name))
178
+ .map((a) => a.toJSON()),
179
+ arrays: p.collection
180
+ .arrays()
181
+ .filter((a) => visited.has(a.name))
182
+ .map((a) => a.toJSON()),
183
+ tuples: p.collection
184
+ .tuples()
185
+ .filter((t) => visited.has(t.name))
186
+ .map((t) => t.toJSON()),
187
+ },
188
+ metadata: p.result.data.toJSON(),
189
+ },
190
+ };
191
+ };
192
+ }
193
+
194
+ const iterateVisited = (metadata: MetadataSchema): Set<string> => {
195
+ const names: Set<string> = new Set();
196
+ MetadataUtil.visit((m) => {
197
+ for (const alias of m.aliases) names.add(alias.type.name);
198
+ for (const array of m.arrays) names.add(array.type.name);
199
+ for (const tuple of m.tuples) names.add(tuple.type.name);
200
+ for (const object of m.objects) names.add(object.type.name);
201
+ })(metadata);
202
+ return names;
203
+ };
204
+
205
+ const join = ({
206
+ object,
207
+ key,
208
+ }: {
209
+ object: MetadataObjectType;
210
+ key: string | object | null;
211
+ }) => {
212
+ if (key === null) return object.name;
213
+ else if (typeof key === "object") return `${object.name}[key]`;
214
+ else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
215
+ return `${object.name}[${JSON.stringify(key)}]`;
216
+ };
217
+
218
+ const getReturnTypeNode = (node: ts.TypeNode): ts.TypeNode | null => {
219
+ if (ts.isTypeReferenceNode(node)) {
220
+ const typeName: string = node.typeName.getText();
221
+ if (typeName === "Promise") return node.typeArguments?.[0] ?? null;
222
+ }
223
+ return node;
224
+ };
225
+
226
+ const getReturnType = (p: {
227
+ checker: ts.TypeChecker;
228
+ signature: ts.Signature | undefined;
229
+ }): ts.Type | null => {
230
+ const type: ts.Type | null =
231
+ (p.signature && p.checker.getReturnTypeOfSignature(p.signature)) ?? null;
232
+ if (type === null) return null;
233
+ else if (type.symbol?.name === "Promise") {
234
+ const generic: readonly ts.Type[] = p.checker.getTypeArguments(
235
+ type as ts.TypeReference,
236
+ );
237
+ return generic[0] ?? null;
238
+ }
239
+ return type;
240
+ };