tods-competition-factory
Version:
Create and mutate TODS compliant tournament objects
1,688 lines (1,673 loc) • 2.43 MB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function factoryVersion() {
return '2.2.29';
}
const SINGLES_MATCHUP = 'SINGLES';
const SINGLES$1 = 'SINGLES';
const DOUBLES_MATCHUP = 'DOUBLES';
const DOUBLES$1 = 'DOUBLES';
const TEAM_MATCHUP = 'TEAM';
const TEAM$2 = 'TEAM';
const matchUpTypes = {
SINGLES_MATCHUP,
SINGLES: SINGLES$1,
DOUBLES_MATCHUP,
DOUBLES: DOUBLES$1,
TEAM_MATCHUP,
TEAM: TEAM$2,
};
const matchUpEventTypeMap = {
[SINGLES$1]: [SINGLES$1, 'S'],
[DOUBLES$1]: [DOUBLES$1, 'D'],
[TEAM$2]: [TEAM$2, 'T'],
S: [SINGLES$1, 'S'],
D: [DOUBLES$1, 'D'],
T: [TEAM$2, 'T'],
};
function numericSort(a, b) {
return (a ?? 0) - (b ?? 0);
}
function ensureInt(val) {
if (typeof val === 'number')
return parseInt(val.toString());
if (typeof val === 'string')
return parseInt(val);
return 0;
}
function isPowerOf2(n) {
if (isNaN(n))
return false;
return n && (n & (n - 1)) === 0;
}
function median(arr) {
if (!arr.length)
return undefined;
const s = [...arr].sort(numericSort);
const mid = Math.floor(s.length / 2);
return s.length % 2 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
}
function deriveExponent(n) {
if (!isPowerOf2(n))
return false;
let m = n;
let i = 1;
while (m !== 2) {
i += 1;
m = m / 2;
}
return i;
}
function coerceEven(n) {
return isNaN(n) ? 0 : (n % 2 && n + 1) || n;
}
function nearestPowerOf2(val) {
return Math.pow(2, Math.round(Math.log(val) / Math.log(2)));
}
function isNumeric(value) {
return !isNaN(parseFloat(value));
}
function isOdd(num) {
const numInt = ensureInt(num);
if (isNaN(numInt))
return undefined;
if (numInt === 0)
return false;
return (numInt & -numInt) === 1;
}
function nextPowerOf2(n) {
if (isNaN(n))
return false;
while (!isPowerOf2(n)) {
n++;
}
return n;
}
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function isConvertableInteger(n) {
return Number.isSafeInteger(typeof n === 'string' ? +n : n);
}
function weightedRandom(max = 1, weight = 3, round = true) {
let num = 0;
for (let i = 0; i < weight; i++) {
num += Math.random() * (max / weight);
}
return round && max > 1 ? Math.round(num) : num;
}
function stepRound(value, step) {
step || (step = 1.0);
const inv = 1.0 / step;
return Math.round(value * inv) / inv;
}
function skewedDistribution(min, max, skew, step, significantDecimals = 2) {
const u = 1 - Math.random();
const v = 1 - Math.random();
let num = Math.sqrt(-2 * Math.log(u)) * Math.cos(2.0 * Math.PI * v);
num = num / 10.0 + 0.5;
if (num > 1 || num < 0) {
num = skewedDistribution(min, max, skew);
}
else {
num = Math.pow(num, skew);
num *= max - min;
num += min;
}
if (step)
num = stepRound(num, step);
return parseFloat(num.toFixed(significantDecimals));
}
function fixedDecimals(value, to = 2) {
return parseFloat(Number(Math.round(value * 1000) / 1000).toFixed(to));
}
function unique(arr) {
if (!Array.isArray(arr))
return [];
return arr?.filter((item, i, s) => s.lastIndexOf(item) === i);
}
function noNulls(arr) {
if (!Array.isArray(arr))
return arr;
return arr?.map((item) => (item === null ? undefined : item));
}
function shuffleArray(arr) {
if (!Array.isArray(arr))
return [];
return arr
.map((a) => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map((a) => a[1]);
}
function numericSortValue(v) {
return isConvertableInteger(v) ? v : Infinity;
}
function instanceCount(values) {
if (!Array.isArray(values))
return {};
return values.reduce((a, c) => {
if (!a[c])
a[c] = 0;
a[c]++;
return a;
}, {});
}
function countValues(values) {
return groupValues(instanceCount(values));
}
function groupValues(obj) {
return Object.keys(obj).reduce((p, c) => {
const value = obj[c];
if (p[value]) {
p[value].push(c);
}
else {
p[value] = [c];
}
return p;
}, {});
}
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
function uniqueValues(arr) {
return arr.filter(onlyUnique);
}
function randomPop(array) {
return Array.isArray(array) && array.length
? array.splice(Math.floor(Math.random() * array.length), 1)[0]
: undefined;
}
function randomMember(arr) {
const index = Math.floor(Math.random() * arr.length);
return arr[index];
}
function generateRange(start, end) {
return Array.from({ length: end - start }, (_, k) => k + start);
}
function arrayIndices(val, arr) {
return arr.reduce((a, e, i) => {
if (e === val)
a.push(i);
return a;
}, []);
}
function intersection(a, b) {
if (!Array.isArray(a) || !Array.isArray(b))
return [];
return a.filter((n) => b.indexOf(n) !== -1).filter((e, i, c) => c.indexOf(e) === i);
}
function difference(a, b) {
if (!Array.isArray(a) || !Array.isArray(b))
return [];
return a.filter((x) => !b.includes(x));
}
function overlap(a, b) {
if (!Array.isArray(a) || !Array.isArray(b))
return false;
return a.some((e) => b.includes(e));
}
function occurrences(val, arr) {
if (!Array.isArray(arr))
return 0;
return (arr.reduce((r, val) => {
r[val] = 1 + r[val] || 1;
return r;
}, {})[val] || 0);
}
function subSort(arr, i, n, sortFx) {
if (!Array.isArray(arr))
return [];
return [].concat(...arr.slice(0, i), ...arr.slice(i, i + n).sort(sortFx), ...arr.slice(i + n, arr.length));
}
function chunkArray(arr, chunksize) {
if (!Array.isArray(arr))
return [];
return arr.reduce((all, one, i) => {
const ch = Math.floor(i / chunksize);
all[ch] = [].concat(all[ch] || [], one);
return all;
}, []);
}
function chunkSizeProfile(arr, [size, ...otherSizes]) {
return arr.length ? [arr.slice(0, size), ...chunkSizeProfile(arr.slice(size), [...otherSizes, size])] : [];
}
function groupConsecutiveNumbers(arr) {
return arr.reduce((result, num) => {
const finalGroup = result[result.length - 1];
if (!finalGroup || finalGroup[finalGroup.length - 1] !== num - 1) {
result.push([]);
}
result[result.length - 1].push(num);
return result;
}, []);
}
function allNumeric$1(arr) {
if (!Array.isArray(arr))
return false;
return arr.reduce((numeric, item) => !isNaN(parseInt(item)) && numeric, true);
}
function noNumeric(arr) {
if (!Array.isArray(arr))
return false;
return arr.reduce((numeric, item) => isNaN(parseInt(item)) && numeric, true);
}
function chunkByNth(arr, chunksCount, shuttle) {
if (!Array.isArray(arr))
return [];
return arr.reduce((chunks, entry, index) => {
const reverseDirection = shuttle ? !!(Math.floor(index / chunksCount) % 2) : false;
const chunkIndex = index % chunksCount;
const directionIndex = reverseDirection ? chunksCount - 1 - chunkIndex : chunkIndex;
if (!chunks[directionIndex])
chunks[directionIndex] = [];
chunks[directionIndex].push(entry);
return chunks;
}, []);
}
function getMissingSequenceNumbers(arr, start = 1) {
if (!Array.isArray(arr) || !arr.every(isConvertableInteger))
return [];
const min = Math.min(...arr, start);
const max = Math.max(...arr);
return generateRange(min, max + 1).filter((n) => !arr.includes(n));
}
function isFunction(obj) {
return typeof obj === 'function';
}
function isString(obj) {
return typeof obj === 'string';
}
function isObject(obj) {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
function objShallowEqual(o1, o2) {
if (!isObject(o1) || !isObject(o2))
return false;
const keys1 = Object.keys(o1);
const keys2 = Object.keys(o2);
if (keys1.length !== keys2.length) {
return false;
}
for (const key of keys1) {
if (o1[key] !== o2[key]) {
return false;
}
}
return true;
}
function createMap(objectArray, attribute) {
if (!Array.isArray(objectArray))
return {};
return Object.assign({}, ...(objectArray ?? [])
.filter(isObject)
.map((obj) => {
return (obj[attribute] && {
[obj[attribute]]: obj,
});
})
.filter(Boolean));
}
const hasAttributeValues = (a) => (o) => Object.keys(a).every((key) => o[key] === a[key]);
function undefinedToNull(obj, shallow) {
if (obj === undefined)
return null;
if (!isObject(obj) || obj === null)
return obj;
const definedKeys = Object.keys(obj);
const notNull = (value) => (value === undefined ? null : value);
return Object.assign({}, ...definedKeys.map((key) => {
return Array.isArray(obj[key])
? {
[key]: shallow ? obj[key] : obj[key].map((m) => undefinedToNull(m)),
}
: { [key]: shallow ? notNull(obj[key]) : undefinedToNull(obj[key]) };
}));
}
function countKeys(o) {
if (Array.isArray(o)) {
return o.length + o.map(countKeys).reduce((a, b) => a + b, 0);
}
else if (isObject(o) && o !== null) {
return (Object.keys(o).length +
Object.keys(o)
.map((k) => countKeys(o[k]))
.reduce((a, b) => a + b, 0));
}
return 0;
}
function generateHashCode(o) {
if (o === null || typeof o !== 'object')
return undefined;
const str = JSON.stringify(o);
const keyCount = countKeys(o);
const charSum = str.split('').reduce((a, b) => a + b.charCodeAt(0), 0);
return [str.length, keyCount, charSum].map((e) => e.toString(36)).join('');
}
function includesMatchUpEventType(types, matchUpEventType) {
if (!Array.isArray(types) || !isString(matchUpEventType))
return false;
return intersection(types, matchUpEventTypeMap[matchUpEventType]).length;
}
const SUCCESS = { success: true };
const ERROR$1 = 'error';
const resultConstants = {
SUCCESS,
ERROR: ERROR$1,
};
function validateCollectionValueProfiles({ collectionValueProfiles, matchUpCount, }) {
const errors = [];
if (!Array.isArray(collectionValueProfiles)) {
errors.push(`collectionValueProfiles is not an array: ${collectionValueProfiles}`);
return { errors };
}
if (collectionValueProfiles.length && collectionValueProfiles.length !== matchUpCount) {
errors.push(`collectionValueProfiles do not align with matchUpsCount`);
return { errors };
}
for (const valueProfile of collectionValueProfiles) {
if (typeof valueProfile !== 'object') {
errors.push(`valueProfile is not type object: ${valueProfile}`);
return { errors };
}
const { matchUpValue, collectionPosition } = valueProfile;
if (typeof matchUpValue !== 'number' ||
typeof collectionPosition !== 'number' ||
collectionPosition > matchUpCount ||
collectionPosition < 1) {
errors.push(`Invalid value profile: value and collectionPosition must be numeric. collectionPosition cannot be greater than matchUpCount`);
return { errors };
}
}
const collectionPositions = collectionValueProfiles.map((valueProfile) => valueProfile.collectionPosition);
if (collectionPositions.length !== unique(collectionPositions).length) {
errors.push('collectionPositions are not unique');
return { errors };
}
return { ...SUCCESS };
}
const ANACHRONISM = {
message: 'Chronological error; time violation.',
code: 'ANACHRONISM',
};
const DUPLICATE_ENTRY = {
message: 'Duplicate entry',
code: 'DUPLICATE_ENTRY',
};
const CANNOT_REMOVE_MAIN_STRUCTURE = {
message: 'Cannot remove main structure',
code: 'ERR_CANNOT_REMOVE_MAIN_STRUCTURE',
};
const INVALID_RECORDS = {
message: 'records must be an object with tournamentId keys',
code: 'ERR_INVALID_TOURNAMENTS',
};
const MISSING_TOURNAMENT_RECORDS = {
message: 'Missing tournamentRecords',
code: 'ERR_MISSING_TOURNAMENTS',
};
const MISSING_TOURNAMENT_RECORD = {
message: 'Missing tournamentRecord',
code: 'ERR_MISSING_TOURNAMENT',
};
const INVALID_TOURNAMENT_RECORD = {
message: 'Invalid tournamentRecord',
code: 'ERR_INVALID_TOURNAMENT',
};
const MISSING_TOURNAMENT_ID = {
message: 'Missing tournamentId',
code: 'ERR_MISSING_TOURNAMENT_ID',
};
const INVALID_DRAW_DEFINITION = {
message: 'Invalid drawDefinition',
code: 'ERR_INVALID_DRAWDEF',
};
const MISSING_DRAW_DEFINITION = {
message: 'Missing drawDefinition',
code: 'ERR_MISSING_DRAWDEF',
};
const EXISTING_DRAW_DEFINITIONS = {
message: 'Existing drawDefinition(s)',
code: 'ERR_EXISTING_DRAWDEFS',
};
const DRAW_DEFINITION_NOT_FOUND = {
message: 'drawDefinition not found',
code: 'ERR_NOT_FOUND_DRAWDEF',
};
const INVALID_STRUCTURE = {
message: 'Invalid structure',
code: 'ERR_INVALID_STRUCTURE',
};
const INCOMPLETE_SOURCE_STRUCTURE = {
message: 'Incomplete source structure',
code: 'ERR_INCOMPLETE_STRUCTURE',
};
const INVALID_DRAW_POSITION_FOR_SEEDING = {
message: 'Invalid drawPosition for seedAssignment',
code: 'ERR_INVALID_SEEDING_POSITION',
};
const DRAW_POSITION_ASSIGNED = {
message: 'drawPosition already assigned',
code: 'ERR_EXISTING_POSITION_ASSIGNMENT',
};
const SCHEDULE_NOT_CLEARED = {
message: 'Schedule not cleared',
code: 'ERR_UNCHANGED_SCHEDULE_NOT_CLEARED',
};
const DRAW_POSITION_NOT_CLEARED = {
message: 'drawPosition not cleared',
code: 'ERR_FAILURE_POSITION_NOT_CLEARED',
};
const DRAW_POSITION_NOT_FOUND = {
message: 'drawPosition not found',
code: 'ERR_NOT_FOUND_DRAW_POSITION',
};
const UNRECOGNIZED_DRAW_TYPE = {
message: 'Unrecognized drawType',
code: 'ERR_UNRECOGNIZED_DRAW_TYPE',
};
const MISSING_DRAW_POSITIONS = {
message: 'Missing drawPositions',
code: 'ERR_MISSING_DRAW_POSITIONS',
};
const DRAW_POSITION_ACTIVE = {
message: 'drawPosition is active',
code: 'ERR_ACTIVE_DRAW_POSITION',
};
const DRAW_POSITION_OCCUPIED = {
message: 'drawPosition is occupied',
code: 'ERR_OCCUPIED_DRAW_POSITION',
};
const INVALID_DRAW_POSITION = {
message: 'Invlid drawPosition',
code: 'ERR_INVALID_DRAW_POSITION',
};
const MISSING_DRAW_POSITION = {
message: 'Missing drawPosition',
code: 'ERR_MISSING_DRAW_POSITION',
};
const INVALID_DRAW_TYPE = {
message: 'Invalid drawType',
code: 'ERR_INVALID_DRAW_TYPE',
};
const INVALID_DRAW_SIZE = {
message: 'Invalid drawSize',
code: 'ERR_INVALID_DRAW_SIZE',
};
const DRAW_SIZE_MISMATCH = {
message: 'Cannot set drawSize to be less than existing entries',
code: 'ERR_INVALID_DRAW_SIZE_MISMATCH',
};
const MISSING_DRAW_SIZE = {
message: 'Missing drawSize',
code: 'ERR_MISSING_DRAW_SIZE',
};
const MISSING_DRAW_ID = {
message: 'Missing drawId',
code: 'ERR_MISSING_DRAW_ID',
};
const DRAW_ID_EXISTS = {
message: 'drawId exists',
code: 'ERR_EXISTING_DRAW_ID',
};
const INVALID_PARTICIPANT_SEEDING = {
message: 'participantId cannot be assigned to multiple seedNumbers',
code: 'INVALID_PARTICIPANT_SEEDING',
};
const SEEDSCOUNT_GREATER_THAN_DRAW_SIZE = {
message: 'seedsCount greater than drawSize',
code: 'ERR_INVALID_SEED_COUNT',
};
const MISSING_SEEDCOUNT_THRESHOLDS = {
message: 'Missing seedCountThresholds',
code: 'ERR_MISSING_SEED_COUNT_THRESHOLD',
};
const INVALID_ACTION = {
message: 'Invalid action',
code: 'ERR_INVALID_ACTION',
};
const INVALID_ASSIGNMENT = {
message: 'Invalid assignment',
code: 'ERR_INVALID_ASSIGNMENT',
};
const MISSING_SEED_ASSIGNMENTS = {
message: 'Missing seedAssignments',
code: 'ERR_MISSING_SEED_ASSIGNMENTS',
};
const INVALID_SEED_NUMBER = {
message: 'Invalid seedNumber',
code: 'ERR_INVALID_SEED_NUMBER',
};
const INVALID_SEED_POSITION = {
message: 'Invalid seedPosition',
code: 'ERR_INVALID_SEED_POSITION',
};
const MISSING_TARGET_LINK = {
message: 'Missing targetLink',
code: 'ERR_MISSING_LINK_TARGET',
};
const EXISTING_ROUND = {
message: 'Existing round',
code: 'ERR_EXISTING_ROUND',
};
const MISSING_ROUND_NUMBER = {
message: 'Missing roundNumber',
code: 'ERR_MISSING_ROUND_NUMBER',
};
const MISSING_STRUCTURE_ID = {
message: 'Missing structureId',
code: 'ERR_MISSING_STRUCTURE_ID',
};
const STRUCTURE_NOT_FOUND = {
message: 'structure not found',
code: 'ERR_NOT_FOUND_STRUCTURE',
};
const MISSING_STRUCTURES = {
message: 'Missing structures',
code: 'ERR_MISSING_STRUCTURES',
};
const MISSING_STRUCTURE = {
message: 'Missing structure',
code: 'ERR_MISSING_STRUCTURE',
};
const MISSING_MAIN_STRUCTURE = {
message: 'Missing MAIN structure',
code: 'ERR_MISSING_MAIN_STRUCTURE',
};
const UNLINKED_STRUCTURES = {
message: 'drawDefinition contains unlinked structures',
code: 'ERR_MISSING_STRUCTURE_LINKS',
};
const INVALID_EVENT_TYPE = {
message: 'Invalid eventType',
code: 'ERR_INVALID_EVENT_TYPE',
};
const MISSING_EVENT = {
message: 'Missing event / eventId',
code: 'ERR_MISSING_EVENT_ID',
};
const EVENT_NOT_FOUND = {
message: 'Event not found',
code: 'ERR_NOT_FOUND_EVENT',
};
const EVENT_EXISTS = {
message: 'Event exists',
code: 'ERR_EXISTING_EVENT',
};
const MISSING_ENTRIES = {
message: 'Missing entries',
code: 'ERR_MISSING_ENTRIES',
};
const INVALID_ENTRIES = {
message: 'Invalid entries',
code: 'ERR_INVALID_ENTRIES',
};
const MISSING_ASSIGNMENTS = {
message: 'Missing assignments',
code: 'ERR_MISSING_ASSIGNMENTS',
};
const MISSING_STAGE = {
message: 'Missing stage',
code: 'ERR_MISSING_STAGE',
};
const INVALID_STAGE = {
message: 'Invalid stage',
code: 'ERR_INVALID_STAGE',
};
const STAGE_SEQUENCE_LIMIT = {
message: 'stageSequence limit',
code: 'ERR_LIMIT_STAGE_SEQUENCE',
};
const MISSING_POSITION_ASSIGNMENTS = {
message: 'Missing positionAssignments',
code: 'ERR_MISSING_POSITION_ASSIGNMENTS',
};
const INVALID_MATCHUP_STATUS_BYE = {
message: 'Cannot Assign BYE status if no assignment: { bye: true }',
code: 'ERR_UNCHANGED_CANNOT_ASSIGN_BYE',
};
const UNRECOGNIZED_MATCHUP_STATUS = {
message: 'Unrecognized matchUpStatus',
code: 'ERR_UNRECOGNIZED_MATCHUP_STATUS',
};
const UNRECOGNIZED_MATCHUP_FORMAT = {
message: 'Unrecognized matchUpFormat',
code: 'ERR_UNRECOGNIZED_MATCHUP_FORMAT',
};
const INCOMPATIBLE_MATCHUP_STATUS = {
message: 'Incompatible matchUpStatus',
code: 'ERR_INCOMPATIBLE_MATCHUP_STATUS',
};
const INVALID_MATCHUP_STATUS = {
message: 'Invalid matchUpStatus',
code: 'ERR_INVALID_MATCHUP_STATUS',
};
const INVALID_TIE_FORMAT = {
message: 'Invalid tieFormat',
code: 'ERR_INVALID_TIE_FORMAT',
};
const INVALID_MATCHUP_FORMAT = {
message: 'Invalid matchUpFormat',
code: 'ERR_INVALID_MATCHUP_FORMAT',
};
const MISSING_MATCHUP_FORMAT = {
message: 'Missing matchUpFormat',
code: 'ERR_MISSING_MATCHUP_FORMAT',
};
const MISSING_COLLECTION_DEFINITION = {
message: 'Missing collectionDefinition',
code: 'ERR_MISSING_COLLECTION_DEFINITION',
};
const MISSING_TIE_FORMAT = {
message: 'Missing tieFormat',
code: 'ERR_MISSING_TIE_FORMAT',
};
const MISSING_MATCHUP_ID = {
message: 'Missing matchUpId',
code: 'ERR_MISSING_MATCHUP_ID',
};
const MISSING_MATCHUP_IDS = {
message: 'Missing matchUpIds',
code: 'ERR_MISSING_MATCHUP_IDS',
};
const MATCHUP_NOT_FOUND = {
message: 'matchUp not found',
code: 'ERR_NOT_FOUND_MATCHUP',
};
const MISSING_MATCHUPS = {
message: 'Missing matchUps',
code: 'ERR_MISSING_MATCHUPS',
};
const MISSING_MATCHUP = {
message: 'Missing matchUp',
code: 'ERR_MISSING_MATCHUP',
};
const INVALID_MATCHUP = {
message: 'Invalid matchUp',
code: 'ERR_INVALID_MATCHUP',
};
const MISSING_POLICY_TYPE = {
message: 'Missing policyType',
code: 'ERR_MISSING_POLICY_TYPE',
};
const MISSING_POLICY_DEFINITION = {
message: 'Missing policyDefinitions',
code: 'ERR_MISSING_POLICY_DEFINITIONS',
};
const MISSING_SEEDING_POLICY = {
message: 'Missing seeding policy',
code: 'ERR_MISSING_POLICY_SEEDING',
};
const MISSING_AVOIDANCE_POLICY = {
message: 'Missing avoidance policy',
code: 'ERR_MISSING_POLICY_AVOIDANCE',
};
const MISSING_POLICY_ATTRIBUTES = {
message: 'Missing policy attributes',
code: 'ERR_MISSING_POLICY_ATTRIBUTES',
};
const INVALID_POLICY_DEFINITION = {
message: 'Invalid policyDefinitions',
code: 'ERR_INVALID_POLICY_DEFINITIONS',
};
const EXISTING_POLICY_TYPE = {
message: 'existing policyType',
code: 'ERR_EXISTING_POLICY_TYPE',
};
const POLICY_NOT_ATTACHED = {
message: 'Policy not attached',
code: 'ERR_FAILURE_POLICY_NOT_ATTACHED',
};
const POLICY_NOT_FOUND = {
message: 'Policy not found',
code: 'ERR_NOT_FOUND_POLICY',
};
const MISSING_SCORING_POLICY = {
message: 'Missing scoring policy / matchUpFormats',
code: 'ERR_MISSING_POLICY_SCORING_MATCHUP_FORMATS',
};
const INVALID_SIDE_NUMBER = {
message: 'Invalid sideNumber',
code: 'ERR_INVALID_SIDE_NUMBER',
};
const INVALID_SET_NUMBER = {
message: 'Invalid setNumber',
code: 'ERR_INVALID_SET_NUMBER',
};
const MISSING_SET_OBJECT = {
message: 'Missing setObject',
code: 'ERR_MISSING_SET_ATTRIBUTE',
};
const MISSING_SET_NUMBER = {
message: 'Missing setNumber',
code: 'ERR_MISSING_SET_NUMBER',
};
const MISSING_SIDE_NUMBER = {
message: 'Missing sideNumber',
code: 'ERR_MISSING_SIDE_NUMBER',
};
const MISSING_COURT_ID = {
message: 'Missing courtId',
code: 'ERR_MISSING_COURT_ID',
};
const MISSING_VALUE = {
message: 'Missing value',
code: 'ERR_MISSING_VALUE',
};
const MISSING_BIRTH_DATE = {
message: 'Missing birthdate',
code: 'ERR_MISSING_BIRTH_DATE',
};
const MISSING_DATE = {
message: 'Missing date',
code: 'ERR_MISSING_DATE',
};
const NO_VALID_DATES = {
message: 'No valid dates',
code: 'ERR_NO_VALID_DATES',
};
const INVALID_BOOKINGS = {
message: 'Invalid bookings',
code: 'ERR_INVALID_BOOKINGS',
};
const INVALID_DATE_AVAILABILITY = {
message: 'Invalid dateAvailability',
code: 'ERR_INVALID_DATE_AVAILABILITY',
};
const MISSING_DATE_AVAILABILITY = {
message: 'Missing dateAvailability',
code: 'ERR_MISSING_DATE_AVAILABILITY',
};
const INVALID_DATE = {
message: 'Invalid Date',
code: 'ERR_INVALID_DATE',
};
const INVALID_TIME = {
message: 'Invalid time',
code: 'ERR_INVALID_TIME',
};
const INVALID_TOURNAMENT_DATES = {
message: 'Invalid tournament dates',
code: 'ERR_INVALID_DATES_TOURNAMENT',
};
const INVALID_GAME_SCORES = {
message: 'Invalid game scores',
code: 'ERR_INVALID_SCORES_GAME',
};
const INVALID_SCORE = {
message: 'Invalid score',
code: 'ERR_INVALID_SCORE',
};
const INVALID_WINNING_SIDE = {
message: 'Invalid winningSide',
code: 'ERR_INVALID_WINNING_SIDE',
};
const NO_PARTICIPANTS_GENERATED = {
message: 'No participants generated',
code: 'ERR_NO_PARTICIPANTS_GENERATED',
};
const CANNOT_MODIFY_TIEFORMAT = {
message: 'Cannot modify tieFormat',
code: 'ERR_UNCHANGED_CANNOT_MODIFY_TIEFORMAT',
};
const CANNOT_MODIFY_PARTICIPANT_TYPE = {
message: 'Cannot modify participantType',
code: 'ERR_UNCHANGED_CANNOT_MODIFY_PARTICIPANT_TYPE',
};
const CANNOT_REMOVE_PARTICIPANTS = {
message: 'Cannot remove participants',
code: 'ERR_UNCHANGED_CANNOT_REMOVE_PARTICIPANTS',
};
const CATEGORY_MISMATCH = {
message: 'Participant category mismatch',
code: 'ERR_CATEGORY_MISMATCH',
};
const CANNOT_CHANGE_WINNING_SIDE = {
message: 'Cannot change winningSide',
code: 'ERR_UNCHANGED_CANNOT_CHANGE_WINNING_SIDE',
};
const INVALID_PARTICIPANT = {
message: 'Invalid participant',
code: 'ERR_INVALID_PARTICIPANT',
};
const INVALID_PARTICIPANT_ID = {
message: 'Invalid participantId',
code: 'ERR_INVALID_PARTICIPANT_ID',
};
const INVALID_PARTICIPANT_IDS = {
message: 'Invalid participantIds',
code: 'ERR_INVALID_PARTICIPANT_IDS',
};
const INVALID_PARTICIPANT_ROLE = {
message: 'Invalid participantRole',
code: 'ERR_INVALID_PARTICIPANT_ROLE',
};
const INVALID_PARTICIPANT_TYPE = {
message: 'Invalid participantType',
code: 'ERR_INVALID_PARTICIPANT_TYPE',
};
const MISSING_PARTICIPANT_ROLE = {
message: 'Missing participantRole',
code: 'ERR_MISSING_PARTICIPANT_ROLE',
};
const MISSING_PARTICIPANT = {
message: 'Missing participant',
code: 'ERR_MISSING_PARTICIPANT',
};
const MISSING_PARTICIPANTS = {
message: 'Missing participants',
code: 'ERR_MISSING_PARTICIPANTS',
};
const MISSING_PARTICIPANT_ID = {
message: 'Missing participantId',
code: 'ERR_MISSING_PARTICIPANT_ID',
};
const MISSING_QUALIFIED_PARTICIPANTS = {
message: 'Missing qualified participants',
code: 'ERR_MISSING_QUALIFIED_PARTICIPANTS',
};
const PARTICIPANT_NOT_FOUND = {
message: 'Participant Not Found',
code: 'ERR_NOT_FOUND_PARTICIPANT',
};
const PARTICIPANT_ID_EXISTS = {
message: 'participantId exists',
code: 'ERR_EXISTING_PARTICIPANT_ID',
};
const PARTICIPANT_PAIR_EXISTS = {
message: 'participant pair exists',
code: 'ERR_EXISTING_PARTICIPANT_PAIR',
};
const NO_PARTICIPANT_REMOVED = {
message: 'No participant removed',
code: 'ERR_UNCHANGED_NO_PARTICIPANT_REMOVED',
};
const MISSING_PARTICIPANT_IDS = {
message: 'Missing participantIds',
code: 'ERR_MISSING_PARTICIPANT_IDS',
};
const MISSING_PARTICIPANT_COUNT = {
message: 'Missing participantsCount',
code: 'ERR_MISSING_PARTICIPANT_COUNT',
};
const PARTICIPANT_NOT_CHECKED_IN = {
message: 'Participant not checked in',
code: 'ERR_UNCHANGED_PARTICIPANT_NOT_CHECKED_IN',
};
const MISSING_PERSON_DETAILS = {
message: 'Missing person details',
code: 'ERR_MISSING_PERSON_DETAILS',
};
const EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT = {
message: 'Existing participant drawPosition assignment',
code: 'ERR_EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT',
};
const EXISTING_PARTICIPANT = {
message: 'Existing participant',
code: 'ERR_EXISTING_PARTICIPANT',
};
const PARTICIPANT_COUNT_EXCEEDS_DRAW_SIZE = {
message: 'participantsCount exceeds drawSize',
code: 'ERR_INVALID_PARTICIPANT_COUNT',
};
const INVALID_ENTRY_STATUS = {
message: 'Invalid entry status',
code: 'ERR_INVALID_ENTRY_STATUS',
};
const PARTICIPANT_ENTRY_NOT_FOUND = {
message: 'Participant Entry Not Found',
code: 'ERR_NOT_FOUND_PARTICIPANT_ENTRY',
};
const PARTICIPANT_NOT_ENTERED_IN_STAGE = {
message: 'Participant not entered in stage',
code: 'ERR_UNCHANGED_PARTICIPANT_NOT_ENTERED',
};
const PARTICIPANT_NOT_FOUND_IN_STAGE = {
message: 'Participant not found in stageSequence',
code: 'ERR_NOT_FOUND_PARTICIPANT_IN_STAGE',
};
const ENTRY_STATUS_NOT_ALLOWED_IN_STAGE = {
message: 'entryStatus not allowed in stage',
code: 'ERR_INVALID_ENTRY_STATUS_IN_STAGE',
};
const ENTRY_STATUS_NOT_ALLOWED_FOR_EVENT = {
message: 'entryStatus not allowed for event',
code: 'ERR_INVALID_ENTRY_STATUS_IN_EVENT',
};
const NO_STAGE_SPACE_AVAILABLE_FOR_ENTRY_STATUS = {
message: 'No stage space available for entryStatus',
code: 'ERR_UNCHANGED_NO_AVAILABLE_STAGE_SPACE',
};
const NO_DRAW_POSITIONS_AVAILABLE_FOR_QUALIFIERS = {
message: 'Insufficient drawPositions to accommodate qualifiers',
code: 'ERR_UNCHANGED_NO_DRAW_POSITIONS_FOR_QUALIFIERS',
};
const INSUFFICIENT_DRAW_POSITIONS = {
message: 'Insufficient drawPositions to accommodate entries',
code: 'ERR_INSUFFICIENT_DRAW_POSITIONS',
};
const MISSING_PENALTY_TYPE = {
message: 'Missing penaltyType',
code: 'ERR_MISSING_PENALTY_TYPE',
};
const MISSING_PENALTY_ID = {
message: 'Missing penaltyId',
code: 'ERR_MISSING_PENALTY_ID',
};
const PENALTY_NOT_FOUND = {
message: 'Penalty not found',
code: 'ERR_NOT_FOUND_PENALTY',
};
const MISSING_COURTS_INFO = {
message: 'Missing courtsCount/courtNames',
code: 'ERR_MISSING_COURTS_INFO',
};
const COURT_NOT_FOUND = {
message: 'Court not found',
code: 'ERR_NOT_FOUND_COURT',
};
const COURT_EXISTS = {
message: 'Court exists',
code: 'ERR_EXISTING_COURT',
};
const VENUE_EXISTS = {
message: 'Venue exists',
code: 'ERR_EXISTING_VENUE',
};
const VENUE_NOT_FOUND = {
message: 'Venue not found',
code: 'ERR_NOT_FOUND_VENUE',
};
const MISSING_VENUE_ID = {
message: 'Missing venueId',
code: 'ERR_MISSING_VENUE_ID',
};
const INVALID_END_TIME = {
message: 'Invalid endTime',
code: 'ERR_INVALID_END_TIME',
};
const EXISTING_END_TIME = {
message: 'Existing endTime',
code: 'ERR_EXISTING_END_TIME',
};
const INVALID_STOP_TIME = {
message: 'Invalid stopTime',
code: 'ERR_INVALID_STOP_TIME',
};
const INVALID_START_TIME = {
message: 'Invalid startTime',
code: 'ERR_INVALID_START_TIME',
};
const INVALID_RESUME_TIME = {
message: 'Invalid resumeTime',
code: 'ERR_INVALID_RESUME_TIME',
};
const INVALID_TIME_ITEM = {
message: 'Invalid timeItem',
code: 'ERR_INVALID_TIME_ITEMS',
};
const MISSING_ASYNC_STATE_PROVIDER = {
message: 'Missing async state provider',
code: 'ERR_MISSING_ASYNC_STATE_PROVIDER',
};
const MISSING_TIME_ITEM = {
message: 'Missing timeItem',
code: 'ERR_MISSING_TIME_ITEM',
};
const MISSING_TIME_ITEMS = {
message: 'Missing timeItems',
code: 'ERR_MISSING_TIME_ITEMS',
};
const MISSING_CONTEXT = {
message: 'Missing context',
code: 'ERR_MISSING_CONTEXT',
};
const MISSING_SCHEDULE = {
message: 'Missing schedule',
code: 'ERR_MISSING_SCHEDULE',
};
const INVALID_SCALE_ITEM = {
message: 'Invalid scaleItem',
code: 'ERR_INVALID_SCALE_ITEM',
};
const MODIFICATIONS_FAILED = {
message: 'Modifications failed',
code: 'ERR_FAILURE_MODIFICATIONS',
};
const NO_MODIFICATIONS_APPLIED = {
message: 'No modifications applied',
code: 'ERR_UNCHANGED_NO_MODIFICATIONS_APPLIED',
};
const UNABLE_TO_ASSIGN_COURT = {
message: 'Unable to assign court',
code: 'ERR_UNCHANGED_COURT_NOT_ASSIGNED',
};
const NO_CANDIDATES = {
message: 'No Candidates',
code: 'ERR_UNCHANGED_NO_CANDIDATES',
};
const INVALID_CONFIGURATION = {
message: 'Invalid configuration',
code: 'ERR_INVALID_CONFIG',
};
const INVALID_COLLECTION_DEFINITION = {
message: 'Invalid collectionDefinition',
code: 'ERR_INVALID_COLLECTION_DEFINITION',
};
const INVALID_OBJECT = {
message: 'Invalid object',
code: 'ERR_INVALID_OBJECT',
};
const INVALID_GENDER = {
message: 'Invalid gender',
code: 'ERR_INVALID_GENDER',
};
const INVALID_CATEGORY = {
message: 'Invalid category',
code: 'ERR_INVALID_CATEGORY',
};
const INVALID_VALUES = {
message: 'Invalid values',
code: 'ERR_INVALID_VALUES',
};
const DUPLICATE_VALUE = {
message: 'Duplicate value',
code: 'ERR_DUPLICATE_VALUE',
};
const TEAM_NOT_FOUND = {
message: 'Team not found',
code: 'ERR_NOT_FOUND_TEAM',
};
const NO_VALID_ACTIONS = {
message: 'No valid actions',
code: 'ERR_NO_VALID_ACTIONS',
};
const NO_VALID_ATTRIBUTES = {
message: 'No valid attributes',
code: 'ERR_NO_VALID_ATTRIBUTES',
};
const VALUE_UNCHANGED = {
message: 'Value unchanged',
code: 'ABORT_UNCHANGED',
};
const NOT_FOUND = { message: 'Not found', code: 'ERR_NOT_FOUND' };
const NOT_IMPLEMENTED = {
message: 'Not implemented',
code: 'ERR_NOT_IMPLEMENTED',
};
const EXISTING_FLIGHT = {
message: 'Existing flight',
code: 'ERR_EXISTING_FLIGHT',
};
const EXISTING_PROFILE = {
message: 'Existing flight profile',
code: 'ERR_EXISTING_FLIGHT_PROFILE',
};
const EXISTING_OUTCOME = {
message: 'Existing outcome',
code: 'ERR_EXISTING_OUTCOME',
};
const EXISTING_MATCHUP_ID = {
message: 'Existing matchUpId',
code: 'ERR_EXISTING_MATCHUP_ID',
};
const EXISTING_STAGE = {
message: 'Existing stage',
code: 'ERR_EXISTING_STAGE',
};
const EXISTING_STRUCTURE = {
message: 'Existing structure',
code: 'ERR_EXISTING_STRUCTURE',
};
const METHOD_NOT_FOUND = {
message: 'Method not found',
code: 'ERR_NOT_FOUND_METHOD',
};
const SCHEDULED_MATCHUPS = {
message: 'Scheduled matchUps',
code: 'ERR_SCHEDULED_MATCHUPS',
};
const SCORES_PRESENT = {
message: 'Scores present',
code: 'ERR_SCORES_PRESENT',
};
const errorConditionConstants = {
ANACHRONISM,
CANNOT_CHANGE_WINNING_SIDE,
CANNOT_MODIFY_TIEFORMAT,
CANNOT_MODIFY_PARTICIPANT_TYPE,
CANNOT_REMOVE_MAIN_STRUCTURE,
CANNOT_REMOVE_PARTICIPANTS,
CATEGORY_MISMATCH,
COURT_EXISTS,
COURT_NOT_FOUND,
DRAW_DEFINITION_NOT_FOUND,
DRAW_ID_EXISTS,
DRAW_POSITION_ACTIVE,
DRAW_POSITION_ASSIGNED,
DRAW_POSITION_NOT_CLEARED,
DRAW_POSITION_NOT_FOUND,
DRAW_SIZE_MISMATCH,
DUPLICATE_ENTRY,
DUPLICATE_VALUE,
ENTRY_STATUS_NOT_ALLOWED_FOR_EVENT,
ENTRY_STATUS_NOT_ALLOWED_IN_STAGE,
EVENT_EXISTS,
EVENT_NOT_FOUND,
EXISTING_DRAW_DEFINITIONS,
EXISTING_END_TIME,
EXISTING_FLIGHT,
EXISTING_MATCHUP_ID,
EXISTING_OUTCOME,
EXISTING_PARTICIPANT_DRAW_POSITION_ASSIGNMENT,
EXISTING_PARTICIPANT,
EXISTING_POLICY_TYPE,
EXISTING_PROFILE,
EXISTING_ROUND,
EXISTING_STAGE,
EXISTING_STRUCTURE,
INCOMPATIBLE_MATCHUP_STATUS,
INCOMPLETE_SOURCE_STRUCTURE,
INSUFFICIENT_DRAW_POSITIONS,
INVALID_ACTION,
INVALID_ASSIGNMENT,
INVALID_BOOKINGS,
INVALID_CATEGORY,
INVALID_COLLECTION_DEFINITION,
INVALID_CONFIGURATION,
INVALID_DATE_AVAILABILITY,
INVALID_DATE,
INVALID_DRAW_DEFINITION,
INVALID_DRAW_POSITION_FOR_SEEDING,
INVALID_DRAW_POSITION,
INVALID_DRAW_SIZE,
INVALID_END_TIME,
INVALID_ENTRIES,
INVALID_EVENT_TYPE,
INVALID_GAME_SCORES,
INVALID_GENDER,
INVALID_MATCHUP_FORMAT,
INVALID_MATCHUP_STATUS,
INVALID_MATCHUP_STATUS_BYE,
INVALID_MATCHUP,
INVALID_OBJECT,
INVALID_PARTICIPANT_ID,
INVALID_PARTICIPANT_IDS,
INVALID_PARTICIPANT_ROLE,
INVALID_PARTICIPANT_SEEDING,
INVALID_PARTICIPANT_TYPE,
INVALID_PARTICIPANT,
INVALID_POLICY_DEFINITION,
INVALID_RECORDS,
INVALID_SCALE_ITEM,
INVALID_SEED_NUMBER,
INVALID_SEED_POSITION,
INVALID_SET_NUMBER,
INVALID_SIDE_NUMBER,
INVALID_SCORE,
INVALID_STAGE,
INVALID_START_TIME,
INVALID_STRUCTURE,
INVALID_STOP_TIME,
INVALID_TIE_FORMAT,
INVALID_TIME,
INVALID_TIME_ITEM,
INVALID_TOURNAMENT_DATES,
INVALID_TOURNAMENT_RECORD,
INVALID_VALUES,
INVALID_WINNING_SIDE,
MATCHUP_NOT_FOUND,
METHOD_NOT_FOUND,
MISSING_ASSIGNMENTS,
MISSING_ASYNC_STATE_PROVIDER,
MISSING_AVOIDANCE_POLICY,
MISSING_BIRTH_DATE,
MISSING_COLLECTION_DEFINITION,
MISSING_COURT_ID,
MISSING_COURTS_INFO,
MISSING_DATE_AVAILABILITY,
MISSING_DATE,
MISSING_DRAW_DEFINITION,
MISSING_DRAW_ID,
MISSING_DRAW_POSITION,
MISSING_DRAW_POSITIONS,
MISSING_DRAW_SIZE,
MISSING_ENTRIES,
MISSING_EVENT,
MISSING_QUALIFIED_PARTICIPANTS,
MISSING_MATCHUP_FORMAT,
MISSING_MATCHUP_ID,
MISSING_MATCHUP_IDS,
MISSING_MATCHUP,
MISSING_MATCHUPS,
MISSING_PARTICIPANT_COUNT,
MISSING_PARTICIPANT_ID,
MISSING_PARTICIPANT_IDS,
MISSING_PARTICIPANT_ROLE,
MISSING_PARTICIPANT,
MISSING_PARTICIPANTS,
MISSING_PENALTY_ID,
MISSING_PENALTY_TYPE,
MISSING_PERSON_DETAILS,
MISSING_POLICY_ATTRIBUTES,
MISSING_POLICY_DEFINITION,
MISSING_POLICY_TYPE,
MISSING_POSITION_ASSIGNMENTS,
MISSING_ROUND_NUMBER,
MISSING_SCHEDULE,
MISSING_SCORING_POLICY,
MISSING_SEED_ASSIGNMENTS,
MISSING_SEEDCOUNT_THRESHOLDS,
MISSING_SEEDING_POLICY,
MISSING_SET_NUMBER,
MISSING_SET_OBJECT,
MISSING_SIDE_NUMBER,
MISSING_STAGE,
MISSING_STRUCTURE_ID,
MISSING_STRUCTURE,
MISSING_MAIN_STRUCTURE,
MISSING_STRUCTURES,
MISSING_TARGET_LINK,
MISSING_TIE_FORMAT,
MISSING_TIME_ITEM,
MISSING_TIME_ITEMS,
MISSING_TOURNAMENT_ID,
MISSING_TOURNAMENT_RECORD,
MISSING_TOURNAMENT_RECORDS,
MISSING_VALUE,
MISSING_VENUE_ID,
MODIFICATIONS_FAILED,
NO_CANDIDATES,
NO_DRAW_POSITIONS_AVAILABLE_FOR_QUALIFIERS,
NO_MODIFICATIONS_APPLIED,
NO_STAGE_SPACE_AVAILABLE_FOR_ENTRY_STATUS,
NO_PARTICIPANT_REMOVED,
NO_VALID_ACTIONS,
NO_VALID_ATTRIBUTES,
NO_VALID_DATES,
NOT_FOUND,
NOT_IMPLEMENTED,
PARTICIPANT_COUNT_EXCEEDS_DRAW_SIZE,
PARTICIPANT_ID_EXISTS,
PARTICIPANT_NOT_CHECKED_IN,
PARTICIPANT_NOT_FOUND,
PARTICIPANT_PAIR_EXISTS,
PENALTY_NOT_FOUND,
POLICY_NOT_ATTACHED,
POLICY_NOT_FOUND,
SCHEDULE_NOT_CLEARED,
SCHEDULED_MATCHUPS,
SCORES_PRESENT,
SEEDSCOUNT_GREATER_THAN_DRAW_SIZE,
STAGE_SEQUENCE_LIMIT,
STRUCTURE_NOT_FOUND,
TEAM_NOT_FOUND,
UNABLE_TO_ASSIGN_COURT,
UNLINKED_STRUCTURES,
UNRECOGNIZED_DRAW_TYPE,
UNRECOGNIZED_MATCHUP_FORMAT,
UNRECOGNIZED_MATCHUP_STATUS,
VALUE_UNCHANGED,
VENUE_EXISTS,
};
const syncGlobalState = {
disableNotifications: false,
tournamentId: undefined,
tournamentRecords: {},
subscriptions: {},
modified: false,
methods: {},
notices: [],
};
var syncGlobalState$1 = {
addNotice: addNotice$1,
callListener: callListener$1,
cycleMutationStatus: cycleMutationStatus$1,
deleteNotice: deleteNotice$1,
deleteNotices: deleteNotices$1,
disableNotifications: disableNotifications$1,
enableNotifications: enableNotifications$1,
getMethods: getMethods$1,
getNotices: getNotices$1,
getTopics: getTopics$1,
getTournamentId: getTournamentId$1,
getTournamentRecord: getTournamentRecord$1,
getTournamentRecords: getTournamentRecords$1,
removeTournamentRecord: removeTournamentRecord$1,
setMethods: setMethods$1,
setSubscriptions: setSubscriptions$1,
setTournamentId: setTournamentId$1,
setTournamentRecord: setTournamentRecord$2,
setTournamentRecords: setTournamentRecords$1,
handleCaughtError: handleCaughtError$1,
};
function disableNotifications$1() {
syncGlobalState.disableNotifications = true;
}
function enableNotifications$1() {
syncGlobalState.disableNotifications = false;
}
function getTournamentId$1() {
return syncGlobalState.tournamentId;
}
function getTournamentRecord$1(tournamentId) {
return syncGlobalState.tournamentRecords[tournamentId];
}
function getTournamentRecords$1() {
return syncGlobalState.tournamentRecords;
}
function setTournamentRecord$2(tournamentRecord) {
const tournamentId = tournamentRecord?.tournamentId;
if (tournamentId) {
syncGlobalState.tournamentRecords[tournamentId] = tournamentRecord;
return { success: true };
}
else {
return { error: INVALID_TOURNAMENT_RECORD };
}
}
function setTournamentId$1(tournamentId) {
if (!tournamentId) {
syncGlobalState.tournamentId = undefined;
return { success: true };
}
if (syncGlobalState.tournamentRecords[tournamentId]) {
syncGlobalState.tournamentId = tournamentId;
return { success: true };
}
else {
return { error: MISSING_TOURNAMENT_RECORD };
}
}
function setTournamentRecords$1(tournamentRecords) {
syncGlobalState.tournamentRecords = tournamentRecords;
const tournamentIds = Object.keys(tournamentRecords);
if (tournamentIds.length === 1) {
syncGlobalState.tournamentId = tournamentIds[0];
}
else if (!tournamentIds.length) {
syncGlobalState.tournamentId = undefined;
}
}
function removeTournamentRecord$1(tournamentId) {
if (typeof tournamentId !== 'string')
return { error: INVALID_VALUES };
if (!syncGlobalState.tournamentRecords[tournamentId])
return { error: NOT_FOUND };
delete syncGlobalState.tournamentRecords[tournamentId];
const tournamentIds = Object.keys(syncGlobalState.tournamentRecords);
if (tournamentIds.length === 1) {
syncGlobalState.tournamentId = tournamentIds[0];
}
else if (!tournamentIds.length) {
syncGlobalState.tournamentId = undefined;
}
return { success: true };
}
function setSubscriptions$1(params) {
if (typeof params.subscriptions !== 'object')
return { error: INVALID_VALUES };
Object.keys(params.subscriptions).forEach((subscription) => {
if (typeof params.subscriptions[subscription] === 'function') {
syncGlobalState.subscriptions[subscription] = params.subscriptions[subscription];
}
else {
delete syncGlobalState.subscriptions[subscription];
}
});
return { ...SUCCESS };
}
function setMethods$1(params) {
if (typeof params !== 'object')
return { error: INVALID_VALUES };
Object.keys(params).forEach((methodName) => {
if (typeof params[methodName] !== 'function')
return;
syncGlobalState.methods[methodName] = params[methodName];
});
return { ...SUCCESS };
}
function cycleMutationStatus$1() {
const status = syncGlobalState.modified;
syncGlobalState.modified = false;
return status;
}
function addNotice$1({ topic, payload, key }, isGlobalSubscription) {
if (typeof topic !== 'string' || typeof payload !== 'object')
return;
if (!syncGlobalState.disableNotifications)
syncGlobalState.modified = true;
if (syncGlobalState.disableNotifications || (!syncGlobalState.subscriptions[topic] && !isGlobalSubscription))
return;
if (key) {
syncGlobalState.notices = syncGlobalState.notices.filter((notice) => !(notice.topic === topic && notice.key === key));
}
syncGlobalState.notices.push({ topic, payload, key });
return { ...SUCCESS };
}
function getMethods$1() {
return syncGlobalState.methods ?? {};
}
function getNotices$1({ topic }) {
return syncGlobalState.notices.filter((notice) => notice.topic === topic).map((notice) => notice.payload);
}
function deleteNotices$1() {
syncGlobalState.notices = [];
}
function deleteNotice$1({ topic, key }) {
syncGlobalState.notices = syncGlobalState.notices.filter((notice) => (!topic || notice.topic === topic) && notice.key !== key);
}
function getTopics$1() {
const topics = Object.keys(syncGlobalState.subscriptions);
return { topics };
}
function callListener$1({ topic, notices }, globalSubscriptions) {
const method = syncGlobalState.subscriptions[topic];
if (method && typeof method === 'function')
method(notices);
const globalMethod = globalSubscriptions?.[topic];
if (globalMethod && typeof globalMethod === 'function')
globalMethod(notices);
}
function handleCaughtError$1({ engineName, methodName, params, err }) {
let error;
if (typeof err === 'string') {
error = err.toUpperCase();
}
else if (err instanceof Error) {
error = err.message;
}
console.log('ERROR', {
tournamentId: getTournamentId$1(),
params: JSON.stringify(params),
engine: engineName,
methodName,
error,
});
return { error };
}
const globalState = {
timers: { default: { elapsedTime: 0 } },
globalSubscriptions: {},
deepCopyAttributes: {
stringify: [],
ignore: [],
toJSON: [],
},
globalMethods: [],
deepCopy: true,
};
let _globalStateProvider = syncGlobalState$1;
const requiredStateProviderMethods = [
'addNotice',
'callListener',
'cycleMutationStatus',
'deleteNotice',
'deleteNotices',
'disableNotifications',
'enableNotifications',
'getMethods',
'getNotices',
'getTopics',
'getTournamentId',
'getTournamentRecord',
'getTournamentRecords',
'removeTournamentRecord',
'setSubscriptions',
'setTournamentId',
'setTournamentRecord',
'setTournamentRecords',
];
function setStateProvider(globalStateProvider) {
if (typeof globalStateProvider !== 'object') {
throw new Error(`Global state provider can not be undefined or null`);
}
else {
const providerMethods = intersection(Object.keys(globalStateProvider), requiredStateProviderMethods);
if (providerMethods.length !== requiredStateProviderMethods.length) {
throw new Error('Global state provider is missing required methods');
}
else {
_globalStateProvider = globalStateProvider;
return { success: true };
}
}
}
function createInstanceState() {
if (_globalStateProvider.createInstanceState) {
try {
_globalStateProvider.createInstanceState();
}
catch (error) {
return { error };
}
return { success: true };
}
else {
return { error: MISSING_ASYNC_STATE_PROVIDER };
}
}
function getDevContext(contextCriteria) {
if (!contextCriteria || typeof contextCriteria !== 'object') {
return globalState.devContext ?? false;
}
else {
if (typeof globalState.devContext !== 'object')
return false;
return (Object.keys(contextCriteria).every((key) => globalState.devContext?.[key] === contextCriteria[key]) &&
globalState.devContext);
}
}
function timeKeeper(action = 'reset', timer = 'default') {
const timeNow = Date.now();
if (action === 'report') {
if (timer === 'allTimers') {
const timers = Object.keys(globalState.timers);
return timers
.filter((timer) => timer !== 'default' || globalState.timers[timer].startTime)
.map((timer) => {
const currentTimer = globalState.timers[timer];
const elapsedPeriod = currentTimer.state === 'stopped' ? 0 : (timeNow - (currentTimer?.startTime ?? 0)) / 1000;
const elapsedTime = currentTimer.elapsedTime + elapsedPeriod;
return {
state: globalState.timers[timer].state,
elapsedTime: elapsedTime.toFixed(2),
timer,
};
});
}
else {
const elapsedPeriod = globalState.timers[timer].state === 'stopped'
? 0
: (timeNow - (globalState.timers[timer]?.startTime ?? 0)) / 1000;
const elapsedTime = globalState.timers[timer].elapsedTime + elapsedPeriod;
return {
state: globalState.timers[timer].state,
elapsedTime: elapsedTime.toFixed(2),
timer,
};
}
}
if (!globalState.timers[timer] || action === 'reset') {
if (timer === 'allTimers') {
globalState.timers = { default: { elapsedTime: 0 } };
return true;
}
else {
globalState.timers[timer] = {
startTime: timeNow,
state: 'active',
elapsedTime: 0,
};
}
}
if (!globalState.timers[timer].elapsedTime)
globalState.timers[timer].elapsedTime = 0;
action === 'stop' &&
globalState.timers[timer].state !== 'stopped' &&
(globalState.timers[timer].state = 'stopped') &&
(globalState.timers[timer].elapsedTime += (timeNow - (globalState.timers[timer]?.startTime ?? 0)) / 1000);
action === 'start' && (globalState.timers[timer].startTime = timeNow) && (globalState.timers[timer].state = 'active');
return globalState.timers[timer];
}
function setGlobalLog(loggingFx) {
if (isFunction(loggingFx)) {
globalState.globalLog = loggingFx;
}
else {
delete globalState.globalLog;
}
}
function setDevContext(value) {
globalState.devContext = value;
}
function disableNotifications() {
_globalStateProvider.disableNotifications();
}
function enableNotifications() {
_globalStateProvider.enableNotifications();
}
function setDeepCopy(value, attributes) {
if (typeof value === 'boolean')
globalState.deepCopy = value;
if (typeof attributes === 'object') {
if (Array.isArray(attributes.ignore))
globalState.deepCopyAttributes.ignore = attributes.ignore;
if (Array.isArray(attributes.toJSON))
globalState.deepCopyAttributes.toJSON = attributes.toJSON;
if (Array.isArray(attributes.stringify))
globalState.deepCopyAttributes.stringify = attributes.stringify;
if (attributes.threshold)
globalState.deepCopyAttributes.threshold = attributes.threshold;
}
}
function deepCopyEnabled() {
return {
enabled: globalState.deepCopy,
...globalState.deepCopyAttributes,
};
}
function setGlobalSubscriptions(params) {
if (!params?.subscriptions)
return { error: MISSING_VALUE, info: 'missing subscriptions' };
Object.keys(params.subscriptions).forEach((subscription) => {
globalState.globalSubscriptions[subscription] = params.subscriptions[subscription];
});
return { ...SUCCESS };
}
function setSubscriptions(params) {
if (!params?.subscriptions)
return { error: MISSING_VALUE, info: 'missing subscriptions' };
return _globalStateProvider.setSubscriptions({ subscriptions: params.subscriptions });
}
function setGlobalMethods(params) {
if (!params)
return { error: MISSING_VALUE, info: 'missing method declarations' };
if (typeof params !== 'object')
return { error: INVALID_VALUES };
Object.keys(params).forEach((methodName) => {
if (!isFunction(params[methodName]))
return;
globalState.globalMethods[methodName] = params[methodNa