ratproto 0.3.1 → 0.3.2

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: 5f6ecf6b20c9235a6f792aedbe3d555e8387d788dbe1bb7e8ae65850a8de34b6
4
- data.tar.gz: 9f6b2dd26064ae1bc1ed8e854c2f0fd1c193672556e99c3ec78df5eab9ba50e9
3
+ metadata.gz: 7ba70d80557249c2c85eeb1e185f1cc0261800b4d3a0aa07f2cf6b777fdd512e
4
+ data.tar.gz: a722e3c61aca7f8827b682885fed4b7fddaef19eaa48b8d8635d82911dc489ff
5
5
  SHA512:
6
- metadata.gz: 0e0326c6bba6787261b88668a0a5877f0a68eaff5146bdfd769a404271f050f200decf652546855cadd2f9f8040190f4d26ff65e867fcb1e1bacbd3148237db8
7
- data.tar.gz: fee5cf28d9a8cf5a64dcf06fae08db2f467832c0ed56327010c31a3bb71c2e0159e2ec8cda2f14aa6df4848eba76751d67563d3f3a83e71f38a36cdac9c92c87
6
+ metadata.gz: 3334b2e69f3a8b4dcb1bc09781ff49d8884125c629b028c8a3b16f5428a341f9a6b0c03390631f77a57b88f40b121a69e5441eba119685d43b892e53d38ee560
7
+ data.tar.gz: 15c356cacc4116c3d2cf142677c538eeb9691e108a1fde6f807267ae8de96cb12aec845d42199a73da2e4db9b43a9ab347d4cab801a9008c53bf6c7c4b02e47e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.3.2] - 2026-07-30
2
+
3
+ - `stream`: filter by record operation type using `-o`
4
+ - `stream`: disable all commit messages and leave account messages by passing `-c -`
5
+ - `stream` & `stream-labels`: disable status messages using `-q`
6
+
1
7
  ## [0.3.1] - 2026-07-30
2
8
 
3
9
  - added polyfill of `Hash#except` for Ruby 2.6
@@ -9,6 +9,8 @@ require_relative 'base'
9
9
  module RatProto
10
10
  module Commands
11
11
  class Stream < Base
12
+ OPERATION_TYPES = %w[create update delete].freeze
13
+
12
14
  banner 'Stream events from a relay or PDS firehose'
13
15
 
14
16
  parameter 'SERVICE', 'relay, PDS or Jetstream hostname'
@@ -26,21 +28,25 @@ module RatProto
26
28
  option ['-d', '--did'], 'DID[,DID...]', 'filter events by DID (comma-separated or repeated)',
27
29
  multivalued: true, attribute_name: :did_values
28
30
 
29
- option ['-c', '--collection'], 'NSID[,NSID...]', 'filter events by collection (comma-separated or repeated)',
31
+ option ['-c', '--collection'], 'NSID[,NSID...]',
32
+ "filter events by collection (comma-separated or repeated; pass '-' to skip all and only print account events)",
30
33
  multivalued: true, attribute_name: :collection_values
31
34
 
32
- option ['-a', '--[no-]account'], :flag, 'print account status events (default: enabled unless filtering by collection)'
35
+ option ['-o', '--operation'], 'ACTION[,ACTION...]',
36
+ 'filter events by operation (create, update or delete; comma-separated or repeated)',
37
+ multivalued: true, attribute_name: :operation_values
38
+
39
+ option ['-a', '--[no-]account'], :flag,
40
+ 'print account status events (default: enabled unless filtering by collection or operation)'
41
+
42
+ option ['-q', '--quiet'], :flag, 'disable status messages'
33
43
  option ['-s', '--print-cursor'], :flag, 'only print current cursor (seq)'
34
44
 
35
45
 
36
46
  def execute
37
47
  require 'skyfall'
38
48
 
39
- @dids = comma_separated(did_values, '-d/--did')
40
- @collections = comma_separated(collection_values, '-c/--collection')
41
-
42
- @dids = (@dids.length > 0) ? @dids.map { |did| map_argument_to_did(did) } : nil
43
- @collections = (@collections.length > 0) ? @collections.map { |collection| validate_nsid(collection) } : nil
49
+ prepare_filters
44
50
 
45
51
  @sky = build_stream
46
52
  configure_interrupt_handler
@@ -63,6 +69,40 @@ module RatProto
63
69
 
64
70
  private
65
71
 
72
+ def prepare_filters
73
+ @dids = comma_separated(did_values, '-d/--did')
74
+ @collections = comma_separated(collection_values, '-c/--collection')
75
+ @operations = comma_separated(operation_values, '-o/--operation')
76
+
77
+ if @collections.include?('-')
78
+ if @collections.any? { |collection| collection != '-' }
79
+ signal_usage_error("'-' cannot be combined with collection names")
80
+ end
81
+
82
+ if @operations.length > 0
83
+ signal_usage_error("'-c -' cannot be combined with -o/--operation")
84
+ end
85
+
86
+ @no_collections = true
87
+ @collections = nil
88
+ elsif @collections.length > 0
89
+ @collections = @collections.map { |collection| validate_nsid(collection) }
90
+ else
91
+ @collections = nil
92
+ end
93
+
94
+ @dids = (@dids.length > 0) ? @dids.map { |did| map_argument_to_did(did) } : nil
95
+ @operations = (@operations.length > 0) ? @operations.map { |operation| validate_operation(operation) } : nil
96
+ end
97
+
98
+ def validate_operation(operation)
99
+ if OPERATION_TYPES.include?(operation)
100
+ operation.to_sym
101
+ else
102
+ signal_usage_error("#{operation.inspect} is not a valid operation (expected create, update or delete)")
103
+ end
104
+ end
105
+
66
106
  def build_stream
67
107
  if jetstream?
68
108
  options = {}
@@ -90,10 +130,10 @@ module RatProto
90
130
  end
91
131
 
92
132
  def report_error(error)
93
- log "ERROR: #{error.message}"
133
+ log "ERROR: #{error.message}", true
94
134
 
95
135
  if !jetstream? && error.message.include?('Unexpected response code')
96
- log "If this is a Jetstream server, retry with -j / --jetstream."
136
+ log "If this is a Jetstream server, retry with -j / --jetstream.", true
97
137
  end
98
138
  end
99
139
 
@@ -107,6 +147,7 @@ module RatProto
107
147
  end
108
148
 
109
149
  def print_commit_message(msg)
150
+ return if @no_collections
110
151
  return if @dids && !@dids.include?(msg.repo)
111
152
 
112
153
  time = msg.time.getlocal.iso8601
@@ -114,6 +155,7 @@ module RatProto
114
155
 
115
156
  msg.operations.each do |op|
116
157
  next if @collections && !@collections.include?(op.collection)
158
+ next if @operations && !@operations.include?(op.action)
117
159
 
118
160
  json = op.raw_record && JSON.generate(op.raw_record.except('$type'))
119
161
  puts "[#{time}] (#{msg.seq}) #{msg.repo} #{op.action.inspect} #{op.collection} #{op.rkey} #{json}"
@@ -133,8 +175,8 @@ module RatProto
133
175
 
134
176
  def show_account_messages?
135
177
  if account? == nil
136
- # enabled by default if -c is not used
137
- @collections.nil?
178
+ # enabled by default if -c or -o is not used, or if commits were explicitly disabled
179
+ @no_collections || (@collections.nil? && @operations.nil?)
138
180
  else
139
181
  # if enabled/disabled explicitly, follow user's choice
140
182
  account?
@@ -143,12 +185,16 @@ module RatProto
143
185
 
144
186
  def configure_interrupt_handler
145
187
  trap('SIGINT') do
146
- log
188
+ log nil, true
147
189
  log 'Disconnecting...'
148
190
  @sky.disconnect
149
191
  end
150
192
  end
151
193
 
194
+ def log(text = nil, force = false)
195
+ super(text) unless quiet? && !force
196
+ end
197
+
152
198
  def print_cursor_and_stop(msg)
153
199
  return if @disconnecting
154
200
 
@@ -24,6 +24,7 @@ module RatProto
24
24
  option ['-t', '--target'], 'PATTERN', "filter by labelled DID/URI (can be a pattern with '*' as a wildcard; repeatable)",
25
25
  multivalued: true, attribute_name: :target_patterns
26
26
 
27
+ option ['-q', '--quiet'], :flag, 'disable status messages'
27
28
  option ['-s', '--print-cursor'], :flag, 'only print current cursor (seq)'
28
29
 
29
30
 
@@ -109,12 +110,16 @@ module RatProto
109
110
 
110
111
  def configure_interrupt_handler
111
112
  trap('SIGINT') do
112
- log
113
+ log nil, true
113
114
  log 'Disconnecting...'
114
115
  @sky.disconnect
115
116
  end
116
117
  end
117
118
 
119
+ def log(text = nil, force = false)
120
+ super(text) unless quiet? && !force
121
+ end
122
+
118
123
  def print_cursor_and_stop(msg)
119
124
  return if @disconnecting
120
125
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RatProto
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Suder