@featurevisor/core 3.1.0 → 3.2.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.
Files changed (208) hide show
  1. package/lib/datasource/datasource.d.ts +1 -1
  2. package/lib/datasource/datasource.js +4 -14
  3. package/lib/datasource/datasource.js.map +1 -1
  4. package/lib/datasource/requiredFeatures.d.ts +7 -0
  5. package/lib/datasource/requiredFeatures.js +38 -0
  6. package/lib/datasource/requiredFeatures.js.map +1 -0
  7. package/lib/linter/checkCircularDependency.d.ts +1 -1
  8. package/lib/linter/checkCircularDependency.js +3 -22
  9. package/lib/linter/checkCircularDependency.js.map +1 -1
  10. package/lib/linter/conditionSchema.js +27 -3
  11. package/lib/linter/conditionSchema.js.map +1 -1
  12. package/lib/tester/testFeature.js +17 -16
  13. package/lib/tester/testFeature.js.map +1 -1
  14. package/package.json +10 -7
  15. package/CHANGELOG.md +0 -2246
  16. package/coverage/clover.xml +0 -5456
  17. package/coverage/coverage-final.json +0 -64
  18. package/coverage/lcov-report/base.css +0 -224
  19. package/coverage/lcov-report/block-navigation.js +0 -87
  20. package/coverage/lcov-report/favicon.png +0 -0
  21. package/coverage/lcov-report/index.html +0 -371
  22. package/coverage/lcov-report/prettify.css +0 -1
  23. package/coverage/lcov-report/prettify.js +0 -2
  24. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  25. package/coverage/lcov-report/sorter.js +0 -210
  26. package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
  27. package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
  28. package/coverage/lcov-report/src/benchmark/index.html +0 -116
  29. package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
  30. package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
  31. package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
  32. package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
  33. package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
  34. package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
  35. package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
  36. package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
  37. package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
  38. package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
  39. package/coverage/lcov-report/src/builder/index.html +0 -311
  40. package/coverage/lcov-report/src/builder/index.ts.html +0 -91
  41. package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
  42. package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
  43. package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
  44. package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
  45. package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
  46. package/coverage/lcov-report/src/cli/index.html +0 -131
  47. package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
  48. package/coverage/lcov-report/src/config/index.html +0 -131
  49. package/coverage/lcov-report/src/config/index.ts.html +0 -88
  50. package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
  51. package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
  52. package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
  53. package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
  54. package/coverage/lcov-report/src/datasource/index.html +0 -161
  55. package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
  56. package/coverage/lcov-report/src/evaluate/index.html +0 -116
  57. package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
  58. package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
  59. package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
  60. package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
  61. package/coverage/lcov-report/src/find-usage/index.html +0 -116
  62. package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
  63. package/coverage/lcov-report/src/generate-code/index.html +0 -131
  64. package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
  65. package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
  66. package/coverage/lcov-report/src/index.html +0 -131
  67. package/coverage/lcov-report/src/info/index.html +0 -116
  68. package/coverage/lcov-report/src/info/index.ts.html +0 -472
  69. package/coverage/lcov-report/src/init/index.html +0 -116
  70. package/coverage/lcov-report/src/init/index.ts.html +0 -280
  71. package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
  72. package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
  73. package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
  74. package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
  75. package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
  76. package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
  77. package/coverage/lcov-report/src/linter/index.html +0 -326
  78. package/coverage/lcov-report/src/linter/index.ts.html +0 -88
  79. package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
  80. package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
  81. package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
  82. package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
  83. package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
  84. package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
  85. package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
  86. package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
  87. package/coverage/lcov-report/src/list/index.html +0 -131
  88. package/coverage/lcov-report/src/list/index.ts.html +0 -2065
  89. package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
  90. package/coverage/lcov-report/src/promoter/index.html +0 -116
  91. package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
  92. package/coverage/lcov-report/src/sets.ts.html +0 -313
  93. package/coverage/lcov-report/src/targeting.ts.html +0 -403
  94. package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
  95. package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
  96. package/coverage/lcov-report/src/tester/index.html +0 -206
  97. package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
  98. package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
  99. package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
  100. package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
  101. package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
  102. package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
  103. package/coverage/lcov-report/src/utils/git.ts.html +0 -559
  104. package/coverage/lcov-report/src/utils/index.html +0 -161
  105. package/coverage/lcov-report/src/utils/index.ts.html +0 -94
  106. package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
  107. package/coverage/lcov.info +0 -11615
  108. package/jest.config.js +0 -22
  109. package/json-schema/README.md +0 -5
  110. package/json-schema/attribute.json +0 -40
  111. package/json-schema/feature.json +0 -394
  112. package/json-schema/segment.json +0 -137
  113. package/src/assess-distribution/index.ts +0 -223
  114. package/src/benchmark/index.ts +0 -236
  115. package/src/builder/allocator.spec.ts +0 -105
  116. package/src/builder/allocator.ts +0 -45
  117. package/src/builder/applyContextToConditions.spec.ts +0 -2677
  118. package/src/builder/applyContextToConditions.ts +0 -139
  119. package/src/builder/applyContextToDatafile.spec.ts +0 -2626
  120. package/src/builder/applyContextToDatafile.ts +0 -229
  121. package/src/builder/applyContextToSegments.spec.ts +0 -1593
  122. package/src/builder/applyContextToSegments.ts +0 -165
  123. package/src/builder/buildDatafile.spec.ts +0 -445
  124. package/src/builder/buildDatafile.ts +0 -656
  125. package/src/builder/buildProject.ts +0 -344
  126. package/src/builder/buildRuntimeDatafiles.ts +0 -57
  127. package/src/builder/getFeatureRanges.ts +0 -61
  128. package/src/builder/hashes.ts +0 -109
  129. package/src/builder/index.ts +0 -2
  130. package/src/builder/mutateVariables.spec.ts +0 -1179
  131. package/src/builder/mutateVariables.ts +0 -112
  132. package/src/builder/mutator.spec.ts +0 -413
  133. package/src/builder/mutator.ts +0 -237
  134. package/src/builder/revision.spec.ts +0 -22
  135. package/src/builder/revision.ts +0 -22
  136. package/src/builder/traffic.spec.ts +0 -946
  137. package/src/builder/traffic.ts +0 -192
  138. package/src/cli/cli.ts +0 -105
  139. package/src/cli/index.ts +0 -2
  140. package/src/cli/plugins.ts +0 -43
  141. package/src/config/index.ts +0 -1
  142. package/src/config/projectConfig.spec.ts +0 -194
  143. package/src/config/projectConfig.ts +0 -280
  144. package/src/datasource/adapter.ts +0 -56
  145. package/src/datasource/datasource.ts +0 -305
  146. package/src/datasource/filesystemAdapter.spec.ts +0 -212
  147. package/src/datasource/filesystemAdapter.ts +0 -497
  148. package/src/datasource/index.ts +0 -3
  149. package/src/dependencies.ts +0 -13
  150. package/src/evaluate/index.ts +0 -243
  151. package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
  152. package/src/find-duplicate-segments/index.ts +0 -74
  153. package/src/find-usage/index.ts +0 -565
  154. package/src/generate-code/index.ts +0 -106
  155. package/src/generate-code/typescript.spec.ts +0 -214
  156. package/src/generate-code/typescript.ts +0 -608
  157. package/src/index.ts +0 -20
  158. package/src/info/index.ts +0 -129
  159. package/src/init/index.ts +0 -65
  160. package/src/linter/attributeSchema.spec.ts +0 -342
  161. package/src/linter/attributeSchema.ts +0 -626
  162. package/src/linter/checkCircularDependency.ts +0 -45
  163. package/src/linter/checkPercentageExceedingSlot.ts +0 -61
  164. package/src/linter/conditionSchema.spec.ts +0 -510
  165. package/src/linter/conditionSchema.ts +0 -713
  166. package/src/linter/featureSchema.spec.ts +0 -1985
  167. package/src/linter/featureSchema.ts +0 -1922
  168. package/src/linter/groupSchema.ts +0 -47
  169. package/src/linter/index.ts +0 -1
  170. package/src/linter/lintProject.spec.ts +0 -336
  171. package/src/linter/lintProject.ts +0 -873
  172. package/src/linter/mutationNotation.spec.ts +0 -704
  173. package/src/linter/mutationNotation.ts +0 -442
  174. package/src/linter/printError.ts +0 -68
  175. package/src/linter/schema.spec.ts +0 -690
  176. package/src/linter/schema.ts +0 -491
  177. package/src/linter/segmentSchema.spec.ts +0 -358
  178. package/src/linter/segmentSchema.ts +0 -18
  179. package/src/linter/targetSchema.spec.ts +0 -159
  180. package/src/linter/targetSchema.ts +0 -46
  181. package/src/linter/testSchema.spec.ts +0 -258
  182. package/src/linter/testSchema.ts +0 -148
  183. package/src/linter/zodHelpers.ts +0 -16
  184. package/src/list/index.spec.ts +0 -135
  185. package/src/list/index.ts +0 -660
  186. package/src/list/matrix.spec.ts +0 -49
  187. package/src/list/matrix.ts +0 -212
  188. package/src/promoter/index.spec.ts +0 -617
  189. package/src/promoter/index.ts +0 -1266
  190. package/src/sets.ts +0 -76
  191. package/src/targeting.spec.ts +0 -74
  192. package/src/targeting.ts +0 -106
  193. package/src/tester/cliFormat.ts +0 -16
  194. package/src/tester/helpers.spec.ts +0 -149
  195. package/src/tester/helpers.ts +0 -76
  196. package/src/tester/index.ts +0 -2
  197. package/src/tester/prettyDuration.ts +0 -34
  198. package/src/tester/printTestResult.ts +0 -84
  199. package/src/tester/testFeature.ts +0 -367
  200. package/src/tester/testProject.spec.ts +0 -50
  201. package/src/tester/testProject.ts +0 -311
  202. package/src/tester/testSegment.ts +0 -77
  203. package/src/utils/extractKeys.ts +0 -136
  204. package/src/utils/git.ts +0 -158
  205. package/src/utils/index.ts +0 -3
  206. package/src/utils/pretty.ts +0 -12
  207. package/tsconfig.cjs.json +0 -13
  208. package/tsconfig.typecheck.json +0 -9
package/src/list/index.ts DELETED
@@ -1,660 +0,0 @@
1
- import type {
2
- ParsedFeature,
3
- Segment,
4
- Attribute,
5
- TestFeature,
6
- TestSegment,
7
- FeatureAssertion,
8
- SegmentAssertion,
9
- Target,
10
- } from "@featurevisor/types";
11
-
12
- import { Dependencies } from "../dependencies";
13
- import type { DatafileFile } from "../datasource";
14
- import { Plugin } from "../cli";
15
- import { getFeatureAssertionsFromMatrix, getSegmentAssertionsFromMatrix } from "./matrix";
16
- import { assertProjectSetJsonSelection, getProjectSetExecutions, printSetHeader } from "../sets";
17
- import { getTargetFeatureKeys, resolveTargets } from "../targeting";
18
- import {
19
- CLI_COLOR_CYAN,
20
- CLI_COLOR_GREEN,
21
- CLI_COLOR_YELLOW,
22
- CLI_FORMAT_BOLD,
23
- CLI_FORMAT_GREEN,
24
- CLI_FORMAT_YELLOW,
25
- colorize,
26
- } from "../tester/cliFormat";
27
-
28
- async function getEntitiesWithTests(
29
- deps: Dependencies,
30
- ): Promise<{ features: string[]; segments: string[] }> {
31
- const { datasource } = deps;
32
-
33
- const featuresWithTests = new Set<string>();
34
- const segmentsWithTests = new Set<string>();
35
-
36
- const tests = await datasource.listTests();
37
- for (const testKey of tests) {
38
- const test = await datasource.readTest(testKey);
39
-
40
- if ((test as TestFeature).feature) {
41
- featuresWithTests.add((test as TestFeature).feature);
42
- }
43
-
44
- if ((test as TestSegment).segment) {
45
- segmentsWithTests.add((test as TestSegment).segment);
46
- }
47
- }
48
-
49
- return {
50
- features: Array.from(featuresWithTests),
51
- segments: Array.from(segmentsWithTests),
52
- };
53
- }
54
-
55
- export async function listEntities<T>(deps: Dependencies, entityType): Promise<T[]> {
56
- const { datasource, options } = deps;
57
-
58
- const result: T[] = [];
59
- let entityKeys: string[] = [];
60
-
61
- if (entityType === "feature") {
62
- entityKeys = await datasource.listFeatures();
63
- } else if (entityType === "segment") {
64
- entityKeys = await datasource.listSegments();
65
- } else if (entityType === "attribute") {
66
- entityKeys = await datasource.listAttributes();
67
- } else if (entityType === "test") {
68
- entityKeys = await datasource.listTests();
69
- } else if (entityType === "target") {
70
- entityKeys = await datasource.listTargets();
71
- }
72
-
73
- if (entityKeys.length === 0) {
74
- return result;
75
- }
76
-
77
- let entitiesWithTests: { features: string[]; segments: string[] } = {
78
- features: [],
79
- segments: [],
80
- };
81
- let entitiesWithTestsInitialized = false;
82
- let targetFeatureKeys: Set<string> | undefined;
83
-
84
- if (entityType === "feature" && options.target) {
85
- const targets = await resolveTargets(datasource, options.target, { defaultToAll: false });
86
- targetFeatureKeys = await getTargetFeatureKeys(datasource, targets);
87
- }
88
-
89
- async function initializeEntitiesWithTests() {
90
- if (entitiesWithTestsInitialized) {
91
- return;
92
- }
93
-
94
- entitiesWithTests = await getEntitiesWithTests(deps);
95
- entitiesWithTestsInitialized = true;
96
- }
97
-
98
- for (const key of entityKeys) {
99
- let entity = {} as T;
100
-
101
- if (entityType === "feature") {
102
- entity = (await datasource.readFeature(key)) as T;
103
- } else if (entityType === "segment") {
104
- entity = (await datasource.readSegment(key)) as T;
105
- } else if (entityType === "attribute") {
106
- entity = (await datasource.readAttribute(key)) as T;
107
- } else if (entityType === "test") {
108
- entity = (await datasource.readTest(key)) as T;
109
- } else if (entityType === "target") {
110
- entity = (await datasource.readTarget(key)) as T;
111
- }
112
-
113
- // filter
114
- if (entityType === "feature") {
115
- const parsedFeature = entity as ParsedFeature;
116
-
117
- if (targetFeatureKeys && !targetFeatureKeys.has(key)) {
118
- continue;
119
- }
120
-
121
- // --archived=true|false
122
- if (parsedFeature.archived) {
123
- const archivedStatus = options.archived === "false";
124
-
125
- if (parsedFeature.archived !== archivedStatus) {
126
- continue;
127
- }
128
- }
129
-
130
- // --description=<pattern>
131
- if (options.description) {
132
- const description = parsedFeature.description || "";
133
-
134
- const regex = new RegExp(options.description, "i");
135
- if (!regex.test(description)) {
136
- continue;
137
- }
138
- }
139
-
140
- // --disabledIn=<environment>
141
- if (options.disabledIn && parsedFeature.rules && parsedFeature.rules[options.disabledIn]) {
142
- const disabledInEnvironment = parsedFeature.rules[options.disabledIn].every((rule) => {
143
- return rule.percentage === 0;
144
- });
145
-
146
- if (!disabledInEnvironment) {
147
- continue;
148
- }
149
- }
150
-
151
- // --enabledIn=<environment>
152
- if (options.enabledIn && parsedFeature.rules && parsedFeature.rules[options.enabledIn]) {
153
- const enabledInEnvironment = parsedFeature.rules[options.enabledIn].some((rule) => {
154
- return rule.percentage > 0;
155
- });
156
-
157
- if (!enabledInEnvironment) {
158
- continue;
159
- }
160
- }
161
-
162
- // --keyPattern=<pattern>
163
- if (options.keyPattern) {
164
- const regex = new RegExp(options.keyPattern, "i");
165
- if (!regex.test(key)) {
166
- continue;
167
- }
168
- }
169
-
170
- // --tag=<tag>
171
- if (options.tag) {
172
- const tags = Array.isArray(options.tag) ? options.tag : [options.tag];
173
- const featureTags = parsedFeature.tags || [];
174
- const hasTags = tags.every((tag) => featureTags.includes(tag));
175
-
176
- if (!hasTags) {
177
- continue;
178
- }
179
- }
180
-
181
- // --variable=<variableKey>
182
- if (options.variable) {
183
- const lookForVariables = Array.isArray(options.variable)
184
- ? options.variable
185
- : [options.variable];
186
-
187
- let variablesInFeature: string[] = Object.keys(parsedFeature.variablesSchema || {});
188
-
189
- const hasVariables = lookForVariables.every((variable) =>
190
- variablesInFeature.includes(variable),
191
- );
192
-
193
- if (!hasVariables) {
194
- continue;
195
- }
196
- }
197
-
198
- // --variation=<variationValue>
199
- if (options.variation) {
200
- const lookForVariations = Array.isArray(options.variation)
201
- ? options.variation
202
- : [options.variation];
203
-
204
- let variationsInFeature: string[] = parsedFeature.variations
205
- ? parsedFeature.variations.map((v) => v.value)
206
- : [];
207
-
208
- const hasVariations = lookForVariations.every((variation) =>
209
- variationsInFeature.includes(variation),
210
- );
211
-
212
- if (!hasVariations) {
213
- continue;
214
- }
215
- }
216
-
217
- // --with-tests
218
- if (options.withTests) {
219
- await initializeEntitiesWithTests();
220
-
221
- if (!entitiesWithTests.features.includes(key)) {
222
- continue;
223
- }
224
- }
225
-
226
- // --with-variables
227
- if (options.withVariables) {
228
- const hasVariables = parsedFeature.variablesSchema;
229
-
230
- if (!hasVariables) {
231
- continue;
232
- }
233
- }
234
-
235
- // --with-variations
236
- if (options.withVariations) {
237
- const hasVariations = parsedFeature.variations;
238
-
239
- if (!hasVariations) {
240
- continue;
241
- }
242
- }
243
-
244
- // --without-tests
245
- if (options.withoutTests) {
246
- await initializeEntitiesWithTests();
247
-
248
- if (entitiesWithTests.features.includes(key)) {
249
- continue;
250
- }
251
- }
252
-
253
- // --without-variables
254
- if (options.withoutVariables) {
255
- const hasVariables = parsedFeature.variablesSchema;
256
-
257
- if (hasVariables) {
258
- continue;
259
- }
260
- }
261
-
262
- // --without-variations
263
- if (options.withoutVariations) {
264
- const hasVariations = parsedFeature.variations;
265
-
266
- if (hasVariations) {
267
- continue;
268
- }
269
- }
270
- } else if (entityType === "segment") {
271
- const segment = entity as Segment;
272
-
273
- // --archived=true|false
274
- if (segment.archived) {
275
- const archivedStatus = options.archived === "false";
276
-
277
- if (segment.archived !== archivedStatus) {
278
- continue;
279
- }
280
- }
281
-
282
- // --description=<pattern>
283
- if (options.description) {
284
- const description = segment.description || "";
285
-
286
- const regex = new RegExp(options.description, "i");
287
- if (!regex.test(description)) {
288
- continue;
289
- }
290
- }
291
-
292
- // --keyPattern=<pattern>
293
- if (options.keyPattern) {
294
- const regex = new RegExp(options.keyPattern, "i");
295
- if (!regex.test(key)) {
296
- continue;
297
- }
298
- }
299
-
300
- // --with-tests
301
- if (options.withTests) {
302
- await initializeEntitiesWithTests();
303
-
304
- if (!entitiesWithTests.segments.includes(key)) {
305
- continue;
306
- }
307
- }
308
-
309
- // --without-tests
310
- if (options.withoutTests) {
311
- await initializeEntitiesWithTests();
312
-
313
- if (entitiesWithTests.segments.includes(key)) {
314
- continue;
315
- }
316
- }
317
- } else if (entityType === "attribute") {
318
- const attribute = entity as Attribute;
319
-
320
- // --archived=true|false
321
- if (options.archived) {
322
- const archivedStatus = options.archived === "false";
323
-
324
- if (attribute.archived !== archivedStatus) {
325
- continue;
326
- }
327
- }
328
-
329
- // --description=<pattern>
330
- if (options.description) {
331
- const description = attribute.description || "";
332
-
333
- const regex = new RegExp(options.description, "i");
334
- if (!regex.test(description)) {
335
- continue;
336
- }
337
- }
338
-
339
- // --keyPattern=<pattern>
340
- if (options.keyPattern) {
341
- const regex = new RegExp(options.keyPattern, "i");
342
- if (!regex.test(key)) {
343
- continue;
344
- }
345
- }
346
- } else if (entityType === "test") {
347
- let test = entity as TestFeature | TestSegment;
348
- const testEntityKey = (test as TestFeature).feature || (test as TestSegment).segment;
349
- const testEntityType = (test as TestSegment).segment ? "segment" : "feature";
350
- let testAssertions = test.assertions;
351
-
352
- // --entityType=<type>
353
- if (options.entityType && options.entityType !== testEntityType) {
354
- continue;
355
- }
356
-
357
- // --apply-matrix
358
- if (options.applyMatrix) {
359
- if (testEntityType === "feature") {
360
- let assertionsAfterApplyingMatrix: FeatureAssertion[] = [];
361
- for (let aIndex = 0; aIndex < testAssertions.length; aIndex++) {
362
- const processedAssertions = getFeatureAssertionsFromMatrix(
363
- aIndex,
364
- testAssertions[aIndex] as FeatureAssertion,
365
- );
366
- assertionsAfterApplyingMatrix =
367
- assertionsAfterApplyingMatrix.concat(processedAssertions);
368
- }
369
-
370
- testAssertions = assertionsAfterApplyingMatrix;
371
- } else if (testEntityType === "segment") {
372
- let assertionsAfterApplyingMatrix: SegmentAssertion[] = [];
373
- for (let aIndex = 0; aIndex < testAssertions.length; aIndex++) {
374
- const processedAssertions = getSegmentAssertionsFromMatrix(
375
- aIndex,
376
- testAssertions[aIndex] as SegmentAssertion,
377
- );
378
- assertionsAfterApplyingMatrix =
379
- assertionsAfterApplyingMatrix.concat(processedAssertions);
380
- }
381
-
382
- testAssertions = assertionsAfterApplyingMatrix;
383
- }
384
- }
385
-
386
- // --keyPattern=<pattern>
387
- if (options.keyPattern) {
388
- const regex = new RegExp(options.keyPattern, "i");
389
- if (!regex.test(testEntityKey)) {
390
- continue;
391
- }
392
- }
393
-
394
- // --assertionPattern=<pattern>
395
- if (options.assertionPattern) {
396
- const regex = new RegExp(options.assertionPattern, "i");
397
- testAssertions = testAssertions.filter((assertion) => {
398
- if (!assertion.description) {
399
- return false;
400
- }
401
-
402
- return regex.test(assertion.description);
403
- }) as FeatureAssertion[] | SegmentAssertion[];
404
-
405
- if (testAssertions.length === 0) {
406
- continue;
407
- }
408
- }
409
-
410
- (entity as TestFeature | TestSegment).assertions = testAssertions;
411
- }
412
-
413
- result.push({
414
- ...entity,
415
- key,
416
- });
417
- }
418
-
419
- return result;
420
- }
421
-
422
- function ucfirst(str: string) {
423
- return str.charAt(0).toUpperCase() + str.slice(1);
424
- }
425
-
426
- function printResult({ result, entityType, options }) {
427
- if (options.json) {
428
- console.log(options.pretty ? JSON.stringify(result, null, 2) : JSON.stringify(result));
429
- return;
430
- }
431
-
432
- if (result.length === 0) {
433
- console.log(CLI_FORMAT_YELLOW, `No ${entityType}s found.`);
434
- return;
435
- }
436
-
437
- console.log("");
438
- console.log(CLI_FORMAT_BOLD, `${ucfirst(entityType)}s`);
439
- console.log("");
440
-
441
- for (const item of result) {
442
- console.log(` ${colorize("•", CLI_COLOR_CYAN)} ${item.key}`);
443
- }
444
-
445
- console.log("");
446
- console.log(CLI_FORMAT_GREEN, `Found ${result.length} ${entityType}s.`);
447
- }
448
-
449
- function getDatafileSizeParts(size: number): { value: string; unit: string; color: number } {
450
- if (size < 1024) {
451
- return { value: size.toFixed(2), unit: "B", color: CLI_COLOR_YELLOW };
452
- }
453
-
454
- if (size < 1024 * 1024) {
455
- return { value: (size / 1024).toFixed(2), unit: "kB", color: CLI_COLOR_CYAN };
456
- }
457
-
458
- return { value: (size / (1024 * 1024)).toFixed(2), unit: "mB", color: CLI_COLOR_GREEN };
459
- }
460
-
461
- export function formatDatafileSize(size: number): string {
462
- const { value, unit, color } = getDatafileSizeParts(size);
463
-
464
- return `${value} ${colorize(unit, color)}`;
465
- }
466
-
467
- function formatDatafileSizeColumn(size: number, valueWidth: number): string {
468
- const { value, unit, color } = getDatafileSizeParts(size);
469
-
470
- return `${value.padStart(valueWidth)} ${" ".repeat(2 - unit.length)}${colorize(unit, color)}`;
471
- }
472
-
473
- function getDatafileDirectory(datafilePath: string): string {
474
- const lastSlashIndex = datafilePath.lastIndexOf("/");
475
-
476
- return lastSlashIndex === -1 ? "" : datafilePath.slice(0, lastSlashIndex);
477
- }
478
-
479
- function getDatafileDirectoryPriority(datafilePath: string): number {
480
- const directory = datafilePath.split("/", 1)[0].toLowerCase();
481
-
482
- if (directory.startsWith("dev")) {
483
- return 0;
484
- }
485
-
486
- if (directory.startsWith("prod")) {
487
- return 2;
488
- }
489
-
490
- return 1;
491
- }
492
-
493
- function sortDatafiles(datafiles: DatafileFile[]): DatafileFile[] {
494
- return datafiles.slice().sort((a, b) => {
495
- const priorityDifference =
496
- getDatafileDirectoryPriority(a.path) - getDatafileDirectoryPriority(b.path);
497
-
498
- return priorityDifference || a.path.localeCompare(b.path);
499
- });
500
- }
501
-
502
- function printDatafiles({ result, options }: { result: DatafileFile[]; options: any }) {
503
- const sortedResult = sortDatafiles(result);
504
-
505
- if (options.json) {
506
- console.log(
507
- options.pretty ? JSON.stringify(sortedResult, null, 2) : JSON.stringify(sortedResult),
508
- );
509
- return;
510
- }
511
-
512
- if (sortedResult.length === 0) {
513
- console.log(CLI_FORMAT_YELLOW, "No datafiles found.");
514
- return;
515
- }
516
-
517
- console.log("");
518
-
519
- const pathWidth = Math.max(
520
- "Datafile".length,
521
- ...sortedResult.map((datafile) => datafile.path.length),
522
- );
523
- const sizeValueWidth = Math.max(
524
- ...sortedResult.map((datafile) => {
525
- const { value } = getDatafileSizeParts(datafile.size);
526
- return value.length;
527
- }),
528
- );
529
- const gzipSizeValueWidth = Math.max(
530
- ...sortedResult.map((datafile) => {
531
- const { value } = getDatafileSizeParts(datafile.gzipSize);
532
- return value.length;
533
- }),
534
- );
535
- const sizeWidth = Math.max("Size".length, sizeValueWidth + 3);
536
- const gzipSizeWidth = Math.max("Gzip".length, gzipSizeValueWidth + 3);
537
-
538
- console.log(
539
- ` ${colorize("Datafile".padEnd(pathWidth), CLI_COLOR_CYAN)} ${colorize(
540
- "Size".padStart(sizeWidth),
541
- CLI_COLOR_CYAN,
542
- )} ${colorize("Gzip".padStart(gzipSizeWidth), CLI_COLOR_CYAN)}`,
543
- );
544
- console.log(` ${"-".repeat(pathWidth)} ${"-".repeat(sizeWidth)} ${"-".repeat(gzipSizeWidth)}`);
545
-
546
- let previousDirectory: string | undefined;
547
- for (const datafile of sortedResult) {
548
- const directory = getDatafileDirectory(datafile.path);
549
- if (previousDirectory !== undefined && directory !== previousDirectory) {
550
- console.log("");
551
- }
552
-
553
- const formattedSize = formatDatafileSizeColumn(datafile.size, sizeValueWidth);
554
- const formattedGzipSize = formatDatafileSizeColumn(datafile.gzipSize, gzipSizeValueWidth);
555
- console.log(` ${datafile.path.padEnd(pathWidth)} ${formattedSize} ${formattedGzipSize}`);
556
- previousDirectory = directory;
557
- }
558
-
559
- console.log("");
560
- console.log(CLI_FORMAT_GREEN, `Found ${sortedResult.length} datafiles.`);
561
- }
562
-
563
- export async function listProject(deps: Dependencies) {
564
- const { options } = deps;
565
-
566
- // datafiles
567
- if (options.datafiles) {
568
- const result = await deps.datasource.listDatafiles();
569
-
570
- return printDatafiles({ result, options });
571
- }
572
-
573
- // features
574
- if (options.features) {
575
- const result = await listEntities<ParsedFeature>(deps, "feature");
576
-
577
- return printResult({
578
- result,
579
- entityType: "feature",
580
- options,
581
- });
582
- }
583
-
584
- // segments
585
- if (options.segments) {
586
- const result = await listEntities<Segment>(deps, "segment");
587
-
588
- return printResult({
589
- result,
590
- entityType: "segment",
591
- options,
592
- });
593
- }
594
-
595
- // attributes
596
- if (options.attributes) {
597
- const result = await listEntities<Attribute>(deps, "attribute");
598
-
599
- return printResult({
600
- result,
601
- entityType: "attribute",
602
- options,
603
- });
604
- }
605
-
606
- // tests
607
- if (options.tests) {
608
- const result = await listEntities<Attribute>(deps, "test");
609
-
610
- return printResult({
611
- result,
612
- entityType: "test",
613
- options,
614
- });
615
- }
616
-
617
- // targets
618
- if (options.targets) {
619
- const result = await listEntities<Target>(deps, "target");
620
-
621
- return printResult({
622
- result,
623
- entityType: "target",
624
- options,
625
- });
626
- }
627
-
628
- console.log("");
629
- console.log(CLI_FORMAT_YELLOW, "Nothing to list.");
630
- console.log("");
631
- console.log(
632
- "Please pass `--datafiles`, `--features`, `--segments`, `--attributes`, or `--targets`.",
633
- );
634
- }
635
-
636
- export const listPlugin: Plugin = {
637
- command: "list",
638
- handler: async function ({ rootDirectoryPath, projectConfig, datasource, parsed }) {
639
- assertProjectSetJsonSelection(projectConfig, parsed.set, parsed.json);
640
-
641
- const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
642
-
643
- for (const execution of executions) {
644
- printSetHeader(projectConfig, execution.set, parsed.json);
645
-
646
- await listProject({
647
- rootDirectoryPath,
648
- projectConfig: execution.projectConfig,
649
- datasource: execution.datasource,
650
- options: parsed,
651
- });
652
- }
653
- },
654
- examples: [
655
- {
656
- command: "list",
657
- description: "list entities",
658
- },
659
- ],
660
- };
@@ -1,49 +0,0 @@
1
- import { getMatrixCombinations } from "./matrix";
2
-
3
- describe("core :: tester :: matrix", function () {
4
- test("should empty array when no keys are available", function () {
5
- const matrix = {};
6
- const combinations = getMatrixCombinations(matrix);
7
-
8
- expect(combinations).toEqual([]);
9
- });
10
-
11
- test("should get combinations from matrix with two keys", function () {
12
- const matrix = {
13
- a: [1, 2],
14
- b: ["x", "y"],
15
- };
16
- const combinations = getMatrixCombinations(matrix);
17
-
18
- expect(combinations).toEqual([
19
- { a: 1, b: "x" },
20
- { a: 1, b: "y" },
21
-
22
- { a: 2, b: "x" },
23
- { a: 2, b: "y" },
24
- ]);
25
- });
26
-
27
- test("should get combinations from matrix with three keys", function () {
28
- const matrix = {
29
- a: [1, 2],
30
- b: ["x", "y"],
31
- c: [true, false],
32
- };
33
- const combinations = getMatrixCombinations(matrix);
34
-
35
- expect(combinations).toEqual([
36
- { a: 1, b: "x", c: true },
37
- { a: 1, b: "x", c: false },
38
-
39
- { a: 1, b: "y", c: true },
40
- { a: 1, b: "y", c: false },
41
-
42
- { a: 2, b: "x", c: true },
43
- { a: 2, b: "x", c: false },
44
-
45
- { a: 2, b: "y", c: true },
46
- { a: 2, b: "y", c: false },
47
- ]);
48
- });
49
- });