Interface IPersistBase<Entity>

Persistence interface for CRUD operations. Implemented by PersistBase.

interface IPersistBase<Entity extends IEntity = IEntity> {
    hasValue(entityId: EntityId): Promise<boolean>;
    readValue(entityId: EntityId): Promise<Entity>;
    waitForInit(initial: boolean): Promise<void>;
    writeValue(entityId: EntityId, entity: Entity): Promise<void>;
}

Type Parameters

  • Entity extends IEntity = IEntity

Methods

  • Check if entity exists in storage.

    Parameters

    • entityId: EntityId

      Unique entity identifier

    Returns Promise<boolean>

    Promise resolving to true if exists, false otherwise

  • Read entity from persistence storage.

    Parameters

    • entityId: EntityId

      Unique entity identifier

    Returns Promise<Entity>

    Promise resolving to entity data

    Error if entity not found or read fails

  • Initialize persistence directory and validate existing files. Uses singleshot to ensure one-time execution.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>

    Promise that resolves when initialization is complete

  • Write entity to storage with atomic file writes.

    Parameters

    • entityId: EntityId

      Unique entity identifier

    • entity: Entity

      Entity data to persist

    Returns Promise<void>

    Promise that resolves when write is complete

    Error if write fails