@codesoul-co/hypha-memory / working-store
模块用法
用于持久化并读取该边界的数据。Working store 模块公开 2 类、4 接口。
从包入口导入
ts
import {
InMemoryWorkingMemoryStore,
RedisWorkingMemoryStore,
} from '@codesoul-co/hypha-memory';
import type {
RedisLikeWorkingMemoryClient,
RedisWorkingMemoryStoreOptions,
WorkingMemoryEntry,
WorkingMemoryStore,
} from '@codesoul-co/hypha-memory';使用要点
- 4 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用
import type,运行时不应依赖它们。 - 2 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
公共导出
| Symbol | 种类 | 签名 | 说明 |
|---|---|---|---|
InMemoryWorkingMemoryStore | 类 | new InMemoryWorkingMemoryStore(now?: () => Date): InMemoryWorkingMemoryStore | In Memory Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。 |
RedisWorkingMemoryStore | 类 | new RedisWorkingMemoryStore(options: RedisWorkingMemoryStoreOptions): RedisWorkingMemoryStore | Redis Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。 |
RedisLikeWorkingMemoryClient | 接口 | interface RedisLikeWorkingMemoryClient | Redis Like Working Memory Client 接口,共包含 5 个公开字段或方法。 |
RedisWorkingMemoryStoreOptions | 接口 | interface RedisWorkingMemoryStoreOptions | Redis Working Memory Store Options 接口,共包含 7 个公开字段或方法。 |
WorkingMemoryEntry | 接口 | interface WorkingMemoryEntry | Working Memory Entry 接口,共包含 8 个公开字段或方法。 |
WorkingMemoryStore | 接口 | interface WorkingMemoryStore | Working Memory Store 接口,共包含 6 个公开字段或方法。 |
InMemoryWorkingMemoryStore
In Memory Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InMemoryWorkingMemoryStore } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export declare class InMemoryWorkingMemoryStore implements WorkingMemoryStore {
constructor(now?: () => Date);
get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null>;
set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, 'scopeHash'>, ttlSeconds?: number): Promise<WorkingMemoryEntry<TValue>>;
delete(scope: ManagedMemoryScope, id: string): Promise<void>;
list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>>;
clearScope(scope: ManagedMemoryScope): Promise<void>;
health(): Promise<ProviderHealth>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
clearScope | 方法 | clearScope(scope: ManagedMemoryScope): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
constructor | 构造函数 | (now?: () => Date): InMemoryWorkingMemoryStore | 创建该类的实例。 |
delete | 方法 | delete(scope: ManagedMemoryScope, id: string): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
get | 方法 | get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null> | 公开方法;参数与返回类型以签名列为准。 |
health | 方法 | health(): Promise<ProviderHealth> | 公开方法;参数与返回类型以签名列为准。 |
list | 方法 | list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, "scopeHash">, ttlSeconds?: number): Promise<WorkingMemoryEntry<TValue>> | 公开方法;参数与返回类型以签名列为准。 |
RedisWorkingMemoryStore
Redis Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { RedisWorkingMemoryStore } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export declare class RedisWorkingMemoryStore implements WorkingMemoryStore {
constructor(options: RedisWorkingMemoryStoreOptions);
get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null>;
set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, 'scopeHash'>, ttlSeconds?: number | undefined): Promise<WorkingMemoryEntry<TValue>>;
delete(scope: ManagedMemoryScope, id: string): Promise<void>;
list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>>;
clearScope(scope: ManagedMemoryScope): Promise<void>;
health(): Promise<ProviderHealth>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
clearScope | 方法 | clearScope(scope: ManagedMemoryScope): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
constructor | 构造函数 | (options: RedisWorkingMemoryStoreOptions): RedisWorkingMemoryStore | 创建该类的实例。 |
delete | 方法 | delete(scope: ManagedMemoryScope, id: string): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
get | 方法 | get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null> | 公开方法;参数与返回类型以签名列为准。 |
health | 方法 | health(): Promise<ProviderHealth> | 公开方法;参数与返回类型以签名列为准。 |
list | 方法 | list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, "scopeHash">, ttlSeconds?: number | undefined): Promise<WorkingMemoryEntry<TValue>> | 公开方法;参数与返回类型以签名列为准。 |
RedisLikeWorkingMemoryClient
Redis Like Working Memory Client 接口,共包含 5 个公开字段或方法。
- 种类: 接口
- 导入:
import type { RedisLikeWorkingMemoryClient } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export interface RedisLikeWorkingMemoryClient {
get(key: string): Promise<string | null>;
set(key: string, value: string, mode?: 'EX', durationSeconds?: number): Promise<unknown>;
del(...keys: string[]): Promise<number>;
scan(cursor: string, matchToken: 'MATCH', pattern: string, countToken: 'COUNT', count: number): Promise<[string, string[]]>;
ping?(): Promise<string>;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
del | 方法 | del(...keys: string[]): Promise<number> | 公开方法;参数与返回类型以签名列为准。 |
get | 方法 | get(key: string): Promise<string | null> | 公开方法;参数与返回类型以签名列为准。 |
ping | 方法 | ping?(): Promise<string> | 公开方法;参数与返回类型以签名列为准。 |
scan | 方法 | scan(cursor: string, matchToken: "MATCH", pattern: string, countToken: "COUNT", count: number): Promise<[string, string[]]> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set(key: string, value: string, mode?: "EX", durationSeconds?: number): Promise<unknown> | 公开方法;参数与返回类型以签名列为准。 |
RedisWorkingMemoryStoreOptions
Redis Working Memory Store Options 接口,共包含 7 个公开字段或方法。
- 种类: 接口
- 导入:
import type { RedisWorkingMemoryStoreOptions } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export interface RedisWorkingMemoryStoreOptions {
client: RedisLikeWorkingMemoryClient;
namespace?: string;
defaultTtlSeconds?: number;
scanCount?: number;
scanBudget?: Partial<Omit<RedisScanBudget, 'count'>>;
now?: () => Date;
nowMs?: () => number;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
client | 属性 | client: RedisLikeWorkingMemoryClient | 公开属性;类型、只读和可选状态以签名列为准。 |
defaultTtlSeconds | 属性 | defaultTtlSeconds?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
namespace | 属性 | namespace?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
now | 方法 | now?(): Date | 公开方法;参数与返回类型以签名列为准。 |
nowMs | 方法 | nowMs?(): number | 公开方法;参数与返回类型以签名列为准。 |
scanBudget | 属性 | scanBudget?: Partial<Omit<RedisScanBudget, "count">> | 公开属性;类型、只读和可选状态以签名列为准。 |
scanCount | 属性 | scanCount?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
WorkingMemoryEntry
Working Memory Entry 接口,共包含 8 个公开字段或方法。
- 种类: 接口
- 导入:
import type { WorkingMemoryEntry } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export interface WorkingMemoryEntry<TValue = unknown> {
id: string;
scope: ManagedMemoryScope;
scopeHash: string;
value: TValue;
createdAt: string;
updatedAt: string;
expiresAt?: string;
metadata?: Record<string, unknown>;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
createdAt | 属性 | createdAt: string | 公开属性;类型、只读和可选状态以签名列为准。 |
expiresAt | 属性 | expiresAt?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
id | 属性 | id: string | 公开属性;类型、只读和可选状态以签名列为准。 |
metadata | 属性 | metadata?: Record<string, unknown> | 公开属性;类型、只读和可选状态以签名列为准。 |
scope | 属性 | scope: ManagedMemoryScope | 公开属性;类型、只读和可选状态以签名列为准。 |
scopeHash | 属性 | scopeHash: string | 公开属性;类型、只读和可选状态以签名列为准。 |
updatedAt | 属性 | updatedAt: string | 公开属性;类型、只读和可选状态以签名列为准。 |
value | 属性 | value: TValue | 公开属性;类型、只读和可选状态以签名列为准。 |
WorkingMemoryStore
Working Memory Store 接口,共包含 6 个公开字段或方法。
- 种类: 接口
- 导入:
import type { WorkingMemoryStore } from '@codesoul-co/hypha-memory'; - 源码模块:
working-store
声明
text
export interface WorkingMemoryStore {
get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null>;
set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, 'scopeHash'>, ttlSeconds?: number): Promise<WorkingMemoryEntry<TValue>>;
delete(scope: ManagedMemoryScope, id: string): Promise<void>;
list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>>;
clearScope(scope: ManagedMemoryScope): Promise<void>;
health(): Promise<ProviderHealth>;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
clearScope | 方法 | clearScope(scope: ManagedMemoryScope): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
delete | 方法 | delete(scope: ManagedMemoryScope, id: string): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
get | 方法 | get<TValue = unknown>(scope: ManagedMemoryScope, id: string): Promise<WorkingMemoryEntry<TValue> | null> | 公开方法;参数与返回类型以签名列为准。 |
health | 方法 | health(): Promise<ProviderHealth> | 公开方法;参数与返回类型以签名列为准。 |
list | 方法 | list<TValue = unknown>(scope: ManagedMemoryScope): Promise<Array<WorkingMemoryEntry<TValue>>> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set<TValue = unknown>(entry: Omit<WorkingMemoryEntry<TValue>, "scopeHash">, ttlSeconds?: number): Promise<WorkingMemoryEntry<TValue>> | 公开方法;参数与返回类型以签名列为准。 |
