import { Component, ComponentOptions, PreStartSettings } from './kalix'; import { Metadata } from './metadata'; /** @public */ export declare namespace View { /** * Context for a view update event. */ interface UpdateHandlerContext { /** * The view id. */ viewId: string; /** * The event subject. */ eventSubject?: string; /** * The update command name. */ commandName: string; /** * Metadata for the event. */ metadata: Metadata; } /** * A handler for transforming an incoming event and the previous view state into a new state * * @typeParam State - the type of the stored state * @typeParam Events - the type of all update events, based on the gRPC method input type * @param event - The event, this will be of the type of the gRPC event handler input type * @param state - The previous view state or 'undefined' if no previous state was stored * @param context - The view handler context * @returns The state to store in the view or undefined to not update/store state for the event */ type Handler = Events extends any ? (event: Events, state: State | undefined, context: UpdateHandlerContext) => State | undefined : never; /** * View update handlers. * * @remarks * The names of the properties must match the names of all the view methods specified in the gRPC * descriptor. * * @typeParam State - the type of the stored state * @typeParam Events - the type of all update events, based on the gRPC method input types */ type Handlers = { [methodName: string]: Handler; }; /** * Options for a view. */ interface Options extends ComponentOptions { /** * The id for the view, used for persisting the view. * * @defaultValue Defaults to the service name */ viewId?: string; } } /** * View. * * @typeParam State - the type of the stored state * @typeParam Events - the type of all update events, based on the gRPC method input types * * @public */ export declare class View = View.Handlers> implements Component { readonly serviceName: string; readonly service: protobuf.Service; readonly options: Required; readonly clients: undefined; /** * View update handlers. * * @remarks * The names of the properties must match the names of all the view methods specified in the gRPC * descriptor. */ updateHandlers?: UpdateHandlers; /** * Create a new view. * * @param desc - A descriptor or list of descriptors to parse, containing the service to serve * @param serviceName - The fully qualified name of the service that provides this interface * @param options - The options for this view */ constructor(desc: string | string[], serviceName: string, options?: View.Options); preStart(settings: PreStartSettings): void; lookupType(messageType: string): protobuf.Type; /** * Set the update handlers of the view. * * @remarks * Only used for updates where event transformation is enabled through * `"transform_updates: true"` in the grpc descriptor. * * @param handlers - The handler callbacks * @returns This view */ setUpdateHandlers(handlers: UpdateHandlers): View; }