@featurevisor/core 2.5.0 → 2.6.7

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 (91) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/LICENSE +1 -1
  3. package/coverage/clover.xml +444 -78
  4. package/coverage/coverage-final.json +9 -3
  5. package/coverage/lcov-report/index.html +42 -42
  6. package/coverage/lcov-report/lib/builder/allocator.js.html +1 -1
  7. package/coverage/lcov-report/lib/builder/buildScopedConditions.js.html +373 -0
  8. package/coverage/lcov-report/lib/builder/buildScopedDatafile.js.html +403 -0
  9. package/coverage/lcov-report/lib/builder/buildScopedSegments.js.html +379 -0
  10. package/coverage/lcov-report/lib/builder/index.html +53 -8
  11. package/coverage/lcov-report/lib/builder/revision.js.html +1 -1
  12. package/coverage/lcov-report/lib/builder/traffic.js.html +1 -1
  13. package/coverage/lcov-report/lib/list/index.html +14 -14
  14. package/coverage/lcov-report/lib/list/matrix.js.html +23 -8
  15. package/coverage/lcov-report/lib/tester/helpers.js.html +1 -1
  16. package/coverage/lcov-report/lib/tester/index.html +1 -1
  17. package/coverage/lcov-report/src/builder/allocator.ts.html +1 -1
  18. package/coverage/lcov-report/src/builder/buildScopedConditions.ts.html +487 -0
  19. package/coverage/lcov-report/src/builder/buildScopedDatafile.ts.html +604 -0
  20. package/coverage/lcov-report/src/builder/buildScopedSegments.ts.html +544 -0
  21. package/coverage/lcov-report/src/builder/index.html +55 -10
  22. package/coverage/lcov-report/src/builder/revision.ts.html +1 -1
  23. package/coverage/lcov-report/src/builder/traffic.ts.html +3 -3
  24. package/coverage/lcov-report/src/list/index.html +14 -14
  25. package/coverage/lcov-report/src/list/matrix.ts.html +33 -12
  26. package/coverage/lcov-report/src/tester/helpers.ts.html +1 -1
  27. package/coverage/lcov-report/src/tester/index.html +1 -1
  28. package/coverage/lcov.info +810 -129
  29. package/jest.config.js +8 -0
  30. package/lib/builder/buildDatafile.d.ts +10 -0
  31. package/lib/builder/buildDatafile.js +27 -0
  32. package/lib/builder/buildDatafile.js.map +1 -1
  33. package/lib/builder/buildProject.d.ts +2 -0
  34. package/lib/builder/buildProject.js +38 -4
  35. package/lib/builder/buildProject.js.map +1 -1
  36. package/lib/builder/buildScopedConditions.d.ts +5 -0
  37. package/lib/builder/buildScopedConditions.js +97 -0
  38. package/lib/builder/buildScopedConditions.js.map +1 -0
  39. package/lib/builder/buildScopedConditions.spec.d.ts +1 -0
  40. package/lib/builder/buildScopedConditions.spec.js +2167 -0
  41. package/lib/builder/buildScopedConditions.spec.js.map +1 -0
  42. package/lib/builder/buildScopedDatafile.d.ts +2 -0
  43. package/lib/builder/buildScopedDatafile.js +107 -0
  44. package/lib/builder/buildScopedDatafile.js.map +1 -0
  45. package/lib/builder/buildScopedDatafile.spec.d.ts +1 -0
  46. package/lib/builder/buildScopedDatafile.spec.js +1988 -0
  47. package/lib/builder/buildScopedDatafile.spec.js.map +1 -0
  48. package/lib/builder/buildScopedSegments.d.ts +5 -0
  49. package/lib/builder/buildScopedSegments.js +99 -0
  50. package/lib/builder/buildScopedSegments.js.map +1 -0
  51. package/lib/builder/buildScopedSegments.spec.d.ts +1 -0
  52. package/lib/builder/buildScopedSegments.spec.js +1062 -0
  53. package/lib/builder/buildScopedSegments.spec.js.map +1 -0
  54. package/lib/builder/index.d.ts +1 -0
  55. package/lib/builder/index.js +1 -0
  56. package/lib/builder/index.js.map +1 -1
  57. package/lib/config/projectConfig.d.ts +9 -1
  58. package/lib/config/projectConfig.js +1 -0
  59. package/lib/config/projectConfig.js.map +1 -1
  60. package/lib/datasource/adapter.d.ts +3 -1
  61. package/lib/datasource/adapter.js.map +1 -1
  62. package/lib/datasource/filesystemAdapter.js +3 -1
  63. package/lib/datasource/filesystemAdapter.js.map +1 -1
  64. package/lib/linter/testSchema.d.ts +5 -0
  65. package/lib/linter/testSchema.js +8 -0
  66. package/lib/linter/testSchema.js.map +1 -1
  67. package/lib/list/matrix.js +5 -0
  68. package/lib/list/matrix.js.map +1 -1
  69. package/lib/tester/testFeature.d.ts +5 -3
  70. package/lib/tester/testFeature.js +34 -9
  71. package/lib/tester/testFeature.js.map +1 -1
  72. package/lib/tester/testProject.d.ts +3 -2
  73. package/lib/tester/testProject.js +40 -6
  74. package/lib/tester/testProject.js.map +1 -1
  75. package/package.json +5 -5
  76. package/src/builder/buildDatafile.ts +47 -0
  77. package/src/builder/buildProject.ts +58 -3
  78. package/src/builder/buildScopedConditions.spec.ts +2659 -0
  79. package/src/builder/buildScopedConditions.ts +134 -0
  80. package/src/builder/buildScopedDatafile.spec.ts +2236 -0
  81. package/src/builder/buildScopedDatafile.ts +173 -0
  82. package/src/builder/buildScopedSegments.spec.ts +1573 -0
  83. package/src/builder/buildScopedSegments.ts +153 -0
  84. package/src/builder/index.ts +1 -0
  85. package/src/config/projectConfig.ts +11 -1
  86. package/src/datasource/adapter.ts +4 -1
  87. package/src/datasource/filesystemAdapter.ts +4 -1
  88. package/src/linter/testSchema.ts +12 -0
  89. package/src/list/matrix.ts +7 -0
  90. package/src/tester/testFeature.ts +50 -16
  91. package/src/tester/testProject.ts +68 -8
@@ -0,0 +1,134 @@
1
+ import type {
2
+ Condition,
3
+ AndCondition,
4
+ OrCondition,
5
+ NotCondition,
6
+ Context,
7
+ } from "@featurevisor/types";
8
+ import type { DatafileReader } from "@featurevisor/sdk";
9
+
10
+ export function buildScopedConditions(
11
+ datafileReader: DatafileReader,
12
+ conditions: Condition | Condition[],
13
+ context: Context,
14
+ ): Condition | Condition[] {
15
+ const scoped = buildScopedCondition(datafileReader, conditions, context);
16
+ const removed = removeRedundantConditions(scoped);
17
+
18
+ return removed;
19
+ }
20
+
21
+ export function removeRedundantConditions(
22
+ conditions: Condition | Condition[],
23
+ ): Condition | Condition[] {
24
+ if (conditions === "*") {
25
+ return conditions;
26
+ }
27
+
28
+ if (Array.isArray(conditions)) {
29
+ // Recursively process each condition
30
+ const processed = conditions.map((c) => removeRedundantConditions(c)) as Condition[];
31
+
32
+ // Filter out "*" values
33
+ const filtered = processed.filter((c) => c !== "*");
34
+
35
+ // If all were "*", return "*"
36
+ if (filtered.length === 0) {
37
+ return "*";
38
+ }
39
+
40
+ return filtered;
41
+ }
42
+
43
+ if (typeof conditions === "object") {
44
+ if ("and" in conditions) {
45
+ const processed = conditions.and.map((c) => removeRedundantConditions(c)) as Condition[];
46
+ const filtered = processed.filter((c) => c !== "*");
47
+
48
+ // If all were "*", return "*"
49
+ if (filtered.length === 0) {
50
+ return "*";
51
+ }
52
+
53
+ return {
54
+ and: filtered,
55
+ } as AndCondition;
56
+ }
57
+
58
+ if ("or" in conditions) {
59
+ const processed = conditions.or.map((c) => removeRedundantConditions(c)) as Condition[];
60
+ const filtered = processed.filter((c) => c !== "*");
61
+
62
+ // If all were "*", return "*"
63
+ if (filtered.length === 0) {
64
+ return "*";
65
+ }
66
+
67
+ return {
68
+ or: filtered,
69
+ } as OrCondition;
70
+ }
71
+
72
+ if ("not" in conditions) {
73
+ const processed = conditions.not.map((c) => removeRedundantConditions(c)) as Condition[];
74
+ const filtered = processed.filter((c) => c !== "*");
75
+
76
+ // If all were "*", return "*"
77
+ if (filtered.length === 0) {
78
+ return "*";
79
+ }
80
+
81
+ return {
82
+ not: filtered,
83
+ } as NotCondition;
84
+ }
85
+ }
86
+
87
+ return conditions;
88
+ }
89
+
90
+ export function buildScopedCondition(
91
+ datafileReader: DatafileReader,
92
+ condition: Condition | Condition[],
93
+ context: Context,
94
+ ): Condition | Condition[] {
95
+ if (condition === "*") {
96
+ return condition;
97
+ }
98
+
99
+ if (Array.isArray(condition)) {
100
+ return condition.map((c) => buildScopedCondition(datafileReader, c, context)) as Condition[];
101
+ }
102
+
103
+ if (typeof condition === "object") {
104
+ // plain condition
105
+ if ("attribute" in condition) {
106
+ const matched = datafileReader.allConditionsAreMatched(condition, context);
107
+
108
+ if (matched) {
109
+ return "*";
110
+ }
111
+ }
112
+
113
+ // AND, OR, NOT conditions
114
+ if ("and" in condition) {
115
+ return {
116
+ and: condition.and.map((c) => buildScopedCondition(datafileReader, c, context)),
117
+ } as AndCondition;
118
+ }
119
+
120
+ if ("or" in condition) {
121
+ return {
122
+ or: condition.or.map((c) => buildScopedCondition(datafileReader, c, context)),
123
+ } as OrCondition;
124
+ }
125
+
126
+ if ("not" in condition) {
127
+ return {
128
+ not: condition.not.map((c) => buildScopedCondition(datafileReader, c, context)),
129
+ } as NotCondition;
130
+ }
131
+ }
132
+
133
+ return condition;
134
+ }