@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.
Files changed (79) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/coverage/clover.xml +684 -3
  3. package/coverage/coverage-final.json +4 -0
  4. package/coverage/lcov-report/builder/allocator.ts.html +1 -1
  5. package/coverage/lcov-report/builder/buildScopedConditions.ts.html +1 -1
  6. package/coverage/lcov-report/builder/buildScopedDatafile.ts.html +1 -1
  7. package/coverage/lcov-report/builder/buildScopedSegments.ts.html +1 -1
  8. package/coverage/lcov-report/builder/index.html +1 -1
  9. package/coverage/lcov-report/builder/revision.ts.html +1 -1
  10. package/coverage/lcov-report/builder/traffic.ts.html +1 -1
  11. package/coverage/lcov-report/index.html +25 -10
  12. package/coverage/lcov-report/linter/conditionSchema.ts.html +775 -0
  13. package/coverage/lcov-report/linter/featureSchema.ts.html +4924 -0
  14. package/coverage/lcov-report/linter/index.html +161 -0
  15. package/coverage/lcov-report/linter/schema.ts.html +1471 -0
  16. package/coverage/lcov-report/linter/segmentSchema.ts.html +130 -0
  17. package/coverage/lcov-report/list/index.html +1 -1
  18. package/coverage/lcov-report/list/matrix.ts.html +1 -1
  19. package/coverage/lcov-report/parsers/index.html +1 -1
  20. package/coverage/lcov-report/parsers/json.ts.html +1 -1
  21. package/coverage/lcov-report/parsers/yml.ts.html +1 -1
  22. package/coverage/lcov-report/tester/helpers.ts.html +1 -1
  23. package/coverage/lcov-report/tester/index.html +1 -1
  24. package/coverage/lcov.info +1471 -0
  25. package/lib/builder/buildDatafile.js +15 -1
  26. package/lib/builder/buildDatafile.js.map +1 -1
  27. package/lib/config/projectConfig.d.ts +2 -0
  28. package/lib/config/projectConfig.js +3 -1
  29. package/lib/config/projectConfig.js.map +1 -1
  30. package/lib/datasource/datasource.d.ts +6 -1
  31. package/lib/datasource/datasource.js +16 -0
  32. package/lib/datasource/datasource.js.map +1 -1
  33. package/lib/datasource/filesystemAdapter.js +10 -0
  34. package/lib/datasource/filesystemAdapter.js.map +1 -1
  35. package/lib/generate-code/typescript.js +283 -49
  36. package/lib/generate-code/typescript.js.map +1 -1
  37. package/lib/linter/conditionSchema.spec.d.ts +1 -0
  38. package/lib/linter/conditionSchema.spec.js +331 -0
  39. package/lib/linter/conditionSchema.spec.js.map +1 -0
  40. package/lib/linter/featureSchema.d.ts +153 -17
  41. package/lib/linter/featureSchema.js +536 -49
  42. package/lib/linter/featureSchema.js.map +1 -1
  43. package/lib/linter/featureSchema.spec.d.ts +1 -0
  44. package/lib/linter/featureSchema.spec.js +978 -0
  45. package/lib/linter/featureSchema.spec.js.map +1 -0
  46. package/lib/linter/lintProject.js +67 -1
  47. package/lib/linter/lintProject.js.map +1 -1
  48. package/lib/linter/schema.d.ts +42 -0
  49. package/lib/linter/schema.js +417 -0
  50. package/lib/linter/schema.js.map +1 -0
  51. package/lib/linter/schema.spec.d.ts +1 -0
  52. package/lib/linter/schema.spec.js +483 -0
  53. package/lib/linter/schema.spec.js.map +1 -0
  54. package/lib/linter/segmentSchema.spec.d.ts +1 -0
  55. package/lib/linter/segmentSchema.spec.js +231 -0
  56. package/lib/linter/segmentSchema.spec.js.map +1 -0
  57. package/lib/tester/testFeature.js +5 -3
  58. package/lib/tester/testFeature.js.map +1 -1
  59. package/lib/utils/git.js +3 -0
  60. package/lib/utils/git.js.map +1 -1
  61. package/package.json +5 -5
  62. package/src/builder/buildDatafile.ts +17 -1
  63. package/src/config/projectConfig.ts +3 -0
  64. package/src/datasource/datasource.ts +23 -0
  65. package/src/datasource/filesystemAdapter.ts +7 -0
  66. package/src/generate-code/typescript.ts +333 -52
  67. package/src/linter/conditionSchema.spec.ts +446 -0
  68. package/src/linter/featureSchema.spec.ts +1218 -0
  69. package/src/linter/featureSchema.ts +747 -70
  70. package/src/linter/lintProject.ts +84 -0
  71. package/src/linter/schema.spec.ts +617 -0
  72. package/src/linter/schema.ts +462 -0
  73. package/src/linter/segmentSchema.spec.ts +273 -0
  74. package/src/tester/testFeature.ts +5 -3
  75. package/src/utils/git.ts +2 -0
  76. package/lib/linter/propertySchema.d.ts +0 -5
  77. package/lib/linter/propertySchema.js +0 -43
  78. package/lib/linter/propertySchema.js.map +0 -1
  79. 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",