@@ -121,6 +121,15 @@ const roles = (connection: ConnectionREST): Roles => {
121
121
} ;
122
122
123
123
export const permissions = {
124
+ /**
125
+ * Create a set of permissions specific to Weaviate's backup functionality.
126
+ *
127
+ * For all collections, provide the `collection` argument as `'*'`.
128
+ *
129
+ * @param {string | string[] } args.collection The collection or collections to create permissions for.
130
+ * @param {boolean } [args.manage] Whether to allow managing backups. Defaults to `false`.
131
+ * @returns {BackupsPermission[] } The permissions for the specified collections.
132
+ */
124
133
backup : ( args : { collection : string | string [ ] ; manage ?: boolean } ) : BackupsPermission [ ] => {
125
134
const collections = Array . isArray ( args . collection ) ? args . collection : [ args . collection ] ;
126
135
return collections . flatMap ( ( collection ) => {
@@ -129,11 +138,27 @@ export const permissions = {
129
138
return out ;
130
139
} ) ;
131
140
} ,
141
+ /**
142
+ * Create a set of permissions specific to Weaviate's cluster endpoints.
143
+ *
144
+ * @param {boolean } [args.read] Whether to allow reading cluster information. Defaults to `false`.
145
+ */
132
146
cluster : ( args : { read ?: boolean } ) : ClusterPermission [ ] => {
133
147
const out : ClusterPermission = { actions : [ ] } ;
134
148
if ( args . read ) out . actions . push ( 'read_cluster' ) ;
135
149
return [ out ] ;
136
150
} ,
151
+ /**
152
+ * Create a set of permissions specific to any operations involving collections.
153
+ *
154
+ * For all collections, provide the `collection` argument as `'*'`.
155
+ *
156
+ * @param {string | string[] } args.collection The collection or collections to create permissions for.
157
+ * @param {boolean } [args.create_collection] Whether to allow creating collections. Defaults to `false`.
158
+ * @param {boolean } [args.read_config] Whether to allow reading collection configurations. Defaults to `false`.
159
+ * @param {boolean } [args.update_config] Whether to allow updating collection configurations. Defaults to `false`.
160
+ * @param {boolean } [args.delete_collection] Whether to allow deleting collections. Defaults to `false`.
161
+ */
137
162
collections : ( args : {
138
163
collection : string | string [ ] ;
139
164
create_collection ?: boolean ;
@@ -151,24 +176,54 @@ export const permissions = {
151
176
return out ;
152
177
} ) ;
153
178
} ,
179
+ /**
180
+ * Create a set of permissions specific to any operations involving objects within collections and tenants.
181
+ *
182
+ * For all collections, provide the `collection` argument as `'*'`.
183
+ * For all tenants, provide the `tenant` argument as `'*'`.
184
+ *
185
+ * Providing arrays of collections and tenants will create permissions for each combination of collection and tenant.
186
+ * E.g., `data({ collection: ['A', 'B'], tenant: ['X', 'Y'] })` will create permissions for tenants `X` and `Y` in both collections `A` and `B`.
187
+ *
188
+ * @param {string | string[] } args.collection The collection or collections to create permissions for.
189
+ * @param {string | string[] } [args.tenant] The tenant or tenants to create permissions for. Defaults to `'*'`.
190
+ * @param {boolean } [args.create] Whether to allow creating objects. Defaults to `false`.
191
+ * @param {boolean } [args.read] Whether to allow reading objects. Defaults to `false`.
192
+ * @param {boolean } [args.update] Whether to allow updating objects. Defaults to `false`.
193
+ * @param {boolean } [args.delete] Whether to allow deleting objects. Defaults to `false`.
194
+ */
154
195
data : ( args : {
155
196
collection : string | string [ ] ;
197
+ tenant ?: string | string [ ] ;
156
198
create ?: boolean ;
157
199
read ?: boolean ;
158
200
update ?: boolean ;
159
201
delete ?: boolean ;
160
202
} ) : DataPermission [ ] => {
161
203
const collections = Array . isArray ( args . collection ) ? args . collection : [ args . collection ] ;
162
- return collections . flatMap ( ( collection ) => {
163
- const out : DataPermission = { collection, actions : [ ] } ;
204
+ const tenants = Array . isArray ( args . tenant ) ? args . tenant : [ args . tenant ?? '*' ] ;
205
+ const combinations = collections . flatMap ( ( collection ) =>
206
+ tenants . map ( ( tenant ) => ( { collection, tenant } ) )
207
+ ) ;
208
+ return combinations . flatMap ( ( { collection, tenant } ) => {
209
+ const out : DataPermission = { collection, tenant, actions : [ ] } ;
164
210
if ( args . create ) out . actions . push ( 'create_data' ) ;
165
211
if ( args . read ) out . actions . push ( 'read_data' ) ;
166
212
if ( args . update ) out . actions . push ( 'update_data' ) ;
167
213
if ( args . delete ) out . actions . push ( 'delete_data' ) ;
168
214
return out ;
169
215
} ) ;
170
216
} ,
217
+ /**
218
+ * This namespace contains methods to create permissions specific to nodes.
219
+ */
171
220
nodes : {
221
+ /**
222
+ * Create a set of permissions specific to reading nodes with verbosity set to `minimal`.
223
+ *
224
+ * @param {boolean } [args.read] Whether to allow reading nodes. Defaults to `false`.
225
+ * @returns {NodesPermission[] } The permissions for reading nodes.
226
+ */
172
227
minimal : ( args : { read ?: boolean } ) : NodesPermission [ ] => {
173
228
const out : NodesPermission = {
174
229
collection : '*' ,
@@ -178,6 +233,13 @@ export const permissions = {
178
233
if ( args . read ) out . actions . push ( 'read_nodes' ) ;
179
234
return [ out ] ;
180
235
} ,
236
+ /**
237
+ * Create a set of permissions specific to reading nodes with verbosity set to `verbose`.
238
+ *
239
+ * @param {string | string[] } args.collection The collection or collections to create permissions for.
240
+ * @param {boolean } [args.read] Whether to allow reading nodes. Defaults to `false`.
241
+ * @returns {NodesPermission[] } The permissions for reading nodes.
242
+ */
181
243
verbose : ( args : { collection : string | string [ ] ; read ?: boolean } ) : NodesPermission [ ] => {
182
244
const collections = Array . isArray ( args . collection ) ? args . collection : [ args . collection ] ;
183
245
return collections . flatMap ( ( collection ) => {
@@ -191,6 +253,16 @@ export const permissions = {
191
253
} ) ;
192
254
} ,
193
255
} ,
256
+ /**
257
+ * Create a set of permissions specific to any operations involving roles.
258
+ *
259
+ * @param {string | string[] } args.role The role or roles to create permissions for.
260
+ * @param {boolean } [args.create] Whether to allow creating roles. Defaults to `false`.
261
+ * @param {boolean } [args.read] Whether to allow reading roles. Defaults to `false`.
262
+ * @param {boolean } [args.update] Whether to allow updating roles. Defaults to `false`.
263
+ * @param {boolean } [args.delete] Whether to allow deleting roles. Defaults to `false`.
264
+ * @returns {RolesPermission[] } The permissions for the specified roles.
265
+ */
194
266
roles : ( args : {
195
267
role : string | string [ ] ;
196
268
create ?: boolean ;
@@ -208,32 +280,62 @@ export const permissions = {
208
280
return out ;
209
281
} ) ;
210
282
} ,
283
+ /**
284
+ * Create a set of permissions specific to any operations involving tenants.
285
+ *
286
+ * For all collections, provide the `collection` argument as `'*'`.
287
+ * For all tenants, provide the `tenant` argument as `'*'`.
288
+ *
289
+ * Providing arrays of collections and tenants will create permissions for each combination of collection and tenant.
290
+ * E.g., `tenants({ collection: ['A', 'B'], tenant: ['X', 'Y'] })` will create permissions for tenants `X` and `Y` in both collections `A` and `B`.
291
+ *
292
+ * @param {string | string[] | Record<string, string | string[]> } args.collection The collection or collections to create permissions for.
293
+ * @param {string | string[] } [args.tenant] The tenant or tenants to create permissions for. Defaults to `'*'`.
294
+ * @param {boolean } [args.create] Whether to allow creating tenants. Defaults to `false`.
295
+ * @param {boolean } [args.read] Whether to allow reading tenants. Defaults to `false`.
296
+ * @param {boolean } [args.update] Whether to allow updating tenants. Defaults to `false`.
297
+ * @param {boolean } [args.delete] Whether to allow deleting tenants. Defaults to `false`.
298
+ * @returns {TenantsPermission[] } The permissions for the specified tenants.
299
+ */
211
300
tenants : ( args : {
212
301
collection : string | string [ ] ;
302
+ tenant ?: string | string [ ] ;
213
303
create ?: boolean ;
214
304
read ?: boolean ;
215
305
update ?: boolean ;
216
306
delete ?: boolean ;
217
307
} ) : TenantsPermission [ ] => {
218
308
const collections = Array . isArray ( args . collection ) ? args . collection : [ args . collection ] ;
219
- return collections . flatMap ( ( collection ) => {
220
- const out : TenantsPermission = { collection, actions : [ ] } ;
309
+ const tenants = Array . isArray ( args . tenant ) ? args . tenant : [ args . tenant ?? '*' ] ;
310
+ const combinations = collections . flatMap ( ( collection ) =>
311
+ tenants . map ( ( tenant ) => ( { collection, tenant } ) )
312
+ ) ;
313
+ return combinations . flatMap ( ( { collection, tenant } ) => {
314
+ const out : TenantsPermission = { collection, tenant, actions : [ ] } ;
221
315
if ( args . create ) out . actions . push ( 'create_tenants' ) ;
222
316
if ( args . read ) out . actions . push ( 'read_tenants' ) ;
223
317
if ( args . update ) out . actions . push ( 'update_tenants' ) ;
224
318
if ( args . delete ) out . actions . push ( 'delete_tenants' ) ;
225
319
return out ;
226
320
} ) ;
227
321
} ,
322
+ /**
323
+ * Create a set of permissions specific to any operations involving users.
324
+ *
325
+ * @param {string | string[] } args.user The user or users to create permissions for.
326
+ * @param {boolean } [args.assignAndRevoke] Whether to allow assigning and revoking users. Defaults to `false`.
327
+ * @param {boolean } [args.read] Whether to allow reading users. Defaults to `false`.
328
+ * @returns {UsersPermission[] } The permissions for the specified users.
329
+ */
228
330
users : ( args : {
229
331
user : string | string [ ] ;
230
- assign_and_revoke ?: boolean ;
332
+ assignAndRevoke ?: boolean ;
231
333
read ?: boolean ;
232
334
} ) : UsersPermission [ ] => {
233
335
const users = Array . isArray ( args . user ) ? args . user : [ args . user ] ;
234
336
return users . flatMap ( ( user ) => {
235
337
const out : UsersPermission = { users : user , actions : [ ] } ;
236
- if ( args . assign_and_revoke ) out . actions . push ( 'assign_and_revoke_users' ) ;
338
+ if ( args . assignAndRevoke ) out . actions . push ( 'assign_and_revoke_users' ) ;
237
339
if ( args . read ) out . actions . push ( 'read_users' ) ;
238
340
return out ;
239
341
} ) ;
0 commit comments