Skip to content

Commit 439c403

Browse files
authored
Merge pull request #230 from mcprostar205/main
Added more missing initializers for several lexicons & fixed a few optional
2 parents 11489d3 + 92d53ed commit 439c403

13 files changed

+313
-4
lines changed

Sources/ATProtoKit/APIReference/AppBskyAPI/AppBskyGraphMuteThreadMethod.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension ATProtoKit {
4141
}
4242

4343
let requestBody = AppBskyLexicon.Graph.MuteThreadRequestBody(
44-
root: rootPostURI
44+
rootURI: rootPostURI
4545
)
4646

4747
do {

Sources/ATProtoKit/Models/Lexicons/app.bsky/Bookmark/AppBskyBookmarkDeleteBookmark.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ extension AppBskyLexicon.Bookmark {
2525

2626
/// The URI of the bookmark to delete.
2727
public let uri: String
28+
29+
public init(uri: String) {
30+
self.uri = uri
31+
}
32+
2833
}
2934
}

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedExternal.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ extension AppBskyLexicon.Embed {
3030
/// The external content needed to be embeeded.
3131
public let external: External
3232

33+
public init(external: External) {
34+
self.external = external
35+
}
36+
37+
public init(from decoder: any Decoder) throws {
38+
let container = try decoder.container(keyedBy: CodingKeys.self)
39+
self.external = try container.decode(AppBskyLexicon.Embed.ExternalDefinition.External.self, forKey: CodingKeys.external)
40+
}
41+
42+
public func encode(to encoder: any Encoder) throws {
43+
var container = encoder.container(keyedBy: CodingKeys.self)
44+
try container.encode(self.type, forKey: CodingKeys.type)
45+
try container.encode(self.external, forKey: CodingKeys.external)
46+
}
47+
3348
enum CodingKeys: String, CodingKey {
3449
case type = "$type"
3550
case external
@@ -63,6 +78,30 @@ extension AppBskyLexicon.Embed {
6378
/// in the image failing to upload.
6479
public let thumbnailImage: ComAtprotoLexicon.Repository.UploadBlobOutput?
6580

81+
public init(uri: URL, title: String, description: String, thumbnailImage: ComAtprotoLexicon.Repository.UploadBlobOutput?) {
82+
self.uri = uri
83+
self.title = title
84+
self.description = description
85+
self.thumbnailImage = thumbnailImage
86+
}
87+
88+
public init(from decoder: any Decoder) throws {
89+
let container = try decoder.container(keyedBy: CodingKeys.self)
90+
self.uri = try container.decode(URL.self, forKey: CodingKeys.uri)
91+
self.title = try container.decode(String.self, forKey: CodingKeys.title)
92+
self.description = try container.decode(String.self, forKey: CodingKeys.description)
93+
self.thumbnailImage = try container.decodeIfPresent(ComAtprotoLexicon.Repository.UploadBlobOutput.self, forKey: CodingKeys.thumbnailImage)
94+
}
95+
96+
public func encode(to encoder: any Encoder) throws {
97+
var container = encoder.container(keyedBy: CodingKeys.self)
98+
try container.encode(self.type, forKey: CodingKeys.type)
99+
try container.encode(self.uri, forKey: CodingKeys.uri)
100+
try container.encode(self.title, forKey: CodingKeys.title)
101+
try container.encode(self.description, forKey: CodingKeys.description)
102+
try container.encodeIfPresent(self.thumbnailImage, forKey: CodingKeys.thumbnailImage)
103+
}
104+
66105
enum CodingKeys: String, CodingKey {
67106
case type = "$type"
68107
case uri
@@ -87,6 +126,21 @@ extension AppBskyLexicon.Embed {
87126
/// The external content embedded in a post.
88127
public let external: ViewExternal
89128

129+
public init(external: ViewExternal) {
130+
self.external = external
131+
}
132+
133+
public init(from decoder: any Decoder) throws {
134+
let container = try decoder.container(keyedBy: CodingKeys.self)
135+
self.external = try container.decode(ViewExternal.self, forKey: CodingKeys.external)
136+
}
137+
138+
public func encode(to encoder: any Encoder) throws {
139+
var container = encoder.container(keyedBy: CodingKeys.self)
140+
try container.encode(self.type, forKey: CodingKeys.type)
141+
try container.encode(self.external, forKey: CodingKeys.external)
142+
}
143+
90144
enum CodingKeys: String, CodingKey {
91145
case type = "$type"
92146
case external
@@ -113,6 +167,30 @@ extension AppBskyLexicon.Embed {
113167
/// The thumbnail image URL of the external content.
114168
public let thumbnailImageURL: URL?
115169

170+
public init(uri: String, title: String, description: String, thumbnailImageURL: URL?) {
171+
self.uri = uri
172+
self.title = title
173+
self.description = description
174+
self.thumbnailImageURL = thumbnailImageURL
175+
}
176+
177+
public init(from decoder: any Decoder) throws {
178+
let container = try decoder.container(keyedBy: CodingKeys.self)
179+
self.uri = try container.decode(String.self, forKey: CodingKeys.uri)
180+
self.title = try container.decode(String.self, forKey: CodingKeys.title)
181+
self.description = try container.decode(String.self, forKey: CodingKeys.description)
182+
self.thumbnailImageURL = try container.decodeIfPresent(URL.self, forKey: CodingKeys.thumbnailImageURL)
183+
}
184+
185+
public func encode(to encoder: any Encoder) throws {
186+
var container = encoder.container(keyedBy: CodingKeys.self)
187+
try container.encode(self.type, forKey: CodingKeys.type)
188+
try container.encode(self.uri, forKey: CodingKeys.uri)
189+
try container.encode(self.title, forKey: CodingKeys.title)
190+
try container.encode(self.description, forKey: CodingKeys.description)
191+
try container.encodeIfPresent(self.thumbnailImageURL, forKey: CodingKeys.thumbnailImageURL)
192+
}
193+
116194
enum CodingKeys: String, CodingKey {
117195
case type = "$type"
118196
case uri

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedImages.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ extension AppBskyLexicon.Embed {
3636
self.images = images
3737
}
3838

39+
public init(from decoder: any Decoder) throws {
40+
let container = try decoder.container(keyedBy: CodingKeys.self)
41+
self.images = try container.decode([AppBskyLexicon.Embed.ImagesDefinition.Image].self, forKey: CodingKeys.images)
42+
}
43+
44+
public func encode(to encoder: any Encoder) throws {
45+
var container = encoder.container(keyedBy: CodingKeys.self)
46+
try container.encode(self.type, forKey: CodingKeys.type)
47+
try container.encode(self.images, forKey: CodingKeys.images)
48+
}
49+
3950
enum CodingKeys: String, CodingKey {
4051
case type = "$type"
4152
case images
@@ -75,6 +86,20 @@ extension AppBskyLexicon.Embed {
7586
self.aspectRatio = aspectRatio
7687
}
7788

89+
public init(from decoder: any Decoder) throws {
90+
let container = try decoder.container(keyedBy: CodingKeys.self)
91+
self.imageBlob = try container.decode(ComAtprotoLexicon.Repository.UploadBlobOutput.self, forKey: CodingKeys.imageBlob)
92+
self.altText = try container.decode(String.self, forKey: CodingKeys.altText)
93+
self.aspectRatio = try container.decodeIfPresent(AppBskyLexicon.Embed.AspectRatioDefinition.self, forKey: CodingKeys.aspectRatio)
94+
}
95+
96+
public func encode(to encoder: any Encoder) throws {
97+
var container = encoder.container(keyedBy: CodingKeys.self)
98+
try container.encode(self.imageBlob, forKey: CodingKeys.imageBlob)
99+
try container.encode(self.altText, forKey: CodingKeys.altText)
100+
try container.encodeIfPresent(self.aspectRatio, forKey: CodingKeys.aspectRatio)
101+
}
102+
78103
enum CodingKeys: String, CodingKey {
79104
case imageBlob = "image"
80105
case altText = "alt"
@@ -163,6 +188,14 @@ extension AppBskyLexicon.Embed {
163188
self.aspectRatio = aspectRatio
164189
}
165190

191+
public init(from decoder: any Decoder) throws {
192+
let container = try decoder.container(keyedBy: CodingKeys.self)
193+
self.thumbnailImageURL = try container.decode(URL.self, forKey: CodingKeys.thumbnailImageURL)
194+
self.fullSizeImageURL = try container.decode(URL.self, forKey: CodingKeys.fullSizeImageURL)
195+
self.altText = try container.decode(String.self, forKey: CodingKeys.altText)
196+
self.aspectRatio = try container.decodeIfPresent(AppBskyLexicon.Embed.AspectRatioDefinition.self, forKey: CodingKeys.aspectRatio)
197+
}
198+
166199
public func encode(to encoder: any Encoder) throws {
167200
var container = encoder.container(keyedBy: CodingKeys.self)
168201

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedRecord.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ extension AppBskyLexicon.Embed {
3131
/// The strong reference of the record.
3232
public let record: ComAtprotoLexicon.Repository.StrongReference
3333

34+
public init(record: ComAtprotoLexicon.Repository.StrongReference) {
35+
self.record = record
36+
}
37+
38+
public init(from decoder: any Decoder) throws {
39+
let container = try decoder.container(keyedBy: CodingKeys.self)
40+
self.record = try container.decode(ComAtprotoLexicon.Repository.StrongReference.self, forKey: CodingKeys.record)
41+
}
42+
43+
public func encode(to encoder: any Encoder) throws {
44+
var container = encoder.container(keyedBy: CodingKeys.self)
45+
try container.encode(self.type, forKey: CodingKeys.type)
46+
try container.encode(self.record, forKey: CodingKeys.record)
47+
}
48+
3449
enum CodingKeys: String, CodingKey {
3550
case type = "$type"
3651
case record
@@ -52,6 +67,21 @@ extension AppBskyLexicon.Embed {
5267
/// The record of a specific type.
5368
public let record: RecordViewUnion
5469

70+
public init(record: RecordViewUnion) {
71+
self.record = record
72+
}
73+
74+
public init(from decoder: any Decoder) throws {
75+
let container = try decoder.container(keyedBy: CodingKeys.self)
76+
self.record = try container.decode(RecordViewUnion.self, forKey: CodingKeys.record)
77+
}
78+
79+
public func encode(to encoder: any Encoder) throws {
80+
var container = encoder.container(keyedBy: CodingKeys.self)
81+
try container.encode(self.type, forKey: CodingKeys.type)
82+
try container.encode(self.record, forKey: CodingKeys.record)
83+
}
84+
5585
enum CodingKeys: String, CodingKey {
5686
case type = "$type"
5787
case record
@@ -194,7 +224,7 @@ extension AppBskyLexicon.Embed {
194224

195225
/// The date the record was last indexed.
196226
public let indexedAt: Date
197-
227+
198228
public init(from decoder: any Decoder) throws {
199229
let container = try decoder.container(keyedBy: CodingKeys.self)
200230

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedRecordWithMedia.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ extension AppBskyLexicon.Embed {
3434
/// The media of a specific type.
3535
public let media: MediaUnion
3636

37+
public init(record: RecordDefinition, media: MediaUnion) {
38+
self.record = record
39+
self.media = media
40+
}
41+
42+
public init(from decoder: any Decoder) throws {
43+
let container = try decoder.container(keyedBy: CodingKeys.self)
44+
self.record = try container.decode(AppBskyLexicon.Embed.RecordDefinition.self, forKey: CodingKeys.record)
45+
self.media = try container.decode(MediaUnion.self, forKey: CodingKeys.media)
46+
}
47+
48+
public func encode(to encoder: any Encoder) throws {
49+
var container = encoder.container(keyedBy: CodingKeys.self)
50+
try container.encode(self.type, forKey: CodingKeys.type)
51+
try container.encode(self.record, forKey: CodingKeys.record)
52+
try container.encode(self.media, forKey: CodingKeys.media)
53+
}
54+
3755
enum CodingKeys: String, CodingKey {
3856
case type = "$type"
3957
case record
@@ -113,6 +131,24 @@ extension AppBskyLexicon.Embed {
113131
/// The embedded media.
114132
public let media: MediaUnion
115133

134+
public init(record: AppBskyLexicon.Embed.RecordDefinition.View, media: MediaUnion) {
135+
self.record = record
136+
self.media = media
137+
}
138+
139+
public init(from decoder: any Decoder) throws {
140+
let container = try decoder.container(keyedBy: CodingKeys.self)
141+
self.record = try container.decode(AppBskyLexicon.Embed.RecordDefinition.View.self, forKey: CodingKeys.record)
142+
self.media = try container.decode(MediaUnion.self, forKey: CodingKeys.media)
143+
}
144+
145+
public func encode(to encoder: any Encoder) throws {
146+
var container = encoder.container(keyedBy: CodingKeys.self)
147+
try container.encode(self.type, forKey: CodingKeys.type)
148+
try container.encode(self.record, forKey: CodingKeys.record)
149+
try container.encode(self.media, forKey: CodingKeys.media)
150+
}
151+
116152
enum CodingKeys: String, CodingKey {
117153
case type = "$type"
118154
case record

Sources/ATProtoKit/Models/Lexicons/app.bsky/Embed/AppBskyEmbedVideo.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ extension AppBskyLexicon.Embed {
5353
/// The aspect ratio of the video. Optional.
5454
public let aspectRatio: AspectRatioDefinition?
5555

56+
public init(video: ComAtprotoLexicon.Repository.UploadBlobOutput, captions: [Caption]?, altText: String?, aspectRatio: AspectRatioDefinition?) {
57+
self.video = video
58+
self.captions = captions
59+
self.altText = altText
60+
self.aspectRatio = aspectRatio
61+
}
62+
63+
public init(from decoder: any Decoder) throws {
64+
let container = try decoder.container(keyedBy: CodingKeys.self)
65+
self.video = try container.decode(ComAtprotoLexicon.Repository.UploadBlobOutput.self, forKey: CodingKeys.video)
66+
self.captions = try container.decodeIfPresent([Caption].self, forKey: CodingKeys.captions)
67+
self.altText = try container.decodeIfPresent(String.self, forKey: CodingKeys.altText)
68+
self.aspectRatio = try container.decodeIfPresent(AppBskyLexicon.Embed.AspectRatioDefinition.self, forKey: CodingKeys.aspectRatio)
69+
}
70+
5671
public func encode(to encoder: any Encoder) throws {
5772
var container = encoder.container(keyedBy: CodingKeys.self)
5873

@@ -92,6 +107,24 @@ extension AppBskyLexicon.Embed {
92107
/// 20,000 bytes (or 2 KB).
93108
public let fileBlob: ComAtprotoLexicon.Repository.UploadBlobOutput
94109

110+
public init(language: String, fileBlob: ComAtprotoLexicon.Repository.UploadBlobOutput) {
111+
self.language = language
112+
self.fileBlob = fileBlob
113+
}
114+
115+
public init(from decoder: any Decoder) throws {
116+
let container = try decoder.container(keyedBy: CodingKeys.self)
117+
self.language = try container.decode(String.self, forKey: CodingKeys.language)
118+
self.fileBlob = try container.decode(ComAtprotoLexicon.Repository.UploadBlobOutput.self, forKey: CodingKeys.fileBlob)
119+
}
120+
121+
public func encode(to encoder: any Encoder) throws {
122+
var container = encoder.container(keyedBy: CodingKeys.self)
123+
try container.encode(self.type, forKey: CodingKeys.type)
124+
try container.encode(self.language, forKey: CodingKeys.language)
125+
try container.encode(self.fileBlob, forKey: CodingKeys.fileBlob)
126+
}
127+
95128
enum CodingKeys: String, CodingKey {
96129
case type = "$type"
97130
case language = "lang"

Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteActor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ extension AppBskyLexicon.Graph {
2525
/// The AT Identifier or handle of a user account.
2626
public let actor: String
2727

28+
public init(actor: String) {
29+
self.actor = actor
30+
}
31+
32+
public init(from decoder: any Decoder) throws {
33+
let container = try decoder.container(keyedBy: CodingKeys.self)
34+
self.actor = try container.decode(String.self, forKey: CodingKeys.actor)
35+
}
36+
37+
public func encode(to encoder: any Encoder) throws {
38+
var container = encoder.container(keyedBy: CodingKeys.self)
39+
try container.encode(self.actor, forKey: CodingKeys.actor)
40+
}
41+
2842
enum CodingKeys: CodingKey {
2943
case actor
3044
}

Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ extension AppBskyLexicon.Graph {
2424
public struct MuteThreadRequestBody: Sendable, Codable {
2525

2626
/// The URI of the root of the post.
27-
public let root: String
27+
public let rootURI: String
28+
29+
public init(rootURI: String) {
30+
self.rootURI = rootURI
31+
}
32+
33+
public init(from decoder: any Decoder) throws {
34+
let container = try decoder.container(keyedBy: CodingKeys.self)
35+
self.rootURI = try container.decode(String.self, forKey: CodingKeys.rootURI)
36+
}
37+
38+
39+
public func encode(to encoder: any Encoder) throws {
40+
var container = encoder.container(keyedBy: CodingKeys.self)
41+
try container.encode(self.rootURI, forKey: CodingKeys.rootURI)
42+
}
43+
44+
enum CodingKeys: String, CodingKey {
45+
case rootURI = "root"
46+
}
2847
}
2948
}

Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteActor.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ extension AppBskyLexicon.Graph {
2525
/// The AT Identifier or handle of a user account.
2626
public let actor: String
2727

28+
public init(actor: String) {
29+
self.actor = actor
30+
}
31+
32+
public init(from decoder: any Decoder) throws {
33+
let container = try decoder.container(keyedBy: CodingKeys.self)
34+
self.actor = try container.decode(String.self, forKey: CodingKeys.actor)
35+
}
36+
37+
public func encode(to encoder: any Encoder) throws {
38+
var container = encoder.container(keyedBy: CodingKeys.self)
39+
try container.encode(self.actor, forKey: CodingKeys.actor)
40+
}
41+
2842
enum CodingKeys: String, CodingKey {
2943
case actor = "actor"
3044
}

0 commit comments

Comments
 (0)