> ## Documentation Index
> Fetch the complete documentation index at: https://botmesh.afaya.com.co/llms.txt
> Use this file to discover all available pages before exploring further.

# NamespacedStore

> Class exported by @botmesh/core.

Defined in: [store/NamespacedStore.ts:39](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L39)

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

## Implements

* [`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore)

## Constructors

### Constructor

```ts theme={null}
new NamespacedStore(innerStore, namespace): NamespacedStore;
```

Defined in: [store/NamespacedStore.ts:58](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L58)

#### Parameters

| Parameter | Type |
| - | - |
| `innerStore` | [`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore) |
| `namespace` | [`StoreNamespace`](https://botmesh.afaya.com.co/api/core/interfaces/StoreNamespace) |

#### Returns

`NamespacedStore`

## Properties

### getUserData?

```ts theme={null}
readonly getUserData?: (userId, namespace, key) => Promise<UserDataEntry | undefined>;
```

Defined in: [store/NamespacedStore.ts:47](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L47)

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

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace` | `string` |
| `key` | `string` |

#### Returns

`Promise`\<[`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry) | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getUserData`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getuserdata)

***

### setUserData?

```ts theme={null}
readonly setUserData?: (entry) => Promise<void>;
```

Defined in: [store/NamespacedStore.ts:48](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L48)

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

| Parameter | Type |
| - | - |
| `entry` | [`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`setUserData`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#setuserdata)

***

### deleteUserData?

```ts theme={null}
readonly deleteUserData?: (userId, namespace?, key?) => Promise<void>;
```

Defined in: [store/NamespacedStore.ts:49](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L49)

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

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace?` | `string` |
| `key?` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`deleteUserData`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#deleteuserdata)

***

### listUserData?

```ts theme={null}
readonly listUserData?: (userId, namespace?) => Promise<UserDataEntry[]>;
```

Defined in: [store/NamespacedStore.ts:50](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L50)

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

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |
| `namespace?` | `string` |

#### Returns

`Promise`\<[`UserDataEntry`](https://botmesh.afaya.com.co/api/core/spi/interfaces/UserDataEntry)\[]>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`listUserData`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#listuserdata)

***

### purgeExpiredUserData?

```ts theme={null}
readonly purgeExpiredUserData?: (now?) => Promise<number>;
```

Defined in: [store/NamespacedStore.ts:51](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L51)

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

| Parameter | Type |
| - | - |
| `now?` | `number` |

#### Returns

`Promise`\<`number`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`purgeExpiredUserData`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#purgeexpireduserdata)

***

### setCheckpointIf?

```ts theme={null}
readonly setCheckpointIf?: (key, cp, expectedRevision) => Promise<boolean>;
```

Defined in: [store/NamespacedStore.ts:55](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L55)

Compare-and-set checkpoint write (multi-replica coordination). Succeeds (resolves
`true`) only when the stored row's [FlowCheckpoint.revision](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint.md#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

| Parameter | Type |
| - | - |
| `key` | `string` |
| `cp` | [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) |
| `expectedRevision` | `number` |

#### Returns

`Promise`\<`boolean`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`setCheckpointIf`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#setcheckpointif)

***

### clearCheckpointIf?

```ts theme={null}
readonly clearCheckpointIf?: (key, expectedRevision) => Promise<boolean>;
```

Defined in: [store/NamespacedStore.ts:56](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L56)

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](https://botmesh.afaya.com.co/api/core/interfaces/IStore.md#setcheckpointif).

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `expectedRevision` | `number` |

#### Returns

`Promise`\<`boolean`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`clearCheckpointIf`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#clearcheckpointif)

***

### innerStore

```ts theme={null}
readonly innerStore: IStore;
```

Defined in: [store/NamespacedStore.ts:59](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L59)

***

### namespace

```ts theme={null}
readonly namespace: StoreNamespace;
```

Defined in: [store/NamespacedStore.ts:60](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L60)

## Methods

### saveMessage()

```ts theme={null}
saveMessage(message): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:148](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L148)

#### Parameters

| Parameter | Type |
| - | - |
| `message` | [`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`saveMessage`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#savemessage)

***

### getMessage()

```ts theme={null}
getMessage(ref): Promise<StoredMessage | undefined>;
```

Defined in: [store/NamespacedStore.ts:151](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L151)

#### Parameters

| Parameter | Type |
| - | - |
| `ref` | [`MessageRef`](https://botmesh.afaya.com.co/api/core/interfaces/MessageRef) |

#### Returns

`Promise`\<[`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage) | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getMessage`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getmessage)

***

### getMessagesByChat()

```ts theme={null}
getMessagesByChat(chatId, limit?): Promise<StoredMessage[]>;
```

Defined in: [store/NamespacedStore.ts:154](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L154)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |
| `limit?` | `number` |

#### Returns

`Promise`\<[`StoredMessage`](https://botmesh.afaya.com.co/api/core/interfaces/StoredMessage)\[]>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getMessagesByChat`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getmessagesbychat)

***

### deleteMessage()

```ts theme={null}
deleteMessage(ref): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:158](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L158)

#### Parameters

| Parameter | Type |
| - | - |
| `ref` | [`MessageRef`](https://botmesh.afaya.com.co/api/core/interfaces/MessageRef) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`deleteMessage`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#deletemessage)

***

### upsertChat()

```ts theme={null}
upsertChat(chat): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:162](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L162)

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

| Parameter | Type |
| - | - |
| `chat` | [`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`upsertChat`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#upsertchat)

***

### getChat()

```ts theme={null}
getChat(chatId): Promise<StoredChat | undefined>;
```

Defined in: [store/NamespacedStore.ts:165](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L165)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |

#### Returns

`Promise`\<[`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat) | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getChat`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getchat)

***

### listChats()

```ts theme={null}
listChats(): Promise<StoredChat[]>;
```

Defined in: [store/NamespacedStore.ts:169](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L169)

#### Returns

`Promise`\<[`StoredChat`](https://botmesh.afaya.com.co/api/core/interfaces/StoredChat)\[]>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`listChats`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#listchats)

***

### deleteChat()

```ts theme={null}
deleteChat(chatId): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:174](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L174)

#### Parameters

| Parameter | Type |
| - | - |
| `chatId` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`deleteChat`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#deletechat)

***

### upsertContact()

```ts theme={null}
upsertContact(contact): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:178](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L178)

Shallow-merge `contact` onto the stored record; same `undefined` = unset rule as [upsertChat](https://botmesh.afaya.com.co/api/core/interfaces/IStore.md#upsertchat).

#### Parameters

| Parameter | Type |
| - | - |
| `contact` | [`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`upsertContact`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#upsertcontact)

***

### getContact()

```ts theme={null}
getContact(userId): Promise<StoredContact | undefined>;
```

Defined in: [store/NamespacedStore.ts:181](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L181)

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |

#### Returns

`Promise`\<[`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact) | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getContact`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getcontact)

***

### listContacts()

```ts theme={null}
listContacts(): Promise<StoredContact[]>;
```

Defined in: [store/NamespacedStore.ts:185](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L185)

#### Returns

`Promise`\<[`StoredContact`](https://botmesh.afaya.com.co/api/core/interfaces/StoredContact)\[]>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`listContacts`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#listcontacts)

***

### deleteContact()

```ts theme={null}
deleteContact(userId): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:190](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L190)

#### Parameters

| Parameter | Type |
| - | - |
| `userId` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`deleteContact`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#deletecontact)

***

### getCursor()

```ts theme={null}
getCursor(key): Promise<string | undefined>;
```

Defined in: [store/NamespacedStore.ts:194](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L194)

Delivery cursor for long-poll/webhook transports (Telegram update\_id).

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`string` | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getCursor`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getcursor)

***

### setCursor()

```ts theme={null}
setCursor(key, value): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:197](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L197)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `value` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`setCursor`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#setcursor)

***

### getConversation()

```ts theme={null}
getConversation(key): Promise<AIMessage[] | undefined>;
```

Defined in: [store/NamespacedStore.ts:201](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L201)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<[`AIMessage`](https://botmesh.afaya.com.co/api/core/interfaces/AIMessage)\[] | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getConversation`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getconversation)

***

### setConversation()

```ts theme={null}
setConversation(key, messages): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:204](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L204)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `messages` | [`AIMessage`](https://botmesh.afaya.com.co/api/core/interfaces/AIMessage)\[] |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`setConversation`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#setconversation)

***

### clearConversation()

```ts theme={null}
clearConversation(key): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:207](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L207)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`clearConversation`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#clearconversation)

***

### getCheckpoint()

```ts theme={null}
getCheckpoint(key): Promise<FlowCheckpoint | undefined>;
```

Defined in: [store/NamespacedStore.ts:211](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L211)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<[`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) | `undefined`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`getCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#getcheckpoint)

***

### setCheckpoint()

```ts theme={null}
setCheckpoint(key, checkpoint): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:214](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L214)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |
| `checkpoint` | [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint) |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`setCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#setcheckpoint)

***

### clearCheckpoint()

```ts theme={null}
clearCheckpoint(key): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:217](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L217)

#### Parameters

| Parameter | Type |
| - | - |
| `key` | `string` |

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`clearCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#clearcheckpoint)

***

### listCheckpoints()

```ts theme={null}
listCheckpoints(): Promise<[string, FlowCheckpoint][]>;
```

Defined in: [store/NamespacedStore.ts:220](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L220)

#### Returns

`Promise`\<\[`string`, [`FlowCheckpoint`](https://botmesh.afaya.com.co/api/core/interfaces/FlowCheckpoint)]\[]>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`listCheckpoints`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#listcheckpoints)

***

### start()

```ts theme={null}
start(): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:227](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L227)

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`start`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#start)

***

### stop()

```ts theme={null}
stop(): Promise<void>;
```

Defined in: [store/NamespacedStore.ts:228](https://github.com/andresayac/botmesh/blob/main/packages/core/src/store/NamespacedStore.ts#L228)

#### Returns

`Promise`\<`void`>

#### Implementation of

[`IStore`](https://botmesh.afaya.com.co/api/core/interfaces/IStore).[`stop`](https://botmesh.afaya.com.co/api/core/interfaces/IStore#stop)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.