nhl-api-ts 0.2.0 → 0.2.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/README.md +9 -4
- package/dist/api/edge.d.mts +23 -23
- package/dist/api/edge.mjs +69 -23
- package/dist/api/game-center.d.mts +14 -14
- package/dist/api/game-center.mjs +20 -8
- package/dist/api/helpers.d.mts +6 -6
- package/dist/api/helpers.mjs +6 -6
- package/dist/api/misc.d.mts +5 -5
- package/dist/api/misc.mjs +15 -5
- package/dist/api/players.d.mts +4 -4
- package/dist/api/players.mjs +6 -2
- package/dist/api/schedule.d.mts +18 -18
- package/dist/api/schedule.mjs +26 -14
- package/dist/api/standings.d.mts +3 -3
- package/dist/api/standings.mjs +4 -4
- package/dist/api/stats.d.mts +10 -10
- package/dist/api/stats.mjs +16 -12
- package/dist/api/teams.d.mts +5 -5
- package/dist/api/teams.mjs +10 -6
- package/dist/cli/colors.d.mts +2 -2
- package/dist/cli/colors.mjs +6 -2
- package/dist/cli/commands.mjs +36 -26
- package/dist/cli/run.mjs +7 -5
- package/dist/http-client.mjs +2 -2
- package/dist/nhl-client.d.mts +1 -1
- package/dist/nhl-client.mjs +8 -6
- package/dist/types/common.d.mts +0 -1
- package/dist/types/edge.d.mts +2 -2
- package/dist/types/game-center.d.mts +54 -111
- package/dist/types/players.d.mts +1 -2
- package/dist/types/schedule.d.mts +34 -62
- package/dist/types/standings.d.mts +1 -2
- package/dist/types/stats.d.mts +106 -110
- package/dist/utils.d.mts +1 -1
- package/dist/utils.mjs +3 -1
- package/package.json +7 -28
package/dist/api/teams.d.mts
CHANGED
|
@@ -32,9 +32,9 @@ export declare function withFranchiseIds(teams: readonly Team[], franchises: rea
|
|
|
32
32
|
* @param params.date Date in YYYY-MM-DD format. Defaults to "now".
|
|
33
33
|
* @example await client.teams.teams()
|
|
34
34
|
*/
|
|
35
|
-
export declare
|
|
35
|
+
export declare function teams(ctx: Context, { date }?: {
|
|
36
36
|
date?: string;
|
|
37
|
-
})
|
|
37
|
+
}): Promise<Team[]>;
|
|
38
38
|
/**
|
|
39
39
|
* Get the roster for the given team and season.
|
|
40
40
|
*
|
|
@@ -42,16 +42,16 @@ export declare const teams: (ctx: Context, { date }?: {
|
|
|
42
42
|
* @param params.season Season in YYYYYYYY format, e.g. 20232024
|
|
43
43
|
* @example https://api-web.nhle.com/v1/roster/BUF/20232024
|
|
44
44
|
*/
|
|
45
|
-
export declare
|
|
45
|
+
export declare function teamRoster(ctx: Context, { teamAbbr, season }: {
|
|
46
46
|
teamAbbr: string;
|
|
47
47
|
season: Id;
|
|
48
|
-
})
|
|
48
|
+
}): Promise<Roster>;
|
|
49
49
|
/**
|
|
50
50
|
* Get a list of all past and current NHL franchises.
|
|
51
51
|
*
|
|
52
52
|
* @example https://api.nhle.com/stats/rest/en/franchise
|
|
53
53
|
*/
|
|
54
|
-
export declare
|
|
54
|
+
export declare function franchises(ctx: Context): Promise<Franchise[]>;
|
|
55
55
|
export declare const teamsApi: {
|
|
56
56
|
readonly teams: typeof teams;
|
|
57
57
|
readonly teamRoster: typeof teamRoster;
|
package/dist/api/teams.mjs
CHANGED
|
@@ -5,7 +5,9 @@ async function fetchStandingsData(ctx, date) {
|
|
|
5
5
|
}
|
|
6
6
|
/** Converts a raw standings entry into a `Team`. */
|
|
7
7
|
export function toTeam(teamData) {
|
|
8
|
-
|
|
8
|
+
function nestedDefault(key) {
|
|
9
|
+
return teamData[key]?.default ?? '';
|
|
10
|
+
}
|
|
9
11
|
return {
|
|
10
12
|
conference: {
|
|
11
13
|
abbr: teamData.conferenceAbbrev ?? '',
|
|
@@ -66,11 +68,11 @@ export function withFranchiseIds(teams, franchises) {
|
|
|
66
68
|
* @param params.date Date in YYYY-MM-DD format. Defaults to "now".
|
|
67
69
|
* @example await client.teams.teams()
|
|
68
70
|
*/
|
|
69
|
-
export
|
|
71
|
+
export async function teams(ctx, { date = 'now' } = {}) {
|
|
70
72
|
const standingsData = await fetchStandingsData(ctx, date);
|
|
71
73
|
const franchiseData = await franchises(ctx);
|
|
72
74
|
return withFranchiseIds(standingsData.map(toTeam), franchiseData);
|
|
73
|
-
}
|
|
75
|
+
}
|
|
74
76
|
/**
|
|
75
77
|
* Get the roster for the given team and season.
|
|
76
78
|
*
|
|
@@ -78,14 +80,16 @@ export const teams = async (ctx, { date = 'now' } = {}) => {
|
|
|
78
80
|
* @param params.season Season in YYYYYYYY format, e.g. 20232024
|
|
79
81
|
* @example https://api-web.nhle.com/v1/roster/BUF/20232024
|
|
80
82
|
*/
|
|
81
|
-
export
|
|
83
|
+
export async function teamRoster(ctx, { teamAbbr, season }) {
|
|
84
|
+
return (await ctx.get(Endpoint.API_WEB_V1, `roster/${teamAbbr}/${season}`)).json();
|
|
85
|
+
}
|
|
82
86
|
/**
|
|
83
87
|
* Get a list of all past and current NHL franchises.
|
|
84
88
|
*
|
|
85
89
|
* @example https://api.nhle.com/stats/rest/en/franchise
|
|
86
90
|
*/
|
|
87
|
-
export
|
|
91
|
+
export async function franchises(ctx) {
|
|
88
92
|
const response = await (await ctx.get(Endpoint.API_STATS, 'en/franchise')).json();
|
|
89
93
|
return response.data ?? [];
|
|
90
|
-
}
|
|
94
|
+
}
|
|
91
95
|
export const teamsApi = { teams, teamRoster, franchises };
|
package/dist/cli/colors.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
2
|
export type Style = Parameters<typeof styleText>[0];
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
3
|
+
export declare function toStdout(format: Style): (text: string) => string;
|
|
4
|
+
export declare function toStderr(format: Style): (text: string) => string;
|
|
5
5
|
export declare const colors: {
|
|
6
6
|
dim: (text: string) => string;
|
|
7
7
|
pass: (text: string) => string;
|
package/dist/cli/colors.mjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { styleText } from 'node:util';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export function toStdout(format) {
|
|
3
|
+
return (text) => styleText(format, text, { stream: process.stdout });
|
|
4
|
+
}
|
|
5
|
+
export function toStderr(format) {
|
|
6
|
+
return (text) => styleText(format, text, { stream: process.stderr });
|
|
7
|
+
}
|
|
4
8
|
export const colors = {
|
|
5
9
|
dim: toStdout('dim'),
|
|
6
10
|
pass: toStdout(['bold', 'green']),
|
package/dist/cli/commands.mjs
CHANGED
|
@@ -5,7 +5,9 @@ import { SKATER_REPORT_TYPES } from '#src/api/query/sorting/sorting-options.mjs'
|
|
|
5
5
|
export class UsageError extends Error {
|
|
6
6
|
}
|
|
7
7
|
// ---- Reusable argument specs ------------------------------------------------
|
|
8
|
-
|
|
8
|
+
function req(spec) {
|
|
9
|
+
return { ...spec, required: true };
|
|
10
|
+
}
|
|
9
11
|
const teamAbbr = req({
|
|
10
12
|
name: 'teamAbbr',
|
|
11
13
|
type: 'string',
|
|
@@ -26,11 +28,13 @@ const playerId = req({
|
|
|
26
28
|
type: 'string',
|
|
27
29
|
description: 'NHL player id, e.g. 8478402',
|
|
28
30
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
function date(description = 'Date in YYYY-MM-DD format') {
|
|
32
|
+
return {
|
|
33
|
+
name: 'date',
|
|
34
|
+
type: 'string',
|
|
35
|
+
description,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
34
38
|
const gameTypeId = {
|
|
35
39
|
name: 'gameTypeId',
|
|
36
40
|
type: 'int',
|
|
@@ -48,29 +52,35 @@ const start = {
|
|
|
48
52
|
description: 'Pagination offset',
|
|
49
53
|
default: '0',
|
|
50
54
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
function limit(def) {
|
|
56
|
+
return {
|
|
57
|
+
name: 'limit',
|
|
58
|
+
type: 'int',
|
|
59
|
+
description: 'Max results',
|
|
60
|
+
default: def,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function factCayenneExp(def) {
|
|
64
|
+
return {
|
|
65
|
+
name: 'factCayenneExp',
|
|
66
|
+
type: 'string',
|
|
67
|
+
description: 'Base fact filter expression',
|
|
68
|
+
default: def,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
63
71
|
const defaultCayenneExp = {
|
|
64
72
|
name: 'defaultCayenneExp',
|
|
65
73
|
type: 'string',
|
|
66
74
|
description: 'Overrides the generated cayenneExp filter entirely',
|
|
67
75
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
function apiSleepRate(def) {
|
|
77
|
+
return {
|
|
78
|
+
name: 'apiSleepRate',
|
|
79
|
+
type: 'number',
|
|
80
|
+
description: 'Seconds to sleep between per-team requests',
|
|
81
|
+
default: def,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
74
84
|
// ---- Edge -------------------------------------------------------------------
|
|
75
85
|
const edgeSeasonArgs = [
|
|
76
86
|
{ ...season, description: `${season.description}. Defaults to current` },
|
|
@@ -81,7 +91,7 @@ const edgeSeasonArgs = [
|
|
|
81
91
|
default: '2',
|
|
82
92
|
},
|
|
83
93
|
];
|
|
84
|
-
|
|
94
|
+
function edgeCommand(name, method, idKind, description) {
|
|
85
95
|
const idArg = idKind === 'player'
|
|
86
96
|
? [playerId]
|
|
87
97
|
: idKind === 'team'
|
|
@@ -101,7 +111,7 @@ const edgeCommand = (name, method, idKind, description) => {
|
|
|
101
111
|
// biome-ignore lint/suspicious/noExplicitAny: dispatch by method name
|
|
102
112
|
client.edge[method].call(client.edge, values),
|
|
103
113
|
};
|
|
104
|
-
}
|
|
114
|
+
}
|
|
105
115
|
// ---- Stats query-context filters --------------------------------------------
|
|
106
116
|
const queryFilterArgs = [
|
|
107
117
|
{
|
package/dist/cli/run.mjs
CHANGED
|
@@ -5,7 +5,9 @@ import { MODULES, UsageError, } from '#src/cli/commands.mjs';
|
|
|
5
5
|
import { NHLApiException } from '#src/errors.mjs';
|
|
6
6
|
import { createNHLClient } from '#src/nhl-client.mjs';
|
|
7
7
|
const BIN = 'nhl-api-ts';
|
|
8
|
-
|
|
8
|
+
function kebab(name) {
|
|
9
|
+
return name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
10
|
+
}
|
|
9
11
|
const GLOBAL_OPTIONS = {
|
|
10
12
|
help: { type: 'boolean', short: 'h' },
|
|
11
13
|
version: { type: 'boolean', short: 'v' },
|
|
@@ -84,7 +86,7 @@ function commandHelp(mod, cmd) {
|
|
|
84
86
|
]
|
|
85
87
|
.filter(Boolean)
|
|
86
88
|
.join(' ');
|
|
87
|
-
|
|
89
|
+
function describe(arg) {
|
|
88
90
|
const extras = [
|
|
89
91
|
arg.choices ? `one of: ${arg.choices.join(', ')}` : '',
|
|
90
92
|
arg.default !== undefined ? `default: ${arg.default}` : '',
|
|
@@ -92,7 +94,7 @@ function commandHelp(mod, cmd) {
|
|
|
92
94
|
return extras.length
|
|
93
95
|
? `${arg.description} (${extras.join('; ')})`
|
|
94
96
|
: arg.description;
|
|
95
|
-
}
|
|
97
|
+
}
|
|
96
98
|
const sections = [`Usage: ${usage}`, cmd.description];
|
|
97
99
|
if (required.length) {
|
|
98
100
|
sections.push(`Arguments (positional, or as flags):\n${table(required.map((arg) => [
|
|
@@ -250,10 +252,10 @@ export async function runCli(argv, io) {
|
|
|
250
252
|
const [moduleName, commandName] = findTargets(argv);
|
|
251
253
|
const mod = MODULES.find((moduleSpec) => moduleSpec.name === moduleName);
|
|
252
254
|
const cmd = mod?.commands.find((command) => command.name === commandName);
|
|
253
|
-
|
|
255
|
+
function usageError(message, help) {
|
|
254
256
|
io.stderr(`${colors.error(`error: ${message}`)}\n\n${help}`);
|
|
255
257
|
return 2;
|
|
256
|
-
}
|
|
258
|
+
}
|
|
257
259
|
let parsed;
|
|
258
260
|
try {
|
|
259
261
|
parsed = parseCommand(argv, cmd);
|
package/dist/http-client.mjs
CHANGED
|
@@ -73,11 +73,11 @@ export async function readErrorMessage(response, url) {
|
|
|
73
73
|
* @throws NHLApiException For other unexpected errors
|
|
74
74
|
*/
|
|
75
75
|
export function createGet(config) {
|
|
76
|
-
|
|
76
|
+
function debug(message) {
|
|
77
77
|
if (config.debug) {
|
|
78
78
|
console.error(`nhl-api-ts.http_client - DEBUG - ${message}`);
|
|
79
79
|
}
|
|
80
|
-
}
|
|
80
|
+
}
|
|
81
81
|
return async (endpoint, resource, queryParams) => {
|
|
82
82
|
const fullUrl = buildUrl(endpoint, resource, queryParams);
|
|
83
83
|
debug(`GET: ${fullUrl}`);
|
package/dist/nhl-client.d.mts
CHANGED
|
@@ -23,7 +23,7 @@ type StatsClient = Omit<Bound<typeof statsApi>, 'skaterStatsWithQueryContext' |
|
|
|
23
23
|
* const client = createNHLClient({ debug: true }); // for a lil extra logging
|
|
24
24
|
* const teams = await client.teams.teams();
|
|
25
25
|
*/
|
|
26
|
-
export declare
|
|
26
|
+
export declare function createNHLClient(options?: ClientOptions): {
|
|
27
27
|
readonly config: Readonly<import("#src/config.mjs").Config>;
|
|
28
28
|
readonly teams: Bound<{
|
|
29
29
|
readonly teams: typeof import("#src/api/teams.mjs").teams;
|
package/dist/nhl-client.mjs
CHANGED
|
@@ -10,10 +10,12 @@ import { teamsApi } from '#src/api/teams.mjs';
|
|
|
10
10
|
import { resolveConfig } from '#src/config.mjs';
|
|
11
11
|
import { createGet } from '#src/http-client.mjs';
|
|
12
12
|
import { sleep } from '#src/utils.mjs';
|
|
13
|
-
|
|
14
|
-
key,
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
function bind(ctx, api) {
|
|
14
|
+
return Object.fromEntries(Object.entries(api).map(([key, fn]) => [
|
|
15
|
+
key,
|
|
16
|
+
(...args) => fn(ctx, ...args),
|
|
17
|
+
]));
|
|
18
|
+
}
|
|
17
19
|
/**
|
|
18
20
|
* Builds the main client used to access the NHL API.
|
|
19
21
|
*
|
|
@@ -22,7 +24,7 @@ const bind = (ctx, api) => Object.fromEntries(Object.entries(api).map(([key, fn]
|
|
|
22
24
|
* const client = createNHLClient({ debug: true }); // for a lil extra logging
|
|
23
25
|
* const teams = await client.teams.teams();
|
|
24
26
|
*/
|
|
25
|
-
export
|
|
27
|
+
export function createNHLClient(options = {}) {
|
|
26
28
|
const config = resolveConfig(options);
|
|
27
29
|
const ctx = { get: createGet(config), sleep };
|
|
28
30
|
return {
|
|
@@ -37,4 +39,4 @@ export const createNHLClient = (options = {}) => {
|
|
|
37
39
|
players: bind(ctx, playersApi),
|
|
38
40
|
edge: bind(ctx, edgeApi),
|
|
39
41
|
};
|
|
40
|
-
}
|
|
42
|
+
}
|
package/dist/types/common.d.mts
CHANGED
package/dist/types/edge.d.mts
CHANGED
|
@@ -174,10 +174,10 @@ export interface GoalieDetailStats {
|
|
|
174
174
|
}
|
|
175
175
|
export interface GoalieLanding {
|
|
176
176
|
seasonsWithEdgeStats: EdgeSeasonAvailability[];
|
|
177
|
-
/**
|
|
177
|
+
/** Regular season only */
|
|
178
178
|
minimumGamesPlayed?: number;
|
|
179
179
|
leaders: GoalieLandingLeaders;
|
|
180
|
-
/**
|
|
180
|
+
/** Playoffs only */
|
|
181
181
|
minimumMinutesPlayed?: number;
|
|
182
182
|
}
|
|
183
183
|
export interface GoalieLandingLeaders {
|