import type { Options as MutativeOptions, Patches, Draft, Immutable, PatchesOptions } from 'mutative'; export type TravelPatches
= { patches: Patches
[]; inversePatches: Patches
[]; }; export type TravelMetadata = { label?: string; timestamp?: number; source?: string; [key: string]: unknown; }; export type TravelHistoryEntry
= { patches: Patches
; inversePatches: Patches
;
metadata?: TravelMetadata;
};
export type PatchesOption = Exclude = {
patches: TravelPatches ;
position: number;
metadata?: Array & {
version: 1;
state: S;
};
export type TravelsPersistenceErrorCode = 'PARSE_ERROR' | 'INVALID_SCHEMA' | 'UNSUPPORTED_VERSION' | 'INVALID_PATCHES' | 'MIGRATION_FAILED';
export type TravelsMigration = {
position: number;
discarded: TravelHistoryEntry [];
};
export type TravelsDevtoolsEvent ;
metadata?: TravelMetadata;
};
export type TravelsErrorCode = 'TRANSACTION_FAILED';
export type TravelsOptions ;
/**
* Restore validated serialized history. This is equivalent to passing
* initialPatches and initialPosition directly, but preserves the first-class
* persistence API shape returned by `Travels.deserialize(...)`.
*/
history?: TravelsHistory ;
/**
* Whether to throw when `initialPatches` is invalid.
* When false (default), invalid patches are discarded and history starts empty.
*/
strictInitialPatches?: boolean;
/**
* Whether to automatically archive the current state, by default `true`
*/
autoArchive?: A;
/**
* Whether to mutate the state in place (for observable state like MobX, Vue, Pinia)
* When true, apply patches directly to the existing state object
* When false (default), create new immutable state objects
* @default false
*/
mutable?: boolean;
/**
* Whether to warn in development when state contains values with weak patch or
* JSON persistence semantics, by default `true` in development.
*/
warnOnUnsupportedState?: boolean;
/**
* Called when Travels wraps a thrown core operation error.
*/
onError?: (error: Error) => void;
/**
* Called when undoing and then making a new edit discards redo history.
*/
onBranchDiscard?: (event: TravelsBranchDiscardEvent ) => void;
/**
* Optional hook for external devtools or debugging timelines.
*/
devtools?: (event: TravelsDevtoolsEvent ;
/**
* Go back in the history
*/
back: (amount?: number) => void;
/**
* Go forward in the history
*/
forward: (amount?: number) => void;
/**
* Reset the history
*/
reset: () => void;
/**
* Go to a specific position in the history
*/
go: (position: number) => void;
/**
* Check if it's possible to go back
*/
canBack: () => boolean;
/**
* Check if it's possible to go forward
*/
canForward: () => boolean;
}
export type RebasableTravelsControls = TravelsHistory = (snapshot: unknown) => TravelsSerializedHistory | unknown;
export type TravelsDeserializeOptions = {
/**
* Migrate old persisted snapshots into the current schema before validation.
*/
migrate?: TravelsMigration;
/**
* Fallback snapshot used when parsing, migration, or validation fails.
*/
fallback?: TravelsSerializedHistory | (() => TravelsSerializedHistory);
/**
* Receive typed persistence errors before a fallback is returned or the error is thrown.
*/
onError?: (error: Error) => void;
};
export type TravelsBranchDiscardEvent = {
type: 'setState' | 'archive' | 'transaction' | 'go' | 'reset' | 'rebase' | 'replaceStateWithoutHistory';
state: S;
position: number;
patches: TravelPatches = (draft: Draft) => void;
export type Updater = S | (() => S) | DraftFunction;
export type Value = F extends true ? Immutable;
export interface TravelsControls {
/**
* The current position in the history
*/
position: number;
/**
* Get the history of the state
*/
getHistory: () => Value[];
/**
* The patches of the history
*/
patches: TravelPatches = TravelsControls & {
/**
* Remove all history and make the current state as the new initial state.
*
* @remarks
* **IMPORTANT**: This is a destructive operation. All previous and future history entries are discarded,
* and the current state (including any unarchived temp patches) becomes the new baseline (position 0). Any subsequent `reset()`
* calls will return to this new baseline, not the original initial state.
*/
rebase: () => void;
};
export interface ManualTravelsControls extends TravelsControls {
/**
* Archive the current state
*/
archive: (metadata?: TravelMetadata) => void;
/**
* Check if it's possible to archive the current state
*/
canArchive: () => boolean;
}
export type RebasableManualTravelsControls = ManualTravelsControls & {
/**
* Remove all history and make the current state as the new initial state.
*
* @remarks
* **IMPORTANT**: This is a destructive operation. All previous and future history entries are discarded,
* and the current state (including any unarchived temp patches) becomes the new baseline (position 0). Any subsequent `reset()`
* calls will return to this new baseline, not the original initial state.
*/
rebase: () => void;
};
export {};
//# sourceMappingURL=type.d.ts.map