@nestia/sdk 3.0.5-dev.20240418 → 3.1.0-dev.20240426
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/lib/NestiaSdkApplication.d.ts +1 -0
- package/lib/NestiaSdkApplication.js +17 -17
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/AccessorAnalyzer.d.ts +3 -2
- package/lib/analyses/AccessorAnalyzer.js.map +1 -1
- package/lib/analyses/ExceptionAnalyzer.d.ts +11 -3
- package/lib/analyses/ExceptionAnalyzer.js +23 -18
- package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
- package/lib/analyses/GenericAnalyzer.d.ts +1 -0
- package/lib/analyses/ImportAnalyzer.d.ts +6 -1
- package/lib/analyses/ImportAnalyzer.js +27 -29
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/PathAnalyzer.d.ts +0 -5
- package/lib/analyses/PathAnalyzer.js +0 -32
- package/lib/analyses/PathAnalyzer.js.map +1 -1
- package/lib/analyses/{ReflectAnalyzer.d.ts → ReflectControllerAnalyzer.d.ts} +3 -4
- package/lib/analyses/ReflectControllerAnalyzer.js +145 -0
- package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js +224 -0
- package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectMetadataAnalyzer.d.ts +8 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js +34 -0
- package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +10 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +78 -0
- package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/analyses/SecurityAnalyzer.js +1 -1
- package/lib/analyses/SecurityAnalyzer.js.map +1 -1
- package/lib/analyses/TypedControllerAnalyzer.d.ts +9 -0
- package/lib/analyses/TypedControllerAnalyzer.js +77 -0
- package/lib/analyses/TypedControllerAnalyzer.js.map +1 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js +251 -0
- package/lib/analyses/TypedHttpOperationAnalyzer.js.map +1 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.d.ts +16 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js +218 -0
- package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -0
- package/lib/executable/internal/NestiaConfigLoader.d.ts +1 -0
- package/lib/generates/CloneGenerator.d.ts +3 -4
- package/lib/generates/CloneGenerator.js +8 -8
- package/lib/generates/CloneGenerator.js.map +1 -1
- package/lib/generates/E2eGenerator.d.ts +3 -4
- package/lib/generates/E2eGenerator.js +7 -7
- package/lib/generates/E2eGenerator.js.map +1 -1
- package/lib/generates/SdkGenerator.d.ts +4 -4
- package/lib/generates/SdkGenerator.js +8 -8
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +5 -2
- package/lib/generates/SwaggerGenerator.js +15 -13
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +4 -5
- package/lib/generates/internal/E2eFileProgrammer.js +13 -12
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
- package/lib/generates/internal/FilePrinter.d.ts +1 -0
- package/lib/generates/internal/ImportDictionary.d.ts +1 -0
- package/lib/generates/internal/SdkAliasCollection.d.ts +9 -8
- package/lib/generates/internal/SdkAliasCollection.js +20 -20
- package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
- package/lib/generates/internal/SdkDistributionComposer.d.ts +1 -1
- package/lib/generates/internal/SdkDistributionComposer.js +36 -2
- package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
- package/lib/generates/internal/SdkFileProgrammer.d.ts +4 -4
- package/lib/generates/internal/SdkFileProgrammer.js +10 -7
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkCloneProgrammer.js → SdkHttpCloneProgrammer.js} +14 -14
- package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkFunctionProgrammer.js → SdkHttpFunctionProgrammer.js} +12 -12
- package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +12 -0
- package/lib/generates/internal/{SdkNamespaceProgrammer.js → SdkHttpNamespaceProgrammer.js} +26 -26
- package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/{SdkRouteProgrammer.js → SdkHttpRouteProgrammer.js} +11 -11
- package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +13 -0
- package/lib/generates/internal/{SdkSimulationProgrammer.js → SdkHttpSimulationProgrammer.js} +18 -18
- package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +3 -2
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
- package/lib/generates/internal/SdkTypeProgrammer.d.ts +4 -3
- package/lib/generates/internal/SdkTypeProgrammer.js +33 -33
- package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +115 -0
- package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +8 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +79 -0
- package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -0
- package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +6 -5
- package/lib/generates/internal/SwaggerSchemaGenerator.js +3 -1
- package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
- package/lib/structures/INestiaProject.d.ts +1 -0
- package/lib/structures/IReflectController.d.ts +15 -0
- package/lib/structures/{IRoute.js → IReflectController.js} +1 -1
- package/lib/structures/IReflectController.js.map +1 -0
- package/lib/structures/{IController.d.ts → IReflectHttpOperation.d.ts} +15 -25
- package/lib/structures/IReflectHttpOperation.js +3 -0
- package/lib/structures/IReflectHttpOperation.js.map +1 -0
- package/lib/structures/IReflectWebSocketOperation.d.ts +16 -0
- package/lib/structures/IReflectWebSocketOperation.js +3 -0
- package/lib/structures/IReflectWebSocketOperation.js.map +1 -0
- package/lib/structures/ISwaggerError.d.ts +2 -2
- package/lib/structures/ITypeTuple.d.ts +1 -0
- package/lib/structures/{IRoute.d.ts → ITypedHttpRoute.d.ts} +12 -12
- package/lib/structures/{IController.js → ITypedHttpRoute.js} +1 -1
- package/lib/structures/ITypedHttpRoute.js.map +1 -0
- package/lib/structures/ITypedWebSocketRoute.d.ts +54 -0
- package/lib/structures/ITypedWebSocketRoute.js +3 -0
- package/lib/structures/ITypedWebSocketRoute.js.map +1 -0
- package/lib/structures/TypeEntry.d.ts +1 -0
- package/lib/utils/VersioningStrategy.d.ts +6 -0
- package/lib/utils/VersioningStrategy.js +22 -0
- package/lib/utils/VersioningStrategy.js.map +1 -0
- package/package.json +9 -7
- package/src/NestiaSdkApplication.ts +36 -34
- package/src/analyses/AccessorAnalyzer.ts +12 -5
- package/src/analyses/ExceptionAnalyzer.ts +49 -39
- package/src/analyses/ImportAnalyzer.ts +123 -104
- package/src/analyses/PathAnalyzer.ts +0 -41
- package/src/analyses/ReflectControllerAnalyzer.ts +155 -0
- package/src/analyses/ReflectHttpOperationAnalyzer.ts +290 -0
- package/src/analyses/ReflectMetadataAnalyzer.ts +53 -0
- package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +96 -0
- package/src/analyses/SecurityAnalyzer.ts +2 -1
- package/src/analyses/TypedControllerAnalyzer.ts +92 -0
- package/src/analyses/TypedHttpOperationAnalyzer.ts +352 -0
- package/src/analyses/TypedWebSocketOperationAnalyzer.ts +368 -0
- package/src/generates/CloneGenerator.ts +17 -15
- package/src/generates/E2eGenerator.ts +10 -12
- package/src/generates/SdkGenerator.ts +19 -12
- package/src/generates/SwaggerGenerator.ts +31 -21
- package/src/generates/internal/E2eFileProgrammer.ts +20 -24
- package/src/generates/internal/SdkAliasCollection.ts +38 -33
- package/src/generates/internal/SdkDistributionComposer.ts +13 -4
- package/src/generates/internal/SdkFileProgrammer.ts +17 -13
- package/src/generates/internal/{SdkCloneProgrammer.ts → SdkHttpCloneProgrammer.ts} +14 -15
- package/src/generates/internal/{SdkFunctionProgrammer.ts → SdkHttpFunctionProgrammer.ts} +24 -23
- package/src/generates/internal/{SdkNamespaceProgrammer.ts → SdkHttpNamespaceProgrammer.ts} +44 -49
- package/src/generates/internal/{SdkRouteProgrammer.ts → SdkHttpRouteProgrammer.ts} +12 -13
- package/src/generates/internal/{SdkSimulationProgrammer.ts → SdkHttpSimulationProgrammer.ts} +23 -25
- package/src/generates/internal/SdkRouteDirectory.ts +3 -2
- package/src/generates/internal/SdkTypeProgrammer.ts +43 -37
- package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +378 -0
- package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +248 -0
- package/src/generates/internal/SwaggerSchemaGenerator.ts +26 -21
- package/src/structures/IReflectController.ts +17 -0
- package/src/structures/{IController.ts → IReflectHttpOperation.ts} +78 -94
- package/src/structures/IReflectWebSocketOperation.ts +17 -0
- package/src/structures/ISwaggerError.ts +2 -2
- package/src/structures/{IRoute.ts → ITypedHttpRoute.ts} +14 -12
- package/src/structures/ITypedWebSocketRoute.ts +67 -0
- package/src/utils/VersioningStrategy.ts +28 -0
- package/lib/analyses/ControllerAnalyzer.d.ts +0 -7
- package/lib/analyses/ControllerAnalyzer.js +0 -269
- package/lib/analyses/ControllerAnalyzer.js.map +0 -1
- package/lib/analyses/ReflectAnalyzer.js +0 -377
- package/lib/analyses/ReflectAnalyzer.js.map +0 -1
- package/lib/generates/internal/SdkCloneProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkCloneProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +0 -11
- package/lib/generates/internal/SdkNamespaceProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkRouteProgrammer.d.ts +0 -7
- package/lib/generates/internal/SdkRouteProgrammer.js.map +0 -1
- package/lib/generates/internal/SdkSimulationProgrammer.d.ts +0 -12
- package/lib/generates/internal/SdkSimulationProgrammer.js.map +0 -1
- package/lib/structures/IController.js.map +0 -1
- package/lib/structures/IRoute.js.map +0 -1
- package/src/analyses/ControllerAnalyzer.ts +0 -402
- package/src/analyses/ReflectAnalyzer.ts +0 -471
|
@@ -7,23 +7,23 @@ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
|
|
|
7
7
|
import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
|
|
8
8
|
import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
|
|
9
9
|
import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
|
|
10
|
+
import { MetadataConstantValue } from "typia/lib/schemas/metadata/MetadataConstantValue";
|
|
10
11
|
import { MetadataEscaped } from "typia/lib/schemas/metadata/MetadataEscaped";
|
|
11
12
|
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
12
13
|
import { MetadataProperty } from "typia/lib/schemas/metadata/MetadataProperty";
|
|
13
14
|
import { MetadataTuple } from "typia/lib/schemas/metadata/MetadataTuple";
|
|
14
15
|
import { Escaper } from "typia/lib/utils/Escaper";
|
|
15
16
|
|
|
16
|
-
import {
|
|
17
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
17
18
|
import { FilePrinter } from "./FilePrinter";
|
|
18
19
|
import { ImportDictionary } from "./ImportDictionary";
|
|
19
|
-
import { MetadataConstantValue } from "typia/lib/schemas/metadata/MetadataConstantValue";
|
|
20
20
|
|
|
21
21
|
export namespace SdkTypeProgrammer {
|
|
22
22
|
/* -----------------------------------------------------------
|
|
23
23
|
FACADE
|
|
24
24
|
----------------------------------------------------------- */
|
|
25
25
|
export const write =
|
|
26
|
-
(
|
|
26
|
+
(project: INestiaProject) =>
|
|
27
27
|
(importer: ImportDictionary) =>
|
|
28
28
|
(meta: Metadata, parentEscaped: boolean = false): ts.TypeNode => {
|
|
29
29
|
const union: ts.TypeNode[] = [];
|
|
@@ -33,20 +33,20 @@ export namespace SdkTypeProgrammer {
|
|
|
33
33
|
if (meta.nullable) union.push(writeNode("null"));
|
|
34
34
|
if (meta.isRequired() === false) union.push(writeNode("undefined"));
|
|
35
35
|
if (parentEscaped === false && meta.escaped)
|
|
36
|
-
union.push(write_escaped(
|
|
36
|
+
union.push(write_escaped(project)(importer)(meta.escaped));
|
|
37
37
|
|
|
38
38
|
// ATOMIC TYPES
|
|
39
39
|
for (const c of meta.constants)
|
|
40
40
|
for (const value of c.values) union.push(write_constant(value));
|
|
41
41
|
for (const tpl of meta.templates)
|
|
42
|
-
union.push(write_template(
|
|
42
|
+
union.push(write_template(project)(importer)(tpl));
|
|
43
43
|
for (const atom of meta.atomics) union.push(write_atomic(importer)(atom));
|
|
44
44
|
|
|
45
45
|
// OBJECT TYPES
|
|
46
46
|
for (const tuple of meta.tuples)
|
|
47
|
-
union.push(write_tuple(
|
|
47
|
+
union.push(write_tuple(project)(importer)(tuple));
|
|
48
48
|
for (const array of meta.arrays)
|
|
49
|
-
union.push(write_array(
|
|
49
|
+
union.push(write_array(project)(importer)(array));
|
|
50
50
|
for (const object of meta.objects)
|
|
51
51
|
if (
|
|
52
52
|
object.name === "object" ||
|
|
@@ -55,10 +55,10 @@ export namespace SdkTypeProgrammer {
|
|
|
55
55
|
object.name === "__object" ||
|
|
56
56
|
object.name.startsWith("__object.")
|
|
57
57
|
)
|
|
58
|
-
union.push(write_object(
|
|
59
|
-
else union.push(write_alias(
|
|
58
|
+
union.push(write_object(project)(importer)(object));
|
|
59
|
+
else union.push(write_alias(project)(importer)(object));
|
|
60
60
|
for (const alias of meta.aliases)
|
|
61
|
-
union.push(write_alias(
|
|
61
|
+
union.push(write_alias(project)(importer)(alias));
|
|
62
62
|
for (const native of meta.natives)
|
|
63
63
|
if (native === "Blob" || native === "File")
|
|
64
64
|
union.push(write_native(native));
|
|
@@ -69,7 +69,7 @@ export namespace SdkTypeProgrammer {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
export const write_object =
|
|
72
|
-
(
|
|
72
|
+
(project: INestiaProject) =>
|
|
73
73
|
(importer: ImportDictionary) =>
|
|
74
74
|
(object: MetadataObject): ts.TypeNode => {
|
|
75
75
|
const regular = object.properties.filter((p) => p.key.isSoleLiteral());
|
|
@@ -77,20 +77,20 @@ export namespace SdkTypeProgrammer {
|
|
|
77
77
|
return FilePrinter.description(
|
|
78
78
|
regular.length && dynamic.length
|
|
79
79
|
? ts.factory.createIntersectionTypeNode([
|
|
80
|
-
write_regular_property(
|
|
81
|
-
...dynamic.map(write_dynamic_property(
|
|
80
|
+
write_regular_property(project)(importer)(regular),
|
|
81
|
+
...dynamic.map(write_dynamic_property(project)(importer)),
|
|
82
82
|
])
|
|
83
83
|
: dynamic.length
|
|
84
84
|
? ts.factory.createIntersectionTypeNode(
|
|
85
|
-
dynamic.map(write_dynamic_property(
|
|
85
|
+
dynamic.map(write_dynamic_property(project)(importer)),
|
|
86
86
|
)
|
|
87
|
-
: write_regular_property(
|
|
87
|
+
: write_regular_property(project)(importer)(regular),
|
|
88
88
|
writeComment([])(object.description ?? null, object.jsDocTags),
|
|
89
89
|
);
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
const write_escaped =
|
|
93
|
-
(
|
|
93
|
+
(project: INestiaProject) =>
|
|
94
94
|
(importer: ImportDictionary) =>
|
|
95
95
|
(meta: MetadataEscaped): ts.TypeNode => {
|
|
96
96
|
if (
|
|
@@ -105,7 +105,7 @@ export namespace SdkTypeProgrammer {
|
|
|
105
105
|
value: "date-time",
|
|
106
106
|
} as IMetadataTypeTag),
|
|
107
107
|
]);
|
|
108
|
-
return write(
|
|
108
|
+
return write(project)(importer)(meta.returns, true);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
/* -----------------------------------------------------------
|
|
@@ -133,7 +133,7 @@ export namespace SdkTypeProgrammer {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
const write_template =
|
|
136
|
-
(
|
|
136
|
+
(project: INestiaProject) =>
|
|
137
137
|
(importer: ImportDictionary) =>
|
|
138
138
|
(meta: Metadata[]): ts.TypeNode => {
|
|
139
139
|
const head: boolean = meta[0].isSoleLiteral();
|
|
@@ -147,7 +147,8 @@ export namespace SdkTypeProgrammer {
|
|
|
147
147
|
return tuple;
|
|
148
148
|
})();
|
|
149
149
|
if (elem.isSoleLiteral())
|
|
150
|
-
if (last[1] === null)
|
|
150
|
+
if (last[1] === null)
|
|
151
|
+
last[1] = String(elem.constants[0].values[0].value);
|
|
151
152
|
else
|
|
152
153
|
spans.push([
|
|
153
154
|
ts.factory.createLiteralTypeNode(
|
|
@@ -157,8 +158,8 @@ export namespace SdkTypeProgrammer {
|
|
|
157
158
|
),
|
|
158
159
|
null,
|
|
159
160
|
]);
|
|
160
|
-
else if (last[0] === null) last[0] = write(
|
|
161
|
-
else spans.push([write(
|
|
161
|
+
else if (last[0] === null) last[0] = write(project)(importer)(elem);
|
|
162
|
+
else spans.push([write(project)(importer)(elem), null]);
|
|
162
163
|
}
|
|
163
164
|
return ts.factory.createTemplateLiteralType(
|
|
164
165
|
ts.factory.createTemplateHead(
|
|
@@ -197,18 +198,18 @@ export namespace SdkTypeProgrammer {
|
|
|
197
198
|
INSTANCES
|
|
198
199
|
----------------------------------------------------------- */
|
|
199
200
|
const write_array =
|
|
200
|
-
(
|
|
201
|
+
(project: INestiaProject) =>
|
|
201
202
|
(importer: ImportDictionary) =>
|
|
202
203
|
(meta: MetadataArray): ts.TypeNode =>
|
|
203
204
|
write_type_tag_matrix(importer)(
|
|
204
205
|
ts.factory.createArrayTypeNode(
|
|
205
|
-
write(
|
|
206
|
+
write(project)(importer)(meta.type.value),
|
|
206
207
|
),
|
|
207
208
|
meta.tags,
|
|
208
209
|
);
|
|
209
210
|
|
|
210
211
|
const write_tuple =
|
|
211
|
-
(
|
|
212
|
+
(project: INestiaProject) =>
|
|
212
213
|
(importer: ImportDictionary) =>
|
|
213
214
|
(meta: MetadataTuple): ts.TypeNode =>
|
|
214
215
|
ts.factory.createTupleTypeNode(
|
|
@@ -216,17 +217,19 @@ export namespace SdkTypeProgrammer {
|
|
|
216
217
|
elem.rest
|
|
217
218
|
? ts.factory.createRestTypeNode(
|
|
218
219
|
ts.factory.createArrayTypeNode(
|
|
219
|
-
write(
|
|
220
|
+
write(project)(importer)(elem.rest),
|
|
220
221
|
),
|
|
221
222
|
)
|
|
222
223
|
: elem.optional
|
|
223
|
-
? ts.factory.createOptionalTypeNode(
|
|
224
|
-
|
|
224
|
+
? ts.factory.createOptionalTypeNode(
|
|
225
|
+
write(project)(importer)(elem),
|
|
226
|
+
)
|
|
227
|
+
: write(project)(importer)(elem),
|
|
225
228
|
),
|
|
226
229
|
);
|
|
227
230
|
|
|
228
231
|
const write_regular_property =
|
|
229
|
-
(
|
|
232
|
+
(project: INestiaProject) =>
|
|
230
233
|
(importer: ImportDictionary) =>
|
|
231
234
|
(properties: MetadataProperty[]): ts.TypeLiteralNode =>
|
|
232
235
|
ts.factory.createTypeLiteralNode(
|
|
@@ -244,7 +247,7 @@ export namespace SdkTypeProgrammer {
|
|
|
244
247
|
p.value.isRequired() === false
|
|
245
248
|
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
246
249
|
: undefined,
|
|
247
|
-
SdkTypeProgrammer.write(
|
|
250
|
+
SdkTypeProgrammer.write(project)(importer)(p.value),
|
|
248
251
|
),
|
|
249
252
|
writeComment(p.value.atomics)(p.description, p.jsDocTags),
|
|
250
253
|
),
|
|
@@ -252,7 +255,7 @@ export namespace SdkTypeProgrammer {
|
|
|
252
255
|
);
|
|
253
256
|
|
|
254
257
|
const write_dynamic_property =
|
|
255
|
-
(
|
|
258
|
+
(project: INestiaProject) =>
|
|
256
259
|
(importer: ImportDictionary) =>
|
|
257
260
|
(property: MetadataProperty): ts.TypeLiteralNode =>
|
|
258
261
|
ts.factory.createTypeLiteralNode([
|
|
@@ -265,10 +268,10 @@ export namespace SdkTypeProgrammer {
|
|
|
265
268
|
undefined,
|
|
266
269
|
ts.factory.createIdentifier("key"),
|
|
267
270
|
undefined,
|
|
268
|
-
SdkTypeProgrammer.write(
|
|
271
|
+
SdkTypeProgrammer.write(project)(importer)(property.key),
|
|
269
272
|
),
|
|
270
273
|
],
|
|
271
|
-
SdkTypeProgrammer.write(
|
|
274
|
+
SdkTypeProgrammer.write(project)(importer)(property.value),
|
|
272
275
|
),
|
|
273
276
|
writeComment(property.value.atomics)(
|
|
274
277
|
property.description,
|
|
@@ -278,10 +281,10 @@ export namespace SdkTypeProgrammer {
|
|
|
278
281
|
]);
|
|
279
282
|
|
|
280
283
|
const write_alias =
|
|
281
|
-
(
|
|
284
|
+
(project: INestiaProject) =>
|
|
282
285
|
(importer: ImportDictionary) =>
|
|
283
286
|
(meta: MetadataAlias | MetadataObject): ts.TypeNode => {
|
|
284
|
-
importInternalFile(
|
|
287
|
+
importInternalFile(project)(importer)(meta.name);
|
|
285
288
|
return ts.factory.createTypeReferenceNode(meta.name);
|
|
286
289
|
};
|
|
287
290
|
|
|
@@ -375,12 +378,15 @@ const writeComment =
|
|
|
375
378
|
};
|
|
376
379
|
|
|
377
380
|
const importInternalFile =
|
|
378
|
-
(
|
|
381
|
+
(project: INestiaProject) =>
|
|
382
|
+
(importer: ImportDictionary) =>
|
|
383
|
+
(name: string) => {
|
|
379
384
|
const top = name.split(".")[0];
|
|
380
|
-
if (importer.file === `${config.output}/structures/${top}.ts`)
|
|
385
|
+
if (importer.file === `${project.config.output}/structures/${top}.ts`)
|
|
386
|
+
return;
|
|
381
387
|
importer.internal({
|
|
382
388
|
type: true,
|
|
383
|
-
file: `${config.output}/structures/${name.split(".")[0]}`,
|
|
389
|
+
file: `${project.config.output}/structures/${name.split(".")[0]}`,
|
|
384
390
|
instance: top,
|
|
385
391
|
});
|
|
386
392
|
};
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { ExpressionFactory } from "typia/lib/factories/ExpressionFactory";
|
|
3
|
+
import { IdentifierFactory } from "typia/lib/factories/IdentifierFactory";
|
|
4
|
+
import { TypeFactory } from "typia/lib/factories/TypeFactory";
|
|
5
|
+
|
|
6
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
7
|
+
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
8
|
+
import { FilePrinter } from "./FilePrinter";
|
|
9
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
10
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace SdkWebSocketNamespaceProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: INestiaProject) =>
|
|
15
|
+
(importer: ImportDictionary) =>
|
|
16
|
+
(route: ITypedWebSocketRoute): ts.ModuleDeclaration =>
|
|
17
|
+
ts.factory.createModuleDeclaration(
|
|
18
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
19
|
+
ts.factory.createIdentifier(route.name),
|
|
20
|
+
ts.factory.createModuleBlock([
|
|
21
|
+
...writeTypes(importer)(route),
|
|
22
|
+
FilePrinter.enter(),
|
|
23
|
+
writePath(project)(importer)(route),
|
|
24
|
+
]),
|
|
25
|
+
ts.NodeFlags.Namespace,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const writeTypes =
|
|
29
|
+
(importer: ImportDictionary) =>
|
|
30
|
+
(route: ITypedWebSocketRoute): ts.TypeAliasDeclaration[] => {
|
|
31
|
+
const output: ts.TypeAliasDeclaration[] = [];
|
|
32
|
+
const declare = (name: string, type: ts.TypeNode) =>
|
|
33
|
+
output.push(
|
|
34
|
+
ts.factory.createTypeAliasDeclaration(
|
|
35
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
36
|
+
name,
|
|
37
|
+
undefined,
|
|
38
|
+
type,
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
declare(
|
|
43
|
+
"Output",
|
|
44
|
+
ts.factory.createTypeLiteralNode([
|
|
45
|
+
ts.factory.createPropertySignature(
|
|
46
|
+
undefined,
|
|
47
|
+
"connector",
|
|
48
|
+
undefined,
|
|
49
|
+
ts.factory.createTypeReferenceNode(
|
|
50
|
+
importer.external({
|
|
51
|
+
type: false,
|
|
52
|
+
library: "tgrid",
|
|
53
|
+
instance: "WebConnector",
|
|
54
|
+
}),
|
|
55
|
+
[
|
|
56
|
+
ts.factory.createTypeReferenceNode("Header"),
|
|
57
|
+
ts.factory.createTypeReferenceNode("Provider"),
|
|
58
|
+
ts.factory.createTypeReferenceNode("Listener"),
|
|
59
|
+
],
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
ts.factory.createPropertySignature(
|
|
63
|
+
undefined,
|
|
64
|
+
"driver",
|
|
65
|
+
undefined,
|
|
66
|
+
ts.factory.createTypeReferenceNode(
|
|
67
|
+
importer.external({
|
|
68
|
+
type: true,
|
|
69
|
+
library: "tgrid",
|
|
70
|
+
instance: "Driver",
|
|
71
|
+
}),
|
|
72
|
+
[ts.factory.createTypeReferenceNode("Listener")],
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
]),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const acceptor: ITypedWebSocketRoute.IAcceptorParameter =
|
|
79
|
+
route.parameters.find(
|
|
80
|
+
(x) => x.category === "acceptor",
|
|
81
|
+
) as ITypedWebSocketRoute.IAcceptorParameter;
|
|
82
|
+
const query = route.parameters.find((x) => x.category === "query") as
|
|
83
|
+
| ITypedWebSocketRoute.IQueryParameter
|
|
84
|
+
| undefined;
|
|
85
|
+
|
|
86
|
+
declare(
|
|
87
|
+
"Header",
|
|
88
|
+
ts.factory.createTypeReferenceNode(
|
|
89
|
+
(
|
|
90
|
+
(route.parameters.find((x) => x.category === "header") as
|
|
91
|
+
| ITypedWebSocketRoute.IHeaderParameter
|
|
92
|
+
| undefined) ?? acceptor.header
|
|
93
|
+
).typeName,
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
declare(
|
|
97
|
+
"Provider",
|
|
98
|
+
ts.factory.createTypeReferenceNode(
|
|
99
|
+
(
|
|
100
|
+
(route.parameters.find((x) => x.category === "driver") as
|
|
101
|
+
| ITypedWebSocketRoute.IDriverParameter
|
|
102
|
+
| undefined) ?? acceptor.listener
|
|
103
|
+
).typeName,
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
declare(
|
|
107
|
+
"Listener",
|
|
108
|
+
ts.factory.createTypeReferenceNode(acceptor.provider.typeName),
|
|
109
|
+
);
|
|
110
|
+
if (query)
|
|
111
|
+
declare("Query", ts.factory.createTypeReferenceNode(query.typeName));
|
|
112
|
+
return output;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const writePath =
|
|
116
|
+
(project: INestiaProject) =>
|
|
117
|
+
(importer: ImportDictionary) =>
|
|
118
|
+
(route: ITypedWebSocketRoute): ts.VariableStatement => {
|
|
119
|
+
const pathParams: ITypedWebSocketRoute.IPathParameter[] =
|
|
120
|
+
route.parameters.filter(
|
|
121
|
+
(p) => p.category === "param",
|
|
122
|
+
) as ITypedWebSocketRoute.IPathParameter[];
|
|
123
|
+
const query: ITypedWebSocketRoute.IQueryParameter | undefined =
|
|
124
|
+
route.parameters.find((p) => p.category === "query") as
|
|
125
|
+
| ITypedWebSocketRoute.IQueryParameter
|
|
126
|
+
| undefined;
|
|
127
|
+
const total: Array<
|
|
128
|
+
| ITypedWebSocketRoute.IPathParameter
|
|
129
|
+
| ITypedWebSocketRoute.IQueryParameter
|
|
130
|
+
> = [...pathParams, ...(query ? [query] : [])];
|
|
131
|
+
const out = (body: ts.ConciseBody) =>
|
|
132
|
+
constant("path")(
|
|
133
|
+
ts.factory.createArrowFunction(
|
|
134
|
+
[],
|
|
135
|
+
[],
|
|
136
|
+
total.map((p) =>
|
|
137
|
+
IdentifierFactory.parameter(
|
|
138
|
+
p.name,
|
|
139
|
+
p === query
|
|
140
|
+
? ts.factory.createTypeReferenceNode(`${route.name}.Query`)
|
|
141
|
+
: getType(project)(importer)(p),
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
undefined,
|
|
145
|
+
undefined,
|
|
146
|
+
body,
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
if (total.length === 0)
|
|
150
|
+
return out(ts.factory.createStringLiteral(route.path));
|
|
151
|
+
|
|
152
|
+
const template = () => {
|
|
153
|
+
const splitted: string[] = route.path.split(":");
|
|
154
|
+
if (splitted.length === 1)
|
|
155
|
+
return ts.factory.createStringLiteral(route.path);
|
|
156
|
+
return ts.factory.createTemplateExpression(
|
|
157
|
+
ts.factory.createTemplateHead(splitted[0]),
|
|
158
|
+
splitted.slice(1).map((s, i, arr) => {
|
|
159
|
+
const name: string = s.split("/")[0];
|
|
160
|
+
return ts.factory.createTemplateSpan(
|
|
161
|
+
ts.factory.createCallExpression(
|
|
162
|
+
ts.factory.createIdentifier("encodeURIComponent"),
|
|
163
|
+
undefined,
|
|
164
|
+
[
|
|
165
|
+
ts.factory.createBinaryExpression(
|
|
166
|
+
ts.factory.createIdentifier(
|
|
167
|
+
pathParams.find((p) => p.field === name)!.name,
|
|
168
|
+
),
|
|
169
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
|
|
170
|
+
ts.factory.createStringLiteral("null"),
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
),
|
|
174
|
+
(i !== arr.length - 1
|
|
175
|
+
? ts.factory.createTemplateMiddle
|
|
176
|
+
: ts.factory.createTemplateTail)(s.substring(name.length)),
|
|
177
|
+
);
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
if (query === undefined) return out(template());
|
|
182
|
+
|
|
183
|
+
const block = (expr: ts.Expression) => {
|
|
184
|
+
const computeName = (str: string): string =>
|
|
185
|
+
total.find((p) => p.name === str) !== undefined
|
|
186
|
+
? computeName("_" + str)
|
|
187
|
+
: str;
|
|
188
|
+
const variables: string = computeName("variables");
|
|
189
|
+
return ts.factory.createBlock(
|
|
190
|
+
[
|
|
191
|
+
local(variables)("URLSearchParams")(
|
|
192
|
+
ts.factory.createNewExpression(
|
|
193
|
+
ts.factory.createIdentifier("URLSearchParams"),
|
|
194
|
+
[],
|
|
195
|
+
[],
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
ts.factory.createForOfStatement(
|
|
199
|
+
undefined,
|
|
200
|
+
ts.factory.createVariableDeclarationList(
|
|
201
|
+
[
|
|
202
|
+
ts.factory.createVariableDeclaration(
|
|
203
|
+
ts.factory.createArrayBindingPattern([
|
|
204
|
+
ts.factory.createBindingElement(
|
|
205
|
+
undefined,
|
|
206
|
+
undefined,
|
|
207
|
+
ts.factory.createIdentifier("key"),
|
|
208
|
+
undefined,
|
|
209
|
+
),
|
|
210
|
+
ts.factory.createBindingElement(
|
|
211
|
+
undefined,
|
|
212
|
+
undefined,
|
|
213
|
+
ts.factory.createIdentifier("value"),
|
|
214
|
+
undefined,
|
|
215
|
+
),
|
|
216
|
+
]),
|
|
217
|
+
undefined,
|
|
218
|
+
undefined,
|
|
219
|
+
undefined,
|
|
220
|
+
),
|
|
221
|
+
],
|
|
222
|
+
ts.NodeFlags.Const,
|
|
223
|
+
),
|
|
224
|
+
ts.factory.createCallExpression(
|
|
225
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
226
|
+
undefined,
|
|
227
|
+
[
|
|
228
|
+
ts.factory.createAsExpression(
|
|
229
|
+
expr,
|
|
230
|
+
TypeFactory.keyword("any"),
|
|
231
|
+
),
|
|
232
|
+
],
|
|
233
|
+
),
|
|
234
|
+
ts.factory.createIfStatement(
|
|
235
|
+
ts.factory.createStrictEquality(
|
|
236
|
+
ts.factory.createIdentifier("undefined"),
|
|
237
|
+
ts.factory.createIdentifier("value"),
|
|
238
|
+
),
|
|
239
|
+
ts.factory.createContinueStatement(),
|
|
240
|
+
ts.factory.createIfStatement(
|
|
241
|
+
ts.factory.createCallExpression(
|
|
242
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
243
|
+
undefined,
|
|
244
|
+
[ts.factory.createIdentifier("value")],
|
|
245
|
+
),
|
|
246
|
+
ts.factory.createExpressionStatement(
|
|
247
|
+
ts.factory.createCallExpression(
|
|
248
|
+
ts.factory.createPropertyAccessExpression(
|
|
249
|
+
ts.factory.createIdentifier("value"),
|
|
250
|
+
ts.factory.createIdentifier("forEach"),
|
|
251
|
+
),
|
|
252
|
+
undefined,
|
|
253
|
+
[
|
|
254
|
+
ts.factory.createArrowFunction(
|
|
255
|
+
undefined,
|
|
256
|
+
undefined,
|
|
257
|
+
[IdentifierFactory.parameter("elem")],
|
|
258
|
+
undefined,
|
|
259
|
+
undefined,
|
|
260
|
+
ts.factory.createCallExpression(
|
|
261
|
+
IdentifierFactory.access(
|
|
262
|
+
ts.factory.createIdentifier(variables),
|
|
263
|
+
)("append"),
|
|
264
|
+
undefined,
|
|
265
|
+
[
|
|
266
|
+
ts.factory.createIdentifier("key"),
|
|
267
|
+
ts.factory.createCallExpression(
|
|
268
|
+
ts.factory.createIdentifier("String"),
|
|
269
|
+
undefined,
|
|
270
|
+
[ts.factory.createIdentifier("elem")],
|
|
271
|
+
),
|
|
272
|
+
],
|
|
273
|
+
),
|
|
274
|
+
),
|
|
275
|
+
],
|
|
276
|
+
),
|
|
277
|
+
),
|
|
278
|
+
ts.factory.createExpressionStatement(
|
|
279
|
+
ts.factory.createCallExpression(
|
|
280
|
+
IdentifierFactory.access(
|
|
281
|
+
ts.factory.createIdentifier(variables),
|
|
282
|
+
)("set"),
|
|
283
|
+
undefined,
|
|
284
|
+
[
|
|
285
|
+
ts.factory.createIdentifier("key"),
|
|
286
|
+
ts.factory.createCallExpression(
|
|
287
|
+
ts.factory.createIdentifier("String"),
|
|
288
|
+
undefined,
|
|
289
|
+
[ts.factory.createIdentifier("value")],
|
|
290
|
+
),
|
|
291
|
+
],
|
|
292
|
+
),
|
|
293
|
+
),
|
|
294
|
+
),
|
|
295
|
+
),
|
|
296
|
+
),
|
|
297
|
+
local("location")("string")(template()),
|
|
298
|
+
ts.factory.createReturnStatement(
|
|
299
|
+
ts.factory.createConditionalExpression(
|
|
300
|
+
ts.factory.createStrictEquality(
|
|
301
|
+
ExpressionFactory.number(0),
|
|
302
|
+
IdentifierFactory.access(
|
|
303
|
+
ts.factory.createIdentifier(variables),
|
|
304
|
+
)("size"),
|
|
305
|
+
),
|
|
306
|
+
undefined,
|
|
307
|
+
ts.factory.createIdentifier("location"),
|
|
308
|
+
undefined,
|
|
309
|
+
ts.factory.createTemplateExpression(
|
|
310
|
+
ts.factory.createTemplateHead(""),
|
|
311
|
+
[
|
|
312
|
+
ts.factory.createTemplateSpan(
|
|
313
|
+
ts.factory.createIdentifier("location"),
|
|
314
|
+
ts.factory.createTemplateMiddle("?"),
|
|
315
|
+
),
|
|
316
|
+
ts.factory.createTemplateSpan(
|
|
317
|
+
ts.factory.createCallExpression(
|
|
318
|
+
IdentifierFactory.access(
|
|
319
|
+
ts.factory.createIdentifier(variables),
|
|
320
|
+
)("toString"),
|
|
321
|
+
undefined,
|
|
322
|
+
undefined,
|
|
323
|
+
),
|
|
324
|
+
ts.factory.createTemplateTail(""),
|
|
325
|
+
),
|
|
326
|
+
],
|
|
327
|
+
),
|
|
328
|
+
),
|
|
329
|
+
),
|
|
330
|
+
],
|
|
331
|
+
true,
|
|
332
|
+
);
|
|
333
|
+
};
|
|
334
|
+
return out(block(ts.factory.createIdentifier(query.name)));
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const local = (name: string) => (type: string) => (expression: ts.Expression) =>
|
|
339
|
+
ts.factory.createVariableStatement(
|
|
340
|
+
[],
|
|
341
|
+
ts.factory.createVariableDeclarationList(
|
|
342
|
+
[
|
|
343
|
+
ts.factory.createVariableDeclaration(
|
|
344
|
+
name,
|
|
345
|
+
undefined,
|
|
346
|
+
ts.factory.createTypeReferenceNode(type),
|
|
347
|
+
expression,
|
|
348
|
+
),
|
|
349
|
+
],
|
|
350
|
+
ts.NodeFlags.Const,
|
|
351
|
+
),
|
|
352
|
+
);
|
|
353
|
+
const constant = (name: string) => (expression: ts.Expression) =>
|
|
354
|
+
ts.factory.createVariableStatement(
|
|
355
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
356
|
+
ts.factory.createVariableDeclarationList(
|
|
357
|
+
[
|
|
358
|
+
ts.factory.createVariableDeclaration(
|
|
359
|
+
name,
|
|
360
|
+
undefined,
|
|
361
|
+
undefined,
|
|
362
|
+
expression,
|
|
363
|
+
),
|
|
364
|
+
],
|
|
365
|
+
ts.NodeFlags.Const,
|
|
366
|
+
),
|
|
367
|
+
);
|
|
368
|
+
const getType =
|
|
369
|
+
(project: INestiaProject) =>
|
|
370
|
+
(importer: ImportDictionary) =>
|
|
371
|
+
(
|
|
372
|
+
p:
|
|
373
|
+
| ITypedWebSocketRoute.IPathParameter
|
|
374
|
+
| ITypedWebSocketRoute.IQueryParameter,
|
|
375
|
+
) =>
|
|
376
|
+
p.metadata
|
|
377
|
+
? SdkTypeProgrammer.write(project)(importer)(p.metadata)
|
|
378
|
+
: ts.factory.createTypeReferenceNode(p.typeName);
|