elections-types 1.0.33 → 1.0.35

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.
@@ -2,6 +2,7 @@ export * from "./types/APIError.js";
2
2
  export * from "./types/Article.js";
3
3
  export * from "./types/Candidate.js";
4
4
  export * from "./types/CandidateArticle.js";
5
+ export * from "./types/CandidateVideo.js";
5
6
  export * from "./types/Committee.js";
6
7
  export * from "./types/Donation.js";
7
8
  export * from "./types/Election.js";
package/dist/src/index.js CHANGED
@@ -2,6 +2,7 @@ export * from "./types/APIError.js";
2
2
  export * from "./types/Article.js";
3
3
  export * from "./types/Candidate.js";
4
4
  export * from "./types/CandidateArticle.js";
5
+ export * from "./types/CandidateVideo.js";
5
6
  export * from "./types/Committee.js";
6
7
  export * from "./types/Donation.js";
7
8
  export * from "./types/Election.js";
@@ -0,0 +1,9 @@
1
+ export declare class CandidateVideo {
2
+ readonly candidate_id: string;
3
+ readonly video_id: string;
4
+ readonly title: string;
5
+ readonly fetch_time: string;
6
+ readonly relevance?: string;
7
+ constructor(candidate_video: any);
8
+ static is(candidate_video: any): candidate_video is CandidateVideo;
9
+ }
@@ -0,0 +1,25 @@
1
+ export class CandidateVideo {
2
+ candidate_id;
3
+ video_id;
4
+ title;
5
+ fetch_time;
6
+ relevance;
7
+ constructor(candidate_video) {
8
+ if (!CandidateVideo.is(candidate_video)) {
9
+ throw Error("Invalid input.");
10
+ }
11
+ this.candidate_id = candidate_video.candidate_id;
12
+ this.video_id = candidate_video.video_id;
13
+ this.title = candidate_video.title;
14
+ this.fetch_time = candidate_video.fetch_time;
15
+ this.relevance = candidate_video.relevance;
16
+ }
17
+ static is(candidate_video) {
18
+ return (candidate_video !== undefined &&
19
+ typeof candidate_video.candidate_id === "string" &&
20
+ typeof candidate_video.video_id === "string" &&
21
+ typeof candidate_video.title === "string" &&
22
+ typeof candidate_video.fetch_time === "string" &&
23
+ (candidate_video.relevance === undefined || typeof candidate_video.relevance === "string"));
24
+ }
25
+ }
@@ -7,7 +7,7 @@ export declare class Video {
7
7
  readonly title: string;
8
8
  readonly description: string;
9
9
  readonly tags?: string[];
10
- readonly duration: number;
10
+ readonly duration?: number;
11
11
  readonly fetch_time: string;
12
12
  constructor(video: any);
13
13
  static is(video: any): video is Video;
@@ -34,7 +34,7 @@ export class Video {
34
34
  typeof video.title === "string" &&
35
35
  typeof video.description === "string" &&
36
36
  (video.tags === undefined || Array.isArray(video.tags) && video.tags.map((tag) => typeof tag === "string")) &&
37
- typeof video.duration === "number" && !isNaN(video.duration) &&
37
+ (video.duration === undefined || typeof video.duration === "number" && !isNaN(video.duration)) &&
38
38
  typeof video.fetch_time === "string");
39
39
  }
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elections-types",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./types/APIError"
2
2
  export * from "./types/Article"
3
3
  export * from "./types/Candidate"
4
4
  export * from "./types/CandidateArticle"
5
+ export * from "./types/CandidateVideo"
5
6
  export * from "./types/Committee"
6
7
  export * from "./types/Donation"
7
8
  export * from "./types/Election"
@@ -0,0 +1,29 @@
1
+ export class CandidateVideo {
2
+ readonly candidate_id : string
3
+ readonly video_id : string
4
+ readonly title : string
5
+ readonly fetch_time : string
6
+ readonly relevance? : string
7
+
8
+ constructor(candidate_video : any) {
9
+ if (!CandidateVideo.is(candidate_video)) {
10
+ throw Error("Invalid input.")
11
+ }
12
+ this.candidate_id = candidate_video.candidate_id
13
+ this.video_id = candidate_video.video_id
14
+ this.title = candidate_video.title
15
+ this.fetch_time = candidate_video.fetch_time
16
+ this.relevance = candidate_video.relevance
17
+ }
18
+
19
+ static is(candidate_video : any) : candidate_video is CandidateVideo {
20
+ return (
21
+ candidate_video !== undefined &&
22
+ typeof candidate_video.candidate_id === "string" &&
23
+ typeof candidate_video.video_id === "string" &&
24
+ typeof candidate_video.title === "string" &&
25
+ typeof candidate_video.fetch_time === "string" &&
26
+ (candidate_video.relevance === undefined || typeof candidate_video.relevance === "string")
27
+ )
28
+ }
29
+ }
@@ -7,7 +7,7 @@ export class Video {
7
7
  readonly title : string
8
8
  readonly description : string
9
9
  readonly tags? : string[]
10
- readonly duration : number
10
+ readonly duration? : number
11
11
  readonly fetch_time : string
12
12
 
13
13
  constructor(video : any) {
@@ -37,7 +37,7 @@ export class Video {
37
37
  typeof video.title === "string" &&
38
38
  typeof video.description === "string" &&
39
39
  (video.tags === undefined || Array.isArray(video.tags) && video.tags.map((tag : any) => typeof tag === "string")) &&
40
- typeof video.duration === "number" && !isNaN(video.duration) &&
40
+ (video.duration === undefined || typeof video.duration === "number" && !isNaN(video.duration)) &&
41
41
  typeof video.fetch_time === "string"
42
42
  )
43
43
  }