Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/dfob.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DevFoundationTests"
BuildableName = "DevFoundationTests"
BlueprintName = "DevFoundationTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
13 changes: 13 additions & 0 deletions Scripts/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Go to the repository root (one level up from Scripts)
REPO_ROOT="$(dirname "$SCRIPT_DIR")"

# Run swift format with --in-place to fix formatting issues
swift format --in-place --recursive \
"$REPO_ROOT/Packages/" \
"$REPO_ROOT/Sources/" \
"$REPO_ROOT/Tests/"
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ extension DispatchQueue {
label: String,
qos: DispatchQoS = .unspecified,
attributes: DispatchQueue.Attributes = [],
autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency = .inherit
autoreleaseFrequency: DispatchQueue.AutoreleaseFrequency = .inherit,
) -> DispatchQueue {
return .init(
label: label,
qos: qos,
attributes: attributes,
autoreleaseFrequency: autoreleaseFrequency,
target: .global(qos: qos.qosClass)
target: .global(qos: qos.qosClass),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ extension DispatchQueue {
/// queue uses `.utility` for its quality-of-service.
public static let utility: DispatchQueue = .makeNonOvercommitting(
label: reverseDNSPrefixed("utility"),
qos: .utility
qos: .utility,
)
}
4 changes: 2 additions & 2 deletions Sources/DevFoundation/Concurrency/ExecutionGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class ExecutionGroup: Sendable {
@discardableResult
public func addTask<Success>(
priority: TaskPriority? = nil,
operation: @escaping @Sendable @isolated(any) () async -> Success
operation: @escaping @Sendable @isolated(any) () async -> Success,
) -> Task<Success, Never> {
incrementTaskCount()

Expand All @@ -103,7 +103,7 @@ public final class ExecutionGroup: Sendable {
@discardableResult
public func addTask<Success>(
priority: TaskPriority? = nil,
operation: @escaping @Sendable @isolated(any) () async throws -> Success
operation: @escaping @Sendable @isolated(any) () async throws -> Success,
) -> Task<Success, any Error> where Success: Sendable {
incrementTaskCount()

Expand Down
2 changes: 1 addition & 1 deletion Sources/DevFoundation/Concurrency/WithTimeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Foundation
public func withTimeout<Success, Failure>(
_ timeout: Duration,
priority: TaskPriority? = nil,
operation: @escaping @Sendable () async throws(Failure) -> Success
operation: @escaping @Sendable () async throws(Failure) -> Success,
) async throws -> Success
where Success: Sendable, Failure: Error {
let deadline = ContinuousClock.Instant.now + timeout
Expand Down
10 changes: 5 additions & 5 deletions Sources/DevFoundation/Event Bus/ContextualBusEventObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class ContextualBusEventObserver<Context>: BusEventObserver where C
@discardableResult
public func addHandler<Event>(
for eventType: Event.Type,
body: @escaping @Sendable (Event, inout Context) -> Void
body: @escaping @Sendable (Event, inout Context) -> Void,
) -> AnyObject where Event: BusEvent {
let key = EventHandlerKey(eventType: eventType)
let handler = Handler<Event>(body: body, eventID: nil)
Expand All @@ -76,7 +76,7 @@ public final class ContextualBusEventObserver<Context>: BusEventObserver where C
public func addHandler<Event>(
for eventType: Event.Type,
id: Event.ID,
body: @escaping @Sendable (Event, inout Context) -> Void
body: @escaping @Sendable (Event, inout Context) -> Void,
) -> AnyObject where Event: BusEvent & Identifiable, Event.ID: Sendable {
let key = IdentifiableEventHandlerKey(eventType: eventType, eventID: id)
let handler = Handler<Event>(body: body, eventID: AnySendableHashable(id))
Expand Down Expand Up @@ -252,7 +252,7 @@ extension ContextualBusEventObserver {
/// - The event ID with which the handler was added.
init(
body: @escaping @Sendable (Event, inout Context) -> Void,
eventID: AnySendableHashable?
eventID: AnySendableHashable?,
) {
self.body = body
self.eventID = eventID
Expand Down Expand Up @@ -283,7 +283,7 @@ extension ContextualBusEventObserver {
/// The serial executor on which this actor’s jobs are executed.
private let serialExecutor = DispatchSerialQueue(
label: reverseDNSPrefixed("contextual-bus-event-observer"),
target: .utility
target: .utility,
)


Expand All @@ -308,7 +308,7 @@ extension ContextualBusEventObserver {


nonisolated var unownedExecutor: UnownedSerialExecutor {
return .init(serialExecutor)
return .init(complexEquality: serialExecutor)
}
}
}
6 changes: 3 additions & 3 deletions Sources/DevFoundation/Extensions/Data+Obfuscation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension Data {
public func obfuscated<MessageSize, KeySize>(
withKey key: Data,
keySizeType: KeySize.Type,
messageSizeType: MessageSize.Type
messageSizeType: MessageSize.Type,
) throws -> Data
where
KeySize: FixedWidthInteger,
Expand Down Expand Up @@ -55,7 +55,7 @@ extension Data {
/// - messageSizeType: The message size type used to obfuscate the data.
public func deobfuscated<MessageSize, KeySize>(
keySizeType: KeySize.Type,
messageSizeType: MessageSize.Type
messageSizeType: MessageSize.Type,
) throws -> Data
where
KeySize: FixedWidthInteger & Sendable,
Expand Down Expand Up @@ -88,7 +88,7 @@ extension Data {
/// be extracted.
private func extractFieldData<FieldSize>(
at index: Int,
sizeType: FieldSize.Type
sizeType: FieldSize.Type,
) -> (Data, Int)?
where FieldSize: FixedWidthInteger & Sendable {
let fieldSizeEndIndex = index + FieldSize.byteWidth
Expand Down
10 changes: 5 additions & 5 deletions Sources/DevFoundation/Networking/HTTP Client/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class HTTPClient<RequestContext>: Sendable where RequestContext: Se
public init(
urlRequestLoader: any URLRequestLoader,
interceptors: [any HTTPClientInterceptor<RequestContext>] = [],
retryPolicy: (any RetryPolicy<(URLRequest, RequestContext), Result<HTTPResponse<Data>, any Error>>)? = nil
retryPolicy: (any RetryPolicy<(URLRequest, RequestContext), Result<HTTPResponse<Data>, any Error>>)? = nil,
) {
self.urlRequestLoader = urlRequestLoader
self.interceptors = interceptors
Expand Down Expand Up @@ -90,7 +90,7 @@ public final class HTTPClient<RequestContext>: Sendable where RequestContext: Se
_ urlRequest: URLRequest,
context: RequestContext,
attemptCount: Int,
initialDelay: Duration
initialDelay: Duration,
) async throws -> HTTPResponse<Data> {
if initialDelay != .zero {
try Task.checkCancellation()
Expand All @@ -107,7 +107,7 @@ public final class HTTPClient<RequestContext>: Sendable where RequestContext: Se
forInput: (urlRequest, context),
output: result,
attemptCount: attemptCount,
previousDelay: initialDelay
previousDelay: initialDelay,
)
else {
return try result.get()
Expand All @@ -131,7 +131,7 @@ public final class HTTPClient<RequestContext>: Sendable where RequestContext: Se
private func load(
_ urlRequest: URLRequest,
context: RequestContext,
interceptorIndex: Int
interceptorIndex: Int,
) async throws -> HTTPResponse<Data> {
// If we’re out of interceptors, load the data
guard interceptorIndex < interceptors.endIndex else {
Expand All @@ -147,7 +147,7 @@ public final class HTTPClient<RequestContext>: Sendable where RequestContext: Se
// Otherwise, pass the interceptor our data and call the next one
return try await interceptors[interceptorIndex].intercept(
request: urlRequest,
context: context
context: context,
) { (request, context) in
return try await load(request, context: context, interceptorIndex: interceptorIndex + 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public protocol HTTPClientInterceptor<RequestContext>: Sendable {
next: (
_ request: URLRequest,
_ context: RequestContext
) async throws -> HTTPResponse<Data>
) async throws -> HTTPResponse<Data>,
) async throws -> HTTPResponse<Data>
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct HTTPResponse<Body> {
) throws(ErrorType) -> HTTPResponse<MappedBody> {
return HTTPResponse<MappedBody>(
httpURLResponse: httpURLResponse,
body: try transform(body)
body: try transform(body),
)
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ extension HTTPResponse where Body == Data {
/// - Throws: Throws any errors that occur during decoding.
public func decode<Value>(
_ type: Value.Type,
decoder: some TopLevelDecoder<Data>
decoder: some TopLevelDecoder<Data>,
) throws -> HTTPResponse<Value>
where Value: Decodable {
return try mapBody { (body) in
Expand All @@ -126,7 +126,7 @@ extension HTTPResponse where Body == Data {
public func decode<Value, Key>(
_ type: Value.Type,
decoder: some TopLevelDecoder<Data>,
topLevelKey: Key
topLevelKey: Key,
) throws -> HTTPResponse<Value>
where Value: Decodable, Key: CodingKey {
return try mapBody { (body) in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ where Self == SimulatedURLRequestLoader.RequestConditions.AnyRequestCondition {
/// - Returns: The new request condition.
public static func bodyEquals<Body>(
_ body: Body,
decoder: any TopLevelDecoder<Data> & Sendable = JSONDecoder()
decoder: any TopLevelDecoder<Data> & Sendable = JSONDecoder(),
) -> Self
where Body: Decodable & Equatable & Sendable {
return .init(
SimulatedURLRequestLoader.RequestConditions.BodyEqualsDecodable(
body: body,
decoder: decoder
decoder: decoder,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension SimulatedURLRequestLoader {
public init(
requestConditions: [any RequestCondition],
responseGenerator: any ResponseGenerator,
maxResponses: Int? = 1
maxResponses: Int? = 1,
) {
self.requestConditions = requestConditions
self.responseGenerator = responseGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ extension SimulatedURLRequestLoader {
with error: any Error,
delay: Duration = .zero,
maxResponses: Int? = 1,
when requestConditions: [any RequestCondition]
when requestConditions: [any RequestCondition],
) -> some Responder {
let responder = Responder(
requestConditions: requestConditions,
responseGenerator: FixedResponseGenerator(
result: .failure(error),
delay: delay
delay: delay,
),
maxResponses: maxResponses
maxResponses: maxResponses,
)
add(responder)
return responder
Expand All @@ -112,7 +112,7 @@ extension SimulatedURLRequestLoader {
body: Data,
delay: Duration = .zero,
maxResponses: Int? = 1,
when requestConditions: [any RequestCondition]
when requestConditions: [any RequestCondition],
) -> some Responder {
let responder = Responder(
requestConditions: requestConditions,
Expand All @@ -121,12 +121,12 @@ extension SimulatedURLRequestLoader {
SuccessResponseTemplate(
statusCode: statusCode,
headerItems: headerItems,
body: body
body: body,
)
),
delay: delay
delay: delay,
),
maxResponses: maxResponses
maxResponses: maxResponses,
)
add(responder)
return responder
Expand All @@ -152,7 +152,7 @@ extension SimulatedURLRequestLoader {
encoding: String.Encoding = .utf8,
delay: Duration = .zero,
maxResponses: Int? = 1,
when requestConditions: [any RequestCondition]
when requestConditions: [any RequestCondition],
) -> some Responder {
let responder = Responder(
requestConditions: requestConditions,
Expand All @@ -161,12 +161,12 @@ extension SimulatedURLRequestLoader {
SuccessResponseTemplate(
statusCode: statusCode,
headerItems: headerItems,
body: body.data(using: encoding)!
body: body.data(using: encoding)!,
)
),
delay: delay
delay: delay,
),
maxResponses: maxResponses
maxResponses: maxResponses,
)
add(responder)
return responder
Expand Down Expand Up @@ -194,7 +194,7 @@ extension SimulatedURLRequestLoader {
encoder: any TopLevelEncoder<Data> = JSONEncoder(),
delay: Duration = .zero,
maxResponses: Int? = 1,
when requestConditions: [any RequestCondition]
when requestConditions: [any RequestCondition],
) -> some Responder
where Body: Encodable {
let responder = Responder(
Expand All @@ -204,12 +204,12 @@ extension SimulatedURLRequestLoader {
SuccessResponseTemplate(
statusCode: statusCode,
headerItems: headerItems,
body: try! encoder.encode(body)
body: try! encoder.encode(body),
)
),
delay: delay
delay: delay,
),
maxResponses: maxResponses
maxResponses: maxResponses,
)
add(responder)
return responder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension SimulatedURLRequestLoader {
public init(
statusCode: HTTPStatusCode,
headerItems: Set<HTTPHeaderItem>,
body: Data
body: Data,
) {
self.statusCode = statusCode
self.headerItems = headerItems
Expand All @@ -58,8 +58,8 @@ extension SimulatedURLRequestLoader {
httpVersion: nil,
headerFields: Dictionary(
headerItems.map { ($0.field.rawValue, $0.value) },
uniquingKeysWith: { $1 }
)
uniquingKeysWith: { $1 },
),
)!

return (body, httpURLResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ where BaseURLConfiguration: BaseURLConfiguring, RequestContext: Sendable {
let urlRequest = try request.urlRequest(with: baseURLConfiguration)
let response = try await httpClient.load(
urlRequest,
context: request.context
context: request.context,
)
return try request.mapResponse(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension WebServiceRequest {
} catch {
throw InvalidWebServiceRequestError(
debugDescription: "could not create the request’s HTTP body",
underlyingError: error
underlyingError: error,
)
}

Expand Down
Loading
Loading