All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningserver.db.ModelInfo.kt Maven / Gradle / Ivy

The newest version!
package com.lightningkite.lightningserver.db

import com.lightningkite.lightningdb.FieldCollection
import com.lightningkite.lightningdb.HasId
import kotlinx.serialization.serializer

inline fun , reified ID : Comparable> ModelInfo(
    crossinline getCollection: () -> FieldCollection,
    crossinline forUser: suspend FieldCollection.(principal: USER) -> FieldCollection,
    modelName: String = serializer().descriptor.serialName.substringBefore('<').substringAfterLast('.')
) = object : ModelInfo {
    override fun collection(): FieldCollection = getCollection()
    override suspend fun collection(principal: USER): FieldCollection =
        this.collection().forUser(principal)

    override val serialization: ModelSerializationInfo = ModelSerializationInfo()
    override val collectionName: String = modelName
}

fun , ID : Comparable> ModelInfo(
    serialization: ModelSerializationInfo,
    getCollection: () -> FieldCollection,
    forUser: suspend FieldCollection.(principal: USER) -> FieldCollection,
    modelName: String = serialization.serializer.descriptor.serialName.substringBefore('<').substringAfterLast('.')
) = object : ModelInfo {
    override val serialization: ModelSerializationInfo = serialization
    override fun collection(): FieldCollection = getCollection()
    override suspend fun collection(principal: USER): FieldCollection =
        this.collection().forUser(principal)

    override val collectionName: String = modelName
}

interface ModelInfo, ID : Comparable> {
    val serialization: ModelSerializationInfo
    val collectionName: String
        get() = serialization.serializer.descriptor.serialName.substringBefore('<').substringAfterLast('.')

    fun collection(): FieldCollection
    suspend fun collection(principal: USER): FieldCollection
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy