sparkling-method 2.0.0-rc.0 → 2.0.0-rc.1
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/README.md +39 -0
- package/android/build.gradle.kts +153 -0
- package/android/gradle.properties +1 -0
- package/android/proguard-rules.pro +21 -0
- package/android/src/androidTest/java/com/tiktok/sparkling/sparkling/methods/ExampleInstrumentedTest.kt +27 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/BridgeContext.kt +74 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImp.kt +47 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImp.kt +233 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/InnerBridge.kt +134 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeCall.kt +79 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/entity/BridgeResult.kt +68 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcher.kt +198 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManager.kt +16 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcher.kt +56 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModel.kt +144 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptor.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModel.kt +66 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModule.kt +31 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtol.kt +69 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModule.kt +31 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxViewImpl.kt +29 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegate.kt +147 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitor.kt +239 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/IBridgeMonitor.kt +17 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntity.kt +22 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeCallback.kt +14 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeClient.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeHandler.kt +23 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeLifeClient.kt +45 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeMethodCallback.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/interfaces/IBridgeProtocol.kt +22 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConstants.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/BridgeConverter.kt +147 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/LogUtils.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/protocol/utils/MonitorUtils.kt +41 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeLocalPool.kt +70 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BridgeSettings.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/BusinessCallHandler.kt +100 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/CancelCallbackConfig.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/DefaultCallHandler.kt +106 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/IBridgeMethod.kt +118 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/PiperDataExt.kt +71 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/SparklingBridge.kt +374 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/Utils.kt +89 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/interfaces/IBridgeNotFound.kt +11 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxDataProcessorForMap.kt +204 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/LynxPlatformDataProcessor.kt +239 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebPlatformDataProcessor.kt +307 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/processor/WebProcessorForMap.kt +227 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeMethodCallbackHelper.kt +29 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/BridgeProtocolConstants.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtils.kt +684 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/IConvertUtils.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/LogHelper.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/api/util/ThreadPool.kt +73 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgeCollections.kt +194 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/BridgePlatformType.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IBridgeContext.kt +137 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLBridgeMethod.kt +100 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistry.kt +132 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCache.kt +150 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryCacheManager.kt +34 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IDLProxyClient.kt +28 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/IRegister.kt +21 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/LocalBridge.kt +70 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/ReadableMapImpl.kt +227 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/RegistryCache.kt +77 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManager.kt +50 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodIntEnum.kt +15 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodName.kt +17 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamField.kt +42 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodParamModel.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodResultModel.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/annotation/IDLMethodStringEnum.kt +15 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethod.kt +276 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodException.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalInputParamException.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOperationException.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/exception/IllegalOutputParamException.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IContainerIDProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/INameSpaceProvider.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IPlatformDataProcessor.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/interfaces/IReleasable.kt +13 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/BridgeCallThreadTypeConfig.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/context/ContextProviderFactory.kt +133 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/CompletionBlock.kt +26 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLDynamic.kt +97 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseModel.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseParamModel.kt +62 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/model/idl/IDLMethodBaseResultModel.kt +18 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/BridgeKTX.kt +37 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IAssignDir.kt +25 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodHelper.kt +44 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelArguments.kt +264 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/IDLMethodResultModelHelper.kt +194 -0
- package/android/src/main/java/com/tiktok/sparkling/method/registry/core/utils/JsonUtils.kt +200 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntime.kt +11 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/CommonDependsProvider.kt +14 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostNetworkDepend.kt +19 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostPermissionDepend.kt +34 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/common/IHostThreadPoolExecutorDepend.kt +12 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStreamConnection.kt +36 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/AbsStringConnection.kt +30 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/HttpRequest.kt +134 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/NetworkRequestImpl.kt +28 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/network/RequestJsonFormatOptionConstants.kt +10 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/BridgeAPIRequestUtils.kt +365 -0
- package/android/src/main/java/com/tiktok/sparkling/method/runtime/depend/utils/HttpUrlBuilder.kt +97 -0
- package/android/src/main/res/drawable/ic_launcher_background.xml +170 -0
- package/android/src/main/res/drawable/ic_launcher_foreground.xml +30 -0
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
- package/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- 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 +10 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/test/java/com/tiktok/sparkling/method/TestApplication.kt +19 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/BridgeContextTest.kt +89 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeClientImpTest.kt +78 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/DefaultBridgeLifeClientImpTest.kt +97 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/InnerBridgeTest.kt +105 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeCallTest.kt +61 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/entity/BridgeResultTest.kt +74 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeDispatcherTest.kt +96 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeFactoryManagerTest.kt +21 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/handler/BridgeThreadDispatcherTest.kt +34 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/errors/JSBErrorReportModelTest.kt +60 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/interceptor/BridgeMockInterceptorTest.kt +51 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lifecycle/fe/FeCallMonitorModelTest.kt +65 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeDelegateModuleTest.kt +57 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxBridgeProtocolTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/LynxRuntimeBridgeDelegateModuleTest.kt +37 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/lynx/RealLynxBridgeDelegateTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/BridgeSDKMonitorTest.kt +10 -0
- package/android/src/test/java/com/tiktok/sparkling/method/protocol/impl/monitor/MonitorEntityTest.kt +43 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/SparklingBridgeTest.kt +444 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/api/util/DataConvertUtilsTest.kt +236 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/IDLMethodRegistryTest.kt +331 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/LocalBridgeTest.kt +299 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/SparklingBridgeManagerTest.kt +213 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/base/AbsSparklingIDLMethodTest.kt +307 -0
- package/android/src/test/java/com/tiktok/sparkling/method/registry/core/exception/IDLMethodExceptionTest.kt +311 -0
- package/android/src/test/java/com/tiktok/sparkling/method/runtime/depend/BridgeBaseRuntimeTest.kt +54 -0
- package/android/src/test/resources/robolectric.properties +5 -0
- package/dist/index.d.ts +55 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -52
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +37 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/typing.d.ts +44 -0
- package/ios/Sources/Core/DI/DIContainerProtocol.swift +27 -0
- package/ios/Sources/Core/DI/DIContainerProvider.swift +10 -0
- package/ios/Sources/Core/DI/DIProviderRegistry.swift +21 -0
- package/ios/Sources/Core/Definitions/CommonDefines.swift +17 -0
- package/ios/Sources/Core/Examples/SampleMethod+impl.swift +24 -0
- package/ios/Sources/Core/Examples/SampleMethod.swift +58 -0
- package/ios/Sources/Core/Models/MethodContext.swift +53 -0
- package/ios/Sources/Core/Models/MethodStatus.swift +146 -0
- package/ios/Sources/Core/Models/SPKAutoRegisteringMethod.swift +7 -0
- package/ios/Sources/Core/Pipe/MethodPipe+Internal.swift +90 -0
- package/ios/Sources/Core/Pipe/MethodPipe.swift +45 -0
- package/ios/Sources/Core/Pipe/MethodRegistry.swift +97 -0
- package/ios/Sources/Core/Protocols/DictionaryCodable.swift +10 -0
- package/ios/Sources/Core/Protocols/MethodModel.swift +143 -0
- package/ios/Sources/Core/Protocols/MethodPipeFacade.swift +16 -0
- package/ios/Sources/Core/Protocols/PipeContainer.swift +21 -0
- package/ios/Sources/Core/Protocols/PipeEngine.swift +10 -0
- package/ios/Sources/Core/Protocols/PipeMethod.swift +83 -0
- package/ios/Sources/Core/Protocols/PipeRuntime.swift +9 -0
- package/ios/Sources/Core/Utils/AnyCodableValue.swift +128 -0
- package/ios/Sources/Core/Utils/CoreUtils.swift +17 -0
- package/ios/Sources/Core/Utils/NSString+SPKBridgeAdditions.swift +35 -0
- package/ios/Sources/Core/Utils/ReadWriteLock.swift +33 -0
- package/ios/Sources/Core/Utils/SPKHttpResponseChromium.swift +24 -0
- package/ios/Sources/Core/Utils/SPKNetworkManager.swift +200 -0
- package/ios/Sources/Core/Utils/SPKReachability.swift +46 -0
- package/ios/Sources/DIProvider/DIContainer.swift +80 -0
- package/ios/Sources/DIProvider/DefaultDIContainerProvider.swift +21 -0
- package/ios/Sources/Debug/MethodPipe+Debug.swift +36 -0
- package/ios/Sources/Lynx/Definitions/LynxConstants.swift +19 -0
- package/ios/Sources/Lynx/Definitions/LynxPipeStatusCode.swift +26 -0
- package/ios/Sources/Lynx/Definitions/LynxTypealiases.swift +7 -0
- package/ios/Sources/Lynx/Engine/LynxConfig+SPKPipe.swift +31 -0
- package/ios/Sources/Lynx/Engine/LynxContext+SPKPipe.swift +21 -0
- package/ios/Sources/Lynx/Engine/LynxPipeEngine.swift +52 -0
- package/ios/Sources/Lynx/Engine/LynxPipeEnginePool.swift +41 -0
- package/ios/Sources/Lynx/Engine/LynxView+SPKPipe.swift +64 -0
- package/ios/Sources/Lynx/Engine/SPKLynxModuleService.swift +23 -0
- package/ios/Sources/Lynx/Models/LynxRecvMessage.swift +31 -0
- package/ios/Sources/Lynx/Models/LynxSendMessage.swift +55 -0
- package/ios/Sources/Lynx/Module/SPKLynxNativeModule.swift +41 -0
- package/ios/Sources/Lynx/Pipe/MethodPipe+Lynx.swift +53 -0
- package/ios/SparklingMethod.podspec +65 -0
- package/package.json +11 -29
- package/src/index.ts +240 -0
- package/src/types.ts +44 -0
- package/src/typing.d.ts +44 -0
- package/tsconfig.json +15 -0
- package/dist/codegen/definition-parser.d.ts +0 -5
- package/dist/codegen/definition-parser.d.ts.map +0 -1
- package/dist/codegen/definition-parser.js +0 -376
- package/dist/codegen/definition-parser.js.map +0 -1
- package/dist/codegen/index.d.ts +0 -3
- package/dist/codegen/index.d.ts.map +0 -1
- package/dist/codegen/index.js +0 -99
- package/dist/codegen/index.js.map +0 -1
- package/dist/codegen/kotlin.d.ts +0 -4
- package/dist/codegen/kotlin.d.ts.map +0 -1
- package/dist/codegen/kotlin.js +0 -273
- package/dist/codegen/kotlin.js.map +0 -1
- package/dist/codegen/metadata.d.ts +0 -4
- package/dist/codegen/metadata.d.ts.map +0 -1
- package/dist/codegen/metadata.js +0 -78
- package/dist/codegen/metadata.js.map +0 -1
- package/dist/codegen/swift.d.ts +0 -4
- package/dist/codegen/swift.d.ts.map +0 -1
- package/dist/codegen/swift.js +0 -145
- package/dist/codegen/swift.js.map +0 -1
- package/dist/codegen/template/android/kotlin-idl-template +0 -119
- package/dist/codegen/template/android/kotlin-impl-template +0 -0
- package/dist/codegen/template/ios/oc-idl-template +0 -0
- package/dist/codegen/template/ios/oc-impl-template +0 -0
- package/dist/codegen/template/ios/swift-idl-template +0 -83
- package/dist/codegen/template/ios/swift-impl-template +0 -0
- package/dist/codegen/template/ts/call-template +0 -0
- package/dist/codegen/template/ts/ts-idl-template +0 -66
- package/dist/codegen/template/ts/ts-impl-template +0 -78
- package/dist/codegen/template/ts/ts-index-template +0 -13
- package/dist/codegen/types.d.ts +0 -157
- package/dist/codegen/types.d.ts.map +0 -1
- package/dist/codegen/types.js +0 -3
- package/dist/codegen/types.js.map +0 -1
- package/dist/codegen/typescript.d.ts +0 -8
- package/dist/codegen/typescript.d.ts.map +0 -1
- package/dist/codegen/typescript.js +0 -232
- package/dist/codegen/typescript.js.map +0 -1
- package/dist/codegen/utils.d.ts +0 -10
- package/dist/codegen/utils.d.ts.map +0 -1
- package/dist/codegen/utils.js +0 -83
- package/dist/codegen/utils.js.map +0 -1
- package/dist/create/index.d.ts +0 -3
- package/dist/create/index.d.ts.map +0 -1
- package/dist/create/index.js +0 -44
- package/dist/create/index.js.map +0 -1
- package/dist/create/prompts.d.ts +0 -7
- package/dist/create/prompts.d.ts.map +0 -1
- package/dist/create/prompts.js +0 -61
- package/dist/create/prompts.js.map +0 -1
- package/dist/create/scaffold.d.ts +0 -9
- package/dist/create/scaffold.d.ts.map +0 -1
- package/dist/create/scaffold.js +0 -131
- package/dist/create/scaffold.js.map +0 -1
- package/dist/create/template/README.md +0 -17
- package/dist/create/template/android/.gitkeep +0 -1
- package/dist/create/template/ios/.gitkeep +0 -1
- package/dist/create/template/src/method.d.ts +0 -17
- package/dist/create/templates.d.ts +0 -5
- package/dist/create/templates.d.ts.map +0 -1
- package/dist/create/templates.js +0 -75
- package/dist/create/templates.js.map +0 -1
- package/dist/create/types.d.ts +0 -12
- package/dist/create/types.d.ts.map +0 -1
- package/dist/create/types.js +0 -3
- package/dist/create/types.js.map +0 -1
- package/dist/create/utils.d.ts +0 -3
- package/dist/create/utils.d.ts.map +0 -1
- package/dist/create/utils.js +0 -19
- package/dist/create/utils.js.map +0 -1
- package/dist/ui.d.ts +0 -13
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js +0 -82
- package/dist/ui.js.map +0 -1
- package/dist/verbose.d.ts +0 -4
- package/dist/verbose.d.ts.map +0 -1
- package/dist/verbose.js +0 -25
- package/dist/verbose.js.map +0 -1
- package/templates/sparkling-app-template-android-groovy/android/sparkling-method-media/build.gradle +0 -44
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.processor
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import com.tiktok.sparkling.method.registry.api.Utils
|
|
10
|
+
import com.tiktok.sparkling.method.registry.api.map
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.IBridgeContext
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.IDLBridgeMethod
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.IDLMethodRegistryCacheManager
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.BridgePlatformType
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.IDLProxyClient
|
|
16
|
+
import com.tiktok.sparkling.method.registry.core.annotation.DefaultType
|
|
17
|
+
import com.tiktok.sparkling.method.registry.core.annotation.IDLMethodIntEnum
|
|
18
|
+
import com.tiktok.sparkling.method.registry.core.annotation.IDLMethodParamField
|
|
19
|
+
import com.tiktok.sparkling.method.registry.core.annotation.IDLMethodStringEnum
|
|
20
|
+
import com.tiktok.sparkling.method.registry.core.interfaces.IPlatformDataProcessor
|
|
21
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalInputParamException
|
|
22
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseModel
|
|
23
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseParamModel
|
|
24
|
+
import org.json.JSONArray
|
|
25
|
+
import org.json.JSONObject
|
|
26
|
+
import java.lang.reflect.Method
|
|
27
|
+
import java.lang.reflect.Proxy
|
|
28
|
+
|
|
29
|
+
class WebPlatformDataProcessor : IPlatformDataProcessor<JSONObject> {
|
|
30
|
+
override fun matchPlatformType(platformType: BridgePlatformType) = platformType == BridgePlatformType.WEB
|
|
31
|
+
|
|
32
|
+
var context: IBridgeContext? = null
|
|
33
|
+
|
|
34
|
+
override fun transformPlatformDataToMap(
|
|
35
|
+
params: JSONObject,
|
|
36
|
+
clazz: Class<out IDLBridgeMethod>
|
|
37
|
+
): Map<String, Any?>? {
|
|
38
|
+
val pool =
|
|
39
|
+
(IDLMethodRegistryCacheManager.provideIDLMethodRegistryCache(context?.containerID))?.BRIDGE_ANNOTATION_MAP?.get(
|
|
40
|
+
clazz
|
|
41
|
+
)
|
|
42
|
+
if (pool != null) {
|
|
43
|
+
return WebProcessorForMap.getJavaOnlyMapParams(params, pool)
|
|
44
|
+
} else {
|
|
45
|
+
val modelClazz = IDLProxyClient.retrieveParamModel(clazz) ?: return null
|
|
46
|
+
return getJsonObjectParams(params, modelClazz)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun getJsonObjectParams(params: JSONObject, clazz: Class<out IDLMethodBaseParamModel>): Map<String, Any?>? {
|
|
51
|
+
val classMap = preCheck(clazz, params) ?: return null
|
|
52
|
+
return params.mapValues {
|
|
53
|
+
val annotation = classMap[it.first]?.second
|
|
54
|
+
val value = it.second
|
|
55
|
+
convertValueWithAnnotation(value, annotation)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private fun preCheck(clazz: Class<out IDLMethodBaseModel>?, params: JSONObject): HashMap<String, Pair<Method, IDLMethodParamField>>? {
|
|
60
|
+
val classMap = clazz?.declaredMethods?.fold(hashMapOf<String, Pair<Method, IDLMethodParamField>>()) { map, method ->
|
|
61
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
62
|
+
if (annotation != null) {
|
|
63
|
+
map[annotation.keyPath] = Pair<Method, IDLMethodParamField>(method, annotation)
|
|
64
|
+
}
|
|
65
|
+
map
|
|
66
|
+
} ?: return null
|
|
67
|
+
/**
|
|
68
|
+
* init default value
|
|
69
|
+
*/
|
|
70
|
+
classMap.filter { !params.has(it.key) && it.value.second.defaultValue.type != DefaultType.NONE }.forEach {
|
|
71
|
+
val annotation = it.value.second
|
|
72
|
+
params.put(it.key, parseStringByReturnType(it.value.first, annotation))
|
|
73
|
+
}
|
|
74
|
+
checkValue(classMap, params)
|
|
75
|
+
return classMap
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun checkValue(classMap: HashMap<String, Pair<Method, IDLMethodParamField>>, params: JSONObject) {
|
|
79
|
+
/**
|
|
80
|
+
* check value
|
|
81
|
+
*/
|
|
82
|
+
classMap.forEach {
|
|
83
|
+
val field = it.value.second
|
|
84
|
+
val method = it.value.first
|
|
85
|
+
val value = params.opt(it.key)
|
|
86
|
+
if (field.required && (value == null || value == JSONObject.NULL)) {
|
|
87
|
+
throw IllegalInputParamException("${it.key} param is missing from input")
|
|
88
|
+
}
|
|
89
|
+
when (method.returnType) {
|
|
90
|
+
String::class.java -> {
|
|
91
|
+
if (value != null && value != JSONObject.NULL && value !is String) {
|
|
92
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except string,but ${value.javaClass}")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
Number::class.java -> {
|
|
96
|
+
if (value != null && value != JSONObject.NULL && value !is Number) {
|
|
97
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except number,but ${value.javaClass}")
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
java.lang.Boolean::class.java, Boolean::class.java -> {
|
|
101
|
+
if (value != null && value != JSONObject.NULL && value !is Boolean) {
|
|
102
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except boolean,but ${value.javaClass}")
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
List::class.java -> {
|
|
106
|
+
if (value != null && value != JSONObject.NULL && value !is JSONArray) {
|
|
107
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except List ,but ${value.javaClass}")
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
Map::class.java -> {
|
|
111
|
+
if (value != null && value != JSONObject.NULL && value !is JSONObject) {
|
|
112
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except Map ,but ${value.javaClass}")
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (value != null && value != JSONObject.NULL && field.isEnum) {
|
|
117
|
+
when (method.returnType) {
|
|
118
|
+
String::class.java -> {
|
|
119
|
+
val stringEnum = method.getAnnotation(IDLMethodStringEnum::class.java)
|
|
120
|
+
val option = stringEnum.option
|
|
121
|
+
if (!option.contains(value)) {
|
|
122
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of ${option.asList()} but got $value")
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Number::class.java -> {
|
|
126
|
+
val stringEnum = method.getAnnotation(IDLMethodIntEnum::class.java)
|
|
127
|
+
val option = stringEnum.option
|
|
128
|
+
if (!option.contains(getInt(value))) {
|
|
129
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of ${option.asList()} but got $value")
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
Map::class.java -> {
|
|
133
|
+
val stringEnum = method.getAnnotation(IDLMethodStringEnum::class.java)
|
|
134
|
+
if (stringEnum != null) {
|
|
135
|
+
val option = stringEnum.option
|
|
136
|
+
(value as JSONObject).mapValues { item ->
|
|
137
|
+
if (!option.contains(item.second)) {
|
|
138
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of ${option.asList()} but got $value")
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
val intEnum = method.getAnnotation(IDLMethodIntEnum::class.java)
|
|
143
|
+
if (intEnum != null) {
|
|
144
|
+
val option = intEnum.option
|
|
145
|
+
(value as JSONObject).mapValues { item ->
|
|
146
|
+
if (!option.contains(getInt(item.second))) {
|
|
147
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of ${option.asList()} but got $value")
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* front end give 1 it may receive 1.0!
|
|
160
|
+
* let 1.0==1
|
|
161
|
+
*/
|
|
162
|
+
private fun getInt(data: Any?): Int {
|
|
163
|
+
if (data is Number) {
|
|
164
|
+
return data.toInt()
|
|
165
|
+
}
|
|
166
|
+
if (data == null) {
|
|
167
|
+
throw IllegalInputParamException("the key is null")
|
|
168
|
+
}
|
|
169
|
+
throw IllegalInputParamException("the key is not a number")
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private fun <R> JSONObject.mapValues(op: (Pair<String, Any>) -> R): Map<String, R> {
|
|
173
|
+
val map = hashMapOf<String, R>()
|
|
174
|
+
this.keys().forEach {
|
|
175
|
+
map[it] = op(Pair(it, this.opt(it)))
|
|
176
|
+
}
|
|
177
|
+
return map
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private fun proxyValue(clazz: Class<out IDLMethodBaseModel>?, map: JSONObject): Any? {
|
|
181
|
+
if (clazz == null) return null
|
|
182
|
+
preCheck(clazz, map) ?: return null
|
|
183
|
+
return Proxy.newProxyInstance(clazz.classLoader, arrayOf(clazz)) { _, method, _ ->
|
|
184
|
+
if (method.name == "toJSON") {
|
|
185
|
+
return@newProxyInstance getMapWithDefault(clazz, map)
|
|
186
|
+
}
|
|
187
|
+
if (method.name == "toString") {
|
|
188
|
+
return@newProxyInstance map.toString()
|
|
189
|
+
}
|
|
190
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
191
|
+
val value = map.opt(annotation.keyPath)
|
|
192
|
+
return@newProxyInstance convertValueWithAnnotation(value, annotation)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private fun convertValueWithAnnotation(value: Any?, annotation: IDLMethodParamField?) = if (isNestClass(value, annotation)) {
|
|
197
|
+
proxyValue(annotation?.nestedClassType?.java, value as JSONObject)
|
|
198
|
+
} else if (isNestListClass(value, annotation)) {
|
|
199
|
+
(value as JSONArray).map {
|
|
200
|
+
proxyValue(annotation?.nestedClassType?.java, it as JSONObject)
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
when (value) {
|
|
204
|
+
is JSONArray -> {
|
|
205
|
+
Utils.jsonToList(value)
|
|
206
|
+
}
|
|
207
|
+
is JSONObject -> {
|
|
208
|
+
Utils.jsonToMap(value)
|
|
209
|
+
}
|
|
210
|
+
JSONObject.NULL -> {
|
|
211
|
+
null
|
|
212
|
+
}
|
|
213
|
+
else -> {
|
|
214
|
+
value
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private fun isNestClass(value: Any?, annotation: IDLMethodParamField?) =
|
|
220
|
+
value is JSONObject && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
221
|
+
|
|
222
|
+
private fun isNestListClass(value: Any?, annotation: IDLMethodParamField?) =
|
|
223
|
+
value is JSONArray && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
224
|
+
|
|
225
|
+
private fun getMapWithDefault(clazz: Class<out IDLMethodBaseModel>?, json: JSONObject): JSONObject {
|
|
226
|
+
val methods = clazz?.declaredMethods?.filter { it.getAnnotation(IDLMethodParamField::class.java)?.isGetter == true }
|
|
227
|
+
return methods?.fold(JSONObject()) { acc, method ->
|
|
228
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
229
|
+
|
|
230
|
+
val value = json.opt(annotation.keyPath)
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* init default value
|
|
234
|
+
*/
|
|
235
|
+
if ((value == null || value == JSONObject.NULL ) && annotation.defaultValue.type != DefaultType.NONE) {
|
|
236
|
+
val defaultValue = parseStringByReturnType(method, annotation)
|
|
237
|
+
json.put(annotation.keyPath, defaultValue)
|
|
238
|
+
}
|
|
239
|
+
val nestedClassType = annotation.nestedClassType
|
|
240
|
+
acc.put(
|
|
241
|
+
annotation.keyPath, if (annotation.nestedClassType != IDLMethodBaseModel.Default::class && value is JSONObject) {
|
|
242
|
+
getMapWithDefault(nestedClassType.java, value)
|
|
243
|
+
} else if(annotation.nestedClassType != IDLMethodBaseModel.Default::class && value is JSONArray){
|
|
244
|
+
value.map { getMapWithDefault(nestedClassType.java, it as JSONObject) }
|
|
245
|
+
} else {
|
|
246
|
+
json.opt(annotation.keyPath)
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
acc
|
|
250
|
+
} ?: JSONObject()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
private fun MutableMap<String, Any>.initDefaultValue(getters: List<Method>) {
|
|
254
|
+
val defaultMethods = getters.filter { it.getAnnotation(IDLMethodParamField::class.java).defaultValue.type != DefaultType.NONE }
|
|
255
|
+
defaultMethods.forEach {
|
|
256
|
+
val annotation = it.getAnnotation(IDLMethodParamField::class.java)
|
|
257
|
+
put(
|
|
258
|
+
annotation.keyPath, parseStringByReturnType(it, annotation)
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private fun getJsonWithDefault(clazz: Class<out IDLMethodBaseModel>?, map: JSONObject): JSONObject? {
|
|
264
|
+
val methods = clazz?.declaredMethods?.filter { it.getAnnotation(IDLMethodParamField::class.java)?.isGetter == true }
|
|
265
|
+
return methods?.fold(JSONObject()) { acc, method ->
|
|
266
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
267
|
+
|
|
268
|
+
val value = map.opt(annotation.keyPath)
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* init default value
|
|
272
|
+
*/
|
|
273
|
+
if ((value == null || value == JSONObject.NULL)&& annotation.defaultValue.type != DefaultType.NONE) {
|
|
274
|
+
val defaultValue = parseStringByReturnType(method, annotation)
|
|
275
|
+
map.put(annotation.keyPath, defaultValue)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
acc.put(
|
|
279
|
+
annotation.keyPath, if (annotation.nestedClassType != IDLMethodBaseModel.Default::class && value != null && value != JSONObject.NULL ) {
|
|
280
|
+
val nestedClassType = annotation.nestedClassType
|
|
281
|
+
getJsonWithDefault(nestedClassType.java, value as JSONObject)
|
|
282
|
+
} else {
|
|
283
|
+
map.opt(annotation.keyPath)
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
acc
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private fun parseStringByReturnType(method: Method, annotation: IDLMethodParamField) = when (method.returnType) {
|
|
291
|
+
Number::class.java -> when (annotation.defaultValue.type) {
|
|
292
|
+
DefaultType.DOUBLE -> annotation.defaultValue.doubleValue
|
|
293
|
+
DefaultType.LONG -> annotation.defaultValue.longValue
|
|
294
|
+
DefaultType.INT -> annotation.defaultValue.intValue
|
|
295
|
+
else -> annotation.defaultValue.intValue
|
|
296
|
+
}
|
|
297
|
+
Boolean::class.java, java.lang.Boolean::class.java -> annotation.defaultValue.boolValue
|
|
298
|
+
else -> annotation.defaultValue.stringValue
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
override fun transformMapToPlatformData(
|
|
302
|
+
params: Map<String, Any?>,
|
|
303
|
+
clazz: Class<out IDLBridgeMethod>
|
|
304
|
+
): JSONObject {
|
|
305
|
+
return Utils.mapToJSON(params)
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.processor
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.registry.api.Utils
|
|
9
|
+
import com.tiktok.sparkling.method.registry.api.map
|
|
10
|
+
import com.tiktok.sparkling.method.registry.core.IDLAnnotationData
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.IDLAnnotationModel
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.IDLParamField
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.annotation.DefaultType
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalInputParamException
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseModel
|
|
16
|
+
import org.json.JSONArray
|
|
17
|
+
import org.json.JSONObject
|
|
18
|
+
import java.lang.reflect.Proxy
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @since 2021/10/13
|
|
22
|
+
* @desc
|
|
23
|
+
*/
|
|
24
|
+
object WebProcessorForMap {
|
|
25
|
+
fun getJavaOnlyMapParams(params: JSONObject, clazz: IDLAnnotationData): Map<String, Any?>? {
|
|
26
|
+
val classMap = preCheck(clazz.methodParamModel, params) ?: return null
|
|
27
|
+
return params.mapValues {
|
|
28
|
+
val annotation = classMap.stringModel[it.first]
|
|
29
|
+
val value = it.second
|
|
30
|
+
convertValueWithAnnotation(value, annotation, clazz)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private fun <R> JSONObject.mapValues(op: (Pair<String, Any>) -> R): Map<String, R> {
|
|
35
|
+
val map = hashMapOf<String, R>()
|
|
36
|
+
this.keys().forEach {
|
|
37
|
+
map[it] = op(Pair(it, this.opt(it)))
|
|
38
|
+
}
|
|
39
|
+
return map
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Throws(IllegalInputParamException::class)
|
|
43
|
+
private fun proxyValue(clazz: Class<out IDLMethodBaseModel>?, map: JSONObject, data: IDLAnnotationData): Any? {
|
|
44
|
+
if (clazz == null) return null
|
|
45
|
+
val clazzMap = preCheck(data.models[clazz], map) ?: return null
|
|
46
|
+
return Proxy.newProxyInstance(clazz.classLoader, arrayOf(clazz)) { _, method, _ ->
|
|
47
|
+
if (method.name == "toJSON") {
|
|
48
|
+
return@newProxyInstance getMapWithDefault(map, data.models[clazz], data)
|
|
49
|
+
}
|
|
50
|
+
if (method.name == "toString") {
|
|
51
|
+
return@newProxyInstance map.toString()
|
|
52
|
+
}
|
|
53
|
+
val annotation = clazzMap.methodModel[method]
|
|
54
|
+
val value = map.opt(annotation?.keyPath)
|
|
55
|
+
return@newProxyInstance convertValueWithAnnotation(value, annotation, data)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private fun convertValueWithAnnotation(value: Any?, annotation: IDLParamField?, data: IDLAnnotationData): Any? {
|
|
60
|
+
val result = if (isNestClass(value, annotation)) {
|
|
61
|
+
proxyValue(annotation?.nestedClassType?.java, value as JSONObject, data)
|
|
62
|
+
}else if (isNestListClass(value, annotation)) {
|
|
63
|
+
(value as JSONArray).map {
|
|
64
|
+
proxyValue(annotation?.nestedClassType?.java, it as JSONObject,data)
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
when (value) {
|
|
68
|
+
is JSONArray -> {
|
|
69
|
+
Utils.jsonToList(value)
|
|
70
|
+
}
|
|
71
|
+
is JSONObject -> {
|
|
72
|
+
Utils.jsonToMap(value)
|
|
73
|
+
}
|
|
74
|
+
JSONObject.NULL->{
|
|
75
|
+
null
|
|
76
|
+
}
|
|
77
|
+
else -> {
|
|
78
|
+
value
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private fun checkValue(classMap: IDLAnnotationModel, params: JSONObject) {
|
|
86
|
+
/**
|
|
87
|
+
* check value
|
|
88
|
+
*/
|
|
89
|
+
classMap.stringModel.forEach {
|
|
90
|
+
val field = it.key
|
|
91
|
+
val method = it.value
|
|
92
|
+
val value = params.opt(field)
|
|
93
|
+
if (method.required && (value == null || value == JSONObject.NULL)) {
|
|
94
|
+
throw IllegalInputParamException("${it.key} param is missing from input")
|
|
95
|
+
}
|
|
96
|
+
when (method.returnType) {
|
|
97
|
+
String::class.java -> {
|
|
98
|
+
if (value != null && value != JSONObject.NULL && value !is String) {
|
|
99
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except string,but ${value.javaClass}")
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Number::class.java -> {
|
|
103
|
+
if (value != null && value != JSONObject.NULL && value !is Number) {
|
|
104
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except number,but ${value.javaClass}")
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
java.lang.Boolean::class.java, Boolean::class.java -> {
|
|
108
|
+
if (value != null && value != JSONObject.NULL && value !is Boolean) {
|
|
109
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except boolean,but ${value.javaClass}")
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
List::class.java -> {
|
|
113
|
+
if (value != null && value != JSONObject.NULL && value !is JSONArray) {
|
|
114
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except List ,but ${value.javaClass}")
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
Map::class.java -> {
|
|
118
|
+
if (value != null && value != JSONObject.NULL && value !is JSONObject) {
|
|
119
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except Map ,but ${value.javaClass}")
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (value != null && value != JSONObject.NULL && method.isEnum) {
|
|
124
|
+
when (method.returnType) {
|
|
125
|
+
String::class.java -> {
|
|
126
|
+
val option = method.stringEnum
|
|
127
|
+
if (!option.contains(value)) {
|
|
128
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of $option but got $value")
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
Number::class.java -> {
|
|
132
|
+
val option = method.intEnum
|
|
133
|
+
if (!option.contains(getInt(value))) {
|
|
134
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of $option but got $value")
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
Map::class.java -> {
|
|
138
|
+
val stringEnum = method.stringEnum
|
|
139
|
+
if (stringEnum.isNotEmpty()) {
|
|
140
|
+
(value as JSONObject).mapValues { item ->
|
|
141
|
+
if (!stringEnum.contains(item.second)) {
|
|
142
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of $stringEnum but got $value")
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
val intEnum = method.intEnum
|
|
147
|
+
if (intEnum.isNotEmpty()) {
|
|
148
|
+
(value as JSONObject).mapValues { item ->
|
|
149
|
+
if (!intEnum.contains(item.second)) {
|
|
150
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of $intEnum but got $value")
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* front end give 1 but lynx receive 1.0!
|
|
163
|
+
* let 1.0==1
|
|
164
|
+
*/
|
|
165
|
+
private fun getInt(data: Any?): Int {
|
|
166
|
+
if (data is Number) {
|
|
167
|
+
return data.toInt()
|
|
168
|
+
}
|
|
169
|
+
if (data == null) {
|
|
170
|
+
throw IllegalInputParamException("the key is null")
|
|
171
|
+
}
|
|
172
|
+
throw IllegalInputParamException("the key is not a number")
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
private fun isNestClass(value: Any?, annotation: IDLParamField?) = value is JSONObject && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
177
|
+
|
|
178
|
+
private fun isNestListClass(value: Any?, annotation: IDLParamField?) =
|
|
179
|
+
value is JSONArray && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
180
|
+
|
|
181
|
+
private fun preCheck(classMap: IDLAnnotationModel?, map: JSONObject): IDLAnnotationModel? {
|
|
182
|
+
/**
|
|
183
|
+
* init default value
|
|
184
|
+
*/
|
|
185
|
+
if (classMap == null) return null
|
|
186
|
+
classMap.stringModel.filter { (map.opt(it.key) == null || map.opt(it.key) == JSONObject.NULL) && it.value.defaultValue.type != DefaultType.NONE }.forEach {
|
|
187
|
+
val idlParamField = it.value
|
|
188
|
+
map.put(it.key, parseStringByReturnType(idlParamField.returnType, idlParamField))
|
|
189
|
+
}
|
|
190
|
+
checkValue(classMap, map)
|
|
191
|
+
return classMap
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private fun parseStringByReturnType(returnType: Class<*>, annotation: IDLParamField) = when (returnType) {
|
|
195
|
+
Number::class.java -> when (annotation.defaultValue.type) {
|
|
196
|
+
DefaultType.DOUBLE -> annotation.defaultValue.doubleValue
|
|
197
|
+
DefaultType.LONG -> annotation.defaultValue.longValue
|
|
198
|
+
DefaultType.INT -> annotation.defaultValue.intValue
|
|
199
|
+
else -> annotation.defaultValue.intValue
|
|
200
|
+
}
|
|
201
|
+
Boolean::class.java, java.lang.Boolean::class.java -> annotation.defaultValue.boolValue
|
|
202
|
+
else -> annotation.defaultValue.stringValue
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private fun getMapWithDefault(map: JSONObject, model: IDLAnnotationModel?, data: IDLAnnotationData): JSONObject? {
|
|
206
|
+
if (model == null) return null
|
|
207
|
+
val stringModel = model.stringModel
|
|
208
|
+
return JSONObject(stringModel.mapValues {
|
|
209
|
+
val value = map.opt(it.value.keyPath)
|
|
210
|
+
/**
|
|
211
|
+
* init default value
|
|
212
|
+
*/
|
|
213
|
+
if ((value == null || value == JSONObject.NULL)&& it.value.defaultValue.type != DefaultType.NONE) {
|
|
214
|
+
val defaultValue = parseStringByReturnType(it.value.returnType, it.value)
|
|
215
|
+
map.put(it.value.keyPath, defaultValue)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (it.value.nestedClassType != IDLMethodBaseModel.Default::class && value is JSONObject) {
|
|
219
|
+
getMapWithDefault(value, data.models[it.value.nestedClassType.java]!!, data)
|
|
220
|
+
} else if (it.value.nestedClassType != IDLMethodBaseModel.Default::class && value is JSONArray) {
|
|
221
|
+
value.map { v -> getMapWithDefault(v as JSONObject, data.models[it.value.nestedClassType.java]!!, data) }
|
|
222
|
+
} else {
|
|
223
|
+
map.opt(it.value.keyPath)
|
|
224
|
+
}
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.util
|
|
7
|
+
|
|
8
|
+
import com.tiktok.sparkling.method.protocol.interfaces.IBridgeMethodCallback
|
|
9
|
+
import org.json.JSONObject
|
|
10
|
+
|
|
11
|
+
object BridgeMethodCallbackHelper {
|
|
12
|
+
fun bridgeNotFound(callback: IBridgeMethodCallback) {
|
|
13
|
+
val jsonObject = JSONObject().apply {
|
|
14
|
+
put("code", -2)
|
|
15
|
+
put("data", JSONObject())
|
|
16
|
+
put("msg", "The JSBridge method is not found, please register")
|
|
17
|
+
}
|
|
18
|
+
callback.onBridgeResult(jsonObject)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fun bridgeNoPermission(callback: IBridgeMethodCallback) {
|
|
22
|
+
val jsonObject = JSONObject().apply {
|
|
23
|
+
put("code", -1)
|
|
24
|
+
put("data", JSONObject())
|
|
25
|
+
put("msg", "The URL is not authorized to call this JSBridge method")
|
|
26
|
+
}
|
|
27
|
+
callback.onBridgeResult(jsonObject)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) 2022 TikTok Pte. Ltd.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
package com.tiktok.sparkling.method.registry.api.util
|
|
7
|
+
|
|
8
|
+
class BridgeProtocolConstants {
|
|
9
|
+
companion object {
|
|
10
|
+
const val BRIDGE_LYNX_PROTOCOL = 1 shl 4
|
|
11
|
+
}
|
|
12
|
+
}
|