@featurevisor/core 0.50.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.eslintcache +1 -1
  2. package/CHANGELOG.md +19 -0
  3. package/coverage/clover.xml +2 -2
  4. package/coverage/lcov-report/index.html +1 -1
  5. package/coverage/lcov-report/lib/allocator.js.html +1 -1
  6. package/coverage/lcov-report/lib/index.html +1 -1
  7. package/coverage/lcov-report/lib/traffic.js.html +1 -1
  8. package/coverage/lcov-report/src/allocator.ts.html +1 -1
  9. package/coverage/lcov-report/src/index.html +1 -1
  10. package/coverage/lcov-report/src/traffic.ts.html +1 -1
  11. package/lib/linter/attributeSchema.d.ts +2 -0
  12. package/lib/linter/attributeSchema.js +15 -0
  13. package/lib/linter/attributeSchema.js.map +1 -0
  14. package/lib/linter/checkCircularDependency.d.ts +3 -0
  15. package/lib/linter/checkCircularDependency.js +30 -0
  16. package/lib/linter/checkCircularDependency.js.map +1 -0
  17. package/lib/linter/conditionSchema.d.ts +3 -0
  18. package/lib/linter/conditionSchema.js +44 -0
  19. package/lib/linter/conditionSchema.js.map +1 -0
  20. package/lib/linter/featureSchema.d.ts +3 -0
  21. package/lib/linter/featureSchema.js +147 -0
  22. package/lib/linter/featureSchema.js.map +1 -0
  23. package/lib/linter/groupSchema.d.ts +4 -0
  24. package/lib/linter/groupSchema.js +51 -0
  25. package/lib/linter/groupSchema.js.map +1 -0
  26. package/lib/linter/index.d.ts +2 -0
  27. package/lib/linter/index.js +241 -0
  28. package/lib/linter/index.js.map +1 -0
  29. package/lib/linter/printJoiError.d.ts +2 -0
  30. package/lib/linter/printJoiError.js +14 -0
  31. package/lib/linter/printJoiError.js.map +1 -0
  32. package/lib/linter/segmentSchema.d.ts +3 -0
  33. package/lib/linter/segmentSchema.js +14 -0
  34. package/lib/linter/segmentSchema.js.map +1 -0
  35. package/lib/linter/testSchema.d.ts +3 -0
  36. package/lib/linter/testSchema.js +33 -0
  37. package/lib/linter/testSchema.js.map +1 -0
  38. package/package.json +5 -5
  39. package/src/linter/attributeSchema.ts +12 -0
  40. package/src/linter/checkCircularDependency.ts +45 -0
  41. package/src/linter/conditionSchema.ts +85 -0
  42. package/src/linter/featureSchema.ts +205 -0
  43. package/src/linter/groupSchema.ts +63 -0
  44. package/src/linter/index.ts +179 -0
  45. package/src/linter/printJoiError.ts +11 -0
  46. package/src/linter/segmentSchema.ts +13 -0
  47. package/src/linter/testSchema.ts +43 -0
  48. package/lib/linter.d.ts +0 -11
  49. package/lib/linter.js +0 -541
  50. package/lib/linter.js.map +0 -1
  51. package/src/linter.ts +0 -626
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.lintProject = void 0;
40
+ // for use in node only
41
+ var fs = require("fs");
42
+ var Joi = require("joi");
43
+ var datasource_1 = require("../datasource/datasource");
44
+ var attributeSchema_1 = require("./attributeSchema");
45
+ var conditionSchema_1 = require("./conditionSchema");
46
+ var segmentSchema_1 = require("./segmentSchema");
47
+ var groupSchema_1 = require("./groupSchema");
48
+ var featureSchema_1 = require("./featureSchema");
49
+ var testSchema_1 = require("./testSchema");
50
+ var checkCircularDependency_1 = require("./checkCircularDependency");
51
+ var printJoiError_1 = require("./printJoiError");
52
+ function lintProject(projectConfig) {
53
+ return __awaiter(this, void 0, void 0, function () {
54
+ var hasError, datasource, availableAttributeKeys, availableSegmentKeys, availableFeatureKeys, attributes, attributeJoiSchema, _i, attributes_1, key, parsed, e_1, segments, conditionsJoiSchema, segmentJoiSchema, _a, segments_1, key, parsed, e_2, groups, groupJoiSchema, _b, groups_1, key, parsed, e_3, features, featureJoiSchema, _c, features_1, key, parsed, e_4, tests, testsJoiSchema, _d, tests_1, key, parsed, e_5;
55
+ return __generator(this, function (_e) {
56
+ switch (_e.label) {
57
+ case 0:
58
+ hasError = false;
59
+ datasource = new datasource_1.Datasource(projectConfig);
60
+ availableAttributeKeys = [];
61
+ availableSegmentKeys = [];
62
+ availableFeatureKeys = [];
63
+ attributes = datasource.listAttributes();
64
+ console.log("Linting ".concat(attributes.length, " attributes...\n"));
65
+ attributeJoiSchema = (0, attributeSchema_1.getAttributeJoiSchema)();
66
+ _i = 0, attributes_1 = attributes;
67
+ _e.label = 1;
68
+ case 1:
69
+ if (!(_i < attributes_1.length)) return [3 /*break*/, 6];
70
+ key = attributes_1[_i];
71
+ parsed = datasource.readAttribute(key);
72
+ availableAttributeKeys.push(key);
73
+ _e.label = 2;
74
+ case 2:
75
+ _e.trys.push([2, 4, , 5]);
76
+ return [4 /*yield*/, attributeJoiSchema.validateAsync(parsed)];
77
+ case 3:
78
+ _e.sent();
79
+ return [3 /*break*/, 5];
80
+ case 4:
81
+ e_1 = _e.sent();
82
+ console.log(" =>", key);
83
+ if (e_1 instanceof Joi.ValidationError) {
84
+ (0, printJoiError_1.printJoiError)(e_1);
85
+ }
86
+ else {
87
+ console.log(e_1);
88
+ }
89
+ hasError = true;
90
+ return [3 /*break*/, 5];
91
+ case 5:
92
+ _i++;
93
+ return [3 /*break*/, 1];
94
+ case 6:
95
+ segments = datasource.listSegments();
96
+ console.log("\nLinting ".concat(segments.length, " segments...\n"));
97
+ conditionsJoiSchema = (0, conditionSchema_1.getConditionsJoiSchema)(projectConfig, availableAttributeKeys);
98
+ segmentJoiSchema = (0, segmentSchema_1.getSegmentJoiSchema)(projectConfig, conditionsJoiSchema);
99
+ _a = 0, segments_1 = segments;
100
+ _e.label = 7;
101
+ case 7:
102
+ if (!(_a < segments_1.length)) return [3 /*break*/, 12];
103
+ key = segments_1[_a];
104
+ parsed = datasource.readSegment(key);
105
+ availableSegmentKeys.push(key);
106
+ _e.label = 8;
107
+ case 8:
108
+ _e.trys.push([8, 10, , 11]);
109
+ return [4 /*yield*/, segmentJoiSchema.validateAsync(parsed)];
110
+ case 9:
111
+ _e.sent();
112
+ return [3 /*break*/, 11];
113
+ case 10:
114
+ e_2 = _e.sent();
115
+ console.log(" =>", key);
116
+ if (e_2 instanceof Joi.ValidationError) {
117
+ (0, printJoiError_1.printJoiError)(e_2);
118
+ }
119
+ else {
120
+ console.log(e_2);
121
+ }
122
+ hasError = true;
123
+ return [3 /*break*/, 11];
124
+ case 11:
125
+ _a++;
126
+ return [3 /*break*/, 7];
127
+ case 12:
128
+ if (!fs.existsSync(projectConfig.groupsDirectoryPath)) return [3 /*break*/, 18];
129
+ groups = datasource.listGroups();
130
+ console.log("\nLinting ".concat(groups.length, " groups...\n"));
131
+ groupJoiSchema = (0, groupSchema_1.getGroupJoiSchema)(projectConfig, datasource, availableFeatureKeys);
132
+ _b = 0, groups_1 = groups;
133
+ _e.label = 13;
134
+ case 13:
135
+ if (!(_b < groups_1.length)) return [3 /*break*/, 18];
136
+ key = groups_1[_b];
137
+ parsed = datasource.readGroup(key);
138
+ _e.label = 14;
139
+ case 14:
140
+ _e.trys.push([14, 16, , 17]);
141
+ return [4 /*yield*/, groupJoiSchema.validateAsync(parsed)];
142
+ case 15:
143
+ _e.sent();
144
+ return [3 /*break*/, 17];
145
+ case 16:
146
+ e_3 = _e.sent();
147
+ console.log(" =>", key);
148
+ if (e_3 instanceof Joi.ValidationError) {
149
+ (0, printJoiError_1.printJoiError)(e_3);
150
+ }
151
+ else {
152
+ console.log(e_3);
153
+ }
154
+ hasError = true;
155
+ return [3 /*break*/, 17];
156
+ case 17:
157
+ _b++;
158
+ return [3 /*break*/, 13];
159
+ case 18:
160
+ features = datasource.listFeatures();
161
+ console.log("\nLinting ".concat(features.length, " features...\n"));
162
+ featureJoiSchema = (0, featureSchema_1.getFeatureJoiSchema)(projectConfig, conditionsJoiSchema, availableSegmentKeys, availableFeatureKeys);
163
+ _c = 0, features_1 = features;
164
+ _e.label = 19;
165
+ case 19:
166
+ if (!(_c < features_1.length)) return [3 /*break*/, 25];
167
+ key = features_1[_c];
168
+ parsed = datasource.readFeature(key);
169
+ availableFeatureKeys.push(key);
170
+ _e.label = 20;
171
+ case 20:
172
+ _e.trys.push([20, 22, , 23]);
173
+ return [4 /*yield*/, featureJoiSchema.validateAsync(parsed)];
174
+ case 21:
175
+ _e.sent();
176
+ return [3 /*break*/, 23];
177
+ case 22:
178
+ e_4 = _e.sent();
179
+ console.log(" =>", key);
180
+ if (e_4 instanceof Joi.ValidationError) {
181
+ (0, printJoiError_1.printJoiError)(e_4);
182
+ }
183
+ else {
184
+ console.log(e_4);
185
+ }
186
+ hasError = true;
187
+ return [3 /*break*/, 23];
188
+ case 23:
189
+ if (parsed.required) {
190
+ try {
191
+ (0, checkCircularDependency_1.checkForCircularDependencyInRequired)(datasource, key, parsed.required);
192
+ }
193
+ catch (e) {
194
+ console.log(" =>", key);
195
+ console.log(" => Error:", e.message);
196
+ hasError = true;
197
+ }
198
+ }
199
+ _e.label = 24;
200
+ case 24:
201
+ _c++;
202
+ return [3 /*break*/, 19];
203
+ case 25:
204
+ if (!fs.existsSync(projectConfig.testsDirectoryPath)) return [3 /*break*/, 31];
205
+ tests = datasource.listTests();
206
+ console.log("\nLinting ".concat(tests.length, " tests...\n"));
207
+ testsJoiSchema = (0, testSchema_1.getTestsJoiSchema)(projectConfig, availableFeatureKeys, availableSegmentKeys);
208
+ _d = 0, tests_1 = tests;
209
+ _e.label = 26;
210
+ case 26:
211
+ if (!(_d < tests_1.length)) return [3 /*break*/, 31];
212
+ key = tests_1[_d];
213
+ parsed = datasource.readTest(key);
214
+ _e.label = 27;
215
+ case 27:
216
+ _e.trys.push([27, 29, , 30]);
217
+ return [4 /*yield*/, testsJoiSchema.validateAsync(parsed)];
218
+ case 28:
219
+ _e.sent();
220
+ return [3 /*break*/, 30];
221
+ case 29:
222
+ e_5 = _e.sent();
223
+ console.log(" =>", key);
224
+ if (e_5 instanceof Joi.ValidationError) {
225
+ (0, printJoiError_1.printJoiError)(e_5);
226
+ }
227
+ else {
228
+ console.log(e_5);
229
+ }
230
+ hasError = true;
231
+ return [3 /*break*/, 30];
232
+ case 30:
233
+ _d++;
234
+ return [3 /*break*/, 26];
235
+ case 31: return [2 /*return*/, hasError];
236
+ }
237
+ });
238
+ });
239
+ }
240
+ exports.lintProject = lintProject;
241
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/linter/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uBAAuB;AACvB,uBAAyB;AAEzB,yBAA2B;AAE3B,uDAAsD;AAGtD,qDAA0D;AAC1D,qDAA2D;AAC3D,iDAAsD;AACtD,6CAAkD;AAClD,iDAAsD;AACtD,2CAAiD;AAEjD,qEAAiF;AACjF,iDAAgD;AAEhD,SAAsB,WAAW,CAAC,aAA4B;;;;;;oBACxD,QAAQ,GAAG,KAAK,CAAC;oBACf,UAAU,GAAG,IAAI,uBAAU,CAAC,aAAa,CAAC,CAAC;oBAE3C,sBAAsB,GAAa,EAAE,CAAC;oBACtC,oBAAoB,GAAa,EAAE,CAAC;oBACpC,oBAAoB,GAAa,EAAE,CAAC;oBAGpC,UAAU,GAAG,UAAU,CAAC,cAAc,EAAE,CAAC;oBAC/C,OAAO,CAAC,GAAG,CAAC,kBAAW,UAAU,CAAC,MAAM,qBAAkB,CAAC,CAAC;oBAEtD,kBAAkB,GAAG,IAAA,uCAAqB,GAAE,CAAC;0BAEvB,EAAV,yBAAU;;;yBAAV,CAAA,wBAAU,CAAA;oBAAjB,GAAG;oBACN,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;oBAC7C,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;;;;oBAG/B,qBAAM,kBAAkB,CAAC,aAAa,CAAC,MAAM,CAAC,EAAA;;oBAA9C,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AAC,GAAC,CAAC,CAAC;qBAClB;yBAAM;wBACL,OAAO,CAAC,GAAG,CAAC,GAAC,CAAC,CAAC;qBAChB;oBAED,QAAQ,GAAG,IAAI,CAAC;;;oBAdF,IAAK,CAAA;;yBAmBzB,sBAAO,QAAQ,EAAC;;;;CACjB;AAhKD,kCAgKC"}
@@ -0,0 +1,2 @@
1
+ import * as Joi from "joi";
2
+ export declare function printJoiError(e: Joi.ValidationError): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printJoiError = void 0;
4
+ function printJoiError(e) {
5
+ var details = e.details;
6
+ details.forEach(function (detail) {
7
+ var _a;
8
+ console.error(" => Error:", detail.message);
9
+ console.error(" => Path:", detail.path.join("."));
10
+ console.error(" => Value:", (_a = detail.context) === null || _a === void 0 ? void 0 : _a.value);
11
+ });
12
+ }
13
+ exports.printJoiError = printJoiError;
14
+ //# sourceMappingURL=printJoiError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printJoiError.js","sourceRoot":"","sources":["../../src/linter/printJoiError.ts"],"names":[],"mappings":";;;AAEA,SAAgB,aAAa,CAAC,CAAsB;IAC1C,IAAA,OAAO,GAAK,CAAC,QAAN,CAAO;IAEtB,OAAO,CAAC,OAAO,CAAC,UAAC,MAAM;;QACrB,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,MAAA,MAAM,CAAC,OAAO,0CAAE,KAAK,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC;AARD,sCAQC"}
@@ -0,0 +1,3 @@
1
+ import * as Joi from "joi";
2
+ import { ProjectConfig } from "../config";
3
+ export declare function getSegmentJoiSchema(projectConfig: ProjectConfig, conditionsJoiSchema: any): Joi.ObjectSchema<any>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSegmentJoiSchema = void 0;
4
+ var Joi = require("joi");
5
+ function getSegmentJoiSchema(projectConfig, conditionsJoiSchema) {
6
+ var segmentJoiSchema = Joi.object({
7
+ archived: Joi.boolean().optional(),
8
+ description: Joi.string().required(),
9
+ conditions: conditionsJoiSchema.required(),
10
+ });
11
+ return segmentJoiSchema;
12
+ }
13
+ exports.getSegmentJoiSchema = getSegmentJoiSchema;
14
+ //# sourceMappingURL=segmentSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segmentSchema.js","sourceRoot":"","sources":["../../src/linter/segmentSchema.ts"],"names":[],"mappings":";;;AAAA,yBAA2B;AAI3B,SAAgB,mBAAmB,CAAC,aAA4B,EAAE,mBAAmB;IACnF,IAAM,gBAAgB,GAAG,GAAG,CAAC,MAAM,CAAC;QAClC,QAAQ,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;QAClC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACpC,UAAU,EAAE,mBAAmB,CAAC,QAAQ,EAAE;KAC3C,CAAC,CAAC;IAEH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AARD,kDAQC"}
@@ -0,0 +1,3 @@
1
+ import * as Joi from "joi";
2
+ import { ProjectConfig } from "../config";
3
+ export declare function getTestsJoiSchema(projectConfig: ProjectConfig, availableFeatureKeys: string[], availableSegmentKeys: string[]): Joi.AlternativesSchema<any>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTestsJoiSchema = void 0;
4
+ var Joi = require("joi");
5
+ function getTestsJoiSchema(projectConfig, availableFeatureKeys, availableSegmentKeys) {
6
+ var _a, _b, _c;
7
+ var segmentTestJoiSchema = Joi.object({
8
+ segment: (_a = Joi.string())
9
+ .valid.apply(_a, availableSegmentKeys).required(),
10
+ assertions: Joi.array().items(Joi.object({
11
+ description: Joi.string().optional(),
12
+ context: Joi.object(),
13
+ expectedToMatch: Joi.boolean(),
14
+ })),
15
+ });
16
+ var featureTestJoiSchema = Joi.object({
17
+ feature: (_b = Joi.string())
18
+ .valid.apply(_b, availableFeatureKeys).required(),
19
+ assertions: Joi.array().items(Joi.object({
20
+ description: Joi.string().optional(),
21
+ at: Joi.number().precision(3).min(0).max(100),
22
+ environment: (_c = Joi.string()).valid.apply(_c, projectConfig.environments),
23
+ context: Joi.object(),
24
+ // @TODO: one or all below
25
+ expectedToBeEnabled: Joi.boolean().required(),
26
+ expectedVariation: Joi.alternatives().try(Joi.string(), Joi.number(), Joi.boolean()),
27
+ expectedVariables: Joi.object(),
28
+ })),
29
+ });
30
+ return Joi.alternatives().try(segmentTestJoiSchema, featureTestJoiSchema);
31
+ }
32
+ exports.getTestsJoiSchema = getTestsJoiSchema;
33
+ //# sourceMappingURL=testSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testSchema.js","sourceRoot":"","sources":["../../src/linter/testSchema.ts"],"names":[],"mappings":";;;AAAA,yBAA2B;AAI3B,SAAgB,iBAAiB,CAC/B,aAA4B,EAC5B,oBAA8B,EAC9B,oBAA8B;;IAE9B,IAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC;QACtC,OAAO,EAAE,CAAA,KAAA,GAAG,CAAC,MAAM,EAAE,CAAA;aAClB,KAAK,WAAI,oBAAoB,EAC7B,QAAQ,EAAE;QACb,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAC3B,GAAG,CAAC,MAAM,CAAC;YACT,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YACpC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;YACrB,eAAe,EAAE,GAAG,CAAC,OAAO,EAAE;SAC/B,CAAC,CACH;KACF,CAAC,CAAC;IAEH,IAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC;QACtC,OAAO,EAAE,CAAA,KAAA,GAAG,CAAC,MAAM,EAAE,CAAA;aAClB,KAAK,WAAI,oBAAoB,EAC7B,QAAQ,EAAE;QACb,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,CAC3B,GAAG,CAAC,MAAM,CAAC;YACT,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;YACpC,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7C,WAAW,EAAE,CAAA,KAAA,GAAG,CAAC,MAAM,EAAE,CAAA,CAAC,KAAK,WAAI,aAAa,CAAC,YAAY,CAAC;YAC9D,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;YAErB,0BAA0B;YAC1B,mBAAmB,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;YAC7C,iBAAiB,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;YACpF,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE;SAChC,CAAC,CACH;KACF,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAC5E,CAAC;AAtCD,8CAsCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@featurevisor/core",
3
- "version": "0.50.0",
3
+ "version": "0.51.1",
4
4
  "description": "Core package of Featurevisor for Node.js usage",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -44,9 +44,9 @@
44
44
  },
45
45
  "license": "MIT",
46
46
  "dependencies": {
47
- "@featurevisor/sdk": "^0.50.0",
48
- "@featurevisor/site": "^0.50.0",
49
- "@featurevisor/types": "^0.50.0",
47
+ "@featurevisor/sdk": "^0.51.0",
48
+ "@featurevisor/site": "^0.51.0",
49
+ "@featurevisor/types": "^0.51.0",
50
50
  "axios": "^1.3.4",
51
51
  "joi": "^17.8.3",
52
52
  "js-yaml": "^4.1.0",
@@ -57,5 +57,5 @@
57
57
  "@types/js-yaml": "^4.0.5",
58
58
  "@types/tar": "^6.1.4"
59
59
  },
60
- "gitHead": "8185b286336d8fe3a9229e7d2545607a88f3c083"
60
+ "gitHead": "352875a02c8c5e99c1231206f4a19c16180d5da6"
61
61
  }
@@ -0,0 +1,12 @@
1
+ import * as Joi from "joi";
2
+
3
+ export function getAttributeJoiSchema() {
4
+ const attributeJoiSchema = Joi.object({
5
+ archived: Joi.boolean(),
6
+ type: Joi.string().allow("boolean", "string", "integer", "double", "date").required(),
7
+ description: Joi.string().required(),
8
+ capture: Joi.boolean(),
9
+ });
10
+
11
+ return attributeJoiSchema;
12
+ }
@@ -0,0 +1,45 @@
1
+ import { FeatureKey, Required } from "@featurevisor/types";
2
+
3
+ import { Datasource } from "../datasource/datasource";
4
+
5
+ export function checkForCircularDependencyInRequired(
6
+ datasource: Datasource,
7
+ featureKey: FeatureKey,
8
+ required?: Required[],
9
+ chain: FeatureKey[] = [],
10
+ ) {
11
+ if (!required) {
12
+ return;
13
+ }
14
+
15
+ const requiredKeys = required.map((r) => (typeof r === "string" ? r : r.key));
16
+
17
+ if (requiredKeys.length === 0) {
18
+ return;
19
+ }
20
+
21
+ for (const requiredKey of requiredKeys) {
22
+ chain.push(requiredKey);
23
+
24
+ if (chain.indexOf(featureKey) > -1) {
25
+ throw new Error(`circular dependency found: ${chain.join(" -> ")}`);
26
+ }
27
+
28
+ const requiredFeatureExists = datasource.entityExists("feature", requiredKey);
29
+
30
+ if (!requiredFeatureExists) {
31
+ throw new Error(`required feature "${requiredKey}" not found`);
32
+ }
33
+
34
+ const requiredParsedFeature = datasource.readFeature(requiredKey);
35
+
36
+ if (requiredParsedFeature.required) {
37
+ checkForCircularDependencyInRequired(
38
+ datasource,
39
+ featureKey,
40
+ requiredParsedFeature.required,
41
+ chain,
42
+ );
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,85 @@
1
+ import * as Joi from "joi";
2
+
3
+ import { ProjectConfig } from "../config";
4
+
5
+ export function getConditionsJoiSchema(
6
+ projectConfig: ProjectConfig,
7
+ availableAttributeKeys: string[],
8
+ ) {
9
+ const plainConditionJoiSchema = Joi.object({
10
+ attribute: Joi.string()
11
+ .valid(...availableAttributeKeys)
12
+ .required(),
13
+ operator: Joi.string()
14
+ .valid(
15
+ "equals",
16
+ "notEquals",
17
+
18
+ // numeric
19
+ "greaterThan",
20
+ "greaterThanOrEquals",
21
+ "lessThan",
22
+ "lessThanOrEquals",
23
+
24
+ // string
25
+ "contains",
26
+ "notContains",
27
+ "startsWith",
28
+ "endsWith",
29
+
30
+ // semver (string)
31
+ "semverEquals",
32
+ "semverNotEquals",
33
+ "semverGreaterThan",
34
+ "semverGreaterThanOrEquals",
35
+ "semverLessThan",
36
+ "semverLessThanOrEquals",
37
+
38
+ // date comparisons
39
+ "before",
40
+ "after",
41
+
42
+ // array of strings
43
+ "in",
44
+ "notIn",
45
+ )
46
+ .required(),
47
+ value: Joi.alternatives()
48
+ .try(
49
+ // @TODO: make them more specific
50
+ Joi.string(),
51
+ Joi.number(),
52
+ Joi.boolean(),
53
+ Joi.date(),
54
+ Joi.array().items(Joi.string()),
55
+ )
56
+ .required(),
57
+ });
58
+
59
+ const andOrNotConditionJoiSchema = Joi.alternatives()
60
+ .try(
61
+ Joi.object({
62
+ and: Joi.array().items(Joi.link("#andOrNotCondition"), plainConditionJoiSchema),
63
+ }),
64
+ Joi.object({
65
+ or: Joi.array().items(Joi.link("#andOrNotCondition"), plainConditionJoiSchema),
66
+ }),
67
+ Joi.object({
68
+ // @TODO: allow plainConditionJoiSchema as well?
69
+ not: Joi.array().items(Joi.link("#andOrNotCondition"), plainConditionJoiSchema),
70
+ }),
71
+ )
72
+ .id("andOrNotCondition");
73
+
74
+ const conditionJoiSchema = Joi.alternatives().try(
75
+ andOrNotConditionJoiSchema,
76
+ plainConditionJoiSchema,
77
+ );
78
+
79
+ const conditionsJoiSchema = Joi.alternatives().try(
80
+ conditionJoiSchema,
81
+ Joi.array().items(conditionJoiSchema),
82
+ );
83
+
84
+ return conditionsJoiSchema;
85
+ }