@univerjs-pro/collaboration-history-database-sqlite 1.0.2 → 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 +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=(_0x2b1b63,_0x302ed0,_0x5ffac8,_0x578e1c)=>{if(_0x302ed0&&typeof _0x302ed0=='object'||typeof _0x302ed0=='function'){for(var _0x2710db=r(_0x302ed0),_0x5610c8=0x0,_0x198caf=_0x2710db['length'],_0x53dd64;_0x5610c8<_0x198caf;_0x5610c8++)_0x53dd64=_0x2710db[_0x5610c8],!a['call'](_0x2b1b63,_0x53dd64)&&_0x53dd64!==_0x5ffac8&&t(_0x2b1b63,_0x53dd64,{'get':(_0x419a18=>_0x302ed0[_0x419a18])['bind'](null,_0x53dd64),'enumerable':!(_0x578e1c=n(_0x302ed0,_0x53dd64))||_0x578e1c['enumerable']});}return _0x2b1b63;},s=(_0xf8ccbd,_0x493325,_0x5bea22)=>(_0x5bea22=_0xf8ccbd==null?{}:e(i(_0xf8ccbd)),o(_0x493325||!_0xf8ccbd||!_0xf8ccbd['__esModule']?t(_0x5bea22,'default',{'value':_0xf8ccbd,'enumerable':!0x0}):_0x5bea22,_0xf8ccbd));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(_0x3f8dbb){if(!_0x3f8dbb?.['filename'])throw TypeError('SQLiteHistoryDatabaseAdapter\x20requires\x20a\x20filename');let _0x21cc36=_0x3f8dbb['busyTimeoutMs']??0x1388;if(!Number['isSafeInteger'](_0x21cc36)||_0x21cc36<0x0)throw TypeError('busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20safe\x20integer');this['_database']=new c['default'](_0x3f8dbb['filename'],{'timeout':_0x21cc36});try{this['_database']['exec']('PRAGMA\x20busy_timeout\x20=\x20'+_0x21cc36+';'),this['_initializeSchema']();}catch(_0x42392d){throw this['_database']['close'](),_0x42392d;}}async['getLatestRecord'](_0x461f40,_0x5b9800){this['_assertOpen']();let _0x3d4545=this['_latest'](_0x5b9800);return _0x3d4545?f(_0x3d4545):null;}async['appendRecord'](_0x44f263,_0x27a920,_0x26034e){if(this['_assertOpen'](),!_0x27a920['unitID']||!_0x27a920['userID']||!Number['isSafeInteger'](_0x27a920['startRevision'])||_0x27a920['startRevision']<0x1||!Number['isSafeInteger'](_0x27a920['createdAt'])||_0x27a920['createdAt']<0x0)throw TypeError('History\x20record\x20is\x20invalid');return this['_transaction'](()=>{let _0x42cf5e=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'](_0x27a920['unitID'],_0x27a920['startRevision']);if(_0x42cf5e)return{'status':_0x42cf5e['user_id']===_0x27a920['userID']&&_0x42cf5e['created_at_ms']===_0x27a920['createdAt']&&_0x42cf5e['origin']===_0x27a920['origin']&&_0x42cf5e['additional_fields']===(_0x27a920['additionalFields']??null)?'already-exists':'conflict'};let _0x23aefb=this['_latest'](_0x27a920['unitID'])?.['start_revision']??null;return _0x23aefb!==_0x26034e['expectedLatestStartRevision']||_0x27a920['startRevision']<=(_0x23aefb??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'](_0x27a920['unitID'],_0x27a920['startRevision'],_0x27a920['userID'],_0x27a920['createdAt'],_0x27a920['origin'],_0x27a920['additionalFields']??null),{'status':'appended'});});}async['listRecords'](_0x45e797,_0x4d1efd,_0x2cd3c6){this['_assertOpen']();let _0xd8a81b=[_0x2cd3c6['throughRevision'],_0x2cd3c6['throughRevision'],_0x4d1efd,_0x2cd3c6['throughRevision']],_0x7c2c34=[];_0x2cd3c6['beforeRevision']!==void 0x0&&(_0x7c2c34['push']('r.start_revision\x20<\x20?'),_0xd8a81b['push'](_0x2cd3c6['beforeRevision'])),_0x2cd3c6['origin']&&(_0x7c2c34['push']('r.origin\x20=\x20?'),_0xd8a81b['push'](_0x2cd3c6['origin'])),_0x2cd3c6['userIDs']?.['length']&&(_0x7c2c34['push']('r.user_id\x20IN\x20('+_0x2cd3c6['userIDs']['map'](()=>'?')['join'](',\x20')+')'),_0xd8a81b['push'](..._0x2cd3c6['userIDs'])),_0xd8a81b['push'](_0x2cd3c6['length']+0x1);let _0x41e685=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'+(_0x7c2c34['length']?'AND\x20'+_0x7c2c34['join']('\x20AND\x20'):'')+'\x0a\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20r.start_revision\x20DESC\x20LIMIT\x20?\x0a\x20\x20\x20\x20')['all'](..._0xd8a81b);return{'records':_0x41e685['slice'](0x0,_0x2cd3c6['length'])['map'](_0x5532f4=>({'record':f(_0x5532f4),'endRevision':_0x5532f4['end_revision']})),'hasMore':_0x41e685['length']>_0x2cd3c6['length']};}async['listCreators'](_0x1f7270,_0x6e05c,_0x385946){this['_assertOpen']();let _0x15d770=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'](_0x6e05c,_0x385946['throughRevision']),_0x181b72=new Map();for(let _0x1a4d04 of _0x15d770){let _0x456d8a=_0x181b72['get'](_0x1a4d04['user_id'])??[];_0x456d8a['push'](_0x1a4d04['origin']),_0x181b72['set'](_0x1a4d04['user_id'],_0x456d8a);}return[..._0x181b72]['map'](([_0x32def3,_0x13dc67])=>({'userID':_0x32def3,'origins':_0x13dc67}));}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_database']['close']());}['_latest'](_0x5a5635){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'](_0x5a5635);}['_initializeSchema'](){this['_transaction'](()=>{let _0x294c4c=_0x3d523c=>!!this['_database']['prepare']('SELECT\x201\x20FROM\x20sqlite_schema\x20WHERE\x20type\x20=\x20\x27table\x27\x20AND\x20name\x20=\x20?')['get'](_0x3d523c),_0x1b80be=_0x294c4c('collaboration_history_revisions')||_0x294c4c('collaboration_history_records');if(!_0x294c4c('collaboration_schema_versions')){if(_0x1b80be)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 _0x4e484d=this['_database']['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27history\x27')['get']();if(_0x4e484d){if(_0x4e484d['version']===0x1)throw Error('SQLite\x20History\x20schema\x20v1\x20requires\x20migrateSQLiteHistoryV1ToV2\x20before\x20opening\x20the\x20Adapter');if(_0x4e484d['version']!==0x2)throw Error('SQLite\x20History\x20schema\x20version\x20'+_0x4e484d['version']+'\x20is\x20not\x20supported');if(!_0x294c4c('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(_0x1b80be)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'](_0x3abbc0){this['_database']['exec']('BEGIN\x20IMMEDIATE;');try{let _0x5c5529=_0x3abbc0();return this['_database']['exec']('COMMIT;'),_0x5c5529;}catch(_0x13feec){throw this['_database']['exec']('ROLLBACK;'),_0x13feec;}}['_assertOpen'](){if(this['_disposed'])throw Error('SQLite\x20History\x20Database\x20Adapter\x20is\x20disposed');}};function f(_0xb89ae4){return{'unitID':_0xb89ae4['unit_id'],'startRevision':_0xb89ae4['start_revision'],'userID':_0xb89ae4['user_id'],'createdAt':_0xb89ae4['created_at_ms'],'origin':_0xb89ae4['origin'],..._0xb89ae4['additional_fields']===null?{}:{'additionalFields':_0xb89ae4['additional_fields']}};}async function p(_0x18b056){let _0x510b22=new c['default'](_0x18b056['filename'],{'fileMustExist':!0x0}),_0x1c3289=!0x1;try{if(_0x510b22['exec']('BEGIN\x20IMMEDIATE;'),_0x1c3289=!0x0,_0x510b22['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(_0x510b22['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 _0xc54243=_0x510b22['prepare']('SELECT\x20version\x20FROM\x20collaboration_schema_versions\x20WHERE\x20component\x20=\x20\x27worktree\x27')['get']();if(_0xc54243&&_0xc54243['version']<0x3)throw Error('Migrate\x20SQLite\x20Worktree\x20before\x20History\x20so\x20creation\x20facts\x20remain\x20available');if(_0x510b22['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');_0x510b22['exec'](l),_0x510b22['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;'),_0x510b22['exec'](u),_0x510b22['exec']('UPDATE\x20collaboration_schema_versions\x20SET\x20version\x20=\x202\x20WHERE\x20component\x20=\x20\x27history\x27;\x20COMMIT;'),_0x1c3289=!0x1;}finally{try{_0x1c3289&&_0x510b22['exec']('ROLLBACK;');}finally{_0x510b22['close']();}}}exports['SQLiteHistoryDatabaseAdapter']=d,exports['migrateSQLiteHistoryV1ToV2']=p;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const _0x1dfe31=_0x5c78;(function(_0x1c5071,_0x1343e3){const _0x23081f=_0x5c78,_0x1c62bf=_0x1c5071();while(!![]){try{const _0x17f3d3=parseInt(_0x23081f(0x1ed))/0x1*(parseInt(_0x23081f(0x1e7))/0x2)+-parseInt(_0x23081f(0x1e4))/0x3+parseInt(_0x23081f(0x1e8))/0x4*(-parseInt(_0x23081f(0x1ec))/0x5)+-parseInt(_0x23081f(0x1e6))/0x6+parseInt(_0x23081f(0x1eb))/0x7*(parseInt(_0x23081f(0x1e9))/0x8)+parseInt(_0x23081f(0x1ea))/0x9+parseInt(_0x23081f(0x1e5))/0xa*(-parseInt(_0x23081f(0x1e3))/0xb);if(_0x17f3d3===_0x1343e3)break;else _0x1c62bf['push'](_0x1c62bf['shift']());}catch(_0x590d57){_0x1c62bf['push'](_0x1c62bf['shift']());}}}(_0x5bcf,0xa8b5b));import _0x128619 from'./index.cjs';function _0x5bcf(){const _0x2f78a0=['migrateSQLiteHistoryV1ToV2','SQLiteHistoryDatabaseAdapter','3487fJZCvz','1180893NbLlom','33010uyjvwz','4391988qcwUrq','1211758brJaMG','140hUzEGL','9216408edWnib','10423269TQbXbh','7iQdzFa','7570IIbqPx','1DSCdcW'];_0x5bcf=function(){return _0x2f78a0;};return _0x5bcf();}function _0x5c78(_0x5def9e,_0x1a6ec1){_0x5def9e=_0x5def9e-0x1e1;const _0x5bcf53=_0x5bcf();let _0x5c78f8=_0x5bcf53[_0x5def9e];return _0x5c78f8;}const facadeExport0=_0x128619[_0x1dfe31(0x1e2)],facadeExport1=_0x128619[_0x1dfe31(0x1e1)];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.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-history-service": "1.0.
|
|
23
|
-
"@univerjs/protocol": "1.0.
|
|
22
|
+
"@univerjs-pro/collaboration-history-service": "1.0.4",
|
|
23
|
+
"@univerjs/protocol": "1.0.4",
|
|
24
24
|
"libsql": "^0.5.29"
|
|
25
25
|
}
|
|
26
26
|
}
|