import { BaseRecord, createRecordType, defineMigrations, RecordId } from '@bigbluebutton/store' import { JsonObject } from '@bigbluebutton/utils' import { T } from '@bigbluebutton/validate' /** * TLDocument * * @public */ export interface TLDocument extends BaseRecord<'document', RecordId> { gridSize: number name: string meta: JsonObject } /** @internal */ export const documentValidator: T.Validator = T.model( 'document', T.object({ typeName: T.literal('document'), id: T.literal('document:document' as RecordId), gridSize: T.number, name: T.string, meta: T.jsonValue as T.ObjectValidator, }) ) /** @internal */ export const documentVersions = { AddName: 1, AddMeta: 2, } as const /** @internal */ export const documentMigrations = defineMigrations({ currentVersion: documentVersions.AddMeta, migrators: { [documentVersions.AddName]: { up: (document: TLDocument) => { return { ...document, name: '' } }, down: ({ name: _, ...document }: TLDocument) => { return document }, }, [documentVersions.AddMeta]: { up: (record) => { return { ...record, meta: {}, } }, down: ({ meta: _, ...record }) => { return { ...record, } }, }, }, }) /** @public */ export const DocumentRecordType = createRecordType('document', { migrations: documentMigrations, validator: documentValidator, scope: 'document', }).withDefaultProperties( (): Omit => ({ gridSize: 10, name: '', meta: {}, }) ) // all document records have the same ID: 'document:document' /** @public */ export const TLDOCUMENT_ID: RecordId = DocumentRecordType.createId('document')