@featurevisor/core 3.11.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/lib/assess-distribution/index.js +6 -2
- package/lib/assess-distribution/index.js.map +1 -1
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.js +15 -10
- package/lib/benchmark/index.js.map +1 -1
- package/lib/builder/applyContextToConditions.d.ts +5 -4
- package/lib/builder/applyContextToConditions.js +84 -89
- package/lib/builder/applyContextToConditions.js.map +1 -1
- package/lib/builder/applyContextToDatafile.d.ts +2 -2
- package/lib/builder/applyContextToDatafile.js +45 -149
- package/lib/builder/applyContextToDatafile.js.map +1 -1
- package/lib/builder/applyContextToSegments.d.ts +6 -4
- package/lib/builder/applyContextToSegments.js +9 -98
- package/lib/builder/applyContextToSegments.js.map +1 -1
- package/lib/builder/buildDatafile.d.ts +15 -6
- package/lib/builder/buildDatafile.js +320 -220
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/builder/buildProject.d.ts +2 -1
- package/lib/builder/buildProject.js +36 -37
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/buildRuntimeDatafiles.js +2 -0
- package/lib/builder/buildRuntimeDatafiles.js.map +1 -1
- package/lib/builder/environments.d.ts +3 -0
- package/lib/builder/environments.js +26 -0
- package/lib/builder/environments.js.map +1 -0
- package/lib/builder/hashes.d.ts +5 -5
- package/lib/builder/hashes.js +82 -100
- package/lib/builder/hashes.js.map +1 -1
- package/lib/builder/inflate.d.ts +7 -0
- package/lib/builder/inflate.js +26 -0
- package/lib/builder/inflate.js.map +1 -0
- package/lib/builder/mutateVariables.d.ts +6 -2
- package/lib/builder/mutateVariables.js +26 -18
- package/lib/builder/mutateVariables.js.map +1 -1
- package/lib/builder/mutationEntries.d.ts +5 -0
- package/lib/builder/mutationEntries.js +23 -0
- package/lib/builder/mutationEntries.js.map +1 -0
- package/lib/builder/mutator.d.ts +4 -2
- package/lib/builder/mutator.js +20 -209
- package/lib/builder/mutator.js.map +1 -1
- package/lib/builder/traffic.d.ts +2 -4
- package/lib/builder/traffic.js +48 -19
- package/lib/builder/traffic.js.map +1 -1
- package/lib/builder/variableOverrideProgram.d.ts +9 -0
- package/lib/builder/variableOverrideProgram.js +147 -0
- package/lib/builder/variableOverrideProgram.js.map +1 -0
- package/lib/catalog.d.ts +23 -0
- package/lib/catalog.js +117 -0
- package/lib/catalog.js.map +1 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +38 -13
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +72 -17
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +11 -3
- package/lib/cli/plugins.js.map +1 -1
- package/lib/cli/suggestions.d.ts +4 -0
- package/lib/cli/suggestions.js +61 -0
- package/lib/cli/suggestions.js.map +1 -0
- package/lib/config/allowedConditions.d.ts +9 -0
- package/lib/config/allowedConditions.js +44 -0
- package/lib/config/allowedConditions.js.map +1 -0
- package/lib/config/index.d.ts +1 -0
- package/lib/config/index.js +1 -0
- package/lib/config/index.js.map +1 -1
- package/lib/config/projectConfig.d.ts +9 -3
- package/lib/config/projectConfig.js +68 -11
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/config/removedGroups.d.ts +5 -0
- package/lib/config/removedGroups.js +62 -0
- package/lib/config/removedGroups.js.map +1 -0
- package/lib/datasource/adapter.d.ts +10 -1
- package/lib/datasource/adapter.js.map +1 -1
- package/lib/datasource/attributeNamespaces.d.ts +14 -0
- package/lib/datasource/attributeNamespaces.js +70 -0
- package/lib/datasource/attributeNamespaces.js.map +1 -0
- package/lib/datasource/composition.d.ts +5 -0
- package/lib/datasource/composition.js +19 -0
- package/lib/datasource/composition.js.map +1 -0
- package/lib/datasource/conditions.d.ts +20 -0
- package/lib/datasource/conditions.js +113 -0
- package/lib/datasource/conditions.js.map +1 -0
- package/lib/datasource/datasource.d.ts +18 -12
- package/lib/datasource/datasource.js +137 -76
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/dependencies.d.ts +52 -0
- package/lib/datasource/dependencies.js +347 -0
- package/lib/datasource/dependencies.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +31 -1
- package/lib/datasource/filesystemAdapter.js +581 -99
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/datasource/index.d.ts +3 -0
- package/lib/datasource/index.js +3 -0
- package/lib/datasource/index.js.map +1 -1
- package/lib/datasource/parseError.d.ts +5 -0
- package/lib/datasource/parseError.js +68 -0
- package/lib/datasource/parseError.js.map +1 -0
- package/lib/datasource/testSpecs.d.ts +4 -0
- package/lib/datasource/testSpecs.js +40 -0
- package/lib/datasource/testSpecs.js.map +1 -0
- package/lib/diff/details.js +31 -0
- package/lib/diff/details.js.map +1 -1
- package/lib/diff/index.d.ts +1 -1
- package/lib/diff/index.js +11 -4
- package/lib/diff/index.js.map +1 -1
- package/lib/error.d.ts +1 -0
- package/lib/error.js +6 -0
- package/lib/error.js.map +1 -1
- package/lib/evaluate/explain.d.ts +15 -2
- package/lib/evaluate/explain.js +273 -79
- package/lib/evaluate/explain.js.map +1 -1
- package/lib/evaluate/index.js +128 -17
- package/lib/evaluate/index.js.map +1 -1
- package/lib/evaluate/probeConditions.d.ts +30 -0
- package/lib/evaluate/probeConditions.js +165 -0
- package/lib/evaluate/probeConditions.js.map +1 -0
- package/lib/evaluate/validateExplanation.js +175 -16
- package/lib/evaluate/validateExplanation.js.map +1 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js +20 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
- package/lib/find-usage/index.d.ts +14 -1
- package/lib/find-usage/index.js +359 -155
- package/lib/find-usage/index.js.map +1 -1
- package/lib/generate-code/typescript.js +156 -60
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/info/index.js +11 -5
- package/lib/info/index.js.map +1 -1
- package/lib/init/index.js +234 -28
- package/lib/init/index.js.map +1 -1
- package/lib/linter/attributeSchema.d.ts +6 -11
- package/lib/linter/attributeSchema.js +59 -53
- package/lib/linter/attributeSchema.js.map +1 -1
- package/lib/linter/comparisonOperators.d.ts +18 -0
- package/lib/linter/comparisonOperators.js +82 -0
- package/lib/linter/comparisonOperators.js.map +1 -0
- package/lib/linter/composedOverrideSchema.d.ts +5 -0
- package/lib/linter/composedOverrideSchema.js +243 -0
- package/lib/linter/composedOverrideSchema.js.map +1 -0
- package/lib/linter/compositionWarnings.d.ts +8 -0
- package/lib/linter/compositionWarnings.js +212 -0
- package/lib/linter/compositionWarnings.js.map +1 -0
- package/lib/linter/conditionKinds.d.ts +12 -0
- package/lib/linter/conditionKinds.js +129 -0
- package/lib/linter/conditionKinds.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +8 -2
- package/lib/linter/conditionSchema.js +253 -52
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/contextWarnings.d.ts +13 -0
- package/lib/linter/contextWarnings.js +241 -0
- package/lib/linter/contextWarnings.js.map +1 -0
- package/lib/linter/definitionReferences.d.ts +39 -0
- package/lib/linter/definitionReferences.js +234 -0
- package/lib/linter/definitionReferences.js.map +1 -0
- package/lib/linter/dependencyDepth.d.ts +14 -0
- package/lib/linter/dependencyDepth.js +106 -0
- package/lib/linter/dependencyDepth.js.map +1 -0
- package/lib/linter/diagnostics.d.ts +129 -0
- package/lib/linter/diagnostics.js +84 -0
- package/lib/linter/diagnostics.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +189 -72
- package/lib/linter/featureSchema.js +385 -210
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +4 -1
- package/lib/linter/lintProject.js +449 -143
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/mutationNotation.d.ts +7 -1
- package/lib/linter/mutationNotation.js +40 -20
- package/lib/linter/mutationNotation.js.map +1 -1
- package/lib/linter/mutationOrder.d.ts +6 -0
- package/lib/linter/mutationOrder.js +105 -0
- package/lib/linter/mutationOrder.js.map +1 -0
- package/lib/linter/mutationResultPaths.d.ts +4 -0
- package/lib/linter/mutationResultPaths.js +131 -0
- package/lib/linter/mutationResultPaths.js.map +1 -0
- package/lib/linter/mutationSchema.d.ts +3 -0
- package/lib/linter/mutationSchema.js +32 -0
- package/lib/linter/mutationSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +3 -0
- package/lib/linter/printError.js +38 -25
- package/lib/linter/printError.js.map +1 -1
- package/lib/linter/regexSafety.d.ts +19 -0
- package/lib/linter/regexSafety.js +307 -0
- package/lib/linter/regexSafety.js.map +1 -0
- package/lib/linter/removedConditionFields.d.ts +10 -0
- package/lib/linter/removedConditionFields.js +47 -0
- package/lib/linter/removedConditionFields.js.map +1 -0
- package/lib/linter/requiredFeaturesSchema.d.ts +2 -2
- package/lib/linter/requiredFeaturesSchema.js +32 -28
- package/lib/linter/requiredFeaturesSchema.js.map +1 -1
- package/lib/linter/requiredVariableCost.d.ts +5 -0
- package/lib/linter/requiredVariableCost.js +60 -0
- package/lib/linter/requiredVariableCost.js.map +1 -0
- package/lib/linter/requiredVariablesSchema.d.ts +13 -0
- package/lib/linter/requiredVariablesSchema.js +498 -0
- package/lib/linter/requiredVariablesSchema.js.map +1 -0
- package/lib/linter/reservedNames.d.ts +12 -0
- package/lib/linter/reservedNames.js +52 -0
- package/lib/linter/reservedNames.js.map +1 -0
- package/lib/linter/schema.d.ts +12 -15
- package/lib/linter/schema.js +108 -26
- package/lib/linter/schema.js.map +1 -1
- package/lib/linter/schemaFormats.d.ts +35 -0
- package/lib/linter/schemaFormats.js +66 -0
- package/lib/linter/schemaFormats.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +11 -1
- package/lib/linter/segmentSchema.js +12 -2
- package/lib/linter/segmentSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +394 -2
- package/lib/linter/testSchema.js +565 -34
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/linter/variableSchema.d.ts +60 -43
- package/lib/linter/variableSchema.js +459 -60
- package/lib/linter/variableSchema.js.map +1 -1
- package/lib/linter/zodHelpers.d.ts +8 -1
- package/lib/linter/zodHelpers.js +9 -1
- package/lib/linter/zodHelpers.js.map +1 -1
- package/lib/list/index.js +384 -66
- package/lib/list/index.js.map +1 -1
- package/lib/list/matrix.d.ts +2 -2
- package/lib/list/matrix.js +60 -39
- package/lib/list/matrix.js.map +1 -1
- package/lib/list/scenarios.d.ts +8 -0
- package/lib/list/scenarios.js +84 -0
- package/lib/list/scenarios.js.map +1 -0
- package/lib/promoter/index.d.ts +1 -1
- package/lib/promoter/index.js +469 -210
- package/lib/promoter/index.js.map +1 -1
- package/lib/sets.js +14 -5
- package/lib/sets.js.map +1 -1
- package/lib/tester/checks.d.ts +12 -0
- package/lib/tester/checks.js +418 -0
- package/lib/tester/checks.js.map +1 -0
- package/lib/tester/coverage.d.ts +16 -0
- package/lib/tester/coverage.js +64 -0
- package/lib/tester/coverage.js.map +1 -0
- package/lib/tester/datafileKey.d.ts +4 -0
- package/lib/tester/datafileKey.js +18 -0
- package/lib/tester/datafileKey.js.map +1 -0
- package/lib/tester/diagnostics.d.ts +5 -0
- package/lib/tester/diagnostics.js +32 -0
- package/lib/tester/diagnostics.js.map +1 -0
- package/lib/tester/index.d.ts +2 -0
- package/lib/tester/printTestResult.d.ts +3 -2
- package/lib/tester/printTestResult.js +53 -8
- package/lib/tester/printTestResult.js.map +1 -1
- package/lib/tester/provenance.d.ts +21 -0
- package/lib/tester/provenance.js +98 -0
- package/lib/tester/provenance.js.map +1 -0
- package/lib/tester/report.d.ts +78 -0
- package/lib/tester/report.js +246 -0
- package/lib/tester/report.js.map +1 -0
- package/lib/tester/segments.d.ts +23 -0
- package/lib/tester/segments.js +103 -0
- package/lib/tester/segments.js.map +1 -0
- package/lib/tester/testFeature.d.ts +2 -0
- package/lib/tester/testFeature.js +17 -8
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +15 -3
- package/lib/tester/testProject.js +198 -83
- package/lib/tester/testProject.js.map +1 -1
- package/lib/tester/testSegment.d.ts +2 -4
- package/lib/tester/testSegment.js +89 -7
- package/lib/tester/testSegment.js.map +1 -1
- package/lib/tester/testVariable.d.ts +2 -2
- package/lib/tester/testVariable.js +195 -24
- package/lib/tester/testVariable.js.map +1 -1
- package/lib/utils/conditionReferences.d.ts +5 -0
- package/lib/utils/conditionReferences.js +30 -0
- package/lib/utils/conditionReferences.js.map +1 -0
- package/lib/utils/extractKeys.d.ts +7 -3
- package/lib/utils/extractKeys.js +32 -113
- package/lib/utils/extractKeys.js.map +1 -1
- package/lib/utils/git.d.ts +7 -2
- package/lib/utils/git.js +87 -72
- package/lib/utils/git.js.map +1 -1
- package/package.json +11 -8
- package/lib/builder/getFeatureRanges.d.ts +0 -11
- package/lib/builder/getFeatureRanges.js +0 -70
- package/lib/builder/getFeatureRanges.js.map +0 -1
- package/lib/datasource/requiredFeatures.d.ts +0 -14
- package/lib/datasource/requiredFeatures.js +0 -75
- package/lib/datasource/requiredFeatures.js.map +0 -1
- package/lib/linter/checkCircularDependency.d.ts +0 -3
- package/lib/linter/checkCircularDependency.js +0 -8
- package/lib/linter/checkCircularDependency.js.map +0 -1
- package/lib/linter/checkPercentageExceedingSlot.d.ts +0 -3
- package/lib/linter/checkPercentageExceedingSlot.js +0 -45
- package/lib/linter/checkPercentageExceedingSlot.js.map +0 -1
- package/lib/linter/groupSchema.d.ts +0 -11
- package/lib/linter/groupSchema.js +0 -31
- package/lib/linter/groupSchema.js.map +0 -1
|
@@ -1,15 +1,25 @@
|
|
|
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
|
|
21
|
+
const diagnostics_1 = require("./diagnostics");
|
|
22
|
+
const removedConditionFields_1 = require("./removedConditionFields");
|
|
13
23
|
function isArrayOfStrings(value) {
|
|
14
24
|
return Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
15
25
|
}
|
|
@@ -30,7 +40,10 @@ function getVariableLabel(variableSchema, variableKey, path) {
|
|
|
30
40
|
*/
|
|
31
41
|
function resolveVariableSchema(variableSchema, schemasByKey) {
|
|
32
42
|
if (variableSchema.schema) {
|
|
33
|
-
|
|
43
|
+
const referenced = schemasByKey?.[variableSchema.schema];
|
|
44
|
+
return referenced
|
|
45
|
+
? resolveSchemaRefs(referenced, schemasByKey)
|
|
46
|
+
: null;
|
|
34
47
|
}
|
|
35
48
|
return variableSchema;
|
|
36
49
|
}
|
|
@@ -41,6 +54,24 @@ function resolveSchemaRefs(schema, schemasByKey) {
|
|
|
41
54
|
}
|
|
42
55
|
return schema;
|
|
43
56
|
}
|
|
57
|
+
function schemaUsesTimestampFormat(schema, schemasByKey, seen = new Set()) {
|
|
58
|
+
if (seen.has(schema))
|
|
59
|
+
return false;
|
|
60
|
+
seen.add(schema);
|
|
61
|
+
const resolved = resolveSchemaRefs(schema, schemasByKey);
|
|
62
|
+
// Literal values are checked against every format, not only timestamps.
|
|
63
|
+
if (resolved.format !== undefined)
|
|
64
|
+
return true;
|
|
65
|
+
const children = [
|
|
66
|
+
resolved.items,
|
|
67
|
+
resolved.additionalProperties,
|
|
68
|
+
...Object.values(resolved.properties || {}),
|
|
69
|
+
...(resolved.oneOf || []),
|
|
70
|
+
];
|
|
71
|
+
return children.some((child) => child && typeof child === "object"
|
|
72
|
+
? schemaUsesTimestampFormat(child, schemasByKey, seen)
|
|
73
|
+
: false);
|
|
74
|
+
}
|
|
44
75
|
/**
|
|
45
76
|
* Returns true if the value matches the given schema (const, enum, type, object properties, array items, or exactly one of oneOf).
|
|
46
77
|
* Used for oneOf validation: value must match exactly one branch.
|
|
@@ -52,10 +83,16 @@ function valueMatchesSchema(schema, value, schemasByKey) {
|
|
|
52
83
|
return matchCount === 1;
|
|
53
84
|
}
|
|
54
85
|
if (resolved.const !== undefined) {
|
|
55
|
-
|
|
86
|
+
if (!valueDeepEqual(value, resolved.const))
|
|
87
|
+
return false;
|
|
88
|
+
if (!schemaUsesTimestampFormat(resolved, schemasByKey))
|
|
89
|
+
return true;
|
|
56
90
|
}
|
|
57
91
|
if (resolved.enum !== undefined && Array.isArray(resolved.enum)) {
|
|
58
|
-
|
|
92
|
+
if (!resolved.enum.some((e) => valueDeepEqual(value, e)))
|
|
93
|
+
return false;
|
|
94
|
+
if (!schemaUsesTimestampFormat(resolved, schemasByKey))
|
|
95
|
+
return true;
|
|
59
96
|
}
|
|
60
97
|
const type = resolved.type;
|
|
61
98
|
if (!type)
|
|
@@ -63,6 +100,8 @@ function valueMatchesSchema(schema, value, schemasByKey) {
|
|
|
63
100
|
if (type === "string") {
|
|
64
101
|
if (typeof value !== "string")
|
|
65
102
|
return false;
|
|
103
|
+
if (!(0, schemaFormats_1.valueMatchesFormat)(resolved.format, value))
|
|
104
|
+
return false;
|
|
66
105
|
const s = value;
|
|
67
106
|
if (resolved.minLength !== undefined && s.length < resolved.minLength)
|
|
68
107
|
return false;
|
|
@@ -90,7 +129,7 @@ function valueMatchesSchema(schema, value, schemasByKey) {
|
|
|
90
129
|
return false;
|
|
91
130
|
return true;
|
|
92
131
|
}
|
|
93
|
-
if (type === "
|
|
132
|
+
if (type === "number") {
|
|
94
133
|
if (typeof value !== "number")
|
|
95
134
|
return false;
|
|
96
135
|
if (resolved.minimum !== undefined && value < resolved.minimum)
|
|
@@ -255,27 +294,64 @@ function typeOfValue(value) {
|
|
|
255
294
|
return "array";
|
|
256
295
|
return typeof value;
|
|
257
296
|
}
|
|
297
|
+
const itemOperationLabels = {
|
|
298
|
+
append: "Item appended to",
|
|
299
|
+
appendUnique: "Item appended to",
|
|
300
|
+
prepend: "Item prepended to",
|
|
301
|
+
removeValue: "Item removed from",
|
|
302
|
+
before: "Item inserted before",
|
|
303
|
+
after: "Item inserted after",
|
|
304
|
+
};
|
|
305
|
+
function appendPath(path, child) {
|
|
306
|
+
return typeof child === "number" ? `${path}[${child}]` : `${path ? `${path}.` : ""}${child}`;
|
|
307
|
+
}
|
|
308
|
+
function childMutationValueContext(context, child) {
|
|
309
|
+
if (!context)
|
|
310
|
+
return undefined;
|
|
311
|
+
if (context.operation && itemOperationLabels[context.operation])
|
|
312
|
+
return { ...context, itemPath: appendPath(context.itemPath || "", child) };
|
|
313
|
+
return { ...context, path: appendPath(context.path, child) };
|
|
314
|
+
}
|
|
315
|
+
function mutationSubject(mutation) {
|
|
316
|
+
const variable = `variable "${mutation.variableKey}"`;
|
|
317
|
+
const label = mutation.operation && itemOperationLabels[mutation.operation];
|
|
318
|
+
if (!label)
|
|
319
|
+
return mutation.path ? `Value at "${mutation.path}" in ${variable}` : `Value of ${variable}`;
|
|
320
|
+
const item = `${label} ${mutation.path ? `"${mutation.path}" in ${variable}` : variable}`;
|
|
321
|
+
return mutation.itemPath
|
|
322
|
+
? `Value at "${mutation.itemPath}" in the ${item.charAt(0).toLowerCase()}${item.slice(1)}`
|
|
323
|
+
: item;
|
|
324
|
+
}
|
|
325
|
+
function valueSubject(variableSchema, variableKey, path, mutation) {
|
|
326
|
+
return mutation
|
|
327
|
+
? mutationSubject(mutation)
|
|
328
|
+
: `Variable "${getVariableLabel(variableSchema, variableKey, path)}"`;
|
|
329
|
+
}
|
|
330
|
+
/** The authored mutation subject already names its schema, so the type aside is omitted. */
|
|
331
|
+
function typedSubject(subject, type, mutation) {
|
|
332
|
+
return mutation ? subject : `${subject} (type ${type})`;
|
|
333
|
+
}
|
|
258
334
|
/**
|
|
259
335
|
* Validates a variable value against an array schema. Recursively validates each item
|
|
260
336
|
* when the schema defines `items` (nested arrays/objects use the same refinement).
|
|
261
337
|
* Enforces minItems, maxItems, and uniqueItems when set.
|
|
262
338
|
*/
|
|
263
|
-
function refineVariableValueArray(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
|
|
264
|
-
const
|
|
339
|
+
function refineVariableValueArray(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
|
|
340
|
+
const subject = valueSubject(variableSchema, variableKey, path, mutation);
|
|
265
341
|
const minItems = variableSchema.minItems;
|
|
266
342
|
const maxItems = variableSchema.maxItems;
|
|
267
343
|
const uniqueItems = variableSchema.uniqueItems;
|
|
268
344
|
if (minItems !== undefined && variableValue.length < minItems) {
|
|
269
345
|
ctx.addIssue({
|
|
270
346
|
code: zod_1.z.ZodIssueCode.custom,
|
|
271
|
-
message:
|
|
347
|
+
message: `${typedSubject(subject, "array", mutation)} must have at least ${minItems} items (\`minItems\`), but has ${variableValue.length}.`,
|
|
272
348
|
path,
|
|
273
349
|
});
|
|
274
350
|
}
|
|
275
351
|
if (maxItems !== undefined && variableValue.length > maxItems) {
|
|
276
352
|
ctx.addIssue({
|
|
277
353
|
code: zod_1.z.ZodIssueCode.custom,
|
|
278
|
-
message:
|
|
354
|
+
message: `${typedSubject(subject, "array", mutation)} must have at most ${maxItems} items (\`maxItems\`), but has ${variableValue.length}.`,
|
|
279
355
|
path,
|
|
280
356
|
});
|
|
281
357
|
}
|
|
@@ -285,7 +361,7 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
|
|
|
285
361
|
if (valueDeepEqual(variableValue[i], variableValue[j])) {
|
|
286
362
|
ctx.addIssue({
|
|
287
363
|
code: zod_1.z.ZodIssueCode.custom,
|
|
288
|
-
message:
|
|
364
|
+
message: `${typedSubject(subject, "array", mutation)} has duplicate items at indices ${i} and ${j} but \`uniqueItems\` is true.`,
|
|
289
365
|
path,
|
|
290
366
|
});
|
|
291
367
|
break;
|
|
@@ -296,14 +372,14 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
|
|
|
296
372
|
const itemSchema = variableSchema.items;
|
|
297
373
|
if (itemSchema) {
|
|
298
374
|
variableValue.forEach((item, index) => {
|
|
299
|
-
superRefineVariableValue(projectConfig, itemSchema, item, [...path, index], ctx, variableKey, schemasByKey);
|
|
375
|
+
superRefineVariableValue(projectConfig, itemSchema, item, [...path, index], ctx, variableKey, schemasByKey, childMutationValueContext(mutation, index));
|
|
300
376
|
});
|
|
301
377
|
}
|
|
302
378
|
else {
|
|
303
379
|
if (!isArrayOfStrings(variableValue)) {
|
|
304
380
|
ctx.addIssue({
|
|
305
381
|
code: zod_1.z.ZodIssueCode.custom,
|
|
306
|
-
message:
|
|
382
|
+
message: `${typedSubject(subject, "array", mutation)}: when \`items\` is not set, array must contain only strings; found non-string element.`,
|
|
307
383
|
path,
|
|
308
384
|
});
|
|
309
385
|
}
|
|
@@ -313,7 +389,7 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
|
|
|
313
389
|
if (stringified.length > projectConfig.maxVariableArrayStringifiedLength) {
|
|
314
390
|
ctx.addIssue({
|
|
315
391
|
code: zod_1.z.ZodIssueCode.custom,
|
|
316
|
-
message:
|
|
392
|
+
message: `${subject} array is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableArrayStringifiedLength}`,
|
|
317
393
|
path,
|
|
318
394
|
});
|
|
319
395
|
}
|
|
@@ -323,19 +399,21 @@ function refineVariableValueArray(projectConfig, variableSchema, variableValue,
|
|
|
323
399
|
* Validates a variable value against an object schema. Recursively validates each property
|
|
324
400
|
* when the schema defines `properties` (nested objects/arrays use the same refinement).
|
|
325
401
|
*/
|
|
326
|
-
function refineVariableValueObject(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
|
|
327
|
-
const
|
|
402
|
+
function refineVariableValueObject(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
|
|
403
|
+
const subject = valueSubject(variableSchema, variableKey, path, mutation);
|
|
328
404
|
const schemaProperties = variableSchema.properties;
|
|
329
405
|
const additionalProperties = variableSchema.additionalProperties;
|
|
330
406
|
if (schemaProperties && typeof schemaProperties === "object") {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
407
|
+
// As in JSON Schema, only keys listed in `required` must be present.
|
|
408
|
+
// Without the list every property is optional, matching generated types.
|
|
409
|
+
const requiredKeys = (variableSchema.required || []).filter((k) => Object.prototype.hasOwnProperty.call(schemaProperties, k));
|
|
334
410
|
for (const key of requiredKeys) {
|
|
335
411
|
if (!Object.prototype.hasOwnProperty.call(variableValue, key)) {
|
|
336
412
|
ctx.addIssue({
|
|
337
413
|
code: zod_1.z.ZodIssueCode.custom,
|
|
338
|
-
message:
|
|
414
|
+
message: mutation
|
|
415
|
+
? `${subject} is missing required property "${key}".`
|
|
416
|
+
: `Missing required property "${key}" in variable "${getVariableLabel(variableSchema, variableKey, path)}"`,
|
|
339
417
|
path: [...path, key],
|
|
340
418
|
});
|
|
341
419
|
}
|
|
@@ -343,23 +421,25 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
|
|
|
343
421
|
for (const key of Object.keys(variableValue)) {
|
|
344
422
|
const propSchema = schemaProperties[key];
|
|
345
423
|
if (!propSchema && additionalProperties && typeof additionalProperties === "object") {
|
|
346
|
-
superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey);
|
|
424
|
+
superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
|
|
347
425
|
}
|
|
348
426
|
else if (!propSchema) {
|
|
349
427
|
ctx.addIssue({
|
|
350
428
|
code: zod_1.z.ZodIssueCode.custom,
|
|
351
|
-
message:
|
|
429
|
+
message: mutation
|
|
430
|
+
? `${subject} has unknown property "${key}" (not in schema).`
|
|
431
|
+
: `Unknown property "${key}" in variable "${getVariableLabel(variableSchema, variableKey, path)}" (not in schema)`,
|
|
352
432
|
path: [...path, key],
|
|
353
433
|
});
|
|
354
434
|
}
|
|
355
435
|
else {
|
|
356
|
-
superRefineVariableValue(projectConfig, propSchema, variableValue[key], [...path, key], ctx, key, schemasByKey);
|
|
436
|
+
superRefineVariableValue(projectConfig, propSchema, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
|
|
357
437
|
}
|
|
358
438
|
}
|
|
359
439
|
}
|
|
360
440
|
else if (additionalProperties && typeof additionalProperties === "object") {
|
|
361
441
|
for (const key of Object.keys(variableValue)) {
|
|
362
|
-
superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey);
|
|
442
|
+
superRefineVariableValue(projectConfig, additionalProperties, variableValue[key], [...path, key], ctx, key, schemasByKey, childMutationValueContext(mutation, key));
|
|
363
443
|
}
|
|
364
444
|
}
|
|
365
445
|
else {
|
|
@@ -368,7 +448,7 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
|
|
|
368
448
|
if (!isFlatObjectValue(propValue)) {
|
|
369
449
|
ctx.addIssue({
|
|
370
450
|
code: zod_1.z.ZodIssueCode.custom,
|
|
371
|
-
message:
|
|
451
|
+
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
452
|
path: [...path, key],
|
|
373
453
|
});
|
|
374
454
|
}
|
|
@@ -379,19 +459,21 @@ function refineVariableValueObject(projectConfig, variableSchema, variableValue,
|
|
|
379
459
|
if (stringified.length > projectConfig.maxVariableObjectStringifiedLength) {
|
|
380
460
|
ctx.addIssue({
|
|
381
461
|
code: zod_1.z.ZodIssueCode.custom,
|
|
382
|
-
message:
|
|
462
|
+
message: `${subject} object is too long (${stringified.length} characters), max length is ${projectConfig.maxVariableObjectStringifiedLength}`,
|
|
383
463
|
path,
|
|
384
464
|
});
|
|
385
465
|
}
|
|
386
466
|
}
|
|
387
467
|
}
|
|
388
|
-
function superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey) {
|
|
389
|
-
const
|
|
468
|
+
function superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation) {
|
|
469
|
+
const subject = valueSubject(variableSchema, variableKey, path, mutation);
|
|
390
470
|
if (!variableSchema) {
|
|
391
471
|
const variableName = path.length > 0 && typeof path[path.length - 1] === "string"
|
|
392
472
|
? String(path[path.length - 1])
|
|
393
473
|
: "variable";
|
|
394
|
-
const message =
|
|
474
|
+
const message = mutation
|
|
475
|
+
? `${subject} cannot be validated because its schema is not defined.`
|
|
476
|
+
: `Variable "${variableName}" is used but not defined in variablesSchema. Define it under variablesSchema first, then use it here.`;
|
|
395
477
|
ctx.addIssue({
|
|
396
478
|
code: zod_1.z.ZodIssueCode.custom,
|
|
397
479
|
message,
|
|
@@ -403,7 +485,9 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
403
485
|
if (variableSchema.schema && effectiveSchema === null) {
|
|
404
486
|
ctx.addIssue({
|
|
405
487
|
code: zod_1.z.ZodIssueCode.custom,
|
|
406
|
-
message:
|
|
488
|
+
message: mutation
|
|
489
|
+
? `${subject} cannot be validated because schema "${variableSchema.schema}" could not be loaded.`
|
|
490
|
+
: `Schema "${variableSchema.schema}" could not be loaded for value validation.`,
|
|
407
491
|
path,
|
|
408
492
|
});
|
|
409
493
|
return;
|
|
@@ -417,14 +501,14 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
417
501
|
if (matchCount === 0) {
|
|
418
502
|
ctx.addIssue({
|
|
419
503
|
code: zod_1.z.ZodIssueCode.custom,
|
|
420
|
-
message:
|
|
504
|
+
message: `${subject} must match exactly one of the \`oneOf\` schemas (got ${JSON.stringify(variableValue)}; matched none).`,
|
|
421
505
|
path,
|
|
422
506
|
});
|
|
423
507
|
}
|
|
424
508
|
else if (matchCount > 1) {
|
|
425
509
|
ctx.addIssue({
|
|
426
510
|
code: zod_1.z.ZodIssueCode.custom,
|
|
427
|
-
message:
|
|
511
|
+
message: `${subject} must match exactly one of the \`oneOf\` schemas (matched ${matchCount}).`,
|
|
428
512
|
path,
|
|
429
513
|
});
|
|
430
514
|
}
|
|
@@ -435,11 +519,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
435
519
|
if (!valueDeepEqual(variableValue, effectiveConst)) {
|
|
436
520
|
ctx.addIssue({
|
|
437
521
|
code: zod_1.z.ZodIssueCode.custom,
|
|
438
|
-
message:
|
|
522
|
+
message: `${subject} must equal the constant value defined in schema (got ${JSON.stringify(variableValue)}).`,
|
|
439
523
|
path,
|
|
440
524
|
});
|
|
441
525
|
}
|
|
442
|
-
|
|
526
|
+
if (!schemaUsesTimestampFormat(effectiveSchema, schemasByKey))
|
|
527
|
+
return;
|
|
443
528
|
}
|
|
444
529
|
const effectiveEnum = effectiveSchema.enum;
|
|
445
530
|
if (effectiveEnum !== undefined && Array.isArray(effectiveEnum) && effectiveEnum.length > 0) {
|
|
@@ -447,47 +532,60 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
447
532
|
if (!allowed) {
|
|
448
533
|
ctx.addIssue({
|
|
449
534
|
code: zod_1.z.ZodIssueCode.custom,
|
|
450
|
-
message:
|
|
535
|
+
message: `${subject} must be one of the allowed enum values (got ${JSON.stringify(variableValue)}).`,
|
|
451
536
|
path,
|
|
452
537
|
});
|
|
453
538
|
}
|
|
454
|
-
|
|
539
|
+
if (!schemaUsesTimestampFormat(effectiveSchema, schemasByKey))
|
|
540
|
+
return;
|
|
455
541
|
}
|
|
456
542
|
// Require a value (no undefined) for every variable usage
|
|
457
543
|
if (variableValue === undefined) {
|
|
458
544
|
ctx.addIssue({
|
|
459
545
|
code: zod_1.z.ZodIssueCode.custom,
|
|
460
|
-
message:
|
|
546
|
+
message: `${subject} is required.`,
|
|
461
547
|
path,
|
|
462
548
|
});
|
|
463
549
|
return;
|
|
464
550
|
}
|
|
465
551
|
const expectedType = effectiveSchema.type;
|
|
466
552
|
const gotType = typeOfValue(variableValue);
|
|
553
|
+
const receivedType = gotType === "null" || gotType === "undefined"
|
|
554
|
+
? gotType
|
|
555
|
+
: `${/^[aeiou]/.test(gotType) ? "an" : "a"} ${gotType}`;
|
|
467
556
|
// string — only string allowed; schema minLength/maxLength/pattern applied when set
|
|
468
557
|
if (expectedType === "string") {
|
|
469
558
|
if (typeof variableValue !== "string") {
|
|
470
559
|
ctx.addIssue({
|
|
471
560
|
code: zod_1.z.ZodIssueCode.custom,
|
|
472
|
-
message:
|
|
561
|
+
message: `${typedSubject(subject, "string", mutation)} must be a string, but got ${receivedType}.`,
|
|
473
562
|
path,
|
|
474
563
|
});
|
|
475
564
|
return;
|
|
476
565
|
}
|
|
477
566
|
const strMinLen = effectiveSchema.minLength;
|
|
567
|
+
if (!(0, schemaFormats_1.valueMatchesFormat)(effectiveSchema.format, variableValue)) {
|
|
568
|
+
ctx.addIssue({
|
|
569
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
570
|
+
message: effectiveSchema.format === "date-time"
|
|
571
|
+
? `${subject} is not a valid portable timestamp for format: date-time. Use YYYY-MM-DDTHH:mm:ss with Z or ±HH:mm.`
|
|
572
|
+
: `${subject} is not valid for format: ${effectiveSchema.format}. ${(0, schemaFormats_1.formatValueMessage)(effectiveSchema.format)}`,
|
|
573
|
+
path,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
478
576
|
const strMaxLen = effectiveSchema.maxLength;
|
|
479
577
|
const strPattern = effectiveSchema.pattern;
|
|
480
578
|
if (strMinLen !== undefined && variableValue.length < strMinLen) {
|
|
481
579
|
ctx.addIssue({
|
|
482
580
|
code: zod_1.z.ZodIssueCode.custom,
|
|
483
|
-
message:
|
|
581
|
+
message: `${typedSubject(subject, "string", mutation)} must be at least ${strMinLen} characters long (\`minLength\`), but has ${variableValue.length}.`,
|
|
484
582
|
path,
|
|
485
583
|
});
|
|
486
584
|
}
|
|
487
585
|
if (strMaxLen !== undefined && variableValue.length > strMaxLen) {
|
|
488
586
|
ctx.addIssue({
|
|
489
587
|
code: zod_1.z.ZodIssueCode.custom,
|
|
490
|
-
message:
|
|
588
|
+
message: `${typedSubject(subject, "string", mutation)} must be at most ${strMaxLen} characters long (\`maxLength\`), but has ${variableValue.length}.`,
|
|
491
589
|
path,
|
|
492
590
|
});
|
|
493
591
|
}
|
|
@@ -496,7 +594,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
496
594
|
if (!new RegExp(strPattern).test(variableValue)) {
|
|
497
595
|
ctx.addIssue({
|
|
498
596
|
code: zod_1.z.ZodIssueCode.custom,
|
|
499
|
-
message:
|
|
597
|
+
message: `${typedSubject(subject, "string", mutation)} does not match \`pattern\`.`,
|
|
500
598
|
path,
|
|
501
599
|
});
|
|
502
600
|
}
|
|
@@ -509,7 +607,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
509
607
|
variableValue.length > projectConfig.maxVariableStringLength) {
|
|
510
608
|
ctx.addIssue({
|
|
511
609
|
code: zod_1.z.ZodIssueCode.custom,
|
|
512
|
-
message:
|
|
610
|
+
message: `${subject} is ${variableValue.length} characters long, but the project allows at most ${projectConfig.maxVariableStringLength} (maxVariableStringLength).`,
|
|
513
611
|
path,
|
|
514
612
|
});
|
|
515
613
|
}
|
|
@@ -520,7 +618,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
520
618
|
if (typeof variableValue !== "number") {
|
|
521
619
|
ctx.addIssue({
|
|
522
620
|
code: zod_1.z.ZodIssueCode.custom,
|
|
523
|
-
message:
|
|
621
|
+
message: `${typedSubject(subject, "integer", mutation)} must be a number, but got ${receivedType}.`,
|
|
524
622
|
path,
|
|
525
623
|
});
|
|
526
624
|
return;
|
|
@@ -528,7 +626,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
528
626
|
if (!Number.isFinite(variableValue)) {
|
|
529
627
|
ctx.addIssue({
|
|
530
628
|
code: zod_1.z.ZodIssueCode.custom,
|
|
531
|
-
message:
|
|
629
|
+
message: `${typedSubject(subject, "integer", mutation)} must be a finite number, but got ${variableValue}.`,
|
|
532
630
|
path,
|
|
533
631
|
});
|
|
534
632
|
return;
|
|
@@ -536,7 +634,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
536
634
|
if (!Number.isInteger(variableValue)) {
|
|
537
635
|
ctx.addIssue({
|
|
538
636
|
code: zod_1.z.ZodIssueCode.custom,
|
|
539
|
-
message:
|
|
637
|
+
message: `${typedSubject(subject, "integer", mutation)} must be an integer, but got ${variableValue}.`,
|
|
540
638
|
path,
|
|
541
639
|
});
|
|
542
640
|
return;
|
|
@@ -546,25 +644,25 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
546
644
|
if (intMin !== undefined && variableValue < intMin) {
|
|
547
645
|
ctx.addIssue({
|
|
548
646
|
code: zod_1.z.ZodIssueCode.custom,
|
|
549
|
-
message:
|
|
647
|
+
message: `${typedSubject(subject, "integer", mutation)} must be >= minimum (${intMin}), but got ${variableValue}.`,
|
|
550
648
|
path,
|
|
551
649
|
});
|
|
552
650
|
}
|
|
553
651
|
if (intMax !== undefined && variableValue > intMax) {
|
|
554
652
|
ctx.addIssue({
|
|
555
653
|
code: zod_1.z.ZodIssueCode.custom,
|
|
556
|
-
message:
|
|
654
|
+
message: `${typedSubject(subject, "integer", mutation)} must be <= maximum (${intMax}), but got ${variableValue}.`,
|
|
557
655
|
path,
|
|
558
656
|
});
|
|
559
657
|
}
|
|
560
658
|
return;
|
|
561
659
|
}
|
|
562
|
-
//
|
|
563
|
-
if (expectedType === "
|
|
660
|
+
// number — only finite number allowed
|
|
661
|
+
if (expectedType === "number") {
|
|
564
662
|
if (typeof variableValue !== "number") {
|
|
565
663
|
ctx.addIssue({
|
|
566
664
|
code: zod_1.z.ZodIssueCode.custom,
|
|
567
|
-
message:
|
|
665
|
+
message: `${typedSubject(subject, "number", mutation)} must be a number, but got ${receivedType}.`,
|
|
568
666
|
path,
|
|
569
667
|
});
|
|
570
668
|
return;
|
|
@@ -572,24 +670,24 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
572
670
|
if (!Number.isFinite(variableValue)) {
|
|
573
671
|
ctx.addIssue({
|
|
574
672
|
code: zod_1.z.ZodIssueCode.custom,
|
|
575
|
-
message:
|
|
673
|
+
message: `${typedSubject(subject, "number", mutation)} must be a finite number, but got ${variableValue}.`,
|
|
576
674
|
path,
|
|
577
675
|
});
|
|
578
676
|
return;
|
|
579
677
|
}
|
|
580
|
-
const
|
|
581
|
-
const
|
|
582
|
-
if (
|
|
678
|
+
const numberMin = effectiveSchema.minimum;
|
|
679
|
+
const numberMax = effectiveSchema.maximum;
|
|
680
|
+
if (numberMin !== undefined && variableValue < numberMin) {
|
|
583
681
|
ctx.addIssue({
|
|
584
682
|
code: zod_1.z.ZodIssueCode.custom,
|
|
585
|
-
message:
|
|
683
|
+
message: `${typedSubject(subject, "number", mutation)} must be >= minimum (${numberMin}), but got ${variableValue}.`,
|
|
586
684
|
path,
|
|
587
685
|
});
|
|
588
686
|
}
|
|
589
|
-
if (
|
|
687
|
+
if (numberMax !== undefined && variableValue > numberMax) {
|
|
590
688
|
ctx.addIssue({
|
|
591
689
|
code: zod_1.z.ZodIssueCode.custom,
|
|
592
|
-
message:
|
|
690
|
+
message: `${typedSubject(subject, "number", mutation)} must be <= maximum (${numberMax}), but got ${variableValue}.`,
|
|
593
691
|
path,
|
|
594
692
|
});
|
|
595
693
|
}
|
|
@@ -600,7 +698,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
600
698
|
if (typeof variableValue !== "boolean") {
|
|
601
699
|
ctx.addIssue({
|
|
602
700
|
code: zod_1.z.ZodIssueCode.custom,
|
|
603
|
-
message:
|
|
701
|
+
message: `${typedSubject(subject, "boolean", mutation)} must be a boolean, but got ${receivedType}.`,
|
|
604
702
|
path,
|
|
605
703
|
});
|
|
606
704
|
}
|
|
@@ -611,12 +709,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
611
709
|
if (!Array.isArray(variableValue)) {
|
|
612
710
|
ctx.addIssue({
|
|
613
711
|
code: zod_1.z.ZodIssueCode.custom,
|
|
614
|
-
message:
|
|
712
|
+
message: `${typedSubject(subject, "array", mutation)} must be an array, but got ${receivedType}.`,
|
|
615
713
|
path,
|
|
616
714
|
});
|
|
617
715
|
return;
|
|
618
716
|
}
|
|
619
|
-
refineVariableValueArray(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey);
|
|
717
|
+
refineVariableValueArray(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation);
|
|
620
718
|
return;
|
|
621
719
|
}
|
|
622
720
|
// object — only plain object allowed (no null, no array)
|
|
@@ -626,12 +724,12 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
626
724
|
Array.isArray(variableValue)) {
|
|
627
725
|
ctx.addIssue({
|
|
628
726
|
code: zod_1.z.ZodIssueCode.custom,
|
|
629
|
-
message:
|
|
727
|
+
message: `${typedSubject(subject, "object", mutation)} must be a plain object, but got ${receivedType}.`,
|
|
630
728
|
path,
|
|
631
729
|
});
|
|
632
730
|
return;
|
|
633
731
|
}
|
|
634
|
-
refineVariableValueObject(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey);
|
|
732
|
+
refineVariableValueObject(projectConfig, effectiveSchema, variableValue, path, ctx, variableKey, schemasByKey, mutation);
|
|
635
733
|
return;
|
|
636
734
|
}
|
|
637
735
|
// json — only string containing valid JSON allowed
|
|
@@ -639,7 +737,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
639
737
|
if (typeof variableValue !== "string") {
|
|
640
738
|
ctx.addIssue({
|
|
641
739
|
code: zod_1.z.ZodIssueCode.custom,
|
|
642
|
-
message:
|
|
740
|
+
message: `${typedSubject(subject, "json", mutation)} must be a string (JSON string), but got ${receivedType}.`,
|
|
643
741
|
path,
|
|
644
742
|
});
|
|
645
743
|
return;
|
|
@@ -650,7 +748,7 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
650
748
|
if (variableValue.length > projectConfig.maxVariableJSONStringifiedLength) {
|
|
651
749
|
ctx.addIssue({
|
|
652
750
|
code: zod_1.z.ZodIssueCode.custom,
|
|
653
|
-
message:
|
|
751
|
+
message: `${subject} JSON is too long (${variableValue.length} characters), max length is ${projectConfig.maxVariableJSONStringifiedLength}`,
|
|
654
752
|
path,
|
|
655
753
|
});
|
|
656
754
|
}
|
|
@@ -660,16 +758,19 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
660
758
|
catch (e) {
|
|
661
759
|
ctx.addIssue({
|
|
662
760
|
code: zod_1.z.ZodIssueCode.custom,
|
|
663
|
-
message:
|
|
761
|
+
message: `${typedSubject(subject, "json", mutation)} must be a valid JSON string; parse failed.`,
|
|
664
762
|
path,
|
|
665
763
|
});
|
|
666
764
|
}
|
|
667
765
|
return;
|
|
668
766
|
}
|
|
767
|
+
// A removed type already reports its migration at `type`.
|
|
768
|
+
if ((0, schemaFormats_1.isRemovedSchemaType)(expectedType))
|
|
769
|
+
return;
|
|
669
770
|
// Unknown variable type — schema is invalid or unsupported
|
|
670
771
|
ctx.addIssue({
|
|
671
772
|
code: zod_1.z.ZodIssueCode.custom,
|
|
672
|
-
message:
|
|
773
|
+
message: `${subject} has unknown or unsupported type "${String(expectedType)}" in variablesSchema.`,
|
|
673
774
|
path,
|
|
674
775
|
});
|
|
675
776
|
}
|
|
@@ -678,7 +779,15 @@ function superRefineVariableValue(projectConfig, variableSchema, variableValue,
|
|
|
678
779
|
* Key may be a root variable name or mutation notation (e.g. "config.width", "items[0].name").
|
|
679
780
|
*/
|
|
680
781
|
function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, variableValue, path, ctx, schemasByKey) {
|
|
681
|
-
|
|
782
|
+
const variableSchema = variableSchemaByKey[variableKey];
|
|
783
|
+
if (!variableSchema && (0, mutationNotation_1.isMutationKey)(variableKey)) {
|
|
784
|
+
try {
|
|
785
|
+
(0, variableOverrideProgram_1.compileVariableMutation)(variableKey, variableValue);
|
|
786
|
+
}
|
|
787
|
+
catch (error) {
|
|
788
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: error.message, path });
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
682
791
|
const validation = (0, mutationNotation_1.validateMutationKey)(variableKey, variableSchemaByKey, schemasByKey);
|
|
683
792
|
if (!validation.valid && validation.error) {
|
|
684
793
|
ctx.addIssue({
|
|
@@ -689,11 +798,14 @@ function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, va
|
|
|
689
798
|
return;
|
|
690
799
|
}
|
|
691
800
|
if (validation.valueSchema) {
|
|
692
|
-
superRefineVariableValue(projectConfig, validation.valueSchema, variableValue, path, ctx,
|
|
801
|
+
superRefineVariableValue(projectConfig, validation.valueSchema, variableValue, path, ctx, validation.rootKey, schemasByKey, {
|
|
802
|
+
variableKey: validation.rootKey,
|
|
803
|
+
path: (0, mutationNotation_1.getMutationPath)(variableKey).slice(validation.rootKey.length).replace(/^\./, ""),
|
|
804
|
+
operation: validation.operation,
|
|
805
|
+
});
|
|
693
806
|
}
|
|
694
807
|
return;
|
|
695
808
|
}
|
|
696
|
-
const variableSchema = variableSchemaByKey[variableKey];
|
|
697
809
|
if (!variableSchema) {
|
|
698
810
|
ctx.addIssue({
|
|
699
811
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -704,9 +816,52 @@ function refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, va
|
|
|
704
816
|
}
|
|
705
817
|
superRefineVariableValue(projectConfig, variableSchema, variableValue, path, ctx, variableKey, schemasByKey);
|
|
706
818
|
}
|
|
707
|
-
function
|
|
819
|
+
function refineResolvedVariableValues(values, variableSchemaByKey, path, projectConfig, ctx, schemasByKey) {
|
|
820
|
+
const validValues = {};
|
|
821
|
+
const invalidRoots = new Set();
|
|
822
|
+
const mutatedRoots = new Set();
|
|
823
|
+
for (const [key, value] of Object.entries(values || {})) {
|
|
824
|
+
const root = (0, mutateVariables_1.rootVariableFromOverrideKey)(key, variableSchemaByKey);
|
|
825
|
+
let invalid = false;
|
|
826
|
+
refineVariableEntry(projectConfig, variableSchemaByKey, key, value, [...path, key], {
|
|
827
|
+
...ctx,
|
|
828
|
+
addIssue(issue) {
|
|
829
|
+
invalid = true;
|
|
830
|
+
ctx.addIssue(issue);
|
|
831
|
+
},
|
|
832
|
+
}, schemasByKey);
|
|
833
|
+
if (invalid)
|
|
834
|
+
invalidRoots.add(root);
|
|
835
|
+
else
|
|
836
|
+
validValues[key] = value;
|
|
837
|
+
if (key !== root)
|
|
838
|
+
mutatedRoots.add(root);
|
|
839
|
+
}
|
|
840
|
+
// Do not resolve a partially valid assignment or cascade from an invalid parent.
|
|
841
|
+
for (const key of Object.keys(validValues)) {
|
|
842
|
+
if (invalidRoots.has((0, mutateVariables_1.rootVariableFromOverrideKey)(key, variableSchemaByKey))) {
|
|
843
|
+
delete validValues[key];
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
try {
|
|
847
|
+
const resolved = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(variableSchemaByKey, validValues);
|
|
848
|
+
for (const [key, value] of Object.entries(resolved || {})) {
|
|
849
|
+
// Direct values were validated above. Only mutations need a result check.
|
|
850
|
+
if (!mutatedRoots.has(key))
|
|
851
|
+
continue;
|
|
852
|
+
superRefineVariableValue(projectConfig, variableSchemaByKey[key], value, [...path, key], ctx, key, schemasByKey);
|
|
853
|
+
}
|
|
854
|
+
return resolved;
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: error.message, path });
|
|
858
|
+
return undefined;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides, pathPrefix, projectConfig, schemasByKey, baseValues, }) {
|
|
708
862
|
for (const variableKey of Object.keys(variableOverrides)) {
|
|
709
|
-
|
|
863
|
+
const variableSchema = variableSchemaByKey[variableKey];
|
|
864
|
+
if (!variableSchema && (0, mutationNotation_1.isMutationKey)(variableKey)) {
|
|
710
865
|
ctx.addIssue({
|
|
711
866
|
code: zod_1.z.ZodIssueCode.custom,
|
|
712
867
|
message: `Variable override key "${variableKey}" must be a declared variable key, not mutation notation. ` +
|
|
@@ -715,7 +870,6 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
|
|
|
715
870
|
});
|
|
716
871
|
continue;
|
|
717
872
|
}
|
|
718
|
-
const variableSchema = variableSchemaByKey[variableKey];
|
|
719
873
|
if (!variableSchema) {
|
|
720
874
|
ctx.addIssue({
|
|
721
875
|
code: zod_1.z.ZodIssueCode.custom,
|
|
@@ -751,9 +905,9 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
|
|
|
751
905
|
];
|
|
752
906
|
if (typeof overrideValue === "object" &&
|
|
753
907
|
overrideValue !== null &&
|
|
754
|
-
!Array.isArray(overrideValue)) {
|
|
755
|
-
const
|
|
756
|
-
const pathKeys =
|
|
908
|
+
(!Array.isArray(overrideValue) || usesExplicitMutation)) {
|
|
909
|
+
const pathEntries = (0, mutationEntries_1.mutationEntries)(overrideValue);
|
|
910
|
+
const pathKeys = pathEntries.map(([key]) => key);
|
|
757
911
|
const hasStructuredObjectSchema = resolvedVariableSchema?.type === "object" &&
|
|
758
912
|
(Boolean(resolvedVariableSchema.properties) ||
|
|
759
913
|
Boolean(resolvedVariableSchema.additionalProperties));
|
|
@@ -761,26 +915,43 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
|
|
|
761
915
|
pathKeys.some((pathKey) => (0, mutationNotation_1.isMutationKey)(pathKey)) ||
|
|
762
916
|
(hasStructuredObjectSchema && pathKeys.length > 0);
|
|
763
917
|
if (treatAsPathMap) {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
918
|
+
let invalidOperand = false;
|
|
919
|
+
const operandContext = {
|
|
920
|
+
...ctx,
|
|
921
|
+
addIssue(issue) {
|
|
922
|
+
invalidOperand = true;
|
|
923
|
+
ctx.addIssue(issue);
|
|
924
|
+
},
|
|
925
|
+
};
|
|
926
|
+
for (const [entryIndex, [pathKey, mutationValue]] of pathEntries.entries()) {
|
|
927
|
+
const mutationPath = [
|
|
928
|
+
...valuePath,
|
|
929
|
+
...(0, mutationEntries_1.mutationEntryPath)(overrideValue, entryIndex, pathKey),
|
|
930
|
+
];
|
|
931
|
+
const validationRootKey = "variable";
|
|
932
|
+
const composedMutationKey = `${validationRootKey}${pathKey.startsWith("[") || pathKey.startsWith(":") ? "" : "."}${pathKey}`;
|
|
933
|
+
try {
|
|
934
|
+
(0, variableOverrideProgram_1.compileVariableMutation)(pathKey, mutationValue);
|
|
935
|
+
}
|
|
936
|
+
catch (error) {
|
|
937
|
+
operandContext.addIssue({
|
|
938
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
939
|
+
message: error.message,
|
|
940
|
+
path: mutationPath,
|
|
941
|
+
});
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
const validation = (0, mutationNotation_1.validateMutationKey)(composedMutationKey, { [validationRootKey]: variableSchema }, schemasByKey, { variableKey, path: pathKey });
|
|
767
945
|
if (!validation.valid) {
|
|
768
|
-
|
|
946
|
+
operandContext.addIssue({
|
|
769
947
|
code: zod_1.z.ZodIssueCode.custom,
|
|
770
948
|
message: validation.error ??
|
|
771
949
|
`Invalid mutation path "${pathKey}" in variableOverride for "${variableKey}".`,
|
|
772
|
-
path:
|
|
950
|
+
path: mutationPath,
|
|
773
951
|
});
|
|
774
952
|
continue;
|
|
775
953
|
}
|
|
776
954
|
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
955
|
continue;
|
|
785
956
|
}
|
|
786
957
|
const fallbackValueSchema = validation.operation === "append" ||
|
|
@@ -793,7 +964,22 @@ function refineVariableOverrides({ ctx, variableSchemaByKey, variableOverrides,
|
|
|
793
964
|
if (!valueSchema) {
|
|
794
965
|
continue;
|
|
795
966
|
}
|
|
796
|
-
superRefineVariableValue(projectConfig, valueSchema,
|
|
967
|
+
superRefineVariableValue(projectConfig, valueSchema, mutationValue, mutationPath, operandContext, variableKey, schemasByKey, { variableKey, path: (0, mutationNotation_1.getMutationPath)(pathKey), operation: validation.operation });
|
|
968
|
+
}
|
|
969
|
+
if (invalidOperand)
|
|
970
|
+
return;
|
|
971
|
+
try {
|
|
972
|
+
const resolved = (0, mutateVariables_1.resolveMutationsForSingleVariable)(variableSchemaByKey, variableKey, overrideValue, baseValues?.[variableKey], usesExplicitMutation);
|
|
973
|
+
superRefineVariableValue(projectConfig, variableSchema, resolved, valuePath, (0, mutationResultPaths_1.withMutationResultPaths)(ctx, override.mutate, valuePath, baseValues?.[variableKey] === undefined
|
|
974
|
+
? variableSchema.defaultValue
|
|
975
|
+
: baseValues[variableKey], variableKey), variableKey, schemasByKey);
|
|
976
|
+
}
|
|
977
|
+
catch (error) {
|
|
978
|
+
ctx.addIssue({
|
|
979
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
980
|
+
message: error.message,
|
|
981
|
+
path: valuePath,
|
|
982
|
+
});
|
|
797
983
|
}
|
|
798
984
|
}
|
|
799
985
|
else {
|
|
@@ -821,26 +1007,20 @@ variableSchemaByKey, variationValues, force, pathPrefix, projectConfig, schemasB
|
|
|
821
1007
|
}
|
|
822
1008
|
// force[n].variables[key]
|
|
823
1009
|
if (f.variables) {
|
|
824
|
-
|
|
825
|
-
refineVariableEntry(projectConfig, variableSchemaByKey, variableKey, f.variables[variableKey], pathPrefix.concat([fN, "variables", variableKey]), ctx, schemasByKey);
|
|
826
|
-
});
|
|
1010
|
+
refineResolvedVariableValues(f.variables, variableSchemaByKey, [...pathPrefix, fN, "variables"], projectConfig, ctx, schemasByKey);
|
|
827
1011
|
}
|
|
828
1012
|
});
|
|
829
1013
|
}
|
|
830
1014
|
function refineRules({ ctx, parsedFeature, variableSchemaByKey, variationValues, rules, pathPrefix, projectConfig, schemasByKey, }) {
|
|
831
1015
|
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
1016
|
// rules[n].variableOverrides[key][].value (path-map or full value)
|
|
1017
|
+
const baseValues = refineResolvedVariableValues(rule.variables, variableSchemaByKey, [...pathPrefix, ruleN, "variables"], projectConfig, ctx, schemasByKey);
|
|
839
1018
|
if (rule.variableOverrides) {
|
|
840
1019
|
refineVariableOverrides({
|
|
841
1020
|
ctx,
|
|
842
1021
|
variableSchemaByKey,
|
|
843
1022
|
variableOverrides: rule.variableOverrides,
|
|
1023
|
+
baseValues,
|
|
844
1024
|
pathPrefix: [...pathPrefix, ruleN, "variableOverrides"],
|
|
845
1025
|
projectConfig,
|
|
846
1026
|
schemasByKey,
|
|
@@ -898,8 +1078,8 @@ function refineRules({ ctx, parsedFeature, variableSchemaByKey, variationValues,
|
|
|
898
1078
|
}
|
|
899
1079
|
});
|
|
900
1080
|
}
|
|
901
|
-
function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttributeKeys, availableSegmentKeys, availableFeatureKeys, availableSchemaKeys = [], schemasByKey = {}, featuresByKey = {}) {
|
|
902
|
-
const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(availableSchemaKeys);
|
|
1081
|
+
function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttributeKeys, availableSegmentKeys, availableFeatureKeys, availableSchemaKeys = [], schemasByKey = {}, featuresByKey = {}, variablesByKey = {}) {
|
|
1082
|
+
const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(availableSchemaKeys, schemasByKey);
|
|
903
1083
|
const variableValueZodSchema = schema_1.valueZodSchema;
|
|
904
1084
|
const variableValueOrNullZodSchema = zod_1.z.union([schema_1.valueZodSchema, zod_1.z.null()]);
|
|
905
1085
|
const overridePathMapValueZodSchema = zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema);
|
|
@@ -908,56 +1088,22 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
908
1088
|
overridePathMapValueZodSchema,
|
|
909
1089
|
]);
|
|
910
1090
|
const variationValueZodSchema = zod_1.z.string().min(1);
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
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();
|
|
1091
|
+
conditionsZodSchema =
|
|
1092
|
+
conditionsZodSchema.withEntities?.(featuresByKey, variablesByKey, availableSegmentKeys) ||
|
|
1093
|
+
conditionsZodSchema;
|
|
932
1094
|
const featureVariableOverrideSchema = zod_1.z
|
|
933
1095
|
.object({
|
|
934
1096
|
key: zod_1.z.string().min(1).optional(),
|
|
935
1097
|
description: zod_1.z.string().optional(),
|
|
936
1098
|
promotable: zod_1.z.boolean().optional(),
|
|
937
1099
|
conditions: conditionsZodSchema.optional(),
|
|
938
|
-
|
|
939
|
-
requiredFeatures: requiredFeaturesZodSchema,
|
|
1100
|
+
...removedConditionFields_1.removedConditionFields,
|
|
940
1101
|
value: overrideValueZodSchema.optional(),
|
|
941
|
-
mutate: overridePathMapValueZodSchema.optional(),
|
|
1102
|
+
mutate: (0, mutationSchema_1.getMutationSchema)(overridePathMapValueZodSchema).optional(),
|
|
942
1103
|
})
|
|
943
1104
|
.strict()
|
|
944
1105
|
.superRefine((override, ctx) => {
|
|
945
|
-
|
|
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
|
-
}
|
|
1106
|
+
(0, removedConditionFields_1.refineRequiredConditions)(override, ctx);
|
|
961
1107
|
const hasValue = Object.prototype.hasOwnProperty.call(override, "value");
|
|
962
1108
|
const hasMutate = Object.prototype.hasOwnProperty.call(override, "mutate");
|
|
963
1109
|
if (hasValue === hasMutate) {
|
|
@@ -1011,7 +1157,8 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1011
1157
|
key: zod_1.z.string(),
|
|
1012
1158
|
description: zod_1.z.string().optional(),
|
|
1013
1159
|
promotable: zod_1.z.boolean().optional(),
|
|
1014
|
-
|
|
1160
|
+
conditions: conditionsZodSchema.optional(),
|
|
1161
|
+
...removedConditionFields_1.removedConditionFields,
|
|
1015
1162
|
percentage: zod_1.z.number().min(0).max(100),
|
|
1016
1163
|
enabled: zod_1.z.boolean().optional(),
|
|
1017
1164
|
variation: variationValueZodSchema.optional(),
|
|
@@ -1019,7 +1166,8 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1019
1166
|
variableOverrides: zod_1.z.record(zod_1.z.string(), featureVariableOverridesSchema).optional(),
|
|
1020
1167
|
variationWeights: zod_1.z.record(zod_1.z.string(), zod_1.z.number().min(0).max(100)).optional(),
|
|
1021
1168
|
})
|
|
1022
|
-
.strict()
|
|
1169
|
+
.strict()
|
|
1170
|
+
.superRefine(removedConditionFields_1.refineRequiredConditions))
|
|
1023
1171
|
// must have at least one rule
|
|
1024
1172
|
.superRefine((value, ctx) => {
|
|
1025
1173
|
if (value.length === 0) {
|
|
@@ -1031,49 +1179,46 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1031
1179
|
})
|
|
1032
1180
|
// duplicate rules
|
|
1033
1181
|
.superRefine((value, ctx) => {
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1182
|
+
const seen = new Set();
|
|
1183
|
+
const reported = new Set();
|
|
1184
|
+
value.forEach((rule, index) => {
|
|
1185
|
+
if (seen.has(rule.key) && !reported.has(rule.key)) {
|
|
1186
|
+
ctx.addIssue({
|
|
1187
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
1188
|
+
message: `Duplicate rule key "${rule.key}". Each rule key must be unique.`,
|
|
1189
|
+
path: [index, "key"],
|
|
1190
|
+
});
|
|
1191
|
+
reported.add(rule.key);
|
|
1192
|
+
}
|
|
1193
|
+
seen.add(rule.key);
|
|
1194
|
+
});
|
|
1041
1195
|
})
|
|
1042
1196
|
// enforce catch-all rule
|
|
1043
1197
|
.superRefine((value, ctx) => {
|
|
1044
1198
|
if (!projectConfig.enforceCatchAllRule) {
|
|
1045
1199
|
return;
|
|
1046
1200
|
}
|
|
1047
|
-
const hasCatchAllAsLastRule = value[value.length - 1]
|
|
1201
|
+
const hasCatchAllAsLastRule = value[value.length - 1]?.conditions === "*";
|
|
1048
1202
|
if (!hasCatchAllAsLastRule) {
|
|
1049
1203
|
ctx.addIssue({
|
|
1050
1204
|
code: zod_1.z.ZodIssueCode.custom,
|
|
1051
|
-
message: `Missing catch-all rule with \`
|
|
1205
|
+
message: `Missing catch-all rule with \`conditions: "*"\` at the end`,
|
|
1052
1206
|
});
|
|
1053
1207
|
}
|
|
1054
1208
|
});
|
|
1055
1209
|
const forceSchema = zod_1.z
|
|
1056
|
-
.array(zod_1.z
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
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
|
-
]))
|
|
1210
|
+
.array(zod_1.z
|
|
1211
|
+
.object({
|
|
1212
|
+
conditions: conditionsZodSchema.optional(),
|
|
1213
|
+
...removedConditionFields_1.removedConditionFields,
|
|
1214
|
+
enabled: zod_1.z.boolean().optional(),
|
|
1215
|
+
variation: variationValueZodSchema.optional(),
|
|
1216
|
+
variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
|
|
1217
|
+
})
|
|
1218
|
+
.strict()
|
|
1219
|
+
.superRefine(removedConditionFields_1.refineRequiredConditions))
|
|
1074
1220
|
.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}"`);
|
|
1221
|
+
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
1222
|
const environmentKeys = Array.isArray(projectConfig.environments)
|
|
1078
1223
|
? projectConfig.environments
|
|
1079
1224
|
: [];
|
|
@@ -1086,26 +1231,20 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1086
1231
|
tags: zod_1.z
|
|
1087
1232
|
.array((0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => projectConfig.tags.includes(value), (value) => `Unknown tag "${value}"`))
|
|
1088
1233
|
.superRefine((value, ctx) => {
|
|
1089
|
-
|
|
1234
|
+
const duplicates = value.filter((tag, index) => value.indexOf(tag) !== index);
|
|
1235
|
+
for (const tag of new Set(duplicates)) {
|
|
1090
1236
|
ctx.addIssue({
|
|
1091
1237
|
code: zod_1.z.ZodIssueCode.custom,
|
|
1092
|
-
message:
|
|
1238
|
+
message: `Duplicate tag "${tag}".`,
|
|
1239
|
+
params: { code: "duplicate_tag" },
|
|
1240
|
+
path: [value.lastIndexOf(tag)],
|
|
1093
1241
|
});
|
|
1094
1242
|
}
|
|
1095
1243
|
})
|
|
1096
1244
|
.optional(),
|
|
1097
|
-
required: zod_1.z
|
|
1098
|
-
|
|
1099
|
-
|
|
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(),
|
|
1245
|
+
required: zod_1.z.unknown().optional(),
|
|
1246
|
+
conditions: conditionsZodSchema.optional(),
|
|
1247
|
+
...removedConditionFields_1.removedConditionFields,
|
|
1109
1248
|
bucketBy: zod_1.z.union([
|
|
1110
1249
|
attributeKeyZodSchema,
|
|
1111
1250
|
zod_1.z.array(attributeKeyZodSchema),
|
|
@@ -1132,11 +1271,12 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1132
1271
|
oneOf: zod_1.z.array(schemaZodSchema).min(1).optional(),
|
|
1133
1272
|
minimum: zod_1.z.number().optional(),
|
|
1134
1273
|
maximum: zod_1.z.number().optional(),
|
|
1135
|
-
minLength:
|
|
1136
|
-
maxLength:
|
|
1274
|
+
minLength: schema_1.countZodSchema.optional(),
|
|
1275
|
+
maxLength: schema_1.countZodSchema.optional(),
|
|
1137
1276
|
pattern: zod_1.z.string().optional(),
|
|
1138
|
-
|
|
1139
|
-
|
|
1277
|
+
format: schema_1.schemaFormatZodSchema.optional(),
|
|
1278
|
+
minItems: schema_1.countZodSchema.optional(),
|
|
1279
|
+
maxItems: schema_1.countZodSchema.optional(),
|
|
1140
1280
|
uniqueItems: zod_1.z.boolean().optional(),
|
|
1141
1281
|
description: zod_1.z.string().optional(),
|
|
1142
1282
|
defaultValue: variableValueZodSchema,
|
|
@@ -1144,6 +1284,8 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1144
1284
|
useDefaultWhenDisabled: zod_1.z.boolean().optional(),
|
|
1145
1285
|
})
|
|
1146
1286
|
.strict()
|
|
1287
|
+
.superRefine((variableSchema, ctx) => (0, schemaFormats_1.refineRemovedSchemaType)(variableSchema, ctx))
|
|
1288
|
+
.superRefine((variableSchema, ctx) => (0, schema_1.refineSchemaFormat)(variableSchema, [], ctx, schemasByKey))
|
|
1147
1289
|
.superRefine((variableSchema, ctx) => {
|
|
1148
1290
|
const hasRef = "schema" in variableSchema && variableSchema.schema != null;
|
|
1149
1291
|
const hasInline = "type" in variableSchema &&
|
|
@@ -1247,32 +1389,24 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1247
1389
|
})
|
|
1248
1390
|
.strict()
|
|
1249
1391
|
.superRefine((value, ctx) => {
|
|
1250
|
-
|
|
1392
|
+
(0, removedConditionFields_1.refineRemovedConditionFields)(value, ctx);
|
|
1393
|
+
if (Object.prototype.hasOwnProperty.call(value, "required")) {
|
|
1251
1394
|
ctx.addIssue({
|
|
1252
1395
|
code: zod_1.z.ZodIssueCode.custom,
|
|
1253
|
-
message: "
|
|
1254
|
-
path: ["
|
|
1396
|
+
message: "Feature `required` has been removed. Use `conditions` and rename each `{ key: ... }` entry to `{ feature: ... }`. Schema property `required` is unchanged.",
|
|
1397
|
+
path: ["required"],
|
|
1255
1398
|
});
|
|
1256
1399
|
}
|
|
1257
1400
|
// disabledVariationValue
|
|
1258
|
-
if (value.disabledVariationValue) {
|
|
1259
|
-
|
|
1401
|
+
if (value.disabledVariationValue !== undefined && value.variations?.length) {
|
|
1402
|
+
const variationValues = value.variations.map((v) => v.value);
|
|
1403
|
+
if (variationValues.indexOf(value.disabledVariationValue) === -1) {
|
|
1260
1404
|
ctx.addIssue({
|
|
1261
1405
|
code: zod_1.z.ZodIssueCode.custom,
|
|
1262
|
-
message:
|
|
1406
|
+
message: `Disabled variation value "${value.disabledVariationValue}" is not one of the defined variations: ${variationValues.join(", ")}`,
|
|
1263
1407
|
path: ["disabledVariationValue"],
|
|
1264
1408
|
});
|
|
1265
1409
|
}
|
|
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
1410
|
}
|
|
1277
1411
|
// When variablesSchema is absent, variableSchemaByKey is {} so any variable key used in
|
|
1278
1412
|
// rules/force/variations will be reported as "not defined in variablesSchema".
|
|
@@ -1335,18 +1469,14 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1335
1469
|
// variations: validate variation.variables and variation.variableOverrides (each value against its variable schema)
|
|
1336
1470
|
if (value.variations) {
|
|
1337
1471
|
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
1472
|
// variations[n].variableOverrides[key][].value (path-map or full value)
|
|
1473
|
+
const baseValues = refineResolvedVariableValues(variation.variables, variableSchemaByKey, ["variations", variationN, "variables"], projectConfig, ctx, schemasByKey);
|
|
1345
1474
|
if (variation.variableOverrides) {
|
|
1346
1475
|
refineVariableOverrides({
|
|
1347
1476
|
ctx,
|
|
1348
1477
|
variableSchemaByKey,
|
|
1349
1478
|
variableOverrides: variation.variableOverrides,
|
|
1479
|
+
baseValues,
|
|
1350
1480
|
pathPrefix: ["variations", variationN, "variableOverrides"],
|
|
1351
1481
|
projectConfig,
|
|
1352
1482
|
schemasByKey,
|
|
@@ -1415,6 +1545,51 @@ function getFeatureZodSchema(projectConfig, conditionsZodSchema, availableAttrib
|
|
|
1415
1545
|
}
|
|
1416
1546
|
}
|
|
1417
1547
|
});
|
|
1418
|
-
|
|
1548
|
+
const editorConditions = conditionsZodSchema.editorSchema || conditionsZodSchema;
|
|
1549
|
+
const editorOverride = zod_1.z
|
|
1550
|
+
.object({
|
|
1551
|
+
...featureVariableOverrideSchema.shape,
|
|
1552
|
+
conditions: editorConditions,
|
|
1553
|
+
})
|
|
1554
|
+
.omit({ segments: true, requiredFeatures: true, requiredVariables: true })
|
|
1555
|
+
.strict();
|
|
1556
|
+
const editorOverrides = zod_1.z.record(zod_1.z.string(), zod_1.z.array(editorOverride));
|
|
1557
|
+
const editorRule = zod_1.z
|
|
1558
|
+
.object({
|
|
1559
|
+
...rulesSchema.element.shape,
|
|
1560
|
+
conditions: editorConditions,
|
|
1561
|
+
variableOverrides: editorOverrides.optional(),
|
|
1562
|
+
})
|
|
1563
|
+
.omit({ segments: true, requiredFeatures: true, requiredVariables: true })
|
|
1564
|
+
.strict();
|
|
1565
|
+
const editorForce = zod_1.z
|
|
1566
|
+
.object({
|
|
1567
|
+
conditions: editorConditions,
|
|
1568
|
+
enabled: zod_1.z.boolean().optional(),
|
|
1569
|
+
variation: variationValueZodSchema.optional(),
|
|
1570
|
+
variables: zod_1.z.record(zod_1.z.string(), variableValueOrNullZodSchema).optional(),
|
|
1571
|
+
})
|
|
1572
|
+
.strict();
|
|
1573
|
+
const editorVariation = zod_1.z
|
|
1574
|
+
.object({
|
|
1575
|
+
...featureZodSchema.shape.variations.unwrap().element.shape,
|
|
1576
|
+
variableOverrides: editorOverrides.optional(),
|
|
1577
|
+
})
|
|
1578
|
+
.strict();
|
|
1579
|
+
const editorSchema = zod_1.z
|
|
1580
|
+
.object({
|
|
1581
|
+
...featureZodSchema.shape,
|
|
1582
|
+
conditions: editorConditions.optional(),
|
|
1583
|
+
variations: zod_1.z.array(editorVariation).optional(),
|
|
1584
|
+
rules: !Array.isArray(projectConfig.environments)
|
|
1585
|
+
? zod_1.z.array(editorRule).min(1)
|
|
1586
|
+
: zod_1.z.partialRecord(zod_1.z.enum(environmentKeys), zod_1.z.array(editorRule).min(1)),
|
|
1587
|
+
force: (!Array.isArray(projectConfig.environments)
|
|
1588
|
+
? zod_1.z.array(editorForce)
|
|
1589
|
+
: zod_1.z.partialRecord(zod_1.z.enum(environmentKeys), zod_1.z.array(editorForce))).optional(),
|
|
1590
|
+
})
|
|
1591
|
+
.omit({ segments: true, requiredFeatures: true, requiredVariables: true })
|
|
1592
|
+
.strict();
|
|
1593
|
+
return Object.assign(featureZodSchema, { editorSchema });
|
|
1419
1594
|
}
|
|
1420
1595
|
//# sourceMappingURL=featureSchema.js.map
|