feat: add type dts and apiKeyObject

This commit is contained in:
2024-07-01 01:02:35 +08:00
parent f3c0707666
commit 9d4a4947e7
9 changed files with 509 additions and 18 deletions

View File

@@ -13,6 +13,7 @@ export type CodeManager = {
status?: CodeStatus;
errorMsg?: string;
} & Partial<RouterCode>;
const codeDemoRun = `async function run(ctx) {
ctx.body = 'test js';
return ctx;

View File

@@ -170,7 +170,19 @@ getRouterApi.run = async (ctx) => {
validator: item.validator,
};
});
ctx.body = apiList;
const apiKeyObject = apiList.reduce((pre: any, cur: any) => {
pre[cur.key] = {
path: cur.path,
key: cur.key,
description: cur.description || '',
validator: cur.validator || {},
};
return pre;
}, {});
ctx.body = {
list: apiList,
keyObject: apiKeyObject,
};
return ctx;
};
getRouterApi.validator = {

3
src/type.ts Normal file
View File

@@ -0,0 +1,3 @@
import { CodeManager } from './admin/dashboard/load.ts';
export { CodeManager };

5
src/utils/filter.ts Normal file
View File

@@ -0,0 +1,5 @@
// 过滤掉值为 null 的字段
export const filterNull = (updateData: Record<string, any>) => {
const filteredData = Object.fromEntries(Object.entries(updateData).filter(([_, v]) => v !== null));
return filteredData;
};