@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,110 +1,110 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaProject } from "../../structures/INestiaProject";
|
|
5
|
-
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
6
|
-
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
7
|
-
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
8
|
-
import { MapUtil } from "../../utils/MapUtil";
|
|
9
|
-
import { FilePrinter } from "./FilePrinter";
|
|
10
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
11
|
-
import { SdkHttpRouteProgrammer } from "./SdkHttpRouteProgrammer";
|
|
12
|
-
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
13
|
-
import { SdkWebSocketRouteProgrammer } from "./SdkWebSocketRouteProgrammer";
|
|
14
|
-
|
|
15
|
-
export namespace SdkFileProgrammer {
|
|
16
|
-
/* ---------------------------------------------------------
|
|
17
|
-
CONSTRUCTOR
|
|
18
|
-
--------------------------------------------------------- */
|
|
19
|
-
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
20
|
-
// CONSTRUCT FOLDER TREE
|
|
21
|
-
const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
|
|
22
|
-
for (const route of app.routes) emplace(root)(route);
|
|
23
|
-
|
|
24
|
-
// ITERATE FILES
|
|
25
|
-
await iterate(app.project)(root)(`${app.project.config.output}/functional`);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const emplace =
|
|
29
|
-
(directory: SdkRouteDirectory) =>
|
|
30
|
-
(route: ITypedHttpRoute | ITypedWebSocketRoute): void => {
|
|
31
|
-
// OPEN DIRECTORIES
|
|
32
|
-
for (const key of route.accessor.slice(0, -1)) {
|
|
33
|
-
directory = MapUtil.take(
|
|
34
|
-
directory.children,
|
|
35
|
-
key,
|
|
36
|
-
() => new SdkRouteDirectory(directory, key),
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ADD ROUTE
|
|
41
|
-
directory.routes.push(route);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/* ---------------------------------------------------------
|
|
45
|
-
FILE ITERATOR
|
|
46
|
-
--------------------------------------------------------- */
|
|
47
|
-
const iterate =
|
|
48
|
-
(project: INestiaProject) =>
|
|
49
|
-
(directory: SdkRouteDirectory) =>
|
|
50
|
-
async (outDir: string): Promise<void> => {
|
|
51
|
-
// CREATE A NEW DIRECTORY
|
|
52
|
-
try {
|
|
53
|
-
await fs.promises.mkdir(outDir);
|
|
54
|
-
} catch {}
|
|
55
|
-
|
|
56
|
-
// ITERATE CHILDREN
|
|
57
|
-
const statements: ts.Statement[] = [];
|
|
58
|
-
for (const [key, value] of directory.children) {
|
|
59
|
-
await iterate(project)(value)(`${outDir}/${key}`);
|
|
60
|
-
statements.push(
|
|
61
|
-
ts.factory.createExportDeclaration(
|
|
62
|
-
undefined,
|
|
63
|
-
false,
|
|
64
|
-
ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
|
|
65
|
-
ts.factory.createStringLiteral(`./${key}/index`),
|
|
66
|
-
undefined,
|
|
67
|
-
),
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
if (statements.length && directory.routes.length)
|
|
71
|
-
statements.push(FilePrinter.enter());
|
|
72
|
-
|
|
73
|
-
// ITERATE ROUTES
|
|
74
|
-
const importer: ImportDictionary = new ImportDictionary(
|
|
75
|
-
`${outDir}/index.ts`,
|
|
76
|
-
);
|
|
77
|
-
directory.routes.forEach((route, i) => {
|
|
78
|
-
if (!(project.config.clone === true && route.protocol === "http"))
|
|
79
|
-
importer.declarations(route.imports);
|
|
80
|
-
statements.push(
|
|
81
|
-
...(route.protocol === "http"
|
|
82
|
-
? SdkHttpRouteProgrammer.write(project)(importer)(route)
|
|
83
|
-
: SdkWebSocketRouteProgrammer.write(project)(importer)(route)),
|
|
84
|
-
);
|
|
85
|
-
if (i !== directory.routes.length - 1)
|
|
86
|
-
statements.push(FilePrinter.enter());
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// FINALIZE THE CONTENT
|
|
90
|
-
if (directory.routes.length !== 0)
|
|
91
|
-
statements.push(
|
|
92
|
-
...importer.toStatements(outDir),
|
|
93
|
-
...(!importer.empty() && statements.length
|
|
94
|
-
? [FilePrinter.enter()]
|
|
95
|
-
: []),
|
|
96
|
-
...statements.splice(0, statements.length),
|
|
97
|
-
);
|
|
98
|
-
await FilePrinter.write({
|
|
99
|
-
location: importer.file,
|
|
100
|
-
statements,
|
|
101
|
-
top:
|
|
102
|
-
"/**\n" +
|
|
103
|
-
" * @packageDocumentation\n" +
|
|
104
|
-
` * @module ${directory.module}\n` +
|
|
105
|
-
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
106
|
-
" */\n" +
|
|
107
|
-
"//================================================================\n",
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
5
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
6
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
7
|
+
import { ITypedWebSocketRoute } from "../../structures/ITypedWebSocketRoute";
|
|
8
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
9
|
+
import { FilePrinter } from "./FilePrinter";
|
|
10
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
11
|
+
import { SdkHttpRouteProgrammer } from "./SdkHttpRouteProgrammer";
|
|
12
|
+
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
13
|
+
import { SdkWebSocketRouteProgrammer } from "./SdkWebSocketRouteProgrammer";
|
|
14
|
+
|
|
15
|
+
export namespace SdkFileProgrammer {
|
|
16
|
+
/* ---------------------------------------------------------
|
|
17
|
+
CONSTRUCTOR
|
|
18
|
+
--------------------------------------------------------- */
|
|
19
|
+
export const generate = async (app: ITypedApplication): Promise<void> => {
|
|
20
|
+
// CONSTRUCT FOLDER TREE
|
|
21
|
+
const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
|
|
22
|
+
for (const route of app.routes) emplace(root)(route);
|
|
23
|
+
|
|
24
|
+
// ITERATE FILES
|
|
25
|
+
await iterate(app.project)(root)(`${app.project.config.output}/functional`);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const emplace =
|
|
29
|
+
(directory: SdkRouteDirectory) =>
|
|
30
|
+
(route: ITypedHttpRoute | ITypedWebSocketRoute): void => {
|
|
31
|
+
// OPEN DIRECTORIES
|
|
32
|
+
for (const key of route.accessor.slice(0, -1)) {
|
|
33
|
+
directory = MapUtil.take(
|
|
34
|
+
directory.children,
|
|
35
|
+
key,
|
|
36
|
+
() => new SdkRouteDirectory(directory, key),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ADD ROUTE
|
|
41
|
+
directory.routes.push(route);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/* ---------------------------------------------------------
|
|
45
|
+
FILE ITERATOR
|
|
46
|
+
--------------------------------------------------------- */
|
|
47
|
+
const iterate =
|
|
48
|
+
(project: INestiaProject) =>
|
|
49
|
+
(directory: SdkRouteDirectory) =>
|
|
50
|
+
async (outDir: string): Promise<void> => {
|
|
51
|
+
// CREATE A NEW DIRECTORY
|
|
52
|
+
try {
|
|
53
|
+
await fs.promises.mkdir(outDir);
|
|
54
|
+
} catch {}
|
|
55
|
+
|
|
56
|
+
// ITERATE CHILDREN
|
|
57
|
+
const statements: ts.Statement[] = [];
|
|
58
|
+
for (const [key, value] of directory.children) {
|
|
59
|
+
await iterate(project)(value)(`${outDir}/${key}`);
|
|
60
|
+
statements.push(
|
|
61
|
+
ts.factory.createExportDeclaration(
|
|
62
|
+
undefined,
|
|
63
|
+
false,
|
|
64
|
+
ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
|
|
65
|
+
ts.factory.createStringLiteral(`./${key}/index`),
|
|
66
|
+
undefined,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (statements.length && directory.routes.length)
|
|
71
|
+
statements.push(FilePrinter.enter());
|
|
72
|
+
|
|
73
|
+
// ITERATE ROUTES
|
|
74
|
+
const importer: ImportDictionary = new ImportDictionary(
|
|
75
|
+
`${outDir}/index.ts`,
|
|
76
|
+
);
|
|
77
|
+
directory.routes.forEach((route, i) => {
|
|
78
|
+
if (!(project.config.clone === true && route.protocol === "http"))
|
|
79
|
+
importer.declarations(route.imports);
|
|
80
|
+
statements.push(
|
|
81
|
+
...(route.protocol === "http"
|
|
82
|
+
? SdkHttpRouteProgrammer.write(project)(importer)(route)
|
|
83
|
+
: SdkWebSocketRouteProgrammer.write(project)(importer)(route)),
|
|
84
|
+
);
|
|
85
|
+
if (i !== directory.routes.length - 1)
|
|
86
|
+
statements.push(FilePrinter.enter());
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// FINALIZE THE CONTENT
|
|
90
|
+
if (directory.routes.length !== 0)
|
|
91
|
+
statements.push(
|
|
92
|
+
...importer.toStatements(outDir),
|
|
93
|
+
...(!importer.empty() && statements.length
|
|
94
|
+
? [FilePrinter.enter()]
|
|
95
|
+
: []),
|
|
96
|
+
...statements.splice(0, statements.length),
|
|
97
|
+
);
|
|
98
|
+
await FilePrinter.write({
|
|
99
|
+
location: importer.file,
|
|
100
|
+
statements,
|
|
101
|
+
top:
|
|
102
|
+
"/**\n" +
|
|
103
|
+
" * @packageDocumentation\n" +
|
|
104
|
+
` * @module ${directory.module}\n` +
|
|
105
|
+
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
106
|
+
" */\n" +
|
|
107
|
+
"//================================================================\n",
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -1,124 +1,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
1
|
+
import {
|
|
2
|
+
MetadataAliasType,
|
|
3
|
+
MetadataAtomic,
|
|
4
|
+
MetadataObjectType,
|
|
5
|
+
} from "@typia/core";
|
|
6
|
+
import { IPointer } from "tstl";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
import { IJsDocTagInfo } from "typia";
|
|
9
|
+
|
|
10
|
+
import { INestiaProject } from "../../structures/INestiaProject";
|
|
11
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
12
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
13
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
14
|
+
import { FilePrinter } from "./FilePrinter";
|
|
15
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
16
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
17
|
+
|
|
18
|
+
export namespace SdkHttpCloneProgrammer {
|
|
19
|
+
export interface IModule {
|
|
20
|
+
name: string;
|
|
21
|
+
children: Map<string, IModule>;
|
|
22
|
+
programmer:
|
|
23
|
+
| null
|
|
24
|
+
| ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const write = (app: ITypedApplication): Map<string, IModule> => {
|
|
28
|
+
// COMPOSE THE DICTIONARY
|
|
29
|
+
const dict: Map<string, IModule> = new Map();
|
|
30
|
+
for (const [k, v] of app.collection.objects.entries())
|
|
31
|
+
if (StringUtil.isImplicit(k) === false)
|
|
32
|
+
prepare({
|
|
33
|
+
dict,
|
|
34
|
+
name: k,
|
|
35
|
+
programmer: (importer) => writeObject(app.project)(importer)(v),
|
|
36
|
+
});
|
|
37
|
+
for (const [k, v] of app.collection.aliases.entries())
|
|
38
|
+
if (StringUtil.isImplicit(k) === false)
|
|
39
|
+
prepare({
|
|
40
|
+
dict,
|
|
41
|
+
name: k,
|
|
42
|
+
programmer: (importer) => writeAlias(app.project)(importer)(v),
|
|
43
|
+
});
|
|
44
|
+
return dict;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const prepare = (props: {
|
|
48
|
+
dict: Map<string, IModule>;
|
|
49
|
+
name: string;
|
|
50
|
+
programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration;
|
|
51
|
+
}) => {
|
|
52
|
+
let next: Map<string, IModule> = props.dict;
|
|
53
|
+
const accessors: string[] = props.name.split(".");
|
|
54
|
+
const modulo: IPointer<IModule> = { value: null! };
|
|
55
|
+
|
|
56
|
+
accessors.forEach((acc, i) => {
|
|
57
|
+
modulo.value = MapUtil.take(next, acc, () => ({
|
|
58
|
+
name: acc,
|
|
59
|
+
children: new Map(),
|
|
60
|
+
programmer: null,
|
|
61
|
+
}));
|
|
62
|
+
if (i === accessors.length - 1)
|
|
63
|
+
modulo.value.programmer = props.programmer;
|
|
64
|
+
next = modulo.value.children;
|
|
65
|
+
});
|
|
66
|
+
return modulo!;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const writeAlias =
|
|
70
|
+
(project: INestiaProject) =>
|
|
71
|
+
(importer: ImportDictionary) =>
|
|
72
|
+
(alias: MetadataAliasType): ts.TypeAliasDeclaration =>
|
|
73
|
+
FilePrinter.description(
|
|
74
|
+
ts.factory.createTypeAliasDeclaration(
|
|
75
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
76
|
+
alias.name.split(".").at(-1)!,
|
|
77
|
+
[],
|
|
78
|
+
SdkTypeProgrammer.write(project)(importer)(alias.value),
|
|
79
|
+
),
|
|
80
|
+
writeComment([])(alias.description, alias.jsDocTags),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const writeObject =
|
|
84
|
+
(project: INestiaProject) =>
|
|
85
|
+
(importer: ImportDictionary) =>
|
|
86
|
+
(object: MetadataObjectType): ts.TypeAliasDeclaration => {
|
|
87
|
+
return FilePrinter.description(
|
|
88
|
+
ts.factory.createTypeAliasDeclaration(
|
|
89
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
90
|
+
object.name.split(".").at(-1)!,
|
|
91
|
+
[],
|
|
92
|
+
SdkTypeProgrammer.write_object(project)(importer)(object),
|
|
93
|
+
),
|
|
94
|
+
writeComment([])(object.description ?? null, object.jsDocTags),
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const writeComment =
|
|
100
|
+
(atomics: MetadataAtomic[]) =>
|
|
101
|
+
(description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
|
|
102
|
+
const lines: string[] = [];
|
|
103
|
+
if (description?.length)
|
|
104
|
+
lines.push(...description.split("\n").map((s) => `${s}`));
|
|
105
|
+
|
|
106
|
+
const filtered: IJsDocTagInfo[] =
|
|
107
|
+
!!atomics.length && !!jsDocTags?.length
|
|
108
|
+
? jsDocTags.filter(
|
|
109
|
+
(tag) =>
|
|
110
|
+
!atomics.some((a) =>
|
|
111
|
+
a.tags.some((r) => r.some((t) => t.kind === tag.name)),
|
|
112
|
+
),
|
|
113
|
+
)
|
|
114
|
+
: (jsDocTags ?? []);
|
|
115
|
+
|
|
116
|
+
if (description?.length && filtered.length) lines.push("");
|
|
117
|
+
if (filtered.length)
|
|
118
|
+
lines.push(
|
|
119
|
+
...filtered.map((t) =>
|
|
120
|
+
t.text?.length
|
|
121
|
+
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
122
|
+
: `@${t.name}`,
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
return lines.join("\n");
|
|
126
|
+
};
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { IReflectType } from "../../structures/IReflectType";
|
|
4
|
-
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
5
|
-
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
6
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
7
|
-
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
8
|
-
|
|
9
|
-
export namespace SdkHttpCloneReferencer {
|
|
10
|
-
export const replace = (app: ITypedApplication): void => {
|
|
11
|
-
const directory: string = `${app.project.config.output}/structures`;
|
|
12
|
-
for (const route of app.routes)
|
|
13
|
-
if (route.protocol === "http")
|
|
14
|
-
visitRoute({
|
|
15
|
-
directory,
|
|
16
|
-
route,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const visitRoute = (props: {
|
|
21
|
-
directory: string;
|
|
22
|
-
route: ITypedHttpRoute;
|
|
23
|
-
}): void => {
|
|
24
|
-
const unique: Set<string> = new Set();
|
|
25
|
-
for (const p of SdkHttpParameterProgrammer.getSignificant(
|
|
26
|
-
props.route,
|
|
27
|
-
true,
|
|
28
|
-
))
|
|
29
|
-
visitType({
|
|
30
|
-
unique,
|
|
31
|
-
metadata: p.metadata,
|
|
32
|
-
type: p.type,
|
|
33
|
-
name: (name) => (p.type = { name }),
|
|
34
|
-
});
|
|
35
|
-
for (const v of Object.values(props.route.exceptions))
|
|
36
|
-
visitType({
|
|
37
|
-
unique,
|
|
38
|
-
metadata: v.metadata,
|
|
39
|
-
type: v.type,
|
|
40
|
-
name: (name) => (v.type = { name }),
|
|
41
|
-
});
|
|
42
|
-
visitType({
|
|
43
|
-
unique,
|
|
44
|
-
metadata: props.route.success.metadata,
|
|
45
|
-
type: props.route.success.type,
|
|
46
|
-
name: (name) => (props.route.success.type = { name }),
|
|
47
|
-
});
|
|
48
|
-
props.route.imports = Array.from(unique).map((str) => ({
|
|
49
|
-
file: `${props.directory}/${str}`,
|
|
50
|
-
asterisk: null,
|
|
51
|
-
default: null,
|
|
52
|
-
elements: [str],
|
|
53
|
-
}));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const visitType = (p: {
|
|
57
|
-
unique: Set<string>;
|
|
58
|
-
metadata:
|
|
59
|
-
type: IReflectType;
|
|
60
|
-
name: (key: string) => void;
|
|
61
|
-
}): void => {
|
|
62
|
-
const enroll = (key: string) => {
|
|
63
|
-
if (key.length && StringUtil.isImplicit(key) === false)
|
|
64
|
-
p.unique.add(key.split(".")[0]);
|
|
65
|
-
};
|
|
66
|
-
for (const alias of p.metadata.aliases) enroll(alias.type.name);
|
|
67
|
-
for (const array of p.metadata.arrays) enroll(array.type.name);
|
|
68
|
-
for (const tuple of p.metadata.tuples) enroll(tuple.type.name);
|
|
69
|
-
for (const object of p.metadata.objects) enroll(object.type.name);
|
|
70
|
-
p.name(p.metadata.getName());
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const getFullText = (type: IReflectType): string =>
|
|
75
|
-
type.typeArguments === undefined
|
|
76
|
-
? type.name
|
|
77
|
-
: `${type.name}<${type.typeArguments.map(getFullText).join(", ")}>`;
|
|
1
|
+
import { MetadataSchema } from "@typia/core";
|
|
2
|
+
|
|
3
|
+
import { IReflectType } from "../../structures/IReflectType";
|
|
4
|
+
import { ITypedApplication } from "../../structures/ITypedApplication";
|
|
5
|
+
import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
|
|
6
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
7
|
+
import { SdkHttpParameterProgrammer } from "./SdkHttpParameterProgrammer";
|
|
8
|
+
|
|
9
|
+
export namespace SdkHttpCloneReferencer {
|
|
10
|
+
export const replace = (app: ITypedApplication): void => {
|
|
11
|
+
const directory: string = `${app.project.config.output}/structures`;
|
|
12
|
+
for (const route of app.routes)
|
|
13
|
+
if (route.protocol === "http")
|
|
14
|
+
visitRoute({
|
|
15
|
+
directory,
|
|
16
|
+
route,
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const visitRoute = (props: {
|
|
21
|
+
directory: string;
|
|
22
|
+
route: ITypedHttpRoute;
|
|
23
|
+
}): void => {
|
|
24
|
+
const unique: Set<string> = new Set();
|
|
25
|
+
for (const p of SdkHttpParameterProgrammer.getSignificant(
|
|
26
|
+
props.route,
|
|
27
|
+
true,
|
|
28
|
+
))
|
|
29
|
+
visitType({
|
|
30
|
+
unique,
|
|
31
|
+
metadata: p.metadata,
|
|
32
|
+
type: p.type,
|
|
33
|
+
name: (name) => (p.type = { name }),
|
|
34
|
+
});
|
|
35
|
+
for (const v of Object.values(props.route.exceptions))
|
|
36
|
+
visitType({
|
|
37
|
+
unique,
|
|
38
|
+
metadata: v.metadata,
|
|
39
|
+
type: v.type,
|
|
40
|
+
name: (name) => (v.type = { name }),
|
|
41
|
+
});
|
|
42
|
+
visitType({
|
|
43
|
+
unique,
|
|
44
|
+
metadata: props.route.success.metadata,
|
|
45
|
+
type: props.route.success.type,
|
|
46
|
+
name: (name) => (props.route.success.type = { name }),
|
|
47
|
+
});
|
|
48
|
+
props.route.imports = Array.from(unique).map((str) => ({
|
|
49
|
+
file: `${props.directory}/${str}`,
|
|
50
|
+
asterisk: null,
|
|
51
|
+
default: null,
|
|
52
|
+
elements: [str],
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const visitType = (p: {
|
|
57
|
+
unique: Set<string>;
|
|
58
|
+
metadata: MetadataSchema;
|
|
59
|
+
type: IReflectType;
|
|
60
|
+
name: (key: string) => void;
|
|
61
|
+
}): void => {
|
|
62
|
+
const enroll = (key: string) => {
|
|
63
|
+
if (key.length && StringUtil.isImplicit(key) === false)
|
|
64
|
+
p.unique.add(key.split(".")[0]!);
|
|
65
|
+
};
|
|
66
|
+
for (const alias of p.metadata.aliases) enroll(alias.type.name);
|
|
67
|
+
for (const array of p.metadata.arrays) enroll(array.type.name);
|
|
68
|
+
for (const tuple of p.metadata.tuples) enroll(tuple.type.name);
|
|
69
|
+
for (const object of p.metadata.objects) enroll(object.type.name);
|
|
70
|
+
p.name(p.metadata.getName());
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getFullText = (type: IReflectType): string =>
|
|
75
|
+
type.typeArguments === undefined
|
|
76
|
+
? type.name
|
|
77
|
+
: `${type.name}<${type.typeArguments.map(getFullText).join(", ")}>`;
|