diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000000..40512fda95 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,3 @@ +# Resolve SwiftLint errors and warnings +# https://github.com/aws-amplify/amplify-swift/pull/3451 +659e8615da059eea5b6a4ce1b77120eae293ebec \ No newline at end of file diff --git a/.github/workflows/notify_issue_comment.yml b/.github/workflows/notify_issue_comment.yml deleted file mode 100644 index b5b2990913..0000000000 --- a/.github/workflows/notify_issue_comment.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Notify Comments on Issues - -# Controls when the workflow will run -on: - # Triggers the workflow on comment events on pending response issues - issue_comment: - types: [created] - -# Limit the GITHUB_TOKEN permissions -permissions: {} - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "notify" - notify: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Exclude comments in PRs and comments made from maintainers - if: ${{ !github.event.issue.pull_request && !contains(fromJSON('["MEMBER", "OWNER"]'), github.event.comment.author_association) }} - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Runs a single command using the runners shell - - name: Run webhook curl command - env: - WEBHOOK_URL: ${{ secrets.SLACK_COMMENT_WEBHOOK_URL }} - COMMENT: ${{toJson(github.event.comment.body)}} - USER: ${{github.event.comment.user.login}} - COMMENT_URL: ${{github.event.comment.html_url}} - shell: bash - run: echo $COMMENT | sed "s/\\\n/. /g; s/\\\r//g; s/[^a-zA-Z0-9 &().,:]//g" | xargs -I {} curl -s POST "$WEBHOOK_URL" -H "Content-Type:application/json" --data '{"comment":"{}", "commentUrl":"'$COMMENT_URL'", "user":"'$USER'"}' diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.yml new file mode 100644 index 0000000000..51c2dd2262 --- /dev/null +++ b/.github/workflows/swiftlint.yml @@ -0,0 +1,46 @@ +name: SwiftLint +on: + workflow_dispatch: + workflow_call: + inputs: + identifier: + required: true + type: string + + push: + branches-ignore: + - main + - v1 + - release + - release-v1 + +permissions: + contents: read + +concurrency: + group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.ref_name != 'main'}} + +jobs: + run-swiftlint: + runs-on: ubuntu-latest + container: + image: ghcr.io/realm/swiftlint:0.54.0 + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 #v3.5.3 + with: + persist-credentials: false + + - name: SwiftLint + run: | + swiftlint --reporter github-actions-logging + + confirm-pass: + runs-on: ubuntu-latest + name: Confirm Passing SwiftLint + if: ${{ !cancelled() }} + needs: [ run-swiftlint ] + env: + EXIT_CODE: ${{ contains(needs.*.result, 'failure') && 1 || 0 }} + steps: + - run: exit $EXIT_CODE diff --git a/.swiftlint.yml b/.swiftlint.yml index a21fcd02f6..4f4f3d8bc7 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,10 +1,22 @@ # Do not specify an `included` section at this top-level file. Specify the # `--config` option pointing to this file, and the `--path` option to the files # you wish to lint +included: + - Amplify + - AmplifyPlugins excluded: - Pods - .build + - AmplifyAsyncTesting + - AmplifyFunctionalTests + - AmplifyTestApp + - AmplifyTestCommon + - AmplifyTests + - AmplifyPlugins/Core/AWSPluginsCoreTests + - AmplifyPlugins/Core/AWSPluginsTestCommon + - AmplifyPlugins/Notifications/Push/Tests + - AmplifyPlugins/*/Tests analyzer_rules: - unused_import @@ -18,10 +30,11 @@ closing_brace: error colon: severity: error comma: error -empty_count: warning +empty_count: + severity: warning empty_enum_arguments: error function_body_length: - warning: 100 + warning: 150 error: 150 identifier_name: excluded: @@ -29,11 +42,17 @@ identifier_name: - of - or line_length: - warning: 120 + ignores_urls: true + ignores_function_declarations: true + ignores_comments: true + warning: 160 error: 160 -opening_brace: error +opening_brace: + severity: error return_arrow_whitespace: error statement_position: severity: error todo: warning trailing_semicolon: error +non_optional_string_data_conversion: + severity: error \ No newline at end of file diff --git a/Amplify/Categories/API/APICategory.swift b/Amplify/Categories/API/APICategory.swift index d09ef87cb2..4725180daa 100644 --- a/Amplify/Categories/API/APICategory.swift +++ b/Amplify/Categories/API/APICategory.swift @@ -11,7 +11,7 @@ final public class APICategory: Category { public var categoryType: CategoryType { .api } - + var plugins = [PluginKey: APICategoryPlugin]() /// Returns the plugin added to the category, if only one plugin is added. Accessing this property if no plugins @@ -49,7 +49,7 @@ final public class APICategory: Category { public var isConfigured = false // MARK: - Plugin handling - + /// Adds `plugin` to the list of Plugins that implement functionality for this category. /// /// - Parameter plugin: The Plugin to add diff --git a/Amplify/Categories/API/ClientBehavior/APICategory+GraphQLBehavior.swift b/Amplify/Categories/API/ClientBehavior/APICategory+GraphQLBehavior.swift index 59d5614dd9..10510fc7e0 100644 --- a/Amplify/Categories/API/ClientBehavior/APICategory+GraphQLBehavior.swift +++ b/Amplify/Categories/API/ClientBehavior/APICategory+GraphQLBehavior.swift @@ -6,16 +6,16 @@ // extension APICategory: APICategoryGraphQLBehavior { - + // MARK: - Request-based GraphQL operations public func query(request: GraphQLRequest) async throws -> GraphQLTask.Success { try await plugin.query(request: request) } - + public func mutate(request: GraphQLRequest) async throws -> GraphQLTask.Success { try await plugin.mutate(request: request) } - + public func subscribe(request: GraphQLRequest) -> AmplifyAsyncThrowingSequence> { plugin.subscribe(request: request) } diff --git a/Amplify/Categories/API/ClientBehavior/APICategory+RESTBehavior.swift b/Amplify/Categories/API/ClientBehavior/APICategory+RESTBehavior.swift index e0e453f327..8daa59636d 100644 --- a/Amplify/Categories/API/ClientBehavior/APICategory+RESTBehavior.swift +++ b/Amplify/Categories/API/ClientBehavior/APICategory+RESTBehavior.swift @@ -8,7 +8,7 @@ import Foundation extension APICategory: APICategoryRESTBehavior { - + public func get(request: RESTRequest) async throws -> RESTTask.Success { try await plugin.get(request: request) } diff --git a/Amplify/Categories/API/ClientBehavior/APICategoryGraphQLBehavior.swift b/Amplify/Categories/API/ClientBehavior/APICategoryGraphQLBehavior.swift index 841c4e1681..d149b5d945 100644 --- a/Amplify/Categories/API/ClientBehavior/APICategoryGraphQLBehavior.swift +++ b/Amplify/Categories/API/ClientBehavior/APICategoryGraphQLBehavior.swift @@ -18,7 +18,7 @@ public protocol APICategoryGraphQLBehavior: AnyObject { /// - listener: The event listener for the operation /// - Returns: The AmplifyOperation being enqueued func query(request: GraphQLRequest) async throws -> GraphQLTask.Success - + /// Perform a GraphQL mutate operation against a previously configured API. This operation /// will be asynchronous, with the callback accessible both locally and via the Hub. /// @@ -36,5 +36,7 @@ public protocol APICategoryGraphQLBehavior: AnyObject { /// - valueListener: Invoked when the GraphQL subscription receives a new value from the service /// - completionListener: Invoked when the subscription has terminated /// - Returns: The AmplifyInProcessReportingOperation being enqueued - func subscribe(request: GraphQLRequest) -> AmplifyAsyncThrowingSequence> + func subscribe( + request: GraphQLRequest + ) -> AmplifyAsyncThrowingSequence> } diff --git a/Amplify/Categories/API/ClientBehavior/APICategoryRESTBehavior.swift b/Amplify/Categories/API/ClientBehavior/APICategoryRESTBehavior.swift index 8fafc4c52d..0a4c33c27e 100644 --- a/Amplify/Categories/API/ClientBehavior/APICategoryRESTBehavior.swift +++ b/Amplify/Categories/API/ClientBehavior/APICategoryRESTBehavior.swift @@ -27,13 +27,13 @@ public protocol APICategoryRESTBehavior { /// - Parameter request: Contains information such as path, query parameters, body. /// - Returns: An operation that can be observed for its value func post(request: RESTRequest) async throws -> RESTTask.Success - + /// Perform an HTTP DELETE operation /// /// - Parameter request: Contains information such as path, query parameters, body. /// - Returns: An operation that can be observed for its value func delete(request: RESTRequest) async throws -> RESTTask.Success - + /// Perform an HTTP HEAD operation /// /// - Parameter request: Contains information such as path, query parameters, body. diff --git a/Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift b/Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift index 7b4b36ef59..ed2a6e2753 100644 --- a/Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift +++ b/Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift @@ -116,7 +116,7 @@ public final class RetryableGraphQLOperation: Operation, Ret self.operationFactory = operationFactory self.resultListener = resultListener } - + public override func main() { Task { start(request: await requestFactory()) diff --git a/Amplify/Categories/Analytics/AnalyticsCategory+ClientBehavior.swift b/Amplify/Categories/Analytics/AnalyticsCategory+ClientBehavior.swift index 796b3865a5..e73abe1c15 100644 --- a/Amplify/Categories/Analytics/AnalyticsCategory+ClientBehavior.swift +++ b/Amplify/Categories/Analytics/AnalyticsCategory+ClientBehavior.swift @@ -50,7 +50,7 @@ extension AnalyticsCategory { public func unregisterGlobalProperties(_ keys: String...) { plugin.unregisterGlobalProperties(keys.isEmpty ? nil : Set(keys)) } - + /// Registered global properties can be unregistered though this method. In case no keys are provided, *all* /// registered global properties will be unregistered. Duplicate keys will be ignored. This method can be called /// from `Amplify.Analytics` and is a wrapper for `unregisterGlobalProperties(_ keys: Set? = nil)` diff --git a/Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift b/Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift index dfd92b9e92..8896be20ea 100644 --- a/Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift +++ b/Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift @@ -9,7 +9,11 @@ import Foundation extension AuthCategory: AuthCategoryBehavior { - public func signUp( username: String, password: String? = nil, options: AuthSignUpRequest.Options? = nil) async throws -> AuthSignUpResult { + public func signUp( + username: String, + password: String? = nil, + options: AuthSignUpRequest.Options? = nil + ) async throws -> AuthSignUpResult { return try await plugin.signUp(username: username, password: password, options: options) } @@ -19,7 +23,10 @@ extension AuthCategory: AuthCategoryBehavior { return try await plugin.confirmSignUp(for: username, confirmationCode: confirmationCode, options: options) } - public func resendSignUpCode(for username: String, options: AuthResendSignUpCodeRequest.Options? = nil) async throws -> AuthCodeDeliveryDetails { + public func resendSignUpCode( + for username: String, + options: AuthResendSignUpCodeRequest.Options? = nil + ) async throws -> AuthCodeDeliveryDetails { return try await plugin.resendSignUpCode(for: username, options: options) } @@ -46,14 +53,17 @@ extension AuthCategory: AuthCategoryBehavior { } #endif - public func confirmSignIn(challengeResponse: String, options: AuthConfirmSignInRequest.Options? = nil) async throws -> AuthSignInResult { + public func confirmSignIn( + challengeResponse: String, + options: AuthConfirmSignInRequest.Options? = nil + ) async throws -> AuthSignInResult { return try await plugin.confirmSignIn(challengeResponse: challengeResponse, options: options) } public func signOut(options: AuthSignOutRequest.Options? = nil) async -> AuthSignOutResult { return await plugin.signOut(options: options) } - + public func deleteUser() async throws { try await plugin.deleteUser() } @@ -62,8 +72,11 @@ extension AuthCategory: AuthCategoryBehavior { return try await plugin.fetchAuthSession(options: options) } - public func resetPassword(for username: String, options: AuthResetPasswordRequest.Options? = nil) async throws -> AuthResetPasswordResult { - return try await plugin.resetPassword(for: username,options: options) + public func resetPassword( + for username: String, + options: AuthResetPasswordRequest.Options? = nil + ) async throws -> AuthResetPasswordResult { + return try await plugin.resetPassword(for: username, options: options) } public func confirmResetPassword( @@ -72,7 +85,12 @@ extension AuthCategory: AuthCategoryBehavior { confirmationCode: String, options: AuthConfirmResetPasswordRequest.Options? = nil ) async throws { - try await plugin.confirmResetPassword(for: username, with: newPassword, confirmationCode: confirmationCode, options: options) + try await plugin.confirmResetPassword( + for: username, + with: newPassword, + confirmationCode: confirmationCode, + options: options + ) } public func setUpTOTP() async throws -> TOTPSetupDetails { diff --git a/Amplify/Categories/Auth/AuthCategory+DeviceBehavior.swift b/Amplify/Categories/Auth/AuthCategory+DeviceBehavior.swift index 104fb56a6f..a9da3b0099 100644 --- a/Amplify/Categories/Auth/AuthCategory+DeviceBehavior.swift +++ b/Amplify/Categories/Auth/AuthCategory+DeviceBehavior.swift @@ -9,11 +9,16 @@ import Foundation extension AuthCategory: AuthCategoryDeviceBehavior { - public func fetchDevices( options: AuthFetchDevicesRequest.Options? = nil) async throws -> [AuthDevice] { + public func fetchDevices( + options: AuthFetchDevicesRequest.Options? = nil + ) async throws -> [AuthDevice] { return try await plugin.fetchDevices(options: options) } - public func forgetDevice( _ device: AuthDevice? = nil, options: AuthForgetDeviceRequest.Options? = nil) async throws { + public func forgetDevice( + _ device: AuthDevice? = nil, + options: AuthForgetDeviceRequest.Options? = nil + ) async throws { try await plugin.forgetDevice(device, options: options) } diff --git a/Amplify/Categories/Auth/AuthCategory+UserBehavior.swift b/Amplify/Categories/Auth/AuthCategory+UserBehavior.swift index 5c3fc21076..6589e03083 100644 --- a/Amplify/Categories/Auth/AuthCategory+UserBehavior.swift +++ b/Amplify/Categories/Auth/AuthCategory+UserBehavior.swift @@ -13,11 +13,16 @@ extension AuthCategory: AuthCategoryUserBehavior { try await plugin.getCurrentUser() } - public func fetchUserAttributes(options: AuthFetchUserAttributesRequest.Options? = nil) async throws -> [AuthUserAttribute] { + public func fetchUserAttributes( + options: AuthFetchUserAttributesRequest.Options? = nil + ) async throws -> [AuthUserAttribute] { try await plugin.fetchUserAttributes(options: options) } - public func update(userAttribute: AuthUserAttribute, options: AuthUpdateUserAttributeRequest.Options? = nil) async throws -> AuthUpdateAttributeResult { + public func update( + userAttribute: AuthUserAttribute, + options: AuthUpdateUserAttributeRequest.Options? = nil + ) async throws -> AuthUpdateAttributeResult { try await plugin.update(userAttribute: userAttribute, options: options) } @@ -45,10 +50,18 @@ extension AuthCategory: AuthCategoryUserBehavior { public func confirm(userAttribute: AuthUserAttributeKey, confirmationCode: String, options: AuthConfirmUserAttributeRequest.Options? = nil) async throws { - try await plugin.confirm(userAttribute: userAttribute, confirmationCode: confirmationCode, options: options) + try await plugin.confirm( + userAttribute: userAttribute, + confirmationCode: confirmationCode, + options: options + ) } - public func update(oldPassword: String, to newPassword: String, options: AuthChangePasswordRequest.Options? = nil) async throws { + public func update( + oldPassword: String, + to newPassword: String, + options: AuthChangePasswordRequest.Options? = nil + ) async throws { try await plugin.update(oldPassword: oldPassword, to: newPassword, options: options) } diff --git a/Amplify/Categories/Auth/AuthCategoryBehavior.swift b/Amplify/Categories/Auth/AuthCategoryBehavior.swift index dd42213863..68f6cc2f7f 100644 --- a/Amplify/Categories/Auth/AuthCategoryBehavior.swift +++ b/Amplify/Categories/Auth/AuthCategoryBehavior.swift @@ -24,7 +24,11 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi /// - username: username to signUp /// - password: password as per the password policy of the provider /// - options: Parameters specific to plugin behavior - func signUp(username: String, password: String?, options: AuthSignUpRequest.Options?) async throws -> AuthSignUpResult + func signUp( + username: String, + password: String?, + options: AuthSignUpRequest.Options? + ) async throws -> AuthSignUpResult /// Confirms the `signUp` operation. /// @@ -44,7 +48,10 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi /// - Parameters: /// - username: Username of the user to be confirmed. /// - options: Parameters specific to plugin behavior. - func resendSignUpCode(for username: String, options: AuthResendSignUpCodeRequest.Options?) async throws -> AuthCodeDeliveryDetails + func resendSignUpCode( + for username: String, + options: AuthResendSignUpCodeRequest.Options? + ) async throws -> AuthCodeDeliveryDetails /// SignIn to the authentication provider /// @@ -90,7 +97,10 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi /// - Parameters: /// - challengeResponse: Challenge response required to confirm the next step in signIn flow /// - options: Parameters specific to plugin behavior. - func confirmSignIn(challengeResponse: String, options: AuthConfirmSignInRequest.Options?) async throws -> AuthSignInResult + func confirmSignIn( + challengeResponse: String, + options: AuthConfirmSignInRequest.Options? + ) async throws -> AuthSignInResult /// Sign out the currently logged-in user. /// @@ -122,12 +132,18 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi /// - newPassword: new password for the user /// - confirmationCode: Received confirmation code /// - options: Parameters specific to plugin behavior - func confirmResetPassword(for username: String, with newPassword: String, confirmationCode: String, options: AuthConfirmResetPasswordRequest.Options?) async throws + func confirmResetPassword( + for username: String, + with newPassword: String, + confirmationCode: String, + options: AuthConfirmResetPasswordRequest.Options? + ) async throws /// Initiates TOTP Setup /// /// Invoke this operation to setup TOTP for the user while signed in. - /// Calling this method will initiate TOTP setup process and returns a shared secret that can be used to generate QR code. + /// Calling this method will initiate TOTP setup process and + /// returns a shared secret that can be used to generate QR code. /// The setup details also contains a URI generator helper that can be used to retireve a TOTP Setup URI. /// func setUpTOTP() async throws -> TOTPSetupDetails @@ -135,7 +151,8 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi /// Verifies TOTP Setup /// /// Invoke this operation to verify TOTP setup for the user while signed in. - /// Calling this method with the verification code from the associated Authenticator app will complete the TOTP setup process. + /// Calling this method with the verification code from the associated Authenticator app + /// will complete the TOTP setup process. /// /// - Parameters: /// - code: verification code from the associated Authenticator app diff --git a/Amplify/Categories/Auth/AuthCategoryUserBehavior.swift b/Amplify/Categories/Auth/AuthCategoryUserBehavior.swift index f3917109c7..ad9d106eaf 100644 --- a/Amplify/Categories/Auth/AuthCategoryUserBehavior.swift +++ b/Amplify/Categories/Auth/AuthCategoryUserBehavior.swift @@ -17,22 +17,29 @@ public protocol AuthCategoryUserBehavior: AnyObject { /// /// - Parameters: /// - options: Parameters specific to plugin behavior - func fetchUserAttributes(options: AuthFetchUserAttributesRequest.Options?) async throws -> [AuthUserAttribute] + func fetchUserAttributes( + options: AuthFetchUserAttributesRequest.Options? + ) async throws -> [AuthUserAttribute] /// Update user attribute for the current user /// /// - Parameters: /// - userAttribute: Attribute that need to be updated /// - options: Parameters specific to plugin behavior - func update(userAttribute: AuthUserAttribute, options: AuthUpdateUserAttributeRequest.Options?) async throws -> AuthUpdateAttributeResult + func update( + userAttribute: AuthUserAttribute, + options: AuthUpdateUserAttributeRequest.Options? + ) async throws -> AuthUpdateAttributeResult /// Update a list of user attributes for the current user /// /// - Parameters: /// - userAttributes: List of attribtues that need ot be updated /// - options: Parameters specific to plugin behavior - func update(userAttributes: [AuthUserAttribute], - options: AuthUpdateUserAttributesRequest.Options?) async throws -> [AuthUserAttributeKey: AuthUpdateAttributeResult] + func update( + userAttributes: [AuthUserAttribute], + options: AuthUpdateUserAttributesRequest.Options? + ) async throws -> [AuthUserAttributeKey: AuthUpdateAttributeResult] /// Resends the confirmation code required to verify an attribute /// @@ -61,7 +68,11 @@ public protocol AuthCategoryUserBehavior: AnyObject { /// - userAttribute: Attribute to verify /// - confirmationCode: Confirmation code received /// - options: Parameters specific to plugin behavior - func confirm(userAttribute: AuthUserAttributeKey, confirmationCode: String, options: AuthConfirmUserAttributeRequest.Options?) async throws + func confirm( + userAttribute: AuthUserAttributeKey, + confirmationCode: String, + options: AuthConfirmUserAttributeRequest.Options? + ) async throws /// Update the current logged in user's password /// @@ -70,5 +81,9 @@ public protocol AuthCategoryUserBehavior: AnyObject { /// - oldPassword: Current password of the user /// - newPassword: New password to be updated /// - options: Parameters specific to plugin behavior - func update(oldPassword: String, to newPassword: String, options: AuthChangePasswordRequest.Options?) async throws + func update( + oldPassword: String, + to newPassword: String, + options: AuthChangePasswordRequest.Options? + ) async throws } diff --git a/Amplify/Categories/Auth/Models/AuthUserAttribute.swift b/Amplify/Categories/Auth/Models/AuthUserAttribute.swift index 01d77b6308..7990ffe276 100644 --- a/Amplify/Categories/Auth/Models/AuthUserAttribute.swift +++ b/Amplify/Categories/Auth/Models/AuthUserAttribute.swift @@ -28,7 +28,7 @@ public enum AuthUserAttributeKey { /// Attribute key for user's email case email - + /// Attribute key for user's email verfication status case emailVerified @@ -55,7 +55,7 @@ public enum AuthUserAttributeKey { /// Attribute key for user's phone number case phoneNumber - + /// Attribute key for user's phone number verficiation status case phoneNumberVerified @@ -64,19 +64,19 @@ public enum AuthUserAttributeKey { /// Attribute key for user's preferred user name case preferredUsername - + /// Attribute key for user's profile case profile - + /// Attribute key for user's identifier case sub - + /// Attribute key for time of user's information last updated case updatedAt - + /// Attribute key for user's web page case website - + /// Attribute key for user's time zone case zoneInfo @@ -90,4 +90,3 @@ public enum AuthUserAttributeKey { extension AuthUserAttributeKey: Hashable {} extension AuthUserAttributeKey: Equatable {} - diff --git a/Amplify/Categories/Auth/Models/DeliveryDestination.swift b/Amplify/Categories/Auth/Models/DeliveryDestination.swift index defa40d415..17a417d8ec 100644 --- a/Amplify/Categories/Auth/Models/DeliveryDestination.swift +++ b/Amplify/Categories/Auth/Models/DeliveryDestination.swift @@ -24,4 +24,3 @@ public enum DeliveryDestination { } extension DeliveryDestination: Equatable { } - diff --git a/Amplify/Categories/Auth/Request/AuthFetchSessionRequest.swift b/Amplify/Categories/Auth/Request/AuthFetchSessionRequest.swift index da8bbd1e7b..debdb449e4 100644 --- a/Amplify/Categories/Auth/Request/AuthFetchSessionRequest.swift +++ b/Amplify/Categories/Auth/Request/AuthFetchSessionRequest.swift @@ -47,4 +47,3 @@ extension AuthFetchSessionRequest.Options { return AuthFetchSessionRequest.Options(forceRefresh: true) } } - diff --git a/Amplify/Categories/Auth/Request/AuthSignOutRequest.swift b/Amplify/Categories/Auth/Request/AuthSignOutRequest.swift index df1ca20da8..4d7e12093f 100644 --- a/Amplify/Categories/Auth/Request/AuthSignOutRequest.swift +++ b/Amplify/Categories/Auth/Request/AuthSignOutRequest.swift @@ -52,7 +52,6 @@ public extension AuthSignOutRequest { #endif } - } #if os(iOS) || os(macOS) diff --git a/Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift b/Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift index 1852dc2564..f320daff43 100644 --- a/Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift +++ b/Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift @@ -21,7 +21,7 @@ public struct AuthWebUISignInRequest: AmplifyOperationRequest { /// Presentation anchor on which the webUI is displayed public let presentationAnchor: AuthUIPresentationAnchor? - + public init(presentationAnchor: AuthUIPresentationAnchor?, authProvider: AuthProvider? = nil, options: Options) { @@ -37,7 +37,7 @@ public extension AuthWebUISignInRequest { /// Scopes to be defined for the sign in user public let scopes: [String]? - + /// Extra plugin specific options, only used in special circumstances when the existing options do not provide /// a way to utilize the underlying auth plugin functionality. See plugin documentation for expected /// key/values diff --git a/Amplify/Categories/DataStore/DataStoreCategory+Behavior.swift b/Amplify/Categories/DataStore/DataStoreCategory+Behavior.swift index ed400245f0..4d15a9bff1 100644 --- a/Amplify/Categories/DataStore/DataStoreCategory+Behavior.swift +++ b/Amplify/Categories/DataStore/DataStoreCategory+Behavior.swift @@ -17,7 +17,7 @@ extension DataStoreCategory: DataStoreBaseBehavior { byId id: String) async throws -> M? { try await plugin.query(modelType, byId: id) } - + public func query(_ modelType: M.Type, byIdentifier id: String) async throws -> M? where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default { @@ -41,13 +41,13 @@ extension DataStoreCategory: DataStoreBaseBehavior { where predicate: QueryPredicate? = nil) async throws { try await plugin.delete(model, where: predicate) } - + public func delete(_ modelType: M.Type, withId id: String, where predicate: QueryPredicate? = nil) async throws { try await plugin.delete(modelType, withId: id, where: predicate) } - + public func delete(_ modelType: M.Type, withIdentifier id: String, where predicate: QueryPredicate? = nil) async throws @@ -60,7 +60,7 @@ extension DataStoreCategory: DataStoreBaseBehavior { where predicate: QueryPredicate? = nil) async throws where M: ModelIdentifiable { try await plugin.delete(modelType, withIdentifier: id, where: predicate) } - + public func delete(_ modelType: M.Type, where predicate: QueryPredicate) async throws { try await plugin.delete(modelType, where: predicate) diff --git a/Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift b/Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift index d6de0186f7..43aa4d3892 100644 --- a/Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift +++ b/Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift @@ -39,7 +39,7 @@ public protocol DataStoreBaseBehavior { func delete(_ modelType: M.Type, withId id: String, where predicate: QueryPredicate?) async throws - + func delete(_ modelType: M.Type, withIdentifier id: String, where predicate: QueryPredicate?) async throws where M: ModelIdentifiable, @@ -82,7 +82,7 @@ public protocol DataStoreSubscribeBehavior { /// Returns an AmplifyAsyncThrowingSequence for model changes (create, updates, delete) /// - Parameter modelType: The model type to observe func observe(_ modelType: M.Type) -> AmplifyAsyncThrowingSequence - + /// Returns a Publisher for query snapshots. /// /// - Parameters: diff --git a/Amplify/Categories/DataStore/Model/Internal/ModelListProvider.swift b/Amplify/Categories/DataStore/Model/Internal/ModelListProvider.swift index 9b593b04e0..582d9bdc1c 100644 --- a/Amplify/Categories/DataStore/Model/Internal/ModelListProvider.swift +++ b/Amplify/Categories/DataStore/Model/Internal/ModelListProvider.swift @@ -40,7 +40,7 @@ public protocol ModelListProvider { associatedtype Element: Model func getState() -> ModelListProviderState - + /// Retrieve the array of `Element` from the data source asychronously. func load() async throws -> [Element] @@ -52,7 +52,7 @@ public protocol ModelListProvider { /// Asynchronously retrieve the next page as a new in-memory List object. Returns a failure if there /// is no next page of results. You can validate whether the list has another page with `hasNextPage()`. func getNextPage() async throws -> List - + /// Custom encoder func encode(to encoder: Encoder) throws } @@ -67,7 +67,7 @@ public struct AnyModelListProvider: ModelListProvider { private let hasNextPageClosure: () -> Bool private let getNextPageAsync: () async throws -> List private let encodeClosure: (Encoder) throws -> Void - + public init( provider: Provider ) where Provider.Element == Self.Element { @@ -81,7 +81,7 @@ public struct AnyModelListProvider: ModelListProvider { public func getState() -> ModelListProviderState { getStateClosure() } - + public func load() async throws -> [Element] { try await loadAsync() } @@ -93,7 +93,7 @@ public struct AnyModelListProvider: ModelListProvider { public func getNextPage() async throws -> List { try await getNextPageAsync() } - + public func encode(to encoder: Encoder) throws { try encodeClosure(encoder) } diff --git a/Amplify/Categories/DataStore/Model/Internal/ModelProvider.swift b/Amplify/Categories/DataStore/Model/Internal/ModelProvider.swift index 2f61c3c562..98c93dfa00 100644 --- a/Amplify/Categories/DataStore/Model/Internal/ModelProvider.swift +++ b/Amplify/Categories/DataStore/Model/Internal/ModelProvider.swift @@ -6,7 +6,7 @@ // import Foundation - +// swiftlint:disable type_name /// Protocol used as a marker to detect when the type is a `LazyReference`. /// Used to retrieve either the `reference` or the `identifiers` of the Model directly, without having load a not /// loaded LazyReference. This is useful when translating the model object over to the payload required for the @@ -18,13 +18,14 @@ import Foundation /// application making any change to these `public` types should be backward compatible, otherwise it will be a breaking /// change. public protocol _LazyReferenceValue { - var _state: _LazyReferenceValueState { get } + var _state: _LazyReferenceValueState { get } // swiftlint:disable:this identifier_name } public enum _LazyReferenceValueState { case notLoaded(identifiers: [LazyReferenceIdentifier]?) case loaded(model: Model?) } +// swiftlint:enable type_name /// State of the ModelProvider /// @@ -43,11 +44,11 @@ public enum ModelProviderState { /// change. public protocol ModelProvider { associatedtype Element: Model - + func load() async throws -> Element? - + func getState() -> ModelProviderState - + func encode(to encoder: Encoder) throws } @@ -56,25 +57,25 @@ public protocol ModelProvider { /// application making any change to these `public` types should be backward compatible, otherwise it will be a breaking /// change. public struct AnyModelProvider: ModelProvider { - + private let loadAsync: () async throws -> Element? private let getStateClosure: () -> ModelProviderState private let encodeClosure: (Encoder) throws -> Void - + public init(provider: Provider) where Provider.Element == Self.Element { self.loadAsync = provider.load self.getStateClosure = provider.getState self.encodeClosure = provider.encode } - + public func load() async throws -> Element? { try await loadAsync() } - + public func getState() -> ModelProviderState { getStateClosure() } - + public func encode(to encoder: Encoder) throws { try encodeClosure(encoder) } diff --git a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelField+Association.swift b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelField+Association.swift index b3d85be2d5..6dfafe2c1b 100644 --- a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelField+Association.swift +++ b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelField+Association.swift @@ -98,8 +98,14 @@ public enum ModelAssociation { return .belongsTo(associatedFieldName: nil, targetNames: targetNames) } - public static func hasMany(associatedWith: CodingKey? = nil, associatedFields: [CodingKey] = []) -> ModelAssociation { - return .hasMany(associatedFieldName: associatedWith?.stringValue, associatedFieldNames: associatedFields.map { $0.stringValue }) + public static func hasMany( + associatedWith: CodingKey? = nil, + associatedFields: [CodingKey] = [] + ) -> ModelAssociation { + return .hasMany( + associatedFieldName: associatedWith?.stringValue, + associatedFieldNames: associatedFields.map { $0.stringValue } + ) } @available(*, deprecated, message: "Use hasOne(associatedWith:targetNames:)") @@ -230,7 +236,7 @@ extension ModelField { /// directly by host applications. The behavior of this may change without warning. Though it is not used by host /// application making any change to these `public` types should be backward compatible, otherwise it will be a /// breaking change. - public var _isBelongsToOrHasOne: Bool { + public var _isBelongsToOrHasOne: Bool { // swiftlint:disable:this identifier_name switch association { case .belongsTo, .hasOne: return true diff --git a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Identifiers.swift b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Identifiers.swift index 2e01b9b12f..a627525ba9 100644 --- a/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Identifiers.swift +++ b/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema+Identifiers.swift @@ -12,12 +12,12 @@ extension ModelSchema { enum ExtractionError: Error { case unsupportedLazyReferenceIdentifier(name: String, value: JSONValue?) } - + var identifiers = [LazyReferenceIdentifier]() for identifierField in primaryKey.fields { let object = modelObject[identifierField.name] - + switch object { case .string(let identifierValue): identifiers.append(.init(name: identifierField.name, value: identifierValue)) @@ -28,7 +28,7 @@ extension ModelSchema { ) } } - + return identifiers } } diff --git a/Amplify/Categories/DataStore/Model/Lazy/ArrayLiteralListProvider.swift b/Amplify/Categories/DataStore/Model/Lazy/ArrayLiteralListProvider.swift index 7aafd0b49a..7c8e128853 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/ArrayLiteralListProvider.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/ArrayLiteralListProvider.swift @@ -8,16 +8,16 @@ import Foundation public struct ArrayLiteralListProvider: ModelListProvider { - + let elements: [Element] public init(elements: [Element]) { self.elements = elements } - + public func getState() -> ModelListProviderState { return .loaded(elements) } - + public func load() -> Result<[Element], CoreError> { .success(elements) } @@ -25,7 +25,7 @@ public struct ArrayLiteralListProvider: ModelListProvider { public func load(completion: @escaping (Result<[Element], CoreError>) -> Void) { completion(.success(elements)) } - + public func load() async throws -> [Element] { return elements } @@ -39,13 +39,13 @@ public struct ArrayLiteralListProvider: ModelListProvider { "Don't call this method", nil))) } - + public func getNextPage() async throws -> List { throw CoreError.clientValidation("No pagination on an array literal", "Don't call this method", nil) } - + public func encode(to encoder: Encoder) throws { try elements.encode(to: encoder) } diff --git a/Amplify/Categories/DataStore/Model/Lazy/DefaultModelProvider.swift b/Amplify/Categories/DataStore/Model/Lazy/DefaultModelProvider.swift index 8eb7b22a74..24dca4f26a 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/DefaultModelProvider.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/DefaultModelProvider.swift @@ -10,17 +10,17 @@ import Foundation // MARK: - DefaultModelProvider public struct DefaultModelProvider: ModelProvider { - + var loadedState: ModelProviderState - + public init(element: Element? = nil) { self.loadedState = .loaded(model: element) } - + public init(identifiers: [LazyReferenceIdentifier]?) { self.loadedState = .notLoaded(identifiers: identifiers) } - + public func load() async throws -> Element? { switch loadedState { case .notLoaded: @@ -29,11 +29,11 @@ public struct DefaultModelProvider: ModelProvider { return model } } - + public func getState() -> ModelProviderState { loadedState } - + public func encode(to encoder: Encoder) throws { switch loadedState { case .notLoaded(let identifiers): diff --git a/Amplify/Categories/DataStore/Model/Lazy/LazyReference.swift b/Amplify/Categories/DataStore/Model/Lazy/LazyReference.swift index 9799282fcd..343b059225 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/LazyReference.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/LazyReference.swift @@ -13,7 +13,7 @@ import Combine public struct LazyReferenceIdentifier: Codable { public let name: String public let value: String - + public init(name: String, value: String) { self.name = name self.value = value @@ -34,21 +34,22 @@ struct LazyReferenceModelIdentifier: ModelIdentifierProtocol { var fields: [(name: String, value: Persistable)] } +// swiftlint: disable identifier_name /// This class represents a lazy reference to a `Model`, meaning that the reference /// may or may not exist at instantiation time. /// /// The default implementation `DefaultModelProvider` only handles in-memory data, therefore `get()` and /// `require()` will simply return the current `reference`. public class LazyReference: Codable, _LazyReferenceValue { - + /// Represents the data state of the `LazyModel`. enum LoadedState { case notLoaded(identifiers: [LazyReferenceIdentifier]?) case loaded(ModelType?) } - + var loadedState: LoadedState - + @_spi(LazyReference) public var _state: _LazyReferenceValueState { switch loadedState { @@ -58,10 +59,10 @@ public class LazyReference: Codable, _LazyReferenceValue { return .loaded(model: model) } } - + /// The provider for fulfilling list behaviors let modelProvider: AnyModelProvider - + public init(modelProvider: AnyModelProvider) { self.modelProvider = modelProvider switch self.modelProvider.getState() { @@ -71,21 +72,21 @@ public class LazyReference: Codable, _LazyReferenceValue { self.loadedState = .notLoaded(identifiers: identifiers) } } - + // MARK: - Initializers - + public convenience init(_ reference: ModelType?) { let modelProvider = DefaultModelProvider(element: reference).eraseToAnyModelProvider() self.init(modelProvider: modelProvider) } - + public convenience init(identifiers: [LazyReferenceIdentifier]?) { let modelProvider = DefaultModelProvider(identifiers: identifiers).eraseToAnyModelProvider() self.init(modelProvider: modelProvider) } - + // MARK: - Codable implementation - + /// Decodable implementation is delegated to the ModelProviders. required convenience public init(from decoder: Decoder) throws { for modelDecoder in ModelProviderRegistry.decoders.get() { @@ -100,8 +101,7 @@ public class LazyReference: Codable, _LazyReferenceValue { if let element = try? ModelType(from: decoder) { self.init(element) return - } - else { + } else { let identifiers = try ModelType.schema.lazyReferenceIdentifiers(from: object) self.init(identifiers: identifiers) return @@ -111,14 +111,14 @@ public class LazyReference: Codable, _LazyReferenceValue { } self.init(identifiers: nil) } - + /// Encodable implementation is delegated to the underlying ModelProviders. public func encode(to encoder: Encoder) throws { try modelProvider.encode(to: encoder) } - + // MARK: - APIs - + /// This function is responsible for retrieving the model reference. In the default /// implementation this means simply returning the existing `reference`, but different /// storage mechanisms can implement their own logic to fetch data, @@ -135,7 +135,7 @@ public class LazyReference: Codable, _LazyReferenceValue { return element } } - + /// The equivalent of `get()` but aimed to retrieve references that are considered /// non-optional. However, referential integrity issues and/or availability constraints /// might affect how required data is fetched. In such scenarios the implementation diff --git a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift index aee10e9e53..283cc53ff7 100644 --- a/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift +++ b/Amplify/Categories/DataStore/Model/Lazy/List+Model.swift @@ -26,13 +26,13 @@ public class List: Collection, Codable, ExpressibleByArrayLite /// The current state of lazily loaded list var loadedState: LoadedState - + /// Boolean property to check if list is loaded public var isLoaded: Bool { if case .loaded = loadedState { return true } - + return false } @@ -70,7 +70,6 @@ public class List: Collection, Codable, ExpressibleByArrayLite } } - // MARK: - Initializers public init(listProvider: AnyModelListProvider) { diff --git a/Amplify/Categories/DataStore/Model/PropertyPath.swift b/Amplify/Categories/DataStore/Model/PropertyPath.swift index 93c24d41c9..212430f56d 100644 --- a/Amplify/Categories/DataStore/Model/PropertyPath.swift +++ b/Amplify/Categories/DataStore/Model/PropertyPath.swift @@ -32,7 +32,7 @@ public protocol PropertyPath { /// i.e. a `struct` representing another `Model`. /// /// - SeeAlso: `ModelPath` -public protocol PropertyContainerPath : PropertyPath { +public protocol PropertyContainerPath: PropertyPath { /// func getKeyPath() -> String @@ -43,7 +43,7 @@ public protocol PropertyContainerPath : PropertyPath { } extension PropertyContainerPath { - + public func getKeyPath() -> String { var metadata = getMetadata() var path = [String]() @@ -80,7 +80,7 @@ public struct FieldPath: PropertyPath { /// var blog: ModelPath { BlogModelPath(name: "blog", parent: self) } /// } /// ``` -open class ModelPath : PropertyContainerPath { +open class ModelPath: PropertyContainerPath { private let metadata: PropertyPathMetadata @@ -123,11 +123,11 @@ open class ModelPath : PropertyContainerPath { public func time(_ name: String) -> FieldPath { FieldPath(name: name, parent: self) } - + public func int(_ name: String) -> FieldPath { FieldPath(name: name, parent: self) } - + public func double(_ name: String) -> FieldPath { FieldPath(name: name, parent: self) } diff --git a/Amplify/Categories/DataStore/Model/Temporal/TimeZone+Extension.swift b/Amplify/Categories/DataStore/Model/Temporal/TimeZone+Extension.swift index 9907557f32..efbbbfb673 100644 --- a/Amplify/Categories/DataStore/Model/Temporal/TimeZone+Extension.swift +++ b/Amplify/Categories/DataStore/Model/Temporal/TimeZone+Extension.swift @@ -5,7 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 // - import Foundation extension TimeZone { @@ -31,7 +30,7 @@ extension TimeZone { } } - +// swiftlint:disable identifier_name /// ISO8601 Time Zone formats /// - Note: /// `±hh:mm:ss` is not a standard of ISO8601 date formate. It's supported by `AWSDateTime` exclusively. @@ -39,7 +38,7 @@ extension TimeZone { /// references: /// https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators /// https://docs.aws.amazon.com/appsync/latest/devguide/scalars.html#graph-ql-aws-appsync-scalars -fileprivate enum ISO8601TimeZoneFormat { +private enum ISO8601TimeZoneFormat { case utc, hh, hhmm, hh_mm, hh_mm_ss var format: String { @@ -98,14 +97,13 @@ fileprivate enum ISO8601TimeZoneFormat { } } -fileprivate enum ISO8601TimeZonePart { +private enum ISO8601TimeZonePart { case utc case hh(hours: Int) case hhmm(hours: Int, minutes: Int) case hh_mm(hours: Int, minuts: Int) case hh_mm_ss(hours: Int, minutes: Int, seconds: Int) - static func from(iso8601DateString: String) -> ISO8601TimeZonePart? { return tryExtract(from: iso8601DateString, with: .utc) ?? tryExtract(from: iso8601DateString, with: .hh) @@ -116,7 +114,7 @@ fileprivate enum ISO8601TimeZonePart { } } -fileprivate func tryExtract( +private func tryExtract( from dateString: String, with format: ISO8601TimeZoneFormat ) -> ISO8601TimeZonePart? { @@ -148,3 +146,4 @@ fileprivate func tryExtract( case .hh_mm_ss: return .hh_mm_ss(hours: parts[0], minutes: parts[1], seconds: parts[2]) } } +// swiftlint:enable identifier_name diff --git a/Amplify/Categories/DataStore/Query/QueryField.swift b/Amplify/Categories/DataStore/Query/QueryField.swift index 07a573945f..9d29967569 100644 --- a/Amplify/Categories/DataStore/Query/QueryField.swift +++ b/Amplify/Categories/DataStore/Query/QueryField.swift @@ -61,10 +61,6 @@ public struct QueryField: QueryFieldOperation { public let name: String - init(name: String) { - self.name = name - } - // MARK: - beginsWith public func beginsWith(_ value: String) -> QueryPredicateOperation { return QueryPredicateOperation(field: name, operator: .beginsWith(value)) diff --git a/Amplify/Categories/DataStore/Query/QueryOperator.swift b/Amplify/Categories/DataStore/Query/QueryOperator.swift index 18578eb552..2fcb50ccd2 100644 --- a/Amplify/Categories/DataStore/Query/QueryOperator.swift +++ b/Amplify/Categories/DataStore/Query/QueryOperator.swift @@ -18,7 +18,7 @@ public enum QueryOperator: Encodable { case notContains(_ value: String) case between(start: Persistable, end: Persistable) case beginsWith(_ value: String) - + public func evaluate(target: Any) -> Bool { switch self { case .notEqual(let predicateValue): @@ -51,17 +51,17 @@ public enum QueryOperator: Encodable { } return false } - + private enum CodingKeys: String, CodingKey { case type case value case start case end } - + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) - + switch self { case .notEqual(let value): try container.encode("notEqual", forKey: .type) @@ -76,32 +76,32 @@ public enum QueryOperator: Encodable { case .lessOrEqual(let value): try container.encode("lessOrEqual", forKey: .type) try container.encode(value, forKey: .value) - + case .lessThan(let value): try container.encode("lessThan", forKey: .type) try container.encode(value, forKey: .value) - + case .greaterOrEqual(let value): try container.encode("greaterOrEqual", forKey: .type) try container.encode(value, forKey: .value) - + case .greaterThan(let value): try container.encode("greaterThan", forKey: .type) try container.encode(value, forKey: .value) - + case .contains(let value): try container.encode("contains", forKey: .type) try container.encode(value, forKey: .value) - + case .notContains(let value): try container.encode("notContains", forKey: .type) try container.encode(value, forKey: .value) - + case .between(let start, let end): try container.encode("between", forKey: .type) try container.encode(start, forKey: .start) try container.encode(end, forKey: .end) - + case .beginsWith(let value): try container.encode("beginsWith", forKey: .type) try container.encode(value, forKey: .value) diff --git a/Amplify/Categories/DataStore/Query/QueryPredicate.swift b/Amplify/Categories/DataStore/Query/QueryPredicate.swift index 5d242502a1..78bdf9f051 100644 --- a/Amplify/Categories/DataStore/Query/QueryPredicate.swift +++ b/Amplify/Categories/DataStore/Query/QueryPredicate.swift @@ -92,9 +92,9 @@ public class QueryPredicateGroup: QueryPredicate, Encodable { return !predicate.evaluate(target: target) } } - + // MARK: - Encodable conformance - + private enum CodingKeys: String, CodingKey { case type case predicates @@ -111,15 +111,15 @@ public class QueryPredicateGroup: QueryPredicate, Encodable { try _encode(encoder) } } - + public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(type.rawValue, forKey: .type) - + let anyPredicates = predicates.map(AnyQueryPredicate.init) try container.encode(anyPredicates, forKey: .predicates) } - + } public class QueryPredicateOperation: QueryPredicate, Encodable { diff --git a/Amplify/Categories/DataStore/Subscribe/DataStoreCategory+Subscribe.swift b/Amplify/Categories/DataStore/Subscribe/DataStoreCategory+Subscribe.swift index 0e1d802b87..ae669c73f9 100644 --- a/Amplify/Categories/DataStore/Subscribe/DataStoreCategory+Subscribe.swift +++ b/Amplify/Categories/DataStore/Subscribe/DataStoreCategory+Subscribe.swift @@ -11,7 +11,7 @@ extension DataStoreCategory: DataStoreSubscribeBehavior { public func observe(_ modelType: M.Type) -> AmplifyAsyncThrowingSequence { return plugin.observe(modelType) } - + public func observeQuery(for modelType: M.Type, where predicate: QueryPredicate? = nil, sort sortInput: QuerySortInput? = nil) diff --git a/Amplify/Categories/Hub/HubChannel.swift b/Amplify/Categories/Hub/HubChannel.swift index ba68e0f85a..0979ac95c3 100644 --- a/Amplify/Categories/Hub/HubChannel.swift +++ b/Amplify/Categories/Hub/HubChannel.swift @@ -25,7 +25,7 @@ public enum HubChannel { case logging case predictions - + case pushNotifications case storage diff --git a/Amplify/Categories/Logging/Internal/BroadcastLogger.swift b/Amplify/Categories/Logging/Internal/BroadcastLogger.swift index 267d19c084..849c93533b 100644 --- a/Amplify/Categories/Logging/Internal/BroadcastLogger.swift +++ b/Amplify/Categories/Logging/Internal/BroadcastLogger.swift @@ -11,23 +11,23 @@ /// /// - Tag: BroadcastLogger final class BroadcastLogger { - + /// The default LogLevel used when no targets are available. /// /// - Tag: LogProxy.defaultLogLevel var defaultLogLevel: Amplify.LogLevel = .error - + private let targets: [Logger] - + /// - Tag: BroadcastLogger.init init(targets: [Logger]) { self.targets = targets } - + } extension BroadcastLogger: Logger { - + var logLevel: Amplify.LogLevel { get { if let logger = targets.first { @@ -42,27 +42,27 @@ extension BroadcastLogger: Logger { } } } - + func error(_ message: @autoclosure () -> String) { targets.forEach { $0.error(message()) } } - + func error(error: Error) { targets.forEach { $0.error(error: error) } } - + func warn(_ message: @autoclosure () -> String) { targets.forEach { $0.warn(message()) } } - + func info(_ message: @autoclosure () -> String) { targets.forEach { $0.info(message()) } } - + func debug(_ message: @autoclosure () -> String) { targets.forEach { $0.debug(message()) } } - + func verbose(_ message: @autoclosure () -> String) { targets.forEach { $0.verbose(message()) } } diff --git a/Amplify/Categories/Logging/Internal/LoggingCategory+CategoryConfigurable.swift b/Amplify/Categories/Logging/Internal/LoggingCategory+CategoryConfigurable.swift index 8a9bee7890..4c691fd65c 100644 --- a/Amplify/Categories/Logging/Internal/LoggingCategory+CategoryConfigurable.swift +++ b/Amplify/Categories/Logging/Internal/LoggingCategory+CategoryConfigurable.swift @@ -27,11 +27,11 @@ extension LoggingCategory: CategoryConfigurable { try plugin.configure(using: configuration?.plugins[plugin.key]) self.plugins[plugin.key] = plugin - + if plugin.key != AWSUnifiedLoggingPlugin.key, let consolePlugin = try? self.getPlugin(for: AWSUnifiedLoggingPlugin.key) { try consolePlugin.configure(using: configuration?.plugins[consolePlugin.key]) } - + configurationState = .configured } diff --git a/Amplify/Categories/Logging/LogLevel.swift b/Amplify/Categories/Logging/LogLevel.swift index 57f92a81da..cee8acfff4 100644 --- a/Amplify/Categories/Logging/LogLevel.swift +++ b/Amplify/Categories/Logging/LogLevel.swift @@ -15,7 +15,7 @@ public extension Amplify { case debug case verbose case none - + public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() if let rawString = try? container.decode(String.self).lowercased() { diff --git a/Amplify/Categories/Logging/LoggingCategory+ClientBehavior.swift b/Amplify/Categories/Logging/LoggingCategory+ClientBehavior.swift index 8c3defed2d..082b38ee67 100644 --- a/Amplify/Categories/Logging/LoggingCategory+ClientBehavior.swift +++ b/Amplify/Categories/Logging/LoggingCategory+ClientBehavior.swift @@ -37,28 +37,28 @@ extension LoggingCategory: LoggingCategoryClientBehavior { } return BroadcastLogger(targets: targets) } - + public func enable() { for plugin in plugins.values { plugin.enable() } } - + public func disable() { for plugin in plugins.values { plugin.disable() } } - + public func logger(forNamespace namespace: String) -> Logger { var targets = [Logger]() for plugin in plugins.values { targets.append(plugin.logger(forNamespace: namespace)) } return BroadcastLogger(targets: targets) - + } - + public func logger(forCategory category: String, forNamespace namespace: String) -> Logger { var targets = [Logger]() for plugin in plugins.values { diff --git a/Amplify/Categories/Logging/LoggingCategory+Logger.swift b/Amplify/Categories/Logging/LoggingCategory+Logger.swift index 33fe94b76b..29f1e95c16 100644 --- a/Amplify/Categories/Logging/LoggingCategory+Logger.swift +++ b/Amplify/Categories/Logging/LoggingCategory+Logger.swift @@ -47,7 +47,7 @@ extension LoggingCategory: Logger { for (_, plugin) in plugins { plugin.default.verbose(message()) } - + } } diff --git a/Amplify/Categories/Logging/LoggingCategory.swift b/Amplify/Categories/Logging/LoggingCategory.swift index 6ec7268d8a..b1dbd0e159 100644 --- a/Amplify/Categories/Logging/LoggingCategory.swift +++ b/Amplify/Categories/Logging/LoggingCategory.swift @@ -19,7 +19,7 @@ final public class LoggingCategory: Category { /// After a custom plugin is added and `configure` is invoked case configured } - + let lock: NSLocking = NSLock() public let categoryType = CategoryType.logging @@ -57,7 +57,7 @@ final public class LoggingCategory: Category { /// For any external cases, Logging is always ready to be used. Internal configuration state is tracked via a /// different mechanism var isConfigured: Bool { - return plugins.count > 0 + return !plugins.isEmpty } var plugins: [PluginKey: LoggingCategoryPlugin] = Amplify.getLoggingCategoryPluginLookup(loggingPlugin: AWSUnifiedLoggingPlugin()) diff --git a/Amplify/Categories/Logging/LoggingCategoryClientBehavior.swift b/Amplify/Categories/Logging/LoggingCategoryClientBehavior.swift index 33525272ac..44a089635f 100644 --- a/Amplify/Categories/Logging/LoggingCategoryClientBehavior.swift +++ b/Amplify/Categories/Logging/LoggingCategoryClientBehavior.swift @@ -15,16 +15,16 @@ public protocol LoggingCategoryClientBehavior { /// Returns a category-specific logger. Defaults to using `Amplify.Logging.logLevel`. func logger(forCategory category: String) -> Logger - + /// enable plugin func enable() - + /// disable plugin func disable() - + /// adding namespace to match Android implementation func logger(forNamespace namespace: String) -> Logger - + /// new api to support category and namespace func logger(forCategory category: String, forNamespace namespace: String) -> Logger } diff --git a/Amplify/Categories/Notifications/NotificationsCategory.swift b/Amplify/Categories/Notifications/NotificationsCategory.swift index 7e9e929653..02c4122b6f 100644 --- a/Amplify/Categories/Notifications/NotificationsCategory.swift +++ b/Amplify/Categories/Notifications/NotificationsCategory.swift @@ -11,7 +11,7 @@ import Foundation public final class NotificationsCategory { /// The Push Notifications category - public internal(set) var Push = PushNotificationsCategory() + public internal(set) var Push = PushNotificationsCategory() // swiftlint:disable:this identifier_name /// The current available subcategories that have been configured var subcategories: [NotificationsSubcategoryBehaviour] { diff --git a/Amplify/Categories/Notifications/NotificationsCategoryConfiguration.swift b/Amplify/Categories/Notifications/NotificationsCategoryConfiguration.swift index df0a825451..7d6da59e62 100644 --- a/Amplify/Categories/Notifications/NotificationsCategoryConfiguration.swift +++ b/Amplify/Categories/Notifications/NotificationsCategoryConfiguration.swift @@ -8,7 +8,7 @@ import Foundation /// The configuration for the Notifications category -public struct NotificationsCategoryConfiguration: CategoryConfiguration { +public struct NotificationsCategoryConfiguration: CategoryConfiguration { /// Plugins public let plugins: [String: JSONValue] diff --git a/Amplify/Categories/Notifications/PushNotifications/PushNotificationsCategory+ClientBehaviour.swift b/Amplify/Categories/Notifications/PushNotifications/PushNotificationsCategory+ClientBehaviour.swift index c151422856..4eff36dc84 100644 --- a/Amplify/Categories/Notifications/PushNotifications/PushNotificationsCategory+ClientBehaviour.swift +++ b/Amplify/Categories/Notifications/PushNotifications/PushNotificationsCategory+ClientBehaviour.swift @@ -12,15 +12,15 @@ extension PushNotificationsCategory: PushNotificationsCategoryBehaviour { public func identifyUser(userId: String, userProfile: UserProfile? = nil) async throws { try await plugin.identifyUser(userId: userId, userProfile: userProfile) } - + public func registerDevice(apnsToken: Data) async throws { try await plugin.registerDevice(apnsToken: apnsToken) } - + public func recordNotificationReceived(_ userInfo: Notifications.Push.UserInfo) async throws { try await plugin.recordNotificationReceived(userInfo) } - + #if !os(tvOS) public func recordNotificationOpened(_ response: UNNotificationResponse) async throws { try await plugin.recordNotificationOpened(response) diff --git a/Amplify/Categories/Predictions/Models/Language.swift b/Amplify/Categories/Predictions/Models/Language.swift index 941ea94e43..484ef1ac1e 100644 --- a/Amplify/Categories/Predictions/Models/Language.swift +++ b/Amplify/Categories/Predictions/Models/Language.swift @@ -8,6 +8,7 @@ import Foundation extension Predictions { + // swiftlint:disable file_length type_body_length public struct Language: Equatable, Decodable { public let code: String @@ -2404,3 +2405,4 @@ extension Predictions.Language { self = .init(code: languageCode) } } +// swiftlint:enable file_length type_body_length diff --git a/Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift b/Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift index 652548eda6..c5639603fa 100644 --- a/Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift +++ b/Amplify/Categories/Predictions/PredictionsCategoryBehavior.swift @@ -21,7 +21,6 @@ public protocol PredictionsCategoryBehavior { options: Predictions.Identify.Options? ) async throws -> Output - /// /// - Parameters: /// - request: diff --git a/Amplify/Categories/Predictions/Request/Identify/Identify+Text+Result.swift b/Amplify/Categories/Predictions/Request/Identify/Identify+Text+Result.swift index 896abd89c1..39f66964a0 100644 --- a/Amplify/Categories/Predictions/Request/Identify/Identify+Text+Result.swift +++ b/Amplify/Categories/Predictions/Request/Identify/Identify+Text+Result.swift @@ -13,7 +13,7 @@ extension Predictions.Identify.Text { public let words: [Predictions.IdentifiedWord]? public let rawLineText: [String]? public let identifiedLines: [Predictions.IdentifiedLine]? - + public init( fullText: String?, words: [Predictions.IdentifiedWord]?, diff --git a/Amplify/Core/Category/CategoryType.swift b/Amplify/Core/Category/CategoryType.swift index 254c2d7a2a..9ff9c5b216 100644 --- a/Amplify/Core/Category/CategoryType.swift +++ b/Amplify/Core/Category/CategoryType.swift @@ -57,7 +57,7 @@ public enum CategoryType: String { /// /// - Tag: CategoryType.predictions case predictions - + /// Push Notifications /// /// - Tag: CategoryType.pushNotifications diff --git a/Amplify/Core/Configuration/Internal/Amplify+Reset.swift b/Amplify/Core/Configuration/Internal/Amplify+Reset.swift index 2975f75166..9a2239fe4b 100644 --- a/Amplify/Core/Configuration/Internal/Amplify+Reset.swift +++ b/Amplify/Core/Configuration/Internal/Amplify+Reset.swift @@ -51,7 +51,7 @@ extension Amplify { ModelListDecoderRegistry.reset() ModelProviderRegistry.reset() log.verbose("Resetting ModelRegistry, ModelListDecoderRegistry, ModelProviderRegistry finished") - + #if os(iOS) await MainActor.run { devMenu = nil diff --git a/Amplify/Core/Error/CoreError.swift b/Amplify/Core/Error/CoreError.swift index 623635fb5c..f6c628c764 100644 --- a/Amplify/Core/Error/CoreError.swift +++ b/Amplify/Core/Error/CoreError.swift @@ -14,7 +14,7 @@ public enum CoreError { /// /// - Tag: CoreError.listOperation case listOperation(ErrorDescription, RecoverySuggestion, Error? = nil) - + /// A client side validation error occured. /// /// - Tag: CoreError.clientValidation diff --git a/Amplify/Core/Support/Amplify+Publisher.swift b/Amplify/Core/Support/Amplify+Publisher.swift index f74b49ed47..98501d9cee 100644 --- a/Amplify/Core/Support/Amplify+Publisher.swift +++ b/Amplify/Core/Support/Amplify+Publisher.swift @@ -9,7 +9,7 @@ import Combine public extension Amplify { - + /// Get Combine Publishers for Amplify APIs. /// /// Provides static methods to create Combine Publishers from Tasks and @@ -37,7 +37,7 @@ public extension Amplify { _ operation: @escaping @Sendable () async throws -> Success ) -> AnyPublisher { let task = Task(operation: operation) - return Future() { promise in + return Future { promise in Task { do { let value = try await task.value @@ -47,7 +47,7 @@ public extension Amplify { } } } - .handleEvents(receiveCancel: { task.cancel() } ) + .handleEvents(receiveCancel: { task.cancel() }) .eraseToAnyPublisher() } @@ -69,16 +69,16 @@ public extension Amplify { _ operation: @escaping @Sendable () async -> Success ) -> AnyPublisher { let task = Task(operation: operation) - return Future() { promise in + return Future { promise in Task { let value = await task.value promise(.success(value)) } } - .handleEvents(receiveCancel: { task.cancel() } ) + .handleEvents(receiveCancel: { task.cancel() }) .eraseToAnyPublisher() } - + /// Create a Combine Publisher for a given AsyncSequence. /// /// Example Usage @@ -113,7 +113,6 @@ public extension Amplify { // This is necessary to prevent the sequence from continuing to send values for a time // after cancellation in the case of a fast Iterator. try Task.checkCancellation() - subject.send(value) } subject.send(completion: .finished) diff --git a/Amplify/Core/Support/AmplifyAsyncSequence.swift b/Amplify/Core/Support/AmplifyAsyncSequence.swift index 95b3a5b631..b98c0f17bb 100644 --- a/Amplify/Core/Support/AmplifyAsyncSequence.swift +++ b/Amplify/Core/Support/AmplifyAsyncSequence.swift @@ -13,8 +13,8 @@ public class AmplifyAsyncSequence: AsyncSequence, Cancellable public typealias Iterator = AsyncStream.Iterator private var asyncStream: AsyncStream! = nil private var continuation: AsyncStream.Continuation! = nil - private var parent: Cancellable? = nil - + private var parent: Cancellable? + public private(set) var isCancelled: Bool = false public init(parent: Cancellable? = nil, diff --git a/Amplify/Core/Support/AmplifyAsyncThrowingSequence.swift b/Amplify/Core/Support/AmplifyAsyncThrowingSequence.swift index 9ece6896b9..38772392da 100644 --- a/Amplify/Core/Support/AmplifyAsyncThrowingSequence.swift +++ b/Amplify/Core/Support/AmplifyAsyncThrowingSequence.swift @@ -13,7 +13,7 @@ public class AmplifyAsyncThrowingSequence: AsyncSequence, Can public typealias Iterator = AsyncThrowingStream.Iterator private var asyncStream: AsyncThrowingStream! = nil private var continuation: AsyncThrowingStream.Continuation! = nil - private var parent: Cancellable? = nil + private var parent: Cancellable? public private(set) var isCancelled: Bool = false diff --git a/Amplify/Core/Support/AmplifyOperation.swift b/Amplify/Core/Support/AmplifyOperation.swift index de556a597e..07d122d68c 100644 --- a/Amplify/Core/Support/AmplifyOperation.swift +++ b/Amplify/Core/Support/AmplifyOperation.swift @@ -61,7 +61,6 @@ open class AmplifyOperation.Promise! #endif - /// Creates an AmplifyOperation for the specified reequest. /// /// ## Events diff --git a/Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift b/Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift index 74c578c87f..fb56c6df18 100644 --- a/Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift +++ b/Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift @@ -10,10 +10,12 @@ import Foundation import Combine #endif -public class AmplifyOperationTaskAdapter: AmplifyTask { +public class AmplifyOperationTaskAdapter: AmplifyTask { let operation: AmplifyOperation let childTask: ChildTask - var resultToken: UnsubscribeToken? = nil + var resultToken: UnsubscribeToken? public init(operation: AmplifyOperation) { self.operation = operation @@ -60,11 +62,14 @@ public class AmplifyOperationTaskAdapter: AmplifyTask, AmplifyInProcessReportingTask { +public class AmplifyInProcessReportingOperationTaskAdapter: AmplifyTask, AmplifyInProcessReportingTask { let operation: AmplifyInProcessReportingOperation let childTask: ChildTask - var resultToken: UnsubscribeToken? = nil - var inProcessToken: UnsubscribeToken? = nil + var resultToken: UnsubscribeToken? + var inProcessToken: UnsubscribeToken? public init(operation: AmplifyInProcessReportingOperation) { self.operation = operation diff --git a/Amplify/Core/Support/AmplifyTask.swift b/Amplify/Core/Support/AmplifyTask.swift index b40ffff779..915f0f06b6 100644 --- a/Amplify/Core/Support/AmplifyTask.swift +++ b/Amplify/Core/Support/AmplifyTask.swift @@ -69,7 +69,7 @@ public extension AmplifyInProcessReportingTask where InProcess == Progress { /// using [Progress](x-source-tag://Progress). /// /// - Tag: AmplifyInProcessReportingTask.progress - var progress : AmplifyAsyncSequence { + var progress: AmplifyAsyncSequence { get async { await inProcess } diff --git a/Amplify/Core/Support/AsyncSequence+forEach.swift b/Amplify/Core/Support/AsyncSequence+forEach.swift index c38279648c..6a579bad27 100644 --- a/Amplify/Core/Support/AsyncSequence+forEach.swift +++ b/Amplify/Core/Support/AsyncSequence+forEach.swift @@ -16,5 +16,5 @@ public extension AsyncSequence { try await block(element) } } - + } diff --git a/Amplify/Core/Support/AtomicDictionary.swift b/Amplify/Core/Support/AtomicDictionary.swift index 52e6f9de4c..fee9411e87 100644 --- a/Amplify/Core/Support/AtomicDictionary.swift +++ b/Amplify/Core/Support/AtomicDictionary.swift @@ -46,7 +46,7 @@ public final class AtomicDictionary { public func set(value: Value, forKey key: Key) { lock.execute { self.value[key] = value } } - + public subscript(key: Key) -> Value? { get { getValue(forKey: key) @@ -70,7 +70,7 @@ extension AtomicDictionary: ExpressibleByDictionaryLiteral { extension AtomicDictionary: Sequence { typealias Iterator = DictionaryIterator - + public func makeIterator() -> DictionaryIterator { lock.execute { value.makeIterator() diff --git a/Amplify/Core/Support/ChildTask.swift b/Amplify/Core/Support/ChildTask.swift index 63d0e7c62d..b9fa73adad 100644 --- a/Amplify/Core/Support/ChildTask.swift +++ b/Amplify/Core/Support/ChildTask.swift @@ -12,9 +12,9 @@ import Foundation actor ChildTask: BufferingSequence { typealias Element = InProcess private let parent: Cancellable - private var inProcessChannel: AmplifyAsyncSequence? = nil + private var inProcessChannel: AmplifyAsyncSequence? private var valueContinuations: [CheckedContinuation] = [] - private var storedResult: Result? = nil + private var storedResult: Result? private var isCancelled = false var inProcess: AmplifyAsyncSequence { diff --git a/Amplify/Core/Support/Fatal.swift b/Amplify/Core/Support/Fatal.swift index deee767414..fa1600351d 100644 --- a/Amplify/Core/Support/Fatal.swift +++ b/Amplify/Core/Support/Fatal.swift @@ -10,8 +10,6 @@ import Foundation // Credit: Dave DeLong // https://forums.swift.org/t/introducing-namespacing-for-common-swift-error-scenarios/10773 -import Foundation - /// An umbrella type supplying static members to handle common /// and conventional exit scenarios. public enum Fatal { diff --git a/Amplify/Core/Support/Optional+Extension.swift b/Amplify/Core/Support/Optional+Extension.swift index 0d3a6ad3c2..4efb0d736f 100644 --- a/Amplify/Core/Support/Optional+Extension.swift +++ b/Amplify/Core/Support/Optional+Extension.swift @@ -4,7 +4,6 @@ // // SPDX-License-Identifier: Apache-2.0 // - import Foundation diff --git a/Amplify/Core/Support/TaskQueue.swift b/Amplify/Core/Support/TaskQueue.swift index 687f088b8a..f281c57e1c 100644 --- a/Amplify/Core/Support/TaskQueue.swift +++ b/Amplify/Core/Support/TaskQueue.swift @@ -10,7 +10,7 @@ import Foundation /// A helper for executing asynchronous work serially. public actor TaskQueue { private var previousTask: Task? - + public init() {} /// Serializes asynchronous requests made from an async context diff --git a/Amplify/DefaultPlugins/AWSHubPlugin/Internal/HubChannelDispatcher.swift b/Amplify/DefaultPlugins/AWSHubPlugin/Internal/HubChannelDispatcher.swift index b54dada954..7a3b10d54a 100644 --- a/Amplify/DefaultPlugins/AWSHubPlugin/Internal/HubChannelDispatcher.swift +++ b/Amplify/DefaultPlugins/AWSHubPlugin/Internal/HubChannelDispatcher.swift @@ -122,7 +122,7 @@ final class HubDispatchOperation: Operation { guard let listeners = delegate?.listeners else { return } - + let dispatcher = SerialDispatcher(channel: channel, payload: payload) dispatcher.dispatch(to: listeners) } diff --git a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/AWSUnifiedLoggingPlugin.swift b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/AWSUnifiedLoggingPlugin.swift index 643ce293d3..50f8c484ff 100644 --- a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/AWSUnifiedLoggingPlugin.swift +++ b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/AWSUnifiedLoggingPlugin.swift @@ -29,7 +29,7 @@ final public class AWSUnifiedLoggingPlugin: LoggingCategoryPlugin { let subsystem: String var enabled: Bool = true private let lock = NSLock() - + /// Initializes the logging system with a default log, and immediately registers a default logger public init() { self.subsystem = Bundle.main.bundleIdentifier ?? "com.amazonaws.amplify.AWSUnifiedLoggingPlugin" @@ -102,7 +102,7 @@ extension AWSUnifiedLoggingPlugin { wrapper.logLevel = logLevel return wrapper } - + public func enable() { enabled = true lock.execute { @@ -111,7 +111,7 @@ extension AWSUnifiedLoggingPlugin { } } } - + public func disable() { enabled = false lock.execute { @@ -120,12 +120,12 @@ extension AWSUnifiedLoggingPlugin { } } } - + public func logger(forNamespace namespace: String) -> Logger { let wrapper = logWrapper(for: namespace) return wrapper } - + public func logger(forCategory category: String, forNamespace namespace: String) -> Logger { let wrapper = logWrapper(for: category + namespace) return wrapper diff --git a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/ConsoleLoggingConfiguration.swift b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/ConsoleLoggingConfiguration.swift index 76de5e93ca..751f4a9eda 100644 --- a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/ConsoleLoggingConfiguration.swift +++ b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/ConsoleLoggingConfiguration.swift @@ -11,7 +11,7 @@ public struct ConsoleLoggingConfiguration: Codable { public init(enable: Bool = true) { self.enable = enable } - + public let enable: Bool } @@ -55,8 +55,7 @@ extension ConsoleLoggingConfiguration { static func decodeConfiguration(from data: Data) throws -> ConsoleLoggingConfiguration? { do { if let configuration = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], - let configurationJson = configuration["consoleLoggingPlugin"] as? [String: Any] - { + let configurationJson = configuration["consoleLoggingPlugin"] as? [String: Any] { let decoder = JSONDecoder() let data = try JSONSerialization.data(withJSONObject: configurationJson) let consoleLoggingConfiguration = try decoder.decode(ConsoleLoggingConfiguration.self, from: data) @@ -79,4 +78,3 @@ extension ConsoleLoggingConfiguration { return nil } } - diff --git a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/OSLogWrapper.swift b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/OSLogWrapper.swift index 4f5f38a417..ad3087d867 100644 --- a/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/OSLogWrapper.swift +++ b/Amplify/DefaultPlugins/AWSUnifiedLoggingPlugin/Internal/OSLogWrapper.swift @@ -9,9 +9,9 @@ import os.log final class OSLogWrapper: Logger { private let osLog: OSLog - + var enabled: Bool = true - + var getLogLevel: () -> LogLevel public var logLevel: LogLevel { diff --git a/Amplify/DevMenu/Amplify+DevMenu.swift b/Amplify/DevMenu/Amplify+DevMenu.swift index 8a9b6bef73..856e00d815 100644 --- a/Amplify/DevMenu/Amplify+DevMenu.swift +++ b/Amplify/DevMenu/Amplify+DevMenu.swift @@ -44,8 +44,10 @@ extension Amplify { return loggingPlugin #endif } - - static func getLoggingCategoryPluginLookup(loggingPlugin: LoggingCategoryPlugin) -> [PluginKey: LoggingCategoryPlugin] { + + static func getLoggingCategoryPluginLookup( + loggingPlugin: LoggingCategoryPlugin + ) -> [PluginKey: LoggingCategoryPlugin] { #if os(iOS) #if DEBUG if isDevMenuEnabled() { diff --git a/Amplify/DevMenu/Data/LogEntryHelper.swift b/Amplify/DevMenu/Data/LogEntryHelper.swift index 5b39c85eac..65fa2229da 100644 --- a/Amplify/DevMenu/Data/LogEntryHelper.swift +++ b/Amplify/DevMenu/Data/LogEntryHelper.swift @@ -25,7 +25,8 @@ struct LogEntryHelper { /// Helper function to fetch logs from `PersistentLoggingPlugin` static func getLogHistory() -> [LogEntryItem] { - if let loggingPlugin: PersistentLoggingPlugin = Amplify.Logging.plugins.first(where: { $0.key == DevMenuStringConstants.persistentLoggingPluginKey})?.value as? PersistentLoggingPlugin { + if let loggingPlugin: PersistentLoggingPlugin = Amplify.Logging.plugins.first(where: { + $0.key == DevMenuStringConstants.persistentLoggingPluginKey})?.value as? PersistentLoggingPlugin { if let logger: PersistentLogWrapper = loggingPlugin.default as? PersistentLogWrapper { return logger.getLogHistory() } diff --git a/Amplify/DevMenu/Data/PluginInfoHelper.swift b/Amplify/DevMenu/Data/PluginInfoHelper.swift index d539a7e6f3..c14d4a05e8 100644 --- a/Amplify/DevMenu/Data/PluginInfoHelper.swift +++ b/Amplify/DevMenu/Data/PluginInfoHelper.swift @@ -13,35 +13,35 @@ struct PluginInfoHelper { static func getPluginInformation() -> [PluginInfoItem] { var pluginList = [PluginInfoItem]() - + pluginList.append(contentsOf: Amplify.Analytics.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.API.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.Auth.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.DataStore.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.Hub.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.Logging.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.Predictions.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) - + pluginList.append(contentsOf: Amplify.Storage.plugins.map { makePluginInfoItem(for: $0.key, versionable: $0.value as? AmplifyVersionable) }) diff --git a/Amplify/DevMenu/Logging/PersistentLoggingPlugin.swift b/Amplify/DevMenu/Logging/PersistentLoggingPlugin.swift index 8bc0218bae..04f41016a1 100644 --- a/Amplify/DevMenu/Logging/PersistentLoggingPlugin.swift +++ b/Amplify/DevMenu/Logging/PersistentLoggingPlugin.swift @@ -27,19 +27,19 @@ public class PersistentLoggingPlugin: LoggingCategoryPlugin { public func logger(forCategory category: String) -> Logger { return plugin.logger(forCategory: category) } - + public func enable() { plugin.enable() } - + public func disable() { plugin.disable() } - + public func logger(forNamespace namespace: String) -> Logger { plugin.logger(forNamespace: namespace) } - + public func logger(forCategory category: String, forNamespace namespace: String) -> Logger { plugin.logger(forCategory: category, forNamespace: namespace) } diff --git a/AmplifyAsyncTesting/Sources/AsyncTesting/AsyncExpectation.swift b/AmplifyAsyncTesting/Sources/AsyncTesting/AsyncExpectation.swift index 593e4ab047..2746528644 100644 --- a/AmplifyAsyncTesting/Sources/AsyncTesting/AsyncExpectation.swift +++ b/AmplifyAsyncTesting/Sources/AsyncTesting/AsyncExpectation.swift @@ -33,11 +33,11 @@ public actor AsyncExpectation { public var isFulfilled: Bool { state == .fulfilled } - + public func setShouldTrigger(_ shouldTrigger: Bool) { self.isInverted = !shouldTrigger } - + public func setExpectedFulfillmentCount(_ count: Int) { self.expectedFulfillmentCount = count } diff --git a/AmplifyAsyncTesting/Tests/AsyncTestingTests/AsyncTestingTests.swift b/AmplifyAsyncTesting/Tests/AsyncTestingTests/AsyncTestingTests.swift index a4bea03173..a4dbea7c0a 100644 --- a/AmplifyAsyncTesting/Tests/AsyncTestingTests/AsyncTestingTests.swift +++ b/AmplifyAsyncTesting/Tests/AsyncTestingTests/AsyncTestingTests.swift @@ -86,7 +86,7 @@ final class AsyncExpectationTests: XCTestCase { let delay = 0.01 let notYetDone = asyncExpectation(description: "not yet done", isInverted: true) let done = asyncExpectation(description: "done") - + let task = Task { await AsyncRunner().run() XCTAssertTrue(Task.isCancelled) diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+GraphQLBehavior.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+GraphQLBehavior.swift index 002cba23a1..6948f9195d 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+GraphQLBehavior.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+GraphQLBehavior.swift @@ -19,7 +19,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func query(request: GraphQLRequest) async throws -> GraphQLTask.Success { let operation = AWSGraphQLOperation(request: request.toOperationRequest(operationType: .query), session: session, @@ -41,7 +41,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func mutate(request: GraphQLRequest) async throws -> GraphQLTask.Success { let operation = AWSGraphQLOperation(request: request.toOperationRequest(operationType: .mutation), session: session, @@ -69,7 +69,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func subscribe(request: GraphQLRequest) -> AmplifyAsyncThrowingSequence> { let request = request.toOperationRequest(operationType: .subscription) let runner = AWSGraphQLSubscriptionTaskRunner(request: request, diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+RESTBehavior.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+RESTBehavior.swift index c60ce3e017..59642d79c0 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+RESTBehavior.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/AWSAPIPlugin+RESTBehavior.swift @@ -23,7 +23,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func get(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .get) @@ -52,7 +52,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func put(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .put) @@ -81,7 +81,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func post(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .post) @@ -109,7 +109,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func patch(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .patch) @@ -137,7 +137,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func delete(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .delete) @@ -166,7 +166,7 @@ public extension AWSAPIPlugin { queue.addOperation(operation) return operation } - + func head(request: RESTRequest) async throws -> RESTTask.Success { let operationRequest = RESTOperationRequest(request: request, operationType: .head) diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListDecoder.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListDecoder.swift index 605b9d50ba..c6050bb2d7 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListDecoder.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListDecoder.swift @@ -19,13 +19,13 @@ public struct AppSyncListDecoder: ModelListDecoder { let appSyncAssociatedFields: [String] let apiName: String? } - + /// Used by the custom decoder implemented in the `List` type to detect if the payload can be /// decoded to an AppSyncListProvider. public static func decode(modelType: ModelType.Type, decoder: Decoder) -> AnyModelListProvider? { self.shouldDecodeToAppSyncListProvider(modelType: modelType, decoder: decoder)?.eraseToAnyModelListProvider() } - + static func shouldDecodeToAppSyncListProvider(modelType: ModelType.Type, decoder: Decoder) -> AppSyncListProvider? { if let listPayload = try? AppSyncListPayload.init(from: decoder) { log.verbose("Creating loaded list of \(modelType.modelName)") diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListProvider.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListProvider.swift index 88388999ab..2edf147c1b 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListProvider.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncListProvider.swift @@ -92,7 +92,7 @@ public class AppSyncListProvider: ModelListProvider { return .loaded(elements) } } - + public func load() async throws -> [Element] { switch loadedState { case .loaded(let elements, _, _): @@ -101,7 +101,7 @@ public class AppSyncListProvider: ModelListProvider { return try await load(associatedIdentifiers: associatedIdentifiers, associatedFields: associatedFields) } } - + //// Internal `load` to perform the retrieval of the first page and storing it in memory func load(associatedIdentifiers: [String], associatedFields: [String]) async throws -> [Element] { @@ -113,7 +113,7 @@ public class AppSyncListProvider: ModelListProvider { filter = predicate.graphQLFilter(for: Element.schema) } else { var queryPredicates: [QueryPredicateOperation] = [] - + let columnNames = columnNames(fields: associatedFields, Element.schema) let predicateValues = zip(columnNames, associatedIdentifiers) for (identifierName, identifierValue) in predicateValues { @@ -123,8 +123,7 @@ public class AppSyncListProvider: ModelListProvider { let groupedQueryPredicates = QueryPredicateGroup(type: .and, predicates: queryPredicates) filter = groupedQueryPredicates.graphQLFilter(for: Element.schema) } - - + let request = GraphQLRequest.listQuery(responseType: JSONValue.self, modelSchema: Element.schema, filter: filter, @@ -142,7 +141,7 @@ public class AppSyncListProvider: ModelListProvider { AWSAppSyncListResponse from: \(graphQLData) """, "", nil) } - + self.loadedState = .loaded(elements: listResponse.items, nextToken: listResponse.nextToken, filter: filter) @@ -163,7 +162,7 @@ public class AppSyncListProvider: ModelListProvider { throw error } } - + public func hasNextPage() -> Bool { switch loadedState { case .loaded(_, let nextToken, _): @@ -172,7 +171,7 @@ public class AppSyncListProvider: ModelListProvider { return false } } - + public func getNextPage() async throws -> List { guard case .loaded(_, let nextTokenOptional, let filter) = loadedState else { throw CoreError.clientValidation(""" @@ -219,7 +218,7 @@ public class AppSyncListProvider: ModelListProvider { throw error } } - + public func encode(to encoder: Encoder) throws { switch loadedState { case .notLoaded(let associatedIdentifiers, let associatedFields): @@ -239,9 +238,9 @@ public class AppSyncListProvider: ModelListProvider { try elements.encode(to: encoder) } } - + // MARK: - Helpers - + /// Retrieve the column names for the specified field `field` for this schema. func columnNames(fields: [String], _ modelSchema: ModelSchema) -> [String] { // Associated field names have already been resolved from the parent model's has-many targetNames @@ -257,14 +256,14 @@ public class AppSyncListProvider: ModelListProvider { case .belongsTo(_, let targetNames), .hasOne(_, let targetNames): guard !targetNames.isEmpty else { return [defaultFieldName] - + } return targetNames default: return fields } } - + } extension AppSyncListProvider: DefaultLogger { diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelDecoder.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelDecoder.swift index fd6b1f22e2..9fc1da75b7 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelDecoder.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelDecoder.swift @@ -12,22 +12,22 @@ import Amplify /// inside an `AppSyncModelProvider` when decoding to the `LazyReference` as a "not yet loaded" Reference. If the data payload /// can be decoded to the Model, then the model provider is created as a "loaded" reference. public struct AppSyncModelDecoder: ModelProviderDecoder { - + public static let AppSyncSource = "AppSync" - + /// Metadata that contains metadata of a model, specifically the identifiers used to hydrate the model. struct Metadata: Codable { let identifiers: [LazyReferenceIdentifier] let apiName: String? let source: String - + init(identifiers: [LazyReferenceIdentifier], apiName: String?, source: String = AppSyncSource) { self.identifiers = identifiers self.apiName = apiName self.source = source } } - + public static func decode(modelType: ModelType.Type, decoder: Decoder) -> AnyModelProvider? { if let metadata = try? Metadata(from: decoder) { if metadata.source == AppSyncSource { @@ -37,12 +37,12 @@ public struct AppSyncModelDecoder: ModelProviderDecoder { return nil } } - + if let model = try? ModelType.init(from: decoder) { log.verbose("Creating loaded model \(model)") return AppSyncModelProvider(model: model).eraseToAnyModelProvider() } - + return nil } } diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelMetadata.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelMetadata.swift index b929e77eb6..31cb93303a 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelMetadata.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelMetadata.swift @@ -10,7 +10,7 @@ import Foundation /// Holds the methods to traverse and maniupulate the response data object by injecting public struct AppSyncModelMetadataUtils { - + // A fairly light check to make sure the payload is an object and we have the schema for `addMetadata`. // Note: `addMetadata` should be very tightly checking the associated fields to determine when it should add // metadata. Do we still need to do this anymore? @@ -65,12 +65,12 @@ public struct AppSyncModelMetadataUtils { encoder.dateEncodingStrategy = ModelDateFormatting.encodingStrategy let decoder = JSONDecoder() decoder.dateDecodingStrategy = ModelDateFormatting.decodingStrategy - + // Iterate over the associations of the model and for each association, either create the identifier metadata // for lazy loading belongs-to or create the model association metadata for lazy loading has-many. // The metadata gets decoded to the LazyReference and List implementations respectively. for modelField in modelSchema.fields.values { - + // Scenario: Belongs-to associations. For the current `modelField` that is a belongs-to association, // retrieve the data and attempt to decode to the association's modelType. If it can be decoded, // this means it is eager loaded and does not need to be lazy loaded. If it cannot, extract the @@ -81,7 +81,7 @@ public struct AppSyncModelMetadataUtils { case .object(let modelObject) = nestedModelJSON, let associatedModelName = modelField.associatedModelName, let associatedModelType = ModelRegistry.modelType(from: associatedModelName) { - + // Scenario: Belongs-To Primary Keys only are available for lazy loading if let modelIdentifierMetadata = createModelIdentifierMetadata(associatedModelType, modelObject: modelObject, @@ -105,11 +105,11 @@ public struct AppSyncModelMetadataUtils { } // otherwise do nothing to the data. } - + // Scenario: Has-Many eager loaded or empty payloads. if modelField.isArray && modelField.hasAssociation, let associatedModelName = modelField.associatedModelName { - + // Scenario: Has-many items array is missing. // Store the association data (parent's identifier and field name) // This allows the list to perform lazy loading of child items using parent identifier as the predicate @@ -127,7 +127,7 @@ public struct AppSyncModelMetadataUtils { """) } } - + // Scenario: Has-Many items array is eager loaded as `nestedModelJSON` // If the model types allow for lazy loading, inject the metadata at each item of `nestedModelJSON` else if let nestedModelJSON = modelJSON[modelField.name], @@ -135,17 +135,17 @@ public struct AppSyncModelMetadataUtils { case .array(var graphQLDataArray) = graphQLDataObject["items"], let associatedModelType = ModelRegistry.modelType(from: associatedModelName), associatedModelType.rootPath != nil { - + for (index, item) in graphQLDataArray.enumerated() { let modelJSON = AppSyncModelMetadataUtils.addMetadata(toModel: item, apiName: apiName) graphQLDataArray[index] = modelJSON } - + graphQLDataObject["items"] = JSONValue.array(graphQLDataArray) let payload = AppSyncListPayload(graphQLData: JSONValue.object(graphQLDataObject), apiName: apiName, variables: nil) - + if let serializedPayload = try? encoder.encode(payload), let payloadJSON = try? decoder.decode(JSONValue.self, from: serializedPayload) { log.verbose("Adding [\(modelField.name): \(payloadJSON)]") @@ -159,7 +159,7 @@ public struct AppSyncModelMetadataUtils { return JSONValue.object(modelJSON) } - + /// Extract the identifiers from the `modelObject`. The number of identifiers extracted compared to the number of /// fields on the `modelObject` is useful determining if the `modelOject` is eager or lazy loaded. If the identifiers /// plus one additional field (`__typename`) doesn't match the number of keys on the `modelObject` then there @@ -185,7 +185,7 @@ public struct AppSyncModelMetadataUtils { return nil } } - + /// Retrieve just the identifiers from the current model. These identifiers are later used /// for creating `AppSyncListDecoder.Metadata` payloads for decoding. static func retrieveIdentifiers(_ modelJSON: [String: JSONValue], _ schema: ModelSchema) -> [String]? { diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelProvider.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelProvider.swift index f71f08194e..ed717eec64 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelProvider.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Core/AppSyncModelProvider.swift @@ -10,27 +10,27 @@ import Amplify import AWSPluginsCore public class AppSyncModelProvider: ModelProvider { - + let apiName: String? - + var loadedState: ModelProviderState - + // Creates a "not loaded" provider init(metadata: AppSyncModelDecoder.Metadata) { self.loadedState = .notLoaded(identifiers: metadata.identifiers) self.apiName = metadata.apiName } - + // Creates a "loaded" provider init(model: ModelType?) { self.loadedState = .loaded(model: model) self.apiName = nil } - + // MARK: - APIs - + public func load() async throws -> ModelType? { - + switch loadedState { case .notLoaded(let identifiers): guard let identifiers = identifiers else { @@ -54,11 +54,11 @@ public class AppSyncModelProvider: ModelProvider { return element } } - + public func getState() -> ModelProviderState { loadedState } - + public func encode(to encoder: Encoder) throws { switch loadedState { case .notLoaded(let identifiers): diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenProviderWrapper.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenProviderWrapper.swift index 6be2ea5a5d..bc5be0d627 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenProviderWrapper.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenProviderWrapper.swift @@ -16,7 +16,7 @@ class AuthTokenProviderWrapper: AuthTokenProvider { init(tokenAuthProvider: AmplifyAuthTokenProvider) { self.wrappedAuthTokenProvider = tokenAuthProvider } - + func getUserPoolAccessToken() async throws -> String { try await wrappedAuthTokenProvider.getLatestAuthToken() } diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenURLRequestInterceptor.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenURLRequestInterceptor.swift index 2d639afca4..a0b33d5825 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenURLRequestInterceptor.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/AuthTokenURLRequestInterceptor.swift @@ -10,9 +10,9 @@ import AWSPluginsCore import Foundation struct AuthTokenURLRequestInterceptor: URLRequestInterceptor { - + static let AWSDateISO8601DateFormat2 = "yyyyMMdd'T'HHmmss'Z'" - + private let userAgent = AmplifyAWSServiceConfiguration.userAgentLib let authTokenProvider: AuthTokenProvider @@ -34,14 +34,14 @@ struct AuthTokenURLRequestInterceptor: URLRequestInterceptor { forHTTPHeaderField: URLRequestConstants.Header.xAmzDate) mutableRequest.addValue(userAgent, forHTTPHeaderField: URLRequestConstants.Header.userAgent) - + let token: String do { token = try await authTokenProvider.getUserPoolAccessToken() } catch { throw APIError.operationError("Failed to retrieve authorization token.", "", error) } - + mutableRequest.setValue(token, forHTTPHeaderField: "authorization") return mutableRequest as URLRequest } diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/IAMURLRequestInterceptor.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/IAMURLRequestInterceptor.swift index 4ad5159992..d012985a63 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/IAMURLRequestInterceptor.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Interceptor/RequestInterceptor/IAMURLRequestInterceptor.swift @@ -17,7 +17,7 @@ struct IAMURLRequestInterceptor: URLRequestInterceptor { let region: AWSRegionType let endpointType: AWSAPICategoryPluginEndpointType private let userAgent = AmplifyAWSServiceConfiguration.userAgentLib - + init(iamCredentialsProvider: IAMCredentialsProvider, region: AWSRegionType, endpointType: AWSAPICategoryPluginEndpointType) { diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLOperation.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLOperation.swift index 859981e321..a6115ff171 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLOperation.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLOperation.swift @@ -154,8 +154,7 @@ final public class AWSGraphQLOperation: GraphQLOperation { getEndpointConfig(from: request).flatMap { endpointConfig in do { if let pluginOptions = request.options.pluginOptions as? AWSPluginOptions, - let authType = pluginOptions.authType - { + let authType = pluginOptions.authType { return .success(try pluginConfig.interceptorsForEndpoint( withConfig: endpointConfig, authType: authType diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLSubscriptionTaskRunner.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLSubscriptionTaskRunner.swift index a9bf16eee9..b8e42644cc 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLSubscriptionTaskRunner.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLSubscriptionTaskRunner.swift @@ -16,7 +16,7 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, public var request: GraphQLOperationRequest public var context = InternalTaskAsyncThrowingSequenceContext>() - + let pluginConfig: AWSAPICategoryPluginConfiguration let subscriptionConnectionFactory: SubscriptionConnectionFactory let authService: AWSAuthServiceBehavior @@ -28,7 +28,7 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, private var running = false private let subscriptionQueue = DispatchQueue(label: "AWSGraphQLSubscriptionOperation.subscriptionQueue") - + init(request: Request, pluginConfig: AWSAPICategoryPluginConfiguration, subscriptionConnectionFactory: SubscriptionConnectionFactory, @@ -40,7 +40,7 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, self.authService = authService self.apiAuthProviderFactory = apiAuthProviderFactory } - + public func cancel() { subscriptionQueue.sync { if let subscriptionItem = subscriptionItem, let subscriptionConnection = subscriptionConnection { @@ -50,7 +50,7 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, } } } - + public func run() async throws { guard !running else { return } running = true @@ -116,9 +116,9 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, urlRequest.setValue(userAgent, forHTTPHeaderField: URLRequestConstants.Header.userAgent) return urlRequest } - + // MARK: - Subscription callbacks - + private func onAsyncSubscriptionEvent(event: SubscriptionItemEvent) { switch event { case .connection(let subscriptionConnectionEvent): @@ -166,7 +166,7 @@ public class AWSGraphQLSubscriptionTaskRunner: InternalTaskRunner, // payload is the right thing to do. Another option would be to propagate a GraphQL error, but // leave the subscription alive. // see https://github.com/aws-amplify/amplify-swift/issues/2577 - + fail(APIError.operationError("Failed to deserialize", "", error)) } } @@ -204,7 +204,7 @@ final public class AWSGraphQLSubscriptionOperation: GraphQLSubscri let subscriptionConnectionFactory: SubscriptionConnectionFactory let authService: AWSAuthServiceBehavior private let userAgent = AmplifyAWSServiceConfiguration.userAgentLib - + var subscriptionConnection: SubscriptionConnection? var subscriptionItem: SubscriptionItem? var apiAuthProviderFactory: APIAuthProviderFactory @@ -318,7 +318,7 @@ final public class AWSGraphQLSubscriptionOperation: GraphQLSubscri } // MARK: - Subscription callbacks - + private func onAsyncSubscriptionEvent(event: SubscriptionItemEvent) { switch event { case .connection(let subscriptionConnectionEvent): diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSHTTPURLResponse.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSHTTPURLResponse.swift index 68c55eadc6..bb4a87396d 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSHTTPURLResponse.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSHTTPURLResponse.swift @@ -52,7 +52,7 @@ public class AWSHTTPURLResponse: HTTPURLResponse { public override class var supportsSecureCoding: Bool { return true } - + public override func encode(with coder: NSCoder) { coder.encode(body, forKey: "body") coder.encode(response, forKey: "response") diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyReachability.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyReachability.swift index 3dfcfe25ae..9045d31e03 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyReachability.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyReachability.swift @@ -177,7 +177,7 @@ public extension AmplifyReachability { func startNotifier() throws { guard !notifierRunning else { return } - let callback: SCNetworkReachabilityCallBack = { reachability, flags, info in + let callback: SCNetworkReachabilityCallBack = { _, flags, info in guard let info = info else { return } // `weakifiedReachability` is guaranteed to exist by virtue of our diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyRechability+watchOS.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyRechability+watchOS.swift index 99195734fe..c5bf5e5dc9 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyRechability+watchOS.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Reachability/AmplifyRechability+watchOS.swift @@ -20,31 +20,31 @@ import Network public class AmplifyReachability { public var allowsCellularConnection: Bool - + // The notification center on which "reachability changed" events are being posted public var notificationCenter: NotificationCenter = NotificationCenter.default - + public var connection: AmplifyReachability.Connection { guard networkReachability.currentPath.status != .unsatisfied else { return .unavailable } - + // If we're reachable but not running on a device, we must be in Wi-Fi if !isRunningOnDevice { return .wifi } - + if networkReachability.currentPath.usesInterfaceType(.wifi) { return .wifi } - + if networkReachability.currentPath.usesInterfaceType(.cellular) { return allowsCellularConnection ? .cellular : .unavailable } - + return .unavailable } - + private let networkReachability: NWPathMonitor private let notificationQueue: DispatchQueue private var isRunningOnDevice: Bool = { @@ -54,7 +54,7 @@ public class AmplifyReachability { return true #endif }() - + public init( networkReachability: NWPathMonitor = NWPathMonitor(), allowsCellularConnection: Bool = true, @@ -73,22 +73,22 @@ public class AmplifyReachability { ) self.notificationQueue = notificationQueue } - + deinit { stopNotifier() } - + // MARK: - *** Notifier methods *** public func startNotifier() throws { guard networkReachability.pathUpdateHandler == nil else { return } - networkReachability.pathUpdateHandler = { [weak self] path in + networkReachability.pathUpdateHandler = { [weak self] _ in guard let self = self else { return } self.notificationQueue.async { self.notificationCenter.post(name: .reachabilityChanged, object: self) } } } - + public func stopNotifier() { networkReachability.pathUpdateHandler = nil } diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Decode/GraphQLResponseDecoder+DecodeData.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Decode/GraphQLResponseDecoder+DecodeData.swift index 57af2aa6fb..bfaf333a7f 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Decode/GraphQLResponseDecoder+DecodeData.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Decode/GraphQLResponseDecoder+DecodeData.swift @@ -10,7 +10,7 @@ import AWSPluginsCore import Foundation extension GraphQLResponseDecoder { - + /* The sequence of `responseType` checking attempts to decode to specific types before falling back to (5) serializing the data and letting the default decode run its course (6). @@ -39,7 +39,7 @@ extension GraphQLResponseDecoder { graphQLData = graphQLDataWithTypeName } let serializedJSON: Data - + if request.responseType == AnyModel.self { // 2 let anyModel = try AnyModel(modelJSON: graphQLData) serializedJSON = try encoder.encode(anyModel) @@ -89,7 +89,7 @@ extension GraphQLResponseDecoder { let variablesData = try JSONSerialization.data(withJSONObject: variables) return try decoder.decode([String: JSONValue].self, from: variablesData) } - + // The Swift DataStore plugin has a dependency on using `__typename` from the response data. // For example, DataStore will use the type `MutationSync` to decode the model with sync metadata by // pulling out the modelName from `__typename` and use that to decode to the actual model type. diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/GraphQLRequest+toListQuery.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/GraphQLRequest+toListQuery.swift index 58c6bae833..130e3d4167 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/GraphQLRequest+toListQuery.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/GraphQLRequest+toListQuery.swift @@ -31,7 +31,7 @@ extension GraphQLRequest { responseType: responseType.self, decodePath: document.name) } - + static func getRequest(_ modelType: M.Type, byIdentifiers identifiers: [LazyReferenceIdentifier], apiName: String?) -> GraphQLRequest { @@ -39,9 +39,9 @@ extension GraphQLRequest { operationType: .query) documentBuilder.add(decorator: DirectiveNameDecorator(type: .get)) documentBuilder.add(decorator: ModelIdDecorator(identifiers: identifiers)) - + let document = documentBuilder.build() - + return GraphQLRequest(apiName: apiName, document: document.stringValue, variables: document.variables, diff --git a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/Result+Async.swift b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/Result+Async.swift index fbf204c971..1b145420f0 100644 --- a/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/Result+Async.swift +++ b/AmplifyPlugins/API/Sources/AWSAPIPlugin/Support/Utils/Result+Async.swift @@ -5,10 +5,10 @@ // SPDX-License-Identifier: Apache-2.0 // - import Foundation extension Result { + // swiftlint:disable:next identifier_name func flatMapAsync(_ f: (Success) async -> Result) async -> Result { switch self { case .success(let value): diff --git a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+ClientBehavior.swift b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+ClientBehavior.swift index 53b3f4e264..ddc52e2657 100644 --- a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+ClientBehavior.swift +++ b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+ClientBehavior.swift @@ -135,7 +135,7 @@ extension AWSPinpointAnalyticsPlugin { globalProperties.removeAll() return } - + for key in keys { if let value = globalProperties[key] { await pinpoint.removeGlobalProperty(value, forKey: key) diff --git a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Configure.swift b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Configure.swift index 4430f3bf9a..421c54b7b1 100644 --- a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Configure.swift +++ b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Configure.swift @@ -37,7 +37,7 @@ extension AWSPinpointAnalyticsPlugin { appId: configuration.appId, region: configuration.region ) - + let interval = TimeInterval(configuration.autoFlushEventsInterval) pinpoint.setAutomaticSubmitEventsInterval(interval) { result in switch result { @@ -47,7 +47,7 @@ extension AWSPinpointAnalyticsPlugin { Amplify.Hub.dispatchFlushEvents(AnalyticsErrorHelper.getDefaultError(error)) } } - + if configuration.trackAppSessions { let sessionBackgroundTimeout: TimeInterval if configuration.autoSessionTrackingInterval == .max { @@ -55,10 +55,10 @@ extension AWSPinpointAnalyticsPlugin { } else { sessionBackgroundTimeout = TimeInterval(configuration.autoSessionTrackingInterval) } - + pinpoint.startTrackingSessions(backgroundTimeout: sessionBackgroundTimeout) } - + let networkMonitor = NWPathMonitor() networkMonitor.startMonitoring( using: DispatchQueue( diff --git a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Reset.swift b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Reset.swift index a86fdb0ffa..4d29463c05 100644 --- a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Reset.swift +++ b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/AWSPinpointAnalyticsPlugin+Reset.swift @@ -23,7 +23,7 @@ extension AWSPinpointAnalyticsPlugin { if isEnabled != nil { isEnabled = nil } - + if networkMonitor != nil { networkMonitor.stopMonitoring() networkMonitor = nil diff --git a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift index 38ee22a95f..06db245ea7 100644 --- a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift +++ b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Configuration/AWSPinpointAnalyticsPluginConfiguration.swift @@ -35,7 +35,7 @@ public struct AWSPinpointAnalyticsPluginConfiguration { let autoFlushEventsInterval: Int let trackAppSessions: Bool let autoSessionTrackingInterval: Int - + private static let logger = Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: Self.self)) init(_ configuration: JSONValue) throws { @@ -52,13 +52,13 @@ public struct AWSPinpointAnalyticsPluginConfiguration { AnalyticsPluginErrorConstant.missingPinpointAnalyicsConfiguration.recoverySuggestion ) } - + let pluginConfiguration = try AWSPinpointPluginConfiguration(pinpointAnalyticsConfig) - + let autoFlushEventsInterval = try Self.getAutoFlushEventsInterval(configObject) let trackAppSessions = try Self.getTrackAppSessions(configObject) let autoSessionTrackingInterval = try Self.getAutoSessionTrackingInterval(configObject) - + // Warn users in case they set different regions between pinpointTargeting and pinpointAnalytics if let pinpointTargetingJson = configObject[Self.pinpointTargetingConfigKey], let pinpointTargetingConfig = try? AWSPinpointPluginConfiguration(pinpointTargetingJson), diff --git a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Utils/NetworkMonitor.swift b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Utils/NetworkMonitor.swift index 1517b7394a..c14182f492 100644 --- a/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Utils/NetworkMonitor.swift +++ b/AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Utils/NetworkMonitor.swift @@ -18,11 +18,11 @@ extension NWPathMonitor: NetworkMonitor { var isOnline: Bool { currentPath.status == .satisfied } - + func startMonitoring(using queue: DispatchQueue) { start(queue: queue) } - + func stopMonitoring() { cancel() } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift index 4fce0d3311..5869e8a229 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift @@ -108,7 +108,7 @@ extension AWSCognitoAuthPlugin { } if let maxRetryUnwrapped = networkPreferences?.maxRetryCount { - configuration.retryStrategyOptions = RetryStrategyOptions(maxRetriesBase: Int(maxRetryUnwrapped)) + configuration.retryStrategyOptions = RetryStrategyOptions(maxRetriesBase: Int(maxRetryUnwrapped)) } return CognitoIdentityProviderClient(config: configuration) @@ -131,7 +131,7 @@ extension AWSCognitoAuthPlugin { } if let maxRetryUnwrapped = networkPreferences?.maxRetryCount { - configuration.retryStrategyOptions = RetryStrategyOptions(maxRetriesBase: Int(maxRetryUnwrapped)) + configuration.retryStrategyOptions = RetryStrategyOptions(maxRetriesBase: Int(maxRetryUnwrapped)) } return CognitoIdentityClient(config: configuration) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+PluginSpecificAPI.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+PluginSpecificAPI.swift index bc5adbfa95..6155f93d27 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+PluginSpecificAPI.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+PluginSpecificAPI.swift @@ -51,5 +51,5 @@ public extension AWSCognitoAuthPlugin { userPoolFactory: authEnvironment.cognitoUserPoolFactory) return try await task.value } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/Configuration/InitializeAuthConfiguration.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/Configuration/InitializeAuthConfiguration.swift index b55a033077..4d1388d7ef 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/Configuration/InitializeAuthConfiguration.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/Configuration/InitializeAuthConfiguration.swift @@ -30,11 +30,9 @@ struct InitializeAuthConfiguration: Action { if case .amplifyCredentials(let fetchedCredentials) = data { credentials = fetchedCredentials } - } - catch KeychainStoreError.itemNotFound { + } catch KeychainStoreError.itemNotFound { logInfo("No existing session found.", environment: environment) - } - catch { + } catch { logError("Error when loading amplify credentials: \(error)", environment: environment) } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift index ee63e5063a..6017f71215 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/CredentialStore/MigrateLegacyCredentialStore.swift @@ -9,6 +9,7 @@ import Foundation import Amplify @_spi(KeychainStore) import AWSPluginsCore +// swiftlint:disable identifier_name struct MigrateLegacyCredentialStore: Action { let identifier = "MigrateLegacyCredentialStore" @@ -361,7 +362,7 @@ extension MigrateLegacyCredentialStore: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } @@ -380,3 +381,4 @@ extension MigrateLegacyCredentialStore: CustomDebugStringConvertible { debugDictionary.debugDescription } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/DeleteUser/InformUserDeletedAndSignedOut.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/DeleteUser/InformUserDeletedAndSignedOut.swift index 2f084dc27f..a604270478 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/DeleteUser/InformUserDeletedAndSignedOut.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/DeleteUser/InformUserDeletedAndSignedOut.swift @@ -36,7 +36,7 @@ extension InformUserDeletedAndSignedOut: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift index d21f30363a..bca1e5e6d0 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionError.swift @@ -47,7 +47,7 @@ extension InformSessionError: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionFetched.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionFetched.swift index d312295754..6bf1e5471a 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionFetched.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InformSessionFetched.swift @@ -30,7 +30,7 @@ extension InformSessionFetched: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchAuthSessionWithUserPool.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchAuthSessionWithUserPool.swift index 88c3b42d91..09ecfed4b2 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchAuthSessionWithUserPool.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchAuthSessionWithUserPool.swift @@ -43,7 +43,7 @@ extension InitializeFetchAuthSessionWithUserPool: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchUnAuthSession.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchUnAuthSession.swift index 225e740b24..619e2586ff 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchUnAuthSession.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/InitializeFetchUnAuthSession.swift @@ -34,7 +34,7 @@ extension InitializeFetchUnAuthSession: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/PersistCredentials.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/PersistCredentials.swift index bacbda3a71..ca59a387f6 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/PersistCredentials.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/FetchAuthorizationSession/PersistCredentials.swift @@ -41,7 +41,7 @@ extension PersistCredentials: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InformSessionRefreshed.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InformSessionRefreshed.swift index 6b5fd05aa3..47d937cbbb 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InformSessionRefreshed.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InformSessionRefreshed.swift @@ -28,7 +28,7 @@ extension InformSessionRefreshed: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InitializeRefreshSession.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InitializeRefreshSession.swift index 402acbdc79..43c36c2cb9 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InitializeRefreshSession.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/InitializeRefreshSession.swift @@ -64,7 +64,7 @@ extension InitializeRefreshSession: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshHostedUITokens.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshHostedUITokens.swift index 859355272f..367b9eb222 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshHostedUITokens.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshHostedUITokens.swift @@ -117,7 +117,7 @@ extension RefreshHostedUITokens: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift index 5a6da9d7bc..cbd3fcbd60 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/RefreshAuthorizationSession/UserPool/RefreshUserPoolTokens.swift @@ -104,7 +104,7 @@ extension RefreshUserPoolTokens: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/CustomSignIn/InitiateCustomAuth.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/CustomSignIn/InitiateCustomAuth.swift index 0b0c717d54..0dc41794d9 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/CustomSignIn/InitiateCustomAuth.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/CustomSignIn/InitiateCustomAuth.swift @@ -78,7 +78,7 @@ extension InitiateCustomAuth: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/InitiateAuthDeviceSRP.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/InitiateAuthDeviceSRP.swift index 7a89fa6615..bc7614301a 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/InitiateAuthDeviceSRP.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/InitiateAuthDeviceSRP.swift @@ -86,7 +86,10 @@ struct InitiateAuthDeviceSRP: Action { _ response: SignInResponseBehavior, with stateData: SRPStateData) -> StateMachineEvent { guard case .devicePasswordVerifier = response.challengeName else { - let message = "Unsupported challenge response during DeviceSRPAuth \(response.challengeName ?? .sdkUnknown("Response did not contain challenge info"))" + let message = """ + Unsupported challenge response during DeviceSRPAuth + \(response.challengeName ?? .sdkUnknown("Response did not contain challenge info")) + """ let error = SignInError.unknown(message: message) return SignInEvent(eventType: .throwAuthError(error)) } @@ -99,7 +102,7 @@ extension InitiateAuthDeviceSRP: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP+Calculations.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP+Calculations.swift index 59cf47a99f..d1846ff20d 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP+Calculations.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP+Calculations.swift @@ -10,6 +10,7 @@ import CryptoKit extension VerifyDevicePasswordSRP { + // swiftlint:disable:next function_parameter_count identifier_name func signature(deviceGroupKey: String, deviceKey: String, deviceSecret: String, @@ -28,6 +29,7 @@ extension VerifyDevicePasswordSRP { do { let dateStr = stateData.clientTimestamp.utcString let clientClass = type(of: srpClient) + // swiftlint:disable:next identifier_name let u = try clientClass.calculateUHexValue( clientPublicKeyHexValue: stateData.srpKeyPair.publicKeyHexValue, serverPublicKeyHexValue: serverPublicBHexString) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP.swift index 08153d6d1d..38b96dac1e 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/VerifyDevicePasswordSRP.swift @@ -99,7 +99,7 @@ extension VerifyDevicePasswordSRP: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/IntializeSignInFlow.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/IntializeSignInFlow.swift index 7f02972975..8ea604a1ff 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/IntializeSignInFlow.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/IntializeSignInFlow.swift @@ -30,7 +30,7 @@ struct InitializeSignInFlow: Action { let event = SignInEvent(eventType: .throwAuthError(.configuration(message: message))) return event } - + var deviceMetadata = DeviceMetadata.noData if let username = signInEventData.username { deviceMetadata = await DeviceMetadataHelper.getDeviceMetadata( diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/MigrateAuth/InitiateMigrateAuth.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/MigrateAuth/InitiateMigrateAuth.swift index 827d29cf22..ed1c98507f 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/MigrateAuth/InitiateMigrateAuth.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/MigrateAuth/InitiateMigrateAuth.swift @@ -82,7 +82,7 @@ extension InitiateMigrateAuth: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/CancelSignIn.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/CancelSignIn.swift index 9cf1df4217..eb5832ac4a 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/CancelSignIn.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/CancelSignIn.swift @@ -25,7 +25,7 @@ extension CancelSignIn: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/InitiateAuthSRP.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/InitiateAuthSRP.swift index 60c2ccb2be..a2c2e23f35 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/InitiateAuthSRP.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/InitiateAuthSRP.swift @@ -112,7 +112,7 @@ extension InitiateAuthSRP: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/ThrowSignInError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/ThrowSignInError.swift index ef123c9695..80222157e2 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/ThrowSignInError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/ThrowSignInError.swift @@ -29,7 +29,7 @@ extension ThrowSignInError: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP+Calculations.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP+Calculations.swift index 4d70f76521..cab2fbc412 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP+Calculations.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP+Calculations.swift @@ -10,6 +10,7 @@ import CryptoKit extension VerifyPasswordSRP { + // swiftlint:disable:next function_parameter_count func signature(userIdForSRP: String, saltHex: String, secretBlock: Data, @@ -28,6 +29,7 @@ extension VerifyPasswordSRP { let strippedPoolId = strippedPoolId(poolId) let dateStr = stateData.clientTimestamp.utcString let clientClass = type(of: srpClient) + // swiftlint:disable:next identifier_name let u = try clientClass.calculateUHexValue( clientPublicKeyHexValue: stateData.srpKeyPair.publicKeyHexValue, serverPublicKeyHexValue: serverPublicBHexString) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift index 8327dbd659..bf09ea4f63 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift @@ -118,7 +118,7 @@ extension VerifyPasswordSRP: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift index 0dc729a532..75bed80e89 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+ClientBehavior.swift @@ -9,6 +9,7 @@ import Foundation import Amplify import AuthenticationServices +// swiftlint:disable force_cast extension AWSCognitoAuthPlugin: AuthCategoryBehavior { public func signUp(username: String, @@ -27,7 +28,7 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior { public func confirmSignUp(for username: String, confirmationCode: String, options: AuthConfirmSignUpRequest.Options?) - async throws-> AuthSignUpResult { + async throws -> AuthSignUpResult { let options = options ?? AuthConfirmSignUpRequest.Options() let request = AuthConfirmSignUpRequest(username: username, code: confirmationCode, @@ -176,7 +177,6 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior { } as! TOTPSetupDetails } - public func verifyTOTPSetup( code: String, options: VerifyTOTPSetupRequest.Options? @@ -194,3 +194,4 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior { } } } +// swiftlint:enable force_cast diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+DeviceBehavior.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+DeviceBehavior.swift index fa055a30cf..4dc7c9c348 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+DeviceBehavior.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+DeviceBehavior.swift @@ -19,11 +19,13 @@ extension AWSCognitoAuthPlugin: AuthCategoryDeviceBehavior { userPoolFactory: authEnvironment.cognitoUserPoolFactory) return try await taskQueue.sync { return try await task.value - } as! [AuthDevice] + } as! [AuthDevice] // swiftlint:disable:this force_cast } - public func forgetDevice(_ device: AuthDevice? = nil, - options: AuthForgetDeviceRequest.Options? = nil) async throws { + public func forgetDevice( + _ device: AuthDevice? = nil, + options: AuthForgetDeviceRequest.Options? = nil + ) async throws { let options = options ?? AuthForgetDeviceRequest.Options() let request = AuthForgetDeviceRequest(device: device, options: options) let task = AWSAuthForgetDeviceTask(request, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+UserBehavior.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+UserBehavior.swift index 9d2608bf16..21df88d96b 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+UserBehavior.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/ClientBehavior/AWSCognitoAuthPlugin+UserBehavior.swift @@ -8,6 +8,7 @@ import Foundation import Amplify +// swiftlint:disable force_cast public extension AWSCognitoAuthPlugin { func fetchUserAttributes(options: AuthFetchUserAttributesRequest.Options? = nil) async throws -> [AuthUserAttribute] { @@ -50,7 +51,11 @@ public extension AWSCognitoAuthPlugin { let options = options ?? AuthAttributeResendConfirmationCodeRequest.Options() let request = AuthAttributeResendConfirmationCodeRequest( attributeKey: userAttributeKey, options: options) - let task = AWSAuthAttributeResendConfirmationCodeTask(request, authStateMachine: authStateMachine, userPoolFactory: authEnvironment.cognitoUserPoolFactory) + let task = AWSAuthAttributeResendConfirmationCodeTask( + request, + authStateMachine: authStateMachine, + userPoolFactory: authEnvironment.cognitoUserPoolFactory + ) return try await taskQueue.sync { return try await task.value } as! AuthCodeDeliveryDetails @@ -98,3 +103,4 @@ public extension AWSCognitoAuthPlugin { return try await taskHelper.getCurrentUser() } } +// swiftlint:enable force_cast diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/HubEvents/AuthHubEventHandler.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/HubEvents/AuthHubEventHandler.swift index c3ca0364e0..c8248e156f 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/HubEvents/AuthHubEventHandler.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/HubEvents/AuthHubEventHandler.swift @@ -67,7 +67,7 @@ class AuthHubEventHandler: AuthHubEventBehavior { } self?.handleSignInEvent(result) #endif - + case HubPayload.EventName.Auth.deleteUserAPI: guard let event = payload.data as? AWSAuthDeleteUserTask.AmplifyAuthTaskResult, case .success = event else { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/AWSCognitoUserPoolTokens.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/AWSCognitoUserPoolTokens.swift index c5f4daed06..38d34ba4d9 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/AWSCognitoUserPoolTokens.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/AWSCognitoUserPoolTokens.swift @@ -19,6 +19,7 @@ public struct AWSCognitoUserPoolTokens: AuthCognitoTokens { @available(*, deprecated, message: "Use of `expiration` is deprecated, use `exp` claim in the `idToken` or `accessToken` for expiries") public let expiration: Date + // swiftlint:disable:next line_length @available(*, deprecated, message: "Use of `init(idToken,accessToken,refreshToken:expiresIn)` is deprecated, use `exp` claim in the `idToken` or `accessToken` instead") public init(idToken: String, accessToken: String, @@ -30,6 +31,7 @@ public struct AWSCognitoUserPoolTokens: AuthCognitoTokens { self.expiration = Date().addingTimeInterval(TimeInterval(expiresIn)) } + // swiftlint:disable:next line_length @available(*, deprecated, message: "Use of `init(idToken,accessToken,refreshToken:expiration)` is deprecated, use `exp` claim in the `idToken` or `accessToken` instead") public init(idToken: String, accessToken: String, @@ -71,7 +73,7 @@ public struct AWSCognitoUserPoolTokens: AuthCognitoTokens { self.expiration = Date(timeIntervalSince1970: TimeInterval(expirationDoubleValue)) } } - + } extension AWSCognitoUserPoolTokens: Equatable { } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/MFAPreference.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/MFAPreference.swift index 521b6f4d8d..0b94b34d77 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/MFAPreference.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/MFAPreference.swift @@ -10,7 +10,7 @@ import Foundation /// Input for updating the MFA preference for a MFA Type public enum MFAPreference { - + // enabled: false case disabled diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Options/AWSAuthConfirmResetPasswordOptions.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Options/AWSAuthConfirmResetPasswordOptions.swift index 9a386c59e7..17de94fab0 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Options/AWSAuthConfirmResetPasswordOptions.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/Options/AWSAuthConfirmResetPasswordOptions.swift @@ -15,4 +15,3 @@ public struct AWSAuthConfirmResetPasswordOptions { self.metadata = metadata } } - diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/UserMFAPreference.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/UserMFAPreference.swift index 6f7068cfe8..a3724c25aa 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/UserMFAPreference.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/UserMFAPreference.swift @@ -16,9 +16,4 @@ public struct UserMFAPreference { /// nil if no preference public let preferred: MFAType? - internal init(enabled: Set?, preferred: MFAType?) { - self.enabled = enabled - self.preferred = preferred - } - } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/FetchAuthSessionOperationHelper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/FetchAuthSessionOperationHelper.swift index b9fdbc1d88..7aa1997b72 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/FetchAuthSessionOperationHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/FetchAuthSessionOperationHelper.swift @@ -10,8 +10,6 @@ import Amplify class FetchAuthSessionOperationHelper: DefaultLogger { - - typealias FetchAuthSessionCompletion = (Result) -> Void func fetch(_ authStateMachine: AuthStateMachine, @@ -181,7 +179,7 @@ class FetchAuthSessionOperationHelper: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift index 6399757df3..375216c8d5 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/Helpers/HostedUISignInHelper.swift @@ -59,7 +59,6 @@ struct HostedUISignInHelper: DefaultLogger { } } - private func doSignIn() async throws -> AuthSignInResult { let oauthConfiguration: OAuthConfigurationData @@ -156,11 +155,11 @@ struct HostedUISignInHelper: DefaultLogger { } } } - + public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/SRP/AmplifySRPClient.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/SRP/AmplifySRPClient.swift index bd76c0e862..de41eead55 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/SRP/AmplifySRPClient.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/SRP/AmplifySRPClient.swift @@ -13,7 +13,7 @@ struct AmplifySRPClient: SRPClientBehavior { let commonState: SRPCommonState let client: SRPClientState - + // swiftlint:disable identifier_name init(NHexValue: String, gHexValue: String) throws { guard let N = BigInt(NHexValue, radix: 16), let g = BigInt(gHexValue, radix: 16) @@ -36,6 +36,7 @@ struct AmplifySRPClient: SRPClientBehavior { return srpKeys } + // swiftlint:disable:next function_parameter_count func calculateSharedSecret(username: String, password: String, saltHexValue: String, @@ -120,5 +121,5 @@ struct AmplifySRPClient: SRPClientBehavior { return (saltData, verifierData) } - + // swiftlint:enable identifier_name } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift index dd16b203a0..dbe795e4fc 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCognitoIdentity+AuthErrorConvertible.swift @@ -102,7 +102,6 @@ extension AWSCognitoIdentity.TooManyRequestsException: AuthErrorConvertible { } } - extension AWSCognitoIdentity.LimitExceededException: AuthErrorConvertible { var fallbackDescription: String { "Too many requests error." } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift index 6179940724..0b3f3c2fa4 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Service/ErrorMapping/AWSCongnitoIdentityProvider+AuthErrorConvertible.swift @@ -160,7 +160,6 @@ extension InvalidLambdaResponseException: AuthErrorConvertible { } } - extension ExpiredCodeException: AuthErrorConvertible { var fallbackDescription: String { "Provided code has expired." } @@ -256,7 +255,6 @@ extension InvalidEmailRoleAccessPolicyException: AuthErrorConvertible { } } - extension InvalidSmsRoleAccessPolicyException: AuthErrorConvertible { var fallbackDescription: String { "Invalid SMS Role Access Policy error." } @@ -328,7 +326,6 @@ extension AWSCognitoIdentityProvider.ConcurrentModificationException: AuthErrorC } } - extension AWSCognitoIdentityProvider.EnableSoftwareTokenMFAException: AuthErrorConvertible { var fallbackDescription: String { "Unable to enable software token MFA" } @@ -355,7 +352,3 @@ extension AWSClientRuntime.UnknownAWSHTTPServiceError: AuthErrorConvertible { ) } } - - - - diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIConfigurationData.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIConfigurationData.swift index c22b127a88..4c62415442 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIConfigurationData.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/HostedUIConfigurationData.swift @@ -50,16 +50,6 @@ struct OAuthConfigurationData: Equatable { let scopes: [String] let signInRedirectURI: String let signOutRedirectURI: String - - init(domain: String, - scopes: [String], - signInRedirectURI: String, - signOutRedirectURI: String) { - self.domain = domain - self.scopes = scopes - self.signInRedirectURI = signInRedirectURI - self.signOutRedirectURI = signOutRedirectURI - } } extension OAuthConfigurationData: Codable { } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/IdentityPoolConfigurationData.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/IdentityPoolConfigurationData.swift index 3647fbfaa1..11e2474e48 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/IdentityPoolConfigurationData.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/IdentityPoolConfigurationData.swift @@ -11,12 +11,6 @@ struct IdentityPoolConfigurationData: Equatable { let poolId: String let region: String - init(poolId: String, - region: String) { - self.poolId = poolId - self.region = region - } - } extension IdentityPoolConfigurationData: Codable { } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/RespondToAuthChallenge.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/RespondToAuthChallenge.swift index 0ee7a963d3..c8a5297f86 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/RespondToAuthChallenge.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/RespondToAuthChallenge.swift @@ -53,7 +53,7 @@ extension RespondToAuthChallenge { let mfaTypesArray = try? JSONDecoder().decode( [String].self, from: Data(mfaTypeParameters.utf8) - ) + ) else { return .init() } let mfaTypes = mfaTypesArray.compactMap(MFAType.init(rawValue:)) diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/SRPStateData.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/SRPStateData.swift index 3d19c9140a..45e138e15c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/SRPStateData.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Data/SRPStateData.swift @@ -15,22 +15,6 @@ struct SRPStateData { let srpKeyPair: SRPKeys let clientTimestamp: Date - init( - username: String, - password: String, - NHexValue: String, - gHexValue: String, - srpKeyPair: SRPKeys, - clientTimestamp: Date - ) { - self.username = username - self.password = password - self.NHexValue = NHexValue - self.gHexValue = gHexValue - self.srpKeyPair = srpKeyPair - self.clientTimestamp = clientTimestamp - } - } extension SRPStateData: Equatable { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/AuthorizationError.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/AuthorizationError.swift index 8c1ed9c1e0..249c189781 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/AuthorizationError.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/AuthorizationError.swift @@ -23,7 +23,7 @@ extension AuthorizationError: AuthErrorConvertible { switch self { case .sessionExpired(let error): return .sessionExpired( - "Session expired", + "Session expired", "Invoke Auth.signIn to re-authenticate the user", error) case .configuration(let message): diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SetUpTOTPEvent.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SetUpTOTPEvent.swift index d21caecae7..387262e785 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SetUpTOTPEvent.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SetUpTOTPEvent.swift @@ -67,5 +67,4 @@ extension SetUpTOTPEvent.EventType: Equatable { } } - } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/CredentialStoreState+Debug.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/CredentialStoreState+Debug.swift index b12c8ec64f..4b9eb908af 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/CredentialStoreState+Debug.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/CredentialStoreState+Debug.swift @@ -35,7 +35,6 @@ extension CredentialStoreState: CustomDebugStringConvertible { return [type: additionalMetadataDictionary] } - var debugDescription: String { return (debugDictionary as AnyObject).description } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/MigrateSignInState+Debug.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/MigrateSignInState+Debug.swift index 0b7571271b..a0df091306 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/MigrateSignInState+Debug.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/MigrateSignInState+Debug.swift @@ -17,11 +17,11 @@ extension MigrateSignInState: CustomDebugDictionaryConvertible { case .notStarted: additionalMetadataDictionary = [:] - case .signingIn(_): + case .signingIn: additionalMetadataDictionary = [:] case .signedIn(let signedInData): additionalMetadataDictionary = ["SignedInData": signedInData.debugDictionary] - case .error(_): + case .error: additionalMetadataDictionary = [:] } return [type: additionalMetadataDictionary] diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/SignInState+Debug.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/SignInState+Debug.swift index 51d86499fe..1cba475ba8 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/SignInState+Debug.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/States/DebugInfo/SignInState+Debug.swift @@ -47,7 +47,7 @@ extension SignInState: CustomDebugDictionaryConvertible { case .resolvingTOTPSetup(let signInTOTPSetupState, let signInEventData): additionalMetadataDictionary = [ "SignInTOTPSetupState": signInTOTPSetupState.debugDictionary, - "SignInEventData" : signInEventData.debugDictionary] + "SignInEventData": signInEventData.debugDictionary] case .error: additionalMetadataDictionary = [:] } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift index 31b7d6b12e..75ba411059 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift @@ -25,7 +25,7 @@ extension SignInError { switch self { case .service(error: let serviceError): return serviceError is AWSCognitoIdentityProvider.PasswordResetRequiredException - default: + default: return false } } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authentication/AuthenticationState+Resolver.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authentication/AuthenticationState+Resolver.swift index 95d24ea6de..d7703d9482 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authentication/AuthenticationState+Resolver.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authentication/AuthenticationState+Resolver.swift @@ -7,12 +7,14 @@ extension AuthenticationState { + // swiftlint:disable:next nesting struct Resolver: StateMachineResolver { typealias StateType = AuthenticationState let defaultState = AuthenticationState.notConfigured init() { } + // swiftlint:disable:next cyclomatic_complexity func resolve( oldState: StateType, byApplying event: StateMachineEvent diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authorization/AuthorizationState+Resolver.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authorization/AuthorizationState+Resolver.swift index 46203130b8..51be1d9500 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authorization/AuthorizationState+Resolver.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/Authorization/AuthorizationState+Resolver.swift @@ -9,12 +9,14 @@ import Foundation extension AuthorizationState { + // swiftlint:disable:next type_body_length nesting struct Resolver: StateMachineResolver { typealias StateType = AuthorizationState let defaultState = AuthorizationState.notConfigured init() { } + // swiftlint:disable:next cyclomatic_complexity function_body_length func resolve( oldState: StateType, byApplying event: StateMachineEvent @@ -247,7 +249,7 @@ extension AuthorizationState { if case .sessionEstablished(let credentials) = event.isAuthorizationEvent { return .init(newState: .sessionEstablished(credentials)) } - + if case .throwError(let error) = event.isAuthorizationEvent { return .init(newState: .error(error)) } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/RefreshSession/RefreshSessionState+Resolver.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/RefreshSession/RefreshSessionState+Resolver.swift index a614bea112..94e09d0412 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/RefreshSession/RefreshSessionState+Resolver.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/RefreshSession/RefreshSessionState+Resolver.swift @@ -14,6 +14,7 @@ extension RefreshSessionState { var defaultState: RefreshSessionState = .notStarted + // swiftlint:disable:next cyclomatic_complexity func resolve(oldState: RefreshSessionState, byApplying event: StateMachineEvent) -> StateResolution { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/SignInState+Resolver.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/SignInState+Resolver.swift index 644e9fabc2..d95da1588c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/SignInState+Resolver.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/SignInState+Resolver.swift @@ -8,11 +8,13 @@ import Foundation extension SignInState { + // swiftlint:disable:next nesting struct Resolver: StateMachineResolver { typealias StateType = SignInState let defaultState = SignInState.notStarted + // swiftlint:disable:next cyclomatic_complexity function_body_length func resolve( oldState: SignInState, byApplying event: StateMachineEvent) @@ -296,7 +298,6 @@ extension SignInState { signInEventData) return .init(newState: signingInWithSRP, actions: resolution.actions) - case .resolvingTOTPSetup(let setUpTOTPState, let signInEventData): if case .finalizeSignIn(let signedInData) = event.isSignInEvent { @@ -341,7 +342,6 @@ extension SignInState { signInEventData) return .init(newState: settingUpTOTPState, actions: resolution.actions) - case .resolvingDeviceSrpa(let deviceSrpState): let signInMethod = SignInMethod.apiBased(.userSRP) if let signInEvent = event as? SignInEvent, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift index c43ec28007..baa46fc0d3 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift @@ -217,7 +217,10 @@ extension AuthPluginErrorConstants { static let confirmSignInMFASelectionResponseError: AuthPluginValidationErrorString = ( "challengeResponse", "challengeResponse for MFA selection can only have SMS_MFA or SOFTWARE_TOKEN_MFA.", - "Make sure that a valid challenge response is passed for confirmSignIn. Try using `MFAType.totp.challengeResponse` or `MFAType.sms.challengeResponse` as the challenge response" + """ + Make sure that a valid challenge response is passed for confirmSignIn. + Try using `MFAType.totp.challengeResponse` or `MFAType.sms.challengeResponse` as the challenge response + """ ) static let confirmResetPasswordUsernameError: AuthPluginValidationErrorString = ( @@ -335,7 +338,7 @@ extension AuthPluginErrorConstants { """ static let forbiddenError: RecoverySuggestion = """ - Check if you are allowed to make this request based on the web ACL thats associated with your user pool + Check if you are allowed to make this request based on the web ACL thats associated with your user pool """ static let concurrentModificationException: RecoverySuggestion = """ diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/DeviceMetadataHelper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/DeviceMetadataHelper.swift index 0065ae8819..f53ae871c3 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/DeviceMetadataHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/DeviceMetadataHelper.swift @@ -20,12 +20,10 @@ struct DeviceMetadataHelper { if case .deviceMetadata(let fetchedMetadata, _) = data { return fetchedMetadata } - } - catch KeychainStoreError.itemNotFound { + } catch KeychainStoreError.itemNotFound { let logger = (environment as? LoggerProvider)?.logger logger?.info("No existing device metadata found. \(environment)") - } - catch { + } catch { let logger = (environment as? LoggerProvider)?.logger logger?.error("Unable to fetch device metadata with error: \(error)") } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift index 8e23f842bb..02a2d74f62 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/UserPoolSignInHelper.swift @@ -100,8 +100,6 @@ struct UserPoolSignInHelper: DefaultLogger { return event } - - static func parseResponse( _ response: SignInResponseBehavior, for username: String, @@ -162,11 +160,11 @@ struct UserPoolSignInHelper: DefaultLogger { return SignInEvent(eventType: .throwAuthError(error)) } } - + public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/AuthUIPresentationAnchorPlaceholder.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/AuthUIPresentationAnchorPlaceholder.swift index 64469c240e..c15d072b39 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/AuthUIPresentationAnchorPlaceholder.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/AuthUIPresentationAnchorPlaceholder.swift @@ -15,9 +15,9 @@ typealias AuthUIPresentationAnchor = AuthUIPresentationAnchorPlaceholder /// It cannot be initialized and exists strictly to facilitate cross-platform compilation without requiring compiler /// checks thorughout the codebase. class AuthUIPresentationAnchorPlaceholder: Equatable { - + private init() {} - + public static func == (lhs: AuthUIPresentationAnchorPlaceholder, rhs: AuthUIPresentationAnchorPlaceholder) -> Bool { true diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift index c5e5b21835..45cc3124c2 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift @@ -70,7 +70,7 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior { #if os(iOS) || os(macOS) var authenticationSessionFactory = ASWebAuthenticationSession.init(url:callbackURLScheme:completionHandler:) - + private func createAuthenticationSession( url: URL, callbackURLScheme: String?, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Logging/AWSCognitoAuthPlugin+Log.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Logging/AWSCognitoAuthPlugin+Log.swift index 1f190abdc9..62898d9094 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Logging/AWSCognitoAuthPlugin+Log.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Logging/AWSCognitoAuthPlugin+Log.swift @@ -11,7 +11,7 @@ extension AWSCognitoAuthPlugin: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/HttpClientEngineProxy.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/HttpClientEngineProxy.swift index e2cd4dd7d1..82a6b939de 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/HttpClientEngineProxy.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/HttpClientEngineProxy.swift @@ -10,7 +10,7 @@ import ClientRuntime import Foundation protocol HttpClientEngineProxy: HttpClientEngine { - var target: HttpClientEngine? { set get } + var target: HttpClientEngine? { get set } } extension UserAgentSuffixAppender: HttpClientEngineProxy {} diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/RespondToAuthChallengeInput+Amplify.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/RespondToAuthChallengeInput+Amplify.swift index 358dab87aa..7ee75ff8b8 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/RespondToAuthChallengeInput+Amplify.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/RespondToAuthChallengeInput+Amplify.swift @@ -10,6 +10,7 @@ import AWSCognitoIdentityProvider extension RespondToAuthChallengeInput { + // swiftlint:disable:next function_parameter_count static func passwordVerifier(username: String, stateData: SRPStateData, session: String?, @@ -36,6 +37,7 @@ extension RespondToAuthChallengeInput { environment: environment) } + // swiftlint:disable:next function_parameter_count static func deviceSRP(username: String, environment: UserPoolEnvironment, deviceMetadata: DeviceMetadata, @@ -83,6 +85,7 @@ extension RespondToAuthChallengeInput { environment: environment) } + // swiftlint:disable:next function_parameter_count static func verifyChallenge( username: String, challengeType: CognitoIdentityProviderClientTypes.ChallengeNameType, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift index 6e16c26142..0fb50718c1 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthChangePasswordTask.swift @@ -57,5 +57,5 @@ class AWSAuthChangePasswordTask: AuthChangePasswordTask, DefaultLogger { proposedPassword: request.newPassword) _ = try await userPoolService.changePassword(input: input) } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthClearFederationToIdentityPoolTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthClearFederationToIdentityPoolTask.swift index 06dfe200c9..293ae92b2f 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthClearFederationToIdentityPoolTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthClearFederationToIdentityPoolTask.swift @@ -41,5 +41,5 @@ public class AWSAuthClearFederationToIdentityPoolTask: AuthClearFederationToIden log.verbose("Cleared federation") return } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift index 4bf0c1bc12..a7b1b03e90 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmResetPasswordTask.swift @@ -32,7 +32,7 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg throw validationError } do { - + try await confirmResetPassword() } catch let error as AuthErrorConvertible { throw error.authError @@ -44,7 +44,7 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg func confirmResetPassword() async throws { let userPoolEnvironment = try environment.userPoolEnvironment() let userPoolService = try userPoolEnvironment.cognitoUserPoolFactory() - + let clientMetaData = (request.options.pluginOptions as? AWSAuthConfirmResetPasswordOptions)?.metadata ?? [:] @@ -88,5 +88,5 @@ class AWSAuthConfirmResetPasswordTask: AuthConfirmResetPasswordTask, DefaultLogg _ = try await userPoolService.confirmForgotPassword(input: input) } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInTask.swift index cba88b1466..3c19a16d61 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignInTask.swift @@ -32,7 +32,7 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask, DefaultLogger { log.verbose("Starting execution") await taskHelper.didStateMachineConfigured() - //Check if we have a user pool configuration + // Check if we have a user pool configuration guard authConfiguration.getUserPoolConfiguration() != nil else { let message = AuthPluginErrorConstants.configurationError let authError = AuthError.configuration( diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift index 819e4e44c9..6a03e246b5 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthConfirmSignUpTask.swift @@ -42,7 +42,7 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger { _ = try await client.confirmSignUp(input: input) log.verbose("Received success") return AuthSignUpResult(.done, userID: nil) - } catch let error as AuthErrorConvertible { + } catch let error as AuthErrorConvertible { throw error.authError } catch { throw AuthError.configuration( @@ -52,5 +52,4 @@ class AWSAuthConfirmSignUpTask: AuthConfirmSignUpTask, DefaultLogger { ) } } - } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthDeleteUserTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthDeleteUserTask.swift index a684ed36d7..4539bcecba 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthDeleteUserTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthDeleteUserTask.swift @@ -48,7 +48,10 @@ class AWSAuthDeleteUserTask: AuthDeleteUserTask, DefaultLogger { log.verbose("Waiting for delete user to complete") for await state in stateSequences { guard case .configured(let authNState, _) = state else { - let error = AuthError.invalidState("Auth state should be in configured state and authentication state should be in deleting user state", AuthPluginErrorConstants.invalidStateError, nil) + let error = AuthError.invalidState( + "Auth state should be in configured state and authentication state should be in deleting user state", + AuthPluginErrorConstants.invalidStateError, + nil) throw error } @@ -85,5 +88,5 @@ class AWSAuthDeleteUserTask: AuthDeleteUserTask, DefaultLogger { await authStateMachine.send(event) await taskHelper.didStateMachineConfigured() } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthFetchSessionTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthFetchSessionTask.swift index 2995593ff6..7a00941ad9 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthFetchSessionTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthFetchSessionTask.swift @@ -32,5 +32,5 @@ class AWSAuthFetchSessionTask: AuthFetchSessionTask, DefaultLogger { return try await fetchAuthSessionHelper.fetch(authStateMachine, forceRefresh: doesNeedForceRefresh) } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift index 9df2af8c99..32402637a3 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthResendSignUpCodeTask.swift @@ -93,5 +93,5 @@ class AWSAuthResendSignUpCodeTask: AuthResendSignUpCodeTask, DefaultLogger { return deliveryDetails } - + } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInTask.swift index 3cb18018bf..3a68e3aeff 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignInTask.swift @@ -31,7 +31,7 @@ class AWSAuthSignInTask: AuthSignInTask, DefaultLogger { func execute() async throws -> AuthSignInResult { log.verbose("Starting execution") await taskHelper.didStateMachineConfigured() - //Check if we have a user pool configuration + // Check if we have a user pool configuration guard let userPoolConfiguration = authConfiguration.getUserPoolConfiguration() else { let message = AuthPluginErrorConstants.configurationError let authError = AuthError.configuration( diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignOutTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignOutTask.swift index 52c6b94f68..f5de608577 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignOutTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthSignOutTask.swift @@ -69,7 +69,7 @@ class AWSAuthSignOutTask: AuthSignOutTask, DefaultLogger { #else presentationAnchor = nil #endif - + let signOutData = SignOutEventData( globalSignOut: request.options.globalSignOut, presentationAnchor: presentationAnchor diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift index 7244ea854c..564b5c177e 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/AWSAuthWebUISignInTask.swift @@ -46,6 +46,6 @@ class AWSAuthWebUISignInTask: AuthWebUISignInTask, DefaultLogger { } } - + } #endif diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift index b3a456214d..acb63eacec 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/FetchMFAPreferenceTask.swift @@ -56,8 +56,8 @@ class FetchMFAPreferenceTask: AuthFetchMFAPreferenceTask, DefaultLogger { let input = GetUserInput(accessToken: accessToken) let result = try await userPoolService.getUser(input: input) - var enabledList: Set? = nil - var preferred: MFAType? = nil + var enabledList: Set? + var preferred: MFAType? for mfaValue in result.userMFASettingList ?? [] { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Helpers/AWSAuthTaskHelper.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Helpers/AWSAuthTaskHelper.swift index 5c9dbeaeae..44267909b1 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Helpers/AWSAuthTaskHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Helpers/AWSAuthTaskHelper.swift @@ -85,13 +85,13 @@ class AWSAuthTaskHelper: DefaultLogger { func getCurrentUser() async throws -> AuthUser { await didStateMachineConfigured() let authState = await authStateMachine.currentState - + guard case .configured(let authenticationState, _) = authState else { throw AuthError.configuration( "Plugin not configured", AuthPluginErrorConstants.configurationError) } - + switch authenticationState { case .notConfigured: throw AuthError.configuration("UserPool configuration is missing", AuthPluginErrorConstants.configurationError) @@ -112,7 +112,7 @@ class AWSAuthTaskHelper: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.auth.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthAttributeResendConfirmationCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthAttributeResendConfirmationCodeTask.swift index bac4785fa1..bd79d06294 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthAttributeResendConfirmationCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthAttributeResendConfirmationCodeTask.swift @@ -7,6 +7,7 @@ import Amplify +// swiftlint:disable:next line_length protocol AuthAttributeResendConfirmationCodeTask: AmplifyAuthTask where Request == AuthAttributeResendConfirmationCodeRequest, Success == AuthCodeDeliveryDetails, Failure == AuthError {} public extension HubPayload.EventName.Auth { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthSendUserAttributeVerificationCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthSendUserAttributeVerificationCodeTask.swift index 2399826053..1c7818e5cf 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthSendUserAttributeVerificationCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthSendUserAttributeVerificationCodeTask.swift @@ -7,6 +7,7 @@ import Amplify +// swiftlint:disable:next line_length protocol AuthSendUserAttributeVerificationCodeTask: AmplifyAuthTask where Request == AuthSendUserAttributeVerificationCodeRequest, Success == AuthCodeDeliveryDetails, Failure == AuthError {} public extension HubPayload.EventName.Auth { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributeTask.swift index 1c9807685f..eaadcd9e78 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributeTask.swift @@ -6,6 +6,7 @@ // import Amplify +// swiftlint:disable:next line_length protocol AuthUpdateUserAttributeTask: AmplifyAuthTask where Request == AuthUpdateUserAttributeRequest, Success == AuthUpdateAttributeResult, Failure == AuthError {} public extension HubPayload.EventName.Auth { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributesTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributesTask.swift index a81f4f592d..b16def3182 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributesTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/Protocols/UserTasks/AuthUpdateUserAttributesTask.swift @@ -6,6 +6,7 @@ // import Amplify +// swiftlint:disable:next line_length protocol AuthUpdateUserAttributesTask: AmplifyAuthTask where Request == AuthUpdateUserAttributesRequest, Success == [AuthUserAttributeKey: AuthUpdateAttributeResult], Failure == AuthError {} public extension HubPayload.EventName.Auth { diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift index 70d30b966b..763af3e80c 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthAttributeResendConfirmationCodeTask.swift @@ -37,7 +37,7 @@ class AWSAuthAttributeResendConfirmationCodeTask: AuthAttributeResendConfirmatio return devices } catch let error as AuthErrorConvertible { throw error.authError - } catch { + } catch { throw AuthError.configuration( "Unable to execute auth task", AuthPluginErrorConstants.configurationError, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthSendUserAttributeVerificationCodeTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthSendUserAttributeVerificationCodeTask.swift index 6acd247d98..0d8d09f435 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthSendUserAttributeVerificationCodeTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthSendUserAttributeVerificationCodeTask.swift @@ -39,7 +39,7 @@ class AWSAuthSendUserAttributeVerificationCodeTask: AuthSendUserAttributeVerific return devices } catch let error as AuthErrorConvertible { throw error.authError - } catch { + } catch { throw AuthError.configuration( "Unable to execute auth task", AuthPluginErrorConstants.configurationError, diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift index 40156b2e12..f5cf58d112 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Task/VerifyTOTPSetupTask.swift @@ -46,7 +46,7 @@ class VerifyTOTPSetupTask: AuthVerifyTOTPSetupTask, DefaultLogger { } } - func verifyTOTPSetup(with accessToken: String, userCode: String) async throws { + func verifyTOTPSetup(with accessToken: String, userCode: String) async throws { let userPoolService = try userPoolFactory() let friendlyDeviceName = (request.options.pluginOptions as? VerifyTOTPSetupOptions)?.friendlyDeviceName let input = VerifySoftwareTokenInput( diff --git a/AmplifyPlugins/Auth/Sources/AmplifyBigInteger/AmplifyBigIntHelper.swift b/AmplifyPlugins/Auth/Sources/AmplifyBigInteger/AmplifyBigIntHelper.swift index 9eb2fb8b40..3b8d78aa99 100644 --- a/AmplifyPlugins/Auth/Sources/AmplifyBigInteger/AmplifyBigIntHelper.swift +++ b/AmplifyPlugins/Auth/Sources/AmplifyBigInteger/AmplifyBigIntHelper.swift @@ -21,8 +21,8 @@ public enum AmplifyBigIntHelper { if byteCount > 1 && bytesArray[0] == 1 { var invertedBytes = [UInt8](repeating: 0, count: bytesArray.count) invertedBytes[0] = ~invertedBytes[0] - for i in 1 ..< bytesArray.count { - invertedBytes[i] = ~bytesArray[i] + for index in 1 ..< bytesArray.count { + invertedBytes[index] = ~bytesArray[index] } let unsignedInvertedBytes = AmplifyBigInt(unsignedData: invertedBytes) let twosComplementNum = unsignedInvertedBytes + AmplifyBigInt(1) diff --git a/AmplifyPlugins/Auth/Sources/AmplifySRP/HKDF.swift b/AmplifyPlugins/Auth/Sources/AmplifySRP/HKDF.swift index 9db66655e2..26aebf4545 100644 --- a/AmplifyPlugins/Auth/Sources/AmplifySRP/HKDF.swift +++ b/AmplifyPlugins/Auth/Sources/AmplifySRP/HKDF.swift @@ -9,6 +9,7 @@ import Foundation import CommonCrypto import CryptoKit +// swiftlint:disable identifier_name // https://tools.ietf.org/html/rfc5869 public enum HMACKeyDerivationFunction { @@ -28,10 +29,12 @@ public enum HMACKeyDerivationFunction { } @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) - private static func generateHKDF(keyingMaterial: Data, - salt: Data, - info: String?, - outputLength: Int) -> Data { + private static func generateHKDF( + keyingMaterial: Data, + salt: Data, + info: String?, + outputLength: Int + ) -> Data { let key = SymmetricKey(data: keyingMaterial) var hkdf: SymmetricKey if let info { @@ -83,3 +86,4 @@ public enum HMACKeyDerivationFunction { return Data(hmacFinal) } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPClientState.swift b/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPClientState.swift index 3641e83372..2bc92a7583 100644 --- a/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPClientState.swift +++ b/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPClientState.swift @@ -11,6 +11,7 @@ import AmplifyBigInteger public typealias BigInt = AmplifyBigInt +// swiftlint:disable identifier_name public struct SRPClientState { public let privateA: BigInt @@ -106,5 +107,5 @@ public struct SRPClientState { return (salt, passwordVerifier) } - +// swiftlint:enable identifier_name } diff --git a/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPCommonState.swift b/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPCommonState.swift index c549b0e719..524e96106a 100644 --- a/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPCommonState.swift +++ b/AmplifyPlugins/Auth/Sources/AmplifySRP/SRPCommonState.swift @@ -9,6 +9,7 @@ import Foundation import CryptoKit import AmplifyBigInteger +// swiftlint:disable identifier_name public struct SRPCommonState { /// Group Parameter N of SRP protocol @@ -37,3 +38,4 @@ public struct SRPCommonState { return BigInt(unsignedData: hashBytes) } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Core/AWSPluginsCore/API/APICategoryGraphQLBehaviorExtended.swift b/AmplifyPlugins/Core/AWSPluginsCore/API/APICategoryGraphQLBehaviorExtended.swift index 2f0a3f62d8..91d56f9763 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/API/APICategoryGraphQLBehaviorExtended.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/API/APICategoryGraphQLBehaviorExtended.swift @@ -33,7 +33,7 @@ public protocol APICategoryGraphQLCallbackBehavior { @discardableResult func mutate(request: GraphQLRequest, listener: GraphQLOperation.ResultListener?) -> GraphQLOperation - + func subscribe(request: GraphQLRequest, valueListener: GraphQLSubscriptionOperation.InProcessListener?, completionListener: GraphQLSubscriptionOperation.ResultListener?) diff --git a/AmplifyPlugins/Core/AWSPluginsCore/AWSPluginOptions.swift b/AmplifyPlugins/Core/AWSPluginsCore/AWSPluginOptions.swift index 039215ff5f..e0aac8de36 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/AWSPluginOptions.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/AWSPluginOptions.swift @@ -16,7 +16,7 @@ public struct AWSPluginOptions { /// name of the model public let modelName: String? - + public init(authType: AWSAuthorizationType?, modelName: String?) { self.authType = authType self.modelName = modelName diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.swift index 1f3edd8786..cce327aed2 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthModeStrategy.swift @@ -42,7 +42,7 @@ public protocol AuthModeStrategy: AnyObject { init() func authTypesFor(schema: ModelSchema, operation: ModelOperation) async -> AWSAuthorizationTypeIterator - + func authTypesFor(schema: ModelSchema, operations: [ModelOperation]) async -> AWSAuthorizationTypeIterator } @@ -95,7 +95,7 @@ public class AWSDefaultAuthModeStrategy: AuthModeStrategy { operation: ModelOperation) -> AWSAuthorizationTypeIterator { return AWSAuthorizationTypeIterator(withValues: []) } - + public func authTypesFor(schema: ModelSchema, operations: [ModelOperation]) -> AWSAuthorizationTypeIterator { return AWSAuthorizationTypeIterator(withValues: []) @@ -197,7 +197,7 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy { operation: ModelOperation) async -> AWSAuthorizationTypeIterator { return await authTypesFor(schema: schema, operations: [operation]) } - + /// Returns the union of authorization types for the provided schema for the given list of operations /// - Parameters: /// - schema: model schema @@ -213,7 +213,7 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy { } }) .sorted(by: AWSMultiAuthModeStrategy.comparator) - + // if there isn't a user signed in, returns only public or custom rules if let authDelegate = authDelegate, await !authDelegate.isUserLoggedIn() { sortedRules = sortedRules.filter { rule in @@ -225,5 +225,5 @@ public class AWSMultiAuthModeStrategy: AuthModeStrategy { } return AWSAuthorizationTypeIterator(withValues: applicableAuthTypes) } - + } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthService.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthService.swift index ab72c799a8..d0c279314c 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthService.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthService.swift @@ -69,7 +69,7 @@ public class AWSAuthService: AWSAuthServiceBehavior { } return .success(convertedDictionary) } - + /// Retrieves the Cognito token from the AuthCognitoTokensProvider public func getUserPoolAccessToken() async throws -> String { let authSession = try await Amplify.Auth.fetchAuthSession() diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthServiceBehavior.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthServiceBehavior.swift index e984116ede..6c302cc928 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthServiceBehavior.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthServiceBehavior.swift @@ -17,7 +17,7 @@ public protocol AWSAuthServiceBehavior: AnyObject { /// Retrieves the identity identifier of for the Auth service func getIdentityID() async throws -> String - + /// Retrieves the token from the Auth token provider func getUserPoolAccessToken() async throws -> String } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthSessionBehavior.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthSessionBehavior.swift index a74a36e390..36d71a87e8 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthSessionBehavior.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/AWSAuthSessionBehavior.swift @@ -17,37 +17,41 @@ import Amplify /// /// Types conforming to the `AuthSession` protocol support an `isSignedIn` flag. `isSignedIn` is true if a user has /// successfully completed a `signIn` flow, and has not subsequently signed out. -public protocol AWSAuthSessionBehavior : AuthSession { +public protocol AWSAuthSessionBehavior: AuthSession { - /// The concrete type holding the OIDC tokens from the authentication provider. Generally, this type will have at least - /// methods for retrieving an identity token and an access token. + /// The concrete type holding the OIDC tokens from the authentication provider. + /// Generally, this type will have at least methods for retrieving an identity token and an access token. associatedtype Tokens /// The result of the most recent attempt to get AWS Credentials. There is no guarantee that the credentials /// are not expired, but conforming types may have logic in place to automatically refresh the credentials. - /// The credentials may be fore either the unauthenticated or authenticated role, depending on the configuration of the - /// identity pool and the tokens used to retrieve the identity ID from Cognito. + /// The credentials may be fore either the unauthenticated or authenticated role, depending on the + /// configuration of the identity pool and the tokens used to retrieve the identity ID from Cognito. /// /// If the most recent attempt caused an error, the result will contain the details of the error. var awsCredentialsResult: Result { get } + // swiftlint:disable line_length /// The result of the most recent attempt to get a /// [Cognito identity pool identity ID](https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html#CognitoIdentity-GetId-response-IdentityId). - /// The identityID may represent either an unauthenticated or authenticated identity, depending on the configuration of the - /// identity pool and the tokens used to retrieve the identity ID from Cognito. + /// The identityID may represent either an unauthenticated or authenticated identity, + /// depending on the configuration of the identity pool and the tokens used to + /// retrieve the identity ID from Cognito. /// /// If the most recent attempt caused an error, the result will contain the details of the error. var identityIdResult: Result { get } + // swiftlint:enable line_length - /// The result of the most recent attempt to get the current user's `sub` (unique User ID). Depending on the underlying - /// implementation, the details of the user ID may vary, but it is expected that this value is the `sub` claim of the - /// OIDC identity and access tokens. + /// The result of the most recent attempt to get the current user's `sub` (unique User ID). + /// Depending on the underlying implementation, the details of the user ID may vary, + /// but it is expected that this value is the `sub` claim of the OIDC identity and access tokens. /// /// If the most recent attempt caused an error, the result will contain the details of the error. var userSubResult: Result { get } - /// The result of the most recent attempt to get the current user's `sub` (unique User ID). Depending on the underlying - /// implementation, the details of the tokens may vary, but it is expected that the type will have at least methods for + /// The result of the most recent attempt to get the current user's `sub` (unique User ID). + /// Depending on the underlying implementation, + /// the details of the tokens may vary, but it is expected that the type will have at least methods for /// retrieving an identity token and an access token. /// /// If the most recent attempt caused an error, the result will contain the details of the error. diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AmplifyAWSSignatureV4Signer.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AmplifyAWSSignatureV4Signer.swift index 4da2777291..015f2e8395 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AmplifyAWSSignatureV4Signer.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AmplifyAWSSignatureV4Signer.swift @@ -46,7 +46,10 @@ public class AmplifyAWSSignatureV4Signer: AWSSignatureV4Signer { signatureType: .requestHeaders, signingAlgorithm: .sigv4) - let httpRequest = await AWSSigV4Signer.sigV4SignedRequest(requestBuilder: requestBuilder, signingConfig: signingConfig) + let httpRequest = await AWSSigV4Signer.sigV4SignedRequest( + requestBuilder: requestBuilder, + signingConfig: signingConfig + ) return httpRequest } catch let error { throw AuthError.unknown("Unable to sign request", error) diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthAWSCredentialsProvider.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthAWSCredentialsProvider.swift index e9e6c7e6ac..c08e8821c8 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthAWSCredentialsProvider.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthAWSCredentialsProvider.swift @@ -13,7 +13,7 @@ public protocol AuthAWSCredentialsProvider { func getAWSCredentials() -> Result } -public extension AuthAWSCredentialsProvider where Self:AWSAuthSessionBehavior { +public extension AuthAWSCredentialsProvider where Self: AWSAuthSessionBehavior { /// Return the most recent Result of fetching the AWS Credentials. If the temporary credentials are expired, returns /// a `AuthError.sessionExpired` failure. func getAWSCredentials() -> Result { diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthCognitoIdentityProvider.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthCognitoIdentityProvider.swift index fe8d6bad45..f58cef8ce3 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthCognitoIdentityProvider.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthCognitoIdentityProvider.swift @@ -15,7 +15,7 @@ public protocol AuthCognitoIdentityProvider { func getUserSub() -> Result } -public extension AuthCognitoIdentityProvider where Self:AWSAuthSessionBehavior { +public extension AuthCognitoIdentityProvider where Self: AWSAuthSessionBehavior { func getIdentityId() -> Result { identityIdResult } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthTokenProvider.swift b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthTokenProvider.swift index b6fe5442e2..4c79d1d77b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthTokenProvider.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthTokenProvider.swift @@ -19,7 +19,7 @@ public struct BasicUserPoolTokenProvider: AuthTokenProvider { public init(authService: AWSAuthServiceBehavior) { self.authService = authService } - + public func getUserPoolAccessToken() async throws -> String { try await authService.getUserPoolAccessToken() } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStatus.swift b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStatus.swift index ee6c00b1e0..3b7ccee072 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStatus.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStatus.swift @@ -46,7 +46,10 @@ extension KeychainStatus: CustomStringConvertible { case .itemNotFound: return "The specified item could not be found in the keychain." case .missingEntitlement: - return "Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements." + return """ + Internal error when a required entitlement isn't present, + client has neither application-identifier nor keychain-access-groups entitlements. + """ case .unexpectedError(let status): return "Unexpected error has occurred with status: \(status)." } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift index e1f6934490..cbacba2e44 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift @@ -8,6 +8,7 @@ import Foundation import Security +// swiftlint:disable identifier_name public protocol KeychainStoreBehavior { @_spi(KeychainStore) @@ -16,14 +17,14 @@ public protocol KeychainStoreBehavior { /// - Parameter key: A String key use to look up the value in the Keychain /// - Returns: A string value func _getString(_ key: String) throws -> String - + @_spi(KeychainStore) /// Get a data value from the Keychain based on the key. /// This System Programming Interface (SPI) may have breaking changes in future updates. /// - Parameter key: A String key use to look up the value in the Keychain /// - Returns: A data value func _getData(_ key: String) throws -> Data - + @_spi(KeychainStore) /// Set a key-value pair in the Keychain. /// This System Programming Interface (SPI) may have breaking changes in future updates. @@ -31,7 +32,7 @@ public protocol KeychainStoreBehavior { /// - value: A string value to store in Keychain /// - key: A String key for the value to store in the Keychain func _set(_ value: String, key: String) throws - + @_spi(KeychainStore) /// Set a key-value pair in the Keychain. /// This iSystem Programming Interface (SPI) may have breaking changes in future updates. @@ -39,13 +40,13 @@ public protocol KeychainStoreBehavior { /// - value: A data value to store in Keychain /// - key: A String key for the value to store in the Keychain func _set(_ value: Data, key: String) throws - + @_spi(KeychainStore) /// Remove key-value pair from Keychain based on the provided key. /// This System Programming Interface (SPI) may have breaking changes in future updates. /// - Parameter key: A String key to delete the key-value pair func _remove(_ key: String) throws - + @_spi(KeychainStore) /// Removes all key-value pair in the Keychain. /// This System Programming Interface (SPI) may have breaking changes in future updates. @@ -187,7 +188,7 @@ public struct KeychainStore: KeychainStoreBehavior { throw KeychainStoreError.securityError(status) } } - + @_spi(KeychainStore) /// Removes all key-value pair in the Keychain. /// This System Programming Interface (SPI) may have breaking changes in future updates. @@ -219,7 +220,7 @@ extension KeychainStore { static let AttributeLabel = String(kSecAttrLabel) static let AttributeComment = String(kSecAttrComment) static let AttributeAccessible = String(kSecAttrAccessible) - + /** Attribute Accessible Constants */ static let AttributeAccessibleAfterFirstUnlockThisDeviceOnly = String(kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly) @@ -234,8 +235,9 @@ extension KeychainStore { /** Value Type Key Constants */ static let ValueData = String(kSecValueData) - + /** Indicates whether to treat macOS keychain items like iOS keychain items without setting kSecAttrSynchronizable */ static let UseDataProtectionKeyChain = String(kSecUseDataProtectionKeychain) } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift index 5d81c8b8d1..a638b2879b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift @@ -12,7 +12,7 @@ struct KeychainStoreAttributes { var itemClass: String = KeychainStore.Constants.ClassGenericPassword var service: String var accessGroup: String? - + } extension KeychainStoreAttributes { @@ -23,7 +23,7 @@ extension KeychainStoreAttributes { KeychainStore.Constants.AttributeService: service, KeychainStore.Constants.UseDataProtectionKeyChain: kCFBooleanTrue ] - + if let accessGroup = accessGroup { query[KeychainStore.Constants.AttributeAccessGroup] = accessGroup } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift index c288ec0b38..4de28d4697 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreError.swift @@ -78,7 +78,9 @@ extension KeychainStoreError: AmplifyError { } return """ To use Auth in a macOS project, you'll need to enable the Keychain Sharing capability. - This capability is required because Auth uses the Data Protection Keychain on macOS as a platform best practice. See TN3137: macOS keychain APIs and implementations for more information on how Keychain works on macOS and the Keychain Sharing entitlement. + This capability is required because Auth uses the Data Protection Keychain on macOS as + a platform best practice. See TN3137: macOS keychain APIs and implementations for more + information on how Keychain works on macOS and the Keychain Sharing entitlement. For more information on adding capabilities to your application, see Xcode Capabilities. """ #else diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/AuthRuleDecorator.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/AuthRuleDecorator.swift index 4c70689a10..0cf0f79d04 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/AuthRuleDecorator.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/AuthRuleDecorator.swift @@ -198,7 +198,7 @@ private extension AuthRules { return authType == provider.toAWSAuthorizationType() } } - + func filterBy(ownerFieldType: ModelFieldType, modelSchema: ModelSchema) -> AuthRules { return filter { diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ConflictResolutionDecorator.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ConflictResolutionDecorator.swift index 72ed86a415..7d17b01e57 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ConflictResolutionDecorator.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ConflictResolutionDecorator.swift @@ -18,7 +18,7 @@ public struct ConflictResolutionDecorator: ModelBasedGraphQLDocumentDecorator { private let lastSync: Int64? private let graphQLType: GraphQLOperationType private var primaryKeysOnly: Bool - + public init(version: Int? = nil, lastSync: Int64? = nil, graphQLType: GraphQLOperationType, @@ -93,8 +93,10 @@ public struct ConflictResolutionDecorator: ModelBasedGraphQLDocumentDecorator { if !primaryKeysOnly || graphQLType == .mutation { // Continue to add version fields for all levels, for backwards compatibility // Reduce the selection set only when the type is "subscription" and "query" - // (specifically for syncQuery). Selection set for mutation should not be reduced because it needs to be the full selection set to send mutation events to older iOS clients, which do not have the reduced subscription - // selection set. subscriptions and sync query is to receive data, so it can be reduced to allow decoding to the + // (specifically for syncQuery). Selection set for mutation should not be reduced + // because it needs to be the full selection set to send mutation events to older iOS clients, + // which do not have the reduced subscription selection set. + // subscriptions and sync query is to receive data, so it can be reduced to allow decoding to the // LazyReference type. selectionSet.children.forEach { child in addConflictResolution(selectionSet: child, diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelDecorator.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelDecorator.swift index 3a42420f98..7a7ef66cfb 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelDecorator.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelDecorator.swift @@ -15,7 +15,7 @@ public struct ModelDecorator: ModelBasedGraphQLDocumentDecorator { private let model: Model private let mutationType: GraphQLMutationType - + public init(model: Model, mutationType: GraphQLMutationType) { self.model = model self.mutationType = mutationType diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelIdDecorator.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelIdDecorator.swift index fb23beb1c1..07a9a2d523 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelIdDecorator.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Decorator/ModelIdDecorator.swift @@ -14,7 +14,7 @@ public struct ModelIdDecorator: ModelBasedGraphQLDocumentDecorator { private var identifierFields = [(name: String, value: GraphQLDocumentValueRepresentable, type: String)]() public init(model: Model, schema: ModelSchema) { - + var firstField = true self.identifierFields = model.identifier(schema: schema).fields.compactMap { fieldName, _ in guard let value = model.graphQLInputForPrimaryKey(modelFieldName: fieldName, @@ -29,7 +29,7 @@ public struct ModelIdDecorator: ModelBasedGraphQLDocumentDecorator { } } } - + public init(identifierFields: [(name: String, value: Persistable)]) { var firstField = true identifierFields.forEach { name, value in @@ -37,7 +37,7 @@ public struct ModelIdDecorator: ModelBasedGraphQLDocumentDecorator { firstField = false } } - + public init(identifiers: [LazyReferenceIdentifier]) { var firstField = true identifiers.forEach({ identifier in diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/GraphQLQuery.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/GraphQLQuery.swift index 0b89ba83e6..2f86d9cb44 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/GraphQLQuery.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/GraphQLQuery.swift @@ -20,7 +20,7 @@ public struct GraphQLQuery: SingleDirectiveGraphQLDocument { self.inputs = inputs self.selectionSet = selectionSet } - + @available(*, deprecated, message: """ Init with modelType is deprecated, use init with modelSchema instead. """) diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/ModelBasedGraphQLDocumentBuilder.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/ModelBasedGraphQLDocumentBuilder.swift index be0558530b..a737d57d2f 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/ModelBasedGraphQLDocumentBuilder.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLDocument/ModelBasedGraphQLDocumentBuilder.swift @@ -36,7 +36,7 @@ public struct ModelBasedGraphQLDocumentBuilder { if primaryKeysOnly && ModelRegistry.modelType(from: modelSchema.name)?.rootPath == nil { primaryKeysOnly = false } - + switch operationType { case .query: self.document = GraphQLQuery(modelSchema: modelSchema, primaryKeysOnly: primaryKeysOnly) diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+AnyModelWithSync.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+AnyModelWithSync.swift index b779199e53..cdc367dde3 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+AnyModelWithSync.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+AnyModelWithSync.swift @@ -44,7 +44,7 @@ protocol ModelSyncGraphQLRequestFactory { subscriptionType: GraphQLSubscriptionType, claims: IdentityClaimsDictionary, authType: AWSAuthorizationType?) -> GraphQLRequest - + static func syncQuery(modelSchema: ModelSchema, where predicate: QueryPredicate?, limit: Int?, @@ -210,7 +210,7 @@ extension GraphQLRequest: ModelSyncGraphQLRequestFactory { decodePath: document.name, options: requestOptions) } - + public static func syncQuery(modelSchema: ModelSchema, where predicate: QueryPredicate? = nil, limit: Int? = nil, diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+Model.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+Model.swift index 6e55f0d929..7229c4ea1b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+Model.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/GraphQLRequest/GraphQLRequest+Model.swift @@ -56,12 +56,12 @@ protocol ModelGraphQLRequestFactory { byIdentifier id: String, includes: IncludedAssociations) -> GraphQLRequest where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default - + static func get(_ modelType: M.Type, byIdentifier id: ModelIdentifier, includes: IncludedAssociations) -> GraphQLRequest where M: ModelIdentifiable - + // MARK: Mutation /// Creates a `GraphQLRequest` that represents a mutation of a given `type` for a `model` instance. @@ -181,7 +181,7 @@ extension GraphQLRequest: ModelGraphQLRequestFactory { type: GraphQLMutationType) -> GraphQLRequest { mutation(of: model, modelSchema: model.schema, where: predicate, includes: includes, type: type) } - + public static func mutation(of model: M, modelSchema: ModelSchema, where predicate: QueryPredicate? = nil, @@ -190,12 +190,12 @@ extension GraphQLRequest: ModelGraphQLRequestFactory { var documentBuilder = ModelBasedGraphQLDocumentBuilder(modelSchema: modelSchema, operationType: .mutation) documentBuilder.add(decorator: DirectiveNameDecorator(type: type)) - + if let modelPath = M.rootPath as? ModelPath { let associations = includes(modelPath) documentBuilder.add(decorator: IncludeAssociationDecorator(associations)) } - + switch type { case .create: documentBuilder.add(decorator: ModelDecorator(model: model, mutationType: type)) @@ -239,14 +239,14 @@ extension GraphQLRequest: ModelGraphQLRequestFactory { responseType: M?.self, decodePath: document.name) } - + public static func get(_ modelType: M.Type, byIdentifier id: String, includes: IncludedAssociations = { _ in [] }) -> GraphQLRequest where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default { return .get(modelType, byId: id, includes: includes) } - + public static func get(_ modelType: M.Type, byIdentifier id: ModelIdentifier, includes: IncludedAssociations = { _ in [] }) -> GraphQLRequest @@ -254,20 +254,20 @@ extension GraphQLRequest: ModelGraphQLRequestFactory { var documentBuilder = ModelBasedGraphQLDocumentBuilder(modelSchema: modelType.schema, operationType: .query) documentBuilder.add(decorator: DirectiveNameDecorator(type: .get)) - + if let modelPath = modelType.rootPath as? ModelPath { let associations = includes(modelPath) documentBuilder.add(decorator: IncludeAssociationDecorator(associations)) } documentBuilder.add(decorator: ModelIdDecorator(identifierFields: id.fields)) let document = documentBuilder.build() - + return GraphQLRequest(document: document.stringValue, variables: document.variables, responseType: M?.self, decodePath: document.name) } - + public static func list(_ modelType: M.Type, where predicate: QueryPredicate? = nil, includes: IncludedAssociations = { _ in [] }, diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift index 18acdaa684..2e4c075b2c 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model+GraphQL.swift @@ -39,7 +39,7 @@ extension Model { for (modelField, modelFieldValue) in fields { let name = modelField.name - + guard let value = modelFieldValue else { // Scenario: When there is no model field value, set `nil` for removal of values or deassociation. // 1. It is unnessessary to set `nil` values for create mutations. @@ -68,7 +68,7 @@ extension Model { // 3. Set field values to `nil` for removal of values. input.updateValue(nil, forKey: name) } - + continue } diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift index 61ab94efe8..b926808de4 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/SelectionSet.swift @@ -56,14 +56,14 @@ extension SelectionSet { if field._isBelongsToOrHasOne { recursive = false } - + let child = SelectionSet(value: .init(name: field.name, fieldType: .model)) if primaryKeysOnly { child.withModelFields(schema.primaryKey.fields, recursive: recursive, primaryKeysOnly: primaryKeysOnly) } else { child.withModelFields(schema.graphQLFields, recursive: recursive, primaryKeysOnly: primaryKeysOnly) } - + self.addChild(settingParentOf: child) } } else { diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata.swift index bcecd4e60e..d6723f4835 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/ModelSync/ModelSyncMetadata.swift @@ -13,7 +13,7 @@ public struct ModelSyncMetadata: Model { /// The timestamp (in Unix seconds) at which the last sync was started, as reported by the service public var lastSync: Int64? - + /// The sync predicate for this model, extracted out from the sync expression. public var syncPredicate: String? diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift index 9ddac1677d..718e3348f6 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Sync/MutationSync/MutationSyncMetadata+Schema.swift @@ -37,7 +37,6 @@ extension MutationSyncMetadata { } } - extension MutationSyncMetadata: ModelIdentifiable { public typealias IdentifierProtocol = ModelIdentifier public typealias IdentifierFormat = ModelIdentifierFormat.Default diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/PluginClientEngine.swift b/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/PluginClientEngine.swift index f779aa7fbe..6ba1ab83aa 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/PluginClientEngine.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/PluginClientEngine.swift @@ -23,4 +23,3 @@ public func baseClientEngine( #endif return baseClientEngine } - diff --git a/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/UserAgentSuffixAppender.swift b/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/UserAgentSuffixAppender.swift index 863fa636bf..49c3adf55b 100644 --- a/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/UserAgentSuffixAppender.swift +++ b/AmplifyPlugins/Core/AWSPluginsCore/Utils/CustomHttpClientEngine/UserAgentSuffixAppender.swift @@ -10,7 +10,7 @@ import ClientRuntime @_spi(InternalAmplifyPluginExtension) public class UserAgentSuffixAppender: AWSPluginExtension { @_spi(InternalHttpEngineProxy) - public var target: HttpClientEngine? = nil + public var target: HttpClientEngine? public let suffix: String private let userAgentKey = "User-Agent" diff --git a/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift b/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift index 8c5d7cfa62..d0d87929a9 100644 --- a/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift +++ b/AmplifyPlugins/Core/AWSPluginsTestCommon/MockAWSAuthService.swift @@ -42,7 +42,7 @@ public class MockAWSAuthService: AWSAuthServiceBehavior { return identityId ?? "IdentityId" } - + public func getUserPoolAccessToken() async throws -> String { interactions.append(#function) if let error = getTokenError { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift index 36eeeca8c2..a7a128f638 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift @@ -16,7 +16,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion: @escaping DataStoreCallback) { save(model, modelSchema: model.schema, where: condition, completion: completion) } - + public func save(_ model: M, where condition: QueryPredicate? = nil) async throws -> M { try await save(model, modelSchema: model.schema, where: condition) @@ -56,7 +56,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion(.failure(error)) } } - + public func save(_ model: M, modelSchema: ModelSchema, where condition: QueryPredicate? = nil) async throws -> M { @@ -107,7 +107,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { identifier: DefaultModelIdentifier.makeDefault(id: identifier), completion: completion) } - + public func query(_ modelType: M.Type, byIdentifier identifier: String) async throws -> M? where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default { @@ -124,7 +124,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { identifier: identifier, completion: completion) } - + public func query(_ modelType: M.Type, byIdentifier identifier: ModelIdentifier) async throws -> M? where M: ModelIdentifiable { @@ -154,7 +154,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { } } } - + private func queryByIdentifier(_ modelType: M.Type, modelSchema: ModelSchema, identifier: ModelIdentifierProtocol) async throws -> M? { @@ -177,7 +177,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { paginate: paginationInput, completion: completion) } - + public func query(_ modelType: M.Type, where predicate: QueryPredicate? = nil, sort sortInput: QuerySortInput? = nil, @@ -212,7 +212,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion(.failure(error)) } } - + public func query(_ modelType: M.Type, modelSchema: ModelSchema, where predicate: QueryPredicate? = nil, @@ -233,7 +233,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { try await delete(modelType, modelSchema: modelType.schema, withId: id, where: predicate) } - + @available(*, deprecated, renamed: "delete(withIdentifier:)") public func delete(_ modelType: M.Type, modelSchema: ModelSchema, @@ -264,7 +264,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { where: predicate, completion: completion) } - + public func delete(_ modelType: M.Type, withIdentifier identifier: String, where predicate: QueryPredicate? = nil) async throws @@ -285,7 +285,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { where: predicate, completion: completion) } - + public func delete(_ modelType: M.Type, withIdentifier identifier: ModelIdentifier, where predicate: QueryPredicate? = nil) async throws where M: ModelIdentifiable { @@ -319,7 +319,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { } } - + private func deleteByIdentifier(_ modelType: M.Type, modelSchema: ModelSchema, identifier: ModelIdentifierProtocol, @@ -336,7 +336,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion: @escaping DataStoreCallback) { delete(model, modelSchema: model.schema, where: predicate, completion: completion) } - + public func delete(_ model: M, where predicate: QueryPredicate? = nil) async throws { try await delete(model, modelSchema: model.schema, where: predicate) @@ -361,7 +361,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { } } - + public func delete(_ model: M, modelSchema: ModelSchema, where predicate: QueryPredicate? = nil) async throws { @@ -377,7 +377,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion: @escaping DataStoreCallback) { delete(modelType, modelSchema: modelType.schema, where: predicate, completion: completion) } - + public func delete(_ modelType: M.Type, where predicate: QueryPredicate) async throws { try await delete(modelType, modelSchema: modelType.schema, where: predicate) @@ -408,7 +408,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion(.failure(error)) } } - + public func delete(_ modelType: M.Type, modelSchema: ModelSchema, where predicate: QueryPredicate) async throws { @@ -425,7 +425,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion(result) } } - + public func start() async throws { _ = try await withCheckedThrowingContinuation { (continuation: CheckedContinuation, Error>) in start { result in @@ -454,7 +454,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { } } } - + public func stop() async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in stop { result in @@ -488,7 +488,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { } } } - + public func clear() async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in clear { result in diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift index 76302653f2..ca41efd230 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift @@ -9,7 +9,7 @@ import Amplify import Combine extension AWSDataStorePlugin: DataStoreSubscribeBehavior { - + public var publisher: AnyPublisher { _ = initStorageEngineAndStartSync() // Force-unwrapping: The optional 'dataStorePublisher' is expected @@ -25,7 +25,7 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior { let runner = ObserveTaskRunner(publisher: publisher(for: modelType.modelName)) return runner.sequence } - + public func observeQuery(for modelType: M.Type, where predicate: QueryPredicate?, sort sortInput: QuerySortInput?) -> AmplifyAsyncThrowingSequence> { @@ -53,7 +53,6 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior { case .failure(let error): return Fatal.preconditionFailure("Unable to get storage adapter \(error.localizedDescription)") } - } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift index 5f775a0e69..cdcbbc2bfb 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift @@ -22,7 +22,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin { /// The Publisher that sends mutation events to subscribers var dataStorePublisher: ModelSubcriptionBehavior? - + var dataStoreStateSubject = PassthroughSubject() var dispatchedModelSyncedEvents: [ModelName: AtomicValue] @@ -108,7 +108,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin { self.dispatchedModelSyncedEvents = [:] } #endif - + /// Internal initializer for testing init(modelRegistration: AmplifyModelRegistration, configuration dataStoreConfiguration: DataStoreConfiguration = .testDefault(), @@ -142,7 +142,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin { /// them to `StorageEngine.setUp(modelSchemas:)` public func configure(using amplifyConfiguration: Any?) throws { modelRegistration.registerModels(registry: ModelRegistry.self) - + for modelSchema in ModelRegistry.modelSchemas { dispatchedModelSyncedEvents[modelSchema.name] = AtomicValue(initialValue: false) configuration.updateIsEagerLoad(modelSchema: modelSchema) @@ -151,7 +151,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin { ModelListDecoderRegistry.registerDecoder(DataStoreListDecoder.self) ModelProviderRegistry.registerDecoder(DataStoreModelDecoder.self) } - + /// Initializes the underlying storage engine /// - Returns: success if the engine is successfully initialized or /// a failure with a DataStoreError diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift index 04487a2ed0..564918daa2 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration+Helper.swift @@ -83,7 +83,7 @@ extension DataStoreConfiguration { authModeStrategy: authModeStrategy) } #endif - + #if os(watchOS) /// Default configuration with subscriptions disabled for watchOS. DataStore uses subscriptions via websockets, /// which work on the watchOS simulator but not on the device. Running DataStore on watchOS with subscriptions @@ -98,7 +98,7 @@ extension DataStoreConfiguration { .custom() } #endif - + #if os(watchOS) /// Internal method for testing static func testDefault(disableSubscriptions: @escaping () -> Bool = { false }) -> DataStoreConfiguration { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift index 96271bd008..a1c3ec8788 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift @@ -71,7 +71,7 @@ public struct DataStoreConfiguration { public var authModeStrategyType: AuthModeStrategyType public let disableSubscriptions: () -> Bool - + #if os(watchOS) init(errorHandler: @escaping DataStoreErrorHandler, conflictHandler: @escaping DataStoreConflictHandler, diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/InternalDatastoreConfiguration.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/InternalDatastoreConfiguration.swift index 55fb1c8523..f70585d5a1 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/InternalDatastoreConfiguration.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/InternalDatastoreConfiguration.swift @@ -16,7 +16,7 @@ struct InternalDatastoreConfiguration { /// Configuration of the query against the local storage, whether it should load /// the belongs-to/has-one associations or not. /// - ///`isEagerLoad` is true by default, unless the models contain the rootPath + /// `isEagerLoad` is true by default, unless the models contain the rootPath /// which is indication of the codegen that supports for lazy loading. var isEagerLoad: Bool = true @@ -30,12 +30,12 @@ struct InternalDatastoreConfiguration { /// Configuration provided during Datastore initialization, this is a `public` configuration. let pluginConfiguration: DataStoreConfiguration - - mutating func updateIsSyncEnabled(_ isEnabled: Bool) { + + mutating func updateIsSyncEnabled(_ isEnabled: Bool) { self.isSyncEnabled = isEnabled } - mutating func updateIsEagerLoad(modelSchema: ModelSchema) { + mutating func updateIsEagerLoad(modelSchema: ModelSchema) { guard isEagerLoad else { return } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListDecoder.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListDecoder.swift index ccacde105a..9241da72e2 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListDecoder.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListDecoder.swift @@ -10,30 +10,30 @@ import Amplify import Combine public struct DataStoreListDecoder: ModelListDecoder { - + struct Metadata: Codable { let dataStoreAssociatedIdentifiers: [String] let dataStoreAssociatedFields: [String] } - + /// Creates a data structure that is capable of initializing a `List` with /// lazy-load capabilities when the list is being decoded. static func lazyInit(associatedIds: [String], associatedWith: [String]) -> [String: Any?] { return [ "dataStoreAssociatedIdentifiers": associatedIds, - "dataStoreAssociatedFields": associatedWith, + "dataStoreAssociatedFields": associatedWith ] } - + public static func decode(modelType: ModelType.Type, decoder: Decoder) -> AnyModelListProvider? { shouldDecodeToDataStoreListProvider(modelType: modelType, decoder: decoder)?.eraseToAnyModelListProvider() } - + public static func shouldDecodeToDataStoreListProvider(modelType: ModelType.Type, decoder: Decoder) -> DataStoreListProvider? { if let metadata = try? Metadata.init(from: decoder) { return DataStoreListProvider(metadata: metadata) } - + let json = try? JSONValue(from: decoder) switch json { case .array: diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListProvider.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListProvider.swift index c754725026..59aee21603 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListProvider.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreListProvider.swift @@ -28,7 +28,7 @@ public class DataStoreListProvider: ModelListProvider { init(_ elements: [Element]) { self.loadedState = .loaded(elements) } - + public func getState() -> ModelListProviderState { switch loadedState { case .notLoaded(let associatedIdentifiers, let associatedFields): @@ -37,7 +37,7 @@ public class DataStoreListProvider: ModelListProvider { return .loaded(elements) } } - + public func load() async throws -> [Element] { switch loadedState { case .loaded(let elements): @@ -59,7 +59,7 @@ public class DataStoreListProvider: ModelListProvider { self.log.verbose("Loading List of \(Element.schema.name) by \(associatedFields) == \(associatedIdentifiers) ") predicate = QueryPredicateGroup(type: .and, predicates: queryPredicates) } - + do { let elements = try await Amplify.DataStore.query(Element.self, where: predicate) self.loadedState = .loaded(elements) @@ -71,7 +71,7 @@ public class DataStoreListProvider: ModelListProvider { error) } catch { throw error - + } } } @@ -79,13 +79,13 @@ public class DataStoreListProvider: ModelListProvider { public func hasNextPage() -> Bool { false } - + public func getNextPage() async throws -> List { throw CoreError.clientValidation("There is no next page.", "Only call `getNextPage()` when `hasNextPage()` is true.", nil) } - + public func encode(to encoder: Encoder) throws { switch loadedState { case .notLoaded(let associatedIdentifiers, diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelDecoder.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelDecoder.swift index 647785d78f..54ede2c97c 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelDecoder.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelDecoder.swift @@ -10,14 +10,14 @@ import Amplify import SQLite public struct DataStoreModelDecoder: ModelProviderDecoder { - + public static let DataStoreSource = "DataStore" - + /// Metadata that contains the foreign key value of a parent model, which is the primary key of the model to be loaded. struct Metadata: Codable { let identifiers: [LazyReferenceIdentifier] let source: String - + init(identifiers: [LazyReferenceIdentifier], source: String = DataStoreSource) { self.identifiers = identifiers self.source = source @@ -27,7 +27,7 @@ public struct DataStoreModelDecoder: ModelProviderDecoder { try? JSONSerialization.jsonObject(with: JSONEncoder().encode(self)) } } - + /// Create a SQLite payload that is capable of initializting a LazyReference, by decoding to `DataStoreModelDecoder.Metadata`. static func lazyInit(identifiers: [LazyReferenceIdentifier]) -> Metadata? { if identifiers.isEmpty { @@ -35,7 +35,7 @@ public struct DataStoreModelDecoder: ModelProviderDecoder { } return Metadata(identifiers: identifiers) } - + public static func decode(modelType: ModelType.Type, decoder: Decoder) -> AnyModelProvider? { if let metadata = try? DataStoreModelDecoder.Metadata(from: decoder) { if metadata.source == DataStoreSource { @@ -44,11 +44,11 @@ public struct DataStoreModelDecoder: ModelProviderDecoder { return nil } } - + if let model = try? ModelType.init(from: decoder) { return DataStoreModelProvider(model: model).eraseToAnyModelProvider() } - + return nil } } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelProvider.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelProvider.swift index e6e98f3f8d..4b43c7de2f 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelProvider.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Core/DataStoreModelProvider.swift @@ -9,21 +9,21 @@ import Foundation import Amplify import Combine -public class DataStoreModelProvider: ModelProvider { +public class DataStoreModelProvider: ModelProvider { var loadedState: ModelProviderState - + // Create a "not loaded" model provider with the identifier metadata, useful for hydrating the model init(metadata: DataStoreModelDecoder.Metadata) { self.loadedState = .notLoaded(identifiers: metadata.identifiers) } - + // Create a "loaded" model provider with the model instance init(model: ModelType?) { self.loadedState = .loaded(model: model) } - + // MARK: - APIs - + public func load() async throws -> ModelType? { switch loadedState { case .notLoaded(let identifiers): @@ -46,18 +46,18 @@ public class DataStoreModelProvider: ModelProvider { return model } } - + public func getState() -> ModelProviderState { loadedState } - + public func encode(to encoder: Encoder) throws { switch loadedState { case .notLoaded(let identifiers): let metadata = DataStoreModelDecoder.Metadata(identifiers: identifiers ?? []) var container = encoder.singleValueContainer() try container.encode(metadata) - + case .loaded(let element): try element.encode(to: encoder) } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Migration/ModelSyncMetadataMigration.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Migration/ModelSyncMetadataMigration.swift index 08dffbe272..0a0eb72e03 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Migration/ModelSyncMetadataMigration.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Migration/ModelSyncMetadataMigration.swift @@ -11,17 +11,17 @@ import SQLite import AWSPluginsCore class ModelSyncMetadataMigration: ModelMigration { - + weak var storageAdapter: SQLiteStorageEngineAdapter? - + func apply() throws { try performModelMetadataSyncPredicateUpgrade() } - + init(storageAdapter: SQLiteStorageEngineAdapter? = nil) { self.storageAdapter = storageAdapter } - + /// Add the new syncPredicate column for the ModelSyncMetadata system table. /// /// ModelSyncMetadata's syncPredicate column was added in Amplify version 2.22.0 to @@ -47,7 +47,7 @@ class ModelSyncMetadataMigration: ModelMigration { log.debug("Detected ModelSyncMetadata table has syncPredicate column. No migration needed") return false } - + log.debug("Detected ModelSyncMetadata table exists without syncPredicate column.") guard let storageAdapter = storageAdapter else { log.debug("Missing SQLiteStorageEngineAdapter for model migration") @@ -75,7 +75,7 @@ class ModelSyncMetadataMigration: ModelMigration { guard let connection = storageAdapter.connection else { throw DataStoreError.nilSQLiteConnection() } - + let tableInfoStatement = TableInfoStatement(modelSchema: modelSchema) do { let existingColumns = try connection.prepare(tableInfoStatement.stringValue).run() diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/CascadeDeleteOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/CascadeDeleteOperation.swift index dc479426b2..08f604de7a 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/CascadeDeleteOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/CascadeDeleteOperation.swift @@ -10,6 +10,7 @@ import Amplify import AWSPluginsCore import Combine +// swiftlint:disable type_body_length file_length /// CascadeDeleteOperation has the following logic: /// 1. Query models from local store based on the following use cases: /// 1a. If the use case is Delete with id, then query by `id` @@ -31,7 +32,7 @@ public class CascadeDeleteOperation: AsynchronousOperation { private let serialQueueSyncDeletions = DispatchQueue(label: "com.amazoncom.Storage.CascadeDeleteOperation.concurrency") private let isDeveloperDefinedModel: Bool - + convenience init( storageAdapter: StorageEngineAdapter, syncEngine: RemoteSyncEngineBehavior?, @@ -110,12 +111,12 @@ public class CascadeDeleteOperation: AsynchronousOperation { syncIfNeededAndFinish(.failure(causedBy: error)) } } - + func queryAndDeleteTransaction() async -> DataStoreResult> { var queriedResult: DataStoreResult<[M]>? var deletedResult: DataStoreResult<[M]>? var associatedModels: [(ModelName, Model)] = [] - + queriedResult = await withCheckedContinuation { continuation in self.storageAdapter.query(self.modelType, modelSchema: self.modelSchema, @@ -139,7 +140,7 @@ public class CascadeDeleteOperation: AsynchronousOperation { deleteResult: deletedResult, associatedModels: associatedModels) } - + // Query using the computed predicate did not return any results, check if model actually exists. do { if try self.storageAdapter.exists(self.modelSchema, withIdentifier: identifier, predicate: nil) { @@ -153,15 +154,15 @@ public class CascadeDeleteOperation: AsynchronousOperation { } catch { queriedResult = .failure(DataStoreError.invalidOperation(causedBy: error)) } - + return collapseResults(queryResult: queriedResult, deleteResult: deletedResult, associatedModels: associatedModels) } - + let modelIds = queriedModels.map { $0.identifier(schema: self.modelSchema).stringValue } logMessage("[CascadeDelete.1] Deleting \(modelSchema.name) with identifiers: \(modelIds)") - + associatedModels = await self.recurseQueryAssociatedModels(modelSchema: self.modelSchema, ids: modelIds) deletedResult = await withCheckedContinuation { continuation in @@ -208,7 +209,7 @@ public class CascadeDeleteOperation: AsynchronousOperation { ids: associatedModelIds) ) } - + return associatedModels } @@ -224,7 +225,7 @@ public class CascadeDeleteOperation: AsynchronousOperation { queryPredicates.append(QueryPredicateOperation(field: associatedField.name, operator: .equals(id))) } let groupedQueryPredicates = QueryPredicateGroup(type: .or, predicates: queryPredicates) - + do { let models = try await withCheckedThrowingContinuation { continuation in storageAdapter.query(modelSchema: modelSchema, predicate: groupedQueryPredicates, eagerLoad: true) { result in @@ -275,7 +276,10 @@ public class CascadeDeleteOperation: AsynchronousOperation { switch transactionResult { case .success(let queryAndDeleteResult): logMessage( - "[CascadeDelete.4] sending a total of \(queryAndDeleteResult.associatedModels.count + queryAndDeleteResult.deletedModels.count) delete mutations" + """ + [CascadeDelete.4] sending a total of + \(queryAndDeleteResult.associatedModels.count + queryAndDeleteResult.deletedModels.count) delete mutations + """ ) switch deleteInput { case .withIdentifier, .withIdentifierAndCondition: @@ -549,3 +553,4 @@ extension CascadeDeleteOperation: DefaultLogger { Self.log } } +// swiftlint:enable type_body_length file_length diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/ModelStorageBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/ModelStorageBehavior.swift index 3a74af0a60..e33537baa5 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/ModelStorageBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/ModelStorageBehavior.swift @@ -32,7 +32,7 @@ protocol ModelStorageBehavior { withId id: Model.Identifier, condition: QueryPredicate?, completion: @escaping DataStoreCallback) - + func delete(_ modelType: M.Type, modelSchema: ModelSchema, withIdentifier identifier: ModelIdentifierProtocol, diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Model+SQLite.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Model+SQLite.swift index 5559050c6e..7ff35dccb2 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Model+SQLite.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Model+SQLite.swift @@ -82,7 +82,7 @@ extension Model { existingFieldOptionalValue = self[internalFieldName] } } - + guard let existingFieldValue = existingFieldOptionalValue else { return nil } @@ -147,7 +147,6 @@ extension Model { return values } - /// Given a serialized JSON model, returns the serialized value of its primary key. /// The returned value is either the value of the field or the serialization of multiple values in case of a composite PK. /// - Parameters: diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/SQLStatement+AlterTable.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/SQLStatement+AlterTable.swift index b60016d856..b29800d8d7 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/SQLStatement+AlterTable.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/SQLStatement+AlterTable.swift @@ -26,9 +26,8 @@ struct AlterTableStatement: SQLStatement { struct AlterTableAddColumnStatement: SQLStatement { var modelSchema: ModelSchema var field: ModelField - + var stringValue: String { "ALTER TABLE \"\(modelSchema.name)\" ADD COLUMN \"\(field.sqlName)\" \"\(field.sqlType)\";" } } - diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Statement+Model.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Statement+Model.swift index 7ada38d738..6045206d6d 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Statement+Model.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/Statement+Model.swift @@ -53,7 +53,6 @@ extension Statement: StatementModelConvertible { Amplify.Logging.logger(forCategory: .dataStore) } - func convert(to modelType: M.Type, withSchema modelSchema: ModelSchema, using statement: SelectStatement, @@ -173,8 +172,7 @@ extension Statement: StatementModelConvertible { private func convertCollection(field: ModelField, schema: ModelSchema, from element: Element, path: [String]) -> Any? { if field.isArray && field.hasAssociation, - case let .some(.hasMany(associatedFieldName: associatedFieldName, associatedFieldNames: associatedFieldNames)) = field.association - { + case let .some(.hasMany(associatedFieldName: associatedFieldName, associatedFieldNames: associatedFieldNames)) = field.association { // Construct the lazy list based on the field reference name and `@@primarykey` or primary key field of the parent if associatedFieldNames.count <= 1, let associatedFieldName = associatedFieldName { let primaryKeyName = schema.primaryKey.isCompositeKey @@ -221,12 +219,11 @@ extension Statement: StatementModelConvertible { private func schemeMetadata(schema: ModelSchema, element: Element, path: [String]) -> ModelValues { var metadata = [ - "__typename": schema.name, + "__typename": schema.name ] if schema.primaryKey.isCompositeKey, - let compositeKey = getValue(from: element, by: path + [ModelIdentifierFormat.Custom.sqlColumnName]) - { + let compositeKey = getValue(from: element, by: path + [ModelIdentifierFormat.Custom.sqlColumnName]) { metadata.updateValue(String(describing: compositeKey), forKey: ModelIdentifierFormat.Custom.sqlColumnName) } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift index 1f65ffc7e7..ae3549bf81 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift @@ -10,6 +10,7 @@ import Foundation import SQLite import AWSPluginsCore +// swiftlint:disable type_body_length file_length /// [SQLite](https://sqlite.org) `StorageEngineAdapter` implementation. This class provides /// an integration layer between the AppSyncLocal `StorageEngine` and SQLite for local storage. final class SQLiteStorageEngineAdapter: StorageEngineAdapter { @@ -118,9 +119,9 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter { storageAdapter: self, modelSchemas: modelSchemas) let mutationSyncMetadataMigration = MutationSyncMetadataMigration(delegate: delegate) - + let modelSyncMetadataMigration = ModelSyncMetadataMigration(storageAdapter: self) - + let modelMigrations = ModelMigrations(modelMigrations: [mutationSyncMetadataMigration, modelSyncMetadataMigration]) do { @@ -246,8 +247,7 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter { } } } - - + func delete(_ modelType: M.Type, modelSchema: ModelSchema, withIdentifier identifier: ModelIdentifierProtocol, @@ -265,7 +265,7 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter { } } } - + func delete(untypedModelType modelType: Model.Type, modelSchema: ModelSchema, withId id: Model.Identifier, @@ -277,7 +277,7 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter { condition: condition, completion: completion) } - + func delete(untypedModelType modelType: Model.Type, modelSchema: ModelSchema, withIdentifier id: ModelIdentifierProtocol, @@ -567,3 +567,4 @@ extension SQLiteStorageEngineAdapter: DefaultLogger { Self.log } } +// swiftlint:enable type_body_length file_length diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+UntypedModel.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+UntypedModel.swift index 60c1a6637c..212840733f 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+UntypedModel.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/SQLite/StorageEngineAdapter+UntypedModel.swift @@ -42,7 +42,7 @@ extension SQLiteStorageEngineAdapter { let statement = InsertStatement(model: untypedModel, modelSchema: modelSchema) _ = try connection.prepare(statement.stringValue).run(statement.variables) } - + query(modelSchema: modelSchema, predicate: untypedModel.identifier(schema: modelSchema).predicate, eagerLoad: eagerLoad) { @@ -58,7 +58,7 @@ extension SQLiteStorageEngineAdapter { completion(.failure(error)) } } - + } catch { completion(.failure(causedBy: error)) } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/StorageEngineAdapter.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/StorageEngineAdapter.swift index 8bfe682307..b911f0a1c3 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/StorageEngineAdapter.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/StorageEngineAdapter.swift @@ -72,7 +72,6 @@ extension StorageEngineAdapter { delete(modelType, modelSchema: modelType.schema, filter: predicate, completion: completion) } - func delete(untypedModelType modelType: Model.Type, withIdentifier identifier: ModelIdentifierProtocol, condition: QueryPredicate? = nil, diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStoreObserveQueryOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStoreObserveQueryOperation.swift index 775b576da5..6e6781716a 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStoreObserveQueryOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStoreObserveQueryOperation.swift @@ -17,9 +17,9 @@ protocol DataStoreObserveQueryOperation { class ObserveQueryRequest: AmplifyOperationRequest { var options: Any - + typealias Options = Any - + init(options: Any) { self.options = options } @@ -44,11 +44,11 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr typealias InProcess = DataStoreQuerySnapshot var request: ObserveQueryRequest var context = InternalTaskAsyncThrowingSequenceContext>() - + private let serialQueue = DispatchQueue(label: "com.amazonaws.AWSDataStoreObseverQueryOperation.serialQueue", target: DispatchQueue.global()) private let itemsChangedPeriodicPublishTimeInSeconds: DispatchQueue.SchedulerTimeType.Stride = 2 - + let modelType: M.Type let modelSchema: ModelSchema let predicate: QueryPredicate? @@ -64,16 +64,16 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr var batchItemsChangedSink: AnyCancellable? var itemsChangedSink: AnyCancellable? var modelSyncedEventSink: AnyCancellable? - + var currentSnapshot: DataStoreQuerySnapshot { DataStoreQuerySnapshot(items: currentItems.sortedModels, isSynced: dispatchedModelSyncedEvent.get()) } - + private var running = false - + var dataStoreStatePublisher: AnyPublisher var dataStoreStateSink: AnyCancellable? - + init(request: ObserveQueryRequest = .init(options: []), context: InternalTaskAsyncThrowingSequenceContext> = InternalTaskAsyncThrowingSequenceContext>(), modelType: M.Type, @@ -87,7 +87,7 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr dataStoreStatePublisher: AnyPublisher) { self.request = request self.context = context - + self.modelType = modelType self.modelSchema = modelSchema self.predicate = predicate @@ -99,22 +99,22 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr self.stopwatch = Stopwatch() self.observeQueryStarted = false self.currentItems = SortedList(sortInput: sortInput, modelSchema: modelSchema) - + self.dataStoreStatePublisher = dataStoreStatePublisher } - + func run() async throws { guard !running else { return } running = true - + subscribeToDataStoreState() startObserveQuery() } - + func subscribeToDataStoreState() { serialQueue.async { [weak self] in guard let self = self else { return } - + self.dataStoreStateSink = self.dataStoreStatePublisher.sink { completion in switch completion { case .finished: @@ -133,17 +133,17 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr } } - + public func cancel() { serialQueue.sync { if let itemsChangedSink = itemsChangedSink { itemsChangedSink.cancel() } - + if let batchItemsChangedSink = batchItemsChangedSink { batchItemsChangedSink.cancel() } - + if let modelSyncedEventSink = modelSyncedEventSink { modelSyncedEventSink.cancel() } @@ -244,7 +244,7 @@ class ObserveQueryTaskRunner: InternalTaskRunner, InternalTaskAsyncThr ) .sink(receiveCompletion: self.onReceiveCompletion(completed:), receiveValue: self.onItemsChangeDuringSync(mutationEvents:)) - + self.itemsChangedSink = self.dataStorePublisher.publisher .filter { _ in self.dispatchedModelSyncedEvent.get() } .filter(self.filterByModelName(mutationEvent:)) diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStorePublisher.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStorePublisher.swift index 6e3dd97e31..9c40ead977 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStorePublisher.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/DataStorePublisher.swift @@ -39,5 +39,3 @@ protocol ModelSubcriptionBehavior { func sendFinished() } - - diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/ObserveTaskRunner.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/ObserveTaskRunner.swift index a3f0ad02b7..755a105f91 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/ObserveTaskRunner.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/ObserveTaskRunner.swift @@ -25,18 +25,18 @@ class ObserveTaskRunner: InternalTaskRunner, InternalTaskAsyncThrowingSequence, var publisher: AnyPublisher var sink: AnyCancellable? var context = InternalTaskAsyncThrowingSequenceContext() - + private var running = false - + public init(request: ObserveRequest = .init(), publisher: AnyPublisher) { self.request = request self.publisher = publisher } - + func run() async throws { guard !running else { return } running = true - + self.sink = publisher.sink { completion in switch completion { case .finished: diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/Support/Model+Sort.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/Support/Model+Sort.swift index 4c3b72f55c..b9eed6bbd9 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/Support/Model+Sort.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Subscribe/Support/Model+Sort.swift @@ -108,13 +108,13 @@ extension ModelSchema { value2Optional: value2Optional) .sortComparator(sortOrder: sortOrder) } - + if let value1Optional = value1 as? Int64?, let value2Optional = value2 as? Int64? { return ModelValueCompare(value1Optional: value1Optional, value2Optional: value2Optional) .sortComparator(sortOrder: sortOrder) } - + return false case .double: guard let value1Optional = value1 as? Double?, let value2Optional = value2 as? Double? else { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOperation.swift index 1fc206425e..6785669c6f 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOperation.swift @@ -29,13 +29,13 @@ final class InitialSyncOperation: AsynchronousOperation { private var syncPageSize: UInt { return dataStoreConfiguration.syncPageSize } - + private var syncPredicate: QueryPredicate? { return dataStoreConfiguration.syncExpressions.first { $0.modelSchema.name == self.modelSchema.name }?.modelPredicate() } - + private var syncPredicateString: String? { guard let syncPredicate = syncPredicate, let data = try? syncPredicateEncoder.encode(syncPredicate) else { @@ -43,18 +43,18 @@ final class InitialSyncOperation: AsynchronousOperation { } return String(data: data, encoding: .utf8) } - + private lazy var _syncPredicateEncoder: JSONEncoder = { var encoder = JSONEncoder() encoder.dateEncodingStrategy = ModelDateFormatting.encodingStrategy encoder.outputFormatting = [.sortedKeys] return encoder }() - + var syncPredicateEncoder: JSONEncoder { _syncPredicateEncoder } - + private let initialSyncOperationTopic: PassthroughSubject var publisher: AnyPublisher { return initialSyncOperationTopic.eraseToAnyPublisher() @@ -110,7 +110,7 @@ final class InitialSyncOperation: AsynchronousOperation { return nil } } - + /// Retrieve the lastSync time for the request before performing the query operation. /// /// - Parameter lastSyncMetadata: Retrieved persisted sync metadata for this model @@ -129,7 +129,7 @@ final class InitialSyncOperation: AsynchronousOperation { initialSyncOperationTopic.send(.started(modelName: modelSchema.name, syncType: syncType)) return lastSyncTime } - + private func syncPredicateChanged(_ lastSyncPredicate: String?, _ currentSyncPredicate: String?) -> Bool { switch (lastSyncPredicate, currentSyncPredicate) { case (.some, .some): @@ -140,7 +140,7 @@ final class InitialSyncOperation: AsynchronousOperation { return false } } - + private func getLastSyncTime(lastSync: Int64?) -> Int64? { guard let lastSync = lastSync else { return nil @@ -174,7 +174,7 @@ final class InitialSyncOperation: AsynchronousOperation { if self.isAuthSignedOutError(apiError: apiError) { self.log.error("Sync for \(self.modelSchema.name) failed due to signed out error \(apiError.errorDescription)") } - + // TODO: Retry query on error let error = DataStoreError.api(apiError) self.dataStoreConfiguration.errorHandler(error) @@ -250,7 +250,7 @@ final class InitialSyncOperation: AsynchronousOperation { finish(result: .failure(DataStoreError.nilStorageAdapter())) return } - + let syncMetadata = ModelSyncMetadata(id: modelSchema.name, lastSync: lastSyncTime, syncPredicate: syncPredicateString) diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOrchestrator.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOrchestrator.swift index 3c2dec737d..dbfe953ab1 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOrchestrator.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/InitialSync/InitialSyncOrchestrator.swift @@ -164,7 +164,7 @@ final class AWSInitialSyncOrchestrator: InitialSyncOrchestrator { allMessages.joined(separator: "\n"), underlyingError ) - + return .failure(syncError) } @@ -215,7 +215,7 @@ extension AWSInitialSyncOrchestrator { else { return false } - + // The following check is to categorize the error as an unauthorized error when the process fails to retrieve // the authorization token. This is taken directly from `AuthTokenURLRequestInterceptor`'s error handling path // that returns an APIError.operationError with an underlying AuthError. @@ -246,7 +246,7 @@ extension AWSInitialSyncOrchestrator { case .unauthorized = AppSyncErrorType(errorTypeValue) { return true } - + // Check is API error is of unauthorized type if case let .api(amplifyError, _) = datastoreError, let apiError = amplifyError as? APIError { @@ -255,13 +255,13 @@ extension AWSInitialSyncOrchestrator { options: .caseInsensitive) != nil { return true } - + if case .httpStatusError(let statusCode, _) = apiError, - (statusCode == 401 || statusCode == 403) { + statusCode == 401 || statusCode == 403 { return true } } - + return false } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/AWSMutationDatabaseAdapter/AWSMutationDatabaseAdapter+MutationEventIngester.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/AWSMutationDatabaseAdapter/AWSMutationDatabaseAdapter+MutationEventIngester.swift index 88851515f7..3a419c8d78 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/AWSMutationDatabaseAdapter/AWSMutationDatabaseAdapter+MutationEventIngester.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/AWSMutationDatabaseAdapter/AWSMutationDatabaseAdapter+MutationEventIngester.swift @@ -13,15 +13,15 @@ extension AWSMutationDatabaseAdapter: MutationEventIngester { /// Accepts a mutation event without a version, applies the latest version from the MutationSyncMetadata table, /// writes the updated mutation event to the local database, then submits it to `mutationEventSubject` - func submit(mutationEvent: MutationEvent, completion: @escaping (Result)->Void) { + func submit(mutationEvent: MutationEvent, completion: @escaping (Result) -> Void) { Task { log.verbose("\(#function): \(mutationEvent)") - + guard let storageAdapter = self.storageAdapter else { completion(.failure(DataStoreError.nilStorageAdapter())) return } - + self.resolveConflictsThenSave(mutationEvent: mutationEvent, storageAdapter: storageAdapter, completion: completion) @@ -32,22 +32,7 @@ extension AWSMutationDatabaseAdapter: MutationEventIngester { /// rejects the event with an error func resolveConflictsThenSave(mutationEvent: MutationEvent, storageAdapter: StorageEngineAdapter, - completion: @escaping (Result)->Void) { - - // We don't want to query MutationSync because a) we already have the model, and b) delete mutations - // are submitted *after* the delete has already been applied to the local data store, meaning there is no model - // to query. - var mutationEvent = mutationEvent - do { - // TODO: Refactor this so that it's clear that the storage engine is not responsible for setting the version - // perhaps as simple as renaming to `submit(unversionedMutationEvent:)` or similar - let syncMetadata = try storageAdapter.queryMutationSyncMetadata(for: mutationEvent.modelId, - modelName: mutationEvent.modelName) - mutationEvent.version = syncMetadata?.version - } catch { - completion(.failure(DataStoreError(error: error))) - } - + completion: @escaping (Result) -> Void) { MutationEvent.pendingMutationEvents( forMutationEvent: mutationEvent, storageAdapter: storageAdapter) { result in @@ -208,8 +193,6 @@ extension AWSMutationDatabaseAdapter: MutationEventIngester { } resolvedEvent.mutationType = updatedMutationType - resolvedEvent.version = candidate.version - return resolvedEvent } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/MutationEvent/MutationEventIngester.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/MutationEvent/MutationEventIngester.swift index 6a116d76e4..854cdd03e1 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/MutationEvent/MutationEventIngester.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/MutationEvent/MutationEventIngester.swift @@ -10,5 +10,5 @@ import Combine /// Ingests MutationEvents from and writes them to the MutationEvent persistent store protocol MutationEventIngester: AnyObject { - func submit(mutationEvent: MutationEvent, completion: @escaping (Result)->Void) + func submit(mutationEvent: MutationEvent, completion: @escaping (Result) -> Void) } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/OutgoingMutationQueue.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/OutgoingMutationQueue.swift index 5e833b41a5..26cde77852 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/OutgoingMutationQueue.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/OutgoingMutationQueue.swift @@ -71,7 +71,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { .$state .sink { [weak self] newState in guard let self else { return } - + self.log.verbose("New state: \(newState)") self.mutationDispatchQueue.async { self.respond(to: newState) @@ -139,7 +139,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { queryMutationEventsFromStorage { [weak self] in guard let self = self else { return } - + self.operationQueue.isSuspended = false // State machine notification to ".receivedSubscription" will be handled in `receive(subscription:)` mutationEventPublisher.publisher.subscribe(self) @@ -204,6 +204,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { Task { let syncMutationToCloudOperation = await SyncMutationToCloudOperation( mutationEvent: mutationEvent, + getLatestSyncMetadata: { try? self.storageAdapter.queryMutationSyncMetadata(for: mutationEvent.modelId, modelName: mutationEvent.modelName) }, api: api, authModeStrategy: authModeStrategy ) { [weak self] result in @@ -248,10 +249,10 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { guard let reconciliationQueue = reconciliationQueue else { let dataStoreError = DataStoreError.configuration( "reconciliationQueue is unexpectedly nil", - """ - The reference to reconciliationQueue has been released while an ongoing mutation was being processed. - \(AmplifyErrorMessages.reportBugToAWS()) - """ + """ + The reference to reconciliationQueue has been released while an ongoing mutation was being processed. + \(AmplifyErrorMessages.reportBugToAWS()) + """ ) stateMachine.notify(action: .errored(dataStoreError)) return @@ -260,7 +261,8 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { MutationEvent.reconcilePendingMutationEventsVersion( sent: mutationEvent, received: mutationSync, - storageAdapter: storageAdapter) { _ in + storageAdapter: storageAdapter + ) { _ in self.completeProcessingEvent(mutationEvent, mutationSync: mutationSync) } } else { @@ -337,7 +339,7 @@ final class OutgoingMutationQueue: OutgoingMutationQueueBehavior { paginationInput: nil, eagerLoad: true) { [weak self] result in guard let self else { return } - + switch result { case .success(let events): self.dispatchOutboxStatusEvent(isEmpty: events.isEmpty) diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/ProcessMutationErrorFromCloudOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/ProcessMutationErrorFromCloudOperation.swift index 2e4528a2e6..bbc4ec0895 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/ProcessMutationErrorFromCloudOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/ProcessMutationErrorFromCloudOperation.swift @@ -10,6 +10,7 @@ import Combine import Foundation import AWSPluginsCore +// swiftlint:disable type_body_length file_length /// Checks the GraphQL error response for specific error scenarios related to data synchronziation to the local store. /// 1. When there is an APIError which is for an unauthenticated user, call the error handler. /// 2. When there is a "conditional request failed" error, then emit to the Hub a 'conditionalSaveFailed' event. @@ -28,7 +29,7 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation { private var mutationOperation: AtomicValue>?> private weak var api: APICategoryGraphQLBehaviorExtended? private weak var reconciliationQueue: IncomingEventReconciliationQueue? - + init(dataStoreConfiguration: DataStoreConfiguration, mutationEvent: MutationEvent, api: APICategoryGraphQLBehaviorExtended, @@ -314,7 +315,7 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation { if case .failure(let error) = cloudResult { dataStoreConfiguration.errorHandler(error) } - + if case let .success(graphQLResponse) = cloudResult { if case .failure(let error) = graphQLResponse { dataStoreConfiguration.errorHandler(error) @@ -330,11 +331,11 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation { finish(result: .failure(dataStoreError)) return } - + reconciliationQueue.offer([graphQLResult], modelName: mutationEvent.modelName) } } - + finish(result: .success(nil)) } @@ -357,7 +358,7 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation { } let identifier = remoteModel.model.identifier(schema: modelSchema) - + storageAdapter.delete(untypedModelType: modelType, modelSchema: modelSchema, withIdentifier: identifier, @@ -471,3 +472,4 @@ extension ProcessMutationErrorFromCloudOperation: DefaultLogger { Self.log } } +// swiftlint:enable type_body_length file_length diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/SyncMutationToCloudOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/SyncMutationToCloudOperation.swift index dac31dd0bf..4577782c41 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/SyncMutationToCloudOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/MutationSync/OutgoingMutationQueue/SyncMutationToCloudOperation.swift @@ -19,6 +19,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { private weak var api: APICategoryGraphQLBehaviorExtended? private let mutationEvent: MutationEvent + private let getLatestSyncMetadata: () -> MutationSyncMetadata? private let completion: GraphQLOperation>.ResultListener private let requestRetryablePolicy: RequestRetryablePolicy @@ -31,6 +32,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { private var authTypesIterator: AWSAuthorizationTypeIterator? init(mutationEvent: MutationEvent, + getLatestSyncMetadata: @escaping () -> MutationSyncMetadata?, api: APICategoryGraphQLBehaviorExtended, authModeStrategy: AuthModeStrategy, networkReachabilityPublisher: AnyPublisher? = nil, @@ -38,6 +40,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { requestRetryablePolicy: RequestRetryablePolicy? = RequestRetryablePolicy(), completion: @escaping GraphQLOperation>.ResultListener) async { self.mutationEvent = mutationEvent + self.getLatestSyncMetadata = getLatestSyncMetadata self.api = api self.networkReachabilityPublisher = networkReachabilityPublisher self.completion = completion @@ -47,7 +50,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { if let modelSchema = ModelRegistry.modelSchema(from: mutationEvent.modelName), let mutationType = GraphQLMutationType(rawValue: mutationEvent.mutationType) { - + self.authTypesIterator = await authModeStrategy.authTypesFor(schema: modelSchema, operation: mutationType.toModelOperation()) } @@ -57,6 +60,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { override func main() { log.verbose(#function) + sendMutationToCloud(withAuthType: authTypesIterator?.next()) } @@ -99,6 +103,33 @@ class SyncMutationToCloudOperation: AsynchronousOperation { } } + /// Always retrieve and use the largest version when available. The source of the version comes + /// from either the MutationEvent itself, which represents the queue request, or the persisted version + /// from the metadata table. + /// + /// **Version in the Mutation Event**. If there are mulitple mutation events pending, each outgoing + /// mutation processing will result in synchronously updating the pending mutation's version + /// before enqueuing the mutation response for reconciliation. + /// + /// **Version persisted in the metadata table**: Reconciliation will persist the latest version in the + /// metadata table. In cases of quick consecutive updates, the MutationEvent's version could + /// be greater than the persisted since the MutationEvent is updated from the original thread that + /// processed the outgoing mutation. + private func getLatestVersion(_ mutationEvent: MutationEvent) -> Int? { + let latestSyncedMetadataVersion = getLatestSyncMetadata()?.version + let mutationEventVersion = mutationEvent.version + switch (latestSyncedMetadataVersion, mutationEventVersion) { + case let (.some(syncedVersion), .some(version)): + return max(syncedVersion, version) + case let (.some(syncedVersion), .none): + return syncedVersion + case let (.none, .some(version)): + return version + case (.none, .none): + return nil + } + } + /// Creates a GraphQLRequest based on given `mutationType` /// - Parameters: /// - mutationType: mutation type @@ -108,6 +139,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { mutationType: GraphQLMutationType, authType: AWSAuthorizationType? = nil ) -> GraphQLRequest>? { + let version = getLatestVersion(mutationEvent) var request: GraphQLRequest> do { @@ -128,7 +160,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { request = GraphQLRequest.deleteMutation(of: model, modelSchema: modelSchema, where: graphQLFilter, - version: mutationEvent.version) + version: version) case .update: let model = try mutationEvent.decodeModel() guard let modelSchema = ModelRegistry.modelSchema(from: mutationEvent.modelName) else { @@ -140,7 +172,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { request = GraphQLRequest.updateMutation(of: model, modelSchema: modelSchema, where: graphQLFilter, - version: mutationEvent.version) + version: version) case .create: let model = try mutationEvent.decodeModel() guard let modelSchema = ModelRegistry.modelSchema(from: mutationEvent.modelName) else { @@ -151,7 +183,7 @@ class SyncMutationToCloudOperation: AsynchronousOperation { } request = GraphQLRequest.createMutation(of: model, modelSchema: modelSchema, - version: mutationEvent.version) + version: version) } } catch { let apiError = APIError.unknown("Couldn't decode model", "", error) diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine+AuthModeStrategyDelegate.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine+AuthModeStrategyDelegate.swift index ee5c84c460..db2ae3b9e4 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine+AuthModeStrategyDelegate.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine+AuthModeStrategyDelegate.swift @@ -11,11 +11,11 @@ import Foundation import AWSPluginsCore extension RemoteSyncEngine: AuthModeStrategyDelegate { - + func isUserLoggedIn() async -> Bool { if let authProviderFactory = api as? APICategoryAuthProviderFactoryBehavior, let oidcAuthProvider = authProviderFactory.apiAuthProviderFactory().oidcAuthProvider() { - + // if OIDC is used as authentication provider // use `getLatestAuthToken` var isLoggedInWithOIDC = false diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine.swift index b361e0ab22..26bb453571 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngine.swift @@ -10,6 +10,7 @@ import Combine import Foundation import AWSPluginsCore +// swiftlint:disable type_body_length file_length class RemoteSyncEngine: RemoteSyncEngineBehavior { weak var storageAdapter: StorageEngineAdapter? @@ -84,10 +85,10 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior { OutgoingMutationQueue(storageAdapter: storageAdapter, dataStoreConfiguration: dataStoreConfiguration, authModeStrategy: resolvedAuthStrategy) - + // swiftlint:disable line_length let reconciliationQueueFactory = reconciliationQueueFactory ?? AWSIncomingEventReconciliationQueue.init(modelSchemas:api:storageAdapter:syncExpressions:auth:authModeStrategy:modelReconciliationQueueFactory:disableSubscriptions:) - + // swiftlint:enable line_length let initialSyncOrchestratorFactory = initialSyncOrchestratorFactory ?? AWSInitialSyncOrchestrator.init(dataStoreConfiguration:authModeStrategy:api:reconciliationQueue:storageAdapter:) @@ -245,7 +246,7 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior { } } - func submit(_ mutationEvent: MutationEvent, completion: @escaping (Result)->Void) { + func submit(_ mutationEvent: MutationEvent, completion: @escaping (Result) -> Void) { mutationEventIngester.submit(mutationEvent: mutationEvent, completion: completion) } @@ -278,7 +279,7 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior { } } } - + private func initializeSubscriptions(api: APICategoryGraphQLBehaviorExtended, storageAdapter: StorageEngineAdapter) async { log.debug("[InitializeSubscription] \(#function)") @@ -448,3 +449,4 @@ extension RemoteSyncEngine: Resettable { } } } +// swiftlint:enable type_body_length file_length diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngineBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngineBehavior.swift index bc9cb80634..ee5710ff21 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngineBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/RemoteSyncEngineBehavior.swift @@ -49,7 +49,7 @@ protocol RemoteSyncEngineBehavior: AnyObject { /// Submits a new mutation for synchronization to the remote API. The response will be handled by the appropriate /// reconciliation queue - func submit(_ mutationEvent: MutationEvent, completion: @escaping (Result)->Void) + func submit(_ mutationEvent: MutationEvent, completion: @escaping (Result) -> Void) var publisher: AnyPublisher { get } } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift index 0f116dec8e..7705120b4b 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift @@ -44,7 +44,7 @@ final class AWSIncomingEventReconciliationQueue: IncomingEventReconciliationQueu return modelSchemasCount == reconciliationQueueConnectionStatus.count } private let modelSchemasCount: Int - + init(modelSchemas: [ModelSchema], api: APICategoryGraphQLBehaviorExtended, storageAdapter: StorageEngineAdapter, @@ -52,27 +52,27 @@ final class AWSIncomingEventReconciliationQueue: IncomingEventReconciliationQueu auth: AuthCategoryBehavior? = nil, authModeStrategy: AuthModeStrategy, modelReconciliationQueueFactory: ModelReconciliationQueueFactory? = nil, - disableSubscriptions: @escaping () -> Bool = { false } ) async { + disableSubscriptions: @escaping () -> Bool = { false }) async { self.modelSchemasCount = modelSchemas.count self.modelReconciliationQueueSinks.set([:]) self.eventReconciliationQueueTopic = CurrentValueSubject(.idle) self.reconciliationQueues.set([:]) self.reconciliationQueueConnectionStatus = [:] self.reconcileAndSaveQueue = ReconcileAndSaveQueue(modelSchemas) - + if let modelReconciliationQueueFactory = modelReconciliationQueueFactory { self.modelReconciliationQueueFactory = modelReconciliationQueueFactory } else { self.modelReconciliationQueueFactory = AWSModelReconciliationQueue.init } - + // TODO: Add target for SyncEngine system to help prevent thread explosion and increase performance // https://github.com/aws-amplify/amplify-ios/issues/399 self.connectionStatusSerialQueue = DispatchQueue(label: "com.amazonaws.DataStore.AWSIncomingEventReconciliationQueue") let subscriptionsDisabled = disableSubscriptions() - + #if targetEnvironment(simulator) && os(watchOS) if !subscriptionsDisabled { let message = """ @@ -102,7 +102,7 @@ final class AWSIncomingEventReconciliationQueue: IncomingEventReconciliationQueu auth, authModeStrategy, subscriptionsDisabled ? OperationDisabledIncomingSubscriptionEventPublisher() : nil) - + reconciliationQueues.with { reconciliationQueues in reconciliationQueues[modelName] = queue } @@ -207,7 +207,8 @@ extension AWSIncomingEventReconciliationQueue: DefaultLogger { // MARK: - Static factory extension AWSIncomingEventReconciliationQueue { - static let factory: IncomingEventReconciliationQueueFactory = { modelSchemas, api, storageAdapter, syncExpressions, auth, authModeStrategy, _, disableSubscriptions in + static let factory: IncomingEventReconciliationQueueFactory = { + modelSchemas, api, storageAdapter, syncExpressions, auth, authModeStrategy, _, disableSubscriptions in await AWSIncomingEventReconciliationQueue(modelSchemas: modelSchemas, api: api, storageAdapter: storageAdapter, @@ -238,7 +239,7 @@ extension AWSIncomingEventReconciliationQueue: Resettable { // We're sometimes hitting a deadlock when waiting for them to finish. Commenting this out and letting // the tests continue onto the next works pretty well, but ideally ReconcileAndLocalSaveOperation's should // always finish. We can uncomment this to explore a better fix that will still gives us test stability. - //reconcileAndSaveQueue.waitUntilOperationsAreFinished() + // reconcileAndSaveQueue.waitUntilOperationsAreFinished() log.verbose("Resetting reconcileAndSaveQueue: finished") log.verbose("Cancelling AWSIncomingEventReconciliationQueue") diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/OperationDisabledSubscriptionEventPublisher.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/OperationDisabledSubscriptionEventPublisher.swift index 277b4685d8..de12d96dca 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/OperationDisabledSubscriptionEventPublisher.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/OperationDisabledSubscriptionEventPublisher.swift @@ -23,7 +23,7 @@ final class OperationDisabledIncomingSubscriptionEventPublisher: IncomingSubscri let apiError = APIError.operationError(AppSyncErrorType.operationDisabled.rawValue, "", nil) let dataStoreError = DataStoreError.api(apiError, nil) subscriptionEventSubject.send(completion: .failure(dataStoreError)) - + } func cancel() { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/AWSModelReconciliationQueue.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/AWSModelReconciliationQueue.swift index 86c7aca2c9..7eacedb029 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/AWSModelReconciliationQueue.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/AWSModelReconciliationQueue.swift @@ -111,7 +111,7 @@ final class AWSModelReconciliationQueue: ModelReconciliationQueue { authModeStrategy: authModeStrategy ) } - + self.incomingSubscriptionEvents = resolvedIncomingSubscriptionEvents self.reconcileAndLocalSaveOperationSinks = AtomicValue(initialValue: Set()) self.incomingEventsSink = resolvedIncomingSubscriptionEvents @@ -122,7 +122,7 @@ final class AWSModelReconciliationQueue: ModelReconciliationQueue { self?.receive(receiveValue) }) } - + /// (Re)starts the incoming subscription event queue. func start() { incomingSubscriptionEventQueue.isSuspended = false @@ -289,7 +289,7 @@ extension AWSModelReconciliationQueue { case .operationDisabled = AppSyncErrorType(errorMessage) { return true } - + if let responseError = error as? GraphQLResponseError, let graphQLError = graphqlErrors(from: responseError)?.first, let errorTypeValue = errorTypeValueFrom(graphQLError: graphQLError), diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/ReconcileAndLocalSaveOperation.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/ReconcileAndLocalSaveOperation.swift index 9afaf2e8a1..474f76666e 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/ReconcileAndLocalSaveOperation.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/ReconcileAndLocalSaveOperation.swift @@ -10,6 +10,7 @@ import Combine import Foundation import AWSPluginsCore +// swiftlint:disable type_body_length file_length /// Reconciles an incoming model mutation with the stored model. If there is no conflict (e.g., the incoming model has /// a later version than the stored model), then write the new data to the store. class ReconcileAndLocalSaveOperation: AsynchronousOperation { @@ -42,7 +43,7 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { } var isEagerLoad: Bool = true - + init(modelSchema: ModelSchema, remoteModels: [RemoteModel], storageAdapter: StorageEngineAdapter?, @@ -56,13 +57,13 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { self.mutationEventPublisher = PassthroughSubject() self.cancellables = Set() - + // `isEagerLoad` is true by default, unless the models contain the rootPath // which is indication that codegenerated model types support for lazy loading. if isEagerLoad && ModelRegistry.modelType(from: modelSchema.name)?.rootPath != nil { self.isEagerLoad = false } - + super.init() self.stateMachineSink = self.stateMachine @@ -113,6 +114,14 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { // MARK: - Responder methods + /// The reconcile function incorporates incoming mutation events into the local database through the following steps: + /// 1. Retrieve the local metadata of the models. + /// 2. Generate dispositions based on incoming mutation events and local metadata. + /// 3. Categorize dispositions into: + /// 3.1 Apply metadata only for those with existing pending mutations. + /// 3.1.1 Notify the count of these incoming mutation events as dropped items. + /// 3.2 Apply incoming mutation and metadata for those without existing pending mutations. + /// 4. Notify the final result. func reconcile(remoteModels: [RemoteModel]) { guard !isCancelled else { log.info("\(#function) - cancelled, aborting") @@ -133,16 +142,21 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { do { try storageAdapter.transaction { - queryPendingMutations(withModels: remoteModels.map(\.model)) + self.queryLocalMetadata(remoteModels) .subscribe(on: workQueue) - .flatMap { mutationEvents -> Future<([RemoteModel], [LocalMetadata]), DataStoreError> in - let remoteModelsToApply = self.reconcile(remoteModels, pendingMutations: mutationEvents) - return self.queryLocalMetadata(remoteModelsToApply) + .map { (remoteModels, localMetadatas) in + self.getDispositions(for: remoteModels, localMetadatas: localMetadatas) } - .flatMap { (remoteModelsToApply, localMetadatas) -> Future in - let dispositions = self.getDispositions(for: remoteModelsToApply, - localMetadatas: localMetadatas) - return self.applyRemoteModelsDispositions(dispositions) + .flatMap { dispositions in + self.queryPendingMutations(withModels: dispositions.map(\.remoteModel.model)) + .map { pendingMutations in (pendingMutations, dispositions) } + } + .map { (pendingMutations, dispositions) in + self.separateDispositions(pendingMutations: pendingMutations, dispositions: dispositions) + } + .flatMap { (dispositions, dispositionOnlyApplyMetadata) in + self.waitAllPublisherFinishes(publishers: dispositionOnlyApplyMetadata.map(self.saveMetadata(disposition:))) + .flatMap { _ in self.applyRemoteModelsDispositions(dispositions) } } .sink( receiveCompletion: { @@ -203,15 +217,27 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { } } - func reconcile(_ remoteModels: [RemoteModel], pendingMutations: [MutationEvent]) -> [RemoteModel] { - guard !remoteModels.isEmpty else { - return [] + func separateDispositions( + pendingMutations: [MutationEvent], + dispositions: [RemoteSyncReconciler.Disposition] + ) -> ([RemoteSyncReconciler.Disposition], [RemoteSyncReconciler.Disposition]) { + guard !dispositions.isEmpty else { + return ([], []) + } + + + let pendingMutationModelIds = Set(pendingMutations.map(\.modelId)) + + let dispositionsToApply = dispositions.filter { + !pendingMutationModelIds.contains($0.remoteModel.model.identifier) } - let remoteModelsToApply = RemoteSyncReconciler.filter(remoteModels, - pendingMutations: pendingMutations) - notifyDropped(count: remoteModels.count - remoteModelsToApply.count) - return remoteModelsToApply + let dispositionsOnlyApplyMetadata = dispositions.filter { + pendingMutationModelIds.contains($0.remoteModel.model.identifier) + } + + notifyDropped(count: dispositionsOnlyApplyMetadata.count) + return (dispositionsToApply, dispositionsOnlyApplyMetadata) } func queryLocalMetadata(_ remoteModels: [RemoteModel]) -> Future<([RemoteModel], [LocalMetadata]), DataStoreError> { @@ -269,24 +295,16 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { disposition: RemoteSyncReconciler.Disposition ) -> AnyPublisher, Never> { let operation: Future - let mutationType: MutationEvent.MutationType switch disposition { - case .create(let remoteModel): - operation = self.save(storageAdapter: storageAdapter, remoteModel: remoteModel) - mutationType = .create - case .update(let remoteModel): - operation = self.save(storageAdapter: storageAdapter, remoteModel: remoteModel) - mutationType = .update - case .delete(let remoteModel): - operation = self.delete(storageAdapter: storageAdapter, remoteModel: remoteModel) - mutationType = .delete + case .create, .update: + operation = self.save(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel) + case .delete: + operation = self.delete(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel) } return operation - .flatMap { applyResult in - self.saveMetadata(storageAdapter: storageAdapter, applyResult: applyResult, mutationType: mutationType) - } - .map {_ in Result.success(()) } + .flatMap { self.saveMetadata(storageAdapter: storageAdapter, result: $0, mutationType: disposition.mutationType) } + .map { _ in Result.success(()) } .catch { Just>(.failure($0))} .eraseToAnyPublisher() } @@ -315,15 +333,7 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { applyRemoteModelsDisposition(storageAdapter: storageAdapter, disposition: $0) } - return Future { promise in - Publishers.MergeMany(publishers) - .collect() - .sink { _ in - // This stream will never fail, as we wrapped error in the result type. - promise(.successfulVoid) - } receiveValue: { _ in } - .store(in: &self.cancellables) - } + return self.waitAllPublisherFinishes(publishers: publishers) } enum ApplyRemoteModelResult { @@ -359,8 +369,10 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { } } - private func save(storageAdapter: StorageEngineAdapter, - remoteModel: RemoteModel) -> Future { + private func save( + storageAdapter: StorageEngineAdapter, + remoteModel: RemoteModel + ) -> Future { Future { promise in storageAdapter.save(untypedModel: remoteModel.model.instance, eagerLoad: self.isEagerLoad) { response in switch response { @@ -388,27 +400,50 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { } } - private func saveMetadata(storageAdapter: StorageEngineAdapter, - applyResult: ApplyRemoteModelResult, - mutationType: MutationEvent.MutationType) -> Future { - Future { promise in - guard case let .applied(inProcessModel) = applyResult else { - promise(.successfulVoid) - return - } + private func saveMetadata( + disposition: RemoteSyncReconciler.Disposition + ) -> AnyPublisher { + guard let storageAdapter = self.storageAdapter else { + return Just(()).eraseToAnyPublisher() + } + return saveMetadata(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel, mutationType: disposition.mutationType) + .map { _ in () } + .catch { _ in Just(()) } + .eraseToAnyPublisher() + } - storageAdapter.save(inProcessModel.syncMetadata, - condition: nil, - eagerLoad: self.isEagerLoad) { result in - switch result { - case .failure(let dataStoreError): - self.notifyDropped(error: dataStoreError) - promise(.failure(dataStoreError)) - case .success(let syncMetadata): + private func saveMetadata( + storageAdapter: StorageEngineAdapter, + result: ApplyRemoteModelResult, + mutationType: MutationEvent.MutationType + ) -> AnyPublisher { + if case let .applied(inProcessModel) = result { + return self.saveMetadata(storageAdapter: storageAdapter, remoteModel: inProcessModel, mutationType: mutationType) + .handleEvents( receiveOutput: { syncMetadata in let appliedModel = MutationSync(model: inProcessModel.model, syncMetadata: syncMetadata) self.notify(savedModel: appliedModel, mutationType: mutationType) - promise(.successfulVoid) - } + }, receiveCompletion: { completion in + if case .failure(let error) = completion { + self.notifyDropped(error: error) + } + }) + .map { _ in () } + .eraseToAnyPublisher() + + } + return Just(()).setFailureType(to: DataStoreError.self).eraseToAnyPublisher() + } + + private func saveMetadata( + storageAdapter: StorageEngineAdapter, + remoteModel: RemoteModel, + mutationType: MutationEvent.MutationType + ) -> Future { + Future { promise in + storageAdapter.save(remoteModel.syncMetadata, + condition: nil, + eagerLoad: self.isEagerLoad) { result in + promise(result) } } } @@ -454,6 +489,17 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation { private static func unfulfilledDataStoreError(name: String = #function) -> DataStoreError { .unknown("\(name) did not fulfill promise", AmplifyErrorMessages.shouldNotHappenReportBugToAWS(), nil) } + + private func waitAllPublisherFinishes(publishers: [AnyPublisher]) -> Future { + Future { promise in + Publishers.MergeMany(publishers) + .collect() + .sink(receiveCompletion: { _ in + promise(.successfulVoid) + }, receiveValue: { _ in }) + .store(in: &self.cancellables) + } + } } extension ReconcileAndLocalSaveOperation: DefaultLogger { @@ -469,3 +515,4 @@ enum ReconcileAndLocalSaveOperationEvent { case mutationEvent(MutationEvent) case mutationEventDropped(modelName: String, error: DataStoreError? = nil) } +// swiftlint:enable type_body_length file_length diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/RemoteSyncReconciler.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/RemoteSyncReconciler.swift index 9115e96cd5..1bfc0852b1 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/RemoteSyncReconciler.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/SubscriptionSync/ReconcileAndLocalSave/RemoteSyncReconciler.swift @@ -16,31 +16,24 @@ struct RemoteSyncReconciler { case create(RemoteModel) case update(RemoteModel) case delete(RemoteModel) - } - - /// Filter the incoming `remoteModels` against the pending mutations. - /// If there is a matching pending mutation, drop the remote model. - /// - /// - Parameters: - /// - remoteModels: models retrieved from the remote store - /// - pendingMutations: pending mutations from the outbox - /// - Returns: remote models to be applied - static func filter(_ remoteModels: [RemoteModel], - pendingMutations: [MutationEvent]) -> [RemoteModel] { - guard !pendingMutations.isEmpty else { - return remoteModels - } - let pendingMutationModelIdsArr = pendingMutations.map { mutationEvent in - mutationEvent.modelId + var remoteModel: RemoteModel { + switch self { + case .create(let model), .update(let model), .delete(let model): + return model + } } - let pendingMutationModelIds = Set(pendingMutationModelIdsArr) - return remoteModels.filter { remoteModel in - !pendingMutationModelIds.contains(remoteModel.model.identifier) + var mutationType: MutationEvent.MutationType { + switch self { + case .create: return .create + case .update: return .update + case .delete: return .delete + } } } + /// Reconciles the incoming `remoteModels` against the local metadata to get the disposition /// /// - Parameters: @@ -84,7 +77,7 @@ struct RemoteSyncReconciler { guard remoteModel.syncMetadata.version > localMetadata.version else { return nil } - + return remoteModel.syncMetadata.deleted ? .delete(remoteModel) : .update(remoteModel) } } diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/Support/MutationEvent+Query.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/Support/MutationEvent+Query.swift index 5d9e157475..d84dad4ce7 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/Support/MutationEvent+Query.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Sync/Support/MutationEvent+Query.swift @@ -56,7 +56,7 @@ extension MutationEvent { completion: completion ) } - + private static func pendingMutationEvents(for modelIds: [(String, String)], storageAdapter: StorageEngineAdapter, completion: @escaping DataStoreCallback<[MutationEvent]>) { @@ -74,7 +74,7 @@ extension MutationEvent { let groupedQueryPredicates = QueryPredicateGroup(type: .or, predicates: queryPredicates) let final = QueryPredicateGroup(type: .and, predicates: [groupedQueryPredicates, predicate]) let sort = QuerySortDescriptor(fieldName: fields.createdAt.stringValue, order: .ascending) - + do { let mutationEvents = try await withCheckedThrowingContinuation { continuation in storageAdapter.query(MutationEvent.self, @@ -85,7 +85,7 @@ extension MutationEvent { continuation.resume(with: result) } } - + queriedMutationEvents.append(contentsOf: mutationEvents) } catch { completion(.failure(causedBy: error)) diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/MutationQueue/SyncMutationToCloudOperationTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/MutationQueue/SyncMutationToCloudOperationTests.swift index 263a6b52f6..96a0ef2252 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/MutationQueue/SyncMutationToCloudOperationTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/MutationQueue/SyncMutationToCloudOperationTests.swift @@ -45,8 +45,10 @@ class SyncMutationToCloudOperationTests: XCTestCase { var listenerFromSecondRequestOptional: GraphQLOperation>.ResultListener? var numberOfTimesEntered = 0 - let responder = MutateRequestListenerResponder> { _, eventListener in + let responder = MutateRequestListenerResponder> { request, eventListener in if numberOfTimesEntered == 0 { + let requestInputVersion = request.variables.flatMap { $0["input"] as? [String: Any] }.flatMap { $0["_version"] as? Int } + XCTAssertEqual(requestInputVersion, 10) listenerFromFirstRequestOptional = eventListener expectFirstCallToAPIMutate.fulfill() } else if numberOfTimesEntered == 1 { @@ -67,12 +69,24 @@ class SyncMutationToCloudOperationTests: XCTestCase { expectMutationRequestCompletion.fulfill() } - let operation = await SyncMutationToCloudOperation(mutationEvent: mutationEvent, - api: mockAPIPlugin, - authModeStrategy: AWSDefaultAuthModeStrategy(), - networkReachabilityPublisher: publisher, - currentAttemptNumber: 1, - completion: completion) + let model = MockSynced(id: "id-1") + let operation = await SyncMutationToCloudOperation( + mutationEvent: mutationEvent, + getLatestSyncMetadata: { + MutationSyncMetadata( + modelId: model.id, + modelName: model.modelName, + deleted: false, + lastChangedAt: Date().unixSeconds, + version: 10 + ) + }, + api: mockAPIPlugin, + authModeStrategy: AWSDefaultAuthModeStrategy(), + networkReachabilityPublisher: publisher, + currentAttemptNumber: 1, + completion: completion + ) let queue = OperationQueue() queue.addOperation(operation) await fulfillment(of: [expectFirstCallToAPIMutate], timeout: defaultAsyncWaitTimeout) @@ -90,7 +104,7 @@ class SyncMutationToCloudOperationTests: XCTestCase { return } - let model = MockSynced(id: "id-1") + let anyModel = try model.eraseToAnyModel() let remoteSyncMetadata = MutationSyncMetadata(modelId: model.id, modelName: model.modelName, @@ -139,13 +153,16 @@ class SyncMutationToCloudOperationTests: XCTestCase { let completion: GraphQLOperation>.ResultListener = { _ in expectMutationRequestCompletion.fulfill() } - let operation = await SyncMutationToCloudOperation(mutationEvent: mutationEvent, - api: mockAPIPlugin, - authModeStrategy: AWSDefaultAuthModeStrategy(), - networkReachabilityPublisher: publisher, - currentAttemptNumber: 1, - requestRetryablePolicy: mockRequestRetryPolicy, - completion: completion) + let operation = await SyncMutationToCloudOperation( + mutationEvent: mutationEvent, + getLatestSyncMetadata: { nil }, + api: mockAPIPlugin, + authModeStrategy: AWSDefaultAuthModeStrategy(), + networkReachabilityPublisher: publisher, + currentAttemptNumber: 1, + requestRetryablePolicy: mockRequestRetryPolicy, + completion: completion + ) let queue = OperationQueue() queue.addOperation(operation) await fulfillment(of: [expectFirstCallToAPIMutate], timeout: defaultAsyncWaitTimeout) @@ -212,13 +229,16 @@ class SyncMutationToCloudOperationTests: XCTestCase { break } } - let operation = await SyncMutationToCloudOperation(mutationEvent: mutationEvent, - api: mockAPIPlugin, - authModeStrategy: AWSDefaultAuthModeStrategy(), - networkReachabilityPublisher: publisher, - currentAttemptNumber: 1, - requestRetryablePolicy: mockRequestRetryPolicy, - completion: completion) + let operation = await SyncMutationToCloudOperation( + mutationEvent: mutationEvent, + getLatestSyncMetadata: { nil }, + api: mockAPIPlugin, + authModeStrategy: AWSDefaultAuthModeStrategy(), + networkReachabilityPublisher: publisher, + currentAttemptNumber: 1, + requestRetryablePolicy: mockRequestRetryPolicy, + completion: completion + ) let queue = OperationQueue() queue.addOperation(operation) await fulfillment(of: [expectFirstCallToAPIMutate], timeout: defaultAsyncWaitTimeout) diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/ReconcileAndLocalSaveOperationTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/ReconcileAndLocalSaveOperationTests.swift index d0d19eeb4e..610c58ba31 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/ReconcileAndLocalSaveOperationTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/ReconcileAndLocalSaveOperationTests.swift @@ -314,23 +314,25 @@ class ReconcileAndLocalSaveOperationTests: XCTestCase { // MARK: - reconcile(remoteModels:pendingMutations) - func testReconcilePendingMutations_emptyModels() { - let result = operation.reconcile([], pendingMutations: [anyPostMutationEvent]) - - XCTAssertTrue(result.isEmpty) + func testSeparateDispositions_emptyModels() { + let result = operation.separateDispositions(pendingMutations: [], dispositions: []) + XCTAssertTrue(result.0.isEmpty) + XCTAssertTrue(result.1.isEmpty) } func testReconcilePendingMutations_emptyPendingMutations() { - let result = operation.reconcile([anyPostMutationSync], pendingMutations: []) + let result = operation.separateDispositions(pendingMutations: [], dispositions: [.update(anyPostMutationSync)]) - guard let remoteModelToApply = result.first else { + guard let remoteModelToApply = result.0.first else { XCTFail("Missing models to apply") return } - XCTAssertEqual(remoteModelToApply.model.id, anyPostMutationSync.model.id) + + XCTAssertTrue(result.1.isEmpty) + XCTAssertEqual(remoteModelToApply.remoteModel.model.id, anyPostMutationSync.model.id) } - func testReconcilePendingMutations_notifyDropped() { + func testSeparateDispositions_notifyDropped () async { let expect = expectation(description: "notify dropped twice") expect.expectedFulfillmentCount = 2 let model1 = AnyModel(Post(title: "post1", content: "content", createdAt: .now())) @@ -377,11 +379,15 @@ class ReconcileAndLocalSaveOperationTests: XCTestCase { } }.store(in: &cancellables) - let result = operation.reconcile([remoteModel1, remoteModel2], - pendingMutations: [mutationEvent1, mutationEvent2]) + let result = operation.separateDispositions( + pendingMutations: [mutationEvent1, mutationEvent2], + dispositions: [.update(remoteModel1), .update(remoteModel2)] + ) - XCTAssertTrue(result.isEmpty) - waitForExpectations(timeout: 1) + XCTAssertTrue(result.0.isEmpty) + XCTAssertEqual(result.1, [.update(remoteModel1), .update(remoteModel2)]) + + await fulfillment(of: [expect], timeout: 1) } // MARK: - queryLocalMetadata diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/RemoteSyncReconcilerTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/RemoteSyncReconcilerTests.swift index 7d734697fa..612947d04d 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/RemoteSyncReconcilerTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/SubscriptionSync/RemoteSyncReconcilerTests.swift @@ -20,37 +20,6 @@ class RemoteSyncReconcilerTests: XCTestCase { ModelRegistry.register(modelType: MockSynced.self) } - // MARK: reconcile(pendingMutations) - - func testFilter_EmptyRemoteModels() { - let pendingMutations: [MutationEvent] = [makeMutationEvent()] - let results = RemoteSyncReconciler.filter([], pendingMutations: pendingMutations) - - XCTAssertTrue(results.isEmpty) - } - - func testFilter_EmptyPendingMutations() { - let remoteModel = makeRemoteModel() - let results = RemoteSyncReconciler.filter([remoteModel], pendingMutations: []) - - XCTAssertEqual(results.first?.model.id, remoteModel.model.id) - } - - func testFilter_pendingMutationMatchRemoteModel() { - let remoteModel = makeRemoteModel() - let pendingMutation = makeMutationEvent(modelId: remoteModel.model.id) - let results = RemoteSyncReconciler.filter([remoteModel], pendingMutations: [pendingMutation]) - - XCTAssertTrue(results.isEmpty) - } - - func testFilter_pendingMutationDoesNotMatchRemoteModel() { - let remoteModel = makeRemoteModel(modelId: "1") - let pendingMutation = makeMutationEvent(modelId: "2") - let results = RemoteSyncReconciler.filter([remoteModel], pendingMutations: [pendingMutation]) - - XCTAssertEqual(results.first?.model.id, remoteModel.model.id) - } // MARK: - reconcile(remoteModel:localMetadata) diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/Support/MutationEventExtensionsTests.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/Support/MutationEventExtensionsTests.swift index 7938a953ff..ab8f7640c1 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/Support/MutationEventExtensionsTests.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/Support/MutationEventExtensionsTests.swift @@ -14,7 +14,6 @@ import XCTest @testable import AWSDataStorePlugin @testable import AWSPluginsCore -// TODO: This flaky test has been disabled, tracking issue: https://github.com/aws-amplify/amplify-ios/issues/1831 // swiftlint:disable type_body_length class MutationEventExtensionsTest: BaseDataStoreTests { @@ -23,7 +22,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests { /// - When: The sent model matches the received model and the first pending mutation event version is `nil`. /// - Then: The pending mutation event version should be updated to the received model version of 1. func testSentModelWithNilVersion_Reconciled() throws { - throw XCTSkip("TODO: fix this test") let modelId = UUID().uuidString let post = Post(id: modelId, title: "title", content: "content", createdAt: .now()) let requestMutationEvent = try createMutationEvent(model: post, @@ -88,7 +86,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests { /// - Then: The first pending mutation event(update) version should be updated to the received model version of 1 /// and the second pending mutation event version(delete) should not be updated. func testSentModelWithNilVersion_SecondPendingEventNotReconciled() throws { - throw XCTSkip("TODO: fix this test") let modelId = UUID().uuidString let post = Post(id: modelId, title: "title", content: "content", createdAt: .now()) let requestMutationEvent = try createMutationEvent(model: post, @@ -158,7 +155,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests { /// - When: The sent model matches the received model and the first pending mutation event version is 2. /// - Then: The first pending mutation event version should NOT be updated. func testSentModelVersionNewerThanResponseVersion_PendingEventNotReconciled() throws { - throw XCTSkip("TODO: fix this test") let modelId = UUID().uuidString let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now()) let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now()) @@ -221,7 +217,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests { /// - When: The sent model doesn't match the received model and the first pending mutation event version is 1. /// - Then: The first pending mutation event version should NOT be updated. func testSentModelNotEqualToResponseModel_PendingEventNotReconciled() throws { - throw XCTSkip("TODO: fix this test") let modelId = UUID().uuidString let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now()) let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now()) @@ -285,7 +280,6 @@ class MutationEventExtensionsTest: BaseDataStoreTests { /// - When: The sent model matches the received model and the first pending mutation event version is 1. /// - Then: The first pending mutation event version should be updated to received mutation sync version i.e. 2. func testPendingVersionReconciledSuccess() throws { - throw XCTSkip("TODO: fix this test") let modelId = UUID().uuidString let post1 = Post(id: modelId, title: "title1", content: "content1", createdAt: .now()) let post2 = Post(id: modelId, title: "title2", content: "content2", createdAt: .now()) diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/AWSPinpointBehavior.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/AWSPinpointBehavior.swift index 6a98e3b4dc..9f4c7d5d7a 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/AWSPinpointBehavior.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/AWSPinpointBehavior.swift @@ -41,19 +41,19 @@ public protocol AWSPinpointBehavior { /// Records the specified `PinpointEvent` to the local storage. /// - Parameter event: The `PinpointEvent` to persist func record(_ event: PinpointEvent) async throws - + /// Sets the interval for the automatic submission of event. If set to `TimeInterval.zero`, /// the automatic submission is disabled /// - Parameter interval: How much to wait between submissions /// - Parameter onSubmit: An optional callback to be run after each submission happens func setAutomaticSubmitEventsInterval(_ interval: TimeInterval, onSubmit: AnalyticsClientBehaviour.SubmitResult?) - + // MARK: Session /// Beings automatically tracking session activity in the device. /// - Parameter backgroundTimeout: How much to wait after the device goes to the background before stopping the session func startTrackingSessions(backgroundTimeout: TimeInterval) - + /// Submits all recorded events to Pinpoint. /// Events are automatically submitted when the application goes into the background. /// - Returns: An array of successfully submitted events. diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/AnalyticsClient.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/AnalyticsClient.swift index 6ed75f1ab6..51fb69a888 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/AnalyticsClient.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/AnalyticsClient.swift @@ -71,21 +71,20 @@ actor AnalyticsClient: AnalyticsClientBehaviour { self.eventRecorder = eventRecorder self.sessionProvider = sessionProvider } - + // Actors no longer use 'convenience' for inits. This is a warning in swift 5.7 and an error in swift 6+. // However, 'convenience' is required to build with swift <5.7 #if swift(>=5.7) init(applicationId: String, pinpointClient: PinpointClientProtocol, endpointClient: EndpointClientBehaviour, - sessionProvider: @escaping SessionProvider) throws - { + sessionProvider: @escaping SessionProvider) throws { let dbAdapter = try SQLiteLocalStorageAdapter(prefixPath: Constants.eventRecorderStoragePathPrefix, databaseName: applicationId) let eventRecorder = try EventRecorder(appId: applicationId, storage: AnalyticsEventSQLStorage(dbAdapter: dbAdapter), pinpointClient: pinpointClient, endpointClient: endpointClient) - + self.init(eventRecorder: eventRecorder, sessionProvider: sessionProvider) } #else @@ -98,11 +97,11 @@ actor AnalyticsClient: AnalyticsClientBehaviour { let eventRecorder = try EventRecorder(appId: applicationId, storage: AnalyticsEventSQLStorage(dbAdapter: dbAdapter), pinpointClient: pinpointClient, endpointClient: endpointClient) - + self.init(eventRecorder: eventRecorder, sessionProvider: sessionProvider) } #endif - + nonisolated var pinpointClient: PinpointClientProtocol { return eventRecorder.pinpointClient } @@ -278,7 +277,7 @@ actor AnalyticsClient: AnalyticsClientBehaviour { automaticSubmitEventsTimer = nil return } - + log.info("Enabling Automatic Submission of Events after \(interval) seconds.") automaticSubmitEventsTimer = RepeatingTimer.createRepeatingTimer( timeInterval: automaticSubmitEventsInterval, @@ -302,7 +301,7 @@ extension AnalyticsClient: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: self)) } - + public nonisolated var log: Logger { Self.log } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/EventRecorder.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/EventRecorder.swift index 61563d86fc..0beb869b77 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/EventRecorder.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/EventRecorder.swift @@ -88,11 +88,11 @@ actor EventRecorder: AnalyticsEventRecording { _ = try? await submissionTask?.value submittedEvents = [] let eventsBatch = try getBatchRecords() - if eventsBatch.count > 0 { + if eventsBatch.isEmpty { + log.verbose("No events to submit") + } else { let endpointProfile = await endpointClient.currentEndpointProfile() try await processBatch(eventsBatch, endpointProfile: endpointProfile) - } else { - log.verbose("No events to submit") } return submittedEvents } @@ -115,7 +115,7 @@ actor EventRecorder: AnalyticsEventRecording { } try storage.removeFailedEvents() let nextEventsBatch = try getBatchRecords() - if nextEventsBatch.count > 0 { + if !nextEventsBatch.isEmpty { try await processBatch(nextEventsBatch, endpointProfile: endpointProfile) } } @@ -231,7 +231,7 @@ actor EventRecorder: AnalyticsEventRecording { throw error } } - + private func handleError(_ error: Error, for pinpointEvents: [PinpointEvent]) { if isConnectivityError(error) { // Connectivity errors should be retried indefinitely, so we won't update the database @@ -256,7 +256,7 @@ actor EventRecorder: AnalyticsEventRecording { } return type(of: modeledError).isRetryable } - + private func errorDescription(_ error: Error) -> String { if isConnectivityError(error) { return AWSPinpointErrorConstants.deviceOffline.errorDescription @@ -273,7 +273,7 @@ actor EventRecorder: AnalyticsEventRecording { return error.localizedDescription } } - + private func isConnectivityError(_ error: Error) -> Bool { switch error { case let error as CommonRunTimeError: @@ -291,7 +291,7 @@ actor EventRecorder: AnalyticsEventRecording { return false } } - + private func deleteEvent(eventId: String) { retry(onErrorMessage: "Unable to delete event with id \(eventId).") { try storage.deleteEvent(eventId: eventId) @@ -303,18 +303,17 @@ actor EventRecorder: AnalyticsEventRecording { try storage.setDirtyEvent(eventId: eventId) } } - + private func markEventsAsDirty(_ events: [PinpointEvent]) { events.forEach { setDirtyEvent(eventId: $0.id) } } - private func incrementEventRetry(eventId: String) { retry(onErrorMessage: "Unable to update retry count for event with id \(eventId).") { try storage.incrementEventRetry(eventId: eventId) } } - + private func incrementRetryCounter(for events: [PinpointEvent]) { events.forEach { incrementEventRetry(eventId: $0.id) } } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/PinpointEvent+Bindings.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/PinpointEvent+Bindings.swift index 1105240b69..571d60b41d 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/PinpointEvent+Bindings.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/PinpointEvent+Bindings.swift @@ -75,7 +75,7 @@ extension PinpointEvent { guard let eventId = element[EventPropertyIndex.id] as? String else { return nil } - + var retryCount = 0 if let retryCountInt = element[EventPropertyIndex.retryCount] as? Int64 { retryCount = Int(retryCountInt) diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/SQLiteLocalStorageAdapter.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/SQLiteLocalStorageAdapter.swift index 433c8b51fa..ae32ef37fd 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/SQLiteLocalStorageAdapter.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/LocalStorage/SQLiteLocalStorageAdapter.swift @@ -111,7 +111,7 @@ extension SQLiteLocalStorageAdapter: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/PinpointEvent.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/PinpointEvent.swift index 0d50342efb..a8296abaed 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/PinpointEvent.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Analytics/PinpointEvent.swift @@ -93,7 +93,7 @@ extension PinpointEvent: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } @@ -117,12 +117,12 @@ extension PinpointEvent: CustomStringConvertible { """ return string } - + private func string(from dictionary: AnalyticsProperties) -> String { if dictionary.isEmpty { return "[:]" } - + var string = "" for (key, value) in dictionary.sorted(by: { $0.key < $1.key}) { string += "\n\t\t\"\(key)\": \"\(value)\"" diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/AWSPinpointFactory.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/AWSPinpointFactory.swift index bae79890c2..05f64ea9e1 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/AWSPinpointFactory.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/AWSPinpointFactory.swift @@ -15,15 +15,15 @@ public class AWSPinpointFactory { let appId: String let region: String } - + private static var instances: AtomicDictionary = [:] - + private init() {} - + static var credentialsProvider = AWSAuthService().getCredentialsProvider() static var provisioningProfileReader: ProvisioningProfileReader = .default - + public static func sharedPinpoint(appId: String, region: String) throws -> AWSPinpointBehavior { let key = PinpointContextKey(appId: appId, region: region) @@ -49,10 +49,9 @@ public class AWSPinpointFactory { credentialsProvider: credentialsProvider, isDebug: isDebug ) - + let pinpointContext = try PinpointContext(with: configuration) instances[key] = pinpointContext return pinpointContext } } - diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext+AWSPinpointBehavior.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext+AWSPinpointBehavior.swift index 30a26275d9..30fe00f951 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext+AWSPinpointBehavior.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext+AWSPinpointBehavior.swift @@ -44,7 +44,7 @@ extension PinpointContext: AWSPinpointBehavior { await analyticsClient.removeGlobalMetric(forKey: forKey) } } - + func addGlobalProperty(_ value: AnalyticsPropertyValue, forKey: String) async { if let value = value as? String { await analyticsClient.addGlobalAttribute(value, forKey: forKey) @@ -57,17 +57,17 @@ extension PinpointContext: AWSPinpointBehavior { } } - func setRemoteGlobalAttributes(_ attributes: [String : String]) async { + func setRemoteGlobalAttributes(_ attributes: [String: String]) async { await analyticsClient.setRemoteGlobalAttributes(attributes) } - + func setAutomaticSubmitEventsInterval(_ interval: TimeInterval, onSubmit: AnalyticsClientBehaviour.SubmitResult?) { Task { await analyticsClient.setAutomaticSubmitEventsInterval(interval, onSubmit: onSubmit) } } - + func startTrackingSessions(backgroundTimeout: TimeInterval) { sessionClient.startTrackingSessions(backgroundTimeout: backgroundTimeout) } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext.swift index 70303f278e..ceeeab6cec 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Context/PinpointContext.swift @@ -47,7 +47,7 @@ extension FileManager: FileManagerBehaviour, DefaultLogger { public var log: Logger { Self.log } - + func createDirectory(atPath path: String, withIntermediateDirectories createIntermediates: Bool) throws { try createDirectory(atPath: path, withIntermediateDirectories: createIntermediates, diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/EndpointClient.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/EndpointClient.swift index 57954e552b..ac034e3653 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/EndpointClient.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Endpoint/EndpointClient.swift @@ -207,7 +207,7 @@ actor EndpointClient: EndpointClientBehaviour { log.error("Unable to migrate Analytics key-value store for key \(Constants.endpointProfileKey)") } } - + let keychainTokenData = try? keychain._getData(Constants.deviceTokenKey) if let tokenData = userDefaults.data(forKey: Constants.deviceTokenKey), keychainTokenData == nil { do { diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/Data+HexString.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/Data+HexString.swift index 66363af0fd..0681f85c91 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/Data+HexString.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/Data+HexString.swift @@ -18,7 +18,7 @@ extension Data { .map { String(chars[$0]) + String(chars[$0 + 1]) } .compactMap { UInt8($0, radix: 16) } - guard bytes.count > 0, hexString.count / bytes.count == 2 else { + guard !bytes.isEmpty, hexString.count / bytes.count == 2 else { return nil } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/SDKModels+AmplifyStringConvertible.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/SDKModels+AmplifyStringConvertible.swift index 33274a5a25..3421574914 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/SDKModels+AmplifyStringConvertible.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Extensions/SDKModels+AmplifyStringConvertible.swift @@ -14,7 +14,7 @@ extension PutEventsOutput: AmplifyStringConvertible { enum CodingKeys: Swift.String, Swift.CodingKey { case eventsResponse = "EventsResponse" } - + public func encode(to encoder: Encoder) throws { var encodeContainer = encoder.container(keyedBy: CodingKeys.self) if let eventsResponse = self.eventsResponse { diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/ActivityTracker.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/ActivityTracker.swift index 20692be11e..1b64474a61 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/ActivityTracker.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/ActivityTracker.swift @@ -55,14 +55,14 @@ extension ApplicationState: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } } protocol ActivityTrackerBehaviour: AnyObject { - var backgroundTrackingTimeout: TimeInterval { set get } + var backgroundTrackingTimeout: TimeInterval { get set } func beginActivityTracking(_ listener: @escaping (ApplicationState) -> Void) } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/StateMachine.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/StateMachine.swift index 6d3cbcf876..58bbe66676 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/StateMachine.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/ActivityTracking/StateMachine.swift @@ -111,7 +111,7 @@ extension StateMachine: DefaultLogger { public static var log: Logger { Amplify.Logging.logger(forCategory: CategoryType.analytics.displayName, forNamespace: String(describing: self)) } - + public var log: Logger { Self.log } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/SessionClient.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/SessionClient.swift index 1837fd7487..4f653d69d1 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/SessionClient.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Session/SessionClient.swift @@ -72,7 +72,7 @@ class SessionClient: SessionClientBehaviour { startNewSession() } } - + func startTrackingSessions(backgroundTimeout: TimeInterval) { sessionBackgroundTimeout = backgroundTimeout activityTracker.backgroundTrackingTimeout = backgroundTimeout diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Constants/AWSPinpointErrorConstants.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Constants/AWSPinpointErrorConstants.swift index 16019e6c5c..0eaeb915fd 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Constants/AWSPinpointErrorConstants.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Constants/AWSPinpointErrorConstants.swift @@ -45,7 +45,7 @@ public struct AWSPinpointErrorConstants { "Region is empty", "Ensure should not be empty" ) - + public static let deviceOffline: AWSPinpointErrorString = ( "The device does not have internet access. Please ensure the device is online and try again.", "" diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift index fede14232a..6f12af8567 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/AmplifyStringConvertible.swift @@ -16,7 +16,7 @@ extension AmplifyStringConvertible { encoder.dateEncodingStrategy = .iso8601 return encoder } - + public var description: String { if let data = try? Self.jsonEncoder.encode(self), let result = String(data: data, encoding: .utf8) { diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/PinpointRequestsRegistry.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/PinpointRequestsRegistry.swift index 6c0b33dc99..55e42943ce 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/PinpointRequestsRegistry.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/PinpointRequestsRegistry.swift @@ -29,11 +29,11 @@ import AWSPluginsCore ) } - fileprivate func sources(for api: API) -> Set { + func sources(for api: API) -> Set { return pendingRequests[api, default: []] } - fileprivate func unregisterSources(for api: API) { + func unregisterSources(for api: API) { pendingRequests[api] = nil } diff --git a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/RemoteNotificationsHelper.swift b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/RemoteNotificationsHelper.swift index e09c675571..514ec7e7fb 100644 --- a/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/RemoteNotificationsHelper.swift +++ b/AmplifyPlugins/Internal/Sources/InternalAWSPinpoint/Support/Utils/RemoteNotificationsHelper.swift @@ -52,4 +52,3 @@ public struct AmplifyRemoteNotificationsHelper: RemoteNotificationsBehaviour { await AUNotificationPermissions.registerForRemoteNotifications() } } - diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift index 4503f4eaf1..86a63bd956 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift @@ -35,7 +35,7 @@ final class AWSCloudWatchLoggingCategoryClient { private var userIdentifier: String? private var authSubscription: AnyCancellable? { willSet { authSubscription?.cancel() } } private let networkMonitor: LoggingNetworkMonitor - + init( enable: Bool, credentialsProvider: CredentialsProviding, @@ -62,7 +62,7 @@ final class AWSCloudWatchLoggingCategoryClient { self?.handle(payload: payload) } } - + func takeUserIdentifierFromCurrentUser() { Task { do { @@ -74,7 +74,7 @@ final class AWSCloudWatchLoggingCategoryClient { self.updateSessionControllers() } } - + private func updateSessionControllers() { lock.execute { for controller in loggersByKey.values { @@ -82,7 +82,7 @@ final class AWSCloudWatchLoggingCategoryClient { } } } - + private func handle(payload: HubPayload) { enum CognitoEventName: String { case signInAPI = "Auth.signInAPI" @@ -98,15 +98,15 @@ final class AWSCloudWatchLoggingCategoryClient { break } } - + /// - Tag: CloudWatchLoggingCategoryClient.reset func reset() async { lock.execute { loggersByKey = [:] } } - - func getLoggerSessionController(forCategory category: String, logLevel: LogLevel) -> AWSCloudWatchLoggingSessionController? { + + func getLoggerSessionController(forCategory category: String, logLevel: LogLevel) -> AWSCloudWatchLoggingSessionController? { let key = LoggerKey(category: category, logLevel: logLevel) if let existing = loggersByKey[key] { return existing @@ -124,7 +124,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior { } } } - + func disable() { enabled = false lock.execute { @@ -133,19 +133,18 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior { } } } - + var `default`: Logger { return self.logger(forCategory: "Amplify") } - + func logger(forCategory category: String, namespace: String?, logLevel: Amplify.LogLevel) -> Logger { return lock.execute { let key = LoggerKey(category: category, logLevel: logLevel) if let existing = loggersByKey[key] { return existing } - - + let controller = AWSCloudWatchLoggingSessionController(credentialsProvider: credentialsProvider, authentication: authentication, logFilter: self.logFilter, @@ -164,25 +163,25 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior { return controller } } - + func logger(forCategory category: String, logLevel: LogLevel) -> Logger { return self.logger(forCategory: category, namespace: nil, logLevel: logLevel) } - + func logger(forCategory category: String) -> Logger { let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier) return self.logger(forCategory: category, namespace: nil, logLevel: defaultLogLevel) } - + func logger(forNamespace namespace: String) -> Logger { self.logger(forCategory: namespace) } - + func logger(forCategory category: String, forNamespace namespace: String) -> Logger { let defaultLogLevel = logFilter.getDefaultLogLevel(forCategory: category, userIdentifier: self.userIdentifier) return self.logger(forCategory: category, namespace: namespace, logLevel: defaultLogLevel) } - + func getInternalClient() -> CloudWatchLogsClientProtocol { guard let client = loggersByKey.first(where: { $0.value.client != nil })?.value.client else { return Fatal.preconditionFailure( @@ -194,7 +193,7 @@ extension AWSCloudWatchLoggingCategoryClient: LoggingCategoryClientBehavior { } return client } - + func flushLogs() async throws { guard enabled else { return } for logger in loggersByKey.values { diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingError.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingError.swift index 7ce738b55c..e10a67b862 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingError.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingError.swift @@ -12,17 +12,17 @@ import Foundation struct AWSCloudWatchLoggingError: AmplifyError { var errorDescription: String - + var recoverySuggestion: String - + var underlyingError: Error? - + init(errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion, error: Error) { self.errorDescription = errorDescription self.recoverySuggestion = recoverySuggestion self.underlyingError = error } - + init(errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion) { self.errorDescription = errorDescription self.recoverySuggestion = recoverySuggestion diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift index e740e0618a..2271e877d8 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift @@ -17,21 +17,21 @@ import Foundation /// delegates all calls to the default Console logger implementation. /// /// - Tag: CloudWatchLoggingPlugin -public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { +public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { /// An instance of the authentication service. var loggingClient: AWSCloudWatchLoggingCategoryClient! - + private var loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration? private var remoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider? - + public var key: PluginKey { return PluginConstants.awsCloudWatchLoggingPluginKey } - + public var `default`: Logger { loggingClient.default } - + public init( loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration? = nil, remoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider? = nil @@ -66,37 +66,37 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { public func logger(forCategory category: String) -> Logger { return loggingClient.logger(forCategory: category) } - + public func logger(forNamespace namespace: String) -> Logger { return loggingClient.logger(forCategory: namespace) } - + public func logger(forCategory category: String, forNamespace namespace: String) -> Logger { return loggingClient.logger(forCategory: category, forNamespace: namespace) } - + /// enable plugin public func enable() { loggingClient.enable() } - + /// disable plugin public func disable() { loggingClient.disable() } - + /// send logs on-demand to AWS CloudWatch public func flushLogs() async throws { try await loggingClient.flushLogs() } - + /// Retrieve the escape hatch to perform low level operations on AWSCloudWatch /// /// - Returns: AWS CloudWatch Client public func getEscapeHatch() -> CloudWatchLogsClientProtocol { return loggingClient.getInternalClient() } - + /// Resets the state of the plugin. /// /// Calls the reset methods on the storage service and authentication service to clean up resources. Setting the @@ -104,7 +104,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { public func reset() async { await loggingClient.reset() } - + /// Configures AWSS3StoragePlugin with the specified configuration. /// /// This method will be invoked as part of the Amplify configuration flow. Retrieves the bucket, region, and @@ -117,14 +117,14 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { if self.loggingPluginConfiguration == nil, let configuration = try? AWSCloudWatchLoggingPluginConfiguration(bundle: Bundle.main) { self.loggingPluginConfiguration = configuration let authService = AWSAuthService() - + if let remoteConfig = configuration.defaultRemoteConfiguration, self.remoteLoggingConstraintsProvider == nil { self.remoteLoggingConstraintsProvider = DefaultRemoteLoggingConstraintsProvider( endpoint: remoteConfig.endpoint, region: configuration.region, refreshIntervalInSeconds: remoteConfig.refreshIntervalInSeconds) } - + self.loggingClient = AWSCloudWatchLoggingCategoryClient( enable: configuration.enable, credentialsProvider: authService.getCredentialsProvider(), @@ -136,7 +136,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { flushIntervalInSeconds: configuration.flushIntervalInSeconds ) } - + if self.loggingPluginConfiguration == nil { throw LoggingError.configuration( """ @@ -149,12 +149,12 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin { """ ) } - + if self.remoteLoggingConstraintsProvider == nil { let localStore: LoggingConstraintsLocalStore = UserDefaults.standard localStore.reset() } - + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) { self.loggingClient.takeUserIdentifierFromCurrentUser() } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift index cccc6ba408..cfa0013092 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSession.swift @@ -84,5 +84,6 @@ extension AWSCloudWatchLoggingSession: LogBatchProducer { } extension AWSCloudWatchLoggingError { - static let sessionInternalErrorForUserId = AWSCloudWatchLoggingError(errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: "") + static let sessionInternalErrorForUserId = AWSCloudWatchLoggingError( + errorDescription: "Internal error while attempting to interpret userId", recoverySuggestion: "") } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSessionController.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSessionController.swift index 7cb6c4a74e..76b32228ce 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSessionController.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingSessionController.swift @@ -19,7 +19,7 @@ import Network /// /// - Tag: CloudWatchLogSessionController final class AWSCloudWatchLoggingSessionController { - + var client: CloudWatchLogsClientProtocol? let namespace: String? private let logGroupName: String @@ -32,13 +32,13 @@ final class AWSCloudWatchLoggingSessionController { private var consumer: LogBatchConsumer? private let logFilter: AWSCloudWatchLoggingFilterBehavior private let networkMonitor: LoggingNetworkMonitor - + private var batchSubscription: AnyCancellable? { willSet { batchSubscription?.cancel() } } - + private var authSubscription: AnyCancellable? { willSet { authSubscription?.cancel() @@ -83,13 +83,13 @@ final class AWSCloudWatchLoggingSessionController { self.userIdentifier = userIdentifier self.networkMonitor = networkMonitor } - + func enable() { updateSession() updateConsumer() connectProducerAndConsumer() } - + func disable() { self.batchSubscription = nil self.authSubscription = nil @@ -119,7 +119,7 @@ final class AWSCloudWatchLoggingSessionController { logGroupName: self.logGroupName, userIdentifier: self.userIdentifier) } - + private func connectProducerAndConsumer() { guard let consumer = consumer else { self.batchSubscription = nil @@ -143,14 +143,14 @@ final class AWSCloudWatchLoggingSessionController { } } } - + private func userIdentifierDidChange() { resetCurrentLogs() updateSession() updateConsumer() connectProducerAndConsumer() } - + private func updateSession() { do { self.session = try AWSCloudWatchLoggingSession(category: self.category, @@ -163,19 +163,19 @@ final class AWSCloudWatchLoggingSessionController { print(error) } } - + func setCurrentUser(identifier: String?) { self.userIdentifier = identifier } - + func flushLogs() async throws { guard let logBatches = try await session?.logger.getLogBatches() else { return } - + for batch in logBatches { try await consumeLogBatch(batch) } } - + private func consumeLogBatch(_ batch: LogBatch) async throws { do { try await consumer?.consume(batch: batch) @@ -186,7 +186,7 @@ final class AWSCloudWatchLoggingSessionController { try batch.complete() } } - + private func resetCurrentLogs() { Task { do { @@ -203,27 +203,27 @@ extension AWSCloudWatchLoggingSessionController: Logger { guard self.logFilter.canLog(withCategory: self.category, logLevel: .error, userIdentifier: self.userIdentifier) else { return } session?.logger.error(message()) } - + func error(error: Error) { guard self.logFilter.canLog(withCategory: self.category, logLevel: .error, userIdentifier: self.userIdentifier) else { return } session?.logger.error(error: error) } - + func warn(_ message: @autoclosure () -> String) { guard self.logFilter.canLog(withCategory: self.category, logLevel: .warn, userIdentifier: self.userIdentifier) else { return } session?.logger.warn(message()) } - + func info(_ message: @autoclosure () -> String) { guard self.logFilter.canLog(withCategory: self.category, logLevel: .info, userIdentifier: self.userIdentifier) else { return } session?.logger.info(message()) } - + func debug(_ message: @autoclosure () -> String) { guard self.logFilter.canLog(withCategory: self.category, logLevel: .debug, userIdentifier: self.userIdentifier) else { return } session?.logger.debug(message()) } - + func verbose(_ message: @autoclosure () -> String) { guard self.logFilter.canLog(withCategory: self.category, logLevel: .verbose, userIdentifier: self.userIdentifier) else { return } session?.logger.verbose(message()) diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/AWSCloudWatchLoggingPluginConfiguration.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/AWSCloudWatchLoggingPluginConfiguration.swift index 19d1cf67b7..5a9ad61361 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/AWSCloudWatchLoggingPluginConfiguration.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/AWSCloudWatchLoggingPluginConfiguration.swift @@ -99,4 +99,3 @@ extension AWSCloudWatchLoggingPluginConfiguration { } } } - diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteConfiguration.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteConfiguration.swift index f833feb98a..79ca6c14d3 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteConfiguration.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteConfiguration.swift @@ -16,7 +16,7 @@ public struct DefaultRemoteConfiguration: Codable { self.endpoint = endpoint self.refreshIntervalInSeconds = refreshIntervalInSeconds } - + public let endpoint: URL public let refreshIntervalInSeconds: Int } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift index 5f8b29c344..64c9863a96 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift @@ -11,23 +11,23 @@ import AWSPluginsCore import AWSClientRuntime import ClientRuntime -public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider { +public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsProvider { public let refreshIntervalInSeconds: Int private let endpoint: URL private let credentialProvider: CredentialsProviding? private let region: String private let loggingConstraintsLocalStore: LoggingConstraintsLocalStore = UserDefaults.standard - + private var loggingConstraint: LoggingConstraints? { return loggingConstraintsLocalStore.getLocalLoggingConstraints() } - + private var refreshTimer: DispatchSourceTimer? { willSet { refreshTimer?.cancel() } } - + public init( endpoint: URL, region: String, @@ -44,26 +44,26 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr self.refreshIntervalInSeconds = refreshIntervalInSeconds self.setupAutomaticRefreshInterval() } - + public func fetchLoggingConstraints() async throws -> LoggingConstraints { var url = URLRequest(url: endpoint) if let etag = loggingConstraintsLocalStore.getLocalLoggingConstraintsEtag() { url.setValue(etag, forHTTPHeaderField: "If-None-Match") } let signedRequest = try await sigV4Sign(url, region: region) - let (data,response) = try await URLSession.shared.data(for: signedRequest) + let (data, response) = try await URLSession.shared.data(for: signedRequest) if (response as? HTTPURLResponse)?.statusCode == 304, let cachedValue = self.loggingConstraint { return cachedValue } let loggingConstraint = try JSONDecoder().decode(LoggingConstraints.self, from: data) loggingConstraintsLocalStore.setLocalLoggingConstraints(loggingConstraints: loggingConstraint) - + if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "If-None-Match") { loggingConstraintsLocalStore.setLocalLoggingConstraintsEtag(etag: etag) } return loggingConstraint } - + func sigV4Sign(_ request: URLRequest, region: String) async throws -> URLRequest { var request = request guard let url = request.url else { @@ -72,7 +72,7 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr guard let host = url.host else { throw APIError.unknown("Could not get host from mutable request", "") } - + request.setValue("application/json", forHTTPHeaderField: "Content-Type") request.setValue(host, forHTTPHeaderField: "host") @@ -92,11 +92,11 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr .withProtocol(.https) .withHeaders(.init(request.allHTTPHeaderFields ?? [:])) .withBody(.data(request.httpBody)) - + guard let credentialProvider = self.credentialProvider else { return request } - + guard let urlRequest = try await AmplifyAWSSignatureV4Signer().sigV4SignedRequest( requestBuilder: requestBuilder, credentialsProvider: credentialProvider, @@ -113,7 +113,7 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr return request } - + func refresh() { Task { do { @@ -123,13 +123,13 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr } } } - + func setupAutomaticRefreshInterval() { guard refreshIntervalInSeconds != .zero else { refreshTimer = nil return } - + refreshTimer = Self.createRepeatingTimer( timeInterval: TimeInterval(self.refreshIntervalInSeconds), eventHandler: { [weak self] in diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/LoggingConstraints.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/LoggingConstraints.swift index 5995194d7a..41feb1ef7f 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/LoggingConstraints.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/LoggingConstraints.swift @@ -18,7 +18,7 @@ public struct LoggingConstraints: Codable { self.categoryLogLevel = categoryLogLevel self.userLogLevel = userLogLevel } - + public let defaultLogLevel: LogLevel public let categoryLogLevel: [String: LogLevel]? public let userLogLevel: [String: UserLogLevel]? diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/UserLogLevel.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/UserLogLevel.swift index 3a2e29e9b7..dc35f4d9fb 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/UserLogLevel.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/UserLogLevel.swift @@ -16,7 +16,7 @@ public struct UserLogLevel: Codable { self.defaultLogLevel = defaultLogLevel self.categoryLogLevel = categoryLogLevel } - + public let defaultLogLevel: LogLevel public let categoryLogLevel: [String: LogLevel] } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingConsumer.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingConsumer.swift index 4ec0d6aa87..a0cfb45b7d 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingConsumer.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingConsumer.swift @@ -12,7 +12,7 @@ import Amplify import Foundation class CloudWatchLoggingConsumer { - + private let client: CloudWatchLogsClientProtocol private let logGroupName: String private let logStreamName: String @@ -38,7 +38,7 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { return } await ensureLogStreamExists() - + let batchByteSize = try encoder.encode(entries).count if entries.count > AWSCloudWatchConstants.maxLogEvents { let smallerEntries = entries.chunked(into: AWSCloudWatchConstants.maxLogEvents) @@ -53,7 +53,7 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { try await sendLogEvents(entries) } } - + } else if batchByteSize > AWSCloudWatchConstants.maxBatchByteSize { let smallerEntries = try chunk(entries, into: AWSCloudWatchConstants.maxBatchByteSize) for entries in smallerEntries { @@ -62,19 +62,19 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { } else { try await sendLogEvents(entries) } - + try batch.complete() } - + private func ensureLogStreamExists() async { if ensureLogStreamExistsComplete { return } - + defer { ensureLogStreamExistsComplete = true } - + let stream = try? await self.client.describeLogStreams(input: .init( logGroupName: self.logGroupName, logStreamNamePrefix: self.logStreamName @@ -84,13 +84,13 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { if stream != nil { return } - + _ = try? await self.client.createLogStream(input: .init( logGroupName: self.logGroupName, logStreamName: self.logStreamName )) } - + private func sendLogEvents(_ entries: [LogEntry]) async throws { let events = convertToCloudWatchInputLogEvents(for: entries) let response = try await self.client.putLogEvents(input: PutLogEventsInput( @@ -110,7 +110,7 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { )) } } - + private func convertToCloudWatchInputLogEvents(for entries: [LogEntry]) -> [CloudWatchLogsClientTypes.InputLogEvent] { let formatter = CloudWatchLoggingEntryFormatter() return entries.map { entry in @@ -120,23 +120,24 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { ) } } - + private func retriable(entries: [LogEntry], in response: PutLogEventsOutput) -> [LogEntry] { guard let tooNewLogEventStartIndex = response.rejectedLogEventsInfo?.tooNewLogEventStartIndex else { return [] } let totalEntries = entries.count - if (tooNewLogEventStartIndex < 0 || tooNewLogEventStartIndex >= totalEntries) { + if tooNewLogEventStartIndex < 0 || tooNewLogEventStartIndex >= totalEntries { return [] } - + var retriableEntries: [LogEntry] = [] for index in tooNewLogEventStartIndex.. [[LogEntry]] { var chunks: [[LogEntry]] = [] var chunk: [LogEntry] = [] @@ -152,7 +153,8 @@ extension CloudWatchLoggingConsumer: LogBatchConsumer { currentChunkSize = currentChunkSize + entrySize } } - + return chunks } + // swiftlint:enable shorthand_operator } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingEntryFormatter.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingEntryFormatter.swift index a334d4f3ff..d96efc8a64 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingEntryFormatter.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingEntryFormatter.swift @@ -32,6 +32,6 @@ struct CloudWatchLoggingEntryFormatter { return "\(entry.logLevelName)/\(entry.category): \(namespace): \(entry.message)" } else { return "\(entry.logLevelName)/\(entry.category): \(entry.message)" - } + } } } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingStreamNameFormatter.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingStreamNameFormatter.swift index 12b7ec93c0..d40e0eebe9 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingStreamNameFormatter.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Consumer/CloudWatchLoggingStreamNameFormatter.swift @@ -24,7 +24,7 @@ struct CloudWatchLoggingStreamNameFormatter { let userIdentifier: String? let deviceIdentifier: String? - + init(userIdentifier: String? = nil) { self.userIdentifier = userIdentifier #if canImport(WatchKit) diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Domain/LogBatchConsumer.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Domain/LogBatchConsumer.swift index e5d71f28f0..ff5b5b6c75 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Domain/LogBatchConsumer.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Domain/LogBatchConsumer.swift @@ -11,7 +11,7 @@ import Foundation /// [LogFile](x-source-tag://LogFile) /// protocol LogBatchConsumer { - + /// Processes the given [LogBatch](x-source-tag://LogBatch) and ensures to call /// [LogBatch.complete](x-source-tag://LogBatch.complete) on the given `batch` when /// done. diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogActor.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogActor.swift index 5647af3d38..91980583de 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogActor.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogActor.swift @@ -12,22 +12,22 @@ import Foundation /// Wrapper around a LogRotation to ensure /// thread-safe usage. actor LogActor { - + private let rotation: LogRotation private let rotationSubject: PassthroughSubject - + /// Initialized the actor with the given directory and fileCountLimit. init(directory: URL, fileSizeLimitInBytes: Int) throws { self.rotation = try LogRotation(directory: directory, fileSizeLimitInBytes: fileSizeLimitInBytes) self.rotationSubject = PassthroughSubject() } - + /// Attempts to persist the given log entry. func record(_ entry: LogEntry) throws { let data = try LogEntryCodec().encode(entry: entry) try write(data) } - + private func write(_ data: Data) throws { try rotation.ensureFileExists() if rotation.currentLogFile.hasSpace(for: data) { @@ -39,22 +39,22 @@ actor LogActor { rotationSubject.send(fileURL) } } - + func rotationPublisher() -> AnyPublisher { return rotationSubject.eraseToAnyPublisher() } - + /// Ensures the contents of the underlying file are flushed to disk. /// /// - Tag: LogActor.record func synchronize() throws { try rotation.currentLogFile.synchronize() } - + func getLogs() throws -> [URL] { return try rotation.getAllLogs() } - + func deleteLogs() throws { try rotation.reset() try synchronize() diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntry.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntry.swift index 1ee0d66ede..9ea55337a2 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntry.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntry.swift @@ -10,14 +10,14 @@ import Foundation /// Represents an individual row in a log. struct LogEntry: Codable, Hashable { - + /// The timestamp representing the creation time of the log entry or event. let created: Date /// The Amplify category logical tag of the log entry or event. This will likely be a /// Category name. let category: String - + /// Additional logical tag of the log entry or event. This will likely be a /// the namespace of the code module being logged. let namespace: String? @@ -25,10 +25,10 @@ struct LogEntry: Codable, Hashable { /// An integer representation of the [LogLevel](x-source-tag://LogLevel) /// associated with the receiver. This attribute's uses an Int to accomodate coding. private let level: Int - + /// The main payload String associated with the receiver. let message: String - + /// The log level associated with the receiver. var logLevel: LogLevel { if let result = LogLevel(rawValue: self.level) { @@ -36,7 +36,7 @@ struct LogEntry: Codable, Hashable { } return .error } - + /// - Returns: String representation of log level var logLevelName: String { switch logLevel { @@ -48,11 +48,11 @@ struct LogEntry: Codable, Hashable { case .none: return "NONE" } } - + var millisecondsSince1970: Int { Int((created.timeIntervalSince1970 * 1000.0).rounded()) } - + init(category: String, namespace: String?, level: LogLevel, message: String, created: Date = Date()) { self.created = created self.level = level.rawValue @@ -60,5 +60,5 @@ struct LogEntry: Codable, Hashable { self.namespace = namespace self.message = message } - + } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntryCodec.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntryCodec.swift index 43f0349848..8f78e7959b 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntryCodec.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogEntryCodec.swift @@ -17,7 +17,7 @@ struct LogEntryCodec { case invalidScheme(log: URL) case invalidEncoding(log: URL) } - + func encode(entry: LogEntry) throws -> Data { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .millisecondsSince1970 @@ -26,19 +26,19 @@ struct LogEntryCodec { data.append(Self.lineDelimiter) return data } - + func decode(data: Data) throws -> LogEntry { let decoder = JSONDecoder() decoder.dateDecodingStrategy = .millisecondsSince1970 return try decoder.decode(LogEntry.self, from: data) } - + func decode(string: String) throws -> LogEntry? { let trimmed = string.trim() let data = Data(trimmed.utf8) return try decode(data: data) } - + func decode(from fileURL: URL) throws -> [LogEntry] { guard fileURL.isFileURL else { throw DecodingError.invalidScheme(log: fileURL) diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogFile.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogFile.swift index f61f310c53..03ee67607a 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogFile.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogFile.swift @@ -12,10 +12,10 @@ import Foundation final class LogFile { let fileURL: URL let sizeLimitInBytes: UInt64 - + private let handle: FileHandle private var count: UInt64 - + /// Creates a new file with the given URL and sets its attributes accordingly. init(forWritingTo fileURL: URL, sizeLimitInBytes: UInt64) throws { self.fileURL = fileURL @@ -35,11 +35,11 @@ final class LogFile { self.count = self.handle.offsetInFile } } - + deinit { try? self.handle.close() } - + /// Returns the number of bytes available in the underlying file. var available: UInt64 { if sizeLimitInBytes > count { @@ -48,32 +48,32 @@ final class LogFile { return 0 } } - + /// Attempts to close the underlying log file. func close() throws { try self.handle.close() } - + /// Atempts to flush the receivers contents to disk. func synchronize() throws { try self.handle.synchronize() } - + /// - Returns: true if writing to the underlying log file will keep its size below the limit. func hasSpace(for data: Data) -> Bool { return UInt64(data.count) <= self.available } - + /// Writes the given **single line of text** represented as a /// Data to the underlying log file. - func write(data: Data) throws { + func write(data: Data) throws { if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) { try self.handle.write(contentsOf: data) } else { self.handle.write(data) } try self.handle.synchronize() - count = count + UInt64(data.count) + count = count + UInt64(data.count) // swiftlint:disable:this shorthand_operator } - + } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift index 6fb4ad7f32..32552df26c 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Persistence/LogRotation.swift @@ -9,22 +9,22 @@ import Foundation /// Represents a directory that contains a set of log files that are part of a LogRotation. final class LogRotation { - + enum LogRotationError: Error { /// Represents the scenario when a caller attempts to initialize a /// `LogRotation` with an invalid file size limit (minimum is 1KB). case invalidFileSizeLimitInBytes(Int) } - + static let minimumFileSizeLimitInBytes = 1024 /* 1KB */ - + /// The name pattern of files managed by `LogRotation`. private static let filePattern = #"amplify[.]([0-9])[.]log"# let directory: URL let fileCountLimit: Int = 5 let fileSizeLimitInBytes: UInt64 - + private(set) var currentLogFile: LogFile { willSet { try? currentLogFile.synchronize() @@ -33,17 +33,17 @@ final class LogRotation { } init(directory: URL, fileSizeLimitInBytes: Int) throws { - if (fileSizeLimitInBytes < LogRotation.minimumFileSizeLimitInBytes) { + if fileSizeLimitInBytes < LogRotation.minimumFileSizeLimitInBytes { throw LogRotationError.invalidFileSizeLimitInBytes(fileSizeLimitInBytes) } - + self.directory = directory.absoluteURL self.fileSizeLimitInBytes = UInt64(fileSizeLimitInBytes) self.currentLogFile = try Self.selectNextLogFile(from: self.directory, fileCountLimit: fileCountLimit, fileSizeLimitInBytes: self.fileSizeLimitInBytes) } - + /// Selects the most-available log file. /// /// The criteria is roughly as follows: @@ -58,11 +58,11 @@ final class LogRotation { fileCountLimit: self.fileCountLimit, fileSizeLimitInBytes: self.fileSizeLimitInBytes) } - + func getAllLogs() throws -> [URL] { return try Self.listLogFiles(in: directory) } - + func reset() throws { let existingFiles = try Self.listLogFiles(in: directory) for file in existingFiles { @@ -72,7 +72,7 @@ final class LogRotation { index: 0, fileSizeLimitInBytes: fileSizeLimitInBytes) } - + private static func selectNextLogFile(from directory: URL, fileCountLimit: Int, fileSizeLimitInBytes: UInt64) throws -> LogFile { @@ -82,7 +82,7 @@ final class LogRotation { index: index, fileSizeLimitInBytes: fileSizeLimitInBytes) } - + if let underutilized = try Self.oldestUnderutilizedFile(from: existingFiles, sizeLimitInBytes: fileSizeLimitInBytes) { return try LogFile(forAppending: underutilized, @@ -93,12 +93,12 @@ final class LogRotation { return try LogFile(forWritingTo: oldestFileURL, sizeLimitInBytes: fileSizeLimitInBytes) } - + return try createLogFile(in: directory, index: 0, fileSizeLimitInBytes: fileSizeLimitInBytes) } - + func ensureFileExists() throws { if !FileManager.default.fileExists(atPath: currentLogFile.fileURL.relativePath) { try rotate() @@ -124,7 +124,7 @@ final class LogRotation { } return (lastIndex + 1) % fileCountLimit } - + /// - Returns: The URL for the file with the oldest last modified date (assumes that the list of files are presorted by date with oldest last) that /// also is taking up less than half of the size limit. private static func oldestUnderutilizedFile(from existingFiles: [URL], sizeLimitInBytes: UInt64) throws -> URL? { @@ -143,7 +143,7 @@ final class LogRotation { private static func listLogFiles(in directory: URL) throws -> [URL] { let fileManager: FileManager = FileManager.default let propertyKeys: [URLResourceKey] = [.contentModificationDateKey, .nameKey, .fileSizeKey] - return try fileManager.contentsOfDirectory(at: directory, includingPropertiesForKeys:propertyKeys) + return try fileManager.contentsOfDirectory(at: directory, includingPropertiesForKeys: propertyKeys) .filter { try index(of: $0) != nil } .sorted(by: { lhs, rhs in let lhsAttributes = try fileManager.attributesOfItem(atPath: lhs.path) @@ -185,15 +185,18 @@ final class LogRotation { let fileURL = directory.appendingPathComponent("amplify.\(index).log") fileManager.createFile(atPath: fileURL.path, contents: nil, - attributes: [FileAttributeKey : Any]()) + attributes: [FileAttributeKey: Any]()) if #available(macOS 11.0, *) { - let resourceValues: [URLResourceKey : Any] = [URLResourceKey.fileProtectionKey: URLFileProtection.complete, URLResourceKey.isExcludedFromBackupKey: true] + let resourceValues: [URLResourceKey: Any] = [ + URLResourceKey.fileProtectionKey: URLFileProtection.complete, + URLResourceKey.isExcludedFromBackupKey: true + ] try (fileURL as NSURL).setResourceValues(resourceValues) - } else { - let resourceValues: [URLResourceKey : Any] = [URLResourceKey.isExcludedFromBackupKey: true] + } else { + let resourceValues: [URLResourceKey: Any] = [URLResourceKey.isExcludedFromBackupKey: true] try (fileURL as NSURL).setResourceValues(resourceValues) } - + return try LogFile(forWritingTo: fileURL, sizeLimitInBytes: fileSizeLimitInBytes) } } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Producer/RotatingLogger.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Producer/RotatingLogger.swift index 3a2810a877..238dbfb7d5 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Producer/RotatingLogger.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Producer/RotatingLogger.swift @@ -10,9 +10,9 @@ import Combine import Foundation final class RotatingLogger { - + var logLevel: Amplify.LogLevel - + private let category: String private let namespace: String? private let actor: LogActor @@ -37,29 +37,29 @@ final class RotatingLogger { self.batchSubject = PassthroughSubject() self.logLevel = logLevel } - + /// Attempts to flush the contents of the log to disk. func synchronize() async throws { try await actor.synchronize() } - + func getLogBatches() async throws -> [RotatingLogBatch] { let logs = try await actor.getLogs() return logs.map({RotatingLogBatch(url: $0)}) } - + func resetLogs() async throws { try await actor.deleteLogs() } - + func record(level: LogLevel, message: @autoclosure () -> String) async throws { try await setupSubscription() let entry = LogEntry(category: self.category, namespace: self.namespace, level: level, message: message()) try await self.actor.record(entry) } - + private func setupSubscription() async throws { - if (rotationSubscription == nil) { + if rotationSubscription == nil { let rotationPublisher = await self.actor.rotationPublisher() rotationSubscription = rotationPublisher.sink { [weak self] url in guard let self = self else { return } @@ -72,7 +72,7 @@ final class RotatingLogger { let payload = message() Task { do { - try await self.record(level: level, message:payload) + try await self.record(level: level, message: payload) } catch { let payload = HubPayload( eventName: HubPayload.EventName.Logging.writeLogFailure, @@ -91,28 +91,28 @@ extension RotatingLogger: LogBatchProducer { } extension RotatingLogger: Logger { - + func error(_ message: @autoclosure () -> String) { _record(level: .error, message: message()) } - + func error(error: Error) { let message = String(describing: error) _record(level: .error, message: message) } - + func warn(_ message: @autoclosure () -> String) { _record(level: .warn, message: message()) } - + func info(_ message: @autoclosure () -> String) { _record(level: .info, message: message()) } - + func debug(_ message: @autoclosure () -> String) { _record(level: .debug, message: message()) } - + func verbose(_ message: @autoclosure () -> String) { _record(level: .verbose, message: message()) } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingConstraintsResolver.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingConstraintsResolver.swift index 3c71953fb2..7dce65c2d2 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingConstraintsResolver.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingConstraintsResolver.swift @@ -13,13 +13,13 @@ import AWSPluginsCore class AWSCloudWatchLoggingConstraintsResolver { let loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration let loggingConstraintsLocalStore: LoggingConstraintsLocalStore - + init(loggingPluginConfiguration: AWSCloudWatchLoggingPluginConfiguration, loggingConstraintsLocalStore: LoggingConstraintsLocalStore = UserDefaults.standard) { self.loggingPluginConfiguration = loggingPluginConfiguration self.loggingConstraintsLocalStore = loggingConstraintsLocalStore } - + /// Returns the active valid logging constraints /// /// - Returns: the LoggingConstraints diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingFilter.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingFilter.swift index 149690d40a..861e05367c 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingFilter.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/AWSCloudWatchLoggingFilter.swift @@ -35,13 +35,13 @@ class AWSCloudWatchLoggingFilter: AWSCloudWatchLoggingFilterBehavior { } return logLevel.rawValue <= userConstraints.defaultLogLevel.rawValue && userConstraints.defaultLogLevel != .none } - + // 2. look for category constraint, is category and log level enabled if let categoryLogLevel = loggingConstraints.categoryLogLevel?.first(where: { $0.key.lowercased() == loweredCasedCategory })?.value { - + return logLevel.rawValue <= categoryLogLevel.rawValue && categoryLogLevel != .none } - + // 3. look for default constraint return logLevel.rawValue <= loggingConstraints.defaultLogLevel.rawValue && loggingConstraints.defaultLogLevel != .none } @@ -51,18 +51,18 @@ class AWSCloudWatchLoggingFilter: AWSCloudWatchLoggingFilterBehavior { /// - Returns: the default LogLevel func getDefaultLogLevel(forCategory category: String, userIdentifier: String?) -> LogLevel { let loweredCasedCategory = category.lowercased() - + if let userConstraints = loggingConstraints.userLogLevel?.first(where: { $0.key == userIdentifier })?.value { if let categoryLogLevel = userConstraints.categoryLogLevel.first(where: { $0.key.lowercased() == loweredCasedCategory })?.value { return categoryLogLevel } return userConstraints.defaultLogLevel } - + if let categoryLogLevel = loggingConstraints.categoryLogLevel?.first(where: { $0.key.lowercased() == loweredCasedCategory })?.value { return categoryLogLevel } - + return loggingConstraints.defaultLogLevel } } diff --git a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/Constants/AWSCloudWatchConstants.swift b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/Constants/AWSCloudWatchConstants.swift index 4ab68734f0..295814e8c5 100644 --- a/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/Constants/AWSCloudWatchConstants.swift +++ b/AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Support/Constants/AWSCloudWatchConstants.swift @@ -9,10 +9,10 @@ import Foundation /// Defines AWS CloudWatch SDK constants struct AWSCloudWatchConstants { - + /// the max byte size of log events that can be sent is 1 MB static let maxBatchByteSize: Int64 = 1_000_000 - + /// the max number of log events that can be sent is 10,000 static let maxLogEvents = 10_000 } diff --git a/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift b/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift index 2c615a7cab..f85e79be0b 100644 --- a/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift +++ b/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+ClientBehaviour.swift @@ -85,7 +85,9 @@ extension AWSPinpointPushNotificationsPlugin { guard let payload = userInfo.payload else { log.error( """ - No valid Pinpoint Push payload found. The recordNotification API only supports Pinpoint Campaigns and Journeys. Test messages will not be recorded. + No valid Pinpoint Push payload found. + The recordNotification API only supports Pinpoint Campaigns and Journeys. + Test messages will not be recorded. """ ) return @@ -140,7 +142,7 @@ extension AWSPinpointPushNotificationsPlugin { #elseif canImport(UIKit) let application = UIApplication.shared #endif - + #if canImport(UIKit) || canImport(WatchKit) switch application.applicationState { case .background: diff --git a/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Types.swift b/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Types.swift index d07eb48625..38949b0850 100644 --- a/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Types.swift +++ b/AmplifyPlugins/Notifications/Push/Sources/AWSPinpointPushNotificationsPlugin/AWSPinpointPushNotificationsPlugin+Types.swift @@ -9,7 +9,7 @@ import AmplifyUtilsNotifications import Foundation extension AWSPinpointPushNotificationsPlugin { - + #if !os(tvOS) /// Service Extension that can handle AWS Pinpoint rich notifications. public typealias ServiceExtension = AUNotificationService diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/AWSTranscribeStreamingAdapter.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/AWSTranscribeStreamingAdapter.swift index 97aed80ff8..ec0cbeb219 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/AWSTranscribeStreamingAdapter.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Dependency/AWSTranscribeStreamingAdapter.swift @@ -113,7 +113,6 @@ class AWSTranscribeStreamingAdapter: AWSTranscribeStreamingBehavior { webSocket.send(message: .data(endFrame), onError: { _ in }) } - let stream = AsyncThrowingStream { continuation in Task { webSocket.onMessageReceived { result in diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/DTOMapping.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/DTOMapping.swift index 7e1d1fa36e..9fc9cca08a 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/DTOMapping.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/DTOMapping.swift @@ -77,7 +77,6 @@ func colorChallenge(from event: ServerSessionInformationEvent) -> FaceLivenessSe ) } - func sessionConfiguration(from event: ServerSessionInformationEvent) -> FaceLivenessSession.SessionConfiguration { .init( colorChallenge: colorChallenge(from: event), diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+BoundingBox.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+BoundingBox.swift index ce45be3669..613808940b 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+BoundingBox.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+BoundingBox.swift @@ -7,6 +7,7 @@ import Foundation +// swiftlint:disable identifier_name extension FaceLivenessSession { @_spi(PredictionsFaceLiveness) public struct BoundingBox: Codable { @@ -28,3 +29,4 @@ extension FaceLivenessSession { } } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+ColorChallenge.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+ColorChallenge.swift index 9403143e4a..78c5b4a156 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+ColorChallenge.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Model/FaceLivenessSession+ColorChallenge.swift @@ -17,7 +17,7 @@ extension FaceLivenessSession { } } } - +// swiftlint:disable identifier_name extension FaceLivenessSession { @_spi(PredictionsFaceLiveness) public struct DisplayColor { @@ -47,3 +47,4 @@ extension FaceLivenessSession { } } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/SPI/AWSPredictionsPlugin+Liveness.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/SPI/AWSPredictionsPlugin+Liveness.swift index b0356cd769..f476122ab0 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/SPI/AWSPredictionsPlugin+Liveness.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/SPI/AWSPredictionsPlugin+Liveness.swift @@ -90,4 +90,3 @@ extension FaceLivenessSessionError { } } } - diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSession.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSession.swift index 22ff8f666b..7e2adf5064 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSession.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSession.swift @@ -82,9 +82,9 @@ public final class FaceLivenessSession: LivenessService { let encodedPayload = eventStreamEncoder.encode( payload: event.payload, headers: [ - ":content-type": .string("application/json"), + ":content-type": .string("application/json"), ":event-type": .string(event.eventTypeHeader), - ":message-type": .string("event") + ":message-type": .string("event") ] ) @@ -105,7 +105,7 @@ public final class FaceLivenessSession: LivenessService { websocket.send( message: .data(encodedEvent), - onError: { error in } + onError: { _ in } ) } diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSessionRepresentable.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSessionRepresentable.swift index 4f502d8c22..92001bc980 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSessionRepresentable.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Liveness/Service/FaceLivenessSessionRepresentable.swift @@ -28,4 +28,3 @@ public protocol LivenessService { func closeSocket(with code: URLSessionWebSocketTask.CloseCode) } - diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/MultiService/IdentifyMultiService.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/MultiService/IdentifyMultiService.swift index 2829b2ec4d..1d15c1cb1a 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/MultiService/IdentifyMultiService.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/MultiService/IdentifyMultiService.swift @@ -66,8 +66,6 @@ class IdentifyMultiService { } } - - func offlineResult() async throws -> Output { guard let offlineService = coreMLService else { throw PredictionsError.client(.offlineIdentityServiceUnavailable) @@ -170,7 +168,6 @@ class IdentifyMultiService { } } - extension Predictions.Label: Hashable { public static func == (lhs: Predictions.Label, rhs: Predictions.Label) -> Bool { return lhs.name.lowercased() == rhs.name.lowercased() diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Rekognition.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Rekognition.swift index 623eec344f..cdfe6e5fdc 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Rekognition.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Service/Predictions/AWSPredictionsService+Rekognition.swift @@ -15,7 +15,7 @@ extension AWSPredictionsService: AWSRekognitionServiceBehavior { func detectLabels( image: URL, type: Predictions.LabelType - ) async throws -> Predictions.Identify.Labels.Result { + ) async throws -> Predictions.Identify.Labels.Result { let imageData = try dataFromImage(url: image) switch type { @@ -37,8 +37,7 @@ extension AWSPredictionsService: AWSRekognitionServiceBehavior { return Predictions.Identify.Labels.Result(labels: labels, unsafeContent: unsafeContent) } catch let error as PredictionsErrorConvertible { throw error.predictionsError - } - catch { + } catch { throw PredictionsError.unexpectedServiceErrorType(error) } @@ -119,7 +118,6 @@ extension AWSPredictionsService: AWSRekognitionServiceBehavior { } } - func detectPlainText(image: URL) async throws -> Predictions.Identify.Text.Result { let imageData = try dataFromImage(url: image) let rekognitionImage = RekognitionClientTypes.Image(bytes: imageData) diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PayloadSigning.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PayloadSigning.swift index 082b851a14..2f88467b0b 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PayloadSigning.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PayloadSigning.swift @@ -47,6 +47,8 @@ extension SigV4Signer { return Data(signature) } + // swiftlint:disable identifier_name + // Generate a StringToSign for a AWS4-HMAC-SHA256-PAYLOAD // type request, which includes the previous signature. func _stringToSignWithPreviousSignature( @@ -86,4 +88,5 @@ extension SigV4Signer { data.append(contentsOf: headerValueBytes) return data } + // swiftlint:enable identifier_name } diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PercentEncoding.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PercentEncoding.swift index 875b3a222c..ed372b6cfe 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PercentEncoding.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer+PercentEncoding.swift @@ -17,18 +17,18 @@ extension SigV4Signer { } static let query = PercentEncoding( - allowedCharacters: CharacterSet(charactersIn:"/;+").inverted + allowedCharacters: CharacterSet(charactersIn: "/;+").inverted ) static let uri = PercentEncoding( allowedCharacters: CharacterSet( - charactersIn:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" + charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" ) ) static let uriWithSlash = PercentEncoding( allowedCharacters: CharacterSet( - charactersIn:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~/" + charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~/" ) ) } diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer.swift index 22dc2c2f0f..a78970295d 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Signing/SigV4Signer.swift @@ -123,6 +123,8 @@ struct SigV4Signer { // e.g. "us-east-1" let region: String + // swiftlint:disable identifier_name + // Reference type storage that holds the // previous signature (if it exists) to use // in subsequent signing requests as needed. @@ -397,3 +399,4 @@ struct SigV4Signer { return hash } } +// swiftlint:enable identifier_name diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/Data+Bytes.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/Data+Bytes.swift index cd2207d36b..4cefc07a09 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/Data+Bytes.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/Data+Bytes.swift @@ -30,7 +30,6 @@ extension Data { return first } - /// Retrieves and removes `n` bytes of `Data`, where `n` = `count` argument /// /// `Data` self-slices, meaning `Data.SubSequence == Data` [[reference](https://developer.apple.com/documentation/foundation/data/subsequence)] diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Decoder.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Decoder.swift index 4e8a604b0d..c9b05f6034 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Decoder.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Decoder.swift @@ -78,7 +78,6 @@ extension EventStream { return message } - private func headers(from data: Data) throws -> [Header] { // Create a mutable slice of the entire (`UnboundedRange_`) // data provided for decoding. @@ -92,7 +91,7 @@ extension EventStream { // If the data is malformed, we'll hit an error // in one of the decoding processes. Therefore // there's no risk of an infinite while loop here. - while data.count > 0 { + while !data.isEmpty { // Despite this being a single byte (UInt8), we're converted it // to an Int to prevent the need for multiple transformations. // It's data representation is unimportant for the decoding @@ -167,7 +166,6 @@ fileprivate extension Data { } } - /** Time Profiling diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Header.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Header.swift index f6fec1c62d..ddebc86c73 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Header.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Header.swift @@ -66,6 +66,3 @@ extension EventStream.Header { case uuid = 9 } } - - - diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Message.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Message.swift index 3d25063397..17367e5f02 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Message.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Streaming/EventStream+Message.swift @@ -61,5 +61,3 @@ extension EventStream { let messageCRC: Int32 } } - - diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Polly+PredictionsErrorConvertible.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Polly+PredictionsErrorConvertible.swift index 78796e95ce..dd3d6f8087 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Polly+PredictionsErrorConvertible.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Polly+PredictionsErrorConvertible.swift @@ -34,12 +34,21 @@ extension AWSPolly.TextLengthExceededException: PredictionsErrorConvertible { extension AWSPolly.LexiconNotFoundException: PredictionsErrorConvertible { var predictionsError: PredictionsError { - .service( - .init( - description: "Amazon Polly can't find the specified lexicon. This could be caused by a lexicon that is missing, its name is misspelled or specifying a lexicon that is in a different region.", - recoverySuggestion: "Verify that the lexicon exists, is in the region (see ListLexicons) and that you spelled its name is spelled correctly. Then try again.", - underlyingError: self - ) + let description = """ + Amazon Polly can't find the specified lexicon. + This could be caused by a lexicon that is missing, + its name is misspelled or specifying a lexicon that is in a different region. + """ + let recoverySuggestion = """ + Verify that the lexicon exists, is in the region (see ListLexicons) and + that you spelled its name is spelled correctly. Then try again. + """ + return .service( + .init( + description: description, + recoverySuggestion: recoverySuggestion, + underlyingError: self + ) ) } } diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Rekognition+PredictionsErrorConvertible.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Rekognition+PredictionsErrorConvertible.swift index 464060e9da..0afa93d4fa 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Rekognition+PredictionsErrorConvertible.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Rekognition+PredictionsErrorConvertible.swift @@ -9,7 +9,6 @@ import AWSRekognition import Amplify import ClientRuntime - extension AWSRekognition.HumanLoopQuotaExceededException: PredictionsErrorConvertible { var predictionsError: PredictionsError { .service( diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Textract+PredictionsErrorConvertible.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Textract+PredictionsErrorConvertible.swift index 9aa5908460..f6e0a56e8e 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Textract+PredictionsErrorConvertible.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Textract+PredictionsErrorConvertible.swift @@ -9,7 +9,6 @@ import AWSTextract import Amplify import ClientRuntime - extension AWSTextract.HumanLoopQuotaExceededException: PredictionsErrorConvertible { var predictionsError: PredictionsError { .service( @@ -88,7 +87,6 @@ extension AWSTextract.ProvisionedThroughputExceededException: PredictionsErrorCo } } - extension AWSTextract.BadDocumentException: PredictionsErrorConvertible { var predictionsError: PredictionsError { .service( @@ -115,7 +113,6 @@ extension AWSTextract.DocumentTooLargeException: PredictionsErrorConvertible { } } - extension AWSTextract.UnsupportedDocumentException: PredictionsErrorConvertible { var predictionsError: PredictionsError { .service( diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Translate+PredictionsErrorConvertible.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Translate+PredictionsErrorConvertible.swift index aeb5897aac..d24f73510c 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Translate+PredictionsErrorConvertible.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/ErrorHandling/Translate+PredictionsErrorConvertible.swift @@ -20,7 +20,6 @@ extension AWSTranslate.InternalServerException: PredictionsErrorConvertible { } } - extension AWSTranslate.InvalidRequestException: PredictionsErrorConvertible { var predictionsError: PredictionsError { .service(.invalidRequest) diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/LanguageTypeExtension.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/LanguageTypeExtension.swift index bb4934cbf8..6623c089fc 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/LanguageTypeExtension.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Internal/LanguageTypeExtension.swift @@ -49,7 +49,6 @@ extension Predictions.Language { } } - func toTranscribeLanguage() -> TranscribeStreamingClientTypes.LanguageCode { switch self { case .usEnglish, diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyLabelsResultTransformers.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyLabelsResultTransformers.swift index 48daa66579..451f3d56d0 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyLabelsResultTransformers.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyLabelsResultTransformers.swift @@ -9,7 +9,7 @@ import Foundation import AWSRekognition import Amplify -enum IdentifyLabelsResultTransformers { +enum IdentifyLabelsResultTransformers { static func processLabels( _ rekognitionLabels: [RekognitionClientTypes.Label] ) -> [Predictions.Label] { diff --git a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyTextResultTransformers.swift b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyTextResultTransformers.swift index d86e661b98..3b0f5a1824 100644 --- a/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyTextResultTransformers.swift +++ b/AmplifyPlugins/Predictions/AWSPredictionsPlugin/Support/Utils/IdentifyTextResultTransformers.swift @@ -26,7 +26,7 @@ enum IdentifyTextResultTransformers { guard let polygon = IdentifyResultTransformers.processPolygon(rekognitionTextBlock.geometry?.polygon) else { continue } - + let word = Predictions.IdentifiedWord( text: detectedText, boundingBox: boundingBox, diff --git a/AmplifyPlugins/Predictions/CoreMLPredictionsPlugin/Dependency/CoreMLSpeechAdapter.swift b/AmplifyPlugins/Predictions/CoreMLPredictionsPlugin/Dependency/CoreMLSpeechAdapter.swift index 1a07dea6a2..218da5d860 100644 --- a/AmplifyPlugins/Predictions/CoreMLPredictionsPlugin/Dependency/CoreMLSpeechAdapter.swift +++ b/AmplifyPlugins/Predictions/CoreMLPredictionsPlugin/Dependency/CoreMLSpeechAdapter.swift @@ -43,7 +43,6 @@ class CoreMLSpeechAdapter: CoreMLSpeechBehavior { return } - continuation.resume(with: .success(result)) } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+AsyncClientBehavior.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+AsyncClientBehavior.swift index 0bd830c3d9..80167b691d 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+AsyncClientBehavior.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/AWSS3StoragePlugin+AsyncClientBehavior.swift @@ -58,7 +58,7 @@ extension AWSS3StoragePlugin { authService: authService) let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation) queue.addOperation(operation) - + return taskAdapter } @@ -94,7 +94,7 @@ extension AWSS3StoragePlugin { authService: authService) let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation) queue.addOperation(operation) - + return taskAdapter } @@ -112,7 +112,7 @@ extension AWSS3StoragePlugin { authService: authService) let taskAdapter = AmplifyInProcessReportingOperationTaskAdapter(operation: operation) queue.addOperation(operation) - + return taskAdapter } @@ -129,7 +129,7 @@ extension AWSS3StoragePlugin { authService: authService) let taskAdapter = AmplifyOperationTaskAdapter(operation: operation) queue.addOperation(operation) - + return try await taskAdapter.value } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Configuration/AWSS3PluginOptions.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Configuration/AWSS3PluginOptions.swift index fcec7bc47e..dcbd174b70 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Configuration/AWSS3PluginOptions.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Configuration/AWSS3PluginOptions.swift @@ -13,7 +13,7 @@ struct AWSS3PluginOptions { /// - Tag: AWSS3PluginOptionsCodingKeys enum CodingKeys: String, CodingKey { - + /// See: https://docs.amplify.aws/lib/storage/transfer-acceleration/q/platform/js/ /// - Tag: AWSS3PluginOptionsCodingKeys.useAccelerateEndpoint case useAccelerateEndpoint @@ -30,7 +30,7 @@ struct AWSS3PluginOptions { /// /// - Tag: AWSS3PluginOptions.accelerateValue static func accelerateValue(pluginOptions: Any?) throws -> Bool? { - guard let pluginOptions = pluginOptions as? [String:Any] else { + guard let pluginOptions = pluginOptions as? [String: Any] else { return nil } guard let value = pluginOptions[CodingKeys.useAccelerateEndpoint.rawValue] else { diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3AbortMultipartUploadRequest.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3AbortMultipartUploadRequest.swift index a4437d9077..c0e30a5388 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3AbortMultipartUploadRequest.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3AbortMultipartUploadRequest.swift @@ -11,12 +11,4 @@ struct AWSS3AbortMultipartUploadRequest { let bucket: String let key: String let uploadId: String - - init(bucket: String, - key: String, - uploadId: String) { - self.bucket = bucket - self.key = key - self.uploadId = uploadId - } } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3Adapter.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3Adapter.swift index 5fd65c6ec0..5d8f64e0e1 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3Adapter.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3Adapter.swift @@ -129,7 +129,12 @@ class AWSS3Adapter: AWSS3Behavior { S3ClientTypes.CompletedPart(eTag: $0.eTag, partNumber: $0.partNumber) } let completedMultipartUpload = S3ClientTypes.CompletedMultipartUpload(parts: parts) - let input = CompleteMultipartUploadInput(bucket: request.bucket, key: request.key, multipartUpload: completedMultipartUpload, uploadId: request.uploadId) + let input = CompleteMultipartUploadInput( + bucket: request.bucket, + key: request.key, + multipartUpload: completedMultipartUpload, + uploadId: request.uploadId + ) do { let response = try await awsS3.completeMultipartUpload(input: input) guard let eTag = response.eTag else { diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadRequest.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadRequest.swift index ae94d61936..3b1478b29a 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadRequest.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadRequest.swift @@ -14,14 +14,4 @@ struct AWSS3CompleteMultipartUploadRequest { let key: String let uploadId: String let parts: [AWSS3MultipartUploadRequestCompletedPart] - - init(bucket: String, - key: String, - uploadId: String, - parts: [AWSS3MultipartUploadRequestCompletedPart]) { - self.bucket = bucket - self.key = key - self.uploadId = uploadId - self.parts = parts - } } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadResponse.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadResponse.swift index 26c3545fd7..3fc5f654ac 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadResponse.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CompleteMultipartUploadResponse.swift @@ -11,10 +11,4 @@ struct AWSS3CompleteMultipartUploadResponse { let bucket: String let key: String let eTag: String - - init(bucket: String, key: String, eTag: String) { - self.bucket = bucket - self.key = key - self.eTag = eTag - } } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CreateMultipartUploadResponse.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CreateMultipartUploadResponse.swift index f9e0395dfb..b8303ed09d 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CreateMultipartUploadResponse.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3CreateMultipartUploadResponse.swift @@ -11,10 +11,4 @@ struct AWSS3CreateMultipartUploadResponse { let bucket: String let key: String let uploadId: String - - init(bucket: String, key: String, uploadId: String) { - self.bucket = bucket - self.key = key - self.uploadId = uploadId - } } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3DeleteObjectRequest.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3DeleteObjectRequest.swift index d466fca0b4..52ae9ca0cd 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3DeleteObjectRequest.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3DeleteObjectRequest.swift @@ -10,9 +10,4 @@ import Foundation struct AWSS3DeleteObjectRequest { let bucket: String let key: String - - init(bucket: String, key: String) { - self.bucket = bucket - self.key = key - } } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3ListUploadPartResponse.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3ListUploadPartResponse.swift index 7298cf3102..67c282e887 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3ListUploadPartResponse.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3ListUploadPartResponse.swift @@ -15,16 +15,6 @@ struct AWSS3ListUploadPartResponse { let key: String let uploadId: String let parts: AWSS3MultipartUploadRequestCompletedParts - - init(bucket: String, - key: String, - uploadId: String, - parts: AWSS3MultipartUploadRequestCompletedParts) { - self.bucket = bucket - self.key = key - self.uploadId = uploadId - self.parts = parts - } } extension AWSS3ListUploadPartResponse { diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3MultipartUploadRequestCompletedPart.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3MultipartUploadRequestCompletedPart.swift index e636eaa92b..e6b5ca4145 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3MultipartUploadRequestCompletedPart.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/AWSS3MultipartUploadRequestCompletedPart.swift @@ -12,11 +12,6 @@ import AWSS3 struct AWSS3MultipartUploadRequestCompletedPart { let partNumber: Int let eTag: String - - init(partNumber: Int, eTag: String) { - self.partNumber = partNumber - self.eTag = eTag - } } typealias AWSS3MultipartUploadRequestCompletedParts = [AWSS3MultipartUploadRequestCompletedPart] diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift index 19ab5c7b9c..29bc2ace4e 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Dependency/UploadPartInput+presignURL.swift @@ -13,7 +13,13 @@ enum UploadPartOutputError: ClientRuntime.HttpResponseErrorBinding { static func makeError(httpResponse: ClientRuntime.HttpResponse, decoder: ClientRuntime.ResponseDecoder? = nil) async throws -> Swift.Error { let restXMLError = try await AWSClientRuntime.RestXMLError.makeError(from: httpResponse) switch restXMLError.errorCode { - default: return try await AWSClientRuntime.UnknownAWSHTTPServiceError.makeError(httpResponse: httpResponse, message: restXMLError.message, requestID: restXMLError.requestId, requestID2: httpResponse.requestId2, typeName: restXMLError.errorCode) + default: return try await AWSClientRuntime.UnknownAWSHTTPServiceError.makeError( + httpResponse: httpResponse, + message: restXMLError.message, + requestID: restXMLError.requestId, + requestID2: httpResponse.requestId2, + typeName: restXMLError.errorCode + ) } } } @@ -41,12 +47,26 @@ extension UploadPartInput { .withSigningName(value: "s3") .withSigningRegion(value: config.signingRegion) var operation = ClientRuntime.OperationStack(id: "uploadPart") - operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware()) + operation.initializeStep.intercept( + position: .after, + middleware: ClientRuntime.URLPathMiddleware() + ) operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware()) - operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: config.endpointParams(withBucket: input.bucket))) + operation.buildStep.intercept( + position: .before, + middleware: EndpointResolverMiddleware( + endpointResolver: config.serviceSpecific.endpointResolver, + endpointParams: config.endpointParams(withBucket: input.bucket) + ) + ) operation.serializeStep.intercept(position: .after, middleware: UploadPartInputBodyMiddleware()) operation.serializeStep.intercept(position: .after, middleware: QueryItemMiddleware()) - operation.finalizeStep.intercept(position: .after, middleware: ClientRuntime.RetryMiddleware(options: config.retryStrategyOptions)) + operation.finalizeStep.intercept( + position: .after, + middleware: ClientRuntime.RetryMiddleware( + options: config.retryStrategyOptions + ) + ) let sigv4Config = AWSClientRuntime.SigV4Config( signatureType: .requestQueryParams, useDoubleURIEncode: false, @@ -54,8 +74,13 @@ extension UploadPartInput { unsignedBody: true, signingAlgorithm: .sigv4 ) - operation.finalizeStep.intercept(position: .before, middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config)) - operation.deserializeStep.intercept(position: .before, middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) + operation.finalizeStep.intercept( + position: .before, + middleware: AWSClientRuntime.SigV4Middleware(config: sigv4Config) + ) + operation.deserializeStep.intercept( + position: .before, + middleware: ClientRuntime.LoggerMiddleware(clientLogMode: config.clientLogMode)) operation.deserializeStep.intercept(position: .after, middleware: ClientRuntime.DeserializeMiddleware()) let presignedRequestBuilder = try await operation.presignedRequest(context: context.build(), input: input, next: ClientRuntime.NoopHandler()) guard let builtRequest = presignedRequestBuilder?.build(), let presignedURL = builtRequest.endpoint.url else { diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Operation/AWSS3StorageRemoveOperation.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Operation/AWSS3StorageRemoveOperation.swift index 5dc1d28914..12602853f3 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Operation/AWSS3StorageRemoveOperation.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Operation/AWSS3StorageRemoveOperation.swift @@ -39,11 +39,6 @@ class AWSS3StorageRemoveOperation: AmplifyOperation< resultListener: resultListener) } - /// Cancels operation. - override public func cancel() { - super.cancel() - } - /// Perform the task to remove item. override public func main() { if isCancelled { diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService.swift index d31b9e588e..14dd8aca32 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Service/Storage/AWSS3StorageService.swift @@ -78,9 +78,9 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy { let awsS3 = AWSS3Adapter(s3Client, config: clientConfig) let preSignedURLBuilder = AWSS3PreSignedURLBuilderAdapter(config: clientConfig, bucket: bucket) - var _sessionConfiguration: URLSessionConfiguration + var sessionConfig: URLSessionConfiguration if let sessionConfiguration = sessionConfiguration { - _sessionConfiguration = sessionConfiguration + sessionConfig = sessionConfiguration } else { #if os(macOS) let sessionConfiguration = URLSessionConfiguration.default @@ -90,16 +90,16 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy { sessionConfiguration.urlCache = nil sessionConfiguration.allowsCellularAccess = storageConfiguration.allowsCellularAccess sessionConfiguration.timeoutIntervalForResource = TimeInterval(storageConfiguration.timeoutIntervalForResource) - _sessionConfiguration = sessionConfiguration + sessionConfig = sessionConfiguration } - _sessionConfiguration.sharedContainerIdentifier = storageConfiguration.sharedContainerIdentifier + sessionConfig.sharedContainerIdentifier = storageConfiguration.sharedContainerIdentifier self.init(authService: authService, storageConfiguration: storageConfiguration, storageTransferDatabase: storageTransferDatabase, fileSystem: fileSystem, - sessionConfiguration: _sessionConfiguration, + sessionConfiguration: sessionConfig, logger: logger, s3Client: s3Client, preSignedURLBuilder: preSignedURLBuilder, @@ -185,7 +185,12 @@ class AWSS3StorageService: AWSS3StorageServiceBehavior, StorageServiceProxy { bucket: pair.transferTask.bucket, key: pair.transferTask.key, uploadFile: uploadFile) - guard let session = StorageMultipartUploadSession(client: client, transferTask: pair.transferTask, multipartUpload: multipartUpload, logger: logger) else { + guard let session = StorageMultipartUploadSession( + client: client, + transferTask: pair.transferTask, + multipartUpload: multipartUpload, + logger: logger + ) else { return } session.restart() diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadClient.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadClient.swift index 7884e13482..d189d1d5d9 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadClient.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadClient.swift @@ -43,7 +43,7 @@ class DefaultStorageMultipartUploadClient: StorageMultipartUploadClient { let requestHeaders: RequestHeaders? weak var session: StorageMultipartUploadSession? let metadata: [String: String]? - + init(serviceProxy: StorageServiceProxy, fileSystem: FileSystem = .default, bucket: String, diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift index fc51016cb9..de59ecc9bb 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageMultipartUploadSession.swift @@ -267,8 +267,7 @@ class StorageMultipartUploadSession { if case .failed = multipartUpload { logger.debug("Multipart Upload is failed and event cannot be handled: \(uploadPartEvent)") return - } - else if case .paused = multipartUpload { + } else if case .paused = multipartUpload { logger.debug("Multipart Upload is paused and event cannot be handled: \(uploadPartEvent)") return } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift index 760940dfc7..1b83d5e17f 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/StorageServiceSessionDelegate.swift @@ -133,7 +133,12 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate { guard let eTag = task.eTag else { let message = "Completed upload part does not include header value for ETAG: [\(partNumber), \(uploadId)]" logURLSessionActivity(message, warning: true) - multipartUploadSession.handle(uploadPartEvent: .failed(partNumber: partNumber, error: StorageError.unknown("Upload for part number does not include value for eTag", nil))) + multipartUploadSession.handle( + uploadPartEvent: .failed( + partNumber: partNumber, + error: StorageError.unknown("Upload for part number does not include value for eTag", nil) + ) + ) return } @@ -153,7 +158,11 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate { } func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) { - logURLSessionActivity("Session task update: [bytesSent: \(bytesSent)], [totalBytesSent: \(totalBytesSent)], [totalBytesExpectedToSend: \(totalBytesExpectedToSend)]") + logURLSessionActivity( + """ + Session task update: [bytesSent: \(bytesSent)], [totalBytesSent: \(totalBytesSent)], [totalBytesExpectedToSend: \(totalBytesExpectedToSend)] + """ + ) guard let storageService = storageService, let transferTask = findTransferTask(for: task.taskIdentifier) else { return } @@ -165,7 +174,13 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate { return } - multipartUploadSession.handle(uploadPartEvent: .progressUpdated(partNumber: partNumber, bytesTransferred: UInt64(bytesSent), taskIdentifier: task.taskIdentifier)) + multipartUploadSession.handle( + uploadPartEvent: .progressUpdated( + partNumber: partNumber, + bytesTransferred: UInt64(bytesSent), + taskIdentifier: task.taskIdentifier + ) + ) case .upload(let onEvent): let progress = Progress(totalUnitCount: totalBytesExpectedToSend) progress.completedUnitCount = totalBytesSent @@ -183,7 +198,12 @@ extension StorageServiceSessionDelegate: URLSessionTaskDelegate { extension StorageServiceSessionDelegate: URLSessionDownloadDelegate { func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) { - logURLSessionActivity("Session download task [\(downloadTask.taskIdentifier)] did write [\(bytesWritten)], [totalBytesWritten \(totalBytesWritten)], [totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)]") + logURLSessionActivity( + """ + Session download task [\(downloadTask.taskIdentifier)] did write [\(bytesWritten)], + [totalBytesWritten \(totalBytesWritten)], [totalBytesExpectedToWrite: \(totalBytesExpectedToWrite)] + """ + ) guard let transferTask = findTransferTask(for: downloadTask.taskIdentifier) else { return } diff --git a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/UploadFile.swift b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/UploadFile.swift index 457c714053..2cb245201c 100644 --- a/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/UploadFile.swift +++ b/AmplifyPlugins/Storage/Sources/AWSS3StoragePlugin/Support/Internal/UploadFile.swift @@ -11,10 +11,4 @@ struct UploadFile { let fileURL: URL let temporaryFileCreated: Bool let size: UInt64 - - init(fileURL: URL, temporaryFileCreated: Bool, size: UInt64) { - self.fileURL = fileURL - self.temporaryFileCreated = temporaryFileCreated - self.size = size - } } diff --git a/AmplifySwiftXcode/AmplifySwiftXcode.xcodeproj/project.pbxproj b/AmplifySwiftXcode/AmplifySwiftXcode.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..e6758ea6a5 --- /dev/null +++ b/AmplifySwiftXcode/AmplifySwiftXcode.xcodeproj/project.pbxproj @@ -0,0 +1,365 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXFileReference section */ + 7383B19E2B471BF900EF62D0 /* AmplifySwiftXcode.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AmplifySwiftXcode.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 7383B1A82B471C1D00EF62D0 /* amplify-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "amplify-swift"; path = ..; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 7383B19B2B471BF900EF62D0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7383B1942B471BF900EF62D0 = { + isa = PBXGroup; + children = ( + 7383B1A82B471C1D00EF62D0 /* amplify-swift */, + 7383B19F2B471BF900EF62D0 /* Products */, + ); + sourceTree = ""; + }; + 7383B19F2B471BF900EF62D0 /* Products */ = { + isa = PBXGroup; + children = ( + 7383B19E2B471BF900EF62D0 /* AmplifySwiftXcode.framework */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 7383B1992B471BF900EF62D0 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 7383B19D2B471BF900EF62D0 /* AmplifySwiftXcode */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7383B1A52B471BF900EF62D0 /* Build configuration list for PBXNativeTarget "AmplifySwiftXcode" */; + buildPhases = ( + 7383B1992B471BF900EF62D0 /* Headers */, + 7383B19A2B471BF900EF62D0 /* Sources */, + 7383B19B2B471BF900EF62D0 /* Frameworks */, + 7383B19C2B471BF900EF62D0 /* Resources */, + 733C6C2D2B471D63001939F8 /* Run SwiftLint */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AmplifySwiftXcode; + productName = AmplifySwiftXcode; + productReference = 7383B19E2B471BF900EF62D0 /* AmplifySwiftXcode.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 7383B1952B471BF900EF62D0 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastUpgradeCheck = 1500; + TargetAttributes = { + 7383B19D2B471BF900EF62D0 = { + CreatedOnToolsVersion = 15.0; + }; + }; + }; + buildConfigurationList = 7383B1982B471BF900EF62D0 /* Build configuration list for PBXProject "AmplifySwiftXcode" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 7383B1942B471BF900EF62D0; + productRefGroup = 7383B19F2B471BF900EF62D0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 7383B19D2B471BF900EF62D0 /* AmplifySwiftXcode */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 7383B19C2B471BF900EF62D0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 733C6C2D2B471D63001939F8 /* Run SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Run SwiftLint"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n cd .. \n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 7383B19A2B471BF900EF62D0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 7383B1A32B471BF900EF62D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 7383B1A42B471BF900EF62D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 7383B1A62B471BF900EF62D0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 13.6; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.aws.amplify.AmplifySwiftXcode; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 7383B1A72B471BF900EF62D0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_MODULE_VERIFIER = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 17.0; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 13.6; + MARKETING_VERSION = 1.0; + MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; + MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20"; + PRODUCT_BUNDLE_IDENTIFIER = com.aws.amplify.AmplifySwiftXcode; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 7383B1982B471BF900EF62D0 /* Build configuration list for PBXProject "AmplifySwiftXcode" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7383B1A32B471BF900EF62D0 /* Debug */, + 7383B1A42B471BF900EF62D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7383B1A52B471BF900EF62D0 /* Build configuration list for PBXNativeTarget "AmplifySwiftXcode" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7383B1A62B471BF900EF62D0 /* Debug */, + 7383B1A72B471BF900EF62D0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 7383B1952B471BF900EF62D0 /* Project object */; +} diff --git a/AmplifyTests/CategoryTests/Storage/StorageCategoryConfigurationTests.swift b/AmplifyTests/CategoryTests/Storage/StorageCategoryConfigurationTests.swift index f653699f38..cccf40b9a1 100644 --- a/AmplifyTests/CategoryTests/Storage/StorageCategoryConfigurationTests.swift +++ b/AmplifyTests/CategoryTests/Storage/StorageCategoryConfigurationTests.swift @@ -157,7 +157,7 @@ class StorageCategoryConfigurationTests: XCTestCase { _ = try Amplify.Storage.getPlugin(for: "MockSecondStorageCategoryPlugin") .downloadData(key: "", options: nil) - await fulfillment(of: [methodShouldNotBeInvokedOnDefaultPlugin, methodShouldBeInvokedOnSecondPlugin]) + await fulfillment(of: [methodShouldNotBeInvokedOnDefaultPlugin, methodShouldBeInvokedOnSecondPlugin], timeout: 10) } func testPreconditionFailureInvokingWithMultiplePlugins() async throws { diff --git a/README.md b/README.md index 68e101a6ce..129adead7b 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ Amplify requires Xcode 14.1 or higher to build for iOS and macOS. Building for w ```swift import Amplify - import AWSCongitoAuthPlugin + import AWSCognitoAuthPlugin import AWSAPIPlugin import AWSDataStorePlugin @@ -99,9 +99,9 @@ Amplify requires Xcode 14.1 or higher to build for iOS and macOS. Building for w func initializeAmplify() { do { - try Amplify.add(AWSCognitoAuthPlugin()) - try Amplify.add(AWSAPIPlugin()) - try Amplify.add(AWSDataStorePlugin()) + try Amplify.add(plugin: AWSCognitoAuthPlugin()) + try Amplify.add(plugin: AWSAPIPlugin()) + try Amplify.add(plugin: AWSDataStorePlugin()) // and so on ... try Amplify.configure() } catch {