import type { ColineActorRef } from "./types"; /** Workspace membership and install consent are checked separately by the host. */ export interface ColineRecordAccess { workspace: "none" | "read" | "write"; readers: string[]; writers: string[]; } export const DEFAULT_RECORD_ACCESS: ColineRecordAccess = { workspace: "write", readers: [], writers: [], }; export function canAccessRecord( access: ColineRecordAccess, creator: ColineActorRef, userId: string | null, action: "read" | "write" | "manage", ): boolean { const owner = creator.kind === "user" ? creator.userId === userId : userId === null; if (owner) return true; if (action === "manage") return false; if (access.workspace === "write") return true; if (!userId) return false; if (access.writers.includes(userId)) return true; return action === "read" && (access.workspace === "read" || access.readers.includes(userId)); } export interface ColineRecordWriteOptions { expectedVersion?: number; } export interface ColineRecordInsertOptions { id?: string; access?: ColineRecordAccess; }