1 | import {RallyBase, lib, AbortError, Collection} from "./rally-tools.js";
|
2 | import {cached, defineAssoc} from "./decorators.js";
|
3 |
|
4 | class Tag extends RallyBase{
|
5 | constructor({data, remote} = {}){
|
6 | super();
|
7 |
|
8 | this.meta = {};
|
9 | this.remote = remote
|
10 | this.data = data;
|
11 |
|
12 |
|
13 |
|
14 | }
|
15 | chalkPrint(pad=true){
|
16 | let id = String("T-" + this.remote + "-" + this.id)
|
17 | if(pad) id = id.padStart(10);
|
18 |
|
19 | let prefix = this.curated ? "blue +" : "red -";
|
20 |
|
21 | return chalk`{green ${id}}: {${prefix}${this.name}}`;
|
22 | }
|
23 | static async create(env, name, {notCurated} = {}){
|
24 | return new Tag({data: await lib.makeAPIRequest({
|
25 | env, path: `/${this.endpoint}`, method: "POST",
|
26 | payload: {
|
27 | data: {
|
28 | attributes: {
|
29 | name,
|
30 | curated: notCurated ? false : true,
|
31 | },
|
32 | type: "tagNames",
|
33 | }
|
34 | }
|
35 | }), remote: env});
|
36 | }
|
37 | }
|
38 |
|
39 | defineAssoc(Tag, "id", "data.id");
|
40 | defineAssoc(Tag, "attributes", "data.attributes");
|
41 | defineAssoc(Tag, "relationships", "data.relationships");
|
42 | defineAssoc(Tag, "name", "data.attributes.name");
|
43 | defineAssoc(Tag, "curated", "data.attributes.curated");
|
44 | defineAssoc(Tag, "remote", "meta.remote");
|
45 | Tag.endpoint = "tagNames";
|
46 |
|
47 | export default Tag;
|