@univerjs-pro/collaboration-database-sqlite 1.0.0-insiders.20260727-46ed76c
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.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/sqlite-database-adapter.d.ts +35 -0
- package/dist/sqlite-database-adapter.js +1 -0
- package/package.json +27 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['SQLiteDatabaseAdapter']=void 0x0;var sqlite_database_adapter_js_1=require('./sqlite-database-adapter.js');Object['defineProperty'](exports,'SQLiteDatabaseAdapter',{'enumerable':!![],'get':function(){return sqlite_database_adapter_js_1['SQLiteDatabaseAdapter'];}});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ChangesetRange, type CommitChangesetInput, type CommitChangesetResult, type CreateUnitDatabaseInput, type CreateUnitDatabaseResult, type DatabaseContext, type DeleteUnitsDatabaseInput, type DeleteUnitsDatabaseResult, type IDatabaseAdapter, type RecoverUnitsDatabaseInput, type RecoverUnitsDatabaseResult, type SaveSnapshotInput, type UnitRecord } from "@univerjs-pro/collaboration-service";
|
|
2
|
+
import type { IChangeset, IGetResourcesResponse, ISheetBlock, ISnapshot } from "@univerjs/protocol";
|
|
3
|
+
export interface SQLiteDatabaseAdapterOptions {
|
|
4
|
+
readonly filename: string;
|
|
5
|
+
readonly busyTimeoutMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class SQLiteDatabaseAdapter implements IDatabaseAdapter {
|
|
8
|
+
private readonly _database;
|
|
9
|
+
private _disposed;
|
|
10
|
+
constructor(options: SQLiteDatabaseAdapterOptions);
|
|
11
|
+
getUnit(_context: DatabaseContext, unitID: string): Promise<UnitRecord | null>;
|
|
12
|
+
getSnapshot(_context: DatabaseContext, unitID: string, options?: {
|
|
13
|
+
readonly revision?: number;
|
|
14
|
+
}): Promise<ISnapshot | null>;
|
|
15
|
+
getChangesets(_context: DatabaseContext, unitID: string, range: {
|
|
16
|
+
readonly from: number;
|
|
17
|
+
readonly to: number;
|
|
18
|
+
}): Promise<ChangesetRange>;
|
|
19
|
+
getSubmission(_context: DatabaseContext, unitID: string, sid: string, reqId: number): Promise<IChangeset | null>;
|
|
20
|
+
createUnit(_context: DatabaseContext, input: CreateUnitDatabaseInput): Promise<CreateUnitDatabaseResult>;
|
|
21
|
+
deleteUnits(_context: DatabaseContext, input: DeleteUnitsDatabaseInput): Promise<DeleteUnitsDatabaseResult>;
|
|
22
|
+
recoverUnits(_context: DatabaseContext, input: RecoverUnitsDatabaseInput): Promise<RecoverUnitsDatabaseResult>;
|
|
23
|
+
commitChangeset(_context: DatabaseContext, input: CommitChangesetInput): Promise<CommitChangesetResult>;
|
|
24
|
+
saveSnapshot(_context: DatabaseContext, input: SaveSnapshotInput): Promise<void>;
|
|
25
|
+
getSheetBlock(_context: DatabaseContext, unitID: string, blockID: string): Promise<ISheetBlock | null>;
|
|
26
|
+
getResources(_context: DatabaseContext, unitID: string, resourceIDs: readonly string[]): Promise<Readonly<IGetResourcesResponse["resources"]>>;
|
|
27
|
+
dispose(): Promise<void>;
|
|
28
|
+
private _initializeSchema;
|
|
29
|
+
private _getActiveUnitRow;
|
|
30
|
+
private _getStoredUnitRow;
|
|
31
|
+
private _hasTombstone;
|
|
32
|
+
private _writeDependencies;
|
|
33
|
+
private _transaction;
|
|
34
|
+
private _assertOpen;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';const _0x5e2357=_0x48b8;(function(_0x21b06a,_0x5e16bf){const _0x49e91b=_0x48b8,_0x2b8780=_0x21b06a();while(!![]){try{const _0x42b8db=parseInt(_0x49e91b(0x19d))/0x1+parseInt(_0x49e91b(0x142))/0x2*(parseInt(_0x49e91b(0x1a7))/0x3)+-parseInt(_0x49e91b(0x175))/0x4+-parseInt(_0x49e91b(0x14e))/0x5*(parseInt(_0x49e91b(0x177))/0x6)+parseInt(_0x49e91b(0x15c))/0x7+parseInt(_0x49e91b(0x14f))/0x8+-parseInt(_0x49e91b(0x17d))/0x9*(-parseInt(_0x49e91b(0x15f))/0xa);if(_0x42b8db===_0x5e16bf)break;else _0x2b8780['push'](_0x2b8780['shift']());}catch(_0x24ce10){_0x2b8780['push'](_0x2b8780['shift']());}}}(_0x4d4a,0xd738d));function _0x48b8(_0x4d1d09,_0x59c09d){_0x4d1d09=_0x4d1d09-0x135;const _0x4d4a52=_0x4d4a();let _0x48b820=_0x4d4a52[_0x4d1d09];return _0x48b820;}Object[_0x5e2357(0x19c)](exports,_0x5e2357(0x144),{'value':!![]}),exports[_0x5e2357(0x19e)]=void 0x0;const node_sqlite_1=require('node:sqlite'),collaboration_service_1=require('@univerjs-pro/collaboration-service'),DEFAULT_BUSY_TIMEOUT_MS=0x1388,BINARY_TAG='__univerCollaborationBinary';class SQLiteDatabaseAdapter{[_0x5e2357(0x188)];['_disposed']=![];constructor(_0x226dec){const _0x393671=_0x5e2357;validateOptions(_0x226dec),this[_0x393671(0x188)]=new node_sqlite_1[(_0x393671(0x1a9))](_0x226dec['filename']);try{this[_0x393671(0x188)][_0x393671(0x173)](_0x393671(0x198)),this['_database']['exec'](_0x393671(0x157)+(_0x226dec[_0x393671(0x16e)]??DEFAULT_BUSY_TIMEOUT_MS)+';'),_0x226dec[_0x393671(0x18e)]!==_0x393671(0x13d)&&this['_database'][_0x393671(0x173)](_0x393671(0x197)),this[_0x393671(0x149)]();}catch(_0x591326){this[_0x393671(0x188)]['close']();throw _0x591326;}}async['getUnit'](_0x563d56,_0xde9d84){const _0xcee98b=_0x5e2357;this[_0xcee98b(0x13f)]();const _0x35496d=this['_database'][_0xcee98b(0x190)](_0xcee98b(0x136))[_0xcee98b(0x196)](_0xde9d84);return _0x35496d?rowToUnitRecord(_0x35496d):null;}async[_0x5e2357(0x1a3)](_0x52804d,_0x512a9b,_0x39feff){const _0x5126f8=_0x5e2357;this[_0x5126f8(0x13f)]();const _0x59fd9e=_0x39feff?.['revision'];if(_0x59fd9e!==undefined&&_0x59fd9e<0x0)throw invalidRequest('Snapshot\x20revision\x20cannot\x20be\x20negative');const _0x2c01c6=this[_0x5126f8(0x191)](_0x512a9b);if(!_0x2c01c6)return null;const _0x42d188=_0x59fd9e===undefined||_0x59fd9e===0x0?_0x2c01c6[_0x5126f8(0x16a)]:Math['min'](_0x59fd9e,_0x2c01c6['head_revision']),_0x3dfaba=this['_database'][_0x5126f8(0x190)]('SELECT\x20snapshots.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20snapshots\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\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\x20snapshots.revision\x20<=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20units.lifecycle\x20=\x20\x27active\x27\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')[_0x5126f8(0x196)](_0x512a9b,_0x42d188);return _0x3dfaba?decode(_0x3dfaba[_0x5126f8(0x167)]):null;}async['getChangesets'](_0x3147a5,_0x141ea4,_0x28e063){const _0x2b535b=_0x5e2357;this[_0x2b535b(0x13f)]();if(_0x28e063[_0x2b535b(0x19a)]<0x0||_0x28e063['to']<0x0)throw invalidRequest(_0x2b535b(0x168));const _0x59708b=this[_0x2b535b(0x188)]['prepare'](_0x2b535b(0x1a4))[_0x2b535b(0x1a0)](_0x28e063[_0x2b535b(0x19a)],_0x28e063['to'],_0x28e063['to'],_0x141ea4),_0x4c861e=_0x59708b[0x0];if(!_0x4c861e)return{'changesets':[],'latestRevision':0x0};return{'changesets':_0x59708b[_0x2b535b(0x172)](_0x1051e5=>_0x1051e5[_0x2b535b(0x167)]?[decode(_0x1051e5[_0x2b535b(0x167)])]:[]),'latestRevision':_0x4c861e[_0x2b535b(0x16a)]};}async[_0x5e2357(0x184)](_0x108d73,_0x6adf95,_0x481e57,_0x22ed83){const _0x2db987=_0x5e2357;this['_assertOpen']();const _0x2bed05=this[_0x2db987(0x188)][_0x2db987(0x190)]('SELECT\x20changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20units\x20ON\x20units.unit_id\x20=\x20changesets.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20changesets.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.sid\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.req_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20units.lifecycle\x20=\x20\x27active\x27')['get'](_0x6adf95,_0x481e57,_0x22ed83);return _0x2bed05?decode(_0x2bed05[_0x2db987(0x167)]):null;}async[_0x5e2357(0x160)](_0x11a547,_0xe84bab){const _0xd5cad0=_0x5e2357;this[_0xd5cad0(0x13f)](),validateInitialUnit(_0xe84bab);const _0x451389=encode(_0xe84bab['snapshot']),_0x4b2b5c=(_0xe84bab[_0xd5cad0(0x15d)]??[])[_0xd5cad0(0x13e)](_0x3e5440=>({'id':_0x3e5440['id'],'payload':encode(_0x3e5440)})),_0x116610=Object[_0xd5cad0(0x1ab)](_0xe84bab[_0xd5cad0(0x146)]??{})[_0xd5cad0(0x13e)](([_0x90c530,_0x1f7208])=>({'resourceID':_0x90c530,'payload':encode(_0x1f7208)}));return this[_0xd5cad0(0x164)](()=>{const _0x854031=_0xd5cad0;if(this[_0x854031(0x16f)](_0xe84bab[_0x854031(0x166)][_0x854031(0x186)]))throw invalidRequest(_0x854031(0x159));const _0x312ada=this['_getStoredUnitRow'](_0xe84bab['record'][_0x854031(0x186)]);if(_0x312ada){if(_0x312ada[_0x854031(0x1a5)]===_0x854031(0x150))throw invalidRequest(_0x854031(0x181));return{'status':_0x854031(0x147),'record':rowToUnitRecord(_0x312ada)};}return this['_database'][_0x854031(0x190)](_0x854031(0x179))[_0x854031(0x158)](_0xe84bab['record'][_0x854031(0x186)],_0xe84bab[_0x854031(0x166)][_0x854031(0x180)]),this[_0x854031(0x185)](_0xe84bab[_0x854031(0x166)][_0x854031(0x186)],_0x4b2b5c,_0x116610),this[_0x854031(0x188)][_0x854031(0x190)]('INSERT\x20INTO\x20snapshots\x20(unit_id,\x20revision,\x20type,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x201,\x20?,\x20?)')['run'](_0xe84bab[_0x854031(0x166)]['unitID'],_0xe84bab[_0x854031(0x166)]['type'],_0x451389),{'status':_0x854031(0x19b),'record':{..._0xe84bab[_0x854031(0x166)]}};});}async[_0x5e2357(0x17b)](_0x151774,_0x53e4e6){const _0x1d6d15=_0x5e2357;return this['_assertOpen'](),this[_0x1d6d15(0x164)](()=>{const _0x3921cc=_0x1d6d15,_0x17b3ce=uniqueUnitIDs(_0x53e4e6[_0x3921cc(0x137)])[_0x3921cc(0x13e)](_0x2c4151=>{const _0x5dd992=_0x3921cc,_0x284794=this['_getStoredUnitRow'](_0x2c4151);if(!_0x284794){if(_0x53e4e6['hardDelete']&&this[_0x5dd992(0x16f)](_0x2c4151))return{'unitID':_0x2c4151,'status':'already-hard-deleted'};throw new collaboration_service_1['CollabError'](_0x5dd992(0x14d),'Cannot\x20delete\x20a\x20missing\x20unit');}if(_0x53e4e6[_0x5dd992(0x176)])return{'unitID':_0x2c4151,'status':_0x5dd992(0x1a1)};return{'unitID':_0x2c4151,'status':_0x284794[_0x5dd992(0x1a5)]===_0x5dd992(0x189)?'soft-deleted':_0x5dd992(0x140)};}),_0x330e14=this[_0x3921cc(0x188)][_0x3921cc(0x190)](_0x3921cc(0x154)),_0x254aa7=this[_0x3921cc(0x188)][_0x3921cc(0x190)]('INSERT\x20INTO\x20unit_tombstones\x20(unit_id,\x20purged_at)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?)'),_0x2a7d4a=this[_0x3921cc(0x188)][_0x3921cc(0x190)]('DELETE\x20FROM\x20units\x20WHERE\x20unit_id\x20=\x20?'),_0x3a8b65=Date[_0x3921cc(0x15e)]();for(const _0x27edfc of _0x17b3ce){if(_0x27edfc['status']==='soft-deleted')_0x330e14[_0x3921cc(0x158)](_0x27edfc['unitID']);else _0x27edfc['status']==='hard-deleted'&&(_0x254aa7[_0x3921cc(0x158)](_0x27edfc['unitID'],_0x3a8b65),_0x2a7d4a[_0x3921cc(0x158)](_0x27edfc[_0x3921cc(0x186)]));}return{'units':_0x17b3ce};});}async[_0x5e2357(0x171)](_0x5506e4,_0x542444){const _0x173b9c=_0x5e2357;return this[_0x173b9c(0x13f)](),this[_0x173b9c(0x164)](()=>{const _0x2a0424=_0x173b9c,_0x1dbbce=uniqueUnitIDs(_0x542444['unitIDs'])[_0x2a0424(0x13e)](_0x1f4392=>{const _0x57bb58=_0x2a0424,_0x12c03d=this['_getStoredUnitRow'](_0x1f4392);if(!_0x12c03d){if(this['_hasTombstone'](_0x1f4392))throw invalidRequest(_0x57bb58(0x141));throw new collaboration_service_1['CollabError'](_0x57bb58(0x14d),_0x57bb58(0x15b));}return{'unitID':_0x1f4392,'status':_0x12c03d[_0x57bb58(0x1a5)]===_0x57bb58(0x189)?_0x57bb58(0x16b):_0x57bb58(0x19f)};}),_0x4997d5=this[_0x2a0424(0x188)][_0x2a0424(0x190)](_0x2a0424(0x135));for(const _0x482fa7 of _0x1dbbce){_0x482fa7[_0x2a0424(0x192)]===_0x2a0424(0x19f)&&_0x4997d5[_0x2a0424(0x158)](_0x482fa7['unitID']);}return{'units':_0x1dbbce};});}async['commitChangeset'](_0x35ea5e,_0x5eacc3){const _0x1aacbd=_0x5e2357;this[_0x1aacbd(0x13f)](),validateSubmissionIdentity(_0x5eacc3[_0x1aacbd(0x145)]);const _0x77c54d=encode(_0x5eacc3[_0x1aacbd(0x145)]);return this[_0x1aacbd(0x164)](()=>{const _0x18ad43=_0x1aacbd,{changeset:_0x468def,expectedHeadRevision:_0x1bfe8d}=_0x5eacc3,_0x42c47a=this[_0x18ad43(0x191)](_0x468def[_0x18ad43(0x186)]);if(!_0x42c47a)throw new collaboration_service_1['CollabError'](_0x18ad43(0x14d),_0x18ad43(0x18a));const _0x368da2=this[_0x18ad43(0x188)][_0x18ad43(0x190)](_0x18ad43(0x1aa))[_0x18ad43(0x196)](_0x468def[_0x18ad43(0x186)],_0x468def[_0x18ad43(0x148)],_0x468def[_0x18ad43(0x165)]);if(_0x368da2)return{'status':'already-committed','changeset':decode(_0x368da2[_0x18ad43(0x167)])};if(_0x42c47a[_0x18ad43(0x16a)]!==_0x1bfe8d)return{'status':_0x18ad43(0x16d),'actualHeadRevision':_0x42c47a[_0x18ad43(0x16a)]};validateCandidate(rowToUnitRecord(_0x42c47a),_0x5eacc3),this['_database'][_0x18ad43(0x190)](_0x18ad43(0x178))['run'](_0x468def[_0x18ad43(0x186)],_0x468def['revision'],_0x468def[_0x18ad43(0x143)],_0x468def[_0x18ad43(0x148)],_0x468def[_0x18ad43(0x165)],_0x77c54d);const _0x41cdd8=this[_0x18ad43(0x188)]['prepare'](_0x18ad43(0x153))[_0x18ad43(0x158)](_0x468def[_0x18ad43(0x17f)],_0x468def[_0x18ad43(0x186)],_0x1bfe8d);if(_0x41cdd8[_0x18ad43(0x18f)]!==0x1)throw new collaboration_service_1[(_0x18ad43(0x139))]('INTERNAL_ERROR',_0x18ad43(0x14c));return{'status':_0x18ad43(0x17a),'changeset':decode(_0x77c54d),'headRevision':_0x468def[_0x18ad43(0x17f)]};});}async[_0x5e2357(0x155)](_0xd5dc98,_0x9bb023){const _0x316d87=_0x5e2357;this[_0x316d87(0x13f)]();const _0x35fd40=encode(_0x9bb023[_0x316d87(0x15a)]),_0x2abc7d=(_0x9bb023[_0x316d87(0x15d)]??[])[_0x316d87(0x13e)](_0x5e3afe=>({'id':_0x5e3afe['id'],'payload':encode(_0x5e3afe)})),_0x28f1d7=Object[_0x316d87(0x1ab)](_0x9bb023[_0x316d87(0x146)]??{})[_0x316d87(0x13e)](([_0x1aabb1,_0x29acd1])=>({'resourceID':_0x1aabb1,'payload':encode(_0x29acd1)}));this[_0x316d87(0x164)](()=>{const _0x446932=_0x316d87,_0x5440cb=this['_getActiveUnitRow'](_0x9bb023[_0x446932(0x15a)][_0x446932(0x186)]);if(!_0x5440cb)throw new collaboration_service_1[(_0x446932(0x139))](_0x446932(0x14d),_0x446932(0x193));if(_0x9bb023['snapshot']['type']!==_0x5440cb[_0x446932(0x180)]||_0x9bb023[_0x446932(0x15a)][_0x446932(0x13c)]<0x1||_0x9bb023[_0x446932(0x15a)]['rev']>_0x5440cb[_0x446932(0x16a)])throw invalidRequest(_0x446932(0x194));this['_writeDependencies'](_0x9bb023['snapshot'][_0x446932(0x186)],_0x2abc7d,_0x28f1d7),this['_database']['prepare'](_0x446932(0x16c))[_0x446932(0x158)](_0x9bb023[_0x446932(0x15a)]['unitID'],_0x9bb023['snapshot']['rev'],_0x9bb023[_0x446932(0x15a)][_0x446932(0x180)],_0x35fd40);});}async['getSheetBlock'](_0x360d6c,_0x3fd096,_0x32ec01){const _0x5c62f0=_0x5e2357;this['_assertOpen']();const _0xd9cd00=this['_database']['prepare'](_0x5c62f0(0x13b))[_0x5c62f0(0x196)](_0x3fd096,_0x32ec01);return _0xd9cd00?decode(_0xd9cd00[_0x5c62f0(0x167)]):null;}async[_0x5e2357(0x14a)](_0x5a304f,_0x3e396b,_0x16ad91){const _0x2e11ec=_0x5e2357;this['_assertOpen']();const _0x4d5cf9=this['_database'][_0x2e11ec(0x190)]('SELECT\x20resources.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20resources\x0a\x20\x20\x20\x20\x20\x20\x20JOIN\x20units\x20ON\x20units.unit_id\x20=\x20resources.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20resources.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20resources.resource_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20units.lifecycle\x20=\x20\x27active\x27'),_0x2f933f={};for(const _0x1d1888 of _0x16ad91){const _0xf7c363=_0x4d5cf9[_0x2e11ec(0x196)](_0x3e396b,_0x1d1888);_0xf7c363&&(_0x2f933f[_0x1d1888]=decode(_0xf7c363[_0x2e11ec(0x167)]));}return _0x2f933f;}async['dispose'](){const _0x1ce080=_0x5e2357;if(this[_0x1ce080(0x156)])return;this[_0x1ce080(0x156)]=!![],this[_0x1ce080(0x188)]['close']();}[_0x5e2357(0x149)](){const _0x1ed4ba=_0x5e2357;this[_0x1ed4ba(0x164)](()=>{const _0x102c13=_0x1ed4ba;this[_0x102c13(0x188)]['exec']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20units\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\x20lifecycle\x20TEXT\x20NOT\x20NULL\x20CHECK\x20(lifecycle\x20IN\x20(\x27active\x27,\x20\x27soft-deleted\x27))\x0a\x20\x20\x20\x20\x20\x20\x20\x20);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20unit_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\x20IF\x20NOT\x20EXISTS\x20snapshots\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)\x20REFERENCES\x20units(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\x20IF\x20NOT\x20EXISTS\x20changesets\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\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)\x20REFERENCES\x20units(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\x20IF\x20NOT\x20EXISTS\x20sheet_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)\x20REFERENCES\x20units(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\x20IF\x20NOT\x20EXISTS\x20resources\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\x20resource_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,\x20resource_id),\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FOREIGN\x20KEY\x20(unit_id)\x20REFERENCES\x20units(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\x20IF\x20NOT\x20EXISTS\x20snapshots_nearest_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20snapshots(unit_id,\x20revision\x20DESC);\x0a\x20\x20\x20\x20\x20\x20\x20\x20CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20changesets_revision_range\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20changesets(unit_id,\x20revision\x20ASC);\x0a\x0a\x20\x20\x20\x20\x20\x20\x20\x20PRAGMA\x20user_version\x20=\x201;\x0a\x20\x20\x20\x20\x20\x20');});}['_getActiveUnitRow'](_0x31b759){const _0x3749f5=_0x5e2357,_0x21825b=this[_0x3749f5(0x188)]['prepare'](_0x3749f5(0x136))[_0x3749f5(0x196)](_0x31b759);return _0x21825b??null;}[_0x5e2357(0x163)](_0x322c9f){const _0x164600=_0x5e2357,_0x4eab35=this[_0x164600(0x188)][_0x164600(0x190)](_0x164600(0x174))[_0x164600(0x196)](_0x322c9f);return _0x4eab35??null;}['_hasTombstone'](_0x422469){const _0x100f11=_0x5e2357;return Boolean(this[_0x100f11(0x188)][_0x100f11(0x190)](_0x100f11(0x199))[_0x100f11(0x196)](_0x422469));}[_0x5e2357(0x185)](_0x59d4de,_0x1b9e50,_0x12fa47){const _0x4a70c3=_0x5e2357,_0x3f430c=this[_0x4a70c3(0x188)][_0x4a70c3(0x190)](_0x4a70c3(0x182));for(const _0x4c364b of _0x1b9e50){_0x3f430c['run'](_0x59d4de,_0x4c364b['id'],_0x4c364b['payload']);}const _0x5d44e1=this['_database'][_0x4a70c3(0x190)]('INSERT\x20INTO\x20resources\x20(unit_id,\x20resource_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,\x20resource_id)\x20DO\x20UPDATE\x20SET\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20payload_json\x20=\x20excluded.payload_json');for(const _0x384da5 of _0x12fa47){_0x5d44e1[_0x4a70c3(0x158)](_0x59d4de,_0x384da5[_0x4a70c3(0x151)],_0x384da5[_0x4a70c3(0x13a)]);}}[_0x5e2357(0x164)](_0x1bfa2f){const _0x19c724=_0x5e2357;this[_0x19c724(0x188)][_0x19c724(0x173)](_0x19c724(0x14b));try{const _0x163c09=_0x1bfa2f();return this[_0x19c724(0x188)][_0x19c724(0x173)](_0x19c724(0x1a2)),_0x163c09;}catch(_0x4e5156){this['_database'][_0x19c724(0x162)]&&this[_0x19c724(0x188)][_0x19c724(0x173)](_0x19c724(0x18d));throw _0x4e5156;}}[_0x5e2357(0x13f)](){const _0x1ef4fb=_0x5e2357;if(this[_0x1ef4fb(0x156)])throw new collaboration_service_1[(_0x1ef4fb(0x139))](_0x1ef4fb(0x195),_0x1ef4fb(0x169));}}exports['SQLiteDatabaseAdapter']=SQLiteDatabaseAdapter;function validateOptions(_0x552095){const _0xd60b21=_0x5e2357;if(!_0x552095[_0xd60b21(0x18e)])throw invalidRequest(_0xd60b21(0x17e));if(_0x552095['busyTimeoutMs']!==undefined&&(!Number[_0xd60b21(0x170)](_0x552095['busyTimeoutMs'])||_0x552095['busyTimeoutMs']<0x0))throw invalidRequest(_0xd60b21(0x1ac));}function validateInitialUnit(_0xa0cd9f){const _0x4ce269=_0x5e2357,{record:_0xf7bb27,snapshot:_0x2f7fdd}=_0xa0cd9f;if(_0xf7bb27[_0x4ce269(0x152)]!==0x1||_0x2f7fdd[_0x4ce269(0x13c)]!==0x1||_0x2f7fdd[_0x4ce269(0x186)]!==_0xf7bb27[_0x4ce269(0x186)]||_0x2f7fdd['type']!==_0xf7bb27['type'])throw invalidRequest('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');}function validateSubmissionIdentity(_0x59da55){const _0x1d8e48=_0x5e2357;if(!_0x59da55[_0x1d8e48(0x148)]||!Number[_0x1d8e48(0x170)](_0x59da55[_0x1d8e48(0x165)])||_0x59da55[_0x1d8e48(0x165)]<0x1)throw invalidRequest(_0x1d8e48(0x187));}function _0x4d4a(){const _0x3e50e2=['Cannot\x20recover\x20a\x20hard-deleted\x20unit','10xEnAHC','baseRev','__esModule','changeset','resources','already-exists','sid','_initializeSchema','getResources','BEGIN\x20IMMEDIATE;','SQLite\x20head\x20changed\x20inside\x20an\x20exclusive\x20write\x20transaction','UNIT_NOT_FOUND','2820110FLlLIb','7013816SurVAc','soft-deleted','resourceID','headRevision','UPDATE\x20units\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\x20lifecycle\x20=\x20\x27active\x27','UPDATE\x20units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20lifecycle\x20=\x20\x27soft-deleted\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20lifecycle\x20=\x20\x27active\x27','saveSnapshot','_disposed','PRAGMA\x20busy_timeout\x20=\x20','run','Cannot\x20reuse\x20a\x20hard-deleted\x20unit\x20ID','snapshot','Cannot\x20recover\x20a\x20missing\x20unit','6575205gLXcuT','sheetBlocks','now','510rzZsZe','createUnit','length','isTransaction','_getStoredUnitRow','_transaction','reqId','record','payload_json','Changeset\x20range\x20revisions\x20cannot\x20be\x20negative','SQLite\x20Database\x20Adapter\x20is\x20disposed','head_revision','already-active','INSERT\x20INTO\x20snapshots\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','revision-mismatch','busyTimeoutMs','_hasTombstone','isSafeInteger','recoverUnits','flatMap','exec','SELECT\x20unit_id,\x20type,\x20head_revision,\x20lifecycle\x20FROM\x20units\x20WHERE\x20unit_id\x20=\x20?','5997224sewaet','hardDelete','12qecOUo','INSERT\x20INTO\x20changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(unit_id,\x20revision,\x20base_revision,\x20sid,\x20req_id,\x20payload_json)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x20?,\x20?,\x20?,\x20?)','INSERT\x20INTO\x20units\x20(unit_id,\x20type,\x20head_revision,\x20lifecycle)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20(?,\x20?,\x201,\x20\x27active\x27)','committed','deleteUnits','object','54TwZqaz','SQLite\x20filename\x20is\x20required','revision','type','Cannot\x20reuse\x20a\x20soft-deleted\x20unit\x20ID','INSERT\x20INTO\x20sheet_blocks\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','unit_id','getSubmission','_writeDependencies','unitID','Changeset\x20sid\x20and\x20positive\x20integer\x20reqId\x20are\x20required','_database','active','Cannot\x20commit\x20to\x20a\x20missing\x20unit','Confirmed\x20changeset\x20must\x20match\x20the\x20unit\x20type\x20and\x20expected\x20revision','string','ROLLBACK;','filename','changes','prepare','_getActiveUnitRow','status','Cannot\x20snapshot\x20a\x20missing\x20unit','Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head','INTERNAL_ERROR','get','PRAGMA\x20journal_mode\x20=\x20WAL;','PRAGMA\x20foreign_keys\x20=\x20ON;','SELECT\x201\x20FROM\x20unit_tombstones\x20WHERE\x20unit_id\x20=\x20?','from','created','defineProperty','1676716oXHaNu','SQLiteDatabaseAdapter','recovered','all','hard-deleted','COMMIT;','getSnapshot','SELECT\x20units.head_revision,\x20changesets.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20changesets.unit_id\x20=\x20units.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.revision\x20>\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20changesets.revision\x20<=\x20CASE\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHEN\x20?\x20=\x200\x20THEN\x20units.head_revision\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ELSE\x20MIN(?,\x20units.head_revision)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20END\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20units.unit_id\x20=\x20?\x20AND\x20units.lifecycle\x20=\x20\x27active\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20changesets.revision\x20ASC','lifecycle','stringify','9501pTGikl','parse','DatabaseSync','SELECT\x20payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20changesets\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20sid\x20=\x20?\x20AND\x20req_id\x20=\x20?','entries','SQLite\x20busyTimeoutMs\x20must\x20be\x20a\x20non-negative\x20integer','UPDATE\x20units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20lifecycle\x20=\x20\x27active\x27\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20lifecycle\x20=\x20\x27soft-deleted\x27','SELECT\x20unit_id,\x20type,\x20head_revision,\x20lifecycle\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20units\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20unit_id\x20=\x20?\x20AND\x20lifecycle\x20=\x20\x27active\x27','unitIDs','INVALID_REQUEST','CollabError','payload','SELECT\x20sheet_blocks.payload_json\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20sheet_blocks\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20JOIN\x20units\x20ON\x20units.unit_id\x20=\x20sheet_blocks.unit_id\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20sheet_blocks.unit_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20sheet_blocks.block_id\x20=\x20?\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20AND\x20units.lifecycle\x20=\x20\x27active\x27','rev',':memory:','map','_assertOpen','already-soft-deleted'];_0x4d4a=function(){return _0x3e50e2;};return _0x4d4a();}function validateCandidate(_0x4afc5e,_0x4d5a19){const _0x176cb8=_0x5e2357,{changeset:_0x38b4e6,expectedHeadRevision:_0x55777f}=_0x4d5a19;if(_0x38b4e6['type']!==_0x4afc5e['type']||_0x38b4e6[_0x176cb8(0x143)]!==_0x55777f||_0x38b4e6[_0x176cb8(0x17f)]!==_0x55777f+0x1)throw invalidRequest(_0x176cb8(0x18b));}function rowToUnitRecord(_0xd20414){const _0x24f3e0=_0x5e2357;return{'unitID':_0xd20414[_0x24f3e0(0x183)],'type':_0xd20414[_0x24f3e0(0x180)],'headRevision':_0xd20414[_0x24f3e0(0x16a)]};}function invalidRequest(_0xed16d2){const _0x55fe09=_0x5e2357;return new collaboration_service_1[(_0x55fe09(0x139))](_0x55fe09(0x138),_0xed16d2);}function uniqueUnitIDs(_0x562206){return[...new Set(_0x562206)];}function encode(_0x337d5c){const _0x4a958f=_0x5e2357;return JSON[_0x4a958f(0x1a6)](_0x337d5c,(_0x5e565a,_0x57e231)=>{if(_0x57e231 instanceof Uint8Array)return{[BINARY_TAG]:Buffer['from'](_0x57e231)['toString']('base64')};return _0x57e231;});}function decode(_0x12cac6){const _0x1c1d69=_0x5e2357;return JSON[_0x1c1d69(0x1a8)](_0x12cac6,(_0x3948df,_0x49474d)=>{if(isBinaryEncoding(_0x49474d))return Uint8Array['from'](Buffer['from'](_0x49474d[BINARY_TAG],'base64'));return _0x49474d;});}function isBinaryEncoding(_0x3e4d56){const _0x325569=_0x5e2357;return typeof _0x3e4d56===_0x325569(0x17c)&&_0x3e4d56!==null&&Object['keys'](_0x3e4d56)[_0x325569(0x161)]===0x1&&typeof _0x3e4d56[BINARY_TAG]===_0x325569(0x18c);}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@univerjs-pro/collaboration-database-sqlite",
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=24"
|
|
18
|
+
},
|
|
19
|
+
"version": "1.0.0-insiders.20260727-46ed76c",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@univerjs-pro/collaboration-service": "1.0.0-insiders.20260727-46ed76c",
|
|
22
|
+
"@univerjs/protocol": "1.0.0-insiders.20260727-46ed76c"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
}
|
|
27
|
+
}
|