@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.
Files changed (151) 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/INestiaConfig.d.ts +3 -3
  15. package/lib/NestiaSdkApplication.js.map +1 -1
  16. package/lib/NestiaSwaggerComposer.d.ts +3 -2
  17. package/lib/NestiaSwaggerComposer.js +5 -6
  18. package/lib/NestiaSwaggerComposer.js.map +1 -1
  19. package/lib/analyses/AccessorAnalyzer.js +2 -2
  20. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  21. package/lib/analyses/DtoAnalyzer.js.map +1 -1
  22. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  23. package/lib/analyses/ReflectHttpOperationAnalyzer.js +3 -3
  24. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  25. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +4 -2
  26. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
  27. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +7 -11
  28. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  29. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +6 -6
  30. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  31. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +1 -1
  32. package/lib/analyses/TypedHttpRouteAnalyzer.js +6 -8
  33. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  34. package/lib/executable/internal/NestiaConfigLoader.js +111 -52
  35. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  36. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  37. package/lib/executable/sdk.js +0 -0
  38. package/lib/generates/SwaggerGenerator.d.ts +1 -1
  39. package/lib/generates/SwaggerGenerator.js +11 -12
  40. package/lib/generates/SwaggerGenerator.js.map +1 -1
  41. package/lib/generates/internal/E2eFileProgrammer.js +8 -9
  42. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  43. package/lib/generates/internal/SdkAliasCollection.d.ts +2 -2
  44. package/lib/generates/internal/SdkAliasCollection.js +2 -2
  45. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  46. package/lib/generates/internal/SdkDistributionComposer.js +1 -1
  47. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  48. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  49. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +11 -12
  50. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  51. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +13 -16
  52. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  53. package/lib/generates/internal/SdkHttpRouteProgrammer.js +4 -4
  54. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  55. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +12 -16
  56. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  57. package/lib/generates/internal/SdkImportWizard.js +2 -2
  58. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  59. package/lib/generates/internal/SdkTypeProgrammer.d.ts +2 -3
  60. package/lib/generates/internal/SdkTypeProgrammer.js +6 -7
  61. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  62. package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +1 -1
  63. package/lib/generates/internal/SdkTypeTagProgrammer.js +11 -11
  64. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  65. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +6 -8
  66. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  67. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +2 -2
  68. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  69. package/lib/generates/internal/SwaggerOperationComposer.d.ts +3 -3
  70. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  71. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +1 -1
  72. package/lib/generates/internal/SwaggerOperationParameterComposer.js +10 -8
  73. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  74. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +3 -3
  75. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  76. package/lib/module.d.ts +1 -0
  77. package/lib/module.js +1 -0
  78. package/lib/module.js.map +1 -1
  79. package/lib/structures/IReflectHttpOperationException.d.ts +3 -4
  80. package/lib/structures/IReflectHttpOperationParameter.d.ts +3 -5
  81. package/lib/structures/IReflectHttpOperationSuccess.d.ts +3 -4
  82. package/lib/structures/ITypedApplication.d.ts +1 -1
  83. package/lib/structures/ITypedHttpRouteException.d.ts +2 -2
  84. package/lib/structures/ITypedHttpRouteParameter.d.ts +2 -2
  85. package/lib/structures/ITypedHttpRouteSuccess.d.ts +2 -2
  86. package/lib/transformers/IOperationMetadata.d.ts +2 -4
  87. package/lib/transformers/ISdkOperationTransformerContext.d.ts +1 -1
  88. package/lib/transformers/SdkOperationProgrammer.js +8 -10
  89. package/lib/transformers/SdkOperationProgrammer.js.map +1 -1
  90. package/lib/transformers/SdkOperationTransformer.js +6 -8
  91. package/lib/transformers/SdkOperationTransformer.js.map +1 -1
  92. package/lib/transformers/TextPlainValidator.d.ts +2 -2
  93. package/lib/transformers/TextPlainValidator.js.map +1 -1
  94. package/lib/utils/MetadataUtil.d.ts +2 -2
  95. package/lib/utils/MetadataUtil.js.map +1 -1
  96. package/lib/validators/HttpHeadersValidator.d.ts +2 -3
  97. package/lib/validators/HttpHeadersValidator.js +2 -2
  98. package/lib/validators/HttpHeadersValidator.js.map +1 -1
  99. package/lib/validators/HttpQueryValidator.d.ts +2 -3
  100. package/lib/validators/HttpQueryValidator.js +2 -2
  101. package/lib/validators/HttpQueryValidator.js.map +1 -1
  102. package/package.json +44 -30
  103. package/src/INestiaConfig.ts +267 -267
  104. package/src/NestiaSdkApplication.ts +307 -307
  105. package/src/NestiaSwaggerComposer.ts +143 -138
  106. package/src/analyses/AccessorAnalyzer.ts +67 -67
  107. package/src/analyses/DtoAnalyzer.ts +260 -260
  108. package/src/analyses/ImportAnalyzer.ts +126 -126
  109. package/src/analyses/ReflectHttpOperationAnalyzer.ts +183 -183
  110. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +72 -71
  111. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +350 -348
  112. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +126 -127
  113. package/src/analyses/TypedHttpRouteAnalyzer.ts +208 -204
  114. package/src/executable/internal/NestiaConfigLoader.ts +85 -78
  115. package/src/executable/internal/NestiaSdkCommand.ts +107 -103
  116. package/src/generates/SwaggerGenerator.ts +291 -284
  117. package/src/generates/internal/E2eFileProgrammer.ts +196 -197
  118. package/src/generates/internal/FilePrinter.ts +64 -64
  119. package/src/generates/internal/ImportDictionary.ts +192 -192
  120. package/src/generates/internal/SdkAliasCollection.ts +260 -261
  121. package/src/generates/internal/SdkFileProgrammer.ts +110 -110
  122. package/src/generates/internal/SdkHttpCloneProgrammer.ts +126 -124
  123. package/src/generates/internal/SdkHttpCloneReferencer.ts +77 -77
  124. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +278 -279
  125. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +502 -500
  126. package/src/generates/internal/SdkHttpRouteProgrammer.ts +109 -108
  127. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +312 -310
  128. package/src/generates/internal/SdkImportWizard.ts +62 -62
  129. package/src/generates/internal/SdkTypeProgrammer.ts +388 -385
  130. package/src/generates/internal/SdkTypeTagProgrammer.ts +114 -104
  131. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +379 -381
  132. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +302 -302
  133. package/src/generates/internal/SwaggerOperationComposer.ts +119 -119
  134. package/src/generates/internal/SwaggerOperationParameterComposer.ts +161 -162
  135. package/src/generates/internal/SwaggerOperationResponseComposer.ts +110 -110
  136. package/src/module.ts +4 -3
  137. package/src/structures/IReflectHttpOperationException.ts +18 -19
  138. package/src/structures/IReflectHttpOperationParameter.ts +79 -77
  139. package/src/structures/IReflectHttpOperationSuccess.ts +21 -22
  140. package/src/structures/ITypedApplication.ts +11 -11
  141. package/src/structures/ITypedHttpRouteException.ts +15 -15
  142. package/src/structures/ITypedHttpRouteParameter.ts +41 -41
  143. package/src/structures/ITypedHttpRouteSuccess.ts +22 -22
  144. package/src/transformers/IOperationMetadata.ts +46 -44
  145. package/src/transformers/ISdkOperationTransformerContext.ts +8 -8
  146. package/src/transformers/SdkOperationProgrammer.ts +240 -238
  147. package/src/transformers/SdkOperationTransformer.ts +248 -252
  148. package/src/transformers/TextPlainValidator.ts +17 -17
  149. package/src/utils/MetadataUtil.ts +26 -26
  150. package/src/validators/HttpHeadersValidator.ts +36 -34
  151. 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 { IPointer } from "tstl";
2
- import ts from "typescript";
3
- import { IJsDocTagInfo } from "typia";
4
- import { MetadataAliasType } from "typia/lib/schemas/metadata/MetadataAliasType";
5
- import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
6
- import { MetadataObjectType } from "typia/lib/schemas/metadata/MetadataObjectType";
7
-
8
- import { INestiaProject } from "../../structures/INestiaProject";
9
- import { ITypedApplication } from "../../structures/ITypedApplication";
10
- import { MapUtil } from "../../utils/MapUtil";
11
- import { StringUtil } from "../../utils/StringUtil";
12
- import { FilePrinter } from "./FilePrinter";
13
- import { ImportDictionary } from "./ImportDictionary";
14
- import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
15
-
16
- export namespace SdkHttpCloneProgrammer {
17
- export interface IModule {
18
- name: string;
19
- children: Map<string, IModule>;
20
- programmer:
21
- | null
22
- | ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
23
- }
24
-
25
- export const write = (app: ITypedApplication): Map<string, IModule> => {
26
- // COMPOSE THE DICTIONARY
27
- const dict: Map<string, IModule> = new Map();
28
- for (const [k, v] of app.collection.objects.entries())
29
- if (StringUtil.isImplicit(k) === false)
30
- prepare({
31
- dict,
32
- name: k,
33
- programmer: (importer) => writeObject(app.project)(importer)(v),
34
- });
35
- for (const [k, v] of app.collection.aliases.entries())
36
- if (StringUtil.isImplicit(k) === false)
37
- prepare({
38
- dict,
39
- name: k,
40
- programmer: (importer) => writeAlias(app.project)(importer)(v),
41
- });
42
- return dict;
43
- };
44
-
45
- const prepare = (props: {
46
- dict: Map<string, IModule>;
47
- name: string;
48
- programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration;
49
- }) => {
50
- let next: Map<string, IModule> = props.dict;
51
- const accessors: string[] = props.name.split(".");
52
- const modulo: IPointer<IModule> = { value: null! };
53
-
54
- accessors.forEach((acc, i) => {
55
- modulo.value = MapUtil.take(next, acc, () => ({
56
- name: acc,
57
- children: new Map(),
58
- programmer: null,
59
- }));
60
- if (i === accessors.length - 1)
61
- modulo.value.programmer = props.programmer;
62
- next = modulo.value.children;
63
- });
64
- return modulo!;
65
- };
66
-
67
- const writeAlias =
68
- (project: INestiaProject) =>
69
- (importer: ImportDictionary) =>
70
- (alias: MetadataAliasType): ts.TypeAliasDeclaration =>
71
- FilePrinter.description(
72
- ts.factory.createTypeAliasDeclaration(
73
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
74
- alias.name.split(".").at(-1)!,
75
- [],
76
- SdkTypeProgrammer.write(project)(importer)(alias.value),
77
- ),
78
- writeComment([])(alias.description, alias.jsDocTags),
79
- );
80
-
81
- const writeObject =
82
- (project: INestiaProject) =>
83
- (importer: ImportDictionary) =>
84
- (object: MetadataObjectType): ts.TypeAliasDeclaration => {
85
- return FilePrinter.description(
86
- ts.factory.createTypeAliasDeclaration(
87
- [ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
88
- object.name.split(".").at(-1)!,
89
- [],
90
- SdkTypeProgrammer.write_object(project)(importer)(object),
91
- ),
92
- writeComment([])(object.description ?? null, object.jsDocTags),
93
- );
94
- };
95
- }
96
-
97
- const writeComment =
98
- (atomics: MetadataAtomic[]) =>
99
- (description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
100
- const lines: string[] = [];
101
- if (description?.length)
102
- lines.push(...description.split("\n").map((s) => `${s}`));
103
-
104
- const filtered: IJsDocTagInfo[] =
105
- !!atomics.length && !!jsDocTags?.length
106
- ? jsDocTags.filter(
107
- (tag) =>
108
- !atomics.some((a) =>
109
- a.tags.some((r) => r.some((t) => t.kind === tag.name)),
110
- ),
111
- )
112
- : (jsDocTags ?? []);
113
-
114
- if (description?.length && filtered.length) lines.push("");
115
- if (filtered.length)
116
- lines.push(
117
- ...filtered.map((t) =>
118
- t.text?.length
119
- ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
120
- : `@${t.name}`,
121
- ),
122
- );
123
- return lines.join("\n");
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 { Metadata } from "typia/lib/schemas/metadata/Metadata";
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: 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(", ")}>`;