tods-competition-factory 7.34.0 → 7.35.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/dist/esm/assemblies/generators/drawDefinitions/drawTypes/adHoc/rotatingPartners/generateRotatingPartnerRound.mjs +6 -6
- package/dist/esm/assemblies/generators/drawDefinitions/drawTypes/adHoc/rotatingPartners/getRotatingPartnerRoundPreview.mjs +10 -2
- package/dist/esm/assemblies/generators/tournamentRecords/anonymizeTournamentRecord.mjs +29 -0
- package/dist/esm/global/state/globalState.mjs +8 -1
- package/dist/esm/global/state/noticeIdentity.mjs +28 -1
- package/dist/esm/global/state/syncGlobalState.mjs +9 -24
- package/dist/esm/helpers/rotatingPartners/scoringContract.mjs +128 -0
- package/dist/esm/mutate/drawDefinitions/competitionProfile.mjs +24 -3
- package/dist/esm/mutate/matchUps/matchUpStatus/reconcileScoredTimes.mjs +7 -1
- package/dist/esm/mutate/matchUps/matchUpStatus/setMatchUpState.mjs +5 -5
- package/dist/esm/mutate/matchUps/matchUpStatus/setMatchUpStatus.mjs +92 -89
- package/dist/esm/mutate/matchUps/outcome/apply.mjs +116 -7
- package/dist/esm/mutate/matchUps/outcome/decide.mjs +62 -20
- package/dist/esm/mutate/matchUps/outcome/differential.mjs +3 -1
- package/dist/esm/mutate/matchUps/outcome/ops.mjs +58 -26
- package/dist/esm/mutate/matchUps/outcome/overlay.mjs +4 -2
- package/dist/esm/mutate/matchUps/outcome/plan/byeChain.mjs +306 -79
- package/dist/esm/mutate/matchUps/outcome/plan/carriedByeSeat.mjs +85 -173
- package/dist/esm/mutate/matchUps/outcome/plan/convergence.mjs +1 -3
- package/dist/esm/mutate/matchUps/outcome/plan/producedExit.mjs +6 -4
- package/dist/esm/mutate/matchUps/outcome/plan.mjs +31 -11
- package/dist/esm/mutate/matchUps/outcome/shadow.mjs +338 -2
- package/dist/esm/mutate/matchUps/outcome/view.mjs +19 -1
- package/dist/esm/mutate/matchUps/score/modifyMatchUpScore.mjs +2 -2
- package/dist/esm/mutate/notifications/drawNotifications.mjs +36 -24
- package/dist/esm/package.json.mjs +1 -1
- package/dist/esm/query/drawDefinition/appliedRotatingPartnerRoundsAreIntact.mjs +9 -3
- package/dist/esm/query/drawDefinition/getRotatingPartnerScoringContract.mjs +4 -4
- package/dist/esm/query/drawDefinition/getRotatingPartnerScoringPolicy.mjs +25 -20
- package/dist/esm/query/drawDefinition/getRotatingPartnerStandings.mjs +18 -4
- package/dist/esm/query/drawDefinition/resolveRotatingPartnerOutcome.mjs +37 -17
- package/dist/esm/tools/clock.mjs +49 -8
- package/dist/esm/tools/cloneState.mjs +3 -2
- package/dist/esm/validators/competitionProfile.mjs +2 -7
- package/dist/esm/validators/tiedFormatCompatibility.mjs +2 -2
- package/dist/schema/tournament.schema.json +363 -101
- package/dist/tods-competition-factory.d.cts +71 -30
- package/dist/tods-competition-factory.d.mts +71 -30
- package/dist/tods-competition-factory.d.ts +71 -30
- package/dist/tods-competition-factory.development.cjs.js +1606 -629
- package/dist/tods-competition-factory.development.cjs.js.map +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js +1 -1
- package/dist/tods-competition-factory.production.cjs.min.js.map +1 -1
- package/package.json +21 -21
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { generateAdHocMatchUps } from '../generateAdHocMatchUps.mjs';
|
|
2
|
-
import { stringifyCombinedPointFormat } from '../../../../../../helpers/matchUpFormatCode/combinedPointFormat.mjs';
|
|
3
2
|
import { addMatchUpsNotice, modifyDrawNotice } from '../../../../../../mutate/notifications/drawNotifications.mjs';
|
|
4
3
|
import { checkMutationLock } from '../../../../../../mutate/tournaments/mutationLocks/checkMutationLock.mjs';
|
|
5
4
|
import { addAdHocMatchUps } from '../../../../../../mutate/structures/addAdHocMatchUps.mjs';
|
|
6
5
|
import { addParticipant } from '../../../../../../mutate/participants/addParticipant.mjs';
|
|
7
6
|
import { matchUpsOf } from '../../../../../../helpers/drawTopology/structureMembers.mjs';
|
|
8
7
|
import { addNotice } from '../../../../../../global/state/globalState.mjs';
|
|
8
|
+
import { sameRotatingPartnerScoreContract, rotatingPartnerContractFormat } from '../../../../../../helpers/rotatingPartners/scoringContract.mjs';
|
|
9
9
|
import { getRotatingPartnerRoundPreview } from './getRotatingPartnerRoundPreview.mjs';
|
|
10
10
|
import { INVALID_VALUES } from '../../../../../../constants/errorConditionConstants.mjs';
|
|
11
11
|
import { ADD_PARTICIPANTS } from '../../../../../../constants/topicConstants.mjs';
|
|
@@ -28,7 +28,7 @@ function generateRotatingPartnerRound(params) {
|
|
|
28
28
|
if (prior) {
|
|
29
29
|
if (prior.roundNumber !== roundNumber ||
|
|
30
30
|
canonicalJson(prior.pairings) !== canonicalJson(expectedPairings) ||
|
|
31
|
-
|
|
31
|
+
!sameRotatingPartnerScoreContract(prior.scoringContract, expectedScoringContract) ||
|
|
32
32
|
(params.structureId && params.structureId !== prior.structureId))
|
|
33
33
|
return { error: INVALID_VALUES, info: 'requestId already used for a different round request' };
|
|
34
34
|
const matches = (drawDefinition.structures ?? [])
|
|
@@ -42,7 +42,7 @@ function generateRotatingPartnerRound(params) {
|
|
|
42
42
|
if (preview.error)
|
|
43
43
|
return preview;
|
|
44
44
|
if (canonicalJson(preview.round) !== canonicalJson(expectedPairings) ||
|
|
45
|
-
|
|
45
|
+
!sameRotatingPartnerScoreContract(preview.scoringContract, expectedScoringContract))
|
|
46
46
|
return { error: INVALID_VALUES, info: 'stale rotating-partner round preview' };
|
|
47
47
|
const staged = copyRoundData(tournamentRecord);
|
|
48
48
|
const stagedEvent = staged.events?.find((candidate) => candidate.eventId === event.eventId);
|
|
@@ -86,11 +86,11 @@ function generateRotatingPartnerRound(params) {
|
|
|
86
86
|
if (generated.error)
|
|
87
87
|
return generated;
|
|
88
88
|
const matchUps = generated.matchUps;
|
|
89
|
-
const
|
|
90
|
-
if (!
|
|
89
|
+
const format = rotatingPartnerContractFormat(preview.scoringContract);
|
|
90
|
+
if (!format)
|
|
91
91
|
return { error: INVALID_VALUES };
|
|
92
92
|
matchUps.forEach((matchUp) => {
|
|
93
|
-
matchUp.matchUpFormat =
|
|
93
|
+
matchUp.matchUpFormat = format;
|
|
94
94
|
});
|
|
95
95
|
const inserted = addAdHocMatchUps({
|
|
96
96
|
tournamentRecord: staged,
|
|
@@ -4,6 +4,7 @@ import { appliedRotatingPartnerRoundsAreIntact } from '../../../../../../query/d
|
|
|
4
4
|
import { getAvailableMatchUpsCount } from '../getAvailableMatchUpsCount.mjs';
|
|
5
5
|
import { getRotatingPartnerScoringContract } from '../../../../../../query/drawDefinition/getRotatingPartnerScoringContract.mjs';
|
|
6
6
|
import { isRotatingPartnerDraw, validateRotatingPartnerEntrants } from '../../../../../../validators/rotatingPartnerDraw.mjs';
|
|
7
|
+
import { getRotatingPartnerScoringPolicy } from '../../../../../../query/drawDefinition/getRotatingPartnerScoringPolicy.mjs';
|
|
7
8
|
import { getRotatingPartnerTallyPolicy } from '../../../../../../query/drawDefinition/getRotatingPartnerTallyPolicy.mjs';
|
|
8
9
|
import { getRotatingPartnerStandings } from '../../../../../../query/drawDefinition/getRotatingPartnerStandings.mjs';
|
|
9
10
|
import { checkValidEntries } from '../../../../../../query/entries/checkValidEntries.mjs';
|
|
@@ -55,10 +56,10 @@ function getRotatingPartnerRoundPreview(params) {
|
|
|
55
56
|
if (existing.length &&
|
|
56
57
|
existing.some((matchUp) => !drawDefinition.competitionRounds?.some((round) => round.matchUpIds.includes(matchUp.matchUpId))))
|
|
57
58
|
return { error: INVALID_VALUES, info: 'existing matches have no rotating-partner provenance' };
|
|
58
|
-
const
|
|
59
|
+
const structure = drawDefinition.structures?.find((candidate) => candidate.structureId === structureId);
|
|
60
|
+
const scoring = approvedScoring({ ...params, structure });
|
|
59
61
|
if (scoring.error)
|
|
60
62
|
return scoring;
|
|
61
|
-
const structure = drawDefinition.structures?.find((candidate) => candidate.structureId === structureId);
|
|
62
63
|
const tally = getRotatingPartnerTallyPolicy({ ...params, structure });
|
|
63
64
|
if (tally.error)
|
|
64
65
|
return tally;
|
|
@@ -103,5 +104,12 @@ function getRotatingPartnerRoundPreview(params) {
|
|
|
103
104
|
seedUsed: generated.seedUsed,
|
|
104
105
|
};
|
|
105
106
|
}
|
|
107
|
+
function approvedScoring(params) {
|
|
108
|
+
const saved = getRotatingPartnerScoringContract(params);
|
|
109
|
+
if (saved.error)
|
|
110
|
+
return saved;
|
|
111
|
+
const governing = getRotatingPartnerScoringPolicy(params);
|
|
112
|
+
return governing.error ? governing : saved;
|
|
113
|
+
}
|
|
106
114
|
|
|
107
115
|
export { appliedRotatingPartnerRoundsAreIntact, getRotatingPartnerRoundPreview };
|
|
@@ -60,6 +60,7 @@ function anonymizeTournamentRecord(params) {
|
|
|
60
60
|
forEachMatchUp(record, anonymizeMatchUp);
|
|
61
61
|
anonymizeIndividualPersons({ record, context, anonymizeParticipantNames, newPersonIds });
|
|
62
62
|
anonymizeGroupedParticipants({ record, random });
|
|
63
|
+
anonymizeTeamNames(record, anonymizeParticipantNames);
|
|
63
64
|
remapReferences(record, context.idMap);
|
|
64
65
|
return { ...SUCCESS, tournamentRecord: record };
|
|
65
66
|
}
|
|
@@ -126,6 +127,8 @@ function mapAdditionalDefinedIds(node, add) {
|
|
|
126
127
|
if (!node || typeof node !== 'object')
|
|
127
128
|
return undefined;
|
|
128
129
|
for (const [key, value] of Object.entries(node)) {
|
|
130
|
+
if (key === 'teamId')
|
|
131
|
+
add(value);
|
|
129
132
|
const idKey = ADDITIONAL_ID_COLLECTIONS.get(key);
|
|
130
133
|
if (idKey && Array.isArray(value)) {
|
|
131
134
|
for (const entry of value)
|
|
@@ -137,6 +140,32 @@ function mapAdditionalDefinedIds(node, add) {
|
|
|
137
140
|
}
|
|
138
141
|
return undefined;
|
|
139
142
|
}
|
|
143
|
+
function anonymizeTeamNames(record, enabled) {
|
|
144
|
+
if (!enabled)
|
|
145
|
+
return;
|
|
146
|
+
const labels = new Map();
|
|
147
|
+
const visit = (node) => {
|
|
148
|
+
if (!node || typeof node !== 'object')
|
|
149
|
+
return;
|
|
150
|
+
if (Array.isArray(node)) {
|
|
151
|
+
node.forEach(visit);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const team = node;
|
|
155
|
+
for (const key of ['teamName', 'nativeTeamName', 'jerseyName']) {
|
|
156
|
+
if (typeof team[key] !== 'string')
|
|
157
|
+
continue;
|
|
158
|
+
const identity = typeof team.teamId === 'string' ? team.teamId : team[key];
|
|
159
|
+
if (!labels.has(identity))
|
|
160
|
+
labels.set(identity, `Team ${labels.size + 1}`);
|
|
161
|
+
team[key] = labels.get(identity);
|
|
162
|
+
}
|
|
163
|
+
delete team.otherTeamNames;
|
|
164
|
+
delete team.previousTeamNames;
|
|
165
|
+
Object.values(team).forEach(visit);
|
|
166
|
+
};
|
|
167
|
+
visit(record);
|
|
168
|
+
}
|
|
140
169
|
function forEachMatchUp(record, fn) {
|
|
141
170
|
const visitMatchUps = (matchUps = []) => {
|
|
142
171
|
for (const matchUp of matchUps) {
|
|
@@ -394,6 +394,13 @@ function deleteNotice({ key, topic }) {
|
|
|
394
394
|
function deleteNotices() {
|
|
395
395
|
return _globalStateProvider.deleteNotices();
|
|
396
396
|
}
|
|
397
|
+
function getNoticeState() {
|
|
398
|
+
const state = _globalStateProvider.getNoticeState?.();
|
|
399
|
+
return (state && {
|
|
400
|
+
...state,
|
|
401
|
+
globalSubscriptions: Object.fromEntries(Object.entries(globalState.globalSubscriptions).map(([topic, subscription]) => [topic, !!subscription])),
|
|
402
|
+
});
|
|
403
|
+
}
|
|
397
404
|
function getNoticeBuffer() {
|
|
398
405
|
return isFunction(_globalStateProvider.getNoticeBuffer) ? _globalStateProvider.getNoticeBuffer() : undefined;
|
|
399
406
|
}
|
|
@@ -485,4 +492,4 @@ function setStateMethods(submittedMethods, traverse, maxDepth, global) {
|
|
|
485
492
|
return { methods };
|
|
486
493
|
}
|
|
487
494
|
|
|
488
|
-
export { DEFERRED_PAYLOAD, addNotice, callListener, clearMutationStatus, createInstanceState, cycleModifiedTopics, cycleModifiedTournamentIds, cycleMutationStatus, deepCopyEnabled, deleteNotice, deleteNotices, disableNotifications, enableNotifications, getAuditAuthorityServer, getCallRandomSource, getCapturedClock, getCapturedCompetitionClock, getCapturedStamps, getDevContext, getFactoryBackend, getInvokeObserver, getMethods, getNoticeBuffer, getNotices, getOutcomePipeline, getPayloads, getProvider, getSaveDrawDeletions, getSchemaWriteMode, getStampScope, getTopics, getTournamentId, getTournamentRecord, getTournamentRecords, globalLog, handleCaughtError, hasTopic, markModified, readMutationStatus, removeTournamentRecord, restoreMutationStatus, setAuditAuthorityServer, setCallRandomSource, setCapturedClock, setCapturedCompetitionClock, setCapturedStamps, setDeepCopy, setDevContext, setFactoryBackend, setGlobalLog, setGlobalMethods, setGlobalSubscriptions, setInvokeObserver, setMethods, setNoticeBuffer, setOutcomePipeline, setSaveDrawDeletions, setSchemaWriteMode, setStampScope, setStateMethods, setStateProvider, setSubscriptions, setTournamentId, setTournamentRecord, setTournamentRecords, timeKeeper, writeLegacyEnabled, writeNativeEnabled };
|
|
495
|
+
export { DEFERRED_PAYLOAD, addNotice, callListener, clearMutationStatus, createInstanceState, cycleModifiedTopics, cycleModifiedTournamentIds, cycleMutationStatus, deepCopyEnabled, deleteNotice, deleteNotices, disableNotifications, enableNotifications, getAuditAuthorityServer, getCallRandomSource, getCapturedClock, getCapturedCompetitionClock, getCapturedStamps, getDevContext, getFactoryBackend, getInvokeObserver, getMethods, getNoticeBuffer, getNoticeState, getNotices, getOutcomePipeline, getPayloads, getProvider, getSaveDrawDeletions, getSchemaWriteMode, getStampScope, getTopics, getTournamentId, getTournamentRecord, getTournamentRecords, globalLog, handleCaughtError, hasTopic, markModified, readMutationStatus, removeTournamentRecord, restoreMutationStatus, setAuditAuthorityServer, setCallRandomSource, setCapturedClock, setCapturedCompetitionClock, setCapturedStamps, setDeepCopy, setDevContext, setFactoryBackend, setGlobalLog, setGlobalMethods, setGlobalSubscriptions, setInvokeObserver, setMethods, setNoticeBuffer, setOutcomePipeline, setSaveDrawDeletions, setSchemaWriteMode, setStampScope, setStateMethods, setStateProvider, setSubscriptions, setTournamentId, setTournamentRecord, setTournamentRecords, timeKeeper, writeLegacyEnabled, writeNativeEnabled };
|
|
@@ -1,5 +1,32 @@
|
|
|
1
|
+
import { SUCCESS } from '../../constants/resultConstants.mjs';
|
|
1
2
|
import { DATA_ISSUE, AUDIT, ADD_MATCHUPS, DELETED_MATCHUP_IDS, MODIFY_DRAW_DEFINITION, MODIFY_DRAW_ENTRIES, MODIFY_MATCHUP, MODIFY_POSITION_ASSIGNMENTS, MODIFY_SEED_ASSIGNMENTS, UPDATE_INCONTEXT_MATCHUP } from '../../constants/topicConstants.mjs';
|
|
2
3
|
|
|
4
|
+
function appendNotice(state, { topic, payload, key }, isGlobalSubscription) {
|
|
5
|
+
if (typeof topic !== 'string' || typeof payload !== 'object')
|
|
6
|
+
return;
|
|
7
|
+
if (!state.disableNotifications && noticeModifies(topic)) {
|
|
8
|
+
state.modified = true;
|
|
9
|
+
state.modifiedTournamentIds ??= new Set();
|
|
10
|
+
state.modifiedTournamentIds.add(modifiedTournamentId(payload));
|
|
11
|
+
state.modifiedTopics ??= new Set();
|
|
12
|
+
state.modifiedTopics.add(topic || UNANNOUNCED_WRITE);
|
|
13
|
+
}
|
|
14
|
+
if (state.disableNotifications || (!state.subscriptions[topic] && !isGlobalSubscription))
|
|
15
|
+
return;
|
|
16
|
+
let outgoing = payload;
|
|
17
|
+
if (key) {
|
|
18
|
+
const retained = [];
|
|
19
|
+
for (const notice of state.notices) {
|
|
20
|
+
if (notice.topic === topic && notice.key === key)
|
|
21
|
+
outgoing = preserveNoticeIdentity(outgoing, notice.payload);
|
|
22
|
+
else
|
|
23
|
+
retained.push(notice);
|
|
24
|
+
}
|
|
25
|
+
state.notices = retained;
|
|
26
|
+
}
|
|
27
|
+
state.notices.push({ topic, payload: outgoing, key });
|
|
28
|
+
return { ...SUCCESS };
|
|
29
|
+
}
|
|
3
30
|
const NOTICE_IDENTITY_FIELDS = [
|
|
4
31
|
'tournamentId',
|
|
5
32
|
'eventId',
|
|
@@ -48,4 +75,4 @@ function modifiedOutsideDraws(topics) {
|
|
|
48
75
|
return [...topics].some((topic) => !DRAW_TOPICS.has(topic));
|
|
49
76
|
}
|
|
50
77
|
|
|
51
|
-
export { NOTICE_IDENTITY_FIELDS, UNANNOUNCED_WRITE, UNNAMED_TOURNAMENT, modifiedOutsideDraws, modifiedTournamentId, noticeModifies, preserveNoticeIdentity };
|
|
78
|
+
export { NOTICE_IDENTITY_FIELDS, UNANNOUNCED_WRITE, UNNAMED_TOURNAMENT, appendNotice, modifiedOutsideDraws, modifiedTournamentId, noticeModifies, preserveNoticeIdentity };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UNNAMED_TOURNAMENT, UNANNOUNCED_WRITE,
|
|
1
|
+
import { UNNAMED_TOURNAMENT, UNANNOUNCED_WRITE, appendNotice } from './noticeIdentity.mjs';
|
|
2
2
|
import { SUCCESS } from '../../constants/resultConstants.mjs';
|
|
3
3
|
import { INVALID_TOURNAMENT_RECORD, MISSING_TOURNAMENT_RECORD, INVALID_VALUES, NOT_FOUND } from '../../constants/errorConditionConstants.mjs';
|
|
4
4
|
|
|
@@ -34,6 +34,7 @@ var syncGlobalState$1 = {
|
|
|
34
34
|
enableNotifications,
|
|
35
35
|
getMethods,
|
|
36
36
|
getNoticeBuffer,
|
|
37
|
+
getNoticeState,
|
|
37
38
|
getNotices,
|
|
38
39
|
getPayloads: getNotices,
|
|
39
40
|
getTopics,
|
|
@@ -189,28 +190,12 @@ function cycleModifiedTopics() {
|
|
|
189
190
|
function setMutationStatus(status) {
|
|
190
191
|
syncGlobalState.modified = status;
|
|
191
192
|
}
|
|
192
|
-
function addNotice(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return;
|
|
199
|
-
let outgoing = payload;
|
|
200
|
-
if (key) {
|
|
201
|
-
const retained = [];
|
|
202
|
-
for (const notice of syncGlobalState.notices) {
|
|
203
|
-
if (notice.topic === topic && notice.key === key) {
|
|
204
|
-
outgoing = preserveNoticeIdentity(outgoing, notice.payload);
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
retained.push(notice);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
syncGlobalState.notices = retained;
|
|
211
|
-
}
|
|
212
|
-
syncGlobalState.notices.push({ topic, payload: outgoing, key });
|
|
213
|
-
return { ...SUCCESS };
|
|
193
|
+
function addNotice(notice, isGlobalSubscription) {
|
|
194
|
+
return appendNotice(syncGlobalState, notice, isGlobalSubscription);
|
|
195
|
+
}
|
|
196
|
+
function getNoticeState() {
|
|
197
|
+
const { disableNotifications, subscriptions, notices, modified, modifiedTournamentIds, modifiedTopics } = syncGlobalState;
|
|
198
|
+
return { disableNotifications, subscriptions, notices, modified, modifiedTournamentIds, modifiedTopics };
|
|
214
199
|
}
|
|
215
200
|
function getMethods() {
|
|
216
201
|
return syncGlobalState.methods ?? {};
|
|
@@ -261,4 +246,4 @@ function handleCaughtError({ engineName, methodName, params, err }) {
|
|
|
261
246
|
return { error };
|
|
262
247
|
}
|
|
263
248
|
|
|
264
|
-
export { addNotice, callListener, cycleModifiedTopics, cycleModifiedTournamentIds, cycleMutationStatus, syncGlobalState$1 as default, deleteNotice, deleteNotices, disableNotifications, enableNotifications, getCallRandomSource, getCapturedClock, getCapturedCompetitionClock, getCapturedStamps, getMethods, getNoticeBuffer, getNotices, getTopics, getTournamentId, getTournamentRecord, getTournamentRecords, handleCaughtError, markModified, removeTournamentRecord, setCallRandomSource, setCapturedClock, setCapturedCompetitionClock, setCapturedStamps, setMethods, setMutationStatus, setNoticeBuffer, setSubscriptions, setTournamentId, setTournamentRecord, setTournamentRecords };
|
|
249
|
+
export { addNotice, callListener, cycleModifiedTopics, cycleModifiedTournamentIds, cycleMutationStatus, syncGlobalState$1 as default, deleteNotice, deleteNotices, disableNotifications, enableNotifications, getCallRandomSource, getCapturedClock, getCapturedCompetitionClock, getCapturedStamps, getMethods, getNoticeBuffer, getNoticeState, getNotices, getTopics, getTournamentId, getTournamentRecord, getTournamentRecords, handleCaughtError, markModified, removeTournamentRecord, setCallRandomSource, setCapturedClock, setCapturedCompetitionClock, setCapturedStamps, setMethods, setMutationStatus, setNoticeBuffer, setSubscriptions, setTournamentId, setTournamentRecord, setTournamentRecords };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { stringifyCombinedPointFormat } from '../matchUpFormatCode/combinedPointFormat.mjs';
|
|
2
|
+
import { isRotatingPartnerTallyPolicy } from '../../validators/rotatingPartnerTallyPolicy.mjs';
|
|
3
|
+
import { canonicalJson } from '../../tools/canonicalJson.mjs';
|
|
4
|
+
import { isRotatingPartnerScoringVariant, isRotatingPartnerScoringPolicy, sameScoringVariant } from '../../validators/rotatingPartnerScoringPolicy.mjs';
|
|
5
|
+
import { INVALID_VALUES } from '../../constants/errorConditionConstants.mjs';
|
|
6
|
+
import { SUCCESS } from '../../constants/resultConstants.mjs';
|
|
7
|
+
|
|
8
|
+
function object(value) {
|
|
9
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function objectWithKeys(value, required, optional = []) {
|
|
12
|
+
const keys = new Set([...required, ...optional]);
|
|
13
|
+
return (object(value) &&
|
|
14
|
+
required.every((key) => Object.hasOwn(value, key)) &&
|
|
15
|
+
Object.keys(value).every((key) => keys.has(key)));
|
|
16
|
+
}
|
|
17
|
+
function positiveInteger(value) {
|
|
18
|
+
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
19
|
+
}
|
|
20
|
+
function isTimedVariant(value) {
|
|
21
|
+
return (objectWithKeys(value, ['tieResolution']) &&
|
|
22
|
+
(value.tieResolution === 'ALLOW' || value.tieResolution === 'DECIDING_POINT'));
|
|
23
|
+
}
|
|
24
|
+
function isRotatingPartnerScoringConfiguration(value) {
|
|
25
|
+
if (!object(value))
|
|
26
|
+
return false;
|
|
27
|
+
if (value.kind === 'TIMED') {
|
|
28
|
+
return (objectWithKeys(value, ['kind', 'minutes'], ['selectedVariant']) &&
|
|
29
|
+
positiveInteger(value.minutes) &&
|
|
30
|
+
(value.selectedVariant === undefined || isTimedVariant(value.selectedVariant)));
|
|
31
|
+
}
|
|
32
|
+
return (objectWithKeys(value, ['combinedPointTotal'], ['kind', 'selectedVariant']) &&
|
|
33
|
+
(value.kind === undefined || value.kind === 'COMBINED_POINTS') &&
|
|
34
|
+
positiveInteger(value.combinedPointTotal) &&
|
|
35
|
+
(value.selectedVariant === undefined || isRotatingPartnerScoringVariant(value.selectedVariant)));
|
|
36
|
+
}
|
|
37
|
+
function isTimedPolicy(value) {
|
|
38
|
+
if (!objectWithKeys(value, ['defaultVariant', 'permittedVariants'], ['permittedMinutes']))
|
|
39
|
+
return false;
|
|
40
|
+
const { defaultVariant, permittedVariants, permittedMinutes } = value;
|
|
41
|
+
return (isTimedVariant(defaultVariant) &&
|
|
42
|
+
Array.isArray(permittedVariants) &&
|
|
43
|
+
permittedVariants.length > 0 &&
|
|
44
|
+
permittedVariants.every(isTimedVariant) &&
|
|
45
|
+
permittedVariants.some((variant) => sameScoringVariant(variant, defaultVariant)) &&
|
|
46
|
+
new Set(permittedVariants.map((variant) => variant.tieResolution)).size === permittedVariants.length &&
|
|
47
|
+
(permittedMinutes === undefined ||
|
|
48
|
+
(Array.isArray(permittedMinutes) &&
|
|
49
|
+
permittedMinutes.length > 0 &&
|
|
50
|
+
permittedMinutes.every(positiveInteger) &&
|
|
51
|
+
new Set(permittedMinutes).size === permittedMinutes.length)));
|
|
52
|
+
}
|
|
53
|
+
function isRotatingPartnerScoringPolicyWithTimed(value) {
|
|
54
|
+
if (!objectWithKeys(value, ['defaultVariant', 'permittedVariants'], ['permittedPointTotals', 'timed']))
|
|
55
|
+
return false;
|
|
56
|
+
const { timed, ...combined } = value;
|
|
57
|
+
return isRotatingPartnerScoringPolicy(combined) && (!Object.hasOwn(value, 'timed') || isTimedPolicy(timed));
|
|
58
|
+
}
|
|
59
|
+
function normalizeRotatingPartnerScoreContract(value) {
|
|
60
|
+
if (!object(value))
|
|
61
|
+
return undefined;
|
|
62
|
+
if (value.kind === 'TIMED') {
|
|
63
|
+
if (!objectWithKeys(value, ['kind', 'minutes', 'tieResolution']))
|
|
64
|
+
return undefined;
|
|
65
|
+
const variant = { tieResolution: value.tieResolution };
|
|
66
|
+
if (!positiveInteger(value.minutes) || !isTimedVariant(variant))
|
|
67
|
+
return undefined;
|
|
68
|
+
return { kind: 'TIMED', minutes: value.minutes, ...variant };
|
|
69
|
+
}
|
|
70
|
+
if (!objectWithKeys(value, ['combinedPointTotal', 'tieResolution'], ['kind', 'winningMargin']))
|
|
71
|
+
return undefined;
|
|
72
|
+
const { kind, combinedPointTotal, ...selectedVariant } = value;
|
|
73
|
+
if ((kind !== undefined && kind !== 'COMBINED_POINTS') ||
|
|
74
|
+
!positiveInteger(combinedPointTotal) ||
|
|
75
|
+
!isRotatingPartnerScoringVariant(selectedVariant))
|
|
76
|
+
return undefined;
|
|
77
|
+
return { combinedPointTotal, ...selectedVariant };
|
|
78
|
+
}
|
|
79
|
+
function rotatingPartnerContractFormat(value) {
|
|
80
|
+
const contract = normalizeRotatingPartnerScoreContract(value);
|
|
81
|
+
if (!contract)
|
|
82
|
+
return undefined;
|
|
83
|
+
return contract.kind === 'TIMED'
|
|
84
|
+
? `SET1-S:T${contract.minutes}P${contract.tieResolution === 'DECIDING_POINT' ? '/TB1' : ''}`
|
|
85
|
+
: `SET1-S:${stringifyCombinedPointFormat(contract)}`;
|
|
86
|
+
}
|
|
87
|
+
function sameRotatingPartnerScoreContract(a, b) {
|
|
88
|
+
const left = normalizeRotatingPartnerScoreContract(a);
|
|
89
|
+
const right = normalizeRotatingPartnerScoreContract(b);
|
|
90
|
+
return !!left && !!right && canonicalJson(left) === canonicalJson(right);
|
|
91
|
+
}
|
|
92
|
+
function validTimedRotatingPartnerPoints(score) {
|
|
93
|
+
return (score.sets?.length === 1 &&
|
|
94
|
+
[score.sets[0].side1Score, score.sets[0].side2Score].every((points) => typeof points === 'number' && Number.isSafeInteger(points) && points >= 0));
|
|
95
|
+
}
|
|
96
|
+
function resolveRotatingPartnerScoringConfiguration(params) {
|
|
97
|
+
const { scoring, policy, tallyPolicy } = params;
|
|
98
|
+
if (!isRotatingPartnerScoringConfiguration(scoring))
|
|
99
|
+
return { error: INVALID_VALUES, info: 'invalid rotating-partner scoring configuration' };
|
|
100
|
+
if (!isRotatingPartnerScoringPolicyWithTimed(policy))
|
|
101
|
+
return { error: INVALID_VALUES, info: 'invalid rotating-partner scoring policy' };
|
|
102
|
+
if (!isRotatingPartnerTallyPolicy(tallyPolicy))
|
|
103
|
+
return { error: INVALID_VALUES, info: 'invalid rotating-partner tally policy' };
|
|
104
|
+
const timed = scoring.kind === 'TIMED';
|
|
105
|
+
const rules = timed ? policy.timed : policy;
|
|
106
|
+
if (!rules)
|
|
107
|
+
return { error: INVALID_VALUES, info: 'timed rotating-partner scoring is not enabled' };
|
|
108
|
+
const selected = scoring.selectedVariant ?? rules.defaultVariant;
|
|
109
|
+
if (!rules.permittedVariants.some((variant) => sameScoringVariant(variant, selected)))
|
|
110
|
+
return { error: INVALID_VALUES, info: 'scoring variant is not permitted' };
|
|
111
|
+
if (timed) {
|
|
112
|
+
if (policy.timed?.permittedMinutes && !new Set(policy.timed.permittedMinutes).has(scoring.minutes))
|
|
113
|
+
return { error: INVALID_VALUES, info: 'timed minutes are not permitted' };
|
|
114
|
+
if (selected.tieResolution === 'DECIDING_POINT' && tallyPolicy.decidingPoints === 'EXCLUDE')
|
|
115
|
+
return { error: INVALID_VALUES, info: 'timed deciding-point exclusion requires decided-result evidence' };
|
|
116
|
+
}
|
|
117
|
+
else if (policy.permittedPointTotals && !new Set(policy.permittedPointTotals).has(scoring.combinedPointTotal)) {
|
|
118
|
+
return { error: INVALID_VALUES, info: 'combined point total is not permitted' };
|
|
119
|
+
}
|
|
120
|
+
const contract = normalizeRotatingPartnerScoreContract(timed
|
|
121
|
+
? { kind: 'TIMED', minutes: scoring.minutes, ...selected }
|
|
122
|
+
: { combinedPointTotal: scoring.combinedPointTotal, ...selected });
|
|
123
|
+
if (!contract)
|
|
124
|
+
return { error: INVALID_VALUES, info: 'invalid rotating-partner scoring contract' };
|
|
125
|
+
return { ...SUCCESS, contract, selectionLocked: rules.permittedVariants.length === 1 };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { isRotatingPartnerScoringConfiguration, isRotatingPartnerScoringPolicyWithTimed, normalizeRotatingPartnerScoreContract, resolveRotatingPartnerScoringConfiguration, rotatingPartnerContractFormat, sameRotatingPartnerScoreContract, validTimedRotatingPartnerPoints };
|
|
@@ -30,7 +30,7 @@ function setCompetitionProfile(params) {
|
|
|
30
30
|
return { error: INVALID_VALUES, info: 'rotating-partner profiles require doubles' };
|
|
31
31
|
}
|
|
32
32
|
if (drawDefinition.competitionProfile &&
|
|
33
|
-
|
|
33
|
+
canonicalProfile(drawDefinition.competitionProfile) === canonicalProfile(competitionProfile))
|
|
34
34
|
return { ...SUCCESS };
|
|
35
35
|
if (competitionProfile.format !== 'LADDER' && drawDefinition.entries?.length) {
|
|
36
36
|
const validation = validateRotatingPartnerEntrants({
|
|
@@ -85,11 +85,32 @@ function setRotatingPartnerScoring(params) {
|
|
|
85
85
|
const profile = drawDefinition?.competitionProfile;
|
|
86
86
|
if (!profile || profile.format === 'LADDER' || !resolved.contract)
|
|
87
87
|
return { error: INVALID_VALUES };
|
|
88
|
-
|
|
88
|
+
if (resolved.contract.kind === 'TIMED') {
|
|
89
|
+
const { kind, minutes, ...selectedVariant } = resolved.contract;
|
|
90
|
+
return setCompetitionProfile({
|
|
91
|
+
...params,
|
|
92
|
+
competitionProfile: { ...profile, scoring: { kind, minutes, selectedVariant } },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const { combinedPointTotal, tieResolution, winningMargin } = resolved.contract;
|
|
96
|
+
const selectedVariant = winningMargin === undefined ? { tieResolution } : { tieResolution, winningMargin };
|
|
89
97
|
return setCompetitionProfile({
|
|
90
98
|
...params,
|
|
91
|
-
competitionProfile: {
|
|
99
|
+
competitionProfile: {
|
|
100
|
+
...profile,
|
|
101
|
+
scoring: {
|
|
102
|
+
...(profile.scoring.kind === 'COMBINED_POINTS' ? { kind: 'COMBINED_POINTS' } : {}),
|
|
103
|
+
combinedPointTotal,
|
|
104
|
+
selectedVariant,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
92
107
|
});
|
|
93
108
|
}
|
|
109
|
+
function canonicalProfile(profile) {
|
|
110
|
+
if (profile.format === 'LADDER')
|
|
111
|
+
return canonicalJson(profile);
|
|
112
|
+
const { kind, ...scoring } = profile.scoring;
|
|
113
|
+
return canonicalJson(kind === 'COMBINED_POINTS' ? { ...profile, scoring } : profile);
|
|
114
|
+
}
|
|
94
115
|
|
|
95
116
|
export { removeCompetitionProfile, setCompetitionProfile, setRotatingPartnerScoring };
|
|
@@ -13,6 +13,12 @@ function matchUpIsScored(matchUp) {
|
|
|
13
13
|
function hasStaleScoredTime(matchUp) {
|
|
14
14
|
return !!matchUp?.schedule?.scoredTime && !matchUpIsScored(matchUp);
|
|
15
15
|
}
|
|
16
|
+
function scoredTimeAction(matchUp, pending = false) {
|
|
17
|
+
const present = pending || !!matchUp.schedule?.scoredTime;
|
|
18
|
+
if (matchUpIsScored(matchUp))
|
|
19
|
+
return present ? 'retain' : 'initialize';
|
|
20
|
+
return present ? 'clear' : 'retain';
|
|
21
|
+
}
|
|
16
22
|
function reconcileScoredTimes({ tournamentRecord, drawDefinition, matchUps, event, }) {
|
|
17
23
|
for (const matchUp of matchUps) {
|
|
18
24
|
if (!hasStaleScoredTime(matchUp))
|
|
@@ -30,4 +36,4 @@ function reconcileScoredTimes({ tournamentRecord, drawDefinition, matchUps, even
|
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
export { hasStaleScoredTime, matchUpIsScored, reconcileScoredTimes };
|
|
39
|
+
export { hasStaleScoredTime, matchUpIsScored, reconcileScoredTimes, scoredTimeAction };
|
|
@@ -13,7 +13,7 @@ import { relabelWithoutDirection } from '../drawPositions/relabelLoserExit.mjs';
|
|
|
13
13
|
import { getProjectedDualWinningSide } from '../../../query/matchUp/getProjectedDualWinningSide.mjs';
|
|
14
14
|
import { rewritesCarriedExit } from './sideExitProvenance.mjs';
|
|
15
15
|
import { setFirstClassOrExtension } from '../../extensions/setFirstClassOrExtension.mjs';
|
|
16
|
-
import {
|
|
16
|
+
import { scoredTimeAction } from './reconcileScoredTimes.mjs';
|
|
17
17
|
import { holdGoesTo, ensureGoesTo } from '../../../query/matchUps/addGoesTo.mjs';
|
|
18
18
|
import { updateTieMatchUpScore } from '../score/updateTieMatchUpScore.mjs';
|
|
19
19
|
import { isMatchUpEventType } from '../../../helpers/matchUpEventTypes/isMatchUpEventType.mjs';
|
|
@@ -533,13 +533,13 @@ function resolveAndApplyOutcome({ dualWinningSideChange, activeDownstream, apply
|
|
|
533
533
|
return decorateResult({ result, stack });
|
|
534
534
|
}
|
|
535
535
|
function applyScoredTime({ matchUp }) {
|
|
536
|
-
|
|
536
|
+
const action = scoredTimeAction(matchUp);
|
|
537
|
+
if (action === 'initialize') {
|
|
537
538
|
if (!matchUp.schedule)
|
|
538
539
|
matchUp.schedule = {};
|
|
539
|
-
|
|
540
|
-
matchUp.schedule.scoredTime = nowIso();
|
|
540
|
+
matchUp.schedule.scoredTime = nowIso({ kind: 'scoredTime', target: matchUp });
|
|
541
541
|
}
|
|
542
|
-
else if (
|
|
542
|
+
else if (action === 'clear') {
|
|
543
543
|
delete matchUp.schedule.scoredTime;
|
|
544
544
|
}
|
|
545
545
|
}
|