@featurevisor/core 3.11.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/lib/assess-distribution/index.js +9 -3
- package/lib/assess-distribution/index.js.map +1 -1
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.js +18 -11
- 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 +191 -74
- package/lib/linter/featureSchema.js +415 -214
- 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
|
@@ -33,129 +33,78 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveVariableOverrideValue = resolveVariableOverrideValue;
|
|
36
37
|
exports.getCustomDatafile = getCustomDatafile;
|
|
37
38
|
exports.buildDatafile = buildDatafile;
|
|
38
39
|
const fs = __importStar(require("fs"));
|
|
39
|
-
const
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const environments_1 = require("./environments");
|
|
42
|
+
const validation_1 = require("../cli/validation");
|
|
43
|
+
const inflate_1 = require("./inflate");
|
|
44
|
+
const removedGroups_1 = require("../config/removedGroups");
|
|
45
|
+
const dependencyDepth_1 = require("../linter/dependencyDepth");
|
|
46
|
+
const composition_1 = require("../datasource/composition");
|
|
47
|
+
const comparisonOperators_1 = require("../linter/comparisonOperators");
|
|
48
|
+
const datasource_1 = require("../datasource");
|
|
40
49
|
const hashes_1 = require("./hashes");
|
|
41
50
|
const traffic_1 = require("./traffic");
|
|
42
|
-
const getFeatureRanges_1 = require("./getFeatureRanges");
|
|
43
51
|
const mutateVariables_1 = require("./mutateVariables");
|
|
44
52
|
const mutator_1 = require("./mutator");
|
|
45
|
-
const
|
|
53
|
+
const mutationEntries_1 = require("./mutationEntries");
|
|
54
|
+
const conditions_1 = require("../datasource/conditions");
|
|
55
|
+
const dependencies_1 = require("../datasource/dependencies");
|
|
56
|
+
const variableOverrideProgram_1 = require("./variableOverrideProgram");
|
|
46
57
|
function buildFeatureVariableOverride(override, variableKey, variablesSchema, baseValue, projectConfig, segmentKeysUsedByTag, attributeKeysUsedByTag) {
|
|
47
58
|
const authoredValue = typeof override.mutate !== "undefined" ? override.mutate : override.value;
|
|
48
|
-
const value = (0, mutateVariables_1.resolveMutationsForSingleVariable)(variablesSchema, variableKey, authoredValue, baseValue);
|
|
49
|
-
const requiredFeatures = typeof override.requiredFeatures !== "undefined"
|
|
50
|
-
? (0, requiredFeatures_1.normalizeRequiredFeatures)(override.requiredFeatures)
|
|
51
|
-
: undefined;
|
|
59
|
+
const value = (0, mutateVariables_1.resolveMutationsForSingleVariable)(variablesSchema, variableKey, authoredValue, baseValue, typeof override.mutate !== "undefined");
|
|
52
60
|
const result = { value };
|
|
53
|
-
if (
|
|
61
|
+
if (override.key !== undefined)
|
|
54
62
|
result.key = override.key;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
result.conditions =
|
|
60
|
-
projectConfig.stringify && typeof override.conditions !== "string"
|
|
61
|
-
? JSON.stringify(override.conditions)
|
|
62
|
-
: override.conditions;
|
|
63
|
-
}
|
|
64
|
-
else if (typeof override.segments !== "undefined") {
|
|
65
|
-
(0, utils_1.extractSegmentKeysFromGroupSegments)(override.segments).forEach((segmentKey) => segmentKeysUsedByTag.add(segmentKey));
|
|
66
|
-
result.segments =
|
|
67
|
-
projectConfig.stringify && typeof override.segments !== "string"
|
|
68
|
-
? JSON.stringify(override.segments)
|
|
69
|
-
: override.segments;
|
|
70
|
-
}
|
|
63
|
+
const references = (0, conditions_1.getConditionReferences)(override.conditions);
|
|
64
|
+
references.attributes.forEach((key) => attributeKeysUsedByTag.add(key));
|
|
65
|
+
references.segments.forEach((key) => segmentKeysUsedByTag.add(key));
|
|
66
|
+
result.conditions = (0, conditions_1.compileConditions)(override.conditions, projectConfig.stringify);
|
|
71
67
|
return result;
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return [];
|
|
76
|
-
return Array.isArray(value) ? value : [value];
|
|
77
|
-
}
|
|
78
|
-
function combineConditions(inherited, own) {
|
|
79
|
-
const conditions = [...toArray(inherited), ...toArray(own)];
|
|
80
|
-
if (conditions.length === 0)
|
|
81
|
-
return undefined;
|
|
82
|
-
return conditions.length === 1 ? conditions[0] : conditions;
|
|
83
|
-
}
|
|
84
|
-
function combineSegments(inherited, own) {
|
|
85
|
-
if (typeof inherited === "undefined" && typeof own === "undefined")
|
|
86
|
-
return undefined;
|
|
87
|
-
const segments = [...toArray(inherited), ...toArray(own)].filter((segment) => segment !== "*");
|
|
88
|
-
if (segments.length === 0)
|
|
89
|
-
return "*";
|
|
90
|
-
return segments.length === 1 ? segments[0] : segments;
|
|
91
|
-
}
|
|
92
|
-
function resolveGlobalVariableOverrideValue(variable, override, baseValue) {
|
|
69
|
+
/** Apply one authored global override's value or mutations to a base value. */
|
|
70
|
+
function resolveVariableOverrideValue(variable, override, baseValue) {
|
|
93
71
|
if (typeof override.mutate === "undefined")
|
|
94
72
|
return override.value;
|
|
95
73
|
let value = JSON.parse(JSON.stringify(baseValue));
|
|
96
|
-
for (const [mutationKey, mutationValue] of
|
|
74
|
+
for (const [mutationKey, mutationValue] of (0, mutationEntries_1.mutationEntries)(override.mutate)) {
|
|
97
75
|
value = (0, mutator_1.mutate)(variable, value, mutationKey, mutationValue);
|
|
98
76
|
}
|
|
99
77
|
return value;
|
|
100
78
|
}
|
|
101
|
-
function
|
|
79
|
+
function buildVariableOverrides(parsedVariable, sourceOverrides, projectConfig, segmentKeysUsedByTag, attributeKeysUsedByTag) {
|
|
102
80
|
const result = [];
|
|
103
|
-
const visit = (overrides, baseValue, inheritedConditions,
|
|
81
|
+
const visit = (overrides, baseValue, inheritedConditions, inheritedPath) => {
|
|
104
82
|
for (const override of overrides || []) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
const value = resolveGlobalVariableOverrideValue(parsedVariable, override, baseValue);
|
|
112
|
-
const conditions = combineConditions(inheritedConditions, override.conditions);
|
|
113
|
-
const segments = combineSegments(inheritedSegments, override.segments);
|
|
114
|
-
const requiredFeatures = [
|
|
115
|
-
...inheritedRequirements,
|
|
116
|
-
...(0, requiredFeatures_1.normalizeRequiredFeatures)(override.requiredFeatures),
|
|
117
|
-
];
|
|
83
|
+
const references = (0, conditions_1.getConditionReferences)(override.conditions);
|
|
84
|
+
references.segments.forEach((key) => segmentKeysUsedByTag.add(key));
|
|
85
|
+
references.attributes.forEach((key) => attributeKeysUsedByTag.add(key));
|
|
86
|
+
const value = resolveVariableOverrideValue(parsedVariable, override, baseValue);
|
|
87
|
+
const conditions = (0, conditions_1.combineConditions)(inheritedConditions, override.conditions);
|
|
118
88
|
const keyPath = [...inheritedPath, override.key];
|
|
119
89
|
// Descendants are more specific than their parent fallback.
|
|
120
|
-
visit(override.overrides, value, conditions,
|
|
121
|
-
const built = {
|
|
122
|
-
key: override.key,
|
|
123
|
-
value,
|
|
124
|
-
};
|
|
90
|
+
visit(override.overrides, value, conditions, keyPath);
|
|
91
|
+
const built = { key: override.key, value };
|
|
125
92
|
if (keyPath.length > 1)
|
|
126
93
|
built.keyPath = keyPath;
|
|
127
|
-
|
|
128
|
-
built.requiredFeatures = requiredFeatures;
|
|
129
|
-
if (typeof conditions !== "undefined") {
|
|
130
|
-
built.conditions = projectConfig.stringify ? JSON.stringify(conditions) : conditions;
|
|
131
|
-
}
|
|
132
|
-
if (typeof segments !== "undefined") {
|
|
133
|
-
built.segments =
|
|
134
|
-
projectConfig.stringify && typeof segments !== "string"
|
|
135
|
-
? JSON.stringify(segments)
|
|
136
|
-
: segments;
|
|
137
|
-
}
|
|
94
|
+
built.conditions = (0, conditions_1.compileConditions)(conditions, projectConfig.stringify);
|
|
138
95
|
result.push(built);
|
|
139
96
|
}
|
|
140
97
|
};
|
|
141
|
-
visit(sourceOverrides, parsedVariable.defaultValue, undefined,
|
|
98
|
+
visit(sourceOverrides, parsedVariable.defaultValue, undefined, []);
|
|
142
99
|
return result;
|
|
143
100
|
}
|
|
144
101
|
async function getCustomDatafile(options) {
|
|
145
|
-
|
|
146
|
-
if (options.featureKey) {
|
|
147
|
-
const requiredChain = await options.datasource.getRequiredFeaturesChain(options.featureKey);
|
|
148
|
-
featuresToInclude = Array.from(requiredChain);
|
|
149
|
-
}
|
|
150
|
-
if (options.variableKey) {
|
|
151
|
-
const requiredChain = await options.datasource.getRequiredFeaturesChainForVariable(options.variableKey);
|
|
152
|
-
featuresToInclude = Array.from(new Set([...(featuresToInclude || []), ...requiredChain]));
|
|
153
|
-
}
|
|
102
|
+
(0, environments_1.resolveBuildEnvironments)(options.projectConfig, options.environment, true);
|
|
154
103
|
const existingState = await options.datasource.readState(options.environment);
|
|
155
104
|
const datafileContent = await buildDatafile(options.projectConfig, options.datasource, {
|
|
156
105
|
revision: options.revision || "tester",
|
|
157
106
|
environment: options.environment,
|
|
158
|
-
features:
|
|
107
|
+
features: options.featureKey ? [options.featureKey] : options.variableKey ? [] : undefined,
|
|
159
108
|
variables: options.variableKey ? [options.variableKey] : options.featureKey ? [] : undefined,
|
|
160
109
|
inflate: options.inflate,
|
|
161
110
|
tag: options.tag,
|
|
@@ -195,14 +144,82 @@ function matchesFeaturePatterns(featureKey, patterns) {
|
|
|
195
144
|
});
|
|
196
145
|
}
|
|
197
146
|
async function buildDatafile(projectConfig, datasource, options, existingState) {
|
|
147
|
+
await (0, removedGroups_1.assertNoLegacyDatasourceGroups)(datasource);
|
|
148
|
+
const inflation = (0, validation_1.parsePositiveIntegerOption)("--inflate", options.inflate, 1);
|
|
149
|
+
const disallowedOperators = projectConfig.disallowOperators || [];
|
|
198
150
|
const segmentKeysUsedByTag = new Set();
|
|
199
151
|
const attributeKeysUsedByTag = new Set();
|
|
200
|
-
const
|
|
152
|
+
const collectConditions = (conditions) => {
|
|
153
|
+
const references = (0, conditions_1.getConditionReferences)(conditions);
|
|
154
|
+
references.segments.forEach((key) => segmentKeysUsedByTag.add(key));
|
|
155
|
+
references.attributes.forEach((key) => attributeKeysUsedByTag.add(key));
|
|
156
|
+
};
|
|
157
|
+
const variableFiles = await datasource.listVariables();
|
|
158
|
+
const featureFiles = await datasource.listFeatures();
|
|
159
|
+
const parsedVariablesByKey = new Map();
|
|
160
|
+
const parsedFeaturesByKey = {};
|
|
161
|
+
const dependencyDatasource = {
|
|
162
|
+
listVariables: async () => variableFiles,
|
|
163
|
+
listFeatures: async () => featureFiles,
|
|
164
|
+
listSegments: () => datasource.listSegments(),
|
|
165
|
+
readSegment: (key) => datasource.readSegment(key),
|
|
166
|
+
readVariable: async (key) => {
|
|
167
|
+
const cached = parsedVariablesByKey.get(key);
|
|
168
|
+
if (cached)
|
|
169
|
+
return cached;
|
|
170
|
+
const value = await datasource.readVariable(key);
|
|
171
|
+
if (disallowedOperators.length > 0) {
|
|
172
|
+
const issue = (0, comparisonOperators_1.findDisallowedAuthoredOperators)(value, disallowedOperators)[0];
|
|
173
|
+
if (issue)
|
|
174
|
+
throw new Error(`Variable "${key}" at ${issue.path.join(".")}: operator "${issue.operator}" is disallowed by project configuration.`);
|
|
175
|
+
}
|
|
176
|
+
parsedVariablesByKey.set(key, value);
|
|
177
|
+
return value;
|
|
178
|
+
},
|
|
179
|
+
readFeature: async (key) => {
|
|
180
|
+
if (parsedFeaturesByKey[key])
|
|
181
|
+
return parsedFeaturesByKey[key];
|
|
182
|
+
const value = await datasource.readFeature(key);
|
|
183
|
+
if (Object.prototype.hasOwnProperty.call(value, "required")) {
|
|
184
|
+
throw new Error(`Feature "${key}" at required: legacy feature \`required\` was removed. Use \`conditions\` and rename \`{ key }\` to \`{ feature }\`.`);
|
|
185
|
+
}
|
|
186
|
+
if (disallowedOperators.length > 0) {
|
|
187
|
+
const issue = (0, comparisonOperators_1.findDisallowedAuthoredOperators)(value, disallowedOperators)[0];
|
|
188
|
+
if (issue)
|
|
189
|
+
throw new Error(`Feature "${key}" at ${issue.path.join(".")}: operator "${issue.operator}" is disallowed by project configuration.`);
|
|
190
|
+
}
|
|
191
|
+
parsedFeaturesByKey[key] = value;
|
|
192
|
+
return value;
|
|
193
|
+
},
|
|
194
|
+
};
|
|
201
195
|
const parsedVariables = [];
|
|
196
|
+
const dependencyGraph = options.dependencyGraph || (await (0, dependencies_1.buildDependencyGraph)(dependencyDatasource));
|
|
197
|
+
// Cycles are unsafe at runtime even when a build deliberately skips lint.
|
|
198
|
+
// Reuse the acquired graph, including a caller's shared graph, before allocation.
|
|
199
|
+
const dependencyCycles = await (0, dependencies_1.findDependencyCycles)(dependencyDatasource, dependencyGraph);
|
|
200
|
+
if (dependencyCycles.length)
|
|
201
|
+
throw dependencyCycles[0];
|
|
202
|
+
// SDKs fail every evaluation of a chain at the runtime limit, so it is never publishable.
|
|
203
|
+
const tooDeep = (0, dependencyDepth_1.findDeepDependencyChains)(dependencyGraph, dependencyDepth_1.DEPENDENCY_HANDOFF_LIMIT)[0];
|
|
204
|
+
if (tooDeep)
|
|
205
|
+
throw new Error(`Evaluation needs ${tooDeep.handoffs} dependency handoffs, more than the runtime limit of ${dependencyDepth_1.DEPENDENCY_HANDOFF_LIMIT}: ${(0, dependencyDepth_1.describeDependencyChain)(tooDeep.nodes)}.`);
|
|
206
|
+
let policySegmentFiles;
|
|
207
|
+
const policySegments = new Map();
|
|
208
|
+
if (disallowedOperators.length > 0) {
|
|
209
|
+
policySegmentFiles = await datasource.listSegments();
|
|
210
|
+
for (const key of policySegmentFiles) {
|
|
211
|
+
const segment = await datasource.readSegment(key);
|
|
212
|
+
const issue = (0, comparisonOperators_1.findDisallowedAuthoredOperators)(segment, disallowedOperators)[0];
|
|
213
|
+
if (issue)
|
|
214
|
+
throw new Error(`Segment "${key}" at ${issue.path.join(".")}: operator "${issue.operator}" is disallowed by project configuration.`);
|
|
215
|
+
policySegments.set(key, segment);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
202
218
|
const featureKeysRequiredByVariables = new Set();
|
|
203
|
-
const
|
|
219
|
+
const variableKeysRequiredStructurally = new Set();
|
|
220
|
+
const selectedVariableRoots = [];
|
|
204
221
|
for (const variableKey of variableFiles) {
|
|
205
|
-
const parsedVariable = await
|
|
222
|
+
const parsedVariable = await dependencyDatasource.readVariable(variableKey);
|
|
206
223
|
const variableTags = parsedVariable.tags || [];
|
|
207
224
|
if (parsedVariable.archived === true)
|
|
208
225
|
continue;
|
|
@@ -219,8 +236,37 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
219
236
|
if (matchesFeaturePatterns(variableKey, options.excludeVariables))
|
|
220
237
|
continue;
|
|
221
238
|
parsedVariables.push({ key: variableKey, value: parsedVariable });
|
|
222
|
-
|
|
223
|
-
|
|
239
|
+
selectedVariableRoots.push((0, dependencies_1.variableNode)(variableKey));
|
|
240
|
+
}
|
|
241
|
+
if (selectedVariableRoots.length > 0) {
|
|
242
|
+
const structural = await (0, dependencies_1.collectDependencyClosure)(datasource, selectedVariableRoots, {
|
|
243
|
+
graph: dependencyGraph,
|
|
244
|
+
});
|
|
245
|
+
structural.segments.forEach((key) => segmentKeysUsedByTag.add(key));
|
|
246
|
+
structural.features.forEach((key) => featureKeysRequiredByVariables.add(key));
|
|
247
|
+
structural.variables.forEach((key) => variableKeysRequiredStructurally.add(key));
|
|
248
|
+
}
|
|
249
|
+
for (const variableKey of variableKeysRequiredStructurally) {
|
|
250
|
+
if (parsedVariables.some((entry) => entry.key === variableKey))
|
|
251
|
+
continue;
|
|
252
|
+
if (await datasource.variableExists(variableKey)) {
|
|
253
|
+
parsedVariables.push({
|
|
254
|
+
key: variableKey,
|
|
255
|
+
value: await dependencyDatasource.readVariable(variableKey),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (disallowedOperators.length > 0) {
|
|
260
|
+
for (const key of (await datasource.listTests?.()) || []) {
|
|
261
|
+
const issue = (0, comparisonOperators_1.findDisallowedCheckOperators)(await datasource.readTest(key), disallowedOperators)[0];
|
|
262
|
+
if (issue)
|
|
263
|
+
throw new Error(`Test "${key}" at ${issue.path.join(".")}: operator "${issue.operator}" is disallowed by project configuration.`);
|
|
264
|
+
}
|
|
265
|
+
for (const key of (await datasource.listScenarios?.()) || []) {
|
|
266
|
+
const issue = (0, comparisonOperators_1.findDisallowedCheckOperators)(await datasource.readScenario(key), disallowedOperators)[0];
|
|
267
|
+
if (issue)
|
|
268
|
+
throw new Error(`Scenario "${key}" at ${issue.path.join(".")}: operator "${issue.operator}" is disallowed by project configuration.`);
|
|
269
|
+
}
|
|
224
270
|
}
|
|
225
271
|
// Load schemas for resolving variable schema references in features
|
|
226
272
|
const schemaKeys = await datasource.listSchemas();
|
|
@@ -234,21 +280,23 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
234
280
|
}
|
|
235
281
|
}
|
|
236
282
|
// features
|
|
237
|
-
|
|
283
|
+
let features = [];
|
|
238
284
|
const featuresDirectory = projectConfig.featuresDirectoryPath;
|
|
239
285
|
if (fs.existsSync(featuresDirectory)) {
|
|
240
|
-
const featureFiles = await datasource.listFeatures();
|
|
241
|
-
const parsedFeaturesByKey = {};
|
|
242
286
|
for (const featureKey of featureFiles) {
|
|
243
|
-
parsedFeaturesByKey[featureKey] = await
|
|
287
|
+
parsedFeaturesByKey[featureKey] = await dependencyDatasource.readFeature(featureKey);
|
|
244
288
|
}
|
|
245
289
|
const featureKeysRequiredByFeatures = new Set();
|
|
246
290
|
const hasFeatureSelection = Boolean(options.tag ||
|
|
247
291
|
options.tags ||
|
|
248
292
|
options.includeFeatures ||
|
|
249
293
|
options.excludeFeatures ||
|
|
250
|
-
options.features
|
|
294
|
+
options.features ||
|
|
295
|
+
options.includeVariables ||
|
|
296
|
+
options.excludeVariables ||
|
|
297
|
+
options.variables);
|
|
251
298
|
if (hasFeatureSelection) {
|
|
299
|
+
const selectedFeatureRoots = [];
|
|
252
300
|
for (const featureKey of featureFiles) {
|
|
253
301
|
const parsedFeature = parsedFeaturesByKey[featureKey];
|
|
254
302
|
if (parsedFeature.archived === true)
|
|
@@ -279,8 +327,23 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
279
327
|
if (options.tags && matchesBuildTags(expose, options.tags) === false)
|
|
280
328
|
continue;
|
|
281
329
|
}
|
|
282
|
-
|
|
283
|
-
|
|
330
|
+
selectedFeatureRoots.push((0, dependencies_1.featureFlagNode)(featureKey));
|
|
331
|
+
}
|
|
332
|
+
const structural = await (0, dependencies_1.collectDependencyClosure)(datasource, selectedFeatureRoots, {
|
|
333
|
+
graph: dependencyGraph,
|
|
334
|
+
});
|
|
335
|
+
structural.segments.forEach((key) => segmentKeysUsedByTag.add(key));
|
|
336
|
+
structural.features.forEach((key) => featureKeysRequiredByFeatures.add(key));
|
|
337
|
+
structural.variables.forEach((key) => variableKeysRequiredStructurally.add(key));
|
|
338
|
+
}
|
|
339
|
+
for (const variableKey of variableKeysRequiredStructurally) {
|
|
340
|
+
if (parsedVariables.some((entry) => entry.key === variableKey))
|
|
341
|
+
continue;
|
|
342
|
+
if (await datasource.variableExists(variableKey)) {
|
|
343
|
+
parsedVariables.push({
|
|
344
|
+
key: variableKey,
|
|
345
|
+
value: await dependencyDatasource.readVariable(variableKey),
|
|
346
|
+
});
|
|
284
347
|
}
|
|
285
348
|
}
|
|
286
349
|
for (const featureKey of featureFiles) {
|
|
@@ -316,7 +379,7 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
316
379
|
let force;
|
|
317
380
|
if (options.environment) {
|
|
318
381
|
expose = parsedFeature.expose?.[options.environment];
|
|
319
|
-
rules = parsedFeature.rules?.[options.environment];
|
|
382
|
+
rules = (parsedFeature.rules?.[options.environment] || []);
|
|
320
383
|
force = parsedFeature.force?.[options.environment];
|
|
321
384
|
}
|
|
322
385
|
else {
|
|
@@ -336,32 +399,14 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
336
399
|
continue;
|
|
337
400
|
}
|
|
338
401
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (parsedRule.variableOverrides) {
|
|
343
|
-
for (const variableOverrides of Object.values(parsedRule.variableOverrides)) {
|
|
344
|
-
for (const override of variableOverrides) {
|
|
345
|
-
if (typeof override.conditions !== "undefined") {
|
|
346
|
-
const extractedAttributeKeys = (0, utils_1.extractAttributeKeysFromConditions)(override.conditions);
|
|
347
|
-
extractedAttributeKeys.forEach((attributeKey) => attributeKeysUsedByTag.add(attributeKey));
|
|
348
|
-
}
|
|
349
|
-
if (typeof override.segments !== "undefined") {
|
|
350
|
-
const extractedOverrideSegmentKeys = (0, utils_1.extractSegmentKeysFromGroupSegments)(override.segments);
|
|
351
|
-
extractedOverrideSegmentKeys.forEach((segmentKey) => segmentKeysUsedByTag.add(segmentKey));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
402
|
+
collectConditions(parsedFeature.conditions);
|
|
403
|
+
for (const parsedRule of rules)
|
|
404
|
+
collectConditions(parsedRule.conditions);
|
|
357
405
|
const feature = {
|
|
358
406
|
key: featureKey,
|
|
359
407
|
deprecated: parsedFeature.deprecated === true ? true : undefined,
|
|
360
408
|
bucketBy: parsedFeature.bucketBy || projectConfig.defaultBucketBy,
|
|
361
|
-
|
|
362
|
-
requiredFeatures: parsedFeature.requiredFeatures
|
|
363
|
-
? (0, requiredFeatures_1.normalizeRequiredFeatures)(parsedFeature.requiredFeatures)
|
|
364
|
-
: undefined,
|
|
409
|
+
conditions: (0, conditions_1.compileConditions)(parsedFeature.conditions, projectConfig.stringify),
|
|
365
410
|
disabledVariationValue: parsedFeature.disabledVariationValue,
|
|
366
411
|
variations: Array.isArray(parsedFeature.variations)
|
|
367
412
|
? parsedFeature.variations.map((variation) => {
|
|
@@ -369,7 +414,9 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
369
414
|
value: variation.value,
|
|
370
415
|
weight: variation.weight, // @NOTE: added so state files can maintain weight info, but datafiles don't need this. find a way to remove it from datafiles later
|
|
371
416
|
variables: (0, mutateVariables_1.resolveMutationsForMultipleVariables)(parsedFeature.variablesSchema, variation.variables),
|
|
372
|
-
|
|
417
|
+
// A new object, filled below in the same key order. Writing into the
|
|
418
|
+
// authored one would change the input for every later Target build.
|
|
419
|
+
variableOverrides: variation.variableOverrides ? {} : variation.variableOverrides,
|
|
373
420
|
};
|
|
374
421
|
if (variation.variableOverrides) {
|
|
375
422
|
const variableOverrides = variation.variableOverrides;
|
|
@@ -384,7 +431,10 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
384
431
|
return mappedVariation;
|
|
385
432
|
})
|
|
386
433
|
: undefined,
|
|
387
|
-
traffic: (0, traffic_1.getTraffic)(parsedFeature.variations, rules, existingState.features[featureKey],
|
|
434
|
+
traffic: (0, traffic_1.getTraffic)(parsedFeature.variations, rules, existingState.features[featureKey], featureKey, projectConfig.adapter === datasource_1.FilesystemAdapter ||
|
|
435
|
+
projectConfig.adapter?.prototype instanceof datasource_1.FilesystemAdapter
|
|
436
|
+
? path.relative(datasource.getRootDirectoryPath() || process.cwd(), (0, datasource_1.getExistingStateFilePath)(projectConfig, options.environment))
|
|
437
|
+
: undefined).map((t) => {
|
|
388
438
|
const resolvedVariables = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(parsedFeature.variablesSchema, t.variables);
|
|
389
439
|
let resolvedVariableOverrides = t.variableOverrides;
|
|
390
440
|
if (t.variableOverrides) {
|
|
@@ -400,12 +450,9 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
400
450
|
...t,
|
|
401
451
|
variables: resolvedVariables,
|
|
402
452
|
variableOverrides: resolvedVariableOverrides,
|
|
403
|
-
|
|
404
|
-
? JSON.stringify(t.segments)
|
|
405
|
-
: t.segments,
|
|
453
|
+
conditions: (0, conditions_1.compileConditions)(t.conditions, projectConfig.stringify),
|
|
406
454
|
};
|
|
407
455
|
}),
|
|
408
|
-
ranges: featureRanges.get(featureKey) || undefined,
|
|
409
456
|
};
|
|
410
457
|
// update state in memory, so that next datafile build can use it (in case it contains the same feature)
|
|
411
458
|
existingState.features[featureKey] = {
|
|
@@ -431,9 +478,6 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
431
478
|
};
|
|
432
479
|
}),
|
|
433
480
|
};
|
|
434
|
-
if (featureIsInGroup[featureKey] === true) {
|
|
435
|
-
feature.ranges = featureRanges.get(featureKey);
|
|
436
|
-
}
|
|
437
481
|
if (parsedFeature.variablesSchema) {
|
|
438
482
|
const variableKeys = Object.keys(parsedFeature.variablesSchema);
|
|
439
483
|
feature.variablesSchema = {};
|
|
@@ -453,21 +497,16 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
453
497
|
}
|
|
454
498
|
}
|
|
455
499
|
if (force) {
|
|
456
|
-
feature.force = force.map((
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
f.conditions =
|
|
467
|
-
typeof f.conditions !== "string" && projectConfig.stringify
|
|
468
|
-
? JSON.stringify(f.conditions)
|
|
469
|
-
: f.conditions;
|
|
470
|
-
}
|
|
500
|
+
feature.force = force.map((authored) => {
|
|
501
|
+
// Assign to a copy. The authored entry is input to every Target and environment.
|
|
502
|
+
const f = {
|
|
503
|
+
conditions: authored.conditions,
|
|
504
|
+
enabled: authored.enabled,
|
|
505
|
+
variation: authored.variation,
|
|
506
|
+
variables: authored.variables,
|
|
507
|
+
};
|
|
508
|
+
collectConditions(f.conditions);
|
|
509
|
+
f.conditions = (0, conditions_1.compileConditions)(f.conditions, projectConfig.stringify);
|
|
471
510
|
if (f.variables) {
|
|
472
511
|
f.variables = (0, mutateVariables_1.resolveMutationsForMultipleVariables)(parsedFeature.variablesSchema, f.variables);
|
|
473
512
|
}
|
|
@@ -478,15 +517,109 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
478
517
|
}
|
|
479
518
|
}
|
|
480
519
|
// global variables
|
|
481
|
-
const
|
|
520
|
+
const includedFeatureKeys = new Set(features.map((feature) => feature.key));
|
|
521
|
+
const unavailableCompositionDependency = (0, dependencies_1.findUnavailableCompositionDependency)(dependencyGraph, parsedVariables
|
|
522
|
+
.filter(({ value }) => (0, composition_1.isComposedVariable)(value))
|
|
523
|
+
.map(({ key }) => (0, dependencies_1.variableNode)(key)), (node) => {
|
|
524
|
+
if (node[0] === "variable") {
|
|
525
|
+
const definition = parsedVariablesByKey.get(node[1]);
|
|
526
|
+
if (!definition)
|
|
527
|
+
return `variable "${node[1]}" has a missing definition`;
|
|
528
|
+
if (definition.archived)
|
|
529
|
+
return `variable "${node[1]}" is archived`;
|
|
530
|
+
}
|
|
531
|
+
else if (node[0] !== "segment") {
|
|
532
|
+
if (!includedFeatureKeys.has(node[1])) {
|
|
533
|
+
const definition = parsedFeaturesByKey[node[1]];
|
|
534
|
+
if (!definition)
|
|
535
|
+
return `feature "${node[1]}" has a missing definition`;
|
|
536
|
+
if (definition.archived)
|
|
537
|
+
return `feature "${node[1]}" is archived`;
|
|
538
|
+
return `feature "${node[1]}" is excluded by exposure`;
|
|
539
|
+
}
|
|
540
|
+
if (node[0] === "feature-variable" &&
|
|
541
|
+
!Object.prototype.hasOwnProperty.call(parsedFeaturesByKey[node[1]]?.variablesSchema || {}, node[2]))
|
|
542
|
+
return `feature "${node[1]}" references missing variable "${node[1]}:${node[2]}"`;
|
|
543
|
+
}
|
|
544
|
+
return undefined;
|
|
545
|
+
});
|
|
546
|
+
if (unavailableCompositionDependency) {
|
|
547
|
+
const { root, alias, nodes, reason } = unavailableCompositionDependency;
|
|
548
|
+
throw new Error(`Composition ${JSON.stringify(JSON.parse(root)[1])}${alias === undefined ? "" : ` property ${JSON.stringify(alias)}`} cannot include its dependency in Target "${options.compositionTargetKey || "custom"}" and environment "${options.environment || "none"}" with filters ${JSON.stringify({ tag: options.tag, tags: options.tags, includeFeatures: options.includeFeatures, excludeFeatures: options.excludeFeatures, includeVariables: options.includeVariables, excludeVariables: options.excludeVariables, features: options.features, variables: options.variables })}. Dependency chain ${(0, dependencies_1.readableDependencyChain)(dependencyGraph, nodes)} is unavailable: ${reason}.`);
|
|
549
|
+
}
|
|
550
|
+
let variables = [];
|
|
551
|
+
const compositionTypes = new Map();
|
|
552
|
+
const compositionType = (variable) => {
|
|
553
|
+
const seen = new Set();
|
|
554
|
+
let type = compositionTypes.get(variable);
|
|
555
|
+
while (type === undefined && typeof variable.compose === "string") {
|
|
556
|
+
if (seen.has(variable))
|
|
557
|
+
throw new Error("circular dependency found through compose");
|
|
558
|
+
seen.add(variable);
|
|
559
|
+
variable = parsedVariablesByKey.get(variable.compose);
|
|
560
|
+
type = compositionTypes.get(variable);
|
|
561
|
+
}
|
|
562
|
+
if (type === undefined) {
|
|
563
|
+
if ((0, composition_1.isComposedVariable)(variable))
|
|
564
|
+
type = "object";
|
|
565
|
+
else {
|
|
566
|
+
let schema = variable;
|
|
567
|
+
const seenSchemas = new Set();
|
|
568
|
+
while (schema?.schema) {
|
|
569
|
+
if (seenSchemas.has(schema.schema))
|
|
570
|
+
throw new Error("circular schema reference found");
|
|
571
|
+
seenSchemas.add(schema.schema);
|
|
572
|
+
schema = schemasByKey[schema.schema];
|
|
573
|
+
}
|
|
574
|
+
type = (schema?.type || "string");
|
|
575
|
+
}
|
|
576
|
+
compositionTypes.set(variable, type);
|
|
577
|
+
}
|
|
578
|
+
for (const alias of seen)
|
|
579
|
+
compositionTypes.set(alias, type);
|
|
580
|
+
return type;
|
|
581
|
+
};
|
|
482
582
|
for (const { key, value: parsedVariable } of parsedVariables) {
|
|
483
|
-
const resolvedSchema = parsedVariable.schema
|
|
484
|
-
? schemasByKey[parsedVariable.schema]
|
|
485
|
-
: parsedVariable;
|
|
486
583
|
const sourceOverrides = options.environment
|
|
487
584
|
? parsedVariable.overrides?.[options.environment]
|
|
488
585
|
: parsedVariable.overrides;
|
|
489
|
-
|
|
586
|
+
// A composition has no static starting value, even without continuation.
|
|
587
|
+
const useProgram = ((0, composition_1.isComposedVariable)(parsedVariable) && !!sourceOverrides?.length) ||
|
|
588
|
+
(0, variableOverrideProgram_1.hasContinuingVariableOverrides)(sourceOverrides) ||
|
|
589
|
+
(projectConfig.precomputeMutations === false &&
|
|
590
|
+
(0, variableOverrideProgram_1.hasVariableOverrideMutations)(sourceOverrides));
|
|
591
|
+
const program = useProgram
|
|
592
|
+
? (0, variableOverrideProgram_1.buildVariableOverrideProgram)(sourceOverrides, projectConfig.stringify)
|
|
593
|
+
: undefined;
|
|
594
|
+
collectConditions(parsedVariable.conditions);
|
|
595
|
+
for (const step of program || [])
|
|
596
|
+
collectConditions(step.conditions);
|
|
597
|
+
if ((0, composition_1.isComposedVariable)(parsedVariable)) {
|
|
598
|
+
const definition = parsedVariable.compose;
|
|
599
|
+
const compose = typeof definition === "string"
|
|
600
|
+
? definition
|
|
601
|
+
: Object.keys(definition)
|
|
602
|
+
.sort()
|
|
603
|
+
.map((alias) => ({ key: alias, ...definition[alias] }));
|
|
604
|
+
variables.push({
|
|
605
|
+
key,
|
|
606
|
+
value: {
|
|
607
|
+
type: compositionType(parsedVariable),
|
|
608
|
+
compose,
|
|
609
|
+
conditions: (0, conditions_1.compileConditions)(parsedVariable.conditions, projectConfig.stringify),
|
|
610
|
+
disabledValue: parsedVariable.disabledValue,
|
|
611
|
+
...(program ? { overrideProgram: program } : {}),
|
|
612
|
+
...(parsedVariable.deprecated ? { deprecated: true } : {}),
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
const resolvedSchema = parsedVariable.schema
|
|
618
|
+
? schemasByKey[parsedVariable.schema]
|
|
619
|
+
: parsedVariable;
|
|
620
|
+
const overrides = program
|
|
621
|
+
? []
|
|
622
|
+
: buildVariableOverrides(parsedVariable, sourceOverrides, projectConfig, segmentKeysUsedByTag, attributeKeysUsedByTag);
|
|
490
623
|
variables.push({
|
|
491
624
|
key,
|
|
492
625
|
value: {
|
|
@@ -498,91 +631,63 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
498
631
|
defaultValue: parsedVariable.defaultValue,
|
|
499
632
|
disabledValue: parsedVariable.disabledValue,
|
|
500
633
|
useDefaultWhenDisabled: parsedVariable.useDefaultWhenDisabled === true ? true : undefined,
|
|
501
|
-
|
|
502
|
-
? (0, requiredFeatures_1.normalizeRequiredFeatures)(parsedVariable.requiredFeatures)
|
|
503
|
-
: undefined,
|
|
634
|
+
conditions: (0, conditions_1.compileConditions)(parsedVariable.conditions, projectConfig.stringify),
|
|
504
635
|
overrides: overrides.length > 0 ? overrides : undefined,
|
|
636
|
+
...(program ? { overrideProgram: program } : {}),
|
|
505
637
|
},
|
|
506
638
|
});
|
|
507
639
|
}
|
|
508
640
|
// segments
|
|
509
|
-
|
|
641
|
+
let segments = [];
|
|
510
642
|
const segmentsDirectory = projectConfig.segmentsDirectoryPath;
|
|
511
643
|
if (fs.existsSync(segmentsDirectory)) {
|
|
512
|
-
const segmentFiles = await datasource.listSegments();
|
|
644
|
+
const segmentFiles = policySegmentFiles || (await datasource.listSegments());
|
|
645
|
+
const pending = [...segmentKeysUsedByTag];
|
|
646
|
+
const visited = new Set();
|
|
647
|
+
while (pending.length) {
|
|
648
|
+
const key = pending.pop();
|
|
649
|
+
if (visited.has(key))
|
|
650
|
+
continue;
|
|
651
|
+
visited.add(key);
|
|
652
|
+
if (!segmentFiles.includes(key))
|
|
653
|
+
continue;
|
|
654
|
+
const segment = policySegments.get(key) || (await datasource.readSegment(key));
|
|
655
|
+
policySegments.set(key, segment);
|
|
656
|
+
for (const ref of (0, conditions_1.getConditionReferences)(segment.conditions).segments) {
|
|
657
|
+
segmentKeysUsedByTag.add(ref);
|
|
658
|
+
pending.push(ref);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
513
661
|
for (const segmentKey of segmentFiles) {
|
|
514
|
-
const parsedSegment = await datasource.readSegment(segmentKey);
|
|
662
|
+
const parsedSegment = policySegments.get(segmentKey) || (await datasource.readSegment(segmentKey));
|
|
515
663
|
if (parsedSegment.archived === true) {
|
|
516
664
|
continue;
|
|
517
665
|
}
|
|
518
666
|
if (segmentKeysUsedByTag.has(segmentKey) === false) {
|
|
519
667
|
continue;
|
|
520
668
|
}
|
|
521
|
-
|
|
522
|
-
extractedAttributeKeys.forEach((attributeKey) => attributeKeysUsedByTag.add(attributeKey));
|
|
669
|
+
collectConditions(parsedSegment.conditions);
|
|
523
670
|
const segment = {
|
|
524
671
|
key: segmentKey,
|
|
525
|
-
conditions:
|
|
526
|
-
? JSON.stringify(parsedSegment.conditions)
|
|
527
|
-
: parsedSegment.conditions,
|
|
672
|
+
conditions: (0, conditions_1.compileConditions)(parsedSegment.conditions, projectConfig.stringify),
|
|
528
673
|
};
|
|
529
674
|
segments.push(segment);
|
|
530
675
|
}
|
|
531
676
|
}
|
|
532
|
-
//
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
for (const attributeKey of attributeFiles) {
|
|
538
|
-
const parsedAttribute = await datasource.readAttribute(attributeKey);
|
|
539
|
-
if (parsedAttribute.archived === true) {
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
if (attributeKeysUsedByTag.has(attributeKey) === false) {
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
const attribute = {
|
|
546
|
-
key: attributeKey,
|
|
547
|
-
type: parsedAttribute.type,
|
|
548
|
-
};
|
|
549
|
-
attributes.push(attribute);
|
|
677
|
+
// Attributes are not part of datafiles. Reading each one still rejects invalid
|
|
678
|
+
// attribute files during build, including attributes nothing uses.
|
|
679
|
+
if (fs.existsSync(projectConfig.attributesDirectoryPath)) {
|
|
680
|
+
for (const attributeKey of await datasource.listAttributes()) {
|
|
681
|
+
await datasource.readAttribute(attributeKey);
|
|
550
682
|
}
|
|
551
683
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const allAttributeKeys = attributes.map((a) => a.key);
|
|
557
|
-
for (let i = 0; i < options.inflate - 1; i++) {
|
|
558
|
-
// feature
|
|
559
|
-
for (const featureKey of allFeatureKeys) {
|
|
560
|
-
const originalFeature = features.find((f) => f.key === featureKey);
|
|
561
|
-
features.unshift({
|
|
562
|
-
...originalFeature,
|
|
563
|
-
key: `${originalFeature.key}-${i}`,
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
// segment
|
|
567
|
-
for (const segmentKey of allSegmentKeys) {
|
|
568
|
-
const originalSegment = segments.find((s) => s.key === segmentKey);
|
|
569
|
-
segments.unshift({
|
|
570
|
-
...originalSegment,
|
|
571
|
-
key: `${originalSegment.key}-${i}`,
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
// attribute
|
|
575
|
-
for (const attributeKey of allAttributeKeys) {
|
|
576
|
-
const originalAttribute = attributes.find((a) => a.key === attributeKey);
|
|
577
|
-
attributes.unshift({
|
|
578
|
-
...originalAttribute,
|
|
579
|
-
key: `${originalAttribute.key}-${i}`,
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
684
|
+
if (inflation > 1) {
|
|
685
|
+
features = (0, inflate_1.inflateEntries)(features, inflation);
|
|
686
|
+
segments = (0, inflate_1.inflateEntries)(segments, inflation);
|
|
687
|
+
variables = (0, inflate_1.inflateEntries)(variables, inflation);
|
|
583
688
|
}
|
|
584
689
|
const datafileContent = {
|
|
585
|
-
schemaVersion: "
|
|
690
|
+
schemaVersion: "4",
|
|
586
691
|
featurevisorVersion: options.featurevisorVersion,
|
|
587
692
|
revision: options.revision,
|
|
588
693
|
segments: {},
|
|
@@ -619,19 +724,14 @@ async function buildDatafile(projectConfig, datasource, options, existingState)
|
|
|
619
724
|
acc[variable.key] = variable.value;
|
|
620
725
|
return acc;
|
|
621
726
|
}, {});
|
|
622
|
-
//
|
|
623
|
-
|
|
727
|
+
// Hash the complete graph, including feature dependencies on global variables.
|
|
728
|
+
(0, hashes_1.refreshDatafileHashes)(datafileContent);
|
|
624
729
|
Object.keys(datafileContent.features).forEach((featureKey) => {
|
|
625
|
-
const hash = (0, hashes_1.generateHashForFeature)(featureKey, datafileContent.features, segmentHashes);
|
|
626
|
-
datafileContent.features[featureKey].hash = hash;
|
|
627
730
|
// check needed to support --inflate option
|
|
628
731
|
if (existingState.features[featureKey]) {
|
|
629
|
-
existingState.features[featureKey].hash = hash;
|
|
732
|
+
existingState.features[featureKey].hash = datafileContent.features[featureKey].hash;
|
|
630
733
|
}
|
|
631
734
|
});
|
|
632
|
-
Object.keys(datafileContent.variables).forEach((variableKey) => {
|
|
633
|
-
datafileContent.variables[variableKey].hash = (0, hashes_1.generateHashForVariable)(variableKey, datafileContent.variables, datafileContent.features, segmentHashes);
|
|
634
|
-
});
|
|
635
735
|
if (options.revisionFromHash) {
|
|
636
736
|
const datafileHash = (0, hashes_1.generateHashForDatafile)(datafileContent);
|
|
637
737
|
datafileContent.revision = `${datafileHash}`;
|