@nestia/sdk 2.6.2 → 2.6.3
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.
- package/lib/analyses/ControllerAnalyzer.js +3 -3
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ImportAnalyzer.d.ts +1 -2
- package/lib/analyses/ImportAnalyzer.js +2 -2
- package/lib/analyses/ImportAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +2 -2
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/generates/SwaggerGenerator.js +4 -4
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/ImportDictionary.js +6 -8
- package/lib/generates/internal/ImportDictionary.js.map +1 -1
- package/lib/structures/TypeEntry.js +2 -2
- package/lib/structures/TypeEntry.js.map +1 -1
- package/package.json +4 -4
- package/src/INestiaConfig.ts +248 -248
- package/src/NestiaSdkApplication.ts +255 -255
- package/src/analyses/ControllerAnalyzer.ts +402 -402
- package/src/analyses/ExceptionAnalyzer.ts +148 -148
- package/src/analyses/ImportAnalyzer.ts +1 -2
- package/src/analyses/ReflectAnalyzer.ts +463 -463
- package/src/analyses/SecurityAnalyzer.ts +24 -24
- package/src/generates/CloneGenerator.ts +62 -62
- package/src/generates/E2eGenerator.ts +66 -66
- package/src/generates/SdkGenerator.ts +84 -84
- package/src/generates/SwaggerGenerator.ts +446 -446
- package/src/generates/internal/E2eFileProgrammer.ts +182 -182
- package/src/generates/internal/FilePrinter.ts +53 -53
- package/src/generates/internal/ImportDictionary.ts +147 -149
- package/src/generates/internal/SdkAliasCollection.ts +152 -152
- package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
- package/src/generates/internal/SdkFileProgrammer.ts +115 -115
- package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
- package/src/generates/internal/SdkImportWizard.ts +55 -55
- package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
- package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
- package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
- package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
- package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
- package/src/structures/IController.ts +94 -94
- package/src/structures/IRoute.ts +53 -53
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerRoute.ts +54 -54
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/structures/ParamCategory.ts +1 -1
- package/src/structures/TypeEntry.ts +1 -1
- package/src/utils/StringUtil.ts +6 -6
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
import { IPointer } from "tstl";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
import { IJsDocTagInfo } from "typia";
|
|
4
|
-
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
5
|
-
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
6
|
-
import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
|
|
7
|
-
import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
|
|
8
|
-
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
9
|
-
|
|
10
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
11
|
-
import { IRoute } from "../../structures/IRoute";
|
|
12
|
-
import { MapUtil } from "../../utils/MapUtil";
|
|
13
|
-
import { FilePrinter } from "./FilePrinter";
|
|
14
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
15
|
-
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
16
|
-
|
|
17
|
-
export namespace SdkCloneProgrammer {
|
|
18
|
-
export interface IModule {
|
|
19
|
-
name: string;
|
|
20
|
-
children: Map<string, IModule>;
|
|
21
|
-
programmer:
|
|
22
|
-
| null
|
|
23
|
-
| ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const write =
|
|
27
|
-
(checker: ts.TypeChecker) =>
|
|
28
|
-
(config: INestiaConfig) =>
|
|
29
|
-
(routes: IRoute[]): Map<string, IModule> => {
|
|
30
|
-
const collection = new MetadataCollection({
|
|
31
|
-
replace: MetadataCollection.replace,
|
|
32
|
-
});
|
|
33
|
-
for (const r of routes) {
|
|
34
|
-
for (const p of r.parameters) {
|
|
35
|
-
const res = MetadataFactory.analyze(checker)({
|
|
36
|
-
escape: false,
|
|
37
|
-
constant: true,
|
|
38
|
-
absorb: false,
|
|
39
|
-
})(collection)(p.type);
|
|
40
|
-
if (res.success) p.metadata = res.data;
|
|
41
|
-
}
|
|
42
|
-
for (const e of Object.values(r.exceptions)) {
|
|
43
|
-
const res = MetadataFactory.analyze(checker)({
|
|
44
|
-
escape: true,
|
|
45
|
-
constant: true,
|
|
46
|
-
absorb: false,
|
|
47
|
-
})(collection)(e.type);
|
|
48
|
-
if (res.success) e.metadata = res.data;
|
|
49
|
-
}
|
|
50
|
-
const res = MetadataFactory.analyze(checker)({
|
|
51
|
-
escape: true,
|
|
52
|
-
constant: true,
|
|
53
|
-
absorb: false,
|
|
54
|
-
})(collection)(r.output.type);
|
|
55
|
-
if (res.success) r.output.metadata = res.data;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const dict: Map<string, IModule> = new Map();
|
|
59
|
-
for (const alias of collection.aliases())
|
|
60
|
-
if (isNamedDeclaration(alias.name))
|
|
61
|
-
prepare(dict)(alias.name)((importer) =>
|
|
62
|
-
write_alias(config)(importer)(alias),
|
|
63
|
-
);
|
|
64
|
-
for (const object of collection.objects())
|
|
65
|
-
if (isNamedDeclaration(object.name))
|
|
66
|
-
prepare(dict)(object.name)((importer) =>
|
|
67
|
-
write_object(config)(importer)(object),
|
|
68
|
-
);
|
|
69
|
-
return dict;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const prepare =
|
|
73
|
-
(dict: Map<string, IModule>) =>
|
|
74
|
-
(name: string) =>
|
|
75
|
-
(programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration) => {
|
|
76
|
-
const accessors: string[] = name.split(".");
|
|
77
|
-
const modulo: IPointer<IModule> = { value: null! };
|
|
78
|
-
|
|
79
|
-
accessors.forEach((acc, i) => {
|
|
80
|
-
modulo.value = MapUtil.take(dict, acc, () => ({
|
|
81
|
-
name: acc,
|
|
82
|
-
children: new Map(),
|
|
83
|
-
programmer: null,
|
|
84
|
-
}));
|
|
85
|
-
if (i === accessors.length - 1) modulo.value.programmer = programmer;
|
|
86
|
-
dict = modulo.value.children;
|
|
87
|
-
});
|
|
88
|
-
return modulo!;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const write_alias =
|
|
92
|
-
(config: INestiaConfig) =>
|
|
93
|
-
(importer: ImportDictionary) =>
|
|
94
|
-
(alias: MetadataAlias): ts.TypeAliasDeclaration =>
|
|
95
|
-
FilePrinter.description(
|
|
96
|
-
ts.factory.createTypeAliasDeclaration(
|
|
97
|
-
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
98
|
-
alias.name.split(".").at(-1)!,
|
|
99
|
-
[],
|
|
100
|
-
SdkTypeProgrammer.write(config)(importer)(alias.value),
|
|
101
|
-
),
|
|
102
|
-
writeComment([])(alias.description, alias.jsDocTags),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const write_object =
|
|
106
|
-
(config: INestiaConfig) =>
|
|
107
|
-
(importer: ImportDictionary) =>
|
|
108
|
-
(object: MetadataObject): ts.TypeAliasDeclaration => {
|
|
109
|
-
return FilePrinter.description(
|
|
110
|
-
ts.factory.createTypeAliasDeclaration(
|
|
111
|
-
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
112
|
-
object.name.split(".").at(-1)!,
|
|
113
|
-
[],
|
|
114
|
-
SdkTypeProgrammer.write_object(config)(importer)(object),
|
|
115
|
-
),
|
|
116
|
-
writeComment([])(object.description ?? null, object.jsDocTags),
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const isNamedDeclaration = (name: string) =>
|
|
122
|
-
name !== "object" &&
|
|
123
|
-
name !== "__type" &&
|
|
124
|
-
!name.startsWith("__type.") &&
|
|
125
|
-
name !== "__object" &&
|
|
126
|
-
!name.startsWith("__object.");
|
|
127
|
-
|
|
128
|
-
const writeComment =
|
|
129
|
-
(atomics: MetadataAtomic[]) =>
|
|
130
|
-
(description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
|
|
131
|
-
const lines: string[] = [];
|
|
132
|
-
if (description?.length)
|
|
133
|
-
lines.push(...description.split("\n").map((s) => `${s}`));
|
|
134
|
-
|
|
135
|
-
const filtered: IJsDocTagInfo[] =
|
|
136
|
-
!!atomics.length && !!jsDocTags?.length
|
|
137
|
-
? jsDocTags.filter(
|
|
138
|
-
(tag) =>
|
|
139
|
-
!atomics.some((a) =>
|
|
140
|
-
a.tags.some((r) => r.some((t) => t.kind === tag.name)),
|
|
141
|
-
),
|
|
142
|
-
)
|
|
143
|
-
: jsDocTags ?? [];
|
|
144
|
-
|
|
145
|
-
if (description?.length && filtered.length) lines.push("");
|
|
146
|
-
if (filtered.length)
|
|
147
|
-
lines.push(
|
|
148
|
-
...filtered.map((t) =>
|
|
149
|
-
t.text?.length
|
|
150
|
-
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
151
|
-
: `@${t.name}`,
|
|
152
|
-
),
|
|
153
|
-
);
|
|
154
|
-
return lines.join("\n");
|
|
155
|
-
};
|
|
1
|
+
import { IPointer } from "tstl";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { IJsDocTagInfo } from "typia";
|
|
4
|
+
import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
|
|
6
|
+
import { MetadataAlias } from "typia/lib/schemas/metadata/MetadataAlias";
|
|
7
|
+
import { MetadataAtomic } from "typia/lib/schemas/metadata/MetadataAtomic";
|
|
8
|
+
import { MetadataObject } from "typia/lib/schemas/metadata/MetadataObject";
|
|
9
|
+
|
|
10
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
11
|
+
import { IRoute } from "../../structures/IRoute";
|
|
12
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
13
|
+
import { FilePrinter } from "./FilePrinter";
|
|
14
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
15
|
+
import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
|
|
16
|
+
|
|
17
|
+
export namespace SdkCloneProgrammer {
|
|
18
|
+
export interface IModule {
|
|
19
|
+
name: string;
|
|
20
|
+
children: Map<string, IModule>;
|
|
21
|
+
programmer:
|
|
22
|
+
| null
|
|
23
|
+
| ((importer: ImportDictionary) => ts.TypeAliasDeclaration);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const write =
|
|
27
|
+
(checker: ts.TypeChecker) =>
|
|
28
|
+
(config: INestiaConfig) =>
|
|
29
|
+
(routes: IRoute[]): Map<string, IModule> => {
|
|
30
|
+
const collection = new MetadataCollection({
|
|
31
|
+
replace: MetadataCollection.replace,
|
|
32
|
+
});
|
|
33
|
+
for (const r of routes) {
|
|
34
|
+
for (const p of r.parameters) {
|
|
35
|
+
const res = MetadataFactory.analyze(checker)({
|
|
36
|
+
escape: false,
|
|
37
|
+
constant: true,
|
|
38
|
+
absorb: false,
|
|
39
|
+
})(collection)(p.type);
|
|
40
|
+
if (res.success) p.metadata = res.data;
|
|
41
|
+
}
|
|
42
|
+
for (const e of Object.values(r.exceptions)) {
|
|
43
|
+
const res = MetadataFactory.analyze(checker)({
|
|
44
|
+
escape: true,
|
|
45
|
+
constant: true,
|
|
46
|
+
absorb: false,
|
|
47
|
+
})(collection)(e.type);
|
|
48
|
+
if (res.success) e.metadata = res.data;
|
|
49
|
+
}
|
|
50
|
+
const res = MetadataFactory.analyze(checker)({
|
|
51
|
+
escape: true,
|
|
52
|
+
constant: true,
|
|
53
|
+
absorb: false,
|
|
54
|
+
})(collection)(r.output.type);
|
|
55
|
+
if (res.success) r.output.metadata = res.data;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const dict: Map<string, IModule> = new Map();
|
|
59
|
+
for (const alias of collection.aliases())
|
|
60
|
+
if (isNamedDeclaration(alias.name))
|
|
61
|
+
prepare(dict)(alias.name)((importer) =>
|
|
62
|
+
write_alias(config)(importer)(alias),
|
|
63
|
+
);
|
|
64
|
+
for (const object of collection.objects())
|
|
65
|
+
if (isNamedDeclaration(object.name))
|
|
66
|
+
prepare(dict)(object.name)((importer) =>
|
|
67
|
+
write_object(config)(importer)(object),
|
|
68
|
+
);
|
|
69
|
+
return dict;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const prepare =
|
|
73
|
+
(dict: Map<string, IModule>) =>
|
|
74
|
+
(name: string) =>
|
|
75
|
+
(programmer: (importer: ImportDictionary) => ts.TypeAliasDeclaration) => {
|
|
76
|
+
const accessors: string[] = name.split(".");
|
|
77
|
+
const modulo: IPointer<IModule> = { value: null! };
|
|
78
|
+
|
|
79
|
+
accessors.forEach((acc, i) => {
|
|
80
|
+
modulo.value = MapUtil.take(dict, acc, () => ({
|
|
81
|
+
name: acc,
|
|
82
|
+
children: new Map(),
|
|
83
|
+
programmer: null,
|
|
84
|
+
}));
|
|
85
|
+
if (i === accessors.length - 1) modulo.value.programmer = programmer;
|
|
86
|
+
dict = modulo.value.children;
|
|
87
|
+
});
|
|
88
|
+
return modulo!;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const write_alias =
|
|
92
|
+
(config: INestiaConfig) =>
|
|
93
|
+
(importer: ImportDictionary) =>
|
|
94
|
+
(alias: MetadataAlias): ts.TypeAliasDeclaration =>
|
|
95
|
+
FilePrinter.description(
|
|
96
|
+
ts.factory.createTypeAliasDeclaration(
|
|
97
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
98
|
+
alias.name.split(".").at(-1)!,
|
|
99
|
+
[],
|
|
100
|
+
SdkTypeProgrammer.write(config)(importer)(alias.value),
|
|
101
|
+
),
|
|
102
|
+
writeComment([])(alias.description, alias.jsDocTags),
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const write_object =
|
|
106
|
+
(config: INestiaConfig) =>
|
|
107
|
+
(importer: ImportDictionary) =>
|
|
108
|
+
(object: MetadataObject): ts.TypeAliasDeclaration => {
|
|
109
|
+
return FilePrinter.description(
|
|
110
|
+
ts.factory.createTypeAliasDeclaration(
|
|
111
|
+
[ts.factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
112
|
+
object.name.split(".").at(-1)!,
|
|
113
|
+
[],
|
|
114
|
+
SdkTypeProgrammer.write_object(config)(importer)(object),
|
|
115
|
+
),
|
|
116
|
+
writeComment([])(object.description ?? null, object.jsDocTags),
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const isNamedDeclaration = (name: string) =>
|
|
122
|
+
name !== "object" &&
|
|
123
|
+
name !== "__type" &&
|
|
124
|
+
!name.startsWith("__type.") &&
|
|
125
|
+
name !== "__object" &&
|
|
126
|
+
!name.startsWith("__object.");
|
|
127
|
+
|
|
128
|
+
const writeComment =
|
|
129
|
+
(atomics: MetadataAtomic[]) =>
|
|
130
|
+
(description: string | null, jsDocTags: IJsDocTagInfo[]): string => {
|
|
131
|
+
const lines: string[] = [];
|
|
132
|
+
if (description?.length)
|
|
133
|
+
lines.push(...description.split("\n").map((s) => `${s}`));
|
|
134
|
+
|
|
135
|
+
const filtered: IJsDocTagInfo[] =
|
|
136
|
+
!!atomics.length && !!jsDocTags?.length
|
|
137
|
+
? jsDocTags.filter(
|
|
138
|
+
(tag) =>
|
|
139
|
+
!atomics.some((a) =>
|
|
140
|
+
a.tags.some((r) => r.some((t) => t.kind === tag.name)),
|
|
141
|
+
),
|
|
142
|
+
)
|
|
143
|
+
: jsDocTags ?? [];
|
|
144
|
+
|
|
145
|
+
if (description?.length && filtered.length) lines.push("");
|
|
146
|
+
if (filtered.length)
|
|
147
|
+
lines.push(
|
|
148
|
+
...filtered.map((t) =>
|
|
149
|
+
t.text?.length
|
|
150
|
+
? `@${t.name} ${t.text.map((e) => e.text).join("")}`
|
|
151
|
+
: `@${t.name}`,
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
return lines.join("\n");
|
|
155
|
+
};
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
-
import { IRoute } from "../../structures/IRoute";
|
|
6
|
-
import { MapUtil } from "../../utils/MapUtil";
|
|
7
|
-
import { FilePrinter } from "./FilePrinter";
|
|
8
|
-
import { ImportDictionary } from "./ImportDictionary";
|
|
9
|
-
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
10
|
-
import { SdkRouteProgrammer } from "./SdkRouteProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace SdkFileProgrammer {
|
|
13
|
-
/* ---------------------------------------------------------
|
|
14
|
-
CONSTRUCTOR
|
|
15
|
-
--------------------------------------------------------- */
|
|
16
|
-
export const generate =
|
|
17
|
-
(checker: ts.TypeChecker) =>
|
|
18
|
-
(config: INestiaConfig) =>
|
|
19
|
-
async (routeList: IRoute[]): Promise<void> => {
|
|
20
|
-
// CONSTRUCT FOLDER TREE
|
|
21
|
-
const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
|
|
22
|
-
for (const route of routeList) emplace(root)(route);
|
|
23
|
-
|
|
24
|
-
// ITERATE FILES
|
|
25
|
-
await iterate(checker)(config)(root)(config.output + "/functional");
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const emplace =
|
|
29
|
-
(directory: SdkRouteDirectory) =>
|
|
30
|
-
(route: IRoute): void => {
|
|
31
|
-
// OPEN DIRECTORIES
|
|
32
|
-
for (const key of route.accessors.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
|
-
(checker: ts.TypeChecker) =>
|
|
49
|
-
(config: INestiaConfig) =>
|
|
50
|
-
(directory: SdkRouteDirectory) =>
|
|
51
|
-
async (outDir: string): Promise<void> => {
|
|
52
|
-
// CREATE A NEW DIRECTORY
|
|
53
|
-
try {
|
|
54
|
-
await fs.promises.mkdir(outDir);
|
|
55
|
-
} catch {}
|
|
56
|
-
|
|
57
|
-
// ITERATE CHILDREN
|
|
58
|
-
const statements: ts.Statement[] = [];
|
|
59
|
-
for (const [key, value] of directory.children) {
|
|
60
|
-
await iterate(checker)(config)(value)(`${outDir}/${key}`);
|
|
61
|
-
statements.push(
|
|
62
|
-
ts.factory.createExportDeclaration(
|
|
63
|
-
undefined,
|
|
64
|
-
false,
|
|
65
|
-
ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
|
|
66
|
-
ts.factory.createStringLiteral(`./${key}`),
|
|
67
|
-
undefined,
|
|
68
|
-
),
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
if (statements.length && directory.routes.length)
|
|
72
|
-
statements.push(FilePrinter.enter());
|
|
73
|
-
|
|
74
|
-
// ITERATE ROUTES
|
|
75
|
-
const importer: ImportDictionary = new ImportDictionary(
|
|
76
|
-
`${outDir}/index.ts`,
|
|
77
|
-
);
|
|
78
|
-
directory.routes.forEach((route, i) => {
|
|
79
|
-
if (config.clone !== true)
|
|
80
|
-
for (const tuple of route.imports)
|
|
81
|
-
for (const instance of tuple[1])
|
|
82
|
-
importer.internal({
|
|
83
|
-
file: tuple[0],
|
|
84
|
-
instance,
|
|
85
|
-
type: true,
|
|
86
|
-
});
|
|
87
|
-
statements.push(
|
|
88
|
-
...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
|
|
89
|
-
);
|
|
90
|
-
if (i !== directory.routes.length - 1)
|
|
91
|
-
statements.push(FilePrinter.enter());
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// FINALIZE THE CONTENT
|
|
95
|
-
if (directory.routes.length !== 0)
|
|
96
|
-
statements.push(
|
|
97
|
-
...importer.toStatements(outDir),
|
|
98
|
-
...(!importer.empty() && statements.length
|
|
99
|
-
? [FilePrinter.enter()]
|
|
100
|
-
: []),
|
|
101
|
-
...statements.splice(0, statements.length),
|
|
102
|
-
);
|
|
103
|
-
await FilePrinter.write({
|
|
104
|
-
location: importer.file,
|
|
105
|
-
statements,
|
|
106
|
-
top:
|
|
107
|
-
"/**\n" +
|
|
108
|
-
" * @packageDocumentation\n" +
|
|
109
|
-
` * @module ${directory.module}\n` +
|
|
110
|
-
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
111
|
-
" */\n" +
|
|
112
|
-
"//================================================================\n",
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
5
|
+
import { IRoute } from "../../structures/IRoute";
|
|
6
|
+
import { MapUtil } from "../../utils/MapUtil";
|
|
7
|
+
import { FilePrinter } from "./FilePrinter";
|
|
8
|
+
import { ImportDictionary } from "./ImportDictionary";
|
|
9
|
+
import { SdkRouteDirectory } from "./SdkRouteDirectory";
|
|
10
|
+
import { SdkRouteProgrammer } from "./SdkRouteProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace SdkFileProgrammer {
|
|
13
|
+
/* ---------------------------------------------------------
|
|
14
|
+
CONSTRUCTOR
|
|
15
|
+
--------------------------------------------------------- */
|
|
16
|
+
export const generate =
|
|
17
|
+
(checker: ts.TypeChecker) =>
|
|
18
|
+
(config: INestiaConfig) =>
|
|
19
|
+
async (routeList: IRoute[]): Promise<void> => {
|
|
20
|
+
// CONSTRUCT FOLDER TREE
|
|
21
|
+
const root: SdkRouteDirectory = new SdkRouteDirectory(null, "functional");
|
|
22
|
+
for (const route of routeList) emplace(root)(route);
|
|
23
|
+
|
|
24
|
+
// ITERATE FILES
|
|
25
|
+
await iterate(checker)(config)(root)(config.output + "/functional");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const emplace =
|
|
29
|
+
(directory: SdkRouteDirectory) =>
|
|
30
|
+
(route: IRoute): void => {
|
|
31
|
+
// OPEN DIRECTORIES
|
|
32
|
+
for (const key of route.accessors.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
|
+
(checker: ts.TypeChecker) =>
|
|
49
|
+
(config: INestiaConfig) =>
|
|
50
|
+
(directory: SdkRouteDirectory) =>
|
|
51
|
+
async (outDir: string): Promise<void> => {
|
|
52
|
+
// CREATE A NEW DIRECTORY
|
|
53
|
+
try {
|
|
54
|
+
await fs.promises.mkdir(outDir);
|
|
55
|
+
} catch {}
|
|
56
|
+
|
|
57
|
+
// ITERATE CHILDREN
|
|
58
|
+
const statements: ts.Statement[] = [];
|
|
59
|
+
for (const [key, value] of directory.children) {
|
|
60
|
+
await iterate(checker)(config)(value)(`${outDir}/${key}`);
|
|
61
|
+
statements.push(
|
|
62
|
+
ts.factory.createExportDeclaration(
|
|
63
|
+
undefined,
|
|
64
|
+
false,
|
|
65
|
+
ts.factory.createNamespaceExport(ts.factory.createIdentifier(key)),
|
|
66
|
+
ts.factory.createStringLiteral(`./${key}`),
|
|
67
|
+
undefined,
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (statements.length && directory.routes.length)
|
|
72
|
+
statements.push(FilePrinter.enter());
|
|
73
|
+
|
|
74
|
+
// ITERATE ROUTES
|
|
75
|
+
const importer: ImportDictionary = new ImportDictionary(
|
|
76
|
+
`${outDir}/index.ts`,
|
|
77
|
+
);
|
|
78
|
+
directory.routes.forEach((route, i) => {
|
|
79
|
+
if (config.clone !== true)
|
|
80
|
+
for (const tuple of route.imports)
|
|
81
|
+
for (const instance of tuple[1])
|
|
82
|
+
importer.internal({
|
|
83
|
+
file: tuple[0],
|
|
84
|
+
instance,
|
|
85
|
+
type: true,
|
|
86
|
+
});
|
|
87
|
+
statements.push(
|
|
88
|
+
...SdkRouteProgrammer.generate(checker)(config)(importer)(route),
|
|
89
|
+
);
|
|
90
|
+
if (i !== directory.routes.length - 1)
|
|
91
|
+
statements.push(FilePrinter.enter());
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// FINALIZE THE CONTENT
|
|
95
|
+
if (directory.routes.length !== 0)
|
|
96
|
+
statements.push(
|
|
97
|
+
...importer.toStatements(outDir),
|
|
98
|
+
...(!importer.empty() && statements.length
|
|
99
|
+
? [FilePrinter.enter()]
|
|
100
|
+
: []),
|
|
101
|
+
...statements.splice(0, statements.length),
|
|
102
|
+
);
|
|
103
|
+
await FilePrinter.write({
|
|
104
|
+
location: importer.file,
|
|
105
|
+
statements,
|
|
106
|
+
top:
|
|
107
|
+
"/**\n" +
|
|
108
|
+
" * @packageDocumentation\n" +
|
|
109
|
+
` * @module ${directory.module}\n` +
|
|
110
|
+
" * @nestia Generated by Nestia - https://github.com/samchon/nestia \n" +
|
|
111
|
+
" */\n" +
|
|
112
|
+
"//================================================================\n",
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
}
|