elections-types 1.0.30 → 1.0.31

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.
@@ -10,4 +10,5 @@ export * from "./types/FormTypeID.js";
10
10
  export * from "./types/State.js";
11
11
  export * from "./types/Tweet.js";
12
12
  export * from "./types/User.js";
13
+ export * from "./types/UserElection.js";
13
14
  export * from "./types/Video.js";
package/dist/src/index.js CHANGED
@@ -10,4 +10,5 @@ export * from "./types/FormTypeID.js";
10
10
  export * from "./types/State.js";
11
11
  export * from "./types/Tweet.js";
12
12
  export * from "./types/User.js";
13
+ export * from "./types/UserElection.js";
13
14
  export * from "./types/Video.js";
@@ -0,0 +1,9 @@
1
+ import { ElectionID } from "./Election.js";
2
+ export declare class UserElection {
3
+ readonly user_id: string;
4
+ readonly election_id: ElectionID;
5
+ readonly candidate_display: Record<string, number>;
6
+ readonly notify: boolean;
7
+ constructor(user_election: any);
8
+ static is(user_election: any): user_election is UserElection;
9
+ }
@@ -0,0 +1,24 @@
1
+ import { is_election_id } from "./Election.js";
2
+ export class UserElection {
3
+ user_id;
4
+ election_id;
5
+ candidate_display;
6
+ notify;
7
+ // readonly [x : string] : any
8
+ constructor(user_election) {
9
+ if (!UserElection.is(user_election)) {
10
+ throw Error("Invalid Input.");
11
+ }
12
+ this.user_id = user_election.user_id;
13
+ this.election_id = user_election.election_id;
14
+ this.candidate_display = user_election.candidate_display;
15
+ this.notify = user_election.notify;
16
+ }
17
+ static is(user_election) {
18
+ return (user_election !== undefined &&
19
+ typeof user_election.user_id === "string" &&
20
+ is_election_id(user_election.election_id) &&
21
+ Object.entries(user_election.candidate_display).every(([key, value]) => (typeof key === "string" && typeof value === "number")) &&
22
+ typeof user_election.notify === "boolean");
23
+ }
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elections-types",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/index.ts CHANGED
@@ -10,4 +10,5 @@ export * from "./types/FormTypeID"
10
10
  export * from "./types/State"
11
11
  export * from "./types/Tweet"
12
12
  export * from "./types/User"
13
+ export * from "./types/UserElection"
13
14
  export * from "./types/Video"
@@ -0,0 +1,31 @@
1
+ import { ElectionID, is_election_id } from "./Election"
2
+ import { is_long_form_type_id, LongFormTypeID } from "./FormTypeID"
3
+
4
+ export class UserElection {
5
+ readonly user_id : string
6
+ readonly election_id : ElectionID
7
+ readonly candidate_display : Record<string, number>
8
+ readonly notify : boolean
9
+
10
+ // readonly [x : string] : any
11
+
12
+ constructor(user_election : any) {
13
+ if (!UserElection.is(user_election)) {
14
+ throw Error("Invalid Input.")
15
+ }
16
+ this.user_id = user_election.user_id
17
+ this.election_id = user_election.election_id
18
+ this.candidate_display = user_election.candidate_display
19
+ this.notify = user_election.notify
20
+ }
21
+
22
+ static is(user_election : any) : user_election is UserElection {
23
+ return (
24
+ user_election !== undefined &&
25
+ typeof user_election.user_id === "string" &&
26
+ is_election_id(user_election.election_id) &&
27
+ Object.entries(user_election.candidate_display).every(([key, value]) => (typeof key === "string" && typeof value === "number")) &&
28
+ typeof user_election.notify === "boolean"
29
+ )
30
+ }
31
+ }