Skip to content

@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种类签名说明
InMemoryWorkingMemoryStorenew InMemoryWorkingMemoryStore(now?: () => Date): InMemoryWorkingMemoryStoreIn Memory Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
RedisWorkingMemoryStorenew RedisWorkingMemoryStore(options: RedisWorkingMemoryStoreOptions): RedisWorkingMemoryStoreRedis Working Memory Store 类,共公开 7 个构造函数或成员;精确签名见本条目的声明与成员表。
RedisLikeWorkingMemoryClient接口interface RedisLikeWorkingMemoryClientRedis Like Working Memory Client 接口,共包含 5 个公开字段或方法。
RedisWorkingMemoryStoreOptions接口interface RedisWorkingMemoryStoreOptionsRedis Working Memory Store Options 接口,共包含 7 个公开字段或方法。
WorkingMemoryEntry接口interface WorkingMemoryEntryWorking Memory Entry 接口,共包含 8 个公开字段或方法。
WorkingMemoryStore接口interface WorkingMemoryStoreWorking 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>>公开方法;参数与返回类型以签名列为准。