Improve typing of Event Index Manager / Seshat

This commit is contained in:
Michael Telatynski 2021-06-19 15:37:06 +01:00
parent 958d4df957
commit be10e77704
2 changed files with 47 additions and 47 deletions

View file

@ -17,7 +17,7 @@ limitations under the License.
// The following interfaces take their names and member names from seshat and the spec // The following interfaces take their names and member names from seshat and the spec
/* eslint-disable camelcase */ /* eslint-disable camelcase */
export interface MatrixEvent { export interface IMatrixEvent {
type: string; type: string;
sender: string; sender: string;
content: {}; content: {};
@ -27,37 +27,37 @@ export interface MatrixEvent {
roomId: string; roomId: string;
} }
export interface MatrixProfile { export interface IMatrixProfile {
avatar_url: string; avatar_url: string;
displayname: string; displayname: string;
} }
export interface CrawlerCheckpoint { export interface ICrawlerCheckpoint {
roomId: string; roomId: string;
token: string; token: string;
fullCrawl?: boolean; fullCrawl?: boolean;
direction: string; direction: string;
} }
export interface ResultContext { export interface IResultContext {
events_before: [MatrixEvent]; events_before: [IMatrixEvent];
events_after: [MatrixEvent]; events_after: [IMatrixEvent];
profile_info: Map<string, MatrixProfile>; profile_info: Map<string, IMatrixProfile>;
} }
export interface ResultsElement { export interface IResultsElement {
rank: number; rank: number;
result: MatrixEvent; result: IMatrixEvent;
context: ResultContext; context: IResultContext;
} }
export interface SearchResult { export interface ISearchResult {
count: number; count: number;
results: [ResultsElement]; results: [IResultsElement];
highlights: [string]; highlights: [string];
} }
export interface SearchArgs { export interface ISearchArgs {
search_term: string; search_term: string;
before_limit: number; before_limit: number;
after_limit: number; after_limit: number;
@ -65,19 +65,19 @@ export interface SearchArgs {
room_id?: string; room_id?: string;
} }
export interface EventAndProfile { export interface IEventAndProfile {
event: MatrixEvent; event: IMatrixEvent;
profile: MatrixProfile; profile: IMatrixProfile;
} }
export interface LoadArgs { export interface ILoadArgs {
roomId: string; roomId: string;
limit: number; limit: number;
fromEvent?: string; fromEvent?: string;
direction?: string; direction?: string;
} }
export interface IndexStats { export interface IIndexStats {
size: number; size: number;
eventCount: number; eventCount: number;
roomCount: number; roomCount: number;
@ -119,13 +119,13 @@ export default abstract class BaseEventIndexManager {
* Queue up an event to be added to the index. * Queue up an event to be added to the index.
* *
* @param {MatrixEvent} ev The event that should be added to the index. * @param {MatrixEvent} ev The event that should be added to the index.
* @param {MatrixProfile} profile The profile of the event sender at the * @param {IMatrixProfile} profile The profile of the event sender at the
* time of the event receival. * time of the event receival.
* *
* @return {Promise} A promise that will resolve when the was queued up for * @return {Promise} A promise that will resolve when the was queued up for
* addition. * addition.
*/ */
async addEventToIndex(ev: MatrixEvent, profile: MatrixProfile): Promise<void> { async addEventToIndex(ev: IMatrixEvent, profile: IMatrixProfile): Promise<void> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -160,10 +160,10 @@ export default abstract class BaseEventIndexManager {
/** /**
* Get statistical information of the index. * Get statistical information of the index.
* *
* @return {Promise<IndexStats>} A promise that will resolve to the index * @return {Promise<IIndexStats>} A promise that will resolve to the index
* statistics. * statistics.
*/ */
async getStats(): Promise<IndexStats> { async getStats(): Promise<IIndexStats> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -203,13 +203,13 @@ export default abstract class BaseEventIndexManager {
/** /**
* Search the event index using the given term for matching events. * Search the event index using the given term for matching events.
* *
* @param {SearchArgs} searchArgs The search configuration for the search, * @param {ISearchArgs} searchArgs The search configuration for the search,
* sets the search term and determines the search result contents. * sets the search term and determines the search result contents.
* *
* @return {Promise<[SearchResult]>} A promise that will resolve to an array * @return {Promise<[ISearchResult]>} A promise that will resolve to an array
* of search results once the search is done. * of search results once the search is done.
*/ */
async searchEventIndex(searchArgs: SearchArgs): Promise<SearchResult> { async searchEventIndex(searchArgs: ISearchArgs): Promise<ISearchResult> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -218,12 +218,12 @@ export default abstract class BaseEventIndexManager {
* *
* This is used to add a batch of events to the index. * This is used to add a batch of events to the index.
* *
* @param {[EventAndProfile]} events The list of events and profiles that * @param {[IEventAndProfile]} events The list of events and profiles that
* should be added to the event index. * should be added to the event index.
* @param {[CrawlerCheckpoint]} checkpoint A new crawler checkpoint that * @param {[ICrawlerCheckpoint]} checkpoint A new crawler checkpoint that
* should be stored in the index which should be used to continue crawling * should be stored in the index which should be used to continue crawling
* the room. * the room.
* @param {[CrawlerCheckpoint]} oldCheckpoint The checkpoint that was used * @param {[ICrawlerCheckpoint]} oldCheckpoint The checkpoint that was used
* to fetch the current batch of events. This checkpoint will be removed * to fetch the current batch of events. This checkpoint will be removed
* from the index. * from the index.
* *
@ -231,9 +231,9 @@ export default abstract class BaseEventIndexManager {
* were already added to the index, false otherwise. * were already added to the index, false otherwise.
*/ */
async addHistoricEvents( async addHistoricEvents(
events: [EventAndProfile], events: IEventAndProfile[],
checkpoint: CrawlerCheckpoint | null, checkpoint: ICrawlerCheckpoint | null,
oldCheckpoint: CrawlerCheckpoint | null, oldCheckpoint: ICrawlerCheckpoint | null,
): Promise<boolean> { ): Promise<boolean> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -241,36 +241,36 @@ export default abstract class BaseEventIndexManager {
/** /**
* Add a new crawler checkpoint to the index. * Add a new crawler checkpoint to the index.
* *
* @param {CrawlerCheckpoint} checkpoint The checkpoint that should be added * @param {ICrawlerCheckpoint} checkpoint The checkpoint that should be added
* to the index. * to the index.
* *
* @return {Promise} A promise that will resolve once the checkpoint has * @return {Promise} A promise that will resolve once the checkpoint has
* been stored. * been stored.
*/ */
async addCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<void> { async addCrawlerCheckpoint(checkpoint: ICrawlerCheckpoint): Promise<void> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
/** /**
* Add a new crawler checkpoint to the index. * Add a new crawler checkpoint to the index.
* *
* @param {CrawlerCheckpoint} checkpoint The checkpoint that should be * @param {ICrawlerCheckpoint} checkpoint The checkpoint that should be
* removed from the index. * removed from the index.
* *
* @return {Promise} A promise that will resolve once the checkpoint has * @return {Promise} A promise that will resolve once the checkpoint has
* been removed. * been removed.
*/ */
async removeCrawlerCheckpoint(checkpoint: CrawlerCheckpoint): Promise<void> { async removeCrawlerCheckpoint(checkpoint: ICrawlerCheckpoint): Promise<void> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
/** /**
* Load the stored checkpoints from the index. * Load the stored checkpoints from the index.
* *
* @return {Promise<[CrawlerCheckpoint]>} A promise that will resolve to an * @return {Promise<[ICrawlerCheckpoint]>} A promise that will resolve to an
* array of crawler checkpoints once they have been loaded from the index. * array of crawler checkpoints once they have been loaded from the index.
*/ */
async loadCheckpoints(): Promise<[CrawlerCheckpoint]> { async loadCheckpoints(): Promise<ICrawlerCheckpoint[]> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
@ -286,11 +286,11 @@ export default abstract class BaseEventIndexManager {
* @param {string} args.direction The direction to which we should continue * @param {string} args.direction The direction to which we should continue
* loading events from. This is used only if fromEvent is used as well. * loading events from. This is used only if fromEvent is used as well.
* *
* @return {Promise<[EventAndProfile]>} A promise that will resolve to an * @return {Promise<[IEventAndProfile]>} A promise that will resolve to an
* array of Matrix events that contain mxc URLs accompanied with the * array of Matrix events that contain mxc URLs accompanied with the
* historic profile of the sender. * historic profile of the sender.
*/ */
async loadFileEvents(args: LoadArgs): Promise<[EventAndProfile]> { async loadFileEvents(args: ILoadArgs): Promise<IEventAndProfile[]> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }

View file

@ -28,7 +28,7 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
import { sleep } from "../utils/promise"; import { sleep } from "../utils/promise";
import SettingsStore from "../settings/SettingsStore"; import SettingsStore from "../settings/SettingsStore";
import { SettingLevel } from "../settings/SettingLevel"; import { SettingLevel } from "../settings/SettingLevel";
import {CrawlerCheckpoint, LoadArgs, SearchArgs} from "./BaseEventIndexManager"; import { ICrawlerCheckpoint, ILoadArgs, ISearchArgs } from "./BaseEventIndexManager";
// The time in ms that the crawler will wait loop iterations if there // The time in ms that the crawler will wait loop iterations if there
// have not been any checkpoints to consume in the last iteration. // have not been any checkpoints to consume in the last iteration.
@ -45,9 +45,9 @@ interface ICrawler {
* Event indexing class that wraps the platform specific event indexing. * Event indexing class that wraps the platform specific event indexing.
*/ */
export default class EventIndex extends EventEmitter { export default class EventIndex extends EventEmitter {
private crawlerCheckpoints: CrawlerCheckpoint[] = []; private crawlerCheckpoints: ICrawlerCheckpoint[] = [];
private crawler: ICrawler = null; private crawler: ICrawler = null;
private currentCheckpoint: CrawlerCheckpoint = null; private currentCheckpoint: ICrawlerCheckpoint = null;
public async init() { public async init() {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
@ -111,14 +111,14 @@ export default class EventIndex extends EventEmitter {
const timeline = room.getLiveTimeline(); const timeline = room.getLiveTimeline();
const token = timeline.getPaginationToken("b"); const token = timeline.getPaginationToken("b");
const backCheckpoint: CrawlerCheckpoint = { const backCheckpoint: ICrawlerCheckpoint = {
roomId: room.roomId, roomId: room.roomId,
token: token, token: token,
direction: "b", direction: "b",
fullCrawl: true, fullCrawl: true,
}; };
const forwardCheckpoint: CrawlerCheckpoint = { const forwardCheckpoint: ICrawlerCheckpoint = {
roomId: room.roomId, roomId: room.roomId,
token: token, token: token,
direction: "f", direction: "f",
@ -668,13 +668,13 @@ export default class EventIndex extends EventEmitter {
/** /**
* Search the event index using the given term for matching events. * Search the event index using the given term for matching events.
* *
* @param {SearchArgs} searchArgs The search configuration for the search, * @param {ISearchArgs} searchArgs The search configuration for the search,
* sets the search term and determines the search result contents. * sets the search term and determines the search result contents.
* *
* @return {Promise<[SearchResult]>} A promise that will resolve to an array * @return {Promise<[SearchResult]>} A promise that will resolve to an array
* of search results once the search is done. * of search results once the search is done.
*/ */
public async search(searchArgs: SearchArgs) { public async search(searchArgs: ISearchArgs) {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
return indexManager.searchEventIndex(searchArgs); return indexManager.searchEventIndex(searchArgs);
} }
@ -709,7 +709,7 @@ export default class EventIndex extends EventEmitter {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
const loadArgs: LoadArgs = { const loadArgs: ILoadArgs = {
roomId: room.roomId, roomId: room.roomId,
limit: limit, limit: limit,
}; };