From 8d862bba5b3b1cb332627b8abaad6182cb4786bd Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 15 Apr 2024 09:49:30 -0700 Subject: [PATCH] chore(deps): Amplify Android 2.15.0 (#4279) * chore(deps): Amplify Android 2.15.0 * chore: update Kotlin version --------- Co-authored-by: Nika Hassani Co-authored-by: Jordan Nelson --- .github/workflows/e2e_android.yaml | 2 +- .github/workflows/flutter_android.yaml | 6 + canaries/android/app/build.gradle | 6 +- .../example/android/app/build.gradle | 6 +- .../amplify_datastore/android/build.gradle | 28 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- .../AmplifyDataStorePlugin.kt | 152 ++- .../DataStoreHubEventStreamHandler.kt | 2 +- .../amplify_datastore/FlutterAuthProvider.kt | 1 - .../NativeAuthPluginWrapper.kt | 15 +- .../exception/ExceptionUtil.kt | 57 +- .../pigeons/NativePluginBindings.kt | 559 +++++------ .../hub/FlutterOutboxMutationEnqueuedEvent.kt | 1 - .../FlutterSubscriptionDataProcessedEvent.kt | 2 +- .../types/model/FlutterAuthRule.kt | 1 - .../types/model/FlutterModelField.kt | 7 +- .../types/model/FlutterModelSchema.kt | 8 +- .../model/FlutterSerializedCustomType.kt | 8 +- .../types/model/FlutterSerializedModel.kt | 16 +- .../types/query/QueryPaginationBuilder.kt | 10 +- .../types/query/QueryPredicateBuilder.kt | 20 +- .../amplify_datastore/util/SafeCastingUtil.kt | 12 +- .../AmplifyDataStoreHubTest.kt | 124 ++- .../AmplifyDataStorePluginTest.kt | 169 ++-- .../AmplifyModelSchemaTest.kt | 12 +- .../AmplifySerializedModelTest.kt | 12 +- .../amplify_datastore/CoroutineTestRule.kt | 2 +- .../amplify/amplify_datastore/SchemaData.kt | 932 +++++++++--------- .../types/query/QueryPaginationBuilderTest.kt | 9 +- .../types/query/QueryPredicateBuilderTest.kt | 33 +- .../example/android/app/build.gradle | 9 +- .../example/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../android/build.gradle | 8 +- .../example/android/app/build.gradle | 6 +- .../android/build.gradle | 8 +- .../example/android/app/build.gradle | 6 +- .../example/android/app/build.gradle | 6 +- .../amplify_auth_cognito/android/build.gradle | 6 +- .../example/android/app/build.gradle | 6 +- .../example/android/app/build.gradle | 9 +- .../example/android/app/build.gradle | 6 +- .../amplify_db_common/android/build.gradle | 8 +- .../example/android/app/build.gradle | 6 +- .../android/build.gradle | 12 +- .../example/android/app/build.gradle | 8 +- .../example/android/build.gradle | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- .../example/android/app/build.gradle | 6 +- .../android/build.gradle | 8 +- .../EncryptedKeyValueRepositoryTest.kt | 2 +- .../example/android/app/build.gradle | 8 +- .../example/android/app/build.gradle | 6 +- .../e2e_flutter_test/android/app/build.gradle | 6 +- .../example/android/app/build.gradle | 6 +- 55 files changed, 1257 insertions(+), 1119 deletions(-) diff --git a/.github/workflows/e2e_android.yaml b/.github/workflows/e2e_android.yaml index e65b5eb948..2953c16075 100644 --- a/.github/workflows/e2e_android.yaml +++ b/.github/workflows/e2e_android.yaml @@ -45,7 +45,7 @@ jobs: - uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # 3.12.0 with: distribution: "corretto" # Amazon Corretto Build of OpenJDK - java-version: "11" + java-version: "17" - name: Install dependencies uses: ./.github/composite_actions/install_dependencies diff --git a/.github/workflows/flutter_android.yaml b/.github/workflows/flutter_android.yaml index 288c9dfd26..bfe7961666 100644 --- a/.github/workflows/flutter_android.yaml +++ b/.github/workflows/flutter_android.yaml @@ -31,6 +31,12 @@ jobs: exclude: - channel: ${{ (github.event_name == 'pull_request') && 'beta' || 'NONE' }} steps: + - name: Setup Java + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # 3.12.0 + with: + distribution: "corretto" # Amazon Corretto Build of OpenJDK + java-version: "17" + - name: Git Checkout uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # 3.6.0 diff --git a/canaries/android/app/build.gradle b/canaries/android/app/build.gradle index 5cb91ce2b3..9fb60499d6 100644 --- a/canaries/android/app/build.gradle +++ b/canaries/android/app/build.gradle @@ -30,12 +30,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/amplify/amplify_flutter/example/android/app/build.gradle b/packages/amplify/amplify_flutter/example/android/app/build.gradle index c72843b8fa..07ee2cc3f8 100644 --- a/packages/amplify/amplify_flutter/example/android/app/build.gradle +++ b/packages/amplify/amplify_flutter/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/amplify_datastore/android/build.gradle b/packages/amplify_datastore/android/build.gradle index 9860f85e3a..5c13041766 100644 --- a/packages/amplify_datastore/android/build.gradle +++ b/packages/amplify_datastore/android/build.gradle @@ -2,7 +2,7 @@ group 'com.amazonaws.amplify.amplify_datastore' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.9.10' repositories { mavenLocal() google() @@ -32,7 +32,7 @@ apply plugin: 'kotlin-android' apply plugin: 'org.jlleitschuh.gradle.ktlint' android { - compileSdkVersion 33 + compileSdk 33 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -54,11 +54,14 @@ android { htmlReport false } compileOptions { - // Support for Java 8 features - coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } + + kotlinOptions { + jvmTarget = '17' + } + testOptions { unitTests { includeAndroidResources = true @@ -69,13 +72,10 @@ android { } dependencies { - // Support for Java 8 features - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' - - implementation 'com.amplifyframework:aws-auth-cognito:2.13.0' - implementation "com.amplifyframework:aws-api:2.13.0" - implementation "com.amplifyframework:aws-datastore:2.13.0" - implementation "com.amplifyframework:aws-api-appsync:2.13.0" + implementation 'com.amplifyframework:aws-auth-cognito:2.15.0' + implementation "com.amplifyframework:aws-api:2.15.0" + implementation "com.amplifyframework:aws-datastore:2.15.0" + implementation "com.amplifyframework:aws-api-appsync:2.15.0" implementation 'com.google.code.gson:gson:2.10.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1' @@ -88,7 +88,7 @@ dependencies { // Tests must be updated if bumped //noinspection GradleDependency - testImplementation 'org.robolectric:robolectric:4.3.1' + testImplementation 'org.robolectric:robolectric:4.12.1' testImplementation 'com.fasterxml.jackson.core:jackson-core:2.12.4' testImplementation 'com.fasterxml.jackson.core:jackson-annotations:2.12.4' testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.12.4' diff --git a/packages/amplify_datastore/android/gradle/wrapper/gradle-wrapper.properties b/packages/amplify_datastore/android/gradle/wrapper/gradle-wrapper.properties index ceccc3a854..ac72c34e8a 100644 --- a/packages/amplify_datastore/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/amplify_datastore/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt index 718d82a005..a122e7909f 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt @@ -6,7 +6,6 @@ package com.amazonaws.amplify.amplify_datastore import android.content.Context import android.os.Handler import android.os.Looper -import androidx.annotation.NonNull import androidx.annotation.VisibleForTesting import com.amazonaws.amplify.amplify_datastore.exception.ExceptionMessages import com.amazonaws.amplify.amplify_datastore.exception.ExceptionUtil.Companion.createSerializedError @@ -51,6 +50,7 @@ import com.amplifyframework.datastore.DataStoreConfiguration import com.amplifyframework.datastore.DataStoreConflictHandler import com.amplifyframework.datastore.DataStoreErrorHandler import com.amplifyframework.datastore.DataStoreException +import com.amplifyframework.datastore.DataStorePlugin import com.amplifyframework.util.UserAgent import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.plugin.common.EventChannel @@ -74,8 +74,12 @@ import kotlin.collections.HashMap typealias ResolutionStrategy = DataStoreConflictHandler.ResolutionStrategy /** AmplifyDataStorePlugin */ -class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBridge, - NativeAuthBridge, NativeApiBridge { +class AmplifyDataStorePlugin : + FlutterPlugin, + MethodCallHandler, + NativeAmplifyBridge, + NativeAuthBridge, + NativeApiBridge { private lateinit var channel: MethodChannel private lateinit var eventChannel: EventChannel private lateinit var observeCancelable: Cancelable @@ -83,7 +87,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr private val dataStoreObserveEventStreamHandler: DataStoreObserveEventStreamHandler private val dataStoreHubEventStreamHandler: DataStoreHubEventStreamHandler - private val uiThreadHandler = Handler(Looper.getMainLooper()) + private val uiThreadHandler: Handler private val LOG = Amplify.Logging.forNamespace("amplify:flutter:datastore") private var isSettingUpObserve = AtomicBoolean() private var nativeAuthPlugin: NativeAuthPlugin? = null @@ -110,10 +114,15 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } val modelProvider = FlutterModelProvider.instance + val _injectedPlugin: AWSDataStorePlugin? + val dataStorePlugin: AWSDataStorePlugin + get() = _injectedPlugin ?: Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin constructor() { dataStoreObserveEventStreamHandler = DataStoreObserveEventStreamHandler() dataStoreHubEventStreamHandler = DataStoreHubEventStreamHandler() + _injectedPlugin = null + uiThreadHandler = Handler(Looper.getMainLooper()) } @VisibleForTesting @@ -123,10 +132,23 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr ) { dataStoreObserveEventStreamHandler = eventHandler dataStoreHubEventStreamHandler = hubEventHandler + _injectedPlugin = null + uiThreadHandler = Handler(Looper.getMainLooper()) + } + internal constructor( + dataStorePlugin: AWSDataStorePlugin, + uiThreadHandler: Handler, + eventHandler: DataStoreObserveEventStreamHandler, + hubEventHandler: DataStoreHubEventStreamHandler + ) { + dataStoreObserveEventStreamHandler = eventHandler + dataStoreHubEventStreamHandler = hubEventHandler + this._injectedPlugin = dataStorePlugin + this.uiThreadHandler = uiThreadHandler } override fun onAttachedToEngine( - @NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding + flutterPluginBinding: FlutterPlugin.FlutterPluginBinding ) { context = flutterPluginBinding.applicationContext channel = MethodChannel( @@ -157,7 +179,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.info("Initiated DataStore plugin") } - override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) nativeAuthPlugin = null @@ -169,7 +191,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr NativeAmplifyBridge.setUp(binding.binaryMessenger, null) } - override fun onMethodCall(@NonNull call: MethodCall, @NonNull _result: Result) { + override fun onMethodCall(call: MethodCall, _result: Result) { val result = AtomicResult(_result, call.method) var data: Map = HashMap() try { @@ -179,8 +201,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - result, "DataStoreException", - createSerializedUnrecognizedError(e) + result, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } return @@ -206,13 +230,15 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr ) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", + flutterResult, + "DataStoreException", createSerializedError( ExceptionMessages.missingExceptionMessage, ExceptionMessages.missingRecoverySuggestion, "Received invalid request from Dart, modelSchemas and/or modelProviderVersion" + - " are not available. Request: " + request.toString() - ) + " are not available. Request: " + request.toString() + ), + uiThreadHandler ) } return @@ -243,8 +269,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedUnrecognizedError(e) + flutterResult, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } } @@ -268,7 +296,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr try { Amplify.addPlugin(dataStorePlugin) } catch (e: Exception) { - handleAddPluginException("Datastore", e, flutterResult) + handleAddPluginException("Datastore", e, flutterResult, uiThreadHandler) return } flutterResult.success(null) @@ -285,14 +313,16 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedUnrecognizedError(e) + flutterResult, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } return } - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin plugin.query( modelName, queryOptions, @@ -308,8 +338,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedUnrecognizedError(e) + flutterResult, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } } @@ -318,8 +350,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.error("Query operation failed.", it) uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } @@ -345,14 +379,16 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedUnrecognizedError(e) + flutterResult, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } return } - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin val instance = SerializedModel.builder() .modelSchema(schema) @@ -373,8 +409,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } else { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } @@ -401,14 +439,16 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } catch (e: Exception) { uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedUnrecognizedError(e) + flutterResult, + "DataStoreException", + createSerializedUnrecognizedError(e), + uiThreadHandler ) } return } - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin val serializedModel = SerializedModel.builder() .modelSchema(schema) @@ -426,8 +466,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.error("Save operation failed", it) uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } @@ -435,7 +477,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } fun onClear(flutterResult: Result) { - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin plugin.clear( { @@ -446,8 +488,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.error("Failed to clear store with error: ", it) uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } @@ -460,7 +504,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr return } - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin plugin.observe( { cancelable -> LOG.info("Established a new stream form flutter $cancelable") @@ -497,7 +541,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr @VisibleForTesting fun onStart(flutterResult: Result) { - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin plugin.start( { @@ -510,8 +554,10 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.error("Failed to start datastore with error: ", it) uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } @@ -520,7 +566,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr @VisibleForTesting fun onStop(flutterResult: Result) { - val plugin = Amplify.DataStore.getPlugin("awsDataStorePlugin") as AWSDataStorePlugin + val plugin = dataStorePlugin plugin.stop( { @@ -533,15 +579,17 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr LOG.error("Failed to stop datastore with error: ", it) uiThreadHandler.post { postExceptionToFlutterChannel( - flutterResult, "DataStoreException", - createSerializedError(it) + flutterResult, + "DataStoreException", + createSerializedError(it), + uiThreadHandler ) } } ) } - private fun checkArguments(@NonNull args: Any): Map { + private fun checkArguments(args: Any): Map { if (args !is Map<*, *>) { throw java.lang.Exception("Flutter method call arguments are not a map.") } @@ -549,8 +597,8 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } private fun buildSyncExpressions( - @NonNull syncExpressions: List>, - @NonNull dataStoreConfigurationBuilder: DataStoreConfiguration.Builder + syncExpressions: List>, + dataStoreConfigurationBuilder: DataStoreConfiguration.Builder ) { syncExpressions.forEach { try { @@ -563,7 +611,8 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr val latch = CountDownLatch(1) uiThreadHandler.post { channel.invokeMethod( - "resolveQueryPredicate", id, + "resolveQueryPredicate", + id, object : Result { override fun success(result: Any?) { try { @@ -591,8 +640,8 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr latch.await() } catch (e: InterruptedException) { LOG.error( - "Failed to resolve query predicate due to ${e}. Reverting to original query " + - "predicate." + "Failed to resolve query predicate due to $e. Reverting to original query " + + "predicate." ) } resolvedQueryPredicate @@ -769,7 +818,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr private fun createConflictHandler(request: Map): DataStoreConflictHandler { return if (request["hasConflictHandler"] as? Boolean? == true) { DataStoreConflictHandler { conflictData, - onDecision -> + onDecision -> val modelName = conflictData.local.modelName val args = mapOf( @@ -780,7 +829,8 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr uiThreadHandler.post { channel.invokeMethod( - "conflictHandler", args, + "conflictHandler", + args, object : Result { override fun success(result: Any?) { val resultMap: Map? = result.safeCastToMap() @@ -827,7 +877,7 @@ class AmplifyDataStorePlugin : FlutterPlugin, MethodCallHandler, NativeAmplifyBr } } else { DataStoreConflictHandler { _, - onDecision -> + onDecision -> onDecision.accept(DataStoreConflictHandler.ConflictResolutionDecision.applyRemote()) } } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/DataStoreHubEventStreamHandler.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/DataStoreHubEventStreamHandler.kt index c04ef90a90..428b33acc1 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/DataStoreHubEventStreamHandler.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/DataStoreHubEventStreamHandler.kt @@ -195,7 +195,7 @@ class DataStoreHubEventStreamHandler : EventChannel.StreamHandler { val message = FlutterSubscriptionDataProcessedEvent( hubEvent.name, model, - eventData.syncMetadata, + eventData.syncMetadata ) sendEvent(message.toValueMap()) } else { diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/FlutterAuthProvider.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/FlutterAuthProvider.kt index 5d8dedeb78..70f28ec008 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/FlutterAuthProvider.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/FlutterAuthProvider.kt @@ -104,7 +104,6 @@ class FlutterAuthProviders( } } launch(Dispatchers.Main) { - nativeApiPlugin.getLatestAuthToken(authType.name) { resultToken -> result.success(resultToken) } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/NativeAuthPluginWrapper.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/NativeAuthPluginWrapper.kt index 1d0d83cb05..ad993a79f8 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/NativeAuthPluginWrapper.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/NativeAuthPluginWrapper.kt @@ -84,7 +84,7 @@ class NativeAuthPluginWrapper( val tokens = FlutterFactory.createAWSCognitoUserPoolTokens( session.userPoolTokens!!.accessToken, session.userPoolTokens!!.idToken, - session.userPoolTokens!!.refreshToken, + session.userPoolTokens!!.refreshToken ) AuthSessionResult.success(tokens) } else { @@ -97,9 +97,13 @@ class NativeAuthPluginWrapper( sessionCredentials.accessKeyId, sessionCredentials.secretAccessKey, sessionCredentials.sessionToken, - if (sessionCredentials.expirationIso8601Utc != null) Instant.fromIso8601( - sessionCredentials.expirationIso8601Utc!! - ).epochSeconds else null, + if (sessionCredentials.expirationIso8601Utc != null) { + Instant.fromIso8601( + sessionCredentials.expirationIso8601Utc!! + ).epochSeconds + } else { + null + } ) AuthSessionResult.success(credentials) } else { @@ -110,7 +114,7 @@ class NativeAuthPluginWrapper( AuthSessionResult.success(session.identityId), awsCredentials, AuthSessionResult.success(session.userSub), - userPoolTokens, + userPoolTokens ) onSuccess.accept(authSession) } @@ -403,5 +407,4 @@ class NativeAuthPluginWrapper( private fun unsupported(methodName: String): Nothing { throw IllegalStateException("$methodName is not supported") } - } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/exception/ExceptionUtil.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/exception/ExceptionUtil.kt index 317f766846..eb8c144e88 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/exception/ExceptionUtil.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/exception/ExceptionUtil.kt @@ -7,11 +7,16 @@ import android.os.Handler import android.os.Looper import com.amplifyframework.AmplifyException import com.amplifyframework.core.Amplify +import com.amplifyframework.datastore.DataStoreException.GraphQLResponseException +import com.google.gson.Gson import com.google.gson.GsonBuilder +import com.google.gson.JsonArray import com.google.gson.JsonElement +import com.google.gson.JsonObject import com.google.gson.JsonPrimitive import com.google.gson.JsonSerializationContext import com.google.gson.JsonSerializer +import com.google.gson.reflect.TypeToken import io.flutter.plugin.common.MethodChannel.Result import java.lang.reflect.Type @@ -21,9 +26,10 @@ class ExceptionUtil { fun postExceptionToFlutterChannel( result: Result, errorCode: String, - details: Map + details: Map, + threadHandler: Handler ) { - Handler(Looper.getMainLooper()).post { + threadHandler.post { result.error( errorCode, ExceptionMessages.defaultFallbackExceptionMessage, @@ -35,9 +41,11 @@ class ExceptionUtil { @JvmStatic fun createSerializedError(e: AmplifyException): Map { val gsonBuilder = GsonBuilder() - gsonBuilder.registerTypeAdapter(Throwable::class.java, ThrowableSerializer()) + gsonBuilder.registerTypeHierarchyAdapter(AmplifyException::class.java, AmplifyExceptionSerializer()) + gsonBuilder.registerTypeHierarchyAdapter(GraphQLResponseException::class.java, GraphQLExceptionSerializer()) val gson = gsonBuilder.create() val serializedJsonException = gson.toJson(e) + @Suppress("UNCHECKED_CAST") var serializedMap: Map = gson.fromJson(serializedJsonException, Map::class.java) as Map @@ -77,7 +85,7 @@ class ExceptionUtil { } @JvmStatic - fun handleAddPluginException(pluginName: String, e: Exception, flutterResult: Result) { + fun handleAddPluginException(pluginName: String, e: Exception, flutterResult: Result, threadHandler: Handler) { var errorCode = pluginName + "Exception" if (e is Amplify.AlreadyConfiguredException) { errorCode = "AmplifyAlreadyConfiguredException" @@ -86,17 +94,42 @@ class ExceptionUtil { is AmplifyException -> createSerializedError(e) else -> createSerializedUnrecognizedError(e) } - postExceptionToFlutterChannel(flutterResult, errorCode, errorDetails) + postExceptionToFlutterChannel(flutterResult, errorCode, errorDetails, threadHandler) } } } -class ThrowableSerializer : JsonSerializer { - override fun serialize( - src: Throwable?, - typeOfSrc: Type?, - context: JsonSerializationContext? - ): JsonElement { - return JsonPrimitive(src.toString()) +class AmplifyExceptionSerializer : JsonSerializer { + override fun serialize(src: AmplifyException?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { + val jsonObject = JsonObject() + src?.let { + jsonObject.addProperty("message", src.message) + jsonObject.addProperty("recoverySuggestion", src.recoverySuggestion) + src.cause?.let { cause -> + jsonObject.addProperty("cause", src.cause.toString()) + } + } + return jsonObject } } + +class GraphQLExceptionSerializer : JsonSerializer { + override fun serialize(src: GraphQLResponseException?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { + val jsonObject = JsonObject() + src?.let { + jsonObject.addProperty("message", src.message) + jsonObject.addProperty("recoverySuggestion", src.recoverySuggestion) + src.cause?.let { cause -> + jsonObject.addProperty("cause", src.cause.toString()) + } + val array = JsonArray() + src.errors.forEach{e -> + val temp = JsonObject() + temp.addProperty("message", e.message) + array.add(temp) + } + jsonObject.add("errors", array) + } + return jsonObject + } +} \ No newline at end of file diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt index ccf949889f..1d556a948f 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt @@ -1,4 +1,4 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // Autogenerated from Pigeon (v11.0.0), do not edit directly. @@ -15,23 +15,23 @@ import java.io.ByteArrayOutputStream import java.nio.ByteBuffer private fun wrapResult(result: Any?): List { - return listOf(result) + return listOf(result) } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( - exception.code, - exception.message, - exception.details - ) - } else { - return listOf( - exception.javaClass.simpleName, - exception.toString(), - "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) - ) - } + if (exception is FlutterError) { + return listOf( + exception.code, + exception.message, + exception.details + ) + } else { + return listOf( + exception.javaClass.simpleName, + exception.toString(), + "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) + ) + } } /** @@ -40,338 +40,345 @@ private fun wrapError(exception: Throwable): List { * @property message The error message. * @property details The error details. Must be a datatype supported by the api codec. */ -class FlutterError ( - val code: String, - override val message: String? = null, - val details: Any? = null +class FlutterError( + val code: String, + override val message: String? = null, + val details: Any? = null ) : Throwable() /** Generated class from Pigeon that represents data sent in messages. */ -data class NativeAuthSession ( - val isSignedIn: Boolean, - val userSub: String? = null, - val userPoolTokens: NativeUserPoolTokens? = null, - val identityId: String? = null, - val awsCredentials: NativeAWSCredentials? = null +data class NativeAuthSession( + val isSignedIn: Boolean, + val userSub: String? = null, + val userPoolTokens: NativeUserPoolTokens? = null, + val identityId: String? = null, + val awsCredentials: NativeAWSCredentials? = null ) { - companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAuthSession { - val isSignedIn = list[0] as Boolean - val userSub = list[1] as String? - val userPoolTokens: NativeUserPoolTokens? = (list[2] as List?)?.let { - NativeUserPoolTokens.fromList(it) - } - val identityId = list[3] as String? - val awsCredentials: NativeAWSCredentials? = (list[4] as List?)?.let { - NativeAWSCredentials.fromList(it) - } - return NativeAuthSession(isSignedIn, userSub, userPoolTokens, identityId, awsCredentials) + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): NativeAuthSession { + val isSignedIn = list[0] as Boolean + val userSub = list[1] as String? + val userPoolTokens: NativeUserPoolTokens? = (list[2] as List?)?.let { + NativeUserPoolTokens.fromList(it) + } + val identityId = list[3] as String? + val awsCredentials: NativeAWSCredentials? = (list[4] as List?)?.let { + NativeAWSCredentials.fromList(it) + } + return NativeAuthSession(isSignedIn, userSub, userPoolTokens, identityId, awsCredentials) + } + } + fun toList(): List { + return listOf( + isSignedIn, + userSub, + userPoolTokens?.toList(), + identityId, + awsCredentials?.toList() + ) } - } - fun toList(): List { - return listOf( - isSignedIn, - userSub, - userPoolTokens?.toList(), - identityId, - awsCredentials?.toList(), - ) - } } /** Generated class from Pigeon that represents data sent in messages. */ -data class NativeAuthUser ( - val userId: String, - val username: String +data class NativeAuthUser( + val userId: String, + val username: String ) { - companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAuthUser { - val userId = list[0] as String - val username = list[1] as String - return NativeAuthUser(userId, username) + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): NativeAuthUser { + val userId = list[0] as String + val username = list[1] as String + return NativeAuthUser(userId, username) + } + } + fun toList(): List { + return listOf( + userId, + username + ) } - } - fun toList(): List { - return listOf( - userId, - username, - ) - } } /** Generated class from Pigeon that represents data sent in messages. */ -data class NativeUserPoolTokens ( - val accessToken: String, - val refreshToken: String, - val idToken: String +data class NativeUserPoolTokens( + val accessToken: String, + val refreshToken: String, + val idToken: String ) { - companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeUserPoolTokens { - val accessToken = list[0] as String - val refreshToken = list[1] as String - val idToken = list[2] as String - return NativeUserPoolTokens(accessToken, refreshToken, idToken) + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): NativeUserPoolTokens { + val accessToken = list[0] as String + val refreshToken = list[1] as String + val idToken = list[2] as String + return NativeUserPoolTokens(accessToken, refreshToken, idToken) + } + } + fun toList(): List { + return listOf( + accessToken, + refreshToken, + idToken + ) } - } - fun toList(): List { - return listOf( - accessToken, - refreshToken, - idToken, - ) - } } /** Generated class from Pigeon that represents data sent in messages. */ -data class NativeAWSCredentials ( - val accessKeyId: String, - val secretAccessKey: String, - val sessionToken: String? = null, - val expirationIso8601Utc: String? = null +data class NativeAWSCredentials( + val accessKeyId: String, + val secretAccessKey: String, + val sessionToken: String? = null, + val expirationIso8601Utc: String? = null ) { - companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAWSCredentials { - val accessKeyId = list[0] as String - val secretAccessKey = list[1] as String - val sessionToken = list[2] as String? - val expirationIso8601Utc = list[3] as String? - return NativeAWSCredentials(accessKeyId, secretAccessKey, sessionToken, expirationIso8601Utc) + companion object { + @Suppress("UNCHECKED_CAST") + fun fromList(list: List): NativeAWSCredentials { + val accessKeyId = list[0] as String + val secretAccessKey = list[1] as String + val sessionToken = list[2] as String? + val expirationIso8601Utc = list[3] as String? + return NativeAWSCredentials(accessKeyId, secretAccessKey, sessionToken, expirationIso8601Utc) + } + } + fun toList(): List { + return listOf( + accessKeyId, + secretAccessKey, + sessionToken, + expirationIso8601Utc + ) } - } - fun toList(): List { - return listOf( - accessKeyId, - secretAccessKey, - sessionToken, - expirationIso8601Utc, - ) - } } @Suppress("UNCHECKED_CAST") private object NativeAuthPluginCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeAWSCredentials.fromList(it) - } - } - 129.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeAuthSession.fromList(it) - } - } - 130.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeUserPoolTokens.fromList(it) + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 128.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeAWSCredentials.fromList(it) + } + } + 129.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeAuthSession.fromList(it) + } + } + 130.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeUserPoolTokens.fromList(it) + } + } + else -> super.readValueOfType(type, buffer) } - } - else -> super.readValueOfType(type, buffer) } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is NativeAWSCredentials -> { - stream.write(128) - writeValue(stream, value.toList()) - } - is NativeAuthSession -> { - stream.write(129) - writeValue(stream, value.toList()) - } - is NativeUserPoolTokens -> { - stream.write(130) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is NativeAWSCredentials -> { + stream.write(128) + writeValue(stream, value.toList()) + } + is NativeAuthSession -> { + stream.write(129) + writeValue(stream, value.toList()) + } + is NativeUserPoolTokens -> { + stream.write(130) + writeValue(stream, value.toList()) + } + else -> super.writeValue(stream, value) + } } - } } /** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ @Suppress("UNCHECKED_CAST") class NativeAuthPlugin(private val binaryMessenger: BinaryMessenger) { - companion object { - /** The codec used by NativeAuthPlugin. */ - val codec: MessageCodec by lazy { - NativeAuthPluginCodec + companion object { + /** The codec used by NativeAuthPlugin. */ + val codec: MessageCodec by lazy { + NativeAuthPluginCodec + } } - } - fun fetchAuthSession(callback: (NativeAuthSession) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession", codec) - channel.send(null) { - val result = it as NativeAuthSession - callback(result) + fun fetchAuthSession(callback: (NativeAuthSession) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession", codec) + channel.send(null) { + val result = it as NativeAuthSession + callback(result) + } } - } } + /** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ @Suppress("UNCHECKED_CAST") class NativeApiPlugin(private val binaryMessenger: BinaryMessenger) { - companion object { - /** The codec used by NativeApiPlugin. */ - val codec: MessageCodec by lazy { - StandardMessageCodec() + companion object { + /** The codec used by NativeApiPlugin. */ + val codec: MessageCodec by lazy { + StandardMessageCodec() + } } - } - fun getLatestAuthToken(providerNameArg: String, callback: (String?) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken", codec) - channel.send(listOf(providerNameArg)) { - val result = it as String? - callback(result) + fun getLatestAuthToken(providerNameArg: String, callback: (String?) -> Unit) { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken", codec) + channel.send(listOf(providerNameArg)) { + val result = it as String? + callback(result) + } } - } } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface NativeAmplifyBridge { - fun configure(version: String, config: String, callback: (Result) -> Unit) + fun configure(version: String, config: String, callback: (Result) -> Unit) - companion object { - /** The codec used by NativeAmplifyBridge. */ - val codec: MessageCodec by lazy { - StandardMessageCodec() - } - /** Sets up an instance of `NativeAmplifyBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeAmplifyBridge?) { - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure", codec) - if (api != null) { - channel.setMessageHandler { message, reply -> - val args = message as List - val versionArg = args[0] as String - val configArg = args[1] as String - api.configure(versionArg, configArg) { result: Result -> - val error = result.exceptionOrNull() - if (error != null) { - reply.reply(wrapError(error)) - } else { - reply.reply(wrapResult(null)) - } + companion object { + /** The codec used by NativeAmplifyBridge. */ + val codec: MessageCodec by lazy { + StandardMessageCodec() + } + + /** Sets up an instance of `NativeAmplifyBridge` to handle messages through the `binaryMessenger`. */ + @Suppress("UNCHECKED_CAST") + fun setUp(binaryMessenger: BinaryMessenger, api: NativeAmplifyBridge?) { + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val versionArg = args[0] as String + val configArg = args[1] as String + api.configure(versionArg, configArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(wrapError(error)) + } else { + reply.reply(wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } } - } - } else { - channel.setMessageHandler(null) } - } } - } } + @Suppress("UNCHECKED_CAST") private object NativeAuthBridgeCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeAuthUser.fromList(it) + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 128.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeAuthUser.fromList(it) + } + } + else -> super.readValueOfType(type, buffer) } - } - else -> super.readValueOfType(type, buffer) } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is NativeAuthUser -> { - stream.write(128) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is NativeAuthUser -> { + stream.write(128) + writeValue(stream, value.toList()) + } + else -> super.writeValue(stream, value) + } } - } } /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface NativeAuthBridge { - fun addAuthPlugin(callback: (Result) -> Unit) - fun updateCurrentUser(user: NativeAuthUser?) + fun addAuthPlugin(callback: (Result) -> Unit) + fun updateCurrentUser(user: NativeAuthUser?) - companion object { - /** The codec used by NativeAuthBridge. */ - val codec: MessageCodec by lazy { - NativeAuthBridgeCodec - } - /** Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?) { - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin", codec) - if (api != null) { - channel.setMessageHandler { _, reply -> - api.addAuthPlugin() { result: Result -> - val error = result.exceptionOrNull() - if (error != null) { - reply.reply(wrapError(error)) - } else { - reply.reply(wrapResult(null)) - } - } - } - } else { - channel.setMessageHandler(null) + companion object { + /** The codec used by NativeAuthBridge. */ + val codec: MessageCodec by lazy { + NativeAuthBridgeCodec } - } - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser", codec) - if (api != null) { - channel.setMessageHandler { message, reply -> - val args = message as List - val userArg = args[0] as NativeAuthUser? - var wrapped: List - try { - api.updateCurrentUser(userArg) - wrapped = listOf(null) - } catch (exception: Throwable) { - wrapped = wrapError(exception) + + /** Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. */ + @Suppress("UNCHECKED_CAST") + fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?) { + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin", codec) + if (api != null) { + channel.setMessageHandler { _, reply -> + api.addAuthPlugin() { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(wrapError(error)) + } else { + reply.reply(wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val userArg = args[0] as NativeAuthUser? + var wrapped: List + try { + api.updateCurrentUser(userArg) + wrapped = listOf(null) + } catch (exception: Throwable) { + wrapped = wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } } - reply.reply(wrapped) - } - } else { - channel.setMessageHandler(null) } - } } - } } + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface NativeApiBridge { - fun addApiPlugin(authProvidersList: List, callback: (Result) -> Unit) + fun addApiPlugin(authProvidersList: List, callback: (Result) -> Unit) - companion object { - /** The codec used by NativeApiBridge. */ - val codec: MessageCodec by lazy { - StandardMessageCodec() - } - /** Sets up an instance of `NativeApiBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeApiBridge?) { - run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin", codec) - if (api != null) { - channel.setMessageHandler { message, reply -> - val args = message as List - val authProvidersListArg = args[0] as List - api.addApiPlugin(authProvidersListArg) { result: Result -> - val error = result.exceptionOrNull() - if (error != null) { - reply.reply(wrapError(error)) - } else { - reply.reply(wrapResult(null)) - } + companion object { + /** The codec used by NativeApiBridge. */ + val codec: MessageCodec by lazy { + StandardMessageCodec() + } + + /** Sets up an instance of `NativeApiBridge` to handle messages through the `binaryMessenger`. */ + @Suppress("UNCHECKED_CAST") + fun setUp(binaryMessenger: BinaryMessenger, api: NativeApiBridge?) { + run { + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val authProvidersListArg = args[0] as List + api.addApiPlugin(authProvidersListArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(wrapError(error)) + } else { + reply.reply(wrapResult(null)) + } + } + } + } else { + channel.setMessageHandler(null) + } } - } - } else { - channel.setMessageHandler(null) } - } } - } } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterOutboxMutationEnqueuedEvent.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterOutboxMutationEnqueuedEvent.kt index 743a6fe050..3772e2f993 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterOutboxMutationEnqueuedEvent.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterOutboxMutationEnqueuedEvent.kt @@ -12,7 +12,6 @@ class FlutterOutboxMutationEnqueuedEvent( private val element: OutboxMutationEvent.OutboxMutationEventElement ) : FlutterHubEvent { override fun toValueMap(): Map { - return mapOf( "eventName" to this.eventName, "modelName" to this.modelName, diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterSubscriptionDataProcessedEvent.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterSubscriptionDataProcessedEvent.kt index 4ca2ae6dcc..b98e5975cf 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterSubscriptionDataProcessedEvent.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/hub/FlutterSubscriptionDataProcessedEvent.kt @@ -10,7 +10,7 @@ import com.amplifyframework.datastore.appsync.ModelMetadata class FlutterSubscriptionDataProcessedEvent( override val eventName: String, private val model: SerializedModel, - private val syncMetadata: ModelMetadata, + private val syncMetadata: ModelMetadata ) : FlutterHubEvent { override fun toValueMap(): Map { return mapOf( diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterAuthRule.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterAuthRule.kt index 50d90fbe52..2f8e632589 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterAuthRule.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterAuthRule.kt @@ -53,7 +53,6 @@ data class FlutterAuthRule(val map: Map) { } fun convertToNativeAuthRule(): AuthRule { - val builder: AuthRule.Builder = AuthRule.builder() .authStrategy(authStrategy) diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelField.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelField.kt index e790d50997..53ccacc09c 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelField.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelField.kt @@ -38,8 +38,11 @@ data class FlutterModelField(val map: Map) { // Association (if any) of the model private val flutterModelAssociation: FlutterModelAssociation? = - if (map["association"] == null) null - else FlutterModelAssociation(map["association"] as Map) + if (map["association"] == null) { + null + } else { + FlutterModelAssociation(map["association"] as Map) + } fun getModelAssociation(): FlutterModelAssociation? { return flutterModelAssociation diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelSchema.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelSchema.kt index e047ddee7a..a95d2edc16 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelSchema.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterModelSchema.kt @@ -32,8 +32,10 @@ data class FlutterModelSchema(val map: Map) { if (rawIndexes is List<*>) { parsedIndexes.putAll( (rawIndexes.cast>()).associate { - (it["name"] as String? - ?: FlutterModelIndex.unnamedIndexKey) to FlutterModelIndex(it).convertToNativeModelIndex() + ( + it["name"] as String? + ?: FlutterModelIndex.unnamedIndexKey + ) to FlutterModelIndex(it).convertToNativeModelIndex() }.toMap() ) } @@ -54,6 +56,6 @@ data class FlutterModelSchema(val map: Map) { // to allow amplify-android correctly interpret custom primary key // schema version needs to be >= 1 .version(1) - .build(); + .build() } } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedCustomType.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedCustomType.kt index cab9edefa7..cf438de94f 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedCustomType.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedCustomType.kt @@ -28,9 +28,11 @@ data class FlutterSerializedCustomType(val serializedCustomType: SerializedCusto serializedData: Map, customTypeSchema: CustomTypeSchema ): Map { - if (serializedData.isEmpty()) throw Exception( - "FlutterSerializedCustomType - no serializedData for ${customTypeSchema.name}" - ) + if (serializedData.isEmpty()) { + throw Exception( + "FlutterSerializedCustomType - no serializedData for ${customTypeSchema.name}" + ) + } return serializedData.mapValues { val field = customTypeSchema.fields[it.key]!! diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedModel.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedModel.kt index e7006ce561..69d7face9f 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedModel.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/model/FlutterSerializedModel.kt @@ -22,7 +22,6 @@ data class FlutterSerializedModel(val serializedModel: SerializedModel) { parseModelName(serializedModel.modelName) // ModelSchema -> SerializedModel should always have a name fun toMap(): Map { - val cleanedSerializedData: Map = serializedData.filterValues { it != null } return mapOf( @@ -32,14 +31,19 @@ data class FlutterSerializedModel(val serializedModel: SerializedModel) { } private fun parseModelName(modelName: String?): String { - return if (modelName.isNullOrEmpty()) "" - else modelName + return if (modelName.isNullOrEmpty()) { + "" + } else { + modelName + } } private fun parseSerializedDataMap(serializedData: Map, modelSchema: ModelSchema): Map { - if (serializedData.isEmpty()) throw Exception( - "FlutterSerializedModel - no serializedData for ${modelSchema.name}" - ) + if (serializedData.isEmpty()) { + throw Exception( + "FlutterSerializedModel - no serializedData for ${modelSchema.name}" + ) + } return serializedData.mapValues { val field = modelSchema.fields[it.key] diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilder.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilder.kt index 938f8f6fd4..5d76f7a38a 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilder.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilder.kt @@ -13,15 +13,17 @@ class QueryPaginationBuilder { if (serializedMap == null) { return null } - var queryPaginationInput = if (serializedMap.containsKey("page")) + var queryPaginationInput = if (serializedMap.containsKey("page")) { Page.startingAt(serializedMap["page"] as Int) - else + } else { Page.firstPage() + } - queryPaginationInput = if (serializedMap.containsKey("limit")) + queryPaginationInput = if (serializedMap.containsKey("limit")) { queryPaginationInput.withLimit(serializedMap["limit"] as Int) - else + } else { queryPaginationInput + } return queryPaginationInput } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilder.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilder.kt index 528f75a84d..5f5eb704bb 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilder.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilder.kt @@ -60,7 +60,7 @@ class QueryPredicateBuilder { is List<*> -> { convertQueryByNestedModelIdentifierToPredicate( queryField, - operand.cast>(), + operand.cast>(), true ) } @@ -70,7 +70,7 @@ class QueryPredicateBuilder { is List<*> -> { convertQueryByNestedModelIdentifierToPredicate( queryField, - operand.cast>(), + operand.cast>(), false ) } @@ -136,7 +136,7 @@ class QueryPredicateBuilder { if (predicates.isNotEmpty()) { throw IllegalArgumentException( "More than one predicates added in the `not` queryPredicate operation." + - " Predicates Size: " + predicates.size + " Predicates Size: " + predicates.size ) } resultQueryPredicate = @@ -195,10 +195,13 @@ class QueryPredicateBuilder { } @JvmStatic - fun convertQueryByIdentifierOperationToPredicate(modelName: String?, operands: List>, - isEqualOperator: - Boolean): - QueryPredicate { + fun convertQueryByIdentifierOperationToPredicate( + modelName: String?, + operands: List>, + isEqualOperator: + Boolean + ): + QueryPredicate { var predicates = operands.map { val operandEntry = it.entries.first() when { @@ -223,7 +226,8 @@ class QueryPredicateBuilder { @JvmStatic fun convertQueryByNestedModelIdentifierToPredicate( - queryField: QueryField, operands: List>, + queryField: QueryField, + operands: List>, isEqualOperator: Boolean ): QueryPredicate { val identifierFieldsValues = operands.map { it.values.first() } diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/util/SafeCastingUtil.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/util/SafeCastingUtil.kt index 8bbaf04d99..1117c324eb 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/util/SafeCastingUtil.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/util/SafeCastingUtil.kt @@ -5,12 +5,16 @@ package com.amazonaws.amplify.amplify_datastore.util @Suppress("UNCHECKED_CAST") inline fun Any?.safeCastToMap() = - if (this is T) + if (this is T) { this as Map - else null + } else { + null + } @Suppress("UNCHECKED_CAST") inline fun Any?.safeCastToList() = - if (this is List<*> && this.all { it is T }) + if (this is List<*> && this.all { it is T }) { this as List - else null + } else { + null + } diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStoreHubTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStoreHubTest.kt index 2fc9f81af7..6ff7356902 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStoreHubTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStoreHubTest.kt @@ -64,20 +64,18 @@ class AmplifyDataStoreHubTest { val modelProvider = FlutterModelProvider.instance modelProvider.addModelSchema("Post", postSchema) modelSchema = flutterPlugin.modelProvider.modelSchemas()["Post"]!! - setFinalStatic(Amplify::class.java.getDeclaredField("DataStore"), mockDataStore) - `when`(mockDataStore.getPlugin("awsDataStorePlugin")).thenReturn(mockAmplifyDataStorePlugin) } @Test fun test_hub_outboxMutationEnqueued_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "outboxMutationEnqueuedEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "outboxMutationEnqueuedEvent.json", + HashMap::class.java + ) as HashMap + ) val element: HashMap = eventData["element"] as HashMap var metadataMap: HashMap val modelMap: HashMap = element["model"] as HashMap @@ -121,12 +119,12 @@ class AmplifyDataStoreHubTest { fun test_hub_outboxMutationProcessed_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "outboxMutationProcessedEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "outboxMutationProcessedEvent.json", + HashMap::class.java + ) as HashMap + ) val element: HashMap = eventData["element"] as HashMap val metadataMap: HashMap = element["syncMetadata"] as HashMap val modelMap: HashMap = element["model"] as HashMap @@ -135,7 +133,7 @@ class AmplifyDataStoreHubTest { metadataMap["id"] as String, metadataMap["_deleted"] as Boolean, metadataMap["_version"] as Int, - time, + time ) val modelData = mapOf( "id" to serializedData["id"] as String, @@ -175,12 +173,12 @@ class AmplifyDataStoreHubTest { fun test_hub_ready_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "readyEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "readyEvent.json", + HashMap::class.java + ) as HashMap + ) val event: HubEvent<*> = HubEvent.create(DataStoreChannelEventName.READY) @@ -205,12 +203,12 @@ class AmplifyDataStoreHubTest { fun test_hub_subscriptionsEstablished_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "subscriptionsEstablishedEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "subscriptionsEstablishedEvent.json", + HashMap::class.java + ) as HashMap + ) val event: HubEvent<*> = HubEvent.create(DataStoreChannelEventName.SUBSCRIPTIONS_ESTABLISHED) @@ -235,12 +233,12 @@ class AmplifyDataStoreHubTest { fun test_hub_syncQueriesReady_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "syncQueriesReadyEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "syncQueriesReadyEvent.json", + HashMap::class.java + ) as HashMap + ) val event: HubEvent<*> = HubEvent.create(DataStoreChannelEventName.SYNC_QUERIES_READY) @@ -267,12 +265,12 @@ class AmplifyDataStoreHubTest { fun test_hub_networkStatus_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "networkStatusEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "networkStatusEvent.json", + HashMap::class.java + ) as HashMap + ) val networkStatusEvent: NetworkStatusEvent = NetworkStatusEvent(eventData["active"] as Boolean) @@ -298,12 +296,12 @@ class AmplifyDataStoreHubTest { fun test_hub_outboxStatus_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "outboxStatusEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "outboxStatusEvent.json", + HashMap::class.java + ) as HashMap + ) val outboxStatusEvent = OutboxStatusEvent(eventData["isEmpty"] as Boolean) @@ -329,12 +327,12 @@ class AmplifyDataStoreHubTest { fun test_hub_syncQueriesStarted_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "syncQueriesStartedEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "syncQueriesStartedEvent.json", + HashMap::class.java + ) as HashMap + ) val syncQueriesStartedEvent: SyncQueriesStartedEvent = SyncQueriesStartedEvent(arrayOf("Post")) val event: HubEvent<*> = HubEvent.create("syncQueriesStarted", syncQueriesStartedEvent) @@ -361,12 +359,12 @@ class AmplifyDataStoreHubTest { fun test_hub_modelSynced_event() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "modelSyncedEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "modelSyncedEvent.json", + HashMap::class.java + ) as HashMap + ) val modelSyncedEvent: ModelSyncedEvent = ModelSyncedEvent( eventData["model"] as String, @@ -404,12 +402,12 @@ class AmplifyDataStoreHubTest { fun test_replay_events() { flutterPlugin = AmplifyDataStorePlugin(eventHandler = mockStreamHandler, hubEventHandler = mockHubHandler) val eventData: HashMap = ( - readMapFromFile( - "hub", - "readyEvent.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "hub", + "readyEvent.json", + HashMap::class.java + ) as HashMap + ) val event: HubEvent<*> = HubEvent.create(DataStoreChannelEventName.READY) diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePluginTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePluginTest.kt index 0b66d0d180..3e9215cc1a 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePluginTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePluginTest.kt @@ -3,6 +3,8 @@ package com.amazonaws.amplify.amplify_datastore +import android.os.Handler +import android.os.Looper import com.amazonaws.amplify.amplify_datastore.exception.ExceptionMessages import com.amazonaws.amplify.amplify_datastore.types.model.FlutterSerializedModel import com.amplifyframework.api.aws.AuthModeStrategyType @@ -35,7 +37,6 @@ import org.mockito.ArgumentMatchers.any import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.RETURNS_SELF -import org.mockito.Mockito.`when` import org.mockito.Mockito.doAnswer import org.mockito.Mockito.mock import org.mockito.Mockito.mockStatic @@ -43,10 +44,9 @@ import org.mockito.Mockito.never import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoInteractions +import org.mockito.Mockito.`when` import org.mockito.invocation.InvocationOnMock import org.robolectric.RobolectricTestRunner -import java.lang.reflect.Field -import java.lang.reflect.Modifier import java.util.concurrent.TimeUnit @RunWith(RobolectricTestRunner::class) @@ -55,7 +55,7 @@ class AmplifyDataStorePluginTest { private lateinit var modelSchema: ModelSchema private lateinit var amplifySuccessResults: MutableList - private var mockDataStore = mock(DataStoreCategory::class.java) + private var mockThreadHandler = mock(Handler::class.java) private var mockAmplifyDataStorePlugin = mock(AWSDataStorePlugin::class.java) private val mockResult: MethodChannel.Result = mock(MethodChannel.Result::class.java) private val mockStreamHandler: DataStoreObserveEventStreamHandler = @@ -64,7 +64,8 @@ class AmplifyDataStorePluginTest { mock(DataStoreHubEventStreamHandler::class.java) private val dataStoreException = DataStoreException("Some useful exception message", "Some useful recovery message") - private val dataStoreObserveStartFailure = DataStoreException("Failed to start DataStore.", "Retry") + private val dataStoreObserveStartFailure = + DataStoreException("Failed to start DataStore.", "Retry") private val mockModelSchemas = mutableListOf( mapOf( "name" to "Post", @@ -84,14 +85,15 @@ class AmplifyDataStorePluginTest { ) ) - private val mockDataStorePluginBuilder = mock(AWSDataStorePlugin.Builder::class.java, RETURNS_SELF) + private val mockDataStorePluginBuilder = + mock(AWSDataStorePlugin.Builder::class.java, RETURNS_SELF) private val defaultDataStoreConfiguration = DataStoreConfiguration.defaults() private val mockDataStoreConfigurationBuilder = mock(DataStoreConfiguration.Builder::class.java, RETURNS_SELF) @Before fun setup() { - flutterPlugin = AmplifyDataStorePlugin() + flutterPlugin = AmplifyDataStorePlugin(mockAmplifyDataStorePlugin, mockThreadHandler, mockStreamHandler, mockHubHandler) val modelProvider = FlutterModelProvider.instance modelProvider.addModelSchema("Post", postSchema) modelProvider.addModelSchema("Blog", blogSchema) @@ -127,8 +129,10 @@ class AmplifyDataStorePluginTest { ) .build() ) - setFinalStatic(Amplify::class.java.getDeclaredField("DataStore"), mockDataStore) - `when`(mockDataStore.getPlugin("awsDataStorePlugin")).thenReturn(mockAmplifyDataStorePlugin) + `when`(mockThreadHandler.post(any(Runnable::class.java))).thenAnswer { + (it.arguments[0] as Runnable).run() + true + } } @Test @@ -160,7 +164,10 @@ class AmplifyDataStorePluginTest { verify(mockDataStoreConfigurationBuilder, times(1)).syncPageSize( defaultDataStoreConfiguration.syncPageSize ) - verify(mockDataStoreConfigurationBuilder, never()).syncExpression(anyString(), any()) + verify(mockDataStoreConfigurationBuilder, never()).syncExpression( + anyString(), + any() + ) verify(mockDataStorePluginBuilder, times(1)).authModeStrategy(authModeStrategy) } mockDataStorePlugin.close() @@ -195,7 +202,9 @@ class AmplifyDataStorePluginTest { mockDataStoreConfigurationBuilder, times(1) ).syncInterval(mockSyncInterval.toLong(), TimeUnit.MINUTES) - verify(mockDataStoreConfigurationBuilder, times(1)).syncMaxRecords(mockSyncMaxRecords) + verify(mockDataStoreConfigurationBuilder, times(1)).syncMaxRecords( + mockSyncMaxRecords + ) verify(mockDataStoreConfigurationBuilder, times(1)).syncPageSize(mockSyncPageSize) verify(mockDataStorePluginBuilder, times(1)).authModeStrategy(authModeStrategy) } @@ -268,7 +277,8 @@ class AmplifyDataStorePluginTest { ) null }.`when`(mockAmplifyDataStorePlugin).query( - anyString(), any(QueryOptions::class.java), + anyString(), + any(QueryOptions::class.java), any>>(), any>() ) @@ -293,10 +303,10 @@ class AmplifyDataStorePluginTest { fun test_query_with_predicates_success_zero_result() { val queryOptions = Where.matches( - field("Post","id").eq("123").or( - field("Post","rating").ge(4).and( + field("Post", "id").eq("123").or( + field("Post", "rating").ge(4).and( not( - field("Post","created").eq("2020-02-20T20:20:20-08:00") + field("Post", "created").eq("2020-02-20T20:20:20-08:00") ) ) ) @@ -331,12 +341,12 @@ class AmplifyDataStorePluginTest { @Test fun test_query_api_error() { val testRequest: HashMap = ( - readMapFromFile( - "query_api", - "request/only_model_name.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "query_api", + "request/only_model_name.json", + HashMap::class.java + ) as HashMap + ) doAnswer { invocation: InvocationOnMock -> assertEquals("Post", invocation.arguments[0]) @@ -385,12 +395,12 @@ class AmplifyDataStorePluginTest { @Test fun test_delete_success_result_no_predicates() { val testRequest: HashMap = ( - readMapFromFile( - "delete_api", - "request/instance_no_predicate.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "delete_api", + "request/instance_no_predicate.json", + HashMap::class.java + ) as HashMap + ) val serializedModelData: HashMap = testRequest["serializedModel"] as HashMap @@ -427,14 +437,13 @@ class AmplifyDataStorePluginTest { @Test fun test_delete_api_error() { - val testRequest: HashMap = ( - readMapFromFile( - "delete_api", - "request/instance_no_predicate.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "delete_api", + "request/instance_no_predicate.json", + HashMap::class.java + ) as HashMap + ) val serializedModelData: HashMap = testRequest["serializedModel"] as HashMap @@ -490,12 +499,12 @@ class AmplifyDataStorePluginTest { @Test fun test_save_success_result_no_predicates() { val testRequest: HashMap = ( - readMapFromFile( - "save_api", - "request/instance_without_predicate.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "save_api", + "request/instance_without_predicate.json", + HashMap::class.java + ) as HashMap + ) val serializedModelData: HashMap = testRequest["serializedModel"] as HashMap @@ -533,14 +542,13 @@ class AmplifyDataStorePluginTest { @Test fun test_save_api_error() { - val testRequest: HashMap = ( - readMapFromFile( - "save_api", - "request/instance_without_predicate.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "save_api", + "request/instance_without_predicate.json", + HashMap::class.java + ) as HashMap + ) val serializedModelData: HashMap = testRequest["serializedModel"] as HashMap @@ -596,11 +604,6 @@ class AmplifyDataStorePluginTest { @Test fun test_observe_set_up_success() { - flutterPlugin = AmplifyDataStorePlugin( - eventHandler = mockStreamHandler, - hubEventHandler = mockHubHandler - ) - doAnswer { invocation: InvocationOnMock -> (invocation.arguments[0] as Consumer).accept( Cancelable { } @@ -620,11 +623,6 @@ class AmplifyDataStorePluginTest { @Test fun test_observe_set_up_failure() { - flutterPlugin = AmplifyDataStorePlugin( - eventHandler = mockStreamHandler, - hubEventHandler = mockHubHandler - ) - doAnswer { invocation: InvocationOnMock -> (invocation.arguments[2] as Consumer).accept( dataStoreObserveStartFailure @@ -644,17 +642,13 @@ class AmplifyDataStorePluginTest { @Test fun test_observe_success_event() { - flutterPlugin = AmplifyDataStorePlugin( - eventHandler = mockStreamHandler, - hubEventHandler = mockHubHandler - ) val eventData: HashMap = ( - readMapFromFile( - "observe_api", - "post_type_success_event.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "observe_api", + "post_type_success_event.json", + HashMap::class.java + ) as HashMap + ) val modelData = mapOf( "id" to "43036c6b-8044-4309-bddc-262b6c686026", "title" to "Title 2", @@ -694,7 +688,9 @@ class AmplifyDataStorePluginTest { fun test_observe_receive_error_event() { flutterPlugin = AmplifyDataStorePlugin( eventHandler = mockStreamHandler, - hubEventHandler = mockHubHandler + hubEventHandler = mockHubHandler, + uiThreadHandler = mockThreadHandler, + dataStorePlugin = mockAmplifyDataStorePlugin, ) doAnswer { invocation: InvocationOnMock -> @@ -836,29 +832,40 @@ class AmplifyDataStorePluginTest { ) ) - val deserializedResult = flutterPlugin.deserializeNestedModel(serializedPersonData, personSchema) + val deserializedResult = + flutterPlugin.deserializeNestedModel(serializedPersonData, personSchema) assertEquals(deserializedResult["id"], serializedPersonData["id"]) assertEquals(deserializedResult["name"], serializedPersonData["name"]) assert(deserializedResult["contact"] is SerializedCustomType) val serializedContactData = serializedPersonData["contact"] as Map<*, *> - val deserializedContactData = (deserializedResult["contact"] as SerializedCustomType).serializedData + val deserializedContactData = + (deserializedResult["contact"] as SerializedCustomType).serializedData assertEquals(deserializedContactData["email"], serializedContactData["email"]) assert(deserializedContactData["phone"] is SerializedCustomType) val serializedPhoneData = serializedContactData["phone"] as Map<*, *> - val deserializedPhoneData = (deserializedContactData["phone"] as SerializedCustomType).serializedData + val deserializedPhoneData = + (deserializedContactData["phone"] as SerializedCustomType).serializedData assertEquals(deserializedPhoneData, serializedPhoneData) assert(deserializedContactData["mailingAddresses"] is List<*>) - val serializedMailingAddressesData = serializedContactData["mailingAddresses"] as List> - val deserializedMailingAddressesData = deserializedContactData["mailingAddresses"] as List - val flatDeserializedMailingAddressesData = deserializedMailingAddressesData.map { it.serializedData } - assertEquals(flatDeserializedMailingAddressesData as List<*>, serializedMailingAddressesData as List<*>) + val serializedMailingAddressesData = + serializedContactData["mailingAddresses"] as List> + val deserializedMailingAddressesData = + deserializedContactData["mailingAddresses"] as List + val flatDeserializedMailingAddressesData = + deserializedMailingAddressesData.map { it.serializedData } + assertEquals( + flatDeserializedMailingAddressesData as List<*>, + serializedMailingAddressesData as List<*> + ) assert(deserializedResult["propertiesAddresses"] is List<*>) - val serializedPropertiesAddressesData = serializedPersonData["propertiesAddresses"] as List> + val serializedPropertiesAddressesData = + serializedPersonData["propertiesAddresses"] as List> val deserializedPropertiesAddressesData = deserializedResult["propertiesAddresses"] as List - val flatDeserializedPropertiesAddressesData = deserializedPropertiesAddressesData.map { it.serializedData } + val flatDeserializedPropertiesAddressesData = + deserializedPropertiesAddressesData.map { it.serializedData } assertEquals(flatDeserializedPropertiesAddressesData, serializedPropertiesAddressesData) } @@ -931,12 +938,4 @@ class AmplifyDataStorePluginTest { ) ) } - - private fun setFinalStatic(field: Field, newValue: Any?) { - field.isAccessible = true - val modifiersField: Field = Field::class.java.getDeclaredField("modifiers") - modifiersField.isAccessible = true - modifiersField.setInt(field, field.modifiers and Modifier.FINAL.inv()) - field.set(null, newValue) - } } diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyModelSchemaTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyModelSchemaTest.kt index 79a68fb6ee..0c300fdad4 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyModelSchemaTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyModelSchemaTest.kt @@ -15,12 +15,12 @@ import org.robolectric.RobolectricTestRunner class AmplifyModelSchemaTest { private var schemasMap: Map = ( - readMapFromFile( - "model_schema", - "model_schema_maps.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "model_schema", + "model_schema_maps.json", + HashMap::class.java + ) as HashMap + ) @Test fun test_schema_blog_with_hasMany() { diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifySerializedModelTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifySerializedModelTest.kt index c51d45f1cd..9d8b0df92e 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifySerializedModelTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifySerializedModelTest.kt @@ -13,12 +13,12 @@ import org.robolectric.RobolectricTestRunner class AmplifySerializedModelTest { private var serializedModelMaps: Map = ( - readMapFromFile( - "model_schema", - "serialized_model_maps.json", - HashMap::class.java - ) as HashMap - ) + readMapFromFile( + "model_schema", + "serialized_model_maps.json", + HashMap::class.java + ) as HashMap + ) @Test fun test_schema_blog_with_hasMany() { diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/CoroutineTestRule.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/CoroutineTestRule.kt index 51debde6b2..7111a86339 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/CoroutineTestRule.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/CoroutineTestRule.kt @@ -25,4 +25,4 @@ class CoroutineTestRule(val testDispatcher: TestCoroutineDispatcher = TestCorout Dispatchers.resetMain() testDispatcher.cleanupTestCoroutines() } -} \ No newline at end of file +} diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/SchemaData.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/SchemaData.kt index e1aee56abf..6e1a2851b3 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/SchemaData.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/SchemaData.kt @@ -18,111 +18,113 @@ import com.amplifyframework.core.model.temporal.Temporal val postSchema = ModelSchema.builder() .name("Post") .pluralName("Posts") - .indexes(mapOf( - "byBlog" to ModelIndex.builder() - .indexName("byBlog") - .indexFieldNames(listOf("blogID")) - .build() - )) + .indexes( + mapOf( + "byBlog" to ModelIndex.builder() + .indexName("byBlog") + .indexFieldNames(listOf("blogID")) + .build() + ) + ) .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "title" to - ModelField.builder() - .name("title") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("title") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "created" to - ModelField.builder() - .name("created") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("created") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .build(), "rating" to - ModelField.builder() - .name("rating") - .javaClassForValue(Integer::class.java) - .targetType("Integer") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("rating") + .javaClassForValue(Integer::class.java) + .targetType("Integer") + .isRequired(false) + .isArray(false) + .build(), "blog" to - ModelField.builder() - .name("blog") - .javaClassForValue(Model::class.java) - .targetType("Blog") - .isRequired(false) - .isArray(false) - .isModel(true) - .build(), + ModelField.builder() + .name("blog") + .javaClassForValue(Model::class.java) + .targetType("Blog") + .isRequired(false) + .isArray(false) + .isModel(true) + .build(), "comments" to - ModelField.builder() - .name("comments") - .javaClassForValue(List::class.java) - .targetType("Comment") - .isRequired(false) - .isArray(true) - .build(), + ModelField.builder() + .name("comments") + .javaClassForValue(List::class.java) + .targetType("Comment") + .isRequired(false) + .isArray(true) + .build(), "likeCount" to - ModelField.builder() - .name("likeCount") - .javaClassForValue(Integer::class.java) - .targetType("Integer") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("likeCount") + .javaClassForValue(Integer::class.java) + .targetType("Integer") + .isRequired(false) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .associations( mapOf( "blog" to - ModelAssociation.builder() - .name("BelongsTo") - .targetNames(listOf("blogID").toTypedArray()) - .build(), + ModelAssociation.builder() + .name("BelongsTo") + .targetNames(listOf("blogID").toTypedArray()) + .build(), "comments" to - ModelAssociation.builder() - .name("HasMany") - .associatedName("post") - .associatedType("Post") - .build() + ModelAssociation.builder() + .name("HasMany") + .associatedName("post") + .associatedType("Post") + .build() ) ) @@ -136,49 +138,49 @@ val postAuthComplexSchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "title" to - ModelField.builder() - .name("title") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("title") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "owner" to - ModelField.builder() - .name("owner") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("owner") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(false) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .authRules( @@ -210,40 +212,40 @@ val postAuthComplexWithProviderUserPoolsSchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "owner" to - ModelField.builder() - .name("owner") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("owner") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(false) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .authRules( @@ -266,32 +268,32 @@ val postAuthComplexWithProviderApiKeySchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .authRules( @@ -312,58 +314,58 @@ val commentSchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "post" to - ModelField.builder() - .name("post") - .javaClassForValue(Model::class.java) - .targetType("Post") - .isRequired(false) - .isArray(false) - .isModel(true) - .build(), + ModelField.builder() + .name("post") + .javaClassForValue(Model::class.java) + .targetType("Post") + .isRequired(false) + .isArray(false) + .isModel(true) + .build(), "content" to - ModelField.builder() - .name("content") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("content") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .associations( mapOf( "post" to - ModelAssociation.builder() - .name("BelongsTo") - .targetNames(listOf("postID").toTypedArray()) - .build() + ModelAssociation.builder() + .name("BelongsTo") + .targetNames(listOf("postID").toTypedArray()) + .build() ) ) .modelClass(SerializedModel::class.java) @@ -376,58 +378,58 @@ val blogSchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "name" to - ModelField.builder() - .name("name") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("name") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "posts" to - ModelField.builder() - .name("posts") - .javaClassForValue(List::class.java) - .targetType("Post") - .isRequired(false) - .isArray(true) - .build(), + ModelField.builder() + .name("posts") + .javaClassForValue(List::class.java) + .targetType("Post") + .isRequired(false) + .isArray(true) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .associations( mapOf( "posts" to - ModelAssociation.builder() - .name("HasMany") - .associatedName("blog") - .associatedType("Blog") - .build() + ModelAssociation.builder() + .name("HasMany") + .associatedName("blog") + .associatedType("Blog") + .build() ) ) .modelClass(SerializedModel::class.java) @@ -440,104 +442,104 @@ val allTypeModelSchema = ModelSchema.builder() .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "stringType" to - ModelField.builder() - .name("stringType") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("stringType") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "intType" to - ModelField.builder() - .name("intType") - .javaClassForValue(Integer::class.java) - .targetType("Integer") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("intType") + .javaClassForValue(Integer::class.java) + .targetType("Integer") + .isRequired(true) + .isArray(false) + .build(), "floatType" to - ModelField.builder() - .name("floatType") - .javaClassForValue(Double::class.javaObjectType) - .targetType("Double") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("floatType") + .javaClassForValue(Double::class.javaObjectType) + .targetType("Double") + .isRequired(true) + .isArray(false) + .build(), "boolType" to - ModelField.builder() - .name("boolType") - .javaClassForValue(Boolean::class.javaObjectType) - .targetType("Boolean") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("boolType") + .javaClassForValue(Boolean::class.javaObjectType) + .targetType("Boolean") + .isRequired(true) + .isArray(false) + .build(), "dateType" to - ModelField.builder() - .name("dateType") - .javaClassForValue(Temporal.Date::class.java) - .targetType("AWSDate") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("dateType") + .javaClassForValue(Temporal.Date::class.java) + .targetType("AWSDate") + .isRequired(true) + .isArray(false) + .build(), "dateTimeType" to - ModelField.builder() - .name("dateTimeType") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("dateTimeType") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(true) + .isArray(false) + .build(), "timeType" to - ModelField.builder() - .name("timeType") - .javaClassForValue(Temporal.Time::class.java) - .targetType("AWSTime") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("timeType") + .javaClassForValue(Temporal.Time::class.java) + .targetType("AWSTime") + .isRequired(true) + .isArray(false) + .build(), "timestampType" to - ModelField.builder() - .name("timestampType") - .javaClassForValue(Temporal.Timestamp::class.java) - .targetType("AWSTimestamp") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("timestampType") + .javaClassForValue(Temporal.Timestamp::class.java) + .targetType("AWSTimestamp") + .isRequired(true) + .isArray(false) + .build(), "enumType" to - ModelField.builder() - .name("enumType") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("enumType") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .modelClass(SerializedModel::class.java) @@ -691,157 +693,163 @@ val inventorySchema = ModelSchema.builder() .name("Inventory") .pluralName("Inventories") .modelClass(SerializedModel::class.java) - .indexes(mapOf( - "undefined" to ModelIndex.builder() - .indexName("undefined") - .indexFieldNames(listOf("productID", "name", "warehouseID", "region")) - .build() - )) - .fields(mapOf( - "productID" to ModelField.builder() - .name("productID") - .targetType("String") - .javaClassForValue(String::class.java) - .isRequired(true) - .isReadOnly(false) - .isArray(false) - .build(), - "name" to ModelField.builder() - .name("name") - .targetType("String") - .javaClassForValue(String::class.java) - .isRequired(true) - .isReadOnly(false) - .isArray(false) - .build(), - "warehouseID" to ModelField.builder() - .name("warehouseID") - .targetType("String") - .javaClassForValue(String::class.java) - .isRequired(true) - .isReadOnly(false) - .isArray(false) - .build(), - "region" to ModelField.builder() - .name("region") - .targetType("String") - .javaClassForValue(String::class.java) - .isRequired(true) - .isReadOnly(false) - .isArray(false) - .build() - )) + .indexes( + mapOf( + "undefined" to ModelIndex.builder() + .indexName("undefined") + .indexFieldNames(listOf("productID", "name", "warehouseID", "region")) + .build() + ) + ) + .fields( + mapOf( + "productID" to ModelField.builder() + .name("productID") + .targetType("String") + .javaClassForValue(String::class.java) + .isRequired(true) + .isReadOnly(false) + .isArray(false) + .build(), + "name" to ModelField.builder() + .name("name") + .targetType("String") + .javaClassForValue(String::class.java) + .isRequired(true) + .isReadOnly(false) + .isArray(false) + .build(), + "warehouseID" to ModelField.builder() + .name("warehouseID") + .targetType("String") + .javaClassForValue(String::class.java) + .isRequired(true) + .isReadOnly(false) + .isArray(false) + .build(), + "region" to ModelField.builder() + .name("region") + .targetType("String") + .javaClassForValue(String::class.java) + .isRequired(true) + .isReadOnly(false) + .isArray(false) + .build() + ) + ) .version(1) .build() val cpkPostSchema = ModelSchema.builder() .name("Post") .pluralName("Posts") - .indexes(mapOf( - "byBlog" to ModelIndex.builder() - .indexName("byBlog") - .indexFieldNames(listOf("blogID")) - .build() - )) + .indexes( + mapOf( + "byBlog" to ModelIndex.builder() + .indexName("byBlog") + .indexFieldNames(listOf("blogID")) + .build() + ) + ) .fields( mapOf( "id" to - ModelField.builder() - .name("id") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("id") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "title" to - ModelField.builder() - .name("title") - .javaClassForValue(String::class.java) - .targetType("String") - .isRequired(true) - .isArray(false) - .build(), + ModelField.builder() + .name("title") + .javaClassForValue(String::class.java) + .targetType("String") + .isRequired(true) + .isArray(false) + .build(), "created" to - ModelField.builder() - .name("created") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("created") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .build(), "rating" to - ModelField.builder() - .name("rating") - .javaClassForValue(Integer::class.java) - .targetType("Integer") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("rating") + .javaClassForValue(Integer::class.java) + .targetType("Integer") + .isRequired(false) + .isArray(false) + .build(), "blog" to - ModelField.builder() - .name("blog") - .javaClassForValue(Model::class.java) - .targetType("Blog") - .isRequired(false) - .isArray(false) - .isModel(true) - .build(), + ModelField.builder() + .name("blog") + .javaClassForValue(Model::class.java) + .targetType("Blog") + .isRequired(false) + .isArray(false) + .isModel(true) + .build(), "comments" to - ModelField.builder() - .name("comments") - .javaClassForValue(List::class.java) - .targetType("Comment") - .isRequired(false) - .isArray(true) - .build(), + ModelField.builder() + .name("comments") + .javaClassForValue(List::class.java) + .targetType("Comment") + .isRequired(false) + .isArray(true) + .build(), "likeCount" to - ModelField.builder() - .name("likeCount") - .javaClassForValue(Integer::class.java) - .targetType("Integer") - .isRequired(false) - .isArray(false) - .build(), + ModelField.builder() + .name("likeCount") + .javaClassForValue(Integer::class.java) + .targetType("Integer") + .isRequired(false) + .isArray(false) + .build(), "createdAt" to - ModelField.builder() - .name("createdAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build(), + ModelField.builder() + .name("createdAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build(), "updatedAt" to - ModelField.builder() - .name("updatedAt") - .javaClassForValue(Temporal.DateTime::class.java) - .targetType("AWSDateTime") - .isRequired(false) - .isArray(false) - .isReadOnly(true) - .build() + ModelField.builder() + .name("updatedAt") + .javaClassForValue(Temporal.DateTime::class.java) + .targetType("AWSDateTime") + .isRequired(false) + .isArray(false) + .isReadOnly(true) + .build() ) ) .associations( mapOf( "blog" to - ModelAssociation.builder() - .name("BelongsTo") - .targetNames(listOf("blogID", "blogName").toTypedArray()) - .build(), + ModelAssociation.builder() + .name("BelongsTo") + .targetNames(listOf("blogID", "blogName").toTypedArray()) + .build(), "comments" to - ModelAssociation.builder() - .name("HasMany") - .associatedName("post") - .associatedType("Post") - .build() + ModelAssociation.builder() + .name("HasMany") + .associatedName("post") + .associatedType("Post") + .build() ) ) diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilderTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilderTest.kt index 329076ce62..53b4538ab6 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilderTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPaginationBuilderTest.kt @@ -16,7 +16,8 @@ class QueryPaginationBuilderTest { Where.paginated(Page.startingAt(3).withLimit(200)).paginationInput, QueryPaginationBuilder.fromSerializedMap( readMapFromFile( - "query_pagination", "custom_page_and_limit.json", + "query_pagination", + "custom_page_and_limit.json", HashMap::class.java ) as HashMap ) @@ -29,7 +30,8 @@ class QueryPaginationBuilderTest { Where.paginated(Page.firstPage()).paginationInput, QueryPaginationBuilder.fromSerializedMap( readMapFromFile( - "query_pagination", "first_page.json", + "query_pagination", + "first_page.json", HashMap::class.java ) as HashMap ) @@ -42,7 +44,8 @@ class QueryPaginationBuilderTest { Where.paginated(Page.firstResult()).paginationInput, QueryPaginationBuilder.fromSerializedMap( readMapFromFile( - "query_pagination", "first_result.json", + "query_pagination", + "first_result.json", HashMap::class.java ) as HashMap ) diff --git a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilderTest.kt b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilderTest.kt index 81a655917b..d59e9002aa 100644 --- a/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilderTest.kt +++ b/packages/amplify_datastore/android/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/types/query/QueryPredicateBuilderTest.kt @@ -3,10 +3,10 @@ package com.amazonaws.amplify.amplify_datastore.types.query -import com.amazonaws.amplify.amplify_datastore.util.cast import com.amazonaws.amplify.amplify_datastore.cpkPostSchema import com.amazonaws.amplify.amplify_datastore.postSchema import com.amazonaws.amplify.amplify_datastore.readMapFromFile +import com.amazonaws.amplify.amplify_datastore.util.cast import com.amplifyframework.core.model.ModelIdentifier import com.amplifyframework.core.model.query.predicate.QueryField import com.amplifyframework.core.model.query.predicate.QueryPredicateGroup @@ -25,7 +25,7 @@ class QueryPredicateBuilderTest { private val inventoryName = QueryField.field("name") private val inventoryWarehouseID = QueryField.field("warehouseID") private val inventoryRegion = QueryField.field("region") - private val cpkBlogForeignKeyField = QueryField.field("Post","@@blogForeignKey") + private val cpkBlogForeignKeyField = QueryField.field("Post", "@@blogForeignKey") @Test fun test_when_id_not_equals() { @@ -33,7 +33,8 @@ class QueryPredicateBuilderTest { id.ne("123"), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "id_not_equals.json", + "query_predicate", + "id_not_equals.json", HashMap::class.java ).cast() ) @@ -167,7 +168,8 @@ class QueryPredicateBuilderTest { .and(inventoryRegion.eq("some region")), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "model_identifier_equals.json", + "query_predicate", + "model_identifier_equals.json", HashMap::class.java ).cast() ) @@ -183,7 +185,8 @@ class QueryPredicateBuilderTest { .and(inventoryRegion.ne("some region")), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "model_identifier_not_equals.json", + "query_predicate", + "model_identifier_not_equals.json", HashMap::class.java ).cast() ) @@ -201,7 +204,8 @@ class QueryPredicateBuilderTest { ), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "model_identifier_group_not_equals.json", + "query_predicate", + "model_identifier_group_not_equals.json", HashMap::class.java ).cast() ) @@ -215,11 +219,12 @@ class QueryPredicateBuilderTest { inventoryProductID.ne("product-id") .and(inventoryName.ne("product-name")) .and(inventoryWarehouseID.ne("warehouse-id")) - .and(inventoryRegion.ne("some region")), + .and(inventoryRegion.ne("some region")) ), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "model_identifier_group_equals.json", + "query_predicate", + "model_identifier_group_equals.json", HashMap::class.java ).cast() ) @@ -229,12 +234,16 @@ class QueryPredicateBuilderTest { @Test fun test_when_query_by_nested_model_identifier() { Assert.assertEquals( - cpkBlogForeignKeyField.eq(ModelIdentifier.Helper.getIdentifier( - "123", listOf("the parent") - )), + cpkBlogForeignKeyField.eq( + ModelIdentifier.Helper.getIdentifier( + "123", + listOf("the parent") + ) + ), QueryPredicateBuilder.fromSerializedMap( readMapFromFile( - "query_predicate", "query_by_nested_model_identifier.json", + "query_predicate", + "query_by_nested_model_identifier.json", HashMap::class.java ).cast(), cpkPostSchema diff --git a/packages/amplify_datastore/example/android/app/build.gradle b/packages/amplify_datastore/example/android/app/build.gradle index 1db33da315..aec60a4d81 100644 --- a/packages/amplify_datastore/example/android/app/build.gradle +++ b/packages/amplify_datastore/example/android/app/build.gradle @@ -27,18 +27,19 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { // TODO(dnys1): Replace with `flutter.compileSdkVersion` when bumping min Flutter version - compileSdkVersion 33 + namespace 'com.amazonaws.amplify.amplify_datastore_example' + compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/amplify_datastore/example/android/build.gradle b/packages/amplify_datastore/example/android/build.gradle index ce647a433b..070b4ffbfd 100644 --- a/packages/amplify_datastore/example/android/build.gradle +++ b/packages/amplify_datastore/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.9.10' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.4.2' + classpath 'com.android.tools.build:gradle:8.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/packages/amplify_datastore/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/amplify_datastore/example/android/gradle/wrapper/gradle-wrapper.properties index ceccc3a854..128177bf1b 100644 --- a/packages/amplify_datastore/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/amplify_datastore/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip diff --git a/packages/amplify_native_legacy_wrapper/android/build.gradle b/packages/amplify_native_legacy_wrapper/android/build.gradle index bded54fcad..56bdbb0b86 100644 --- a/packages/amplify_native_legacy_wrapper/android/build.gradle +++ b/packages/amplify_native_legacy_wrapper/android/build.gradle @@ -28,12 +28,12 @@ android { compileSdkVersion 31 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -41,7 +41,7 @@ android { } defaultConfig { - minSdkVersion 16 + minSdkVersion 24 } namespace 'com.amazonaws.amplify.amplify_native_legacy_wrapper' diff --git a/packages/amplify_native_legacy_wrapper/example/android/app/build.gradle b/packages/amplify_native_legacy_wrapper/example/android/app/build.gradle index c65642eac2..ce345269c6 100644 --- a/packages/amplify_native_legacy_wrapper/example/android/app/build.gradle +++ b/packages/amplify_native_legacy_wrapper/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/analytics/amplify_analytics_pinpoint/android/build.gradle b/packages/analytics/amplify_analytics_pinpoint/android/build.gradle index 5b91c490e9..bd95f41457 100644 --- a/packages/analytics/amplify_analytics_pinpoint/android/build.gradle +++ b/packages/analytics/amplify_analytics_pinpoint/android/build.gradle @@ -28,12 +28,12 @@ android { compileSdkVersion 33 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -41,7 +41,7 @@ android { } defaultConfig { - minSdkVersion 23 + minSdkVersion 24 } namespace 'com.amazonaws.amplify.amplify_analytics_pinpoint' diff --git a/packages/analytics/amplify_analytics_pinpoint/example/android/app/build.gradle b/packages/analytics/amplify_analytics_pinpoint/example/android/app/build.gradle index 987b594e90..c880d42fb8 100644 --- a/packages/analytics/amplify_analytics_pinpoint/example/android/app/build.gradle +++ b/packages/analytics/amplify_analytics_pinpoint/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/api/amplify_api/example/android/app/build.gradle b/packages/api/amplify_api/example/android/app/build.gradle index 2eeb79a95a..dc522262ba 100644 --- a/packages/api/amplify_api/example/android/app/build.gradle +++ b/packages/api/amplify_api/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/auth/amplify_auth_cognito/android/build.gradle b/packages/auth/amplify_auth_cognito/android/build.gradle index 4edb0f9845..05a473a4af 100644 --- a/packages/auth/amplify_auth_cognito/android/build.gradle +++ b/packages/auth/amplify_auth_cognito/android/build.gradle @@ -28,12 +28,12 @@ android { compileSdkVersion 33 compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '11' + jvmTarget = '17' } sourceSets { diff --git a/packages/auth/amplify_auth_cognito/example/android/app/build.gradle b/packages/auth/amplify_auth_cognito/example/android/app/build.gradle index 87229227fc..3b5a840f1d 100644 --- a/packages/auth/amplify_auth_cognito/example/android/app/build.gradle +++ b/packages/auth/amplify_auth_cognito/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/authenticator/amplify_authenticator/example/android/app/build.gradle b/packages/authenticator/amplify_authenticator/example/android/app/build.gradle index 700cb486dd..28f25e3a91 100644 --- a/packages/authenticator/amplify_authenticator/example/android/app/build.gradle +++ b/packages/authenticator/amplify_authenticator/example/android/app/build.gradle @@ -26,17 +26,16 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - // TODO(dnys1): Replace with `flutter.compileSdkVersion` when bumping min Flutter version - compileSdkVersion 33 + compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/authenticator/amplify_authenticator_test/example/android/app/build.gradle b/packages/authenticator/amplify_authenticator_test/example/android/app/build.gradle index da24017e07..74bfd747ed 100644 --- a/packages/authenticator/amplify_authenticator_test/example/android/app/build.gradle +++ b/packages/authenticator/amplify_authenticator_test/example/android/app/build.gradle @@ -28,12 +28,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/common/amplify_db_common/android/build.gradle b/packages/common/amplify_db_common/android/build.gradle index 20b8528620..62db495a94 100644 --- a/packages/common/amplify_db_common/android/build.gradle +++ b/packages/common/amplify_db_common/android/build.gradle @@ -28,12 +28,12 @@ android { compileSdkVersion 33 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -41,7 +41,7 @@ android { } defaultConfig { - minSdkVersion 19 + minSdkVersion 24 } namespace 'com.amazonaws.amplify.amplify_db_common' diff --git a/packages/common/amplify_db_common/example/android/app/build.gradle b/packages/common/amplify_db_common/example/android/app/build.gradle index 97f901e1bd..2a547c3235 100644 --- a/packages/common/amplify_db_common/example/android/app/build.gradle +++ b/packages/common/amplify_db_common/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/notifications/push/amplify_push_notifications/android/build.gradle b/packages/notifications/push/amplify_push_notifications/android/build.gradle index f93e2fd098..7b2d5bb67e 100644 --- a/packages/notifications/push/amplify_push_notifications/android/build.gradle +++ b/packages/notifications/push/amplify_push_notifications/android/build.gradle @@ -2,7 +2,7 @@ group 'com.amazonaws.amplify.amplify_push_notifications' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.9.10' repositories { google() mavenCentral() @@ -27,15 +27,15 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlinx-serialization' android { - compileSdkVersion 33 + compileSdk 34 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -65,7 +65,7 @@ android { dependencies { api "com.google.firebase:firebase-messaging:23.2.0" // Import support library for Amplify push utils - implementation 'com.amplifyframework:aws-push-notifications-pinpoint-common:2.13.0' + implementation 'com.amplifyframework:aws-push-notifications-pinpoint-common:2.15.0' implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1" implementation project(path: ':flutter_plugin_android_lifecycle') implementation 'androidx.test:core-ktx:1.5.0' diff --git a/packages/notifications/push/amplify_push_notifications/example/android/app/build.gradle b/packages/notifications/push/amplify_push_notifications/example/android/app/build.gradle index 4e00d7ee09..791a70a3ff 100644 --- a/packages/notifications/push/amplify_push_notifications/example/android/app/build.gradle +++ b/packages/notifications/push/amplify_push_notifications/example/android/app/build.gradle @@ -27,16 +27,16 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { namespace "com.amazonaws.amplify.amplify_push_notifications_example" - compileSdkVersion flutter.compileSdkVersion + compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/notifications/push/amplify_push_notifications/example/android/build.gradle b/packages/notifications/push/amplify_push_notifications/example/android/build.gradle index f7eb7f63ce..070b4ffbfd 100644 --- a/packages/notifications/push/amplify_push_notifications/example/android/build.gradle +++ b/packages/notifications/push/amplify_push_notifications/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.9.10' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:8.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/packages/notifications/push/amplify_push_notifications/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/notifications/push/amplify_push_notifications/example/android/gradle/wrapper/gradle-wrapper.properties index 3c472b99c6..ac72c34e8a 100644 --- a/packages/notifications/push/amplify_push_notifications/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/notifications/push/amplify_push_notifications/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/packages/notifications/push/amplify_push_notifications_pinpoint/example/android/app/build.gradle b/packages/notifications/push/amplify_push_notifications_pinpoint/example/android/app/build.gradle index 3c04f827c2..c9313b0cb4 100644 --- a/packages/notifications/push/amplify_push_notifications_pinpoint/example/android/app/build.gradle +++ b/packages/notifications/push/amplify_push_notifications_pinpoint/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/secure_storage/amplify_secure_storage/android/build.gradle b/packages/secure_storage/amplify_secure_storage/android/build.gradle index eaa91135d2..bbc002a658 100644 --- a/packages/secure_storage/amplify_secure_storage/android/build.gradle +++ b/packages/secure_storage/amplify_secure_storage/android/build.gradle @@ -28,12 +28,12 @@ android { compileSdkVersion 33 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -41,7 +41,7 @@ android { } defaultConfig { - minSdkVersion 23 + minSdkVersion 24 } testOptions.unitTests.includeAndroidResources = true diff --git a/packages/secure_storage/amplify_secure_storage/android/src/test/kotlin/com/amazonaws/amplify/amplify_secure_storage/EncryptedKeyValueRepositoryTest.kt b/packages/secure_storage/amplify_secure_storage/android/src/test/kotlin/com/amazonaws/amplify/amplify_secure_storage/EncryptedKeyValueRepositoryTest.kt index 24cc5a06ca..fd382bb1c3 100644 --- a/packages/secure_storage/amplify_secure_storage/android/src/test/kotlin/com/amazonaws/amplify/amplify_secure_storage/EncryptedKeyValueRepositoryTest.kt +++ b/packages/secure_storage/amplify_secure_storage/android/src/test/kotlin/com/amazonaws/amplify/amplify_secure_storage/EncryptedKeyValueRepositoryTest.kt @@ -16,7 +16,7 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) -@Config(manifest = Config.NONE, sdk = [23,33]) +@Config(manifest = Config.NONE, sdk = [24,33]) class EncryptedKeyValueRepositoryTest { private var context: Context = ApplicationProvider.getApplicationContext() diff --git a/packages/secure_storage/amplify_secure_storage/example/android/app/build.gradle b/packages/secure_storage/amplify_secure_storage/example/android/app/build.gradle index 85d8d9bc0b..5474dde175 100644 --- a/packages/secure_storage/amplify_secure_storage/example/android/app/build.gradle +++ b/packages/secure_storage/amplify_secure_storage/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { @@ -48,7 +48,7 @@ android { applicationId "com.amazonaws.amplify.amplify_secure_storage_example" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion 23 + minSdkVersion 24 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/packages/storage/amplify_storage_s3/example/android/app/build.gradle b/packages/storage/amplify_storage_s3/example/android/app/build.gradle index 8e166af4f0..57de3edc0c 100644 --- a/packages/storage/amplify_storage_s3/example/android/app/build.gradle +++ b/packages/storage/amplify_storage_s3/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/packages/worker_bee/e2e_flutter_test/android/app/build.gradle b/packages/worker_bee/e2e_flutter_test/android/app/build.gradle index 084c6fa419..b42dcd3911 100644 --- a/packages/worker_bee/e2e_flutter_test/android/app/build.gradle +++ b/packages/worker_bee/e2e_flutter_test/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets { diff --git a/templates/flutter-package/__brick__/example/android/app/build.gradle b/templates/flutter-package/__brick__/example/android/app/build.gradle index 48c8935148..b1343f02a5 100644 --- a/templates/flutter-package/__brick__/example/android/app/build.gradle +++ b/templates/flutter-package/__brick__/example/android/app/build.gradle @@ -31,12 +31,12 @@ android { ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } sourceSets {