@featurevisor/core 3.10.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 +78 -17
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +13 -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/compare.d.ts +9 -0
- package/lib/diff/compare.js +31 -0
- package/lib/diff/compare.js.map +1 -0
- package/lib/diff/details.d.ts +11 -0
- package/lib/diff/details.js +210 -0
- package/lib/diff/details.js.map +1 -0
- package/lib/diff/git.d.ts +28 -0
- package/lib/diff/git.js +195 -0
- package/lib/diff/git.js.map +1 -0
- package/lib/diff/index.d.ts +36 -0
- package/lib/diff/index.js +229 -0
- package/lib/diff/index.js.map +1 -0
- 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
|
@@ -3,12 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getVariableZodSchema = getVariableZodSchema;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const mutator_1 = require("../builder/mutator");
|
|
6
|
+
const mutationEntries_1 = require("../builder/mutationEntries");
|
|
7
|
+
const mutationSchema_1 = require("./mutationSchema");
|
|
8
|
+
const mutationResultPaths_1 = require("./mutationResultPaths");
|
|
9
|
+
const variableOverrideProgram_1 = require("../builder/variableOverrideProgram");
|
|
10
|
+
const sdk_1 = require("@featurevisor/sdk");
|
|
6
11
|
const conditionSchema_1 = require("./conditionSchema");
|
|
7
12
|
const featureSchema_1 = require("./featureSchema");
|
|
8
13
|
const mutationNotation_1 = require("./mutationNotation");
|
|
14
|
+
const schemaFormats_1 = require("./schemaFormats");
|
|
9
15
|
const schema_1 = require("./schema");
|
|
10
16
|
const zodHelpers_1 = require("./zodHelpers");
|
|
11
|
-
const
|
|
17
|
+
const diagnostics_1 = require("./diagnostics");
|
|
18
|
+
const removedConditionFields_1 = require("./removedConditionFields");
|
|
19
|
+
const composedOverrideSchema_1 = require("./composedOverrideSchema");
|
|
20
|
+
const composition_1 = require("../datasource/composition");
|
|
21
|
+
// Evaluated composition members can be null at any depth, including inside a
|
|
22
|
+
// replacement object. Typed schema validation still rejects incompatible nulls.
|
|
23
|
+
const variableValueSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
24
|
+
zod_1.z.null(),
|
|
25
|
+
zod_1.z.boolean(),
|
|
26
|
+
zod_1.z.string(),
|
|
27
|
+
zod_1.z.number(),
|
|
28
|
+
zod_1.z.array(variableValueSchema),
|
|
29
|
+
zod_1.z.record(zod_1.z.string(), variableValueSchema),
|
|
30
|
+
]));
|
|
12
31
|
function mutationKeyForRoot(key) {
|
|
13
32
|
return key.startsWith("[") || key.startsWith(":") ? `value${key}` : `value.${key}`;
|
|
14
33
|
}
|
|
@@ -16,6 +35,17 @@ function getStaticExpressionValue(value) {
|
|
|
16
35
|
if (value === "*")
|
|
17
36
|
return true;
|
|
18
37
|
if (Array.isArray(value)) {
|
|
38
|
+
// A leaf AND its negation is false without evaluating dependencies. This
|
|
39
|
+
// preserves dead continuation analysis without allowing nested wildcards.
|
|
40
|
+
const positive = new Set(value.map((entry) => JSON.stringify(entry)));
|
|
41
|
+
if (value.some((entry) => entry &&
|
|
42
|
+
typeof entry === "object" &&
|
|
43
|
+
!Array.isArray(entry) &&
|
|
44
|
+
"not" in entry &&
|
|
45
|
+
Array.isArray(entry.not) &&
|
|
46
|
+
entry.not.length === 1 &&
|
|
47
|
+
positive.has(JSON.stringify(entry.not[0]))))
|
|
48
|
+
return false;
|
|
19
49
|
const values = value.map(getStaticExpressionValue);
|
|
20
50
|
if (values.indexOf(false) !== -1)
|
|
21
51
|
return false;
|
|
@@ -38,49 +68,183 @@ function getStaticExpressionValue(value) {
|
|
|
38
68
|
}
|
|
39
69
|
return undefined;
|
|
40
70
|
}
|
|
41
|
-
function
|
|
71
|
+
function getStaticOverrideMatch(override) {
|
|
72
|
+
return getStaticExpressionValue(override.conditions);
|
|
73
|
+
}
|
|
74
|
+
function getErrorMessage(error) {
|
|
75
|
+
return error instanceof Error ? error.message : String(error);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Continuation programs may reach a later override with values produced by more
|
|
79
|
+
* than one earlier match. Explore every statically possible route, while keeping
|
|
80
|
+
* a finite set of index/value states so authored input cannot cause unbounded
|
|
81
|
+
* linter work.
|
|
82
|
+
*/
|
|
83
|
+
function validateAccumulatingOverrides(overrides, rootPath, defaultValue, parsedVariable, projectConfig, schemasByKey, ctx, variableKey = "value", stateBudget = 4096) {
|
|
84
|
+
const pathsByKeyPath = new Map();
|
|
85
|
+
const overridesByKeyPath = new Map();
|
|
86
|
+
const seenKeys = new Map();
|
|
87
|
+
let hasCompilationError = false;
|
|
88
|
+
const inspectionContext = {
|
|
89
|
+
...ctx,
|
|
90
|
+
addIssue(issue) {
|
|
91
|
+
hasCompilationError = true;
|
|
92
|
+
ctx.addIssue(issue);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const inspect = (entries, parentPath, parentKeyPath) => {
|
|
96
|
+
entries.forEach((override, overrideIndex) => {
|
|
97
|
+
const pathPrefix = [...parentPath, overrideIndex];
|
|
98
|
+
const keyPath = [...parentKeyPath, override.key];
|
|
99
|
+
const serializedKeyPath = JSON.stringify(keyPath);
|
|
100
|
+
pathsByKeyPath.set(serializedKeyPath, pathPrefix);
|
|
101
|
+
overridesByKeyPath.set(serializedKeyPath, override);
|
|
102
|
+
if (seenKeys.has(override.key)) {
|
|
103
|
+
inspectionContext.addIssue({
|
|
104
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
105
|
+
message: `Duplicate override key found in tree: ${override.key}`,
|
|
106
|
+
path: [...pathPrefix, "key"],
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
seenKeys.set(override.key, pathPrefix);
|
|
111
|
+
}
|
|
112
|
+
if (Object.prototype.hasOwnProperty.call(override, "value")) {
|
|
113
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, override.value, [...pathPrefix, "value"], inspectionContext, variableKey, schemasByKey);
|
|
114
|
+
}
|
|
115
|
+
if (override.mutate) {
|
|
116
|
+
for (const [entryIndex, [mutationKey, mutationValue]] of (0, mutationEntries_1.mutationEntries)(override.mutate).entries()) {
|
|
117
|
+
const mutationPath = [
|
|
118
|
+
...pathPrefix,
|
|
119
|
+
"mutate",
|
|
120
|
+
...(0, mutationEntries_1.mutationEntryPath)(override.mutate, entryIndex, mutationKey),
|
|
121
|
+
];
|
|
122
|
+
try {
|
|
123
|
+
(0, variableOverrideProgram_1.compileVariableMutation)(mutationKey, mutationValue);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
hasCompilationError = true;
|
|
127
|
+
inspectionContext.addIssue({
|
|
128
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
129
|
+
message: getErrorMessage(error),
|
|
130
|
+
path: mutationPath,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const validation = (0, mutationNotation_1.validateMutationKey)(mutationKeyForRoot(mutationKey), { value: parsedVariable }, schemasByKey, { variableKey, path: mutationKey });
|
|
134
|
+
if (!validation.valid) {
|
|
135
|
+
inspectionContext.addIssue({
|
|
136
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
137
|
+
message: validation.error || `Invalid mutation path "${mutationKey}"`,
|
|
138
|
+
path: mutationPath,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else if (validation.operation !== "remove") {
|
|
142
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, validation.valueSchema, mutationValue, mutationPath, inspectionContext, variableKey, schemasByKey, { variableKey, path: (0, mutationNotation_1.getMutationPath)(mutationKey), operation: validation.operation });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
inspect(override.overrides || [], [...pathPrefix, "overrides"], keyPath);
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
inspect(overrides, rootPath, []);
|
|
150
|
+
if (hasCompilationError)
|
|
151
|
+
return;
|
|
152
|
+
let program;
|
|
153
|
+
try {
|
|
154
|
+
program = (0, variableOverrideProgram_1.buildVariableOverrideProgram)(overrides);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
ctx.addIssue({
|
|
158
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
159
|
+
message: getErrorMessage(error),
|
|
160
|
+
path: rootPath,
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const states = [{ index: 0, value: defaultValue }];
|
|
165
|
+
const visited = new Set();
|
|
166
|
+
let exceededBudget = false;
|
|
167
|
+
const stateKey = (state) => `${state.index}:${JSON.stringify(state.value)}`;
|
|
168
|
+
visited.add(stateKey(states[0]));
|
|
169
|
+
const addState = (state, path) => {
|
|
170
|
+
const key = stateKey(state);
|
|
171
|
+
if (visited.has(key) || exceededBudget)
|
|
172
|
+
return;
|
|
173
|
+
if (visited.size >= stateBudget) {
|
|
174
|
+
exceededBudget = true;
|
|
175
|
+
ctx.addIssue({
|
|
176
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
177
|
+
message: `Accumulating variable overrides exceed the validation state budget (${stateBudget}). Simplify the continuing override composition.`,
|
|
178
|
+
path,
|
|
179
|
+
});
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
visited.add(key);
|
|
183
|
+
states.push(state);
|
|
184
|
+
};
|
|
185
|
+
while (states.length > 0 && !exceededBudget) {
|
|
186
|
+
const state = states.pop();
|
|
187
|
+
const step = program[state.index];
|
|
188
|
+
if (!step)
|
|
189
|
+
continue;
|
|
190
|
+
const serializedKeyPath = JSON.stringify(step.keyPath);
|
|
191
|
+
const pathPrefix = pathsByKeyPath.get(serializedKeyPath) || rootPath;
|
|
192
|
+
const authoredOverride = overridesByKeyPath.get(serializedKeyPath);
|
|
193
|
+
const staticMatch = authoredOverride ? getStaticOverrideMatch(authoredOverride) : undefined;
|
|
194
|
+
if (staticMatch !== false) {
|
|
195
|
+
try {
|
|
196
|
+
const value = (0, sdk_1.applyVariableOperations)(state.value, step.operations);
|
|
197
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, value, [...pathPrefix, authoredOverride?.mutate ? "mutate" : "value"], (0, mutationResultPaths_1.withMutationResultPaths)(ctx, authoredOverride?.mutate, [...pathPrefix, "mutate"], state.value), variableKey, schemasByKey);
|
|
198
|
+
addState({ index: step.onMatch, value }, pathPrefix);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
ctx.addIssue({
|
|
202
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
203
|
+
message: `Unable to apply accumulating override "${step.key}": ${getErrorMessage(error)}`,
|
|
204
|
+
path: authoredOverride?.mutate ? [...pathPrefix, "mutate"] : [...pathPrefix, "value"],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (staticMatch !== true) {
|
|
209
|
+
addState({ index: step.onMiss, value: state.value }, pathPrefix);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featuresByKey, schemasByKey, variablesByKey = {}, getVariableKey = () => "value") {
|
|
42
214
|
const schemaKeys = Object.keys(schemasByKey);
|
|
43
|
-
const nestedSchema = (0, schema_1.getSchemaZodSchema)(schemaKeys);
|
|
44
|
-
const conditionsSchema = (0, conditionSchema_1.getConditionsZodSchema)(projectConfig, attributesByKey, schemasByKey);
|
|
45
|
-
const valueSchema =
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
215
|
+
const nestedSchema = (0, schema_1.getSchemaZodSchema)(schemaKeys, schemasByKey);
|
|
216
|
+
const conditionsSchema = (0, conditionSchema_1.getConditionsZodSchema)(projectConfig, attributesByKey, schemasByKey, featuresByKey, variablesByKey, segmentKeys);
|
|
217
|
+
const valueSchema = variableValueSchema;
|
|
218
|
+
const mutationMapSchema = zod_1.z
|
|
219
|
+
.unknown()
|
|
220
|
+
.superRefine((value, ctx) => {
|
|
221
|
+
if (value &&
|
|
222
|
+
typeof value === "object" &&
|
|
223
|
+
Object.prototype.hasOwnProperty.call(value, "__proto__")) {
|
|
224
|
+
ctx.addIssue({
|
|
225
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
226
|
+
message: 'Unsafe mutation key "__proto__" is not allowed.',
|
|
227
|
+
path: ["__proto__"],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
})
|
|
231
|
+
.pipe(zod_1.z.record(zod_1.z.string(), valueSchema));
|
|
55
232
|
let overridesArraySchema;
|
|
56
233
|
const overrideSchema = zod_1.z.lazy(() => zod_1.z
|
|
57
234
|
.object({
|
|
58
235
|
key: zod_1.z.string().min(1),
|
|
59
236
|
description: zod_1.z.string().optional(),
|
|
60
237
|
promotable: zod_1.z.boolean().optional(),
|
|
61
|
-
segments: segmentsSchema.optional(),
|
|
62
238
|
conditions: conditionsSchema.optional(),
|
|
63
|
-
|
|
239
|
+
...removedConditionFields_1.removedConditionFields,
|
|
240
|
+
continue: zod_1.z.boolean().optional(),
|
|
64
241
|
value: valueSchema.optional(),
|
|
65
|
-
mutate:
|
|
242
|
+
mutate: (0, mutationSchema_1.getMutationSchema)(mutationMapSchema).optional(),
|
|
66
243
|
overrides: overridesArraySchema.optional(),
|
|
67
244
|
})
|
|
68
245
|
.strict()
|
|
69
246
|
.superRefine((override, ctx) => {
|
|
70
|
-
|
|
71
|
-
ctx.addIssue({
|
|
72
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
73
|
-
message: "An override must define `conditions`, `segments`, or `requiredFeatures`.",
|
|
74
|
-
path: ["segments"],
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
if (override.segments && override.conditions) {
|
|
78
|
-
ctx.addIssue({
|
|
79
|
-
code: zod_1.z.ZodIssueCode.custom,
|
|
80
|
-
message: "An override cannot define both `conditions` and `segments`.",
|
|
81
|
-
path: ["segments"],
|
|
82
|
-
});
|
|
83
|
-
}
|
|
247
|
+
(0, removedConditionFields_1.refineRequiredConditions)(override, ctx);
|
|
84
248
|
const hasValue = Object.prototype.hasOwnProperty.call(override, "value");
|
|
85
249
|
const hasMutate = Object.prototype.hasOwnProperty.call(override, "mutate");
|
|
86
250
|
if (hasValue === hasMutate) {
|
|
@@ -100,23 +264,12 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
100
264
|
});
|
|
101
265
|
}
|
|
102
266
|
overrides.forEach((override, index) => {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
: undefined;
|
|
106
|
-
const conditionsValue = override.conditions
|
|
107
|
-
? getStaticExpressionValue(override.conditions)
|
|
108
|
-
: undefined;
|
|
109
|
-
const isCatchAll = typeof override.requiredFeatures === "undefined" &&
|
|
110
|
-
(segmentsValue === true || conditionsValue === true) &&
|
|
111
|
-
segmentsValue !== false &&
|
|
112
|
-
conditionsValue !== false &&
|
|
113
|
-
(typeof override.segments === "undefined" || segmentsValue === true) &&
|
|
114
|
-
(typeof override.conditions === "undefined" || conditionsValue === true);
|
|
115
|
-
if (isCatchAll && index !== overrides.length - 1) {
|
|
267
|
+
const isCatchAll = getStaticExpressionValue(override.conditions) === true;
|
|
268
|
+
if (isCatchAll && override.continue !== true && index !== overrides.length - 1) {
|
|
116
269
|
ctx.addIssue({
|
|
117
270
|
code: zod_1.z.ZodIssueCode.custom,
|
|
118
271
|
message: "A catch-all override must be the final override because subsequent overrides are unreachable.",
|
|
119
|
-
path: [index, "
|
|
272
|
+
path: [index, "conditions"],
|
|
120
273
|
});
|
|
121
274
|
}
|
|
122
275
|
});
|
|
@@ -144,20 +297,24 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
144
297
|
oneOf: zod_1.z.array(nestedSchema).min(2).optional(),
|
|
145
298
|
minimum: zod_1.z.number().optional(),
|
|
146
299
|
maximum: zod_1.z.number().optional(),
|
|
147
|
-
minLength:
|
|
148
|
-
maxLength:
|
|
300
|
+
minLength: schema_1.countZodSchema.optional(),
|
|
301
|
+
maxLength: schema_1.countZodSchema.optional(),
|
|
149
302
|
pattern: zod_1.z.string().optional(),
|
|
150
|
-
|
|
151
|
-
|
|
303
|
+
format: schema_1.schemaFormatZodSchema.optional(),
|
|
304
|
+
minItems: schema_1.countZodSchema.optional(),
|
|
305
|
+
maxItems: schema_1.countZodSchema.optional(),
|
|
152
306
|
uniqueItems: zod_1.z.boolean().optional(),
|
|
153
307
|
defaultValue: valueSchema,
|
|
154
308
|
disabledValue: valueSchema.optional(),
|
|
155
309
|
useDefaultWhenDisabled: zod_1.z.boolean().optional(),
|
|
156
|
-
|
|
310
|
+
conditions: conditionsSchema.optional(),
|
|
311
|
+
...removedConditionFields_1.removedConditionFields,
|
|
157
312
|
overrides: overridesSchema.optional(),
|
|
158
313
|
})
|
|
159
314
|
.strict()
|
|
160
315
|
.superRefine((variable, ctx) => {
|
|
316
|
+
(0, removedConditionFields_1.refineRemovedConditionFields)(variable, ctx);
|
|
317
|
+
const variableKey = getVariableKey();
|
|
161
318
|
const hasReference = Boolean(variable.schema);
|
|
162
319
|
const inlineFields = [
|
|
163
320
|
"type",
|
|
@@ -173,6 +330,7 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
173
330
|
"minLength",
|
|
174
331
|
"maxLength",
|
|
175
332
|
"pattern",
|
|
333
|
+
"format",
|
|
176
334
|
"minItems",
|
|
177
335
|
"maxItems",
|
|
178
336
|
"uniqueItems",
|
|
@@ -199,17 +357,19 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
199
357
|
path: ["oneOf"],
|
|
200
358
|
});
|
|
201
359
|
}
|
|
360
|
+
(0, schemaFormats_1.refineRemovedSchemaType)(variable, ctx);
|
|
202
361
|
if (!hasReference) {
|
|
203
362
|
(0, schema_1.refineEnumMatchesType)(variable, [], ctx);
|
|
204
363
|
(0, schema_1.refineMinimumMaximum)(variable, [], ctx);
|
|
205
364
|
(0, schema_1.refineStringLengthPattern)(variable, [], ctx);
|
|
365
|
+
(0, schema_1.refineSchemaFormat)(variable, [], ctx, schemasByKey);
|
|
206
366
|
(0, schema_1.refineArrayItems)(variable, [], ctx);
|
|
207
367
|
(0, featureSchema_1.refineRequiredKeysInSchema)(variable, [], ctx, schemasByKey);
|
|
208
368
|
}
|
|
209
369
|
const parsedVariable = variable;
|
|
210
|
-
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, variable.defaultValue, ["defaultValue"], ctx,
|
|
370
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, variable.defaultValue, ["defaultValue"], ctx, variableKey, schemasByKey);
|
|
211
371
|
if (typeof variable.disabledValue !== "undefined") {
|
|
212
|
-
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, variable.disabledValue, ["disabledValue"], ctx,
|
|
372
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, variable.disabledValue, ["disabledValue"], ctx, variableKey, schemasByKey);
|
|
213
373
|
}
|
|
214
374
|
const overrideGroups = Array.isArray(variable.overrides)
|
|
215
375
|
? [[undefined, variable.overrides]]
|
|
@@ -218,6 +378,10 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
218
378
|
const rootPath = ["overrides"];
|
|
219
379
|
if (environment)
|
|
220
380
|
rootPath.push(environment);
|
|
381
|
+
if ((0, variableOverrideProgram_1.hasContinuingVariableOverrides)(overrides)) {
|
|
382
|
+
validateAccumulatingOverrides(overrides, rootPath, variable.defaultValue, parsedVariable, projectConfig, schemasByKey, ctx, variableKey);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
221
385
|
const seenKeys = new Map();
|
|
222
386
|
const validateOverrides = (entries, baseValue, parentPath) => {
|
|
223
387
|
entries.forEach((override, overrideIndex) => {
|
|
@@ -235,23 +399,57 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
235
399
|
}
|
|
236
400
|
let resolvedValue = override.value;
|
|
237
401
|
if (Object.prototype.hasOwnProperty.call(override, "value")) {
|
|
238
|
-
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, override.value, [...pathPrefix, "value"], ctx,
|
|
402
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, override.value, [...pathPrefix, "value"], ctx, variableKey, schemasByKey);
|
|
239
403
|
}
|
|
240
404
|
if (override.mutate) {
|
|
241
405
|
resolvedValue = JSON.parse(JSON.stringify(baseValue));
|
|
242
|
-
|
|
243
|
-
|
|
406
|
+
let invalidMutation = false;
|
|
407
|
+
for (const [entryIndex, [key, mutationValue]] of (0, mutationEntries_1.mutationEntries)(override.mutate).entries()) {
|
|
408
|
+
let invalidOperand = false;
|
|
409
|
+
const operandContext = {
|
|
410
|
+
...ctx,
|
|
411
|
+
addIssue(issue) {
|
|
412
|
+
invalidOperand = true;
|
|
413
|
+
invalidMutation = true;
|
|
414
|
+
ctx.addIssue(issue);
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
const mutationPath = [
|
|
418
|
+
...pathPrefix,
|
|
419
|
+
"mutate",
|
|
420
|
+
...(0, mutationEntries_1.mutationEntryPath)(override.mutate, entryIndex, key),
|
|
421
|
+
];
|
|
422
|
+
const validation = (0, mutationNotation_1.validateMutationKey)(mutationKeyForRoot(key), { value: parsedVariable }, schemasByKey, { variableKey, path: key });
|
|
244
423
|
if (!validation.valid) {
|
|
245
|
-
|
|
424
|
+
operandContext.addIssue({
|
|
246
425
|
code: zod_1.z.ZodIssueCode.custom,
|
|
247
426
|
message: validation.error || `Invalid mutation path "${key}"`,
|
|
248
|
-
path:
|
|
427
|
+
path: mutationPath,
|
|
249
428
|
});
|
|
250
429
|
continue;
|
|
251
430
|
}
|
|
252
|
-
|
|
431
|
+
try {
|
|
432
|
+
// Validate operands even if an index or selector cannot match the current value.
|
|
433
|
+
(0, variableOverrideProgram_1.compileVariableMutation)(key, mutationValue);
|
|
434
|
+
if (validation.operation !== "remove" && validation.valueSchema) {
|
|
435
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, validation.valueSchema, mutationValue, mutationPath, operandContext, variableKey, schemasByKey, { variableKey, path: (0, mutationNotation_1.getMutationPath)(key), operation: validation.operation });
|
|
436
|
+
}
|
|
437
|
+
if (invalidOperand)
|
|
438
|
+
continue;
|
|
439
|
+
resolvedValue = (0, mutator_1.mutate)(parsedVariable, resolvedValue, key, mutationValue);
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
operandContext.addIssue({
|
|
443
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
444
|
+
message: getErrorMessage(error),
|
|
445
|
+
path: mutationPath,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
253
448
|
}
|
|
254
|
-
|
|
449
|
+
if (invalidMutation)
|
|
450
|
+
resolvedValue = baseValue;
|
|
451
|
+
else
|
|
452
|
+
(0, featureSchema_1.superRefineVariableValue)(projectConfig, parsedVariable, resolvedValue, [...pathPrefix, "mutate"], (0, mutationResultPaths_1.withMutationResultPaths)(ctx, override.mutate, [...pathPrefix, "mutate"], baseValue), variableKey, schemasByKey);
|
|
255
453
|
}
|
|
256
454
|
validateOverrides(override.overrides || [], resolvedValue, [
|
|
257
455
|
...pathPrefix,
|
|
@@ -269,6 +467,207 @@ function getVariableZodSchema(projectConfig, attributesByKey, segmentKeys, featu
|
|
|
269
467
|
});
|
|
270
468
|
}
|
|
271
469
|
});
|
|
272
|
-
|
|
470
|
+
const referenceKey = zod_1.z.string().min(1, "Reference keys must be nonempty strings.");
|
|
471
|
+
const referenceSchema = zod_1.z.union([
|
|
472
|
+
zod_1.z.object({ feature: referenceKey }).strict(),
|
|
473
|
+
zod_1.z.object({ feature: referenceKey, variation: zod_1.z.literal(true) }).strict(),
|
|
474
|
+
zod_1.z.object({ feature: referenceKey, variable: referenceKey }).strict(),
|
|
475
|
+
zod_1.z.object({ variable: referenceKey }).strict(),
|
|
476
|
+
], {
|
|
477
|
+
error: "Composition members must be exactly { feature }, { feature, variation: true }, { feature, variable }, or { variable }, with nonempty string keys and no unknown fields.",
|
|
478
|
+
});
|
|
479
|
+
const forbiddenFields = [
|
|
480
|
+
"type",
|
|
481
|
+
"schema",
|
|
482
|
+
"items",
|
|
483
|
+
"properties",
|
|
484
|
+
"additionalProperties",
|
|
485
|
+
"required",
|
|
486
|
+
"enum",
|
|
487
|
+
"const",
|
|
488
|
+
"oneOf",
|
|
489
|
+
"minimum",
|
|
490
|
+
"maximum",
|
|
491
|
+
"minLength",
|
|
492
|
+
"maxLength",
|
|
493
|
+
"pattern",
|
|
494
|
+
"format",
|
|
495
|
+
"minItems",
|
|
496
|
+
"maxItems",
|
|
497
|
+
"uniqueItems",
|
|
498
|
+
"defaultValue",
|
|
499
|
+
"useDefaultWhenDisabled",
|
|
500
|
+
"mutate",
|
|
501
|
+
"continue",
|
|
502
|
+
"value",
|
|
503
|
+
];
|
|
504
|
+
const composeMapSchema = zod_1.z
|
|
505
|
+
.record(zod_1.z
|
|
506
|
+
.string()
|
|
507
|
+
.min(1)
|
|
508
|
+
.refine((alias) => !["__proto__", "constructor", "prototype"].includes(alias), "Unsafe composition property is not allowed."), referenceSchema)
|
|
509
|
+
.refine((members) => Object.keys(members).length > 0, "compose must be a nonempty map.");
|
|
510
|
+
const composedShape = zod_1.z
|
|
511
|
+
.object({
|
|
512
|
+
description: zod_1.z.string().min(1),
|
|
513
|
+
tags: variableSchema.shape.tags,
|
|
514
|
+
archived: zod_1.z.boolean().optional(),
|
|
515
|
+
deprecated: zod_1.z.boolean().optional(),
|
|
516
|
+
promotable: zod_1.z.boolean().optional(),
|
|
517
|
+
overrides: overridesSchema.optional(),
|
|
518
|
+
compose: zod_1.z.union([referenceKey, composeMapSchema]),
|
|
519
|
+
conditions: conditionsSchema.optional(),
|
|
520
|
+
disabledValue: valueSchema.optional(),
|
|
521
|
+
...removedConditionFields_1.removedConditionFields,
|
|
522
|
+
})
|
|
523
|
+
.strict();
|
|
524
|
+
const composedSchema = zod_1.z
|
|
525
|
+
.unknown()
|
|
526
|
+
.superRefine((value, ctx) => {
|
|
527
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
528
|
+
return;
|
|
529
|
+
// Zod records deliberately omit __proto__. Inspect authored keys first so
|
|
530
|
+
// the diagnostic names the rejected property rather than an empty result.
|
|
531
|
+
if ("compose" in value && value.compose && typeof value.compose === "object") {
|
|
532
|
+
for (const alias of Object.keys(value.compose)) {
|
|
533
|
+
if (["__proto__", "prototype", "constructor"].includes(alias))
|
|
534
|
+
ctx.addIssue({
|
|
535
|
+
code: "custom",
|
|
536
|
+
path: ["compose", alias],
|
|
537
|
+
message: `Composition property ${JSON.stringify(alias)} is not allowed.`,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
for (const field of forbiddenFields) {
|
|
542
|
+
if (Object.prototype.hasOwnProperty.call(value, field)) {
|
|
543
|
+
ctx.addIssue({
|
|
544
|
+
code: "custom",
|
|
545
|
+
path: [field],
|
|
546
|
+
message: `\`${field}\` is not supported on a composed variable.`,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
})
|
|
551
|
+
.pipe(composedShape.extend({
|
|
552
|
+
// Select the authored form before parsing so map diagnostics retain their paths.
|
|
553
|
+
compose: zod_1.z.unknown().transform((value, ctx) => {
|
|
554
|
+
if (typeof value !== "string" &&
|
|
555
|
+
(!value ||
|
|
556
|
+
typeof value !== "object" ||
|
|
557
|
+
Array.isArray(value) ||
|
|
558
|
+
![Object.prototype, null].includes(Object.getPrototypeOf(value)))) {
|
|
559
|
+
ctx.addIssue({
|
|
560
|
+
code: "custom",
|
|
561
|
+
message: "compose must be a global variable key or a nonempty map of references.",
|
|
562
|
+
});
|
|
563
|
+
return zod_1.z.NEVER;
|
|
564
|
+
}
|
|
565
|
+
const result = (typeof value === "string" ? referenceKey : composeMapSchema).safeParse(value, diagnostics_1.diagnosticParseOptions);
|
|
566
|
+
if (!result.success) {
|
|
567
|
+
for (const issue of result.error.issues)
|
|
568
|
+
ctx.addIssue({ ...issue });
|
|
569
|
+
return zod_1.z.NEVER;
|
|
570
|
+
}
|
|
571
|
+
return result.data;
|
|
572
|
+
}),
|
|
573
|
+
}))
|
|
574
|
+
.superRefine((variable, ctx) => {
|
|
575
|
+
(0, removedConditionFields_1.refineRemovedConditionFields)(variable, ctx);
|
|
576
|
+
for (const [alias, reference] of (0, composition_1.getCompositionEntries)(variable)) {
|
|
577
|
+
if (!referenceSchema.safeParse(reference).success)
|
|
578
|
+
continue;
|
|
579
|
+
if ("feature" in reference) {
|
|
580
|
+
const feature = Object.prototype.hasOwnProperty.call(featuresByKey, reference.feature)
|
|
581
|
+
? featuresByKey[reference.feature]
|
|
582
|
+
: undefined;
|
|
583
|
+
if (!feature) {
|
|
584
|
+
ctx.addIssue({
|
|
585
|
+
code: "custom",
|
|
586
|
+
path: ["compose", alias, "feature"],
|
|
587
|
+
message: `Unknown feature "${reference.feature}".${(0, diagnostics_1.suggestKey)(reference.feature, Object.keys(featuresByKey))}`,
|
|
588
|
+
params: zodHelpers_1.UNKNOWN_REFERENCE,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
else if ("variation" in reference &&
|
|
592
|
+
!feature.variations?.length &&
|
|
593
|
+
feature.disabledVariationValue === undefined) {
|
|
594
|
+
ctx.addIssue({
|
|
595
|
+
code: "custom",
|
|
596
|
+
path: ["compose", alias, "variation"],
|
|
597
|
+
message: `Feature "${reference.feature}" has no variations, so this member is always null. Reference its flag instead.`,
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
else if ("variable" in reference &&
|
|
601
|
+
!Object.prototype.hasOwnProperty.call(feature.variablesSchema || {}, reference.variable)) {
|
|
602
|
+
ctx.addIssue({
|
|
603
|
+
code: "custom",
|
|
604
|
+
path: alias === undefined ? ["compose"] : ["compose", alias, "variable"],
|
|
605
|
+
message: `Unknown feature variable "${reference.variable}" in feature "${reference.feature}".${(0, diagnostics_1.suggestKey)(reference.variable, Object.keys(feature.variablesSchema || {}))}`,
|
|
606
|
+
params: zodHelpers_1.UNKNOWN_REFERENCE,
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
const source = Object.prototype.hasOwnProperty.call(variablesByKey, reference.variable)
|
|
612
|
+
? variablesByKey[reference.variable]
|
|
613
|
+
: undefined;
|
|
614
|
+
if (!source) {
|
|
615
|
+
ctx.addIssue({
|
|
616
|
+
code: "custom",
|
|
617
|
+
path: alias === undefined ? ["compose"] : ["compose", alias, "variable"],
|
|
618
|
+
message: `Unknown global variable "${reference.variable}".${alias === undefined &&
|
|
619
|
+
Object.prototype.hasOwnProperty.call(featuresByKey, reference.variable)
|
|
620
|
+
? ` "${reference.variable}" is a feature. Use { enabled: { feature: ${JSON.stringify(reference.variable)} } } in compose to read its flag.`
|
|
621
|
+
: (0, diagnostics_1.suggestKey)(reference.variable, Object.keys(variablesByKey))}`,
|
|
622
|
+
params: zodHelpers_1.UNKNOWN_REFERENCE,
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
(0, composedOverrideSchema_1.refineComposedOverrides)({ ...variable, compose: variable.compose }, featuresByKey, variablesByKey, schemasByKey, projectConfig, ctx, getVariableKey());
|
|
628
|
+
});
|
|
629
|
+
const editorConditions = conditionsSchema.editorSchema;
|
|
630
|
+
const editorOverride = zod_1.z.lazy(() => zod_1.z
|
|
631
|
+
.object({
|
|
632
|
+
key: zod_1.z.string().min(1),
|
|
633
|
+
description: zod_1.z.string().optional(),
|
|
634
|
+
promotable: zod_1.z.boolean().optional(),
|
|
635
|
+
conditions: editorConditions,
|
|
636
|
+
continue: zod_1.z.boolean().optional(),
|
|
637
|
+
value: valueSchema.optional(),
|
|
638
|
+
mutate: (0, mutationSchema_1.getMutationSchema)(mutationMapSchema).optional(),
|
|
639
|
+
overrides: zod_1.z.array(editorOverride).optional(),
|
|
640
|
+
})
|
|
641
|
+
.strict());
|
|
642
|
+
const editorOverrides = (Array.isArray(projectConfig.environments)
|
|
643
|
+
? zod_1.z.partialRecord(zod_1.z.enum(projectConfig.environments), zod_1.z.array(editorOverride))
|
|
644
|
+
: zod_1.z.array(editorOverride)).optional();
|
|
645
|
+
const editorOrdinary = zod_1.z
|
|
646
|
+
.object({
|
|
647
|
+
...variableSchema.shape,
|
|
648
|
+
conditions: editorConditions.optional(),
|
|
649
|
+
overrides: editorOverrides,
|
|
650
|
+
})
|
|
651
|
+
.omit({ segments: true, requiredFeatures: true, requiredVariables: true })
|
|
652
|
+
.strict();
|
|
653
|
+
const editorComposed = zod_1.z
|
|
654
|
+
.object({
|
|
655
|
+
...composedShape.shape,
|
|
656
|
+
conditions: editorConditions.optional(),
|
|
657
|
+
overrides: editorOverrides,
|
|
658
|
+
})
|
|
659
|
+
.omit({ segments: true, requiredFeatures: true, requiredVariables: true })
|
|
660
|
+
.strict();
|
|
661
|
+
const editorSchema = zod_1.z.union([editorOrdinary, editorComposed]);
|
|
662
|
+
const authoredSchema = zod_1.z.unknown().transform((value, ctx) => {
|
|
663
|
+
const isComposed = value && typeof value === "object" && Object.prototype.hasOwnProperty.call(value, "compose");
|
|
664
|
+
const result = (isComposed ? composedSchema : variableSchema).safeParse(value, diagnostics_1.diagnosticParseOptions);
|
|
665
|
+
if (!result.success) {
|
|
666
|
+
result.error.issues.forEach((issue) => ctx.addIssue({ ...issue }));
|
|
667
|
+
return zod_1.z.NEVER;
|
|
668
|
+
}
|
|
669
|
+
return result.data;
|
|
670
|
+
});
|
|
671
|
+
return Object.assign(authoredSchema, { editorSchema });
|
|
273
672
|
}
|
|
274
673
|
//# sourceMappingURL=variableSchema.js.map
|