강력한 API 타입 체크

This commit is contained in:
2023-08-06 09:27:24 +00:00
parent 7352cdbf23
commit 826b4212e5
11 changed files with 266 additions and 445 deletions
+5 -12
View File
@@ -6,20 +6,13 @@ export function buildAPISystem<N extends APINamespace, Q extends APIExecuter<any
for (const [key, value] of Object.entries(api)) {
if (typeof value === 'function') {
const executer = new value() as Q;
if(!executer.reqType){
if (!executer.reqType) {
throw new Error('APIExecuter.reqType is not defined');
}
if(!Array.isArray(executer.reqType)){
router[executer.reqType](key, async (req, res) => {
await executer.run(req, res);
});
continue;
}
for(const type of new Set(executer.reqType)){
router[type](key, async (req, res) => {
await executer.run(req, res);
});
}
router[executer.reqType](key, async (req, res) => {
await executer.run(req, res);
});
continue;
} else {
router.use(key, buildAPISystem(value));
}