mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
42 lines
908 B
TypeScript
42 lines
908 B
TypeScript
import type { Document } from './document';
|
|
import type { Schema } from './schema';
|
|
import type { Searcher, Subscriber } from './searcher';
|
|
|
|
export interface Index<S extends Schema>
|
|
extends IndexReader<S>,
|
|
Searcher<S>,
|
|
Subscriber<S> {
|
|
write(): Promise<IndexWriter<S>>;
|
|
|
|
clear(): Promise<void>;
|
|
}
|
|
|
|
export interface IndexWriter<S extends Schema>
|
|
extends IndexReader<S>,
|
|
Searcher<S> {
|
|
insert(document: Document<S>): void;
|
|
|
|
put(document: Document<S>): void;
|
|
|
|
delete(id: string): void;
|
|
|
|
// TODO(@eyhn)
|
|
// deleteByQuery(query: Query<S>): void;
|
|
|
|
commit(): Promise<void>;
|
|
|
|
rollback(): void;
|
|
}
|
|
|
|
export interface IndexReader<S extends Schema> {
|
|
get(id: string): Promise<Document<S> | null>;
|
|
|
|
getAll(ids?: string[]): Promise<Document<S>[]>;
|
|
|
|
has(id: string): Promise<boolean>;
|
|
}
|
|
|
|
export interface IndexStorage {
|
|
getIndex<S extends Schema>(name: string, schema: S): Index<S>;
|
|
}
|