chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1,2 @@
export * from './indexeddb.js';
export * from './memory.js';
@@ -0,0 +1,39 @@
import { createStore, del, get, keys, set } from 'idb-keyval';
import type { BlobSource } from '../source.js';
export class IndexedDBBlobSource implements BlobSource {
readonly mimeTypeStore = createStore(`${this.name}_blob_mime`, 'blob_mime');
readonly = false;
readonly store = createStore(`${this.name}_blob`, 'blob');
constructor(readonly name: string) {}
async delete(key: string) {
await del(key, this.store);
await del(key, this.mimeTypeStore);
}
async get(key: string) {
const res = await get<ArrayBuffer>(key, this.store);
if (res) {
return new Blob([res], {
type: await get(key, this.mimeTypeStore),
});
}
return null;
}
async list() {
const list = await keys<string>(this.store);
return list;
}
async set(key: string, value: Blob) {
await set(key, await value.arrayBuffer(), this.store);
await set(key, value.type, this.mimeTypeStore);
return key;
}
}
@@ -0,0 +1,27 @@
import type { BlobSource } from '../source.js';
export class MemoryBlobSource implements BlobSource {
readonly map = new Map<string, Blob>();
name = 'memory';
readonly = false;
delete(key: string) {
this.map.delete(key);
return Promise.resolve();
}
get(key: string) {
return Promise.resolve(this.map.get(key) ?? null);
}
list() {
return Promise.resolve(Array.from(this.map.keys()));
}
set(key: string, value: Blob) {
this.map.set(key, value);
return Promise.resolve(key);
}
}