@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.
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/dist/base/getter.d.ts +272 -0
- package/dist/base/getter.d.ts.map +1 -0
- package/dist/base/getter.js +545 -0
- package/dist/base/getter.js.map +1 -0
- package/dist/base/stage/creator.d.ts +269 -0
- package/dist/base/stage/creator.d.ts.map +1 -0
- package/dist/base/stage/creator.js +735 -0
- package/dist/base/stage/creator.js.map +1 -0
- package/dist/base/updater.d.ts +121 -0
- package/dist/base/updater.d.ts.map +1 -0
- package/dist/base/updater.js +323 -0
- package/dist/base/updater.js.map +1 -0
- package/dist/create.d.ts +25 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +55 -0
- package/dist/create.js.map +1 -0
- package/dist/delete.d.ts +33 -0
- package/dist/delete.d.ts.map +1 -0
- package/dist/delete.js +57 -0
- package/dist/delete.js.map +1 -0
- package/dist/find.d.ts +60 -0
- package/dist/find.d.ts.map +1 -0
- package/dist/find.js +196 -0
- package/dist/find.js.map +1 -0
- package/dist/get.d.ts +121 -0
- package/dist/get.d.ts.map +1 -0
- package/dist/get.js +420 -0
- package/dist/get.js.map +1 -0
- package/dist/helpers.d.ts +804 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +1897 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/manager.d.ts +60 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +189 -0
- package/dist/manager.js.map +1 -0
- package/dist/ordering.d.ts +7 -0
- package/dist/ordering.d.ts.map +1 -0
- package/dist/ordering.js +147 -0
- package/dist/ordering.js.map +1 -0
- package/dist/reset.d.ts +27 -0
- package/dist/reset.d.ts.map +1 -0
- package/dist/reset.js +82 -0
- package/dist/reset.js.map +1 -0
- package/dist/types.d.ts +260 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/update.d.ts +111 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +265 -0
- package/dist/update.js.map +1 -0
- package/package.json +67 -0
package/dist/delete.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Delete = void 0;
|
|
4
|
+
class Delete {
|
|
5
|
+
/**
|
|
6
|
+
* Creates an instance of Delete, which will handle cleanly deleting data in the storage.
|
|
7
|
+
*
|
|
8
|
+
* @param storage The implementation of Storage.
|
|
9
|
+
*/
|
|
10
|
+
constructor(storage) {
|
|
11
|
+
this.storage = storage;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Deletes a stage, and all its components:
|
|
15
|
+
*
|
|
16
|
+
* - Groups
|
|
17
|
+
* - Rounds
|
|
18
|
+
* - Matches
|
|
19
|
+
* - Match games
|
|
20
|
+
*
|
|
21
|
+
* This does not delete the related participants.
|
|
22
|
+
*
|
|
23
|
+
* @param stageId ID of the stage.
|
|
24
|
+
*/
|
|
25
|
+
async stage(stageId) {
|
|
26
|
+
// The order is important here, because the abstract storage can possibly have foreign key checks (e.g. SQL).
|
|
27
|
+
if (!(await this.storage.delete('match_game', { stage_id: stageId })))
|
|
28
|
+
throw Error('Could not delete match games.');
|
|
29
|
+
if (!(await this.storage.delete('match', { stage_id: stageId })))
|
|
30
|
+
throw Error('Could not delete matches.');
|
|
31
|
+
if (!(await this.storage.delete('round', { stage_id: stageId })))
|
|
32
|
+
throw Error('Could not delete rounds.');
|
|
33
|
+
if (!(await this.storage.delete('group', { stage_id: stageId })))
|
|
34
|
+
throw Error('Could not delete groups.');
|
|
35
|
+
if (!(await this.storage.delete('stage', { id: stageId })))
|
|
36
|
+
throw Error('Could not delete the stage.');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Deletes **the stages** of a tournament (and all their components, see {@link stage | delete.stage()}).
|
|
40
|
+
*
|
|
41
|
+
* This does not delete the related participants and you are responsible for deleting the tournament itself.
|
|
42
|
+
*
|
|
43
|
+
* @param tournamentId ID of the tournament.
|
|
44
|
+
*/
|
|
45
|
+
async tournament(tournamentId) {
|
|
46
|
+
const stages = await this.storage.select('stage', {
|
|
47
|
+
tournament_id: tournamentId,
|
|
48
|
+
});
|
|
49
|
+
if (!stages)
|
|
50
|
+
throw Error('Error getting the stages.');
|
|
51
|
+
// Not doing this in a `Promise.all()` since this can be a heavy operation.
|
|
52
|
+
for (const stage of stages)
|
|
53
|
+
await this.stage(stage.id);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.Delete = Delete;
|
|
57
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../src/delete.ts"],"names":[],"mappings":";;;AAGA,MAAa,MAAM;IAGf;;;;OAIG;IACH,YAAY,OAAgB;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,KAAK,CAAC,OAAW;QAC1B,6GAA6G;QAE7G,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YACjE,MAAM,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAEjD,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5D,MAAM,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE7C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5D,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAE5C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YAC5D,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAE5C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,UAAU,CAAC,YAAgB;QACpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE;YAC9C,aAAa,EAAE,YAAY;SAC9B,CAAC,CAAC;QACH,IAAI,CAAC,MAAM;YAAE,MAAM,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAEtD,2EAA2E;QAC3E,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3D,CAAC;CACJ;AA3DD,wBA2DC"}
|
package/dist/find.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Group, Id, Match, MatchGame } from 'brackets-model';
|
|
2
|
+
import { BaseGetter } from './base/getter';
|
|
3
|
+
export declare class Find extends BaseGetter {
|
|
4
|
+
/**
|
|
5
|
+
* Gets the upper bracket (the only bracket if single elimination or the winner bracket in double elimination).
|
|
6
|
+
*
|
|
7
|
+
* @param stageId ID of the stage.
|
|
8
|
+
*/
|
|
9
|
+
upperBracket(stageId: Id): Promise<Group>;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the loser bracket.
|
|
12
|
+
*
|
|
13
|
+
* @param stageId ID of the stage.
|
|
14
|
+
*/
|
|
15
|
+
loserBracket(stageId: Id): Promise<Group>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the matches leading to the given match.
|
|
18
|
+
*
|
|
19
|
+
* If a `participantId` is given, the previous match _from their point of view_ is returned.
|
|
20
|
+
*
|
|
21
|
+
* @param matchId ID of the target match.
|
|
22
|
+
* @param participantId Optional ID of the participant.
|
|
23
|
+
*/
|
|
24
|
+
previousMatches(matchId: Id, participantId?: number): Promise<Match[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the matches following the given match.
|
|
27
|
+
*
|
|
28
|
+
* If a `participantId` is given:
|
|
29
|
+
* - If the participant won, the next match _from their point of view_ is returned.
|
|
30
|
+
* - If the participant is eliminated, no match is returned.
|
|
31
|
+
*
|
|
32
|
+
* @param matchId ID of the target match.
|
|
33
|
+
* @param participantId Optional ID of the participant.
|
|
34
|
+
*/
|
|
35
|
+
nextMatches(matchId: Id, participantId?: number): Promise<Match[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Finds a match in a given group. The match must have the given number in a round of which the number in group is given.
|
|
38
|
+
*
|
|
39
|
+
* **Example:** In group of id 1, give me the 4th match in the 3rd round.
|
|
40
|
+
*
|
|
41
|
+
* @param groupId ID of the group.
|
|
42
|
+
* @param roundNumber Number of the round in its parent group.
|
|
43
|
+
* @param matchNumber Number of the match in its parent round.
|
|
44
|
+
*/
|
|
45
|
+
match(groupId: Id, roundNumber: number, matchNumber: number): Promise<Match>;
|
|
46
|
+
/**
|
|
47
|
+
* Finds a match game based on its `id` or based on the combination of its `parent_id` and `number`.
|
|
48
|
+
*
|
|
49
|
+
* @param game Values to change in a match game.
|
|
50
|
+
*/
|
|
51
|
+
matchGame(game: Partial<MatchGame>): Promise<MatchGame>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns an object with 1 match per group type. Only supports double elimination.
|
|
54
|
+
*
|
|
55
|
+
* @param matches A list of matches.
|
|
56
|
+
* @param fetchedGroups A map of groups which were already fetched.
|
|
57
|
+
*/
|
|
58
|
+
private getMatchesByGroupDoubleElimination;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=find.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,qBAAa,IAAK,SAAQ,UAAU;IAChC;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IAetD;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC;IAoBtD;;;;;;;OAOG;IACU,eAAe,CACxB,OAAO,EAAE,EAAE,EACX,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,KAAK,EAAE,CAAC;IAiCnB;;;;;;;;;OASG;IACU,WAAW,CACpB,OAAO,EAAE,EAAE,EACX,aAAa,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,KAAK,EAAE,CAAC;IAwFnB;;;;;;;;OAQG;IACU,KAAK,CACd,OAAO,EAAE,EAAE,EACX,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GACpB,OAAO,CAAC,KAAK,CAAC;IAIjB;;;;OAIG;IACU,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAIpE;;;;;OAKG;YACW,kCAAkC;CAgDnD"}
|
package/dist/find.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Find = void 0;
|
|
4
|
+
const getter_1 = require("./base/getter");
|
|
5
|
+
const helpers = require("./helpers");
|
|
6
|
+
class Find extends getter_1.BaseGetter {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the upper bracket (the only bracket if single elimination or the winner bracket in double elimination).
|
|
9
|
+
*
|
|
10
|
+
* @param stageId ID of the stage.
|
|
11
|
+
*/
|
|
12
|
+
async upperBracket(stageId) {
|
|
13
|
+
const stage = await this.storage.select('stage', stageId);
|
|
14
|
+
if (!stage)
|
|
15
|
+
throw Error('Stage not found.');
|
|
16
|
+
switch (stage.type) {
|
|
17
|
+
case 'round_robin':
|
|
18
|
+
throw Error('Round-robin stages do not have an upper bracket.');
|
|
19
|
+
case 'single_elimination':
|
|
20
|
+
case 'double_elimination':
|
|
21
|
+
return this.getUpperBracket(stageId);
|
|
22
|
+
default:
|
|
23
|
+
throw Error('Unknown stage type.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets the loser bracket.
|
|
28
|
+
*
|
|
29
|
+
* @param stageId ID of the stage.
|
|
30
|
+
*/
|
|
31
|
+
async loserBracket(stageId) {
|
|
32
|
+
const stage = await this.storage.select('stage', stageId);
|
|
33
|
+
if (!stage)
|
|
34
|
+
throw Error('Stage not found.');
|
|
35
|
+
switch (stage.type) {
|
|
36
|
+
case 'round_robin':
|
|
37
|
+
throw Error('Round-robin stages do not have a loser bracket.');
|
|
38
|
+
case 'single_elimination':
|
|
39
|
+
throw Error('Single elimination stages do not have a loser bracket.');
|
|
40
|
+
case 'double_elimination':
|
|
41
|
+
const group = await this.getLoserBracket(stageId);
|
|
42
|
+
if (!group)
|
|
43
|
+
throw Error('Loser bracket not found.');
|
|
44
|
+
return group;
|
|
45
|
+
default:
|
|
46
|
+
throw Error('Unknown stage type.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the matches leading to the given match.
|
|
51
|
+
*
|
|
52
|
+
* If a `participantId` is given, the previous match _from their point of view_ is returned.
|
|
53
|
+
*
|
|
54
|
+
* @param matchId ID of the target match.
|
|
55
|
+
* @param participantId Optional ID of the participant.
|
|
56
|
+
*/
|
|
57
|
+
async previousMatches(matchId, participantId) {
|
|
58
|
+
const match = await this.storage.select('match', matchId);
|
|
59
|
+
if (!match)
|
|
60
|
+
throw Error('Match not found.');
|
|
61
|
+
const stage = await this.storage.select('stage', match.stage_id);
|
|
62
|
+
if (!stage)
|
|
63
|
+
throw Error('Stage not found.');
|
|
64
|
+
const group = await this.storage.select('group', match.group_id);
|
|
65
|
+
if (!group)
|
|
66
|
+
throw Error('Group not found.');
|
|
67
|
+
const round = await this.storage.select('round', match.round_id);
|
|
68
|
+
if (!round)
|
|
69
|
+
throw Error('Round not found.');
|
|
70
|
+
const matchLocation = helpers.getMatchLocation(stage.type, group.number);
|
|
71
|
+
const previousMatches = await this.getPreviousMatches(match, matchLocation, stage, round.number);
|
|
72
|
+
if (participantId !== undefined) {
|
|
73
|
+
return previousMatches.filter((m) => helpers.isParticipantInMatch(m, participantId));
|
|
74
|
+
}
|
|
75
|
+
return previousMatches;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the matches following the given match.
|
|
79
|
+
*
|
|
80
|
+
* If a `participantId` is given:
|
|
81
|
+
* - If the participant won, the next match _from their point of view_ is returned.
|
|
82
|
+
* - If the participant is eliminated, no match is returned.
|
|
83
|
+
*
|
|
84
|
+
* @param matchId ID of the target match.
|
|
85
|
+
* @param participantId Optional ID of the participant.
|
|
86
|
+
*/
|
|
87
|
+
async nextMatches(matchId, participantId) {
|
|
88
|
+
const match = await this.storage.select('match', matchId);
|
|
89
|
+
if (!match)
|
|
90
|
+
throw Error('Match not found.');
|
|
91
|
+
const stage = await this.storage.select('stage', match.stage_id);
|
|
92
|
+
if (!stage)
|
|
93
|
+
throw Error('Stage not found.');
|
|
94
|
+
const group = await this.storage.select('group', match.group_id);
|
|
95
|
+
if (!group)
|
|
96
|
+
throw Error('Group not found.');
|
|
97
|
+
const { roundNumber, roundCount } = await this.getRoundPositionalInfo(match.round_id);
|
|
98
|
+
const matchLocation = helpers.getMatchLocation(stage.type, group.number);
|
|
99
|
+
const nextMatches = helpers.getNonNull(await this.getNextMatches(match, matchLocation, stage, roundNumber, roundCount));
|
|
100
|
+
if (participantId !== undefined) {
|
|
101
|
+
if (!helpers.isParticipantInMatch(match, participantId))
|
|
102
|
+
throw Error('The participant does not belong to this match.');
|
|
103
|
+
if (!helpers.isMatchStale(match)) {
|
|
104
|
+
throw Error('The match is not stale yet, so it is not possible to conclude the next matches for this participant.');
|
|
105
|
+
}
|
|
106
|
+
const loser = helpers.getLoser(match);
|
|
107
|
+
if (stage.type === 'single_elimination' &&
|
|
108
|
+
(loser === null || loser === void 0 ? void 0 : loser.id) === participantId)
|
|
109
|
+
return []; // Eliminated.
|
|
110
|
+
if (stage.type === 'double_elimination') {
|
|
111
|
+
// TODO: refactor `getNextMatches()` to return 1 next match per group. Then we can get rid of `getMatchesByGroupDoubleElimination()`.
|
|
112
|
+
const { winnerBracketMatch, loserBracketMatch, finalGroupMatch, } = await this.getMatchesByGroupDoubleElimination(nextMatches, new Map([[group.id, group]]));
|
|
113
|
+
const winner = helpers.getWinner(match);
|
|
114
|
+
if (matchLocation === 'loser_bracket') {
|
|
115
|
+
if (participantId === (loser === null || loser === void 0 ? void 0 : loser.id))
|
|
116
|
+
return []; // Eliminated from lower bracket.
|
|
117
|
+
if (participantId === (winner === null || winner === void 0 ? void 0 : winner.id))
|
|
118
|
+
return loserBracketMatch ? [loserBracketMatch] : [];
|
|
119
|
+
}
|
|
120
|
+
else if (matchLocation === 'winner_bracket') {
|
|
121
|
+
if (!loserBracketMatch) {
|
|
122
|
+
throw Error('All matches of winner bracket should lead to loser bracket.');
|
|
123
|
+
}
|
|
124
|
+
if (participantId === (loser === null || loser === void 0 ? void 0 : loser.id))
|
|
125
|
+
return [loserBracketMatch]; // Eliminated from upper bracket, going to lower bracket.
|
|
126
|
+
if (participantId === (winner === null || winner === void 0 ? void 0 : winner.id))
|
|
127
|
+
return winnerBracketMatch ? [winnerBracketMatch] : [];
|
|
128
|
+
}
|
|
129
|
+
else if (matchLocation === 'final_group') {
|
|
130
|
+
if (!finalGroupMatch) {
|
|
131
|
+
throw Error('All matches of a final group should also lead to the final group.');
|
|
132
|
+
}
|
|
133
|
+
return [finalGroupMatch];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return nextMatches;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Finds a match in a given group. The match must have the given number in a round of which the number in group is given.
|
|
141
|
+
*
|
|
142
|
+
* **Example:** In group of id 1, give me the 4th match in the 3rd round.
|
|
143
|
+
*
|
|
144
|
+
* @param groupId ID of the group.
|
|
145
|
+
* @param roundNumber Number of the round in its parent group.
|
|
146
|
+
* @param matchNumber Number of the match in its parent round.
|
|
147
|
+
*/
|
|
148
|
+
async match(groupId, roundNumber, matchNumber) {
|
|
149
|
+
return this.findMatch(groupId, roundNumber, matchNumber);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Finds a match game based on its `id` or based on the combination of its `parent_id` and `number`.
|
|
153
|
+
*
|
|
154
|
+
* @param game Values to change in a match game.
|
|
155
|
+
*/
|
|
156
|
+
async matchGame(game) {
|
|
157
|
+
return this.findMatchGame(game);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns an object with 1 match per group type. Only supports double elimination.
|
|
161
|
+
*
|
|
162
|
+
* @param matches A list of matches.
|
|
163
|
+
* @param fetchedGroups A map of groups which were already fetched.
|
|
164
|
+
*/
|
|
165
|
+
async getMatchesByGroupDoubleElimination(matches, fetchedGroups) {
|
|
166
|
+
var _a, _b, _c;
|
|
167
|
+
const getGroup = async (groupId) => {
|
|
168
|
+
const existing = fetchedGroups.get(groupId);
|
|
169
|
+
if (existing)
|
|
170
|
+
return existing;
|
|
171
|
+
const group = await this.storage.select('group', groupId);
|
|
172
|
+
if (!group)
|
|
173
|
+
throw Error('Group not found.');
|
|
174
|
+
fetchedGroups.set(groupId, group);
|
|
175
|
+
return group;
|
|
176
|
+
};
|
|
177
|
+
let matchByGroupType = {};
|
|
178
|
+
for (const match of matches) {
|
|
179
|
+
const group = await getGroup(match.group_id);
|
|
180
|
+
matchByGroupType = {
|
|
181
|
+
winnerBracketMatch: (_a = matchByGroupType['winnerBracketMatch']) !== null && _a !== void 0 ? _a : (helpers.isWinnerBracket('double_elimination', group.number)
|
|
182
|
+
? match
|
|
183
|
+
: undefined),
|
|
184
|
+
loserBracketMatch: (_b = matchByGroupType['loserBracketMatch']) !== null && _b !== void 0 ? _b : (helpers.isLoserBracket('double_elimination', group.number)
|
|
185
|
+
? match
|
|
186
|
+
: undefined),
|
|
187
|
+
finalGroupMatch: (_c = matchByGroupType['finalGroupMatch']) !== null && _c !== void 0 ? _c : (helpers.isFinalGroup('double_elimination', group.number)
|
|
188
|
+
? match
|
|
189
|
+
: undefined),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return matchByGroupType;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.Find = Find;
|
|
196
|
+
//# sourceMappingURL=find.js.map
|
package/dist/find.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find.js","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":";;;AACA,0CAA2C;AAC3C,qCAAqC;AAErC,MAAa,IAAK,SAAQ,mBAAU;IAChC;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,OAAW;QACjC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK;YAAE,MAAM,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAE5C,QAAQ,KAAK,CAAC,IAAI,EAAE;YAChB,KAAK,aAAa;gBACd,MAAM,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACpE,KAAK,oBAAoB,CAAC;YAC1B,KAAK,oBAAoB;gBAC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AAM,CAAC;oBACrD,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,SAAS,CAAC;aACvB,CAAC;SACL;QAED,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ;AA/QD,oBA+QC"}
|
package/dist/get.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Stage, Round, Match, MatchGame, Id, RankingItem } from 'brackets-model';
|
|
2
|
+
import { FinalStandingsItem, ParticipantSlot, StageData, type RoundRobinFinalStandingsOptions } from './types';
|
|
3
|
+
import { BaseGetter } from './base/getter';
|
|
4
|
+
export declare class Get extends BaseGetter {
|
|
5
|
+
/**
|
|
6
|
+
* Returns the data needed to display a stage.
|
|
7
|
+
*
|
|
8
|
+
* @param stageId ID of the stage.
|
|
9
|
+
*/
|
|
10
|
+
stageData(stageId: Id): Promise<StageData>;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the data needed to display a whole tournament with all its stages.
|
|
13
|
+
*
|
|
14
|
+
* @param tournamentId ID of the tournament.
|
|
15
|
+
*/
|
|
16
|
+
tournamentData(tournamentId: Id): Promise<StageData>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the match games associated to a list of matches.
|
|
19
|
+
*
|
|
20
|
+
* @param matches A list of matches.
|
|
21
|
+
*/
|
|
22
|
+
matchGames(matches: Match[]): Promise<MatchGame[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the stage that is not completed yet, because of uncompleted matches.
|
|
25
|
+
* If all matches are completed in this tournament, there is no "current stage", so `null` is returned.
|
|
26
|
+
*
|
|
27
|
+
* @param tournamentId ID of the tournament.
|
|
28
|
+
*/
|
|
29
|
+
currentStage(tournamentId: Id): Promise<Stage | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the round that is not completed yet, because of uncompleted matches.
|
|
32
|
+
* If all matches are completed in this stage of a tournament, there is no "current round", so `null` is returned.
|
|
33
|
+
*
|
|
34
|
+
* Note: The consolation final of single elimination and the grand final of double elimination will be in a different `Group`.
|
|
35
|
+
*
|
|
36
|
+
* @param stageId ID of the stage.
|
|
37
|
+
* @example
|
|
38
|
+
* If you don't know the stage id, you can first get the current stage.
|
|
39
|
+
* ```js
|
|
40
|
+
* const tournamentId = 3;
|
|
41
|
+
* const currentStage = await manager.get.currentStage(tournamentId);
|
|
42
|
+
* const currentRound = await manager.get.currentRound(currentStage.id);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
currentRound(stageId: Id): Promise<Round | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the matches that can currently be played in parallel.
|
|
48
|
+
* If the stage doesn't contain any, an empty array is returned.
|
|
49
|
+
*
|
|
50
|
+
* Note:
|
|
51
|
+
* - Returned matches are ongoing (i.e. ready or running).
|
|
52
|
+
* - Returned matches can be from different rounds.
|
|
53
|
+
*
|
|
54
|
+
* @param stageId ID of the stage.
|
|
55
|
+
* @example
|
|
56
|
+
* If you don't know the stage id, you can first get the current stage.
|
|
57
|
+
* ```js
|
|
58
|
+
* const tournamentId = 3;
|
|
59
|
+
* const currentStage = await manager.get.currentStage(tournamentId);
|
|
60
|
+
* const currentMatches = await manager.get.currentMatches(currentStage.id);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
currentMatches(stageId: Id): Promise<Match[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the seeding of a stage.
|
|
66
|
+
*
|
|
67
|
+
* @param stageId ID of the stage.
|
|
68
|
+
*/
|
|
69
|
+
seeding(stageId: Id): Promise<ParticipantSlot[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the final standings of an elimination stage.
|
|
72
|
+
*
|
|
73
|
+
* @param stageId ID of the stage.
|
|
74
|
+
*/
|
|
75
|
+
finalStandings(stageId: Id): Promise<FinalStandingsItem[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the final standings of a round-robin stage with a ranking formula.
|
|
78
|
+
*
|
|
79
|
+
* @param stageId ID of the stage.
|
|
80
|
+
* @param rankingFormula The formula to compute the points for the ranking.
|
|
81
|
+
*/
|
|
82
|
+
finalStandings(stageId: Id, roundRobinOptions: RoundRobinFinalStandingsOptions): Promise<RankingItem[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the seeding of a round-robin stage.
|
|
85
|
+
*
|
|
86
|
+
* @param stage The stage.
|
|
87
|
+
*/
|
|
88
|
+
private roundRobinSeeding;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the seeding of an elimination stage.
|
|
91
|
+
*
|
|
92
|
+
* @param stage The stage.
|
|
93
|
+
*/
|
|
94
|
+
private eliminationSeeding;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the final standings of a round-robin stage.
|
|
97
|
+
*
|
|
98
|
+
* @param stage The stage.
|
|
99
|
+
* @param roundRobinOptions The options for the round-robin standings.
|
|
100
|
+
*/
|
|
101
|
+
private roundRobinStandings;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the final standings of a single elimination stage.
|
|
104
|
+
*
|
|
105
|
+
* @param stage The stage.
|
|
106
|
+
*/
|
|
107
|
+
private singleEliminationStandings;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the final standings of a double elimination stage.
|
|
110
|
+
*
|
|
111
|
+
* @param stage The stage.
|
|
112
|
+
*/
|
|
113
|
+
private doubleEliminationStandings;
|
|
114
|
+
/**
|
|
115
|
+
* Returns only the data specific to the given stage (without the participants).
|
|
116
|
+
*
|
|
117
|
+
* @param stageId ID of the stage.
|
|
118
|
+
*/
|
|
119
|
+
private getStageSpecificData;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=get.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../src/get.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAEL,KAAK,EACL,KAAK,EACL,SAAS,EAGT,EAAE,EACF,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,kBAAkB,EAClB,eAAe,EACf,SAAS,EAET,KAAK,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