fix: first binary on y-indexeddb (#1972)

This commit is contained in:
Himself65
2023-04-16 21:33:54 -05:00
committed by GitHub
parent 4cb6b8fdc8
commit 9c517907eb
4 changed files with 139 additions and 60 deletions

View File

@@ -0,0 +1,49 @@
import type { DBSchema, IDBPDatabase } from 'idb/build/entry';
export const dbVersion = 1;
export const DEFAULT_DB_NAME = 'affine-local' as const;
export function upgradeDB(db: IDBPDatabase<BlockSuiteBinaryDB>) {
db.createObjectStore('workspace', { keyPath: 'id' });
db.createObjectStore('milestone', { keyPath: 'id' });
}
export interface IndexedDBProvider {
connect: () => void;
disconnect: () => void;
cleanup: () => void;
whenSynced: Promise<void>;
}
export type UpdateMessage = {
timestamp: number;
update: Uint8Array;
};
export type WorkspacePersist = {
id: string;
updates: UpdateMessage[];
};
export type WorkspaceMilestone = {
id: string;
milestone: Record<string, Uint8Array>;
};
export interface BlockSuiteBinaryDB extends DBSchema {
workspace: {
key: string;
value: WorkspacePersist;
};
milestone: {
key: string;
value: WorkspaceMilestone;
};
}
export interface OldYjsDB extends DBSchema {
updates: {
key: number;
value: Uint8Array;
};
}