···1+import {ValidationResult} from '@atproto/lexicon'
2+3+export * as profile from './profile'
4+5+/**
6+ * Fast type checking without full schema validation, for use with data we
7+ * trust, or for non-critical path use cases. Why? Our SDK's `is*` identity
8+ * utils do not assert the type of the entire object, only the `$type` string.
9+ *
10+ * For full validation of the object schema, use the `validate` export from
11+ * this file.
12+ *
13+ * Usage:
14+ * ```ts
15+ * import * as bsky from '#/types/bsky'
16+ *
17+ * if (bsky.dangerousIsType<AppBskyFeedPost.Record>(item, AppBskyFeedPost.isRecord)) {
18+ * // `item` has type `$Typed<AppBskyFeedPost.Record>` here
19+ * }
20+ * ```
21+ */
22+export function dangerousIsType<R extends {$type?: string}>(
23+ record: unknown,
24+ identity: <V>(v: V) => v is V & {$type: NonNullable<R['$type']>},
25+): record is R {
26+ return identity(record)
27+}
28+29+/**
30+ * Fully validates the object schema, which has a performance cost.
31+ *
32+ * For faster checks with data we trust, like that from our app view, use the
33+ * `dangerousIsType` export from this same file.
34+ *
35+ * Usage:
36+ * ```ts
37+ * import * as bsky from '#/types/bsky'
38+ *
39+ * if (bsky.validate(item, AppBskyFeedPost.validateRecord)) {
40+ * // `item` has type `$Typed<AppBskyFeedPost.Record>` here
41+ * }
42+ * ```
43+ */
44+export function validate<R extends {$type?: string}>(
45+ record: unknown,
46+ validator: (v: unknown) => ValidationResult<R>,
47+): record is R {
48+ return validator(record).success
49+}
+10
bskyembed/src/types/bsky/profile.ts
···0000000000
···1+import {type AppBskyActorDefs, type ChatBskyActorDefs} from '@atproto/api'
2+3+/**
4+ * Matches any profile view exported by our SDK
5+ */
6+export type AnyProfileView =
7+ | AppBskyActorDefs.ProfileViewBasic
8+ | AppBskyActorDefs.ProfileView
9+ | AppBskyActorDefs.ProfileViewDetailed
10+ | ChatBskyActorDefs.ProfileViewBasic
+11
bskyembed/src/util/nice-date.ts
···00000000000
···1+export function niceDate(date: number | string | Date) {
2+ const d = new Date(date)
3+ return `${d.toLocaleDateString('en-us', {
4+ year: 'numeric',
5+ month: 'short',
6+ day: 'numeric',
7+ })} at ${d.toLocaleTimeString(undefined, {
8+ hour: 'numeric',
9+ minute: '2-digit',
10+ })}`
11+}