volleyballsimtypes 0.0.481 → 0.0.483
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 +10 -18
- package/dist/cjs/src/data/models/tactics.d.ts +17 -19
- package/dist/cjs/src/data/models/tactics.js +9 -0
- package/dist/cjs/src/data/transformers/match-preset-override.test.js +10 -1
- package/dist/cjs/src/data/transformers/rally-event.d.ts +2 -1
- package/dist/cjs/src/data/transformers/rally-event.js +12 -0
- package/dist/cjs/src/data/transformers/rally.js +2 -0
- package/dist/cjs/src/data/transformers/rally.test.d.ts +1 -0
- package/dist/cjs/src/data/transformers/rally.test.js +62 -0
- package/dist/cjs/src/data/transformers/tactics.js +38 -58
- package/dist/cjs/src/data/transformers/tactics.test.js +39 -20
- package/dist/cjs/src/service/team/blocking-preference.d.ts +5 -0
- package/dist/cjs/src/service/team/blocking-preference.js +2 -0
- package/dist/cjs/src/service/team/designated-sub.d.ts +2 -4
- package/dist/cjs/src/service/team/index.d.ts +2 -0
- package/dist/cjs/src/service/team/index.js +2 -0
- package/dist/cjs/src/service/team/libero-sub.d.ts +0 -4
- package/dist/cjs/src/service/team/offensive-preference.d.ts +1 -2
- package/dist/cjs/src/service/team/pinch-condition.d.ts +11 -3
- package/dist/cjs/src/service/team/pinch-condition.js +9 -4
- package/dist/cjs/src/service/team/schemas/designated-sub.z.d.ts +30 -32
- package/dist/cjs/src/service/team/schemas/designated-sub.z.js +27 -23
- package/dist/cjs/src/service/team/schemas/designated-sub.z.test.js +4 -2
- package/dist/cjs/src/service/team/schemas/libero-sub.z.d.ts +15 -34
- package/dist/cjs/src/service/team/schemas/libero-sub.z.js +10 -26
- package/dist/cjs/src/service/team/schemas/libero-sub.z.test.js +74 -35
- package/dist/cjs/src/service/team/schemas/tactics.z.d.ts +39 -39
- package/dist/cjs/src/service/team/schemas/tactics.z.js +47 -13
- package/dist/cjs/src/service/team/schemas/tactics.z.test.js +81 -8
- package/dist/cjs/src/service/team/schemas/team.z.d.ts +38 -38
- package/dist/cjs/src/service/team/sub-config-convert.d.ts +13 -0
- package/dist/cjs/src/service/team/sub-config-convert.js +91 -0
- package/dist/cjs/src/service/team/sub-config-convert.test.d.ts +1 -0
- package/dist/cjs/src/service/team/sub-config-convert.test.js +84 -0
- package/dist/cjs/src/service/team/tactics.d.ts +5 -0
- package/dist/cjs/src/service/team/tactics.js +3 -1
- package/dist/esm/src/api/index.d.ts +10 -18
- package/dist/esm/src/data/models/tactics.d.ts +17 -19
- package/dist/esm/src/data/models/tactics.js +9 -0
- package/dist/esm/src/data/transformers/match-preset-override.test.js +10 -1
- package/dist/esm/src/data/transformers/rally-event.d.ts +2 -1
- package/dist/esm/src/data/transformers/rally-event.js +12 -1
- package/dist/esm/src/data/transformers/rally.js +4 -2
- package/dist/esm/src/data/transformers/rally.test.d.ts +1 -0
- package/dist/esm/src/data/transformers/rally.test.js +60 -0
- package/dist/esm/src/data/transformers/tactics.js +39 -59
- package/dist/esm/src/data/transformers/tactics.test.js +40 -21
- package/dist/esm/src/service/team/blocking-preference.d.ts +5 -0
- package/dist/esm/src/service/team/blocking-preference.js +1 -0
- package/dist/esm/src/service/team/designated-sub.d.ts +2 -4
- package/dist/esm/src/service/team/index.d.ts +2 -0
- package/dist/esm/src/service/team/index.js +2 -0
- package/dist/esm/src/service/team/libero-sub.d.ts +0 -4
- package/dist/esm/src/service/team/offensive-preference.d.ts +1 -2
- package/dist/esm/src/service/team/pinch-condition.d.ts +11 -3
- package/dist/esm/src/service/team/pinch-condition.js +9 -4
- package/dist/esm/src/service/team/schemas/designated-sub.z.d.ts +30 -32
- package/dist/esm/src/service/team/schemas/designated-sub.z.js +26 -22
- package/dist/esm/src/service/team/schemas/designated-sub.z.test.js +4 -2
- package/dist/esm/src/service/team/schemas/libero-sub.z.d.ts +15 -34
- package/dist/esm/src/service/team/schemas/libero-sub.z.js +9 -25
- package/dist/esm/src/service/team/schemas/libero-sub.z.test.js +75 -36
- package/dist/esm/src/service/team/schemas/tactics.z.d.ts +39 -39
- package/dist/esm/src/service/team/schemas/tactics.z.js +48 -14
- package/dist/esm/src/service/team/schemas/tactics.z.test.js +81 -8
- package/dist/esm/src/service/team/schemas/team.z.d.ts +38 -38
- package/dist/esm/src/service/team/sub-config-convert.d.ts +13 -0
- package/dist/esm/src/service/team/sub-config-convert.js +85 -0
- package/dist/esm/src/service/team/sub-config-convert.test.d.ts +1 -0
- package/dist/esm/src/service/team/sub-config-convert.test.js +82 -0
- package/dist/esm/src/service/team/tactics.d.ts +5 -0
- package/dist/esm/src/service/team/tactics.js +3 -1
- package/package.json +1 -1
|
@@ -7,9 +7,11 @@ export * from './energy-band';
|
|
|
7
7
|
export * from './pinch-condition';
|
|
8
8
|
export * from './designated-sub';
|
|
9
9
|
export * from './libero-sub';
|
|
10
|
+
export * from './sub-config-convert';
|
|
10
11
|
export * from './rotation-system';
|
|
11
12
|
export * from './lineup-function';
|
|
12
13
|
export * from './base-position';
|
|
13
14
|
export * from './offensive-preference';
|
|
15
|
+
export * from './blocking-preference';
|
|
14
16
|
export * from './injury-replacement';
|
|
15
17
|
export * from './libero-injury';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { EnergyBand } from './energy-band';
|
|
2
1
|
import { ConditionLogic, PinchCondition } from './pinch-condition';
|
|
3
|
-
export type LiberoSubMode = 'NEVER' | 'FATIGUE' | 'ALWAYS' | 'CONDITIONS';
|
|
4
2
|
export interface LiberoSetSubConfig {
|
|
5
|
-
readonly mode: LiberoSubMode;
|
|
6
|
-
readonly fatigueBand?: EnergyBand;
|
|
7
3
|
readonly conditions?: PinchCondition[];
|
|
8
4
|
readonly conditionLogic?: ConditionLogic;
|
|
9
5
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Player } from '../player';
|
|
2
1
|
export type TempoPreference = 'FAST' | 'HIGH';
|
|
3
2
|
export interface OffensivePreference {
|
|
4
3
|
readonly rotation: number;
|
|
5
|
-
readonly
|
|
4
|
+
readonly weights: Record<string, number>;
|
|
6
5
|
readonly tempos?: Record<string, TempoPreference>;
|
|
7
6
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { EnergyBand, SubBand } from './energy-band';
|
|
1
2
|
export declare enum PinchConditionType {
|
|
2
|
-
ASAP = "ASAP",//
|
|
3
|
+
ASAP = "ASAP",// unconditionally true (pinch server: every serve gain; libero rule: "Always")
|
|
3
4
|
TEAM_SET_POINT = "TEAM_SET_POINT",// team within `margin` of winning the set
|
|
4
5
|
OPPONENT_SET_POINT = "OPPONENT_SET_POINT",// opponent within `margin` of winning the set
|
|
5
6
|
SCORE_DIFF = "SCORE_DIFF",// team trailing/leading by at least `points`
|
|
@@ -7,7 +8,8 @@ export declare enum PinchConditionType {
|
|
|
7
8
|
FROM_SET = "FROM_SET",// only set N or later
|
|
8
9
|
MIN_OWN_SCORE = "MIN_OWN_SCORE",// only once own score >= N
|
|
9
10
|
MIN_OPPONENT_SCORE = "MIN_OPPONENT_SCORE",// only once opponent score >= N
|
|
10
|
-
PHASE = "PHASE"
|
|
11
|
+
PHASE = "PHASE",// the team is serving or receiving this rally (used by the libero deployment rule)
|
|
12
|
+
FATIGUE = "FATIGUE"
|
|
11
13
|
}
|
|
12
14
|
export declare enum MatchPhase {
|
|
13
15
|
SERVING = "SERVING",
|
|
@@ -66,7 +68,11 @@ export interface PhaseCondition {
|
|
|
66
68
|
readonly type: PinchConditionType.PHASE;
|
|
67
69
|
readonly phase: MatchPhase;
|
|
68
70
|
}
|
|
69
|
-
export
|
|
71
|
+
export interface FatigueCondition {
|
|
72
|
+
readonly type: PinchConditionType.FATIGUE;
|
|
73
|
+
readonly band?: EnergyBand;
|
|
74
|
+
}
|
|
75
|
+
export type PinchCondition = AsapCondition | TeamSetPointCondition | OpponentSetPointCondition | ScoreDiffCondition | AfterRotationsCondition | FromSetCondition | MinOwnScoreCondition | MinOpponentScoreCondition | PhaseCondition | FatigueCondition;
|
|
70
76
|
export type ConditionLogic = 'ALL' | 'ANY';
|
|
71
77
|
export interface PinchSetState {
|
|
72
78
|
readonly ownScore: number;
|
|
@@ -75,4 +81,6 @@ export interface PinchSetState {
|
|
|
75
81
|
readonly setNumber: number;
|
|
76
82
|
readonly ownServeTurns: number;
|
|
77
83
|
readonly phase: MatchPhase;
|
|
84
|
+
readonly subjectBand?: EnergyBand;
|
|
85
|
+
readonly defaultBand?: SubBand;
|
|
78
86
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// state
|
|
1
|
+
// The ONE condition vocabulary of the substitution engine (owner 2026-07-11): designated substitutions,
|
|
2
|
+
// pinch servers, sub-backs, and the libero deployment rule all evaluate the same catalog against the live
|
|
3
|
+
// set state, combined with ALL (every condition must hold) or ANY (one is enough). A config with NO
|
|
4
|
+
// conditions never fires.
|
|
4
5
|
export var PinchConditionType;
|
|
5
6
|
(function (PinchConditionType) {
|
|
6
7
|
PinchConditionType["ASAP"] = "ASAP";
|
|
@@ -11,7 +12,11 @@ export var PinchConditionType;
|
|
|
11
12
|
PinchConditionType["FROM_SET"] = "FROM_SET";
|
|
12
13
|
PinchConditionType["MIN_OWN_SCORE"] = "MIN_OWN_SCORE";
|
|
13
14
|
PinchConditionType["MIN_OPPONENT_SCORE"] = "MIN_OPPONENT_SCORE";
|
|
14
|
-
PinchConditionType["PHASE"] = "PHASE";
|
|
15
|
+
PinchConditionType["PHASE"] = "PHASE";
|
|
16
|
+
// The SUBJECT player's energy is at-or-worse than `band` (absent band = the team `substitutionBand`). The
|
|
17
|
+
// subject comes from the evaluation context, never from the condition: sub-in conditions judge the STARTER
|
|
18
|
+
// on court, sub-back conditions judge the SUBSTITUTE on court, the libero rule judges the STARTING libero.
|
|
19
|
+
PinchConditionType["FATIGUE"] = "FATIGUE";
|
|
15
20
|
})(PinchConditionType || (PinchConditionType = {}));
|
|
16
21
|
// Which side of the rally the team is on. Known at each dead ball: the serving team is SERVING, the other
|
|
17
22
|
// RECEIVING. Consumed by the PHASE condition (libero deployment); pinch servers always evaluate while SERVING.
|
|
@@ -34,26 +34,17 @@ export declare const PinchConditionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<
|
|
|
34
34
|
}, z.core.$strip>, z.ZodObject<{
|
|
35
35
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
36
36
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
37
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
38
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
39
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
37
40
|
}, z.core.$strip>], "type">;
|
|
38
41
|
export declare const ConditionLogicSchema: z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>;
|
|
39
|
-
export declare const SubModeSchema: z.ZodEnum<{
|
|
40
|
-
NEVER: "NEVER";
|
|
41
|
-
FATIGUE: "FATIGUE";
|
|
42
|
-
PINCH: "PINCH";
|
|
43
|
-
}>;
|
|
44
42
|
export declare const SubBackModeSchema: z.ZodEnum<{
|
|
45
43
|
FATIGUE: "FATIGUE";
|
|
46
44
|
CONDITIONS: "CONDITIONS";
|
|
47
45
|
}>;
|
|
48
|
-
export declare const SetSubConfigSchema: z.ZodObject<{
|
|
49
|
-
mode: z.ZodEnum<{
|
|
50
|
-
NEVER: "NEVER";
|
|
51
|
-
FATIGUE: "FATIGUE";
|
|
52
|
-
PINCH: "PINCH";
|
|
53
|
-
}>;
|
|
46
|
+
export declare const SetSubConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
54
47
|
bench: z.ZodOptional<z.ZodCustom<Player, Player>>;
|
|
55
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
56
|
-
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
57
48
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
58
49
|
type: z.ZodLiteral<PinchConditionType.ASAP>;
|
|
59
50
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -85,9 +76,13 @@ export declare const SetSubConfigSchema: z.ZodObject<{
|
|
|
85
76
|
}, z.core.$strip>, z.ZodObject<{
|
|
86
77
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
87
78
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
79
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
80
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
81
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
88
82
|
}, z.core.$strip>], "type">>>;
|
|
89
83
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
90
84
|
pinchServer: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
91
86
|
subBackMode: z.ZodOptional<z.ZodEnum<{
|
|
92
87
|
FATIGUE: "FATIGUE";
|
|
93
88
|
CONDITIONS: "CONDITIONS";
|
|
@@ -123,19 +118,15 @@ export declare const SetSubConfigSchema: z.ZodObject<{
|
|
|
123
118
|
}, z.core.$strip>, z.ZodObject<{
|
|
124
119
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
125
120
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
121
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
122
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
123
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
126
124
|
}, z.core.$strip>], "type">>>;
|
|
127
125
|
subBackConditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
128
|
-
}, z.core.$strip
|
|
129
|
-
export declare const DesignatedSubSchema: z.ZodObject<{
|
|
130
|
-
sets: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
131
|
-
mode: z.ZodEnum<{
|
|
132
|
-
NEVER: "NEVER";
|
|
133
|
-
FATIGUE: "FATIGUE";
|
|
134
|
-
PINCH: "PINCH";
|
|
135
|
-
}>;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
export declare const DesignatedSubSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
128
|
+
sets: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
136
129
|
bench: z.ZodOptional<z.ZodCustom<Player, Player>>;
|
|
137
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
138
|
-
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
139
130
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
140
131
|
type: z.ZodLiteral<PinchConditionType.ASAP>;
|
|
141
132
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -167,9 +158,13 @@ export declare const DesignatedSubSchema: z.ZodObject<{
|
|
|
167
158
|
}, z.core.$strip>, z.ZodObject<{
|
|
168
159
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
169
160
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
161
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
162
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
163
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
170
164
|
}, z.core.$strip>], "type">>>;
|
|
171
165
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
172
166
|
pinchServer: z.ZodOptional<z.ZodBoolean>;
|
|
167
|
+
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
173
168
|
subBackMode: z.ZodOptional<z.ZodEnum<{
|
|
174
169
|
FATIGUE: "FATIGUE";
|
|
175
170
|
CONDITIONS: "CONDITIONS";
|
|
@@ -205,17 +200,13 @@ export declare const DesignatedSubSchema: z.ZodObject<{
|
|
|
205
200
|
}, z.core.$strip>, z.ZodObject<{
|
|
206
201
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
207
202
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
203
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
204
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
205
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
208
206
|
}, z.core.$strip>], "type">>>;
|
|
209
207
|
subBackConditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
210
|
-
}, z.core.$strip
|
|
211
|
-
mode: z.ZodEnum<{
|
|
212
|
-
NEVER: "NEVER";
|
|
213
|
-
FATIGUE: "FATIGUE";
|
|
214
|
-
PINCH: "PINCH";
|
|
215
|
-
}>;
|
|
208
|
+
}, z.core.$strip>>>>;
|
|
216
209
|
bench: z.ZodOptional<z.ZodCustom<Player, Player>>;
|
|
217
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
218
|
-
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
219
210
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
220
211
|
type: z.ZodLiteral<PinchConditionType.ASAP>;
|
|
221
212
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -247,9 +238,13 @@ export declare const DesignatedSubSchema: z.ZodObject<{
|
|
|
247
238
|
}, z.core.$strip>, z.ZodObject<{
|
|
248
239
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
249
240
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
241
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
242
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
243
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
250
244
|
}, z.core.$strip>], "type">>>;
|
|
251
245
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
252
246
|
pinchServer: z.ZodOptional<z.ZodBoolean>;
|
|
247
|
+
benchFatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
253
248
|
subBackMode: z.ZodOptional<z.ZodEnum<{
|
|
254
249
|
FATIGUE: "FATIGUE";
|
|
255
250
|
CONDITIONS: "CONDITIONS";
|
|
@@ -285,7 +280,10 @@ export declare const DesignatedSubSchema: z.ZodObject<{
|
|
|
285
280
|
}, z.core.$strip>, z.ZodObject<{
|
|
286
281
|
type: z.ZodLiteral<PinchConditionType.PHASE>;
|
|
287
282
|
phase: z.ZodEnum<typeof MatchPhase>;
|
|
283
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
284
|
+
type: z.ZodLiteral<PinchConditionType.FATIGUE>;
|
|
285
|
+
band: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
288
286
|
}, z.core.$strip>], "type">>>;
|
|
289
287
|
subBackConditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
290
288
|
starter: z.ZodCustom<Player, Player>;
|
|
291
|
-
}, z.core.$strip
|
|
289
|
+
}, z.core.$strip>>;
|
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { Player } from '../../player';
|
|
3
3
|
import { EnergyBand } from '../energy-band';
|
|
4
4
|
import { Comparison, MatchPhase, OpponentRelation, PinchConditionType, ScoreDirection } from '../pinch-condition';
|
|
5
|
+
import { convertLegacyDesignatedSub, convertLegacySetSubConfig } from '../sub-config-convert';
|
|
5
6
|
const playerInstanceSchema = z.custom((v) => v instanceof Player, {
|
|
6
7
|
message: 'INVALID_PLAYER_INSTANCE'
|
|
7
8
|
});
|
|
@@ -18,44 +19,47 @@ export const PinchConditionSchema = z.discriminatedUnion('type', [
|
|
|
18
19
|
z.object({ type: z.literal(PinchConditionType.MIN_OWN_SCORE), score: z.number().int().min(0).max(40), comparison: z.nativeEnum(Comparison).optional() }),
|
|
19
20
|
z.object({ type: z.literal(PinchConditionType.MIN_OPPONENT_SCORE), score: z.number().int().min(0).max(40), comparison: z.nativeEnum(Comparison).optional() }),
|
|
20
21
|
// PHASE is used by the libero deployment rule (which reuses this schema); pinch servers never offer it.
|
|
21
|
-
z.object({ type: z.literal(PinchConditionType.PHASE), phase: z.nativeEnum(MatchPhase) })
|
|
22
|
+
z.object({ type: z.literal(PinchConditionType.PHASE), phase: z.nativeEnum(MatchPhase) }),
|
|
23
|
+
// The subject player's energy is at-or-worse than `band` (absent = the team `substitutionBand`); the
|
|
24
|
+
// subject comes from the evaluation context (starter / substitute / starting libero).
|
|
25
|
+
z.object({ type: z.literal(PinchConditionType.FATIGUE), band: z.nativeEnum(EnergyBand).optional() })
|
|
22
26
|
]);
|
|
23
27
|
export const ConditionLogicSchema = z.union([z.literal('ALL'), z.literal('ANY')]);
|
|
24
|
-
export const SubModeSchema = z.enum(['FATIGUE', 'PINCH', 'NEVER']);
|
|
25
28
|
export const SubBackModeSchema = z.enum(['FATIGUE', 'CONDITIONS']);
|
|
26
|
-
// Fields shared by the all-sets config and each per-set config.
|
|
29
|
+
// Fields shared by the all-sets config and each per-set config. Pure condition engine (owner 2026-07-11):
|
|
30
|
+
// no mode; `conditions` is the sub-in trigger and an EMPTY/absent list means the starter is never substituted
|
|
31
|
+
// by this rule. Legacy mode-shaped inputs are auto-converted by the preprocess below.
|
|
27
32
|
const setSubConfigShape = {
|
|
28
|
-
mode: SubModeSchema,
|
|
29
33
|
bench: playerInstanceSchema.optional(),
|
|
30
|
-
fatigueBand: z.nativeEnum(EnergyBand).optional(),
|
|
31
|
-
benchFatigueBand: z.nativeEnum(EnergyBand).optional(),
|
|
32
34
|
conditions: z.array(PinchConditionSchema).optional(),
|
|
33
35
|
conditionLogic: ConditionLogicSchema.optional(),
|
|
34
|
-
//
|
|
36
|
+
// true = serve-and-return pinch server; false/absent = regular conditional sub (stays until sub-back).
|
|
35
37
|
pinchServer: z.boolean().optional(),
|
|
36
|
-
//
|
|
38
|
+
// The substitute's own pull band for FATIGUE sub-backs (absent = the team `substitutionBand`).
|
|
39
|
+
benchFatigueBand: z.nativeEnum(EnergyBand).optional(),
|
|
37
40
|
subBackMode: SubBackModeSchema.optional(),
|
|
38
41
|
subBackConditions: z.array(PinchConditionSchema).optional(),
|
|
39
42
|
subBackConditionLogic: ConditionLogicSchema.optional()
|
|
40
43
|
};
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
// A pinch server needs a designated bench player and at least one sub-in condition. A regular conditional sub
|
|
45
|
+
// with a CONDITIONS sub-back needs at least one sub-back condition. Empty sub-in conditions are otherwise
|
|
46
|
+
// VALID (= never fires).
|
|
47
|
+
function refineSubConfig(data, ctx) {
|
|
48
|
+
if (data.pinchServer === true) {
|
|
49
|
+
if (data.bench == null) {
|
|
50
|
+
ctx.addIssue({ code: 'custom', message: 'PINCH_SERVER_REQUIRES_BENCH', path: ['bench'] });
|
|
51
|
+
}
|
|
52
|
+
if (data.conditions == null || data.conditions.length === 0) {
|
|
53
|
+
ctx.addIssue({ code: 'custom', message: 'PINCH_SERVER_REQUIRES_CONDITIONS', path: ['conditions'] });
|
|
54
|
+
}
|
|
51
55
|
}
|
|
52
56
|
if (data.pinchServer !== true && data.subBackMode === 'CONDITIONS' &&
|
|
53
57
|
(data.subBackConditions == null || data.subBackConditions.length === 0)) {
|
|
54
58
|
ctx.addIssue({ code: 'custom', message: 'CONDITIONAL_SUB_BACK_REQUIRES_CONDITIONS', path: ['subBackConditions'] });
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
|
-
export const SetSubConfigSchema = z.object(setSubConfigShape).superRefine(
|
|
58
|
-
export const DesignatedSubSchema = z.object({
|
|
61
|
+
export const SetSubConfigSchema = z.preprocess(convertLegacySetSubConfig, z.object(setSubConfigShape).superRefine(refineSubConfig));
|
|
62
|
+
export const DesignatedSubSchema = z.preprocess(convertLegacyDesignatedSub, z.object({
|
|
59
63
|
starter: playerInstanceSchema,
|
|
60
64
|
...setSubConfigShape,
|
|
61
65
|
// Optional per-set overrides (index 0 = set 1 ... index 4 = set 5); absent => the flat config for all sets.
|
|
@@ -64,5 +68,5 @@ export const DesignatedSubSchema = z.object({
|
|
|
64
68
|
// The flat config is the fallback for any set a partial `sets` array doesn't cover, so validate it whenever
|
|
65
69
|
// `sets` is absent or covers fewer than 5 sets (each present per-set config is validated by SetSubConfigSchema).
|
|
66
70
|
if (data.sets == null || data.sets.length < 5)
|
|
67
|
-
|
|
68
|
-
});
|
|
71
|
+
refineSubConfig(data, ctx);
|
|
72
|
+
}));
|
|
@@ -114,12 +114,14 @@ describe('DesignatedSubSchema', () => {
|
|
|
114
114
|
});
|
|
115
115
|
expect(res.success).toBe(true);
|
|
116
116
|
});
|
|
117
|
-
it('
|
|
117
|
+
it('heals an unknown legacy mode by stripping it (lenient conversion, config stays valid)', () => {
|
|
118
118
|
const res = DesignatedSubSchema.safeParse({
|
|
119
119
|
starter,
|
|
120
120
|
mode: 'SOMETIMES'
|
|
121
121
|
});
|
|
122
|
-
expect(res.success).toBe(
|
|
122
|
+
expect(res.success).toBe(true);
|
|
123
|
+
if (res.success)
|
|
124
|
+
expect(res.data.mode).toBeUndefined();
|
|
123
125
|
});
|
|
124
126
|
it('accepts a pinch-mode entry with a bench server and conditions', () => {
|
|
125
127
|
const res = DesignatedSubSchema.safeParse({
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
3
|
-
export declare const LiberoSubModeSchema: z.ZodEnum<{
|
|
4
|
-
NEVER: "NEVER";
|
|
5
|
-
FATIGUE: "FATIGUE";
|
|
6
|
-
CONDITIONS: "CONDITIONS";
|
|
7
|
-
ALWAYS: "ALWAYS";
|
|
8
|
-
}>;
|
|
9
|
-
export declare const LiberoSetSubConfigSchema: z.ZodObject<{
|
|
10
|
-
mode: z.ZodEnum<{
|
|
11
|
-
NEVER: "NEVER";
|
|
12
|
-
FATIGUE: "FATIGUE";
|
|
13
|
-
CONDITIONS: "CONDITIONS";
|
|
14
|
-
ALWAYS: "ALWAYS";
|
|
15
|
-
}>;
|
|
16
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
2
|
+
export declare const LiberoSetSubConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
17
3
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
18
4
|
type: z.ZodLiteral<import("..").PinchConditionType.ASAP>;
|
|
19
5
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -45,18 +31,14 @@ export declare const LiberoSetSubConfigSchema: z.ZodObject<{
|
|
|
45
31
|
}, z.core.$strip>, z.ZodObject<{
|
|
46
32
|
type: z.ZodLiteral<import("..").PinchConditionType.PHASE>;
|
|
47
33
|
phase: z.ZodEnum<typeof import("..").MatchPhase>;
|
|
34
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
35
|
+
type: z.ZodLiteral<import("..").PinchConditionType.FATIGUE>;
|
|
36
|
+
band: z.ZodOptional<z.ZodEnum<typeof import("..").EnergyBand>>;
|
|
48
37
|
}, z.core.$strip>], "type">>>;
|
|
49
38
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
50
|
-
}, z.core.$strip
|
|
51
|
-
export declare const LiberoSubConfigSchema: z.ZodObject<{
|
|
52
|
-
sets: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
53
|
-
mode: z.ZodEnum<{
|
|
54
|
-
NEVER: "NEVER";
|
|
55
|
-
FATIGUE: "FATIGUE";
|
|
56
|
-
CONDITIONS: "CONDITIONS";
|
|
57
|
-
ALWAYS: "ALWAYS";
|
|
58
|
-
}>;
|
|
59
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
39
|
+
}, z.core.$strip>>;
|
|
40
|
+
export declare const LiberoSubConfigSchema: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
41
|
+
sets: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodObject<{
|
|
60
42
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
61
43
|
type: z.ZodLiteral<import("..").PinchConditionType.ASAP>;
|
|
62
44
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -88,16 +70,12 @@ export declare const LiberoSubConfigSchema: z.ZodObject<{
|
|
|
88
70
|
}, z.core.$strip>, z.ZodObject<{
|
|
89
71
|
type: z.ZodLiteral<import("..").PinchConditionType.PHASE>;
|
|
90
72
|
phase: z.ZodEnum<typeof import("..").MatchPhase>;
|
|
73
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
74
|
+
type: z.ZodLiteral<import("..").PinchConditionType.FATIGUE>;
|
|
75
|
+
band: z.ZodOptional<z.ZodEnum<typeof import("..").EnergyBand>>;
|
|
91
76
|
}, z.core.$strip>], "type">>>;
|
|
92
77
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
93
|
-
}, z.core.$strip
|
|
94
|
-
mode: z.ZodEnum<{
|
|
95
|
-
NEVER: "NEVER";
|
|
96
|
-
FATIGUE: "FATIGUE";
|
|
97
|
-
CONDITIONS: "CONDITIONS";
|
|
98
|
-
ALWAYS: "ALWAYS";
|
|
99
|
-
}>;
|
|
100
|
-
fatigueBand: z.ZodOptional<z.ZodEnum<typeof EnergyBand>>;
|
|
78
|
+
}, z.core.$strip>>>>;
|
|
101
79
|
conditions: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
102
80
|
type: z.ZodLiteral<import("..").PinchConditionType.ASAP>;
|
|
103
81
|
}, z.core.$strip>, z.ZodObject<{
|
|
@@ -129,6 +107,9 @@ export declare const LiberoSubConfigSchema: z.ZodObject<{
|
|
|
129
107
|
}, z.core.$strip>, z.ZodObject<{
|
|
130
108
|
type: z.ZodLiteral<import("..").PinchConditionType.PHASE>;
|
|
131
109
|
phase: z.ZodEnum<typeof import("..").MatchPhase>;
|
|
110
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
111
|
+
type: z.ZodLiteral<import("..").PinchConditionType.FATIGUE>;
|
|
112
|
+
band: z.ZodOptional<z.ZodEnum<typeof import("..").EnergyBand>>;
|
|
132
113
|
}, z.core.$strip>], "type">>>;
|
|
133
114
|
conditionLogic: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"ALL">, z.ZodLiteral<"ANY">]>>;
|
|
134
|
-
}, z.core.$strip
|
|
115
|
+
}, z.core.$strip>>;
|
|
@@ -1,34 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { convertLegacyLiberoSetSubConfig, convertLegacyLiberoSubConfig } from '../sub-config-convert';
|
|
3
3
|
import { ConditionLogicSchema, PinchConditionSchema } from './designated-sub.z';
|
|
4
|
-
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// Pure condition engine (owner 2026-07-11): the second libero is active while `conditions` hold (combined
|
|
5
|
+
// per `conditionLogic`, default ALL; the STARTING libero is the FATIGUE-condition subject). No conditions =
|
|
6
|
+
// the starting libero always plays; [{ASAP}] = always the second libero (the old ALWAYS). The swapped-in
|
|
7
|
+
// player is always the dedicated `secondLibero`, so there is no bench to validate. Legacy mode-shaped
|
|
8
|
+
// configs (NEVER/FATIGUE/ALWAYS/CONDITIONS) are auto-converted by the preprocess.
|
|
8
9
|
const liberoSetSubConfigShape = {
|
|
9
|
-
mode: LiberoSubModeSchema,
|
|
10
|
-
// fatigue mode only (absent => the team default `substitutionBand`):
|
|
11
|
-
fatigueBand: z.nativeEnum(EnergyBand).optional(),
|
|
12
|
-
// conditions mode only:
|
|
13
10
|
conditions: z.array(PinchConditionSchema).optional(),
|
|
14
11
|
conditionLogic: ConditionLogicSchema.optional()
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (data.mode !== 'CONDITIONS')
|
|
19
|
-
return;
|
|
20
|
-
if (data.conditions == null || data.conditions.length === 0) {
|
|
21
|
-
ctx.addIssue({ code: 'custom', message: 'LIBERO_CONDITIONS_REQUIRE_A_CONDITION', path: ['conditions'] });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export const LiberoSetSubConfigSchema = z.object(liberoSetSubConfigShape).superRefine(refineConditions);
|
|
25
|
-
export const LiberoSubConfigSchema = z.object({
|
|
13
|
+
export const LiberoSetSubConfigSchema = z.preprocess(convertLegacyLiberoSetSubConfig, z.object(liberoSetSubConfigShape));
|
|
14
|
+
export const LiberoSubConfigSchema = z.preprocess(convertLegacyLiberoSubConfig, z.object({
|
|
26
15
|
...liberoSetSubConfigShape,
|
|
27
16
|
// Optional per-set overrides (index 0 = set 1 ... index 4 = set 5); absent => the flat config for all sets.
|
|
28
17
|
sets: z.array(LiberoSetSubConfigSchema).max(5).optional()
|
|
29
|
-
})
|
|
30
|
-
// The flat config is the fallback for any set a partial `sets` array doesn't cover, so validate it whenever
|
|
31
|
-
// `sets` is absent or covers fewer than 5 sets (each present per-set config is validated by its own schema).
|
|
32
|
-
if (data.sets == null || data.sets.length < 5)
|
|
33
|
-
refineConditions(data, ctx);
|
|
34
|
-
});
|
|
18
|
+
}));
|
|
@@ -1,86 +1,125 @@
|
|
|
1
1
|
import { describe, it, expect } from '@jest/globals';
|
|
2
|
-
import { LiberoSetSubConfigSchema, LiberoSubConfigSchema
|
|
2
|
+
import { LiberoSetSubConfigSchema, LiberoSubConfigSchema } from './libero-sub.z';
|
|
3
3
|
import { EnergyBand } from '../energy-band';
|
|
4
4
|
import { MatchPhase, PinchConditionType } from '../pinch-condition';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
// Unified condition engine (owner 2026-07-11): the libero rule is a pure condition list; legacy mode-shaped
|
|
6
|
+
// configs (NEVER/FATIGUE/ALWAYS/CONDITIONS) auto-convert in the schema preprocess.
|
|
7
|
+
describe('LiberoSetSubConfigSchema (unified)', () => {
|
|
8
|
+
it('accepts an empty config (no conditions = the starting libero always plays)', () => {
|
|
9
|
+
const res = LiberoSetSubConfigSchema.safeParse({});
|
|
10
|
+
expect(res.success).toBe(true);
|
|
11
|
+
if (res.success)
|
|
12
|
+
expect(res.data.conditions ?? []).toHaveLength(0);
|
|
13
13
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
it('accepts a FATIGUE condition with a band', () => {
|
|
15
|
+
const res = LiberoSetSubConfigSchema.safeParse({
|
|
16
|
+
conditions: [{ type: PinchConditionType.FATIGUE, band: EnergyBand.TIRED }]
|
|
17
|
+
});
|
|
18
|
+
expect(res.success).toBe(true);
|
|
18
19
|
});
|
|
19
|
-
it('accepts a
|
|
20
|
-
expect(LiberoSetSubConfigSchema.safeParse({
|
|
20
|
+
it('accepts a FATIGUE condition without a band (team default)', () => {
|
|
21
|
+
expect(LiberoSetSubConfigSchema.safeParse({ conditions: [{ type: PinchConditionType.FATIGUE }] }).success).toBe(true);
|
|
21
22
|
});
|
|
22
|
-
it('rejects an unknown band', () => {
|
|
23
|
-
expect(LiberoSetSubConfigSchema.safeParse({
|
|
23
|
+
it('rejects a FATIGUE condition with an unknown band', () => {
|
|
24
|
+
expect(LiberoSetSubConfigSchema.safeParse({ conditions: [{ type: PinchConditionType.FATIGUE, band: 'SLEEPY' }] }).success).toBe(false);
|
|
24
25
|
});
|
|
25
|
-
it('accepts
|
|
26
|
+
it('accepts a PHASE condition (serve/receive split)', () => {
|
|
26
27
|
const res = LiberoSetSubConfigSchema.safeParse({
|
|
27
|
-
mode: 'CONDITIONS',
|
|
28
28
|
conditionLogic: 'ALL',
|
|
29
29
|
conditions: [{ type: PinchConditionType.PHASE, phase: MatchPhase.RECEIVING }]
|
|
30
30
|
});
|
|
31
31
|
expect(res.success).toBe(true);
|
|
32
32
|
});
|
|
33
|
-
it('accepts
|
|
33
|
+
it('accepts mixed conditions (score + phase + fatigue) under ANY logic', () => {
|
|
34
34
|
const res = LiberoSetSubConfigSchema.safeParse({
|
|
35
|
-
mode: 'CONDITIONS',
|
|
36
35
|
conditionLogic: 'ANY',
|
|
37
36
|
conditions: [
|
|
38
37
|
{ type: PinchConditionType.MIN_OWN_SCORE, score: 20 },
|
|
39
|
-
{ type: PinchConditionType.PHASE, phase: MatchPhase.SERVING }
|
|
38
|
+
{ type: PinchConditionType.PHASE, phase: MatchPhase.SERVING },
|
|
39
|
+
{ type: PinchConditionType.FATIGUE, band: EnergyBand.EXHAUSTED }
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
42
|
expect(res.success).toBe(true);
|
|
43
43
|
});
|
|
44
|
-
it('rejects CONDITIONS mode with no conditions', () => {
|
|
45
|
-
expect(LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS' }).success).toBe(false);
|
|
46
|
-
expect(LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS', conditions: [] }).success).toBe(false);
|
|
47
|
-
});
|
|
48
44
|
it('rejects an invalid PHASE value', () => {
|
|
49
45
|
const res = LiberoSetSubConfigSchema.safeParse({
|
|
50
|
-
mode: 'CONDITIONS',
|
|
51
46
|
conditions: [{ type: PinchConditionType.PHASE, phase: 'ATTACKING' }]
|
|
52
47
|
});
|
|
53
48
|
expect(res.success).toBe(false);
|
|
54
49
|
});
|
|
55
50
|
});
|
|
51
|
+
describe('LiberoSetSubConfigSchema (legacy conversion)', () => {
|
|
52
|
+
it('converts legacy NEVER to an empty condition list', () => {
|
|
53
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'NEVER' });
|
|
54
|
+
expect(res.success).toBe(true);
|
|
55
|
+
if (res.success)
|
|
56
|
+
expect(res.data.conditions).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
it('converts legacy ALWAYS to a single ASAP condition', () => {
|
|
59
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'ALWAYS' });
|
|
60
|
+
expect(res.success).toBe(true);
|
|
61
|
+
if (res.success)
|
|
62
|
+
expect(res.data.conditions).toEqual([{ type: PinchConditionType.ASAP }]);
|
|
63
|
+
});
|
|
64
|
+
it('converts legacy FATIGUE + band to a FATIGUE condition carrying the band', () => {
|
|
65
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: EnergyBand.WORN });
|
|
66
|
+
expect(res.success).toBe(true);
|
|
67
|
+
if (res.success)
|
|
68
|
+
expect(res.data.conditions).toEqual([{ type: PinchConditionType.FATIGUE, band: EnergyBand.WORN }]);
|
|
69
|
+
});
|
|
70
|
+
it('converts legacy FATIGUE without a band to a bandless FATIGUE condition (team default)', () => {
|
|
71
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE' });
|
|
72
|
+
expect(res.success).toBe(true);
|
|
73
|
+
if (res.success)
|
|
74
|
+
expect(res.data.conditions).toEqual([{ type: PinchConditionType.FATIGUE }]);
|
|
75
|
+
});
|
|
76
|
+
it('converts legacy CONDITIONS by stripping the mode and keeping the conditions', () => {
|
|
77
|
+
const conditions = [{ type: PinchConditionType.PHASE, phase: MatchPhase.RECEIVING }];
|
|
78
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS', conditionLogic: 'ALL', conditions });
|
|
79
|
+
expect(res.success).toBe(true);
|
|
80
|
+
if (res.success) {
|
|
81
|
+
expect(res.data.conditions).toEqual(conditions);
|
|
82
|
+
expect(res.data.mode).toBeUndefined();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
it('heals a legacy CONDITIONS config with no conditions to never (empty list) instead of rejecting', () => {
|
|
86
|
+
const res = LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS' });
|
|
87
|
+
expect(res.success).toBe(true);
|
|
88
|
+
if (res.success)
|
|
89
|
+
expect(res.data.conditions ?? []).toHaveLength(0);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
56
92
|
describe('LiberoSubConfigSchema', () => {
|
|
57
|
-
it('accepts a flat config with no per-set overrides', () => {
|
|
93
|
+
it('accepts a flat config with no per-set overrides (legacy shape converts)', () => {
|
|
58
94
|
expect(LiberoSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: EnergyBand.WORN }).success).toBe(true);
|
|
59
95
|
});
|
|
60
|
-
it('accepts up to five per-set configs', () => {
|
|
96
|
+
it('accepts up to five per-set configs (legacy per-set entries convert)', () => {
|
|
61
97
|
const res = LiberoSubConfigSchema.safeParse({
|
|
62
98
|
mode: 'NEVER',
|
|
63
99
|
sets: [
|
|
64
100
|
{ mode: 'NEVER' },
|
|
65
101
|
{ mode: 'ALWAYS' },
|
|
66
102
|
{ mode: 'FATIGUE', fatigueBand: EnergyBand.TIRED },
|
|
67
|
-
{
|
|
68
|
-
{
|
|
103
|
+
{ conditions: [{ type: PinchConditionType.FATIGUE }] },
|
|
104
|
+
{}
|
|
69
105
|
]
|
|
70
106
|
});
|
|
71
107
|
expect(res.success).toBe(true);
|
|
108
|
+
if (res.success) {
|
|
109
|
+
expect(res.data.sets?.[0].conditions).toEqual([]);
|
|
110
|
+
expect(res.data.sets?.[1].conditions).toEqual([{ type: PinchConditionType.ASAP }]);
|
|
111
|
+
expect(res.data.sets?.[2].conditions).toEqual([{ type: PinchConditionType.FATIGUE, band: EnergyBand.TIRED }]);
|
|
112
|
+
}
|
|
72
113
|
});
|
|
73
114
|
it('rejects more than five per-set configs', () => {
|
|
74
115
|
const res = LiberoSubConfigSchema.safeParse({
|
|
75
|
-
|
|
76
|
-
sets: Array.from({ length: 6 }, () => ({ mode: 'NEVER' }))
|
|
116
|
+
sets: Array.from({ length: 6 }, () => ({}))
|
|
77
117
|
});
|
|
78
118
|
expect(res.success).toBe(false);
|
|
79
119
|
});
|
|
80
|
-
it('rejects an unknown
|
|
120
|
+
it('rejects an unknown condition type in a per-set config', () => {
|
|
81
121
|
const res = LiberoSubConfigSchema.safeParse({
|
|
82
|
-
|
|
83
|
-
sets: [{ mode: 'WHENEVER' }]
|
|
122
|
+
sets: [{ conditions: [{ type: 'WHENEVER' }] }]
|
|
84
123
|
});
|
|
85
124
|
expect(res.success).toBe(false);
|
|
86
125
|
});
|