koa-ts-core 0.0.9-beta.1 → 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.
@@ -1,8 +0,0 @@
1
- import Koa from "koa";
2
- /**
3
- * 初始化服务
4
- * @param app - Koa 应用实例
5
- * @returns - 可用的端口号
6
- */
7
- declare const initializeServer: (app: Koa) => Promise<void>;
8
- export default initializeServer;
@@ -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,5 +0,0 @@
1
- /**
2
- * 初始化dotenv
3
- */
4
- declare const initializeDotenv: () => void;
5
- export default initializeDotenv;
@@ -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,2 +0,0 @@
1
- declare const generateDocHtml: () => Promise<string>;
2
- export default generateDocHtml;
@@ -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;
@@ -1,7 +0,0 @@
1
- import { Middleware } from "koa";
2
- /**
3
- * 往global添加属性
4
- * @param ctx
5
- */
6
- declare const requestParamsMiddleware: Middleware;
7
- export default requestParamsMiddleware;
package/dist/router.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import AppRouter from 'koa-router';
2
- export declare const appRouter: AppRouter<any, {}>;
@@ -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 {};
@@ -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
- }
@@ -1,8 +0,0 @@
1
- import { AsyncLocalStorage } from "async_hooks";
2
- import type { Context } from "koa";
3
- export declare const contextStore: AsyncLocalStorage<Context>;
4
- /**
5
- * 当前上下文
6
- * @returns
7
- */
8
- export declare const getCurrentContext: () => Context;
@@ -1,2 +0,0 @@
1
- export * from "./rsp";
2
- export * from "./context_store";
@@ -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;
@@ -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 {};