@maiyunnet/kebab 3.2.13 → 3.2.15
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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/net.d.ts +11 -3
- package/lib/net.js +24 -3
- package/lib/s3.d.ts +1 -1
- package/package.json +5 -5
- package/sys/child.js +2 -2
- package/sys/mod.d.ts +9 -13
- package/sys/mod.js +45 -71
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '3.2.
|
|
9
|
+
export const VER = '3.2.15';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/net.d.ts
CHANGED
|
@@ -34,11 +34,19 @@ export declare function get(u: string, opt?: IRequestOptions): Promise<lResponse
|
|
|
34
34
|
export declare function post(u: string, data: Record<string, kebab.Json> | Buffer | string | stream.Readable, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
35
35
|
/**
|
|
36
36
|
* --- 发起 JSON 请求 ---
|
|
37
|
-
* @param u
|
|
38
|
-
* @param data
|
|
39
|
-
* @param opt
|
|
37
|
+
* @param u 网址
|
|
38
|
+
* @param data 数据
|
|
39
|
+
* @param opt选项
|
|
40
40
|
*/
|
|
41
41
|
export declare function postJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<lResponse.Response>;
|
|
42
|
+
/**
|
|
43
|
+
* --- 发起 JSON 请求并解析 JSON 响应 ---
|
|
44
|
+
* @param url 网址
|
|
45
|
+
* @param data 数据
|
|
46
|
+
* @param init 选项
|
|
47
|
+
* @returns JSON 数据,失败时返回 null
|
|
48
|
+
*/
|
|
49
|
+
export declare function postJsonResponseJson(u: string, data: kebab.Json[] | Record<string, kebab.Json>, opt?: IRequestOptions): Promise<any | null>;
|
|
42
50
|
/**
|
|
43
51
|
* --- 发起一个请求 ---
|
|
44
52
|
* @param opt 配置项
|
package/lib/net.js
CHANGED
|
@@ -57,15 +57,36 @@ export async function post(u, data, opt = {}) {
|
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* --- 发起 JSON 请求 ---
|
|
60
|
-
* @param u
|
|
61
|
-
* @param data
|
|
62
|
-
* @param opt
|
|
60
|
+
* @param u 网址
|
|
61
|
+
* @param data 数据
|
|
62
|
+
* @param opt选项
|
|
63
63
|
*/
|
|
64
64
|
export async function postJson(u, data, opt = {}) {
|
|
65
65
|
opt.method = 'POST';
|
|
66
66
|
opt.type = 'json';
|
|
67
67
|
return request(u, data, opt);
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* --- 发起 JSON 请求并解析 JSON 响应 ---
|
|
71
|
+
* @param url 网址
|
|
72
|
+
* @param data 数据
|
|
73
|
+
* @param init 选项
|
|
74
|
+
* @returns JSON 数据,失败时返回 null
|
|
75
|
+
*/
|
|
76
|
+
export async function postJsonResponseJson(u, data, opt = {}) {
|
|
77
|
+
opt.method = 'POST';
|
|
78
|
+
opt.type = 'json';
|
|
79
|
+
const res = await request(u, data, opt);
|
|
80
|
+
const rtn = await res.getContent();
|
|
81
|
+
if (!rtn) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const json = lText.parseJson(rtn.toString());
|
|
85
|
+
if (!json) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return json;
|
|
89
|
+
}
|
|
69
90
|
/**
|
|
70
91
|
* --- 发起一个请求 ---
|
|
71
92
|
* @param opt 配置项
|
package/lib/s3.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export declare class S3 {
|
|
|
60
60
|
* @param key 对象路径
|
|
61
61
|
* @param bucket bucket 名
|
|
62
62
|
*/
|
|
63
|
-
getObject(key: string, bucket?: string): Promise<
|
|
63
|
+
getObject(key: string, bucket?: string): Promise<any>;
|
|
64
64
|
/**
|
|
65
65
|
* --- 删除对象 ---
|
|
66
66
|
* @param key 对象路径
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.15",
|
|
4
4
|
"description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"#kebab/*": "./*"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@aws-sdk/client-s3": "^3.
|
|
23
|
-
"@aws-sdk/lib-storage": "^3.
|
|
22
|
+
"@aws-sdk/client-s3": "^3.913.0",
|
|
23
|
+
"@aws-sdk/lib-storage": "^3.913.0",
|
|
24
24
|
"@litert/http-client": "^1.1.2",
|
|
25
25
|
"@litert/mime": "^0.1.3",
|
|
26
26
|
"@litert/redis": "^3.0.5",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"mysql2": "^3.15.2",
|
|
32
32
|
"ssh2": "^1.17.0",
|
|
33
33
|
"svg-captcha": "^1.4.0",
|
|
34
|
-
"tencentcloud-sdk-nodejs": "^4.1.
|
|
34
|
+
"tencentcloud-sdk-nodejs": "^4.1.133"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@litert/eslint-plugin-rules": "^0.3.1",
|
|
38
38
|
"@types/ejs": "^3.1.5",
|
|
39
|
-
"@types/node": "^24.
|
|
39
|
+
"@types/node": "^24.9.1",
|
|
40
40
|
"tsc-alias": "^1.8.16",
|
|
41
41
|
"typescript": "^5.9.3"
|
|
42
42
|
}
|
package/sys/child.js
CHANGED
|
@@ -294,7 +294,7 @@ async function requestHandler(req, res, https) {
|
|
|
294
294
|
'cookie': {},
|
|
295
295
|
'headers': {}
|
|
296
296
|
}, '[CHILD][requestHandler][E0]' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
|
|
297
|
-
const content = '<h1>500 Server Error</h1><hr>
|
|
297
|
+
const content = '<h1>500 Server Error</h1><hr>Kebab';
|
|
298
298
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
299
299
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
300
300
|
res.writeHead(500);
|
|
@@ -333,7 +333,7 @@ async function requestHandler(req, res, https) {
|
|
|
333
333
|
}
|
|
334
334
|
catch (e) {
|
|
335
335
|
lCore.log({}, '[CHILD][requestHandler][E1]' + lText.stringifyJson(e.stack).slice(1, -1), '-error');
|
|
336
|
-
const content = '<h1>500 Server Error</h1><hr>
|
|
336
|
+
const content = '<h1>500 Server Error</h1><hr>Kebab';
|
|
337
337
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
338
338
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
339
339
|
res.writeHead(500);
|
package/sys/mod.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type TOnlyProperties<T> = {
|
|
|
12
12
|
[K in keyof T as T[K] extends (...args: any[]) => any ? never : K]: T[K];
|
|
13
13
|
};
|
|
14
14
|
/** --- 条数列表 --- */
|
|
15
|
-
declare class Rows<T extends Mod> implements
|
|
15
|
+
declare class Rows<T extends Mod> implements IRows<T> {
|
|
16
16
|
private readonly _items;
|
|
17
17
|
constructor(initialItems?: T[]);
|
|
18
18
|
/** --- 总行数 --- */
|
|
@@ -24,8 +24,9 @@ declare class Rows<T extends Mod> implements CRows<T> {
|
|
|
24
24
|
/** --- 根据规则筛掉项,predicate 返回 true 代表保留 --- */
|
|
25
25
|
filter(predicate: (value: T, index: number) => boolean): Rows<T>;
|
|
26
26
|
/** --- 重塑对象内容 --- */
|
|
27
|
-
map<TU>(
|
|
28
|
-
|
|
27
|
+
map<TU extends Mod>(fn: (v: T, i: number) => TU): Rows<TU>;
|
|
28
|
+
/** --- for of --- */
|
|
29
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* --- 开启软更需要在表添加字段:ALTER TABLE `table_name` ADD `time_remove` bigint NOT NULL DEFAULT '0' AFTER `xxx`; ---
|
|
@@ -127,7 +128,7 @@ export default class Mod {
|
|
|
127
128
|
static removeByWhere(db: lDb.Pool | lDb.Transaction, where: string | kebab.Json, opt?: {
|
|
128
129
|
'raw'?: boolean;
|
|
129
130
|
'pre'?: sCtr.Ctr | string;
|
|
130
|
-
'index'?: string;
|
|
131
|
+
'index'?: string | string[];
|
|
131
132
|
'by'?: [string | string[], 'DESC' | 'ASC'];
|
|
132
133
|
'limit'?: [number, number?];
|
|
133
134
|
}): Promise<number | false | null>;
|
|
@@ -226,7 +227,7 @@ export default class Mod {
|
|
|
226
227
|
'lock'?: boolean;
|
|
227
228
|
'raw'?: boolean;
|
|
228
229
|
'pre'?: string;
|
|
229
|
-
'index'?: string;
|
|
230
|
+
'index'?: string | string[];
|
|
230
231
|
}): Promise<false | null | (T & Record<string, any>)>;
|
|
231
232
|
static one(db: lDb.Pool | lDb.Transaction, s: string | kebab.Json, opt: {
|
|
232
233
|
'ctr'?: sCtr.Ctr;
|
|
@@ -475,15 +476,10 @@ export default class Mod {
|
|
|
475
476
|
*/
|
|
476
477
|
protected _keyGenerator(): string;
|
|
477
478
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
/** --- 总行数 --- */
|
|
481
|
-
get length(): number;
|
|
482
|
-
/** --- 通过索引获取一个对象 --- */
|
|
479
|
+
export interface IRows<T> extends Iterable<T> {
|
|
480
|
+
readonly length: number;
|
|
483
481
|
item(index: number): T;
|
|
484
|
-
|
|
485
|
-
toArray(): Array<Record<string, kebab.DbValue>>;
|
|
486
|
-
[Symbol.iterator](): Iterator<T>;
|
|
482
|
+
toArray(): Array<Record<string, any>>;
|
|
487
483
|
}
|
|
488
484
|
export interface IModUnionItem {
|
|
489
485
|
'field': string;
|
package/sys/mod.js
CHANGED
|
@@ -11,7 +11,6 @@ import * as sCtr from '#kebab/sys/ctr.js';
|
|
|
11
11
|
/** --- 条数列表 --- */
|
|
12
12
|
class Rows {
|
|
13
13
|
constructor(initialItems = []) {
|
|
14
|
-
this._items = [];
|
|
15
14
|
this._items = initialItems;
|
|
16
15
|
}
|
|
17
16
|
/** --- 总行数 --- */
|
|
@@ -24,49 +23,19 @@ class Rows {
|
|
|
24
23
|
}
|
|
25
24
|
/** --- 转换为数组对象,获取的是新创建的数组 --- */
|
|
26
25
|
toArray() {
|
|
27
|
-
|
|
28
|
-
for (const item of this._items) {
|
|
29
|
-
arr.push(item.toArray());
|
|
30
|
-
}
|
|
31
|
-
return arr;
|
|
26
|
+
return this._items.map(i => i.toArray());
|
|
32
27
|
}
|
|
33
28
|
/** --- 根据规则筛掉项,predicate 返回 true 代表保留 --- */
|
|
34
29
|
filter(predicate) {
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < this._items.length; ++i) {
|
|
37
|
-
if (!predicate(this._items[i], i)) {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
items.push(this._items[i]);
|
|
41
|
-
}
|
|
42
|
-
return new Rows(items);
|
|
30
|
+
return new Rows(this._items.filter(predicate));
|
|
43
31
|
}
|
|
44
32
|
/** --- 重塑对象内容 --- */
|
|
45
|
-
map(
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < this._items.length; ++i) {
|
|
48
|
-
items.push(allbackfn(this._items[i], i));
|
|
49
|
-
}
|
|
50
|
-
return items;
|
|
33
|
+
map(fn) {
|
|
34
|
+
return new Rows(this._items.map(fn));
|
|
51
35
|
}
|
|
36
|
+
/** --- for of --- */
|
|
52
37
|
[Symbol.iterator]() {
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
next: () => {
|
|
56
|
-
if (index < this._items.length) {
|
|
57
|
-
return {
|
|
58
|
-
value: this._items[index++],
|
|
59
|
-
done: false
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return {
|
|
64
|
-
value: undefined,
|
|
65
|
-
done: true
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
38
|
+
return this._items[Symbol.iterator]();
|
|
70
39
|
}
|
|
71
40
|
}
|
|
72
41
|
/**
|
|
@@ -226,12 +195,9 @@ class Mod {
|
|
|
226
195
|
*/
|
|
227
196
|
static async removeByWhere(db, where, opt = {}) {
|
|
228
197
|
const tim = lTime.stamp();
|
|
229
|
-
const
|
|
198
|
+
const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
|
|
230
199
|
if (this._$soft && !opt.raw) {
|
|
231
200
|
// --- 软删除 ---
|
|
232
|
-
sq.update(this._$table + (opt.index ? ('_' + opt.index) : ''), [{
|
|
233
|
-
'time_remove': tim
|
|
234
|
-
}]);
|
|
235
201
|
if (typeof where === 'string') {
|
|
236
202
|
where = '(' + where + ') AND `time_remove` = 0';
|
|
237
203
|
}
|
|
@@ -244,26 +210,36 @@ class Mod {
|
|
|
244
210
|
where['time_remove'] = 0;
|
|
245
211
|
}
|
|
246
212
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
sq
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
213
|
+
let ar = 0;
|
|
214
|
+
for (const index of indexs) {
|
|
215
|
+
const sq = lSql.get(opt.pre);
|
|
216
|
+
if (this._$soft && !opt.raw) {
|
|
217
|
+
// --- 软删除 ---
|
|
218
|
+
sq.update(this._$table + (index ? ('_' + index) : ''), [{
|
|
219
|
+
'time_remove': tim,
|
|
220
|
+
}]);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// --- 真删除 ---
|
|
224
|
+
sq.delete(this._$table + (index ? ('_' + index) : ''));
|
|
225
|
+
}
|
|
226
|
+
sq.where(where);
|
|
227
|
+
if (opt.by) {
|
|
228
|
+
sq.by(opt.by[0], opt.by[1]);
|
|
229
|
+
}
|
|
230
|
+
if (opt.limit) {
|
|
231
|
+
sq.limit(opt.limit[0], opt.limit[1]);
|
|
232
|
+
}
|
|
233
|
+
const r = await db.execute(sq.getSql(), sq.getData());
|
|
234
|
+
if (r.packet === null) {
|
|
235
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[removeByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
if (r.packet.affectedRows > 0) {
|
|
239
|
+
ar += r.packet.affectedRows;
|
|
240
|
+
}
|
|
265
241
|
}
|
|
266
|
-
return null;
|
|
242
|
+
return ar ? ar : null;
|
|
267
243
|
}
|
|
268
244
|
/**
|
|
269
245
|
* --- 根据条件移除条目(仅获取 SQL 对象) ---
|
|
@@ -312,12 +288,7 @@ class Mod {
|
|
|
312
288
|
* @param opt 选项
|
|
313
289
|
*/
|
|
314
290
|
static async updateByWhere(db, data, where, opt = {}) {
|
|
315
|
-
|
|
316
|
-
opt.index = [opt.index];
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
opt.index ??= [''];
|
|
320
|
-
}
|
|
291
|
+
const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
|
|
321
292
|
if (this._$soft && !opt.raw) {
|
|
322
293
|
if (typeof where === 'string') {
|
|
323
294
|
where = '(' + where + ') AND `time_remove` = 0';
|
|
@@ -332,7 +303,7 @@ class Mod {
|
|
|
332
303
|
}
|
|
333
304
|
}
|
|
334
305
|
let ar = 0;
|
|
335
|
-
for (const index of
|
|
306
|
+
for (const index of indexs) {
|
|
336
307
|
const sq = lSql.get(opt.pre);
|
|
337
308
|
sq.update(this._$table + (index ? ('_' + index) : ''), data);
|
|
338
309
|
sq.where(where);
|
|
@@ -448,7 +419,7 @@ class Mod {
|
|
|
448
419
|
[this._$primary]: val
|
|
449
420
|
}],
|
|
450
421
|
'raw': opt.raw,
|
|
451
|
-
'index': opt.index
|
|
422
|
+
'index': opt.index,
|
|
452
423
|
}).first(opt.lock);
|
|
453
424
|
}
|
|
454
425
|
/**
|
|
@@ -459,6 +430,7 @@ class Mod {
|
|
|
459
430
|
*/
|
|
460
431
|
static async one(db, s, opt = {}) {
|
|
461
432
|
if (!opt.index) {
|
|
433
|
+
// --- 无 index ---
|
|
462
434
|
const o = new this({
|
|
463
435
|
'select': opt.select,
|
|
464
436
|
'db': db,
|
|
@@ -472,8 +444,8 @@ class Mod {
|
|
|
472
444
|
}
|
|
473
445
|
return opt.array ? o.firstArray() : o.first();
|
|
474
446
|
}
|
|
475
|
-
|
|
476
|
-
for (const item of
|
|
447
|
+
const indexs = (typeof opt.index === 'string') ? [opt.index] : [...new Set(opt.index)];
|
|
448
|
+
for (const item of indexs) {
|
|
477
449
|
const row = new this({
|
|
478
450
|
'select': opt.select,
|
|
479
451
|
'db': db,
|
|
@@ -481,7 +453,7 @@ class Mod {
|
|
|
481
453
|
'pre': opt.pre,
|
|
482
454
|
'where': s,
|
|
483
455
|
'raw': opt.raw,
|
|
484
|
-
'index': item
|
|
456
|
+
'index': item,
|
|
485
457
|
});
|
|
486
458
|
if (opt.by) {
|
|
487
459
|
row.by(opt.by[0], opt.by[1]);
|
|
@@ -638,6 +610,8 @@ class Mod {
|
|
|
638
610
|
// --- 确实重复了 ---
|
|
639
611
|
continue;
|
|
640
612
|
}
|
|
613
|
+
// --- 1062 非 index 冲突,那需要用户自行处理(可能不允许重复的邮箱) ---
|
|
614
|
+
return false;
|
|
641
615
|
}
|
|
642
616
|
// --- 未处理的错误 ---
|
|
643
617
|
lCore.log(this._ctr ?? {}, '[create0, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|