koa-ts-core 0.2.0 → 0.2.2
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/README.md +1 -0
- package/dist/decorate/router_decorate.d.ts +7 -9
- package/dist/index.cjs.js +8 -8
- package/dist/index.esm.js +8 -8
- package/dist/init/register_controller.d.ts +5 -3
- package/dist/init/register_env.d.ts +10 -1
- package/dist/init/register_route.d.ts +2 -2
- package/dist/init/render_doc.d.ts +6 -0
- package/dist/types/route.d.ts +1 -2
- package/dist/utils/funtions.d.ts +1 -0
- package/dist/utils/path.d.ts +11 -29
- package/package.json +2 -3
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { AuthRouterCallback } from '../types/route';
|
|
2
2
|
/**
|
|
3
3
|
* 约定式控制器注册路由
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* - 扫描 controller 目录下的所有控制器文件
|
|
5
|
+
* - 读取其中由装饰器收集的 routesMap
|
|
6
|
+
* - 为每个控制器注册路由(挂载鉴权与参数校验)
|
|
7
|
+
*
|
|
8
|
+
* @param authCheckCallback 鉴权回调(配合 @AuthRouter 使用)
|
|
7
9
|
*/
|
|
8
10
|
declare const registerControllers: (authCheckCallback?: AuthRouterCallback) => void;
|
|
9
11
|
export default registerControllers;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 初始化dotenv
|
|
2
|
+
* 初始化 dotenv
|
|
3
|
+
*
|
|
4
|
+
* 搜索 env 目录优先级:
|
|
5
|
+
* 1. process.env.ENV_DIR(可为绝对或相对路径)
|
|
6
|
+
* 2. <src>/env
|
|
7
|
+
* 3. <projectRoot>/env(即 src 的上一级)
|
|
8
|
+
*
|
|
9
|
+
* 加载顺序:
|
|
10
|
+
* 1. .common.env
|
|
11
|
+
* 2. .development.env / .test.env / .production.env (按 NODE_ENV)
|
|
3
12
|
*/
|
|
4
13
|
declare const initializeDotenv: () => void;
|
|
5
14
|
export default initializeDotenv;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AuthRouterHandler, FilePathMeta, RouteConfig } from '../types/route';
|
|
2
2
|
/**
|
|
3
3
|
* 注册路由
|
|
4
|
-
* @param validateModulePath
|
|
5
|
-
* @param filePath
|
|
4
|
+
* @param validateModulePath validate 根目录路径
|
|
5
|
+
* @param filePath 控制器文件路径元信息
|
|
6
6
|
* @param routesMap 路由映射
|
|
7
7
|
* @param authCheckResult 鉴权结果处理函数
|
|
8
8
|
*/
|
package/dist/types/route.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, Middleware } from "koa";
|
|
2
2
|
import type { Dirent } from "fs";
|
|
3
|
-
export type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options";
|
|
3
|
+
export type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
|
|
4
4
|
/** 文件路径元数据 */
|
|
5
5
|
export interface FilePathMeta {
|
|
6
6
|
path: string;
|
|
@@ -16,7 +16,6 @@ export type WalkSyncHandler = (filePath: FilePathMeta, dirent: Dirent) => void;
|
|
|
16
16
|
export interface RouteConfig {
|
|
17
17
|
path: string;
|
|
18
18
|
method: HttpMethod;
|
|
19
|
-
/** 控制器函数(使用 Koa 标准 Middleware 类型) */
|
|
20
19
|
handler: Middleware;
|
|
21
20
|
functionName: string;
|
|
22
21
|
authRequired: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generateUuid: () => `${string}-${string}-${string}-${string}-${string}`;
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { FilePathMeta, WalkSyncHandler } from '../types/route';
|
|
1
|
+
import type { FilePathMeta, WalkSyncHandler } from '../types/route';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @returns 模块路径对象
|
|
3
|
+
* 获取 src 根目录
|
|
5
4
|
*/
|
|
6
5
|
export declare const getEntryPath: () => string;
|
|
7
6
|
/**
|
|
8
|
-
* 获取 src
|
|
9
|
-
* @returns 模块路径对象
|
|
7
|
+
* 获取 src 下各模块目录
|
|
10
8
|
*/
|
|
11
9
|
export declare const getSrcModulePaths: () => {
|
|
12
10
|
controllerModule: string;
|
|
@@ -16,20 +14,18 @@ export declare const getSrcModulePaths: () => {
|
|
|
16
14
|
};
|
|
17
15
|
/**
|
|
18
16
|
* 获取指定路径的默认导出
|
|
19
|
-
* @param {string} filePath - 文件路径
|
|
20
|
-
* @returns {T | undefined} - 文件的默认导出或 undefined
|
|
21
17
|
*/
|
|
22
18
|
export declare const getDefaultExportFromFile: <T = any>(filePath: string) => T | undefined;
|
|
23
19
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {string} currentDirPath - 当前目录路径
|
|
26
|
-
* @param {WalkSyncHandler} callback - 处理每个文件的回调函数
|
|
20
|
+
* 递归遍历指定目录下的所有文件
|
|
27
21
|
*/
|
|
28
22
|
export declare function walkDirectorySync(currentDirPath: string, callback: WalkSyncHandler): void;
|
|
29
23
|
/**
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
* 统一处理不同平台的文件路径格式,将路径转换为 '/test/file' 格式
|
|
25
|
+
*/
|
|
26
|
+
export declare const formatPathByPlatform: (filePath: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* 根据文件路径和关键字部分生成 controller 对应的路由前缀信息
|
|
33
29
|
*/
|
|
34
30
|
export declare const generateOptionsByKeyPart: (filePath: FilePathMeta, keyPart: string) => {
|
|
35
31
|
pathPrefix: string;
|
|
@@ -37,21 +33,7 @@ export declare const generateOptionsByKeyPart: (filePath: FilePathMeta, keyPart:
|
|
|
37
33
|
name: string;
|
|
38
34
|
};
|
|
39
35
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {string} filePath - 原始文件路径
|
|
42
|
-
* @returns {string} 转换后的文件路径
|
|
43
|
-
*/
|
|
44
|
-
export declare const formatPathByPlatform: (filePath: string) => string;
|
|
45
|
-
/**
|
|
46
|
-
* 确保文件存在,如果不存在则创建目录和文件
|
|
47
|
-
* @param {string} filePath - 要检查的文件路径
|
|
48
|
-
* @param {string} content - 文件内容,如果不指定,则为空文件
|
|
49
|
-
* @returns {boolean} 文件是否存在
|
|
50
|
-
*/
|
|
51
|
-
export declare function ensureFileExists(filePath: string, content?: string): boolean;
|
|
52
|
-
/**
|
|
53
|
-
* 检查文件夹是否存在
|
|
54
|
-
* @param targetPath - 目标路径
|
|
55
|
-
* @returns
|
|
36
|
+
* 把类似 "api/v1" 转成 "/api/v1"
|
|
56
37
|
*/
|
|
38
|
+
export declare const normalizeRoutePath: (p: string) => string;
|
|
57
39
|
export declare function folderExists(targetPath: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koa-ts-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "koa-ts-core",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -33,8 +33,7 @@
|
|
|
33
33
|
"portfinder": "^1.0.38",
|
|
34
34
|
"pug": "^3.0.3",
|
|
35
35
|
"rollup-plugin-copy-and-reference-dts": "0.0.2",
|
|
36
|
-
"rollup-plugin-pug": "^1.1.1"
|
|
37
|
-
"uuid": "^13.0.0"
|
|
36
|
+
"rollup-plugin-pug": "^1.1.1"
|
|
38
37
|
},
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@rollup/plugin-commonjs": "^29.0.0",
|