-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move query framework to inkt subproject
- Loading branch information
Showing
9 changed files
with
248 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# inkt | ||
|
||
An incremental query framework for Kotlin | ||
|
||
Heavily inspired by [Salsa](https://github.com/salsa-rs/salsa) | ||
|
||
## Quick Start | ||
|
||
See [DefinedQueryExample.kt](src/main/kotlin/dev/dialector/inkt/query/example/DefinedQueryExample.kt) for an example of how to define queries and use the database. | ||
A KSP-based code generator will eventually replace manual definition of query database implementations. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("org.jetbrains.kotlinx.kover") | ||
id("maven-publish") | ||
signing | ||
} | ||
|
||
dependencies { | ||
implementation(kotlin("reflect")) | ||
} | ||
|
||
kotlin { | ||
explicitApiWarning() | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(8)) | ||
} | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
tasks.withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
|
||
kover { | ||
xmlReport { | ||
onCheck.set(true) | ||
} | ||
} | ||
|
||
publishing { | ||
repositories { | ||
maven { | ||
name = "OSSRH" | ||
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") | ||
credentials { | ||
username = System.getenv("SONATYPE_USERNAME") | ||
password = System.getenv("SONATYPE_PASSWORD") | ||
} | ||
} | ||
maven { | ||
name = "GitHubPackages" | ||
setUrl("https://maven.pkg.github.com/ty1824/dialector") | ||
credentials { | ||
username = System.getenv("GITHUB_ACTOR") | ||
password = System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
} | ||
repositories.forEach { println((it as MavenArtifactRepository).url)} | ||
publications { | ||
register<MavenPublication>("default") { | ||
from(components["java"]) | ||
pom { | ||
name.set("inkt") | ||
description.set("Incremental computation framework for Kotlin") | ||
url.set("http://dialector.dev") | ||
licenses { | ||
license { | ||
name.set("GPL-3.0") | ||
url.set("https://opensource.org/licenses/GPL-3.0") | ||
} | ||
} | ||
issueManagement { | ||
system.set("Github") | ||
url.set("https://github.com/ty1824/dialector/issues") | ||
} | ||
scm { | ||
connection.set("https://github.com/ty1824/dialector.git") | ||
url.set("https://github.com/ty1824/dialector") | ||
} | ||
developers { | ||
developer { | ||
name.set("Tyler Hodgkins") | ||
email.set("[email protected]") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
signing { | ||
val gpgPrivateKey = System.getenv("GPG_SIGNING_KEY") | ||
if (!gpgPrivateKey.isNullOrBlank()) { | ||
useInMemoryPgpKeys( | ||
gpgPrivateKey, | ||
System.getenv("GPG_SIGNING_PASSPHRASE") | ||
) | ||
sign(publishing.publications) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.dialector.inkt | ||
|
||
internal data class QueryKey<K, V>(val queryDef: DatabaseQuery<K, V>, val key: K) | ||
|
||
internal sealed interface Value<V> { | ||
var value: V | ||
var changedAt: Int | ||
} | ||
|
||
internal data class InputValue<V>(override var value: V, override var changedAt: Int) : Value<V> | ||
|
||
internal data class DerivedValue<V>( | ||
override var value: V, | ||
val dependencies: MutableList<QueryKey<*, *>>, | ||
var verifiedAt: Int, | ||
override var changedAt: Int | ||
) : Value<V> | ||
|
||
internal class QueryFrame<K>( | ||
val queryKey: QueryKey<K, *>, | ||
var maxRevision: Int = 0, | ||
val dependencies: MutableList<QueryKey<*, *>> = mutableListOf() | ||
) |
75 changes: 6 additions & 69 deletions
75
...in/dev/dialector/query/QueryDefinition.kt → ...otlin/dev/dialector/inkt/QueryDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dev.dialector.inkt | ||
|
||
import kotlin.reflect.KClass | ||
|
||
public annotation class QueryGroup | ||
|
||
public annotation class Query | ||
|
||
public annotation class Input | ||
|
||
public annotation class Tracked | ||
|
||
public annotation class DatabaseDef(vararg val groups: KClass<*>) | ||
|
||
public class NoInputDefinedException(message: String) : RuntimeException(message) | ||
|
||
public interface DatabaseQuery<K, V> { | ||
public val name: String | ||
public fun get(key: K): V | ||
} | ||
|
||
/** | ||
* This function is used to create a typesafe storage map for a query. | ||
* The receiver is necessary to properly infer types, even though IntelliJ says otherwise. | ||
*/ | ||
internal fun <K, V> DatabaseQuery<K, V>.createMap(): MutableMap<K, Value<V>> = mutableMapOf() | ||
|
||
public data class InputQuery<K, V>( | ||
override val name: String, | ||
private val query: (K) -> V | ||
) : DatabaseQuery<K, V> { | ||
override fun get(key: K): V = query(key) | ||
} | ||
|
||
public data class DerivedQuery<K, V>( | ||
override val name: String, | ||
private val query: (K) -> V | ||
) : DatabaseQuery<K, V> { | ||
override fun get(key: K): V = query(key) | ||
} | ||
|
||
public fun <K, V> inputQuery( | ||
name: String, | ||
query: (K) -> V = { throw NoInputDefinedException("No input exists for query $name($it)") } | ||
): InputQuery<K, V> = InputQuery(name, query) | ||
|
||
public fun <K, V> derivedQuery(name: String, query: (K) -> V): DerivedQuery<K, V> = DerivedQuery(name, query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.