Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
  •  
  •  
  •  
13 changes: 9 additions & 4 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@
--enable void
--empty void

--disable wrapArguments
--closingparen same-line
--wraparguments after-first
--enable wrapArguments
--closingparen balanced
--wraparguments before-first
--wrapcollections before-first
--wrapconditions preserve

# standalone rules
--disable preferKeyPath
--disable conditionalAssignment
--disable wrapMultilineConditionalAssignment
--disable wrapMultilineStatementBraces
--disable andOperator
--disable anyObjectProtocol
--disable blankLinesAroundMark
Expand Down Expand Up @@ -114,4 +119,4 @@
--enable strongifiedSelf
--disable todos
--enable typeSugar
--enable yodaConditions
--enable yodaConditions
29 changes: 17 additions & 12 deletions Amplify/Amplify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,63 +37,63 @@ public class Amplify: @unchecked Sendable {

/// - Tag: Amplify.Analytics
private static let analyticsAtomic = AtomicValue<AnalyticsCategory>(initialValue: AnalyticsCategory())
public static internal(set) var Analytics: AnalyticsCategory {
public internal(set) static var Analytics: AnalyticsCategory {
get { analyticsAtomic.get() }
set { analyticsAtomic.set(newValue) }
}

/// - Tag: Amplify.API
private static let apiAtomic = AtomicValue<APICategory>(initialValue: APICategory())
public static internal(set) var API: APICategory {
public internal(set) static var API: APICategory {
get { apiAtomic.get() }
set { apiAtomic.set(newValue) }
}

/// - Tag: Amplify.Auth
private static let authAtomic = AtomicValue<AuthCategory>(initialValue: AuthCategory())
public static internal(set) var Auth: AuthCategory {
public internal(set) static var Auth: AuthCategory {
get { authAtomic.get() }
set { authAtomic.set(newValue) }
}

/// - Tag: Amplify.DataStore
private static let dataStoreAtomic = AtomicValue<DataStoreCategory>(initialValue: DataStoreCategory())
public static internal(set) var DataStore: DataStoreCategory {
public internal(set) static var DataStore: DataStoreCategory {
get { dataStoreAtomic.get() }
set { dataStoreAtomic.set(newValue) }
}

/// - Tag: Amplify.Geo
private static let geoAtomic = AtomicValue<GeoCategory>(initialValue: GeoCategory())
public static internal(set) var Geo: GeoCategory {
public internal(set) static var Geo: GeoCategory {
get { geoAtomic.get() }
set { geoAtomic.set(newValue) }
}

/// - Tag: Amplify.Hub
private static let hubAtomic = AtomicValue<HubCategory>(initialValue: HubCategory())
public static internal(set) var Hub: HubCategory {
public internal(set) static var Hub: HubCategory {
get { hubAtomic.get() }
set { hubAtomic.set(newValue) }
}

/// - Tag: Amplify.Notifications
private static let notificationsAtomic = AtomicValue<NotificationsCategory>(initialValue: NotificationsCategory())
public static internal(set) var Notifications: NotificationsCategory {
public internal(set) static var Notifications: NotificationsCategory {
get { notificationsAtomic.get() }
set { notificationsAtomic.set(newValue) }
}

/// - Tag: Amplify.Predictions
private static let predictionsAtomic = AtomicValue<PredictionsCategory>(initialValue: PredictionsCategory())
public static internal(set) var Predictions: PredictionsCategory {
public internal(set) static var Predictions: PredictionsCategory {
get { predictionsAtomic.get() }
set { predictionsAtomic.set(newValue) }
}

/// - Tag: Amplify.Storage
private static let storageAtomic = AtomicValue<StorageCategory>(initialValue: StorageCategory())
public static internal(set) var Storage: StorageCategory {
public internal(set) static var Storage: StorageCategory {
get { storageAtomic.get() }
set { storageAtomic.set(newValue) }
}
Expand All @@ -102,7 +102,7 @@ public class Amplify: @unchecked Sendable {
/// 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 @@ -112,13 +112,15 @@ public class Amplify: @unchecked Sendable {
}
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 @@ -144,8 +146,11 @@ public class Amplify: @unchecked Sendable {
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
1 change: 1 addition & 0 deletions Amplify/Categories/API/Error/APIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ extension APIError: AmplifyError {
For more information on HTTP status codes, take a look at
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
"""

case .pluginError(let error):
return error.recoverySuggestion
}
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
20 changes: 10 additions & 10 deletions Amplify/Categories/API/Operation/RetryableGraphQLOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Combine
import Foundation


// MARK: - RetryableGraphQLOperation
Expand Down Expand Up @@ -91,15 +91,15 @@ public final class RetryableGraphQLSubscriptionOperation<Payload> where Payload:

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,13 +122,13 @@ public final class RetryableGraphQLSubscriptionOperation<Payload> where Payload:
}

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()
Expand All @@ -145,11 +145,11 @@ extension AsyncSequence {
}
}

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
Loading
Loading