Skip to content

Commit

Permalink
codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Dec 18, 2024
1 parent 3416201 commit 8e57a62
Show file tree
Hide file tree
Showing 193 changed files with 3,723 additions and 2,285 deletions.
48 changes: 46 additions & 2 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* GENERATED CODE - DO NOT MODIFY
*/
import { LexiconDoc, Lexicons } from '@atproto/lexicon'
import {
LexiconDoc,
Lexicons,
ValidationError,
ValidationResult,
} from '@atproto/lexicon'
import { $Typed, is$typed, maybe$typed } from './util'

export const schemaDict = {
ComAtprotoAdminDefs: {
Expand Down Expand Up @@ -10809,6 +10815,44 @@ export const schemaDict = {

export const schemas = Object.values(schemaDict)
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 }>(
v: unknown,
id: string,
hash: string,
requiredType: true,
): v is $Typed<V>
export function isValid<V extends { $type?: string }>(
v: unknown,
id: string,
hash: string,
requiredType?: boolean,
): v is V
export function isValid(
v: unknown,
id: string,
hash: string,
requiredType?: boolean,
) {
return (
(requiredType ? is$typed : maybe$typed)(v, id, hash) &&
validate(v, id, hash).success
)
}

export const ids = {
ComAtprotoAdminDefs: 'com.atproto.admin.defs',
ComAtprotoAdminDeleteAccount: 'com.atproto.admin.deleteAccount',
Expand Down Expand Up @@ -11018,4 +11062,4 @@ export const ids = {
ChatBskyModerationGetActorMetadata: 'chat.bsky.moderation.getActorMetadata',
ChatBskyModerationGetMessageContext: 'chat.bsky.moderation.getMessageContext',
ChatBskyModerationUpdateActorAccess: 'chat.bsky.moderation.updateActorAccess',
}
} as const
Loading

0 comments on commit 8e57a62

Please sign in to comment.