streamline-code-by-ikun2274 0.12.71 → 0.12.80
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/Example.js +0 -51
- package/package.json +1 -1
- package/src/Request/StreamlineCode.js +1 -3
- package/types/index.d.ts +91 -59
package/Example.js
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { setDbConfig,startServer,
|
|
2
|
-
DefineRoutePlus_A } from './src/StreamlineCodeIndex.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
setDbConfig({
|
|
8
|
-
host: 'localhost',
|
|
9
|
-
user: 'root', // 你的 MySQL 用户名
|
|
10
|
-
password: '123456', // 你的 MySQL 密码
|
|
11
|
-
database: 'my_test_db' // 数据库名
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
startServer({
|
|
17
|
-
port: 8008, // 端口配置
|
|
18
|
-
allowedOrigins: [ // 允许的域名
|
|
19
|
-
'http://127.0.0.1:5501',
|
|
20
|
-
'http://ztgame.click',
|
|
21
|
-
'http://60.205.158.63',
|
|
22
|
-
'http://localhost:5173'
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
DefineRoutePlus_A({
|
|
30
|
-
url: '/api/productlist',
|
|
31
|
-
method: 'get',
|
|
32
|
-
// 可选:内置中间件配置
|
|
33
|
-
BuiltinMid: {
|
|
34
|
-
//可选的中间件参数
|
|
35
|
-
Parameter: ['pagination:12', 'unifiedResponse', 'shuffle','requireAuth'] // 启用分页和统一响应
|
|
36
|
-
},
|
|
37
|
-
PlusHandler: {
|
|
38
|
-
db: {
|
|
39
|
-
table: 'productdb',
|
|
40
|
-
operation: 'select', // select/read 都可以
|
|
41
|
-
primaryKey: 'id',
|
|
42
|
-
fields: '*',
|
|
43
|
-
categoryField: 'category_id' // 可选,默认为 'category_id'
|
|
44
|
-
},
|
|
45
|
-
other: {
|
|
46
|
-
successMessage: '操作成功',
|
|
47
|
-
errorMessage: '操作失败',
|
|
48
|
-
customLogic: null // 可选,自定义逻辑函数
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
package/package.json
CHANGED
|
@@ -2,8 +2,6 @@ import express from 'express';
|
|
|
2
2
|
const app = express();
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
let s =['','']
|
|
6
|
-
|
|
7
5
|
import { ToolDb } from '../Databaseope/data.js';
|
|
8
6
|
import {
|
|
9
7
|
validateLogin, verifyUser, generateToken,
|
|
@@ -93,7 +91,7 @@ export const defineRoute = (options) => {
|
|
|
93
91
|
* @param {string} [options.PlusHandler.other.errorMessage='操作失败'] - 错误消息(可选)
|
|
94
92
|
* */
|
|
95
93
|
|
|
96
|
-
export function
|
|
94
|
+
export function StreamlineRouter(options) {
|
|
97
95
|
|
|
98
96
|
const {
|
|
99
97
|
url,
|
package/types/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
// types/index.d.ts
|
|
2
|
+
|
|
4
3
|
import express from 'express';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
|
|
6
|
+
// types/index.d.ts
|
|
7
|
+
|
|
8
|
+
// 数据库配置类型
|
|
9
9
|
export interface DbConfig {
|
|
10
|
-
/**
|
|
10
|
+
/** 数据库主机地址--- */
|
|
11
11
|
host: string;
|
|
12
12
|
/** 数据库用户名 */
|
|
13
13
|
user: string;
|
|
@@ -17,62 +17,60 @@ export interface DbConfig {
|
|
|
17
17
|
database: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
* 服务器配置接口
|
|
22
|
-
*/
|
|
20
|
+
// 服务器配置类型
|
|
23
21
|
export interface ServerConfig {
|
|
24
22
|
/** 服务器端口 */
|
|
25
23
|
port: number;
|
|
26
|
-
/**
|
|
24
|
+
/** 允许的域名 */
|
|
27
25
|
allowedOrigins: string[];
|
|
28
26
|
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
* 路由配置接口
|
|
32
|
-
*/
|
|
28
|
+
// 路由配置类型
|
|
33
29
|
export interface RouteConfig {
|
|
34
30
|
/** 路由路径 */
|
|
35
31
|
url: string;
|
|
36
|
-
/**
|
|
32
|
+
/** 路由方法 */
|
|
37
33
|
method: 'get' | 'post' | 'put' | 'delete';
|
|
38
34
|
/** 中间件数组 */
|
|
39
35
|
middlewares?: Array<Function>;
|
|
40
|
-
/** 内置中间件配置 */
|
|
41
36
|
BuiltinMid?: {
|
|
42
|
-
/**
|
|
37
|
+
/** 内置中间件参数 */
|
|
43
38
|
Parameter?: string | string[];
|
|
44
39
|
};
|
|
45
|
-
/** 额外处理选项 */
|
|
46
40
|
PlusHandler: {
|
|
47
41
|
/** 数据库操作配置 */
|
|
48
42
|
db: {
|
|
49
43
|
/** 数据库表名 */
|
|
50
44
|
table: string;
|
|
51
|
-
/**
|
|
45
|
+
/** 操作类型:create, read, update, delete, select */
|
|
52
46
|
operation: 'select' | 'read' | 'create' | 'update' | 'delete';
|
|
53
|
-
/**
|
|
47
|
+
/** 主键字段,默认为 'id' */
|
|
54
48
|
primaryKey?: string;
|
|
55
|
-
/**
|
|
49
|
+
/** 查询字段,默认为 '*' */
|
|
50
|
+
fields?: string;
|
|
51
|
+
/** 分类字段,默认为 'category_id' */
|
|
52
|
+
categoryField?: string;
|
|
53
|
+
/** 查询字段,默认为 '*' */
|
|
56
54
|
fields?: string;
|
|
57
|
-
/**
|
|
55
|
+
/** 分类字段,默认为 'category_id' */
|
|
58
56
|
categoryField?: string;
|
|
59
57
|
};
|
|
60
|
-
/** 模式配置 */
|
|
58
|
+
/** 模式配置 可选 */
|
|
61
59
|
Mode?: {
|
|
62
|
-
/**
|
|
60
|
+
/** 分页,默认为 false */
|
|
63
61
|
pagination?: boolean;
|
|
64
|
-
/**
|
|
62
|
+
/** 是否需要认证,默认为 false */
|
|
65
63
|
requireAuth?: boolean;
|
|
66
|
-
/**
|
|
64
|
+
/** 是否随机,默认为 false */
|
|
67
65
|
shuffle?: boolean;
|
|
68
|
-
/**
|
|
66
|
+
/** 每页数量,默认为 10 */
|
|
69
67
|
pageSize?: number;
|
|
70
68
|
};
|
|
71
69
|
/** 其他配置 */
|
|
72
70
|
other: {
|
|
73
|
-
/**
|
|
71
|
+
/** 成功消息,默认为 '操作成功' */
|
|
74
72
|
successMessage?: string;
|
|
75
|
-
/**
|
|
73
|
+
/** 错误消息,默认为 '操作失败' */
|
|
76
74
|
errorMessage?: string;
|
|
77
75
|
/** 自定义逻辑函数 */
|
|
78
76
|
customLogic?: Function;
|
|
@@ -80,9 +78,35 @@ export interface RouteConfig {
|
|
|
80
78
|
};
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
// 函数类型定义
|
|
82
|
+
export function setDbConfig(config: DbConfig): void;
|
|
83
|
+
export function startServer(config: ServerConfig): void;
|
|
84
|
+
export function DefineRoutePlus_A(config: RouteConfig): void;
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/** 数据库配置接口 */
|
|
90
|
+
export interface setDbConfig {
|
|
91
|
+
/** 数据库主机地址 */
|
|
92
|
+
host: string;
|
|
93
|
+
/** 数据库用户名 */
|
|
94
|
+
user: string;
|
|
95
|
+
/** 数据库密码 */
|
|
96
|
+
password: string;
|
|
97
|
+
/** 数据库名称 */
|
|
98
|
+
database: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 服务器配置接口 */
|
|
102
|
+
export interface ServerConfig {
|
|
103
|
+
/** 服务器端口 */
|
|
104
|
+
port: number;
|
|
105
|
+
/** 数据库配置 */
|
|
106
|
+
db: DbConfig;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 数据库操作配置接口 */
|
|
86
110
|
export interface DbOperationConfig {
|
|
87
111
|
/** 数据库表名 */
|
|
88
112
|
table: string;
|
|
@@ -96,9 +120,7 @@ export interface DbOperationConfig {
|
|
|
96
120
|
categoryField?: string;
|
|
97
121
|
}
|
|
98
122
|
|
|
99
|
-
/**
|
|
100
|
-
* 其他配置接口
|
|
101
|
-
*/
|
|
123
|
+
/** 其他配置接口 */
|
|
102
124
|
export interface OtherConfig {
|
|
103
125
|
/** 自定义逻辑函数 */
|
|
104
126
|
customLogic?: (req: express.Request, res: express.Response, ToolDb: any, successMessage: string, errorMessage: string) => Promise<any>;
|
|
@@ -108,17 +130,12 @@ export interface OtherConfig {
|
|
|
108
130
|
errorMessage?: string;
|
|
109
131
|
}
|
|
110
132
|
|
|
111
|
-
/**
|
|
112
|
-
* 内置中间件配置接口
|
|
113
|
-
*/
|
|
114
133
|
export interface BuiltinMidConfig {
|
|
115
134
|
/** 中间件参数,可以是字符串或字符串数组 */
|
|
116
135
|
Parameter: string | string[];
|
|
117
136
|
}
|
|
118
137
|
|
|
119
|
-
/**
|
|
120
|
-
* 路由配置接口(新版)
|
|
121
|
-
*/
|
|
138
|
+
/** 路由配置接口 */
|
|
122
139
|
export interface RouteConfig {
|
|
123
140
|
/** 路由路径 */
|
|
124
141
|
url: string;
|
|
@@ -139,9 +156,7 @@ export interface RouteConfig {
|
|
|
139
156
|
};
|
|
140
157
|
}
|
|
141
158
|
|
|
142
|
-
/**
|
|
143
|
-
* 数据库操作工具类
|
|
144
|
-
*/
|
|
159
|
+
/** 数据库操作工具类 */
|
|
145
160
|
export interface ToolDb {
|
|
146
161
|
/**
|
|
147
162
|
* 查询单条记录
|
|
@@ -151,7 +166,7 @@ export interface ToolDb {
|
|
|
151
166
|
* @returns 查询结果
|
|
152
167
|
*/
|
|
153
168
|
findOne(table: string, where?: any, fields?: string[]): Promise<any>;
|
|
154
|
-
|
|
169
|
+
|
|
155
170
|
/**
|
|
156
171
|
* 查询多条记录
|
|
157
172
|
* @param table 表名
|
|
@@ -161,7 +176,7 @@ export interface ToolDb {
|
|
|
161
176
|
* @returns 查询结果数组
|
|
162
177
|
*/
|
|
163
178
|
find(table: string, where?: any, fields?: string[], options?: any): Promise<any[]>;
|
|
164
|
-
|
|
179
|
+
|
|
165
180
|
/**
|
|
166
181
|
* 插入记录
|
|
167
182
|
* @param table 表名
|
|
@@ -169,7 +184,7 @@ export interface ToolDb {
|
|
|
169
184
|
* @returns 插入结果
|
|
170
185
|
*/
|
|
171
186
|
create(table: string, data: any): Promise<any>;
|
|
172
|
-
|
|
187
|
+
|
|
173
188
|
/**
|
|
174
189
|
* 更新记录
|
|
175
190
|
* @param table 表名
|
|
@@ -178,7 +193,7 @@ export interface ToolDb {
|
|
|
178
193
|
* @returns 是否更新成功
|
|
179
194
|
*/
|
|
180
195
|
update(table: string, data: any, where: any): Promise<boolean>;
|
|
181
|
-
|
|
196
|
+
|
|
182
197
|
/**
|
|
183
198
|
* 删除记录
|
|
184
199
|
* @param table 表名
|
|
@@ -189,18 +204,37 @@ export interface ToolDb {
|
|
|
189
204
|
}
|
|
190
205
|
|
|
191
206
|
/**
|
|
192
|
-
*
|
|
193
|
-
* @param options 路由配置选项
|
|
207
|
+
* StreamlineRouter低代码函数
|
|
208
|
+
* @param {Object} options - 路由配置选项
|
|
209
|
+
* @param {string} options.url - 路由路径(必填)
|
|
210
|
+
* @param {string} options.method - HTTP 方法(GET/POST/PUT/DELETE,必填)
|
|
211
|
+
* @param {Array<Function>} [options.middlewares=[]] - 中间件数组(可选 用户自定义中间件)--作者会尽可能集成中间件
|
|
212
|
+
* @param {Object} options.PlusHandler - 额外处理选项(必填)
|
|
213
|
+
* @param {Object} options.PlusHandler.db - 数据库操作(必填)
|
|
214
|
+
* @param {string} options.PlusHandler.db.table - 数据库表名(必填)
|
|
215
|
+
* @param {string} options.PlusHandler.db.operation - 数据表操作(必填)select/insert/update/update/delete
|
|
216
|
+
* @param {string} [options.PlusHandler.db.primaryKey='id'] - 主键字段(可选)
|
|
217
|
+
* @param {string} [options.PlusHandler.db.fields='*'] - 查询字段(可选)
|
|
218
|
+
* @param {string} [options.PlusHandler.db.categoryField='category_id'] - 分类字段(可选)
|
|
219
|
+
* @param {object} [options.BuiltinMid.Parameter=[]] - 中间件参数(可选的内置中间件)填一个激活一个
|
|
220
|
+
* 'requireAuth': () => verifyToken,验证用户身份中间件
|
|
221
|
+
* 'login': () => [validateLogin, verifyUser, generateToken],登陆中间件集合
|
|
222
|
+
* 'register': () => [validateRegister, checkUsername],注册中间件集合
|
|
223
|
+
* 'categoryFilter': (field = categoryField) => categoryFilter(field),分类筛选中间件
|
|
224
|
+
* 'pagination': (size = 10) => Dpagination(Number(size)),分页中间件
|
|
225
|
+
* 'shuffle': () => shuffleData,打乱数据中间件
|
|
226
|
+
* 'unifiedResponse': (message = successMessage) => unifiedResponse(message),统一响应中间件
|
|
227
|
+
* @param {Object} options.PlusHandler.other - 其他选项(必填)
|
|
228
|
+
* @param {string} [options.PlusHandler.other.successMessage='操作成功'] - 成功消息(可选)
|
|
229
|
+
* @param {string} [options.PlusHandler.other.errorMessage='操作失败'] - 错误消息(可选)
|
|
230
|
+
*
|
|
194
231
|
*/
|
|
195
|
-
|
|
232
|
+
|
|
233
|
+
export function StreamlineRouter(options: RouteConfig): void;
|
|
196
234
|
|
|
197
235
|
/**
|
|
198
236
|
* 二次封装 Express 路由注册
|
|
199
237
|
* @param options 路由配置选项
|
|
200
|
-
* @param options.url 路由路径
|
|
201
|
-
* @param options.method HTTP 方法
|
|
202
|
-
* @param options.middlewares 中间件数组
|
|
203
|
-
* @param options.handler 业务逻辑处理函数
|
|
204
238
|
*/
|
|
205
239
|
export function defineRoute(options: {
|
|
206
240
|
url: string;
|
|
@@ -217,10 +251,6 @@ export const ToolDb: ToolDb;
|
|
|
217
251
|
/**
|
|
218
252
|
* 设置数据库配置
|
|
219
253
|
* @param config 数据库配置
|
|
220
|
-
* @param config.host 数据库主机地址
|
|
221
|
-
* @param config.user 数据库用户名
|
|
222
|
-
* @param config.password 数据库密码
|
|
223
|
-
* @param config.database 数据库名称
|
|
224
254
|
*/
|
|
225
255
|
export function setDbConfig(config: Partial<DbConfig>): void;
|
|
226
256
|
|
|
@@ -239,7 +269,9 @@ export function query(sql: string, params?: any[]): Promise<any>;
|
|
|
239
269
|
* @param options.allowedOrigins 允许的域名列表
|
|
240
270
|
*/
|
|
241
271
|
export function startServer(options?: {
|
|
272
|
+
/** 服务器端口,默认3001 */
|
|
242
273
|
port?: number;
|
|
274
|
+
/** 允许的域名列表 */
|
|
243
275
|
allowedOrigins?: string[];
|
|
244
276
|
}): void;
|
|
245
277
|
|