skyfall 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c52f2f3c63530b1e032666c7bfb71ba0b0279bfe0128c7432b8e267f1e2f9e95
4
- data.tar.gz: 1c7e2e5cac7ec4f421be5c291a311dede53221150901a44418f01f7a6cdeae9e
3
+ metadata.gz: 2b953131060753aed24131f0ba3286a8d956d35c93d89b3400b2179b93cec3f7
4
+ data.tar.gz: 2227498a04c1a2611c905cd4a6a1b4bd7d12c7197154d266b9d94c36654225a0
5
5
  SHA512:
6
- metadata.gz: 1eb9556cbc363f6a9c2ae42d27dc9a4471a24f8e08f0b1b8046c131fe320b63de73498d839367f0fd89c3841b27877c53bc0a937b9eeed41ea486f05b55a38c3
7
- data.tar.gz: 9b61caf5cc63834efd8185622c435a9102b4a310f890a988fd029e9e691e80acf7527e0afc5e5fecde967c4f2de538559168d07a72a2af4dd9d5ef06cc16ab50
6
+ metadata.gz: 26d7ed43387432f24d6ac60081fd232973bc755f3d7afa99690814a31afc3b04fbf24be9d4964f6addfb94e3a419579d4d97e54e6b8f21372938ca259d1b4bb9
7
+ data.tar.gz: 51c8c92daba02ba2b48575323555fd9908cd9f6bb7f4a728a9cc027dedc4e39836a5db2a79df13263e33c6c793c5b3f69f29bb4532cdc8fdefbbade53ad73cbe
data/CHANGELOG.md CHANGED
@@ -1,9 +1,44 @@
1
- ## [0.7.1] - 2026-08-05
1
+ ## [0.8.0] – 2026-11-24
2
+
3
+ Added:
4
+
5
+ - added support for the Jetstream v2 API via `Skyfall::JetstreamV2` and related `Message` class family; `Skyfall::Jetstream` can also be used to connect to a v2 service, though it uses the `/subscribe` compatibility endpoint (`Skyfall::JetstreamV2` does not work with v1 services)
6
+ - added support for Zstd compression (`:compress => true`) in both Jetstream APIs
7
+ - added support for `:maxMessageSizeBytes` option in both Jetstream APIs
8
+ - added `#cursor` as an alias for `#seq` in `Message` classes
9
+ - added `#time_us` to `Skyfall::Firehose::Message`
10
+ - added `#rev` to `Skyfall::Jetstream::CommitMessage`
11
+ - `Skyfall::Jetstream` also accepts parameter names `dids` & `collections` as used in `Skyfall::JetstreamV2`
12
+ - added constants and symbol shortcodes for `app.bsky.actor.link`, `app.bsky.graph.referencelistoptout` and `app.bsky.actor.contentVisibilityDeclaration`
13
+
14
+ Changed:
15
+
16
+ - some stricter/improved validation in `Message` constructors and in parameter parsing
17
+ - don't reset `cursor` to nil when processing a `Skyfall::Firehose::InfoMessage`
18
+
19
+ Possibly breaking changes:
20
+
21
+ - when connecting to a Jetstream v2 service using `Skyfall::Jetstream` through the compatibility API, `#seq` and `#cursor` will now return a sequential number cursor from the `cursor` field instead of the `time_us` timestamp (both can be passed as the cursor when reconnecting)
22
+ - `Skyfall::Jetstream` and `Skyfall::JetstreamV2` will now reject `nil` and `[]` values passed as dids/collections/kinds filter
23
+
24
+ ## [0.7.2] – 2026-08-17
25
+
26
+ - bumped up Oxygene dependency (see below under 0.7.1) to 0.1, with a stricter dependency rule
27
+ - includes various performance improvements for Base 32 en/decoding, CID & CAR parsing
28
+ - commit message decoding can be around 30% faster
29
+ - un-deprecated `#path` in both `Operation` classes (marked deprecated in 0.7.0)
30
+ - added `#ops` as alias for `#operations` in all message classes
31
+ - fixed `CommitMessage#prev_data` throwing an error if `prevData` is nil
32
+ - updated Firehose message constructors to verify that required fields aren't nil (not only that they're present), and for `LabelsMessage` that `labels` is an array
33
+ - some minor optimizations
34
+ - added some unit tests
35
+
36
+ ## [0.7.1] – 2026-08-05
2
37
 
3
38
  - extracted `CID` and `CarArchive` to a new gem "oxygene"
4
39
  - added `CommitMessage#cid` as alias of `#commit`
5
40
 
6
- ## [0.7.0] - 2026-02-13
41
+ ## [0.7.0] – 2026-02-13
7
42
 
8
43
  The main change in this version is that inline [YARD documentation](https://rubydoc.info/gems/skyfall/) has been added. This was also a good opportunity to review some APIs and tweak some things in order to get Skyfall a bit closer to 1.0.
9
44
 
@@ -46,26 +81,26 @@ Additional validations and other changes:
46
81
  - fixed the `require`s config in some files so they can be loaded in any order
47
82
 
48
83
 
49
- ## [0.6.1] - 2026-01-08
84
+ ## [0.6.1] – 2026-01-08
50
85
 
51
86
  - added `:bsky_notif_declaration` shortcode for `app.bsky.notification.declaration` collection
52
87
  - throw error when trying to run two streams in one process (see b4a1514f5da28983205765e55724b5c4abe6c5e4 for details)
53
88
  - added protected `#send_data` and `#socket` methods in `Stream` for use in `Stream` subclasses (currently for the Tapfall gem)
54
89
  - added a way to customize headers sent when connecting in `Stream` subclasses through the `#request_headers` method
55
90
 
56
- ## [0.6.0] - 2025-06-25
91
+ ## [0.6.0] – 2025-06-25
57
92
 
58
93
  - significantly speeded up reading of events from the binary firehose (`Skyfall::Firehose`) – up to 4-5x faster than before
59
94
  - removed the `Skyfall::Stream.new` constructor deprecated in 0.5.0
60
95
 
61
- ## [0.5.1] - 2025-05-18
96
+ ## [0.5.1] – 2025-05-18
62
97
 
63
98
  - added support for the new `#sync` message type
64
99
  - added `#unknown?` helper in `Skyfall::Firehose::Message` and `Skyfall::Jetstream::Message`, which returns true if the message type is `UnknownMessage`
65
100
  - added `:bsky_verification` and `:bsky_actor_status` lexicon type and shortcode
66
101
  - added one missing require
67
102
 
68
- ## [0.5.0] - 2024-11-15
103
+ ## [0.5.0] – 2024-11-15
69
104
 
70
105
  Jetstream support! You can now connect to [Jetstream](https://github.com/bluesky-social/jetstream) sources using `Skyfall::Jetstream` (see readme).
71
106
 
@@ -80,17 +115,17 @@ In most cases, you should only need to update the `Skyfall::Stream` class name i
80
115
 
81
116
  Also, small change to the user agent API: `Skyfall::Stream` now has an additional metod `version_string`, which will always return `Skyfall/0.x.y` – it's recommended to use that instead of `default_user_agent` to build your own user agent string that includes the library version. `default_user_agent` now passes through to `version_string`, but it could be changed in future to return something else.
82
117
 
83
- ## [0.4.1] - 2024-10-04
118
+ ## [0.4.1] – 2024-10-04
84
119
 
85
120
  - performance fix – don't decode CAR sections which aren't needed, which is most of them; this cuts the amount of memory that GC has to free up by about one third, and should speed up processing by around ~10%
86
121
 
87
- ## [0.4.0] - 2024-09-23
122
+ ## [0.4.0] – 2024-09-23
88
123
 
89
124
  - (re)added a "hearbeat" feature (removed earlier in 0.2.0) to fix the occasional issue when the websocket stops receiving data, but doesn't disconnect (not enabled by default, turn it on by setting `check_heartbeat` to true)
90
125
  - added a way to set the user agent sent when connecting using the `user_agent` field (default is `"Skyfall/#{version}"`)
91
126
  - added `app.bsky.feed.postgate` record type
92
127
 
93
- ## [0.3.1] - 2024-06-28
128
+ ## [0.3.1] – 2024-06-28
94
129
 
95
130
  - added `app.bsky.graph.starterpack` and `chat.bsky.actor.declaration` record types
96
131
  - added `#account` event type (`AccountMessage`)
@@ -98,7 +133,7 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
98
133
  - fixed param validation on `Stream` initialization
99
134
  - reverted the change that added Ruby stdlib dependencies explicitly to the gemspec, since this causes more problems than it's worth – only `base64` is left there, since it's the one now required to be listed
100
135
 
101
- ## [0.3.0] - 2024-03-21
136
+ ## [0.3.0] – 2024-03-21
102
137
 
103
138
  - added support for labeller firehose, served by labeller services at the `com.atproto.label.subscribeLabels` endpoint (aliased as `:subscribe_labels`)
104
139
  - the `#labels` messages from the labeller firehose are parsed into a `LabelsMessage`, which includes a `labels` array of `Label` objects
@@ -106,11 +141,11 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
106
141
  - added default error handler to `Stream` which logs the error to `$stdout` – set `stream.on_error = nil` to disable
107
142
  - added Ruby stdlib dependencies explicitly to the gemspec – fixes a warning in Ruby 3.3 when requiring `base64`, which will be extracted as an optional gem in 3.4
108
143
 
109
- ## [0.2.5] - 2024-03-14
144
+ ## [0.2.5] – 2024-03-14
110
145
 
111
146
  - added `:bsky_labeler` record type symbol & collection constant
112
147
 
113
- ## [0.2.4] - 2024-02-27
148
+ ## [0.2.4] – 2024-02-27
114
149
 
115
150
  - added support for `#identity` message type
116
151
  - added `Operation#did` as an alias of `#repo`
@@ -119,24 +154,24 @@ Also, small change to the user agent API: `Skyfall::Stream` now has an additiona
119
154
  - the `server` parameter in `Stream` initializer can be a full URL with scheme, which lets you connect to e.g. `ws://localhost` (since by default, `wss://` is used)
120
155
  - tweaked `#inspect` output of `Stream` and `Operation`
121
156
 
122
- ## [0.2.3] - 2023-09-28
157
+ ## [0.2.3] – 2023-09-28
123
158
 
124
159
  - fixed encoding of image CIDs again (they should be wrapped in a `$link` object)
125
160
  - binary strings are now correctly returned as `$bytes` objects
126
161
  - added `list`, `listblock` and `threadgate` to record type symbols and collection constants
127
162
 
128
- ## [0.2.2] - 2023-09-06
163
+ ## [0.2.2] – 2023-09-06
129
164
 
130
165
  - fixed image CIDs returned in the record JSON as CBOR tag objects (they are now returned decoded to the string form)
131
166
 
132
- ## [0.2.1] - 2023-08-19
167
+ ## [0.2.1] – 2023-08-19
133
168
 
134
169
  - optimized `WebsocketMessage` parsing performance – lazy parsing of most properties (message decoding should be over 50% faster on average)
135
170
  - added separate subclasses of `WebsocketMessage` for different message types
136
171
  - added support for `#handle`, `#info` and `#tombstone` message types
137
172
  - `UnknownMessage` is returned for unrecognized message types
138
173
 
139
- ## [0.2.0] - 2023-07-24
174
+ ## [0.2.0] – 2023-07-24
140
175
 
141
176
  - switched the websocket library from `websocket-client-simple` to `faye-websocket`, which should make event parsing up to ~30× faster (!)
142
177
  - added `auto_reconnect` property to `Stream` (on by default) – if true, it will try to reconnect with an exponential backoff when the websocket disconnects, until you call `Stream#disconnect`
@@ -147,7 +182,7 @@ Note:
147
182
  - the disconnect event no longer passes an error object in the argument
148
183
  - there is currently no "heartbeat" feature as in 0.1.x that checks for a stuck connection – but it doesn't seem to be needed
149
184
 
150
- ## [0.1.3] - 2023-07-04
185
+ ## [0.1.3] – 2023-07-04
151
186
 
152
187
  - allow passing a previously saved cursor to websocket to replay any missed events
153
188
  - the cursor is also kept in memory and automatically used when reconnecting
@@ -155,19 +190,19 @@ Note:
155
190
  - fixed connecting to websocket when endpoint is given as a string
156
191
  - improved error handling during parsing
157
192
 
158
- ## [0.1.2] - 2023-06-15
193
+ ## [0.1.2] – 2023-06-15
159
194
 
160
195
  - added rkey property for Operation
161
196
 
162
- ## [0.1.1] - 2023-06-13
197
+ ## [0.1.1] – 2023-06-13
163
198
 
164
199
  - added heartbeat thread to restart websocket if it stops responding
165
200
 
166
- ## [0.1.0] - 2023-06-01
201
+ ## [0.1.0] – 2023-06-01
167
202
 
168
203
  - connecting to the firehose websocket
169
204
 
170
- ## [0.0.1] - 2023-05-31
205
+ ## [0.0.1] – 2023-05-31
171
206
 
172
207
  Initial release:
173
208
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ A Ruby gem for streaming data from the Bluesky/ATProto firehose 🦋
12
12
 
13
13
  Skyfall is a Ruby library for connecting to the *"[firehose](https://atproto.com/specs/event-stream)"* of the Bluesky social network, i.e. a websocket which streams all new posts and everything else happening on the Bluesky network in real time. The code connects to the websocket endpoint, decodes the messages which are encoded in some binary formats like DAG-CBOR, and returns the data as Ruby objects, which you can filter and save to some kind of database (e.g. in order to create a custom feed).
14
14
 
15
- Since version 0.5, Skyfall also supports connecting to [Jetstream](https://github.com/bluesky-social/jetstream/) sources, which serve the same kind of stream, but as JSON messages instead of CBOR.
15
+ Since version 0.5, Skyfall also supports connecting to [Jetstream](https://github.com/bluesky-social/jetstream/) sources, which serve the same kind of stream, but as JSON messages instead of CBOR. Jetstream v2 API is supported since version 0.8.
16
16
 
17
17
 
18
18
  ## Installation
@@ -25,22 +25,25 @@ To install the gem, run the command:
25
25
 
26
26
  Or add this to your app's `Gemfile`:
27
27
 
28
- gem 'skyfall', '~> 0.6'
28
+ gem 'skyfall', '~> 0.8'
29
29
 
30
30
 
31
31
  ## Usage
32
32
 
33
33
  ### Standard ATProto firehose
34
34
 
35
- To connect to the firehose, start by creating a `Skyfall::Firehose` object, specifying the server hostname and endpoint name:
35
+ To connect to the firehose, start by creating a `Skyfall::Firehose` object, specifying the server hostname and optionally an endpoint name:
36
36
 
37
37
  ```rb
38
38
  require 'skyfall'
39
39
 
40
40
  sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos)
41
+
42
+ # or (:subscribe_repos is the default)
43
+ sky = Skyfall::Firehose.new('bsky.network')
41
44
  ```
42
45
 
43
- The server name can be just a hostname, or a full URL with a `ws:` or `wss:` scheme, which is useful if you want to use a non-encrypted websocket connection, e.g. `"ws://localhost:8000"`. The endpoint can be either a full NSID string like `"com.atproto.sync.subscribeRepos"`, or one of the defined symbol shortcuts – you will almost always want to pass `:subscribe_repos` here.
46
+ The server name can be just a hostname, or a full URL with a `ws:` or `wss:` scheme, which is useful if you want to use a non-encrypted websocket connection, e.g. `"ws://localhost:8000"`. The endpoint can be either a full NSID string like `"com.atproto.sync.subscribeRepos"`, or one of the defined symbol shortcuts – you will almost always want to use `:subscribe_repos`.
44
47
 
45
48
  Next, set up event listeners to handle incoming messages and get notified of errors. Here are all the available listeners (you will need at least either `on_message` or `on_raw_message`):
46
49
 
@@ -81,10 +84,16 @@ The `#connect` method blocks until the connection is explicitly closed with `#di
81
84
 
82
85
  Alternatively, you can connect to a [Jetstream](https://github.com/bluesky-social/jetstream/) server. Jetstream is a firehose proxy that lets you stream data as simple JSON instead, which uses much less bandwidth, and allows you to pick only a subset of events that you're interested in, e.g. only posts or only from specific accounts. (See the [configuration section](#jetstream-filters) for more info on Jetstream filtering.)
83
86
 
84
- Jetstream connections are made using a `Skyfall::Jetstream` instance, which has more or less the same API as `Skyfall::Firehose`, so it should be possible to switch between those by just changing the line that creates the client instance:
87
+ There are two different versions of Jetstream:
88
+
89
+ * the [original Jetstream](https://github.com/bluesky-social/jetstream-legacy/) (v1); most community-run [Jetstream instances](https://pulsar.feeds.blue) out there are running this version. Use the `Skyfall::Jetstream` class to connect to those.
90
+ * the [Jetstream v2](https://github.com/bluesky-social/jetstream/), which uses a slightly different JSON structure, keeps a complete historical archive, and has APIs for backfilling historical data (not supported in Skyfall yet). Use the `Skyfall::JetstreamV2` class to connect to v2 instances, although `Skyfall::Jetstream` can also be used to connect to the v1 compatibility API. `Skyfall::JetstreamV2` will not work with v1 instances.
91
+
92
+ Both `Skyfall::Jetstream` and `Skyfall::JetstreamV2` have intentionally the same API as `Skyfall::Firehose` as much as possible:
85
93
 
86
94
  ```rb
87
- sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network')
95
+ sky = Skyfall::Jetstream.new('frankfurt.firehose.stream')
96
+ sky2 = Skyfall::JetstreamV2.new('jetstream.us-east.bsky.network')
88
97
 
89
98
  sky.on_message { |msg| ... }
90
99
  sky.on_error { |e| ... }
@@ -96,30 +105,49 @@ sky.connect
96
105
 
97
106
  ### Cursors
98
107
 
99
- ATProto websocket endpoints implement a "*cursor*" feature to help you make sure that you don't miss anything if your connection is down for a bit (because of a network issue, server restart, deploy etc.). Each message includes a `seq` field, which is the sequence number of the event. You can keep track of the last seq you've seen, and when you reconnect, you pass that number as a cursor parameter – the server will then "replay" all events you might have missed since that last one. (The `bsky.network` Relay firehose currently has a buffer of about 72 hours, though that's not something required by specification.)
108
+ ATProto websocket endpoints implement a "*cursor*" feature to help you make sure that you don't miss anything if your connection is down for a bit (because of a network issue, server restart, deploy etc.). Each message includes a `seq` field, which is the sequence number of the event. You can keep track of the last seq you've seen, and when you reconnect, you pass that number as a cursor parameter – the server will then "replay" all events you might have missed since that last one. (Different relay and Jetstream servers have differently sized replay buffers depending on configuration, usually between 24 and 72 hours.)
100
109
 
101
- To use a cursor when connecting to the firehose, pass it as the third parameter to `Skyfall::Firehose`. You should then regularly save the `seq` of the last event to some permanent storage, and then load it from there when reconnecting.
110
+ To use a cursor when connecting to the CBOR firehose, pass it as the third (or second) parameter to `Skyfall::Firehose`. You should then regularly save the `seq` of the last event (also aliased as `cursor`) to some permanent storage, and then load it from there when reconnecting.
102
111
 
103
112
  A full-network firehose sends many hundreds of events per second, so depending on your use case, it might be enough if you save it every n events (e.g. every 100 or 1000) and on clean shutdown:
104
113
 
105
114
  ```rb
106
115
  cursor = load_cursor
107
116
 
108
- sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos, cursor)
117
+ sky = Skyfall::Firehose.new('bsky.network', cursor)
118
+
109
119
  sky.on_message do |msg|
110
- save_cursor(msg.seq) if msg.seq % 1000 == 0
120
+ save_cursor(msg.cursor) if msg.cursor % 1000 == 0
111
121
  process_message(msg)
112
122
  end
113
123
  ```
114
124
 
115
- Jetstream has a similar mechanism, except the cursor is the event's timestamp in Unix time microseconds instead of just a number incrementing by 1. For `Skyfall::Jetstream`, pass the cursor as a key in an options hash:
125
+ Jetstream has a similar mechanism, except the cursor works a bit differently depending on the Jetstream client and server version:
126
+
127
+ * v1 servers include a `time_us` field, which is the Unix timestamp of the event in microseconds, which acts as a cursor. For a v1 service, `seq` and `cursor` methods in `Skyfall::Jetstream::Message` will both return this value.
128
+ * v2 servers include a `seq` field with a sequential number cursor like in the CBOR firehose. `seq` / `cursor` methods in `Skyfall::JetstreamV2::Message` return this sequential cursor value. For symmetry with `Skyfall::Jetstream::Message`, a `time_us` method is also provided here that returns the event time in microseconds.
129
+ * when a v1 client (`Skyfall::Jetstream`) connects to a v2 service, it uses a special v1 compatibility API there. In that API, the responses have a v1 JSON shape, *except* they also include a sequential cursor in a `cursor` field. In that case, `Skyfall::Jetstream::Message` will have a `time_us` with the timestamp field, but `seq` & `cursor` return that sequential cursor.
130
+ * in both APIs on a v2 service, either the sequential or the timestamp cursor can be passed when reconnecting.
131
+ * to simplify, in any combination of client and server API you can record & reuse the value returned from `message.cursor` and it should be accepted by the same server. You might need to take some more care with the cursor when switching between different instances.
132
+
133
+ Here's a table showing all combinations:
134
+
135
+ | | `seq` | `cursor` | `time_us` | `time` |
136
+ |---------------------|-------------------|-------------------|------------------|----------------------|
137
+ | CBOR firehose | seq cursor | seq cursor | `time` in µs | built from `time` |
138
+ | Jetstream v1 | timestamp cursor | timestamp cursor | timestamp cursor | built from `time_us` |
139
+ | v1 compat API on v2 | seq cursor | seq cursor | timestamp cursor | built from `time_us` |
140
+ | Jetstream v2 | seq cursor | seq cursor | `time` in µs | built from `time` |
141
+
142
+ For any cursor and Jetstream client version, you pass the cursor as a key in an options hash:
116
143
 
117
144
  ```rb
118
145
  cursor = load_cursor
119
146
 
120
- sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network', { cursor: cursor })
147
+ sky = Skyfall::Jetstream.new('london.firehose.stream', { cursor: cursor })
148
+
121
149
  sky.on_message do |msg|
122
- save_cursor(msg.seq)
150
+ save_cursor(msg.cursor) unless msg.cursor.nil?
123
151
  process_message(msg)
124
152
  end
125
153
  ```
@@ -127,7 +155,7 @@ end
127
155
 
128
156
  ### Processing messages
129
157
 
130
- Each message passed to `on_message` is an instance of a subclass of either `Skyfall::Firehose::Message` or `Skyfall::Jetstream::Message`, depending on the selected source. The supported message types are:
158
+ Each message passed to `on_message` is an instance of a subclass of `Skyfall::Firehose::Message`, `Skyfall::Jetstream::Message`, or `Skyfall::JetstreamV2::Message`, depending on the selected source. For the CBOR firehose, the supported message types are:
131
159
 
132
160
  - `CommitMessage` (`#commit`) – represents a change in a user's repo; most messages are of this type
133
161
  - `IdentityMessage` (`#identity`) – notifies about a change in user's DID document, e.g. a handle change or a migration to a new PDS
@@ -137,36 +165,46 @@ Each message passed to `on_message` is an instance of a subclass of either `Skyf
137
165
  - `InfoMessage` (`#info`) – a protocol error message, e.g. about an invalid cursor parameter
138
166
  - `UnknownMessage` is used for other unrecognized message types
139
167
 
140
- `Skyfall::Firehose::Message` and `Skyfall::Jetstream::Message` variants of message classes should have more or less the same interface, except when a given field is not included in one of the formats.
168
+ `Skyfall::Jetstream` and `Skyfall::JetstreamV2` have their own message class families which mirror these and have more or less the same interface, except when a given field or message type is not included in one of the formats:
169
+
170
+ - Jetstream has: `AccountMessage`, `CommitMessage`, `IdentityMessage` and `UnknownMessage`
171
+ - JetstreamV2 has: `AccountMessage`, `CommitMessage`, `IdentityMessage`, `SyncMessage`, `InfoMessage` and `UnknownMessage`
141
172
 
142
173
  All message objects have the following shared properties:
143
174
 
144
- - `type` (symbol) – the message type identifier, e.g. `:commit`
145
- - `seq` (integer) – a sequential index of the message; Jetstream messages instead have a `time_us` value, which is a Unix timestamp in microseconds (also aliased as `seq` for compatibility)
175
+ - `type` or `kind` (symbol) – the message type identifier, e.g. `:commit`
176
+ - `seq` or `cursor` (integer) – the cursor value to pass when reconnecting; either a sequential index of the message, or a Unix timestamp in microseconds for Jetstream v1 servers
146
177
  - `repo` or `did` (string) – DID of the repository (user account)
147
178
  - `time` (Time) – timestamp of the described action
179
+ - `time_us` (integer) – timestamp in Unix microseconds (for Jetstream v1/v2 can be used as a cursor)
148
180
 
149
181
  All properties except `type` may be nil for some message types that aren't related to a specific user, like `#info`.
150
182
 
151
- Commit messages additionally have:
183
+ Commit messages additionally include (depending on the version):
152
184
 
153
- - `commit` – CID of the commit
154
- - `operations` – list of operations (usually one)
185
+ - `commit` or `cid` – CID of the commit
186
+ - `operations` or `ops` – list of operations (usually one for CBOR, always one for Jetstream)
187
+ - `operation` or `op` – in Jetstream only
188
+ - `rev` – current revision identifier of the repo
189
+ - `since` – revision of the previous commit
190
+ - `blocks` – commit data as a parsed CAR archive
155
191
 
156
- Handle and Identity messages additionally have:
192
+ Identity messages additionally include:
157
193
 
158
194
  - `handle` – the new handle assigned to the DID
159
195
 
160
- Account messages additionally have:
196
+ Account messages additionally include:
161
197
 
162
198
  - `active?` – whether the account is active, or inactive for any reason
163
199
  - `status` – if not active, shows the status of the account (`:deactivated`, `:deleted`, `:takendown`)
164
200
 
165
- Info messages additionally have:
201
+ Info messages additionally include:
166
202
 
167
203
  - `name` – identifier of the message/error
168
204
  - `message` – a human-readable description
169
205
 
206
+ See the [YARD API docs](https://rubydoc.info/gems/skyfall/) for more details on what specific message classes are available and what fields each one has.
207
+
170
208
 
171
209
  ### Commit operations
172
210
 
@@ -213,7 +251,7 @@ Do not however check if such operations have a `type` equal to `:unknown` first
213
251
 
214
252
  ## Reconnection logic
215
253
 
216
- In a perfect world, the websocket would never disconnect until you disconnect it, but unfortunately we don't live in a perfect world. The socket sometimes disconnects or stops responding, and Skyfall has some built-in protections to make sure it can operate without much oversight.
254
+ In a perfect world, the websocket would never disconnect until you disconnect it, but unfortunately we don't live in a perfect world. The socket sometimes disconnects or stops responding, and Skyfall has some built-in protections to make sure it can operate without much oversight. (This section applies to all three stream types.)
217
255
 
218
256
 
219
257
  ### Broken connections
@@ -252,7 +290,9 @@ To connect to a labeller, pass `:subscribe_labels` as the endpoint name to `Skyf
252
290
 
253
291
  ```rb
254
292
  cursor = load_cursor(service)
293
+
255
294
  sky = Skyfall::Firehose.new(service, :subscribe_labels, cursor)
295
+
256
296
  sky.on_message do |msg|
257
297
  if msg.type == :labels
258
298
  msg.labels.each do |l|
@@ -279,12 +319,12 @@ sky.user_agent = "NewsBot (@news.bot) #{sky.version_string}"
279
319
 
280
320
  ### Jetstream filters
281
321
 
282
- Jetstream allows you to specify [filters](https://github.com/bluesky-social/jetstream?tab=readme-ov-file#consuming-jetstream) of collection types and/or tracked DIDs when you connect, so it will send you only the events you're interested in. You can e.g. ask only for posts and ignore likes, or only profile events and ignore everything else, or only listen for posts from a few specific accounts.
322
+ Jetstream allows you to specify [filters](https://bsky.network/docs/jetstream#filtering-ask-for-just-your-slice) of collection types and/or tracked DIDs when you connect, so it will send you only the events you're interested in. You can e.g. ask only for posts and ignore likes, or only profile events and ignore everything else, or only listen for posts from a few specific accounts.
283
323
 
284
- To use these filters, pass the "wantedCollections" and/or "wantedDids" parameters in the options hash when initializing `Skyfall::Jetstream`. You can use the original JavaScript param names, or a more Ruby-like snake_case form:
324
+ To use these filters, pass the "wantedCollections" and/or "wantedDids" parameters in the options hash when initializing `Skyfall::Jetstream`. You can use the original JavaScript param names, or a more Ruby-like snake_case form, with a single value or an array:
285
325
 
286
326
  ```rb
287
- sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network', {
327
+ sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
288
328
  wanted_collections: 'app.bsky.feed.post',
289
329
  wanted_dids: @dids
290
330
  })
@@ -293,15 +333,79 @@ sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network', {
293
333
  For collections, you can also use the symbol codes used in `Operation#type`, e.g. `:bsky_post`:
294
334
 
295
335
  ```rb
296
- sky = Skyfall::Jetstream.new('jetstream2.us-east.bsky.network', {
336
+ sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
297
337
  wanted_collections: [:bsky_post]
298
338
  })
299
339
  ```
300
340
 
301
- See [Jetstream docs](https://github.com/bluesky-social/jetstream?tab=readme-ov-file#consuming-jetstream) for more info on available filters.
341
+ The parameters are named `collections` and `dids` respectively in the Jetstream v2 API, but you can use any variant in either of the client versions here.
342
+
343
+ Jetstream v2 additionally allows you to filter by event kinds. Pass one or more event types as the `kinds` option – note that `collections` can be combined with `kinds`, but only if `kinds` includes `commit`:
344
+
345
+ ```rb
346
+ sky = Skyfall::JetstreamV2.new('jetstream.us-east.bsky.network', {
347
+ collections: [:bsky_post, :bsky_like],
348
+ kinds: [:commit, :identity]
349
+ })
350
+ ```
351
+
352
+ See [Jetstream docs](https://bsky.network/docs/jetstream#filtering-ask-for-just-your-slice) for more info on available filters.
302
353
 
303
354
  > [!NOTE]
304
- > The `compress` and `requireHello` options (and zstd compression) are not available at the moment. Also the "subscriber sourced messages" aren't implemented yet.
355
+ > The `requireHello` option and "subscriber sourced messages" from the Jetstream v1 aren't currently supported (and probably won't be).
356
+
357
+
358
+ ### Jetstream compression
359
+
360
+ Both Jetstream v1 and v2 support optional Zstd compression (off by default), using a pre-shared compression dictionary. For Jetstream v1 there is a single hardcoded dictionary, for v2 the currently used dictionary is fetched from the server before making a connection.
361
+
362
+ In both versions, enable compression by adding a `compress: true` option:
363
+
364
+ ```rb
365
+ sky = Skyfall::Jetstream.new('nyc.firehose.stream', {
366
+ wanted_collections: [:bsky_post],
367
+ compress: true
368
+ })
369
+ ```
370
+
371
+ The decompression and dictionary handling happens automatically. Note that if compression is enabled, `on_raw_message` callbacks will receive the original compressed message bytes; `on_message` receives a parsed `Message` object as before.
372
+
373
+
374
+ ### Jetstream message size limit
375
+
376
+ Another Jetstream option is `maxMessageSizeBytes`, available in both v1 and v2, which sets a limit in bytes on how large events will be sent to the client; events larger than the limit are silently dropped.
377
+
378
+ Note: when compression is also enabled, the value is interpreted differently in Jetstream v1 and v2:
379
+
380
+ * Jetstream v1 uses the value as the max *compressed* event size
381
+ * Jetstream v2 servers, including the v1 compatibility API, use the value as the max *uncompressed* event size
382
+
383
+ Pass the limit as a number in bytes to `:maxMessageSizeBytes` or `:max_message_size_bytes` (0 will be interpreted as no limit):
384
+
385
+ ```rb
386
+ sky = Skyfall::Jetstream.new('nyc.firehose.stream', { max_message_size_bytes: 1_000_000 })
387
+ ```
388
+
389
+ ## Available servers
390
+
391
+ Bluesky PBC currently runs these official firehose and Jetstream servers:
392
+
393
+ Relay:
394
+
395
+ - `bsky.network`
396
+
397
+ Jetstream v2:
398
+
399
+ - `jetstream.us-west.bsky.network`
400
+ - `jetstream.us-east.bsky.network`
401
+
402
+ The ATProto developer community is running a number of independent relays and Jetstream v1 instances, including:
403
+
404
+ - the [firehose.network](https://firehose.network) relays and [firehose.stream](https://firehose.stream) Jetstream servers run by [@sri.xyz](https://bsky.app/profile/did:plc:7gm5ejhut7kia2kzglqfew5b)
405
+ - the [Microcosm relays](https://www.microcosm.blue/#infra) run by [@bad-example.com](https://bsky.app/profile/did:plc:hdhoaan3xa3jiuq4fg4mefid)
406
+ - the [Blacksky](https://blackskyweb.xyz) and [Eurosky](https://eurosky.tech) infrastructure
407
+
408
+ I'm running a tool named [Pulsar](https://pulsar.feeds.blue) at [pulsar.feeds.blue](https://pulsar.feeds.blue) which lists all of those and more, and tracks their uptime and network coverage statistics.
305
409
 
306
410
 
307
411
  ## Other resources
data/SECURITY.md ADDED
@@ -0,0 +1,16 @@
1
+ # Security Policy
2
+
3
+ ## How To Report a Vulnerability
4
+
5
+ If you find a potential vulnerability in one of my projects, it's recommended not to report it through a standard publicly-readable issue report, in order to avoid giving possible clues to any potential attackers who could abuse it before it's fixed (see: ["Just a rumour of a bug is enough to find a security exploit these days"](https://anil.recoil.org/notes/rumour-is-the-exploit)).
6
+
7
+ You can use one of these to contact me instead:
8
+
9
+ - [@mackuba.eu](https://bsky.app/profile/did:plc:oio4hkxaop4ao4wz2pp3f4cr) on Bluesky (my DMs should be open, or mention me discretely with a request for contact)
10
+ - [@mackuba@martianbase.net](https://martianbase.net/@mackuba) on Mastodon (my personal instance)
11
+ - email: mackuba `@` protonmail.ch (optionally with [this PGP key](https://mail-api.proton.me/pks/lookup?op=get&search=mackuba@protonmail.ch))
12
+ - ["Report a vulnerability"](https://github.com/mackuba/skyfall/security/advisories/new) form on GitHub
13
+
14
+ I do not check my Twitter/X or LinkedIn accounts regularly.
15
+
16
+ Note: please don't submit AI-reported issues that have not been verified manually :)
Binary file
@@ -9,6 +9,7 @@ module Skyfall
9
9
  #
10
10
 
11
11
  module Collection
12
+ BSKY_ACTOR_LINK = "app.bsky.actor.link"
12
13
  BSKY_PROFILE = "app.bsky.actor.profile"
13
14
  BSKY_ACTOR_STATUS = "app.bsky.actor.status"
14
15
  BSKY_FEED = "app.bsky.feed.generator"
@@ -22,16 +23,20 @@ module Skyfall
22
23
  BSKY_LIST = "app.bsky.graph.list"
23
24
  BSKY_LISTBLOCK = "app.bsky.graph.listblock"
24
25
  BSKY_LISTITEM = "app.bsky.graph.listitem"
26
+ BSKY_LIST_OPTOUT = "app.bsky.graph.referencelistoptout"
25
27
  BSKY_STARTERPACK = "app.bsky.graph.starterpack"
26
28
  BSKY_VERIFICATION = "app.bsky.graph.verification"
27
29
  BSKY_LABELER = "app.bsky.labeler.service"
28
30
 
29
31
  BSKY_NOTIF_DECLARATION = "app.bsky.notification.declaration"
30
32
  BSKY_CHAT_DECLARATION = "chat.bsky.actor.declaration"
33
+ BSKY_VISIBILITY_DECLARATION = "app.bsky.actor.contentVisibilityDeclaration"
34
+
31
35
 
32
36
  # Mapping of NSID collection names to symbol short codes
33
37
 
34
38
  SHORT_CODES = {
39
+ BSKY_ACTOR_LINK => :bsky_actor_link,
35
40
  BSKY_ACTOR_STATUS => :bsky_actor_status,
36
41
  BSKY_BLOCK => :bsky_block,
37
42
  BSKY_FEED => :bsky_feed,
@@ -41,6 +46,7 @@ module Skyfall
41
46
  BSKY_LIST => :bsky_list,
42
47
  BSKY_LISTBLOCK => :bsky_listblock,
43
48
  BSKY_LISTITEM => :bsky_listitem,
49
+ BSKY_LIST_OPTOUT => :bsky_list_optout,
44
50
  BSKY_POST => :bsky_post,
45
51
  BSKY_POSTGATE => :bsky_postgate,
46
52
  BSKY_PROFILE => :bsky_profile,
@@ -49,7 +55,8 @@ module Skyfall
49
55
  BSKY_THREADGATE => :bsky_threadgate,
50
56
  BSKY_VERIFICATION => :bsky_verification,
51
57
  BSKY_CHAT_DECLARATION => :bsky_chat_declaration,
52
- BSKY_NOTIF_DECLARATION => :bsky_notif_declaration
58
+ BSKY_NOTIF_DECLARATION => :bsky_notif_declaration,
59
+ BSKY_VISIBILITY_DECLARATION => :bsky_visibility_declaration
53
60
  }
54
61
 
55
62
  # Returns a symbol short code for a given collection NSID, or `:unknown`
@@ -19,6 +19,12 @@ module Skyfall
19
19
  class DecodeError < Error
20
20
  end
21
21
 
22
+ #
23
+ # Raised when the Zstd compression dictionary used for Jetstream can't be loaded or is invalid.
24
+ #
25
+ class DictionaryError < Error
26
+ end
27
+
22
28
  #
23
29
  # Raised when {Stream#connect} is called and there's already another instance of {Stream} or its
24
30
  # subclass like {Firehose} that's connected to another websocket.
@@ -40,7 +40,7 @@ module Skyfall
40
40
 
41
41
  # @return [Oxygene::CID, nil] CID (Content Identifier) of data of the previous commit in the repo
42
42
  def prev_data
43
- @prev_data ||= Oxygene::CID.from_cbor_tag(@data_object['prevData'])
43
+ @prev_data ||= @data_object['prevData'] && Oxygene::CID.from_cbor_tag(@data_object['prevData'])
44
44
  end
45
45
 
46
46
  # @return [Oxygene::CID] CID (Content Identifier) of the commit
@@ -60,11 +60,14 @@ module Skyfall
60
60
  @operations ||= @data_object['ops'].map { |op| Firehose::Operation.new(self, op) }
61
61
  end
62
62
 
63
+ alias ops operations
64
+
63
65
  # Looks up record data assigned to a given operation in the commit's CAR archive.
64
66
  # @param op [Firehose::Operation]
65
67
  # @return [Hash, nil]
66
68
  def raw_record_for_operation(op)
67
- op.cid && blocks.section_with_cid(op.cid)
69
+ cid = op.cid
70
+ cid && blocks.section_with_cid(cid, use_map: false, return_body: false)&.json_body
68
71
  end
69
72
  end
70
73
  end
@@ -45,7 +45,7 @@ module Skyfall
45
45
 
46
46
  # @return [String] a formatted summary
47
47
  def to_s
48
- (@name || "InfoMessage") + (@message ? ": #{@message}" : "")
48
+ @message ? "#{@name}: #{@message}" : @name
49
49
  end
50
50
 
51
51
  protected
@@ -28,7 +28,10 @@ module Skyfall
28
28
  super
29
29
  check_if_not_nil 'seq', 'labels'
30
30
 
31
- @labels = @data_object['labels'].map { |x| Label.new(x) }
31
+ label_data = @data_object['labels']
32
+ raise DecodeError.new("Invalid labels field") unless label_data.is_a?(Array)
33
+
34
+ @labels = label_data.map { |x| Label.new(x) }
32
35
  end
33
36
 
34
37
  protected