@maiyunnet/kebab 4.1.0 → 5.0.1
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 +7 -2
- package/index.js +1 -1
- package/lib/db/conn.d.ts +91 -0
- package/lib/db/conn.js +328 -0
- package/lib/db/pool.d.ts +61 -0
- package/lib/db/pool.js +281 -0
- package/lib/db/tran.d.ts +33 -0
- package/lib/db/tran.js +122 -0
- package/lib/db.d.ts +35 -169
- package/lib/db.js +21 -582
- package/lib/scan.js +2 -2
- package/lib/sql.d.ts +24 -25
- package/lib/sql.js +230 -132
- package/lib/time.d.ts +1 -1
- package/lib/time.js +1 -1
- package/lib/turnstile.js +1 -1
- package/lib/vector.d.ts +9 -4
- package/lib/vector.js +46 -27
- package/package.json +6 -5
- package/sys/cmd.js +29 -6
- package/sys/mod.d.ts +8 -26
- package/sys/mod.js +110 -261
- package/www/example/ctr/test.js +119 -112
- package/www/example/data/test.zip +0 -0
- package/www/example/mod/test.js +22 -0
package/lib/time.d.ts
CHANGED
|
@@ -70,6 +70,6 @@ export declare function isMs(time: number): boolean;
|
|
|
70
70
|
* --- 将时间对象转换为时间字符串 ---
|
|
71
71
|
* @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
|
|
72
72
|
* @param f 转换格式
|
|
73
|
-
* @param date
|
|
73
|
+
* @param date 时间对象秒/毫秒级数字均可
|
|
74
74
|
*/
|
|
75
75
|
export declare function format(zone: number | sCtr.Ctr | null, f: string, date?: Date | number): string;
|
package/lib/time.js
CHANGED
|
@@ -132,7 +132,7 @@ export function isMs(time) {
|
|
|
132
132
|
* --- 将时间对象转换为时间字符串 ---
|
|
133
133
|
* @param zone 时区小时或 ctr 对象,如 8,设置 null 则以系统时区为准
|
|
134
134
|
* @param f 转换格式
|
|
135
|
-
* @param date
|
|
135
|
+
* @param date 时间对象秒/毫秒级数字均可
|
|
136
136
|
*/
|
|
137
137
|
export function format(zone, f, date) {
|
|
138
138
|
const over = [];
|
package/lib/turnstile.js
CHANGED
|
@@ -62,7 +62,7 @@ export async function verify(ctr, opt) {
|
|
|
62
62
|
'Ticket': opt.token.slice(0, io),
|
|
63
63
|
'UserIp': opt.ip,
|
|
64
64
|
'Randstr': opt.token.slice(io + 1),
|
|
65
|
-
'CaptchaAppId': parseInt(config.turnstile['TENCENT'].aid), // --- 防止后期又不是 number 了还要改config,这样只需要更新代码无损升级 ---
|
|
65
|
+
'CaptchaAppId': parseInt(config.turnstile['TENCENT'].aid), // --- 防止后期又不是 number 了还要改 config,这样只需要更新代码无损升级 ---
|
|
66
66
|
'AppSecretKey': config.turnstile['TENCENT'].akey,
|
|
67
67
|
});
|
|
68
68
|
return res.CaptchaCode === 1;
|
package/lib/vector.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Last: 2025-10-28 15:18:44
|
|
5
5
|
*/
|
|
6
6
|
import * as milvus from '@zilliz/milvus2-sdk-node';
|
|
7
|
+
import * as kebab from '#kebab/index.js';
|
|
7
8
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
8
9
|
/** --- 选项 --- */
|
|
9
10
|
export interface IOptions {
|
|
@@ -19,9 +20,9 @@ export interface IOptions {
|
|
|
19
20
|
'pwd'?: string;
|
|
20
21
|
}
|
|
21
22
|
export declare class Vector {
|
|
22
|
-
/** ---
|
|
23
|
-
readonly
|
|
24
|
-
constructor(
|
|
23
|
+
/** --- 当前的 vector 连接信息 --- */
|
|
24
|
+
private readonly _etc;
|
|
25
|
+
constructor(etc: kebab.IConfigVector);
|
|
25
26
|
/** --- 搜索 --- */
|
|
26
27
|
seach(data: {
|
|
27
28
|
/** --- 表名 --- */
|
|
@@ -44,9 +45,13 @@ export declare class Vector {
|
|
|
44
45
|
metric_type: "L2" | "IP" | "COSINE";
|
|
45
46
|
output_fields: string[] | undefined;
|
|
46
47
|
}>>;
|
|
48
|
+
/**
|
|
49
|
+
* --- 从连接池中获取一个符合要求的连接 ---
|
|
50
|
+
*/
|
|
51
|
+
private _getConnection;
|
|
47
52
|
}
|
|
48
53
|
/**
|
|
49
54
|
* --- 创建一个 Vector 对象 ---
|
|
50
55
|
* @param opt 选项
|
|
51
56
|
*/
|
|
52
|
-
export declare function get(
|
|
57
|
+
export declare function get(ctrEtc: sCtr.Ctr | kebab.IConfigVector): Vector;
|
package/lib/vector.js
CHANGED
|
@@ -4,39 +4,23 @@
|
|
|
4
4
|
* Last: 2025-10-28 15:18:44
|
|
5
5
|
*/
|
|
6
6
|
import * as milvus from '@zilliz/milvus2-sdk-node';
|
|
7
|
+
import * as lCore from '#kebab/lib/core.js';
|
|
8
|
+
import * as sCtr from '#kebab/sys/ctr.js';
|
|
7
9
|
/** --- milvus 的连接对象 --- */
|
|
8
10
|
const links = [];
|
|
9
11
|
export class Vector {
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
const host = opt?.host ?? config.vector?.host ?? '127.0.0.1';
|
|
13
|
-
const port = opt?.port ?? config.vector?.port ?? 19530;
|
|
14
|
-
const name = opt?.name ?? config.vector?.name ?? 'default';
|
|
15
|
-
const user = opt?.user ?? config.vector?.user ?? 'root';
|
|
16
|
-
const pwd = opt?.pwd ?? config.vector?.pwd ?? 'Milvue';
|
|
17
|
-
const token = `${host}-${port}-${name}-${user}`;
|
|
18
|
-
const link = links.find((item) => item.token === token);
|
|
19
|
-
if (link) {
|
|
20
|
-
this.link = link.link;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
this.link = new milvus.MilvusClient({
|
|
24
|
-
'address': `${host}:${port}`,
|
|
25
|
-
'ssl': false,
|
|
26
|
-
'database': name,
|
|
27
|
-
'username': user,
|
|
28
|
-
'password': pwd,
|
|
29
|
-
});
|
|
30
|
-
links.push({
|
|
31
|
-
'token': token,
|
|
32
|
-
'link': this.link,
|
|
33
|
-
});
|
|
12
|
+
constructor(etc) {
|
|
13
|
+
this._etc = etc;
|
|
34
14
|
}
|
|
35
15
|
/** --- 搜索 --- */
|
|
36
16
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
37
17
|
async seach(data) {
|
|
18
|
+
const link = await this._getConnection();
|
|
19
|
+
if (!link) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
38
22
|
try {
|
|
39
|
-
|
|
23
|
+
const res = await link.search({
|
|
40
24
|
'collection_name': data.collection,
|
|
41
25
|
'data': data.data,
|
|
42
26
|
'filter': data.filter,
|
|
@@ -44,16 +28,51 @@ export class Vector {
|
|
|
44
28
|
'metric_type': data.metric ?? 'L2',
|
|
45
29
|
'output_fields': data.fields,
|
|
46
30
|
});
|
|
31
|
+
return res;
|
|
47
32
|
}
|
|
48
33
|
catch {
|
|
49
34
|
return false;
|
|
50
35
|
}
|
|
51
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* --- 从连接池中获取一个符合要求的连接 ---
|
|
39
|
+
*/
|
|
40
|
+
async _getConnection() {
|
|
41
|
+
const token = `${this._etc.host}-${this._etc.port}-${this._etc.name}-${this._etc.user}`;
|
|
42
|
+
const item = links.find(item => item.token === token);
|
|
43
|
+
if (item) {
|
|
44
|
+
return item.link;
|
|
45
|
+
}
|
|
46
|
+
// --- 没有找到合适的连接,创建一个 ---
|
|
47
|
+
try {
|
|
48
|
+
const link = new milvus.MilvusClient({
|
|
49
|
+
'address': `${this._etc.host}:${this._etc.port}`,
|
|
50
|
+
'ssl': false,
|
|
51
|
+
'database': this._etc.name,
|
|
52
|
+
'username': this._etc.user,
|
|
53
|
+
'password': this._etc.pwd,
|
|
54
|
+
});
|
|
55
|
+
await link.connectPromise;
|
|
56
|
+
links.push({
|
|
57
|
+
'token': token,
|
|
58
|
+
link,
|
|
59
|
+
});
|
|
60
|
+
return link;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
lCore.debug('[VECTOR][_getConnection]', e.code, e.message);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
52
67
|
}
|
|
53
68
|
/**
|
|
54
69
|
* --- 创建一个 Vector 对象 ---
|
|
55
70
|
* @param opt 选项
|
|
56
71
|
*/
|
|
57
|
-
export function get(
|
|
58
|
-
|
|
72
|
+
export function get(ctrEtc) {
|
|
73
|
+
if (ctrEtc instanceof sCtr.Ctr) {
|
|
74
|
+
const config = ctrEtc.getPrototype('_config');
|
|
75
|
+
return new Vector(config.vector);
|
|
76
|
+
}
|
|
77
|
+
return new Vector(ctrEtc);
|
|
59
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
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.927.0",
|
|
23
|
+
"@aws-sdk/lib-storage": "^3.927.0",
|
|
24
24
|
"@litert/http-client": "^1.1.2",
|
|
25
25
|
"@litert/mime": "^0.1.3",
|
|
26
26
|
"@litert/redis": "^3.0.5",
|
|
@@ -32,15 +32,16 @@
|
|
|
32
32
|
"mysql2": "^3.15.3",
|
|
33
33
|
"node-cron": "^4.2.1",
|
|
34
34
|
"openai": "^6.8.1",
|
|
35
|
+
"pg": "^8.16.3",
|
|
35
36
|
"ssh2": "^1.17.0",
|
|
36
37
|
"svg-captcha": "^1.4.0",
|
|
37
|
-
"tencentcloud-sdk-nodejs": "^4.1.
|
|
38
|
+
"tencentcloud-sdk-nodejs": "^4.1.140"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@litert/eslint-plugin-rules": "^0.3.1",
|
|
41
42
|
"@types/ejs": "^3.1.5",
|
|
42
43
|
"@types/node": "^24.10.0",
|
|
43
|
-
"
|
|
44
|
+
"@types/pg": "^8.15.6",
|
|
44
45
|
"typescript": "^5.9.3"
|
|
45
46
|
}
|
|
46
47
|
}
|
package/sys/cmd.js
CHANGED
|
@@ -86,12 +86,35 @@ async function run() {
|
|
|
86
86
|
config.set.staticPath ??= '';
|
|
87
87
|
// --- config - db ---
|
|
88
88
|
config.db ??= {};
|
|
89
|
-
config.db.
|
|
90
|
-
config.db
|
|
91
|
-
config.db.
|
|
92
|
-
config.db.
|
|
93
|
-
config.db.
|
|
94
|
-
config.db.
|
|
89
|
+
config.db.default ??= 'PGSQL';
|
|
90
|
+
config.db['MYSQL'] ??= {};
|
|
91
|
+
config.db['MYSQL'].default ??= {};
|
|
92
|
+
config.db['MYSQL'].default.host ??= '127.0.0.1';
|
|
93
|
+
config.db['MYSQL'].default.port ??= 3306;
|
|
94
|
+
config.db['MYSQL'].default.charset ??= 'utf8mb4';
|
|
95
|
+
config.db['MYSQL'].default.name ??= 'maiyun';
|
|
96
|
+
config.db['MYSQL'].default.user ??= 'root';
|
|
97
|
+
config.db['MYSQL'].default.pwd ??= 'DashAdmin';
|
|
98
|
+
config.db['MYSQL'].read ??= {};
|
|
99
|
+
config.db['MYSQL'].read.host ??= '127.0.0.1';
|
|
100
|
+
config.db['MYSQL'].read.port ??= 3306;
|
|
101
|
+
config.db['MYSQL'].read.charset ??= 'utf8mb4';
|
|
102
|
+
config.db['MYSQL'].read.name ??= 'maiyun';
|
|
103
|
+
config.db['MYSQL'].read.user ??= 'root';
|
|
104
|
+
config.db['MYSQL'].read.pwd ??= 'DashAdmin';
|
|
105
|
+
config.db['PGSQL'] ??= {};
|
|
106
|
+
config.db['PGSQL'].default ??= {};
|
|
107
|
+
config.db['PGSQL'].default.host ??= '127.0.0.1';
|
|
108
|
+
config.db['PGSQL'].default.port ??= 5432;
|
|
109
|
+
config.db['PGSQL'].default.name ??= 'maiyun';
|
|
110
|
+
config.db['PGSQL'].default.user ??= 'root';
|
|
111
|
+
config.db['PGSQL'].default.pwd ??= 'DashAdmin';
|
|
112
|
+
config.db['PGSQL'].read ??= {};
|
|
113
|
+
config.db['PGSQL'].read.host ??= '127.0.0.1';
|
|
114
|
+
config.db['PGSQL'].read.port ??= 5432;
|
|
115
|
+
config.db['PGSQL'].read.name ??= 'maiyun';
|
|
116
|
+
config.db['PGSQL'].read.user ??= 'root';
|
|
117
|
+
config.db['PGSQL'].read.pwd ??= 'DashAdmin';
|
|
95
118
|
// --- config - jwt ---
|
|
96
119
|
config.jwt ??= {};
|
|
97
120
|
config.jwt.name ??= 'KE_JWT';
|
package/sys/mod.d.ts
CHANGED
|
@@ -40,8 +40,6 @@ export default class Mod {
|
|
|
40
40
|
protected static _$key: string;
|
|
41
41
|
/** --- 若使用 _$key 并且有多个 unique 索引,这里指定 _$key 的索引名 --- */
|
|
42
42
|
protected static _$index: string;
|
|
43
|
-
/** ---- 可开启软删软更新软新增 --- */
|
|
44
|
-
protected static _$soft: boolean;
|
|
45
43
|
/** --- 要 update 的内容 --- */
|
|
46
44
|
protected _updates: Record<string, boolean>;
|
|
47
45
|
/** --- 模型获取的属性 --- */
|
|
@@ -101,25 +99,15 @@ export default class Mod {
|
|
|
101
99
|
}): Promise<boolean | null | false>;
|
|
102
100
|
/**
|
|
103
101
|
* --- 获取添加一个序列的模拟 SQL ---
|
|
102
|
+
* @param db 数据库对象
|
|
104
103
|
* @param cs 字段列表
|
|
105
104
|
* @param vs 数据列表
|
|
106
105
|
* @param opt 选项
|
|
107
106
|
*/
|
|
108
|
-
static insertSql(cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
|
|
107
|
+
static insertSql(db: lDb.Pool | lDb.Transaction, cs: string[] | Record<string, any>, vs?: any[] | any[][], opt?: {
|
|
109
108
|
'pre'?: sCtr.Ctr | string;
|
|
110
109
|
'index'?: string;
|
|
111
110
|
}): string;
|
|
112
|
-
/**
|
|
113
|
-
* --- 插入数据如果唯一键冲突则更新 ---
|
|
114
|
-
* @param db 数据库对象
|
|
115
|
-
* @param data 要插入的数据
|
|
116
|
-
* @param update 要更新的数据
|
|
117
|
-
* @param opt 选项
|
|
118
|
-
*/
|
|
119
|
-
static insertDuplicate(db: lDb.Pool | lDb.Transaction, data: Record<string, any>, update: kebab.Json, opt?: {
|
|
120
|
-
'pre'?: sCtr.Ctr | string;
|
|
121
|
-
'index'?: string;
|
|
122
|
-
}): Promise<boolean | null>;
|
|
123
111
|
/**
|
|
124
112
|
* --- 根据条件移除条目 ---
|
|
125
113
|
* @param db 数据库对象
|
|
@@ -162,11 +150,12 @@ export default class Mod {
|
|
|
162
150
|
}): Promise<number | false | null>;
|
|
163
151
|
/**
|
|
164
152
|
* --- 根据条件更新数据(仅获取 SQL 对象) ---
|
|
153
|
+
* @param db 数据库对象
|
|
165
154
|
* @param data 要更新的数据
|
|
166
155
|
* @param where 筛选条件
|
|
167
156
|
* @param opt 选项
|
|
168
157
|
*/
|
|
169
|
-
static updateByWhereSql(data: kebab.Json, where: string | kebab.Json, opt?: {
|
|
158
|
+
static updateByWhereSql(db: lDb.Pool | lDb.Transaction, data: kebab.Json, where: string | kebab.Json, opt?: {
|
|
170
159
|
'raw'?: boolean;
|
|
171
160
|
'pre'?: sCtr.Ctr | string;
|
|
172
161
|
'index'?: string;
|
|
@@ -289,14 +278,8 @@ export default class Mod {
|
|
|
289
278
|
get(n: string): any;
|
|
290
279
|
/**
|
|
291
280
|
* --- 创建数据 ---
|
|
292
|
-
* @param notWhere 若要不存在才成功,则要传入限定条件
|
|
293
|
-
* @param table 可对限定条件传入适当的表
|
|
294
|
-
*/
|
|
295
|
-
create(notWhere?: string | kebab.Json, table?: string): Promise<boolean>;
|
|
296
|
-
/**
|
|
297
|
-
* --- 唯一键冲突则替换,不冲突则创建数据 ---
|
|
298
281
|
*/
|
|
299
|
-
|
|
282
|
+
create(): Promise<boolean>;
|
|
300
283
|
/**
|
|
301
284
|
* --- 刷新当前模型获取最新数据 ---
|
|
302
285
|
* @param lock 是否加锁
|
|
@@ -308,9 +291,8 @@ export default class Mod {
|
|
|
308
291
|
save(): Promise<boolean>;
|
|
309
292
|
/**
|
|
310
293
|
* --- 移除本条目 ---
|
|
311
|
-
* @param raw 是否真实移除
|
|
312
294
|
*/
|
|
313
|
-
remove(
|
|
295
|
+
remove(): Promise<boolean>;
|
|
314
296
|
first(lock: boolean, array: true): Promise<false | null | Record<string, any>>;
|
|
315
297
|
first(lock?: boolean, array?: false): Promise<false | null | (this & Record<string, any>)>;
|
|
316
298
|
/**
|
|
@@ -401,13 +383,13 @@ export default class Mod {
|
|
|
401
383
|
* @param s 筛选条件数组或字符串
|
|
402
384
|
* @param raw 是否包含已被软删除的数据
|
|
403
385
|
*/
|
|
404
|
-
filter(s: kebab.Json
|
|
386
|
+
filter(s: kebab.Json): this;
|
|
405
387
|
/**
|
|
406
388
|
* --- 是 filter 的别名 ---
|
|
407
389
|
* @param s 筛选条件数组或字符串
|
|
408
390
|
* @param raw 是否包含已被软删除的数据
|
|
409
391
|
*/
|
|
410
|
-
where(s: kebab.Json
|
|
392
|
+
where(s: kebab.Json): this;
|
|
411
393
|
/**
|
|
412
394
|
* --- ORDER BY ---
|
|
413
395
|
* @param c 字段字符串或数组
|