-
Notifications
You must be signed in to change notification settings - Fork 585
/
crate.js
74 lines (64 loc) · 2.1 KB
/
crate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Model, { attr, hasMany } from '@ember-data/model';
import { apiAction } from '@mainmatter/ember-api-actions';
export default class Crate extends Model {
@attr name;
@attr downloads;
@attr recent_downloads;
@attr('date') created_at;
@attr('date') updated_at;
@attr max_version;
@attr max_stable_version;
@attr newest_version;
@attr description;
@attr homepage;
@attr documentation;
@attr repository;
@hasMany('version', { async: true, inverse: 'crate' }) versions;
@hasMany('team', { async: true, inverse: null }) owner_team;
@hasMany('user', { async: true, inverse: null }) owner_user;
@hasMany('version-download', { async: true, inverse: null }) version_downloads;
@hasMany('keyword', { async: true, inverse: null }) keywords;
@hasMany('category', { async: true, inverse: null }) categories;
@hasMany('dependency', { async: true, inverse: null }) reverse_dependencies;
/**
* This is the default version that will be shown when visiting the crate
* details page. Note that this can be `undefined` if all versions of the crate
* have been yanked.
* @return {string}
*/
get defaultVersion() {
if (this.max_stable_version) {
return this.max_stable_version;
}
if (this.max_version && this.max_version !== '0.0.0') {
return this.max_version;
}
}
get owners() {
let teams = this.owner_team.toArray() ?? [];
let users = this.owner_user.toArray() ?? [];
return [...teams, ...users];
}
async follow() {
return await apiAction(this, { method: 'PUT', path: 'follow' });
}
async unfollow() {
return await apiAction(this, { method: 'DELETE', path: 'follow' });
}
async inviteOwner(username) {
let response = await apiAction(this, { method: 'PUT', path: 'owners', data: { owners: [username] } });
if (response.ok) {
return response;
} else {
throw response;
}
}
async removeOwner(username) {
let response = await apiAction(this, { method: 'DELETE', path: 'owners', data: { owners: [username] } });
if (response.ok) {
return response;
} else {
throw response;
}
}
}