@featurevisor/core 3.1.0 → 3.3.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/datasource/datasource.d.ts +1 -1
- package/lib/datasource/datasource.js +4 -14
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/requiredFeatures.d.ts +7 -0
- package/lib/datasource/requiredFeatures.js +38 -0
- package/lib/datasource/requiredFeatures.js.map +1 -0
- package/lib/linter/checkCircularDependency.d.ts +1 -1
- package/lib/linter/checkCircularDependency.js +3 -22
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/conditionSchema.js +27 -3
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +4 -0
- package/lib/linter/testSchema.js +46 -4
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/promoter/index.js +62 -1
- package/lib/promoter/index.js.map +1 -1
- package/lib/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2246
- package/coverage/clover.xml +0 -5456
- package/coverage/coverage-final.json +0 -64
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -371
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
- package/coverage/lcov-report/src/benchmark/index.html +0 -116
- package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
- package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
- package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
- package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
- package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
- package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
- package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
- package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
- package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
- package/coverage/lcov-report/src/builder/index.html +0 -311
- package/coverage/lcov-report/src/builder/index.ts.html +0 -91
- package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
- package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
- package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
- package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
- package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
- package/coverage/lcov-report/src/cli/index.html +0 -131
- package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
- package/coverage/lcov-report/src/config/index.html +0 -131
- package/coverage/lcov-report/src/config/index.ts.html +0 -88
- package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
- package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
- package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
- package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
- package/coverage/lcov-report/src/datasource/index.html +0 -161
- package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
- package/coverage/lcov-report/src/evaluate/index.html +0 -116
- package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
- package/coverage/lcov-report/src/find-usage/index.html +0 -116
- package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
- package/coverage/lcov-report/src/generate-code/index.html +0 -131
- package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
- package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/info/index.html +0 -116
- package/coverage/lcov-report/src/info/index.ts.html +0 -472
- package/coverage/lcov-report/src/init/index.html +0 -116
- package/coverage/lcov-report/src/init/index.ts.html +0 -280
- package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
- package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
- package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
- package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
- package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
- package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
- package/coverage/lcov-report/src/linter/index.html +0 -326
- package/coverage/lcov-report/src/linter/index.ts.html +0 -88
- package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
- package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
- package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
- package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
- package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
- package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
- package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
- package/coverage/lcov-report/src/list/index.html +0 -131
- package/coverage/lcov-report/src/list/index.ts.html +0 -2065
- package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
- package/coverage/lcov-report/src/promoter/index.html +0 -116
- package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
- package/coverage/lcov-report/src/sets.ts.html +0 -313
- package/coverage/lcov-report/src/targeting.ts.html +0 -403
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
- package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
- package/coverage/lcov-report/src/tester/index.html +0 -206
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
- package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
- package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
- package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
- package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
- package/coverage/lcov-report/src/utils/git.ts.html +0 -559
- package/coverage/lcov-report/src/utils/index.html +0 -161
- package/coverage/lcov-report/src/utils/index.ts.html +0 -94
- package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
- package/coverage/lcov.info +0 -11615
- package/jest.config.js +0 -22
- package/json-schema/README.md +0 -5
- package/json-schema/attribute.json +0 -40
- package/json-schema/feature.json +0 -394
- package/json-schema/segment.json +0 -137
- package/src/assess-distribution/index.ts +0 -223
- package/src/benchmark/index.ts +0 -236
- package/src/builder/allocator.spec.ts +0 -105
- package/src/builder/allocator.ts +0 -45
- package/src/builder/applyContextToConditions.spec.ts +0 -2677
- package/src/builder/applyContextToConditions.ts +0 -139
- package/src/builder/applyContextToDatafile.spec.ts +0 -2626
- package/src/builder/applyContextToDatafile.ts +0 -229
- package/src/builder/applyContextToSegments.spec.ts +0 -1593
- package/src/builder/applyContextToSegments.ts +0 -165
- package/src/builder/buildDatafile.spec.ts +0 -445
- package/src/builder/buildDatafile.ts +0 -656
- package/src/builder/buildProject.ts +0 -344
- package/src/builder/buildRuntimeDatafiles.ts +0 -57
- package/src/builder/getFeatureRanges.ts +0 -61
- package/src/builder/hashes.ts +0 -109
- package/src/builder/index.ts +0 -2
- package/src/builder/mutateVariables.spec.ts +0 -1179
- package/src/builder/mutateVariables.ts +0 -112
- package/src/builder/mutator.spec.ts +0 -413
- package/src/builder/mutator.ts +0 -237
- package/src/builder/revision.spec.ts +0 -22
- package/src/builder/revision.ts +0 -22
- package/src/builder/traffic.spec.ts +0 -946
- package/src/builder/traffic.ts +0 -192
- package/src/cli/cli.ts +0 -105
- package/src/cli/index.ts +0 -2
- package/src/cli/plugins.ts +0 -43
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.spec.ts +0 -194
- package/src/config/projectConfig.ts +0 -280
- package/src/datasource/adapter.ts +0 -56
- package/src/datasource/datasource.ts +0 -305
- package/src/datasource/filesystemAdapter.spec.ts +0 -212
- package/src/datasource/filesystemAdapter.ts +0 -497
- package/src/datasource/index.ts +0 -3
- package/src/dependencies.ts +0 -13
- package/src/evaluate/index.ts +0 -243
- package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
- package/src/find-duplicate-segments/index.ts +0 -74
- package/src/find-usage/index.ts +0 -565
- package/src/generate-code/index.ts +0 -106
- package/src/generate-code/typescript.spec.ts +0 -214
- package/src/generate-code/typescript.ts +0 -608
- package/src/index.ts +0 -20
- package/src/info/index.ts +0 -129
- package/src/init/index.ts +0 -65
- package/src/linter/attributeSchema.spec.ts +0 -342
- package/src/linter/attributeSchema.ts +0 -626
- package/src/linter/checkCircularDependency.ts +0 -45
- package/src/linter/checkPercentageExceedingSlot.ts +0 -61
- package/src/linter/conditionSchema.spec.ts +0 -510
- package/src/linter/conditionSchema.ts +0 -713
- package/src/linter/featureSchema.spec.ts +0 -1985
- package/src/linter/featureSchema.ts +0 -1922
- package/src/linter/groupSchema.ts +0 -47
- package/src/linter/index.ts +0 -1
- package/src/linter/lintProject.spec.ts +0 -336
- package/src/linter/lintProject.ts +0 -873
- package/src/linter/mutationNotation.spec.ts +0 -704
- package/src/linter/mutationNotation.ts +0 -442
- package/src/linter/printError.ts +0 -68
- package/src/linter/schema.spec.ts +0 -690
- package/src/linter/schema.ts +0 -491
- package/src/linter/segmentSchema.spec.ts +0 -358
- package/src/linter/segmentSchema.ts +0 -18
- package/src/linter/targetSchema.spec.ts +0 -159
- package/src/linter/targetSchema.ts +0 -46
- package/src/linter/testSchema.spec.ts +0 -258
- package/src/linter/testSchema.ts +0 -148
- package/src/linter/zodHelpers.ts +0 -16
- package/src/list/index.spec.ts +0 -135
- package/src/list/index.ts +0 -660
- package/src/list/matrix.spec.ts +0 -49
- package/src/list/matrix.ts +0 -212
- package/src/promoter/index.spec.ts +0 -617
- package/src/promoter/index.ts +0 -1266
- package/src/sets.ts +0 -76
- package/src/targeting.spec.ts +0 -74
- package/src/targeting.ts +0 -106
- package/src/tester/cliFormat.ts +0 -16
- package/src/tester/helpers.spec.ts +0 -149
- package/src/tester/helpers.ts +0 -76
- package/src/tester/index.ts +0 -2
- package/src/tester/prettyDuration.ts +0 -34
- package/src/tester/printTestResult.ts +0 -84
- package/src/tester/testFeature.ts +0 -367
- package/src/tester/testProject.spec.ts +0 -50
- package/src/tester/testProject.ts +0 -311
- package/src/tester/testSegment.ts +0 -77
- package/src/utils/extractKeys.ts +0 -136
- package/src/utils/git.ts +0 -158
- package/src/utils/index.ts +0 -3
- package/src/utils/pretty.ts +0 -12
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.typecheck.json +0 -9
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
|
|
3
|
-
import type { BucketBy } from "@featurevisor/types";
|
|
4
|
-
import { Parser, parsers } from "@featurevisor/parsers";
|
|
5
|
-
|
|
6
|
-
import { FilesystemAdapter } from "../datasource/filesystemAdapter";
|
|
7
|
-
import type { Plugin } from "../cli";
|
|
8
|
-
import { CLI_COLOR_CYAN, CLI_FORMAT_BOLD, colorize } from "../tester/cliFormat";
|
|
9
|
-
|
|
10
|
-
export const FEATURES_DIRECTORY_NAME = "features";
|
|
11
|
-
export const SEGMENTS_DIRECTORY_NAME = "segments";
|
|
12
|
-
export const ATTRIBUTES_DIRECTORY_NAME = "attributes";
|
|
13
|
-
export const GROUPS_DIRECTORY_NAME = "groups";
|
|
14
|
-
export const SCHEMAS_DIRECTORY_NAME = "schemas";
|
|
15
|
-
export const TARGETS_DIRECTORY_NAME = "targets";
|
|
16
|
-
export const TESTS_DIRECTORY_NAME = "tests";
|
|
17
|
-
export const STATE_DIRECTORY_NAME = ".featurevisor";
|
|
18
|
-
export const DATAFILES_DIRECTORY_NAME = "datafiles";
|
|
19
|
-
export const DATAFILE_NAME_PATTERN = "featurevisor-%s.json";
|
|
20
|
-
export const REVISION_FILE_NAME = "REVISION";
|
|
21
|
-
export const CATALOG_DIRECTORY_NAME = "catalog";
|
|
22
|
-
export const SETS_DIRECTORY_NAME = "sets";
|
|
23
|
-
|
|
24
|
-
export const CONFIG_MODULE_NAME = "featurevisor.config.js";
|
|
25
|
-
export const ROOT_DIR_PLACEHOLDER = "<rootDir>";
|
|
26
|
-
|
|
27
|
-
export const DEFAULT_NAMESPACE_CHARACTER = ".";
|
|
28
|
-
export const DEFAULT_TAGS = ["all"];
|
|
29
|
-
export const DEFAULT_BUCKET_BY_ATTRIBUTE = "userId";
|
|
30
|
-
export const DEFAULT_SETS = false;
|
|
31
|
-
|
|
32
|
-
export const DEFAULT_PRETTY_STATE = true;
|
|
33
|
-
export const DEFAULT_PRETTY_DATAFILE = false;
|
|
34
|
-
|
|
35
|
-
export const DEFAULT_PARSER: Parser = "yml";
|
|
36
|
-
|
|
37
|
-
export interface ProjectConfig {
|
|
38
|
-
promotionFlows?: Array<{
|
|
39
|
-
from: string;
|
|
40
|
-
to: string;
|
|
41
|
-
}>;
|
|
42
|
-
namespaceCharacter: string;
|
|
43
|
-
featuresDirectoryPath: string;
|
|
44
|
-
segmentsDirectoryPath: string;
|
|
45
|
-
attributesDirectoryPath: string;
|
|
46
|
-
groupsDirectoryPath: string;
|
|
47
|
-
schemasDirectoryPath: string;
|
|
48
|
-
targetsDirectoryPath: string;
|
|
49
|
-
testsDirectoryPath: string;
|
|
50
|
-
stateDirectoryPath: string;
|
|
51
|
-
datafilesDirectoryPath: string;
|
|
52
|
-
datafileNamePattern: string;
|
|
53
|
-
revisionFileName: string;
|
|
54
|
-
catalogDirectoryPath: string;
|
|
55
|
-
setsDirectoryPath: string;
|
|
56
|
-
|
|
57
|
-
environments?: string[];
|
|
58
|
-
sets: boolean;
|
|
59
|
-
tags: string[];
|
|
60
|
-
|
|
61
|
-
adapter: any; // @NOTE: type this properly later
|
|
62
|
-
plugins: Plugin[];
|
|
63
|
-
|
|
64
|
-
defaultBucketBy: BucketBy;
|
|
65
|
-
parser: Parser;
|
|
66
|
-
|
|
67
|
-
prettyState: boolean;
|
|
68
|
-
prettyDatafile: boolean;
|
|
69
|
-
stringify: boolean;
|
|
70
|
-
|
|
71
|
-
enforceCatchAllRule?: boolean;
|
|
72
|
-
maxVariableStringLength?: number;
|
|
73
|
-
maxVariableArrayStringifiedLength?: number;
|
|
74
|
-
maxVariableObjectStringifiedLength?: number;
|
|
75
|
-
maxVariableJSONStringifiedLength?: number;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// rootDirectoryPath: path to the root directory of the project (without ending with a slash)
|
|
79
|
-
export function getProjectConfig(rootDirectoryPath: string): ProjectConfig {
|
|
80
|
-
const baseConfig: ProjectConfig = {
|
|
81
|
-
environments: undefined,
|
|
82
|
-
sets: DEFAULT_SETS,
|
|
83
|
-
promotionFlows: undefined,
|
|
84
|
-
namespaceCharacter: DEFAULT_NAMESPACE_CHARACTER,
|
|
85
|
-
tags: DEFAULT_TAGS,
|
|
86
|
-
defaultBucketBy: "userId",
|
|
87
|
-
|
|
88
|
-
parser: DEFAULT_PARSER,
|
|
89
|
-
|
|
90
|
-
prettyState: DEFAULT_PRETTY_STATE,
|
|
91
|
-
prettyDatafile: DEFAULT_PRETTY_DATAFILE,
|
|
92
|
-
stringify: true,
|
|
93
|
-
|
|
94
|
-
adapter: FilesystemAdapter,
|
|
95
|
-
|
|
96
|
-
featuresDirectoryPath: path.join(rootDirectoryPath, FEATURES_DIRECTORY_NAME),
|
|
97
|
-
setsDirectoryPath: path.join(rootDirectoryPath, SETS_DIRECTORY_NAME),
|
|
98
|
-
segmentsDirectoryPath: path.join(rootDirectoryPath, SEGMENTS_DIRECTORY_NAME),
|
|
99
|
-
attributesDirectoryPath: path.join(rootDirectoryPath, ATTRIBUTES_DIRECTORY_NAME),
|
|
100
|
-
groupsDirectoryPath: path.join(rootDirectoryPath, GROUPS_DIRECTORY_NAME),
|
|
101
|
-
schemasDirectoryPath: path.join(rootDirectoryPath, SCHEMAS_DIRECTORY_NAME),
|
|
102
|
-
targetsDirectoryPath: path.join(rootDirectoryPath, TARGETS_DIRECTORY_NAME),
|
|
103
|
-
testsDirectoryPath: path.join(rootDirectoryPath, TESTS_DIRECTORY_NAME),
|
|
104
|
-
stateDirectoryPath: path.join(rootDirectoryPath, STATE_DIRECTORY_NAME),
|
|
105
|
-
datafilesDirectoryPath: path.join(rootDirectoryPath, DATAFILES_DIRECTORY_NAME),
|
|
106
|
-
datafileNamePattern: DATAFILE_NAME_PATTERN,
|
|
107
|
-
revisionFileName: REVISION_FILE_NAME,
|
|
108
|
-
catalogDirectoryPath: path.join(rootDirectoryPath, CATALOG_DIRECTORY_NAME),
|
|
109
|
-
|
|
110
|
-
enforceCatchAllRule: false,
|
|
111
|
-
plugins: [],
|
|
112
|
-
|
|
113
|
-
maxVariableStringLength: undefined,
|
|
114
|
-
maxVariableArrayStringifiedLength: undefined,
|
|
115
|
-
maxVariableObjectStringifiedLength: undefined,
|
|
116
|
-
maxVariableJSONStringifiedLength: undefined,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const configModulePath = path.join(rootDirectoryPath, CONFIG_MODULE_NAME);
|
|
120
|
-
const customConfig = require(configModulePath);
|
|
121
|
-
|
|
122
|
-
const mergedConfig = {};
|
|
123
|
-
|
|
124
|
-
Object.keys(baseConfig).forEach((key) => {
|
|
125
|
-
mergedConfig[key] =
|
|
126
|
-
typeof customConfig[key] !== "undefined" ? customConfig[key] : baseConfig[key];
|
|
127
|
-
|
|
128
|
-
if (key.endsWith("Path") && mergedConfig[key].indexOf(ROOT_DIR_PLACEHOLDER) !== -1) {
|
|
129
|
-
mergedConfig[key] = mergedConfig[key].replace(ROOT_DIR_PLACEHOLDER, rootDirectoryPath);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const finalConfig = mergedConfig as ProjectConfig;
|
|
134
|
-
|
|
135
|
-
if (typeof finalConfig.parser === "string") {
|
|
136
|
-
const allowedParsers = Object.keys(parsers);
|
|
137
|
-
if (allowedParsers.indexOf(finalConfig.parser) === -1) {
|
|
138
|
-
throw new Error(`Invalid parser: ${finalConfig.parser}`);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
finalConfig.parser = parsers[finalConfig.parser];
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (typeof finalConfig.sets !== "boolean") {
|
|
145
|
-
throw new Error(`Invalid sets: ${finalConfig.sets}. It must be a boolean.`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (typeof finalConfig.environments !== "undefined") {
|
|
149
|
-
if (!Array.isArray(finalConfig.environments)) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
`Invalid environments: ${finalConfig.environments}. It must be an array of strings when defined.`,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
finalConfig.environments.forEach((environment: unknown, index: number) => {
|
|
156
|
-
if (typeof environment !== "string") {
|
|
157
|
-
throw new Error(`Invalid environments[${index}]: ${environment}. It must be a string.`);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (
|
|
163
|
-
typeof finalConfig.namespaceCharacter !== "string" ||
|
|
164
|
-
finalConfig.namespaceCharacter.length === 0
|
|
165
|
-
) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`Invalid namespaceCharacter: ${finalConfig.namespaceCharacter}. It must be a non-empty string.`,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (typeof finalConfig.promotionFlows !== "undefined") {
|
|
172
|
-
if (!Array.isArray(finalConfig.promotionFlows)) {
|
|
173
|
-
throw new Error(
|
|
174
|
-
`Invalid promotionFlows: ${finalConfig.promotionFlows}. It must be an array.`,
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
finalConfig.promotionFlows.forEach((entry: any, index: number) => {
|
|
179
|
-
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
`Invalid promotionFlows[${index}]: ${entry}. Each entry must be an object with exactly "from" and "to" string fields.`,
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const keys = Object.keys(entry).sort();
|
|
186
|
-
|
|
187
|
-
if (keys.length !== 2 || keys[0] !== "from" || keys[1] !== "to") {
|
|
188
|
-
throw new Error(
|
|
189
|
-
`Invalid promotionFlows[${index}]: ${JSON.stringify(entry)}. Each entry must contain exactly "from" and "to".`,
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (typeof entry.from !== "string" || typeof entry.to !== "string") {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`Invalid promotionFlows[${index}]: ${JSON.stringify(entry)}. "from" and "to" must be strings.`,
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return finalConfig as ProjectConfig;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function getProjectConfigForSet(projectConfig: ProjectConfig, set: string): ProjectConfig {
|
|
205
|
-
const setRootDirectoryPath = path.join(projectConfig.setsDirectoryPath, set);
|
|
206
|
-
|
|
207
|
-
return {
|
|
208
|
-
...projectConfig,
|
|
209
|
-
featuresDirectoryPath: path.join(setRootDirectoryPath, FEATURES_DIRECTORY_NAME),
|
|
210
|
-
segmentsDirectoryPath: path.join(setRootDirectoryPath, SEGMENTS_DIRECTORY_NAME),
|
|
211
|
-
attributesDirectoryPath: path.join(setRootDirectoryPath, ATTRIBUTES_DIRECTORY_NAME),
|
|
212
|
-
groupsDirectoryPath: path.join(setRootDirectoryPath, GROUPS_DIRECTORY_NAME),
|
|
213
|
-
schemasDirectoryPath: path.join(setRootDirectoryPath, SCHEMAS_DIRECTORY_NAME),
|
|
214
|
-
targetsDirectoryPath: path.join(setRootDirectoryPath, TARGETS_DIRECTORY_NAME),
|
|
215
|
-
testsDirectoryPath: path.join(setRootDirectoryPath, TESTS_DIRECTORY_NAME),
|
|
216
|
-
stateDirectoryPath: path.join(projectConfig.stateDirectoryPath, SETS_DIRECTORY_NAME, set),
|
|
217
|
-
datafilesDirectoryPath: path.join(projectConfig.datafilesDirectoryPath, set),
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export interface ShowProjectConfigOptions {
|
|
222
|
-
json?: boolean;
|
|
223
|
-
pretty?: boolean;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function showProjectConfig(
|
|
227
|
-
projectConfig: ProjectConfig,
|
|
228
|
-
options: ShowProjectConfigOptions = {},
|
|
229
|
-
) {
|
|
230
|
-
if (options.json) {
|
|
231
|
-
console.log(
|
|
232
|
-
options.pretty ? JSON.stringify(projectConfig, null, 2) : JSON.stringify(projectConfig),
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
console.log("");
|
|
239
|
-
console.log(CLI_FORMAT_BOLD, "Project configuration");
|
|
240
|
-
console.log("");
|
|
241
|
-
|
|
242
|
-
const keys = Object.keys(projectConfig);
|
|
243
|
-
const longestKeyLength = keys.reduce((acc, key) => (key.length > acc ? key.length : acc), 0);
|
|
244
|
-
const ignoreKeys = ["adapter", "parser"];
|
|
245
|
-
|
|
246
|
-
for (const key of keys) {
|
|
247
|
-
if (ignoreKeys.indexOf(key) !== -1) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
console.log(
|
|
252
|
-
` ${colorize(key.padEnd(longestKeyLength, " "), CLI_COLOR_CYAN)}: ${projectConfig[key]}`,
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
export const configPlugin: Plugin = {
|
|
258
|
-
command: "config",
|
|
259
|
-
handler: async ({ rootDirectoryPath, parsed }) => {
|
|
260
|
-
const projectConfig = getProjectConfig(rootDirectoryPath);
|
|
261
|
-
showProjectConfig(projectConfig, {
|
|
262
|
-
json: parsed.json,
|
|
263
|
-
pretty: parsed.pretty,
|
|
264
|
-
});
|
|
265
|
-
},
|
|
266
|
-
examples: [
|
|
267
|
-
{
|
|
268
|
-
command: "config",
|
|
269
|
-
description: "show the project configuration",
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
command: "config --print",
|
|
273
|
-
description: "show the project configuration as JSON",
|
|
274
|
-
},
|
|
275
|
-
{
|
|
276
|
-
command: "config --print --pretty",
|
|
277
|
-
description: "show the project configuration (as pretty JSON)",
|
|
278
|
-
},
|
|
279
|
-
],
|
|
280
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DatafileContent,
|
|
3
|
-
EnvironmentKey,
|
|
4
|
-
ExistingState,
|
|
5
|
-
HistoryEntry,
|
|
6
|
-
Commit,
|
|
7
|
-
CommitHash,
|
|
8
|
-
EntityType,
|
|
9
|
-
} from "@featurevisor/types";
|
|
10
|
-
|
|
11
|
-
export interface DatafileOptions {
|
|
12
|
-
environment: EnvironmentKey | false;
|
|
13
|
-
target?: string;
|
|
14
|
-
datafilesDir?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface DatafileFile {
|
|
18
|
-
path: string;
|
|
19
|
-
size: number;
|
|
20
|
-
gzipSize: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export abstract class Adapter {
|
|
24
|
-
abstract listSets(): Promise<string[]>;
|
|
25
|
-
|
|
26
|
-
// entities
|
|
27
|
-
abstract listEntities(entityType: EntityType): Promise<string[]>;
|
|
28
|
-
abstract entityExists(entityType: EntityType, entityKey: string): Promise<boolean>;
|
|
29
|
-
abstract readEntity<T>(entityType: EntityType, entityKey: string): Promise<T>;
|
|
30
|
-
abstract writeEntity<T>(entityType: EntityType, entityKey: string, entity: T): Promise<T>;
|
|
31
|
-
abstract deleteEntity(entityType: EntityType, entityKey: string): Promise<void>;
|
|
32
|
-
|
|
33
|
-
// state
|
|
34
|
-
abstract readState(environment: EnvironmentKey | false): Promise<ExistingState>;
|
|
35
|
-
abstract writeState(
|
|
36
|
-
environment: EnvironmentKey | false,
|
|
37
|
-
existingState: ExistingState,
|
|
38
|
-
): Promise<void>;
|
|
39
|
-
|
|
40
|
-
// datafile
|
|
41
|
-
listDatafiles?(): Promise<DatafileFile[]>;
|
|
42
|
-
abstract readDatafile(options: DatafileOptions): Promise<DatafileContent>;
|
|
43
|
-
abstract writeDatafile(datafileContent: DatafileContent, options: DatafileOptions): Promise<void>;
|
|
44
|
-
|
|
45
|
-
// revision
|
|
46
|
-
abstract readRevision(): Promise<string>;
|
|
47
|
-
abstract writeRevision(revision: string): Promise<void>;
|
|
48
|
-
|
|
49
|
-
// history
|
|
50
|
-
abstract listHistoryEntries(entityType?: EntityType, entityKey?: string): Promise<HistoryEntry[]>;
|
|
51
|
-
abstract readCommit(
|
|
52
|
-
commit: CommitHash,
|
|
53
|
-
entityType?: EntityType,
|
|
54
|
-
entityKey?: string,
|
|
55
|
-
): Promise<Commit>;
|
|
56
|
-
}
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ParsedFeature,
|
|
3
|
-
Segment,
|
|
4
|
-
Attribute,
|
|
5
|
-
Group,
|
|
6
|
-
FeatureKey,
|
|
7
|
-
Test,
|
|
8
|
-
EnvironmentKey,
|
|
9
|
-
ExistingState,
|
|
10
|
-
SegmentKey,
|
|
11
|
-
AttributeKey,
|
|
12
|
-
DatafileContent,
|
|
13
|
-
EntityType,
|
|
14
|
-
SchemaKey,
|
|
15
|
-
Schema,
|
|
16
|
-
Target,
|
|
17
|
-
TargetKey,
|
|
18
|
-
} from "@featurevisor/types";
|
|
19
|
-
|
|
20
|
-
import { getProjectConfigForSet, ProjectConfig } from "../config";
|
|
21
|
-
import type { CustomParser } from "@featurevisor/parsers";
|
|
22
|
-
|
|
23
|
-
import { Adapter, DatafileFile, DatafileOptions } from "./adapter";
|
|
24
|
-
|
|
25
|
-
export class Datasource {
|
|
26
|
-
private adapter: Adapter;
|
|
27
|
-
private rootConfig: ProjectConfig;
|
|
28
|
-
|
|
29
|
-
constructor(
|
|
30
|
-
private config: ProjectConfig,
|
|
31
|
-
private rootDirectoryPath?: string,
|
|
32
|
-
private set?: string,
|
|
33
|
-
) {
|
|
34
|
-
this.rootConfig = config;
|
|
35
|
-
this.config = set ? getProjectConfigForSet(this.rootConfig, set) : config;
|
|
36
|
-
this.adapter = new this.config.adapter(this.config, rootDirectoryPath);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getConfig() {
|
|
40
|
-
return this.config;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getSet() {
|
|
44
|
-
return this.set;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
forSet(set: string) {
|
|
48
|
-
return new Datasource(this.rootConfig, this.rootDirectoryPath, set);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
listSets() {
|
|
52
|
-
return this.adapter.listSets();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getExtension() {
|
|
56
|
-
return (this.config.parser as CustomParser).extension;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* State
|
|
61
|
-
*/
|
|
62
|
-
readState(environment: EnvironmentKey | false): Promise<ExistingState> {
|
|
63
|
-
return this.adapter.readState(environment);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
writeState(environment: EnvironmentKey | false, existingState: ExistingState) {
|
|
67
|
-
return this.adapter.writeState(environment, existingState);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Revision
|
|
72
|
-
*/
|
|
73
|
-
readRevision() {
|
|
74
|
-
return this.adapter.readRevision();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
writeRevision(revision: string) {
|
|
78
|
-
return this.adapter.writeRevision(revision);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Datafile
|
|
83
|
-
*/
|
|
84
|
-
listDatafiles(): Promise<DatafileFile[]> {
|
|
85
|
-
return this.adapter.listDatafiles ? this.adapter.listDatafiles() : Promise.resolve([]);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
readDatafile(options: DatafileOptions) {
|
|
89
|
-
return this.adapter.readDatafile(options);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
writeDatafile(datafileContent: DatafileContent, options: DatafileOptions) {
|
|
93
|
-
return this.adapter.writeDatafile(datafileContent, options);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Entity specific methods
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
// features
|
|
101
|
-
listFeatures() {
|
|
102
|
-
return this.adapter.listEntities("feature");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
featureExists(featureKey: FeatureKey) {
|
|
106
|
-
return this.adapter.entityExists("feature", featureKey);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
readFeature(featureKey: FeatureKey) {
|
|
110
|
-
return this.adapter.readEntity<ParsedFeature>("feature", featureKey);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
writeFeature(featureKey: FeatureKey, feature: ParsedFeature) {
|
|
114
|
-
return this.adapter.writeEntity<ParsedFeature>("feature", featureKey, feature);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
deleteFeature(featureKey: FeatureKey) {
|
|
118
|
-
return this.adapter.deleteEntity("feature", featureKey);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async getRequiredFeaturesChain(
|
|
122
|
-
featureKey: FeatureKey,
|
|
123
|
-
chain = new Set<FeatureKey>(),
|
|
124
|
-
): Promise<Set<FeatureKey>> {
|
|
125
|
-
chain.add(featureKey);
|
|
126
|
-
|
|
127
|
-
if (!this.adapter.entityExists("feature", featureKey)) {
|
|
128
|
-
throw new Error(`Feature not found: ${featureKey}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const feature = await this.readFeature(featureKey);
|
|
132
|
-
|
|
133
|
-
if (!feature.required) {
|
|
134
|
-
return chain;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (const r of feature.required) {
|
|
138
|
-
const requiredKey = typeof r === "string" ? r : r.key;
|
|
139
|
-
|
|
140
|
-
if (chain.has(requiredKey)) {
|
|
141
|
-
throw new Error(`Circular dependency detected: ${chain.toString()}`);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
await this.getRequiredFeaturesChain(requiredKey, chain);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return chain;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// segments
|
|
151
|
-
listSegments() {
|
|
152
|
-
return this.adapter.listEntities("segment");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
segmentExists(segmentKey: SegmentKey) {
|
|
156
|
-
return this.adapter.entityExists("segment", segmentKey);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
readSegment(segmentKey: SegmentKey) {
|
|
160
|
-
return this.adapter.readEntity<Segment>("segment", segmentKey);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
writeSegment(segmentKey: SegmentKey, segment: Segment) {
|
|
164
|
-
return this.adapter.writeEntity<Segment>("segment", segmentKey, segment);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
deleteSegment(segmentKey: SegmentKey) {
|
|
168
|
-
return this.adapter.deleteEntity("segment", segmentKey);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// attributes
|
|
172
|
-
listAttributes() {
|
|
173
|
-
return this.adapter.listEntities("attribute");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async listFlattenedAttributes() {
|
|
177
|
-
const attributes = await this.listAttributes();
|
|
178
|
-
const result: string[] = [];
|
|
179
|
-
|
|
180
|
-
for (const key of attributes) {
|
|
181
|
-
const attribute = await this.readAttribute(key);
|
|
182
|
-
|
|
183
|
-
result.push(key);
|
|
184
|
-
|
|
185
|
-
if (attribute.type === "object") {
|
|
186
|
-
// @NOTE: in future, this can be recursive
|
|
187
|
-
const propertyKeys = Object.keys(attribute.properties || {});
|
|
188
|
-
for (const propertyKey of propertyKeys) {
|
|
189
|
-
result.push(`${key}.${propertyKey}`);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
attributeExists(attributeKey: AttributeKey) {
|
|
198
|
-
return this.adapter.entityExists("attribute", attributeKey);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
readAttribute(attributeKey: AttributeKey) {
|
|
202
|
-
return this.adapter.readEntity<Attribute>("attribute", attributeKey);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
writeAttribute(attributeKey: AttributeKey, attribute: Attribute) {
|
|
206
|
-
return this.adapter.writeEntity<Attribute>("attribute", attributeKey, attribute);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
deleteAttribute(attributeKey: AttributeKey) {
|
|
210
|
-
return this.adapter.deleteEntity("attribute", attributeKey);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// groups
|
|
214
|
-
listGroups() {
|
|
215
|
-
return this.adapter.listEntities("group");
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
groupExists(groupKey: string) {
|
|
219
|
-
return this.adapter.entityExists("group", groupKey);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
readGroup(groupKey: string) {
|
|
223
|
-
return this.adapter.readEntity<Group>("group", groupKey);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
writeGroup(groupKey: string, group: Group) {
|
|
227
|
-
return this.adapter.writeEntity<Group>("group", groupKey, group);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
deleteGroup(groupKey: string) {
|
|
231
|
-
return this.adapter.deleteEntity("group", groupKey);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// schemas
|
|
235
|
-
listSchemas() {
|
|
236
|
-
return this.adapter.listEntities("schema");
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
schemaExists(schemaKey: SchemaKey) {
|
|
240
|
-
return this.adapter.entityExists("schema", schemaKey);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
readSchema(schemaKey: SchemaKey) {
|
|
244
|
-
return this.adapter.readEntity<Schema>("schema", schemaKey);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
writeSchema(schemaKey: SchemaKey, schema: Schema) {
|
|
248
|
-
return this.adapter.writeEntity<Schema>("schema", schemaKey, schema);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
deleteSchema(schemaKey: SchemaKey) {
|
|
252
|
-
return this.adapter.deleteEntity("schema", schemaKey);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// targets
|
|
256
|
-
listTargets() {
|
|
257
|
-
return this.adapter.listEntities("target");
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
targetExists(targetKey: TargetKey) {
|
|
261
|
-
return this.adapter.entityExists("target", targetKey);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
readTarget(targetKey: TargetKey) {
|
|
265
|
-
return this.adapter.readEntity<Target>("target", targetKey);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
writeTarget(targetKey: TargetKey, target: Target) {
|
|
269
|
-
return this.adapter.writeEntity<Target>("target", targetKey, target);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
deleteTarget(targetKey: TargetKey) {
|
|
273
|
-
return this.adapter.deleteEntity("target", targetKey);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// tests
|
|
277
|
-
listTests() {
|
|
278
|
-
return this.adapter.listEntities("test");
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
readTest(testKey: string) {
|
|
282
|
-
return this.adapter.readEntity<Test>("test", testKey);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
writeTest(testKey: string, test: Test) {
|
|
286
|
-
return this.adapter.writeEntity<Test>("test", testKey, test);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
deleteTest(testKey: string) {
|
|
290
|
-
return this.adapter.deleteEntity("test", testKey);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
getTestSpecName(testKey: string) {
|
|
294
|
-
return `${testKey}.${this.getExtension()}`;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// history
|
|
298
|
-
listHistoryEntries(entityType?: EntityType, entityKey?: string) {
|
|
299
|
-
return this.adapter.listHistoryEntries(entityType, entityKey);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
readCommit(commitHash: string, entityType?: EntityType, entityKey?: string) {
|
|
303
|
-
return this.adapter.readCommit(commitHash, entityType, entityKey);
|
|
304
|
-
}
|
|
305
|
-
}
|