Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: resolving swift formatting errors #3906

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
29 changes: 17 additions & 12 deletions Amplify/Amplify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ public class Amplify {
// ease of testing.

/// - Tag: Amplify.Analytics
public static internal(set) var Analytics = AnalyticsCategory()
public internal(set) static var Analytics = AnalyticsCategory()

/// - Tag: Amplify.API
public static internal(set) var API: APICategory = APICategory()
public internal(set) static var API = APICategory()

/// - Tag: Amplify.Auth
public static internal(set) var Auth = AuthCategory()
public internal(set) static var Auth = AuthCategory()

/// - Tag: Amplify.DataStore
public static internal(set) var DataStore = DataStoreCategory()
public internal(set) static var DataStore = DataStoreCategory()

/// - Tag: Amplify.Geo
public static internal(set) var Geo = GeoCategory()
public internal(set) static var Geo = GeoCategory()

/// - Tag: Amplify.Hub
public static internal(set) var Hub = HubCategory()
public internal(set) static var Hub = HubCategory()

/// - Tag: Amplify.Notifications
public static internal(set) var Notifications = NotificationsCategory()
public internal(set) static var Notifications = NotificationsCategory()

/// - Tag: Amplify.Predictions
public static internal(set) var Predictions = PredictionsCategory()
public internal(set) static var Predictions = PredictionsCategory()

/// - Tag: Amplify.Storage
public static internal(set) var Storage = StorageCategory()
public internal(set) static var Storage = StorageCategory()

/// Special case category. We protect this with an AtomicValue because it is used by reset()
/// methods during setup & teardown of tests
///
/// - Tag: Amplify.Logging
public static internal(set) var Logging: LoggingCategory {
public internal(set) static var Logging: LoggingCategory {
get {
loggingAtomic.get()
}
Expand All @@ -73,13 +73,15 @@ public class Amplify {
}
private static let loggingAtomic = AtomicValue<LoggingCategory>(initialValue: LoggingCategory())

// swiftlint:disable cyclomatic_complexity

/// Adds `plugin` to the category
///
/// See: [Category.removePlugin(for:)](x-source-tag://Category.removePlugin)
///
/// - Parameter plugin: The plugin to add
/// - Tag: Amplify.add_plugin
public static func add<P: Plugin>(plugin: P) throws {
public static func add(plugin: some Plugin) throws {
log.debug("Adding plugin: \(plugin))")
switch plugin {
case let plugin as AnalyticsCategoryPlugin:
Expand All @@ -105,8 +107,11 @@ public class Amplify {
default:
throw PluginError.pluginConfigurationError(
"Plugin category does not exist.",
"Verify that the library version is correct and supports the plugin's category.")
"Verify that the library version is correct and supports the plugin's category."
)
}

// swiftlint:enable cyclomatic_complexity
}
}

Expand Down
14 changes: 9 additions & 5 deletions Amplify/Categories/API/APICategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

/// The API category provides a solution for making HTTP requests to REST and GraphQL endpoints.
final public class APICategory: Category {
public final class APICategory: Category {
/// The category type for API
public var categoryType: CategoryType {
.api
Expand Down Expand Up @@ -57,8 +57,10 @@ final public class APICategory: Category {
let key = plugin.key
guard !key.isEmpty else {
let pluginDescription = String(describing: plugin)
let error = APIError.invalidConfiguration("Plugin \(pluginDescription) has an empty `key`.",
"Set the `key` property for \(String(describing: plugin))")
let error = APIError.invalidConfiguration(
"Plugin \(pluginDescription) has an empty `key`.",
"Set the `key` property for \(String(describing: plugin))"
)
throw error
}

Expand All @@ -81,8 +83,10 @@ final public class APICategory: Category {
public func getPlugin(for key: PluginKey) throws -> APICategoryPlugin {
guard let plugin = plugins[key] else {
let keys = plugins.keys.joined(separator: ", ")
let error = APIError.invalidConfiguration("No plugin has been added for '\(key)'.",
"Either add a plugin for '\(key)', or use one of the known keys: \(keys)")
let error = APIError.invalidConfiguration(
"No plugin has been added for '\(key)'.",
"Either add a plugin for '\(key)', or use one of the known keys: \(keys)"
)
throw error
}
return plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

#if canImport(Combine)
import Foundation
import Combine
import Foundation

extension APICategory: APICategoryReachabilityBehavior {
#if !os(watchOS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

/// Behavior of the API category that clients will use
public typealias APICategoryBehavior =
APICategoryRESTBehavior &
APICategoryAuthProviderFactoryBehavior &
APICategoryGraphQLBehavior &
APICategoryInterceptorBehavior &
APICategoryReachabilityBehavior &
APICategoryAuthProviderFactoryBehavior
APICategoryRESTBehavior &
APICategoryReachabilityBehavior
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public protocol APICategoryGraphQLBehavior: AnyObject {
/// - request: The GraphQL request containing apiName, document, variables, and responseType
/// - 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
/// - Returns: The AmplifyInProcessReportingOperation being enqueued
func subscribe<R: Decodable>(
request: GraphQLRequest<R>
) -> AmplifyAsyncThrowingSequence<GraphQLSubscriptionEvent<R>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

#if canImport(Combine)
import Foundation
import Combine
import Foundation

/// API Reachability Behavior
public protocol APICategoryReachabilityBehavior {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

#if canImport(Combine)
import Foundation
import Combine
import Foundation

// MARK: - GraphQLSubscriptionOperation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//


import Combine

/**
A non-deterministic operation offers multiple paths to accomplish its task.
It attempts the next path if all preceding paths have failed with an error that allows for continuation.
Expand Down Expand Up @@ -62,7 +62,7 @@ final class NondeterminsticOperation<T> {
self?.task = Task { [weak self] in
do {
if let self {
promise(.success(try await self.run()))
try await promise(.success(run()))
} else {
promise(.failure(NondeterminsticOperationError.cancelled))
}
Expand Down
24 changes: 12 additions & 12 deletions Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Combine
import Foundation


Check warning on line 11 in Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
// MARK: - RetryableGraphQLOperation
public final class RetryableGraphQLOperation<Payload: Decodable> {
public typealias Payload = Payload
Expand All @@ -16,7 +16,7 @@
private let nondeterminsticOperation: NondeterminsticOperation<GraphQLTask<Payload>.Success>

public init(
requestStream: AsyncStream<() async throws -> GraphQLTask<Payload>.Success>
requestStream: AsyncStream < () async throws -> GraphQLTask<Payload>.Success>
) {
self.nondeterminsticOperation = NondeterminsticOperation(
operations: requestStream,
Expand Down Expand Up @@ -80,7 +80,7 @@
private let nondeterminsticOperation: NondeterminsticOperation<AmplifyAsyncThrowingSequence<SubscriptionEvents>>

public init(
requestStream: AsyncStream<() async throws -> AmplifyAsyncThrowingSequence<SubscriptionEvents>>
requestStream: AsyncStream < () async throws -> AmplifyAsyncThrowingSequence < SubscriptionEvents>>
) {
self.nondeterminsticOperation = NondeterminsticOperation(operations: requestStream)
}
Expand All @@ -91,15 +91,15 @@

public func subscribe() -> AnyPublisher<SubscriptionEvents, APIError> {
let subject = PassthroughSubject<SubscriptionEvents, APIError>()
self.task = Task { await self.trySubscribe(subject) }
task = Task { await self.trySubscribe(subject) }
return subject.eraseToAnyPublisher()
}

private func trySubscribe(_ subject: PassthroughSubject<SubscriptionEvents, APIError>) async {
var apiError: APIError?
do {
try Task.checkCancellation()
let sequence = try await self.nondeterminsticOperation.run()
let sequence = try await nondeterminsticOperation.run()
defer { sequence.cancel() }
for try await event in sequence {
try Task.checkCancellation()
Expand All @@ -122,16 +122,16 @@
}

public func cancel() {
self.task?.cancel()
self.nondeterminsticOperation.cancel()
task?.cancel()
nondeterminsticOperation.cancel()
}
}

extension AsyncSequence {
fileprivate var asyncStream: AsyncStream<Self.Element> {
private extension AsyncSequence {
var asyncStream: AsyncStream<Self.Element> {
AsyncStream { continuation in
Task {
var it = self.makeAsyncIterator()

Check warning on line 134 in Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Variable name 'it' should be between 3 and 40 characters long (identifier_name)
do {
while let ele = try await it.next() {
continuation.yield(ele)
Expand All @@ -145,11 +145,11 @@
}
}

extension RetryableGraphQLSubscriptionOperation {
public static var log: Logger {
public extension RetryableGraphQLSubscriptionOperation {
static var log: Logger {
Amplify.Logging.logger(forCategory: CategoryType.api.displayName, forNamespace: String(describing: self))
}
public var log: Logger {
var log: Logger {
Self.log
}
}
18 changes: 10 additions & 8 deletions Amplify/Categories/API/Request/GraphQLOperationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public struct GraphQLOperationRequest<R: Decodable>: AmplifyOperationRequest {
public let options: Options

/// Initializer for GraphQLOperationRequest
public init(apiName: String?,
operationType: GraphQLOperationType,
document: String,
variables: [String: Any]? = nil,
responseType: R.Type,
decodePath: String? = nil,
authMode: AuthorizationMode? = nil,
options: Options) {
public init(
apiName: String?,
operationType: GraphQLOperationType,
document: String,
variables: [String: Any]? = nil,
responseType: R.Type,
decodePath: String? = nil,
authMode: AuthorizationMode? = nil,
options: Options
) {
self.apiName = apiName
self.operationType = operationType
self.document = document
Expand Down
16 changes: 9 additions & 7 deletions Amplify/Categories/API/Request/GraphQLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public struct GraphQLRequest<R: Decodable> {
/// Options to adjust the behavior of this request, including plugin-options
public var options: Options?

public init(apiName: String? = nil,
document: String,
variables: [String: Any]? = nil,
responseType: R.Type,
decodePath: String? = nil,
authMode: AuthorizationMode? = nil,
options: GraphQLRequest<R>.Options? = nil) {
public init(
apiName: String? = nil,
document: String,
variables: [String: Any]? = nil,
responseType: R.Type,
decodePath: String? = nil,
authMode: AuthorizationMode? = nil,
options: GraphQLRequest<R>.Options? = nil
) {
self.apiName = apiName
self.document = document
self.variables = variables
Expand Down
16 changes: 9 additions & 7 deletions Amplify/Categories/API/Request/RESTOperationRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public struct RESTOperationRequest: AmplifyOperationRequest {
public let options: Options

/// Initializer with all properties
public init(apiName: String?,
operationType: RESTOperationType,
path: String? = nil,
headers: [String: String]? = nil,
queryParameters: [String: String]? = nil,
body: Data? = nil,
options: Options) {
public init(
apiName: String?,
operationType: RESTOperationType,
path: String? = nil,
headers: [String: String]? = nil,
queryParameters: [String: String]? = nil,
body: Data? = nil,
options: Options
) {
self.apiName = apiName
self.operationType = operationType
self.path = path
Expand Down
12 changes: 7 additions & 5 deletions Amplify/Categories/API/Request/RESTRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ public class RESTRequest {
public let body: Data?

/// Initializer with all properties
public init(apiName: String? = nil,
path: String? = nil,
headers: [String: String]? = nil,
queryParameters: [String: String]? = nil,
body: Data? = nil) {
public init(
apiName: String? = nil,
path: String? = nil,
headers: [String: String]? = nil,
queryParameters: [String: String]? = nil,
body: Data? = nil
) {
let inputHeaders = headers ?? [:]
self.headers = inputHeaders.merging(
["Cache-Control": "no-store"],
Expand Down
14 changes: 8 additions & 6 deletions Amplify/Categories/API/Response/GraphQLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ public struct GraphQLError: Decodable {
public let extensions: [String: JSONValue]?

/// Initializer with all properties
public init(message: String,
locations: [Location]? = nil,
path: [JSONValue]? = nil,
extensions: [String: JSONValue]? = nil) {
public init(
message: String,
locations: [Location]? = nil,
path: [JSONValue]? = nil,
extensions: [String: JSONValue]? = nil
) {
self.message = message
self.locations = locations
self.path = path
self.extensions = extensions
}
}

extension GraphQLError {
public extension GraphQLError {

/// Both `line` and `column` are positive numbers describing the beginning of an associated syntax element
public struct Location: Decodable {
struct Location: Decodable {

/// The line describing the associated syntax element
public let line: Int
Expand Down
Loading
Loading