@mshowes/brackets-manager 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -0
  3. package/dist/base/getter.d.ts +272 -0
  4. package/dist/base/getter.d.ts.map +1 -0
  5. package/dist/base/getter.js +545 -0
  6. package/dist/base/getter.js.map +1 -0
  7. package/dist/base/stage/creator.d.ts +269 -0
  8. package/dist/base/stage/creator.d.ts.map +1 -0
  9. package/dist/base/stage/creator.js +735 -0
  10. package/dist/base/stage/creator.js.map +1 -0
  11. package/dist/base/updater.d.ts +121 -0
  12. package/dist/base/updater.d.ts.map +1 -0
  13. package/dist/base/updater.js +323 -0
  14. package/dist/base/updater.js.map +1 -0
  15. package/dist/create.d.ts +25 -0
  16. package/dist/create.d.ts.map +1 -0
  17. package/dist/create.js +55 -0
  18. package/dist/create.js.map +1 -0
  19. package/dist/delete.d.ts +33 -0
  20. package/dist/delete.d.ts.map +1 -0
  21. package/dist/delete.js +57 -0
  22. package/dist/delete.js.map +1 -0
  23. package/dist/find.d.ts +60 -0
  24. package/dist/find.d.ts.map +1 -0
  25. package/dist/find.js +196 -0
  26. package/dist/find.js.map +1 -0
  27. package/dist/get.d.ts +121 -0
  28. package/dist/get.d.ts.map +1 -0
  29. package/dist/get.js +420 -0
  30. package/dist/get.js.map +1 -0
  31. package/dist/helpers.d.ts +804 -0
  32. package/dist/helpers.d.ts.map +1 -0
  33. package/dist/helpers.js +1897 -0
  34. package/dist/helpers.js.map +1 -0
  35. package/dist/index.d.ts +11 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +21 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/manager.d.ts +60 -0
  40. package/dist/manager.d.ts.map +1 -0
  41. package/dist/manager.js +189 -0
  42. package/dist/manager.js.map +1 -0
  43. package/dist/ordering.d.ts +7 -0
  44. package/dist/ordering.d.ts.map +1 -0
  45. package/dist/ordering.js +147 -0
  46. package/dist/ordering.js.map +1 -0
  47. package/dist/reset.d.ts +27 -0
  48. package/dist/reset.d.ts.map +1 -0
  49. package/dist/reset.js +82 -0
  50. package/dist/reset.js.map +1 -0
  51. package/dist/types.d.ts +260 -0
  52. package/dist/types.d.ts.map +1 -0
  53. package/dist/types.js +3 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/update.d.ts +111 -0
  56. package/dist/update.d.ts.map +1 -0
  57. package/dist/update.js +265 -0
  58. package/dist/update.js.map +1 -0
  59. package/package.json +67 -0
@@ -0,0 +1,804 @@
1
+ import { GrandFinalType, Match, MatchGame, MatchResults, Participant, ParticipantResult, Result, RoundRobinMode, Seeding, SeedOrdering, Stage, StageType, Status, GroupType, Id, RankingItem, RankingFormula } from 'brackets-model';
2
+ import { Database, DeepPartial, Duel, FinalStandingsItem, IdMapping, Nullable, OmitId, ParitySplit, ParticipantSlot, Scores, Side } from './types';
3
+ /**
4
+ * Checks whether a value is defined (i.e. not null nor undefined).
5
+ *
6
+ * @param value The value to check.
7
+ */
8
+ export declare function isDefined<T>(value: undefined | null | T): value is T;
9
+ /**
10
+ * Splits an array of objects based on their values at a given key.
11
+ *
12
+ * @param objects The array to split.
13
+ * @param key The key of T.
14
+ */
15
+ export declare function splitBy<T extends Record<string, unknown>, K extends keyof T, U extends Record<K, string | number>>(objects: U[], key: K): U[][];
16
+ /**
17
+ * Splits an array in two parts: one with even indices and the other with odd indices.
18
+ *
19
+ * @param array The array to split.
20
+ */
21
+ export declare function splitByParity<T>(array: T[]): ParitySplit<T>;
22
+ /**
23
+ * Makes a list of rounds containing the matches of a round-robin group.
24
+ *
25
+ * @param participants The participants to distribute.
26
+ * @param mode The round-robin mode.
27
+ */
28
+ export declare function makeRoundRobinMatches<T>(participants: T[], mode?: RoundRobinMode): [T, T][][];
29
+ /**
30
+ * Distributes participants in rounds for a round-robin group.
31
+ *
32
+ * Conditions:
33
+ * - Each participant plays each other once.
34
+ * - Each participant plays once in each round.
35
+ *
36
+ * @param participants The participants to distribute.
37
+ */
38
+ export declare function makeRoundRobinDistribution<T>(participants: T[]): [T, T][][];
39
+ /**
40
+ * A helper to assert our generated round-robin is correct.
41
+ *
42
+ * @param input The input seeding.
43
+ * @param output The resulting distribution of seeds in groups.
44
+ */
45
+ export declare function assertRoundRobin(input: number[], output: [number, number][][]): void;
46
+ /**
47
+ * Distributes elements in groups of equal size.
48
+ *
49
+ * @param elements A list of elements to distribute in groups.
50
+ * @param groupCount The group count.
51
+ */
52
+ export declare function makeGroups<T>(elements: T[], groupCount: number): T[][];
53
+ /**
54
+ * Balances BYEs to prevents having BYE against BYE in matches.
55
+ *
56
+ * @param seeding The seeding of the stage.
57
+ * @param participantCount The number of participants in the stage.
58
+ */
59
+ export declare function balanceByes(seeding: Seeding, participantCount?: number): Seeding;
60
+ /**
61
+ * Normalizes IDs in a database.
62
+ *
63
+ * All IDs (and references to them) are remapped to consecutive IDs starting from 0.
64
+ *
65
+ * @param data Data to normalize.
66
+ */
67
+ export declare function normalizeIds(data: Database): Database;
68
+ /**
69
+ * Makes a mapping between old IDs and new normalized IDs.
70
+ *
71
+ * @param elements A list of elements with IDs.
72
+ */
73
+ export declare function makeNormalizedIdMapping(elements: {
74
+ id: Id;
75
+ }[]): IdMapping;
76
+ /**
77
+ * Apply a normalizing mapping to a participant.
78
+ *
79
+ * @param participant The participant.
80
+ * @param mapping The mapping of IDs.
81
+ */
82
+ export declare function normalizeParticipant(participant: ParticipantResult | null, mapping: IdMapping): ParticipantResult | null;
83
+ /**
84
+ * Sets the size of an array with a placeholder if the size is bigger.
85
+ *
86
+ * @param array The original array.
87
+ * @param length The new length.
88
+ * @param placeholder A placeholder to use to fill the empty space.
89
+ */
90
+ export declare function setArraySize<T>(array: T[], length: number, placeholder: T): T[];
91
+ /**
92
+ * Makes pairs with each element and its next one.
93
+ *
94
+ * @example [1, 2, 3, 4] --> [[1, 2], [3, 4]]
95
+ * @param array A list of elements.
96
+ */
97
+ export declare function makePairs<T>(array: T[]): [T, T][];
98
+ /**
99
+ * Ensures that a list of elements has an even size.
100
+ *
101
+ * @param array A list of elements.
102
+ */
103
+ export declare function ensureEvenSized<T>(array: T[]): void;
104
+ /**
105
+ * Ensures there are no duplicates in a list of elements.
106
+ *
107
+ * @param array A list of elements.
108
+ */
109
+ export declare function ensureNoDuplicates<T>(array: Nullable<T>[]): void;
110
+ /**
111
+ * Ensures that two lists of elements have the same size.
112
+ *
113
+ * @param left The first list of elements.
114
+ * @param right The second list of elements.
115
+ */
116
+ export declare function ensureEquallySized<T>(left: T[], right: T[]): void;
117
+ /**
118
+ * Fixes the seeding by enlarging it if it's not complete.
119
+ *
120
+ * @param seeding The seeding of the stage.
121
+ * @param participantCount The number of participants in the stage.
122
+ */
123
+ export declare function fixSeeding(seeding: Seeding, participantCount: number): Seeding;
124
+ /**
125
+ * Indicates whether a number is a power of two.
126
+ *
127
+ * @param number The number to test.
128
+ */
129
+ export declare function isPowerOfTwo(number: number): boolean;
130
+ /**
131
+ * Ensures that the participant count is valid.
132
+ *
133
+ * @param stageType Type of the stage to test.
134
+ * @param participantCount The number to test.
135
+ */
136
+ export declare function ensureValidSize(stageType: StageType, participantCount: number): void;
137
+ /**
138
+ * Ensures that a match scores aren't tied.
139
+ *
140
+ * @param scores Two numbers which are scores.
141
+ */
142
+ export declare function ensureNotTied(scores: [number, number]): void;
143
+ /**
144
+ * Converts a TBD to a BYE.
145
+ *
146
+ * @param slot The slot to convert.
147
+ */
148
+ export declare function convertTBDtoBYE(slot: ParticipantSlot): ParticipantSlot;
149
+ /**
150
+ * Converts a participant slot to a result stored in storage.
151
+ *
152
+ * @param slot A participant slot.
153
+ */
154
+ export declare function toResult(slot: ParticipantSlot): ParticipantSlot;
155
+ /**
156
+ * Converts a participant slot to a result stored in storage, with the position the participant is coming from.
157
+ *
158
+ * @param slot A participant slot.
159
+ */
160
+ export declare function toResultWithPosition(slot: ParticipantSlot): ParticipantSlot;
161
+ /**
162
+ * Returns the winner of a match.
163
+ *
164
+ * @param match The match.
165
+ */
166
+ export declare function getWinner(match: MatchResults): ParticipantSlot;
167
+ /**
168
+ * Returns the loser of a match.
169
+ *
170
+ * @param match The match.
171
+ */
172
+ export declare function getLoser(match: MatchResults): ParticipantSlot;
173
+ /**
174
+ * Returns the pre-computed winner for a match because of BYEs.
175
+ *
176
+ * @param opponents Two opponents.
177
+ */
178
+ export declare function byeWinner(opponents: Duel): ParticipantSlot;
179
+ /**
180
+ * Returns the pre-computed winner for a match because of BYEs in a lower bracket.
181
+ *
182
+ * @param opponents Two opponents.
183
+ */
184
+ export declare function byeWinnerToGrandFinal(opponents: Duel): ParticipantSlot;
185
+ /**
186
+ * Returns the pre-computed loser for a match because of BYEs.
187
+ *
188
+ * Only used for loser bracket.
189
+ *
190
+ * @param opponents Two opponents.
191
+ * @param index The index of the duel in the round.
192
+ */
193
+ export declare function byeLoser(opponents: Duel, index: number): ParticipantSlot;
194
+ /**
195
+ * Returns the winner side or `null` if no winner.
196
+ *
197
+ * @param match A match's results.
198
+ */
199
+ export declare function getMatchResult(match: MatchResults): Side | null;
200
+ /**
201
+ * Finds a position in a list of matches.
202
+ *
203
+ * @param matches A list of matches to search into.
204
+ * @param position The position to find.
205
+ */
206
+ export declare function findPosition(matches: Match[], position: number): ParticipantSlot;
207
+ /**
208
+ * Checks if a participant is involved in a given match.
209
+ *
210
+ * @param match A match.
211
+ * @param participantId ID of a participant.
212
+ */
213
+ export declare function isParticipantInMatch(match: MatchResults, participantId: Id): boolean;
214
+ /**
215
+ * Gets the side where the winner of the given match will go in the next match.
216
+ *
217
+ * @param matchNumber Number of the match.
218
+ */
219
+ export declare function getSide(matchNumber: number): Side;
220
+ /**
221
+ * Gets the other side of a match.
222
+ *
223
+ * @param side The side that we don't want.
224
+ */
225
+ export declare function getOtherSide(side: Side): Side;
226
+ /**
227
+ * Checks if a match is pending (i.e. locked or waiting).
228
+ *
229
+ * [Locked > Waiting] > Ready > Running > Completed > Archived
230
+ *
231
+ * @param match Partial match results.
232
+ */
233
+ export declare function isMatchPending(match: DeepPartial<MatchResults>): boolean;
234
+ /**
235
+ * Checks if a match is started.
236
+ *
237
+ * Note: this is score-based. A completed or archived match is seen as "started" as well.
238
+ *
239
+ * Locked > Waiting > Ready > [Running > Completed > Archived]
240
+ *
241
+ * @param match Partial match results.
242
+ */
243
+ export declare function isMatchStarted(match: DeepPartial<MatchResults>): boolean;
244
+ /**
245
+ * Checks if a match is completed (based on BYEs, forfeit or result).
246
+ *
247
+ * Note: archived matches are not seen as completed by this helper.
248
+ *
249
+ * Locked > Waiting > Ready > Running > [Completed] > Archived
250
+ *
251
+ * @param match Partial match results.
252
+ */
253
+ export declare function isMatchCompleted(match: DeepPartial<MatchResults>): boolean;
254
+ /**
255
+ * Checks if a match is ongoing (i.e. ready or running).
256
+ *
257
+ * Locked > Waiting > [Ready > Running] > Completed > Archived
258
+ *
259
+ * @param match Partial match results.
260
+ */
261
+ export declare function isMatchOngoing(match: MatchResults): boolean;
262
+ /**
263
+ * Checks if a match is stale (i.e. it should not change anymore).
264
+ *
265
+ * [Locked - BYE] > Waiting > Ready > Running > [Completed > Archived]
266
+ *
267
+ * @param match Partial match results.
268
+ */
269
+ export declare function isMatchStale(match: MatchResults): boolean;
270
+ /**
271
+ * Checks if a match is completed because of a forfeit.
272
+ *
273
+ * @param match Partial match results.
274
+ */
275
+ export declare function isMatchForfeitCompleted(match: DeepPartial<MatchResults>): boolean;
276
+ /**
277
+ * Checks if a match is completed because of a either a draw or a win.
278
+ *
279
+ * @param match Partial match results.
280
+ */
281
+ export declare function isMatchResultCompleted(match: DeepPartial<MatchResults>): boolean;
282
+ /**
283
+ * Checks if a match is completed because of a draw.
284
+ *
285
+ * @param match Partial match results.
286
+ */
287
+ export declare function isMatchDrawCompleted(match: DeepPartial<MatchResults>): boolean;
288
+ /**
289
+ * Checks if a match is completed because of a win.
290
+ *
291
+ * @param match Partial match results.
292
+ */
293
+ export declare function isMatchWinCompleted(match: DeepPartial<MatchResults>): boolean;
294
+ /**
295
+ * Checks if a match is completed because of at least one BYE.
296
+ *
297
+ * A match "BYE vs. TBD" isn't considered completed yet.
298
+ *
299
+ * @param match Partial match results.
300
+ */
301
+ export declare function isMatchByeCompleted(match: DeepPartial<MatchResults>): boolean;
302
+ /**
303
+ * Checks if a match's results can't be updated.
304
+ *
305
+ * @param match The match to check.
306
+ */
307
+ export declare function isMatchUpdateLocked(match: MatchResults): boolean;
308
+ /**
309
+ * Checks if a match's participants can't be updated.
310
+ *
311
+ * @param match The match to check.
312
+ */
313
+ export declare function isMatchParticipantLocked(match: MatchResults): boolean;
314
+ /**
315
+ * Indicates whether a match has at least one BYE or not.
316
+ *
317
+ * @param match Partial match results.
318
+ */
319
+ export declare function hasBye(match: DeepPartial<MatchResults>): boolean;
320
+ /**
321
+ * Returns the status of a match based on the opponents of a match.
322
+ *
323
+ * @param opponents The opponents of a match.
324
+ */
325
+ export declare function getMatchStatus(opponents: Duel): Status;
326
+ /**
327
+ * Returns the status of a match based on the results of a match.
328
+ *
329
+ * @param match Partial match results.
330
+ */
331
+ export declare function getMatchStatus(match: Omit<MatchResults, 'status'>): Status;
332
+ /**
333
+ * Updates a match results based on an input.
334
+ *
335
+ * @param stored A reference to what will be updated in the storage.
336
+ * @param match Input of the update.
337
+ * @param inRoundRobin Indicates whether the match is in a round-robin stage.
338
+ */
339
+ export declare function setMatchResults(stored: MatchResults, match: DeepPartial<MatchResults>, inRoundRobin: boolean): {
340
+ statusChanged: boolean;
341
+ resultChanged: boolean;
342
+ };
343
+ /**
344
+ * Resets the results of a match. (status, forfeit, result)
345
+ *
346
+ * @param stored A reference to what will be updated in the storage.
347
+ */
348
+ export declare function resetMatchResults(stored: MatchResults): void;
349
+ /**
350
+ * Passes user-defined extra fields to the stored match.
351
+ *
352
+ * @param stored A reference to what will be updated in the storage.
353
+ * @param match Input of the update.
354
+ */
355
+ export declare function setExtraFields(stored: MatchResults, match: DeepPartial<MatchResults>): void;
356
+ /**
357
+ * Gets the id of the opponent at the given side of the given match.
358
+ *
359
+ * @param match The match to get the opponent from.
360
+ * @param side The side where to get the opponent from.
361
+ */
362
+ export declare function getOpponentId(match: MatchResults, side: Side): Id | null;
363
+ /**
364
+ * Gets the origin position of a side of a match.
365
+ *
366
+ * @param match The match.
367
+ * @param side The side.
368
+ */
369
+ export declare function getOriginPosition(match: Match, side: Side): number;
370
+ /**
371
+ * Returns every loser in a list of matches.
372
+ *
373
+ * @param participants The list of participants.
374
+ * @param matches A list of matches to get losers of.
375
+ */
376
+ export declare function getLosers(participants: Participant[], matches: Match[]): Participant[][];
377
+ /**
378
+ * Makes final standings based on participants grouped by ranking.
379
+ *
380
+ * @param grouped A list of participants grouped by ranking.
381
+ */
382
+ export declare function makeFinalStandings(grouped: Participant[][]): FinalStandingsItem[];
383
+ /**
384
+ * Returns the decisive match of a Grand Final.
385
+ *
386
+ * @param type The type of Grand Final.
387
+ * @param matches The matches in the Grand Final.
388
+ */
389
+ export declare function getGrandFinalDecisiveMatch(type: GrandFinalType, matches: Match[]): Match;
390
+ /**
391
+ * Finds a participant in a list.
392
+ *
393
+ * @param participants The list of participants.
394
+ * @param slot The slot of the participant to find.
395
+ */
396
+ export declare function findParticipant(participants: Participant[], slot: ParticipantSlot): Participant;
397
+ /**
398
+ * Gets the side the winner of the current match will go to in the next match.
399
+ *
400
+ * @param matchNumber Number of the current match.
401
+ * @param roundNumber Number of the current round.
402
+ * @param roundCount Count of rounds.
403
+ * @param matchLocation Location of the current match.
404
+ */
405
+ export declare function getNextSide(matchNumber: number, roundNumber: number, roundCount: number, matchLocation: GroupType): Side;
406
+ /**
407
+ * Gets the side the winner of the current match in loser bracket will go in the next match.
408
+ *
409
+ * @param matchNumber Number of the match.
410
+ * @param nextMatch The next match.
411
+ * @param roundNumber Number of the current round.
412
+ */
413
+ export declare function getNextSideLoserBracket(matchNumber: number, nextMatch: Match, roundNumber: number): Side;
414
+ /**
415
+ * Gets the side the loser of the current match in loser bracket will go in the next match.
416
+ *
417
+ * @param roundNumber Number of the current round.
418
+ */
419
+ export declare function getNextSideConsolationFinalDoubleElimination(roundNumber: number): Side;
420
+ export type SetNextOpponent = (nextMatch: Match, nextSide: Side, match?: Match, currentSide?: Side) => void;
421
+ /**
422
+ * Sets an opponent in the next match he has to go.
423
+ *
424
+ * @param nextMatch A match which follows the current one.
425
+ * @param nextSide The side the opponent will be on in the next match.
426
+ * @param match The current match.
427
+ * @param currentSide The side the opponent is currently on.
428
+ */
429
+ export declare function setNextOpponent(nextMatch: Match, nextSide: Side, match?: Match, currentSide?: Side): void;
430
+ /**
431
+ * Resets an opponent in the match following the current one.
432
+ *
433
+ * @param nextMatch A match which follows the current one.
434
+ * @param nextSide The side the opponent will be on in the next match.
435
+ */
436
+ export declare function resetNextOpponent(nextMatch: Match, nextSide: Side): void;
437
+ /**
438
+ * Inverts opponents if requested by the input.
439
+ *
440
+ * @param stored A reference to what will be updated in the storage.
441
+ * @param match Input of the update.
442
+ */
443
+ export declare function handleOpponentsInversion(stored: MatchResults, match: DeepPartial<MatchResults>): void;
444
+ /**
445
+ * Sets the `result` of both opponents based on their scores.
446
+ *
447
+ * @param stored A reference to what will be updated in the storage.
448
+ * @param match Input of the update.
449
+ */
450
+ export declare function handleGivenStatus(stored: MatchResults, match: DeepPartial<MatchResults>): void;
451
+ /**
452
+ * Inverts `opponent1` and `opponent2` in a match.
453
+ *
454
+ * @param match A match to update.
455
+ */
456
+ export declare function invertOpponents(match: DeepPartial<MatchResults>): void;
457
+ /**
458
+ * Updates the scores of a match.
459
+ *
460
+ * @param stored A reference to what will be updated in the storage.
461
+ * @param match Input of the update.
462
+ * @returns `true` if the status of the match changed, `false` otherwise.
463
+ */
464
+ export declare function setScores(stored: MatchResults, match: DeepPartial<MatchResults>): boolean;
465
+ /**
466
+ * Infers the win result based on BYEs.
467
+ *
468
+ * @param opponent1 Opponent 1.
469
+ * @param opponent2 Opponent 2.
470
+ */
471
+ export declare function getInferredResult(opponent1: ParticipantSlot, opponent2: ParticipantSlot): Pick<MatchResults, 'opponent1' | 'opponent2'>;
472
+ /**
473
+ * Completes a match and handles results and forfeits.
474
+ *
475
+ * @param stored A reference to what will be updated in the storage.
476
+ * @param match Input of the update.
477
+ * @param inRoundRobin Indicates whether the match is in a round-robin stage.
478
+ */
479
+ export declare function setCompleted(stored: MatchResults, match: DeepPartial<MatchResults>, inRoundRobin: boolean): void;
480
+ /**
481
+ * Enforces the symmetry between opponents.
482
+ *
483
+ * Sets an opponent's result to something, based on the result on the other opponent.
484
+ *
485
+ * @param stored A reference to what will be updated in the storage.
486
+ * @param match Input of the update.
487
+ * @param check A result to check in each opponent.
488
+ * @param change A result to set in each other opponent if `check` is correct.
489
+ * @param inRoundRobin Indicates whether the match is in a round-robin stage.
490
+ */
491
+ export declare function setResults(stored: MatchResults, match: DeepPartial<MatchResults>, check: Result, change: Result, inRoundRobin: boolean): void;
492
+ /**
493
+ * Sets forfeits for each opponent (if needed).
494
+ *
495
+ * @param stored A reference to what will be updated in the storage.
496
+ * @param match Input of the update.
497
+ */
498
+ export declare function setForfeits(stored: MatchResults, match: DeepPartial<MatchResults>): void;
499
+ /**
500
+ * Indicates if a seeding is filled with participants' IDs.
501
+ *
502
+ * @param seeding The seeding.
503
+ */
504
+ export declare function isSeedingWithIds(seeding: Seeding): boolean;
505
+ /**
506
+ * Extracts participants from a seeding, without the BYEs.
507
+ *
508
+ * @param tournamentId ID of the tournament.
509
+ * @param seeding The seeding (no IDs).
510
+ */
511
+ export declare function extractParticipantsFromSeeding(tournamentId: Id, seeding: Seeding): OmitId<Participant>[];
512
+ /**
513
+ * Returns participant slots mapped to the instances stored in the database thanks to their name.
514
+ *
515
+ * @param seeding The seeding.
516
+ * @param database The participants stored in the database.
517
+ * @param positions An optional list of positions (seeds) for a manual ordering.
518
+ */
519
+ export declare function mapParticipantsNamesToDatabase(seeding: Seeding, database: Participant[], positions?: number[]): ParticipantSlot[];
520
+ /**
521
+ * Returns participant slots mapped to the instances stored in the database thanks to their id.
522
+ *
523
+ * @param seeding The seeding.
524
+ * @param database The participants stored in the database.
525
+ * @param positions An optional list of positions (seeds) for a manual ordering.
526
+ */
527
+ export declare function mapParticipantsIdsToDatabase(seeding: Seeding, database: Participant[], positions?: number[]): ParticipantSlot[];
528
+ /**
529
+ * Returns participant slots mapped to the instances stored in the database thanks to a property of theirs.
530
+ *
531
+ * @param prop The property to search participants with.
532
+ * @param seeding The seeding.
533
+ * @param database The participants stored in the database.
534
+ * @param positions An optional list of positions (seeds) for a manual ordering.
535
+ */
536
+ export declare function mapParticipantsToDatabase(prop: 'id' | 'name', seeding: Seeding, database: Participant[], positions?: number[]): ParticipantSlot[];
537
+ /**
538
+ * Converts a list of matches to a seeding.
539
+ *
540
+ * @param matches The input matches.
541
+ */
542
+ export declare function convertMatchesToSeeding(matches: Match[]): ParticipantSlot[];
543
+ /**
544
+ * Converts a list of slots to an input seeding.
545
+ *
546
+ * @param slots The slots to convert.
547
+ */
548
+ export declare function convertSlotsToSeeding(slots: ParticipantSlot[]): Seeding;
549
+ /**
550
+ * Sorts the seeding with the BYEs in the correct position.
551
+ *
552
+ * @param slots A list of slots to sort.
553
+ */
554
+ export declare function sortSeeding(slots: ParticipantSlot[]): ParticipantSlot[];
555
+ /**
556
+ * Returns only the non null elements.
557
+ *
558
+ * @param array The array to process.
559
+ */
560
+ export declare function getNonNull<T>(array: Nullable<T>[]): T[];
561
+ /**
562
+ * Returns a list of objects which have unique values of a specific key.
563
+ *
564
+ * @param array The array to process.
565
+ * @param key The key to filter by.
566
+ */
567
+ export declare function uniqueBy<T>(array: T[], key: (obj: T) => unknown): T[];
568
+ /**
569
+ * Indicates whether the loser bracket round is major.
570
+ *
571
+ * @param roundNumber Number of the round.
572
+ */
573
+ export declare function isMajorRound(roundNumber: number): boolean;
574
+ /**
575
+ * Indicates whether the loser bracket round is minor.
576
+ *
577
+ * @param roundNumber Number of the round.
578
+ */
579
+ export declare function isMinorRound(roundNumber: number): boolean;
580
+ /**
581
+ * Makes the transition to a major round for duels of the previous round. The duel count is divided by 2.
582
+ *
583
+ * @param previousDuels The previous duels to transition from.
584
+ */
585
+ export declare function transitionToMajor(previousDuels: Duel[]): Duel[];
586
+ /**
587
+ * Makes the transition to a minor round for duels of the previous round. The duel count stays the same.
588
+ *
589
+ * @param previousDuels The previous duels to transition from.
590
+ * @param losers Losers from the previous major round.
591
+ * @param method The ordering method for the losers.
592
+ */
593
+ export declare function transitionToMinor(previousDuels: Duel[], losers: ParticipantSlot[], method?: SeedOrdering): Duel[];
594
+ /**
595
+ * Sets the parent match to a completed status if all its child games are completed.
596
+ *
597
+ * @param parent The partial parent match to update.
598
+ * @param childCount Child count of this parent match.
599
+ * @param inRoundRobin Indicates whether the parent match is in a round-robin stage.
600
+ */
601
+ export declare function setParentMatchCompleted(parent: Pick<MatchResults, 'opponent1' | 'opponent2'>, childCount: number, inRoundRobin: boolean): void;
602
+ /**
603
+ * Returns a parent match results based on its child games scores.
604
+ *
605
+ * @param storedParent The parent match stored in the database.
606
+ * @param scores The scores of the match child games.
607
+ */
608
+ export declare function getParentMatchResults(storedParent: Match, scores: Scores): Pick<MatchResults, 'opponent1' | 'opponent2'>;
609
+ /**
610
+ * Gets the values which need to be updated in a match when it's updated on insertion.
611
+ *
612
+ * @param match The up to date match.
613
+ * @param existing The base match.
614
+ * @param enableByes Whether to use BYEs or TBDs for `null` values in an input seeding.
615
+ */
616
+ export declare function getUpdatedMatchResults<T extends MatchResults>(match: T, existing: T, enableByes: boolean): T;
617
+ /**
618
+ * Calculates the score of a parent match based on its child games.
619
+ *
620
+ * @param games The child games to process.
621
+ */
622
+ export declare function getChildGamesResults(games: MatchGame[]): Scores;
623
+ /**
624
+ * Gets the default list of seeds for a round's matches.
625
+ *
626
+ * @param inLoserBracket Whether the match is in the loser bracket.
627
+ * @param roundNumber The number of the current round.
628
+ * @param roundCountLB The count of rounds in loser bracket.
629
+ * @param matchCount The count of matches in the round.
630
+ */
631
+ export declare function getSeeds(inLoserBracket: boolean, roundNumber: number, roundCountLB: number, matchCount: number): number[];
632
+ /**
633
+ * Gets the number of seeds for a round's matches.
634
+ *
635
+ * @param inLoserBracket Whether the match is in the loser bracket.
636
+ * @param roundNumber The number of the current round.
637
+ * @param roundCountLB The count of rounds in loser bracket.
638
+ * @param matchCount The count of matches in the round.
639
+ */
640
+ export declare function getSeedCount(inLoserBracket: boolean, roundNumber: number, roundCountLB: number, matchCount: number): number;
641
+ /**
642
+ * Throws if the ordering is not supported on the given round number.
643
+ *
644
+ * @param inLoserBracket Whether the match is in the loser bracket.
645
+ * @param roundNumber The number of the round.
646
+ * @param roundCountLB The count of rounds in loser bracket.
647
+ */
648
+ export declare function ensureOrderingSupported(inLoserBracket: boolean, roundNumber: number, roundCountLB: number): void;
649
+ /**
650
+ * Indicates whether the ordering is supported in upper bracket, given the round number.
651
+ *
652
+ * @param roundNumber The number of the round.
653
+ */
654
+ export declare function isOrderingSupportedUpperBracket(roundNumber: number): boolean;
655
+ /**
656
+ * Indicates whether the ordering is supported in loser bracket, given the round number.
657
+ *
658
+ * @param roundNumber The number of the round.
659
+ * @param roundCount The count of rounds.
660
+ */
661
+ export declare function isOrderingSupportedLoserBracket(roundNumber: number, roundCount: number): boolean;
662
+ /**
663
+ * Returns the number of rounds an upper bracket has given the number of participants in the stage.
664
+ *
665
+ * @param participantCount The number of participants in the stage.
666
+ */
667
+ export declare function getUpperBracketRoundCount(participantCount: number): number;
668
+ /**
669
+ * Returns the count of round pairs (major & minor) in a loser bracket.
670
+ *
671
+ * @param participantCount The number of participants in the stage.
672
+ */
673
+ export declare function getRoundPairCount(participantCount: number): number;
674
+ /**
675
+ * Determines whether a double elimination stage is really necessary.
676
+ *
677
+ * If the size is only two (less is impossible), then a lower bracket and a grand final are not necessary.
678
+ *
679
+ * @param participantCount The number of participants in the stage.
680
+ */
681
+ export declare function isDoubleEliminationNecessary(participantCount: number): boolean;
682
+ /**
683
+ * Returns the real (because of loser ordering) number of a match in a loser bracket.
684
+ *
685
+ * @param participantCount The number of participants in a stage.
686
+ * @param roundNumber Number of the round.
687
+ * @param matchNumber Number of the match.
688
+ * @param method The method used for the round.
689
+ */
690
+ export declare function findLoserMatchNumber(participantCount: number, roundNumber: number, matchNumber: number, method?: SeedOrdering): number;
691
+ /**
692
+ * Returns the count of matches in a round of a loser bracket.
693
+ *
694
+ * @param participantCount The number of participants in a stage.
695
+ * @param roundNumber Number of the round.
696
+ */
697
+ export declare function getLoserRoundMatchCount(participantCount: number, roundNumber: number): number;
698
+ /**
699
+ * Returns the count of losers coming from the winner bracket in a round of loser bracket.
700
+ *
701
+ * @param participantCount The number of participants in the stage.
702
+ * @param roundNumber Number of the round.
703
+ */
704
+ export declare function getLoserCountFromWbForLbRound(participantCount: number, roundNumber: number): number;
705
+ /**
706
+ * Returns the ordering method of a round of a loser bracket.
707
+ *
708
+ * @param seedOrdering The list of seed orderings.
709
+ * @param roundNumber Number of the round.
710
+ */
711
+ export declare function getLoserOrdering(seedOrdering: SeedOrdering[], roundNumber: number): SeedOrdering | undefined;
712
+ /**
713
+ * Returns the number of rounds a lower bracket has given the number of participants in a double elimination stage.
714
+ *
715
+ * @param participantCount The number of participants in the stage.
716
+ */
717
+ export declare function getLowerBracketRoundCount(participantCount: number): number;
718
+ /**
719
+ * Returns the match number of the corresponding match in the next round by dividing by two.
720
+ *
721
+ * @param matchNumber The current match number.
722
+ */
723
+ export declare function getDiagonalMatchNumber(matchNumber: number): number;
724
+ /**
725
+ * Returns the nearest power of two **greater than** or equal to the given number.
726
+ *
727
+ * @param input The input number.
728
+ */
729
+ export declare function getNearestPowerOfTwo(input: number): number;
730
+ /**
731
+ * Returns the minimum score a participant must have to win a Best Of X series match.
732
+ *
733
+ * @param x The count of child games in the series.
734
+ */
735
+ export declare function minScoreToWinBestOfX(x: number): number;
736
+ /**
737
+ * Checks if a stage is a round-robin stage.
738
+ *
739
+ * @param stage The stage to check.
740
+ */
741
+ export declare function isRoundRobin(stage: Stage): boolean;
742
+ /**
743
+ * Throws if a stage is round-robin.
744
+ *
745
+ * @param stage The stage to check.
746
+ */
747
+ export declare function ensureNotRoundRobin(stage: Stage): void;
748
+ /**
749
+ * Checks if a round is completed based on its matches.
750
+ *
751
+ * @param roundMatches Matches of the round.
752
+ * @deprecated This is both functionally and semantically incorrect because:
753
+ * 1. A match could be completed because of BYEs.
754
+ * 2. You could totally give a list of matches from different rounds to this function, and it wouldn't complain
755
+ * although the result will **not** tell you whether a _round_ is completed.
756
+ *
757
+ * Please do something like `matches.every(m => isMatchCompleted(m))` instead.
758
+ */
759
+ export declare function isRoundCompleted(roundMatches: Match[]): boolean;
760
+ /**
761
+ * Checks if a group is a winner bracket.
762
+ *
763
+ * It's not always the opposite of `inLoserBracket()`: it could be the only bracket of a single elimination stage.
764
+ *
765
+ * @param stageType Type of the stage.
766
+ * @param groupNumber Number of the group.
767
+ */
768
+ export declare function isWinnerBracket(stageType: StageType, groupNumber: number): boolean;
769
+ /**
770
+ * Checks if a group is a loser bracket.
771
+ *
772
+ * @param stageType Type of the stage.
773
+ * @param groupNumber Number of the group.
774
+ */
775
+ export declare function isLoserBracket(stageType: StageType, groupNumber: number): boolean;
776
+ /**
777
+ * Checks if a group is a final group (consolation final or grand final).
778
+ *
779
+ * @param stageType Type of the stage.
780
+ * @param groupNumber Number of the group.
781
+ */
782
+ export declare function isFinalGroup(stageType: StageType, groupNumber: number): boolean;
783
+ /**
784
+ * Returns the type of group the match is located into.
785
+ *
786
+ * @param stageType Type of the stage.
787
+ * @param groupNumber Number of the group.
788
+ */
789
+ export declare function getMatchLocation(stageType: StageType, groupNumber: number): GroupType;
790
+ /**
791
+ * Returns the fraction of final for the current round (e.g. `1/2` for semi finals or `1/4` for quarter finals).
792
+ *
793
+ * @param roundNumber Number of the current round.
794
+ * @param roundCount Count of rounds.
795
+ */
796
+ export declare function getFractionOfFinal(roundNumber: number, roundCount: number): number;
797
+ /**
798
+ * Calculates a ranking based on a list of matches and a formula.
799
+ *
800
+ * @param matches The list of matches.
801
+ * @param formula The points formula to apply.
802
+ */
803
+ export declare function getRanking(matches: Match[], formula: RankingFormula): RankingItem[];
804
+ //# sourceMappingURL=helpers.d.ts.map