States are where you can store information when a usecase is run so that it can be used again in another usecase execution.

Using state in usecase rules

process() function injects state parameter so that it can be called.

async process({ state }) {
    // code

Set state


state.set(key: string, value: unknown): Promise<void>

Set a project-wide state value to a key.

If the specified key already has value, the supplied value need to be of the same type. By doing so, the previous state will be overwritten.

Accessing state


state.get(key: string): Promise<unknown>

Retrieve a value of state with specified key previously set.

If key does not exist, return undefined instead.

Removing state


state.remove(key: string): Promise<void>

Remove a state with the specified key

Last updated