@univerjs-pro/collaboration-worktree-database-sqlite 1.0.0-insiders.20260805-b15e7f3 → 1.0.0-rc.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 +50 -0
- package/README.zh-CN.md +47 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +1 -1
- package/package.json +5 -8
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-worktree-database-sqlite
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A persistent SQLite `IWorktreeDatabaseAdapter` for `@univerjs-pro/collaboration-worktree-service`. It uses the stable synchronous `libsql` API and supports Node.js 22 and later.
|
|
6
|
+
|
|
7
|
+
## Installation and usage
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add \
|
|
11
|
+
@univerjs-pro/collaboration-worktree-service \
|
|
12
|
+
@univerjs-pro/collaboration-worktree-database-sqlite
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const worktreeDatabase = new SQLiteWorktreeDatabaseAdapter({
|
|
17
|
+
filename: './data/collaboration.sqlite',
|
|
18
|
+
busyTimeoutMs: 5_000,
|
|
19
|
+
});
|
|
20
|
+
const worktreeService = new UniverCollabWorktreeService({
|
|
21
|
+
trunk: {
|
|
22
|
+
service: collabService,
|
|
23
|
+
dbAdapter: trunkDatabase,
|
|
24
|
+
},
|
|
25
|
+
dbAdapter: worktreeDatabase,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
await worktreeService.dispose();
|
|
29
|
+
await worktreeDatabase.dispose();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The caller must create the database parent directory in advance and dispose the Adapter after stopping Worktree Service.
|
|
33
|
+
|
|
34
|
+
## Storage contract
|
|
35
|
+
|
|
36
|
+
- Tables use the `collaboration_worktree_*` prefix.
|
|
37
|
+
- Schema version `('worktree', 2)` is stored in shared `collaboration_schema_versions`; `PRAGMA user_version` is not used.
|
|
38
|
+
- Draft-changeset scalar columns and the submission unique constraint provide database-level integrity, while commits use revision CAS and do not query the submission key.
|
|
39
|
+
- It can share a database file with trunk, Comment, and History SQLite Adapters.
|
|
40
|
+
- State transitions, draft CAS, and merge results use SQLite transactions for atomicity.
|
|
41
|
+
- An empty Worktree schema is initialized automatically. Incomplete or unsupported schemas are rejected.
|
|
42
|
+
|
|
43
|
+
Worktree Adapter does not own trunk collaboration data and does not manage Worktree names, list discovery, ACLs, or product-resource extension data for the application.
|
|
44
|
+
|
|
45
|
+
Schema v1 upgrades transactionally to v2 by adding a removal flag, defaulting
|
|
46
|
+
to false for all existing Units. Draft changesets, merge artifacts, and pending
|
|
47
|
+
merge results are preserved. Stop old writers and back up the database before
|
|
48
|
+
upgrading; older Adapters reject v2. Restarting v2 does not rerun the migration.
|
|
49
|
+
Removal updates and draft commits share the Adapter transaction boundary, so a
|
|
50
|
+
commit cannot succeed after removal has been persisted.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-worktree-database-sqlite
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
面向 `@univerjs-pro/collaboration-worktree-service` 的持久化 SQLite
|
|
6
|
+
`IWorktreeDatabaseAdapter`。它使用稳定的 `libsql` 同步接口,支持 Node.js 22 及以上。
|
|
7
|
+
|
|
8
|
+
## 安装与使用
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add \
|
|
12
|
+
@univerjs-pro/collaboration-worktree-service \
|
|
13
|
+
@univerjs-pro/collaboration-worktree-database-sqlite
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
const worktreeDatabase = new SQLiteWorktreeDatabaseAdapter({
|
|
18
|
+
filename: './data/collaboration.sqlite',
|
|
19
|
+
busyTimeoutMs: 5_000,
|
|
20
|
+
});
|
|
21
|
+
const worktreeService = new UniverCollabWorktreeService({
|
|
22
|
+
trunk: {
|
|
23
|
+
service: collabService,
|
|
24
|
+
dbAdapter: trunkDatabase,
|
|
25
|
+
},
|
|
26
|
+
dbAdapter: worktreeDatabase,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await worktreeService.dispose();
|
|
30
|
+
await worktreeDatabase.dispose();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
调用方必须预先创建数据库父目录,并在 Worktree Service 停止后释放 Adapter。
|
|
34
|
+
|
|
35
|
+
## 存储契约
|
|
36
|
+
|
|
37
|
+
- 表使用 `collaboration_worktree_*` 前缀。
|
|
38
|
+
- schema 版本 `('worktree', 1)` 记录在共享的
|
|
39
|
+
`collaboration_schema_versions`,不占用 `PRAGMA user_version`。
|
|
40
|
+
- draft changeset 标量列和 submission unique constraint 提供数据库级完整性;提交只做
|
|
41
|
+
revision CAS,不按 submission key 点查。
|
|
42
|
+
- 可以与 trunk、Comment 和 History SQLite Adapter 共用一个数据库文件。
|
|
43
|
+
- 状态转换、draft CAS 和 merge result 使用 SQLite transaction 保证原子契约。
|
|
44
|
+
- 空 Worktree schema 自动初始化;不完整或不支持的 schema 会被拒绝。
|
|
45
|
+
|
|
46
|
+
Worktree Adapter 不拥有 trunk 协同数据,也不替应用管理 Worktree 名称、列表发现、ACL 或
|
|
47
|
+
产品资源扩展数据。
|
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=(_0x5a1770,_0x575092,_0x3dccf7,_0x3f3b3b)=>{if(_0x575092&&typeof _0x575092=='object'||typeof _0x575092=='function'){for(var _0x35404=r(_0x575092),_0x2eaebc=0x0,_0x3f6035=_0x35404['length'],_0x1342e4;_0x2eaebc<_0x3f6035;_0x2eaebc++)_0x1342e4=_0x35404[_0x2eaebc],!a['call'](_0x5a1770,_0x1342e4)&&_0x1342e4!==_0x3dccf7&&t(_0x5a1770,_0x1342e4,{'get':(_0xf67f6b=>_0x575092[_0xf67f6b])['bind'](null,_0x1342e4),'enumerable':!(_0x3f3b3b=n(_0x575092,_0x1342e4))||_0x3f3b3b['enumerable']});}return _0x5a1770;},s=(_0x372fb5,_0x27e1a1,_0x581e43)=>(_0x581e43=_0x372fb5==null?{}:e(i(_0x372fb5)),o(_0x27e1a1||!_0x372fb5||!_0x372fb5['__esModule']?t(_0x581e43,'default',{'value':_0x372fb5,'enumerable':!0x0}):_0x581e43,_0x372fb5));let c=require('node:util'),l=require('libsql');l=s(l,0x1);let u=require('@univerjs-pro/collaboration-service'),d=require('@univerjs/protocol');var f='worktree',p=0x1,m=['collaboration_worktrees','collaboration_worktree_units','collaboration_worktree_changesets','collaboration_worktree_unit_seeds','collaboration_worktree_unit_merge_artifacts'],h=0x1388,g='__univerCollaborationBinary',_=new Set([d['UniverType']['UNIVER_SHEET'],d['UniverType']['UNIVER_DOC'],d['UniverType']['UNIVER_SLIDE'],d['UniverType']['UNIVER_BOARD'],d['UniverType']['UNIVER_BASE']]),v=class{['_database'];['_disposed']=!0x1;constructor(_0x5a1c96){b(_0x5a1c96),this['_database']=new l['default'](_0x5a1c96['filename'],{'timeout':_0x5a1c96['busyTimeoutMs']??h});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x5a1c96['busyTimeoutMs']??h)+';'),this['_initializeSchema']();}catch(_0x51e109){throw this['_database']['close'](),_0x51e109;}}async['getWorktree'](_0x3f563b,_0x18310e){return this['_assertOpen'](),this['_getAggregate'](_0x18310e);}async['getWorktreeUnit'](_0x3245de,_0x518fcc,_0x1aaaad){this['_assertOpen']();let _0x51f547=this['_getUnitRow'](_0x518fcc,_0x1aaaad);return _0x51f547?y(_0x51f547):null;}async['getDraftChangesets'](_0x3a6f68,_0x1ea03c,_0x39b8e9,_0x42f3f7){this['_assertOpen'](),D(_0x42f3f7);let _0x37a95a=this['_getUnitRow'](_0x1ea03c,_0x39b8e9);if(!_0x37a95a)return{'changesets':[],'latestRevision':0x0};let _0xda14ba=_0x42f3f7['to']===0x0?_0x37a95a['draft_head_revision']:Math['min'](_0x42f3f7['to'],_0x37a95a['draft_head_revision']);return{'changesets':this['_database']['prepare']('SELECT\x20payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20revision\x20>\x20?\x20AND\x20revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20revision\x20ASC')['all'](_0x1ea03c,_0x39b8e9,_0x42f3f7['from'],_0xda14ba)['map'](({payload_json:_0xd19701})=>L(_0xd19701)),'latestRevision':_0x37a95a['draft_head_revision']};}async['getDraftSubmission'](_0x1edd82,_0x387257,_0x16471f,_0x30a920,_0x3c4c1e){this['_assertOpen']();let _0x3bd677=this['_database']['prepare']('SELECT\x20payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?\x20AND\x20sid\x20=\x20?\x20AND\x20req_id\x20=\x20?')['get'](_0x387257,_0x16471f,_0x30a920,_0x3c4c1e);return _0x3bd677?L(_0x3bd677['payload_json']):null;}async['getUnitSeed'](_0x469d01,_0x568ffb,_0x31d971){return this['_assertOpen'](),this['_getUnitSeed'](_0x568ffb,_0x31d971);}async['getUnitMergeArtifact'](_0x4ab0e5,_0x1ac1f0,_0x2d5c66){return this['_assertOpen'](),this['_getUnitMergeArtifact'](_0x1ac1f0,_0x2d5c66);}async['createWorktree'](_0x45745c,_0x260abc){return this['_assertOpen'](),x(_0x260abc),this['_transaction'](()=>{let _0x36391c=this['_getAggregate'](_0x260abc['record']['worktreeID']);if(_0x36391c)return{'status':'already-exists','aggregate':_0x36391c};this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktrees\x20(worktree_id,\x20sid,\x20status)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20\x27draft\x27)')['run'](_0x260abc['record']['worktreeID'],_0x260abc['record']['sid']);let _0x37abb3=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27trunk\x27,\x20?,\x20?)');return _0x260abc['units']['forEach']((_0x4a1241,_0x5929c3)=>{_0x37abb3['run'](_0x4a1241['worktreeID'],_0x4a1241['unitID'],_0x5929c3,_0x4a1241['type'],_0x4a1241['baselineTrunkRevision'],_0x4a1241['draftHeadRevision']);}),{'status':'created','aggregate':this['_requireAggregate'](_0x260abc['record']['worktreeID'])};});}async['addUnit'](_0x83c785,_0x53d026){return this['_assertOpen'](),w(_0x53d026['unit']),this['_transaction'](()=>{let {unit:_0x6561c0}=_0x53d026,_0x264f94=this['_getWorktreeRow'](_0x6561c0['worktreeID']);if(!_0x264f94)return{'status':'not-found'};if(this['_getUnitRow'](_0x6561c0['worktreeID'],_0x6561c0['unitID']))return{'status':'already-exists','aggregate':this['_requireAggregate'](_0x6561c0['worktreeID'])};if(_0x264f94['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x6561c0['worktreeID'])};S(_0x6561c0);let _0x352ccf=this['_database']['prepare']('SELECT\x20COALESCE(MAX(unit_order),\x20-1)\x20+\x201\x20AS\x20next_order\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0x6561c0['worktreeID']);return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27trunk\x27,\x20?,\x20?)')['run'](_0x6561c0['worktreeID'],_0x6561c0['unitID'],_0x352ccf['next_order'],_0x6561c0['type'],_0x6561c0['baselineTrunkRevision'],_0x6561c0['draftHeadRevision']),{'status':'added','aggregate':this['_requireAggregate'](_0x6561c0['worktreeID'])};});}async['createUnit'](_0x10f454,_0x4385c2){return this['_assertOpen'](),C(_0x4385c2['unit'],_0x4385c2['seed']),this['_transaction'](()=>{let {unit:_0x2fc903,seed:_0x4e3e0b}=_0x4385c2,_0x272b4f=this['_getWorktreeRow'](_0x2fc903['worktreeID']);if(!_0x272b4f)return{'status':'not-found'};let _0x285508=this['_getUnitRow'](_0x2fc903['worktreeID'],_0x2fc903['unitID']);if(_0x285508){let _0x1907e3=this['_getUnitSeed'](_0x2fc903['worktreeID'],_0x2fc903['unitID']);return{'status':_0x285508['source']==='worktree'&&_0x285508['type']===_0x2fc903['type']&&_0x1907e3!==null&&I(_0x1907e3)===I(_0x4e3e0b)?'already-created':'unit-exists','aggregate':this['_requireAggregate'](_0x2fc903['worktreeID'])};}if(_0x272b4f['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x2fc903['worktreeID'])};let _0x2d64c8=this['_database']['prepare']('SELECT\x20COALESCE(MAX(unit_order),\x20-1)\x20+\x201\x20AS\x20next_order\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0x2fc903['worktreeID']);return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27worktree\x27,\x201,\x201)')['run'](_0x2fc903['worktreeID'],_0x2fc903['unitID'],_0x2d64c8['next_order'],_0x2fc903['type']),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_unit_seeds\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20snapshot_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json,\x20resources_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x2fc903['worktreeID'],_0x2fc903['unitID'],I(_0x4e3e0b['snapshot']),_0x4e3e0b['sheetBlocks']===void 0x0?null:I(_0x4e3e0b['sheetBlocks']),_0x4e3e0b['resources']===void 0x0?null:I(_0x4e3e0b['resources'])),{'status':'created','aggregate':this['_requireAggregate'](_0x2fc903['worktreeID'])};});}async['saveUnitMergeArtifact'](_0x260027,_0x3bd78b){return this['_assertOpen'](),this['_transaction'](()=>{let _0x394ab5=this['_getWorktreeRow'](_0x3bd78b['worktreeID']),_0x560577=this['_getUnitRow'](_0x3bd78b['worktreeID'],_0x3bd78b['unitID']);if(!_0x394ab5||!_0x560577)return{'status':'not-found'};let _0x56fe38=y(_0x560577);if(_0x394ab5['status']!=='merging'||_0x56fe38['source']!=='worktree'||_0x56fe38['readyDraftHeadRevision']!==_0x3bd78b['artifact']['readyDraftHeadRevision']||A(_0x56fe38))return{'status':'stale-merge'};let _0x5b46f1=this['_getUnitMergeArtifact'](_0x3bd78b['worktreeID'],_0x3bd78b['unitID']);return _0x5b46f1?{'status':'already-saved','artifact':_0x5b46f1}:(k(_0x56fe38,_0x3bd78b['artifact']),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20snapshot_json,\x20sheet_blocks_json,\x20resources_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x3bd78b['worktreeID'],_0x3bd78b['unitID'],_0x3bd78b['artifact']['readyDraftHeadRevision'],I(_0x3bd78b['artifact']['unit']['snapshot']),_0x3bd78b['artifact']['unit']['sheetBlocks']===void 0x0?null:I(_0x3bd78b['artifact']['unit']['sheetBlocks']),_0x3bd78b['artifact']['unit']['resources']===void 0x0?null:I(_0x3bd78b['artifact']['unit']['resources'])),{'status':'saved','artifact':L(I(_0x3bd78b['artifact']))});});}async['commitDraftChangeset'](_0x2aa794,_0x1758f2){return this['_assertOpen'](),T(_0x1758f2['changeset']),this['_transaction'](()=>{let {worktreeID:_0x594e00,expectedHeadRevision:_0x4ce7a0,changeset:_0x33a9d4}=_0x1758f2,_0x1937e1=this['_database']['prepare']('SELECT\x20payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?\x20AND\x20sid\x20=\x20?\x20AND\x20req_id\x20=\x20?')['get'](_0x594e00,_0x33a9d4['unitID'],_0x33a9d4['sid'],_0x33a9d4['reqId']);if(_0x1937e1)return{'status':'already-committed','changeset':L(_0x1937e1['payload_json'])};let _0x2ebe4d=this['_getWorktreeRow'](_0x594e00),_0x2cd9b1=this['_getUnitRow'](_0x594e00,_0x33a9d4['unitID']);if(!_0x2ebe4d||!_0x2cd9b1)return{'status':'not-found'};if(_0x2ebe4d['status']!=='draft')return{'status':'not-editable','worktreeStatus':M(_0x2ebe4d['status'])};let _0x269218=y(_0x2cd9b1);if(A(_0x269218))return{'status':'unit-frozen'};if(_0x269218['draftHeadRevision']!==_0x4ce7a0)return{'status':'revision-mismatch','actualHeadRevision':_0x269218['draftHeadRevision']};if(E(_0x269218,_0x1758f2),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20revision,\x20base_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid,\x20req_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x594e00,_0x33a9d4['unitID'],_0x33a9d4['revision'],_0x33a9d4['baseRev'],_0x33a9d4['sid'],_0x33a9d4['reqId'],I(_0x33a9d4)),this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20draft_head_revision\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20draft_head_revision\x20=\x20?')['run'](_0x33a9d4['revision'],_0x594e00,_0x33a9d4['unitID'],_0x4ce7a0)['changes']!==0x1)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20draft\x20head\x20changed\x20inside\x20a\x20write\x20transaction');return{'status':'committed','changeset':L(I(_0x33a9d4)),'headRevision':_0x33a9d4['revision']};});}async['markReady'](_0x68e9cc,_0xd9c609){return this['_assertOpen'](),this['_transaction'](()=>{let _0x29cc13=this['_getWorktreeRow'](_0xd9c609);if(!_0x29cc13)return{'status':'not-found'};if(_0x29cc13['status']==='ready')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0xd9c609)};if(_0x29cc13['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0xd9c609)};for(let _0x3613cf of this['_getUnitRows'](_0xd9c609))A(y(_0x3613cf))||(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20ready_draft_head_revision\x20=\x20draft_head_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0xd9c609,_0x3613cf['unit_id']),this['_database']['prepare']('DELETE\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0xd9c609,_0x3613cf['unit_id']));return this['_updateStatus'](_0xd9c609,'ready'),{'status':'transitioned','previousStatus':'draft','aggregate':this['_requireAggregate'](_0xd9c609)};});}async['reopenWorktree'](_0x126fa6,_0x25fb44){return this['_assertOpen'](),this['_transaction'](()=>{let _0x4f5990=this['_getWorktreeRow'](_0x25fb44);if(!_0x4f5990)return{'status':'not-found'};if(_0x4f5990['status']==='draft')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x25fb44)};if(_0x4f5990['status']!=='ready')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x25fb44)};for(let _0x34699d of this['_getUnitRows'](_0x25fb44))A(y(_0x34699d))||(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20ready_draft_head_revision\x20=\x20NULL,\x20merge_result_json\x20=\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x25fb44,_0x34699d['unit_id']),this['_database']['prepare']('DELETE\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x25fb44,_0x34699d['unit_id']));return this['_updateStatus'](_0x25fb44,'draft'),{'status':'transitioned','previousStatus':'ready','aggregate':this['_requireAggregate'](_0x25fb44)};});}async['discardWorktree'](_0xd70b82,_0x290bca){return this['_assertOpen'](),this['_transaction'](()=>{let _0x476937=this['_getWorktreeRow'](_0x290bca);if(!_0x476937)return{'status':'not-found'};if(_0x476937['status']==='discarded')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x290bca)};if(_0x476937['status']!=='draft'&&_0x476937['status']!=='ready')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x290bca)};let _0x481948=M(_0x476937['status']);return this['_updateStatus'](_0x290bca,'discarded'),{'status':'transitioned','previousStatus':_0x481948,'aggregate':this['_requireAggregate'](_0x290bca)};});}async['startOrResumeMerge'](_0x3f12b8,_0x2e31d2){return this['_assertOpen'](),this['_transaction'](()=>{let _0x3a3327=this['_getWorktreeRow'](_0x2e31d2);return _0x3a3327?_0x3a3327['status']==='merged'?{'status':'already-merged','aggregate':this['_requireAggregate'](_0x2e31d2)}:_0x3a3327['status']==='merging'?{'status':'resumed','aggregate':this['_requireAggregate'](_0x2e31d2)}:_0x3a3327['status']==='ready'?(this['_updateStatus'](_0x2e31d2,'merging'),{'status':'started','aggregate':this['_requireAggregate'](_0x2e31d2)}):{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x2e31d2)}:{'status':'not-found'};});}async['recordUnitMergeResult'](_0x356142,_0xeb4b1e){return this['_assertOpen'](),O(_0xeb4b1e['mergeResult']),this['_transaction'](()=>{let _0x1ea498=this['_getWorktreeRow'](_0xeb4b1e['worktreeID']),_0x3f042d=this['_getUnitRow'](_0xeb4b1e['worktreeID'],_0xeb4b1e['unitID']);if(!_0x1ea498||!_0x3f042d)return{'status':'not-found'};let _0x57579c=y(_0x3f042d);if(_0x1ea498['status']!=='merging'||_0x57579c['readyDraftHeadRevision']!==_0xeb4b1e['readyDraftHeadRevision'])return{'status':'stale-merge'};let _0x3832c5=_0x57579c['mergeResult'];return _0x3832c5&&(0x0,c['isDeepStrictEqual'])(_0x3832c5,_0xeb4b1e['mergeResult'])?{'status':'already-recorded','aggregate':this['_requireAggregate'](_0xeb4b1e['worktreeID'])}:_0x3832c5&&j(_0x3832c5)?{'status':'stale-merge'}:(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20merge_result_json\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](I(_0xeb4b1e['mergeResult']),_0xeb4b1e['worktreeID'],_0xeb4b1e['unitID']),{'status':'recorded','aggregate':this['_requireAggregate'](_0xeb4b1e['worktreeID'])});});}async['finishMerge'](_0xe67232,_0x443d4b){return this['_assertOpen'](),this['_transaction'](()=>{let _0xc235da=this['_getWorktreeRow'](_0x443d4b);if(!_0xc235da)return{'status':'not-found'};if(_0xc235da['status']==='merged')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x443d4b)};if(_0xc235da['status']!=='merging')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x443d4b)};let _0xc4e7c4=this['_getUnitRows'](_0x443d4b)['every'](_0x1692ba=>A(y(_0x1692ba)));return this['_updateStatus'](_0x443d4b,_0xc4e7c4?'merged':'ready'),{'status':'transitioned','previousStatus':'merging','aggregate':this['_requireAggregate'](_0x443d4b)};});}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyOwnedTable']())throw F('SQLite\x20Worktree\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 _0x14c9ed=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'](f);if(_0x14c9ed){if(_0x14c9ed['version']!==p)throw F('SQLite\x20Worktree\x20schema\x20version\x20'+_0x14c9ed['version']+'\x20is\x20not\x20supported');let _0x1cca2c=m['filter'](_0x3badb8=>!this['_hasTable'](_0x3badb8));if(_0x1cca2c['length']>0x0)throw F('SQLite\x20Worktree\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x1cca2c['join'](',\x20'));return;}if(this['_hasAnyOwnedTable']())throw F('SQLite\x20Worktree\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktrees\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20status\x20TEXT\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(status\x20IN\x20(\x27draft\x27,\x20\x27ready\x27,\x20\x27merging\x27,\x20\x27merged\x27,\x20\x27discarded\x27))\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_units\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20unit_order\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(unit_order\x20>=\x200),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20source\x20TEXT\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(source\x20IN\x20(\x27trunk\x27,\x20\x27worktree\x27)),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(baseline_trunk_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(draft_head_revision\x20>=\x20baseline_trunk_revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ready_draft_head_revision\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(worktree_id,\x20unit_order),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktrees(worktree_id)\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_changesets\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(revision\x20>=\x202),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20base_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(base_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20req_id\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(req_id\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(worktree_id,\x20unit_id,\x20sid,\x20req_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_worktree_changesets_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_worktree_changesets(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id,\x20unit_id,\x20revision\x20ASC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_unit_seeds\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20snapshot_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20resources_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_unit_merge_artifacts\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20ready_draft_head_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(ready_draft_head_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20snapshot_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20resources_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\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(\x27worktree\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_hasTable'](_0x579d27){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'](_0x579d27);}['_hasAnyOwnedTable'](){return m['some'](_0x5201f8=>this['_hasTable'](_0x5201f8));}['_getWorktreeRow'](_0x33ec37){return this['_database']['prepare']('SELECT\x20worktree_id,\x20sid,\x20status\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktrees\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0x33ec37)??null;}['_getUnitRow'](_0x52b7a8,_0x52dd62){return this['_database']['prepare']('SELECT\x20worktree_id,\x20unit_id,\x20type,\x20source,\x20baseline_trunk_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x52b7a8,_0x52dd62)??null;}['_getUnitRows'](_0x2509b6){return this['_database']['prepare']('SELECT\x20worktree_id,\x20unit_id,\x20type,\x20source,\x20baseline_trunk_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20unit_order\x20ASC')['all'](_0x2509b6);}['_getUnitSeed'](_0x45e398,_0x19358c){let _0x12ffc2=this['_database']['prepare']('SELECT\x20snapshot_json,\x20sheet_blocks_json,\x20resources_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_unit_seeds\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x45e398,_0x19358c);return _0x12ffc2?{'snapshot':L(_0x12ffc2['snapshot_json']),..._0x12ffc2['sheet_blocks_json']===null?{}:{'sheetBlocks':L(_0x12ffc2['sheet_blocks_json'])},..._0x12ffc2['resources_json']===null?{}:{'resources':L(_0x12ffc2['resources_json'])}}:null;}['_getUnitMergeArtifact'](_0x4ad4bd,_0x4fd55f){let _0x340986=this['_database']['prepare']('SELECT\x20ready_draft_head_revision,\x20snapshot_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json,\x20resources_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x4ad4bd,_0x4fd55f);return _0x340986?{'readyDraftHeadRevision':_0x340986['ready_draft_head_revision'],'unit':{'snapshot':L(_0x340986['snapshot_json']),..._0x340986['sheet_blocks_json']===null?{}:{'sheetBlocks':L(_0x340986['sheet_blocks_json'])},..._0x340986['resources_json']===null?{}:{'resources':L(_0x340986['resources_json'])}}}:null;}['_getAggregate'](_0x506d60){let _0x179ea8=this['_getWorktreeRow'](_0x506d60);return _0x179ea8?{'worktree':{'worktreeID':_0x179ea8['worktree_id'],'sid':_0x179ea8['sid'],'status':M(_0x179ea8['status'])},'units':this['_getUnitRows'](_0x506d60)['map'](y)}:null;}['_requireAggregate'](_0x10f496){let _0x5ab180=this['_getAggregate'](_0x10f496);if(!_0x5ab180)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20disappeared\x20inside\x20a\x20write\x20transaction');return _0x5ab180;}['_updateStatus'](_0x3c5815,_0x3196d8){if(this['_database']['prepare']('UPDATE\x20collaboration_worktrees\x20SET\x20status\x20=\x20?\x20WHERE\x20worktree_id\x20=\x20?')['run'](_0x3196d8,_0x3c5815)['changes']!==0x1)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20status\x20update\x20did\x20not\x20affect\x20one\x20record');}['_transaction'](_0x926ec4){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x366b4f=_0x926ec4();return this['_database']['exec']('COMMIT;'),_0x366b4f;}catch(_0x513eed){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x513eed;}}['_assertOpen'](){if(this['_disposed'])throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20Database\x20Adapter\x20is\x20disposed');}};function y(_0x1b9775){let _0x2951fd=N(_0x1b9775['source']);return{'worktreeID':_0x1b9775['worktree_id'],'unitID':_0x1b9775['unit_id'],'type':_0x1b9775['type'],'source':_0x2951fd,..._0x2951fd==='trunk'?{'baselineTrunkRevision':_0x1b9775['baseline_trunk_revision']}:{},'draftHeadRevision':_0x1b9775['draft_head_revision'],..._0x1b9775['ready_draft_head_revision']===null?{}:{'readyDraftHeadRevision':_0x1b9775['ready_draft_head_revision']},..._0x1b9775['merge_result_json']===null?{}:{'mergeResult':L(_0x1b9775['merge_result_json'])}};}function b(_0x1ce09e){if(!_0x1ce09e['filename'])throw P('SQLite\x20filename\x20is\x20required');if(_0x1ce09e['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x1ce09e['busyTimeoutMs'])||_0x1ce09e['busyTimeoutMs']<0x0))throw P('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function x(_0x2d4d0e){if(!_0x2d4d0e['record']['worktreeID']||!_0x2d4d0e['record']['sid']||_0x2d4d0e['record']['status']!=='draft')throw P('New\x20Worktree\x20must\x20be\x20a\x20draft\x20with\x20identity');let _0x2d4bec=new Set();for(let _0x94c84 of _0x2d4d0e['units']){if(_0x94c84['worktreeID']!==_0x2d4d0e['record']['worktreeID']||_0x2d4bec['has'](_0x94c84['unitID']))throw P('Initial\x20Worktree\x20Units\x20must\x20be\x20unique\x20and\x20share\x20identity');_0x2d4bec['add'](_0x94c84['unitID']),S(_0x94c84);}}function S(_0x5f528a){if(w(_0x5f528a),_0x5f528a['source']!=='trunk'||!_['has'](_0x5f528a['type'])||!Number['isSafeInteger'](_0x5f528a['baselineTrunkRevision'])||_0x5f528a['baselineTrunkRevision']<0x1||_0x5f528a['draftHeadRevision']!==_0x5f528a['baselineTrunkRevision']||_0x5f528a['readyDraftHeadRevision']!==void 0x0||_0x5f528a['mergeResult']!==void 0x0)throw P('New\x20Worktree\x20Unit\x20must\x20start\x20at\x20its\x20trunk\x20baseline');}function C(_0x48cac1,_0x389457){if(w(_0x48cac1),_0x48cac1['source']!=='worktree'||_0x48cac1['baselineTrunkRevision']!==void 0x0||!_['has'](_0x48cac1['type'])||_0x48cac1['draftHeadRevision']!==0x1||_0x48cac1['readyDraftHeadRevision']!==void 0x0||_0x48cac1['mergeResult']!==void 0x0||_0x389457['snapshot']['unitID']!==_0x48cac1['unitID']||_0x389457['snapshot']['type']!==_0x48cac1['type']||_0x389457['snapshot']['rev']!==0x1)throw P('Worktree-created\x20Unit\x20must\x20start\x20from\x20its\x20revision\x201\x20seed');}function w(_0x17257c){if(!_0x17257c['worktreeID']||!_0x17257c['unitID'])throw P('Worktree\x20and\x20Unit\x20identity\x20are\x20required');}function T(_0x157a9c){if(!_0x157a9c['sid']||!Number['isSafeInteger'](_0x157a9c['reqId'])||_0x157a9c['reqId']<0x1)throw P('Changeset\x20sid\x20and\x20positive\x20integer\x20reqId\x20are\x20required');}function E(_0x285135,_0x51a541){let {changeset:_0x41893d,expectedHeadRevision:_0x15690b}=_0x51a541;if(_0x41893d['type']!==_0x285135['type']||_0x41893d['baseRev']!==_0x15690b||_0x41893d['revision']!==_0x15690b+0x1)throw P('Draft\x20changeset\x20must\x20match\x20Unit\x20type\x20and\x20expected\x20revision');}function D(_0x5c79ff){if(!Number['isSafeInteger'](_0x5c79ff['from'])||!Number['isSafeInteger'](_0x5c79ff['to'])||_0x5c79ff['from']<0x0||_0x5c79ff['to']<0x0)throw P('Draft\x20revision\x20range\x20cannot\x20be\x20negative');}function O(_0x14636b){if(_0x14636b['status']==='merged'){if(!Number['isSafeInteger'](_0x14636b['trunkRevision'])||_0x14636b['trunkRevision']<0x1)throw P('Merged\x20result\x20requires\x20a\x20trunk\x20revision');return;}if(_0x14636b['status']!=='unchanged'&&(!_0x14636b['error']['code']||!_0x14636b['error']['message']||typeof _0x14636b['error']['retryable']!='boolean'))throw P('Merge\x20error\x20must\x20be\x20stable\x20and\x20serializable');}function k(_0x1a3f81,_0x11baa0){if(_0x11baa0['unit']['snapshot']['unitID']!==_0x1a3f81['unitID']||_0x11baa0['unit']['snapshot']['type']!==_0x1a3f81['type']||_0x11baa0['unit']['snapshot']['rev']!==0x1)throw P('Worktree\x20Unit\x20merge\x20artifact\x20must\x20be\x20a\x20revision\x201\x20snapshot');}function A(_0x5beb22){return j(_0x5beb22['mergeResult']);}function j(_0x5d6042){return _0x5d6042?.['status']==='merged'||_0x5d6042?.['status']==='unchanged';}function M(_0x2e0bf3){if(_0x2e0bf3==='draft'||_0x2e0bf3==='ready'||_0x2e0bf3==='merging'||_0x2e0bf3==='merged'||_0x2e0bf3==='discarded')return _0x2e0bf3;throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20contains\x20invalid\x20Worktree\x20status\x20'+_0x2e0bf3);}function N(_0x35fc60){if(_0x35fc60==='trunk'||_0x35fc60==='worktree')return _0x35fc60;throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20contains\x20invalid\x20Worktree\x20Unit\x20source\x20'+_0x35fc60);}function P(_0xbd3567){return new u['CollabError']('INVALID_REQUEST',_0xbd3567);}function F(_0x5ea369){return new u['CollabError']('INTERNAL_ERROR',_0x5ea369);}function I(_0x23dfe5){return JSON['stringify'](_0x23dfe5,(_0x395012,_0x3e9163)=>_0x3e9163 instanceof Uint8Array?{[g]:Buffer['from'](_0x3e9163)['toString']('base64')}:_0x3e9163);}function L(_0x1d60f8){return JSON['parse'](_0x1d60f8,(_0x266225,_0x4ee471)=>R(_0x4ee471)?Uint8Array['from'](Buffer['from'](_0x4ee471[g],'base64')):_0x4ee471);}function R(_0x29c443){return typeof _0x29c443=='object'&&!!_0x29c443&&Object['keys'](_0x29c443)['length']===0x1&&typeof _0x29c443[g]=='string';}exports['SQLiteWorktreeDatabaseAdapter']=v;
|
|
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=(_0xe17632,_0x176475,_0x55a337,_0x107690)=>{if(_0x176475&&typeof _0x176475=='object'||typeof _0x176475=='function'){for(var _0x2f516a=r(_0x176475),_0x31e505=0x0,_0x1ea650=_0x2f516a['length'],_0x3f2e66;_0x31e505<_0x1ea650;_0x31e505++)_0x3f2e66=_0x2f516a[_0x31e505],!a['call'](_0xe17632,_0x3f2e66)&&_0x3f2e66!==_0x55a337&&t(_0xe17632,_0x3f2e66,{'get':(_0x49dc3e=>_0x176475[_0x49dc3e])['bind'](null,_0x3f2e66),'enumerable':!(_0x107690=n(_0x176475,_0x3f2e66))||_0x107690['enumerable']});}return _0xe17632;},s=(_0x29dbca,_0x53e208,_0x252420)=>(_0x252420=_0x29dbca==null?{}:e(i(_0x29dbca)),o(_0x53e208||!_0x29dbca||!_0x29dbca['__esModule']?t(_0x252420,'default',{'value':_0x29dbca,'enumerable':!0x0}):_0x252420,_0x29dbca));let c=require('node:util'),l=require('libsql');l=s(l,0x1);let u=require('@univerjs-pro/collaboration-service'),d=require('@univerjs/protocol');var f='worktree',p=0x2,m=['collaboration_worktrees','collaboration_worktree_units','collaboration_worktree_changesets','collaboration_worktree_unit_seeds','collaboration_worktree_unit_merge_artifacts'],h=0x1388,g='__univerCollaborationBinary',_=new Set([d['UniverType']['UNIVER_SHEET'],d['UniverType']['UNIVER_DOC'],d['UniverType']['UNIVER_SLIDE'],d['UniverType']['UNIVER_BOARD'],d['UniverType']['UNIVER_BASE']]),v=class{['_database'];['_disposed']=!0x1;constructor(_0x1ac4cf){b(_0x1ac4cf),this['_database']=new l['default'](_0x1ac4cf['filename'],{'timeout':_0x1ac4cf['busyTimeoutMs']??h});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x1ac4cf['busyTimeoutMs']??h)+';'),this['_initializeSchema']();}catch(_0x567b49){throw this['_database']['close'](),_0x567b49;}}async['getWorktree'](_0x3509a3,_0x13dd8a){return this['_assertOpen'](),this['_getAggregate'](_0x13dd8a);}async['getWorktreeUnit'](_0x520e38,_0x24b128,_0x4d2448){this['_assertOpen']();let _0x4b1aac=this['_getUnitRow'](_0x24b128,_0x4d2448);return _0x4b1aac?y(_0x4b1aac):null;}async['getDraftChangesets'](_0x24d46c,_0x25bae4,_0x3bb814,_0x7dc0d2){this['_assertOpen'](),T(_0x7dc0d2);let _0x295c1e=this['_database']['prepare']('SELECT\x20changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x20AS\x20units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_worktree_changesets\x20AS\x20changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20changesets.worktree_id\x20=\x20units.worktree_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.unit_id\x20=\x20units.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.revision\x20>\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+(_0x7dc0d2['to']===void 0x0?'':'AND\x20changesets.revision\x20<=\x20?')+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20units.worktree_id\x20=\x20?\x20AND\x20units.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20changesets.revision\x20ASC')['all'](_0x7dc0d2['from'],..._0x7dc0d2['to']===void 0x0?[]:[_0x7dc0d2['to']],_0x25bae4,_0x3bb814);return _0x295c1e['length']===0x0?null:_0x295c1e['flatMap'](({payload_json:_0x347f1f})=>_0x347f1f?[F(_0x347f1f)]:[]);}async['getUnitSeed'](_0x5d2ddb,_0xc23920,_0x54102a){return this['_assertOpen'](),this['_getUnitSeed'](_0xc23920,_0x54102a);}async['getUnitMergeArtifact'](_0x29bc3a,_0x414e57,_0x3a6812){return this['_assertOpen'](),this['_getUnitMergeArtifact'](_0x414e57,_0x3a6812);}async['createWorktree'](_0x8de60,_0x280c06){return this['_assertOpen'](),x(_0x280c06),this['_transaction'](()=>{let _0x46241d=this['_getAggregate'](_0x280c06['record']['worktreeID']);if(_0x46241d)return{'status':'already-exists','aggregate':_0x46241d};this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktrees\x20(worktree_id,\x20sid,\x20status)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20\x27draft\x27)')['run'](_0x280c06['record']['worktreeID'],_0x280c06['record']['sid']);let _0x3eba60=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27trunk\x27,\x20?,\x20?)');return _0x280c06['units']['forEach']((_0x382d76,_0x94985e)=>{_0x3eba60['run'](_0x382d76['worktreeID'],_0x382d76['unitID'],_0x94985e,_0x382d76['type'],_0x382d76['baselineTrunkRevision'],_0x382d76['draftHeadRevision']);}),{'status':'created','aggregate':this['_requireAggregate'](_0x280c06['record']['worktreeID'])};});}async['addUnit'](_0x425ecb,_0x574984){return this['_assertOpen'](),w(_0x574984['unit']),this['_transaction'](()=>{let {unit:_0x29ad66}=_0x574984,_0x10855e=this['_getWorktreeRow'](_0x29ad66['worktreeID']);if(!_0x10855e)return{'status':'not-found'};if(this['_getUnitRow'](_0x29ad66['worktreeID'],_0x29ad66['unitID']))return{'status':'already-exists','aggregate':this['_requireAggregate'](_0x29ad66['worktreeID'])};if(_0x10855e['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x29ad66['worktreeID'])};S(_0x29ad66);let _0x1d3d6e=this['_database']['prepare']('SELECT\x20COALESCE(MAX(unit_order),\x20-1)\x20+\x201\x20AS\x20next_order\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0x29ad66['worktreeID']);return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27trunk\x27,\x20?,\x20?)')['run'](_0x29ad66['worktreeID'],_0x29ad66['unitID'],_0x1d3d6e['next_order'],_0x29ad66['type'],_0x29ad66['baselineTrunkRevision'],_0x29ad66['draftHeadRevision']),{'status':'added','aggregate':this['_requireAggregate'](_0x29ad66['worktreeID'])};});}async['createUnit'](_0x257894,_0x43cb20){return this['_assertOpen'](),C(_0x43cb20['unit'],_0x43cb20['seed']),this['_transaction'](()=>{let {unit:_0x2636be,seed:_0x1d2c7f}=_0x43cb20,_0x58ad36=this['_getWorktreeRow'](_0x2636be['worktreeID']);if(!_0x58ad36)return{'status':'not-found'};let _0x3f7497=this['_getUnitRow'](_0x2636be['worktreeID'],_0x2636be['unitID']);if(_0x3f7497){let _0x5a7b3c=this['_getUnitSeed'](_0x2636be['worktreeID'],_0x2636be['unitID']);return{'status':_0x3f7497['source']==='worktree'&&_0x3f7497['type']===_0x2636be['type']&&_0x5a7b3c!==null&&P(_0x5a7b3c)===P(_0x1d2c7f)?'already-created':'unit-exists','aggregate':this['_requireAggregate'](_0x2636be['worktreeID'])};}if(_0x58ad36['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x2636be['worktreeID'])};let _0x31576c=this['_database']['prepare']('SELECT\x20COALESCE(MAX(unit_order),\x20-1)\x20+\x201\x20AS\x20next_order\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0x2636be['worktreeID']);return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20unit_order,\x20type,\x20source,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision,\x20draft_head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20\x27worktree\x27,\x201,\x201)')['run'](_0x2636be['worktreeID'],_0x2636be['unitID'],_0x31576c['next_order'],_0x2636be['type']),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_unit_seeds\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20snapshot_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?)')['run'](_0x2636be['worktreeID'],_0x2636be['unitID'],P(_0x1d2c7f['snapshot']),_0x1d2c7f['sheetBlocks']===void 0x0?null:P(_0x1d2c7f['sheetBlocks'])),{'status':'created','aggregate':this['_requireAggregate'](_0x2636be['worktreeID'])};});}async['saveUnitMergeArtifact'](_0xf06380,_0x130c44){return this['_assertOpen'](),this['_transaction'](()=>{let _0x3053c9=this['_getWorktreeRow'](_0x130c44['worktreeID']),_0x570a6c=this['_getUnitRow'](_0x130c44['worktreeID'],_0x130c44['unitID']);if(!_0x3053c9||!_0x570a6c)return{'status':'not-found'};let _0x190b1f=y(_0x570a6c);if(_0x3053c9['status']!=='merging'||_0x190b1f['source']!=='worktree'||_0x190b1f['readyDraftHeadRevision']!==_0x130c44['artifact']['readyDraftHeadRevision']||O(_0x190b1f))return{'status':'stale-merge'};let _0x298a76=this['_getUnitMergeArtifact'](_0x130c44['worktreeID'],_0x130c44['unitID']);return _0x298a76?{'status':'already-saved','artifact':_0x298a76}:(D(_0x190b1f,_0x130c44['artifact']),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20snapshot_json,\x20sheet_blocks_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x130c44['worktreeID'],_0x130c44['unitID'],_0x130c44['artifact']['readyDraftHeadRevision'],P(_0x130c44['artifact']['unit']['snapshot']),_0x130c44['artifact']['unit']['sheetBlocks']===void 0x0?null:P(_0x130c44['artifact']['unit']['sheetBlocks'])),{'status':'saved','artifact':F(P(_0x130c44['artifact']))});});}async['setUnitRemoved'](_0x391dce,_0x4e3afd){return this['_assertOpen'](),this['_transaction'](()=>{let _0x2c78e3=this['_getWorktreeRow'](_0x4e3afd['worktreeID']),_0xbac36b=this['_getUnitRow'](_0x4e3afd['worktreeID'],_0x4e3afd['unitID']);return!_0x2c78e3||!_0xbac36b?{'status':'not-found'}:_0x2c78e3['status']!=='draft'||O(y(_0xbac36b))?{'status':'not-editable','aggregate':this['_requireAggregate'](_0x4e3afd['worktreeID'])}:_0xbac36b['removed']===0x1===_0x4e3afd['removed']?{'status':'unchanged','aggregate':this['_requireAggregate'](_0x4e3afd['worktreeID'])}:(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x20SET\x20removed\x20=\x20?\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](+!!_0x4e3afd['removed'],_0x4e3afd['worktreeID'],_0x4e3afd['unitID']),{'status':'updated','aggregate':this['_requireAggregate'](_0x4e3afd['worktreeID'])});});}async['commitDraftChangeset'](_0x2052ea,_0x17824a){return this['_assertOpen'](),this['_transaction'](()=>{let {worktreeID:_0x466fa3,changeset:_0x61030e}=_0x17824a,_0x46143c=this['_getWorktreeRow'](_0x466fa3),_0x3b1da3=this['_getUnitRow'](_0x466fa3,_0x61030e['unitID']);if(!_0x46143c||!_0x3b1da3)return{'status':'not-found'};if(_0x46143c['status']!=='draft')return{'status':'not-editable','worktreeStatus':A(_0x46143c['status'])};let _0x3b603c=y(_0x3b1da3);if(_0x3b603c['removed']||O(_0x3b603c))return{'status':'unit-frozen'};if(_0x3b603c['draftHeadRevision']!==_0x61030e['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x3b603c['draftHeadRevision']};if(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_worktree_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(worktree_id,\x20unit_id,\x20revision,\x20base_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid,\x20req_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x466fa3,_0x61030e['unitID'],_0x61030e['revision'],_0x61030e['baseRev'],_0x61030e['sid'],_0x61030e['reqId'],P(_0x61030e)),this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20draft_head_revision\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20draft_head_revision\x20=\x20?')['run'](_0x61030e['revision'],_0x466fa3,_0x61030e['unitID'],_0x61030e['revision']-0x1)['changes']!==0x1)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20draft\x20head\x20changed\x20inside\x20a\x20write\x20transaction');return{'status':'committed','changeset':F(P(_0x61030e)),'headRevision':_0x61030e['revision']};});}async['markReady'](_0x969d8a,_0x48d5b2){return this['_assertOpen'](),this['_transaction'](()=>{let _0x3786b1=this['_getWorktreeRow'](_0x48d5b2);if(!_0x3786b1)return{'status':'not-found'};if(_0x3786b1['status']==='ready')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x48d5b2)};if(_0x3786b1['status']!=='draft')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x48d5b2)};for(let _0x4e2a94 of this['_getUnitRows'](_0x48d5b2))O(y(_0x4e2a94))||(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20ready_draft_head_revision\x20=\x20draft_head_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x48d5b2,_0x4e2a94['unit_id']),this['_database']['prepare']('DELETE\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x48d5b2,_0x4e2a94['unit_id']));return this['_updateStatus'](_0x48d5b2,'ready'),{'status':'transitioned','previousStatus':'draft','aggregate':this['_requireAggregate'](_0x48d5b2)};});}async['reopenWorktree'](_0x1f9f9c,_0x255232){return this['_assertOpen'](),this['_transaction'](()=>{let _0x54b5c9=this['_getWorktreeRow'](_0x255232);if(!_0x54b5c9)return{'status':'not-found'};if(_0x54b5c9['status']==='draft')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x255232)};if(_0x54b5c9['status']!=='ready')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x255232)};for(let _0xc030ff of this['_getUnitRows'](_0x255232))O(y(_0xc030ff))||(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20ready_draft_head_revision\x20=\x20NULL,\x20merge_result_json\x20=\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x255232,_0xc030ff['unit_id']),this['_database']['prepare']('DELETE\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](_0x255232,_0xc030ff['unit_id']));return this['_updateStatus'](_0x255232,'draft'),{'status':'transitioned','previousStatus':'ready','aggregate':this['_requireAggregate'](_0x255232)};});}async['discardWorktree'](_0x5895d2,_0x32aed4){return this['_assertOpen'](),this['_transaction'](()=>{let _0x560420=this['_getWorktreeRow'](_0x32aed4);if(!_0x560420)return{'status':'not-found'};if(_0x560420['status']==='discarded')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x32aed4)};if(_0x560420['status']!=='draft'&&_0x560420['status']!=='ready')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x32aed4)};let _0x35765c=A(_0x560420['status']);return this['_updateStatus'](_0x32aed4,'discarded'),{'status':'transitioned','previousStatus':_0x35765c,'aggregate':this['_requireAggregate'](_0x32aed4)};});}async['startOrResumeMerge'](_0x470d2a,_0x2b595c){return this['_assertOpen'](),this['_transaction'](()=>{let _0x9d9940=this['_getWorktreeRow'](_0x2b595c);return _0x9d9940?_0x9d9940['status']==='merged'?{'status':'already-merged','aggregate':this['_requireAggregate'](_0x2b595c)}:_0x9d9940['status']==='merging'?{'status':'resumed','aggregate':this['_requireAggregate'](_0x2b595c)}:_0x9d9940['status']==='ready'?(this['_updateStatus'](_0x2b595c,'merging'),{'status':'started','aggregate':this['_requireAggregate'](_0x2b595c)}):{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x2b595c)}:{'status':'not-found'};});}async['recordUnitMergeResult'](_0x33e0e3,_0x4fd159){return this['_assertOpen'](),E(_0x4fd159['mergeResult']),this['_transaction'](()=>{let _0x232bce=this['_getWorktreeRow'](_0x4fd159['worktreeID']),_0x1fef1c=this['_getUnitRow'](_0x4fd159['worktreeID'],_0x4fd159['unitID']);if(!_0x232bce||!_0x1fef1c)return{'status':'not-found'};let _0xa53fe9=y(_0x1fef1c);if(_0x232bce['status']!=='merging'||_0xa53fe9['readyDraftHeadRevision']!==_0x4fd159['readyDraftHeadRevision'])return{'status':'stale-merge'};if(_0x4fd159['mergeResult']['status']==='removed'&&!_0xa53fe9['removed']||_0xa53fe9['removed']&&(_0x4fd159['mergeResult']['status']==='merged'||_0x4fd159['mergeResult']['status']==='unchanged'))throw new u['CollabError']('INVALID_REQUEST','Merge\x20result\x20does\x20not\x20match\x20frozen\x20Unit\x20removal\x20intent');let _0x74b82f=_0xa53fe9['mergeResult'];return _0x74b82f&&(0x0,c['isDeepStrictEqual'])(_0x74b82f,_0x4fd159['mergeResult'])?{'status':'already-recorded','aggregate':this['_requireAggregate'](_0x4fd159['worktreeID'])}:_0x74b82f&&k(_0x74b82f)?{'status':'stale-merge'}:(this['_database']['prepare']('UPDATE\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20merge_result_json\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['run'](P(_0x4fd159['mergeResult']),_0x4fd159['worktreeID'],_0x4fd159['unitID']),{'status':'recorded','aggregate':this['_requireAggregate'](_0x4fd159['worktreeID'])});});}async['finishMerge'](_0x2ce0fa,_0x5066b3){return this['_assertOpen'](),this['_transaction'](()=>{let _0x847488=this['_getWorktreeRow'](_0x5066b3);if(!_0x847488)return{'status':'not-found'};if(_0x847488['status']==='merged')return{'status':'already-in-target','aggregate':this['_requireAggregate'](_0x5066b3)};if(_0x847488['status']!=='merging')return{'status':'status-mismatch','aggregate':this['_requireAggregate'](_0x5066b3)};let _0x2c590b=this['_getUnitRows'](_0x5066b3)['every'](_0x41b771=>O(y(_0x41b771)));return this['_updateStatus'](_0x5066b3,_0x2c590b?'merged':'ready'),{'status':'transitioned','previousStatus':'merging','aggregate':this['_requireAggregate'](_0x5066b3)};});}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyOwnedTable']())throw N('SQLite\x20Worktree\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 _0x3ee407=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'](f);if(_0x3ee407){if(_0x3ee407['version']!==0x1&&_0x3ee407['version']!==p)throw N('SQLite\x20Worktree\x20schema\x20version\x20'+_0x3ee407['version']+'\x20is\x20not\x20supported');let _0x4c9777=m['filter'](_0x240af4=>!this['_hasTable'](_0x240af4));if(_0x4c9777['length']>0x0)throw N('SQLite\x20Worktree\x20schema\x20v'+_0x3ee407['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x4c9777['join'](',\x20'));if(_0x3ee407['version']===0x1&&(this['_database']['exec']('ALTER\x20TABLE\x20collaboration_worktree_units\x20ADD\x20COLUMN\x20removed\x20INTEGER\x20NOT\x20NULL\x20DEFAULT\x200\x20CHECK\x20(removed\x20IN\x20(0,\x201))'),this['_database']['prepare']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x20?\x20WHERE\x20component\x20=\x20?')['run'](p,f)),!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_worktree_units)')['all']()['some'](_0xf6bf24=>_0xf6bf24['name']==='removed'))throw N('SQLite\x20Worktree\x20schema\x20v2\x20is\x20missing\x20the\x20removed\x20column');return;}if(this['_hasAnyOwnedTable']())throw N('SQLite\x20Worktree\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktrees\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20status\x20TEXT\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(status\x20IN\x20(\x27draft\x27,\x20\x27ready\x27,\x20\x27merging\x27,\x20\x27merged\x27,\x20\x27discarded\x27))\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_units\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20removed\x20INTEGER\x20NOT\x20NULL\x20DEFAULT\x200\x20CHECK\x20(removed\x20IN\x20(0,\x201)),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20unit_order\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(unit_order\x20>=\x200),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20source\x20TEXT\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(source\x20IN\x20(\x27trunk\x27,\x20\x27worktree\x27)),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20baseline_trunk_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(baseline_trunk_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(draft_head_revision\x20>=\x20baseline_trunk_revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ready_draft_head_revision\x20INTEGER,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(worktree_id,\x20unit_order),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktrees(worktree_id)\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_changesets\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(revision\x20>=\x202),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20base_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(base_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sid\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20req_id\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(req_id\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(worktree_id,\x20unit_id,\x20sid,\x20req_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_worktree_changesets_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_worktree_changesets(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id,\x20unit_id,\x20revision\x20ASC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_unit_seeds\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20snapshot_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20resources_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_worktree_unit_merge_artifacts\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20worktree_id\x20TEXT\x20NOT\x20NULL,\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\x20ready_draft_head_revision\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20CHECK\x20(ready_draft_head_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20snapshot_json\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20resources_json\x20TEXT,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20PRIMARY\x20KEY\x20(worktree_id,\x20unit_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_worktree_units(worktree_id,\x20unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\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(\x27worktree\x27,\x20'+p+');\x0a\x20\x20\x20\x20\x20\x20');});}['_hasTable'](_0x37a56d){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'](_0x37a56d);}['_hasAnyOwnedTable'](){return m['some'](_0x2bcfb6=>this['_hasTable'](_0x2bcfb6));}['_getWorktreeRow'](_0xa6039a){return this['_database']['prepare']('SELECT\x20worktree_id,\x20sid,\x20status\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktrees\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?')['get'](_0xa6039a)??null;}['_getUnitRow'](_0x319899,_0x5f48d4){return this['_database']['prepare']('SELECT\x20worktree_id,\x20unit_id,\x20type,\x20source,\x20baseline_trunk_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json,\x20removed\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x319899,_0x5f48d4)??null;}['_getUnitRows'](_0x508e92){return this['_database']['prepare']('SELECT\x20worktree_id,\x20unit_id,\x20type,\x20source,\x20baseline_trunk_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20draft_head_revision,\x20ready_draft_head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20merge_result_json,\x20removed\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20unit_order\x20ASC')['all'](_0x508e92);}['_getUnitSeed'](_0x1a02ab,_0x16fb0b){let _0x2b4199=this['_database']['prepare']('SELECT\x20snapshot_json,\x20sheet_blocks_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_unit_seeds\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x1a02ab,_0x16fb0b);return _0x2b4199?{'snapshot':F(_0x2b4199['snapshot_json']),..._0x2b4199['sheet_blocks_json']===null?{}:{'sheetBlocks':F(_0x2b4199['sheet_blocks_json'])}}:null;}['_getUnitMergeArtifact'](_0x40be7f,_0x25aa4c){let _0x425b55=this['_database']['prepare']('SELECT\x20ready_draft_head_revision,\x20snapshot_json,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20sheet_blocks_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_worktree_unit_merge_artifacts\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20worktree_id\x20=\x20?\x20AND\x20unit_id\x20=\x20?')['get'](_0x40be7f,_0x25aa4c);return _0x425b55?{'readyDraftHeadRevision':_0x425b55['ready_draft_head_revision'],'unit':{'snapshot':F(_0x425b55['snapshot_json']),..._0x425b55['sheet_blocks_json']===null?{}:{'sheetBlocks':F(_0x425b55['sheet_blocks_json'])}}}:null;}['_getAggregate'](_0x1f2fdd){let _0x40714d=this['_getWorktreeRow'](_0x1f2fdd);return _0x40714d?{'worktree':{'worktreeID':_0x40714d['worktree_id'],'sid':_0x40714d['sid'],'status':A(_0x40714d['status'])},'units':this['_getUnitRows'](_0x1f2fdd)['map'](y)}:null;}['_requireAggregate'](_0x17dd15){let _0x1190cf=this['_getAggregate'](_0x17dd15);if(!_0x1190cf)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20disappeared\x20inside\x20a\x20write\x20transaction');return _0x1190cf;}['_updateStatus'](_0x5dd102,_0x2c434b){if(this['_database']['prepare']('UPDATE\x20collaboration_worktrees\x20SET\x20status\x20=\x20?\x20WHERE\x20worktree_id\x20=\x20?')['run'](_0x2c434b,_0x5dd102)['changes']!==0x1)throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20status\x20update\x20did\x20not\x20affect\x20one\x20record');}['_transaction'](_0x5be5dd){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x2da354=_0x5be5dd();return this['_database']['exec']('COMMIT;'),_0x2da354;}catch(_0x559e24){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x559e24;}}['_assertOpen'](){if(this['_disposed'])throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20Worktree\x20Database\x20Adapter\x20is\x20disposed');}};function y(_0x5016ec){let _0x1fd237=j(_0x5016ec['source']);return{'worktreeID':_0x5016ec['worktree_id'],'unitID':_0x5016ec['unit_id'],'type':_0x5016ec['type'],'source':_0x1fd237,..._0x1fd237==='trunk'?{'baselineTrunkRevision':_0x5016ec['baseline_trunk_revision']}:{},..._0x5016ec['removed']===0x1?{'removed':!0x0}:{},'draftHeadRevision':_0x5016ec['draft_head_revision'],..._0x5016ec['ready_draft_head_revision']===null?{}:{'readyDraftHeadRevision':_0x5016ec['ready_draft_head_revision']},..._0x5016ec['merge_result_json']===null?{}:{'mergeResult':F(_0x5016ec['merge_result_json'])}};}function b(_0x474dd3){if(!_0x474dd3['filename'])throw M('SQLite\x20filename\x20is\x20required');if(_0x474dd3['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x474dd3['busyTimeoutMs'])||_0x474dd3['busyTimeoutMs']<0x0))throw M('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function x(_0x19caa6){if(!_0x19caa6['record']['worktreeID']||!_0x19caa6['record']['sid']||_0x19caa6['record']['status']!=='draft')throw M('New\x20Worktree\x20must\x20be\x20a\x20draft\x20with\x20identity');let _0x3de756=new Set();for(let _0x249a5a of _0x19caa6['units']){if(_0x249a5a['worktreeID']!==_0x19caa6['record']['worktreeID']||_0x3de756['has'](_0x249a5a['unitID']))throw M('Initial\x20Worktree\x20Units\x20must\x20be\x20unique\x20and\x20share\x20identity');_0x3de756['add'](_0x249a5a['unitID']),S(_0x249a5a);}}function S(_0x1421e2){if(w(_0x1421e2),_0x1421e2['source']!=='trunk'||!_['has'](_0x1421e2['type'])||!Number['isSafeInteger'](_0x1421e2['baselineTrunkRevision'])||_0x1421e2['baselineTrunkRevision']<0x1||_0x1421e2['draftHeadRevision']!==_0x1421e2['baselineTrunkRevision']||_0x1421e2['readyDraftHeadRevision']!==void 0x0||_0x1421e2['mergeResult']!==void 0x0)throw M('New\x20Worktree\x20Unit\x20must\x20start\x20at\x20its\x20trunk\x20baseline');}function C(_0x5608d5,_0x2769ed){if(w(_0x5608d5),_0x5608d5['source']!=='worktree'||_0x5608d5['baselineTrunkRevision']!==void 0x0||!_['has'](_0x5608d5['type'])||_0x5608d5['draftHeadRevision']!==0x1||_0x5608d5['readyDraftHeadRevision']!==void 0x0||_0x5608d5['mergeResult']!==void 0x0||_0x2769ed['snapshot']['unitID']!==_0x5608d5['unitID']||_0x2769ed['snapshot']['type']!==_0x5608d5['type']||_0x2769ed['snapshot']['rev']!==0x1)throw M('Worktree-created\x20Unit\x20must\x20start\x20from\x20its\x20revision\x201\x20seed');}function w(_0x52e42e){if(!_0x52e42e['worktreeID']||!_0x52e42e['unitID'])throw M('Worktree\x20and\x20Unit\x20identity\x20are\x20required');}function T(_0x25c9f2){if(!Number['isSafeInteger'](_0x25c9f2['from'])||_0x25c9f2['from']<0x0||_0x25c9f2['to']!==void 0x0&&(!Number['isSafeInteger'](_0x25c9f2['to'])||_0x25c9f2['to']<0x0))throw M('Draft\x20revision\x20range\x20cannot\x20be\x20negative');}function E(_0x53ad30){if(_0x53ad30['status']==='merged'){if(!Number['isSafeInteger'](_0x53ad30['trunkRevision'])||_0x53ad30['trunkRevision']<0x1)throw M('Merged\x20result\x20requires\x20a\x20trunk\x20revision');return;}if(!(_0x53ad30['status']==='unchanged'||_0x53ad30['status']==='removed')&&(!_0x53ad30['error']['code']||!_0x53ad30['error']['message']||typeof _0x53ad30['error']['retryable']!='boolean'))throw M('Merge\x20error\x20must\x20be\x20stable\x20and\x20serializable');}function D(_0x431cf6,_0x1b6762){if(_0x1b6762['unit']['snapshot']['unitID']!==_0x431cf6['unitID']||_0x1b6762['unit']['snapshot']['type']!==_0x431cf6['type']||_0x1b6762['unit']['snapshot']['rev']!==0x1)throw M('Worktree\x20Unit\x20merge\x20artifact\x20must\x20be\x20a\x20revision\x201\x20snapshot');}function O(_0xf434a3){return k(_0xf434a3['mergeResult']);}function k(_0x343e95){return _0x343e95?.['status']==='merged'||_0x343e95?.['status']==='unchanged'||_0x343e95?.['status']==='removed';}function A(_0x285eb0){if(_0x285eb0==='draft'||_0x285eb0==='ready'||_0x285eb0==='merging'||_0x285eb0==='merged'||_0x285eb0==='discarded')return _0x285eb0;throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20contains\x20invalid\x20Worktree\x20status\x20'+_0x285eb0);}function j(_0x5d4bf8){if(_0x5d4bf8==='trunk'||_0x5d4bf8==='worktree')return _0x5d4bf8;throw new u['CollabError']('INTERNAL_ERROR','SQLite\x20contains\x20invalid\x20Worktree\x20Unit\x20source\x20'+_0x5d4bf8);}function M(_0x45eb09){return new u['CollabError']('INVALID_REQUEST',_0x45eb09);}function N(_0x572411){return new u['CollabError']('INTERNAL_ERROR',_0x572411);}function P(_0x416fea){return JSON['stringify'](_0x416fea,function(_0x3e2bec,_0x5070e0){let _0x4478b5=this[_0x3e2bec];return _0x4478b5 instanceof Uint8Array?{[g]:Buffer['from'](_0x4478b5)['toString']('base64')}:_0x5070e0;});}function F(_0x2851b2){return JSON['parse'](_0x2851b2,(_0x5be691,_0x7b8f7)=>I(_0x7b8f7)?Uint8Array['from'](Buffer['from'](_0x7b8f7[g],'base64')):_0x7b8f7);}function I(_0x4e2b22){return typeof _0x4e2b22=='object'&&!!_0x4e2b22&&Object['keys'](_0x4e2b22)['length']===0x1&&typeof _0x4e2b22[g]=='string';}exports['SQLiteWorktreeDatabaseAdapter']=v;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AddWorktreeUnitDatabaseInput, AddWorktreeUnitDatabaseResult, CommitWorktreeChangesetInput, CommitWorktreeChangesetResult, CreateWorktreeDatabaseInput, CreateWorktreeDatabaseResult, CreateWorktreeUnitDatabaseInput, CreateWorktreeUnitDatabaseResult, IWorktreeDatabaseAdapter, RecordUnitMergeResultInput, RecordUnitMergeResultResult, SaveWorktreeUnitMergeArtifactInput, SaveWorktreeUnitMergeArtifactResult, StartMergeResult, WorktreeAggregateRecord, WorktreeRevisionRange, WorktreeTransitionResult, WorktreeUnitMergeArtifact, WorktreeUnitRecord, WorktreeUnitSeed } from "@univerjs-pro/collaboration-worktree-service";
|
|
1
|
+
import { DatabaseContext } from "@univerjs-pro/collaboration-service";
|
|
2
|
+
import { AddWorktreeUnitDatabaseInput, AddWorktreeUnitDatabaseResult, CommitWorktreeChangesetInput, CommitWorktreeChangesetResult, CreateWorktreeDatabaseInput, CreateWorktreeDatabaseResult, CreateWorktreeUnitDatabaseInput, CreateWorktreeUnitDatabaseResult, IWorktreeDatabaseAdapter, RecordUnitMergeResultInput, RecordUnitMergeResultResult, SaveWorktreeUnitMergeArtifactInput, SaveWorktreeUnitMergeArtifactResult, SetWorktreeUnitRemovedDatabaseInput, SetWorktreeUnitRemovedResult, StartMergeResult, WorktreeAggregateRecord, WorktreeRevisionRange, WorktreeTransitionResult, WorktreeUnitMergeArtifact, WorktreeUnitRecord, WorktreeUnitSeed } from "@univerjs-pro/collaboration-worktree-service";
|
|
3
3
|
import { IChangeset } from "@univerjs/protocol";
|
|
4
4
|
|
|
5
5
|
//#region src/sqlite-worktree-database-adapter.d.ts
|
|
@@ -13,14 +13,14 @@ declare class SQLiteWorktreeDatabaseAdapter implements IWorktreeDatabaseAdapter
|
|
|
13
13
|
constructor(options: SQLiteWorktreeDatabaseAdapterOptions);
|
|
14
14
|
getWorktree(_context: DatabaseContext, worktreeID: string): Promise<WorktreeAggregateRecord | null>;
|
|
15
15
|
getWorktreeUnit(_context: DatabaseContext, worktreeID: string, unitID: string): Promise<WorktreeUnitRecord | null>;
|
|
16
|
-
getDraftChangesets(_context: DatabaseContext, worktreeID: string, unitID: string, range: WorktreeRevisionRange): Promise<
|
|
17
|
-
getDraftSubmission(_context: DatabaseContext, worktreeID: string, unitID: string, sid: string, reqId: number): Promise<IChangeset | null>;
|
|
16
|
+
getDraftChangesets(_context: DatabaseContext, worktreeID: string, unitID: string, range: WorktreeRevisionRange): Promise<readonly IChangeset[] | null>;
|
|
18
17
|
getUnitSeed(_context: DatabaseContext, worktreeID: string, unitID: string): Promise<WorktreeUnitSeed | null>;
|
|
19
18
|
getUnitMergeArtifact(_context: DatabaseContext, worktreeID: string, unitID: string): Promise<WorktreeUnitMergeArtifact | null>;
|
|
20
19
|
createWorktree(_context: DatabaseContext, input: CreateWorktreeDatabaseInput): Promise<CreateWorktreeDatabaseResult>;
|
|
21
20
|
addUnit(_context: DatabaseContext, input: AddWorktreeUnitDatabaseInput): Promise<AddWorktreeUnitDatabaseResult>;
|
|
22
21
|
createUnit(_context: DatabaseContext, input: CreateWorktreeUnitDatabaseInput): Promise<CreateWorktreeUnitDatabaseResult>;
|
|
23
22
|
saveUnitMergeArtifact(_context: DatabaseContext, input: SaveWorktreeUnitMergeArtifactInput): Promise<SaveWorktreeUnitMergeArtifactResult>;
|
|
23
|
+
setUnitRemoved(_context: DatabaseContext, input: SetWorktreeUnitRemovedDatabaseInput): Promise<SetWorktreeUnitRemovedResult>;
|
|
24
24
|
commitDraftChangeset(_context: DatabaseContext, input: CommitWorktreeChangesetInput): Promise<CommitWorktreeChangesetResult>;
|
|
25
25
|
markReady(_context: DatabaseContext, worktreeID: string): Promise<WorktreeTransitionResult>;
|
|
26
26
|
reopenWorktree(_context: DatabaseContext, worktreeID: string): Promise<WorktreeTransitionResult>;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
const _0x17d171=_0x3e4e;(function(_0x1e36fd,_0x573c87){const _0xe8446b=_0x3e4e,_0x24d042=_0x1e36fd();while(!![]){try{const _0x22a4ac=parseInt(_0xe8446b(0x104))/0x1+-parseInt(_0xe8446b(0x101))/0x2*(-parseInt(_0xe8446b(0x103))/0x3)+parseInt(_0xe8446b(0xfc))/0x4+-parseInt(_0xe8446b(0xfe))/0x5*(-parseInt(_0xe8446b(0x105))/0x6)+-parseInt(_0xe8446b(0x102))/0x7*(-parseInt(_0xe8446b(0xfb))/0x8)+-parseInt(_0xe8446b(0xfd))/0x9*(parseInt(_0xe8446b(0xfa))/0xa)+-parseInt(_0xe8446b(0x100))/0xb;if(_0x22a4ac===_0x573c87)break;else _0x24d042['push'](_0x24d042['shift']());}catch(_0x2b190d){_0x24d042['push'](_0x24d042['shift']());}}}(_0x4f0f,0x481bf));import _0x1b6571 from'./index.cjs';function _0x3e4e(_0x26a951,_0x10a763){_0x26a951=_0x26a951-0xfa;const _0x4f0ffa=_0x4f0f();let _0x3e4e3f=_0x4f0ffa[_0x26a951];return _0x3e4e3f;}const facadeExport0=_0x1b6571[_0x17d171(0xff)];function _0x4f0f(){const _0x450866=['582giotYF','1532690LJzMRJ','8epqTzW','2159980iuMiwA','18wDLvxm','24870tMiEnb','SQLiteWorktreeDatabaseAdapter','7963010SXynNT','112766KzcgkT','1128113gtdYZN','3bIbVYs','85792WPcAdS'];_0x4f0f=function(){return _0x450866;};return _0x4f0f();}export{facadeExport0 as SQLiteWorktreeDatabaseAdapter};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.0-
|
|
7
|
+
"version": "1.0.0-rc.0",
|
|
8
8
|
"main": "./dist/index.cjs",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -19,12 +19,9 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@univerjs-pro/collaboration-service": "1.0.0-
|
|
23
|
-
"@univerjs-pro/collaboration-worktree-service": "1.0.0-
|
|
24
|
-
"@univerjs/protocol": "1.0.0-
|
|
22
|
+
"@univerjs-pro/collaboration-service": "1.0.0-rc.0",
|
|
23
|
+
"@univerjs-pro/collaboration-worktree-service": "1.0.0-rc.0",
|
|
24
|
+
"@univerjs/protocol": "1.0.0-rc.0",
|
|
25
25
|
"libsql": "^0.5.29"
|
|
26
|
-
},
|
|
27
|
-
"publishConfig": {
|
|
28
|
-
"access": "public"
|
|
29
26
|
}
|
|
30
|
-
}
|
|
27
|
+
}
|