@maiyunnet/kebab 8.0.1 → 8.0.3

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/doc/kebab-rag.md CHANGED
@@ -576,9 +576,9 @@ Defined in: [index.ts:149](https://github.com/maiyunnet/kebab/blob/master/index.
576
576
 
577
577
  ***
578
578
 
579
- ### name
579
+ ### name?
580
580
 
581
- > **name**: `string`
581
+ > `optional` **name**: `string`
582
582
 
583
583
  Defined in: [index.ts:152](https://github.com/maiyunnet/kebab/blob/master/index.ts#L152)
584
584
 
@@ -1385,7 +1385,7 @@ index/variables/VER.md
1385
1385
 
1386
1386
  # Variable: VER
1387
1387
 
1388
- > `const` **VER**: `"8.0.1"` = `'8.0.1'`
1388
+ > `const` **VER**: `"8.0.3"` = `'8.0.3'`
1389
1389
 
1390
1390
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1391
1391
 
@@ -6838,9 +6838,9 @@ Defined in: [lib/db/pool.ts:27](https://github.com/maiyunnet/kebab/blob/master/l
6838
6838
 
6839
6839
  ***
6840
6840
 
6841
- ### name
6841
+ ### name?
6842
6842
 
6843
- > **name**: `string`
6843
+ > `optional` **name**: `string`
6844
6844
 
6845
6845
  Defined in: [lib/db/pool.ts:24](https://github.com/maiyunnet/kebab/blob/master/lib/db/pool.ts#L24)
6846
6846
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "8.0.1";
8
+ export declare const VER = "8.0.3";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
@@ -118,7 +118,7 @@ export interface IConfigDb {
118
118
  'host': string;
119
119
  'port': number;
120
120
  'charset': string;
121
- 'name': string;
121
+ 'name'?: string;
122
122
  'user': string;
123
123
  'pwd': string;
124
124
  }
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '8.0.1';
9
+ export const VER = '8.0.3';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/db/pool.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface IConnectionInfo {
9
9
  'last': number;
10
10
  'host': string;
11
11
  'port': number;
12
- 'name': string;
12
+ 'name'?: string;
13
13
  'user': string;
14
14
  'lost': boolean;
15
15
  'using': boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "8.0.1",
3
+ "version": "8.0.3",
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": [
package/sys/mod.js CHANGED
@@ -134,7 +134,7 @@ export default class Mod {
134
134
  sq.values(cs);
135
135
  const r = await db.execute(sq.getSql(), sq.getData());
136
136
  if (r.packet === null) {
137
- lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
137
+ lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
138
138
  return false;
139
139
  }
140
140
  return r.packet.affected ? true : null;
@@ -154,7 +154,7 @@ export default class Mod {
154
154
  sq.values(cs, vs.slice(i * line, (i + 1) * line));
155
155
  const r = await db.execute(sq.getSql(), sq.getData());
156
156
  if (r.packet === null) {
157
- lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1), '-error');
157
+ lCore.log(opt.ctr ?? {}, '[MOD][insert] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
158
158
  return false;
159
159
  }
160
160
  if (r.packet.affected) {
@@ -204,7 +204,7 @@ export default class Mod {
204
204
  }
205
205
  const r = await db.execute(sq.getSql(), sq.getData());
206
206
  if (r.packet === null) {
207
- lCore.log(opt.ctr ?? {}, '[MOD][removeByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
207
+ lCore.log(opt.ctr ?? {}, '[MOD][removeByWhere] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
208
208
  return false;
209
209
  }
210
210
  if (r.packet.affected) {
@@ -259,7 +259,7 @@ export default class Mod {
259
259
  }
260
260
  const r = await db.execute(sq.getSql(), sq.getData());
261
261
  if (r.packet === null) {
262
- lCore.log(opt.ctr ?? {}, '[MOD][updateByWhere] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
262
+ lCore.log(opt.ctr ?? {}, '[MOD][updateByWhere] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + '-' + sq.format()).replaceAll('"', '""'), '-error');
263
263
  return false;
264
264
  }
265
265
  if (r.packet.affected) {
@@ -358,7 +358,7 @@ export default class Mod {
358
358
  .where({ [key]: keys });
359
359
  const r = await db.execute(sq.getSql(), sq.getData());
360
360
  if (r.packet === null) {
361
- lCore.log(opt.ctr ?? {}, '[MOD][updateList] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
361
+ lCore.log(opt.ctr ?? {}, '[MOD][updateList] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + sq.format()).replaceAll('"', '""'), '-error');
362
362
  return false;
363
363
  }
364
364
  }
@@ -502,7 +502,7 @@ export default class Mod {
502
502
  sq.select(this._$primary, this._$table + (opt.index ? ('_' + opt.index) : '')).where(where);
503
503
  const r = await db.query(sq.getSql(), sq.getData());
504
504
  if (r.rows === null) {
505
- lCore.log(opt.ctr ?? {}, '[primarys, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
505
+ lCore.log(opt.ctr ?? {}, '[MOD][PRIMARYS] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + sq.format()).replaceAll('"', '""'), '-error');
506
506
  return false;
507
507
  }
508
508
  const primarys = [];
@@ -615,7 +615,7 @@ export default class Mod {
615
615
  }
616
616
  // --- 未处理的错误 ---
617
617
  const service = this._db.getService();
618
- lCore.log(this._ctr ?? {}, '[MOD][create0][' + cstr._$table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
618
+ lCore.log(this._ctr ?? {}, '[MOD][create0][' + cstr._$table + '] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
619
619
  if (lCore.globalConfig.debug) {
620
620
  lCore.debug('[MOD][create0][' + cstr._$table + ']', service !== null ? lDb.ESERVICE[service] : 'NONE', r);
621
621
  lCore.debug(this._sql.format());
@@ -629,7 +629,7 @@ export default class Mod {
629
629
  r = await this._db.execute(this._sql.getSql(), this._sql.getData());
630
630
  if (r.error) {
631
631
  if (r.error.errno !== 1062) {
632
- lCore.log(this._ctr ?? {}, '[MOD][create1][' + cstr._$table + '] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
632
+ lCore.log(this._ctr ?? {}, '[MOD][create1][' + cstr._$table + '] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
633
633
  if (lCore.globalConfig.debug) {
634
634
  lCore.debug('[MOD][create1][' + cstr._$table + ']', r);
635
635
  lCore.debug(this._sql.format());
@@ -692,7 +692,7 @@ export default class Mod {
692
692
  }
693
693
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
694
694
  if (r.rows === null) {
695
- lCore.log(this._ctr ?? {}, '[MOD][refresh] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
695
+ lCore.log(this._ctr ?? {}, '[MOD][refresh] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replace(/"/g, '""'), '-error');
696
696
  return false;
697
697
  }
698
698
  if (r.rows.length === 0) {
@@ -723,7 +723,7 @@ export default class Mod {
723
723
  });
724
724
  const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
725
725
  if (r.packet === null) {
726
- lCore.log(this._ctr ?? {}, '[MOD][save] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
726
+ lCore.log(this._ctr ?? {}, '[MOD][save] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
727
727
  return false;
728
728
  }
729
729
  if (r.packet.affected) {
@@ -744,7 +744,7 @@ export default class Mod {
744
744
  }]);
745
745
  const r = await this._db.execute(this._sql.getSql(), this._sql.getData());
746
746
  if (r.packet === null) {
747
- lCore.log(this._ctr ?? {}, '[remove, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
747
+ lCore.log(this._ctr ?? {}, '[MOD][remove] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
748
748
  return false;
749
749
  }
750
750
  if (r.packet.affected) {
@@ -766,7 +766,7 @@ export default class Mod {
766
766
  }
767
767
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
768
768
  if (r.rows === null) {
769
- lCore.log(this._ctr ?? {}, '[first, mod] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
769
+ lCore.log(this._ctr ?? {}, '[MOD][first] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
770
770
  return false;
771
771
  }
772
772
  if (r.rows.length === 0) {
@@ -897,7 +897,7 @@ export default class Mod {
897
897
  const lsql = sql.replace(/ LIMIT [0-9 ,]+(OFFSET [0-9]+)?/g, ` LIMIT ${remain} OFFSET ${cz}`);
898
898
  const r = await this._db.query(lsql, this._sql.getData());
899
899
  if (r.rows === null) {
900
- lCore.log(this._ctr ?? {}, '[MOD][all] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
900
+ lCore.log(this._ctr ?? {}, '[MOD][all] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
901
901
  return false;
902
902
  }
903
903
  if (key) {
@@ -934,7 +934,7 @@ export default class Mod {
934
934
  const contain = this._contain ? lCore.clone(this._contain.list) : null;
935
935
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
936
936
  if (r.rows === null) {
937
- lCore.log(this._ctr ?? {}, '[MOD][all] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
937
+ lCore.log(this._ctr ?? {}, '[MOD][all] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
938
938
  return false;
939
939
  }
940
940
  // --- 检查没被查到的必包含项 ---
@@ -1059,7 +1059,7 @@ export default class Mod {
1059
1059
  const lsql = sql.replace(/ LIMIT [0-9 ,]+(OFFSET [0-9]+)?/g, ` LIMIT ${remain} OFFSET ${cz}`);
1060
1060
  const r = await this._db.query(lsql, this._sql.getData());
1061
1061
  if (r.rows === null) {
1062
- lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1062
+ lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
1063
1063
  return false;
1064
1064
  }
1065
1065
  if (key) {
@@ -1081,7 +1081,7 @@ export default class Mod {
1081
1081
  const contain = this._contain ? lCore.clone(this._contain.list) : null;
1082
1082
  const r = await this._db.query(this._sql.getSql(), this._sql.getData());
1083
1083
  if (r.rows === null) {
1084
- lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1084
+ lCore.log(this._ctr ?? {}, '[MOD][allArray] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
1085
1085
  return false;
1086
1086
  }
1087
1087
  // --- 检查没被查到的必包含项 ---
@@ -1130,7 +1130,7 @@ export default class Mod {
1130
1130
  async explain(all = false) {
1131
1131
  const r = await this._db.query('EXPLAIN ' + this._sql.getSql(), this._sql.getData());
1132
1132
  if (r.rows === null) {
1133
- lCore.log(this._ctr ?? {}, '[MOD][explain] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1133
+ lCore.log(this._ctr ?? {}, '[MOD][explain] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
1134
1134
  return false;
1135
1135
  }
1136
1136
  if (!r.rows[0]) {
@@ -1173,7 +1173,7 @@ export default class Mod {
1173
1173
  const sql = this._formatTotal(this._sql.getSql(), f);
1174
1174
  const r = await this._db.query(sql, this._sql.getData());
1175
1175
  if (r.rows === null) {
1176
- lCore.log(this._ctr ?? {}, '[MOD][total] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1176
+ lCore.log(this._ctr ?? {}, '[MOD][total] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
1177
1177
  return 0;
1178
1178
  }
1179
1179
  let count = 0;
@@ -1191,7 +1191,7 @@ export default class Mod {
1191
1191
  'SELECT COUNT(0) AS "count" FROM');
1192
1192
  const r = await this._db.query(sql, this._sql.getData());
1193
1193
  if (r.rows === null) {
1194
- lCore.log(this._ctr ?? {}, '[MOD][count] ' + lText.stringifyJson(r.error?.message ?? '').slice(1, -1).replace(/"/g, '""'), '-error');
1194
+ lCore.log(this._ctr ?? {}, '[MOD][count] ' + (lText.stringifyJson(r.error?.message ?? '').slice(1, -1) + ' - ' + this._sql.format()).replaceAll('"', '""'), '-error');
1195
1195
  return 0;
1196
1196
  }
1197
1197
  let count = 0;
@@ -84,6 +84,12 @@ function captureDiag(blockSec) {
84
84
  const pauseTimeout = setTimeout(() => {
85
85
  if (!didPause) {
86
86
  timedOut = true;
87
+ try {
88
+ session.post('Debugger.resume');
89
+ }
90
+ catch {
91
+ // --- 忽略 ---
92
+ }
87
93
  try {
88
94
  session.post('Debugger.disable');
89
95
  }
@@ -171,10 +177,6 @@ function captureDiag(blockSec) {
171
177
  }
172
178
  return;
173
179
  }
174
- if (timedOut) {
175
- clearTimeout(pauseTimeout);
176
- return;
177
- }
178
180
  try {
179
181
  session.post('Debugger.pause', (err2) => {
180
182
  if (err2 || timedOut) {
@@ -249,6 +251,10 @@ setInterval(() => {
249
251
  if (lastHb <= 0 || now - lastHb < data.threshold) {
250
252
  return;
251
253
  }
254
+ // --- 调试模式下跳过阻塞检测,避免干扰 IDE 调试器 ---
255
+ if (Atomics.load(view, 1) === 1) {
256
+ return;
257
+ }
252
258
  if (now - lastAlertTime < data.cooldown) {
253
259
  return;
254
260
  }
package/sys/monitor.js CHANGED
@@ -49,6 +49,12 @@ let requestCounter = 0;
49
49
  let lastDiagnosticTime = 0;
50
50
  /** --- 是否正在进行 CPU Profile 采集 --- */
51
51
  let profiling = false;
52
+ /**
53
+ * --- 检测当前是否处于调试模式(以 --inspect 启动或 IDE 调试器已连接) ---
54
+ */
55
+ function isDebugMode() {
56
+ return !!inspector.url();
57
+ }
52
58
  // --- 看门狗相关 ---
53
59
  /** --- 看门狗 Worker 实例 --- */
54
60
  let watchdog = null;
@@ -85,10 +91,11 @@ export function start(opt) {
85
91
  lastOsCpus = os.cpus();
86
92
  spikeCounter = 0;
87
93
  lastDiagnosticTime = 0;
88
- // --- 初始化心跳共享内存 ---
89
- heartbeatBuffer = new SharedArrayBuffer(4);
94
+ // --- 初始化心跳共享内存(索引 0: 秒级时间戳, 索引 1: 调试模式标志) ---
95
+ heartbeatBuffer = new SharedArrayBuffer(8);
90
96
  heartbeatView = new Int32Array(heartbeatBuffer);
91
97
  Atomics.store(heartbeatView, 0, Math.floor(Date.now() / 1000));
98
+ Atomics.store(heartbeatView, 1, isDebugMode() ? 1 : 0);
92
99
  // --- 启用事件循环延迟直方图 ---
93
100
  eloopHistogram = perfHooks.monitorEventLoopDelay({ 'resolution': 20 });
94
101
  eloopHistogram.enable();
@@ -259,6 +266,8 @@ function check() {
259
266
  // --- 更新心跳时间戳,让看门狗线程知道主线程还活着 ---
260
267
  if (heartbeatView) {
261
268
  Atomics.store(heartbeatView, 0, Math.floor(now / 1000));
269
+ // --- 更新调试模式标志,让看门狗线程知道当前是否在调试 ---
270
+ Atomics.store(heartbeatView, 1, isDebugMode() ? 1 : 0);
262
271
  }
263
272
  /** --- 计算本周期进程 CPU 使用率(单核基准) --- */
264
273
  let cpuPercent = 0;
@@ -284,6 +293,11 @@ function check() {
284
293
  }
285
294
  // --- 检测事件循环阻塞:实际间隔远大于预期说明事件循环曾被阻塞 ---
286
295
  if (actualElapsed > INTERVAL * 3) {
296
+ // --- 调试模式下断点暂停会导致计时差异,跳过阻塞检测 ---
297
+ if (isDebugMode()) {
298
+ spikeCounter = 0;
299
+ return;
300
+ }
287
301
  const blockMs = actualElapsed - INTERVAL;
288
302
  const alerts = [
289
303
  `ELOOP_BLOCKED ${Math.round(blockMs)}ms`