@maiyunnet/kebab 3.2.13 → 3.2.14
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/package.json +1 -1
- package/sys/mod.d.ts +2 -2
- package/sys/mod.js +40 -35
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.14';
|
|
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/package.json
CHANGED
package/sys/mod.d.ts
CHANGED
|
@@ -127,7 +127,7 @@ export default class Mod {
|
|
|
127
127
|
static removeByWhere(db: lDb.Pool | lDb.Transaction, where: string | kebab.Json, opt?: {
|
|
128
128
|
'raw'?: boolean;
|
|
129
129
|
'pre'?: sCtr.Ctr | string;
|
|
130
|
-
'index'?: string;
|
|
130
|
+
'index'?: string | string[];
|
|
131
131
|
'by'?: [string | string[], 'DESC' | 'ASC'];
|
|
132
132
|
'limit'?: [number, number?];
|
|
133
133
|
}): Promise<number | false | null>;
|
|
@@ -226,7 +226,7 @@ export default class Mod {
|
|
|
226
226
|
'lock'?: boolean;
|
|
227
227
|
'raw'?: boolean;
|
|
228
228
|
'pre'?: string;
|
|
229
|
-
'index'?: string;
|
|
229
|
+
'index'?: string | string[];
|
|
230
230
|
}): Promise<false | null | (T & Record<string, any>)>;
|
|
231
231
|
static one(db: lDb.Pool | lDb.Transaction, s: string | kebab.Json, opt: {
|
|
232
232
|
'ctr'?: sCtr.Ctr;
|
package/sys/mod.js
CHANGED
|
@@ -55,7 +55,7 @@ class Rows {
|
|
|
55
55
|
next: () => {
|
|
56
56
|
if (index < this._items.length) {
|
|
57
57
|
return {
|
|
58
|
-
value: this._items[index
|
|
58
|
+
value: this._items[++index],
|
|
59
59
|
done: false
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -226,12 +226,9 @@ class Mod {
|
|
|
226
226
|
*/
|
|
227
227
|
static async removeByWhere(db, where, opt = {}) {
|
|
228
228
|
const tim = lTime.stamp();
|
|
229
|
-
const
|
|
229
|
+
const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
|
|
230
230
|
if (this._$soft && !opt.raw) {
|
|
231
231
|
// --- 软删除 ---
|
|
232
|
-
sq.update(this._$table + (opt.index ? ('_' + opt.index) : ''), [{
|
|
233
|
-
'time_remove': tim
|
|
234
|
-
}]);
|
|
235
232
|
if (typeof where === 'string') {
|
|
236
233
|
where = '(' + where + ') AND `time_remove` = 0';
|
|
237
234
|
}
|
|
@@ -244,26 +241,36 @@ class Mod {
|
|
|
244
241
|
where['time_remove'] = 0;
|
|
245
242
|
}
|
|
246
243
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
sq
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
244
|
+
let ar = 0;
|
|
245
|
+
for (const index of indexs) {
|
|
246
|
+
const sq = lSql.get(opt.pre);
|
|
247
|
+
if (this._$soft && !opt.raw) {
|
|
248
|
+
// --- 软删除 ---
|
|
249
|
+
sq.update(this._$table + (index ? ('_' + index) : ''), [{
|
|
250
|
+
'time_remove': tim,
|
|
251
|
+
}]);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
// --- 真删除 ---
|
|
255
|
+
sq.delete(this._$table + (index ? ('_' + index) : ''));
|
|
256
|
+
}
|
|
257
|
+
sq.where(where);
|
|
258
|
+
if (opt.by) {
|
|
259
|
+
sq.by(opt.by[0], opt.by[1]);
|
|
260
|
+
}
|
|
261
|
+
if (opt.limit) {
|
|
262
|
+
sq.limit(opt.limit[0], opt.limit[1]);
|
|
263
|
+
}
|
|
264
|
+
const r = await db.execute(sq.getSql(), sq.getData());
|
|
265
|
+
if (r.packet === null) {
|
|
266
|
+
lCore.log(opt.pre instanceof sCtr.Ctr ? opt.pre : {}, '[removeByWhere, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
if (r.packet.affectedRows > 0) {
|
|
270
|
+
ar += r.packet.affectedRows;
|
|
271
|
+
}
|
|
265
272
|
}
|
|
266
|
-
return null;
|
|
273
|
+
return ar ? ar : null;
|
|
267
274
|
}
|
|
268
275
|
/**
|
|
269
276
|
* --- 根据条件移除条目(仅获取 SQL 对象) ---
|
|
@@ -312,12 +319,7 @@ class Mod {
|
|
|
312
319
|
* @param opt 选项
|
|
313
320
|
*/
|
|
314
321
|
static async updateByWhere(db, data, where, opt = {}) {
|
|
315
|
-
|
|
316
|
-
opt.index = [opt.index];
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
opt.index ??= [''];
|
|
320
|
-
}
|
|
322
|
+
const indexs = opt.index ? (typeof opt.index === 'string' ? [opt.index] : [...new Set(opt.index)]) : [''];
|
|
321
323
|
if (this._$soft && !opt.raw) {
|
|
322
324
|
if (typeof where === 'string') {
|
|
323
325
|
where = '(' + where + ') AND `time_remove` = 0';
|
|
@@ -332,7 +334,7 @@ class Mod {
|
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
let ar = 0;
|
|
335
|
-
for (const index of
|
|
337
|
+
for (const index of indexs) {
|
|
336
338
|
const sq = lSql.get(opt.pre);
|
|
337
339
|
sq.update(this._$table + (index ? ('_' + index) : ''), data);
|
|
338
340
|
sq.where(where);
|
|
@@ -448,7 +450,7 @@ class Mod {
|
|
|
448
450
|
[this._$primary]: val
|
|
449
451
|
}],
|
|
450
452
|
'raw': opt.raw,
|
|
451
|
-
'index': opt.index
|
|
453
|
+
'index': opt.index,
|
|
452
454
|
}).first(opt.lock);
|
|
453
455
|
}
|
|
454
456
|
/**
|
|
@@ -459,6 +461,7 @@ class Mod {
|
|
|
459
461
|
*/
|
|
460
462
|
static async one(db, s, opt = {}) {
|
|
461
463
|
if (!opt.index) {
|
|
464
|
+
// --- 无 index ---
|
|
462
465
|
const o = new this({
|
|
463
466
|
'select': opt.select,
|
|
464
467
|
'db': db,
|
|
@@ -472,8 +475,8 @@ class Mod {
|
|
|
472
475
|
}
|
|
473
476
|
return opt.array ? o.firstArray() : o.first();
|
|
474
477
|
}
|
|
475
|
-
|
|
476
|
-
for (const item of
|
|
478
|
+
const indexs = (typeof opt.index === 'string') ? [opt.index] : [...new Set(opt.index)];
|
|
479
|
+
for (const item of indexs) {
|
|
477
480
|
const row = new this({
|
|
478
481
|
'select': opt.select,
|
|
479
482
|
'db': db,
|
|
@@ -481,7 +484,7 @@ class Mod {
|
|
|
481
484
|
'pre': opt.pre,
|
|
482
485
|
'where': s,
|
|
483
486
|
'raw': opt.raw,
|
|
484
|
-
'index': item
|
|
487
|
+
'index': item,
|
|
485
488
|
});
|
|
486
489
|
if (opt.by) {
|
|
487
490
|
row.by(opt.by[0], opt.by[1]);
|
|
@@ -638,6 +641,8 @@ class Mod {
|
|
|
638
641
|
// --- 确实重复了 ---
|
|
639
642
|
continue;
|
|
640
643
|
}
|
|
644
|
+
// --- 1062 非 index 冲突,那需要用户自行处理(可能不允许重复的邮箱) ---
|
|
645
|
+
return false;
|
|
641
646
|
}
|
|
642
647
|
// --- 未处理的错误 ---
|
|
643
648
|
lCore.log(this._ctr ?? {}, '[create0, mod] [' + table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
|