Skip to main content
Version: Next

RecoverableStateBaseOptions <TStateModel, TPersistedState>

The fields of RecoverableStateOptions, without the constraint tying contentType to the conversions.

Hierarchy

Index

Properties

optionalconfiguration

configuration?: Configuration

Configuration instance to use when opening the KeyValueStore

optionalcontentType

contentType?: string

Content type of the persisted record. Setting it hands the record encoding over to RecoverableStateBaseOptions.serialize and RecoverableStateBaseOptions.deserialize, both of which are then required - the default JSON codec is bypassed in both directions. Meant for a state too large for JSON.stringify, which serialize can then stream out instead.

defaultState

defaultState: TStateModel | () => TStateModel

The state used when no persisted state is found, and the state RecoverableState.reset restores.

A plain value is deep-copied with structuredClone each time it is used, so pass a factory for a state that structuredClone cannot rebuild - one holding class instances, say, or one derived from a schema.

optionaldeserialize

deserialize?: StateConversion<TPersistedState, TStateModel>

Optional conversion of a persisted value back to the state model, and the place to validate a record before trusting it. If not provided, the persisted value is used as is.

With RecoverableStateBaseOptions.contentType set, it receives a Readable of the record bytes instead of a parsed value.

optionalinheritedkeyValueStore

keyValueStore?: KeyValueStore | PromiseLike<KeyValueStore>

The KeyValueStore to persist into, defaulting to the default store. Accepts a pending KeyValueStore.open so that callers do not have to be async to point at a specific store.

optionallogger

logger?: CrawleeLogger

A logger instance for logging operations related to state persistence

optionalinheritedpersistenceEnabled

persistenceEnabled?: boolean

Flag to enable or disable state persistence

optionalinheritedpersistenceTimeoutMillis

persistenceTimeoutMillis?: number = 60_000

Time limit for a single load or save of the state, in milliseconds.

inheritedpersistStateKey

persistStateKey: string

The key under which the state is stored in the KeyValueStore

optionalserialize

serialize?: StateConversion<TStateModel, TPersistedState>

Optional conversion of the state to a plain JSON-serializable value before it is persisted. If not provided, the state is persisted as is.

With RecoverableStateBaseOptions.contentType set, it has to produce what KeyValueStore.setValue accepts alongside an explicit content type - a string, a Buffer or a stream.