streamline-code-by-ikun2274 0.12.7 → 0.12.72
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 +1 -1
- package/src/Request/StreamlineCode.js +13 -10
- package/types/index.d.ts +67 -50
package/package.json
CHANGED
|
@@ -93,7 +93,7 @@ export const defineRoute = (options) => {
|
|
|
93
93
|
* @param {string} [options.PlusHandler.other.errorMessage='操作失败'] - 错误消息(可选)
|
|
94
94
|
* */
|
|
95
95
|
|
|
96
|
-
export function
|
|
96
|
+
export function StreamlineRouter(options) {
|
|
97
97
|
|
|
98
98
|
const {
|
|
99
99
|
url,
|
|
@@ -193,15 +193,18 @@ export function DefineRoutePlus_A(options) {
|
|
|
193
193
|
// 处理创建操作
|
|
194
194
|
let createData = req.body;
|
|
195
195
|
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
// 如果需要自动生成ID
|
|
197
|
+
if (autoGenerateId) {
|
|
198
|
+
// 直接使用generateId中间件的逻辑
|
|
199
|
+
const records = await ToolDb.find(table);
|
|
200
|
+
const ids = Array.isArray(records)
|
|
201
|
+
? records.map(record => record[primaryKey])
|
|
202
|
+
.filter(id => id !== null && id !== undefined && typeof id === 'number')
|
|
203
|
+
: [];
|
|
204
|
+
const maxId = ids.length > 0 ? Math.max(...ids) : 0;
|
|
205
|
+
const newId = maxId + 1;
|
|
206
|
+
createData = { [primaryKey]: newId, ...createData };
|
|
207
|
+
}
|
|
205
208
|
|
|
206
209
|
await ToolDb.create(table, createData);
|
|
207
210
|
break;
|
package/types/index.d.ts
CHANGED
|
@@ -1,83 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 类型定义文件
|
|
3
|
+
*/
|
|
3
4
|
import express from 'express';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// 数据库配置类型
|
|
6
|
+
/**
|
|
7
|
+
* 数据库配置接口
|
|
8
|
+
*/
|
|
9
9
|
export interface DbConfig {
|
|
10
|
+
/** 数据库主机地址 */
|
|
10
11
|
host: string;
|
|
12
|
+
/** 数据库用户名 */
|
|
11
13
|
user: string;
|
|
14
|
+
/** 数据库密码 */
|
|
12
15
|
password: string;
|
|
16
|
+
/** 数据库名称 */
|
|
13
17
|
database: string;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* 服务器配置接口
|
|
22
|
+
*/
|
|
17
23
|
export interface ServerConfig {
|
|
24
|
+
/** 服务器端口 */
|
|
18
25
|
port: number;
|
|
26
|
+
/** 允许的域名列表 */
|
|
19
27
|
allowedOrigins: string[];
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
/**
|
|
31
|
+
* 路由配置接口
|
|
32
|
+
*/
|
|
23
33
|
export interface RouteConfig {
|
|
34
|
+
/** 路由路径 */
|
|
24
35
|
url: string;
|
|
36
|
+
/** HTTP 方法 */
|
|
25
37
|
method: 'get' | 'post' | 'put' | 'delete';
|
|
38
|
+
/** 中间件数组 */
|
|
26
39
|
middlewares?: Array<Function>;
|
|
40
|
+
/** 内置中间件配置 */
|
|
27
41
|
BuiltinMid?: {
|
|
42
|
+
/** 中间件参数 */
|
|
28
43
|
Parameter?: string | string[];
|
|
29
44
|
};
|
|
45
|
+
/** 额外处理选项 */
|
|
30
46
|
PlusHandler: {
|
|
47
|
+
/** 数据库操作配置 */
|
|
31
48
|
db: {
|
|
49
|
+
/** 数据库表名 */
|
|
32
50
|
table: string;
|
|
51
|
+
/** 操作类型 */
|
|
33
52
|
operation: 'select' | 'read' | 'create' | 'update' | 'delete';
|
|
53
|
+
/** 主键字段 */
|
|
34
54
|
primaryKey?: string;
|
|
55
|
+
/** 查询字段 */
|
|
35
56
|
fields?: string;
|
|
57
|
+
/** 分类字段 */
|
|
36
58
|
categoryField?: string;
|
|
37
59
|
};
|
|
60
|
+
/** 模式配置 */
|
|
38
61
|
Mode?: {
|
|
62
|
+
/** 是否启用分页 */
|
|
39
63
|
pagination?: boolean;
|
|
64
|
+
/** 是否需要认证 */
|
|
40
65
|
requireAuth?: boolean;
|
|
66
|
+
/** 是否打乱数据 */
|
|
41
67
|
shuffle?: boolean;
|
|
68
|
+
/** 分页大小 */
|
|
42
69
|
pageSize?: number;
|
|
43
70
|
};
|
|
71
|
+
/** 其他配置 */
|
|
44
72
|
other: {
|
|
73
|
+
/** 成功消息 */
|
|
45
74
|
successMessage?: string;
|
|
75
|
+
/** 错误消息 */
|
|
46
76
|
errorMessage?: string;
|
|
77
|
+
/** 自定义逻辑函数 */
|
|
47
78
|
customLogic?: Function;
|
|
48
79
|
};
|
|
49
80
|
};
|
|
50
81
|
}
|
|
51
82
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export function DefineRoutePlus_A(config: RouteConfig): void;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/** 数据库配置接口 */
|
|
61
|
-
export interface setDbConfig {
|
|
62
|
-
/** 数据库主机地址 */
|
|
63
|
-
host: string;
|
|
64
|
-
/** 数据库用户名 */
|
|
65
|
-
user: string;
|
|
66
|
-
/** 数据库密码 */
|
|
67
|
-
password: string;
|
|
68
|
-
/** 数据库名称 */
|
|
69
|
-
database: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** 服务器配置接口 */
|
|
73
|
-
export interface ServerConfig {
|
|
74
|
-
/** 服务器端口 */
|
|
75
|
-
port: number;
|
|
76
|
-
/** 数据库配置 */
|
|
77
|
-
db: DbConfig;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** 数据库操作配置接口 */
|
|
83
|
+
/**
|
|
84
|
+
* 数据库操作配置接口
|
|
85
|
+
*/
|
|
81
86
|
export interface DbOperationConfig {
|
|
82
87
|
/** 数据库表名 */
|
|
83
88
|
table: string;
|
|
@@ -91,7 +96,9 @@ export interface DbOperationConfig {
|
|
|
91
96
|
categoryField?: string;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* 其他配置接口
|
|
101
|
+
*/
|
|
95
102
|
export interface OtherConfig {
|
|
96
103
|
/** 自定义逻辑函数 */
|
|
97
104
|
customLogic?: (req: express.Request, res: express.Response, ToolDb: any, successMessage: string, errorMessage: string) => Promise<any>;
|
|
@@ -101,13 +108,17 @@ export interface OtherConfig {
|
|
|
101
108
|
errorMessage?: string;
|
|
102
109
|
}
|
|
103
110
|
|
|
104
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* 内置中间件配置接口
|
|
113
|
+
*/
|
|
105
114
|
export interface BuiltinMidConfig {
|
|
106
115
|
/** 中间件参数,可以是字符串或字符串数组 */
|
|
107
116
|
Parameter: string | string[];
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
/**
|
|
119
|
+
/**
|
|
120
|
+
* 路由配置接口(新版)
|
|
121
|
+
*/
|
|
111
122
|
export interface RouteConfig {
|
|
112
123
|
/** 路由路径 */
|
|
113
124
|
url: string;
|
|
@@ -128,7 +139,9 @@ export interface RouteConfig {
|
|
|
128
139
|
};
|
|
129
140
|
}
|
|
130
141
|
|
|
131
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* 数据库操作工具类
|
|
144
|
+
*/
|
|
132
145
|
export interface ToolDb {
|
|
133
146
|
/**
|
|
134
147
|
* 查询单条记录
|
|
@@ -176,11 +189,7 @@ export interface ToolDb {
|
|
|
176
189
|
}
|
|
177
190
|
|
|
178
191
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param options 路由配置选项
|
|
181
|
-
*
|
|
182
|
-
* /**
|
|
183
|
-
* 二次封装 defineRoute
|
|
192
|
+
* StreamlineRouter低代码 --路由注册函数
|
|
184
193
|
* @param {Object} options - 路由配置选项
|
|
185
194
|
* @param {string} options.url - 路由路径(必填)
|
|
186
195
|
* @param {string} options.method - HTTP 方法(GET/POST/PUT/DELETE,必填)
|
|
@@ -200,17 +209,21 @@ export interface ToolDb {
|
|
|
200
209
|
* 'pagination': (size = 10) => Dpagination(Number(size)),分页中间件
|
|
201
210
|
* 'shuffle': () => shuffleData,打乱数据中间件
|
|
202
211
|
* 'unifiedResponse': (message = successMessage) => unifiedResponse(message),统一响应中间件
|
|
212
|
+
*
|
|
213
|
+
*
|
|
203
214
|
* @param {Object} options.PlusHandler.other - 其他选项(必填)
|
|
204
215
|
* @param {string} [options.PlusHandler.other.successMessage='操作成功'] - 成功消息(可选)
|
|
205
216
|
* @param {string} [options.PlusHandler.other.errorMessage='操作失败'] - 错误消息(可选)
|
|
206
|
-
*
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
export function DefineRoutePlus_A(options: RouteConfig): void;
|
|
217
|
+
* */
|
|
218
|
+
export function StreamlineRouter(options: RouteConfig): void;
|
|
210
219
|
|
|
211
220
|
/**
|
|
212
221
|
* 二次封装 Express 路由注册
|
|
213
222
|
* @param options 路由配置选项
|
|
223
|
+
* @param options.url 路由路径
|
|
224
|
+
* @param options.method HTTP 方法
|
|
225
|
+
* @param options.middlewares 中间件数组
|
|
226
|
+
* @param options.handler 业务逻辑处理函数
|
|
214
227
|
*/
|
|
215
228
|
export function defineRoute(options: {
|
|
216
229
|
url: string;
|
|
@@ -227,6 +240,10 @@ export const ToolDb: ToolDb;
|
|
|
227
240
|
/**
|
|
228
241
|
* 设置数据库配置
|
|
229
242
|
* @param config 数据库配置
|
|
243
|
+
* @param config.host 数据库主机地址
|
|
244
|
+
* @param config.user 数据库用户名
|
|
245
|
+
* @param config.password 数据库密码
|
|
246
|
+
* @param config.database 数据库名称
|
|
230
247
|
*/
|
|
231
248
|
export function setDbConfig(config: Partial<DbConfig>): void;
|
|
232
249
|
|