Skip to content

Commit 8c464de

Browse files
committed
feat(node): support receiving empty inputs
Useful for the Diff Injector Node, which will react to elements removed from the input.
1 parent f6fc917 commit 8c464de

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

api/src/main/kotlin/me/snoty/integration/common/annotation/RegisterNode.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ annotation class RegisterNode(
2424
val inputType: KClass<out Any> = NoSchema::class,
2525
val outputType: KClass<out Any> = NoSchema::class,
2626
)
27+
28+
/**
29+
* Marks that the node wants to receive empty input. Otherwise, following nodes will not be executed at all if no input element was produced by the prior node.
30+
*/
31+
annotation class ReceiveEmptyInput

api/src/main/kotlin/me/snoty/integration/common/model/metadata/NodeMetadata.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ data class NodeMetadata(
1818
@Transient
1919
val settingsClass: KClass<out NodeSettings> = NodeSettings::class, // previously threw an error, but since we deserialize this AND remain compatible, we need to keep this
2020
val input: ObjectSchema?,
21+
val receiveEmptyInput: Boolean = false,
2122
val output: ObjectSchema?
2223
)
2324

integration-plugin/src/main/kotlin/me/snoty/integration/plugin/utils/MetadataGenerator.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.devtools.ksp.KspExperimental
44
import com.google.devtools.ksp.processing.Resolver
55
import com.google.devtools.ksp.symbol.KSClassDeclaration
66
import me.snoty.backend.wiring.node.metadataJson
7+
import me.snoty.integration.common.annotation.ReceiveEmptyInput
78
import me.snoty.integration.common.annotation.RegisterNode
89
import me.snoty.integration.common.model.metadata.NodeMetadata
910
import me.snoty.integration.common.wiring.node.NodeSettings
@@ -20,7 +21,8 @@ fun generateMetadata(resolver: Resolver, clazz: KSClassDeclaration, node: Regist
2021
settingsClass = NodeSettings::class,
2122
settings = generateObjectSchema(resolver, settingsClass)!!,
2223
input = generateObjectSchema(resolver, inputClass),
23-
output = generateObjectSchema(resolver, outputClass)
24+
receiveEmptyInput = clazz.hasAnnotation<ReceiveEmptyInput>(),
25+
output = generateObjectSchema(resolver, outputClass),
2426
)
2527

2628
return metadataJson.encodeToString(metadata)

src/main/kotlin/me/snoty/backend/integration/flow/execution/FlowRunnerImpl.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ class FlowRunnerImpl(
192192
}
193193
.flowOn(span.asContextElement() + MDCContext())
194194
.flatMapConcat { output ->
195-
@Suppress("UnusedFlow") // yeah I don't think so
196-
if (output.isEmpty()) return@flatMapConcat emptyFlow()
197195
node.next
198196
.asFlow()
199197
.mapNotNull { nextNodeId ->
@@ -202,6 +200,7 @@ class FlowRunnerImpl(
202200
null
203201
}
204202
}
203+
.filter { nextNode -> !output.isEmpty() || nodeRegistry.getMetadata(nextNode.descriptor).receiveEmptyInput }
205204
.flatMapConcat { nextNode ->
206205
val subspan = span.subspan(flowTracing, traceName(nextNode)) {
207206
setNodeAttributes(nextNode, output)

0 commit comments

Comments
 (0)