@vinerima/jetstream-types
v2.0.0
Published
Zod schemas and TypeScript types for Bluesky Jetstream events, generated from AT Protocol lexicon definitions.
Readme
@vinerima/jetstream-types
Zod schemas and TypeScript types for Bluesky Jetstream events, generated from official AT Protocol lexicon definitions.
Installation
npm install @vinerima/jetstream-typesRequires zod v4 as a peer dependency.
Usage
Validate a Jetstream post create event
import { jetstreamPostCreateSchema, jetstreamToPost } from "@vinerima/jetstream-types";
const parsed = jetstreamPostCreateSchema.parse(rawMessage);
const post = jetstreamToPost(parsed);Validate any collection's commit events
import {
jetstreamCommitCreateSchema,
jetstreamCommitDeleteSchema,
} from "@vinerima/jetstream-types";
// Typed by collection — record field is fully typed
const likeCreate = jetstreamCommitCreateSchema("app.bsky.feed.like").parse(raw);
// likeCreate.commit.record is { $type: "app.bsky.feed.like", subject: {...}, createdAt: string }
const followCreate = jetstreamCommitCreateSchema("app.bsky.graph.follow").parse(raw);
// followCreate.commit.record is { $type: "app.bsky.graph.follow", subject: string, createdAt: string }
// Delete events have no record field
const deleted = jetstreamCommitDeleteSchema.parse(raw);Validate identity and account events
import { jetstreamIdentitySchema, jetstreamAccountSchema } from "@vinerima/jetstream-types";
const identity = jetstreamIdentitySchema.parse(raw);
const account = jetstreamAccountSchema.parse(raw);Use record schemas standalone
import { appBskyFeedPost, appBskyActorProfile } from "@vinerima/jetstream-types";
const post = appBskyFeedPost.parse(record);
const profile = appBskyActorProfile.parse(record);Supported collections
| Collection | Schema |
|---|---|
| app.bsky.feed.post | appBskyFeedPost |
| app.bsky.feed.like | appBskyFeedLike |
| app.bsky.feed.repost | appBskyFeedRepost |
| app.bsky.feed.threadgate | appBskyFeedThreadgate |
| app.bsky.feed.postgate | appBskyFeedPostgate |
| app.bsky.graph.follow | appBskyGraphFollow |
| app.bsky.graph.block | appBskyGraphBlock |
| app.bsky.graph.list | appBskyGraphList |
| app.bsky.graph.listitem | appBskyGraphListitem |
| app.bsky.graph.listblock | appBskyGraphListblock |
| app.bsky.actor.profile | appBskyActorProfile |
All record schemas include their transitive dependencies (embeds, facets, labels, strongRef, etc.).
Exports
Envelope schemas
jetstreamCommitCreateSchema(collection)-- typed commit create envelope for a given collectionjetstreamCommitUpdateSchema(collection)-- typed commit update envelopejetstreamCommitDeleteSchema-- commit delete envelope (no record field)jetstreamIdentitySchema-- identity event envelopejetstreamAccountSchema-- account event envelope
Record schemas
All AT Protocol record types listed above, plus supporting types like comAtprotoRepoStrongRef, appBskyRichtextFacet, comAtprotoLabelDefsSelfLabels, embed schemas, etc.
Each schema has a corresponding TypeScript type export (PascalCase), e.g. AppBskyFeedPost, AppBskyFeedLike.
Utilities
collectionSchemas-- mapping from collection NSID string to its Zod record schemaCollectionNsid-- union type of all supported collection NSID stringsjetstreamToPost(msg)-- converts a post create event into a flatPostobjectPost-- interface withuri,cid,authorDid,text,rootUri,rootCid
Backward-compatible (v1)
jetstreamPostCreateSchema-- equivalent tojetstreamCommitCreateSchema("app.bsky.feed.post")JetstreamPostCreate-- inferred type
Regenerating schemas
Record schemas are generated from official AT Protocol lexicon JSON files. To regenerate after upstream changes:
pnpm codegen
pnpm buildThe codegen script fetches lexicons from the bluesky-social/atproto repository and outputs src/generated/lexicons.ts.
Breaking changes from v1
- The
embedfield onapp.bsky.feed.postis now a discriminated union of 5 specific embed types instead ofz.unknown(). Records with non-standard embed shapes will fail validation. - The
replyfield now uses the generatedcomAtprotoRepoStrongRefschema (structurally identical to the previous hand-written schema).
License
MIT
