expo-modules-core 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/android/CMakeLists.txt +154 -0
  3. package/android/build.gradle +293 -5
  4. package/android/src/main/cpp/Exceptions.cpp +22 -0
  5. package/android/src/main/cpp/Exceptions.h +38 -0
  6. package/android/src/main/cpp/ExpoModulesHostObject.cpp +47 -0
  7. package/android/src/main/cpp/ExpoModulesHostObject.h +32 -0
  8. package/android/src/main/cpp/JNIFunctionBody.cpp +29 -0
  9. package/android/src/main/cpp/JNIFunctionBody.h +50 -0
  10. package/android/src/main/cpp/JNIInjector.cpp +19 -0
  11. package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +122 -0
  12. package/android/src/main/cpp/JSIInteropModuleRegistry.h +96 -0
  13. package/android/src/main/cpp/JSIObjectWrapper.h +33 -0
  14. package/android/src/main/cpp/JSITypeConverter.h +84 -0
  15. package/android/src/main/cpp/JavaScriptModuleObject.cpp +138 -0
  16. package/android/src/main/cpp/JavaScriptModuleObject.h +122 -0
  17. package/android/src/main/cpp/JavaScriptObject.cpp +125 -0
  18. package/android/src/main/cpp/JavaScriptObject.h +131 -0
  19. package/android/src/main/cpp/JavaScriptRuntime.cpp +127 -0
  20. package/android/src/main/cpp/JavaScriptRuntime.h +87 -0
  21. package/android/src/main/cpp/JavaScriptValue.cpp +172 -0
  22. package/android/src/main/cpp/JavaScriptValue.h +78 -0
  23. package/android/src/main/cpp/MethodMetadata.cpp +230 -0
  24. package/android/src/main/cpp/MethodMetadata.h +92 -0
  25. package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +2 -0
  26. package/android/src/main/java/expo/modules/core/errors/ContextDestroyedException.kt +7 -0
  27. package/android/src/main/java/expo/modules/interfaces/permissions/Permissions.java +30 -0
  28. package/android/src/main/java/expo/modules/kotlin/AppContext.kt +49 -1
  29. package/android/src/main/java/expo/modules/kotlin/ConcatIterator.kt +18 -0
  30. package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +15 -12
  31. package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +39 -3
  32. package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +2 -2
  33. package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +13 -0
  34. package/android/src/main/java/expo/modules/kotlin/exception/ExceptionDecorator.kt +2 -0
  35. package/android/src/main/java/expo/modules/kotlin/functions/AnyFunction.kt +19 -14
  36. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunction.kt +29 -7
  37. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +13 -13
  38. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +18 -0
  39. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromiseComponent.kt +18 -0
  40. package/android/src/main/java/expo/modules/kotlin/functions/SuspendFunctionComponent.kt +56 -0
  41. package/android/src/main/java/expo/modules/kotlin/functions/SyncFunctionComponent.kt +28 -0
  42. package/android/src/main/java/expo/modules/kotlin/jni/CppType.kt +18 -0
  43. package/android/src/main/java/expo/modules/kotlin/jni/JNIFunctionBody.kt +39 -0
  44. package/android/src/main/java/expo/modules/kotlin/jni/JSIInteropModuleRegistry.kt +89 -0
  45. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +44 -0
  46. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +113 -0
  47. package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +35 -0
  48. package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +15 -5
  49. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +65 -111
  50. package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionData.kt +35 -2
  51. package/android/src/main/java/expo/modules/kotlin/providers/AppContextProvider.kt +14 -0
  52. package/android/src/main/java/expo/modules/kotlin/providers/CurrentActivityProvider.kt +22 -0
  53. package/android/src/main/java/expo/modules/kotlin/records/RecordTypeConverter.kt +19 -2
  54. package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +3 -2
  55. package/android/src/main/java/expo/modules/kotlin/types/ArrayTypeConverter.kt +7 -2
  56. package/android/src/main/java/expo/modules/kotlin/types/BasicTypeConverters.kt +68 -20
  57. package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +50 -22
  58. package/android/src/main/java/expo/modules/kotlin/types/ListTypeConverter.kt +18 -2
  59. package/android/src/main/java/expo/modules/kotlin/types/MapTypeConverter.kt +18 -2
  60. package/android/src/main/java/expo/modules/kotlin/types/PairTypeConverter.kt +17 -2
  61. package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +43 -3
  62. package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +5 -0
  63. package/build/NativeModulesProxy.native.d.ts.map +1 -1
  64. package/build/NativeModulesProxy.native.js +9 -3
  65. package/build/NativeModulesProxy.native.js.map +1 -1
  66. package/ios/AppDelegates/EXAppDelegatesLoader.m +1 -2
  67. package/ios/ExpoModulesCore.podspec +1 -1
  68. package/ios/JSI/EXJSIConversions.mm +6 -0
  69. package/ios/JSI/EXJSIInstaller.h +15 -21
  70. package/ios/JSI/EXJSIInstaller.mm +39 -3
  71. package/ios/JSI/EXJSIUtils.h +47 -3
  72. package/ios/JSI/EXJSIUtils.mm +88 -4
  73. package/ios/JSI/EXJavaScriptObject.h +11 -18
  74. package/ios/JSI/EXJavaScriptObject.mm +37 -18
  75. package/ios/JSI/EXJavaScriptRuntime.h +43 -9
  76. package/ios/JSI/EXJavaScriptRuntime.mm +70 -27
  77. package/ios/JSI/EXJavaScriptTypedArray.h +30 -0
  78. package/ios/JSI/EXJavaScriptTypedArray.mm +29 -0
  79. package/ios/JSI/EXJavaScriptValue.h +3 -2
  80. package/ios/JSI/EXJavaScriptValue.mm +17 -20
  81. package/ios/JSI/EXJavaScriptWeakObject.h +23 -0
  82. package/ios/JSI/EXJavaScriptWeakObject.mm +53 -0
  83. package/ios/JSI/EXObjectDeallocator.h +27 -0
  84. package/ios/JSI/ExpoModulesHostObject.h +3 -3
  85. package/ios/JSI/ExpoModulesHostObject.mm +4 -4
  86. package/ios/JSI/JavaScriptRuntime.swift +38 -1
  87. package/ios/JSI/JavaScriptValue.swift +7 -0
  88. package/ios/JSI/TypedArray.cpp +67 -0
  89. package/ios/JSI/TypedArray.h +46 -0
  90. package/ios/ModuleRegistryAdapter/EXModuleRegistryAdapter.m +0 -11
  91. package/ios/NativeModulesProxy/EXNativeModulesProxy.h +17 -10
  92. package/ios/NativeModulesProxy/EXNativeModulesProxy.mm +88 -77
  93. package/ios/NativeModulesProxy/NativeModulesProxyModule.swift +17 -0
  94. package/ios/Services/EXReactNativeEventEmitter.h +2 -2
  95. package/ios/Services/EXReactNativeEventEmitter.m +11 -6
  96. package/ios/Swift/AppContext.swift +208 -28
  97. package/ios/Swift/Arguments/AnyArgument.swift +18 -0
  98. package/ios/Swift/Arguments/{Types/EnumArgumentType.swift → EnumArgument.swift} +2 -17
  99. package/ios/Swift/Classes/ClassComponent.swift +95 -0
  100. package/ios/Swift/Classes/ClassComponentElement.swift +33 -0
  101. package/ios/Swift/Classes/ClassComponentElementsBuilder.swift +34 -0
  102. package/ios/Swift/Classes/ClassComponentFactories.swift +96 -0
  103. package/ios/Swift/DynamicTypes/AnyDynamicType.swift +44 -0
  104. package/ios/Swift/DynamicTypes/DynamicArrayType.swift +56 -0
  105. package/ios/Swift/DynamicTypes/DynamicConvertibleType.swift +27 -0
  106. package/ios/Swift/DynamicTypes/DynamicEnumType.swift +27 -0
  107. package/ios/Swift/DynamicTypes/DynamicOptionalType.swift +63 -0
  108. package/ios/Swift/DynamicTypes/DynamicRawType.swift +33 -0
  109. package/ios/Swift/DynamicTypes/DynamicSharedObjectType.swift +37 -0
  110. package/ios/Swift/DynamicTypes/DynamicType.swift +39 -0
  111. package/ios/Swift/DynamicTypes/DynamicTypedArrayType.swift +46 -0
  112. package/ios/Swift/Exceptions/CodedError.swift +1 -1
  113. package/ios/Swift/Exceptions/Exception.swift +8 -6
  114. package/ios/Swift/Exceptions/UnexpectedException.swift +2 -1
  115. package/ios/Swift/ExpoBridgeModule.m +5 -0
  116. package/ios/Swift/ExpoBridgeModule.swift +65 -0
  117. package/ios/Swift/Functions/AnyFunction.swift +33 -31
  118. package/ios/Swift/Functions/AsyncFunctionComponent.swift +196 -59
  119. package/ios/Swift/Functions/SyncFunctionComponent.swift +142 -58
  120. package/ios/Swift/JavaScriptUtils.swift +32 -57
  121. package/ios/Swift/Logging/LogHandlers.swift +39 -0
  122. package/ios/Swift/Logging/LogType.swift +62 -0
  123. package/ios/Swift/Logging/Logger.swift +198 -0
  124. package/ios/Swift/ModuleHolder.swift +19 -54
  125. package/ios/Swift/ModuleRegistry.swift +7 -1
  126. package/ios/Swift/Modules/AnyModule.swift +3 -3
  127. package/ios/Swift/ModulesProvider.swift +2 -0
  128. package/ios/Swift/Objects/JavaScriptObjectBuilder.swift +37 -0
  129. package/ios/Swift/Objects/ObjectDefinition.swift +74 -1
  130. package/ios/Swift/Objects/ObjectDefinitionComponents.swift +77 -68
  131. package/ios/Swift/Objects/PropertyComponent.swift +147 -0
  132. package/ios/Swift/Promise.swift +12 -3
  133. package/ios/Swift/Records/Field.swift +2 -2
  134. package/ios/Swift/SharedObjects/SharedObject.swift +20 -0
  135. package/ios/Swift/SharedObjects/SharedObjectRegistry.swift +129 -0
  136. package/ios/Swift/TypedArrays/AnyTypedArray.swift +11 -0
  137. package/ios/Swift/TypedArrays/ConcreteTypedArrays.swift +56 -0
  138. package/ios/Swift/TypedArrays/GenericTypedArray.swift +49 -0
  139. package/ios/Swift/TypedArrays/TypedArray.swift +80 -0
  140. package/ios/Swift/Utilities.swift +28 -0
  141. package/ios/Swift/Views/ConcreteViewProp.swift +3 -3
  142. package/ios/Swift/Views/ViewManagerDefinitionComponents.swift +2 -2
  143. package/ios/Tests/ClassComponentSpec.swift +210 -0
  144. package/ios/Tests/DynamicTypeSpec.swift +336 -0
  145. package/ios/Tests/EnumArgumentSpec.swift +48 -0
  146. package/ios/Tests/ExpoModulesSpec.swift +17 -3
  147. package/ios/Tests/FunctionSpec.swift +167 -118
  148. package/ios/Tests/Mocks/ModuleMocks.swift +1 -1
  149. package/ios/Tests/PropertyComponentSpec.swift +95 -0
  150. package/ios/Tests/SharedObjectRegistrySpec.swift +109 -0
  151. package/ios/Tests/TypedArraysSpec.swift +136 -0
  152. package/package.json +2 -2
  153. package/src/NativeModulesProxy.native.ts +13 -3
  154. package/src/ts-declarations/ExpoModules.d.ts +7 -0
  155. package/tsconfig.json +1 -1
  156. package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionWithPromise.kt +0 -15
  157. package/android/src/main/java/expo/modules/kotlin/functions/AsyncSuspendFunction.kt +0 -36
  158. package/ios/Swift/Arguments/AnyArgumentType.swift +0 -13
  159. package/ios/Swift/Arguments/ArgumentType.swift +0 -28
  160. package/ios/Swift/Arguments/Types/ArrayArgumentType.swift +0 -42
  161. package/ios/Swift/Arguments/Types/ConvertibleArgumentType.swift +0 -16
  162. package/ios/Swift/Arguments/Types/OptionalArgumentType.swift +0 -49
  163. package/ios/Swift/Arguments/Types/PromiseArgumentType.swift +0 -15
  164. package/ios/Swift/Arguments/Types/RawArgumentType.swift +0 -25
  165. package/ios/Swift/Functions/ConcreteFunction.swift +0 -103
  166. package/ios/Swift/SwiftInteropBridge.swift +0 -155
  167. package/ios/Tests/ArgumentTypeSpec.swift +0 -143
@@ -0,0 +1,113 @@
1
+ package expo.modules.kotlin.jni
2
+
3
+ import com.facebook.jni.HybridData
4
+ import expo.modules.core.interfaces.DoNotStrip
5
+
6
+ /**
7
+ * A Kotlin representation of jsi::Object.
8
+ * Should be used only on the runtime thread.
9
+ */
10
+ @Suppress("KotlinJniMissingFunction")
11
+ @DoNotStrip
12
+ class JavaScriptObject @DoNotStrip private constructor(@DoNotStrip private val mHybridData: HybridData) {
13
+ /**
14
+ * The property descriptor options for the property being defined or modified.
15
+ */
16
+ enum class PropertyDescriptor(val value: Int) {
17
+ /**
18
+ * If set, the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.
19
+ */
20
+ Configurable(1 shl 0),
21
+
22
+ /**
23
+ * If set, the property shows up during enumeration of the properties on the corresponding object.
24
+ */
25
+ Enumerable(1 shl 1),
26
+
27
+ /**
28
+ * If set, the value associated with the property may be changed with an assignment operator.
29
+ */
30
+ Writable(1 shl 2),
31
+ }
32
+
33
+ external fun hasProperty(name: String): Boolean
34
+ external fun getProperty(name: String): JavaScriptValue
35
+ external fun getPropertyNames(): Array<String>
36
+
37
+ private external fun setBoolProperty(name: String, value: Boolean)
38
+ private external fun setDoubleProperty(name: String, value: Double)
39
+ private external fun setStringProperty(name: String, value: String?)
40
+ private external fun setJSValueProperty(name: String, value: JavaScriptValue?)
41
+ private external fun setJSObjectProperty(name: String, value: JavaScriptObject?)
42
+ private external fun unsetProperty(name: String)
43
+
44
+ private external fun defineBoolProperty(name: String, value: Boolean, options: Int)
45
+ private external fun defineDoubleProperty(name: String, value: Double, options: Int)
46
+ private external fun defineStringProperty(name: String, value: String?, options: Int)
47
+ private external fun defineJSValueProperty(name: String, value: JavaScriptValue?, options: Int)
48
+ private external fun defineJSObjectProperty(name: String, value: JavaScriptObject?, options: Int)
49
+
50
+ fun setProperty(name: String, value: Boolean) = setBoolProperty(name, value)
51
+ fun setProperty(name: String, value: Int) = setDoubleProperty(name, value.toDouble())
52
+ fun setProperty(name: String, value: Double) = setDoubleProperty(name, value)
53
+ fun setProperty(name: String, value: String?) = setStringProperty(name, value)
54
+ fun setProperty(name: String, value: JavaScriptValue?) = setJSValueProperty(name, value)
55
+ fun setProperty(name: String, value: JavaScriptObject?) = setJSObjectProperty(name, value)
56
+
57
+ // Needed to handle untyped null value
58
+ // Without it setProperty(name, null) won't work
59
+ fun setProperty(name: String, `null`: Nothing?) = unsetProperty(name)
60
+
61
+ fun defineProperty(
62
+ name: String,
63
+ value: Boolean,
64
+ options: List<PropertyDescriptor> = emptyList()
65
+ ) = defineBoolProperty(name, value, options.toCppOptions())
66
+
67
+ fun defineProperty(
68
+ name: String,
69
+ value: Int,
70
+ options: List<PropertyDescriptor> = emptyList()
71
+ ) = defineDoubleProperty(name, value.toDouble(), options.toCppOptions())
72
+
73
+ fun defineProperty(
74
+ name: String,
75
+ value: Double,
76
+ options: List<PropertyDescriptor> = emptyList()
77
+ ) = defineDoubleProperty(name, value, options.toCppOptions())
78
+
79
+ fun defineProperty(
80
+ name: String,
81
+ value: String?,
82
+ options: List<PropertyDescriptor> = emptyList()
83
+ ) = defineStringProperty(name, value, options.toCppOptions())
84
+
85
+ fun defineProperty(
86
+ name: String,
87
+ value: JavaScriptValue?,
88
+ options: List<PropertyDescriptor> = emptyList()
89
+ ) = defineJSValueProperty(name, value, options.toCppOptions())
90
+
91
+ fun defineProperty(
92
+ name: String,
93
+ value: JavaScriptObject?,
94
+ options: List<PropertyDescriptor> = emptyList()
95
+ ) = defineJSObjectProperty(name, value, options.toCppOptions())
96
+
97
+ // Needed to handle untyped null value
98
+ fun defineProperty(
99
+ name: String,
100
+ `null`: Nothing?,
101
+ options: List<PropertyDescriptor> = emptyList()
102
+ ) = defineJSObjectProperty(name, null, options.toCppOptions())
103
+
104
+ @Throws(Throwable::class)
105
+ protected fun finalize() {
106
+ mHybridData.resetNative()
107
+ }
108
+ }
109
+
110
+ private fun List<JavaScriptObject.PropertyDescriptor>.toCppOptions(): Int =
111
+ fold(0) { acc, current ->
112
+ acc or current.value
113
+ }
@@ -0,0 +1,35 @@
1
+ package expo.modules.kotlin.jni
2
+
3
+ import com.facebook.jni.HybridData
4
+ import expo.modules.core.interfaces.DoNotStrip
5
+
6
+ /**
7
+ * A Kotlin representation of jsi::Value.
8
+ * Should be used only on the runtime thread.
9
+ */
10
+ @Suppress("KotlinJniMissingFunction")
11
+ @DoNotStrip
12
+ class JavaScriptValue @DoNotStrip private constructor(@DoNotStrip private val mHybridData: HybridData) {
13
+ external fun kind(): String
14
+
15
+ external fun isNull(): Boolean
16
+ external fun isUndefined(): Boolean
17
+ external fun isBool(): Boolean
18
+ external fun isNumber(): Boolean
19
+ external fun isString(): Boolean
20
+ external fun isSymbol(): Boolean
21
+ external fun isFunction(): Boolean
22
+ external fun isArray(): Boolean
23
+ external fun isObject(): Boolean
24
+
25
+ external fun getBool(): Boolean
26
+ external fun getDouble(): Double
27
+ external fun getString(): String
28
+ external fun getObject(): JavaScriptObject
29
+ external fun getArray(): Array<JavaScriptValue>
30
+
31
+ @Throws(Throwable::class)
32
+ protected fun finalize() {
33
+ mHybridData.resetNative()
34
+ }
35
+ }
@@ -3,24 +3,34 @@ package expo.modules.kotlin.modules
3
3
  import android.os.Bundle
4
4
  import expo.modules.core.errors.ModuleDestroyedException
5
5
  import expo.modules.kotlin.AppContext
6
+ import expo.modules.kotlin.providers.AppContextProvider
6
7
  import kotlinx.coroutines.CoroutineScope
7
8
  import kotlinx.coroutines.cancel
8
9
 
9
- abstract class Module {
10
+ abstract class Module : AppContextProvider {
11
+
12
+ // region AppContextProvider
13
+
10
14
  @Suppress("PropertyName")
11
15
  internal var _appContext: AppContext? = null
12
16
 
13
- private val moduleEventEmitter by lazy { appContext.eventEmitter(this) }
14
-
15
- val appContext: AppContext
17
+ override val appContext: AppContext
16
18
  get() = requireNotNull(_appContext) { "The module wasn't created! You can't access the app context." }
17
19
 
20
+ // endregion
21
+
22
+ private val moduleEventEmitter by lazy { appContext.eventEmitter(this) }
23
+
18
24
  @Suppress("PropertyName")
19
25
  @PublishedApi
20
26
  internal lateinit var coroutineScopeDelegate: Lazy<CoroutineScope>
21
27
  val coroutineScope get() = coroutineScopeDelegate.value
22
28
 
23
- fun sendEvent(name: String, body: Bundle?) {
29
+ fun sendEvent(name: String, body: Bundle? = Bundle.EMPTY) {
30
+ moduleEventEmitter?.emit(name, body)
31
+ }
32
+
33
+ fun sendEvent(name: String, body: Map<String, Any?>?) {
24
34
  moduleEventEmitter?.emit(name, body)
25
35
  }
26
36
 
@@ -24,10 +24,11 @@ import expo.modules.kotlin.events.EventListenerWithSenderAndPayload
24
24
  import expo.modules.kotlin.events.EventName
25
25
  import expo.modules.kotlin.events.EventsDefinition
26
26
  import expo.modules.kotlin.events.OnActivityResultPayload
27
- import expo.modules.kotlin.functions.AnyFunction
28
27
  import expo.modules.kotlin.functions.AsyncFunction
29
- import expo.modules.kotlin.functions.AsyncFunctionWithPromise
30
28
  import expo.modules.kotlin.functions.AsyncFunctionBuilder
29
+ import expo.modules.kotlin.functions.AsyncFunctionComponent
30
+ import expo.modules.kotlin.functions.AsyncFunctionWithPromiseComponent
31
+ import expo.modules.kotlin.functions.SyncFunctionComponent
31
32
  import expo.modules.kotlin.types.toAnyType
32
33
  import expo.modules.kotlin.views.ViewManagerDefinition
33
34
  import expo.modules.kotlin.views.ViewManagerDefinitionBuilder
@@ -41,7 +42,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
41
42
  private var functionBuilders = mutableListOf<AsyncFunctionBuilder>()
42
43
 
43
44
  @PublishedApi
44
- internal var methods = mutableMapOf<String, AnyFunction>()
45
+ internal var syncFunctions = mutableMapOf<String, SyncFunctionComponent>()
46
+
47
+ @PublishedApi
48
+ internal var asyncFunctions = mutableMapOf<String, AsyncFunction>()
45
49
 
46
50
  @PublishedApi
47
51
  internal var viewManagerDefinition: ViewManagerDefinition? = null
@@ -55,7 +59,9 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
55
59
  return ModuleDefinitionData(
56
60
  requireNotNull(moduleName),
57
61
  constantsProvider,
58
- methods + functionBuilders.associate { it.build() },
62
+ syncFunctions,
63
+ asyncFunctions,
64
+ functionBuilders.map { it.build() },
59
65
  viewManagerDefinition,
60
66
  eventListeners,
61
67
  eventsDefinition
@@ -101,146 +107,94 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
101
107
  constantsProvider = { constants.toMap() }
102
108
  }
103
109
 
104
- @Deprecated(
105
- message = "The 'function' component was deprecated and will change its behavior in the future.",
106
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
107
- )
108
- @JvmName("functionWithoutArgs")
109
- inline fun function(
110
+ @JvmName("FunctionWithoutArgs")
111
+ inline fun Function(
110
112
  name: String,
111
113
  crossinline body: () -> Any?
112
114
  ) {
113
- methods[name] = AsyncFunction(name, arrayOf()) { body() }
115
+ SyncFunctionComponent(name, arrayOf()) { body() }.also {
116
+ syncFunctions[name] = it
117
+ }
114
118
  }
115
119
 
116
- @Deprecated(
117
- message = "The 'function' component was deprecated and will change its behavior in the future.",
118
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
119
- )
120
- inline fun <reified R> function(
120
+ inline fun <reified R> Function(
121
121
  name: String,
122
122
  crossinline body: () -> R
123
123
  ) {
124
- methods[name] = AsyncFunction(name, arrayOf()) { body() }
124
+ SyncFunctionComponent(name, arrayOf()) { body() }.also {
125
+ syncFunctions[name] = it
126
+ }
125
127
  }
126
128
 
127
- @Deprecated(
128
- message = "The 'function' component was deprecated and will change its behavior in the future.",
129
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
130
- )
131
- inline fun <reified R, reified P0> function(
129
+ inline fun <reified R, reified P0> Function(
132
130
  name: String,
133
131
  crossinline body: (p0: P0) -> R
134
132
  ) {
135
- methods[name] = if (P0::class == Promise::class) {
136
- AsyncFunctionWithPromise(name, arrayOf()) { _, promise -> body(promise as P0) }
137
- } else {
138
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
133
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }.also {
134
+ syncFunctions[name] = it
139
135
  }
140
136
  }
141
137
 
142
- @Deprecated(
143
- message = "The 'function' component was deprecated and will change its behavior in the future.",
144
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
145
- )
146
- inline fun <reified R, reified P0, reified P1> function(
138
+ inline fun <reified R, reified P0, reified P1> Function(
147
139
  name: String,
148
140
  crossinline body: (p0: P0, p1: P1) -> R
149
141
  ) {
150
- methods[name] = if (P1::class == Promise::class) {
151
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
152
- } else {
153
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
142
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }.also {
143
+ syncFunctions[name] = it
154
144
  }
155
145
  }
156
146
 
157
- @Deprecated(
158
- message = "The 'function' component was deprecated and will change its behavior in the future.",
159
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
160
- )
161
- inline fun <reified R, reified P0, reified P1, reified P2> function(
147
+ inline fun <reified R, reified P0, reified P1, reified P2> Function(
162
148
  name: String,
163
149
  crossinline body: (p0: P0, p1: P1, p2: P2) -> R
164
150
  ) {
165
- methods[name] = if (P2::class == Promise::class) {
166
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
167
- } else {
168
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
151
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }.also {
152
+ syncFunctions[name] = it
169
153
  }
170
154
  }
171
155
 
172
- @Deprecated(
173
- message = "The 'function' component was deprecated and will change its behavior in the future.",
174
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
175
- )
176
156
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3> function(
177
157
  name: String,
178
158
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
179
159
  ) {
180
- methods[name] = if (P3::class == Promise::class) {
181
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
182
- } else {
183
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
160
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }.also {
161
+ syncFunctions[name] = it
184
162
  }
185
163
  }
186
164
 
187
- @Deprecated(
188
- message = "The 'function' component was deprecated and will change its behavior in the future.",
189
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
190
- )
191
165
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4> function(
192
166
  name: String,
193
167
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
194
168
  ) {
195
- methods[name] = if (P4::class == Promise::class) {
196
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
197
- } else {
198
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
169
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }.also {
170
+ syncFunctions[name] = it
199
171
  }
200
172
  }
201
173
 
202
- @Deprecated(
203
- message = "The 'function' component was deprecated and will change its behavior in the future.",
204
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
205
- )
206
- inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> function(
174
+ inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5> Function(
207
175
  name: String,
208
176
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
209
177
  ) {
210
- methods[name] = if (P5::class == Promise::class) {
211
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
212
- } else {
213
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
178
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }.also {
179
+ syncFunctions[name] = it
214
180
  }
215
181
  }
216
182
 
217
- @Deprecated(
218
- message = "The 'function' component was deprecated and will change its behavior in the future.",
219
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
220
- )
221
183
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6> function(
222
184
  name: String,
223
185
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
224
186
  ) {
225
- methods[name] = if (P6::class == Promise::class) {
226
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
227
- } else {
228
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
187
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }.also {
188
+ syncFunctions[name] = it
229
189
  }
230
190
  }
231
191
 
232
- @Deprecated(
233
- message = "The 'function' component was deprecated and will change its behavior in the future.",
234
- replaceWith = ReplaceWith("AsyncFunction(name, body)")
235
- )
236
192
  inline fun <reified R, reified P0, reified P1, reified P2, reified P3, reified P4, reified P5, reified P6, reified P7> function(
237
193
  name: String,
238
194
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
239
195
  ) {
240
- methods[name] = if (P7::class == Promise::class) {
241
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
242
- } else {
243
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
196
+ SyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }.also {
197
+ syncFunctions[name] = it
244
198
  }
245
199
  }
246
200
 
@@ -259,7 +213,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
259
213
  name: String,
260
214
  crossinline body: () -> Any?
261
215
  ) {
262
- methods[name] = AsyncFunction(name, arrayOf()) { body() }
216
+ asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
263
217
  }
264
218
 
265
219
  @Deprecated(
@@ -275,7 +229,7 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
275
229
  name: String,
276
230
  crossinline body: () -> R
277
231
  ) {
278
- methods[name] = AsyncFunction(name, arrayOf()) { body() }
232
+ asyncFunctions[name] = AsyncFunctionComponent(name, arrayOf()) { body() }
279
233
  }
280
234
 
281
235
  @Deprecated(
@@ -291,10 +245,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
291
245
  name: String,
292
246
  crossinline body: (p0: P0) -> R
293
247
  ) {
294
- methods[name] = if (P0::class == Promise::class) {
295
- AsyncFunctionWithPromise(name, arrayOf()) { _, promise -> body(promise as P0) }
248
+ asyncFunctions[name] = if (P0::class == Promise::class) {
249
+ AsyncFunctionWithPromiseComponent(name, arrayOf()) { _, promise -> body(promise as P0) }
296
250
  } else {
297
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
251
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType())) { body(it[0] as P0) }
298
252
  }
299
253
  }
300
254
 
@@ -311,10 +265,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
311
265
  name: String,
312
266
  crossinline body: (p0: P0, p1: P1) -> R
313
267
  ) {
314
- methods[name] = if (P1::class == Promise::class) {
315
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
268
+ asyncFunctions[name] = if (P1::class == Promise::class) {
269
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType())) { args, promise -> body(args[0] as P0, promise as P1) }
316
270
  } else {
317
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
271
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { body(it[0] as P0, it[1] as P1) }
318
272
  }
319
273
  }
320
274
 
@@ -331,10 +285,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
331
285
  name: String,
332
286
  crossinline body: (p0: P0, p1: P1, p2: P2) -> R
333
287
  ) {
334
- methods[name] = if (P2::class == Promise::class) {
335
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
288
+ asyncFunctions[name] = if (P2::class == Promise::class) {
289
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, promise as P2) }
336
290
  } else {
337
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
291
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2) }
338
292
  }
339
293
  }
340
294
 
@@ -351,10 +305,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
351
305
  name: String,
352
306
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3) -> R
353
307
  ) {
354
- methods[name] = if (P3::class == Promise::class) {
355
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
308
+ asyncFunctions[name] = if (P3::class == Promise::class) {
309
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, promise as P3) }
356
310
  } else {
357
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
311
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3) }
358
312
  }
359
313
  }
360
314
 
@@ -371,10 +325,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
371
325
  name: String,
372
326
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4) -> R
373
327
  ) {
374
- methods[name] = if (P4::class == Promise::class) {
375
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
328
+ asyncFunctions[name] = if (P4::class == Promise::class) {
329
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, promise as P4) }
376
330
  } else {
377
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
331
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4) }
378
332
  }
379
333
  }
380
334
 
@@ -391,10 +345,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
391
345
  name: String,
392
346
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) -> R
393
347
  ) {
394
- methods[name] = if (P5::class == Promise::class) {
395
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
348
+ asyncFunctions[name] = if (P5::class == Promise::class) {
349
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, promise as P5) }
396
350
  } else {
397
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
351
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5) }
398
352
  }
399
353
  }
400
354
 
@@ -411,10 +365,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
411
365
  name: String,
412
366
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) -> R
413
367
  ) {
414
- methods[name] = if (P6::class == Promise::class) {
415
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
368
+ asyncFunctions[name] = if (P6::class == Promise::class) {
369
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, promise as P6) }
416
370
  } else {
417
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
371
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6) }
418
372
  }
419
373
  }
420
374
 
@@ -431,10 +385,10 @@ class ModuleDefinitionBuilder(@PublishedApi internal val module: Module? = null)
431
385
  name: String,
432
386
  crossinline body: (p0: P0, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) -> R
433
387
  ) {
434
- methods[name] = if (P7::class == Promise::class) {
435
- AsyncFunctionWithPromise(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
388
+ asyncFunctions[name] = if (P7::class == Promise::class) {
389
+ AsyncFunctionWithPromiseComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType())) { args, promise -> body(args[0] as P0, args[1] as P1, args[2] as P2, args[3] as P3, args[4] as P4, args[5] as P5, args[6] as P6, promise as P7) }
436
390
  } else {
437
- AsyncFunction(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
391
+ AsyncFunctionComponent(name, arrayOf(typeOf<P0>().toAnyType(), typeOf<P1>().toAnyType(), typeOf<P2>().toAnyType(), typeOf<P3>().toAnyType(), typeOf<P4>().toAnyType(), typeOf<P5>().toAnyType(), typeOf<P6>().toAnyType(), typeOf<P7>().toAnyType())) { body(it[0] as P0, it[1] as P1, it[2] as P2, it[3] as P3, it[4] as P4, it[5] as P5, it[6] as P6, it[7] as P7) }
438
392
  }
439
393
  }
440
394
 
@@ -1,16 +1,49 @@
1
1
  package expo.modules.kotlin.modules
2
2
 
3
+ import expo.modules.kotlin.ConcatIterator
4
+ import expo.modules.kotlin.ModuleHolder
3
5
  import expo.modules.kotlin.events.EventListener
4
6
  import expo.modules.kotlin.events.EventName
5
7
  import expo.modules.kotlin.events.EventsDefinition
6
- import expo.modules.kotlin.functions.AnyFunction
8
+ import expo.modules.kotlin.functions.AsyncFunction
9
+ import expo.modules.kotlin.functions.SuspendFunctionComponentBuilder
10
+ import expo.modules.kotlin.functions.SyncFunctionComponent
7
11
  import expo.modules.kotlin.views.ViewManagerDefinition
8
12
 
13
+ /**
14
+ * Intermediate data used to create a proper [ProcessedModuleDefinition].
15
+ * It contains all, unprocessed data from [ModuleDefinitionBuilder].
16
+ */
9
17
  class ModuleDefinitionData(
10
18
  val name: String,
11
19
  val constantsProvider: () -> Map<String, Any?>,
12
- val methods: Map<String, AnyFunction>,
20
+ val syncFunctions: Map<String, SyncFunctionComponent>,
21
+ val asyncFunctions: Map<String, AsyncFunction>,
22
+ val suspendFunctionBuilders: List<SuspendFunctionComponentBuilder>,
13
23
  val viewManagerDefinition: ViewManagerDefinition? = null,
14
24
  val eventListeners: Map<EventName, EventListener> = emptyMap(),
15
25
  val eventsDefinition: EventsDefinition? = null
16
26
  )
27
+
28
+ /**
29
+ * A final version of the ModuleDefinition.
30
+ * Most values are just copied from [ModuleDefinitionData].
31
+ * However some fields like `asyncFunctions` need to be processed or bound with the [ModuleHolder].
32
+ */
33
+ class ProcessedModuleDefinition(
34
+ data: ModuleDefinitionData,
35
+ moduleHolder: ModuleHolder
36
+ ) {
37
+ val name = data.name
38
+ val constantsProvider = data.constantsProvider
39
+ val syncFunctions = data.syncFunctions
40
+ val asyncFunctions = data.asyncFunctions + data.suspendFunctionBuilders.associate { builder ->
41
+ builder.name to builder.build((moduleHolder))
42
+ }
43
+ val viewManagerDefinition = data.viewManagerDefinition
44
+ val eventListeners = data.eventListeners
45
+ val eventsDefinition = data.eventsDefinition
46
+
47
+ val functions
48
+ get() = ConcatIterator(syncFunctions.values.iterator(), asyncFunctions.values.iterator())
49
+ }
@@ -0,0 +1,14 @@
1
+ package expo.modules.kotlin.providers
2
+
3
+ import expo.modules.kotlin.AppContext
4
+
5
+ /**
6
+ * Provider that allows accessing [AppContext] and all it's public parts (e.g. [AppContext.reactContext]).
7
+ */
8
+ interface AppContextProvider {
9
+ /**
10
+ * [AppContext] reference. If it's not possible to access the [AppContext], because it's null
11
+ * then it's an invalid situation and should result in throwing descriptive error.
12
+ */
13
+ val appContext: AppContext
14
+ }
@@ -0,0 +1,22 @@
1
+ package expo.modules.kotlin.providers
2
+
3
+ import com.facebook.react.ReactActivity
4
+ import androidx.appcompat.app.AppCompatActivity
5
+ import androidx.fragment.app.FragmentActivity
6
+ import androidx.core.app.ComponentActivity
7
+ import android.app.Activity
8
+
9
+ /**
10
+ * A class that provides the accessor to the [ReactActivity]. It enables accessing
11
+ * AndroidX/Android Jetpack features in Expo libraries coming from all subclassing chain:
12
+ * [AppCompatActivity], [FragmentActivity], [ComponentActivity], [Activity]
13
+ */
14
+ interface CurrentActivityProvider {
15
+ /**
16
+ * Returns the current [Activity] that should be an instance of [AppCompatActivity].
17
+ * This activity is most likely an instance of [ReactActivity], but it's been decided not to expose
18
+ * `react-native` symbols via `expo-module-core` public API.
19
+ * @returns null if the [Activity] is not yet available (eg. Application has not yet fully started)
20
+ */
21
+ val currentActivity: AppCompatActivity?
22
+ }