MapperReadCRUDRepo

A ReadCRUDRepo wrapper that maps between different key and value types. Allows adapting a repository with one type system to work with another type system.

Parameters

to

The underlying repository to wrap

mapper

The mapper that defines the bidirectional type conversions

Type Parameters

FromId

The external ID type exposed by this wrapper

FromRegistered

The external object type exposed by this wrapper

ToId

The internal ID type used by the underlying repository

ToRegistered

The internal object type used by the underlying repository

Constructors

Link copied to clipboard

Properties

Link copied to clipboard

Provides a mapper for converting keys between inner and outer types.

Link copied to clipboard

Provides a mapper for converting values between inner and outer types.

Functions

Link copied to clipboard

Wraps this ReadCRUDRepo as a ReadKeyValueFromCRUDRepo, exposing CRUD IDs as keys and CRUD objects as values in a ReadKeyValueRepo.

Link copied to clipboard
Link copied to clipboard
open suspend override fun contains(id: FromId): Boolean

Returns true if an object with the given id exists in the repository.

Link copied to clipboard
open suspend override fun count(): Long

Returns the total count of objects stored in the repository.

Link copied to clipboard

Computes the difference between this ReadCRUDRepo and a map of items. Retrieves all items from the repository and compares them with the provided map.

Link copied to clipboard
open suspend override fun getAll(): Map<FromId, FromRegistered>

Returns all objects in the repository as a map of ID to object. Default implementation iterates all pages using getIdsByPagination and getById.

Link copied to clipboard
open suspend override fun getById(id: FromId): FromRegistered?

Returns the object associated with the given id, or null if not found.

Link copied to clipboard
open suspend override fun getByPagination(pagination: Pagination): PaginationResult<FromRegistered>

Returns a paginated list of all objects in the repository.

Link copied to clipboard
open suspend override fun getIdsByPagination(pagination: Pagination): PaginationResult<FromId>

Returns a paginated list of all IDs in the repository.

Link copied to clipboard
inline suspend fun ReadCRUDRepo<*, *>.maxPagePagination(): SimplePagination

Creates a pagination starting from the first page with size equal to the total count of items in this ReadCRUDRepo. This effectively creates a single page containing all items.

Link copied to clipboard
open suspend override fun ToId.toInnerKey(): FromId

Converts a key from the outer type to the inner type.

Link copied to clipboard
open suspend override fun ToRegistered.toInnerValue(): FromRegistered

Converts a value from the outer type to the inner type.

Link copied to clipboard
open suspend override fun FromId.toOutKey(): ToId

Converts a key from the inner type to the outer type.

Link copied to clipboard
open suspend override fun FromRegistered.toOutValue(): ToRegistered

Converts a value from the inner type to the outer type.

Link copied to clipboard

Wraps this ReadCRUDRepo with a mapper to expose different key and value types.

inline fun <FromKey, FromValue, ToKey, ToValue> ReadCRUDRepo<ToValue, ToKey>.withMapper(noinline keyFromToTo: suspend FromKey.() -> ToKey = { this as ToKey }, noinline valueFromToTo: suspend FromValue.() -> ToValue = { this as ToValue }, noinline keyToToFrom: suspend ToKey.() -> FromKey = { this as FromKey }, noinline valueToToFrom: suspend ToValue.() -> FromValue = { this as FromValue }): ReadCRUDRepo<FromValue, FromKey>

Wraps this ReadCRUDRepo with custom conversion functions for keys and values.