Files
AFFiNE-Mirror/packages/y-indexeddb/src/shared.ts
三咲智子 Kevin Deng 2c49c774af feat(y-indexeddb): add connected (#2208)
Co-authored-by: Himself65 <himself65@outlook.com>
2023-05-05 03:42:49 +00:00

51 lines
1.0 KiB
TypeScript

import type { DBSchema, IDBPDatabase } from 'idb/build/entry';
export const dbVersion = 1;
export const DEFAULT_DB_NAME = 'affine-local';
export function upgradeDB(db: IDBPDatabase<BlockSuiteBinaryDB>) {
db.createObjectStore('workspace', { keyPath: 'id' });
db.createObjectStore('milestone', { keyPath: 'id' });
}
export interface IndexedDBProvider {
connect: () => void;
disconnect: () => void;
cleanup: () => Promise<void>;
whenSynced: Promise<void>;
readonly connected: boolean;
}
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;
};
}