@univerjs-pro/collaboration-database-sqlite 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/README.zh-CN.md +20 -4
- package/dist/index.cjs +68 -25
- package/dist/index.d.ts +17 -15
- package/dist/index.mjs +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,12 +38,22 @@ Pass the Adapter to `UniverCollabService` as `dbAdapter`.
|
|
|
38
38
|
|
|
39
39
|
- It does not change `journal_mode`; configure WAL, checkpointing, or backup policy before opening the Adapter when needed.
|
|
40
40
|
- Core tables use the `collaboration_` prefix. Protocol objects are stored as MessagePack `BLOB` payloads.
|
|
41
|
-
- Schema version `('core',
|
|
41
|
+
- Schema version `('core', 4)` is stored in `collaboration_schema_versions`, which other Univer collaboration components share; `PRAGMA user_version` is not used.
|
|
42
42
|
- Changeset scalar columns and the submission unique constraint provide database-level integrity, while commits use revision CAS and do not query the submission key.
|
|
43
|
-
- An empty database is initialized automatically. A core schema version other than
|
|
43
|
+
- An empty database is initialized automatically. A core schema version other than 4 is rejected; see Migrations.
|
|
44
44
|
|
|
45
45
|
This implementation suits local applications and small-to-medium single-Node deployments.
|
|
46
46
|
|
|
47
|
+
## Application metadata
|
|
48
|
+
|
|
49
|
+
`UnitRecord.metadata` and `ChangesetRecord.metadata` use `Record<string, unknown>` and must contain
|
|
50
|
+
JSON values. Creation stores `record.metadata`; `getUnit()` and `getChangesets()` return the saved values.
|
|
51
|
+
`commitChangeset()` requires complete `unitMetadata` and `changeset.metadata` and saves both atomically
|
|
52
|
+
with the new head. The Service prepares the metadata defaults and drafts before each commit.
|
|
53
|
+
|
|
54
|
+
Soft deletion and recovery preserve metadata; hard deletion removes changesets and clears Unit
|
|
55
|
+
metadata. Snapshot saves leave metadata unchanged.
|
|
56
|
+
|
|
47
57
|
## Migrations
|
|
48
58
|
|
|
49
59
|
Each release writes one core schema version and opens only that version. Opening an older database
|
|
@@ -53,7 +63,8 @@ fails with an error that points here; migrations never run when the adapter open
|
|
|
53
63
|
| --- | --- |
|
|
54
64
|
| v1 | 1.0.0-rc |
|
|
55
65
|
| v2 | 1.0.0 to 1.3.x |
|
|
56
|
-
| v3 |
|
|
66
|
+
| v3 | 1.4.x |
|
|
67
|
+
| v4 | 1.5.0 onward |
|
|
57
68
|
|
|
58
69
|
Stop writers, then let `migrateSQLiteCore` back up the file and apply every missing step:
|
|
59
70
|
|
|
@@ -61,7 +72,7 @@ Stop writers, then let `migrateSQLiteCore` back up the file and apply every miss
|
|
|
61
72
|
import { migrateSQLiteCore } from '@univerjs-pro/collaboration-database-sqlite';
|
|
62
73
|
|
|
63
74
|
const result = await migrateSQLiteCore({ filename: './data/collaboration.sqlite' });
|
|
64
|
-
// { from: 2, to:
|
|
75
|
+
// { from: 2, to: 4, backupFilename: './data/collaboration.sqlite.v2.backup' }
|
|
65
76
|
```
|
|
66
77
|
|
|
67
78
|
The backup is a consistent copy written next to the database before anything changes; pass
|
|
@@ -96,3 +107,8 @@ V3 stores protocol objects as MessagePack `BLOB` payloads instead of JSON text,
|
|
|
96
107
|
explicit indexes. Each v2 tombstone becomes a hard-delete marker row that keeps its Unit ID reserved;
|
|
97
108
|
the marker carries placeholder values (Sheet type, revision 1, creator `anonymous`, purge time as
|
|
98
109
|
creation time) and is never returned by reads.
|
|
110
|
+
|
|
111
|
+
### Data added in v4
|
|
112
|
+
|
|
113
|
+
V4 adds metadata to Units and changesets. Existing records receive `{}`; no metadata is inferred
|
|
114
|
+
from document contents, and changeset payloads remain unchanged.
|
package/README.zh-CN.md
CHANGED
|
@@ -39,14 +39,24 @@ await database.dispose();
|
|
|
39
39
|
|
|
40
40
|
- 不主动修改 `journal_mode`;需要 WAL、checkpoint 或备份策略时由应用在打开前配置。
|
|
41
41
|
- 核心表使用 `collaboration_` 前缀;协议对象以 MessagePack `BLOB` 保存。
|
|
42
|
-
- schema 版本以 `('core',
|
|
42
|
+
- schema 版本以 `('core', 4)` 写入 `collaboration_schema_versions`,该表与其他 Univer 协同
|
|
43
43
|
组件共用,不占用 `PRAGMA user_version`。
|
|
44
44
|
- changeset 标量列和 submission unique constraint 提供数据库级完整性;提交只做 revision
|
|
45
45
|
CAS,不按 submission key 点查。
|
|
46
|
-
- 空库会自动初始化;版本不为
|
|
46
|
+
- 空库会自动初始化;版本不为 4 的核心 schema 会被拒绝,见下文的迁移一节。
|
|
47
47
|
|
|
48
48
|
本实现适合本地应用和中小规模单 Node 部署。
|
|
49
49
|
|
|
50
|
+
## 应用元数据
|
|
51
|
+
|
|
52
|
+
`UnitRecord.metadata` 和 `ChangesetRecord.metadata` 使用 `Record<string, unknown>`,只接受 JSON 值。
|
|
53
|
+
创建时保存 `record.metadata`,通过 `getUnit()` 和 `getChangesets()` 读取已保存的值。
|
|
54
|
+
`commitChangeset()` 必须接收完整的 `unitMetadata` 和 `changeset.metadata`,并与新 head
|
|
55
|
+
原子保存。metadata 的默认值和草稿由 Service 在每次提交前统一准备。
|
|
56
|
+
|
|
57
|
+
软删除和恢复保留 metadata;hard delete 删除 changeset 并清空 Unit metadata。
|
|
58
|
+
保存 snapshot 不修改 metadata。
|
|
59
|
+
|
|
50
60
|
## 迁移
|
|
51
61
|
|
|
52
62
|
每个版本只写入并打开一个核心 schema 版本。打开旧库会报错并指向这里;打开数据库时从不自动迁移。
|
|
@@ -55,7 +65,8 @@ await database.dispose();
|
|
|
55
65
|
| --- | --- |
|
|
56
66
|
| v1 | 1.0.0-rc |
|
|
57
67
|
| v2 | 1.0.0 至 1.3.x |
|
|
58
|
-
| v3 |
|
|
68
|
+
| v3 | 1.4.x |
|
|
69
|
+
| v4 | 1.5.0 起 |
|
|
59
70
|
|
|
60
71
|
先停止写入,然后由 `migrateSQLiteCore` 备份文件并补齐所有缺少的步骤:
|
|
61
72
|
|
|
@@ -63,7 +74,7 @@ await database.dispose();
|
|
|
63
74
|
import { migrateSQLiteCore } from '@univerjs-pro/collaboration-database-sqlite';
|
|
64
75
|
|
|
65
76
|
const result = await migrateSQLiteCore({ filename: './data/collaboration.sqlite' });
|
|
66
|
-
// { from: 2, to:
|
|
77
|
+
// { from: 2, to: 4, backupFilename: './data/collaboration.sqlite.v2.backup' }
|
|
67
78
|
```
|
|
68
79
|
|
|
69
80
|
备份是在任何改动之前写到数据库旁边的一致副本,可用 `backupFilename` 指定路径;已有的备份文件永远不会被
|
|
@@ -91,3 +102,8 @@ v3 以 MessagePack `BLOB` 保存协议对象而不再是 JSON 文本,删除状
|
|
|
91
102
|
`deleted_status` 与 `deleted_at_ms` 中,并移除 tombstone 表和显式索引。每条 v2 tombstone 变成一行
|
|
92
103
|
hard delete 标记,继续占住该 Unit ID;标记行使用占位值(Sheet 类型、revision 1、创建者 `anonymous`、
|
|
93
104
|
清除时间作为创建时间),读取接口永远不会返回它。
|
|
105
|
+
|
|
106
|
+
### v4 新增的数据
|
|
107
|
+
|
|
108
|
+
v4 为 Unit 和 changeset 增加 metadata。已有记录初始化为 `{}`,不从文档内容推导 metadata,
|
|
109
|
+
changeset payload 保持不变。
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("@msgpack/msgpack"),l=require("libsql");l=s(l,1);let u=require("@univerjs-pro/collaboration-service"),d=require("node:fs"),f=require("node:buffer"),p=require("@univerjs/protocol");var m=`core`,h=`
|
|
2
|
+
CREATE TABLE IF NOT EXISTS collaboration_schema_versions (
|
|
3
|
+
component TEXT PRIMARY KEY,
|
|
4
|
+
version INTEGER NOT NULL CHECK (version >= 1)
|
|
5
|
+
);
|
|
6
|
+
`,g=`
|
|
2
7
|
CREATE TABLE collaboration_units (
|
|
3
8
|
unit_id TEXT PRIMARY KEY NOT NULL,
|
|
4
9
|
type INTEGER NOT NULL,
|
|
@@ -7,6 +12,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
7
12
|
created_at_ms INTEGER NOT NULL,
|
|
8
13
|
deleted_at_ms INTEGER,
|
|
9
14
|
deleted_status TEXT CHECK (deleted_status IN ('soft', 'hard')),
|
|
15
|
+
metadata TEXT NOT NULL DEFAULT '{}'
|
|
16
|
+
CHECK (json_valid(metadata)),
|
|
10
17
|
CHECK ((deleted_status IS NULL) = (deleted_at_ms IS NULL))
|
|
11
18
|
);
|
|
12
19
|
CREATE TABLE collaboration_snapshots (
|
|
@@ -23,6 +30,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
23
30
|
req_id INTEGER NOT NULL CHECK (req_id >= 1),
|
|
24
31
|
created_at_ms INTEGER NOT NULL,
|
|
25
32
|
payload BLOB NOT NULL,
|
|
33
|
+
metadata TEXT NOT NULL DEFAULT '{}'
|
|
34
|
+
CHECK (json_valid(metadata)),
|
|
26
35
|
PRIMARY KEY (unit_id, revision),
|
|
27
36
|
UNIQUE (unit_id, sid, req_id)
|
|
28
37
|
);
|
|
@@ -32,9 +41,9 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
32
41
|
payload BLOB NOT NULL,
|
|
33
42
|
PRIMARY KEY (unit_id, block_id)
|
|
34
43
|
);
|
|
35
|
-
`,
|
|
44
|
+
`,_=class{_database;_encoder=new c.Encoder({ignoreUndefined:!0});_decoder=new c.Decoder;_disposed=!1;_getUnit;_getSnapshot;_getSnapshotAtRevision;_getSnapshotInfo;_getSnapshotInfoAtRevision;_getChangesets;_getChangesetsInRange;_getSheetBlock;_insertUnit;_insertChangeset;_updateUnitHeadAndMetadata;_upsertSnapshot;_insertSheetBlock;_deleteSnapshots;_deleteChangesets;_deleteSheetBlocks;_markSoftDeleted;_markHardDeleted;_markActive;constructor(e){if(!e.filename)throw new u.CollabError(`INVALID_REQUEST`,`SQLite filename is required`);let t=e.busyTimeoutMs??5e3;this._database=new l.default(e.filename,{timeout:t});try{this._database.exec(`PRAGMA foreign_keys = ON; PRAGMA busy_timeout = ${t};`),this._initializeSchema(),this._getUnit=this._database.prepare(`
|
|
36
45
|
SELECT unit_id AS unitID, type, head_revision AS headRevision,
|
|
37
|
-
creator_id AS creatorID, created_at_ms AS createdAt, deleted_status AS deletedStatus
|
|
46
|
+
creator_id AS creatorID, created_at_ms AS createdAt, metadata, deleted_status AS deletedStatus
|
|
38
47
|
FROM collaboration_units
|
|
39
48
|
WHERE unit_id = ?
|
|
40
49
|
`),this._getSnapshot=this._database.prepare(`
|
|
@@ -66,13 +75,13 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
66
75
|
ORDER BY s.revision DESC
|
|
67
76
|
LIMIT 1
|
|
68
77
|
`),this._getChangesets=this._database.prepare(`
|
|
69
|
-
SELECT c.payload
|
|
78
|
+
SELECT c.payload, c.metadata
|
|
70
79
|
FROM collaboration_units u
|
|
71
80
|
LEFT JOIN collaboration_changesets c ON c.unit_id = u.unit_id AND c.revision > ?
|
|
72
81
|
WHERE u.unit_id = ? AND u.deleted_status IS NULL
|
|
73
82
|
ORDER BY c.revision ASC
|
|
74
83
|
`),this._getChangesetsInRange=this._database.prepare(`
|
|
75
|
-
SELECT c.payload
|
|
84
|
+
SELECT c.payload, c.metadata
|
|
76
85
|
FROM collaboration_units u
|
|
77
86
|
LEFT JOIN collaboration_changesets c
|
|
78
87
|
ON c.unit_id = u.unit_id AND c.revision > ? AND c.revision <= ?
|
|
@@ -84,39 +93,68 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
84
93
|
JOIN collaboration_units u ON u.unit_id = b.unit_id
|
|
85
94
|
WHERE b.unit_id = ? AND b.block_id = ? AND u.deleted_status IS NULL
|
|
86
95
|
`),this._insertUnit=this._database.prepare(`
|
|
87
|
-
INSERT INTO collaboration_units (unit_id, type, head_revision, creator_id, created_at_ms)
|
|
88
|
-
VALUES (?, ?, 1, ?, ?)
|
|
96
|
+
INSERT INTO collaboration_units (unit_id, type, head_revision, creator_id, created_at_ms, metadata)
|
|
97
|
+
VALUES (?, ?, 1, ?, ?, ?)
|
|
89
98
|
`),this._insertChangeset=this._database.prepare(`
|
|
90
99
|
INSERT INTO collaboration_changesets
|
|
91
|
-
(unit_id, revision, base_revision, sid, req_id, created_at_ms, payload)
|
|
92
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
93
|
-
`),this.
|
|
100
|
+
(unit_id, revision, base_revision, sid, req_id, created_at_ms, payload, metadata)
|
|
101
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
102
|
+
`),this._updateUnitHeadAndMetadata=this._database.prepare(`UPDATE collaboration_units SET head_revision = ?, metadata = ? WHERE unit_id = ?`),this._upsertSnapshot=this._database.prepare(`
|
|
94
103
|
INSERT INTO collaboration_snapshots (unit_id, revision, payload) VALUES (?, ?, ?)
|
|
95
104
|
ON CONFLICT (unit_id, revision) DO UPDATE SET payload = excluded.payload
|
|
96
|
-
`),this.
|
|
105
|
+
`),this._insertSheetBlock=this._database.prepare(`
|
|
97
106
|
INSERT INTO collaboration_sheet_blocks (unit_id, block_id, payload) VALUES (?, ?, ?)
|
|
98
|
-
ON CONFLICT (unit_id, block_id) DO
|
|
99
|
-
`),this._deleteSnapshots=this._database.prepare(`DELETE FROM collaboration_snapshots WHERE unit_id = ?`),this._deleteChangesets=this._database.prepare(`DELETE FROM collaboration_changesets WHERE unit_id = ?`),this._deleteSheetBlocks=this._database.prepare(`DELETE FROM collaboration_sheet_blocks WHERE unit_id = ?`),this._markSoftDeleted=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = ?, deleted_status = 'soft' WHERE unit_id = ?`),this._markHardDeleted=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = ?, deleted_status = 'hard' WHERE unit_id = ?`),this._markActive=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = NULL, deleted_status = NULL WHERE unit_id = ?`)}catch(e){throw this._database.close(),e}}async getUnit(e,t){this._assertOpen();let n=this._readUnit(t);return n&&n.deletedStatus===null?
|
|
100
|
-
|
|
101
|
-
component TEXT PRIMARY KEY,
|
|
102
|
-
version INTEGER NOT NULL CHECK (version >= 1)
|
|
103
|
-
);
|
|
104
|
-
`);let e=this._readSchemaVersion();if(e!==3){if(e!==void 0)throw y(e);this._createSchema()}}).immediate()}_readSchemaVersion(){return this._database.prepare(`SELECT version FROM collaboration_schema_versions WHERE component = ?`).get(m)?.version}_createSchema(){this._database.exec(`
|
|
105
|
-
${h}
|
|
107
|
+
ON CONFLICT (unit_id, block_id) DO NOTHING
|
|
108
|
+
`),this._deleteSnapshots=this._database.prepare(`DELETE FROM collaboration_snapshots WHERE unit_id = ?`),this._deleteChangesets=this._database.prepare(`DELETE FROM collaboration_changesets WHERE unit_id = ?`),this._deleteSheetBlocks=this._database.prepare(`DELETE FROM collaboration_sheet_blocks WHERE unit_id = ?`),this._markSoftDeleted=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = ?, deleted_status = 'soft' WHERE unit_id = ?`),this._markHardDeleted=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = ?, deleted_status = 'hard', metadata = '{}' WHERE unit_id = ?`),this._markActive=this._database.prepare(`UPDATE collaboration_units SET deleted_at_ms = NULL, deleted_status = NULL WHERE unit_id = ?`)}catch(e){throw this._database.close(),e}}async getUnit(e,t){this._assertOpen();let n=this._readUnit(t);return n&&n.deletedStatus===null?x(n):null}async getSnapshot(e,t,n){this._assertOpen();let r=y(n?.revision),i=r===void 0?this._getSnapshot.get(t):this._getSnapshotAtRevision.get(t,r);return i?this._decode(i.payload):null}async getSnapshotInfo(e,t,n){this._assertOpen();let r=y(n?.revision),i=r===void 0?this._getSnapshotInfo.get(t):this._getSnapshotInfoAtRevision.get(t,r);return i?{unitID:i.unitID,type:i.type,rev:i.rev}:null}async getChangesets(e,t,n){if(this._assertOpen(),n.from<0||n.to!==void 0&&n.to<0)throw new u.CollabError(`INVALID_REQUEST`,`Changeset range revisions cannot be negative`);let r=n.to===void 0?this._getChangesets.all(n.from,t):this._getChangesetsInRange.all(n.from,n.to,t);if(r.length===0)return null;let i=[];for(let e of r)e.payload!==null&&i.push(this._decodeChangeset(e.payload,e.metadata));return i}async getSheetBlock(e,t,n){this._assertOpen();let r=this._getSheetBlock.get(t,n);return r?this._decode(r.payload):null}async createUnit(e,t){this._assertOpen(),v(t);let{record:n,snapshot:r,sheetBlocks:i=[]}=t,a=this._encode(r),o=this._encodeBlocks(i),s=JSON.stringify(n.metadata);return this._database.transaction(()=>{let e=this._readUnit(n.unitID);if(e){if(e.deletedStatus!==null)throw new u.CollabError(`INVALID_REQUEST`,`A deleted unit ID cannot be reused`);return{status:`already-exists`,record:x(e)}}return this._insertUnit.run(n.unitID,n.type,n.creatorID,n.createdAt,s),this._writeSnapshot(n.unitID,1,a,o),{status:`created`,record:{...n,metadata:JSON.parse(s)}}}).immediate()}async commitChangeset(e,t){this._assertOpen();let{changeset:n}=t;return this._database.transaction(()=>{let e=this._requireActiveUnit(n.unitID);if(e.headRevision!==n.revision-1)return{status:`revision-mismatch`,actualHeadRevision:e.headRevision};let r=Date.now(),{metadata:i,...a}=n,o=this._encode({...a,createTime:Math.floor(r/1e3)}),s=JSON.stringify(i);return this._insertChangeset.run(n.unitID,n.revision,n.baseRev,n.sid,n.reqId,r,o,s),this._updateUnitHeadAndMetadata.run(n.revision,JSON.stringify(t.unitMetadata),n.unitID),{status:`committed`,changeset:this._decodeChangeset(o,s),headRevision:n.revision}}).immediate()}async saveSnapshot(e,t){this._assertOpen();let{snapshot:n,sheetBlocks:r=[]}=t,i=this._encode(n),a=this._encodeBlocks(r);this._database.transaction(()=>{let e=this._requireActiveUnit(n.unitID);if(n.type!==e.type||n.rev<1||n.rev>e.headRevision)throw new u.CollabError(`INVALID_REQUEST`,`Snapshot does not match the stored unit head`);this._writeSnapshot(n.unitID,n.rev,i,a)}).immediate()}async deleteUnits(e,t){this._assertOpen();let{unitIDs:n}=t;return n.length===0?{units:[]}:this._database.transaction(()=>{let e=n.map(e=>{let n=this._readUnit(e);if(!n||n.deletedStatus===`hard`&&!t.hardDelete)throw new u.CollabError(`UNIT_NOT_FOUND`,`Cannot delete a missing unit`);return{unitID:e,status:t.hardDelete?n.deletedStatus===`hard`?`already-hard-deleted`:`hard-deleted`:n.deletedStatus===null?`soft-deleted`:`already-soft-deleted`}}),r=Date.now();for(let t of e)t.status===`hard-deleted`?(this._deleteSnapshots.run(t.unitID),this._deleteChangesets.run(t.unitID),this._deleteSheetBlocks.run(t.unitID),this._markHardDeleted.run(r,t.unitID)):t.status===`soft-deleted`&&this._markSoftDeleted.run(r,t.unitID);return{units:e}}).immediate()}async recoverUnits(e,t){this._assertOpen();let{unitIDs:n}=t;return n.length===0?{units:[]}:this._database.transaction(()=>{let e=n.map(e=>{let t=this._readUnit(e);if(!t)throw new u.CollabError(`UNIT_NOT_FOUND`,`Cannot recover a missing unit`);if(t.deletedStatus===`hard`)throw new u.CollabError(`INVALID_REQUEST`,`A hard-deleted unit cannot be recovered`);return{unitID:e,status:t.deletedStatus===null?`already-active`:`recovered`}});for(let t of e)t.status===`recovered`&&this._markActive.run(t.unitID);return{units:e}}).immediate()}async dispose(){this._disposed||(this._disposed=!0,this._database.close())}_initializeSchema(){this._database.transaction(()=>{this._database.exec(h);let e=this._readSchemaVersion();if(e!==4){if(e!==void 0)throw b(e);this._createSchema()}}).immediate()}_readSchemaVersion(){return this._database.prepare(`SELECT version FROM collaboration_schema_versions WHERE component = ?`).get(m)?.version}_createSchema(){this._database.exec(`
|
|
109
|
+
${g}
|
|
106
110
|
INSERT INTO collaboration_schema_versions (component, version)
|
|
107
|
-
VALUES ('${m}',
|
|
108
|
-
`)}_readUnit(e){return this._getUnit.get(e)}_requireActiveUnit(e){let t=this._readUnit(e);if(!t||t.deletedStatus!==null)throw new u.CollabError(`UNIT_NOT_FOUND`,`Unit is not active`);return t}_writeSnapshot(e,t,n,r){for(let t of r)this.
|
|
109
|
-
WHERE tbl_name IN (${r}) AND type IN ('index', 'trigger') AND sql IS NOT NULL`).all(...t).filter(e=>!n.has(e.name))}function
|
|
111
|
+
VALUES ('${m}', 4);
|
|
112
|
+
`)}_readUnit(e){return this._getUnit.get(e)}_requireActiveUnit(e){let t=this._readUnit(e);if(!t||t.deletedStatus!==null)throw new u.CollabError(`UNIT_NOT_FOUND`,`Unit is not active`);return t}_writeSnapshot(e,t,n,r){for(let t of r)this._insertSheetBlock.run(e,t.id,t.payload);this._upsertSnapshot.run(e,t,n)}_assertOpen(){if(this._disposed)throw new u.CollabError(`INTERNAL_ERROR`,`SQLite Database Adapter is disposed`)}_encode(e){return this._encoder.encode(e)}_encodeBlocks(e){return e.map(e=>({id:e.id,payload:this._encode(e)}))}_decode(e){let t=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return this._decoder.decode(t)}_decodeChangeset(e,t){return{...this._decode(e),metadata:JSON.parse(t)}}};function v({record:e,snapshot:t}){if(e.headRevision!==1||t.rev!==1||t.unitID!==e.unitID||t.type!==e.type)throw new u.CollabError(`INVALID_REQUEST`,`Initial record and snapshot must match at revision 1`);if(typeof e.creatorID!=`string`||e.creatorID.length===0||!Number.isSafeInteger(e.createdAt)||e.createdAt<0)throw new u.CollabError(`INVALID_REQUEST`,`Unit creation requires creatorID and createdAt in Unix milliseconds`)}function y(e){if(e!==void 0&&e<0)throw new u.CollabError(`INVALID_REQUEST`,`Snapshot revision cannot be negative`);return e}function b(e){return new u.CollabError(`INTERNAL_ERROR`,`Core schema version ${e} is not supported by this adapter (expected 4); ${e<4?`run migrateSQLiteCore first`:`upgrade the adapter`}`)}function x(e){return{unitID:e.unitID,type:e.type,headRevision:e.headRevision,creatorID:e.creatorID,createdAt:e.createdAt,metadata:JSON.parse(e.metadata)}}async function S(e,t){let n=new l.default(e,{fileMustExist:!0}),r=!1;try{n.exec(`PRAGMA foreign_keys = OFF; PRAGMA legacy_alter_table = ON; BEGIN IMMEDIATE;`),r=!0,await t(n),n.exec(`COMMIT;`),r=!1}finally{try{r&&n.exec(`ROLLBACK;`)}finally{n.close()}}}function C(e,t,n){if(e.prepare(`SELECT version FROM collaboration_schema_versions WHERE component = 'core'`).get()?.version!==t)throw new u.CollabError(`INVALID_REQUEST`,`${n} requires core schema version ${t}`)}function w(e,t,n){let r=e.prepare(`PRAGMA table_info(${t})`).all().map(e=>e.name);if(r.length===0||n.some(e=>!r.includes(e)))throw new u.CollabError(`INVALID_REQUEST`,`Table ${t} differs from the supported schema; refusing a potentially lossy migration`)}function T(e,t){if(e.prepare(`UPDATE collaboration_schema_versions SET version = ? WHERE component = 'core'`).run(t),e.prepare(`PRAGMA foreign_key_check`).all().length>0)throw new u.CollabError(`INVALID_REQUEST`,`Foreign key validation failed during core migration`)}function E(e,t,n=new Set){let r=t.map(()=>`?`).join(`, `);return e.prepare(`SELECT name, sql FROM sqlite_schema
|
|
113
|
+
WHERE tbl_name IN (${r}) AND type IN ('index', 'trigger') AND sql IS NOT NULL`).all(...t).filter(e=>!n.has(e.name))}function D(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function*O(e,t,n){let r=n.join(`, `),i=e.prepare(`SELECT * FROM ${t} ORDER BY ${r} LIMIT 100`),a=e.prepare(`SELECT * FROM ${t} WHERE (${r}) > (${n.map(()=>`?`).join(`, `)}) ORDER BY ${r} LIMIT 100`),o=i.all();for(;o.length>0;){yield*o;let e=n.map(e=>o[o.length-1][e]);o=[],o=a.all(...e)}}async function k(e){let t=Date.now();await S(e.filename,async n=>{if(C(n,1,`migrateSQLiteCoreV1ToV2`),w(n,`collaboration_units`,[`unit_id`,`type`,`head_revision`,`soft_deleted_at_ms`]),w(n,`collaboration_unit_tombstones`,[`unit_id`]),w(n,`collaboration_snapshots`,[`unit_id`]),w(n,`collaboration_changesets`,[`unit_id`,`revision`,`payload_json`]),w(n,`collaboration_sheet_blocks`,[`unit_id`]),n.prepare(`PRAGMA table_info(collaboration_units)`).all().length!==4)throw new u.CollabError(`INVALID_REQUEST`,`Core v1 Unit columns differ from the supported schema; refusing a potentially lossy migration`);let r=A(n),i=E(n,[`collaboration_units`]);n.exec(`CREATE TABLE collaboration_units_v2 (
|
|
110
114
|
unit_id TEXT PRIMARY KEY,
|
|
111
115
|
type INTEGER NOT NULL,
|
|
112
116
|
head_revision INTEGER NOT NULL CHECK (head_revision >= 1),
|
|
113
117
|
creator_id TEXT NOT NULL,
|
|
114
118
|
created_at_ms INTEGER NOT NULL,
|
|
115
119
|
soft_deleted_at_ms INTEGER
|
|
116
|
-
);`);let a=n.prepare(`INSERT INTO collaboration_units_v2 VALUES (?, ?, ?, ?, ?, ?)`);for(let i of
|
|
120
|
+
);`);let a=n.prepare(`INSERT INTO collaboration_units_v2 VALUES (?, ?, ?, ?, ?, ?)`);for(let i of O(n,`collaboration_units`,[`unit_id`])){let n=i.unit_id,o=e.resolveUnitCreation?void 0:r(n,1),s=e.resolveUnitCreation?await e.resolveUnitCreation(n):{creatorID:o?.user_id||`anonymous`,createdAt:D(o?.committed_at)?o.committed_at:t};if(!s||typeof s.creatorID!=`string`||s.creatorID.length===0||!D(s.createdAt))throw new u.CollabError(`INVALID_REQUEST`,`Missing or invalid creation facts for Unit ${n}`);a.run(n,i.type,i.head_revision,s.creatorID,s.createdAt,i.soft_deleted_at_ms)}n.exec(`DROP TABLE collaboration_units; ALTER TABLE collaboration_units_v2 RENAME TO collaboration_units;`);for(let e of i)n.exec(e.sql);let o=n.prepare(`PRAGMA table_info(collaboration_changesets)`).all();if(o.some(e=>e.name===`created_at_ms`))throw new u.CollabError(`INVALID_REQUEST`,`Unexpected changeset creation-time column in legacy schema`);let s=n.prepare(`SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = 'collaboration_changesets'`).get(),c=E(n,[`collaboration_changesets`]);n.exec(`CREATE TABLE collaboration_changesets_v2 (
|
|
117
121
|
created_at_ms INTEGER NOT NULL,
|
|
118
122
|
${s.sql.slice(s.sql.indexOf(`(`)+1)}`);let l=o.map(e=>`"${e.name.replaceAll(`"`,`""`)}"`).join(`, `),d=n.prepare(`INSERT INTO collaboration_changesets_v2 (${l}, created_at_ms)
|
|
119
|
-
VALUES (${o.map(()=>`?`).join(`, `)}, ?)`);for(let i of
|
|
123
|
+
VALUES (${o.map(()=>`?`).join(`, `)}, ?)`);for(let i of O(n,`collaboration_changesets`,[`unit_id`,`revision`])){let n=i.unit_id,a=i.revision,s=JSON.parse(i.payload_json),c=typeof s.createTime==`number`?s.createTime*1e3:void 0,l=!e.resolveChangesetCreatedAt&&!D(c)?r(n,a)?.committed_at:void 0,f=e.resolveChangesetCreatedAt?await e.resolveChangesetCreatedAt(n,a):D(c)?c:D(l)?l:t;if(!D(f))throw new u.CollabError(`INVALID_REQUEST`,`Missing or invalid changeset time for Unit ${n} revision ${a}`);s.createTime=Math.floor(f/1e3),d.run(...o.map(e=>e.name===`payload_json`?JSON.stringify(s):i[e.name]),f)}n.exec(`DROP TABLE collaboration_changesets; ALTER TABLE collaboration_changesets_v2 RENAME TO collaboration_changesets;`);for(let e of c)n.exec(e.sql);T(n,2)})}function A(e){let t=e.prepare(`SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = 'collaboration_history_revisions'`).get()?e.prepare(`SELECT user_id, committed_at FROM collaboration_history_revisions WHERE unit_id = ? AND revision = ?`):void 0;return(e,n)=>t?.get(e,n)}var j=`
|
|
124
|
+
CREATE TABLE collaboration_units (
|
|
125
|
+
unit_id TEXT PRIMARY KEY NOT NULL,
|
|
126
|
+
type INTEGER NOT NULL,
|
|
127
|
+
head_revision INTEGER NOT NULL CHECK (head_revision >= 1),
|
|
128
|
+
creator_id TEXT NOT NULL,
|
|
129
|
+
created_at_ms INTEGER NOT NULL,
|
|
130
|
+
deleted_at_ms INTEGER,
|
|
131
|
+
deleted_status TEXT CHECK (deleted_status IN ('soft', 'hard')),
|
|
132
|
+
CHECK ((deleted_status IS NULL) = (deleted_at_ms IS NULL))
|
|
133
|
+
);
|
|
134
|
+
CREATE TABLE collaboration_snapshots (
|
|
135
|
+
unit_id TEXT NOT NULL REFERENCES collaboration_units(unit_id) ON DELETE CASCADE,
|
|
136
|
+
revision INTEGER NOT NULL CHECK (revision >= 1),
|
|
137
|
+
payload BLOB NOT NULL,
|
|
138
|
+
PRIMARY KEY (unit_id, revision)
|
|
139
|
+
);
|
|
140
|
+
CREATE TABLE collaboration_changesets (
|
|
141
|
+
unit_id TEXT NOT NULL REFERENCES collaboration_units(unit_id) ON DELETE CASCADE,
|
|
142
|
+
revision INTEGER NOT NULL CHECK (revision >= 2),
|
|
143
|
+
base_revision INTEGER NOT NULL CHECK (base_revision >= 1),
|
|
144
|
+
sid TEXT NOT NULL,
|
|
145
|
+
req_id INTEGER NOT NULL CHECK (req_id >= 1),
|
|
146
|
+
created_at_ms INTEGER NOT NULL,
|
|
147
|
+
payload BLOB NOT NULL,
|
|
148
|
+
PRIMARY KEY (unit_id, revision),
|
|
149
|
+
UNIQUE (unit_id, sid, req_id)
|
|
150
|
+
);
|
|
151
|
+
CREATE TABLE collaboration_sheet_blocks (
|
|
152
|
+
unit_id TEXT NOT NULL REFERENCES collaboration_units(unit_id) ON DELETE CASCADE,
|
|
153
|
+
block_id TEXT NOT NULL,
|
|
154
|
+
payload BLOB NOT NULL,
|
|
155
|
+
PRIMARY KEY (unit_id, block_id)
|
|
156
|
+
);
|
|
157
|
+
`,M=[`collaboration_units`,`collaboration_snapshots`,`collaboration_changesets`,`collaboration_sheet_blocks`],N=new Set([`collaboration_snapshots_nearest_revision`,`collaboration_changesets_revision_range`]),P=`__univerCollaborationBinary`;async function F(e){await S(e.filename,e=>{C(e,2,`migrateSQLiteCoreV2ToV3`),w(e,`collaboration_units`,[`unit_id`,`type`,`head_revision`,`creator_id`,`created_at_ms`,`soft_deleted_at_ms`]),w(e,`collaboration_unit_tombstones`,[`unit_id`,`purged_at`]),w(e,`collaboration_snapshots`,[`unit_id`,`revision`,`payload_json`]),w(e,`collaboration_changesets`,[`unit_id`,`revision`,`base_revision`,`sid`,`req_id`,`created_at_ms`,`payload_json`]),w(e,`collaboration_sheet_blocks`,[`unit_id`,`block_id`,`payload_json`]);let t=E(e,M,N);for(let t of M)e.exec(`ALTER TABLE ${t} RENAME TO ${t}_v2;`);e.exec(j),e.exec(`
|
|
120
158
|
INSERT INTO collaboration_units
|
|
121
159
|
(unit_id, type, head_revision, creator_id, created_at_ms, deleted_at_ms, deleted_status)
|
|
122
160
|
SELECT unit_id, type, head_revision, creator_id, created_at_ms, soft_deleted_at_ms,
|
|
@@ -127,4 +165,9 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
|
|
|
127
165
|
(unit_id, type, head_revision, creator_id, created_at_ms, deleted_at_ms, deleted_status)
|
|
128
166
|
SELECT unit_id, ${p.UniverType.UNIVER_SHEET}, 1, 'anonymous', purged_at, purged_at, 'hard'
|
|
129
167
|
FROM collaboration_unit_tombstones;
|
|
130
|
-
`);let n=new c.Encoder({ignoreUndefined:!0}),r=e=>{let t=n.encode(
|
|
168
|
+
`);let n=new c.Encoder({ignoreUndefined:!0}),r=e=>{let t=n.encode(L(e));return f.Buffer.from(t.buffer,t.byteOffset,t.byteLength)};I(e,`collaboration_snapshots`,[`unit_id`,`revision`],r),I(e,`collaboration_changesets`,[`unit_id`,`revision`,`base_revision`,`sid`,`req_id`,`created_at_ms`],r),I(e,`collaboration_sheet_blocks`,[`unit_id`,`block_id`],r);for(let t of M)e.exec(`DROP TABLE ${t}_v2;`);e.exec(`DROP TABLE collaboration_unit_tombstones;`);for(let n of t)e.exec(n.sql);T(e,3)})}function I(e,t,n,r){let i=e.prepare(`INSERT INTO ${t} (${n.join(`, `)}, payload) VALUES (${n.map(()=>`?`).join(`, `)}, ?)`);for(let a of O(e,`${t}_v2`,n.slice(0,2)))i.run(...n.map(e=>a[e]),r(a.payload_json))}function L(e){return JSON.parse(e,(e,t)=>typeof t==`object`&&t&&Object.keys(t).length===1&&typeof t[P]==`string`?Uint8Array.from(f.Buffer.from(t[P],`base64`)):t)}async function R(e){await S(e.filename,e=>{C(e,3,`Metadata migration`),w(e,`collaboration_units`,[`unit_id`,`head_revision`,`deleted_status`]),w(e,`collaboration_changesets`,[`unit_id`,`revision`,`payload`]),e.exec(`
|
|
169
|
+
ALTER TABLE collaboration_units ADD COLUMN metadata TEXT NOT NULL DEFAULT '{}'
|
|
170
|
+
CHECK (json_valid(metadata));
|
|
171
|
+
ALTER TABLE collaboration_changesets ADD COLUMN metadata TEXT NOT NULL DEFAULT '{}'
|
|
172
|
+
CHECK (json_valid(metadata));
|
|
173
|
+
`),T(e,4)})}var z=[k,F,R];async function B(e){let t=V(e.filename);if(t===4)return{from:t,to:t};if(t>4)throw new u.CollabError(`INVALID_REQUEST`,`Core schema version ${t} is newer than this package supports (4)`);let n=e.backupFilename??`${e.filename}.v${t}.backup`;H(e.filename,n);for(let n of z.slice(t-1))await n(e);return{from:t,to:4,backupFilename:n}}function V(e){let t=new l.default(e,{fileMustExist:!0});try{let e=t.prepare(`SELECT version FROM collaboration_schema_versions WHERE component = 'core'`).get();if(!e||!Number.isInteger(e.version)||e.version<1)throw new u.CollabError(`INVALID_REQUEST`,`The database has no core schema version to migrate from`);return e.version}catch(e){throw e instanceof u.CollabError?e:new u.CollabError(`INVALID_REQUEST`,`The database has no core schema version to migrate from`)}finally{t.close()}}function H(e,t){if((0,d.existsSync)(t))throw new u.CollabError(`INVALID_REQUEST`,`Backup target already exists: ${t}`);let n=new l.default(e,{fileMustExist:!0});try{n.prepare(`VACUUM INTO ?`).run(t)}finally{n.close()}}exports.SQLiteDatabaseAdapter=_,exports.migrateSQLiteCore=B,exports.migrateSQLiteCoreV1ToV2=k,exports.migrateSQLiteCoreV2ToV3=F,exports.migrateSQLiteCoreV3ToV4=R;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CommitChangesetInput, CommitChangesetResult, CreateUnitDatabaseInput, CreateUnitDatabaseResult, DatabaseContext, DeleteUnitsDatabaseInput, DeleteUnitsDatabaseResult, IDatabaseAdapter, RecoverUnitsDatabaseInput, RecoverUnitsDatabaseResult, SaveSnapshotInput, SnapshotInfo, SubmitDatabaseContext, UnitRecord } from "@univerjs-pro/collaboration-service";
|
|
2
|
-
import {
|
|
1
|
+
import { ChangesetRecord, CommitChangesetInput, CommitChangesetResult, CreateUnitDatabaseInput, CreateUnitDatabaseResult, DatabaseContext, DeleteUnitsDatabaseInput, DeleteUnitsDatabaseResult, IDatabaseAdapter, RecoverUnitsDatabaseInput, RecoverUnitsDatabaseResult, SaveSnapshotInput, SnapshotInfo, SubmitDatabaseContext, UnitRecord } from "@univerjs-pro/collaboration-service";
|
|
2
|
+
import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/sqlite-database-adapter.d.ts
|
|
5
5
|
interface SQLiteDatabaseAdapterOptions {
|
|
6
6
|
/** SQLite filename or `:memory:`. The parent directory must already exist. */
|
|
7
7
|
readonly filename: string;
|
|
@@ -30,9 +30,9 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
|
|
|
30
30
|
private readonly _getSheetBlock;
|
|
31
31
|
private readonly _insertUnit;
|
|
32
32
|
private readonly _insertChangeset;
|
|
33
|
-
private readonly
|
|
33
|
+
private readonly _updateUnitHeadAndMetadata;
|
|
34
34
|
private readonly _upsertSnapshot;
|
|
35
|
-
private readonly
|
|
35
|
+
private readonly _insertSheetBlock;
|
|
36
36
|
private readonly _deleteSnapshots;
|
|
37
37
|
private readonly _deleteChangesets;
|
|
38
38
|
private readonly _deleteSheetBlocks;
|
|
@@ -45,7 +45,7 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
|
|
|
45
45
|
getSnapshot(_ctx: DatabaseContext, unitID: string, options?: {
|
|
46
46
|
readonly revision?: number;
|
|
47
47
|
}): Promise<ISnapshot | null>;
|
|
48
|
-
/** Reads
|
|
48
|
+
/** Reads snapshot info with the same selection rules as getSnapshot, without decoding the payload. */
|
|
49
49
|
getSnapshotInfo(_ctx: DatabaseContext, unitID: string, options?: {
|
|
50
50
|
readonly revision?: number;
|
|
51
51
|
}): Promise<SnapshotInfo | null>;
|
|
@@ -53,7 +53,7 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
|
|
|
53
53
|
getChangesets(_ctx: DatabaseContext, unitID: string, range: {
|
|
54
54
|
readonly from: number;
|
|
55
55
|
readonly to?: number;
|
|
56
|
-
}): Promise<readonly
|
|
56
|
+
}): Promise<readonly ChangesetRecord[] | null>;
|
|
57
57
|
getSheetBlock(_ctx: DatabaseContext, unitID: string, blockID: string): Promise<ISheetBlock | null>;
|
|
58
58
|
/** Atomically creates a Unit at revision 1 with its snapshot and blocks; an existing active Unit returns its record. */
|
|
59
59
|
createUnit(_ctx: DatabaseContext, input: CreateUnitDatabaseInput): Promise<CreateUnitDatabaseResult>;
|
|
@@ -76,9 +76,8 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
|
|
|
76
76
|
private _encode;
|
|
77
77
|
private _encodeBlocks;
|
|
78
78
|
private _decode;
|
|
79
|
+
private _decodeChangeset;
|
|
79
80
|
}
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/migrations/v1-to-v2.d.ts
|
|
82
81
|
interface SQLiteCoreV1ToV2MigrationOptions {
|
|
83
82
|
readonly filename: string;
|
|
84
83
|
/** Override default History lookup and fallback for every Unit, including soft-deleted Units. */
|
|
@@ -92,8 +91,6 @@ interface SQLiteCoreV1ToV2MigrationOptions {
|
|
|
92
91
|
* must not write to this database.
|
|
93
92
|
*/
|
|
94
93
|
declare function migrateSQLiteCoreV1ToV2(options: SQLiteCoreV1ToV2MigrationOptions): Promise<void>;
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/migrations/migrate.d.ts
|
|
97
94
|
interface SQLiteCoreMigrationOptions extends SQLiteCoreV1ToV2MigrationOptions {
|
|
98
95
|
/** Where the backup is written before any change. Defaults to `<filename>.v<from>.backup`. */
|
|
99
96
|
readonly backupFilename?: string;
|
|
@@ -112,8 +109,6 @@ interface SQLiteCoreMigrationResult {
|
|
|
112
109
|
* complete version, so the call can be repeated after the cause is fixed. Stop writers before calling.
|
|
113
110
|
*/
|
|
114
111
|
declare function migrateSQLiteCore(options: SQLiteCoreMigrationOptions): Promise<SQLiteCoreMigrationResult>;
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/migrations/v2-to-v3.d.ts
|
|
117
112
|
interface SQLiteCoreV2ToV3MigrationOptions {
|
|
118
113
|
readonly filename: string;
|
|
119
114
|
}
|
|
@@ -123,5 +118,12 @@ interface SQLiteCoreV2ToV3MigrationOptions {
|
|
|
123
118
|
* table. Stop writers before calling.
|
|
124
119
|
*/
|
|
125
120
|
declare function migrateSQLiteCoreV2ToV3(options: SQLiteCoreV2ToV3MigrationOptions): Promise<void>;
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Atomically upgrades core schema v3 to v4, adding empty Unit and changeset metadata.
|
|
123
|
+
* Requires schema v3. Stop writers and back up the database before calling; this step does not create a backup.
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
declare function migrateSQLiteCoreV3ToV4(options: {
|
|
127
|
+
readonly filename: string;
|
|
128
|
+
}): Promise<void>;
|
|
129
|
+
export { type SQLiteCoreMigrationOptions, type SQLiteCoreMigrationResult, type SQLiteCoreV1ToV2MigrationOptions, type SQLiteCoreV2ToV3MigrationOptions, SQLiteDatabaseAdapter, type SQLiteDatabaseAdapterOptions, migrateSQLiteCore, migrateSQLiteCoreV1ToV2, migrateSQLiteCoreV2ToV3, migrateSQLiteCoreV3ToV4 };
|
package/dist/index.mjs
CHANGED
|
@@ -3,4 +3,5 @@ const facadeExport0 = cjsModule["SQLiteDatabaseAdapter"];
|
|
|
3
3
|
const facadeExport1 = cjsModule["migrateSQLiteCore"];
|
|
4
4
|
const facadeExport2 = cjsModule["migrateSQLiteCoreV1ToV2"];
|
|
5
5
|
const facadeExport3 = cjsModule["migrateSQLiteCoreV2ToV3"];
|
|
6
|
-
|
|
6
|
+
const facadeExport4 = cjsModule["migrateSQLiteCoreV3ToV4"];
|
|
7
|
+
export { facadeExport0 as SQLiteDatabaseAdapter, facadeExport1 as migrateSQLiteCore, facadeExport2 as migrateSQLiteCoreV1ToV2, facadeExport3 as migrateSQLiteCoreV2ToV3, facadeExport4 as migrateSQLiteCoreV3ToV4 };
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=22"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.6.0",
|
|
15
15
|
"main": "./dist/index.cjs",
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"libsql": "^0.5.29"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@univerjs-pro/collaboration-service": "1.
|
|
34
|
-
"@univerjs/protocol": "1.
|
|
33
|
+
"@univerjs-pro/collaboration-service": "1.6.0",
|
|
34
|
+
"@univerjs/protocol": "1.6.0"
|
|
35
35
|
}
|
|
36
36
|
}
|