@adcp/sdk API Reference - v7.9.0
    Preparing search index...

    Class PostgresStateStore

    Generic document store for AdCP domain objects.

    Collections are logical groupings (e.g., 'media_buys', 'accounts', 'creatives'). Each document is identified by collection + id.

    Implements

    Index

    Constructors

    Methods

    • Get a document by collection and id. Returns null if not found.

      Type Parameters

      • T extends Record<string, unknown> = Record<string, unknown>

      Parameters

      • collection: string
      • id: string

      Returns Promise<T | null>

    • Read a document with its current row version. Returns null if the row doesn't exist. Optional on the interface — custom stores that don't track versions don't have to implement it. Use patchWithRetry to guard against read-modify-write races without calling this directly.

      Type Parameters

      • T extends Record<string, unknown> = Record<string, unknown>

      Parameters

      • collection: string
      • id: string

      Returns Promise<VersionedDocument<T> | null>

    • Create or replace a document (upsert semantics).

      Parameters

      • collection: string
      • id: string
      • data: Record<string, unknown>

      Returns Promise<void>

    • Atomic compare-and-swap write. Succeeds only if the row's current version equals expectedVersion (or if the row doesn't exist and expectedVersion is null). On conflict, returns the version the store actually has so the caller can re-read and retry.

      Optional on the interface — custom stores that can't implement CAS don't have to. Use patchWithRetry for the common "update a field with retry on conflict" case.

      Parameters

      • collection: string
      • id: string
      • data: Record<string, unknown>
      • expectedVersion: number | null

      Returns Promise<PutIfMatchResult>

    • Merge fields into an existing document. Creates the document if it doesn't exist. Only top-level fields are merged — nested objects are replaced, not deep-merged.

      Parameters

      • collection: string
      • id: string
      • partial: Record<string, unknown>

      Returns Promise<void>