Getting Started
@skyware/jetstream
is a utility library for consuming data from a Jetstream instance.
Setup
The Jetstream
class takes an object parameter with the following properties:
wantedCollections
: An array of collections to subscribe to events for. This can contain any collection name or wildcard strings such asapp.bsky.feed.*
to receive events for all collections whose name starts withapp.bsky.feed.
. If not provided or empty, you will receive events for all collections.wantedDids
: An array of DIDs to subscribe to events for. If not provided or empty, you will receive events for all DIDs.cursor
: The Unix timestamp in microseconds to start listening from. A cursor is included in every event emitted as thetime_us
property. If you don’t provide a cursor, the class will start listening from the most recent event.endpoint
: The subscription URL of the Jetstream instance to connect to. Defaults towss://jetstream.atproto.tools/subscribe
.
Handling events
Jetstream allows you to subscribe to a filtered feed of events related to specific collections. The Jetstream class has three useful methods for listening for commits:
- onCreate: Listen for new records created in a collection.
- onUpdate: Listen for updated records in a collection.
- onDelete: Listen for deleted records in a collection.
The class also emits broader events.
Using Jetstream over a direct Relay connection can help you save bandwidth and only receive the events you care about.
A Note on Types
When using method such as onCreate, the type of the event will be inferred from the collection name. However, you may encounter an error resulting in missing properties on the record object. Make sure that your tsconfig.json
has the following:
Event Reference
The Jetstream
class may emit the following events:
Update events
Event | Description |
---|---|
commit | Represents a commit to a user’s repository. |
identity | Represents a change to an account’s identity. Could be an updated handle, signing key, or PDS hosting endpoint. |
account | Represents a change to an account’s status. The account may be deactivated, suspended, or deleted. |
System events
Event | Description |
---|---|
open | Emitted when the websocket connection is opened. |
close | Emitted when the websocket connection is closed. |
error | Emitted when an error occurs while handling a message. |