Skip to main content
import { defineStores, codes } from '@collab-kit/utils';

defineStores()

Identity function that preserves store schema types for full TypeScript inference. Use it to define your store schemas when initializing the client.
function defineStores<T extends StoresConfig>(config: T): T;

Usage

import { defineStores } from '@collab-kit/utils';

const stores = defineStores({
  tasks: {
    title: { type: 'string', required: true },
    completed: { type: 'boolean', default: false },
    assignee: { type: 'string' },
  },
  settings: {
    theme: { type: 'string', required: true, default: 'light' },
    fontSize: { type: 'number', required: true, default: 14 },
  },
});
The returned value is the same object you pass in, but TypeScript preserves the exact literal types of your schema. This enables full type inference when calling client.stores.<name>.set(), get(), etc. Pass the result to the CollabKitClient constructor:
const client = new CollabKitClient({
  serverUrl: 'https://api.collab-kit.com',
  authToken: '<jwt>',
  stores,
});

// Fully typed: value is { title: string; completed?: boolean; assignee?: string }
await client.stores.tasks.set({
  key: 'task-1',
  value: { title: 'Ship v1' },
});

codes

Mapping of ResponseCode enum values to their HTTP status codes, descriptions, and messages. Useful for interpreting error responses.
const codes: Record<ResponseCode, {
  description: string;
  code: number;
  message: string;
}>;

Usage

import { codes, ResponseCode } from '@collab-kit/utils';

const info = codes[ResponseCode.NOT_FOUND];
// { description: 'NOT_FOUND', code: 404, message: 'Not found' }