@maiyunnet/kebab 9.29.6 → 10.1.0
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/abox/proxy.js +24 -2
- package/abox/response.js +36 -17
- package/abox/session-login.js +1 -13
- package/doc/kebab-rag.md +1687 -1061
- package/index.d.ts +14 -2
- package/index.js +1 -1
- package/lib/ai.d.ts +4 -0
- package/lib/ai.js +32 -16
- package/lib/cookie.d.ts +2 -0
- package/lib/cookie.js +47 -45
- package/lib/core.d.ts +26 -0
- package/lib/core.js +36 -13
- package/lib/cron.js +1 -8
- package/lib/crypto.js +20 -6
- package/lib/db/conn.d.ts +4 -2
- package/lib/db/conn.js +1 -0
- package/lib/db/pool.d.ts +17 -4
- package/lib/db/pool.js +41 -23
- package/lib/db/tran.d.ts +6 -4
- package/lib/db.d.ts +10 -5
- package/lib/db.js +36 -6
- package/lib/fs.js +78 -31
- package/lib/kv.d.ts +182 -79
- package/lib/kv.js +518 -214
- package/lib/s3.d.ts +2 -0
- package/lib/s3.js +14 -27
- package/lib/session.d.ts +7 -0
- package/lib/session.js +23 -2
- package/lib/socket.d.ts +4 -1
- package/lib/socket.js +1 -0
- package/lib/sql.d.ts +0 -5
- package/lib/sql.js +48 -12
- package/lib/text.d.ts +10 -5
- package/lib/text.js +22 -12
- package/lib/turnstile.d.ts +6 -0
- package/lib/turnstile.js +16 -9
- package/lib/undici/response.d.ts +1 -1
- package/lib/undici.d.ts +7 -1
- package/lib/undici.js +72 -36
- package/lib/ws.d.ts +1 -1
- package/lib/ws.js +85 -128
- package/lib/zip.js +46 -45
- package/package.json +2 -2
- package/sys/child.js +178 -146
- package/sys/cmd.js +196 -210
- package/sys/ctr.d.ts +16 -16
- package/sys/ctr.js +147 -61
- package/sys/master.js +111 -80
- package/sys/mod.d.ts +24 -2
- package/sys/mod.js +56 -26
- package/sys/monitor/files.d.ts +2 -1
- package/sys/monitor/files.js +77 -21
- package/sys/monitor/watchdog.d.ts +7 -0
- package/sys/monitor/watchdog.js +311 -203
- package/sys/monitor.d.ts +59 -54
- package/sys/monitor.js +742 -681
- package/sys/route.d.ts +4 -4
- package/sys/route.js +93 -52
- package/www/example/ctr/test.d.ts +1 -1
- package/www/example/ctr/test.js +34 -15
- package/www/example/mod/test.js +0 -1
package/sys/master.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Date: 2019-5-2 21:03:42
|
|
4
4
|
* Last: 2020-3-7 10:33:17, 2022-07-22 13:40:10, 2022-09-06 22:40:58, 2024-2-7 01:44:59, 2024-7-2 15:17:09, 2025-6-13 13:06:43, 2025-12-5 13:15:03, 2026-3-22 00:00:00, 2026-4-30 13:49:44
|
|
5
5
|
*/
|
|
6
|
+
// --- 系统 ---
|
|
6
7
|
import cluster from 'cluster';
|
|
7
8
|
import * as os from 'os';
|
|
8
9
|
import * as fs from 'fs';
|
|
@@ -41,6 +42,29 @@ const replaceVhost = masterVhost.replace;
|
|
|
41
42
|
* @returns true 表示所有文件可写入;false 表示整批拒绝,不修改旧配置
|
|
42
43
|
*/
|
|
43
44
|
const isVhostFiles = masterVhost.isFiles;
|
|
45
|
+
/** --- kebab 子项目中仅允许部署的子文件夹名集合 --- */
|
|
46
|
+
const KEBAB_ALLOWED_DIRS = new Set(['ctr', 'data', 'stc', 'view', 'lib', 'abox']);
|
|
47
|
+
/** --- 常见开发、依赖、缓存、构建产物目录不参与部署 --- */
|
|
48
|
+
const DEPLOY_EXCLUDE_DIRS = new Set([
|
|
49
|
+
'.git',
|
|
50
|
+
'.svn',
|
|
51
|
+
'.hg',
|
|
52
|
+
'.vscode',
|
|
53
|
+
'.idea',
|
|
54
|
+
'.history',
|
|
55
|
+
'node_modules',
|
|
56
|
+
'bower_components',
|
|
57
|
+
'.cache',
|
|
58
|
+
'.parcel-cache',
|
|
59
|
+
'.turbo',
|
|
60
|
+
'.next',
|
|
61
|
+
'.nuxt',
|
|
62
|
+
'.vite',
|
|
63
|
+
'coverage',
|
|
64
|
+
'.nyc_output',
|
|
65
|
+
'tmp',
|
|
66
|
+
'temp',
|
|
67
|
+
]);
|
|
44
68
|
/** --- 当前运行中的子进程列表 --- */
|
|
45
69
|
const workerList = {};
|
|
46
70
|
/** --- 是否已开始停止整个服务 --- */
|
|
@@ -101,6 +125,27 @@ async function resolvePathInside(rootPath, inputPath) {
|
|
|
101
125
|
}
|
|
102
126
|
}
|
|
103
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* --- 解析并校验目标目录是否位于根目录内(同时兼容相对路径与根目录内的绝对路径) ---
|
|
130
|
+
* @param rootPath 限定的根目录
|
|
131
|
+
* @param inputPath 待校验目录路径
|
|
132
|
+
*/
|
|
133
|
+
async function resolveDirInside(rootPath, inputPath) {
|
|
134
|
+
if ((typeof inputPath !== 'string') || inputPath.includes('\0')) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const rootReal = await fs.promises.realpath(rootPath);
|
|
138
|
+
if (path.isAbsolute(inputPath)) {
|
|
139
|
+
try {
|
|
140
|
+
const targetReal = await fs.promises.realpath(inputPath);
|
|
141
|
+
return isPathInside(rootReal, targetReal) ? targetReal : null;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return resolvePathInside(rootReal, inputPath);
|
|
148
|
+
}
|
|
104
149
|
/**
|
|
105
150
|
* --- 统一 ZIP 文件路径中的斜杠,并拒绝 .. 等不安全写法 ---
|
|
106
151
|
* @param archivePath ZIP 内的原始路径
|
|
@@ -304,6 +349,10 @@ function createRpcListener() {
|
|
|
304
349
|
break;
|
|
305
350
|
}
|
|
306
351
|
case 'global': {
|
|
352
|
+
if (typeof msg.key !== 'string' || msg.key === '__proto__' || msg.key === 'constructor' || msg.key === 'prototype') {
|
|
353
|
+
res.end('Invalid key');
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
307
356
|
// --- 为所有子进程更新 global 变量 ---
|
|
308
357
|
for (const pid in workerList) {
|
|
309
358
|
workerList[pid].worker.send({
|
|
@@ -350,12 +399,17 @@ function createRpcListener() {
|
|
|
350
399
|
return;
|
|
351
400
|
}
|
|
352
401
|
case 'npm': {
|
|
353
|
-
// --- 执行 npm install
|
|
402
|
+
// --- 执行 npm install 操作(路径必须位于项目根目录内) ---
|
|
354
403
|
if (!msg.path || typeof msg.path !== 'string') {
|
|
355
404
|
res.end('Invalid path');
|
|
356
405
|
return;
|
|
357
406
|
}
|
|
358
|
-
|
|
407
|
+
const npmPath = await resolveDirInside(kebab.ROOT_CWD, msg.path);
|
|
408
|
+
if (!npmPath) {
|
|
409
|
+
res.end('Invalid path');
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (!await lFs.isDir(npmPath)) {
|
|
359
413
|
res.end('Path not found');
|
|
360
414
|
return;
|
|
361
415
|
}
|
|
@@ -363,7 +417,7 @@ function createRpcListener() {
|
|
|
363
417
|
const npmTimeout = 300_000;
|
|
364
418
|
const npmDeadline = Date.now() + npmTimeout;
|
|
365
419
|
let rtn = await lCore.exec('npm i --omit=dev', {
|
|
366
|
-
'cwd':
|
|
420
|
+
'cwd': npmPath,
|
|
367
421
|
'timeout': npmTimeout,
|
|
368
422
|
});
|
|
369
423
|
if (rtn === false) {
|
|
@@ -371,7 +425,7 @@ function createRpcListener() {
|
|
|
371
425
|
const remaining = npmDeadline - Date.now();
|
|
372
426
|
if (remaining > 0) {
|
|
373
427
|
rtn = await lCore.exec('npm i --omit=dev --legacy-peer-deps', {
|
|
374
|
-
'cwd':
|
|
428
|
+
'cwd': npmPath,
|
|
375
429
|
'timeout': remaining,
|
|
376
430
|
});
|
|
377
431
|
}
|
|
@@ -433,6 +487,11 @@ function createRpcListener() {
|
|
|
433
487
|
res.end('Invalid content');
|
|
434
488
|
return;
|
|
435
489
|
}
|
|
490
|
+
const parsedPkg = lText.parseJson(msg.content);
|
|
491
|
+
if (!parsedPkg || typeof parsedPkg !== 'object' || Array.isArray(parsedPkg)) {
|
|
492
|
+
res.end('Invalid content');
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
436
495
|
const packageFile = kebab.ROOT_CWD + 'package.json';
|
|
437
496
|
if (!await lFs.isFile(packageFile)) {
|
|
438
497
|
res.end('package.json not found');
|
|
@@ -522,35 +581,28 @@ function createRpcListener() {
|
|
|
522
581
|
ls[normalizedPath] = rawList[archivePath];
|
|
523
582
|
}
|
|
524
583
|
// --- 预扫描:收集 .cga 锁定目录和 kebab 子项目目录 ---
|
|
525
|
-
/** --- .cga
|
|
584
|
+
/** --- .cga 锁定的目录集合,格式如 "www/pika/" --- */
|
|
526
585
|
const cgaLockedDirs = new Set();
|
|
527
|
-
/** --- 含有 kebab.json
|
|
586
|
+
/** --- 含有 kebab.json 的目录集合,格式如 "www/pika/",根目录为空字符串 --- */
|
|
528
587
|
const kebabProjectDirs = new Set();
|
|
529
|
-
/** ---
|
|
588
|
+
/** --- 本次部署涉及的目录集合 --- */
|
|
530
589
|
const touchedDirs = new Set();
|
|
531
590
|
for (const scanPath in ls) {
|
|
532
|
-
/** --- 纯路径中最后一个 / 的位置索引 --- */
|
|
533
591
|
const scanLio = scanPath.lastIndexOf('/');
|
|
534
|
-
/** --- 纯路径,不以 / 开头,以 / 结尾,若是根路径就是空字符串,例如 "www/pika/" --- */
|
|
535
592
|
const scanPat = scanPath.slice(1, scanLio + 1);
|
|
536
|
-
/** --- 纯文件名,例如 "index.ts" 或 "pika.cga" --- */
|
|
537
593
|
const scanFname = scanPath.slice(scanLio + 1);
|
|
538
594
|
touchedDirs.add(scanPat);
|
|
539
|
-
if (scanFname.endsWith('.cga')) {
|
|
540
|
-
|
|
541
|
-
cgaLockedDirs.add(scanPat + scanFname.slice(0, -4) + '/');
|
|
595
|
+
if (scanFname.toLowerCase().endsWith('.cga')) {
|
|
596
|
+
cgaLockedDirs.add((scanPat + scanFname.slice(0, -4) + '/').toLowerCase());
|
|
542
597
|
}
|
|
543
|
-
if (scanFname === 'kebab.json') {
|
|
544
|
-
// --- 记录含有 kebab.json 的目录(即 kebab 子项目根目录)---
|
|
598
|
+
if (scanFname.toLowerCase() === 'kebab.json') {
|
|
545
599
|
kebabProjectDirs.add(scanPat);
|
|
546
600
|
}
|
|
547
601
|
}
|
|
548
602
|
// --- 补充扫描目标目录中现存的 kebab.json,兼容压缩包未携带 kebab.json 的情况 ---
|
|
549
603
|
for (const dir of touchedDirs) {
|
|
550
|
-
/** --- 把目录拆成各级目录名,先检查当前目录,再一层层往上找 --- */
|
|
551
604
|
const dirs = dir ? dir.split('/').filter(Boolean) : [];
|
|
552
605
|
for (let i = dirs.length; i >= 0; --i) {
|
|
553
|
-
/** --- 当前要检查的目录路径,不含开头/,含尾部/,根目录为空字符串 --- */
|
|
554
606
|
const currentDir = i ? dirs.slice(0, i).join('/') + '/' : '';
|
|
555
607
|
if (kebabProjectDirs.has(currentDir)) {
|
|
556
608
|
break;
|
|
@@ -561,68 +613,42 @@ function createRpcListener() {
|
|
|
561
613
|
}
|
|
562
614
|
}
|
|
563
615
|
}
|
|
564
|
-
|
|
565
|
-
const KEBAB_ALLOWED_DIRS = new Set(['ctr', 'data', 'stc', 'view', 'lib', 'abox']);
|
|
566
|
-
/** --- 常见开发、依赖、缓存、构建产物目录不参与部署 --- */
|
|
567
|
-
const DEPLOY_EXCLUDE_DIRS = new Set([
|
|
568
|
-
'.git',
|
|
569
|
-
'.svn',
|
|
570
|
-
'.hg',
|
|
571
|
-
'.vscode',
|
|
572
|
-
'.idea',
|
|
573
|
-
'.history',
|
|
574
|
-
'node_modules',
|
|
575
|
-
'bower_components',
|
|
576
|
-
'.cache',
|
|
577
|
-
'.parcel-cache',
|
|
578
|
-
'.turbo',
|
|
579
|
-
'.next',
|
|
580
|
-
'.nuxt',
|
|
581
|
-
'.vite',
|
|
582
|
-
'coverage',
|
|
583
|
-
'.nyc_output',
|
|
584
|
-
'tmp',
|
|
585
|
-
'temp',
|
|
586
|
-
]);
|
|
616
|
+
// --- 按安全与过滤规则逐项写入文件(统一小写比对防止大小写绕过) ---
|
|
587
617
|
for (const archivePath in ls) {
|
|
588
|
-
/** --- 纯路径中最后一个 / 的位置索引 --- */
|
|
589
618
|
const lio = archivePath.lastIndexOf('/');
|
|
590
|
-
/** --- 纯路径,不以 / 开头,以 / 结尾,若是根路径就是空字符串,例如 "www/pika/ctr/" --- */
|
|
591
619
|
const pat = archivePath.slice(1, lio + 1);
|
|
592
|
-
/** --- 纯文件名,例如 "api.js" --- */
|
|
593
620
|
const fname = archivePath.slice(lio + 1);
|
|
621
|
+
const fnameLower = fname.toLowerCase();
|
|
594
622
|
const dirs = archivePath.slice(1).split('/').slice(0, -1);
|
|
595
|
-
|
|
596
|
-
|
|
623
|
+
const dirsLower = dirs.map(seg => seg.toLowerCase());
|
|
624
|
+
if (dirsLower.some(seg => DEPLOY_EXCLUDE_DIRS.has(seg))) {
|
|
597
625
|
continue;
|
|
598
626
|
}
|
|
599
|
-
if (
|
|
627
|
+
if (dirsLower.some((seg, index) => seg === 'abox' && ['test', 'tests'].includes(dirsLower[index + 1]))) {
|
|
600
628
|
// --- abox 运行代码参与部署,测试目录不进入线上目录 ---
|
|
601
629
|
continue;
|
|
602
630
|
}
|
|
603
|
-
if (
|
|
604
|
-
// --- 包含密码或密钥的 kebab.json
|
|
605
|
-
continue;
|
|
606
|
-
}
|
|
607
|
-
if (pat === 'conf/' && fname === 'config.json') {
|
|
608
|
-
// --- 全局配置文件不能覆盖 ---
|
|
631
|
+
if (fnameLower === 'kebab.json' && hasSensitiveConfig(ls[archivePath])) {
|
|
632
|
+
// --- 包含密码或密钥的 kebab.json 不覆盖 ---
|
|
609
633
|
continue;
|
|
610
634
|
}
|
|
611
|
-
if (
|
|
612
|
-
// --- 测试或开发文件不覆盖 ---
|
|
635
|
+
if (pat.toLowerCase() === 'conf/' && fnameLower === 'config.json') {
|
|
613
636
|
continue;
|
|
614
637
|
}
|
|
615
|
-
if (
|
|
616
|
-
|
|
638
|
+
if (fnameLower.endsWith('.js.map') ||
|
|
639
|
+
fnameLower.endsWith('.ts') ||
|
|
640
|
+
fnameLower.endsWith('.tsx') ||
|
|
641
|
+
fnameLower.endsWith('.scss') ||
|
|
642
|
+
fnameLower.endsWith('.gitignore') ||
|
|
643
|
+
fnameLower.endsWith('.ds_store') ||
|
|
644
|
+
fnameLower === 'agents.md') {
|
|
617
645
|
continue;
|
|
618
646
|
}
|
|
619
|
-
// --- 规则 1
|
|
647
|
+
// --- 规则 1:若同级或上级目录存在 xxx.cga,则 xxx 目录下所有内容不部署 ---
|
|
620
648
|
if (pat) {
|
|
621
|
-
/** --- 当前目录或上级目录是否有同名 .cga 文件 --- */
|
|
622
649
|
let cgaBlocked = false;
|
|
623
|
-
/** --- 逐层拼出的目录路径,如 a/、a/b/,检查是否有同名 .cga 文件 --- */
|
|
624
650
|
let accumulated = '';
|
|
625
|
-
for (const seg of pat.split('/').filter(Boolean)) {
|
|
651
|
+
for (const seg of pat.toLowerCase().split('/').filter(Boolean)) {
|
|
626
652
|
accumulated += seg + '/';
|
|
627
653
|
if (cgaLockedDirs.has(accumulated)) {
|
|
628
654
|
cgaBlocked = true;
|
|
@@ -633,26 +659,20 @@ function createRpcListener() {
|
|
|
633
659
|
continue;
|
|
634
660
|
}
|
|
635
661
|
}
|
|
636
|
-
// --- 规则 2:kebab 子项目目录中,仅允许部署 ctr/data/stc/view/lib/abox
|
|
662
|
+
// --- 规则 2:kebab 子项目目录中,仅允许部署 ctr/data/stc/view/lib/abox 子目录 ---
|
|
637
663
|
if (kebabProjectDirs.size > 0) {
|
|
638
|
-
// --- 同时属于多个 Kebab
|
|
639
|
-
// --- 例如根项目不允许 backup/,backup/ 自带 kebab.json 也不能绕过 ---
|
|
640
|
-
/** --- 当前文件所属的最外层 Kebab 项目目录,找不到时为 null --- */
|
|
664
|
+
// --- 同时属于多个 Kebab 项目时,按最外层项目规则检查 ---
|
|
641
665
|
let shortestMatch = null;
|
|
642
666
|
for (const kdir of kebabProjectDirs) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
if (pat.startsWith(kdir) && isShallower) {
|
|
667
|
+
if (pat.startsWith(kdir) &&
|
|
668
|
+
(shortestMatch === null || kdir.length < shortestMatch.length)) {
|
|
646
669
|
shortestMatch = kdir;
|
|
647
670
|
}
|
|
648
671
|
}
|
|
649
672
|
if (shortestMatch !== null) {
|
|
650
|
-
// --- 取相对于 kebab 项目目录的路径,检查第一级子目录 ---
|
|
651
|
-
/** --- 相对路径,例如若 pat 为 "www/pika/ctr/" 且 shortestMatch 为 "www/pika/",则 relPath 为 "ctr/" --- */
|
|
652
673
|
const relPath = pat.slice(shortestMatch.length);
|
|
653
674
|
if (relPath) {
|
|
654
|
-
|
|
655
|
-
const firstSeg = relPath.split('/')[0];
|
|
675
|
+
const firstSeg = relPath.split('/')[0].toLowerCase();
|
|
656
676
|
if (!KEBAB_ALLOWED_DIRS.has(firstSeg)) {
|
|
657
677
|
continue;
|
|
658
678
|
}
|
|
@@ -783,11 +803,7 @@ function createRpcListener() {
|
|
|
783
803
|
const list = [];
|
|
784
804
|
let total = 0;
|
|
785
805
|
let skipHeader = format === 'csv';
|
|
786
|
-
|
|
787
|
-
* --- 统计匹配行数并取出当前页,跳过 CSV 表头 ---
|
|
788
|
-
* @param line 不含换行符的日志行
|
|
789
|
-
* @returns 无返回值
|
|
790
|
-
*/
|
|
806
|
+
// --- 统计匹配行数并取出当前页,跳过 CSV 表头 ---
|
|
791
807
|
const consumeLine = (line) => {
|
|
792
808
|
if (skipHeader) {
|
|
793
809
|
skipHeader = false;
|
|
@@ -840,21 +856,30 @@ function createRpcListener() {
|
|
|
840
856
|
return;
|
|
841
857
|
}
|
|
842
858
|
case 'monitor-events': {
|
|
859
|
+
// --- 按天分页查询监控事件摘要 ---
|
|
843
860
|
const result = await sMonitorFiles.getEvents(path.join(kebab.LOG_CWD, 'monitor'), msg.path ?? lTime.format(null, 'Y/m/d'), msg.offset ?? 0, msg.limit ?? 20);
|
|
844
861
|
res.setHeader('cache-control', 'no-store');
|
|
845
|
-
res.end(lText.stringifyJson(result === false ? { 'result': 0 } : {
|
|
862
|
+
res.end(lText.stringifyJson(result === false ? { 'result': 0 } : {
|
|
863
|
+
'result': 1,
|
|
864
|
+
...result,
|
|
865
|
+
}));
|
|
846
866
|
return;
|
|
847
867
|
}
|
|
848
868
|
case 'monitor-event': {
|
|
869
|
+
// --- 查询单条监控事件详情与文件清单 ---
|
|
849
870
|
const data = await sMonitorFiles.getEvent(path.join(kebab.LOG_CWD, 'monitor'), msg.path);
|
|
850
871
|
res.setHeader('cache-control', 'no-store');
|
|
851
|
-
res.end(lText.stringifyJson(data === false ? { 'result': 0 } : {
|
|
872
|
+
res.end(lText.stringifyJson(data === false ? { 'result': 0 } : {
|
|
873
|
+
'result': 1,
|
|
874
|
+
'data': data,
|
|
875
|
+
}));
|
|
852
876
|
return;
|
|
853
877
|
}
|
|
854
878
|
case 'monitor-file': {
|
|
879
|
+
// --- 校验目标诊断文件及预览权限 ---
|
|
855
880
|
const file = await sMonitorFiles.getFile(path.join(kebab.LOG_CWD, 'monitor'), msg.path);
|
|
856
881
|
res.setHeader('cache-control', 'no-store');
|
|
857
|
-
if (file === false || msg.preview !== undefined && typeof msg.preview !== 'boolean') {
|
|
882
|
+
if (file === false || (msg.preview !== undefined && typeof msg.preview !== 'boolean')) {
|
|
858
883
|
res.writeHead(400);
|
|
859
884
|
res.end();
|
|
860
885
|
return;
|
|
@@ -869,9 +894,12 @@ function createRpcListener() {
|
|
|
869
894
|
res.end();
|
|
870
895
|
return;
|
|
871
896
|
}
|
|
897
|
+
// --- 设置响应头并流式输出文件 ---
|
|
872
898
|
let contentType = 'application/octet-stream';
|
|
873
899
|
if (msg.preview) {
|
|
874
|
-
contentType = file.info.preview === 'json'
|
|
900
|
+
contentType = file.info.preview === 'json'
|
|
901
|
+
? 'application/json; charset=utf-8'
|
|
902
|
+
: 'text/plain; charset=utf-8';
|
|
875
903
|
}
|
|
876
904
|
res.setHeader('content-type', contentType);
|
|
877
905
|
res.setHeader('x-content-type-options', 'nosniff');
|
|
@@ -1120,6 +1148,9 @@ async function createChildProcess(cpu) {
|
|
|
1120
1148
|
break;
|
|
1121
1149
|
}
|
|
1122
1150
|
case 'global': {
|
|
1151
|
+
if (typeof msg.key !== 'string' || msg.key === '__proto__' || msg.key === 'constructor' || msg.key === 'prototype') {
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1123
1154
|
// --- 为所有子进程更新 global 变量 ---
|
|
1124
1155
|
for (const pid in workerList) {
|
|
1125
1156
|
workerList[pid].worker.send({
|
package/sys/mod.d.ts
CHANGED
|
@@ -15,15 +15,22 @@ export type TOnlyProperties<T> = {
|
|
|
15
15
|
export type TModRow = Record<string, kebab.Json>;
|
|
16
16
|
/** --- 按条件查询单条记录的选项 --- */
|
|
17
17
|
export interface IModOneOptions {
|
|
18
|
+
/** --- 所属控制器,用于错误日志 --- */
|
|
18
19
|
'ctr'?: sCtr.Ctr;
|
|
19
20
|
/** --- 加锁时确保 WHERE 条件命中索引,以免锁定过多记录 --- */
|
|
20
21
|
'lock'?: boolean;
|
|
21
22
|
/** --- MySQL 表前缀或 PostgreSQL Schema 名 --- */
|
|
22
23
|
'pre'?: string;
|
|
24
|
+
/** --- 分表后缀 --- */
|
|
23
25
|
'index'?: string | string[];
|
|
26
|
+
/** --- 指定查询字段 --- */
|
|
24
27
|
'select'?: string | string[];
|
|
28
|
+
/** --- 排序字段与方向 --- */
|
|
25
29
|
'by'?: [string | string[], 'DESC' | 'ASC'];
|
|
30
|
+
/** --- SQL 优化提示 --- */
|
|
26
31
|
'hint'?: string;
|
|
32
|
+
/** --- 是否优先使用只读从库,默认 false(走主库);加锁或事务内仍走主库 --- */
|
|
33
|
+
'read'?: boolean;
|
|
27
34
|
}
|
|
28
35
|
/** --- 一批游标查询结果,hasMore 表示扫描方向上还有记录 --- */
|
|
29
36
|
export interface ICursorPage<T extends object = Record<string, unknown>> {
|
|
@@ -94,6 +101,8 @@ export default class Mod {
|
|
|
94
101
|
protected _ctr?: sCtr.Ctr;
|
|
95
102
|
/** --- 主表筛选前缀,优先 alias,其次表名 --- */
|
|
96
103
|
protected _fieldPrefix: string;
|
|
104
|
+
/** --- 当前查询是否优先使用只读从库 --- */
|
|
105
|
+
protected _read: boolean;
|
|
97
106
|
/**
|
|
98
107
|
* --- 构造函数 ---
|
|
99
108
|
* @param opt 选项
|
|
@@ -115,6 +124,8 @@ export default class Mod {
|
|
|
115
124
|
'hint'?: string;
|
|
116
125
|
/** --- MySQL 表前缀或 PostgreSQL Schema 名,优先级:选项 > 类属性 > 配置 --- */
|
|
117
126
|
'pre'?: string;
|
|
127
|
+
/** --- 是否优先使用只读从库,默认 false(走主库) --- */
|
|
128
|
+
'read'?: boolean;
|
|
118
129
|
});
|
|
119
130
|
/** --- 创建字段对象 --- */
|
|
120
131
|
static column(field: string): {
|
|
@@ -243,6 +254,7 @@ export default class Mod {
|
|
|
243
254
|
'list': string[];
|
|
244
255
|
};
|
|
245
256
|
'hint'?: string;
|
|
257
|
+
'read'?: boolean;
|
|
246
258
|
}): T;
|
|
247
259
|
/**
|
|
248
260
|
* --- 通过 where 条件获取模型 ---
|
|
@@ -260,6 +272,7 @@ export default class Mod {
|
|
|
260
272
|
'list': string[];
|
|
261
273
|
};
|
|
262
274
|
'hint'?: string;
|
|
275
|
+
'read'?: boolean;
|
|
263
276
|
}): T;
|
|
264
277
|
/**
|
|
265
278
|
* --- 获取创建对象,通常用于新建数据库条目 ---
|
|
@@ -285,6 +298,8 @@ export default class Mod {
|
|
|
285
298
|
/** --- 通过 key 字段获取,默认为 false,即从主键获取 --- */
|
|
286
299
|
'key'?: boolean;
|
|
287
300
|
'hint'?: string;
|
|
301
|
+
/** --- 是否优先使用只读从库,默认 false(走主库);加锁或事务内仍走主库 --- */
|
|
302
|
+
'read'?: boolean;
|
|
288
303
|
}): Promise<false | null | (T & Record<string, any>)>;
|
|
289
304
|
/** --- 按条件读取一条原生记录,查询失败返回 false,未找到返回 null --- */
|
|
290
305
|
static one(db: lDb.Pool | lDb.Transaction, s: string | kebab.Json, opt: IModOneOptions & {
|
|
@@ -318,6 +333,7 @@ export default class Mod {
|
|
|
318
333
|
'ctr'?: sCtr.Ctr;
|
|
319
334
|
'pre'?: string;
|
|
320
335
|
'index'?: string;
|
|
336
|
+
'read'?: boolean;
|
|
321
337
|
}): Promise<any[] | false>;
|
|
322
338
|
/**
|
|
323
339
|
* --- 将模型字典转换为普通对象字典,沿用原有键 ---
|
|
@@ -383,6 +399,11 @@ export default class Mod {
|
|
|
383
399
|
* @returns 是否成功,缺少定位字段、记录不存在或删除失败返回 false
|
|
384
400
|
*/
|
|
385
401
|
remove(): Promise<boolean>;
|
|
402
|
+
/**
|
|
403
|
+
* --- 设置当前查询是否优先使用只读从库(加锁查询或事务内仍走主库) ---
|
|
404
|
+
* @param enable 是否使用只读从库,默认 true
|
|
405
|
+
*/
|
|
406
|
+
read(enable?: boolean): this;
|
|
386
407
|
/** --- 获取第一条原生记录,查询失败返回 false,未找到返回 null --- */
|
|
387
408
|
first(lock: boolean, array: true): Promise<false | null | TModRow>;
|
|
388
409
|
/** --- 获取第一个模型实例,查询失败返回 false,未找到返回 null --- */
|
|
@@ -640,7 +661,7 @@ export default class Mod {
|
|
|
640
661
|
*/
|
|
641
662
|
updates(): Record<string, any>;
|
|
642
663
|
/**
|
|
643
|
-
* --- 当前是否设置了未保存
|
|
664
|
+
* --- 当前是否设置了未保存 ---
|
|
644
665
|
*/
|
|
645
666
|
unsaved(): boolean;
|
|
646
667
|
/**
|
|
@@ -654,8 +675,9 @@ export default class Mod {
|
|
|
654
675
|
*/
|
|
655
676
|
protected _keyGenerator(): string;
|
|
656
677
|
}
|
|
678
|
+
/** --- 模型记录集合接口 --- */
|
|
657
679
|
export interface IRows<T> extends Iterable<T> {
|
|
658
|
-
readonly length: number;
|
|
680
|
+
readonly 'length': number;
|
|
659
681
|
item(index: number): T;
|
|
660
682
|
toArray(): Array<Record<string, any>>;
|
|
661
683
|
}
|