@nestia/sdk 7.1.1 → 7.2.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 (76) hide show
  1. package/lib/analyses/DtoAnalyzer.d.ts +21 -0
  2. package/lib/analyses/DtoAnalyzer.js +203 -0
  3. package/lib/analyses/DtoAnalyzer.js.map +1 -0
  4. package/lib/analyses/ImportAnalyzer.d.ts +3 -8
  5. package/lib/analyses/ImportAnalyzer.js +84 -102
  6. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  7. package/lib/analyses/ReflectHttpOperationAnalyzer.js +1 -1
  8. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  9. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +1 -1
  10. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  11. package/lib/generates/internal/E2eFileProgrammer.js +3 -9
  12. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  13. package/lib/generates/internal/ImportDictionary.d.ts +9 -11
  14. package/lib/generates/internal/ImportDictionary.js +55 -48
  15. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  16. package/lib/generates/internal/SdkAliasCollection.js +24 -18
  17. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  18. package/lib/generates/internal/SdkFileProgrammer.js +1 -7
  19. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  20. package/lib/generates/internal/SdkHttpCloneReferencer.js +3 -1
  21. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  22. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +4 -3
  23. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  24. package/lib/generates/internal/SdkImportWizard.js +28 -21
  25. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  26. package/lib/generates/internal/SdkTypeProgrammer.js +3 -2
  27. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkTypeTagProgrammer.js +10 -8
  29. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  30. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +8 -6
  31. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  32. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +12 -9
  33. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  34. package/lib/structures/IReflectHttpOperation.d.ts +2 -2
  35. package/lib/structures/IReflectImport.d.ts +6 -0
  36. package/lib/structures/{IReflectTypeImport.js → IReflectImport.js} +1 -1
  37. package/lib/structures/IReflectImport.js.map +1 -0
  38. package/lib/structures/IReflectWebSocketOperation.d.ts +2 -2
  39. package/lib/structures/IReflectWebSocketOperationParameter.d.ts +2 -2
  40. package/lib/structures/ITypedHttpRoute.d.ts +2 -2
  41. package/lib/structures/ITypedWebSocketRoute.d.ts +2 -2
  42. package/lib/transformers/IOperationMetadata.d.ts +3 -3
  43. package/lib/transformers/SdkOperationProgrammer.d.ts +3 -1
  44. package/lib/transformers/SdkOperationProgrammer.js +57 -26
  45. package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
  46. package/lib/transformers/SdkOperationTransformer.js +3 -3
  47. package/lib/transformers/SdkOperationTransformer.js.map +1 -1
  48. package/package.json +4 -4
  49. package/src/analyses/DtoAnalyzer.ts +246 -0
  50. package/src/analyses/ImportAnalyzer.ts +110 -155
  51. package/src/analyses/ReflectHttpOperationAnalyzer.ts +1 -1
  52. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +3 -3
  53. package/src/generates/internal/E2eFileProgrammer.ts +3 -11
  54. package/src/generates/internal/ImportDictionary.ts +111 -84
  55. package/src/generates/internal/SdkAliasCollection.ts +24 -18
  56. package/src/generates/internal/SdkFileProgrammer.ts +1 -7
  57. package/src/generates/internal/SdkHttpCloneReferencer.ts +3 -1
  58. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +4 -3
  59. package/src/generates/internal/SdkImportWizard.ts +28 -21
  60. package/src/generates/internal/SdkTypeProgrammer.ts +3 -2
  61. package/src/generates/internal/SdkTypeTagProgrammer.ts +10 -8
  62. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +8 -6
  63. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +12 -9
  64. package/src/structures/IReflectHttpOperation.ts +2 -2
  65. package/src/structures/IReflectHttpOperationParameter.ts +2 -6
  66. package/src/structures/IReflectImport.ts +6 -0
  67. package/src/structures/IReflectWebSocketOperation.ts +2 -2
  68. package/src/structures/IReflectWebSocketOperationParameter.ts +3 -5
  69. package/src/structures/ITypedHttpRoute.ts +2 -2
  70. package/src/structures/ITypedWebSocketRoute.ts +2 -2
  71. package/src/transformers/IOperationMetadata.ts +3 -3
  72. package/src/transformers/SdkOperationProgrammer.ts +60 -31
  73. package/src/transformers/SdkOperationTransformer.ts +7 -8
  74. package/lib/structures/IReflectTypeImport.d.ts +0 -4
  75. package/lib/structures/IReflectTypeImport.js.map +0 -1
  76. package/src/structures/IReflectTypeImport.ts +0 -4
@@ -1,7 +1,7 @@
1
1
  import { IJsDocTagInfo } from "typia";
2
2
 
3
3
  import { IReflectController } from "./IReflectController";
4
- import { IReflectTypeImport } from "./IReflectTypeImport";
4
+ import { IReflectImport } from "./IReflectImport";
5
5
  import { ITypedHttpRouteException } from "./ITypedHttpRouteException";
6
6
  import { ITypedHttpRouteParameter } from "./ITypedHttpRouteParameter";
7
7
  import { ITypedHttpRouteSuccess } from "./ITypedHttpRouteSuccess";
@@ -33,7 +33,7 @@ export interface ITypedHttpRoute {
33
33
  // ADDITIONAL INFORMATION
34
34
  security: Record<string, string[]>[];
35
35
  tags: string[];
36
- imports: IReflectTypeImport[];
36
+ imports: IReflectImport[];
37
37
  description: string | null;
38
38
  jsDocTags: IJsDocTagInfo[];
39
39
  operationId: string | undefined;
@@ -2,7 +2,7 @@ import { VERSION_NEUTRAL } from "@nestjs/common";
2
2
  import ts from "typescript";
3
3
 
4
4
  import { IReflectController } from "./IReflectController";
5
- import { IReflectTypeImport } from "./IReflectTypeImport";
5
+ import { IReflectImport } from "./IReflectImport";
6
6
  import { ITypedWebSocketRouteParameter } from "./ITypedWebSocketRouteParameter";
7
7
 
8
8
  export interface ITypedWebSocketRoute {
@@ -18,7 +18,7 @@ export interface ITypedWebSocketRoute {
18
18
  pathParameters: ITypedWebSocketRouteParameter.IParam[];
19
19
  query: ITypedWebSocketRouteParameter.IQuery | null;
20
20
  driver: ITypedWebSocketRouteParameter.IDriver | null;
21
- imports: IReflectTypeImport[];
21
+ imports: IReflectImport[];
22
22
  description: string | null;
23
23
  jsDocTags: ts.JSDocTagInfo[];
24
24
  }
@@ -3,8 +3,8 @@ import { IMetadata } from "typia/lib/schemas/metadata/IMetadata";
3
3
  import { IMetadataComponents } from "typia/lib/schemas/metadata/IMetadataComponents";
4
4
  import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
5
5
 
6
+ import { IReflectImport } from "../structures/IReflectImport";
6
7
  import { IReflectType } from "../structures/IReflectType";
7
- import { IReflectTypeImport } from "../structures/IReflectTypeImport";
8
8
 
9
9
  export interface IOperationMetadata {
10
10
  parameters: IOperationMetadata.IParameter[];
@@ -22,13 +22,13 @@ export namespace IOperationMetadata {
22
22
  }
23
23
  export interface IResponse {
24
24
  type: IReflectType | null;
25
- imports: IReflectTypeImport[];
25
+ imports: IReflectImport[];
26
26
  primitive: ValidationPipe<ISchema, IError>;
27
27
  resolved: ValidationPipe<ISchema, IError>;
28
28
  }
29
29
  export interface IException {
30
30
  type: IReflectType | null;
31
- imports: IReflectTypeImport[];
31
+ imports: IReflectImport[];
32
32
  primitive: ValidationPipe<ISchema, IError>;
33
33
  }
34
34
 
@@ -1,3 +1,4 @@
1
+ import { Singleton } from "tstl";
1
2
  import ts from "typescript";
2
3
  import { CommentFactory } from "typia/lib/factories/CommentFactory";
3
4
  import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
@@ -8,7 +9,8 @@ import { MetadataObjectType } from "typia/lib/schemas/metadata/MetadataObjectTyp
8
9
  import { ValidationPipe } from "typia/lib/typings/ValidationPipe";
9
10
  import { Escaper } from "typia/lib/utils/Escaper";
10
11
 
11
- import { ImportAnalyzer } from "../analyses/ImportAnalyzer";
12
+ import { DtoAnalyzer } from "../analyses/DtoAnalyzer";
13
+ import { IReflectImport } from "../structures/IReflectImport";
12
14
  import { MetadataUtil } from "../utils/MetadataUtil";
13
15
  import { IOperationMetadata } from "./IOperationMetadata";
14
16
  import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
@@ -16,7 +18,7 @@ import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerConte
16
18
  export namespace SdkOperationProgrammer {
17
19
  export interface IProps {
18
20
  context: ISdkOperationTransformerContext;
19
- generics: WeakMap<ts.Type, ts.Type>;
21
+ imports: Singleton<IReflectImport[]>;
20
22
  node: ts.MethodDeclaration;
21
23
  symbol: ts.Symbol | undefined;
22
24
  exceptions: ts.TypeNode[];
@@ -26,14 +28,15 @@ export namespace SdkOperationProgrammer {
26
28
  parameters: p.node.parameters.map((parameter, index) =>
27
29
  writeParameter({
28
30
  context: p.context,
29
- generics: p.generics,
31
+ imports: p.imports,
30
32
  parameter,
31
33
  index,
32
34
  }),
33
35
  ),
34
36
  success: writeResponse({
35
37
  context: p.context,
36
- generics: p.generics,
38
+ imports: p.imports,
39
+ typeNode: p.node.type ? getReturnTypeNode(p.node.type) : null,
37
40
  type: getReturnType({
38
41
  checker: p.context.checker,
39
42
  signature: p.context.checker.getSignatureFromDeclaration(p.node),
@@ -42,7 +45,8 @@ export namespace SdkOperationProgrammer {
42
45
  exceptions: p.exceptions.map((e) =>
43
46
  writeResponse({
44
47
  context: p.context,
45
- generics: p.generics,
48
+ imports: p.imports,
49
+ typeNode: e,
46
50
  type: p.context.checker.getTypeFromTypeNode(e),
47
51
  }),
48
52
  ),
@@ -55,7 +59,7 @@ export namespace SdkOperationProgrammer {
55
59
 
56
60
  const writeParameter = (props: {
57
61
  context: ISdkOperationTransformerContext;
58
- generics: WeakMap<ts.Type, ts.Type>;
62
+ imports: Singleton<IReflectImport[]>;
59
63
  parameter: ts.ParameterDeclaration;
60
64
  index: number;
61
65
  }): IOperationMetadata.IParameter => {
@@ -63,7 +67,8 @@ export namespace SdkOperationProgrammer {
63
67
  props.context.checker.getSymbolAtLocation(props.parameter);
64
68
  const common: IOperationMetadata.IResponse = writeResponse({
65
69
  context: props.context,
66
- generics: props.generics,
70
+ imports: props.imports,
71
+ typeNode: props.parameter.type ?? null,
67
72
  type:
68
73
  props.context.checker.getTypeFromTypeNode(
69
74
  props.parameter.type ?? TypeFactory.keyword("any"),
@@ -86,15 +91,26 @@ export namespace SdkOperationProgrammer {
86
91
 
87
92
  const writeResponse = (p: {
88
93
  context: ISdkOperationTransformerContext;
89
- generics: WeakMap<ts.Type, ts.Type>;
94
+ imports: Singleton<IReflectImport[]>;
95
+ typeNode: ts.TypeNode | null;
90
96
  type: ts.Type | null;
91
97
  }): IOperationMetadata.IResponse => {
92
- const analyzed: ImportAnalyzer.IOutput = p.type
93
- ? ImportAnalyzer.analyze(p.context.checker, p.generics, p.type)
94
- : {
95
- type: { name: "any" },
96
- imports: [],
97
- };
98
+ const analyzed: DtoAnalyzer.IOutput | null = p.typeNode
99
+ ? DtoAnalyzer.analyzeNode({
100
+ checker: p.context.checker,
101
+ imports: p.imports.get(),
102
+ typeNode: p.typeNode,
103
+ })
104
+ : p.type
105
+ ? DtoAnalyzer.analyzeType({
106
+ checker: p.context.checker,
107
+ imports: p.imports.get(),
108
+ type: p.type,
109
+ })
110
+ : {
111
+ type: { name: "any" },
112
+ imports: [],
113
+ };
98
114
  const [primitive, resolved] = [true, false].map((escape) =>
99
115
  MetadataFactory.analyze({
100
116
  checker: p.context.checker,
@@ -109,7 +125,12 @@ export namespace SdkOperationProgrammer {
109
125
  }),
110
126
  );
111
127
  return {
112
- ...analyzed,
128
+ ...(analyzed
129
+ ? analyzed
130
+ : {
131
+ imports: [],
132
+ type: null,
133
+ }),
113
134
  primitive: writeSchema({
114
135
  collection: p.context.collection,
115
136
  result: primitive,
@@ -166,22 +187,6 @@ export namespace SdkOperationProgrammer {
166
187
  },
167
188
  };
168
189
  };
169
-
170
- const getReturnType = (p: {
171
- checker: ts.TypeChecker;
172
- signature: ts.Signature | undefined;
173
- }): ts.Type | null => {
174
- const type: ts.Type | null =
175
- (p.signature && p.checker.getReturnTypeOfSignature(p.signature)) ?? null;
176
- if (type === null) return null;
177
- else if (type.symbol?.name === "Promise") {
178
- const generic: readonly ts.Type[] = p.checker.getTypeArguments(
179
- type as ts.TypeReference,
180
- );
181
- return generic[0] ?? null;
182
- }
183
- return type;
184
- };
185
190
  }
186
191
 
187
192
  const iterateVisited = (metadata: Metadata): Set<string> => {
@@ -207,3 +212,27 @@ const join = ({
207
212
  else if (Escaper.variable(key)) return `${object.name}.${key}`;
208
213
  return `${object.name}[${JSON.stringify(key)}]`;
209
214
  };
215
+
216
+ const getReturnTypeNode = (node: ts.TypeNode): ts.TypeNode | null => {
217
+ if (ts.isTypeReferenceNode(node)) {
218
+ const typeName: string = node.typeName.getText();
219
+ if (typeName === "Promise") return node.typeArguments?.[0] ?? null;
220
+ }
221
+ return node;
222
+ };
223
+
224
+ const getReturnType = (p: {
225
+ checker: ts.TypeChecker;
226
+ signature: ts.Signature | undefined;
227
+ }): ts.Type | null => {
228
+ const type: ts.Type | null =
229
+ (p.signature && p.checker.getReturnTypeOfSignature(p.signature)) ?? null;
230
+ if (type === null) return null;
231
+ else if (type.symbol?.name === "Promise") {
232
+ const generic: readonly ts.Type[] = p.checker.getTypeArguments(
233
+ type as ts.TypeReference,
234
+ );
235
+ return generic[0] ?? null;
236
+ }
237
+ return type;
238
+ };
@@ -5,7 +5,8 @@ import { LiteralFactory } from "typia/lib/factories/LiteralFactory";
5
5
  import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
6
6
  import { TypeFactory } from "typia/lib/factories/TypeFactory";
7
7
 
8
- import { GenericAnalyzer } from "../analyses/GenericAnalyzer";
8
+ import { ImportAnalyzer } from "../analyses/ImportAnalyzer";
9
+ import { IReflectImport } from "../structures/IReflectImport";
9
10
  import { IOperationMetadata } from "./IOperationMetadata";
10
11
  import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
11
12
  import { SdkOperationProgrammer } from "./SdkOperationProgrammer";
@@ -29,6 +30,7 @@ export namespace SdkOperationTransformer {
29
30
  (node) =>
30
31
  iterateNode({
31
32
  context,
33
+ imports: new Singleton(() => ImportAnalyzer.analyze(file)),
32
34
  visitor,
33
35
  node,
34
36
  }),
@@ -62,6 +64,7 @@ export namespace SdkOperationTransformer {
62
64
 
63
65
  const iterateNode = (props: {
64
66
  context: ISdkOperationTransformerContext;
67
+ imports: Singleton<IReflectImport[]>;
65
68
  visitor: IVisitor;
66
69
  node: ts.Node;
67
70
  }): ts.Node =>
@@ -77,6 +80,7 @@ export namespace SdkOperationTransformer {
77
80
 
78
81
  const transformNode = (props: {
79
82
  context: ISdkOperationTransformerContext;
83
+ imports: Singleton<IReflectImport[]>;
80
84
  visitor: IVisitor;
81
85
  node: ts.Node;
82
86
  }): ts.Node => {
@@ -91,13 +95,9 @@ export namespace SdkOperationTransformer {
91
95
  const transformClass = (props: {
92
96
  context: ISdkOperationTransformerContext;
93
97
  visitor: IVisitor;
98
+ imports: Singleton<IReflectImport[]>;
94
99
  node: ts.ClassDeclaration;
95
100
  }): ts.ClassDeclaration => {
96
- const generics: WeakMap<ts.Type, ts.Type> = GenericAnalyzer.analyze(
97
- props.context.checker,
98
- props.node,
99
- );
100
-
101
101
  // TO AVOID COMMENT COMPILATION BUG
102
102
  const symbolDict: Map<string, ts.Symbol> = new Map();
103
103
  const classType: ts.InterfaceType = props.context.checker.getTypeAtLocation(
@@ -121,7 +121,6 @@ export namespace SdkOperationTransformer {
121
121
  ts.isMethodDeclaration(m)
122
122
  ? transformMethod({
123
123
  ...props,
124
- generics,
125
124
  class: props.node,
126
125
  node: m,
127
126
  symbol: symbolDict.get(m.name.getText()),
@@ -134,8 +133,8 @@ export namespace SdkOperationTransformer {
134
133
  const transformMethod = (props: {
135
134
  context: ISdkOperationTransformerContext;
136
135
  visitor: IVisitor;
136
+ imports: Singleton<IReflectImport[]>;
137
137
  class: ts.ClassDeclaration;
138
- generics: WeakMap<ts.Type, ts.Type>;
139
138
  node: ts.MethodDeclaration;
140
139
  symbol: ts.Symbol | undefined;
141
140
  }): ts.MethodDeclaration => {
@@ -1,4 +0,0 @@
1
- export interface IReflectTypeImport {
2
- file: string;
3
- instances: string[];
4
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"IReflectTypeImport.js","sourceRoot":"","sources":["../../src/structures/IReflectTypeImport.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- export interface IReflectTypeImport {
2
- file: string;
3
- instances: string[];
4
- }