@univerjs-pro/collaboration-database-sqlite 1.0.0-rc.0 → 1.0.1

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 CHANGED
@@ -49,8 +49,35 @@ It stores only core collaboration data. Product resources, users, ACLs, History,
49
49
 
50
50
  - It does not change `journal_mode`; configure WAL, checkpointing, or backup policy before opening the Adapter when needed.
51
51
  - Core tables use the `collaboration_` prefix.
52
- - Schema version `('core', 1)` is stored in `collaboration_schema_versions`; `PRAGMA user_version` is not used.
52
+ - Schema version `('core', 2)` is stored in `collaboration_schema_versions`; `PRAGMA user_version` is not used.
53
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
54
  - An empty database is initialized automatically. Incomplete or unsupported core schemas are rejected.
55
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.
56
+ This implementation suits local applications and small-to-medium single-Node deployments.
57
+
58
+ ## Explicit v1 → v2 migration
59
+
60
+ V2 adds required `creator_id` (creator) and `created_at_ms` (creation time, Unix milliseconds)
61
+ to `collaboration_units`, and required `created_at_ms` (commit time, Unix milliseconds)
62
+ to `collaboration_changesets`.
63
+
64
+ Stop writers and back up the file,
65
+ then migrate before constructing the Adapter. Opening an old database does not migrate it automatically.
66
+
67
+ ```ts
68
+ import { migrateSQLiteCoreV1ToV2 } from '@univerjs-pro/collaboration-database-sqlite';
69
+
70
+ await migrateSQLiteCoreV1ToV2({ filename: './data/collaboration.sqlite' });
71
+ ```
72
+
73
+ Missing data is filled using these rules:
74
+
75
+ - Unit creator and creation time: revision 1's `user_id` and `committed_at` in `collaboration_history_revisions` in the same database.
76
+ - Changeset time: payload `createTime` (seconds), then the matching History revision's `committed_at` (milliseconds).
77
+ - Missing or invalid information: `anonymous` for the creator and the migration start time for timestamps.
78
+ These fallback values do not represent historical facts.
79
+
80
+ Optional `resolveUnitCreation(unitID)` and `resolveChangesetCreatedAt(unitID, revision)` callbacks
81
+ replace the defaults. They may be async and return `{ creatorID, createdAt }` and a timestamp,
82
+ respectively, using Unix milliseconds. They cover soft-deleted Units too and must not write to
83
+ the same database. Invalid callback results or exceptions roll back the migration.
package/README.zh-CN.md CHANGED
@@ -51,11 +51,34 @@ Adapter 使用 foreign keys 和 `BEGIN IMMEDIATE` 写事务,保证:
51
51
 
52
52
  - 不主动修改 `journal_mode`;需要 WAL、checkpoint 或备份策略时由应用在打开前配置。
53
53
  - 核心表使用 `collaboration_` 前缀。
54
- - schema 版本以 `('core', 1)` 写入 `collaboration_schema_versions`,不占用
54
+ - schema 版本以 `('core', 2)` 写入 `collaboration_schema_versions`,不占用
55
55
  `PRAGMA user_version`。
56
56
  - changeset 标量列和 submission unique constraint 提供数据库级完整性;提交只做 revision
57
57
  CAS,不按 submission key 点查。
58
58
  - 空库会自动初始化;不完整或不支持的核心 schema 会被拒绝。
59
59
 
60
- 本实现适合本地应用和中小规模单 Node 部署。多个 Service 实例共享数据库文件时,
61
- revision CAS 仍能保证协同数据正确性。
60
+ 本实现适合本地应用和中小规模单 Node 部署。
61
+
62
+ ## 显式 v1 → v2 迁移
63
+
64
+ v2 为 `collaboration_units` 新增必填的 `creator_id`(创建者)和
65
+ `created_at_ms`(创建时间,Unix 毫秒),为 `collaboration_changesets` 新增必填的
66
+ `created_at_ms`(提交时间,Unix 毫秒)。
67
+
68
+ 停止写入并备份后,在构造 Adapter 前执行;打开旧库不会自动迁移。
69
+
70
+ ```ts
71
+ import { migrateSQLiteCoreV1ToV2 } from '@univerjs-pro/collaboration-database-sqlite';
72
+
73
+ await migrateSQLiteCoreV1ToV2({ filename: './data/collaboration.sqlite' });
74
+ ```
75
+
76
+ 默认按以下规则补齐数据:
77
+
78
+ - Unit 创建者和时间:同一数据库中 `collaboration_history_revisions` 的 revision 1 记录中的 `user_id`、`committed_at`。
79
+ - Changeset 时间:优先使用 payload 的 `createTime`(秒),其次使用对应 History revision 的 `committed_at`(毫秒)。
80
+ - 信息缺失或非法:创建者使用 `anonymous`,时间使用本次迁移开始时间。这些兜底值不代表真实历史。
81
+
82
+ 可选回调 `resolveUnitCreation(unitID)` 和 `resolveChangesetCreatedAt(unitID, revision)`
83
+ 可覆盖默认策略,分别返回 `{ creatorID, createdAt }` 和时间值,时间均为 Unix 毫秒,支持异步。
84
+ 回调也包含软删除 Unit,不得写入同一数据库;返回非法值或抛出异常会使迁移整体回滚。
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=(_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;
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=(_0x1d5315,_0xfdb949,_0xd9b2e0,_0x1eb31b)=>{if(_0xfdb949&&typeof _0xfdb949=='object'||typeof _0xfdb949=='function'){for(var _0xd0faca=r(_0xfdb949),_0x4e7ef9=0x0,_0x4eac0f=_0xd0faca['length'],_0x9f2762;_0x4e7ef9<_0x4eac0f;_0x4e7ef9++)_0x9f2762=_0xd0faca[_0x4e7ef9],!a['call'](_0x1d5315,_0x9f2762)&&_0x9f2762!==_0xd9b2e0&&t(_0x1d5315,_0x9f2762,{'get':(_0x3aa1b1=>_0xfdb949[_0x3aa1b1])['bind'](null,_0x9f2762),'enumerable':!(_0x1eb31b=n(_0xfdb949,_0x9f2762))||_0x1eb31b['enumerable']});}return _0x1d5315;},s=(_0x4b1bce,_0x14be88,_0x3b6fd8)=>(_0x3b6fd8=_0x4b1bce==null?{}:e(i(_0x4b1bce)),o(_0x14be88||!_0x4b1bce||!_0x4b1bce['__esModule']?t(_0x3b6fd8,'default',{'value':_0x4b1bce,'enumerable':!0x0}):_0x3b6fd8,_0x4b1bce));let c=require('libsql');c=s(c,0x1);let l=require('@univerjs-pro/collaboration-service');var u=0x1388,d='__univerCollaborationBinary',f='core',p=0x2,m=['collaboration_units','collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'],h=class{['_database'];['_disposed']=!0x1;constructor(_0x37c1d7){g(_0x37c1d7),this['_database']=new c['default'](_0x37c1d7['filename'],{'timeout':_0x37c1d7['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x37c1d7['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x391c73){throw this['_database']['close'](),_0x391c73;}}async['getUnit'](_0x248542,_0x38e516){this['_assertOpen']();let _0x426a11=this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20creator_id,\x20created_at_ms,\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'](_0x38e516);return _0x426a11?v(_0x426a11):null;}async['getSnapshot'](_0x29f5e1,_0x11d7c8,_0x4d5c15){this['_assertOpen']();let _0x4b59b0=_0x4d5c15?.['revision'];if(_0x4b59b0!==void 0x0&&_0x4b59b0<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x9530e3=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\x20'+(_0x4b59b0===void 0x0?'':'AND\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'](_0x11d7c8,..._0x4b59b0===void 0x0?[]:[_0x4b59b0]);return _0x9530e3?C(_0x9530e3['payload_json']):null;}async['getSnapshotInfo'](_0x57aec3,_0x3dbdab,_0x4c8a74){this['_assertOpen']();let _0x5cd4b2=_0x4c8a74?.['revision'];if(_0x5cd4b2!==void 0x0&&_0x5cd4b2<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x523622=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\x20'+(_0x5cd4b2===void 0x0?'':'AND\x20snapshots.revision\x20<=\x20?')+'\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'](_0x3dbdab,..._0x5cd4b2===void 0x0?[]:[_0x5cd4b2]);return _0x523622?{'unitID':_0x523622['unitID'],'type':_0x523622['type'],'rev':_0x523622['rev']}:null;}async['getChangesets'](_0x4ffd56,_0x35d27e,_0x2cdfab){if(this['_assertOpen'](),_0x2cdfab['from']<0x0||_0x2cdfab['to']!==void 0x0&&_0x2cdfab['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x51ed4e=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'+(_0x2cdfab['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'](_0x2cdfab['from'],..._0x2cdfab['to']===void 0x0?[]:[_0x2cdfab['to']],_0x35d27e);return _0x51ed4e['length']===0x0?null:_0x51ed4e['flatMap'](_0x26343b=>_0x26343b['payload_json']?[C(_0x26343b['payload_json'])]:[]);}async['createUnit'](_0x5f0ec9,_0x3fbeff){this['_assertOpen'](),_(_0x3fbeff);let _0x1147be=S(_0x3fbeff['snapshot']),_0x3db414=(_0x3fbeff['sheetBlocks']??[])['map'](_0x4b05d3=>({'id':_0x4b05d3['id'],'payload':S(_0x4b05d3)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x3fbeff['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x588dae=this['_getStoredUnitRow'](_0x3fbeff['record']['unitID']);if(_0x588dae){if(_0x588dae['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x588dae)};}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,\x20creator_id,\x20created_at_ms,\x20soft_deleted_at_ms)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x201,\x20?,\x20?,\x20NULL)')['run'](_0x3fbeff['record']['unitID'],_0x3fbeff['record']['type'],_0x3fbeff['record']['creatorID'],_0x3fbeff['record']['createdAt']),this['_writeSheetBlocks'](_0x3fbeff['record']['unitID'],_0x3db414),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'](_0x3fbeff['record']['unitID'],_0x3fbeff['record']['type'],_0x1147be),{'status':'created','record':{..._0x3fbeff['record']}};});}async['deleteUnits'](_0x1dc96f,_0x28d358){return this['_assertOpen'](),this['_transaction'](()=>{let _0x3531bd=x(_0x28d358['unitIDs'])['map'](_0x332029=>{let _0x39f73c=this['_getStoredUnitRow'](_0x332029);if(!_0x39f73c){if(_0x28d358['hardDelete']&&this['_hasTombstone'](_0x332029))return{'unitID':_0x332029,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x28d358['hardDelete']?{'unitID':_0x332029,'status':'hard-deleted'}:{'unitID':_0x332029,'status':_0x39f73c['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x5e311f=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'),_0x3b240a=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?)'),_0x3fd847=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x358b15=Date['now']();for(let _0x76fc9f of _0x3531bd)_0x76fc9f['status']==='soft-deleted'?_0x5e311f['run'](_0x358b15,_0x76fc9f['unitID']):_0x76fc9f['status']==='hard-deleted'&&(_0x3b240a['run'](_0x76fc9f['unitID'],_0x358b15),_0x3fd847['run'](_0x76fc9f['unitID']));return{'units':_0x3531bd};});}async['recoverUnits'](_0x51ee6a,_0x5e5a55){return this['_assertOpen'](),this['_transaction'](()=>{let _0x4adc4c=x(_0x5e5a55['unitIDs'])['map'](_0x5b8a0e=>{let _0x1f9141=this['_getStoredUnitRow'](_0x5b8a0e);if(!_0x1f9141)throw this['_hasTombstone'](_0x5b8a0e)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x5b8a0e,'status':_0x1f9141['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x260fdf=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 _0x2a2ab5 of _0x4adc4c)_0x2a2ab5['status']==='recovered'&&_0x260fdf['run'](_0x2a2ab5['unitID']);return{'units':_0x4adc4c};});}async['commitChangeset'](_0x591073,_0x5194cf){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x412f5f}=_0x5194cf,_0x142d74=this['_getActiveUnitRow'](_0x412f5f['unitID']);if(!_0x142d74)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x142d74['head_revision']!==_0x412f5f['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x142d74['head_revision']};let _0x60982d=Date['now'](),_0x189762=S({..._0x412f5f,'createTime':Math['floor'](_0x60982d/0x3e8)});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,\x20created_at_ms,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x412f5f['unitID'],_0x412f5f['revision'],_0x412f5f['baseRev'],_0x412f5f['sid'],_0x412f5f['reqId'],_0x60982d,_0x189762),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'](_0x412f5f['revision'],_0x412f5f['unitID'],_0x412f5f['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x189762),'headRevision':_0x412f5f['revision']};});}async['saveSnapshot'](_0x13d24d,_0x499b0e){this['_assertOpen']();let _0x258ed6=S(_0x499b0e['snapshot']),_0x1fed5b=(_0x499b0e['sheetBlocks']??[])['map'](_0x40a733=>({'id':_0x40a733['id'],'payload':S(_0x40a733)}));this['_transaction'](()=>{let _0x2b3b0b=this['_getActiveUnitRow'](_0x499b0e['snapshot']['unitID']);if(!_0x2b3b0b)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x499b0e['snapshot']['type']!==_0x2b3b0b['type']||_0x499b0e['snapshot']['rev']<0x1||_0x499b0e['snapshot']['rev']>_0x2b3b0b['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x499b0e['snapshot']['unitID'],_0x1fed5b),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'](_0x499b0e['snapshot']['unitID'],_0x499b0e['snapshot']['rev'],_0x499b0e['snapshot']['type'],_0x258ed6);});}async['getSheetBlock'](_0x133cda,_0x4dc414,_0x16b408){this['_assertOpen']();let _0x3b19b3=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'](_0x4dc414,_0x16b408);return _0x3b19b3?C(_0x3b19b3['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 _0x51869f=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(_0x51869f){if(_0x51869f['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x51869f['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x4598ad=m['filter'](_0x18280b=>!this['_hasTable'](_0x18280b));if(_0x4598ad['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x51869f['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x4598ad['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x44a2d=>_0x44a2d['name']==='created_at_ms'&&_0x44a2d['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x5f418f=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x39e4dc=>_0x5f418f['some'](_0x52ed78=>_0x52ed78['name']===_0x39e4dc&&_0x52ed78['notnull']===0x1)))throw b('SQLite\x20collaboration\x20core\x20schema\x20v2\x20requires\x20NOT\x20NULL\x20creator_id\x20and\x20created_at_ms');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\x20creator_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL,\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\x20created_at_ms\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\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\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,\x202);\x0a\x20\x20\x20\x20\x20\x20');});}['_getActiveUnitRow'](_0x15f837){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20creator_id,\x20created_at_ms,\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'](_0x15f837)??null;}['_getStoredUnitRow'](_0x57683e){return this['_database']['prepare']('SELECT\x20unit_id,\x20type,\x20head_revision,\x20creator_id,\x20created_at_ms,\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'](_0x57683e)??null;}['_hasTombstone'](_0x5197f5){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x5197f5);}['_hasTable'](_0x186377){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'](_0x186377);}['_hasAnyCoreTable'](){return m['some'](_0x5ce4c4=>this['_hasTable'](_0x5ce4c4));}['_writeSheetBlocks'](_0x4117c8,_0x1d976d){let _0x1b49bd=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 _0x1120b9 of _0x1d976d)_0x1b49bd['run'](_0x4117c8,_0x1120b9['id'],_0x1120b9['payload']);}['_transaction'](_0x131a76){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x455b9a=_0x131a76();return this['_database']['exec']('COMMIT;'),_0x455b9a;}catch(_0x56deb8){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x56deb8;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x49f717){if(!_0x49f717['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x49f717['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x49f717['busyTimeoutMs'])||_0x49f717['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x3baabf){let {record:_0x25e480,snapshot:_0xdc04d6}=_0x3baabf;if(_0x25e480['headRevision']!==0x1||_0xdc04d6['rev']!==0x1||_0xdc04d6['unitID']!==_0x25e480['unitID']||_0xdc04d6['type']!==_0x25e480['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x25e480['creatorID']!='string'||_0x25e480['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x25e480['createdAt'])||_0x25e480['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0xb5e47f){return{'unitID':_0xb5e47f['unit_id'],'type':_0xb5e47f['type'],'headRevision':_0xb5e47f['head_revision'],'creatorID':_0xb5e47f['creator_id'],'createdAt':_0xb5e47f['created_at_ms']};}function y(_0x3285f1){return new l['CollabError']('INVALID_REQUEST',_0x3285f1);}function b(_0xf00676){return new l['CollabError']('INTERNAL_ERROR',_0xf00676);}function x(_0xfab486){return[...new Set(_0xfab486)];}function S(_0x3e9401){return JSON['stringify'](_0x3e9401,function(_0x4ce97d,_0x10af77){let _0x55aeed=this[_0x4ce97d];return _0x55aeed instanceof Uint8Array?{[d]:Buffer['from'](_0x55aeed)['toString']('base64')}:_0x10af77;});}function C(_0x24c5d9){return JSON['parse'](_0x24c5d9,(_0x39dd96,_0xd2f2f6)=>w(_0xd2f2f6)?Uint8Array['from'](Buffer['from'](_0xd2f2f6[d],'base64')):_0xd2f2f6);}function w(_0x10720d){return typeof _0x10720d=='object'&&!!_0x10720d&&Object['keys'](_0x10720d)['length']===0x1&&typeof _0x10720d[d]=='string';}async function T(_0x3b539b){let _0x144124=Date['now'](),_0x355079=new c['default'](_0x3b539b['filename'],{'fileMustExist':!0x0}),_0x51bbe9=!0x1;try{if(_0x355079['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x51bbe9=!0x0,_0x355079['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27core\x27')['get']()?.['version']!==0x1)throw new l['CollabError']('INVALID_REQUEST','migrateSQLiteCoreV1ToV2\x20requires\x20core\x20schema\x20version\x201');for(let _0x2435a8 of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x355079['prepare']('SELECT\x201\x20FROM\x20'+_0x2435a8+'\x20LIMIT\x200')['all']();let _0x31d88b=_0x355079['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x355079['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x4c501b=(_0x4dac39,_0x2ad5b7)=>_0x31d88b?.['get'](_0x4dac39,_0x2ad5b7),_0x17eb37=_0x355079['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x358da0=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x17eb37['length']!==_0x358da0['length']||_0x358da0['some'](_0x44c7f7=>!_0x17eb37['some'](_0x5ee2ee=>_0x5ee2ee['name']===_0x44c7f7)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x1b1805=_0x355079['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20tbl_name\x20=\x20\x27collaboration_units\x27\x20AND\x20type\x20IN\x20(\x27index\x27,\x20\x27trigger\x27)\x20AND\x20sql\x20IS\x20NOT\x20NULL')['all']();_0x355079['exec']('CREATE\x20TABLE\x20collaboration_units_v2\x20(\x0a\x20\x20\x20\x20\x20\x20unit_id\x20TEXT\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20type\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20head_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(head_revision\x20>=\x201),\x0a\x20\x20\x20\x20\x20\x20creator_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20soft_deleted_at_ms\x20INTEGER\x0a\x20\x20\x20\x20);');let _0x50ac0d=D(_0x355079,'collaboration_units',['unit_id']),_0x394771=_0x355079['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x144d7a of _0x50ac0d){let _0x383c54=_0x3b539b['resolveUnitCreation']?void 0x0:_0x4c501b(_0x144d7a['unit_id'],0x1),_0xa2a518=_0x3b539b['resolveUnitCreation']?await _0x3b539b['resolveUnitCreation'](_0x144d7a['unit_id']):{'creatorID':_0x383c54?.['user_id']||'anonymous','createdAt':E(_0x383c54?.['committed_at'])?_0x383c54['committed_at']:_0x144124};if(!_0xa2a518||typeof _0xa2a518['creatorID']!='string'||_0xa2a518['creatorID']['length']===0x0||!Number['isSafeInteger'](_0xa2a518['createdAt'])||_0xa2a518['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x144d7a['unit_id']);_0x394771['run'](_0x144d7a['unit_id'],_0x144d7a['type'],_0x144d7a['head_revision'],_0xa2a518['creatorID'],_0xa2a518['createdAt'],_0x144d7a['soft_deleted_at_ms']);}_0x355079['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0x21ae33 of _0x1b1805)_0x355079['exec'](_0x21ae33['sql']);let _0x1d9415=_0x355079['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0xce2734=_0x355079['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0xce2734['some'](_0x56c6d3=>_0x56c6d3['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x3a77e3=_0x355079['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20tbl_name\x20=\x20\x27collaboration_changesets\x27\x20AND\x20type\x20IN\x20(\x27index\x27,\x20\x27trigger\x27)\x20AND\x20sql\x20IS\x20NOT\x20NULL')['all']();_0x355079['exec']('CREATE\x20TABLE\x20collaboration_changesets_new\x20(\x0a\x20\x20\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20\x20\x20'+_0x1d9415['sql']['slice'](_0x1d9415['sql']['indexOf']('(')+0x1));let _0x55ab8a=D(_0x355079,'collaboration_changesets',['unit_id','revision']),_0x76a9b0=_0xce2734['map'](_0x14d5f5=>'\x22'+_0x14d5f5['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x39ce79=_0x355079['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x76a9b0+',\x20created_at_ms)\x20VALUES\x20('+_0xce2734['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x334f60 of _0x55ab8a){let _0x303a0a=JSON['parse'](_0x334f60['payload_json']),_0x118b05=typeof _0x303a0a['createTime']=='number'?_0x303a0a['createTime']*0x3e8:void 0x0,_0x470224=!_0x3b539b['resolveChangesetCreatedAt']&&!E(_0x118b05)?_0x4c501b(_0x334f60['unit_id'],_0x334f60['revision'])?.['committed_at']:void 0x0,_0x2666c6=_0x3b539b['resolveChangesetCreatedAt']?await _0x3b539b['resolveChangesetCreatedAt'](_0x334f60['unit_id'],_0x334f60['revision']):E(_0x118b05)?_0x118b05:E(_0x470224)?_0x470224:_0x144124;if(!Number['isSafeInteger'](_0x2666c6)||_0x2666c6<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x334f60['unit_id']+'\x20revision\x20'+_0x334f60['revision']);_0x303a0a['createTime']=Math['floor'](_0x2666c6/0x3e8),_0x39ce79['run'](..._0xce2734['map'](_0x145d74=>_0x145d74['name']==='payload_json'?JSON['stringify'](_0x303a0a):_0x334f60[_0x145d74['name']]),_0x2666c6);}_0x355079['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x22e5f0 of _0x3a77e3)_0x355079['exec'](_0x22e5f0['sql']);if(_0x355079['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x355079['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x51bbe9=!0x1;}finally{try{_0x51bbe9&&_0x355079['exec']('ROLLBACK;');}finally{_0x355079['close']();}}}function E(_0x5069a7){return typeof _0x5069a7=='number'&&Number['isSafeInteger'](_0x5069a7)&&_0x5069a7>=0x0;}function*D(_0x583f83,_0x5ee2f4,_0x1243ca){let _0x2485b4=_0x1243ca['join'](',\x20'),_0x49d21d=_0x583f83['prepare']('SELECT\x20*\x20FROM\x20'+_0x5ee2f4+'\x20ORDER\x20BY\x20'+_0x2485b4+'\x20LIMIT\x20100'),_0x19e24c=_0x583f83['prepare']('SELECT\x20*\x20FROM\x20'+_0x5ee2f4+'\x20WHERE\x20('+_0x2485b4+')\x20>\x20('+_0x1243ca['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x2485b4+'\x20LIMIT\x20100'),_0x5d9a69=_0x49d21d['all']();for(;_0x5d9a69['length']>0x0;){yield*_0x5d9a69;let _0x1313d6=_0x1243ca['map'](_0x46dcc6=>_0x5d9a69[_0x5d9a69['length']-0x1][_0x46dcc6]);_0x5d9a69=[],_0x5d9a69=_0x19e24c['all'](..._0x1313d6);}}exports['SQLiteDatabaseAdapter']=h,exports['migrateSQLiteCoreV1ToV2']=T;
package/dist/index.d.ts CHANGED
@@ -39,4 +39,12 @@ declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
39
39
  private _assertOpen;
40
40
  }
41
41
  //#endregion
42
- export { SQLiteDatabaseAdapter, type SQLiteDatabaseAdapterOptions };
42
+ //#region src/migrations/v1-to-v2.d.ts
43
+ interface SQLiteCoreV1ToV2MigrationOptions {
44
+ readonly filename: string;
45
+ readonly resolveUnitCreation?: (unitID: string) => Pick<UnitRecord, "creatorID" | "createdAt"> | Promise<Pick<UnitRecord, "creatorID" | "createdAt">>;
46
+ readonly resolveChangesetCreatedAt?: (unitID: string, revision: number) => number | Promise<number>;
47
+ }
48
+ declare function migrateSQLiteCoreV1ToV2(options: SQLiteCoreV1ToV2MigrationOptions): Promise<void>;
49
+ //#endregion
50
+ export { type SQLiteCoreV1ToV2MigrationOptions, SQLiteDatabaseAdapter, type SQLiteDatabaseAdapterOptions, migrateSQLiteCoreV1ToV2 };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
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};
1
+ const _0x175f7f=_0x5257;(function(_0x209d00,_0x4f6911){const _0x33acb1=_0x5257,_0x1f1c62=_0x209d00();while(!![]){try{const _0x127293=-parseInt(_0x33acb1(0x170))/0x1*(-parseInt(_0x33acb1(0x174))/0x2)+-parseInt(_0x33acb1(0x179))/0x3+parseInt(_0x33acb1(0x178))/0x4+-parseInt(_0x33acb1(0x16f))/0x5+-parseInt(_0x33acb1(0x173))/0x6*(-parseInt(_0x33acb1(0x175))/0x7)+parseInt(_0x33acb1(0x176))/0x8*(-parseInt(_0x33acb1(0x172))/0x9)+-parseInt(_0x33acb1(0x17a))/0xa*(-parseInt(_0x33acb1(0x177))/0xb);if(_0x127293===_0x4f6911)break;else _0x1f1c62['push'](_0x1f1c62['shift']());}catch(_0xc59e09){_0x1f1c62['push'](_0x1f1c62['shift']());}}}(_0x45fb,0x38f57));function _0x45fb(){const _0x21ca28=['49WhGIhl','migrateSQLiteCoreV1ToV2','9JesklN','6tlSXYu','13934vFXcIB','2796493BTpzTp','2140088ROpFRW','28237JswFid','564704iuvdwp','1124652nlaisv','1730bOoQZp','2252255ViQZNW'];_0x45fb=function(){return _0x21ca28;};return _0x45fb();}import _0x5e812d from'./index.cjs';function _0x5257(_0x5da46c,_0x21b815){_0x5da46c=_0x5da46c-0x16f;const _0x45fb76=_0x45fb();let _0x525714=_0x45fb76[_0x5da46c];return _0x525714;}const facadeExport0=_0x5e812d['SQLiteDatabaseAdapter'],facadeExport1=_0x5e812d[_0x175f7f(0x171)];export{facadeExport0 as SQLiteDatabaseAdapter,facadeExport1 as migrateSQLiteCoreV1ToV2};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
7
- "version": "1.0.0-rc.0",
7
+ "version": "1.0.1",
8
8
  "main": "./dist/index.cjs",
9
9
  "module": "./dist/index.mjs",
10
10
  "types": "./dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@univerjs-pro/collaboration-service": "1.0.0-rc.0",
23
- "@univerjs/protocol": "1.0.0-rc.0",
22
+ "@univerjs-pro/collaboration-service": "1.0.1",
23
+ "@univerjs/protocol": "1.0.1",
24
24
  "libsql": "^0.5.29"
25
25
  }
26
26
  }