@nestia/sdk 1.1.0 → 1.2.0-dev.20230504
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/assets/bundle/api/index.ts +4 -0
- package/assets/bundle/api/module.ts +5 -0
- package/assets/bundle/e2e/index.ts +41 -0
- package/lib/INestiaConfig.d.ts +6 -0
- package/lib/NestiaSdkApplication.d.ts +1 -0
- package/lib/NestiaSdkApplication.js +35 -14
- package/lib/NestiaSdkApplication.js.map +1 -1
- package/lib/analyses/ControllerAnalyzer.js +1 -0
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/analyses/ReflectAnalyzer.js +14 -2
- package/lib/analyses/ReflectAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkCommand.d.ts +3 -2
- package/lib/executable/internal/NestiaSdkCommand.js +53 -57
- package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
- package/lib/executable/internal/NestiaSdkConfig.js +23 -50
- package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
- package/lib/executable/sdk.js +5 -8
- package/lib/executable/sdk.js.map +1 -1
- package/lib/generates/E2eGenerator.d.ts +5 -0
- package/lib/generates/E2eGenerator.js +52 -0
- package/lib/generates/E2eGenerator.js.map +1 -0
- package/lib/generates/SdkGenerator.d.ts +1 -2
- package/lib/generates/SdkGenerator.js +20 -22
- package/lib/generates/SdkGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +1 -1
- package/lib/generates/SwaggerGenerator.js +40 -43
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/generates/internal/E2eFileProgrammer.d.ts +8 -0
- package/lib/generates/internal/E2eFileProgrammer.js +101 -0
- package/lib/generates/internal/E2eFileProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkFileProgrammer.d.ts +5 -0
- package/lib/generates/internal/SdkFileProgrammer.js +121 -0
- package/lib/generates/internal/SdkFileProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkFunctionProgrammer.d.ts +5 -0
- package/lib/generates/{FunctionGenerator.js → internal/SdkFunctionProgrammer.js} +58 -57
- package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -0
- package/lib/generates/internal/SdkRouteDirectory.d.ts +10 -0
- package/lib/generates/internal/SdkRouteDirectory.js +18 -0
- package/lib/generates/internal/SdkRouteDirectory.js.map +1 -0
- package/lib/structures/IController.d.ts +4 -0
- package/lib/structures/IRoute.d.ts +4 -0
- package/lib/utils/NestiaConfigUtil.d.ts +4 -0
- package/lib/utils/NestiaConfigUtil.js +24 -0
- package/lib/utils/NestiaConfigUtil.js.map +1 -0
- package/lib/utils/SourceFinder.d.ts +9 -0
- package/lib/utils/SourceFinder.js +60 -0
- package/lib/utils/SourceFinder.js.map +1 -0
- package/package.json +6 -10
- package/src/INestiaConfig.ts +7 -0
- package/src/NestiaSdkApplication.ts +54 -17
- package/src/analyses/ControllerAnalyzer.ts +1 -0
- package/src/analyses/ReflectAnalyzer.ts +14 -2
- package/src/executable/internal/NestiaSdkCommand.ts +87 -105
- package/src/executable/sdk.ts +4 -8
- package/src/generates/E2eGenerator.ts +65 -0
- package/src/generates/SdkGenerator.ts +29 -30
- package/src/generates/SwaggerGenerator.ts +66 -64
- package/src/generates/internal/E2eFileProgrammer.ts +119 -0
- package/src/generates/internal/SdkFileProgrammer.ts +144 -0
- package/src/generates/internal/SdkFunctionProgrammer.ts +371 -0
- package/src/generates/internal/SdkRouteDirectory.ts +21 -0
- package/src/structures/IController.ts +4 -0
- package/src/structures/IRoute.ts +4 -0
- package/src/utils/NestiaConfigUtil.ts +21 -0
- package/src/utils/SourceFinder.ts +60 -0
- package/lib/analyses/SourceFinder.d.ts +0 -4
- package/lib/analyses/SourceFinder.js +0 -71
- package/lib/analyses/SourceFinder.js.map +0 -1
- package/lib/generates/FileGenerator.d.ts +0 -5
- package/lib/generates/FileGenerator.js +0 -138
- package/lib/generates/FileGenerator.js.map +0 -1
- package/lib/generates/FunctionGenerator.d.ts +0 -5
- package/lib/generates/FunctionGenerator.js.map +0 -1
- package/src/analyses/SourceFinder.ts +0 -59
- package/src/generates/FileGenerator.ts +0 -156
- package/src/generates/FunctionGenerator.ts +0 -348
- /package/assets/bundle/{HttpError.ts → api/HttpError.ts} +0 -0
- /package/assets/bundle/{IConnection.ts → api/IConnection.ts} +0 -0
- /package/assets/bundle/{Primitive.ts → api/Primitive.ts} +0 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { Vector } from "tstl/container/Vector";
|
|
2
|
+
import { Pair } from "tstl/utility/Pair";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { Escaper } from "typia/lib/utils/Escaper";
|
|
6
|
+
|
|
7
|
+
import { INestiaConfig } from "../../INestiaConfig";
|
|
8
|
+
import { IRoute } from "../../structures/IRoute";
|
|
9
|
+
|
|
10
|
+
export namespace SdkFunctionProgrammer {
|
|
11
|
+
export const generate =
|
|
12
|
+
(config: INestiaConfig) =>
|
|
13
|
+
(route: IRoute): string => {
|
|
14
|
+
const query: IRoute.IParameter | undefined = route.parameters.find(
|
|
15
|
+
(param) =>
|
|
16
|
+
param.category === "query" && param.field === undefined,
|
|
17
|
+
);
|
|
18
|
+
const input: IRoute.IParameter | undefined = route.parameters.find(
|
|
19
|
+
(param) => param.category === "body",
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return [head, body, tail]
|
|
23
|
+
.map((closure) => closure(config)(route)({ query, input }))
|
|
24
|
+
.filter((str) => !!str)
|
|
25
|
+
.join("\n");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/* ---------------------------------------------------------
|
|
29
|
+
BODY
|
|
30
|
+
--------------------------------------------------------- */
|
|
31
|
+
const body =
|
|
32
|
+
(config: INestiaConfig) =>
|
|
33
|
+
(route: IRoute) =>
|
|
34
|
+
(props: {
|
|
35
|
+
query: IRoute.IParameter | undefined;
|
|
36
|
+
input: IRoute.IParameter | undefined;
|
|
37
|
+
}): string => {
|
|
38
|
+
// FETCH ARGUMENTS WITH REQUST BODY
|
|
39
|
+
const parameters = filter_parameters(route)(props.query);
|
|
40
|
+
const fetchArguments: string[] = [
|
|
41
|
+
"connection",
|
|
42
|
+
`${route.name}.ENCRYPTED`,
|
|
43
|
+
`${route.name}.METHOD`,
|
|
44
|
+
`${route.name}.path(${parameters
|
|
45
|
+
.map((p) => p.name)
|
|
46
|
+
.join(", ")})`,
|
|
47
|
+
];
|
|
48
|
+
if (props.input !== undefined) {
|
|
49
|
+
fetchArguments.push(props.input.name);
|
|
50
|
+
if (config.json === true)
|
|
51
|
+
fetchArguments.push(`${route.name}.stringify`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const assertions: string =
|
|
55
|
+
config.assert === true && route.parameters.length !== 0
|
|
56
|
+
? route.parameters
|
|
57
|
+
.map(
|
|
58
|
+
(param) =>
|
|
59
|
+
` typia.assert<typeof ${param.name}>(${param.name});`,
|
|
60
|
+
)
|
|
61
|
+
.join("\n") + "\n\n"
|
|
62
|
+
: "";
|
|
63
|
+
|
|
64
|
+
// FUNCTION CALL STATEMENT
|
|
65
|
+
const caller: string =
|
|
66
|
+
"Fetcher.fetch\n" +
|
|
67
|
+
" (\n" +
|
|
68
|
+
fetchArguments.map((param) => ` ${param}`).join(",\n") +
|
|
69
|
+
"\n" +
|
|
70
|
+
" )";
|
|
71
|
+
if (route.setHeaders.length === 0)
|
|
72
|
+
return `{\n${assertions} return ${caller};\n}`;
|
|
73
|
+
|
|
74
|
+
// SET HEADERS
|
|
75
|
+
const content: string[] = [
|
|
76
|
+
`{\n`,
|
|
77
|
+
assertions,
|
|
78
|
+
` const output: ${route.name}.Output = await ${caller};\n`,
|
|
79
|
+
"\n",
|
|
80
|
+
` // configure header(s)\n`,
|
|
81
|
+
` connection.headers ??= {};\n`,
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
for (const header of route.setHeaders) {
|
|
85
|
+
if (header.type === "assigner")
|
|
86
|
+
content.push(
|
|
87
|
+
" ",
|
|
88
|
+
`Object.assign(connection.headers, ${access("output")(
|
|
89
|
+
header.source,
|
|
90
|
+
)});\n`,
|
|
91
|
+
);
|
|
92
|
+
else
|
|
93
|
+
content.push(
|
|
94
|
+
" ",
|
|
95
|
+
`${access("connection.headers")(
|
|
96
|
+
header.target ?? header.source,
|
|
97
|
+
)} = ${access("output")(header.source)};\n`,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
content.push("\n", " return output;\n", "}");
|
|
101
|
+
return content.join("");
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const filter_parameters =
|
|
105
|
+
(route: IRoute) =>
|
|
106
|
+
(query: IRoute.IParameter | undefined): IRoute.IParameter[] => {
|
|
107
|
+
const parameters: IRoute.IParameter[] = route.parameters.filter(
|
|
108
|
+
(param) =>
|
|
109
|
+
param.category === "param" ||
|
|
110
|
+
(param.category === "query" && param.field !== undefined),
|
|
111
|
+
);
|
|
112
|
+
if (query) parameters.push(query);
|
|
113
|
+
return parameters;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const access =
|
|
117
|
+
(x: string) =>
|
|
118
|
+
(y: string): string =>
|
|
119
|
+
y[0] === "[" ? `${x}${y}` : `${x}.${y}`;
|
|
120
|
+
|
|
121
|
+
/* ---------------------------------------------------------
|
|
122
|
+
HEAD & TAIL
|
|
123
|
+
--------------------------------------------------------- */
|
|
124
|
+
const head =
|
|
125
|
+
(config: INestiaConfig) =>
|
|
126
|
+
(route: IRoute) =>
|
|
127
|
+
(props: {
|
|
128
|
+
query: IRoute.IParameter | undefined;
|
|
129
|
+
input: IRoute.IParameter | undefined;
|
|
130
|
+
}): string => {
|
|
131
|
+
//----
|
|
132
|
+
// CONSTRUCT COMMENT
|
|
133
|
+
//----
|
|
134
|
+
// MAIN DESCRIPTION
|
|
135
|
+
const comments: string[] = route.comments
|
|
136
|
+
.map(
|
|
137
|
+
(part) =>
|
|
138
|
+
`${part.kind === "linkText" ? " " : ""}${part.text}`,
|
|
139
|
+
)
|
|
140
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
141
|
+
.join("")
|
|
142
|
+
.split("\n")
|
|
143
|
+
.filter(
|
|
144
|
+
(str, i, array) => str !== "" || i !== array.length - 1,
|
|
145
|
+
);
|
|
146
|
+
if (comments.length) comments.push("");
|
|
147
|
+
|
|
148
|
+
// FILTER TAGS (VULNERABLE PARAMETERS WOULD BE REMOVED)
|
|
149
|
+
const tagList: ts.JSDocTagInfo[] = route.tags.slice();
|
|
150
|
+
if (tagList.length !== 0) {
|
|
151
|
+
const index: number = tagList.findIndex(
|
|
152
|
+
(t) => t.name === "param",
|
|
153
|
+
);
|
|
154
|
+
if (index !== -1) {
|
|
155
|
+
const capsule: Vector<ts.JSDocTagInfo> =
|
|
156
|
+
Vector.wrap(tagList);
|
|
157
|
+
capsule.insert(capsule.nth(index), {
|
|
158
|
+
name: "param",
|
|
159
|
+
text: [
|
|
160
|
+
{
|
|
161
|
+
kind: "parameterName",
|
|
162
|
+
text: "connection",
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
kind: "space",
|
|
166
|
+
text: " ",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
kind: "text",
|
|
170
|
+
text: "connection Information of the remote HTTP(s) server with headers (+encryption password)",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
comments.push(
|
|
176
|
+
...tagList.map((tag) =>
|
|
177
|
+
tag.text
|
|
178
|
+
? `@${tag.name} ${tag.text
|
|
179
|
+
.map((elem) => elem.text)
|
|
180
|
+
.join("")}`
|
|
181
|
+
: `@${tag.name}`,
|
|
182
|
+
),
|
|
183
|
+
"",
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// COMPLETE THE COMMENT
|
|
188
|
+
comments.push(
|
|
189
|
+
`@controller ${route.symbol}`,
|
|
190
|
+
`@path ${route.method} ${route.path}`,
|
|
191
|
+
`@nestia Generated by Nestia - https://github.com/samchon/nestia`,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
//----
|
|
195
|
+
// FINALIZATION
|
|
196
|
+
//----
|
|
197
|
+
// REFORM PARAMETERS TEXT
|
|
198
|
+
const parameters: string[] = [
|
|
199
|
+
"connection: IConnection",
|
|
200
|
+
...route.parameters.map((param) => {
|
|
201
|
+
const type: string =
|
|
202
|
+
config.primitive !== false &&
|
|
203
|
+
(param === props.query || param === props.input)
|
|
204
|
+
? `Primitive<${route.name}.${
|
|
205
|
+
param === props.query ? "Query" : "Input"
|
|
206
|
+
}>`
|
|
207
|
+
: param.type.name;
|
|
208
|
+
return `${param.name}${param.optional ? "?" : ""}: ${type}`;
|
|
209
|
+
}),
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
// OUTPUT TYPE
|
|
213
|
+
const output: string =
|
|
214
|
+
route.output.name === "void" ? "void" : `${route.name}.Output`;
|
|
215
|
+
|
|
216
|
+
// RETURNS WITH CONSTRUCTION
|
|
217
|
+
return (
|
|
218
|
+
"" +
|
|
219
|
+
"/**\n" +
|
|
220
|
+
comments.map((str) => ` * ${str}`).join("\n") +
|
|
221
|
+
"\n" +
|
|
222
|
+
" */\n" +
|
|
223
|
+
`export${route.setHeaders.length ? " async" : ""} function ${
|
|
224
|
+
route.name
|
|
225
|
+
}\n` +
|
|
226
|
+
` (\n` +
|
|
227
|
+
`${parameters.map((str) => ` ${str}`).join(",\n")}\n` +
|
|
228
|
+
` ): Promise<${output}>`
|
|
229
|
+
);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const tail =
|
|
233
|
+
(config: INestiaConfig) =>
|
|
234
|
+
(route: IRoute) =>
|
|
235
|
+
(props: {
|
|
236
|
+
query: IRoute.IParameter | undefined;
|
|
237
|
+
input: IRoute.IParameter | undefined;
|
|
238
|
+
}): string | null => {
|
|
239
|
+
// LIST UP TYPES
|
|
240
|
+
const types: Pair<string, string>[] = [];
|
|
241
|
+
if (props.query !== undefined)
|
|
242
|
+
types.push(new Pair("Query", props.query.type.name));
|
|
243
|
+
if (props.input !== undefined)
|
|
244
|
+
types.push(new Pair("Input", props.input.type.name));
|
|
245
|
+
if (route.output.name !== "void")
|
|
246
|
+
types.push(new Pair("Output", route.output.name));
|
|
247
|
+
|
|
248
|
+
// PATH WITH PARAMETERS
|
|
249
|
+
const parameters: IRoute.IParameter[] = filter_parameters(route)(
|
|
250
|
+
props.query,
|
|
251
|
+
);
|
|
252
|
+
const path: string = compute_path({
|
|
253
|
+
path: route.path,
|
|
254
|
+
query: props.query,
|
|
255
|
+
parameters,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
`export namespace ${route.name}\n` +
|
|
260
|
+
"{\n" +
|
|
261
|
+
(types.length !== 0
|
|
262
|
+
? types
|
|
263
|
+
.map(
|
|
264
|
+
(tuple) =>
|
|
265
|
+
` export type ${tuple.first} = ${
|
|
266
|
+
config.primitive !== false
|
|
267
|
+
? `Primitive<${tuple.second}>`
|
|
268
|
+
: tuple.second
|
|
269
|
+
};`,
|
|
270
|
+
)
|
|
271
|
+
.join("\n") + "\n"
|
|
272
|
+
: "") +
|
|
273
|
+
"\n" +
|
|
274
|
+
` export const METHOD = "${route.method}" as const;\n` +
|
|
275
|
+
` export const PATH: string = "${route.path}";\n` +
|
|
276
|
+
` export const ENCRYPTED: Fetcher.IEncrypted = {\n` +
|
|
277
|
+
` request: ${
|
|
278
|
+
props.input !== undefined && props.input.encrypted
|
|
279
|
+
},\n` +
|
|
280
|
+
` response: ${route.encrypted},\n` +
|
|
281
|
+
(route.status !== undefined
|
|
282
|
+
? ` status: ${route.status},\n`
|
|
283
|
+
: "") +
|
|
284
|
+
` };\n` +
|
|
285
|
+
"\n" +
|
|
286
|
+
` export function path(${parameters
|
|
287
|
+
.map((param) => `${param.name}: ${param.type.name}`)
|
|
288
|
+
.join(", ")}): string\n` +
|
|
289
|
+
` {\n` +
|
|
290
|
+
`${path};\n` +
|
|
291
|
+
` }\n` +
|
|
292
|
+
(config.json === true &&
|
|
293
|
+
route.parameters.find((param) => param.category === "body") !==
|
|
294
|
+
undefined
|
|
295
|
+
? ` export const stringify = (input: Input) => typia.assertStringify(input);\n`
|
|
296
|
+
: "") +
|
|
297
|
+
"}"
|
|
298
|
+
);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const compute_path = (props: {
|
|
302
|
+
query: IRoute.IParameter | undefined;
|
|
303
|
+
parameters: IRoute.IParameter[];
|
|
304
|
+
path: string;
|
|
305
|
+
}): string => {
|
|
306
|
+
for (const param of props.parameters)
|
|
307
|
+
if (param.category === "param")
|
|
308
|
+
props.path = props.path.replace(
|
|
309
|
+
`:${param.field}`,
|
|
310
|
+
`\${encodeURIComponent(${param.name} ?? "null")}`,
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
// NO QUERY PARAMETER
|
|
314
|
+
const queryParams: IRoute.IParameter[] = props.parameters.filter(
|
|
315
|
+
(param) => param.category === "query" && param.field !== undefined,
|
|
316
|
+
);
|
|
317
|
+
if (props.query === undefined && queryParams.length === 0)
|
|
318
|
+
return `${" ".repeat(8)}return \`${props.path}\``;
|
|
319
|
+
|
|
320
|
+
const computeName = (str: string): string =>
|
|
321
|
+
props.parameters.find((p) => p.name === str) !== undefined
|
|
322
|
+
? computeName("_" + str)
|
|
323
|
+
: str;
|
|
324
|
+
const variables: string = computeName("variables");
|
|
325
|
+
const search: string = computeName("search");
|
|
326
|
+
const encoded: string = computeName("encoded");
|
|
327
|
+
|
|
328
|
+
const wrapper = (expr: string) =>
|
|
329
|
+
[
|
|
330
|
+
`const ${variables}: Record<any, any> = ${expr};`,
|
|
331
|
+
`const ${search}: URLSearchParams = new URLSearchParams();`,
|
|
332
|
+
`for (const [key, value] of Object.entries(${variables}))`,
|
|
333
|
+
` if (value === undefined) continue;`,
|
|
334
|
+
` else if (Array.isArray(value))`,
|
|
335
|
+
` value.forEach((elem) => ${search}.append(key, String(elem)));`,
|
|
336
|
+
` else`,
|
|
337
|
+
` ${search}.set(key, String(value));`,
|
|
338
|
+
`const ${encoded}: string = ${search}.toString();`,
|
|
339
|
+
`return \`${props.path}\${${encoded}.length ? \`?\${${encoded}}\` : ""}\`;`,
|
|
340
|
+
]
|
|
341
|
+
.map((str) => `${" ".repeat(8)}${str}`)
|
|
342
|
+
.join("\n");
|
|
343
|
+
|
|
344
|
+
if (props.query !== undefined && queryParams.length === 0)
|
|
345
|
+
return wrapper(`${props.query.name} as any`);
|
|
346
|
+
else if (props.query === undefined)
|
|
347
|
+
return wrapper(`
|
|
348
|
+
{
|
|
349
|
+
${rest_query_parameters(queryParams)}
|
|
350
|
+
} as any`);
|
|
351
|
+
|
|
352
|
+
return wrapper(`
|
|
353
|
+
{
|
|
354
|
+
...${props.query.name},
|
|
355
|
+
${rest_query_parameters(queryParams)},
|
|
356
|
+
} as any`);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const rest_query_parameters = (parameters: IRoute.IParameter[]): string =>
|
|
360
|
+
parameters
|
|
361
|
+
.map((param) =>
|
|
362
|
+
param.name === param.field
|
|
363
|
+
? param.name
|
|
364
|
+
: `${
|
|
365
|
+
Escaper.variable(param.field!)
|
|
366
|
+
? param.field
|
|
367
|
+
: JSON.stringify(param.field)
|
|
368
|
+
}: ${param.name}`,
|
|
369
|
+
)
|
|
370
|
+
.join(`,\n${" ".repeat(12)}`);
|
|
371
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HashMap } from "tstl";
|
|
2
|
+
|
|
3
|
+
import { IRoute } from "../../structures/IRoute";
|
|
4
|
+
|
|
5
|
+
export class SdkRouteDirectory {
|
|
6
|
+
public readonly module: string;
|
|
7
|
+
public readonly directories: HashMap<string, SdkRouteDirectory>;
|
|
8
|
+
public readonly routes: IRoute[];
|
|
9
|
+
|
|
10
|
+
public constructor(
|
|
11
|
+
readonly parent: SdkRouteDirectory | null,
|
|
12
|
+
readonly name: string,
|
|
13
|
+
) {
|
|
14
|
+
this.directories = new HashMap();
|
|
15
|
+
this.routes = [];
|
|
16
|
+
this.module =
|
|
17
|
+
this.parent !== null
|
|
18
|
+
? `${this.parent.module}.${name}`
|
|
19
|
+
: `api.${name}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/structures/IRoute.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { INestiaConfig } from "../INestiaConfig";
|
|
2
|
+
|
|
3
|
+
export namespace NestiaConfigUtil {
|
|
4
|
+
export const input = (
|
|
5
|
+
config: INestiaConfig["input"],
|
|
6
|
+
): INestiaConfig.IInput =>
|
|
7
|
+
Array.isArray(config)
|
|
8
|
+
? {
|
|
9
|
+
include: config,
|
|
10
|
+
exclude: [],
|
|
11
|
+
}
|
|
12
|
+
: typeof config === "object"
|
|
13
|
+
? {
|
|
14
|
+
include: config.include,
|
|
15
|
+
exclude: config.exclude ?? [],
|
|
16
|
+
}
|
|
17
|
+
: {
|
|
18
|
+
include: [config],
|
|
19
|
+
exclude: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import glob from "glob";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
export namespace SourceFinder {
|
|
6
|
+
export const find = async (props: IProps): Promise<string[]> => {
|
|
7
|
+
const dict: Set<string> = new Set();
|
|
8
|
+
|
|
9
|
+
await emplace(props.filter)(props.include)((str) => dict.add(str));
|
|
10
|
+
if (props.exclude?.length)
|
|
11
|
+
await emplace(props.filter)(props.exclude)((str) =>
|
|
12
|
+
dict.delete(str),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return [...dict];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const emplace =
|
|
19
|
+
(filter: (file: string) => boolean) =>
|
|
20
|
+
(input: string[]) =>
|
|
21
|
+
async (closure: (location: string) => void): Promise<void> => {
|
|
22
|
+
for (const pattern of input) {
|
|
23
|
+
for (const file of await _Glob(path.resolve(pattern))) {
|
|
24
|
+
const stats: fs.Stats = await fs.promises.stat(file);
|
|
25
|
+
if (stats.isDirectory() === true)
|
|
26
|
+
await iterate(filter)(closure)(file);
|
|
27
|
+
else if (stats.isFile() && filter(file)) closure(file);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const iterate =
|
|
33
|
+
(filter: (location: string) => boolean) =>
|
|
34
|
+
(closure: (location: string) => void) =>
|
|
35
|
+
async (location: string): Promise<void> => {
|
|
36
|
+
const directory: string[] = await fs.promises.readdir(location);
|
|
37
|
+
for (const file of directory) {
|
|
38
|
+
const next: string = path.resolve(`${location}/${file}`);
|
|
39
|
+
const stats: fs.Stats = await fs.promises.stat(next);
|
|
40
|
+
|
|
41
|
+
if (stats.isDirectory() === true)
|
|
42
|
+
await iterate(filter)(closure)(next);
|
|
43
|
+
else if (stats.isFile() && filter(next)) closure(next);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const _Glob = (pattern: string): Promise<string[]> =>
|
|
48
|
+
new Promise((resolve, reject) => {
|
|
49
|
+
glob(pattern, (err, matches) => {
|
|
50
|
+
if (err) reject(err);
|
|
51
|
+
else resolve(matches.map((str) => path.resolve(str)));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface IProps {
|
|
57
|
+
exclude?: string[];
|
|
58
|
+
include: string[];
|
|
59
|
+
filter: (location: string) => boolean;
|
|
60
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SourceFinder = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const glob_1 = __importDefault(require("glob"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
var SourceFinder;
|
|
20
|
-
(function (SourceFinder) {
|
|
21
|
-
function find(input) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const dict = new Set();
|
|
24
|
-
yield decode(input.include, (str) => dict.add(str));
|
|
25
|
-
if (input.exclude)
|
|
26
|
-
yield decode(input.exclude, (str) => dict.delete(str));
|
|
27
|
-
return [...dict];
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
SourceFinder.find = find;
|
|
31
|
-
function decode(input, closure) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
for (const pattern of input) {
|
|
34
|
-
for (const location of yield _Glob(path_1.default.resolve(pattern))) {
|
|
35
|
-
const stats = yield fs_1.default.promises.stat(location);
|
|
36
|
-
if (stats.isDirectory() === true)
|
|
37
|
-
yield iterate(closure, location);
|
|
38
|
-
else if (stats.isFile() && _Is_ts_file(location))
|
|
39
|
-
closure(location);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function iterate(closure, location) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const directory = yield fs_1.default.promises.readdir(location);
|
|
47
|
-
for (const file of directory) {
|
|
48
|
-
const next = path_1.default.resolve(`${location}/${file}`);
|
|
49
|
-
const stats = yield fs_1.default.promises.stat(next);
|
|
50
|
-
if (stats.isDirectory() === true)
|
|
51
|
-
yield iterate(closure, next);
|
|
52
|
-
else if (stats.isFile() && _Is_ts_file(file))
|
|
53
|
-
closure(next);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
function _Glob(pattern) {
|
|
58
|
-
return new Promise((resolve, reject) => {
|
|
59
|
-
(0, glob_1.default)(pattern, (err, matches) => {
|
|
60
|
-
if (err)
|
|
61
|
-
reject(err);
|
|
62
|
-
else
|
|
63
|
-
resolve(matches.map((str) => path_1.default.resolve(str)));
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function _Is_ts_file(file) {
|
|
68
|
-
return file.substr(-3) === ".ts" && file.substr(-5) !== ".d.ts";
|
|
69
|
-
}
|
|
70
|
-
})(SourceFinder = exports.SourceFinder || (exports.SourceFinder = {}));
|
|
71
|
-
//# sourceMappingURL=SourceFinder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SourceFinder.js","sourceRoot":"","sources":["../../src/analyses/SourceFinder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,gDAAwB;AAIxB,IAAiB,YAAY,CAoD5B;AApDD,WAAiB,YAAY;IACzB,SAAsB,IAAI,CAAC,KAA2B;;YAClD,MAAM,IAAI,GAAgB,IAAI,GAAG,EAAE,CAAC;YAEpC,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACpD,IAAI,KAAK,CAAC,OAAO;gBACb,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAE3D,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACrB,CAAC;KAAA;IARqB,iBAAI,OAQzB,CAAA;IAED,SAAe,MAAM,CACjB,KAAe,EACf,OAAmC;;YAEnC,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE;gBACzB,KAAK,MAAM,QAAQ,IAAI,MAAM,KAAK,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE;oBACvD,MAAM,KAAK,GAAa,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;oBACzD,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI;wBAC5B,MAAM,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;yBAChC,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,WAAW,CAAC,QAAQ,CAAC;wBAC5C,OAAO,CAAC,QAAQ,CAAC,CAAC;iBACzB;aACJ;QACL,CAAC;KAAA;IAED,SAAe,OAAO,CAClB,OAAmC,EACnC,QAAgB;;YAEhB,MAAM,SAAS,GAAa,MAAM,YAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAChE,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE;gBAC1B,MAAM,IAAI,GAAW,cAAI,CAAC,OAAO,CAAC,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;gBACzD,MAAM,KAAK,GAAa,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAErD,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI;oBAAE,MAAM,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;qBAC1D,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,WAAW,CAAC,IAAI,CAAC;oBAAE,OAAO,CAAC,IAAI,CAAC,CAAC;aAC/D;QACL,CAAC;KAAA;IAED,SAAS,KAAK,CAAC,OAAe;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,IAAA,cAAI,EAAC,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;gBAC3B,IAAI,GAAG;oBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;oBAChB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IACpE,CAAC;AACL,CAAC,EApDgB,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAoD5B"}
|