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

# Store Types

> Types for schema-driven KV store definitions and type inference.

```typescript theme={null}
import type { StoreFieldDefinition, StoreSchema, StoresConfig, InferDocument } from '@collab-kit/utils';
```

## StoreFieldDefinition

Defines a single field in a store schema.

```typescript theme={null}
interface StoreFieldDefinition {
  type: 'string' | 'number' | 'boolean';
  required?: boolean;
  default?: string | number | boolean;
}
```

## StoreSchema

A record of field names to their definitions.

```typescript theme={null}
type StoreSchema = Record<string, StoreFieldDefinition>;
```

## StoresConfig

A record of store names to their schemas. Passed to the client constructor.

```typescript theme={null}
type StoresConfig = Record<string, StoreSchema>;
```

## InferDocument

Infers a TypeScript type from a store schema. Required fields become mandatory keys; optional fields become optional keys.

```typescript theme={null}
type InferDocument<S extends StoreSchema> = {
  [K in keyof S as S[K] extends { required: true } ? K : never]: FieldTypeMap[S[K]['type']];
} & {
  [K in keyof S as S[K] extends { required: true } ? never : K]?: FieldTypeMap[S[K]['type']];
};
```

**Example:**

```typescript theme={null}
const schema = {
  theme: { type: 'string' as const, required: true as const },
  fontSize: { type: 'number' as const, required: true as const },
  notifications: { type: 'boolean' as const },
};

// InferDocument<typeof schema> resolves to:
// { theme: string; fontSize: number; notifications?: boolean }
```
