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

# DurableKv

> Interface exported by @botmesh/core.

Defined in: [durability/kv.ts:68](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L68)

Versioned document store with two sorted indexes per table.

Contract (checked by `runDurableKvConformance`):

* `insert` writes only when `id` is absent and returns the new version, else `undefined`;
* `replace` writes only when the stored version equals `version` and returns the new
  version, else `undefined` (missing document or concurrent write);
* `remove` deletes only when the stored version equals `version`;
* `range` returns ids whose index score is `<= max`, ascending by score, at most `limit`.
  It may return ids whose document changed since (callers re-read); it must not miss a
  document whose committed score is `<= max` beyond `limit`.

## Methods

### start()?

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

Defined in: [durability/kv.ts:69](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L69)

#### Returns

`Promise`\<`void`>

***

### stop()?

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

Defined in: [durability/kv.ts:70](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L70)

#### Returns

`Promise`\<`void`>

***

### get()

```ts theme={null}
get(table, id): Promise<DurableKvEntry | undefined>;
```

Defined in: [durability/kv.ts:71](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L71)

#### Parameters

| Parameter | Type |
| - | - |
| `table` | `string` |
| `id` | `string` |

#### Returns

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

***

### insert()

```ts theme={null}
insert(
   table, 
   id, 
   value, 
   index
): Promise<string | undefined>;
```

Defined in: [durability/kv.ts:72](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L72)

#### Parameters

| Parameter | Type |
| - | - |
| `table` | `string` |
| `id` | `string` |
| `value` | `string` |
| `index` | [`DurableKvIndex`](https://botmesh.afaya.com.co/api/core/spi/interfaces/DurableKvIndex) |

#### Returns

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

***

### replace()

```ts theme={null}
replace(
   table, 
   id, 
   version, 
   value, 
   index
): Promise<string | undefined>;
```

Defined in: [durability/kv.ts:73](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L73)

#### Parameters

| Parameter | Type |
| - | - |
| `table` | `string` |
| `id` | `string` |
| `version` | `string` |
| `value` | `string` |
| `index` | [`DurableKvIndex`](https://botmesh.afaya.com.co/api/core/spi/interfaces/DurableKvIndex) |

#### Returns

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

***

### remove()

```ts theme={null}
remove(
   table, 
   id, 
   version
): Promise<boolean>;
```

Defined in: [durability/kv.ts:74](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L74)

#### Parameters

| Parameter | Type |
| - | - |
| `table` | `string` |
| `id` | `string` |
| `version` | `string` |

#### Returns

`Promise`\<`boolean`>

***

### range()

```ts theme={null}
range(
   table, 
   index, 
   max, 
   limit
): Promise<string[]>;
```

Defined in: [durability/kv.ts:75](https://github.com/andresayac/botmesh/blob/main/packages/core/src/durability/kv.ts#L75)

#### Parameters

| Parameter | Type |
| - | - |
| `table` | `string` |
| `index` | keyof [`DurableKvIndex`](https://botmesh.afaya.com.co/api/core/spi/interfaces/DurableKvIndex) |
| `max` | `number` |
| `limit` | `number` |

#### Returns

`Promise`\<`string`\[]>


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