feat(nbstore): rename SyncStorage to DocSyncStorage (#10751)

This commit is contained in:
EYHN
2025-03-14 06:25:26 +00:00
parent 92effd9b51
commit f3ef9c4415
19 changed files with 90 additions and 79 deletions

View File

@@ -6,7 +6,7 @@ import { Doc as YDoc, encodeStateAsUpdate } from 'yjs';
import {
IndexedDBBlobStorage,
IndexedDBDocStorage,
IndexedDBSyncStorage,
IndexedDBDocSyncStorage,
} from '../impls/idb';
import { SpaceStorage } from '../storage';
import { Sync } from '../sync';
@@ -23,7 +23,7 @@ test('doc', async () => {
type: 'workspace',
});
const peerASync = new IndexedDBSyncStorage({
const peerASync = new IndexedDBDocSyncStorage({
id: 'ws1',
flavour: 'a',
type: 'workspace',
@@ -42,7 +42,7 @@ test('doc', async () => {
const peerA = new SpaceStorage({
doc: peerADoc,
sync: peerASync,
docSync: peerASync,
});
const peerB = new SpaceStorage({
doc: peerBDoc,

View File

@@ -1,9 +1,13 @@
import { share } from '../../connection';
import { type DocClock, type DocClocks, SyncStorageBase } from '../../storage';
import {
type DocClock,
type DocClocks,
DocSyncStorageBase,
} from '../../storage';
import { IDBConnection, type IDBConnectionOptions } from './db';
export class IndexedDBSyncStorage extends SyncStorageBase {
static readonly identifier = 'IndexedDBSyncStorage';
export class IndexedDBDocSyncStorage extends DocSyncStorageBase {
static readonly identifier = 'IndexedDBDocSyncStorage';
constructor(private readonly options: IDBConnectionOptions) {
super();

View File

@@ -1,14 +1,14 @@
import type { StorageConstructor } from '..';
import { IndexedDBBlobStorage } from './blob';
import { IndexedDBDocStorage } from './doc';
import { IndexedDBSyncStorage } from './sync';
import { IndexedDBDocSyncStorage } from './doc-sync';
export * from './blob';
export * from './doc';
export * from './sync';
export * from './doc-sync';
export const idbStorages = [
IndexedDBDocStorage,
IndexedDBBlobStorage,
IndexedDBSyncStorage,
IndexedDBDocSyncStorage,
] satisfies StorageConstructor[];

View File

@@ -1,9 +1,9 @@
import { share } from '../../connection';
import { type DocClock, SyncStorageBase } from '../../storage';
import { type DocClock, DocSyncStorageBase } from '../../storage';
import { NativeDBConnection, type SqliteNativeDBOptions } from './db';
export class SqliteSyncStorage extends SyncStorageBase {
static readonly identifier = 'SqliteSyncStorage';
export class SqliteDocSyncStorage extends DocSyncStorageBase {
static readonly identifier = 'SqliteDocSyncStorage';
override connection = share(new NativeDBConnection(this.options));

View File

@@ -1,15 +1,15 @@
import type { StorageConstructor } from '..';
import { SqliteBlobStorage } from './blob';
import { SqliteDocStorage } from './doc';
import { SqliteSyncStorage } from './sync';
import { SqliteDocSyncStorage } from './doc-sync';
export * from './blob';
export { bindNativeDBApis, type NativeDBApis } from './db';
export * from './doc';
export * from './sync';
export * from './doc-sync';
export const sqliteStorages = [
SqliteDocStorage,
SqliteBlobStorage,
SqliteSyncStorage,
SqliteDocSyncStorage,
] satisfies StorageConstructor[];

View File

@@ -2,8 +2,8 @@ import type { Connection } from '../connection';
import type { DocClock, DocClocks } from './doc';
import { type Storage } from './storage';
export interface SyncStorage extends Storage {
readonly storageType: 'sync';
export interface DocSyncStorage extends Storage {
readonly storageType: 'docSync';
getPeerRemoteClock(peer: string, docId: string): Promise<DocClock | null>;
getPeerRemoteClocks(peer: string): Promise<DocClocks>;
@@ -20,8 +20,8 @@ export interface SyncStorage extends Storage {
clearClocks(): Promise<void>;
}
export abstract class SyncStorageBase implements SyncStorage {
readonly storageType = 'sync';
export abstract class DocSyncStorageBase implements DocSyncStorage {
readonly storageType = 'docSync';
abstract readonly connection: Connection;
abstract getPeerRemoteClock(

View File

@@ -1,8 +1,8 @@
import { DummyConnection } from '../../connection';
import type { DocClock, DocClocks } from '../doc';
import { SyncStorageBase } from '../sync';
import { DocSyncStorageBase } from '../doc-sync';
export class DummySyncStorage extends SyncStorageBase {
export class DummyDocSyncStorage extends DocSyncStorageBase {
override getPeerRemoteClock(
_peer: string,
_docId: string

View File

@@ -9,6 +9,7 @@ import {
} from '../doc';
export class DummyDocStorage implements DocStorage {
spaceId = '';
readonly storageType = 'doc';
readonly isReadonly = true;
getDoc(_docId: string): Promise<DocRecord | null> {

View File

@@ -3,14 +3,14 @@ import EventEmitter2 from 'eventemitter2';
import type { AwarenessStorage } from './awareness';
import type { BlobStorage } from './blob';
import type { DocStorage } from './doc';
import type { DocSyncStorage } from './doc-sync';
import { DummyAwarenessStorage } from './dummy/awareness';
import { DummyBlobStorage } from './dummy/blob';
import { DummyDocStorage } from './dummy/doc';
import { DummySyncStorage } from './dummy/sync';
import { DummyDocSyncStorage } from './dummy/doc-sync';
import type { StorageType } from './storage';
import type { SyncStorage } from './sync';
type Storages = DocStorage | BlobStorage | SyncStorage | AwarenessStorage;
type Storages = DocStorage | BlobStorage | DocSyncStorage | AwarenessStorage;
export type SpaceStorageOptions = {
[K in StorageType]?: Storages & { storageType: K };
@@ -28,7 +28,7 @@ export class SpaceStorage {
awareness: storages.awareness ?? new DummyAwarenessStorage(),
blob: storages.blob ?? new DummyBlobStorage(),
doc: storages.doc ?? new DummyDocStorage(),
sync: storages.sync ?? new DummySyncStorage(),
['docSync']: storages['docSync'] ?? new DummyDocSyncStorage(),
};
}
@@ -71,7 +71,7 @@ export class SpaceStorage {
export * from './awareness';
export * from './blob';
export * from './doc';
export * from './doc-sync';
export * from './errors';
export * from './history';
export * from './storage';
export * from './sync';

View File

@@ -1,6 +1,6 @@
import type { Connection } from '../connection';
export type StorageType = 'blob' | 'doc' | 'sync' | 'awareness';
export type StorageType = 'blob' | 'doc' | 'docSync' | 'awareness';
export interface Storage {
readonly storageType: StorageType;

View File

@@ -1,9 +1,9 @@
import type { Observable } from 'rxjs';
import { combineLatest, map, of, ReplaySubject, share } from 'rxjs';
import type { DocStorage, SyncStorage } from '../../storage';
import type { DocStorage, DocSyncStorage } from '../../storage';
import { DummyDocStorage } from '../../storage/dummy/doc';
import { DummySyncStorage } from '../../storage/dummy/sync';
import { DummyDocSyncStorage } from '../../storage/dummy/doc-sync';
import { MANUALLY_STOP } from '../../utils/throw-if-aborted';
import type { PeerStorageOptions } from '../types';
import { DocSyncPeer } from './peer';
@@ -68,7 +68,7 @@ export class DocSyncImpl implements DocSync {
constructor(
readonly storages: PeerStorageOptions<DocStorage>,
readonly sync: SyncStorage
readonly sync: DocSyncStorage
) {}
/**
@@ -80,7 +80,7 @@ export class DocSyncImpl implements DocSync {
local: new DummyDocStorage(),
remotes: {},
},
new DummySyncStorage()
new DummyDocSyncStorage()
);
}

View File

@@ -3,7 +3,7 @@ import { nanoid } from 'nanoid';
import { Observable, ReplaySubject, share, Subject } from 'rxjs';
import { diffUpdate, encodeStateVectorFromUpdate, mergeUpdates } from 'yjs';
import type { DocStorage, SyncStorage } from '../../storage';
import type { DocStorage, DocSyncStorage } from '../../storage';
import { AsyncPriorityQueue } from '../../utils/async-priority-queue';
import { ClockMap } from '../../utils/clock';
import { isEmptyUpdate } from '../../utils/is-empty-update';
@@ -147,7 +147,7 @@ export class DocSyncPeer {
constructor(
readonly peerId: string,
readonly local: DocStorage,
readonly syncMetadata: SyncStorage,
readonly syncMetadata: DocSyncStorage,
readonly remote: DocStorage,
readonly options: DocSyncPeerOptions = {}
) {}

View File

@@ -23,7 +23,7 @@ export class Sync {
constructor(readonly storages: PeerStorageOptions<SpaceStorage>) {
const doc = storages.local.get('doc');
const blob = storages.local.get('blob');
const sync = storages.local.get('sync');
const docSync = storages.local.get('docSync');
const awareness = storages.local.get('awareness');
this.doc = new DocSyncImpl(
@@ -36,7 +36,7 @@ export class Sync {
])
),
},
sync
docSync
);
this.blob = new BlobSyncImpl({
local: blob,

View File

@@ -45,8 +45,8 @@ class StoreConsumer {
return this.ensureSync.blob;
}
get syncStorage() {
return this.ensureLocal.get('sync');
get docSyncStorage() {
return this.ensureLocal.get('docSync');
}
get awarenessStorage() {
@@ -170,25 +170,25 @@ class StoreConsumer {
this.blobStorage.delete(key, permanently),
'blobStorage.releaseBlobs': () => this.blobStorage.release(),
'blobStorage.listBlobs': () => this.blobStorage.list(),
'syncStorage.clearClocks': () => this.syncStorage.clearClocks(),
'syncStorage.getPeerPulledRemoteClock': ({ peer, docId }) =>
this.syncStorage.getPeerPulledRemoteClock(peer, docId),
'syncStorage.getPeerPulledRemoteClocks': ({ peer }) =>
this.syncStorage.getPeerPulledRemoteClocks(peer),
'syncStorage.setPeerPulledRemoteClock': ({ peer, clock }) =>
this.syncStorage.setPeerPulledRemoteClock(peer, clock),
'syncStorage.getPeerRemoteClock': ({ peer, docId }) =>
this.syncStorage.getPeerRemoteClock(peer, docId),
'syncStorage.getPeerRemoteClocks': ({ peer }) =>
this.syncStorage.getPeerRemoteClocks(peer),
'syncStorage.setPeerRemoteClock': ({ peer, clock }) =>
this.syncStorage.setPeerRemoteClock(peer, clock),
'syncStorage.getPeerPushedClock': ({ peer, docId }) =>
this.syncStorage.getPeerPushedClock(peer, docId),
'syncStorage.getPeerPushedClocks': ({ peer }) =>
this.syncStorage.getPeerPushedClocks(peer),
'syncStorage.setPeerPushedClock': ({ peer, clock }) =>
this.syncStorage.setPeerPushedClock(peer, clock),
'docSyncStorage.clearClocks': () => this.docSyncStorage.clearClocks(),
'docSyncStorage.getPeerPulledRemoteClock': ({ peer, docId }) =>
this.docSyncStorage.getPeerPulledRemoteClock(peer, docId),
'docSyncStorage.getPeerPulledRemoteClocks': ({ peer }) =>
this.docSyncStorage.getPeerPulledRemoteClocks(peer),
'docSyncStorage.setPeerPulledRemoteClock': ({ peer, clock }) =>
this.docSyncStorage.setPeerPulledRemoteClock(peer, clock),
'docSyncStorage.getPeerRemoteClock': ({ peer, docId }) =>
this.docSyncStorage.getPeerRemoteClock(peer, docId),
'docSyncStorage.getPeerRemoteClocks': ({ peer }) =>
this.docSyncStorage.getPeerRemoteClocks(peer),
'docSyncStorage.setPeerRemoteClock': ({ peer, clock }) =>
this.docSyncStorage.setPeerRemoteClock(peer, clock),
'docSyncStorage.getPeerPushedClock': ({ peer, docId }) =>
this.docSyncStorage.getPeerPushedClock(peer, docId),
'docSyncStorage.getPeerPushedClocks': ({ peer }) =>
this.docSyncStorage.getPeerPushedClocks(peer),
'docSyncStorage.setPeerPushedClock': ({ peer, clock }) =>
this.docSyncStorage.setPeerPushedClock(peer, clock),
'awarenessStorage.update': ({ awareness, origin }) =>
this.awarenessStorage.update(awareness, origin),
'awarenessStorage.subscribeUpdate': docId =>

View File

@@ -45,7 +45,7 @@ interface GroupedWorkerOps {
listBlobs: [void, ListedBlobRecord[]];
};
syncStorage: {
docSyncStorage: {
getPeerPulledRemoteClocks: [{ peer: string }, DocClocks];
getPeerPulledRemoteClock: [
{ peer: string; docId: string },