legiscan-ts 3.0.0 → 3.0.1

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/index.js CHANGED
@@ -136,7 +136,7 @@ const BillType = {
136
136
  Remonstration: 22,
137
137
  CommitteeBill: 23
138
138
  };
139
- const Vote = {
139
+ const VoteType = {
140
140
  Yea: 1,
141
141
  Nay: 2,
142
142
  Abstain: 3,
@@ -216,9 +216,8 @@ function zNames(haystack) {
216
216
  function zNumbers(haystack) {
217
217
  return z.union(Object.values(haystack).map((n) => z.literal(n)));
218
218
  }
219
- // src/schemas/types.ts
220
- /** @public */
221
- const _zSession = z.object({
219
+ // src/types.ts
220
+ const SessionSchema = z.object({
222
221
  session_id: z.number().describe("Internal session id"),
223
222
  session_name: z.string().describe("State specific session name"),
224
223
  session_title: z.string().describe("Normalized session title with year(s) and Regular/Nth Special Session"),
@@ -232,13 +231,11 @@ const _zSession = z.object({
232
231
  prior: z.boolean().describe("Flag for session being archived"),
233
232
  sine_die: z.boolean().describe("Flag for session being adjourned sine die")
234
233
  });
235
- /** @public */
236
- const zGetSessionList = z.array(_zSession.extend({
234
+ const SessionListSchema = z.array(SessionSchema.extend({
237
235
  session_hash: z.hash("md5").nullable().describe("Hash of session data, used for caching"),
238
236
  dataset_hash: z.hash("md5").nullable().describe("Hash of entire dataset, used for caching")
239
237
  }));
240
- /** @public */
241
- const _zBillText = z.object({
238
+ const BillTextSchema = z.object({
242
239
  doc_id: z.number().describe("Internal document id"),
243
240
  bill_id: z.number().optional().describe("Internal bill id"),
244
241
  type: zNames(TextType).describe("Type of draft text"),
@@ -258,38 +255,30 @@ const _zBillText = z.object({
258
255
  alt_mime_raw: z.string().nullable().describe("Raw MIME type of the alternate document, e.g. 'application/pdf'"),
259
256
  alt_state_link: z.url().nullable().describe("URL of alternate document on state website"),
260
257
  alt_text_size: z.number().nullable().describe("Size in bytes of the decoded BASE64 alternate document (add 33% for base64)"),
261
- alt_text_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded BASE64 alternate document")
258
+ alt_text_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded BASE64 alternate document"),
259
+ doc: z.base64().describe("BASE64 encoded document").nullish(),
260
+ alt_doc: z.base64().describe("BASE64 encoded alternate document").nullish()
262
261
  });
263
- /** @public */
264
- const zGetBillText = _zBillText.extend({
265
- doc: z.base64().describe("BASE64 encoded document"),
266
- alt_doc: z.unknown()
267
- });
268
- /** @public */
269
- const _zCommittee = z.object({
262
+ const CommitteeSchema = z.object({
270
263
  committee_id: z.number().describe("Internal committee id"),
271
264
  chamber_raw: z.string().describe("Internal chamber name, e.g. 'S' or 'H'"),
272
265
  chamber_id: z.number().describe("Internal chamber id"),
273
266
  name: z.string().describe("Committee name")
274
267
  });
275
- /** @public */
276
- const _zCommitteeReferral = z.intersection(_zCommittee, z.object({ date: z.iso.date().describe("Date of referral") }));
277
- /** @public */
278
- const _zBillProgress = z.object({
268
+ const CommitteeReferralSchema = z.intersection(CommitteeSchema, z.object({ date: z.iso.date().describe("Date of referral") }));
269
+ const BillProgressSchema = z.object({
279
270
  date: z.iso.date().describe("Date of progress event"),
280
271
  event: zNames(Progress).describe("Normalized progress event"),
281
272
  event_id: zNumbers(Progress).describe("Internal progress event id")
282
273
  });
283
- /** @public */
284
- const _zBillHistory = z.object({
274
+ const BillHistorySchema = z.object({
285
275
  date: z.iso.date().describe("Date of action"),
286
276
  action: z.string().describe("Description of action taken"),
287
277
  chamber_raw: z.string().nullable().describe("Internal chamber name"),
288
278
  chamber_id: z.number().nullable().describe("Internal chamber id"),
289
279
  importance: z.boolean().describe("Flag for major steps (i.e. those included in progress list)")
290
280
  });
291
- /** @public */
292
- const _zPerson = z.object({
281
+ const PersonSchema = z.object({
293
282
  people_id: z.number().describe("Internal person id"),
294
283
  person_hash: z.string().describe("Hash of the person's details, used for caching"),
295
284
  party: zNames(Party).describe("Normalized party, e.g. 'Democrat' or 'Republican'"),
@@ -318,23 +307,18 @@ const _zPerson = z.object({
318
307
  state_federal: z.unknown(),
319
308
  bio: z.unknown()
320
309
  });
321
- /** @public */
322
- const zGetPerson = _zPerson.extend({});
323
- /** @public */
324
- const _zSast = z.object({
310
+ const SastSchema = z.object({
325
311
  type: zNames(SastType).describe("Normalized sast type"),
326
312
  type_id: zNumbers(SastType).describe("Internal sast id"),
327
313
  type_raw: z.string().describe("Internal sast type name"),
328
314
  sast_bill_number: z.string().describe("Bill number of the sast, e.g. HB 1234"),
329
315
  sast_bill_id: z.number().describe("Internal bill id of the sast")
330
316
  });
331
- /** @public */
332
- const _zSubject = z.object({
317
+ const SubjectSchema = z.object({
333
318
  subject_id: z.number().describe("Internal subject id"),
334
319
  subject_name: z.string().describe("Name of the subject")
335
320
  });
336
- /** @public */
337
- const _zVote = z.object({
321
+ const VoteSchema = z.object({
338
322
  roll_call_id: z.number().describe("Internal roll call id"),
339
323
  date: z.iso.date().describe("Date of the vote"),
340
324
  description: z.string().describe("Description of the vote"),
@@ -347,8 +331,7 @@ const _zVote = z.object({
347
331
  chamber_id: z.number().describe("Internal chamber id"),
348
332
  chamber_raw: z.string().describe("Internal chamber name, e.g. 'S' or 'H'")
349
333
  });
350
- /** @public */
351
- const _zAmendment = z.object({
334
+ const AmendmentSchema = z.object({
352
335
  amendment_id: z.number().describe("Internal amendment id"),
353
336
  adopted: z.boolean().describe("Flag for whether the amendment was adopted"),
354
337
  chamber_id: z.number().describe("Internal chamber id"),
@@ -369,16 +352,12 @@ const _zAmendment = z.object({
369
352
  alt_mime_raw: z.string().nullable().describe("Raw MIME type of the alternate document, e.g. 'application/pdf'"),
370
353
  alt_state_link: z.url().nullable().describe("URL of the alternate document on state website"),
371
354
  alt_amendment_size: z.number().nullable().describe("Size in bytes of the decoded alternate BASE64 document (add 33% for base64)"),
372
- alt_amendment_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded alternate BASE64 document")
373
- });
374
- /** @public */
375
- const zGetAmendment = _zAmendment.extend({
376
- bill_id: z.number().describe("Internal bill id the amendment belongs to"),
377
- doc: z.base64().describe("BASE64 encoded document"),
378
- alt_doc: z.base64().nullable().describe("BASE64 encoded alternate document")
355
+ alt_amendment_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded alternate BASE64 document"),
356
+ bill_id: z.number().describe("Internal bill id the amendment belongs to").nullish(),
357
+ doc: z.base64().describe("BASE64 encoded document").nullish(),
358
+ alt_doc: z.base64().nullable().describe("BASE64 encoded alternate document").nullish()
379
359
  });
380
- /** @public */
381
- const _zSupplement = z.object({
360
+ const SupplementSchema = z.object({
382
361
  supplement_id: z.number().describe("Internal supplement id"),
383
362
  date: z.iso.date().nullable().describe("Date of the supplement"),
384
363
  type: zNames(SupplementType).describe("Normalized supplement type"),
@@ -397,16 +376,12 @@ const _zSupplement = z.object({
397
376
  alt_mime_raw: z.string().nullable().describe("Raw MIME type of the alternate document, e.g. 'application/pdf'"),
398
377
  alt_state_link: z.url().nullable().describe("URL of the alternate document on state website"),
399
378
  alt_supplement_size: z.number().nullable().describe("Size in bytes of the decoded alternate BASE64 document (add 33% for base64)"),
400
- alt_supplement_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded alternate BASE64 document")
379
+ alt_supplement_hash: z.hash("md5").nullable().describe("MD5 hash of the decoded alternate BASE64 document"),
380
+ bill_id: z.number().describe("Internal bill id the supplement belongs to").nullish(),
381
+ doc: z.base64().describe("BASE64 encoded document").nullish(),
382
+ alt_doc: z.base64().nullable().describe("BASE64 encoded alternate document").nullish()
401
383
  });
402
- /** @public */
403
- const zGetSupplement = _zSupplement.extend({
404
- bill_id: z.number().describe("Internal bill id the supplement belongs to"),
405
- doc: z.base64().describe("BASE64 encoded document"),
406
- alt_doc: z.base64().nullable().describe("BASE64 encoded alternate document")
407
- });
408
- /** @public */
409
- const _zEvent = z.object({
384
+ const EventSchema = z.object({
410
385
  type: zNames(EventType).describe("Normalized event type"),
411
386
  type_id: zNumbers(EventType).describe("Internal event type id"),
412
387
  type_raw: z.string().describe("Internal event type name"),
@@ -415,8 +390,7 @@ const _zEvent = z.object({
415
390
  location: z.string().nullable().describe("Location of the event (if available)"),
416
391
  description: z.string().describe("Description of the event")
417
392
  });
418
- /** @public */
419
- const _zBill = z.object({
393
+ const BillBaseSchema = z.object({
420
394
  bill_id: z.number().describe("Internal bill id"),
421
395
  bill_number: z.string().describe("Bill number, e.g. HB 1234"),
422
396
  title: z.string().describe("Official bill title"),
@@ -427,43 +401,40 @@ const _zBill = z.object({
427
401
  status_date: z.iso.date().nullable().describe("Date of last progress update (if available)"),
428
402
  change_hash: z.hash("md5").describe("Hash of bill data, used for caching")
429
403
  });
430
- /** @public */
431
- const _zBillWithAction = _zBill.extend({
404
+ const MasterListSchema = z.array(BillBaseSchema.extend({
432
405
  last_action: z.string().nullable().describe("Description of the bill's last action (if available)"),
433
406
  last_action_date: z.iso.date().nullable().describe("Date of the bill's last action (if available)")
434
- });
435
- const zGetMasterList = z.array(_zBillWithAction);
436
- z.array(_zBillWithAction.extend({
407
+ }));
408
+ const SearchSchema = z.array(BillBaseSchema.extend({
437
409
  relevance: z.number().describe("Relevance score of the search result"),
438
410
  state: zNames(State).describe("Normalized state"),
439
411
  state_id: zNumbers(State).describe("Internal state id"),
440
412
  bill_id: z.number().describe("Internal bill id"),
441
413
  text_url: z.url().describe("URL of the bill text on legiscan.com"),
442
- research_url: z.url().describe("URL of the bill research page on legiscan.com")
414
+ research_url: z.url().describe("URL of the bill research page on legiscan.com"),
415
+ last_action: z.string().nullable().describe("Description of the bill's last action (if available)"),
416
+ last_action_date: z.iso.date().nullable().describe("Date of the bill's last action (if available)")
443
417
  }).omit({
444
418
  description: true,
445
419
  status: true,
446
420
  status_id: true,
447
421
  status_date: true
448
422
  }));
449
- /** @public */
450
- const _zBillVote = _zVote.extend({
423
+ const BillVoteSchema = VoteSchema.extend({
451
424
  url: z.url().describe("URL of the vote on legiscan.com"),
452
425
  state_link: z.url().describe("URL of the vote on state website")
453
426
  });
454
- /** @public */
455
- const _zSponsor = _zPerson.extend({
427
+ const SponsorSchema = PersonSchema.extend({
456
428
  sponsor_type: zNames(SponsorType).describe("Normalized sponsor type"),
457
429
  sponsor_type_id: zNumbers(SponsorType).describe("Internal sponsor type id"),
458
430
  sponsor_order: z.number().describe("Order of sponsorship")
459
431
  });
460
- /** @public */
461
- const zGetBill = _zBill.extend({
432
+ const BillSchema = BillBaseSchema.extend({
462
433
  session_id: z.number().describe("Internal session id"),
463
- session: _zSession.describe("Session object"),
434
+ session: SessionSchema.describe("Session object"),
464
435
  state_link: z.url().describe("URL of bill on state website"),
465
436
  completed: z.boolean().describe("Flag for whether bill is completed"),
466
- progress: z.array(_zBillProgress).describe("Major history of the bill (i.e. important items from history)"),
437
+ progress: z.array(BillProgressSchema).describe("Major history of the bill (i.e. important items from history)"),
467
438
  state: zNames(State).describe("Normalized state"),
468
439
  state_id: zNumbers(State).describe("Internal state id"),
469
440
  state_raw: z.string().describe("Internal state name"),
@@ -475,37 +446,33 @@ const zGetBill = _zBill.extend({
475
446
  current_body_id: z.number().nullable().describe("Internal body id (current)"),
476
447
  current_body_raw: z.string().nullable().describe("Internal body name (current)"),
477
448
  pending_committee_id: z.number().describe("Internal committee id"),
478
- committee: z.array(_zCommittee).describe("List of committees if pending"),
479
- referrals: z.array(_zCommitteeReferral).describe("History of committee referrals"),
480
- history: z.array(_zBillHistory).describe("Full history of the bill"),
481
- sponsors: z.array(_zSponsor).describe("Sponsors of the bill"),
482
- sasts: z.array(_zSast).describe("SASTs of the bill"),
483
- subjects: z.array(_zSubject).describe("Subjects of the bill"),
484
- texts: z.array(_zBillText).describe("Documents from the bill"),
485
- votes: z.array(_zBillVote).describe("Votes for the bill"),
486
- amendments: z.array(_zAmendment).describe("Amendments to the bill"),
487
- supplements: z.array(_zSupplement).describe("Supplements to the bill"),
488
- calendar: z.array(_zEvent).describe("Events related to the bill")
449
+ committee: z.array(CommitteeSchema).describe("List of committees if pending"),
450
+ referrals: z.array(CommitteeReferralSchema).describe("History of committee referrals"),
451
+ history: z.array(BillHistorySchema).describe("Full history of the bill"),
452
+ sponsors: z.array(SponsorSchema).describe("Sponsors of the bill"),
453
+ sasts: z.array(SastSchema).describe("SASTs of the bill"),
454
+ subjects: z.array(SubjectSchema).describe("Subjects of the bill"),
455
+ texts: z.array(BillTextSchema).describe("Documents from the bill"),
456
+ votes: z.array(BillVoteSchema).describe("Votes for the bill"),
457
+ amendments: z.array(AmendmentSchema).describe("Amendments to the bill"),
458
+ supplements: z.array(SupplementSchema).describe("Supplements to the bill"),
459
+ calendar: z.array(EventSchema).describe("Events related to the bill")
489
460
  });
490
- /** @public */
491
- const _zRollCallVote = z.object({
461
+ const RollCallVoteSchema = z.object({
492
462
  people_id: z.number().describe("Internal person id"),
493
- vote: zNames(Vote).describe("Vote of the person"),
494
- vote_id: zNumbers(Vote).describe("Internal vote id"),
463
+ vote: zNames(VoteType).describe("Vote of the person"),
464
+ vote_id: zNumbers(VoteType).describe("Internal vote id"),
495
465
  vote_raw: z.string().describe("Internal vote name")
496
466
  });
497
- /** @public */
498
- const zGetRollCall = _zVote.extend({
467
+ const RollCallSchema = VoteSchema.extend({
499
468
  bill_id: z.number().describe("Internal bill id the vote belongs to"),
500
- votes: z.array(_zRollCallVote).describe("Individual votes for the roll call")
469
+ votes: z.array(RollCallVoteSchema).describe("Individual votes for the roll call")
501
470
  });
502
- /** @public */
503
- const zGetSessionPeople = z.array(_zPerson.extend({}));
504
- /** @public */
505
- const zGetSponsoredList = z.array(z.object({
471
+ const SessionPeopleSchema = z.array(PersonSchema.extend({}));
472
+ const SponsoredListSchema = z.array(z.object({
506
473
  bill_id: z.number().describe("Internal bill id"),
507
474
  bill_number: z.string().describe("Bill number, e.g. HB 1234"),
508
- session: _zSession
475
+ session: SessionSchema
509
476
  }));
510
477
  // src/client.ts
511
478
  /**
@@ -557,7 +524,7 @@ var LegiscanClient = class {
557
524
  */
558
525
  async getSessionList({ state }) {
559
526
  const { sessions } = await this.request("getSessionList", { ...state ? { state: asName(State, state) } : {} });
560
- return zGetSessionList.parse(sessions.map((s) => ({
527
+ return SessionListSchema.parse(sessions.map((s) => ({
561
528
  session_id: s.session_id,
562
529
  state: asName(State, s.state_id),
563
530
  state_id: s.state_id,
@@ -585,7 +552,7 @@ var LegiscanClient = class {
585
552
  ...state ? { state: asName(State, state) } : {},
586
553
  ...session ? { id: session.toString() } : {}
587
554
  });
588
- return zGetMasterList.parse(numericalToArray(masterlist).map((b) => ({
555
+ return MasterListSchema.parse(numericalToArray(masterlist).map((b) => ({
589
556
  bill_id: b.bill_id,
590
557
  bill_number: b.number,
591
558
  title: b.title,
@@ -606,7 +573,7 @@ var LegiscanClient = class {
606
573
  */
607
574
  async getBillText({ id }) {
608
575
  const { text } = await this.request("getBillText", { id });
609
- return zGetBillText.parse({
576
+ return BillTextSchema.parse({
610
577
  doc_id: text.doc_id,
611
578
  bill_id: text.bill_id,
612
579
  type: asName(TextType, text.type_id),
@@ -639,7 +606,7 @@ var LegiscanClient = class {
639
606
  async getBill({ id }) {
640
607
  const { bill } = await this.request("getBill", { id });
641
608
  if (!Array.isArray(bill.committee)) bill.committee = [bill.committee];
642
- return zGetBill.parse({
609
+ return BillSchema.parse({
643
610
  bill_id: bill.bill_id,
644
611
  change_hash: bill.change_hash,
645
612
  session_id: bill.session_id,
@@ -844,7 +811,7 @@ var LegiscanClient = class {
844
811
  */
845
812
  async getAmendment({ id }) {
846
813
  const { amendment } = await this.request("getAmendment", { id });
847
- return zGetAmendment.parse({
814
+ return AmendmentSchema.parse({
848
815
  amendment_id: amendment.amendment_id,
849
816
  bill_id: amendment.bill_id,
850
817
  adopted: Boolean(amendment.adopted),
@@ -878,7 +845,7 @@ var LegiscanClient = class {
878
845
  */
879
846
  async getSupplement({ id }) {
880
847
  const { supplement } = await this.request("getSupplement", { id });
881
- return zGetSupplement.parse({
848
+ return SupplementSchema.parse({
882
849
  supplement_id: supplement.supplement_id,
883
850
  bill_id: supplement.bill_id,
884
851
  date: supplement.date !== "0000-00-00" ? supplement.date : null,
@@ -910,7 +877,7 @@ var LegiscanClient = class {
910
877
  */
911
878
  async getRollCall({ id }) {
912
879
  const { roll_call } = await this.request("getRollCall", { id });
913
- return zGetRollCall.parse({
880
+ return RollCallSchema.parse({
914
881
  roll_call_id: roll_call.roll_call_id,
915
882
  bill_id: roll_call.bill_id,
916
883
  date: roll_call.date,
@@ -925,7 +892,7 @@ var LegiscanClient = class {
925
892
  chamber_raw: roll_call.chamber,
926
893
  votes: numericalToArray(roll_call.votes).map((v) => ({
927
894
  people_id: v.people_id,
928
- vote: asName(Vote, v.vote_id),
895
+ vote: asName(VoteType, v.vote_id),
929
896
  vote_id: v.vote_id,
930
897
  vote_raw: v.vote_text
931
898
  }))
@@ -938,7 +905,7 @@ var LegiscanClient = class {
938
905
  */
939
906
  async getPerson({ id }) {
940
907
  const { person } = await this.request("getPerson", { id });
941
- return zGetPerson.parse({
908
+ return PersonSchema.parse({
942
909
  people_id: person.people_id,
943
910
  person_hash: person.person_hash,
944
911
  party: asName(Party, parseInt(person.party_id, 10)),
@@ -975,7 +942,7 @@ var LegiscanClient = class {
975
942
  */
976
943
  async getSessionPeople({ id }) {
977
944
  const { sessionpeople: { people } } = await this.request("getSessionPeople", { id });
978
- return zGetSessionPeople.parse((people ?? []).map((person) => ({
945
+ return SessionPeopleSchema.parse((people ?? []).map((person) => ({
979
946
  people_id: person.people_id,
980
947
  person_hash: person.person_hash,
981
948
  party: asName(Party, parseInt(person.party_id, 10)),
@@ -1012,7 +979,7 @@ var LegiscanClient = class {
1012
979
  */
1013
980
  async getSponsoredList({ id }) {
1014
981
  const { sponsoredbills: { sessions, bills } } = await this.request("getSponsoredList", { id });
1015
- return zGetSponsoredList.parse(bills.map((b) => ({
982
+ return SponsoredListSchema.parse(bills.map((b) => ({
1016
983
  bill_id: b.bill_id,
1017
984
  bill_number: b.number,
1018
985
  session: sessions.map((s) => ({
@@ -1062,7 +1029,7 @@ var LegiscanClient = class {
1062
1029
  ...state ? { state: asName(State, state) } : {},
1063
1030
  ...year ? { year: year.toString() } : {}
1064
1031
  });
1065
- yield* numericalToArray(searchresult).map((b) => ({
1032
+ yield* SearchSchema.parse(numericalToArray(searchresult).map((b) => ({
1066
1033
  relevance: b.relevance,
1067
1034
  state: b.state,
1068
1035
  state_id: asNumber(State, b.state),
@@ -1075,12 +1042,12 @@ var LegiscanClient = class {
1075
1042
  last_action: b.last_action,
1076
1043
  last_action_date: b.last_action_date,
1077
1044
  title: b.title
1078
- }));
1045
+ })));
1079
1046
  page++;
1080
1047
  if (searchresult.summary.page_total < page) return;
1081
1048
  }
1082
1049
  }
1083
1050
  };
1084
- export { BillType, EventType, LegiscanClient, Mime, Party, Progress, Reason, Role, SastType, SponsorType, Stance, State, SupplementType, TextType, Vote, asName, asNumber, numericalToArray, zNames, zNumbers };
1051
+ export { AmendmentSchema, BillBaseSchema, BillHistorySchema, BillProgressSchema, BillSchema, BillTextSchema, BillType, BillVoteSchema, CommitteeReferralSchema, CommitteeSchema, EventSchema, EventType, LegiscanClient, MasterListSchema, Mime, Party, PersonSchema, Progress, Reason, Role, RollCallSchema, RollCallVoteSchema, SastSchema, SastType, SearchSchema, SessionListSchema, SessionPeopleSchema, SessionSchema, SponsorSchema, SponsorType, SponsoredListSchema, Stance, State, SubjectSchema, SupplementSchema, SupplementType, TextType, VoteSchema, VoteType, asName, asNumber, numericalToArray, zNames, zNumbers };
1085
1052
 
1086
1053
  //# sourceMappingURL=index.js.map