rspace-online/modules/rdesign/schemas.ts

37 lines
1.0 KiB
TypeScript

/**
* rDesign Automerge document schemas.
*
* Syncs linked Affine design projects per space.
* Actual design data lives in the Affine instance.
*
* DocId format: {space}:design:projects
*/
import type { DocSchema } from '../../shared/local-first/document';
export interface LinkedProject {
id: string;
url: string;
name: string;
addedBy: string | null;
addedAt: number;
}
export interface DesignDoc {
meta: { module: string; collection: string; version: number; spaceSlug: string; createdAt: number };
linkedProjects: Record<string, LinkedProject>;
}
export const designSchema: DocSchema<DesignDoc> = {
module: 'design',
collection: 'projects',
version: 1,
init: (): DesignDoc => ({
meta: { module: 'design', collection: 'projects', version: 1, spaceSlug: '', createdAt: Date.now() },
linkedProjects: {},
}),
migrate: (doc: any) => { if (!doc.linkedProjects) doc.linkedProjects = {}; doc.meta.version = 1; return doc; },
};
export function designDocId(space: string) { return `${space}:design:projects` as const; }