Skip to content

Commit 0a699c6

Browse files
authored
Merge pull request #192 from mcprostar205/main
Added public initializers to Lexicons: UploadBlobOutput, BlobReference, ReplyReference
2 parents 721692b + efd64ae commit 0a699c6

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedPost.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ extension AppBskyLexicon.Feed {
147147
/// - Note: If `parent` and `root` are identical, the post is a direct reply to the original
148148
/// post of the thread.
149149
public let parent: ComAtprotoLexicon.Repository.StrongReference
150+
151+
public init(root: ComAtprotoLexicon.Repository.StrongReference, parent: ComAtprotoLexicon.Repository.StrongReference) {
152+
self.root = root
153+
self.parent = parent
154+
}
155+
156+
public init(from decoder: any Decoder) throws {
157+
let container = try decoder.container(keyedBy: CodingKeys.self)
158+
self.root = try container.decode(ComAtprotoLexicon.Repository.StrongReference.self, forKey: .root)
159+
self.parent = try container.decode(ComAtprotoLexicon.Repository.StrongReference.self, forKey: .parent)
160+
}
161+
162+
public func encode(to encoder: any Encoder) throws {
163+
var container = encoder.container(keyedBy: CodingKeys.self)
164+
try container.encode(self.root, forKey: .root)
165+
try container.encode(self.parent, forKey: .parent)
166+
}
167+
168+
enum CodingKeys: String, CodingKey {
169+
case root
170+
case parent
171+
}
150172
}
151173

152174
// Unions

Sources/ATProtoKit/Models/Lexicons/com.atproto/Repo/ComAtprotoRepoUploadBlob.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@ extension ComAtprotoLexicon.Repository {
5454
/// The size of the blob.
5555
public let size: Int
5656

57+
public init(type: String, reference: ComAtprotoLexicon.Repository.BlobReference, mimeType: String, size: Int) {
58+
self.type = type
59+
self.reference = reference
60+
self.mimeType = mimeType
61+
self.size = size
62+
}
63+
64+
public init(from decoder: any Decoder) throws {
65+
let container = try decoder.container(keyedBy: CodingKeys.self)
66+
67+
self.type = try? container.decodeIfPresent(String.self, forKey: .type)
68+
self.reference = try container.decode(ComAtprotoLexicon.Repository.BlobReference.self, forKey: .reference)
69+
self.mimeType = try container.decode(String.self, forKey: .mimeType)
70+
self.size = try container.decode(Int.self, forKey: .size)
71+
}
72+
73+
public func encode(to encoder: any Encoder) throws {
74+
var container = encoder.container(keyedBy: CodingKeys.self)
75+
76+
try container.encodeIfPresent(self.type, forKey: .type)
77+
try container.encode(self.reference, forKey: .reference)
78+
try container.encode(self.mimeType, forKey: .mimeType)
79+
try container.encode(self.size, forKey: .size)
80+
}
81+
5782
enum CodingKeys: String, CodingKey {
5883
case type = "$type"
5984
case reference = "ref"
@@ -67,7 +92,21 @@ extension ComAtprotoLexicon.Repository {
6792

6893
/// The link of the blob reference.
6994
public let link: String
95+
96+
public init(link: String) {
97+
self.link = link
98+
}
7099

100+
public init(from decoder: Decoder) throws {
101+
let container = try decoder.container(keyedBy: CodingKeys.self)
102+
self.link = try container.decode(String.self, forKey: .link)
103+
}
104+
105+
public func encode(to encoder: any Encoder) throws {
106+
var container = encoder.container(keyedBy: CodingKeys.self)
107+
try container.encode(self.link, forKey: .link)
108+
}
109+
71110
enum CodingKeys: String, CodingKey {
72111
case link = "$link"
73112
}

0 commit comments

Comments
 (0)