@dra2020/dra-types 1.8.142 → 1.8.143

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/lib/datasets.ts CHANGED
@@ -118,3 +118,50 @@ export function datasetRestrict(ds: Dataset): { [key: string]: boolean }
118
118
 
119
119
  // Index of database records
120
120
  export type DatasetIndex = { [id: string]: Dataset };
121
+
122
+ export interface PrimaryKeys { CENSUS: string, VAP: string, ELECTION: string };
123
+ export function defaultBuiltinKeys(state: string, datasource: string, planType: string, builtins: Set<string>): PrimaryKeys
124
+ {
125
+ function bestOf(a: string[]): string { return a.find(s => builtins.has(s)) }
126
+
127
+ return (datasource === '2020_VD')
128
+ ? {
129
+ CENSUS: bestOf((usesPrisonerAdjust(state, datasource, planType)
130
+ ? ['D20FA', 'D20F', 'D19F', 'D18F']
131
+ : ['D20F', 'D19F', 'D18F'])),
132
+ VAP: bestOf(['D20T', 'D19T', 'D18T']),
133
+ ELECTION: bestOf(['C16GCO', 'E20GPR', 'E16GPR'])
134
+ }
135
+ :
136
+ {
137
+ CENSUS: bestOf(['D10F', 'D16F']),
138
+ VAP: bestOf(['D10T', 'D16T']),
139
+ ELECTION: bestOf(['C16GCO', 'E20GPR', 'E16GPR', 'E08GPR'])
140
+ }
141
+ }
142
+
143
+ // Hard-coded based on both the existence of the dataset and the legal requirements of that particular state
144
+ // (e.g. NY uses for state house maps but not congressional maps). So that is why we hard-code rather than
145
+ // derive from dataset metadata.
146
+ //
147
+ export function usesPrisonerAdjust(state: string, datasource: string, planType: string): boolean
148
+ {
149
+ if (datasource !== '2020_VD') return false;
150
+ switch (state)
151
+ {
152
+ case 'CA':
153
+ case 'DE':
154
+ case 'MD':
155
+ case 'NJ':
156
+ case 'NV':
157
+ case 'PA':
158
+ case 'VA':
159
+ case 'WA':
160
+ return (planType === 'congress' || planType === 'upper' || planType === 'lower' || planType === 'coi');
161
+ case 'CO':
162
+ case 'CT':
163
+ case 'NY':
164
+ return (planType === 'upper' || planType === 'lower' || planType === 'coi');
165
+ }
166
+ return false;
167
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-types",
3
- "version": "1.8.142",
3
+ "version": "1.8.143",
4
4
  "description": "Shared types used between client, server and tools.",
5
5
  "main": "dist/dra-types.js",
6
6
  "types": "./dist/all.d.ts",
@@ -36,7 +36,7 @@
36
36
  "webpack-cli": "^5.1.4"
37
37
  },
38
38
  "dependencies": {
39
- "@dra2020/baseclient": "^1.0.158",
39
+ "@dra2020/baseclient": "^1.0.159",
40
40
  "geojson": "^0.5.0",
41
41
  "object-hash": "^3.0.0"
42
42
  }