77package kotlinx.rpc
88
99import org.gradle.api.Action
10+ import org.gradle.api.Project
1011import org.gradle.api.model.ObjectFactory
1112import org.gradle.api.provider.Property
13+ import org.gradle.kotlin.dsl.findByType
1214import org.gradle.kotlin.dsl.newInstance
1315import org.gradle.kotlin.dsl.property
1416import javax.inject.Inject
1517
16- open class RpcExtension @Inject constructor(objects : ObjectFactory ) {
18+ public fun Project.rpcExtension (): RpcExtension = extensions.findByType<RpcExtension >() ? : RpcExtension (objects)
19+
20+ public open class RpcExtension @Inject constructor(objects : ObjectFactory ) {
1721 /* *
1822 * Controls `@Rpc` [annotation type-safety](https://github.com/Kotlin/kotlinx-rpc/pull/240) compile-time checkers.
1923 *
2024 * CAUTION: Disabling is considered unsafe.
2125 * This option is only needed to prevent cases where type-safety analysis fails and valid code can't be compiled.
2226 */
2327 @RpcDangerousApi
24- val annotationTypeSafetyEnabled = objects.property<Boolean >().convention(true )
28+ public val annotationTypeSafetyEnabled: Property < Boolean > = objects.property<Boolean >().convention(true )
2529
2630 /* *
2731 * Strict mode settings.
2832 * Allows configuring the reporting state of deprecated features.
2933 */
30- val strict: RpcStrictModeExtension = objects.newInstance<RpcStrictModeExtension >()
34+ public val strict: RpcStrictModeExtension = objects.newInstance<RpcStrictModeExtension >()
3135
3236 /* *
3337 * Strict mode settings.
3438 * Allows configuring the reporting state of deprecated features.
3539 */
36- fun strict (configure : Action <RpcStrictModeExtension >) {
40+ public fun strict (configure : Action <RpcStrictModeExtension >) {
3741 configure.execute(strict)
3842 }
43+
44+ /* *
45+ * Grpc settings.
46+ */
47+ public val grpc: GrpcExtension = objects.newInstance<GrpcExtension >()
48+
49+ /* *
50+ * Grpc settings.
51+ */
52+ public fun grpc (configure : Action <GrpcExtension >) {
53+ configure.execute(grpc)
54+ }
3955}
4056
41- open class RpcStrictModeExtension @Inject constructor(objects : ObjectFactory ) {
57+ public open class RpcStrictModeExtension @Inject constructor(objects : ObjectFactory ) {
4258 /* *
4359 * `StateFlow`s in RPC services are deprecated,
4460 * due to their error-prone nature.
4561 *
4662 * Consider using plain flows and converting them to state on the application side.
4763 */
48- val stateFlow: Property <RpcStrictMode > = objects.strictModeProperty()
64+ public val stateFlow: Property <RpcStrictMode > = objects.strictModeProperty()
4965
5066 /* *
5167 * `SharedFlow`s in RPC services are deprecated,
5268 * due to their error-prone nature.
5369 *
5470 * Consider using plain flows and converting them to state on the application side.
5571 */
56- val sharedFlow: Property <RpcStrictMode > = objects.strictModeProperty()
72+ public val sharedFlow: Property <RpcStrictMode > = objects.strictModeProperty()
5773
5874 /* *
5975 * Nested flows in RPC services are deprecated,
6076 * due to their error-prone nature.
6177 *
6278 * Consider using plain flows and converting them to state on the application side.
6379 */
64- val nestedFlow: Property <RpcStrictMode > = objects.strictModeProperty()
80+ public val nestedFlow: Property <RpcStrictMode > = objects.strictModeProperty()
6581
6682 /* *
6783 * StreamScoped functions are deprecated.
@@ -80,15 +96,15 @@ open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
8096 *
8197 * Consider returning a Flow and requesting other data in a different method.
8298 */
83- val notTopLevelServerFlow: Property <RpcStrictMode > = objects.strictModeProperty()
99+ public val notTopLevelServerFlow: Property <RpcStrictMode > = objects.strictModeProperty()
84100
85101 /* *
86102 * Fields in RPC services are deprecated,
87103 * due to its error-prone nature.
88104 *
89105 * Consider using regular streaming.
90106 */
91- val fields: Property <RpcStrictMode > = objects.strictModeProperty()
107+ public val fields: Property <RpcStrictMode > = objects.strictModeProperty()
92108
93109 private fun ObjectFactory.strictModeProperty (
94110 default : RpcStrictMode = RpcStrictMode .WARNING ,
@@ -97,8 +113,12 @@ open class RpcStrictModeExtension @Inject constructor(objects: ObjectFactory) {
97113 }
98114}
99115
100- enum class RpcStrictMode {
116+ /* *
117+ * Strict mode inspections levels.
118+ * Correspond to same compiler levels of messages.
119+ */
120+ public enum class RpcStrictMode {
101121 NONE , WARNING , ERROR ;
102122
103- fun toCompilerArg (): String = name.lowercase()
123+ internal fun toCompilerArg (): String = name.lowercase()
104124}
0 commit comments