baja-lite 1.3.42 → 1.3.44
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/package.json +6 -6
- package/sql.d.ts +8 -1
- package/sql.js +11 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "baja-lite",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.44",
|
|
4
4
|
"description": "some util for self",
|
|
5
5
|
"homepage": "https://github.com/void-soul/util-man",
|
|
6
6
|
"repository": {
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"reflect-metadata": "0.2.2",
|
|
50
50
|
"request": "2.88.2",
|
|
51
51
|
"request-promise": "4.2.6",
|
|
52
|
-
"sql-formatter": "15.
|
|
52
|
+
"sql-formatter": "15.5.2",
|
|
53
53
|
"sqlstring": "2.3.3",
|
|
54
54
|
"tslib": "2.8.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@types/better-sqlite3": "7.6.
|
|
57
|
+
"@types/better-sqlite3": "7.6.13",
|
|
58
58
|
"@types/lodash.get": "4.4.9",
|
|
59
59
|
"@types/mustache": "4.2.5",
|
|
60
|
-
"@types/node": "22.13.
|
|
60
|
+
"@types/node": "22.13.0",
|
|
61
61
|
"@types/pg-pool": "2.0.6",
|
|
62
62
|
"@types/shelljs": "0.8.15",
|
|
63
63
|
"@types/sqlstring": "2.3.2",
|
|
64
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
65
|
-
"@typescript-eslint/parser": "8.
|
|
64
|
+
"@typescript-eslint/eslint-plugin": "8.29.1",
|
|
65
|
+
"@typescript-eslint/parser": "8.29.1",
|
|
66
66
|
"better-sqlite3": "11.9.1",
|
|
67
67
|
"ioredis": "5.6.0",
|
|
68
68
|
"mongodb": "6.15.0",
|
package/sql.d.ts
CHANGED
|
@@ -1741,6 +1741,7 @@ export declare function getRedisDB<T = any>(db?: string): T;
|
|
|
1741
1741
|
redlock
|
|
1742
1742
|
*/
|
|
1743
1743
|
export declare function GetRedisLock(key: string, lockMaxActive?: number): Promise<boolean>;
|
|
1744
|
+
/** 对FN加锁、缓存执行 */
|
|
1744
1745
|
export declare function excuteWithLock<T>(config: {
|
|
1745
1746
|
/** 返回缓存key,参数=方法的参数+当前用户对象,可以用来清空缓存。 */
|
|
1746
1747
|
key: ((...args: any[]) => string) | string;
|
|
@@ -1774,7 +1775,12 @@ export declare function MethodLock<T = any>(config: {
|
|
|
1774
1775
|
/** 单个锁多少【毫秒】后自动释放?即时任务没有执行完毕或者没有主动释放锁? */
|
|
1775
1776
|
lockMaxTime?: number;
|
|
1776
1777
|
}): (target: T, _propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
1778
|
+
/** 清空方法缓存 */
|
|
1777
1779
|
export declare function clearMethodCache(key: string): Promise<void>;
|
|
1780
|
+
/**
|
|
1781
|
+
* 执行一个方法fn,
|
|
1782
|
+
* 如果有缓存,则返回缓存,否则执行方法并缓存
|
|
1783
|
+
*/
|
|
1778
1784
|
export declare function excuteWithCache<T>(config: {
|
|
1779
1785
|
/** 返回缓存key,参数=方法的参数+当前用户对象,可以用来清空缓存。 */
|
|
1780
1786
|
key: string;
|
|
@@ -1784,7 +1790,8 @@ export declare function excuteWithCache<T>(config: {
|
|
|
1784
1790
|
autoClearTime?: number;
|
|
1785
1791
|
/** 随着当前用户sesion的清空而一起清空 */
|
|
1786
1792
|
clearWithSession?: boolean;
|
|
1787
|
-
}, fn: () => Promise<T>): Promise<
|
|
1793
|
+
}, fn: () => Promise<T>): Promise<T>;
|
|
1794
|
+
/** 缓存注解 */
|
|
1788
1795
|
export declare function MethodCache<T = any>(config: {
|
|
1789
1796
|
/** 返回缓存key,参数=方法的参数[注意:必须和主方法的参数数量、完全一致,同时会追加一个当前用户对象]+当前用户对象,可以用来清空缓存。 */
|
|
1790
1797
|
key: ((this: T, ...args: any[]) => string) | string;
|
package/sql.js
CHANGED
|
@@ -4567,6 +4567,7 @@ export async function GetRedisLock(key, lockMaxActive) {
|
|
|
4567
4567
|
}
|
|
4568
4568
|
}
|
|
4569
4569
|
;
|
|
4570
|
+
/** 对FN加锁、缓存执行 */
|
|
4570
4571
|
export async function excuteWithLock(config, fn__) {
|
|
4571
4572
|
const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
|
|
4572
4573
|
const db = getRedisDB();
|
|
@@ -4587,13 +4588,13 @@ export async function excuteWithLock(config, fn__) {
|
|
|
4587
4588
|
}
|
|
4588
4589
|
else {
|
|
4589
4590
|
logger.debug(`get lock ${key} ok!`);
|
|
4590
|
-
await db.
|
|
4591
|
+
await db.pexpire(key, config.lockMaxTime ?? 60000);
|
|
4591
4592
|
try {
|
|
4592
4593
|
return await fn__();
|
|
4593
4594
|
}
|
|
4594
4595
|
finally {
|
|
4595
4596
|
logger.debug(`unlock ${key} ok!`);
|
|
4596
|
-
await db.
|
|
4597
|
+
await db.decr(key);
|
|
4597
4598
|
}
|
|
4598
4599
|
}
|
|
4599
4600
|
};
|
|
@@ -4609,6 +4610,7 @@ export function MethodLock(config) {
|
|
|
4609
4610
|
};
|
|
4610
4611
|
};
|
|
4611
4612
|
}
|
|
4613
|
+
/** 设置方法缓存 */
|
|
4612
4614
|
async function setMethodCache(config, devid) {
|
|
4613
4615
|
const db = getRedisDB();
|
|
4614
4616
|
if (config.result !== null && config.result !== undefined) {
|
|
@@ -4639,6 +4641,7 @@ async function setMethodCache(config, devid) {
|
|
|
4639
4641
|
}
|
|
4640
4642
|
}
|
|
4641
4643
|
}
|
|
4644
|
+
/** 清空方法缓存 */
|
|
4642
4645
|
export async function clearMethodCache(key) {
|
|
4643
4646
|
const db = getRedisDB();
|
|
4644
4647
|
let type = await db.type(`[cache-parent]${key}`);
|
|
@@ -4677,6 +4680,10 @@ async function clearParent(clearKey) {
|
|
|
4677
4680
|
}
|
|
4678
4681
|
}
|
|
4679
4682
|
}
|
|
4683
|
+
/**
|
|
4684
|
+
* 执行一个方法fn,
|
|
4685
|
+
* 如果有缓存,则返回缓存,否则执行方法并缓存
|
|
4686
|
+
*/
|
|
4680
4687
|
export async function excuteWithCache(config, fn) {
|
|
4681
4688
|
const db = getRedisDB();
|
|
4682
4689
|
const cache = await db.get(`[cache]${config.key}`);
|
|
@@ -4696,13 +4703,14 @@ export async function excuteWithCache(config, fn) {
|
|
|
4696
4703
|
return result;
|
|
4697
4704
|
}
|
|
4698
4705
|
}
|
|
4706
|
+
/** 缓存注解 */
|
|
4699
4707
|
export function MethodCache(config) {
|
|
4700
4708
|
return function (target, _propertyKey, descriptor) {
|
|
4701
4709
|
const fn = descriptor.value;
|
|
4702
4710
|
descriptor.value = async function (...args) {
|
|
4703
4711
|
const key = typeof config.key === 'function' ? config.key.call(this, ...args) : config.key;
|
|
4704
4712
|
const db = getRedisDB();
|
|
4705
|
-
const cache = await db.get(
|
|
4713
|
+
const cache = await db.get(`[cache]${key}`);
|
|
4706
4714
|
if (cache) {
|
|
4707
4715
|
logger.debug(`cache ${key} hit!`);
|
|
4708
4716
|
return JSON.parse(cache);
|