at_protocol 0.0.4.1 → 0.0.4.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: b9079f38f8b754c7aab1c556dd3b79e98a5f95ffa5091ce0a36f3f3da483b69d
4
- data.tar.gz: b3423fa8c0a4595f7afb81cbb823c38a58a6d5e609dff38ebe297b85dfd4c84b
3
+ metadata.gz: bac3005062f2494c16a3fcabc3af9f45daf3b127b81624872ab71603de1f9fbc
4
+ data.tar.gz: 28088b1b416163feab91d06e42245279216673cf2ae1d077eebc78bfb79a0b1c
5
5
  SHA512:
6
- metadata.gz: 066a7e0ba5ea613209e4b180be05c25c82251968fad5e7b611fa3200ae820ceb41268c1759d0ec77eb733aa410c8878cbd6890c61e7bf47ebd1171c364ca84ed
7
- data.tar.gz: b106124acf97f5d6443aae45adcf65eac04319d923f92e08e3404bb87c8912ab59ff7feb739ef9b0a377c9b23e83fa0789bed8ba8128dd5e8ad9be4d4a7c0dad
6
+ metadata.gz: eeb00d26cead39126432d2be52540da02f5d9734eebe9c5c4735dd4e4e556ae88a0886fe8455c98a72969b7728e2213ad0f957317a1d89852cdbcb687e7d44f7
7
+ data.tar.gz: deb75bae3fe96f9eb2831f0e61ce48f23aa9030b5fe1714123cb0c7293e7378ac3a13cef0850f3b653e5467376b19fbf07de5a9d50e21d2a775527ce16b507ba
@@ -13,6 +13,10 @@ module ATProto
13
13
 
14
14
  module_function :at_uri
15
15
  end
16
+
17
+ def self.AtUri(str)
18
+ RequestUtils.at_uri(str)
19
+ end
16
20
  end
17
21
 
18
22
  module ATProto
@@ -9,22 +9,10 @@ module ATProto
9
9
  const(:repo, ATProto::Repo)
10
10
  const(:collection, String)
11
11
 
12
- sig { params(limit: Integer).returns(T::Array[ATProto::Record]) }
13
-
14
- def list(limit = 10)
15
- self.repo.xrpc
16
- .get.com_atproto_repo_listRecords(
17
- repo: self.repo.did,
18
- collection: self.collection,
19
- limit: limit,
20
- )["records"]
21
- .map { |record|
22
- ATProto::Record.from_hash(record)
23
- }
24
- end
12
+ sig { params(count: T.nilable(Integer)).returns(T::Array[ATProto::Record]) }
25
13
 
26
- def list_all()
27
- T.must(get_paginated_data(self.repo, :com_atproto_repo_listRecords.to_s, key: "records", params: { repo: self.repo.to_s, collection: self.to_s }, cursor: nil) do |record|
14
+ def list(count = nil)
15
+ T.must(get_paginated_data(self.repo, :com_atproto_repo_listRecords.to_s, key: "records", params: { repo: self.repo.to_s, collection: self.to_s }, count: count, cursor: nil) do |record|
28
16
  ATProto::Record.from_hash(record)
29
17
  end)
30
18
  end
@@ -78,6 +78,9 @@ module ATProto
78
78
  cursor: T.nilable(
79
79
  String
80
80
  ),
81
+ count: T.nilable(
82
+ Integer
83
+ ),
81
84
  map_block: T.nilable(Proc),
82
85
  )
83
86
  .returns(T
@@ -86,7 +89,7 @@ module ATProto
86
89
  ))
87
90
  }
88
91
 
89
- def get_paginated_data(session, method, key:, params:, cursor: nil, &map_block)
92
+ def get_paginated_data(session, method, key:, params:, cursor: nil, count: nil, &map_block)
90
93
  params.merge({ limit: 100, cursor: cursor }).then do |send_data|
91
94
  session.xrpc.get.public_send(method, **send_data).then do |response|
92
95
  response.dig(key).then do |data|
@@ -94,26 +97,19 @@ module ATProto
94
97
  return []
95
98
  end
96
99
 
97
- if block_given?
98
- data.map(&map_block).then do |results|
99
- response.dig("cursor").then do |next_cursor|
100
- if next_cursor.nil?
101
- return results
102
- else
103
- get_paginated_data(session, method, key: key, params: params, cursor: next_cursor, &map_block).then do |next_results|
104
- return results + next_results
105
- end
106
- end
107
- end
100
+ results = if block_given?
101
+ data.map(&map_block)
102
+ else
103
+ data
108
104
  end
109
- else
110
- response.dig("cursor").then do |next_cursor|
111
- if next_cursor.nil?
112
- return data
113
- else
114
- get_paginated_data(session, method, key: key, params: params, cursor: next_cursor, &map_block).then do |next_results|
115
- return data + next_results
116
- end
105
+
106
+ response.dig("cursor").then do |next_cursor|
107
+ if next_cursor.nil? || (count && results.length >= count)
108
+ return results[0..count]
109
+ else
110
+ remaining_count = count ? count - results.length : nil
111
+ get_paginated_data(session, method, key: key, params: params, cursor: next_cursor, count: remaining_count, &map_block).then do |next_results|
112
+ return (results + next_results)
117
113
  end
118
114
  end
119
115
  end
@@ -123,3 +119,26 @@ module ATProto
123
119
  end
124
120
  end
125
121
  end
122
+
123
+ module ATProto
124
+ module RequestUtils
125
+ class XRPCResponseCode < T::Enum
126
+ enums do
127
+ Unknown = new(1)
128
+ InvalidResponse = new(2)
129
+ Success = new(200)
130
+ InvalidRequest = new(400)
131
+ AuthRequired = new(401)
132
+ Forbidden = new(403)
133
+ XRPCNotSupported = new(404)
134
+ PayloadTooLarge = new(413)
135
+ RateLimitExceeded = new(429)
136
+ InternalServerError = new(500)
137
+ MethodNotImplemented = new(501)
138
+ UpstreamFailure = new(502)
139
+ NotEnoughResouces = new(503)
140
+ UpstreamTimeout = new(504)
141
+ end
142
+ end
143
+ end
144
+ end
@@ -66,6 +66,10 @@ module ATProto
66
66
  raise UnauthorizedError
67
67
  end
68
68
  end
69
+
70
+ def inspect
71
+ "#<ATProto::Session(did: #{did}, access_token: #{access_token})>"
72
+ end
69
73
  end
70
74
  end
71
75
 
@@ -1,4 +1,4 @@
1
1
  # typed: strict
2
2
  module ATProto
3
- VERSION = "0.0.4.1"
3
+ VERSION = "0.0.4.2"
4
4
  end
@@ -1,5 +1,7 @@
1
1
  # typed: true
2
2
  module ATProto
3
+ extend T::Sig
4
+
3
5
  class Writes < T::Struct
4
6
  class Write < T::Struct
5
7
  class Action < T::Enum
@@ -101,14 +103,13 @@ module ATProto
101
103
 
102
104
  class << self
103
105
  extend T::Sig
104
- sig { params(block: Proc).returns(T::Array[Write]) }
105
-
106
- def generate(&block)
107
- Collector.new.instance_eval(&block)
108
- end
109
106
  end
110
107
  end
111
108
 
109
+ def self.Writes(session, &block)
110
+ Writes.new(writes: Writes::Collector.new.instance_eval(&block), session: session, repo: Repo.new(session.did))
111
+ end
112
+
112
113
  class Writes
113
114
  class Collector
114
115
  include RequestUtils
data/lib/at_protocol.rb CHANGED
@@ -15,6 +15,18 @@ class Class
15
15
  end
16
16
  end
17
17
 
18
+ module ATProto
19
+ class << self
20
+ def method_missing(method_name, *args, &block)
21
+ if const_defined?(method_name)
22
+ Object.const_get(method_name).new(*args, &block)
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+
18
30
  require "skyfall/cid"
19
31
  require "xrpc"
20
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: at_protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shreyan Jain
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-01 00:00:00.000000000 Z
12
+ date: 2023-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xrpc