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

    Interface AdcpStateStore

    Generic document store for AdCP domain objects.

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

    interface AdcpStateStore {
        get<T extends Record<string, unknown> = Record<string, unknown>>(
            collection: string,
            id: string,
        ): Promise<T | null>;
        put(
            collection: string,
            id: string,
            data: Record<string, unknown>,
        ): Promise<void>;
        patch(
            collection: string,
            id: string,
            partial: Record<string, unknown>,
        ): Promise<void>;
        delete(collection: string, id: string): Promise<boolean>;
        list<T extends Record<string, unknown> = Record<string, unknown>>(
            collection: string,
            options?: StateListOptions,
        ): Promise<StateListResult<T>>;
        scoped?(sessionKey: string): AdcpStateStore;
        getWithVersion?<
            T extends Record<string, unknown> = Record<string, unknown>,
        >(
            collection: string,
            id: string,
        ): Promise<VersionedDocument<T> | null>;
        putIfMatch?(
            collection: string,
            id: string,
            data: Record<string, unknown>,
            expectedVersion: number | null,
        ): Promise<PutIfMatchResult>;
    }

    Implemented by

    Index

    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>

    • Create or replace a document (upsert semantics).

      Parameters

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

      Returns Promise<void>

    • 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>

    • Delete a document. Returns true if it existed.

      Parameters

      • collection: string
      • id: string

      Returns Promise<boolean>

    • Convenience method for built-in stores: returns a session-scoped view. Optional on the interface so custom AdcpStateStore implementations aren't forced to implement it — callers who need the wrapper on any store should use scopedStore instead, which handles the fallback.

      Parameters

      • sessionKey: string

      Returns AdcpStateStore

    • 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>

    • 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>