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.
- package/ios/Sources/Core/DI/DIContainerProtocol.swift +1 -1
- package/ios/Sources/Core/DI/DIProviderRegistry.swift +1 -1
- package/ios/Sources/Core/Examples/SampleMethod+impl.swift +3 -3
- package/ios/Sources/Core/Examples/SampleMethod.swift +7 -7
- package/ios/Sources/Core/Models/MethodContext.swift +5 -5
- package/ios/Sources/Core/Models/MethodStatus.swift +24 -24
- package/ios/Sources/Core/Pipe/MethodPipe+Internal.swift +9 -8
- package/ios/Sources/Core/Pipe/MethodPipe.swift +8 -8
- package/ios/Sources/Core/Pipe/MethodRegistry.swift +26 -25
- package/ios/Sources/Core/Protocols/MethodModel.swift +41 -36
- package/ios/Sources/Core/Protocols/PipeMethod.swift +13 -13
- package/ios/Sources/Core/Utils/AnyCodableValue.swift +6 -6
- package/ios/Sources/Core/Utils/NSString+SPKBridgeAdditions.swift +2 -2
- package/ios/Sources/Core/Utils/ReadWriteLock.swift +6 -6
- package/ios/Sources/Core/Utils/SPKHttpResponseChromium.swift +3 -3
- package/ios/Sources/Core/Utils/SPKNetworkManager.swift +50 -46
- package/ios/Sources/Core/Utils/SPKReachability.swift +16 -12
- package/ios/Sources/DIProvider/DIContainer.swift +9 -9
- package/ios/Sources/DIProvider/DefaultDIContainerProvider.swift +3 -3
- package/ios/Sources/Debug/MethodPipe+Debug.swift +6 -4
- package/ios/Sources/Lynx/Definitions/LynxPipeStatusCode.swift +7 -7
- package/ios/Sources/Lynx/Engine/LynxConfig+SPKPipe.swift +5 -5
- package/ios/Sources/Lynx/Engine/LynxContext+SPKPipe.swift +2 -2
- package/ios/Sources/Lynx/Engine/LynxPipeEngine.swift +5 -5
- package/ios/Sources/Lynx/Engine/LynxPipeEnginePool.swift +5 -5
- package/ios/Sources/Lynx/Engine/LynxView+SPKPipe.swift +3 -3
- package/ios/Sources/Lynx/Engine/SPKLynxModuleService.swift +8 -4
- package/ios/Sources/Lynx/Models/LynxRecvMessage.swift +3 -3
- package/ios/Sources/Lynx/Models/LynxSendMessage.swift +7 -7
- package/ios/Sources/Lynx/Module/SPKLynxNativeModule.swift +7 -7
- package/ios/Sources/Lynx/Pipe/MethodPipe+Lynx.swift +11 -9
- package/ios/SparklingMethod.podspec +12 -12
- package/package.json +7 -2
- package/android/build.gradle.kts +0 -245
- package/android/gradle.properties +0 -1
- package/android/proguard-rules.pro +0 -21
- package/android/src/androidTest/java/com/tiktok/sparkling/sparkling/methods/ExampleInstrumentedTest.kt +0 -27
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/BridgeContext.kt +0 -74
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImp.kt +0 -47
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImp.kt +0 -233
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/InnerBridge.kt +0 -134
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeCall.kt +0 -79
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeResult.kt +0 -68
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcher.kt +0 -198
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManager.kt +0 -16
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcher.kt +0 -56
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModel.kt +0 -144
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptor.kt +0 -30
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModel.kt +0 -66
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModule.kt +0 -31
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtol.kt +0 -69
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModule.kt +0 -31
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxViewImpl.kt +0 -29
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegate.kt +0 -147
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitor.kt +0 -239
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/IBridgeMonitor.kt +0 -17
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntity.kt +0 -22
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeCallback.kt +0 -14
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeClient.kt +0 -19
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeHandler.kt +0 -23
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeLifeClient.kt +0 -45
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeMethodCallback.kt +0 -10
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeProtocol.kt +0 -22
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConstants.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConverter.kt +0 -147
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/LogUtils.kt +0 -37
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/MonitorUtils.kt +0 -41
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeLocalPool.kt +0 -70
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeSettings.kt +0 -19
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BusinessCallHandler.kt +0 -100
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/CancelCallbackConfig.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/DefaultCallHandler.kt +0 -106
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/IBridgeMethod.kt +0 -118
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/PiperDataExt.kt +0 -71
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/SparklingBridge.kt +0 -374
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/Utils.kt +0 -89
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/interfaces/IBridgeNotFound.kt +0 -11
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxDataProcessorForMap.kt +0 -204
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxPlatformDataProcessor.kt +0 -239
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebPlatformDataProcessor.kt +0 -307
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebProcessorForMap.kt +0 -227
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeMethodCallbackHelper.kt +0 -29
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeProtocolConstants.kt +0 -12
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtils.kt +0 -684
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/IConvertUtils.kt +0 -44
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/LogHelper.kt +0 -30
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/ThreadPool.kt +0 -73
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgeCollections.kt +0 -194
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgePlatformType.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IBridgeContext.kt +0 -137
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLBridgeMethod.kt +0 -100
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodProvider.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistry.kt +0 -132
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCache.kt +0 -150
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCacheManager.kt +0 -34
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLProxyClient.kt +0 -28
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IRegister.kt +0 -21
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/LocalBridge.kt +0 -70
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/ReadableMapImpl.kt +0 -227
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/RegistryCache.kt +0 -77
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManager.kt +0 -50
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodIntEnum.kt +0 -15
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodName.kt +0 -14
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamField.kt +0 -42
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamModel.kt +0 -10
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodResultModel.kt +0 -10
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodStringEnum.kt +0 -15
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethod.kt +0 -276
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodException.kt +0 -10
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalInputParamException.kt +0 -12
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOperationException.kt +0 -12
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOutputParamException.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IContainerIDProvider.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/INameSpaceProvider.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IPlatformDataProcessor.kt +0 -19
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IReleasable.kt +0 -13
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/BridgeCallThreadTypeConfig.kt +0 -44
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/ContextProviderFactory.kt +0 -133
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/CompletionBlock.kt +0 -26
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLDynamic.kt +0 -97
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseModel.kt +0 -37
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseParamModel.kt +0 -62
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseResultModel.kt +0 -18
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/BridgeKTX.kt +0 -37
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IAssignDir.kt +0 -25
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodHelper.kt +0 -44
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelArguments.kt +0 -264
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelHelper.kt +0 -194
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/JsonUtils.kt +0 -200
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntime.kt +0 -11
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/CommonDependsProvider.kt +0 -14
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostNetworkDepend.kt +0 -19
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostPermissionDepend.kt +0 -34
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostThreadPoolExecutorDepend.kt +0 -12
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStreamConnection.kt +0 -36
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStringConnection.kt +0 -30
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/HttpRequest.kt +0 -134
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/NetworkRequestImpl.kt +0 -28
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/RequestJsonFormatOptionConstants.kt +0 -10
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/BridgeAPIRequestUtils.kt +0 -365
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/HttpUrlBuilder.kt +0 -97
- package/android/src/main/res/drawable/ic_launcher_background.xml +0 -170
- package/android/src/main/res/drawable/ic_launcher_foreground.xml +0 -30
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -6
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -6
- package/android/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
- package/android/src/main/res/values/colors.xml +0 -10
- package/android/src/main/res/values/strings.xml +0 -3
- package/android/src/test/java/com/tiktok/sparkling/method/TestApplication.kt +0 -19
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/BridgeContextTest.kt +0 -89
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImpTest.kt +0 -78
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImpTest.kt +0 -97
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/InnerBridgeTest.kt +0 -105
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeCallTest.kt +0 -61
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeResultTest.kt +0 -74
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcherTest.kt +0 -96
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManagerTest.kt +0 -21
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcherTest.kt +0 -34
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModelTest.kt +0 -60
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptorTest.kt +0 -51
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModelTest.kt +0 -65
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModuleTest.kt +0 -57
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtocolTest.kt +0 -10
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModuleTest.kt +0 -37
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegateTest.kt +0 -10
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitorTest.kt +0 -10
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntityTest.kt +0 -43
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/SparklingBridgeTest.kt +0 -444
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtilsTest.kt +0 -236
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryTest.kt +0 -331
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/LocalBridgeTest.kt +0 -299
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManagerTest.kt +0 -213
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethodTest.kt +0 -307
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodExceptionTest.kt +0 -311
- package/android/src/test/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntimeTest.kt +0 -54
- package/android/src/test/resources/robolectric.properties +0 -5
- package/src/index.ts +0 -240
- package/src/types.ts +0 -44
- package/src/typing.d.ts +0 -44
- 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
|
}
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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] }
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
15
|
-
func toDict() throws -> [String
|
|
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
|
|
22
|
-
if
|
|
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(
|
|
28
|
-
|
|
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
|
-
|
|
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(
|
|
79
|
-
|
|
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
|
|
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(
|
|
110
|
-
|
|
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"
|