@featurevisor/core 3.11.0 → 4.0.1

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 (292) hide show
  1. package/README.md +20 -2
  2. package/lib/assess-distribution/index.js +9 -3
  3. package/lib/assess-distribution/index.js.map +1 -1
  4. package/lib/benchmark/index.d.ts +1 -1
  5. package/lib/benchmark/index.js +18 -11
  6. package/lib/benchmark/index.js.map +1 -1
  7. package/lib/builder/applyContextToConditions.d.ts +5 -4
  8. package/lib/builder/applyContextToConditions.js +84 -89
  9. package/lib/builder/applyContextToConditions.js.map +1 -1
  10. package/lib/builder/applyContextToDatafile.d.ts +2 -2
  11. package/lib/builder/applyContextToDatafile.js +45 -149
  12. package/lib/builder/applyContextToDatafile.js.map +1 -1
  13. package/lib/builder/applyContextToSegments.d.ts +6 -4
  14. package/lib/builder/applyContextToSegments.js +9 -98
  15. package/lib/builder/applyContextToSegments.js.map +1 -1
  16. package/lib/builder/buildDatafile.d.ts +15 -6
  17. package/lib/builder/buildDatafile.js +320 -220
  18. package/lib/builder/buildDatafile.js.map +1 -1
  19. package/lib/builder/buildProject.d.ts +2 -1
  20. package/lib/builder/buildProject.js +36 -37
  21. package/lib/builder/buildProject.js.map +1 -1
  22. package/lib/builder/buildRuntimeDatafiles.js +2 -0
  23. package/lib/builder/buildRuntimeDatafiles.js.map +1 -1
  24. package/lib/builder/environments.d.ts +3 -0
  25. package/lib/builder/environments.js +26 -0
  26. package/lib/builder/environments.js.map +1 -0
  27. package/lib/builder/hashes.d.ts +5 -5
  28. package/lib/builder/hashes.js +82 -100
  29. package/lib/builder/hashes.js.map +1 -1
  30. package/lib/builder/inflate.d.ts +7 -0
  31. package/lib/builder/inflate.js +26 -0
  32. package/lib/builder/inflate.js.map +1 -0
  33. package/lib/builder/mutateVariables.d.ts +6 -2
  34. package/lib/builder/mutateVariables.js +26 -18
  35. package/lib/builder/mutateVariables.js.map +1 -1
  36. package/lib/builder/mutationEntries.d.ts +5 -0
  37. package/lib/builder/mutationEntries.js +23 -0
  38. package/lib/builder/mutationEntries.js.map +1 -0
  39. package/lib/builder/mutator.d.ts +4 -2
  40. package/lib/builder/mutator.js +20 -209
  41. package/lib/builder/mutator.js.map +1 -1
  42. package/lib/builder/traffic.d.ts +2 -4
  43. package/lib/builder/traffic.js +48 -19
  44. package/lib/builder/traffic.js.map +1 -1
  45. package/lib/builder/variableOverrideProgram.d.ts +9 -0
  46. package/lib/builder/variableOverrideProgram.js +147 -0
  47. package/lib/builder/variableOverrideProgram.js.map +1 -0
  48. package/lib/catalog.d.ts +23 -0
  49. package/lib/catalog.js +117 -0
  50. package/lib/catalog.js.map +1 -0
  51. package/lib/cli/cli.d.ts +2 -0
  52. package/lib/cli/cli.js +38 -13
  53. package/lib/cli/cli.js.map +1 -1
  54. package/lib/cli/options.js +72 -17
  55. package/lib/cli/options.js.map +1 -1
  56. package/lib/cli/plugins.js +11 -3
  57. package/lib/cli/plugins.js.map +1 -1
  58. package/lib/cli/suggestions.d.ts +4 -0
  59. package/lib/cli/suggestions.js +61 -0
  60. package/lib/cli/suggestions.js.map +1 -0
  61. package/lib/config/allowedConditions.d.ts +9 -0
  62. package/lib/config/allowedConditions.js +44 -0
  63. package/lib/config/allowedConditions.js.map +1 -0
  64. package/lib/config/index.d.ts +1 -0
  65. package/lib/config/index.js +1 -0
  66. package/lib/config/index.js.map +1 -1
  67. package/lib/config/projectConfig.d.ts +9 -3
  68. package/lib/config/projectConfig.js +68 -11
  69. package/lib/config/projectConfig.js.map +1 -1
  70. package/lib/config/removedGroups.d.ts +5 -0
  71. package/lib/config/removedGroups.js +62 -0
  72. package/lib/config/removedGroups.js.map +1 -0
  73. package/lib/datasource/adapter.d.ts +10 -1
  74. package/lib/datasource/adapter.js.map +1 -1
  75. package/lib/datasource/attributeNamespaces.d.ts +14 -0
  76. package/lib/datasource/attributeNamespaces.js +70 -0
  77. package/lib/datasource/attributeNamespaces.js.map +1 -0
  78. package/lib/datasource/composition.d.ts +5 -0
  79. package/lib/datasource/composition.js +19 -0
  80. package/lib/datasource/composition.js.map +1 -0
  81. package/lib/datasource/conditions.d.ts +20 -0
  82. package/lib/datasource/conditions.js +113 -0
  83. package/lib/datasource/conditions.js.map +1 -0
  84. package/lib/datasource/datasource.d.ts +18 -12
  85. package/lib/datasource/datasource.js +137 -76
  86. package/lib/datasource/datasource.js.map +1 -1
  87. package/lib/datasource/dependencies.d.ts +52 -0
  88. package/lib/datasource/dependencies.js +347 -0
  89. package/lib/datasource/dependencies.js.map +1 -0
  90. package/lib/datasource/filesystemAdapter.d.ts +31 -1
  91. package/lib/datasource/filesystemAdapter.js +581 -99
  92. package/lib/datasource/filesystemAdapter.js.map +1 -1
  93. package/lib/datasource/index.d.ts +3 -0
  94. package/lib/datasource/index.js +3 -0
  95. package/lib/datasource/index.js.map +1 -1
  96. package/lib/datasource/parseError.d.ts +5 -0
  97. package/lib/datasource/parseError.js +68 -0
  98. package/lib/datasource/parseError.js.map +1 -0
  99. package/lib/datasource/testSpecs.d.ts +4 -0
  100. package/lib/datasource/testSpecs.js +40 -0
  101. package/lib/datasource/testSpecs.js.map +1 -0
  102. package/lib/diff/details.js +31 -0
  103. package/lib/diff/details.js.map +1 -1
  104. package/lib/diff/index.d.ts +1 -1
  105. package/lib/diff/index.js +11 -4
  106. package/lib/diff/index.js.map +1 -1
  107. package/lib/error.d.ts +1 -0
  108. package/lib/error.js +6 -0
  109. package/lib/error.js.map +1 -1
  110. package/lib/evaluate/explain.d.ts +15 -2
  111. package/lib/evaluate/explain.js +273 -79
  112. package/lib/evaluate/explain.js.map +1 -1
  113. package/lib/evaluate/index.js +128 -17
  114. package/lib/evaluate/index.js.map +1 -1
  115. package/lib/evaluate/probeConditions.d.ts +30 -0
  116. package/lib/evaluate/probeConditions.js +165 -0
  117. package/lib/evaluate/probeConditions.js.map +1 -0
  118. package/lib/evaluate/validateExplanation.js +175 -16
  119. package/lib/evaluate/validateExplanation.js.map +1 -1
  120. package/lib/find-duplicate-segments/findDuplicateSegments.js +20 -1
  121. package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
  122. package/lib/find-usage/index.d.ts +14 -1
  123. package/lib/find-usage/index.js +359 -155
  124. package/lib/find-usage/index.js.map +1 -1
  125. package/lib/generate-code/typescript.js +156 -60
  126. package/lib/generate-code/typescript.js.map +1 -1
  127. package/lib/info/index.js +11 -5
  128. package/lib/info/index.js.map +1 -1
  129. package/lib/init/index.js +234 -28
  130. package/lib/init/index.js.map +1 -1
  131. package/lib/linter/attributeSchema.d.ts +6 -11
  132. package/lib/linter/attributeSchema.js +59 -53
  133. package/lib/linter/attributeSchema.js.map +1 -1
  134. package/lib/linter/comparisonOperators.d.ts +18 -0
  135. package/lib/linter/comparisonOperators.js +82 -0
  136. package/lib/linter/comparisonOperators.js.map +1 -0
  137. package/lib/linter/composedOverrideSchema.d.ts +5 -0
  138. package/lib/linter/composedOverrideSchema.js +243 -0
  139. package/lib/linter/composedOverrideSchema.js.map +1 -0
  140. package/lib/linter/compositionWarnings.d.ts +8 -0
  141. package/lib/linter/compositionWarnings.js +212 -0
  142. package/lib/linter/compositionWarnings.js.map +1 -0
  143. package/lib/linter/conditionKinds.d.ts +12 -0
  144. package/lib/linter/conditionKinds.js +129 -0
  145. package/lib/linter/conditionKinds.js.map +1 -0
  146. package/lib/linter/conditionSchema.d.ts +8 -2
  147. package/lib/linter/conditionSchema.js +253 -52
  148. package/lib/linter/conditionSchema.js.map +1 -1
  149. package/lib/linter/contextWarnings.d.ts +13 -0
  150. package/lib/linter/contextWarnings.js +241 -0
  151. package/lib/linter/contextWarnings.js.map +1 -0
  152. package/lib/linter/definitionReferences.d.ts +39 -0
  153. package/lib/linter/definitionReferences.js +234 -0
  154. package/lib/linter/definitionReferences.js.map +1 -0
  155. package/lib/linter/dependencyDepth.d.ts +14 -0
  156. package/lib/linter/dependencyDepth.js +106 -0
  157. package/lib/linter/dependencyDepth.js.map +1 -0
  158. package/lib/linter/diagnostics.d.ts +129 -0
  159. package/lib/linter/diagnostics.js +84 -0
  160. package/lib/linter/diagnostics.js.map +1 -0
  161. package/lib/linter/featureSchema.d.ts +191 -74
  162. package/lib/linter/featureSchema.js +415 -214
  163. package/lib/linter/featureSchema.js.map +1 -1
  164. package/lib/linter/lintProject.d.ts +4 -1
  165. package/lib/linter/lintProject.js +449 -143
  166. package/lib/linter/lintProject.js.map +1 -1
  167. package/lib/linter/mutationNotation.d.ts +7 -1
  168. package/lib/linter/mutationNotation.js +40 -20
  169. package/lib/linter/mutationNotation.js.map +1 -1
  170. package/lib/linter/mutationOrder.d.ts +6 -0
  171. package/lib/linter/mutationOrder.js +105 -0
  172. package/lib/linter/mutationOrder.js.map +1 -0
  173. package/lib/linter/mutationResultPaths.d.ts +4 -0
  174. package/lib/linter/mutationResultPaths.js +131 -0
  175. package/lib/linter/mutationResultPaths.js.map +1 -0
  176. package/lib/linter/mutationSchema.d.ts +3 -0
  177. package/lib/linter/mutationSchema.js +32 -0
  178. package/lib/linter/mutationSchema.js.map +1 -0
  179. package/lib/linter/printError.d.ts +3 -0
  180. package/lib/linter/printError.js +38 -25
  181. package/lib/linter/printError.js.map +1 -1
  182. package/lib/linter/regexSafety.d.ts +19 -0
  183. package/lib/linter/regexSafety.js +307 -0
  184. package/lib/linter/regexSafety.js.map +1 -0
  185. package/lib/linter/removedConditionFields.d.ts +10 -0
  186. package/lib/linter/removedConditionFields.js +47 -0
  187. package/lib/linter/removedConditionFields.js.map +1 -0
  188. package/lib/linter/requiredFeaturesSchema.d.ts +2 -2
  189. package/lib/linter/requiredFeaturesSchema.js +32 -28
  190. package/lib/linter/requiredFeaturesSchema.js.map +1 -1
  191. package/lib/linter/requiredVariableCost.d.ts +5 -0
  192. package/lib/linter/requiredVariableCost.js +60 -0
  193. package/lib/linter/requiredVariableCost.js.map +1 -0
  194. package/lib/linter/requiredVariablesSchema.d.ts +13 -0
  195. package/lib/linter/requiredVariablesSchema.js +498 -0
  196. package/lib/linter/requiredVariablesSchema.js.map +1 -0
  197. package/lib/linter/reservedNames.d.ts +12 -0
  198. package/lib/linter/reservedNames.js +52 -0
  199. package/lib/linter/reservedNames.js.map +1 -0
  200. package/lib/linter/schema.d.ts +12 -15
  201. package/lib/linter/schema.js +108 -26
  202. package/lib/linter/schema.js.map +1 -1
  203. package/lib/linter/schemaFormats.d.ts +35 -0
  204. package/lib/linter/schemaFormats.js +66 -0
  205. package/lib/linter/schemaFormats.js.map +1 -0
  206. package/lib/linter/segmentSchema.d.ts +11 -1
  207. package/lib/linter/segmentSchema.js +12 -2
  208. package/lib/linter/segmentSchema.js.map +1 -1
  209. package/lib/linter/testSchema.d.ts +394 -2
  210. package/lib/linter/testSchema.js +565 -34
  211. package/lib/linter/testSchema.js.map +1 -1
  212. package/lib/linter/variableSchema.d.ts +60 -43
  213. package/lib/linter/variableSchema.js +459 -60
  214. package/lib/linter/variableSchema.js.map +1 -1
  215. package/lib/linter/zodHelpers.d.ts +8 -1
  216. package/lib/linter/zodHelpers.js +9 -1
  217. package/lib/linter/zodHelpers.js.map +1 -1
  218. package/lib/list/index.js +384 -66
  219. package/lib/list/index.js.map +1 -1
  220. package/lib/list/matrix.d.ts +2 -2
  221. package/lib/list/matrix.js +60 -39
  222. package/lib/list/matrix.js.map +1 -1
  223. package/lib/list/scenarios.d.ts +8 -0
  224. package/lib/list/scenarios.js +84 -0
  225. package/lib/list/scenarios.js.map +1 -0
  226. package/lib/promoter/index.d.ts +1 -1
  227. package/lib/promoter/index.js +469 -210
  228. package/lib/promoter/index.js.map +1 -1
  229. package/lib/sets.js +14 -5
  230. package/lib/sets.js.map +1 -1
  231. package/lib/tester/checks.d.ts +12 -0
  232. package/lib/tester/checks.js +418 -0
  233. package/lib/tester/checks.js.map +1 -0
  234. package/lib/tester/coverage.d.ts +16 -0
  235. package/lib/tester/coverage.js +64 -0
  236. package/lib/tester/coverage.js.map +1 -0
  237. package/lib/tester/datafileKey.d.ts +4 -0
  238. package/lib/tester/datafileKey.js +18 -0
  239. package/lib/tester/datafileKey.js.map +1 -0
  240. package/lib/tester/diagnostics.d.ts +5 -0
  241. package/lib/tester/diagnostics.js +32 -0
  242. package/lib/tester/diagnostics.js.map +1 -0
  243. package/lib/tester/index.d.ts +2 -0
  244. package/lib/tester/printTestResult.d.ts +3 -2
  245. package/lib/tester/printTestResult.js +53 -8
  246. package/lib/tester/printTestResult.js.map +1 -1
  247. package/lib/tester/provenance.d.ts +21 -0
  248. package/lib/tester/provenance.js +98 -0
  249. package/lib/tester/provenance.js.map +1 -0
  250. package/lib/tester/report.d.ts +78 -0
  251. package/lib/tester/report.js +246 -0
  252. package/lib/tester/report.js.map +1 -0
  253. package/lib/tester/segments.d.ts +23 -0
  254. package/lib/tester/segments.js +103 -0
  255. package/lib/tester/segments.js.map +1 -0
  256. package/lib/tester/testFeature.d.ts +2 -0
  257. package/lib/tester/testFeature.js +17 -8
  258. package/lib/tester/testFeature.js.map +1 -1
  259. package/lib/tester/testProject.d.ts +15 -3
  260. package/lib/tester/testProject.js +198 -83
  261. package/lib/tester/testProject.js.map +1 -1
  262. package/lib/tester/testSegment.d.ts +2 -4
  263. package/lib/tester/testSegment.js +89 -7
  264. package/lib/tester/testSegment.js.map +1 -1
  265. package/lib/tester/testVariable.d.ts +2 -2
  266. package/lib/tester/testVariable.js +195 -24
  267. package/lib/tester/testVariable.js.map +1 -1
  268. package/lib/utils/conditionReferences.d.ts +5 -0
  269. package/lib/utils/conditionReferences.js +30 -0
  270. package/lib/utils/conditionReferences.js.map +1 -0
  271. package/lib/utils/extractKeys.d.ts +7 -3
  272. package/lib/utils/extractKeys.js +32 -113
  273. package/lib/utils/extractKeys.js.map +1 -1
  274. package/lib/utils/git.d.ts +7 -2
  275. package/lib/utils/git.js +87 -72
  276. package/lib/utils/git.js.map +1 -1
  277. package/package.json +11 -8
  278. package/lib/builder/getFeatureRanges.d.ts +0 -11
  279. package/lib/builder/getFeatureRanges.js +0 -70
  280. package/lib/builder/getFeatureRanges.js.map +0 -1
  281. package/lib/datasource/requiredFeatures.d.ts +0 -14
  282. package/lib/datasource/requiredFeatures.js +0 -75
  283. package/lib/datasource/requiredFeatures.js.map +0 -1
  284. package/lib/linter/checkCircularDependency.d.ts +0 -3
  285. package/lib/linter/checkCircularDependency.js +0 -8
  286. package/lib/linter/checkCircularDependency.js.map +0 -1
  287. package/lib/linter/checkPercentageExceedingSlot.d.ts +0 -3
  288. package/lib/linter/checkPercentageExceedingSlot.js +0 -45
  289. package/lib/linter/checkPercentageExceedingSlot.js.map +0 -1
  290. package/lib/linter/groupSchema.d.ts +0 -11
  291. package/lib/linter/groupSchema.js +0 -31
  292. package/lib/linter/groupSchema.js.map +0 -1
@@ -1,15 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveVariableSchema = resolveVariableSchema;
4
+ exports.valueMatchesSchema = valueMatchesSchema;
4
5
  exports.refineRequiredKeysInSchema = refineRequiredKeysInSchema;
6
+ exports.childMutationValueContext = childMutationValueContext;
7
+ exports.mutationSubject = mutationSubject;
5
8
  exports.superRefineVariableValue = superRefineVariableValue;
6
9
  exports.getFeatureZodSchema = getFeatureZodSchema;
7
10
  const zod_1 = require("zod");
11
+ const schemaFormats_1 = require("./schemaFormats");
8
12
  const config_1 = require("../config");
9
13
  const mutationNotation_1 = require("./mutationNotation");
14
+ const variableOverrideProgram_1 = require("../builder/variableOverrideProgram");
15
+ const mutationEntries_1 = require("../builder/mutationEntries");
16
+ const mutationSchema_1 = require("./mutationSchema");
17
+ const mutationResultPaths_1 = require("./mutationResultPaths");
18
+ const mutateVariables_1 = require("../builder/mutateVariables");
10
19
  const schema_1 = require("./schema");
11
20
  const zodHelpers_1 = require("./zodHelpers");
12
- const requiredFeaturesSchema_1 = require("./requiredFeaturesSchema");
21
+ const diagnostics_1 = require("./diagnostics");
22
+ const removedConditionFields_1 = require("./removedConditionFields");
23
+ // Weights have up to three decimals, so compare without floating point noise.
24
+ function weightsSumTo100(weights) {
25
+ const sum = weights.reduce((total, weight) => total + weight, 0);
26
+ return Math.abs(sum - 100) < 1e-9;
27
+ }
28
+ function formatWeightsSum(weights) {
29
+ const sum = weights.reduce((total, weight) => total + weight, 0);
30
+ return String(Math.round(sum * 1000) / 1000);
31
+ }
13
32
  function isArrayOfStrings(value) {
14
33
  return Array.isArray(value) && value.every((v) => typeof v === "string");
15
34
  }
@@ -30,7 +49,10 @@ function getVariableLabel(variableSchema, variableKey, path) {
30
49
  */
31
50
  function resolveVariableSchema(variableSchema, schemasByKey) {
32
51
  if (variableSchema.schema) {
33
- return schemasByKey?.[variableSchema.schema] ?? null;
52
+ const referenced = schemasByKey?.[variableSchema.schema];
53
+ return referenced
54
+ ? resolveSchemaRefs(referenced, schemasByKey)
55
+ : null;
34
56
  }
35
57
  return variableSchema;
36
58
  }
@@ -41,6 +63,24 @@ function resolveSchemaRefs(schema, schemasByKey) {
41
63
  }
42
64
  return schema;
43
65
  }
66
+ function schemaUsesTimestampFormat(schema, schemasByKey, seen = new Set()) {
67
+ if (seen.has(schema))
68
+ return false;
69
+ seen.add(schema);
70
+ const resolved = resolveSchemaRefs(schema, schemasByKey);
71
+ // Literal values are checked against every format, not only timestamps.
72
+ if (resolved.format !== undefined)
73
+ return true;
74
+ const children = [
75
+ resolved.items,
76
+ resolved.additionalProperties,
77
+ ...Object.values(resolved.properties || {}),
78
+ ...(resolved.oneOf || []),
79
+ ];
80
+ return children.some((child) => child && typeof child === "object"
81
+ ? schemaUsesTimestampFormat(child, schemasByKey, seen)
82
+ : false);
83
+ }
44
84
  /**
45
85
  * Returns true if the value matches the given schema (const, enum, type, object properties, array items, or exactly one of oneOf).
46
86
  * Used for oneOf validation: value must match exactly one branch.
@@ -52,10 +92,16 @@ function valueMatchesSchema(schema, value, schemasByKey) {
52
92
  return matchCount === 1;
53
93
  }
54
94
  if (resolved.const !== undefined) {
55
- return valueDeepEqual(value, resolved.const);
95
+ if (!valueDeepEqual(value, resolved.const))
96
+ return false;
97
+ if (!schemaUsesTimestampFormat(resolved, schemasByKey))
98
+ return true;
56
99
  }
57
100
  if (resolved.enum !== undefined && Array.isArray(resolved.enum)) {
58
- return resolved.enum.some((e) => valueDeepEqual(value, e));
101
+ if (!resolved.enum.some((e) => valueDeepEqual(value, e)))
102
+ return false;
103
+ if (!schemaUsesTimestampFormat(resolved, schemasByKey))
104
+ return true;
59
105
  }
60
106
  const type = resolved.type;
61
107
  if (!type)
@@ -63,6 +109,8 @@ function valueMatchesSchema(schema, value, schemasByKey) {
63
109
  if (type === "string") {
64
110
  if (typeof value !== "string")
65
111
  return false;
112
+ if (!(0, schemaFormats_1.valueMatchesFormat)(resolved.format, value))
113
+ return false;
66
114
  const s = value;
67
115
  if (resolved.minLength !== undefined && s.length < resolved.minLength)
68
116
  return false;
@@ -90,7 +138,7 @@ function valueMatchesSchema(schema, value, schemasByKey) {
90
138
  return false;
91
139
  return true;
92
140
  }
93
- if (type === "double") {
141
+ if (type === "number") {
94
142
  if (typeof value !== "number")
95
143
  return false;
96
144
  if (resolved.minimum !== undefined && value < resolved.minimum)
@@ -255,27 +303,64 @@ function typeOfValue(value) {
255
303
  return "array";
256
304
  return typeof value;
257
305
  }
306
+ const itemOperationLabels = {
307
+ append: "Item appended to",
308
+ appendUnique: "Item appended to",
309
+ prepend: "Item prepended to",
310
+ removeValue: "Item removed from",
311
+ before: "Item inserted before",
312
+ after: "Item inserted after",
313
+ };
314
+ function appendPath(path, child) {
315
+ return typeof child === "number" ? `${path}[${child}]` : `${path ? `${path}.` : ""}${child}`;
316
+ }
317
+ function childMutationValueContext(context, child) {
318
+ if (!context)
319
+ return undefined;
320
+ if (context.operation && itemOperationLabels[context.operation])
321
+ return { ...context, itemPath: appendPath(context.itemPath || "", child) };
322
+ return { ...context, path: appendPath(context.path, child) };
323
+ }
324
+ function mutationSubject(mutation) {
325
+ const variable = `variable "${mutation.variableKey}"`;
326
+ const label = mutation.operation && itemOperationLabels[mutation.operation];
327
+ if (!label)
328
+ return mutation.path ? `Value at "${mutation.path}" in ${variable}` : `Value of ${variable}`;
329
+ const item = `${label} ${mutation.path ? `"${mutation.path}" in ${variable}` : variable}`;
330
+ return mutation.itemPath
331
+ ? `Value at "${mutation.itemPath}" in the ${item.charAt(0).toLowerCase()}${item.slice(1)}`
332
+ : item;
333
+ }
334
+ function valueSubject(variableSchema, variableKey, path, mutation) {
335
+ return mutation
336
+ ? mutationSubject(mutation)
337
+ : `Variable "${getVariableLabel(variableSchema, variableKey, path)}"`;
338
+ }
339
+ /** The authored mutation subject already names its schema, so the type aside is omitted. */
340
+ function typedSubject(subject, type, mutation) {
341
+ return mutation ? subject : `${subject} (type ${type})`;
342
+ }
258
343
  /**
259
344
  * Validates a variable value against an array schema. Recursively validates each item
260
345
  * when the schema defines `items` (nested arrays/objects use the same refinement).
261
346
  * Enforces minItems, maxItems, and uniqueItems when set.
262
347
  */
263
- function refineVariableValueArray(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
264
- const label = getVariableLabel(variableSchema, variableKey, path);
348
+ function refineVariableValueArray(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
349
+ const subject = valueSubject(variableSchema, variableKey, path, mutation);
265
350
  const minItems = variableSchema.minItems;
266
351
  const maxItems = variableSchema.maxItems;
267
352
  const uniqueItems = variableSchema.uniqueItems;
268
353
  if (minItems !== undefined && variableValue.length < minItems) {
269
354
  ctx.addIssue({
270
355
  code: zod_1.z.ZodIssueCode.custom,
271
- message: `Variable "${label}" (type array) length (${variableValue.length}) is less than \`minItems\` (${minItems}).`,
356
+ message: `${typedSubject(subject, "array", mutation)} must have at least ${minItems} items (\`minItems\`), but has ${variableValue.length}.`,
272
357
  path,
273
358
  });
274
359
  }
275
360
  if (maxItems !== undefined && variableValue.length > maxItems) {
276
361
  ctx.addIssue({
277
362
  code: zod_1.z.ZodIssueCode.custom,
278
- message: `Variable "${label}" (type array) length (${variableValue.length}) is greater than \`maxItems\` (${maxItems}).`,
363
+ message: `${typedSubject(subject, "array", mutation)} must have at most ${maxItems} items (\`maxItems\`), but has ${variableValue.length}.`,
279
364
  path,
280
365
  });
281
366
  }
@@ -285,7 +370,7 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
285
370
  if (valueDeepEqual(variableValue[i], variableValue[j])) {
286
371
  ctx.addIssue({
287
372
  code: zod_1.z.ZodIssueCode.custom,
288
- message: `Variable "${label}" (type array) has duplicate items at indices ${i} and ${j} but \`uniqueItems\` is true.`,
373
+ message: `${typedSubject(subject, "array", mutation)} has duplicate items at indices ${i} and ${j} but \`uniqueItems\` is true.`,
289
374
  path,
290
375
  });
291
376
  break;
@@ -296,14 +381,14 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
296
381
  const itemSchema = variableSchema.items;
297
382
  if (itemSchema) {
298
383
  variableValue.forEach((item, index) => {
299
- superRefineVariableValue(projectConfig, itemSchema, item, [...path, index], ctx, variableKey, schemasByKey);
384
+ superRefineVariableValue(projectConfig, itemSchema, item, [...path, index], ctx, variableKey, schemasByKey, childMutationValueContext(mutation, index));
300
385
  });
301
386
  }
302
387
  else {
303
388
  if (!isArrayOfStrings(variableValue)) {
304
389
  ctx.addIssue({
305
390
  code: zod_1.z.ZodIssueCode.custom,
306
- message: `Variable "${label}" (type array): when \`items\` is not set, array must contain only strings; found non-string element.`,
391
+ message: `${typedSubject(subject, "array", mutation)}: when \`items\` is not set, array must contain only strings; found non-string element.`,
307
392
  path,
308
393
  });
309
394
  }
@@ -313,7 +398,7 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
313
398
  if (stringified.length > projectConfig.maxVariableArrayStringifiedLength) {
314
399
  ctx.addIssue({
315
400
  code: zod_1.z.ZodIssueCode.custom,
316
- message: `Variable "${label}" array is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableArrayStringifiedLength}`,
401
+ message: `${subject} array is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableArrayStringifiedLength}`,
317
402
  path,
318
403
  });
319
404
  }
@@ -323,19 +408,21 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
323
408
  * Validates a variable value against an object schema. Recursively validates each property
324
409
  * when the schema defines `properties` (nested objects/arrays use the same refinement).
325
410
  */
326
- function refineVariableValueObject(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
327
- const label = getVariableLabel(variableSchema, variableKey, path);
411
+ function refineVariableValueObject(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
412
+ const subject = valueSubject(variableSchema, variableKey, path, mutation);
328
413
  const schemaProperties = variableSchema.properties;
329
414
  const additionalProperties = variableSchema.additionalProperties;
330
415
  if (schemaProperties && typeof schemaProperties === "object") {
331
- const requiredKeys = variableSchema.required && variableSchema.required.length > 0
332
- ? variableSchema.required.filter((k) => Object.prototype.hasOwnProperty.call(schemaProperties, k))
333
- : Object.keys(schemaProperties);
416
+ // As in JSON Schema, only keys listed in `required` must be present.
417
+ // Without the list every property is optional, matching generated types.
418
+ const requiredKeys = (variableSchema.required || []).filter((k) => Object.prototype.hasOwnProperty.call(schemaProperties, k));
334
419
  for (const key of requiredKeys) {
335
420
  if (!Object.prototype.hasOwnProperty.call(variableValue, key)) {
336
421
  ctx.addIssue({
337
422
  code: zod_1.z.ZodIssueCode.custom,
338
- message: `Missing required property "${key}" in variable "${label}"`,
423
+ message: mutation
424
+ ? `${subject} is missing required property "${key}".`
425
+ : `Missing required property "${key}" in variable "${getVariableLabel(variableSchema, variableKey, path)}"`,
339
426
  path: [...path, key],
340
427
  });
341
428
  }
@@ -343,23 +430,25 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
343
430
  for (const key of Object.keys(variableValue)) {
344
431
  const propSchema = schemaProperties[key];
345
432
  if (!propSchema && additionalProperties && typeof additionalProperties === "object") {
346
- superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey);
433
+ superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
347
434
  }
348
435
  else if (!propSchema) {
349
436
  ctx.addIssue({
350
437
  code: zod_1.z.ZodIssueCode.custom,
351
- message: `Unknown property "${key}" in variable "${label}" (not in schema)`,
438
+ message: mutation
439
+ ? `${subject} has unknown property "${key}" (not in schema).`
440
+ : `Unknown property "${key}" in variable "${getVariableLabel(variableSchema, variableKey, path)}" (not in schema)`,
352
441
  path: [...path, key],
353
442
  });
354
443
  }
355
444
  else {
356
- superRefineVariableValue(projectConfig, propSchema, variableValue[key], [...path, key], ctx, key, schemasByKey);
445
+ superRefineVariableValue(projectConfig, propSchema, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
357
446
  }
358
447
  }
359
448
  }
360
449
  else if (additionalProperties && typeof additionalProperties === "object") {
361
450
  for (const key of Object.keys(variableValue)) {
362
- superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey);
451
+ superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
363
452
  }
364
453
  }
365
454
  else {
@@ -368,7 +457,7 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
368
457
  if (!isFlatObjectValue(propValue)) {
369
458
  ctx.addIssue({
370
459
  code: zod_1.z.ZodIssueCode.custom,
371
- message: `Variable "${label}" is a flat object (no \`properties\` in schema); property "${key}" must be a primitive (string, number, boolean, or null), got: ${typeof propValue}`,
460
+ message: `${subject} is a flat object (no \`properties\` in schema); property "${key}" must be a primitive (string, number, boolean, or null), got: ${typeof propValue}`,
372
461
  path: [...path, key],
373
462
  });
374
463
  }
@@ -379,19 +468,21 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
379
468
  if (stringified.length > projectConfig.maxVariableObjectStringifiedLength) {
380
469
  ctx.addIssue({
381
470
  code: zod_1.z.ZodIssueCode.custom,
382
- message: `Variable "${label}" object is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableObjectStringifiedLength}`,
471
+ message: `${subject} object is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableObjectStringifiedLength}`,
383
472
  path,
384
473
  });
385
474
  }
386
475
  }
387
476
  }
388
- function superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
389
- const label = getVariableLabel(variableSchema, variableKey, path);
477
+ function superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
478
+ const subject = valueSubject(variableSchema, variableKey, path, mutation);
390
479
  if (!variableSchema) {
391
480
  const variableName = path.length > 0 && typeof path[path.length - 1] === "string"
392
481
  ? String(path[path.length - 1])
393
482
  : "variable";
394
- const message = `Variable "${variableName}" is used but not defined in variablesSchema. Define it under variablesSchema first, then use it here.`;
483
+ const message = mutation
484
+ ? `${subject} cannot be validated because its schema is not defined.`
485
+ : `Variable "${variableName}" is used but not defined in variablesSchema. Define it under variablesSchema first, then use it here.`;
395
486
  ctx.addIssue({
396
487
  code: zod_1.z.ZodIssueCode.custom,
397
488
  message,
@@ -403,7 +494,9 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
403
494
  if (variableSchema.schema && effectiveSchema === null) {
404
495
  ctx.addIssue({
405
496
  code: zod_1.z.ZodIssueCode.custom,
406
- message: `Schema "${variableSchema.schema}" could not be loaded for value validation.`,
497
+ message: mutation
498
+ ? `${subject} cannot be validated because schema "${variableSchema.schema}" could not be loaded.`
499
+ : `Schema "${variableSchema.schema}" could not be loaded for value validation.`,
407
500
  path,
408
501
  });
409
502
  return;
@@ -417,14 +510,14 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
417
510
  if (matchCount === 0) {
418
511
  ctx.addIssue({
419
512
  code: zod_1.z.ZodIssueCode.custom,
420
- message: `Variable "${label}" must match exactly one of the \`oneOf\` schemas (got ${JSON.stringify(variableValue)}; matched none).`,
513
+ message: `${subject} must match exactly one of the \`oneOf\` schemas (got ${JSON.stringify(variableValue)}; matched none).`,
421
514
  path,
422
515
  });
423
516
  }
424
517
  else if (matchCount > 1) {
425
518
  ctx.addIssue({
426
519
  code: zod_1.z.ZodIssueCode.custom,
427
- message: `Variable "${label}" must match exactly one of the \`oneOf\` schemas (matched ${matchCount}).`,
520
+ message: `${subject} must match exactly one of the \`oneOf\` schemas (matched ${matchCount}).`,
428
521
  path,
429
522
  });
430
523
  }
@@ -435,11 +528,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
435
528
  if (!valueDeepEqual(variableValue, effectiveConst)) {
436
529
  ctx.addIssue({
437
530
  code: zod_1.z.ZodIssueCode.custom,
438
- message: `Variable "${label}" must equal the constant value defined in schema (got ${JSON.stringify(variableValue)}).`,
531
+ message: `${subject} must equal the constant value defined in schema (got ${JSON.stringify(variableValue)}).`,
439
532
  path,
440
533
  });
441
534
  }
442
- return;
535
+ if (!schemaUsesTimestampFormat(effectiveSchema, schemasByKey))
536
+ return;
443
537
  }
444
538
  const effectiveEnum = effectiveSchema.enum;
445
539
  if (effectiveEnum !== undefined && Array.isArray(effectiveEnum) && effectiveEnum.length > 0) {
@@ -447,47 +541,60 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
447
541
  if (!allowed) {
448
542
  ctx.addIssue({
449
543
  code: zod_1.z.ZodIssueCode.custom,
450
- message: `Variable "${label}" must be one of the allowed enum values (got ${JSON.stringify(variableValue)}).`,
544
+ message: `${subject} must be one of the allowed enum values (got ${JSON.stringify(variableValue)}).`,
451
545
  path,
452
546
  });
453
547
  }
454
- return;
548
+ if (!schemaUsesTimestampFormat(effectiveSchema, schemasByKey))
549
+ return;
455
550
  }
456
551
  // Require a value (no undefined) for every variable usage
457
552
  if (variableValue === undefined) {
458
553
  ctx.addIssue({
459
554
  code: zod_1.z.ZodIssueCode.custom,
460
- message: `Variable "${label}" value is required (got undefined).`,
555
+ message: `${subject} is required.`,
461
556
  path,
462
557
  });
463
558
  return;
464
559
  }
465
560
  const expectedType = effectiveSchema.type;
466
561
  const gotType = typeOfValue(variableValue);
562
+ const receivedType = gotType === "null" || gotType === "undefined"
563
+ ? gotType
564
+ : `${/^[aeiou]/.test(gotType) ? "an" : "a"} ${gotType}`;
467
565
  // string — only string allowed; schema minLength/maxLength/pattern applied when set
468
566
  if (expectedType === "string") {
469
567
  if (typeof variableValue !== "string") {
470
568
  ctx.addIssue({
471
569
  code: zod_1.z.ZodIssueCode.custom,
472
- message: `Variable "${label}" (type string) must be a string; got ${gotType}.`,
570
+ message: `${typedSubject(subject, "string", mutation)} must be a string, but got ${receivedType}.`,
473
571
  path,
474
572
  });
475
573
  return;
476
574
  }
477
575
  const strMinLen = effectiveSchema.minLength;
576
+ if (!(0, schemaFormats_1.valueMatchesFormat)(effectiveSchema.format, variableValue)) {
577
+ ctx.addIssue({
578
+ code: zod_1.z.ZodIssueCode.custom,
579
+ message: effectiveSchema.format === "date-time"
580
+ ? `${subject} is not a valid portable timestamp for format: date-time. Use YYYY-MM-DDTHH:mm:ss with Z or ±HH:mm.`
581
+ : `${subject} is not valid for format: ${effectiveSchema.format}. ${(0, schemaFormats_1.formatValueMessage)(effectiveSchema.format)}`,
582
+ path,
583
+ });
584
+ }
478
585
  const strMaxLen = effectiveSchema.maxLength;
479
586
  const strPattern = effectiveSchema.pattern;
480
587
  if (strMinLen !== undefined && variableValue.length < strMinLen) {
481
588
  ctx.addIssue({
482
589
  code: zod_1.z.ZodIssueCode.custom,
483
- message: `Variable "${label}" (type string) length (${variableValue.length}) is less than \`minLength\` (${strMinLen}).`,
590
+ message: `${typedSubject(subject, "string", mutation)} must be at least ${strMinLen} characters long (\`minLength\`), but has ${variableValue.length}.`,
484
591
  path,
485
592
  });
486
593
  }
487
594
  if (strMaxLen !== undefined && variableValue.length > strMaxLen) {
488
595
  ctx.addIssue({
489
596
  code: zod_1.z.ZodIssueCode.custom,
490
- message: `Variable "${label}" (type string) length (${variableValue.length}) is greater than \`maxLength\` (${strMaxLen}).`,
597
+ message: `${typedSubject(subject, "string", mutation)} must be at most ${strMaxLen} characters long (\`maxLength\`), but has ${variableValue.length}.`,
491
598
  path,
492
599
  });
493
600
  }
@@ -496,7 +603,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
496
603
  if (!new RegExp(strPattern).test(variableValue)) {
497
604
  ctx.addIssue({
498
605
  code: zod_1.z.ZodIssueCode.custom,
499
- message: `Variable "${label}" (type string) does not match \`pattern\`.`,
606
+ message: `${typedSubject(subject, "string", mutation)} does not match \`pattern\`.`,
500
607
  path,
501
608
  });
502
609
  }
@@ -509,7 +616,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
509
616
  variableValue.length > projectConfig.maxVariableStringLength) {
510
617
  ctx.addIssue({
511
618
  code: zod_1.z.ZodIssueCode.custom,
512
- message: `Variable "${label}" value is too long (${variableValue.length} characters), max length is ${projectConfig.maxVariableStringLength}`,
619
+ message: `${subject} is ${variableValue.length} characters long, but the project allows at most ${projectConfig.maxVariableStringLength} (maxVariableStringLength).`,
513
620
  path,
514
621
  });
515
622
  }
@@ -520,7 +627,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
520
627
  if (typeof variableValue !== "number") {
521
628
  ctx.addIssue({
522
629
  code: zod_1.z.ZodIssueCode.custom,
523
- message: `Variable "${label}" (type integer) must be a number; got ${gotType}.`,
630
+ message: `${typedSubject(subject, "integer", mutation)} must be a number, but got ${receivedType}.`,
524
631
  path,
525
632
  });
526
633
  return;
@@ -528,7 +635,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
528
635
  if (!Number.isFinite(variableValue)) {
529
636
  ctx.addIssue({
530
637
  code: zod_1.z.ZodIssueCode.custom,
531
- message: `Variable "${label}" (type integer) must be a finite number; got ${variableValue}.`,
638
+ message: `${typedSubject(subject, "integer", mutation)} must be a finite number, but got ${variableValue}.`,
532
639
  path,
533
640
  });
534
641
  return;
@@ -536,7 +643,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
536
643
  if (!Number.isInteger(variableValue)) {
537
644
  ctx.addIssue({
538
645
  code: zod_1.z.ZodIssueCode.custom,
539
- message: `Variable "${label}" (type integer) must be an integer; got ${variableValue}.`,
646
+ message: `${typedSubject(subject, "integer", mutation)} must be an integer, but got ${variableValue}.`,
540
647
  path,
541
648
  });
542
649
  return;
@@ -546,25 +653,25 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
546
653
  if (intMin !== undefined && variableValue < intMin) {
547
654
  ctx.addIssue({
548
655
  code: zod_1.z.ZodIssueCode.custom,
549
- message: `Variable "${label}" (type integer) must be >= minimum (${intMin}); got ${variableValue}.`,
656
+ message: `${typedSubject(subject, "integer", mutation)} must be >= minimum (${intMin}), but got ${variableValue}.`,
550
657
  path,
551
658
  });
552
659
  }
553
660
  if (intMax !== undefined && variableValue > intMax) {
554
661
  ctx.addIssue({
555
662
  code: zod_1.z.ZodIssueCode.custom,
556
- message: `Variable "${label}" (type integer) must be <= maximum (${intMax}); got ${variableValue}.`,
663
+ message: `${typedSubject(subject, "integer", mutation)} must be <= maximum (${intMax}), but got ${variableValue}.`,
557
664
  path,
558
665
  });
559
666
  }
560
667
  return;
561
668
  }
562
- // double — only finite number allowed
563
- if (expectedType === "double") {
669
+ // number — only finite number allowed
670
+ if (expectedType === "number") {
564
671
  if (typeof variableValue !== "number") {
565
672
  ctx.addIssue({
566
673
  code: zod_1.z.ZodIssueCode.custom,
567
- message: `Variable "${label}" (type double) must be a number; got ${gotType}.`,
674
+ message: `${typedSubject(subject, "number", mutation)} must be a number, but got ${receivedType}.`,
568
675
  path,
569
676
  });
570
677
  return;
@@ -572,24 +679,24 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
572
679
  if (!Number.isFinite(variableValue)) {
573
680
  ctx.addIssue({
574
681
  code: zod_1.z.ZodIssueCode.custom,
575
- message: `Variable "${label}" (type double) must be a finite number; got ${variableValue}.`,
682
+ message: `${typedSubject(subject, "number", mutation)} must be a finite number, but got ${variableValue}.`,
576
683
  path,
577
684
  });
578
685
  return;
579
686
  }
580
- const doubleMin = effectiveSchema.minimum;
581
- const doubleMax = effectiveSchema.maximum;
582
- if (doubleMin !== undefined && variableValue < doubleMin) {
687
+ const numberMin = effectiveSchema.minimum;
688
+ const numberMax = effectiveSchema.maximum;
689
+ if (numberMin !== undefined && variableValue < numberMin) {
583
690
  ctx.addIssue({
584
691
  code: zod_1.z.ZodIssueCode.custom,
585
- message: `Variable "${label}" (type double) must be >= minimum (${doubleMin}); got ${variableValue}.`,
692
+ message: `${typedSubject(subject, "number", mutation)} must be >= minimum (${numberMin}), but got ${variableValue}.`,
586
693
  path,
587
694
  });
588
695
  }
589
- if (doubleMax !== undefined && variableValue > doubleMax) {
696
+ if (numberMax !== undefined && variableValue > numberMax) {
590
697
  ctx.addIssue({
591
698
  code: zod_1.z.ZodIssueCode.custom,
592
- message: `Variable "${label}" (type double) must be <= maximum (${doubleMax}); got ${variableValue}.`,
699
+ message: `${typedSubject(subject, "number", mutation)} must be <= maximum (${numberMax}), but got ${variableValue}.`,
593
700
  path,
594
701
  });
595
702
  }
@@ -600,7 +707,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
600
707
  if (typeof variableValue !== "boolean") {
601
708
  ctx.addIssue({
602
709
  code: zod_1.z.ZodIssueCode.custom,
603
- message: `Variable "${label}" (type boolean) must be a boolean; got ${gotType}.`,
710
+ message: `${typedSubject(subject, "boolean", mutation)} must be a boolean, but got ${receivedType}.`,
604
711
  path,
605
712
  });
606
713
  }
@@ -611,12 +718,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
611
718
  if (!Array.isArray(variableValue)) {
612
719
  ctx.addIssue({
613
720
  code: zod_1.z.ZodIssueCode.custom,
614
- message: `Variable "${label}" (type array) must be an array; got ${gotType}.`,
721
+ message: `${typedSubject(subject, "array", mutation)} must be an array, but got ${receivedType}.`,
615
722
  path,
616
723
  });
617
724
  return;
618
725
  }
619
- refineVariableValueArray(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey);
726
+ refineVariableValueArray(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation);
620
727
  return;
621
728
  }
622
729
  // object — only plain object allowed (no null, no array)
@@ -626,12 +733,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
626
733
  Array.isArray(variableValue)) {
627
734
  ctx.addIssue({
628
735
  code: zod_1.z.ZodIssueCode.custom,
629
- message: `Variable "${label}" (type object) must be a plain object; got ${gotType}.`,
736
+ message: `${typedSubject(subject, "object", mutation)} must be a plain object, but got ${receivedType}.`,
630
737
  path,
631
738
  });
632
739
  return;
633
740
  }
634
- refineVariableValueObject(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey);
741
+ refineVariableValueObject(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation);
635
742
  return;
636
743
  }
637
744
  // json — only string containing valid JSON allowed
@@ -639,7 +746,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
639
746
  if (typeof variableValue !== "string") {
640
747
  ctx.addIssue({
641
748
  code: zod_1.z.ZodIssueCode.custom,
642
- message: `Variable "${label}" (type json) must be a string (JSON string); got ${gotType}.`,
749
+ message: `${typedSubject(subject, "json", mutation)} must be a string (JSON string), but got ${receivedType}.`,
643
750
  path,
644
751
  });
645
752
  return;
@@ -650,7 +757,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
650
757
  if (variableValue.length > projectConfig.maxVariableJSONStringifiedLength) {
651
758
  ctx.addIssue({
652
759
  code: zod_1.z.ZodIssueCode.custom,
653
- message: `Variable "${label}" JSON is too long (${variableValue.length} characters), max length is ${projectConfig.maxVariableJSONStringifiedLength}`,
760
+ message: `${subject} JSON is too long (${variableValue.length} characters), max length is ${projectConfig.maxVariableJSONStringifiedLength}`,
654
761
  path,
655
762
  });
656
763
  }
@@ -660,16 +767,19 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
660
767
  catch (e) {
661
768
  ctx.addIssue({
662
769
  code: zod_1.z.ZodIssueCode.custom,
663
- message: `Variable "${label}" (type json) must be a valid JSON string; parse failed.`,
770
+ message: `${typedSubject(subject, "json", mutation)} must be a valid JSON string; parse failed.`,
664
771
  path,
665
772
  });
666
773
  }
667
774
  return;
668
775
  }
776
+ // A removed type already reports its migration at `type`.
777
+ if ((0, schemaFormats_1.isRemovedSchemaType)(expectedType))
778
+ return;
669
779
  // Unknown variable type — schema is invalid or unsupported
670
780
  ctx.addIssue({
671
781
  code: zod_1.z.ZodIssueCode.custom,
672
- message: `Variable "${label}" has unknown or unsupported type "${String(expectedType)}" in variablesSchema.`,
782
+ message: `${subject} has unknown or unsupported type "${String(expectedType)}" in variablesSchema.`,
673
783
  path,
674
784
  });
675
785
  }
@@ -678,7 +788,15 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
678
788
  * Key may be a root variable name or mutation notation (e.g. "config.width", "items[0].name").
679
789
  */
680
790
  function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, variableValue, path, ctx, schemasByKey) {
681
- if ((0, mutationNotation_1.isMutationKey)(variableKey)) {
791
+ const variableSchema = variableSchemaByKey[variableKey];
792
+ if (!variableSchema && (0, mutationNotation_1.isMutationKey)(variableKey)) {
793
+ try {
794
+ (0, variableOverrideProgram_1.compileVariableMutation)(variableKey, variableValue);
795
+ }
796
+ catch (error) {
797
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: error.message, path });
798
+ return;
799
+ }
682
800
  const validation = (0, mutationNotation_1.validateMutationKey)(variableKey, variableSchemaByKey, schemasByKey);
683
801
  if (!validation.valid && validation.error) {
684
802
  ctx.addIssue({
@@ -689,11 +807,14 @@ function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, va
689
807
  return;
690
808
  }
691
809
  if (validation.valueSchema) {
692
- superRefineVariableValue(projectConfig, validation.valueSchema, variableValue, path, ctx, variableKey, schemasByKey);
810
+ superRefineVariableValue(projectConfig, validation.valueSchema, variableValue, path, ctx, validation.rootKey, schemasByKey, {
811
+ variableKey: validation.rootKey,
812
+ path: (0, mutationNotation_1.getMutationPath)(variableKey).slice(validation.rootKey.length).replace(/^\./, ""),
813
+ operation: validation.operation,
814
+ });
693
815
  }
694
816
  return;
695
817
  }
696
- const variableSchema = variableSchemaByKey[variableKey];
697
818
  if (!variableSchema) {
698
819
  ctx.addIssue({
699
820
  code: zod_1.z.ZodIssueCode.custom,
@@ -704,9 +825,52 @@ function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, va
704
825
  }
705
826
  superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey);
706
827
  }
707
- function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides, pathPrefix, projectConfig, schemasByKey, }) {
828
+ function refineResolvedVariableValues(values, variableSchemaByKey, path, projectConfig, ctx, schemasByKey) {
829
+ const validValues = {};
830
+ const invalidRoots = new Set();
831
+ const mutatedRoots = new Set();
832
+ for (const [key, value] of Object.entries(values || {})) {
833
+ const root = (0, mutateVariables_1.rootVariableFromOverrideKey)(key, variableSchemaByKey);
834
+ let invalid = false;
835
+ refineVariableEntry(projectConfig, variableSchemaByKey, key, value, [...path, key], {
836
+ ...ctx,
837
+ addIssue(issue) {
838
+ invalid = true;
839
+ ctx.addIssue(issue);
840
+ },
841
+ }, schemasByKey);
842
+ if (invalid)
843
+ invalidRoots.add(root);
844
+ else
845
+ validValues[key] = value;
846
+ if (key !== root)
847
+ mutatedRoots.add(root);
848
+ }
849
+ // Do not resolve a partially valid assignment or cascade from an invalid parent.
850
+ for (const key of Object.keys(validValues)) {
851
+ if (invalidRoots.has((0, mutateVariables_1.rootVariableFromOverrideKey)(key, variableSchemaByKey))) {
852
+ delete validValues[key];
853
+ }
854
+ }
855
+ try {
856
+ const resolved = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variableSchemaByKey, validValues);
857
+ for (const [key, value] of Object.entries(resolved || {})) {
858
+ // Direct values were validated above. Only mutations need a result check.
859
+ if (!mutatedRoots.has(key))
860
+ continue;
861
+ superRefineVariableValue(projectConfig, variableSchemaByKey[key], value, [...path, key], ctx, key, schemasByKey);
862
+ }
863
+ return resolved;
864
+ }
865
+ catch (error) {
866
+ ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: error.message, path });
867
+ return undefined;
868
+ }
869
+ }
870
+ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides, pathPrefix, projectConfig, schemasByKey, baseValues, }) {
708
871
  for (const variableKey of Object.keys(variableOverrides)) {
709
- if ((0, mutationNotation_1.isMutationKey)(variableKey)) {
872
+ const variableSchema = variableSchemaByKey[variableKey];
873
+ if (!variableSchema && (0, mutationNotation_1.isMutationKey)(variableKey)) {
710
874
  ctx.addIssue({
711
875
  code: zod_1.z.ZodIssueCode.custom,
712
876
  message: `Variable override key "${variableKey}" must be a declared variable key, not mutation notation. ` +
@@ -715,7 +879,6 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
715
879
  });
716
880
  continue;
717
881
  }
718
- const variableSchema = variableSchemaByKey[variableKey];
719
882
  if (!variableSchema) {
720
883
  ctx.addIssue({
721
884
  code: zod_1.z.ZodIssueCode.custom,
@@ -751,9 +914,9 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
751
914
  ];
752
915
  if (typeof overrideValue === "object" &&
753
916
  overrideValue !== null &&
754
- !Array.isArray(overrideValue)) {
755
- const pathMap = overrideValue;
756
- const pathKeys = Object.keys(pathMap);
917
+ (!Array.isArray(overrideValue) || usesExplicitMutation)) {
918
+ const pathEntries = (0, mutationEntries_1.mutationEntries)(overrideValue);
919
+ const pathKeys = pathEntries.map(([key]) => key);
757
920
  const hasStructuredObjectSchema = resolvedVariableSchema?.type === "object" &&
758
921
  (Boolean(resolvedVariableSchema.properties) ||
759
922
  Boolean(resolvedVariableSchema.additionalProperties));
@@ -761,26 +924,43 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
761
924
  pathKeys.some((pathKey) => (0, mutationNotation_1.isMutationKey)(pathKey)) ||
762
925
  (hasStructuredObjectSchema && pathKeys.length > 0);
763
926
  if (treatAsPathMap) {
764
- for (const pathKey of pathKeys) {
765
- const composedMutationKey = `${variableKey}.${pathKey}`;
766
- const validation = (0, mutationNotation_1.validateMutationKey)(composedMutationKey, variableSchemaByKey, schemasByKey);
927
+ let invalidOperand = false;
928
+ const operandContext = {
929
+ ...ctx,
930
+ addIssue(issue) {
931
+ invalidOperand = true;
932
+ ctx.addIssue(issue);
933
+ },
934
+ };
935
+ for (const [entryIndex, [pathKey, mutationValue]] of pathEntries.entries()) {
936
+ const mutationPath = [
937
+ ...valuePath,
938
+ ...(0, mutationEntries_1.mutationEntryPath)(overrideValue, entryIndex, pathKey),
939
+ ];
940
+ const validationRootKey = "variable";
941
+ const composedMutationKey = `${validationRootKey}${pathKey.startsWith("[") || pathKey.startsWith(":") ? "" : "."}${pathKey}`;
942
+ try {
943
+ (0, variableOverrideProgram_1.compileVariableMutation)(pathKey, mutationValue);
944
+ }
945
+ catch (error) {
946
+ operandContext.addIssue({
947
+ code: zod_1.z.ZodIssueCode.custom,
948
+ message: error.message,
949
+ path: mutationPath,
950
+ });
951
+ continue;
952
+ }
953
+ const validation = (0, mutationNotation_1.validateMutationKey)(composedMutationKey, { [validationRootKey]: variableSchema }, schemasByKey, { variableKey, path: pathKey });
767
954
  if (!validation.valid) {
768
- ctx.addIssue({
955
+ operandContext.addIssue({
769
956
  code: zod_1.z.ZodIssueCode.custom,
770
957
  message: validation.error ??
771
958
  `Invalid mutation path "${pathKey}" in variableOverride for "${variableKey}".`,
772
- path: [...valuePath, pathKey],
959
+ path: mutationPath,
773
960
  });
774
961
  continue;
775
962
  }
776
963
  if (validation.operation === "remove") {
777
- if (pathMap[pathKey] !== null) {
778
- ctx.addIssue({
779
- code: zod_1.z.ZodIssueCode.custom,
780
- message: `Mutation "${pathKey}:remove" must use \`null\` as value.`,
781
- path: [...valuePath, pathKey],
782
- });
783
- }
784
964
  continue;
785
965
  }
786
966
  const fallbackValueSchema = validation.operation === "append" ||
@@ -793,7 +973,22 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
793
973
  if (!valueSchema) {
794
974
  continue;
795
975
  }
796
- superRefineVariableValue(projectConfig, valueSchema, pathMap[pathKey], [...valuePath, pathKey], ctx, pathKey, schemasByKey);
976
+ superRefineVariableValue(projectConfig, valueSchema, mutationValue, mutationPath, operandContext, variableKey, schemasByKey, { variableKey, path: (0, mutationNotation_1.getMutationPath)(pathKey), operation: validation.operation });
977
+ }
978
+ if (invalidOperand)
979
+ return;
980
+ try {
981
+ const resolved = (0, mutateVariables_1.resolveMutationsForSingleVariable)(variableSchemaByKey, variableKey, overrideValue, baseValues?.[variableKey], usesExplicitMutation);
982
+ superRefineVariableValue(projectConfig, variableSchema, resolved, valuePath, (0, mutationResultPaths_1.withMutationResultPaths)(ctx, override.mutate, valuePath, baseValues?.[variableKey] === undefined
983
+ ? variableSchema.defaultValue
984
+ : baseValues[variableKey], variableKey), variableKey, schemasByKey);
985
+ }
986
+ catch (error) {
987
+ ctx.addIssue({
988
+ code: zod_1.z.ZodIssueCode.custom,
989
+ message: error.message,
990
+ path: valuePath,
991
+ });
797
992
  }
798
993
  }
799
994
  else {
@@ -821,26 +1016,20 @@ variableSchemaByKey, variationValues, force, pathPrefix, projectConfig, schemasB
821
1016
  }
822
1017
  // force[n].variables[key]
823
1018
  if (f.variables) {
824
- Object.keys(f.variables).forEach((variableKey) => {
825
- refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, f.variables[variableKey], pathPrefix.concat([fN, "variables", variableKey]), ctx, schemasByKey);
826
- });
1019
+ refineResolvedVariableValues(f.variables, variableSchemaByKey, [...pathPrefix, fN, "variables"], projectConfig, ctx, schemasByKey);
827
1020
  }
828
1021
  });
829
1022
  }
830
1023
  function refineRules({ ctx, parsedFeature, variableSchemaByKey, variationValues, rules, pathPrefix, projectConfig, schemasByKey, }) {
831
1024
  rules.forEach((rule, ruleN) => {
832
- // rules[n].variables[key]
833
- if (rule.variables) {
834
- Object.keys(rule.variables).forEach((variableKey) => {
835
- refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, rule.variables[variableKey], pathPrefix.concat([ruleN, "variables", variableKey]), ctx, schemasByKey);
836
- });
837
- }
838
1025
  // rules[n].variableOverrides[key][].value (path-map or full value)
1026
+ const baseValues = refineResolvedVariableValues(rule.variables, variableSchemaByKey, [...pathPrefix, ruleN, "variables"], projectConfig, ctx, schemasByKey);
839
1027
  if (rule.variableOverrides) {
840
1028
  refineVariableOverrides({
841
1029
  ctx,
842
1030
  variableSchemaByKey,
843
1031
  variableOverrides: rule.variableOverrides,
1032
+ baseValues,
844
1033
  pathPrefix: [...pathPrefix, ruleN, "variableOverrides"],
845
1034
  projectConfig,
846
1035
  schemasByKey,
@@ -886,11 +1075,10 @@ function refineRules({ ctx, parsedFeature, variableSchemaByKey, variationValues,
886
1075
  });
887
1076
  }
888
1077
  // weights sum must be 100
889
- const weightsSum = overriddenVariationWeights.reduce((sum, weight) => sum + weight, 0);
890
- if (weightsSum !== 100) {
1078
+ if (!weightsSumTo100(overriddenVariationWeights)) {
891
1079
  ctx.addIssue({
892
1080
  code: zod_1.z.ZodIssueCode.custom,
893
- message: "Variation weights must sum to 100",
1081
+ message: `Variation weights must sum to 100, but they sum to ${formatWeightsSum(overriddenVariationWeights)}.`,
894
1082
  path: pathPrefix.concat([ruleN, "variationWeights"]),
895
1083
  });
896
1084
  }
@@ -898,8 +1086,8 @@ function refineRules({ ctx, parsedFeature, variableSchemaByKey, variationValues,
898
1086
  }
899
1087
  });
900
1088
  }
901
- function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttributeKeys, availableSegmentKeys, availableFeatureKeys, availableSchemaKeys = [], schemasByKey = {}, featuresByKey = {}) {
902
- const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(availableSchemaKeys);
1089
+ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttributeKeys, availableSegmentKeys, availableFeatureKeys, availableSchemaKeys = [], schemasByKey = {}, featuresByKey = {}, variablesByKey = {}) {
1090
+ const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(availableSchemaKeys, schemasByKey);
903
1091
  const variableValueZodSchema = schema_1.valueZodSchema;
904
1092
  const variableValueOrNullZodSchema = zod_1.z.union([schema_1.valueZodSchema, zod_1.z.null()]);
905
1093
  const overridePathMapValueZodSchema = zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema);
@@ -908,56 +1096,22 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
908
1096
  overridePathMapValueZodSchema,
909
1097
  ]);
910
1098
  const variationValueZodSchema = zod_1.z.string().min(1);
911
- const plainGroupSegment = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => value === "*" || availableSegmentKeys.includes(value), (value) => `Unknown segment key "${value}"`);
912
- const andOrNotGroupSegment = zod_1.z.union([
913
- zod_1.z
914
- .object({
915
- and: zod_1.z.array(zod_1.z.lazy(() => groupSegmentZodSchema)).min(1),
916
- })
917
- .strict(),
918
- zod_1.z
919
- .object({
920
- or: zod_1.z.array(zod_1.z.lazy(() => groupSegmentZodSchema)).min(1),
921
- })
922
- .strict(),
923
- zod_1.z
924
- .object({
925
- not: zod_1.z.array(zod_1.z.lazy(() => groupSegmentZodSchema)).min(1),
926
- })
927
- .strict(),
928
- ]);
929
- const groupSegmentZodSchema = zod_1.z.union([andOrNotGroupSegment, plainGroupSegment]);
930
- const groupSegmentsZodSchema = zod_1.z.union([zod_1.z.array(groupSegmentZodSchema), groupSegmentZodSchema]);
931
- const requiredFeaturesZodSchema = (0, requiredFeaturesSchema_1.getRequiredFeaturesZodSchema)(featuresByKey, availableFeatureKeys).optional();
1099
+ conditionsZodSchema =
1100
+ conditionsZodSchema.withEntities?.(featuresByKey, variablesByKey, availableSegmentKeys) ||
1101
+ conditionsZodSchema;
932
1102
  const featureVariableOverrideSchema = zod_1.z
933
1103
  .object({
934
1104
  key: zod_1.z.string().min(1).optional(),
935
1105
  description: zod_1.z.string().optional(),
936
1106
  promotable: zod_1.z.boolean().optional(),
937
1107
  conditions: conditionsZodSchema.optional(),
938
- segments: groupSegmentsZodSchema.optional(),
939
- requiredFeatures: requiredFeaturesZodSchema,
1108
+ ...removedConditionFields_1.removedConditionFields,
940
1109
  value: overrideValueZodSchema.optional(),
941
- mutate: overridePathMapValueZodSchema.optional(),
1110
+ mutate: (0, mutationSchema_1.getMutationSchema)(overridePathMapValueZodSchema).optional(),
942
1111
  })
943
1112
  .strict()
944
1113
  .superRefine((override, ctx) => {
945
- if (typeof override.conditions === "undefined" &&
946
- typeof override.segments === "undefined" &&
947
- typeof override.requiredFeatures === "undefined") {
948
- ctx.addIssue({
949
- code: zod_1.z.ZodIssueCode.custom,
950
- message: "A variable override must define `conditions`, `segments`, or `requiredFeatures`.",
951
- path: ["segments"],
952
- });
953
- }
954
- if (typeof override.conditions !== "undefined" && typeof override.segments !== "undefined") {
955
- ctx.addIssue({
956
- code: zod_1.z.ZodIssueCode.custom,
957
- message: "A variable override cannot define both `conditions` and `segments`.",
958
- path: ["segments"],
959
- });
960
- }
1114
+ (0, removedConditionFields_1.refineRequiredConditions)(override, ctx);
961
1115
  const hasValue = Object.prototype.hasOwnProperty.call(override, "value");
962
1116
  const hasMutate = Object.prototype.hasOwnProperty.call(override, "mutate");
963
1117
  if (hasValue === hasMutate) {
@@ -1011,15 +1165,27 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1011
1165
  key: zod_1.z.string(),
1012
1166
  description: zod_1.z.string().optional(),
1013
1167
  promotable: zod_1.z.boolean().optional(),
1014
- segments: groupSegmentsZodSchema,
1168
+ conditions: conditionsZodSchema.optional(),
1169
+ ...removedConditionFields_1.removedConditionFields,
1015
1170
  percentage: zod_1.z.number().min(0).max(100),
1016
- enabled: zod_1.z.boolean().optional(),
1171
+ // Accepted only so lint can explain the replacement below.
1172
+ enabled: zod_1.z.unknown().optional(),
1017
1173
  variation: variationValueZodSchema.optional(),
1018
1174
  variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
1019
1175
  variableOverrides: zod_1.z.record(zod_1.z.string(), featureVariableOverridesSchema).optional(),
1020
1176
  variationWeights: zod_1.z.record(zod_1.z.string(), zod_1.z.number().min(0).max(100)).optional(),
1021
1177
  })
1022
- .strict())
1178
+ .strict()
1179
+ .superRefine(removedConditionFields_1.refineRequiredConditions)
1180
+ .superRefine((rule, ctx) => {
1181
+ if (Object.prototype.hasOwnProperty.call(rule, "enabled")) {
1182
+ ctx.addIssue({
1183
+ code: zod_1.z.ZodIssueCode.custom,
1184
+ message: "Rules do not take `enabled`. Set `percentage: 0` to switch this audience off, or add a `force` entry.",
1185
+ path: ["enabled"],
1186
+ });
1187
+ }
1188
+ }))
1023
1189
  // must have at least one rule
1024
1190
  .superRefine((value, ctx) => {
1025
1191
  if (value.length === 0) {
@@ -1031,49 +1197,46 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1031
1197
  })
1032
1198
  // duplicate rules
1033
1199
  .superRefine((value, ctx) => {
1034
- const keys = value.map((v) => v.key);
1035
- if (keys.length !== new Set(keys).size) {
1036
- ctx.addIssue({
1037
- code: zod_1.z.ZodIssueCode.custom,
1038
- message: "Duplicate rule keys found: " + value.map((v) => v.key).join(", "),
1039
- });
1040
- }
1200
+ const seen = new Set();
1201
+ const reported = new Set();
1202
+ value.forEach((rule, index) => {
1203
+ if (seen.has(rule.key) && !reported.has(rule.key)) {
1204
+ ctx.addIssue({
1205
+ code: zod_1.z.ZodIssueCode.custom,
1206
+ message: `Duplicate rule key "${rule.key}". Each rule key must be unique.`,
1207
+ path: [index, "key"],
1208
+ });
1209
+ reported.add(rule.key);
1210
+ }
1211
+ seen.add(rule.key);
1212
+ });
1041
1213
  })
1042
1214
  // enforce catch-all rule
1043
1215
  .superRefine((value, ctx) => {
1044
1216
  if (!projectConfig.enforceCatchAllRule) {
1045
1217
  return;
1046
1218
  }
1047
- const hasCatchAllAsLastRule = value[value.length - 1].segments === "*";
1219
+ const hasCatchAllAsLastRule = value[value.length - 1]?.conditions === "*";
1048
1220
  if (!hasCatchAllAsLastRule) {
1049
1221
  ctx.addIssue({
1050
1222
  code: zod_1.z.ZodIssueCode.custom,
1051
- message: `Missing catch-all rule with \`segments: "*"\` at the end`,
1223
+ message: `Missing catch-all rule with \`conditions: "*"\` at the end`,
1052
1224
  });
1053
1225
  }
1054
1226
  });
1055
1227
  const forceSchema = zod_1.z
1056
- .array(zod_1.z.union([
1057
- zod_1.z
1058
- .object({
1059
- segments: groupSegmentsZodSchema,
1060
- enabled: zod_1.z.boolean().optional(),
1061
- variation: variationValueZodSchema.optional(),
1062
- variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
1063
- })
1064
- .strict(),
1065
- zod_1.z
1066
- .object({
1067
- conditions: conditionsZodSchema,
1068
- enabled: zod_1.z.boolean().optional(),
1069
- variation: variationValueZodSchema.optional(),
1070
- variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
1071
- })
1072
- .strict(),
1073
- ]))
1228
+ .array(zod_1.z
1229
+ .object({
1230
+ conditions: conditionsZodSchema.optional(),
1231
+ ...removedConditionFields_1.removedConditionFields,
1232
+ enabled: zod_1.z.boolean().optional(),
1233
+ variation: variationValueZodSchema.optional(),
1234
+ variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
1235
+ })
1236
+ .strict()
1237
+ .superRefine(removedConditionFields_1.refineRequiredConditions))
1074
1238
  .optional();
1075
- const attributeKeyZodSchema = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => value === "*" || availableAttributeKeys.includes(value), (value) => `Unknown attribute "${value}"`);
1076
- const featureKeyZodSchema = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => availableFeatureKeys.includes(value), (value) => `Unknown feature "${value}"`);
1239
+ const attributeKeyZodSchema = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => value === "*" || availableAttributeKeys.includes(value), (value) => `Unknown attribute "${value}".${(0, diagnostics_1.suggestKey)(value, availableAttributeKeys)}`, () => zodHelpers_1.UNKNOWN_REFERENCE);
1077
1240
  const environmentKeys = Array.isArray(projectConfig.environments)
1078
1241
  ? projectConfig.environments
1079
1242
  : [];
@@ -1086,26 +1249,20 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1086
1249
  tags: zod_1.z
1087
1250
  .array((0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => projectConfig.tags.includes(value), (value) => `Unknown tag "${value}"`))
1088
1251
  .superRefine((value, ctx) => {
1089
- if (value.length !== new Set(value).size) {
1252
+ const duplicates = value.filter((tag, index) => value.indexOf(tag) !== index);
1253
+ for (const tag of new Set(duplicates)) {
1090
1254
  ctx.addIssue({
1091
1255
  code: zod_1.z.ZodIssueCode.custom,
1092
- message: "Duplicate tags found: " + value.join(", "),
1256
+ message: `Duplicate tag "${tag}".`,
1257
+ params: { code: "duplicate_tag" },
1258
+ path: [value.lastIndexOf(tag)],
1093
1259
  });
1094
1260
  }
1095
1261
  })
1096
1262
  .optional(),
1097
- required: zod_1.z
1098
- .array(zod_1.z.union([
1099
- featureKeyZodSchema,
1100
- zod_1.z
1101
- .object({
1102
- key: featureKeyZodSchema,
1103
- variation: zod_1.z.string().optional(),
1104
- })
1105
- .strict(),
1106
- ]))
1107
- .optional(),
1108
- requiredFeatures: (0, requiredFeaturesSchema_1.getRequiredFeaturesZodSchema)(featuresByKey, availableFeatureKeys).optional(),
1263
+ required: zod_1.z.unknown().optional(),
1264
+ conditions: conditionsZodSchema.optional(),
1265
+ ...removedConditionFields_1.removedConditionFields,
1109
1266
  bucketBy: zod_1.z.union([
1110
1267
  attributeKeyZodSchema,
1111
1268
  zod_1.z.array(attributeKeyZodSchema),
@@ -1132,11 +1289,12 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1132
1289
  oneOf: zod_1.z.array(schemaZodSchema).min(1).optional(),
1133
1290
  minimum: zod_1.z.number().optional(),
1134
1291
  maximum: zod_1.z.number().optional(),
1135
- minLength: zod_1.z.number().optional(),
1136
- maxLength: zod_1.z.number().optional(),
1292
+ minLength: schema_1.countZodSchema.optional(),
1293
+ maxLength: schema_1.countZodSchema.optional(),
1137
1294
  pattern: zod_1.z.string().optional(),
1138
- minItems: zod_1.z.number().optional(),
1139
- maxItems: zod_1.z.number().optional(),
1295
+ format: schema_1.schemaFormatZodSchema.optional(),
1296
+ minItems: schema_1.countZodSchema.optional(),
1297
+ maxItems: schema_1.countZodSchema.optional(),
1140
1298
  uniqueItems: zod_1.z.boolean().optional(),
1141
1299
  description: zod_1.z.string().optional(),
1142
1300
  defaultValue: variableValueZodSchema,
@@ -1144,6 +1302,8 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1144
1302
  useDefaultWhenDisabled: zod_1.z.boolean().optional(),
1145
1303
  })
1146
1304
  .strict()
1305
+ .superRefine((variableSchema, ctx) => (0, schemaFormats_1.refineRemovedSchemaType)(variableSchema, ctx))
1306
+ .superRefine((variableSchema, ctx) => (0, schema_1.refineSchemaFormat)(variableSchema, [], ctx, schemasByKey))
1147
1307
  .superRefine((variableSchema, ctx) => {
1148
1308
  const hasRef = "schema" in variableSchema && variableSchema.schema != null;
1149
1309
  const hasInline = "type" in variableSchema &&
@@ -1231,6 +1391,14 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1231
1391
  message: "Duplicate variation values found: " + value.map((v) => v.value).join(", "),
1232
1392
  });
1233
1393
  }
1394
+ // A short split builds once, then every later build rejects its saved allocation.
1395
+ const weights = value.map((v) => v.weight);
1396
+ if (value.length > 0 && !weightsSumTo100(weights)) {
1397
+ ctx.addIssue({
1398
+ code: zod_1.z.ZodIssueCode.custom,
1399
+ message: `Variation weights must sum to 100, but they sum to ${formatWeightsSum(weights)}.`,
1400
+ });
1401
+ }
1234
1402
  })
1235
1403
  .optional(),
1236
1404
  expose: !Array.isArray(projectConfig.environments)
@@ -1247,32 +1415,24 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1247
1415
  })
1248
1416
  .strict()
1249
1417
  .superRefine((value, ctx) => {
1250
- if (value.required && value.requiredFeatures) {
1418
+ (0, removedConditionFields_1.refineRemovedConditionFields)(value, ctx);
1419
+ if (Object.prototype.hasOwnProperty.call(value, "required")) {
1251
1420
  ctx.addIssue({
1252
1421
  code: zod_1.z.ZodIssueCode.custom,
1253
- message: "A feature cannot define both `required` and `requiredFeatures`.",
1254
- path: ["requiredFeatures"],
1422
+ message: "Feature `required` has been removed. Use `conditions` and rename each `{ key: ... }` entry to `{ feature: ... }`. Schema property `required` is unchanged.",
1423
+ path: ["required"],
1255
1424
  });
1256
1425
  }
1257
1426
  // disabledVariationValue
1258
- if (value.disabledVariationValue) {
1259
- if (!value.variations) {
1427
+ if (value.disabledVariationValue !== undefined && value.variations?.length) {
1428
+ const variationValues = value.variations.map((v) => v.value);
1429
+ if (variationValues.indexOf(value.disabledVariationValue) === -1) {
1260
1430
  ctx.addIssue({
1261
1431
  code: zod_1.z.ZodIssueCode.custom,
1262
- message: "Disabled variation value is set, but no variations are present in feature.",
1432
+ message: `Disabled variation value "${value.disabledVariationValue}" is not one of the defined variations: ${variationValues.join(", ")}`,
1263
1433
  path: ["disabledVariationValue"],
1264
1434
  });
1265
1435
  }
1266
- else {
1267
- const variationValues = value.variations.map((v) => v.value);
1268
- if (variationValues.indexOf(value.disabledVariationValue) === -1) {
1269
- ctx.addIssue({
1270
- code: zod_1.z.ZodIssueCode.custom,
1271
- message: `Disabled variation value "${value.disabledVariationValue}" is not one of the defined variations: ${variationValues.join(", ")}`,
1272
- path: ["disabledVariationValue"],
1273
- });
1274
- }
1275
- }
1276
1436
  }
1277
1437
  // When variablesSchema is absent, variableSchemaByKey is {} so any variable key used in
1278
1438
  // rules/force/variations will be reported as "not defined in variablesSchema".
@@ -1335,18 +1495,14 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1335
1495
  // variations: validate variation.variables and variation.variableOverrides (each value against its variable schema)
1336
1496
  if (value.variations) {
1337
1497
  value.variations.forEach((variation, variationN) => {
1338
- // variations[n].variables[key]
1339
- if (variation.variables) {
1340
- for (const variableKey of Object.keys(variation.variables)) {
1341
- refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, variation.variables[variableKey], ["variations", variationN, "variables", variableKey], ctx, schemasByKey);
1342
- }
1343
- }
1344
1498
  // variations[n].variableOverrides[key][].value (path-map or full value)
1499
+ const baseValues = refineResolvedVariableValues(variation.variables, variableSchemaByKey, ["variations", variationN, "variables"], projectConfig, ctx, schemasByKey);
1345
1500
  if (variation.variableOverrides) {
1346
1501
  refineVariableOverrides({
1347
1502
  ctx,
1348
1503
  variableSchemaByKey,
1349
1504
  variableOverrides: variation.variableOverrides,
1505
+ baseValues,
1350
1506
  pathPrefix: ["variations", variationN, "variableOverrides"],
1351
1507
  projectConfig,
1352
1508
  schemasByKey,
@@ -1415,6 +1571,51 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
1415
1571
  }
1416
1572
  }
1417
1573
  });
1418
- return featureZodSchema;
1574
+ const editorConditions = conditionsZodSchema.editorSchema || conditionsZodSchema;
1575
+ const editorOverride = zod_1.z
1576
+ .object({
1577
+ ...featureVariableOverrideSchema.shape,
1578
+ conditions: editorConditions,
1579
+ })
1580
+ .omit({ segments: true, requiredFeatures: true, requiredVariables: true })
1581
+ .strict();
1582
+ const editorOverrides = zod_1.z.record(zod_1.z.string(), zod_1.z.array(editorOverride));
1583
+ const editorRule = zod_1.z
1584
+ .object({
1585
+ ...rulesSchema.element.shape,
1586
+ conditions: editorConditions,
1587
+ variableOverrides: editorOverrides.optional(),
1588
+ })
1589
+ .omit({ segments: true, requiredFeatures: true, requiredVariables: true })
1590
+ .strict();
1591
+ const editorForce = zod_1.z
1592
+ .object({
1593
+ conditions: editorConditions,
1594
+ enabled: zod_1.z.boolean().optional(),
1595
+ variation: variationValueZodSchema.optional(),
1596
+ variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
1597
+ })
1598
+ .strict();
1599
+ const editorVariation = zod_1.z
1600
+ .object({
1601
+ ...featureZodSchema.shape.variations.unwrap().element.shape,
1602
+ variableOverrides: editorOverrides.optional(),
1603
+ })
1604
+ .strict();
1605
+ const editorSchema = zod_1.z
1606
+ .object({
1607
+ ...featureZodSchema.shape,
1608
+ conditions: editorConditions.optional(),
1609
+ variations: zod_1.z.array(editorVariation).optional(),
1610
+ rules: !Array.isArray(projectConfig.environments)
1611
+ ? zod_1.z.array(editorRule).min(1)
1612
+ : zod_1.z.partialRecord(zod_1.z.enum(environmentKeys), zod_1.z.array(editorRule).min(1)),
1613
+ force: (!Array.isArray(projectConfig.environments)
1614
+ ? zod_1.z.array(editorForce)
1615
+ : zod_1.z.partialRecord(zod_1.z.enum(environmentKeys), zod_1.z.array(editorForce))).optional(),
1616
+ })
1617
+ .omit({ segments: true, requiredFeatures: true, requiredVariables: true })
1618
+ .strict();
1619
+ return Object.assign(featureZodSchema, { editorSchema });
1419
1620
  }
1420
1621
  //# sourceMappingURL=featureSchema.js.map