@univerjs-pro/collaboration-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 ADDED
@@ -0,0 +1,56 @@
1
+ # @univerjs-pro/collaboration-database-sqlite
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ A persistent SQLite `IDatabaseAdapter` using the stable synchronous `libsql` API. Requires Node.js 22 or later.
6
+
7
+ ## Create the Adapter
8
+
9
+ ```bash
10
+ pnpm add \
11
+ @univerjs-pro/collaboration-service \
12
+ @univerjs-pro/collaboration-database-sqlite
13
+ ```
14
+
15
+ The caller must create the database parent directory first:
16
+
17
+ ```ts
18
+ import { mkdir } from 'node:fs/promises';
19
+ import { SQLiteDatabaseAdapter } from '@univerjs-pro/collaboration-database-sqlite';
20
+ import { UniverCollabService } from '@univerjs-pro/collaboration-service';
21
+
22
+ await mkdir('./data', { recursive: true });
23
+
24
+ const database = new SQLiteDatabaseAdapter({
25
+ filename: './data/collaboration.sqlite',
26
+ busyTimeoutMs: 5_000,
27
+ });
28
+ const service = new UniverCollabService({ dbAdapter: database });
29
+
30
+ await service.dispose();
31
+ await database.dispose();
32
+ ```
33
+
34
+ Pass the Adapter to `UniverCollabService` as `dbAdapter`.
35
+
36
+ ## Persistence guarantees
37
+
38
+ The Adapter uses foreign keys and `BEGIN IMMEDIATE` write transactions to guarantee:
39
+
40
+ - atomic creation of the initial snapshot and Sheet blocks;
41
+ - revision CAS with atomic changeset and head publication;
42
+ - a snapshot becomes visible to new reads only after all of its dependencies are complete;
43
+ - soft-delete, recovery, and hard-delete batches are all-or-nothing;
44
+ - hard delete keeps a permanent deletion marker that prevents Unit ID reuse.
45
+
46
+ It stores only core collaboration data. Product resources, users, ACLs, History, Comment, and Worktree are managed by the application or their respective Adapters.
47
+
48
+ ## SQLite behavior
49
+
50
+ - It does not change `journal_mode`; configure WAL, checkpointing, or backup policy before opening the Adapter when needed.
51
+ - Core tables use the `collaboration_` prefix.
52
+ - Schema version `('core', 1)` is stored in `collaboration_schema_versions`; `PRAGMA user_version` is not used.
53
+ - Changeset scalar columns and the submission unique constraint provide database-level integrity, while commits use revision CAS and do not query the submission key.
54
+ - An empty database is initialized automatically. Incomplete or unsupported core schemas are rejected.
55
+
56
+ This implementation suits local applications and small-to-medium single-Node deployments. Revision CAS still preserves collaboration-data correctness when multiple Service instances share the database file.
@@ -0,0 +1,61 @@
1
+ # @univerjs-pro/collaboration-database-sqlite
2
+
3
+ [English](./README.md) | [简体中文](./README.zh-CN.md)
4
+
5
+ 持久化 SQLite `IDatabaseAdapter`,使用稳定的 `libsql` 同步接口,支持 Node.js 22
6
+ 及以上版本。
7
+
8
+ ## 创建 Adapter
9
+
10
+ ```bash
11
+ pnpm add \
12
+ @univerjs-pro/collaboration-service \
13
+ @univerjs-pro/collaboration-database-sqlite
14
+ ```
15
+
16
+ 调用方需要先创建数据库父目录:
17
+
18
+ ```ts
19
+ import { mkdir } from 'node:fs/promises';
20
+ import { SQLiteDatabaseAdapter } from '@univerjs-pro/collaboration-database-sqlite';
21
+ import { UniverCollabService } from '@univerjs-pro/collaboration-service';
22
+
23
+ await mkdir('./data', { recursive: true });
24
+
25
+ const database = new SQLiteDatabaseAdapter({
26
+ filename: './data/collaboration.sqlite',
27
+ busyTimeoutMs: 5_000,
28
+ });
29
+ const service = new UniverCollabService({ dbAdapter: database });
30
+
31
+ await service.dispose();
32
+ await database.dispose();
33
+ ```
34
+
35
+ 将 Adapter 作为 `dbAdapter` 传给 `UniverCollabService`。
36
+
37
+ ## 持久化保证
38
+
39
+ Adapter 使用 foreign keys 和 `BEGIN IMMEDIATE` 写事务,保证:
40
+
41
+ - 初始 snapshot 与 Sheet blocks 原子创建;
42
+ - revision CAS 与 changeset/head 原子发布;
43
+ - snapshot 依赖完整后才对新读取可见;
44
+ - 软删除、恢复和 hard delete 批次全有或全无;
45
+ - hard delete 保留永久删除标记,禁止 Unit ID 复用。
46
+
47
+ 它只保存协同核心数据。产品资源、用户、ACL、History、Comment 和 Worktree 分别由应用
48
+ 或对应 Adapter 管理。
49
+
50
+ ## SQLite 行为
51
+
52
+ - 不主动修改 `journal_mode`;需要 WAL、checkpoint 或备份策略时由应用在打开前配置。
53
+ - 核心表使用 `collaboration_` 前缀。
54
+ - schema 版本以 `('core', 1)` 写入 `collaboration_schema_versions`,不占用
55
+ `PRAGMA user_version`。
56
+ - changeset 标量列和 submission unique constraint 提供数据库级完整性;提交只做 revision
57
+ CAS,不按 submission key 点查。
58
+ - 空库会自动初始化;不完整或不支持的核心 schema 会被拒绝。
59
+
60
+ 本实现适合本地应用和中小规模单 Node 部署。多个 Service 实例共享数据库文件时,
61
+ revision CAS 仍能保证协同数据正确性。
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=(_0x459285,_0x3854c9,_0x135288,_0x3344ef)=>{if(_0x3854c9&&typeof _0x3854c9=='object'||typeof _0x3854c9=='function'){for(var _0x3c8137=r(_0x3854c9),_0x52ba60=0x0,_0x3ed9db=_0x3c8137['length'],_0x2155fc;_0x52ba60<_0x3ed9db;_0x52ba60++)_0x2155fc=_0x3c8137[_0x52ba60],!a['call'](_0x459285,_0x2155fc)&&_0x2155fc!==_0x135288&&t(_0x459285,_0x2155fc,{'get':(_0x130329=>_0x3854c9[_0x130329])['bind'](null,_0x2155fc),'enumerable':!(_0x3344ef=n(_0x3854c9,_0x2155fc))||_0x3344ef['enumerable']});}return _0x459285;},s=(_0x5b0cc5,_0x402963,_0x3653a3)=>(_0x3653a3=_0x5b0cc5==null?{}:e(i(_0x5b0cc5)),o(_0x402963||!_0x5b0cc5||!_0x5b0cc5['__esModule']?t(_0x3653a3,'default',{'value':_0x5b0cc5,'enumerable':!0x0}):_0x3653a3,_0x5b0cc5));let c=require('libsql');c=s(c,0x1);let l=require('@univerjs-pro/collaboration-service');var u=0x1388,d='__univerCollaborationBinary',f='core',p=0x1,m=['collaboration_units','collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks','collaboration_resources'],h=class{['_database'];['_disposed']=!0x1;constructor(_0xbafd6f){g(_0xbafd6f),this['_database']=new c['default'](_0xbafd6f['filename'],{'timeout':_0xbafd6f['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0xbafd6f['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x208d54){throw this['_database']['close'](),_0x208d54;}}async['getUnit'](_0x13ffab,_0x62bb6a){this['_assertOpen']();let _0x52231d=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x62bb6a);return _0x52231d?b(_0x52231d):null;}async['getSnapshot'](_0x15fae0,_0x1e177d,_0x5b803a){this['_assertOpen']();let _0x4af303=_0x5b803a?.['revision'];if(_0x4af303!==void 0x0&&_0x4af303<0x0)throw x('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x1443c0=this['_getActiveUnitRow'](_0x1e177d);if(!_0x1443c0)return null;let _0x7eccff=_0x4af303===void 0x0||_0x4af303===0x0?_0x1443c0['head_revision']:Math['min'](_0x4af303,_0x1443c0['head_revision']),_0x2006b6=this['_database']['prepare']('SELECT\x20collaboration_snapshots.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_snapshots.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_snapshots.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_snapshots.revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20collaboration_snapshots.revision\x20DESC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201')['get'](_0x1e177d,_0x7eccff);return _0x2006b6?T(_0x2006b6['payload_json']):null;}async['getChangesets'](_0x257611,_0x4b1bf4,_0x2911fd){if(this['_assertOpen'](),_0x2911fd['from']<0x0||_0x2911fd['to']<0x0)throw x('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x19c570=this['_database']['prepare']('SELECT\x20collaboration_units.head_revision,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20collaboration_changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_changesets.unit_id\x20=\x20collaboration_units.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_changesets.revision\x20>\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_changesets.revision\x20<=\x20CASE\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHEN\x20?\x20=\x200\x20THEN\x20collaboration_units.head_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ELSE\x20MIN(?,\x20collaboration_units.head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20END\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_units.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20collaboration_changesets.revision\x20ASC')['all'](_0x2911fd['from'],_0x2911fd['to'],_0x2911fd['to'],_0x4b1bf4),_0x50d486=_0x19c570[0x0];return _0x50d486?{'changesets':_0x19c570['flatMap'](_0x252f69=>_0x252f69['payload_json']?[T(_0x252f69['payload_json'])]:[]),'latestRevision':_0x50d486['head_revision']}:{'changesets':[],'latestRevision':0x0};}async['getSubmission'](_0x17c30b,_0x3a90ae,_0x33d74f,_0x59f3b6){this['_assertOpen']();let _0x4d7a20=this['_database']['prepare']('SELECT\x20collaboration_changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_changesets.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_changesets.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_changesets.sid\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_changesets.req_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x3a90ae,_0x33d74f,_0x59f3b6);return _0x4d7a20?T(_0x4d7a20['payload_json']):null;}async['createUnit'](_0x28e1c5,_0x4979fd){this['_assertOpen'](),_(_0x4979fd);let _0x3d8fe5=w(_0x4979fd['snapshot']),_0xe74785=(_0x4979fd['sheetBlocks']??[])['map'](_0x729f2=>({'id':_0x729f2['id'],'payload':w(_0x729f2)})),_0x12fd8a=Object['entries'](_0x4979fd['resources']??{})['map'](([_0x26ce32,_0x49a737])=>({'resourceID':_0x26ce32,'payload':w(_0x49a737)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x4979fd['record']['unitID']))throw x('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x5c7c52=this['_getStoredUnitRow'](_0x4979fd['record']['unitID']);if(_0x5c7c52){if(_0x5c7c52['soft_deleted_at_ms']!==null)throw x('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':b(_0x5c7c52)};}return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x201,\x20NULL)')['run'](_0x4979fd['record']['unitID'],_0x4979fd['record']['type']),this['_writeDependencies'](_0x4979fd['record']['unitID'],_0xe74785,_0x12fd8a),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20type,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x201,\x20?,\x20?)')['run'](_0x4979fd['record']['unitID'],_0x4979fd['record']['type'],_0x3d8fe5),{'status':'created','record':{..._0x4979fd['record']}};});}async['deleteUnits'](_0x595381,_0x2f3a3e){return this['_assertOpen'](),this['_transaction'](()=>{let _0x4ea5e8=C(_0x2f3a3e['unitIDs'])['map'](_0x5a294b=>{let _0x269c02=this['_getStoredUnitRow'](_0x5a294b);if(!_0x269c02){if(_0x2f3a3e['hardDelete']&&this['_hasTombstone'](_0x5a294b))return{'unitID':_0x5a294b,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x2f3a3e['hardDelete']?{'unitID':_0x5a294b,'status':'hard-deleted'}:{'unitID':_0x5a294b,'status':_0x269c02['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x530c48=this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20soft_deleted_at_ms\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL'),_0x4d48b3=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_unit_tombstones\x20(unit_id,\x20purged_at)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?)'),_0x8090a6=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x33afa8=Date['now']();for(let _0x252311 of _0x4ea5e8)_0x252311['status']==='soft-deleted'?_0x530c48['run'](_0x33afa8,_0x252311['unitID']):_0x252311['status']==='hard-deleted'&&(_0x4d48b3['run'](_0x252311['unitID'],_0x33afa8),_0x8090a6['run'](_0x252311['unitID']));return{'units':_0x4ea5e8};});}async['recoverUnits'](_0x59b678,_0x58228e){return this['_assertOpen'](),this['_transaction'](()=>{let _0x8e2ca5=C(_0x58228e['unitIDs'])['map'](_0x52f0fd=>{let _0x3aea38=this['_getStoredUnitRow'](_0x52f0fd);if(!_0x3aea38)throw this['_hasTombstone'](_0x52f0fd)?x('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x52f0fd,'status':_0x3aea38['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x6648bd=this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20soft_deleted_at_ms\x20=\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NOT\x20NULL');for(let _0x7e3f9b of _0x8e2ca5)_0x7e3f9b['status']==='recovered'&&_0x6648bd['run'](_0x7e3f9b['unitID']);return{'units':_0x8e2ca5};});}async['commitChangeset'](_0x43dca4,_0x22aad1){this['_assertOpen'](),v(_0x22aad1['changeset']);let _0x4ba192=w(_0x22aad1['changeset']);return this['_transaction'](()=>{let {changeset:_0x5a0d60,expectedHeadRevision:_0x521933}=_0x22aad1,_0x19395a=this['_getActiveUnitRow'](_0x5a0d60['unitID']);if(!_0x19395a)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');let _0x125bd6=this['_database']['prepare']('SELECT\x20payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20sid\x20=\x20?\x20AND\x20req_id\x20=\x20?')['get'](_0x5a0d60['unitID'],_0x5a0d60['sid'],_0x5a0d60['reqId']);if(_0x125bd6)return{'status':'already-committed','changeset':T(_0x125bd6['payload_json'])};if(_0x19395a['head_revision']!==_0x521933)return{'status':'revision-mismatch','actualHeadRevision':_0x19395a['head_revision']};if(y(b(_0x19395a),_0x22aad1),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20base_revision,\x20sid,\x20req_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x5a0d60['unitID'],_0x5a0d60['revision'],_0x5a0d60['baseRev'],_0x5a0d60['sid'],_0x5a0d60['reqId'],_0x4ba192),this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20head_revision\x20=\x20?\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\x20\x20\x20AND\x20head_revision\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['run'](_0x5a0d60['revision'],_0x5a0d60['unitID'],_0x521933)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':T(_0x4ba192),'headRevision':_0x5a0d60['revision']};});}async['saveSnapshot'](_0x4a633e,_0x342b31){this['_assertOpen']();let _0x34c938=w(_0x342b31['snapshot']),_0x50928f=(_0x342b31['sheetBlocks']??[])['map'](_0x265e4b=>({'id':_0x265e4b['id'],'payload':w(_0x265e4b)})),_0x29644b=Object['entries'](_0x342b31['resources']??{})['map'](([_0x54ee2a,_0x594d2f])=>({'resourceID':_0x54ee2a,'payload':w(_0x594d2f)}));this['_transaction'](()=>{let _0x1dab84=this['_getActiveUnitRow'](_0x342b31['snapshot']['unitID']);if(!_0x1dab84)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x342b31['snapshot']['type']!==_0x1dab84['type']||_0x342b31['snapshot']['rev']<0x1||_0x342b31['snapshot']['rev']>_0x1dab84['head_revision'])throw x('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeDependencies'](_0x342b31['snapshot']['unitID'],_0x50928f,_0x29644b),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20type,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(unit_id,\x20revision)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20=\x20excluded.type,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json')['run'](_0x342b31['snapshot']['unitID'],_0x342b31['snapshot']['rev'],_0x342b31['snapshot']['type'],_0x34c938);});}async['getSheetBlock'](_0x13d67a,_0x528ee0,_0x12a4d3){this['_assertOpen']();let _0x5365c5=this['_database']['prepare']('SELECT\x20collaboration_sheet_blocks.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_sheet_blocks\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_sheet_blocks.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_sheet_blocks.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_sheet_blocks.block_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x528ee0,_0x12a4d3);return _0x5365c5?T(_0x5365c5['payload_json']):null;}async['getResources'](_0x53f892,_0x2cb091,_0x11914e){this['_assertOpen']();let _0xb38a09=this['_database']['prepare']('SELECT\x20collaboration_resources.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_resources\x0a\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_resources.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_resources.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_resources.resource_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL'),_0x419598={};for(let _0x417ec6 of _0x11914e){let _0x1e9fae=_0xb38a09['get'](_0x2cb091,_0x417ec6);_0x1e9fae&&(_0x419598[_0x417ec6]=T(_0x1e9fae['payload_json']));}return _0x419598;}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyCoreTable']())throw S('SQLite\x20collaboration\x20core\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 _0x1eb3c6=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(_0x1eb3c6){if(_0x1eb3c6['version']!==p)throw S('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x1eb3c6['version']+'\x20is\x20not\x20supported');let _0x1db380=m['filter'](_0x2e5fcc=>!this['_hasTable'](_0x2e5fcc));if(_0x1db380['length']>0x0)throw S('SQLite\x20collaboration\x20core\x20schema\x20v1\x20is\x20incomplete:\x20missing\x20'+_0x1db380['join'](',\x20'));return;}if(this['_hasAnyCoreTable']())throw S('SQLite\x20collaboration\x20core\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_units\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20head_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(head_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20soft_deleted_at_ms\x20INTEGER\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_unit_tombstones\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20purged_at\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_snapshots\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\x20revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\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(unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_changesets\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\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(unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(unit_id,\x20sid,\x20req_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_sheet_blocks\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\x20block_id\x20TEXT\x20NOT\x20NULL,\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(unit_id,\x20block_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_resources\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\x20resource_id\x20TEXT\x20NOT\x20NULL,\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(unit_id,\x20resource_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_id)\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_snapshots_nearest_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_snapshots(unit_id,\x20revision\x20DESC);\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_changesets_revision_range\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_changesets(unit_id,\x20revision\x20ASC);\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(\x27core\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_getActiveUnitRow'](_0x331824){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x331824)??null;}['_getStoredUnitRow'](_0x395590){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x395590)??null;}['_hasTombstone'](_0x132441){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x132441);}['_hasTable'](_0x30ac05){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'](_0x30ac05);}['_hasAnyCoreTable'](){return m['some'](_0xb47a04=>this['_hasTable'](_0xb47a04));}['_writeDependencies'](_0x1e78d9,_0x2df0c2,_0x24e161){let _0x5b8291=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_sheet_blocks\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20block_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(unit_id,\x20block_id)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json');for(let _0x4ab598 of _0x2df0c2)_0x5b8291['run'](_0x1e78d9,_0x4ab598['id'],_0x4ab598['payload']);let _0x37922c=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_resources\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20resource_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(unit_id,\x20resource_id)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json');for(let _0x17d01 of _0x24e161)_0x37922c['run'](_0x1e78d9,_0x17d01['resourceID'],_0x17d01['payload']);}['_transaction'](_0x4b380f){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x192f06=_0x4b380f();return this['_database']['exec']('COMMIT;'),_0x192f06;}catch(_0x3ad819){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x3ad819;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x598680){if(!_0x598680['filename'])throw x('SQLite\x20filename\x20is\x20required');if(_0x598680['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x598680['busyTimeoutMs'])||_0x598680['busyTimeoutMs']<0x0))throw x('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x396a6d){let {record:_0x5a1620,snapshot:_0x5cf61d}=_0x396a6d;if(_0x5a1620['headRevision']!==0x1||_0x5cf61d['rev']!==0x1||_0x5cf61d['unitID']!==_0x5a1620['unitID']||_0x5cf61d['type']!==_0x5a1620['type'])throw x('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');}function v(_0x5580ef){if(!_0x5580ef['sid']||!Number['isSafeInteger'](_0x5580ef['reqId'])||_0x5580ef['reqId']<0x1)throw x('Changeset\x20sid\x20and\x20positive\x20integer\x20reqId\x20are\x20required');}function y(_0x5f4594,_0x568125){let {changeset:_0x3bb79e,expectedHeadRevision:_0x55eaaa}=_0x568125;if(_0x3bb79e['type']!==_0x5f4594['type']||_0x3bb79e['baseRev']!==_0x55eaaa||_0x3bb79e['revision']!==_0x55eaaa+0x1)throw x('Confirmed\x20changeset\x20must\x20match\x20the\x20unit\x20type\x20and\x20expected\x20revision');}function b(_0x11f8ff){return{'unitID':_0x11f8ff['unit_id'],'type':_0x11f8ff['type'],'headRevision':_0x11f8ff['head_revision']};}function x(_0x292b6e){return new l['CollabError']('INVALID_REQUEST',_0x292b6e);}function S(_0x4df27a){return new l['CollabError']('INTERNAL_ERROR',_0x4df27a);}function C(_0x1d1f48){return[...new Set(_0x1d1f48)];}function w(_0x34424e){return JSON['stringify'](_0x34424e,(_0x336aa5,_0x24d39d)=>_0x24d39d instanceof Uint8Array?{[d]:Buffer['from'](_0x24d39d)['toString']('base64')}:_0x24d39d);}function T(_0x4b3ec9){return JSON['parse'](_0x4b3ec9,(_0x3ae267,_0x4aed36)=>E(_0x4aed36)?Uint8Array['from'](Buffer['from'](_0x4aed36[d],'base64')):_0x4aed36);}function E(_0x5d6605){return typeof _0x5d6605=='object'&&!!_0x5d6605&&Object['keys'](_0x5d6605)['length']===0x1&&typeof _0x5d6605[d]=='string';}exports['SQLiteDatabaseAdapter']=h;
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=(_0x2e1381,_0x4bc021,_0xb2fe04,_0x2ad381)=>{if(_0x4bc021&&typeof _0x4bc021=='object'||typeof _0x4bc021=='function'){for(var _0xc8d1eb=r(_0x4bc021),_0x5ac30b=0x0,_0x3a6c99=_0xc8d1eb['length'],_0x4f9e6e;_0x5ac30b<_0x3a6c99;_0x5ac30b++)_0x4f9e6e=_0xc8d1eb[_0x5ac30b],!a['call'](_0x2e1381,_0x4f9e6e)&&_0x4f9e6e!==_0xb2fe04&&t(_0x2e1381,_0x4f9e6e,{'get':(_0x1862b1=>_0x4bc021[_0x1862b1])['bind'](null,_0x4f9e6e),'enumerable':!(_0x2ad381=n(_0x4bc021,_0x4f9e6e))||_0x2ad381['enumerable']});}return _0x2e1381;},s=(_0x1b896b,_0x468ec1,_0x356711)=>(_0x356711=_0x1b896b==null?{}:e(i(_0x1b896b)),o(_0x468ec1||!_0x1b896b||!_0x1b896b['__esModule']?t(_0x356711,'default',{'value':_0x1b896b,'enumerable':!0x0}):_0x356711,_0x1b896b));let c=require('libsql');c=s(c,0x1);let l=require('@univerjs-pro/collaboration-service');var u=0x1388,d='__univerCollaborationBinary',f='core',p=0x1,m=['collaboration_units','collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks','collaboration_resources'],h=class{['_database'];['_disposed']=!0x1;constructor(_0x3852f8){g(_0x3852f8),this['_database']=new c['default'](_0x3852f8['filename'],{'timeout':_0x3852f8['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x3852f8['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x48ea07){throw this['_database']['close'](),_0x48ea07;}}async['getUnit'](_0x224add,_0x482558){this['_assertOpen']();let _0x1927b4=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x482558);return _0x1927b4?v(_0x1927b4):null;}async['getSnapshot'](_0x39aa41,_0x35ed1e,_0x42eea8){this['_assertOpen']();let _0x271384=_0x42eea8?.['revision'];if(_0x271384!==void 0x0&&_0x271384<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x3fc885=this['_getActiveUnitRow'](_0x35ed1e);if(!_0x3fc885)return null;let _0x1c0733=_0x271384===void 0x0?_0x3fc885['head_revision']:Math['min'](_0x271384,_0x3fc885['head_revision']),_0x37f4eb=this['_database']['prepare']('SELECT\x20collaboration_snapshots.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_snapshots.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_snapshots.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_snapshots.revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20collaboration_snapshots.revision\x20DESC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201')['get'](_0x35ed1e,_0x1c0733);return _0x37f4eb?C(_0x37f4eb['payload_json']):null;}async['getSnapshotInfo'](_0xca227e,_0x550ce3,_0x2e6a50){this['_assertOpen']();let _0x934d4=_0x2e6a50?.['revision']??null;if(_0x934d4!==null&&_0x934d4<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x5d2234=this['_database']['prepare']('SELECT\x20snapshots.unit_id\x20AS\x20unitID,\x20snapshots.type,\x20snapshots.revision\x20AS\x20rev\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_snapshots\x20AS\x20snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x20AS\x20units\x20ON\x20units.unit_id\x20=\x20snapshots.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20snapshots.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20units.soft_deleted_at_ms\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20snapshots.revision\x20<=\x20CASE\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHEN\x20?\x20IS\x20NULL\x20THEN\x20units.head_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ELSE\x20MIN(?,\x20units.head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20END\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20snapshots.revision\x20DESC\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LIMIT\x201')['get'](_0x550ce3,_0x934d4,_0x934d4);return _0x5d2234?{'unitID':_0x5d2234['unitID'],'type':_0x5d2234['type'],'rev':_0x5d2234['rev']}:null;}async['getChangesets'](_0x5e069b,_0x51f7f4,_0x8df9bb){if(this['_assertOpen'](),_0x8df9bb['from']<0x0||_0x8df9bb['to']!==void 0x0&&_0x8df9bb['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x48864d=this['_database']['prepare']('SELECT\x20collaboration_changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_changesets.unit_id\x20=\x20collaboration_units.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_changesets.revision\x20>\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20'+(_0x8df9bb['to']===void 0x0?'':'AND\x20collaboration_changesets.revision\x20<=\x20?')+'\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_units.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20collaboration_changesets.revision\x20ASC')['all'](_0x8df9bb['from'],..._0x8df9bb['to']===void 0x0?[]:[_0x8df9bb['to']],_0x51f7f4);return _0x48864d['length']===0x0?null:_0x48864d['flatMap'](_0x502bf6=>_0x502bf6['payload_json']?[C(_0x502bf6['payload_json'])]:[]);}async['createUnit'](_0x4b485e,_0x5d12d9){this['_assertOpen'](),_(_0x5d12d9);let _0x272f1c=S(_0x5d12d9['snapshot']),_0x181ed4=(_0x5d12d9['sheetBlocks']??[])['map'](_0x1a8d66=>({'id':_0x1a8d66['id'],'payload':S(_0x1a8d66)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x5d12d9['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x5ec54e=this['_getStoredUnitRow'](_0x5d12d9['record']['unitID']);if(_0x5ec54e){if(_0x5ec54e['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x5ec54e)};}return this['_database']['prepare']('INSERT\x20INTO\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x201,\x20NULL)')['run'](_0x5d12d9['record']['unitID'],_0x5d12d9['record']['type']),this['_writeSheetBlocks'](_0x5d12d9['record']['unitID'],_0x181ed4),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20type,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x201,\x20?,\x20?)')['run'](_0x5d12d9['record']['unitID'],_0x5d12d9['record']['type'],_0x272f1c),{'status':'created','record':{..._0x5d12d9['record']}};});}async['deleteUnits'](_0xb1135a,_0x2866e6){return this['_assertOpen'](),this['_transaction'](()=>{let _0x149c71=x(_0x2866e6['unitIDs'])['map'](_0x3ddbf7=>{let _0x3a9a78=this['_getStoredUnitRow'](_0x3ddbf7);if(!_0x3a9a78){if(_0x2866e6['hardDelete']&&this['_hasTombstone'](_0x3ddbf7))return{'unitID':_0x3ddbf7,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x2866e6['hardDelete']?{'unitID':_0x3ddbf7,'status':'hard-deleted'}:{'unitID':_0x3ddbf7,'status':_0x3a9a78['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x467864=this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20soft_deleted_at_ms\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL'),_0xc9f54f=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_unit_tombstones\x20(unit_id,\x20purged_at)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?)'),_0x4e4b77=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x4c939f=Date['now']();for(let _0x30c728 of _0x149c71)_0x30c728['status']==='soft-deleted'?_0x467864['run'](_0x4c939f,_0x30c728['unitID']):_0x30c728['status']==='hard-deleted'&&(_0xc9f54f['run'](_0x30c728['unitID'],_0x4c939f),_0x4e4b77['run'](_0x30c728['unitID']));return{'units':_0x149c71};});}async['recoverUnits'](_0x2d9c94,_0x1e4df3){return this['_assertOpen'](),this['_transaction'](()=>{let _0x36bdfa=x(_0x1e4df3['unitIDs'])['map'](_0x50dc18=>{let _0x3087f4=this['_getStoredUnitRow'](_0x50dc18);if(!_0x3087f4)throw this['_hasTombstone'](_0x50dc18)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x50dc18,'status':_0x3087f4['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x2523bd=this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20soft_deleted_at_ms\x20=\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NOT\x20NULL');for(let _0x42e746 of _0x36bdfa)_0x42e746['status']==='recovered'&&_0x2523bd['run'](_0x42e746['unitID']);return{'units':_0x36bdfa};});}async['commitChangeset'](_0x447aca,_0x494fff){this['_assertOpen']();let _0xd4147d=S(_0x494fff['changeset']);return this['_transaction'](()=>{let {changeset:_0x37a155}=_0x494fff,_0x25dae7=this['_getActiveUnitRow'](_0x37a155['unitID']);if(!_0x25dae7)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x25dae7['head_revision']!==_0x37a155['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x25dae7['head_revision']};if(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20base_revision,\x20sid,\x20req_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x37a155['unitID'],_0x37a155['revision'],_0x37a155['baseRev'],_0x37a155['sid'],_0x37a155['reqId'],_0xd4147d),this['_database']['prepare']('UPDATE\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20head_revision\x20=\x20?\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\x20\x20\x20AND\x20head_revision\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['run'](_0x37a155['revision'],_0x37a155['unitID'],_0x37a155['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0xd4147d),'headRevision':_0x37a155['revision']};});}async['saveSnapshot'](_0x4b61d9,_0x2e327e){this['_assertOpen']();let _0x3e20b5=S(_0x2e327e['snapshot']),_0x2d2a98=(_0x2e327e['sheetBlocks']??[])['map'](_0x144f2f=>({'id':_0x144f2f['id'],'payload':S(_0x144f2f)}));this['_transaction'](()=>{let _0x591739=this['_getActiveUnitRow'](_0x2e327e['snapshot']['unitID']);if(!_0x591739)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x2e327e['snapshot']['type']!==_0x591739['type']||_0x2e327e['snapshot']['rev']<0x1||_0x2e327e['snapshot']['rev']>_0x591739['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x2e327e['snapshot']['unitID'],_0x2d2a98),this['_database']['prepare']('INSERT\x20INTO\x20collaboration_snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20type,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(unit_id,\x20revision)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20=\x20excluded.type,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json')['run'](_0x2e327e['snapshot']['unitID'],_0x2e327e['snapshot']['rev'],_0x2e327e['snapshot']['type'],_0x3e20b5);});}async['getSheetBlock'](_0x16544b,_0xc6fd,_0x1afba5){this['_assertOpen']();let _0x44151e=this['_database']['prepare']('SELECT\x20collaboration_sheet_blocks.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_sheet_blocks\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_units.unit_id\x20=\x20collaboration_sheet_blocks.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20collaboration_sheet_blocks.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_sheet_blocks.block_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20collaboration_units.soft_deleted_at_ms\x20IS\x20NULL')['get'](_0xc6fd,_0x1afba5);return _0x44151e?C(_0x44151e['payload_json']):null;}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_initializeSchema'](){this['_transaction'](()=>{if(!this['_hasTable']('collaboration_schema_versions')){if(this['_hasAnyCoreTable']())throw b('SQLite\x20collaboration\x20core\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 _0x559c4e=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(_0x559c4e){if(_0x559c4e['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x559c4e['version']+'\x20is\x20not\x20supported');let _0x2b5172=m['filter'](_0xda8535=>!this['_hasTable'](_0xda8535));if(_0x2b5172['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+p+'\x20is\x20incomplete:\x20missing\x20'+_0x2b5172['join'](',\x20'));return;}if(this['_hasAnyCoreTable']())throw b('SQLite\x20collaboration\x20core\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_units\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20head_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(head_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20soft_deleted_at_ms\x20INTEGER\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_unit_tombstones\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20purged_at\x20INTEGER\x20NOT\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20collaboration_snapshots\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\x20revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\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(unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_changesets\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\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(unit_id,\x20revision),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20UNIQUE\x20(unit_id,\x20sid,\x20req_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_sheet_blocks\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\x20block_id\x20TEXT\x20NOT\x20NULL,\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(unit_id,\x20block_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_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_resources\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\x20resource_id\x20TEXT\x20NOT\x20NULL,\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(unit_id,\x20resource_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20REFERENCES\x20collaboration_units(unit_id)\x20ON\x20DELETE\x20CASCADE\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_snapshots_nearest_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_snapshots(unit_id,\x20revision\x20DESC);\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20collaboration_changesets_revision_range\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20collaboration_changesets(unit_id,\x20revision\x20ASC);\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(\x27core\x27,\x201);\x0a\x20\x20\x20\x20\x20\x20');});}['_getActiveUnitRow'](_0x428d48){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20soft_deleted_at_ms\x20IS\x20NULL')['get'](_0x428d48)??null;}['_getStoredUnitRow'](_0x1b5066){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20soft_deleted_at_ms\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20collaboration_units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x1b5066)??null;}['_hasTombstone'](_0x1d58cc){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x1d58cc);}['_hasTable'](_0x116a7a){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'](_0x116a7a);}['_hasAnyCoreTable'](){return m['some'](_0x3ef240=>this['_hasTable'](_0x3ef240));}['_writeSheetBlocks'](_0x4692f9,_0x2aa76d){let _0x368003=this['_database']['prepare']('INSERT\x20INTO\x20collaboration_sheet_blocks\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20block_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?)\x0a\x20\x20\x20\x20\x20\x20\x20ON\x20CONFLICT(unit_id,\x20block_id)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json');for(let _0x22994b of _0x2aa76d)_0x368003['run'](_0x4692f9,_0x22994b['id'],_0x22994b['payload']);}['_transaction'](_0x2993b2){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x5492bd=_0x2993b2();return this['_database']['exec']('COMMIT;'),_0x5492bd;}catch(_0x445ef7){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x445ef7;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x3b57a8){if(!_0x3b57a8['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x3b57a8['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x3b57a8['busyTimeoutMs'])||_0x3b57a8['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x3e9eec){let {record:_0x36dee6,snapshot:_0x1777aa}=_0x3e9eec;if(_0x36dee6['headRevision']!==0x1||_0x1777aa['rev']!==0x1||_0x1777aa['unitID']!==_0x36dee6['unitID']||_0x1777aa['type']!==_0x36dee6['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');}function v(_0x55a311){return{'unitID':_0x55a311['unit_id'],'type':_0x55a311['type'],'headRevision':_0x55a311['head_revision']};}function y(_0x124386){return new l['CollabError']('INVALID_REQUEST',_0x124386);}function b(_0x4f3f40){return new l['CollabError']('INTERNAL_ERROR',_0x4f3f40);}function x(_0x23e8f8){return[...new Set(_0x23e8f8)];}function S(_0x52620e){return JSON['stringify'](_0x52620e,function(_0x46cc42,_0x3f7ac2){let _0x5d429f=this[_0x46cc42];return _0x5d429f instanceof Uint8Array?{[d]:Buffer['from'](_0x5d429f)['toString']('base64')}:_0x3f7ac2;});}function C(_0xb55a28){return JSON['parse'](_0xb55a28,(_0x1b719b,_0x54fd97)=>w(_0x54fd97)?Uint8Array['from'](Buffer['from'](_0x54fd97[d],'base64')):_0x54fd97);}function w(_0x486a17){return typeof _0x486a17=='object'&&!!_0x486a17&&Object['keys'](_0x486a17)['length']===0x1&&typeof _0x486a17[d]=='string';}exports['SQLiteDatabaseAdapter']=h;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ChangesetRange, CommitChangesetInput, CommitChangesetResult, CreateUnitDatabaseInput, CreateUnitDatabaseResult, DatabaseContext, DeleteUnitsDatabaseInput, DeleteUnitsDatabaseResult, IDatabaseAdapter, RecoverUnitsDatabaseInput, RecoverUnitsDatabaseResult, SaveSnapshotInput, UnitRecord } from "@univerjs-pro/collaboration-service";
2
- import { IChangeset, IGetResourcesResponse, ISheetBlock, ISnapshot } from "@univerjs/protocol";
1
+ import { CommitChangesetInput, CommitChangesetResult, CreateUnitDatabaseInput, CreateUnitDatabaseResult, DatabaseContext, DeleteUnitsDatabaseInput, DeleteUnitsDatabaseResult, IDatabaseAdapter, RecoverUnitsDatabaseInput, RecoverUnitsDatabaseResult, SaveSnapshotInput, SnapshotInfo, UnitRecord } from "@univerjs-pro/collaboration-service";
2
+ import { IChangeset, ISheetBlock, ISnapshot } from "@univerjs/protocol";
3
3
 
4
4
  //#region src/sqlite-database-adapter.d.ts
5
5
  interface SQLiteDatabaseAdapterOptions {
@@ -14,18 +14,19 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
14
14
  getSnapshot(_context: DatabaseContext, unitID: string, options?: {
15
15
  readonly revision?: number;
16
16
  }): Promise<ISnapshot | null>;
17
+ getSnapshotInfo(_context: DatabaseContext, unitID: string, options?: {
18
+ readonly revision?: number;
19
+ }): Promise<SnapshotInfo | null>;
17
20
  getChangesets(_context: DatabaseContext, unitID: string, range: {
18
21
  readonly from: number;
19
- readonly to: number;
20
- }): Promise<ChangesetRange>;
21
- getSubmission(_context: DatabaseContext, unitID: string, sid: string, reqId: number): Promise<IChangeset | null>;
22
+ readonly to?: number;
23
+ }): Promise<readonly IChangeset[] | null>;
22
24
  createUnit(_context: DatabaseContext, input: CreateUnitDatabaseInput): Promise<CreateUnitDatabaseResult>;
23
25
  deleteUnits(_context: DatabaseContext, input: DeleteUnitsDatabaseInput): Promise<DeleteUnitsDatabaseResult>;
24
26
  recoverUnits(_context: DatabaseContext, input: RecoverUnitsDatabaseInput): Promise<RecoverUnitsDatabaseResult>;
25
27
  commitChangeset(_context: DatabaseContext, input: CommitChangesetInput): Promise<CommitChangesetResult>;
26
28
  saveSnapshot(_context: DatabaseContext, input: SaveSnapshotInput): Promise<void>;
27
29
  getSheetBlock(_context: DatabaseContext, unitID: string, blockID: string): Promise<ISheetBlock | null>;
28
- getResources(_context: DatabaseContext, unitID: string, resourceIDs: readonly string[]): Promise<Readonly<IGetResourcesResponse["resources"]>>;
29
30
  dispose(): Promise<void>;
30
31
  private _initializeSchema;
31
32
  private _getActiveUnitRow;
@@ -33,7 +34,7 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
33
34
  private _hasTombstone;
34
35
  private _hasTable;
35
36
  private _hasAnyCoreTable;
36
- private _writeDependencies;
37
+ private _writeSheetBlocks;
37
38
  private _transaction;
38
39
  private _assertOpen;
39
40
  }
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const _0x3c01e8=_0x1173;function _0x1173(_0x4de62a,_0x4b16d6){_0x4de62a=_0x4de62a-0x1ac;const _0x239a37=_0x239a();let _0x1173d4=_0x239a37[_0x4de62a];return _0x1173d4;}(function(_0x3aaa04,_0x5462b7){const _0x57debb=_0x1173,_0x4a3e3e=_0x3aaa04();while(!![]){try{const _0xf988ca=-parseInt(_0x57debb(0x1b0))/0x1+parseInt(_0x57debb(0x1ac))/0x2+parseInt(_0x57debb(0x1ad))/0x3*(parseInt(_0x57debb(0x1af))/0x4)+-parseInt(_0x57debb(0x1b1))/0x5+-parseInt(_0x57debb(0x1b4))/0x6+-parseInt(_0x57debb(0x1b2))/0x7+parseInt(_0x57debb(0x1ae))/0x8;if(_0xf988ca===_0x5462b7)break;else _0x4a3e3e['push'](_0x4a3e3e['shift']());}catch(_0x311fd2){_0x4a3e3e['push'](_0x4a3e3e['shift']());}}}(_0x239a,0x8f81c));import _0x3c25d3 from'./index.cjs';const facadeExport0=_0x3c25d3[_0x3c01e8(0x1b3)];export{facadeExport0 as SQLiteDatabaseAdapter};function _0x239a(){const _0x2ec07e=['SQLiteDatabaseAdapter','6812886jsPCXx','976830NXolDF','3JYmIIs','22997072BgsjWy','1230308ynGtDE','314189DXfBNL','3620985TshcVd','6362685pGAbOR'];_0x239a=function(){return _0x2ec07e;};return _0x239a();}
1
+ const _0xcedaf6=_0x1a42;(function(_0x1ee396,_0xc162a8){const _0x2ab62f=_0x1a42,_0x54fffa=_0x1ee396();while(!![]){try{const _0x5c2ca1=-parseInt(_0x2ab62f(0x8b))/0x1+parseInt(_0x2ab62f(0x8f))/0x2+parseInt(_0x2ab62f(0x8a))/0x3+parseInt(_0x2ab62f(0x8e))/0x4+parseInt(_0x2ab62f(0x86))/0x5*(-parseInt(_0x2ab62f(0x88))/0x6)+-parseInt(_0x2ab62f(0x8c))/0x7*(parseInt(_0x2ab62f(0x8d))/0x8)+-parseInt(_0x2ab62f(0x85))/0x9*(parseInt(_0x2ab62f(0x87))/0xa);if(_0x5c2ca1===_0xc162a8)break;else _0x54fffa['push'](_0x54fffa['shift']());}catch(_0x4543a9){_0x54fffa['push'](_0x54fffa['shift']());}}}(_0x501a,0x42f8b));function _0x1a42(_0x11a82d,_0x2675be){_0x11a82d=_0x11a82d-0x85;const _0x501ad9=_0x501a();let _0x1a424e=_0x501ad9[_0x11a82d];return _0x1a424e;}import _0x2229e5 from'./index.cjs';function _0x501a(){const _0x55b635=['1394930mXcxSk','987438TlmmbC','SQLiteDatabaseAdapter','1414923pCBPZG','355334ZUdPJV','4158SiiQyN','3808DRCzxQ','2095908arpOyH','1049814wHUTaz','18vplnyC','10nOvnsy'];_0x501a=function(){return _0x55b635;};return _0x501a();}const facadeExport0=_0x2229e5[_0xcedaf6(0x89)];export{facadeExport0 as SQLiteDatabaseAdapter};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
7
- "version": "1.0.0-insiders.20260805-b15e7f3",
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,11 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@univerjs-pro/collaboration-service": "1.0.0-insiders.20260805-b15e7f3",
23
- "@univerjs/protocol": "1.0.0-insiders.20260805-b15e7f3",
22
+ "@univerjs-pro/collaboration-service": "1.0.0-rc.0",
23
+ "@univerjs/protocol": "1.0.0-rc.0",
24
24
  "libsql": "^0.5.29"
25
- },
26
- "publishConfig": {
27
- "access": "public"
28
25
  }
29
- }
26
+ }