@featurevisor/core 2.10.0 → 2.12.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/CHANGELOG.md +22 -0
- package/coverage/clover.xml +684 -3
- package/coverage/coverage-final.json +4 -0
- package/coverage/lcov-report/builder/allocator.ts.html +1 -1
- package/coverage/lcov-report/builder/buildScopedConditions.ts.html +1 -1
- package/coverage/lcov-report/builder/buildScopedDatafile.ts.html +1 -1
- package/coverage/lcov-report/builder/buildScopedSegments.ts.html +1 -1
- package/coverage/lcov-report/builder/index.html +1 -1
- package/coverage/lcov-report/builder/revision.ts.html +1 -1
- package/coverage/lcov-report/builder/traffic.ts.html +1 -1
- package/coverage/lcov-report/index.html +25 -10
- package/coverage/lcov-report/linter/conditionSchema.ts.html +775 -0
- package/coverage/lcov-report/linter/featureSchema.ts.html +4924 -0
- package/coverage/lcov-report/linter/index.html +161 -0
- package/coverage/lcov-report/linter/schema.ts.html +1471 -0
- package/coverage/lcov-report/linter/segmentSchema.ts.html +130 -0
- package/coverage/lcov-report/list/index.html +1 -1
- package/coverage/lcov-report/list/matrix.ts.html +1 -1
- package/coverage/lcov-report/parsers/index.html +1 -1
- package/coverage/lcov-report/parsers/json.ts.html +1 -1
- package/coverage/lcov-report/parsers/yml.ts.html +1 -1
- package/coverage/lcov-report/tester/helpers.ts.html +1 -1
- package/coverage/lcov-report/tester/index.html +1 -1
- package/coverage/lcov.info +1471 -0
- package/lib/builder/buildDatafile.js +15 -1
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/config/projectConfig.d.ts +2 -0
- package/lib/config/projectConfig.js +3 -1
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/datasource/datasource.d.ts +6 -1
- package/lib/datasource/datasource.js +16 -0
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/filesystemAdapter.js +10 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/generate-code/typescript.js +283 -49
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/linter/conditionSchema.spec.d.ts +1 -0
- package/lib/linter/conditionSchema.spec.js +331 -0
- package/lib/linter/conditionSchema.spec.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +153 -17
- package/lib/linter/featureSchema.js +536 -49
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/featureSchema.spec.d.ts +1 -0
- package/lib/linter/featureSchema.spec.js +978 -0
- package/lib/linter/featureSchema.spec.js.map +1 -0
- package/lib/linter/lintProject.js +67 -1
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/schema.d.ts +42 -0
- package/lib/linter/schema.js +417 -0
- package/lib/linter/schema.js.map +1 -0
- package/lib/linter/schema.spec.d.ts +1 -0
- package/lib/linter/schema.spec.js +483 -0
- package/lib/linter/schema.spec.js.map +1 -0
- package/lib/linter/segmentSchema.spec.d.ts +1 -0
- package/lib/linter/segmentSchema.spec.js +231 -0
- package/lib/linter/segmentSchema.spec.js.map +1 -0
- package/lib/tester/testFeature.js +5 -3
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/utils/git.js +3 -0
- package/lib/utils/git.js.map +1 -1
- package/package.json +5 -5
- package/src/builder/buildDatafile.ts +17 -1
- package/src/config/projectConfig.ts +3 -0
- package/src/datasource/datasource.ts +23 -0
- package/src/datasource/filesystemAdapter.ts +7 -0
- package/src/generate-code/typescript.ts +333 -52
- package/src/linter/conditionSchema.spec.ts +446 -0
- package/src/linter/featureSchema.spec.ts +1218 -0
- package/src/linter/featureSchema.ts +747 -70
- package/src/linter/lintProject.ts +84 -0
- package/src/linter/schema.spec.ts +617 -0
- package/src/linter/schema.ts +462 -0
- package/src/linter/segmentSchema.spec.ts +273 -0
- package/src/tester/testFeature.ts +5 -3
- package/src/utils/git.ts +2 -0
- package/lib/linter/propertySchema.d.ts +0 -5
- package/lib/linter/propertySchema.js +0 -43
- package/lib/linter/propertySchema.js.map +0 -1
- package/src/linter/propertySchema.ts +0 -47
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
// for use in node only
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
|
|
4
|
+
import type { Schema } from "@featurevisor/types";
|
|
5
|
+
|
|
4
6
|
import { getAttributeZodSchema } from "./attributeSchema";
|
|
5
7
|
import { getConditionsZodSchema } from "./conditionSchema";
|
|
6
8
|
import { getSegmentZodSchema } from "./segmentSchema";
|
|
7
9
|
import { getGroupZodSchema } from "./groupSchema";
|
|
8
10
|
import { getFeatureZodSchema } from "./featureSchema";
|
|
11
|
+
import { getSchemaZodSchema } from "./schema";
|
|
9
12
|
import { getTestsZodSchema } from "./testSchema";
|
|
10
13
|
|
|
11
14
|
import { checkForCircularDependencyInRequired } from "./checkCircularDependency";
|
|
@@ -54,6 +57,8 @@ export async function lintProject(
|
|
|
54
57
|
fullPath = path.join(projectConfig.featuresDirectoryPath, fileName);
|
|
55
58
|
} else if (type === "group") {
|
|
56
59
|
fullPath = path.join(projectConfig.groupsDirectoryPath, fileName);
|
|
60
|
+
} else if (type === "schema") {
|
|
61
|
+
fullPath = path.join(projectConfig.schemasDirectoryPath, fileName);
|
|
57
62
|
} else if (type === "test") {
|
|
58
63
|
fullPath = path.join(projectConfig.testsDirectoryPath, fileName);
|
|
59
64
|
} else {
|
|
@@ -209,6 +214,17 @@ export async function lintProject(
|
|
|
209
214
|
}
|
|
210
215
|
}
|
|
211
216
|
|
|
217
|
+
// List schemas and load parsed schemas for feature variable validation (schema references)
|
|
218
|
+
const schemas = await datasource.listSchemas();
|
|
219
|
+
const schemasByKey: Record<string, Schema> = {};
|
|
220
|
+
for (const key of schemas) {
|
|
221
|
+
try {
|
|
222
|
+
schemasByKey[key] = await datasource.readSchema(key);
|
|
223
|
+
} catch {
|
|
224
|
+
// Schema file may be invalid; skip for feature variable resolution
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
212
228
|
// lint features
|
|
213
229
|
const features = await datasource.listFeatures();
|
|
214
230
|
const featureZodSchema = getFeatureZodSchema(
|
|
@@ -217,6 +233,8 @@ export async function lintProject(
|
|
|
217
233
|
flattenedAttributes as [string, ...string[]],
|
|
218
234
|
segments as [string, ...string[]],
|
|
219
235
|
features as [string, ...string[]],
|
|
236
|
+
schemas,
|
|
237
|
+
schemasByKey,
|
|
220
238
|
);
|
|
221
239
|
|
|
222
240
|
if (!options.entityType || options.entityType === "feature") {
|
|
@@ -374,6 +392,68 @@ export async function lintProject(
|
|
|
374
392
|
|
|
375
393
|
// @TODO: feature cannot exist in multiple groups
|
|
376
394
|
|
|
395
|
+
// lint schemas (schemas and schemasByKey already loaded above for feature linting)
|
|
396
|
+
const schemaZodSchema = getSchemaZodSchema(schemas);
|
|
397
|
+
|
|
398
|
+
if (!options.entityType || options.entityType === "schema") {
|
|
399
|
+
const filteredKeys = !keyPattern ? schemas : schemas.filter((key) => keyPattern.test(key));
|
|
400
|
+
|
|
401
|
+
if (filteredKeys.length > 0) {
|
|
402
|
+
console.log(`Linting ${filteredKeys.length} schemas...\n`);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
for (const key of filteredKeys) {
|
|
406
|
+
const fullPath = getFullPathFromKey("schema", key);
|
|
407
|
+
|
|
408
|
+
if (!ENTITY_NAME_REGEX.test(key)) {
|
|
409
|
+
console.log(CLI_FORMAT_BOLD_UNDERLINE, fullPath);
|
|
410
|
+
|
|
411
|
+
if (options.authors) {
|
|
412
|
+
const authors = await getAuthorsOfEntity(datasource, "schema", key);
|
|
413
|
+
console.log(` Authors: ${authors.join(", ")}\n`);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
console.log(CLI_FORMAT_RED, ` => Error: Invalid name: "${key}"`);
|
|
417
|
+
console.log(CLI_FORMAT_RED, ` ${ENTITY_NAME_REGEX_ERROR}`);
|
|
418
|
+
console.log("");
|
|
419
|
+
hasError = true;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
try {
|
|
423
|
+
const parsed = await datasource.readSchema(key);
|
|
424
|
+
|
|
425
|
+
const result = schemaZodSchema.safeParse(parsed);
|
|
426
|
+
|
|
427
|
+
if (!result.success) {
|
|
428
|
+
console.log(CLI_FORMAT_BOLD_UNDERLINE, fullPath);
|
|
429
|
+
|
|
430
|
+
if (options.authors) {
|
|
431
|
+
const authors = await getAuthorsOfEntity(datasource, "schema", key);
|
|
432
|
+
console.log(` Authors: ${authors.join(", ")}\n`);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if ("error" in result) {
|
|
436
|
+
printZodError(result.error);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
hasError = true;
|
|
440
|
+
}
|
|
441
|
+
} catch (e) {
|
|
442
|
+
console.log(CLI_FORMAT_BOLD_UNDERLINE, fullPath);
|
|
443
|
+
|
|
444
|
+
if (options.authors) {
|
|
445
|
+
const authors = await getAuthorsOfEntity(datasource, "schema", key);
|
|
446
|
+
console.log(` Authors: ${authors.join(", ")}\n`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
console.log("");
|
|
450
|
+
console.log(e);
|
|
451
|
+
|
|
452
|
+
hasError = true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
377
457
|
// lint tests
|
|
378
458
|
const tests = await datasource.listTests();
|
|
379
459
|
|
|
@@ -487,6 +567,10 @@ export const lintPlugin: Plugin = {
|
|
|
487
567
|
command: "lint --entityType=group",
|
|
488
568
|
description: "lint only groups",
|
|
489
569
|
},
|
|
570
|
+
{
|
|
571
|
+
command: "lint --entityType=schema",
|
|
572
|
+
description: "lint only schemas",
|
|
573
|
+
},
|
|
490
574
|
{
|
|
491
575
|
command: "lint --entityType=test",
|
|
492
576
|
description: "lint only tests",
|