@casual-simulation/aux-common
Version:
Common library for AUX projects
90 lines • 2.34 kB
TypeScript
import type { Bot } from './Bot';
import type { Observable } from 'rxjs';
/**
* Defines a union type for bot index events.
*/
export type BotIndexEvent = BotTagAddedEvent | BotTagRemovedEvent | BotTagUpdatedEvent;
/**
* Defines an event that indicates a bot has added a value for a tag.
*/
export interface BotTagAddedEvent {
type: 'bot_tag_added';
bot: Bot;
tag: string;
}
/**
* Defines an event that indicates a bot has removed the value for a tag.
*/
export interface BotTagRemovedEvent {
type: 'bot_tag_removed';
bot: Bot;
oldBot?: Bot;
tag: string;
}
/**
* Defines an event that indicates a bot has updated the value for a tag.
*/
export interface BotTagUpdatedEvent {
type: 'bot_tag_updated';
bot: Bot;
oldBot: Bot;
tag: string;
}
/**
* Defines an index that is optimized for looking up bots by their tags.
*/
export declare class BotIndex {
/**
* The index events.
*/
private _events;
/**
* A map of tags to bot IDs.
*/
private _tagMap;
/**
* A map of Bot IDs to bots.
*/
private _botMap;
private _batch;
get events(): Observable<BotIndexEvent[]>;
initialEvents(): BotTagAddedEvent[];
constructor();
/**
* Finds a list of bots that have the given tag.
* @param tag The tag.
*/
findBotsWithTag(tag: string): Bot[];
/**
* Batches all the index events during the given function.
* @param func The function.
*/
batch(func: () => void): BotIndexEvent[];
/**
* Adds the given bots to the index.
* @param bots The bots to add.
*/
addBots(bots: Bot[]): BotIndexEvent[];
/**
* Updates the given bots in the index by adding new tags and removing old tags.
* @param bots The bot that were updated.
*/
updateBots(bots: BotIndexUpdate[]): BotIndexEvent[];
/**
* Removes the given bots from the index.
* @param botIds The bots that were removed.
*/
removeBots(botIds: string[]): BotIndexEvent[];
/**
* Watches the given tag for changes.
* @param tag The tag to watch.
*/
watchTag(tag: string): Observable<BotIndexEvent[]>;
private _issueEvents;
private _botList;
}
export interface BotIndexUpdate {
bot: Bot;
tags: Set<string>;
}
//# sourceMappingURL=BotIndex.d.ts.map