@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,126 +1,126 @@
1
- import { SwaggerExample } from "@nestia/core";
2
- import {
3
- HEADERS_METADATA,
4
- HTTP_CODE_METADATA,
5
- INTERCEPTORS_METADATA,
6
- } from "@nestjs/common/constants";
7
- import { HttpQueryProgrammer, JsonMetadataFactory } from "@typia/core";
8
- import typia from "typia";
9
-
10
- import { IReflectController } from "../structures/IReflectController";
11
- import { IReflectHttpOperationSuccess } from "../structures/IReflectHttpOperationSuccess";
12
- import { IReflectOperationError } from "../structures/IReflectOperationError";
13
- import { IOperationMetadata } from "../transformers/IOperationMetadata";
14
- import { TextPlainValidator } from "../transformers/TextPlainValidator";
15
-
16
- export namespace ReflectHttpOperationResponseAnalyzer {
17
- export interface IContext {
18
- controller: IReflectController;
19
- function: Function;
20
- functionName: string;
21
- httpMethod: string;
22
- metadata: IOperationMetadata;
23
- errors: IReflectOperationError[];
24
- }
25
-
26
- export const analyze = (
27
- ctx: IContext,
28
- ): IReflectHttpOperationSuccess | null => {
29
- const errors: Array<string | IOperationMetadata.IError> = [];
30
- const report = () => {
31
- ctx.errors.push({
32
- file: ctx.controller.file,
33
- class: ctx.controller.class.name,
34
- function: ctx.functionName,
35
- from: "return",
36
- contents: errors,
37
- });
38
- return null;
39
- };
40
-
41
- const encrypted: boolean = hasInterceptor({
42
- name: "EncryptedRouteInterceptor",
43
- function: ctx.function,
44
- });
45
- const contentType: string | null = encrypted
46
- ? "text/plain"
47
- : hasInterceptor({
48
- name: "TypedQueryRouteInterceptor",
49
- function: ctx.function,
50
- })
51
- ? "application/x-www-form-urlencoded"
52
- : (Reflect.getMetadata(HEADERS_METADATA, ctx.function)?.find(
53
- (h: Record<string, string>) =>
54
- typeof h?.name === "string" &&
55
- typeof h?.value === "string" &&
56
- h.name.toLowerCase() === "content-type",
57
- )?.value ??
58
- Reflect.getMetadata("swagger/apiProduces", ctx.function)?.[0] ??
59
- (ctx.httpMethod === "HEAD" ? null : "application/json"));
60
-
61
- const schema =
62
- contentType === "application/json"
63
- ? ctx.metadata.success.primitive
64
- : ctx.metadata.success.resolved;
65
- if (schema.success === false) errors.push(...schema.errors);
66
- if (ctx.httpMethod === "HEAD" && contentType !== null)
67
- errors.push(`HEAD method must not have a content type.`);
68
- if (
69
- typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType) ===
70
- false
71
- )
72
- errors.push(
73
- `@nestia/sdk does not support ${JSON.stringify(contentType)} content type.`,
74
- );
75
-
76
- if (errors.length) return report();
77
- else if (
78
- ctx.metadata.success.type === null ||
79
- schema.success === false ||
80
- !typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType)
81
- )
82
- return null;
83
-
84
- const example: SwaggerExample.IData<any> | undefined = Reflect.getMetadata(
85
- "nestia/SwaggerExample/Response",
86
- ctx.function,
87
- );
88
- return {
89
- contentType,
90
- encrypted,
91
- status:
92
- getStatus(ctx.function) ?? (ctx.httpMethod === "POST" ? 201 : 200),
93
- type: ctx.metadata.success.type,
94
- ...schema.data,
95
- validate:
96
- contentType === "application/json" || encrypted === true
97
- ? JsonMetadataFactory.validate
98
- : contentType === "application/x-www-form-urlencoded"
99
- ? HttpQueryProgrammer.validate
100
- : contentType === "text/plain"
101
- ? TextPlainValidator.validate
102
- : (next) =>
103
- next.metadata.size() !== 0
104
- ? ["HEAD method must not have any return value."]
105
- : [],
106
- example: example?.example,
107
- examples: example?.examples,
108
- };
109
- };
110
-
111
- const getStatus = (func: Function): number | null => {
112
- const text = Reflect.getMetadata(HTTP_CODE_METADATA, func);
113
- if (text === undefined) return null;
114
- const value: number = Number(text);
115
- return isNaN(value) ? null : value;
116
- };
117
-
118
- const hasInterceptor = (props: {
119
- name: string;
120
- function: Function;
121
- }): boolean => {
122
- const meta = Reflect.getMetadata(INTERCEPTORS_METADATA, props.function);
123
- if (Array.isArray(meta) === false) return false;
124
- return meta.some((elem) => elem?.constructor?.name === props.name);
125
- };
126
- }
1
+ import { SwaggerExample } from "@nestia/core";
2
+ import {
3
+ HEADERS_METADATA,
4
+ HTTP_CODE_METADATA,
5
+ INTERCEPTORS_METADATA,
6
+ } from "@nestjs/common/constants";
7
+ import { HttpQueryProgrammer, JsonMetadataFactory } from "@typia/core";
8
+ import typia from "typia";
9
+
10
+ import { IReflectController } from "../structures/IReflectController";
11
+ import { IReflectHttpOperationSuccess } from "../structures/IReflectHttpOperationSuccess";
12
+ import { IReflectOperationError } from "../structures/IReflectOperationError";
13
+ import { IOperationMetadata } from "../transformers/IOperationMetadata";
14
+ import { TextPlainValidator } from "../transformers/TextPlainValidator";
15
+
16
+ export namespace ReflectHttpOperationResponseAnalyzer {
17
+ export interface IContext {
18
+ controller: IReflectController;
19
+ function: Function;
20
+ functionName: string;
21
+ httpMethod: string;
22
+ metadata: IOperationMetadata;
23
+ errors: IReflectOperationError[];
24
+ }
25
+
26
+ export const analyze = (
27
+ ctx: IContext,
28
+ ): IReflectHttpOperationSuccess | null => {
29
+ const errors: Array<string | IOperationMetadata.IError> = [];
30
+ const report = () => {
31
+ ctx.errors.push({
32
+ file: ctx.controller.file,
33
+ class: ctx.controller.class.name,
34
+ function: ctx.functionName,
35
+ from: "return",
36
+ contents: errors,
37
+ });
38
+ return null;
39
+ };
40
+
41
+ const encrypted: boolean = hasInterceptor({
42
+ name: "EncryptedRouteInterceptor",
43
+ function: ctx.function,
44
+ });
45
+ const contentType: string | null = encrypted
46
+ ? "text/plain"
47
+ : hasInterceptor({
48
+ name: "TypedQueryRouteInterceptor",
49
+ function: ctx.function,
50
+ })
51
+ ? "application/x-www-form-urlencoded"
52
+ : (Reflect.getMetadata(HEADERS_METADATA, ctx.function)?.find(
53
+ (h: Record<string, string>) =>
54
+ typeof h?.name === "string" &&
55
+ typeof h?.value === "string" &&
56
+ h.name.toLowerCase() === "content-type",
57
+ )?.value ??
58
+ Reflect.getMetadata("swagger/apiProduces", ctx.function)?.[0] ??
59
+ (ctx.httpMethod === "HEAD" ? null : "application/json"));
60
+
61
+ const schema =
62
+ contentType === "application/json"
63
+ ? ctx.metadata.success.primitive
64
+ : ctx.metadata.success.resolved;
65
+ if (schema.success === false) errors.push(...schema.errors);
66
+ if (ctx.httpMethod === "HEAD" && contentType !== null)
67
+ errors.push(`HEAD method must not have a content type.`);
68
+ if (
69
+ typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType) ===
70
+ false
71
+ )
72
+ errors.push(
73
+ `@nestia/sdk does not support ${JSON.stringify(contentType)} content type.`,
74
+ );
75
+
76
+ if (errors.length) return report();
77
+ else if (
78
+ ctx.metadata.success.type === null ||
79
+ schema.success === false ||
80
+ !typia.is<IReflectHttpOperationSuccess["contentType"]>(contentType)
81
+ )
82
+ return null;
83
+
84
+ const example: SwaggerExample.IData<any> | undefined = Reflect.getMetadata(
85
+ "nestia/SwaggerExample/Response",
86
+ ctx.function,
87
+ );
88
+ return {
89
+ contentType,
90
+ encrypted,
91
+ status:
92
+ getStatus(ctx.function) ?? (ctx.httpMethod === "POST" ? 201 : 200),
93
+ type: ctx.metadata.success.type,
94
+ ...schema.data,
95
+ validate:
96
+ contentType === "application/json" || encrypted === true
97
+ ? JsonMetadataFactory.validate
98
+ : contentType === "application/x-www-form-urlencoded"
99
+ ? HttpQueryProgrammer.validate
100
+ : contentType === "text/plain"
101
+ ? TextPlainValidator.validate
102
+ : (next) =>
103
+ next.metadata.size() !== 0
104
+ ? ["HEAD method must not have any return value."]
105
+ : [],
106
+ example: example?.example,
107
+ examples: example?.examples,
108
+ };
109
+ };
110
+
111
+ const getStatus = (func: Function): number | null => {
112
+ const text = Reflect.getMetadata(HTTP_CODE_METADATA, func);
113
+ if (text === undefined) return null;
114
+ const value: number = Number(text);
115
+ return isNaN(value) ? null : value;
116
+ };
117
+
118
+ const hasInterceptor = (props: {
119
+ name: string;
120
+ function: Function;
121
+ }): boolean => {
122
+ const meta = Reflect.getMetadata(INTERCEPTORS_METADATA, props.function);
123
+ if (Array.isArray(meta) === false) return false;
124
+ return meta.some((elem) => elem?.constructor?.name === props.name);
125
+ };
126
+ }
@@ -1,208 +1,208 @@
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
+ 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
+ };