@univerjs-pro/collaboration-history-database-sqlite 1.0.0-insiders.20260808-70eefdd → 1.0.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 ADDED
@@ -0,0 +1,46 @@
1
+ # @univerjs-pro/collaboration-history-database-sqlite
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ A persistent SQLite `IHistoryDatabaseAdapter` for `@univerjs-pro/collaboration-history-service`. It supports Node.js 22 and later and can share a database file with Core, Comment, and Worktree.
6
+
7
+ ## Installation and usage
8
+
9
+ ```bash
10
+ pnpm add \
11
+ @univerjs-pro/collaboration-history-service \
12
+ @univerjs-pro/collaboration-history-database-sqlite
13
+ ```
14
+
15
+ ```ts
16
+ import { UniverHistoryService } from '@univerjs-pro/collaboration-history-service';
17
+ import { SQLiteHistoryDatabaseAdapter } from '@univerjs-pro/collaboration-history-database-sqlite';
18
+
19
+ const historyDatabase = new SQLiteHistoryDatabaseAdapter({
20
+ filename: './data/collaboration.sqlite',
21
+ busyTimeoutMs: 5_000,
22
+ });
23
+ const historyService = new UniverHistoryService({
24
+ collabService,
25
+ dbAdapter: historyDatabase,
26
+ });
27
+
28
+ await historyService.dispose();
29
+ await historyDatabase.dispose();
30
+ ```
31
+
32
+ The caller must create the database parent directory in advance and dispose the Adapter after stopping the Service.
33
+
34
+ Empty databases are initialized automatically. The application coordinates History cleanup when permanently deleting a Unit.
35
+
36
+ ## Migration from v1 to v2
37
+
38
+ Migrate a v1 database before opening it with this Adapter. Stop writers and back up the database, then run:
39
+
40
+ ```ts
41
+ import { migrateSQLiteHistoryV1ToV2 } from '@univerjs-pro/collaboration-history-database-sqlite';
42
+
43
+ await migrateSQLiteHistoryV1ToV2({ filename: './data/collaboration.sqlite' });
44
+ ```
45
+
46
+ Migrate older Core and Worktree schemas in the same file first. The migration preserves existing History and rolls back on failure. Restore the backup to downgrade.
@@ -0,0 +1,49 @@
1
+ # @univerjs-pro/collaboration-history-database-sqlite
2
+
3
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
4
+
5
+ 面向 `@univerjs-pro/collaboration-history-service` 的持久化 SQLite
6
+ `IHistoryDatabaseAdapter`。支持 Node.js 22 及以上,可与 Core、Comment 和 Worktree
7
+ 共用一个数据库文件。
8
+
9
+ ## 安装与使用
10
+
11
+ ```bash
12
+ pnpm add \
13
+ @univerjs-pro/collaboration-history-service \
14
+ @univerjs-pro/collaboration-history-database-sqlite
15
+ ```
16
+
17
+ ```ts
18
+ import { UniverHistoryService } from '@univerjs-pro/collaboration-history-service';
19
+ import { SQLiteHistoryDatabaseAdapter } from '@univerjs-pro/collaboration-history-database-sqlite';
20
+
21
+ const historyDatabase = new SQLiteHistoryDatabaseAdapter({
22
+ filename: './data/collaboration.sqlite',
23
+ busyTimeoutMs: 5_000,
24
+ });
25
+ const historyService = new UniverHistoryService({
26
+ collabService,
27
+ dbAdapter: historyDatabase,
28
+ });
29
+
30
+ await historyService.dispose();
31
+ await historyDatabase.dispose();
32
+ ```
33
+
34
+ 调用方必须预先创建数据库父目录,并在 Service 停止后释放 Adapter。
35
+
36
+ 空库自动初始化。永久删除 Unit 时,由应用协调清理 History 数据。
37
+
38
+ ## v1 → v2 迁移
39
+
40
+ 使用此 Adapter 打开 v1 数据库前需先迁移。停止写入并备份后执行:
41
+
42
+ ```ts
43
+ import { migrateSQLiteHistoryV1ToV2 } from '@univerjs-pro/collaboration-history-database-sqlite';
44
+
45
+ await migrateSQLiteHistoryV1ToV2({ filename: './data/collaboration.sqlite' });
46
+ ```
47
+
48
+ 同文件中的旧版 Core 和 Worktree 应先完成迁移。迁移保留已有历史,失败时整体回滚。
49
+ 降级需恢复备份。
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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=(_0x6e8ccd,_0x5b6dc1,_0x41881d,_0x2e3ef1)=>{if(_0x5b6dc1&&typeof _0x5b6dc1=='object'||typeof _0x5b6dc1=='function'){for(var _0x3d9579=r(_0x5b6dc1),_0x277fac=0x0,_0xc93cf0=_0x3d9579['length'],_0xc017b1;_0x277fac<_0xc93cf0;_0x277fac++)_0xc017b1=_0x3d9579[_0x277fac],!a['call'](_0x6e8ccd,_0xc017b1)&&_0xc017b1!==_0x41881d&&t(_0x6e8ccd,_0xc017b1,{'get':(_0x5f3000=>_0x5b6dc1[_0x5f3000])['bind'](null,_0xc017b1),'enumerable':!(_0x2e3ef1=n(_0x5b6dc1,_0xc017b1))||_0x2e3ef1['enumerable']});}return _0x6e8ccd;},s=(_0xaa3d47,_0x522b24,_0xa28ce5)=>(_0xa28ce5=_0xaa3d47==null?{}:e(i(_0xaa3d47)),o(_0x522b24||!_0xaa3d47||!_0xaa3d47['__esModule']?t(_0xa28ce5,'default',{'value':_0xaa3d47,'enumerable':!0x0}):_0xa28ce5,_0xaa3d47));let c=require('libsql');c=s(c,0x1);let l=require('@univerjs-pro/collaboration-history-service');var u=0x1388,d='history',f=0x1,p=['collaboration_history_revisions'],m=class{['_database'];['_disposed']=!0x1;constructor(_0x475755){g(_0x475755),this['_database']=new c['default'](_0x475755['filename'],{'timeout':_0x475755['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x475755['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x439e6a){throw this['_database']['close'](),_0x439e6a;}}async['getIndexState'](_0x1060f9){this['_assertOpen']();let _0x35a041=this['_latestEntry'](_0x1060f9);if(!_0x35a041)return null;let _0x505b01=this['_getEntry'](_0x1060f9,_0x35a041['historyRevision']);if(!_0x505b01)throw Error('SQLite\x20History\x20contains\x20an\x20invalid\x20history\x20revision');return{'unitID':_0x1060f9,'type':_0x35a041['type'],'latestRevision':_0x35a041['revision'],'currentHistoryRevision':_0x35a041['historyRevision'],'currentHistoryCreatedAt':_0x505b01['committedAt'],'forceNextHistory':_0x35a041['forceNextHistory']};}async['getRevision'](_0xc7e069,_0x291e3e){return this['_assertOpen'](),this['_getEntry'](_0xc7e069,_0x291e3e);}async['appendRevision'](_0x599731,_0x9e6765){return this['_assertOpen'](),v(_0x599731),this['_transaction'](()=>{if(this['_getEntry'](_0x599731['unitID'],_0x599731['revision']))return{'status':'already-indexed'};let _0x3f1f64=this['_database']['prepare']('SELECT\x20revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20revision\x20DESC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201')['get'](_0x599731['unitID'])?.['revision']??0x0;return _0x3f1f64!==_0x9e6765['expectedLatestRevision']||_0x599731['revision']!==_0x3f1f64+0x1?{'status':'revision-conflict','actualLatestRevision':_0x3f1f64}:(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20type,\x20revision,\x20user_id,\x20commands_json,\x20committed_at,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20additional_fields,\x20origin,\x20history_revision,\x20force_next_history,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20restored_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x599731['unitID'],_0x599731['type'],_0x599731['revision'],_0x599731['userId'],JSON['stringify'](_0x599731['commands']),_0x599731['committedAt'],_0x599731['additionalFields']??null,_0x599731['origin'],_0x599731['historyRevision'],+!!_0x599731['forceNextHistory'],_0x599731['restoredRevision']??null),{'status':'appended'});});}async['listRecords'](_0x4f450c,_0x215f31){return this['_assertOpen'](),(0x0,l['selectHistoryRecords'])((0x0,l['buildHistoryRecords'])(this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20revision,\x20user_id,\x20commands_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20committed_at,\x20additional_fields,\x20origin,\x20history_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20force_next_history,\x20restored_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20revision\x20ASC')['all'](_0x4f450c)['map'](h)),_0x215f31);}async['listCreators'](_0xb85971){this['_assertOpen']();let _0x1cc2d6=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20revision,\x20user_id,\x20commands_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20committed_at,\x20additional_fields,\x20origin,\x20history_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20force_next_history,\x20restored_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20revision\x20ASC')['all'](_0xb85971)['map'](h),_0xca0a5e=new Map();for(let _0x3170d6 of _0x1cc2d6){let _0x149795=_0xca0a5e['get'](_0x3170d6['userId'])??new Set();_0x149795['add'](_0x3170d6['origin']),_0xca0a5e['set'](_0x3170d6['userId'],_0x149795);}return[..._0xca0a5e]['map'](([_0x50b5bf,_0x449c9d])=>({'userId':_0x50b5bf,'origins':[..._0x449c9d]}));}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyOwnedTable']())throw _('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x20\x20\x20\x20\x20\x20\x20\x20');}let _0x54d7ff=this['_database']['prepare']('SELECT\x20version\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_schema_versions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20component\x20=\x20?')['get'](d);if(_0x54d7ff){if(_0x54d7ff['version']!==f)throw _('SQLite\x20History\x20schema\x20version\x20'+_0x54d7ff['version']+'\x20is\x20not\x20supported');let _0x1e55aa=p['filter'](_0x325c36=>!this['_hasTable'](_0x325c36));if(_0x1e55aa['length']>0x0)throw _('SQLite\x20History\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x1e55aa['join'](',\x20'));return;}if(this['_hasAnyOwnedTable']())throw _('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_history_revisions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20commands_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20committed_at\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(committed_at\x20>=\x200),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20additional_fields\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20origin\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20history_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(history_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20force_next_history\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20restored_revision\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_history_record_lookup\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_history_revisions(unit_id,\x20history_revision\x20DESC);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_history_creator_lookup\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_history_revisions(unit_id,\x20user_id);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(\x27history\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_hasTable'](_0x50ce2c){return!!this['_database']['prepare']('SELECT\x201\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20sqlite_schema\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x50ce2c);}['_hasAnyOwnedTable'](){return p['some'](_0x530ea8=>this['_hasTable'](_0x530ea8));}['_latestEntry'](_0x2f8fcf){let _0x58b7b6=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20revision,\x20user_id,\x20commands_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20committed_at,\x20additional_fields,\x20origin,\x20history_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20force_next_history,\x20restored_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20revision\x20DESC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201')['get'](_0x2f8fcf);return _0x58b7b6?h(_0x58b7b6):null;}['_getEntry'](_0x2d4cac,_0x1b4d2c){let _0x270118=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20revision,\x20user_id,\x20commands_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20committed_at,\x20additional_fields,\x20origin,\x20history_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20force_next_history,\x20restored_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?')['get'](_0x2d4cac,_0x1b4d2c);return _0x270118?h(_0x270118):null;}['_transaction'](_0x154bb5){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x4707ab=_0x154bb5();return this['_database']['exec']('COMMIT;'),_0x4707ab;}catch(_0x431479){try{this['_database']['exec']('ROLLBACK;');}catch{}throw _0x431479;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20History\x20Database\x20Adapter\x20is\x20disposed');}};function h(_0x1051d5){let _0x1f5603=JSON['parse'](_0x1051d5['commands_json']);if(!Array['isArray'](_0x1f5603)||_0x1f5603['some'](_0x5d63fb=>typeof _0x5d63fb!='string'))throw Error('SQLite\x20History\x20contains\x20invalid\x20commands');if(_0x1051d5['origin']!==0x0&&_0x1051d5['origin']!==0x1&&_0x1051d5['origin']!==0x2)throw Error('SQLite\x20History\x20contains\x20an\x20invalid\x20origin');return{'unitID':_0x1051d5['unit_id'],'type':_0x1051d5['type'],'revision':_0x1051d5['revision'],'userId':_0x1051d5['user_id'],'commands':_0x1f5603,'committedAt':_0x1051d5['committed_at'],..._0x1051d5['additional_fields']===null?{}:{'additionalFields':_0x1051d5['additional_fields']},'origin':_0x1051d5['origin'],'historyRevision':_0x1051d5['history_revision'],'forceNextHistory':_0x1051d5['force_next_history']===0x1,..._0x1051d5['restored_revision']===null?{}:{'restoredRevision':_0x1051d5['restored_revision']}};}function g(_0x21cf54){if(!_0x21cf54?.['filename'])throw TypeError('SQLiteHistoryDatabaseAdapter\x20requires\x20a\x20filename');if(_0x21cf54['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x21cf54['busyTimeoutMs'])||_0x21cf54['busyTimeoutMs']<0x0))throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');}function _(_0x1d7d14){return Error(_0x1d7d14);}function v(_0x524e6e){if(!_0x524e6e['unitID']||!_0x524e6e['userId']||!Number['isSafeInteger'](_0x524e6e['revision'])||_0x524e6e['revision']<0x1||!Number['isSafeInteger'](_0x524e6e['historyRevision'])||_0x524e6e['historyRevision']<0x1||_0x524e6e['historyRevision']>_0x524e6e['revision']||!Number['isSafeInteger'](_0x524e6e['committedAt'])||_0x524e6e['committedAt']<0x0)throw TypeError('History\x20revision\x20entry\x20is\x20invalid');}exports['SQLiteHistoryDatabaseAdapter']=m;
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=(_0x5c5c98,_0x2a8eb4,_0x1fac07,_0x24e209)=>{if(_0x2a8eb4&&typeof _0x2a8eb4=='object'||typeof _0x2a8eb4=='function'){for(var _0x124413=r(_0x2a8eb4),_0x490834=0x0,_0x36e239=_0x124413['length'],_0x1ef2a3;_0x490834<_0x36e239;_0x490834++)_0x1ef2a3=_0x124413[_0x490834],!a['call'](_0x5c5c98,_0x1ef2a3)&&_0x1ef2a3!==_0x1fac07&&t(_0x5c5c98,_0x1ef2a3,{'get':(_0x44a387=>_0x2a8eb4[_0x44a387])['bind'](null,_0x1ef2a3),'enumerable':!(_0x24e209=n(_0x2a8eb4,_0x1ef2a3))||_0x24e209['enumerable']});}return _0x5c5c98;},s=(_0x5c12cf,_0x4cc6e8,_0x5f424e)=>(_0x5f424e=_0x5c12cf==null?{}:e(i(_0x5c12cf)),o(_0x4cc6e8||!_0x5c12cf||!_0x5c12cf['__esModule']?t(_0x5f424e,'default',{'value':_0x5c12cf,'enumerable':!0x0}):_0x5f424e,_0x5c12cf));let c=require('libsql');c=s(c,0x1);var l='\x0a\x20\x20CREATE\x20TABLE\x20collaboration_history_records\x20(\x0a\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20start_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(start_revision\x20>=\x201),\x0a\x20\x20\x20\x20user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(created_at_ms\x20>=\x200),\x0a\x20\x20\x20\x20origin\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20additional_fields\x20TEXT,\x0a\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20start_revision)\x0a\x20\x20);\x0a',u='\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_origin_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20origin,\x20start_revision);\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_creator_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20user_id,\x20start_revision);\x0a',d=class{['_database'];['_disposed']=!0x1;constructor(_0x435963){if(!_0x435963?.['filename'])throw TypeError('SQLiteHistoryDatabaseAdapter\x20requires\x20a\x20filename');let _0xd21118=_0x435963['busyTimeoutMs']??0x1388;if(!Number['isSafeInteger'](_0xd21118)||_0xd21118<0x0)throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');this['_database']=new c['default'](_0x435963['filename'],{'timeout':_0xd21118});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+_0xd21118+';'),this['_initializeSchema']();}catch(_0x6fb5a){throw this['_database']['close'](),_0x6fb5a;}}async['getLatestRecord'](_0x263965,_0x155d04){this['_assertOpen']();let _0x3c9a89=this['_latest'](_0x155d04);return _0x3c9a89?f(_0x3c9a89):null;}async['appendRecord'](_0x47225c,_0x2a2973,_0x36d1bc){if(this['_assertOpen'](),!_0x2a2973['unitID']||!_0x2a2973['userID']||!Number['isSafeInteger'](_0x2a2973['startRevision'])||_0x2a2973['startRevision']<0x1||!Number['isSafeInteger'](_0x2a2973['createdAt'])||_0x2a2973['createdAt']<0x0)throw TypeError('History\x20record\x20is\x20invalid');return this['_transaction'](()=>{let _0x112fa0=this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20=\x20?')['get'](_0x2a2973['unitID'],_0x2a2973['startRevision']);if(_0x112fa0)return{'status':_0x112fa0['user_id']===_0x2a2973['userID']&&_0x112fa0['created_at_ms']===_0x2a2973['createdAt']&&_0x112fa0['origin']===_0x2a2973['origin']&&_0x112fa0['additional_fields']===(_0x2a2973['additionalFields']??null)?'already-exists':'conflict'};let _0x883779=this['_latest'](_0x2a2973['unitID'])?.['start_revision']??null;return _0x883779!==_0x36d1bc['expectedLatestStartRevision']||_0x2a2973['startRevision']<=(_0x883779??0x0)?{'status':'conflict'}:(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x2a2973['unitID'],_0x2a2973['startRevision'],_0x2a2973['userID'],_0x2a2973['createdAt'],_0x2a2973['origin'],_0x2a2973['additionalFields']??null),{'status':'appended'});});}async['listRecords'](_0x230b9c,_0x1b9588,_0x9df6b9){this['_assertOpen']();let _0x55aba0=[_0x9df6b9['throughRevision'],_0x9df6b9['throughRevision'],_0x1b9588,_0x9df6b9['throughRevision']],_0x3d423b=[];_0x9df6b9['beforeRevision']!==void 0x0&&(_0x3d423b['push']('r.start_revision\x20<\x20?'),_0x55aba0['push'](_0x9df6b9['beforeRevision'])),_0x9df6b9['origin']&&(_0x3d423b['push']('r.origin\x20=\x20?'),_0x55aba0['push'](_0x9df6b9['origin'])),_0x9df6b9['userIDs']?.['length']&&(_0x3d423b['push']('r.user_id\x20IN\x20('+_0x9df6b9['userIDs']['map'](()=>'?')['join'](',\x20')+')'),_0x55aba0['push'](..._0x9df6b9['userIDs'])),_0x55aba0['push'](_0x9df6b9['length']+0x1);let _0x2c9f20=this['_database']['prepare']('\x0a\x20\x20\x20\x20\x20\x20SELECT\x20r.*,\x20MIN(?,\x20COALESCE((\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20next.start_revision\x20-\x201\x20FROM\x20collaboration_history_records\x20AS\x20next\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20next.unit_id\x20=\x20r.unit_id\x20AND\x20next.start_revision\x20>\x20r.start_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20next.start_revision\x20ASC\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20),\x20?))\x20AS\x20end_revision\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_records\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.unit_id\x20=\x20?\x20AND\x20r.start_revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20'+(_0x3d423b['length']?'AND\x20'+_0x3d423b['join']('\x20AND\x20'):'')+'\x0a\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20r.start_revision\x20DESC\x20LIMIT\x20?\x0a\x20\x20\x20\x20')['all'](..._0x55aba0);return{'records':_0x2c9f20['slice'](0x0,_0x9df6b9['length'])['map'](_0x14da22=>({'record':f(_0x14da22),'endRevision':_0x14da22['end_revision']})),'hasMore':_0x2c9f20['length']>_0x9df6b9['length']};}async['listCreators'](_0x4eafca,_0x586dcf,_0x170e56){this['_assertOpen']();let _0x50059d=this['_database']['prepare']('SELECT\x20DISTINCT\x20user_id,\x20origin\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20<=\x20?\x20ORDER\x20BY\x20user_id,\x20origin')['all'](_0x586dcf,_0x170e56['throughRevision']),_0x4dd603=new Map();for(let _0xebd329 of _0x50059d){let _0x41728a=_0x4dd603['get'](_0xebd329['user_id'])??[];_0x41728a['push'](_0xebd329['origin']),_0x4dd603['set'](_0xebd329['user_id'],_0x41728a);}return[..._0x4dd603]['map'](([_0x19c877,_0x2a32c9])=>({'userID':_0x19c877,'origins':_0x2a32c9}));}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_latest'](_0xf1b300){return this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20ORDER\x20BY\x20start_revision\x20DESC\x20LIMIT\x201')['get'](_0xf1b300);}['_initializeSchema'](){this['_transaction'](()=>{let _0x24efa7=_0x1d1c97=>!!this['_database']['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x1d1c97),_0x55a263=_0x24efa7('collaboration_history_revisions')||_0x24efa7('collaboration_history_records');if(!_0x24efa7('collaboration_schema_versions')){if(_0x55a263)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201));');}let _0x56af2f=this['_database']['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']();if(_0x56af2f){if(_0x56af2f['version']===0x1)throw Error('SQLite\x20History\x20schema\x20v1\x20requires\x20migrateSQLiteHistoryV1ToV2\x20before\x20opening\x20the\x20Adapter');if(_0x56af2f['version']!==0x2)throw Error('SQLite\x20History\x20schema\x20version\x20'+_0x56af2f['version']+'\x20is\x20not\x20supported');if(!_0x24efa7('collaboration_history_records'))throw Error('SQLite\x20History\x20schema\x20v2\x20is\x20incomplete');this['_database']['prepare']('SELECT\x20unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20additional_fields\x20FROM\x20collaboration_history_records\x20LIMIT\x200')['all']();return;}if(_0x55a263)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec'](l+u+'INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x20VALUES\x20(\x27history\x27,\x202);');});}['_transaction'](_0x530bf1){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x54963a=_0x530bf1();return this['_database']['exec']('COMMIT;'),_0x54963a;}catch(_0x26c23c){throw this['_database']['exec']('ROLLBACK;'),_0x26c23c;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20History\x20Database\x20Adapter\x20is\x20disposed');}};function f(_0x3524ac){return{'unitID':_0x3524ac['unit_id'],'startRevision':_0x3524ac['start_revision'],'userID':_0x3524ac['user_id'],'createdAt':_0x3524ac['created_at_ms'],'origin':_0x3524ac['origin'],..._0x3524ac['additional_fields']===null?{}:{'additionalFields':_0x3524ac['additional_fields']}};}async function p(_0x2c535a){let _0x539834=new c['default'](_0x2c535a['filename'],{'fileMustExist':!0x0}),_0x19af82=!0x1;try{if(_0x539834['exec']('BEGIN\x20IMMEDIATE;'),_0x19af82=!0x0,_0x539834['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']()?.['version']!==0x1)throw Error('History\x20v1-to-v2\x20migration\x20requires\x20schema\x20version\x201');if(_0x539834['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27core\x27')['get']()?.['version']===0x1)throw Error('Migrate\x20SQLite\x20Core\x20v1\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');let _0x7780f4=_0x539834['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27worktree\x27')['get']();if(_0x7780f4&&_0x7780f4['version']<0x3)throw Error('Migrate\x20SQLite\x20Worktree\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');if(_0x539834['prepare']('SELECT\x201\x20FROM\x20collaboration_history_revisions\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_history_revisions\x20AS\x20first\x0a\x20\x20\x20\x20\x20\x20\x20\x20ON\x20first.unit_id\x20=\x20r.unit_id\x20AND\x20first.revision\x20=\x20r.history_revision\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.history_revision\x20>\x20r.revision\x20OR\x20first.revision\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.history_revision\x20!=\x20first.revision\x20OR\x20first.user_id\x20=\x20\x27\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20typeof(first.committed_at)\x20!=\x20\x27integer\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.committed_at\x20<\x200\x20OR\x20first.committed_at\x20>\x209007199254740991\x0a\x20\x20\x20\x20\x20\x20LIMIT\x201')['get']())throw Error('History\x20v1\x20contains\x20a\x20missing\x20or\x20invalid\x20segment\x20starting\x20revision');_0x539834['exec'](l),_0x539834['exec']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20SELECT\x20unit_id,\x20revision,\x20user_id,\x20committed_at,\x20origin,\x20additional_fields\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x20WHERE\x20revision\x20=\x20history_revision;\x0a\x20\x20\x20\x20\x20\x20DROP\x20TABLE\x20collaboration_history_revisions;'),_0x539834['exec'](u),_0x539834['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27history\x27;\x20COMMIT;'),_0x19af82=!0x1;}finally{try{_0x19af82&&_0x539834['exec']('ROLLBACK;');}finally{_0x539834['close']();}}}exports['SQLiteHistoryDatabaseAdapter']=d,exports['migrateSQLiteHistoryV1ToV2']=p;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppendHistoryRevisionResult, HistoryCreatorIndex, HistoryIndexState, HistoryRevision, IHistoryDatabaseAdapter, ListHistoryRecordsOptions, ListHistoryRecordsResult } from "@univerjs-pro/collaboration-history-service";
1
+ import { AppendHistoryRecordResult, HistoryCreatorIndex, HistoryDatabaseContext, HistoryRecord, IHistoryDatabaseAdapter, ListHistoryRecordsOptions, ListHistoryRecordsResult } from "@univerjs-pro/collaboration-history-service";
2
2
 
3
3
  //#region src/sqlite-history-database-adapter.d.ts
4
4
  interface SQLiteHistoryDatabaseAdapterOptions {
@@ -9,21 +9,25 @@ declare class SQLiteHistoryDatabaseAdapter implements IHistoryDatabaseAdapter {
9
9
  private readonly _database;
10
10
  private _disposed;
11
11
  constructor(options: SQLiteHistoryDatabaseAdapterOptions);
12
- getIndexState(unitID: string): Promise<HistoryIndexState | null>;
13
- getRevision(unitID: string, revision: number): Promise<HistoryRevision | null>;
14
- appendRevision(entry: HistoryRevision, options: {
15
- readonly expectedLatestRevision: number;
16
- }): Promise<AppendHistoryRevisionResult>;
17
- listRecords(unitID: string, options: ListHistoryRecordsOptions): Promise<ListHistoryRecordsResult>;
18
- listCreators(unitID: string): Promise<readonly HistoryCreatorIndex[]>;
12
+ getLatestRecord(_context: HistoryDatabaseContext, unitID: string): Promise<HistoryRecord | null>;
13
+ appendRecord(_context: HistoryDatabaseContext, record: HistoryRecord, options: {
14
+ readonly expectedLatestStartRevision: number | null;
15
+ }): Promise<AppendHistoryRecordResult>;
16
+ listRecords(_context: HistoryDatabaseContext, unitID: string, options: ListHistoryRecordsOptions): Promise<ListHistoryRecordsResult>;
17
+ listCreators(_context: HistoryDatabaseContext, unitID: string, options: {
18
+ readonly throughRevision: number;
19
+ }): Promise<readonly HistoryCreatorIndex[]>;
19
20
  dispose(): Promise<void>;
21
+ private _latest;
20
22
  private _initializeSchema;
21
- private _hasTable;
22
- private _hasAnyOwnedTable;
23
- private _latestEntry;
24
- private _getEntry;
25
23
  private _transaction;
26
24
  private _assertOpen;
27
25
  }
28
26
  //#endregion
29
- export { SQLiteHistoryDatabaseAdapter, type SQLiteHistoryDatabaseAdapterOptions };
27
+ //#region src/migrations/v1-to-v2.d.ts
28
+ interface SQLiteHistoryV1ToV2MigrationOptions {
29
+ readonly filename: string;
30
+ }
31
+ declare function migrateSQLiteHistoryV1ToV2(options: SQLiteHistoryV1ToV2MigrationOptions): Promise<void>;
32
+ //#endregion
33
+ export { SQLiteHistoryDatabaseAdapter, type SQLiteHistoryDatabaseAdapterOptions, type SQLiteHistoryV1ToV2MigrationOptions, migrateSQLiteHistoryV1ToV2 };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- function _0x1784(_0x5bdb6c,_0x4e44c7){_0x5bdb6c=_0x5bdb6c-0x76;const _0x5a34c4=_0x5a34();let _0x1784df=_0x5a34c4[_0x5bdb6c];return _0x1784df;}function _0x5a34(){const _0x92c820=['166WBmeiy','8LOdJqx','857465vohJnU','1659812dwlmOu','363472pvQIda','7332lpYxyW','3134637wSvhPK','4868465xuGekT','2907504ypYsPX'];_0x5a34=function(){return _0x92c820;};return _0x5a34();}(function(_0x2ba6da,_0xab06ed){const _0x18ef1e=_0x1784,_0x438ae6=_0x2ba6da();while(!![]){try{const _0xb62bd2=parseInt(_0x18ef1e(0x77))/0x1+-parseInt(_0x18ef1e(0x7c))/0x2*(parseInt(_0x18ef1e(0x78))/0x3)+-parseInt(_0x18ef1e(0x76))/0x4+-parseInt(_0x18ef1e(0x7e))/0x5+parseInt(_0x18ef1e(0x7b))/0x6+parseInt(_0x18ef1e(0x7a))/0x7*(parseInt(_0x18ef1e(0x7d))/0x8)+-parseInt(_0x18ef1e(0x79))/0x9;if(_0xb62bd2===_0xab06ed)break;else _0x438ae6['push'](_0x438ae6['shift']());}catch(_0x16f6d0){_0x438ae6['push'](_0x438ae6['shift']());}}}(_0x5a34,0x631c8));import _0x2a8746 from'./index.cjs';const facadeExport0=_0x2a8746['SQLiteHistoryDatabaseAdapter'];export{facadeExport0 as SQLiteHistoryDatabaseAdapter};
1
+ function _0x445e(_0x3673b4,_0x259c96){_0x3673b4=_0x3673b4-0x1cb;const _0x25f29c=_0x25f2();let _0x445e9c=_0x25f29c[_0x3673b4];return _0x445e9c;}const _0x1f4761=_0x445e;(function(_0x4bca63,_0x5b9849){const _0x43d4b1=_0x445e,_0x3976fd=_0x4bca63();while(!![]){try{const _0x5746d3=-parseInt(_0x43d4b1(0x1d3))/0x1*(parseInt(_0x43d4b1(0x1d1))/0x2)+parseInt(_0x43d4b1(0x1cd))/0x3*(parseInt(_0x43d4b1(0x1d0))/0x4)+-parseInt(_0x43d4b1(0x1cc))/0x5+-parseInt(_0x43d4b1(0x1d5))/0x6+-parseInt(_0x43d4b1(0x1d7))/0x7*(-parseInt(_0x43d4b1(0x1cb))/0x8)+parseInt(_0x43d4b1(0x1d2))/0x9*(-parseInt(_0x43d4b1(0x1d6))/0xa)+-parseInt(_0x43d4b1(0x1cf))/0xb*(-parseInt(_0x43d4b1(0x1ce))/0xc);if(_0x5746d3===_0x5b9849)break;else _0x3976fd['push'](_0x3976fd['shift']());}catch(_0x49d454){_0x3976fd['push'](_0x3976fd['shift']());}}}(_0x25f2,0x3816d));import _0x3b3e4f from'./index.cjs';const facadeExport0=_0x3b3e4f['SQLiteHistoryDatabaseAdapter'],facadeExport1=_0x3b3e4f[_0x1f4761(0x1d4)];export{facadeExport0 as SQLiteHistoryDatabaseAdapter,facadeExport1 as migrateSQLiteHistoryV1ToV2};function _0x25f2(){const _0x26c6af=['10cTHuaU','1015049NCJHEZ','16nGpxjm','1813280xhWOnG','3JIghdB','12yynvrc','11216843tHPKUN','263052AauAui','860014LRCNhP','514854bcsPYS','1xSUWBK','migrateSQLiteHistoryV1ToV2','1775280iwclSG'];_0x25f2=function(){return _0x26c6af;};return _0x25f2();}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
7
- "version": "1.0.0-insiders.20260808-70eefdd",
7
+ "version": "1.0.0",
8
8
  "main": "./dist/index.cjs",
9
9
  "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
@@ -19,11 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@univerjs-pro/collaboration-history-service": "1.0.0-insiders.20260808-70eefdd",
23
- "@univerjs/protocol": "1.0.0-insiders.20260808-70eefdd",
22
+ "@univerjs-pro/collaboration-history-service": "1.0.0",
23
+ "@univerjs/protocol": "1.0.0",
24
24
  "libsql": "^0.5.29"
25
- },
26
- "publishConfig": {
27
- "access": "public"
28
25
  }
29
- }
26
+ }