@nestia/sdk 3.0.0-dev.20231209 → 3.0.0-dev.20240412

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 (168) hide show
  1. package/README.md +12 -9
  2. package/assets/config/nestia.config.ts +82 -79
  3. package/lib/INestiaConfig.d.ts +28 -6
  4. package/lib/NestiaSdkApplication.js +12 -10
  5. package/lib/NestiaSdkApplication.js.map +1 -1
  6. package/lib/analyses/ConfigAnalyzer.js +1 -1
  7. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  8. package/lib/analyses/ControllerAnalyzer.js +30 -15
  9. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  10. package/lib/analyses/ExceptionAnalyzer.js +35 -6
  11. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +1 -2
  13. package/lib/analyses/ImportAnalyzer.js +2 -2
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/PathAnalyzer.d.ts +2 -4
  16. package/lib/analyses/PathAnalyzer.js +27 -11
  17. package/lib/analyses/PathAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectAnalyzer.js +34 -22
  19. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  20. package/lib/analyses/SecurityAnalyzer.js +13 -8
  21. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  22. package/lib/executable/internal/NestiaConfigLoader.js +300 -220
  23. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  24. package/lib/executable/sdk.js +11 -11
  25. package/lib/generates/CloneGenerator.d.ts +6 -0
  26. package/lib/generates/CloneGenerator.js +62 -0
  27. package/lib/generates/CloneGenerator.js.map +1 -0
  28. package/lib/generates/E2eGenerator.d.ts +2 -1
  29. package/lib/generates/E2eGenerator.js +2 -2
  30. package/lib/generates/E2eGenerator.js.map +1 -1
  31. package/lib/generates/SdkGenerator.js +3 -11
  32. package/lib/generates/SdkGenerator.js.map +1 -1
  33. package/lib/generates/SwaggerGenerator.d.ts +2 -0
  34. package/lib/generates/SwaggerGenerator.js +119 -62
  35. package/lib/generates/SwaggerGenerator.js.map +1 -1
  36. package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
  37. package/lib/generates/internal/E2eFileProgrammer.js +49 -53
  38. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  39. package/lib/generates/internal/FilePrinter.d.ts +10 -0
  40. package/lib/generates/internal/FilePrinter.js +46 -0
  41. package/lib/generates/internal/FilePrinter.js.map +1 -0
  42. package/lib/{utils → generates/internal}/ImportDictionary.d.ts +2 -1
  43. package/lib/{utils → generates/internal}/ImportDictionary.js +20 -14
  44. package/lib/generates/internal/ImportDictionary.js.map +1 -0
  45. package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
  46. package/lib/generates/internal/SdkAliasCollection.js +97 -0
  47. package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
  48. package/lib/generates/internal/SdkCloneProgrammer.d.ts +12 -0
  49. package/lib/generates/internal/SdkCloneProgrammer.js +99 -0
  50. package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -0
  51. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
  52. package/lib/generates/internal/SdkFileProgrammer.js +27 -28
  53. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  54. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +7 -2
  55. package/lib/generates/internal/SdkFunctionProgrammer.js +115 -322
  56. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  57. package/lib/generates/internal/SdkImportWizard.d.ts +1 -1
  58. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
  59. package/lib/generates/internal/SdkNamespaceProgrammer.js +180 -0
  60. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
  61. package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
  62. package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
  63. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
  64. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +8 -2
  65. package/lib/generates/internal/SdkSimulationProgrammer.js +103 -89
  66. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  67. package/lib/generates/internal/SdkTypeProgrammer.d.ts +9 -0
  68. package/lib/generates/internal/SdkTypeProgrammer.js +228 -0
  69. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
  70. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +4 -4
  71. package/lib/generates/internal/SwaggerSchemaGenerator.js +30 -28
  72. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  73. package/lib/structures/IController.d.ts +4 -2
  74. package/lib/structures/IRoute.d.ts +5 -4
  75. package/lib/structures/ISwaggerLazyProperty.d.ts +2 -2
  76. package/lib/structures/ISwaggerLazySchema.d.ts +2 -2
  77. package/lib/structures/ParamCategory.d.ts +1 -1
  78. package/lib/structures/TypeEntry.js +2 -2
  79. package/lib/structures/TypeEntry.js.map +1 -1
  80. package/lib/utils/StringUtil.d.ts +3 -0
  81. package/lib/utils/StringUtil.js +8 -0
  82. package/lib/utils/StringUtil.js.map +1 -0
  83. package/package.json +12 -16
  84. package/src/INestiaConfig.ts +30 -6
  85. package/src/NestiaSdkApplication.ts +255 -253
  86. package/src/analyses/AccessorAnalyzer.ts +60 -60
  87. package/src/analyses/ConfigAnalyzer.ts +147 -147
  88. package/src/analyses/ControllerAnalyzer.ts +42 -19
  89. package/src/analyses/ExceptionAnalyzer.ts +148 -115
  90. package/src/analyses/GenericAnalyzer.ts +51 -51
  91. package/src/analyses/ImportAnalyzer.ts +1 -2
  92. package/src/analyses/PathAnalyzer.ts +110 -98
  93. package/src/analyses/ReflectAnalyzer.ts +39 -35
  94. package/src/analyses/SecurityAnalyzer.ts +24 -20
  95. package/src/executable/internal/CommandParser.ts +15 -15
  96. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  97. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  98. package/src/executable/sdk.ts +73 -73
  99. package/src/generates/CloneGenerator.ts +62 -0
  100. package/src/generates/E2eGenerator.ts +66 -64
  101. package/src/generates/SdkGenerator.ts +84 -96
  102. package/src/generates/SwaggerGenerator.ts +145 -53
  103. package/src/generates/internal/E2eFileProgrammer.ts +182 -123
  104. package/src/generates/internal/FilePrinter.ts +53 -0
  105. package/src/{utils → generates/internal}/ImportDictionary.ts +35 -13
  106. package/src/generates/internal/SdkAliasCollection.ts +152 -0
  107. package/src/generates/internal/SdkCloneProgrammer.ts +155 -0
  108. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  109. package/src/generates/internal/SdkFileProgrammer.ts +115 -106
  110. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -518
  111. package/src/generates/internal/SdkImportWizard.ts +55 -55
  112. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -0
  113. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  114. package/src/generates/internal/SdkRouteProgrammer.ts +83 -0
  115. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -133
  116. package/src/generates/internal/SdkTypeProgrammer.ts +386 -0
  117. package/src/generates/internal/SwaggerSchemaGenerator.ts +437 -427
  118. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  119. package/src/index.ts +4 -4
  120. package/src/module.ts +2 -2
  121. package/src/structures/IController.ts +94 -95
  122. package/src/structures/IErrorReport.ts +6 -6
  123. package/src/structures/INestiaProject.ts +13 -13
  124. package/src/structures/INormalizedInput.ts +20 -20
  125. package/src/structures/IRoute.ts +53 -53
  126. package/src/structures/ISwaggerLazyProperty.ts +2 -2
  127. package/src/structures/ISwaggerLazySchema.ts +2 -2
  128. package/src/structures/ITypeTuple.ts +6 -6
  129. package/src/structures/MethodType.ts +5 -5
  130. package/src/structures/ParamCategory.ts +1 -1
  131. package/src/structures/TypeEntry.ts +1 -1
  132. package/src/utils/ArrayUtil.ts +26 -26
  133. package/src/utils/FileRetriever.ts +22 -22
  134. package/src/utils/MapUtil.ts +14 -14
  135. package/src/utils/PathUtil.ts +10 -10
  136. package/src/utils/SourceFinder.ts +66 -66
  137. package/src/utils/StringUtil.ts +6 -0
  138. package/src/utils/StripEnums.ts +5 -5
  139. package/assets/bundle/api/utils/NestiaSimulator.ts +0 -70
  140. package/lib/generates/internal/SdkDtoGenerator.d.ts +0 -9
  141. package/lib/generates/internal/SdkDtoGenerator.js +0 -294
  142. package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
  143. package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
  144. package/lib/generates/internal/SdkTypeDefiner.js +0 -82
  145. package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
  146. package/lib/structures/ISwagger.d.ts +0 -72
  147. package/lib/structures/ISwagger.js +0 -3
  148. package/lib/structures/ISwagger.js.map +0 -1
  149. package/lib/structures/ISwaggerComponents.d.ts +0 -26
  150. package/lib/structures/ISwaggerComponents.js +0 -3
  151. package/lib/structures/ISwaggerComponents.js.map +0 -1
  152. package/lib/structures/ISwaggerInfo.d.ts +0 -71
  153. package/lib/structures/ISwaggerInfo.js +0 -3
  154. package/lib/structures/ISwaggerInfo.js.map +0 -1
  155. package/lib/structures/ISwaggerRoute.d.ts +0 -47
  156. package/lib/structures/ISwaggerRoute.js +0 -3
  157. package/lib/structures/ISwaggerRoute.js.map +0 -1
  158. package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -56
  159. package/lib/structures/ISwaggerSecurityScheme.js +0 -3
  160. package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
  161. package/lib/utils/ImportDictionary.js.map +0 -1
  162. package/src/generates/internal/SdkDtoGenerator.ts +0 -424
  163. package/src/generates/internal/SdkTypeDefiner.ts +0 -119
  164. package/src/structures/ISwagger.ts +0 -91
  165. package/src/structures/ISwaggerComponents.ts +0 -29
  166. package/src/structures/ISwaggerInfo.ts +0 -80
  167. package/src/structures/ISwaggerRoute.ts +0 -51
  168. package/src/structures/ISwaggerSecurityScheme.ts +0 -65
@@ -1,47 +0,0 @@
1
- import { IJsonSchema } from "typia";
2
- import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
3
- export interface ISwaggerRoute {
4
- deprecated?: boolean;
5
- security?: Record<string, string[]>[];
6
- operationId?: string;
7
- tags: string[];
8
- parameters: ISwaggerRoute.IParameter[];
9
- requestBody?: ISwaggerRoute.IRequestBody;
10
- responses: ISwaggerRoute.IResponseBody;
11
- summary?: string;
12
- description?: string;
13
- "x-nestia-method": string;
14
- "x-nestia-namespace": string;
15
- "x-nestia-jsDocTags"?: IJsDocTagInfo[];
16
- }
17
- export declare namespace ISwaggerRoute {
18
- interface IParameter {
19
- name: string;
20
- in: string;
21
- schema: IJsonSchema;
22
- required: boolean;
23
- description?: string;
24
- }
25
- interface IRequestBody {
26
- description?: string;
27
- content: IContent;
28
- required: true;
29
- "x-nestia-encrypted": boolean;
30
- }
31
- type IResponseBody = Record<string, {
32
- description: string;
33
- content?: IContent;
34
- "x-nestia-encrypted"?: boolean;
35
- }>;
36
- interface IContent {
37
- "application/x-www-form-urlencoded"?: {
38
- schema: IJsonSchema;
39
- };
40
- "application/json"?: {
41
- schema: IJsonSchema;
42
- };
43
- "text/plain"?: {
44
- schema: IJsonSchema;
45
- };
46
- }
47
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ISwaggerRoute.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ISwaggerRoute.js","sourceRoot":"","sources":["../../src/structures/ISwaggerRoute.ts"],"names":[],"mappings":""}
@@ -1,56 +0,0 @@
1
- /**
2
- * Security scheme of Swagger Documents.
3
- *
4
- * `ISwaggerSecurityScheme` is a data structure representing content of
5
- * `securitySchemes` in `swagger.json` file. It is composed with 5 types of security
6
- * schemes as an union type like below.
7
- *
8
- * @reference https://swagger.io/specification/#security-scheme-object
9
- * @author Jeongho Nam - https://github.com/samchon
10
- */
11
- export type ISwaggerSecurityScheme = ISwaggerSecurityScheme.IHttpBasic | ISwaggerSecurityScheme.IHttpBearer | ISwaggerSecurityScheme.IApiKey | ISwaggerSecurityScheme.IOpenId | ISwaggerSecurityScheme.IOAuth2;
12
- export declare namespace ISwaggerSecurityScheme {
13
- interface IHttpBasic {
14
- type: "http";
15
- scheme: "basic";
16
- }
17
- interface IHttpBearer {
18
- type: "http";
19
- scheme: "bearer";
20
- bearerFormat?: string;
21
- }
22
- interface IApiKey {
23
- type: "apiKey";
24
- /**
25
- * @default header
26
- */
27
- in?: "header" | "query" | "cookie";
28
- /**
29
- * @default Authorization
30
- */
31
- name?: string;
32
- }
33
- interface IOpenId {
34
- type: "openIdConnect";
35
- openIdConnectUrl: string;
36
- }
37
- interface IOAuth2 {
38
- type: "oauth2";
39
- flows: IOAuth2.IFlowSet;
40
- description?: string;
41
- }
42
- namespace IOAuth2 {
43
- interface IFlowSet {
44
- authorizationCode?: IFlow;
45
- implicit?: Omit<IFlow, "tokenUrl">;
46
- password?: Omit<IFlow, "authorizationUrl">;
47
- clientCredentials?: Omit<IFlow, "authorizationUrl">;
48
- }
49
- interface IFlow {
50
- authorizationUrl: string;
51
- tokenUrl: string;
52
- refreshUrl: string;
53
- scopes?: Record<string, string>;
54
- }
55
- }
56
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ISwaggerSecurityScheme.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ISwaggerSecurityScheme.js","sourceRoot":"","sources":["../../src/structures/ISwaggerSecurityScheme.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;AAEzC,MAAa,gBAAgB;IAI3B,YAAmC,IAAY;QAAZ,S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AAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UACnD,CAAC,CAAC,QACJ,IAAI,CACL,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;QAEJ,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5D,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAE5D,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1D,OAAO,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;CACF;AAhGD,4CAgGC;AAuBD,MAAM,YAAY,GAAG,eAAe,CAAC"}
@@ -1,424 +0,0 @@
1
- import fs from "fs";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
6
- import { IMetadataTypeTag } from "typia/lib/schemas/metadata/IMetadataTypeTag";
7
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
8
- import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
9
- import { MetadataArray } from "typia/lib/schemas/metadata/MetadataArray";
10
- import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
11
- import { MetadataConstant } from "typia/lib/schemas/metadata/MetadataConstant";
12
- import { MetadataEscaped } from "typia/lib/schemas/metadata/MetadataEscaped";
13
- import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
14
- import { MetadataProperty } from "typia/lib/schemas/metadata/MetadataProperty";
15
- import { MetadataTuple } from "typia/lib/schemas/metadata/MetadataTuple";
16
- import { Escaper } from "typia/lib/utils/Escaper";
17
-
18
- import { INestiaConfig } from "../../INestiaConfig";
19
- import { IRoute } from "../../structures/IRoute";
20
- import { ImportDictionary } from "../../utils/ImportDictionary";
21
- import { MapUtil } from "../../utils/MapUtil";
22
-
23
- export namespace SdkDtoGenerator {
24
- export const generate =
25
- (checker: ts.TypeChecker) =>
26
- (config: INestiaConfig) =>
27
- async (routes: IRoute[]): Promise<void> => {
28
- try {
29
- await fs.promises.mkdir(`${config.output}/structures`);
30
- } catch {}
31
-
32
- const collection = new MetadataCollection({
33
- replace: MetadataCollection.replace,
34
- });
35
- for (const r of routes) {
36
- for (const p of r.parameters) {
37
- const res = MetadataFactory.analyze(checker)({
38
- escape: false,
39
- constant: true,
40
- absorb: false,
41
- })(collection)(p.type);
42
- if (res.success) p.metadata = res.data;
43
- }
44
- for (const e of Object.values(r.exceptions)) {
45
- const res = MetadataFactory.analyze(checker)({
46
- escape: true,
47
- constant: true,
48
- absorb: false,
49
- })(collection)(e.type);
50
- if (res.success) e.metadata = res.data;
51
- }
52
- const res = MetadataFactory.analyze(checker)({
53
- escape: true,
54
- constant: true,
55
- absorb: false,
56
- })(collection)(r.output.type);
57
- if (res.success) r.output.metadata = res.data;
58
- }
59
-
60
- const modules: Map<string, IModule> = new Map();
61
- for (const alias of collection.aliases())
62
- prepare(modules)(alias.name)((importer) =>
63
- defineAlias(config)(importer)(alias),
64
- );
65
- for (const object of collection.objects())
66
- prepare(modules)(object.name)((importer) =>
67
- defineObject(config)(importer)(object),
68
- );
69
-
70
- for (const module of modules.values()) await generateFile(config)(module);
71
- };
72
-
73
- const prepare =
74
- (dict: Map<string, IModule>) =>
75
- (name: string) =>
76
- (programmer: (importer: ImportDictionary) => string) => {
77
- const accessors: string[] = name.split(".");
78
- let module: IModule;
79
-
80
- accessors.forEach((acc, i) => {
81
- module = MapUtil.take(dict, acc, () => ({
82
- name: accessors.slice(0, i + 1).join("."),
83
- children: new Map(),
84
- }));
85
- if (i === accessors.length - 1) module.programmer = programmer;
86
- dict = module.children;
87
- });
88
- return module!;
89
- };
90
-
91
- const generateFile =
92
- (config: INestiaConfig) =>
93
- async (module: IModule): Promise<void> => {
94
- const importer: ImportDictionary = new ImportDictionary(
95
- `${config.output}/structures/${module.name}.ts`,
96
- );
97
-
98
- const body: string = writeModule(importer)(module);
99
- const content: string[] = [];
100
- if (!importer.empty())
101
- content.push(importer.toScript(`${config.output}/structures`), "");
102
- content.push(body);
103
-
104
- await fs.promises.writeFile(importer.file, content.join("\n"), "utf8");
105
- };
106
-
107
- const writeModule =
108
- (importer: ImportDictionary) =>
109
- (module: IModule): string => {
110
- const content: string[] = [];
111
- if (module.programmer) content.push(module.programmer(importer));
112
- if (module.children.size) {
113
- content.push(`export namespace ${module.name.split(".").at(-1)} {`);
114
- for (const child of module.children.values())
115
- content.push(
116
- writeModule(importer)(child)
117
- .split("\n")
118
- .map((l) => ` ${l}`)
119
- .join("\n"),
120
- );
121
- content.push("}");
122
- }
123
- return content.join("\n");
124
- };
125
-
126
- const defineAlias =
127
- (config: INestiaConfig) =>
128
- (importer: ImportDictionary) =>
129
- (alias: MetadataAlias) =>
130
- [
131
- ...writeComment(alias.value.atomics)(
132
- alias.description,
133
- alias.jsDocTags,
134
- ),
135
- `export type ${alias.name.split(".").at(-1)} = ${decode(config)(
136
- importer,
137
- )(alias.value)};`,
138
- ].join("\n");
139
-
140
- const defineObject =
141
- (config: INestiaConfig) =>
142
- (importer: ImportDictionary) =>
143
- (object: MetadataObject) => {
144
- const top: string = [
145
- ...writeComment([])(object.description ?? null, object.jsDocTags),
146
- `export type ${object.name.split(".").at(-1)} = `,
147
- ].join("\n");
148
- if (object.properties.length === 0) return top + "{};";
149
-
150
- const regular: MetadataProperty[] = object.properties.filter((p) =>
151
- p.key.isSoleLiteral(),
152
- );
153
- const dynamic: MetadataProperty[] = object.properties.filter(
154
- (p) => !p.key.isSoleLiteral(),
155
- );
156
-
157
- const brackets: string[][] = [];
158
- if (regular.length) {
159
- const row: string[] = ["{"];
160
- for (const p of regular) {
161
- const key: string = p.key.constants[0].values[0] as string;
162
- const identifier: string = Escaper.variable(key)
163
- ? key
164
- : JSON.stringify(key);
165
- row.push(
166
- ...writeComment(p.value.atomics)(p.description, p.jsDocTags).map(
167
- (l) => ` ${l}`,
168
- ),
169
- ` ${identifier}${
170
- p.value.isRequired() === false ? "?" : ""
171
- }: ${decode(config)(importer)(p.value)};`,
172
- );
173
- }
174
- row.push("}");
175
- brackets.push(row);
176
- }
177
- for (const p of dynamic) {
178
- const row: string[] = ["{"];
179
- row.push(
180
- ...writeComment(p.value.atomics)(p.description, p.jsDocTags).map(
181
- (l) => ` ${l}`,
182
- ),
183
- ` [key: ${decode(config)(importer)(p.key)}]: ${decode(config)(
184
- importer,
185
- )(p.value)};`,
186
- );
187
- row.push("}");
188
- brackets.push(row);
189
- }
190
- return top + brackets.map((row) => row.join("\n")).join(" & ");
191
- };
192
-
193
- const writeComment =
194
- (atomics: MetadataAtomic[]) =>
195
- (description: string | null, jsDocTags: IJsDocTagInfo[]): string[] => {
196
- const lines: string[] = [];
197
- if (description?.length)
198
- lines.push(...description.split("\n").map((s) => `${s}`));
199
-
200
- const filtered: IJsDocTagInfo[] =
201
- !!atomics.length && !!jsDocTags?.length
202
- ? jsDocTags.filter(
203
- (tag) =>
204
- !atomics.some((a) =>
205
- a.tags.some((r) => r.some((t) => t.kind === tag.name)),
206
- ),
207
- )
208
- : jsDocTags ?? [];
209
-
210
- if (description?.length && filtered.length) lines.push("");
211
- if (filtered.length)
212
- lines.push(
213
- ...filtered.map((t) =>
214
- t.text?.length
215
- ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
216
- : `@${t.name}`,
217
- ),
218
- );
219
- if (lines.length === 0) return [];
220
- return ["/**", ...lines.map((s) => ` * ${s}`), " */"];
221
- };
222
-
223
- export const decode =
224
- (config: INestiaConfig) =>
225
- (importer: ImportDictionary) =>
226
- (meta: Metadata, parentEscaped: boolean = false): string => {
227
- const union: string[] = [];
228
-
229
- // COALESCES
230
- if (meta.any) union.push("any");
231
- if (meta.nullable) union.push("null");
232
- if (meta.isRequired() === false) union.push("undefined");
233
- if (parentEscaped === false && meta.escaped)
234
- union.push(decodeEscaped(config)(importer)(meta.escaped));
235
-
236
- // ATOMICS
237
- for (const atomic of meta.atomics)
238
- union.push(decodeAtomic(importer)(atomic));
239
- for (const constant of meta.constants)
240
- union.push(decodeConstant(constant));
241
- for (const tpl of meta.templates)
242
- union.push(decodeTemplate(config)(importer)(tpl));
243
-
244
- // ARRAYS
245
- for (const array of meta.arrays)
246
- union.push(decodeArray(config)(importer)(array));
247
- for (const tuple of meta.tuples)
248
- union.push(decodeTuple(config)(importer)(tuple));
249
-
250
- // OBJECTS
251
- for (const obj of meta.objects)
252
- union.push(decodeObject(config)(importer)(obj));
253
- for (const alias of meta.aliases)
254
- union.push(decodeAlias(config)(importer)(alias));
255
-
256
- // NATIVES
257
- for (const native of meta.natives) union.push(native);
258
- for (const set of meta.sets)
259
- union.push(`Set<${decode(config)(importer)(set)}>`);
260
- for (const map of meta.maps)
261
- union.push(
262
- `Map<${decode(config)(importer)(map.key)}, ${decode(config)(importer)(
263
- map.value,
264
- )}>`,
265
- );
266
- return union.join(" | ");
267
- };
268
-
269
- const decodeEscaped =
270
- (config: INestiaConfig) =>
271
- (importer: ImportDictionary) =>
272
- (escaped: MetadataEscaped) => {
273
- if (
274
- escaped.original.size() === 1 &&
275
- escaped.original.natives.length === 1 &&
276
- escaped.original.natives[0] === "Date"
277
- )
278
- return `(string & ${importer.external({
279
- type: true,
280
- library: `typia/lib/tags/Format`,
281
- instance: "Format",
282
- })}<"date-time">)`;
283
- return `(${decode(config)(importer)(escaped.returns, true)})`;
284
- };
285
-
286
- const decodeTypeTag =
287
- (importer: ImportDictionary) =>
288
- (tag: IMetadataTypeTag): string => {
289
- const front: string = tag.name.split("<")[0];
290
- if (NATIVE_TYPE_TAGS.has(front)) {
291
- importer.external({
292
- type: true,
293
- library: `typia/lib/tags/${front}`,
294
- instance: front,
295
- });
296
- return tag.name;
297
- }
298
- importer.external({
299
- type: true,
300
- library: `typia/lib/tags/TagBase`,
301
- instance: "TagBase",
302
- });
303
- return `TagBase<${JSON.stringify(tag)}>`;
304
- };
305
-
306
- const decodeTypeTagMatrix =
307
- (importer: ImportDictionary) =>
308
- (base: string, tags: IMetadataTypeTag[][]): string => {
309
- if (tags.length === 0) return base;
310
- else if (tags.length === 1)
311
- return `(${base} & ${tags[0]
312
- .map((t) => decodeTypeTag(importer)(t))
313
- .join(" & ")})`;
314
- return (
315
- "(" +
316
- [
317
- base,
318
- ...tags.map(
319
- (row) =>
320
- `(${row.map((t) => decodeTypeTag(importer)(t)).join(" & ")})`,
321
- ),
322
- ] +
323
- ")"
324
- );
325
- };
326
-
327
- const decodeAtomic =
328
- (importer: ImportDictionary) =>
329
- (atomic: MetadataAtomic): string =>
330
- decodeTypeTagMatrix(importer)(atomic.type, atomic.tags);
331
-
332
- const decodeTemplate =
333
- (config: INestiaConfig) =>
334
- (importer: ImportDictionary) =>
335
- (template: Metadata[]): string =>
336
- "`" +
337
- template
338
- .map((meta) =>
339
- meta.size() === 1 &&
340
- meta.isRequired() &&
341
- meta.nullable === false &&
342
- meta.constants.length === 1
343
- ? String(meta.constants[0].values[0]).split("`").join("\\`")
344
- : `\${${decode(config)(importer)(meta)}}`,
345
- )
346
- .join("") +
347
- "`";
348
-
349
- const decodeConstant = (constant: MetadataConstant): string => {
350
- if (constant.values.length === 0) return JSON.stringify(constant.values[0]);
351
- return `(${constant.values.map((val) => JSON.stringify(val)).join(" | ")})`;
352
- };
353
-
354
- const decodeArray =
355
- (config: INestiaConfig) =>
356
- (importer: ImportDictionary) =>
357
- (array: MetadataArray): string =>
358
- decodeTypeTagMatrix(importer)(
359
- `Array<${decode(config)(importer)(array.type.value)}>`,
360
- array.tags,
361
- );
362
-
363
- const decodeTuple =
364
- (config: INestiaConfig) =>
365
- (importer: ImportDictionary) =>
366
- (tuple: MetadataTuple): string =>
367
- "[" +
368
- tuple.type.elements.map((e) =>
369
- e.rest
370
- ? `...${decode(config)(importer)(e.rest)}[]`
371
- : decode(config)(importer)(e),
372
- ) +
373
- "]";
374
-
375
- const decodeAlias =
376
- (config: INestiaConfig) =>
377
- (importer: ImportDictionary) =>
378
- (alias: MetadataAlias) => {
379
- importInternalFile(config)(importer)(alias.name);
380
- return alias.name;
381
- };
382
-
383
- const decodeObject =
384
- (config: INestiaConfig) =>
385
- (importer: ImportDictionary) =>
386
- (object: MetadataObject) => {
387
- importInternalFile(config)(importer)(object.name);
388
- return object.name;
389
- };
390
-
391
- const importInternalFile =
392
- (config: INestiaConfig) =>
393
- (importer: ImportDictionary) =>
394
- (name: string) => {
395
- const top = name.split(".")[0];
396
- if (importer.file === `${config.output}/structures/${top}.ts`) return;
397
- importer.internal({
398
- type: true,
399
- file: `${config.output}/structures/${name.split(".")[0]}`,
400
- instance: top,
401
- });
402
- };
403
- }
404
-
405
- const NATIVE_TYPE_TAGS = new Set([
406
- "ExclusiveMinimum",
407
- "ExclusiveMaximum",
408
- "Format",
409
- "Maximum",
410
- "MaxItems",
411
- "MaxLength",
412
- "Minimum",
413
- "MinItems",
414
- "MinLength",
415
- "MultipleOf",
416
- "Pattern",
417
- "Type",
418
- ]);
419
-
420
- interface IModule {
421
- name: string;
422
- children: Map<string, IModule>;
423
- programmer?: (importer: ImportDictionary) => string;
424
- }
@@ -1,119 +0,0 @@
1
- import { INestiaConfig } from "../../INestiaConfig";
2
- import { IRoute } from "../../structures/IRoute";
3
- import { ImportDictionary } from "../../utils/ImportDictionary";
4
- import { SdkDtoGenerator } from "./SdkDtoGenerator";
5
-
6
- export namespace SdkTypeDefiner {
7
- export const name =
8
- (config: INestiaConfig) =>
9
- (importer: ImportDictionary) =>
10
- (p: IRoute.IParameter | IRoute.IOutput): string =>
11
- p.metadata
12
- ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
13
- : p.typeName;
14
-
15
- export const headers =
16
- (config: INestiaConfig) =>
17
- (importer: ImportDictionary) =>
18
- (param: IRoute.IParameter): string => {
19
- const type: string = name(config)(importer)(param);
20
- if (config.primitive === false) return type;
21
-
22
- const resolved: string = importer.external({
23
- type: true,
24
- library: "@nestia/fetcher",
25
- instance: "Resolved",
26
- });
27
- return `${resolved}<${type}>`;
28
- };
29
-
30
- export const query =
31
- (config: INestiaConfig) =>
32
- (importer: ImportDictionary) =>
33
- (param: IRoute.IParameter): string => {
34
- const type: string = name(config)(importer)(param);
35
- if (config.primitive === false) return type;
36
-
37
- const resolved: string = importer.external({
38
- type: true,
39
- library: "@nestia/fetcher",
40
- instance: "Resolved",
41
- });
42
- return `${resolved}<${type}>`;
43
- };
44
-
45
- export const input =
46
- (config: INestiaConfig) =>
47
- (importer: ImportDictionary) =>
48
- (param: IRoute.IParameter): string => {
49
- const type: string = name(config)(importer)(param);
50
- if (config.primitive === false) return type;
51
-
52
- const primitive: string = importer.external({
53
- type: true,
54
- library: "@nestia/fetcher",
55
- instance: "Primitive",
56
- });
57
- return `${primitive}<${type}>`;
58
- };
59
-
60
- export const output =
61
- (config: INestiaConfig) =>
62
- (importer: ImportDictionary) =>
63
- (route: IRoute): string => {
64
- if (config.propagate !== true) {
65
- const type: string = name(config)(importer)(route.output);
66
- if (type === "void" || config.primitive === false) return type;
67
-
68
- const wrapper: string = importer.external({
69
- type: true,
70
- library: "@nestia/fetcher",
71
- instance:
72
- route.output.contentType === "application/x-www-form-urlencoded"
73
- ? "Resolved"
74
- : "Primitive",
75
- });
76
- return `${wrapper}<${type}>`;
77
- }
78
-
79
- const propagation: string = importer.external({
80
- type: true,
81
- library: "@nestia/fetcher",
82
- instance: "IPropagation",
83
- });
84
- const branches: IBranch[] = [
85
- {
86
- status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
87
- type: name(config)(importer)(route.output),
88
- },
89
- ...Object.entries(route.exceptions).map(([status, value]) => ({
90
- status,
91
- type: name(config)(importer)(value),
92
- })),
93
- ];
94
- return (
95
- `${propagation}<{\n` +
96
- branches
97
- .map(
98
- (b) =>
99
- ` ${
100
- b.status.endsWith("XX") ? `"${b.status}"` : b.status
101
- }: ${b.type};`,
102
- )
103
- .join("\n") +
104
- "\n" +
105
- ` }${route.status ? `, ${route.status}` : ""}>`
106
- );
107
- };
108
-
109
- export const responseBody =
110
- (config: INestiaConfig) =>
111
- (importer: ImportDictionary) =>
112
- (route: IRoute): string =>
113
- output({ ...config, propagate: false })(importer)(route);
114
- }
115
-
116
- interface IBranch {
117
- status: string;
118
- type: string;
119
- }