Skip to content

Commit 3cbf47d

Browse files
committed
and now to conditionally apply sendable more broadly
1 parent 250c97e commit 3cbf47d

File tree

12 files changed

+64
-7
lines changed

12 files changed

+64
-7
lines changed

Sources/JSONAPI/Document/APIDescription.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public struct APIDescription<Meta: JSONAPI.Meta>: APIDescriptionType {
2121
}
2222
}
2323

24+
extension APIDescription: Sendable where Meta: Sendable {}
25+
2426
/// Can be used as `APIDescriptionType` for Documents that do not
2527
/// have any API Description (a.k.a. "JSON:API Object").
2628
public struct NoAPIDescription: APIDescriptionType, CustomStringConvertible {
@@ -33,6 +35,8 @@ public struct NoAPIDescription: APIDescriptionType, CustomStringConvertible {
3335
public var description: String { return "No JSON:API Object" }
3436
}
3537

38+
extension NoAPIDescription: Sendable {}
39+
3640
extension APIDescription {
3741
private enum CodingKeys: String, CodingKey {
3842
case version

Sources/JSONAPI/Document/Document.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public struct Document<PrimaryResourceBody: JSONAPI.EncodableResourceBody, MetaT
186186
}
187187
}
188188

189+
extension Document: Sendable where
190+
APIDescription: Sendable,
191+
Body: Sendable {}
192+
189193
extension Document {
190194
public enum Body: DocumentBody, Equatable {
191195
case errors([Error], meta: MetaType?, links: LinksType?)
@@ -260,6 +264,17 @@ extension Document {
260264
}
261265
}
262266

267+
extension Document.Body: Sendable where
268+
MetaType: Sendable,
269+
LinksType: Sendable,
270+
Data: Sendable {}
271+
272+
extension Document.Body.Data: Sendable where
273+
PrimaryResourceBody: Sendable,
274+
IncludeType: Sendable,
275+
MetaType: Sendable,
276+
LinksType: Sendable {}
277+
263278
extension Document.Body.Data where PrimaryResourceBody: ResourceBodyAppendable {
264279
public func merging<OtherDescription, OtherError>(_ other: Document<PrimaryResourceBody, MetaType, LinksType, IncludeType, OtherDescription, OtherError>.Body.Data,
265280
combiningMetaWith metaMerge: (MetaType, MetaType) -> MetaType,

Sources/JSONAPI/Document/Includes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public struct Includes<I: Include>: Encodable, Equatable {
4545
}
4646
}
4747

48+
extension Includes: Sendable where I: Sendable {}
49+
4850
extension Includes: Decodable where I: Decodable {
4951
public init(from decoder: Decoder) throws {
5052
var container = try decoder.unkeyedContainer()

Sources/JSONAPI/Document/ResourceBody.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public struct SingleResourceBody<PrimaryResource: JSONAPI.OptionalEncodablePrima
6565
}
6666
}
6767

68+
extension SingleResourceBody: Sendable where PrimaryResource: Sendable {}
69+
6870
public protocol ManyResourceBodyProtocol: EncodableResourceBody {
6971
var values: [PrimaryResource] { get }
7072

@@ -84,6 +86,8 @@ public struct ManyResourceBody<PrimaryResource: JSONAPI.EncodablePrimaryResource
8486
}
8587
}
8688

89+
extension ManyResourceBody: Sendable where PrimaryResource: Sendable {}
90+
8791
/// Use NoResourceBody to indicate you expect a JSON API document to not
8892
/// contain a "data" top-level key.
8993
public struct NoResourceBody: CodableResourceBody {
@@ -92,6 +96,8 @@ public struct NoResourceBody: CodableResourceBody {
9296
public static var none: NoResourceBody { return NoResourceBody() }
9397
}
9498

99+
extension NoResourceBody: Sendable {}
100+
95101
// MARK: Codable
96102
extension SingleResourceBody {
97103
public func encode(to encoder: Encoder) throws {

Sources/JSONAPI/Meta/Links.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public protocol Links: Codable, Equatable {}
1010

1111
/// Use NoLinks where no links should belong to a JSON API component
12-
public struct NoLinks: Links, CustomStringConvertible {
12+
public struct NoLinks: Links, CustomStringConvertible, Sendable {
1313
public static var none: NoLinks { return NoLinks() }
1414
public init() {}
1515

@@ -28,6 +28,8 @@ public struct Link<URL: JSONAPI.JSONAPIURL, Meta: JSONAPI.Meta>: Equatable, Coda
2828
}
2929
}
3030

31+
extension Link: Sendable where Meta: Sendable, URL: Sendable {}
32+
3133
extension Link where Meta == NoMetadata {
3234
public init(url: URL) {
3335
self.init(url: url, meta: .none)

Sources/JSONAPI/Meta/Meta.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension Optional: Meta where Wrapped: Meta {}
2121

2222
/// Use this type when you want to specify not to encode or decode any metadata
2323
/// for a type.
24-
public struct NoMetadata: Meta, CustomStringConvertible {
24+
public struct NoMetadata: Meta, CustomStringConvertible, Sendable {
2525
public static var none: NoMetadata { return NoMetadata() }
2626

2727
public init() { }

Sources/JSONAPI/Resource/Attribute.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public struct TransformedAttribute<RawValue: Codable, Transformer: JSONAPI.Trans
3434
}
3535
}
3636

37+
extension TransformedAttribute: Sendable where RawValue: Sendable, Transformer.To: Sendable {}
38+
3739
extension TransformedAttribute where Transformer == IdentityTransformer<RawValue> {
3840
// If we are using the identity transform, we can skip the transform and guarantee no
3941
// error is thrown.
@@ -82,6 +84,8 @@ public struct Attribute<RawValue: Codable>: AttributeType {
8284
}
8385
}
8486

87+
extension Attribute: Sendable where RawValue: Sendable {}
88+
8589
extension Attribute: CustomStringConvertible {
8690
public var description: String {
8791
return "Attribute<\(String(describing: RawValue.self))>(\(String(describing: value)))"

Sources/JSONAPI/Resource/Id.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public struct Id<RawType: MaybeRawId, IdentifiableType: JSONAPI.JSONTyped>: Equa
9797
}
9898
}
9999

100+
extension Id: Sendable where RawType: Sendable {}
101+
100102
extension Id: Hashable where RawType: RawIdType {
101103
public func hash(into hasher: inout Hasher) {
102104
hasher.combine(ObjectIdentifier(Self.self))

Sources/JSONAPI/Resource/Poly+PrimaryResource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Poly
1515
/// disparate types under one roof for
1616
/// the purposes of JSON API compliant
1717
/// encoding or decoding.
18-
public typealias EncodableJSONPoly = Poly & EncodablePrimaryResource & Sendable
18+
public typealias EncodableJSONPoly = Poly & EncodablePrimaryResource
1919

2020
public typealias EncodablePolyWrapped = Encodable & Equatable
2121
public typealias CodablePolyWrapped = EncodablePolyWrapped & Decodable

Sources/JSONAPI/Resource/Relationship.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public struct ToOneRelationship<Identifiable: JSONAPI.JSONAPIIdentifiable, IdMet
6060
}
6161
}
6262

63+
extension ToOneRelationship: Sendable where
64+
Identifiable.ID: Sendable,
65+
IdMetaType: Sendable,
66+
MetaType: Sendable,
67+
LinksType: Sendable {}
68+
6369
extension ToOneRelationship where IdMetaType == NoIdMetadata {
6470
public init(id: Identifiable.ID, meta: MetaType, links: LinksType) {
6571
self.id = id
@@ -167,6 +173,15 @@ public struct ToManyRelationship<Relatable: JSONAPI.Relatable, IdMetaType: JSONA
167173
}
168174
}
169175

176+
extension ToManyRelationship.ID: Sendable where
177+
Relatable.ID: Sendable,
178+
IdMetaType: Sendable {}
179+
180+
extension ToManyRelationship: Sendable where
181+
ID: Sendable,
182+
MetaType: Sendable,
183+
LinksType: Sendable {}
184+
170185
extension ToManyRelationship where IdMetaType == NoIdMetadata {
171186
public init(ids: [Relatable.ID], meta: MetaType, links: LinksType) {
172187
self.idsWithMeta = ids.map { .init(id: $0, meta: .none) }

0 commit comments

Comments
 (0)