weaviate-ruby 0.9.2 → 0.10.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.
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ # Manage RBAC roles and their permissions. Requires RBAC to be enabled.
5
+ class Roles < Base
6
+ PATH = "authz/roles"
7
+
8
+ def list
9
+ response = client.connection.get(PATH)
10
+ response.body
11
+ end
12
+
13
+ def get(name:)
14
+ response = client.connection.get("#{PATH}/#{name}")
15
+ response.body
16
+ end
17
+
18
+ # @param permissions [Array<Hash>] e.g. [{ action: "read_data", data: { collection: "Products" } }]
19
+ def create(name:, permissions:)
20
+ response = client.connection.post(PATH) do |req|
21
+ req.body = {name: name, permissions: permissions}
22
+ end
23
+ response.success?
24
+ end
25
+
26
+ def delete(name:)
27
+ response = client.connection.delete("#{PATH}/#{name}")
28
+ response.success?
29
+ end
30
+
31
+ def add_permissions(name:, permissions:)
32
+ response = client.connection.post("#{PATH}/#{name}/add-permissions") do |req|
33
+ req.body = {permissions: permissions}
34
+ end
35
+ response.success?
36
+ end
37
+
38
+ def remove_permissions(name:, permissions:)
39
+ response = client.connection.post("#{PATH}/#{name}/remove-permissions") do |req|
40
+ req.body = {permissions: permissions}
41
+ end
42
+ response.success?
43
+ end
44
+
45
+ # @param permission [Hash] e.g. { action: "read_data", data: { collection: "Products" } }
46
+ def has_permission?(name:, permission:)
47
+ response = client.connection.post("#{PATH}/#{name}/has-permission") do |req|
48
+ req.body = permission
49
+ end
50
+ response.body == true
51
+ end
52
+
53
+ # Users the role is assigned to.
54
+ def user_assignments(name:)
55
+ response = client.connection.get("#{PATH}/#{name}/user-assignments")
56
+ response.body
57
+ end
58
+
59
+ # Groups the role is assigned to.
60
+ def group_assignments(name:)
61
+ response = client.connection.get("#{PATH}/#{name}/group-assignments")
62
+ response.body
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ # Manage database users and their roles. Requires RBAC to be enabled.
5
+ class Users < Base
6
+ PATH = "users"
7
+ USER_TYPES = %w[db oidc].freeze
8
+
9
+ # Information about the current user.
10
+ def own_info
11
+ response = client.connection.get("#{PATH}/own-info")
12
+ response.body
13
+ end
14
+
15
+ def list(include_last_used_time: nil)
16
+ response = client.connection.get("#{PATH}/db") do |req|
17
+ req.params["includeLastUsedTime"] = include_last_used_time unless include_last_used_time.nil?
18
+ end
19
+ response.body
20
+ end
21
+
22
+ def get(user_id:, include_last_used_time: nil)
23
+ response = client.connection.get("#{PATH}/db/#{user_id}") do |req|
24
+ req.params["includeLastUsedTime"] = include_last_used_time unless include_last_used_time.nil?
25
+ end
26
+ response.body
27
+ end
28
+
29
+ # Create a database user. The response contains the user's API key.
30
+ def create(user_id:)
31
+ response = client.connection.post("#{PATH}/db/#{user_id}")
32
+ response.body
33
+ end
34
+
35
+ def delete(user_id:)
36
+ response = client.connection.delete("#{PATH}/db/#{user_id}")
37
+ response.success?
38
+ end
39
+
40
+ def activate(user_id:)
41
+ response = client.connection.post("#{PATH}/db/#{user_id}/activate")
42
+ response.success?
43
+ end
44
+
45
+ # @param revoke_key [Boolean] Also revoke the user's API key
46
+ def deactivate(user_id:, revoke_key: nil)
47
+ response = client.connection.post("#{PATH}/db/#{user_id}/deactivate") do |req|
48
+ req.body = {revoke_key: revoke_key} unless revoke_key.nil?
49
+ end
50
+ response.success?
51
+ end
52
+
53
+ # Rotate a user's API key. The response contains the new key.
54
+ def rotate_key(user_id:)
55
+ response = client.connection.post("#{PATH}/db/#{user_id}/rotate-key")
56
+ response.body
57
+ end
58
+
59
+ # @param user_type [String] "db" or "oidc"
60
+ def roles(user_id:, user_type: "db", include_full_roles: nil)
61
+ validate_user_type!(user_type)
62
+
63
+ response = client.connection.get("authz/users/#{user_id}/roles/#{user_type}") do |req|
64
+ req.params["includeFullRoles"] = include_full_roles unless include_full_roles.nil?
65
+ end
66
+ response.body
67
+ end
68
+
69
+ def assign_roles(user_id:, roles:, user_type: "db")
70
+ update_roles(user_id, "assign", roles, user_type)
71
+ end
72
+
73
+ def revoke_roles(user_id:, roles:, user_type: "db")
74
+ update_roles(user_id, "revoke", roles, user_type)
75
+ end
76
+
77
+ private
78
+
79
+ def update_roles(user_id, action, roles, user_type)
80
+ validate_user_type!(user_type)
81
+
82
+ response = client.connection.post("authz/users/#{user_id}/#{action}") do |req|
83
+ req.body = {roles: Array(roles), userType: user_type}
84
+ end
85
+ response.success?
86
+ end
87
+
88
+ def validate_user_type!(user_type)
89
+ unless USER_TYPES.include?(user_type.to_s)
90
+ raise ArgumentError, 'user_type must be either "db" or "oidc"'
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- VERSION = "0.9.2"
4
+ VERSION = "0.10.0"
5
5
  end
data/lib/weaviate.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "weaviate/version"
4
+ require_relative "weaviate/error"
4
5
 
5
6
  module Weaviate
6
7
  autoload :Base, "weaviate/base"
7
8
  autoload :Client, "weaviate/client"
8
- autoload :Error, "weaviate/error"
9
- autoload :Schema, "weaviate/schema"
9
+ autoload :Connection, "weaviate/connection"
10
+ autoload :Collections, "weaviate/collections"
11
+ autoload :Schema, "weaviate/collections"
12
+ autoload :GraphQL, "weaviate/graphql"
10
13
  autoload :Meta, "weaviate/meta"
11
14
  autoload :Objects, "weaviate/objects"
12
15
  autoload :OIDC, "weaviate/oidc"
@@ -15,4 +18,8 @@ module Weaviate
15
18
  autoload :Health, "weaviate/health"
16
19
  autoload :Classifications, "weaviate/classifications"
17
20
  autoload :Backups, "weaviate/backups"
21
+ autoload :Aliases, "weaviate/aliases"
22
+ autoload :Users, "weaviate/users"
23
+ autoload :Roles, "weaviate/roles"
24
+ autoload :Groups, "weaviate/groups"
18
25
  end
data/sig/weaviate.rbs CHANGED
@@ -1,4 +1,422 @@
1
1
  module Weaviate
2
2
  VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
3
+
4
+ # Parsed JSON returned by Weaviate
5
+ type json = untyped
6
+
7
+ # A raw GraphQL string, or a Ruby value serialized to GraphQL
8
+ type graphql_argument = String | Hash[untyped, untyped] | Array[untyped]
9
+
10
+ type consistency_level = String | Symbol
11
+
12
+ class Error < StandardError
13
+ end
14
+
15
+ class ConnectionFailed < Error
16
+ end
17
+
18
+ class TimeoutError < ConnectionFailed
19
+ end
20
+
21
+ class HTTPError < Error
22
+ attr_reader response: Connection::Response?
23
+
24
+ def initialize: (?String? message, ?response: Connection::Response?) -> void
25
+ def status: () -> Integer?
26
+ def body: () -> json
27
+ end
28
+
29
+ class ClientError < HTTPError
30
+ end
31
+
32
+ class BadRequestError < ClientError
33
+ end
34
+
35
+ class UnauthorizedError < ClientError
36
+ end
37
+
38
+ class ForbiddenError < ClientError
39
+ end
40
+
41
+ class ResourceNotFound < ClientError
42
+ end
43
+
44
+ class ConflictError < ClientError
45
+ end
46
+
47
+ class UnprocessableEntityError < ClientError
48
+ end
49
+
50
+ class ServerError < HTTPError
51
+ end
52
+
53
+ class GraphQLError < Error
54
+ attr_reader errors: Array[Hash[String, untyped]]
55
+
56
+ def initialize: (Array[Hash[String, untyped]] errors) -> void
57
+ end
58
+
59
+ class Client
60
+ API_VERSION: String
61
+ API_KEY_HEADERS: Hash[Symbol, String]
62
+
63
+ attr_reader url: String
64
+ attr_reader api_key: String?
65
+ attr_reader model_service: Symbol?
66
+ attr_reader model_service_api_key: String?
67
+ attr_reader headers: Hash[String, String]
68
+ attr_reader proxy: String?
69
+ attr_reader logger: Logger
70
+ attr_reader open_timeout: Numeric?
71
+ attr_reader read_timeout: Numeric?
72
+ attr_reader write_timeout: Numeric?
73
+
74
+ def initialize: (
75
+ url: String,
76
+ ?api_key: String?,
77
+ ?model_service: Symbol?,
78
+ ?model_service_api_key: String?,
79
+ ?headers: Hash[String, String],
80
+ ?proxy: String?,
81
+ ?logger: Logger?,
82
+ ?open_timeout: Numeric?,
83
+ ?read_timeout: Numeric?,
84
+ ?write_timeout: Numeric?,
85
+ ?adapter: untyped
86
+ ) -> void
87
+
88
+ def oidc: () -> json
89
+ def collections: () -> Collections
90
+ def schema: () -> Collections
91
+ def meta: () -> json
92
+ def nodes: (?output: String?, ?class_name: String?, ?shard_name: String?) -> json
93
+ def live?: () -> bool
94
+ def ready?: () -> bool
95
+ def backups: () -> Backups
96
+ def classifications: () -> Classifications
97
+ def objects: () -> Objects
98
+ def query: () -> Query
99
+ def aliases: () -> Aliases
100
+ def users: () -> Users
101
+ def roles: () -> Roles
102
+ def groups: () -> Groups
103
+ def graphql: () -> GraphQL
104
+ def connection: () -> Connection
105
+ end
106
+
107
+ class Connection
108
+ class Request < Struct[untyped]
109
+ attr_accessor params: Hash[String, untyped]
110
+ attr_accessor headers: Hash[String, String]
111
+ attr_accessor body: untyped
112
+ end
113
+
114
+ class Response < Struct[untyped]
115
+ attr_accessor status: Integer
116
+ attr_accessor reason_phrase: String
117
+ attr_accessor headers: Hash[String, Array[String]]
118
+ attr_accessor body: json
119
+
120
+ def success?: () -> bool
121
+ end
122
+
123
+ attr_reader url: String
124
+ attr_reader headers: Hash[String, String]
125
+ attr_reader logger: Logger?
126
+ attr_reader proxy: URI::Generic?
127
+ attr_reader timeouts: Hash[Symbol, Numeric]
128
+
129
+ def initialize: (
130
+ url: String,
131
+ ?headers: Hash[String, String],
132
+ ?logger: Logger?,
133
+ ?proxy: String?,
134
+ ?open_timeout: Numeric?,
135
+ ?read_timeout: Numeric?,
136
+ ?write_timeout: Numeric?
137
+ ) -> void
138
+
139
+ def get: (String path) ?{ (Request) -> void } -> Response
140
+ def head: (String path) ?{ (Request) -> void } -> Response
141
+ def post: (String path) ?{ (Request) -> void } -> Response
142
+ def put: (String path) ?{ (Request) -> void } -> Response
143
+ def patch: (String path) ?{ (Request) -> void } -> Response
144
+ def delete: (String path) ?{ (Request) -> void } -> Response
145
+ end
146
+
147
+ class Base
148
+ attr_reader client: Client
149
+
150
+ def initialize: (client: Client) -> void
151
+ end
152
+
153
+ class GraphQL < Base
154
+ def execute: (String query) -> json
155
+ end
156
+
157
+ class Collections < Base
158
+ def list: () -> json
159
+ def get: (class_name: String) -> json
160
+
161
+ def create: (
162
+ class_name: String,
163
+ ?description: String?,
164
+ ?properties: Array[Hash[untyped, untyped]]?,
165
+ ?multi_tenant: bool,
166
+ ?auto_tenant_creation: bool,
167
+ ?auto_tenant_activation: bool,
168
+ ?vector_index_type: String?,
169
+ ?vector_index_config: Hash[untyped, untyped]?,
170
+ ?vectorizer: String?,
171
+ ?module_config: Hash[untyped, untyped]?,
172
+ ?inverted_index_config: Hash[untyped, untyped]?,
173
+ ?replication_config: Hash[untyped, untyped]?,
174
+ ?vector_config: Hash[untyped, untyped]?
175
+ ) -> json
176
+
177
+ def update: (
178
+ class_name: String,
179
+ ?description: String?,
180
+ ?vector_index_type: String?,
181
+ ?vector_index_config: Hash[untyped, untyped]?,
182
+ ?vectorizer: String?,
183
+ ?module_config: Hash[untyped, untyped]?,
184
+ ?properties: Array[Hash[untyped, untyped]]?,
185
+ ?inverted_index_config: Hash[untyped, untyped]?,
186
+ ?replication_config: Hash[untyped, untyped]?,
187
+ ?vector_config: Hash[untyped, untyped]?
188
+ ) -> json
189
+
190
+ def delete: (class_name: String) -> bool
191
+ def add_property: (class_name: String, property: Hash[untyped, untyped]) -> json
192
+ def add_tenants: (class_name: String, tenants: Array[String | Hash[untyped, untyped]]) -> json
193
+ def update_tenants: (class_name: String, tenants: Array[String | Hash[untyped, untyped]]) -> json
194
+ def get_tenant: (class_name: String, tenant: String) -> json
195
+ def tenant_exists?: (class_name: String, tenant: String) -> bool
196
+ def list_tenants: (class_name: String) -> json
197
+ def remove_tenants: (class_name: String, tenants: Array[String]) -> json
198
+ def shards: (class_name: String, ?tenant: String?) -> json
199
+ def update_shard_status: (class_name: String, shard_name: String, status: String) -> json
200
+ end
201
+
202
+ Schema: singleton(Collections)
203
+
204
+ class Objects < Base
205
+ def list: (
206
+ ?class_name: String?,
207
+ ?limit: Integer?,
208
+ ?tenant: String?,
209
+ ?offset: Integer?,
210
+ ?after: String?,
211
+ ?include: String?,
212
+ ?sort: String?,
213
+ ?order: String?
214
+ ) -> json
215
+
216
+ def create: (
217
+ class_name: String,
218
+ properties: Hash[untyped, untyped],
219
+ ?tenant: String?,
220
+ ?consistency_level: consistency_level?,
221
+ ?id: String?,
222
+ ?vector: Array[Float]?
223
+ ) -> json
224
+
225
+ def batch_create: (objects: Array[Hash[untyped, untyped]], ?consistency_level: consistency_level?, ?tenant: String?) -> json
226
+ def get: (class_name: String, id: String, ?include: String?, ?consistency_level: consistency_level?, ?tenant: String?) -> json
227
+ def exists?: (class_name: String, id: String, ?consistency_level: consistency_level?, ?tenant: String?) -> bool
228
+
229
+ def update: (
230
+ class_name: String,
231
+ id: String,
232
+ properties: Hash[untyped, untyped],
233
+ ?vector: Array[Float]?,
234
+ ?tenant: String?,
235
+ ?consistency_level: consistency_level?
236
+ ) -> json
237
+
238
+ def replace: (
239
+ class_name: String,
240
+ id: String,
241
+ properties: Hash[untyped, untyped],
242
+ ?vector: Array[Float]?,
243
+ ?tenant: String?,
244
+ ?consistency_level: consistency_level?
245
+ ) -> json
246
+
247
+ def delete: (class_name: String, id: String, ?consistency_level: consistency_level?, ?tenant: String?) -> bool
248
+
249
+ def batch_delete: (
250
+ class_name: String,
251
+ where: Hash[untyped, untyped],
252
+ ?consistency_level: consistency_level?,
253
+ ?output: String?,
254
+ ?dry_run: bool?,
255
+ ?tenant: String?
256
+ ) -> json
257
+
258
+ def add_reference: (
259
+ class_name: String,
260
+ id: String,
261
+ property: String,
262
+ to_class_name: String,
263
+ to_id: String,
264
+ ?tenant: String?,
265
+ ?consistency_level: consistency_level?
266
+ ) -> bool
267
+
268
+ def replace_references: (
269
+ class_name: String,
270
+ id: String,
271
+ property: String,
272
+ to: Array[{ class_name: String, id: String }],
273
+ ?tenant: String?,
274
+ ?consistency_level: consistency_level?
275
+ ) -> bool
276
+
277
+ def delete_reference: (
278
+ class_name: String,
279
+ id: String,
280
+ property: String,
281
+ to_class_name: String,
282
+ to_id: String,
283
+ ?tenant: String?,
284
+ ?consistency_level: consistency_level?
285
+ ) -> bool
286
+
287
+ def batch_create_references: (references: Array[Hash[Symbol, String]], ?consistency_level: consistency_level?) -> json
288
+ def validate: (class_name: String, properties: Hash[untyped, untyped], ?id: String?) -> bool
289
+ end
290
+
291
+ class Query < Base
292
+ def get: (
293
+ class_name: String,
294
+ fields: String,
295
+ ?after: String?,
296
+ ?tenant: String?,
297
+ ?limit: Integer | String | nil,
298
+ ?autocut: Integer | String | nil,
299
+ ?offset: Integer | String | nil,
300
+ ?sort: graphql_argument?,
301
+ ?where: graphql_argument?,
302
+ ?near_text: graphql_argument?,
303
+ ?near_vector: graphql_argument?,
304
+ ?near_image: graphql_argument?,
305
+ ?near_object: graphql_argument?,
306
+ ?with_hybrid: graphql_argument?,
307
+ ?bm25: graphql_argument?,
308
+ ?ask: graphql_argument?,
309
+ ?group_by: graphql_argument?
310
+ ) -> json
311
+
312
+ def aggs: (
313
+ class_name: String,
314
+ ?fields: String?,
315
+ ?tenant: String?,
316
+ ?where: graphql_argument?,
317
+ ?object_limit: Integer | String | nil,
318
+ ?near_text: graphql_argument?,
319
+ ?near_vector: graphql_argument?,
320
+ ?near_image: graphql_argument?,
321
+ ?near_object: graphql_argument?,
322
+ ?group_by: Array[String] | String | nil,
323
+ ?limit: Integer | String | nil,
324
+ ?with_hybrid: graphql_argument?
325
+ ) -> json
326
+
327
+ # @deprecated
328
+ def explore: (
329
+ fields: String,
330
+ ?after: String?,
331
+ ?limit: Integer | String | nil,
332
+ ?offset: Integer | String | nil,
333
+ ?sort: graphql_argument?,
334
+ ?where: graphql_argument?,
335
+ ?near_text: graphql_argument?,
336
+ ?near_vector: graphql_argument?,
337
+ ?near_image: graphql_argument?,
338
+ ?near_object: graphql_argument?
339
+ ) -> json
340
+ end
341
+
342
+ class Backups < Base
343
+ def list: (backend: String, ?order: String?) -> json
344
+ def create: (backend: String, id: String, ?include: Array[String]?, ?exclude: Array[String]?, ?config: Hash[untyped, untyped]?) -> json
345
+ def get: (backend: String, id: String, ?bucket: String?, ?path: String?) -> json
346
+ def cancel: (backend: String, id: String, ?bucket: String?, ?path: String?) -> bool
347
+ def restore: (backend: String, id: String, ?include: Array[String]?, ?exclude: Array[String]?, ?config: Hash[untyped, untyped]?) -> json
348
+ def restore_status: (backend: String, id: String, ?bucket: String?, ?path: String?) -> json
349
+ def cancel_restore: (backend: String, id: String, ?bucket: String?, ?path: String?) -> bool
350
+ end
351
+
352
+ class Classifications < Base
353
+ def get: (id: String) -> json
354
+
355
+ def create: (
356
+ class_name: String,
357
+ type: String,
358
+ ?classify_properties: Array[String]?,
359
+ ?based_on_properties: Array[String]?,
360
+ ?settings: Hash[untyped, untyped]?,
361
+ ?filters: Hash[untyped, untyped]?
362
+ ) -> json
363
+ end
364
+
365
+ class Nodes < Base
366
+ def list: (?output: String?, ?class_name: String?, ?shard_name: String?) -> json
367
+ end
368
+
369
+ class Health < Base
370
+ def live?: () -> bool
371
+ def ready?: () -> bool
372
+ end
373
+
374
+ class Meta < Base
375
+ def get: () -> json
376
+ end
377
+
378
+ class OIDC < Base
379
+ def get: () -> json
380
+ end
381
+
382
+ class Aliases < Base
383
+ def list: (?class_name: String?) -> json
384
+ def create: (alias_name: String, class_name: String) -> json
385
+ def get: (alias_name: String) -> json
386
+ def update: (alias_name: String, class_name: String) -> json
387
+ def delete: (alias_name: String) -> bool
388
+ end
389
+
390
+ class Users < Base
391
+ def own_info: () -> json
392
+ def list: (?include_last_used_time: bool?) -> json
393
+ def get: (user_id: String, ?include_last_used_time: bool?) -> json
394
+ def create: (user_id: String) -> json
395
+ def delete: (user_id: String) -> bool
396
+ def activate: (user_id: String) -> bool
397
+ def deactivate: (user_id: String, ?revoke_key: bool?) -> bool
398
+ def rotate_key: (user_id: String) -> json
399
+ def roles: (user_id: String, ?user_type: String, ?include_full_roles: bool?) -> json
400
+ def assign_roles: (user_id: String, roles: Array[String] | String, ?user_type: String) -> bool
401
+ def revoke_roles: (user_id: String, roles: Array[String] | String, ?user_type: String) -> bool
402
+ end
403
+
404
+ class Roles < Base
405
+ def list: () -> json
406
+ def get: (name: String) -> json
407
+ def create: (name: String, permissions: Array[Hash[untyped, untyped]]) -> bool
408
+ def delete: (name: String) -> bool
409
+ def add_permissions: (name: String, permissions: Array[Hash[untyped, untyped]]) -> bool
410
+ def remove_permissions: (name: String, permissions: Array[Hash[untyped, untyped]]) -> bool
411
+ def has_permission?: (name: String, permission: Hash[untyped, untyped]) -> bool
412
+ def user_assignments: (name: String) -> json
413
+ def group_assignments: (name: String) -> json
414
+ end
415
+
416
+ class Groups < Base
417
+ def list: () -> json
418
+ def roles: (group_id: String, ?include_full_roles: bool?) -> json
419
+ def assign_roles: (group_id: String, roles: Array[String] | String) -> bool
420
+ def revoke_roles: (group_id: String, roles: Array[String] | String) -> bool
421
+ end
4
422
  end