UNPKG

1.48 kBJavaScriptView Raw
1import {RallyBase, lib, AbortError, Collection} from "./rally-tools.js";
2import {cached, defineAssoc} from "./decorators.js";
3
4class Tag extends RallyBase{
5 constructor({data, remote} = {}){
6 super();
7
8 this.meta = {};
9 this.remote = remote
10 this.data = data;
11
12 //this.data.attributes.rallyConfiguration = undefined;
13 //this.data.attributes.systemManaged = undefined;
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
39defineAssoc(Tag, "id", "data.id");
40defineAssoc(Tag, "attributes", "data.attributes");
41defineAssoc(Tag, "relationships", "data.relationships");
42defineAssoc(Tag, "name", "data.attributes.name");
43defineAssoc(Tag, "curated", "data.attributes.curated");
44defineAssoc(Tag, "remote", "meta.remote");
45Tag.endpoint = "tagNames";
46
47export default Tag;