baja-lite 1.8.1 → 1.8.2
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/boot-remote.js +0 -3
- package/boot.js +0 -3
- package/math.js +2 -2
- package/package.json +1 -1
- package/snowflake.js +13 -3
- package/sql.js +5 -1
- package/string.d.ts +4 -1
- package/string.js +4 -1
package/boot-remote.js
CHANGED
|
@@ -8,9 +8,6 @@ export const BootRomote = async function (options) {
|
|
|
8
8
|
if (options.skipNull !== undefined) {
|
|
9
9
|
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
10
10
|
}
|
|
11
|
-
if (options.skipEmptyString !== undefined) {
|
|
12
|
-
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
13
|
-
}
|
|
14
11
|
if (options.maxDeal !== undefined) {
|
|
15
12
|
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
16
13
|
}
|
package/boot.js
CHANGED
|
@@ -9,9 +9,6 @@ export const Boot = async function (options) {
|
|
|
9
9
|
if (options.skipNull !== undefined) {
|
|
10
10
|
globalThis[_GlobalSqlOption].skipNull = options.skipNull;
|
|
11
11
|
}
|
|
12
|
-
if (options.skipEmptyString !== undefined) {
|
|
13
|
-
globalThis[_GlobalSqlOption].skipEmptyString = options.skipEmptyString;
|
|
14
|
-
}
|
|
15
12
|
if (options.maxDeal !== undefined) {
|
|
16
13
|
globalThis[_GlobalSqlOption].maxDeal = options.maxDeal;
|
|
17
14
|
}
|
package/math.js
CHANGED
|
@@ -85,8 +85,8 @@ export const div = (...args) => {
|
|
|
85
85
|
export const divDef = (def, ...args) => {
|
|
86
86
|
const arr = filterNumber2(args);
|
|
87
87
|
if (arr.length > 1) {
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
88
|
+
const hasZeroDivisor = arr.slice(1).some(i => i.equals(ZERO));
|
|
89
|
+
if (hasZeroDivisor) {
|
|
90
90
|
return new Decimal(def).toNumber();
|
|
91
91
|
}
|
|
92
92
|
return arr.reduce((a, b) => a.div(b)).toNumber();
|
package/package.json
CHANGED
package/snowflake.js
CHANGED
|
@@ -84,15 +84,25 @@ export class Snowflake {
|
|
|
84
84
|
*/
|
|
85
85
|
generate() {
|
|
86
86
|
let time = Date.now();
|
|
87
|
-
//
|
|
87
|
+
// 时钟回拨处理
|
|
88
88
|
if (time < this.lastTime) {
|
|
89
|
-
|
|
89
|
+
const offset = this.lastTime - time;
|
|
90
|
+
// 如果回拨超过 5 秒,拒绝生成 ID
|
|
91
|
+
if (offset > 5000) {
|
|
92
|
+
console.error(`Clock moved backwards by ${offset}ms. Refusing to generate id`);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// 小幅回拨,等待追上上次时间
|
|
96
|
+
while (Date.now() <= this.lastTime) {
|
|
97
|
+
// 忙等待
|
|
98
|
+
}
|
|
99
|
+
time = Date.now();
|
|
90
100
|
}
|
|
91
101
|
if (this.lastTime === time) {
|
|
92
102
|
this.seq++;
|
|
93
103
|
if (this.seq > 4095) {
|
|
94
104
|
this.seq = 0;
|
|
95
|
-
//
|
|
105
|
+
// 序列号溢出,进入下一毫秒
|
|
96
106
|
time++;
|
|
97
107
|
}
|
|
98
108
|
}
|
package/sql.js
CHANGED
|
@@ -1874,7 +1874,11 @@ function P(skipConn = false) {
|
|
|
1874
1874
|
return result;
|
|
1875
1875
|
}
|
|
1876
1876
|
catch (error) {
|
|
1877
|
-
|
|
1877
|
+
let args = '';
|
|
1878
|
+
if (args.length > 0 && args[0].params) {
|
|
1879
|
+
args = JSON.stringify(args[0].params);
|
|
1880
|
+
}
|
|
1881
|
+
console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
|
|
1878
1882
|
throw error;
|
|
1879
1883
|
}
|
|
1880
1884
|
finally {
|
package/string.d.ts
CHANGED
|
@@ -18,7 +18,10 @@ export declare const emptyString: (source: any, skipEmptyString?: boolean) => bo
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const notEmptyString: (source: any, skipEmptyString?: boolean) => boolean;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* 安全字符串处理(移除单引号)
|
|
22
|
+
* @deprecated 不推荐用于 SQL 注入防护,请使用参数化查询
|
|
23
|
+
* @param source 源字符串
|
|
24
|
+
* @returns 移除单引号后的字符串
|
|
22
25
|
*/
|
|
23
26
|
export declare const safeString: (source?: string) => string;
|
|
24
27
|
/**
|
package/string.js
CHANGED
|
@@ -30,7 +30,10 @@ export const notEmptyString = (source, skipEmptyString = true) => {
|
|
|
30
30
|
return emptyString(source, skipEmptyString) === false;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* 安全字符串处理(移除单引号)
|
|
34
|
+
* @deprecated 不推荐用于 SQL 注入防护,请使用参数化查询
|
|
35
|
+
* @param source 源字符串
|
|
36
|
+
* @returns 移除单引号后的字符串
|
|
34
37
|
*/
|
|
35
38
|
export const safeString = (source) => {
|
|
36
39
|
if (source) {
|