// Copyright (c) Dolittle. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. import { Guid } from '@dolittle/rudiments'; import { Constructor } from '@dolittle/types'; import { Generation } from '@dolittle/sdk.artifacts'; import { EventType, EventTypeIdLike, ScopeId } from '@dolittle/sdk.events'; import { ProjectionCallback } from '../ProjectionCallback'; import { CopyToMongoDBCallback } from './Copies/CopyToMongoDBCallback'; import { KeySelectorBuilderCallback } from './KeySelectorBuilderCallback'; import { ProjectionAliasLike } from '../ProjectionAlias'; /** * Defines a builder for building a projection for a read model from method callbacks. * @template T The type of the projection read model. */ export abstract class IProjectionBuilderForReadModel { /** * Add an on method for handling the event. * @template TEvent Type of event. * @param {Constructor} type - The type of event. * @param {KeySelectorBuilderCallback} keySelectorCallback - Callback for building key selector. * @param {ProjectionCallback} callback - Callback to call for each event. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract on(type: Constructor, keySelectorCallback: KeySelectorBuilderCallback, callback: ProjectionCallback): IProjectionBuilderForReadModel; /** * Add an on method for handling the event. * @param {EventType} eventType - The identifier of the event. * @param {KeySelectorBuilderCallback} keySelectorCallback - Callback for building key selector. * @param {ProjectionCallback} callback - Callback to call for each event. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract on(eventType: EventType, keySelectorCallback: KeySelectorBuilderCallback, callback: ProjectionCallback): IProjectionBuilderForReadModel; /** * Add an on method for handling the event. * @param {EventTypeIdLike} eventType - The identifier of the event. * @param {KeySelectorBuilderCallback} keySelectorCallback - Callback for building key selector. * @param {ProjectionCallback} callback - Callback to call for each event. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract on(eventTypeId: EventTypeIdLike, keySelectorCallback: KeySelectorBuilderCallback, callback: ProjectionCallback): IProjectionBuilderForReadModel; /** * Add an on method for handling the event. * @param {EventTypeIdLike} eventType - The identifier of the event. * @param {Generation | number} generation - The generation of the event type. * @param {KeySelectorBuilderCallback} keySelectorCallback - Callback for building key selector. * @param {ProjectionCallback} method - Callback to call for each event. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract on(eventTypeId: EventTypeIdLike, generation: Generation | number, keySelectorCallback: KeySelectorBuilderCallback, callback: ProjectionCallback): IProjectionBuilderForReadModel; /** * Defines the projection to operate in a specific {@link ScopeId}. * @param {ScopeId | Guid | string} scopeId - Scope the projection operates in. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract inScope(scopeId: ScopeId | Guid | string): IProjectionBuilderForReadModel; /** * Defines an alias for the projection. * @param {ProjectionAliasLike} alias - The projection alias. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract withAlias(alias: ProjectionAliasLike): IProjectionBuilderForReadModel; /** * Configures the projection to write copies of read models to a MongoDB collection. * @param {CopyToMongoDBCallback} [callback] - An optional callback to use to configure the read model copies. * @returns {IProjectionBuilderForReadModel} The builder for continuation. */ abstract copyToMongoDB(callback?: CopyToMongoDBCallback): IProjectionBuilderForReadModel; }