// Copyright (c) Cratis. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. import { PropertyAccessor } from '@cratis/fundamentals'; import { IChildrenBuilder } from './IChildrenBuilder.js'; import { IFromBuilder } from './IFromBuilder.js'; import { IFromEveryBuilder } from './IFromEveryBuilder.js'; import { IJoinBuilder } from './IJoinBuilder.js'; import { INestedBuilder } from './INestedBuilder.js'; import { IRemovedWithBuilder } from './IRemovedWithBuilder.js'; import { IRemovedWithJoinBuilder } from './IRemovedWithJoinBuilder.js'; /** * Defines the core builder interface for configuring a projection. * @template TReadModel - The read model type this projection produces. * @template TBuilder - The concrete builder type for fluent return. */ export interface IProjectionBuilder { /** * Enables automatic property mapping by naming convention. * @returns This builder for fluent chaining. */ autoMap(): TBuilder; /** * Disables automatic property mapping by naming convention. * @returns This builder for fluent chaining. */ noAutoMap(): TBuilder; /** * Provides initial property values for newly created read model instances. * @param initialValueProvider - A factory function that returns the initial values. * @returns This builder for fluent chaining. */ withInitialValues(initialValueProvider: () => TReadModel): TBuilder; /** * Configures a projection from a specific event type. * @param eventType - The event class constructor. * @param builderCallback - Optional callback for configuring property mappings. * @returns This builder for fluent chaining. */ from(eventType: new (...args: any[]) => TEvent, builderCallback?: (builder: IFromBuilder) => void): TBuilder; /** * Configures a join projection from a specific event type. * @param eventType - The event class constructor. * @param builderCallback - Optional callback for configuring the join mappings. * @returns This builder for fluent chaining. */ join(eventType: new (...args: any[]) => TEvent, builderCallback?: (builder: IJoinBuilder) => void): TBuilder; /** * Configures property mappings that apply to every projected event type. * @param builderCallback - Callback for configuring the fromEvery mappings. * @returns This builder for fluent chaining. */ fromEvery(builderCallback: (builder: IFromEveryBuilder) => void): TBuilder; /** * Specifies the event type that causes this read model instance to be removed. * @param eventType - The event class constructor. * @param builderCallback - Optional callback for configuring the removal behavior. * @returns This builder for fluent chaining. */ removedWith(eventType: new (...args: any[]) => TEvent, builderCallback?: (builder: IRemovedWithBuilder) => void): TBuilder; /** * Specifies the joined event type that causes this read model instance to be removed. * @param eventType - The event class constructor. * @param builderCallback - Optional callback for configuring the removal behavior. * @returns This builder for fluent chaining. */ removedWithJoin(eventType: new (...args: any[]) => TEvent, builderCallback?: (builder: IRemovedWithJoinBuilder) => void): TBuilder; /** * Configures a child collection projection on the specified read model property. * @param targetPropertyAccessor - Accessor for the collection property on the read model. * @param builderCallback - Callback for configuring the children projection. * @returns This builder for fluent chaining. */ children( targetPropertyAccessor: PropertyAccessor, builderCallback: (builder: IChildrenBuilder) => void ): TBuilder; /** * Configures a nested single-object projection on the specified read model property. * @param targetPropertyAccessor - Accessor for the nested property on the read model. * @param builderCallback - Callback for configuring the nested projection. * @returns This builder for fluent chaining. */ nested( targetPropertyAccessor: PropertyAccessor, builderCallback: (builder: INestedBuilder) => void ): TBuilder; }