mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
refactor(infra): migrate to new infra (#5565)
This commit is contained in:
@@ -11,10 +11,6 @@ export const AwarenessProvider =
|
||||
export class AwarenessEngine {
|
||||
constructor(public readonly providers: AwarenessProvider[]) {}
|
||||
|
||||
static get EMPTY() {
|
||||
return new AwarenessEngine([]);
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.providers.forEach(provider => provider.connect());
|
||||
}
|
||||
|
||||
@@ -54,10 +54,6 @@ export class BlobEngine {
|
||||
private readonly remotes: BlobStorage[]
|
||||
) {}
|
||||
|
||||
static get EMPTY() {
|
||||
return new BlobEngine(createEmptyBlobStorage(), []);
|
||||
}
|
||||
|
||||
start() {
|
||||
if (this.abort || this._status.isStorageOverCapacity) {
|
||||
return;
|
||||
@@ -222,21 +218,19 @@ export class BlobEngine {
|
||||
}
|
||||
}
|
||||
|
||||
export function createEmptyBlobStorage() {
|
||||
return {
|
||||
name: 'empty',
|
||||
readonly: true,
|
||||
async get(_key: string) {
|
||||
return null;
|
||||
},
|
||||
async set(_key: string, _value: Blob) {
|
||||
throw new Error('not supported');
|
||||
},
|
||||
async delete(_key: string) {
|
||||
throw new Error('not supported');
|
||||
},
|
||||
async list() {
|
||||
return [];
|
||||
},
|
||||
} satisfies BlobStorage;
|
||||
}
|
||||
export const EmptyBlobStorage: BlobStorage = {
|
||||
name: 'empty',
|
||||
readonly: true,
|
||||
async get(_key: string) {
|
||||
return null;
|
||||
},
|
||||
async set(_key: string, _value: Blob) {
|
||||
throw new Error('not supported');
|
||||
},
|
||||
async delete(_key: string) {
|
||||
throw new Error('not supported');
|
||||
},
|
||||
async list() {
|
||||
return [];
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,3 +23,22 @@ export interface SyncStorage {
|
||||
disconnect: (reason: string) => void
|
||||
): Promise<() => void>;
|
||||
}
|
||||
|
||||
export const EmptySyncStorage: SyncStorage = {
|
||||
name: 'empty',
|
||||
pull: async () => null,
|
||||
push: async () => {},
|
||||
subscribe: async () => () => {},
|
||||
};
|
||||
|
||||
export const ReadonlyMappingSyncStorage = (map: {
|
||||
[key: string]: Uint8Array;
|
||||
}): SyncStorage => ({
|
||||
name: 'map',
|
||||
pull: async (id: string) => {
|
||||
const data = map[id];
|
||||
return data ? { data } : null;
|
||||
},
|
||||
push: async () => {},
|
||||
subscribe: async () => () => {},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user