@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
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchesSchemaValue = matchesSchemaValue;
|
|
3
4
|
exports.getConditionsZodSchema = getConditionsZodSchema;
|
|
4
5
|
const zod_1 = require("zod");
|
|
6
|
+
const sdk_1 = require("@featurevisor/sdk");
|
|
7
|
+
const regexSafety_1 = require("./regexSafety");
|
|
8
|
+
const schemaFormats_1 = require("./schemaFormats");
|
|
5
9
|
const zodHelpers_1 = require("./zodHelpers");
|
|
10
|
+
const diagnostics_1 = require("./diagnostics");
|
|
11
|
+
const comparisonOperators_1 = require("./comparisonOperators");
|
|
12
|
+
const requiredFeaturesSchema_1 = require("./requiredFeaturesSchema");
|
|
13
|
+
const requiredVariablesSchema_1 = require("./requiredVariablesSchema");
|
|
6
14
|
const commonOperators = ["equals", "notEquals"];
|
|
7
15
|
const numericOperators = ["greaterThan", "greaterThanOrEquals", "lessThan", "lessThanOrEquals"];
|
|
8
16
|
const stringOperators = [
|
|
@@ -24,10 +32,12 @@ const semverOperators = [
|
|
|
24
32
|
const dateOperators = ["before", "after"];
|
|
25
33
|
const arrayMembershipOperators = ["in", "notIn"];
|
|
26
34
|
const arrayOperators = ["includes", "notIncludes"];
|
|
27
|
-
const
|
|
28
|
-
const
|
|
35
|
+
const arrayListOperators = ["includesAny", "notIncludesAny"];
|
|
36
|
+
const emptinessOperators = ["empty", "notEmpty"];
|
|
37
|
+
const operatorsWithoutValue = ["exists", "notExists", "isNull", "notNull", ...emptinessOperators];
|
|
38
|
+
const emptinessTypes = ["primitive", "string", "semver", "date-time", "array", "object", "json"];
|
|
29
39
|
function isIsoDateString(value) {
|
|
30
|
-
return
|
|
40
|
+
return (0, sdk_1.getPortableTimestamp)(value) !== null;
|
|
31
41
|
}
|
|
32
42
|
function isPrimitiveAttributeValue(value) {
|
|
33
43
|
return (value === null ||
|
|
@@ -90,7 +100,7 @@ function getLeafType(resolvedLeaf) {
|
|
|
90
100
|
if (resolvedLeaf.kind === "flat-object-property" || resolvedLeaf.kind === "flat-array-item") {
|
|
91
101
|
return "primitive";
|
|
92
102
|
}
|
|
93
|
-
return
|
|
103
|
+
return (0, schemaFormats_1.getSchemaKind)(resolvedLeaf.schema);
|
|
94
104
|
}
|
|
95
105
|
function getLeafTypes(resolvedLeaf, schemasByKey) {
|
|
96
106
|
if (resolvedLeaf.kind === "flat-object-property" || resolvedLeaf.kind === "flat-array-item") {
|
|
@@ -100,11 +110,14 @@ function getLeafTypes(resolvedLeaf, schemasByKey) {
|
|
|
100
110
|
if (resolved.oneOf && Array.isArray(resolved.oneOf) && resolved.oneOf.length > 0) {
|
|
101
111
|
return Array.from(new Set(resolved.oneOf.flatMap((branch) => getLeafTypes({ kind: "schema", schema: branch }, schemasByKey))));
|
|
102
112
|
}
|
|
103
|
-
|
|
113
|
+
const kind = (0, schemaFormats_1.getSchemaKind)(resolved);
|
|
114
|
+
return kind ? [kind] : [];
|
|
104
115
|
}
|
|
105
116
|
function resolveAttributePath(attributePath, attributesByKey, schemasByKey) {
|
|
106
117
|
const [rootKey, ...rest] = attributePath.split(".");
|
|
107
|
-
const rootAttribute = attributesByKey
|
|
118
|
+
const rootAttribute = Object.prototype.hasOwnProperty.call(attributesByKey, rootKey)
|
|
119
|
+
? attributesByKey[rootKey]
|
|
120
|
+
: undefined;
|
|
108
121
|
if (!rootAttribute) {
|
|
109
122
|
return null;
|
|
110
123
|
}
|
|
@@ -124,7 +137,9 @@ function resolveAttributePath(attributePath, attributesByKey, schemasByKey) {
|
|
|
124
137
|
}
|
|
125
138
|
const properties = "properties" in current ? current.properties : undefined;
|
|
126
139
|
const additionalProperties = "additionalProperties" in current ? current.additionalProperties : undefined;
|
|
127
|
-
if (properties &&
|
|
140
|
+
if (properties &&
|
|
141
|
+
typeof properties === "object" &&
|
|
142
|
+
Object.prototype.hasOwnProperty.call(properties, segment)) {
|
|
128
143
|
current = properties[segment];
|
|
129
144
|
continue;
|
|
130
145
|
}
|
|
@@ -139,17 +154,35 @@ function resolveAttributePath(attributePath, attributesByKey, schemasByKey) {
|
|
|
139
154
|
}
|
|
140
155
|
return { kind: "schema", schema: resolveSchemaRefs(current, schemasByKey) };
|
|
141
156
|
}
|
|
142
|
-
function matchesSchemaValue(schema, value, schemasByKey) {
|
|
157
|
+
function matchesSchemaValue(schema, value, schemasByKey, nativeDates = false) {
|
|
143
158
|
const resolved = resolveSchemaRefs(schema, schemasByKey);
|
|
144
159
|
if (resolved.oneOf && Array.isArray(resolved.oneOf) && resolved.oneOf.length > 0) {
|
|
145
|
-
const matches = resolved.oneOf.filter((branch) => matchesSchemaValue(branch, value, schemasByKey)).length;
|
|
160
|
+
const matches = resolved.oneOf.filter((branch) => matchesSchemaValue(branch, value, schemasByKey, nativeDates)).length;
|
|
146
161
|
return matches === 1;
|
|
147
162
|
}
|
|
148
|
-
|
|
149
|
-
|
|
163
|
+
const isDateTime = (0, schemaFormats_1.getSchemaKind)(resolved) === "date-time";
|
|
164
|
+
if (isDateTime && nativeDates && value instanceof Date) {
|
|
165
|
+
const timestamp = (0, sdk_1.getPortableTimestamp)(value);
|
|
166
|
+
if (timestamp === null)
|
|
167
|
+
return false;
|
|
168
|
+
if (resolved.const !== undefined && (0, sdk_1.getPortableTimestamp)(resolved.const) !== timestamp) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (resolved.enum?.length &&
|
|
172
|
+
!resolved.enum.some((entry) => (0, sdk_1.getPortableTimestamp)(entry) === timestamp)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
// Enum and const constrain a valid timestamp; they must not bypass its type.
|
|
178
|
+
if (isDateTime && (typeof value !== "string" || !isIsoDateString(value))) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (resolved.const !== undefined && !valueDeepEqual(value, resolved.const)) {
|
|
182
|
+
return false;
|
|
150
183
|
}
|
|
151
|
-
if (
|
|
152
|
-
return
|
|
184
|
+
if (resolved.enum?.length && !resolved.enum.some((entry) => valueDeepEqual(entry, value))) {
|
|
185
|
+
return false;
|
|
153
186
|
}
|
|
154
187
|
const type = resolved.type;
|
|
155
188
|
if (!type) {
|
|
@@ -158,10 +191,12 @@ function matchesSchemaValue(schema, value, schemasByKey) {
|
|
|
158
191
|
if (type === "boolean") {
|
|
159
192
|
return typeof value === "boolean";
|
|
160
193
|
}
|
|
161
|
-
if (type === "string"
|
|
194
|
+
if (type === "string") {
|
|
162
195
|
if (typeof value !== "string") {
|
|
163
196
|
return false;
|
|
164
197
|
}
|
|
198
|
+
if (!(0, schemaFormats_1.valueMatchesFormat)(resolved.format, value))
|
|
199
|
+
return false;
|
|
165
200
|
if (resolved.minLength !== undefined && value.length < resolved.minLength)
|
|
166
201
|
return false;
|
|
167
202
|
if (resolved.maxLength !== undefined && value.length > resolved.maxLength)
|
|
@@ -175,13 +210,10 @@ function matchesSchemaValue(schema, value, schemasByKey) {
|
|
|
175
210
|
return true;
|
|
176
211
|
}
|
|
177
212
|
}
|
|
178
|
-
if (type === "date" && !isIsoDateString(value)) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
213
|
return true;
|
|
182
214
|
}
|
|
183
|
-
if (type === "integer" || type === "
|
|
184
|
-
if (typeof value !== "number") {
|
|
215
|
+
if (type === "integer" || type === "number") {
|
|
216
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
185
217
|
return false;
|
|
186
218
|
}
|
|
187
219
|
if (type === "integer" && !Number.isInteger(value)) {
|
|
@@ -212,13 +244,13 @@ function matchesSchemaValue(schema, value, schemasByKey) {
|
|
|
212
244
|
}
|
|
213
245
|
for (const key of Object.keys(objectValue)) {
|
|
214
246
|
if (properties[key]) {
|
|
215
|
-
if (!matchesSchemaValue(properties[key], objectValue[key], schemasByKey)) {
|
|
247
|
+
if (!matchesSchemaValue(properties[key], objectValue[key], schemasByKey, nativeDates)) {
|
|
216
248
|
return false;
|
|
217
249
|
}
|
|
218
250
|
continue;
|
|
219
251
|
}
|
|
220
252
|
if (additionalProperties && typeof additionalProperties === "object") {
|
|
221
|
-
if (!matchesSchemaValue(additionalProperties, objectValue[key], schemasByKey)) {
|
|
253
|
+
if (!matchesSchemaValue(additionalProperties, objectValue[key], schemasByKey, nativeDates)) {
|
|
222
254
|
return false;
|
|
223
255
|
}
|
|
224
256
|
continue;
|
|
@@ -228,7 +260,7 @@ function matchesSchemaValue(schema, value, schemasByKey) {
|
|
|
228
260
|
return true;
|
|
229
261
|
}
|
|
230
262
|
if (additionalProperties && typeof additionalProperties === "object") {
|
|
231
|
-
return Object.values(objectValue).every((entry) => matchesSchemaValue(additionalProperties, entry, schemasByKey));
|
|
263
|
+
return Object.values(objectValue).every((entry) => matchesSchemaValue(additionalProperties, entry, schemasByKey, nativeDates));
|
|
232
264
|
}
|
|
233
265
|
return true;
|
|
234
266
|
}
|
|
@@ -251,7 +283,7 @@ function matchesSchemaValue(schema, value, schemasByKey) {
|
|
|
251
283
|
if (!resolved.items || typeof resolved.items !== "object") {
|
|
252
284
|
return value.every((entry) => typeof entry === "string");
|
|
253
285
|
}
|
|
254
|
-
return value.every((entry) => matchesSchemaValue(resolved.items, entry, schemasByKey));
|
|
286
|
+
return value.every((entry) => matchesSchemaValue(resolved.items, entry, schemasByKey, nativeDates));
|
|
255
287
|
}
|
|
256
288
|
return true;
|
|
257
289
|
}
|
|
@@ -296,13 +328,33 @@ function getArrayItemLeaf(leaf, schemasByKey) {
|
|
|
296
328
|
}
|
|
297
329
|
return { kind: "flat-array-item" };
|
|
298
330
|
}
|
|
299
|
-
function addIssue(context, message, path = ["value"]) {
|
|
331
|
+
function addIssue(context, message, path = ["value"], code) {
|
|
300
332
|
context.addIssue({
|
|
301
333
|
code: zod_1.z.ZodIssueCode.custom,
|
|
302
334
|
message,
|
|
303
335
|
path,
|
|
336
|
+
...(code ? { params: { code } } : {}),
|
|
304
337
|
});
|
|
305
338
|
}
|
|
339
|
+
function getDateOperatorError(attribute, operator, attributesByKey, schemasByKey) {
|
|
340
|
+
const leaf = resolveAttributePath(attribute, attributesByKey, schemasByKey);
|
|
341
|
+
const isDateSchema = (schema) => {
|
|
342
|
+
const resolved = resolveSchemaRefs(schema, schemasByKey);
|
|
343
|
+
if ("oneOf" in resolved && resolved.oneOf?.length) {
|
|
344
|
+
return resolved.oneOf.every((branch) => isDateSchema(branch));
|
|
345
|
+
}
|
|
346
|
+
return (0, schemaFormats_1.getSchemaKind)(resolved) === "date-time";
|
|
347
|
+
};
|
|
348
|
+
if (!leaf ||
|
|
349
|
+
leaf.kind !== "schema" ||
|
|
350
|
+
!isDateSchema(leaf.schema) ||
|
|
351
|
+
[...dateOperators, "exists", "notExists", "isNull", "notNull"].includes(operator)) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
return emptinessOperators.includes(operator)
|
|
355
|
+
? `Operator "${operator}" cannot be used with date-time attribute "${attribute}". Use exists or notNull to check that a date was sent.`
|
|
356
|
+
: `Operator "${operator}" cannot be used with date-time attribute "${attribute}". Compare dates with before or after. To compare it as text too, declare it as a plain string without a format.`;
|
|
357
|
+
}
|
|
306
358
|
function validateAttributeAwareCondition(data, context, attributesByKey, schemasByKey) {
|
|
307
359
|
const resolvedLeaf = resolveAttributePath(data.attribute, attributesByKey, schemasByKey);
|
|
308
360
|
if (!resolvedLeaf) {
|
|
@@ -310,6 +362,12 @@ function validateAttributeAwareCondition(data, context, attributesByKey, schemas
|
|
|
310
362
|
}
|
|
311
363
|
const leafType = getLeafType(resolvedLeaf);
|
|
312
364
|
const leafTypes = getLeafTypes(resolvedLeaf, schemasByKey);
|
|
365
|
+
if (emptinessOperators.includes(data.operator)) {
|
|
366
|
+
if (leafTypes.length > 0 && !leafTypes.some((type) => emptinessTypes.includes(type))) {
|
|
367
|
+
addIssue(context, `Operator "${data.operator}" can only be used with string, array or object attributes.`);
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
313
371
|
if (operatorsWithoutValue.includes(data.operator)) {
|
|
314
372
|
return;
|
|
315
373
|
}
|
|
@@ -318,28 +376,28 @@ function validateAttributeAwareCondition(data, context, attributesByKey, schemas
|
|
|
318
376
|
return;
|
|
319
377
|
}
|
|
320
378
|
if (numericOperators.includes(data.operator) &&
|
|
321
|
-
!leafTypes.some((type) => ["integer", "
|
|
322
|
-
addIssue(context, `Operator "${data.operator}" can only be used with integer or
|
|
379
|
+
!leafTypes.some((type) => ["integer", "number"].includes(type))) {
|
|
380
|
+
addIssue(context, `Operator "${data.operator}" can only be used with integer or number attributes.`);
|
|
323
381
|
return;
|
|
324
382
|
}
|
|
325
383
|
if (stringOperators.includes(data.operator) &&
|
|
326
|
-
!leafTypes.some((type) => ["string", "semver", "date"].includes(type))) {
|
|
384
|
+
!leafTypes.some((type) => ["string", "semver", "date-time"].includes(type))) {
|
|
327
385
|
addIssue(context, `Operator "${data.operator}" can only be used with string-like attributes.`);
|
|
328
386
|
return;
|
|
329
387
|
}
|
|
330
388
|
if (semverOperators.includes(data.operator) &&
|
|
331
389
|
!leafTypes.some((type) => ["string", "semver"].includes(type))) {
|
|
332
|
-
addIssue(context, `Operator "${data.operator}" can only be used with string
|
|
390
|
+
addIssue(context, `Operator "${data.operator}" can only be used with string attributes, including format: semver.`);
|
|
333
391
|
return;
|
|
334
392
|
}
|
|
335
393
|
if (dateOperators.includes(data.operator) &&
|
|
336
|
-
!leafTypes.some((type) => ["string", "date"].includes(type))) {
|
|
337
|
-
addIssue(context, `Operator "${data.operator}" can only be used with string
|
|
394
|
+
!leafTypes.some((type) => ["string", "date-time"].includes(type))) {
|
|
395
|
+
addIssue(context, `Operator "${data.operator}" can only be used with string attributes, including format: date-time.`);
|
|
338
396
|
return;
|
|
339
397
|
}
|
|
340
398
|
if (arrayMembershipOperators.includes(data.operator)) {
|
|
341
|
-
if (
|
|
342
|
-
addIssue(context, `Operator "${data.operator}" can only be used with
|
|
399
|
+
if (leafTypes.length === 0 || leafTypes.some((type) => type !== "string")) {
|
|
400
|
+
addIssue(context, `Operator "${data.operator}" can only be used with string attributes or nested paths declared as strings. ${data.operator === "notIn" ? "Use a not group containing an or group of equals conditions for numbers." : "Use an or group of equals conditions for numbers."}`);
|
|
343
401
|
return;
|
|
344
402
|
}
|
|
345
403
|
if (!Array.isArray(data.value)) {
|
|
@@ -352,7 +410,7 @@ function validateAttributeAwareCondition(data, context, attributesByKey, schemas
|
|
|
352
410
|
});
|
|
353
411
|
return;
|
|
354
412
|
}
|
|
355
|
-
if (arrayOperators.includes(data.operator)) {
|
|
413
|
+
if ([...arrayOperators, ...arrayListOperators].includes(data.operator)) {
|
|
356
414
|
const itemLeaf = getArrayItemLeaf(resolvedLeaf, schemasByKey);
|
|
357
415
|
if (!itemLeaf) {
|
|
358
416
|
addIssue(context, `Operator "${data.operator}" can only be used with array attributes.`);
|
|
@@ -363,7 +421,19 @@ function validateAttributeAwareCondition(data, context, attributesByKey, schemas
|
|
|
363
421
|
addIssue(context, `Operator "${data.operator}" only supports arrays of primitive values.`);
|
|
364
422
|
return;
|
|
365
423
|
}
|
|
366
|
-
if (
|
|
424
|
+
if (arrayListOperators.includes(data.operator)) {
|
|
425
|
+
if (Array.isArray(data.value))
|
|
426
|
+
data.value.forEach((value, index) => {
|
|
427
|
+
// Malformed candidates already have an indexed operand diagnostic.
|
|
428
|
+
if (!isPrimitiveAttributeValue(value) ||
|
|
429
|
+
(typeof value === "number" && !Number.isFinite(value)))
|
|
430
|
+
return;
|
|
431
|
+
if (!matchesLeafValue(itemLeaf, value, schemasByKey)) {
|
|
432
|
+
addIssue(context, `Value at index ${index} does not match the item schema of attribute "${data.attribute}".`, ["value", index]);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
else if (!matchesLeafValue(itemLeaf, data.value, schemasByKey)) {
|
|
367
437
|
addIssue(context, `Value does not match the item schema of attribute "${data.attribute}".`);
|
|
368
438
|
}
|
|
369
439
|
return;
|
|
@@ -377,10 +447,10 @@ function validateAttributeAwareCondition(data, context, attributesByKey, schemas
|
|
|
377
447
|
}
|
|
378
448
|
}
|
|
379
449
|
}
|
|
380
|
-
function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {}) {
|
|
450
|
+
function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {}, featuresByKey = {}, variablesByKey = {}, segmentKeys = []) {
|
|
381
451
|
const plainConditionZodSchema = zod_1.z
|
|
382
452
|
.object({
|
|
383
|
-
attribute: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => resolveAttributePath(value, attributesByKey, schemasByKey) !== null, (value) => `Unknown attribute "${value}"
|
|
453
|
+
attribute: (0, zodHelpers_1.refineWithMessage)(zod_1.z.string(), (value) => resolveAttributePath(value, attributesByKey, schemasByKey) !== null, (value) => `Unknown attribute "${value}".${(0, diagnostics_1.suggestKey)(value, Object.keys(attributesByKey))}`, () => zodHelpers_1.UNKNOWN_REFERENCE),
|
|
384
454
|
operator: zod_1.z.enum([
|
|
385
455
|
...commonOperators,
|
|
386
456
|
...numericOperators,
|
|
@@ -389,10 +459,11 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
389
459
|
...dateOperators,
|
|
390
460
|
...arrayMembershipOperators,
|
|
391
461
|
...arrayOperators,
|
|
462
|
+
...arrayListOperators,
|
|
392
463
|
...operatorsWithoutValue,
|
|
393
464
|
]),
|
|
394
465
|
value: zod_1.z
|
|
395
|
-
.union([zod_1.z.string(), zod_1.z.array(zod_1.z.
|
|
466
|
+
.union([zod_1.z.string(), zod_1.z.array(zod_1.z.unknown()), zod_1.z.number(), zod_1.z.boolean(), zod_1.z.date(), zod_1.z.null()])
|
|
396
467
|
.optional(),
|
|
397
468
|
regexFlags: zod_1.z
|
|
398
469
|
.string()
|
|
@@ -405,8 +476,31 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
405
476
|
message: `regexFlags must contain unique characters from the cross-SDK set: g, i, m, s`,
|
|
406
477
|
})
|
|
407
478
|
.optional(),
|
|
479
|
+
compareTo: zod_1.z.never().optional(),
|
|
408
480
|
})
|
|
481
|
+
.strict()
|
|
409
482
|
.superRefine((data, context) => {
|
|
483
|
+
for (const issue of (0, comparisonOperators_1.findDisallowedOperators)(data, projectConfig.disallowOperators || [], [])) {
|
|
484
|
+
context.addIssue({
|
|
485
|
+
code: zod_1.z.ZodIssueCode.custom,
|
|
486
|
+
path: issue.path,
|
|
487
|
+
message: `Operator "${issue.operator}" is disallowed by project configuration.`,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
const dateOperatorError = getDateOperatorError(data.attribute, data.operator, attributesByKey, schemasByKey);
|
|
491
|
+
if (dateOperatorError) {
|
|
492
|
+
addIssue(context, dateOperatorError, ["operator"]);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
// Diagnose the unsupported attribute before checking its membership values.
|
|
496
|
+
if (arrayMembershipOperators.includes(data.operator)) {
|
|
497
|
+
const leaf = resolveAttributePath(data.attribute, attributesByKey, schemasByKey);
|
|
498
|
+
const types = leaf ? getLeafTypes(leaf, schemasByKey) : [];
|
|
499
|
+
if (leaf && (types.length === 0 || types.some((type) => type !== "string"))) {
|
|
500
|
+
validateAttributeAwareCondition(data, context, attributesByKey, schemasByKey);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
410
504
|
if (commonOperators.includes(data.operator) &&
|
|
411
505
|
!(data.value === null ||
|
|
412
506
|
typeof data.value === "string" ||
|
|
@@ -421,7 +515,13 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
421
515
|
}
|
|
422
516
|
if ([...stringOperators, ...semverOperators].includes(data.operator) &&
|
|
423
517
|
typeof data.value !== "string") {
|
|
424
|
-
addIssue(context,
|
|
518
|
+
addIssue(context, semverOperators.includes(data.operator) && typeof data.value === "number"
|
|
519
|
+
? `when operator is "${data.operator}", value must be a string. Quote versions such as '5.5' so YAML keeps them as text.`
|
|
520
|
+
: `when operator is "${data.operator}", value must be a string`);
|
|
521
|
+
}
|
|
522
|
+
else if (semverOperators.includes(data.operator) && !(0, sdk_1.isValidVersion)(data.value)) {
|
|
523
|
+
// The operators treat an unparseable version as no match, so the condition can never pass.
|
|
524
|
+
addIssue(context, `when operator is "${data.operator}", value must be a version the operators can compare, such as 5.5.0, 5.5 or v5.5.0`);
|
|
425
525
|
}
|
|
426
526
|
if (dateOperators.includes(data.operator)) {
|
|
427
527
|
if (typeof data.value === "undefined" || data.value === null || data.value === "") {
|
|
@@ -429,16 +529,16 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
429
529
|
}
|
|
430
530
|
else if (typeof data.value === "string") {
|
|
431
531
|
if (!isIsoDateString(data.value)) {
|
|
432
|
-
addIssue(context, `when operator is "${data.operator}",
|
|
532
|
+
addIssue(context, `when operator is "${data.operator}", use an ISO 8601 timestamp YYYY-MM-DDTHH:mm:ss with Z or ±HH:mm and optional 1 to 9 fractional digits, for example 2026-11-27T00:00:00.123456Z`);
|
|
433
533
|
}
|
|
434
534
|
}
|
|
435
535
|
else if (data.value instanceof Date) {
|
|
436
|
-
if (
|
|
536
|
+
if ((0, sdk_1.getPortableTimestamp)(data.value) === null) {
|
|
437
537
|
addIssue(context, `when operator is "${data.operator}", value is a Date but invalid`);
|
|
438
538
|
}
|
|
439
539
|
}
|
|
440
540
|
else {
|
|
441
|
-
addIssue(context, `when operator is "${data.operator}",
|
|
541
|
+
addIssue(context, `when operator is "${data.operator}", use an ISO 8601 timestamp YYYY-MM-DDTHH:mm:ss with Z or ±HH:mm and optional 1 to 9 fractional digits, for example 2026-11-27T00:00:00.123456Z`);
|
|
442
542
|
}
|
|
443
543
|
}
|
|
444
544
|
if (arrayMembershipOperators.includes(data.operator) && !Array.isArray(data.value)) {
|
|
@@ -449,8 +549,20 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
449
549
|
!isStringArray(data.value)) {
|
|
450
550
|
addIssue(context, `when operator is "${data.operator}", value must be an array of strings`);
|
|
451
551
|
}
|
|
552
|
+
if (arrayListOperators.includes(data.operator)) {
|
|
553
|
+
if (!Array.isArray(data.value)) {
|
|
554
|
+
addIssue(context, `when operator is "${data.operator}", value must be an array of primitive values`, ["value"]);
|
|
555
|
+
}
|
|
556
|
+
else
|
|
557
|
+
for (let index = 0; index < data.value.length; index++) {
|
|
558
|
+
const value = data.value[index];
|
|
559
|
+
if (!isPrimitiveAttributeValue(value) ||
|
|
560
|
+
(typeof value === "number" && !Number.isFinite(value)))
|
|
561
|
+
addIssue(context, `when operator is "${data.operator}", each candidate must be a string, number, boolean or null`, ["value", index]);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
452
564
|
if (!arrayMembershipOperators.includes(data.operator) && Array.isArray(data.value)) {
|
|
453
|
-
if (!
|
|
565
|
+
if (!arrayListOperators.includes(data.operator)) {
|
|
454
566
|
addIssue(context, `when operator is "${data.operator}", value must not be an array`);
|
|
455
567
|
}
|
|
456
568
|
}
|
|
@@ -460,39 +572,128 @@ function getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey = {
|
|
|
460
572
|
}
|
|
461
573
|
else {
|
|
462
574
|
const portableRegexError = getPortableRegexError(data.value);
|
|
575
|
+
const backtrackingError = !portableRegexError && (0, regexSafety_1.getBacktrackingError)(data.value);
|
|
463
576
|
if (portableRegexError) {
|
|
464
|
-
addIssue(context, `when operator is "${data.operator}", value ${portableRegexError} in the cross-SDK regex subset`, ["value"]);
|
|
577
|
+
addIssue(context, `when operator is "${data.operator}", value ${portableRegexError} in the cross-SDK regex subset`, ["value"], "unportable_regex");
|
|
578
|
+
}
|
|
579
|
+
else if (backtrackingError) {
|
|
580
|
+
addIssue(context, `when operator is "${data.operator}", value ${backtrackingError}.`, ["value"], "regex_backtracking");
|
|
465
581
|
}
|
|
466
582
|
}
|
|
467
583
|
}
|
|
468
584
|
else if (data.regexFlags) {
|
|
469
|
-
addIssue(context, `when operator is
|
|
585
|
+
addIssue(context, `when operator is neither "matches" nor "notMatches", regexFlags are not needed`, ["regexFlags"]);
|
|
470
586
|
}
|
|
471
587
|
if (operatorsWithoutValue.includes(data.operator) && data.value !== undefined) {
|
|
472
588
|
addIssue(context, `when operator is "${data.operator}", value is not needed`);
|
|
473
589
|
}
|
|
474
590
|
validateAttributeAwareCondition(data, context, attributesByKey, schemasByKey);
|
|
475
591
|
});
|
|
476
|
-
const
|
|
592
|
+
const featureSchema = (0, requiredFeaturesSchema_1.getFeatureConditionZodSchema)(featuresByKey);
|
|
593
|
+
const variableSchema = (0, requiredVariablesSchema_1.getVariableConditionZodSchema)(featuresByKey, variablesByKey, schemasByKey, projectConfig);
|
|
594
|
+
const segmentSchema = (0, zodHelpers_1.refineWithMessage)(zod_1.z.string().min(1), (key) => key !== "*" && segmentKeys.includes(key), (key) => key === "*"
|
|
595
|
+
? "`*` is only allowed as the entire `conditions` value."
|
|
596
|
+
: Object.prototype.hasOwnProperty.call(featuresByKey, key)
|
|
597
|
+
? `Unknown segment "${key}". "${key}" is a feature: use { feature: ${key} }.`
|
|
598
|
+
: `Unknown segment "${key}".${(0, diagnostics_1.suggestKey)(key, segmentKeys)}`, (key) => (key === "*" ? undefined : zodHelpers_1.UNKNOWN_REFERENCE));
|
|
599
|
+
// Dispatch before parsing, keeping leaf diagnostics and their exact authored paths.
|
|
600
|
+
const expression = zod_1.z.lazy(() => zod_1.z.unknown().transform((value, ctx) => {
|
|
601
|
+
let selected;
|
|
602
|
+
if (typeof value === "string")
|
|
603
|
+
selected = segmentSchema;
|
|
604
|
+
else if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
605
|
+
const object = value;
|
|
606
|
+
const owns = (key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
607
|
+
if (owns("attribute") && (owns("feature") || owns("variable"))) {
|
|
608
|
+
ctx.addIssue({
|
|
609
|
+
code: "custom",
|
|
610
|
+
message: "An attribute condition cannot also contain feature or variable.",
|
|
611
|
+
path: ["attribute"],
|
|
612
|
+
});
|
|
613
|
+
return zod_1.z.NEVER;
|
|
614
|
+
}
|
|
615
|
+
const groups = ["and", "or", "not"].filter(owns);
|
|
616
|
+
if (groups.length)
|
|
617
|
+
selected = zod_1.z
|
|
618
|
+
.object({
|
|
619
|
+
[groups[0]]: zod_1.z
|
|
620
|
+
.array(expression)
|
|
621
|
+
.min(1, `\`${groups[0]}\` must contain at least one condition`),
|
|
622
|
+
})
|
|
623
|
+
.strict();
|
|
624
|
+
else if (owns("variable"))
|
|
625
|
+
selected = variableSchema;
|
|
626
|
+
else if (owns("feature")) {
|
|
627
|
+
if (owns("operator")) {
|
|
628
|
+
ctx.addIssue({
|
|
629
|
+
code: "custom",
|
|
630
|
+
message: "To compare a variation, use variation: <value>",
|
|
631
|
+
path: ["operator"],
|
|
632
|
+
});
|
|
633
|
+
return zod_1.z.NEVER;
|
|
634
|
+
}
|
|
635
|
+
selected = featureSchema;
|
|
636
|
+
}
|
|
637
|
+
else
|
|
638
|
+
selected = plainConditionZodSchema;
|
|
639
|
+
}
|
|
640
|
+
else
|
|
641
|
+
selected = plainConditionZodSchema;
|
|
642
|
+
const result = selected.safeParse(value, diagnostics_1.diagnosticParseOptions);
|
|
643
|
+
if (!result.success) {
|
|
644
|
+
for (const issue of result.error.issues)
|
|
645
|
+
ctx.addIssue({ ...issue });
|
|
646
|
+
return zod_1.z.NEVER;
|
|
647
|
+
}
|
|
648
|
+
return result.data;
|
|
649
|
+
}));
|
|
650
|
+
const schema = zod_1.z.unknown().transform((value, ctx) => {
|
|
651
|
+
if (value === "*")
|
|
652
|
+
return value;
|
|
653
|
+
const result = (Array.isArray(value)
|
|
654
|
+
? zod_1.z.array(expression).min(1, "conditions must not be empty. Use '*' to match everything.")
|
|
655
|
+
: expression).safeParse(value, diagnostics_1.diagnosticParseOptions);
|
|
656
|
+
if (!result.success) {
|
|
657
|
+
for (const issue of result.error.issues)
|
|
658
|
+
ctx.addIssue({ ...issue });
|
|
659
|
+
return zod_1.z.NEVER;
|
|
660
|
+
}
|
|
661
|
+
return result.data;
|
|
662
|
+
});
|
|
663
|
+
const editorExpression = zod_1.z.lazy(() => zod_1.z.union([
|
|
664
|
+
plainConditionZodSchema,
|
|
665
|
+
featureSchema,
|
|
666
|
+
variableSchema,
|
|
667
|
+
zod_1.z
|
|
668
|
+
.string()
|
|
669
|
+
.min(1)
|
|
670
|
+
.regex(/^(?!\*$).+/),
|
|
477
671
|
zod_1.z
|
|
478
672
|
.object({
|
|
479
|
-
and: zod_1.z.array(
|
|
673
|
+
and: zod_1.z.array(editorExpression).min(1, "`and` must contain at least one condition"),
|
|
480
674
|
})
|
|
481
675
|
.strict(),
|
|
482
676
|
zod_1.z
|
|
483
677
|
.object({
|
|
484
|
-
or: zod_1.z.array(
|
|
678
|
+
or: zod_1.z.array(editorExpression).min(1, "`or` must contain at least one condition"),
|
|
485
679
|
})
|
|
486
680
|
.strict(),
|
|
487
681
|
zod_1.z
|
|
488
682
|
.object({
|
|
489
|
-
not: zod_1.z.array(
|
|
683
|
+
not: zod_1.z.array(editorExpression).min(1, "`not` must contain at least one condition"),
|
|
490
684
|
})
|
|
491
685
|
.strict(),
|
|
492
|
-
]);
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
686
|
+
]));
|
|
687
|
+
return Object.assign(schema, {
|
|
688
|
+
editorSchema: zod_1.z.union([
|
|
689
|
+
zod_1.z.literal("*"),
|
|
690
|
+
editorExpression,
|
|
691
|
+
zod_1.z
|
|
692
|
+
.array(editorExpression)
|
|
693
|
+
.min(1, "conditions must not be empty. Use '*' to match everything."),
|
|
694
|
+
]),
|
|
695
|
+
withEntities: (features, variables, segments) => getConditionsZodSchema(projectConfig, attributesByKey, schemasByKey, features, variables, segments),
|
|
696
|
+
});
|
|
496
697
|
}
|
|
497
698
|
function regexFlagsRequired(operator) {
|
|
498
699
|
return operator === "matches" || operator === "notMatches";
|