/
facet.ts
98 lines (83 loc) · 2.93 KB
/
facet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { isObj, hasProp } from '../../../../util'
import { lexicons } from '../../../../lexicons'
import { CID } from 'multiformats/cid'
/** Annotation of a sub-string within rich text. */
export interface Main {
index: ByteSlice
features: (Mention | Link | Tag | { $type: string; [k: string]: unknown })[]
[k: string]: unknown
}
export function isMain(v: unknown): v is Main {
return (
isObj(v) &&
hasProp(v, '$type') &&
(v.$type === 'app.bsky.richtext.facet#main' ||
v.$type === 'app.bsky.richtext.facet')
)
}
export function validateMain(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#main', v)
}
/** Facet feature for mention of another account. The text is usually a handle, including a '@' prefix, but the facet reference is a DID. */
export interface Mention {
did: string
[k: string]: unknown
}
export function isMention(v: unknown): v is Mention {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#mention'
)
}
export function validateMention(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#mention', v)
}
/** Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL. */
export interface Link {
uri: string
[k: string]: unknown
}
export function isLink(v: unknown): v is Link {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#link'
)
}
export function validateLink(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#link', v)
}
/** 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'). */
export interface Tag {
tag: string
[k: string]: unknown
}
export function isTag(v: unknown): v is Tag {
return (
isObj(v) && hasProp(v, '$type') && v.$type === 'app.bsky.richtext.facet#tag'
)
}
export function validateTag(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#tag', v)
}
/** 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. */
export interface ByteSlice {
byteStart: number
byteEnd: number
[k: string]: unknown
}
export function isByteSlice(v: unknown): v is ByteSlice {
return (
isObj(v) &&
hasProp(v, '$type') &&
v.$type === 'app.bsky.richtext.facet#byteSlice'
)
}
export function validateByteSlice(v: unknown): ValidationResult {
return lexicons.validate('app.bsky.richtext.facet#byteSlice', v)
}