sparkling-method 2.1.0-rc.2 → 2.1.0-rc.24

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 (190) hide show
  1. package/ios/Sources/Core/DI/DIContainerProtocol.swift +1 -1
  2. package/ios/Sources/Core/DI/DIProviderRegistry.swift +1 -1
  3. package/ios/Sources/Core/Examples/SampleMethod+impl.swift +3 -3
  4. package/ios/Sources/Core/Examples/SampleMethod.swift +7 -7
  5. package/ios/Sources/Core/Models/MethodContext.swift +5 -5
  6. package/ios/Sources/Core/Models/MethodStatus.swift +24 -24
  7. package/ios/Sources/Core/Pipe/MethodPipe+Internal.swift +9 -8
  8. package/ios/Sources/Core/Pipe/MethodPipe.swift +8 -8
  9. package/ios/Sources/Core/Pipe/MethodRegistry.swift +26 -25
  10. package/ios/Sources/Core/Protocols/MethodModel.swift +41 -36
  11. package/ios/Sources/Core/Protocols/PipeMethod.swift +13 -13
  12. package/ios/Sources/Core/Utils/AnyCodableValue.swift +6 -6
  13. package/ios/Sources/Core/Utils/NSString+SPKBridgeAdditions.swift +2 -2
  14. package/ios/Sources/Core/Utils/ReadWriteLock.swift +6 -6
  15. package/ios/Sources/Core/Utils/SPKHttpResponseChromium.swift +3 -3
  16. package/ios/Sources/Core/Utils/SPKNetworkManager.swift +50 -46
  17. package/ios/Sources/Core/Utils/SPKReachability.swift +16 -12
  18. package/ios/Sources/DIProvider/DIContainer.swift +9 -9
  19. package/ios/Sources/DIProvider/DefaultDIContainerProvider.swift +3 -3
  20. package/ios/Sources/Debug/MethodPipe+Debug.swift +6 -4
  21. package/ios/Sources/Lynx/Definitions/LynxPipeStatusCode.swift +7 -7
  22. package/ios/Sources/Lynx/Engine/LynxConfig+SPKPipe.swift +5 -5
  23. package/ios/Sources/Lynx/Engine/LynxContext+SPKPipe.swift +2 -2
  24. package/ios/Sources/Lynx/Engine/LynxPipeEngine.swift +5 -5
  25. package/ios/Sources/Lynx/Engine/LynxPipeEnginePool.swift +5 -5
  26. package/ios/Sources/Lynx/Engine/LynxView+SPKPipe.swift +3 -3
  27. package/ios/Sources/Lynx/Engine/SPKLynxModuleService.swift +8 -4
  28. package/ios/Sources/Lynx/Models/LynxRecvMessage.swift +3 -3
  29. package/ios/Sources/Lynx/Models/LynxSendMessage.swift +7 -7
  30. package/ios/Sources/Lynx/Module/SPKLynxNativeModule.swift +7 -7
  31. package/ios/Sources/Lynx/Pipe/MethodPipe+Lynx.swift +11 -9
  32. package/ios/SparklingMethod.podspec +12 -12
  33. package/package.json +7 -2
  34. package/android/build.gradle.kts +0 -245
  35. package/android/gradle.properties +0 -1
  36. package/android/proguard-rules.pro +0 -21
  37. package/android/src/androidTest/java/com/tiktok/sparkling/sparkling/methods/ExampleInstrumentedTest.kt +0 -27
  38. package/android/src/main/AndroidManifest.xml +0 -5
  39. package/android/src/main/java/com/tiktok/sparkling/method/protocol/BridgeContext.kt +0 -74
  40. package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImp.kt +0 -47
  41. package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImp.kt +0 -233
  42. package/android/src/main/java/com/tiktok/sparkling/method/protocol/InnerBridge.kt +0 -134
  43. package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeCall.kt +0 -79
  44. package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeResult.kt +0 -68
  45. package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcher.kt +0 -198
  46. package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManager.kt +0 -16
  47. package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcher.kt +0 -56
  48. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModel.kt +0 -144
  49. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptor.kt +0 -30
  50. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModel.kt +0 -66
  51. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModule.kt +0 -31
  52. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtol.kt +0 -69
  53. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModule.kt +0 -31
  54. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxViewImpl.kt +0 -29
  55. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegate.kt +0 -147
  56. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitor.kt +0 -239
  57. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/IBridgeMonitor.kt +0 -17
  58. package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntity.kt +0 -22
  59. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeCallback.kt +0 -14
  60. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeClient.kt +0 -19
  61. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeHandler.kt +0 -23
  62. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeLifeClient.kt +0 -45
  63. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeMethodCallback.kt +0 -10
  64. package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeProtocol.kt +0 -22
  65. package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConstants.kt +0 -13
  66. package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConverter.kt +0 -147
  67. package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/LogUtils.kt +0 -37
  68. package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/MonitorUtils.kt +0 -41
  69. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeLocalPool.kt +0 -70
  70. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeSettings.kt +0 -19
  71. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BusinessCallHandler.kt +0 -100
  72. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/CancelCallbackConfig.kt +0 -13
  73. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/DefaultCallHandler.kt +0 -106
  74. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/IBridgeMethod.kt +0 -118
  75. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/PiperDataExt.kt +0 -71
  76. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/SparklingBridge.kt +0 -374
  77. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/Utils.kt +0 -89
  78. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/interfaces/IBridgeNotFound.kt +0 -11
  79. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxDataProcessorForMap.kt +0 -204
  80. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxPlatformDataProcessor.kt +0 -239
  81. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebPlatformDataProcessor.kt +0 -307
  82. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebProcessorForMap.kt +0 -227
  83. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeMethodCallbackHelper.kt +0 -29
  84. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeProtocolConstants.kt +0 -12
  85. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtils.kt +0 -684
  86. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/IConvertUtils.kt +0 -44
  87. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/LogHelper.kt +0 -30
  88. package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/ThreadPool.kt +0 -73
  89. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgeCollections.kt +0 -194
  90. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgePlatformType.kt +0 -13
  91. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IBridgeContext.kt +0 -137
  92. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLBridgeMethod.kt +0 -100
  93. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodProvider.kt +0 -13
  94. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistry.kt +0 -132
  95. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCache.kt +0 -150
  96. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCacheManager.kt +0 -34
  97. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLProxyClient.kt +0 -28
  98. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IRegister.kt +0 -21
  99. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/LocalBridge.kt +0 -70
  100. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/ReadableMapImpl.kt +0 -227
  101. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/RegistryCache.kt +0 -77
  102. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManager.kt +0 -50
  103. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodIntEnum.kt +0 -15
  104. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodName.kt +0 -14
  105. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamField.kt +0 -42
  106. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamModel.kt +0 -10
  107. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodResultModel.kt +0 -10
  108. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodStringEnum.kt +0 -15
  109. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethod.kt +0 -276
  110. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodException.kt +0 -10
  111. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalInputParamException.kt +0 -12
  112. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOperationException.kt +0 -12
  113. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOutputParamException.kt +0 -13
  114. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IContainerIDProvider.kt +0 -13
  115. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/INameSpaceProvider.kt +0 -13
  116. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IPlatformDataProcessor.kt +0 -19
  117. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IReleasable.kt +0 -13
  118. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/BridgeCallThreadTypeConfig.kt +0 -44
  119. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/ContextProviderFactory.kt +0 -133
  120. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/CompletionBlock.kt +0 -26
  121. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLDynamic.kt +0 -97
  122. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseModel.kt +0 -37
  123. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseParamModel.kt +0 -62
  124. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseResultModel.kt +0 -18
  125. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/BridgeKTX.kt +0 -37
  126. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IAssignDir.kt +0 -25
  127. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodHelper.kt +0 -44
  128. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelArguments.kt +0 -264
  129. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelHelper.kt +0 -194
  130. package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/JsonUtils.kt +0 -200
  131. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntime.kt +0 -11
  132. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/CommonDependsProvider.kt +0 -14
  133. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostNetworkDepend.kt +0 -19
  134. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostPermissionDepend.kt +0 -34
  135. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostThreadPoolExecutorDepend.kt +0 -12
  136. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStreamConnection.kt +0 -36
  137. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStringConnection.kt +0 -30
  138. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/HttpRequest.kt +0 -134
  139. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/NetworkRequestImpl.kt +0 -28
  140. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/RequestJsonFormatOptionConstants.kt +0 -10
  141. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/BridgeAPIRequestUtils.kt +0 -365
  142. package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/HttpUrlBuilder.kt +0 -97
  143. package/android/src/main/res/drawable/ic_launcher_background.xml +0 -170
  144. package/android/src/main/res/drawable/ic_launcher_foreground.xml +0 -30
  145. package/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -6
  146. package/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -6
  147. package/android/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  148. package/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  149. package/android/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  150. package/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  151. package/android/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  152. package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  153. package/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  154. package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  155. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  156. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  157. package/android/src/main/res/values/colors.xml +0 -10
  158. package/android/src/main/res/values/strings.xml +0 -3
  159. package/android/src/test/java/com/tiktok/sparkling/method/TestApplication.kt +0 -19
  160. package/android/src/test/java/com/tiktok/sparkling/method/protocol/BridgeContextTest.kt +0 -89
  161. package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImpTest.kt +0 -78
  162. package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImpTest.kt +0 -97
  163. package/android/src/test/java/com/tiktok/sparkling/method/protocol/InnerBridgeTest.kt +0 -105
  164. package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeCallTest.kt +0 -61
  165. package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeResultTest.kt +0 -74
  166. package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcherTest.kt +0 -96
  167. package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManagerTest.kt +0 -21
  168. package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcherTest.kt +0 -34
  169. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModelTest.kt +0 -60
  170. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptorTest.kt +0 -51
  171. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModelTest.kt +0 -65
  172. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModuleTest.kt +0 -57
  173. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtocolTest.kt +0 -10
  174. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModuleTest.kt +0 -37
  175. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegateTest.kt +0 -10
  176. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitorTest.kt +0 -10
  177. package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntityTest.kt +0 -43
  178. package/android/src/test/java/com/tiktok/sparkling/method/registry/api/SparklingBridgeTest.kt +0 -444
  179. package/android/src/test/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtilsTest.kt +0 -236
  180. package/android/src/test/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryTest.kt +0 -331
  181. package/android/src/test/java/com/tiktok/sparkling/method/registry/core/LocalBridgeTest.kt +0 -299
  182. package/android/src/test/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManagerTest.kt +0 -213
  183. package/android/src/test/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethodTest.kt +0 -307
  184. package/android/src/test/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodExceptionTest.kt +0 -311
  185. package/android/src/test/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntimeTest.kt +0 -54
  186. package/android/src/test/resources/robolectric.properties +0 -5
  187. package/src/index.ts +0 -240
  188. package/src/types.ts +0 -44
  189. package/src/typing.d.ts +0 -44
  190. package/tsconfig.json +0 -15
@@ -20,7 +20,7 @@ extension DIContainerProtocol {
20
20
  public func register<Service>(_ serviceType: Service.Type, name: AnyHashable? = nil, scope: ServiceScope = .container, factory: @escaping Factory<Service>) {
21
21
  self.register(serviceType, name: name, scope: scope, factory: factory)
22
22
  }
23
-
23
+
24
24
  public func resolve<Service>(_ serviceType: Service.Type, name: AnyHashable? = nil) -> Service? {
25
25
  return self.resolve(serviceType, name: name)
26
26
  }
@@ -6,7 +6,7 @@ import Foundation
6
6
 
7
7
  public enum DIProviderRegistry {
8
8
  private static var _provider: DIContainerProvider?
9
-
9
+
10
10
  public static var provider: DIContainerProvider! {
11
11
  get {
12
12
  guard let instance = _provider else {
@@ -13,12 +13,12 @@ import Foundation
13
13
  completionHandler.handleCompletion(status: .invalidParameter(message: "Invalid parameter model type"), result: nil)
14
14
  return
15
15
  }
16
-
16
+
17
17
  // Simulate processing logic
18
18
  let result = SampleMethodResultModel()
19
19
  result.sampleResult = "Processed: \(params.sampleParam ?? "")"
20
-
20
+
21
21
  // Return success result
22
22
  completionHandler.handleCompletion(status: MethodStatus.succeeded(), result: result)
23
23
  }
24
- }
24
+ }
@@ -13,7 +13,7 @@ class SampleMethodParamModel: SPKMethodModel {
13
13
  @objc public static func requiredKeyPaths() -> Set<String>? {
14
14
  return ["sampleParam"]
15
15
  }
16
-
16
+
17
17
  override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
18
18
  return ["sampleParam": "sample_param"]
19
19
  }
@@ -23,12 +23,12 @@ class SampleMethodParamModel: SPKMethodModel {
23
23
  @objc(SampleMethodResultModel)
24
24
  public final class SampleMethodResultModel: SPKMethodModel {
25
25
  var sampleResult: String?
26
-
26
+
27
27
  // Required parameter key paths
28
28
  @objc public static func requiredKeyPaths() -> Set<String>? {
29
29
  return ["sampleResult"]
30
30
  }
31
-
31
+
32
32
  override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
33
33
  return ["sampleResult": "sample_result"]
34
34
  }
@@ -41,18 +41,18 @@ public final class SampleMethod: PipeMethod {
41
41
  public override var methodName: String {
42
42
  return "sample_method"
43
43
  }
44
-
44
+
45
45
  public override class func methodName() -> String {
46
46
  return "sample_method"
47
47
  }
48
-
48
+
49
49
  /// Parameter model type
50
50
  @objc override var paramsModelType: AnyClass {
51
51
  return SampleMethodParamModel.self
52
52
  }
53
-
53
+
54
54
  /// Result model type
55
55
  @objc override var resultModelType: AnyClass {
56
56
  return SampleMethodResultModel.self
57
57
  }
58
- }
58
+ }
@@ -6,7 +6,7 @@ import Foundation
6
6
 
7
7
  final class WeakWrap {
8
8
  weak var value: AnyObject?
9
-
9
+
10
10
  init(_ value: AnyObject) {
11
11
  self.value = value
12
12
  }
@@ -19,7 +19,7 @@ enum ValueWrap {
19
19
 
20
20
  public class MethodContext {
21
21
  private var storage: [String: ValueWrap] = [:]
22
-
22
+
23
23
  public func set(_ value: Any, forKey key: String, weak: Bool = false) {
24
24
  if weak, let obj = value as? AnyObject {
25
25
  storage[key] = .weak(WeakWrap(obj))
@@ -27,7 +27,7 @@ public class MethodContext {
27
27
  storage[key] = .strong(value)
28
28
  }
29
29
  }
30
-
30
+
31
31
  public func get<T>(_ key: String, as type: T.Type = T.self) -> T? {
32
32
  guard let valueWrap = storage[key] else { return nil }
33
33
  switch valueWrap {
@@ -35,11 +35,11 @@ public class MethodContext {
35
35
  case .weak(let weakWrap): return weakWrap.value as? T
36
36
  }
37
37
  }
38
-
38
+
39
39
  public func removeValue(forKey key: String) {
40
40
  storage.removeValue(forKey: key)
41
41
  }
42
-
42
+
43
43
  public subscript<T>(key: String) -> T? {
44
44
  get { get(key, as: T.self) }
45
45
  set {
@@ -30,97 +30,97 @@ import Foundation
30
30
  @objc public class MethodStatus: NSObject {
31
31
  @objc public let code: MethodStatusCode
32
32
  @objc public let message: String?
33
-
33
+
34
34
  // Convenience constructor
35
35
  @objc public init(code: MethodStatusCode, message: String? = nil) {
36
36
  self.code = code
37
37
  self.message = message
38
38
  }
39
-
39
+
40
40
  // Convenience factory method
41
41
  @objc public static func succeeded() -> MethodStatus {
42
42
  return MethodStatus(code: .succeeded)
43
43
  }
44
-
44
+
45
45
  @objc public static func failed(message: String? = nil) -> MethodStatus {
46
46
  return MethodStatus(code: .failed, message: message)
47
47
  }
48
-
48
+
49
49
  @objc public static func invalidParameter(message: String? = nil) -> MethodStatus {
50
50
  return MethodStatus(code: .invalidInputParameter, message: message)
51
51
  }
52
-
52
+
53
53
  @objc public static func notImplemented(message: String? = nil) -> MethodStatus {
54
54
  return MethodStatus(code: .notImplemented, message: message)
55
55
  }
56
-
56
+
57
57
  // Convenience methods for other common statuses
58
58
  @objc public static func unregisteredMethod(message: String? = nil) -> MethodStatus {
59
59
  return MethodStatus(code: .unregisteredMethod, message: message)
60
60
  }
61
-
61
+
62
62
  @objc public static func invalidNamespace(message: String? = nil) -> MethodStatus {
63
63
  return MethodStatus(code: .invalidNamespace, message: message)
64
64
  }
65
-
65
+
66
66
  @objc public static func invalidResult(message: String? = nil) -> MethodStatus {
67
67
  return MethodStatus(code: .invalidResult, message: message)
68
68
  }
69
-
69
+
70
70
  @objc public static func unauthorizedAccess(message: String? = nil) -> MethodStatus {
71
71
  return MethodStatus(code: .unauthorizedAccess, message: message)
72
72
  }
73
-
73
+
74
74
  @objc public static func operationCancelled(message: String? = nil) -> MethodStatus {
75
75
  return MethodStatus(code: .operationCancelled, message: message)
76
76
  }
77
-
77
+
78
78
  @objc public static func operationTimeout(message: String? = nil) -> MethodStatus {
79
79
  return MethodStatus(code: .operationTimeout, message: message)
80
80
  }
81
-
81
+
82
82
  @objc public static func notFound(message: String? = nil) -> MethodStatus {
83
83
  return MethodStatus(code: .notFound, message: message)
84
84
  }
85
-
85
+
86
86
  @objc public static func alreadyExists(message: String? = nil) -> MethodStatus {
87
87
  return MethodStatus(code: .alreadyExists, message: message)
88
88
  }
89
-
89
+
90
90
  @objc public static func paramModelTypeWrong(message: String? = nil) -> MethodStatus {
91
91
  return MethodStatus(code: .paramModelTypeWrong, message: message)
92
92
  }
93
-
93
+
94
94
  @objc public static func resultModelTypeWrong(message: String? = nil) -> MethodStatus {
95
95
  return MethodStatus(code: .resultModelTypeWrong, message: message)
96
96
  }
97
-
97
+
98
98
  @objc public static func unknown(message: String? = nil) -> MethodStatus {
99
99
  return MethodStatus(code: .unknown, message: message)
100
100
  }
101
-
101
+
102
102
  @objc public static func networkUnreachable(message: String? = nil) -> MethodStatus {
103
103
  return MethodStatus(code: .networkUnreachable, message: message)
104
104
  }
105
-
105
+
106
106
  @objc public static func networkTimeout(message: String? = nil) -> MethodStatus {
107
107
  return MethodStatus(code: .networkTimeout, message: message)
108
108
  }
109
-
109
+
110
110
  @objc public static func malformedResponse(message: String? = nil) -> MethodStatus {
111
111
  return MethodStatus(code: .malformedResponse, message: message)
112
112
  }
113
-
113
+
114
114
  // For compatibility with original Int type code access
115
115
  @objc public var rawCode: Int {
116
116
  return code.rawValue
117
117
  }
118
-
118
+
119
119
  // Whether it's successful
120
120
  @objc public var isSuccess: Bool {
121
121
  return code == .succeeded
122
122
  }
123
-
123
+
124
124
  // Already have instance variable message, no need for duplicate computed property
125
125
  }
126
126
 
@@ -129,11 +129,11 @@ extension MethodStatus {
129
129
  let msg = self.message ?? ""
130
130
  return "<MethodStatus - code: \(self.code), message: \"\(msg)\">"
131
131
  }
132
-
132
+
133
133
  public static func == (lhs: MethodStatus, rhs: MethodStatus) -> Bool {
134
134
  return lhs.code == rhs.code
135
135
  }
136
-
136
+
137
137
  public static func === (lhs: MethodStatus, rhs: MethodStatus) -> Bool {
138
138
  return lhs.code == rhs.code && lhs.message == rhs.message
139
139
  }
@@ -10,7 +10,7 @@ extension MethodPipe {
10
10
  completion?(.notFound(), nil)
11
11
  return
12
12
  }
13
-
13
+
14
14
  let resultModelType = method.resultModelClass
15
15
  let resultBlk: PipeMethod.CompletionBlock = { status, result in
16
16
  if let result = result, type(of: result) != EmptyMethodModel.self {
@@ -20,7 +20,7 @@ extension MethodPipe {
20
20
  return
21
21
  }
22
22
  }
23
-
23
+
24
24
  var fStatus = status
25
25
  var resultDict: [String: Any] = [:]
26
26
  do {
@@ -30,7 +30,7 @@ extension MethodPipe {
30
30
  } catch {
31
31
  fStatus = .invalidResult(message: error.localizedDescription)
32
32
  }
33
-
33
+
34
34
  resultDict[DictKeys.statusMessage] = fStatus.message
35
35
  completion?(fStatus, resultDict)
36
36
  }
@@ -39,10 +39,11 @@ extension MethodPipe {
39
39
  completion?(.invalidParameter(message: "Pipe inner error: empty params"), nil)
40
40
  return
41
41
  }
42
-
42
+
43
43
  // Safely get requiredKeyPaths
44
- if let methodModelType = paramsModelType as? MethodModel.Type,
45
- let requiredKeyPaths = methodModelType.requiredKeyPaths {
44
+ if let methodModelType = paramsModelType as? MethodModel.Type,
45
+ let requiredKeyPaths = methodModelType.requiredKeyPaths
46
+ {
46
47
  let paramsKeys: Set<String> = Set(params.keys)
47
48
  let missingKeys = requiredKeyPaths.subtracting(paramsKeys).sorted().joined(separator: ", ")
48
49
  if missingKeys.count > 0 {
@@ -50,7 +51,7 @@ extension MethodPipe {
50
51
  return
51
52
  }
52
53
  }
53
-
54
+
54
55
  var paramModel: MethodModel?
55
56
  do {
56
57
  if let methodModelType = paramsModelType as? MethodModel.Type {
@@ -71,7 +72,7 @@ extension MethodPipe {
71
72
  context.pipeContainer = self.engine?.pipeContainer
72
73
  return context
73
74
  }()
74
-
75
+
75
76
  let invokeBlk: () -> Void = {
76
77
  method.invokeErased(withParams: paramModel, completion: resultBlk)
77
78
  }
@@ -7,38 +7,38 @@ import Foundation
7
7
  public class MethodPipe: MethodPipeFacade {
8
8
  var engine: PipeEngine?
9
9
  public private(set) lazy var registry = MethodRegistry()
10
-
10
+
11
11
  public func register(localMethod method: PipeMethod) {
12
12
  registry.register(method: method)
13
13
  }
14
-
14
+
15
15
  public func register(localMethods methods: [PipeMethod]) {
16
16
  registry.register(methods: methods)
17
17
  }
18
-
18
+
19
19
  public func register(globalMethod method: PipeMethod) {
20
20
  MethodRegistry.global.register(method: method)
21
21
  }
22
22
  public func unregister(localMethodName name: String) {
23
23
  registry.unregister(methodName: name)
24
24
  }
25
-
25
+
26
26
  public func unregister(globalMethodName name: String) {
27
27
  MethodRegistry.global.unregister(methodName: name)
28
28
  }
29
-
29
+
30
30
  public func respondTo(methodName name: String) -> Bool {
31
31
  return registry.respondTo(methodName: name) || MethodRegistry.global.respondTo(methodName: name)
32
32
  }
33
-
33
+
34
34
  public func method(forName name: String) -> PipeMethod? {
35
35
  return registry.method(forName: name) ?? MethodRegistry.global.method(forName: name)
36
36
  }
37
-
37
+
38
38
  public func method<T: PipeMethod>(forName name: String) -> T? {
39
39
  return method(forName: name) as? T
40
40
  }
41
-
41
+
42
42
  public func fireEvent(name: String, params: [String: Any]?) {
43
43
  engine?.fireEvent(name: name, params: params)
44
44
  }
@@ -7,37 +7,37 @@ import ObjectiveC.runtime
7
7
 
8
8
  public final class MethodRegistry {
9
9
  public static let global = MethodRegistry()
10
-
10
+
11
11
  private var methodTypeMap: [String: PipeMethod.Type] = [:]
12
12
  private var methodMap: [String: PipeMethod] = [:]
13
13
  private var lock = ReadWriteLock()
14
-
14
+
15
15
  init() {}
16
-
16
+
17
17
  public func register(methodType: PipeMethod.Type) {
18
18
  lock.write {
19
19
  methodTypeMap[methodType.methodName()] = methodType
20
20
  }
21
21
  }
22
-
22
+
23
23
  public func register(method: PipeMethod) {
24
24
  let methodName = type(of: method).methodName()
25
25
  lock.write {
26
26
  methodMap[methodName] = method
27
27
  }
28
28
  }
29
-
29
+
30
30
  public func register(methods: [PipeMethod]) {
31
- if (methods.isEmpty) { return }
31
+ if methods.isEmpty { return }
32
32
  lock.write {
33
33
  for method in methods {
34
34
  methodMap[type(of: method).methodName()] = method
35
35
  }
36
36
  }
37
37
  }
38
-
38
+
39
39
  public func register(methodTypes: [PipeMethod.Type]) {
40
- if (methodTypes.isEmpty) { return }
40
+ if methodTypes.isEmpty { return }
41
41
  let validMap: [String: PipeMethod.Type] = methodTypes.reduce(into: [String: PipeMethod.Type]()) { result, type in
42
42
  result[type.methodName()] = type
43
43
  }
@@ -45,47 +45,48 @@ public final class MethodRegistry {
45
45
  methodTypeMap.merge(validMap) { (_, new) in new }
46
46
  }
47
47
  }
48
-
48
+
49
49
  public func unregister(methodName name: String) {
50
50
  lock.write {
51
51
  methodMap[name] = nil
52
52
  methodTypeMap[name] = nil
53
53
  }
54
54
  }
55
-
55
+
56
56
  public func respondTo(methodName name: String) -> Bool {
57
57
  return lock.read {
58
58
  methodMap[name] != nil || methodTypeMap[name] != nil
59
59
  }
60
60
  }
61
-
61
+
62
62
  public func method(forName name: String) -> PipeMethod? {
63
- return lock.read { methodMap[name] } ?? lock.write {
64
- if let method = methodMap[name] {
65
- return method
63
+ return lock.read { methodMap[name] }
64
+ ?? lock.write {
65
+ if let method = methodMap[name] {
66
+ return method
67
+ }
68
+ guard let methodType = methodTypeMap[name] else {
69
+ return nil
70
+ }
71
+ let newMethod = methodType.init()
72
+ methodMap[name] = newMethod
73
+ return newMethod
66
74
  }
67
- guard let methodType = methodTypeMap[name] else {
68
- return nil
69
- }
70
- let newMethod = methodType.init()
71
- methodMap[name] = newMethod
72
- return newMethod
73
- }
74
75
  }
75
-
76
+
76
77
  public func method<T: PipeMethod>(forName name: String) -> T? {
77
78
  return method(forName: name) as? T
78
79
  }
79
-
80
+
80
81
  public static func autoRegisterGlobalMethods() {
81
82
  var count: UInt32 = 0
82
83
  let classList = objc_copyClassList(&count)!
83
84
  defer {
84
85
  free(UnsafeMutableRawPointer(classList))
85
86
  }
86
-
87
+
87
88
  let classes = UnsafeBufferPointer(start: classList, count: Int(count))
88
- var methodTypes:[PipeMethod.Type] = []
89
+ var methodTypes: [PipeMethod.Type] = []
89
90
  for i in 0..<Int(count) {
90
91
  let cls: AnyClass = classes[i]
91
92
  if class_getSuperclass(cls) == PipeMethod.self, let type = cls as? PipeMethod.Type {
@@ -7,82 +7,85 @@ import Mantle
7
7
 
8
8
  public protocol MethodModel: Codable, DictionaryCodable {
9
9
  static var requiredKeyPaths: Set<String>? { get }
10
-
10
+
11
11
  var context: MethodContext? { get set }
12
12
  }
13
13
 
14
- public extension MethodModel {
15
- func toDict() throws -> [String : Any]? {
14
+ extension MethodModel {
15
+ public func toDict() throws -> [String: Any]? {
16
16
  let data = try JSONEncoder().encode(self)
17
17
  let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any]
18
18
  return dict
19
19
  }
20
-
21
- public static func from(dict: [String : Any]) throws -> Self? {
22
- if (JSONSerialization.isValidJSONObject(dict)) {
20
+
21
+ public static func from(dict: [String: Any]) throws -> Self? {
22
+ if JSONSerialization.isValidJSONObject(dict) {
23
23
  let data = try JSONSerialization.data(withJSONObject: dict)
24
24
  let obj = try JSONDecoder().decode(Self.self, from: data)
25
25
  return obj
26
26
  }
27
- throw NSError(domain: MethodStatus.Constants.ErrorDomain, code: -1, userInfo: [
28
- NSLocalizedDescriptionKey: "\(dict) is not a valid JSONObject"
29
- ])
27
+ throw NSError(
28
+ domain: MethodStatus.Constants.ErrorDomain, code: -1,
29
+ userInfo: [
30
+ NSLocalizedDescriptionKey: "\(dict) is not a valid JSONObject"
31
+ ])
30
32
  return nil
31
33
  }
32
34
  }
33
35
 
34
- public extension MethodModel {
35
- static var requiredKeyPaths: Set<String>? {
36
+ extension MethodModel {
37
+ public static var requiredKeyPaths: Set<String>? {
36
38
  return nil
37
39
  }
38
40
  }
39
41
 
40
42
  public struct EmptyMethodModel: MethodModel {
41
43
  public static var requiredKeyPaths: Set<String>? { return nil }
42
-
44
+
43
45
  public var extraInfo: Any?
44
46
  public var context: MethodContext?
45
-
47
+
46
48
  private enum CodingKeys: CodingKey {}
47
-
49
+
48
50
  }
49
51
 
50
52
  // Added Mantle-based MethodModel base class for both Objective-C and Swift
51
53
  @objc(SPKMethodModel)
52
54
  open class SPKMethodModel: MTLModel, MTLJSONSerializing, MethodModel {
53
55
  open var context: MethodContext?
54
-
56
+
55
57
  @objc open class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
56
- return [: ]
58
+ return [:]
57
59
  }
58
-
60
+
59
61
  @objc open class func defaultValues() -> [AnyHashable: Any]? {
60
62
  return nil
61
63
  }
62
-
64
+
63
65
  open class func requiredKeyPaths() -> Set<String>? {
64
- [
65
- ]
66
+ []
66
67
  }
67
-
68
+
68
69
  // Implement DictionaryCodable protocol
69
70
  open func toDict() throws -> [String: Any]? {
70
71
  return self.dictionaryValue as? [String: Any]
71
72
  }
72
-
73
+
73
74
  public static func from(dict: [String: Any]) throws -> Self? {
74
75
  // throw a error when requiredKeyPaths is not nil and any of the keys are missing
75
76
  if let requiredKeyPaths = Self.requiredKeyPaths() {
76
77
  for key in requiredKeyPaths {
77
78
  if dict[key] == nil {
78
- throw NSError(domain: MethodStatus.Constants.ErrorDomain, code: -1, userInfo: [
79
- NSLocalizedDescriptionKey: "\(key) is required"
80
- ])
79
+ throw NSError(
80
+ domain: MethodStatus.Constants.ErrorDomain, code: -1,
81
+ userInfo: [
82
+ NSLocalizedDescriptionKey: "\(key) is required"
83
+ ])
81
84
  }
82
85
  }
83
86
  }
84
87
  // Using Swift's try-catch and Mantle's standard approach
85
-
88
+
86
89
  let adapter = MTLJSONAdapter(modelClass: self)
87
90
  do {
88
91
  let model = try adapter?.model(fromJSONDictionary: dict) as? Self
@@ -91,24 +94,26 @@ open class SPKMethodModel: MTLModel, MTLJSONSerializing, MethodModel {
91
94
  throw error
92
95
  }
93
96
  }
94
-
97
+
95
98
  // Ensure compliance with Codable protocol
96
99
  public override required init() {
97
100
  super.init()
98
101
  }
99
-
102
+
100
103
  required public init?(coder aDecoder: NSCoder) {
101
104
  super.init(coder: aDecoder)
102
105
  }
103
-
104
- required public init(dictionary dictionaryValue: [AnyHashable : Any]!) throws {
106
+
107
+ required public init(dictionary dictionaryValue: [AnyHashable: Any]!) throws {
105
108
  // throw a error when requiredKeyPaths is not nil and any of the keys are missing
106
109
  if let requiredKeyPaths = Self.requiredKeyPaths() {
107
110
  for key in requiredKeyPaths {
108
111
  if dictionaryValue[key] == nil {
109
- throw NSError(domain: MethodStatus.Constants.ErrorDomain, code: -1, userInfo: [
110
- NSLocalizedDescriptionKey: "\(key) is required"
111
- ])
112
+ throw NSError(
113
+ domain: MethodStatus.Constants.ErrorDomain, code: -1,
114
+ userInfo: [
115
+ NSLocalizedDescriptionKey: "\(key) is required"
116
+ ])
112
117
  }
113
118
  }
114
119
  }
@@ -118,12 +123,12 @@ open class SPKMethodModel: MTLModel, MTLJSONSerializing, MethodModel {
118
123
  super.init()
119
124
  }
120
125
  }
121
-
126
+
122
127
  // Implement Codable protocol methods
123
128
  public func encode(to encoder: Encoder) throws {
124
129
  // Basic implementation, subclasses can override
125
130
  }
126
-
131
+
127
132
  required public init(from decoder: Decoder) throws {
128
133
  super.init()
129
134
  // Basic implementation, subclasses can override
@@ -134,7 +139,7 @@ open class SPKMethodModel: MTLModel, MTLJSONSerializing, MethodModel {
134
139
  @objc(EmptyMethodModelClass)
135
140
  public class EmptyMethodModelClass: SPKMethodModel {
136
141
  @objc public var extraInfo: Any?
137
-
142
+
138
143
  @objc public override class func jsonKeyPathsByPropertyKey() -> [AnyHashable: Any] {
139
144
  var keyPaths = super.jsonKeyPathsByPropertyKey()
140
145
  keyPaths["extraInfo"] = "extraInfo"