mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 22:38:56 +08:00
feat(nbstore): add awareness storage&sync&frontend (#9016)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { Storage, type StorageOptions } from './storage';
|
||||
|
||||
export interface AwarenessStorageOptions extends StorageOptions {}
|
||||
|
||||
export type AwarenessRecord = {
|
||||
docId: string;
|
||||
bin: Uint8Array;
|
||||
};
|
||||
|
||||
export abstract class AwarenessStorage<
|
||||
Options extends AwarenessStorageOptions = AwarenessStorageOptions,
|
||||
> extends Storage<Options> {
|
||||
override readonly storageType = 'awareness';
|
||||
|
||||
/**
|
||||
* Update the awareness record.
|
||||
*
|
||||
* @param origin - Internal identifier to recognize the source in the "update" event. Will not be stored or transferred.
|
||||
*/
|
||||
abstract update(record: AwarenessRecord, origin?: string): Promise<void>;
|
||||
|
||||
abstract subscribeUpdate(
|
||||
id: string,
|
||||
onUpdate: (update: AwarenessRecord, origin?: string) => void,
|
||||
onCollect: () => AwarenessRecord
|
||||
): () => void;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import EventEmitter2 from 'eventemitter2';
|
||||
import type { ConnectionStatus } from '../connection';
|
||||
import type { BlobStorage } from './blob';
|
||||
import type { DocStorage } from './doc';
|
||||
import { type Storage, type StorageType } from './storage';
|
||||
import type { Storage, StorageType } from './storage';
|
||||
import type { SyncStorage } from './sync';
|
||||
|
||||
type Storages = DocStorage | BlobStorage | SyncStorage;
|
||||
@@ -22,7 +22,10 @@ export class SpaceStorage {
|
||||
tryGet<T extends StorageType>(
|
||||
type: T
|
||||
): Extract<Storages, { storageType: T }> | undefined {
|
||||
return this.storages.get(type) as Extract<Storages, { storageType: T }>;
|
||||
return this.storages.get(type) as unknown as Extract<
|
||||
Storages,
|
||||
{ storageType: T }
|
||||
>;
|
||||
}
|
||||
|
||||
get<T extends StorageType>(type: T): Extract<Storages, { storageType: T }> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Connection } from '../connection';
|
||||
|
||||
export type SpaceType = 'workspace' | 'userspace';
|
||||
export type StorageType = 'blob' | 'doc' | 'sync';
|
||||
export type StorageType = 'blob' | 'doc' | 'sync' | 'awareness';
|
||||
|
||||
export interface StorageOptions {
|
||||
peer: string;
|
||||
|
||||
Reference in New Issue
Block a user