import type { ViewOf } from "atom.io" import type { Canonical } from "atom.io/foundations/canonical" import type { stringified } from "atom.io/foundations/json" import type { AtomOnly, TimelineManageable } from "./timeline.ts" import type { AtomToken, ReadableToken, SelectorToken, TokenType, TransactionToken, WritableToken, } from "./tokens.ts" export type StateUpdate = { readonly oldValue?: ViewOf readonly newValue: ViewOf } export type AtomUpdateEvent> = { type: `atom_update` token: A update: StateUpdate> timestamp: number } export type SelectorUpdateSubEvent> = | AtomUpdateEvent | AtomCreationEvent export type TimelineSelectorUpdateEvent = { type: `selector_update` token: SelectorToken subEvents: SelectorUpdateSubEvent>[] timestamp: number } export type AtomCreationEvent> = { type: `atom_creation` token: A timestamp: number value?: TokenType } export type AtomDisposalEvent> = { type: `atom_disposal` token: A timestamp: number value?: TokenType } export type AtomLifecycleEvent> = | AtomCreationEvent | AtomDisposalEvent export type MoleculeCreationEvent = { type: `molecule_creation` key: Canonical provenance: Canonical timestamp: number } export type MoleculeDisposalEvent = { type: `molecule_disposal` key: Canonical provenance: stringified[] values: [key: string, value: any][] timestamp: number } export type MoleculeTransferEvent = { type: `molecule_transfer` key: Canonical exclusive: boolean from: Canonical[] to: Canonical[] timestamp: number } export type TransactionSubEvent = | AtomLifecycleEvent> | AtomUpdateEvent> | MoleculeCreationEvent | MoleculeDisposalEvent | MoleculeTransferEvent | TransactionOutcomeEvent> export type TransactionOutcomeEvent> = { type: `transaction_outcome` token: T id: string timestamp: number subEvents: TransactionSubEvent[] params: Parameters> output: ReturnType> } export type TimelineEvent = { checkpoint?: true } & ( | AtomUpdateEvent> | AtomCreationEvent> | AtomDisposalEvent> | TimelineSelectorUpdateEvent | TransactionOutcomeEvent> ) export type TimelineCullEvent = { type: `timeline_cull` target: `undo_steps` /** Logical undo steps available before collection. */ from: number /** Logical undo steps remaining after collection. */ to: number } export type TimelineUpdate = { type: `timeline_update` event: | TimelineEvent | TimelineCullEvent | `clear` | `redo` | `undo` at: number length: number }