Setu-TS
    Preparing search index...

    Interface IDataSource

    The data-access seam a backend provides per entity.

    One instance is bound to one entity (table/model/collection). The data source owns query evaluation end to end: it applies where, orderBy, offset/limit and select itself, and the repository above it must not re-apply any of them.

    Transaction-scoped instances may defer their writes. A backend whose store has no interactive transaction (Cloudflare D1, where a pre-declared batch() is the only unit of atomicity) has to buffer writes and apply them at commit. On such a backend the write methods below describe what WILL be written rather than what already is, and reads observe committed state only. A backend that defers must document it; D1Adapter is the worked example.

    0.2.0

    interface IDataSource {
        count(
            where: Record<string, unknown>,
            filter?: FilterExpression,
        ): Promise<number>;
        create(
            data: Partial<Record<string, unknown>>,
        ): Promise<Record<string, unknown>>;
        delete(id: EntityKey): Promise<boolean>;
        deleteWhere?(id: EntityKey, where: WritePrecondition): Promise<boolean>;
        findAll(query: NormalizedQuery): Promise<Record<string, unknown>[]>;
        findById(id: EntityKey): Promise<Record<string, unknown> | null>;
        findPage?(query: NormalizedQuery): Promise<PageResult>;
        update(
            id: EntityKey,
            data: Partial<Record<string, unknown>>,
        ): Promise<Record<string, unknown>>;
        updateWhere?(
            id: EntityKey,
            where: WritePrecondition,
            data: Partial<Record<string, unknown>>,
        ): Promise<Record<string, unknown> | null>;
    }
    Index
    • Count entities matching a filter.

      Parameters

      • where: Record<string, unknown>

        Equality conditions; empty alone counts all rows

      • Optionalfilter: FilterExpression

        Optional portable expression conjoined with where

      Returns Promise<number>

      The matching row count

    • Insert a new entity.

      Parameters

      • data: Partial<Record<string, unknown>>

        The column values to insert

      Returns Promise<Record<string, unknown>>

      The persisted row, including any generated columns. On a deferred-write transaction the row is the one that will be written, and a generated column is therefore not yet known.

    • Delete an entity by primary key.

      Parameters

      • id: EntityKey

        The primary key value (scalar or composite record)

      Returns Promise<boolean>

      true when a row was deleted, false when none matched. On a deferred-write transaction this reports whether a committed row matched, and the delete itself lands at commit.

    • Delete a row only while every precondition field equals its value. Optional permanently; deferred-write transaction sources omit this member.

      Parameters

      • id: EntityKey

        Primary key, conjoined with the precondition

      • where: WritePrecondition

        Non-empty string/number equality map on stored values

      Returns Promise<boolean>

      true when deleted, false for a missing key or failed predicate

      When validation or the backend refuses the write

      0.9.0

    • Find a single entity by its primary key value.

      The key is an EntityKey: a scalar string/number or a composite record. A composite record is refused by the backend when it maps to a single column (e.g. Prisma's where: { id }), so widening this parameter is source-compatible for callers but breaking for an out-of-repo implementor whose method still declares the scalar-only form.

      Parameters

      • id: EntityKey

        The primary key value (scalar or composite record)

      Returns Promise<Record<string, unknown> | null>

      The row, or null when no row has that key

    • Find a page of entities by cursor pagination.

      Optional. The member exists on every in-repo adapter but is declared optional so an out-of-repo implementor that cannot page by cursor keeps compiling. When it is absent, the repository above refuses cursor paging by name (UnsupportedQueryFeatureError): absence means "cannot page by cursor", never "there are no more rows" — the distinction an absent member cannot otherwise preserve.

      Parameters

      • query: NormalizedQuery

        The fully-resolved query, carrying an incoming cursor

      Returns Promise<PageResult>

      The matching rows plus a nextCursor that is null when no further page exists

    • Update an existing entity by primary key.

      Parameters

      • id: EntityKey

        The primary key value

      • data: Partial<Record<string, unknown>>

        The columns to merge into the row

      Returns Promise<Record<string, unknown>>

      The updated row

      When no row has that key

    • Update a row only while every precondition field equals its value. Optional permanently: absence means this source cannot write conditionally. Deferred-write transaction sources omit this member.

      Parameters

      • id: EntityKey

        Primary key, conjoined with the precondition

      • where: WritePrecondition

        Non-empty string/number equality map on stored values

      • data: Partial<Record<string, unknown>>

        Non-empty update payload

      Returns Promise<Record<string, unknown> | null>

      The updated row, or null for a missing key or failed predicate

      When validation or the backend refuses the write

      0.9.0