CustomRecordInfo

See source code
Table of contents

Configuration for a custom record type in the schema.

Custom record types allow you to add entirely new data types to the tldraw store that don't fit into the existing shape, binding, or asset categories. This is useful for storing domain-specific data like comments, annotations, or application state that needs to participate in persistence and synchronization.

interface CustomRecordInfo {}

Example

const commentRecordConfig: CustomRecordInfo = {
  scope: 'document',
  validator: T.object({
    id: T.string,
    typeName: T.literal('comment'),
    text: T.string,
    shapeId: T.string,
    authorId: T.string,
    createdAt: T.number,
  }),
  migrations: createRecordMigrationSequence({
    sequenceId: 'com.myapp.comment',
    recordType: 'comment',
    sequence: [],
  }),
}

Properties

createDefaultProperties

optional

Optional factory function that returns default property values for new records.

Called when creating new records to provide initial values for any properties not explicitly provided during creation.

createDefaultProperties?: () => Record<string, unknown>

migrations

optional

Optional migration sequence for handling schema evolution over time.

Can be a full MigrationSequence or a simplified TLPropsMigrations format. If not provided, an empty migration sequence will be created automatically.


scope

The scope determines how records of this type are persisted and synchronized: - document: Persisted and synced across all clients - session: Local to current session, not synced - presence: Ephemeral presence data, may be synced but not persisted

scope: RecordScope

validator

Validator for the complete record structure.

Should validate the entire record including id and typeName fields. Use validators like T.object, T.string, etc.

validator: T.Validatable<any>

Prev
BoxModel
Next
SchemaPropsInfo