tods-competition-factory 0.24.0 → 0.25.2

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.
@@ -6567,17 +6567,20 @@ const garman = {
6567
6567
  * @returns {string} - joined by '\r\n' or specified line separator
6568
6568
  *
6569
6569
  * config {
6570
- * {boolean} transformAccesorFilter, // transform accessors are included with columnAccessors
6570
+ * {boolean} includeTransoformAccessors, // transform accessors are included with columnAccessors
6571
6571
  * {string[]} columnAccessors, // [ 'includeThis', 'andThis' ]
6572
6572
  * {object} columnTransform, // e.g. { 'newColumnName': ['oldColumn1', 'oldColumn2' ]}
6573
6573
  * {object} columnMap, // e.g. { 'columnName': 'newColumnName' }
6574
+ * {object} valuesMap, // e.g. { 'columnName': { 'value1': 'mappedValue' }} // useful for mapping IDs
6575
+ * {object} context, // attributes which are to be added to all rows { 'columnName': 'value }
6576
+ * {string} delimiter, // defaults to '"'
6574
6577
  * {string} columnJoiner, // defaults to ',' // defines how CSV columns are joined
6575
6578
  * {string} rowJoiner, // defaults to '\r\n' // defines how CSV lines are joined
6576
6579
  * {string} keyJoiner, // defaults to '.' // defines how flattened column names are constructed
6577
6580
  * }
6578
6581
  *
6579
- * NOTE: `columnMap` should not contain newColumnName(s) that are `columnTransform` keys
6580
6582
  * NOTE: `columnTransform` mapped array elements are sensitive to order and will resolve to the first matching value
6583
+ * NOTE: `columnMap` should not contain new columnName(s) that are `columnTransform` keys
6581
6584
  */
6582
6585
 
6583
6586
  function JSON2CSV(arrayOfJSON, config) {
@@ -6585,21 +6588,23 @@ function JSON2CSV(arrayOfJSON, config) {
6585
6588
  error: INVALID_VALUES
6586
6589
  };
6587
6590
  const {
6588
- transformAccesorFilter,
6591
+ includeTransoformAccessors,
6589
6592
  columnAccessors = [],
6590
6593
  columnTransform = {},
6591
6594
  columnMap = {},
6595
+ valuesMap = {},
6592
6596
  context = {},
6597
+ delimiter = '"',
6593
6598
  columnJoiner = ',',
6594
6599
  rowJoiner = '\r\n',
6595
6600
  keyJoiner = '.'
6596
6601
  } = config || {};
6597
- if (!Array.isArray(arrayOfJSON) || !Array.isArray(columnAccessors) || !Array.isArray(Object.keys(columnMap || {})) || typeof keyJoiner !== 'string') return {
6602
+ if (!Array.isArray(arrayOfJSON) || !Array.isArray(columnAccessors) || !Array.isArray(Object.keys(columnTransform || {})) || !Array.isArray(Object.keys(columnMap || {})) || !Array.isArray(Object.keys(valuesMap || {})) || !Array.isArray(Object.keys(context || {})) || typeof columnJoiner !== 'string' || typeof rowJoiner !== 'string' || typeof keyJoiner !== 'string' || typeof delimiter !== 'string') return {
6598
6603
  error: INVALID_VALUES
6599
6604
  };
6600
6605
  const flattened = arrayOfJSON.filter(Boolean).map(obj => flatten(obj, keyJoiner));
6601
6606
  const transformColumns = Object.values(columnTransform).flat();
6602
- if (transformAccesorFilter) columnAccessors.push(...transformColumns);
6607
+ if (includeTransoformAccessors) columnAccessors.push(...transformColumns);
6603
6608
  const headerRow = flattened.reduce((aggregator, row) => Object.keys(row).every(key => !aggregator.includes(key) && aggregator.push(key) || true) && aggregator, []).filter(key => !(columnAccessors !== null && columnAccessors !== void 0 && columnAccessors.length) || columnAccessors.includes(key));
6604
6609
  const accessorMap = Object.assign({}, ...Object.keys(columnTransform).map(transform => columnTransform[transform].map(value => ({
6605
6610
  [value]: transform
@@ -6620,17 +6625,23 @@ function JSON2CSV(arrayOfJSON, config) {
6620
6625
  typeof context === 'object' && Object.keys(context).forEach(columnName => !tranformedHeaderRow.includes(columnName) && tranformedHeaderRow.unshift(columnName));
6621
6626
  const mappedHeaderRow = tranformedHeaderRow.map(key => columnMap[key] || key);
6622
6627
 
6628
+ const withDelimiter = value => `${delimiter}${value}${delimiter}`;
6629
+
6623
6630
  const processRow = row => {
6624
- const valueMap = Object.values(tranformedHeaderRow.reduce((valueMap, key) => {
6625
- const accessors = columnTransform[key];
6626
- valueMap[key] = (accessors !== null && accessors !== void 0 && accessors.length ? row[accessors.find(accessor => row[accessor])] : row[key]) || (context === null || context === void 0 ? void 0 : context[key]) || '';
6627
- return valueMap;
6631
+ const columnsMap = Object.values(tranformedHeaderRow.reduce((columnsMap, columnName) => {
6632
+ var _valuesMap$columnName;
6633
+
6634
+ const accessors = columnTransform[columnName];
6635
+ const value = (accessors !== null && accessors !== void 0 && accessors.length ? row[accessors.find(accessor => row[accessor])] : row[columnName]) || (context === null || context === void 0 ? void 0 : context[columnName]) || '';
6636
+ const mappedValue = ((_valuesMap$columnName = valuesMap[columnName]) === null || _valuesMap$columnName === void 0 ? void 0 : _valuesMap$columnName[value]) || value;
6637
+ columnsMap[columnName] = withDelimiter(mappedValue);
6638
+ return columnsMap;
6628
6639
  }, {}));
6629
- return valueMap;
6640
+ return columnsMap.join(columnJoiner);
6630
6641
  };
6631
6642
 
6632
6643
  const rows = flattened.map(processRow);
6633
- return [mappedHeaderRow.join(columnJoiner), ...rows].join(rowJoiner);
6644
+ return [mappedHeaderRow.map(withDelimiter).join(columnJoiner), ...rows].join(rowJoiner);
6634
6645
  }
6635
6646
 
6636
6647
  function flatten(obj, keyJoiner = '.', path = []) {
@@ -25231,7 +25242,7 @@ const scheduleGovernor = {
25231
25242
  };
25232
25243
 
25233
25244
  function factoryVersion() {
25234
- return '0.24.0';
25245
+ return '0.25.2';
25235
25246
  }
25236
25247
 
25237
25248
  function attachPolicies({
@@ -29726,16 +29737,20 @@ function destroyGroupEntry({
29726
29737
  participantIds: [participantId]
29727
29738
  });
29728
29739
  if (result.error) return result;
29729
- result = addEventEntries({
29730
- event,
29731
- drawId,
29732
- drawDefinition,
29733
- tournamentRecord,
29734
- entryStage: entry.entryStage,
29735
- entryStatus: entryStatus || defaultEntryStatus,
29736
- participantIds: individualParticipantIds
29737
- });
29738
- if (result.error) return result;
29740
+
29741
+ if (individualParticipantIds.length) {
29742
+ result = addEventEntries({
29743
+ event,
29744
+ drawId,
29745
+ drawDefinition,
29746
+ tournamentRecord,
29747
+ entryStage: entry.entryStage,
29748
+ entryStatus: entryStatus || defaultEntryStatus,
29749
+ participantIds: individualParticipantIds
29750
+ });
29751
+ if (result.error) return result;
29752
+ }
29753
+
29739
29754
  let participantRemoved;
29740
29755
 
29741
29756
  if (removeGroupParticipant) {
@@ -36691,15 +36706,16 @@ function addPlayoffStructures(params) {
36691
36706
  error: sourceRoundsError
36692
36707
  };
36693
36708
  const {
36694
- uuids,
36695
- roundNumbers,
36696
- roundProfiles,
36697
- drawDefinition,
36698
- playoffPositions,
36709
+ structureId: sourceStructureId,
36710
+ playoffStructureNameBase,
36699
36711
  playoffAttributes,
36712
+ playoffPositions,
36700
36713
  exitProfileLimit,
36701
- playoffStructureNameBase,
36702
- structureId: sourceStructureId
36714
+ drawDefinition,
36715
+ roundProfiles,
36716
+ roundNumbers,
36717
+ idPrefix,
36718
+ uuids
36703
36719
  } = params;
36704
36720
  const roundProfile = (roundProfiles === null || roundProfiles === void 0 ? void 0 : roundProfiles.length) && Object.assign({}, ...roundProfiles);
36705
36721
  const targetRoundNumbers = roundNumbers || typeof roundProfiles === 'object' && roundProfiles.map(p => Object.keys(p)).flat();
@@ -36752,18 +36768,19 @@ function addPlayoffStructures(params) {
36752
36768
  const {
36753
36769
  structure: targetStructure
36754
36770
  } = playoff({
36755
- uuids,
36756
- drawSize,
36757
- sequenceLimit,
36758
- stageSequence,
36759
- roundOffset: 0,
36760
- drawDefinition,
36761
- stage: PLAY_OFF,
36762
- exitProfileLimit,
36763
- playoffAttributes,
36771
+ exitProfile: `0-${roundNumber}`,
36764
36772
  playoffStructureNameBase,
36765
36773
  finishingPositionOffset,
36766
- exitProfile: `0-${roundNumber}`
36774
+ playoffAttributes,
36775
+ exitProfileLimit,
36776
+ stage: PLAY_OFF,
36777
+ drawDefinition,
36778
+ roundOffset: 0,
36779
+ sequenceLimit,
36780
+ stageSequence,
36781
+ drawSize,
36782
+ idPrefix,
36783
+ uuids
36767
36784
  });
36768
36785
 
36769
36786
  if (targetStructure) {
@@ -36844,23 +36861,25 @@ function addPlayoffStructures$1({
36844
36861
  playoffAttributes,
36845
36862
  playoffPositions,
36846
36863
  exitProfileLimit,
36847
- roundNumbers,
36848
36864
  roundProfiles,
36865
+ roundNumbers,
36849
36866
  structureId,
36867
+ idPrefix,
36850
36868
  uuids
36851
36869
  }) {
36852
36870
  if (!tournamentRecord) return {
36853
36871
  error: MISSING_TOURNAMENT_RECORD
36854
36872
  };
36855
36873
  const result = addPlayoffStructures({
36856
- drawDefinition,
36857
- structureId,
36858
- roundNumbers,
36859
- roundProfiles,
36860
- playoffPositions,
36861
- playoffAttributes,
36862
36874
  playoffStructureNameBase,
36875
+ playoffAttributes,
36876
+ playoffPositions,
36863
36877
  exitProfileLimit,
36878
+ drawDefinition,
36879
+ roundProfiles,
36880
+ roundNumbers,
36881
+ structureId,
36882
+ idPrefix,
36864
36883
  uuids
36865
36884
  });
36866
36885
  const playoffDetails = {
@@ -45164,6 +45183,7 @@ function generateEventWithFlights({
45164
45183
  startDate,
45165
45184
  uuids
45166
45185
  }) {
45186
+ let gender = eventProfile.gender;
45167
45187
  const {
45168
45188
  eventName = 'Generated Event',
45169
45189
  eventType = SINGLES$1,
@@ -45174,12 +45194,16 @@ function generateEventWithFlights({
45174
45194
  discipline,
45175
45195
  eventLevel,
45176
45196
  ballType,
45177
- category,
45178
- gender
45197
+ category
45179
45198
  } = eventProfile;
45180
45199
  const tieFormat = eventProfile.tieFormat || eventType === TEAM$1 && tieFormatDefaults();
45181
45200
  let targetParticipants = tournamentRecord.participants;
45182
45201
  let uniqueDrawParticipants = [];
45202
+
45203
+ for (const drawProfile of drawProfiles) {
45204
+ if (!gender && drawProfile.gender) gender = drawProfile.gender;
45205
+ }
45206
+
45183
45207
  let uniqueParticipantsCount = {};
45184
45208
  const stageParticipantsCount = drawProfiles.reduce((stageParticipantsCount, drawProfile) => {
45185
45209
  const {
@@ -45192,7 +45216,7 @@ function generateEventWithFlights({
45192
45216
  if (!Object.keys(stageParticipantsCount).includes(stage)) stageParticipantsCount[stage] = 0;
45193
45217
  const stageCount = participantsCount || drawSize - qualifyingPositions;
45194
45218
 
45195
- if (uniqueParticipants) {
45219
+ if (uniqueParticipants || gender) {
45196
45220
  if (!Object.keys(uniqueParticipantsCount).includes(stage)) uniqueParticipantsCount[stage] = 0;
45197
45221
  uniqueParticipantsCount[stage] += stageCount;
45198
45222
  } else {
@@ -45319,7 +45343,7 @@ function generateEventWithFlights({
45319
45343
  const entriesCount = drawSize - qualifyingPositions; // if a drawProfile has specified uniqueParticipants...
45320
45344
 
45321
45345
  const drawParticipants = uniqueParticipants ? uniqueDrawParticipants.slice(uniqueParticipantsIndex, entriesCount) : stageParticipants[stage || MAIN] || [];
45322
- if (uniqueParticipants) uniqueParticipantsIndex += entriesCount;
45346
+ if (uniqueParticipants || gender) uniqueParticipantsIndex += entriesCount;
45323
45347
  const drawParticipantIds = drawParticipants.slice(0, entriesCount).map(({
45324
45348
  participantId
45325
45349
  }) => participantId);
@@ -45434,7 +45458,20 @@ function generateEventWithFlights({
45434
45458
  event
45435
45459
  });
45436
45460
  if (result.error) return result;
45437
- drawIds.push(flight.drawId); // TODO: enable { outcomes: [] } in eventProfile: { drawProfiles }
45461
+ drawIds.push(flight.drawId);
45462
+
45463
+ if (drawProfile.withPlayoffs) {
45464
+ const structureId = drawDefinition.structures[0].structureId;
45465
+ const result = addPlayoffStructures$1({
45466
+ idPrefix: drawProfile.idPrefix,
45467
+ ...drawProfile.withPlayoffs,
45468
+ tournamentRecord,
45469
+ drawDefinition,
45470
+ structureId
45471
+ });
45472
+ if (result !== null && result !== void 0 && result.error) return result;
45473
+ } // TODO: enable { outcomes: [] } in eventProfile: { drawProfiles }
45474
+
45438
45475
 
45439
45476
  const manual = drawProfile.automated === false;
45440
45477
 
@@ -45504,6 +45541,7 @@ function generateEventWithDraw({
45504
45541
  drawSize = 32,
45505
45542
  seedsCount,
45506
45543
  category,
45544
+ idPrefix,
45507
45545
  gender,
45508
45546
  stage
45509
45547
  } = drawProfile;
@@ -45586,11 +45624,14 @@ function generateEventWithDraw({
45586
45624
  };
45587
45625
 
45588
45626
  const isEventGender = participant => {
45589
- var _participant$person, _participant$individu, _participant$individu2;
45627
+ var _participant$person, _participant$individu;
45590
45628
 
45591
45629
  if (!drawProfile.gender) return true;
45592
45630
  if (((_participant$person = participant.person) === null || _participant$person === void 0 ? void 0 : _participant$person.sex) === drawProfile.gender) return true;
45593
- if (((_participant$individu = participant.individualParticipants) === null || _participant$individu === void 0 ? void 0 : (_participant$individu2 = _participant$individu[0]) === null || _participant$individu2 === void 0 ? void 0 : _participant$individu2.sex) === drawProfile.gender) return true;
45631
+ if ((_participant$individu = participant.individualParticipantIds) !== null && _participant$individu !== void 0 && _participant$individu.some(participantId => {
45632
+ const individualParticipant = targetParticipants.find(p => p.participantId === participantId);
45633
+ return individualParticipant && isEventGender(individualParticipant);
45634
+ })) return true;
45594
45635
  };
45595
45636
 
45596
45637
  const consideredParticipants = targetParticipants.filter(isEventParticipantType).filter(isEventGender).filter(({
@@ -45677,6 +45718,18 @@ function generateEventWithDraw({
45677
45718
  const {
45678
45719
  drawId
45679
45720
  } = drawDefinition;
45721
+
45722
+ if (drawProfile.withPlayoffs) {
45723
+ const structureId = drawDefinition.structures[0].structureId;
45724
+ const result = addPlayoffStructures$1({ ...drawProfile.withPlayoffs,
45725
+ tournamentRecord,
45726
+ drawDefinition,
45727
+ structureId,
45728
+ idPrefix
45729
+ });
45730
+ if (result !== null && result !== void 0 && result.error) return result;
45731
+ }
45732
+
45680
45733
  const manual = drawProfile.automated === false;
45681
45734
 
45682
45735
  if (!manual) {
@@ -45830,7 +45883,7 @@ function generateTournamentRecord({
45830
45883
 
45831
45884
  if (!startDate) {
45832
45885
  const tournamentDate = new Date();
45833
- startDate = formatDate(tournamentDate);
45886
+ startDate = formatDate(endDate || tournamentDate);
45834
45887
  endDate = formatDate(tournamentDate.setDate(tournamentDate.getDate() + 7));
45835
45888
  }
45836
45889
 
@@ -46139,7 +46192,7 @@ const mocksGovernor = {
46139
46192
  const mocksEngine = /*#__PURE__*/function () {
46140
46193
  const engine = {
46141
46194
  version: () => {
46142
- return '0.24.0';
46195
+ return '0.25.2';
46143
46196
  },
46144
46197
  devContext: isDev => {
46145
46198
  setDevContext(isDev);