@univerjs-pro/collaboration-database-sqlite 1.1.0 → 1.2.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/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=(_0x1d78a1,_0x5452d2,_0x3908d6,_0x2325c4)=>{if(_0x5452d2&&typeof _0x5452d2=='object'||typeof _0x5452d2=='function'){for(var _0x37b2ed=r(_0x5452d2),_0x1e2605=0x0,_0x518358=_0x37b2ed['length'],_0x3cfb7c;_0x1e2605<_0x518358;_0x1e2605++)_0x3cfb7c=_0x37b2ed[_0x1e2605],!a['call'](_0x1d78a1,_0x3cfb7c)&&_0x3cfb7c!==_0x3908d6&&t(_0x1d78a1,_0x3cfb7c,{'get':(_0x1ecd26=>_0x5452d2[_0x1ecd26])['bind'](null,_0x3cfb7c),'enumerable':!(_0x2325c4=n(_0x5452d2,_0x3cfb7c))||_0x2325c4['enumerable']});}return _0x1d78a1;},s=(_0x2065c2,_0x31fc10,_0x4d479b)=>(_0x4d479b=_0x2065c2==null?{}:e(i(_0x2065c2)),o(_0x31fc10||!_0x2065c2||!_0x2065c2['__esModule']?t(_0x4d479b,'default',{'value':_0x2065c2,'enumerable':!0x0}):_0x4d479b,_0x2065c2));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(_0x529b47){g(_0x529b47),this['_database']=new c['default'](_0x529b47['filename'],{'timeout':_0x529b47['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x529b47['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x42ea00){throw this['_database']['close'](),_0x42ea00;}}async['getUnit'](_0x14ef8d,_0x2815cb){this['_assertOpen']();let _0x4d6840=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'](_0x2815cb);return _0x4d6840?v(_0x4d6840):null;}async['getSnapshot'](_0x5d6613,_0x2381e2,_0x328f6a){this['_assertOpen']();let _0x4d6524=_0x328f6a?.['revision'];if(_0x4d6524!==void 0x0&&_0x4d6524<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x5b8c2e=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'+(_0x4d6524===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'](_0x2381e2,..._0x4d6524===void 0x0?[]:[_0x4d6524]);return _0x5b8c2e?C(_0x5b8c2e['payload_json']):null;}async['getSnapshotInfo'](_0x2408ec,_0x15d348,_0xc3040d){this['_assertOpen']();let _0x4a797c=_0xc3040d?.['revision'];if(_0x4a797c!==void 0x0&&_0x4a797c<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x2e9cf3=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'+(_0x4a797c===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'](_0x15d348,..._0x4a797c===void 0x0?[]:[_0x4a797c]);return _0x2e9cf3?{'unitID':_0x2e9cf3['unitID'],'type':_0x2e9cf3['type'],'rev':_0x2e9cf3['rev']}:null;}async['getChangesets'](_0x4d7278,_0x329b0a,_0x43f602){if(this['_assertOpen'](),_0x43f602['from']<0x0||_0x43f602['to']!==void 0x0&&_0x43f602['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x53b491=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'+(_0x43f602['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'](_0x43f602['from'],..._0x43f602['to']===void 0x0?[]:[_0x43f602['to']],_0x329b0a);return _0x53b491['length']===0x0?null:_0x53b491['flatMap'](_0x28c3ee=>_0x28c3ee['payload_json']?[C(_0x28c3ee['payload_json'])]:[]);}async['createUnit'](_0x10a0a2,_0x2754c6){this['_assertOpen'](),_(_0x2754c6);let _0x3c0620=S(_0x2754c6['snapshot']),_0x46bfd8=(_0x2754c6['sheetBlocks']??[])['map'](_0x71dff5=>({'id':_0x71dff5['id'],'payload':S(_0x71dff5)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x2754c6['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x38b281=this['_getStoredUnitRow'](_0x2754c6['record']['unitID']);if(_0x38b281){if(_0x38b281['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x38b281)};}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'](_0x2754c6['record']['unitID'],_0x2754c6['record']['type'],_0x2754c6['record']['creatorID'],_0x2754c6['record']['createdAt']),this['_writeSheetBlocks'](_0x2754c6['record']['unitID'],_0x46bfd8),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'](_0x2754c6['record']['unitID'],_0x2754c6['record']['type'],_0x3c0620),{'status':'created','record':{..._0x2754c6['record']}};});}async['deleteUnits'](_0x55e429,_0x16041a){return this['_assertOpen'](),this['_transaction'](()=>{let _0x497889=x(_0x16041a['unitIDs'])['map'](_0x4c7ce2=>{let _0x44a685=this['_getStoredUnitRow'](_0x4c7ce2);if(!_0x44a685){if(_0x16041a['hardDelete']&&this['_hasTombstone'](_0x4c7ce2))return{'unitID':_0x4c7ce2,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x16041a['hardDelete']?{'unitID':_0x4c7ce2,'status':'hard-deleted'}:{'unitID':_0x4c7ce2,'status':_0x44a685['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x526b43=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'),_0x4c5c93=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?)'),_0xfdcb16=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x27d142=Date['now']();for(let _0x245cf3 of _0x497889)_0x245cf3['status']==='soft-deleted'?_0x526b43['run'](_0x27d142,_0x245cf3['unitID']):_0x245cf3['status']==='hard-deleted'&&(_0x4c5c93['run'](_0x245cf3['unitID'],_0x27d142),_0xfdcb16['run'](_0x245cf3['unitID']));return{'units':_0x497889};});}async['recoverUnits'](_0x263590,_0x267d36){return this['_assertOpen'](),this['_transaction'](()=>{let _0x44e573=x(_0x267d36['unitIDs'])['map'](_0x17e7dd=>{let _0x235246=this['_getStoredUnitRow'](_0x17e7dd);if(!_0x235246)throw this['_hasTombstone'](_0x17e7dd)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x17e7dd,'status':_0x235246['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x392b27=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 _0xceda18 of _0x44e573)_0xceda18['status']==='recovered'&&_0x392b27['run'](_0xceda18['unitID']);return{'units':_0x44e573};});}async['commitChangeset'](_0x8020ee,_0x1e2d6a){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x32c791}=_0x1e2d6a,_0x22161b=this['_getActiveUnitRow'](_0x32c791['unitID']);if(!_0x22161b)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x22161b['head_revision']!==_0x32c791['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x22161b['head_revision']};let _0x25b187=Date['now'](),_0x5dc0e1=S({..._0x32c791,'createTime':Math['floor'](_0x25b187/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'](_0x32c791['unitID'],_0x32c791['revision'],_0x32c791['baseRev'],_0x32c791['sid'],_0x32c791['reqId'],_0x25b187,_0x5dc0e1),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'](_0x32c791['revision'],_0x32c791['unitID'],_0x32c791['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x5dc0e1),'headRevision':_0x32c791['revision']};});}async['saveSnapshot'](_0x56e981,_0x1c4ea0){this['_assertOpen']();let _0x2aba41=S(_0x1c4ea0['snapshot']),_0x311d35=(_0x1c4ea0['sheetBlocks']??[])['map'](_0x3a0760=>({'id':_0x3a0760['id'],'payload':S(_0x3a0760)}));this['_transaction'](()=>{let _0x49c74c=this['_getActiveUnitRow'](_0x1c4ea0['snapshot']['unitID']);if(!_0x49c74c)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x1c4ea0['snapshot']['type']!==_0x49c74c['type']||_0x1c4ea0['snapshot']['rev']<0x1||_0x1c4ea0['snapshot']['rev']>_0x49c74c['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x1c4ea0['snapshot']['unitID'],_0x311d35),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'](_0x1c4ea0['snapshot']['unitID'],_0x1c4ea0['snapshot']['rev'],_0x1c4ea0['snapshot']['type'],_0x2aba41);});}async['getSheetBlock'](_0x2a3048,_0x58f2ee,_0x34f261){this['_assertOpen']();let _0x59af92=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'](_0x58f2ee,_0x34f261);return _0x59af92?C(_0x59af92['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 _0x1993fa=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(_0x1993fa){if(_0x1993fa['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x1993fa['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x24898e=m['filter'](_0x5d1351=>!this['_hasTable'](_0x5d1351));if(_0x24898e['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x1993fa['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x24898e['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x1c0c43=>_0x1c0c43['name']==='created_at_ms'&&_0x1c0c43['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x8515c0=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x2e9db5=>_0x8515c0['some'](_0x11bc48=>_0x11bc48['name']===_0x2e9db5&&_0x11bc48['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'](_0x1d4f7d){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'](_0x1d4f7d)??null;}['_getStoredUnitRow'](_0x2c3336){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'](_0x2c3336)??null;}['_hasTombstone'](_0x39a454){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x39a454);}['_hasTable'](_0x415520){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'](_0x415520);}['_hasAnyCoreTable'](){return m['some'](_0x461516=>this['_hasTable'](_0x461516));}['_writeSheetBlocks'](_0xe60dbc,_0x373a0d){let _0x763581=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 _0x561aa4 of _0x373a0d)_0x763581['run'](_0xe60dbc,_0x561aa4['id'],_0x561aa4['payload']);}['_transaction'](_0x47228e){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x21934b=_0x47228e();return this['_database']['exec']('COMMIT;'),_0x21934b;}catch(_0x109b8f){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x109b8f;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x285e30){if(!_0x285e30['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x285e30['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x285e30['busyTimeoutMs'])||_0x285e30['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x5a92df){let {record:_0x28018d,snapshot:_0x150776}=_0x5a92df;if(_0x28018d['headRevision']!==0x1||_0x150776['rev']!==0x1||_0x150776['unitID']!==_0x28018d['unitID']||_0x150776['type']!==_0x28018d['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x28018d['creatorID']!='string'||_0x28018d['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x28018d['createdAt'])||_0x28018d['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0x159d07){return{'unitID':_0x159d07['unit_id'],'type':_0x159d07['type'],'headRevision':_0x159d07['head_revision'],'creatorID':_0x159d07['creator_id'],'createdAt':_0x159d07['created_at_ms']};}function y(_0x3df583){return new l['CollabError']('INVALID_REQUEST',_0x3df583);}function b(_0xa07302){return new l['CollabError']('INTERNAL_ERROR',_0xa07302);}function x(_0x5d071d){return[...new Set(_0x5d071d)];}function S(_0xf2d324){return JSON['stringify'](_0xf2d324,function(_0x44d940,_0x4cab27){let _0x57c8ee=this[_0x44d940];return _0x57c8ee instanceof Uint8Array?{[d]:Buffer['from'](_0x57c8ee)['toString']('base64')}:_0x4cab27;});}function C(_0x4571a2){return JSON['parse'](_0x4571a2,(_0x58a537,_0x38a800)=>w(_0x38a800)?Uint8Array['from'](Buffer['from'](_0x38a800[d],'base64')):_0x38a800);}function w(_0x57a76d){return typeof _0x57a76d=='object'&&!!_0x57a76d&&Object['keys'](_0x57a76d)['length']===0x1&&typeof _0x57a76d[d]=='string';}async function T(_0x3fc57e){let _0x4b989b=Date['now'](),_0x1c1e54=new c['default'](_0x3fc57e['filename'],{'fileMustExist':!0x0}),_0x4f24b5=!0x1;try{if(_0x1c1e54['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x4f24b5=!0x0,_0x1c1e54['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 _0x2b52e7 of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x1c1e54['prepare']('SELECT\x201\x20FROM\x20'+_0x2b52e7+'\x20LIMIT\x200')['all']();let _0x3d259f=_0x1c1e54['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x1c1e54['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x4356b9=(_0xeca4ac,_0x5e7bfd)=>_0x3d259f?.['get'](_0xeca4ac,_0x5e7bfd),_0x4e9d41=_0x1c1e54['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x425465=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x4e9d41['length']!==_0x425465['length']||_0x425465['some'](_0x44b6d9=>!_0x4e9d41['some'](_0x19d546=>_0x19d546['name']===_0x44b6d9)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x396ec9=_0x1c1e54['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']();_0x1c1e54['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 _0x5227ac=D(_0x1c1e54,'collaboration_units',['unit_id']),_0x24b321=_0x1c1e54['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x2033c9 of _0x5227ac){let _0x400818=_0x3fc57e['resolveUnitCreation']?void 0x0:_0x4356b9(_0x2033c9['unit_id'],0x1),_0x4d873a=_0x3fc57e['resolveUnitCreation']?await _0x3fc57e['resolveUnitCreation'](_0x2033c9['unit_id']):{'creatorID':_0x400818?.['user_id']||'anonymous','createdAt':E(_0x400818?.['committed_at'])?_0x400818['committed_at']:_0x4b989b};if(!_0x4d873a||typeof _0x4d873a['creatorID']!='string'||_0x4d873a['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x4d873a['createdAt'])||_0x4d873a['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x2033c9['unit_id']);_0x24b321['run'](_0x2033c9['unit_id'],_0x2033c9['type'],_0x2033c9['head_revision'],_0x4d873a['creatorID'],_0x4d873a['createdAt'],_0x2033c9['soft_deleted_at_ms']);}_0x1c1e54['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0xbd65e3 of _0x396ec9)_0x1c1e54['exec'](_0xbd65e3['sql']);let _0x57fec4=_0x1c1e54['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x5ad0cc=_0x1c1e54['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x5ad0cc['some'](_0x30f3aa=>_0x30f3aa['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x222dad=_0x1c1e54['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']();_0x1c1e54['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'+_0x57fec4['sql']['slice'](_0x57fec4['sql']['indexOf']('(')+0x1));let _0x43d606=D(_0x1c1e54,'collaboration_changesets',['unit_id','revision']),_0x21ab0e=_0x5ad0cc['map'](_0x559ff9=>'\x22'+_0x559ff9['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x3af3f0=_0x1c1e54['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x21ab0e+',\x20created_at_ms)\x20VALUES\x20('+_0x5ad0cc['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x2f7e6f of _0x43d606){let _0x22a429=JSON['parse'](_0x2f7e6f['payload_json']),_0xdc43d9=typeof _0x22a429['createTime']=='number'?_0x22a429['createTime']*0x3e8:void 0x0,_0x58648c=!_0x3fc57e['resolveChangesetCreatedAt']&&!E(_0xdc43d9)?_0x4356b9(_0x2f7e6f['unit_id'],_0x2f7e6f['revision'])?.['committed_at']:void 0x0,_0x35d94f=_0x3fc57e['resolveChangesetCreatedAt']?await _0x3fc57e['resolveChangesetCreatedAt'](_0x2f7e6f['unit_id'],_0x2f7e6f['revision']):E(_0xdc43d9)?_0xdc43d9:E(_0x58648c)?_0x58648c:_0x4b989b;if(!Number['isSafeInteger'](_0x35d94f)||_0x35d94f<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x2f7e6f['unit_id']+'\x20revision\x20'+_0x2f7e6f['revision']);_0x22a429['createTime']=Math['floor'](_0x35d94f/0x3e8),_0x3af3f0['run'](..._0x5ad0cc['map'](_0x29af0a=>_0x29af0a['name']==='payload_json'?JSON['stringify'](_0x22a429):_0x2f7e6f[_0x29af0a['name']]),_0x35d94f);}_0x1c1e54['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x26f494 of _0x222dad)_0x1c1e54['exec'](_0x26f494['sql']);if(_0x1c1e54['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x1c1e54['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x4f24b5=!0x1;}finally{try{_0x4f24b5&&_0x1c1e54['exec']('ROLLBACK;');}finally{_0x1c1e54['close']();}}}function E(_0x2717fb){return typeof _0x2717fb=='number'&&Number['isSafeInteger'](_0x2717fb)&&_0x2717fb>=0x0;}function*D(_0x24e0c4,_0x59deed,_0x1e2867){let _0x3340cc=_0x1e2867['join'](',\x20'),_0x54d754=_0x24e0c4['prepare']('SELECT\x20*\x20FROM\x20'+_0x59deed+'\x20ORDER\x20BY\x20'+_0x3340cc+'\x20LIMIT\x20100'),_0x501268=_0x24e0c4['prepare']('SELECT\x20*\x20FROM\x20'+_0x59deed+'\x20WHERE\x20('+_0x3340cc+')\x20>\x20('+_0x1e2867['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x3340cc+'\x20LIMIT\x20100'),_0x48e7f0=_0x54d754['all']();for(;_0x48e7f0['length']>0x0;){yield*_0x48e7f0;let _0x3e6b01=_0x1e2867['map'](_0x49d7f1=>_0x48e7f0[_0x48e7f0['length']-0x1][_0x49d7f1]);_0x48e7f0=[],_0x48e7f0=_0x501268['all'](..._0x3e6b01);}}exports['SQLiteDatabaseAdapter']=h,exports['migrateSQLiteCoreV1ToV2']=T;
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=(_0x23db8c,_0x6fc722,_0x15153f,_0x2f9280)=>{if(_0x6fc722&&typeof _0x6fc722=='object'||typeof _0x6fc722=='function'){for(var _0x1cf647=r(_0x6fc722),_0x464e6c=0x0,_0x4a3d1d=_0x1cf647['length'],_0xe80909;_0x464e6c<_0x4a3d1d;_0x464e6c++)_0xe80909=_0x1cf647[_0x464e6c],!a['call'](_0x23db8c,_0xe80909)&&_0xe80909!==_0x15153f&&t(_0x23db8c,_0xe80909,{'get':(_0x1763b5=>_0x6fc722[_0x1763b5])['bind'](null,_0xe80909),'enumerable':!(_0x2f9280=n(_0x6fc722,_0xe80909))||_0x2f9280['enumerable']});}return _0x23db8c;},s=(_0x5dcf0e,_0x2fa643,_0x53013c)=>(_0x53013c=_0x5dcf0e==null?{}:e(i(_0x5dcf0e)),o(_0x2fa643||!_0x5dcf0e||!_0x5dcf0e['__esModule']?t(_0x53013c,'default',{'value':_0x5dcf0e,'enumerable':!0x0}):_0x53013c,_0x5dcf0e));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(_0x568f60){g(_0x568f60),this['_database']=new c['default'](_0x568f60['filename'],{'timeout':_0x568f60['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x568f60['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0xe4d302){throw this['_database']['close'](),_0xe4d302;}}async['getUnit'](_0x1d0043,_0x378076){this['_assertOpen']();let _0x328b74=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'](_0x378076);return _0x328b74?v(_0x328b74):null;}async['getSnapshot'](_0xff5c8b,_0x3c03f3,_0x40370f){this['_assertOpen']();let _0x214148=_0x40370f?.['revision'];if(_0x214148!==void 0x0&&_0x214148<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x19e79d=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'+(_0x214148===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'](_0x3c03f3,..._0x214148===void 0x0?[]:[_0x214148]);return _0x19e79d?C(_0x19e79d['payload_json']):null;}async['getSnapshotInfo'](_0x1acae7,_0x2f8ad3,_0x1e34f8){this['_assertOpen']();let _0x332bf6=_0x1e34f8?.['revision'];if(_0x332bf6!==void 0x0&&_0x332bf6<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x4a5cde=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'+(_0x332bf6===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'](_0x2f8ad3,..._0x332bf6===void 0x0?[]:[_0x332bf6]);return _0x4a5cde?{'unitID':_0x4a5cde['unitID'],'type':_0x4a5cde['type'],'rev':_0x4a5cde['rev']}:null;}async['getChangesets'](_0x5caff5,_0x490623,_0x102bd6){if(this['_assertOpen'](),_0x102bd6['from']<0x0||_0x102bd6['to']!==void 0x0&&_0x102bd6['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x155b37=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'+(_0x102bd6['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'](_0x102bd6['from'],..._0x102bd6['to']===void 0x0?[]:[_0x102bd6['to']],_0x490623);return _0x155b37['length']===0x0?null:_0x155b37['flatMap'](_0xbf3620=>_0xbf3620['payload_json']?[C(_0xbf3620['payload_json'])]:[]);}async['createUnit'](_0x3468b2,_0x20e269){this['_assertOpen'](),_(_0x20e269);let _0x5a6bed=S(_0x20e269['snapshot']),_0x365d63=(_0x20e269['sheetBlocks']??[])['map'](_0x528c18=>({'id':_0x528c18['id'],'payload':S(_0x528c18)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x20e269['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0xde41de=this['_getStoredUnitRow'](_0x20e269['record']['unitID']);if(_0xde41de){if(_0xde41de['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0xde41de)};}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'](_0x20e269['record']['unitID'],_0x20e269['record']['type'],_0x20e269['record']['creatorID'],_0x20e269['record']['createdAt']),this['_writeSheetBlocks'](_0x20e269['record']['unitID'],_0x365d63),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'](_0x20e269['record']['unitID'],_0x20e269['record']['type'],_0x5a6bed),{'status':'created','record':{..._0x20e269['record']}};});}async['deleteUnits'](_0x5136cb,_0xa41f98){return this['_assertOpen'](),this['_transaction'](()=>{let _0x2facff=x(_0xa41f98['unitIDs'])['map'](_0x123815=>{let _0x2822=this['_getStoredUnitRow'](_0x123815);if(!_0x2822){if(_0xa41f98['hardDelete']&&this['_hasTombstone'](_0x123815))return{'unitID':_0x123815,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0xa41f98['hardDelete']?{'unitID':_0x123815,'status':'hard-deleted'}:{'unitID':_0x123815,'status':_0x2822['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x4e148c=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'),_0x31f1c0=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?)'),_0x3f9062=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x33c7d3=Date['now']();for(let _0x26f485 of _0x2facff)_0x26f485['status']==='soft-deleted'?_0x4e148c['run'](_0x33c7d3,_0x26f485['unitID']):_0x26f485['status']==='hard-deleted'&&(_0x31f1c0['run'](_0x26f485['unitID'],_0x33c7d3),_0x3f9062['run'](_0x26f485['unitID']));return{'units':_0x2facff};});}async['recoverUnits'](_0x1e6dfd,_0x452042){return this['_assertOpen'](),this['_transaction'](()=>{let _0x5c1826=x(_0x452042['unitIDs'])['map'](_0x13e557=>{let _0xf798c6=this['_getStoredUnitRow'](_0x13e557);if(!_0xf798c6)throw this['_hasTombstone'](_0x13e557)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x13e557,'status':_0xf798c6['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x579f31=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 _0x159dd0 of _0x5c1826)_0x159dd0['status']==='recovered'&&_0x579f31['run'](_0x159dd0['unitID']);return{'units':_0x5c1826};});}async['commitChangeset'](_0x40af87,_0x2ede8f){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x3d2d44}=_0x2ede8f,_0x3c9dcb=this['_getActiveUnitRow'](_0x3d2d44['unitID']);if(!_0x3c9dcb)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x3c9dcb['head_revision']!==_0x3d2d44['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x3c9dcb['head_revision']};let _0x840472=Date['now'](),_0x41674f=S({..._0x3d2d44,'createTime':Math['floor'](_0x840472/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'](_0x3d2d44['unitID'],_0x3d2d44['revision'],_0x3d2d44['baseRev'],_0x3d2d44['sid'],_0x3d2d44['reqId'],_0x840472,_0x41674f),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'](_0x3d2d44['revision'],_0x3d2d44['unitID'],_0x3d2d44['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x41674f),'headRevision':_0x3d2d44['revision']};});}async['saveSnapshot'](_0x1bdc80,_0x575fd2){this['_assertOpen']();let _0x23400f=S(_0x575fd2['snapshot']),_0x39bae1=(_0x575fd2['sheetBlocks']??[])['map'](_0x9fed6f=>({'id':_0x9fed6f['id'],'payload':S(_0x9fed6f)}));this['_transaction'](()=>{let _0x53fd7c=this['_getActiveUnitRow'](_0x575fd2['snapshot']['unitID']);if(!_0x53fd7c)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x575fd2['snapshot']['type']!==_0x53fd7c['type']||_0x575fd2['snapshot']['rev']<0x1||_0x575fd2['snapshot']['rev']>_0x53fd7c['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x575fd2['snapshot']['unitID'],_0x39bae1),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'](_0x575fd2['snapshot']['unitID'],_0x575fd2['snapshot']['rev'],_0x575fd2['snapshot']['type'],_0x23400f);});}async['getSheetBlock'](_0xd597e5,_0x542b0f,_0x500822){this['_assertOpen']();let _0x7fd35a=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'](_0x542b0f,_0x500822);return _0x7fd35a?C(_0x7fd35a['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 _0x35b246=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(_0x35b246){if(_0x35b246['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x35b246['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x245b2c=m['filter'](_0x53b2df=>!this['_hasTable'](_0x53b2df));if(_0x245b2c['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x35b246['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x245b2c['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x4a3ac5=>_0x4a3ac5['name']==='created_at_ms'&&_0x4a3ac5['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x10c62e=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x26541f=>_0x10c62e['some'](_0x38edf6=>_0x38edf6['name']===_0x26541f&&_0x38edf6['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'](_0x29f8c2){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'](_0x29f8c2)??null;}['_getStoredUnitRow'](_0x277623){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'](_0x277623)??null;}['_hasTombstone'](_0x51a016){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x51a016);}['_hasTable'](_0x2f90b2){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'](_0x2f90b2);}['_hasAnyCoreTable'](){return m['some'](_0x1410c6=>this['_hasTable'](_0x1410c6));}['_writeSheetBlocks'](_0x2c33d6,_0x19181e){let _0x348f83=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 _0x1b73ca of _0x19181e)_0x348f83['run'](_0x2c33d6,_0x1b73ca['id'],_0x1b73ca['payload']);}['_transaction'](_0x64d2a6){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x40a43b=_0x64d2a6();return this['_database']['exec']('COMMIT;'),_0x40a43b;}catch(_0x38eeb9){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x38eeb9;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x12d543){if(!_0x12d543['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x12d543['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x12d543['busyTimeoutMs'])||_0x12d543['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x2bd3ea){let {record:_0x14c20b,snapshot:_0xc4f407}=_0x2bd3ea;if(_0x14c20b['headRevision']!==0x1||_0xc4f407['rev']!==0x1||_0xc4f407['unitID']!==_0x14c20b['unitID']||_0xc4f407['type']!==_0x14c20b['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x14c20b['creatorID']!='string'||_0x14c20b['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x14c20b['createdAt'])||_0x14c20b['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0x1c4a62){return{'unitID':_0x1c4a62['unit_id'],'type':_0x1c4a62['type'],'headRevision':_0x1c4a62['head_revision'],'creatorID':_0x1c4a62['creator_id'],'createdAt':_0x1c4a62['created_at_ms']};}function y(_0xf6da8e){return new l['CollabError']('INVALID_REQUEST',_0xf6da8e);}function b(_0x27db3c){return new l['CollabError']('INTERNAL_ERROR',_0x27db3c);}function x(_0x4793ea){return[...new Set(_0x4793ea)];}function S(_0x447963){return JSON['stringify'](_0x447963,function(_0x3ed4f5,_0x1d4d7a){let _0x24f020=this[_0x3ed4f5];return _0x24f020 instanceof Uint8Array?{[d]:Buffer['from'](_0x24f020)['toString']('base64')}:_0x1d4d7a;});}function C(_0x20c3de){return JSON['parse'](_0x20c3de,(_0x5d17ed,_0x18ca02)=>w(_0x18ca02)?Uint8Array['from'](Buffer['from'](_0x18ca02[d],'base64')):_0x18ca02);}function w(_0x1a5a63){return typeof _0x1a5a63=='object'&&!!_0x1a5a63&&Object['keys'](_0x1a5a63)['length']===0x1&&typeof _0x1a5a63[d]=='string';}async function T(_0x5682d9){let _0x66b338=Date['now'](),_0x50d0d2=new c['default'](_0x5682d9['filename'],{'fileMustExist':!0x0}),_0x24a92b=!0x1;try{if(_0x50d0d2['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x24a92b=!0x0,_0x50d0d2['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 _0x5cefae of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x50d0d2['prepare']('SELECT\x201\x20FROM\x20'+_0x5cefae+'\x20LIMIT\x200')['all']();let _0xa66f52=_0x50d0d2['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x50d0d2['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x395c40=(_0x3f7db1,_0x234ee9)=>_0xa66f52?.['get'](_0x3f7db1,_0x234ee9),_0xa123ce=_0x50d0d2['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x516a9b=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0xa123ce['length']!==_0x516a9b['length']||_0x516a9b['some'](_0x5d04af=>!_0xa123ce['some'](_0x58f7b9=>_0x58f7b9['name']===_0x5d04af)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x48f757=_0x50d0d2['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']();_0x50d0d2['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 _0x3ac520=D(_0x50d0d2,'collaboration_units',['unit_id']),_0x5adf59=_0x50d0d2['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x23b044 of _0x3ac520){let _0x2ba274=_0x5682d9['resolveUnitCreation']?void 0x0:_0x395c40(_0x23b044['unit_id'],0x1),_0x5dda9e=_0x5682d9['resolveUnitCreation']?await _0x5682d9['resolveUnitCreation'](_0x23b044['unit_id']):{'creatorID':_0x2ba274?.['user_id']||'anonymous','createdAt':E(_0x2ba274?.['committed_at'])?_0x2ba274['committed_at']:_0x66b338};if(!_0x5dda9e||typeof _0x5dda9e['creatorID']!='string'||_0x5dda9e['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x5dda9e['createdAt'])||_0x5dda9e['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x23b044['unit_id']);_0x5adf59['run'](_0x23b044['unit_id'],_0x23b044['type'],_0x23b044['head_revision'],_0x5dda9e['creatorID'],_0x5dda9e['createdAt'],_0x23b044['soft_deleted_at_ms']);}_0x50d0d2['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0x12129b of _0x48f757)_0x50d0d2['exec'](_0x12129b['sql']);let _0xc6ac53=_0x50d0d2['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x426034=_0x50d0d2['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x426034['some'](_0x28fda0=>_0x28fda0['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x2ec0ee=_0x50d0d2['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']();_0x50d0d2['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'+_0xc6ac53['sql']['slice'](_0xc6ac53['sql']['indexOf']('(')+0x1));let _0x22fc5c=D(_0x50d0d2,'collaboration_changesets',['unit_id','revision']),_0x473183=_0x426034['map'](_0x328d20=>'\x22'+_0x328d20['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x54e909=_0x50d0d2['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x473183+',\x20created_at_ms)\x20VALUES\x20('+_0x426034['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x1060bb of _0x22fc5c){let _0x129274=JSON['parse'](_0x1060bb['payload_json']),_0xefb563=typeof _0x129274['createTime']=='number'?_0x129274['createTime']*0x3e8:void 0x0,_0x500403=!_0x5682d9['resolveChangesetCreatedAt']&&!E(_0xefb563)?_0x395c40(_0x1060bb['unit_id'],_0x1060bb['revision'])?.['committed_at']:void 0x0,_0x480a41=_0x5682d9['resolveChangesetCreatedAt']?await _0x5682d9['resolveChangesetCreatedAt'](_0x1060bb['unit_id'],_0x1060bb['revision']):E(_0xefb563)?_0xefb563:E(_0x500403)?_0x500403:_0x66b338;if(!Number['isSafeInteger'](_0x480a41)||_0x480a41<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x1060bb['unit_id']+'\x20revision\x20'+_0x1060bb['revision']);_0x129274['createTime']=Math['floor'](_0x480a41/0x3e8),_0x54e909['run'](..._0x426034['map'](_0xe04c7d=>_0xe04c7d['name']==='payload_json'?JSON['stringify'](_0x129274):_0x1060bb[_0xe04c7d['name']]),_0x480a41);}_0x50d0d2['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x237c21 of _0x2ec0ee)_0x50d0d2['exec'](_0x237c21['sql']);if(_0x50d0d2['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x50d0d2['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x24a92b=!0x1;}finally{try{_0x24a92b&&_0x50d0d2['exec']('ROLLBACK;');}finally{_0x50d0d2['close']();}}}function E(_0x5a2ae7){return typeof _0x5a2ae7=='number'&&Number['isSafeInteger'](_0x5a2ae7)&&_0x5a2ae7>=0x0;}function*D(_0x35347e,_0x4ca311,_0x14fff1){let _0x1f1e41=_0x14fff1['join'](',\x20'),_0x2573a4=_0x35347e['prepare']('SELECT\x20*\x20FROM\x20'+_0x4ca311+'\x20ORDER\x20BY\x20'+_0x1f1e41+'\x20LIMIT\x20100'),_0x1de697=_0x35347e['prepare']('SELECT\x20*\x20FROM\x20'+_0x4ca311+'\x20WHERE\x20('+_0x1f1e41+')\x20>\x20('+_0x14fff1['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x1f1e41+'\x20LIMIT\x20100'),_0xdebf59=_0x2573a4['all']();for(;_0xdebf59['length']>0x0;){yield*_0xdebf59;let _0x356c55=_0x14fff1['map'](_0xa2d903=>_0xdebf59[_0xdebf59['length']-0x1][_0xa2d903]);_0xdebf59=[],_0xdebf59=_0x1de697['all'](..._0x356c55);}}exports['SQLiteDatabaseAdapter']=h,exports['migrateSQLiteCoreV1ToV2']=T;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- function _0x4aa3(_0x53f08a,_0x3ba8e3){_0x53f08a=_0x53f08a-0x7d;const _0x22bbf2=_0x22bb();let _0x4aa3d8=_0x22bbf2[_0x53f08a];return _0x4aa3d8;}function _0x22bb(){const _0x399bf2=['SQLiteDatabaseAdapter','1830TCRmld','81WcgMrQ','335456BHECLl','515408Khldmk','161fqpWOc','91536iZvaXM','1433676FobTRe','23931vsPaZF','205500Dqtejp','7093670DDzHqA'];_0x22bb=function(){return _0x399bf2;};return _0x22bb();}const _0x3354fe=_0x4aa3;(function(_0x316178,_0x4a20bb){const _0x1dc0ab=_0x4aa3,_0x480e15=_0x316178();while(!![]){try{const _0x17287c=-parseInt(_0x1dc0ab(0x7f))/0x1+-parseInt(_0x1dc0ab(0x83))/0x2+-parseInt(_0x1dc0ab(0x7e))/0x3*(-parseInt(_0x1dc0ab(0x85))/0x4)+parseInt(_0x1dc0ab(0x86))/0x5+parseInt(_0x1dc0ab(0x82))/0x6+-parseInt(_0x1dc0ab(0x81))/0x7*(parseInt(_0x1dc0ab(0x80))/0x8)+parseInt(_0x1dc0ab(0x84))/0x9*(parseInt(_0x1dc0ab(0x7d))/0xa);if(_0x17287c===_0x4a20bb)break;else _0x480e15['push'](_0x480e15['shift']());}catch(_0x66cc99){_0x480e15['push'](_0x480e15['shift']());}}}(_0x22bb,0xbcdf4));import _0x5d5a43 from'./index.cjs';const facadeExport0=_0x5d5a43[_0x3354fe(0x87)],facadeExport1=_0x5d5a43['migrateSQLiteCoreV1ToV2'];export{facadeExport0 as SQLiteDatabaseAdapter,facadeExport1 as migrateSQLiteCoreV1ToV2};
1
+ const _0x14970c=_0x53a7;function _0x27a9(){const _0x899d3e=['21745141JzqXLr','242412yHWVUa','SQLiteDatabaseAdapter','12XZefZn','738164pgUtYM','237672GUFenb','2862702KOyjea','1139380VCuOfn','5439hMAgdP','4CqpeCR','3536WZJNkO','90BAsblx'];_0x27a9=function(){return _0x899d3e;};return _0x27a9();}(function(_0x500a37,_0x50a985){const _0x3175a2=_0x53a7,_0x412c33=_0x500a37();while(!![]){try{const _0x36d04f=parseInt(_0x3175a2(0x12b))/0x1*(parseInt(_0x3175a2(0x127))/0x2)+parseInt(_0x3175a2(0x124))/0x3+parseInt(_0x3175a2(0x12e))/0x4+parseInt(_0x3175a2(0x125))/0x5*(parseInt(_0x3175a2(0x12d))/0x6)+parseInt(_0x3175a2(0x126))/0x7*(parseInt(_0x3175a2(0x128))/0x8)+-parseInt(_0x3175a2(0x123))/0x9*(-parseInt(_0x3175a2(0x129))/0xa)+-parseInt(_0x3175a2(0x12a))/0xb;if(_0x36d04f===_0x50a985)break;else _0x412c33['push'](_0x412c33['shift']());}catch(_0x4ce9c3){_0x412c33['push'](_0x412c33['shift']());}}}(_0x27a9,0xa6e6a));import _0x45842c from'./index.cjs';function _0x53a7(_0x2e6045,_0x2b43bd){_0x2e6045=_0x2e6045-0x123;const _0x27a9ae=_0x27a9();let _0x53a786=_0x27a9ae[_0x2e6045];return _0x53a786;}const facadeExport0=_0x45842c[_0x14970c(0x12c)],facadeExport1=_0x45842c['migrateSQLiteCoreV1ToV2'];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.1.0",
7
+ "version": "1.2.0",
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.1.0",
23
- "@univerjs/protocol": "1.1.0",
22
+ "@univerjs-pro/collaboration-service": "1.2.0",
23
+ "@univerjs/protocol": "1.2.0",
24
24
  "libsql": "^0.5.29"
25
25
  }
26
26
  }