feat(nbstore): add cloud implementation (#8810)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import {
|
||||
applyUpdate,
|
||||
diffUpdate,
|
||||
Doc,
|
||||
encodeStateAsUpdate,
|
||||
encodeStateVector,
|
||||
encodeStateVectorFromUpdate,
|
||||
mergeUpdates,
|
||||
UndoManager,
|
||||
} from 'yjs';
|
||||
@@ -19,6 +21,12 @@ export interface DocRecord {
|
||||
editor?: string;
|
||||
}
|
||||
|
||||
export interface DocDiff {
|
||||
missing: Uint8Array;
|
||||
state: Uint8Array;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
export interface DocUpdate {
|
||||
bin: Uint8Array;
|
||||
timestamp: number;
|
||||
@@ -96,6 +104,27 @@ export abstract class DocStorageAdapter extends Connection {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
async getDocDiff(
|
||||
spaceId: string,
|
||||
docId: string,
|
||||
stateVector?: Uint8Array
|
||||
): Promise<DocDiff | null> {
|
||||
const doc = await this.getDoc(spaceId, docId);
|
||||
|
||||
if (!doc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const missing = stateVector ? diffUpdate(doc.bin, stateVector) : doc.bin;
|
||||
const state = encodeStateVectorFromUpdate(doc.bin);
|
||||
|
||||
return {
|
||||
missing,
|
||||
state,
|
||||
timestamp: doc.timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
abstract pushDocUpdates(
|
||||
spaceId: string,
|
||||
docId: string,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// TODO(@forehalo): share with frontend
|
||||
// This is a totally copy of definitions in [@affine/space-store]
|
||||
// because currently importing cross workspace package from [@affine/server] is not yet supported
|
||||
// should be kept updated with the original definitions in [@affine/space-store]
|
||||
import type { BlobStorageAdapter } from './blob';
|
||||
import { Connection } from './connection';
|
||||
import type { DocStorageAdapter } from './doc';
|
||||
|
||||
Reference in New Issue
Block a user