Skip to content

Commit 958fb4a

Browse files
committed
Add documentation for BskyRichTextFacet
1 parent 537292b commit 958fb4a

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

Sources/ATProtoKit/Models/Lexicons/app.bsky/RichText/BskyRichTextFacet.swift

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77

88
import Foundation
99

10+
// MARK: - Main definition
11+
/// The main data model definition for a facet.
12+
///
13+
/// - Note: According to the AT Protocol specifications: "Annotation of a sub-string within rich text."
14+
///
15+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
16+
///
17+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
1018
public struct Facet: Codable {
19+
/// The range of characters related to the facet.
1120
public let index: ByteSlice
21+
/// The facet's feature type..
1222
public let features: [FeatureUnion]
1323

1424
public init(index: ByteSlice, features: [FeatureUnion]) {
@@ -38,8 +48,17 @@ public struct Facet: Codable {
3848
}
3949

4050
// Represents the ByteSlice
51+
/// The data model definition for the byte slice.
52+
///
53+
/// - Note: According to the AT Protocol specifications: "Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets."
54+
///
55+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
56+
///
57+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
4158
public struct ByteSlice: Codable {
59+
/// The start index of the byte slice.
4260
public let byteStart: Int
61+
/// The end index of the byte slice.
4362
public let byteEnd: Int
4463

4564
public init(byteStart: Int, byteEnd: Int) {
@@ -65,13 +84,32 @@ public struct ByteSlice: Codable {
6584
}
6685
}
6786

87+
/// A data model protocol for Features.
88+
///
89+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
90+
///
91+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
6892
internal protocol FeatureCodable: Codable {
93+
/// The identifier of the lexicon.
94+
///
95+
/// - Warning: The value must not change.
6996
static var type: String { get }
7097
}
7198

72-
// Mention feature
99+
100+
/// A data model for the Mention feature definition.
101+
///
102+
/// - Note: According to the AT Protocol specifications: "Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID."
103+
///
104+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
105+
///
106+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
73107
public struct Mention: FeatureCodable {
108+
/// The decentralized identifier (DID) of the feature.
74109
public let did: String
110+
/// The identifier of the lexicon.
111+
///
112+
/// - Warning: The value must not change.
75113
static public var type: String = "app.bsky.richtext.facet#mention"
76114

77115
public init(did: String) {
@@ -98,9 +136,20 @@ public struct Mention: FeatureCodable {
98136
}
99137
}
100138

101-
// Link feature
139+
140+
/// A data model for the Link feature definition.
141+
///
142+
/// - Note: According to the AT Protocol specifications: "Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL."
143+
///
144+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
145+
///
146+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
102147
public struct Link: FeatureCodable {
148+
/// The URI of the feature..
103149
public let uri: String
150+
/// The identifier of the lexicon.
151+
///
152+
/// - Warning: The value must not change.
104153
static public var type: String = "app.bsky.richtext.facet#link"
105154

106155
public init(uri: String) {
@@ -127,9 +176,19 @@ public struct Link: FeatureCodable {
127176
}
128177
}
129178

130-
// Hashtag feature
179+
/// A data model for the Tag feature definition.
180+
///
181+
/// - Note: According to the AT Protocol specifications: "Facet feature for a hashtag. The text usually includes a '#' prefix, but the facet reference should not (except in the case of 'double hash tags')."
182+
///
183+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
184+
///
185+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
131186
public struct Tag: FeatureCodable {
187+
/// The
132188
public let tag: String
189+
/// The identifier of the lexicon.
190+
///
191+
/// - Warning: The value must not change.
133192
static public var type: String = "app.bsky.richtext.facet#tag"
134193

135194
public init(tag: String) {
@@ -156,9 +215,18 @@ public struct Tag: FeatureCodable {
156215
}
157216
}
158217

218+
// MARK: - Union types
219+
/// A reference containing the list of feature types.
220+
///
221+
/// - SeeAlso: This is based on the [`app.bsky.richtext.facet`][github] lexicon.
222+
///
223+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/richtext/facet.json
159224
public enum FeatureUnion: Codable {
225+
/// The Mention feature.
160226
case mention(Mention)
227+
/// The Link feature.
161228
case link(Link)
229+
/// The Tag feature.
162230
case tag(Tag)
163231

164232
public init(from decoder: Decoder) throws {

0 commit comments

Comments
 (0)