import { Actyx, ActyxOpts, AppManifest, CancelSubscription, Metadata, NodeId, NodeInfo, PendingEmission, TaggedEvent, Tags, TestEvent, TimeInjector, Where } from '@actyx/sdk'; import { PondState } from './pond-state'; import { SplashState, WaitForSwarmConfig } from './splashState'; import { Fish, FishErrorReporter, ObserveAllOpts, StateEffect } from './types'; /** Advanced configuration options for the Pond. * @public */ export declare type PondOptions = { /** * Callback that is invoked whenever Fish execution encounters an error. * If none is supplied, errors will be logged to the console. */ fishErrorReporter?: FishErrorReporter; }; /** Information concerning the running Pond. * @public */ export declare type PondInfo = { nodeId: NodeId; }; /** Pending command application. * @public */ export declare type PendingCommand = { subscribe: (whenEmitted: () => void) => void; toPromise: () => Promise; }; /** Parameter object for the `Pond.getNodeConnectivity` call. * @public */ export declare type GetNodeConnectivityParams = { callback: (newState: unknown) => void; specialSources?: NodeId[]; }; /** Parameter object for the `Pond.waitForSwarmSync` call. * @public */ export declare type WaitForSwarmSyncParams = WaitForSwarmConfig & { onSyncComplete: () => void; onProgress?: (newState: SplashState) => void; }; /** * Main interface for interaction with the Actyx event system. * New instances are created via `Pond.default()` or `Pond.of(options)`. * Acquire a Pond for testing (which uses a simulated clean Event Store) via `Pond.test()`. * @public */ export declare type Pond = { /** * Emit a single event directly. * * @typeParam E - Type of the event payload. If your tags are statically declared, * their type will be checked against the payload’s type. * * @param tags - Tags to attach to the event. E.g. `Tags('myTag', 'myOtherTag')` * @param event - The event itself. * @returns A `PendingEmission` object that can be used to register * callbacks with the emission’s completion. * * @deprecated Use `publish` instead, and always await the Promise. */ emit(tags: Tags, event: E): PendingEmission; /** * Publish any number of events. * * @param events - Events to publish. Use `Tag('foo').apply(event)` to create an array of `TaggedEvent`. * * @returns A Promise that resolves to the emitted event’s metadata. */ publish(event: TaggedEvent): Promise; publish(events: TaggedEvent[]): Promise; /** * Observe the current state of a Fish. * * Caching is done based on the `fishId` inside the `fish`, i.e. if a fish with the included * `fishId` is already known, that other Fish’s ongoing aggregation will be used instead of * starting a new one. * * @param fish - Complete Fish information. * @param callback - Function that will be called whenever a new state becomes available. * @param stoppedByError - Function that will be called when one of the Fish’s functions throws an error. * A Fish will always stop emitting further states after errors, even if no `stoppedByError` argument is passed. * @returns A function that can be called in order to cancel the subscription. */ observe(fish: Fish, callback: (newState: S) => void, stoppedByError?: (err: unknown) => void): CancelSubscription; /** * Read the current state of a Fish. * * Caching is done based on the `fishId` inside the `fish`, i.e. if a fish with the included * `fishId` is already known, that other Fish’s ongoing aggregation will be used instead of * starting a new one. * * @param fish - Complete Fish information. * * @returns A Promise that resolves to the Fish’s latest known state. If the Fish was stopped due to an error, the Promise will reject with that error. */ currentState(fish: Fish): Promise; /** * Create Fish from events and observe them all. * Note that if a Fish created from some event f0 will also observe events earlier than f0, if they are selected by `where` * * @typeParam F - Type of the events used to initialize Fish. * @typeParam S - Type of the observed Fish’s state. * * @param seedEventsSelector - A `Where` object identifying the seed events to start Fish from * @param makeFish - Factory function to create a Fish with state `S` from an event of type `F`. * If Fish with same FishId are created by makeFish, these Fish must be identical! * `undefined` may be returned to indicate the given seed event should not be converted to a Fish at all. * @param opts - Optional arguments regarding caching and expiry * @param callback - Function that will be called with the array of states whenever the set of Fish * changes or any of the contained Fish’s state changes. * * @returns A function that can be called in order to cancel the subscription. * * @beta */ observeAll(seedEventsSelector: Where, makeFish: (seedEvent: ESeed) => Fish | undefined, opts: ObserveAllOpts, callback: (states: S[]) => void): CancelSubscription; /** * Find the event selected by `firstEvent`, and start a Fish from it. * It is legal for `firstEvent` to actually select multiple events; * however, `makeFish` must yield the same Fish no matter one is passed in. * * @typeParam F - Type of the initial event. * @typeParam S - Type of the observed Fish’s state. * * @param seedEventSelector - A `Where` object identifying the seed event * @param makeFish - Factory function to create the Fish with state `S` from the event of type `F`. * The Fish is able to observe events earlier than the first event. * @param callback - Function that will be called with the Fish’s state `S`. * As long as the first event does not exist, this callback will also not be called. * * @returns A function that can be called in order to cancel the subscription. * * @beta */ observeOne(seedEventSelector: Where, makeFish: (seedEvent: ESeed) => Fish, callback: (newState: S) => void, stoppedByError?: (err: unknown) => void): CancelSubscription; /** * Run a `StateEffect` against currently known local state of Fish. Emit events based on it by * calling the `enqueue` function passed into the invocation of your effect. Every subsequent * invocation of `run` for the same Fish is guaranteed to see all events previously enqueued by * effects on that Fish already applied to the state. (Local serialisation guarantee.) * * In regards to other nodes or Fishes, there are no serialisation guarantees. * * @typeParam S - State of the Fish, input value to the effect. * @typeParam EWrite - Event type(s) the effect may emit. * * @param fish - Complete Fish information. * @param effect - Function to enqueue new events based on state. * @returns A `PendingEmission` object that can be used to register callbacks with the effect’s completion. */ run(fish: Fish, fn: StateEffect): PendingCommand; /** * Install a StateEffect that will be applied automatically whenever the `Fish`’s State has changed. * Every application will see the previous one’s resulting Events applied to the State already, if applicable; * but any number of intermediate States may have been skipped between two applications. * * In regards to other nodes or Fishes, there are no serialisation guarantees. * * The effect can be uninstalled by calling the returned `CancelSubscription`. * * @typeParam S - State of the Fish, input value to the effect. * @typeParam EWrite - Event type(s) the effect may emit. * * @param fish - Complete Fish information. * @param effect - Function that decides whether to enqueue new events based on the current state. * @param autoCancel - Condition on which the automatic effect will be cancelled -- state on which `autoCancel` returns `true` * will be the first state the effect is *not* applied to anymore. Keep in mind that not all intermediate * states will be seen by this function. * @returns A `CancelSubscription` object that can be used to cancel the automatic effect. */ keepRunning(fish: Fish, fn: StateEffect, autoCancel?: (state: S) => boolean): CancelSubscription; /** * Dispose of this Pond, stopping all underlying async operations. */ dispose(): void; /** * Information about the current pond */ info(): PondInfo; /** * Obtain information on the Actyx node. In order to save some cycles, and because the information * doesn’t change all that quickly, please provide a time parameter that matches your app’s * freshness requirements — for human consumption a couple hundred milliseconds is good enough. * * The underlying API endpoint has been added in Actyx 2.5.0, earlier versions report dummy data. */ nodeInfo(maxAgeMillis: number): Promise; /** * Register a callback invoked whenever the Pond’s state changes. * The `PondState` is a general description of activity within the Pond internals. */ getPondState(callback: (newState: PondState) => void): CancelSubscription; /** * Wait for the node to get in sync with the swarm. * It is strongly recommended that any interaction with the Pond is delayed until the onSyncComplete callback has been notified. * To obtain progress information about the sync, the onProgress callback can be supplied. */ waitForSwarmSync(params: WaitForSwarmSyncParams): void; /** * Get an object that offers a number of functions related purely to events (no Fish). */ events(): Actyx; }; /** A Pond with extensions for testing. * @public */ export declare type TestPond = Pond & { directlyPushEvents: (events: TestEvent[]) => void; }; /** Extended options for TestPond. * @public */ export declare type TestPondOptions = PondOptions & { timeInjector?: TimeInjector; }; /** Static methods for constructing Pond instances. * @public */ export declare const Pond: { /** Start Pond with default parameters. * @public */ default: (manifest: AppManifest) => Promise; /** Start Pond with custom parameters. * @public */ of: (manifest: AppManifest, connectionOpts: ActyxOpts, opts: PondOptions) => Promise; /** Start Pond from provided Actyx SDK instance. * @public */ from: (actyx: Actyx, opts: PondOptions) => Pond; /** * Get a Pond instance that runs a simulated store locally * whose contents can be manually modified. * @public */ test: (opts?: TestPondOptions | undefined) => TestPond; };