volleyballsimtypes 0.0.482 → 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.
Files changed (59) hide show
  1. package/dist/cjs/src/api/index.d.ts +3 -17
  2. package/dist/cjs/src/data/models/tactics.d.ts +7 -17
  3. package/dist/cjs/src/data/transformers/match-preset-override.test.js +10 -1
  4. package/dist/cjs/src/data/transformers/rally-event.d.ts +2 -1
  5. package/dist/cjs/src/data/transformers/rally-event.js +12 -0
  6. package/dist/cjs/src/data/transformers/rally.js +2 -0
  7. package/dist/cjs/src/data/transformers/rally.test.d.ts +1 -0
  8. package/dist/cjs/src/data/transformers/rally.test.js +62 -0
  9. package/dist/cjs/src/data/transformers/tactics.js +26 -54
  10. package/dist/cjs/src/data/transformers/tactics.test.js +16 -11
  11. package/dist/cjs/src/service/team/designated-sub.d.ts +2 -4
  12. package/dist/cjs/src/service/team/index.d.ts +1 -0
  13. package/dist/cjs/src/service/team/index.js +1 -0
  14. package/dist/cjs/src/service/team/libero-sub.d.ts +0 -4
  15. package/dist/cjs/src/service/team/pinch-condition.d.ts +11 -3
  16. package/dist/cjs/src/service/team/pinch-condition.js +9 -4
  17. package/dist/cjs/src/service/team/schemas/designated-sub.z.d.ts +30 -32
  18. package/dist/cjs/src/service/team/schemas/designated-sub.z.js +27 -23
  19. package/dist/cjs/src/service/team/schemas/designated-sub.z.test.js +4 -2
  20. package/dist/cjs/src/service/team/schemas/libero-sub.z.d.ts +15 -34
  21. package/dist/cjs/src/service/team/schemas/libero-sub.z.js +10 -26
  22. package/dist/cjs/src/service/team/schemas/libero-sub.z.test.js +74 -35
  23. package/dist/cjs/src/service/team/schemas/tactics.z.d.ts +28 -36
  24. package/dist/cjs/src/service/team/schemas/tactics.z.js +4 -3
  25. package/dist/cjs/src/service/team/schemas/team.z.d.ts +28 -36
  26. package/dist/cjs/src/service/team/sub-config-convert.d.ts +13 -0
  27. package/dist/cjs/src/service/team/sub-config-convert.js +91 -0
  28. package/dist/cjs/src/service/team/sub-config-convert.test.d.ts +1 -0
  29. package/dist/cjs/src/service/team/sub-config-convert.test.js +84 -0
  30. package/dist/esm/src/api/index.d.ts +3 -17
  31. package/dist/esm/src/data/models/tactics.d.ts +7 -17
  32. package/dist/esm/src/data/transformers/match-preset-override.test.js +10 -1
  33. package/dist/esm/src/data/transformers/rally-event.d.ts +2 -1
  34. package/dist/esm/src/data/transformers/rally-event.js +12 -1
  35. package/dist/esm/src/data/transformers/rally.js +4 -2
  36. package/dist/esm/src/data/transformers/rally.test.d.ts +1 -0
  37. package/dist/esm/src/data/transformers/rally.test.js +60 -0
  38. package/dist/esm/src/data/transformers/tactics.js +27 -55
  39. package/dist/esm/src/data/transformers/tactics.test.js +16 -11
  40. package/dist/esm/src/service/team/designated-sub.d.ts +2 -4
  41. package/dist/esm/src/service/team/index.d.ts +1 -0
  42. package/dist/esm/src/service/team/index.js +1 -0
  43. package/dist/esm/src/service/team/libero-sub.d.ts +0 -4
  44. package/dist/esm/src/service/team/pinch-condition.d.ts +11 -3
  45. package/dist/esm/src/service/team/pinch-condition.js +9 -4
  46. package/dist/esm/src/service/team/schemas/designated-sub.z.d.ts +30 -32
  47. package/dist/esm/src/service/team/schemas/designated-sub.z.js +26 -22
  48. package/dist/esm/src/service/team/schemas/designated-sub.z.test.js +4 -2
  49. package/dist/esm/src/service/team/schemas/libero-sub.z.d.ts +15 -34
  50. package/dist/esm/src/service/team/schemas/libero-sub.z.js +9 -25
  51. package/dist/esm/src/service/team/schemas/libero-sub.z.test.js +75 -36
  52. package/dist/esm/src/service/team/schemas/tactics.z.d.ts +28 -36
  53. package/dist/esm/src/service/team/schemas/tactics.z.js +4 -3
  54. package/dist/esm/src/service/team/schemas/team.z.d.ts +28 -36
  55. package/dist/esm/src/service/team/sub-config-convert.d.ts +13 -0
  56. package/dist/esm/src/service/team/sub-config-convert.js +85 -0
  57. package/dist/esm/src/service/team/sub-config-convert.test.d.ts +1 -0
  58. package/dist/esm/src/service/team/sub-config-convert.test.js +82 -0
  59. package/package.json +1 -1
@@ -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>>;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DesignatedSubSchema = exports.SetSubConfigSchema = exports.SubBackModeSchema = exports.SubModeSchema = exports.ConditionLogicSchema = exports.PinchConditionSchema = exports.SubBandSchema = void 0;
3
+ exports.DesignatedSubSchema = exports.SetSubConfigSchema = exports.SubBackModeSchema = exports.ConditionLogicSchema = exports.PinchConditionSchema = exports.SubBandSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const player_1 = require("../../player");
6
6
  const energy_band_1 = require("../energy-band");
7
7
  const pinch_condition_1 = require("../pinch-condition");
8
+ const sub_config_convert_1 = require("../sub-config-convert");
8
9
  const playerInstanceSchema = zod_1.z.custom((v) => v instanceof player_1.Player, {
9
10
  message: 'INVALID_PLAYER_INSTANCE'
10
11
  });
@@ -21,44 +22,47 @@ exports.PinchConditionSchema = zod_1.z.discriminatedUnion('type', [
21
22
  zod_1.z.object({ type: zod_1.z.literal(pinch_condition_1.PinchConditionType.MIN_OWN_SCORE), score: zod_1.z.number().int().min(0).max(40), comparison: zod_1.z.nativeEnum(pinch_condition_1.Comparison).optional() }),
22
23
  zod_1.z.object({ type: zod_1.z.literal(pinch_condition_1.PinchConditionType.MIN_OPPONENT_SCORE), score: zod_1.z.number().int().min(0).max(40), comparison: zod_1.z.nativeEnum(pinch_condition_1.Comparison).optional() }),
23
24
  // PHASE is used by the libero deployment rule (which reuses this schema); pinch servers never offer it.
24
- zod_1.z.object({ type: zod_1.z.literal(pinch_condition_1.PinchConditionType.PHASE), phase: zod_1.z.nativeEnum(pinch_condition_1.MatchPhase) })
25
+ zod_1.z.object({ type: zod_1.z.literal(pinch_condition_1.PinchConditionType.PHASE), phase: zod_1.z.nativeEnum(pinch_condition_1.MatchPhase) }),
26
+ // The subject player's energy is at-or-worse than `band` (absent = the team `substitutionBand`); the
27
+ // subject comes from the evaluation context (starter / substitute / starting libero).
28
+ zod_1.z.object({ type: zod_1.z.literal(pinch_condition_1.PinchConditionType.FATIGUE), band: zod_1.z.nativeEnum(energy_band_1.EnergyBand).optional() })
25
29
  ]);
26
30
  exports.ConditionLogicSchema = zod_1.z.union([zod_1.z.literal('ALL'), zod_1.z.literal('ANY')]);
27
- exports.SubModeSchema = zod_1.z.enum(['FATIGUE', 'PINCH', 'NEVER']);
28
31
  exports.SubBackModeSchema = zod_1.z.enum(['FATIGUE', 'CONDITIONS']);
29
- // Fields shared by the all-sets config and each per-set config.
32
+ // Fields shared by the all-sets config and each per-set config. Pure condition engine (owner 2026-07-11):
33
+ // no mode; `conditions` is the sub-in trigger and an EMPTY/absent list means the starter is never substituted
34
+ // by this rule. Legacy mode-shaped inputs are auto-converted by the preprocess below.
30
35
  const setSubConfigShape = {
31
- mode: exports.SubModeSchema,
32
36
  bench: playerInstanceSchema.optional(),
33
- fatigueBand: zod_1.z.nativeEnum(energy_band_1.EnergyBand).optional(),
34
- benchFatigueBand: zod_1.z.nativeEnum(energy_band_1.EnergyBand).optional(),
35
37
  conditions: zod_1.z.array(exports.PinchConditionSchema).optional(),
36
38
  conditionLogic: exports.ConditionLogicSchema.optional(),
37
- // pinch ("Conditions") mode. true = serve-and-return pinch server; false/absent = regular conditional sub.
39
+ // true = serve-and-return pinch server; false/absent = regular conditional sub (stays until sub-back).
38
40
  pinchServer: zod_1.z.boolean().optional(),
39
- // a regular conditional sub's sub-back trigger + its condition set (subBackMode === 'CONDITIONS').
41
+ // The substitute's own pull band for FATIGUE sub-backs (absent = the team `substitutionBand`).
42
+ benchFatigueBand: zod_1.z.nativeEnum(energy_band_1.EnergyBand).optional(),
40
43
  subBackMode: exports.SubBackModeSchema.optional(),
41
44
  subBackConditions: zod_1.z.array(exports.PinchConditionSchema).optional(),
42
45
  subBackConditionLogic: exports.ConditionLogicSchema.optional()
43
46
  };
44
- // Pinch ("Conditions") mode needs a designated bench player and at least one sub-in condition. A regular
45
- // conditional sub (pinchServer !== true) with a CONDITIONS sub-back also needs at least one sub-back condition.
46
- function refinePinch(data, ctx) {
47
- if (data.mode !== 'PINCH')
48
- return;
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'] });
47
+ // A pinch server needs a designated bench player and at least one sub-in condition. A regular conditional sub
48
+ // with a CONDITIONS sub-back needs at least one sub-back condition. Empty sub-in conditions are otherwise
49
+ // VALID (= never fires).
50
+ function refineSubConfig(data, ctx) {
51
+ if (data.pinchServer === true) {
52
+ if (data.bench == null) {
53
+ ctx.addIssue({ code: 'custom', message: 'PINCH_SERVER_REQUIRES_BENCH', path: ['bench'] });
54
+ }
55
+ if (data.conditions == null || data.conditions.length === 0) {
56
+ ctx.addIssue({ code: 'custom', message: 'PINCH_SERVER_REQUIRES_CONDITIONS', path: ['conditions'] });
57
+ }
54
58
  }
55
59
  if (data.pinchServer !== true && data.subBackMode === 'CONDITIONS' &&
56
60
  (data.subBackConditions == null || data.subBackConditions.length === 0)) {
57
61
  ctx.addIssue({ code: 'custom', message: 'CONDITIONAL_SUB_BACK_REQUIRES_CONDITIONS', path: ['subBackConditions'] });
58
62
  }
59
63
  }
60
- exports.SetSubConfigSchema = zod_1.z.object(setSubConfigShape).superRefine(refinePinch);
61
- exports.DesignatedSubSchema = zod_1.z.object({
64
+ exports.SetSubConfigSchema = zod_1.z.preprocess(sub_config_convert_1.convertLegacySetSubConfig, zod_1.z.object(setSubConfigShape).superRefine(refineSubConfig));
65
+ exports.DesignatedSubSchema = zod_1.z.preprocess(sub_config_convert_1.convertLegacyDesignatedSub, zod_1.z.object({
62
66
  starter: playerInstanceSchema,
63
67
  ...setSubConfigShape,
64
68
  // Optional per-set overrides (index 0 = set 1 ... index 4 = set 5); absent => the flat config for all sets.
@@ -67,5 +71,5 @@ exports.DesignatedSubSchema = zod_1.z.object({
67
71
  // The flat config is the fallback for any set a partial `sets` array doesn't cover, so validate it whenever
68
72
  // `sets` is absent or covers fewer than 5 sets (each present per-set config is validated by SetSubConfigSchema).
69
73
  if (data.sets == null || data.sets.length < 5)
70
- refinePinch(data, ctx);
71
- });
74
+ refineSubConfig(data, ctx);
75
+ }));
@@ -116,12 +116,14 @@ const test_helpers_1 = require("../../test-helpers");
116
116
  });
117
117
  (0, globals_1.expect)(res.success).toBe(true);
118
118
  });
119
- (0, globals_1.it)('rejects an unknown mode', () => {
119
+ (0, globals_1.it)('heals an unknown legacy mode by stripping it (lenient conversion, config stays valid)', () => {
120
120
  const res = designated_sub_z_1.DesignatedSubSchema.safeParse({
121
121
  starter,
122
122
  mode: 'SOMETIMES'
123
123
  });
124
- (0, globals_1.expect)(res.success).toBe(false);
124
+ (0, globals_1.expect)(res.success).toBe(true);
125
+ if (res.success)
126
+ (0, globals_1.expect)(res.data.mode).toBeUndefined();
125
127
  });
126
128
  (0, globals_1.it)('accepts a pinch-mode entry with a bench server and conditions', () => {
127
129
  const res = designated_sub_z_1.DesignatedSubSchema.safeParse({
@@ -1,19 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { EnergyBand } from '../energy-band';
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,37 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LiberoSubConfigSchema = exports.LiberoSetSubConfigSchema = exports.LiberoSubModeSchema = void 0;
3
+ exports.LiberoSubConfigSchema = exports.LiberoSetSubConfigSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- const energy_band_1 = require("../energy-band");
5
+ const sub_config_convert_1 = require("../sub-config-convert");
6
6
  const designated_sub_z_1 = require("./designated-sub.z");
7
- exports.LiberoSubModeSchema = zod_1.z.enum(['NEVER', 'FATIGUE', 'ALWAYS', 'CONDITIONS']);
8
- // Fields shared by the all-sets config and each per-set config. The swapped-in player is always the dedicated
9
- // `secondLibero`, so there is no bench to validate; the CONDITIONS mode reuses the pinch-server condition
10
- // catalog (PinchConditionSchema, which includes the libero-only PHASE condition) + ALL/ANY logic.
7
+ // Pure condition engine (owner 2026-07-11): the second libero is active while `conditions` hold (combined
8
+ // per `conditionLogic`, default ALL; the STARTING libero is the FATIGUE-condition subject). No conditions =
9
+ // the starting libero always plays; [{ASAP}] = always the second libero (the old ALWAYS). The swapped-in
10
+ // player is always the dedicated `secondLibero`, so there is no bench to validate. Legacy mode-shaped
11
+ // configs (NEVER/FATIGUE/ALWAYS/CONDITIONS) are auto-converted by the preprocess.
11
12
  const liberoSetSubConfigShape = {
12
- mode: exports.LiberoSubModeSchema,
13
- // fatigue mode only (absent => the team default `substitutionBand`):
14
- fatigueBand: zod_1.z.nativeEnum(energy_band_1.EnergyBand).optional(),
15
- // conditions mode only:
16
13
  conditions: zod_1.z.array(designated_sub_z_1.PinchConditionSchema).optional(),
17
14
  conditionLogic: designated_sub_z_1.ConditionLogicSchema.optional()
18
15
  };
19
- // CONDITIONS mode needs at least one condition (mirrors the designated-sub pinch refine).
20
- function refineConditions(data, ctx) {
21
- if (data.mode !== 'CONDITIONS')
22
- return;
23
- if (data.conditions == null || data.conditions.length === 0) {
24
- ctx.addIssue({ code: 'custom', message: 'LIBERO_CONDITIONS_REQUIRE_A_CONDITION', path: ['conditions'] });
25
- }
26
- }
27
- exports.LiberoSetSubConfigSchema = zod_1.z.object(liberoSetSubConfigShape).superRefine(refineConditions);
28
- exports.LiberoSubConfigSchema = zod_1.z.object({
16
+ exports.LiberoSetSubConfigSchema = zod_1.z.preprocess(sub_config_convert_1.convertLegacyLiberoSetSubConfig, zod_1.z.object(liberoSetSubConfigShape));
17
+ exports.LiberoSubConfigSchema = zod_1.z.preprocess(sub_config_convert_1.convertLegacyLiberoSubConfig, zod_1.z.object({
29
18
  ...liberoSetSubConfigShape,
30
19
  // Optional per-set overrides (index 0 = set 1 ... index 4 = set 5); absent => the flat config for all sets.
31
20
  sets: zod_1.z.array(exports.LiberoSetSubConfigSchema).max(5).optional()
32
- }).superRefine((data, ctx) => {
33
- // The flat config is the fallback for any set a partial `sets` array doesn't cover, so validate it whenever
34
- // `sets` is absent or covers fewer than 5 sets (each present per-set config is validated by its own schema).
35
- if (data.sets == null || data.sets.length < 5)
36
- refineConditions(data, ctx);
37
- });
21
+ }));
@@ -4,85 +4,124 @@ const globals_1 = require("@jest/globals");
4
4
  const libero_sub_z_1 = require("./libero-sub.z");
5
5
  const energy_band_1 = require("../energy-band");
6
6
  const pinch_condition_1 = require("../pinch-condition");
7
- (0, globals_1.describe)('LiberoSubModeSchema', () => {
8
- (0, globals_1.it)('accepts NEVER, FATIGUE, ALWAYS and CONDITIONS', () => {
9
- for (const mode of ['NEVER', 'FATIGUE', 'ALWAYS', 'CONDITIONS']) {
10
- (0, globals_1.expect)(libero_sub_z_1.LiberoSubModeSchema.safeParse(mode).success).toBe(true);
11
- }
12
- });
13
- (0, globals_1.it)('rejects an unknown mode', () => {
14
- (0, globals_1.expect)(libero_sub_z_1.LiberoSubModeSchema.safeParse('SOMETIMES').success).toBe(false);
7
+ // Unified condition engine (owner 2026-07-11): the libero rule is a pure condition list; legacy mode-shaped
8
+ // configs (NEVER/FATIGUE/ALWAYS/CONDITIONS) auto-convert in the schema preprocess.
9
+ (0, globals_1.describe)('LiberoSetSubConfigSchema (unified)', () => {
10
+ (0, globals_1.it)('accepts an empty config (no conditions = the starting libero always plays)', () => {
11
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({});
12
+ (0, globals_1.expect)(res.success).toBe(true);
13
+ if (res.success)
14
+ (0, globals_1.expect)(res.data.conditions ?? []).toHaveLength(0);
15
15
  });
16
- });
17
- (0, globals_1.describe)('LiberoSetSubConfigSchema', () => {
18
- (0, globals_1.it)('accepts a mode with no band', () => {
19
- (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'ALWAYS' }).success).toBe(true);
16
+ (0, globals_1.it)('accepts a FATIGUE condition with a band', () => {
17
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({
18
+ conditions: [{ type: pinch_condition_1.PinchConditionType.FATIGUE, band: energy_band_1.EnergyBand.TIRED }]
19
+ });
20
+ (0, globals_1.expect)(res.success).toBe(true);
20
21
  });
21
- (0, globals_1.it)('accepts a fatigue mode with a band', () => {
22
- (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: energy_band_1.EnergyBand.TIRED }).success).toBe(true);
22
+ (0, globals_1.it)('accepts a FATIGUE condition without a band (team default)', () => {
23
+ (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ conditions: [{ type: pinch_condition_1.PinchConditionType.FATIGUE }] }).success).toBe(true);
23
24
  });
24
- (0, globals_1.it)('rejects an unknown band', () => {
25
- (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: 'SLEEPY' }).success).toBe(false);
25
+ (0, globals_1.it)('rejects a FATIGUE condition with an unknown band', () => {
26
+ (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ conditions: [{ type: pinch_condition_1.PinchConditionType.FATIGUE, band: 'SLEEPY' }] }).success).toBe(false);
26
27
  });
27
- (0, globals_1.it)('accepts CONDITIONS with a PHASE condition (serve/receive split)', () => {
28
+ (0, globals_1.it)('accepts a PHASE condition (serve/receive split)', () => {
28
29
  const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({
29
- mode: 'CONDITIONS',
30
30
  conditionLogic: 'ALL',
31
31
  conditions: [{ type: pinch_condition_1.PinchConditionType.PHASE, phase: pinch_condition_1.MatchPhase.RECEIVING }]
32
32
  });
33
33
  (0, globals_1.expect)(res.success).toBe(true);
34
34
  });
35
- (0, globals_1.it)('accepts CONDITIONS mixing a pinch condition and a PHASE condition', () => {
35
+ (0, globals_1.it)('accepts mixed conditions (score + phase + fatigue) under ANY logic', () => {
36
36
  const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({
37
- mode: 'CONDITIONS',
38
37
  conditionLogic: 'ANY',
39
38
  conditions: [
40
39
  { type: pinch_condition_1.PinchConditionType.MIN_OWN_SCORE, score: 20 },
41
- { type: pinch_condition_1.PinchConditionType.PHASE, phase: pinch_condition_1.MatchPhase.SERVING }
40
+ { type: pinch_condition_1.PinchConditionType.PHASE, phase: pinch_condition_1.MatchPhase.SERVING },
41
+ { type: pinch_condition_1.PinchConditionType.FATIGUE, band: energy_band_1.EnergyBand.EXHAUSTED }
42
42
  ]
43
43
  });
44
44
  (0, globals_1.expect)(res.success).toBe(true);
45
45
  });
46
- (0, globals_1.it)('rejects CONDITIONS mode with no conditions', () => {
47
- (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS' }).success).toBe(false);
48
- (0, globals_1.expect)(libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS', conditions: [] }).success).toBe(false);
49
- });
50
46
  (0, globals_1.it)('rejects an invalid PHASE value', () => {
51
47
  const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({
52
- mode: 'CONDITIONS',
53
48
  conditions: [{ type: pinch_condition_1.PinchConditionType.PHASE, phase: 'ATTACKING' }]
54
49
  });
55
50
  (0, globals_1.expect)(res.success).toBe(false);
56
51
  });
57
52
  });
53
+ (0, globals_1.describe)('LiberoSetSubConfigSchema (legacy conversion)', () => {
54
+ (0, globals_1.it)('converts legacy NEVER to an empty condition list', () => {
55
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'NEVER' });
56
+ (0, globals_1.expect)(res.success).toBe(true);
57
+ if (res.success)
58
+ (0, globals_1.expect)(res.data.conditions).toEqual([]);
59
+ });
60
+ (0, globals_1.it)('converts legacy ALWAYS to a single ASAP condition', () => {
61
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'ALWAYS' });
62
+ (0, globals_1.expect)(res.success).toBe(true);
63
+ if (res.success)
64
+ (0, globals_1.expect)(res.data.conditions).toEqual([{ type: pinch_condition_1.PinchConditionType.ASAP }]);
65
+ });
66
+ (0, globals_1.it)('converts legacy FATIGUE + band to a FATIGUE condition carrying the band', () => {
67
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: energy_band_1.EnergyBand.WORN });
68
+ (0, globals_1.expect)(res.success).toBe(true);
69
+ if (res.success)
70
+ (0, globals_1.expect)(res.data.conditions).toEqual([{ type: pinch_condition_1.PinchConditionType.FATIGUE, band: energy_band_1.EnergyBand.WORN }]);
71
+ });
72
+ (0, globals_1.it)('converts legacy FATIGUE without a band to a bandless FATIGUE condition (team default)', () => {
73
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'FATIGUE' });
74
+ (0, globals_1.expect)(res.success).toBe(true);
75
+ if (res.success)
76
+ (0, globals_1.expect)(res.data.conditions).toEqual([{ type: pinch_condition_1.PinchConditionType.FATIGUE }]);
77
+ });
78
+ (0, globals_1.it)('converts legacy CONDITIONS by stripping the mode and keeping the conditions', () => {
79
+ const conditions = [{ type: pinch_condition_1.PinchConditionType.PHASE, phase: pinch_condition_1.MatchPhase.RECEIVING }];
80
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS', conditionLogic: 'ALL', conditions });
81
+ (0, globals_1.expect)(res.success).toBe(true);
82
+ if (res.success) {
83
+ (0, globals_1.expect)(res.data.conditions).toEqual(conditions);
84
+ (0, globals_1.expect)(res.data.mode).toBeUndefined();
85
+ }
86
+ });
87
+ (0, globals_1.it)('heals a legacy CONDITIONS config with no conditions to never (empty list) instead of rejecting', () => {
88
+ const res = libero_sub_z_1.LiberoSetSubConfigSchema.safeParse({ mode: 'CONDITIONS' });
89
+ (0, globals_1.expect)(res.success).toBe(true);
90
+ if (res.success)
91
+ (0, globals_1.expect)(res.data.conditions ?? []).toHaveLength(0);
92
+ });
93
+ });
58
94
  (0, globals_1.describe)('LiberoSubConfigSchema', () => {
59
- (0, globals_1.it)('accepts a flat config with no per-set overrides', () => {
95
+ (0, globals_1.it)('accepts a flat config with no per-set overrides (legacy shape converts)', () => {
60
96
  (0, globals_1.expect)(libero_sub_z_1.LiberoSubConfigSchema.safeParse({ mode: 'FATIGUE', fatigueBand: energy_band_1.EnergyBand.WORN }).success).toBe(true);
61
97
  });
62
- (0, globals_1.it)('accepts up to five per-set configs', () => {
98
+ (0, globals_1.it)('accepts up to five per-set configs (legacy per-set entries convert)', () => {
63
99
  const res = libero_sub_z_1.LiberoSubConfigSchema.safeParse({
64
100
  mode: 'NEVER',
65
101
  sets: [
66
102
  { mode: 'NEVER' },
67
103
  { mode: 'ALWAYS' },
68
104
  { mode: 'FATIGUE', fatigueBand: energy_band_1.EnergyBand.TIRED },
69
- { mode: 'NEVER' },
70
- { mode: 'ALWAYS' }
105
+ { conditions: [{ type: pinch_condition_1.PinchConditionType.FATIGUE }] },
106
+ {}
71
107
  ]
72
108
  });
73
109
  (0, globals_1.expect)(res.success).toBe(true);
110
+ if (res.success) {
111
+ (0, globals_1.expect)(res.data.sets?.[0].conditions).toEqual([]);
112
+ (0, globals_1.expect)(res.data.sets?.[1].conditions).toEqual([{ type: pinch_condition_1.PinchConditionType.ASAP }]);
113
+ (0, globals_1.expect)(res.data.sets?.[2].conditions).toEqual([{ type: pinch_condition_1.PinchConditionType.FATIGUE, band: energy_band_1.EnergyBand.TIRED }]);
114
+ }
74
115
  });
75
116
  (0, globals_1.it)('rejects more than five per-set configs', () => {
76
117
  const res = libero_sub_z_1.LiberoSubConfigSchema.safeParse({
77
- mode: 'NEVER',
78
- sets: Array.from({ length: 6 }, () => ({ mode: 'NEVER' }))
118
+ sets: Array.from({ length: 6 }, () => ({}))
79
119
  });
80
120
  (0, globals_1.expect)(res.success).toBe(false);
81
121
  });
82
- (0, globals_1.it)('rejects an unknown mode in a per-set config', () => {
122
+ (0, globals_1.it)('rejects an unknown condition type in a per-set config', () => {
83
123
  const res = libero_sub_z_1.LiberoSubConfigSchema.safeParse({
84
- mode: 'NEVER',
85
- sets: [{ mode: 'WHENEVER' }]
124
+ sets: [{ conditions: [{ type: 'WHENEVER' }] }]
86
125
  });
87
126
  (0, globals_1.expect)(res.success).toBe(false);
88
127
  });