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,89 @@
|
|
|
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
|
|
7
|
+
|
|
8
|
+
import com.lynx.react.bridge.WritableArray
|
|
9
|
+
import com.lynx.react.bridge.WritableMap
|
|
10
|
+
import com.tiktok.sparkling.method.registry.core.XReadableArray
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.XReadableMap
|
|
12
|
+
import com.tiktok.sparkling.method.registry.api.util.DataConvertUtils
|
|
13
|
+
import org.json.JSONArray
|
|
14
|
+
import org.json.JSONObject
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
object Utils {
|
|
18
|
+
|
|
19
|
+
fun toStringOrJson(data: Any?): String {
|
|
20
|
+
return DataConvertUtils.toStringOrJson(data)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fun mapToJSON(map: Map<String, Any?>): JSONObject {
|
|
24
|
+
return DataConvertUtils.mapToJSON(map)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fun mapSupportPiperdataToJSON(map: Map<String, Any?>): JSONObject {
|
|
28
|
+
return DataConvertUtils.mapSupportPiperdataToJSON(map)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fun listSupportPiperdataToJSON(list: List<Any>): JSONArray {
|
|
32
|
+
return DataConvertUtils.listSupportPiperdataToJSON(list)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun listToJSON(list: List<Any>): JSONArray {
|
|
36
|
+
return DataConvertUtils.listToJSON(list)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun jsonToMap(json: JSONObject): Map<String, Any?> {
|
|
40
|
+
return DataConvertUtils.jsonToMap(json)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fun jsonToList(json: JSONArray): List<Any?> {
|
|
44
|
+
return DataConvertUtils.jsonToList(json)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@JvmStatic
|
|
48
|
+
fun convertJsonToMap(jsonObject: JSONObject): WritableMap {
|
|
49
|
+
return DataConvertUtils.convertJsonToMap(jsonObject)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@JvmStatic
|
|
53
|
+
fun convertJsonToArray(jsonArray: JSONArray): WritableArray {
|
|
54
|
+
return DataConvertUtils.convertJsonToArray(jsonArray)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@JvmStatic
|
|
58
|
+
fun convertMapToReadableMap(source: Map<String, Any?>): WritableMap {
|
|
59
|
+
return DataConvertUtils.convertMapToReadableMap(source)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@JvmStatic
|
|
63
|
+
fun convertArrayToWritableArray(sourceArray: List<Any>): WritableArray {
|
|
64
|
+
return DataConvertUtils.convertArrayToWritableArray(sourceArray)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@JvmStatic
|
|
68
|
+
fun convertXReadableMapToReadableMap(source: XReadableMap): WritableMap {
|
|
69
|
+
return DataConvertUtils.convertXReadableMapToReadableMap(source)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@JvmStatic
|
|
73
|
+
fun convertXReadableArrayToReadableArray(source: XReadableArray): WritableArray {
|
|
74
|
+
return DataConvertUtils.convertXReadableArrayToReadableArray(source)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fun getValue(value: Any?): Any? {
|
|
78
|
+
return DataConvertUtils.getValue(value)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
internal fun <T> JSONArray.map(cb: (item: Any) -> T): List<T> {
|
|
84
|
+
val result = mutableListOf<T>()
|
|
85
|
+
for (i in 0 until this.length()) {
|
|
86
|
+
result.add(cb(opt(i)))
|
|
87
|
+
}
|
|
88
|
+
return result
|
|
89
|
+
}
|
package/android/src/main/java/com/tiktok/sparkling/method/registry/api/interfaces/IBridgeNotFound.kt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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.interfaces
|
|
7
|
+
|
|
8
|
+
interface IBridgeNotFound {
|
|
9
|
+
fun callBridgeNotFound()
|
|
10
|
+
}
|
|
11
|
+
|
|
@@ -0,0 +1,204 @@
|
|
|
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.lynx.react.bridge.ReadableArray
|
|
10
|
+
import com.lynx.react.bridge.ReadableMap
|
|
11
|
+
import com.tiktok.sparkling.method.registry.core.IDLAnnotationData
|
|
12
|
+
import com.tiktok.sparkling.method.registry.core.IDLAnnotationModel
|
|
13
|
+
import com.tiktok.sparkling.method.registry.core.IDLParamField
|
|
14
|
+
import com.tiktok.sparkling.method.registry.core.annotation.DefaultType
|
|
15
|
+
import com.tiktok.sparkling.method.registry.core.exception.IllegalInputParamException
|
|
16
|
+
import com.tiktok.sparkling.method.registry.core.model.idl.IDLMethodBaseModel
|
|
17
|
+
import org.json.JSONObject
|
|
18
|
+
import java.lang.reflect.Proxy
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @since 2021/10/13
|
|
22
|
+
* @desc
|
|
23
|
+
*/
|
|
24
|
+
object LynxDataProcessorForMap {
|
|
25
|
+
fun getJavaOnlyMapParams(params: HashMap<String, Any>, clazz: IDLAnnotationData): Map<String, Any?>? {
|
|
26
|
+
val classMap = preCheck(clazz.methodParamModel, params) ?: return null
|
|
27
|
+
return params.mapValues {
|
|
28
|
+
val annotation = classMap.stringModel[it.key]
|
|
29
|
+
val value = it.value
|
|
30
|
+
convertValueWithAnnotation(value, annotation, clazz)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Throws(IllegalInputParamException::class)
|
|
35
|
+
private fun proxyValue(clazz: Class<out IDLMethodBaseModel>?, map: HashMap<String, Any>, data: IDLAnnotationData): Any? {
|
|
36
|
+
if (clazz == null) return null
|
|
37
|
+
val clazzMap = preCheck(data.models[clazz], map) ?: return null
|
|
38
|
+
return Proxy.newProxyInstance(clazz.classLoader, arrayOf(clazz)) { _, method, _ ->
|
|
39
|
+
if (method.name == "toJSON") {
|
|
40
|
+
val fold = getMapWithDefault(map, data.models[clazz], data)
|
|
41
|
+
return@newProxyInstance JSONObject(fold)
|
|
42
|
+
}
|
|
43
|
+
if (method.name == "toString") {
|
|
44
|
+
return@newProxyInstance map.toString()
|
|
45
|
+
}
|
|
46
|
+
val annotation = clazzMap.methodModel[method]
|
|
47
|
+
val value = map[annotation?.keyPath]
|
|
48
|
+
return@newProxyInstance convertValueWithAnnotation(value, annotation, data)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private fun convertValueWithAnnotation(value: Any?, annotation: IDLParamField?, data: IDLAnnotationData): Any? {
|
|
53
|
+
val result = if (isNestClass(value, annotation)) {
|
|
54
|
+
proxyValue(annotation?.nestedClassType?.java, (value as ReadableMap).toHashMap(), data)
|
|
55
|
+
} else if (isNestListClass(value, annotation)) {
|
|
56
|
+
(value as List<*>).map {
|
|
57
|
+
proxyValue(annotation?.nestedClassType?.java, (it as ReadableMap).toHashMap(), data)
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
Utils.getValue(value)
|
|
61
|
+
}
|
|
62
|
+
return result
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private fun checkValue(classMap: IDLAnnotationModel, params: HashMap<String, Any>) {
|
|
66
|
+
/**
|
|
67
|
+
* check value
|
|
68
|
+
*/
|
|
69
|
+
classMap.stringModel.forEach {
|
|
70
|
+
val field = it.key
|
|
71
|
+
val method = it.value
|
|
72
|
+
val value = params[field]
|
|
73
|
+
if (method.required && value == null) {
|
|
74
|
+
throw IllegalInputParamException("${it.key} param is missing from input")
|
|
75
|
+
}
|
|
76
|
+
when (method.returnType) {
|
|
77
|
+
String::class.java -> {
|
|
78
|
+
if (value != null && value !is String) {
|
|
79
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except string,but ${value.javaClass}")
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
Number::class.java -> {
|
|
83
|
+
if (value != null && value !is Number) {
|
|
84
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except number,but ${value.javaClass}")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
java.lang.Boolean::class.java, Boolean::class.java -> {
|
|
88
|
+
if (value != null && value !is Boolean) {
|
|
89
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except boolean,but ${value.javaClass}")
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
List::class.java -> {
|
|
93
|
+
if (value != null && value !is List<*>) {
|
|
94
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except List ,but ${value.javaClass}")
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
Map::class.java -> {
|
|
98
|
+
if (value != null && value !is Map<*, *>) {
|
|
99
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except Map ,but ${value.javaClass}")
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (value != null && method.isEnum) {
|
|
104
|
+
when (method.returnType) {
|
|
105
|
+
String::class.java -> {
|
|
106
|
+
val option = method.stringEnum
|
|
107
|
+
if (!option.contains(value)) {
|
|
108
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of $option but got $value")
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
Number::class.java -> {
|
|
112
|
+
val option = method.intEnum
|
|
113
|
+
if (!option.contains(getInt(value))) {
|
|
114
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of $option but got $value")
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
Map::class.java -> {
|
|
118
|
+
val stringEnum = method.stringEnum
|
|
119
|
+
if (stringEnum.isNotEmpty()) {
|
|
120
|
+
if ((value as Map<String, Any>).any { item -> !stringEnum.contains(item.value) }) {
|
|
121
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of $stringEnum but got $value")
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
val intEnum = method.intEnum
|
|
125
|
+
if (intEnum.isNotEmpty()) {
|
|
126
|
+
if ((value as Map<String, Any>).any { item -> !intEnum.contains(getInt(item.value)) }) {
|
|
127
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of $intEnum but got $value")
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* front end give 1 but lynx receive 1.0!
|
|
139
|
+
* let 1.0==1
|
|
140
|
+
*/
|
|
141
|
+
private fun getInt(data: Any?): Int {
|
|
142
|
+
if (data is Number) {
|
|
143
|
+
return data.toInt()
|
|
144
|
+
}
|
|
145
|
+
if (data == null) {
|
|
146
|
+
throw IllegalInputParamException("the key is null")
|
|
147
|
+
}
|
|
148
|
+
throw IllegalInputParamException("the key is not a number")
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
private fun isNestClass(value: Any?, annotation: IDLParamField?) = value is Map<*, *> && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
153
|
+
|
|
154
|
+
private fun isNestListClass(value: Any?, annotation: IDLParamField?) =
|
|
155
|
+
value is List<*> && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
private fun preCheck(classMap: IDLAnnotationModel?, map: HashMap<String, Any>): IDLAnnotationModel? {
|
|
159
|
+
/**
|
|
160
|
+
* init default value
|
|
161
|
+
*/
|
|
162
|
+
if (classMap == null) return null
|
|
163
|
+
classMap.stringModel.filter { map[it.key] == null && it.value.defaultValue.type != DefaultType.NONE }.forEach {
|
|
164
|
+
val idlParamField = it.value
|
|
165
|
+
map[it.key] = parseStringByReturnType(idlParamField.returnType, idlParamField)
|
|
166
|
+
}
|
|
167
|
+
checkValue(classMap, map)
|
|
168
|
+
return classMap
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private fun parseStringByReturnType(returnType: Class<*>, annotation: IDLParamField) = when (returnType) {
|
|
172
|
+
Number::class.java -> when (annotation.defaultValue.type) {
|
|
173
|
+
DefaultType.DOUBLE -> annotation.defaultValue.doubleValue
|
|
174
|
+
DefaultType.LONG -> annotation.defaultValue.longValue
|
|
175
|
+
DefaultType.INT -> annotation.defaultValue.intValue
|
|
176
|
+
else -> annotation.defaultValue.intValue
|
|
177
|
+
}
|
|
178
|
+
Boolean::class.java, java.lang.Boolean::class.java -> annotation.defaultValue.boolValue
|
|
179
|
+
else -> annotation.defaultValue.stringValue
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private fun getMapWithDefault(map: HashMap<String, Any>, model: IDLAnnotationModel?, data: IDLAnnotationData): Map<String, Any?>? {
|
|
183
|
+
if (model == null) return null
|
|
184
|
+
val stringModel = model.stringModel
|
|
185
|
+
return stringModel.mapValues {
|
|
186
|
+
val value = map[it.value.keyPath]
|
|
187
|
+
/**
|
|
188
|
+
* init default value
|
|
189
|
+
*/
|
|
190
|
+
if (value == null && it.value.defaultValue.type != DefaultType.NONE) {
|
|
191
|
+
val defaultValue = parseStringByReturnType(it.value.returnType, it.value)
|
|
192
|
+
map[it.value.keyPath] = defaultValue
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (it.value.nestedClassType != IDLMethodBaseModel.Default::class && value is ReadableMap) {
|
|
196
|
+
getMapWithDefault(value.toHashMap(), data.models[it.value.nestedClassType.java]!!, data)
|
|
197
|
+
} else if (it.value.nestedClassType != IDLMethodBaseModel.Default::class && value is ReadableArray) {
|
|
198
|
+
value.toArrayList().map { v -> getMapWithDefault((v as ReadableMap).toHashMap(), data.models[it.value.nestedClassType.java]!!, data) }
|
|
199
|
+
} else {
|
|
200
|
+
map[it.value.keyPath]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
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.lynx.react.bridge.ReadableArray
|
|
10
|
+
import com.lynx.react.bridge.ReadableMap
|
|
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.JSONObject
|
|
25
|
+
import java.lang.reflect.Method
|
|
26
|
+
import java.lang.reflect.Proxy
|
|
27
|
+
|
|
28
|
+
class LynxPlatformDataProcessor : IPlatformDataProcessor<ReadableMap> {
|
|
29
|
+
|
|
30
|
+
var context : IBridgeContext? = null
|
|
31
|
+
|
|
32
|
+
override fun matchPlatformType(platformType: BridgePlatformType) = platformType == BridgePlatformType.LYNX
|
|
33
|
+
|
|
34
|
+
@Throws(IllegalInputParamException::class)
|
|
35
|
+
override fun transformPlatformDataToMap(params: ReadableMap, clazz: Class<out IDLBridgeMethod>): Map<String, Any?>? {
|
|
36
|
+
val pool = (IDLMethodRegistryCacheManager.provideIDLMethodRegistryCache(context?.containerID))?.BRIDGE_ANNOTATION_MAP?.get(clazz)
|
|
37
|
+
return if (pool != null) {
|
|
38
|
+
LynxDataProcessorForMap.getJavaOnlyMapParams(params.toHashMap(), pool)
|
|
39
|
+
} else {
|
|
40
|
+
println("idl ReadableMap->Map. no cache")
|
|
41
|
+
val modelClazz = IDLProxyClient.retrieveParamModel(clazz) ?: return null
|
|
42
|
+
getJavaOnlyMapParams(params.toHashMap(), modelClazz)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private fun getJavaOnlyMapParams(params: HashMap<String, Any>, clazz: Class<out IDLMethodBaseParamModel>): Map<String, Any?>? {
|
|
47
|
+
val classMap = preCheck(clazz, params) ?: return null
|
|
48
|
+
return params.mapValues {
|
|
49
|
+
val annotation = classMap[it.key]?.second
|
|
50
|
+
val value = it.value
|
|
51
|
+
convertValueWithAnnotation(value, annotation)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Throws(IllegalInputParamException::class)
|
|
56
|
+
private fun proxyValue(clazz: Class<out IDLMethodBaseModel>?, map: HashMap<String, Any>): Any? {
|
|
57
|
+
if (clazz == null) return null
|
|
58
|
+
preCheck(clazz, map) ?: return null
|
|
59
|
+
return Proxy.newProxyInstance(clazz.classLoader, arrayOf(clazz)) { _, method, _ ->
|
|
60
|
+
if (method.name == "toJSON") {
|
|
61
|
+
val fold = getMapWithDefault(clazz, map)
|
|
62
|
+
return@newProxyInstance JSONObject(fold)
|
|
63
|
+
}
|
|
64
|
+
if (method.name == "toString") {
|
|
65
|
+
return@newProxyInstance map.toString()
|
|
66
|
+
}
|
|
67
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
68
|
+
val value = map[annotation.keyPath]
|
|
69
|
+
return@newProxyInstance convertValueWithAnnotation(value, annotation)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private fun convertValueWithAnnotation(value: Any?, annotation: IDLMethodParamField?): Any? {
|
|
74
|
+
val result = if (isNestClass(value, annotation)) {
|
|
75
|
+
proxyValue(annotation?.nestedClassType?.java, (value as ReadableMap).toHashMap()/* = java.util.HashMap<kotlin.String, kotlin.Any> */)
|
|
76
|
+
} else if (isNestListClass(value, annotation)){
|
|
77
|
+
(value as List<*>).map {
|
|
78
|
+
proxyValue(annotation?.nestedClassType?.java, (it as ReadableMap).toHashMap())
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
Utils.getValue(value)
|
|
82
|
+
}
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private fun checkValue(classMap: HashMap<String, Pair<Method, IDLMethodParamField>>, params: HashMap<String, Any>) {
|
|
87
|
+
/**
|
|
88
|
+
* check value
|
|
89
|
+
*/
|
|
90
|
+
classMap.forEach {
|
|
91
|
+
val field = it.value.second
|
|
92
|
+
val method = it.value.first
|
|
93
|
+
val value = params[it.key]
|
|
94
|
+
if (field.required && value == null) {
|
|
95
|
+
throw IllegalInputParamException("${it.key} param is missing from input")
|
|
96
|
+
}
|
|
97
|
+
when (method.returnType) {
|
|
98
|
+
String::class.java -> {
|
|
99
|
+
if (value != null && value !is String) {
|
|
100
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except string,but ${value.javaClass}")
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
Number::class.java -> {
|
|
104
|
+
if (value != null && value !is Number) {
|
|
105
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except number,but ${value.javaClass}")
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
java.lang.Boolean::class.java, Boolean::class.java -> {
|
|
109
|
+
if (value != null && value !is Boolean) {
|
|
110
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except boolean,but ${value.javaClass}")
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
List::class.java -> {
|
|
114
|
+
if (value != null && value !is List<*>) {
|
|
115
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except List ,but ${value.javaClass}")
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
Map::class.java -> {
|
|
119
|
+
if (value != null && value !is Map<*, *>) {
|
|
120
|
+
throw IllegalInputParamException("${it.key} param has wrong declared type. except Map ,but ${value.javaClass}")
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (value != null && field.isEnum) {
|
|
125
|
+
when (method.returnType) {
|
|
126
|
+
String::class.java -> {
|
|
127
|
+
val stringEnum = method.getAnnotation(IDLMethodStringEnum::class.java)
|
|
128
|
+
val option = stringEnum.option
|
|
129
|
+
if (!option.contains(value)) {
|
|
130
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of ${option.asList()} but got $value")
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
Number::class.java -> {
|
|
134
|
+
val intEnum = method.getAnnotation(IDLMethodIntEnum::class.java)
|
|
135
|
+
val option = intEnum.option
|
|
136
|
+
if (!option.contains(getInt(value))) {
|
|
137
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of ${option.asList()} but got $value")
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
Map::class.java -> {
|
|
141
|
+
val stringEnum = method.getAnnotation(IDLMethodStringEnum::class.java)
|
|
142
|
+
if (stringEnum != null) {
|
|
143
|
+
val option = stringEnum.option
|
|
144
|
+
if ((value as Map<String, Any>).any { item -> !option.contains(item.value) }) {
|
|
145
|
+
throw IllegalInputParamException("${it.key} has wrong type.should be one of ${option.asList()} but got $value")
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
val intEnum = method.getAnnotation(IDLMethodIntEnum::class.java)
|
|
149
|
+
if (intEnum != null) {
|
|
150
|
+
val option = intEnum.option
|
|
151
|
+
if ((value as Map<String, Any>).any { item -> !option.contains(getInt(item.value)) }) {
|
|
152
|
+
throw IllegalInputParamException("${it.key} has wrong value.should be one of ${option.asList()} but got $value")
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* front end give 1 but lynx receive 1.0!
|
|
164
|
+
* let 1.0==1
|
|
165
|
+
*/
|
|
166
|
+
private fun getInt(data: Any?): Int {
|
|
167
|
+
if (data is Number) {
|
|
168
|
+
return data.toInt()
|
|
169
|
+
}
|
|
170
|
+
if (data == null) {
|
|
171
|
+
throw IllegalInputParamException("the key is null")
|
|
172
|
+
}
|
|
173
|
+
throw IllegalInputParamException("the key is not a number")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
private fun isNestClass(value: Any?, annotation: IDLMethodParamField?) = value is Map<*, *> && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
178
|
+
private fun isNestListClass(value: Any?, annotation: IDLMethodParamField?) = value is List<*> && annotation?.nestedClassType != IDLMethodBaseModel.Default::class
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
private fun preCheck(clazz: Class<out IDLMethodBaseModel>?, map: HashMap<String, Any>): HashMap<String, Pair<Method, IDLMethodParamField>>? {
|
|
182
|
+
val classMap = clazz?.declaredMethods?.fold(hashMapOf<String, Pair<Method, IDLMethodParamField>>()) { _map, method ->
|
|
183
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
184
|
+
if (annotation != null) {
|
|
185
|
+
_map[annotation.keyPath] = Pair<Method, IDLMethodParamField>(method, annotation)
|
|
186
|
+
}
|
|
187
|
+
_map
|
|
188
|
+
} ?: return null
|
|
189
|
+
/**
|
|
190
|
+
* init default value
|
|
191
|
+
*/
|
|
192
|
+
classMap.filter { map[it.key] == null && it.value.second.defaultValue.type != DefaultType.NONE }.forEach {
|
|
193
|
+
val annotation = it.value.second
|
|
194
|
+
map[it.key] = parseStringByReturnType(it.value.first, annotation)
|
|
195
|
+
}
|
|
196
|
+
checkValue(classMap, map)
|
|
197
|
+
return classMap
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private fun parseStringByReturnType(method: Method, annotation: IDLMethodParamField) = when (method.returnType) {
|
|
201
|
+
Number::class.java -> when (annotation.defaultValue.type) {
|
|
202
|
+
DefaultType.DOUBLE -> annotation.defaultValue.doubleValue
|
|
203
|
+
DefaultType.LONG -> annotation.defaultValue.longValue
|
|
204
|
+
DefaultType.INT -> annotation.defaultValue.intValue
|
|
205
|
+
else -> annotation.defaultValue.intValue
|
|
206
|
+
}
|
|
207
|
+
Boolean::class.java, java.lang.Boolean::class.java -> annotation.defaultValue.boolValue
|
|
208
|
+
else -> annotation.defaultValue.stringValue
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private fun getMapWithDefault(clazz: Class<out IDLMethodBaseModel>?, map: HashMap<String, Any>): HashMap<String, Any?>? {
|
|
212
|
+
val methods = clazz?.declaredMethods?.filter { it.getAnnotation(IDLMethodParamField::class.java)?.isGetter == true }
|
|
213
|
+
return methods?.fold(hashMapOf()) { acc, method ->
|
|
214
|
+
val annotation = method.getAnnotation(IDLMethodParamField::class.java)
|
|
215
|
+
val value = map[annotation.keyPath]
|
|
216
|
+
/**
|
|
217
|
+
* init default value
|
|
218
|
+
*/
|
|
219
|
+
if (value == null && annotation.defaultValue.type != DefaultType.NONE) {
|
|
220
|
+
val defaultValue = parseStringByReturnType(method, annotation)
|
|
221
|
+
map[annotation.keyPath] = defaultValue
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
acc[annotation.keyPath] = if (annotation.nestedClassType != IDLMethodBaseModel.Default::class && value is ReadableMap) {
|
|
225
|
+
val nestedClassType = annotation.nestedClassType
|
|
226
|
+
getMapWithDefault(nestedClassType.java, value.toHashMap())
|
|
227
|
+
} else if (annotation.nestedClassType != IDLMethodBaseModel.Default::class && value is ReadableArray) {
|
|
228
|
+
value.toArrayList().map { getMapWithDefault(annotation.nestedClassType.java, (it as ReadableMap).toHashMap()) }
|
|
229
|
+
} else {
|
|
230
|
+
map[annotation.keyPath]
|
|
231
|
+
}
|
|
232
|
+
acc
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
override fun transformMapToPlatformData(params: Map<String, Any?>, clazz: Class<out IDLBridgeMethod>): ReadableMap {
|
|
237
|
+
return Utils.convertMapToReadableMap(params)
|
|
238
|
+
}
|
|
239
|
+
}
|