@nestia/sdk 10.0.2 → 11.0.0-dev.20260312
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.
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/assets/bundle/api/HttpError.ts +1 -1
- package/assets/bundle/api/IConnection.ts +1 -1
- package/assets/bundle/api/Primitive.ts +1 -1
- package/assets/bundle/api/Resolved.ts +1 -1
- package/assets/bundle/api/index.ts +4 -4
- package/assets/bundle/api/module.ts +6 -6
- package/assets/bundle/distribute/README.md +37 -37
- package/assets/bundle/distribute/package.json +28 -28
- package/assets/bundle/distribute/tsconfig.json +109 -109
- package/assets/bundle/e2e/index.ts +42 -42
- package/assets/config/nestia.config.ts +97 -97
- package/lib/INestiaConfig.d.ts +3 -3
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/NestiaSwaggerComposer.d.ts +3 -2
- package/lib/NestiaSwaggerComposer.js +5 -6
- package/lib/NestiaSwaggerComposer.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.js +2 -2
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/DtoAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +3 -3
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +4 -2
- package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +7 -11
- package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +6 -6
- package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +1 -1
- package/lib/analyses/TypedHttpRouteAnalyzer.js +6 -8
- package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaConfigLoader.js +111 -52
- package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/sdk.js +0 -0
- package/lib/generates/SwaggerGenerator.d.ts +1 -1
- package/lib/generates/SwaggerGenerator.js +11 -12
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.js +8 -9
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkAliasCollection.d.ts +2 -2
- package/lib/generates/internal/SdkAliasCollection.js +2 -2
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js +11 -12
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +13 -16
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpRouteProgrammer.js +4 -4
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js +12 -16
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkImportWizard.js +2 -2
- package/lib/generates/internal/SdkImportWizard.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +2 -3
- package/lib/generates/internal/SdkTypeProgrammer.js +6 -7
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +1 -1
- package/lib/generates/internal/SdkTypeTagProgrammer.js +11 -11
- package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +6 -8
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +2 -2
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationComposer.d.ts +3 -3
- package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
- package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -8
- package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
- package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +3 -3
- package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/structures/IReflectHttpOperationException.d.ts +3 -4
- package/lib/structures/IReflectHttpOperationParameter.d.ts +3 -5
- package/lib/structures/IReflectHttpOperationSuccess.d.ts +3 -4
- package/lib/structures/ITypedApplication.d.ts +1 -1
- package/lib/structures/ITypedHttpRouteException.d.ts +2 -2
- package/lib/structures/ITypedHttpRouteParameter.d.ts +2 -2
- package/lib/structures/ITypedHttpRouteSuccess.d.ts +2 -2
- package/lib/transformers/IOperationMetadata.d.ts +2 -4
- package/lib/transformers/ISdkOperationTransformerContext.d.ts +1 -1
- package/lib/transformers/SdkOperationProgrammer.js +8 -10
- package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
- package/lib/transformers/SdkOperationTransformer.js +6 -8
- package/lib/transformers/SdkOperationTransformer.js.map +1 -1
- package/lib/transformers/TextPlainValidator.d.ts +2 -2
- package/lib/transformers/TextPlainValidator.js.map +1 -1
- package/lib/utils/MetadataUtil.d.ts +2 -2
- package/lib/utils/MetadataUtil.js.map +1 -1
- package/lib/validators/HttpHeadersValidator.d.ts +2 -3
- package/lib/validators/HttpHeadersValidator.js +2 -2
- package/lib/validators/HttpHeadersValidator.js.map +1 -1
- package/lib/validators/HttpQueryValidator.d.ts +2 -3
- package/lib/validators/HttpQueryValidator.js +2 -2
- package/lib/validators/HttpQueryValidator.js.map +1 -1
- package/package.json +44 -30
- package/src/INestiaConfig.ts +267 -267
- package/src/NestiaSdkApplication.ts +307 -307
- package/src/NestiaSwaggerComposer.ts +143 -138
- package/src/analyses/AccessorAnalyzer.ts +67 -67
- package/src/analyses/DtoAnalyzer.ts +260 -260
- package/src/analyses/ImportAnalyzer.ts +126 -126
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
- package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -71
- package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -348
- package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -127
- package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -204
- package/src/executable/internal/NestiaConfigLoader.ts +85 -78
- package/src/executable/internal/NestiaSdkCommand.ts +107 -103
- package/src/generates/SwaggerGenerator.ts +291 -284
- package/src/generates/internal/E2eFileProgrammer.ts +196 -197
- package/src/generates/internal/FilePrinter.ts +64 -64
- package/src/generates/internal/ImportDictionary.ts +192 -192
- package/src/generates/internal/SdkAliasCollection.ts +260 -261
- package/src/generates/internal/SdkFileProgrammer.ts +110 -110
- package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -124
- package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
- package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -279
- package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -500
- package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -108
- package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -310
- package/src/generates/internal/SdkImportWizard.ts +62 -62
- package/src/generates/internal/SdkTypeProgrammer.ts +388 -385
- package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -104
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -381
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
- package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
- package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -162
- package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
- package/src/module.ts +4 -3
- package/src/structures/IReflectHttpOperationException.ts +18 -19
- package/src/structures/IReflectHttpOperationParameter.ts +79 -77
- package/src/structures/IReflectHttpOperationSuccess.ts +21 -22
- package/src/structures/ITypedApplication.ts +11 -11
- package/src/structures/ITypedHttpRouteException.ts +15 -15
- package/src/structures/ITypedHttpRouteParameter.ts +41 -41
- package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
- package/src/transformers/IOperationMetadata.ts +46 -44
- package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
- package/src/transformers/SdkOperationProgrammer.ts +240 -238
- package/src/transformers/SdkOperationTransformer.ts +248 -252
- package/src/transformers/TextPlainValidator.ts +17 -17
- package/src/utils/MetadataUtil.ts +26 -26
- package/src/validators/HttpHeadersValidator.ts +36 -34
- package/src/validators/HttpQueryValidator.ts +36 -34
|
@@ -1,252 +1,248 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
props.node,
|
|
116
|
-
props.node.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
props.node.
|
|
181
|
-
props.node.
|
|
182
|
-
props.node.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
public
|
|
224
|
-
return this.className
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
"
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
new MetadataCollection({
|
|
250
|
-
replace: MetadataCollection.replace,
|
|
251
|
-
}),
|
|
252
|
-
);
|
|
1
|
+
import { LiteralFactory, MetadataCollection, TypeFactory } from "@typia/core";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { HashSet, Singleton, hash } from "tstl";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
import { ImportAnalyzer } from "../analyses/ImportAnalyzer";
|
|
7
|
+
import { IReflectImport } from "../structures/IReflectImport";
|
|
8
|
+
import { IOperationMetadata } from "./IOperationMetadata";
|
|
9
|
+
import { ISdkOperationTransformerContext } from "./ISdkOperationTransformerContext";
|
|
10
|
+
import { SdkOperationProgrammer } from "./SdkOperationProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace SdkOperationTransformer {
|
|
13
|
+
export const iterateFile =
|
|
14
|
+
(checker: ts.TypeChecker) => (api: ts.TransformationContext) => {
|
|
15
|
+
const context: ISdkOperationTransformerContext = {
|
|
16
|
+
checker,
|
|
17
|
+
transformer: api,
|
|
18
|
+
collection: collection.get(),
|
|
19
|
+
};
|
|
20
|
+
return (file: ts.SourceFile): ts.SourceFile => {
|
|
21
|
+
if (file.isDeclarationFile === true) return file;
|
|
22
|
+
const visitor: IVisitor = {
|
|
23
|
+
done: false,
|
|
24
|
+
visited: new HashSet(),
|
|
25
|
+
};
|
|
26
|
+
file = ts.visitEachChild(
|
|
27
|
+
file,
|
|
28
|
+
(node) =>
|
|
29
|
+
iterateNode({
|
|
30
|
+
context,
|
|
31
|
+
imports: new Singleton(() => ImportAnalyzer.analyze(file)),
|
|
32
|
+
visitor,
|
|
33
|
+
node,
|
|
34
|
+
}),
|
|
35
|
+
api,
|
|
36
|
+
);
|
|
37
|
+
if (visitor.done === false) return file;
|
|
38
|
+
return ts.factory.updateSourceFile(file, [
|
|
39
|
+
ts.factory.createImportDeclaration(
|
|
40
|
+
undefined,
|
|
41
|
+
ts.factory.createImportClause(
|
|
42
|
+
false,
|
|
43
|
+
undefined,
|
|
44
|
+
ts.factory.createNamespaceImport(
|
|
45
|
+
ts.factory.createIdentifier("__OperationMetadata"),
|
|
46
|
+
),
|
|
47
|
+
),
|
|
48
|
+
ts.factory.createStringLiteral("@nestia/sdk"),
|
|
49
|
+
undefined,
|
|
50
|
+
),
|
|
51
|
+
...file.statements,
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
interface IVisitor {
|
|
57
|
+
done: boolean;
|
|
58
|
+
visited: HashSet<MethodKey>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const iterateNode = (props: {
|
|
62
|
+
context: ISdkOperationTransformerContext;
|
|
63
|
+
imports: Singleton<IReflectImport[]>;
|
|
64
|
+
visitor: IVisitor;
|
|
65
|
+
node: ts.Node;
|
|
66
|
+
}): ts.Node =>
|
|
67
|
+
ts.visitEachChild(
|
|
68
|
+
transformNode(props),
|
|
69
|
+
(child) =>
|
|
70
|
+
iterateNode({
|
|
71
|
+
...props,
|
|
72
|
+
node: child,
|
|
73
|
+
}),
|
|
74
|
+
props.context.transformer,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const transformNode = (props: {
|
|
78
|
+
context: ISdkOperationTransformerContext;
|
|
79
|
+
imports: Singleton<IReflectImport[]>;
|
|
80
|
+
visitor: IVisitor;
|
|
81
|
+
node: ts.Node;
|
|
82
|
+
}): ts.Node => {
|
|
83
|
+
return ts.isClassDeclaration(props.node)
|
|
84
|
+
? transformClass({
|
|
85
|
+
...props,
|
|
86
|
+
node: props.node,
|
|
87
|
+
})
|
|
88
|
+
: props.node;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const transformClass = (props: {
|
|
92
|
+
context: ISdkOperationTransformerContext;
|
|
93
|
+
visitor: IVisitor;
|
|
94
|
+
imports: Singleton<IReflectImport[]>;
|
|
95
|
+
node: ts.ClassDeclaration;
|
|
96
|
+
}): ts.ClassDeclaration => {
|
|
97
|
+
// TO AVOID COMMENT COMPILATION BUG
|
|
98
|
+
const symbolDict: Map<string, ts.Symbol> = new Map();
|
|
99
|
+
const classType: ts.InterfaceType = props.context.checker.getTypeAtLocation(
|
|
100
|
+
props.node,
|
|
101
|
+
) as ts.InterfaceType;
|
|
102
|
+
for (const symbol of classType.getProperties()) {
|
|
103
|
+
const declaration: ts.Declaration | undefined = (symbol.declarations ||
|
|
104
|
+
[])[0];
|
|
105
|
+
if (!declaration || !ts.isMethodDeclaration(declaration)) continue;
|
|
106
|
+
const identifier = declaration.name;
|
|
107
|
+
if (!ts.isIdentifier(identifier)) continue;
|
|
108
|
+
symbolDict.set(identifier.escapedText.toString(), symbol);
|
|
109
|
+
}
|
|
110
|
+
return ts.factory.updateClassDeclaration(
|
|
111
|
+
props.node,
|
|
112
|
+
props.node.modifiers,
|
|
113
|
+
props.node.name,
|
|
114
|
+
props.node.typeParameters,
|
|
115
|
+
props.node.heritageClauses,
|
|
116
|
+
props.node.members.map((m) =>
|
|
117
|
+
ts.isMethodDeclaration(m)
|
|
118
|
+
? transformMethod({
|
|
119
|
+
...props,
|
|
120
|
+
class: props.node,
|
|
121
|
+
node: m,
|
|
122
|
+
symbol: symbolDict.get(m.name.getText()),
|
|
123
|
+
})
|
|
124
|
+
: m,
|
|
125
|
+
),
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const transformMethod = (props: {
|
|
130
|
+
context: ISdkOperationTransformerContext;
|
|
131
|
+
visitor: IVisitor;
|
|
132
|
+
imports: Singleton<IReflectImport[]>;
|
|
133
|
+
class: ts.ClassDeclaration;
|
|
134
|
+
node: ts.MethodDeclaration;
|
|
135
|
+
symbol: ts.Symbol | undefined;
|
|
136
|
+
}): ts.MethodDeclaration => {
|
|
137
|
+
const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
|
|
138
|
+
? ts.getDecorators(props.node)
|
|
139
|
+
: (props.node as any).decorators;
|
|
140
|
+
if (!decorators?.length) return props.node;
|
|
141
|
+
|
|
142
|
+
const key: MethodKey = new MethodKey(
|
|
143
|
+
props.class.name?.getText() ?? "",
|
|
144
|
+
props.node.name.getText(),
|
|
145
|
+
);
|
|
146
|
+
props.visitor.done ||= true;
|
|
147
|
+
if (props.visitor.visited.has(key)) return props.node;
|
|
148
|
+
else props.visitor.visited.insert(key);
|
|
149
|
+
|
|
150
|
+
const metadata: IOperationMetadata = SdkOperationProgrammer.write({
|
|
151
|
+
...props,
|
|
152
|
+
exceptions: getExceptionTypes({
|
|
153
|
+
checker: props.context.checker,
|
|
154
|
+
decorators,
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
return ts.factory.updateMethodDeclaration(
|
|
158
|
+
props.node,
|
|
159
|
+
[
|
|
160
|
+
...(props.node.modifiers ?? []),
|
|
161
|
+
ts.factory.createDecorator(
|
|
162
|
+
ts.factory.createCallExpression(
|
|
163
|
+
ts.factory.createIdentifier(
|
|
164
|
+
"__OperationMetadata.OperationMetadata",
|
|
165
|
+
),
|
|
166
|
+
undefined,
|
|
167
|
+
[
|
|
168
|
+
ts.factory.createAsExpression(
|
|
169
|
+
LiteralFactory.write(metadata),
|
|
170
|
+
TypeFactory.keyword("any"),
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
],
|
|
176
|
+
props.node.asteriskToken,
|
|
177
|
+
props.node.name,
|
|
178
|
+
props.node.questionToken,
|
|
179
|
+
props.node.typeParameters,
|
|
180
|
+
props.node.parameters,
|
|
181
|
+
props.node.type,
|
|
182
|
+
props.node.body,
|
|
183
|
+
);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const getExceptionTypes = (props: {
|
|
187
|
+
checker: ts.TypeChecker;
|
|
188
|
+
decorators: readonly ts.Decorator[];
|
|
189
|
+
}) =>
|
|
190
|
+
props.decorators
|
|
191
|
+
.map((deco) => {
|
|
192
|
+
if (false === ts.isCallExpression(deco.expression)) return null;
|
|
193
|
+
|
|
194
|
+
const signature: ts.Signature | undefined =
|
|
195
|
+
props.checker.getResolvedSignature(deco.expression);
|
|
196
|
+
if (signature === undefined) return null;
|
|
197
|
+
else if (!signature.declaration) return null;
|
|
198
|
+
|
|
199
|
+
const location: string = path.resolve(
|
|
200
|
+
signature.declaration.getSourceFile()?.fileName ?? "",
|
|
201
|
+
);
|
|
202
|
+
if (
|
|
203
|
+
location.includes(TYPED_EXCEPTION_LIB_PATH) === false &&
|
|
204
|
+
location.includes(TYPED_EXCEPTION_MONO_PATH) === false
|
|
205
|
+
)
|
|
206
|
+
return null;
|
|
207
|
+
else if (deco.expression.typeArguments?.length !== 1) return null;
|
|
208
|
+
return deco.expression.typeArguments[0]!;
|
|
209
|
+
})
|
|
210
|
+
.filter((t) => t !== null);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
class MethodKey {
|
|
214
|
+
public constructor(
|
|
215
|
+
public readonly className: string,
|
|
216
|
+
public readonly methodName: string,
|
|
217
|
+
) {}
|
|
218
|
+
|
|
219
|
+
public equals(o: MethodKey): boolean {
|
|
220
|
+
return this.className === o.className && this.methodName === o.methodName;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public hashCode(): number {
|
|
224
|
+
return hash(this.className, this.methodName);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const TYPED_EXCEPTION_LIB_PATH = path.join(
|
|
229
|
+
"@nestia",
|
|
230
|
+
"core",
|
|
231
|
+
"lib",
|
|
232
|
+
"decorators",
|
|
233
|
+
`TypedException.d.ts`,
|
|
234
|
+
);
|
|
235
|
+
const TYPED_EXCEPTION_MONO_PATH = path.join(
|
|
236
|
+
"packages",
|
|
237
|
+
"core",
|
|
238
|
+
"src",
|
|
239
|
+
"decorators",
|
|
240
|
+
`TypedException.ts`,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const collection = new Singleton(
|
|
244
|
+
() =>
|
|
245
|
+
new MetadataCollection({
|
|
246
|
+
replace: MetadataCollection.replace,
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export namespace TextPlainValidator {
|
|
4
|
-
export const validate = (metadata:
|
|
5
|
-
const expected: number =
|
|
6
|
-
metadata.atomics.filter((a) => a.type === "string").length +
|
|
7
|
-
metadata.constants
|
|
8
|
-
.filter((c) => c.type === "string")
|
|
9
|
-
.map((c) => c.values.length)
|
|
10
|
-
.reduce((a, b) => a + b, 0) +
|
|
11
|
-
metadata.templates.length +
|
|
12
|
-
metadata.natives.filter((n) => n.name === "String").length;
|
|
13
|
-
if (metadata.size() === 0 || metadata.size() !== expected)
|
|
14
|
-
return [`Only string type is allowed in the "text/plain" content type.`];
|
|
15
|
-
return [];
|
|
16
|
-
};
|
|
17
|
-
}
|
|
1
|
+
import { MetadataSchema } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
export namespace TextPlainValidator {
|
|
4
|
+
export const validate = (metadata: MetadataSchema): string[] => {
|
|
5
|
+
const expected: number =
|
|
6
|
+
metadata.atomics.filter((a) => a.type === "string").length +
|
|
7
|
+
metadata.constants
|
|
8
|
+
.filter((c) => c.type === "string")
|
|
9
|
+
.map((c) => c.values.length)
|
|
10
|
+
.reduce((a, b) => a + b, 0) +
|
|
11
|
+
metadata.templates.length +
|
|
12
|
+
metadata.natives.filter((n) => n.name === "String").length;
|
|
13
|
+
if (metadata.size() === 0 || metadata.size() !== expected)
|
|
14
|
+
return [`Only string type is allowed in the "text/plain" content type.`];
|
|
15
|
+
return [];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export namespace MetadataUtil {
|
|
4
|
-
export const visit = (closure: (m:
|
|
5
|
-
const visited: WeakSet<
|
|
6
|
-
const iterate = (metadata:
|
|
7
|
-
if (visited.has(metadata)) return;
|
|
8
|
-
visited.add(metadata);
|
|
9
|
-
closure(metadata);
|
|
10
|
-
for (const alias of metadata.aliases) iterate(alias.type.value);
|
|
11
|
-
for (const array of metadata.arrays) iterate(array.type.value);
|
|
12
|
-
for (const tuple of metadata.tuples) tuple.type.elements.map(iterate);
|
|
13
|
-
for (const object of metadata.objects)
|
|
14
|
-
object.type.properties.forEach((p) => {
|
|
15
|
-
iterate(p.key);
|
|
16
|
-
iterate(p.value);
|
|
17
|
-
});
|
|
18
|
-
if (metadata.escaped) {
|
|
19
|
-
iterate(metadata.escaped.original);
|
|
20
|
-
iterate(metadata.escaped.returns);
|
|
21
|
-
}
|
|
22
|
-
if (metadata.rest) iterate(metadata.rest);
|
|
23
|
-
};
|
|
24
|
-
return iterate;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
1
|
+
import { MetadataSchema } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
export namespace MetadataUtil {
|
|
4
|
+
export const visit = (closure: (m: MetadataSchema) => unknown) => {
|
|
5
|
+
const visited: WeakSet<MetadataSchema> = new WeakSet();
|
|
6
|
+
const iterate = (metadata: MetadataSchema): void => {
|
|
7
|
+
if (visited.has(metadata)) return;
|
|
8
|
+
visited.add(metadata);
|
|
9
|
+
closure(metadata);
|
|
10
|
+
for (const alias of metadata.aliases) iterate(alias.type.value);
|
|
11
|
+
for (const array of metadata.arrays) iterate(array.type.value);
|
|
12
|
+
for (const tuple of metadata.tuples) tuple.type.elements.map(iterate);
|
|
13
|
+
for (const object of metadata.objects)
|
|
14
|
+
object.type.properties.forEach((p) => {
|
|
15
|
+
iterate(p.key);
|
|
16
|
+
iterate(p.value);
|
|
17
|
+
});
|
|
18
|
+
if (metadata.escaped) {
|
|
19
|
+
iterate(metadata.escaped.original);
|
|
20
|
+
iterate(metadata.escaped.returns);
|
|
21
|
+
}
|
|
22
|
+
if (metadata.rest) iterate(metadata.rest);
|
|
23
|
+
};
|
|
24
|
+
return iterate;
|
|
25
|
+
};
|
|
26
|
+
}
|