import { Timestamp } from '@actyx/sdk'; import { TaggedIndex } from '../types'; export declare type SnapshotLevels = ReadonlyArray; export declare const isEven: (x: number) => boolean; /** * Mark indices at which a snapshot should be taken with a tag indicating the level of the snapshot * * @param cycle cycle of the first event. Cycles start with 1! * @param events events to tag with snapshot markers * @param from which point on to check the array for snapshots * * @returns a sparse array of the same size as events, with the tags for the corresponding events. */ export declare type GetSnapshotLevels = (cycle: number, events: ReadonlyArray, from: number) => SnapshotLevels; /** * Qualify previously scheduled (via GetSnapshotLevels) snapshots for application/storage, * i.e. decide whether they are old enough to be applied to the fishEventStore without too much * danger of shattering soon. * * @param scheduledSnapshot snapshot that was scheduled previously * @param latestState the latest known event, to calculate how old the snapshot is * * @returns whether to apply the `scheduledSnapshot` to the FES */ export declare type IsEligibleForStorage = (scheduledSnapshot: HasTimestamp, latestState: HasTimestamp) => boolean; export declare type SnapshotScheduler = { minEventsForSnapshot: number; getSnapshotLevels: GetSnapshotLevels; isEligibleForStorage: IsEligibleForStorage; }; /** * Minimum age of a state before it will be considered for a snapshot. * * Everything younger than this will be considered "the present", where * time travel can happen at any time and storing snapshots would be wasteful. */ export declare const minSnapshotAge: number; /** * The part of an event that we care about for the purpose of this method * * Not taking whole events makes it easier to write tests */ export declare type HasTimestamp = { timestamp: Timestamp; }; export declare const isEligibleForStorage: IsEligibleForStorage; export declare const SnapshotScheduler: { create: (minLevel: number) => SnapshotScheduler; };