nhl-api-ts 0.1.0 → 0.2.0

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.
Files changed (80) hide show
  1. package/README.md +22 -2
  2. package/dist/api/edge.d.mts +25 -24
  3. package/dist/api/game-center.d.mts +9 -8
  4. package/dist/api/helpers.d.mts +4 -3
  5. package/dist/api/misc.d.mts +6 -6
  6. package/dist/api/players.d.mts +4 -3
  7. package/dist/api/query/builder.d.mts +2 -0
  8. package/dist/api/query/builder.mjs +3 -1
  9. package/dist/api/query/index.d.mts +2 -2
  10. package/dist/api/query/index.mjs +1 -1
  11. package/dist/api/query/sorting/goalie-sorts.d.mts +55 -0
  12. package/dist/api/query/sorting/goalie-sorts.mjs +43 -48
  13. package/dist/api/query/sorting/sorting-options.d.mts +125 -0
  14. package/dist/api/query/sorting/sorting-options.mjs +3 -2
  15. package/dist/api/schedule.d.mts +12 -11
  16. package/dist/api/standings.d.mts +4 -3
  17. package/dist/api/stats.d.mts +19 -14
  18. package/dist/api/stats.mjs +23 -5
  19. package/dist/api/teams.d.mts +6 -5
  20. package/dist/index.d.mts +2 -1
  21. package/dist/nhl-client.d.mts +13 -9
  22. package/dist/nhl-client.mjs +1 -1
  23. package/dist/types/common.d.mts +81 -0
  24. package/dist/types/common.mjs +2 -0
  25. package/dist/types/edge.d.mts +1024 -0
  26. package/dist/types/edge.mjs +1 -0
  27. package/dist/types/game-center.d.mts +1194 -0
  28. package/dist/types/game-center.mjs +1 -0
  29. package/dist/types/helpers.d.mts +17 -0
  30. package/dist/types/helpers.mjs +1 -0
  31. package/dist/types/index.d.mts +10 -0
  32. package/dist/types/index.mjs +1 -0
  33. package/dist/types/misc.d.mts +68 -0
  34. package/dist/types/misc.mjs +2 -0
  35. package/dist/types/players.d.mts +42 -0
  36. package/dist/types/players.mjs +1 -0
  37. package/dist/types/schedule.d.mts +456 -0
  38. package/dist/types/schedule.mjs +1 -0
  39. package/dist/types/standings.d.mts +104 -0
  40. package/dist/types/standings.mjs +1 -0
  41. package/dist/types/stats.d.mts +1086 -0
  42. package/dist/types/stats.mjs +1 -0
  43. package/dist/types/teams.d.mts +29 -0
  44. package/dist/types/teams.mjs +1 -0
  45. package/dist/utils.d.mts +0 -1
  46. package/package.json +11 -3
  47. package/dist/api/query/errors.d.mts +0 -3
  48. package/dist/api/query/errors.mjs +0 -6
  49. package/dist/api/query/filters/base.d.mts +0 -4
  50. package/dist/api/query/filters/base.mjs +0 -2
  51. package/dist/api/query/filters/decision.d.mts +0 -13
  52. package/dist/api/query/filters/decision.mjs +0 -26
  53. package/dist/api/query/filters/draft.d.mts +0 -15
  54. package/dist/api/query/filters/draft.mjs +0 -27
  55. package/dist/api/query/filters/experience.d.mts +0 -9
  56. package/dist/api/query/filters/experience.mjs +0 -17
  57. package/dist/api/query/filters/franchise.d.mts +0 -9
  58. package/dist/api/query/filters/franchise.mjs +0 -15
  59. package/dist/api/query/filters/game-type.d.mts +0 -10
  60. package/dist/api/query/filters/game-type.mjs +0 -16
  61. package/dist/api/query/filters/goalie-sorts.d.mts +0 -3
  62. package/dist/api/query/filters/goalie-sorts.mjs +0 -55
  63. package/dist/api/query/filters/home-road.d.mts +0 -9
  64. package/dist/api/query/filters/home-road.mjs +0 -16
  65. package/dist/api/query/filters/index.d.mts +0 -14
  66. package/dist/api/query/filters/index.mjs +0 -14
  67. package/dist/api/query/filters/nationality.d.mts +0 -12
  68. package/dist/api/query/filters/nationality.mjs +0 -19
  69. package/dist/api/query/filters/opponent.d.mts +0 -10
  70. package/dist/api/query/filters/opponent.mjs +0 -16
  71. package/dist/api/query/filters/position.d.mts +0 -16
  72. package/dist/api/query/filters/position.mjs +0 -28
  73. package/dist/api/query/filters/season.d.mts +0 -14
  74. package/dist/api/query/filters/season.mjs +0 -24
  75. package/dist/api/query/filters/shoot-catch.d.mts +0 -9
  76. package/dist/api/query/filters/shoot-catch.mjs +0 -16
  77. package/dist/api/query/filters/status.d.mts +0 -20
  78. package/dist/api/query/filters/status.mjs +0 -28
  79. package/dist/logging.d.mts +0 -14
  80. package/dist/logging.mjs +0 -13
package/README.md CHANGED
@@ -6,7 +6,7 @@ Every SDK method is also available as a CLI command.
6
6
 
7
7
  - Zero runtime dependencies (uses the built-in `fetch`)
8
8
  - Node.js >= 24, ESM only
9
- - Fully typed
9
+ - Fully typed: every response has a named interface you can [extend](docs/recipes/extending-response-types.md)
10
10
 
11
11
  ## Documentation
12
12
 
@@ -15,7 +15,8 @@ Every SDK method is also available as a CLI command.
15
15
  - [Recipes](docs/recipes/): [filtered stats](docs/recipes/filter-skater-stats.md),
16
16
  [pagination](docs/recipes/paginate-stats.md), [live scores](docs/recipes/live-scores.md),
17
17
  [season-wide data](docs/recipes/season-wide-data.md), [retries](docs/recipes/retries.md),
18
- [CLI + jq](docs/recipes/cli-and-jq.md), [testing](docs/recipes/testing.md)
18
+ [CLI + jq](docs/recipes/cli-and-jq.md), [testing](docs/recipes/testing.md),
19
+ [extending response types](docs/recipes/extending-response-types.md)
19
20
  - [Examples](examples/): runnable scripts
20
21
  - [API report](api-report.md): the full public TypeScript API
21
22
  - [OpenAPI](openapi.yaml): every HTTP path the SDK calls
@@ -181,6 +182,25 @@ Skater report types: `summary`, `bios`, `faceoffpercentages`, `faceoffwins`,
181
182
  `powerplay`, `puckPossessions`, `summaryshooting`, `percentages`,
182
183
  `scoringRates`, `scoringpergame`, `shootout`, `shottype`, `timeonice`.
183
184
 
185
+ ## Extending the types
186
+
187
+ Response types come from real API responses, and the NHL adds fields without
188
+ notice. Every object type is an `interface`, so you can add what's missing with
189
+ module augmentation:
190
+
191
+ ```ts
192
+ declare module 'nhl-api-ts' {
193
+ interface Boxscore {
194
+ someNewField?: string;
195
+ }
196
+ }
197
+ ```
198
+
199
+ New play types and report types are added through registries (`PlayTypes`,
200
+ `SkaterReportRows`, `GoalieReportRows`). See
201
+ [Extending response types](docs/recipes/extending-response-types.md) for those
202
+ and for the one-off cast.
203
+
184
204
  ## Errors
185
205
 
186
206
  HTTP failures throw exceptions that all extend `NHLApiException`, which has
@@ -1,5 +1,6 @@
1
1
  import type { Context } from '#src/context.mjs';
2
- import type { Id, JsonObject } from '#src/utils.mjs';
2
+ import type { CatGoalieDetail, CatSkaterDetail, Goalie5v5Detail, GoalieComparison, GoalieDetail, GoalieLanding, GoalieSavePercentageDetail, GoalieShotLocationDetail, SkaterComparison, SkaterDetail, SkaterLanding, SkaterShotLocationDetail, SkaterShotSpeedDetail, SkaterSkatingDistanceDetail, SkaterSkatingSpeedDetail, SkaterZoneTime, TeamDetail, TeamLanding, TeamShotLocationDetail, TeamShotSpeedDetail, TeamSkatingDistanceDetail, TeamSkatingSpeedDetail, TeamZoneTimeDetails } from '#src/types/index.mjs';
3
+ import type { Id } from '#src/utils.mjs';
3
4
  export interface EdgeSeasonParams {
4
5
  /** Season in YYYYYYYY format, e.g. 20232024. Defaults to the current season ("now"). */
5
6
  season?: Id;
@@ -19,139 +20,139 @@ export interface EdgeTeamParams extends EdgeSeasonParams {
19
20
  *
20
21
  * @example await client.edge.skaterDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
21
22
  */
22
- export declare const skaterDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
23
+ export declare const skaterDetail: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterDetail>;
23
24
  /**
24
25
  * Get NHL EDGE shot speed details for a specific skater.
25
26
  *
26
27
  * @example await client.edge.skaterShotSpeedDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
27
28
  */
28
- export declare const skaterShotSpeedDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
29
+ export declare const skaterShotSpeedDetail: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterShotSpeedDetail>;
29
30
  /**
30
31
  * Get NHL EDGE skating speed details for a specific skater.
31
32
  *
32
33
  * @example await client.edge.skaterSkatingSpeedDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
33
34
  */
34
- export declare const skaterSkatingSpeedDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
35
+ export declare const skaterSkatingSpeedDetail: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterSkatingSpeedDetail>;
35
36
  /**
36
37
  * Get NHL EDGE shot location details for a specific skater.
37
38
  *
38
39
  * @example await client.edge.skaterShotLocationDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
39
40
  */
40
- export declare const skaterShotLocationDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
41
+ export declare const skaterShotLocationDetail: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterShotLocationDetail>;
41
42
  /**
42
43
  * Get NHL EDGE skating distance details for a specific skater.
43
44
  *
44
45
  * @example await client.edge.skaterSkatingDistanceDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
45
46
  */
46
- export declare const skaterSkatingDistanceDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
47
+ export declare const skaterSkatingDistanceDetail: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterSkatingDistanceDetail>;
47
48
  /**
48
49
  * Get NHL EDGE comparison statistics for a specific skater.
49
50
  *
50
51
  * @example await client.edge.skaterComparison({ playerId: 8478402, season: '20232024', gameType: 2 })
51
52
  */
52
- export declare const skaterComparison: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
53
+ export declare const skaterComparison: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterComparison>;
53
54
  /**
54
55
  * Get NHL EDGE zone time details for a specific skater.
55
56
  *
56
57
  * @example await client.edge.skaterZoneTime({ playerId: 8478402, season: '20232024', gameType: 2 })
57
58
  */
58
- export declare const skaterZoneTime: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
59
+ export declare const skaterZoneTime: (ctx: Context, params: EdgePlayerParams) => Promise<SkaterZoneTime>;
59
60
  /**
60
61
  * Get NHL EDGE skater landing page data.
61
62
  *
62
63
  * @example await client.edge.skaterLanding({ season: '20232024' })
63
64
  */
64
- export declare const skaterLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<JsonObject>;
65
+ export declare const skaterLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<SkaterLanding>;
65
66
  /**
66
67
  * Get NHL CAT (Catch All Tracking) EDGE skater details.
67
68
  *
68
69
  * @example await client.edge.catSkaterDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
69
70
  */
70
- export declare const catSkaterDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
71
+ export declare const catSkaterDetail: (ctx: Context, params: EdgePlayerParams) => Promise<CatSkaterDetail>;
71
72
  /**
72
73
  * Get NHL EDGE goalie detail statistics for a specific player.
73
74
  *
74
75
  * @example await client.edge.goalieDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
75
76
  */
76
- export declare const goalieDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
77
+ export declare const goalieDetail: (ctx: Context, params: EdgePlayerParams) => Promise<GoalieDetail>;
77
78
  /**
78
79
  * Get NHL EDGE shot location details for a specific goalie.
79
80
  *
80
81
  * @example await client.edge.goalieShotLocationDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
81
82
  */
82
- export declare const goalieShotLocationDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
83
+ export declare const goalieShotLocationDetail: (ctx: Context, params: EdgePlayerParams) => Promise<GoalieShotLocationDetail>;
83
84
  /**
84
85
  * Get NHL EDGE 5v5 performance details for a specific goalie.
85
86
  *
86
87
  * @example await client.edge.goalie5v5Detail({ playerId: 8478402, season: '20232024', gameType: 2 })
87
88
  */
88
- export declare const goalie5v5Detail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
89
+ export declare const goalie5v5Detail: (ctx: Context, params: EdgePlayerParams) => Promise<Goalie5v5Detail>;
89
90
  /**
90
91
  * Get NHL EDGE comparison statistics for a specific goalie.
91
92
  *
92
93
  * @example await client.edge.goalieComparison({ playerId: 8478402, season: '20232024', gameType: 2 })
93
94
  */
94
- export declare const goalieComparison: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
95
+ export declare const goalieComparison: (ctx: Context, params: EdgePlayerParams) => Promise<GoalieComparison>;
95
96
  /**
96
97
  * Get NHL EDGE save percentage details for a specific goalie.
97
98
  *
98
99
  * @example await client.edge.goalieSavePercentageDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
99
100
  */
100
- export declare const goalieSavePercentageDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
101
+ export declare const goalieSavePercentageDetail: (ctx: Context, params: EdgePlayerParams) => Promise<GoalieSavePercentageDetail>;
101
102
  /**
102
103
  * Get NHL EDGE goalie landing page data.
103
104
  *
104
105
  * @example await client.edge.goalieLanding({ season: '20232024' })
105
106
  */
106
- export declare const goalieLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<JsonObject>;
107
+ export declare const goalieLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<GoalieLanding>;
107
108
  /**
108
109
  * Get NHL CAT (Catch All Tracking) EDGE goalie details.
109
110
  *
110
111
  * @example await client.edge.catGoalieDetail({ playerId: 8478402, season: '20232024', gameType: 2 })
111
112
  */
112
- export declare const catGoalieDetail: (ctx: Context, params: EdgePlayerParams) => Promise<JsonObject>;
113
+ export declare const catGoalieDetail: (ctx: Context, params: EdgePlayerParams) => Promise<CatGoalieDetail>;
113
114
  /**
114
115
  * Get NHL EDGE team detail statistics for a specific team.
115
116
  *
116
117
  * @example await client.edge.teamDetail({ teamId: 10 })
117
118
  */
118
- export declare const teamDetail: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
119
+ export declare const teamDetail: (ctx: Context, params: EdgeTeamParams) => Promise<TeamDetail>;
119
120
  /**
120
121
  * Get NHL EDGE skating distance details for a specific team.
121
122
  *
122
123
  * @example await client.edge.teamSkatingDistanceDetail({ teamId: 10 })
123
124
  */
124
- export declare const teamSkatingDistanceDetail: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
125
+ export declare const teamSkatingDistanceDetail: (ctx: Context, params: EdgeTeamParams) => Promise<TeamSkatingDistanceDetail>;
125
126
  /**
126
127
  * Get NHL EDGE zone time details for a specific team.
127
128
  *
128
129
  * @example await client.edge.teamZoneTimeDetails({ teamId: 10 })
129
130
  */
130
- export declare const teamZoneTimeDetails: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
131
+ export declare const teamZoneTimeDetails: (ctx: Context, params: EdgeTeamParams) => Promise<TeamZoneTimeDetails>;
131
132
  /**
132
133
  * Get NHL EDGE shot location details for a specific team.
133
134
  *
134
135
  * @example await client.edge.teamShotLocationDetail({ teamId: 10 })
135
136
  */
136
- export declare const teamShotLocationDetail: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
137
+ export declare const teamShotLocationDetail: (ctx: Context, params: EdgeTeamParams) => Promise<TeamShotLocationDetail>;
137
138
  /**
138
139
  * Get NHL EDGE team landing page data.
139
140
  *
140
141
  * @example await client.edge.teamLanding({ season: '20232024' })
141
142
  */
142
- export declare const teamLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<JsonObject>;
143
+ export declare const teamLanding: (ctx: Context, params?: EdgeSeasonParams) => Promise<TeamLanding>;
143
144
  /**
144
145
  * Get NHL EDGE shot speed details for a specific team.
145
146
  *
146
147
  * @example await client.edge.teamShotSpeedDetail({ teamId: 10 })
147
148
  */
148
- export declare const teamShotSpeedDetail: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
149
+ export declare const teamShotSpeedDetail: (ctx: Context, params: EdgeTeamParams) => Promise<TeamShotSpeedDetail>;
149
150
  /**
150
151
  * Get NHL EDGE skating speed details for a specific team.
151
152
  *
152
153
  * @example await client.edge.teamSkatingSpeedDetail({ teamId: 10 })
153
154
  */
154
- export declare const teamSkatingSpeedDetail: (ctx: Context, params: EdgeTeamParams) => Promise<JsonObject>;
155
+ export declare const teamSkatingSpeedDetail: (ctx: Context, params: EdgeTeamParams) => Promise<TeamSkatingSpeedDetail>;
155
156
  export declare const edgeApi: {
156
157
  readonly skaterDetail: typeof skaterDetail;
157
158
  readonly skaterShotSpeedDetail: typeof skaterShotSpeedDetail;
@@ -1,5 +1,6 @@
1
1
  import type { Context } from '#src/context.mjs';
2
- import type { Id, JsonObject } from '#src/utils.mjs';
2
+ import type { Boxscore, DailyScores, GameLanding, GameStory, PlayByPlay, RightRail, ShiftChart } from '#src/types/index.mjs';
3
+ import type { Id } from '#src/utils.mjs';
3
4
  /**
4
5
  * Get the full boxscore for a specific NHL game, including team scores,
5
6
  * shots on goal, and per-player stats.
@@ -9,7 +10,7 @@ import type { Id, JsonObject } from '#src/utils.mjs';
9
10
  */
10
11
  export declare const boxscore: (ctx: Context, { gameId }: {
11
12
  gameId: Id;
12
- }) => Promise<JsonObject>;
13
+ }) => Promise<Boxscore>;
13
14
  /**
14
15
  * Get the full play-by-play feed for a specific NHL game, containing every
15
16
  * recorded event (shots, hits, faceoffs, goals, penalties...).
@@ -19,7 +20,7 @@ export declare const boxscore: (ctx: Context, { gameId }: {
19
20
  */
20
21
  export declare const playByPlay: (ctx: Context, { gameId }: {
21
22
  gameId: Id;
22
- }) => Promise<JsonObject>;
23
+ }) => Promise<PlayByPlay>;
23
24
  /**
24
25
  * Get the landing-page summary for a specific NHL game, including scoring by
25
26
  * period, three stars and penalties.
@@ -29,7 +30,7 @@ export declare const playByPlay: (ctx: Context, { gameId }: {
29
30
  */
30
31
  export declare const matchUp: (ctx: Context, { gameId }: {
31
32
  gameId: Id;
32
- }) => Promise<JsonObject>;
33
+ }) => Promise<GameLanding>;
33
34
  /**
34
35
  * Get scores and game states for all NHL games on a given date. Returns the
35
36
  * current day's scores when no date is supplied.
@@ -39,7 +40,7 @@ export declare const matchUp: (ctx: Context, { gameId }: {
39
40
  */
40
41
  export declare const dailyScores: (ctx: Context, { date }?: {
41
42
  date?: string;
42
- }) => Promise<JsonObject>;
43
+ }) => Promise<DailyScores>;
43
44
  /**
44
45
  * Get individual player shift data for a specific game, including start/end
45
46
  * times and durations.
@@ -51,7 +52,7 @@ export declare const dailyScores: (ctx: Context, { date }?: {
51
52
  export declare const shiftChartData: (ctx: Context, { gameId, excludes }: {
52
53
  gameId: Id;
53
54
  excludes?: string[];
54
- }) => Promise<JsonObject>;
55
+ }) => Promise<ShiftChart>;
55
56
  /**
56
57
  * Get the season-series record and contextual stats for a specific game,
57
58
  * including team season stats and last games.
@@ -61,7 +62,7 @@ export declare const shiftChartData: (ctx: Context, { gameId, excludes }: {
61
62
  */
62
63
  export declare const seasonSeriesMatchup: (ctx: Context, { gameId }: {
63
64
  gameId: Id;
64
- }) => Promise<JsonObject>;
65
+ }) => Promise<RightRail>;
65
66
  /**
66
67
  * Get the narrative game story for a specific game, including scoring
67
68
  * summaries, three stars and team game stats.
@@ -71,7 +72,7 @@ export declare const seasonSeriesMatchup: (ctx: Context, { gameId }: {
71
72
  */
72
73
  export declare const gameStory: (ctx: Context, { gameId }: {
73
74
  gameId: Id;
74
- }) => Promise<JsonObject>;
75
+ }) => Promise<GameStory>;
75
76
  export declare const gameCenterApi: {
76
77
  readonly boxscore: typeof boxscore;
77
78
  readonly playByPlay: typeof playByPlay;
@@ -1,5 +1,6 @@
1
1
  import type { Context } from '#src/context.mjs';
2
- import type { Id, JsonObject } from '#src/utils.mjs';
2
+ import type { AllPlayersEntry, PlayerSummaryStatistics } from '#src/types/index.mjs';
3
+ import type { Id } from '#src/utils.mjs';
3
4
  /**
4
5
  * Gets all game IDs for a specified season by querying every team's
5
6
  * schedule. Games appear once per participating team, so ids may repeat.
@@ -25,7 +26,7 @@ export declare const gameIdsBySeason: (ctx: Context, { season, gameTypes, apiSle
25
26
  export declare const allPlayers: (ctx: Context, { season, apiSleepRate }: {
26
27
  season: Id;
27
28
  apiSleepRate?: number;
28
- }) => Promise<JsonObject[]>;
29
+ }) => Promise<AllPlayersEntry[]>;
29
30
  /**
30
31
  * Gets summary statistics for every skater in a given season, merged with
31
32
  * the roster info from `allPlayers` (stat fields win on key collisions).
@@ -38,7 +39,7 @@ export declare const allPlayers: (ctx: Context, { season, apiSleepRate }: {
38
39
  export declare const allPlayersSummaryStatistics: (ctx: Context, { season, apiSleepRate }: {
39
40
  season: Id;
40
41
  apiSleepRate?: number;
41
- }) => Promise<JsonObject[]>;
42
+ }) => Promise<PlayerSummaryStatistics[]>;
42
43
  export declare const helpersApi: {
43
44
  readonly gameIdsBySeason: typeof gameIdsBySeason;
44
45
  readonly allPlayers: typeof allPlayers;
@@ -1,36 +1,36 @@
1
1
  import type { Context } from '#src/context.mjs';
2
- import type { JsonObject } from '#src/utils.mjs';
2
+ import type { Country, DraftYear, GlossaryEntry, SeasonRules, StatsConfig } from '#src/types/index.mjs';
3
3
  /**
4
4
  * Gets the full NHL glossary of statistical terms and abbreviations.
5
5
  *
6
6
  * @example https://api.nhle.com/stats/rest/en/glossary?sort=fullName
7
7
  */
8
- export declare const glossary: (ctx: Context) => Promise<JsonObject[]>;
8
+ export declare const glossary: (ctx: Context) => Promise<GlossaryEntry[]>;
9
9
  /**
10
10
  * Gets the stats API configuration, including available report types and
11
11
  * filters.
12
12
  *
13
13
  * @example https://api.nhle.com/stats/rest/en/config
14
14
  */
15
- export declare const config: (ctx: Context) => Promise<JsonObject>;
15
+ export declare const config: (ctx: Context) => Promise<StatsConfig>;
16
16
  /**
17
17
  * Gets the list of countries recognized by the NHL.
18
18
  *
19
19
  * @example https://api.nhle.com/stats/rest/en/country
20
20
  */
21
- export declare const countries: (ctx: Context) => Promise<JsonObject[]>;
21
+ export declare const countries: (ctx: Context) => Promise<Country[]>;
22
22
  /**
23
23
  * Gets rules and metadata for every NHL season on record.
24
24
  *
25
25
  * @example https://api.nhle.com/stats/rest/en/season
26
26
  */
27
- export declare const seasonSpecificRulesAndInfo: (ctx: Context) => Promise<JsonObject[]>;
27
+ export declare const seasonSpecificRulesAndInfo: (ctx: Context) => Promise<SeasonRules[]>;
28
28
  /**
29
29
  * Gets the number of rounds for each NHL draft year.
30
30
  *
31
31
  * @example https://api.nhle.com/stats/rest/en/draft
32
32
  */
33
- export declare const draftYearAndRounds: (ctx: Context) => Promise<JsonObject[]>;
33
+ export declare const draftYearAndRounds: (ctx: Context) => Promise<DraftYear[]>;
34
34
  export declare const miscApi: {
35
35
  readonly glossary: typeof glossary;
36
36
  readonly config: typeof config;
@@ -1,5 +1,6 @@
1
1
  import type { Context } from '#src/context.mjs';
2
- import type { Id, JsonObject } from '#src/utils.mjs';
2
+ import type { Prospects, Roster } from '#src/types/index.mjs';
3
+ import type { Id } from '#src/utils.mjs';
3
4
  /**
4
5
  * Gets prospects for a specific team, grouped by position.
5
6
  *
@@ -8,7 +9,7 @@ import type { Id, JsonObject } from '#src/utils.mjs';
8
9
  */
9
10
  export declare const prospectsByTeam: (ctx: Context, { teamAbbr }: {
10
11
  teamAbbr: string;
11
- }) => Promise<JsonObject>;
12
+ }) => Promise<Prospects>;
12
13
  /**
13
14
  * Gets the roster for a given team and season, grouped by position
14
15
  * (forwards, defensemen, goalies). Same data as `teams.teamRoster`.
@@ -20,7 +21,7 @@ export declare const prospectsByTeam: (ctx: Context, { teamAbbr }: {
20
21
  export declare const playersByTeam: (ctx: Context, { teamAbbr, season }: {
21
22
  teamAbbr: string;
22
23
  season: Id;
23
- }) => Promise<JsonObject>;
24
+ }) => Promise<Roster>;
24
25
  export declare const playersApi: {
25
26
  readonly prospectsByTeam: typeof prospectsByTeam;
26
27
  readonly playersByTeam: typeof playersByTeam;
@@ -15,6 +15,8 @@ export interface QueryContext {
15
15
  * filters are skipped and their errors collected; valid filters are joined
16
16
  * with " and ".
17
17
  */
18
+ /** Fact filter `buildQuery` applies unless told otherwise. */
19
+ export declare const DEFAULT_FACT_QUERY = "gamesPlayed>=1";
18
20
  export declare function buildQuery(filters: readonly Filter[], factQuery?: string): QueryContext;
19
21
  /** True if there are no validation errors. */
20
22
  export declare function isValidQuery(context: QueryContext): boolean;
@@ -4,7 +4,9 @@ import { toQuery, validateFilter } from '#src/api/query/filters.mjs';
4
4
  * filters are skipped and their errors collected; valid filters are joined
5
5
  * with " and ".
6
6
  */
7
- export function buildQuery(filters, factQuery = 'gamesPlayed>=1') {
7
+ /** Fact filter `buildQuery` applies unless told otherwise. */
8
+ export const DEFAULT_FACT_QUERY = 'gamesPlayed>=1';
9
+ export function buildQuery(filters, factQuery = DEFAULT_FACT_QUERY) {
8
10
  const outputFilters = [];
9
11
  const errors = [];
10
12
  for (const filter of filters) {
@@ -1,4 +1,4 @@
1
1
  export { buildQuery, isValidQuery, type QueryContext, } from '#src/api/query/builder.mjs';
2
2
  export * from '#src/api/query/filters.mjs';
3
- export { goalieStatsSorts } from '#src/api/query/sorting/goalie-sorts.mjs';
4
- export { defaultSortForReport, SKATER_REPORT_TYPES, type SortExpr, } from '#src/api/query/sorting/sorting-options.mjs';
3
+ export { type GoalieReportType, goalieStatsSorts, } from '#src/api/query/sorting/goalie-sorts.mjs';
4
+ export { defaultSortForReport, SKATER_REPORT_TYPES, type SkaterReportType, type SortExpr, } from '#src/api/query/sorting/sorting-options.mjs';
@@ -1,4 +1,4 @@
1
1
  export { buildQuery, isValidQuery, } from '#src/api/query/builder.mjs';
2
2
  export * from '#src/api/query/filters.mjs';
3
- export { goalieStatsSorts } from '#src/api/query/sorting/goalie-sorts.mjs';
3
+ export { goalieStatsSorts, } from '#src/api/query/sorting/goalie-sorts.mjs';
4
4
  export { defaultSortForReport, SKATER_REPORT_TYPES, } from '#src/api/query/sorting/sorting-options.mjs';
@@ -1,4 +1,59 @@
1
1
  import type { SortExpr } from '#src/api/query/sorting/sorting-options.mjs';
2
+ /** Default sort criteria per goalie report type. */
3
+ export declare const goalieSortingByReport: {
4
+ summary: SortExpr[];
5
+ advanced: ({
6
+ property: string;
7
+ direction: "DESC";
8
+ } | {
9
+ property: string;
10
+ direction: "ASC";
11
+ })[];
12
+ bios: ({
13
+ property: string;
14
+ direction: "ASC_CI";
15
+ } | {
16
+ property: string;
17
+ direction: "ASC";
18
+ })[];
19
+ daysrest: ({
20
+ property: string;
21
+ direction: "DESC";
22
+ } | {
23
+ property: string;
24
+ direction: "ASC";
25
+ })[];
26
+ penaltyShots: ({
27
+ property: string;
28
+ direction: "DESC";
29
+ } | {
30
+ property: string;
31
+ direction: "ASC";
32
+ })[];
33
+ savesByStrength: ({
34
+ property: string;
35
+ direction: "DESC";
36
+ } | {
37
+ property: string;
38
+ direction: "ASC";
39
+ })[];
40
+ shootout: ({
41
+ property: string;
42
+ direction: "DESC";
43
+ } | {
44
+ property: string;
45
+ direction: "ASC";
46
+ })[];
47
+ startedVsRelieved: ({
48
+ property: string;
49
+ direction: "DESC";
50
+ } | {
51
+ property: string;
52
+ direction: "ASC";
53
+ })[];
54
+ };
55
+ /** Goalie report types that have a default sort configured. */
56
+ export type GoalieReportType = keyof typeof goalieSortingByReport;
2
57
  /**
3
58
  * Default sorting criteria for goalie stats reports. Falls back to the
4
59
  * goalie summary sort for unknown report types.
@@ -3,57 +3,52 @@ const goalieSummaryDefaultSorting = [
3
3
  { property: 'gamesPlayed', direction: 'ASC' },
4
4
  { property: 'playerId', direction: 'ASC' },
5
5
  ];
6
+ /** Default sort criteria per goalie report type. */
7
+ export const goalieSortingByReport = {
8
+ summary: goalieSummaryDefaultSorting,
9
+ advanced: [
10
+ { property: 'qualityStart', direction: 'DESC' },
11
+ { property: 'goalsAgainstAverage', direction: 'ASC' },
12
+ { property: 'playerId', direction: 'ASC' },
13
+ ],
14
+ bios: [
15
+ { property: 'lastName', direction: 'ASC_CI' },
16
+ { property: 'goalieFullName', direction: 'ASC_CI' },
17
+ { property: 'playerId', direction: 'ASC' },
18
+ ],
19
+ daysrest: [
20
+ { property: 'wins', direction: 'DESC' },
21
+ { property: 'savePct', direction: 'DESC' },
22
+ { property: 'playerId', direction: 'ASC' },
23
+ ],
24
+ penaltyShots: [
25
+ { property: 'penaltyShotsSaves', direction: 'DESC' },
26
+ { property: 'penaltyShotSavePct', direction: 'DESC' },
27
+ { property: 'playerId', direction: 'ASC' },
28
+ ],
29
+ savesByStrength: [
30
+ { property: 'wins', direction: 'DESC' },
31
+ { property: 'savePct', direction: 'DESC' },
32
+ { property: 'playerId', direction: 'ASC' },
33
+ ],
34
+ shootout: [
35
+ { property: 'shootoutWins', direction: 'DESC' },
36
+ { property: 'shootoutSavePct', direction: 'DESC' },
37
+ { property: 'playerId', direction: 'ASC' },
38
+ ],
39
+ startedVsRelieved: [
40
+ { property: 'gamesStarted', direction: 'DESC' },
41
+ { property: 'gamesStartedSavePct', direction: 'DESC' },
42
+ { property: 'playerId', direction: 'ASC' },
43
+ ],
44
+ };
45
+ const sortingLookup = goalieSortingByReport;
6
46
  /**
7
47
  * Default sorting criteria for goalie stats reports. Falls back to the
8
48
  * goalie summary sort for unknown report types.
9
49
  */
10
50
  export function goalieStatsSorts(report) {
11
- switch (report) {
12
- case 'summary':
13
- return goalieSummaryDefaultSorting;
14
- case 'advanced':
15
- return [
16
- { property: 'qualityStart', direction: 'DESC' },
17
- { property: 'goalsAgainstAverage', direction: 'ASC' },
18
- { property: 'playerId', direction: 'ASC' },
19
- ];
20
- case 'bios':
21
- return [
22
- { property: 'lastName', direction: 'ASC_CI' },
23
- { property: 'goalieFullName', direction: 'ASC_CI' },
24
- { property: 'playerId', direction: 'ASC' },
25
- ];
26
- case 'daysrest':
27
- return [
28
- { property: 'wins', direction: 'DESC' },
29
- { property: 'savePct', direction: 'DESC' },
30
- { property: 'playerId', direction: 'ASC' },
31
- ];
32
- case 'penaltyShots':
33
- return [
34
- { property: 'penaltyShotsSaves', direction: 'DESC' },
35
- { property: 'penaltyShotSavePct', direction: 'DESC' },
36
- { property: 'playerId', direction: 'ASC' },
37
- ];
38
- case 'savesByStrength':
39
- return [
40
- { property: 'wins', direction: 'DESC' },
41
- { property: 'savePct', direction: 'DESC' },
42
- { property: 'playerId', direction: 'ASC' },
43
- ];
44
- case 'shootout':
45
- return [
46
- { property: 'shootoutWins', direction: 'DESC' },
47
- { property: 'shootoutSavePct', direction: 'DESC' },
48
- { property: 'playerId', direction: 'ASC' },
49
- ];
50
- case 'startedVsRelieved':
51
- return [
52
- { property: 'gamesStarted', direction: 'DESC' },
53
- { property: 'gamesStartedSavePct', direction: 'DESC' },
54
- { property: 'playerId', direction: 'ASC' },
55
- ];
56
- default:
57
- return goalieSummaryDefaultSorting;
58
- }
51
+ return ((Object.hasOwn(sortingLookup, report)
52
+ ? sortingLookup[report]
53
+ : undefined) ?? goalieSummaryDefaultSorting);
59
54
  }