import { ReplicatedData } from './replicated-data'; import { GrpcClientLookup } from './grpc-util'; import { Entity, EntityOptions, PreStartSettings } from './kalix'; import { EntityCommandContext, CommandReply } from './command'; export { ReplicatedData }; export { ReplicatedCounter, ReplicatedSet, ReplicatedRegister, ReplicatedMap, ReplicatedCounterMap, ReplicatedRegisterMap, ReplicatedMultiMap, Vote, Clock, Clocks, } from './replicated-data'; /** * Context for a Replicated Entity command handler. * * @typeParam State - the type of {@link ReplicatedData} state * * @public */ export declare type ReplicatedEntityCommandContext = ReplicatedEntity.CommandContext; /** * Context that allows managing a Replicated Entity's state. * * @typeParam State - the type of {@link ReplicatedData} state * * @public */ export declare type StateManagementContext = ReplicatedEntity.StateContext; /** @public */ export declare namespace ReplicatedEntity { /** * Context for a Replicated Entity command handler. * * @typeParam State - the type of {@link ReplicatedData} state */ interface CommandContext extends StateContext, EntityCommandContext { } /** * Context that allows managing a Replicated Entity's state. * * @typeParam State - the type of {@link ReplicatedData} state */ interface StateContext { /** * The Replicated Data state for a Replicated Entity. * * @remarks * It may only be set once, if it's already set, an error will be thrown. */ state: State; /** * Delete this Replicated Entity. */ delete(): void; } /** * A command handler callback. * * @typeParam State - the type of {@link ReplicatedData} state * @param command - The command message, this will be of the type of the gRPC service call input type * @param context - The command context * @returns The message to reply with, which must match the gRPC service call output type for this command. */ type CommandHandler = (command: any, context: CommandContext) => Promise | CommandReply; /** * Replicated entity command handlers. * * @typeParam State - the type of {@link ReplicatedData} state */ type CommandHandlers = { [commandName: string]: CommandHandler; }; /** * A state set handler callback. * * @remarks * * This is invoked whenever a new state is set on the Replicated Entity, to allow the state to be * enriched with domain specific properties and methods. This may be due to the state being set * explicitly from a command handler on the command context, or implicitly as the default value, * or implicitly when a new state is received from the proxy. * * @typeParam State - the type of {@link ReplicatedData} state * @param state - The Replicated Data state that was set * @param entityId - The id of the entity */ type OnStateSetCallback = (state: State, entityId: string) => void; /** * A callback that is invoked to create a default value if the Kalix proxy doesn't send an existing one. * * @typeParam State - the type of {@link ReplicatedData} state * @param entityId - The id of the entity * @returns The default value to use for this entity */ type DefaultValueCallback = (entityId: string) => State | null; /** * Options for creating a Replicated Entity. */ interface Options extends EntityOptions { } } /** * Replicated Entity. * * @typeParam State - the type of {@link ReplicatedData} state * * @public */ export declare class ReplicatedEntity implements Entity { readonly serviceName: string; readonly service: protobuf.Service; readonly options: Required; clients?: GrpcClientLookup; /** * The command handlers. * * @remarks * The names of the properties must match the names of the service calls specified in the gRPC descriptor for this * Replicated Entity service. */ commandHandlers: ReplicatedEntity.CommandHandlers; /** * A callback that is invoked whenever the Replicated Data state is set for this Replicated Entity. * * @remarks * * This is invoked whenever a new Replicated Data state is set on the Replicated Entity, to allow the state to be * enriched with domain specific properties and methods. This may be due to the state being set explicitly from a * command handler on the command context, or implicitly as the default value, or implicitly when a new state is * received from the proxy. */ onStateSet: ReplicatedEntity.OnStateSetCallback; /** * A callback that is invoked to create a default value if the Kalix proxy doesn't send an existing one. */ defaultValue: ReplicatedEntity.DefaultValueCallback; /** * Create a Replicated Entity. * * @param desc - The file name of a protobuf descriptor or set of descriptors containing the Replicated Entity service * @param serviceName - The fully qualified name of the gRPC service that this Replicated Entity implements * @param entityType - The entity type name, used to namespace entities of different Replicated Data types in the same service * @param options - The options for this entity */ constructor(desc: string | string[], serviceName: string, entityType: string, options?: ReplicatedEntity.Options); preStart(settings: PreStartSettings): void; lookupType(messageType: string): protobuf.Type; }