baja-lite 1.8.1 → 1.8.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/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 zeros = arr.slice(1).findIndex(i => i.equals(ZERO));
89
- if (zeros > -1) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
package/snowflake.js CHANGED
@@ -84,15 +84,25 @@ export class Snowflake {
84
84
  */
85
85
  generate() {
86
86
  let time = Date.now();
87
- // 基础保护:如果系统时间回拨,强制同步到最后一次生成时间以防止 ID 重复
87
+ // 时钟回拨处理
88
88
  if (time < this.lastTime) {
89
- time = this.lastTime;
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
- // 方案2:不再忙等待,直接预支进入下一毫秒
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
- console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
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 {
@@ -1912,7 +1916,11 @@ function P(skipConn = false) {
1912
1916
  resolve(result);
1913
1917
  }
1914
1918
  catch (error) {
1915
- console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1919
+ let args = '';
1920
+ if (args.length > 0 && args[0].params) {
1921
+ args = JSON.stringify(args[0].params);
1922
+ }
1923
+ console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
1916
1924
  reject(error);
1917
1925
  }
1918
1926
  finally {
@@ -1942,7 +1950,11 @@ function P(skipConn = false) {
1942
1950
  resolve(result);
1943
1951
  }
1944
1952
  catch (error) {
1945
- console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1953
+ let args = '';
1954
+ if (args.length > 0 && args[0].params) {
1955
+ args = JSON.stringify(args[0].params);
1956
+ }
1957
+ console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
1946
1958
  reject(error);
1947
1959
  }
1948
1960
  finally {
@@ -1972,7 +1984,11 @@ function P(skipConn = false) {
1972
1984
  resolve(result);
1973
1985
  }
1974
1986
  catch (error) {
1975
- console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${JSON.stringify(args.filter(i => typeof i !== 'object' || (typeof i === 'object' && !i.insert)))}`);
1987
+ let args = '';
1988
+ if (args.length > 0 && args[0].params) {
1989
+ args = JSON.stringify(args[0].params);
1990
+ }
1991
+ console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
1976
1992
  reject(error);
1977
1993
  }
1978
1994
  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
- * 安全字符串处理(移除单引号,防止简单 SQL 注入)
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
- * 安全字符串处理(移除单引号,防止简单 SQL 注入)
33
+ * 安全字符串处理(移除单引号)
34
+ * @deprecated 不推荐用于 SQL 注入防护,请使用参数化查询
35
+ * @param source 源字符串
36
+ * @returns 移除单引号后的字符串
34
37
  */
35
38
  export const safeString = (source) => {
36
39
  if (source) {