turbopuffer-ruby 0.2.0.pre.alpha.1
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 +7 -0
- data/.ignore +2 -0
- data/CHANGELOG.md +60 -0
- data/README.md +291 -0
- data/SECURITY.md +27 -0
- data/lib/turbopuffer/client.rb +130 -0
- data/lib/turbopuffer/errors.rb +214 -0
- data/lib/turbopuffer/file_part.rb +55 -0
- data/lib/turbopuffer/internal/namespace_page.rb +86 -0
- data/lib/turbopuffer/internal/transport/base_client.rb +563 -0
- data/lib/turbopuffer/internal/transport/pooled_net_requester.rb +209 -0
- data/lib/turbopuffer/internal/type/array_of.rb +167 -0
- data/lib/turbopuffer/internal/type/base_model.rb +534 -0
- data/lib/turbopuffer/internal/type/base_page.rb +55 -0
- data/lib/turbopuffer/internal/type/boolean.rb +77 -0
- data/lib/turbopuffer/internal/type/converter.rb +300 -0
- data/lib/turbopuffer/internal/type/enum.rb +152 -0
- data/lib/turbopuffer/internal/type/file_input.rb +108 -0
- data/lib/turbopuffer/internal/type/hash_of.rb +187 -0
- data/lib/turbopuffer/internal/type/request_parameters.rb +42 -0
- data/lib/turbopuffer/internal/type/union.rb +252 -0
- data/lib/turbopuffer/internal/type/unknown.rb +81 -0
- data/lib/turbopuffer/internal/util.rb +914 -0
- data/lib/turbopuffer/internal.rb +20 -0
- data/lib/turbopuffer/models/attribute_schema.rb +19 -0
- data/lib/turbopuffer/models/attribute_schema_config.rb +48 -0
- data/lib/turbopuffer/models/attribute_type.rb +7 -0
- data/lib/turbopuffer/models/client_namespaces_params.rb +38 -0
- data/lib/turbopuffer/models/columns.rb +64 -0
- data/lib/turbopuffer/models/distance_metric.rb +19 -0
- data/lib/turbopuffer/models/full_text_search.rb +20 -0
- data/lib/turbopuffer/models/full_text_search_config.rb +72 -0
- data/lib/turbopuffer/models/id.rb +19 -0
- data/lib/turbopuffer/models/include_attributes.rb +22 -0
- data/lib/turbopuffer/models/language.rb +32 -0
- data/lib/turbopuffer/models/namespace_delete_all_params.rb +20 -0
- data/lib/turbopuffer/models/namespace_delete_all_response.rb +19 -0
- data/lib/turbopuffer/models/namespace_hint_cache_warm_params.rb +20 -0
- data/lib/turbopuffer/models/namespace_hint_cache_warm_response.rb +26 -0
- data/lib/turbopuffer/models/namespace_metadata.rb +35 -0
- data/lib/turbopuffer/models/namespace_metadata_params.rb +20 -0
- data/lib/turbopuffer/models/namespace_multi_query_params.rb +73 -0
- data/lib/turbopuffer/models/namespace_multi_query_response.rb +51 -0
- data/lib/turbopuffer/models/namespace_query_params.rb +119 -0
- data/lib/turbopuffer/models/namespace_query_response.rb +41 -0
- data/lib/turbopuffer/models/namespace_recall_params.rb +57 -0
- data/lib/turbopuffer/models/namespace_recall_response.rb +39 -0
- data/lib/turbopuffer/models/namespace_schema_params.rb +20 -0
- data/lib/turbopuffer/models/namespace_schema_response.rb +8 -0
- data/lib/turbopuffer/models/namespace_summary.rb +19 -0
- data/lib/turbopuffer/models/namespace_update_schema_params.rb +29 -0
- data/lib/turbopuffer/models/namespace_update_schema_response.rb +9 -0
- data/lib/turbopuffer/models/namespace_write_params.rb +158 -0
- data/lib/turbopuffer/models/namespace_write_response.rb +67 -0
- data/lib/turbopuffer/models/query.rb +63 -0
- data/lib/turbopuffer/models/query_billing.rb +26 -0
- data/lib/turbopuffer/models/query_performance.rb +63 -0
- data/lib/turbopuffer/models/row.rb +38 -0
- data/lib/turbopuffer/models/tokenizer.rb +17 -0
- data/lib/turbopuffer/models/vector.rb +22 -0
- data/lib/turbopuffer/models/vector_encoding.rb +16 -0
- data/lib/turbopuffer/models/write_billing.rb +26 -0
- data/lib/turbopuffer/models.rb +101 -0
- data/lib/turbopuffer/namespace.rb +22 -0
- data/lib/turbopuffer/request_options.rb +77 -0
- data/lib/turbopuffer/resources/namespaces.rb +311 -0
- data/lib/turbopuffer/version.rb +5 -0
- data/lib/turbopuffer.rb +94 -0
- data/manifest.yaml +15 -0
- data/rbi/turbopuffer/client.rbi +91 -0
- data/rbi/turbopuffer/errors.rbi +178 -0
- data/rbi/turbopuffer/file_part.rbi +37 -0
- data/rbi/turbopuffer/internal/namespace_page.rbi +22 -0
- data/rbi/turbopuffer/internal/transport/base_client.rbi +298 -0
- data/rbi/turbopuffer/internal/transport/pooled_net_requester.rbi +80 -0
- data/rbi/turbopuffer/internal/type/array_of.rbi +104 -0
- data/rbi/turbopuffer/internal/type/base_model.rbi +304 -0
- data/rbi/turbopuffer/internal/type/base_page.rbi +43 -0
- data/rbi/turbopuffer/internal/type/boolean.rbi +58 -0
- data/rbi/turbopuffer/internal/type/converter.rbi +162 -0
- data/rbi/turbopuffer/internal/type/enum.rbi +82 -0
- data/rbi/turbopuffer/internal/type/file_input.rbi +59 -0
- data/rbi/turbopuffer/internal/type/hash_of.rbi +104 -0
- data/rbi/turbopuffer/internal/type/request_parameters.rbi +31 -0
- data/rbi/turbopuffer/internal/type/union.rbi +121 -0
- data/rbi/turbopuffer/internal/type/unknown.rbi +58 -0
- data/rbi/turbopuffer/internal/util.rbi +487 -0
- data/rbi/turbopuffer/internal.rbi +18 -0
- data/rbi/turbopuffer/models/attribute_schema.rbi +17 -0
- data/rbi/turbopuffer/models/attribute_schema_config.rbi +92 -0
- data/rbi/turbopuffer/models/attribute_type.rbi +7 -0
- data/rbi/turbopuffer/models/client_namespaces_params.rbi +71 -0
- data/rbi/turbopuffer/models/columns.rbi +82 -0
- data/rbi/turbopuffer/models/distance_metric.rbi +27 -0
- data/rbi/turbopuffer/models/full_text_search.rbi +19 -0
- data/rbi/turbopuffer/models/full_text_search_config.rbi +116 -0
- data/rbi/turbopuffer/models/id.rbi +16 -0
- data/rbi/turbopuffer/models/include_attributes.rbi +24 -0
- data/rbi/turbopuffer/models/language.rbi +36 -0
- data/rbi/turbopuffer/models/namespace_delete_all_params.rbi +41 -0
- data/rbi/turbopuffer/models/namespace_delete_all_response.rbi +31 -0
- data/rbi/turbopuffer/models/namespace_hint_cache_warm_params.rbi +41 -0
- data/rbi/turbopuffer/models/namespace_hint_cache_warm_response.rbi +38 -0
- data/rbi/turbopuffer/models/namespace_metadata.rbi +54 -0
- data/rbi/turbopuffer/models/namespace_metadata_params.rbi +41 -0
- data/rbi/turbopuffer/models/namespace_multi_query_params.rbi +175 -0
- data/rbi/turbopuffer/models/namespace_multi_query_response.rbi +111 -0
- data/rbi/turbopuffer/models/namespace_query_params.rbi +241 -0
- data/rbi/turbopuffer/models/namespace_query_response.rbi +73 -0
- data/rbi/turbopuffer/models/namespace_recall_params.rbi +93 -0
- data/rbi/turbopuffer/models/namespace_recall_response.rbi +59 -0
- data/rbi/turbopuffer/models/namespace_schema_params.rbi +41 -0
- data/rbi/turbopuffer/models/namespace_schema_response.rbi +11 -0
- data/rbi/turbopuffer/models/namespace_summary.rbi +28 -0
- data/rbi/turbopuffer/models/namespace_update_schema_params.rbi +80 -0
- data/rbi/turbopuffer/models/namespace_update_schema_response.rbi +11 -0
- data/rbi/turbopuffer/models/namespace_write_params.rbi +290 -0
- data/rbi/turbopuffer/models/namespace_write_response.rbi +101 -0
- data/rbi/turbopuffer/models/query.rbi +106 -0
- data/rbi/turbopuffer/models/query_billing.rbi +46 -0
- data/rbi/turbopuffer/models/query_performance.rbi +82 -0
- data/rbi/turbopuffer/models/row.rbi +47 -0
- data/rbi/turbopuffer/models/tokenizer.rbi +22 -0
- data/rbi/turbopuffer/models/vector.rbi +22 -0
- data/rbi/turbopuffer/models/vector_encoding.rbi +22 -0
- data/rbi/turbopuffer/models/write_billing.rbi +49 -0
- data/rbi/turbopuffer/models.rbi +64 -0
- data/rbi/turbopuffer/namespace.rbi +8 -0
- data/rbi/turbopuffer/request_options.rbi +59 -0
- data/rbi/turbopuffer/resources/namespaces.rbi +243 -0
- data/rbi/turbopuffer/version.rbi +5 -0
- data/sig/turbopuffer/client.rbs +41 -0
- data/sig/turbopuffer/errors.rbs +110 -0
- data/sig/turbopuffer/file_part.rbs +21 -0
- data/sig/turbopuffer/internal/namespace_page.rbs +13 -0
- data/sig/turbopuffer/internal/transport/base_client.rbs +131 -0
- data/sig/turbopuffer/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/turbopuffer/internal/type/array_of.rbs +48 -0
- data/sig/turbopuffer/internal/type/base_model.rbs +102 -0
- data/sig/turbopuffer/internal/type/base_page.rbs +24 -0
- data/sig/turbopuffer/internal/type/boolean.rbs +26 -0
- data/sig/turbopuffer/internal/type/converter.rbs +62 -0
- data/sig/turbopuffer/internal/type/enum.rbs +32 -0
- data/sig/turbopuffer/internal/type/file_input.rbs +25 -0
- data/sig/turbopuffer/internal/type/hash_of.rbs +48 -0
- data/sig/turbopuffer/internal/type/request_parameters.rbs +19 -0
- data/sig/turbopuffer/internal/type/union.rbs +52 -0
- data/sig/turbopuffer/internal/type/unknown.rbs +26 -0
- data/sig/turbopuffer/internal/util.rbs +185 -0
- data/sig/turbopuffer/internal.rbs +9 -0
- data/sig/turbopuffer/models/attribute_schema.rbs +11 -0
- data/sig/turbopuffer/models/attribute_schema_config.rbs +45 -0
- data/sig/turbopuffer/models/attribute_type.rbs +5 -0
- data/sig/turbopuffer/models/client_namespaces_params.rbs +38 -0
- data/sig/turbopuffer/models/columns.rbs +42 -0
- data/sig/turbopuffer/models/distance_metric.rbs +17 -0
- data/sig/turbopuffer/models/full_text_search.rbs +11 -0
- data/sig/turbopuffer/models/full_text_search_config.rbs +68 -0
- data/sig/turbopuffer/models/id.rbs +11 -0
- data/sig/turbopuffer/models/include_attributes.rbs +13 -0
- data/sig/turbopuffer/models/language.rbs +48 -0
- data/sig/turbopuffer/models/namespace_delete_all_params.rbs +25 -0
- data/sig/turbopuffer/models/namespace_delete_all_response.rbs +13 -0
- data/sig/turbopuffer/models/namespace_hint_cache_warm_params.rbs +25 -0
- data/sig/turbopuffer/models/namespace_hint_cache_warm_response.rbs +17 -0
- data/sig/turbopuffer/models/namespace_metadata.rbs +30 -0
- data/sig/turbopuffer/models/namespace_metadata_params.rbs +25 -0
- data/sig/turbopuffer/models/namespace_multi_query_params.rbs +86 -0
- data/sig/turbopuffer/models/namespace_multi_query_response.rbs +53 -0
- data/sig/turbopuffer/models/namespace_query_params.rbs +125 -0
- data/sig/turbopuffer/models/namespace_query_response.rbs +39 -0
- data/sig/turbopuffer/models/namespace_recall_params.rbs +56 -0
- data/sig/turbopuffer/models/namespace_recall_response.rbs +26 -0
- data/sig/turbopuffer/models/namespace_schema_params.rbs +25 -0
- data/sig/turbopuffer/models/namespace_schema_response.rbs +8 -0
- data/sig/turbopuffer/models/namespace_summary.rbs +13 -0
- data/sig/turbopuffer/models/namespace_update_schema_params.rbs +37 -0
- data/sig/turbopuffer/models/namespace_update_schema_response.rbs +8 -0
- data/sig/turbopuffer/models/namespace_write_params.rbs +156 -0
- data/sig/turbopuffer/models/namespace_write_response.rbs +56 -0
- data/sig/turbopuffer/models/query.rbs +61 -0
- data/sig/turbopuffer/models/query_billing.rbs +25 -0
- data/sig/turbopuffer/models/query_performance.rbs +45 -0
- data/sig/turbopuffer/models/row.rbs +24 -0
- data/sig/turbopuffer/models/tokenizer.rbs +15 -0
- data/sig/turbopuffer/models/vector.rbs +13 -0
- data/sig/turbopuffer/models/vector_encoding.rbs +14 -0
- data/sig/turbopuffer/models/write_billing.rbs +27 -0
- data/sig/turbopuffer/models.rbs +61 -0
- data/sig/turbopuffer/namespace.rbs +5 -0
- data/sig/turbopuffer/request_options.rbs +36 -0
- data/sig/turbopuffer/resources/namespaces.rbs +81 -0
- data/sig/turbopuffer/version.rbs +3 -0
- metadata +251 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Turbopuffer
|
4
|
+
module Errors
|
5
|
+
class Error < StandardError
|
6
|
+
# @!attribute cause
|
7
|
+
#
|
8
|
+
# @return [StandardError, nil]
|
9
|
+
end
|
10
|
+
|
11
|
+
class ConversionError < Turbopuffer::Errors::Error
|
12
|
+
# @return [StandardError, nil]
|
13
|
+
def cause = @cause.nil? ? super : @cause
|
14
|
+
|
15
|
+
# @api private
|
16
|
+
#
|
17
|
+
# @param on [Class<StandardError>]
|
18
|
+
# @param method [Symbol]
|
19
|
+
# @param target [Object]
|
20
|
+
# @param value [Object]
|
21
|
+
# @param cause [StandardError, nil]
|
22
|
+
def initialize(on:, method:, target:, value:, cause: nil)
|
23
|
+
cls = on.name.split("::").last
|
24
|
+
|
25
|
+
message = [
|
26
|
+
"Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
|
27
|
+
"To get the unparsed API response, use #{cls}[#{method.inspect}].",
|
28
|
+
cause && "Cause: #{cause.message}"
|
29
|
+
].filter(&:itself).join(" ")
|
30
|
+
|
31
|
+
@cause = cause
|
32
|
+
super(message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class APIError < Turbopuffer::Errors::Error
|
37
|
+
# @return [URI::Generic]
|
38
|
+
attr_accessor :url
|
39
|
+
|
40
|
+
# @return [Integer, nil]
|
41
|
+
attr_accessor :status
|
42
|
+
|
43
|
+
# @return [Object, nil]
|
44
|
+
attr_accessor :body
|
45
|
+
|
46
|
+
# @api private
|
47
|
+
#
|
48
|
+
# @param url [URI::Generic]
|
49
|
+
# @param status [Integer, nil]
|
50
|
+
# @param body [Object, nil]
|
51
|
+
# @param request [nil]
|
52
|
+
# @param response [nil]
|
53
|
+
# @param message [String, nil]
|
54
|
+
def initialize(url:, status: nil, body: nil, request: nil, response: nil, message: nil)
|
55
|
+
@url = url
|
56
|
+
@status = status
|
57
|
+
@body = body
|
58
|
+
@request = request
|
59
|
+
@response = response
|
60
|
+
super(message)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class APIConnectionError < Turbopuffer::Errors::APIError
|
65
|
+
# @!attribute status
|
66
|
+
#
|
67
|
+
# @return [nil]
|
68
|
+
|
69
|
+
# @!attribute body
|
70
|
+
#
|
71
|
+
# @return [nil]
|
72
|
+
|
73
|
+
# @api private
|
74
|
+
#
|
75
|
+
# @param url [URI::Generic]
|
76
|
+
# @param status [nil]
|
77
|
+
# @param body [nil]
|
78
|
+
# @param request [nil]
|
79
|
+
# @param response [nil]
|
80
|
+
# @param message [String, nil]
|
81
|
+
def initialize(
|
82
|
+
url:,
|
83
|
+
status: nil,
|
84
|
+
body: nil,
|
85
|
+
request: nil,
|
86
|
+
response: nil,
|
87
|
+
message: "Connection error."
|
88
|
+
)
|
89
|
+
super
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class APITimeoutError < Turbopuffer::Errors::APIConnectionError
|
94
|
+
# @api private
|
95
|
+
#
|
96
|
+
# @param url [URI::Generic]
|
97
|
+
# @param status [nil]
|
98
|
+
# @param body [nil]
|
99
|
+
# @param request [nil]
|
100
|
+
# @param response [nil]
|
101
|
+
# @param message [String, nil]
|
102
|
+
def initialize(
|
103
|
+
url:,
|
104
|
+
status: nil,
|
105
|
+
body: nil,
|
106
|
+
request: nil,
|
107
|
+
response: nil,
|
108
|
+
message: "Request timed out."
|
109
|
+
)
|
110
|
+
super
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class APIStatusError < Turbopuffer::Errors::APIError
|
115
|
+
# @api private
|
116
|
+
#
|
117
|
+
# @param url [URI::Generic]
|
118
|
+
# @param status [Integer]
|
119
|
+
# @param body [Object, nil]
|
120
|
+
# @param request [nil]
|
121
|
+
# @param response [nil]
|
122
|
+
# @param message [String, nil]
|
123
|
+
#
|
124
|
+
# @return [self]
|
125
|
+
def self.for(url:, status:, body:, request:, response:, message: nil)
|
126
|
+
kwargs = {
|
127
|
+
url: url,
|
128
|
+
status: status,
|
129
|
+
body: body,
|
130
|
+
request: request,
|
131
|
+
response: response,
|
132
|
+
message: message
|
133
|
+
}
|
134
|
+
|
135
|
+
case status
|
136
|
+
in 400
|
137
|
+
Turbopuffer::Errors::BadRequestError.new(**kwargs)
|
138
|
+
in 401
|
139
|
+
Turbopuffer::Errors::AuthenticationError.new(**kwargs)
|
140
|
+
in 403
|
141
|
+
Turbopuffer::Errors::PermissionDeniedError.new(**kwargs)
|
142
|
+
in 404
|
143
|
+
Turbopuffer::Errors::NotFoundError.new(**kwargs)
|
144
|
+
in 409
|
145
|
+
Turbopuffer::Errors::ConflictError.new(**kwargs)
|
146
|
+
in 422
|
147
|
+
Turbopuffer::Errors::UnprocessableEntityError.new(**kwargs)
|
148
|
+
in 429
|
149
|
+
Turbopuffer::Errors::RateLimitError.new(**kwargs)
|
150
|
+
in (500..)
|
151
|
+
Turbopuffer::Errors::InternalServerError.new(**kwargs)
|
152
|
+
else
|
153
|
+
Turbopuffer::Errors::APIStatusError.new(**kwargs)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# @!parse
|
158
|
+
# # @return [Integer]
|
159
|
+
# attr_accessor :status
|
160
|
+
|
161
|
+
# @api private
|
162
|
+
#
|
163
|
+
# @param url [URI::Generic]
|
164
|
+
# @param status [Integer]
|
165
|
+
# @param body [Object, nil]
|
166
|
+
# @param request [nil]
|
167
|
+
# @param response [nil]
|
168
|
+
# @param message [String, nil]
|
169
|
+
def initialize(url:, status:, body:, request:, response:, message: nil)
|
170
|
+
message ||= {url: url.to_s, status: status, body: body}
|
171
|
+
super(
|
172
|
+
url: url,
|
173
|
+
status: status,
|
174
|
+
body: body,
|
175
|
+
request: request,
|
176
|
+
response: response,
|
177
|
+
message: message&.to_s
|
178
|
+
)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class BadRequestError < Turbopuffer::Errors::APIStatusError
|
183
|
+
HTTP_STATUS = 400
|
184
|
+
end
|
185
|
+
|
186
|
+
class AuthenticationError < Turbopuffer::Errors::APIStatusError
|
187
|
+
HTTP_STATUS = 401
|
188
|
+
end
|
189
|
+
|
190
|
+
class PermissionDeniedError < Turbopuffer::Errors::APIStatusError
|
191
|
+
HTTP_STATUS = 403
|
192
|
+
end
|
193
|
+
|
194
|
+
class NotFoundError < Turbopuffer::Errors::APIStatusError
|
195
|
+
HTTP_STATUS = 404
|
196
|
+
end
|
197
|
+
|
198
|
+
class ConflictError < Turbopuffer::Errors::APIStatusError
|
199
|
+
HTTP_STATUS = 409
|
200
|
+
end
|
201
|
+
|
202
|
+
class UnprocessableEntityError < Turbopuffer::Errors::APIStatusError
|
203
|
+
HTTP_STATUS = 422
|
204
|
+
end
|
205
|
+
|
206
|
+
class RateLimitError < Turbopuffer::Errors::APIStatusError
|
207
|
+
HTTP_STATUS = 429
|
208
|
+
end
|
209
|
+
|
210
|
+
class InternalServerError < Turbopuffer::Errors::APIStatusError
|
211
|
+
HTTP_STATUS = (500..)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Turbopuffer
|
4
|
+
class FilePart
|
5
|
+
# @return [Pathname, StringIO, IO, String]
|
6
|
+
attr_reader :content
|
7
|
+
|
8
|
+
# @return [String, nil]
|
9
|
+
attr_reader :content_type
|
10
|
+
|
11
|
+
# @return [String, nil]
|
12
|
+
attr_reader :filename
|
13
|
+
|
14
|
+
# @api private
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
private def read
|
18
|
+
case content
|
19
|
+
in Pathname
|
20
|
+
content.read(binmode: true)
|
21
|
+
in StringIO
|
22
|
+
content.string
|
23
|
+
in IO
|
24
|
+
content.read
|
25
|
+
in String
|
26
|
+
content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param a [Object]
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
def to_json(*a) = read.to_json(*a)
|
34
|
+
|
35
|
+
# @param a [Object]
|
36
|
+
#
|
37
|
+
# @return [String]
|
38
|
+
def to_yaml(*a) = read.to_yaml(*a)
|
39
|
+
|
40
|
+
# @param content [Pathname, StringIO, IO, String]
|
41
|
+
# @param filename [String, nil]
|
42
|
+
# @param content_type [String, nil]
|
43
|
+
def initialize(content, filename: nil, content_type: nil)
|
44
|
+
@content = content
|
45
|
+
@filename =
|
46
|
+
case content
|
47
|
+
in Pathname
|
48
|
+
filename.nil? ? content.basename.to_path : ::File.basename(filename)
|
49
|
+
else
|
50
|
+
filename.nil? ? nil : ::File.basename(filename)
|
51
|
+
end
|
52
|
+
@content_type = content_type
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Turbopuffer
|
4
|
+
module Internal
|
5
|
+
# @generic Elem
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# if namespace_page.has_next?
|
9
|
+
# namespace_page = namespace_page.next_page
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# namespace_page.auto_paging_each do |client|
|
14
|
+
# puts(client)
|
15
|
+
# end
|
16
|
+
class NamespacePage
|
17
|
+
include Turbopuffer::Internal::Type::BasePage
|
18
|
+
|
19
|
+
# @return [Array<generic<Elem>>, nil]
|
20
|
+
attr_accessor :namespaces
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :next_cursor
|
24
|
+
|
25
|
+
# @return [Boolean]
|
26
|
+
def next_page?
|
27
|
+
!namespaces.to_a.empty? && !next_cursor.to_s.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
# @raise [Turbopuffer::HTTP::Error]
|
31
|
+
# @return [self]
|
32
|
+
def next_page
|
33
|
+
unless next_page?
|
34
|
+
message = "No more pages available. Please check #next_page? before calling ##{__method__}"
|
35
|
+
raise RuntimeError.new(message)
|
36
|
+
end
|
37
|
+
|
38
|
+
req = Turbopuffer::Internal::Util.deep_merge(@req, {query: {cursor: next_cursor}})
|
39
|
+
@client.request(req)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param blk [Proc]
|
43
|
+
#
|
44
|
+
# @yieldparam [generic<Elem>]
|
45
|
+
def auto_paging_each(&blk)
|
46
|
+
unless block_given?
|
47
|
+
raise ArgumentError.new("A block must be given to ##{__method__}")
|
48
|
+
end
|
49
|
+
|
50
|
+
page = self
|
51
|
+
loop do
|
52
|
+
page.namespaces&.each(&blk)
|
53
|
+
|
54
|
+
break unless page.next_page?
|
55
|
+
page = page.next_page
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# @api private
|
60
|
+
#
|
61
|
+
# @param client [Turbopuffer::Internal::Transport::BaseClient]
|
62
|
+
# @param req [Hash{Symbol=>Object}]
|
63
|
+
# @param headers [Hash{String=>String}, Net::HTTPHeader]
|
64
|
+
# @param page_data [Hash{Symbol=>Object}]
|
65
|
+
def initialize(client:, req:, headers:, page_data:)
|
66
|
+
super
|
67
|
+
|
68
|
+
case page_data
|
69
|
+
in {namespaces: Array => namespaces}
|
70
|
+
@namespaces = namespaces.map { Turbopuffer::Internal::Type::Converter.coerce(@model, _1) }
|
71
|
+
else
|
72
|
+
end
|
73
|
+
@next_cursor = page_data[:next_cursor]
|
74
|
+
end
|
75
|
+
|
76
|
+
# @api private
|
77
|
+
#
|
78
|
+
# @return [String]
|
79
|
+
def inspect
|
80
|
+
model = Turbopuffer::Internal::Type::Converter.inspect(@model, depth: 1)
|
81
|
+
|
82
|
+
"#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} next_cursor=#{next_cursor.inspect}>"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|