volleyballsimtypes 0.0.204 → 0.0.206

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # VolleyballSimTypes
2
+
3
+ Tree-shaking
4
+
5
+ This package ships ESM + CJS builds and supports subpath imports. Prefer subpath imports to avoid pulling in unused modules.
6
+
7
+ Examples:
8
+
9
+ ```ts
10
+ import { Team } from 'volleyballsimtypes/service'
11
+ import { initModels } from 'volleyballsimtypes/data'
12
+ import { transformToTeam } from 'volleyballsimtypes/data/transformers'
13
+ ```
@@ -9,7 +9,7 @@ function transformToAttributes(team) {
9
9
  name: team.name,
10
10
  short_name: team.shortName,
11
11
  country_id: team.country?.id,
12
- tactics: (0, _1.transformFromTactics)(team.tactics, team.id),
12
+ tactics: team.tactics != null ? (0, _1.transformFromTactics)(team.tactics, team.id) : undefined,
13
13
  rating: team.rating,
14
14
  division_id: team.divisionId
15
15
  };
@@ -22,9 +22,9 @@ function transformToObject(model) {
22
22
  name: model.name,
23
23
  shortName: model.short_name,
24
24
  country: (0, _1.transformToCountry)(model.country),
25
- tactics: (0, _1.transformToTactics)(model.tactics, roster),
26
- roster,
27
25
  rating: model.rating,
26
+ tactics: roster != null && roster.length > 0 ? (0, _1.transformToTactics)(model.tactics, roster) : undefined,
27
+ roster,
28
28
  divisionId: model.division_id
29
29
  });
30
30
  }
@@ -23,5 +23,6 @@ export declare class Season {
23
23
  champion?: Team;
24
24
  constructor({ id, iteration, teams, matches, champion, status, divisionId }: SeasonOpts);
25
25
  calculateStandings(): Standing[];
26
+ updateStandings(): void;
26
27
  }
27
28
  export {};
@@ -20,5 +20,14 @@ class Season {
20
20
  return standing;
21
21
  }).sort(standing_1.Standing.sortFn);
22
22
  }
23
+ updateStandings() {
24
+ if (this.matches == null || this.matches.length < 1)
25
+ throw new Error('NO_MATCHES');
26
+ const updated = this.calculateStandings();
27
+ this.standings.splice(0, this.standings.length, ...updated);
28
+ if (this.matches.every((match) => match.isOver())) {
29
+ this.champion = this.standings[0].team;
30
+ }
31
+ }
23
32
  }
24
33
  exports.Season = Season;
@@ -32,13 +32,10 @@ class Match {
32
32
  return `${this.getTeamSets(match_team_1.MatchTeam.HOME)}-${this.getTeamSets(match_team_1.MatchTeam.AWAY)}`;
33
33
  }
34
34
  isOver() {
35
- const gamesRequired = 3;
36
- const lastSet = this.sets.at(-1);
37
- if (lastSet == null || !lastSet.isOver() || this.sets.length < gamesRequired)
38
- return false;
35
+ const setsToWin = 3;
39
36
  const homeSets = this.getTeamSets(match_team_1.MatchTeam.HOME);
40
37
  const awaySets = this.getTeamSets(match_team_1.MatchTeam.AWAY);
41
- return !(homeSets < gamesRequired && awaySets < gamesRequired);
38
+ return !(homeSets < setsToWin && awaySets < setsToWin);
42
39
  }
43
40
  getWinner() {
44
41
  if (!this.isOver())
@@ -9,7 +9,7 @@ interface TeamParams {
9
9
  readonly divisionId: string;
10
10
  readonly roster: Player[];
11
11
  readonly country: Country;
12
- readonly tactics: Tactics;
12
+ readonly tactics?: Tactics;
13
13
  }
14
14
  export declare class Team {
15
15
  readonly id: string;
@@ -17,7 +17,7 @@ export declare class Team {
17
17
  readonly name: string;
18
18
  readonly shortName: string;
19
19
  readonly divisionId: string;
20
- readonly tactics: Tactics;
20
+ readonly tactics?: Tactics;
21
21
  readonly country: Country;
22
22
  private _rating;
23
23
  constructor({ id, rating, name, shortName, divisionId, country, roster, tactics }: TeamParams);
@@ -6,7 +6,7 @@ function transformToAttributes(team) {
6
6
  name: team.name,
7
7
  short_name: team.shortName,
8
8
  country_id: team.country?.id,
9
- tactics: transformFromTactics(team.tactics, team.id),
9
+ tactics: team.tactics != null ? transformFromTactics(team.tactics, team.id) : undefined,
10
10
  rating: team.rating,
11
11
  division_id: team.divisionId
12
12
  };
@@ -18,9 +18,9 @@ function transformToObject(model) {
18
18
  name: model.name,
19
19
  shortName: model.short_name,
20
20
  country: transformToCountry(model.country),
21
- tactics: transformToTactics(model.tactics, roster),
22
- roster,
23
21
  rating: model.rating,
22
+ tactics: roster != null && roster.length > 0 ? transformToTactics(model.tactics, roster) : undefined,
23
+ roster,
24
24
  divisionId: model.division_id
25
25
  });
26
26
  }
@@ -23,5 +23,6 @@ export declare class Season {
23
23
  champion?: Team;
24
24
  constructor({ id, iteration, teams, matches, champion, status, divisionId }: SeasonOpts);
25
25
  calculateStandings(): Standing[];
26
+ updateStandings(): void;
26
27
  }
27
28
  export {};
@@ -17,4 +17,13 @@ export class Season {
17
17
  return standing;
18
18
  }).sort(Standing.sortFn);
19
19
  }
20
+ updateStandings() {
21
+ if (this.matches == null || this.matches.length < 1)
22
+ throw new Error('NO_MATCHES');
23
+ const updated = this.calculateStandings();
24
+ this.standings.splice(0, this.standings.length, ...updated);
25
+ if (this.matches.every((match) => match.isOver())) {
26
+ this.champion = this.standings[0].team;
27
+ }
28
+ }
20
29
  }
@@ -29,13 +29,10 @@ export class Match {
29
29
  return `${this.getTeamSets(MatchTeam.HOME)}-${this.getTeamSets(MatchTeam.AWAY)}`;
30
30
  }
31
31
  isOver() {
32
- const gamesRequired = 3;
33
- const lastSet = this.sets.at(-1);
34
- if (lastSet == null || !lastSet.isOver() || this.sets.length < gamesRequired)
35
- return false;
32
+ const setsToWin = 3;
36
33
  const homeSets = this.getTeamSets(MatchTeam.HOME);
37
34
  const awaySets = this.getTeamSets(MatchTeam.AWAY);
38
- return !(homeSets < gamesRequired && awaySets < gamesRequired);
35
+ return !(homeSets < setsToWin && awaySets < setsToWin);
39
36
  }
40
37
  getWinner() {
41
38
  if (!this.isOver())
@@ -9,7 +9,7 @@ interface TeamParams {
9
9
  readonly divisionId: string;
10
10
  readonly roster: Player[];
11
11
  readonly country: Country;
12
- readonly tactics: Tactics;
12
+ readonly tactics?: Tactics;
13
13
  }
14
14
  export declare class Team {
15
15
  readonly id: string;
@@ -17,7 +17,7 @@ export declare class Team {
17
17
  readonly name: string;
18
18
  readonly shortName: string;
19
19
  readonly divisionId: string;
20
- readonly tactics: Tactics;
20
+ readonly tactics?: Tactics;
21
21
  readonly country: Country;
22
22
  private _rating;
23
23
  constructor({ id, rating, name, shortName, divisionId, country, roster, tactics }: TeamParams);
package/package.json CHANGED
@@ -1,9 +1,43 @@
1
1
  {
2
2
  "name": "volleyballsimtypes",
3
- "version": "0.0.204",
3
+ "version": "0.0.206",
4
4
  "description": "vbsim types",
5
5
  "main": "./dist/cjs/src/index.js",
6
6
  "module": "./dist/esm/src/index.js",
7
+ "types": "./dist/esm/src/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/esm/src/index.d.ts",
12
+ "import": "./dist/esm/src/index.js",
13
+ "require": "./dist/cjs/src/index.js"
14
+ },
15
+ "./service": {
16
+ "types": "./dist/esm/src/service/index.d.ts",
17
+ "import": "./dist/esm/src/service/index.js",
18
+ "require": "./dist/cjs/src/service/index.js"
19
+ },
20
+ "./data": {
21
+ "types": "./dist/esm/src/data/index.d.ts",
22
+ "import": "./dist/esm/src/data/index.js",
23
+ "require": "./dist/cjs/src/data/index.js"
24
+ },
25
+ "./data/models": {
26
+ "types": "./dist/esm/src/data/models/index.d.ts",
27
+ "import": "./dist/esm/src/data/models/index.js",
28
+ "require": "./dist/cjs/src/data/models/index.js"
29
+ },
30
+ "./data/transformers": {
31
+ "types": "./dist/esm/src/data/transformers/index.d.ts",
32
+ "import": "./dist/esm/src/data/transformers/index.js",
33
+ "require": "./dist/cjs/src/data/transformers/index.js"
34
+ },
35
+ "./data/common": {
36
+ "types": "./dist/esm/src/data/common/index.d.ts",
37
+ "import": "./dist/esm/src/data/common/index.js",
38
+ "require": "./dist/cjs/src/data/common/index.js"
39
+ }
40
+ },
7
41
  "files": [
8
42
  "dist/"
9
43
  ],