Skip to main content

TestStateProvider

Keeps state in memory, and discards it when the process ends. For tests.

@group

Services/State Management

@see

Techniques for State Providers.

Implements

Index

Constructors

constructor

Methods

getAppLock

  • getAppLock(): Promise<string | undefined>
  • The id of the lock currently held, or undefined when the app is unlocked.


    Returns Promise<string | undefined>

getSealedStates

  • getSealedStates(stateFileNames: string[]): Promise<(Buffer<ArrayBufferLike> | undefined)[]>
  • Reads state files. Nothing is sealed here, so the state itself stands in for the sealed state.


    Parameters

    • stateFileNames: string[]

    Returns Promise<(Buffer<ArrayBufferLike> | undefined)[]>

getState

  • getState(stateFileName: string): Promise<Buffer<ArrayBufferLike>>
  • Reads a state file.

    @throws

    TransactionError With the message No state found! when the file does not exist.


    Parameters

    • stateFileName: string

    Returns Promise<Buffer<ArrayBufferLike>>

getTemporaryFilePath

  • getTemporaryFilePath(name: string): Promise<string>
  • A new path in the system's temporary directory, since the state holds no files.


    Parameters

    • name: string

    Returns Promise<string>

isAppLocked

  • isAppLocked(lockId: string): Promise<boolean>
  • Whether lockId is the lock currently held.

    @throws

    TransactionError With the message Invalid lock ID! when a different lock is held.


    Parameters

    • lockId: string

    Returns Promise<boolean>

listStates

  • listStates(prefix: string): Promise<string[]>
  • The names of the state files whose name starts with prefix.


    Parameters

    • prefix: string

    Returns Promise<string[]>

lockApp

  • lockApp(lock: { commitId: string } | { lockId: string }): Promise<{ commitId?: string; lockId: string; resumedFrom?: directory | run | sealed }>
  • Takes the app lock. With lockId, resumes the run already holding it.

    @throws

    TransactionError When a lock is held, naming the id that holds it. When lockId is given and is not the lock held.


    Parameters

    • lock: { commitId: string } | { lockId: string }
      • commitId: string
      • lockId: string

    Returns Promise<{ commitId?: string; lockId: string; resumedFrom?: directory | run | sealed }>

refreshState

  • refreshState(): Promise<{ replaced: boolean }>
  • Does nothing: the state lives in this process alone, so it is always the newest.


    Returns Promise<{ replaced: boolean }>

saveStates

  • saveStates(stateFiles: ({ data: Buffer<ArrayBufferLike> | undefined; stateFileName: string } | { filePath: string; stateFileName: string })[]): Promise<void>
  • Writes state files, overwriting whatever was there, moving each one given a filePath into memory, and deleting each one given no data.


    Parameters

    • stateFiles: ({ data: Buffer<ArrayBufferLike> | undefined; stateFileName: string } | { filePath: string; stateFileName: string })[]

    Returns Promise<void>

unlockApp

  • unlockApp(lockId: string): Promise<void>
  • Clears the journal, which a run that follows would refuse to lock over, and releases the app lock.

    @throws

    TransactionError With the message Invalid lock ID! when a different lock is held.


    Parameters

    • lockId: string

    Returns Promise<void>