more api cleanup

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-08-18 14:11:45 +02:00
parent e195112c5c
commit 3f739be9d9
88 changed files with 358 additions and 594 deletions
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
DocumentDecoratorFactory,
DocumentTypeInfo,
@@ -38,12 +39,12 @@ export class IndexBuilder {
private searchEngine: SearchEngine;
private logger: Logger;
constructor({ logger, searchEngine }: IndexBuilderOptions) {
constructor(options: IndexBuilderOptions) {
this.collators = {};
this.decorators = {};
this.documentTypes = {};
this.logger = logger;
this.searchEngine = searchEngine;
this.logger = options.logger;
this.searchEngine = options.searchEngine;
}
/**
@@ -64,7 +65,9 @@ export class IndexBuilder {
* Makes the index builder aware of a collator that should be executed at the
* given refresh interval.
*/
addCollator({ factory, schedule }: RegisterCollatorParameters): void {
addCollator(options: RegisterCollatorParameters): void {
const { factory, schedule } = options;
this.logger.info(
`Added ${factory.constructor.name} collator factory for type ${factory.type}`,
);
@@ -82,7 +85,8 @@ export class IndexBuilder {
* the decorator, it will be applied to documents from all known collators,
* otherwise it will only be applied to documents of the given types.
*/
addDecorator({ factory }: RegisterDecoratorParameters): void {
addDecorator(options: RegisterDecoratorParameters): void {
const { factory } = options;
const types = factory.types || ['*'];
this.logger.info(
`Added decorator ${factory.constructor.name} to types ${types.join(
+5 -3
View File
@@ -43,8 +43,8 @@ export class Scheduler {
private abortController: AbortController;
private isRunning: boolean;
constructor({ logger }: { logger: Logger }) {
this.logger = logger;
constructor(options: { logger: Logger }) {
this.logger = options.logger;
this.schedule = {};
this.abortController = new AbortController();
this.isRunning = false;
@@ -55,7 +55,9 @@ export class Scheduler {
* When running the tasks, the scheduler waits at least for the time specified
* in the interval once the task was completed, before running it again.
*/
addToSchedule({ id, task, scheduledRunner }: ScheduleTaskParameters) {
addToSchedule(options: ScheduleTaskParameters) {
const { id, task, scheduledRunner } = options;
if (this.isRunning) {
throw new Error(
'Cannot add task to schedule that has already been started.',
@@ -43,7 +43,7 @@ type LunrResultEnvelope = {
};
/**
* Translator repsonsible for translating search term and filters to a query that the Lunr Search Engine understands.
* Translator responsible for translating search term and filters to a query that the Lunr Search Engine understands.
* @public
*/
export type LunrQueryTranslator = (query: SearchQuery) => ConcreteLunrQuery;
@@ -59,8 +59,8 @@ export class LunrSearchEngine implements SearchEngine {
protected highlightPreTag: string;
protected highlightPostTag: string;
constructor({ logger }: { logger: Logger }) {
this.logger = logger;
constructor(options: { logger: Logger }) {
this.logger = options.logger;
this.docStore = {};
const uuidTag = uuid();
this.highlightPreTag = `<${uuidTag}>`;