@nestia/sdk 11.0.0-dev.20260316 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/assets/bundle/api/HttpError.ts +1 -1
  4. package/assets/bundle/api/IConnection.ts +1 -1
  5. package/assets/bundle/api/Primitive.ts +1 -1
  6. package/assets/bundle/api/Resolved.ts +1 -1
  7. package/assets/bundle/api/index.ts +4 -4
  8. package/assets/bundle/api/module.ts +6 -6
  9. package/assets/bundle/distribute/README.md +37 -37
  10. package/assets/bundle/distribute/package.json +28 -28
  11. package/assets/bundle/distribute/tsconfig.json +109 -109
  12. package/assets/bundle/e2e/index.ts +42 -42
  13. package/assets/config/nestia.config.ts +97 -97
  14. package/lib/executable/internal/NestiaConfigLoader.js +5 -5
  15. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  16. package/package.json +8 -8
  17. package/src/INestiaConfig.ts +267 -267
  18. package/src/NestiaSdkApplication.ts +307 -307
  19. package/src/NestiaSwaggerComposer.ts +143 -143
  20. package/src/analyses/AccessorAnalyzer.ts +67 -67
  21. package/src/analyses/DtoAnalyzer.ts +260 -260
  22. package/src/analyses/ImportAnalyzer.ts +126 -126
  23. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  24. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -72
  25. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -350
  26. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -126
  27. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -208
  28. package/src/executable/internal/NestiaConfigLoader.ts +85 -85
  29. package/src/executable/internal/NestiaSdkCommand.ts +107 -107
  30. package/src/generates/SwaggerGenerator.ts +291 -291
  31. package/src/generates/internal/E2eFileProgrammer.ts +196 -196
  32. package/src/generates/internal/FilePrinter.ts +64 -64
  33. package/src/generates/internal/ImportDictionary.ts +192 -192
  34. package/src/generates/internal/SdkAliasCollection.ts +260 -260
  35. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  36. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -126
  37. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  38. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -278
  39. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -502
  40. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -109
  41. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -312
  42. package/src/generates/internal/SdkImportWizard.ts +62 -62
  43. package/src/generates/internal/SdkTypeProgrammer.ts +388 -388
  44. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -114
  45. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -379
  46. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  47. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  48. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -161
  49. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  50. package/src/module.ts +4 -4
  51. package/src/structures/IReflectHttpOperationException.ts +18 -18
  52. package/src/structures/IReflectHttpOperationParameter.ts +79 -79
  53. package/src/structures/IReflectHttpOperationSuccess.ts +21 -21
  54. package/src/structures/ITypedApplication.ts +11 -11
  55. package/src/structures/ITypedHttpRouteException.ts +15 -15
  56. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  57. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  58. package/src/transformers/IOperationMetadata.ts +46 -46
  59. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  60. package/src/transformers/SdkOperationProgrammer.ts +240 -240
  61. package/src/transformers/SdkOperationTransformer.ts +248 -248
  62. package/src/transformers/TextPlainValidator.ts +17 -17
  63. package/src/utils/MetadataUtil.ts +26 -26
  64. package/src/validators/HttpHeadersValidator.ts +40 -40
  65. package/src/validators/HttpQueryValidator.ts +40 -40
@@ -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,126 +1,126 @@
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
+ 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 { 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(", ")}>`;
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(", ")}>`;