tods-competition-factory 2.0.21 → 2.0.23
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/index.mjs +6 -6
- package/dist/tods-competition-factory.d.ts +115 -79
- package/dist/tods-competition-factory.development.cjs.js +2077 -1997
- 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 +9 -9
|
@@ -3,7 +3,517 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function factoryVersion() {
|
|
6
|
-
return '2.0.
|
|
6
|
+
return '2.0.23';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const validDateString = /^[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])$/;
|
|
10
|
+
const validTimeString = /^((0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)([.,][0-9]{3})?$/;
|
|
11
|
+
const dateValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))([ T](0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
|
|
12
|
+
const timeValidation = /^([\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]))?([ T]?(0[\d]|1[\d]|2[0-3]):[0-5][\d](:[0-5][\d])?)?([.,][\d]{3})?Z?$/;
|
|
13
|
+
|
|
14
|
+
function getIsoDateString(schedule) {
|
|
15
|
+
let { scheduledDate } = schedule;
|
|
16
|
+
if (!scheduledDate && schedule.scheduledTime)
|
|
17
|
+
scheduledDate = extractDate(schedule.scheduledTime);
|
|
18
|
+
if (!scheduledDate)
|
|
19
|
+
return;
|
|
20
|
+
const extractedTime = extractTime(schedule.scheduledTime);
|
|
21
|
+
let isoDateString = extractDate(scheduledDate);
|
|
22
|
+
if (isoDateString && extractedTime)
|
|
23
|
+
isoDateString += `T${extractedTime}`;
|
|
24
|
+
return isoDateString;
|
|
25
|
+
}
|
|
26
|
+
function isDateObject(value) {
|
|
27
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const datePrototype = Object.prototype.toString.call(value);
|
|
32
|
+
return datePrototype === '[object Date]';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function validTimeValue(value) {
|
|
36
|
+
const spaceSplit = typeof value === 'string' ? value?.split(' ') : [];
|
|
37
|
+
if (value && spaceSplit?.length > 1 && !['AM', 'PM'].includes(spaceSplit[1].toUpperCase()))
|
|
38
|
+
return false;
|
|
39
|
+
return !!(!value || timeValidation.test(convertTime(value, true, true)));
|
|
40
|
+
}
|
|
41
|
+
function isValidDateString(scheduleDate) {
|
|
42
|
+
return isISODateString(scheduleDate) || validDateString.test(scheduleDate);
|
|
43
|
+
}
|
|
44
|
+
function DateHHMM(date) {
|
|
45
|
+
const dt = new Date(date);
|
|
46
|
+
const secs = dt.getSeconds() + 60 * dt.getMinutes() + 60 * 60 * dt.getHours();
|
|
47
|
+
return HHMMSS(secs, { displaySeconds: false });
|
|
48
|
+
}
|
|
49
|
+
function HHMMSS(s, format) {
|
|
50
|
+
const secondNumber = parseInt(s, 10);
|
|
51
|
+
const hours = Math.floor(secondNumber / 3600);
|
|
52
|
+
const minutes = Math.floor((secondNumber - hours * 3600) / 60);
|
|
53
|
+
const seconds = secondNumber - hours * 3600 - minutes * 60;
|
|
54
|
+
const displaySeconds = !format || format?.displaySeconds;
|
|
55
|
+
const timeString = displaySeconds ? hours + ':' + minutes + ':' + seconds : hours + ':' + minutes;
|
|
56
|
+
return timeString.split(':').map(zeroPad).join(':');
|
|
57
|
+
}
|
|
58
|
+
const getUTCdateString = (date) => {
|
|
59
|
+
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
|
|
60
|
+
const monthNumber = dateDate.getUTCMonth() + 1;
|
|
61
|
+
const utcMonth = monthNumber < 10 ? `0${monthNumber}` : `${monthNumber}`;
|
|
62
|
+
return `${dateDate.getUTCFullYear()}-${zeroPad(utcMonth)}-${zeroPad(dateDate.getUTCDate())}`;
|
|
63
|
+
};
|
|
64
|
+
function timeUTC(date) {
|
|
65
|
+
const dateDate = isDate(date) || isISODateString(date) ? new Date(date) : new Date();
|
|
66
|
+
return Date.UTC(dateDate.getFullYear(), dateDate.getMonth(), dateDate.getDate());
|
|
67
|
+
}
|
|
68
|
+
function formatDate(date, separator = '-', format = 'YMD') {
|
|
69
|
+
if (!date)
|
|
70
|
+
return '';
|
|
71
|
+
if (typeof date === 'string' && date.indexOf('T') < 0)
|
|
72
|
+
date = date + 'T00:00';
|
|
73
|
+
const d = new Date(date);
|
|
74
|
+
let month = '' + (d.getMonth() + 1);
|
|
75
|
+
let day = '' + d.getDate();
|
|
76
|
+
const year = d.getFullYear();
|
|
77
|
+
if (month.length < 2)
|
|
78
|
+
month = '0' + month;
|
|
79
|
+
if (day.length < 2)
|
|
80
|
+
day = '0' + day;
|
|
81
|
+
if (format === 'DMY')
|
|
82
|
+
return [day, month, year].join(separator);
|
|
83
|
+
if (format === 'MDY')
|
|
84
|
+
return [month, day, year].join(separator);
|
|
85
|
+
if (format === 'YDM')
|
|
86
|
+
return [year, day, month].join(separator);
|
|
87
|
+
if (format === 'DYM')
|
|
88
|
+
return [day, year, month].join(separator);
|
|
89
|
+
if (format === 'MYD')
|
|
90
|
+
return [month, year, day].join(separator);
|
|
91
|
+
return [year, month, day].join(separator);
|
|
92
|
+
}
|
|
93
|
+
function offsetDate(date) {
|
|
94
|
+
const targetTime = date ? new Date(date) : new Date();
|
|
95
|
+
const tzDifference = targetTime.getTimezoneOffset();
|
|
96
|
+
return new Date(targetTime.getTime() - tzDifference * 60 * 1000);
|
|
97
|
+
}
|
|
98
|
+
function offsetTime(date) {
|
|
99
|
+
return offsetDate(date).getTime();
|
|
100
|
+
}
|
|
101
|
+
function isDate(dateArg) {
|
|
102
|
+
if (typeof dateArg == 'boolean')
|
|
103
|
+
return false;
|
|
104
|
+
const t = (dateArg instanceof Date && dateArg) || (!isNaN(dateArg) && new Date(dateArg)) || false;
|
|
105
|
+
return t && !isNaN(t.valueOf());
|
|
106
|
+
}
|
|
107
|
+
function generateDateRange(startDt, endDt) {
|
|
108
|
+
if (!isValidDateString(startDt) || !isValidDateString(endDt))
|
|
109
|
+
return [];
|
|
110
|
+
const startDateString = extractDate(startDt) + 'T00:00';
|
|
111
|
+
const endDateString = extractDate(endDt) + 'T00:00';
|
|
112
|
+
const startDate = new Date(startDateString);
|
|
113
|
+
const endDate = new Date(endDateString);
|
|
114
|
+
const process = isDate(endDate) && isDate(startDate) && isValidDateRange(startDate, endDate);
|
|
115
|
+
const between = [];
|
|
116
|
+
let iterations = 0;
|
|
117
|
+
if (process) {
|
|
118
|
+
const currentDate = startDate;
|
|
119
|
+
let dateSecs = currentDate.getTime();
|
|
120
|
+
while (dateSecs <= endDate.getTime() && iterations < 300) {
|
|
121
|
+
iterations += 1;
|
|
122
|
+
between.push(new Date(currentDate));
|
|
123
|
+
dateSecs = currentDate.setDate(currentDate.getDate() + 1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return between.map((date) => formatDate(date));
|
|
127
|
+
function isValidDateRange(minDate, maxDate) {
|
|
128
|
+
return minDate <= maxDate;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const re = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
132
|
+
function isISODateString(dateString) {
|
|
133
|
+
if (typeof dateString !== 'string')
|
|
134
|
+
return false;
|
|
135
|
+
return re.test(dateString);
|
|
136
|
+
}
|
|
137
|
+
function isTimeString(timeString) {
|
|
138
|
+
if (typeof timeString !== 'string')
|
|
139
|
+
return false;
|
|
140
|
+
const noZ = timeString.split('Z')[0];
|
|
141
|
+
const parts = noZ.split(':');
|
|
142
|
+
const isNumeric = parts.every((part) => !isNaN(parseInt(part)));
|
|
143
|
+
const invalid = parts.length < 2 || !isNumeric || parseInt(parts[0]) > 23 || parseInt(parts[1]) > 60;
|
|
144
|
+
return !invalid;
|
|
145
|
+
}
|
|
146
|
+
function timeStringMinutes(timeString) {
|
|
147
|
+
const validTimeString = extractTime(timeString);
|
|
148
|
+
if (!validTimeString)
|
|
149
|
+
return 0;
|
|
150
|
+
const [hours, minutes] = validTimeString.split(':').map((value) => parseInt(value));
|
|
151
|
+
return hours * 60 + minutes;
|
|
152
|
+
}
|
|
153
|
+
function dayMinutesToTimeString(totalMinutes) {
|
|
154
|
+
let hours = Math.floor(totalMinutes / 60);
|
|
155
|
+
const minutes = totalMinutes - hours * 60;
|
|
156
|
+
if (hours > 23)
|
|
157
|
+
hours = hours % 24;
|
|
158
|
+
return [zeroPad(hours), zeroPad(minutes)].join(':');
|
|
159
|
+
}
|
|
160
|
+
function tidyTime(timeString) {
|
|
161
|
+
return isTimeString(timeString) ? timeString.split(':').slice(0, 2).map(zeroPad).join(':') : undefined;
|
|
162
|
+
}
|
|
163
|
+
function extractTime(dateString) {
|
|
164
|
+
return isISODateString(dateString) && dateString.indexOf('T') > 0
|
|
165
|
+
? tidyTime(dateString.split('T').reverse()[0])
|
|
166
|
+
: tidyTime(dateString);
|
|
167
|
+
}
|
|
168
|
+
function extractDate(dateString) {
|
|
169
|
+
return isISODateString(dateString) || dateValidation.test(dateString) ? dateString.split('T')[0] : undefined;
|
|
170
|
+
}
|
|
171
|
+
function dateStringDaysChange(dateString, daysChange) {
|
|
172
|
+
const date = new Date(dateString);
|
|
173
|
+
date.setDate(date.getDate() + daysChange);
|
|
174
|
+
return extractDate(date.toISOString());
|
|
175
|
+
}
|
|
176
|
+
function splitTime(value) {
|
|
177
|
+
value = typeof value !== 'string' ? '00:00' : value;
|
|
178
|
+
const o = {}, time = {};
|
|
179
|
+
({ 0: o.time, 1: o.ampm } = value.split(' ') || []);
|
|
180
|
+
({ 0: time.hours, 1: time.minutes } = o.time.split(':') || []);
|
|
181
|
+
time.ampm = o.ampm;
|
|
182
|
+
if (isNaN(time.hours) || isNaN(time.minutes) || (time.ampm && !['AM', 'PM'].includes(time.ampm.toUpperCase())))
|
|
183
|
+
return {};
|
|
184
|
+
return time;
|
|
185
|
+
}
|
|
186
|
+
function militaryTime(value) {
|
|
187
|
+
const time = splitTime(value);
|
|
188
|
+
if (time.ampm && time.hours) {
|
|
189
|
+
if (time.ampm.toLowerCase() === 'pm' && parseInt(time.hours) < 12)
|
|
190
|
+
time.hours = ((time.hours && parseInt(time.hours)) || 0) + 12;
|
|
191
|
+
if (time.ampm.toLowerCase() === 'am' && time.hours === '12')
|
|
192
|
+
time.hours = '00';
|
|
193
|
+
}
|
|
194
|
+
const timeString = `${time.hours || '12'}:${time.minutes || '00'}`;
|
|
195
|
+
return timeString.split(':').map(zeroPad).join(':');
|
|
196
|
+
}
|
|
197
|
+
function regularTime(value) {
|
|
198
|
+
const time = splitTime(value);
|
|
199
|
+
if (typeof time === 'object' && !Object.keys(time).length)
|
|
200
|
+
return undefined;
|
|
201
|
+
if (time.ampm)
|
|
202
|
+
return value;
|
|
203
|
+
if (time.hours > 12) {
|
|
204
|
+
time.hours -= 12;
|
|
205
|
+
time.ampm = 'PM';
|
|
206
|
+
}
|
|
207
|
+
else if (time.hours === '12') {
|
|
208
|
+
time.ampm = 'PM';
|
|
209
|
+
}
|
|
210
|
+
else if (time.hours === '00') {
|
|
211
|
+
time.hours = '12';
|
|
212
|
+
time.ampm = 'AM';
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
time.ampm = 'AM';
|
|
216
|
+
}
|
|
217
|
+
if (time.hours?.[0] === '0') {
|
|
218
|
+
time.hours = time.hours.slice(1);
|
|
219
|
+
}
|
|
220
|
+
return `${time.hours || '12'}:${time.minutes || '00'} ${time.ampm}`;
|
|
221
|
+
}
|
|
222
|
+
function convertTime(value, time24, keepDate) {
|
|
223
|
+
const hasDate = extractDate(value);
|
|
224
|
+
const timeString = extractTime(value);
|
|
225
|
+
const timeValue = hasDate ? timeString : value;
|
|
226
|
+
return !value
|
|
227
|
+
? undefined
|
|
228
|
+
: (time24 && ((hasDate && keepDate && value) || militaryTime(timeValue))) || regularTime(timeValue);
|
|
229
|
+
}
|
|
230
|
+
function timeSort(a, b) {
|
|
231
|
+
const as = splitTime(a);
|
|
232
|
+
const bs = splitTime(b);
|
|
233
|
+
if (parseInt(as.hours) < parseInt(bs.hours))
|
|
234
|
+
return -1;
|
|
235
|
+
if (parseInt(as.hours) > parseInt(bs.hours))
|
|
236
|
+
return 1;
|
|
237
|
+
if (as.hours === bs.hours) {
|
|
238
|
+
if (parseInt(as.minutes) < parseInt(bs.minutes))
|
|
239
|
+
return -1;
|
|
240
|
+
if (parseInt(as.minutes) > parseInt(bs.minutes))
|
|
241
|
+
return 1;
|
|
242
|
+
}
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
function addDays(date, days = 7) {
|
|
246
|
+
const universalDate = extractDate(date) + 'T00:00';
|
|
247
|
+
const now = new Date(universalDate);
|
|
248
|
+
const adjustedDate = new Date(now.setDate(now.getDate() + days));
|
|
249
|
+
return formatDate(adjustedDate);
|
|
250
|
+
}
|
|
251
|
+
function addWeek(date) {
|
|
252
|
+
return addDays(date);
|
|
253
|
+
}
|
|
254
|
+
function getDateByWeek(week, year, dateFormat, sunday = false) {
|
|
255
|
+
const date = new Date(year, 0, 1 + (week - 1) * 7);
|
|
256
|
+
const startValue = sunday ? 0 : 1;
|
|
257
|
+
date.setDate(date.getDate() + (startValue - date.getDay()));
|
|
258
|
+
return formatDate(date, dateFormat);
|
|
259
|
+
}
|
|
260
|
+
function dateFromDay(year, day, dateFormat) {
|
|
261
|
+
const date = new Date(year, 0);
|
|
262
|
+
return formatDate(new Date(date.setDate(day)), dateFormat);
|
|
263
|
+
}
|
|
264
|
+
function timeToDate(timeString, date = undefined) {
|
|
265
|
+
const [hours, minutes] = (timeString || '00:00').split(':').map(zeroPad);
|
|
266
|
+
const milliseconds = offsetDate(date).setHours(hours, minutes, 0, 0);
|
|
267
|
+
return offsetDate(milliseconds);
|
|
268
|
+
}
|
|
269
|
+
function minutesDifference(date1, date2, absolute = true) {
|
|
270
|
+
const dt1 = new Date(date1);
|
|
271
|
+
const dt2 = new Date(date2);
|
|
272
|
+
const diff = (dt2.getTime() - dt1.getTime()) / 1000 / 60;
|
|
273
|
+
return absolute ? Math.abs(Math.round(diff)) : Math.round(diff);
|
|
274
|
+
}
|
|
275
|
+
function addMinutesToTimeString(timeString, minutes) {
|
|
276
|
+
const validTimeString = extractTime(timeString);
|
|
277
|
+
if (!validTimeString)
|
|
278
|
+
return '00:00';
|
|
279
|
+
const minutesToAdd = isNaN(minutes) ? 0 : minutes;
|
|
280
|
+
return extractTime(addMinutes(timeToDate(validTimeString), minutesToAdd).toISOString());
|
|
281
|
+
}
|
|
282
|
+
function addMinutes(startDate, minutes) {
|
|
283
|
+
const date = new Date(startDate);
|
|
284
|
+
return new Date(date.getTime() + minutes * 60000);
|
|
285
|
+
}
|
|
286
|
+
function zeroPad(number) {
|
|
287
|
+
return number.toString()[1] ? number : '0' + number;
|
|
288
|
+
}
|
|
289
|
+
function sameDay(date1, date2) {
|
|
290
|
+
const d1 = new Date(date1);
|
|
291
|
+
const d2 = new Date(date2);
|
|
292
|
+
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
293
|
+
}
|
|
294
|
+
const dateTime = {
|
|
295
|
+
addDays,
|
|
296
|
+
addWeek,
|
|
297
|
+
addMinutesToTimeString,
|
|
298
|
+
convertTime,
|
|
299
|
+
getIsoDateString,
|
|
300
|
+
getUTCdateString,
|
|
301
|
+
DateHHMM,
|
|
302
|
+
extractDate,
|
|
303
|
+
extractTime,
|
|
304
|
+
formatDate,
|
|
305
|
+
getDateByWeek,
|
|
306
|
+
isISODateString,
|
|
307
|
+
isDate,
|
|
308
|
+
isTimeString,
|
|
309
|
+
offsetDate,
|
|
310
|
+
offsetTime,
|
|
311
|
+
sameDay,
|
|
312
|
+
timeStringMinutes,
|
|
313
|
+
timeToDate,
|
|
314
|
+
timeUTC,
|
|
315
|
+
validTimeValue,
|
|
316
|
+
validDateString,
|
|
317
|
+
timeValidation,
|
|
318
|
+
dateValidation,
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
function makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions, iteration = 0) {
|
|
322
|
+
if (getProvider().makeDeepCopy)
|
|
323
|
+
return getProvider().makeDeepCopy(sourceObject, convertExtensions, internalUse, removeExtensions);
|
|
324
|
+
const deepCopy = deepCopyEnabled();
|
|
325
|
+
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
326
|
+
if ((!deepCopy?.enabled && !internalUse) ||
|
|
327
|
+
typeof sourceObject !== 'object' ||
|
|
328
|
+
typeof sourceObject === 'function' ||
|
|
329
|
+
sourceObject === null ||
|
|
330
|
+
(typeof deepCopy?.threshold === 'number' && iteration >= deepCopy.threshold)) {
|
|
331
|
+
return sourceObject;
|
|
332
|
+
}
|
|
333
|
+
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
334
|
+
const sourceObjectKeys = Object.keys(sourceObject).filter((key) => !internalUse ||
|
|
335
|
+
!ignore ||
|
|
336
|
+
(Array.isArray(ignore) && !ignore.includes(key)) ||
|
|
337
|
+
(typeof ignore === 'function' && !ignore(key)));
|
|
338
|
+
const stringifyValue = (key, value) => {
|
|
339
|
+
targetObject[key] = typeof value?.toString === 'function' ? value.toString() : JSON.stringify(value);
|
|
340
|
+
};
|
|
341
|
+
for (const key of sourceObjectKeys) {
|
|
342
|
+
const value = sourceObject[key];
|
|
343
|
+
const modulated = typeof modulate === 'function' ? modulate(value) : undefined;
|
|
344
|
+
if (modulated !== undefined) {
|
|
345
|
+
targetObject[key] = modulated;
|
|
346
|
+
}
|
|
347
|
+
else if (convertExtensions && key === 'extensions' && Array.isArray(value)) {
|
|
348
|
+
const extensionConversions = extensionsToAttributes(value);
|
|
349
|
+
Object.assign(targetObject, ...extensionConversions);
|
|
350
|
+
}
|
|
351
|
+
else if (removeExtensions && key === 'extensions') {
|
|
352
|
+
targetObject[key] = [];
|
|
353
|
+
}
|
|
354
|
+
else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
355
|
+
stringifyValue(key, value);
|
|
356
|
+
}
|
|
357
|
+
else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === 'function') {
|
|
358
|
+
targetObject[key] = value.toJSON();
|
|
359
|
+
}
|
|
360
|
+
else if (value === null) {
|
|
361
|
+
targetObject[key] = undefined;
|
|
362
|
+
}
|
|
363
|
+
else if (isDateObject(value)) {
|
|
364
|
+
targetObject[key] = new Date(value).toISOString();
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
targetObject[key] = makeDeepCopy(value, convertExtensions, internalUse, removeExtensions, iteration + 1);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return targetObject;
|
|
371
|
+
}
|
|
372
|
+
function extensionsToAttributes(extensions) {
|
|
373
|
+
return extensions
|
|
374
|
+
?.map((extension) => {
|
|
375
|
+
const { name, value } = extension;
|
|
376
|
+
return name && value && { [`_${name}`]: value };
|
|
377
|
+
})
|
|
378
|
+
.filter(Boolean);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function getAccessorValue({ element, accessor }) {
|
|
382
|
+
if (typeof accessor !== 'string')
|
|
383
|
+
return { values: [] };
|
|
384
|
+
const targetElement = makeDeepCopy(element);
|
|
385
|
+
const attributes = accessor.split('.');
|
|
386
|
+
const values = [];
|
|
387
|
+
let value;
|
|
388
|
+
processKeys({ targetElement, attributes });
|
|
389
|
+
const result = { value };
|
|
390
|
+
if (values.length)
|
|
391
|
+
result.values = values;
|
|
392
|
+
return result;
|
|
393
|
+
function processKeys({ targetElement, attributes = [], significantCharacters }) {
|
|
394
|
+
for (const [index, attribute] of attributes.entries()) {
|
|
395
|
+
if (targetElement?.[attribute]) {
|
|
396
|
+
const remainingKeys = attributes.slice(index + 1);
|
|
397
|
+
if (!remainingKeys.length) {
|
|
398
|
+
if (!value)
|
|
399
|
+
value = targetElement[attribute];
|
|
400
|
+
if (!values.includes(targetElement[attribute])) {
|
|
401
|
+
values.push(targetElement[attribute]);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
else if (Array.isArray(targetElement[attribute])) {
|
|
405
|
+
const values = targetElement[attribute];
|
|
406
|
+
values.forEach((nestedTarget) => processKeys({
|
|
407
|
+
targetElement: nestedTarget,
|
|
408
|
+
attributes: remainingKeys,
|
|
409
|
+
}));
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
targetElement = targetElement[attribute];
|
|
413
|
+
checkValue({ targetElement, index });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function checkValue({ targetElement, index }) {
|
|
418
|
+
if (targetElement && index === attributes.length - 1 && ['string', 'number'].includes(typeof targetElement)) {
|
|
419
|
+
const extractedValue = significantCharacters ? targetElement.slice(0, significantCharacters) : targetElement;
|
|
420
|
+
if (value) {
|
|
421
|
+
if (!values.includes(extractedValue)) {
|
|
422
|
+
values.push(extractedValue);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
value = extractedValue;
|
|
427
|
+
values.push(extractedValue);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function isFunction(obj) {
|
|
435
|
+
return typeof obj === 'function';
|
|
436
|
+
}
|
|
437
|
+
function isString(obj) {
|
|
438
|
+
return typeof obj === 'string';
|
|
439
|
+
}
|
|
440
|
+
function isObject(obj) {
|
|
441
|
+
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
|
442
|
+
}
|
|
443
|
+
function objShallowEqual(o1, o2) {
|
|
444
|
+
if (!isObject(o1) || !isObject(o2))
|
|
445
|
+
return false;
|
|
446
|
+
const keys1 = Object.keys(o1);
|
|
447
|
+
const keys2 = Object.keys(o2);
|
|
448
|
+
if (keys1.length !== keys2.length) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
for (const key of keys1) {
|
|
452
|
+
if (o1[key] !== o2[key]) {
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
function createMap(objectArray, attribute) {
|
|
459
|
+
if (!Array.isArray(objectArray))
|
|
460
|
+
return {};
|
|
461
|
+
return Object.assign({}, ...(objectArray ?? [])
|
|
462
|
+
.filter(isObject)
|
|
463
|
+
.map((obj) => {
|
|
464
|
+
return (obj[attribute] && {
|
|
465
|
+
[obj[attribute]]: obj,
|
|
466
|
+
});
|
|
467
|
+
})
|
|
468
|
+
.filter(Boolean));
|
|
469
|
+
}
|
|
470
|
+
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
|
|
471
|
+
const extractAttributes = (accessor) => (element) => !accessor || typeof element !== 'object'
|
|
472
|
+
? undefined
|
|
473
|
+
: (Array.isArray(accessor) &&
|
|
474
|
+
accessor.map((a) => ({
|
|
475
|
+
[a]: getAccessorValue({ element, accessor: a })?.value,
|
|
476
|
+
}))) ||
|
|
477
|
+
(typeof accessor === 'object' &&
|
|
478
|
+
Object.keys(accessor).map((key) => ({
|
|
479
|
+
[key]: getAccessorValue({ element, accessor: key })?.value,
|
|
480
|
+
}))) ||
|
|
481
|
+
(typeof accessor === 'string' && getAccessorValue({ element, accessor }))?.value;
|
|
482
|
+
const xa = extractAttributes;
|
|
483
|
+
function undefinedToNull(obj, shallow) {
|
|
484
|
+
if (obj === undefined)
|
|
485
|
+
return null;
|
|
486
|
+
if (typeof obj !== 'object' || obj === null)
|
|
487
|
+
return obj;
|
|
488
|
+
const definedKeys = Object.keys(obj);
|
|
489
|
+
const notNull = (value) => (value === undefined ? null : value);
|
|
490
|
+
return Object.assign({}, ...definedKeys.map((key) => {
|
|
491
|
+
return Array.isArray(obj[key])
|
|
492
|
+
? {
|
|
493
|
+
[key]: shallow ? obj[key] : obj[key].map((m) => undefinedToNull(m)),
|
|
494
|
+
}
|
|
495
|
+
: { [key]: shallow ? notNull(obj[key]) : undefinedToNull(obj[key]) };
|
|
496
|
+
}));
|
|
497
|
+
}
|
|
498
|
+
function countKeys(o) {
|
|
499
|
+
if (Array.isArray(o)) {
|
|
500
|
+
return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
|
|
501
|
+
}
|
|
502
|
+
else if (typeof o === 'object' && o !== null) {
|
|
503
|
+
return (Object.keys(o).length +
|
|
504
|
+
Object.keys(o)
|
|
505
|
+
.map((k) => countKeys(o[k]))
|
|
506
|
+
.reduce((a, b) => a + b, 0));
|
|
507
|
+
}
|
|
508
|
+
return 0;
|
|
509
|
+
}
|
|
510
|
+
function generateHashCode(o) {
|
|
511
|
+
if (o === null || typeof o !== 'object')
|
|
512
|
+
return undefined;
|
|
513
|
+
const str = JSON.stringify(o);
|
|
514
|
+
const keyCount = countKeys(o);
|
|
515
|
+
const charSum = str.split('').reduce((a, b) => a + b.charCodeAt(0), 0);
|
|
516
|
+
return [str.length, keyCount, charSum].map((e) => e.toString(36)).join('');
|
|
7
517
|
}
|
|
8
518
|
|
|
9
519
|
const SUCCESS = { success: true };
|
|
@@ -1012,6 +1522,8 @@ function setSubscriptions$1(params) {
|
|
|
1012
1522
|
return { ...SUCCESS };
|
|
1013
1523
|
}
|
|
1014
1524
|
function setMethods$1(params) {
|
|
1525
|
+
if (typeof params !== 'object')
|
|
1526
|
+
return { error: INVALID_VALUES };
|
|
1015
1527
|
Object.keys(params).forEach((methodName) => {
|
|
1016
1528
|
if (typeof params[methodName] !== 'function')
|
|
1017
1529
|
return;
|
|
@@ -1024,15 +1536,13 @@ function cycleMutationStatus$1() {
|
|
|
1024
1536
|
syncGlobalState.modified = false;
|
|
1025
1537
|
return status;
|
|
1026
1538
|
}
|
|
1027
|
-
function addNotice$1({ topic, payload, key }) {
|
|
1028
|
-
if (typeof topic !== 'string' || typeof payload !== 'object')
|
|
1539
|
+
function addNotice$1({ topic, payload, key }, isGlobalSubscription) {
|
|
1540
|
+
if (typeof topic !== 'string' || typeof payload !== 'object')
|
|
1029
1541
|
return;
|
|
1030
|
-
}
|
|
1031
1542
|
if (!syncGlobalState.disableNotifications)
|
|
1032
1543
|
syncGlobalState.modified = true;
|
|
1033
|
-
if (syncGlobalState.disableNotifications || !syncGlobalState.subscriptions[topic])
|
|
1544
|
+
if (syncGlobalState.disableNotifications || (!syncGlobalState.subscriptions[topic] && !isGlobalSubscription))
|
|
1034
1545
|
return;
|
|
1035
|
-
}
|
|
1036
1546
|
if (key) {
|
|
1037
1547
|
syncGlobalState.notices = syncGlobalState.notices.filter((notice) => !(notice.topic === topic && notice.key === key));
|
|
1038
1548
|
}
|
|
@@ -1043,8 +1553,7 @@ function getMethods$1() {
|
|
|
1043
1553
|
return syncGlobalState.methods ?? {};
|
|
1044
1554
|
}
|
|
1045
1555
|
function getNotices$1({ topic }) {
|
|
1046
|
-
|
|
1047
|
-
return notices.length && notices;
|
|
1556
|
+
return syncGlobalState.notices.filter((notice) => notice.topic === topic).map((notice) => notice.payload);
|
|
1048
1557
|
}
|
|
1049
1558
|
function deleteNotices$1() {
|
|
1050
1559
|
syncGlobalState.notices = [];
|
|
@@ -1056,11 +1565,13 @@ function getTopics$1() {
|
|
|
1056
1565
|
const topics = Object.keys(syncGlobalState.subscriptions);
|
|
1057
1566
|
return { topics };
|
|
1058
1567
|
}
|
|
1059
|
-
function callListener$1({ topic, notices }) {
|
|
1568
|
+
function callListener$1({ topic, notices }, globalSubscriptions) {
|
|
1060
1569
|
const method = syncGlobalState.subscriptions[topic];
|
|
1061
|
-
if (method && typeof method === 'function')
|
|
1570
|
+
if (method && typeof method === 'function')
|
|
1062
1571
|
method(notices);
|
|
1063
|
-
|
|
1572
|
+
const globalMethod = globalSubscriptions?.[topic];
|
|
1573
|
+
if (globalMethod && typeof globalMethod === 'function')
|
|
1574
|
+
globalMethod(notices);
|
|
1064
1575
|
}
|
|
1065
1576
|
function handleCaughtError$1({ engineName, methodName, params, err }) {
|
|
1066
1577
|
let error;
|
|
@@ -1331,13 +1842,14 @@ function getMissingSequenceNumbers(arr, start = 1) {
|
|
|
1331
1842
|
}
|
|
1332
1843
|
|
|
1333
1844
|
const globalState = {
|
|
1334
|
-
tournamentFactoryVersion: '0.0.0',
|
|
1335
1845
|
timers: { default: { elapsedTime: 0 } },
|
|
1846
|
+
globalSubscriptions: {},
|
|
1336
1847
|
deepCopyAttributes: {
|
|
1337
1848
|
stringify: [],
|
|
1338
1849
|
ignore: [],
|
|
1339
1850
|
toJSON: [],
|
|
1340
1851
|
},
|
|
1852
|
+
globalMethods: [],
|
|
1341
1853
|
deepCopy: true,
|
|
1342
1854
|
};
|
|
1343
1855
|
let _globalStateProvider = syncGlobalState$1;
|
|
@@ -1491,12 +2003,30 @@ function deepCopyEnabled() {
|
|
|
1491
2003
|
...globalState.deepCopyAttributes,
|
|
1492
2004
|
};
|
|
1493
2005
|
}
|
|
2006
|
+
function setGlobalSubscriptions(params) {
|
|
2007
|
+
if (!params?.subscriptions)
|
|
2008
|
+
return { error: MISSING_VALUE, info: 'missing subscriptions' };
|
|
2009
|
+
Object.keys(params.subscriptions).forEach((subscription) => {
|
|
2010
|
+
globalState.globalSubscriptions[subscription] = params.subscriptions[subscription];
|
|
2011
|
+
});
|
|
2012
|
+
return { ...SUCCESS };
|
|
2013
|
+
}
|
|
1494
2014
|
function setSubscriptions(params) {
|
|
1495
2015
|
if (!params?.subscriptions)
|
|
1496
2016
|
return { error: MISSING_VALUE, info: 'missing subscriptions' };
|
|
1497
|
-
return _globalStateProvider.setSubscriptions({
|
|
1498
|
-
|
|
2017
|
+
return _globalStateProvider.setSubscriptions({ subscriptions: params.subscriptions });
|
|
2018
|
+
}
|
|
2019
|
+
function setGlobalMethods(params) {
|
|
2020
|
+
if (!params)
|
|
2021
|
+
return { error: MISSING_VALUE, info: 'missing method declarations' };
|
|
2022
|
+
if (typeof params !== 'object')
|
|
2023
|
+
return { error: INVALID_VALUES };
|
|
2024
|
+
Object.keys(params).forEach((methodName) => {
|
|
2025
|
+
if (typeof params[methodName] !== 'function')
|
|
2026
|
+
return;
|
|
2027
|
+
globalState.globalMethods[methodName] = params[methodName];
|
|
1499
2028
|
});
|
|
2029
|
+
return { ...SUCCESS };
|
|
1500
2030
|
}
|
|
1501
2031
|
function setMethods(params) {
|
|
1502
2032
|
if (!params)
|
|
@@ -1509,10 +2039,13 @@ function cycleMutationStatus() {
|
|
|
1509
2039
|
return _globalStateProvider.cycleMutationStatus();
|
|
1510
2040
|
}
|
|
1511
2041
|
function addNotice(notice) {
|
|
1512
|
-
|
|
2042
|
+
if (typeof notice?.topic !== 'string')
|
|
2043
|
+
return;
|
|
2044
|
+
const isGlobalSubscription = globalState.globalSubscriptions[notice.topic];
|
|
2045
|
+
return _globalStateProvider.addNotice(notice, isGlobalSubscription);
|
|
1513
2046
|
}
|
|
1514
2047
|
function getMethods() {
|
|
1515
|
-
return _globalStateProvider.getMethods();
|
|
2048
|
+
return { ...globalState.globalMethods, ..._globalStateProvider.getMethods() };
|
|
1516
2049
|
}
|
|
1517
2050
|
function getNotices(params) {
|
|
1518
2051
|
return _globalStateProvider.getNotices(params);
|
|
@@ -1527,7 +2060,7 @@ function getTopics() {
|
|
|
1527
2060
|
return _globalStateProvider.getTopics();
|
|
1528
2061
|
}
|
|
1529
2062
|
async function callListener(payload) {
|
|
1530
|
-
return _globalStateProvider.callListener(payload);
|
|
2063
|
+
return _globalStateProvider.callListener(payload, globalState.globalSubscriptions);
|
|
1531
2064
|
}
|
|
1532
2065
|
function getTournamentId() {
|
|
1533
2066
|
return _globalStateProvider.getTournamentId();
|
|
@@ -1578,6 +2111,29 @@ function globalLog$1(log, engine) {
|
|
|
1578
2111
|
console.log(engine, log);
|
|
1579
2112
|
}
|
|
1580
2113
|
}
|
|
2114
|
+
function setStateMethods(submittedMethods, traverse, maxDepth, global) {
|
|
2115
|
+
if (!isObject(submittedMethods))
|
|
2116
|
+
return { error: INVALID_VALUES };
|
|
2117
|
+
if (!isNumeric)
|
|
2118
|
+
maxDepth = 1;
|
|
2119
|
+
const collectionFilter = Array.isArray(traverse) ? traverse : [];
|
|
2120
|
+
const methods = {};
|
|
2121
|
+
const attrWalker = (obj, depth = 0) => {
|
|
2122
|
+
Object.keys(obj).forEach((key) => {
|
|
2123
|
+
if (isFunction(obj[key])) {
|
|
2124
|
+
methods[key] = obj[key];
|
|
2125
|
+
}
|
|
2126
|
+
else if (isObject(obj[key]) &&
|
|
2127
|
+
(traverse === true || collectionFilter?.includes(key)) &&
|
|
2128
|
+
(maxDepth === undefined || depth < maxDepth)) {
|
|
2129
|
+
attrWalker(obj[key], depth + 1);
|
|
2130
|
+
}
|
|
2131
|
+
});
|
|
2132
|
+
};
|
|
2133
|
+
attrWalker(submittedMethods);
|
|
2134
|
+
global ? setGlobalMethods(methods) : setMethods(methods);
|
|
2135
|
+
return { methods };
|
|
2136
|
+
}
|
|
1581
2137
|
|
|
1582
2138
|
var globalState$1 = {
|
|
1583
2139
|
__proto__: null,
|
|
@@ -1604,7 +2160,10 @@ var globalState$1 = {
|
|
|
1604
2160
|
setDeepCopy: setDeepCopy,
|
|
1605
2161
|
setDevContext: setDevContext,
|
|
1606
2162
|
setGlobalLog: setGlobalLog,
|
|
2163
|
+
setGlobalMethods: setGlobalMethods,
|
|
2164
|
+
setGlobalSubscriptions: setGlobalSubscriptions,
|
|
1607
2165
|
setMethods: setMethods,
|
|
2166
|
+
setStateMethods: setStateMethods,
|
|
1608
2167
|
setStateProvider: setStateProvider,
|
|
1609
2168
|
setSubscriptions: setSubscriptions,
|
|
1610
2169
|
setTournamentId: setTournamentId,
|
|
@@ -1653,1063 +2212,553 @@ function decorateResult({ context, result, stack, info }) {
|
|
|
1653
2212
|
return result ?? { success: true };
|
|
1654
2213
|
}
|
|
1655
2214
|
|
|
1656
|
-
const
|
|
1657
|
-
const
|
|
1658
|
-
const
|
|
1659
|
-
const
|
|
2215
|
+
const TOURNAMENT_RECORDS = 'tournamentRecords';
|
|
2216
|
+
const POLICY_DEFINITIONS = 'policyDefinitions';
|
|
2217
|
+
const TOURNAMENT_RECORD = 'tournamentRecord';
|
|
2218
|
+
const DRAW_DEFINITION = 'drawDefinition';
|
|
2219
|
+
const MATCHUP_FORMAT = 'matchUpFormat';
|
|
2220
|
+
const PARTICIPANT_ID = 'participantId';
|
|
2221
|
+
const SCHEDULE_DATES = 'scheduleDates';
|
|
2222
|
+
const TOURNAMENT_ID = 'tournamentId';
|
|
2223
|
+
const SCHEDULE_DATE = 'scheduleDate';
|
|
2224
|
+
const STRUCTURE_ID = 'structureId';
|
|
2225
|
+
const PARTICIPANT = 'participant';
|
|
2226
|
+
const MATCHUP_IDS = 'matchUpIds';
|
|
2227
|
+
const POLICY_TYPE = 'policyType';
|
|
2228
|
+
const STRUCTURES = 'structures';
|
|
2229
|
+
const MATCHUP_ID = 'matchUpId';
|
|
2230
|
+
const IN_CONTEXT = 'inContext';
|
|
2231
|
+
const STRUCTURE = 'structure';
|
|
2232
|
+
const COURT_IDS = 'courtIds';
|
|
2233
|
+
const PERSON_ID = 'personId';
|
|
2234
|
+
const VENUE_IDS = 'venueIds';
|
|
2235
|
+
const MATCHUPS = 'matchUps';
|
|
2236
|
+
const COURT_ID = 'courtId';
|
|
2237
|
+
const EVENT_ID = 'eventId';
|
|
2238
|
+
const MATCHUP = 'matchUp';
|
|
2239
|
+
const DRAW_ID = 'drawId';
|
|
2240
|
+
const ERROR = 'error';
|
|
2241
|
+
const EVENT = 'event';
|
|
2242
|
+
const PARAM = 'param';
|
|
2243
|
+
const UUIDS$1 = 'uuids';
|
|
2244
|
+
const AVERAGE_MATCHUP_MINUTES = 'averageMatchUpMinutes';
|
|
2245
|
+
const RECOVERY_MINUTES = 'recoveryMinutes';
|
|
2246
|
+
const PERIOD_LENGTH = 'periodLength';
|
|
2247
|
+
const OBJECT = 'object';
|
|
2248
|
+
const ARRAY = 'array';
|
|
2249
|
+
const VALIDATE = '_validate';
|
|
2250
|
+
const MESSAGE = '_message';
|
|
2251
|
+
const INVALID = '_invalid';
|
|
2252
|
+
const OF_TYPE = '_ofType';
|
|
2253
|
+
const ANY_OF = '_anyOf';
|
|
2254
|
+
const ONE_OF = '_oneOf';
|
|
1660
2255
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
2256
|
+
const errors = {
|
|
2257
|
+
[TOURNAMENT_RECORDS]: MISSING_TOURNAMENT_RECORDS,
|
|
2258
|
+
[TOURNAMENT_RECORD]: MISSING_TOURNAMENT_RECORD,
|
|
2259
|
+
[POLICY_DEFINITIONS]: MISSING_POLICY_DEFINITION,
|
|
2260
|
+
[DRAW_DEFINITION]: MISSING_DRAW_DEFINITION,
|
|
2261
|
+
[PARTICIPANT_ID]: MISSING_PARTICIPANT_ID,
|
|
2262
|
+
[MATCHUP_FORMAT]: MISSING_MATCHUP_FORMAT,
|
|
2263
|
+
[TOURNAMENT_ID]: MISSING_TOURNAMENT_ID,
|
|
2264
|
+
[STRUCTURE_ID]: MISSING_STRUCTURE_ID,
|
|
2265
|
+
[MATCHUP_IDS]: MISSING_MATCHUP_IDS,
|
|
2266
|
+
[PARTICIPANT]: MISSING_PARTICIPANT,
|
|
2267
|
+
[STRUCTURES]: MISSING_STRUCTURES,
|
|
2268
|
+
[MATCHUP_ID]: MISSING_MATCHUP_ID,
|
|
2269
|
+
[STRUCTURE]: MISSING_STRUCTURE,
|
|
2270
|
+
[COURT_ID]: MISSING_COURT_ID,
|
|
2271
|
+
[MATCHUPS]: MISSING_MATCHUPS,
|
|
2272
|
+
[EVENT_ID]: EVENT_NOT_FOUND,
|
|
2273
|
+
[MATCHUP]: MISSING_MATCHUP,
|
|
2274
|
+
[COURT_IDS]: MISSING_VALUE,
|
|
2275
|
+
[VENUE_IDS]: MISSING_VALUE,
|
|
2276
|
+
[DRAW_ID]: MISSING_DRAW_ID,
|
|
2277
|
+
[EVENT]: MISSING_EVENT,
|
|
2278
|
+
};
|
|
2279
|
+
const paramTypes = {
|
|
2280
|
+
[TOURNAMENT_RECORDS]: OBJECT,
|
|
2281
|
+
[POLICY_DEFINITIONS]: OBJECT,
|
|
2282
|
+
[TOURNAMENT_RECORD]: OBJECT,
|
|
2283
|
+
[DRAW_DEFINITION]: OBJECT,
|
|
2284
|
+
[SCHEDULE_DATES]: ARRAY,
|
|
2285
|
+
[PARTICIPANT]: OBJECT,
|
|
2286
|
+
[MATCHUP_IDS]: ARRAY,
|
|
2287
|
+
[STRUCTURES]: ARRAY,
|
|
2288
|
+
[STRUCTURE]: OBJECT,
|
|
2289
|
+
[COURT_IDS]: ARRAY,
|
|
2290
|
+
[VENUE_IDS]: ARRAY,
|
|
2291
|
+
[MATCHUPS]: ARRAY,
|
|
2292
|
+
[MATCHUP]: OBJECT,
|
|
2293
|
+
[EVENT]: OBJECT,
|
|
2294
|
+
[UUIDS$1]: ARRAY,
|
|
2295
|
+
};
|
|
2296
|
+
function checkRequiredParameters(params, requiredParams, stack) {
|
|
2297
|
+
if (!params && !isObject(params))
|
|
2298
|
+
return { error: INVALID_VALUES };
|
|
2299
|
+
if (!requiredParams?.length || params?._bypassParamCheck)
|
|
2300
|
+
return { valid: true };
|
|
2301
|
+
if (!Array.isArray(requiredParams))
|
|
2302
|
+
return { error: INVALID_VALUES };
|
|
2303
|
+
const { paramError, errorParam } = findParamError(params, requiredParams);
|
|
2304
|
+
if (!paramError)
|
|
2305
|
+
return { valid: true };
|
|
2306
|
+
const error = params?.[errorParam] === undefined
|
|
2307
|
+
? errors[errorParam] || INVALID_VALUES
|
|
2308
|
+
: (paramError[VALIDATE] && paramError[INVALID]) || INVALID_VALUES;
|
|
2309
|
+
const param = errorParam ?? (paramError[ONE_OF] && Object.keys(paramError[ONE_OF]).join(', '));
|
|
2310
|
+
return decorateResult({
|
|
2311
|
+
info: { param, message: paramError[MESSAGE] },
|
|
2312
|
+
result: { error },
|
|
2313
|
+
stack,
|
|
2314
|
+
});
|
|
1687
2315
|
}
|
|
1688
|
-
function
|
|
1689
|
-
|
|
2316
|
+
function getIntersection(params, constraint) {
|
|
2317
|
+
const paramKeys = Object.keys(params);
|
|
2318
|
+
const constraintKeys = Object.keys(constraint);
|
|
2319
|
+
return intersection(paramKeys, constraintKeys);
|
|
1690
2320
|
}
|
|
1691
|
-
function
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
2321
|
+
function getOneOf(params, _oneOf) {
|
|
2322
|
+
if (!_oneOf)
|
|
2323
|
+
return;
|
|
2324
|
+
const overlap = getIntersection(params, _oneOf);
|
|
2325
|
+
if (overlap.length !== 1)
|
|
2326
|
+
return { error: INVALID_VALUES };
|
|
2327
|
+
return overlap.reduce((attr, param) => ({ ...attr, [param]: true }), {});
|
|
1695
2328
|
}
|
|
1696
|
-
function
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
return timeString.split(':').map(zeroPad).join(':');
|
|
2329
|
+
function getAnyOf(params, _anyOf) {
|
|
2330
|
+
if (!_anyOf)
|
|
2331
|
+
return;
|
|
2332
|
+
const overlap = getIntersection(params, _anyOf).filter((param) => params[param]);
|
|
2333
|
+
if (overlap.length < 1)
|
|
2334
|
+
return { error: INVALID_VALUES };
|
|
2335
|
+
return overlap.reduce((attr, param) => ({ ...attr, [param]: true }), {});
|
|
1704
2336
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
const
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
2337
|
+
function findParamError(params, requiredParams) {
|
|
2338
|
+
let errorParam, paramInfo;
|
|
2339
|
+
const paramError = requiredParams.find(({ _ofType, _oneOf, _anyOf, _validate, _info, ...attrs }) => {
|
|
2340
|
+
const oneOf = _oneOf && getOneOf(params, _oneOf);
|
|
2341
|
+
if (oneOf?.error)
|
|
2342
|
+
return oneOf.error;
|
|
2343
|
+
oneOf && Object.assign(attrs, oneOf);
|
|
2344
|
+
const anyOf = _anyOf && getAnyOf(params, _anyOf);
|
|
2345
|
+
if (anyOf?.error)
|
|
2346
|
+
return anyOf.error;
|
|
2347
|
+
anyOf && Object.assign(attrs, anyOf);
|
|
2348
|
+
const booleanParams = Object.keys(attrs).filter((key) => typeof attrs[key] === 'boolean');
|
|
2349
|
+
const invalidParam = booleanParams.find((param) => {
|
|
2350
|
+
const invalidValidationFunction = _validate && !isFunction(_validate);
|
|
2351
|
+
const faliedTypeCheck = params[param] && !_validate && invalidType(params, param, _ofType);
|
|
2352
|
+
const paramNotPresent = attrs[param] && !params[param];
|
|
2353
|
+
const invalid = invalidValidationFunction || faliedTypeCheck || paramNotPresent;
|
|
2354
|
+
const hasError = invalid || (_validate && params[param] && !checkValidation(params[param], _validate));
|
|
2355
|
+
if (hasError) {
|
|
2356
|
+
errorParam = param;
|
|
2357
|
+
paramInfo = _info;
|
|
2358
|
+
}
|
|
2359
|
+
return hasError;
|
|
2360
|
+
});
|
|
2361
|
+
return !booleanParams.length || invalidParam;
|
|
2362
|
+
});
|
|
2363
|
+
return { paramError, errorParam, paramInfo };
|
|
1714
2364
|
}
|
|
1715
|
-
function
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
let month = '' + (d.getMonth() + 1);
|
|
1722
|
-
let day = '' + d.getDate();
|
|
1723
|
-
const year = d.getFullYear();
|
|
1724
|
-
if (month.length < 2)
|
|
1725
|
-
month = '0' + month;
|
|
1726
|
-
if (day.length < 2)
|
|
1727
|
-
day = '0' + day;
|
|
1728
|
-
if (format === 'DMY')
|
|
1729
|
-
return [day, month, year].join(separator);
|
|
1730
|
-
if (format === 'MDY')
|
|
1731
|
-
return [month, day, year].join(separator);
|
|
1732
|
-
if (format === 'YDM')
|
|
1733
|
-
return [year, day, month].join(separator);
|
|
1734
|
-
if (format === 'DYM')
|
|
1735
|
-
return [day, year, month].join(separator);
|
|
1736
|
-
if (format === 'MYD')
|
|
1737
|
-
return [month, year, day].join(separator);
|
|
1738
|
-
return [year, month, day].join(separator);
|
|
2365
|
+
function invalidType(params, param, _ofType) {
|
|
2366
|
+
_ofType = _ofType || paramTypes[param] || 'string';
|
|
2367
|
+
if (_ofType === 'array') {
|
|
2368
|
+
return !Array.isArray(params[param]);
|
|
2369
|
+
}
|
|
2370
|
+
return typeof params[param] !== _ofType;
|
|
1739
2371
|
}
|
|
1740
|
-
function
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
return
|
|
2372
|
+
function checkValidation(value, validate) {
|
|
2373
|
+
if (isFunction(validate))
|
|
2374
|
+
return validate(value);
|
|
2375
|
+
return true;
|
|
1744
2376
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
2377
|
+
|
|
2378
|
+
const SINGLES$1 = 'SINGLES';
|
|
2379
|
+
const SINGLES_EVENT = 'SINGLES';
|
|
2380
|
+
const DOUBLES$1 = 'DOUBLES';
|
|
2381
|
+
const DOUBLES_EVENT = 'DOUBLES';
|
|
2382
|
+
const TEAM$2 = 'TEAM';
|
|
2383
|
+
const TEAM_EVENT = 'TEAM';
|
|
2384
|
+
const AGE = 'AGE';
|
|
2385
|
+
const RATING$2 = 'RATING';
|
|
2386
|
+
const BOTH = 'BOTH';
|
|
2387
|
+
const eventConstants = {
|
|
2388
|
+
AGE,
|
|
2389
|
+
BOTH,
|
|
2390
|
+
DOUBLES: DOUBLES$1,
|
|
2391
|
+
DOUBLES_EVENT,
|
|
2392
|
+
RATING: RATING$2,
|
|
2393
|
+
SINGLES: SINGLES$1,
|
|
2394
|
+
SINGLES_EVENT,
|
|
2395
|
+
TEAM_EVENT,
|
|
2396
|
+
TEAM: TEAM$2,
|
|
2397
|
+
};
|
|
2398
|
+
|
|
2399
|
+
const DYNAMIC = 'DYNAMIC';
|
|
2400
|
+
const RANKING$1 = 'RANKING';
|
|
2401
|
+
const RATING$1 = 'RATING';
|
|
2402
|
+
const SCALE$1 = 'SCALE';
|
|
2403
|
+
const SEEDING$1 = 'SEEDING';
|
|
2404
|
+
const scaleConstants = {
|
|
2405
|
+
RANKING: RANKING$1,
|
|
2406
|
+
RATING: RATING$1,
|
|
2407
|
+
SCALE: SCALE$1,
|
|
2408
|
+
SEEDING: SEEDING$1,
|
|
2409
|
+
};
|
|
2410
|
+
|
|
2411
|
+
function getScaleValues(params) {
|
|
2412
|
+
const paramCheck = checkRequiredParameters(params, [{ [PARTICIPANT]: true }]);
|
|
2413
|
+
if (paramCheck.error)
|
|
2414
|
+
return paramCheck;
|
|
2415
|
+
const scaleItems = params.participant.timeItems?.filter(({ itemType }) => itemType?.startsWith(SCALE$1) && [RANKING$1, RATING$1, SEEDING$1].includes(itemType.split('.')[1]));
|
|
2416
|
+
const scales = { ratings: {}, rankings: {}, seedings: {} };
|
|
2417
|
+
if (scaleItems?.length) {
|
|
2418
|
+
const latestScaleItem = (scaleType) => scaleItems
|
|
2419
|
+
.filter((timeItem) => timeItem?.itemType === scaleType)
|
|
2420
|
+
.sort((a, b) => new Date(a.createdAt || undefined).getTime() - new Date(b.createdAt || undefined).getTime())
|
|
2421
|
+
.pop();
|
|
2422
|
+
const itemTypes = unique(scaleItems.map(({ itemType }) => itemType));
|
|
2423
|
+
for (const itemType of itemTypes) {
|
|
2424
|
+
const scaleItem = latestScaleItem(itemType);
|
|
2425
|
+
if (scaleItem) {
|
|
2426
|
+
const [, type, format, scaleName, modifier] = scaleItem.itemType.split('.');
|
|
2427
|
+
const namedScale = modifier ? `${scaleName}.${modifier}` : scaleName;
|
|
2428
|
+
const scaleType = (type === SEEDING$1 && 'seedings') || (type === RANKING$1 && 'rankings') || 'ratings';
|
|
2429
|
+
if (!scales[scaleType][format])
|
|
2430
|
+
scales[scaleType][format] = [];
|
|
2431
|
+
scales[scaleType][format].push({
|
|
2432
|
+
scaleValue: scaleItem.itemValue,
|
|
2433
|
+
scaleDate: scaleItem.itemDate,
|
|
2434
|
+
scaleName: namedScale,
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
return { ...SUCCESS, ...scales };
|
|
1747
2440
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
2441
|
+
|
|
2442
|
+
function attributeFilter(params) {
|
|
2443
|
+
if (params === null)
|
|
2444
|
+
return {};
|
|
2445
|
+
const { source, template } = params || {};
|
|
2446
|
+
if (!template)
|
|
2447
|
+
return source;
|
|
2448
|
+
const target = {};
|
|
2449
|
+
attributeCopy(source, template, target);
|
|
2450
|
+
return target;
|
|
2451
|
+
function attributeCopy(valuesObject, templateObject, outputObject) {
|
|
2452
|
+
if (!valuesObject || !templateObject)
|
|
2453
|
+
return undefined;
|
|
2454
|
+
const vKeys = Object.keys(valuesObject);
|
|
2455
|
+
const oKeys = Object.keys(templateObject);
|
|
2456
|
+
const orMap = Object.assign({}, ...oKeys
|
|
2457
|
+
.filter((key) => key.indexOf('||'))
|
|
2458
|
+
.map((key) => key.split('||').map((or) => ({ [or]: key })))
|
|
2459
|
+
.flat());
|
|
2460
|
+
const allKeys = oKeys.concat(...Object.keys(orMap));
|
|
2461
|
+
const wildcard = allKeys.includes('*');
|
|
2462
|
+
for (const vKey of vKeys) {
|
|
2463
|
+
if (allKeys.indexOf(vKey) >= 0 || wildcard) {
|
|
2464
|
+
const templateKey = orMap[vKey] || vKey;
|
|
2465
|
+
const tobj = templateObject[templateKey] || wildcard;
|
|
2466
|
+
const vobj = valuesObject[vKey];
|
|
2467
|
+
if (typeof tobj === 'object' && typeof vobj !== 'function' && !Array.isArray(tobj)) {
|
|
2468
|
+
if (Array.isArray(vobj)) {
|
|
2469
|
+
const mappedElements = vobj
|
|
2470
|
+
.map((arrayMember) => {
|
|
2471
|
+
const target = {};
|
|
2472
|
+
const result = attributeCopy(arrayMember, tobj, target);
|
|
2473
|
+
return result !== false ? target : undefined;
|
|
2474
|
+
})
|
|
2475
|
+
.filter(Boolean);
|
|
2476
|
+
outputObject[vKey] = mappedElements;
|
|
2477
|
+
}
|
|
2478
|
+
else if (vobj) {
|
|
2479
|
+
outputObject[vKey] = {};
|
|
2480
|
+
attributeCopy(vobj, tobj, outputObject[vKey]);
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
else {
|
|
2484
|
+
const value = valuesObject[vKey];
|
|
2485
|
+
const exclude = Array.isArray(tobj) && !tobj.includes(value);
|
|
2486
|
+
if (exclude)
|
|
2487
|
+
return false;
|
|
2488
|
+
if (templateObject[vKey] || (wildcard && templateObject[vKey] !== false)) {
|
|
2489
|
+
outputObject[vKey] = value;
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
return undefined;
|
|
2495
|
+
}
|
|
1753
2496
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2497
|
+
|
|
2498
|
+
const POLICY_TYPE_VOLUNTARY_CONSOLATION = 'voluntaryConsolation';
|
|
2499
|
+
const POLICY_TYPE_COMPETITIVE_BANDS = 'competitiveBands';
|
|
2500
|
+
const POLICY_TYPE_ROUND_ROBIN_TALLY = 'roundRobinTally';
|
|
2501
|
+
const POLICY_TYPE_POSITION_ACTIONS = 'positionActions';
|
|
2502
|
+
const POLICY_TYPE_MATCHUP_ACTIONS = 'matchUpActions';
|
|
2503
|
+
const POLICY_TYPE_RANKING_POINTS = 'rankingPoints';
|
|
2504
|
+
const POLICY_TYPE_ROUND_NAMING = 'roundNaming';
|
|
2505
|
+
const POLICY_TYPE_PARTICIPANT = 'participant';
|
|
2506
|
+
const POLICY_TYPE_PROGRESSION = 'progression';
|
|
2507
|
+
const POLICY_TYPE_SCHEDULING = 'scheduling';
|
|
2508
|
+
const POLICY_TYPE_AVOIDANCE = 'avoidance';
|
|
2509
|
+
const POLICY_TYPE_DISPLAY = 'display';
|
|
2510
|
+
const POLICY_TYPE_SCORING = 'scoring';
|
|
2511
|
+
const POLICY_TYPE_SEEDING = 'seeding';
|
|
2512
|
+
const POLICY_TYPE_FEED_IN = 'feedIn';
|
|
2513
|
+
const POLICY_TYPE_AUDIT = 'audit';
|
|
2514
|
+
const POLICY_TYPE_DRAWS = 'draws';
|
|
2515
|
+
const policyConstants = {
|
|
2516
|
+
POLICY_TYPE_VOLUNTARY_CONSOLATION,
|
|
2517
|
+
POLICY_TYPE_COMPETITIVE_BANDS,
|
|
2518
|
+
POLICY_TYPE_ROUND_ROBIN_TALLY,
|
|
2519
|
+
POLICY_TYPE_POSITION_ACTIONS,
|
|
2520
|
+
POLICY_TYPE_MATCHUP_ACTIONS,
|
|
2521
|
+
POLICY_TYPE_RANKING_POINTS,
|
|
2522
|
+
POLICY_TYPE_ROUND_NAMING,
|
|
2523
|
+
POLICY_TYPE_PARTICIPANT,
|
|
2524
|
+
POLICY_TYPE_PROGRESSION,
|
|
2525
|
+
POLICY_TYPE_SCHEDULING,
|
|
2526
|
+
POLICY_TYPE_AVOIDANCE,
|
|
2527
|
+
POLICY_TYPE_DISPLAY,
|
|
2528
|
+
POLICY_TYPE_FEED_IN,
|
|
2529
|
+
POLICY_TYPE_SCORING,
|
|
2530
|
+
POLICY_TYPE_SEEDING,
|
|
2531
|
+
POLICY_TYPE_AUDIT,
|
|
2532
|
+
POLICY_TYPE_DRAWS,
|
|
2533
|
+
};
|
|
2534
|
+
|
|
2535
|
+
function findParticipant({ tournamentParticipants = [], policyDefinitions = {}, contextProfile, participantId, internalUse, personId, }) {
|
|
2536
|
+
const foundParticipant = tournamentParticipants.find((candidate) => (participantId && candidate.participantId === participantId) ||
|
|
2537
|
+
(personId && candidate.person && candidate.person.personId === personId));
|
|
2538
|
+
const participant = makeDeepCopy(foundParticipant, false, internalUse);
|
|
2539
|
+
if (participant) {
|
|
2540
|
+
const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
|
|
2541
|
+
if (contextProfile?.withScaleValues) {
|
|
2542
|
+
const { ratings, rankings } = getScaleValues({ participant });
|
|
2543
|
+
participant.rankings = rankings;
|
|
2544
|
+
participant.ratings = ratings;
|
|
2545
|
+
}
|
|
2546
|
+
if (participantAttributes?.participant) {
|
|
2547
|
+
return attributeFilter({
|
|
2548
|
+
template: participantAttributes.participant,
|
|
2549
|
+
source: participant,
|
|
2550
|
+
});
|
|
1771
2551
|
}
|
|
1772
2552
|
}
|
|
1773
|
-
return
|
|
1774
|
-
|
|
1775
|
-
|
|
2553
|
+
return participant;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
const ELEMENT_REQUIRED = 'element required';
|
|
2557
|
+
const MISSING_NAME = 'missing name';
|
|
2558
|
+
|
|
2559
|
+
function removeExtension(params) {
|
|
2560
|
+
if (!params || typeof params !== 'object')
|
|
2561
|
+
return { error: MISSING_VALUE };
|
|
2562
|
+
if (params.element && typeof params?.element !== 'object')
|
|
2563
|
+
return { error: INVALID_VALUES };
|
|
2564
|
+
if (!params?.name)
|
|
2565
|
+
return { error: MISSING_VALUE, info: MISSING_NAME };
|
|
2566
|
+
if (!params?.element) {
|
|
2567
|
+
if (params.discover && params.tournamentRecords) {
|
|
2568
|
+
for (const tournamentId of Object.keys(params.tournamentRecords)) {
|
|
2569
|
+
const tournamentRecord = params.tournamentRecords[tournamentId];
|
|
2570
|
+
const result = removeExtension({
|
|
2571
|
+
element: tournamentRecord,
|
|
2572
|
+
name: params.name,
|
|
2573
|
+
});
|
|
2574
|
+
if (result.error)
|
|
2575
|
+
return decorateResult({ result, stack: 'removeExtension' });
|
|
2576
|
+
}
|
|
2577
|
+
return { ...SUCCESS };
|
|
2578
|
+
}
|
|
2579
|
+
return { error: MISSING_VALUE, info: ELEMENT_REQUIRED };
|
|
1776
2580
|
}
|
|
2581
|
+
if (!params?.element.extensions)
|
|
2582
|
+
return { ...SUCCESS, info: NOT_FOUND };
|
|
2583
|
+
params.element.extensions = params.element.extensions.filter((extension) => extension?.name !== params.name);
|
|
2584
|
+
return { ...SUCCESS };
|
|
1777
2585
|
}
|
|
1778
|
-
|
|
1779
|
-
function
|
|
1780
|
-
if (typeof
|
|
2586
|
+
|
|
2587
|
+
function isValidExtension({ requiredAttributes = ['name', 'value'], extension }) {
|
|
2588
|
+
if (!extension || typeof extension !== 'object')
|
|
1781
2589
|
return false;
|
|
1782
|
-
|
|
1783
|
-
}
|
|
1784
|
-
function isTimeString(timeString) {
|
|
1785
|
-
if (typeof timeString !== 'string')
|
|
2590
|
+
if (typeof extension.name !== 'string')
|
|
1786
2591
|
return false;
|
|
1787
|
-
const
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
const invalid = parts.length < 2 || !isNumeric || parseInt(parts[0]) > 23 || parseInt(parts[1]) > 60;
|
|
1791
|
-
return !invalid;
|
|
1792
|
-
}
|
|
1793
|
-
function timeStringMinutes(timeString) {
|
|
1794
|
-
const validTimeString = extractTime(timeString);
|
|
1795
|
-
if (!validTimeString)
|
|
1796
|
-
return 0;
|
|
1797
|
-
const [hours, minutes] = validTimeString.split(':').map((value) => parseInt(value));
|
|
1798
|
-
return hours * 60 + minutes;
|
|
1799
|
-
}
|
|
1800
|
-
function dayMinutesToTimeString(totalMinutes) {
|
|
1801
|
-
let hours = Math.floor(totalMinutes / 60);
|
|
1802
|
-
const minutes = totalMinutes - hours * 60;
|
|
1803
|
-
if (hours > 23)
|
|
1804
|
-
hours = hours % 24;
|
|
1805
|
-
return [zeroPad(hours), zeroPad(minutes)].join(':');
|
|
1806
|
-
}
|
|
1807
|
-
function tidyTime(timeString) {
|
|
1808
|
-
return isTimeString(timeString) ? timeString.split(':').slice(0, 2).map(zeroPad).join(':') : undefined;
|
|
1809
|
-
}
|
|
1810
|
-
function extractTime(dateString) {
|
|
1811
|
-
return isISODateString(dateString) && dateString.indexOf('T') > 0
|
|
1812
|
-
? tidyTime(dateString.split('T').reverse()[0])
|
|
1813
|
-
: tidyTime(dateString);
|
|
1814
|
-
}
|
|
1815
|
-
function extractDate(dateString) {
|
|
1816
|
-
return isISODateString(dateString) || dateValidation.test(dateString) ? dateString.split('T')[0] : undefined;
|
|
1817
|
-
}
|
|
1818
|
-
function dateStringDaysChange(dateString, daysChange) {
|
|
1819
|
-
const date = new Date(dateString);
|
|
1820
|
-
date.setDate(date.getDate() + daysChange);
|
|
1821
|
-
return extractDate(date.toISOString());
|
|
1822
|
-
}
|
|
1823
|
-
function splitTime(value) {
|
|
1824
|
-
value = typeof value !== 'string' ? '00:00' : value;
|
|
1825
|
-
const o = {}, time = {};
|
|
1826
|
-
({ 0: o.time, 1: o.ampm } = value.split(' ') || []);
|
|
1827
|
-
({ 0: time.hours, 1: time.minutes } = o.time.split(':') || []);
|
|
1828
|
-
time.ampm = o.ampm;
|
|
1829
|
-
if (isNaN(time.hours) || isNaN(time.minutes) || (time.ampm && !['AM', 'PM'].includes(time.ampm.toUpperCase())))
|
|
1830
|
-
return {};
|
|
1831
|
-
return time;
|
|
1832
|
-
}
|
|
1833
|
-
function militaryTime(value) {
|
|
1834
|
-
const time = splitTime(value);
|
|
1835
|
-
if (time.ampm && time.hours) {
|
|
1836
|
-
if (time.ampm.toLowerCase() === 'pm' && parseInt(time.hours) < 12)
|
|
1837
|
-
time.hours = ((time.hours && parseInt(time.hours)) || 0) + 12;
|
|
1838
|
-
if (time.ampm.toLowerCase() === 'am' && time.hours === '12')
|
|
1839
|
-
time.hours = '00';
|
|
1840
|
-
}
|
|
1841
|
-
const timeString = `${time.hours || '12'}:${time.minutes || '00'}`;
|
|
1842
|
-
return timeString.split(':').map(zeroPad).join(':');
|
|
2592
|
+
const extensionAttributes = Object.keys(extension);
|
|
2593
|
+
return (requiredAttributes.filter((attribute) => extensionAttributes.includes(attribute)).length ===
|
|
2594
|
+
requiredAttributes.length);
|
|
1843
2595
|
}
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
if (typeof
|
|
1847
|
-
return
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
2596
|
+
|
|
2597
|
+
function addExtension(params) {
|
|
2598
|
+
if (typeof params !== 'object')
|
|
2599
|
+
return { error: MISSING_VALUE };
|
|
2600
|
+
const stack = 'addExtension';
|
|
2601
|
+
if (params?.element && typeof params.element !== 'object')
|
|
2602
|
+
return decorateResult({ result: { error: INVALID_VALUES }, stack });
|
|
2603
|
+
if (!isValidExtension({ extension: params.extension }))
|
|
2604
|
+
return decorateResult({
|
|
2605
|
+
result: { error: INVALID_VALUES, info: 'invalid extension' },
|
|
2606
|
+
stack,
|
|
2607
|
+
});
|
|
2608
|
+
if (!params.element) {
|
|
2609
|
+
if (params.discover && !params.tournamentId && params.tournamentRecords) {
|
|
2610
|
+
for (const tournamentRecord of Object.values(params.tournamentRecords)) {
|
|
2611
|
+
const result = addExtension({
|
|
2612
|
+
extension: params.extension,
|
|
2613
|
+
element: tournamentRecord,
|
|
2614
|
+
});
|
|
2615
|
+
if (result.error)
|
|
2616
|
+
return decorateResult({ result, stack });
|
|
2617
|
+
}
|
|
2618
|
+
return { ...SUCCESS };
|
|
2619
|
+
}
|
|
2620
|
+
else {
|
|
2621
|
+
return decorateResult({ result: { error: MISSING_VALUE }, stack });
|
|
2622
|
+
}
|
|
1860
2623
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
2624
|
+
if (!params.element.extensions)
|
|
2625
|
+
params.element.extensions = [];
|
|
2626
|
+
const creationTime = params?.creationTime ?? true;
|
|
2627
|
+
if (creationTime) {
|
|
2628
|
+
const createdAt = new Date().toISOString();
|
|
2629
|
+
Object.assign(params.extension, { createdAt });
|
|
1863
2630
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
2631
|
+
const existingExtension = params.element.extensions.find(({ name }) => name === params.extension.name);
|
|
2632
|
+
if (existingExtension) {
|
|
2633
|
+
existingExtension.value = params.extension.value;
|
|
1866
2634
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
function convertTime(value, time24, keepDate) {
|
|
1870
|
-
const hasDate = extractDate(value);
|
|
1871
|
-
const timeString = extractTime(value);
|
|
1872
|
-
const timeValue = hasDate ? timeString : value;
|
|
1873
|
-
return !value
|
|
1874
|
-
? undefined
|
|
1875
|
-
: (time24 && ((hasDate && keepDate && value) || militaryTime(timeValue))) || regularTime(timeValue);
|
|
1876
|
-
}
|
|
1877
|
-
function timeSort(a, b) {
|
|
1878
|
-
const as = splitTime(a);
|
|
1879
|
-
const bs = splitTime(b);
|
|
1880
|
-
if (parseInt(as.hours) < parseInt(bs.hours))
|
|
1881
|
-
return -1;
|
|
1882
|
-
if (parseInt(as.hours) > parseInt(bs.hours))
|
|
1883
|
-
return 1;
|
|
1884
|
-
if (as.hours === bs.hours) {
|
|
1885
|
-
if (parseInt(as.minutes) < parseInt(bs.minutes))
|
|
1886
|
-
return -1;
|
|
1887
|
-
if (parseInt(as.minutes) > parseInt(bs.minutes))
|
|
1888
|
-
return 1;
|
|
2635
|
+
else if (params.extension.value) {
|
|
2636
|
+
params.element.extensions.push(params.extension);
|
|
1889
2637
|
}
|
|
1890
|
-
return
|
|
1891
|
-
}
|
|
1892
|
-
function addDays(date, days = 7) {
|
|
1893
|
-
const universalDate = extractDate(date) + 'T00:00';
|
|
1894
|
-
const now = new Date(universalDate);
|
|
1895
|
-
const adjustedDate = new Date(now.setDate(now.getDate() + days));
|
|
1896
|
-
return formatDate(adjustedDate);
|
|
1897
|
-
}
|
|
1898
|
-
function addWeek(date) {
|
|
1899
|
-
return addDays(date);
|
|
2638
|
+
return { ...SUCCESS };
|
|
1900
2639
|
}
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2640
|
+
|
|
2641
|
+
function addTournamentExtension(params) {
|
|
2642
|
+
if (!params || typeof params !== 'object')
|
|
2643
|
+
return { error: MISSING_VALUE };
|
|
2644
|
+
if (!params.tournamentRecord)
|
|
2645
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
2646
|
+
return addExtension({
|
|
2647
|
+
creationTime: params.creationTime,
|
|
2648
|
+
element: params.tournamentRecord,
|
|
2649
|
+
extension: params.extension,
|
|
2650
|
+
});
|
|
1906
2651
|
}
|
|
1907
|
-
function
|
|
1908
|
-
|
|
1909
|
-
|
|
2652
|
+
function addDrawDefinitionExtension(params) {
|
|
2653
|
+
if (!params || typeof params !== 'object')
|
|
2654
|
+
return { error: MISSING_VALUE };
|
|
2655
|
+
if (!params.drawDefinition)
|
|
2656
|
+
return { error: DRAW_DEFINITION_NOT_FOUND };
|
|
2657
|
+
return addExtension({
|
|
2658
|
+
creationTime: params.creationTime,
|
|
2659
|
+
element: params.drawDefinition,
|
|
2660
|
+
extension: params.extension,
|
|
2661
|
+
});
|
|
1910
2662
|
}
|
|
1911
|
-
function
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2663
|
+
function addEventExtension(params) {
|
|
2664
|
+
if (!params || typeof params !== 'object')
|
|
2665
|
+
return { error: MISSING_VALUE };
|
|
2666
|
+
if (!params.event)
|
|
2667
|
+
return { error: EVENT_NOT_FOUND };
|
|
2668
|
+
return addExtension({
|
|
2669
|
+
creationTime: params.creationTime,
|
|
2670
|
+
extension: params.extension,
|
|
2671
|
+
element: params.event,
|
|
2672
|
+
});
|
|
1915
2673
|
}
|
|
1916
|
-
function
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
2674
|
+
function addParticipantExtension(params) {
|
|
2675
|
+
if (!params || typeof params !== 'object')
|
|
2676
|
+
return { error: MISSING_VALUE };
|
|
2677
|
+
if (!params.participantId)
|
|
2678
|
+
return { error: MISSING_PARTICIPANT_ID };
|
|
2679
|
+
const tournamentParticipants = params.tournamentRecord?.participants || [];
|
|
2680
|
+
const participant = findParticipant({
|
|
2681
|
+
participantId: params.participantId,
|
|
2682
|
+
tournamentParticipants,
|
|
2683
|
+
});
|
|
2684
|
+
if (!participant)
|
|
2685
|
+
return { error: PARTICIPANT_NOT_FOUND };
|
|
2686
|
+
return addExtension({
|
|
2687
|
+
creationTime: params.creationTime,
|
|
2688
|
+
extension: params.extension,
|
|
2689
|
+
element: participant,
|
|
2690
|
+
});
|
|
1921
2691
|
}
|
|
1922
|
-
function
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
return
|
|
2692
|
+
function removeTournamentExtension(params) {
|
|
2693
|
+
if (!params || typeof params !== 'object')
|
|
2694
|
+
return { error: MISSING_VALUE };
|
|
2695
|
+
if (!params.tournamentRecord)
|
|
2696
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
2697
|
+
return removeExtension({
|
|
2698
|
+
element: params.tournamentRecord,
|
|
2699
|
+
name: params.name,
|
|
2700
|
+
});
|
|
1928
2701
|
}
|
|
1929
|
-
function
|
|
1930
|
-
|
|
1931
|
-
|
|
2702
|
+
function removeDrawDefinitionExtension(params) {
|
|
2703
|
+
if (!params || typeof params !== 'object')
|
|
2704
|
+
return { error: MISSING_VALUE };
|
|
2705
|
+
if (!params.drawDefinition)
|
|
2706
|
+
return { error: DRAW_DEFINITION_NOT_FOUND };
|
|
2707
|
+
return removeExtension({ element: params.drawDefinition, name: params.name });
|
|
1932
2708
|
}
|
|
1933
|
-
function
|
|
1934
|
-
|
|
2709
|
+
function removeEventExtension(params) {
|
|
2710
|
+
if (!params || typeof params !== 'object')
|
|
2711
|
+
return { error: MISSING_VALUE };
|
|
2712
|
+
if (!params?.event)
|
|
2713
|
+
return { error: EVENT_NOT_FOUND };
|
|
2714
|
+
return removeExtension({ element: params.event, name: params.name });
|
|
1935
2715
|
}
|
|
1936
|
-
function
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
2716
|
+
function removeParticipantExtension(params) {
|
|
2717
|
+
if (!params || typeof params !== 'object')
|
|
2718
|
+
return { error: MISSING_VALUE };
|
|
2719
|
+
if (!params.participantId)
|
|
2720
|
+
return { error: MISSING_PARTICIPANT_ID };
|
|
2721
|
+
const tournamentParticipants = params.tournamentRecord?.participants || [];
|
|
2722
|
+
const participant = findParticipant({
|
|
2723
|
+
participantId: params.participantId,
|
|
2724
|
+
tournamentParticipants,
|
|
2725
|
+
});
|
|
2726
|
+
if (!participant)
|
|
2727
|
+
return { error: PARTICIPANT_NOT_FOUND };
|
|
2728
|
+
return removeExtension({ element: participant, name: params.name });
|
|
1940
2729
|
}
|
|
1941
|
-
const dateTime = {
|
|
1942
|
-
addDays,
|
|
1943
|
-
addWeek,
|
|
1944
|
-
addMinutesToTimeString,
|
|
1945
|
-
convertTime,
|
|
1946
|
-
getIsoDateString,
|
|
1947
|
-
getUTCdateString,
|
|
1948
|
-
DateHHMM,
|
|
1949
|
-
extractDate,
|
|
1950
|
-
extractTime,
|
|
1951
|
-
formatDate,
|
|
1952
|
-
getDateByWeek,
|
|
1953
|
-
isISODateString,
|
|
1954
|
-
isDate,
|
|
1955
|
-
isTimeString,
|
|
1956
|
-
offsetDate,
|
|
1957
|
-
offsetTime,
|
|
1958
|
-
sameDay,
|
|
1959
|
-
timeStringMinutes,
|
|
1960
|
-
timeToDate,
|
|
1961
|
-
timeUTC,
|
|
1962
|
-
validTimeValue,
|
|
1963
|
-
validDateString,
|
|
1964
|
-
timeValidation,
|
|
1965
|
-
dateValidation,
|
|
1966
|
-
};
|
|
1967
2730
|
|
|
1968
|
-
function
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
const deepCopy = deepCopyEnabled();
|
|
1972
|
-
const { stringify, toJSON, ignore, modulate } = deepCopy || {};
|
|
1973
|
-
if ((!deepCopy?.enabled && !internalUse) ||
|
|
1974
|
-
typeof sourceObject !== 'object' ||
|
|
1975
|
-
typeof sourceObject === 'function' ||
|
|
1976
|
-
sourceObject === null ||
|
|
1977
|
-
(typeof deepCopy?.threshold === 'number' && iteration >= deepCopy.threshold)) {
|
|
1978
|
-
return sourceObject;
|
|
1979
|
-
}
|
|
1980
|
-
const targetObject = Array.isArray(sourceObject) ? [] : {};
|
|
1981
|
-
const sourceObjectKeys = Object.keys(sourceObject).filter((key) => !internalUse ||
|
|
1982
|
-
!ignore ||
|
|
1983
|
-
(Array.isArray(ignore) && !ignore.includes(key)) ||
|
|
1984
|
-
(typeof ignore === 'function' && !ignore(key)));
|
|
1985
|
-
const stringifyValue = (key, value) => {
|
|
1986
|
-
targetObject[key] = typeof value?.toString === 'function' ? value.toString() : JSON.stringify(value);
|
|
1987
|
-
};
|
|
1988
|
-
for (const key of sourceObjectKeys) {
|
|
1989
|
-
const value = sourceObject[key];
|
|
1990
|
-
const modulated = typeof modulate === 'function' ? modulate(value) : undefined;
|
|
1991
|
-
if (modulated !== undefined) {
|
|
1992
|
-
targetObject[key] = modulated;
|
|
1993
|
-
}
|
|
1994
|
-
else if (convertExtensions && key === 'extensions' && Array.isArray(value)) {
|
|
1995
|
-
const extensionConversions = extensionsToAttributes(value);
|
|
1996
|
-
Object.assign(targetObject, ...extensionConversions);
|
|
1997
|
-
}
|
|
1998
|
-
else if (removeExtensions && key === 'extensions') {
|
|
1999
|
-
targetObject[key] = [];
|
|
2000
|
-
}
|
|
2001
|
-
else if (Array.isArray(stringify) && stringify.includes(key)) {
|
|
2002
|
-
stringifyValue(key, value);
|
|
2003
|
-
}
|
|
2004
|
-
else if (Array.isArray(toJSON) && toJSON.includes(key) && typeof value?.toJSON === 'function') {
|
|
2005
|
-
targetObject[key] = value.toJSON();
|
|
2006
|
-
}
|
|
2007
|
-
else if (value === null) {
|
|
2008
|
-
targetObject[key] = undefined;
|
|
2009
|
-
}
|
|
2010
|
-
else if (isDateObject(value)) {
|
|
2011
|
-
targetObject[key] = new Date(value).toISOString();
|
|
2012
|
-
}
|
|
2013
|
-
else {
|
|
2014
|
-
targetObject[key] = makeDeepCopy(value, convertExtensions, internalUse, removeExtensions, iteration + 1);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
return targetObject;
|
|
2018
|
-
}
|
|
2019
|
-
function extensionsToAttributes(extensions) {
|
|
2020
|
-
return extensions
|
|
2021
|
-
?.map((extension) => {
|
|
2022
|
-
const { name, value } = extension;
|
|
2023
|
-
return name && value && { [`_${name}`]: value };
|
|
2024
|
-
})
|
|
2025
|
-
.filter(Boolean);
|
|
2731
|
+
function getTournamentIds({ tournamentRecords }) {
|
|
2732
|
+
const tournamentIds = isObject(tournamentRecords) ? Object.keys(tournamentRecords) : [];
|
|
2733
|
+
return { tournamentIds, ...SUCCESS };
|
|
2026
2734
|
}
|
|
2027
2735
|
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
if (targetElement?.[attribute]) {
|
|
2043
|
-
const remainingKeys = attributes.slice(index + 1);
|
|
2044
|
-
if (!remainingKeys.length) {
|
|
2045
|
-
if (!value)
|
|
2046
|
-
value = targetElement[attribute];
|
|
2047
|
-
if (!values.includes(targetElement[attribute])) {
|
|
2048
|
-
values.push(targetElement[attribute]);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
else if (Array.isArray(targetElement[attribute])) {
|
|
2052
|
-
const values = targetElement[attribute];
|
|
2053
|
-
values.forEach((nestedTarget) => processKeys({
|
|
2054
|
-
targetElement: nestedTarget,
|
|
2055
|
-
attributes: remainingKeys,
|
|
2056
|
-
}));
|
|
2057
|
-
}
|
|
2058
|
-
else {
|
|
2059
|
-
targetElement = targetElement[attribute];
|
|
2060
|
-
checkValue({ targetElement, index });
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
function checkValue({ targetElement, index }) {
|
|
2065
|
-
if (targetElement && index === attributes.length - 1 && ['string', 'number'].includes(typeof targetElement)) {
|
|
2066
|
-
const extractedValue = significantCharacters ? targetElement.slice(0, significantCharacters) : targetElement;
|
|
2067
|
-
if (value) {
|
|
2068
|
-
if (!values.includes(extractedValue)) {
|
|
2069
|
-
values.push(extractedValue);
|
|
2070
|
-
}
|
|
2071
|
-
}
|
|
2072
|
-
else {
|
|
2073
|
-
value = extractedValue;
|
|
2074
|
-
values.push(extractedValue);
|
|
2075
|
-
}
|
|
2736
|
+
const stack = 'extensionQueries';
|
|
2737
|
+
function findExtension({ discover, element, name, ...params }) {
|
|
2738
|
+
if (!element || !name) {
|
|
2739
|
+
if (discover && params) {
|
|
2740
|
+
const attr = Object.keys(params)
|
|
2741
|
+
.filter((key) => typeof discover === 'boolean' || (Array.isArray(discover) && discover.includes(key)))
|
|
2742
|
+
.find((key) => {
|
|
2743
|
+
if (!Array.isArray(params[key]?.extensions))
|
|
2744
|
+
return false;
|
|
2745
|
+
return params[key].extensions.find((extension) => extension?.name === name);
|
|
2746
|
+
});
|
|
2747
|
+
let element = attr && params[attr];
|
|
2748
|
+
if (!element && params.tournamentRecords) {
|
|
2749
|
+
element = Object.values(params.tournamentRecords).find((tournamentRecord) => tournamentRecord.extensions?.length);
|
|
2076
2750
|
}
|
|
2751
|
+
const extension = element?.extensions?.find((extension) => extension?.name === name);
|
|
2752
|
+
const info = !extension ? NOT_FOUND : undefined;
|
|
2753
|
+
return { extension, info };
|
|
2077
2754
|
}
|
|
2755
|
+
return decorateResult({ result: { error: MISSING_VALUE }, stack });
|
|
2078
2756
|
}
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
}
|
|
2084
|
-
function isString(obj) {
|
|
2085
|
-
return typeof obj === 'string';
|
|
2086
|
-
}
|
|
2087
|
-
function isObject(obj) {
|
|
2088
|
-
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
|
2089
|
-
}
|
|
2090
|
-
function objShallowEqual(o1, o2) {
|
|
2091
|
-
if (!isObject(o1) || !isObject(o2))
|
|
2092
|
-
return false;
|
|
2093
|
-
const keys1 = Object.keys(o1);
|
|
2094
|
-
const keys2 = Object.keys(o2);
|
|
2095
|
-
if (keys1.length !== keys2.length) {
|
|
2096
|
-
return false;
|
|
2097
|
-
}
|
|
2098
|
-
for (const key of keys1) {
|
|
2099
|
-
if (o1[key] !== o2[key]) {
|
|
2100
|
-
return false;
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
return true;
|
|
2104
|
-
}
|
|
2105
|
-
function createMap(objectArray, attribute) {
|
|
2106
|
-
if (!Array.isArray(objectArray))
|
|
2107
|
-
return {};
|
|
2108
|
-
return Object.assign({}, ...(objectArray ?? [])
|
|
2109
|
-
.filter(isObject)
|
|
2110
|
-
.map((obj) => {
|
|
2111
|
-
return (obj[attribute] && {
|
|
2112
|
-
[obj[attribute]]: obj,
|
|
2113
|
-
});
|
|
2114
|
-
})
|
|
2115
|
-
.filter(Boolean));
|
|
2116
|
-
}
|
|
2117
|
-
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
|
|
2118
|
-
const extractAttributes = (accessor) => (element) => !accessor || typeof element !== 'object'
|
|
2119
|
-
? undefined
|
|
2120
|
-
: (Array.isArray(accessor) &&
|
|
2121
|
-
accessor.map((a) => ({
|
|
2122
|
-
[a]: getAccessorValue({ element, accessor: a })?.value,
|
|
2123
|
-
}))) ||
|
|
2124
|
-
(typeof accessor === 'object' &&
|
|
2125
|
-
Object.keys(accessor).map((key) => ({
|
|
2126
|
-
[key]: getAccessorValue({ element, accessor: key })?.value,
|
|
2127
|
-
}))) ||
|
|
2128
|
-
(typeof accessor === 'string' && getAccessorValue({ element, accessor }))?.value;
|
|
2129
|
-
const xa = extractAttributes;
|
|
2130
|
-
function undefinedToNull(obj, shallow) {
|
|
2131
|
-
if (obj === undefined)
|
|
2132
|
-
return null;
|
|
2133
|
-
if (typeof obj !== 'object' || obj === null)
|
|
2134
|
-
return obj;
|
|
2135
|
-
const definedKeys = Object.keys(obj);
|
|
2136
|
-
const notNull = (value) => (value === undefined ? null : value);
|
|
2137
|
-
return Object.assign({}, ...definedKeys.map((key) => {
|
|
2138
|
-
return Array.isArray(obj[key])
|
|
2139
|
-
? {
|
|
2140
|
-
[key]: shallow ? obj[key] : obj[key].map((m) => undefinedToNull(m)),
|
|
2141
|
-
}
|
|
2142
|
-
: { [key]: shallow ? notNull(obj[key]) : undefinedToNull(obj[key]) };
|
|
2143
|
-
}));
|
|
2144
|
-
}
|
|
2145
|
-
function countKeys(o) {
|
|
2146
|
-
if (Array.isArray(o)) {
|
|
2147
|
-
return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
|
|
2148
|
-
}
|
|
2149
|
-
else if (typeof o === 'object' && o !== null) {
|
|
2150
|
-
return (Object.keys(o).length +
|
|
2151
|
-
Object.keys(o)
|
|
2152
|
-
.map((k) => countKeys(o[k]))
|
|
2153
|
-
.reduce((a, b) => a + b, 0));
|
|
2154
|
-
}
|
|
2155
|
-
return 0;
|
|
2156
|
-
}
|
|
2157
|
-
function generateHashCode(o) {
|
|
2158
|
-
if (o === null || typeof o !== 'object')
|
|
2159
|
-
return undefined;
|
|
2160
|
-
const str = JSON.stringify(o);
|
|
2161
|
-
const keyCount = countKeys(o);
|
|
2162
|
-
const charSum = str.split('').reduce((a, b) => a + b.charCodeAt(0), 0);
|
|
2163
|
-
return [str.length, keyCount, charSum].map((e) => e.toString(36)).join('');
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
const TOURNAMENT_RECORDS = 'tournamentRecords';
|
|
2167
|
-
const POLICY_DEFINITIONS = 'policyDefinitions';
|
|
2168
|
-
const TOURNAMENT_RECORD = 'tournamentRecord';
|
|
2169
|
-
const DRAW_DEFINITION = 'drawDefinition';
|
|
2170
|
-
const MATCHUP_FORMAT = 'matchUpFormat';
|
|
2171
|
-
const PARTICIPANT_ID = 'participantId';
|
|
2172
|
-
const SCHEDULE_DATES = 'scheduleDates';
|
|
2173
|
-
const TOURNAMENT_ID = 'tournamentId';
|
|
2174
|
-
const SCHEDULE_DATE = 'scheduleDate';
|
|
2175
|
-
const STRUCTURE_ID = 'structureId';
|
|
2176
|
-
const PARTICIPANT = 'participant';
|
|
2177
|
-
const MATCHUP_IDS = 'matchUpIds';
|
|
2178
|
-
const POLICY_TYPE = 'policyType';
|
|
2179
|
-
const STRUCTURES = 'structures';
|
|
2180
|
-
const MATCHUP_ID = 'matchUpId';
|
|
2181
|
-
const IN_CONTEXT = 'inContext';
|
|
2182
|
-
const STRUCTURE = 'structure';
|
|
2183
|
-
const COURT_IDS = 'courtIds';
|
|
2184
|
-
const PERSON_ID = 'personId';
|
|
2185
|
-
const VENUE_IDS = 'venueIds';
|
|
2186
|
-
const MATCHUPS = 'matchUps';
|
|
2187
|
-
const COURT_ID = 'courtId';
|
|
2188
|
-
const EVENT_ID = 'eventId';
|
|
2189
|
-
const MATCHUP = 'matchUp';
|
|
2190
|
-
const DRAW_ID = 'drawId';
|
|
2191
|
-
const ERROR = 'error';
|
|
2192
|
-
const EVENT = 'event';
|
|
2193
|
-
const PARAM = 'param';
|
|
2194
|
-
const UUIDS$1 = 'uuids';
|
|
2195
|
-
const AVERAGE_MATCHUP_MINUTES = 'averageMatchUpMinutes';
|
|
2196
|
-
const RECOVERY_MINUTES = 'recoveryMinutes';
|
|
2197
|
-
const PERIOD_LENGTH = 'periodLength';
|
|
2198
|
-
const OBJECT = 'object';
|
|
2199
|
-
const ARRAY = 'array';
|
|
2200
|
-
const VALIDATE = '_validate';
|
|
2201
|
-
const MESSAGE = '_message';
|
|
2202
|
-
const INVALID = '_invalid';
|
|
2203
|
-
const OF_TYPE = '_ofType';
|
|
2204
|
-
const ANY_OF = '_anyOf';
|
|
2205
|
-
const ONE_OF = '_oneOf';
|
|
2206
|
-
|
|
2207
|
-
const errors = {
|
|
2208
|
-
[TOURNAMENT_RECORDS]: MISSING_TOURNAMENT_RECORDS,
|
|
2209
|
-
[TOURNAMENT_RECORD]: MISSING_TOURNAMENT_RECORD,
|
|
2210
|
-
[POLICY_DEFINITIONS]: MISSING_POLICY_DEFINITION,
|
|
2211
|
-
[DRAW_DEFINITION]: MISSING_DRAW_DEFINITION,
|
|
2212
|
-
[PARTICIPANT_ID]: MISSING_PARTICIPANT_ID,
|
|
2213
|
-
[MATCHUP_FORMAT]: MISSING_MATCHUP_FORMAT,
|
|
2214
|
-
[TOURNAMENT_ID]: MISSING_TOURNAMENT_ID,
|
|
2215
|
-
[STRUCTURE_ID]: MISSING_STRUCTURE_ID,
|
|
2216
|
-
[MATCHUP_IDS]: MISSING_MATCHUP_IDS,
|
|
2217
|
-
[PARTICIPANT]: MISSING_PARTICIPANT,
|
|
2218
|
-
[STRUCTURES]: MISSING_STRUCTURES,
|
|
2219
|
-
[MATCHUP_ID]: MISSING_MATCHUP_ID,
|
|
2220
|
-
[STRUCTURE]: MISSING_STRUCTURE,
|
|
2221
|
-
[COURT_ID]: MISSING_COURT_ID,
|
|
2222
|
-
[MATCHUPS]: MISSING_MATCHUPS,
|
|
2223
|
-
[MATCHUP]: MISSING_MATCHUP,
|
|
2224
|
-
[COURT_IDS]: MISSING_VALUE,
|
|
2225
|
-
[VENUE_IDS]: MISSING_VALUE,
|
|
2226
|
-
[DRAW_ID]: MISSING_DRAW_ID,
|
|
2227
|
-
[EVENT_ID]: MISSING_EVENT,
|
|
2228
|
-
[EVENT]: EVENT_NOT_FOUND,
|
|
2229
|
-
};
|
|
2230
|
-
const paramTypes = {
|
|
2231
|
-
[TOURNAMENT_RECORDS]: OBJECT,
|
|
2232
|
-
[POLICY_DEFINITIONS]: OBJECT,
|
|
2233
|
-
[TOURNAMENT_RECORD]: OBJECT,
|
|
2234
|
-
[DRAW_DEFINITION]: OBJECT,
|
|
2235
|
-
[SCHEDULE_DATES]: ARRAY,
|
|
2236
|
-
[PARTICIPANT]: OBJECT,
|
|
2237
|
-
[MATCHUP_IDS]: ARRAY,
|
|
2238
|
-
[STRUCTURES]: ARRAY,
|
|
2239
|
-
[STRUCTURE]: OBJECT,
|
|
2240
|
-
[COURT_IDS]: ARRAY,
|
|
2241
|
-
[VENUE_IDS]: ARRAY,
|
|
2242
|
-
[MATCHUPS]: ARRAY,
|
|
2243
|
-
[MATCHUP]: OBJECT,
|
|
2244
|
-
[EVENT]: OBJECT,
|
|
2245
|
-
[UUIDS$1]: ARRAY,
|
|
2246
|
-
};
|
|
2247
|
-
function checkRequiredParameters(params, requiredParams, stack) {
|
|
2248
|
-
if (!params && !isObject(params))
|
|
2249
|
-
return { error: INVALID_VALUES };
|
|
2250
|
-
if (!requiredParams?.length || params?._bypassParamCheck)
|
|
2251
|
-
return { valid: true };
|
|
2252
|
-
if (!Array.isArray(requiredParams))
|
|
2253
|
-
return { error: INVALID_VALUES };
|
|
2254
|
-
const { paramError, errorParam } = findParamError(params, requiredParams);
|
|
2255
|
-
if (!paramError)
|
|
2256
|
-
return { valid: true };
|
|
2257
|
-
const error = params?.[errorParam] === undefined
|
|
2258
|
-
? errors[errorParam] || INVALID_VALUES
|
|
2259
|
-
: (paramError[VALIDATE] && paramError[INVALID]) || INVALID_VALUES;
|
|
2260
|
-
const param = errorParam ?? (paramError[ONE_OF] && Object.keys(paramError[ONE_OF]).join(', '));
|
|
2261
|
-
return decorateResult({
|
|
2262
|
-
info: { param, message: paramError[MESSAGE] },
|
|
2263
|
-
result: { error },
|
|
2264
|
-
stack,
|
|
2265
|
-
});
|
|
2266
|
-
}
|
|
2267
|
-
function getIntersection(params, constraint) {
|
|
2268
|
-
const paramKeys = Object.keys(params);
|
|
2269
|
-
const constraintKeys = Object.keys(constraint);
|
|
2270
|
-
return intersection(paramKeys, constraintKeys);
|
|
2271
|
-
}
|
|
2272
|
-
function getOneOf(params, _oneOf) {
|
|
2273
|
-
if (!_oneOf)
|
|
2274
|
-
return;
|
|
2275
|
-
const overlap = getIntersection(params, _oneOf);
|
|
2276
|
-
if (overlap.length !== 1)
|
|
2277
|
-
return { error: INVALID_VALUES };
|
|
2278
|
-
return overlap.reduce((attr, param) => ({ ...attr, [param]: true }), {});
|
|
2279
|
-
}
|
|
2280
|
-
function getAnyOf(params, _anyOf) {
|
|
2281
|
-
if (!_anyOf)
|
|
2282
|
-
return;
|
|
2283
|
-
const overlap = getIntersection(params, _anyOf).filter((param) => params[param]);
|
|
2284
|
-
if (overlap.length < 1)
|
|
2285
|
-
return { error: INVALID_VALUES };
|
|
2286
|
-
return overlap.reduce((attr, param) => ({ ...attr, [param]: true }), {});
|
|
2287
|
-
}
|
|
2288
|
-
function findParamError(params, requiredParams) {
|
|
2289
|
-
let errorParam, paramInfo;
|
|
2290
|
-
const paramError = requiredParams.find(({ _ofType, _oneOf, _anyOf, _validate, _info, ...attrs }) => {
|
|
2291
|
-
const oneOf = _oneOf && getOneOf(params, _oneOf);
|
|
2292
|
-
if (oneOf?.error)
|
|
2293
|
-
return oneOf.error;
|
|
2294
|
-
oneOf && Object.assign(attrs, oneOf);
|
|
2295
|
-
const anyOf = _anyOf && getAnyOf(params, _anyOf);
|
|
2296
|
-
if (anyOf?.error)
|
|
2297
|
-
return anyOf.error;
|
|
2298
|
-
anyOf && Object.assign(attrs, anyOf);
|
|
2299
|
-
const booleanParams = Object.keys(attrs).filter((key) => typeof attrs[key] === 'boolean');
|
|
2300
|
-
const invalidParam = booleanParams.find((param) => {
|
|
2301
|
-
const invalidValidationFunction = _validate && !isFunction(_validate);
|
|
2302
|
-
const faliedTypeCheck = params[param] && !_validate && invalidType(params, param, _ofType);
|
|
2303
|
-
const paramNotPresent = attrs[param] && !params[param];
|
|
2304
|
-
const invalid = invalidValidationFunction || faliedTypeCheck || paramNotPresent;
|
|
2305
|
-
const hasError = invalid || (_validate && params[param] && !checkValidation(params[param], _validate));
|
|
2306
|
-
if (hasError) {
|
|
2307
|
-
errorParam = param;
|
|
2308
|
-
paramInfo = _info;
|
|
2309
|
-
}
|
|
2310
|
-
return hasError;
|
|
2311
|
-
});
|
|
2312
|
-
return !booleanParams.length || invalidParam;
|
|
2313
|
-
});
|
|
2314
|
-
return { paramError, errorParam, paramInfo };
|
|
2315
|
-
}
|
|
2316
|
-
function invalidType(params, param, _ofType) {
|
|
2317
|
-
_ofType = _ofType || paramTypes[param] || 'string';
|
|
2318
|
-
if (_ofType === 'array') {
|
|
2319
|
-
return !Array.isArray(params[param]);
|
|
2320
|
-
}
|
|
2321
|
-
return typeof params[param] !== _ofType;
|
|
2322
|
-
}
|
|
2323
|
-
function checkValidation(value, validate) {
|
|
2324
|
-
if (isFunction(validate))
|
|
2325
|
-
return validate(value);
|
|
2326
|
-
return true;
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
const SINGLES$1 = 'SINGLES';
|
|
2330
|
-
const SINGLES_EVENT = 'SINGLES';
|
|
2331
|
-
const DOUBLES$1 = 'DOUBLES';
|
|
2332
|
-
const DOUBLES_EVENT = 'DOUBLES';
|
|
2333
|
-
const TEAM$2 = 'TEAM';
|
|
2334
|
-
const TEAM_EVENT = 'TEAM';
|
|
2335
|
-
const AGE = 'AGE';
|
|
2336
|
-
const RATING$2 = 'RATING';
|
|
2337
|
-
const BOTH = 'BOTH';
|
|
2338
|
-
const eventConstants = {
|
|
2339
|
-
AGE,
|
|
2340
|
-
BOTH,
|
|
2341
|
-
DOUBLES: DOUBLES$1,
|
|
2342
|
-
DOUBLES_EVENT,
|
|
2343
|
-
RATING: RATING$2,
|
|
2344
|
-
SINGLES: SINGLES$1,
|
|
2345
|
-
SINGLES_EVENT,
|
|
2346
|
-
TEAM_EVENT,
|
|
2347
|
-
TEAM: TEAM$2,
|
|
2348
|
-
};
|
|
2349
|
-
|
|
2350
|
-
const DYNAMIC = 'DYNAMIC';
|
|
2351
|
-
const RANKING$1 = 'RANKING';
|
|
2352
|
-
const RATING$1 = 'RATING';
|
|
2353
|
-
const SCALE$1 = 'SCALE';
|
|
2354
|
-
const SEEDING$1 = 'SEEDING';
|
|
2355
|
-
const scaleConstants = {
|
|
2356
|
-
RANKING: RANKING$1,
|
|
2357
|
-
RATING: RATING$1,
|
|
2358
|
-
SCALE: SCALE$1,
|
|
2359
|
-
SEEDING: SEEDING$1,
|
|
2360
|
-
};
|
|
2361
|
-
|
|
2362
|
-
function getScaleValues(params) {
|
|
2363
|
-
const paramCheck = checkRequiredParameters(params, [{ [PARTICIPANT]: true }]);
|
|
2364
|
-
if (paramCheck.error)
|
|
2365
|
-
return paramCheck;
|
|
2366
|
-
const scaleItems = params.participant.timeItems?.filter(({ itemType }) => itemType?.startsWith(SCALE$1) && [RANKING$1, RATING$1, SEEDING$1].includes(itemType.split('.')[1]));
|
|
2367
|
-
const scales = { ratings: {}, rankings: {}, seedings: {} };
|
|
2368
|
-
if (scaleItems?.length) {
|
|
2369
|
-
const latestScaleItem = (scaleType) => scaleItems
|
|
2370
|
-
.filter((timeItem) => timeItem?.itemType === scaleType)
|
|
2371
|
-
.sort((a, b) => new Date(a.createdAt || undefined).getTime() - new Date(b.createdAt || undefined).getTime())
|
|
2372
|
-
.pop();
|
|
2373
|
-
const itemTypes = unique(scaleItems.map(({ itemType }) => itemType));
|
|
2374
|
-
for (const itemType of itemTypes) {
|
|
2375
|
-
const scaleItem = latestScaleItem(itemType);
|
|
2376
|
-
if (scaleItem) {
|
|
2377
|
-
const [, type, format, scaleName, modifier] = scaleItem.itemType.split('.');
|
|
2378
|
-
const namedScale = modifier ? `${scaleName}.${modifier}` : scaleName;
|
|
2379
|
-
const scaleType = (type === SEEDING$1 && 'seedings') || (type === RANKING$1 && 'rankings') || 'ratings';
|
|
2380
|
-
if (!scales[scaleType][format])
|
|
2381
|
-
scales[scaleType][format] = [];
|
|
2382
|
-
scales[scaleType][format].push({
|
|
2383
|
-
scaleValue: scaleItem.itemValue,
|
|
2384
|
-
scaleDate: scaleItem.itemDate,
|
|
2385
|
-
scaleName: namedScale,
|
|
2386
|
-
});
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
}
|
|
2390
|
-
return { ...SUCCESS, ...scales };
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
function attributeFilter(params) {
|
|
2394
|
-
if (params === null)
|
|
2395
|
-
return {};
|
|
2396
|
-
const { source, template } = params || {};
|
|
2397
|
-
if (!template)
|
|
2398
|
-
return source;
|
|
2399
|
-
const target = {};
|
|
2400
|
-
attributeCopy(source, template, target);
|
|
2401
|
-
return target;
|
|
2402
|
-
function attributeCopy(valuesObject, templateObject, outputObject) {
|
|
2403
|
-
if (!valuesObject || !templateObject)
|
|
2404
|
-
return undefined;
|
|
2405
|
-
const vKeys = Object.keys(valuesObject);
|
|
2406
|
-
const oKeys = Object.keys(templateObject);
|
|
2407
|
-
const orMap = Object.assign({}, ...oKeys
|
|
2408
|
-
.filter((key) => key.indexOf('||'))
|
|
2409
|
-
.map((key) => key.split('||').map((or) => ({ [or]: key })))
|
|
2410
|
-
.flat());
|
|
2411
|
-
const allKeys = oKeys.concat(...Object.keys(orMap));
|
|
2412
|
-
const wildcard = allKeys.includes('*');
|
|
2413
|
-
for (const vKey of vKeys) {
|
|
2414
|
-
if (allKeys.indexOf(vKey) >= 0 || wildcard) {
|
|
2415
|
-
const templateKey = orMap[vKey] || vKey;
|
|
2416
|
-
const tobj = templateObject[templateKey] || wildcard;
|
|
2417
|
-
const vobj = valuesObject[vKey];
|
|
2418
|
-
if (typeof tobj === 'object' && typeof vobj !== 'function' && !Array.isArray(tobj)) {
|
|
2419
|
-
if (Array.isArray(vobj)) {
|
|
2420
|
-
const mappedElements = vobj
|
|
2421
|
-
.map((arrayMember) => {
|
|
2422
|
-
const target = {};
|
|
2423
|
-
const result = attributeCopy(arrayMember, tobj, target);
|
|
2424
|
-
return result !== false ? target : undefined;
|
|
2425
|
-
})
|
|
2426
|
-
.filter(Boolean);
|
|
2427
|
-
outputObject[vKey] = mappedElements;
|
|
2428
|
-
}
|
|
2429
|
-
else if (vobj) {
|
|
2430
|
-
outputObject[vKey] = {};
|
|
2431
|
-
attributeCopy(vobj, tobj, outputObject[vKey]);
|
|
2432
|
-
}
|
|
2433
|
-
}
|
|
2434
|
-
else {
|
|
2435
|
-
const value = valuesObject[vKey];
|
|
2436
|
-
const exclude = Array.isArray(tobj) && !tobj.includes(value);
|
|
2437
|
-
if (exclude)
|
|
2438
|
-
return false;
|
|
2439
|
-
if (templateObject[vKey] || (wildcard && templateObject[vKey] !== false)) {
|
|
2440
|
-
outputObject[vKey] = value;
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
return undefined;
|
|
2446
|
-
}
|
|
2447
|
-
}
|
|
2448
|
-
|
|
2449
|
-
const POLICY_TYPE_VOLUNTARY_CONSOLATION = 'voluntaryConsolation';
|
|
2450
|
-
const POLICY_TYPE_COMPETITIVE_BANDS = 'competitiveBands';
|
|
2451
|
-
const POLICY_TYPE_ROUND_ROBIN_TALLY = 'roundRobinTally';
|
|
2452
|
-
const POLICY_TYPE_POSITION_ACTIONS = 'positionActions';
|
|
2453
|
-
const POLICY_TYPE_MATCHUP_ACTIONS = 'matchUpActions';
|
|
2454
|
-
const POLICY_TYPE_RANKING_POINTS = 'rankingPoints';
|
|
2455
|
-
const POLICY_TYPE_ROUND_NAMING = 'roundNaming';
|
|
2456
|
-
const POLICY_TYPE_PARTICIPANT = 'participant';
|
|
2457
|
-
const POLICY_TYPE_PROGRESSION = 'progression';
|
|
2458
|
-
const POLICY_TYPE_SCHEDULING = 'scheduling';
|
|
2459
|
-
const POLICY_TYPE_AVOIDANCE = 'avoidance';
|
|
2460
|
-
const POLICY_TYPE_DISPLAY = 'display';
|
|
2461
|
-
const POLICY_TYPE_SCORING = 'scoring';
|
|
2462
|
-
const POLICY_TYPE_SEEDING = 'seeding';
|
|
2463
|
-
const POLICY_TYPE_FEED_IN = 'feedIn';
|
|
2464
|
-
const POLICY_TYPE_AUDIT = 'audit';
|
|
2465
|
-
const POLICY_TYPE_DRAWS = 'draws';
|
|
2466
|
-
const policyConstants = {
|
|
2467
|
-
POLICY_TYPE_VOLUNTARY_CONSOLATION,
|
|
2468
|
-
POLICY_TYPE_COMPETITIVE_BANDS,
|
|
2469
|
-
POLICY_TYPE_ROUND_ROBIN_TALLY,
|
|
2470
|
-
POLICY_TYPE_POSITION_ACTIONS,
|
|
2471
|
-
POLICY_TYPE_MATCHUP_ACTIONS,
|
|
2472
|
-
POLICY_TYPE_RANKING_POINTS,
|
|
2473
|
-
POLICY_TYPE_ROUND_NAMING,
|
|
2474
|
-
POLICY_TYPE_PARTICIPANT,
|
|
2475
|
-
POLICY_TYPE_PROGRESSION,
|
|
2476
|
-
POLICY_TYPE_SCHEDULING,
|
|
2477
|
-
POLICY_TYPE_AVOIDANCE,
|
|
2478
|
-
POLICY_TYPE_DISPLAY,
|
|
2479
|
-
POLICY_TYPE_FEED_IN,
|
|
2480
|
-
POLICY_TYPE_SCORING,
|
|
2481
|
-
POLICY_TYPE_SEEDING,
|
|
2482
|
-
POLICY_TYPE_AUDIT,
|
|
2483
|
-
POLICY_TYPE_DRAWS,
|
|
2484
|
-
};
|
|
2485
|
-
|
|
2486
|
-
function findParticipant({ tournamentParticipants = [], policyDefinitions = {}, contextProfile, participantId, internalUse, personId, }) {
|
|
2487
|
-
const foundParticipant = tournamentParticipants.find((candidate) => (participantId && candidate.participantId === participantId) ||
|
|
2488
|
-
(personId && candidate.person && candidate.person.personId === personId));
|
|
2489
|
-
const participant = makeDeepCopy(foundParticipant, false, internalUse);
|
|
2490
|
-
if (participant) {
|
|
2491
|
-
const participantAttributes = policyDefinitions?.[POLICY_TYPE_PARTICIPANT];
|
|
2492
|
-
if (contextProfile?.withScaleValues) {
|
|
2493
|
-
const { ratings, rankings } = getScaleValues({ participant });
|
|
2494
|
-
participant.rankings = rankings;
|
|
2495
|
-
participant.ratings = ratings;
|
|
2496
|
-
}
|
|
2497
|
-
if (participantAttributes?.participant) {
|
|
2498
|
-
return attributeFilter({
|
|
2499
|
-
template: participantAttributes.participant,
|
|
2500
|
-
source: participant,
|
|
2501
|
-
});
|
|
2502
|
-
}
|
|
2503
|
-
}
|
|
2504
|
-
return participant;
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
const ELEMENT_REQUIRED = 'element required';
|
|
2508
|
-
const MISSING_NAME = 'missing name';
|
|
2509
|
-
|
|
2510
|
-
function removeExtension(params) {
|
|
2511
|
-
if (!params || typeof params !== 'object')
|
|
2512
|
-
return { error: MISSING_VALUE };
|
|
2513
|
-
if (params.element && typeof params?.element !== 'object')
|
|
2514
|
-
return { error: INVALID_VALUES };
|
|
2515
|
-
if (!params?.name)
|
|
2516
|
-
return { error: MISSING_VALUE, info: MISSING_NAME };
|
|
2517
|
-
if (!params?.element) {
|
|
2518
|
-
if (params.discover && params.tournamentRecords) {
|
|
2519
|
-
for (const tournamentId of Object.keys(params.tournamentRecords)) {
|
|
2520
|
-
const tournamentRecord = params.tournamentRecords[tournamentId];
|
|
2521
|
-
const result = removeExtension({
|
|
2522
|
-
element: tournamentRecord,
|
|
2523
|
-
name: params.name,
|
|
2524
|
-
});
|
|
2525
|
-
if (result.error)
|
|
2526
|
-
return decorateResult({ result, stack: 'removeExtension' });
|
|
2527
|
-
}
|
|
2528
|
-
return { ...SUCCESS };
|
|
2529
|
-
}
|
|
2530
|
-
return { error: MISSING_VALUE, info: ELEMENT_REQUIRED };
|
|
2531
|
-
}
|
|
2532
|
-
if (!params?.element.extensions)
|
|
2533
|
-
return { ...SUCCESS, info: NOT_FOUND };
|
|
2534
|
-
params.element.extensions = params.element.extensions.filter((extension) => extension?.name !== params.name);
|
|
2535
|
-
return { ...SUCCESS };
|
|
2536
|
-
}
|
|
2537
|
-
|
|
2538
|
-
function isValidExtension({ requiredAttributes = ['name', 'value'], extension }) {
|
|
2539
|
-
if (!extension || typeof extension !== 'object')
|
|
2540
|
-
return false;
|
|
2541
|
-
if (typeof extension.name !== 'string')
|
|
2542
|
-
return false;
|
|
2543
|
-
const extensionAttributes = Object.keys(extension);
|
|
2544
|
-
return (requiredAttributes.filter((attribute) => extensionAttributes.includes(attribute)).length ===
|
|
2545
|
-
requiredAttributes.length);
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
|
-
function addExtension(params) {
|
|
2549
|
-
if (typeof params !== 'object')
|
|
2550
|
-
return { error: MISSING_VALUE };
|
|
2551
|
-
const stack = 'addExtension';
|
|
2552
|
-
if (params?.element && typeof params.element !== 'object')
|
|
2553
|
-
return decorateResult({ result: { error: INVALID_VALUES }, stack });
|
|
2554
|
-
if (!isValidExtension({ extension: params.extension }))
|
|
2555
|
-
return decorateResult({
|
|
2556
|
-
result: { error: INVALID_VALUES, info: 'invalid extension' },
|
|
2557
|
-
stack,
|
|
2558
|
-
});
|
|
2559
|
-
if (!params.element) {
|
|
2560
|
-
if (params.discover && !params.tournamentId && params.tournamentRecords) {
|
|
2561
|
-
for (const tournamentRecord of Object.values(params.tournamentRecords)) {
|
|
2562
|
-
const result = addExtension({
|
|
2563
|
-
extension: params.extension,
|
|
2564
|
-
element: tournamentRecord,
|
|
2565
|
-
});
|
|
2566
|
-
if (result.error)
|
|
2567
|
-
return decorateResult({ result, stack });
|
|
2568
|
-
}
|
|
2569
|
-
return { ...SUCCESS };
|
|
2570
|
-
}
|
|
2571
|
-
else {
|
|
2572
|
-
return decorateResult({ result: { error: MISSING_VALUE }, stack });
|
|
2573
|
-
}
|
|
2574
|
-
}
|
|
2575
|
-
if (!params.element.extensions)
|
|
2576
|
-
params.element.extensions = [];
|
|
2577
|
-
const creationTime = params?.creationTime ?? true;
|
|
2578
|
-
if (creationTime) {
|
|
2579
|
-
const createdAt = new Date().toISOString();
|
|
2580
|
-
Object.assign(params.extension, { createdAt });
|
|
2581
|
-
}
|
|
2582
|
-
const existingExtension = params.element.extensions.find(({ name }) => name === params.extension.name);
|
|
2583
|
-
if (existingExtension) {
|
|
2584
|
-
existingExtension.value = params.extension.value;
|
|
2585
|
-
}
|
|
2586
|
-
else if (params.extension.value) {
|
|
2587
|
-
params.element.extensions.push(params.extension);
|
|
2588
|
-
}
|
|
2589
|
-
return { ...SUCCESS };
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2592
|
-
function addTournamentExtension(params) {
|
|
2593
|
-
if (!params || typeof params !== 'object')
|
|
2594
|
-
return { error: MISSING_VALUE };
|
|
2595
|
-
if (!params.tournamentRecord)
|
|
2596
|
-
return { error: MISSING_TOURNAMENT_RECORD };
|
|
2597
|
-
return addExtension({
|
|
2598
|
-
creationTime: params.creationTime,
|
|
2599
|
-
element: params.tournamentRecord,
|
|
2600
|
-
extension: params.extension,
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
function addDrawDefinitionExtension(params) {
|
|
2604
|
-
if (!params || typeof params !== 'object')
|
|
2605
|
-
return { error: MISSING_VALUE };
|
|
2606
|
-
if (!params.drawDefinition)
|
|
2607
|
-
return { error: DRAW_DEFINITION_NOT_FOUND };
|
|
2608
|
-
return addExtension({
|
|
2609
|
-
creationTime: params.creationTime,
|
|
2610
|
-
element: params.drawDefinition,
|
|
2611
|
-
extension: params.extension,
|
|
2612
|
-
});
|
|
2613
|
-
}
|
|
2614
|
-
function addEventExtension(params) {
|
|
2615
|
-
if (!params || typeof params !== 'object')
|
|
2616
|
-
return { error: MISSING_VALUE };
|
|
2617
|
-
if (!params.event)
|
|
2618
|
-
return { error: EVENT_NOT_FOUND };
|
|
2619
|
-
return addExtension({
|
|
2620
|
-
creationTime: params.creationTime,
|
|
2621
|
-
extension: params.extension,
|
|
2622
|
-
element: params.event,
|
|
2623
|
-
});
|
|
2624
|
-
}
|
|
2625
|
-
function addParticipantExtension(params) {
|
|
2626
|
-
if (!params || typeof params !== 'object')
|
|
2627
|
-
return { error: MISSING_VALUE };
|
|
2628
|
-
if (!params.participantId)
|
|
2629
|
-
return { error: MISSING_PARTICIPANT_ID };
|
|
2630
|
-
const tournamentParticipants = params.tournamentRecord?.participants || [];
|
|
2631
|
-
const participant = findParticipant({
|
|
2632
|
-
participantId: params.participantId,
|
|
2633
|
-
tournamentParticipants,
|
|
2634
|
-
});
|
|
2635
|
-
if (!participant)
|
|
2636
|
-
return { error: PARTICIPANT_NOT_FOUND };
|
|
2637
|
-
return addExtension({
|
|
2638
|
-
creationTime: params.creationTime,
|
|
2639
|
-
extension: params.extension,
|
|
2640
|
-
element: participant,
|
|
2641
|
-
});
|
|
2642
|
-
}
|
|
2643
|
-
function removeTournamentExtension(params) {
|
|
2644
|
-
if (!params || typeof params !== 'object')
|
|
2645
|
-
return { error: MISSING_VALUE };
|
|
2646
|
-
if (!params.tournamentRecord)
|
|
2647
|
-
return { error: MISSING_TOURNAMENT_RECORD };
|
|
2648
|
-
return removeExtension({
|
|
2649
|
-
element: params.tournamentRecord,
|
|
2650
|
-
name: params.name,
|
|
2651
|
-
});
|
|
2652
|
-
}
|
|
2653
|
-
function removeDrawDefinitionExtension(params) {
|
|
2654
|
-
if (!params || typeof params !== 'object')
|
|
2655
|
-
return { error: MISSING_VALUE };
|
|
2656
|
-
if (!params.drawDefinition)
|
|
2657
|
-
return { error: DRAW_DEFINITION_NOT_FOUND };
|
|
2658
|
-
return removeExtension({ element: params.drawDefinition, name: params.name });
|
|
2659
|
-
}
|
|
2660
|
-
function removeEventExtension(params) {
|
|
2661
|
-
if (!params || typeof params !== 'object')
|
|
2662
|
-
return { error: MISSING_VALUE };
|
|
2663
|
-
if (!params?.event)
|
|
2664
|
-
return { error: EVENT_NOT_FOUND };
|
|
2665
|
-
return removeExtension({ element: params.event, name: params.name });
|
|
2666
|
-
}
|
|
2667
|
-
function removeParticipantExtension(params) {
|
|
2668
|
-
if (!params || typeof params !== 'object')
|
|
2669
|
-
return { error: MISSING_VALUE };
|
|
2670
|
-
if (!params.participantId)
|
|
2671
|
-
return { error: MISSING_PARTICIPANT_ID };
|
|
2672
|
-
const tournamentParticipants = params.tournamentRecord?.participants || [];
|
|
2673
|
-
const participant = findParticipant({
|
|
2674
|
-
participantId: params.participantId,
|
|
2675
|
-
tournamentParticipants,
|
|
2676
|
-
});
|
|
2677
|
-
if (!participant)
|
|
2678
|
-
return { error: PARTICIPANT_NOT_FOUND };
|
|
2679
|
-
return removeExtension({ element: participant, name: params.name });
|
|
2680
|
-
}
|
|
2681
|
-
|
|
2682
|
-
function getTournamentIds({ tournamentRecords }) {
|
|
2683
|
-
const tournamentIds = isObject(tournamentRecords) ? Object.keys(tournamentRecords) : [];
|
|
2684
|
-
return { tournamentIds, ...SUCCESS };
|
|
2685
|
-
}
|
|
2686
|
-
|
|
2687
|
-
const stack = 'extensionQueries';
|
|
2688
|
-
function findExtension({ discover, element, name, ...params }) {
|
|
2689
|
-
if (!element || !name) {
|
|
2690
|
-
if (discover && params) {
|
|
2691
|
-
const attr = Object.keys(params)
|
|
2692
|
-
.filter((key) => typeof discover === 'boolean' || (Array.isArray(discover) && discover.includes(key)))
|
|
2693
|
-
.find((key) => {
|
|
2694
|
-
if (!Array.isArray(params[key]?.extensions))
|
|
2695
|
-
return false;
|
|
2696
|
-
return params[key].extensions.find((extension) => extension?.name === name);
|
|
2697
|
-
});
|
|
2698
|
-
let element = attr && params[attr];
|
|
2699
|
-
if (!element && params.tournamentRecords) {
|
|
2700
|
-
element = Object.values(params.tournamentRecords).find((tournamentRecord) => tournamentRecord.extensions?.length);
|
|
2701
|
-
}
|
|
2702
|
-
const extension = element?.extensions?.find((extension) => extension?.name === name);
|
|
2703
|
-
const info = !extension ? NOT_FOUND : undefined;
|
|
2704
|
-
return { extension, info };
|
|
2705
|
-
}
|
|
2706
|
-
return decorateResult({ result: { error: MISSING_VALUE }, stack });
|
|
2707
|
-
}
|
|
2708
|
-
if (!Array.isArray(element.extensions))
|
|
2709
|
-
return { info: 'no extensions' };
|
|
2710
|
-
const extension = element.extensions.find((extension) => extension?.name === name);
|
|
2711
|
-
const info = !extension ? NOT_FOUND : undefined;
|
|
2712
|
-
return { extension, info };
|
|
2757
|
+
if (!Array.isArray(element.extensions))
|
|
2758
|
+
return { info: 'no extensions' };
|
|
2759
|
+
const extension = element.extensions.find((extension) => extension?.name === name);
|
|
2760
|
+
const info = !extension ? NOT_FOUND : undefined;
|
|
2761
|
+
return { extension, info };
|
|
2713
2762
|
}
|
|
2714
2763
|
|
|
2715
2764
|
const ACTIVE_SUSPENSION = 'activeSuspension';
|
|
@@ -11466,7 +11515,7 @@ function getPublishState(params) {
|
|
|
11466
11515
|
};
|
|
11467
11516
|
}
|
|
11468
11517
|
else if (Array.isArray(drawIds) && drawIds?.length) {
|
|
11469
|
-
const eventDrawIds = event.drawDefinitions?.map(getDrawId)
|
|
11518
|
+
const eventDrawIds = event.drawDefinitions?.map(getDrawId) ?? [];
|
|
11470
11519
|
for (const drawId of drawIds) {
|
|
11471
11520
|
if (!isString(drawId))
|
|
11472
11521
|
return { error: INVALID_VALUES };
|
|
@@ -26787,8 +26836,8 @@ function getTournamentInfo(params) {
|
|
|
26787
26836
|
const publishState = getPublishState({ tournamentRecord })?.publishState;
|
|
26788
26837
|
const publishedEventIds = publishState?.tournament?.status?.publishedEventIds || [];
|
|
26789
26838
|
const eventInfo = [];
|
|
26790
|
-
for (const event of tournamentRecord.events
|
|
26791
|
-
if (publishedEventIds.includes(event.eventId)) {
|
|
26839
|
+
for (const event of tournamentRecord.events ?? []) {
|
|
26840
|
+
if (!params?.usePublishState || publishedEventIds.includes(event.eventId)) {
|
|
26792
26841
|
const info = extractEventInfo({ event }).eventInfo;
|
|
26793
26842
|
if (info)
|
|
26794
26843
|
eventInfo.push(info);
|
|
@@ -26801,371 +26850,938 @@ function getTournamentInfo(params) {
|
|
|
26801
26850
|
};
|
|
26802
26851
|
}
|
|
26803
26852
|
|
|
26804
|
-
function getCompetitionDateRange({ tournamentRecords }) {
|
|
26805
|
-
if (!isObject(tournamentRecords))
|
|
26806
|
-
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
26807
|
-
const tournamentIds = Object.keys(tournamentRecords ?? {});
|
|
26808
|
-
const dateRange = tournamentIds.reduce((dateRange, tournamentId) => {
|
|
26853
|
+
function getCompetitionDateRange({ tournamentRecords }) {
|
|
26854
|
+
if (!isObject(tournamentRecords))
|
|
26855
|
+
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
26856
|
+
const tournamentIds = Object.keys(tournamentRecords ?? {});
|
|
26857
|
+
const dateRange = tournamentIds.reduce((dateRange, tournamentId) => {
|
|
26858
|
+
const tournamentRecord = tournamentRecords[tournamentId];
|
|
26859
|
+
const { tournamentInfo: { startDate, endDate }, } = getTournamentInfo({ tournamentRecord });
|
|
26860
|
+
const dateOfStart = startDate && new Date(extractDate(startDate));
|
|
26861
|
+
if (!dateRange.startDate || (dateOfStart && dateOfStart < dateRange.startDate)) {
|
|
26862
|
+
dateRange.startDate = dateOfStart;
|
|
26863
|
+
}
|
|
26864
|
+
const dateOfEnd = endDate && new Date(extractDate(endDate));
|
|
26865
|
+
if (!dateRange.endDate || (dateOfEnd && dateOfEnd > dateRange.endDate)) {
|
|
26866
|
+
dateRange.endDate = dateOfEnd;
|
|
26867
|
+
}
|
|
26868
|
+
return dateRange;
|
|
26869
|
+
}, { startDate: undefined, endDate: undefined });
|
|
26870
|
+
const startDate = dateRange.startDate && extractDate(dateRange.startDate.toISOString());
|
|
26871
|
+
const endDate = dateRange.endDate && extractDate(dateRange.endDate.toISOString());
|
|
26872
|
+
if (!startDate || !endDate)
|
|
26873
|
+
return { error: MISSING_DATE };
|
|
26874
|
+
return { startDate, endDate };
|
|
26875
|
+
}
|
|
26876
|
+
|
|
26877
|
+
function getTournamentPersons({ tournamentRecord, participantFilters }) {
|
|
26878
|
+
if (!tournamentRecord)
|
|
26879
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
26880
|
+
let tournamentParticipants = tournamentRecord.participants || [];
|
|
26881
|
+
if (participantFilters)
|
|
26882
|
+
tournamentParticipants = filterParticipants({
|
|
26883
|
+
participants: tournamentParticipants,
|
|
26884
|
+
participantFilters,
|
|
26885
|
+
tournamentRecord,
|
|
26886
|
+
});
|
|
26887
|
+
const tournamentPersons = {};
|
|
26888
|
+
const extractPerson = (participant) => {
|
|
26889
|
+
if (participant.person) {
|
|
26890
|
+
const { personId } = participant.person;
|
|
26891
|
+
if (tournamentPersons[personId]) {
|
|
26892
|
+
tournamentPersons[personId].participantIds.push(participant.participantId);
|
|
26893
|
+
}
|
|
26894
|
+
else {
|
|
26895
|
+
tournamentPersons[personId] = {
|
|
26896
|
+
...participant.person,
|
|
26897
|
+
participantIds: [participant.participantId],
|
|
26898
|
+
};
|
|
26899
|
+
}
|
|
26900
|
+
}
|
|
26901
|
+
};
|
|
26902
|
+
tournamentParticipants.forEach((participant) => {
|
|
26903
|
+
if (participant.person)
|
|
26904
|
+
extractPerson(participant);
|
|
26905
|
+
});
|
|
26906
|
+
return { tournamentPersons: Object.values(tournamentPersons) };
|
|
26907
|
+
}
|
|
26908
|
+
|
|
26909
|
+
function checkIsDual(tournamentRecord) {
|
|
26910
|
+
const teamParticipants = tournamentRecord.participants?.filter(({ participantType }) => participantType === TEAM);
|
|
26911
|
+
const twoTeams = teamParticipants?.length === 2;
|
|
26912
|
+
const event = tournamentRecord.events?.length === 1 && tournamentRecord.events[0];
|
|
26913
|
+
const drawDefinition = event?.drawDefinitions?.length === 1 && event.drawDefinitions[0];
|
|
26914
|
+
const structure = drawDefinition?.structures?.length === 1 && drawDefinition.structures[0];
|
|
26915
|
+
const twoDrawPositions = structure?.positionAssignments?.length === 2;
|
|
26916
|
+
return !!(event.tieFormat && twoTeams && twoDrawPositions);
|
|
26917
|
+
}
|
|
26918
|
+
|
|
26919
|
+
function analyzeTournament({ tournamentRecord }) {
|
|
26920
|
+
if (!tournamentRecord)
|
|
26921
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
26922
|
+
const { drawsAnalysis } = analyzeDraws({ tournamentRecord });
|
|
26923
|
+
const analysis = {
|
|
26924
|
+
isDual: checkIsDual(tournamentRecord),
|
|
26925
|
+
drawsAnalysis,
|
|
26926
|
+
};
|
|
26927
|
+
return { ...SUCCESS, analysis };
|
|
26928
|
+
}
|
|
26929
|
+
|
|
26930
|
+
var query$9 = {
|
|
26931
|
+
__proto__: null,
|
|
26932
|
+
analyzeDraws: analyzeDraws,
|
|
26933
|
+
analyzeTournament: analyzeTournament,
|
|
26934
|
+
getAllowedDrawTypes: getAllowedDrawTypes,
|
|
26935
|
+
getAllowedMatchUpFormats: getAllowedMatchUpFormats,
|
|
26936
|
+
getAppliedPolicies: getAppliedPolicies,
|
|
26937
|
+
getCompetitionDateRange: getCompetitionDateRange,
|
|
26938
|
+
getCompetitionPenalties: getCompetitionPenalties,
|
|
26939
|
+
getPolicyDefinitions: getPolicyDefinitions,
|
|
26940
|
+
getTournamentInfo: getTournamentInfo,
|
|
26941
|
+
getTournamentPenalties: getTournamentPenalties,
|
|
26942
|
+
getTournamentPersons: getTournamentPersons,
|
|
26943
|
+
getTournamentStructures: getTournamentStructures,
|
|
26944
|
+
getTournamentTimeItem: getTournamentTimeItem
|
|
26945
|
+
};
|
|
26946
|
+
|
|
26947
|
+
function getTieFormatDesc(tieFormat) {
|
|
26948
|
+
if (!tieFormat)
|
|
26949
|
+
return {};
|
|
26950
|
+
const matchUpFormats = [];
|
|
26951
|
+
const tieFormatName = tieFormat.tieFormatName;
|
|
26952
|
+
const tieFormatDesc = tieFormat.collectionDefinitions
|
|
26953
|
+
?.map((def) => {
|
|
26954
|
+
const { matchUpType, matchUpFormat, matchUpCount, category, gender } = def;
|
|
26955
|
+
if (!matchUpFormats.includes(matchUpFormat))
|
|
26956
|
+
matchUpFormats.push(matchUpFormat);
|
|
26957
|
+
const ageCategoryCode = category?.ageCategoryCode;
|
|
26958
|
+
const matchUpTypeCode = matchUpType === DOUBLES_MATCHUP ? 'D' : 'S';
|
|
26959
|
+
return [matchUpCount, matchUpTypeCode, ageCategoryCode, matchUpFormat, gender].join(';');
|
|
26960
|
+
})
|
|
26961
|
+
.join('|');
|
|
26962
|
+
return {
|
|
26963
|
+
tieFormatName: (tieFormat && tieFormatName) || 'UNNAMED',
|
|
26964
|
+
matchUpFormats,
|
|
26965
|
+
tieFormatDesc,
|
|
26966
|
+
};
|
|
26967
|
+
}
|
|
26968
|
+
|
|
26969
|
+
function compareTieFormats({ considerations = {}, descendant, ancestor }) {
|
|
26970
|
+
const descendantDifferences = {};
|
|
26971
|
+
const ancestorDifferences = {};
|
|
26972
|
+
const { matchUpFormats: descendantMatchUpFormats, tieFormatDesc: descendantDesc } = getTieFormatDesc(descendant);
|
|
26973
|
+
const { matchUpFormats: ancestorMatchUpFormats, tieFormatDesc: ancestorDesc } = getTieFormatDesc(ancestor);
|
|
26974
|
+
const matchUpFormatDifferences = unique((descendantMatchUpFormats ?? [])
|
|
26975
|
+
.filter((format) => !(ancestorMatchUpFormats ?? []).includes(format))
|
|
26976
|
+
.concat((ancestorMatchUpFormats ?? []).filter((format) => !(descendantMatchUpFormats ?? []).includes(format))));
|
|
26977
|
+
const nameDifference = !!(considerations?.collectionName &&
|
|
26978
|
+
descendant.collectionDefinitions.map(({ collectionName }) => collectionName).join('|') !==
|
|
26979
|
+
ancestor.collectionDefinitions.map(({ collectionName }) => collectionName).join('|'));
|
|
26980
|
+
const orderDifference = !!(considerations?.collectionOrder &&
|
|
26981
|
+
descendant.collectionDefinitions.map(({ collectionOrder }) => collectionOrder).join('|') !==
|
|
26982
|
+
ancestor.collectionDefinitions.map(({ collectionOrder }) => collectionOrder).join('|'));
|
|
26983
|
+
const descendantCollectionDefinitions = Object.assign({}, ...(descendant?.collectionDefinitions || []).map((collectionDefinition) => ({
|
|
26984
|
+
[collectionDefinition.collectionId]: collectionDefinition,
|
|
26985
|
+
})));
|
|
26986
|
+
const ancestorCollectionDefinitions = Object.assign({}, ...(ancestor?.collectionDefinitions || []).map((collectionDefinition) => ({
|
|
26987
|
+
[collectionDefinition.collectionId]: collectionDefinition,
|
|
26988
|
+
})));
|
|
26989
|
+
descendantDifferences.collectionIds = difference(Object.keys(descendantCollectionDefinitions), Object.keys(ancestorCollectionDefinitions));
|
|
26990
|
+
ancestorDifferences.collectionIds = difference(Object.keys(ancestorCollectionDefinitions), Object.keys(descendantCollectionDefinitions));
|
|
26991
|
+
descendantDifferences.collectionsValue = getCollectionsValue(descendantCollectionDefinitions);
|
|
26992
|
+
ancestorDifferences.collectionsValue = getCollectionsValue(ancestorCollectionDefinitions);
|
|
26993
|
+
descendantDifferences.groupsCount =
|
|
26994
|
+
ancestor?.collectionGroups?.length ?? (0 - (descendant?.collectionGroups?.length ?? 0) || 0);
|
|
26995
|
+
ancestorDifferences.groupsCount = descendantDifferences.groupsCount ? -1 * descendantDifferences.groupsCount : 0;
|
|
26996
|
+
const valueDifference = descendantDifferences.collectionsValue.totalValue - ancestorDifferences.collectionsValue.totalValue;
|
|
26997
|
+
const matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps - ancestorDifferences.collectionsValue.totalMatchUps;
|
|
26998
|
+
const assignmentValuesCountDifference = ancestorDifferences.collectionsValue.assignmentValues.length !==
|
|
26999
|
+
descendantDifferences.collectionsValue.assignmentValues.length;
|
|
27000
|
+
const assignmentValuesDifference = ancestorDifferences.collectionsValue.assignmentValues.some((assignment, i) => {
|
|
27001
|
+
const comparisonAssignment = descendantDifferences.collectionsValue.assignmentValues[i];
|
|
27002
|
+
if (!comparisonAssignment)
|
|
27003
|
+
return true;
|
|
27004
|
+
if (assignment.valueKey !== comparisonAssignment.valueKey)
|
|
27005
|
+
return true;
|
|
27006
|
+
if (assignment.value !== comparisonAssignment.value)
|
|
27007
|
+
return true;
|
|
27008
|
+
if (Array.isArray(assignment.value)) {
|
|
27009
|
+
return assignment.value.every((value, i) => comparisonAssignment.value[i] === value);
|
|
27010
|
+
}
|
|
27011
|
+
return false;
|
|
27012
|
+
});
|
|
27013
|
+
const different = nameDifference ||
|
|
27014
|
+
orderDifference ||
|
|
27015
|
+
ancestorDesc !== descendantDesc ||
|
|
27016
|
+
assignmentValuesCountDifference ||
|
|
27017
|
+
assignmentValuesDifference ||
|
|
27018
|
+
valueDifference !== 0;
|
|
27019
|
+
const invalidValues = [
|
|
27020
|
+
...ancestorDifferences.collectionsValue.invalidValues,
|
|
27021
|
+
...descendantDifferences.collectionsValue.invalidValues,
|
|
27022
|
+
];
|
|
27023
|
+
const invalid = invalidValues.length && invalidValues;
|
|
27024
|
+
return {
|
|
27025
|
+
matchUpFormatDifferences,
|
|
27026
|
+
matchUpCountDifference,
|
|
27027
|
+
descendantDifferences,
|
|
27028
|
+
ancestorDifferences,
|
|
27029
|
+
orderDifference,
|
|
27030
|
+
valueDifference,
|
|
27031
|
+
nameDifference,
|
|
27032
|
+
descendantDesc,
|
|
27033
|
+
ancestorDesc,
|
|
27034
|
+
...SUCCESS,
|
|
27035
|
+
different,
|
|
27036
|
+
invalid,
|
|
27037
|
+
};
|
|
27038
|
+
}
|
|
27039
|
+
function getCollectionsValue(definitions) {
|
|
27040
|
+
const invalidValues = [];
|
|
27041
|
+
const assignmentValues = [];
|
|
27042
|
+
let totalMatchUps = 0;
|
|
27043
|
+
const collectionIds = Object.keys(definitions).sort(stringSort);
|
|
27044
|
+
const totalValue = collectionIds.reduce((total, collectionId) => {
|
|
27045
|
+
const collectionDefinition = definitions[collectionId];
|
|
27046
|
+
const { collectionValueProfiles, collectionValue, matchUpCount, matchUpValue, scoreValue, setValue } = collectionDefinition;
|
|
27047
|
+
const valueAssignments = {
|
|
27048
|
+
collectionValueProfiles,
|
|
27049
|
+
collectionValue,
|
|
27050
|
+
matchUpValue,
|
|
27051
|
+
scoreValue,
|
|
27052
|
+
setValue,
|
|
27053
|
+
};
|
|
27054
|
+
const valueKeys = Object.keys(valueAssignments).filter((key) => ![undefined, null].includes(valueAssignments[key]));
|
|
27055
|
+
if (valueKeys.length !== 1) {
|
|
27056
|
+
invalidValues.push({ collectionId });
|
|
27057
|
+
}
|
|
27058
|
+
const valueKey = valueKeys[0];
|
|
27059
|
+
if (valueKey) {
|
|
27060
|
+
const value = valueKey === 'collectionValueProfiles' ? Object.values(collectionValueProfiles) : valueAssignments[valueKey];
|
|
27061
|
+
assignmentValues.push({ valueKey, value });
|
|
27062
|
+
}
|
|
27063
|
+
totalMatchUps += matchUpCount;
|
|
27064
|
+
if (collectionValueProfiles)
|
|
27065
|
+
return total + collectionValueProfiles.reduce((total, profile) => total + profile.value, 0);
|
|
27066
|
+
if (matchUpCount) {
|
|
27067
|
+
if (isConvertableInteger(matchUpValue))
|
|
27068
|
+
return total + matchUpValue * matchUpCount;
|
|
27069
|
+
if (isConvertableInteger(scoreValue))
|
|
27070
|
+
return total + scoreValue * matchUpCount;
|
|
27071
|
+
if (isConvertableInteger(setValue))
|
|
27072
|
+
return total + setValue * matchUpCount;
|
|
27073
|
+
return total + collectionValue;
|
|
27074
|
+
}
|
|
27075
|
+
return total;
|
|
27076
|
+
}, 0);
|
|
27077
|
+
return { totalValue, totalMatchUps, invalidValues, assignmentValues };
|
|
27078
|
+
}
|
|
27079
|
+
|
|
27080
|
+
function publicFindMatchUp(params) {
|
|
27081
|
+
Object.assign(params, { inContext: true });
|
|
27082
|
+
const { matchUp, error } = findMatchUp(params);
|
|
27083
|
+
return { matchUp: makeDeepCopy(matchUp, true, true), error };
|
|
27084
|
+
}
|
|
27085
|
+
function findMatchUp({ participantsProfile, afterRecoveryTimes, tournamentRecord, contextContent, contextProfile, drawDefinition, nextMatchUps, matchUpId, inContext, eventId, drawId, event, }) {
|
|
27086
|
+
if (!tournamentRecord)
|
|
27087
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
27088
|
+
if (typeof matchUpId !== 'string')
|
|
27089
|
+
return { error: MISSING_MATCHUP_ID };
|
|
27090
|
+
if (!drawDefinition || !event) {
|
|
27091
|
+
const matchUps = allTournamentMatchUps({ tournamentRecord, nextMatchUps }).matchUps ?? [];
|
|
27092
|
+
const inContextMatchUp = matchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
|
|
27093
|
+
if (!inContextMatchUp)
|
|
27094
|
+
return { error: MATCHUP_NOT_FOUND };
|
|
27095
|
+
({ eventId, drawId } = inContextMatchUp);
|
|
27096
|
+
({ event, drawDefinition } = findEvent({
|
|
27097
|
+
tournamentRecord,
|
|
27098
|
+
eventId,
|
|
27099
|
+
drawId,
|
|
27100
|
+
}));
|
|
27101
|
+
}
|
|
27102
|
+
if (!drawDefinition)
|
|
27103
|
+
return { error: DRAW_DEFINITION_NOT_FOUND };
|
|
27104
|
+
if (contextProfile && !contextContent)
|
|
27105
|
+
contextContent = getContextContent({ tournamentRecord, contextProfile });
|
|
27106
|
+
const additionalContext = {
|
|
27107
|
+
surfaceCategory: event?.surfaceCategory ?? tournamentRecord.surfaceCategory,
|
|
27108
|
+
indoorOutDoor: event?.indoorOutdoor ?? tournamentRecord.indoorOutdoor,
|
|
27109
|
+
endDate: event?.endDate ?? tournamentRecord.endDate,
|
|
27110
|
+
tournamentId: tournamentRecord.tournamentId,
|
|
27111
|
+
eventId: eventId ?? event?.eventId,
|
|
27112
|
+
drawId,
|
|
27113
|
+
};
|
|
27114
|
+
const { participants: tournamentParticipants = [] } = hydrateParticipants({
|
|
27115
|
+
participantsProfile,
|
|
27116
|
+
tournamentRecord,
|
|
27117
|
+
contextProfile,
|
|
27118
|
+
inContext,
|
|
27119
|
+
});
|
|
27120
|
+
if (nextMatchUps) {
|
|
27121
|
+
const matchUps = allDrawMatchUps({
|
|
27122
|
+
context: inContext ? additionalContext : undefined,
|
|
27123
|
+
participants: tournamentParticipants,
|
|
27124
|
+
afterRecoveryTimes,
|
|
27125
|
+
contextContent,
|
|
27126
|
+
contextProfile,
|
|
27127
|
+
drawDefinition,
|
|
27128
|
+
nextMatchUps,
|
|
27129
|
+
inContext,
|
|
27130
|
+
event,
|
|
27131
|
+
}).matchUps ?? [];
|
|
27132
|
+
const inContextMatchUp = matchUps.find((matchUp) => matchUp.matchUpId === matchUpId);
|
|
27133
|
+
if (!inContextMatchUp)
|
|
27134
|
+
return { error: MATCHUP_NOT_FOUND };
|
|
27135
|
+
const structure = drawDefinition?.structures?.find((structure) => structure.structureId === inContextMatchUp.structureId);
|
|
27136
|
+
return { drawDefinition, structure, matchUp: inContextMatchUp };
|
|
27137
|
+
}
|
|
27138
|
+
else {
|
|
27139
|
+
const { matchUp, structure } = findDrawMatchUp({
|
|
27140
|
+
context: inContext ? additionalContext : undefined,
|
|
27141
|
+
tournamentParticipants,
|
|
27142
|
+
afterRecoveryTimes,
|
|
27143
|
+
contextContent,
|
|
27144
|
+
drawDefinition,
|
|
27145
|
+
contextProfile,
|
|
27146
|
+
matchUpId,
|
|
27147
|
+
inContext,
|
|
27148
|
+
event,
|
|
27149
|
+
});
|
|
27150
|
+
return { matchUp, structure, drawDefinition };
|
|
27151
|
+
}
|
|
27152
|
+
}
|
|
27153
|
+
|
|
27154
|
+
function getTieFormat$1({ tournamentRecord, drawDefinition, structureId, matchUpId, structure, eventId, drawId, event, }) {
|
|
27155
|
+
if (!tournamentRecord)
|
|
27156
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
27157
|
+
if (!drawId && !event && !structureId && !matchUpId)
|
|
27158
|
+
return decorateResult({
|
|
27159
|
+
result: { error: MISSING_VALUE },
|
|
27160
|
+
stack: 'getTieFormat',
|
|
27161
|
+
});
|
|
27162
|
+
if (eventId && !event) {
|
|
27163
|
+
event = tournamentRecord.events?.find((event) => event.eventId === eventId);
|
|
27164
|
+
}
|
|
27165
|
+
const matchUpResult = publicFindMatchUp({
|
|
27166
|
+
tournamentRecord,
|
|
27167
|
+
drawDefinition,
|
|
27168
|
+
matchUpId,
|
|
27169
|
+
drawId,
|
|
27170
|
+
event,
|
|
27171
|
+
});
|
|
27172
|
+
if (matchUpId && matchUpResult?.error) {
|
|
27173
|
+
return matchUpResult;
|
|
27174
|
+
}
|
|
27175
|
+
else if (!drawDefinition && matchUpResult?.drawDefinition) {
|
|
27176
|
+
drawDefinition = matchUpResult?.drawDefinition;
|
|
27177
|
+
}
|
|
27178
|
+
structure = structure ?? matchUpResult?.structure;
|
|
27179
|
+
if (!structure && structureId && !matchUpId) {
|
|
27180
|
+
if (!drawDefinition)
|
|
27181
|
+
return { error: MISSING_DRAW_ID };
|
|
27182
|
+
const structureResult = findStructure({ drawDefinition, structureId });
|
|
27183
|
+
if (structureResult.error)
|
|
27184
|
+
return structureResult;
|
|
27185
|
+
structure = structureResult.structure;
|
|
27186
|
+
}
|
|
27187
|
+
const structureDefaultTieFormat = (structure?.tieFormat || structure?.tieFormatId) &&
|
|
27188
|
+
resolveTieFormat({ structure, drawDefinition, event })?.tieFormat;
|
|
27189
|
+
const drawDefaultTieFormat = (drawDefinition?.tieFormat || drawDefinition?.tieFormatId) &&
|
|
27190
|
+
resolveTieFormat({
|
|
27191
|
+
drawDefinition,
|
|
27192
|
+
event,
|
|
27193
|
+
})?.tieFormat;
|
|
27194
|
+
const eventDefaultTieFormat = resolveTieFormat({ event })?.tieFormat;
|
|
27195
|
+
const tieFormat = resolveTieFormat({
|
|
27196
|
+
matchUp: matchUpResult?.matchUp,
|
|
27197
|
+
drawDefinition,
|
|
27198
|
+
structure,
|
|
27199
|
+
event,
|
|
27200
|
+
})?.tieFormat;
|
|
27201
|
+
return {
|
|
27202
|
+
...SUCCESS,
|
|
27203
|
+
matchUp: matchUpResult?.matchUp,
|
|
27204
|
+
structureDefaultTieFormat: copyTieFormat(structureDefaultTieFormat),
|
|
27205
|
+
eventDefaultTieFormat: copyTieFormat(eventDefaultTieFormat),
|
|
27206
|
+
drawDefaultTieFormat: copyTieFormat(drawDefaultTieFormat),
|
|
27207
|
+
tieFormat: copyTieFormat(tieFormat),
|
|
27208
|
+
structure,
|
|
27209
|
+
};
|
|
27210
|
+
}
|
|
27211
|
+
|
|
27212
|
+
var query$8 = {
|
|
27213
|
+
__proto__: null,
|
|
27214
|
+
compareTieFormats: compareTieFormats,
|
|
27215
|
+
getTieFormat: getTieFormat$1,
|
|
27216
|
+
tieFormatGenderValidityCheck: tieFormatGenderValidityCheck,
|
|
27217
|
+
validateCollectionDefinition: validateCollectionDefinition
|
|
27218
|
+
};
|
|
27219
|
+
|
|
27220
|
+
function bulkUpdatePublishedEventIds({ tournamentRecord, outcomes }) {
|
|
27221
|
+
if (!tournamentRecord)
|
|
27222
|
+
return { error: MISSING_TOURNAMENT_RECORD };
|
|
27223
|
+
if (!outcomes?.length)
|
|
27224
|
+
return { error: MISSING_VALUE, info: 'Missing outcomes' };
|
|
27225
|
+
const eventIdsMap = outcomes.reduce((eventIdsMap, outcome) => {
|
|
27226
|
+
const { drawId, eventId } = outcome;
|
|
27227
|
+
if (eventId && drawId) {
|
|
27228
|
+
if (!eventIdsMap[eventId]) {
|
|
27229
|
+
eventIdsMap[eventId] = [drawId];
|
|
27230
|
+
}
|
|
27231
|
+
else if (!eventIdsMap[eventId].includes(drawId)) {
|
|
27232
|
+
eventIdsMap[eventId].push(drawId);
|
|
27233
|
+
}
|
|
27234
|
+
}
|
|
27235
|
+
return eventIdsMap;
|
|
27236
|
+
}, {});
|
|
27237
|
+
const relevantEventsIds = Object.keys(eventIdsMap);
|
|
27238
|
+
const relevantEvents = tournamentRecord.events?.filter((event) => relevantEventsIds.includes(event.eventId));
|
|
27239
|
+
const publishedEventIds = relevantEvents
|
|
27240
|
+
.filter((event) => {
|
|
27241
|
+
const pubStatus = getEventPublishStatus({ event });
|
|
27242
|
+
const { drawDetails, drawIds } = pubStatus ?? {};
|
|
27243
|
+
const { eventId } = event;
|
|
27244
|
+
const publishedDrawIds = eventIdsMap[eventId].filter((drawId) => {
|
|
27245
|
+
const keyedDrawIds = drawDetails
|
|
27246
|
+
? Object.keys(pubStatus.drawDetails).filter((drawId) => getDrawPublishStatus({ drawId, drawDetails }))
|
|
27247
|
+
: [];
|
|
27248
|
+
return drawIds?.includes(drawId) || keyedDrawIds.includes(drawId);
|
|
27249
|
+
});
|
|
27250
|
+
return publishedDrawIds.length;
|
|
27251
|
+
})
|
|
27252
|
+
.map((event) => event.eventId);
|
|
27253
|
+
return { publishedEventIds, eventIdPublishedDrawIdsMap: eventIdsMap };
|
|
27254
|
+
}
|
|
27255
|
+
|
|
27256
|
+
function getDisabledStatus({ dates = [], extension }) {
|
|
27257
|
+
if (!extension)
|
|
27258
|
+
return false;
|
|
27259
|
+
if (typeof extension.value === 'boolean' && extension.value)
|
|
27260
|
+
return true;
|
|
27261
|
+
if (!dates.length)
|
|
27262
|
+
return false;
|
|
27263
|
+
const disabledDates = isObject(extension.value) ? extension.value?.dates : undefined;
|
|
27264
|
+
if (Array.isArray(disabledDates)) {
|
|
27265
|
+
if (!disabledDates?.length)
|
|
27266
|
+
return false;
|
|
27267
|
+
const datesToConsider = disabledDates.filter((date) => !dates.length || dates.includes(date));
|
|
27268
|
+
return !!datesToConsider.length;
|
|
27269
|
+
}
|
|
27270
|
+
return undefined;
|
|
27271
|
+
}
|
|
27272
|
+
|
|
27273
|
+
function getInContextCourt({ convertExtensions, ignoreDisabled, venue, court }) {
|
|
27274
|
+
const inContextCourt = {
|
|
27275
|
+
...makeDeepCopy(court, convertExtensions, true),
|
|
27276
|
+
venueId: venue.venueId,
|
|
27277
|
+
};
|
|
27278
|
+
const { extension } = findExtension({
|
|
27279
|
+
name: DISABLED,
|
|
27280
|
+
element: court,
|
|
27281
|
+
});
|
|
27282
|
+
if (ignoreDisabled && extension) {
|
|
27283
|
+
const disabledDates = isObject(extension.value) ? extension.value?.dates : undefined;
|
|
27284
|
+
const dateAvailability = extension?.value === true
|
|
27285
|
+
? []
|
|
27286
|
+
: inContextCourt.dateAvailability
|
|
27287
|
+
.map((availability) => {
|
|
27288
|
+
const date = availability.date;
|
|
27289
|
+
if (!date || disabledDates.includes(date))
|
|
27290
|
+
return;
|
|
27291
|
+
return availability;
|
|
27292
|
+
})
|
|
27293
|
+
.filter(Boolean);
|
|
27294
|
+
inContextCourt.dateAvailability = dateAvailability;
|
|
27295
|
+
}
|
|
27296
|
+
return { inContextCourt };
|
|
27297
|
+
}
|
|
27298
|
+
|
|
27299
|
+
function getVenuesAndCourts(params) {
|
|
27300
|
+
const { convertExtensions, ignoreDisabled, venueIds = [], dates, } = params;
|
|
27301
|
+
const tournamentRecords = params.tournamentRecords ||
|
|
27302
|
+
(params.tournamentRecord && {
|
|
27303
|
+
[params.tournamentRecord.tournamentId]: params.tournamentRecord,
|
|
27304
|
+
}) ||
|
|
27305
|
+
{};
|
|
27306
|
+
const uniqueVenueIds = [];
|
|
27307
|
+
const uniqueCourtIds = [];
|
|
27308
|
+
const courts = [];
|
|
27309
|
+
const venues = [];
|
|
27310
|
+
const tournamentIds = Object.keys(tournamentRecords).filter((id) => !params.tournamentId || id === params.tournamentId);
|
|
27311
|
+
tournamentIds.forEach((tournamentId) => {
|
|
26809
27312
|
const tournamentRecord = tournamentRecords[tournamentId];
|
|
26810
|
-
const
|
|
26811
|
-
|
|
26812
|
-
|
|
26813
|
-
|
|
26814
|
-
|
|
26815
|
-
|
|
26816
|
-
|
|
26817
|
-
|
|
27313
|
+
for (const venue of tournamentRecord.venues ?? []) {
|
|
27314
|
+
if (venueIds.length && !venueIds.includes(venue.venueId))
|
|
27315
|
+
continue;
|
|
27316
|
+
if (ignoreDisabled) {
|
|
27317
|
+
const { extension } = findExtension({
|
|
27318
|
+
name: DISABLED,
|
|
27319
|
+
element: venue,
|
|
27320
|
+
});
|
|
27321
|
+
if (extension?.value)
|
|
27322
|
+
continue;
|
|
27323
|
+
}
|
|
27324
|
+
if (!uniqueVenueIds.includes(venue.venueId)) {
|
|
27325
|
+
venues.push(makeDeepCopy(venue, convertExtensions, true));
|
|
27326
|
+
uniqueVenueIds.push(venue.venueId);
|
|
27327
|
+
}
|
|
27328
|
+
for (const court of venue.courts ?? []) {
|
|
27329
|
+
if (!uniqueCourtIds.includes(court.courtId)) {
|
|
27330
|
+
if (ignoreDisabled) {
|
|
27331
|
+
const { extension } = findExtension({
|
|
27332
|
+
name: DISABLED,
|
|
27333
|
+
element: court,
|
|
27334
|
+
});
|
|
27335
|
+
const isDisabled = getDisabledStatus({ extension, dates });
|
|
27336
|
+
if (isDisabled)
|
|
27337
|
+
continue;
|
|
27338
|
+
}
|
|
27339
|
+
const { inContextCourt } = getInContextCourt({
|
|
27340
|
+
convertExtensions,
|
|
27341
|
+
ignoreDisabled,
|
|
27342
|
+
venue,
|
|
27343
|
+
court,
|
|
27344
|
+
});
|
|
27345
|
+
courts.push(inContextCourt);
|
|
27346
|
+
uniqueCourtIds.push(court.courtId);
|
|
27347
|
+
}
|
|
27348
|
+
}
|
|
26818
27349
|
}
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
const startDate = dateRange.startDate && extractDate(dateRange.startDate.toISOString());
|
|
26822
|
-
const endDate = dateRange.endDate && extractDate(dateRange.endDate.toISOString());
|
|
26823
|
-
if (!startDate || !endDate)
|
|
26824
|
-
return { error: MISSING_DATE };
|
|
26825
|
-
return { startDate, endDate };
|
|
27350
|
+
});
|
|
27351
|
+
return { courts, venues, ...SUCCESS };
|
|
26826
27352
|
}
|
|
26827
|
-
|
|
26828
|
-
function getTournamentPersons({ tournamentRecord, participantFilters }) {
|
|
27353
|
+
function getTournamentVenuesAndCourts({ convertExtensions, tournamentRecord, ignoreDisabled, dates, }) {
|
|
26829
27354
|
if (!tournamentRecord)
|
|
26830
|
-
return { error:
|
|
26831
|
-
|
|
26832
|
-
|
|
26833
|
-
|
|
26834
|
-
|
|
26835
|
-
|
|
27355
|
+
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
27356
|
+
const venues = makeDeepCopy(tournamentRecord.venues ?? [], convertExtensions)
|
|
27357
|
+
.filter((venue) => {
|
|
27358
|
+
if (!ignoreDisabled)
|
|
27359
|
+
return venue;
|
|
27360
|
+
const { extension } = findExtension({
|
|
27361
|
+
name: DISABLED,
|
|
27362
|
+
element: venue,
|
|
27363
|
+
});
|
|
27364
|
+
return !extension?.value && venue;
|
|
27365
|
+
})
|
|
27366
|
+
.filter(Boolean);
|
|
27367
|
+
const courts = venues.reduce((courts, venue) => {
|
|
27368
|
+
const additionalCourts = (venue?.courts || [])
|
|
27369
|
+
.filter((court) => {
|
|
27370
|
+
if (!ignoreDisabled && !dates?.length)
|
|
27371
|
+
return court;
|
|
27372
|
+
const { extension } = findExtension({
|
|
27373
|
+
name: DISABLED,
|
|
27374
|
+
element: court,
|
|
27375
|
+
});
|
|
27376
|
+
return getDisabledStatus({ extension, dates });
|
|
27377
|
+
})
|
|
27378
|
+
.filter(Boolean)
|
|
27379
|
+
.map((court) => {
|
|
27380
|
+
const { inContextCourt } = getInContextCourt({
|
|
27381
|
+
convertExtensions,
|
|
27382
|
+
ignoreDisabled,
|
|
27383
|
+
venue,
|
|
27384
|
+
court,
|
|
27385
|
+
});
|
|
27386
|
+
return inContextCourt;
|
|
27387
|
+
});
|
|
27388
|
+
return additionalCourts.length ? courts.concat(additionalCourts) : courts;
|
|
27389
|
+
}, []);
|
|
27390
|
+
return { venues, courts };
|
|
27391
|
+
}
|
|
27392
|
+
function getCompetitionVenues({ tournamentRecords, requireCourts, dates }) {
|
|
27393
|
+
if (typeof tournamentRecords !== 'object' || !Object.keys(tournamentRecords).length)
|
|
27394
|
+
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
27395
|
+
const tournamentIds = Object.keys(tournamentRecords);
|
|
27396
|
+
return tournamentIds.reduce((accumulator, tournamentId) => {
|
|
27397
|
+
const tournamentRecord = tournamentRecords[tournamentId];
|
|
27398
|
+
const { venues } = getTournamentVenuesAndCourts({
|
|
26836
27399
|
tournamentRecord,
|
|
27400
|
+
dates,
|
|
26837
27401
|
});
|
|
26838
|
-
|
|
26839
|
-
|
|
26840
|
-
|
|
26841
|
-
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
}
|
|
26845
|
-
else {
|
|
26846
|
-
tournamentPersons[personId] = {
|
|
26847
|
-
...participant.person,
|
|
26848
|
-
participantIds: [participant.participantId],
|
|
26849
|
-
};
|
|
27402
|
+
venues?.forEach((venue) => {
|
|
27403
|
+
const { venueId, courts } = venue;
|
|
27404
|
+
const includeVenue = !requireCourts || courts?.length;
|
|
27405
|
+
if (includeVenue && !accumulator.venueIds.includes(venueId)) {
|
|
27406
|
+
accumulator.venues.push(venue);
|
|
27407
|
+
accumulator.venueIds.push(venueId);
|
|
26850
27408
|
}
|
|
26851
|
-
}
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
if (participant.person)
|
|
26855
|
-
extractPerson(participant);
|
|
26856
|
-
});
|
|
26857
|
-
return { tournamentPersons: Object.values(tournamentPersons) };
|
|
26858
|
-
}
|
|
26859
|
-
|
|
26860
|
-
function checkIsDual(tournamentRecord) {
|
|
26861
|
-
const teamParticipants = tournamentRecord.participants?.filter(({ participantType }) => participantType === TEAM);
|
|
26862
|
-
const twoTeams = teamParticipants?.length === 2;
|
|
26863
|
-
const event = tournamentRecord.events?.length === 1 && tournamentRecord.events[0];
|
|
26864
|
-
const drawDefinition = event?.drawDefinitions?.length === 1 && event.drawDefinitions[0];
|
|
26865
|
-
const structure = drawDefinition?.structures?.length === 1 && drawDefinition.structures[0];
|
|
26866
|
-
const twoDrawPositions = structure?.positionAssignments?.length === 2;
|
|
26867
|
-
return !!(event.tieFormat && twoTeams && twoDrawPositions);
|
|
27409
|
+
});
|
|
27410
|
+
return accumulator;
|
|
27411
|
+
}, { venues: [], venueIds: [] });
|
|
26868
27412
|
}
|
|
26869
27413
|
|
|
26870
|
-
function
|
|
27414
|
+
function getAllEventData({ tournamentRecord, policyDefinitions }) {
|
|
26871
27415
|
if (!tournamentRecord)
|
|
26872
27416
|
return { error: MISSING_TOURNAMENT_RECORD };
|
|
26873
|
-
const
|
|
26874
|
-
const
|
|
26875
|
-
|
|
26876
|
-
|
|
26877
|
-
|
|
26878
|
-
|
|
27417
|
+
const events = tournamentRecord.events || [];
|
|
27418
|
+
const tournamentParticipants = tournamentRecord?.participants || [];
|
|
27419
|
+
const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
|
|
27420
|
+
const { venues: venuesData } = getVenuesAndCourts({
|
|
27421
|
+
tournamentRecord,
|
|
27422
|
+
});
|
|
27423
|
+
const eventsData = events.map((event) => {
|
|
27424
|
+
const { eventId } = event;
|
|
27425
|
+
const eventInfo = extractEventInfo({ event }).eventInfo;
|
|
27426
|
+
const scheduleTiming = getScheduleTiming({
|
|
27427
|
+
tournamentRecord,
|
|
27428
|
+
event,
|
|
27429
|
+
}).scheduleTiming;
|
|
27430
|
+
const drawsData = (event.drawDefinitions || []).map((drawDefinition) => {
|
|
27431
|
+
const drawInfo = (({ drawId, drawName, matchUpFormat, updatedAt }) => ({
|
|
27432
|
+
matchUpFormat,
|
|
27433
|
+
updatedAt,
|
|
27434
|
+
drawName,
|
|
27435
|
+
drawId,
|
|
27436
|
+
}))(drawDefinition);
|
|
27437
|
+
const { abandonedMatchUps, completedMatchUps, upcomingMatchUps, pendingMatchUps } = getDrawMatchUps({
|
|
27438
|
+
requireParticipants: true,
|
|
27439
|
+
tournamentParticipants,
|
|
27440
|
+
context: { eventId },
|
|
27441
|
+
policyDefinitions,
|
|
27442
|
+
tournamentRecord,
|
|
27443
|
+
inContext: true,
|
|
27444
|
+
scheduleTiming,
|
|
27445
|
+
drawDefinition,
|
|
27446
|
+
event,
|
|
27447
|
+
});
|
|
27448
|
+
return {
|
|
27449
|
+
drawInfo,
|
|
27450
|
+
matchUps: {
|
|
27451
|
+
abandonedMatchUps,
|
|
27452
|
+
completedMatchUps,
|
|
27453
|
+
upcomingMatchUps,
|
|
27454
|
+
pendingMatchUps,
|
|
27455
|
+
},
|
|
27456
|
+
};
|
|
27457
|
+
});
|
|
27458
|
+
const publish = getEventPublishStatus({ event });
|
|
27459
|
+
Object.assign(eventInfo, {
|
|
27460
|
+
drawsData,
|
|
27461
|
+
publish,
|
|
27462
|
+
});
|
|
27463
|
+
return eventInfo;
|
|
27464
|
+
});
|
|
27465
|
+
const allEventData = { tournamentInfo, venuesData, eventsData };
|
|
27466
|
+
return { allEventData };
|
|
26879
27467
|
}
|
|
26880
27468
|
|
|
26881
|
-
|
|
26882
|
-
|
|
26883
|
-
|
|
26884
|
-
|
|
26885
|
-
|
|
26886
|
-
|
|
26887
|
-
|
|
26888
|
-
|
|
26889
|
-
getCompetitionPenalties: getCompetitionPenalties,
|
|
26890
|
-
getPolicyDefinitions: getPolicyDefinitions,
|
|
26891
|
-
getTournamentInfo: getTournamentInfo,
|
|
26892
|
-
getTournamentPenalties: getTournamentPenalties,
|
|
26893
|
-
getTournamentPersons: getTournamentPersons,
|
|
26894
|
-
getTournamentStructures: getTournamentStructures,
|
|
26895
|
-
getTournamentTimeItem: getTournamentTimeItem
|
|
26896
|
-
};
|
|
26897
|
-
|
|
26898
|
-
function getTieFormatDesc(tieFormat) {
|
|
26899
|
-
if (!tieFormat)
|
|
26900
|
-
return {};
|
|
26901
|
-
const matchUpFormats = [];
|
|
26902
|
-
const tieFormatName = tieFormat.tieFormatName;
|
|
26903
|
-
const tieFormatDesc = tieFormat.collectionDefinitions
|
|
26904
|
-
?.map((def) => {
|
|
26905
|
-
const { matchUpType, matchUpFormat, matchUpCount, category, gender } = def;
|
|
26906
|
-
if (!matchUpFormats.includes(matchUpFormat))
|
|
26907
|
-
matchUpFormats.push(matchUpFormat);
|
|
26908
|
-
const ageCategoryCode = category?.ageCategoryCode;
|
|
26909
|
-
const matchUpTypeCode = matchUpType === DOUBLES_MATCHUP ? 'D' : 'S';
|
|
26910
|
-
return [matchUpCount, matchUpTypeCode, ageCategoryCode, matchUpFormat, gender].join(';');
|
|
26911
|
-
})
|
|
26912
|
-
.join('|');
|
|
26913
|
-
return {
|
|
26914
|
-
tieFormatName: (tieFormat && tieFormatName) || 'UNNAMED',
|
|
26915
|
-
matchUpFormats,
|
|
26916
|
-
tieFormatDesc,
|
|
26917
|
-
};
|
|
27469
|
+
function getDrawIsPublished({ publishStatus, drawId }) {
|
|
27470
|
+
if (publishStatus?.drawDetails) {
|
|
27471
|
+
return publishStatus.drawDetails?.[drawId]?.publishingDetail?.published;
|
|
27472
|
+
}
|
|
27473
|
+
else if (publishStatus?.drawIds) {
|
|
27474
|
+
return publishStatus.drawIds.includes(drawId);
|
|
27475
|
+
}
|
|
27476
|
+
return true;
|
|
26918
27477
|
}
|
|
26919
27478
|
|
|
26920
|
-
function
|
|
26921
|
-
const
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
const {
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
26928
|
-
|
|
26929
|
-
|
|
26930
|
-
|
|
26931
|
-
|
|
26932
|
-
|
|
26933
|
-
|
|
26934
|
-
const descendantCollectionDefinitions = Object.assign({}, ...(descendant?.collectionDefinitions || []).map((collectionDefinition) => ({
|
|
26935
|
-
[collectionDefinition.collectionId]: collectionDefinition,
|
|
26936
|
-
})));
|
|
26937
|
-
const ancestorCollectionDefinitions = Object.assign({}, ...(ancestor?.collectionDefinitions || []).map((collectionDefinition) => ({
|
|
26938
|
-
[collectionDefinition.collectionId]: collectionDefinition,
|
|
26939
|
-
})));
|
|
26940
|
-
descendantDifferences.collectionIds = difference(Object.keys(descendantCollectionDefinitions), Object.keys(ancestorCollectionDefinitions));
|
|
26941
|
-
ancestorDifferences.collectionIds = difference(Object.keys(ancestorCollectionDefinitions), Object.keys(descendantCollectionDefinitions));
|
|
26942
|
-
descendantDifferences.collectionsValue = getCollectionsValue(descendantCollectionDefinitions);
|
|
26943
|
-
ancestorDifferences.collectionsValue = getCollectionsValue(ancestorCollectionDefinitions);
|
|
26944
|
-
descendantDifferences.groupsCount =
|
|
26945
|
-
ancestor?.collectionGroups?.length ?? (0 - (descendant?.collectionGroups?.length ?? 0) || 0);
|
|
26946
|
-
ancestorDifferences.groupsCount = descendantDifferences.groupsCount ? -1 * descendantDifferences.groupsCount : 0;
|
|
26947
|
-
const valueDifference = descendantDifferences.collectionsValue.totalValue - ancestorDifferences.collectionsValue.totalValue;
|
|
26948
|
-
const matchUpCountDifference = descendantDifferences.collectionsValue.totalMatchUps - ancestorDifferences.collectionsValue.totalMatchUps;
|
|
26949
|
-
const assignmentValuesCountDifference = ancestorDifferences.collectionsValue.assignmentValues.length !==
|
|
26950
|
-
descendantDifferences.collectionsValue.assignmentValues.length;
|
|
26951
|
-
const assignmentValuesDifference = ancestorDifferences.collectionsValue.assignmentValues.some((assignment, i) => {
|
|
26952
|
-
const comparisonAssignment = descendantDifferences.collectionsValue.assignmentValues[i];
|
|
26953
|
-
if (!comparisonAssignment)
|
|
26954
|
-
return true;
|
|
26955
|
-
if (assignment.valueKey !== comparisonAssignment.valueKey)
|
|
26956
|
-
return true;
|
|
26957
|
-
if (assignment.value !== comparisonAssignment.value)
|
|
26958
|
-
return true;
|
|
26959
|
-
if (Array.isArray(assignment.value)) {
|
|
26960
|
-
return assignment.value.every((value, i) => comparisonAssignment.value[i] === value);
|
|
26961
|
-
}
|
|
26962
|
-
return false;
|
|
27479
|
+
function getDrawData(params) {
|
|
27480
|
+
const { tournamentParticipants = [], includePositionAssignments, policyDefinitions, tournamentRecord, inContext = true, usePublishState, status = PUBLIC, drawDefinition, noDeepCopy, sortConfig, context, event, } = params;
|
|
27481
|
+
if (!drawDefinition)
|
|
27482
|
+
return { error: MISSING_DRAW_DEFINITION };
|
|
27483
|
+
const drawInfo = (({ matchUpFormat, updatedAt, drawType, drawName, drawId }) => ({
|
|
27484
|
+
matchUpFormat,
|
|
27485
|
+
updatedAt,
|
|
27486
|
+
drawName,
|
|
27487
|
+
drawType,
|
|
27488
|
+
drawId,
|
|
27489
|
+
}))(drawDefinition);
|
|
27490
|
+
let mainStageSeedAssignments, qualificationStageSeedAssignments;
|
|
27491
|
+
const { allStructuresLinked, sourceStructureIds, hasDrawFeedProfile, structureGroups } = getStructureGroups({
|
|
27492
|
+
drawDefinition,
|
|
26963
27493
|
});
|
|
26964
|
-
|
|
26965
|
-
|
|
26966
|
-
|
|
26967
|
-
|
|
26968
|
-
|
|
26969
|
-
|
|
26970
|
-
const
|
|
26971
|
-
|
|
26972
|
-
|
|
26973
|
-
|
|
26974
|
-
|
|
27494
|
+
if (!allStructuresLinked)
|
|
27495
|
+
return { error: UNLINKED_STRUCTURES };
|
|
27496
|
+
const publishStatus = params?.publishStatus ?? getEventPublishStatus({ event, status });
|
|
27497
|
+
const eventPublished = params.eventPublished ?? !!getPublishState({ event }).publishState?.status?.published;
|
|
27498
|
+
let drawActive = false;
|
|
27499
|
+
let participantPlacements = false;
|
|
27500
|
+
const groupedStructures = structureGroups.map((structureIds) => {
|
|
27501
|
+
const completedStructures = {};
|
|
27502
|
+
const structures = structureIds
|
|
27503
|
+
.map((structureId) => {
|
|
27504
|
+
const { structure } = findStructure({ drawDefinition, structureId });
|
|
27505
|
+
const { seedAssignments } = getStructureSeedAssignments({
|
|
27506
|
+
drawDefinition,
|
|
27507
|
+
structure,
|
|
27508
|
+
});
|
|
27509
|
+
if (structure?.stage === MAIN && structure.stageSequence === 1) {
|
|
27510
|
+
mainStageSeedAssignments = seedAssignments;
|
|
27511
|
+
}
|
|
27512
|
+
if (structure?.stage === QUALIFYING && structure.stageSequence === 1) {
|
|
27513
|
+
qualificationStageSeedAssignments = seedAssignments;
|
|
27514
|
+
}
|
|
27515
|
+
return structure;
|
|
27516
|
+
})
|
|
27517
|
+
.sort((a, b) => structureSort(a, b, sortConfig))
|
|
27518
|
+
.map((structure) => {
|
|
27519
|
+
if (!structure)
|
|
27520
|
+
return;
|
|
27521
|
+
const structureId = structure?.structureId;
|
|
27522
|
+
let seedAssignments = [];
|
|
27523
|
+
if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
|
|
27524
|
+
seedAssignments = mainStageSeedAssignments;
|
|
27525
|
+
}
|
|
27526
|
+
if (structure?.stage === QUALIFYING) {
|
|
27527
|
+
seedAssignments = qualificationStageSeedAssignments;
|
|
27528
|
+
}
|
|
27529
|
+
const { matchUps, roundMatchUps, roundProfile } = getAllStructureMatchUps({
|
|
27530
|
+
seedAssignments: !structure?.seedAssignments?.length ? seedAssignments : undefined,
|
|
27531
|
+
context: { drawId: drawInfo.drawId, ...context },
|
|
27532
|
+
tournamentParticipants,
|
|
27533
|
+
policyDefinitions,
|
|
27534
|
+
tournamentRecord,
|
|
27535
|
+
usePublishState,
|
|
27536
|
+
publishStatus,
|
|
27537
|
+
drawDefinition,
|
|
27538
|
+
inContext,
|
|
27539
|
+
structure,
|
|
27540
|
+
event,
|
|
27541
|
+
});
|
|
27542
|
+
const { positionAssignments } = getPositionAssignments$1({
|
|
27543
|
+
structure,
|
|
27544
|
+
});
|
|
27545
|
+
let participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
|
|
27546
|
+
const { drawPosition, participantId } = assignment;
|
|
27547
|
+
const { extension } = findExtension({
|
|
27548
|
+
element: assignment,
|
|
27549
|
+
name: TALLY,
|
|
27550
|
+
});
|
|
27551
|
+
participantPlacements = true;
|
|
27552
|
+
return {
|
|
27553
|
+
participantResult: extension?.value,
|
|
27554
|
+
participantId,
|
|
27555
|
+
drawPosition,
|
|
27556
|
+
};
|
|
27557
|
+
});
|
|
27558
|
+
if (!participantResults?.length && matchUps.length && params.allParticipantResults) {
|
|
27559
|
+
const { subOrderMap } = createSubOrderMap({ positionAssignments });
|
|
27560
|
+
const result = tallyParticipantResults({
|
|
27561
|
+
matchUpFormat: structure.matchUpFormat,
|
|
27562
|
+
policyDefinitions,
|
|
27563
|
+
subOrderMap,
|
|
27564
|
+
matchUps,
|
|
27565
|
+
});
|
|
27566
|
+
participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
|
|
27567
|
+
const { drawPosition, participantId } = assignment;
|
|
27568
|
+
participantPlacements = true;
|
|
27569
|
+
return {
|
|
27570
|
+
participantResult: participantId && result.participantResults[participantId],
|
|
27571
|
+
participantId,
|
|
27572
|
+
drawPosition,
|
|
27573
|
+
};
|
|
27574
|
+
});
|
|
27575
|
+
}
|
|
27576
|
+
const structureInfo = structure
|
|
27577
|
+
? (({ stageSequence, structureName, structureType, matchUpFormat, stage }) => ({
|
|
27578
|
+
stageSequence,
|
|
27579
|
+
structureName,
|
|
27580
|
+
structureType,
|
|
27581
|
+
matchUpFormat,
|
|
27582
|
+
stage,
|
|
27583
|
+
}))(structure)
|
|
27584
|
+
: {};
|
|
27585
|
+
structureInfo.sourceStructureIds = sourceStructureIds[structureId];
|
|
27586
|
+
structureInfo.hasDrawFeedProfile = hasDrawFeedProfile[structureId];
|
|
27587
|
+
structureInfo.positionAssignments = positionAssignments;
|
|
27588
|
+
structureInfo.structureActive = matchUps.reduce((active, matchUp) => {
|
|
27589
|
+
const activeMatchUpStatus = [
|
|
27590
|
+
COMPLETED$1,
|
|
27591
|
+
CANCELLED$1,
|
|
27592
|
+
DEFAULTED,
|
|
27593
|
+
RETIRED$1,
|
|
27594
|
+
WALKOVER$2,
|
|
27595
|
+
IN_PROGRESS$1,
|
|
27596
|
+
DOUBLE_DEFAULT,
|
|
27597
|
+
DOUBLE_WALKOVER,
|
|
27598
|
+
].includes(matchUp.matchUpStatus);
|
|
27599
|
+
return active || activeMatchUpStatus || !!matchUp.winningSide || !!matchUp.score?.scoreStringSide1;
|
|
27600
|
+
}, false);
|
|
27601
|
+
const structureCompleted = matchUps.reduce((completed, matchUp) => {
|
|
27602
|
+
return completed && [BYE, COMPLETED$1, RETIRED$1, WALKOVER$2, DEFAULTED, ABANDONED$1].includes(matchUp.matchUpStatus);
|
|
27603
|
+
}, !!matchUps.length);
|
|
27604
|
+
structureInfo.structureCompleted = structureCompleted;
|
|
27605
|
+
completedStructures[structureId] = structureCompleted;
|
|
27606
|
+
if (structureInfo.structureActive)
|
|
27607
|
+
drawActive = true;
|
|
27608
|
+
return {
|
|
27609
|
+
...structureInfo,
|
|
27610
|
+
participantResults,
|
|
27611
|
+
seedAssignments,
|
|
27612
|
+
roundMatchUps,
|
|
27613
|
+
roundProfile,
|
|
27614
|
+
structureId,
|
|
27615
|
+
};
|
|
27616
|
+
});
|
|
27617
|
+
structures.forEach((structure) => {
|
|
27618
|
+
if (!includePositionAssignments)
|
|
27619
|
+
delete structure.positionAssignments;
|
|
27620
|
+
structure.sourceStructuresComplete = structure.sourceStructureIds?.every((id) => completedStructures[id]);
|
|
27621
|
+
});
|
|
27622
|
+
return structures;
|
|
27623
|
+
});
|
|
27624
|
+
const structures = groupedStructures.flat();
|
|
27625
|
+
drawInfo.drawActive = drawActive;
|
|
27626
|
+
drawInfo.participantPlacements = participantPlacements;
|
|
27627
|
+
drawInfo.drawGenerated = structures?.reduce((generated, structure) => {
|
|
27628
|
+
return generated || !!structure?.roundMatchUps;
|
|
27629
|
+
}, false);
|
|
27630
|
+
drawInfo.drawCompleted = structures?.reduce((completed, structure) => completed && structure.structureCompleted, true);
|
|
27631
|
+
drawInfo.drawPublished = usePublishState
|
|
27632
|
+
? eventPublished && getDrawIsPublished({ publishStatus, drawId: drawInfo.drawId })
|
|
27633
|
+
: undefined;
|
|
26975
27634
|
return {
|
|
26976
|
-
|
|
26977
|
-
|
|
26978
|
-
|
|
26979
|
-
|
|
26980
|
-
|
|
26981
|
-
|
|
26982
|
-
|
|
26983
|
-
descendantDesc,
|
|
26984
|
-
ancestorDesc,
|
|
26985
|
-
...SUCCESS,
|
|
26986
|
-
different,
|
|
26987
|
-
invalid,
|
|
27635
|
+
structures: !usePublishState || drawInfo.drawPublished
|
|
27636
|
+
? noDeepCopy
|
|
27637
|
+
? structures
|
|
27638
|
+
: makeDeepCopy(structures, false, true)
|
|
27639
|
+
: undefined,
|
|
27640
|
+
drawInfo: noDeepCopy ? drawInfo : makeDeepCopy(drawInfo, false, true),
|
|
27641
|
+
...SUCCESS,
|
|
26988
27642
|
};
|
|
26989
27643
|
}
|
|
26990
|
-
function getCollectionsValue(definitions) {
|
|
26991
|
-
const invalidValues = [];
|
|
26992
|
-
const assignmentValues = [];
|
|
26993
|
-
let totalMatchUps = 0;
|
|
26994
|
-
const collectionIds = Object.keys(definitions).sort(stringSort);
|
|
26995
|
-
const totalValue = collectionIds.reduce((total, collectionId) => {
|
|
26996
|
-
const collectionDefinition = definitions[collectionId];
|
|
26997
|
-
const { collectionValueProfiles, collectionValue, matchUpCount, matchUpValue, scoreValue, setValue } = collectionDefinition;
|
|
26998
|
-
const valueAssignments = {
|
|
26999
|
-
collectionValueProfiles,
|
|
27000
|
-
collectionValue,
|
|
27001
|
-
matchUpValue,
|
|
27002
|
-
scoreValue,
|
|
27003
|
-
setValue,
|
|
27004
|
-
};
|
|
27005
|
-
const valueKeys = Object.keys(valueAssignments).filter((key) => ![undefined, null].includes(valueAssignments[key]));
|
|
27006
|
-
if (valueKeys.length !== 1) {
|
|
27007
|
-
invalidValues.push({ collectionId });
|
|
27008
|
-
}
|
|
27009
|
-
const valueKey = valueKeys[0];
|
|
27010
|
-
if (valueKey) {
|
|
27011
|
-
const value = valueKey === 'collectionValueProfiles' ? Object.values(collectionValueProfiles) : valueAssignments[valueKey];
|
|
27012
|
-
assignmentValues.push({ valueKey, value });
|
|
27013
|
-
}
|
|
27014
|
-
totalMatchUps += matchUpCount;
|
|
27015
|
-
if (collectionValueProfiles)
|
|
27016
|
-
return total + collectionValueProfiles.reduce((total, profile) => total + profile.value, 0);
|
|
27017
|
-
if (matchUpCount) {
|
|
27018
|
-
if (isConvertableInteger(matchUpValue))
|
|
27019
|
-
return total + matchUpValue * matchUpCount;
|
|
27020
|
-
if (isConvertableInteger(scoreValue))
|
|
27021
|
-
return total + scoreValue * matchUpCount;
|
|
27022
|
-
if (isConvertableInteger(setValue))
|
|
27023
|
-
return total + setValue * matchUpCount;
|
|
27024
|
-
return total + collectionValue;
|
|
27025
|
-
}
|
|
27026
|
-
return total;
|
|
27027
|
-
}, 0);
|
|
27028
|
-
return { totalValue, totalMatchUps, invalidValues, assignmentValues };
|
|
27029
|
-
}
|
|
27030
27644
|
|
|
27031
|
-
function
|
|
27032
|
-
|
|
27033
|
-
const
|
|
27034
|
-
|
|
27035
|
-
}
|
|
27036
|
-
|
|
27037
|
-
if (
|
|
27038
|
-
return
|
|
27039
|
-
|
|
27040
|
-
|
|
27041
|
-
|
|
27042
|
-
|
|
27043
|
-
|
|
27044
|
-
|
|
27045
|
-
|
|
27046
|
-
|
|
27047
|
-
|
|
27048
|
-
|
|
27049
|
-
|
|
27050
|
-
|
|
27051
|
-
|
|
27052
|
-
|
|
27053
|
-
|
|
27054
|
-
|
|
27055
|
-
|
|
27056
|
-
|
|
27057
|
-
const additionalContext = {
|
|
27058
|
-
surfaceCategory: event?.surfaceCategory ?? tournamentRecord.surfaceCategory,
|
|
27059
|
-
indoorOutDoor: event?.indoorOutdoor ?? tournamentRecord.indoorOutdoor,
|
|
27060
|
-
endDate: event?.endDate ?? tournamentRecord.endDate,
|
|
27061
|
-
tournamentId: tournamentRecord.tournamentId,
|
|
27062
|
-
eventId: eventId ?? event?.eventId,
|
|
27063
|
-
drawId,
|
|
27064
|
-
};
|
|
27065
|
-
const { participants: tournamentParticipants = [] } = hydrateParticipants({
|
|
27066
|
-
participantsProfile,
|
|
27645
|
+
function getEventData(params) {
|
|
27646
|
+
const { includePositionAssignments, participantsProfile, policyDefinitions, usePublishState, status = PUBLIC, sortConfig, } = params;
|
|
27647
|
+
const paramsCheck = checkRequiredParameters(params, [
|
|
27648
|
+
{ tournamentRecord: true },
|
|
27649
|
+
{ [ANY_OF]: { event: false, eventId: false } },
|
|
27650
|
+
]);
|
|
27651
|
+
if (paramsCheck.error)
|
|
27652
|
+
return paramsCheck;
|
|
27653
|
+
const tournamentRecord = makeDeepCopy(params.tournamentRecord, false, true);
|
|
27654
|
+
const foundEvent = !params.event ? findEvent({ tournamentRecord, eventId: params.eventId }).event : undefined;
|
|
27655
|
+
const event = params.event
|
|
27656
|
+
? makeDeepCopy(params.event, false, true)
|
|
27657
|
+
: (foundEvent && makeDeepCopy(foundEvent, false, true)) || undefined;
|
|
27658
|
+
if (!event)
|
|
27659
|
+
return { error: EVENT_NOT_FOUND };
|
|
27660
|
+
const { eventId } = event;
|
|
27661
|
+
const { tournamentId, endDate } = tournamentRecord;
|
|
27662
|
+
const publishStatus = getEventPublishStatus({ event, status });
|
|
27663
|
+
const publishState = getPublishState({ event }).publishState ?? {};
|
|
27664
|
+
const eventPublished = !!publishState?.status?.published;
|
|
27665
|
+
const { participants: tournamentParticipants } = getParticipants({
|
|
27666
|
+
withGroupings: true,
|
|
27667
|
+
withEvents: false,
|
|
27668
|
+
withDraws: false,
|
|
27669
|
+
policyDefinitions,
|
|
27670
|
+
...participantsProfile,
|
|
27067
27671
|
tournamentRecord,
|
|
27068
|
-
contextProfile,
|
|
27069
|
-
inContext,
|
|
27070
27672
|
});
|
|
27071
|
-
|
|
27072
|
-
|
|
27073
|
-
|
|
27074
|
-
|
|
27075
|
-
|
|
27076
|
-
|
|
27077
|
-
|
|
27078
|
-
|
|
27079
|
-
|
|
27080
|
-
|
|
27081
|
-
|
|
27082
|
-
|
|
27083
|
-
|
|
27084
|
-
|
|
27085
|
-
|
|
27086
|
-
|
|
27087
|
-
|
|
27088
|
-
}
|
|
27089
|
-
|
|
27090
|
-
|
|
27091
|
-
|
|
27673
|
+
const stageFilter = ({ stage, drawId }) => {
|
|
27674
|
+
if (!usePublishState)
|
|
27675
|
+
return true;
|
|
27676
|
+
const stageDetails = publishStatus?.drawDetails?.[drawId]?.stageDetails;
|
|
27677
|
+
if (!stageDetails || !Object.keys(stageDetails).length)
|
|
27678
|
+
return true;
|
|
27679
|
+
return stageDetails[stage]?.published;
|
|
27680
|
+
};
|
|
27681
|
+
const structureFilter = ({ structureId, drawId }) => {
|
|
27682
|
+
if (!usePublishState)
|
|
27683
|
+
return true;
|
|
27684
|
+
const structureDetails = publishStatus?.drawDetails?.[drawId]?.structureDetails;
|
|
27685
|
+
if (!structureDetails || !Object.keys(structureDetails).length)
|
|
27686
|
+
return true;
|
|
27687
|
+
return structureDetails[structureId]?.published;
|
|
27688
|
+
};
|
|
27689
|
+
const drawFilter = ({ drawId }) => (!usePublishState ? true : getDrawIsPublished({ publishStatus, drawId }));
|
|
27690
|
+
const roundLimitMapper = ({ drawId, structure }) => {
|
|
27691
|
+
if (!usePublishState)
|
|
27692
|
+
return structure;
|
|
27693
|
+
const roundLimit = publishStatus?.drawDetails?.[drawId]?.structureDetails?.[structure.structureId]?.roundLimit;
|
|
27694
|
+
if (isConvertableInteger(roundLimit)) {
|
|
27695
|
+
const roundNumbers = generateRange(1, roundLimit + 1);
|
|
27696
|
+
const roundMatchUps = {};
|
|
27697
|
+
const roundProfile = {};
|
|
27698
|
+
for (const roundNumber of roundNumbers) {
|
|
27699
|
+
if (structure.roundMatchUps[roundNumber]) {
|
|
27700
|
+
roundMatchUps[roundNumber] = structure.roundMatchUps[roundNumber];
|
|
27701
|
+
roundProfile[roundNumber] = structure.roundProfile[roundNumber];
|
|
27702
|
+
}
|
|
27703
|
+
}
|
|
27704
|
+
structure.roundMatchUps = roundMatchUps;
|
|
27705
|
+
structure.roundProfile = roundProfile;
|
|
27706
|
+
}
|
|
27707
|
+
return structure;
|
|
27708
|
+
};
|
|
27709
|
+
const drawDefinitions = event.drawDefinitions || [];
|
|
27710
|
+
const drawsData = !usePublishState || eventPublished
|
|
27711
|
+
? drawDefinitions
|
|
27712
|
+
.filter(drawFilter)
|
|
27713
|
+
.map((drawDefinition) => (({ drawInfo, structures }) => ({
|
|
27714
|
+
...drawInfo,
|
|
27715
|
+
structures,
|
|
27716
|
+
}))(getDrawData({
|
|
27717
|
+
allParticipantResults: params.allParticipantResults,
|
|
27718
|
+
context: { eventId, tournamentId, endDate },
|
|
27719
|
+
includePositionAssignments,
|
|
27092
27720
|
tournamentParticipants,
|
|
27093
|
-
|
|
27094
|
-
|
|
27721
|
+
noDeepCopy: true,
|
|
27722
|
+
policyDefinitions,
|
|
27723
|
+
tournamentRecord,
|
|
27724
|
+
usePublishState,
|
|
27095
27725
|
drawDefinition,
|
|
27096
|
-
|
|
27097
|
-
|
|
27098
|
-
inContext,
|
|
27726
|
+
publishStatus,
|
|
27727
|
+
sortConfig,
|
|
27099
27728
|
event,
|
|
27100
|
-
})
|
|
27101
|
-
|
|
27102
|
-
|
|
27103
|
-
}
|
|
27104
|
-
|
|
27105
|
-
|
|
27106
|
-
|
|
27107
|
-
|
|
27108
|
-
|
|
27109
|
-
|
|
27110
|
-
|
|
27111
|
-
|
|
27112
|
-
|
|
27113
|
-
|
|
27114
|
-
|
|
27115
|
-
}
|
|
27116
|
-
|
|
27729
|
+
})))
|
|
27730
|
+
.map(({ structures, ...drawData }) => {
|
|
27731
|
+
const filteredStructures = structures
|
|
27732
|
+
?.filter(({ stage, structureId }) => structureFilter({ structureId, drawId: drawData.drawId }) &&
|
|
27733
|
+
stageFilter({ stage, drawId: drawData.drawId }))
|
|
27734
|
+
.map((structure) => roundLimitMapper({ drawId: drawData.drawId, structure }));
|
|
27735
|
+
return {
|
|
27736
|
+
...drawData,
|
|
27737
|
+
structures: filteredStructures,
|
|
27738
|
+
};
|
|
27739
|
+
})
|
|
27740
|
+
.filter((drawData) => drawData.structures?.length)
|
|
27741
|
+
: undefined;
|
|
27742
|
+
const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
|
|
27743
|
+
const venues = tournamentRecord.venues || [];
|
|
27744
|
+
const venuesData = venues.map((venue) => (({ venueData }) => ({
|
|
27745
|
+
...venueData,
|
|
27746
|
+
}))(getVenueData({
|
|
27117
27747
|
tournamentRecord,
|
|
27118
|
-
|
|
27119
|
-
|
|
27120
|
-
|
|
27121
|
-
|
|
27122
|
-
|
|
27123
|
-
|
|
27124
|
-
|
|
27125
|
-
|
|
27126
|
-
|
|
27127
|
-
|
|
27128
|
-
|
|
27129
|
-
|
|
27130
|
-
|
|
27131
|
-
|
|
27132
|
-
|
|
27133
|
-
|
|
27134
|
-
|
|
27135
|
-
|
|
27136
|
-
|
|
27137
|
-
|
|
27138
|
-
|
|
27139
|
-
resolveTieFormat({ structure, drawDefinition, event })?.tieFormat;
|
|
27140
|
-
const drawDefaultTieFormat = (drawDefinition?.tieFormat || drawDefinition?.tieFormatId) &&
|
|
27141
|
-
resolveTieFormat({
|
|
27142
|
-
drawDefinition,
|
|
27143
|
-
event,
|
|
27144
|
-
})?.tieFormat;
|
|
27145
|
-
const eventDefaultTieFormat = resolveTieFormat({ event })?.tieFormat;
|
|
27146
|
-
const tieFormat = resolveTieFormat({
|
|
27147
|
-
matchUp: matchUpResult?.matchUp,
|
|
27148
|
-
drawDefinition,
|
|
27149
|
-
structure,
|
|
27150
|
-
event,
|
|
27151
|
-
})?.tieFormat;
|
|
27152
|
-
return {
|
|
27153
|
-
...SUCCESS,
|
|
27154
|
-
matchUp: matchUpResult?.matchUp,
|
|
27155
|
-
structureDefaultTieFormat: copyTieFormat(structureDefaultTieFormat),
|
|
27156
|
-
eventDefaultTieFormat: copyTieFormat(eventDefaultTieFormat),
|
|
27157
|
-
drawDefaultTieFormat: copyTieFormat(drawDefaultTieFormat),
|
|
27158
|
-
tieFormat: copyTieFormat(tieFormat),
|
|
27159
|
-
structure,
|
|
27748
|
+
venueId: venue.venueId,
|
|
27749
|
+
})));
|
|
27750
|
+
const eventInfo = (({ eventId, eventName, eventType, eventLevel, surfaceCategory, matchUpFormat, category, gender, startDate, endDate, ballType, discipline, }) => ({
|
|
27751
|
+
eventId,
|
|
27752
|
+
eventName,
|
|
27753
|
+
eventType,
|
|
27754
|
+
eventLevel,
|
|
27755
|
+
surfaceCategory,
|
|
27756
|
+
matchUpFormat,
|
|
27757
|
+
category,
|
|
27758
|
+
gender,
|
|
27759
|
+
startDate,
|
|
27760
|
+
endDate,
|
|
27761
|
+
ballType,
|
|
27762
|
+
discipline,
|
|
27763
|
+
}))(event);
|
|
27764
|
+
const eventData = {
|
|
27765
|
+
tournamentInfo,
|
|
27766
|
+
venuesData,
|
|
27767
|
+
eventInfo,
|
|
27768
|
+
drawsData,
|
|
27160
27769
|
};
|
|
27770
|
+
eventData.eventInfo.publishState = publishState;
|
|
27771
|
+
eventData.eventInfo.published = publishState?.status?.published;
|
|
27772
|
+
return { ...SUCCESS, eventData, participants: tournamentParticipants };
|
|
27161
27773
|
}
|
|
27162
27774
|
|
|
27163
|
-
var query$
|
|
27775
|
+
var query$7 = {
|
|
27164
27776
|
__proto__: null,
|
|
27165
|
-
|
|
27166
|
-
|
|
27167
|
-
|
|
27168
|
-
|
|
27777
|
+
bulkUpdatePublishedEventIds: bulkUpdatePublishedEventIds,
|
|
27778
|
+
getAllEventData: getAllEventData,
|
|
27779
|
+
getCourtInfo: getCourtInfo,
|
|
27780
|
+
getDrawData: getDrawData,
|
|
27781
|
+
getEventData: getEventData,
|
|
27782
|
+
getEventPublishStatus: getEventPublishStatus,
|
|
27783
|
+
getPublishState: getPublishState,
|
|
27784
|
+
getVenueData: getVenueData
|
|
27169
27785
|
};
|
|
27170
27786
|
|
|
27171
27787
|
function findMatchUpFormatTiming({ defaultRecoveryMinutes = 0, defaultAverageMinutes, tournamentRecords, matchUpFormat, categoryName, categoryType, tournamentId, eventType, eventId, }) {
|
|
@@ -27486,164 +28102,6 @@ function getAllRelevantSchedulingIds(params) {
|
|
|
27486
28102
|
};
|
|
27487
28103
|
}
|
|
27488
28104
|
|
|
27489
|
-
function getDisabledStatus({ dates = [], extension }) {
|
|
27490
|
-
if (!extension)
|
|
27491
|
-
return false;
|
|
27492
|
-
if (typeof extension.value === 'boolean' && extension.value)
|
|
27493
|
-
return true;
|
|
27494
|
-
if (!dates.length)
|
|
27495
|
-
return false;
|
|
27496
|
-
const disabledDates = isObject(extension.value) ? extension.value?.dates : undefined;
|
|
27497
|
-
if (Array.isArray(disabledDates)) {
|
|
27498
|
-
if (!disabledDates?.length)
|
|
27499
|
-
return false;
|
|
27500
|
-
const datesToConsider = disabledDates.filter((date) => !dates.length || dates.includes(date));
|
|
27501
|
-
return !!datesToConsider.length;
|
|
27502
|
-
}
|
|
27503
|
-
return undefined;
|
|
27504
|
-
}
|
|
27505
|
-
|
|
27506
|
-
function getInContextCourt({ convertExtensions, ignoreDisabled, venue, court }) {
|
|
27507
|
-
const inContextCourt = {
|
|
27508
|
-
...makeDeepCopy(court, convertExtensions, true),
|
|
27509
|
-
venueId: venue.venueId,
|
|
27510
|
-
};
|
|
27511
|
-
const { extension } = findExtension({
|
|
27512
|
-
name: DISABLED,
|
|
27513
|
-
element: court,
|
|
27514
|
-
});
|
|
27515
|
-
if (ignoreDisabled && extension) {
|
|
27516
|
-
const disabledDates = isObject(extension.value) ? extension.value?.dates : undefined;
|
|
27517
|
-
const dateAvailability = extension?.value === true
|
|
27518
|
-
? []
|
|
27519
|
-
: inContextCourt.dateAvailability
|
|
27520
|
-
.map((availability) => {
|
|
27521
|
-
const date = availability.date;
|
|
27522
|
-
if (!date || disabledDates.includes(date))
|
|
27523
|
-
return;
|
|
27524
|
-
return availability;
|
|
27525
|
-
})
|
|
27526
|
-
.filter(Boolean);
|
|
27527
|
-
inContextCourt.dateAvailability = dateAvailability;
|
|
27528
|
-
}
|
|
27529
|
-
return { inContextCourt };
|
|
27530
|
-
}
|
|
27531
|
-
|
|
27532
|
-
function getVenuesAndCourts(params) {
|
|
27533
|
-
const { convertExtensions, ignoreDisabled, venueIds = [], dates, } = params;
|
|
27534
|
-
const tournamentRecords = params.tournamentRecords ||
|
|
27535
|
-
(params.tournamentRecord && {
|
|
27536
|
-
[params.tournamentRecord.tournamentId]: params.tournamentRecord,
|
|
27537
|
-
}) ||
|
|
27538
|
-
{};
|
|
27539
|
-
const uniqueVenueIds = [];
|
|
27540
|
-
const uniqueCourtIds = [];
|
|
27541
|
-
const courts = [];
|
|
27542
|
-
const venues = [];
|
|
27543
|
-
const tournamentIds = Object.keys(tournamentRecords).filter((id) => !params.tournamentId || id === params.tournamentId);
|
|
27544
|
-
tournamentIds.forEach((tournamentId) => {
|
|
27545
|
-
const tournamentRecord = tournamentRecords[tournamentId];
|
|
27546
|
-
for (const venue of tournamentRecord.venues ?? []) {
|
|
27547
|
-
if (venueIds.length && !venueIds.includes(venue.venueId))
|
|
27548
|
-
continue;
|
|
27549
|
-
if (ignoreDisabled) {
|
|
27550
|
-
const { extension } = findExtension({
|
|
27551
|
-
name: DISABLED,
|
|
27552
|
-
element: venue,
|
|
27553
|
-
});
|
|
27554
|
-
if (extension?.value)
|
|
27555
|
-
continue;
|
|
27556
|
-
}
|
|
27557
|
-
if (!uniqueVenueIds.includes(venue.venueId)) {
|
|
27558
|
-
venues.push(makeDeepCopy(venue, convertExtensions, true));
|
|
27559
|
-
uniqueVenueIds.push(venue.venueId);
|
|
27560
|
-
}
|
|
27561
|
-
for (const court of venue.courts ?? []) {
|
|
27562
|
-
if (!uniqueCourtIds.includes(court.courtId)) {
|
|
27563
|
-
if (ignoreDisabled) {
|
|
27564
|
-
const { extension } = findExtension({
|
|
27565
|
-
name: DISABLED,
|
|
27566
|
-
element: court,
|
|
27567
|
-
});
|
|
27568
|
-
const isDisabled = getDisabledStatus({ extension, dates });
|
|
27569
|
-
if (isDisabled)
|
|
27570
|
-
continue;
|
|
27571
|
-
}
|
|
27572
|
-
const { inContextCourt } = getInContextCourt({
|
|
27573
|
-
convertExtensions,
|
|
27574
|
-
ignoreDisabled,
|
|
27575
|
-
venue,
|
|
27576
|
-
court,
|
|
27577
|
-
});
|
|
27578
|
-
courts.push(inContextCourt);
|
|
27579
|
-
uniqueCourtIds.push(court.courtId);
|
|
27580
|
-
}
|
|
27581
|
-
}
|
|
27582
|
-
}
|
|
27583
|
-
});
|
|
27584
|
-
return { courts, venues, ...SUCCESS };
|
|
27585
|
-
}
|
|
27586
|
-
function getTournamentVenuesAndCourts({ convertExtensions, tournamentRecord, ignoreDisabled, dates, }) {
|
|
27587
|
-
if (!tournamentRecord)
|
|
27588
|
-
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
27589
|
-
const venues = makeDeepCopy(tournamentRecord.venues ?? [], convertExtensions)
|
|
27590
|
-
.filter((venue) => {
|
|
27591
|
-
if (!ignoreDisabled)
|
|
27592
|
-
return venue;
|
|
27593
|
-
const { extension } = findExtension({
|
|
27594
|
-
name: DISABLED,
|
|
27595
|
-
element: venue,
|
|
27596
|
-
});
|
|
27597
|
-
return !extension?.value && venue;
|
|
27598
|
-
})
|
|
27599
|
-
.filter(Boolean);
|
|
27600
|
-
const courts = venues.reduce((courts, venue) => {
|
|
27601
|
-
const additionalCourts = (venue?.courts || [])
|
|
27602
|
-
.filter((court) => {
|
|
27603
|
-
if (!ignoreDisabled && !dates?.length)
|
|
27604
|
-
return court;
|
|
27605
|
-
const { extension } = findExtension({
|
|
27606
|
-
name: DISABLED,
|
|
27607
|
-
element: court,
|
|
27608
|
-
});
|
|
27609
|
-
return getDisabledStatus({ extension, dates });
|
|
27610
|
-
})
|
|
27611
|
-
.filter(Boolean)
|
|
27612
|
-
.map((court) => {
|
|
27613
|
-
const { inContextCourt } = getInContextCourt({
|
|
27614
|
-
convertExtensions,
|
|
27615
|
-
ignoreDisabled,
|
|
27616
|
-
venue,
|
|
27617
|
-
court,
|
|
27618
|
-
});
|
|
27619
|
-
return inContextCourt;
|
|
27620
|
-
});
|
|
27621
|
-
return additionalCourts.length ? courts.concat(additionalCourts) : courts;
|
|
27622
|
-
}, []);
|
|
27623
|
-
return { venues, courts };
|
|
27624
|
-
}
|
|
27625
|
-
function getCompetitionVenues({ tournamentRecords, requireCourts, dates }) {
|
|
27626
|
-
if (typeof tournamentRecords !== 'object' || !Object.keys(tournamentRecords).length)
|
|
27627
|
-
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
27628
|
-
const tournamentIds = Object.keys(tournamentRecords);
|
|
27629
|
-
return tournamentIds.reduce((accumulator, tournamentId) => {
|
|
27630
|
-
const tournamentRecord = tournamentRecords[tournamentId];
|
|
27631
|
-
const { venues } = getTournamentVenuesAndCourts({
|
|
27632
|
-
tournamentRecord,
|
|
27633
|
-
dates,
|
|
27634
|
-
});
|
|
27635
|
-
venues?.forEach((venue) => {
|
|
27636
|
-
const { venueId, courts } = venue;
|
|
27637
|
-
const includeVenue = !requireCourts || courts?.length;
|
|
27638
|
-
if (includeVenue && !accumulator.venueIds.includes(venueId)) {
|
|
27639
|
-
accumulator.venues.push(venue);
|
|
27640
|
-
accumulator.venueIds.push(venueId);
|
|
27641
|
-
}
|
|
27642
|
-
});
|
|
27643
|
-
return accumulator;
|
|
27644
|
-
}, { venues: [], venueIds: [] });
|
|
27645
|
-
}
|
|
27646
|
-
|
|
27647
28105
|
function getSchedulingProfile({ tournamentRecords, tournamentRecord }) {
|
|
27648
28106
|
if (typeof tournamentRecords !== 'object' || !Object.keys(tournamentRecords).length)
|
|
27649
28107
|
return { error: MISSING_TOURNAMENT_RECORDS };
|
|
@@ -27972,7 +28430,7 @@ function getProfileRounds({ tournamentRecords, schedulingProfile, tournamentReco
|
|
|
27972
28430
|
return { profileRounds, segmentedRounds };
|
|
27973
28431
|
}
|
|
27974
28432
|
|
|
27975
|
-
var query$
|
|
28433
|
+
var query$6 = {
|
|
27976
28434
|
__proto__: null,
|
|
27977
28435
|
getPersonRequests: getPersonRequests,
|
|
27978
28436
|
getProfileRounds: getProfileRounds,
|
|
@@ -28014,7 +28472,7 @@ function getMaxEntryPosition(params) {
|
|
|
28014
28472
|
.map(({ entryPosition }) => ensureInt(entryPosition || 0)), 0);
|
|
28015
28473
|
}
|
|
28016
28474
|
|
|
28017
|
-
var query$
|
|
28475
|
+
var query$5 = {
|
|
28018
28476
|
__proto__: null,
|
|
28019
28477
|
getEntriesAndSeedsCount: getEntriesAndSeedsCount,
|
|
28020
28478
|
getMaxEntryPosition: getMaxEntryPosition
|
|
@@ -29930,7 +30388,7 @@ function drawMatchUps({ participants: tournamentParticipants, tournamentAppliedP
|
|
|
29930
30388
|
return { ...drawMatchUpsResult, groupInfo };
|
|
29931
30389
|
}
|
|
29932
30390
|
|
|
29933
|
-
var query$
|
|
30391
|
+
var query$4 = {
|
|
29934
30392
|
__proto__: null,
|
|
29935
30393
|
allCompetitionMatchUps: allCompetitionMatchUps,
|
|
29936
30394
|
allDrawMatchUps: allDrawMatchUps,
|
|
@@ -29993,7 +30451,7 @@ function getCourts({ tournamentRecord, venueId, venueIds }) {
|
|
|
29993
30451
|
return { courts };
|
|
29994
30452
|
}
|
|
29995
30453
|
|
|
29996
|
-
var query$
|
|
30454
|
+
var query$3 = {
|
|
29997
30455
|
__proto__: null,
|
|
29998
30456
|
getCompetitionVenues: getCompetitionVenues,
|
|
29999
30457
|
getCourts: getCourts,
|
|
@@ -30001,42 +30459,6 @@ var query$4 = {
|
|
|
30001
30459
|
publicFindVenue: publicFindVenue
|
|
30002
30460
|
};
|
|
30003
30461
|
|
|
30004
|
-
function bulkUpdatePublishedEventIds({ tournamentRecord, outcomes }) {
|
|
30005
|
-
if (!tournamentRecord)
|
|
30006
|
-
return { error: MISSING_TOURNAMENT_RECORD };
|
|
30007
|
-
if (!outcomes?.length)
|
|
30008
|
-
return { error: MISSING_VALUE, info: 'Missing outcomes' };
|
|
30009
|
-
const eventIdsMap = outcomes.reduce((eventIdsMap, outcome) => {
|
|
30010
|
-
const { drawId, eventId } = outcome;
|
|
30011
|
-
if (eventId && drawId) {
|
|
30012
|
-
if (!eventIdsMap[eventId]) {
|
|
30013
|
-
eventIdsMap[eventId] = [drawId];
|
|
30014
|
-
}
|
|
30015
|
-
else if (!eventIdsMap[eventId].includes(drawId)) {
|
|
30016
|
-
eventIdsMap[eventId].push(drawId);
|
|
30017
|
-
}
|
|
30018
|
-
}
|
|
30019
|
-
return eventIdsMap;
|
|
30020
|
-
}, {});
|
|
30021
|
-
const relevantEventsIds = Object.keys(eventIdsMap);
|
|
30022
|
-
const relevantEvents = tournamentRecord.events?.filter((event) => relevantEventsIds.includes(event.eventId));
|
|
30023
|
-
const publishedEventIds = relevantEvents
|
|
30024
|
-
.filter((event) => {
|
|
30025
|
-
const pubStatus = getEventPublishStatus({ event });
|
|
30026
|
-
const { drawDetails, drawIds } = pubStatus ?? {};
|
|
30027
|
-
const { eventId } = event;
|
|
30028
|
-
const publishedDrawIds = eventIdsMap[eventId].filter((drawId) => {
|
|
30029
|
-
const keyedDrawIds = drawDetails
|
|
30030
|
-
? Object.keys(pubStatus.drawDetails).filter((drawId) => getDrawPublishStatus({ drawId, drawDetails }))
|
|
30031
|
-
: [];
|
|
30032
|
-
return drawIds?.includes(drawId) || keyedDrawIds.includes(drawId);
|
|
30033
|
-
});
|
|
30034
|
-
return publishedDrawIds.length;
|
|
30035
|
-
})
|
|
30036
|
-
.map((event) => event.eventId);
|
|
30037
|
-
return { publishedEventIds, eventIdPublishedDrawIdsMap: eventIdsMap };
|
|
30038
|
-
}
|
|
30039
|
-
|
|
30040
30462
|
function getEventProperties({ tournamentRecord, event }) {
|
|
30041
30463
|
if (!tournamentRecord)
|
|
30042
30464
|
return { error: MISSING_TOURNAMENT_RECORD };
|
|
@@ -30301,9 +30723,8 @@ function getEvent({ tournamentRecord, drawDefinition, context, event }) {
|
|
|
30301
30723
|
});
|
|
30302
30724
|
}
|
|
30303
30725
|
|
|
30304
|
-
var query$
|
|
30726
|
+
var query$2 = {
|
|
30305
30727
|
__proto__: null,
|
|
30306
|
-
bulkUpdatePublishedEventIds: bulkUpdatePublishedEventIds,
|
|
30307
30728
|
categoryCanContain: categoryCanContain,
|
|
30308
30729
|
getCategoryAgeDetails: getCategoryAgeDetails,
|
|
30309
30730
|
getEvent: getEvent,
|
|
@@ -30340,6 +30761,7 @@ var index$g = {
|
|
|
30340
30761
|
findDrawDefinition: publicFindDrawDefinition,
|
|
30341
30762
|
findExtension: findExtension,
|
|
30342
30763
|
getAllDrawMatchUps: getAllDrawMatchUps,
|
|
30764
|
+
getAllEventData: getAllEventData,
|
|
30343
30765
|
getAllStructureMatchUps: getAllStructureMatchUps,
|
|
30344
30766
|
getAllowedDrawTypes: getAllowedDrawTypes,
|
|
30345
30767
|
getAllowedMatchUpFormats: getAllowedMatchUpFormats,
|
|
@@ -30354,15 +30776,19 @@ var index$g = {
|
|
|
30354
30776
|
getCompetitionParticipants: getCompetitionParticipants,
|
|
30355
30777
|
getCompetitionPenalties: getCompetitionPenalties,
|
|
30356
30778
|
getCompetitionVenues: getCompetitionVenues,
|
|
30779
|
+
getCourtInfo: getCourtInfo,
|
|
30357
30780
|
getCourts: getCourts,
|
|
30781
|
+
getDrawData: getDrawData,
|
|
30358
30782
|
getDrawDefinitionTimeItem: getDrawDefinitionTimeItem,
|
|
30359
30783
|
getDrawParticipantRepresentativeIds: getDrawParticipantRepresentativeIds,
|
|
30360
30784
|
getDrawTypeCoercion: getDrawTypeCoercion,
|
|
30361
30785
|
getEligibleVoluntaryConsolationParticipants: getEligibleVoluntaryConsolationParticipants,
|
|
30362
30786
|
getEntriesAndSeedsCount: getEntriesAndSeedsCount,
|
|
30363
30787
|
getEvent: getEvent,
|
|
30788
|
+
getEventData: getEventData,
|
|
30364
30789
|
getEventMatchUpFormatTiming: getEventMatchUpFormatTiming,
|
|
30365
30790
|
getEventProperties: getEventProperties,
|
|
30791
|
+
getEventPublishStatus: getEventPublishStatus,
|
|
30366
30792
|
getEventStructures: getEventStructures,
|
|
30367
30793
|
getEventTimeItem: getEventTimeItem,
|
|
30368
30794
|
getEvents: getEvents,
|
|
@@ -30398,6 +30824,7 @@ var index$g = {
|
|
|
30398
30824
|
getPositionsPlayedOff: getPositionsPlayedOff,
|
|
30399
30825
|
getPredictiveAccuracy: getPredictiveAccuracy,
|
|
30400
30826
|
getProfileRounds: getProfileRounds,
|
|
30827
|
+
getPublishState: getPublishState,
|
|
30401
30828
|
getRoundMatchUps: getRoundMatchUps,
|
|
30402
30829
|
getRounds: getRounds,
|
|
30403
30830
|
getScaleValues: getScaleValues,
|
|
@@ -30418,6 +30845,7 @@ var index$g = {
|
|
|
30418
30845
|
getTournamentStructures: getTournamentStructures,
|
|
30419
30846
|
getTournamentTimeItem: getTournamentTimeItem,
|
|
30420
30847
|
getValidGroupSizes: getValidGroupSizes,
|
|
30848
|
+
getVenueData: getVenueData,
|
|
30421
30849
|
getVenuesAndCourts: getVenuesAndCourts,
|
|
30422
30850
|
isAdHoc: isAdHoc,
|
|
30423
30851
|
isCompletedStructure: isCompletedStructure,
|
|
@@ -33792,7 +34220,7 @@ function parseScoreString({ tiebreakTo = 7, scoreString = '' }) {
|
|
|
33792
34220
|
}
|
|
33793
34221
|
}
|
|
33794
34222
|
|
|
33795
|
-
var query$
|
|
34223
|
+
var query$1 = {
|
|
33796
34224
|
__proto__: null,
|
|
33797
34225
|
analyzeSet: analyzeSet,
|
|
33798
34226
|
checkScoreHasValue: checkScoreHasValue,
|
|
@@ -33827,7 +34255,7 @@ var scoreGovernor = {
|
|
|
33827
34255
|
mutate: mutate$b,
|
|
33828
34256
|
parseMatchUpFormat: parse,
|
|
33829
34257
|
parseScoreString: parseScoreString,
|
|
33830
|
-
query: query$
|
|
34258
|
+
query: query$1,
|
|
33831
34259
|
redo: redo,
|
|
33832
34260
|
reverseScore: reverseScore,
|
|
33833
34261
|
setServingSide: setServingSide,
|
|
@@ -35858,7 +36286,7 @@ var mutate$a = {
|
|
|
35858
36286
|
removePolicy: removePolicy
|
|
35859
36287
|
};
|
|
35860
36288
|
|
|
35861
|
-
var query
|
|
36289
|
+
var query = {
|
|
35862
36290
|
__proto__: null,
|
|
35863
36291
|
findPolicy: findPolicy,
|
|
35864
36292
|
getAppliedPolicies: getAppliedPolicies,
|
|
@@ -35872,7 +36300,7 @@ var index$f = {
|
|
|
35872
36300
|
getAppliedPolicies: getAppliedPolicies,
|
|
35873
36301
|
getPolicyDefinitions: getPolicyDefinitions,
|
|
35874
36302
|
mutate: mutate$a,
|
|
35875
|
-
query: query
|
|
36303
|
+
query: query,
|
|
35876
36304
|
removePolicy: removePolicy
|
|
35877
36305
|
};
|
|
35878
36306
|
|
|
@@ -36861,7 +37289,7 @@ var index$d = {
|
|
|
36861
37289
|
mutate: mutate$9,
|
|
36862
37290
|
promoteAlternate: promoteAlternate,
|
|
36863
37291
|
promoteAlternates: promoteAlternates,
|
|
36864
|
-
query: query$
|
|
37292
|
+
query: query$5,
|
|
36865
37293
|
removeDrawEntries: removeDrawEntries,
|
|
36866
37294
|
removeEventEntries: removeEventEntries,
|
|
36867
37295
|
setEntryPosition: setEntryPosition,
|
|
@@ -36884,305 +37312,6 @@ function modifyEventPublishStatus({ removePriorValues = true, status = PUBLIC, s
|
|
|
36884
37312
|
});
|
|
36885
37313
|
}
|
|
36886
37314
|
|
|
36887
|
-
function getDrawIsPublished({ publishStatus, drawId }) {
|
|
36888
|
-
if (publishStatus?.drawDetails) {
|
|
36889
|
-
return publishStatus.drawDetails?.[drawId]?.publishingDetail?.published;
|
|
36890
|
-
}
|
|
36891
|
-
else if (publishStatus?.drawIds) {
|
|
36892
|
-
return publishStatus.drawIds.includes(drawId);
|
|
36893
|
-
}
|
|
36894
|
-
return true;
|
|
36895
|
-
}
|
|
36896
|
-
|
|
36897
|
-
function getDrawData(params) {
|
|
36898
|
-
const { tournamentParticipants = [], includePositionAssignments, policyDefinitions, tournamentRecord, inContext = true, usePublishState, status = PUBLIC, drawDefinition, noDeepCopy, sortConfig, context, event, } = params;
|
|
36899
|
-
if (!drawDefinition)
|
|
36900
|
-
return { error: MISSING_DRAW_DEFINITION };
|
|
36901
|
-
const drawInfo = (({ matchUpFormat, updatedAt, drawType, drawName, drawId }) => ({
|
|
36902
|
-
matchUpFormat,
|
|
36903
|
-
updatedAt,
|
|
36904
|
-
drawName,
|
|
36905
|
-
drawType,
|
|
36906
|
-
drawId,
|
|
36907
|
-
}))(drawDefinition);
|
|
36908
|
-
let mainStageSeedAssignments, qualificationStageSeedAssignments;
|
|
36909
|
-
const { allStructuresLinked, sourceStructureIds, hasDrawFeedProfile, structureGroups } = getStructureGroups({
|
|
36910
|
-
drawDefinition,
|
|
36911
|
-
});
|
|
36912
|
-
if (!allStructuresLinked)
|
|
36913
|
-
return { error: UNLINKED_STRUCTURES };
|
|
36914
|
-
const publishStatus = params?.publishStatus ?? getEventPublishStatus({ event, status });
|
|
36915
|
-
const eventPublished = params.eventPublished ?? !!getPublishState({ event }).publishState?.status?.published;
|
|
36916
|
-
let drawActive = false;
|
|
36917
|
-
let participantPlacements = false;
|
|
36918
|
-
const groupedStructures = structureGroups.map((structureIds) => {
|
|
36919
|
-
const completedStructures = {};
|
|
36920
|
-
const structures = structureIds
|
|
36921
|
-
.map((structureId) => {
|
|
36922
|
-
const { structure } = findStructure({ drawDefinition, structureId });
|
|
36923
|
-
const { seedAssignments } = getStructureSeedAssignments({
|
|
36924
|
-
drawDefinition,
|
|
36925
|
-
structure,
|
|
36926
|
-
});
|
|
36927
|
-
if (structure?.stage === MAIN && structure.stageSequence === 1) {
|
|
36928
|
-
mainStageSeedAssignments = seedAssignments;
|
|
36929
|
-
}
|
|
36930
|
-
if (structure?.stage === QUALIFYING && structure.stageSequence === 1) {
|
|
36931
|
-
qualificationStageSeedAssignments = seedAssignments;
|
|
36932
|
-
}
|
|
36933
|
-
return structure;
|
|
36934
|
-
})
|
|
36935
|
-
.sort((a, b) => structureSort(a, b, sortConfig))
|
|
36936
|
-
.map((structure) => {
|
|
36937
|
-
if (!structure)
|
|
36938
|
-
return;
|
|
36939
|
-
const structureId = structure?.structureId;
|
|
36940
|
-
let seedAssignments = [];
|
|
36941
|
-
if (structure.stage && [MAIN, CONSOLATION, PLAY_OFF].includes(structure.stage)) {
|
|
36942
|
-
seedAssignments = mainStageSeedAssignments;
|
|
36943
|
-
}
|
|
36944
|
-
if (structure?.stage === QUALIFYING) {
|
|
36945
|
-
seedAssignments = qualificationStageSeedAssignments;
|
|
36946
|
-
}
|
|
36947
|
-
const { matchUps, roundMatchUps, roundProfile } = getAllStructureMatchUps({
|
|
36948
|
-
seedAssignments: !structure?.seedAssignments?.length ? seedAssignments : undefined,
|
|
36949
|
-
context: { drawId: drawInfo.drawId, ...context },
|
|
36950
|
-
tournamentParticipants,
|
|
36951
|
-
policyDefinitions,
|
|
36952
|
-
tournamentRecord,
|
|
36953
|
-
usePublishState,
|
|
36954
|
-
publishStatus,
|
|
36955
|
-
drawDefinition,
|
|
36956
|
-
inContext,
|
|
36957
|
-
structure,
|
|
36958
|
-
event,
|
|
36959
|
-
});
|
|
36960
|
-
const { positionAssignments } = getPositionAssignments$1({
|
|
36961
|
-
structure,
|
|
36962
|
-
});
|
|
36963
|
-
let participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
|
|
36964
|
-
const { drawPosition, participantId } = assignment;
|
|
36965
|
-
const { extension } = findExtension({
|
|
36966
|
-
element: assignment,
|
|
36967
|
-
name: TALLY,
|
|
36968
|
-
});
|
|
36969
|
-
participantPlacements = true;
|
|
36970
|
-
return {
|
|
36971
|
-
participantResult: extension?.value,
|
|
36972
|
-
participantId,
|
|
36973
|
-
drawPosition,
|
|
36974
|
-
};
|
|
36975
|
-
});
|
|
36976
|
-
if (!participantResults?.length && matchUps.length && params.allParticipantResults) {
|
|
36977
|
-
const { subOrderMap } = createSubOrderMap({ positionAssignments });
|
|
36978
|
-
const result = tallyParticipantResults({
|
|
36979
|
-
matchUpFormat: structure.matchUpFormat,
|
|
36980
|
-
policyDefinitions,
|
|
36981
|
-
subOrderMap,
|
|
36982
|
-
matchUps,
|
|
36983
|
-
});
|
|
36984
|
-
participantResults = positionAssignments?.filter(xa(PARTICIPANT_ID)).map((assignment) => {
|
|
36985
|
-
const { drawPosition, participantId } = assignment;
|
|
36986
|
-
participantPlacements = true;
|
|
36987
|
-
return {
|
|
36988
|
-
participantResult: participantId && result.participantResults[participantId],
|
|
36989
|
-
participantId,
|
|
36990
|
-
drawPosition,
|
|
36991
|
-
};
|
|
36992
|
-
});
|
|
36993
|
-
}
|
|
36994
|
-
const structureInfo = structure
|
|
36995
|
-
? (({ stageSequence, structureName, structureType, matchUpFormat, stage }) => ({
|
|
36996
|
-
stageSequence,
|
|
36997
|
-
structureName,
|
|
36998
|
-
structureType,
|
|
36999
|
-
matchUpFormat,
|
|
37000
|
-
stage,
|
|
37001
|
-
}))(structure)
|
|
37002
|
-
: {};
|
|
37003
|
-
structureInfo.sourceStructureIds = sourceStructureIds[structureId];
|
|
37004
|
-
structureInfo.hasDrawFeedProfile = hasDrawFeedProfile[structureId];
|
|
37005
|
-
structureInfo.positionAssignments = positionAssignments;
|
|
37006
|
-
structureInfo.structureActive = matchUps.reduce((active, matchUp) => {
|
|
37007
|
-
const activeMatchUpStatus = [
|
|
37008
|
-
COMPLETED$1,
|
|
37009
|
-
CANCELLED$1,
|
|
37010
|
-
DEFAULTED,
|
|
37011
|
-
RETIRED$1,
|
|
37012
|
-
WALKOVER$2,
|
|
37013
|
-
IN_PROGRESS$1,
|
|
37014
|
-
DOUBLE_DEFAULT,
|
|
37015
|
-
DOUBLE_WALKOVER,
|
|
37016
|
-
].includes(matchUp.matchUpStatus);
|
|
37017
|
-
return active || activeMatchUpStatus || !!matchUp.winningSide || !!matchUp.score?.scoreStringSide1;
|
|
37018
|
-
}, false);
|
|
37019
|
-
const structureCompleted = matchUps.reduce((completed, matchUp) => {
|
|
37020
|
-
return completed && [BYE, COMPLETED$1, RETIRED$1, WALKOVER$2, DEFAULTED, ABANDONED$1].includes(matchUp.matchUpStatus);
|
|
37021
|
-
}, !!matchUps.length);
|
|
37022
|
-
structureInfo.structureCompleted = structureCompleted;
|
|
37023
|
-
completedStructures[structureId] = structureCompleted;
|
|
37024
|
-
if (structureInfo.structureActive)
|
|
37025
|
-
drawActive = true;
|
|
37026
|
-
return {
|
|
37027
|
-
...structureInfo,
|
|
37028
|
-
participantResults,
|
|
37029
|
-
seedAssignments,
|
|
37030
|
-
roundMatchUps,
|
|
37031
|
-
roundProfile,
|
|
37032
|
-
structureId,
|
|
37033
|
-
};
|
|
37034
|
-
});
|
|
37035
|
-
structures.forEach((structure) => {
|
|
37036
|
-
if (!includePositionAssignments)
|
|
37037
|
-
delete structure.positionAssignments;
|
|
37038
|
-
structure.sourceStructuresComplete = structure.sourceStructureIds?.every((id) => completedStructures[id]);
|
|
37039
|
-
});
|
|
37040
|
-
return structures;
|
|
37041
|
-
});
|
|
37042
|
-
const structures = groupedStructures.flat();
|
|
37043
|
-
drawInfo.drawActive = drawActive;
|
|
37044
|
-
drawInfo.participantPlacements = participantPlacements;
|
|
37045
|
-
drawInfo.drawGenerated = structures?.reduce((generated, structure) => {
|
|
37046
|
-
return generated || !!structure?.roundMatchUps;
|
|
37047
|
-
}, false);
|
|
37048
|
-
drawInfo.drawCompleted = structures?.reduce((completed, structure) => completed && structure.structureCompleted, true);
|
|
37049
|
-
drawInfo.drawPublished = usePublishState
|
|
37050
|
-
? eventPublished && getDrawIsPublished({ publishStatus, drawId: drawInfo.drawId })
|
|
37051
|
-
: undefined;
|
|
37052
|
-
return {
|
|
37053
|
-
structures: !usePublishState || drawInfo.drawPublished
|
|
37054
|
-
? noDeepCopy
|
|
37055
|
-
? structures
|
|
37056
|
-
: makeDeepCopy(structures, false, true)
|
|
37057
|
-
: undefined,
|
|
37058
|
-
drawInfo: noDeepCopy ? drawInfo : makeDeepCopy(drawInfo, false, true),
|
|
37059
|
-
...SUCCESS,
|
|
37060
|
-
};
|
|
37061
|
-
}
|
|
37062
|
-
|
|
37063
|
-
function getEventData(params) {
|
|
37064
|
-
const { includePositionAssignments, tournamentRecord: t, participantsProfile, policyDefinitions, usePublishState, status = PUBLIC, sortConfig, event: e, } = params;
|
|
37065
|
-
const tournamentRecord = makeDeepCopy(t, false, true);
|
|
37066
|
-
const event = makeDeepCopy(e, false, true);
|
|
37067
|
-
if (!tournamentRecord)
|
|
37068
|
-
return { error: MISSING_TOURNAMENT_RECORD };
|
|
37069
|
-
if (!event)
|
|
37070
|
-
return { error: MISSING_EVENT };
|
|
37071
|
-
const { eventId } = event;
|
|
37072
|
-
const { tournamentId, endDate } = tournamentRecord;
|
|
37073
|
-
const publishStatus = getEventPublishStatus({ event, status });
|
|
37074
|
-
const publishState = getPublishState({ event }).publishState ?? {};
|
|
37075
|
-
const eventPublished = !!publishState?.status?.published;
|
|
37076
|
-
const { participants: tournamentParticipants } = getParticipants({
|
|
37077
|
-
withGroupings: true,
|
|
37078
|
-
withEvents: false,
|
|
37079
|
-
withDraws: false,
|
|
37080
|
-
policyDefinitions,
|
|
37081
|
-
...participantsProfile,
|
|
37082
|
-
tournamentRecord,
|
|
37083
|
-
});
|
|
37084
|
-
const stageFilter = ({ stage, drawId }) => {
|
|
37085
|
-
if (!usePublishState)
|
|
37086
|
-
return true;
|
|
37087
|
-
const stageDetails = publishStatus?.drawDetails?.[drawId]?.stageDetails;
|
|
37088
|
-
if (!stageDetails || !Object.keys(stageDetails).length)
|
|
37089
|
-
return true;
|
|
37090
|
-
return stageDetails[stage]?.published;
|
|
37091
|
-
};
|
|
37092
|
-
const structureFilter = ({ structureId, drawId }) => {
|
|
37093
|
-
if (!usePublishState)
|
|
37094
|
-
return true;
|
|
37095
|
-
const structureDetails = publishStatus?.drawDetails?.[drawId]?.structureDetails;
|
|
37096
|
-
if (!structureDetails || !Object.keys(structureDetails).length)
|
|
37097
|
-
return true;
|
|
37098
|
-
return structureDetails[structureId]?.published;
|
|
37099
|
-
};
|
|
37100
|
-
const drawFilter = ({ drawId }) => (!usePublishState ? true : getDrawIsPublished({ publishStatus, drawId }));
|
|
37101
|
-
const roundLimitMapper = ({ drawId, structure }) => {
|
|
37102
|
-
if (!usePublishState)
|
|
37103
|
-
return structure;
|
|
37104
|
-
const roundLimit = publishStatus?.drawDetails?.[drawId]?.structureDetails?.[structure.structureId]?.roundLimit;
|
|
37105
|
-
if (isConvertableInteger(roundLimit)) {
|
|
37106
|
-
const roundNumbers = generateRange(1, roundLimit + 1);
|
|
37107
|
-
const roundMatchUps = {};
|
|
37108
|
-
const roundProfile = {};
|
|
37109
|
-
for (const roundNumber of roundNumbers) {
|
|
37110
|
-
if (structure.roundMatchUps[roundNumber]) {
|
|
37111
|
-
roundMatchUps[roundNumber] = structure.roundMatchUps[roundNumber];
|
|
37112
|
-
roundProfile[roundNumber] = structure.roundProfile[roundNumber];
|
|
37113
|
-
}
|
|
37114
|
-
}
|
|
37115
|
-
structure.roundMatchUps = roundMatchUps;
|
|
37116
|
-
structure.roundProfile = roundProfile;
|
|
37117
|
-
}
|
|
37118
|
-
return structure;
|
|
37119
|
-
};
|
|
37120
|
-
const drawDefinitions = event.drawDefinitions || [];
|
|
37121
|
-
const drawsData = !usePublishState || eventPublished
|
|
37122
|
-
? drawDefinitions
|
|
37123
|
-
.filter(drawFilter)
|
|
37124
|
-
.map((drawDefinition) => (({ drawInfo, structures }) => ({
|
|
37125
|
-
...drawInfo,
|
|
37126
|
-
structures,
|
|
37127
|
-
}))(getDrawData({
|
|
37128
|
-
allParticipantResults: params.allParticipantResults,
|
|
37129
|
-
context: { eventId, tournamentId, endDate },
|
|
37130
|
-
includePositionAssignments,
|
|
37131
|
-
tournamentParticipants,
|
|
37132
|
-
noDeepCopy: true,
|
|
37133
|
-
policyDefinitions,
|
|
37134
|
-
tournamentRecord,
|
|
37135
|
-
usePublishState,
|
|
37136
|
-
drawDefinition,
|
|
37137
|
-
publishStatus,
|
|
37138
|
-
sortConfig,
|
|
37139
|
-
event,
|
|
37140
|
-
})))
|
|
37141
|
-
.map(({ structures, ...drawData }) => {
|
|
37142
|
-
const filteredStructures = structures
|
|
37143
|
-
?.filter(({ stage, structureId }) => structureFilter({ structureId, drawId: drawData.drawId }) &&
|
|
37144
|
-
stageFilter({ stage, drawId: drawData.drawId }))
|
|
37145
|
-
.map((structure) => roundLimitMapper({ drawId: drawData.drawId, structure }));
|
|
37146
|
-
return {
|
|
37147
|
-
...drawData,
|
|
37148
|
-
structures: filteredStructures,
|
|
37149
|
-
};
|
|
37150
|
-
})
|
|
37151
|
-
.filter((drawData) => drawData.structures?.length)
|
|
37152
|
-
: undefined;
|
|
37153
|
-
const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
|
|
37154
|
-
const venues = tournamentRecord.venues || [];
|
|
37155
|
-
const venuesData = venues.map((venue) => (({ venueData }) => ({
|
|
37156
|
-
...venueData,
|
|
37157
|
-
}))(getVenueData({
|
|
37158
|
-
tournamentRecord,
|
|
37159
|
-
venueId: venue.venueId,
|
|
37160
|
-
})));
|
|
37161
|
-
const eventInfo = (({ eventId, eventName, eventType, eventLevel, surfaceCategory, matchUpFormat, category, gender, startDate, endDate, ballType, discipline, }) => ({
|
|
37162
|
-
eventId,
|
|
37163
|
-
eventName,
|
|
37164
|
-
eventType,
|
|
37165
|
-
eventLevel,
|
|
37166
|
-
surfaceCategory,
|
|
37167
|
-
matchUpFormat,
|
|
37168
|
-
category,
|
|
37169
|
-
gender,
|
|
37170
|
-
startDate,
|
|
37171
|
-
endDate,
|
|
37172
|
-
ballType,
|
|
37173
|
-
discipline,
|
|
37174
|
-
}))(event);
|
|
37175
|
-
const eventData = {
|
|
37176
|
-
tournamentInfo,
|
|
37177
|
-
venuesData,
|
|
37178
|
-
eventInfo,
|
|
37179
|
-
drawsData,
|
|
37180
|
-
};
|
|
37181
|
-
eventData.eventInfo.publishState = publishState;
|
|
37182
|
-
eventData.eventInfo.published = publishState?.status?.published;
|
|
37183
|
-
return { ...SUCCESS, eventData, participants: tournamentParticipants };
|
|
37184
|
-
}
|
|
37185
|
-
|
|
37186
37315
|
function publishEvent(params) {
|
|
37187
37316
|
const { includePositionAssignments, removePriorValues, tournamentRecord, status = PUBLIC, event, drawIdsToRemove, drawIdsToAdd, } = params;
|
|
37188
37317
|
if (!tournamentRecord)
|
|
@@ -38731,7 +38860,6 @@ var index$c = {
|
|
|
38731
38860
|
addFlight: addFlight,
|
|
38732
38861
|
assignSeedPositions: assignSeedPositions,
|
|
38733
38862
|
attachFlightProfile: attachFlightProfile,
|
|
38734
|
-
bulkUpdatePublishedEventIds: bulkUpdatePublishedEventIds,
|
|
38735
38863
|
categoryCanContain: categoryCanContain,
|
|
38736
38864
|
deleteDrawDefinitions: deleteDrawDefinitions,
|
|
38737
38865
|
deleteEvents: deleteEvents,
|
|
@@ -38749,7 +38877,7 @@ var index$c = {
|
|
|
38749
38877
|
modifyEventMatchUpFormatTiming: modifyEventMatchUpFormatTiming,
|
|
38750
38878
|
modifyPairAssignment: modifyPairAssignment,
|
|
38751
38879
|
mutate: mutate$8,
|
|
38752
|
-
query: query$
|
|
38880
|
+
query: query$2,
|
|
38753
38881
|
refreshEventDrawOrder: refreshEventDrawOrder,
|
|
38754
38882
|
removeEventMatchUpFormatTiming: removeEventMatchUpFormatTiming,
|
|
38755
38883
|
removeScaleValues: removeScaleValues,
|
|
@@ -43948,7 +44076,7 @@ var index$9 = {
|
|
|
43948
44076
|
matchUpActions: matchUpActions,
|
|
43949
44077
|
mutate: mutate$7,
|
|
43950
44078
|
participantScheduledMatchUps: participantScheduledMatchUps,
|
|
43951
|
-
query: query$
|
|
44079
|
+
query: query$4,
|
|
43952
44080
|
removeDelegatedOutcome: removeDelegatedOutcome,
|
|
43953
44081
|
removeMatchUpSideParticipant: removeMatchUpSideParticipant,
|
|
43954
44082
|
removeTieMatchUpParticipantId: removeTieMatchUpParticipantId,
|
|
@@ -45537,22 +45665,40 @@ function clearSchedules({ scheduleAttributes = ['scheduledDate', 'scheduledTime'
|
|
|
45537
45665
|
matchUpFilters: { scheduledDates },
|
|
45538
45666
|
tournamentRecord,
|
|
45539
45667
|
}).matchUps ?? [];
|
|
45540
|
-
const
|
|
45541
|
-
|
|
45542
|
-
!ignoreMatchUpStatuses.includes(
|
|
45543
|
-
|
|
45544
|
-
|
|
45545
|
-
|
|
45546
|
-
|
|
45547
|
-
|
|
45548
|
-
|
|
45549
|
-
})
|
|
45668
|
+
const drawMatchUpIds = {};
|
|
45669
|
+
inContextMatchUps.forEach(({ matchUpStatus, schedule, drawId, matchUpId }) => {
|
|
45670
|
+
if ((!matchUpStatus || !ignoreMatchUpStatuses.includes(matchUpStatus)) &&
|
|
45671
|
+
hasSchedule({ schedule, scheduleAttributes }) &&
|
|
45672
|
+
(!venueIds?.length || venueIds.includes(schedule.venueId))) {
|
|
45673
|
+
if (!drawMatchUpIds[drawId])
|
|
45674
|
+
drawMatchUpIds[drawId] = [];
|
|
45675
|
+
drawMatchUpIds[drawId].push(matchUpId);
|
|
45676
|
+
}
|
|
45677
|
+
});
|
|
45678
|
+
const tournamentId = tournamentRecord.tournamentId;
|
|
45550
45679
|
let clearedScheduleCount = 0;
|
|
45551
|
-
for (const
|
|
45552
|
-
|
|
45553
|
-
|
|
45554
|
-
|
|
45555
|
-
|
|
45680
|
+
for (const drawId in drawMatchUpIds) {
|
|
45681
|
+
const { event, drawDefinition } = findEvent({ tournamentRecord, drawId });
|
|
45682
|
+
const drawMatchUps = allDrawMatchUps({ drawDefinition, matchUpFilters: { matchUpIds: drawMatchUpIds[drawId] } }).matchUps ?? [];
|
|
45683
|
+
for (const matchUp of drawMatchUps) {
|
|
45684
|
+
let modified = false;
|
|
45685
|
+
matchUp.timeItems = (matchUp.timeItems ?? []).filter((timeItem) => {
|
|
45686
|
+
const preserve = timeItem?.itemType &&
|
|
45687
|
+
![ALLOCATE_COURTS, ASSIGN_COURT, ASSIGN_VENUE, SCHEDULED_DATE, SCHEDULED_TIME].includes(timeItem?.itemType);
|
|
45688
|
+
if (!preserve)
|
|
45689
|
+
modified = true;
|
|
45690
|
+
return preserve;
|
|
45691
|
+
});
|
|
45692
|
+
if (modified) {
|
|
45693
|
+
modifyMatchUpNotice({
|
|
45694
|
+
context: 'clear schedules',
|
|
45695
|
+
eventId: event?.eventId,
|
|
45696
|
+
drawDefinition,
|
|
45697
|
+
tournamentId,
|
|
45698
|
+
matchUp,
|
|
45699
|
+
});
|
|
45700
|
+
clearedScheduleCount += 1;
|
|
45701
|
+
}
|
|
45556
45702
|
}
|
|
45557
45703
|
}
|
|
45558
45704
|
return { ...SUCCESS, clearedScheduleCount };
|
|
@@ -50684,73 +50830,6 @@ var mutate$4 = {
|
|
|
50684
50830
|
unPublishOrderOfPlay: unPublishOrderOfPlay
|
|
50685
50831
|
};
|
|
50686
50832
|
|
|
50687
|
-
function getAllEventData({ tournamentRecord, policyDefinitions }) {
|
|
50688
|
-
if (!tournamentRecord)
|
|
50689
|
-
return { error: MISSING_TOURNAMENT_RECORD };
|
|
50690
|
-
const events = tournamentRecord.events || [];
|
|
50691
|
-
const tournamentParticipants = tournamentRecord?.participants || [];
|
|
50692
|
-
const { tournamentInfo } = getTournamentInfo({ tournamentRecord });
|
|
50693
|
-
const { venues: venuesData } = getVenuesAndCourts({
|
|
50694
|
-
tournamentRecord,
|
|
50695
|
-
});
|
|
50696
|
-
const eventsData = events.map((event) => {
|
|
50697
|
-
const { eventId } = event;
|
|
50698
|
-
const eventInfo = extractEventInfo({ event }).eventInfo;
|
|
50699
|
-
const scheduleTiming = getScheduleTiming({
|
|
50700
|
-
tournamentRecord,
|
|
50701
|
-
event,
|
|
50702
|
-
}).scheduleTiming;
|
|
50703
|
-
const drawsData = (event.drawDefinitions || []).map((drawDefinition) => {
|
|
50704
|
-
const drawInfo = (({ drawId, drawName, matchUpFormat, updatedAt }) => ({
|
|
50705
|
-
matchUpFormat,
|
|
50706
|
-
updatedAt,
|
|
50707
|
-
drawName,
|
|
50708
|
-
drawId,
|
|
50709
|
-
}))(drawDefinition);
|
|
50710
|
-
const { abandonedMatchUps, completedMatchUps, upcomingMatchUps, pendingMatchUps } = getDrawMatchUps({
|
|
50711
|
-
requireParticipants: true,
|
|
50712
|
-
tournamentParticipants,
|
|
50713
|
-
context: { eventId },
|
|
50714
|
-
policyDefinitions,
|
|
50715
|
-
tournamentRecord,
|
|
50716
|
-
inContext: true,
|
|
50717
|
-
scheduleTiming,
|
|
50718
|
-
drawDefinition,
|
|
50719
|
-
event,
|
|
50720
|
-
});
|
|
50721
|
-
return {
|
|
50722
|
-
drawInfo,
|
|
50723
|
-
matchUps: {
|
|
50724
|
-
abandonedMatchUps,
|
|
50725
|
-
completedMatchUps,
|
|
50726
|
-
upcomingMatchUps,
|
|
50727
|
-
pendingMatchUps,
|
|
50728
|
-
},
|
|
50729
|
-
};
|
|
50730
|
-
});
|
|
50731
|
-
const publish = getEventPublishStatus({ event });
|
|
50732
|
-
Object.assign(eventInfo, {
|
|
50733
|
-
drawsData,
|
|
50734
|
-
publish,
|
|
50735
|
-
});
|
|
50736
|
-
return eventInfo;
|
|
50737
|
-
});
|
|
50738
|
-
const allEventData = { tournamentInfo, venuesData, eventsData };
|
|
50739
|
-
return { allEventData };
|
|
50740
|
-
}
|
|
50741
|
-
|
|
50742
|
-
var query = {
|
|
50743
|
-
__proto__: null,
|
|
50744
|
-
bulkUpdatePublishedEventIds: bulkUpdatePublishedEventIds,
|
|
50745
|
-
getAllEventData: getAllEventData,
|
|
50746
|
-
getCourtInfo: getCourtInfo,
|
|
50747
|
-
getDrawData: getDrawData,
|
|
50748
|
-
getEventData: getEventData,
|
|
50749
|
-
getEventPublishStatus: getEventPublishStatus,
|
|
50750
|
-
getPublishState: getPublishState,
|
|
50751
|
-
getVenueData: getVenueData
|
|
50752
|
-
};
|
|
50753
|
-
|
|
50754
50833
|
var index$7 = {
|
|
50755
50834
|
__proto__: null,
|
|
50756
50835
|
bulkUpdatePublishedEventIds: bulkUpdatePublishedEventIds,
|
|
@@ -50765,7 +50844,7 @@ var index$7 = {
|
|
|
50765
50844
|
publishEvent: publishEvent,
|
|
50766
50845
|
publishEventSeeding: publishEventSeeding,
|
|
50767
50846
|
publishOrderOfPlay: publishOrderOfPlay,
|
|
50768
|
-
query: query,
|
|
50847
|
+
query: query$7,
|
|
50769
50848
|
setEventDisplay: setEventDisplay,
|
|
50770
50849
|
unPublishEvent: unPublishEvent,
|
|
50771
50850
|
unPublishEventSeeding: unPublishEventSeeding,
|
|
@@ -52663,7 +52742,7 @@ var index$5 = {
|
|
|
52663
52742
|
proAutoSchedule: proAutoSchedule,
|
|
52664
52743
|
proConflicts: proConflicts,
|
|
52665
52744
|
publicFindCourt: publicFindCourt,
|
|
52666
|
-
query: query$
|
|
52745
|
+
query: query$6,
|
|
52667
52746
|
removeEventMatchUpFormatTiming: removeEventMatchUpFormatTiming,
|
|
52668
52747
|
removeMatchUpCourtAssignment: removeMatchUpCourtAssignment,
|
|
52669
52748
|
reorderUpcomingMatchUps: reorderUpcomingMatchUps,
|
|
@@ -54490,13 +54569,18 @@ function updateCourtAvailability({ tournamentRecord }) {
|
|
|
54490
54569
|
return { ...SUCCESS };
|
|
54491
54570
|
}
|
|
54492
54571
|
|
|
54493
|
-
function setTournamentDates(
|
|
54494
|
-
|
|
54495
|
-
|
|
54496
|
-
|
|
54497
|
-
|
|
54498
|
-
|
|
54499
|
-
|
|
54572
|
+
function setTournamentDates(params) {
|
|
54573
|
+
const { tournamentRecord, startDate, endDate } = params;
|
|
54574
|
+
const paramsCheck = checkRequiredParameters(params, [
|
|
54575
|
+
{ tournamentRecord: true },
|
|
54576
|
+
{
|
|
54577
|
+
[ANY_OF]: { startDate: false, endDate: false },
|
|
54578
|
+
[INVALID]: INVALID_DATE,
|
|
54579
|
+
[VALIDATE]: (value) => dateValidation.test(value),
|
|
54580
|
+
},
|
|
54581
|
+
]);
|
|
54582
|
+
if (paramsCheck.error)
|
|
54583
|
+
return paramsCheck;
|
|
54500
54584
|
if (endDate && startDate && new Date(endDate) < new Date(startDate))
|
|
54501
54585
|
return { error: INVALID_VALUES };
|
|
54502
54586
|
let checkScheduling;
|
|
@@ -54504,10 +54588,20 @@ function setTournamentDates({ tournamentRecord, startDate, endDate }) {
|
|
|
54504
54588
|
(endDate && tournamentRecord.endDate && new Date(endDate) < new Date(tournamentRecord.endDate))) {
|
|
54505
54589
|
checkScheduling = true;
|
|
54506
54590
|
}
|
|
54591
|
+
const initialDateRange = generateDateRange(tournamentRecord.startDate, tournamentRecord.endDate);
|
|
54507
54592
|
if (startDate)
|
|
54508
54593
|
tournamentRecord.startDate = startDate;
|
|
54509
54594
|
if (endDate)
|
|
54510
54595
|
tournamentRecord.endDate = endDate;
|
|
54596
|
+
const resultingDateRange = generateDateRange(tournamentRecord.startDate, tournamentRecord.endDate);
|
|
54597
|
+
const datesRemoved = initialDateRange.filter((date) => !resultingDateRange.includes(date));
|
|
54598
|
+
const datesAdded = resultingDateRange.filter((date) => !initialDateRange.includes(date));
|
|
54599
|
+
for (const event of tournamentRecord.events ?? []) {
|
|
54600
|
+
if (startDate && event.startDate && new Date(startDate) > new Date(event.startDate))
|
|
54601
|
+
event.startDate = startDate;
|
|
54602
|
+
if (endDate && event.endDate && new Date(endDate) < new Date(event.endDate))
|
|
54603
|
+
event.endDate = endDate;
|
|
54604
|
+
}
|
|
54511
54605
|
if (startDate && tournamentRecord.endDate && new Date(startDate) > new Date(tournamentRecord.endDate)) {
|
|
54512
54606
|
tournamentRecord.endDate = startDate;
|
|
54513
54607
|
}
|
|
@@ -54520,7 +54614,7 @@ function setTournamentDates({ tournamentRecord, startDate, endDate }) {
|
|
|
54520
54614
|
topic: MODIFY_TOURNAMENT_DETAIL,
|
|
54521
54615
|
payload: { startDate, endDate },
|
|
54522
54616
|
});
|
|
54523
|
-
return { ...SUCCESS, unscheduledMatchUpIds };
|
|
54617
|
+
return { ...SUCCESS, unscheduledMatchUpIds, datesAdded, datesRemoved };
|
|
54524
54618
|
}
|
|
54525
54619
|
function setTournamentStartDate({ tournamentRecord, startDate }) {
|
|
54526
54620
|
return setTournamentDates({ tournamentRecord, startDate });
|
|
@@ -55333,7 +55427,7 @@ var index$2 = {
|
|
|
55333
55427
|
modifyVenue: modifyVenue,
|
|
55334
55428
|
mutate: mutate,
|
|
55335
55429
|
publicFindVenue: publicFindVenue,
|
|
55336
|
-
query: query$
|
|
55430
|
+
query: query$3
|
|
55337
55431
|
};
|
|
55338
55432
|
|
|
55339
55433
|
var governors = {
|
|
@@ -55820,7 +55914,7 @@ function notifySubscribers(params) {
|
|
|
55820
55914
|
const { topics } = getTopics();
|
|
55821
55915
|
for (const topic of [...topics].sort(topicSort)) {
|
|
55822
55916
|
const notices = getNotices({ topic });
|
|
55823
|
-
if (notices)
|
|
55917
|
+
if (notices?.length)
|
|
55824
55918
|
callListener({ topic, notices });
|
|
55825
55919
|
}
|
|
55826
55920
|
if (mutationStatus && timeStamp && topics.includes(MUTATIONS)) {
|
|
@@ -56005,25 +56099,11 @@ async function asyncEngineInvoke(engine, args) {
|
|
|
56005
56099
|
return result;
|
|
56006
56100
|
}
|
|
56007
56101
|
|
|
56008
|
-
function
|
|
56009
|
-
|
|
56010
|
-
|
|
56011
|
-
|
|
56012
|
-
const methods =
|
|
56013
|
-
const attrWalker = (obj, depth = 0) => {
|
|
56014
|
-
Object.keys(obj).forEach((key) => {
|
|
56015
|
-
if (isFunction(obj[key])) {
|
|
56016
|
-
methods[key] = obj[key];
|
|
56017
|
-
}
|
|
56018
|
-
else if (isObject(obj[key]) &&
|
|
56019
|
-
(traverse === true || collectionFilter?.includes(key)) &&
|
|
56020
|
-
(maxDepth === undefined || depth < maxDepth)) {
|
|
56021
|
-
attrWalker(obj[key], depth + 1);
|
|
56022
|
-
}
|
|
56023
|
-
});
|
|
56024
|
-
};
|
|
56025
|
-
attrWalker(submittedMethods);
|
|
56026
|
-
setMethods(methods);
|
|
56102
|
+
function methodImporter(engine, engineInvoke, submittedMethods, traverse, maxDepth, global) {
|
|
56103
|
+
const setResult = setStateMethods(submittedMethods, traverse, maxDepth, global);
|
|
56104
|
+
if (setResult.error)
|
|
56105
|
+
return setResult;
|
|
56106
|
+
const methods = setResult.methods ?? [];
|
|
56027
56107
|
const methodNames = Object.keys(methods).filter((key) => isFunction(methods[key]));
|
|
56028
56108
|
methodNames.forEach((methodName) => {
|
|
56029
56109
|
engine[methodName] = (params) => {
|
|
@@ -56065,7 +56145,7 @@ function processResult(engine, result) {
|
|
|
56065
56145
|
}
|
|
56066
56146
|
|
|
56067
56147
|
function engineStart(engine, engineInvoke) {
|
|
56068
|
-
engine.importMethods = (methods, collections, depth) =>
|
|
56148
|
+
engine.importMethods = (methods, collections, depth, global) => methodImporter(engine, engineInvoke, methods, collections, depth, global);
|
|
56069
56149
|
engine.getTournament = (params) => getTournament(params);
|
|
56070
56150
|
engine.getState = (params) => getState$1({
|
|
56071
56151
|
convertExtensions: params?.convertExtensions,
|