fitzroy 1.5.0 → 1.6.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/cli.js CHANGED
@@ -555,6 +555,7 @@ function mergeFootyWireStats(basicTeams, advancedTeams, matchId, season, roundNu
555
555
  goalEfficiency: null,
556
556
  shotEfficiency: null,
557
557
  interchangeCounts: null,
558
+ brownlowVotes: null,
558
559
  supercoachScore: basic.supercoachPoints,
559
560
  dreamTeamPoints: basic.dreamTeamPoints,
560
561
  effectiveDisposals: adv?.effectiveDisposals ?? null,
@@ -639,6 +640,14 @@ var init_footywire_player_stats = __esm({
639
640
  });
640
641
 
641
642
  // src/transforms/match-results.ts
643
+ function toRoundCode(roundName) {
644
+ if (!roundName) return null;
645
+ const mapped = ROUND_CODE_MAP.get(roundName);
646
+ if (mapped) return mapped;
647
+ const m = ROUND_NUMBER_PATTERN.exec(roundName);
648
+ if (m?.[1]) return `R${m[1]}`;
649
+ return roundName;
650
+ }
642
651
  function inferRoundType(roundName) {
643
652
  return FINALS_PATTERN.test(roundName) ? "Finals" : "HomeAndAway";
644
653
  }
@@ -713,7 +722,10 @@ function transformMatchItems(items, season, competition, source = "afl-api") {
713
722
  q3Away: findPeriod(awayScore?.periodScore, 3),
714
723
  q4Away: findPeriod(awayScore?.periodScore, 4),
715
724
  status: toMatchStatus(item.match.status),
716
- attendance: null,
725
+ attendance: item.attendance ?? null,
726
+ weatherTempCelsius: item.weather?.tempInCelsius ?? null,
727
+ weatherType: item.weather?.weatherType ?? null,
728
+ roundCode: toRoundCode(item.round?.name),
717
729
  venueState: item.venue?.state ?? null,
718
730
  venueTimezone: item.venue?.timeZone ?? null,
719
731
  homeRushedBehinds: homeScore?.rushedBehinds ?? null,
@@ -725,13 +737,21 @@ function transformMatchItems(items, season, competition, source = "afl-api") {
725
737
  };
726
738
  });
727
739
  }
728
- var FINALS_PATTERN;
740
+ var FINALS_PATTERN, ROUND_CODE_MAP, ROUND_NUMBER_PATTERN;
729
741
  var init_match_results = __esm({
730
742
  "src/transforms/match-results.ts"() {
731
743
  "use strict";
732
744
  init_team_mapping();
733
745
  init_venue_mapping();
734
746
  FINALS_PATTERN = /final|elimination|qualifying|preliminary|semi|grand/i;
747
+ ROUND_CODE_MAP = /* @__PURE__ */ new Map([
748
+ ["Qualifying Final", "QF"],
749
+ ["Elimination Final", "EF"],
750
+ ["Semi Final", "SF"],
751
+ ["Preliminary Final", "PF"],
752
+ ["Grand Final", "GF"]
753
+ ]);
754
+ ROUND_NUMBER_PATTERN = /^Round\s+(\d+)$/i;
735
755
  }
736
756
  });
737
757
 
@@ -813,6 +833,9 @@ function parseMatchList(html, year) {
813
833
  q4Away: null,
814
834
  status: "Complete",
815
835
  attendance: attendance ? Number.parseInt(attendance, 10) || null : null,
836
+ weatherTempCelsius: null,
837
+ weatherType: null,
838
+ roundCode: toRoundCode(currentRoundName),
816
839
  venueState: null,
817
840
  venueTimezone: null,
818
841
  homeRushedBehinds: null,
@@ -1022,7 +1045,7 @@ var init_footywire = __esm({
1022
1045
  FootyWireClient = class {
1023
1046
  fetchFn;
1024
1047
  constructor(options) {
1025
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
1048
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
1026
1049
  }
1027
1050
  /**
1028
1051
  * Fetch the HTML content of any URL using this client's fetch function.
@@ -1338,7 +1361,7 @@ var init_afl_coaches = __esm({
1338
1361
  AflCoachesClient = class {
1339
1362
  fetchFn;
1340
1363
  constructor(options) {
1341
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
1364
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
1342
1365
  }
1343
1366
  /**
1344
1367
  * Fetch the HTML content of an AFLCA page.
@@ -1504,7 +1527,7 @@ var init_concurrency = __esm({
1504
1527
 
1505
1528
  // src/lib/validation.ts
1506
1529
  import { z } from "zod/v4";
1507
- var AflApiTokenSchema, CompetitionSchema, CompetitionListSchema, CompseasonSchema, CompseasonListSchema, RoundSchema, RoundListSchema, ScoreSchema, PeriodScoreSchema, TeamScoreSchema, CfsMatchTeamSchema, CfsMatchSchema, CfsScoreSchema, CfsVenueSchema, MatchItemSchema, MatchItemListSchema, CfsPlayerInnerSchema, statNum, PlayerGameStatsSchema, PlayerStatsItemSchema, PlayerStatsListSchema, RosterPlayerSchema, TeamPlayersSchema, MatchRosterSchema, TeamItemSchema, TeamListSchema, SquadPlayerInnerSchema, SquadPlayerItemSchema, SquadSchema, SquadListSchema, WinLossRecordSchema, LadderEntryRawSchema, LadderResponseSchema;
1530
+ var AflApiTokenSchema, CompetitionSchema, CompetitionListSchema, CompseasonSchema, CompseasonListSchema, RoundSchema, RoundListSchema, ScoreSchema, PeriodScoreSchema, TeamScoreSchema, CfsMatchTeamSchema, CfsMatchSchema, CfsScoreSchema, CfsVenueSchema, CfsWeatherSchema, MatchItemSchema, MatchItemListSchema, CfsPlayerInnerSchema, statNum, PlayerGameStatsSchema, PlayerStatsItemSchema, PlayerStatsListSchema, RosterPlayerSchema, TeamPlayersSchema, MatchRosterSchema, TeamItemSchema, TeamListSchema, SquadPlayerInnerSchema, SquadPlayerItemSchema, SquadSchema, SquadListSchema, WinLossRecordSchema, LadderEntryRawSchema, LadderResponseSchema;
1508
1531
  var init_validation = __esm({
1509
1532
  "src/lib/validation.ts"() {
1510
1533
  "use strict";
@@ -1588,6 +1611,10 @@ var init_validation = __esm({
1588
1611
  state: z.string().optional(),
1589
1612
  timeZone: z.string().optional()
1590
1613
  }).passthrough();
1614
+ CfsWeatherSchema = z.object({
1615
+ tempInCelsius: z.number().nullable().optional(),
1616
+ weatherType: z.string().nullable().optional()
1617
+ }).passthrough();
1591
1618
  MatchItemSchema = z.object({
1592
1619
  match: CfsMatchSchema,
1593
1620
  score: CfsScoreSchema.nullish(),
@@ -1596,7 +1623,9 @@ var init_validation = __esm({
1596
1623
  name: z.string(),
1597
1624
  roundId: z.string(),
1598
1625
  roundNumber: z.number()
1599
- }).passthrough().optional()
1626
+ }).passthrough().optional(),
1627
+ attendance: z.number().nullable().optional(),
1628
+ weather: CfsWeatherSchema.nullable().optional()
1600
1629
  }).passthrough();
1601
1630
  MatchItemListSchema = z.object({
1602
1631
  roundId: z.string().optional(),
@@ -1660,6 +1689,7 @@ var init_validation = __esm({
1660
1689
  goalEfficiency: statNum,
1661
1690
  shotEfficiency: statNum,
1662
1691
  interchangeCounts: statNum,
1692
+ brownlowVotes: statNum,
1663
1693
  extendedStats: z.object({
1664
1694
  effectiveDisposals: statNum,
1665
1695
  effectiveKicks: statNum,
@@ -1814,7 +1844,7 @@ var init_afl_api = __esm({
1814
1844
  cachedToken = null;
1815
1845
  pendingAuth = null;
1816
1846
  constructor(options) {
1817
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
1847
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
1818
1848
  this.tokenUrl = options?.tokenUrl ?? TOKEN_URL;
1819
1849
  }
1820
1850
  /**
@@ -2243,7 +2273,7 @@ var init_squiggle = __esm({
2243
2273
  SquiggleClient = class {
2244
2274
  fetchFn;
2245
2275
  constructor(options) {
2246
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
2276
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
2247
2277
  }
2248
2278
  /**
2249
2279
  * Fetch JSON from the Squiggle API.
@@ -2348,6 +2378,9 @@ function transformSquiggleGamesToResults(games, season) {
2348
2378
  q4Away: null,
2349
2379
  status: "Complete",
2350
2380
  attendance: null,
2381
+ weatherTempCelsius: null,
2382
+ weatherType: null,
2383
+ roundCode: toRoundCode(g.roundname),
2351
2384
  venueState: null,
2352
2385
  venueTimezone: g.tz || null,
2353
2386
  homeRushedBehinds: null,
@@ -2561,6 +2594,7 @@ function parseAflTablesGameStats(html, matchId, season, roundNumber) {
2561
2594
  goalEfficiency: null,
2562
2595
  shotEfficiency: null,
2563
2596
  interchangeCounts: null,
2597
+ brownlowVotes: null,
2564
2598
  supercoachScore: null,
2565
2599
  dreamTeamPoints: null,
2566
2600
  effectiveDisposals: null,
@@ -2693,6 +2727,9 @@ function parseSeasonPage(html, year) {
2693
2727
  q4Away: awayQuarters[3] ?? null,
2694
2728
  status: "Complete",
2695
2729
  attendance,
2730
+ weatherTempCelsius: null,
2731
+ weatherType: null,
2732
+ roundCode: toRoundCode(currentRoundName),
2696
2733
  venueState: null,
2697
2734
  venueTimezone: null,
2698
2735
  homeRushedBehinds: null,
@@ -2857,7 +2894,7 @@ var init_afl_tables = __esm({
2857
2894
  AflTablesClient = class {
2858
2895
  fetchFn;
2859
2896
  constructor(options) {
2860
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
2897
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
2861
2898
  }
2862
2899
  /**
2863
2900
  * Fetch season match results from AFL Tables.
@@ -3580,6 +3617,7 @@ function transformOne(item, ctx) {
3580
3617
  goalEfficiency: toNullable(stats?.goalEfficiency),
3581
3618
  shotEfficiency: toNullable(stats?.shotEfficiency),
3582
3619
  interchangeCounts: toNullable(stats?.interchangeCounts),
3620
+ brownlowVotes: toNullable(stats?.brownlowVotes),
3583
3621
  supercoachScore: null,
3584
3622
  dreamTeamPoints: toNullable(stats?.dreamTeamPoints),
3585
3623
  effectiveDisposals: toNullable(stats?.extendedStats?.effectiveDisposals),
@@ -5354,7 +5392,7 @@ resolveAliases();
5354
5392
  var main = defineCommand11({
5355
5393
  meta: {
5356
5394
  name: "fitzroy",
5357
- version: "1.5.0",
5395
+ version: "1.6.1",
5358
5396
  description: "TypeScript port of the fitzRoy R package \u2014 fetch AFL data from the command line"
5359
5397
  },
5360
5398
  subCommands: {
package/dist/index.d.ts CHANGED
@@ -82,6 +82,11 @@ interface MatchResult {
82
82
  readonly q4Away: QuarterScore | null;
83
83
  readonly status: MatchStatus;
84
84
  readonly attendance: number | null;
85
+ /** Weather conditions at the venue (null when unavailable). */
86
+ readonly weatherTempCelsius: number | null;
87
+ readonly weatherType: string | null;
88
+ /** Normalised round code (e.g. "R1", "QF", "GF"). Null for scraped sources. */
89
+ readonly roundCode: string | null;
85
90
  /** Venue metadata (null for scraped sources). */
86
91
  readonly venueState: string | null;
87
92
  readonly venueTimezone: string | null;
@@ -161,6 +166,8 @@ interface PlayerStats {
161
166
  readonly goalEfficiency: number | null;
162
167
  readonly shotEfficiency: number | null;
163
168
  readonly interchangeCounts: number | null;
169
+ /** Brownlow votes received in this match (null when unavailable). */
170
+ readonly brownlowVotes: number | null;
164
171
  /** Fantasy. */
165
172
  readonly supercoachScore: number | null;
166
173
  readonly dreamTeamPoints: number | null;
@@ -1100,6 +1107,11 @@ declare const MatchItemSchema: z2.ZodObject<{
1100
1107
  roundId: z2.ZodString;
1101
1108
  roundNumber: z2.ZodNumber;
1102
1109
  }, z2.core.$loose>>;
1110
+ attendance: z2.ZodOptional<z2.ZodNullable<z2.ZodNumber>>;
1111
+ weather: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1112
+ tempInCelsius: z2.ZodOptional<z2.ZodNullable<z2.ZodNumber>>;
1113
+ weatherType: z2.ZodOptional<z2.ZodNullable<z2.ZodString>>;
1114
+ }, z2.core.$loose>>>;
1103
1115
  }, z2.core.$loose>;
1104
1116
  /** Schema for the match items (round results) response. */
1105
1117
  declare const MatchItemListSchema: z2.ZodObject<{
@@ -1180,6 +1192,11 @@ declare const MatchItemListSchema: z2.ZodObject<{
1180
1192
  roundId: z2.ZodString;
1181
1193
  roundNumber: z2.ZodNumber;
1182
1194
  }, z2.core.$loose>>;
1195
+ attendance: z2.ZodOptional<z2.ZodNullable<z2.ZodNumber>>;
1196
+ weather: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1197
+ tempInCelsius: z2.ZodOptional<z2.ZodNullable<z2.ZodNumber>>;
1198
+ weatherType: z2.ZodOptional<z2.ZodNullable<z2.ZodString>>;
1199
+ }, z2.core.$loose>>>;
1183
1200
  }, z2.core.$loose>>;
1184
1201
  }, z2.core.$loose>;
1185
1202
  /** Inferred type for a single match item. */
@@ -1227,6 +1244,7 @@ declare const PlayerGameStatsSchema: z2.ZodObject<{
1227
1244
  goalEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1228
1245
  shotEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1229
1246
  interchangeCounts: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1247
+ brownlowVotes: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1230
1248
  extendedStats: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1231
1249
  effectiveDisposals: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1232
1250
  effectiveKicks: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
@@ -1315,6 +1333,7 @@ declare const PlayerStatsItemSchema: z2.ZodObject<{
1315
1333
  goalEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1316
1334
  shotEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1317
1335
  interchangeCounts: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1336
+ brownlowVotes: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1318
1337
  extendedStats: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1319
1338
  effectiveDisposals: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1320
1339
  effectiveKicks: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
@@ -1407,6 +1426,7 @@ declare const PlayerStatsListSchema: z2.ZodObject<{
1407
1426
  goalEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1408
1427
  shotEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1409
1428
  interchangeCounts: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1429
+ brownlowVotes: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1410
1430
  extendedStats: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1411
1431
  effectiveDisposals: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1412
1432
  effectiveKicks: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
@@ -1497,6 +1517,7 @@ declare const PlayerStatsListSchema: z2.ZodObject<{
1497
1517
  goalEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1498
1518
  shotEfficiency: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1499
1519
  interchangeCounts: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1520
+ brownlowVotes: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1500
1521
  extendedStats: z2.ZodOptional<z2.ZodNullable<z2.ZodObject<{
1501
1522
  effectiveDisposals: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
1502
1523
  effectiveKicks: z2.ZodOptional<z2.ZodNullable<z2.ZodUnion<readonly [z2.ZodNumber, z2.ZodPipe<z2.ZodString, z2.ZodTransform<number | null, string>>, z2.ZodPipe<z2.ZodBoolean, z2.ZodTransform<1 | 0, boolean>>]>>>;
package/dist/index.js CHANGED
@@ -535,6 +535,7 @@ function mergeFootyWireStats(basicTeams, advancedTeams, matchId, season, roundNu
535
535
  goalEfficiency: null,
536
536
  shotEfficiency: null,
537
537
  interchangeCounts: null,
538
+ brownlowVotes: null,
538
539
  supercoachScore: basic.supercoachPoints,
539
540
  dreamTeamPoints: basic.dreamTeamPoints,
540
541
  effectiveDisposals: adv?.effectiveDisposals ?? null,
@@ -572,6 +573,22 @@ function mergeFootyWireStats(basicTeams, advancedTeams, matchId, season, roundNu
572
573
 
573
574
  // src/transforms/match-results.ts
574
575
  var FINALS_PATTERN = /final|elimination|qualifying|preliminary|semi|grand/i;
576
+ var ROUND_CODE_MAP = /* @__PURE__ */ new Map([
577
+ ["Qualifying Final", "QF"],
578
+ ["Elimination Final", "EF"],
579
+ ["Semi Final", "SF"],
580
+ ["Preliminary Final", "PF"],
581
+ ["Grand Final", "GF"]
582
+ ]);
583
+ var ROUND_NUMBER_PATTERN = /^Round\s+(\d+)$/i;
584
+ function toRoundCode(roundName) {
585
+ if (!roundName) return null;
586
+ const mapped = ROUND_CODE_MAP.get(roundName);
587
+ if (mapped) return mapped;
588
+ const m = ROUND_NUMBER_PATTERN.exec(roundName);
589
+ if (m?.[1]) return `R${m[1]}`;
590
+ return roundName;
591
+ }
575
592
  function inferRoundType(roundName) {
576
593
  return FINALS_PATTERN.test(roundName) ? "Finals" : "HomeAndAway";
577
594
  }
@@ -646,7 +663,10 @@ function transformMatchItems(items, season, competition, source = "afl-api") {
646
663
  q3Away: findPeriod(awayScore?.periodScore, 3),
647
664
  q4Away: findPeriod(awayScore?.periodScore, 4),
648
665
  status: toMatchStatus(item.match.status),
649
- attendance: null,
666
+ attendance: item.attendance ?? null,
667
+ weatherTempCelsius: item.weather?.tempInCelsius ?? null,
668
+ weatherType: item.weather?.weatherType ?? null,
669
+ roundCode: toRoundCode(item.round?.name),
650
670
  venueState: item.venue?.state ?? null,
651
671
  venueTimezone: item.venue?.timeZone ?? null,
652
672
  homeRushedBehinds: homeScore?.rushedBehinds ?? null,
@@ -664,7 +684,7 @@ var FOOTYWIRE_BASE = "https://www.footywire.com/afl/footy";
664
684
  var FootyWireClient = class {
665
685
  fetchFn;
666
686
  constructor(options) {
667
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
687
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
668
688
  }
669
689
  /**
670
690
  * Fetch the HTML content of any URL using this client's fetch function.
@@ -970,6 +990,9 @@ function parseMatchList(html, year) {
970
990
  q4Away: null,
971
991
  status: "Complete",
972
992
  attendance: attendance ? Number.parseInt(attendance, 10) || null : null,
993
+ weatherTempCelsius: null,
994
+ weatherType: null,
995
+ roundCode: toRoundCode(currentRoundName),
973
996
  venueState: null,
974
997
  venueTimezone: null,
975
998
  homeRushedBehinds: null,
@@ -1353,7 +1376,7 @@ import * as cheerio4 from "cheerio";
1353
1376
  var AflCoachesClient = class {
1354
1377
  fetchFn;
1355
1378
  constructor(options) {
1356
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
1379
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
1357
1380
  }
1358
1381
  /**
1359
1382
  * Fetch the HTML content of an AFLCA page.
@@ -1635,6 +1658,10 @@ var CfsVenueSchema = z.object({
1635
1658
  state: z.string().optional(),
1636
1659
  timeZone: z.string().optional()
1637
1660
  }).passthrough();
1661
+ var CfsWeatherSchema = z.object({
1662
+ tempInCelsius: z.number().nullable().optional(),
1663
+ weatherType: z.string().nullable().optional()
1664
+ }).passthrough();
1638
1665
  var MatchItemSchema = z.object({
1639
1666
  match: CfsMatchSchema,
1640
1667
  score: CfsScoreSchema.nullish(),
@@ -1643,7 +1670,9 @@ var MatchItemSchema = z.object({
1643
1670
  name: z.string(),
1644
1671
  roundId: z.string(),
1645
1672
  roundNumber: z.number()
1646
- }).passthrough().optional()
1673
+ }).passthrough().optional(),
1674
+ attendance: z.number().nullable().optional(),
1675
+ weather: CfsWeatherSchema.nullable().optional()
1647
1676
  }).passthrough();
1648
1677
  var MatchItemListSchema = z.object({
1649
1678
  roundId: z.string().optional(),
@@ -1707,6 +1736,7 @@ var PlayerGameStatsSchema = z.object({
1707
1736
  goalEfficiency: statNum,
1708
1737
  shotEfficiency: statNum,
1709
1738
  interchangeCounts: statNum,
1739
+ brownlowVotes: statNum,
1710
1740
  extendedStats: z.object({
1711
1741
  effectiveDisposals: statNum,
1712
1742
  effectiveKicks: statNum,
@@ -1851,7 +1881,7 @@ var AflApiClient = class {
1851
1881
  cachedToken = null;
1852
1882
  pendingAuth = null;
1853
1883
  constructor(options) {
1854
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
1884
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
1855
1885
  this.tokenUrl = options?.tokenUrl ?? TOKEN_URL;
1856
1886
  }
1857
1887
  /**
@@ -2265,7 +2295,7 @@ var USER_AGENT = "fitzRoy-ts/1.0 (https://github.com/jackemcpherson/fitzRoy-ts)"
2265
2295
  var SquiggleClient = class {
2266
2296
  fetchFn;
2267
2297
  constructor(options) {
2268
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
2298
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
2269
2299
  }
2270
2300
  /**
2271
2301
  * Fetch JSON from the Squiggle API.
@@ -2368,6 +2398,9 @@ function transformSquiggleGamesToResults(games, season) {
2368
2398
  q4Away: null,
2369
2399
  status: "Complete",
2370
2400
  attendance: null,
2401
+ weatherTempCelsius: null,
2402
+ weatherType: null,
2403
+ roundCode: toRoundCode(g.roundname),
2371
2404
  venueState: null,
2372
2405
  venueTimezone: g.tz || null,
2373
2406
  homeRushedBehinds: null,
@@ -2561,6 +2594,7 @@ function parseAflTablesGameStats(html, matchId, season, roundNumber) {
2561
2594
  goalEfficiency: null,
2562
2595
  shotEfficiency: null,
2563
2596
  interchangeCounts: null,
2597
+ brownlowVotes: null,
2564
2598
  supercoachScore: null,
2565
2599
  dreamTeamPoints: null,
2566
2600
  effectiveDisposals: null,
@@ -2612,7 +2646,7 @@ var AFL_TABLES_BASE = "https://afltables.com/afl/seas";
2612
2646
  var AflTablesClient = class {
2613
2647
  fetchFn;
2614
2648
  constructor(options) {
2615
- this.fetchFn = options?.fetchFn ?? globalThis.fetch;
2649
+ this.fetchFn = options?.fetchFn ?? globalThis.fetch.bind(globalThis);
2616
2650
  }
2617
2651
  /**
2618
2652
  * Fetch season match results from AFL Tables.
@@ -2857,6 +2891,9 @@ function parseSeasonPage(html, year) {
2857
2891
  q4Away: awayQuarters[3] ?? null,
2858
2892
  status: "Complete",
2859
2893
  attendance,
2894
+ weatherTempCelsius: null,
2895
+ weatherType: null,
2896
+ roundCode: toRoundCode(currentRoundName),
2860
2897
  venueState: null,
2861
2898
  venueTimezone: null,
2862
2899
  homeRushedBehinds: null,
@@ -3492,6 +3529,7 @@ function transformOne(item, ctx) {
3492
3529
  goalEfficiency: toNullable(stats?.goalEfficiency),
3493
3530
  shotEfficiency: toNullable(stats?.shotEfficiency),
3494
3531
  interchangeCounts: toNullable(stats?.interchangeCounts),
3532
+ brownlowVotes: toNullable(stats?.brownlowVotes),
3495
3533
  supercoachScore: null,
3496
3534
  dreamTeamPoints: toNullable(stats?.dreamTeamPoints),
3497
3535
  effectiveDisposals: toNullable(stats?.extendedStats?.effectiveDisposals),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fitzroy",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "TypeScript port of the fitzRoy R package — programmatic access to AFL data including match results, player stats, fixtures, ladders, and more",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",