Skip to content

Commit

Permalink
codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Jan 24, 2025
1 parent 2c2a544 commit 6fa83af
Show file tree
Hide file tree
Showing 885 changed files with 1,069 additions and 7,749 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ export class SchemaRecord {
ComAtprotoRepoCreateRecord.InputSchema,
'collection' | 'record'
>,
record: ComAtprotoLexiconSchema.Record,
record: Un$Typed<ComAtprotoLexiconSchema.Record>,
headers?: Record<string, string>,
): Promise<{ uri: string; cid: string }> {
const collection = 'com.atproto.lexicon.schema'
Expand Down
37 changes: 14 additions & 23 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13797,41 +13797,32 @@ export const schemaDict = {
export const schemas = Object.values(schemaDict) satisfies LexiconDoc[]
export const lexicons: Lexicons = new Lexicons(schemas)

export function validate<V>(v: unknown, id: string, hash: string) {
return (
maybe$typed(v, id, hash)
? lexicons.validate(`${id}#${hash}`, v)
: {
success: false,
error: new ValidationError(
`Must be an object with "${id}#${hash}" $type property`,
),
}
) as ValidationResult<V>
}

export function isValid<V extends { $type?: string }>(
export function validate<T extends { $type: string }>(
v: unknown,
id: string,
hash: string,
requiredType: true,
): v is $Typed<V>
export function isValid<V extends { $type?: string }>(
): ValidationResult<T>
export function validate<T extends { $type?: string }>(
v: unknown,
id: string,
hash: string,
requiredType?: false,
): v is V
export function isValid(
): ValidationResult<T>
export function validate(
v: unknown,
id: string,
hash: string,
requiredType?: boolean,
) {
return (
(requiredType ? is$typed : maybe$typed)(v, id, hash) &&
validate(v, id, hash).success
)
): ValidationResult {
return (requiredType ? is$typed : maybe$typed)(v, id, hash)
? lexicons.validate(`${id}#${hash}`, v)
: {
success: false,
error: new ValidationError(
`Must be an object with "${hash === 'main' ? id : `${id}#${hash}`}" $type property`,
),
}
}

export const ids = {
Expand Down
102 changes: 1 addition & 101 deletions packages/api/src/client/types/app/bsky/actor/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
*/
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { CID } from 'multiformats/cid'
import {
isValid as _isValid,
validate as _validate,
} from '../../../../lexicons'
import { validate as _validate } from '../../../../lexicons'
import { $Type, $Typed, is$typed as _is$typed, OmitKey } from '../../../../util'
import type * as ComAtprotoLabelDefs from '../../../com/atproto/label/defs'
import type * as AppBskyGraphDefs from '../graph/defs'
import type * as ComAtprotoRepoStrongRef from '../../../com/atproto/repo/strongRef'

const is$typed = _is$typed,
isValid = _isValid,
validate = _validate
const id = 'app.bsky.actor.defs'

Expand All @@ -39,10 +35,6 @@ export function validateProfileViewBasic<V>(v: V) {
return validate<ProfileViewBasic & V>(v, id, hashProfileViewBasic)
}

export function isValidProfileViewBasic<V>(v: V) {
return isValid<ProfileViewBasic & V>(v, id, hashProfileViewBasic)
}

export interface ProfileView {
$type?: $Type<'app.bsky.actor.defs', 'profileView'>
did: string
Expand All @@ -67,10 +59,6 @@ export function validateProfileView<V>(v: V) {
return validate<ProfileView & V>(v, id, hashProfileView)
}

export function isValidProfileView<V>(v: V) {
return isValid<ProfileView & V>(v, id, hashProfileView)
}

export interface ProfileViewDetailed {
$type?: $Type<'app.bsky.actor.defs', 'profileViewDetailed'>
did: string
Expand Down Expand Up @@ -101,10 +89,6 @@ export function validateProfileViewDetailed<V>(v: V) {
return validate<ProfileViewDetailed & V>(v, id, hashProfileViewDetailed)
}

export function isValidProfileViewDetailed<V>(v: V) {
return isValid<ProfileViewDetailed & V>(v, id, hashProfileViewDetailed)
}

export interface ProfileAssociated {
$type?: $Type<'app.bsky.actor.defs', 'profileAssociated'>
lists?: number
Expand All @@ -124,10 +108,6 @@ export function validateProfileAssociated<V>(v: V) {
return validate<ProfileAssociated & V>(v, id, hashProfileAssociated)
}

export function isValidProfileAssociated<V>(v: V) {
return isValid<ProfileAssociated & V>(v, id, hashProfileAssociated)
}

export interface ProfileAssociatedChat {
$type?: $Type<'app.bsky.actor.defs', 'profileAssociatedChat'>
allowIncoming: 'all' | 'none' | 'following' | (string & {})
Expand All @@ -143,10 +123,6 @@ export function validateProfileAssociatedChat<V>(v: V) {
return validate<ProfileAssociatedChat & V>(v, id, hashProfileAssociatedChat)
}

export function isValidProfileAssociatedChat<V>(v: V) {
return isValid<ProfileAssociatedChat & V>(v, id, hashProfileAssociatedChat)
}

/** Metadata about the requesting account's relationship with the subject account. Only has meaningful content for authed requests. */
export interface ViewerState {
$type?: $Type<'app.bsky.actor.defs', 'viewerState'>
Expand All @@ -170,10 +146,6 @@ export function validateViewerState<V>(v: V) {
return validate<ViewerState & V>(v, id, hashViewerState)
}

export function isValidViewerState<V>(v: V) {
return isValid<ViewerState & V>(v, id, hashViewerState)
}

/** The subject's followers whom you also follow */
export interface KnownFollowers {
$type?: $Type<'app.bsky.actor.defs', 'knownFollowers'>
Expand All @@ -191,10 +163,6 @@ export function validateKnownFollowers<V>(v: V) {
return validate<KnownFollowers & V>(v, id, hashKnownFollowers)
}

export function isValidKnownFollowers<V>(v: V) {
return isValid<KnownFollowers & V>(v, id, hashKnownFollowers)
}

export type Preferences = (
| $Typed<AdultContentPref>
| $Typed<ContentLabelPref>
Expand Down Expand Up @@ -226,10 +194,6 @@ export function validateAdultContentPref<V>(v: V) {
return validate<AdultContentPref & V>(v, id, hashAdultContentPref)
}

export function isValidAdultContentPref<V>(v: V) {
return isValid<AdultContentPref & V>(v, id, hashAdultContentPref)
}

export interface ContentLabelPref {
$type?: $Type<'app.bsky.actor.defs', 'contentLabelPref'>
/** Which labeler does this preference apply to? If undefined, applies globally. */
Expand All @@ -248,10 +212,6 @@ export function validateContentLabelPref<V>(v: V) {
return validate<ContentLabelPref & V>(v, id, hashContentLabelPref)
}

export function isValidContentLabelPref<V>(v: V) {
return isValid<ContentLabelPref & V>(v, id, hashContentLabelPref)
}

export interface SavedFeed {
$type?: $Type<'app.bsky.actor.defs', 'savedFeed'>
id: string
Expand All @@ -270,10 +230,6 @@ export function validateSavedFeed<V>(v: V) {
return validate<SavedFeed & V>(v, id, hashSavedFeed)
}

export function isValidSavedFeed<V>(v: V) {
return isValid<SavedFeed & V>(v, id, hashSavedFeed)
}

export interface SavedFeedsPrefV2 {
$type?: $Type<'app.bsky.actor.defs', 'savedFeedsPrefV2'>
items: SavedFeed[]
Expand All @@ -289,10 +245,6 @@ export function validateSavedFeedsPrefV2<V>(v: V) {
return validate<SavedFeedsPrefV2 & V>(v, id, hashSavedFeedsPrefV2)
}

export function isValidSavedFeedsPrefV2<V>(v: V) {
return isValid<SavedFeedsPrefV2 & V>(v, id, hashSavedFeedsPrefV2)
}

export interface SavedFeedsPref {
$type?: $Type<'app.bsky.actor.defs', 'savedFeedsPref'>
pinned: string[]
Expand All @@ -310,10 +262,6 @@ export function validateSavedFeedsPref<V>(v: V) {
return validate<SavedFeedsPref & V>(v, id, hashSavedFeedsPref)
}

export function isValidSavedFeedsPref<V>(v: V) {
return isValid<SavedFeedsPref & V>(v, id, hashSavedFeedsPref)
}

export interface PersonalDetailsPref {
$type?: $Type<'app.bsky.actor.defs', 'personalDetailsPref'>
/** The birth date of account owner. */
Expand All @@ -330,10 +278,6 @@ export function validatePersonalDetailsPref<V>(v: V) {
return validate<PersonalDetailsPref & V>(v, id, hashPersonalDetailsPref)
}

export function isValidPersonalDetailsPref<V>(v: V) {
return isValid<PersonalDetailsPref & V>(v, id, hashPersonalDetailsPref)
}

export interface FeedViewPref {
$type?: $Type<'app.bsky.actor.defs', 'feedViewPref'>
/** The URI of the feed, or an identifier which describes the feed. */
Expand All @@ -360,10 +304,6 @@ export function validateFeedViewPref<V>(v: V) {
return validate<FeedViewPref & V>(v, id, hashFeedViewPref)
}

export function isValidFeedViewPref<V>(v: V) {
return isValid<FeedViewPref & V>(v, id, hashFeedViewPref)
}

export interface ThreadViewPref {
$type?: $Type<'app.bsky.actor.defs', 'threadViewPref'>
/** Sorting mode for threads. */
Expand All @@ -388,10 +328,6 @@ export function validateThreadViewPref<V>(v: V) {
return validate<ThreadViewPref & V>(v, id, hashThreadViewPref)
}

export function isValidThreadViewPref<V>(v: V) {
return isValid<ThreadViewPref & V>(v, id, hashThreadViewPref)
}

export interface InterestsPref {
$type?: $Type<'app.bsky.actor.defs', 'interestsPref'>
/** A list of tags which describe the account owner's interests gathered during onboarding. */
Expand All @@ -408,10 +344,6 @@ export function validateInterestsPref<V>(v: V) {
return validate<InterestsPref & V>(v, id, hashInterestsPref)
}

export function isValidInterestsPref<V>(v: V) {
return isValid<InterestsPref & V>(v, id, hashInterestsPref)
}

export type MutedWordTarget = 'content' | 'tag' | (string & {})

/** A word that the account owner has muted. */
Expand All @@ -438,10 +370,6 @@ export function validateMutedWord<V>(v: V) {
return validate<MutedWord & V>(v, id, hashMutedWord)
}

export function isValidMutedWord<V>(v: V) {
return isValid<MutedWord & V>(v, id, hashMutedWord)
}

export interface MutedWordsPref {
$type?: $Type<'app.bsky.actor.defs', 'mutedWordsPref'>
/** A list of words the account owner has muted. */
Expand All @@ -458,10 +386,6 @@ export function validateMutedWordsPref<V>(v: V) {
return validate<MutedWordsPref & V>(v, id, hashMutedWordsPref)
}

export function isValidMutedWordsPref<V>(v: V) {
return isValid<MutedWordsPref & V>(v, id, hashMutedWordsPref)
}

export interface HiddenPostsPref {
$type?: $Type<'app.bsky.actor.defs', 'hiddenPostsPref'>
/** A list of URIs of posts the account owner has hidden. */
Expand All @@ -478,10 +402,6 @@ export function validateHiddenPostsPref<V>(v: V) {
return validate<HiddenPostsPref & V>(v, id, hashHiddenPostsPref)
}

export function isValidHiddenPostsPref<V>(v: V) {
return isValid<HiddenPostsPref & V>(v, id, hashHiddenPostsPref)
}

export interface LabelersPref {
$type?: $Type<'app.bsky.actor.defs', 'labelersPref'>
labelers: LabelerPrefItem[]
Expand All @@ -497,10 +417,6 @@ export function validateLabelersPref<V>(v: V) {
return validate<LabelersPref & V>(v, id, hashLabelersPref)
}

export function isValidLabelersPref<V>(v: V) {
return isValid<LabelersPref & V>(v, id, hashLabelersPref)
}

export interface LabelerPrefItem {
$type?: $Type<'app.bsky.actor.defs', 'labelerPrefItem'>
did: string
Expand All @@ -516,10 +432,6 @@ export function validateLabelerPrefItem<V>(v: V) {
return validate<LabelerPrefItem & V>(v, id, hashLabelerPrefItem)
}

export function isValidLabelerPrefItem<V>(v: V) {
return isValid<LabelerPrefItem & V>(v, id, hashLabelerPrefItem)
}

/** A grab bag of state that's specific to the bsky.app program. Third-party apps shouldn't use this. */
export interface BskyAppStatePref {
$type?: $Type<'app.bsky.actor.defs', 'bskyAppStatePref'>
Expand All @@ -540,10 +452,6 @@ export function validateBskyAppStatePref<V>(v: V) {
return validate<BskyAppStatePref & V>(v, id, hashBskyAppStatePref)
}

export function isValidBskyAppStatePref<V>(v: V) {
return isValid<BskyAppStatePref & V>(v, id, hashBskyAppStatePref)
}

/** If set, an active progress guide. Once completed, can be set to undefined. Should have unspecced fields tracking progress. */
export interface BskyAppProgressGuide {
$type?: $Type<'app.bsky.actor.defs', 'bskyAppProgressGuide'>
Expand All @@ -560,10 +468,6 @@ export function validateBskyAppProgressGuide<V>(v: V) {
return validate<BskyAppProgressGuide & V>(v, id, hashBskyAppProgressGuide)
}

export function isValidBskyAppProgressGuide<V>(v: V) {
return isValid<BskyAppProgressGuide & V>(v, id, hashBskyAppProgressGuide)
}

/** A new user experiences (NUX) storage object */
export interface Nux {
$type?: $Type<'app.bsky.actor.defs', 'nux'>
Expand All @@ -584,7 +488,3 @@ export function isNux<V>(v: V) {
export function validateNux<V>(v: V) {
return validate<Nux & V>(v, id, hashNux)
}

export function isValidNux<V>(v: V) {
return isValid<Nux & V>(v, id, hashNux)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
import { HeadersMap, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { CID } from 'multiformats/cid'
import {
isValid as _isValid,
validate as _validate,
} from '../../../../lexicons'
import { validate as _validate } from '../../../../lexicons'
import { $Type, $Typed, is$typed as _is$typed, OmitKey } from '../../../../util'
import type * as AppBskyActorDefs from './defs'

const is$typed = _is$typed,
isValid = _isValid,
validate = _validate
const id = 'app.bsky.actor.getPreferences'

Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/client/types/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
import { HeadersMap, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { CID } from 'multiformats/cid'
import {
isValid as _isValid,
validate as _validate,
} from '../../../../lexicons'
import { validate as _validate } from '../../../../lexicons'
import { $Type, $Typed, is$typed as _is$typed, OmitKey } from '../../../../util'
import type * as AppBskyActorDefs from './defs'

const is$typed = _is$typed,
isValid = _isValid,
validate = _validate
const id = 'app.bsky.actor.getProfile'

Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/client/types/app/bsky/actor/getProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
import { HeadersMap, XRPCError } from '@atproto/xrpc'
import { ValidationResult, BlobRef } from '@atproto/lexicon'
import { CID } from 'multiformats/cid'
import {
isValid as _isValid,
validate as _validate,
} from '../../../../lexicons'
import { validate as _validate } from '../../../../lexicons'
import { $Type, $Typed, is$typed as _is$typed, OmitKey } from '../../../../util'
import type * as AppBskyActorDefs from './defs'

const is$typed = _is$typed,
isValid = _isValid,
validate = _validate
const id = 'app.bsky.actor.getProfiles'

Expand Down
Loading

0 comments on commit 6fa83af

Please sign in to comment.