baja-lite 1.8.0 → 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/README.md +920 -1
- package/boot-remote.js +0 -3
- package/boot.js +0 -3
- package/error.d.ts +27 -0
- package/error.js +42 -0
- package/math.js +2 -2
- package/package.json +1 -1
- package/snowflake.js +13 -3
- package/sql.d.ts +5 -0
- package/sql.js +124 -78
- package/string.d.ts +6 -1
- package/string.js +23 -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/error.d.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据库错误类
|
|
3
|
+
* 用于统一数据库操作中的错误处理
|
|
4
|
+
*/
|
|
5
|
+
export declare class DatabaseError extends Error {
|
|
6
|
+
code: string;
|
|
7
|
+
sql?: string | undefined;
|
|
8
|
+
params?: any | undefined;
|
|
9
|
+
cause?: Error | undefined;
|
|
10
|
+
constructor(message: string, code: string, sql?: string | undefined, params?: any | undefined, cause?: Error | undefined);
|
|
11
|
+
/**
|
|
12
|
+
* 创建连接错误
|
|
13
|
+
*/
|
|
14
|
+
static connection(message: string, cause?: Error): DatabaseError;
|
|
15
|
+
/**
|
|
16
|
+
* 创建查询错误
|
|
17
|
+
*/
|
|
18
|
+
static query(message: string, sql: string, params?: any, cause?: Error): DatabaseError;
|
|
19
|
+
/**
|
|
20
|
+
* 创建事务错误
|
|
21
|
+
*/
|
|
22
|
+
static transaction(message: string, cause?: Error): DatabaseError;
|
|
23
|
+
/**
|
|
24
|
+
* 获取安全的错误信息(不包含敏感数据)
|
|
25
|
+
*/
|
|
26
|
+
getSafeMessage(): string;
|
|
27
|
+
}
|
|
1
28
|
export declare const Throw: {
|
|
2
29
|
if(test: boolean, message: string | Error | any): void;
|
|
3
30
|
ifNot(test: boolean, message: string | Error | any): void;
|
package/error.js
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据库错误类
|
|
3
|
+
* 用于统一数据库操作中的错误处理
|
|
4
|
+
*/
|
|
5
|
+
export class DatabaseError extends Error {
|
|
6
|
+
constructor(message, code, sql, params, cause) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.sql = sql;
|
|
10
|
+
this.params = params;
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.name = 'DatabaseError';
|
|
13
|
+
// 保持正确的堆栈跟踪
|
|
14
|
+
if (Error.captureStackTrace) {
|
|
15
|
+
Error.captureStackTrace(this, DatabaseError);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 创建连接错误
|
|
20
|
+
*/
|
|
21
|
+
static connection(message, cause) {
|
|
22
|
+
return new DatabaseError(message, 'CONNECTION_ERROR', undefined, undefined, cause);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 创建查询错误
|
|
26
|
+
*/
|
|
27
|
+
static query(message, sql, params, cause) {
|
|
28
|
+
return new DatabaseError(message, 'QUERY_ERROR', sql, params, cause);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 创建事务错误
|
|
32
|
+
*/
|
|
33
|
+
static transaction(message, cause) {
|
|
34
|
+
return new DatabaseError(message, 'TRANSACTION_ERROR', undefined, undefined, cause);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 获取安全的错误信息(不包含敏感数据)
|
|
38
|
+
*/
|
|
39
|
+
getSafeMessage() {
|
|
40
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
1
43
|
export const Throw = {
|
|
2
44
|
if(test, message) {
|
|
3
45
|
if (test === true)
|
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.d.ts
CHANGED
|
@@ -538,6 +538,8 @@ interface Dao {
|
|
|
538
538
|
}
|
|
539
539
|
export declare class Mysql implements Dao {
|
|
540
540
|
[_daoDB]: any;
|
|
541
|
+
private keepAliveTimer?;
|
|
542
|
+
private isClosing;
|
|
541
543
|
constructor(pool: any);
|
|
542
544
|
keepAlive(): Promise<void>;
|
|
543
545
|
createConnection(sync: SyncMode.Sync): Connection | null;
|
|
@@ -555,7 +557,10 @@ export declare class Mysql implements Dao {
|
|
|
555
557
|
}
|
|
556
558
|
export declare class Postgresql implements Dao {
|
|
557
559
|
[_daoDB]: any;
|
|
560
|
+
private keepAliveTimer?;
|
|
561
|
+
private isClosing;
|
|
558
562
|
constructor(pool: any);
|
|
563
|
+
keepAlive(): Promise<void>;
|
|
559
564
|
createConnection(sync: SyncMode.Sync): Connection | null;
|
|
560
565
|
createConnection(sync: SyncMode.Async): Promise<Connection | null>;
|
|
561
566
|
transaction<T = any>(sync: SyncMode.Sync, fn: (conn: Connection) => T, conn?: Connection | null): T | null;
|