nhle-api 0.5.4 → 0.6.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.
- package/CHANGELOG.md +40 -0
- package/README.md +319 -234
- package/lib/index.cjs +922 -418
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3071 -802
- package/lib/index.d.ts +3071 -802
- package/lib/index.js +899 -417
- package/lib/index.js.map +1 -1
- package/lib/nhl-B7Hg7iMB.d.cts +462 -0
- package/lib/nhl-B7Hg7iMB.d.ts +462 -0
- package/lib/toolkit.cjs +1216 -0
- package/lib/toolkit.cjs.map +1 -0
- package/lib/toolkit.d.cts +502 -0
- package/lib/toolkit.d.ts +502 -0
- package/lib/toolkit.js +1194 -0
- package/lib/toolkit.js.map +1 -0
- package/package.json +42 -11
package/lib/index.cjs
CHANGED
|
@@ -29,86 +29,52 @@ __export(goalies_exports, {
|
|
|
29
29
|
top10: () => top10
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
// src/config/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (Number.isNaN(parsed) || parsed <= 0) {
|
|
38
|
-
console.warn(
|
|
39
|
-
`Invalid NHLE_API_TIMEOUT: "${timeout}". Using default 5000ms`
|
|
40
|
-
);
|
|
41
|
-
return 5e3;
|
|
42
|
-
}
|
|
43
|
-
return parsed;
|
|
44
|
-
}
|
|
45
|
-
function parseLanguage() {
|
|
46
|
-
const language = process.env.NHLE_API_LANGUAGE?.toLowerCase();
|
|
47
|
-
if (language === "fr") return "fr";
|
|
48
|
-
if (language && language !== "en") {
|
|
49
|
-
console.warn(
|
|
50
|
-
`Invalid NHLE_API_LANGUAGE: "${language}". Using default 'en'`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
return "en";
|
|
54
|
-
}
|
|
55
|
-
function parseLogLevel() {
|
|
56
|
-
const logLevel = process.env.NHLE_API_LOGLEVEL?.toLowerCase();
|
|
57
|
-
const validLevels = [
|
|
58
|
-
"silent",
|
|
59
|
-
"error",
|
|
60
|
-
"warn",
|
|
61
|
-
"info",
|
|
62
|
-
"debug"
|
|
63
|
-
];
|
|
64
|
-
if (!logLevel) return "warn";
|
|
65
|
-
if (validLevels.includes(logLevel)) {
|
|
66
|
-
return logLevel;
|
|
67
|
-
}
|
|
68
|
-
console.warn(
|
|
69
|
-
`Invalid NHLE_API_LOGLEVEL: "${logLevel}". Valid options: ${validLevels.join(", ")}. Using default 'warn'`
|
|
70
|
-
);
|
|
71
|
-
return "warn";
|
|
72
|
-
}
|
|
73
|
-
var envConfig = {
|
|
74
|
-
/**
|
|
75
|
-
* Request timeout in milliseconds
|
|
76
|
-
* Set via NHLE_API_TIMEOUT environment variable
|
|
77
|
-
* @default 5000
|
|
78
|
-
*/
|
|
79
|
-
timeout: parseTimeout(),
|
|
80
|
-
/**
|
|
81
|
-
* Language code for API responses
|
|
82
|
-
* Set via NHLE_API_LANGUAGE environment variable
|
|
83
|
-
* @default 'en'
|
|
84
|
-
*/
|
|
85
|
-
language: parseLanguage(),
|
|
86
|
-
/**
|
|
87
|
-
* Logging level for the client
|
|
88
|
-
* Set via NHLE_API_LOGLEVEL environment variable
|
|
89
|
-
* @default 'warn'
|
|
90
|
-
*/
|
|
91
|
-
logLevel: parseLogLevel()
|
|
32
|
+
// src/config/index.ts
|
|
33
|
+
var config = {
|
|
34
|
+
timeout: 5e3,
|
|
35
|
+
language: "en",
|
|
36
|
+
logLevel: "warn"
|
|
92
37
|
};
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
timeout: process.env.NHLE_API_TIMEOUT,
|
|
96
|
-
language: process.env.NHLE_API_LANGUAGE,
|
|
97
|
-
logLevel: process.env.NHLE_API_LOGLEVEL
|
|
98
|
-
};
|
|
99
|
-
const configured = Object.entries(vars).filter(
|
|
100
|
-
([, v]) => v !== void 0
|
|
101
|
-
);
|
|
102
|
-
if (configured.length > 0) {
|
|
103
|
-
console.debug("NHL API Environment Configuration:", {
|
|
104
|
-
...Object.fromEntries(configured),
|
|
105
|
-
resolvedTimeout: envConfig.timeout,
|
|
106
|
-
resolvedLanguage: envConfig.language,
|
|
107
|
-
resolvedLogLevel: envConfig.logLevel
|
|
108
|
-
});
|
|
109
|
-
}
|
|
38
|
+
function logConfig() {
|
|
39
|
+
console.debug("NHL API Configuration:", config);
|
|
110
40
|
}
|
|
111
41
|
|
|
42
|
+
// src/logging/index.ts
|
|
43
|
+
var levelRank = {
|
|
44
|
+
silent: 0,
|
|
45
|
+
error: 1,
|
|
46
|
+
warn: 2,
|
|
47
|
+
info: 3,
|
|
48
|
+
debug: 4
|
|
49
|
+
};
|
|
50
|
+
function isEnabled(level, threshold) {
|
|
51
|
+
return levelRank[level] > 0 && levelRank[level] <= levelRank[threshold];
|
|
52
|
+
}
|
|
53
|
+
function writeLog(level, message, context, threshold = config.logLevel) {
|
|
54
|
+
if (!isEnabled(level, threshold)) return;
|
|
55
|
+
const args = context === void 0 ? [message] : [message, context];
|
|
56
|
+
switch (level) {
|
|
57
|
+
case "error":
|
|
58
|
+
console.error(...args);
|
|
59
|
+
break;
|
|
60
|
+
case "warn":
|
|
61
|
+
console.warn(...args);
|
|
62
|
+
break;
|
|
63
|
+
case "info":
|
|
64
|
+
console.info(...args);
|
|
65
|
+
break;
|
|
66
|
+
case "debug":
|
|
67
|
+
console.debug(...args);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var logger = {
|
|
72
|
+
error: (message, context) => writeLog("error", message, context),
|
|
73
|
+
warn: (message, context) => writeLog("warn", message, context),
|
|
74
|
+
info: (message, context) => writeLog("info", message, context),
|
|
75
|
+
debug: (message, context) => writeLog("debug", message, context)
|
|
76
|
+
};
|
|
77
|
+
|
|
112
78
|
// src/errors/index.ts
|
|
113
79
|
var ErrorCategory = {
|
|
114
80
|
/** Network-level errors (connection refused, timeout, etc.) */
|
|
@@ -127,6 +93,7 @@ var ErrorCategory = {
|
|
|
127
93
|
VALIDATION: "VALIDATION"
|
|
128
94
|
};
|
|
129
95
|
var LogLevel = {
|
|
96
|
+
NONE: 0,
|
|
130
97
|
ERROR: 1,
|
|
131
98
|
WARN: 2,
|
|
132
99
|
INFO: 3,
|
|
@@ -193,18 +160,30 @@ var APIError = class extends NHLError {
|
|
|
193
160
|
super(message, ErrorCategory.API_ERROR, context);
|
|
194
161
|
}
|
|
195
162
|
};
|
|
163
|
+
var ParseError = class extends NHLError {
|
|
164
|
+
constructor(message, context = {}) {
|
|
165
|
+
super(message, ErrorCategory.PARSE, context);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
196
168
|
var ValidationError = class extends NHLError {
|
|
197
169
|
constructor(message, context = {}) {
|
|
198
170
|
super(message, ErrorCategory.VALIDATION, context);
|
|
199
171
|
}
|
|
200
172
|
};
|
|
201
173
|
var ErrorHandler = class {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
174
|
+
overrides;
|
|
175
|
+
/**
|
|
176
|
+
* @param config - Overrides; an unset `logLevel` follows the shared
|
|
177
|
+
* `config.logLevel` at log time.
|
|
178
|
+
*/
|
|
179
|
+
constructor(config2 = {}) {
|
|
180
|
+
this.overrides = { ...config2 };
|
|
181
|
+
}
|
|
182
|
+
get config() {
|
|
183
|
+
return {
|
|
184
|
+
logLevel: this.overrides.logLevel ?? toErrorLogLevel(config.logLevel),
|
|
185
|
+
logger: this.overrides.logger ?? this.defaultLogger.bind(this),
|
|
186
|
+
includeStack: this.overrides.includeStack ?? true
|
|
208
187
|
};
|
|
209
188
|
}
|
|
210
189
|
/**
|
|
@@ -212,8 +191,12 @@ var ErrorHandler = class {
|
|
|
212
191
|
*/
|
|
213
192
|
defaultLogger(level, message, context) {
|
|
214
193
|
if (level > this.config.logLevel) return;
|
|
215
|
-
|
|
216
|
-
|
|
194
|
+
writeLog(
|
|
195
|
+
toClientLogLevel(level),
|
|
196
|
+
`[NHL API] ${message}`,
|
|
197
|
+
context,
|
|
198
|
+
toClientThreshold(this.config.logLevel)
|
|
199
|
+
);
|
|
217
200
|
}
|
|
218
201
|
/**
|
|
219
202
|
* Log an error based on configuration
|
|
@@ -311,10 +294,41 @@ var ErrorHandler = class {
|
|
|
311
294
|
/**
|
|
312
295
|
* Update configuration
|
|
313
296
|
*/
|
|
314
|
-
configure(
|
|
315
|
-
this.
|
|
297
|
+
configure(config2) {
|
|
298
|
+
this.overrides = { ...this.overrides, ...config2 };
|
|
316
299
|
}
|
|
317
300
|
};
|
|
301
|
+
function toErrorLogLevel(level) {
|
|
302
|
+
switch (level) {
|
|
303
|
+
case "silent":
|
|
304
|
+
return LogLevel.NONE;
|
|
305
|
+
case "error":
|
|
306
|
+
return LogLevel.ERROR;
|
|
307
|
+
case "warn":
|
|
308
|
+
return LogLevel.WARN;
|
|
309
|
+
case "info":
|
|
310
|
+
return LogLevel.INFO;
|
|
311
|
+
case "debug":
|
|
312
|
+
return LogLevel.DEBUG;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function toClientLogLevel(level) {
|
|
316
|
+
switch (level) {
|
|
317
|
+
case LogLevel.ERROR:
|
|
318
|
+
return "error";
|
|
319
|
+
case LogLevel.WARN:
|
|
320
|
+
return "warn";
|
|
321
|
+
case LogLevel.INFO:
|
|
322
|
+
return "info";
|
|
323
|
+
case LogLevel.DEBUG:
|
|
324
|
+
return "debug";
|
|
325
|
+
default:
|
|
326
|
+
return "debug";
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function toClientThreshold(level) {
|
|
330
|
+
return level === LogLevel.NONE ? "silent" : toClientLogLevel(level);
|
|
331
|
+
}
|
|
318
332
|
new ErrorHandler();
|
|
319
333
|
|
|
320
334
|
// src/client/index.ts
|
|
@@ -322,26 +336,42 @@ var BASE_URLS = {
|
|
|
322
336
|
gamecenter: "https://api-web.nhle.com/v1",
|
|
323
337
|
edgeStats: "https://api.nhle.com/stats/rest"
|
|
324
338
|
};
|
|
325
|
-
var
|
|
326
|
-
|
|
327
|
-
timeout: envConfig.timeout,
|
|
328
|
-
headers: {
|
|
329
|
-
Accept: "application/json"
|
|
330
|
-
},
|
|
331
|
-
language: envConfig.language
|
|
339
|
+
var DEFAULT_HEADERS = {
|
|
340
|
+
Accept: "application/json"
|
|
332
341
|
};
|
|
333
342
|
var NHLClient = class {
|
|
334
|
-
|
|
343
|
+
options;
|
|
335
344
|
errorHandler;
|
|
336
345
|
/**
|
|
337
346
|
* Creates a new NHL API client instance
|
|
338
|
-
*
|
|
347
|
+
*
|
|
348
|
+
* Options left unset (timeout, language) follow the shared `config`
|
|
349
|
+
* object at request time, so changing `config` after import still
|
|
350
|
+
* applies to this client.
|
|
351
|
+
*
|
|
352
|
+
* @param baseURLOrOptions - Base URL, or client options
|
|
339
353
|
* @param errorConfig - Optional error handling configuration
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* const client = new NHLClient('https://api-web.nhle.com/v1');
|
|
357
|
+
* const slow = new NHLClient({ timeout: 15000, language: 'fr' });
|
|
340
358
|
*/
|
|
341
|
-
constructor(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
this.
|
|
359
|
+
constructor(baseURLOrOptions, errorConfig) {
|
|
360
|
+
const options = typeof baseURLOrOptions === "string" ? { baseUrl: baseURLOrOptions } : baseURLOrOptions ?? {};
|
|
361
|
+
const { errorConfig: optionsErrorConfig, ...clientOptions } = options;
|
|
362
|
+
this.options = clientOptions;
|
|
363
|
+
this.errorHandler = new ErrorHandler(
|
|
364
|
+
errorConfig ?? optionsErrorConfig
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
/** Base URL, timeout, headers and language in effect for the next request. */
|
|
368
|
+
get config() {
|
|
369
|
+
return {
|
|
370
|
+
baseUrl: this.options.baseUrl ?? BASE_URLS.gamecenter,
|
|
371
|
+
timeout: this.options.timeout ?? config.timeout,
|
|
372
|
+
headers: { ...DEFAULT_HEADERS, ...this.options.headers },
|
|
373
|
+
language: this.options.language ?? config.language
|
|
374
|
+
};
|
|
345
375
|
}
|
|
346
376
|
/**
|
|
347
377
|
* Helper to build URL with query parameters
|
|
@@ -366,18 +396,16 @@ var NHLClient = class {
|
|
|
366
396
|
* @returns Promise resolving to an APIResponse containing either data or error
|
|
367
397
|
*/
|
|
368
398
|
async get(endpoint, params) {
|
|
399
|
+
const { timeout, headers, language } = this.config;
|
|
369
400
|
const url = this.buildUrl(endpoint, params);
|
|
370
401
|
const controller = new AbortController();
|
|
371
|
-
const timeoutId = setTimeout(
|
|
372
|
-
() => controller.abort(),
|
|
373
|
-
this.config.timeout
|
|
374
|
-
);
|
|
402
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
375
403
|
try {
|
|
376
404
|
const response = await fetch(url, {
|
|
377
405
|
method: "GET",
|
|
378
406
|
headers: {
|
|
379
|
-
...
|
|
380
|
-
"Accept-Language":
|
|
407
|
+
...headers,
|
|
408
|
+
"Accept-Language": language
|
|
381
409
|
},
|
|
382
410
|
signal: controller.signal
|
|
383
411
|
});
|
|
@@ -419,15 +447,15 @@ var NHLClient = class {
|
|
|
419
447
|
* Configure error handling behavior
|
|
420
448
|
* @param config - Error configuration options
|
|
421
449
|
*/
|
|
422
|
-
configureErrorHandling(
|
|
423
|
-
this.errorHandler.configure(
|
|
450
|
+
configureErrorHandling(config2) {
|
|
451
|
+
this.errorHandler.configure(config2);
|
|
424
452
|
}
|
|
425
453
|
};
|
|
426
|
-
function createNHLClient(
|
|
427
|
-
return new NHLClient(
|
|
454
|
+
function createNHLClient(baseURLOrOptions, errorConfig) {
|
|
455
|
+
return new NHLClient(baseURLOrOptions, errorConfig);
|
|
428
456
|
}
|
|
429
457
|
var nhlClient = createNHLClient(BASE_URLS.gamecenter);
|
|
430
|
-
createNHLClient(BASE_URLS.edgeStats);
|
|
458
|
+
var edgeStatsClient = createNHLClient(BASE_URLS.edgeStats);
|
|
431
459
|
|
|
432
460
|
// src/constants/edge-adv.ts
|
|
433
461
|
var edge_adv_exports = {};
|
|
@@ -549,9 +577,6 @@ var ZoneTimeSortEnum = {
|
|
|
549
577
|
NZ: "neutral"
|
|
550
578
|
};
|
|
551
579
|
|
|
552
|
-
// src/constants/edge-stats.ts
|
|
553
|
-
var edge_stats_exports = {};
|
|
554
|
-
|
|
555
580
|
// src/constants/nhl.ts
|
|
556
581
|
var nhl_exports = {};
|
|
557
582
|
__export(nhl_exports, {
|
|
@@ -576,6 +601,50 @@ __export(nhl_exports, {
|
|
|
576
601
|
TeamsReverseEnum: () => TeamsReverseEnum,
|
|
577
602
|
YEAR_RANGE: () => YEAR_RANGE
|
|
578
603
|
});
|
|
604
|
+
|
|
605
|
+
// src/utils/date.ts
|
|
606
|
+
var NHL_TIMEZONE = "America/New_York";
|
|
607
|
+
var getNHLDate = (date) => new Intl.DateTimeFormat("en-CA", {
|
|
608
|
+
timeZone: NHL_TIMEZONE,
|
|
609
|
+
year: "numeric",
|
|
610
|
+
month: "2-digit",
|
|
611
|
+
day: "2-digit"
|
|
612
|
+
}).format(date);
|
|
613
|
+
var getCurrentNHLDate = () => getNHLDate(/* @__PURE__ */ new Date());
|
|
614
|
+
var getNHLMonth = (date) => {
|
|
615
|
+
return new Intl.DateTimeFormat("en-CA", {
|
|
616
|
+
timeZone: NHL_TIMEZONE,
|
|
617
|
+
year: "numeric",
|
|
618
|
+
month: "2-digit"
|
|
619
|
+
}).format(date);
|
|
620
|
+
};
|
|
621
|
+
var getYear = (date) => new Intl.DateTimeFormat("en-CA", {
|
|
622
|
+
timeZone: NHL_TIMEZONE,
|
|
623
|
+
year: "numeric"
|
|
624
|
+
}).format(date);
|
|
625
|
+
var getCurrentNHLYear = () => getYear(/* @__PURE__ */ new Date());
|
|
626
|
+
var getSeason = (date) => {
|
|
627
|
+
const format = new Intl.DateTimeFormat("en-CA", {
|
|
628
|
+
timeZone: NHL_TIMEZONE,
|
|
629
|
+
year: "numeric",
|
|
630
|
+
month: "numeric"
|
|
631
|
+
}).formatToParts(date instanceof Date ? date : new Date(date));
|
|
632
|
+
const month = format.find((part) => part.type === "month")?.value;
|
|
633
|
+
const year = format.find((part) => part.type === "year")?.value;
|
|
634
|
+
if (!year) {
|
|
635
|
+
throw new Error("Invalid date provided, could not extract year");
|
|
636
|
+
}
|
|
637
|
+
if (month && parseInt(month, 10) < 7) {
|
|
638
|
+
return `${parseInt(year, 10) - 1}${year}`;
|
|
639
|
+
}
|
|
640
|
+
return `${year}${parseInt(year, 10) + 1}`;
|
|
641
|
+
};
|
|
642
|
+
var getCurrentSeason = () => getSeason(/* @__PURE__ */ new Date());
|
|
643
|
+
/* @__PURE__ */ new Date(
|
|
644
|
+
`${getCurrentSeason().slice(4, 8)}-06-30`
|
|
645
|
+
);
|
|
646
|
+
|
|
647
|
+
// src/constants/nhl.ts
|
|
579
648
|
var TeamsEnum = {
|
|
580
649
|
/** Anaheim Ducks */
|
|
581
650
|
ANA: 24,
|
|
@@ -910,54 +979,26 @@ var YEAR_RANGE = {
|
|
|
910
979
|
var START_YEAR = YEAR_RANGE.START;
|
|
911
980
|
var END_YEAR = YEAR_RANGE.END;
|
|
912
981
|
var CURRENT = {
|
|
913
|
-
|
|
982
|
+
/** The season for today's date, so the default never goes stale. */
|
|
983
|
+
SEASON: Number(getCurrentSeason()),
|
|
914
984
|
YEAR: YEAR_RANGE.END
|
|
915
985
|
};
|
|
916
986
|
var PLAYER_ID_RANGE = { MIN: 8444e3, MAX: 8489999 };
|
|
917
987
|
var TEAM_ID_RANGE = { MIN: 1, MAX: 59 };
|
|
918
988
|
|
|
919
989
|
// src/constants/index.ts
|
|
920
|
-
var EDGE = { ...edge_adv_exports
|
|
921
|
-
|
|
922
|
-
// src/utils/date.ts
|
|
923
|
-
var NHL_TIMEZONE = "America/New_York";
|
|
924
|
-
var getDate = (date) => new Intl.DateTimeFormat("en-CA", {
|
|
925
|
-
timeZone: NHL_TIMEZONE,
|
|
926
|
-
year: "numeric",
|
|
927
|
-
month: "2-digit",
|
|
928
|
-
day: "2-digit"
|
|
929
|
-
}).format(date);
|
|
930
|
-
var getCurrentDate = () => getDate(/* @__PURE__ */ new Date());
|
|
931
|
-
var getYear = (date) => new Intl.DateTimeFormat("en-CA", {
|
|
932
|
-
timeZone: NHL_TIMEZONE,
|
|
933
|
-
year: "numeric"
|
|
934
|
-
}).format(date);
|
|
935
|
-
var getCurrentYear = () => getYear(/* @__PURE__ */ new Date());
|
|
936
|
-
var getSeason = (date) => {
|
|
937
|
-
const format = new Intl.DateTimeFormat("en-CA", {
|
|
938
|
-
timeZone: NHL_TIMEZONE,
|
|
939
|
-
year: "numeric",
|
|
940
|
-
month: "numeric"
|
|
941
|
-
}).formatToParts(date instanceof Date ? date : new Date(date));
|
|
942
|
-
const month = format.find((part) => part.type === "month")?.value;
|
|
943
|
-
const year = format.find((part) => part.type === "year")?.value;
|
|
944
|
-
if (!year) {
|
|
945
|
-
throw new Error("Invalid date provided, could not extract year");
|
|
946
|
-
}
|
|
947
|
-
if (month && parseInt(month, 10) < 7) {
|
|
948
|
-
return `${parseInt(year, 10) - 1}${year}`;
|
|
949
|
-
}
|
|
950
|
-
return `${year}${parseInt(year, 10) + 1}`;
|
|
951
|
-
};
|
|
952
|
-
var getCurrentSeason = () => getSeason(/* @__PURE__ */ new Date());
|
|
953
|
-
/* @__PURE__ */ new Date(
|
|
954
|
-
`${getCurrentSeason().slice(4, 8)}-06-30`
|
|
955
|
-
);
|
|
990
|
+
var EDGE = { ...edge_adv_exports };
|
|
956
991
|
|
|
957
992
|
// src/utils/schemas.ts
|
|
958
993
|
function isParseError(value) {
|
|
959
994
|
return value instanceof arktype.type.errors;
|
|
960
995
|
}
|
|
996
|
+
function invalidParams(errors, endpoint) {
|
|
997
|
+
return {
|
|
998
|
+
success: false,
|
|
999
|
+
error: new ValidationError(errors.summary, { endpoint })
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
961
1002
|
var Year = arktype.type(`${nhl_exports.START_YEAR} <= number <= ${nhl_exports.END_YEAR}`).or(
|
|
962
1003
|
arktype.type("string.numeric.parse").narrow((v) => {
|
|
963
1004
|
return v >= nhl_exports.START_YEAR && v <= nhl_exports.END_YEAR;
|
|
@@ -970,11 +1011,11 @@ var NHLMonth = arktype.type("Date | string").narrow((v) => {
|
|
|
970
1011
|
return true;
|
|
971
1012
|
}
|
|
972
1013
|
return false;
|
|
973
|
-
}).pipe((v) => typeof v === "string" ? v : v
|
|
1014
|
+
}).pipe((v) => typeof v === "string" ? v : getNHLMonth(v)).describe(
|
|
974
1015
|
"a valid month, either as a string (formatted as YYYY-MM) or a Date object"
|
|
975
1016
|
);
|
|
976
1017
|
var NHLDate = arktype.type("Date | string.date.iso").pipe(
|
|
977
|
-
(v) => typeof v === "string" ? new Date(v).toISOString().slice(0, 10) : v
|
|
1018
|
+
(v) => typeof v === "string" ? new Date(v).toISOString().slice(0, 10) : getNHLDate(v)
|
|
978
1019
|
).describe(
|
|
979
1020
|
"a valid date, either as a string (ISO date string) or a Date object"
|
|
980
1021
|
);
|
|
@@ -1024,8 +1065,10 @@ var GameId = arktype.type("number.integer | string.numeric.parse").narrow((v) =>
|
|
|
1024
1065
|
var SeriesLetter = arktype.type.enumerated(...Object.values(nhl_exports.SeriesLetterEnum)).describe("a valid NHL playoff series letter (A-O)");
|
|
1025
1066
|
arktype.type.enumerated(...Object.values(nhl_exports.GameStateEnum)).describe("a valid NHL game state");
|
|
1026
1067
|
var CountryCode = arktype.type(/^[a-zA-Z]{2}$/).pipe((v) => v.toLowerCase()).describe("a valid ISO 3166-1 alpha-2 country code, e.g. US, CA, RU");
|
|
1027
|
-
var PostalCode = arktype.type(/^[a-zA-Z]\d[a-zA-Z][ -]?\d[a-zA-Z]\d$/).or(arktype.type(/^\d{5}$/)).
|
|
1028
|
-
|
|
1068
|
+
var PostalCode = arktype.type(/^[a-zA-Z]\d[a-zA-Z][ -]?\d[a-zA-Z]\d$/).or(arktype.type(/^\d{5}$/)).pipe(
|
|
1069
|
+
(v) => v.length === 5 ? v : `${v.slice(0, 3)} ${v.slice(-3)}`.toUpperCase()
|
|
1070
|
+
).describe(
|
|
1071
|
+
"a valid postal code, either US ZIP code (5 digit) or Canadian postal code (A1A 1A1, A1A1A1 or A1A-1A1)"
|
|
1029
1072
|
);
|
|
1030
1073
|
var PlayerId = arktype.type("number").atLeast(nhl_exports.PLAYER_ID_RANGE.MIN).atMost(nhl_exports.PLAYER_ID_RANGE.MAX).or(
|
|
1031
1074
|
arktype.type("string.numeric.parse").narrow((v) => {
|
|
@@ -1081,7 +1124,7 @@ var SkatingDistanceSort = arktype.type.enumerated(
|
|
|
1081
1124
|
...Object.keys(
|
|
1082
1125
|
EDGE.SkatingDistanceSortEnum
|
|
1083
1126
|
)
|
|
1084
|
-
);
|
|
1127
|
+
).pipe((v) => EDGE.SkatingDistanceSortEnum[v]);
|
|
1085
1128
|
var ShotLocationCategory = arktype.type.enumerated(
|
|
1086
1129
|
...Object.keys(
|
|
1087
1130
|
EDGE.ShotLocationCategoryEnum
|
|
@@ -1092,6 +1135,11 @@ var ZoneTimeSort = arktype.type.enumerated(
|
|
|
1092
1135
|
EDGE.ZoneTimeSortEnum
|
|
1093
1136
|
)
|
|
1094
1137
|
).pipe((v) => EDGE.ZoneTimeSortEnum[v]);
|
|
1138
|
+
function withDefault(schema, fallback) {
|
|
1139
|
+
const resolved = schema.assert(fallback);
|
|
1140
|
+
const optional = schema.or("undefined").pipe((v) => v ?? resolved);
|
|
1141
|
+
return [optional, "=", fallback];
|
|
1142
|
+
}
|
|
1095
1143
|
var BaseParams = arktype.type({
|
|
1096
1144
|
season: Season.or("undefined").pipe((v) => v ?? nhl_exports.CURRENT.SEASON),
|
|
1097
1145
|
gameType: GameType.or("undefined").pipe(
|
|
@@ -1106,8 +1154,8 @@ var TeamParams = BaseParams.merge({
|
|
|
1106
1154
|
teamId: TeamId
|
|
1107
1155
|
});
|
|
1108
1156
|
var top10Params = BaseParams.merge({
|
|
1109
|
-
position: PositionFilter
|
|
1110
|
-
strength: SkatersStrength
|
|
1157
|
+
position: withDefault(PositionFilter, "ALL"),
|
|
1158
|
+
strength: withDefault(SkatersStrength, "ALL")
|
|
1111
1159
|
});
|
|
1112
1160
|
var DraftParams = arktype.type({
|
|
1113
1161
|
year: Year.or("undefined").pipe((v) => v ?? nhl_exports.CURRENT.YEAR),
|
|
@@ -1131,9 +1179,9 @@ var SeriesParams = arktype.type({
|
|
|
1131
1179
|
});
|
|
1132
1180
|
var ScheduleParams = arktype.type({
|
|
1133
1181
|
team: TeamAbbrev,
|
|
1134
|
-
date: NHLDate.or("undefined").pipe((v) => v ??
|
|
1182
|
+
date: NHLDate.or("undefined").pipe((v) => v ?? getCurrentNHLDate()),
|
|
1135
1183
|
month: NHLMonth.or("undefined").pipe(
|
|
1136
|
-
(v) => v ??
|
|
1184
|
+
(v) => v ?? getCurrentNHLDate().slice(0, 7)
|
|
1137
1185
|
)
|
|
1138
1186
|
});
|
|
1139
1187
|
|
|
@@ -1164,71 +1212,71 @@ var goaliesPaths = {
|
|
|
1164
1212
|
/** Goalie top 10 leaders. */
|
|
1165
1213
|
top10: {
|
|
1166
1214
|
/** Top 10 goalies by save percentage. */
|
|
1167
|
-
|
|
1215
|
+
savePercentage: "edge/goalie-edge-save-pctg-top-10/{sortBy}/{season}/{gameType}",
|
|
1168
1216
|
/** Top 10 goalies by 5v5 save percentage. */
|
|
1169
|
-
|
|
1217
|
+
savePercentage5v5: "edge/goalie-5v5-top-10/{sortBy}/{season}/{gameType}",
|
|
1170
1218
|
/** Top 10 goalies by shot location. */
|
|
1171
|
-
|
|
1219
|
+
saveLocation: "edge/goalie-shot-location-top-10/{category}/{sortBy}/{season}/{gameType}"
|
|
1172
1220
|
}
|
|
1173
1221
|
};
|
|
1174
1222
|
var skatersPaths = {
|
|
1175
1223
|
/** Skater detail page. */
|
|
1176
|
-
player: "skater-detail/{playerId}/{season}/{gameType}",
|
|
1224
|
+
player: "edge/skater-detail/{playerId}/{season}/{gameType}",
|
|
1177
1225
|
/** Skater comparison data. */
|
|
1178
|
-
compare: "skater-comparison/{playerId}/{season}/{gameType}",
|
|
1226
|
+
compare: "edge/skater-comparison/{playerId}/{season}/{gameType}",
|
|
1179
1227
|
/** Skater leaders landing page. */
|
|
1180
|
-
leaders: "skater-landing/{season}/{gameType}",
|
|
1228
|
+
leaders: "edge/skater-landing/{season}/{gameType}",
|
|
1181
1229
|
/** Skater shot location analysis. */
|
|
1182
|
-
shotLocation: "skater-shot-location-detail/{playerId}/{season}/{gameType}",
|
|
1230
|
+
shotLocation: "edge/skater-shot-location-detail/{playerId}/{season}/{gameType}",
|
|
1183
1231
|
/** Skater shot speed analysis. */
|
|
1184
|
-
shotSpeed: "skater-shot-speed-detail/{playerId}/{season}/{gameType}",
|
|
1232
|
+
shotSpeed: "edge/skater-shot-speed-detail/{playerId}/{season}/{gameType}",
|
|
1185
1233
|
/** Skater skating distance analysis. */
|
|
1186
|
-
skatingDistance: "skater-skating-distance-detail/{playerId}/{season}/{gameType}",
|
|
1234
|
+
skatingDistance: "edge/skater-skating-distance-detail/{playerId}/{season}/{gameType}",
|
|
1187
1235
|
/** Skater skating speed analysis. */
|
|
1188
|
-
skatingSpeed: "skater-skating-speed-detail/{playerId}/{season}/{gameType}",
|
|
1236
|
+
skatingSpeed: "edge/skater-skating-speed-detail/{playerId}/{season}/{gameType}",
|
|
1189
1237
|
/** Skater zone time analysis. */
|
|
1190
|
-
zoneTime: "skater-zone-time/{playerId}/{season}/{gameType}",
|
|
1238
|
+
zoneTime: "edge/skater-zone-time/{playerId}/{season}/{gameType}",
|
|
1191
1239
|
/** Skater top 10 leaders. */
|
|
1192
1240
|
top10: {
|
|
1193
1241
|
/** Top 10 skaters by shot location. */
|
|
1194
|
-
shotLocation: "skater-shot-location-top-10/{position}/{category}/{sortBy}/{season}/{gameType}",
|
|
1242
|
+
shotLocation: "edge/skater-shot-location-top-10/{position}/{category}/{sortBy}/{season}/{gameType}",
|
|
1195
1243
|
/** Top 10 skaters by shot speed. */
|
|
1196
|
-
shotSpeed: "skater-shot-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1244
|
+
shotSpeed: "edge/skater-shot-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1197
1245
|
/** Top 10 skaters by skating distance. */
|
|
1198
|
-
skatingDistance: "skater-distance-top-10/{position}/{strength}/{sortBy}/{season}/{gameType}",
|
|
1246
|
+
skatingDistance: "edge/skater-distance-top-10/{position}/{strength}/{sortBy}/{season}/{gameType}",
|
|
1199
1247
|
/** Top 10 skaters by skating speed. */
|
|
1200
|
-
skatingSpeed: "skater-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1248
|
+
skatingSpeed: "edge/skater-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1201
1249
|
/** Top 10 skaters by zone time. */
|
|
1202
|
-
zoneTime: "skater-zone-time-top-10/{position}/{strength}/{sortBy}/{season}/{gameType}"
|
|
1250
|
+
zoneTime: "edge/skater-zone-time-top-10/{position}/{strength}/{sortBy}/{season}/{gameType}"
|
|
1203
1251
|
}
|
|
1204
1252
|
};
|
|
1205
1253
|
var teamsPaths = {
|
|
1206
1254
|
/** Team statistics detail page. */
|
|
1207
|
-
stats: "edge/team-
|
|
1255
|
+
stats: "edge/team-detail/{teamId}/{season}/{gameType}",
|
|
1208
1256
|
/** Team comparison data. */
|
|
1209
|
-
compare: "edge/team-
|
|
1257
|
+
compare: "edge/team-comparison/{teamId}/{season}/{gameType}",
|
|
1210
1258
|
/** Team leaders landing page. */
|
|
1211
1259
|
leaders: "edge/team-landing/{season}/{gameType}",
|
|
1212
1260
|
/** Team shot location analysis. */
|
|
1213
1261
|
shotLocation: "edge/team-shot-location-detail/{teamId}/{season}/{gameType}",
|
|
1214
1262
|
/** Team shot speed analysis. */
|
|
1215
|
-
shotSpeed: "edge/team-shot-
|
|
1263
|
+
shotSpeed: "edge/team-shot-speed-detail/{teamId}/{season}/{gameType}",
|
|
1216
1264
|
/** Team skating distance analysis. */
|
|
1217
|
-
skatingDistance: "edge/team-
|
|
1265
|
+
skatingDistance: "edge/team-skating-distance-detail/{teamId}/{season}/{gameType}",
|
|
1218
1266
|
/** Team skating speed analysis. */
|
|
1219
|
-
skatingSpeed: "edge/team-
|
|
1267
|
+
skatingSpeed: "edge/team-skating-speed-detail/{teamId}/{season}/{gameType}",
|
|
1220
1268
|
/** Team zone time analysis. */
|
|
1221
|
-
zoneTime: "edge/team-
|
|
1269
|
+
zoneTime: "edge/team-zone-time-details/{teamId}/{season}/{gameType}",
|
|
1222
1270
|
/** Team top 10 leaders. */
|
|
1223
1271
|
top10: {
|
|
1224
1272
|
/** Top 10 teams by shot location. */
|
|
1225
|
-
shotLocation: "edge/team-
|
|
1273
|
+
shotLocation: "edge/team-shot-location-top-10/{position}/{category}/{sortBy}/{season}/{gameType}",
|
|
1226
1274
|
/** Top 10 teams by shot speed. */
|
|
1227
|
-
shotSpeed: "edge/team-
|
|
1275
|
+
shotSpeed: "edge/team-shot-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1228
1276
|
/** Top 10 teams by skating distance. */
|
|
1229
|
-
skatingDistance: "edge/team-skating-
|
|
1277
|
+
skatingDistance: "edge/team-skating-distance-top-10/{position}/{strength}/{sortBy}/{season}/{gameType}",
|
|
1230
1278
|
/** Top 10 teams by skating speed. */
|
|
1231
|
-
skatingSpeed: "edge/team-
|
|
1279
|
+
skatingSpeed: "edge/team-skating-speed-top-10/{position}/{sortBy}/{season}/{gameType}",
|
|
1232
1280
|
/** Top 10 teams by zone time. */
|
|
1233
1281
|
zoneTime: "edge/team-zone-time-top-10/{strength}/{sortBy}/{season}/{gameType}"
|
|
1234
1282
|
}
|
|
@@ -1241,67 +1289,38 @@ var summaryPaths = {
|
|
|
1241
1289
|
// src/api/edge-adv/goalies.ts
|
|
1242
1290
|
async function player(playerId, season, gameType) {
|
|
1243
1291
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1244
|
-
if (isParseError(parsed))
|
|
1245
|
-
return Promise.reject(
|
|
1246
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1247
|
-
endpoint: goaliesPaths.player
|
|
1248
|
-
})
|
|
1249
|
-
);
|
|
1292
|
+
if (isParseError(parsed)) return invalidParams(parsed, goaliesPaths.player);
|
|
1250
1293
|
const path = resolvePath(goaliesPaths.player, parsed);
|
|
1251
1294
|
return nhlClient.get(path);
|
|
1252
1295
|
}
|
|
1253
1296
|
async function compare(playerId, season, gameType) {
|
|
1254
1297
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1255
|
-
if (isParseError(parsed))
|
|
1256
|
-
return Promise.reject(
|
|
1257
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1258
|
-
endpoint: goaliesPaths.compare
|
|
1259
|
-
})
|
|
1260
|
-
);
|
|
1298
|
+
if (isParseError(parsed)) return invalidParams(parsed, goaliesPaths.compare);
|
|
1261
1299
|
const path = resolvePath(goaliesPaths.compare, parsed);
|
|
1262
1300
|
return nhlClient.get(path);
|
|
1263
1301
|
}
|
|
1264
1302
|
async function leaders(season, gameType) {
|
|
1265
1303
|
const parsed = BaseParams({ season, gameType });
|
|
1266
|
-
if (isParseError(parsed))
|
|
1267
|
-
return Promise.reject(
|
|
1268
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1269
|
-
endpoint: goaliesPaths.leaders
|
|
1270
|
-
})
|
|
1271
|
-
);
|
|
1304
|
+
if (isParseError(parsed)) return invalidParams(parsed, goaliesPaths.leaders);
|
|
1272
1305
|
const path = resolvePath(goaliesPaths.leaders, parsed);
|
|
1273
1306
|
return nhlClient.get(path);
|
|
1274
1307
|
}
|
|
1275
1308
|
async function savePercentage5v5(playerId, season, gameType) {
|
|
1276
1309
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1277
1310
|
if (isParseError(parsed))
|
|
1278
|
-
return
|
|
1279
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1280
|
-
endpoint: goaliesPaths.savePercentage5v5
|
|
1281
|
-
})
|
|
1282
|
-
);
|
|
1311
|
+
return invalidParams(parsed, goaliesPaths.savePercentage5v5);
|
|
1283
1312
|
const path = resolvePath(goaliesPaths.savePercentage5v5, parsed);
|
|
1284
1313
|
return nhlClient.get(path);
|
|
1285
1314
|
}
|
|
1286
1315
|
async function savePercentage(playerId, season, gameType) {
|
|
1287
1316
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1288
|
-
if (isParseError(parsed))
|
|
1289
|
-
return Promise.reject(
|
|
1290
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1291
|
-
endpoint: goaliesPaths.savePercentage
|
|
1292
|
-
})
|
|
1293
|
-
);
|
|
1317
|
+
if (isParseError(parsed)) return invalidParams(parsed, goaliesPaths.savePercentage);
|
|
1294
1318
|
const path = resolvePath(goaliesPaths.savePercentage, parsed);
|
|
1295
1319
|
return nhlClient.get(path);
|
|
1296
1320
|
}
|
|
1297
1321
|
async function saveLocation(playerId, season, gameType) {
|
|
1298
1322
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1299
|
-
if (isParseError(parsed))
|
|
1300
|
-
return Promise.reject(
|
|
1301
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1302
|
-
endpoint: goaliesPaths.saveLocation
|
|
1303
|
-
})
|
|
1304
|
-
);
|
|
1323
|
+
if (isParseError(parsed)) return invalidParams(parsed, goaliesPaths.saveLocation);
|
|
1305
1324
|
const path = resolvePath(goaliesPaths.saveLocation, parsed);
|
|
1306
1325
|
return nhlClient.get(path);
|
|
1307
1326
|
}
|
|
@@ -1312,36 +1331,28 @@ var top10 = {
|
|
|
1312
1331
|
};
|
|
1313
1332
|
async function top10SavePercentage(season, gameType, sortBy) {
|
|
1314
1333
|
const Parser = BaseParams.merge({
|
|
1315
|
-
sortBy: SavePercentageSort
|
|
1334
|
+
sortBy: withDefault(SavePercentageSort, "GAMES")
|
|
1316
1335
|
});
|
|
1317
1336
|
const parsed = Parser({ season, gameType, sortBy });
|
|
1318
1337
|
if (isParseError(parsed))
|
|
1319
|
-
return
|
|
1320
|
-
|
|
1321
|
-
endpoint: goaliesPaths.top10.SavePercentage
|
|
1322
|
-
})
|
|
1323
|
-
);
|
|
1324
|
-
const path = resolvePath(goaliesPaths.top10.SavePercentage, parsed);
|
|
1338
|
+
return invalidParams(parsed, goaliesPaths.top10.savePercentage);
|
|
1339
|
+
const path = resolvePath(goaliesPaths.top10.savePercentage, parsed);
|
|
1325
1340
|
return nhlClient.get(path);
|
|
1326
1341
|
}
|
|
1327
1342
|
async function top10SavePercentage5v5(season, gameType, sortBy) {
|
|
1328
1343
|
const Parser = BaseParams.merge({
|
|
1329
|
-
sortBy: SavePercentage5v5Sort
|
|
1344
|
+
sortBy: withDefault(SavePercentage5v5Sort, "5v5-SV%")
|
|
1330
1345
|
});
|
|
1331
1346
|
const parsed = Parser({ season, gameType, sortBy });
|
|
1332
1347
|
if (isParseError(parsed))
|
|
1333
|
-
return
|
|
1334
|
-
|
|
1335
|
-
endpoint: goaliesPaths.top10.SavePercentage5v5
|
|
1336
|
-
})
|
|
1337
|
-
);
|
|
1338
|
-
const path = resolvePath(goaliesPaths.top10.SavePercentage5v5, parsed);
|
|
1348
|
+
return invalidParams(parsed, goaliesPaths.top10.savePercentage5v5);
|
|
1349
|
+
const path = resolvePath(goaliesPaths.top10.savePercentage5v5, parsed);
|
|
1339
1350
|
return nhlClient.get(path);
|
|
1340
1351
|
}
|
|
1341
1352
|
async function top10SaveLocation(season, gameType, category, sortBy) {
|
|
1342
1353
|
const Parser = BaseParams.merge({
|
|
1343
|
-
category: SaveLocationCategory
|
|
1344
|
-
sortBy: SaveLocationSort
|
|
1354
|
+
category: withDefault(SaveLocationCategory, "SV%"),
|
|
1355
|
+
sortBy: withDefault(SaveLocationSort, "ALL")
|
|
1345
1356
|
});
|
|
1346
1357
|
const parsed = Parser({
|
|
1347
1358
|
season,
|
|
@@ -1350,12 +1361,8 @@ async function top10SaveLocation(season, gameType, category, sortBy) {
|
|
|
1350
1361
|
sortBy
|
|
1351
1362
|
});
|
|
1352
1363
|
if (isParseError(parsed))
|
|
1353
|
-
return
|
|
1354
|
-
|
|
1355
|
-
endpoint: goaliesPaths.top10.SaveLocation
|
|
1356
|
-
})
|
|
1357
|
-
);
|
|
1358
|
-
const path = resolvePath(goaliesPaths.top10.SaveLocation, parsed);
|
|
1364
|
+
return invalidParams(parsed, goaliesPaths.top10.saveLocation);
|
|
1365
|
+
const path = resolvePath(goaliesPaths.top10.saveLocation, parsed);
|
|
1359
1366
|
return nhlClient.get(path);
|
|
1360
1367
|
}
|
|
1361
1368
|
|
|
@@ -1374,89 +1381,50 @@ __export(skaters_exports, {
|
|
|
1374
1381
|
});
|
|
1375
1382
|
async function detail(playerId, season, gameType) {
|
|
1376
1383
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1377
|
-
if (isParseError(parsed))
|
|
1378
|
-
return Promise.reject(
|
|
1379
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1380
|
-
endpoint: skatersPaths.player
|
|
1381
|
-
})
|
|
1382
|
-
);
|
|
1384
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.player);
|
|
1383
1385
|
const path = resolvePath(skatersPaths.player, parsed);
|
|
1384
1386
|
return nhlClient.get(path);
|
|
1385
1387
|
}
|
|
1386
1388
|
async function shotLocation(playerId, season, gameType) {
|
|
1387
1389
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1388
|
-
if (isParseError(parsed))
|
|
1389
|
-
return Promise.reject(
|
|
1390
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1391
|
-
endpoint: skatersPaths.shotLocation
|
|
1392
|
-
})
|
|
1393
|
-
);
|
|
1390
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.shotLocation);
|
|
1394
1391
|
const path = resolvePath(skatersPaths.shotLocation, parsed);
|
|
1395
1392
|
return nhlClient.get(path);
|
|
1396
1393
|
}
|
|
1397
1394
|
async function shotSpeed(playerId, season, gameType) {
|
|
1398
1395
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1399
|
-
if (isParseError(parsed))
|
|
1400
|
-
return Promise.reject(
|
|
1401
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1402
|
-
endpoint: skatersPaths.shotSpeed
|
|
1403
|
-
})
|
|
1404
|
-
);
|
|
1396
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.shotSpeed);
|
|
1405
1397
|
const path = resolvePath(skatersPaths.shotSpeed, parsed);
|
|
1406
1398
|
return nhlClient.get(path);
|
|
1407
1399
|
}
|
|
1408
1400
|
async function skatingDistance(playerId, season, gameType) {
|
|
1409
1401
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1410
1402
|
if (isParseError(parsed))
|
|
1411
|
-
return
|
|
1412
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1413
|
-
endpoint: skatersPaths.skatingDistance
|
|
1414
|
-
})
|
|
1415
|
-
);
|
|
1403
|
+
return invalidParams(parsed, skatersPaths.skatingDistance);
|
|
1416
1404
|
const path = resolvePath(skatersPaths.skatingDistance, parsed);
|
|
1417
1405
|
return nhlClient.get(path);
|
|
1418
1406
|
}
|
|
1419
1407
|
async function skatingSpeed(playerId, season, gameType) {
|
|
1420
1408
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1421
|
-
if (isParseError(parsed))
|
|
1422
|
-
return Promise.reject(
|
|
1423
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1424
|
-
endpoint: skatersPaths.skatingSpeed
|
|
1425
|
-
})
|
|
1426
|
-
);
|
|
1409
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.skatingSpeed);
|
|
1427
1410
|
const path = resolvePath(skatersPaths.skatingSpeed, parsed);
|
|
1428
1411
|
return nhlClient.get(path);
|
|
1429
1412
|
}
|
|
1430
1413
|
async function zoneTime(playerId, season, gameType) {
|
|
1431
1414
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1432
|
-
if (isParseError(parsed))
|
|
1433
|
-
return Promise.reject(
|
|
1434
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1435
|
-
endpoint: skatersPaths.zoneTime
|
|
1436
|
-
})
|
|
1437
|
-
);
|
|
1415
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.zoneTime);
|
|
1438
1416
|
const path = resolvePath(skatersPaths.zoneTime, parsed);
|
|
1439
1417
|
return nhlClient.get(path);
|
|
1440
1418
|
}
|
|
1441
1419
|
async function comparison(playerId, season, gameType) {
|
|
1442
1420
|
const parsed = PlayerParams({ playerId, season, gameType });
|
|
1443
|
-
if (isParseError(parsed))
|
|
1444
|
-
return Promise.reject(
|
|
1445
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1446
|
-
endpoint: skatersPaths.compare
|
|
1447
|
-
})
|
|
1448
|
-
);
|
|
1421
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.compare);
|
|
1449
1422
|
const path = resolvePath(skatersPaths.compare, parsed);
|
|
1450
1423
|
return nhlClient.get(path);
|
|
1451
1424
|
}
|
|
1452
1425
|
async function leaders2(season, gameType) {
|
|
1453
1426
|
const parsed = BaseParams({ season, gameType });
|
|
1454
|
-
if (isParseError(parsed))
|
|
1455
|
-
return Promise.reject(
|
|
1456
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1457
|
-
endpoint: skatersPaths.leaders
|
|
1458
|
-
})
|
|
1459
|
-
);
|
|
1427
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.leaders);
|
|
1460
1428
|
const path = resolvePath(skatersPaths.leaders, parsed);
|
|
1461
1429
|
return nhlClient.get(path);
|
|
1462
1430
|
}
|
|
@@ -1469,7 +1437,7 @@ var top102 = {
|
|
|
1469
1437
|
};
|
|
1470
1438
|
async function top10Distance(season, gameType, position, strength, sortBy) {
|
|
1471
1439
|
const parsed = top10Params.merge({
|
|
1472
|
-
sortBy: SkatingDistanceSort
|
|
1440
|
+
sortBy: withDefault(SkatingDistanceSort, "TOTAL")
|
|
1473
1441
|
})({
|
|
1474
1442
|
season,
|
|
1475
1443
|
gameType,
|
|
@@ -1478,18 +1446,14 @@ async function top10Distance(season, gameType, position, strength, sortBy) {
|
|
|
1478
1446
|
sortBy
|
|
1479
1447
|
});
|
|
1480
1448
|
if (isParseError(parsed))
|
|
1481
|
-
return
|
|
1482
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1483
|
-
endpoint: skatersPaths.top10.skatingDistance
|
|
1484
|
-
})
|
|
1485
|
-
);
|
|
1449
|
+
return invalidParams(parsed, skatersPaths.top10.skatingDistance);
|
|
1486
1450
|
const path = resolvePath(skatersPaths.top10.skatingDistance, parsed);
|
|
1487
1451
|
return nhlClient.get(path);
|
|
1488
1452
|
}
|
|
1489
1453
|
async function top10ShotLocation(season, gameType, position, category, sortBy) {
|
|
1490
1454
|
const parsed = top10Params.merge({
|
|
1491
|
-
category: ShotLocationCategory
|
|
1492
|
-
sortBy: ShotLocationSort
|
|
1455
|
+
category: withDefault(ShotLocationCategory, "G"),
|
|
1456
|
+
sortBy: withDefault(ShotLocationSort, "ALL")
|
|
1493
1457
|
})({
|
|
1494
1458
|
season,
|
|
1495
1459
|
gameType,
|
|
@@ -1498,17 +1462,13 @@ async function top10ShotLocation(season, gameType, position, category, sortBy) {
|
|
|
1498
1462
|
sortBy
|
|
1499
1463
|
});
|
|
1500
1464
|
if (isParseError(parsed))
|
|
1501
|
-
return
|
|
1502
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1503
|
-
endpoint: skatersPaths.top10.shotLocation
|
|
1504
|
-
})
|
|
1505
|
-
);
|
|
1465
|
+
return invalidParams(parsed, skatersPaths.top10.shotLocation);
|
|
1506
1466
|
const path = resolvePath(skatersPaths.top10.shotLocation, parsed);
|
|
1507
1467
|
return nhlClient.get(path);
|
|
1508
1468
|
}
|
|
1509
1469
|
async function top10ShotSpeed(season, gameType, position, sortBy) {
|
|
1510
1470
|
const parsed = top10Params.merge({
|
|
1511
|
-
sortBy: ShotSpeedSort
|
|
1471
|
+
sortBy: withDefault(ShotSpeedSort, "MAX")
|
|
1512
1472
|
})({
|
|
1513
1473
|
season,
|
|
1514
1474
|
gameType,
|
|
@@ -1516,17 +1476,13 @@ async function top10ShotSpeed(season, gameType, position, sortBy) {
|
|
|
1516
1476
|
sortBy
|
|
1517
1477
|
});
|
|
1518
1478
|
if (isParseError(parsed))
|
|
1519
|
-
return
|
|
1520
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1521
|
-
endpoint: skatersPaths.top10.shotSpeed
|
|
1522
|
-
})
|
|
1523
|
-
);
|
|
1479
|
+
return invalidParams(parsed, skatersPaths.top10.shotSpeed);
|
|
1524
1480
|
const path = resolvePath(skatersPaths.top10.shotSpeed, parsed);
|
|
1525
1481
|
return nhlClient.get(path);
|
|
1526
1482
|
}
|
|
1527
1483
|
async function top10Speed(season, gameType, position, sortBy) {
|
|
1528
1484
|
const parsed = top10Params.merge({
|
|
1529
|
-
sortBy: SkatingSpeedSort
|
|
1485
|
+
sortBy: withDefault(SkatingSpeedSort, "TOP")
|
|
1530
1486
|
})({
|
|
1531
1487
|
season,
|
|
1532
1488
|
gameType,
|
|
@@ -1534,17 +1490,13 @@ async function top10Speed(season, gameType, position, sortBy) {
|
|
|
1534
1490
|
sortBy
|
|
1535
1491
|
});
|
|
1536
1492
|
if (isParseError(parsed))
|
|
1537
|
-
return
|
|
1538
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1539
|
-
endpoint: skatersPaths.top10.skatingSpeed
|
|
1540
|
-
})
|
|
1541
|
-
);
|
|
1493
|
+
return invalidParams(parsed, skatersPaths.top10.skatingSpeed);
|
|
1542
1494
|
const path = resolvePath(skatersPaths.top10.skatingSpeed, parsed);
|
|
1543
1495
|
return nhlClient.get(path);
|
|
1544
1496
|
}
|
|
1545
1497
|
async function top10ZoneTime(season, gameType, position, strength, sortBy) {
|
|
1546
1498
|
const parsed = top10Params.merge({
|
|
1547
|
-
sortBy: ZoneTimeSort
|
|
1499
|
+
sortBy: withDefault(ZoneTimeSort, "OZ")
|
|
1548
1500
|
})({
|
|
1549
1501
|
season,
|
|
1550
1502
|
gameType,
|
|
@@ -1552,12 +1504,7 @@ async function top10ZoneTime(season, gameType, position, strength, sortBy) {
|
|
|
1552
1504
|
strength,
|
|
1553
1505
|
sortBy
|
|
1554
1506
|
});
|
|
1555
|
-
if (isParseError(parsed))
|
|
1556
|
-
return Promise.reject(
|
|
1557
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1558
|
-
endpoint: skatersPaths.top10.zoneTime
|
|
1559
|
-
})
|
|
1560
|
-
);
|
|
1507
|
+
if (isParseError(parsed)) return invalidParams(parsed, skatersPaths.top10.zoneTime);
|
|
1561
1508
|
const path = resolvePath(skatersPaths.top10.zoneTime, parsed);
|
|
1562
1509
|
return nhlClient.get(path);
|
|
1563
1510
|
}
|
|
@@ -1582,90 +1529,51 @@ __export(teams_exports, {
|
|
|
1582
1529
|
});
|
|
1583
1530
|
async function stats(teamId, season, gameType) {
|
|
1584
1531
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1585
|
-
if (isParseError(parsed))
|
|
1586
|
-
return Promise.reject(
|
|
1587
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1588
|
-
endpoint: teamsPaths.stats
|
|
1589
|
-
})
|
|
1590
|
-
);
|
|
1532
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.stats);
|
|
1591
1533
|
const path = resolvePath(teamsPaths.stats, parsed);
|
|
1592
1534
|
return nhlClient.get(path);
|
|
1593
1535
|
}
|
|
1594
1536
|
async function compare2(teamId, season, gameType) {
|
|
1595
1537
|
gameType ??= "REG";
|
|
1596
1538
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1597
|
-
if (isParseError(parsed))
|
|
1598
|
-
return Promise.reject(
|
|
1599
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1600
|
-
endpoint: teamsPaths.compare
|
|
1601
|
-
})
|
|
1602
|
-
);
|
|
1539
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.compare);
|
|
1603
1540
|
const path = resolvePath(teamsPaths.compare, parsed);
|
|
1604
1541
|
return nhlClient.get(path);
|
|
1605
1542
|
}
|
|
1606
1543
|
async function leaders3(season, gameType) {
|
|
1607
1544
|
const parsed = BaseParams({ season, gameType });
|
|
1608
|
-
if (isParseError(parsed))
|
|
1609
|
-
return Promise.reject(
|
|
1610
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1611
|
-
endpoint: teamsPaths.leaders
|
|
1612
|
-
})
|
|
1613
|
-
);
|
|
1545
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.leaders);
|
|
1614
1546
|
const path = resolvePath(teamsPaths.leaders, parsed);
|
|
1615
1547
|
return nhlClient.get(path);
|
|
1616
1548
|
}
|
|
1617
1549
|
async function shotLocation2(teamId, season, gameType) {
|
|
1618
1550
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1619
|
-
if (isParseError(parsed))
|
|
1620
|
-
return Promise.reject(
|
|
1621
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1622
|
-
endpoint: teamsPaths.shotLocation
|
|
1623
|
-
})
|
|
1624
|
-
);
|
|
1551
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.shotLocation);
|
|
1625
1552
|
const path = resolvePath(teamsPaths.shotLocation, parsed);
|
|
1626
1553
|
return nhlClient.get(path);
|
|
1627
1554
|
}
|
|
1628
1555
|
async function shotSpeed2(teamId, season, gameType) {
|
|
1629
1556
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1630
|
-
if (isParseError(parsed))
|
|
1631
|
-
return Promise.reject(
|
|
1632
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1633
|
-
endpoint: teamsPaths.shotSpeed
|
|
1634
|
-
})
|
|
1635
|
-
);
|
|
1557
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.shotSpeed);
|
|
1636
1558
|
const path = resolvePath(teamsPaths.shotSpeed, parsed);
|
|
1637
1559
|
return nhlClient.get(path);
|
|
1638
1560
|
}
|
|
1639
1561
|
async function skatingDistance2(teamId, season, gameType) {
|
|
1640
1562
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1641
1563
|
if (isParseError(parsed))
|
|
1642
|
-
return
|
|
1643
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1644
|
-
endpoint: teamsPaths.skatingDistance
|
|
1645
|
-
})
|
|
1646
|
-
);
|
|
1564
|
+
return invalidParams(parsed, teamsPaths.skatingDistance);
|
|
1647
1565
|
const path = resolvePath(teamsPaths.skatingDistance, parsed);
|
|
1648
1566
|
return nhlClient.get(path);
|
|
1649
1567
|
}
|
|
1650
1568
|
async function skatingSpeed2(teamId, season, gameType) {
|
|
1651
1569
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1652
|
-
if (isParseError(parsed))
|
|
1653
|
-
return Promise.reject(
|
|
1654
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1655
|
-
endpoint: teamsPaths.skatingSpeed
|
|
1656
|
-
})
|
|
1657
|
-
);
|
|
1570
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.skatingSpeed);
|
|
1658
1571
|
const path = resolvePath(teamsPaths.skatingSpeed, parsed);
|
|
1659
1572
|
return nhlClient.get(path);
|
|
1660
1573
|
}
|
|
1661
1574
|
async function zoneTime2(teamId, season, gameType) {
|
|
1662
1575
|
const parsed = TeamParams({ teamId, season, gameType });
|
|
1663
|
-
if (isParseError(parsed))
|
|
1664
|
-
return Promise.reject(
|
|
1665
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1666
|
-
endpoint: teamsPaths.zoneTime
|
|
1667
|
-
})
|
|
1668
|
-
);
|
|
1576
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.zoneTime);
|
|
1669
1577
|
const path = resolvePath(teamsPaths.zoneTime, parsed);
|
|
1670
1578
|
return nhlClient.get(path);
|
|
1671
1579
|
}
|
|
@@ -1678,9 +1586,9 @@ var top103 = {
|
|
|
1678
1586
|
};
|
|
1679
1587
|
async function top10ShotLocation2(season, gameType, position, category, sortBy) {
|
|
1680
1588
|
const Parser = BaseParams.merge({
|
|
1681
|
-
position: PositionFilter
|
|
1682
|
-
category: ShotLocationCategory
|
|
1683
|
-
sortBy: ShotLocationSort
|
|
1589
|
+
position: withDefault(PositionFilter, "ALL"),
|
|
1590
|
+
category: withDefault(ShotLocationCategory, "G"),
|
|
1591
|
+
sortBy: withDefault(ShotLocationSort, "ALL")
|
|
1684
1592
|
});
|
|
1685
1593
|
const parsed = Parser({
|
|
1686
1594
|
season,
|
|
@@ -1690,18 +1598,14 @@ async function top10ShotLocation2(season, gameType, position, category, sortBy)
|
|
|
1690
1598
|
sortBy
|
|
1691
1599
|
});
|
|
1692
1600
|
if (isParseError(parsed))
|
|
1693
|
-
return
|
|
1694
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1695
|
-
endpoint: teamsPaths.shotLocation
|
|
1696
|
-
})
|
|
1697
|
-
);
|
|
1601
|
+
return invalidParams(parsed, teamsPaths.top10.shotLocation);
|
|
1698
1602
|
const path = resolvePath(teamsPaths.top10.shotLocation, parsed);
|
|
1699
1603
|
return nhlClient.get(path);
|
|
1700
1604
|
}
|
|
1701
1605
|
async function top10ShotSpeed2(season, gameType, position, sortBy) {
|
|
1702
1606
|
const Parser = BaseParams.merge({
|
|
1703
|
-
position: PositionFilter
|
|
1704
|
-
sortBy: ShotSpeedSort
|
|
1607
|
+
position: withDefault(PositionFilter, "ALL"),
|
|
1608
|
+
sortBy: withDefault(ShotSpeedSort, "MAX")
|
|
1705
1609
|
});
|
|
1706
1610
|
const parsed = Parser({
|
|
1707
1611
|
season,
|
|
@@ -1710,19 +1614,15 @@ async function top10ShotSpeed2(season, gameType, position, sortBy) {
|
|
|
1710
1614
|
sortBy
|
|
1711
1615
|
});
|
|
1712
1616
|
if (isParseError(parsed))
|
|
1713
|
-
return
|
|
1714
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1715
|
-
endpoint: teamsPaths.shotSpeed
|
|
1716
|
-
})
|
|
1717
|
-
);
|
|
1617
|
+
return invalidParams(parsed, teamsPaths.top10.shotSpeed);
|
|
1718
1618
|
const path = resolvePath(teamsPaths.top10.shotSpeed, parsed);
|
|
1719
1619
|
return nhlClient.get(path);
|
|
1720
1620
|
}
|
|
1721
1621
|
async function top10SkatingDistance(season, gameType, position, strength, sortBy) {
|
|
1722
1622
|
const Parser = BaseParams.merge({
|
|
1723
|
-
position: PositionFilter
|
|
1724
|
-
strength: SkatersStrength
|
|
1725
|
-
sortBy: SkatingDistanceSort
|
|
1623
|
+
position: withDefault(PositionFilter, "ALL"),
|
|
1624
|
+
strength: withDefault(SkatersStrength, "ALL"),
|
|
1625
|
+
sortBy: withDefault(SkatingDistanceSort, "TOTAL")
|
|
1726
1626
|
});
|
|
1727
1627
|
const parsed = Parser({
|
|
1728
1628
|
season,
|
|
@@ -1732,18 +1632,14 @@ async function top10SkatingDistance(season, gameType, position, strength, sortBy
|
|
|
1732
1632
|
sortBy
|
|
1733
1633
|
});
|
|
1734
1634
|
if (isParseError(parsed))
|
|
1735
|
-
return
|
|
1736
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1737
|
-
endpoint: teamsPaths.skatingDistance
|
|
1738
|
-
})
|
|
1739
|
-
);
|
|
1635
|
+
return invalidParams(parsed, teamsPaths.top10.skatingDistance);
|
|
1740
1636
|
const path = resolvePath(teamsPaths.top10.skatingDistance, parsed);
|
|
1741
1637
|
return nhlClient.get(path);
|
|
1742
1638
|
}
|
|
1743
1639
|
async function top10SkatingSpeed(season, gameType, position, sortBy) {
|
|
1744
1640
|
const Parser = BaseParams.merge({
|
|
1745
|
-
position: PositionFilter
|
|
1746
|
-
sortBy: SkatingSpeedSort
|
|
1641
|
+
position: withDefault(PositionFilter, "ALL"),
|
|
1642
|
+
sortBy: withDefault(SkatingSpeedSort, "TOP")
|
|
1747
1643
|
});
|
|
1748
1644
|
const parsed = Parser({
|
|
1749
1645
|
season,
|
|
@@ -1752,18 +1648,14 @@ async function top10SkatingSpeed(season, gameType, position, sortBy) {
|
|
|
1752
1648
|
sortBy
|
|
1753
1649
|
});
|
|
1754
1650
|
if (isParseError(parsed))
|
|
1755
|
-
return
|
|
1756
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1757
|
-
endpoint: teamsPaths.skatingSpeed
|
|
1758
|
-
})
|
|
1759
|
-
);
|
|
1651
|
+
return invalidParams(parsed, teamsPaths.top10.skatingSpeed);
|
|
1760
1652
|
const path = resolvePath(teamsPaths.top10.skatingSpeed, parsed);
|
|
1761
1653
|
return nhlClient.get(path);
|
|
1762
1654
|
}
|
|
1763
1655
|
async function top10ZoneTime2(season, gameType, strength, sortBy) {
|
|
1764
1656
|
const Parser = BaseParams.merge({
|
|
1765
|
-
strength: SkatersStrength
|
|
1766
|
-
sortBy: ZoneTimeSort
|
|
1657
|
+
strength: withDefault(SkatersStrength, "ALL"),
|
|
1658
|
+
sortBy: withDefault(ZoneTimeSort, "OZ")
|
|
1767
1659
|
});
|
|
1768
1660
|
const parsed = Parser({
|
|
1769
1661
|
season,
|
|
@@ -1771,22 +1663,569 @@ async function top10ZoneTime2(season, gameType, strength, sortBy) {
|
|
|
1771
1663
|
strength,
|
|
1772
1664
|
sortBy
|
|
1773
1665
|
});
|
|
1774
|
-
if (isParseError(parsed))
|
|
1775
|
-
return Promise.reject(
|
|
1776
|
-
new NHLError(parsed.summary, "VALIDATION", {
|
|
1777
|
-
endpoint: teamsPaths.zoneTime
|
|
1778
|
-
})
|
|
1779
|
-
);
|
|
1666
|
+
if (isParseError(parsed)) return invalidParams(parsed, teamsPaths.top10.zoneTime);
|
|
1780
1667
|
const path = resolvePath(teamsPaths.top10.zoneTime, parsed);
|
|
1781
1668
|
return nhlClient.get(path);
|
|
1782
1669
|
}
|
|
1783
1670
|
|
|
1671
|
+
// src/api/edge-stats/index.ts
|
|
1672
|
+
var edge_stats_exports = {};
|
|
1673
|
+
__export(edge_stats_exports, {
|
|
1674
|
+
goalies: () => goalies_exports2,
|
|
1675
|
+
misc: () => misc_exports,
|
|
1676
|
+
season: () => season_game_exports,
|
|
1677
|
+
skaters: () => skaters_exports2,
|
|
1678
|
+
teams: () => teams_exports2
|
|
1679
|
+
});
|
|
1680
|
+
|
|
1681
|
+
// src/api/edge-stats/goalies.ts
|
|
1682
|
+
var goalies_exports2 = {};
|
|
1683
|
+
__export(goalies_exports2, {
|
|
1684
|
+
getLeaders: () => getLeaders,
|
|
1685
|
+
getMilestones: () => getMilestones,
|
|
1686
|
+
getStats: () => getStats,
|
|
1687
|
+
getStatsWithBuilder: () => getStatsWithBuilder,
|
|
1688
|
+
getStatsWithFilters: () => getStatsWithFilters,
|
|
1689
|
+
getStatsWithParams: () => getStatsWithParams
|
|
1690
|
+
});
|
|
1691
|
+
|
|
1692
|
+
// src/utils/cayenne-query-builder.ts
|
|
1693
|
+
var CayenneQueryBuilder = class {
|
|
1694
|
+
conditions = [];
|
|
1695
|
+
currentLogicalOp = "and";
|
|
1696
|
+
groupStack = [];
|
|
1697
|
+
/**
|
|
1698
|
+
* Start a new logical group
|
|
1699
|
+
* All subsequent conditions will be added to this group until endGroup() is called
|
|
1700
|
+
* @returns This builder instance for chaining
|
|
1701
|
+
* @example
|
|
1702
|
+
* builder
|
|
1703
|
+
* .equals('field1', 'value1')
|
|
1704
|
+
* .group()
|
|
1705
|
+
* .equals('field2', 'value2')
|
|
1706
|
+
* .or()
|
|
1707
|
+
* .equals('field3', 'value3')
|
|
1708
|
+
* .endGroup()
|
|
1709
|
+
* // Generates: "field1=value1 and (field2=value2 or field3=value3)"
|
|
1710
|
+
*/
|
|
1711
|
+
group() {
|
|
1712
|
+
this.groupStack.push({
|
|
1713
|
+
conditions: this.conditions,
|
|
1714
|
+
logicalOp: this.currentLogicalOp
|
|
1715
|
+
});
|
|
1716
|
+
this.conditions = [];
|
|
1717
|
+
this.currentLogicalOp = "and";
|
|
1718
|
+
return this;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* End the current logical group
|
|
1722
|
+
* @returns This builder instance for chaining
|
|
1723
|
+
* @throws Error if there's no open group
|
|
1724
|
+
*/
|
|
1725
|
+
endGroup() {
|
|
1726
|
+
if (this.groupStack.length === 0) {
|
|
1727
|
+
throw new Error("Cannot end group: no open group found");
|
|
1728
|
+
}
|
|
1729
|
+
const groupConditions = this.conditions;
|
|
1730
|
+
const parent = this.groupStack.pop();
|
|
1731
|
+
if (!parent) {
|
|
1732
|
+
throw new Error("Failed to restore parent context");
|
|
1733
|
+
}
|
|
1734
|
+
this.conditions = parent.conditions;
|
|
1735
|
+
const groupLogicalOp = parent.logicalOp;
|
|
1736
|
+
this.currentLogicalOp = parent.logicalOp;
|
|
1737
|
+
const group = {
|
|
1738
|
+
type: "group",
|
|
1739
|
+
conditions: groupConditions,
|
|
1740
|
+
logicalOp: groupLogicalOp
|
|
1741
|
+
};
|
|
1742
|
+
this.conditions.push(group);
|
|
1743
|
+
return this;
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* Set the logical operator to AND for subsequent conditions
|
|
1747
|
+
* @returns This builder instance for chaining
|
|
1748
|
+
*/
|
|
1749
|
+
and() {
|
|
1750
|
+
this.currentLogicalOp = "and";
|
|
1751
|
+
return this;
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Set the logical operator to OR for subsequent conditions
|
|
1755
|
+
* @returns This builder instance for chaining
|
|
1756
|
+
*/
|
|
1757
|
+
or() {
|
|
1758
|
+
this.currentLogicalOp = "or";
|
|
1759
|
+
return this;
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Add an equality condition
|
|
1763
|
+
* @param field - The field name to filter on
|
|
1764
|
+
* @param value - The value to match
|
|
1765
|
+
* @returns This builder instance for chaining
|
|
1766
|
+
*/
|
|
1767
|
+
equals(field, value) {
|
|
1768
|
+
this.conditions.push({
|
|
1769
|
+
field,
|
|
1770
|
+
operator: "=",
|
|
1771
|
+
value,
|
|
1772
|
+
logicalOp: this.currentLogicalOp
|
|
1773
|
+
});
|
|
1774
|
+
return this;
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Add a not-equal condition
|
|
1778
|
+
* @param field - The field name to filter on
|
|
1779
|
+
* @param value - The value to exclude
|
|
1780
|
+
* @returns This builder instance for chaining
|
|
1781
|
+
*/
|
|
1782
|
+
notEquals(field, value) {
|
|
1783
|
+
this.conditions.push({
|
|
1784
|
+
field,
|
|
1785
|
+
operator: "!=",
|
|
1786
|
+
value,
|
|
1787
|
+
logicalOp: this.currentLogicalOp
|
|
1788
|
+
});
|
|
1789
|
+
return this;
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* Add a less-than condition
|
|
1793
|
+
* @param field - The field name to filter on
|
|
1794
|
+
* @param value - The upper bound (exclusive)
|
|
1795
|
+
* @returns This builder instance for chaining
|
|
1796
|
+
*/
|
|
1797
|
+
lessThan(field, value) {
|
|
1798
|
+
this.conditions.push({
|
|
1799
|
+
field,
|
|
1800
|
+
operator: "<",
|
|
1801
|
+
value,
|
|
1802
|
+
logicalOp: this.currentLogicalOp
|
|
1803
|
+
});
|
|
1804
|
+
return this;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Add a greater-than condition
|
|
1808
|
+
* @param field - The field name to filter on
|
|
1809
|
+
* @param value - The lower bound (exclusive)
|
|
1810
|
+
* @returns This builder instance for chaining
|
|
1811
|
+
*/
|
|
1812
|
+
greaterThan(field, value) {
|
|
1813
|
+
this.conditions.push({
|
|
1814
|
+
field,
|
|
1815
|
+
operator: ">",
|
|
1816
|
+
value,
|
|
1817
|
+
logicalOp: this.currentLogicalOp
|
|
1818
|
+
});
|
|
1819
|
+
return this;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Add a less-than-or-equal condition
|
|
1823
|
+
* @param field - The field name to filter on
|
|
1824
|
+
* @param value - The upper bound (inclusive)
|
|
1825
|
+
* @returns This builder instance for chaining
|
|
1826
|
+
*/
|
|
1827
|
+
lessThanOrEqual(field, value) {
|
|
1828
|
+
this.conditions.push({
|
|
1829
|
+
field,
|
|
1830
|
+
operator: "<=",
|
|
1831
|
+
value,
|
|
1832
|
+
logicalOp: this.currentLogicalOp
|
|
1833
|
+
});
|
|
1834
|
+
return this;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Add a greater-than-or-equal condition
|
|
1838
|
+
* @param field - The field name to filter on
|
|
1839
|
+
* @param value - The lower bound (inclusive)
|
|
1840
|
+
* @returns This builder instance for chaining
|
|
1841
|
+
*/
|
|
1842
|
+
greaterThanOrEqual(field, value) {
|
|
1843
|
+
this.conditions.push({
|
|
1844
|
+
field,
|
|
1845
|
+
operator: ">=",
|
|
1846
|
+
value,
|
|
1847
|
+
logicalOp: this.currentLogicalOp
|
|
1848
|
+
});
|
|
1849
|
+
return this;
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Add an IN condition to match multiple values
|
|
1853
|
+
* @param field - The field name to filter on
|
|
1854
|
+
* @param values - Array of values to match against
|
|
1855
|
+
* @returns This builder instance for chaining
|
|
1856
|
+
* @example
|
|
1857
|
+
* builder.in('playerId', [8476791, 8477933, 8478402])
|
|
1858
|
+
* // Generates: "playerId in (8476791, 8477933, 8478402)"
|
|
1859
|
+
*/
|
|
1860
|
+
in(field, values) {
|
|
1861
|
+
if (values.length === 0) {
|
|
1862
|
+
throw new Error("IN condition requires at least one value");
|
|
1863
|
+
}
|
|
1864
|
+
this.conditions.push({
|
|
1865
|
+
field,
|
|
1866
|
+
operator: "in",
|
|
1867
|
+
value: values,
|
|
1868
|
+
logicalOp: this.currentLogicalOp
|
|
1869
|
+
});
|
|
1870
|
+
return this;
|
|
1871
|
+
}
|
|
1872
|
+
/**
|
|
1873
|
+
* Add a LIKE condition for pattern matching
|
|
1874
|
+
* @param field - The field name to filter on
|
|
1875
|
+
* @param pattern - The pattern to match (supports % for wildcards)
|
|
1876
|
+
* @returns This builder instance for chaining
|
|
1877
|
+
* @example
|
|
1878
|
+
* builder.like('playerName', '%McDavid%')
|
|
1879
|
+
* // Generates: "playerName like '%McDavid%'"
|
|
1880
|
+
*/
|
|
1881
|
+
like(field, pattern) {
|
|
1882
|
+
this.conditions.push({
|
|
1883
|
+
field,
|
|
1884
|
+
operator: "like",
|
|
1885
|
+
value: pattern,
|
|
1886
|
+
logicalOp: this.currentLogicalOp
|
|
1887
|
+
});
|
|
1888
|
+
return this;
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Add a raw condition string
|
|
1892
|
+
* Useful for complex expressions or unsupported operators
|
|
1893
|
+
* @param condition - The raw condition string (e.g., "playerId=8476791")
|
|
1894
|
+
* @returns This builder instance for chaining
|
|
1895
|
+
*/
|
|
1896
|
+
raw(condition) {
|
|
1897
|
+
this.conditions.push({
|
|
1898
|
+
field: "__raw__",
|
|
1899
|
+
operator: "=",
|
|
1900
|
+
value: condition,
|
|
1901
|
+
logicalOp: this.currentLogicalOp
|
|
1902
|
+
});
|
|
1903
|
+
return this;
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Build the cayenneExp string
|
|
1907
|
+
* @returns The formatted cayenneExp string ready for API consumption
|
|
1908
|
+
*/
|
|
1909
|
+
build() {
|
|
1910
|
+
if (this.groupStack.length > 0) {
|
|
1911
|
+
throw new Error(
|
|
1912
|
+
`Cannot build: ${this.groupStack.length} group(s) still open. Call endGroup() to close them.`
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
const buildExpression = (items, depth = 0) => {
|
|
1916
|
+
return items.map((item, index) => {
|
|
1917
|
+
let expr = "";
|
|
1918
|
+
if ("type" in item && item.type === "group") {
|
|
1919
|
+
const groupExpr = buildExpression(
|
|
1920
|
+
item.conditions,
|
|
1921
|
+
depth + 1
|
|
1922
|
+
);
|
|
1923
|
+
expr = `(${groupExpr})`;
|
|
1924
|
+
} else if ("field" in item) {
|
|
1925
|
+
const condition = item;
|
|
1926
|
+
if (condition.field === "__raw__") {
|
|
1927
|
+
expr = String(condition.value);
|
|
1928
|
+
} else if (condition.operator === "in") {
|
|
1929
|
+
const values = Array.isArray(condition.value) ? condition.value.join(", ") : condition.value;
|
|
1930
|
+
expr = `${condition.field} in (${values})`;
|
|
1931
|
+
} else if (condition.operator === "like") {
|
|
1932
|
+
expr = `${condition.field} like '${condition.value}'`;
|
|
1933
|
+
} else {
|
|
1934
|
+
expr = `${condition.field}${condition.operator}${condition.value}`;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
if (index < items.length - 1) {
|
|
1938
|
+
const nextItem = items[index + 1];
|
|
1939
|
+
if (nextItem) {
|
|
1940
|
+
const nextLogicalOp = ("logicalOp" in nextItem ? nextItem.logicalOp : void 0) || "and";
|
|
1941
|
+
expr += ` ${nextLogicalOp}`;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return expr;
|
|
1945
|
+
}).join(" ");
|
|
1946
|
+
};
|
|
1947
|
+
return buildExpression(this.conditions);
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Clear all conditions
|
|
1951
|
+
* @returns This builder instance for chaining
|
|
1952
|
+
*/
|
|
1953
|
+
clear() {
|
|
1954
|
+
this.conditions = [];
|
|
1955
|
+
return this;
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Get the number of conditions currently in the builder
|
|
1959
|
+
*/
|
|
1960
|
+
count() {
|
|
1961
|
+
return this.conditions.length;
|
|
1962
|
+
}
|
|
1963
|
+
};
|
|
1964
|
+
function createCayenneQuery() {
|
|
1965
|
+
return new CayenneQueryBuilder();
|
|
1966
|
+
}
|
|
1967
|
+
function buildCayenneExp(filters) {
|
|
1968
|
+
const builder = new CayenneQueryBuilder();
|
|
1969
|
+
Object.entries(filters).forEach(([field, value]) => {
|
|
1970
|
+
builder.equals(field, value);
|
|
1971
|
+
});
|
|
1972
|
+
return builder.build();
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
// src/api/edge-stats/paths.ts
|
|
1976
|
+
var dataPaths = {
|
|
1977
|
+
/** Goalie-related statistics and reports. */
|
|
1978
|
+
goalie: {
|
|
1979
|
+
/** Goalie leader boards by stat category. */
|
|
1980
|
+
leaders: {
|
|
1981
|
+
/** Goals-against average leaders. */
|
|
1982
|
+
gaa: "{lang}/leaders/goalies/gaa",
|
|
1983
|
+
/** Save percentage leaders. */
|
|
1984
|
+
savePctg: "{lang}/leaders/goalies/savePctg",
|
|
1985
|
+
/** Shutouts leaders. */
|
|
1986
|
+
shutouts: "{lang}/leaders/goalies/shutouts"
|
|
1987
|
+
},
|
|
1988
|
+
/** Goalie statistical reports. */
|
|
1989
|
+
report: "{lang}/goalie/{report}",
|
|
1990
|
+
/** Goalie career milestones. */
|
|
1991
|
+
milestones: "{lang}/milestones/goalies"
|
|
1992
|
+
},
|
|
1993
|
+
/** Skater/player-related statistics and reports. */
|
|
1994
|
+
skater: {
|
|
1995
|
+
/** Player directory and information. */
|
|
1996
|
+
players: "{lang}/players",
|
|
1997
|
+
/** Skater leader boards by stat category. */
|
|
1998
|
+
leaders: {
|
|
1999
|
+
/** Assists leaders. */
|
|
2000
|
+
assists: "{lang}/leaders/skaters/assists",
|
|
2001
|
+
/** Goals leaders. */
|
|
2002
|
+
goals: "{lang}/leaders/skaters/goals",
|
|
2003
|
+
/** Points leaders. */
|
|
2004
|
+
points: "{lang}/leaders/skaters/points"
|
|
2005
|
+
},
|
|
2006
|
+
/** Skater career milestones. */
|
|
2007
|
+
milestones: "{lang}/milestones/skaters",
|
|
2008
|
+
/** Skater statistical reports. */
|
|
2009
|
+
report: "{lang}/skater/{report}"
|
|
2010
|
+
},
|
|
2011
|
+
/** Team-related statistics and reports. */
|
|
2012
|
+
team: {
|
|
2013
|
+
/** All teams data. */
|
|
2014
|
+
all: "{lang}/team",
|
|
2015
|
+
/** Team data by team ID. */
|
|
2016
|
+
byId: "{lang}/team/id/{teamId}",
|
|
2017
|
+
/** Team statistical reports. */
|
|
2018
|
+
report: "{lang}/team/{report}"
|
|
2019
|
+
},
|
|
2020
|
+
/** Season-related data. */
|
|
2021
|
+
season: "{lang}/season",
|
|
2022
|
+
/** Game-related data. */
|
|
2023
|
+
game: "{lang}/game",
|
|
2024
|
+
/** Draft-related data. */
|
|
2025
|
+
draft: "{lang}/draft",
|
|
2026
|
+
/** Configuration data for skater, goalie, and team reports. */
|
|
2027
|
+
config: "{lang}/config",
|
|
2028
|
+
/** Country data. */
|
|
2029
|
+
countries: "{lang}/country",
|
|
2030
|
+
/** Shift chart data. */
|
|
2031
|
+
shiftCharts: "{lang}/shiftcharts",
|
|
2032
|
+
/** Glossary data. */
|
|
2033
|
+
glossary: "{lang}/glossary",
|
|
2034
|
+
/** Franchise data. */
|
|
2035
|
+
franchises: "{lang}/franchise"
|
|
2036
|
+
};
|
|
2037
|
+
|
|
2038
|
+
// src/api/edge-stats/query.ts
|
|
2039
|
+
function reportParams(params = {}) {
|
|
2040
|
+
return { ...params, cayenneExp: params.cayenneExp ?? "" };
|
|
2041
|
+
}
|
|
2042
|
+
function filterParams(filters = {}, sorting = {}, pagination = {}) {
|
|
2043
|
+
const conditions = {};
|
|
2044
|
+
for (const [field, value] of Object.entries(filters)) {
|
|
2045
|
+
if (value !== void 0 && value !== "") conditions[field] = value;
|
|
2046
|
+
}
|
|
2047
|
+
const params = {
|
|
2048
|
+
cayenneExp: buildCayenneExp(conditions)
|
|
2049
|
+
};
|
|
2050
|
+
if (sorting.sortBy) params.sort = sorting.sortBy;
|
|
2051
|
+
if (sorting.direction) params.dir = sorting.direction;
|
|
2052
|
+
if (pagination.limit !== void 0) params.limit = pagination.limit;
|
|
2053
|
+
if (pagination.start !== void 0) params.start = pagination.start;
|
|
2054
|
+
return params;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
// src/api/edge-stats/goalies.ts
|
|
2058
|
+
async function getLeaders(statCategory, params = {}, lang = config.language) {
|
|
2059
|
+
const path = resolvePath(dataPaths.goalie.leaders[statCategory], { lang });
|
|
2060
|
+
return edgeStatsClient.get(path, params);
|
|
2061
|
+
}
|
|
2062
|
+
async function getStats(report = "summary", params = {}, lang = config.language) {
|
|
2063
|
+
const path = resolvePath(dataPaths.goalie.report, { lang, report });
|
|
2064
|
+
return edgeStatsClient.get(
|
|
2065
|
+
path,
|
|
2066
|
+
reportParams(params)
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
async function getStatsWithParams(report, params, lang = config.language) {
|
|
2070
|
+
return getStats(report, params, lang);
|
|
2071
|
+
}
|
|
2072
|
+
async function getStatsWithBuilder(report, buildQuery, lang = config.language) {
|
|
2073
|
+
return getStats(report, buildQuery(new CayenneQueryBuilder()), lang);
|
|
2074
|
+
}
|
|
2075
|
+
async function getStatsWithFilters(report, filters, sorting, pagination, lang = config.language) {
|
|
2076
|
+
return getStats(
|
|
2077
|
+
report,
|
|
2078
|
+
filterParams(filters, sorting, pagination),
|
|
2079
|
+
lang
|
|
2080
|
+
);
|
|
2081
|
+
}
|
|
2082
|
+
async function getMilestones(lang = config.language) {
|
|
2083
|
+
const path = resolvePath(dataPaths.goalie.milestones, { lang });
|
|
2084
|
+
return edgeStatsClient.get(path);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
// src/api/edge-stats/misc.ts
|
|
2088
|
+
var misc_exports = {};
|
|
2089
|
+
__export(misc_exports, {
|
|
2090
|
+
getConfig: () => getConfig,
|
|
2091
|
+
getCountries: () => getCountries,
|
|
2092
|
+
getFranchises: () => getFranchises,
|
|
2093
|
+
getGlossary: () => getGlossary
|
|
2094
|
+
});
|
|
2095
|
+
async function getConfig(lang = config.language) {
|
|
2096
|
+
const path = resolvePath(dataPaths.config, { lang });
|
|
2097
|
+
return edgeStatsClient.get(path);
|
|
2098
|
+
}
|
|
2099
|
+
async function getCountries(lang = config.language) {
|
|
2100
|
+
const path = resolvePath(dataPaths.countries, { lang });
|
|
2101
|
+
return edgeStatsClient.get(path);
|
|
2102
|
+
}
|
|
2103
|
+
async function getGlossary(lang = config.language) {
|
|
2104
|
+
const path = resolvePath(dataPaths.glossary, { lang });
|
|
2105
|
+
return edgeStatsClient.get(path);
|
|
2106
|
+
}
|
|
2107
|
+
async function getFranchises(lang = config.language) {
|
|
2108
|
+
const path = resolvePath(dataPaths.franchises, { lang });
|
|
2109
|
+
return edgeStatsClient.get(path);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// src/api/edge-stats/season-game.ts
|
|
2113
|
+
var season_game_exports = {};
|
|
2114
|
+
__export(season_game_exports, {
|
|
2115
|
+
getDraft: () => getDraft,
|
|
2116
|
+
getGames: () => getGames,
|
|
2117
|
+
getSeasons: () => getSeasons,
|
|
2118
|
+
getShiftChart: () => getShiftChart
|
|
2119
|
+
});
|
|
2120
|
+
async function getSeasons(lang = config.language) {
|
|
2121
|
+
const path = resolvePath(dataPaths.season, { lang });
|
|
2122
|
+
return edgeStatsClient.get(path);
|
|
2123
|
+
}
|
|
2124
|
+
async function getGames(params = {}, lang = config.language) {
|
|
2125
|
+
const path = resolvePath(dataPaths.game, { lang });
|
|
2126
|
+
return edgeStatsClient.get(path, params);
|
|
2127
|
+
}
|
|
2128
|
+
async function getShiftChart(gameId, lang = config.language) {
|
|
2129
|
+
const path = resolvePath(dataPaths.shiftCharts, { lang });
|
|
2130
|
+
const cayenneExp = `gameId=${gameId}`;
|
|
2131
|
+
return edgeStatsClient.get(path, {
|
|
2132
|
+
cayenneExp
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
async function getDraft(lang = config.language) {
|
|
2136
|
+
const path = resolvePath(dataPaths.draft, { lang });
|
|
2137
|
+
return edgeStatsClient.get(path);
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
// src/api/edge-stats/skaters.ts
|
|
2141
|
+
var skaters_exports2 = {};
|
|
2142
|
+
__export(skaters_exports2, {
|
|
2143
|
+
getLeaders: () => getLeaders2,
|
|
2144
|
+
getMilestones: () => getMilestones2,
|
|
2145
|
+
getPlayerInfo: () => getPlayerInfo,
|
|
2146
|
+
getStats: () => getStats2,
|
|
2147
|
+
getStatsWithBuilder: () => getStatsWithBuilder2,
|
|
2148
|
+
getStatsWithFilters: () => getStatsWithFilters2,
|
|
2149
|
+
getStatsWithParams: () => getStatsWithParams2
|
|
2150
|
+
});
|
|
2151
|
+
async function getPlayerInfo(params = {}, lang = config.language) {
|
|
2152
|
+
const path = resolvePath(dataPaths.skater.players, { lang });
|
|
2153
|
+
return edgeStatsClient.get(path, params);
|
|
2154
|
+
}
|
|
2155
|
+
async function getLeaders2(statCategory, params = {}, lang = config.language) {
|
|
2156
|
+
const path = resolvePath(dataPaths.skater.leaders[statCategory], { lang });
|
|
2157
|
+
return edgeStatsClient.get(path, params);
|
|
2158
|
+
}
|
|
2159
|
+
async function getMilestones2(lang = config.language) {
|
|
2160
|
+
const path = resolvePath(dataPaths.skater.milestones, { lang });
|
|
2161
|
+
return edgeStatsClient.get(path);
|
|
2162
|
+
}
|
|
2163
|
+
async function getStats2(report = "summary", params = {}, lang = config.language) {
|
|
2164
|
+
const path = resolvePath(dataPaths.skater.report, { lang, report });
|
|
2165
|
+
return edgeStatsClient.get(
|
|
2166
|
+
path,
|
|
2167
|
+
reportParams(params)
|
|
2168
|
+
);
|
|
2169
|
+
}
|
|
2170
|
+
async function getStatsWithParams2(report, params, lang = config.language) {
|
|
2171
|
+
return getStats2(report, params, lang);
|
|
2172
|
+
}
|
|
2173
|
+
async function getStatsWithBuilder2(report, buildQuery, lang = config.language) {
|
|
2174
|
+
return getStats2(report, buildQuery(new CayenneQueryBuilder()), lang);
|
|
2175
|
+
}
|
|
2176
|
+
async function getStatsWithFilters2(report, filters, sorting, pagination, lang = config.language) {
|
|
2177
|
+
return getStats2(
|
|
2178
|
+
report,
|
|
2179
|
+
filterParams(filters, sorting, pagination),
|
|
2180
|
+
lang
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
// src/api/edge-stats/teams.ts
|
|
2185
|
+
var teams_exports2 = {};
|
|
2186
|
+
__export(teams_exports2, {
|
|
2187
|
+
getAll: () => getAll,
|
|
2188
|
+
getById: () => getById,
|
|
2189
|
+
getStats: () => getStats3,
|
|
2190
|
+
getStatsWithBuilder: () => getStatsWithBuilder3,
|
|
2191
|
+
getStatsWithFilters: () => getStatsWithFilters3,
|
|
2192
|
+
getStatsWithParams: () => getStatsWithParams3
|
|
2193
|
+
});
|
|
2194
|
+
async function getAll(params = {}, lang = config.language) {
|
|
2195
|
+
const path = resolvePath(dataPaths.team.all, { lang });
|
|
2196
|
+
return edgeStatsClient.get(path, params);
|
|
2197
|
+
}
|
|
2198
|
+
async function getById(teamId, params = {}, lang = config.language) {
|
|
2199
|
+
const path = resolvePath(dataPaths.team.byId, { lang, teamId });
|
|
2200
|
+
return edgeStatsClient.get(path, params);
|
|
2201
|
+
}
|
|
2202
|
+
async function getStats3(report = "summary", params = {}, lang = config.language) {
|
|
2203
|
+
const path = resolvePath(dataPaths.team.report, { lang, report });
|
|
2204
|
+
return edgeStatsClient.get(
|
|
2205
|
+
path,
|
|
2206
|
+
reportParams(params)
|
|
2207
|
+
);
|
|
2208
|
+
}
|
|
2209
|
+
async function getStatsWithParams3(report, params, lang = config.language) {
|
|
2210
|
+
return getStats3(report, params, lang);
|
|
2211
|
+
}
|
|
2212
|
+
async function getStatsWithBuilder3(report, buildQuery, lang = config.language) {
|
|
2213
|
+
return getStats3(report, buildQuery(new CayenneQueryBuilder()), lang);
|
|
2214
|
+
}
|
|
2215
|
+
async function getStatsWithFilters3(report, filters, sorting, pagination, lang = config.language) {
|
|
2216
|
+
return getStats3(
|
|
2217
|
+
report,
|
|
2218
|
+
filterParams(filters, sorting, pagination),
|
|
2219
|
+
lang
|
|
2220
|
+
);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
1784
2223
|
// src/api/gamecenter/index.ts
|
|
1785
2224
|
var gamecenter_exports = {};
|
|
1786
2225
|
__export(gamecenter_exports, {
|
|
1787
2226
|
draft: () => draft_exports,
|
|
1788
2227
|
game: () => game_exports,
|
|
1789
|
-
misc: () =>
|
|
2228
|
+
misc: () => misc_exports2,
|
|
1790
2229
|
player: () => player_exports,
|
|
1791
2230
|
score: () => score,
|
|
1792
2231
|
scoreboard: () => scoreboard,
|
|
@@ -1956,7 +2395,7 @@ function rankings(year) {
|
|
|
1956
2395
|
goaliesIntl: "4"
|
|
1957
2396
|
};
|
|
1958
2397
|
const getRankings = async (type2) => {
|
|
1959
|
-
const parsedYear = Year(year ??
|
|
2398
|
+
const parsedYear = Year(year ?? getCurrentNHLYear());
|
|
1960
2399
|
if (isParseError(parsedYear)) {
|
|
1961
2400
|
return {
|
|
1962
2401
|
success: false,
|
|
@@ -2157,7 +2596,7 @@ async function pptReplayEvent(gameId, eventId) {
|
|
|
2157
2596
|
return nhlClient.get(path);
|
|
2158
2597
|
}
|
|
2159
2598
|
async function schedule(date) {
|
|
2160
|
-
const parsedDate = NHLDate(date ??
|
|
2599
|
+
const parsedDate = NHLDate(date ?? getCurrentNHLDate());
|
|
2161
2600
|
if (isParseError(parsedDate)) {
|
|
2162
2601
|
return {
|
|
2163
2602
|
success: false,
|
|
@@ -2183,7 +2622,7 @@ async function scheduleCalendar(date) {
|
|
|
2183
2622
|
return nhlClient.get(path);
|
|
2184
2623
|
}
|
|
2185
2624
|
async function playoffBracket(year) {
|
|
2186
|
-
const parsedYear = Year(year ??
|
|
2625
|
+
const parsedYear = Year(year ?? getCurrentNHLYear());
|
|
2187
2626
|
if (isParseError(parsedYear)) {
|
|
2188
2627
|
return {
|
|
2189
2628
|
success: false,
|
|
@@ -2229,7 +2668,7 @@ async function whereToWatch() {
|
|
|
2229
2668
|
return nhlClient.get(path);
|
|
2230
2669
|
}
|
|
2231
2670
|
async function networkTVSchedule(date) {
|
|
2232
|
-
const parsedDate = NHLDate(date ??
|
|
2671
|
+
const parsedDate = NHLDate(date ?? getCurrentNHLDate());
|
|
2233
2672
|
if (isParseError(parsedDate)) {
|
|
2234
2673
|
return {
|
|
2235
2674
|
success: false,
|
|
@@ -2243,8 +2682,8 @@ async function networkTVSchedule(date) {
|
|
|
2243
2682
|
}
|
|
2244
2683
|
|
|
2245
2684
|
// src/api/gamecenter/misc.ts
|
|
2246
|
-
var
|
|
2247
|
-
__export(
|
|
2685
|
+
var misc_exports2 = {};
|
|
2686
|
+
__export(misc_exports2, {
|
|
2248
2687
|
location: () => location,
|
|
2249
2688
|
meta: () => meta,
|
|
2250
2689
|
partnerGame: () => partnerGame,
|
|
@@ -2400,7 +2839,7 @@ async function statsLeadersGoalies(season, gameType) {
|
|
|
2400
2839
|
|
|
2401
2840
|
// src/api/gamecenter/score.ts
|
|
2402
2841
|
async function score(date) {
|
|
2403
|
-
const parsed = NHLDate(date ??
|
|
2842
|
+
const parsed = NHLDate(date ?? getCurrentNHLDate());
|
|
2404
2843
|
if (isParseError(parsed)) {
|
|
2405
2844
|
return {
|
|
2406
2845
|
success: false,
|
|
@@ -2523,7 +2962,7 @@ async function statsSeason(team) {
|
|
|
2523
2962
|
return nhlClient.get(path);
|
|
2524
2963
|
}
|
|
2525
2964
|
async function standings(date) {
|
|
2526
|
-
const parsed = NHLDate(date ??
|
|
2965
|
+
const parsed = NHLDate(date ?? getCurrentNHLDate());
|
|
2527
2966
|
if (isParseError(parsed)) {
|
|
2528
2967
|
return {
|
|
2529
2968
|
success: false,
|
|
@@ -2583,11 +3022,76 @@ var schedule2 = {
|
|
|
2583
3022
|
month: scheduleMonth
|
|
2584
3023
|
};
|
|
2585
3024
|
|
|
3025
|
+
// src/api/video.ts
|
|
3026
|
+
var video_exports = {};
|
|
3027
|
+
__export(video_exports, {
|
|
3028
|
+
metadata: () => metadata
|
|
3029
|
+
});
|
|
3030
|
+
var ACCOUNT_ID = "6415718365001";
|
|
3031
|
+
var POLICY_KEY = "BCpkADawqM3l37Vq8trLJ95vVwxubXYZXYglAopEZXQTHTWX3YdalyF9xmkuknxjBgiMYwt8VZ_OZ1jAjYxz_yzuNh_cjC3uOaMspVTD-hZfNUHtNnBnhVD0Gmsih8TBF8QlQFXiCQM3W_u4ydJ1qK2Rx8ZutCUg3PHb7Q";
|
|
3032
|
+
var brightcoveClient = createNHLClient({
|
|
3033
|
+
baseUrl: `https://edge.api.brightcove.com/playback/v1/accounts/${ACCOUNT_ID}`,
|
|
3034
|
+
headers: { Accept: `application/json;pk=${POLICY_KEY}` }
|
|
3035
|
+
});
|
|
3036
|
+
async function metadata(videoId) {
|
|
3037
|
+
const result = await brightcoveClient.get(
|
|
3038
|
+
`videos/${encodeURIComponent(String(videoId))}`
|
|
3039
|
+
);
|
|
3040
|
+
if (!result.success) return result;
|
|
3041
|
+
const video = result.data;
|
|
3042
|
+
const mp4 = video.sources.filter((s) => s.container === "MP4" && s.src?.startsWith("https:")).sort((a, b) => (b.width ?? 0) - (a.width ?? 0));
|
|
3043
|
+
return {
|
|
3044
|
+
success: true,
|
|
3045
|
+
data: {
|
|
3046
|
+
id: video.id,
|
|
3047
|
+
title: video.name,
|
|
3048
|
+
description: video.description,
|
|
3049
|
+
longDescription: video.long_description,
|
|
3050
|
+
duration: video.duration,
|
|
3051
|
+
publishedAt: video.published_at,
|
|
3052
|
+
poster: video.poster,
|
|
3053
|
+
thumbnail: video.thumbnail,
|
|
3054
|
+
url: mp4[0]?.src ?? null,
|
|
3055
|
+
sources: video.sources.map((s) => ({
|
|
3056
|
+
src: s.src,
|
|
3057
|
+
...s.type && { type: s.type },
|
|
3058
|
+
...s.container && { container: s.container },
|
|
3059
|
+
...s.codec && { codec: s.codec },
|
|
3060
|
+
...s.width && { width: s.width },
|
|
3061
|
+
...s.height && { height: s.height }
|
|
3062
|
+
})),
|
|
3063
|
+
tags: video.tags
|
|
3064
|
+
}
|
|
3065
|
+
};
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
exports.APIError = APIError;
|
|
3069
|
+
exports.BASE_URLS = BASE_URLS;
|
|
3070
|
+
exports.CayenneQueryBuilder = CayenneQueryBuilder;
|
|
3071
|
+
exports.ClientError = ClientError;
|
|
2586
3072
|
exports.EDGE = EDGE;
|
|
3073
|
+
exports.ErrorCategory = ErrorCategory;
|
|
3074
|
+
exports.ErrorHandler = ErrorHandler;
|
|
3075
|
+
exports.ErrorLogLevel = LogLevel;
|
|
2587
3076
|
exports.NHL = nhl_exports;
|
|
3077
|
+
exports.NHLClient = NHLClient;
|
|
3078
|
+
exports.NHLError = NHLError;
|
|
3079
|
+
exports.NetworkError = NetworkError;
|
|
3080
|
+
exports.NotFoundError = NotFoundError;
|
|
3081
|
+
exports.ParseError = ParseError;
|
|
3082
|
+
exports.RateLimitError = RateLimitError;
|
|
3083
|
+
exports.ServerError = ServerError;
|
|
3084
|
+
exports.ValidationError = ValidationError;
|
|
2588
3085
|
exports.adv = edge_adv_exports2;
|
|
2589
|
-
exports.
|
|
3086
|
+
exports.buildCayenneExp = buildCayenneExp;
|
|
3087
|
+
exports.config = config;
|
|
3088
|
+
exports.createCayenneQuery = createCayenneQuery;
|
|
3089
|
+
exports.createNHLClient = createNHLClient;
|
|
2590
3090
|
exports.gc = gamecenter_exports;
|
|
2591
|
-
exports.
|
|
3091
|
+
exports.logConfig = logConfig;
|
|
3092
|
+
exports.logger = logger;
|
|
3093
|
+
exports.stats = edge_stats_exports;
|
|
3094
|
+
exports.video = video_exports;
|
|
3095
|
+
exports.writeLog = writeLog;
|
|
2592
3096
|
//# sourceMappingURL=index.cjs.map
|
|
2593
3097
|
//# sourceMappingURL=index.cjs.map
|