Class AuthorizationResultBasedEntityLoader<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>

Authorization-result-based entity loader. All normal loads are batched, cached, and authorized against the entity's EntityPrivacyPolicy. All loads through this loader are are results (or null for some loader methods), where an unsuccessful result means an authorization error or entity construction error occurred. Other errors are thrown.

Type Parameters

Constructors

Properties

metricsAdapter: IEntityMetricsAdapter

Methods

  • Load an entity where fieldName equals fieldValue, or null if no entity exists.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • uniqueFieldName: N

      entity field being queried

    • fieldValue: NonNullable<TFields[N]>

      uniqueFieldName field value being queried

    Returns Promise<null | Result<TEntity>>

    entity result where uniqueFieldName equals fieldValue, or null if no entity matches the condition.

    when multiple entities match the condition

  • Loads the first entity matching the selection constructed from the conjunction of specified operands, or null if no matching entity exists. Entities loaded using this method are not batched or cached.

    This is a convenience method for loadManyByFieldEqualityConjunctionAsync. However, the orderBy option must be specified to define what "first" means. If ordering doesn't matter, explicitly pass in an empty array.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    Returns Promise<null | Result<TEntity>>

    the first entity results that matches the query, where result error can be UnauthorizedError

  • Load many entities where fieldName equals fieldValue.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      entity field being queried

    • fieldValue: NonNullable<TFields[N]>

      fieldName field value being queried

    Returns Promise<readonly Result<TEntity>[]>

    array of entity results that match the query for fieldValue, where result error can be UnauthorizedError

  • Load many entities where fieldName is one of fieldValues.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      entity field being queried

    • fieldValues: readonly NonNullable<TFields[N]>[]

      fieldName field values being queried

    Returns Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Result<TEntity>[]>>

    map from fieldValue to entity results that match the query for that fieldValue, where result errors can be UnauthorizedError

  • Loads many entities matching the selection constructed from the conjunction of specified operands. Entities loaded using this method are not batched or cached.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    Returns Promise<readonly Result<TEntity>[]>

    array of entity results that match the query, where result error can be UnauthorizedError

    fieldEqualityOperands:
    `[{fieldName: 'hello', fieldValue: 1}, {fieldName: 'world', fieldValues: [2, 3]}]`
    Entities returned with a SQL EntityDatabaseAdapter:
    `WHERE hello = 1 AND world = ANY({2, 3})`
  • Loads many entities for a list of IDs, returning null for any IDs that are non-existent.

    Parameters

    • ids: readonly TID[]

      IDs of the entities to load

    Returns Promise<ReadonlyMap<TID, null | Result<TEntity>>>

    map from ID to nullable corresponding entity result, where result error can be UnauthorizedError or EntityNotFoundError.

  • Loads many entities matching the raw WHERE clause. Corresponds to the knex whereRaw argument format.

    Parameters

    • rawWhereClause: string

      parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders

    • bindings: object | any[]

      array of positional bindings or object of named bindings

    • querySelectionModifiers: QuerySelectionModifiersWithOrderByRaw<TFields> = {}

      limit, offset, orderBy, and orderByRaw for the query

    Returns Promise<readonly Result<TEntity>[]>

    array of entity results that match the query, where result error can be UnauthorizedError

    Important notes:

    • Fields in clause are database column names instead of transformed entity field names.
    • Entities loaded using this method are not batched or cached.
    • Not all database adapters implement the ability to execute this method of fetching entities.
    rawWhereClause: `id = ?`
    bindings: `[1]`
    Entites returned `WHERE id = 1`

    http://knexjs.org/#Builder-whereRaw
    http://knexjs.org/#Raw-Bindings

    Error when rawWhereClause or bindings are invalid