expo-modules-core 0.9.2 → 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 +18 -5
  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 +85 -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
@@ -42,10 +42,11 @@ public func Constants(_ body: @autoclosure @escaping () -> [String: Any?]) -> An
42
42
  public func function<R>(
43
43
  _ name: String,
44
44
  _ closure: @escaping () throws -> R
45
- ) -> AnyFunction {
46
- return ConcreteFunction(
45
+ ) -> AsyncFunctionComponent<(), Void, R> {
46
+ return AsyncFunctionComponent(
47
47
  name,
48
- argTypes: [],
48
+ firstArgType: Void.self,
49
+ dynamicArgumentTypes: [],
49
50
  closure
50
51
  )
51
52
  }
@@ -57,10 +58,11 @@ public func function<R>(
57
58
  public func function<R, A0: AnyArgument>(
58
59
  _ name: String,
59
60
  _ closure: @escaping (A0) throws -> R
60
- ) -> AnyFunction {
61
- return ConcreteFunction(
61
+ ) -> AsyncFunctionComponent<(A0), A0, R> {
62
+ return AsyncFunctionComponent(
62
63
  name,
63
- argTypes: [ArgumentType(A0.self)],
64
+ firstArgType: A0.self,
65
+ dynamicArgumentTypes: [~A0.self],
64
66
  closure
65
67
  )
66
68
  }
@@ -72,10 +74,11 @@ public func function<R, A0: AnyArgument>(
72
74
  public func function<R, A0: AnyArgument, A1: AnyArgument>(
73
75
  _ name: String,
74
76
  _ closure: @escaping (A0, A1) throws -> R
75
- ) -> AnyFunction {
76
- return ConcreteFunction(
77
+ ) -> AsyncFunctionComponent<(A0, A1), A0, R> {
78
+ return AsyncFunctionComponent(
77
79
  name,
78
- argTypes: [ArgumentType(A0.self), ArgumentType(A1.self)],
80
+ firstArgType: A0.self,
81
+ dynamicArgumentTypes: [~A0.self, ~A1.self],
79
82
  closure
80
83
  )
81
84
  }
@@ -87,13 +90,14 @@ public func function<R, A0: AnyArgument, A1: AnyArgument>(
87
90
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument>(
88
91
  _ name: String,
89
92
  _ closure: @escaping (A0, A1, A2) throws -> R
90
- ) -> AnyFunction {
91
- return ConcreteFunction(
93
+ ) -> AsyncFunctionComponent<(A0, A1, A2), A0, R> {
94
+ return AsyncFunctionComponent(
92
95
  name,
93
- argTypes: [
94
- ArgumentType(A0.self),
95
- ArgumentType(A1.self),
96
- ArgumentType(A2.self)
96
+ firstArgType: A0.self,
97
+ dynamicArgumentTypes: [
98
+ ~A0.self,
99
+ ~A1.self,
100
+ ~A2.self
97
101
  ],
98
102
  closure
99
103
  )
@@ -106,14 +110,15 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument>(
106
110
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument>(
107
111
  _ name: String,
108
112
  _ closure: @escaping (A0, A1, A2, A3) throws -> R
109
- ) -> AnyFunction {
110
- return ConcreteFunction(
113
+ ) -> AsyncFunctionComponent<(A0, A1, A2, A3), A0, R> {
114
+ return AsyncFunctionComponent(
111
115
  name,
112
- argTypes: [
113
- ArgumentType(A0.self),
114
- ArgumentType(A1.self),
115
- ArgumentType(A2.self),
116
- ArgumentType(A3.self)
116
+ firstArgType: A0.self,
117
+ dynamicArgumentTypes: [
118
+ ~A0.self,
119
+ ~A1.self,
120
+ ~A2.self,
121
+ ~A3.self
117
122
  ],
118
123
  closure
119
124
  )
@@ -126,15 +131,16 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
126
131
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument>(
127
132
  _ name: String,
128
133
  _ closure: @escaping (A0, A1, A2, A3, A4) throws -> R
129
- ) -> AnyFunction {
130
- return ConcreteFunction(
134
+ ) -> AsyncFunctionComponent<(A0, A1, A2, A3, A4), A0, R> {
135
+ return AsyncFunctionComponent(
131
136
  name,
132
- argTypes: [
133
- ArgumentType(A0.self),
134
- ArgumentType(A1.self),
135
- ArgumentType(A2.self),
136
- ArgumentType(A3.self),
137
- ArgumentType(A4.self)
137
+ firstArgType: A0.self,
138
+ dynamicArgumentTypes: [
139
+ ~A0.self,
140
+ ~A1.self,
141
+ ~A2.self,
142
+ ~A3.self,
143
+ ~A4.self
138
144
  ],
139
145
  closure
140
146
  )
@@ -147,16 +153,17 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
147
153
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument>(
148
154
  _ name: String,
149
155
  _ closure: @escaping (A0, A1, A2, A3, A4, A5) throws -> R
150
- ) -> AnyFunction {
151
- return ConcreteFunction(
156
+ ) -> AsyncFunctionComponent<(A0, A1, A2, A3, A4, A5), A0, R> {
157
+ return AsyncFunctionComponent(
152
158
  name,
153
- argTypes: [
154
- ArgumentType(A0.self),
155
- ArgumentType(A1.self),
156
- ArgumentType(A2.self),
157
- ArgumentType(A3.self),
158
- ArgumentType(A4.self),
159
- ArgumentType(A5.self)
159
+ firstArgType: A0.self,
160
+ dynamicArgumentTypes: [
161
+ ~A0.self,
162
+ ~A1.self,
163
+ ~A2.self,
164
+ ~A3.self,
165
+ ~A4.self,
166
+ ~A5.self
160
167
  ],
161
168
  closure
162
169
  )
@@ -169,17 +176,18 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
169
176
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument, A6: AnyArgument>(
170
177
  _ name: String,
171
178
  _ closure: @escaping (A0, A1, A2, A3, A4, A5, A6) throws -> R
172
- ) -> AnyFunction {
173
- return ConcreteFunction(
179
+ ) -> AsyncFunctionComponent<(A0, A1, A2, A3, A4, A5, A6), A0, R> {
180
+ return AsyncFunctionComponent(
174
181
  name,
175
- argTypes: [
176
- ArgumentType(A0.self),
177
- ArgumentType(A1.self),
178
- ArgumentType(A2.self),
179
- ArgumentType(A3.self),
180
- ArgumentType(A4.self),
181
- ArgumentType(A5.self),
182
- ArgumentType(A6.self)
182
+ firstArgType: A0.self,
183
+ dynamicArgumentTypes: [
184
+ ~A0.self,
185
+ ~A1.self,
186
+ ~A2.self,
187
+ ~A3.self,
188
+ ~A4.self,
189
+ ~A5.self,
190
+ ~A6.self
183
191
  ],
184
192
  closure
185
193
  )
@@ -192,18 +200,19 @@ public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: A
192
200
  public func function<R, A0: AnyArgument, A1: AnyArgument, A2: AnyArgument, A3: AnyArgument, A4: AnyArgument, A5: AnyArgument, A6: AnyArgument, A7: AnyArgument>(
193
201
  _ name: String,
194
202
  _ closure: @escaping (A0, A1, A2, A3, A4, A5, A6, A7) throws -> R
195
- ) -> AnyFunction {
196
- return ConcreteFunction(
203
+ ) -> AsyncFunctionComponent<(A0, A1, A2, A3, A4, A5, A6, A7), A0, R> {
204
+ return AsyncFunctionComponent(
197
205
  name,
198
- argTypes: [
199
- ArgumentType(A0.self),
200
- ArgumentType(A1.self),
201
- ArgumentType(A2.self),
202
- ArgumentType(A3.self),
203
- ArgumentType(A4.self),
204
- ArgumentType(A5.self),
205
- ArgumentType(A6.self),
206
- ArgumentType(A7.self)
206
+ firstArgType: A0.self,
207
+ dynamicArgumentTypes: [
208
+ ~A0.self,
209
+ ~A1.self,
210
+ ~A2.self,
211
+ ~A3.self,
212
+ ~A4.self,
213
+ ~A5.self,
214
+ ~A6.self,
215
+ ~A7.self
207
216
  ],
208
217
  closure
209
218
  )
@@ -230,28 +239,28 @@ public func Events(_ names: String...) -> AnyDefinition {
230
239
  Function that is invoked when the first event listener is added.
231
240
  */
232
241
  @available(*, deprecated, renamed: "OnStartObserving")
233
- public func onStartObserving(_ body: @escaping () -> Void) -> AnyFunction {
234
- return ConcreteFunction("startObserving", argTypes: [], body)
242
+ public func onStartObserving(_ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
243
+ return AsyncFunctionComponent("startObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
235
244
  }
236
245
 
237
246
  /**
238
247
  Function that is invoked when the first event listener is added.
239
248
  */
240
- public func OnStartObserving(_ body: @escaping () -> Void) -> AnyFunction {
241
- return ConcreteFunction("startObserving", argTypes: [], body)
249
+ public func OnStartObserving(_ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
250
+ return AsyncFunctionComponent("startObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
242
251
  }
243
252
 
244
253
  /**
245
254
  Function that is invoked when all event listeners are removed.
246
255
  */
247
256
  @available(*, deprecated, renamed: "OnStopObserving")
248
- public func onStopObserving(_ body: @escaping () -> Void) -> AnyFunction {
249
- return ConcreteFunction("stopObserving", argTypes: [], body)
257
+ public func onStopObserving(_ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
258
+ return AsyncFunctionComponent("stopObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
250
259
  }
251
260
 
252
261
  /**
253
262
  Function that is invoked when all event listeners are removed.
254
263
  */
255
- public func OnStopObserving(_ body: @escaping () -> Void) -> AnyFunction {
256
- return ConcreteFunction("stopObserving", argTypes: [], body)
264
+ public func OnStopObserving(_ body: @escaping () -> Void) -> AsyncFunctionComponent<(), Void, Void> {
265
+ return AsyncFunctionComponent("stopObserving", firstArgType: Void.self, dynamicArgumentTypes: [], body)
257
266
  }
@@ -0,0 +1,147 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ public final class PropertyComponent: AnyDefinition {
4
+ /**
5
+ Name of the property.
6
+ */
7
+ let name: String
8
+
9
+ /**
10
+ Synchronous function that is called when the property is being accessed.
11
+ */
12
+ var getter: AnySyncFunctionComponent?
13
+
14
+ /**
15
+ Synchronous function that is called when the property is being set.
16
+ */
17
+ var setter: AnySyncFunctionComponent?
18
+
19
+ init(name: String) {
20
+ self.name = name
21
+ }
22
+
23
+ // MARK: - Modifiers
24
+
25
+ /**
26
+ Modifier that sets property getter that has no arguments (the caller is not used).
27
+ */
28
+ public func get<Value>(_ getter: @escaping () -> Value) -> Self {
29
+ self.getter = SyncFunctionComponent(
30
+ "get",
31
+ firstArgType: Void.self,
32
+ dynamicArgumentTypes: [~Any.self],
33
+ { (caller: Any) in getter() }
34
+ )
35
+ return self
36
+ }
37
+
38
+ /**
39
+ Modifier that sets property setter that receives only the new value as an argument.
40
+ */
41
+ public func set<Value>(_ setter: @escaping (_ newValue: Value) -> ()) -> Self {
42
+ self.setter = SyncFunctionComponent(
43
+ "set",
44
+ firstArgType: Void.self,
45
+ dynamicArgumentTypes: [~Any.self, ~Value.self],
46
+ { (caller: Any, value: Value) in setter(value) }
47
+ )
48
+ return self
49
+ }
50
+
51
+ /**
52
+ Modifier that sets property getter that receives the caller as an argument.
53
+ The caller is an object on which the function is called, like `this` in JavaScript.
54
+ */
55
+ public func get<Value, Caller>(_ getter: @escaping (_ this: Caller) -> Value) -> Self {
56
+ self.getter = SyncFunctionComponent(
57
+ "get",
58
+ firstArgType: Caller.self,
59
+ dynamicArgumentTypes: [~Caller.self],
60
+ getter
61
+ )
62
+ return self
63
+ }
64
+
65
+ /**
66
+ Modifier that sets property setter that receives the caller and the new value as arguments.
67
+ The caller is an object on which the function is called, like `this` in JavaScript.
68
+ */
69
+ public func set<Value, Caller>(_ setter: @escaping (_ this: Caller, _ newValue: Value) -> ()) -> Self {
70
+ self.setter = SyncFunctionComponent(
71
+ "set",
72
+ firstArgType: Caller.self,
73
+ dynamicArgumentTypes: [~Caller.self, ~Value.self],
74
+ setter
75
+ )
76
+ return self
77
+ }
78
+
79
+ // MARK: - Internals
80
+
81
+ internal func getValue<Value>(caller: AnyObject? = nil) -> Value? {
82
+ let value = try? getter?.call(by: caller, withArguments: [caller as Any])
83
+ return value as? Value
84
+ }
85
+
86
+ internal func setValue(_ value: Any, caller: AnyObject? = nil) {
87
+ let _ = try? setter?.call(by: caller, withArguments: [caller as Any, value])
88
+ }
89
+
90
+ /**
91
+ Creates the JavaScript function that will be used as a getter of the property.
92
+ */
93
+ internal func buildGetter(inRuntime runtime: JavaScriptRuntime, withCaller caller: AnyObject?) -> JavaScriptObject {
94
+ return runtime.createSyncFunction(name, argsCount: 0) { [weak self, weak caller] this, args in
95
+ return self?.getValue(caller: caller)
96
+ }
97
+ }
98
+
99
+ /**
100
+ Creates the JavaScript function that will be used as a setter of the property.
101
+ */
102
+ internal func buildSetter(inRuntime runtime: JavaScriptRuntime, withCaller caller: AnyObject?) -> JavaScriptObject {
103
+ return runtime.createSyncFunction(name, argsCount: 1) { [weak self, weak caller] this, args in
104
+ return self?.setValue(args.first as Any, caller: caller)
105
+ }
106
+ }
107
+
108
+ /**
109
+ Creates the JavaScript object representing the property descriptor.
110
+ */
111
+ internal func buildDescriptor(inRuntime runtime: JavaScriptRuntime, withCaller caller: AnyObject?) -> JavaScriptObject {
112
+ let descriptor = runtime.createObject()
113
+
114
+ descriptor.setProperty("enumerable", value: true)
115
+
116
+ if getter != nil {
117
+ descriptor.setProperty("get", value: buildGetter(inRuntime: runtime, withCaller: caller))
118
+ }
119
+ if setter != nil {
120
+ descriptor.setProperty("set", value: buildSetter(inRuntime: runtime, withCaller: caller))
121
+ }
122
+ return descriptor
123
+ }
124
+ }
125
+
126
+ // MARK: - Factory functions
127
+
128
+ /**
129
+ Creates the property with given name. The component is basically no-op if you don't call `.get(_:)` or `.set(_:)` on it.
130
+ */
131
+ public func Property(_ name: String) -> PropertyComponent {
132
+ return PropertyComponent(name: name)
133
+ }
134
+
135
+ /**
136
+ Creates the read-only property whose getter doesn't take the caller as an argument.
137
+ */
138
+ public func Property<Value: AnyArgument>(_ name: String, get: @escaping () -> Value) -> PropertyComponent {
139
+ return PropertyComponent(name: name).get(get)
140
+ }
141
+
142
+ /**
143
+ Creates the read-only property whose getter takes the caller as an argument.
144
+ */
145
+ public func Property<Value: AnyArgument, Caller>(_ name: String, get: @escaping (Caller) -> Value) -> PropertyComponent {
146
+ return PropertyComponent(name: name).get(get)
147
+ }
@@ -2,7 +2,7 @@
2
2
 
3
3
  public struct Promise: AnyArgument {
4
4
  public typealias ResolveClosure = (Any?) -> Void
5
- public typealias RejectClosure = (CodedError) -> Void
5
+ public typealias RejectClosure = (Exception) -> Void
6
6
 
7
7
  public var resolver: ResolveClosure
8
8
  public var rejecter: RejectClosure
@@ -25,11 +25,20 @@ public struct Promise: AnyArgument {
25
25
  rejecter(UnexpectedException(error))
26
26
  }
27
27
 
28
- public func reject(_ error: CodedError) {
28
+ public func reject(_ error: Exception) {
29
29
  rejecter(error)
30
30
  }
31
31
 
32
32
  public func reject(_ code: String, _ description: String) {
33
- rejecter(SimpleCodedError(code, description))
33
+ rejecter(Exception(name: code, description: description))
34
+ }
35
+
36
+ public func settle<ValueType, ExceptionType: Exception>(with result: Result<ValueType, ExceptionType>) {
37
+ switch result {
38
+ case .success(let value):
39
+ resolve(value)
40
+ case .failure(let exception):
41
+ reject(exception)
42
+ }
34
43
  }
35
44
  }
@@ -8,7 +8,7 @@ public final class Field<Type>: AnyFieldInternal {
8
8
  */
9
9
  public var wrappedValue: Type
10
10
 
11
- private let fieldType: AnyArgumentType = ArgumentType(Type.self)
11
+ private let fieldType: AnyDynamicType = ~Type.self
12
12
 
13
13
  /**
14
14
  Field's key in the dictionary, which by default is a label of the wrapped property.
@@ -27,7 +27,7 @@ public final class Field<Type>: AnyFieldInternal {
27
27
  Whether the generic field type accepts `nil` values.
28
28
  */
29
29
  internal var isOptional: Bool {
30
- return fieldType is OptionalArgumentType
30
+ return fieldType is DynamicOptionalType
31
31
  }
32
32
 
33
33
  internal var isRequired: Bool {
@@ -0,0 +1,20 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ public protocol AnySharedObject: AnyArgument {
4
+ var sharedObjectId: SharedObjectId { get }
5
+ }
6
+
7
+ open class SharedObject: AnySharedObject {
8
+ /**
9
+ An identifier of the native shared object that maps to the JavaScript object.
10
+ When the object is not linked with any JavaScript object, its value is 0.
11
+ */
12
+ public internal(set) var sharedObjectId: SharedObjectId = 0
13
+
14
+ /**
15
+ Returns the JavaScript shared object associated with the native shared object.
16
+ */
17
+ public func getJavaScriptObject() -> JavaScriptObject? {
18
+ return SharedObjectRegistry.toJavaScriptObject(self)
19
+ }
20
+ }
@@ -0,0 +1,129 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ /**
4
+ Type of the IDs of shared objects.
5
+ */
6
+ public typealias SharedObjectId = Int
7
+
8
+ /**
9
+ A tuple containing a pair of matching native and JS objects.
10
+ */
11
+ internal typealias SharedObjectPair = (native: SharedObject, javaScript: JavaScriptWeakObject)
12
+
13
+ /**
14
+ Property name of the JS object where the shared object ID is stored.
15
+ */
16
+ let sharedObjectIdPropertyName = "__expo_shared_object_id__"
17
+
18
+ /**
19
+ The registry of all shared objects used in the entire app.
20
+ It's been made static for simplicity.
21
+ */
22
+ public final class SharedObjectRegistry {
23
+ /**
24
+ The counter of IDs to assign to the shared object pairs.
25
+ The next pair added to the registry will be saved using this ID.
26
+ */
27
+ internal static var nextId: SharedObjectId = 1
28
+
29
+ /**
30
+ A dictionary of shared object pairs.
31
+ */
32
+ internal static var pairs = [SharedObjectId: SharedObjectPair]()
33
+
34
+ /**
35
+ A number of all pairs stored in the registry.
36
+ */
37
+ internal static var size: Int {
38
+ return pairs.count
39
+ }
40
+
41
+ /**
42
+ Returns the next shared object ID and increases the counter.
43
+ */
44
+ @discardableResult
45
+ internal static func pullNextId() -> SharedObjectId {
46
+ let id = nextId
47
+ nextId += 1
48
+ return id
49
+ }
50
+
51
+ /**
52
+ Returns a pair of shared objects with given ID or `nil` when there is no such pair in the registry.
53
+ */
54
+ internal static func get(_ id: SharedObjectId) -> SharedObjectPair? {
55
+ return pairs[id]
56
+ }
57
+
58
+ /**
59
+ Adds a pair of native and JS shared object to the registry. Assigns a new shared object ID to these objects.
60
+ */
61
+ @discardableResult
62
+ internal static func add(native nativeObject: SharedObject, javaScript jsObject: JavaScriptObject) -> SharedObjectId {
63
+ let id = pullNextId()
64
+
65
+ // Assigns the ID to the objects.
66
+ nativeObject.sharedObjectId = id
67
+ jsObject.defineProperty(sharedObjectIdPropertyName, value: id, options: [.writable])
68
+
69
+ // Set the deallocator on the JS object that deletes the entire pair.
70
+ jsObject.setObjectDeallocator { delete(id) }
71
+
72
+ // Save the pair in the dictionary.
73
+ pairs[id] = (native: nativeObject, javaScript: jsObject.createWeak())
74
+
75
+ return id
76
+ }
77
+
78
+ /**
79
+ Deletes the shared objects pair with a given ID.
80
+ */
81
+ internal static func delete(_ id: SharedObjectId) {
82
+ if let pair = pairs[id] {
83
+ // Reset an ID on the objects.
84
+ pair.native.sharedObjectId = 0
85
+ pair.javaScript.lock()?.defineProperty(sharedObjectIdPropertyName, value: 0, options: [.writable])
86
+
87
+ // Delete the pair from the dictionary.
88
+ pairs[id] = nil
89
+ }
90
+ }
91
+
92
+ /**
93
+ Gets the native shared object that is paired with a given JS object.
94
+ */
95
+ internal static func toNativeObject(_ jsObject: JavaScriptObject) -> SharedObject? {
96
+ if let objectId = try? jsObject.getProperty(sharedObjectIdPropertyName).asInt() {
97
+ return pairs[objectId]?.native
98
+ }
99
+ return nil
100
+ }
101
+
102
+ /**
103
+ Gets the JS shared object that is paired with a given native object.
104
+ */
105
+ internal static func toJavaScriptObject(_ nativeObject: SharedObject) -> JavaScriptObject? {
106
+ let objectId = nativeObject.sharedObjectId
107
+ return pairs[objectId]?.javaScript.lock()
108
+ }
109
+
110
+ /**
111
+ Creates a plain JS object and pairs it with a given native object.
112
+ */
113
+ internal static func createSharedJavaScriptObject(runtime: JavaScriptRuntime, nativeObject: SharedObject) -> JavaScriptObject {
114
+ let object = runtime.createObject()
115
+ add(native: nativeObject, javaScript: object)
116
+ return object
117
+ }
118
+
119
+ /**
120
+ Ensures that there is a JS object paired with a given native object. If not, a plain JS object is created.
121
+ */
122
+ internal static func ensureSharedJavaScriptObject(runtime: JavaScriptRuntime, nativeObject: SharedObject) -> JavaScriptObject {
123
+ if let jsObject = toJavaScriptObject(nativeObject) {
124
+ // JS object for this native object already exists in the registry, just return it.
125
+ return jsObject
126
+ }
127
+ return createSharedJavaScriptObject(runtime: runtime, nativeObject: nativeObject)
128
+ }
129
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ /**
4
+ A protocol for all typed arrays.
5
+ */
6
+ internal protocol AnyTypedArray: AnyArgument {
7
+ /**
8
+ Initializes a typed array from the given JavaScript representation.
9
+ */
10
+ init(_ jsTypedArray: JavaScriptTypedArray)
11
+ }
@@ -0,0 +1,56 @@
1
+ // Copyright 2022-present 650 Industries. All rights reserved.
2
+
3
+ /**
4
+ Native equivalent of `Int8Array` in JavaScript, an array of two's-complement 8-bit signed integers.
5
+ */
6
+ public final class Int8Array: GenericTypedArray<Int8> {}
7
+
8
+ /**
9
+ Native equivalent of `Int16Array` in JavaScript, an array of two's-complement 16-bit signed integers.
10
+ */
11
+ public final class Int16Array: GenericTypedArray<Int16> {}
12
+
13
+ /**
14
+ Native equivalent of `Int32Array` in JavaScript, an array of two's-complement 32-bit signed integers.
15
+ */
16
+ public final class Int32Array: GenericTypedArray<Int32> {}
17
+
18
+ /**
19
+ Native equivalent of `Uint8Array` in JavaScript, an array of 8-bit unsigned integers.
20
+ */
21
+ public final class Uint8Array: GenericTypedArray<UInt8> {}
22
+
23
+ /**
24
+ Native equivalent of `Uint8ClampedArray` in JavaScript, an array of 8-bit unsigned integers clamped to 0-255.
25
+ */
26
+ public final class Uint8ClampedArray: GenericTypedArray<UInt8> {}
27
+
28
+ /**
29
+ Native equivalent of `Uint16Array` in JavaScript, an array of 16-bit unsigned integers.
30
+ */
31
+ public final class Uint16Array: GenericTypedArray<UInt16> {}
32
+
33
+ /**
34
+ Native equivalent of `Uint32Array` in JavaScript, an array of 32-bit unsigned integers.
35
+ */
36
+ public final class Uint32Array: GenericTypedArray<UInt32> {}
37
+
38
+ /**
39
+ Native equivalent of `Float32Array` in JavaScript, an array of 32-bit floating point numbers.
40
+ */
41
+ public final class Float32Array: GenericTypedArray<Float32> {}
42
+
43
+ /**
44
+ Native equivalent of `Float64Array` in JavaScript, an array of 64-bit floating point numbers.
45
+ */
46
+ public final class Float64Array: GenericTypedArray<Float64> {}
47
+
48
+ /**
49
+ Native equivalent of `BigInt64Array` in JavaScript, an array of 64-bit signed integers.
50
+ */
51
+ public final class BigInt64Array: GenericTypedArray<Int64> {}
52
+
53
+ /**
54
+ Native equivalent of `BigUint64Array` in JavaScript, an array of 64-bit unsigned integers.
55
+ */
56
+ public final class BigUint64Array: GenericTypedArray<UInt64> {}