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
87 changes: 76 additions & 11 deletions buildSrc/src/main/kotlin/Active.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FunSpec
Expand Down Expand Up @@ -40,7 +41,7 @@ object Active : FunctionProvider {
val publisherPatternSupplierParameter =
ParameterSpec.builder(
"supplier",
pathVariablesSupplierClassName.parameterizedBy(
requestSupplierClassName.parameterizedBy(
publisherType.className.parameterizedBy(projectedParameterTypeName),
),
)
Expand All @@ -61,7 +62,7 @@ object Active : FunctionProvider {
.addParameter(publisherPatternSupplierParameter)
.addCode(
"""
%N.%N(%N, %N) { %N.asFlow(%N(it, %N.extractPathVariables(it))) }
%N.%N(%N, %N) { %N.asFlow(with(%N) { %T(it, %N.extractPathVariables(it), %N.extractQueryParameters(it)).invoke() }) }
"""
.trimIndent(),
binderProperty,
Expand All @@ -70,6 +71,8 @@ object Active : FunctionProvider {
antNamespaceParameter,
adapterProperty,
publisherPatternSupplierParameter,
requestClassName,
antNamespaceParameter,
antNamespaceParameter,
)
.build()
Expand Down Expand Up @@ -101,6 +104,66 @@ object Active : FunctionProvider {
)
.build()

val deprecatedSupplierParameter =
ParameterSpec.builder(
"supplier",
pathVariablesSupplierClassName.parameterizedBy(
publisherType.className.parameterizedBy(projectedParameterTypeName),
),
)
.build()

val deprecatedAnnotation =
AnnotationSpec.builder(Deprecated::class)
.addMember(
"%S",
"Use the supplier overload taking a Request, which also carries query parameters.",
)
.build()

val suppressDeprecationAnnotation =
AnnotationSpec.builder(Suppress::class).addMember("%S", "DEPRECATION").build()

val byNamespaceDeprecatedFunction =
FunSpec.builder("namespace")
.addAnnotation(deprecatedAnnotation)
.addAnnotation(suppressDeprecationAnnotation)
.addAnnotation(JvmOverloads::class)
.addParameter(antNamespaceParameter)
.addParameter(configureParameter)
.addParameter(deprecatedSupplierParameter)
.addCode(
"%N(%N, %N, %T { %N(path, pathVariables) })",
byNamespaceFunction,
antNamespaceParameter,
configureParameter,
requestSupplierClassName,
deprecatedSupplierParameter,
)
.build()

val byPatternDeprecatedFunction =
FunSpec.builder("pattern")
.addAnnotation(deprecatedAnnotation)
.addAnnotation(suppressDeprecationAnnotation)
.addAnnotation(JvmOverloads::class)
.addParameter(patternParameter)
.addParameter(configureParameter)
.addParameter(deprecatedSupplierParameter)
.addCode(
"""
val namespace = %T(%N)
%N(namespace, %N, %N)
"""
.trimIndent(),
antPatternNamespaceClassName,
patternParameter,
byNamespaceDeprecatedFunction,
configureParameter,
deprecatedSupplierParameter,
)
.build()

val byPathFunction =
FunSpec.builder("path")
.addAnnotation(JvmOverloads::class)
Expand All @@ -112,7 +175,7 @@ object Active : FunctionProvider {
"""
val namespace = %T(%N)
check(namespace.isExact) { %S }
%N(namespace, %N) { _, _ -> %N }
%N(namespace, %N) { %N }
"""
.trimIndent(),
antPatternNamespaceClassName,
Expand Down Expand Up @@ -151,7 +214,9 @@ object Active : FunctionProvider {
return Functions(
listOf(
byNamespaceFunction,
byNamespaceDeprecatedFunction,
byPatternFunction,
byPatternDeprecatedFunction,
byPathFunction,
byPathValueFunction,
),
Expand All @@ -169,14 +234,14 @@ object Active : FunctionProvider {
Bind a [%N] to a [%N] of data publishers.

For example, if a [%T] for /fx/ is bound then when a request for /fx/gbpusd is received
the [%N] will be called with /fx/gbpusd as the %N parameter to return a [%T] which will be subscribed to
the [%N] will be called with a [%T] whose path is /fx/gbpusd to return a [%T] which will be subscribed to
in order to provide data.

@param %N A namespace for matching subjects for which this [%N] will be invoked.
@param %N A configuration block that can be used to set up the behaviour of this publisher.
@param %N This will be invoked on each incoming request. It should parse the `subject` and provide a
%T capable of supplying data in response.

@see %T
@see %T
@see %T
Expand All @@ -186,7 +251,7 @@ object Active : FunctionProvider {
flowSupplierParameter,
prefixNamespaceClassName,
flowSupplierParameter,
pathParameter,
requestClassName,
publisherType,
antNamespaceParameter,
flowSupplierParameter,
Expand All @@ -210,21 +275,21 @@ object Active : FunctionProvider {
Bind an ant pattern to a [%N] of data publishers.

For example, if [%N] is provided as /fx/* then when a request for /fx/gbpusd is received
the [%N] will be called with /fx/gbpusd as the %N parameter to return a [%T] which will be subscribed to
the [%N] will be called with a [%T] whose path is /fx/gbpusd to return a [%T] which will be subscribed to
in order to provide data.

@param %N The ant pattern for matching subjects for which this [%N] will be invoked.
@param %N A configuration block that can be used to set up the behaviour of this publisher.
@param %N This will be invoked on each incoming request. It should parse the `subject` and provide a
%T capable of supplying data in response.

@see %T
"""
.trimIndent(),
flowSupplierParameter,
patternParameter,
flowSupplierParameter,
pathParameter,
requestClassName,
publisherType,
patternParameter,
flowSupplierParameter,
Expand Down
71 changes: 68 additions & 3 deletions buildSrc/src/main/kotlin/ActiveContainer.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.squareup.kotlinpoet.AnnotationSpec
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.MemberName
Expand Down Expand Up @@ -46,7 +47,7 @@ object ActiveContainer : FunctionProvider {
val publisherPatternSupplierParameter =
ParameterSpec.builder(
"supplier",
pathVariablesSupplierClassName.parameterizedBy(
requestSupplierClassName.parameterizedBy(
publisherType.className.parameterizedBy(containerEventTypeName),
),
)
Expand All @@ -60,7 +61,7 @@ object ActiveContainer : FunctionProvider {
.addParameter(publisherPatternSupplierParameter)
.addCode(
"""
%N.%N(%N, %N) { path -> %N.asFlow(%N(path, %N.extractPathVariables(path))) }
%N.%N(%N, %N) { path -> %N.asFlow(with(%N) { %T(path, %N.extractPathVariables(path), %N.extractQueryParameters(path)).invoke() }) }
"""
.trimIndent(),
binderProperty,
Expand All @@ -69,6 +70,8 @@ object ActiveContainer : FunctionProvider {
antNamespaceParameter,
adapterProperty,
publisherPatternSupplierParameter,
requestClassName,
antNamespaceParameter,
antNamespaceParameter,
)
.build()
Expand All @@ -93,6 +96,66 @@ object ActiveContainer : FunctionProvider {
)
.build()

val deprecatedSupplierParameter =
ParameterSpec.builder(
"supplier",
pathVariablesSupplierClassName.parameterizedBy(
publisherType.className.parameterizedBy(containerEventTypeName),
),
)
.build()

val deprecatedAnnotation =
AnnotationSpec.builder(Deprecated::class)
.addMember(
"%S",
"Use the supplier overload taking a Request, which also carries query parameters.",
)
.build()

val suppressDeprecationAnnotation =
AnnotationSpec.builder(Suppress::class).addMember("%S", "DEPRECATION").build()

val byNamespaceDeprecatedFunction =
FunSpec.builder("namespace")
.addAnnotation(deprecatedAnnotation)
.addAnnotation(suppressDeprecationAnnotation)
.addAnnotation(JvmOverloads::class)
.addParameter(antNamespaceParameter)
.addParameter(configureParameter)
.addParameter(deprecatedSupplierParameter)
.addCode(
"%N(%N, %N, %T { %N(path, pathVariables) })",
primaryFunction,
antNamespaceParameter,
configureParameter,
requestSupplierClassName,
deprecatedSupplierParameter,
)
.build()

val byPatternDeprecatedFunction =
FunSpec.builder("pattern")
.addAnnotation(deprecatedAnnotation)
.addAnnotation(suppressDeprecationAnnotation)
.addAnnotation(JvmOverloads::class)
.addParameter(patternParameter)
.addParameter(configureParameter)
.addParameter(deprecatedSupplierParameter)
.addCode(
"""
val namespace = %T(%N)
%N(namespace, %N, %N)
"""
.trimIndent(),
antPatternNamespaceClassName,
patternParameter,
byNamespaceDeprecatedFunction,
configureParameter,
deprecatedSupplierParameter,
)
.build()

val byPathFunction =
FunSpec.builder("path")
.addAnnotation(JvmOverloads::class)
Expand All @@ -103,7 +166,7 @@ object ActiveContainer : FunctionProvider {
"""
val namespace = %T(%N)
check(namespace.isExact) { %S }
%N(namespace, %N) { _, _ -> %N }
%N(namespace, %N) { %N }
"""
.trimIndent(),
antPatternNamespaceClassName,
Expand Down Expand Up @@ -142,7 +205,9 @@ object ActiveContainer : FunctionProvider {
return Functions(
listOf(
primaryFunction,
byNamespaceDeprecatedFunction,
byPatternFunction,
byPatternDeprecatedFunction,
byPathFunction,
byPathValueFunction,
),
Expand Down
Loading
Loading