@univerjs-pro/collaboration-database-memory 1.0.0-beta.2
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/README.md +35 -0
- package/README.zh-CN.md +37 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.mjs +1 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-database-memory
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
An in-process `IDatabaseAdapter` for tests, local development, and temporary collaboration services.
|
|
6
|
+
|
|
7
|
+
## Create the Adapter
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add \
|
|
11
|
+
@univerjs-pro/collaboration-service \
|
|
12
|
+
@univerjs-pro/collaboration-database-memory
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { MemoryDatabaseAdapter } from '@univerjs-pro/collaboration-database-memory';
|
|
17
|
+
import { UniverCollabService } from '@univerjs-pro/collaboration-service';
|
|
18
|
+
|
|
19
|
+
const database = new MemoryDatabaseAdapter();
|
|
20
|
+
const service = new UniverCollabService({ dbAdapter: database });
|
|
21
|
+
|
|
22
|
+
await service.dispose();
|
|
23
|
+
await database.dispose();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Pass the Adapter to `UniverCollabService` as `dbAdapter`.
|
|
27
|
+
|
|
28
|
+
It follows the same collaboration persistence contract as the SQLite Adapter, including revision CAS, revisioned snapshots, Sheet blocks, and atomic Unit lifecycle batches. Submission idempotency is resolved by the Service from continuous changeset history, not by the Adapter.
|
|
29
|
+
|
|
30
|
+
## Limitations
|
|
31
|
+
|
|
32
|
+
- All data is lost when the process exits.
|
|
33
|
+
- State is not shared between Node.js processes.
|
|
34
|
+
- It is intended only for tests and temporary environments, not persistent production data.
|
|
35
|
+
- Hard delete removes core Unit data from the current process and retains a permanent deletion marker that prevents ID reuse.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @univerjs-pro/collaboration-database-memory
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
进程内 `IDatabaseAdapter`,适合测试、本地开发和临时协同服务。
|
|
6
|
+
|
|
7
|
+
## 创建 Adapter
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add \
|
|
11
|
+
@univerjs-pro/collaboration-service \
|
|
12
|
+
@univerjs-pro/collaboration-database-memory
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { MemoryDatabaseAdapter } from '@univerjs-pro/collaboration-database-memory';
|
|
17
|
+
import { UniverCollabService } from '@univerjs-pro/collaboration-service';
|
|
18
|
+
|
|
19
|
+
const database = new MemoryDatabaseAdapter();
|
|
20
|
+
const service = new UniverCollabService({ dbAdapter: database });
|
|
21
|
+
|
|
22
|
+
await service.dispose();
|
|
23
|
+
await database.dispose();
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
将 Adapter 作为 `dbAdapter` 传给 `UniverCollabService`。
|
|
27
|
+
|
|
28
|
+
它与 SQLite Adapter 遵守相同的协同持久化契约,包括 revision CAS、revisioned
|
|
29
|
+
snapshot、Sheet blocks 和原子 Unit 生命周期批次。提交幂等由 Service 从连续
|
|
30
|
+
changeset history 中判断,不由 Adapter 维护 submission 索引。
|
|
31
|
+
|
|
32
|
+
## 限制
|
|
33
|
+
|
|
34
|
+
- 进程退出后全部数据丢失。
|
|
35
|
+
- 多个 Node.js 进程之间不共享状态。
|
|
36
|
+
- 只适合测试和临时环境,不适合持久化生产数据。
|
|
37
|
+
- hard delete 会清理当前进程中的核心 Unit 数据,并保留永久删除标记以禁止 ID 复用。
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object['defineProperty'](exports,Symbol['toStringTag'],{'value':'Module'});let e=require('@univerjs-pro/collaboration-service');var t=class{['_units']=new Map();['_tombstones']=new Set();['_disposed']=!0x1;async['getUnit'](_0x11d9eb,_0x1af9e7){this['_assertOpen']();let _0x50c627=this['_activeUnit'](_0x1af9e7);return _0x50c627?c(_0x50c627['record']):null;}async['getSnapshot'](_0x3ebb91,_0x187ac0,_0x46c7ae){this['_assertOpen']();let _0x46f4fa=this['_activeUnit'](_0x187ac0);if(!_0x46f4fa)return null;let _0x2c69ba=_0x46c7ae?.['revision'],_0x333913=_0x2c69ba===void 0x0||_0x2c69ba===0x0?_0x46f4fa['record']['headRevision']:Math['min'](_0x2c69ba,_0x46f4fa['record']['headRevision']),_0x1e9591=-0x1;for(let _0x4a3add of _0x46f4fa['snapshots']['keys']())_0x4a3add<=_0x333913&&_0x4a3add>_0x1e9591&&(_0x1e9591=_0x4a3add);let _0x45faad=_0x46f4fa['snapshots']['get'](_0x1e9591);return _0x45faad?c(_0x45faad):null;}async['getChangesets'](_0x4edb6c,_0x36ddc1,_0x1dffd9){if(this['_assertOpen'](),_0x1dffd9['from']<0x0||_0x1dffd9['to']<0x0)throw a('Changeset\x20range\x20revisions\x20cannot\x20be\x20negative');let _0x272a45=this['_activeUnit'](_0x36ddc1);if(!_0x272a45)return{'changesets':[],'latestRevision':0x0};let _0x13100d=_0x1dffd9['to']===0x0?_0x272a45['record']['headRevision']:Math['min'](_0x1dffd9['to'],_0x272a45['record']['headRevision']);return{'changesets':[..._0x272a45['changesets']['entries']()]['filter'](([_0x295d2d])=>_0x295d2d>_0x1dffd9['from']&&_0x295d2d<=_0x13100d)['sort'](([_0x28bf64],[_0x4af5ad])=>_0x28bf64-_0x4af5ad)['map'](([,_0x449411])=>c(_0x449411)),'latestRevision':_0x272a45['record']['headRevision']};}async['createUnit'](_0x38c233,_0x29b67d){this['_assertOpen'](),n(_0x29b67d);let _0x25f611=this['_units']['get'](_0x29b67d['record']['unitID']);if(_0x25f611){if(_0x25f611['lifecycle']==='soft-deleted')throw a('A\x20soft-deleted\x20unit\x20ID\x20cannot\x20be\x20reused');return{'status':'already-exists','record':c(_0x25f611['record'])};}if(this['_tombstones']['has'](_0x29b67d['record']['unitID']))throw a('A\x20purged\x20unit\x20ID\x20cannot\x20be\x20reused');let _0x426ed3=r(_0x29b67d['sheetBlocks']),_0x2b0674={'record':c(_0x29b67d['record']),'lifecycle':'active','snapshots':new Map([[0x1,c(_0x29b67d['snapshot'])]]),'changesets':new Map(),'sheetBlocks':_0x426ed3};return this['_units']['set'](_0x29b67d['record']['unitID'],_0x2b0674),{'status':'created','record':c(_0x2b0674['record'])};}async['deleteUnits'](_0x26447b,_0x44f447){this['_assertOpen']();let _0x54ebce=s(_0x44f447['unitIDs'])['map'](_0x252963=>{let _0x4bb5f2=this['_units']['get'](_0x252963);if(_0x44f447['hardDelete']){if(_0x4bb5f2)return{'unitID':_0x252963,'stored':_0x4bb5f2,'status':'hard-deleted'};if(this['_tombstones']['has'](_0x252963))return{'unitID':_0x252963,'status':'already-hard-deleted'};throw o('Cannot\x20hard-delete\x20a\x20missing\x20unit');}if(!_0x4bb5f2||this['_tombstones']['has'](_0x252963))throw o('Cannot\x20soft-delete\x20a\x20missing\x20unit');return{'unitID':_0x252963,'stored':_0x4bb5f2,'status':_0x4bb5f2['lifecycle']==='active'?'soft-deleted':'already-soft-deleted'};});for(let _0x2e8b05 of _0x54ebce)_0x44f447['hardDelete']&&_0x2e8b05['status']==='hard-deleted'?(this['_units']['delete'](_0x2e8b05['unitID']),this['_tombstones']['add'](_0x2e8b05['unitID'])):!_0x44f447['hardDelete']&&_0x2e8b05['stored']&&(_0x2e8b05['stored']['lifecycle']='soft-deleted');return{'units':_0x54ebce['map'](({unitID:_0x28ba8b,status:_0x43755f})=>({'unitID':_0x28ba8b,'status':_0x43755f}))};}async['recoverUnits'](_0x9234e4,_0x48172f){this['_assertOpen']();let _0x50672c=s(_0x48172f['unitIDs'])['map'](_0xc9e13d=>{if(this['_tombstones']['has'](_0xc9e13d))throw a('A\x20purged\x20unit\x20cannot\x20be\x20recovered');let _0x14a0ed=this['_units']['get'](_0xc9e13d);if(!_0x14a0ed)throw o('Cannot\x20recover\x20a\x20missing\x20unit');return{'unitID':_0xc9e13d,'stored':_0x14a0ed,'status':_0x14a0ed['lifecycle']==='active'?'already-active':'recovered'};});for(let _0xe771e3 of _0x50672c)_0xe771e3['stored']['lifecycle']='active';return{'units':_0x50672c['map'](({unitID:_0x4f73fe,status:_0xfe699c})=>({'unitID':_0x4f73fe,'status':_0xfe699c}))};}async['commitChangeset'](_0x3d4885,_0x1ac20a){this['_assertOpen']();let {changeset:_0x549341}=_0x1ac20a,_0x2622b8=this['_activeUnit'](_0x549341['unitID']);if(!_0x2622b8)throw o('Cannot\x20commit\x20to\x20a\x20missing\x20unit');if(_0x2622b8['record']['headRevision']!==_0x549341['revision']-0x1)return{'status':'revision-mismatch','actualHeadRevision':_0x2622b8['record']['headRevision']};let _0x357f79=c(_0x549341);return _0x2622b8['changesets']['set'](_0x357f79['revision'],_0x357f79),_0x2622b8['record']={..._0x2622b8['record'],'headRevision':_0x357f79['revision']},{'status':'committed','changeset':c(_0x357f79),'headRevision':_0x2622b8['record']['headRevision']};}async['saveSnapshot'](_0x8d983b,_0x5048b9){this['_assertOpen']();let _0x11513b=this['_activeUnit'](_0x5048b9['snapshot']['unitID']);if(!_0x11513b)throw o('Cannot\x20snapshot\x20a\x20missing\x20unit');if(_0x5048b9['snapshot']['type']!==_0x11513b['record']['type']||_0x5048b9['snapshot']['rev']<0x1||_0x5048b9['snapshot']['rev']>_0x11513b['record']['headRevision'])throw a('Snapshot\x20does\x20not\x20match\x20the\x20stored\x20unit\x20head');let _0x9d37a6=c(_0x5048b9['snapshot']);i(_0x11513b,r(_0x5048b9['sheetBlocks'])),_0x11513b['snapshots']['set'](_0x9d37a6['rev'],_0x9d37a6);}async['getSheetBlock'](_0x470df2,_0xd82feb,_0x543a54){this['_assertOpen']();let _0x17ecb2=this['_activeUnit'](_0xd82feb)?.['sheetBlocks']['get'](_0x543a54);return _0x17ecb2?c(_0x17ecb2):null;}async['dispose'](){this['_disposed']||(this['_disposed']=!0x0,this['_units']['clear'](),this['_tombstones']['clear']());}['_activeUnit'](_0x52c07b){let _0x475650=this['_units']['get'](_0x52c07b);return _0x475650?.['lifecycle']==='active'?_0x475650:void 0x0;}['_assertOpen'](){if(this['_disposed'])throw new e['CollabError']('INTERNAL_ERROR','Memory\x20Database\x20Adapter\x20is\x20disposed');}};function n(_0x2869a6){let {record:_0x4aec24,snapshot:_0x3c0a16}=_0x2869a6;if(_0x4aec24['headRevision']!==0x1||_0x3c0a16['rev']!==0x1||_0x3c0a16['unitID']!==_0x4aec24['unitID']||_0x3c0a16['type']!==_0x4aec24['type'])throw a('Initial\x20unit\x20record\x20and\x20snapshot\x20must\x20match\x20at\x20revision\x201');}function r(_0x4cdf02){let _0x40ee12=new Map();for(let _0x410716 of _0x4cdf02??[])_0x40ee12['set'](_0x410716['id'],c(_0x410716));return _0x40ee12;}function i(_0x30a9ff,_0x3a2c5f){for(let [_0x4e01eb,_0x4ba081]of _0x3a2c5f)_0x30a9ff['sheetBlocks']['set'](_0x4e01eb,_0x4ba081);}function a(_0x4ddc8b){return new e['CollabError']('INVALID_REQUEST',_0x4ddc8b);}function o(_0x257156){return new e['CollabError']('UNIT_NOT_FOUND',_0x257156);}function s(_0x2e94ba){return[...new Set(_0x2e94ba)];}function c(_0x3dd1b1){return structuredClone(_0x3dd1b1);}exports['MemoryDatabaseAdapter']=t;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ChangesetRange, CommitChangesetInput, CommitChangesetResult, CreateUnitDatabaseInput, CreateUnitDatabaseResult, DatabaseContext, DeleteUnitsDatabaseInput, DeleteUnitsDatabaseResult, IDatabaseAdapter, RecoverUnitsDatabaseInput, RecoverUnitsDatabaseResult, SaveSnapshotInput, UnitRecord } from "@univerjs-pro/collaboration-service";
|
|
2
|
+
import { ISheetBlock, ISnapshot } from "@univerjs/protocol";
|
|
3
|
+
|
|
4
|
+
//#region src/memory-database-adapter.d.ts
|
|
5
|
+
declare class MemoryDatabaseAdapter implements IDatabaseAdapter {
|
|
6
|
+
private readonly _units;
|
|
7
|
+
private readonly _tombstones;
|
|
8
|
+
private _disposed;
|
|
9
|
+
getUnit(_context: DatabaseContext, unitID: string): Promise<UnitRecord | null>;
|
|
10
|
+
getSnapshot(_context: DatabaseContext, unitID: string, options?: {
|
|
11
|
+
readonly revision?: number;
|
|
12
|
+
}): Promise<ISnapshot | null>;
|
|
13
|
+
getChangesets(_context: DatabaseContext, unitID: string, range: {
|
|
14
|
+
readonly from: number;
|
|
15
|
+
readonly to: number;
|
|
16
|
+
}): Promise<ChangesetRange>;
|
|
17
|
+
createUnit(_context: DatabaseContext, input: CreateUnitDatabaseInput): Promise<CreateUnitDatabaseResult>;
|
|
18
|
+
deleteUnits(_context: DatabaseContext, input: DeleteUnitsDatabaseInput): Promise<DeleteUnitsDatabaseResult>;
|
|
19
|
+
recoverUnits(_context: DatabaseContext, input: RecoverUnitsDatabaseInput): Promise<RecoverUnitsDatabaseResult>;
|
|
20
|
+
commitChangeset(_context: DatabaseContext, input: CommitChangesetInput): Promise<CommitChangesetResult>;
|
|
21
|
+
saveSnapshot(_context: DatabaseContext, input: SaveSnapshotInput): Promise<void>;
|
|
22
|
+
getSheetBlock(_context: DatabaseContext, unitID: string, blockID: string): Promise<ISheetBlock | null>;
|
|
23
|
+
dispose(): Promise<void>;
|
|
24
|
+
private _activeUnit;
|
|
25
|
+
private _assertOpen;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { MemoryDatabaseAdapter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function _0x5c60(_0x225e06,_0x1a8d70){_0x225e06=_0x225e06-0x1bd;const _0x5206bf=_0x5206();let _0x5c604b=_0x5206bf[_0x225e06];return _0x5c604b;}const _0x194255=_0x5c60;(function(_0x2920b8,_0x346a7e){const _0x2561ad=_0x5c60,_0x560be8=_0x2920b8();while(!![]){try{const _0x1e0bf5=-parseInt(_0x2561ad(0x1be))/0x1*(parseInt(_0x2561ad(0x1c9))/0x2)+parseInt(_0x2561ad(0x1c4))/0x3*(-parseInt(_0x2561ad(0x1c2))/0x4)+parseInt(_0x2561ad(0x1c7))/0x5*(parseInt(_0x2561ad(0x1c6))/0x6)+parseInt(_0x2561ad(0x1c1))/0x7+-parseInt(_0x2561ad(0x1bd))/0x8*(parseInt(_0x2561ad(0x1bf))/0x9)+parseInt(_0x2561ad(0x1c0))/0xa+-parseInt(_0x2561ad(0x1c8))/0xb*(-parseInt(_0x2561ad(0x1c3))/0xc);if(_0x1e0bf5===_0x346a7e)break;else _0x560be8['push'](_0x560be8['shift']());}catch(_0x35baf0){_0x560be8['push'](_0x560be8['shift']());}}}(_0x5206,0xdd6d9));import _0x481258 from'./index.cjs';const facadeExport0=_0x481258[_0x194255(0x1c5)];export{facadeExport0 as MemoryDatabaseAdapter};function _0x5206(){const _0x23b8e0=['759962CqOpfh','713188QvxiZs','614580UxVLLd','9DGvXPh','MemoryDatabaseAdapter','312oUCUUF','171815KzlLpw','330MpHSDr','2msGVYm','16FoNXuG','1703427JsSuCF','3752703Hwjicw','5473290KoJoDn'];_0x5206=function(){return _0x23b8e0;};return _0x5206();}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@univerjs-pro/collaboration-database-memory",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@univerjs-pro/collaboration-service": "1.0.0-beta.2",
|
|
20
|
+
"@univerjs/protocol": "1.0.0-beta.2"
|
|
21
|
+
}
|
|
22
|
+
}
|