@univerjs-pro/collaboration-history-database-sqlite 1.0.2 → 1.0.3
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=(_0x3bb1cc,_0x3118f5,_0x326234,_0x5d2a4a)=>{if(_0x3118f5&&typeof _0x3118f5=='object'||typeof _0x3118f5=='function'){for(var _0x17ad26=r(_0x3118f5),_0x2a4cbe=0x0,_0x14e3b9=_0x17ad26['length'],_0x2ac7bd;_0x2a4cbe<_0x14e3b9;_0x2a4cbe++)_0x2ac7bd=_0x17ad26[_0x2a4cbe],!a['call'](_0x3bb1cc,_0x2ac7bd)&&_0x2ac7bd!==_0x326234&&t(_0x3bb1cc,_0x2ac7bd,{'get':(_0x5a374b=>_0x3118f5[_0x5a374b])['bind'](null,_0x2ac7bd),'enumerable':!(_0x5d2a4a=n(_0x3118f5,_0x2ac7bd))||_0x5d2a4a['enumerable']});}return _0x3bb1cc;},s=(_0x476dab,_0x14585f,_0x563366)=>(_0x563366=_0x476dab==null?{}:e(i(_0x476dab)),o(_0x14585f||!_0x476dab||!_0x476dab['__esModule']?t(_0x563366,'default',{'value':_0x476dab,'enumerable':!0x0}):_0x563366,_0x476dab));let c=require('libsql');c=s(c,0x1);var l='\x0a\x20\x20CREATE\x20TABLE\x20collaboration_history_records\x20(\x0a\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20start_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(start_revision\x20>=\x201),\x0a\x20\x20\x20\x20user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(created_at_ms\x20>=\x200),\x0a\x20\x20\x20\x20origin\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20additional_fields\x20TEXT,\x0a\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20start_revision)\x0a\x20\x20);\x0a',u='\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_origin_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20origin,\x20start_revision);\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_creator_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20user_id,\x20start_revision);\x0a',d=class{['_database'];['_disposed']=!0x1;constructor(_0x56b6fe){if(!_0x56b6fe?.['filename'])throw TypeError('SQLiteHistoryDatabaseAdapter\x20requires\x20a\x20filename');let _0x253d11=_0x56b6fe['busyTimeoutMs']??0x1388;if(!Number['isSafeInteger'](_0x253d11)||_0x253d11<0x0)throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');this['_database']=new c['default'](_0x56b6fe['filename'],{'timeout':_0x253d11});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+_0x253d11+';'),this['_initializeSchema']();}catch(_0x12b411){throw this['_database']['close'](),_0x12b411;}}async['getLatestRecord'](_0x3e560a,_0x18b5ad){this['_assertOpen']();let _0x18734f=this['_latest'](_0x18b5ad);return _0x18734f?f(_0x18734f):null;}async['appendRecord'](_0x525627,_0x4e10b9,_0x42790a){if(this['_assertOpen'](),!_0x4e10b9['unitID']||!_0x4e10b9['userID']||!Number['isSafeInteger'](_0x4e10b9['startRevision'])||_0x4e10b9['startRevision']<0x1||!Number['isSafeInteger'](_0x4e10b9['createdAt'])||_0x4e10b9['createdAt']<0x0)throw TypeError('History\x20record\x20is\x20invalid');return this['_transaction'](()=>{let _0x1a00a9=this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20=\x20?')['get'](_0x4e10b9['unitID'],_0x4e10b9['startRevision']);if(_0x1a00a9)return{'status':_0x1a00a9['user_id']===_0x4e10b9['userID']&&_0x1a00a9['created_at_ms']===_0x4e10b9['createdAt']&&_0x1a00a9['origin']===_0x4e10b9['origin']&&_0x1a00a9['additional_fields']===(_0x4e10b9['additionalFields']??null)?'already-exists':'conflict'};let _0x389594=this['_latest'](_0x4e10b9['unitID'])?.['start_revision']??null;return _0x389594!==_0x42790a['expectedLatestStartRevision']||_0x4e10b9['startRevision']<=(_0x389594??0x0)?{'status':'conflict'}:(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x4e10b9['unitID'],_0x4e10b9['startRevision'],_0x4e10b9['userID'],_0x4e10b9['createdAt'],_0x4e10b9['origin'],_0x4e10b9['additionalFields']??null),{'status':'appended'});});}async['listRecords'](_0x38bc63,_0x24a748,_0x55aca1){this['_assertOpen']();let _0x5a5044=[_0x55aca1['throughRevision'],_0x55aca1['throughRevision'],_0x24a748,_0x55aca1['throughRevision']],_0x2fccd5=[];_0x55aca1['beforeRevision']!==void 0x0&&(_0x2fccd5['push']('r.start_revision\x20<\x20?'),_0x5a5044['push'](_0x55aca1['beforeRevision'])),_0x55aca1['origin']&&(_0x2fccd5['push']('r.origin\x20=\x20?'),_0x5a5044['push'](_0x55aca1['origin'])),_0x55aca1['userIDs']?.['length']&&(_0x2fccd5['push']('r.user_id\x20IN\x20('+_0x55aca1['userIDs']['map'](()=>'?')['join'](',\x20')+')'),_0x5a5044['push'](..._0x55aca1['userIDs'])),_0x5a5044['push'](_0x55aca1['length']+0x1);let _0x255fc6=this['_database']['prepare']('\x0a\x20\x20\x20\x20\x20\x20SELECT\x20r.*,\x20MIN(?,\x20COALESCE((\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20next.start_revision\x20-\x201\x20FROM\x20collaboration_history_records\x20AS\x20next\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20next.unit_id\x20=\x20r.unit_id\x20AND\x20next.start_revision\x20>\x20r.start_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20next.start_revision\x20ASC\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20),\x20?))\x20AS\x20end_revision\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_records\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.unit_id\x20=\x20?\x20AND\x20r.start_revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20'+(_0x2fccd5['length']?'AND\x20'+_0x2fccd5['join']('\x20AND\x20'):'')+'\x0a\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20r.start_revision\x20DESC\x20LIMIT\x20?\x0a\x20\x20\x20\x20')['all'](..._0x5a5044);return{'records':_0x255fc6['slice'](0x0,_0x55aca1['length'])['map'](_0x3c6759=>({'record':f(_0x3c6759),'endRevision':_0x3c6759['end_revision']})),'hasMore':_0x255fc6['length']>_0x55aca1['length']};}async['listCreators'](_0x14a30d,_0x14c968,_0x4cd97e){this['_assertOpen']();let _0x3e76e4=this['_database']['prepare']('SELECT\x20DISTINCT\x20user_id,\x20origin\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20<=\x20?\x20ORDER\x20BY\x20user_id,\x20origin')['all'](_0x14c968,_0x4cd97e['throughRevision']),_0x4a17c6=new Map();for(let _0x18a928 of _0x3e76e4){let _0xf4707=_0x4a17c6['get'](_0x18a928['user_id'])??[];_0xf4707['push'](_0x18a928['origin']),_0x4a17c6['set'](_0x18a928['user_id'],_0xf4707);}return[..._0x4a17c6]['map'](([_0x38465d,_0x33c3c5])=>({'userID':_0x38465d,'origins':_0x33c3c5}));}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_latest'](_0x18bec4){return this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20ORDER\x20BY\x20start_revision\x20DESC\x20LIMIT\x201')['get'](_0x18bec4);}['_initializeSchema'](){this['_transaction'](()=>{let _0x49dc61=_0x26361f=>!!this['_database']['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x26361f),_0x3f9d23=_0x49dc61('collaboration_history_revisions')||_0x49dc61('collaboration_history_records');if(!_0x49dc61('collaboration_schema_versions')){if(_0x3f9d23)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201));');}let _0x1c3111=this['_database']['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']();if(_0x1c3111){if(_0x1c3111['version']===0x1)throw Error('SQLite\x20History\x20schema\x20v1\x20requires\x20migrateSQLiteHistoryV1ToV2\x20before\x20opening\x20the\x20Adapter');if(_0x1c3111['version']!==0x2)throw Error('SQLite\x20History\x20schema\x20version\x20'+_0x1c3111['version']+'\x20is\x20not\x20supported');if(!_0x49dc61('collaboration_history_records'))throw Error('SQLite\x20History\x20schema\x20v2\x20is\x20incomplete');this['_database']['prepare']('SELECT\x20unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20additional_fields\x20FROM\x20collaboration_history_records\x20LIMIT\x200')['all']();return;}if(_0x3f9d23)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec'](l+u+'INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x20VALUES\x20(\x27history\x27,\x202);');});}['_transaction'](_0x6bad4f){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x2ea4c0=_0x6bad4f();return this['_database']['exec']('COMMIT;'),_0x2ea4c0;}catch(_0x3dba3f){throw this['_database']['exec']('ROLLBACK;'),_0x3dba3f;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20History\x20Database\x20Adapter\x20is\x20disposed');}};function f(_0x34f585){return{'unitID':_0x34f585['unit_id'],'startRevision':_0x34f585['start_revision'],'userID':_0x34f585['user_id'],'createdAt':_0x34f585['created_at_ms'],'origin':_0x34f585['origin'],..._0x34f585['additional_fields']===null?{}:{'additionalFields':_0x34f585['additional_fields']}};}async function p(_0x5c545d){let _0x4e1093=new c['default'](_0x5c545d['filename'],{'fileMustExist':!0x0}),_0x5265aa=!0x1;try{if(_0x4e1093['exec']('BEGIN\x20IMMEDIATE;'),_0x5265aa=!0x0,_0x4e1093['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']()?.['version']!==0x1)throw Error('History\x20v1-to-v2\x20migration\x20requires\x20schema\x20version\x201');if(_0x4e1093['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27core\x27')['get']()?.['version']===0x1)throw Error('Migrate\x20SQLite\x20Core\x20v1\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');let _0x8e85f1=_0x4e1093['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27worktree\x27')['get']();if(_0x8e85f1&&_0x8e85f1['version']<0x3)throw Error('Migrate\x20SQLite\x20Worktree\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');if(_0x4e1093['prepare']('SELECT\x201\x20FROM\x20collaboration_history_revisions\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_history_revisions\x20AS\x20first\x0a\x20\x20\x20\x20\x20\x20\x20\x20ON\x20first.unit_id\x20=\x20r.unit_id\x20AND\x20first.revision\x20=\x20r.history_revision\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.history_revision\x20>\x20r.revision\x20OR\x20first.revision\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.history_revision\x20!=\x20first.revision\x20OR\x20first.user_id\x20=\x20\x27\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20typeof(first.committed_at)\x20!=\x20\x27integer\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.committed_at\x20<\x200\x20OR\x20first.committed_at\x20>\x209007199254740991\x0a\x20\x20\x20\x20\x20\x20LIMIT\x201')['get']())throw Error('History\x20v1\x20contains\x20a\x20missing\x20or\x20invalid\x20segment\x20starting\x20revision');_0x4e1093['exec'](l),_0x4e1093['exec']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20SELECT\x20unit_id,\x20revision,\x20user_id,\x20committed_at,\x20origin,\x20additional_fields\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x20WHERE\x20revision\x20=\x20history_revision;\x0a\x20\x20\x20\x20\x20\x20DROP\x20TABLE\x20collaboration_history_revisions;'),_0x4e1093['exec'](u),_0x4e1093['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27history\x27;\x20COMMIT;'),_0x5265aa=!0x1;}finally{try{_0x5265aa&&_0x4e1093['exec']('ROLLBACK;');}finally{_0x4e1093['close']();}}}exports['SQLiteHistoryDatabaseAdapter']=d,exports['migrateSQLiteHistoryV1ToV2']=p;
|
|
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=(_0x234d1b,_0x3220d4,_0x205c0b,_0x104668)=>{if(_0x3220d4&&typeof _0x3220d4=='object'||typeof _0x3220d4=='function'){for(var _0x56293d=r(_0x3220d4),_0x218c1c=0x0,_0x2a5a51=_0x56293d['length'],_0x5293ea;_0x218c1c<_0x2a5a51;_0x218c1c++)_0x5293ea=_0x56293d[_0x218c1c],!a['call'](_0x234d1b,_0x5293ea)&&_0x5293ea!==_0x205c0b&&t(_0x234d1b,_0x5293ea,{'get':(_0x26c2fc=>_0x3220d4[_0x26c2fc])['bind'](null,_0x5293ea),'enumerable':!(_0x104668=n(_0x3220d4,_0x5293ea))||_0x104668['enumerable']});}return _0x234d1b;},s=(_0x3db8bd,_0x88f2c8,_0x23b1bc)=>(_0x23b1bc=_0x3db8bd==null?{}:e(i(_0x3db8bd)),o(_0x88f2c8||!_0x3db8bd||!_0x3db8bd['__esModule']?t(_0x23b1bc,'default',{'value':_0x3db8bd,'enumerable':!0x0}):_0x23b1bc,_0x3db8bd));let c=require('libsql');c=s(c,0x1);var l='\x0a\x20\x20CREATE\x20TABLE\x20collaboration_history_records\x20(\x0a\x20\x20\x20\x20unit_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20start_revision\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(start_revision\x20>=\x201),\x0a\x20\x20\x20\x20user_id\x20TEXT\x20NOT\x20NULL,\x0a\x20\x20\x20\x20created_at_ms\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(created_at_ms\x20>=\x200),\x0a\x20\x20\x20\x20origin\x20INTEGER\x20NOT\x20NULL,\x0a\x20\x20\x20\x20additional_fields\x20TEXT,\x0a\x20\x20\x20\x20PRIMARY\x20KEY\x20(unit_id,\x20start_revision)\x0a\x20\x20);\x0a',u='\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_origin_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20origin,\x20start_revision);\x0a\x20\x20CREATE\x20INDEX\x20collaboration_history_creator_lookup\x0a\x20\x20\x20\x20ON\x20collaboration_history_records(unit_id,\x20user_id,\x20start_revision);\x0a',d=class{['_database'];['_disposed']=!0x1;constructor(_0x414ae8){if(!_0x414ae8?.['filename'])throw TypeError('SQLiteHistoryDatabaseAdapter\x20requires\x20a\x20filename');let _0x17697c=_0x414ae8['busyTimeoutMs']??0x1388;if(!Number['isSafeInteger'](_0x17697c)||_0x17697c<0x0)throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');this['_database']=new c['default'](_0x414ae8['filename'],{'timeout':_0x17697c});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+_0x17697c+';'),this['_initializeSchema']();}catch(_0x3ad4ec){throw this['_database']['close'](),_0x3ad4ec;}}async['getLatestRecord'](_0x465ccf,_0x538b55){this['_assertOpen']();let _0x2b1e33=this['_latest'](_0x538b55);return _0x2b1e33?f(_0x2b1e33):null;}async['appendRecord'](_0x1bca63,_0x2c8e98,_0x4c3cbe){if(this['_assertOpen'](),!_0x2c8e98['unitID']||!_0x2c8e98['userID']||!Number['isSafeInteger'](_0x2c8e98['startRevision'])||_0x2c8e98['startRevision']<0x1||!Number['isSafeInteger'](_0x2c8e98['createdAt'])||_0x2c8e98['createdAt']<0x0)throw TypeError('History\x20record\x20is\x20invalid');return this['_transaction'](()=>{let _0x39cfa6=this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20=\x20?')['get'](_0x2c8e98['unitID'],_0x2c8e98['startRevision']);if(_0x39cfa6)return{'status':_0x39cfa6['user_id']===_0x2c8e98['userID']&&_0x39cfa6['created_at_ms']===_0x2c8e98['createdAt']&&_0x39cfa6['origin']===_0x2c8e98['origin']&&_0x39cfa6['additional_fields']===(_0x2c8e98['additionalFields']??null)?'already-exists':'conflict'};let _0x118ca0=this['_latest'](_0x2c8e98['unitID'])?.['start_revision']??null;return _0x118ca0!==_0x4c3cbe['expectedLatestStartRevision']||_0x2c8e98['startRevision']<=(_0x118ca0??0x0)?{'status':'conflict'}:(this['_database']['prepare']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)')['run'](_0x2c8e98['unitID'],_0x2c8e98['startRevision'],_0x2c8e98['userID'],_0x2c8e98['createdAt'],_0x2c8e98['origin'],_0x2c8e98['additionalFields']??null),{'status':'appended'});});}async['listRecords'](_0x29c3b3,_0x19a410,_0x3a6caf){this['_assertOpen']();let _0x13dd14=[_0x3a6caf['throughRevision'],_0x3a6caf['throughRevision'],_0x19a410,_0x3a6caf['throughRevision']],_0x268f2c=[];_0x3a6caf['beforeRevision']!==void 0x0&&(_0x268f2c['push']('r.start_revision\x20<\x20?'),_0x13dd14['push'](_0x3a6caf['beforeRevision'])),_0x3a6caf['origin']&&(_0x268f2c['push']('r.origin\x20=\x20?'),_0x13dd14['push'](_0x3a6caf['origin'])),_0x3a6caf['userIDs']?.['length']&&(_0x268f2c['push']('r.user_id\x20IN\x20('+_0x3a6caf['userIDs']['map'](()=>'?')['join'](',\x20')+')'),_0x13dd14['push'](..._0x3a6caf['userIDs'])),_0x13dd14['push'](_0x3a6caf['length']+0x1);let _0x476626=this['_database']['prepare']('\x0a\x20\x20\x20\x20\x20\x20SELECT\x20r.*,\x20MIN(?,\x20COALESCE((\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20next.start_revision\x20-\x201\x20FROM\x20collaboration_history_records\x20AS\x20next\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20next.unit_id\x20=\x20r.unit_id\x20AND\x20next.start_revision\x20>\x20r.start_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20next.start_revision\x20ASC\x20LIMIT\x201\x0a\x20\x20\x20\x20\x20\x20),\x20?))\x20AS\x20end_revision\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_records\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.unit_id\x20=\x20?\x20AND\x20r.start_revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20'+(_0x268f2c['length']?'AND\x20'+_0x268f2c['join']('\x20AND\x20'):'')+'\x0a\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20r.start_revision\x20DESC\x20LIMIT\x20?\x0a\x20\x20\x20\x20')['all'](..._0x13dd14);return{'records':_0x476626['slice'](0x0,_0x3a6caf['length'])['map'](_0x3da87f=>({'record':f(_0x3da87f),'endRevision':_0x3da87f['end_revision']})),'hasMore':_0x476626['length']>_0x3a6caf['length']};}async['listCreators'](_0x5d1702,_0x20a70e,_0x5a8f0f){this['_assertOpen']();let _0x4098f2=this['_database']['prepare']('SELECT\x20DISTINCT\x20user_id,\x20origin\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20start_revision\x20<=\x20?\x20ORDER\x20BY\x20user_id,\x20origin')['all'](_0x20a70e,_0x5a8f0f['throughRevision']),_0x11601d=new Map();for(let _0x473dbc of _0x4098f2){let _0x5c56b4=_0x11601d['get'](_0x473dbc['user_id'])??[];_0x5c56b4['push'](_0x473dbc['origin']),_0x11601d['set'](_0x473dbc['user_id'],_0x5c56b4);}return[..._0x11601d]['map'](([_0x52cd61,_0x14a22d])=>({'userID':_0x52cd61,'origins':_0x14a22d}));}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_latest'](_0x3f74a3){return this['_database']['prepare']('SELECT\x20*\x20FROM\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20ORDER\x20BY\x20start_revision\x20DESC\x20LIMIT\x201')['get'](_0x3f74a3);}['_initializeSchema'](){this['_transaction'](()=>{let _0x1675e6=_0x1ce9a1=>!!this['_database']['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x1ce9a1),_0x589883=_0x1675e6('collaboration_history_revisions')||_0x1675e6('collaboration_history_records');if(!_0x1675e6('collaboration_schema_versions')){if(_0x589883)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec']('CREATE\x20TABLE\x20collaboration_schema_versions\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20component\x20TEXT\x20PRIMARY\x20KEY,\x20version\x20INTEGER\x20NOT\x20NULL\x20CHECK\x20(version\x20>=\x201));');}let _0x5ccc41=this['_database']['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']();if(_0x5ccc41){if(_0x5ccc41['version']===0x1)throw Error('SQLite\x20History\x20schema\x20v1\x20requires\x20migrateSQLiteHistoryV1ToV2\x20before\x20opening\x20the\x20Adapter');if(_0x5ccc41['version']!==0x2)throw Error('SQLite\x20History\x20schema\x20version\x20'+_0x5ccc41['version']+'\x20is\x20not\x20supported');if(!_0x1675e6('collaboration_history_records'))throw Error('SQLite\x20History\x20schema\x20v2\x20is\x20incomplete');this['_database']['prepare']('SELECT\x20unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20additional_fields\x20FROM\x20collaboration_history_records\x20LIMIT\x200')['all']();return;}if(_0x589883)throw Error('SQLite\x20History\x20tables\x20exist\x20without\x20a\x20schema\x20version');this['_database']['exec'](l+u+'INSERT\x20INTO\x20collaboration_schema_versions\x20(component,\x20version)\x20VALUES\x20(\x27history\x27,\x202);');});}['_transaction'](_0x3e9025){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x54bc31=_0x3e9025();return this['_database']['exec']('COMMIT;'),_0x54bc31;}catch(_0x4bcb7c){throw this['_database']['exec']('ROLLBACK;'),_0x4bcb7c;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20History\x20Database\x20Adapter\x20is\x20disposed');}};function f(_0x1efadd){return{'unitID':_0x1efadd['unit_id'],'startRevision':_0x1efadd['start_revision'],'userID':_0x1efadd['user_id'],'createdAt':_0x1efadd['created_at_ms'],'origin':_0x1efadd['origin'],..._0x1efadd['additional_fields']===null?{}:{'additionalFields':_0x1efadd['additional_fields']}};}async function p(_0x66a76c){let _0x8d5f1f=new c['default'](_0x66a76c['filename'],{'fileMustExist':!0x0}),_0x316785=!0x1;try{if(_0x8d5f1f['exec']('BEGIN\x20IMMEDIATE;'),_0x316785=!0x0,_0x8d5f1f['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']()?.['version']!==0x1)throw Error('History\x20v1-to-v2\x20migration\x20requires\x20schema\x20version\x201');if(_0x8d5f1f['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27core\x27')['get']()?.['version']===0x1)throw Error('Migrate\x20SQLite\x20Core\x20v1\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');let _0x2a0f1f=_0x8d5f1f['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27worktree\x27')['get']();if(_0x2a0f1f&&_0x2a0f1f['version']<0x3)throw Error('Migrate\x20SQLite\x20Worktree\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');if(_0x8d5f1f['prepare']('SELECT\x201\x20FROM\x20collaboration_history_revisions\x20AS\x20r\x0a\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20collaboration_history_revisions\x20AS\x20first\x0a\x20\x20\x20\x20\x20\x20\x20\x20ON\x20first.unit_id\x20=\x20r.unit_id\x20AND\x20first.revision\x20=\x20r.history_revision\x0a\x20\x20\x20\x20\x20\x20WHERE\x20r.history_revision\x20>\x20r.revision\x20OR\x20first.revision\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.history_revision\x20!=\x20first.revision\x20OR\x20first.user_id\x20=\x20\x27\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20typeof(first.committed_at)\x20!=\x20\x27integer\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20OR\x20first.committed_at\x20<\x200\x20OR\x20first.committed_at\x20>\x209007199254740991\x0a\x20\x20\x20\x20\x20\x20LIMIT\x201')['get']())throw Error('History\x20v1\x20contains\x20a\x20missing\x20or\x20invalid\x20segment\x20starting\x20revision');_0x8d5f1f['exec'](l),_0x8d5f1f['exec']('INSERT\x20INTO\x20collaboration_history_records\x0a\x20\x20\x20\x20\x20\x20(unit_id,\x20start_revision,\x20user_id,\x20created_at_ms,\x20origin,\x20additional_fields)\x0a\x20\x20\x20\x20\x20\x20SELECT\x20unit_id,\x20revision,\x20user_id,\x20committed_at,\x20origin,\x20additional_fields\x0a\x20\x20\x20\x20\x20\x20FROM\x20collaboration_history_revisions\x20WHERE\x20revision\x20=\x20history_revision;\x0a\x20\x20\x20\x20\x20\x20DROP\x20TABLE\x20collaboration_history_revisions;'),_0x8d5f1f['exec'](u),_0x8d5f1f['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27history\x27;\x20COMMIT;'),_0x316785=!0x1;}finally{try{_0x316785&&_0x8d5f1f['exec']('ROLLBACK;');}finally{_0x8d5f1f['close']();}}}exports['SQLiteHistoryDatabaseAdapter']=d,exports['migrateSQLiteHistoryV1ToV2']=p;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _0x3f7566=_0x28b7;(function(_0x2789e6,_0x56d1a0){const _0x1b6ec7=_0x28b7,_0x2547c7=_0x2789e6();while(!![]){try{const _0x210f1d=parseInt(_0x1b6ec7(0x128))/0x1+-parseInt(_0x1b6ec7(0x126))/0x2+-parseInt(_0x1b6ec7(0x12a))/0x3+-parseInt(_0x1b6ec7(0x12b))/0x4+parseInt(_0x1b6ec7(0x127))/0x5*(-parseInt(_0x1b6ec7(0x125))/0x6)+-parseInt(_0x1b6ec7(0x12c))/0x7*(-parseInt(_0x1b6ec7(0x12d))/0x8)+parseInt(_0x1b6ec7(0x129))/0x9;if(_0x210f1d===_0x56d1a0)break;else _0x2547c7['push'](_0x2547c7['shift']());}catch(_0xf5453a){_0x2547c7['push'](_0x2547c7['shift']());}}}(_0x2550,0xda535));function _0x28b7(_0x83f1ed,_0x562f34){_0x83f1ed=_0x83f1ed-0x124;const _0x255076=_0x2550();let _0x28b7b1=_0x255076[_0x83f1ed];return _0x28b7b1;}function _0x2550(){const _0x3b20f0=['SQLiteHistoryDatabaseAdapter','9374082mFoamy','3313908uukzRl','5NPLXOB','1298412vrzxXy','31800276xIWAhY','912561PxIITC','2563772OacHOf','1588412MvxXjI','8MVenGj'];_0x2550=function(){return _0x3b20f0;};return _0x2550();}import _0x402a37 from'./index.cjs';const facadeExport0=_0x402a37[_0x3f7566(0x124)],facadeExport1=_0x402a37['migrateSQLiteHistoryV1ToV2'];export{facadeExport0 as SQLiteHistoryDatabaseAdapter,facadeExport1 as migrateSQLiteHistoryV1ToV2};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.3",
|
|
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-history-service": "1.0.
|
|
23
|
-
"@univerjs/protocol": "1.0.
|
|
22
|
+
"@univerjs-pro/collaboration-history-service": "1.0.3",
|
|
23
|
+
"@univerjs/protocol": "1.0.3",
|
|
24
24
|
"libsql": "^0.5.29"
|
|
25
25
|
}
|
|
26
26
|
}
|