elections-types 1.0.36 → 1.0.38

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/CandidateTweet.js";
5
6
  export * from "./types/CandidateVideo.js";
6
7
  export * from "./types/Committee.js";
7
8
  export * from "./types/Donation.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/CandidateTweet.js";
5
6
  export * from "./types/CandidateVideo.js";
6
7
  export * from "./types/Committee.js";
7
8
  export * from "./types/Donation.js";
@@ -0,0 +1,10 @@
1
+ export declare class CandidateTweet {
2
+ readonly candidate_id: string;
3
+ readonly tweet_id: string;
4
+ readonly url: string;
5
+ readonly fetch_time: string;
6
+ readonly relevance?: string;
7
+ readonly sentiment?: string;
8
+ constructor(candidate_tweet: any);
9
+ static is(candidate_tweet: any): candidate_tweet is CandidateTweet;
10
+ }
@@ -0,0 +1,28 @@
1
+ export class CandidateTweet {
2
+ candidate_id;
3
+ tweet_id;
4
+ url;
5
+ fetch_time;
6
+ relevance;
7
+ sentiment;
8
+ constructor(candidate_tweet) {
9
+ if (!CandidateTweet.is(candidate_tweet)) {
10
+ throw Error("Invalid input.");
11
+ }
12
+ this.candidate_id = candidate_tweet.candidate_id;
13
+ this.tweet_id = candidate_tweet.tweet_id;
14
+ this.url = candidate_tweet.url;
15
+ this.fetch_time = candidate_tweet.fetch_time;
16
+ this.relevance = candidate_tweet.relevance;
17
+ this.sentiment = candidate_tweet.sentiment;
18
+ }
19
+ static is(candidate_tweet) {
20
+ return (candidate_tweet !== undefined &&
21
+ typeof candidate_tweet.candidate_id === "string" &&
22
+ typeof candidate_tweet.tweet_id === "string" &&
23
+ typeof candidate_tweet.url === "string" &&
24
+ typeof candidate_tweet.fetch_time === "string" &&
25
+ (candidate_tweet.relevance === undefined || typeof candidate_tweet.relevance === "string") &&
26
+ (candidate_tweet.sentiment === undefined || typeof candidate_tweet.sentiment === "string"));
27
+ }
28
+ }
@@ -22,7 +22,6 @@ export class User {
22
22
  typeof user.admin === "boolean" &&
23
23
  typeof user.premium === "boolean" &&
24
24
  typeof user.email === "string" &&
25
- Array.isArray(user.scout_ids) &&
26
25
  typeof user.email_settings === "object" &&
27
26
  Object.entries(user.email_settings).every(([key, value]) => (is_long_form_type_id(key) || key === "NEWS") && typeof value === "number"));
28
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elections-types",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
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/CandidateTweet"
5
6
  export * from "./types/CandidateVideo"
6
7
  export * from "./types/Committee"
7
8
  export * from "./types/Donation"
@@ -0,0 +1,32 @@
1
+ export class CandidateTweet {
2
+ readonly candidate_id : string
3
+ readonly tweet_id : string
4
+ readonly url : string
5
+ readonly fetch_time : string
6
+ readonly relevance? : string
7
+ readonly sentiment? : string
8
+
9
+ constructor(candidate_tweet : any) {
10
+ if (!CandidateTweet.is(candidate_tweet)) {
11
+ throw Error("Invalid input.")
12
+ }
13
+ this.candidate_id = candidate_tweet.candidate_id
14
+ this.tweet_id = candidate_tweet.tweet_id
15
+ this.url = candidate_tweet.url
16
+ this.fetch_time = candidate_tweet.fetch_time
17
+ this.relevance = candidate_tweet.relevance
18
+ this.sentiment = candidate_tweet.sentiment
19
+ }
20
+
21
+ static is(candidate_tweet : any) : candidate_tweet is CandidateTweet {
22
+ return (
23
+ candidate_tweet !== undefined &&
24
+ typeof candidate_tweet.candidate_id === "string" &&
25
+ typeof candidate_tweet.tweet_id === "string" &&
26
+ typeof candidate_tweet.url === "string" &&
27
+ typeof candidate_tweet.fetch_time === "string" &&
28
+ (candidate_tweet.relevance === undefined || typeof candidate_tweet.relevance === "string") &&
29
+ (candidate_tweet.sentiment === undefined || typeof candidate_tweet.sentiment === "string")
30
+ )
31
+ }
32
+ }
package/src/types/User.ts CHANGED
@@ -26,7 +26,6 @@ export class User {
26
26
  typeof user.admin === "boolean" &&
27
27
  typeof user.premium === "boolean" &&
28
28
  typeof user.email === "string" &&
29
- Array.isArray(user.scout_ids) &&
30
29
  typeof user.email_settings === "object" &&
31
30
  Object.entries(user.email_settings).every(([key, value]) => (is_long_form_type_id(key) || key === "NEWS") && typeof value === "number")
32
31
  )