@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,204 +1,208 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (o.
|
|
28
|
-
|
|
29
|
-
for (const
|
|
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
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
.filter((p) => p.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.filter((p) => p.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
import {
|
|
2
|
+
IMetadataDictionary,
|
|
3
|
+
MetadataComponents,
|
|
4
|
+
MetadataFactory,
|
|
5
|
+
MetadataObjectType,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { NamingConvention } from "@typia/utils";
|
|
9
|
+
import { IMetadataComponents, IMetadataSchema } from "typia";
|
|
10
|
+
|
|
11
|
+
import { IReflectController } from "../structures/IReflectController";
|
|
12
|
+
import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
|
|
13
|
+
import { IReflectOperationError } from "../structures/IReflectOperationError";
|
|
14
|
+
import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
|
|
15
|
+
import { ITypedHttpRouteException } from "../structures/ITypedHttpRouteException";
|
|
16
|
+
import { ITypedHttpRouteParameter } from "../structures/ITypedHttpRouteParameter";
|
|
17
|
+
import { ITypedHttpRouteSuccess } from "../structures/ITypedHttpRouteSuccess";
|
|
18
|
+
import { PathUtil } from "../utils/PathUtil";
|
|
19
|
+
|
|
20
|
+
export namespace TypedHttpRouteAnalyzer {
|
|
21
|
+
export const dictionary = (
|
|
22
|
+
controllers: IReflectController[],
|
|
23
|
+
): IMetadataDictionary => {
|
|
24
|
+
const individual: IMetadataComponents[] = [];
|
|
25
|
+
for (const c of controllers)
|
|
26
|
+
for (const o of c.operations) {
|
|
27
|
+
if (o.protocol !== "http") continue;
|
|
28
|
+
if (o.success) individual.push(o.success.components);
|
|
29
|
+
for (const p of o.parameters) individual.push(p.components);
|
|
30
|
+
for (const e of Object.values(o.exceptions))
|
|
31
|
+
individual.push(e.components);
|
|
32
|
+
}
|
|
33
|
+
const components: MetadataComponents = MetadataComponents.from({
|
|
34
|
+
objects: Object.values(
|
|
35
|
+
Object.fromEntries(
|
|
36
|
+
individual.map((c) => c.objects.map((o) => [o.name, o])).flat(),
|
|
37
|
+
),
|
|
38
|
+
),
|
|
39
|
+
arrays: Object.values(
|
|
40
|
+
Object.fromEntries(
|
|
41
|
+
individual.map((c) => c.arrays.map((a) => [a.name, a])).flat(),
|
|
42
|
+
),
|
|
43
|
+
),
|
|
44
|
+
tuples: Object.values(
|
|
45
|
+
Object.fromEntries(
|
|
46
|
+
individual.map((c) => c.tuples.map((t) => [t.name, t])).flat(),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
aliases: Object.values(
|
|
50
|
+
Object.fromEntries(
|
|
51
|
+
individual.map((c) => c.aliases.map((a) => [a.name, a])).flat(),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
});
|
|
55
|
+
return components.dictionary;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const analyze = (props: {
|
|
59
|
+
controller: IReflectController;
|
|
60
|
+
errors: IReflectOperationError[];
|
|
61
|
+
dictionary: IMetadataDictionary;
|
|
62
|
+
operation: IReflectHttpOperation;
|
|
63
|
+
paths: string[];
|
|
64
|
+
}): ITypedHttpRoute[] => {
|
|
65
|
+
const errors: IReflectOperationError[] = [];
|
|
66
|
+
const cast = (
|
|
67
|
+
next: {
|
|
68
|
+
metadata: IMetadataSchema;
|
|
69
|
+
validate: MetadataFactory.Validator;
|
|
70
|
+
},
|
|
71
|
+
from: string,
|
|
72
|
+
escape: boolean,
|
|
73
|
+
): MetadataSchema => {
|
|
74
|
+
const metadata: MetadataSchema = MetadataSchema.from(
|
|
75
|
+
next.metadata,
|
|
76
|
+
props.dictionary,
|
|
77
|
+
);
|
|
78
|
+
const metaErrors: MetadataFactory.IError[] = MetadataFactory.validate({
|
|
79
|
+
options: {
|
|
80
|
+
escape,
|
|
81
|
+
constant: true,
|
|
82
|
+
absorb: true,
|
|
83
|
+
validate: next.validate, // @todo -> CHECK IN TYPIA
|
|
84
|
+
},
|
|
85
|
+
functor: next.validate, // @todo -> CHECK IN TYPIA
|
|
86
|
+
metadata,
|
|
87
|
+
});
|
|
88
|
+
if (metaErrors.length)
|
|
89
|
+
errors.push({
|
|
90
|
+
file: props.controller.file,
|
|
91
|
+
class: props.controller.class.name,
|
|
92
|
+
function: props.operation.name,
|
|
93
|
+
from,
|
|
94
|
+
contents: metaErrors.map((e) => ({
|
|
95
|
+
name: e.name,
|
|
96
|
+
accessor:
|
|
97
|
+
e.explore.object !== null
|
|
98
|
+
? join({
|
|
99
|
+
object: e.explore.object,
|
|
100
|
+
key: e.explore.property,
|
|
101
|
+
})
|
|
102
|
+
: null,
|
|
103
|
+
messages: e.messages,
|
|
104
|
+
})),
|
|
105
|
+
});
|
|
106
|
+
return metadata;
|
|
107
|
+
};
|
|
108
|
+
const exceptions: Record<
|
|
109
|
+
number | "2XX" | "3XX" | "4XX" | "5XX",
|
|
110
|
+
ITypedHttpRouteException
|
|
111
|
+
> = Object.fromEntries(
|
|
112
|
+
Object.entries(props.operation.exceptions).map(([key, value]) => [
|
|
113
|
+
key as any,
|
|
114
|
+
{
|
|
115
|
+
status: value.status,
|
|
116
|
+
description: value.description,
|
|
117
|
+
example: value.example,
|
|
118
|
+
examples: value.examples,
|
|
119
|
+
type: value.type,
|
|
120
|
+
metadata: cast(value, `exception (status: ${key})`, true),
|
|
121
|
+
},
|
|
122
|
+
]),
|
|
123
|
+
);
|
|
124
|
+
const parameters: ITypedHttpRouteParameter[] =
|
|
125
|
+
props.operation.parameters.map((p) => ({
|
|
126
|
+
...p,
|
|
127
|
+
metadata: cast(
|
|
128
|
+
p,
|
|
129
|
+
`parameter (name: ${JSON.stringify(p.name)})`,
|
|
130
|
+
p.category === "body" &&
|
|
131
|
+
(p.contentType === "application/json" || p.encrypted === true),
|
|
132
|
+
),
|
|
133
|
+
}));
|
|
134
|
+
const success: ITypedHttpRouteSuccess = {
|
|
135
|
+
...props.operation.success,
|
|
136
|
+
metadata: cast(
|
|
137
|
+
props.operation.success,
|
|
138
|
+
"success",
|
|
139
|
+
props.operation.success.encrypted ||
|
|
140
|
+
props.operation.success.contentType === "application/json",
|
|
141
|
+
),
|
|
142
|
+
setHeaders: props.operation.jsDocTags
|
|
143
|
+
.filter(
|
|
144
|
+
(t) =>
|
|
145
|
+
t.text?.length &&
|
|
146
|
+
t.text[0]!.text &&
|
|
147
|
+
(t.name === "setHeader" || t.name === "assignHeaders"),
|
|
148
|
+
)
|
|
149
|
+
.map((t) =>
|
|
150
|
+
t.name === "setHeader"
|
|
151
|
+
? {
|
|
152
|
+
type: "setter",
|
|
153
|
+
source: t.text![0]!.text.split(" ")[0]!.trim(),
|
|
154
|
+
target: t.text![0]!.text.split(" ")[1]?.trim(),
|
|
155
|
+
}
|
|
156
|
+
: {
|
|
157
|
+
type: "assigner",
|
|
158
|
+
source: t.text![0]!.text,
|
|
159
|
+
},
|
|
160
|
+
),
|
|
161
|
+
};
|
|
162
|
+
if (errors.length) {
|
|
163
|
+
props.errors.push(...errors);
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
return props.paths.map(
|
|
167
|
+
(path) =>
|
|
168
|
+
({
|
|
169
|
+
...props.operation,
|
|
170
|
+
controller: props.controller,
|
|
171
|
+
path,
|
|
172
|
+
accessor: [...PathUtil.accessors(path), props.operation.name],
|
|
173
|
+
exceptions,
|
|
174
|
+
pathParameters: parameters.filter((p) => p.category === "param"),
|
|
175
|
+
queryParameters: parameters
|
|
176
|
+
.filter((p) => p.category === "query")
|
|
177
|
+
.filter((p) => p.field !== null),
|
|
178
|
+
headerParameters: parameters
|
|
179
|
+
.filter((p) => p.category === "headers")
|
|
180
|
+
.filter((p) => p.field !== null),
|
|
181
|
+
queryObject:
|
|
182
|
+
parameters
|
|
183
|
+
.filter((p) => p.category === "query")
|
|
184
|
+
.filter((p) => p.field === null)[0] ?? null,
|
|
185
|
+
body: parameters.filter((p) => p.category === "body")[0] ?? null,
|
|
186
|
+
headerObject:
|
|
187
|
+
parameters
|
|
188
|
+
.filter((p) => p.category === "headers")
|
|
189
|
+
.filter((p) => p.field === null)[0] ?? null,
|
|
190
|
+
success,
|
|
191
|
+
extensions: props.operation.extensions,
|
|
192
|
+
}) satisfies ITypedHttpRoute,
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const join = ({
|
|
198
|
+
object,
|
|
199
|
+
key,
|
|
200
|
+
}: {
|
|
201
|
+
object: MetadataObjectType;
|
|
202
|
+
key: string | object | null;
|
|
203
|
+
}) => {
|
|
204
|
+
if (key === null) return object.name;
|
|
205
|
+
else if (typeof key === "object") return `${object.name}[key]`;
|
|
206
|
+
else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
|
|
207
|
+
return `${object.name}[${JSON.stringify(key)}]`;
|
|
208
|
+
};
|
|
@@ -1,78 +1,85 @@
|
|
|
1
|
-
import { NoTransformConfigurationError } from "@nestia/core
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { register } from "ts-node";
|
|
5
|
-
import { parse } from "tsconfck";
|
|
6
|
-
import ts from "typescript";
|
|
7
|
-
import typia from "typia";
|
|
8
|
-
|
|
9
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
10
|
-
|
|
11
|
-
export namespace NestiaConfigLoader {
|
|
12
|
-
export const compilerOptions = async (
|
|
13
|
-
project: string,
|
|
14
|
-
): Promise<ts.ParsedCommandLine> => {
|
|
15
|
-
const configFileName = ts.findConfigFile(
|
|
16
|
-
process.cwd(),
|
|
17
|
-
ts.sys.fileExists,
|
|
18
|
-
project,
|
|
19
|
-
);
|
|
20
|
-
if (!configFileName) throw new Error(`unable to find "${project}" file.`);
|
|
21
|
-
const { tsconfig } = await parse(configFileName);
|
|
22
|
-
const configFileText = JSON.stringify(tsconfig);
|
|
23
|
-
const { config } = ts.parseConfigFileTextToJson(
|
|
24
|
-
configFileName,
|
|
25
|
-
configFileText,
|
|
26
|
-
);
|
|
27
|
-
return ts.parseJsonConfigFileContent(
|
|
28
|
-
config,
|
|
29
|
-
ts.sys,
|
|
30
|
-
path.dirname(configFileName),
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const configurations = async (
|
|
35
|
-
file: string,
|
|
36
|
-
compilerOptions: Record<string, any>,
|
|
37
|
-
): Promise<INestiaConfig[]> => {
|
|
38
|
-
if (fs.existsSync(path.resolve(file)) === false)
|
|
39
|
-
throw new Error(`Unable to find "${file}" file.`);
|
|
40
|
-
|
|
41
|
-
NoTransformConfigurationError.throws = false;
|
|
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
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import { NoTransformConfigurationError } from "@nestia/core";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { register } from "ts-node";
|
|
5
|
+
import { parse } from "tsconfck";
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import typia from "typia";
|
|
8
|
+
|
|
9
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
10
|
+
|
|
11
|
+
export namespace NestiaConfigLoader {
|
|
12
|
+
export const compilerOptions = async (
|
|
13
|
+
project: string,
|
|
14
|
+
): Promise<ts.ParsedCommandLine> => {
|
|
15
|
+
const configFileName = ts.findConfigFile(
|
|
16
|
+
process.cwd(),
|
|
17
|
+
ts.sys.fileExists,
|
|
18
|
+
project,
|
|
19
|
+
);
|
|
20
|
+
if (!configFileName) throw new Error(`unable to find "${project}" file.`);
|
|
21
|
+
const { tsconfig } = await parse(configFileName);
|
|
22
|
+
const configFileText = JSON.stringify(tsconfig);
|
|
23
|
+
const { config } = ts.parseConfigFileTextToJson(
|
|
24
|
+
configFileName,
|
|
25
|
+
configFileText,
|
|
26
|
+
);
|
|
27
|
+
return ts.parseJsonConfigFileContent(
|
|
28
|
+
config,
|
|
29
|
+
ts.sys,
|
|
30
|
+
path.dirname(configFileName),
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const configurations = async (
|
|
35
|
+
file: string,
|
|
36
|
+
compilerOptions: Record<string, any>,
|
|
37
|
+
): Promise<INestiaConfig[]> => {
|
|
38
|
+
if (fs.existsSync(path.resolve(file)) === false)
|
|
39
|
+
throw new Error(`Unable to find "${file}" file.`);
|
|
40
|
+
|
|
41
|
+
NoTransformConfigurationError.throws = false;
|
|
42
|
+
|
|
43
|
+
const setup: boolean = typia
|
|
44
|
+
.assert<object[]>(compilerOptions.plugins ?? [])
|
|
45
|
+
.some(
|
|
46
|
+
(x: any) =>
|
|
47
|
+
x.transform === "@nestia/sdk/lib/transform" ||
|
|
48
|
+
x.transform === "@nestia/sdk/src/transform.ts",
|
|
49
|
+
);
|
|
50
|
+
const plugins: any[] = [
|
|
51
|
+
...(compilerOptions.plugins ?? []),
|
|
52
|
+
...(setup ? [{ transform: "@nestia/sdk/lib/transform" }] : []),
|
|
53
|
+
];
|
|
54
|
+
if (!(process as any)[Symbol.for("ts-node.register.instance")])
|
|
55
|
+
register({
|
|
56
|
+
emit: false,
|
|
57
|
+
compilerOptions: {
|
|
58
|
+
...compilerOptions,
|
|
59
|
+
plugins,
|
|
60
|
+
},
|
|
61
|
+
require: compilerOptions.baseUrl
|
|
62
|
+
? ["tsconfig-paths/register"]
|
|
63
|
+
: undefined,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const loaded: (INestiaConfig | INestiaConfig[]) & {
|
|
67
|
+
default?: INestiaConfig | INestiaConfig[];
|
|
68
|
+
} = await import(path.resolve(file));
|
|
69
|
+
const instance: INestiaConfig | INestiaConfig[] =
|
|
70
|
+
typeof loaded?.default === "object" && loaded.default !== null
|
|
71
|
+
? loaded.default
|
|
72
|
+
: loaded;
|
|
73
|
+
const configurations: INestiaConfig[] = Array.isArray(instance)
|
|
74
|
+
? instance
|
|
75
|
+
: [instance];
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
return typia.assert(configurations);
|
|
79
|
+
} catch (exp) {
|
|
80
|
+
if (typia.is<typia.TypeGuardError>(exp))
|
|
81
|
+
exp.message = `invalid "${file}" data.`;
|
|
82
|
+
throw exp;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|