mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 04:26:23 +08:00
feat(nbstore): add blob sync storage (#10752)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { share } from '../../connection';
|
||||
import { BlobSyncStorageBase } from '../../storage';
|
||||
import { NativeDBConnection, type SqliteNativeDBOptions } from './db';
|
||||
|
||||
export class SqliteBlobSyncStorage extends BlobSyncStorageBase {
|
||||
static readonly identifier = 'SqliteBlobSyncStorage';
|
||||
|
||||
override connection = share(new NativeDBConnection(this.options));
|
||||
|
||||
constructor(private readonly options: SqliteNativeDBOptions) {
|
||||
super();
|
||||
}
|
||||
|
||||
get db() {
|
||||
return this.connection.apis;
|
||||
}
|
||||
|
||||
override async setBlobUploadedAt(
|
||||
peer: string,
|
||||
blobId: string,
|
||||
uploadedAt: Date | null
|
||||
): Promise<void> {
|
||||
await this.db.setBlobUploadedAt(peer, blobId, uploadedAt);
|
||||
}
|
||||
|
||||
override async getBlobUploadedAt(
|
||||
peer: string,
|
||||
blobId: string
|
||||
): Promise<Date | null> {
|
||||
return this.db.getBlobUploadedAt(peer, blobId);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { NativeDBConnection, type SqliteNativeDBOptions } from './db';
|
||||
|
||||
export class SqliteBlobStorage extends BlobStorageBase {
|
||||
static readonly identifier = 'SqliteBlobStorage';
|
||||
override readonly isReadonly = false;
|
||||
|
||||
override connection = share(new NativeDBConnection(this.options));
|
||||
|
||||
|
||||
@@ -13,67 +13,75 @@ export interface SqliteNativeDBOptions {
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export type NativeDBApis = {
|
||||
connect(id: string): Promise<void>;
|
||||
disconnect(id: string): Promise<void>;
|
||||
pushUpdate(id: string, docId: string, update: Uint8Array): Promise<Date>;
|
||||
getDocSnapshot(id: string, docId: string): Promise<DocRecord | null>;
|
||||
setDocSnapshot(id: string, snapshot: DocRecord): Promise<boolean>;
|
||||
getDocUpdates(id: string, docId: string): Promise<DocRecord[]>;
|
||||
markUpdatesMerged(
|
||||
export interface NativeDBApis {
|
||||
connect: (id: string) => Promise<void>;
|
||||
disconnect: (id: string) => Promise<void>;
|
||||
pushUpdate: (id: string, docId: string, update: Uint8Array) => Promise<Date>;
|
||||
getDocSnapshot: (id: string, docId: string) => Promise<DocRecord | null>;
|
||||
setDocSnapshot: (id: string, snapshot: DocRecord) => Promise<boolean>;
|
||||
getDocUpdates: (id: string, docId: string) => Promise<DocRecord[]>;
|
||||
markUpdatesMerged: (
|
||||
id: string,
|
||||
docId: string,
|
||||
updates: Date[]
|
||||
): Promise<number>;
|
||||
deleteDoc(id: string, docId: string): Promise<void>;
|
||||
getDocClocks(
|
||||
id: string,
|
||||
after?: Date | undefined | null
|
||||
): Promise<DocClock[]>;
|
||||
getDocClock(id: string, docId: string): Promise<DocClock | null>;
|
||||
getBlob(id: string, key: string): Promise<BlobRecord | null>;
|
||||
setBlob(id: string, blob: BlobRecord): Promise<void>;
|
||||
deleteBlob(id: string, key: string, permanently: boolean): Promise<void>;
|
||||
releaseBlobs(id: string): Promise<void>;
|
||||
listBlobs(id: string): Promise<ListedBlobRecord[]>;
|
||||
getPeerRemoteClocks(id: string, peer: string): Promise<DocClock[]>;
|
||||
getPeerRemoteClock(
|
||||
) => Promise<number>;
|
||||
deleteDoc: (id: string, docId: string) => Promise<void>;
|
||||
getDocClocks: (id: string, after?: Date | null) => Promise<DocClock[]>;
|
||||
getDocClock: (id: string, docId: string) => Promise<DocClock | null>;
|
||||
getBlob: (id: string, key: string) => Promise<BlobRecord | null>;
|
||||
setBlob: (id: string, blob: BlobRecord) => Promise<void>;
|
||||
deleteBlob: (id: string, key: string, permanently: boolean) => Promise<void>;
|
||||
releaseBlobs: (id: string) => Promise<void>;
|
||||
listBlobs: (id: string) => Promise<ListedBlobRecord[]>;
|
||||
getPeerRemoteClocks: (id: string, peer: string) => Promise<DocClock[]>;
|
||||
getPeerRemoteClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string
|
||||
): Promise<DocClock | null>;
|
||||
setPeerRemoteClock(
|
||||
) => Promise<DocClock | null>;
|
||||
setPeerRemoteClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string,
|
||||
clock: Date
|
||||
): Promise<void>;
|
||||
getPeerPulledRemoteClocks(id: string, peer: string): Promise<DocClock[]>;
|
||||
getPeerPulledRemoteClock(
|
||||
) => Promise<void>;
|
||||
getPeerPulledRemoteClocks: (id: string, peer: string) => Promise<DocClock[]>;
|
||||
getPeerPulledRemoteClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string
|
||||
): Promise<DocClock | null>;
|
||||
setPeerPulledRemoteClock(
|
||||
) => Promise<DocClock | null>;
|
||||
setPeerPulledRemoteClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string,
|
||||
clock: Date
|
||||
): Promise<void>;
|
||||
getPeerPushedClocks(id: string, peer: string): Promise<DocClock[]>;
|
||||
getPeerPushedClock(
|
||||
) => Promise<void>;
|
||||
getPeerPushedClocks: (id: string, peer: string) => Promise<DocClock[]>;
|
||||
getPeerPushedClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string
|
||||
): Promise<DocClock | null>;
|
||||
setPeerPushedClock(
|
||||
) => Promise<DocClock | null>;
|
||||
setPeerPushedClock: (
|
||||
id: string,
|
||||
peer: string,
|
||||
docId: string,
|
||||
clock: Date
|
||||
): Promise<void>;
|
||||
clearClocks(id: string): Promise<void>;
|
||||
};
|
||||
) => Promise<void>;
|
||||
clearClocks: (id: string) => Promise<void>;
|
||||
setBlobUploadedAt: (
|
||||
id: string,
|
||||
peer: string,
|
||||
blobId: string,
|
||||
uploadedAt: Date | null
|
||||
) => Promise<void>;
|
||||
getBlobUploadedAt: (
|
||||
id: string,
|
||||
peer: string,
|
||||
blobId: string
|
||||
) => Promise<Date | null>;
|
||||
}
|
||||
|
||||
type NativeDBApisWrapper = NativeDBApis extends infer APIs
|
||||
? {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { StorageConstructor } from '..';
|
||||
import { SqliteBlobStorage } from './blob';
|
||||
import { SqliteBlobSyncStorage } from './blob-sync';
|
||||
import { SqliteDocStorage } from './doc';
|
||||
import { SqliteDocSyncStorage } from './doc-sync';
|
||||
|
||||
export * from './blob';
|
||||
export * from './blob-sync';
|
||||
export { bindNativeDBApis, type NativeDBApis } from './db';
|
||||
export * from './doc';
|
||||
export * from './doc-sync';
|
||||
@@ -12,4 +14,5 @@ export const sqliteStorages = [
|
||||
SqliteDocStorage,
|
||||
SqliteBlobStorage,
|
||||
SqliteDocSyncStorage,
|
||||
SqliteBlobSyncStorage,
|
||||
] satisfies StorageConstructor[];
|
||||
|
||||
@@ -9,6 +9,7 @@ import { apis } from './db';
|
||||
export class SqliteV1BlobStorage extends BlobStorageBase {
|
||||
static identifier = 'SqliteV1BlobStorage';
|
||||
override connection = new DummyConnection();
|
||||
override readonly isReadonly = true;
|
||||
|
||||
constructor(private readonly options: { type: SpaceType; id: string }) {
|
||||
super();
|
||||
|
||||
Reference in New Issue
Block a user