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.
@@ -0,0 +1,462 @@
1
+ /**
2
+ * Cayenne Expression Query Builder
3
+ * A utility for constructing cayenneExp filter strings for the NHL Stats API
4
+ * Cayenne expressions are filter strings used in the NHL Stats API to filter results
5
+ *
6
+ * Syntax: condition1=value1 and condition2=value2
7
+ * Example: seasonId=20232024 and gameTypeId=2
8
+ */
9
+ /**
10
+ * Represents a single condition in a Cayenne expression
11
+ */
12
+ interface CayenneCondition {
13
+ field: string;
14
+ operator: '=' | '!=' | '<' | '>' | '<=' | '>=' | 'in' | 'like';
15
+ value: string | number | (string | number)[];
16
+ logicalOp?: 'and' | 'or';
17
+ }
18
+ /**
19
+ * Represents a grouped set of conditions
20
+ */
21
+ interface CayenneGroup {
22
+ type: 'group';
23
+ conditions: (CayenneCondition | CayenneGroup)[];
24
+ logicalOp?: 'and' | 'or';
25
+ }
26
+ /**
27
+ * Type for items that can be in the conditions array
28
+ */
29
+ type CayenneExpression = CayenneCondition | CayenneGroup;
30
+ /**
31
+ * Cayenne Expression Query Builder
32
+ * Provides a fluent API for building complex filter strings
33
+ */
34
+ declare class CayenneQueryBuilder {
35
+ private conditions;
36
+ private currentLogicalOp;
37
+ private groupStack;
38
+ /**
39
+ * Start a new logical group
40
+ * All subsequent conditions will be added to this group until endGroup() is called
41
+ * @returns This builder instance for chaining
42
+ * @example
43
+ * builder
44
+ * .equals('field1', 'value1')
45
+ * .group()
46
+ * .equals('field2', 'value2')
47
+ * .or()
48
+ * .equals('field3', 'value3')
49
+ * .endGroup()
50
+ * // Generates: "field1=value1 and (field2=value2 or field3=value3)"
51
+ */
52
+ group(): this;
53
+ /**
54
+ * End the current logical group
55
+ * @returns This builder instance for chaining
56
+ * @throws Error if there's no open group
57
+ */
58
+ endGroup(): this;
59
+ /**
60
+ * Set the logical operator to AND for subsequent conditions
61
+ * @returns This builder instance for chaining
62
+ */
63
+ and(): this;
64
+ /**
65
+ * Set the logical operator to OR for subsequent conditions
66
+ * @returns This builder instance for chaining
67
+ */
68
+ or(): this;
69
+ /**
70
+ * Add an equality condition
71
+ * @param field - The field name to filter on
72
+ * @param value - The value to match
73
+ * @returns This builder instance for chaining
74
+ */
75
+ equals(field: string, value: string | number): this;
76
+ /**
77
+ * Add a not-equal condition
78
+ * @param field - The field name to filter on
79
+ * @param value - The value to exclude
80
+ * @returns This builder instance for chaining
81
+ */
82
+ notEquals(field: string, value: string | number): this;
83
+ /**
84
+ * Add a less-than condition
85
+ * @param field - The field name to filter on
86
+ * @param value - The upper bound (exclusive)
87
+ * @returns This builder instance for chaining
88
+ */
89
+ lessThan(field: string, value: number): this;
90
+ /**
91
+ * Add a greater-than condition
92
+ * @param field - The field name to filter on
93
+ * @param value - The lower bound (exclusive)
94
+ * @returns This builder instance for chaining
95
+ */
96
+ greaterThan(field: string, value: number): this;
97
+ /**
98
+ * Add a less-than-or-equal condition
99
+ * @param field - The field name to filter on
100
+ * @param value - The upper bound (inclusive)
101
+ * @returns This builder instance for chaining
102
+ */
103
+ lessThanOrEqual(field: string, value: number): this;
104
+ /**
105
+ * Add a greater-than-or-equal condition
106
+ * @param field - The field name to filter on
107
+ * @param value - The lower bound (inclusive)
108
+ * @returns This builder instance for chaining
109
+ */
110
+ greaterThanOrEqual(field: string, value: number): this;
111
+ /**
112
+ * Add an IN condition to match multiple values
113
+ * @param field - The field name to filter on
114
+ * @param values - Array of values to match against
115
+ * @returns This builder instance for chaining
116
+ * @example
117
+ * builder.in('playerId', [8476791, 8477933, 8478402])
118
+ * // Generates: "playerId in (8476791, 8477933, 8478402)"
119
+ */
120
+ in(field: string, values: (string | number)[]): this;
121
+ /**
122
+ * Add a LIKE condition for pattern matching
123
+ * @param field - The field name to filter on
124
+ * @param pattern - The pattern to match (supports % for wildcards)
125
+ * @returns This builder instance for chaining
126
+ * @example
127
+ * builder.like('playerName', '%McDavid%')
128
+ * // Generates: "playerName like '%McDavid%'"
129
+ */
130
+ like(field: string, pattern: string): this;
131
+ /**
132
+ * Add a raw condition string
133
+ * Useful for complex expressions or unsupported operators
134
+ * @param condition - The raw condition string (e.g., "playerId=8476791")
135
+ * @returns This builder instance for chaining
136
+ */
137
+ raw(condition: string): this;
138
+ /**
139
+ * Build the cayenneExp string
140
+ * @returns The formatted cayenneExp string ready for API consumption
141
+ */
142
+ build(): string;
143
+ /**
144
+ * Clear all conditions
145
+ * @returns This builder instance for chaining
146
+ */
147
+ clear(): this;
148
+ /**
149
+ * Get the number of conditions currently in the builder
150
+ */
151
+ count(): number;
152
+ }
153
+ /**
154
+ * Create a new CayenneQueryBuilder instance
155
+ * @returns A new builder instance
156
+ */
157
+ declare function createCayenneQuery(): CayenneQueryBuilder;
158
+ /**
159
+ * Quick helper to build a simple cayenneExp from an object
160
+ * @param filters - An object where keys are field names and values are expected values
161
+ * @returns The formatted cayenneExp string
162
+ * @example
163
+ * buildCayenneExp({ seasonId: '20232024', gameTypeId: 2 })
164
+ * // Returns: "seasonId=20232024 and gameTypeId=2"
165
+ */
166
+ declare function buildCayenneExp(filters: Record<string, string | number>): string;
167
+
168
+ /**
169
+ * All valid NHL team abbreviations and their corresponding team IDs.
170
+ */
171
+ declare const TeamsEnum: {
172
+ /** Anaheim Ducks */
173
+ readonly ANA: 24;
174
+ /** Boston Bruins */
175
+ readonly BOS: 6;
176
+ /** Buffalo Sabres */
177
+ readonly BUF: 7;
178
+ /** Calgary Flames */
179
+ readonly CGY: 20;
180
+ /** Carolina Hurricanes */
181
+ readonly CAR: 12;
182
+ /** Chicago Blackhawks */
183
+ readonly CHI: 16;
184
+ /** Colorado Avalanche */
185
+ readonly COL: 21;
186
+ /** Columbus Blue Jackets */
187
+ readonly CBJ: 29;
188
+ /** Dallas Stars */
189
+ readonly DAL: 25;
190
+ /** Detroit Red Wings */
191
+ readonly DET: 17;
192
+ /** Edmonton Oilers */
193
+ readonly EDM: 22;
194
+ /** Florida Panthers */
195
+ readonly FLA: 13;
196
+ /** Los Angeles Kings */
197
+ readonly LAK: 26;
198
+ /** Minnesota Wild*/
199
+ readonly MIN: 30;
200
+ /** Montreal Canadiens */
201
+ readonly MTL: 8;
202
+ /** New Jersey Devils */
203
+ readonly NJD: 1;
204
+ /** Nashville Predators */
205
+ readonly NSH: 18;
206
+ /** New York Islanders */
207
+ readonly NYI: 2;
208
+ /** New York Rangers */
209
+ readonly NYR: 3;
210
+ /** Ottawa Senators */
211
+ readonly OTT: 9;
212
+ /** Philadelphia Flyers */
213
+ readonly PHI: 4;
214
+ /** Pittsburgh Penguins */
215
+ readonly PIT: 5;
216
+ /** San Jose Sharks */
217
+ readonly SJS: 28;
218
+ /** Seattle Kraken */
219
+ readonly SEA: 55;
220
+ /** St. Louis Blues */
221
+ readonly STL: 19;
222
+ /** Tampa Bay Lightning */
223
+ readonly TBL: 14;
224
+ /** Toronto Maple Leafs */
225
+ readonly TOR: 10;
226
+ /** Utah Hockey Club */
227
+ readonly UTA: 59;
228
+ /** Vancouver Canucks */
229
+ readonly VAN: 23;
230
+ /** Vegas Golden Knights */
231
+ readonly VGK: 54;
232
+ /** Winnipeg Jets */
233
+ readonly WPG: 52;
234
+ /** Washington Capitals */
235
+ readonly WSH: 15;
236
+ };
237
+ declare const TeamsReverseEnum: Record<(typeof TeamsEnum)[keyof typeof TeamsEnum], keyof typeof TeamsEnum>;
238
+ /**
239
+ * All inactive NHL teams and their corresponding team IDs.
240
+ */
241
+ declare const InactiveTeamsEnum: {
242
+ /** Atlanta Flames (not active) */
243
+ readonly AFM: 47;
244
+ /** Arizona Coyotes (not active) */
245
+ readonly ARI: 53;
246
+ /** Atlanta Thrashers (not active) */
247
+ readonly ATL: 11;
248
+ /** Brooklyn Americans - (not active) */
249
+ readonly BRK: 51;
250
+ /** California Golden Seals (aka Bay Area Seals) - (not active) */
251
+ readonly CGS: 56;
252
+ /** Cleveland Barons - (not active) */
253
+ readonly CLE: 49;
254
+ /** Colorado Rockies - (not active) */
255
+ readonly CLR: 35;
256
+ /** Detroit Cougars - (not active) */
257
+ readonly DCG: 40;
258
+ /** Detroit Falcons - (not active) */
259
+ readonly DFL: 50;
260
+ /** Hamilton Tigers - (not active) */
261
+ readonly HAM: 37;
262
+ /** Hartford Whalers - (not active) */
263
+ readonly HFD: 34;
264
+ /** Kansas City Scouts - (not active) */
265
+ readonly KCS: 48;
266
+ /** Montreal Maroons - (not active) */
267
+ readonly MMR: 43;
268
+ /** Minnesota North Stars - (not active) */
269
+ readonly MNS: 31;
270
+ /** Montreal Wanderers - (not active) */
271
+ readonly MWN: 41;
272
+ /** New York Americans - (not active) */
273
+ readonly NYA: 44;
274
+ /** California Seals (aka Oakland Seals) - (not active) */
275
+ readonly OAK: 46;
276
+ /** Phoenix Coyotes - (not active) */
277
+ readonly PHX: 27;
278
+ /** Pittsburgh Pirates - (not active) */
279
+ readonly PIR: 38;
280
+ /** Quebec Bulldogs - (not active) */
281
+ readonly QBD: 42;
282
+ /** Philadelphia Quakers - (not active) */
283
+ readonly QUA: 39;
284
+ /** Quebec Nordiques - (not active) */
285
+ readonly QUE: 32;
286
+ /** Ottawa Senators (original franchise) - (not active) */
287
+ readonly SEN: 36;
288
+ /** St. Louis Eagles - (not active) */
289
+ readonly SLE: 45;
290
+ /** Toronto Hockey Club (aka Toronto Arenas) - (not active) */
291
+ readonly TAN: 57;
292
+ /** Toronto St. Patricks - (not active) */
293
+ readonly TSP: 58;
294
+ /** Winnipeg Jets (original franchise) - (not active) */
295
+ readonly WIN: 33;
296
+ };
297
+ declare const InactiveTeamsReverseEnum: Record<(typeof InactiveTeamsEnum)[keyof typeof InactiveTeamsEnum], keyof typeof InactiveTeamsEnum>;
298
+ /**
299
+ * All valid NHL seasons in yyyyYYYY format.
300
+ */
301
+ declare const SeasonsArray: readonly [19171918, 19181919, 19191920, 19201921, 19211922, 19221923, 19231924, 19241925, 19251926, 19261927, 19271928, 19281929, 19291930, 19301931, 19311932, 19321933, 19331934, 19341935, 19351936, 19361937, 19371938, 19381939, 19391940, 19401941, 19411942, 19421943, 19431944, 19441945, 19451946, 19461947, 19471948, 19481949, 19491950, 19501951, 19511952, 19521953, 19531954, 19541955, 19551956, 19561957, 19571958, 19581959, 19591960, 19601961, 19611962, 19621963, 19631964, 19641965, 19651966, 19661967, 19671968, 19681969, 19691970, 19701971, 19711972, 19721973, 19731974, 19741975, 19751976, 19761977, 19771978, 19781979, 19791980, 19801981, 19811982, 19821983, 19831984, 19841985, 19851986, 19861987, 19871988, 19881989, 19891990, 19901991, 19911992, 19921993, 19931994, 19941995, 19951996, 19961997, 19971998, 19981999, 19992000, 20002001, 20012002, 20022003, 20032004, 20052006, 20062007, 20072008, 20082009, 20092010, 20102011, 20112012, 20122013, 20132014, 20142015, 20152016, 20162017, 20172018, 20182019, 20192020, 20202021, 20212022, 20222023, 20232024, 20242025, 20252026];
302
+ /**
303
+ * All valid NHL playoff series letters.
304
+ */
305
+ declare const SeriesLetterEnum: {
306
+ /** Atlantic Division Round 1: D1 vs WC# */
307
+ readonly A: "A";
308
+ /** Atlantic Division Round 1: D2 vs D3 */
309
+ readonly B: "B";
310
+ /** Metropolitan Division Round 1: D1 vs WC# */
311
+ readonly C: "C";
312
+ /** Metropolitan Division Round 1: D2 vs D3 */
313
+ readonly D: "D";
314
+ /** Central Division Round 1: D1 vs WC# */
315
+ readonly E: "E";
316
+ /** Central Division Round 1: D2 vs D3 */
317
+ readonly F: "F";
318
+ /** Pacific Division Round 1: D1 vs WC# */
319
+ readonly G: "G";
320
+ /** Pacific Division Round 1: D2 vs D3 */
321
+ readonly H: "H";
322
+ /** Atlantic Division Round 2: Aw vs Bw */
323
+ readonly I: "I";
324
+ /** Metropolitan Division Round 2: Cw vs Dw */
325
+ readonly J: "J";
326
+ /** Central Division Round 2: Ew vs Fw */
327
+ readonly K: "K";
328
+ /** Pacific Division Round 2: Gw vs Hw */
329
+ readonly L: "L";
330
+ /** Eastern Conference Finals */
331
+ readonly M: "M";
332
+ /** Western Conference Finals*/
333
+ readonly N: "N";
334
+ /** Stanley Cup Finals */
335
+ readonly O: "O";
336
+ };
337
+ /**
338
+ * All valid NHL playoff series letters grouped by round.
339
+ */
340
+ declare const SeriesLetterByRound: {
341
+ R1: string[];
342
+ R2: string[];
343
+ CF: string[];
344
+ SCF: string[];
345
+ };
346
+ /**
347
+ * All valid NHL playoff series letters mapped to human-readable names.
348
+ */
349
+ declare const PlayoffSeriesEnum: {
350
+ Atlantic_R1_D1_vs_WC: string;
351
+ Atlantic_R1_D2_vs_D3: string;
352
+ Metropolitan_R1_D1_vs_WC: string;
353
+ Metropolitan_R1_D2_vs_D3: string;
354
+ Central_R1_D1_vs_WC: string;
355
+ Central_R1_D2_vs_D3: string;
356
+ Pacific_R1_D1_vs_WC: string;
357
+ Pacific_R1_D2_vs_D3: string;
358
+ Atlantic_R2_Aw_vs_Bw: string;
359
+ Metropolitan_R2_Cw_vs_Dw: string;
360
+ Central_R2_Ew_vs_Fw: string;
361
+ Pacific_R2_Gw_vs_Hw: string;
362
+ Eastern_Conference_Finals: string;
363
+ Western_Conference_Finals: string;
364
+ Stanley_Cup_Finals: string;
365
+ };
366
+ /**
367
+ * All valid NHL game states.
368
+ */
369
+ declare const GameStateEnum: {
370
+ /** Future */
371
+ readonly FUT: "FUT";
372
+ /** Live */
373
+ readonly LIV: "LIV";
374
+ /** Finished */
375
+ readonly FIN: "FIN";
376
+ };
377
+ /**
378
+ * All valid NHL period types.
379
+ */
380
+ declare const PeriodTypeEnum: {
381
+ /** Regulation */
382
+ readonly REG: "REG";
383
+ /** Overtime */
384
+ readonly OT: "OT";
385
+ /** Shootout */
386
+ readonly SO: "SO";
387
+ };
388
+ /**
389
+ * All valid NHL game types.
390
+ */
391
+ declare const GameTypeEnum: {
392
+ /** Pre-season */
393
+ readonly PRE: 1;
394
+ /** Regular season */
395
+ readonly REG: 2;
396
+ /** Post-season (aka playoffs) */
397
+ readonly POST: 3;
398
+ /** All-Star Game (unconfirmed) */
399
+ readonly ASG: 4;
400
+ /** International (unconfirmed) */
401
+ readonly INTL: 19;
402
+ };
403
+ /** */
404
+ declare const SEASON_RANGE: {
405
+ START: number;
406
+ END: number;
407
+ };
408
+ /** */
409
+ declare const START_SEASON: number;
410
+ /** */
411
+ declare const END_SEASON: number;
412
+ /** */
413
+ declare const YEAR_RANGE: {
414
+ START: number;
415
+ END: number;
416
+ };
417
+ /** */
418
+ declare const START_YEAR: number;
419
+ /** */
420
+ declare const END_YEAR: number;
421
+ /** */
422
+ declare const CURRENT: {
423
+ /** The season for today's date, so the default never goes stale. */
424
+ SEASON: number;
425
+ YEAR: number;
426
+ };
427
+ /** */
428
+ declare const PLAYER_ID_RANGE: {
429
+ readonly MIN: 8444000;
430
+ readonly MAX: 8489999;
431
+ };
432
+ /** */
433
+ declare const TEAM_ID_RANGE: {
434
+ readonly MIN: 1;
435
+ readonly MAX: 59;
436
+ };
437
+
438
+ declare const nhl_CURRENT: typeof CURRENT;
439
+ declare const nhl_END_SEASON: typeof END_SEASON;
440
+ declare const nhl_END_YEAR: typeof END_YEAR;
441
+ declare const nhl_GameStateEnum: typeof GameStateEnum;
442
+ declare const nhl_GameTypeEnum: typeof GameTypeEnum;
443
+ declare const nhl_InactiveTeamsEnum: typeof InactiveTeamsEnum;
444
+ declare const nhl_InactiveTeamsReverseEnum: typeof InactiveTeamsReverseEnum;
445
+ declare const nhl_PLAYER_ID_RANGE: typeof PLAYER_ID_RANGE;
446
+ declare const nhl_PeriodTypeEnum: typeof PeriodTypeEnum;
447
+ declare const nhl_PlayoffSeriesEnum: typeof PlayoffSeriesEnum;
448
+ declare const nhl_SEASON_RANGE: typeof SEASON_RANGE;
449
+ declare const nhl_START_SEASON: typeof START_SEASON;
450
+ declare const nhl_START_YEAR: typeof START_YEAR;
451
+ declare const nhl_SeasonsArray: typeof SeasonsArray;
452
+ declare const nhl_SeriesLetterByRound: typeof SeriesLetterByRound;
453
+ declare const nhl_SeriesLetterEnum: typeof SeriesLetterEnum;
454
+ declare const nhl_TEAM_ID_RANGE: typeof TEAM_ID_RANGE;
455
+ declare const nhl_TeamsEnum: typeof TeamsEnum;
456
+ declare const nhl_TeamsReverseEnum: typeof TeamsReverseEnum;
457
+ declare const nhl_YEAR_RANGE: typeof YEAR_RANGE;
458
+ declare namespace nhl {
459
+ export { nhl_CURRENT as CURRENT, nhl_END_SEASON as END_SEASON, nhl_END_YEAR as END_YEAR, nhl_GameStateEnum as GameStateEnum, nhl_GameTypeEnum as GameTypeEnum, nhl_InactiveTeamsEnum as InactiveTeamsEnum, nhl_InactiveTeamsReverseEnum as InactiveTeamsReverseEnum, nhl_PLAYER_ID_RANGE as PLAYER_ID_RANGE, nhl_PeriodTypeEnum as PeriodTypeEnum, nhl_PlayoffSeriesEnum as PlayoffSeriesEnum, nhl_SEASON_RANGE as SEASON_RANGE, nhl_START_SEASON as START_SEASON, nhl_START_YEAR as START_YEAR, nhl_SeasonsArray as SeasonsArray, nhl_SeriesLetterByRound as SeriesLetterByRound, nhl_SeriesLetterEnum as SeriesLetterEnum, nhl_TEAM_ID_RANGE as TEAM_ID_RANGE, nhl_TeamsEnum as TeamsEnum, nhl_TeamsReverseEnum as TeamsReverseEnum, nhl_YEAR_RANGE as YEAR_RANGE };
460
+ }
461
+
462
+ export { CayenneQueryBuilder as C, TeamsEnum as T, type CayenneCondition as a, buildCayenneExp as b, type CayenneExpression as c, type CayenneGroup as d, createCayenneQuery as e, nhl as n };