volleyballsimtypes 0.0.457 → 0.0.462
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/cjs/src/api/index.d.ts +6 -0
- package/dist/cjs/src/data/init-models.js +4 -0
- package/dist/cjs/src/data/models/index.d.ts +1 -0
- package/dist/cjs/src/data/models/index.js +1 -0
- package/dist/cjs/src/data/models/tactics.d.ts +9 -1
- package/dist/cjs/src/data/models/tactics.js +8 -0
- package/dist/cjs/src/data/models/user-device-token.d.ts +23 -0
- package/dist/cjs/src/data/models/user-device-token.js +65 -0
- package/dist/cjs/src/data/transformers/tactics.js +21 -3
- package/dist/cjs/src/data/transformers/tactics.test.js +61 -0
- package/dist/cjs/src/service/team/schemas/tactics.z.d.ts +8 -0
- package/dist/cjs/src/service/team/schemas/tactics.z.js +53 -31
- package/dist/cjs/src/service/team/schemas/tactics.z.test.js +115 -0
- package/dist/cjs/src/service/team/schemas/team.z.d.ts +8 -0
- package/dist/cjs/src/service/team/tactics.d.ts +8 -0
- package/dist/cjs/src/service/team/tactics.js +3 -1
- package/dist/esm/src/api/index.d.ts +6 -0
- package/dist/esm/src/data/init-models.js +5 -1
- package/dist/esm/src/data/models/index.d.ts +1 -0
- package/dist/esm/src/data/models/index.js +1 -0
- package/dist/esm/src/data/models/tactics.d.ts +9 -1
- package/dist/esm/src/data/models/tactics.js +8 -0
- package/dist/esm/src/data/models/user-device-token.d.ts +23 -0
- package/dist/esm/src/data/models/user-device-token.js +61 -0
- package/dist/esm/src/data/transformers/tactics.js +21 -3
- package/dist/esm/src/data/transformers/tactics.test.js +63 -2
- package/dist/esm/src/service/team/schemas/tactics.z.d.ts +8 -0
- package/dist/esm/src/service/team/schemas/tactics.z.js +53 -31
- package/dist/esm/src/service/team/schemas/tactics.z.test.js +115 -0
- package/dist/esm/src/service/team/schemas/team.z.d.ts +8 -0
- package/dist/esm/src/service/team/tactics.d.ts +8 -0
- package/dist/esm/src/service/team/tactics.js +3 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthIdentityModel, AuthSessionModel, AuthUserModel, BoxScoreModel, CoachModel, ScoutModel, BoxScoreTotalsModel, CompetitionChampionModel, CurrencyTransactionModel, GachaPityModel, GachaPullHistoryModel, WishlistModel, UserSettingsModel, CompetitionMatchModel, CompetitionMVPModel, CompetitionModel, CompetitionStandingsMatchModel, CompetitionStandingsModel, CompetitionTeamsModel, CountryModel, DivisionModel, DivisionSeasonModel, IterationModel, LeagueModel, MatchModel, MatchRatingModel, MatchResultModel, MatchSetModel, PerformanceStatsModel, PlayerModel, PlayerImprovementLogModel, PlayerDeclineLogModel, PlayerTeamModel, RetiredPlayerModel, PromotionMatchModel, FriendlyModel, RegionQualifierModel, NationalCountryModel, RallyModel, TacticsModel, LineupPresetModel, TeamModel, TeamReplacementModel, UserCurrencyModel, UserPlayerProgressModel, UserPullGrantModel, UserTeamModel, VPERModel, NotificationModel, AppConfigModel, LegacyTeamFlagModel } from './models';
|
|
1
|
+
import { AuthIdentityModel, AuthSessionModel, AuthUserModel, BoxScoreModel, CoachModel, ScoutModel, BoxScoreTotalsModel, CompetitionChampionModel, CurrencyTransactionModel, GachaPityModel, GachaPullHistoryModel, WishlistModel, UserSettingsModel, UserDeviceTokenModel, CompetitionMatchModel, CompetitionMVPModel, CompetitionModel, CompetitionStandingsMatchModel, CompetitionStandingsModel, CompetitionTeamsModel, CountryModel, DivisionModel, DivisionSeasonModel, IterationModel, LeagueModel, MatchModel, MatchRatingModel, MatchResultModel, MatchSetModel, PerformanceStatsModel, PlayerModel, PlayerImprovementLogModel, PlayerDeclineLogModel, PlayerTeamModel, RetiredPlayerModel, PromotionMatchModel, FriendlyModel, RegionQualifierModel, NationalCountryModel, RallyModel, TacticsModel, LineupPresetModel, TeamModel, TeamReplacementModel, UserCurrencyModel, UserPlayerProgressModel, UserPullGrantModel, UserTeamModel, VPERModel, NotificationModel, AppConfigModel, LegacyTeamFlagModel } from './models';
|
|
2
2
|
export function initModels(sequelize) {
|
|
3
3
|
const Coach = CoachModel.initModel(sequelize);
|
|
4
4
|
const Scout = ScoutModel.initModel(sequelize);
|
|
@@ -13,6 +13,7 @@ export function initModels(sequelize) {
|
|
|
13
13
|
const UserPullGrant = UserPullGrantModel.initModel(sequelize);
|
|
14
14
|
const Wishlist = WishlistModel.initModel(sequelize);
|
|
15
15
|
const UserSettings = UserSettingsModel.initModel(sequelize);
|
|
16
|
+
const UserDeviceToken = UserDeviceTokenModel.initModel(sequelize);
|
|
16
17
|
const Notification = NotificationModel.initModel(sequelize);
|
|
17
18
|
const AuthIdentity = AuthIdentityModel.initModel(sequelize);
|
|
18
19
|
const AuthSession = AuthSessionModel.initModel(sequelize);
|
|
@@ -60,7 +61,9 @@ export function initModels(sequelize) {
|
|
|
60
61
|
AuthUser.hasOne(GachaPity, { as: 'GachaPity', foreignKey: 'user_id' });
|
|
61
62
|
AuthUser.hasOne(Wishlist, { as: 'Wishlist', foreignKey: 'user_id' });
|
|
62
63
|
AuthUser.hasOne(UserSettings, { as: 'UserSettings', foreignKey: 'user_id' });
|
|
64
|
+
AuthUser.hasMany(UserDeviceToken, { as: 'UserDeviceTokens', foreignKey: 'user_id' });
|
|
63
65
|
AuthUser.hasMany(Notification, { as: 'Notifications', foreignKey: 'user_id' });
|
|
66
|
+
UserDeviceToken.belongsTo(AuthUser, { as: 'user', foreignKey: 'user_id' });
|
|
64
67
|
Notification.belongsTo(AuthUser, { as: 'user', foreignKey: 'user_id' });
|
|
65
68
|
AuthUser.hasMany(GachaPullHistory, { as: 'GachaPullHistory', foreignKey: 'user_id' });
|
|
66
69
|
AuthUser.hasMany(UserPullGrant, { as: 'UserPullGrants', foreignKey: 'user_id' });
|
|
@@ -291,6 +294,7 @@ export function initModels(sequelize) {
|
|
|
291
294
|
UserPullGrant,
|
|
292
295
|
Wishlist,
|
|
293
296
|
UserSettings,
|
|
297
|
+
UserDeviceToken,
|
|
294
298
|
Notification,
|
|
295
299
|
Coach,
|
|
296
300
|
Scout,
|
|
@@ -44,6 +44,7 @@ export * from './wishlist';
|
|
|
44
44
|
export * from './currency-transaction';
|
|
45
45
|
export * from './user-pull-grant';
|
|
46
46
|
export * from './user-settings';
|
|
47
|
+
export * from './user-device-token';
|
|
47
48
|
export * from './notification';
|
|
48
49
|
export * from './vper';
|
|
49
50
|
export * from './views';
|
|
@@ -44,6 +44,7 @@ export * from './wishlist';
|
|
|
44
44
|
export * from './currency-transaction';
|
|
45
45
|
export * from './user-pull-grant';
|
|
46
46
|
export * from './user-settings';
|
|
47
|
+
export * from './user-device-token';
|
|
47
48
|
export * from './notification';
|
|
48
49
|
export * from './vper';
|
|
49
50
|
export * from './views';
|
|
@@ -35,6 +35,10 @@ export interface OffensivePreferenceAttributes {
|
|
|
35
35
|
rotation: number;
|
|
36
36
|
order: PlayerId[];
|
|
37
37
|
}
|
|
38
|
+
export interface SystemSetAttributes {
|
|
39
|
+
rotationSystem: RotationSystemEnum;
|
|
40
|
+
designatedSetters: PlayerId[];
|
|
41
|
+
}
|
|
38
42
|
export interface LiberoSetSubConfigAttributes {
|
|
39
43
|
mode: LiberoSubMode;
|
|
40
44
|
fatigueBand?: EnergyBand;
|
|
@@ -55,10 +59,12 @@ export interface TacticsAttributes {
|
|
|
55
59
|
rotation_system: RotationSystemEnum;
|
|
56
60
|
designated_setters: PlayerId[];
|
|
57
61
|
offensive_preferences: OffensivePreferenceAttributes[];
|
|
62
|
+
system_sets?: SystemSetAttributes[];
|
|
63
|
+
offensive_preference_sets?: OffensivePreferenceAttributes[][];
|
|
58
64
|
}
|
|
59
65
|
export type TacticsPk = 'team_id';
|
|
60
66
|
export type TacticsId = TacticsModel[TacticsPk];
|
|
61
|
-
export type TacticsOptionalAttributes = 'lineup' | 'libero_replacements' | 'receive_rotation_offset' | 'designated_subs' | 'substitution_band' | 'second_libero' | 'libero_sub' | 'libero_replacement_sets' | 'rotation_system' | 'designated_setters' | 'offensive_preferences';
|
|
67
|
+
export type TacticsOptionalAttributes = 'lineup' | 'libero_replacements' | 'receive_rotation_offset' | 'designated_subs' | 'substitution_band' | 'second_libero' | 'libero_sub' | 'libero_replacement_sets' | 'rotation_system' | 'designated_setters' | 'offensive_preferences' | 'system_sets' | 'offensive_preference_sets';
|
|
62
68
|
export type TacticsCreationAttributes = Optional<TacticsAttributes, TacticsOptionalAttributes>;
|
|
63
69
|
export declare class TacticsModel extends Model<TacticsAttributes, TacticsCreationAttributes> implements TacticsAttributes {
|
|
64
70
|
team_id: string;
|
|
@@ -73,6 +79,8 @@ export declare class TacticsModel extends Model<TacticsAttributes, TacticsCreati
|
|
|
73
79
|
rotation_system: RotationSystemEnum;
|
|
74
80
|
designated_setters: PlayerId[];
|
|
75
81
|
offensive_preferences: OffensivePreferenceAttributes[];
|
|
82
|
+
system_sets?: SystemSetAttributes[];
|
|
83
|
+
offensive_preference_sets?: OffensivePreferenceAttributes[][];
|
|
76
84
|
team: TeamModel;
|
|
77
85
|
getTeam: Sequelize.BelongsToGetAssociationMixin<TeamModel>;
|
|
78
86
|
setTeam: Sequelize.BelongsToSetAssociationMixin<TeamModel, TeamId>;
|
|
@@ -63,6 +63,14 @@ export class TacticsModel extends Model {
|
|
|
63
63
|
type: DataTypes.JSONB,
|
|
64
64
|
allowNull: false,
|
|
65
65
|
defaultValue: []
|
|
66
|
+
},
|
|
67
|
+
system_sets: {
|
|
68
|
+
type: DataTypes.JSONB,
|
|
69
|
+
allowNull: true
|
|
70
|
+
},
|
|
71
|
+
offensive_preference_sets: {
|
|
72
|
+
type: DataTypes.JSONB,
|
|
73
|
+
allowNull: true
|
|
66
74
|
}
|
|
67
75
|
}, {
|
|
68
76
|
sequelize,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as Sequelize from 'sequelize';
|
|
2
|
+
import { Model, Optional } from 'sequelize';
|
|
3
|
+
export interface UserDeviceTokenAttributes {
|
|
4
|
+
user_device_token_id: string;
|
|
5
|
+
user_id: string;
|
|
6
|
+
device_token: string;
|
|
7
|
+
platform: string;
|
|
8
|
+
created_at?: Date;
|
|
9
|
+
updated_at?: Date;
|
|
10
|
+
}
|
|
11
|
+
export type UserDeviceTokenPk = 'user_device_token_id';
|
|
12
|
+
export type UserDeviceTokenId = UserDeviceTokenModel[UserDeviceTokenPk];
|
|
13
|
+
export type UserDeviceTokenOptionalAttributes = 'user_device_token_id' | 'platform' | 'created_at' | 'updated_at';
|
|
14
|
+
export type UserDeviceTokenCreationAttributes = Optional<UserDeviceTokenAttributes, UserDeviceTokenOptionalAttributes>;
|
|
15
|
+
export declare class UserDeviceTokenModel extends Model<UserDeviceTokenAttributes, UserDeviceTokenCreationAttributes> implements UserDeviceTokenAttributes {
|
|
16
|
+
user_device_token_id: string;
|
|
17
|
+
user_id: string;
|
|
18
|
+
device_token: string;
|
|
19
|
+
platform: string;
|
|
20
|
+
created_at?: Date;
|
|
21
|
+
updated_at?: Date;
|
|
22
|
+
static initModel(sequelize: Sequelize.Sequelize): typeof UserDeviceTokenModel;
|
|
23
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { DataTypes, Model } from 'sequelize';
|
|
2
|
+
export class UserDeviceTokenModel extends Model {
|
|
3
|
+
static initModel(sequelize) {
|
|
4
|
+
return UserDeviceTokenModel.init({
|
|
5
|
+
user_device_token_id: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
allowNull: false,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
defaultValue: DataTypes.UUIDV4
|
|
10
|
+
},
|
|
11
|
+
user_id: {
|
|
12
|
+
type: DataTypes.UUID,
|
|
13
|
+
allowNull: false,
|
|
14
|
+
references: {
|
|
15
|
+
model: 'AuthUser',
|
|
16
|
+
key: 'user_id'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
device_token: {
|
|
20
|
+
type: DataTypes.TEXT,
|
|
21
|
+
allowNull: false
|
|
22
|
+
},
|
|
23
|
+
platform: {
|
|
24
|
+
type: DataTypes.TEXT,
|
|
25
|
+
allowNull: false,
|
|
26
|
+
defaultValue: 'android'
|
|
27
|
+
},
|
|
28
|
+
created_at: {
|
|
29
|
+
type: DataTypes.DATE,
|
|
30
|
+
allowNull: false,
|
|
31
|
+
defaultValue: DataTypes.NOW
|
|
32
|
+
},
|
|
33
|
+
updated_at: {
|
|
34
|
+
type: DataTypes.DATE,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
defaultValue: DataTypes.NOW
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
sequelize,
|
|
40
|
+
tableName: 'UserDeviceToken',
|
|
41
|
+
schema: 'public',
|
|
42
|
+
timestamps: false,
|
|
43
|
+
indexes: [
|
|
44
|
+
{
|
|
45
|
+
name: 'UserDeviceToken_pk',
|
|
46
|
+
unique: true,
|
|
47
|
+
fields: [{ name: 'user_device_token_id' }]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'UserDeviceToken_user_id_device_token_uq',
|
|
51
|
+
unique: true,
|
|
52
|
+
fields: [{ name: 'user_id' }, { name: 'device_token' }]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'UserDeviceToken_user_id_idx',
|
|
56
|
+
fields: [{ name: 'user_id' }]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -73,7 +73,15 @@ function transformToAttributes(tactics, teamId) {
|
|
|
73
73
|
offensive_preferences: tactics.offensivePreferences.map(p => ({
|
|
74
74
|
rotation: p.rotation,
|
|
75
75
|
order: p.order.map((a) => a.id)
|
|
76
|
-
}))
|
|
76
|
+
})),
|
|
77
|
+
system_sets: tactics.systemSets?.map(s => ({
|
|
78
|
+
rotationSystem: s.rotationSystem,
|
|
79
|
+
designatedSetters: s.designatedSetters.map((p) => p.id)
|
|
80
|
+
})),
|
|
81
|
+
offensive_preference_sets: tactics.offensivePreferenceSets?.map(prefs => prefs.map(p => ({
|
|
82
|
+
rotation: p.rotation,
|
|
83
|
+
order: p.order.map((a) => a.id)
|
|
84
|
+
})))
|
|
77
85
|
};
|
|
78
86
|
}
|
|
79
87
|
function transformToObject(model, roster) {
|
|
@@ -140,7 +148,15 @@ function transformToObject(model, roster) {
|
|
|
140
148
|
offensivePreferences: (model.offensive_preferences ?? []).map(p => ({
|
|
141
149
|
rotation: p.rotation,
|
|
142
150
|
order: p.order.map((id) => findPlayer(id, roster))
|
|
143
|
-
}))
|
|
151
|
+
})),
|
|
152
|
+
systemSets: model.system_sets?.map(s => ({
|
|
153
|
+
rotationSystem: s.rotationSystem,
|
|
154
|
+
designatedSetters: s.designatedSetters.map((id) => findPlayer(id, roster))
|
|
155
|
+
})),
|
|
156
|
+
offensivePreferenceSets: model.offensive_preference_sets?.map(prefs => prefs.map(p => ({
|
|
157
|
+
rotation: p.rotation,
|
|
158
|
+
order: p.order.map((id) => findPlayer(id, roster))
|
|
159
|
+
})))
|
|
144
160
|
});
|
|
145
161
|
}
|
|
146
162
|
// Serialize a Tactics ROW (db columns) straight to the API Tactics DTO (player references stay as ids; no
|
|
@@ -198,7 +214,9 @@ function tacticsColumnsToApiDto(model) {
|
|
|
198
214
|
})),
|
|
199
215
|
rotationSystem: model.rotation_system,
|
|
200
216
|
designatedSetters: model.designated_setters,
|
|
201
|
-
offensivePreferences: model.offensive_preferences
|
|
217
|
+
offensivePreferences: model.offensive_preferences,
|
|
218
|
+
systemSets: model.system_sets,
|
|
219
|
+
offensivePreferenceSets: model.offensive_preference_sets
|
|
202
220
|
};
|
|
203
221
|
}
|
|
204
222
|
export { transformToObject as transformToTactics, transformToAttributes as transformFromTactics, tacticsColumnsToApiDto };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from '@jest/globals';
|
|
2
|
-
import { tacticsColumnsToApiDto } from './tactics';
|
|
3
|
-
import { CourtPosition, EnergyBand } from '../../service';
|
|
2
|
+
import { tacticsColumnsToApiDto, transformFromTactics, transformToTactics } from './tactics';
|
|
3
|
+
import { CourtPosition, EnergyBand, RotationSystemEnum, Tactics } from '../../service';
|
|
4
|
+
import { makeCountry, makePlayer } from '../../service/test-helpers';
|
|
4
5
|
// Minimal TacticsModel-shaped object; cast through unknown since the transformer only reads columns.
|
|
5
6
|
function makeTactics(designatedSubs) {
|
|
6
7
|
return {
|
|
@@ -75,4 +76,64 @@ describe('tacticsColumnsToApiDto()', () => {
|
|
|
75
76
|
expect(dto.secondLibero).toBe('reserve1');
|
|
76
77
|
expect(dto.liberoSub).toEqual({ mode: 'FATIGUE' });
|
|
77
78
|
});
|
|
79
|
+
it('passes per-set tactics columns through to the API DTO shape', () => {
|
|
80
|
+
const model = makeTactics([]);
|
|
81
|
+
model.system_sets = [{ rotationSystem: RotationSystemEnum.FIVE_ONE, designatedSetters: ['lf'] }];
|
|
82
|
+
model.offensive_preference_sets = [[{ rotation: 1, order: ['rf', 'mf'] }]];
|
|
83
|
+
const dto = tacticsColumnsToApiDto(model);
|
|
84
|
+
expect(dto.systemSets).toEqual([{ rotationSystem: '5-1', designatedSetters: ['lf'] }]);
|
|
85
|
+
expect(dto.offensivePreferenceSets).toEqual([[{ rotation: 1, order: ['rf', 'mf'] }]]);
|
|
86
|
+
});
|
|
87
|
+
it('leaves the per-set DTO fields undefined when the columns are absent', () => {
|
|
88
|
+
const dto = tacticsColumnsToApiDto(makeTactics([]));
|
|
89
|
+
expect(dto.systemSets).toBeUndefined();
|
|
90
|
+
expect(dto.offensivePreferenceSets).toBeUndefined();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('per-set tactics — service <-> row round-trip', () => {
|
|
94
|
+
const country = makeCountry();
|
|
95
|
+
const p1 = makePlayer(country);
|
|
96
|
+
const p2 = makePlayer(country);
|
|
97
|
+
const p3 = makePlayer(country);
|
|
98
|
+
const p4 = makePlayer(country);
|
|
99
|
+
const p5 = makePlayer(country);
|
|
100
|
+
const p6 = makePlayer(country);
|
|
101
|
+
const roster = [p1, p2, p3, p4, p5, p6];
|
|
102
|
+
const tactics = Tactics.create({
|
|
103
|
+
lineup: { 4: p4, 3: p3, 2: p2, 5: p5, 6: p6, 1: p1, bench: [] },
|
|
104
|
+
liberoReplacements: [],
|
|
105
|
+
systemSets: [
|
|
106
|
+
{ rotationSystem: RotationSystemEnum.FIVE_ONE, designatedSetters: [p1] },
|
|
107
|
+
{ rotationSystem: RotationSystemEnum.SIX_ZERO, designatedSetters: [] }
|
|
108
|
+
],
|
|
109
|
+
offensivePreferenceSets: [[{ rotation: 1, order: [p2, p3] }]]
|
|
110
|
+
});
|
|
111
|
+
it('transformFromTactics writes the per-set overrides as id-based jsonb columns', () => {
|
|
112
|
+
const attrs = transformFromTactics(tactics, 'team-1');
|
|
113
|
+
expect(attrs.system_sets).toEqual([
|
|
114
|
+
{ rotationSystem: '5-1', designatedSetters: [p1.id] },
|
|
115
|
+
{ rotationSystem: '6-0', designatedSetters: [] }
|
|
116
|
+
]);
|
|
117
|
+
expect(attrs.offensive_preference_sets).toEqual([[{ rotation: 1, order: [p2.id, p3.id] }]]);
|
|
118
|
+
});
|
|
119
|
+
it('transformToTactics resolves the stored ids back to roster players', () => {
|
|
120
|
+
const attrs = transformFromTactics(tactics, 'team-1');
|
|
121
|
+
const back = transformToTactics(attrs, roster);
|
|
122
|
+
expect(back.systemSets?.[0].rotationSystem).toBe(RotationSystemEnum.FIVE_ONE);
|
|
123
|
+
expect(back.systemSets?.[0].designatedSetters[0].id).toBe(p1.id);
|
|
124
|
+
expect(back.systemSets?.[1].designatedSetters).toEqual([]);
|
|
125
|
+
expect(back.offensivePreferenceSets?.[0][0].order.map(p => p.id)).toEqual([p2.id, p3.id]);
|
|
126
|
+
});
|
|
127
|
+
it('omits the per-set columns entirely for an all-sets config', () => {
|
|
128
|
+
const flat = Tactics.create({
|
|
129
|
+
lineup: { 4: p4, 3: p3, 2: p2, 5: p5, 6: p6, 1: p1, bench: [] },
|
|
130
|
+
liberoReplacements: []
|
|
131
|
+
});
|
|
132
|
+
const attrs = transformFromTactics(flat, 'team-1');
|
|
133
|
+
expect(attrs.system_sets).toBeUndefined();
|
|
134
|
+
expect(attrs.offensive_preference_sets).toBeUndefined();
|
|
135
|
+
const back = transformToTactics(attrs, roster);
|
|
136
|
+
expect(back.systemSets).toBeUndefined();
|
|
137
|
+
expect(back.offensivePreferenceSets).toBeUndefined();
|
|
138
|
+
});
|
|
78
139
|
});
|
|
@@ -115,5 +115,13 @@ export declare const TacticsInputSchema: z.ZodObject<{
|
|
|
115
115
|
rotation: z.ZodNumber;
|
|
116
116
|
order: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
117
117
|
}, z.core.$strip>>>;
|
|
118
|
+
systemSets: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
119
|
+
rotationSystem: z.ZodEnum<typeof RotationSystemEnum>;
|
|
120
|
+
designatedSetters: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
121
|
+
}, z.core.$strip>>>;
|
|
122
|
+
offensivePreferenceSets: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
123
|
+
rotation: z.ZodNumber;
|
|
124
|
+
order: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
125
|
+
}, z.core.$strip>>>>;
|
|
118
126
|
}, z.core.$strip>;
|
|
119
127
|
export type TacticsInput = z.infer<typeof TacticsInputSchema>;
|
|
@@ -51,6 +51,11 @@ const offensivePreferenceSchema = z.object({
|
|
|
51
51
|
rotation: z.number().int().min(1).max(6),
|
|
52
52
|
order: z.array(playerInstanceSchema)
|
|
53
53
|
});
|
|
54
|
+
// One set's rotation-system override (per-set tactics): system + its designated setters travel together.
|
|
55
|
+
const systemSetSchema = z.object({
|
|
56
|
+
rotationSystem: z.nativeEnum(RotationSystemEnum),
|
|
57
|
+
designatedSetters: z.array(playerInstanceSchema)
|
|
58
|
+
});
|
|
54
59
|
export const TacticsInputSchema = z.object({
|
|
55
60
|
lineup: lineupSchema,
|
|
56
61
|
liberoReplacements: z.array(playerInstanceSchema),
|
|
@@ -68,7 +73,11 @@ export const TacticsInputSchema = z.object({
|
|
|
68
73
|
// Tactics.create({...}) call valid and make an unconfigured team play exactly as before.
|
|
69
74
|
rotationSystem: z.nativeEnum(RotationSystemEnum).default(RotationSystemEnum.SIX_ZERO),
|
|
70
75
|
designatedSetters: z.array(playerInstanceSchema).default([]),
|
|
71
|
-
offensivePreferences: z.array(offensivePreferenceSchema).default([])
|
|
76
|
+
offensivePreferences: z.array(offensivePreferenceSchema).default([]),
|
|
77
|
+
// Per-set overrides (5 entries, index 0 = set 1; absent => the flat fields apply to all sets). Each entry is
|
|
78
|
+
// validated with the same cross-field rules as the flat fields (see superRefine below).
|
|
79
|
+
systemSets: z.array(systemSetSchema).max(5).optional(),
|
|
80
|
+
offensivePreferenceSets: z.array(z.array(offensivePreferenceSchema)).max(5).optional()
|
|
72
81
|
}).superRefine((data, ctx) => {
|
|
73
82
|
// Cross-field rules for the rotation system. These keep an invalid config from ever reaching the sim (the
|
|
74
83
|
// pinch-server outage was caused by an unvalidated tactics payload).
|
|
@@ -87,41 +96,54 @@ export const TacticsInputSchema = z.object({
|
|
|
87
96
|
const starters = slots.map(([position, player]) => ({ position, id: player.id }));
|
|
88
97
|
const starterIds = new Set(starters.map(s => s.id));
|
|
89
98
|
const positionById = new Map(starters.map(s => [s.id, s.position]));
|
|
90
|
-
// Designated setters: count must match the system,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!starterIds.has(setter.id)) {
|
|
97
|
-
ctx.addIssue({ code: 'custom', message: 'DESIGNATED_SETTER_NOT_A_STARTER', path: ['designatedSetters'] });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// 4-2 / 6-2: the two setters sit in opposite slots (3 rotations apart).
|
|
101
|
-
if ((data.rotationSystem === RotationSystemEnum.FOUR_TWO || data.rotationSystem === RotationSystemEnum.SIX_TWO) &&
|
|
102
|
-
data.designatedSetters.length === 2) {
|
|
103
|
-
const a = positionById.get(data.designatedSetters[0].id);
|
|
104
|
-
const b = positionById.get(data.designatedSetters[1].id);
|
|
105
|
-
if (a != null && b != null && ((((a - b) % 6) + 6) % 6) !== 3) {
|
|
106
|
-
ctx.addIssue({ code: 'custom', message: 'DESIGNATED_SETTERS_NOT_IN_OPPOSITE_SLOTS', path: ['designatedSetters'] });
|
|
99
|
+
// Designated setters: count must match the system, each must be an on-court starter, and in 4-2 / 6-2 the two
|
|
100
|
+
// setters sit in opposite slots (3 rotations apart). Run on the flat fields and on every per-set entry.
|
|
101
|
+
const validateSystem = (rotationSystem, designatedSetters, path) => {
|
|
102
|
+
const expectedSetters = setterCountFor(rotationSystem);
|
|
103
|
+
if (designatedSetters.length !== expectedSetters) {
|
|
104
|
+
ctx.addIssue({ code: 'custom', message: `DESIGNATED_SETTERS_COUNT_${rotationSystem}_EXPECTED_${expectedSetters}`, path });
|
|
107
105
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (seenRotations.has(pref.rotation)) {
|
|
113
|
-
ctx.addIssue({ code: 'custom', message: 'OFFENSIVE_PREFERENCE_DUPLICATE_ROTATION', path: ['offensivePreferences'] });
|
|
106
|
+
for (const setter of designatedSetters) {
|
|
107
|
+
if (!starterIds.has(setter.id)) {
|
|
108
|
+
ctx.addIssue({ code: 'custom', message: 'DESIGNATED_SETTER_NOT_A_STARTER', path });
|
|
109
|
+
}
|
|
114
110
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
if ((rotationSystem === RotationSystemEnum.FOUR_TWO || rotationSystem === RotationSystemEnum.SIX_TWO) &&
|
|
112
|
+
designatedSetters.length === 2) {
|
|
113
|
+
const a = positionById.get(designatedSetters[0].id);
|
|
114
|
+
const b = positionById.get(designatedSetters[1].id);
|
|
115
|
+
if (a != null && b != null && ((((a - b) % 6) + 6) % 6) !== 3) {
|
|
116
|
+
ctx.addIssue({ code: 'custom', message: 'DESIGNATED_SETTERS_NOT_IN_OPPOSITE_SLOTS', path });
|
|
117
|
+
}
|
|
119
118
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
};
|
|
120
|
+
// Offensive preferences: unique rotations, and each order lists only on-court starters with no duplicates.
|
|
121
|
+
// Run on the flat list and on every per-set list.
|
|
122
|
+
const validateOffensivePreferences = (preferences, path) => {
|
|
123
|
+
const seenRotations = new Set();
|
|
124
|
+
for (const pref of preferences) {
|
|
125
|
+
if (seenRotations.has(pref.rotation)) {
|
|
126
|
+
ctx.addIssue({ code: 'custom', message: 'OFFENSIVE_PREFERENCE_DUPLICATE_ROTATION', path });
|
|
127
|
+
}
|
|
128
|
+
seenRotations.add(pref.rotation);
|
|
129
|
+
const ids = pref.order.map(p => p.id);
|
|
130
|
+
if (new Set(ids).size !== ids.length) {
|
|
131
|
+
ctx.addIssue({ code: 'custom', message: 'OFFENSIVE_PREFERENCE_DUPLICATE_ATTACKER', path });
|
|
132
|
+
}
|
|
133
|
+
for (const id of ids) {
|
|
134
|
+
if (!starterIds.has(id)) {
|
|
135
|
+
ctx.addIssue({ code: 'custom', message: 'OFFENSIVE_PREFERENCE_ATTACKER_NOT_A_STARTER', path });
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
}
|
|
139
|
+
};
|
|
140
|
+
validateSystem(data.rotationSystem, data.designatedSetters, ['designatedSetters']);
|
|
141
|
+
for (const [i, systemSet] of (data.systemSets ?? []).entries()) {
|
|
142
|
+
validateSystem(systemSet.rotationSystem, systemSet.designatedSetters, ['systemSets', i]);
|
|
143
|
+
}
|
|
144
|
+
validateOffensivePreferences(data.offensivePreferences, ['offensivePreferences']);
|
|
145
|
+
for (const [i, preferences] of (data.offensivePreferenceSets ?? []).entries()) {
|
|
146
|
+
validateOffensivePreferences(preferences, ['offensivePreferenceSets', i]);
|
|
125
147
|
}
|
|
126
148
|
// Second libero (L2). The second libero is a reserve (not a starter, the libero, or a bench player). A swap
|
|
127
149
|
// rule (FATIGUE/ALWAYS in any set) needs someone to swap in, so it requires a second libero, and a second
|
|
@@ -67,3 +67,118 @@ describe('TacticsInputSchema — second libero rules', () => {
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
|
+
describe('TacticsInputSchema — per-set tactics (systemSets / offensivePreferenceSets)', () => {
|
|
71
|
+
const country = makeCountry();
|
|
72
|
+
const p1 = makePlayer(country);
|
|
73
|
+
const p2 = makePlayer(country);
|
|
74
|
+
const p3 = makePlayer(country);
|
|
75
|
+
const p4 = makePlayer(country);
|
|
76
|
+
const p5 = makePlayer(country);
|
|
77
|
+
const p6 = makePlayer(country);
|
|
78
|
+
const reserve = makePlayer(country);
|
|
79
|
+
// Minimal valid flat input (6-0 default: no setters, no preferences). Zone layout: p1@1, p2@2, p3@3,
|
|
80
|
+
// p4@4, p5@5, p6@6 — opposite slot pairs (3 apart) are (1,4), (2,5), (3,6).
|
|
81
|
+
function baseInput(overrides = {}) {
|
|
82
|
+
return {
|
|
83
|
+
lineup: { 4: p4, 3: p3, 2: p2, 5: p5, 6: p6, 1: p1, bench: [] },
|
|
84
|
+
liberoReplacements: [],
|
|
85
|
+
...overrides
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
it('accepts valid per-set overrides for both scopes', () => {
|
|
89
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
90
|
+
systemSets: [
|
|
91
|
+
{ rotationSystem: '5-1', designatedSetters: [p1] },
|
|
92
|
+
{ rotationSystem: '6-0', designatedSetters: [] },
|
|
93
|
+
{ rotationSystem: '4-2', designatedSetters: [p1, p4] }
|
|
94
|
+
],
|
|
95
|
+
offensivePreferenceSets: [
|
|
96
|
+
[{ rotation: 1, order: [p2, p3] }],
|
|
97
|
+
[]
|
|
98
|
+
]
|
|
99
|
+
}));
|
|
100
|
+
expect(res.success).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
it('carries the per-set fields through Tactics.create parsing', () => {
|
|
103
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
104
|
+
systemSets: [{ rotationSystem: '5-1', designatedSetters: [p1] }],
|
|
105
|
+
offensivePreferenceSets: [[{ rotation: 2, order: [p3] }]]
|
|
106
|
+
}));
|
|
107
|
+
expect(res.success).toBe(true);
|
|
108
|
+
if (res.success) {
|
|
109
|
+
expect(res.data.systemSets?.[0].rotationSystem).toBe('5-1');
|
|
110
|
+
expect(res.data.systemSets?.[0].designatedSetters[0].id).toBe(p1.id);
|
|
111
|
+
expect(res.data.offensivePreferenceSets?.[0][0]).toMatchObject({ rotation: 2 });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
it('rejects more than 5 per-set entries', () => {
|
|
115
|
+
const entry = { rotationSystem: '6-0', designatedSetters: [] };
|
|
116
|
+
expect(TacticsInputSchema.safeParse(baseInput({ systemSets: Array.from({ length: 6 }, () => entry) })).success).toBe(false);
|
|
117
|
+
expect(TacticsInputSchema.safeParse(baseInput({ offensivePreferenceSets: Array.from({ length: 6 }, () => []) })).success).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
it('rejects a set entry whose setter count does not match its system (5-1 with none)', () => {
|
|
120
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
121
|
+
systemSets: [{ rotationSystem: '5-1', designatedSetters: [] }]
|
|
122
|
+
}));
|
|
123
|
+
expect(res.success).toBe(false);
|
|
124
|
+
if (!res.success) {
|
|
125
|
+
const issue = res.error.issues.find(i => i.message === 'DESIGNATED_SETTERS_COUNT_5-1_EXPECTED_1');
|
|
126
|
+
expect(issue?.path).toEqual(['systemSets', 0]);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
it('rejects a set entry whose setter is not a court starter', () => {
|
|
130
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
131
|
+
systemSets: [
|
|
132
|
+
{ rotationSystem: '6-0', designatedSetters: [] },
|
|
133
|
+
{ rotationSystem: '5-1', designatedSetters: [reserve] }
|
|
134
|
+
]
|
|
135
|
+
}));
|
|
136
|
+
expect(res.success).toBe(false);
|
|
137
|
+
if (!res.success) {
|
|
138
|
+
const issue = res.error.issues.find(i => i.message === 'DESIGNATED_SETTER_NOT_A_STARTER');
|
|
139
|
+
expect(issue?.path).toEqual(['systemSets', 1]);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
it('rejects a 4-2 set entry whose setters are not in opposite slots', () => {
|
|
143
|
+
// p1@1 and p2@2 are adjacent (not 3 apart), so the 4-2 pair rule fails for that set entry.
|
|
144
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
145
|
+
systemSets: [{ rotationSystem: '4-2', designatedSetters: [p1, p2] }]
|
|
146
|
+
}));
|
|
147
|
+
expect(res.success).toBe(false);
|
|
148
|
+
if (!res.success) {
|
|
149
|
+
expect(res.error.issues.some(i => i.message === 'DESIGNATED_SETTERS_NOT_IN_OPPOSITE_SLOTS')).toBe(true);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
it('rejects a per-set preferences list with a duplicate rotation', () => {
|
|
153
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
154
|
+
offensivePreferenceSets: [[{ rotation: 1, order: [p2] }, { rotation: 1, order: [p3] }]]
|
|
155
|
+
}));
|
|
156
|
+
expect(res.success).toBe(false);
|
|
157
|
+
if (!res.success) {
|
|
158
|
+
const issue = res.error.issues.find(i => i.message === 'OFFENSIVE_PREFERENCE_DUPLICATE_ROTATION');
|
|
159
|
+
expect(issue?.path).toEqual(['offensivePreferenceSets', 0]);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
it('rejects a per-set preferences order that lists a non-starter', () => {
|
|
163
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
164
|
+
offensivePreferenceSets: [[{ rotation: 1, order: [reserve] }]]
|
|
165
|
+
}));
|
|
166
|
+
expect(res.success).toBe(false);
|
|
167
|
+
if (!res.success) {
|
|
168
|
+
expect(res.error.issues.some(i => i.message === 'OFFENSIVE_PREFERENCE_ATTACKER_NOT_A_STARTER')).toBe(true);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
it('still validates the flat fields when per-set overrides are present', () => {
|
|
172
|
+
// Flat 5-1 with no setter is invalid even though every set entry is valid.
|
|
173
|
+
const res = TacticsInputSchema.safeParse(baseInput({
|
|
174
|
+
rotationSystem: '5-1',
|
|
175
|
+
designatedSetters: [],
|
|
176
|
+
systemSets: [{ rotationSystem: '6-0', designatedSetters: [] }]
|
|
177
|
+
}));
|
|
178
|
+
expect(res.success).toBe(false);
|
|
179
|
+
if (!res.success) {
|
|
180
|
+
const issue = res.error.issues.find(i => i.message === 'DESIGNATED_SETTERS_COUNT_5-1_EXPECTED_1');
|
|
181
|
+
expect(issue?.path).toEqual(['designatedSetters']);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -123,6 +123,14 @@ export declare const TeamInputSchema: z.ZodObject<{
|
|
|
123
123
|
rotation: z.ZodNumber;
|
|
124
124
|
order: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
125
125
|
}, z.core.$strip>>>;
|
|
126
|
+
systemSets: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
127
|
+
rotationSystem: z.ZodEnum<typeof import("..").RotationSystemEnum>;
|
|
128
|
+
designatedSetters: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
129
|
+
}, z.core.$strip>>>;
|
|
130
|
+
offensivePreferenceSets: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
131
|
+
rotation: z.ZodNumber;
|
|
132
|
+
order: z.ZodArray<z.ZodCustom<Player, Player>>;
|
|
133
|
+
}, z.core.$strip>>>>;
|
|
126
134
|
}, z.core.$strip>>;
|
|
127
135
|
}, z.core.$strip>;
|
|
128
136
|
export type TeamInput = z.infer<typeof TeamInputSchema>;
|
|
@@ -15,6 +15,10 @@ export interface StartingLineup {
|
|
|
15
15
|
readonly [CourtPosition.LIBERO_ZONE]?: Player;
|
|
16
16
|
readonly bench: Player[];
|
|
17
17
|
}
|
|
18
|
+
export interface SystemSet {
|
|
19
|
+
readonly rotationSystem: RotationSystemEnum;
|
|
20
|
+
readonly designatedSetters: Player[];
|
|
21
|
+
}
|
|
18
22
|
export interface TacticsOpts {
|
|
19
23
|
readonly lineup: StartingLineup;
|
|
20
24
|
readonly liberoReplacements: Player[];
|
|
@@ -27,6 +31,8 @@ export interface TacticsOpts {
|
|
|
27
31
|
readonly rotationSystem: RotationSystemEnum;
|
|
28
32
|
readonly designatedSetters: Player[];
|
|
29
33
|
readonly offensivePreferences: OffensivePreference[];
|
|
34
|
+
readonly systemSets?: SystemSet[];
|
|
35
|
+
readonly offensivePreferenceSets?: OffensivePreference[][];
|
|
30
36
|
}
|
|
31
37
|
export declare class Tactics {
|
|
32
38
|
readonly lineup: StartingLineup;
|
|
@@ -40,6 +46,8 @@ export declare class Tactics {
|
|
|
40
46
|
readonly rotationSystem: RotationSystemEnum;
|
|
41
47
|
readonly designatedSetters: Player[];
|
|
42
48
|
readonly offensivePreferences: OffensivePreference[];
|
|
49
|
+
readonly systemSets?: SystemSet[];
|
|
50
|
+
readonly offensivePreferenceSets?: OffensivePreference[][];
|
|
43
51
|
static create(input: unknown): Tactics;
|
|
44
52
|
private constructor();
|
|
45
53
|
findPlayerInLineup(id: string): CourtPosition | undefined;
|
|
@@ -15,7 +15,7 @@ export class Tactics {
|
|
|
15
15
|
}
|
|
16
16
|
return new Tactics(result.data);
|
|
17
17
|
}
|
|
18
|
-
constructor({ lineup, liberoReplacements, receiveRotationOffset = false, designatedSubs = [], substitutionBand = EnergyBand.TIRED, secondLibero, liberoSub, liberoReplacementSets, rotationSystem = RotationSystemEnum.SIX_ZERO, designatedSetters = [], offensivePreferences = [] }) {
|
|
18
|
+
constructor({ lineup, liberoReplacements, receiveRotationOffset = false, designatedSubs = [], substitutionBand = EnergyBand.TIRED, secondLibero, liberoSub, liberoReplacementSets, rotationSystem = RotationSystemEnum.SIX_ZERO, designatedSetters = [], offensivePreferences = [], systemSets, offensivePreferenceSets }) {
|
|
19
19
|
this.lineup = lineup;
|
|
20
20
|
this.liberoReplacements = liberoReplacements;
|
|
21
21
|
this.receiveRotationOffset = receiveRotationOffset;
|
|
@@ -27,6 +27,8 @@ export class Tactics {
|
|
|
27
27
|
this.rotationSystem = rotationSystem;
|
|
28
28
|
this.designatedSetters = designatedSetters;
|
|
29
29
|
this.offensivePreferences = offensivePreferences;
|
|
30
|
+
this.systemSets = systemSets;
|
|
31
|
+
this.offensivePreferenceSets = offensivePreferenceSets;
|
|
30
32
|
}
|
|
31
33
|
findPlayerInLineup(id) {
|
|
32
34
|
if (this.lineup.bench.some(p => p.id === id))
|