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

    Class NamespacedStore

    Isolates every opaque store key by tenant/bot/provider connection while preserving the public, unprefixed ids seen by callers.

    Implements

    Index
    getUserData?: (
        userId: string,
        namespace: string,
        key: string,
    ) => Promise<UserDataEntry | undefined>

    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).

    setUserData?: (entry: UserDataEntry) => Promise<void>

    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.

    deleteUserData?: (
        userId: string,
        namespace?: string,
        key?: string,
    ) => 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.

    listUserData?: (userId: string, namespace?: string) => Promise<UserDataEntry[]>

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

    purgeExpiredUserData?: (now?: number) => Promise<number>

    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.

    setCheckpointIf?: (
        key: string,
        cp: FlowCheckpoint,
        expectedRevision: number,
    ) => Promise<boolean>

    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).

    clearCheckpointIf?: (key: string, expectedRevision: number) => 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.

    innerStore: IStore
    namespace: StoreNamespace
    • 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>

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

      Parameters

      • key: string

      Returns Promise<string | undefined>