import { a as Storage, E as EventEmitter, j as EventMap, U as UnexpectedErrorEvent, T as Trace, S as Selector, D as Database, f as DatabaseMetadata } from '../shared/hive.DlaRxYsk.js'; import { Logger } from '../sdk/logger.js'; import '../sdk/transaction.js'; import 'zod'; import '../streams/index.js'; //#region src/index.d.ts type SnapshotCreationReason = 'MANUAL' | 'SCHEDULED' | null; type RetentionPolicy = { /** * Maximum number of Snapshots */ max?: number | null | undefined; } | { /** * Maximum number of day Snapshots are kept for. */ maxAge?: number | null | undefined; }; type SnapshotManagerConfig = { /** * `Storage` instance to use for reading and persisting Snapshot state. */ storage: Storage; /** * `EventEmitter` instance to use for listening to and emitting events. */ events: EventEmitter; /** * `Logger` instance to use for logging. * * @default null */ logger?: Logger | null | undefined; /** * Schedule in cron format at which Snapshots will be created. * * Only Resources which had changes since their last Snapshot will be * snapshotted again. * * By default, a new Snapshot will be created every hour. */ schedule?: string | null | undefined; /** * Retention policy configuration for Snapshots. * * If provided, Snapshots not matching the configured policy will * be deleted. * * @default null */ retention?: RetentionPolicy | null | undefined; /** * Handler errors are passed to occur during background operations. * * @default null */ onError?: ((event: UnexpectedErrorEvent) => void) | null | undefined; }; declare class SnapshotManager { static readonly name = "snapshot-manager"; /** * `Storage` instance to use for reading and persisting Snapshot state. */ private readonly storage; /** * `EventEmitter` instance to use for listening to and emitting events. */ private readonly events; /** * `Logger` instance to use for logging. */ private readonly logger; /** * Schedule at which, if provided, Snapshots will be taken of * modified Databases. */ private readonly cron; /** * Timer that, if running, triggers the creation of Snapshots at the * configured schedule. */ private timer; /** * Map containing modifications counts for each managed Database. */ private readonly modifications; /** * Map containing references to pending Snapshot creation promises. */ private readonly pending; /** * Error handler to invoke with any errors which might occur during * background tasks. */ private readonly onError; constructor(config: SnapshotManagerConfig); /** * Internal method to create a Snapshot of a Resource. * * @param selector Details about the Resource to snapshot. * @param opts Options for the operation. * * @returns Promise resolving when the Snapshot has been created. */ private readonly snapshot; /** * Internal method to handle a Resource query event. * * @param event Details about the Resource query event. */ private readonly handleTransaction; /** * Internal method to handle a Storage delete event. * * @param event Details about the Storage delete event. */ private readonly handleDelete; /** * Start the `SnapshotManager` instance. * * @param opts Options for starting the `SnapshotManager` instance. * * @returns Promise resolving the `SnapshotManager` instance. */ readonly start: (_opts?: { trace?: Trace | null | undefined; }) => Promise; /** * Stop the `SnapshotManager` instance. * * @param opts Options for stopping the `SnapshotManager` instance. * * @returns Promise resolving the `SnapshotManager` instance. */ readonly stop: (_opts?: { trace?: Trace | null | undefined; }) => Promise; /** * Schedule the creation of Snapshots of all Resources that were modified * since their last Snapshot was created. * * If the creation of a Snapshot fails, errors are handled individually * and other Snapshot creations will continue to be attempted, though the * Promise will reject. * * If a Snapshot is already being created of a Resource, the ongoing * operation will be awaited instead. * * @example ``` * // Schedule the creation of Snapshots of all modified Resources. * await snapshotManager.schedule(); * ``` * * @param opts Options for creating Snapshots. * * @returns Promise resolving when all scheduled Snapshots have been created. * * @throws `Error` if the creation of one or more Snapshots fails. */ readonly schedule: (opts?: { reason?: SnapshotCreationReason | null | undefined; trace?: Trace | null | undefined; }) => Promise; /** * Create a new Snapshot of a Resource. * * @param source Details about the Resource to create a Snapshot of. * @param target Details about the Snapshot to create. * @param opts Options for creating the Snapshot. * * @returns Promise resolving when the Snapshot has been created. */ readonly create: (source: Selector<"database">, target?: Selector<"snapshot">, opts?: { reason?: SnapshotCreationReason | null | undefined; trace?: Trace | null | undefined; }) => Promise<{ resource: Database<"snapshot">; metadata: DatabaseMetadata; }>; /** * Restore a Snapshot of a Resource. * * @param source Details about the Snapshot to restore. * @param target Details about the Resource to restore the Snapshot to. * @param opts Options for restoring the Snapshot. * * @returns Promise resolving when the Snapshot has been restored. */ readonly restore: (source: Selector<"snapshot">, target: Selector<"database">, opts?: { trace?: Trace | null | undefined; }) => Promise; } export { SnapshotManager }; export type { RetentionPolicy, SnapshotCreationReason, SnapshotManagerConfig };