@univerjs-pro/collaboration-database-sqlite 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
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=(_0x3a7ee9,_0x28eb0c,_0x50db8a,_0x555717)=>{if(_0x28eb0c&&typeof _0x28eb0c=='object'||typeof _0x28eb0c=='function'){for(var _0x53fd6d=r(_0x28eb0c),_0x337698=0x0,_0x15e1e2=_0x53fd6d['length'],_0x2bbcfd;_0x337698<_0x15e1e2;_0x337698++)_0x2bbcfd=_0x53fd6d[_0x337698],!a['call'](_0x3a7ee9,_0x2bbcfd)&&_0x2bbcfd!==_0x50db8a&&t(_0x3a7ee9,_0x2bbcfd,{'get':(_0x37a1bf=>_0x28eb0c[_0x37a1bf])['bind'](null,_0x2bbcfd),'enumerable':!(_0x555717=n(_0x28eb0c,_0x2bbcfd))||_0x555717['enumerable']});}return _0x3a7ee9;},s=(_0x179223,_0x1f0a96,_0x6673c4)=>(_0x6673c4=_0x179223==null?{}:e(i(_0x179223)),o(_0x1f0a96||!_0x179223||!_0x179223['__esModule']?t(_0x6673c4,'default',{'value':_0x179223,'enumerable':!0x0}):_0x6673c4,_0x179223));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(_0x5b1441){g(_0x5b1441),this['_database']=new c['default'](_0x5b1441['filename'],{'timeout':_0x5b1441['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x5b1441['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x482e4c){throw this['_database']['close'](),_0x482e4c;}}async['getUnit'](_0x304f8e,_0x2a3e5e){this['_assertOpen']();let _0x330382=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'](_0x2a3e5e);return _0x330382?v(_0x330382):null;}async['getSnapshot'](_0x37b2ca,_0x50dd46,_0x1a16cf){this['_assertOpen']();let _0x5af126=_0x1a16cf?.['revision'];if(_0x5af126!==void 0x0&&_0x5af126<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x11725a=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'+(_0x5af126===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'](_0x50dd46,..._0x5af126===void 0x0?[]:[_0x5af126]);return _0x11725a?C(_0x11725a['payload_json']):null;}async['getSnapshotInfo'](_0x5e0084,_0x3dd253,_0x30be3e){this['_assertOpen']();let _0x37f90d=_0x30be3e?.['revision'];if(_0x37f90d!==void 0x0&&_0x37f90d<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x62c7f9=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'+(_0x37f90d===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'](_0x3dd253,..._0x37f90d===void 0x0?[]:[_0x37f90d]);return _0x62c7f9?{'unitID':_0x62c7f9['unitID'],'type':_0x62c7f9['type'],'rev':_0x62c7f9['rev']}:null;}async['getChangesets'](_0x3d95ee,_0x351b47,_0x1486e1){if(this['_assertOpen'](),_0x1486e1['from']<0x0||_0x1486e1['to']!==void 0x0&&_0x1486e1['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x16817c=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'+(_0x1486e1['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'](_0x1486e1['from'],..._0x1486e1['to']===void 0x0?[]:[_0x1486e1['to']],_0x351b47);return _0x16817c['length']===0x0?null:_0x16817c['flatMap'](_0x29f27a=>_0x29f27a['payload_json']?[C(_0x29f27a['payload_json'])]:[]);}async['createUnit'](_0x281bef,_0x40fc9d){this['_assertOpen'](),_(_0x40fc9d);let _0x195eff=S(_0x40fc9d['snapshot']),_0x3cc575=(_0x40fc9d['sheetBlocks']??[])['map'](_0x1cfe96=>({'id':_0x1cfe96['id'],'payload':S(_0x1cfe96)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x40fc9d['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x3eafef=this['_getStoredUnitRow'](_0x40fc9d['record']['unitID']);if(_0x3eafef){if(_0x3eafef['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x3eafef)};}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'](_0x40fc9d['record']['unitID'],_0x40fc9d['record']['type'],_0x40fc9d['record']['creatorID'],_0x40fc9d['record']['createdAt']),this['_writeSheetBlocks'](_0x40fc9d['record']['unitID'],_0x3cc575),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'](_0x40fc9d['record']['unitID'],_0x40fc9d['record']['type'],_0x195eff),{'status':'created','record':{..._0x40fc9d['record']}};});}async['deleteUnits'](_0x4348f1,_0x462f25){return this['_assertOpen'](),this['_transaction'](()=>{let _0x111a7e=x(_0x462f25['unitIDs'])['map'](_0xde64b1=>{let _0x972e45=this['_getStoredUnitRow'](_0xde64b1);if(!_0x972e45){if(_0x462f25['hardDelete']&&this['_hasTombstone'](_0xde64b1))return{'unitID':_0xde64b1,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0x462f25['hardDelete']?{'unitID':_0xde64b1,'status':'hard-deleted'}:{'unitID':_0xde64b1,'status':_0x972e45['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x40ccba=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'),_0x300469=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?)'),_0xedf67e=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x37cb16=Date['now']();for(let _0x24df5d of _0x111a7e)_0x24df5d['status']==='soft-deleted'?_0x40ccba['run'](_0x37cb16,_0x24df5d['unitID']):_0x24df5d['status']==='hard-deleted'&&(_0x300469['run'](_0x24df5d['unitID'],_0x37cb16),_0xedf67e['run'](_0x24df5d['unitID']));return{'units':_0x111a7e};});}async['recoverUnits'](_0x284c39,_0x58a7e0){return this['_assertOpen'](),this['_transaction'](()=>{let _0x4062c6=x(_0x58a7e0['unitIDs'])['map'](_0x54ac06=>{let _0x1e550b=this['_getStoredUnitRow'](_0x54ac06);if(!_0x1e550b)throw this['_hasTombstone'](_0x54ac06)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x54ac06,'status':_0x1e550b['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0x24c0f3=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 _0x221a56 of _0x4062c6)_0x221a56['status']==='recovered'&&_0x24c0f3['run'](_0x221a56['unitID']);return{'units':_0x4062c6};});}async['commitChangeset'](_0x473389,_0x2d1c0b){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0xd7e103}=_0x2d1c0b,_0x549fdc=this['_getActiveUnitRow'](_0xd7e103['unitID']);if(!_0x549fdc)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x549fdc['head_revision']!==_0xd7e103['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x549fdc['head_revision']};let _0x500305=Date['now'](),_0xd15977=S({..._0xd7e103,'createTime':Math['floor'](_0x500305/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'](_0xd7e103['unitID'],_0xd7e103['revision'],_0xd7e103['baseRev'],_0xd7e103['sid'],_0xd7e103['reqId'],_0x500305,_0xd15977),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'](_0xd7e103['revision'],_0xd7e103['unitID'],_0xd7e103['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0xd15977),'headRevision':_0xd7e103['revision']};});}async['saveSnapshot'](_0x169fb3,_0x11ebd4){this['_assertOpen']();let _0x1f2538=S(_0x11ebd4['snapshot']),_0x522a1e=(_0x11ebd4['sheetBlocks']??[])['map'](_0x51d4c4=>({'id':_0x51d4c4['id'],'payload':S(_0x51d4c4)}));this['_transaction'](()=>{let _0x59dfea=this['_getActiveUnitRow'](_0x11ebd4['snapshot']['unitID']);if(!_0x59dfea)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x11ebd4['snapshot']['type']!==_0x59dfea['type']||_0x11ebd4['snapshot']['rev']<0x1||_0x11ebd4['snapshot']['rev']>_0x59dfea['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x11ebd4['snapshot']['unitID'],_0x522a1e),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'](_0x11ebd4['snapshot']['unitID'],_0x11ebd4['snapshot']['rev'],_0x11ebd4['snapshot']['type'],_0x1f2538);});}async['getSheetBlock'](_0x393faf,_0x4784aa,_0xa120c5){this['_assertOpen']();let _0x28d4ed=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'](_0x4784aa,_0xa120c5);return _0x28d4ed?C(_0x28d4ed['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 _0x2086bb=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(_0x2086bb){if(_0x2086bb['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x2086bb['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x5bd141=m['filter'](_0x20248c=>!this['_hasTable'](_0x20248c));if(_0x5bd141['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x2086bb['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x5bd141['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x247949=>_0x247949['name']==='created_at_ms'&&_0x247949['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x224095=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x11e555=>_0x224095['some'](_0x4a0fd8=>_0x4a0fd8['name']===_0x11e555&&_0x4a0fd8['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'](_0x11f6e3){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'](_0x11f6e3)??null;}['_getStoredUnitRow'](_0x28d583){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'](_0x28d583)??null;}['_hasTombstone'](_0x453dd1){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x453dd1);}['_hasTable'](_0x530db2){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'](_0x530db2);}['_hasAnyCoreTable'](){return m['some'](_0x22b420=>this['_hasTable'](_0x22b420));}['_writeSheetBlocks'](_0x468096,_0x45dc42){let _0x5a65a9=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 _0x43cb8c of _0x45dc42)_0x5a65a9['run'](_0x468096,_0x43cb8c['id'],_0x43cb8c['payload']);}['_transaction'](_0x40ab9f){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x25774f=_0x40ab9f();return this['_database']['exec']('COMMIT;'),_0x25774f;}catch(_0x319779){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x319779;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x2577dd){if(!_0x2577dd['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x2577dd['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x2577dd['busyTimeoutMs'])||_0x2577dd['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x2bac71){let {record:_0x3e18ca,snapshot:_0x42e93d}=_0x2bac71;if(_0x3e18ca['headRevision']!==0x1||_0x42e93d['rev']!==0x1||_0x42e93d['unitID']!==_0x3e18ca['unitID']||_0x42e93d['type']!==_0x3e18ca['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x3e18ca['creatorID']!='string'||_0x3e18ca['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x3e18ca['createdAt'])||_0x3e18ca['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0xe3164d){return{'unitID':_0xe3164d['unit_id'],'type':_0xe3164d['type'],'headRevision':_0xe3164d['head_revision'],'creatorID':_0xe3164d['creator_id'],'createdAt':_0xe3164d['created_at_ms']};}function y(_0x12298e){return new l['CollabError']('INVALID_REQUEST',_0x12298e);}function b(_0x3715e5){return new l['CollabError']('INTERNAL_ERROR',_0x3715e5);}function x(_0x54b81c){return[...new Set(_0x54b81c)];}function S(_0x504f13){return JSON['stringify'](_0x504f13,function(_0x36cd73,_0x577b5b){let _0xe20e05=this[_0x36cd73];return _0xe20e05 instanceof Uint8Array?{[d]:Buffer['from'](_0xe20e05)['toString']('base64')}:_0x577b5b;});}function C(_0x12a5be){return JSON['parse'](_0x12a5be,(_0x550a96,_0x1b6808)=>w(_0x1b6808)?Uint8Array['from'](Buffer['from'](_0x1b6808[d],'base64')):_0x1b6808);}function w(_0x430302){return typeof _0x430302=='object'&&!!_0x430302&&Object['keys'](_0x430302)['length']===0x1&&typeof _0x430302[d]=='string';}async function T(_0x37e9e6){let _0x61802b=Date['now'](),_0x3c338c=new c['default'](_0x37e9e6['filename'],{'fileMustExist':!0x0}),_0x3a11a8=!0x1;try{if(_0x3c338c['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x3a11a8=!0x0,_0x3c338c['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 _0x2a2a00 of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x3c338c['prepare']('SELECT\x201\x20FROM\x20'+_0x2a2a00+'\x20LIMIT\x200')['all']();let _0x22b427=_0x3c338c['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x3c338c['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x1ec095=(_0x6d653f,_0x20683b)=>_0x22b427?.['get'](_0x6d653f,_0x20683b),_0x5df48a=_0x3c338c['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0x2ce5b9=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x5df48a['length']!==_0x2ce5b9['length']||_0x2ce5b9['some'](_0x2458d2=>!_0x5df48a['some'](_0x185c3e=>_0x185c3e['name']===_0x2458d2)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x200c00=_0x3c338c['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']();_0x3c338c['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 _0x4cbfc0=D(_0x3c338c,'collaboration_units',['unit_id']),_0x174570=_0x3c338c['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0x58560b of _0x4cbfc0){let _0x1ad44a=_0x37e9e6['resolveUnitCreation']?void 0x0:_0x1ec095(_0x58560b['unit_id'],0x1),_0x1b8d20=_0x37e9e6['resolveUnitCreation']?await _0x37e9e6['resolveUnitCreation'](_0x58560b['unit_id']):{'creatorID':_0x1ad44a?.['user_id']||'anonymous','createdAt':E(_0x1ad44a?.['committed_at'])?_0x1ad44a['committed_at']:_0x61802b};if(!_0x1b8d20||typeof _0x1b8d20['creatorID']!='string'||_0x1b8d20['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x1b8d20['createdAt'])||_0x1b8d20['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0x58560b['unit_id']);_0x174570['run'](_0x58560b['unit_id'],_0x58560b['type'],_0x58560b['head_revision'],_0x1b8d20['creatorID'],_0x1b8d20['createdAt'],_0x58560b['soft_deleted_at_ms']);}_0x3c338c['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0x4c7260 of _0x200c00)_0x3c338c['exec'](_0x4c7260['sql']);let _0x31b4f4=_0x3c338c['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x5c153e=_0x3c338c['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x5c153e['some'](_0x2c3275=>_0x2c3275['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x73d7fd=_0x3c338c['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']();_0x3c338c['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'+_0x31b4f4['sql']['slice'](_0x31b4f4['sql']['indexOf']('(')+0x1));let _0x10c7af=D(_0x3c338c,'collaboration_changesets',['unit_id','revision']),_0x19f325=_0x5c153e['map'](_0x2258b0=>'\x22'+_0x2258b0['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x3c9898=_0x3c338c['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x19f325+',\x20created_at_ms)\x20VALUES\x20('+_0x5c153e['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x7c5db0 of _0x10c7af){let _0x48a2b5=JSON['parse'](_0x7c5db0['payload_json']),_0x12ea9c=typeof _0x48a2b5['createTime']=='number'?_0x48a2b5['createTime']*0x3e8:void 0x0,_0x2309d5=!_0x37e9e6['resolveChangesetCreatedAt']&&!E(_0x12ea9c)?_0x1ec095(_0x7c5db0['unit_id'],_0x7c5db0['revision'])?.['committed_at']:void 0x0,_0xb643d5=_0x37e9e6['resolveChangesetCreatedAt']?await _0x37e9e6['resolveChangesetCreatedAt'](_0x7c5db0['unit_id'],_0x7c5db0['revision']):E(_0x12ea9c)?_0x12ea9c:E(_0x2309d5)?_0x2309d5:_0x61802b;if(!Number['isSafeInteger'](_0xb643d5)||_0xb643d5<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x7c5db0['unit_id']+'\x20revision\x20'+_0x7c5db0['revision']);_0x48a2b5['createTime']=Math['floor'](_0xb643d5/0x3e8),_0x3c9898['run'](..._0x5c153e['map'](_0x4b8a3c=>_0x4b8a3c['name']==='payload_json'?JSON['stringify'](_0x48a2b5):_0x7c5db0[_0x4b8a3c['name']]),_0xb643d5);}_0x3c338c['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x37dabb of _0x73d7fd)_0x3c338c['exec'](_0x37dabb['sql']);if(_0x3c338c['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x3c338c['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x3a11a8=!0x1;}finally{try{_0x3a11a8&&_0x3c338c['exec']('ROLLBACK;');}finally{_0x3c338c['close']();}}}function E(_0x468fc8){return typeof _0x468fc8=='number'&&Number['isSafeInteger'](_0x468fc8)&&_0x468fc8>=0x0;}function*D(_0x4234af,_0x4cce59,_0x1f5d25){let _0x243688=_0x1f5d25['join'](',\x20'),_0x2f56f2=_0x4234af['prepare']('SELECT\x20*\x20FROM\x20'+_0x4cce59+'\x20ORDER\x20BY\x20'+_0x243688+'\x20LIMIT\x20100'),_0x47c832=_0x4234af['prepare']('SELECT\x20*\x20FROM\x20'+_0x4cce59+'\x20WHERE\x20('+_0x243688+')\x20>\x20('+_0x1f5d25['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x243688+'\x20LIMIT\x20100'),_0x227f98=_0x2f56f2['all']();for(;_0x227f98['length']>0x0;){yield*_0x227f98;let _0x55eaea=_0x1f5d25['map'](_0x4897df=>_0x227f98[_0x227f98['length']-0x1][_0x4897df]);_0x227f98=[],_0x227f98=_0x47c832['all'](..._0x55eaea);}}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=(_0x22b0ed,_0x1f2f51,_0x55f8ff,_0x1b66fd)=>{if(_0x1f2f51&&typeof _0x1f2f51=='object'||typeof _0x1f2f51=='function'){for(var _0x3ddd14=r(_0x1f2f51),_0x3d094a=0x0,_0x5f53ca=_0x3ddd14['length'],_0xf68f3d;_0x3d094a<_0x5f53ca;_0x3d094a++)_0xf68f3d=_0x3ddd14[_0x3d094a],!a['call'](_0x22b0ed,_0xf68f3d)&&_0xf68f3d!==_0x55f8ff&&t(_0x22b0ed,_0xf68f3d,{'get':(_0x442a02=>_0x1f2f51[_0x442a02])['bind'](null,_0xf68f3d),'enumerable':!(_0x1b66fd=n(_0x1f2f51,_0xf68f3d))||_0x1b66fd['enumerable']});}return _0x22b0ed;},s=(_0x35d6f1,_0x23d277,_0x591363)=>(_0x591363=_0x35d6f1==null?{}:e(i(_0x35d6f1)),o(_0x23d277||!_0x35d6f1||!_0x35d6f1['__esModule']?t(_0x591363,'default',{'value':_0x35d6f1,'enumerable':!0x0}):_0x591363,_0x35d6f1));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(_0x3f97cc){g(_0x3f97cc),this['_database']=new c['default'](_0x3f97cc['filename'],{'timeout':_0x3f97cc['busyTimeoutMs']??u});try{this['_database']['exec']('PRAGMA\x20foreign_keys\x20=\x20ON;'),this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+(_0x3f97cc['busyTimeoutMs']??u)+';'),this['_initializeSchema']();}catch(_0x1360cf){throw this['_database']['close'](),_0x1360cf;}}async['getUnit'](_0x44da5d,_0x52e300){this['_assertOpen']();let _0x363632=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'](_0x52e300);return _0x363632?v(_0x363632):null;}async['getSnapshot'](_0x26339a,_0x3d24e0,_0x5131ea){this['_assertOpen']();let _0x46b3d5=_0x5131ea?.['revision'];if(_0x46b3d5!==void 0x0&&_0x46b3d5<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x443a96=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'+(_0x46b3d5===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'](_0x3d24e0,..._0x46b3d5===void 0x0?[]:[_0x46b3d5]);return _0x443a96?C(_0x443a96['payload_json']):null;}async['getSnapshotInfo'](_0x3518db,_0x5fd69b,_0x1c34eb){this['_assertOpen']();let _0x51dad7=_0x1c34eb?.['revision'];if(_0x51dad7!==void 0x0&&_0x51dad7<0x0)throw y('Snapshot\x20revision\x20cannot\x20be\x20negative');let _0x30a47a=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'+(_0x51dad7===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'](_0x5fd69b,..._0x51dad7===void 0x0?[]:[_0x51dad7]);return _0x30a47a?{'unitID':_0x30a47a['unitID'],'type':_0x30a47a['type'],'rev':_0x30a47a['rev']}:null;}async['getChangesets'](_0x6e8692,_0x43c8a9,_0x93717f){if(this['_assertOpen'](),_0x93717f['from']<0x0||_0x93717f['to']!==void 0x0&&_0x93717f['to']<0x0)throw y('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x382734=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'+(_0x93717f['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'](_0x93717f['from'],..._0x93717f['to']===void 0x0?[]:[_0x93717f['to']],_0x43c8a9);return _0x382734['length']===0x0?null:_0x382734['flatMap'](_0x3bfa52=>_0x3bfa52['payload_json']?[C(_0x3bfa52['payload_json'])]:[]);}async['createUnit'](_0x141f37,_0x37ade2){this['_assertOpen'](),_(_0x37ade2);let _0x59e0f2=S(_0x37ade2['snapshot']),_0x3b3c85=(_0x37ade2['sheetBlocks']??[])['map'](_0x38801b=>({'id':_0x38801b['id'],'payload':S(_0x38801b)}));return this['_transaction'](()=>{if(this['_hasTombstone'](_0x37ade2['record']['unitID']))throw y('Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID');let _0x2e9c31=this['_getStoredUnitRow'](_0x37ade2['record']['unitID']);if(_0x2e9c31){if(_0x2e9c31['soft_deleted_at_ms']!==null)throw y('Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID');return{'status':'already-exists','record':v(_0x2e9c31)};}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'](_0x37ade2['record']['unitID'],_0x37ade2['record']['type'],_0x37ade2['record']['creatorID'],_0x37ade2['record']['createdAt']),this['_writeSheetBlocks'](_0x37ade2['record']['unitID'],_0x3b3c85),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'](_0x37ade2['record']['unitID'],_0x37ade2['record']['type'],_0x59e0f2),{'status':'created','record':{..._0x37ade2['record']}};});}async['deleteUnits'](_0x5cdb94,_0xb65b8f){return this['_assertOpen'](),this['_transaction'](()=>{let _0x25b308=x(_0xb65b8f['unitIDs'])['map'](_0x2fd91a=>{let _0xe932e1=this['_getStoredUnitRow'](_0x2fd91a);if(!_0xe932e1){if(_0xb65b8f['hardDelete']&&this['_hasTombstone'](_0x2fd91a))return{'unitID':_0x2fd91a,'status':'already-hard-deleted'};throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20delete\x20a\x20missing\x20unit');}return _0xb65b8f['hardDelete']?{'unitID':_0x2fd91a,'status':'hard-deleted'}:{'unitID':_0x2fd91a,'status':_0xe932e1['soft_deleted_at_ms']===null?'soft-deleted':'already-soft-deleted'};}),_0x457038=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'),_0x259881=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?)'),_0x283ecc=this['_database']['prepare']('DELETE\x20FROM\x20collaboration_units\x20WHERE\x20unit_id\x20=\x20?'),_0x5c0937=Date['now']();for(let _0x5af0c8 of _0x25b308)_0x5af0c8['status']==='soft-deleted'?_0x457038['run'](_0x5c0937,_0x5af0c8['unitID']):_0x5af0c8['status']==='hard-deleted'&&(_0x259881['run'](_0x5af0c8['unitID'],_0x5c0937),_0x283ecc['run'](_0x5af0c8['unitID']));return{'units':_0x25b308};});}async['recoverUnits'](_0x4b6e3a,_0x368f25){return this['_assertOpen'](),this['_transaction'](()=>{let _0x52d06c=x(_0x368f25['unitIDs'])['map'](_0x4e933e=>{let _0x210a75=this['_getStoredUnitRow'](_0x4e933e);if(!_0x210a75)throw this['_hasTombstone'](_0x4e933e)?y('Cannot\x20recover\x20a\x20hard-deleted\x20unit'):new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x4e933e,'status':_0x210a75['soft_deleted_at_ms']===null?'already-active':'recovered'};}),_0xa0dcbc=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 _0x8744cf of _0x52d06c)_0x8744cf['status']==='recovered'&&_0xa0dcbc['run'](_0x8744cf['unitID']);return{'units':_0x52d06c};});}async['commitChangeset'](_0x24ebcc,_0x3a58ce){return this['_assertOpen'](),this['_transaction'](()=>{let {changeset:_0x1f2d24}=_0x3a58ce,_0x4f61f9=this['_getActiveUnitRow'](_0x1f2d24['unitID']);if(!_0x4f61f9)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x4f61f9['head_revision']!==_0x1f2d24['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x4f61f9['head_revision']};let _0x14348b=Date['now'](),_0x518b1b=S({..._0x1f2d24,'createTime':Math['floor'](_0x14348b/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'](_0x1f2d24['unitID'],_0x1f2d24['revision'],_0x1f2d24['baseRev'],_0x1f2d24['sid'],_0x1f2d24['reqId'],_0x14348b,_0x518b1b),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'](_0x1f2d24['revision'],_0x1f2d24['unitID'],_0x1f2d24['revision']-0x1)['changes']!==0x1)throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction');return{'status':'committed','changeset':C(_0x518b1b),'headRevision':_0x1f2d24['revision']};});}async['saveSnapshot'](_0x538e0c,_0x5d3558){this['_assertOpen']();let _0x5a717a=S(_0x5d3558['snapshot']),_0x5bf0a8=(_0x5d3558['sheetBlocks']??[])['map'](_0x281e41=>({'id':_0x281e41['id'],'payload':S(_0x281e41)}));this['_transaction'](()=>{let _0x47fd99=this['_getActiveUnitRow'](_0x5d3558['snapshot']['unitID']);if(!_0x47fd99)throw new l['CollabError']('UNIT_NOT_FOUND','Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x5d3558['snapshot']['type']!==_0x47fd99['type']||_0x5d3558['snapshot']['rev']<0x1||_0x5d3558['snapshot']['rev']>_0x47fd99['head_revision'])throw y('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');this['_writeSheetBlocks'](_0x5d3558['snapshot']['unitID'],_0x5bf0a8),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'](_0x5d3558['snapshot']['unitID'],_0x5d3558['snapshot']['rev'],_0x5d3558['snapshot']['type'],_0x5a717a);});}async['getSheetBlock'](_0x2785fd,_0x4a3458,_0x25b9bd){this['_assertOpen']();let _0x119863=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'](_0x4a3458,_0x25b9bd);return _0x119863?C(_0x119863['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 _0x32f3dd=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(_0x32f3dd){if(_0x32f3dd['version']!==p)throw b('SQLite\x20collaboration\x20core\x20schema\x20version\x20'+_0x32f3dd['version']+'\x20is\x20not\x20supported;\x20version\x201\x20requires\x20explicit\x20migrateSQLiteCoreV1ToV2\x20with\x20a\x20Unit\x20creation\x20resolver');let _0x5ddd02=m['filter'](_0x1befff=>!this['_hasTable'](_0x1befff));if(_0x5ddd02['length']>0x0)throw b('SQLite\x20collaboration\x20core\x20schema\x20v'+_0x32f3dd['version']+'\x20is\x20incomplete:\x20missing\x20'+_0x5ddd02['join'](',\x20'));if(!this['_database']['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']()['some'](_0x2f2fba=>_0x2f2fba['name']==='created_at_ms'&&_0x2f2fba['notnull']===0x1))throw b('Changeset\x20schema\x20requires\x20NOT\x20NULL\x20created_at_ms');let _0x4e861a=this['_database']['prepare']('PRAGMA\x20table_info(collaboration_units)')['all']();if(!['creator_id','created_at_ms']['every'](_0x2ebb77=>_0x4e861a['some'](_0x4d60ff=>_0x4d60ff['name']===_0x2ebb77&&_0x4d60ff['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'](_0x3729bd){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'](_0x3729bd)??null;}['_getStoredUnitRow'](_0x3199c9){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'](_0x3199c9)??null;}['_hasTombstone'](_0x351a13){return!!this['_database']['prepare']('SELECT\x201\x20FROM\x20collaboration_unit_tombstones\x20WHERE\x20unit_id\x20=\x20?')['get'](_0x351a13);}['_hasTable'](_0x12bc1d){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'](_0x12bc1d);}['_hasAnyCoreTable'](){return m['some'](_0x4bf02a=>this['_hasTable'](_0x4bf02a));}['_writeSheetBlocks'](_0x499c5d,_0x407700){let _0x1b4dd0=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 _0x1be5b1 of _0x407700)_0x1b4dd0['run'](_0x499c5d,_0x1be5b1['id'],_0x1be5b1['payload']);}['_transaction'](_0x710410){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x3bb171=_0x710410();return this['_database']['exec']('COMMIT;'),_0x3bb171;}catch(_0x5f2dbe){throw this['_database']['inTransaction']&&this['_database']['exec']('ROLLBACK;'),_0x5f2dbe;}}['_assertOpen'](){if(this['_disposed'])throw new l['CollabError']('INTERNAL_ERROR','SQLite\x20Database\x20Adapter\x20is\x20disposed');}};function g(_0x21463f){if(!_0x21463f['filename'])throw y('SQLite\x20filename\x20is\x20required');if(_0x21463f['busyTimeoutMs']!==void 0x0&&(!Number['isSafeInteger'](_0x21463f['busyTimeoutMs'])||_0x21463f['busyTimeoutMs']<0x0))throw y('SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer');}function _(_0x4b274c){let {record:_0x413748,snapshot:_0x169704}=_0x4b274c;if(_0x413748['headRevision']!==0x1||_0x169704['rev']!==0x1||_0x169704['unitID']!==_0x413748['unitID']||_0x169704['type']!==_0x413748['type'])throw y('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');if(typeof _0x413748['creatorID']!='string'||_0x413748['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x413748['createdAt'])||_0x413748['createdAt']<0x0)throw y('Unit\x20creation\x20requires\x20creatorID\x20and\x20createdAt\x20in\x20Unix\x20milliseconds');}function v(_0x470501){return{'unitID':_0x470501['unit_id'],'type':_0x470501['type'],'headRevision':_0x470501['head_revision'],'creatorID':_0x470501['creator_id'],'createdAt':_0x470501['created_at_ms']};}function y(_0x340e14){return new l['CollabError']('INVALID_REQUEST',_0x340e14);}function b(_0xdda294){return new l['CollabError']('INTERNAL_ERROR',_0xdda294);}function x(_0x5c8634){return[...new Set(_0x5c8634)];}function S(_0x428ad2){return JSON['stringify'](_0x428ad2,function(_0x466185,_0x40f4a6){let _0x26cc02=this[_0x466185];return _0x26cc02 instanceof Uint8Array?{[d]:Buffer['from'](_0x26cc02)['toString']('base64')}:_0x40f4a6;});}function C(_0x4cfd8e){return JSON['parse'](_0x4cfd8e,(_0x5d76b6,_0x512ac1)=>w(_0x512ac1)?Uint8Array['from'](Buffer['from'](_0x512ac1[d],'base64')):_0x512ac1);}function w(_0x3159f1){return typeof _0x3159f1=='object'&&!!_0x3159f1&&Object['keys'](_0x3159f1)['length']===0x1&&typeof _0x3159f1[d]=='string';}async function T(_0x1b60c7){let _0x488c15=Date['now'](),_0x1a4b66=new c['default'](_0x1b60c7['filename'],{'fileMustExist':!0x0}),_0x205dcf=!0x1;try{if(_0x1a4b66['exec']('PRAGMA\x20foreign_keys\x20=\x20OFF;\x20PRAGMA\x20legacy_alter_table\x20=\x20ON;\x20BEGIN\x20IMMEDIATE;'),_0x205dcf=!0x0,_0x1a4b66['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 _0x4cc9fd of['collaboration_unit_tombstones','collaboration_snapshots','collaboration_changesets','collaboration_sheet_blocks'])_0x1a4b66['prepare']('SELECT\x201\x20FROM\x20'+_0x4cc9fd+'\x20LIMIT\x200')['all']();let _0x53f3bc=_0x1a4b66['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_history_revisions\x27')['get']()?_0x1a4b66['prepare']('SELECT\x20user_id,\x20committed_at\x20FROM\x20collaboration_history_revisions\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20revision\x20=\x20?'):void 0x0,_0x3f1579=(_0x2a3b5f,_0x12587b)=>_0x53f3bc?.['get'](_0x2a3b5f,_0x12587b),_0x45a9f1=_0x1a4b66['prepare']('PRAGMA\x20table_info(collaboration_units)')['all'](),_0xaeb75c=['unit_id','type','head_revision','soft_deleted_at_ms'];if(_0x45a9f1['length']!==_0xaeb75c['length']||_0xaeb75c['some'](_0x30fcb3=>!_0x45a9f1['some'](_0x2648b0=>_0x2648b0['name']===_0x30fcb3)))throw new l['CollabError']('INVALID_REQUEST','Core\x20v1\x20Unit\x20columns\x20differ\x20from\x20the\x20supported\x20schema;\x20refusing\x20a\x20potentially\x20lossy\x20migration');let _0x23032a=_0x1a4b66['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']();_0x1a4b66['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 _0x1938e1=D(_0x1a4b66,'collaboration_units',['unit_id']),_0x36d593=_0x1a4b66['prepare']('INSERT\x20INTO\x20collaboration_units_v2\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)');for(let _0xac63a5 of _0x1938e1){let _0x4778f0=_0x1b60c7['resolveUnitCreation']?void 0x0:_0x3f1579(_0xac63a5['unit_id'],0x1),_0x1ae12c=_0x1b60c7['resolveUnitCreation']?await _0x1b60c7['resolveUnitCreation'](_0xac63a5['unit_id']):{'creatorID':_0x4778f0?.['user_id']||'anonymous','createdAt':E(_0x4778f0?.['committed_at'])?_0x4778f0['committed_at']:_0x488c15};if(!_0x1ae12c||typeof _0x1ae12c['creatorID']!='string'||_0x1ae12c['creatorID']['length']===0x0||!Number['isSafeInteger'](_0x1ae12c['createdAt'])||_0x1ae12c['createdAt']<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20creation\x20facts\x20for\x20Unit\x20'+_0xac63a5['unit_id']);_0x36d593['run'](_0xac63a5['unit_id'],_0xac63a5['type'],_0xac63a5['head_revision'],_0x1ae12c['creatorID'],_0x1ae12c['createdAt'],_0xac63a5['soft_deleted_at_ms']);}_0x1a4b66['exec']('DROP\x20TABLE\x20collaboration_units;\x20ALTER\x20TABLE\x20collaboration_units_v2\x20RENAME\x20TO\x20collaboration_units;');for(let _0x574af3 of _0x23032a)_0x1a4b66['exec'](_0x574af3['sql']);let _0x30a734=_0x1a4b66['prepare']('SELECT\x20sql\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20\x27collaboration_changesets\x27')['get'](),_0x204f76=_0x1a4b66['prepare']('PRAGMA\x20table_info(collaboration_changesets)')['all']();if(_0x204f76['some'](_0x3dc1eb=>_0x3dc1eb['name']==='created_at_ms'))throw new l['CollabError']('INVALID_REQUEST','Unexpected\x20changeset\x20creation-time\x20column\x20in\x20legacy\x20schema');let _0x1efff6=_0x1a4b66['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']();_0x1a4b66['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'+_0x30a734['sql']['slice'](_0x30a734['sql']['indexOf']('(')+0x1));let _0xf5e714=D(_0x1a4b66,'collaboration_changesets',['unit_id','revision']),_0x30e61b=_0x204f76['map'](_0x142816=>'\x22'+_0x142816['name']['replaceAll']('\x22','\x22\x22')+'\x22')['join'](',\x20'),_0x404587=_0x1a4b66['prepare']('INSERT\x20INTO\x20collaboration_changesets_new\x20('+_0x30e61b+',\x20created_at_ms)\x20VALUES\x20('+_0x204f76['map'](()=>'?')['join'](',\x20')+',\x20?)');for(let _0x4cac8a of _0xf5e714){let _0x14df36=JSON['parse'](_0x4cac8a['payload_json']),_0x1dd624=typeof _0x14df36['createTime']=='number'?_0x14df36['createTime']*0x3e8:void 0x0,_0xccf4c3=!_0x1b60c7['resolveChangesetCreatedAt']&&!E(_0x1dd624)?_0x3f1579(_0x4cac8a['unit_id'],_0x4cac8a['revision'])?.['committed_at']:void 0x0,_0x271309=_0x1b60c7['resolveChangesetCreatedAt']?await _0x1b60c7['resolveChangesetCreatedAt'](_0x4cac8a['unit_id'],_0x4cac8a['revision']):E(_0x1dd624)?_0x1dd624:E(_0xccf4c3)?_0xccf4c3:_0x488c15;if(!Number['isSafeInteger'](_0x271309)||_0x271309<0x0)throw new l['CollabError']('INVALID_REQUEST','Missing\x20or\x20invalid\x20changeset\x20time\x20for\x20Unit\x20'+_0x4cac8a['unit_id']+'\x20revision\x20'+_0x4cac8a['revision']);_0x14df36['createTime']=Math['floor'](_0x271309/0x3e8),_0x404587['run'](..._0x204f76['map'](_0x2ab511=>_0x2ab511['name']==='payload_json'?JSON['stringify'](_0x14df36):_0x4cac8a[_0x2ab511['name']]),_0x271309);}_0x1a4b66['exec']('DROP\x20TABLE\x20collaboration_changesets;\x20ALTER\x20TABLE\x20collaboration_changesets_new\x20RENAME\x20TO\x20collaboration_changesets;');for(let _0x4f95a6 of _0x1efff6)_0x1a4b66['exec'](_0x4f95a6['sql']);if(_0x1a4b66['prepare']('PRAGMA\x20foreign_key_check')['all']()['length']>0x0)throw new l['CollabError']('INVALID_REQUEST','Foreign\x20key\x20validation\x20failed\x20during\x20core\x20migration');_0x1a4b66['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27core\x27;\x20COMMIT;'),_0x205dcf=!0x1;}finally{try{_0x205dcf&&_0x1a4b66['exec']('ROLLBACK;');}finally{_0x1a4b66['close']();}}}function E(_0x53c4cf){return typeof _0x53c4cf=='number'&&Number['isSafeInteger'](_0x53c4cf)&&_0x53c4cf>=0x0;}function*D(_0x55e8f4,_0x2577c3,_0x3a6b3c){let _0x43ada2=_0x3a6b3c['join'](',\x20'),_0x252ee4=_0x55e8f4['prepare']('SELECT\x20*\x20FROM\x20'+_0x2577c3+'\x20ORDER\x20BY\x20'+_0x43ada2+'\x20LIMIT\x20100'),_0x3b06b4=_0x55e8f4['prepare']('SELECT\x20*\x20FROM\x20'+_0x2577c3+'\x20WHERE\x20('+_0x43ada2+')\x20>\x20('+_0x3a6b3c['map'](()=>'?')['join'](',\x20')+')\x20ORDER\x20BY\x20'+_0x43ada2+'\x20LIMIT\x20100'),_0x1656e6=_0x252ee4['all']();for(;_0x1656e6['length']>0x0;){yield*_0x1656e6;let _0x386e33=_0x3a6b3c['map'](_0x430b76=>_0x1656e6[_0x1656e6['length']-0x1][_0x430b76]);_0x1656e6=[],_0x1656e6=_0x3b06b4['all'](..._0x386e33);}}exports['SQLiteDatabaseAdapter']=h,exports['migrateSQLiteCoreV1ToV2']=T;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _0x226e13=_0x526f;(function(_0x4268b5,_0x2e061b){const _0x19ccce=_0x526f,_0x27b7a1=_0x4268b5();while(!![]){try{const _0xbaae75=parseInt(_0x19ccce(0x1df))/0x1*(parseInt(_0x19ccce(0x1e0))/0x2)+-parseInt(_0x19ccce(0x1e5))/0x3+-parseInt(_0x19ccce(0x1de))/0x4*(-parseInt(_0x19ccce(0x1e6))/0x5)+-parseInt(_0x19ccce(0x1e7))/0x6+-parseInt(_0x19ccce(0x1e3))/0x7+-parseInt(_0x19ccce(0x1e4))/0x8+parseInt(_0x19ccce(0x1e1))/0x9;if(_0xbaae75===_0x2e061b)break;else _0x27b7a1['push'](_0x27b7a1['shift']());}catch(_0x16ae69){_0x27b7a1['push'](_0x27b7a1['shift']());}}}(_0x3eb2,0x8b07e));function _0x526f(_0x118e9c,_0x12f458){_0x118e9c=_0x118e9c-0x1de;const _0x3eb23d=_0x3eb2();let _0x526f80=_0x3eb23d[_0x118e9c];return _0x526f80;}function _0x3eb2(){const _0x35784d=['12242124JDfIBV','migrateSQLiteCoreV1ToV2','3799040CoZGZh','1303424EQifOM','2705223ifKAfa','220rCxmFM','3314634ORFWwp','40184egyHeQ','161OTxzCY','11516xMmxnu'];_0x3eb2=function(){return _0x35784d;};return _0x3eb2();}import _0x2c47fa from'./index.cjs';const facadeExport0=_0x2c47fa['SQLiteDatabaseAdapter'],facadeExport1=_0x2c47fa[_0x226e13(0x1e2)];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.3.
|
|
7
|
+
"version": "1.3.1",
|
|
8
8
|
"main": "./dist/index.cjs",
|
|
9
9
|
"module": "./dist/index.mjs",
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@univerjs-pro/collaboration-service": "1.3.
|
|
23
|
-
"@univerjs/protocol": "1.3.
|
|
22
|
+
"@univerjs-pro/collaboration-service": "1.3.1",
|
|
23
|
+
"@univerjs/protocol": "1.3.1",
|
|
24
24
|
"libsql": "^0.5.29"
|
|
25
25
|
}
|
|
26
26
|
}
|