/** * Shared type definitions for the DeepSpace SDK * * Types used by both client-side SDK and server-side workers. */ type ColumnInterpretation = { kind: 'plain'; } | { kind: 'currency'; symbol: string; decimals: number; } | { kind: 'date'; format?: string; } | { kind: 'datetime'; format?: string; } | { kind: 'boolean'; trueLabel?: string; falseLabel?: string; } | { kind: 'percent'; decimals?: number; } | { kind: 'select'; options: string[]; } | { kind: 'multiselect'; options: string[]; } | { kind: 'url'; } | { kind: 'email'; } | { kind: 'json'; } | { kind: 'reference'; targetTable: string; displayColumn: string; }; interface ColumnDefinition { /** Stable ID override (survives renames). Falls back to `col_{name}`. */ id?: string; name: string; storage: 'number' | 'text'; interpretation: ColumnInterpretation | string; expression?: string; userBound?: boolean; immutable?: boolean; required?: boolean; default?: unknown; timestampTrigger?: { field: string; value?: unknown; }; } type PermissionLevel = boolean | 'own' | 'unclaimed-or-own' | 'collaborator' | 'team' | 'access' | 'published' | 'shared'; interface RolePermissions { read: PermissionLevel; /** Create has no existing record to evaluate, so it is an explicit grant. */ create: boolean; update: PermissionLevel; delete: PermissionLevel; /** If set, only these caller-supplied columns can be created or updated by this role. */ writableFields?: string[]; } interface CollectionSchema { name: string; /** Every collection is stored in typed SQL columns. */ columns: ColumnDefinition[]; /** Composite uniqueness constraint (for example `['userId', 'taskId']`). */ uniqueOn?: string[]; /** Ownership column; defaults to the row creator. */ ownerField?: string; /** Column containing a JSON array of collaborator user ids. */ collaboratorsField?: string; /** Column containing the team id used by team permission rules. */ teamField?: string; /** A string is public when equal to `public`; an object supplies an exact value. */ visibilityField?: string | { field: string; value: unknown; }; /** Permissions per role; `*` is the catch-all role. */ permissions: Record; /** Default role assigned on the `users` collection. */ defaultRole?: string; /** * `users` collection only: what the `user.list` roster shows a non-admin * whose `read` policy is row-scoped (`'own'`, `'team'`, …). Default * `'public-identity'`: every registered user's id/name/imageUrl/role/lastSeenAt * (`lastSeenAt` is what `usePresence` reads) — the * row policy keeps guarding full-row reads on the records/query path. * `'read-policy'`: the roster contains only the rows the caller's read * policy grants (still projected to public identity) — for apps that scope * users to a tenant/team and must not show names across it. */ roster?: 'public-identity' | 'read-policy'; } /** * Collection Schema Definitions & Validation * * All collections use typed SQL columns. No document-mode / fields-based storage. */ /** Standard user columns. Apps spread these into their users schema. */ declare const USERS_COLUMNS: ColumnDefinition[]; declare const BASE_USERS_SCHEMA: CollectionSchema; /** * AI Chat Schemas * * Pre-built collection schemas for DO-backed AI chat history. * The worker is the only writer; the client reads via `useQuery`. */ declare const AI_CHATS_SCHEMA: CollectionSchema; declare const AI_MESSAGES_SCHEMA: CollectionSchema; /** * Messaging Schemas * * Pre-built collection schemas for messaging functionality. * These schemas intentionally model public channels only. RecordRoom row * permissions cannot make a channel private by themselves; advertising DMs * or private groups here would expose their records to every room member. * * @example * ```typescript * import { CHANNELS_SCHEMA, MESSAGES_SCHEMA, REACTIONS_SCHEMA } from 'deepspace/worker' * export const schemas = [usersSchema, CHANNELS_SCHEMA, MESSAGES_SCHEMA, REACTIONS_SCHEMA] * ``` */ declare const CHANNELS_SCHEMA: CollectionSchema; declare const MESSAGES_SCHEMA: CollectionSchema; declare const REACTIONS_SCHEMA: CollectionSchema; declare const CHANNEL_MEMBERS_SCHEMA: CollectionSchema; declare const READ_RECEIPTS_SCHEMA: CollectionSchema; export { AI_CHATS_SCHEMA, AI_MESSAGES_SCHEMA, BASE_USERS_SCHEMA, CHANNELS_SCHEMA, CHANNEL_MEMBERS_SCHEMA, type CollectionSchema, type ColumnDefinition, type ColumnInterpretation, MESSAGES_SCHEMA, type PermissionLevel, REACTIONS_SCHEMA, READ_RECEIPTS_SCHEMA, type RolePermissions, USERS_COLUMNS };