@botmesh/core - v2.0.0-alpha.2
    Preparing search index...

    Interface IStore

    interface IStore {
        saveMessage(msg: StoredMessage): Promise<void>;
        getMessage(ref: MessageRef): Promise<StoredMessage | undefined>;
        getMessagesByChat(chatId: string, limit?: number): Promise<StoredMessage[]>;
        deleteMessage(ref: MessageRef): Promise<void>;
        upsertChat(chat: StoredChat): Promise<void>;
        getChat(chatId: string): Promise<StoredChat | undefined>;
        listChats(): Promise<StoredChat[]>;
        deleteChat(chatId: string): Promise<void>;
        upsertContact(contact: StoredContact): Promise<void>;
        getContact(userId: string): Promise<StoredContact | undefined>;
        listContacts(): Promise<StoredContact[]>;
        deleteContact(userId: string): Promise<void>;
        getCursor?(key: string): Promise<string | undefined>;
        setCursor?(key: string, value: string): Promise<void>;
        getConversation(key: string): Promise<AIMessage[] | undefined>;
        setConversation(key: string, messages: AIMessage[]): Promise<void>;
        clearConversation(key: string): Promise<void>;
        getCheckpoint(key: string): Promise<FlowCheckpoint | undefined>;
        setCheckpoint(key: string, cp: FlowCheckpoint): Promise<void>;
        clearCheckpoint(key: string): Promise<void>;
        listCheckpoints(): Promise<[string, FlowCheckpoint][]>;
        setCheckpointIf?(
            key: string,
            cp: FlowCheckpoint,
            expectedRevision: number,
        ): Promise<boolean>;
        clearCheckpointIf?(key: string, expectedRevision: number): Promise<boolean>;
        getUserData?(
            userId: string,
            namespace: string,
            key: string,
        ): Promise<UserDataEntry | undefined>;
        setUserData?(entry: UserDataEntry): Promise<void>;
        deleteUserData?(
            userId: string,
            namespace?: string,
            key?: string,
        ): Promise<void>;
        listUserData?(userId: string, namespace?: string): Promise<UserDataEntry[]>;
        purgeExpiredUserData?(now?: number): Promise<number>;
        start(): Promise<void>;
        stop(): Promise<void>;
    }

    Implemented by

    Index
    • Shallow-merge chat onto the stored record. An own field set to undefined UNSETS that field, so a partial upsert must omit what it does not know (the Bot does).

      Parameters

      Returns Promise<void>

    • Parameters

      • chatId: string

      Returns Promise<void>

    • Parameters

      • userId: string

      Returns Promise<void>

    • Delivery cursor for long-poll/webhook transports (Telegram update_id).

      Parameters

      • key: string

      Returns Promise<string | undefined>

    • Parameters

      • key: string
      • value: string

      Returns Promise<void>

    • Parameters

      • key: string

      Returns Promise<void>

    • Parameters

      • key: string

      Returns Promise<void>

    • Compare-and-set checkpoint write (multi-replica coordination). Succeeds (resolves true) only when the stored row's FlowCheckpoint.revision equals expectedRevision, where 0 means "no row, or a row without revision"; otherwise the row is left untouched and it resolves false. ONE atomic statement per store (never a read-modify-write), so two replicas racing on one key see exactly one winner. expectedRevision is a non-negative integer (RangeError otherwise). Optional: a store without it keeps the local-fence behaviour; all six built-in stores implement it and pass the shared conformance block (test-utils/store-conformance.ts).

      Parameters

      Returns Promise<boolean>

    • Conditional delete: true when the row is absent, or its revision (0 without one) matched expectedRevision and it was deleted; false when a different revision is stored (the row is left untouched). Same atomicity rule as setCheckpointIf.

      Parameters

      • key: string
      • expectedRevision: number

      Returns Promise<boolean>

    • Read one entry. MUST return undefined when the entry is missing OR its expiresAt is <= Date.now() (lazy expiry — expired rows may still exist physically until purged).

      Parameters

      • userId: string
      • namespace: string
      • key: string

      Returns Promise<UserDataEntry | undefined>

    • Upsert one entry as a SINGLE atomic write that replaces both value and expiresAt (no read-modify-write inside the store). An entry whose expiresAt is already in the past may be dropped instead of written.

      Parameters

      Returns Promise<void>

    • Delete one key (namespace + key), one whole namespace (key omitted) or every namespace of the user (namespace omitted; key is then ignored). Deleting missing data is a no-op.

      Parameters

      • userId: string
      • Optionalnamespace: string
      • Optionalkey: string

      Returns Promise<void>

    • Live (non-expired) entries of a user — all namespaces, or just namespace. Order unspecified.

      Parameters

      • userId: string
      • Optionalnamespace: string

      Returns Promise<UserDataEntry[]>

    • Physically remove entries whose expiresAt <= now (default Date.now()) across the whole store; resolves with how many were removed. Stores with native expiry (Redis) resolve 0.

      Parameters

      • Optionalnow: number

      Returns Promise<number>