com.cultureamp.eventsourcing.Upcast.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kestrel Show documentation
Show all versions of kestrel Show documentation
Kotlin Framework for running event-sourced services
The newest version!
package com.cultureamp.eventsourcing
import kotlin.reflect.KClass
import kotlin.reflect.full.functions
interface Upcast {
fun upcast(event: E, metadata: M): OE
}
@Target(AnnotationTarget.CLASS)
@MustBeDocumented
annotation class UpcastEvent(val upcastType: KClass>)
fun UpcastEvent.upcasting(event: DomainEvent, metadata: EventMetadata): DomainEvent = this.upcastType
.functions
.find {
f ->
f.name == "upcast" &&
f.parameters.size == 3 &&
f.parameters[1].type.classifier is KClass<*> &&
(f.parameters[1].type.classifier as KClass<*>).isInstance(event)
}
?.call(this.upcastType.objectInstance, event, metadata) as DomainEvent
© 2015 - 2025 Weber Informatics LLC | Privacy Policy