@featurevisor/core 4.1.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/builder/buildProject.js +24 -6
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/schemaV2.d.ts +47 -0
- package/lib/builder/schemaV2.js +529 -0
- package/lib/builder/schemaV2.js.map +1 -0
- package/lib/catalog.js +10 -2
- package/lib/catalog.js.map +1 -1
- package/lib/cli/cli.d.ts +2 -1
- package/lib/cli/cli.js +9 -6
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +61 -0
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +7 -1
- package/lib/cli/plugins.js.map +1 -1
- package/lib/config/projectConfig.js +6 -0
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/convert/check.d.ts +33 -0
- package/lib/convert/check.js +377 -0
- package/lib/convert/check.js.map +1 -0
- package/lib/convert/config.d.ts +20 -0
- package/lib/convert/config.js +147 -0
- package/lib/convert/config.js.map +1 -0
- package/lib/convert/documents.d.ts +55 -0
- package/lib/convert/documents.js +195 -0
- package/lib/convert/documents.js.map +1 -0
- package/lib/convert/index.d.ts +7 -0
- package/lib/convert/index.js +35 -0
- package/lib/convert/index.js.map +1 -0
- package/lib/convert/plan.d.ts +41 -0
- package/lib/convert/plan.js +562 -0
- package/lib/convert/plan.js.map +1 -0
- package/lib/convert/project.d.ts +29 -0
- package/lib/convert/project.js +109 -0
- package/lib/convert/project.js.map +1 -0
- package/lib/convert/run.d.ts +3 -0
- package/lib/convert/run.js +224 -0
- package/lib/convert/run.js.map +1 -0
- package/lib/convert/tests.d.ts +22 -0
- package/lib/convert/tests.js +267 -0
- package/lib/convert/tests.js.map +1 -0
- package/lib/datasource/datasource.d.ts +2 -0
- package/lib/datasource/datasource.js +8 -0
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/parseError.d.ts +11 -0
- package/lib/datasource/parseError.js +33 -19
- package/lib/datasource/parseError.js.map +1 -1
- package/lib/formatter/formatDefinition.d.ts +32 -0
- package/lib/formatter/formatDefinition.js +161 -0
- package/lib/formatter/formatDefinition.js.map +1 -0
- package/lib/formatter/formatProject.d.ts +68 -0
- package/lib/formatter/formatProject.js +184 -0
- package/lib/formatter/formatProject.js.map +1 -0
- package/lib/formatter/index.d.ts +6 -0
- package/lib/formatter/index.js +49 -0
- package/lib/formatter/index.js.map +1 -0
- package/lib/formatter/layout.d.ts +26 -0
- package/lib/formatter/layout.js +175 -0
- package/lib/formatter/layout.js.map +1 -0
- package/lib/formatter/printFormatResult.d.ts +8 -0
- package/lib/formatter/printFormatResult.js +98 -0
- package/lib/formatter/printFormatResult.js.map +1 -0
- package/lib/formatter/run.d.ts +6 -0
- package/lib/formatter/run.js +92 -0
- package/lib/formatter/run.js.map +1 -0
- package/lib/formatter/since.d.ts +6 -0
- package/lib/formatter/since.js +80 -0
- package/lib/formatter/since.js.map +1 -0
- package/lib/formatter/style.d.ts +94 -0
- package/lib/formatter/style.js +237 -0
- package/lib/formatter/style.js.map +1 -0
- package/lib/linter/diagnostics.d.ts +12 -12
- package/lib/linter/featureSchema.js +14 -13
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.js +45 -0
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/schemaV2Targets.d.ts +16 -0
- package/lib/linter/schemaV2Targets.js +62 -0
- package/lib/linter/schemaV2Targets.js.map +1 -0
- package/lib/linter/targetSchema.d.ts +4 -0
- package/lib/linter/targetSchema.js +5 -0
- package/lib/linter/targetSchema.js.map +1 -1
- package/lib/migrate/definitions.d.ts +46 -0
- package/lib/migrate/definitions.js +488 -0
- package/lib/migrate/definitions.js.map +1 -0
- package/lib/migrate/index.d.ts +6 -0
- package/lib/migrate/index.js +30 -0
- package/lib/migrate/index.js.map +1 -0
- package/lib/migrate/migrateProject.d.ts +33 -0
- package/lib/migrate/migrateProject.js +195 -0
- package/lib/migrate/migrateProject.js.map +1 -0
- package/lib/migrate/project.d.ts +31 -0
- package/lib/migrate/project.js +153 -0
- package/lib/migrate/project.js.map +1 -0
- package/lib/migrate/run.d.ts +3 -0
- package/lib/migrate/run.js +81 -0
- package/lib/migrate/run.js.map +1 -0
- package/lib/migrate/write.d.ts +10 -0
- package/lib/migrate/write.js +150 -0
- package/lib/migrate/write.js.map +1 -0
- package/lib/promoter/index.js +38 -2
- package/lib/promoter/index.js.map +1 -1
- package/lib/rewrite/diff.d.ts +2 -0
- package/lib/rewrite/diff.js +76 -0
- package/lib/rewrite/diff.js.map +1 -0
- package/lib/rewrite/files.d.ts +6 -0
- package/lib/rewrite/files.js +66 -0
- package/lib/rewrite/files.js.map +1 -0
- package/lib/rewrite/lines.d.ts +56 -0
- package/lib/rewrite/lines.js +204 -0
- package/lib/rewrite/lines.js.map +1 -0
- package/package.json +6 -6
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findSchemaV2TargetIssues = findSchemaV2TargetIssues;
|
|
4
|
+
exports.describeSchemaV2TargetIssue = describeSchemaV2TargetIssue;
|
|
5
|
+
const buildProject_1 = require("../builder/buildProject");
|
|
6
|
+
const environments_1 = require("../builder/environments");
|
|
7
|
+
const schemaV2_1 = require("../builder/schemaV2");
|
|
8
|
+
/**
|
|
9
|
+
* Definitions that a schemaVersion "2" target would carry but cannot express.
|
|
10
|
+
* Only those targets are built, so a project without one pays nothing.
|
|
11
|
+
*/
|
|
12
|
+
async function findSchemaV2TargetIssues(projectConfig, datasource, targets) {
|
|
13
|
+
const selected = targets.filter((target) => target.schemaVersion === schemaV2_1.SCHEMA_V2);
|
|
14
|
+
if (!selected.length)
|
|
15
|
+
return [];
|
|
16
|
+
const found = new Map();
|
|
17
|
+
for (const environment of (0, environments_1.resolveBuildEnvironments)(projectConfig, undefined)) {
|
|
18
|
+
const existingState = await datasource.readState(environment);
|
|
19
|
+
for (const target of selected) {
|
|
20
|
+
let datafile;
|
|
21
|
+
try {
|
|
22
|
+
datafile = await (0, buildProject_1.buildTargetDatafile)({
|
|
23
|
+
projectConfig,
|
|
24
|
+
datasource,
|
|
25
|
+
target: { ...target, schemaVersion: undefined },
|
|
26
|
+
environment,
|
|
27
|
+
existingState,
|
|
28
|
+
revision: "lint",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Other checks report why this target cannot build.
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const { issues } = (0, schemaV2_1.convertDatafileToSchemaV2)(datafile, {
|
|
36
|
+
stringify: projectConfig.stringify,
|
|
37
|
+
});
|
|
38
|
+
for (const issue of issues) {
|
|
39
|
+
const id = JSON.stringify([issue.entityType, issue.key, issue.location, issue.reason]);
|
|
40
|
+
const entry = found.get(id) || { ...issue, targets: [], environments: [] };
|
|
41
|
+
if (!entry.targets.includes(target.key))
|
|
42
|
+
entry.targets.push(target.key);
|
|
43
|
+
if (environment !== false && !entry.environments.includes(environment)) {
|
|
44
|
+
entry.environments.push(environment);
|
|
45
|
+
}
|
|
46
|
+
found.set(id, entry);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return [...found.values()];
|
|
51
|
+
}
|
|
52
|
+
function describeSchemaV2TargetIssue(issue) {
|
|
53
|
+
const names = issue.targets.map((key) => `"${key}"`);
|
|
54
|
+
const targets = names.length === 1
|
|
55
|
+
? `Target ${names[0]} sets`
|
|
56
|
+
: `Targets ${names.slice(0, -1).join(", ")} and ${names[names.length - 1]} set`;
|
|
57
|
+
const environments = issue.environments.length
|
|
58
|
+
? ` in ${issue.environments.length === 1 ? "environment" : "environments"} ${issue.environments.join(", ")}`
|
|
59
|
+
: "";
|
|
60
|
+
return `${issue.location[0].toUpperCase()}${issue.location.slice(1)} ${issue.reason}. ${targets} schemaVersion "2"${environments}, so keep this ${issue.entityType} out of ${names.length === 1 ? "it" : "them"} or write it in a form schema version "2" supports.`;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=schemaV2Targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaV2Targets.js","sourceRoot":"","sources":["../../src/linter/schemaV2Targets.ts"],"names":[],"mappings":"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"}
|
|
@@ -15,4 +15,8 @@ export declare function getTargetZodSchema(projectConfig: ProjectConfig): z.ZodO
|
|
|
15
15
|
includeVariables: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>>;
|
|
16
16
|
excludeVariables: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodArray<z.ZodString>]>>;
|
|
17
17
|
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
18
|
+
schemaVersion: z.ZodOptional<z.ZodEnum<{
|
|
19
|
+
2: "2";
|
|
20
|
+
4: "4";
|
|
21
|
+
}>>;
|
|
18
22
|
}, z.core.$strict>;
|
|
@@ -32,6 +32,11 @@ function getTargetZodSchema(projectConfig) {
|
|
|
32
32
|
includeVariables: entityPatternsSchema.optional(),
|
|
33
33
|
excludeVariables: entityPatternsSchema.optional(),
|
|
34
34
|
context: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
|
|
35
|
+
schemaVersion: zod_1.z
|
|
36
|
+
.enum(["2", "4"], {
|
|
37
|
+
error: () => 'schemaVersion must be the string "2" or "4", in quotes',
|
|
38
|
+
})
|
|
39
|
+
.optional(),
|
|
35
40
|
})
|
|
36
41
|
.strict()
|
|
37
42
|
.refine((target) => !(target.tag && target.tags), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targetSchema.js","sourceRoot":"","sources":["../../src/linter/targetSchema.ts"],"names":[],"mappings":";;AAYA,
|
|
1
|
+
{"version":3,"file":"targetSchema.js","sourceRoot":"","sources":["../../src/linter/targetSchema.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v3 to v4 rewrites of parsed definitions. Each keeps what the definition means: selectors
|
|
3
|
+
* convert as v4 SDKs read v3 datafiles, and mutation maps keep the values v3 resolved.
|
|
4
|
+
*/
|
|
5
|
+
export type Path = (string | number)[];
|
|
6
|
+
type Plain = Record<string, unknown>;
|
|
7
|
+
/** Keys a rewrite renamed, or merged into one, so a writer can keep their comments */
|
|
8
|
+
export interface Rename {
|
|
9
|
+
path: Path;
|
|
10
|
+
from: string[];
|
|
11
|
+
to: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Note {
|
|
14
|
+
path: Path;
|
|
15
|
+
message: string;
|
|
16
|
+
/** The section of the v4 migration guide that explains it */
|
|
17
|
+
section: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class Migration {
|
|
20
|
+
changes: Set<string>;
|
|
21
|
+
renames: Rename[];
|
|
22
|
+
notes: Note[];
|
|
23
|
+
change(name: string): void;
|
|
24
|
+
note(path: Path, message: string, section: string): void;
|
|
25
|
+
}
|
|
26
|
+
/** Attribute schemas by key, after their types are migrated */
|
|
27
|
+
export type Attributes = Record<string, unknown>;
|
|
28
|
+
/** A map, as parsers give them, but not a list or a date */
|
|
29
|
+
export declare function isPlain(value: unknown): value is Plain;
|
|
30
|
+
/** `double`, `date` and `semver` become JSON Schema types, through every nested schema */
|
|
31
|
+
export declare function migrateSchema(schema: unknown, path: Path, migration: Migration): unknown;
|
|
32
|
+
type Location = "feature" | "variable" | "rule" | "force" | "featureVariableOverride" | "variableOverride";
|
|
33
|
+
/**
|
|
34
|
+
* Moves a selector's v3 fields into `conditions`, ANDed in the order v4 SDKs read them from a
|
|
35
|
+
* v3 datafile: `conditions`, `segments`, then required features and variables. `conditions`
|
|
36
|
+
* takes the place of the first of them.
|
|
37
|
+
*/
|
|
38
|
+
export declare function migrateSelector(entry: unknown, path: Path, location: Location, migration: Migration): unknown;
|
|
39
|
+
/** `in` and `notIn` on numbers become `equals` groups, and date comparisons are reported */
|
|
40
|
+
export declare function migrateConditions(conditions: unknown, path: Path, attributes: Attributes, migration: Migration): unknown;
|
|
41
|
+
export declare function migrateAttribute(value: unknown, migration: Migration): unknown;
|
|
42
|
+
export declare function migrateSegment(value: unknown, attributes: Attributes, migration: Migration): unknown;
|
|
43
|
+
export declare function migrateFeature(value: unknown, attributes: Attributes, migration: Migration): unknown;
|
|
44
|
+
export declare function migrateVariable(value: unknown, attributes: Attributes, migration: Migration): unknown;
|
|
45
|
+
export declare function migrateTest(value: unknown, migration: Migration): unknown;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Migration = void 0;
|
|
4
|
+
exports.isPlain = isPlain;
|
|
5
|
+
exports.migrateSchema = migrateSchema;
|
|
6
|
+
exports.migrateSelector = migrateSelector;
|
|
7
|
+
exports.migrateConditions = migrateConditions;
|
|
8
|
+
exports.migrateAttribute = migrateAttribute;
|
|
9
|
+
exports.migrateSegment = migrateSegment;
|
|
10
|
+
exports.migrateFeature = migrateFeature;
|
|
11
|
+
exports.migrateVariable = migrateVariable;
|
|
12
|
+
exports.migrateTest = migrateTest;
|
|
13
|
+
const mutationOrder_1 = require("../linter/mutationOrder");
|
|
14
|
+
const lines_1 = require("../rewrite/lines");
|
|
15
|
+
class Migration {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.changes = new Set();
|
|
18
|
+
this.renames = [];
|
|
19
|
+
this.notes = [];
|
|
20
|
+
}
|
|
21
|
+
change(name) {
|
|
22
|
+
this.changes.add(name);
|
|
23
|
+
}
|
|
24
|
+
note(path, message, section) {
|
|
25
|
+
this.notes.push({ path, message, section });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Migration = Migration;
|
|
29
|
+
/** A map, as parsers give them, but not a list or a date */
|
|
30
|
+
function isPlain(value) {
|
|
31
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
32
|
+
return false;
|
|
33
|
+
const prototype = Object.getPrototypeOf(value);
|
|
34
|
+
return prototype === Object.prototype || prototype === null;
|
|
35
|
+
}
|
|
36
|
+
const has = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
37
|
+
/** Rebuilds an object with `key` replaced, or removed when `value` is undefined */
|
|
38
|
+
function withKey(value, key, next) {
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const [name, item] of Object.entries(value)) {
|
|
41
|
+
if (name !== key)
|
|
42
|
+
result[name] = item;
|
|
43
|
+
else if (next !== undefined)
|
|
44
|
+
result[name] = next;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
// Types
|
|
49
|
+
const TYPES = {
|
|
50
|
+
double: { type: "number" },
|
|
51
|
+
date: { type: "string", format: "date-time" },
|
|
52
|
+
semver: { type: "string", format: "semver" },
|
|
53
|
+
};
|
|
54
|
+
/** `double`, `date` and `semver` become JSON Schema types, through every nested schema */
|
|
55
|
+
function migrateSchema(schema, path, migration) {
|
|
56
|
+
if (!isPlain(schema))
|
|
57
|
+
return schema;
|
|
58
|
+
let result = schema;
|
|
59
|
+
const target = typeof schema.type === "string" ? TYPES[schema.type] : undefined;
|
|
60
|
+
if (target) {
|
|
61
|
+
if (target.format && has(schema, "format") && schema.format !== target.format) {
|
|
62
|
+
migration.note([...path, "format"], `type: ${schema.type} becomes a string with format: ${target.format}, but the schema already has format: ${String(schema.format)}. Choose one.`, "attribute-and-schema-types");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
result = {};
|
|
66
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
67
|
+
if (key === "format" && target.format)
|
|
68
|
+
continue;
|
|
69
|
+
result[key] = key === "type" ? target.type : value;
|
|
70
|
+
if (key === "type" && target.format)
|
|
71
|
+
result.format = target.format;
|
|
72
|
+
}
|
|
73
|
+
migration.change("types");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (isPlain(result.properties)) {
|
|
77
|
+
const properties = {};
|
|
78
|
+
for (const [key, value] of Object.entries(result.properties)) {
|
|
79
|
+
properties[key] = migrateSchema(value, [...path, "properties", key], migration);
|
|
80
|
+
}
|
|
81
|
+
result = withKey(result, "properties", properties);
|
|
82
|
+
}
|
|
83
|
+
if (isPlain(result.items)) {
|
|
84
|
+
result = withKey(result, "items", migrateSchema(result.items, [...path, "items"], migration));
|
|
85
|
+
}
|
|
86
|
+
if (Array.isArray(result.oneOf)) {
|
|
87
|
+
const oneOf = result.oneOf.map((item, index) => migrateSchema(item, [...path, "oneOf", index], migration));
|
|
88
|
+
result = withKey(result, "oneOf", oneOf);
|
|
89
|
+
}
|
|
90
|
+
return (0, lines_1.same)(result, schema) ? schema : result;
|
|
91
|
+
}
|
|
92
|
+
// Selectors, as packages/sdk/src/normalize.ts reads them from v3 datafiles
|
|
93
|
+
/** v3 read an empty list or `and` group as everyone, where v4 reads it as no one */
|
|
94
|
+
function legacySegments(value, nested = false) {
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
const items = value.map((item) => legacySegments(item, true));
|
|
97
|
+
if (items.length === 0)
|
|
98
|
+
return "*";
|
|
99
|
+
// a list inside a list is an AND, which v4 writes as a group
|
|
100
|
+
return nested ? { and: items } : items;
|
|
101
|
+
}
|
|
102
|
+
if (!isPlain(value))
|
|
103
|
+
return value;
|
|
104
|
+
if (Array.isArray(value.and)) {
|
|
105
|
+
return value.and.length ? { and: value.and.map((item) => legacySegments(item, true)) } : "*";
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(value.or))
|
|
108
|
+
return { or: value.or.map((item) => legacySegments(item, true)) };
|
|
109
|
+
if (Array.isArray(value.not))
|
|
110
|
+
return { not: value.not.map((item) => legacySegments(item, true)) };
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
/** A required feature becomes a feature condition. v3's `required` named it `key`. */
|
|
114
|
+
function legacyFeature(value) {
|
|
115
|
+
if (typeof value === "string")
|
|
116
|
+
return { feature: value };
|
|
117
|
+
if (!isPlain(value))
|
|
118
|
+
return value;
|
|
119
|
+
if (Array.isArray(value.and))
|
|
120
|
+
return value.and.length ? { and: value.and.map(legacyFeature) } : "*";
|
|
121
|
+
if (Array.isArray(value.or))
|
|
122
|
+
return { or: value.or.map(legacyFeature) };
|
|
123
|
+
if (Array.isArray(value.not))
|
|
124
|
+
return { not: value.not.map(legacyFeature) };
|
|
125
|
+
if (!has(value, "feature") && typeof value.key === "string") {
|
|
126
|
+
const { key, ...rest } = value;
|
|
127
|
+
return { feature: key, ...rest };
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
const asList = (value) => (Array.isArray(value) ? value : [value]);
|
|
132
|
+
/**
|
|
133
|
+
* `"*"` is only valid as a whole expression in v4. Inside an AND it changes nothing, so it is
|
|
134
|
+
* dropped, and an OR holding it matches everyone.
|
|
135
|
+
*/
|
|
136
|
+
function tidy(conditions, path, migration) {
|
|
137
|
+
const list = (items) => items.map((item) => tidy(item, path, migration));
|
|
138
|
+
if (Array.isArray(conditions)) {
|
|
139
|
+
const items = list(conditions).filter((item) => item !== "*");
|
|
140
|
+
return items.length ? items : "*";
|
|
141
|
+
}
|
|
142
|
+
if (!isPlain(conditions))
|
|
143
|
+
return conditions;
|
|
144
|
+
if (Array.isArray(conditions.and)) {
|
|
145
|
+
const items = list(conditions.and).filter((item) => item !== "*");
|
|
146
|
+
return items.length ? { and: items } : "*";
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(conditions.or)) {
|
|
149
|
+
const items = list(conditions.or);
|
|
150
|
+
if (items.includes("*"))
|
|
151
|
+
return "*";
|
|
152
|
+
if (!items.length) {
|
|
153
|
+
migration.note(path, "An empty `or` group never matches. Remove the selector or give it conditions.", "strings-are-segments");
|
|
154
|
+
}
|
|
155
|
+
return { or: items };
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(conditions.not)) {
|
|
158
|
+
const items = list(conditions.not).filter((item) => item !== "*");
|
|
159
|
+
if (!items.length) {
|
|
160
|
+
migration.note(path, "This `not` group never matches. Remove the selector or give it conditions.", "strings-are-segments");
|
|
161
|
+
return conditions;
|
|
162
|
+
}
|
|
163
|
+
return { not: items };
|
|
164
|
+
}
|
|
165
|
+
return conditions;
|
|
166
|
+
}
|
|
167
|
+
const SELECTOR_KEYS = [
|
|
168
|
+
"conditions",
|
|
169
|
+
"segments",
|
|
170
|
+
"requiredFeatures",
|
|
171
|
+
"required",
|
|
172
|
+
"requiredVariables",
|
|
173
|
+
];
|
|
174
|
+
/**
|
|
175
|
+
* Moves a selector's v3 fields into `conditions`, ANDed in the order v4 SDKs read them from a
|
|
176
|
+
* v3 datafile: `conditions`, `segments`, then required features and variables. `conditions`
|
|
177
|
+
* takes the place of the first of them.
|
|
178
|
+
*/
|
|
179
|
+
function migrateSelector(entry, path, location, migration) {
|
|
180
|
+
if (!isPlain(entry))
|
|
181
|
+
return entry;
|
|
182
|
+
// v3 named required features `required` at a feature's root only. Elsewhere, such as in a
|
|
183
|
+
// global variable's schema, `required` lists object properties.
|
|
184
|
+
const present = SELECTOR_KEYS.filter((key) => has(entry, key) && (key !== "required" || location === "feature"));
|
|
185
|
+
const roots = ["feature", "variable", "rule"];
|
|
186
|
+
// v4 SDKs read v3 conditions on force entries and overrides as v3 read them
|
|
187
|
+
const legacy = !roots.includes(location);
|
|
188
|
+
if (present.length === 0) {
|
|
189
|
+
if (location === "variableOverride") {
|
|
190
|
+
// an override without a selector matched everyone, as v4 SDKs still read it
|
|
191
|
+
migration.change("conditions");
|
|
192
|
+
const result = {};
|
|
193
|
+
if (has(entry, "key"))
|
|
194
|
+
result.key = entry.key;
|
|
195
|
+
return Object.assign(result, { conditions: "*" }, entry);
|
|
196
|
+
}
|
|
197
|
+
if (location !== "feature" && location !== "variable") {
|
|
198
|
+
migration.note(path, "This selector has no conditions, so it never matches in v4. Give it `conditions`.", "unified-conditions");
|
|
199
|
+
}
|
|
200
|
+
return entry;
|
|
201
|
+
}
|
|
202
|
+
const parts = [];
|
|
203
|
+
if (has(entry, "conditions"))
|
|
204
|
+
parts.push(legacy ? legacySegments(entry.conditions) : entry.conditions);
|
|
205
|
+
if (has(entry, "segments"))
|
|
206
|
+
parts.push(legacySegments(entry.segments));
|
|
207
|
+
for (const key of ["requiredFeatures", "required"]) {
|
|
208
|
+
if (!has(entry, key))
|
|
209
|
+
continue;
|
|
210
|
+
const features = asList(entry[key]);
|
|
211
|
+
if (features.length)
|
|
212
|
+
parts.push(features.map(legacyFeature));
|
|
213
|
+
}
|
|
214
|
+
if (has(entry, "requiredVariables")) {
|
|
215
|
+
const variables = asList(entry.requiredVariables);
|
|
216
|
+
if (variables.length)
|
|
217
|
+
parts.push(variables);
|
|
218
|
+
}
|
|
219
|
+
let conditions;
|
|
220
|
+
if (parts.length === 0)
|
|
221
|
+
conditions = "*";
|
|
222
|
+
else if (parts.length === 1)
|
|
223
|
+
conditions = parts[0];
|
|
224
|
+
else
|
|
225
|
+
conditions = parts.flatMap((part) => (Array.isArray(part) ? part : [part]));
|
|
226
|
+
conditions = tidy(conditions, [...path, "conditions"], migration);
|
|
227
|
+
if (present.length === 1 && present[0] === "conditions" && (0, lines_1.same)(conditions, entry.conditions)) {
|
|
228
|
+
return entry;
|
|
229
|
+
}
|
|
230
|
+
const result = {};
|
|
231
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
232
|
+
if (!present.includes(key))
|
|
233
|
+
result[key] = value;
|
|
234
|
+
else if (!has(result, "conditions"))
|
|
235
|
+
result.conditions = conditions;
|
|
236
|
+
}
|
|
237
|
+
migration.change("conditions");
|
|
238
|
+
migration.renames.push({ path, from: present, to: "conditions" });
|
|
239
|
+
if (present.includes("required")) {
|
|
240
|
+
migration.note([...path, "required"], "v4 SDKs ignore `required` in datafiles the v3 CLI built. Publish datafiles built with `requiredFeatures` by the v3 CLI before upgrading SDKs.", "prepare-while-still-on-v3");
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
/** Each entry of a list, or of a map of environments to lists */
|
|
245
|
+
function eachEntry(value, path, migrate) {
|
|
246
|
+
if (Array.isArray(value))
|
|
247
|
+
return value.map((entry, index) => migrate(entry, [...path, index]));
|
|
248
|
+
if (!isPlain(value))
|
|
249
|
+
return value;
|
|
250
|
+
const result = {};
|
|
251
|
+
for (const [environment, entries] of Object.entries(value)) {
|
|
252
|
+
result[environment] = Array.isArray(entries)
|
|
253
|
+
? entries.map((entry, index) => migrate(entry, [...path, environment, index]))
|
|
254
|
+
: entries;
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
// Conditions that v4 lint rejects for an attribute's type
|
|
259
|
+
const DATE_OPERATORS = ["before", "after", "exists", "notExists", "isNull", "notNull"];
|
|
260
|
+
function attributeSchema(attributes, name) {
|
|
261
|
+
const [key, ...properties] = name.split(".");
|
|
262
|
+
let schema = attributes[key];
|
|
263
|
+
for (const property of properties) {
|
|
264
|
+
schema =
|
|
265
|
+
isPlain(schema) && isPlain(schema.properties) ? schema.properties[property] : undefined;
|
|
266
|
+
}
|
|
267
|
+
return schema;
|
|
268
|
+
}
|
|
269
|
+
/** Whether every value the schema allows is a number or a boolean */
|
|
270
|
+
function isNotString(schema) {
|
|
271
|
+
if (!isPlain(schema))
|
|
272
|
+
return false;
|
|
273
|
+
if (Array.isArray(schema.oneOf))
|
|
274
|
+
return schema.oneOf.length > 0 && schema.oneOf.every(isNotString);
|
|
275
|
+
return ["integer", "number", "boolean"].includes(schema.type);
|
|
276
|
+
}
|
|
277
|
+
/** `in` and `notIn` on numbers become `equals` groups, and date comparisons are reported */
|
|
278
|
+
function migrateConditions(conditions, path, attributes, migration) {
|
|
279
|
+
if (Array.isArray(conditions)) {
|
|
280
|
+
return conditions.map((item, index) => migrateConditions(item, [...path, index], attributes, migration));
|
|
281
|
+
}
|
|
282
|
+
if (!isPlain(conditions))
|
|
283
|
+
return conditions;
|
|
284
|
+
for (const group of ["and", "or", "not"]) {
|
|
285
|
+
if (Array.isArray(conditions[group])) {
|
|
286
|
+
return withKey(conditions, group, migrateConditions(conditions[group], [...path, group], attributes, migration));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (typeof conditions.attribute !== "string")
|
|
290
|
+
return conditions;
|
|
291
|
+
const schema = attributeSchema(attributes, conditions.attribute);
|
|
292
|
+
const { operator } = conditions;
|
|
293
|
+
if (isPlain(schema) &&
|
|
294
|
+
schema.format === "date-time" &&
|
|
295
|
+
!DATE_OPERATORS.includes(operator)) {
|
|
296
|
+
migration.note(path, `${conditions.attribute} holds a timestamp, which v4 compares with before and after only. Rewrite \`${String(operator)}\` for what you meant.`, "date-attribute-comparisons");
|
|
297
|
+
}
|
|
298
|
+
if ((operator === "in" || operator === "notIn") && isNotString(schema)) {
|
|
299
|
+
if (!Array.isArray(conditions.value) || conditions.value.length === 0) {
|
|
300
|
+
migration.note(path, `\`${operator}\` with no values needs rewriting by hand.`, "string-membership-conditions");
|
|
301
|
+
return conditions;
|
|
302
|
+
}
|
|
303
|
+
const equals = conditions.value.map((value) => ({
|
|
304
|
+
attribute: conditions.attribute,
|
|
305
|
+
operator: "equals",
|
|
306
|
+
value,
|
|
307
|
+
}));
|
|
308
|
+
migration.change("operators");
|
|
309
|
+
return operator === "in" ? { or: equals } : { not: [{ or: equals }] };
|
|
310
|
+
}
|
|
311
|
+
return conditions;
|
|
312
|
+
}
|
|
313
|
+
/** A selector moved into `conditions`, with those conditions migrated */
|
|
314
|
+
function migrateWhole(entry, path, location, attributes, migration) {
|
|
315
|
+
const result = migrateSelector(entry, path, location, migration);
|
|
316
|
+
if (!isPlain(result) || !has(result, "conditions"))
|
|
317
|
+
return result;
|
|
318
|
+
const conditions = migrateConditions(result.conditions, [...path, "conditions"], attributes, migration);
|
|
319
|
+
return (0, lines_1.same)(conditions, result.conditions) ? result : withKey(result, "conditions", conditions);
|
|
320
|
+
}
|
|
321
|
+
function migrateVariableOverrides(entry, path, attributes, migration) {
|
|
322
|
+
if (!isPlain(entry) || !isPlain(entry.variableOverrides))
|
|
323
|
+
return entry;
|
|
324
|
+
const overrides = {};
|
|
325
|
+
for (const [variable, list] of Object.entries(entry.variableOverrides)) {
|
|
326
|
+
overrides[variable] = Array.isArray(list)
|
|
327
|
+
? list.map((override, index) => migrateWhole(override, [...path, "variableOverrides", variable, index], "featureVariableOverride", attributes, migration))
|
|
328
|
+
: list;
|
|
329
|
+
}
|
|
330
|
+
return withKey(entry, "variableOverrides", overrides);
|
|
331
|
+
}
|
|
332
|
+
// Definitions
|
|
333
|
+
function migrateAttribute(value, migration) {
|
|
334
|
+
return migrateSchema(value, [], migration);
|
|
335
|
+
}
|
|
336
|
+
function migrateSegment(value, attributes, migration) {
|
|
337
|
+
if (!isPlain(value) || !has(value, "conditions"))
|
|
338
|
+
return value;
|
|
339
|
+
const legacy = tidy(legacySegments(value.conditions), ["conditions"], migration);
|
|
340
|
+
if (!(0, lines_1.same)(legacy, value.conditions))
|
|
341
|
+
migration.change("conditions");
|
|
342
|
+
const conditions = migrateConditions(legacy, ["conditions"], attributes, migration);
|
|
343
|
+
return (0, lines_1.same)(conditions, value.conditions) ? value : withKey(value, "conditions", conditions);
|
|
344
|
+
}
|
|
345
|
+
function migrateFeature(value, attributes, migration) {
|
|
346
|
+
if (!isPlain(value))
|
|
347
|
+
return value;
|
|
348
|
+
const whole = (location) => (entry, path) => migrateWhole(entry, path, location, attributes, migration);
|
|
349
|
+
let feature = whole("feature")(value, []);
|
|
350
|
+
if (isPlain(feature.variablesSchema)) {
|
|
351
|
+
const schema = {};
|
|
352
|
+
for (const [key, item] of Object.entries(feature.variablesSchema)) {
|
|
353
|
+
schema[key] = migrateSchema(item, ["variablesSchema", key], migration);
|
|
354
|
+
}
|
|
355
|
+
feature = withKey(feature, "variablesSchema", schema);
|
|
356
|
+
}
|
|
357
|
+
if (has(feature, "rules")) {
|
|
358
|
+
const rules = eachEntry(feature.rules, ["rules"], (rule, path) => migrateVariableOverrides(whole("rule")(rule, path), path, attributes, migration));
|
|
359
|
+
feature = withKey(feature, "rules", rules);
|
|
360
|
+
}
|
|
361
|
+
if (has(feature, "force")) {
|
|
362
|
+
feature = withKey(feature, "force", eachEntry(feature.force, ["force"], whole("force")));
|
|
363
|
+
}
|
|
364
|
+
if (Array.isArray(feature.variations)) {
|
|
365
|
+
const variations = feature.variations.map((variation, index) => migrateVariableOverrides(variation, ["variations", index], attributes, migration));
|
|
366
|
+
feature = withKey(feature, "variations", variations);
|
|
367
|
+
}
|
|
368
|
+
return keepMutationOrder(feature, migration);
|
|
369
|
+
}
|
|
370
|
+
/** Puts each mutation map whose v4 result differs from v3's in the order v3 applied it */
|
|
371
|
+
function keepMutationOrder(feature, migration) {
|
|
372
|
+
let changes;
|
|
373
|
+
try {
|
|
374
|
+
changes = (0, mutationOrder_1.getMutationOrderChanges)(feature);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return feature;
|
|
378
|
+
}
|
|
379
|
+
let result = feature;
|
|
380
|
+
for (const { path } of changes) {
|
|
381
|
+
result = updateAt(result, path, (map) => {
|
|
382
|
+
if (!isPlain(map))
|
|
383
|
+
return map;
|
|
384
|
+
// v3 applied the shortest paths first
|
|
385
|
+
return Object.fromEntries(Object.entries(map).sort(([a], [b]) => a.length - b.length));
|
|
386
|
+
});
|
|
387
|
+
migration.change("mutation order");
|
|
388
|
+
}
|
|
389
|
+
return result;
|
|
390
|
+
}
|
|
391
|
+
function updateAt(value, path, update) {
|
|
392
|
+
if (path.length === 0)
|
|
393
|
+
return update(value);
|
|
394
|
+
const [key, ...rest] = path;
|
|
395
|
+
if (Array.isArray(value) && typeof key === "number") {
|
|
396
|
+
return value.map((item, index) => (index === key ? updateAt(item, rest, update) : item));
|
|
397
|
+
}
|
|
398
|
+
if (isPlain(value) && typeof key === "string" && has(value, key)) {
|
|
399
|
+
return withKey(value, key, updateAt(value[key], rest, update));
|
|
400
|
+
}
|
|
401
|
+
return value;
|
|
402
|
+
}
|
|
403
|
+
function migrateVariable(value, attributes, migration) {
|
|
404
|
+
if (!isPlain(value))
|
|
405
|
+
return value;
|
|
406
|
+
let variable = migrateSchema(value, [], migration);
|
|
407
|
+
variable = migrateWhole(variable, [], "variable", attributes, migration);
|
|
408
|
+
if (has(variable, "overrides")) {
|
|
409
|
+
const override = (entry, path) => {
|
|
410
|
+
let result = migrateWhole(entry, path, "variableOverride", attributes, migration);
|
|
411
|
+
if (isPlain(result) && has(result, "overrides")) {
|
|
412
|
+
result = withKey(result, "overrides", eachEntry(result.overrides, [...path, "overrides"], override));
|
|
413
|
+
}
|
|
414
|
+
return result;
|
|
415
|
+
};
|
|
416
|
+
variable = withKey(variable, "overrides", eachEntry(variable.overrides, ["overrides"], override));
|
|
417
|
+
}
|
|
418
|
+
return variable;
|
|
419
|
+
}
|
|
420
|
+
const REMOVED_REASONS = ["required", "required_features_unmet"];
|
|
421
|
+
/** An expected evaluation's removed reasons and fields */
|
|
422
|
+
function migrateEvaluation(evaluation, path, migration) {
|
|
423
|
+
if (!isPlain(evaluation))
|
|
424
|
+
return evaluation;
|
|
425
|
+
let result = evaluation;
|
|
426
|
+
if (REMOVED_REASONS.includes(result.reason)) {
|
|
427
|
+
result = withKey(result, "reason", "conditions_unmet");
|
|
428
|
+
migration.change("evaluations");
|
|
429
|
+
}
|
|
430
|
+
for (const key of ["requiredFeatures", "requiredVariables"]) {
|
|
431
|
+
if (!has(result, key))
|
|
432
|
+
continue;
|
|
433
|
+
result = withKey(result, key, undefined);
|
|
434
|
+
migration.change("evaluations");
|
|
435
|
+
migration.note([...path, key], `Removed \`${key}\` from this expected evaluation. v4 evaluations have no such field, and \`reason: conditions_unmet\` covers an unmet dependency.`, "evaluation-details-and-tests");
|
|
436
|
+
}
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
function migrateAssertion(assertion, path, feature, migration) {
|
|
440
|
+
if (!isPlain(assertion))
|
|
441
|
+
return assertion;
|
|
442
|
+
let result = assertion;
|
|
443
|
+
if (feature && has(result, "sticky")) {
|
|
444
|
+
if (has(result, "stickyFeatures")) {
|
|
445
|
+
migration.note([...path, "sticky"], "This assertion has both `sticky` and `stickyFeatures`. Merge them into `stickyFeatures`.", "sticky-values-in-feature-specs");
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
const renamed = {};
|
|
449
|
+
for (const [key, value] of Object.entries(result))
|
|
450
|
+
renamed[key === "sticky" ? "stickyFeatures" : key] = value;
|
|
451
|
+
result = renamed;
|
|
452
|
+
migration.change("stickyFeatures");
|
|
453
|
+
migration.renames.push({ path, from: ["sticky"], to: "stickyFeatures" });
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (has(result, "expectedEvaluation")) {
|
|
457
|
+
result = withKey(result, "expectedEvaluation", migrateEvaluation(result.expectedEvaluation, [...path, "expectedEvaluation"], migration));
|
|
458
|
+
}
|
|
459
|
+
if (isPlain(result.expectedEvaluations)) {
|
|
460
|
+
const evaluations = {};
|
|
461
|
+
for (const [kind, evaluation] of Object.entries(result.expectedEvaluations)) {
|
|
462
|
+
const at = [...path, "expectedEvaluations", kind];
|
|
463
|
+
if (kind === "variables" && isPlain(evaluation)) {
|
|
464
|
+
const variables = {};
|
|
465
|
+
for (const [key, item] of Object.entries(evaluation))
|
|
466
|
+
variables[key] = migrateEvaluation(item, [...at, key], migration);
|
|
467
|
+
evaluations[kind] = variables;
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
evaluations[kind] = migrateEvaluation(evaluation, at, migration);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
result = withKey(result, "expectedEvaluations", evaluations);
|
|
474
|
+
}
|
|
475
|
+
if (Array.isArray(result.children)) {
|
|
476
|
+
const children = result.children.map((child, index) => migrateAssertion(child, [...path, "children", index], feature, migration));
|
|
477
|
+
result = withKey(result, "children", children);
|
|
478
|
+
}
|
|
479
|
+
return (0, lines_1.same)(result, assertion) ? assertion : result;
|
|
480
|
+
}
|
|
481
|
+
function migrateTest(value, migration) {
|
|
482
|
+
if (!isPlain(value) || !Array.isArray(value.assertions))
|
|
483
|
+
return value;
|
|
484
|
+
const feature = typeof value.feature === "string";
|
|
485
|
+
const assertions = value.assertions.map((assertion, index) => migrateAssertion(assertion, ["assertions", index], feature, migration));
|
|
486
|
+
return (0, lines_1.same)(assertions, value.assertions) ? value : withKey(value, "assertions", assertions);
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=definitions.js.map
|