commonMain.com.caesarealabs.loggy.shared.Query.kt Maven / Gradle / Ivy
The newest version!
package com.caesarealabs.loggy.shared
import kotlinx.serialization.Serializable
@Serializable
data class Query(val text: String, val page: Int, val maxItemsPerPage: Int,)
/**
* This does not use sealed classes as you cannot use @Serializable with generic sealed classes.
*
* Same as `SearchitResult` but does not depend on Searchit (`lib` doesn't depend on Searchit but we use `shared` in it)
*/
@Serializable
public data class SearchResult(val success: SearchSuccess?, val error: String?) {
public companion object {
public fun syntaxError(error: String?): SearchResult = SearchResult(success = null, error = error)
public fun success(pageCount: Int, items: List, dataKeys: List): SearchResult = SearchResult(
success = SearchSuccess(pageCount, items, dataKeys), error = null
)
}
inline fun map(mapper: (T) -> R): SearchResult {
return SearchResult(
success = success?.map(mapper),
error = error
)
}
}
@Serializable
/**
* @param dataKeys A list of all data keys (from Logging.logData) of the search result, in ALL pages.
*/
public data class SearchSuccess(val pageCount: Int, val items: List, val dataKeys: List) {
inline fun map(mapper: (T) -> R): SearchSuccess {
return SearchSuccess(
pageCount = pageCount,
items = items.map(mapper),
dataKeys
)
}
}