koa-ts-core 0.0.9-beta.2 → 0.0.9-beta.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/package.json +2 -3
- package/dist/base/exception.d.ts +0 -18
- package/dist/base/index.d.ts +0 -1
- package/dist/constant.d.ts +0 -5
- package/dist/decorate/index.d.ts +0 -1
- package/dist/decorate/router_decorate.d.ts +0 -16
- package/dist/index.cjs.js +0 -39
- package/dist/index.d.ts +0 -5
- package/dist/index.esm.js +0 -39
- package/dist/init/address.d.ts +0 -8
- package/dist/init/index.d.ts +0 -16
- package/dist/init/register_controller.d.ts +0 -9
- package/dist/init/register_env.d.ts +0 -5
- package/dist/init/register_route.d.ts +0 -10
- package/dist/init/render_doc.d.ts +0 -2
- package/dist/middleware/context_middleware.d.ts +0 -15
- package/dist/middleware/exception_middleware.d.ts +0 -10
- package/dist/middleware/request_params_middleware.d.ts +0 -7
- package/dist/router.d.ts +0 -2
- package/dist/types/meta_data.d.ts +0 -16
- package/dist/types/route.d.ts +0 -26
- package/dist/utils/context_store.d.ts +0 -8
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/path.d.ts +0 -46
- package/dist/utils/rsp.d.ts +0 -22
package/dist/init/address.d.ts
DELETED
package/dist/init/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import Koa from "koa";
|
|
2
|
-
import { TErrorCallback } from '../middleware/exception_middleware';
|
|
3
|
-
import { appRouter } from '../router';
|
|
4
|
-
import type { AuthRouterCallback } from '../types/route';
|
|
5
|
-
export type TInitOPtions = Partial<{
|
|
6
|
-
koaInstance: Koa;
|
|
7
|
-
authCheckCallback: AuthRouterCallback;
|
|
8
|
-
catchErrorCallback: TErrorCallback;
|
|
9
|
-
registerHighPriorityMiddleware: (app: Koa) => void;
|
|
10
|
-
}>;
|
|
11
|
-
/**
|
|
12
|
-
* 初始化core
|
|
13
|
-
* @param {TInitOPtions} options
|
|
14
|
-
* @returns {[Koa, typeof appRouter]} [app, appRouter]
|
|
15
|
-
*/
|
|
16
|
-
export declare const initializeKoaApp: (options: TInitOPtions) => Promise<[Koa, typeof appRouter]>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AuthRouterCallback } from '../types/route';
|
|
2
|
-
/**
|
|
3
|
-
* 约定式控制器注册路由
|
|
4
|
-
* @param controllerModulePath 控制器模块路径
|
|
5
|
-
* @param validateModulePath 验证模块路径
|
|
6
|
-
* @param authCallback 鉴权回调
|
|
7
|
-
*/
|
|
8
|
-
declare const registerControllers: (authCheckCallback?: AuthRouterCallback) => void;
|
|
9
|
-
export default registerControllers;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AuthRouterHandler, FilePathMeta, RouteConfig } from '../types/route';
|
|
2
|
-
/**
|
|
3
|
-
* 注册路由
|
|
4
|
-
* @param validateModulePath 参数验证器路径
|
|
5
|
-
* @param filePath 控制器文件路径
|
|
6
|
-
* @param routesMap 路由映射
|
|
7
|
-
* @param authCheckResult 鉴权结果处理函数
|
|
8
|
-
*/
|
|
9
|
-
declare const registerRoute: (validateModulePath: string, filePath: FilePathMeta, routesMap: Map<string, RouteConfig>, authCheckResult: AuthRouterHandler) => void;
|
|
10
|
-
export default registerRoute;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Middleware } from "koa";
|
|
2
|
-
/**
|
|
3
|
-
* Koa 上下文存储中间件
|
|
4
|
-
*
|
|
5
|
-
* 功能:
|
|
6
|
-
* 1. 为每个请求创建独立的上下文存储环境
|
|
7
|
-
* 2. 确保后续中间件和业务逻辑可以安全访问当前请求的上下文
|
|
8
|
-
* 3. 基于 AsyncLocalStorage 实现请求级别的数据隔离
|
|
9
|
-
*
|
|
10
|
-
* @param ctx Koa 上下文对象
|
|
11
|
-
* @param next 后续中间件执行函数
|
|
12
|
-
* @returns Promise<void>
|
|
13
|
-
*/
|
|
14
|
-
declare const contextMiddleware: Middleware;
|
|
15
|
-
export default contextMiddleware;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import BaseException from '../base/exception';
|
|
2
|
-
import type Koa from "koa";
|
|
3
|
-
export type TErrorCallback = (error: Error | BaseException, ctx: Koa.Context) => void;
|
|
4
|
-
/**
|
|
5
|
-
* 错误处理中间件
|
|
6
|
-
* @param {TErrorCallback} catchCallback
|
|
7
|
-
* @returns
|
|
8
|
-
*/
|
|
9
|
-
declare const catchErrorMiddleware: (catchCallback?: TErrorCallback) => (ctx: Koa.Context, next: Koa.Next) => Promise<void>;
|
|
10
|
-
export default catchErrorMiddleware;
|
package/dist/router.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface IMetaData {
|
|
2
|
-
method: string;
|
|
3
|
-
description: string;
|
|
4
|
-
path: string;
|
|
5
|
-
request: Request;
|
|
6
|
-
response: Response;
|
|
7
|
-
}
|
|
8
|
-
interface Response {
|
|
9
|
-
body: any;
|
|
10
|
-
}
|
|
11
|
-
interface Request {
|
|
12
|
-
header: Record<string, string>;
|
|
13
|
-
body: any;
|
|
14
|
-
query: any;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
package/dist/types/route.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Context, Middleware } from "koa";
|
|
2
|
-
import type { Dirent } from "fs";
|
|
3
|
-
export type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options";
|
|
4
|
-
/** 文件路径元数据 */
|
|
5
|
-
export interface FilePathMeta {
|
|
6
|
-
path: string;
|
|
7
|
-
name: string;
|
|
8
|
-
wholePath: string;
|
|
9
|
-
}
|
|
10
|
-
export type AuthRouterHandler = (isAuthRouter: boolean, ctx: Context) => Promise<boolean> | boolean;
|
|
11
|
-
export type AuthRouterCallback = (params: {
|
|
12
|
-
filePath: FilePathMeta;
|
|
13
|
-
ctx: Context;
|
|
14
|
-
}) => Promise<boolean> | boolean;
|
|
15
|
-
export type WalkSyncHandler = (filePath: FilePathMeta, dirent: Dirent) => void;
|
|
16
|
-
export interface RouteConfig {
|
|
17
|
-
path: string;
|
|
18
|
-
method: HttpMethod;
|
|
19
|
-
/** 控制器函数(使用 Koa 标准 Middleware 类型) */
|
|
20
|
-
handler: Middleware;
|
|
21
|
-
functionName: string;
|
|
22
|
-
authRequired: boolean;
|
|
23
|
-
middlewares: Middleware[];
|
|
24
|
-
className: string;
|
|
25
|
-
apiPrePath: string;
|
|
26
|
-
}
|
package/dist/utils/index.d.ts
DELETED
package/dist/utils/path.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { FilePathMeta, WalkSyncHandler } from '../types/route';
|
|
2
|
-
/**
|
|
3
|
-
* 获取 src 模块的路径
|
|
4
|
-
* @returns 模块路径对象
|
|
5
|
-
*/
|
|
6
|
-
export declare const getSrcModulePaths: () => {
|
|
7
|
-
controllerModule: string;
|
|
8
|
-
validateModule: string;
|
|
9
|
-
viewModule: string;
|
|
10
|
-
docModule: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* 获取指定路径的默认导出
|
|
14
|
-
* @param {string} filePath - 文件路径
|
|
15
|
-
* @returns {T | undefined} - 文件的默认导出或 undefined
|
|
16
|
-
*/
|
|
17
|
-
export declare const getDefaultExportFromFile: <T = any>(filePath: string) => T | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* 递归同步遍历指定目录下的所有文件
|
|
20
|
-
* @param {string} currentDirPath - 当前目录路径
|
|
21
|
-
* @param {WalkSyncHandler} callback - 处理每个文件的回调函数
|
|
22
|
-
*/
|
|
23
|
-
export declare function walkDirectorySync(currentDirPath: string, callback: WalkSyncHandler): void;
|
|
24
|
-
/**
|
|
25
|
-
* 根据文件路径和关键字部分生成路径的模块选项
|
|
26
|
-
* @param {FilePathMeta} filePath - 文件路径元数据
|
|
27
|
-
* @returns {Object} 包含控制器前缀、模块名和文件名的对象
|
|
28
|
-
*/
|
|
29
|
-
export declare const generateOptionsByKeyPart: (filePath: FilePathMeta, keyPart: string) => {
|
|
30
|
-
pathPrefix: string;
|
|
31
|
-
moduleName: string;
|
|
32
|
-
name: string;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* 统一处理不同平台的文件路径格式,将路径转换为 '/test/file' 格式
|
|
36
|
-
* @param {string} filePath - 原始文件路径
|
|
37
|
-
* @returns {string} 转换后的文件路径
|
|
38
|
-
*/
|
|
39
|
-
export declare const formatPathByPlatform: (filePath: string) => string;
|
|
40
|
-
/**
|
|
41
|
-
* 确保文件存在,如果不存在则创建目录和文件
|
|
42
|
-
* @param {string} filePath - 要检查的文件路径
|
|
43
|
-
* @param {string} content - 文件内容,如果不指定,则为空文件
|
|
44
|
-
* @returns {boolean} 文件是否存在
|
|
45
|
-
*/
|
|
46
|
-
export declare function ensureFileExists(filePath: string, content?: string): boolean;
|
package/dist/utils/rsp.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
type Options = Partial<{
|
|
2
|
-
data: any;
|
|
3
|
-
message: string;
|
|
4
|
-
code: number;
|
|
5
|
-
}>;
|
|
6
|
-
/**
|
|
7
|
-
* 构建成功的请求响应
|
|
8
|
-
* @param options - 成功响应的选项,如数据和消息
|
|
9
|
-
*/
|
|
10
|
-
export declare const successRsp: (options?: Options) => void;
|
|
11
|
-
/**
|
|
12
|
-
* 构建不成功的请求响应,但 HTTP 状态码仍为 200
|
|
13
|
-
* @param options - 包含可能的错误码、消息和数据
|
|
14
|
-
*/
|
|
15
|
-
export declare const unSuccessRsp: (options?: Options) => void;
|
|
16
|
-
/**
|
|
17
|
-
* 构建异常请求响应,HTTP 状态码不为 200
|
|
18
|
-
* @param statusCode - 要返回的 HTTP 状态码
|
|
19
|
-
* @param options - 包含可能的错误信息、数据等
|
|
20
|
-
*/
|
|
21
|
-
export declare const errorRsp: (statusCode: number, options?: Options) => void;
|
|
22
|
-
export {};
|