@nestia/sdk 2.5.0-dev.20240130 → 2.5.0-dev.20240130-2

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.
@@ -1,86 +1,86 @@
1
- import ts from "typescript";
2
- import { IJsDocTagInfo } from "typia";
3
-
4
- import { INestiaConfig } from "../../INestiaConfig";
5
- import { IRoute } from "../../structures/IRoute";
6
- import { FormatUtil } from "../../utils/FormatUtil";
7
- import { ImportDictionary } from "../../utils/ImportDictionary";
8
- import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
9
- import { SdkNamespaceProgrammer } from "./SdkNamespaceProgrammer";
10
-
11
- export namespace SdkRouteProgrammer {
12
- export const generate =
13
- (checker: ts.TypeChecker) =>
14
- (config: INestiaConfig) =>
15
- (importer: ImportDictionary) =>
16
- (route: IRoute): ts.Statement[] => {
17
- const props = {
18
- headers: route.parameters.find(
19
- (p) => p.category === "headers" && p.field === undefined,
20
- ),
21
- query: route.parameters.find(
22
- (p) => p.category === "query" && p.field === undefined,
23
- ),
24
- input: route.parameters.find((p) => p.category === "body"),
25
- };
26
- return [
27
- FormatUtil.description(
28
- SdkFunctionProgrammer.generate(config)(importer)(route, props),
29
- describe(route),
30
- ),
31
- SdkNamespaceProgrammer.generate(checker)(config)(importer)(
32
- route,
33
- props,
34
- ),
35
- ];
36
- };
37
-
38
- const describe = (route: IRoute): string => {
39
- // MAIN DESCRIPTION
40
- const comments: string[] = route.description
41
- ? route.description.split("\n")
42
- : [];
43
-
44
- // COMMENT TAGS
45
- const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
46
- (tag) =>
47
- tag.name !== "param" ||
48
- route.parameters
49
- .filter((p) => p.category !== "headers")
50
- .some((p) => p.name === tag.text?.[0]?.text),
51
- );
52
- if (tags.length !== 0) {
53
- const content: string[] = tags.map((t) =>
54
- t.text?.length
55
- ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
56
- : `@${t.name}`,
57
- );
58
- comments.push("", ...new Set(content));
59
- }
60
-
61
- // EXCEPTIONS
62
- for (const [key, value] of Object.entries(route.exceptions)) {
63
- if (
64
- comments.some(
65
- (str) =>
66
- str.startsWith(`@throw ${key}`) || str.startsWith(`@throws ${key}`),
67
- )
68
- )
69
- continue;
70
- comments.push(
71
- value.description?.length
72
- ? `@throws ${key} ${value.description.split("\n")[0]}`
73
- : `@throws ${key}`,
74
- );
75
- }
76
-
77
- // POSTFIX
78
- if (!!comments.length) comments.push("");
79
- comments.push(
80
- `@controller ${route.symbol.class}.${route.symbol.function}`,
81
- `@path ${route.method} ${route.path}`,
82
- `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
83
- );
84
- return comments.join("\n");
85
- };
86
- }
1
+ import ts from "typescript";
2
+ import { IJsDocTagInfo } from "typia";
3
+
4
+ import { INestiaConfig } from "../../INestiaConfig";
5
+ import { IRoute } from "../../structures/IRoute";
6
+ import { FormatUtil } from "../../utils/FormatUtil";
7
+ import { ImportDictionary } from "../../utils/ImportDictionary";
8
+ import { SdkFunctionProgrammer } from "./SdkFunctionProgrammer";
9
+ import { SdkNamespaceProgrammer } from "./SdkNamespaceProgrammer";
10
+
11
+ export namespace SdkRouteProgrammer {
12
+ export const generate =
13
+ (checker: ts.TypeChecker) =>
14
+ (config: INestiaConfig) =>
15
+ (importer: ImportDictionary) =>
16
+ (route: IRoute): ts.Statement[] => {
17
+ const props = {
18
+ headers: route.parameters.find(
19
+ (p) => p.category === "headers" && p.field === undefined,
20
+ ),
21
+ query: route.parameters.find(
22
+ (p) => p.category === "query" && p.field === undefined,
23
+ ),
24
+ input: route.parameters.find((p) => p.category === "body"),
25
+ };
26
+ return [
27
+ FormatUtil.description(
28
+ SdkFunctionProgrammer.generate(config)(importer)(route, props),
29
+ describe(route),
30
+ ),
31
+ SdkNamespaceProgrammer.generate(checker)(config)(importer)(
32
+ route,
33
+ props,
34
+ ),
35
+ ];
36
+ };
37
+
38
+ const describe = (route: IRoute): string => {
39
+ // MAIN DESCRIPTION
40
+ const comments: string[] = route.description
41
+ ? route.description.split("\n")
42
+ : [];
43
+
44
+ // COMMENT TAGS
45
+ const tags: IJsDocTagInfo[] = route.jsDocTags.filter(
46
+ (tag) =>
47
+ tag.name !== "param" ||
48
+ route.parameters
49
+ .filter((p) => p.category !== "headers")
50
+ .some((p) => p.name === tag.text?.[0]?.text),
51
+ );
52
+ if (tags.length !== 0) {
53
+ const content: string[] = tags.map((t) =>
54
+ t.text?.length
55
+ ? `@${t.name} ${t.text.map((e) => e.text).join("")}`
56
+ : `@${t.name}`,
57
+ );
58
+ comments.push("", ...new Set(content));
59
+ }
60
+
61
+ // EXCEPTIONS
62
+ for (const [key, value] of Object.entries(route.exceptions)) {
63
+ if (
64
+ comments.some(
65
+ (str) =>
66
+ str.startsWith(`@throw ${key}`) || str.startsWith(`@throws ${key}`),
67
+ )
68
+ )
69
+ continue;
70
+ comments.push(
71
+ value.description?.length
72
+ ? `@throws ${key} ${value.description.split("\n")[0]}`
73
+ : `@throws ${key}`,
74
+ );
75
+ }
76
+
77
+ // POSTFIX
78
+ if (!!comments.length) comments.push("");
79
+ comments.push(
80
+ `@controller ${route.symbol.class}.${route.symbol.function}`,
81
+ `@path ${route.method} ${route.path}`,
82
+ `@nestia Generated by Nestia - https://github.com/samchon/nestia`,
83
+ );
84
+ return comments.join("\n");
85
+ };
86
+ }