@univerjs-pro/collaboration-database-memory 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.
@@ -0,0 +1 @@
1
+ export { MemoryDatabaseAdapter } from "./memory-database-adapter.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports['MemoryDatabaseAdapter']=void 0x0;var memory_database_adapter_js_1=require('./memory-database-adapter.js');Object['defineProperty'](exports,'MemoryDatabaseAdapter',{'enumerable':!![],'get':function(){return memory_database_adapter_js_1['MemoryDatabaseAdapter'];}});
@@ -0,0 +1,26 @@
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 declare class MemoryDatabaseAdapter implements IDatabaseAdapter {
4
+ private readonly _units;
5
+ private readonly _tombstones;
6
+ private _disposed;
7
+ getUnit(_context: DatabaseContext, unitID: string): Promise<UnitRecord | null>;
8
+ getSnapshot(_context: DatabaseContext, unitID: string, options?: {
9
+ readonly revision?: number;
10
+ }): Promise<ISnapshot | null>;
11
+ getChangesets(_context: DatabaseContext, unitID: string, range: {
12
+ readonly from: number;
13
+ readonly to: number;
14
+ }): Promise<ChangesetRange>;
15
+ getSubmission(_context: DatabaseContext, unitID: string, sid: string, reqId: number): Promise<IChangeset | null>;
16
+ createUnit(_context: DatabaseContext, input: CreateUnitDatabaseInput): Promise<CreateUnitDatabaseResult>;
17
+ deleteUnits(_context: DatabaseContext, input: DeleteUnitsDatabaseInput): Promise<DeleteUnitsDatabaseResult>;
18
+ recoverUnits(_context: DatabaseContext, input: RecoverUnitsDatabaseInput): Promise<RecoverUnitsDatabaseResult>;
19
+ commitChangeset(_context: DatabaseContext, input: CommitChangesetInput): Promise<CommitChangesetResult>;
20
+ saveSnapshot(_context: DatabaseContext, input: SaveSnapshotInput): Promise<void>;
21
+ getSheetBlock(_context: DatabaseContext, unitID: string, blockID: string): Promise<ISheetBlock | null>;
22
+ getResources(_context: DatabaseContext, unitID: string, resourceIDs: readonly string[]): Promise<Readonly<IGetResourcesResponse["resources"]>>;
23
+ dispose(): Promise<void>;
24
+ private _activeUnit;
25
+ private _assertOpen;
26
+ }
@@ -0,0 +1 @@
1
+ 'use strict';const _0x24eecb=_0x1d7d;(function(_0x3d8792,_0x34b827){const _0x55a821=_0x1d7d,_0x3c9619=_0x3d8792();while(!![]){try{const _0x57fed5=-parseInt(_0x55a821(0x151))/0x1*(parseInt(_0x55a821(0x130))/0x2)+parseInt(_0x55a821(0x139))/0x3+parseInt(_0x55a821(0x14c))/0x4*(parseInt(_0x55a821(0x12c))/0x5)+parseInt(_0x55a821(0x11c))/0x6*(-parseInt(_0x55a821(0x12e))/0x7)+parseInt(_0x55a821(0x135))/0x8*(-parseInt(_0x55a821(0x10d))/0x9)+-parseInt(_0x55a821(0x157))/0xa+parseInt(_0x55a821(0x14f))/0xb;if(_0x57fed5===_0x34b827)break;else _0x3c9619['push'](_0x3c9619['shift']());}catch(_0x2aeade){_0x3c9619['push'](_0x3c9619['shift']());}}}(_0x4315,0x367aa));Object['defineProperty'](exports,_0x24eecb(0x155),{'value':!![]}),exports['MemoryDatabaseAdapter']=void 0x0;const collaboration_service_1=require('@univerjs-pro/collaboration-service');class MemoryDatabaseAdapter{[_0x24eecb(0x154)]=new Map();['_tombstones']=new Set();['_disposed']=![];async['getUnit'](_0x157344,_0x453d21){const _0x2da086=_0x24eecb;this[_0x2da086(0x15b)]();const _0x473bd8=this[_0x2da086(0x122)](_0x453d21);return _0x473bd8?clone(_0x473bd8[_0x2da086(0x115)]):null;}async[_0x24eecb(0x111)](_0x2bfd7a,_0x62867b,_0x16aa63){const _0x575505=_0x24eecb;this[_0x575505(0x15b)]();const _0x3399c3=this[_0x575505(0x122)](_0x62867b);if(!_0x3399c3)return null;const _0x22f5d3=_0x16aa63?.['revision'],_0x22c721=_0x22f5d3===undefined||_0x22f5d3===0x0?_0x3399c3['record'][_0x575505(0x150)]:Math[_0x575505(0x156)](_0x22f5d3,_0x3399c3[_0x575505(0x115)]['headRevision']);let _0x55764a=-0x1;for(const _0x1ea987 of _0x3399c3[_0x575505(0x13a)][_0x575505(0x129)]()){_0x1ea987<=_0x22c721&&_0x1ea987>_0x55764a&&(_0x55764a=_0x1ea987);}const _0x1ac6f0=_0x3399c3[_0x575505(0x13a)][_0x575505(0x138)](_0x55764a);return _0x1ac6f0?clone(_0x1ac6f0):null;}async[_0x24eecb(0x145)](_0x481e28,_0x5423ab,_0x11feee){const _0x50b7b4=_0x24eecb;this['_assertOpen']();if(_0x11feee[_0x50b7b4(0x12a)]<0x0||_0x11feee['to']<0x0)throw invalidRequest(_0x50b7b4(0x11e));const _0xf80ceb=this[_0x50b7b4(0x122)](_0x5423ab);if(!_0xf80ceb)return{'changesets':[],'latestRevision':0x0};const _0x3a8734=_0x11feee['to']===0x0?_0xf80ceb[_0x50b7b4(0x115)]['headRevision']:Math[_0x50b7b4(0x156)](_0x11feee['to'],_0xf80ceb[_0x50b7b4(0x115)][_0x50b7b4(0x150)]),_0x4a51d3=[..._0xf80ceb[_0x50b7b4(0x126)][_0x50b7b4(0x118)]()][_0x50b7b4(0x159)](([_0x2950c0])=>_0x2950c0>_0x11feee[_0x50b7b4(0x12a)]&&_0x2950c0<=_0x3a8734)[_0x50b7b4(0x11d)](([_0x63144],[_0x5235b0])=>_0x63144-_0x5235b0)[_0x50b7b4(0x121)](([,_0x49780b])=>clone(_0x49780b));return{'changesets':_0x4a51d3,'latestRevision':_0xf80ceb[_0x50b7b4(0x115)][_0x50b7b4(0x150)]};}async[_0x24eecb(0x12f)](_0x40aaf4,_0x345dda,_0x2ab143,_0x13f4ad){const _0x41f7e9=_0x24eecb;this[_0x41f7e9(0x15b)]();const _0x319ad2=this[_0x41f7e9(0x122)](_0x345dda)?.[_0x41f7e9(0x140)][_0x41f7e9(0x138)](submissionKey(_0x2ab143,_0x13f4ad));return _0x319ad2?clone(_0x319ad2):null;}async[_0x24eecb(0x133)](_0x3e3b1f,_0x5103da){const _0x2cf107=_0x24eecb;this['_assertOpen'](),validateInitialUnit(_0x5103da);const _0x522087=this[_0x2cf107(0x154)][_0x2cf107(0x138)](_0x5103da[_0x2cf107(0x115)][_0x2cf107(0x117)]);if(_0x522087){if(_0x522087[_0x2cf107(0x147)]===_0x2cf107(0x114))throw invalidRequest('A\x20soft-deleted\x20unit\x20ID\x20cannot\x20be\x20reused');return{'status':'already-exists','record':clone(_0x522087[_0x2cf107(0x115)])};}if(this[_0x2cf107(0x148)][_0x2cf107(0x13c)](_0x5103da[_0x2cf107(0x115)][_0x2cf107(0x117)]))throw invalidRequest(_0x2cf107(0x11a));const _0x52ea5d=cloneDependencies(_0x5103da['sheetBlocks'],_0x5103da['resources']),_0x14496b={'record':clone(_0x5103da[_0x2cf107(0x115)]),'lifecycle':_0x2cf107(0x137),'snapshots':new Map([[0x1,clone(_0x5103da[_0x2cf107(0x142)])]]),'changesets':new Map(),'submissions':new Map(),'sheetBlocks':_0x52ea5d[_0x2cf107(0x14a)],'resources':_0x52ea5d[_0x2cf107(0x112)]};return this['_units']['set'](_0x5103da[_0x2cf107(0x115)][_0x2cf107(0x117)],_0x14496b),{'status':_0x2cf107(0x14d),'record':clone(_0x14496b['record'])};}async[_0x24eecb(0x144)](_0x57d7be,_0x2cd6e8){const _0x8a9ef5=_0x24eecb;this[_0x8a9ef5(0x15b)]();const _0x6aa738=uniqueUnitIDs(_0x2cd6e8['unitIDs'])['map'](_0xb6d87c=>{const _0x17d30e=_0x8a9ef5,_0x247c8f=this[_0x17d30e(0x154)][_0x17d30e(0x138)](_0xb6d87c);if(_0x2cd6e8[_0x17d30e(0x146)]){if(_0x247c8f)return{'unitID':_0xb6d87c,'stored':_0x247c8f,'status':_0x17d30e(0x123)};if(this['_tombstones']['has'](_0xb6d87c))return{'unitID':_0xb6d87c,'status':_0x17d30e(0x109)};throw unitNotFound(_0x17d30e(0x134));}if(!_0x247c8f||this['_tombstones'][_0x17d30e(0x13c)](_0xb6d87c))throw unitNotFound('Cannot\x20soft-delete\x20a\x20missing\x20unit');return{'unitID':_0xb6d87c,'stored':_0x247c8f,'status':_0x247c8f[_0x17d30e(0x147)]===_0x17d30e(0x137)?'soft-deleted':_0x17d30e(0x119)};});for(const _0x53a6ce of _0x6aa738){if(_0x2cd6e8[_0x8a9ef5(0x146)]&&_0x53a6ce[_0x8a9ef5(0x153)]===_0x8a9ef5(0x123))this[_0x8a9ef5(0x154)][_0x8a9ef5(0x13d)](_0x53a6ce['unitID']),this[_0x8a9ef5(0x148)]['add'](_0x53a6ce[_0x8a9ef5(0x117)]);else!_0x2cd6e8[_0x8a9ef5(0x146)]&&_0x53a6ce[_0x8a9ef5(0x13b)]&&(_0x53a6ce[_0x8a9ef5(0x13b)][_0x8a9ef5(0x147)]=_0x8a9ef5(0x114));}return{'units':_0x6aa738[_0x8a9ef5(0x121)](({unitID:_0x2feb8e,status:_0xa75ec5})=>({'unitID':_0x2feb8e,'status':_0xa75ec5}))};}async[_0x24eecb(0x15c)](_0x561134,_0x13dbb6){const _0xb4bdcc=_0x24eecb;this['_assertOpen']();const _0x185624=uniqueUnitIDs(_0x13dbb6['unitIDs'])[_0xb4bdcc(0x121)](_0x47e2c6=>{const _0x26e9dc=_0xb4bdcc;if(this[_0x26e9dc(0x148)][_0x26e9dc(0x13c)](_0x47e2c6))throw invalidRequest(_0x26e9dc(0x158));const _0x5eac50=this[_0x26e9dc(0x154)][_0x26e9dc(0x138)](_0x47e2c6);if(!_0x5eac50)throw unitNotFound('Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0x47e2c6,'stored':_0x5eac50,'status':_0x5eac50[_0x26e9dc(0x147)]===_0x26e9dc(0x137)?_0x26e9dc(0x143):_0x26e9dc(0x13e)};});for(const _0x5c52b7 of _0x185624){_0x5c52b7[_0xb4bdcc(0x13b)][_0xb4bdcc(0x147)]=_0xb4bdcc(0x137);}return{'units':_0x185624[_0xb4bdcc(0x121)](({unitID:_0x3ec62f,status:_0x49d3b0})=>({'unitID':_0x3ec62f,'status':_0x49d3b0}))};}async[_0x24eecb(0x11b)](_0x1661cf,_0x218e90){const _0x53cf51=_0x24eecb;this['_assertOpen']();const {changeset:_0x360e91,expectedHeadRevision:_0x432708}=_0x218e90,_0x363111=this['_activeUnit'](_0x360e91[_0x53cf51(0x117)]);if(!_0x363111)throw unitNotFound(_0x53cf51(0x125));validateSubmissionIdentity(_0x360e91);const _0x5887fe=submissionKey(_0x360e91[_0x53cf51(0x12b)],_0x360e91['reqId']),_0x52662d=_0x363111[_0x53cf51(0x140)][_0x53cf51(0x138)](_0x5887fe);if(_0x52662d)return{'status':_0x53cf51(0x132),'changeset':clone(_0x52662d)};if(_0x363111[_0x53cf51(0x115)][_0x53cf51(0x150)]!==_0x432708)return{'status':_0x53cf51(0x10e),'actualHeadRevision':_0x363111[_0x53cf51(0x115)][_0x53cf51(0x150)]};validateCandidate(_0x363111[_0x53cf51(0x115)],_0x218e90);const _0x10a1f2=clone(_0x360e91);return _0x363111[_0x53cf51(0x126)]['set'](_0x10a1f2[_0x53cf51(0x128)],_0x10a1f2),_0x363111[_0x53cf51(0x140)]['set'](_0x5887fe,_0x10a1f2),_0x363111[_0x53cf51(0x115)]={..._0x363111['record'],'headRevision':_0x10a1f2[_0x53cf51(0x128)]},{'status':_0x53cf51(0x152),'changeset':clone(_0x10a1f2),'headRevision':_0x363111['record'][_0x53cf51(0x150)]};}async[_0x24eecb(0x124)](_0x3985c1,_0x5b5018){const _0x423c39=_0x24eecb;this[_0x423c39(0x15b)]();const _0x2692b6=this[_0x423c39(0x122)](_0x5b5018['snapshot'][_0x423c39(0x117)]);if(!_0x2692b6)throw unitNotFound(_0x423c39(0x113));if(_0x5b5018[_0x423c39(0x142)]['type']!==_0x2692b6[_0x423c39(0x115)][_0x423c39(0x10b)]||_0x5b5018[_0x423c39(0x142)]['rev']<0x1||_0x5b5018[_0x423c39(0x142)][_0x423c39(0x149)]>_0x2692b6[_0x423c39(0x115)][_0x423c39(0x150)])throw invalidRequest(_0x423c39(0x116));const _0x1c554c=clone(_0x5b5018['snapshot']),_0x1d0032=cloneDependencies(_0x5b5018[_0x423c39(0x14a)],_0x5b5018[_0x423c39(0x112)]);publishDependencies(_0x2692b6,_0x1d0032),_0x2692b6[_0x423c39(0x13a)][_0x423c39(0x127)](_0x1c554c['rev'],_0x1c554c);}async[_0x24eecb(0x10a)](_0x594dd1,_0x132dad,_0x1f7b0e){const _0x98bbf5=_0x24eecb;this[_0x98bbf5(0x15b)]();const _0xfa9015=this[_0x98bbf5(0x122)](_0x132dad)?.[_0x98bbf5(0x14a)][_0x98bbf5(0x138)](_0x1f7b0e);return _0xfa9015?clone(_0xfa9015):null;}async[_0x24eecb(0x14e)](_0x33a574,_0x4316b7,_0x3f507f){const _0x20b9ab=_0x24eecb;this[_0x20b9ab(0x15b)]();const _0x143774=this[_0x20b9ab(0x122)](_0x4316b7)?.['resources'];if(!_0x143774)return{};const _0x4d4e91={};for(const _0x4731f2 of _0x3f507f){const _0x5292c2=_0x143774['get'](_0x4731f2);_0x5292c2&&(_0x4d4e91[_0x4731f2]=clone(_0x5292c2));}return _0x4d4e91;}async[_0x24eecb(0x120)](){const _0x2ce796=_0x24eecb;if(this['_disposed'])return;this['_disposed']=!![],this['_units'][_0x2ce796(0x11f)](),this[_0x2ce796(0x148)][_0x2ce796(0x11f)]();}['_activeUnit'](_0x1fbee0){const _0x863abc=_0x24eecb,_0x2b5c8c=this[_0x863abc(0x154)]['get'](_0x1fbee0);return _0x2b5c8c?.[_0x863abc(0x147)]==='active'?_0x2b5c8c:undefined;}['_assertOpen'](){const _0x5e756e=_0x24eecb;if(this['_disposed'])throw new collaboration_service_1['CollabError']('INTERNAL_ERROR',_0x5e756e(0x13f));}}exports[_0x24eecb(0x136)]=MemoryDatabaseAdapter;function validateInitialUnit(_0x8ea4cc){const _0x13f0a6=_0x24eecb,{record:_0x3f23b8,snapshot:_0x55aad2}=_0x8ea4cc;if(_0x3f23b8[_0x13f0a6(0x150)]!==0x1||_0x55aad2['rev']!==0x1||_0x55aad2['unitID']!==_0x3f23b8[_0x13f0a6(0x117)]||_0x55aad2[_0x13f0a6(0x10b)]!==_0x3f23b8[_0x13f0a6(0x10b)])throw invalidRequest(_0x13f0a6(0x110));}function validateSubmissionIdentity(_0x40c903){const _0x4406b1=_0x24eecb;if(!_0x40c903[_0x4406b1(0x12b)]||!Number['isSafeInteger'](_0x40c903[_0x4406b1(0x131)])||_0x40c903[_0x4406b1(0x131)]<0x1)throw invalidRequest(_0x4406b1(0x141));}function validateCandidate(_0x2cf8de,_0x507eaa){const _0x36e7ec=_0x24eecb,{changeset:_0x37fd37,expectedHeadRevision:_0x307203}=_0x507eaa;if(_0x37fd37[_0x36e7ec(0x10b)]!==_0x2cf8de[_0x36e7ec(0x10b)]||_0x37fd37[_0x36e7ec(0x12d)]!==_0x307203||_0x37fd37[_0x36e7ec(0x128)]!==_0x307203+0x1)throw invalidRequest(_0x36e7ec(0x14b));}function cloneDependencies(_0xfb2382,_0x186f38){const _0x31de5f=_0x24eecb,_0x4ebbbd={'sheetBlocks':new Map(),'resources':new Map()};for(const _0x307718 of _0xfb2382??[]){_0x4ebbbd[_0x31de5f(0x14a)][_0x31de5f(0x127)](_0x307718['id'],clone(_0x307718));}for(const [_0x1093f2,_0x38ee9b]of Object[_0x31de5f(0x118)](_0x186f38??{})){_0x4ebbbd['resources'][_0x31de5f(0x127)](_0x1093f2,clone(_0x38ee9b));}return _0x4ebbbd;}function publishDependencies(_0xadca1c,_0x50c5f8){const _0xc1ea85=_0x24eecb;for(const [_0x4366c4,_0x3b8f37]of _0x50c5f8[_0xc1ea85(0x14a)]){_0xadca1c['sheetBlocks'][_0xc1ea85(0x127)](_0x4366c4,_0x3b8f37);}for(const [_0xdfef5d,_0x39e8ae]of _0x50c5f8[_0xc1ea85(0x112)]){_0xadca1c[_0xc1ea85(0x112)][_0xc1ea85(0x127)](_0xdfef5d,_0x39e8ae);}}function _0x1d7d(_0x2c3f50,_0x421eb2){_0x2c3f50=_0x2c3f50-0x109;const _0x4315b0=_0x4315();let _0x1d7d5a=_0x4315b0[_0x2c3f50];return _0x1d7d5a;}function submissionKey(_0x5b6ce3,_0x585192){const _0x5a3e38=_0x24eecb;return _0x5b6ce3[_0x5a3e38(0x10f)]+':'+_0x5b6ce3+':'+_0x585192;}function invalidRequest(_0x4ea2f0){const _0x57f6cb=_0x24eecb;return new collaboration_service_1[(_0x57f6cb(0x10c))]('INVALID_REQUEST',_0x4ea2f0);}function unitNotFound(_0x42fbd0){const _0x1d1734=_0x24eecb;return new collaboration_service_1['CollabError'](_0x1d1734(0x15a),_0x42fbd0);}function uniqueUnitIDs(_0x511539){return[...new Set(_0x511539)];}function clone(_0x3e4be5){return structuredClone(_0x3e4be5);}function _0x4315(){const _0x9656cf=['Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201','getSnapshot','resources','Cannot\x20snapshot\x20a\x20missing\x20unit','soft-deleted','record','Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head','unitID','entries','already-soft-deleted','A\x20purged\x20unit\x20ID\x20cannot\x20be\x20reused','commitChangeset','3342VtlXST','sort','Changeset\x20range\x20revisions\x20cannot\x20be\x20negative','clear','dispose','map','_activeUnit','hard-deleted','saveSnapshot','Cannot\x20commit\x20to\x20a\x20missing\x20unit','changesets','set','revision','keys','from','sid','35ZmdYHC','baseRev','175gYwvJw','getSubmission','72902RtcTIc','reqId','already-committed','createUnit','Cannot\x20hard-delete\x20a\x20missing\x20unit','32hdxQSo','MemoryDatabaseAdapter','active','get','420714XUmPkj','snapshots','stored','has','delete','recovered','Memory\x20Database\x20Adapter\x20is\x20disposed','submissions','Changeset\x20sid\x20and\x20positive\x20integer\x20reqId\x20are\x20required','snapshot','already-active','deleteUnits','getChangesets','hardDelete','lifecycle','_tombstones','rev','sheetBlocks','Confirmed\x20changeset\x20must\x20match\x20the\x20unit\x20type\x20and\x20expected\x20revision','202604OORwai','created','getResources','6707998aANoop','headRevision','3aBsUPO','committed','status','_units','__esModule','min','3671330oJOxUA','A\x20purged\x20unit\x20cannot\x20be\x20recovered','filter','UNIT_NOT_FOUND','_assertOpen','recoverUnits','already-hard-deleted','getSheetBlock','type','CollabError','879876pPRAbD','revision-mismatch','length'];_0x4315=function(){return _0x9656cf;};return _0x4315();}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@univerjs-pro/collaboration-database-memory",
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
+ "version": "1.0.0-insiders.20260727-46ed76c",
17
+ "dependencies": {
18
+ "@univerjs-pro/collaboration-service": "1.0.0-insiders.20260727-46ed76c",
19
+ "@univerjs/protocol": "1.0.0-insiders.20260727-46ed76c"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ }
24
+ }