mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-05 03:19:52 +08:00
feat(nbstore): improve nbstore (#9512)
This commit is contained in:
@@ -1,47 +1,24 @@
|
||||
import type { Storage } from '../storage';
|
||||
import { BroadcastChannelAwarenessStorage } from './broadcast-channel/awareness';
|
||||
import {
|
||||
CloudAwarenessStorage,
|
||||
CloudBlobStorage,
|
||||
CloudDocStorage,
|
||||
} from './cloud';
|
||||
import {
|
||||
IndexedDBBlobStorage,
|
||||
IndexedDBDocStorage,
|
||||
IndexedDBSyncStorage,
|
||||
} from './idb';
|
||||
import { IndexedDBV1BlobStorage, IndexedDBV1DocStorage } from './idb/v1';
|
||||
import type { broadcastChannelStorages } from './broadcast-channel';
|
||||
import type { cloudStorages } from './cloud';
|
||||
import type { idbStorages, idbv1Storages } from './idb';
|
||||
import type { sqliteStorages } from './sqlite';
|
||||
|
||||
type StorageConstructor = new (...args: any[]) => Storage;
|
||||
|
||||
const idb: StorageConstructor[] = [
|
||||
IndexedDBDocStorage,
|
||||
IndexedDBBlobStorage,
|
||||
IndexedDBSyncStorage,
|
||||
BroadcastChannelAwarenessStorage,
|
||||
];
|
||||
|
||||
const idbv1: StorageConstructor[] = [
|
||||
IndexedDBV1DocStorage,
|
||||
IndexedDBV1BlobStorage,
|
||||
];
|
||||
|
||||
const cloud: StorageConstructor[] = [
|
||||
CloudDocStorage,
|
||||
CloudBlobStorage,
|
||||
CloudAwarenessStorage,
|
||||
];
|
||||
|
||||
export const storages: StorageConstructor[] = cloud.concat(idbv1, idb);
|
||||
|
||||
const AvailableStorageImplementations = storages.reduce(
|
||||
(acc, curr) => {
|
||||
acc[curr.name] = curr;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, StorageConstructor>
|
||||
);
|
||||
|
||||
export const getAvailableStorageImplementations = (name: string) => {
|
||||
return AvailableStorageImplementations[name];
|
||||
export type StorageConstructor = {
|
||||
new (...args: any[]): Storage;
|
||||
readonly identifier: string;
|
||||
};
|
||||
|
||||
type Storages =
|
||||
| typeof cloudStorages
|
||||
| typeof idbv1Storages
|
||||
| typeof idbStorages
|
||||
| typeof sqliteStorages
|
||||
| typeof broadcastChannelStorages;
|
||||
|
||||
// oxlint-disable-next-line no-redeclare
|
||||
export type AvailableStorageImplementations = {
|
||||
[key in Storages[number]['identifier']]: Storages[number] & {
|
||||
identifier: key;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user