@maiyunnet/kebab 5.0.4 → 5.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/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/ai.d.ts +2 -0
- package/lib/ai.js +11 -0
- package/lib/crypto.d.ts +55 -0
- package/lib/crypto.js +0 -55
- package/lib/sql.js +6 -1
- package/package.json +1 -1
- package/sys/mod.d.ts +6 -1
- package/sys/mod.js +7 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '5.0
|
|
9
|
+
export const VER = '5.1.0';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/ai.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare class Ai {
|
|
|
43
43
|
chat(body: openai.default.Chat.Completions.ChatCompletionCreateParamsNonStreaming): Promise<openai.APIPromise<openai.default.Chat.ChatCompletion> | false>;
|
|
44
44
|
/** --- 创建流式对话 --- */
|
|
45
45
|
chat(body: openai.default.Chat.Completions.ChatCompletionCreateParamsStreaming): Promise<openai.APIPromise<streaming.Stream<openai.default.Chat.ChatCompletionChunk>> | false>;
|
|
46
|
+
/** --- 创建向量 --- */
|
|
47
|
+
embedding(body: openai.default.EmbeddingCreateParams): Promise<openai.APIPromise<openai.default.CreateEmbeddingResponse> | false>;
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
50
|
* --- 创建一个 AI 对象 ---
|
package/lib/ai.js
CHANGED
|
@@ -83,6 +83,17 @@ export class Ai {
|
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
/** --- 创建向量 --- */
|
|
87
|
+
async embedding(body) {
|
|
88
|
+
try {
|
|
89
|
+
return await this.link.embeddings.create(body);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
lCore.debug('[AI][EMBEDDING]', e);
|
|
93
|
+
lCore.log(this._ctr, `[AI][EMBEDDING] ${e.message}`, '-error');
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
86
97
|
}
|
|
87
98
|
/**
|
|
88
99
|
* --- 创建一个 AI 对象 ---
|
package/lib/crypto.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ export declare function generateKeyPair(type: string, options?: {
|
|
|
24
24
|
'public': string | Buffer;
|
|
25
25
|
'private': string | Buffer;
|
|
26
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* --- 非对称加签 ---
|
|
29
|
+
* @param data 数据
|
|
30
|
+
* @param privateKey 私钥
|
|
31
|
+
* @param format 输出格式
|
|
32
|
+
* @param algorithm 哈希方式
|
|
33
|
+
*/
|
|
27
34
|
export declare function sign(data: crypto.BinaryLike, privateKey: crypto.KeyLike | crypto.SignKeyObjectInput | crypto.SignPrivateKeyInput | crypto.SignJsonWebKeyInput, format: 'hex' | 'base64' | 'binary', algorithm?: string): string;
|
|
28
35
|
export declare function sign(data: crypto.BinaryLike, privateKey: crypto.KeyLike | crypto.SignKeyObjectInput | crypto.SignPrivateKeyInput | crypto.SignJsonWebKeyInput, format?: 'buffer', algorithm?: string): Buffer;
|
|
29
36
|
/**
|
|
@@ -77,10 +84,31 @@ export declare const SM4_CFB = "sm4-cfb";
|
|
|
77
84
|
* @param method 加密方法
|
|
78
85
|
*/
|
|
79
86
|
export declare function cipherEncrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64' | 'buffer'): string | Buffer | false;
|
|
87
|
+
/**
|
|
88
|
+
* --- AES 加密 ---
|
|
89
|
+
* @param original 原始字符串
|
|
90
|
+
* @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
|
|
91
|
+
* @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
|
|
92
|
+
* @param method 加密方法
|
|
93
|
+
* @param output 输出类型
|
|
94
|
+
*/
|
|
80
95
|
export declare function aesEncrypt(original: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
|
|
81
96
|
export declare function aesEncrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64'): string | false;
|
|
97
|
+
/**
|
|
98
|
+
* --- AES GCM 托管加密 ---
|
|
99
|
+
* @param original 原始字符串
|
|
100
|
+
* @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
|
|
101
|
+
* @param output 输出类型
|
|
102
|
+
*/
|
|
82
103
|
export declare function gcmEncrypt(original: string | Buffer, key: crypto.CipherKey, output: 'buffer'): Buffer | false;
|
|
83
104
|
export declare function gcmEncrypt(original: string | Buffer, key: crypto.CipherKey, output?: 'base64'): string | false;
|
|
105
|
+
/**
|
|
106
|
+
* --- SM4 加密 ---
|
|
107
|
+
* @param original 原始字符串
|
|
108
|
+
* @param key 密钥 32 个英文字母和数字
|
|
109
|
+
* @param iv 向量 16 个英文字母和数字
|
|
110
|
+
* @param method 加密方法
|
|
111
|
+
*/
|
|
84
112
|
export declare function sm4Encrypt(original: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
|
|
85
113
|
export declare function sm4Encrypt(original: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'base64'): string | false;
|
|
86
114
|
/**
|
|
@@ -91,12 +119,39 @@ export declare function sm4Encrypt(original: string | Buffer, key: crypto.Cipher
|
|
|
91
119
|
* @param method 加密方法
|
|
92
120
|
*/
|
|
93
121
|
export declare function cipherDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary' | 'buffer'): string | Buffer | false;
|
|
122
|
+
/**
|
|
123
|
+
* --- AES 解密 ---
|
|
124
|
+
* @param encrypt 需解密的字符串
|
|
125
|
+
* @param key 密钥 32 个英文字母和数字
|
|
126
|
+
* @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
|
|
127
|
+
* @param method 加密方法
|
|
128
|
+
*/
|
|
94
129
|
export declare function aesDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
|
|
95
130
|
export declare function aesDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary'): string | false;
|
|
131
|
+
/**
|
|
132
|
+
* --- AES 解密 ---
|
|
133
|
+
* @param encrypt 需解密的字符串
|
|
134
|
+
* @param key 密钥 32 个英文字母和数字
|
|
135
|
+
* @param iv 向量 16 个英文字母和数字
|
|
136
|
+
* @param method 加密方法
|
|
137
|
+
*/
|
|
96
138
|
export declare function gcmDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, output: 'buffer'): Buffer | false;
|
|
97
139
|
export declare function gcmDecrypt(encrypt: string | Buffer, key: crypto.CipherKey, output?: 'binary'): string | false;
|
|
140
|
+
/**
|
|
141
|
+
* --- SM4 解密 ---
|
|
142
|
+
* @param encrypt 需解密的字符串
|
|
143
|
+
* @param key 密钥 32 个英文字母和数字
|
|
144
|
+
* @param iv 向量 16 个英文字母和数字
|
|
145
|
+
* @param method 加密方法
|
|
146
|
+
*/
|
|
98
147
|
export declare function sm4Decrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv: string, method: string, output: 'buffer'): Buffer | false;
|
|
99
148
|
export declare function sm4Decrypt(encrypt: string | Buffer, key: crypto.CipherKey, iv?: string, method?: string, output?: 'binary'): string | false;
|
|
149
|
+
/**
|
|
150
|
+
* --- hash 或 hmac 加密 ---
|
|
151
|
+
* @param algorithm 哈希方式
|
|
152
|
+
* @param data 源数据
|
|
153
|
+
* @param key 设置则采用 hmac 加密
|
|
154
|
+
*/
|
|
100
155
|
export declare function hashHmac(algorithm: string, data: Buffer | string, key?: crypto.CipherKey, format?: 'hex' | 'base64'): string;
|
|
101
156
|
export declare function hashHmac(algorithm: string, data: Buffer | string, key: crypto.CipherKey | undefined, format: 'buffer'): Buffer;
|
|
102
157
|
export declare function hashHmacFile(algorithm: string, path: string, key?: crypto.CipherKey, encoding?: 'hex' | 'base64' | 'base64url'): Promise<string | false>;
|
package/lib/crypto.js
CHANGED
|
@@ -39,13 +39,6 @@ export function generateKeyPair(type, options = {}) {
|
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
43
|
-
* --- 非对称加签 ---
|
|
44
|
-
* @param data 数据
|
|
45
|
-
* @param privateKey 私钥
|
|
46
|
-
* @param format 输出格式
|
|
47
|
-
* @param algorithm 哈希方式
|
|
48
|
-
*/
|
|
49
42
|
export function sign(data, privateKey, format = 'buffer', algorithm = 'sha256') {
|
|
50
43
|
const sign = crypto.createSign(algorithm);
|
|
51
44
|
sign.update(data);
|
|
@@ -165,26 +158,12 @@ export function cipherEncrypt(original, key, iv = '', method = AES_256_ECB, outp
|
|
|
165
158
|
return false;
|
|
166
159
|
}
|
|
167
160
|
}
|
|
168
|
-
/**
|
|
169
|
-
* --- AES 加密 ---
|
|
170
|
-
* @param original 原始字符串
|
|
171
|
-
* @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
|
|
172
|
-
* @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
|
|
173
|
-
* @param method 加密方法
|
|
174
|
-
* @param output 输出类型
|
|
175
|
-
*/
|
|
176
161
|
export function aesEncrypt(original, key, iv = '', method = AES_256_ECB, output = 'base64') {
|
|
177
162
|
if (iv !== '') {
|
|
178
163
|
method = method === AES_256_ECB ? AES_256_CTR : method;
|
|
179
164
|
}
|
|
180
165
|
return cipherEncrypt(original, key, iv, method, output);
|
|
181
166
|
}
|
|
182
|
-
/**
|
|
183
|
-
* --- AES GCM 托管加密 ---
|
|
184
|
-
* @param original 原始字符串
|
|
185
|
-
* @param key 密钥尽量 32 个英文字母和数字,不是 32 个系统会自动处理
|
|
186
|
-
* @param output 输出类型
|
|
187
|
-
*/
|
|
188
167
|
export function gcmEncrypt(original, key, output = 'base64') {
|
|
189
168
|
const iv = lCore.random(12, lCore.RANDOM_LUNS);
|
|
190
169
|
const rtn = cipherEncrypt(original, key, iv, AES_256_GCM, output);
|
|
@@ -193,13 +172,6 @@ export function gcmEncrypt(original, key, output = 'base64') {
|
|
|
193
172
|
}
|
|
194
173
|
return typeof rtn === 'string' ? iv + rtn : Buffer.concat([Buffer.from(iv), rtn]);
|
|
195
174
|
}
|
|
196
|
-
/**
|
|
197
|
-
* --- SM4 加密 ---
|
|
198
|
-
* @param original 原始字符串
|
|
199
|
-
* @param key 密钥 32 个英文字母和数字
|
|
200
|
-
* @param iv 向量 16 个英文字母和数字
|
|
201
|
-
* @param method 加密方法
|
|
202
|
-
*/
|
|
203
175
|
export function sm4Encrypt(original, key, iv = '', method = SM4_ECB, output = 'base64') {
|
|
204
176
|
if (iv !== '') {
|
|
205
177
|
method = method === SM4_ECB ? SM4_CFB : method;
|
|
@@ -268,48 +240,21 @@ export function cipherDecrypt(encrypt, key, iv = '', method = AES_256_ECB, outpu
|
|
|
268
240
|
return false;
|
|
269
241
|
}
|
|
270
242
|
}
|
|
271
|
-
/**
|
|
272
|
-
* --- AES 解密 ---
|
|
273
|
-
* @param encrypt 需解密的字符串
|
|
274
|
-
* @param key 密钥 32 个英文字母和数字
|
|
275
|
-
* @param iv 向量 16(CTR) 或 12(GCM) 个英文字母和数字
|
|
276
|
-
* @param method 加密方法
|
|
277
|
-
*/
|
|
278
243
|
export function aesDecrypt(encrypt, key, iv = '', method = AES_256_ECB, output = 'binary') {
|
|
279
244
|
if (iv !== '') {
|
|
280
245
|
method = method === AES_256_ECB ? AES_256_CTR : method;
|
|
281
246
|
}
|
|
282
247
|
return cipherDecrypt(encrypt, key, iv, method, output);
|
|
283
248
|
}
|
|
284
|
-
/**
|
|
285
|
-
* --- AES 解密 ---
|
|
286
|
-
* @param encrypt 需解密的字符串
|
|
287
|
-
* @param key 密钥 32 个英文字母和数字
|
|
288
|
-
* @param iv 向量 16 个英文字母和数字
|
|
289
|
-
* @param method 加密方法
|
|
290
|
-
*/
|
|
291
249
|
export function gcmDecrypt(encrypt, key, output = 'binary') {
|
|
292
250
|
return cipherDecrypt(typeof encrypt === 'string' ? encrypt.slice(12) : encrypt.subarray(12), key, typeof encrypt === 'string' ? encrypt.slice(0, 12) : encrypt.subarray(0, 12).toString(), AES_256_GCM, output);
|
|
293
251
|
}
|
|
294
|
-
/**
|
|
295
|
-
* --- SM4 解密 ---
|
|
296
|
-
* @param encrypt 需解密的字符串
|
|
297
|
-
* @param key 密钥 32 个英文字母和数字
|
|
298
|
-
* @param iv 向量 16 个英文字母和数字
|
|
299
|
-
* @param method 加密方法
|
|
300
|
-
*/
|
|
301
252
|
export function sm4Decrypt(encrypt, key, iv = '', method = SM4_ECB, output = 'binary') {
|
|
302
253
|
if (iv !== '') {
|
|
303
254
|
method = method === SM4_ECB ? SM4_CFB : method;
|
|
304
255
|
}
|
|
305
256
|
return cipherDecrypt(encrypt, key, iv, method, output);
|
|
306
257
|
}
|
|
307
|
-
/**
|
|
308
|
-
* --- hash 或 hmac 加密 ---
|
|
309
|
-
* @param algorithm 哈希方式
|
|
310
|
-
* @param data 源数据
|
|
311
|
-
* @param key 设置则采用 hmac 加密
|
|
312
|
-
*/
|
|
313
258
|
export function hashHmac(algorithm, data, key, format = 'hex') {
|
|
314
259
|
const cry = key ? crypto.createHmac(algorithm, key) : crypto.createHash(algorithm);
|
|
315
260
|
cry.update(data);
|
package/lib/sql.js
CHANGED
|
@@ -474,7 +474,12 @@ export class Sql {
|
|
|
474
474
|
let field = this.field(f, pre || this._pre, suf ? ('#' + suf) : '');
|
|
475
475
|
if (pre) {
|
|
476
476
|
// --- 处理不同 pre 的 as 前缀问题 ---
|
|
477
|
-
|
|
477
|
+
if (this._service === ESERVICE.MYSQL) {
|
|
478
|
+
field = field.replace(new RegExp(`AS \`${pre}(.+?)\``), `AS \`${this._pre}$1\``);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
field = field.replace(new RegExp(`AS "${pre}"."(.+?)"`), `AS "${this._pre}"."$1"`);
|
|
482
|
+
}
|
|
478
483
|
}
|
|
479
484
|
let sql = ' ' + type + ' JOIN ' + field;
|
|
480
485
|
if (Array.isArray(s) ? s.length : Object.keys(s).length) {
|
package/package.json
CHANGED
package/sys/mod.d.ts
CHANGED
|
@@ -335,7 +335,7 @@ export default class Mod {
|
|
|
335
335
|
* @param s ON 信息
|
|
336
336
|
* @param type 类型
|
|
337
337
|
* @param index 给本表增加 index 分表项
|
|
338
|
-
* @param pre
|
|
338
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
339
339
|
*/
|
|
340
340
|
join(f: string, s?: kebab.Json, type?: string, index?: string, pre?: string): this;
|
|
341
341
|
/**
|
|
@@ -343,6 +343,7 @@ export default class Mod {
|
|
|
343
343
|
* @param f 表名
|
|
344
344
|
* @param s ON 信息
|
|
345
345
|
* @param index 给本表增加 index 分表项
|
|
346
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
346
347
|
*/
|
|
347
348
|
leftJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
|
|
348
349
|
/**
|
|
@@ -350,6 +351,7 @@ export default class Mod {
|
|
|
350
351
|
* @param f 表名
|
|
351
352
|
* @param s ON 信息
|
|
352
353
|
* @param index 给本表增加 index 分表项
|
|
354
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
353
355
|
*/
|
|
354
356
|
rightJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
|
|
355
357
|
/**
|
|
@@ -357,6 +359,7 @@ export default class Mod {
|
|
|
357
359
|
* @param f 表名
|
|
358
360
|
* @param s ON 信息
|
|
359
361
|
* @param index 给本表增加 index 分表项
|
|
362
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
360
363
|
*/
|
|
361
364
|
innerJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
|
|
362
365
|
/**
|
|
@@ -364,6 +367,7 @@ export default class Mod {
|
|
|
364
367
|
* @param f 表名
|
|
365
368
|
* @param s ON 信息
|
|
366
369
|
* @param index 给本表增加 index 分表项
|
|
370
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
367
371
|
*/
|
|
368
372
|
fullJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
|
|
369
373
|
/**
|
|
@@ -371,6 +375,7 @@ export default class Mod {
|
|
|
371
375
|
* @param f 表名
|
|
372
376
|
* @param s ON 信息
|
|
373
377
|
* @param index 给本表增加 index 分表项
|
|
378
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
374
379
|
*/
|
|
375
380
|
crossJoin(f: string, s: kebab.Json, index?: string, pre?: string): this;
|
|
376
381
|
/**
|
package/sys/mod.js
CHANGED
|
@@ -435,7 +435,7 @@ export default class Mod {
|
|
|
435
435
|
return rtn;
|
|
436
436
|
}
|
|
437
437
|
/**
|
|
438
|
-
* ---
|
|
438
|
+
* --- 设置一个/多个属性,值为 underfind 则不会被更新 ---
|
|
439
439
|
* @param n 字符串或键/值
|
|
440
440
|
* @param v 可能是数字
|
|
441
441
|
*/
|
|
@@ -1085,7 +1085,7 @@ export default class Mod {
|
|
|
1085
1085
|
* @param s ON 信息
|
|
1086
1086
|
* @param type 类型
|
|
1087
1087
|
* @param index 给本表增加 index 分表项
|
|
1088
|
-
* @param pre
|
|
1088
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1089
1089
|
*/
|
|
1090
1090
|
join(f, s = [], type = 'INNER', index = '', pre = '') {
|
|
1091
1091
|
this._sql.join(f, s, type, index ? '_' + index : '', pre);
|
|
@@ -1096,6 +1096,7 @@ export default class Mod {
|
|
|
1096
1096
|
* @param f 表名
|
|
1097
1097
|
* @param s ON 信息
|
|
1098
1098
|
* @param index 给本表增加 index 分表项
|
|
1099
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1099
1100
|
*/
|
|
1100
1101
|
leftJoin(f, s, index = '', pre = '') {
|
|
1101
1102
|
this._sql.leftJoin(f, s, index ? '_' + index : '', pre);
|
|
@@ -1106,6 +1107,7 @@ export default class Mod {
|
|
|
1106
1107
|
* @param f 表名
|
|
1107
1108
|
* @param s ON 信息
|
|
1108
1109
|
* @param index 给本表增加 index 分表项
|
|
1110
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1109
1111
|
*/
|
|
1110
1112
|
rightJoin(f, s, index = '', pre = '') {
|
|
1111
1113
|
this._sql.rightJoin(f, s, index ? '_' + index : '', pre);
|
|
@@ -1116,6 +1118,7 @@ export default class Mod {
|
|
|
1116
1118
|
* @param f 表名
|
|
1117
1119
|
* @param s ON 信息
|
|
1118
1120
|
* @param index 给本表增加 index 分表项
|
|
1121
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1119
1122
|
*/
|
|
1120
1123
|
innerJoin(f, s, index = '', pre = '') {
|
|
1121
1124
|
this._sql.innerJoin(f, s, index ? '_' + index : '', pre);
|
|
@@ -1126,6 +1129,7 @@ export default class Mod {
|
|
|
1126
1129
|
* @param f 表名
|
|
1127
1130
|
* @param s ON 信息
|
|
1128
1131
|
* @param index 给本表增加 index 分表项
|
|
1132
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1129
1133
|
*/
|
|
1130
1134
|
fullJoin(f, s, index = '', pre = '') {
|
|
1131
1135
|
this._sql.fullJoin(f, s, index ? '_' + index : '', pre);
|
|
@@ -1136,6 +1140,7 @@ export default class Mod {
|
|
|
1136
1140
|
* @param f 表名
|
|
1137
1141
|
* @param s ON 信息
|
|
1138
1142
|
* @param index 给本表增加 index 分表项
|
|
1143
|
+
* @param pre 前缀,仅与主表的 pre 不同时传入
|
|
1139
1144
|
*/
|
|
1140
1145
|
crossJoin(f, s, index = '', pre = '') {
|
|
1141
1146
|
this._sql.crossJoin(f, s, index ? '_' + index : '', pre);
|