@univerjs-pro/collaboration-database-sqlite 1.0.3 → 1.0.4

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=(_0xb03eb9,_0x26fc26,_0x5c5374,_0x394396)=>{if(_0x26fc26&&typeof _0x26fc26=='object'||typeof _0x26fc26=='function'){for(var _0x2a6262=r(_0x26fc26),_0x319185=0x0,_0x535b3e=_0x2a6262['length'],_0x7fa0b0;_0x319185<_0x535b3e;_0x319185++)_0x7fa0b0=_0x2a6262[_0x319185],!a['call'](_0xb03eb9,_0x7fa0b0)&&_0x7fa0b0!==_0x5c5374&&t(_0xb03eb9,_0x7fa0b0,{'get':(_0x1016c0=>_0x26fc26[_0x1016c0])['bind'](null,_0x7fa0b0),'enumerable':!(_0x394396=n(_0x26fc26,_0x7fa0b0))||_0x394396['enumerable']});}return _0xb03eb9;},s=(_0x58e78a,_0x169890,_0x3165ad)=>(_0x3165ad=_0x58e78a==null?{}:e(i(_0x58e78a)),o(_0x169890||!_0x58e78a||!_0x58e78a['__esModule']?t(_0x3165ad,'default',{'value':_0x58e78a,'enumerable':!0x0}):_0x3165ad,_0x58e78a));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(_0x40fb25){g(_0x40fb25),this['_database']=new c['default'](_0x40fb25['filename'],{'timeout':_0x40fb25['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x40fb25['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x48f2a5){throw this['_database']['close'](),_0x48f2a5;}}async['getUnit'](_0x47896d,_0x3cdff4){this['_assertOpen']();let _0x27d68b=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'](_0x3cdff4);return _0x27d68b?v(_0x27d68b):null;}async['getSnapshot'](_0x1fc743,_0xa01e4,_0x3c2f87){this['_assertOpen']();let _0xca758a=_0x3c2f87?.['revision'];if(_0xca758a!==void 0x0&&_0xca758a<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x514fa7=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'+(_0xca758a===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'](_0xa01e4,..._0xca758a===void 0x0?[]:[_0xca758a]);return _0x514fa7?C(_0x514fa7['payload_json']):null;}async['getSnapshotInfo'](_0x1719aa,_0x18246f,_0x1f6b70){this['_assertOpen']();let _0x3ab6fd=_0x1f6b70?.['revision'];if(_0x3ab6fd!==void 0x0&&_0x3ab6fd<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x5dfd8f=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'+(_0x3ab6fd===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'](_0x18246f,..._0x3ab6fd===void 0x0?[]:[_0x3ab6fd]);return _0x5dfd8f?{'unitID':_0x5dfd8f['unitID'],'type':_0x5dfd8f['type'],'rev':_0x5dfd8f['rev']}:null;}async['getChangesets'](_0x53be8f,_0xacc7bd,_0x2735e7){if(this['_assertOpen'](),_0x2735e7['from']<0x0||_0x2735e7['to']!==void 0x0&&_0x2735e7['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x30aaa2=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'+(_0x2735e7['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'](_0x2735e7['from'],..._0x2735e7['to']===void 0x0?[]:[_0x2735e7['to']],_0xacc7bd);return _0x30aaa2['length']===0x0?null:_0x30aaa2['flatMap'](_0x5c9025=>_0x5c9025['payload_json']?[C(_0x5c9025['payload_json'])]:[]);}async['createUnit'](_0x44c9b8,_0x55e0d1){this['_assertOpen'](),_(_0x55e0d1);let _0x3fa0b0=S(_0x55e0d1['snapshot']),_0x408460=(_0x55e0d1['sheetBlocks']??[])['map'](_0x53e352=>({'id':_0x53e352['id'],'payload':S(_0x53e352)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x55e0d1['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x14977c=this['_getStoredUnitRow'](_0x55e0d1['record']['unitID']);if(_0x14977c){if(_0x14977c['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x14977c)};}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'](_0x55e0d1['record']['unitID'],_0x55e0d1['record']['type'],_0x55e0d1['record']['creatorID'],_0x55e0d1['record']['createdAt']),this['_writeSheetBlocks'](_0x55e0d1['record']['unitID'],_0x408460),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'](_0x55e0d1['record']['unitID'],_0x55e0d1['record']['type'],_0x3fa0b0),{'status':'created','record':{..._0x55e0d1['record']}};});}async['deleteUnits'](_0x370465,_0x3fd044){return this['_assertOpen'](),this['_transaction'](()=>{let _0x300206=x(_0x3fd044['unitIDs'])['map'](_0x377a0e=>{let _0x5b5d10=this['_getStoredUnitRow'](_0x377a0e);if(!_0x5b5d10){if(_0x3fd044['hardDelete']&&this['_hasTombstone'](_0x377a0e))return{'unitID':_0x377a0e,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x3fd044['hardDelete']?{'unitID':_0x377a0e,'status':'hard-deleted'}:{'unitID':_0x377a0e,'status':_0x5b5d10['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x45d7a5=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'),_0x2cef5a=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?)'),_0x388ada=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x2d52d1=Date['now']();for(let _0x3f1e61 of _0x300206)_0x3f1e61['status']==='soft-deleted'?_0x45d7a5['run'](_0x2d52d1,_0x3f1e61['unitID']):_0x3f1e61['status']==='hard-deleted'&&(_0x2cef5a['run'](_0x3f1e61['unitID'],_0x2d52d1),_0x388ada['run'](_0x3f1e61['unitID']));return{'units':_0x300206};});}async['recoverUnits'](_0x40386a,_0x252ab9){return this['_assertOpen'](),this['_transaction'](()=>{let _0x10c7b5=x(_0x252ab9['unitIDs'])['map'](_0x3180ce=>{let _0x56ce04=this['_getStoredUnitRow'](_0x3180ce);if(!_0x56ce04)throw this['_hasTombstone'](_0x3180ce)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x3180ce,'status':_0x56ce04['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x54a63f=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 _0x70a9af of _0x10c7b5)_0x70a9af['status']==='recovered'&&_0x54a63f['run'](_0x70a9af['unitID']);return{'units':_0x10c7b5};});}async['commitChangeset'](_0x100500,_0x3a8f42){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x284aea}=_0x3a8f42,_0x167dba=this['_getActiveUnitRow'](_0x284aea['unitID']);if(!_0x167dba)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x167dba['head_revision']!==_0x284aea['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x167dba['head_revision']};let _0x3eabe5=Date['now'](),_0x24ed9e=S({..._0x284aea,'createTime':Math['floor'](_0x3eabe5/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'](_0x284aea['unitID'],_0x284aea['revision'],_0x284aea['baseRev'],_0x284aea['sid'],_0x284aea['reqId'],_0x3eabe5,_0x24ed9e),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'](_0x284aea['revision'],_0x284aea['unitID'],_0x284aea['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x24ed9e),'headRevision':_0x284aea['revision']};});}async['saveSnapshot'](_0x3036ea,_0x5a7665){this['_assertOpen']();let _0x3508b1=S(_0x5a7665['snapshot']),_0x2d0c94=(_0x5a7665['sheetBlocks']??[])['map'](_0x5ce3f1=>({'id':_0x5ce3f1['id'],'payload':S(_0x5ce3f1)}));this['_transaction'](()=>{let _0x4a7ab5=this['_getActiveUnitRow'](_0x5a7665['snapshot']['unitID']);if(!_0x4a7ab5)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x5a7665['snapshot']['type']!==_0x4a7ab5['type']||_0x5a7665['snapshot']['rev']<0x1||_0x5a7665['snapshot']['rev']>_0x4a7ab5['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x5a7665['snapshot']['unitID'],_0x2d0c94),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'](_0x5a7665['snapshot']['unitID'],_0x5a7665['snapshot']['rev'],_0x5a7665['snapshot']['type'],_0x3508b1);});}async['getSheetBlock'](_0x28a9aa,_0x3dd59d,_0xbc3f4e){this['_assertOpen']();let _0x2a59c5=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'](_0x3dd59d,_0xbc3f4e);return _0x2a59c5?C(_0x2a59c5['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 _0xfa6546=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(_0xfa6546){if(_0xfa6546['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0xfa6546['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x3474ec=m['filter'](_0x48ae1d=>!this['_hasTable'](_0x48ae1d));if(_0x3474ec['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0xfa6546['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x3474ec['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x5e4183=>_0x5e4183['name']==='created_at_ms'&&_0x5e4183['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x1c2a81=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x7f1774=>_0x1c2a81['some'](_0xe14201=>_0xe14201['name']===_0x7f1774&&_0xe14201['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'](_0xa015ee){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'](_0xa015ee)??null;}['_getStoredUnitRow'](_0x410d03){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'](_0x410d03)??null;}['_hasTombstone'](_0x5f2b24){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x5f2b24);}['_hasTable'](_0x3d984f){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'](_0x3d984f);}['_hasAnyCoreTable'](){return m['some'](_0x18f848=>this['_hasTable'](_0x18f848));}['_writeSheetBlocks'](_0x35e7e9,_0xb642f4){let _0x51e629=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 _0x59fe68 of _0xb642f4)_0x51e629['run'](_0x35e7e9,_0x59fe68['id'],_0x59fe68['payload']);}['_transaction'](_0x253dc1){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x5d73cd=_0x253dc1();return this['_database']['exec']('COMMIT;'),_0x5d73cd;}catch(_0x3db0fa){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x3db0fa;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x3a5e41){if(!_0x3a5e41['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x3a5e41['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x3a5e41['busyTimeoutMs'])||_0x3a5e41['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x110458){let {record:_0x36e84d,snapshot:_0x59c7a8}=_0x110458;if(_0x36e84d['headRevision']!==0x1||_0x59c7a8['rev']!==0x1||_0x59c7a8['unitID']!==_0x36e84d['unitID']||_0x59c7a8['type']!==_0x36e84d['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x36e84d['creatorID']!='string'||_0x36e84d['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x36e84d['createdAt'])||_0x36e84d['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0xe0a07d){return{'unitID':_0xe0a07d['unit_id'],'type':_0xe0a07d['type'],'headRevision':_0xe0a07d['head_revision'],'creatorID':_0xe0a07d['creator_id'],'createdAt':_0xe0a07d['created_at_ms']};}function y(_0xca060){return new l['CollabError']('INVALID_REQUEST',_0xca060);}function b(_0x1c6f77){return new l['CollabError']('INTERNAL_ERROR',_0x1c6f77);}function x(_0x75ed79){return[...new Set(_0x75ed79)];}function S(_0x30fd7b){return JSON['stringify'](_0x30fd7b,function(_0x2bcece,_0x5164f1){let _0x15e6fb=this[_0x2bcece];return _0x15e6fb instanceof Uint8Array?{[d]:Buffer['from'](_0x15e6fb)['toString']('base64')}:_0x5164f1;});}function C(_0x38c159){return JSON['parse'](_0x38c159,(_0x538df3,_0x427ed9)=>w(_0x427ed9)?Uint8Array['from'](Buffer['from'](_0x427ed9[d],'base64')):_0x427ed9);}function w(_0x4fdb20){return typeof _0x4fdb20=='object'&&!!_0x4fdb20&&Object['keys'](_0x4fdb20)['length']===0x1&&typeof _0x4fdb20[d]=='string';}async function T(_0x35928c){let _0x3fd388=Date['now'](),_0x173643=new c['default'](_0x35928c['filename'],{'fileMustExist':!0x0}),_0x5bbb50=!0x1;try{if(_0x173643['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x5bbb50=!0x0,_0x173643['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 _0x9683b8 of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x173643['prepare']('SELECT\x201\x20FROM\x20'+_0x9683b8+'\x20LIMIT\x200')['all']();let _0x4db0d2=_0x173643['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x173643['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x3538e3=(_0x21e46b,_0x1c5574)=>_0x4db0d2?.['get'](_0x21e46b,_0x1c5574),_0x59a508=_0x173643['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x41e551=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x59a508['length']!==_0x41e551['length']||_0x41e551['some'](_0x21eed3=>!_0x59a508['some'](_0x13adc4=>_0x13adc4['name']===_0x21eed3)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x58883d=_0x173643['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']();_0x173643['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 _0x17c87e=D(_0x173643,'collaboration_units',['unit_id']),_0x4657dc=_0x173643['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x173519 of _0x17c87e){let _0x4250d8=_0x35928c['resolveUnitCreation']?void 0x0:_0x3538e3(_0x173519['unit_id'],0x1),_0x186a4d=_0x35928c['resolveUnitCreation']?await _0x35928c['resolveUnitCreation'](_0x173519['unit_id']):{'creatorID':_0x4250d8?.['user_id']||'anonymous','createdAt':E(_0x4250d8?.['committed_at'])?_0x4250d8['committed_at']:_0x3fd388};if(!_0x186a4d||typeof _0x186a4d['creatorID']!='string'||_0x186a4d['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x186a4d['createdAt'])||_0x186a4d['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x173519['unit_id']);_0x4657dc['run'](_0x173519['unit_id'],_0x173519['type'],_0x173519['head_revision'],_0x186a4d['creatorID'],_0x186a4d['createdAt'],_0x173519['soft_deleted_at_ms']);}_0x173643['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0x55d83f of _0x58883d)_0x173643['exec'](_0x55d83f['sql']);let _0x18a6cb=_0x173643['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x21055e=_0x173643['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x21055e['some'](_0x3706b7=>_0x3706b7['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x5b4701=_0x173643['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']();_0x173643['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'+_0x18a6cb['sql']['slice'](_0x18a6cb['sql']['indexOf']('(')+0x1));let _0x13fa18=D(_0x173643,'collaboration_changesets',['unit_id','revision']),_0x1756b7=_0x21055e['map'](_0x17d8d3=>'\x22'+_0x17d8d3['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x1fa901=_0x173643['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x1756b7+',\x20created_at_ms)\x20VALUES\x20('+_0x21055e['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x3b5ef3 of _0x13fa18){let _0x588aaa=JSON['parse'](_0x3b5ef3['payload_json']),_0x2e355e=typeof _0x588aaa['createTime']=='number'?_0x588aaa['createTime']*0x3e8:void 0x0,_0x2644f7=!_0x35928c['resolveChangesetCreatedAt']&&!E(_0x2e355e)?_0x3538e3(_0x3b5ef3['unit_id'],_0x3b5ef3['revision'])?.['committed_at']:void 0x0,_0x307ce5=_0x35928c['resolveChangesetCreatedAt']?await _0x35928c['resolveChangesetCreatedAt'](_0x3b5ef3['unit_id'],_0x3b5ef3['revision']):E(_0x2e355e)?_0x2e355e:E(_0x2644f7)?_0x2644f7:_0x3fd388;if(!Number['isSafeInteger'](_0x307ce5)||_0x307ce5<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x3b5ef3['unit_id']+'\x20revision\x20'+_0x3b5ef3['revision']);_0x588aaa['createTime']=Math['floor'](_0x307ce5/0x3e8),_0x1fa901['run'](..._0x21055e['map'](_0x5af21b=>_0x5af21b['name']==='payload_json'?JSON['stringify'](_0x588aaa):_0x3b5ef3[_0x5af21b['name']]),_0x307ce5);}_0x173643['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x515048 of _0x5b4701)_0x173643['exec'](_0x515048['sql']);if(_0x173643['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x173643['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x5bbb50=!0x1;}finally{try{_0x5bbb50&&_0x173643['exec']('ROLLBACK;');}finally{_0x173643['close']();}}}function E(_0x3bb5d2){return typeof _0x3bb5d2=='number'&&Number['isSafeInteger'](_0x3bb5d2)&&_0x3bb5d2>=0x0;}function*D(_0x5b6f6e,_0x125619,_0x3a298c){let _0x57a8f9=_0x3a298c['join'](',\x20'),_0x4e3dd5=_0x5b6f6e['prepare']('SELECT\x20*\x20FROM\x20'+_0x125619+'\x20ORDER\x20BY\x20'+_0x57a8f9+'\x20LIMIT\x20100'),_0x47af50=_0x5b6f6e['prepare']('SELECT\x20*\x20FROM\x20'+_0x125619+'\x20WHERE\x20('+_0x57a8f9+')\x20>\x20('+_0x3a298c['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x57a8f9+'\x20LIMIT\x20100'),_0x45c713=_0x4e3dd5['all']();for(;_0x45c713['length']>0x0;){yield*_0x45c713;let _0x1937b9=_0x3a298c['map'](_0x2ae13b=>_0x45c713[_0x45c713['length']-0x1][_0x2ae13b]);_0x45c713=[],_0x45c713=_0x47af50['all'](..._0x1937b9);}}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=(_0x4651ed,_0x2e0453,_0x5c0f1c,_0x10acb0)=>{if(_0x2e0453&&typeof _0x2e0453=='object'||typeof _0x2e0453=='function'){for(var _0x214d89=r(_0x2e0453),_0x5e0bc2=0x0,_0x3a63f4=_0x214d89['length'],_0x583dd1;_0x5e0bc2<_0x3a63f4;_0x5e0bc2++)_0x583dd1=_0x214d89[_0x5e0bc2],!a['call'](_0x4651ed,_0x583dd1)&&_0x583dd1!==_0x5c0f1c&&t(_0x4651ed,_0x583dd1,{'get':(_0x4789af=>_0x2e0453[_0x4789af])['bind'](null,_0x583dd1),'enumerable':!(_0x10acb0=n(_0x2e0453,_0x583dd1))||_0x10acb0['enumerable']});}return _0x4651ed;},s=(_0x22aba8,_0x14ea83,_0x3603de)=>(_0x3603de=_0x22aba8==null?{}:e(i(_0x22aba8)),o(_0x14ea83||!_0x22aba8||!_0x22aba8['__esModule']?t(_0x3603de,'default',{'value':_0x22aba8,'enumerable':!0x0}):_0x3603de,_0x22aba8));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(_0x1644ad){g(_0x1644ad),this['_database']=new c['default'](_0x1644ad['filename'],{'timeout':_0x1644ad['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x1644ad['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x36fd5c){throw this['_database']['close'](),_0x36fd5c;}}async['getUnit'](_0x51e1fa,_0x5641cb){this['_assertOpen']();let _0x1e4633=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'](_0x5641cb);return _0x1e4633?v(_0x1e4633):null;}async['getSnapshot'](_0x4acf94,_0x33ea15,_0x2c213a){this['_assertOpen']();let _0x15631b=_0x2c213a?.['revision'];if(_0x15631b!==void 0x0&&_0x15631b<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0xd83e32=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'+(_0x15631b===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'](_0x33ea15,..._0x15631b===void 0x0?[]:[_0x15631b]);return _0xd83e32?C(_0xd83e32['payload_json']):null;}async['getSnapshotInfo'](_0x5af6ad,_0x56fb9a,_0x2393bb){this['_assertOpen']();let _0x122e5f=_0x2393bb?.['revision'];if(_0x122e5f!==void 0x0&&_0x122e5f<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0xaa0ccd=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'+(_0x122e5f===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'](_0x56fb9a,..._0x122e5f===void 0x0?[]:[_0x122e5f]);return _0xaa0ccd?{'unitID':_0xaa0ccd['unitID'],'type':_0xaa0ccd['type'],'rev':_0xaa0ccd['rev']}:null;}async['getChangesets'](_0x764d1a,_0x36e5e0,_0x199173){if(this['_assertOpen'](),_0x199173['from']<0x0||_0x199173['to']!==void 0x0&&_0x199173['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x98eb8b=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'+(_0x199173['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'](_0x199173['from'],..._0x199173['to']===void 0x0?[]:[_0x199173['to']],_0x36e5e0);return _0x98eb8b['length']===0x0?null:_0x98eb8b['flatMap'](_0x335b52=>_0x335b52['payload_json']?[C(_0x335b52['payload_json'])]:[]);}async['createUnit'](_0x1ad65e,_0x229957){this['_assertOpen'](),_(_0x229957);let _0x172137=S(_0x229957['snapshot']),_0x5cba0b=(_0x229957['sheetBlocks']??[])['map'](_0x321e3e=>({'id':_0x321e3e['id'],'payload':S(_0x321e3e)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x229957['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x2e7899=this['_getStoredUnitRow'](_0x229957['record']['unitID']);if(_0x2e7899){if(_0x2e7899['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x2e7899)};}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'](_0x229957['record']['unitID'],_0x229957['record']['type'],_0x229957['record']['creatorID'],_0x229957['record']['createdAt']),this['_writeSheetBlocks'](_0x229957['record']['unitID'],_0x5cba0b),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'](_0x229957['record']['unitID'],_0x229957['record']['type'],_0x172137),{'status':'created','record':{..._0x229957['record']}};});}async['deleteUnits'](_0x5d11de,_0x457899){return this['_assertOpen'](),this['_transaction'](()=>{let _0x1b7d5a=x(_0x457899['unitIDs'])['map'](_0x3f85a9=>{let _0x5ea48e=this['_getStoredUnitRow'](_0x3f85a9);if(!_0x5ea48e){if(_0x457899['hardDelete']&&this['_hasTombstone'](_0x3f85a9))return{'unitID':_0x3f85a9,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x457899['hardDelete']?{'unitID':_0x3f85a9,'status':'hard-deleted'}:{'unitID':_0x3f85a9,'status':_0x5ea48e['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x550cdd=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'),_0x3868df=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?)'),_0x51fcd2=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x41bf87=Date['now']();for(let _0x21003f of _0x1b7d5a)_0x21003f['status']==='soft-deleted'?_0x550cdd['run'](_0x41bf87,_0x21003f['unitID']):_0x21003f['status']==='hard-deleted'&&(_0x3868df['run'](_0x21003f['unitID'],_0x41bf87),_0x51fcd2['run'](_0x21003f['unitID']));return{'units':_0x1b7d5a};});}async['recoverUnits'](_0x23bc69,_0x3a910){return this['_assertOpen'](),this['_transaction'](()=>{let _0x29628e=x(_0x3a910['unitIDs'])['map'](_0x1e73d5=>{let _0x10feaa=this['_getStoredUnitRow'](_0x1e73d5);if(!_0x10feaa)throw this['_hasTombstone'](_0x1e73d5)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x1e73d5,'status':_0x10feaa['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x99818a=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 _0x5e08de of _0x29628e)_0x5e08de['status']==='recovered'&&_0x99818a['run'](_0x5e08de['unitID']);return{'units':_0x29628e};});}async['commitChangeset'](_0x33e819,_0x2842f8){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x59ec00}=_0x2842f8,_0x11136a=this['_getActiveUnitRow'](_0x59ec00['unitID']);if(!_0x11136a)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x11136a['head_revision']!==_0x59ec00['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x11136a['head_revision']};let _0x4ddd28=Date['now'](),_0x239068=S({..._0x59ec00,'createTime':Math['floor'](_0x4ddd28/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'](_0x59ec00['unitID'],_0x59ec00['revision'],_0x59ec00['baseRev'],_0x59ec00['sid'],_0x59ec00['reqId'],_0x4ddd28,_0x239068),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'](_0x59ec00['revision'],_0x59ec00['unitID'],_0x59ec00['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x239068),'headRevision':_0x59ec00['revision']};});}async['saveSnapshot'](_0x599b84,_0x12e132){this['_assertOpen']();let _0x558383=S(_0x12e132['snapshot']),_0x5462e8=(_0x12e132['sheetBlocks']??[])['map'](_0xa98ce2=>({'id':_0xa98ce2['id'],'payload':S(_0xa98ce2)}));this['_transaction'](()=>{let _0x335b83=this['_getActiveUnitRow'](_0x12e132['snapshot']['unitID']);if(!_0x335b83)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x12e132['snapshot']['type']!==_0x335b83['type']||_0x12e132['snapshot']['rev']<0x1||_0x12e132['snapshot']['rev']>_0x335b83['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x12e132['snapshot']['unitID'],_0x5462e8),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'](_0x12e132['snapshot']['unitID'],_0x12e132['snapshot']['rev'],_0x12e132['snapshot']['type'],_0x558383);});}async['getSheetBlock'](_0x4ee09f,_0x4e2080,_0x3efed2){this['_assertOpen']();let _0x59659c=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'](_0x4e2080,_0x3efed2);return _0x59659c?C(_0x59659c['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 _0x438bdd=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(_0x438bdd){if(_0x438bdd['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x438bdd['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x2b0692=m['filter'](_0xb7ded7=>!this['_hasTable'](_0xb7ded7));if(_0x2b0692['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x438bdd['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x2b0692['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x5ceff7=>_0x5ceff7['name']==='created_at_ms'&&_0x5ceff7['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x5af553=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x434a73=>_0x5af553['some'](_0x1fc864=>_0x1fc864['name']===_0x434a73&&_0x1fc864['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'](_0x436e85){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'](_0x436e85)??null;}['_getStoredUnitRow'](_0x54f04c){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'](_0x54f04c)??null;}['_hasTombstone'](_0x1497ef){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x1497ef);}['_hasTable'](_0x528bf4){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'](_0x528bf4);}['_hasAnyCoreTable'](){return m['some'](_0x2b78af=>this['_hasTable'](_0x2b78af));}['_writeSheetBlocks'](_0x31a40c,_0x3f030f){let _0x5f20ce=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 _0x454818 of _0x3f030f)_0x5f20ce['run'](_0x31a40c,_0x454818['id'],_0x454818['payload']);}['_transaction'](_0x230c0b){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x38bd96=_0x230c0b();return this['_database']['exec']('COMMIT;'),_0x38bd96;}catch(_0xab9e72){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0xab9e72;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x8b771f){if(!_0x8b771f['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x8b771f['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x8b771f['busyTimeoutMs'])||_0x8b771f['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x2ae2ee){let {record:_0x49ce79,snapshot:_0x4d42b4}=_0x2ae2ee;if(_0x49ce79['headRevision']!==0x1||_0x4d42b4['rev']!==0x1||_0x4d42b4['unitID']!==_0x49ce79['unitID']||_0x4d42b4['type']!==_0x49ce79['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x49ce79['creatorID']!='string'||_0x49ce79['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x49ce79['createdAt'])||_0x49ce79['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0x282372){return{'unitID':_0x282372['unit_id'],'type':_0x282372['type'],'headRevision':_0x282372['head_revision'],'creatorID':_0x282372['creator_id'],'createdAt':_0x282372['created_at_ms']};}function y(_0x30c18f){return new l['CollabError']('INVALID_REQUEST',_0x30c18f);}function b(_0x12a50a){return new l['CollabError']('INTERNAL_ERROR',_0x12a50a);}function x(_0x18a744){return[...new Set(_0x18a744)];}function S(_0x47aafd){return JSON['stringify'](_0x47aafd,function(_0x4ea5e2,_0x5dccd4){let _0x490162=this[_0x4ea5e2];return _0x490162 instanceof Uint8Array?{[d]:Buffer['from'](_0x490162)['toString']('base64')}:_0x5dccd4;});}function C(_0xe50dce){return JSON['parse'](_0xe50dce,(_0x52a563,_0x45e15f)=>w(_0x45e15f)?Uint8Array['from'](Buffer['from'](_0x45e15f[d],'base64')):_0x45e15f);}function w(_0x49eaab){return typeof _0x49eaab=='object'&&!!_0x49eaab&&Object['keys'](_0x49eaab)['length']===0x1&&typeof _0x49eaab[d]=='string';}async function T(_0x1e17f1){let _0x160e9e=Date['now'](),_0x2aa793=new c['default'](_0x1e17f1['filename'],{'fileMustExist':!0x0}),_0x503234=!0x1;try{if(_0x2aa793['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x503234=!0x0,_0x2aa793['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 _0x228bf3 of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x2aa793['prepare']('SELECT\x201\x20FROM\x20'+_0x228bf3+'\x20LIMIT\x200')['all']();let _0x329007=_0x2aa793['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x2aa793['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x1d3325=(_0x3be314,_0x345fa2)=>_0x329007?.['get'](_0x3be314,_0x345fa2),_0x259b72=_0x2aa793['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x1d8382=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x259b72['length']!==_0x1d8382['length']||_0x1d8382['some'](_0x474646=>!_0x259b72['some'](_0x4be650=>_0x4be650['name']===_0x474646)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x47f1a6=_0x2aa793['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']();_0x2aa793['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 _0x1a5f33=D(_0x2aa793,'collaboration_units',['unit_id']),_0x30d8c3=_0x2aa793['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x4b866d of _0x1a5f33){let _0xd77830=_0x1e17f1['resolveUnitCreation']?void 0x0:_0x1d3325(_0x4b866d['unit_id'],0x1),_0x539971=_0x1e17f1['resolveUnitCreation']?await _0x1e17f1['resolveUnitCreation'](_0x4b866d['unit_id']):{'creatorID':_0xd77830?.['user_id']||'anonymous','createdAt':E(_0xd77830?.['committed_at'])?_0xd77830['committed_at']:_0x160e9e};if(!_0x539971||typeof _0x539971['creatorID']!='string'||_0x539971['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x539971['createdAt'])||_0x539971['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x4b866d['unit_id']);_0x30d8c3['run'](_0x4b866d['unit_id'],_0x4b866d['type'],_0x4b866d['head_revision'],_0x539971['creatorID'],_0x539971['createdAt'],_0x4b866d['soft_deleted_at_ms']);}_0x2aa793['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0xce4074 of _0x47f1a6)_0x2aa793['exec'](_0xce4074['sql']);let _0x347c26=_0x2aa793['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x8a0342=_0x2aa793['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x8a0342['some'](_0x408387=>_0x408387['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x3f056a=_0x2aa793['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']();_0x2aa793['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'+_0x347c26['sql']['slice'](_0x347c26['sql']['indexOf']('(')+0x1));let _0x15ecbf=D(_0x2aa793,'collaboration_changesets',['unit_id','revision']),_0x9be869=_0x8a0342['map'](_0x4e6907=>'\x22'+_0x4e6907['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x20cefe=_0x2aa793['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x9be869+',\x20created_at_ms)\x20VALUES\x20('+_0x8a0342['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x399f36 of _0x15ecbf){let _0x2b9b48=JSON['parse'](_0x399f36['payload_json']),_0xfd72a5=typeof _0x2b9b48['createTime']=='number'?_0x2b9b48['createTime']*0x3e8:void 0x0,_0x49ed04=!_0x1e17f1['resolveChangesetCreatedAt']&&!E(_0xfd72a5)?_0x1d3325(_0x399f36['unit_id'],_0x399f36['revision'])?.['committed_at']:void 0x0,_0x4401aa=_0x1e17f1['resolveChangesetCreatedAt']?await _0x1e17f1['resolveChangesetCreatedAt'](_0x399f36['unit_id'],_0x399f36['revision']):E(_0xfd72a5)?_0xfd72a5:E(_0x49ed04)?_0x49ed04:_0x160e9e;if(!Number['isSafeInteger'](_0x4401aa)||_0x4401aa<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x399f36['unit_id']+'\x20revision\x20'+_0x399f36['revision']);_0x2b9b48['createTime']=Math['floor'](_0x4401aa/0x3e8),_0x20cefe['run'](..._0x8a0342['map'](_0x4375ad=>_0x4375ad['name']==='payload_json'?JSON['stringify'](_0x2b9b48):_0x399f36[_0x4375ad['name']]),_0x4401aa);}_0x2aa793['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x3e9599 of _0x3f056a)_0x2aa793['exec'](_0x3e9599['sql']);if(_0x2aa793['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x2aa793['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x503234=!0x1;}finally{try{_0x503234&&_0x2aa793['exec']('ROLLBACK;');}finally{_0x2aa793['close']();}}}function E(_0x148fa3){return typeof _0x148fa3=='number'&&Number['isSafeInteger'](_0x148fa3)&&_0x148fa3>=0x0;}function*D(_0x48cd4a,_0x3b157b,_0x593fa2){let _0x27f9f9=_0x593fa2['join'](',\x20'),_0x5ca6a3=_0x48cd4a['prepare']('SELECT\x20*\x20FROM\x20'+_0x3b157b+'\x20ORDER\x20BY\x20'+_0x27f9f9+'\x20LIMIT\x20100'),_0x5c64b0=_0x48cd4a['prepare']('SELECT\x20*\x20FROM\x20'+_0x3b157b+'\x20WHERE\x20('+_0x27f9f9+')\x20>\x20('+_0x593fa2['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x27f9f9+'\x20LIMIT\x20100'),_0x471b9b=_0x5ca6a3['all']();for(;_0x471b9b['length']>0x0;){yield*_0x471b9b;let _0x30cd50=_0x593fa2['map'](_0x6f2f20=>_0x471b9b[_0x471b9b['length']-0x1][_0x6f2f20]);_0x471b9b=[],_0x471b9b=_0x5c64b0['all'](..._0x30cd50);}}exports['SQLiteDatabaseAdapter']=h,exports['migrateSQLiteCoreV1ToV2']=T;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const _0x397e1a=_0x21dc;(function(_0x14a210,_0x42672a){const _0x776878=_0x21dc,_0x5af94b=_0x14a210();while(!![]){try{const _0x21b560=-parseInt(_0x776878(0xe7))/0x1*(parseInt(_0x776878(0xe8))/0x2)+parseInt(_0x776878(0xef))/0x3+-parseInt(_0x776878(0xea))/0x4*(parseInt(_0x776878(0xf1))/0x5)+parseInt(_0x776878(0xf0))/0x6*(-parseInt(_0x776878(0xed))/0x7)+parseInt(_0x776878(0xe6))/0x8+-parseInt(_0x776878(0xec))/0x9+parseInt(_0x776878(0xe9))/0xa*(parseInt(_0x776878(0xee))/0xb);if(_0x21b560===_0x42672a)break;else _0x5af94b['push'](_0x5af94b['shift']());}catch(_0x5c0370){_0x5af94b['push'](_0x5af94b['shift']());}}}(_0x2218,0x8a757));function _0x21dc(_0x3ab819,_0x541fb6){_0x3ab819=_0x3ab819-0xe6;const _0x221874=_0x2218();let _0x21dca6=_0x221874[_0x3ab819];return _0x21dca6;}import _0x14aebd from'./index.cjs';const facadeExport0=_0x14aebd[_0x397e1a(0xeb)],facadeExport1=_0x14aebd['migrateSQLiteCoreV1ToV2'];function _0x2218(){const _0x228b33=['33pptXBj','2604198dWhHoj','140694ePYBYu','10RjMccu','6412328SuHhyH','27374VPNyVy','78sYndIL','7019490naiQmk','593400uqeKbc','SQLiteDatabaseAdapter','8787852iKcKpI','259ZphyXI'];_0x2218=function(){return _0x228b33;};return _0x2218();}export{facadeExport0 as SQLiteDatabaseAdapter,facadeExport1 as migrateSQLiteCoreV1ToV2};
1
+ function _0x50dd(_0x134da4,_0x3768b6){_0x134da4=_0x134da4-0x1f2;const _0x1741c1=_0x1741();let _0x50dda5=_0x1741c1[_0x134da4];return _0x50dda5;}const _0x5e43a0=_0x50dd;(function(_0x28acef,_0x256cb8){const _0x253a61=_0x50dd,_0x203c63=_0x28acef();while(!![]){try{const _0x329da4=parseInt(_0x253a61(0x1f2))/0x1*(parseInt(_0x253a61(0x1fa))/0x2)+-parseInt(_0x253a61(0x1f6))/0x3+-parseInt(_0x253a61(0x1f3))/0x4*(parseInt(_0x253a61(0x1f4))/0x5)+parseInt(_0x253a61(0x1fb))/0x6+parseInt(_0x253a61(0x1f8))/0x7+-parseInt(_0x253a61(0x1f9))/0x8+parseInt(_0x253a61(0x1f5))/0x9;if(_0x329da4===_0x256cb8)break;else _0x203c63['push'](_0x203c63['shift']());}catch(_0x4f7b57){_0x203c63['push'](_0x203c63['shift']());}}}(_0x1741,0xd8eb3));import _0xead828 from'./index.cjs';const facadeExport0=_0xead828[_0x5e43a0(0x1f7)],facadeExport1=_0xead828['migrateSQLiteCoreV1ToV2'];function _0x1741(){const _0xee05a9=['2778835trKZXW','9667143rFOSZW','1813665aLGHFD','SQLiteDatabaseAdapter','3379586VnTAPv','11583288RtOvFo','965652CBVOVc','9179532rmGYXO','2NdKYfM','8ZbpsYx'];_0x1741=function(){return _0xee05a9;};return _0x1741();}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.3",
7
+ "version": "1.0.4",
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.3",
23
- "@univerjs/protocol": "1.0.3",
22
+ "@univerjs-pro/collaboration-service": "1.0.4",
23
+ "@univerjs/protocol": "1.0.4",
24
24
  "libsql": "^0.5.29"
25
25
  }
26
26
  }