Skip to content

Commit

Permalink
Syntax fixes for defining model infos
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Oct 19, 2023
1 parent 32c5ebe commit 802d2d0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
15 changes: 12 additions & 3 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ If your project's `build.gradle.kts` was generated with this line, comment it ou

## Add Gradle Plugins

```properties
# gradle.properties
kotlinVersion=1.9.10
kspVersion=1.9.10-1.0.13
lightningServerVersion=version-2-SNAPSHOT
```

```kotlin
// settings.gradle.kts
pluginManagement {
val kotlinVersion: String by settings
val kspVersion: String by settings
plugins {
kotlin("jvm") version "1.8.10"
kotlin("plugin.serialization") version "1.8.10"
id("com.google.devtools.ksp") version "1.8.10-1.0.9"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("com.google.devtools.ksp") version kspVersion
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import kotlin.concurrent.withLock
open class InMemoryFieldCollection<Model : Any>(
val data: MutableList<Model> = ArrayList(),
override val serializer: KSerializer<Model>
) :
AbstractSignalFieldCollection<Model>() {
) : AbstractSignalFieldCollection<Model>() {

private val lock = ReentrantLock()

Expand All @@ -27,7 +26,7 @@ open class InMemoryFieldCollection<Model : Any>(
private fun uniqueCheck(changes: List<EntryChange<Model>>) = uniqueIndexChecks.forEach { it(changes) }

init {
serializer.descriptor.indexes().forEach { index: NeededIndex ->
serializer.descriptor.indexes().plus(NeededIndex(fields = listOf("_id"), true, "primary key")).forEach { index: NeededIndex ->
if (index.unique) {
val fields = serializer.serializableProperties!!.filter { index.fields.contains(it.name) }
uniqueIndexChecks.add { changes: List<EntryChange<Model>> ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ data class Mask<T>(
}
}

inline fun <reified T> mask(builder: Mask.Builder<T>.()->Unit): Mask<T> {
return Mask.Builder<T>(serializerOrContextual()).apply(builder).build()
inline fun <reified T> mask(builder: Mask.Builder<T>.(DataClassPath<T, T>)->Unit): Mask<T> {
return Mask.Builder<T>(serializerOrContextual()).apply { builder(path()) }.build()
}

operator fun <T> Condition<T>.invoke(map: Partial<T>): Boolean? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ data class UpdateRestrictions<T>(
/**
* DSL for defining [UpdateRestrictions]
*/
inline fun <reified T> updateRestrictions(builder: UpdateRestrictions.Builder<T>.()->Unit): UpdateRestrictions<T> {
return UpdateRestrictions.Builder<T>(serializerOrContextual()).apply(builder).build()
inline fun <reified T> updateRestrictions(builder: UpdateRestrictions.Builder<T>.(DataClassPath<T, T>)->Unit): UpdateRestrictions<T> {
return UpdateRestrictions.Builder<T>(serializerOrContextual()).apply { builder(path<T>()) }.build()
}
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,8 @@ open class ModelRestEndpoints<USER : HasId<*>?, T : HasId<ID>, ID : Comparable<I
description = "Gets the total number of ${collectionName}s matching the given condition divided by group.",
errorCases = listOf(),
examples = exampleItem()?.let {
sampleConditions().map { c ->
val f = sampleSorts().random().random().field
sampleConditions().mapNotNull { c ->
val f = sampleSorts().randomOrNull()?.randomOrNull()?.field ?: return@mapNotNull null
ApiExample(
GroupCountQuery(c, f),
mapOf(f.getAny(it).toString() to 3)
Expand Down

0 comments on commit 802d2d0

Please sign in to comment.