ratproto 0.3.2 → 0.3.3

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: 7ba70d80557249c2c85eeb1e185f1cc0261800b4d3a0aa07f2cf6b777fdd512e
4
- data.tar.gz: a722e3c61aca7f8827b682885fed4b7fddaef19eaa48b8d8635d82911dc489ff
3
+ metadata.gz: a098c33a93bc8b33f32631f733fb3b5d3d1f3b233035d1cdbf8d397071a8d566
4
+ data.tar.gz: ae846bf49bca35fa4ee7fe748e8d0a05eeaf60a44f6cd687d7a0d66f61c4254f
5
5
  SHA512:
6
- metadata.gz: 3334b2e69f3a8b4dcb1bc09781ff49d8884125c629b028c8a3b16f5428a341f9a6b0c03390631f77a57b88f40b121a69e5441eba119685d43b892e53d38ee560
7
- data.tar.gz: 15c356cacc4116c3d2cf142677c538eeb9691e108a1fde6f807267ae8de96cb12aec845d42199a73da2e4db9b43a9ab347d4cab801a9008c53bf6c7c4b02e47e
6
+ metadata.gz: 9abf0ae89949e3e20b9f89c6b0ed9d09275a4fe55b68104c0579f6c85b6f10b7901c0dc9c884c022b8f269cf28bcfe6e07e00db9519266ab4e00bc5fab5e8b35
7
+ data.tar.gz: 0dfd41610d6faf493475041b065b8e688bae795bdb14c85238945ec0498a80d9ea530e7ce9e1e8fe81d7938f106c9467d100859404925000a4e58927c60a480a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.3.3] - 2026-08-17
2
+
3
+ - `stream`: added `--print-time` mode, bug fixes, unified timestamp formats
4
+ - added `status` command that prints account status
5
+
1
6
  ## [0.3.2] - 2026-07-30
2
7
 
3
8
  - `stream`: filter by record operation type using `-o`
data/lib/ratproto/cli.rb CHANGED
@@ -5,6 +5,7 @@ require 'clamp'
5
5
  require_relative 'version'
6
6
  require_relative 'ext'
7
7
  require_relative 'commands/base'
8
+ require_relative 'commands/account_status'
8
9
  require_relative 'commands/fetch'
9
10
  require_relative 'commands/resolve'
10
11
  require_relative 'commands/stream'
@@ -51,6 +52,7 @@ module RatProto
51
52
  end
52
53
 
53
54
  subcommand 'fetch', 'fetch a single record given its at:// URI', Commands::Fetch
55
+ subcommand 'status', 'print account status', Commands::AccountStatus
54
56
  subcommand 'stream', 'stream events from a relay or PDS firehose', Commands::Stream
55
57
  subcommand 'stream-labels', 'stream labels a labeller firehose', Commands::StreamLabels
56
58
  subcommand 'resolve', 'resolve a DID or @handle', Commands::Resolve
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'didkit'
4
+
5
+ require_relative 'base'
6
+
7
+ module RatProto
8
+ module Commands
9
+ class AccountStatus < Base
10
+ banner 'Print status of an account on its PDS'
11
+
12
+ parameter 'TARGET', 'DID or handle'
13
+
14
+ option ['-s', '--status'], :flag, 'print only the status without a full message'
15
+
16
+ def execute
17
+ begin
18
+ resolved_did = DID.resolve_handle(target)
19
+ rescue StandardError => e
20
+ signal_error "resolving #{target.inspect}: #{e.class}: #{e.message}"
21
+ end
22
+
23
+ if resolved_did.nil?
24
+ signal_error "couldn't resolve #{target}"
25
+ end
26
+
27
+ result = resolved_did.account_status
28
+
29
+ if status?
30
+ puts (result&.to_s || 'deleted')
31
+ return
32
+ end
33
+
34
+ case result
35
+ when :active
36
+ puts "#{resolved_did} at #{resolved_did.document.pds_host}: account active"
37
+ when nil
38
+ puts "#{resolved_did} at #{resolved_did.document.pds_host}: account not found"
39
+ else
40
+ puts "#{resolved_did} at #{resolved_did.document.pds_host}: account inactive (status = #{result})"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -40,7 +40,8 @@ module RatProto
40
40
  'print account status events (default: enabled unless filtering by collection or operation)'
41
41
 
42
42
  option ['-q', '--quiet'], :flag, 'disable status messages'
43
- option ['-s', '--print-cursor'], :flag, 'only print current cursor (seq)'
43
+ option ['-s', '--print-cursor'], :flag, 'only print cursor (seq) of first event and disconnect'
44
+ option ['--print-time'], :flag, 'only print timestamp of first event and disconnect'
44
45
 
45
46
 
46
47
  def execute
@@ -51,12 +52,13 @@ module RatProto
51
52
  @sky = build_stream
52
53
  configure_interrupt_handler
53
54
 
54
- if print_cursor?
55
+ if print_cursor? || print_time?
55
56
  @sky.on_message do |msg|
56
57
  print_cursor_and_stop(msg)
57
58
  next
58
59
  end
59
60
 
61
+ @sky.on_error { |e| report_error(e) }
60
62
  @sky.connect
61
63
  else
62
64
  configure_callbacks
@@ -147,12 +149,12 @@ module RatProto
147
149
  end
148
150
 
149
151
  def print_commit_message(msg)
152
+ time = msg.time.getlocal
153
+ @last_timestamp = time
154
+
150
155
  return if @no_collections
151
156
  return if @dids && !@dids.include?(msg.repo)
152
157
 
153
- time = msg.time.getlocal.iso8601
154
- @last_timestamp = time
155
-
156
158
  msg.operations.each do |op|
157
159
  next if @collections && !@collections.include?(op.collection)
158
160
  next if @operations && !@operations.include?(op.action)
@@ -163,11 +165,11 @@ module RatProto
163
165
  end
164
166
 
165
167
  def print_account_message(msg)
166
- return if @dids && !@dids.include?(msg.repo)
167
-
168
- time = msg.time.getlocal.iso8601
168
+ time = msg.time.getlocal
169
169
  @last_timestamp = time
170
170
 
171
+ return if @dids && !@dids.include?(msg.repo)
172
+
171
173
  status = (msg.active?) ? :active : msg.status
172
174
 
173
175
  puts "[#{time}] (#{msg.seq}) #{msg.repo} #account (status = #{status.inspect})"
@@ -198,7 +200,8 @@ module RatProto
198
200
  def print_cursor_and_stop(msg)
199
201
  return if @disconnecting
200
202
 
201
- puts msg.seq
203
+ puts (print_time?) ? msg.time.getlocal : msg.seq
204
+
202
205
  @sky.disconnect
203
206
  @disconnecting = true
204
207
  end
@@ -25,7 +25,8 @@ module RatProto
25
25
  multivalued: true, attribute_name: :target_patterns
26
26
 
27
27
  option ['-q', '--quiet'], :flag, 'disable status messages'
28
- option ['-s', '--print-cursor'], :flag, 'only print current cursor (seq)'
28
+ option ['-s', '--print-cursor'], :flag, 'only print cursor (seq) of first event and disconnect'
29
+ option ['--print-time'], :flag, 'only print timestamp of first event and disconnect'
29
30
 
30
31
 
31
32
  def execute
@@ -38,12 +39,13 @@ module RatProto
38
39
  @sky = Skyfall::Firehose.new(@service, :subscribe_labels, cursor)
39
40
  configure_interrupt_handler
40
41
 
41
- if print_cursor?
42
+ if print_cursor? || print_time?
42
43
  @sky.on_message do |msg|
43
44
  print_cursor_and_stop(msg)
44
45
  next
45
46
  end
46
47
 
48
+ @sky.on_error { |e| log "ERROR: #{e.message}" }
47
49
  @sky.connect
48
50
  else
49
51
  configure_callbacks
@@ -91,19 +93,20 @@ module RatProto
91
93
  @sky.on_disconnect { log "Disconnected" }
92
94
  @sky.on_reconnect { log "Connection lost, trying to reconnect..." }
93
95
  @sky.on_timeout { log "Connection stalled, triggering a reconnect..." }
94
- @sky.on_error { |e| log "ERROR: #{e}" }
96
+ @sky.on_error { |e| log "ERROR: #{e.message}" }
95
97
 
96
98
  @sky.on_message do |msg|
97
99
  next unless msg.type == :labels
98
100
 
99
101
  msg.labels.each do |label|
102
+ time = label.created_at.getlocal
103
+ @last_timestamp = time
104
+
100
105
  next if @labels && !@labels.include?(label.value)
101
106
  next if @targets && @targets.none? { |pattern| pattern.match?(label.subject) }
102
107
 
103
- @last_timestamp = label.created_at
104
-
105
108
  json = JSON.generate(label.data.except('cid', 'cts', 'sig', 'src', 'ver'))
106
- puts "[#{label.created_at}] (#{msg.seq}) #{json}"
109
+ puts "[#{time}] (#{msg.seq}) #{json}"
107
110
  end
108
111
  end
109
112
  end
@@ -123,7 +126,8 @@ module RatProto
123
126
  def print_cursor_and_stop(msg)
124
127
  return if @disconnecting
125
128
 
126
- puts msg.seq
129
+ puts (print_time?) ? msg.labels.first.created_at.getlocal : msg.seq
130
+
127
131
  @sky.disconnect
128
132
  @disconnecting = true
129
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RatProto
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
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.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Suder
@@ -102,6 +102,7 @@ files:
102
102
  - exe/rat
103
103
  - lib/ratproto.rb
104
104
  - lib/ratproto/cli.rb
105
+ - lib/ratproto/commands/account_status.rb
105
106
  - lib/ratproto/commands/base.rb
106
107
  - lib/ratproto/commands/fetch.rb
107
108
  - lib/ratproto/commands/resolve.rb
@@ -117,6 +118,7 @@ metadata:
117
118
  bug_tracker_uri: https://tangled.org/mackuba.eu/ratproto/issues
118
119
  changelog_uri: https://tangled.org/mackuba.eu/ratproto/blob/master/CHANGELOG.md
119
120
  source_code_uri: https://tangled.org/mackuba.eu/ratproto
121
+ rubygems_mfa_required: 'true'
120
122
  rdoc_options: []
121
123
  require_paths:
122
124
  - lib