Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {
}
}

version = "0.0.2"
version = "0.0.3-alpha.1-SNAPSHOT"
group = "io.github.ustudiocompany"

configurations.all {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ detekt = "1.23.7"
dokka = "1.9.20"
gradle-git-version="3.1.0"
knit = "0.5.0"
kotlin = "2.1.0"
kotlin = "2.2.21"
kover = "0.9.0"
license-report = "2.9"
pitest = "1.15.0"
Expand Down
2 changes: 2 additions & 0 deletions library/json/element/api/json-element.api
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class io/github/ustudiocompany/uframework/json/element/JsonElement$
public fun toArray ()[Ljava/lang/Object;
public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object;
public fun toJson ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
}

public final class io/github/ustudiocompany/uframework/json/element/JsonElement$Array$Builder {
Expand Down Expand Up @@ -123,6 +124,7 @@ public final class io/github/ustudiocompany/uframework/json/element/JsonElement$
public fun remove (Ljava/lang/String;)Lio/github/ustudiocompany/uframework/json/element/JsonElement;
public final fun size ()I
public fun toJson ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public final fun values ()Ljava/util/Collection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public sealed interface JsonElement {

public data object Null : JsonElement {
override fun toJson(): String = "null"
override fun toString(): String = "Null()"
}

public data class Bool(val get: Boolean) : JsonElement {
Expand All @@ -27,7 +28,6 @@ public sealed interface JsonElement {

public data class Text(val get: String) : JsonElement {
override fun toJson(): String = "\"$get\""
public override fun toString(): String = get
}

public data class Decimal(val get: BigDecimal) : JsonElement {
Expand Down Expand Up @@ -65,6 +65,8 @@ public sealed interface JsonElement {
override fun equals(other: Any?): Boolean =
this === other || (other is Array && items == other.items)

override fun toString(): String = "Array($items)"

public class Builder {
private val items: MutableList<JsonElement> = mutableListOf()

Expand Down Expand Up @@ -119,6 +121,8 @@ public sealed interface JsonElement {
override fun equals(other: Any?): Boolean =
this === other || (other is Struct && properties == other.properties)

override fun toString(): String = "Struct($properties)"

public class Builder {
private val properties = mutableMapOf<String, JsonElement>()

Expand Down
4 changes: 4 additions & 0 deletions library/rules-engine/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Internal env variables:

- `__RULE_ID__` - identifier of the current executing rule.
- `__STEP_ID__` - identifier of the current executing step.
176 changes: 133 additions & 43 deletions library/rules-engine/core/api/rules-engine-core.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,11 @@ package io.github.ustudiocompany.uframework.rulesengine.core.env

import io.github.ustudiocompany.uframework.json.element.JsonElement

public class EnvVars private constructor(
private val variables: MutableMap<EnvVarName, JsonElement>
) : Iterable<Pair<EnvVarName, JsonElement>> {

public fun isEmpty(): Boolean = variables.isEmpty()

public interface EnvVars : Iterable<EnvVars.Variable> {
public fun isEmpty(): Boolean
public fun isNotEmpty(): Boolean = !isEmpty()
public fun getOrNull(name: EnvVarName): JsonElement?
public operator fun contains(name: EnvVarName): Boolean

public fun getOrNull(envVarName: EnvVarName): JsonElement? = variables[envVarName]

public operator fun contains(envVarName: EnvVarName): Boolean = envVarName in variables

override fun iterator(): Iterator<Pair<EnvVarName, JsonElement>> = EnvVarsIterator(variables)

public companion object {
public val EMPTY: EnvVars = EnvVars(variables = mutableMapOf())

public operator fun invoke(vararg envVars: Pair<EnvVarName, JsonElement>): EnvVars =
if (envVars.isNotEmpty())
EnvVars(variables = envVars.toMap(mutableMapOf()))
else
EMPTY

public operator fun invoke(envVars: Map<EnvVarName, JsonElement> = emptyMap()): EnvVars =
if (envVars.isNotEmpty())
EnvVars(variables = envVars.toMutableMap())
else
EMPTY
}

public class Builder {
private val envVars: MutableMap<EnvVarName, JsonElement> = mutableMapOf()

public operator fun set(envVarName: EnvVarName, value: JsonElement): Builder {
envVars[envVarName] = value
return this
}

public fun build(): EnvVars = if (envVars.isNotEmpty()) EnvVars(envVars) else EMPTY
}

private class EnvVarsIterator(
data: Map<EnvVarName, JsonElement>
) : AbstractIterator<Pair<EnvVarName, JsonElement>>() {
val original = data.iterator()
override fun computeNext() {
if (original.hasNext())
setNext(original.next().toPair())
else
done()
}
}
public data class Variable(val name: EnvVarName, val value: JsonElement)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.ustudiocompany.uframework.rulesengine.core.env

import io.github.ustudiocompany.uframework.json.element.JsonElement

public fun envVarsOf(vararg envVars: Pair<EnvVarName, JsonElement>): EnvVars {
if (envVars.isEmpty()) return EnvVarsMap.EMPTY
val builder = EnvVarsMap.Builder()
for ((name, value) in envVars)
builder[name] = value
return builder.build()
}

private class EnvVarsMap private constructor(
private val variables: Map<EnvVarName, JsonElement>
) : EnvVars {

override fun isEmpty(): Boolean = variables.isEmpty()

override fun getOrNull(name: EnvVarName): JsonElement? = variables[name]

override operator fun contains(name: EnvVarName): Boolean = name in variables

override fun iterator(): Iterator<EnvVars.Variable> = EnvVarsIterator()

companion object {
val EMPTY: EnvVars = EnvVarsMap(variables = mapOf())
}

class Builder {
private val envVars: MutableMap<EnvVarName, JsonElement> = mutableMapOf()

operator fun set(envVarName: EnvVarName, value: JsonElement): Builder {
envVars[envVarName] = value
return this
}

fun build(): EnvVars = if (envVars.isNotEmpty()) EnvVarsMap(envVars) else EMPTY
}

private inner class EnvVarsIterator : AbstractIterator<EnvVars.Variable>() {
val iter = variables.iterator()
override fun computeNext() {
if (iter.hasNext()) {
val item = iter.next()
setNext(EnvVars.Variable(name = item.key, value = item.value))
} else
done()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.ustudiocompany.uframework.rulesengine.core.rule.condition.Condi
import io.github.ustudiocompany.uframework.rulesengine.core.rule.step.Steps

public data class Rule(
public val id: RuleId,
override val condition: Condition,
public val steps: Steps
) : Conditional
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.ustudiocompany.uframework.rulesengine.core.rule

@JvmInline
public value class RuleId(public val get: String)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.ustudiocompany.uframework.rulesengine.core.rule.step
import io.github.ustudiocompany.uframework.rulesengine.core.rule.condition.Condition

public data class DataBuildStep(
public override val id: StepId,
override val condition: Condition,
public val dataSchema: DataSchema,
public val result: StepResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.ustudiocompany.uframework.rulesengine.core.rule.step
import io.github.ustudiocompany.uframework.rulesengine.core.rule.condition.Condition

public data class DataRetrieveStep(
public override val id: StepId,
public override val condition: Condition,
public val uri: Uri,
public val args: Args,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.ustudiocompany.uframework.rulesengine.core.rule.step

import io.github.ustudiocompany.uframework.rulesengine.core.rule.Value

public data class MessageHeader(
public val name: String,
public val value: Value
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.ustudiocompany.uframework.rulesengine.core.rule.step

@JvmInline
public value class MessageHeaders private constructor(public val get: List<MessageHeader>) {

public companion object {
public val NONE: MessageHeaders = MessageHeaders(emptyList())

@JvmStatic
public operator fun invoke(headers: List<MessageHeader>): MessageHeaders =
if (headers.isEmpty()) NONE else MessageHeaders(headers)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.ustudiocompany.uframework.rulesengine.core.rule.step

import io.github.ustudiocompany.uframework.rulesengine.core.rule.Value
import io.github.ustudiocompany.uframework.rulesengine.core.rule.condition.Condition

public data class MessagePublishStep(
public override val id: StepId,
override val condition: Condition,
public val routeKey: Value?,
public val headers: MessageHeaders,
public val body: Value?
) : Step
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package io.github.ustudiocompany.uframework.rulesengine.core.rule.step

import io.github.ustudiocompany.uframework.rulesengine.core.rule.condition.Conditional

public sealed interface Step : Conditional
public sealed interface Step : Conditional {
public val id: StepId
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.ustudiocompany.uframework.rulesengine.core.rule.step

@JvmInline
public value class StepId(public val get: String)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.ustudiocompany.uframework.rulesengine.core.rule.operation.Opera
import io.github.ustudiocompany.uframework.rulesengine.core.rule.operation.operator.Operator

public data class ValidationStep(
public override val id: StepId,
public override val condition: Condition,
override val target: Value,
override val operator: Operator<Boolean>,
Expand Down
Loading
Loading