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.
@@ -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 const teams: (ctx: Context, { date }?: {
35
+ export declare function teams(ctx: Context, { date }?: {
36
36
  date?: string;
37
- }) => Promise<Team[]>;
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 const teamRoster: (ctx: Context, { teamAbbr, season }: {
45
+ export declare function teamRoster(ctx: Context, { teamAbbr, season }: {
46
46
  teamAbbr: string;
47
47
  season: Id;
48
- }) => Promise<Roster>;
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 const franchises: (ctx: Context) => Promise<Franchise[]>;
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;
@@ -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
- const nestedDefault = (key) => teamData[key]?.default ?? '';
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 const teams = async (ctx, { date = 'now' } = {}) => {
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 const teamRoster = async (ctx, { teamAbbr, season }) => (await ctx.get(Endpoint.API_WEB_V1, `roster/${teamAbbr}/${season}`)).json();
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 const franchises = async (ctx) => {
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 };
@@ -1,7 +1,7 @@
1
1
  import { styleText } from 'node:util';
2
2
  export type Style = Parameters<typeof styleText>[0];
3
- export declare const toStdout: (format: Style) => (text: string) => string;
4
- export declare const toStderr: (format: Style) => (text: string) => string;
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;
@@ -1,6 +1,10 @@
1
1
  import { styleText } from 'node:util';
2
- export const toStdout = (format) => (text) => styleText(format, text, { stream: process.stdout });
3
- export const toStderr = (format) => (text) => styleText(format, text, { stream: process.stderr });
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']),
@@ -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
- const req = (spec) => ({ ...spec, required: true });
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
- const date = (description = 'Date in YYYY-MM-DD format') => ({
30
- name: 'date',
31
- type: 'string',
32
- description,
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
- const limit = (def) => ({
52
- name: 'limit',
53
- type: 'int',
54
- description: 'Max results',
55
- default: def,
56
- });
57
- const factCayenneExp = (def) => ({
58
- name: 'factCayenneExp',
59
- type: 'string',
60
- description: 'Base fact filter expression',
61
- default: def,
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
- const apiSleepRate = (def) => ({
69
- name: 'apiSleepRate',
70
- type: 'number',
71
- description: 'Seconds to sleep between per-team requests',
72
- default: def,
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
- const edgeCommand = (name, method, idKind, description) => {
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
- const kebab = (name) => name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
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
- const describe = (arg) => {
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
- const usageError = (message, help) => {
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);
@@ -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
- const debug = (message) => {
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}`);
@@ -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 const createNHLClient: (options?: ClientOptions) => {
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;
@@ -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
- const bind = (ctx, api) => Object.fromEntries(Object.entries(api).map(([key, fn]) => [
14
- key,
15
- (...args) => fn(ctx, ...args),
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 const createNHLClient = (options = {}) => {
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
+ }
@@ -33,7 +33,6 @@ export interface StatsApiPage<Row> {
33
33
  }
34
34
  export interface GameOutcome {
35
35
  lastPeriodType: PeriodType;
36
- /** Low sample count */
37
36
  otPeriods?: number;
38
37
  }
39
38
  export interface PeriodDescriptor {
@@ -174,10 +174,10 @@ export interface GoalieDetailStats {
174
174
  }
175
175
  export interface GoalieLanding {
176
176
  seasonsWithEdgeStats: EdgeSeasonAvailability[];
177
- /** Absent when variant=playoffs. Low sample count */
177
+ /** Regular season only */
178
178
  minimumGamesPlayed?: number;
179
179
  leaders: GoalieLandingLeaders;
180
- /** Absent when variant=regular. Low sample count */
180
+ /** Playoffs only */
181
181
  minimumMinutesPlayed?: number;
182
182
  }
183
183
  export interface GoalieLandingLeaders {