import { Lamport, Metadata, Milliseconds, NodeId, StateWithProvenance, TaggedTypedEvent, Tags, Timestamp, Where } from '@actyx/sdk'; import * as t from 'io-ts'; import { Pond } from '.'; export declare type Semantics = string; export declare const Semantics: { of(name: string): Semantics; jelly: (s: string) => Semantics; isJelly: (s: Semantics) => boolean; internal: (s: string) => Semantics; isInternal: (s: Semantics) => boolean; none: string; FromString: t.Type; }; export declare type FishName = string; export declare const FishName: { of: (s: string) => FishName; none: string; FromString: t.Type; }; /** * The source of an event stream: a single localized fish instance * characterised by its semantic name, instance name, pond sourceId. */ export declare type Source = { semantics: Semantics; name: FishName; sourceId: NodeId; }; export declare type Envelope = { readonly source: Source; readonly lamport: Lamport; readonly timestamp: Timestamp; readonly payload: E; }; export declare type SnapshotFormat = { /** * This number must be increased whenever: * * - code changes are made that affect the computed private state * - private state type definition is changed * - subscription set is changed * * The version number may remain the same in those rare cases where the new * code will seamlessly work with the old snapshots, or if the deserialize * function recognizes old snapshot format and converts them to the new one. */ version: number; /** * This function is used to transform the private state into an object that * can be serialized using `JSON.stringify()`. In many cases this can be the * identity function. Please note that while e.g. immutable Map serializes * itself into json automatically, you should still explicitly call `.toJS()` * in case the serialization is something else than JSON.stringify(), like * e.g. CBOR encoding or storing in indexeddb. * * In case of function objects within the private state this needs to ensure * that the functions can be properly recreated by persisting the values * that are captured by the closures. */ serialize: (state: S) => Serialized; /** * A snapshot comes back from the store as the JS object that `serialize` * produced, and this function needs to restore it into a proper private * state. Please note that while e.g. immutable Map serializes to a proper * object by itself, deserialization does NOT yield an immutable Map but * just a plain object, so `deserialize` needs to use `Map(obj)` * constructor function. * * In case of a closure, it can be recreated by bringing the needed values * into scope and creating an arrow function: * * const { paramA, paramB } = (blob as any).some.property * return { myFunc: (x, y) => x * paramA + y * paramB } */ deserialize: (blob: Serialized) => S; }; export declare const SnapshotFormat: { identity: (version: number) => SnapshotFormat; }; export declare type TaggedIndex = { i: number; readonly tag: string; readonly persistAsLocalSnapshot: boolean; }; export declare const TaggedIndex: { ord: import("fp-ts/lib/Ord").Ord; }; export declare type CachedState = { readonly state: StateWithProvenance; readonly finalIncludedEvent: Event; }; export declare type StatePointer = TaggedIndex & CachedState; /** * Combine the existing ("old") state and next event into a new state. * The returned value may be something completely new, or a mutated version of the input state. * @public */ export declare type Reduce = (state: S, event: E, metadata: Metadata) => S; /** * A function indicating events which completely determine the state. * Any event for which isReset returns true will be applied to the initial state, all earlier events discarded. * @public */ export declare type IsReset = (event: E, metadata: Metadata) => boolean; /** * Unique identifier for a fish. * @public */ export declare type FishId = { entityType: string; name: string; version: number; }; /** * FishId associated functions. * @public */ export declare const FishId: { /** * Create a FishId from three components. * * @param entityType - A general description for the class of thing the Fish represents, e.g. 'robot' * @param name - Concrete name of the represented thing, e.g. 'superAssembler2000' * @param version - Version of the underlying code. Must be increased whenever the Fish’s underlying logic or event selection changes. * @returns A FishId. */ of: (entityType: string, name: string, version: number) => { entityType: string; name: string; version: number; }; canonical: (v: FishId) => string; }; /** Indicate in-process (nonpersistent) Caching. * @beta */ export declare type InProcessCaching = { type: 'in-process'; key: string; }; /** Indicator for disabled caching of pond.observeAll(). * @beta */ export declare type NoCaching = { readonly type: 'none'; }; /** Caching indicator for pond.observeAll(). * @beta */ export declare type Caching = NoCaching | InProcessCaching; export declare type EnabledCaching = InProcessCaching; /** Caching related functions * @beta */ export declare const Caching: { none: { type: "none"; }; isEnabled: (c: Caching | undefined) => c is InProcessCaching; inProcess: (key: string) => Caching; }; /** Optional parameters to pond.observeAll * @beta */ export declare type ObserveAllOpts = Partial<{ /** * How to cache the known set of Fish. * Defaults to no caching, i.e. the set will be rebuilt from events on every invocation. */ caching: Caching; /** Fish expires from the set of 'all' when its first event reaches a certain age */ expireAfterSeed: Milliseconds; /** * @deprecated Renamed to `expireAfterSeed` */ expireAfterFirst: Milliseconds; }>; /** * A `Fish` describes an ongoing aggregration (fold) of events of type `E` into state of type `S`. * A Fish always sees events in the correct order, even though event delivery on Actyx is only eventually consistent: * To this effect, arrival of an hitherto unknown event "from the past" will cause a replay of the aggregation * from an earlier state, instead of passing that event to the Fish out of order. * @public */ export declare type Fish = { /** * Selection of events to aggregate in this Fish. * You may specify plain strings inline: `where: Tags('my', 'tag', 'selection')` (which requires all three tags) * Or refer to typed static tags: `where: myFirstTag.and(mySecondTag).or(myThirdTag)` * In both cases you would select events which contain all three given tags. */ where: Where; initialState: S; /** * Function to create the next state from previous state and next event. It works similar to `Array.reduce`. * Do note however that — while it may modify the passed-in state — this function must be _pure_: * - It should not cause any side-effects (except logging) * - It should not reference dynamic outside state like random numbers or the current time. The result must depend purely on the input parameters. */ onEvent: Reduce; fishId: FishId; isReset?: IsReset; deserializeState?: (jsonState: unknown) => S; }; /** * Fish generic generator methods. * @public */ export declare const Fish: { latestEvent: (where: Where) => Fish; eventsDescending: (where: Where, capacity?: number) => Fish; eventsAscending: (where: Where, capacity?: number) => Fish; }; /** * Queue emission of an event whose type is covered by `EWrite`. * @public */ export declare type AddEmission = (...args: [Tags, E] | [TaggedTypedEvent]) => void; /** * Enqueue event emissions based on currently known local state. * @public */ export declare type StateEffect = (state: S, enqueue: AddEmission, pond: Pond) => void | Promise; /** Context for an error thrown by a Fish’s functions. * @public */ export declare type FishErrorContext = { occuredIn: 'onEvent'; state: unknown; event: unknown; metadata: Metadata; } | { occuredIn: 'isReset'; event: unknown; metadata: Metadata; } | { occuredIn: 'deserializeState'; jsonState: unknown; }; /** Error reporter for when Fish functions throw exceptions. * @public */ export declare type FishErrorReporter = (err: unknown, fishId: FishId, detail: FishErrorContext) => void;