@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,204 +1,208 @@
1
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
2
- import { IMetadata } from "typia/lib/schemas/metadata/IMetadata";
3
- import { IMetadataComponents } from "typia/lib/schemas/metadata/IMetadataComponents";
4
- import { IMetadataDictionary } from "typia/lib/schemas/metadata/IMetadataDictionary";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
- import { MetadataComponents } from "typia/lib/schemas/metadata/MetadataComponents";
7
- import { MetadataObjectType } from "typia/lib/schemas/metadata/MetadataObjectType";
8
- import { Escaper } from "typia/lib/utils/Escaper";
9
-
10
- import { IReflectController } from "../structures/IReflectController";
11
- import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
12
- import { IReflectOperationError } from "../structures/IReflectOperationError";
13
- import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
14
- import { ITypedHttpRouteException } from "../structures/ITypedHttpRouteException";
15
- import { ITypedHttpRouteParameter } from "../structures/ITypedHttpRouteParameter";
16
- import { ITypedHttpRouteSuccess } from "../structures/ITypedHttpRouteSuccess";
17
- import { PathUtil } from "../utils/PathUtil";
18
-
19
- export namespace TypedHttpRouteAnalyzer {
20
- export const dictionary = (
21
- controllers: IReflectController[],
22
- ): IMetadataDictionary => {
23
- const individual: IMetadataComponents[] = [];
24
- for (const c of controllers)
25
- for (const o of c.operations) {
26
- if (o.protocol !== "http") continue;
27
- if (o.success) individual.push(o.success.components);
28
- for (const p of o.parameters) individual.push(p.components);
29
- for (const e of Object.values(o.exceptions))
30
- individual.push(e.components);
31
- }
32
- const components: MetadataComponents = MetadataComponents.from({
33
- objects: Object.values(
34
- Object.fromEntries(
35
- individual.map((c) => c.objects.map((o) => [o.name, o])).flat(),
36
- ),
37
- ),
38
- arrays: Object.values(
39
- Object.fromEntries(
40
- individual.map((c) => c.arrays.map((a) => [a.name, a])).flat(),
41
- ),
42
- ),
43
- tuples: Object.values(
44
- Object.fromEntries(
45
- individual.map((c) => c.tuples.map((t) => [t.name, t])).flat(),
46
- ),
47
- ),
48
- aliases: Object.values(
49
- Object.fromEntries(
50
- individual.map((c) => c.aliases.map((a) => [a.name, a])).flat(),
51
- ),
52
- ),
53
- });
54
- return components.dictionary;
55
- };
56
-
57
- export const analyze = (props: {
58
- controller: IReflectController;
59
- errors: IReflectOperationError[];
60
- dictionary: IMetadataDictionary;
61
- operation: IReflectHttpOperation;
62
- paths: string[];
63
- }): ITypedHttpRoute[] => {
64
- const errors: IReflectOperationError[] = [];
65
- const cast = (
66
- next: {
67
- metadata: IMetadata;
68
- validate: MetadataFactory.Validator;
69
- },
70
- from: string,
71
- escape: boolean,
72
- ): Metadata => {
73
- const metadata: Metadata = Metadata.from(next.metadata, props.dictionary);
74
- const metaErrors: MetadataFactory.IError[] = MetadataFactory.validate({
75
- options: {
76
- escape,
77
- constant: true,
78
- absorb: true,
79
- validate: next.validate, // @todo -> CHECK IN TYPIA
80
- },
81
- functor: next.validate, // @todo -> CHECK IN TYPIA
82
- metadata,
83
- });
84
- if (metaErrors.length)
85
- errors.push({
86
- file: props.controller.file,
87
- class: props.controller.class.name,
88
- function: props.operation.name,
89
- from,
90
- contents: metaErrors.map((e) => ({
91
- name: e.name,
92
- accessor:
93
- e.explore.object !== null
94
- ? join({
95
- object: e.explore.object,
96
- key: e.explore.property,
97
- })
98
- : null,
99
- messages: e.messages,
100
- })),
101
- });
102
- return metadata;
103
- };
104
- const exceptions: Record<
105
- number | "2XX" | "3XX" | "4XX" | "5XX",
106
- ITypedHttpRouteException
107
- > = Object.fromEntries(
108
- Object.entries(props.operation.exceptions).map(([key, value]) => [
109
- key as any,
110
- {
111
- status: value.status,
112
- description: value.description,
113
- example: value.example,
114
- examples: value.examples,
115
- type: value.type,
116
- metadata: cast(value, `exception (status: ${key})`, true),
117
- },
118
- ]),
119
- );
120
- const parameters: ITypedHttpRouteParameter[] =
121
- props.operation.parameters.map((p) => ({
122
- ...p,
123
- metadata: cast(
124
- p,
125
- `parameter (name: ${JSON.stringify(p.name)})`,
126
- p.category === "body" &&
127
- (p.contentType === "application/json" || p.encrypted === true),
128
- ),
129
- }));
130
- const success: ITypedHttpRouteSuccess = {
131
- ...props.operation.success,
132
- metadata: cast(
133
- props.operation.success,
134
- "success",
135
- props.operation.success.encrypted ||
136
- props.operation.success.contentType === "application/json",
137
- ),
138
- setHeaders: props.operation.jsDocTags
139
- .filter(
140
- (t) =>
141
- t.text?.length &&
142
- t.text[0].text &&
143
- (t.name === "setHeader" || t.name === "assignHeaders"),
144
- )
145
- .map((t) =>
146
- t.name === "setHeader"
147
- ? {
148
- type: "setter",
149
- source: t.text![0].text.split(" ")[0].trim(),
150
- target: t.text![0].text.split(" ")[1]?.trim(),
151
- }
152
- : {
153
- type: "assigner",
154
- source: t.text![0].text,
155
- },
156
- ),
157
- };
158
- if (errors.length) {
159
- props.errors.push(...errors);
160
- return [];
161
- }
162
- return props.paths.map(
163
- (path) =>
164
- ({
165
- ...props.operation,
166
- controller: props.controller,
167
- path,
168
- accessor: [...PathUtil.accessors(path), props.operation.name],
169
- exceptions,
170
- pathParameters: parameters.filter((p) => p.category === "param"),
171
- queryParameters: parameters
172
- .filter((p) => p.category === "query")
173
- .filter((p) => p.field !== null),
174
- headerParameters: parameters
175
- .filter((p) => p.category === "headers")
176
- .filter((p) => p.field !== null),
177
- queryObject:
178
- parameters
179
- .filter((p) => p.category === "query")
180
- .filter((p) => p.field === null)[0] ?? null,
181
- body: parameters.filter((p) => p.category === "body")[0] ?? null,
182
- headerObject:
183
- parameters
184
- .filter((p) => p.category === "headers")
185
- .filter((p) => p.field === null)[0] ?? null,
186
- success,
187
- extensions: props.operation.extensions,
188
- }) satisfies ITypedHttpRoute,
189
- );
190
- };
191
- }
192
-
193
- const join = ({
194
- object,
195
- key,
196
- }: {
197
- object: MetadataObjectType;
198
- key: string | object | null;
199
- }) => {
200
- if (key === null) return object.name;
201
- else if (typeof key === "object") return `${object.name}[key]`;
202
- else if (Escaper.variable(key)) return `${object.name}.${key}`;
203
- return `${object.name}[${JSON.stringify(key)}]`;
204
- };
1
+ import {
2
+ IMetadataDictionary,
3
+ MetadataComponents,
4
+ MetadataFactory,
5
+ MetadataObjectType,
6
+ MetadataSchema,
7
+ } from "@typia/core";
8
+ import { NamingConvention } from "@typia/utils";
9
+ import { IMetadataComponents, IMetadataSchema } from "typia";
10
+
11
+ import { IReflectController } from "../structures/IReflectController";
12
+ import { IReflectHttpOperation } from "../structures/IReflectHttpOperation";
13
+ import { IReflectOperationError } from "../structures/IReflectOperationError";
14
+ import { ITypedHttpRoute } from "../structures/ITypedHttpRoute";
15
+ import { ITypedHttpRouteException } from "../structures/ITypedHttpRouteException";
16
+ import { ITypedHttpRouteParameter } from "../structures/ITypedHttpRouteParameter";
17
+ import { ITypedHttpRouteSuccess } from "../structures/ITypedHttpRouteSuccess";
18
+ import { PathUtil } from "../utils/PathUtil";
19
+
20
+ export namespace TypedHttpRouteAnalyzer {
21
+ export const dictionary = (
22
+ controllers: IReflectController[],
23
+ ): IMetadataDictionary => {
24
+ const individual: IMetadataComponents[] = [];
25
+ for (const c of controllers)
26
+ for (const o of c.operations) {
27
+ if (o.protocol !== "http") continue;
28
+ if (o.success) individual.push(o.success.components);
29
+ for (const p of o.parameters) individual.push(p.components);
30
+ for (const e of Object.values(o.exceptions))
31
+ individual.push(e.components);
32
+ }
33
+ const components: MetadataComponents = MetadataComponents.from({
34
+ objects: Object.values(
35
+ Object.fromEntries(
36
+ individual.map((c) => c.objects.map((o) => [o.name, o])).flat(),
37
+ ),
38
+ ),
39
+ arrays: Object.values(
40
+ Object.fromEntries(
41
+ individual.map((c) => c.arrays.map((a) => [a.name, a])).flat(),
42
+ ),
43
+ ),
44
+ tuples: Object.values(
45
+ Object.fromEntries(
46
+ individual.map((c) => c.tuples.map((t) => [t.name, t])).flat(),
47
+ ),
48
+ ),
49
+ aliases: Object.values(
50
+ Object.fromEntries(
51
+ individual.map((c) => c.aliases.map((a) => [a.name, a])).flat(),
52
+ ),
53
+ ),
54
+ });
55
+ return components.dictionary;
56
+ };
57
+
58
+ export const analyze = (props: {
59
+ controller: IReflectController;
60
+ errors: IReflectOperationError[];
61
+ dictionary: IMetadataDictionary;
62
+ operation: IReflectHttpOperation;
63
+ paths: string[];
64
+ }): ITypedHttpRoute[] => {
65
+ const errors: IReflectOperationError[] = [];
66
+ const cast = (
67
+ next: {
68
+ metadata: IMetadataSchema;
69
+ validate: MetadataFactory.Validator;
70
+ },
71
+ from: string,
72
+ escape: boolean,
73
+ ): MetadataSchema => {
74
+ const metadata: MetadataSchema = MetadataSchema.from(
75
+ next.metadata,
76
+ props.dictionary,
77
+ );
78
+ const metaErrors: MetadataFactory.IError[] = MetadataFactory.validate({
79
+ options: {
80
+ escape,
81
+ constant: true,
82
+ absorb: true,
83
+ validate: next.validate, // @todo -> CHECK IN TYPIA
84
+ },
85
+ functor: next.validate, // @todo -> CHECK IN TYPIA
86
+ metadata,
87
+ });
88
+ if (metaErrors.length)
89
+ errors.push({
90
+ file: props.controller.file,
91
+ class: props.controller.class.name,
92
+ function: props.operation.name,
93
+ from,
94
+ contents: metaErrors.map((e) => ({
95
+ name: e.name,
96
+ accessor:
97
+ e.explore.object !== null
98
+ ? join({
99
+ object: e.explore.object,
100
+ key: e.explore.property,
101
+ })
102
+ : null,
103
+ messages: e.messages,
104
+ })),
105
+ });
106
+ return metadata;
107
+ };
108
+ const exceptions: Record<
109
+ number | "2XX" | "3XX" | "4XX" | "5XX",
110
+ ITypedHttpRouteException
111
+ > = Object.fromEntries(
112
+ Object.entries(props.operation.exceptions).map(([key, value]) => [
113
+ key as any,
114
+ {
115
+ status: value.status,
116
+ description: value.description,
117
+ example: value.example,
118
+ examples: value.examples,
119
+ type: value.type,
120
+ metadata: cast(value, `exception (status: ${key})`, true),
121
+ },
122
+ ]),
123
+ );
124
+ const parameters: ITypedHttpRouteParameter[] =
125
+ props.operation.parameters.map((p) => ({
126
+ ...p,
127
+ metadata: cast(
128
+ p,
129
+ `parameter (name: ${JSON.stringify(p.name)})`,
130
+ p.category === "body" &&
131
+ (p.contentType === "application/json" || p.encrypted === true),
132
+ ),
133
+ }));
134
+ const success: ITypedHttpRouteSuccess = {
135
+ ...props.operation.success,
136
+ metadata: cast(
137
+ props.operation.success,
138
+ "success",
139
+ props.operation.success.encrypted ||
140
+ props.operation.success.contentType === "application/json",
141
+ ),
142
+ setHeaders: props.operation.jsDocTags
143
+ .filter(
144
+ (t) =>
145
+ t.text?.length &&
146
+ t.text[0]!.text &&
147
+ (t.name === "setHeader" || t.name === "assignHeaders"),
148
+ )
149
+ .map((t) =>
150
+ t.name === "setHeader"
151
+ ? {
152
+ type: "setter",
153
+ source: t.text![0]!.text.split(" ")[0]!.trim(),
154
+ target: t.text![0]!.text.split(" ")[1]?.trim(),
155
+ }
156
+ : {
157
+ type: "assigner",
158
+ source: t.text![0]!.text,
159
+ },
160
+ ),
161
+ };
162
+ if (errors.length) {
163
+ props.errors.push(...errors);
164
+ return [];
165
+ }
166
+ return props.paths.map(
167
+ (path) =>
168
+ ({
169
+ ...props.operation,
170
+ controller: props.controller,
171
+ path,
172
+ accessor: [...PathUtil.accessors(path), props.operation.name],
173
+ exceptions,
174
+ pathParameters: parameters.filter((p) => p.category === "param"),
175
+ queryParameters: parameters
176
+ .filter((p) => p.category === "query")
177
+ .filter((p) => p.field !== null),
178
+ headerParameters: parameters
179
+ .filter((p) => p.category === "headers")
180
+ .filter((p) => p.field !== null),
181
+ queryObject:
182
+ parameters
183
+ .filter((p) => p.category === "query")
184
+ .filter((p) => p.field === null)[0] ?? null,
185
+ body: parameters.filter((p) => p.category === "body")[0] ?? null,
186
+ headerObject:
187
+ parameters
188
+ .filter((p) => p.category === "headers")
189
+ .filter((p) => p.field === null)[0] ?? null,
190
+ success,
191
+ extensions: props.operation.extensions,
192
+ }) satisfies ITypedHttpRoute,
193
+ );
194
+ };
195
+ }
196
+
197
+ const join = ({
198
+ object,
199
+ key,
200
+ }: {
201
+ object: MetadataObjectType;
202
+ key: string | object | null;
203
+ }) => {
204
+ if (key === null) return object.name;
205
+ else if (typeof key === "object") return `${object.name}[key]`;
206
+ else if (NamingConvention.variable(key)) return `${object.name}.${key}`;
207
+ return `${object.name}[${JSON.stringify(key)}]`;
208
+ };
@@ -1,78 +1,85 @@
1
- import { NoTransformConfigurationError } from "@nestia/core/lib/decorators/NoTransformConfigurationError";
2
- import fs from "fs";
3
- import path from "path";
4
- import { register } from "ts-node";
5
- import { parse } from "tsconfck";
6
- import ts from "typescript";
7
- import typia from "typia";
8
-
9
- import { INestiaConfig } from "../../INestiaConfig";
10
-
11
- export namespace NestiaConfigLoader {
12
- export const compilerOptions = async (
13
- project: string,
14
- ): Promise<ts.ParsedCommandLine> => {
15
- const configFileName = ts.findConfigFile(
16
- process.cwd(),
17
- ts.sys.fileExists,
18
- project,
19
- );
20
- if (!configFileName) throw new Error(`unable to find "${project}" file.`);
21
- const { tsconfig } = await parse(configFileName);
22
- const configFileText = JSON.stringify(tsconfig);
23
- const { config } = ts.parseConfigFileTextToJson(
24
- configFileName,
25
- configFileText,
26
- );
27
- return ts.parseJsonConfigFileContent(
28
- config,
29
- ts.sys,
30
- path.dirname(configFileName),
31
- );
32
- };
33
-
34
- export const configurations = async (
35
- file: string,
36
- compilerOptions: Record<string, any>,
37
- ): Promise<INestiaConfig[]> => {
38
- if (fs.existsSync(path.resolve(file)) === false)
39
- throw new Error(`Unable to find "${file}" file.`);
40
-
41
- NoTransformConfigurationError.throws = false;
42
- const plugins: any[] = [
43
- ...typia
44
- .assert<object[]>(compilerOptions.plugins ?? [])
45
- .filter((x: any) => x.transform !== "@nestia/sdk/lib/transform"),
46
- { transform: "@nestia/sdk/lib/transform" },
47
- ];
48
- register({
49
- emit: false,
50
- compilerOptions: {
51
- ...compilerOptions,
52
- plugins,
53
- },
54
- require: compilerOptions.baseUrl
55
- ? ["tsconfig-paths/register"]
56
- : undefined,
57
- });
58
-
59
- const loaded: (INestiaConfig | INestiaConfig[]) & {
60
- default?: INestiaConfig | INestiaConfig[];
61
- } = await import(path.resolve(file));
62
- const instance: INestiaConfig | INestiaConfig[] =
63
- typeof loaded?.default === "object" && loaded.default !== null
64
- ? loaded.default
65
- : loaded;
66
- const configurations: INestiaConfig[] = Array.isArray(instance)
67
- ? instance
68
- : [instance];
69
-
70
- try {
71
- return typia.assert(configurations);
72
- } catch (exp) {
73
- if (typia.is<typia.TypeGuardError>(exp))
74
- exp.message = `invalid "${file}" data.`;
75
- throw exp;
76
- }
77
- };
78
- }
1
+ import { NoTransformConfigurationError } from "@nestia/core";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { register } from "ts-node";
5
+ import { parse } from "tsconfck";
6
+ import ts from "typescript";
7
+ import typia from "typia";
8
+
9
+ import { INestiaConfig } from "../../INestiaConfig";
10
+
11
+ export namespace NestiaConfigLoader {
12
+ export const compilerOptions = async (
13
+ project: string,
14
+ ): Promise<ts.ParsedCommandLine> => {
15
+ const configFileName = ts.findConfigFile(
16
+ process.cwd(),
17
+ ts.sys.fileExists,
18
+ project,
19
+ );
20
+ if (!configFileName) throw new Error(`unable to find "${project}" file.`);
21
+ const { tsconfig } = await parse(configFileName);
22
+ const configFileText = JSON.stringify(tsconfig);
23
+ const { config } = ts.parseConfigFileTextToJson(
24
+ configFileName,
25
+ configFileText,
26
+ );
27
+ return ts.parseJsonConfigFileContent(
28
+ config,
29
+ ts.sys,
30
+ path.dirname(configFileName),
31
+ );
32
+ };
33
+
34
+ export const configurations = async (
35
+ file: string,
36
+ compilerOptions: Record<string, any>,
37
+ ): Promise<INestiaConfig[]> => {
38
+ if (fs.existsSync(path.resolve(file)) === false)
39
+ throw new Error(`Unable to find "${file}" file.`);
40
+
41
+ NoTransformConfigurationError.throws = false;
42
+
43
+ const setup: boolean = typia
44
+ .assert<object[]>(compilerOptions.plugins ?? [])
45
+ .some(
46
+ (x: any) =>
47
+ x.transform === "@nestia/sdk/lib/transform" ||
48
+ x.transform === "@nestia/sdk/src/transform.ts",
49
+ );
50
+ const plugins: any[] = [
51
+ ...(compilerOptions.plugins ?? []),
52
+ ...(setup ? [{ transform: "@nestia/sdk/lib/transform" }] : []),
53
+ ];
54
+ if (!(process as any)[Symbol.for("ts-node.register.instance")])
55
+ register({
56
+ emit: false,
57
+ compilerOptions: {
58
+ ...compilerOptions,
59
+ plugins,
60
+ },
61
+ require: compilerOptions.baseUrl
62
+ ? ["tsconfig-paths/register"]
63
+ : undefined,
64
+ });
65
+
66
+ const loaded: (INestiaConfig | INestiaConfig[]) & {
67
+ default?: INestiaConfig | INestiaConfig[];
68
+ } = await import(path.resolve(file));
69
+ const instance: INestiaConfig | INestiaConfig[] =
70
+ typeof loaded?.default === "object" && loaded.default !== null
71
+ ? loaded.default
72
+ : loaded;
73
+ const configurations: INestiaConfig[] = Array.isArray(instance)
74
+ ? instance
75
+ : [instance];
76
+
77
+ try {
78
+ return typia.assert(configurations);
79
+ } catch (exp) {
80
+ if (typia.is<typia.TypeGuardError>(exp))
81
+ exp.message = `invalid "${file}" data.`;
82
+ throw exp;
83
+ }
84
+ };
85
+ }