baja-lite 1.8.6 → 1.8.8

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.
Files changed (3) hide show
  1. package/package.json +3 -6
  2. package/sql.d.ts +22 -7
  3. package/sql.js +427 -395
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.8.6",
3
+ "version": "1.8.8",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/baja-lite",
6
6
  "repository": {
@@ -26,12 +26,9 @@
26
26
  "scripts": {
27
27
  "dist": "node ./ci.js",
28
28
  "mysql": "bun --inspect ./src/test-mysql.ts",
29
- "mysql2": "node inspect ./dist/cjs/test-mysql.js",
30
29
  "postgres": "bun --inspect ./src/test-postgresql.ts",
31
- "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
32
- "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
30
+ "sqlite": "bun --inspect ./src/test-sqlite.ts",
33
31
  "test": "bun --inspect ./src/test.ts",
34
- "test2": "node inspect ./dist/cjs/tes.js",
35
32
  "xml": "bun --inspect ./src/test-xml.ts"
36
33
  },
37
34
  "dependencies": {
@@ -43,7 +40,7 @@
43
40
  "pino": "10.3.1",
44
41
  "pino-pretty": "13.1.3",
45
42
  "reflect-metadata": "0.2.2",
46
- "sql-formatter": "15.8.1",
43
+ "sql-formatter": "15.8.2",
47
44
  "sqlstring": "2.3.3",
48
45
  "tslib": "2.8.1"
49
46
  },
package/sql.d.ts CHANGED
@@ -2093,9 +2093,6 @@ declare class StreamQuery<T extends object> {
2093
2093
  ```
2094
2094
  */
2095
2095
  export declare function getRedisDB<T = any>(db?: string): T;
2096
- /**
2097
- redlock
2098
- */
2099
2096
  export declare function GetRedisLock(key: string, lockMaxActive?: number): Promise<boolean>;
2100
2097
  /** 对FN加锁、缓存执行 */
2101
2098
  export declare function excuteWithLock<T>(config: {
@@ -2114,7 +2111,12 @@ export declare function excuteWithLock<T>(config: {
2114
2111
  /** 单个锁多少【毫秒】后自动释放?默认:60*1000MS */
2115
2112
  lockMaxTime?: number;
2116
2113
  }, fn__: () => Promise<T>): Promise<T>;
2117
- /** 与缓存共用时,需要在缓存之前:有缓存则返回缓存,否则加锁执行并缓存,后续队列全部返回缓存,跳过执行 */
2114
+ /**
2115
+ * 方法加锁装饰器。
2116
+ * 与 `MethodCache` 组合时,**不要**手工叠装饰器——`MethodCache` 内部已经实现了
2117
+ * "先查缓存 → miss 才加锁 → 锁内二次检查 → 仍 miss 才执行" 的 single-flight 语义,
2118
+ * 直接给方法加 `@MethodCache` 即可。`@MethodLock` 单独使用时仅做并发互斥,不感知缓存。
2119
+ */
2118
2120
  export declare function MethodLock<T = any>(config: {
2119
2121
  /** 返回缓存key,参数=方法的参数[注意:必须和主方法的参数数量、完全一致,同时会追加一个当前用户对象]+当前用户对象,可以用来清空缓存。 */
2120
2122
  key: ((this: T, ...args: any[]) => string) | string;
@@ -2135,7 +2137,8 @@ export declare function MethodLock<T = any>(config: {
2135
2137
  export declare function clearMethodCache(key: string): Promise<void>;
2136
2138
  /**
2137
2139
  * 执行一个方法fn,
2138
- * 如果有缓存,则返回缓存,否则执行方法并缓存
2140
+ * 如果有缓存,则返回缓存,否则【加锁、二次检查】后执行方法并缓存,防止缓存击穿。
2141
+ * 可选 `cacheNullValue=true` 开启负缓存,防穿透;负缓存默认沿用 autoClearTime,可单独用 nullCacheTime 设短。
2139
2142
  */
2140
2143
  export declare function excuteWithCache<T>(config: {
2141
2144
  /** 返回缓存key,参数=方法的参数+当前用户对象,可以用来清空缓存。 */
@@ -2144,10 +2147,18 @@ export declare function excuteWithCache<T>(config: {
2144
2147
  clearKey?: string[];
2145
2148
  /** 自动清空缓存的时间,单位分钟 */
2146
2149
  autoClearTime?: number;
2150
+ /** 是否缓存 null / undefined(负缓存防穿透),默认 false。 */
2151
+ cacheNullValue?: boolean;
2152
+ /** 负缓存 TTL(分钟),默认沿用 autoClearTime。 */
2153
+ nullCacheTime?: number;
2147
2154
  /** 随着当前用户sesion的清空而一起清空 */
2148
2155
  clearWithSession?: boolean;
2149
2156
  }, fn: () => Promise<T>): Promise<T>;
2150
- /** 缓存注解 */
2157
+ /**
2158
+ * 缓存注解:先查缓存 → miss 才加锁 → 锁内再查一次 → 仍 miss 才执行原方法。
2159
+ * 已内置 single-flight,不需要再叠 `@MethodLock`。
2160
+ * 可选 `cacheNullValue=true` 开启负缓存,防穿透。
2161
+ */
2151
2162
  export declare function MethodCache<T = any>(config: {
2152
2163
  /** 返回缓存key,参数=方法的参数[注意:必须和主方法的参数数量、完全一致,同时会追加一个当前用户对象]+当前用户对象,可以用来清空缓存。 */
2153
2164
  key: ((this: T, ...args: any[]) => string) | string;
@@ -2155,9 +2166,13 @@ export declare function MethodCache<T = any>(config: {
2155
2166
  clearKey?: ((this: T, ...args: any[]) => string[]) | string[];
2156
2167
  /** 自动清空缓存的时间,单位分钟 */
2157
2168
  autoClearTime?: number;
2169
+ /** 是否缓存 null / undefined(负缓存防穿透),默认 false。 */
2170
+ cacheNullValue?: boolean;
2171
+ /** 负缓存 TTL(分钟),默认沿用 autoClearTime。 */
2172
+ nullCacheTime?: number;
2158
2173
  /** 随着当前用户sesion的清空而一起清空 */
2159
2174
  clearWithSession?: boolean;
2160
- }): (target: T, _propertyKey: string, descriptor: PropertyDescriptor) => void;
2175
+ }): (_target: T, _propertyKey: string, descriptor: PropertyDescriptor) => void;
2161
2176
  export declare const LOG_LEVELS: ["verbose", "debug", "info", "log", "warn", "error", "fatal"];
2162
2177
  export type LogLevel = (typeof LOG_LEVELS)[number];
2163
2178
  export interface LoggerService {