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

The primary interface for loading entities. All normal loads are batched, cached, and authorized against the entity's EntityPrivacyPolicy.

Type Parameters

  • TFields extends object

  • TID extends NonNullable<TFields[TSelectedFields]>

  • TViewerContext extends ViewerContext

  • TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields>

  • TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields>

  • TSelectedFields extends keyof TFields

Hierarchy

  • EntityLoader

Constructors

  • Type Parameters

    • TFields extends object

    • TID extends {}

    • TViewerContext extends ViewerContext<TViewerContext>

    • TEntity extends ReadonlyEntity<TFields, TID, TViewerContext, TSelectedFields, TEntity>

    • TPrivacyPolicy extends EntityPrivacyPolicy<TFields, TID, TViewerContext, TEntity, TSelectedFields, TPrivacyPolicy>

    • TSelectedFields extends string | number | symbol

    Parameters

    Returns EntityLoader<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>

Properties

dataManager: EntityDataManager<TFields>
entityClass: IEntityClass<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>
entityConfiguration: EntityConfiguration<TFields>
entitySelectedFields: undefined | TSelectedFields[]
metricsAdapter: IEntityMetricsAdapter
privacyPolicy: TPrivacyPolicy
privacyPolicyEvaluationContext: EntityPrivacyPolicyEvaluationContext
queryContext: EntityQueryContext
viewerContext: TViewerContext

Methods

  • Construct and authorize entities from fields map, returning error results for entities that fail to construct or fail to authorize.

    Type Parameters

    • K

    Parameters

    • map: ReadonlyMap<K, readonly Readonly<TFields>[]>

      map from an arbitrary key type to an array of entity field objects

    Returns Promise<ReadonlyMap<K, readonly Result<TEntity>[]>>

  • Enforcing view on this entity loader. All loads through this view are guaranteed to be the values of successful results (or null for some loader methods), and will throw otherwise.

    Returns EnforcingEntityLoader<TFields, TID, TViewerContext, TEntity, TPrivacyPolicy, TSelectedFields>

  • Invalidate all caches for an entity. One potential use case would be to keep the entity framework in sync with changes made to data outside of the framework.

    Parameters

    • entity: TEntity

      entity to be invalidated

    Returns Promise<void>

  • Invalidate all caches for an entity's fields. Exposed primarily for internal use by EntityMutator.

    Parameters

    • objectFields: Readonly<TFields>

      entity data object to be invalidated

    Returns Promise<void>

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

    Throws

    when multiple entities match the condition

  • Loads an entity by a specified ID.

    Parameters

    • id: TID

      ID of the entity

    Returns Promise<Result<TEntity>>

    entity result for matching ID, where result error can be UnauthorizedError or EntityNotFoundError.

  • Load an entity by a specified ID, or return null if non-existent.

    Parameters

    • id: TID

      ID of the entity

    Returns Promise<null | Result<TEntity>>

    entity result for matching ID, or null if no entity exists for ID.

  • 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

    Example

    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.

    Parameters

    • ids: readonly TID[]

      IDs of the entities to load

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

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

  • 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

    Remarks

    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.

    Example

    rawWhereClause: `id = ?`
    bindings: `[1]`
    Entites returned `WHERE id = 1`

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

    Throws

    Error when rawWhereClause or bindings are invalid

    Deprecated

    prefer caching loaders

  • Parameters

    • fieldsObjects: readonly TFields[]

    Returns readonly Result<TEntity>[]

  • Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N
    • fieldValues: readonly TFields[N][]

    Returns void

Generated using TypeDoc