elections-types 1.0.92 → 1.0.93
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.
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.js +6 -6
- package/dist/src/types/ElectionsConfig.d.ts +6 -6
- package/dist/src/types/FederalElection.d.ts +27 -0
- package/dist/src/types/FederalElection.js +86 -0
- package/dist/src/types/FederalElectionCandidate.d.ts +38 -0
- package/dist/src/types/FederalElectionCandidate.js +99 -0
- package/dist/src/types/FederalElectionCandidateCommittee.d.ts +7 -0
- package/dist/src/types/FederalElectionCandidateCommittee.js +32 -0
- package/dist/src/types/FederalElectionCommittee.d.ts +27 -0
- package/dist/src/types/FederalElectionCommittee.js +68 -0
- package/dist/src/types/FederalElectionF1File.d.ts +10 -10
- package/dist/src/types/FederalElectionF1File.js +24 -24
- package/dist/src/types/FederalElectionF24File.d.ts +3 -3
- package/dist/src/types/FederalElectionF24File.js +5 -5
- package/dist/src/types/FederalElectionF2File.d.ts +5 -5
- package/dist/src/types/FederalElectionF2File.js +13 -13
- package/dist/src/types/FederalElectionF3File.d.ts +1 -1
- package/dist/src/types/FederalElectionF3File.js +3 -3
- package/dist/src/types/FederalElectionFileExpenditure.d.ts +28 -0
- package/dist/src/types/FederalElectionFileExpenditure.js +70 -0
- package/dist/src/types/Tweet.d.ts +1 -4
- package/dist/src/types/Tweet.js +14 -13
- package/dist/src/types/UserFederalElection.d.ts +9 -0
- package/dist/src/types/UserFederalElection.js +24 -0
- package/package.json +1 -1
- package/src/index.ts +6 -6
- package/src/types/ElectionsConfig.ts +6 -6
- package/src/types/FederalElection.ts +105 -0
- package/src/types/FederalElectionCandidate.ts +118 -0
- package/src/types/FederalElectionCandidateCommittee.ts +42 -0
- package/src/types/FederalElectionCommittee.ts +84 -0
- package/src/types/FederalElectionF1File.ts +25 -25
- package/src/types/FederalElectionF24File.ts +6 -6
- package/src/types/FederalElectionF2File.ts +13 -13
- package/src/types/FederalElectionF3File.ts +3 -3
- package/src/types/FederalElectionFileExpenditure.ts +82 -0
- package/src/types/Tweet.ts +13 -13
- package/src/types/UserFederalElection.ts +31 -0
- package/src/types/Candidate.ts +0 -118
- package/src/types/CandidateCommittee.ts +0 -42
- package/src/types/Committee.ts +0 -84
- package/src/types/Election.ts +0 -105
- package/src/types/Expenditure.ts +0 -82
- package/src/types/UserElection.ts +0 -31
package/src/types/Committee.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Candidate } from "./Candidate"
|
|
2
|
-
import { CandidateCommittee } from "./CandidateCommittee"
|
|
3
|
-
import { FederalElectionF3File } from "./FederalElectionF3File"
|
|
4
|
-
|
|
5
|
-
export const designations = ["P", "A", "U", "J", "D", "B"] as const
|
|
6
|
-
|
|
7
|
-
export type CommitteeDesignation = typeof designations[number]
|
|
8
|
-
|
|
9
|
-
export function is_committee_designation(designation : any) : designation is CommitteeDesignation {
|
|
10
|
-
return designations.includes(designation)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class Committee {
|
|
14
|
-
readonly committee_id : string
|
|
15
|
-
readonly name : string
|
|
16
|
-
readonly url? : string
|
|
17
|
-
readonly designation? : CommitteeDesignation
|
|
18
|
-
readonly federal_election_file_id? : number
|
|
19
|
-
readonly jfp_committee_ids? : string[]
|
|
20
|
-
readonly jfr_committee_ids : string[]
|
|
21
|
-
readonly aff_committee_ids : string[]
|
|
22
|
-
readonly [x : string] : any
|
|
23
|
-
|
|
24
|
-
constructor(committee : Committee) {
|
|
25
|
-
if (!Committee.is(committee)) {
|
|
26
|
-
throw Error("Invalid input.")
|
|
27
|
-
}
|
|
28
|
-
this.committee_id = committee.committee_id
|
|
29
|
-
this.name = committee.name
|
|
30
|
-
this.url = committee.url
|
|
31
|
-
this.designation = committee.designation
|
|
32
|
-
this.federal_election_file_id = committee.federal_election_file_id
|
|
33
|
-
this.jfp_committee_ids = committee.jfp_committee_ids
|
|
34
|
-
this.jfr_committee_ids = committee.jfr_committee_ids
|
|
35
|
-
this.aff_committee_ids = committee.aff_committee_ids
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
static is(committee : any) : committee is Committee {
|
|
39
|
-
return (
|
|
40
|
-
committee !== undefined &&
|
|
41
|
-
typeof committee.committee_id === "string" &&
|
|
42
|
-
typeof committee.name === "string" &&
|
|
43
|
-
(committee.url === undefined || typeof committee.url === "string") &&
|
|
44
|
-
(committee.designation === undefined || is_committee_designation(committee.designation)) &&
|
|
45
|
-
(committee.federal_election_file_id === undefined || typeof committee.federal_election_file_id === "number" && !isNaN(committee.federal_election_file_id)) &&
|
|
46
|
-
(committee.jfp_committee_ids === undefined || Array.isArray(committee.jfp_committee_ids) && committee.jfp_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
|
|
47
|
-
(Array.isArray(committee.jfr_committee_ids) && committee.jfr_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
|
|
48
|
-
(Array.isArray(committee.aff_committee_ids) && committee.aff_committee_ids.every((committee_id : any) => typeof committee_id === "string"))
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class CommitteeAux extends Committee {
|
|
54
|
-
readonly candidates : Candidate[]
|
|
55
|
-
readonly federal_election_f3_files : FederalElectionF3File[]
|
|
56
|
-
readonly jfp_committees? : Committee[]
|
|
57
|
-
readonly jfr_committees : Committee[]
|
|
58
|
-
readonly aff_committees : Committee[]
|
|
59
|
-
|
|
60
|
-
constructor(committee : any) {
|
|
61
|
-
if (!CommitteeAux.is(committee)) {
|
|
62
|
-
throw Error("Invalid input.")
|
|
63
|
-
}
|
|
64
|
-
super(committee)
|
|
65
|
-
this.candidates = committee.candidates
|
|
66
|
-
this.federal_election_f3_files = committee.federal_election_f3_files
|
|
67
|
-
this.jfp_committees = committee.jfp_committees
|
|
68
|
-
this.jfr_committees = committee.jfr_committees
|
|
69
|
-
this.aff_committees = committee.aff_committees
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
static is(committee : any) : committee is CommitteeAux {
|
|
73
|
-
return (
|
|
74
|
-
Committee.is(committee) &&
|
|
75
|
-
Array.isArray(committee.candidates) &&
|
|
76
|
-
committee.candidates.every(Candidate.is) &&
|
|
77
|
-
Array.isArray(committee.federal_election_f3_files) &&
|
|
78
|
-
committee.federal_election_f3_files.every(FederalElectionF3File.is) &&
|
|
79
|
-
(committee.jfp_committees === undefined || Array.isArray(committee.jfp_committees) && committee.jfp_committees.every(Committee.is)) &&
|
|
80
|
-
(Array.isArray(committee.jfr_committees) && committee.jfr_committees.every(Committee.is)) &&
|
|
81
|
-
(Array.isArray(committee.aff_committees) && committee.aff_committees.every(Committee.is))
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/types/Election.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Candidate, CandidateAux } from "./Candidate"
|
|
2
|
-
import { Committee, CommitteeAux } from "./Committee"
|
|
3
|
-
import { ExpenditureAux } from "./Expenditure"
|
|
4
|
-
import { is_state_id, state_ids, StateID } from "./State"
|
|
5
|
-
|
|
6
|
-
const office_ids = ["H", "S", "P"] as const
|
|
7
|
-
|
|
8
|
-
export type OfficeID = typeof office_ids[number]
|
|
9
|
-
|
|
10
|
-
export function is_office_id(office_id : any) : office_id is OfficeID {
|
|
11
|
-
return office_ids.includes(office_id)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const state_ids_without_district : StateID[] = ["AK", "DE", "ND", "SD", "VT", "WY"]
|
|
15
|
-
|
|
16
|
-
export type ElectionID = string
|
|
17
|
-
|
|
18
|
-
export function is_election_id(election_id : any) : election_id is ElectionID {
|
|
19
|
-
const parts = election_id.split("-")
|
|
20
|
-
const year = Number(parts[0])
|
|
21
|
-
const office_id = parts[1]
|
|
22
|
-
const state_id = parts[2]
|
|
23
|
-
const district = Number(parts[3])
|
|
24
|
-
if (!(Number.isInteger(year) && year > 1700 && year < 3000 && is_office_id(office_id))) {
|
|
25
|
-
return false
|
|
26
|
-
}
|
|
27
|
-
if (office_id === "P" && parts.length === 2) {
|
|
28
|
-
return true
|
|
29
|
-
}
|
|
30
|
-
if (!is_state_id(state_id)) {
|
|
31
|
-
return false
|
|
32
|
-
}
|
|
33
|
-
if (office_id === "S" && parts.length === 3) {
|
|
34
|
-
return true
|
|
35
|
-
}
|
|
36
|
-
if (office_id !== "H") {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
|
-
if (!(state_ids_without_district.includes(state_id) && parts.length === 3 || parts.length === 4)) {
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
if (!Number.isInteger(district) && district < 100) {
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
return true
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class Election {
|
|
49
|
-
readonly election_id : ElectionID
|
|
50
|
-
readonly name : string
|
|
51
|
-
readonly office_id : OfficeID
|
|
52
|
-
readonly state_id? : StateID
|
|
53
|
-
readonly district? : number
|
|
54
|
-
readonly [x : string] : any
|
|
55
|
-
|
|
56
|
-
constructor(election : Election) {
|
|
57
|
-
if (!Election.is(election)) {
|
|
58
|
-
throw Error("Invalid input.")
|
|
59
|
-
}
|
|
60
|
-
this.election_id = election.election_id
|
|
61
|
-
this.name = election.name
|
|
62
|
-
this.office_id = election.office_id
|
|
63
|
-
this.state_id = election.state_id
|
|
64
|
-
this.district = election.district
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static is(election : any) : election is Election {
|
|
68
|
-
return (
|
|
69
|
-
election !== undefined &&
|
|
70
|
-
is_election_id(election.election_id) &&
|
|
71
|
-
typeof election.name === "string" &&
|
|
72
|
-
is_office_id(election.office_id) &&
|
|
73
|
-
(election.state_id === undefined || is_state_id(election.state_id)) &&
|
|
74
|
-
(election.district === undefined || typeof election.district === "number")
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export class ElectionAux extends Election {
|
|
80
|
-
readonly candidates : CandidateAux[]
|
|
81
|
-
readonly committees : CommitteeAux[]
|
|
82
|
-
readonly expenditures : ExpenditureAux[]
|
|
83
|
-
|
|
84
|
-
constructor(election : any) {
|
|
85
|
-
if (!ElectionAux.is(election)) {
|
|
86
|
-
throw Error("Invalid input.")
|
|
87
|
-
}
|
|
88
|
-
super(election)
|
|
89
|
-
this.candidates = election.candidates.map(candidate => new CandidateAux(candidate))
|
|
90
|
-
this.committees = election.committees.map(committee => new CommitteeAux(committee))
|
|
91
|
-
this.expenditures = election.expenditures.map(expenditure => new ExpenditureAux(expenditure))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static is(election : any) : election is ElectionAux {
|
|
95
|
-
return (
|
|
96
|
-
Election.is(election) &&
|
|
97
|
-
Array.isArray(election.candidates) &&
|
|
98
|
-
election.candidates.every(CandidateAux.is) &&
|
|
99
|
-
Array.isArray(election.committees) &&
|
|
100
|
-
election.committees.every(CommitteeAux.is) &&
|
|
101
|
-
Array.isArray(election.expenditures) &&
|
|
102
|
-
election.expenditures.every(ExpenditureAux.is)
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/types/Expenditure.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { Candidate } from "./Candidate"
|
|
2
|
-
import { Committee } from "./Committee"
|
|
3
|
-
import { ElectionID, is_election_id } from "./Election"
|
|
4
|
-
import { FederalElectionF24File } from "./FederalElectionF24File"
|
|
5
|
-
|
|
6
|
-
export class Expenditure {
|
|
7
|
-
readonly federal_election_file_id : number
|
|
8
|
-
readonly expenditure_id : string
|
|
9
|
-
readonly committee_id : string
|
|
10
|
-
readonly date : string
|
|
11
|
-
readonly payee : string
|
|
12
|
-
readonly election_stage : string
|
|
13
|
-
readonly election_id : ElectionID
|
|
14
|
-
readonly candidate_id : string
|
|
15
|
-
readonly amount : number
|
|
16
|
-
readonly cumulative_amount : number
|
|
17
|
-
readonly purpose : string
|
|
18
|
-
readonly is_support : boolean
|
|
19
|
-
readonly [x : string] : any
|
|
20
|
-
|
|
21
|
-
constructor(expenditure : any) {
|
|
22
|
-
if (!Expenditure.is(expenditure)) {
|
|
23
|
-
throw Error("Invalid input.")
|
|
24
|
-
}
|
|
25
|
-
this.federal_election_file_id = expenditure.federal_election_file_id
|
|
26
|
-
this.expenditure_id = expenditure.expenditure_id
|
|
27
|
-
this.committee_id = expenditure.committee_id
|
|
28
|
-
this.date = expenditure.date
|
|
29
|
-
this.payee = expenditure.payee
|
|
30
|
-
this.election_stage = expenditure.election_stage
|
|
31
|
-
this.election_id = expenditure.election_id
|
|
32
|
-
this.candidate_id = expenditure.candidate_id
|
|
33
|
-
this.amount = expenditure.amount
|
|
34
|
-
this.cumulative_amount = expenditure.cumulative_amount
|
|
35
|
-
this.purpose = expenditure.purpose
|
|
36
|
-
this.is_support = expenditure.is_support
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static is(expenditure : any) : expenditure is Expenditure {
|
|
40
|
-
return (
|
|
41
|
-
expenditure !== undefined &&
|
|
42
|
-
typeof expenditure.federal_election_file_id === "number" &&
|
|
43
|
-
typeof expenditure.expenditure_id === "string" &&
|
|
44
|
-
typeof expenditure.committee_id === "string" &&
|
|
45
|
-
typeof expenditure.date === "string" &&
|
|
46
|
-
typeof expenditure.payee === "string" &&
|
|
47
|
-
typeof expenditure.election_stage === "string" &&
|
|
48
|
-
is_election_id(expenditure.election_id) &&
|
|
49
|
-
typeof expenditure.candidate_id === "string" &&
|
|
50
|
-
typeof expenditure.amount === "number" &&
|
|
51
|
-
typeof expenditure.cumulative_amount === "number" &&
|
|
52
|
-
typeof expenditure.purpose === "string" &&
|
|
53
|
-
typeof expenditure.is_support === "boolean"
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class ExpenditureAux extends Expenditure {
|
|
60
|
-
readonly candidate : Candidate
|
|
61
|
-
readonly committee : Committee
|
|
62
|
-
readonly federal_election_f24_file : FederalElectionF24File
|
|
63
|
-
|
|
64
|
-
constructor(expenditure : any) {
|
|
65
|
-
if (!ExpenditureAux.is(expenditure)) {
|
|
66
|
-
throw Error("Invalid input.")
|
|
67
|
-
}
|
|
68
|
-
super(expenditure)
|
|
69
|
-
this.candidate = new Candidate(expenditure.candidate)
|
|
70
|
-
this.committee = new Committee(expenditure.committee)
|
|
71
|
-
this.federal_election_f24_file = new FederalElectionF24File(expenditure.federal_election_f24_file)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static is(expenditure : any) : expenditure is ExpenditureAux {
|
|
75
|
-
return (
|
|
76
|
-
Expenditure.is(expenditure) &&
|
|
77
|
-
Candidate.is(expenditure.candidate) &&
|
|
78
|
-
Committee.is(expenditure.committee) &&
|
|
79
|
-
FederalElectionF24File.is(expenditure.federal_election_f24_file)
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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 : UserElection) {
|
|
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
|
-
}
|