Base Snapshot
IBaseSnapshot
IBaseSnapshot is the persistence format used by Univer Bases. It describes one Base unit, including tables, table order, schema version, timestamps, and optional revision metadata.
Properties
| Property | Type | Description |
|---|---|---|
| id | string | Unique id of the Base unit. |
| name | string | Base name. |
| schemaVersion | number | Snapshot schema version. |
| tables | Record\<string, ITableSnapshot\> | Tables keyed by table id. |
| tableOrder | string[] | Ordered list of table ids. |
| createdAt | number | Creation timestamp. |
| updatedAt | number | Update timestamp. |
| createdBy? | string | Creator id. |
| rev? | number | Optional revision value used by persistence or collaboration layers. |
Minimal snapshot
TypeScript
const baseSnapshot = { id: 'base-1', name: 'Product tracker', schemaVersion: 1, tableOrder: ['tasks'], tables: { tasks: { id: 'tasks', name: 'Tasks', primaryFieldId: 'title', fieldOrder: ['title', 'status'], fields: { title: { id: 'title', name: 'Title', type: 'text', config: {} }, status: { id: 'status', name: 'Status', type: 'singleSelect', config: {} }, }, recordOrder: ['rec-1'], records: { 'rec-1': { id: 'rec-1', values: { title: 'Write docs', status: 'In progress' }, orderKey: 'a0', createdAt: Date.now(), updatedAt: Date.now(), }, }, views: {}, viewOrder: [], }, }, createdAt: Date.now(), updatedAt: Date.now(),}Usage
IBaseSnapshot is mainly used to:
- Create a
UniverInstanceType.UNIVER_BASEunit. - Persist and restore structured data.
- Prepare data for server-side processing.
- Transfer data between collaboration and import/export services.
Snapshot objects are persistence data. After a Base is running, prefer Facade APIs instead of mutating the snapshot object directly.
Save and restore
Use Facade save() to include registered plugin resources, such as dashboards and local comments. saveToBackend below is your application's persistence function:
TypeScript
const base = univerAPI.getActiveBase()if (!base) throw new Error('Open a Base first')await saveToBackend(base.save())In a new editor instance, register the same plugins before restoring with univerAPI.createBase(savedSnapshot). Do not save only tables or mutate the live model snapshot directly.
How is this guide?