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
@@ -1,155 +0,0 @@
1
- // Copyright 2021-present 650 Industries. All rights reserved.
2
-
3
- import Foundation
4
- import React
5
-
6
- @objc
7
- public final class SwiftInteropBridge: NSObject {
8
- let appContext: AppContext
9
-
10
- var registry: ModuleRegistry {
11
- appContext.moduleRegistry
12
- }
13
-
14
- internal init(appContext: AppContext) {
15
- self.appContext = appContext
16
- super.init()
17
- }
18
-
19
- @objc
20
- public init(modulesProvider: ModulesProvider, legacyModuleRegistry: EXModuleRegistry) {
21
- self.appContext = AppContext(withModulesProvider: modulesProvider, legacyModuleRegistry: legacyModuleRegistry)
22
- super.init()
23
- }
24
-
25
- @objc
26
- public func hasModule(_ moduleName: String) -> Bool {
27
- return registry.has(moduleWithName: moduleName)
28
- }
29
-
30
- @objc
31
- public func setReactBridge(_ reactBridge: RCTBridge) {
32
- appContext.reactBridge = reactBridge
33
- }
34
-
35
- @objc
36
- public func callFunction(
37
- _ functionName: String,
38
- onModule moduleName: String,
39
- withArgs args: [Any],
40
- resolve: @escaping EXPromiseResolveBlock,
41
- reject: @escaping EXPromiseRejectBlock
42
- ) {
43
- registry
44
- .get(moduleHolderForName: moduleName)?
45
- .call(function: functionName, args: args) { value, error in
46
- if let error = error {
47
- reject(error.code, error.description, error)
48
- } else if let error = error {
49
- reject("ERR_UNKNOWN_ERROR", error.localizedDescription, error)
50
- } else {
51
- resolve(value)
52
- }
53
- }
54
- }
55
-
56
- @objc
57
- public func callFunctionSync(
58
- _ functionName: String,
59
- onModule moduleName: String,
60
- withArgs args: [Any]
61
- ) -> Any? {
62
- return registry
63
- .get(moduleHolderForName: moduleName)?
64
- .callSync(function: functionName, args: args)
65
- }
66
-
67
- @objc
68
- public func exportedFunctionNames() -> [String: [[String: Any]]] {
69
- var constants = [String: [[String: Any]]]()
70
-
71
- for holder in registry {
72
- constants[holder.name] = holder.definition.functions.map({ functionName, function in
73
- return [
74
- "name": functionName,
75
- "argumentsCount": function.argumentsCount,
76
- "key": functionName
77
- ]
78
- })
79
- }
80
- return constants
81
- }
82
-
83
- @objc
84
- public func exportedModulesConstants() -> [String: Any] {
85
- return registry.reduce(into: [String: Any]()) { acc, holder in
86
- acc[holder.name] = holder.getConstants()
87
- }
88
- }
89
-
90
- @objc
91
- public func viewManagersMetadata() -> [String: Any] {
92
- return registry.reduce(into: [String: Any]()) { acc, holder in
93
- if let viewManager = holder.definition.viewManager {
94
- acc[holder.name] = [
95
- "propsNames": viewManager.props.map { $0.name }
96
- ]
97
- }
98
- }
99
- }
100
-
101
- /**
102
- Returns view modules wrapped by the base `ViewModuleWrapper` class.
103
- */
104
- @objc
105
- public func getViewManagers() -> [ViewModuleWrapper] {
106
- return registry.compactMap { holder in
107
- if holder.definition.viewManager != nil {
108
- return ViewModuleWrapper(holder)
109
- } else {
110
- return nil
111
- }
112
- }
113
- }
114
-
115
- /**
116
- Sets the JSI runtime on the operating `AppContext`.
117
- */
118
- @objc
119
- public func setRuntime(_ runtime: JavaScriptRuntime?) {
120
- appContext.runtime = runtime
121
- }
122
-
123
- @objc
124
- public func getModuleNames() -> [String] {
125
- return registry.getModuleNames()
126
- }
127
-
128
- @objc
129
- public func getNativeModuleObject(_ moduleName: String) -> JavaScriptObject? {
130
- return registry.get(moduleHolderForName: moduleName)?.javaScriptObject
131
- }
132
-
133
- // MARK: - Events
134
-
135
- /**
136
- Returns an array of event names supported by all Swift modules.
137
- */
138
- @objc
139
- public func getSupportedEvents() -> [String] {
140
- return registry.reduce(into: [String]()) { events, holder in
141
- events.append(contentsOf: holder.definition.eventNames)
142
- }
143
- }
144
-
145
- /**
146
- Modifies listeners count for module with given name. Depending on the listeners count,
147
- `onStartObserving` and `onStopObserving` are called.
148
- */
149
- @objc
150
- public func modifyEventListenersCount(_ moduleName: String, count: Int) {
151
- registry
152
- .get(moduleHolderForName: moduleName)?
153
- .modifyListenersCount(count)
154
- }
155
- }
@@ -1,143 +0,0 @@
1
- // Copyright 2021-present 650 Industries. All rights reserved.
2
-
3
- import ExpoModulesTestCore
4
-
5
- @testable import ExpoModulesCore
6
-
7
- class ArgumentTypeSpec: ExpoSpec {
8
- override func spec() {
9
- it("casts primitives") {
10
- let type = ArgumentType(Int.self)
11
- let value = 123
12
- let anyValue = value as Any
13
-
14
- expect(try type.cast(anyValue)).to(be(value))
15
- }
16
-
17
- it("casts optional types") {
18
- let type = ArgumentType(Double?.self)
19
- let value: Double? = nil
20
- let anyValue = value as Any
21
- let result = try type.cast(anyValue)
22
-
23
- expect(result).to(beAKindOf(Double?.self))
24
-
25
- // Since this `nil` is in fact of non-optional `Any` type, under the hood it's described as `Optional` enum.
26
- // Simply checking `result == nil` does NOT work here, see `Optional.isNil` extension implementation.
27
- expect(Optional.isNil(result)) == true
28
- }
29
-
30
- it("throws null cast error") {
31
- let type = ArgumentType(Double.self) // non-optional (!)
32
- let value: Double? = nil
33
- let anyValue = value as Any
34
-
35
- expect { try type.cast(anyValue) }.to(throwError(errorType: Conversions.NullCastException<Double>.self))
36
- }
37
-
38
- it("casts arrays") {
39
- let type = ArgumentType([Double].self)
40
- let value = 9.9
41
- let anyValue = [value] as [Any]
42
- let result = try type.cast(anyValue) as! [Any]
43
-
44
- expect(result).to(beAKindOf([Double].self))
45
- expect((result as! [Double]).first) == value
46
- }
47
-
48
- it("casts convertibles") {
49
- let type = ArgumentType(ConvertibleTestStruct.self)
50
- let value = "expo is the best"
51
- let result = try type.cast(value)
52
-
53
- expect(result).to(beAKindOf(ConvertibleTestStruct.self))
54
- expect((result as! ConvertibleTestStruct).value) == value
55
- }
56
-
57
- it("casts array of convertibles") {
58
- let type = ArgumentType([ConvertibleTestStruct].self)
59
- let value = ["expo is the best"]
60
- let result = try type.cast(value)
61
-
62
- expect(result).to(beAKindOf([ConvertibleTestStruct].self))
63
- expect((result as! [ConvertibleTestStruct]).first!.value) == value.first
64
- }
65
-
66
- it("casts array of array of convertibles") {
67
- let type = ArgumentType([[ConvertibleTestStruct]].self)
68
- let value = [["expo is the best"]]
69
- let result = try type.cast(value)
70
-
71
- expect(result).to(beAKindOf([[ConvertibleTestStruct]].self))
72
- expect((result as! [[ConvertibleTestStruct]]).first!.first!.value) == value.first!.first
73
- }
74
-
75
- describe("EnumArgumentType") {
76
- it("casts from String") {
77
- let type = ArgumentType(StringTestEnum.self)
78
- let input = "expo"
79
- let output = try type.cast(input)
80
-
81
- expect(output).to(beAKindOf(StringTestEnum.self))
82
- expect(output as? StringTestEnum) == StringTestEnum.expo
83
- expect(output as? StringTestEnum) == StringTestEnum(rawValue: input)
84
- expect((output as! StringTestEnum).rawValue) == input
85
- expect((output as! EnumArgument).anyRawValue).to(beAKindOf(String.self))
86
- }
87
-
88
- it("casts from Int") {
89
- let type = ArgumentType(IntTestEnum.self)
90
- let input: Int = -1
91
- let output = try type.cast(input)
92
-
93
- expect(output).to(beAKindOf(IntTestEnum.self))
94
- expect(output as? IntTestEnum) == IntTestEnum.negative
95
- expect(output as? IntTestEnum) == IntTestEnum(rawValue: input)
96
- expect((output as! IntTestEnum).rawValue) == input
97
- expect((output as! EnumArgument).anyRawValue).to(beAKindOf(Int.self))
98
- }
99
-
100
- it("throws casting error") {
101
- let type = ArgumentType(IntTestEnum.self)
102
-
103
- // "841" is not a raw value of any `IntTestEnum` case
104
- expect { try type.cast("string instead of int") }.to(throwError {
105
- expect($0).to(beAKindOf(EnumCastingException.self))
106
- })
107
- }
108
-
109
- it("throws no such value error") {
110
- let type = ArgumentType(IntTestEnum.self)
111
-
112
- // "841" is not a raw value of any `IntTestEnum` case
113
- expect { try type.cast(841) }.to(throwError {
114
- expect($0).to(beAKindOf(EnumNoSuchValueException.self))
115
- })
116
- }
117
-
118
- it("gets a list of all raw values") {
119
- expect(StringTestEnum.allRawValues as? [String]) == ["hello", "expo"]
120
- expect(IntTestEnum.allRawValues as? [Int]) == [-1, 1]
121
- }
122
- }
123
- }
124
- }
125
-
126
- struct ConvertibleTestStruct: ConvertibleArgument {
127
- let value: String
128
-
129
- static func convert(from value: Any?) throws -> ConvertibleTestStruct {
130
- guard let str = value as? String else { fatalError() }
131
- return ConvertibleTestStruct(value: str)
132
- }
133
- }
134
-
135
- enum StringTestEnum: String, EnumArgument {
136
- case hello
137
- case expo
138
- }
139
-
140
- enum IntTestEnum: Int, EnumArgument {
141
- case negative = -1
142
- case positive = 1
143
- }