weifuwu 0.61.2 → 0.63.0
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 +168 -11
- package/dist/client/diff.d.ts +13 -1
- package/dist/client/index.js +3 -3
- package/dist/client/popup.d.ts +22 -0
- package/dist/client/types.d.ts +63 -0
- package/dist/client/ui.d.ts +6 -0
- package/dist/components/Accordion/Accordion.d.ts +9 -0
- package/dist/components/Affix/Affix.d.ts +16 -0
- package/dist/components/AspectRatio/AspectRatio.d.ts +10 -0
- package/dist/components/AvatarGroup/AvatarGroup.d.ts +21 -0
- package/dist/components/BackTop/BackTop.d.ts +16 -0
- package/dist/components/Calendar/Calendar.d.ts +21 -0
- package/dist/components/Carousel/Carousel.d.ts +17 -0
- package/dist/components/Cascader/Cascader.d.ts +21 -0
- package/dist/components/CheckboxGroup/CheckboxGroup.d.ts +23 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +14 -0
- package/dist/components/Collapse/Collapse.d.ts +28 -0
- package/dist/components/ColorPicker/ColorPicker.d.ts +16 -0
- package/dist/components/Command/Command.d.ts +22 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +17 -0
- package/dist/components/CopyButton/CopyButton.d.ts +18 -0
- package/dist/components/Descriptions/Descriptions.d.ts +21 -0
- package/dist/components/Highlight/Highlight.d.ts +13 -0
- package/dist/components/HoverCard/HoverCard.d.ts +16 -0
- package/dist/components/Icon/Icon.d.ts +1 -1
- package/dist/components/Img/Img.d.ts +4 -0
- package/dist/components/InView/InView.d.ts +1 -1
- package/dist/components/InfiniteScroll/InfiniteScroll.d.ts +15 -0
- package/dist/components/InputNumber/InputNumber.d.ts +25 -0
- package/dist/components/Label/Label.d.ts +11 -0
- package/dist/components/List/List.d.ts +18 -0
- package/dist/components/Markdown/Markdown.d.ts +14 -0
- package/dist/components/Markdown/parser.d.ts +32 -0
- package/dist/components/Mentions/Mentions.d.ts +19 -0
- package/dist/components/Menu/Menu.d.ts +25 -0
- package/dist/components/Menubar/Menubar.d.ts +22 -0
- package/dist/components/MessageBubble/MessageBubble.d.ts +20 -0
- package/dist/components/Notification/Notification.d.ts +70 -0
- package/dist/components/PasswordInput/PasswordInput.d.ts +21 -0
- package/dist/components/PinInput/PinInput.d.ts +18 -0
- package/dist/components/QRCode/QRCode.d.ts +20 -0
- package/dist/components/QRCode/qr.d.ts +15 -0
- package/dist/components/Rate/Rate.d.ts +16 -0
- package/dist/components/Resizable/Resizable.d.ts +18 -0
- package/dist/components/Result/Result.d.ts +17 -0
- package/dist/components/Select/Select.d.ts +4 -2
- package/dist/components/Table/Table.d.ts +10 -0
- package/dist/components/TagsInput/TagsInput.d.ts +21 -0
- package/dist/components/Timeline/Timeline.d.ts +25 -0
- package/dist/components/ToggleGroup/ToggleGroup.d.ts +33 -0
- package/dist/components/Transfer/Transfer.d.ts +18 -0
- package/dist/components/Tree/Tree.d.ts +27 -0
- package/dist/components/Typography/Typography.d.ts +39 -0
- package/dist/components/VirtualList/VirtualList.d.ts +21 -0
- package/dist/components/Watermark/Watermark.d.ts +19 -0
- package/dist/components/index.d.ts +85 -0
- package/dist/components/index.js +14 -1
- package/dist/components/style.css +4824 -2211
- package/dist/db/postgres/connection.d.ts +24 -3
- package/dist/db/postgres/pool.d.ts +30 -8
- package/dist/db/redis/client.d.ts +43 -0
- package/dist/db/redis/connection.d.ts +12 -0
- package/dist/db/redis/pipeline.d.ts +26 -0
- package/dist/db/redis/pool.d.ts +27 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1055 -94
- package/dist/layout/weifuwu-layout.css +11 -1
- package/dist/postgres/types.d.ts +2 -1
- package/dist/redis/types.d.ts +6 -0
- package/dist/scheduler/cron.d.ts +26 -0
- package/dist/scheduler/index.d.ts +69 -0
- package/package.json +2 -4
|
@@ -24,6 +24,10 @@ export interface PgConnectionOptions {
|
|
|
24
24
|
export interface Row {
|
|
25
25
|
[col: string]: unknown;
|
|
26
26
|
}
|
|
27
|
+
/** 查询结果:行数组 + 影响行数(INSERT/UPDATE/DELETE/MERGE 的 CommandComplete tag) */
|
|
28
|
+
export interface QueryResult<T = Row> extends Array<T> {
|
|
29
|
+
affectedRows?: number;
|
|
30
|
+
}
|
|
27
31
|
export declare class PgConnection {
|
|
28
32
|
private opts;
|
|
29
33
|
private timeoutSet;
|
|
@@ -35,6 +39,8 @@ export declare class PgConnection {
|
|
|
35
39
|
private waiters;
|
|
36
40
|
constructor(options?: PgConnectionOptions);
|
|
37
41
|
get connected(): boolean;
|
|
42
|
+
/** 池空闲回收用:最近一次查询完成时间戳(pool release 时更新) */
|
|
43
|
+
lastUsed: number;
|
|
38
44
|
connect(): Promise<void>;
|
|
39
45
|
private onReady;
|
|
40
46
|
private onAuthFail;
|
|
@@ -43,7 +49,13 @@ export declare class PgConnection {
|
|
|
43
49
|
private prepared;
|
|
44
50
|
private static readonly PREPARED_MAX;
|
|
45
51
|
private stmtSeq;
|
|
52
|
+
/** LRU 淘汰的 statement 名——连接空闲时批量 DEALLOCATE(服务端同步释放,防 plan 缓存膨胀) */
|
|
53
|
+
private deallocQueue;
|
|
54
|
+
/** DEALLOCATE 批量的响应 Z——仅消费(不 resolve 查询) */
|
|
55
|
+
private awaitingDeallocZ;
|
|
46
56
|
private currentQuery;
|
|
57
|
+
/** DDL 失效重试:缓存语句被 DROP 后服务器拒绝执行,Sync 复位后以新语句名重 Parse */
|
|
58
|
+
private pendingRetry;
|
|
47
59
|
private onData;
|
|
48
60
|
private handle;
|
|
49
61
|
/** SCRAM client-final 消息 */
|
|
@@ -51,14 +63,23 @@ export declare class PgConnection {
|
|
|
51
63
|
private scramServerSignature;
|
|
52
64
|
/** LRU 读取:命中移到尾部(最近使用),超限删最旧 */
|
|
53
65
|
private getPrepared;
|
|
54
|
-
/** LRU
|
|
66
|
+
/** LRU 写入:刷新位置;超上限淘汰最旧(长运行服务防无限累积)——淘汰的 statement 推入 deallocQueue,连接空闲时服务端同步释放 */
|
|
55
67
|
private setPrepared;
|
|
68
|
+
/** 连接空闲时批量 DEALLOCATE:LRU 淘汰的 statement 不残留服务端(plan 缓存膨胀防线)。
|
|
69
|
+
* 同步 write 先于后续查询(调用点在 Z handler 的同步段内,resolve 的微任务后至)。
|
|
70
|
+
* 其响应 C+Z 在无 currentQuery 时到达——awaitingDeallocZ 消费首个 Z,后续查询 Z 正常。 */
|
|
71
|
+
private flushDealloc;
|
|
56
72
|
/** 事务:BEGIN → fn(tx) → COMMIT;fn 抛错 → ROLLBACK(回滚失败吞掉,保留原始错误) */
|
|
57
73
|
transaction<T>(fn: (tx: {
|
|
58
|
-
query: (sql: string, params?: (string | number | boolean | object | null)[]) => Promise<Row
|
|
74
|
+
query: (sql: string, params?: (string | number | boolean | object | null)[]) => Promise<QueryResult<Row>>;
|
|
59
75
|
}) => Promise<T>): Promise<T>;
|
|
60
76
|
/** 查询:无参数走简单协议(Q),有参数走扩展查询(Parse/Bind/Execute/Sync) */
|
|
61
|
-
query(sql: string, params?: (string | number | boolean | object | null)[]): Promise<Row
|
|
77
|
+
query(sql: string, params?: (string | number | boolean | object | null)[]): Promise<QueryResult<Row>>;
|
|
78
|
+
/**
|
|
79
|
+
* 扩展查询首次准备:Parse + Describe + Flush(无 Sync——错误时由调用方发 Sync 复位)。
|
|
80
|
+
* retry 路径复用:新语句名强制服务器按当前 schema 重新解析(DDL 失效恢复)。
|
|
81
|
+
*/
|
|
82
|
+
private issueExtendedQuery;
|
|
62
83
|
private send;
|
|
63
84
|
private notifyIdle;
|
|
64
85
|
/** 等待连接空闲(事务/多语句流程用) */
|
|
@@ -8,13 +8,15 @@
|
|
|
8
8
|
* 解决 PgConnection 单连接串行(一个 currentQuery)的限制:
|
|
9
9
|
* 并发查询路由到不同连接,全忙时排队等待而非 reject。
|
|
10
10
|
*/
|
|
11
|
-
import { type PgConnectionOptions, type Row } from './connection.ts';
|
|
11
|
+
import { type PgConnectionOptions, type Row, type QueryResult } from './connection.ts';
|
|
12
12
|
import { type Schema } from './schema.ts';
|
|
13
13
|
export interface PgPoolOptions extends PgConnectionOptions {
|
|
14
14
|
/** 池大小(连接数)。默认 5。 */
|
|
15
15
|
poolSize?: number;
|
|
16
16
|
/** acquire 超时 ms(池全忙时等待上限,防饿死)。默认 30_000。0 = 无限。 */
|
|
17
17
|
acquireTimeoutMs?: number;
|
|
18
|
+
/** 空闲连接回收 ms(超时未使用的连接关闭,容量收缩;下次需要时自动重建)。默认 0 = 禁用。 */
|
|
19
|
+
idleTimeoutMs?: number;
|
|
18
20
|
/** 查询观测钩子(慢查询日志/审计) */
|
|
19
21
|
onQuery?: (sql: string, durationMs: number, rowCount: number) => void;
|
|
20
22
|
}
|
|
@@ -27,39 +29,59 @@ export declare class PgPool {
|
|
|
27
29
|
private opts;
|
|
28
30
|
private initPromise;
|
|
29
31
|
private schemas;
|
|
32
|
+
private idleTimer;
|
|
30
33
|
/** 懒连接:构造不连接,ensure() 首次初始化(中间件注入场景) */
|
|
31
34
|
constructor(options?: PgPoolOptions);
|
|
32
35
|
static create(options?: PgPoolOptions): Promise<PgPool>;
|
|
33
36
|
private readyPromise;
|
|
34
37
|
private ensure;
|
|
35
38
|
private init;
|
|
36
|
-
/**
|
|
39
|
+
/** 空闲回收定时器(idleTimeoutMs > 0 时启动;unref 不阻塞进程退出) */
|
|
40
|
+
private startIdleReaper;
|
|
41
|
+
/** 扫描空闲连接:超时未使用 → close + 从池移除(容量收缩;acquire 时自动重建) */
|
|
42
|
+
private reapIdle;
|
|
43
|
+
/** 当前打开的连接数(含借出;测试/观测用) */
|
|
44
|
+
get open(): number;
|
|
45
|
+
/** 获取一个空闲连接(全忙则排队等待;池被空闲回收收缩时自动新建恢复容量) */
|
|
37
46
|
private acquire;
|
|
38
47
|
private release;
|
|
39
48
|
/** 连接可用事件统一入口:优先唤醒等待者,否则回空闲池(release 与 replenish 共用) */
|
|
40
49
|
private dispatchAvailable;
|
|
41
50
|
/** 坏连接剔除后异步重建(池容量保持)——就绪后走统一分发(唤醒 waiter) */
|
|
42
51
|
private replenish;
|
|
43
|
-
query<T = Row>(sql: string, params?: QueryParams): Promise<T
|
|
52
|
+
query<T = Row>(sql: string, params?: QueryParams): Promise<QueryResult<T>>;
|
|
44
53
|
/** 注册表结构(元数据闭环:校验/类型推断的起点) */
|
|
45
54
|
register(table: string, schema: Schema): void;
|
|
55
|
+
/**
|
|
56
|
+
* 批量插入:多行 VALUES 单次往返(种子/批量写场景 N 往返 → 1)。
|
|
57
|
+
* 诚实裁剪:所有行必须键集合一致(否则抛 ValidationError);batchSize 分批(默认 500)。
|
|
58
|
+
*/
|
|
59
|
+
insertMany<T = Row>(table: string, rows: Record<string, unknown>[], opts?: {
|
|
60
|
+
batchSize?: number;
|
|
61
|
+
}): Promise<QueryResult<T>>;
|
|
62
|
+
/** 参数化 UPDATE:SET + WHERE 全部参数化(防注入);返回 affectedRows;returning 可回读修改行 */
|
|
63
|
+
update<T = Row>(table: string, set: Record<string, unknown>, where: Record<string, unknown>, opts?: {
|
|
64
|
+
returning?: string[];
|
|
65
|
+
}): Promise<QueryResult<T>>;
|
|
66
|
+
/** 参数化 DELETE:WHERE 参数化;返回 affectedRows。WHERE 必填(防全表误删) */
|
|
67
|
+
delete<T = Row>(table: string, where: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
46
68
|
/** 写前校验 + 参数化插入(schema 驱动,脏数据源头拦截) */
|
|
47
|
-
insert<T = Row>(table: string, row: Record<string, unknown>): Promise<T
|
|
69
|
+
insert<T = Row>(table: string, row: Record<string, unknown>): Promise<QueryResult<T>>;
|
|
48
70
|
/**
|
|
49
71
|
* tagged template: sql\`SELECT * FROM t WHERE id = \${id}\`
|
|
50
72
|
* 插值 = 参数(postgres.js 语义,防注入);表名必须硬编码(插值会被当参数)。
|
|
51
73
|
* 对象插值自动 JSON.stringify → jsonb。
|
|
52
74
|
*/
|
|
53
|
-
tag(strings: TemplateStringsArray, ...values: unknown[]): Promise<Row
|
|
75
|
+
tag(strings: TemplateStringsArray, ...values: unknown[]): Promise<QueryResult<Row>>;
|
|
54
76
|
/** postgres.js 兼容事务 API: begin(fn)——fn 收到 tagged template 事务 sql */
|
|
55
77
|
begin<T>(fn: (txSql: TaggedSql) => Promise<T>): Promise<T>;
|
|
56
78
|
/** 片段:可嵌套的 SQL 片段(postgres.js fragment 语义,条件过滤模式) */
|
|
57
79
|
frag(strings: TemplateStringsArray, ...values: unknown[]): SqlFragment;
|
|
58
80
|
/** 原生 SQL(DDL / 动态表名场景);$1 占位符 + 参数数组 */
|
|
59
|
-
unsafe(sql: string, params?: QueryParams): Promise<Row
|
|
81
|
+
unsafe(sql: string, params?: QueryParams): Promise<QueryResult<Row>>;
|
|
60
82
|
/** 事务:固定在单个连接上执行整个 BEGIN→fn→COMMIT/ROLLBACK */
|
|
61
83
|
transaction<T>(fn: (tx: {
|
|
62
|
-
query: (sql: string, params?: QueryParams) => Promise<Row
|
|
84
|
+
query: (sql: string, params?: QueryParams) => Promise<QueryResult<Row>>;
|
|
63
85
|
}) => Promise<T>): Promise<T>;
|
|
64
86
|
close(): Promise<void>;
|
|
65
87
|
get size(): number;
|
|
@@ -72,5 +94,5 @@ export interface SqlFragment {
|
|
|
72
94
|
};
|
|
73
95
|
}
|
|
74
96
|
/** tagged template 事务 sql(begin 回调参数) */
|
|
75
|
-
export type TaggedSql = (strings: TemplateStringsArray, ...values: unknown[]) => Promise<Row
|
|
97
|
+
export type TaggedSql = (strings: TemplateStringsArray, ...values: unknown[]) => Promise<QueryResult<Row>>;
|
|
76
98
|
export {};
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type RedisConnectionOptions } from './connection.ts';
|
|
10
10
|
import type { RespValue } from './resp.ts';
|
|
11
|
+
import { RedisPipeline } from './pipeline.ts';
|
|
11
12
|
export interface RedisClientOptions extends RedisConnectionOptions {
|
|
12
13
|
}
|
|
13
14
|
export declare class RedisClient {
|
|
@@ -17,6 +18,8 @@ export declare class RedisClient {
|
|
|
17
18
|
static connect(options?: RedisClientOptions): Promise<RedisClient>;
|
|
18
19
|
/** 底层命令透传(RESP 值);Buffer 参数字节原样发送 */
|
|
19
20
|
command(name: string, ...args: (string | number | Buffer)[]): Promise<RespValue>;
|
|
21
|
+
/** 连接是否就绪(池坏连接剔除用) */
|
|
22
|
+
get connected(): boolean;
|
|
20
23
|
get(key: string): Promise<string | null>;
|
|
21
24
|
/**
|
|
22
25
|
* 二进制安全读取:返回原始字节(Uint8Array),不经过字符串解码。
|
|
@@ -35,6 +38,46 @@ export declare class RedisClient {
|
|
|
35
38
|
expire(key: string, seconds: number): Promise<number>;
|
|
36
39
|
/** TTL 剩余秒数;-1=无 TTL -2=key 不存在 */
|
|
37
40
|
ttl(key: string): Promise<number>;
|
|
41
|
+
/** 批量读:返回与 key 一一对应的值(缺失为 null) */
|
|
42
|
+
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
43
|
+
/** 批量写:mset(k1, v1, k2, v2, ...)(偶数参数) */
|
|
44
|
+
mset(...kv: (string | number)[]): Promise<'OK'>;
|
|
45
|
+
/** 存在性:返回存在的 key 数 */
|
|
46
|
+
exists(...keys: string[]): Promise<number>;
|
|
47
|
+
/** 原子设置(仅 key 不存在时):1=设置成功 0=已存在(分布式锁基础) */
|
|
48
|
+
setnx(key: string, value: string | number): Promise<number>;
|
|
49
|
+
/** 原子加增量,返回新值 */
|
|
50
|
+
incrby(key: string, delta: number): Promise<number>;
|
|
51
|
+
/** 设置字段,返回新增字段数 */
|
|
52
|
+
hset(key: string, field: string, value: string | number): Promise<number>;
|
|
53
|
+
/** 读字段(缺失 null) */
|
|
54
|
+
hget(key: string, field: string): Promise<string | null>;
|
|
55
|
+
/** 读整个 hash → Record(key 不存在 → {}) */
|
|
56
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
57
|
+
/** 删除字段,返回删除数 */
|
|
58
|
+
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
59
|
+
/** 头插,返回长度 */
|
|
60
|
+
lpush(key: string, ...values: (string | number)[]): Promise<number>;
|
|
61
|
+
/** 尾插,返回长度 */
|
|
62
|
+
rpush(key: string, ...values: (string | number)[]): Promise<number>;
|
|
63
|
+
/** 头弹(缺失 null) */
|
|
64
|
+
lpop(key: string): Promise<string | null>;
|
|
65
|
+
/** 尾弹(缺失 null) */
|
|
66
|
+
rpop(key: string): Promise<string | null>;
|
|
67
|
+
/** 范围读(start/stop 支持负数,如 0 -1 全量) */
|
|
68
|
+
lrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
69
|
+
/** 加成员,返回新增数(重复不加) */
|
|
70
|
+
sadd(key: string, ...members: (string | number)[]): Promise<number>;
|
|
71
|
+
/** 删成员,返回删除数 */
|
|
72
|
+
srem(key: string, ...members: (string | number)[]): Promise<number>;
|
|
73
|
+
/** 全部成员(无序) */
|
|
74
|
+
smembers(key: string): Promise<string[]>;
|
|
75
|
+
/** 加成员(score 排序),返回新增数 */
|
|
76
|
+
zadd(key: string, score: number, member: string | number): Promise<number>;
|
|
77
|
+
/** 范围读(按 score 升序;start/stop 为排名,支持负数) */
|
|
78
|
+
zrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
79
|
+
/** 创建管道(批量命令一次往返;结果按序) */
|
|
80
|
+
pipeline(): RedisPipeline;
|
|
38
81
|
/** 读取并 JSON.parse;key 不存在返回 null */
|
|
39
82
|
jsonGet(key: string): Promise<unknown | null>;
|
|
40
83
|
/** JSON.stringify 后写入,可选 TTL */
|
|
@@ -20,6 +20,12 @@ export interface RedisConnectionOptions {
|
|
|
20
20
|
enableOfflineQueue?: boolean;
|
|
21
21
|
/** 离线队列上限。默认 5000。超限命令立即 reject(防断线期间无限累积)。 */
|
|
22
22
|
maxOfflineQueue?: number;
|
|
23
|
+
/** 命令超时 ms(服务器慢/挂起时 reject,防 promise 永久挂起)。默认 0 = 禁用。 */
|
|
24
|
+
commandTimeoutMs?: number;
|
|
25
|
+
/** socket 响应超时 ms(僵尸自愈:有 pending 命令且超时无数据 → 主动断开走重连)。默认 0 = 禁用。 */
|
|
26
|
+
socketTimeoutMs?: number;
|
|
27
|
+
/** 命令观测钩子(慢命令日志/审计;traceId 由中间件 ALS 注入第 4 参) */
|
|
28
|
+
onCommand?: (command: string, args: (string | number)[], durationMs: number, traceId?: string) => void;
|
|
23
29
|
}
|
|
24
30
|
export declare class RedisConnection {
|
|
25
31
|
readonly ready = false;
|
|
@@ -35,6 +41,7 @@ export declare class RedisConnection {
|
|
|
35
41
|
private status;
|
|
36
42
|
private retries;
|
|
37
43
|
private reconnectTimer;
|
|
44
|
+
private socketTimeoutTimer;
|
|
38
45
|
private connectPromise;
|
|
39
46
|
private closed;
|
|
40
47
|
private connectedOnce;
|
|
@@ -54,6 +61,11 @@ export declare class RedisConnection {
|
|
|
54
61
|
asBuffer?: boolean;
|
|
55
62
|
})[]): Promise<RespValue>;
|
|
56
63
|
private sendNow;
|
|
64
|
+
/** 命令超时(commandTimeoutMs > 0):超时标记 timedOut + 处理(阻塞命令 resolve(null),其余 reject) */
|
|
65
|
+
private armTimeout;
|
|
66
|
+
/** socket 响应超时(socketTimeoutMs > 0):期望数据但超时未达 → 僵尸连接 → 主动断开走标准重连 */
|
|
67
|
+
private armSocketTimeout;
|
|
68
|
+
private clearSocketTimeout;
|
|
57
69
|
private flushOffline;
|
|
58
70
|
/** 批量执行:一次 write 发送所有命令字节,响应按序路由(管道) */
|
|
59
71
|
batch(payload: Uint8Array, count: number): Promise<RespValue[]>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* weifuwu/db/redis — Redis 管道
|
|
3
|
+
*
|
|
4
|
+
* 批量命令一次网络往返发送(单次 write + 响应 pushAll 批量解析)。
|
|
5
|
+
* 结果按命令顺序返回;错误命令对应位置返回 Error。
|
|
6
|
+
*/
|
|
7
|
+
import type { RedisConnection } from './connection.ts';
|
|
8
|
+
import type { RespValue } from './resp.ts';
|
|
9
|
+
export declare class RedisPipeline {
|
|
10
|
+
private cmds;
|
|
11
|
+
private conn;
|
|
12
|
+
constructor(conn: RedisConnection);
|
|
13
|
+
set(key: string, value: string | number, ttl?: number): this;
|
|
14
|
+
get(key: string): this;
|
|
15
|
+
del(...keys: string[]): this;
|
|
16
|
+
incr(key: string): this;
|
|
17
|
+
expire(key: string, seconds: number): this;
|
|
18
|
+
ttl(key: string): this;
|
|
19
|
+
/** 任意命令透传 */
|
|
20
|
+
raw(name: string, ...args: (string | number)[]): this;
|
|
21
|
+
/**
|
|
22
|
+
* 一次往返执行所有命令。结果按命令顺序;错误命令对应位置为 Error 实例,
|
|
23
|
+
* 其余命令不受影响(Redis 管道语义)。
|
|
24
|
+
*/
|
|
25
|
+
exec(): Promise<RespValue[]>;
|
|
26
|
+
}
|
package/dist/db/redis/pool.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { type RedisClientOptions } from './client.ts';
|
|
8
8
|
import { RedisSubscriber } from './subscriber.ts';
|
|
9
|
+
import { RedisPipeline } from './pipeline.ts';
|
|
9
10
|
import type { RespValue } from './resp.ts';
|
|
10
11
|
export interface RedisPoolOptions extends RedisClientOptions {
|
|
11
12
|
/** 池大小(连接数)。默认 5。 */
|
|
@@ -16,6 +17,7 @@ export interface RedisPoolOptions extends RedisClientOptions {
|
|
|
16
17
|
export declare class RedisPool {
|
|
17
18
|
private clients;
|
|
18
19
|
private rr;
|
|
20
|
+
private replenishWaiters;
|
|
19
21
|
private closed;
|
|
20
22
|
private keyPrefix;
|
|
21
23
|
private opts;
|
|
@@ -30,8 +32,11 @@ export declare class RedisPool {
|
|
|
30
32
|
private init;
|
|
31
33
|
/** 应用 key 前缀(command 透传不加) */
|
|
32
34
|
private k;
|
|
33
|
-
/** round-robin
|
|
34
|
-
|
|
35
|
+
/** round-robin 选择健康连接;跳过不可用连接(断线/重连中/closed)——剔除并异步重建,防分发到死连接。
|
|
36
|
+
* 全部不可用时等待 replenish 补位(Redis 真宕机 1s 后明确报错,不无限挂起)。 */
|
|
37
|
+
private acquireHealthy;
|
|
38
|
+
/** 剔除后补位:异步重建连接,就绪后回池并唤醒等待者 */
|
|
39
|
+
private replenish;
|
|
35
40
|
command(name: string, ...args: (string | number)[]): Promise<RespValue>;
|
|
36
41
|
get(key: string): Promise<string | null>;
|
|
37
42
|
/** 二进制安全读取(原始字节,不解码) */
|
|
@@ -44,6 +49,26 @@ export declare class RedisPool {
|
|
|
44
49
|
jsonGet(key: string): Promise<unknown | null>;
|
|
45
50
|
jsonSet(key: string, value: unknown, ttl?: number): Promise<'OK'>;
|
|
46
51
|
cache<T>(key: string, fn: () => Promise<T | null>, ttl: number): Promise<T | null>;
|
|
52
|
+
mget(...keys: string[]): Promise<(string | null)[]>;
|
|
53
|
+
mset(...kv: (string | number)[]): Promise<'OK'>;
|
|
54
|
+
exists(...keys: string[]): Promise<number>;
|
|
55
|
+
setnx(key: string, value: string | number): Promise<number>;
|
|
56
|
+
incrby(key: string, delta: number): Promise<number>;
|
|
57
|
+
hset(key: string, field: string, value: string | number): Promise<number>;
|
|
58
|
+
hget(key: string, field: string): Promise<string | null>;
|
|
59
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
60
|
+
hdel(key: string, ...fields: string[]): Promise<number>;
|
|
61
|
+
lpush(key: string, ...values: (string | number)[]): Promise<number>;
|
|
62
|
+
rpush(key: string, ...values: (string | number)[]): Promise<number>;
|
|
63
|
+
lpop(key: string): Promise<string | null>;
|
|
64
|
+
rpop(key: string): Promise<string | null>;
|
|
65
|
+
lrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
66
|
+
sadd(key: string, ...members: (string | number)[]): Promise<number>;
|
|
67
|
+
srem(key: string, ...members: (string | number)[]): Promise<number>;
|
|
68
|
+
smembers(key: string): Promise<string[]>;
|
|
69
|
+
zadd(key: string, score: number, member: string | number): Promise<number>;
|
|
70
|
+
zrange(key: string, start: number, stop: number): Promise<string[]>;
|
|
71
|
+
pipeline(): Promise<RedisPipeline>;
|
|
47
72
|
/** PUBLISH 消息到频道,返回收到消息的订阅者数 */
|
|
48
73
|
publish(channel: string, message: string | number): Promise<number>;
|
|
49
74
|
/** 创建独立订阅者连接(Pub/Sub 场景) */
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export { messager } from './messager/index.ts';
|
|
|
22
22
|
export type { UserSystemOptions, UserInjected, AuthApi, RegisterInput } from './user/index.ts';
|
|
23
23
|
export type { MessagerOptions, MessagerInjected, MessagerClient, MessagerSystem, Message, Conversation } from './messager/index.ts';
|
|
24
24
|
export { queue } from './queue/index.ts';
|
|
25
|
+
export { scheduler } from './scheduler/index.ts';
|
|
25
26
|
export type { QueueOptions, QueueClient, QueueInjected, QueueWorker, WorkerOptions, AddOptions, Job } from './queue/index.ts';
|
|
26
27
|
export { ai } from './ai/index.ts';
|
|
27
28
|
export type { AiOptions, AiInjected, AiClient, AiClientModule, ChatResponse, AgentConfig, AgentTool, AgentRunner, ToolContext, AgentRunResult, AgentStep, WfEmitter, } from './ai/index.ts';
|