@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/info/index.ts DELETED
@@ -1,129 +0,0 @@
1
- import { Dependencies } from "../dependencies";
2
- import { getMatrixCombinations } from "../list/matrix";
3
- import { Plugin } from "../cli";
4
- import { getProjectSetExecutions, printSetHeader } from "../sets";
5
- import { CLI_COLOR_CYAN, CLI_FORMAT_BOLD, colorize } from "../tester/cliFormat";
6
- import { buildRuntimeDatafiles } from "../builder/buildRuntimeDatafiles";
7
-
8
- async function showTargetInfo(deps: Dependencies, target: string | string[]) {
9
- const { projectConfig } = deps;
10
- const environments = Array.isArray(projectConfig.environments)
11
- ? projectConfig.environments
12
- : [false as const];
13
-
14
- for (const environment of environments) {
15
- const datafiles = await buildRuntimeDatafiles(deps, {
16
- environment,
17
- target,
18
- revision: "info",
19
- });
20
-
21
- for (const entry of datafiles) {
22
- const variables = Object.values(entry.datafile.features).reduce((count, feature) => {
23
- const schemas = feature.variablesSchema;
24
- return (
25
- count + (Array.isArray(schemas) ? schemas.length : Object.keys(schemas || {}).length)
26
- );
27
- }, 0);
28
-
29
- console.log("");
30
- console.log(CLI_FORMAT_BOLD, `Target "${entry.target}"`);
31
- console.log(` ${colorize("Environment", CLI_COLOR_CYAN)}: ${environment}`);
32
- console.log(
33
- ` ${colorize("Features", CLI_COLOR_CYAN)}: ${Object.keys(entry.datafile.features).length}`,
34
- );
35
- console.log(
36
- ` ${colorize("Segments", CLI_COLOR_CYAN)}: ${Object.keys(entry.datafile.segments).length}`,
37
- );
38
- console.log(` ${colorize("Variables", CLI_COLOR_CYAN)}: ${variables}`);
39
- console.log(
40
- ` ${colorize("Datafile size", CLI_COLOR_CYAN)}: ${(JSON.stringify(entry.datafile).length / 1024).toFixed(2)} kB`,
41
- );
42
- }
43
- }
44
- }
45
-
46
- export async function showProjectInfo(deps: Dependencies) {
47
- const { datasource, options } = deps;
48
-
49
- if (options.target) {
50
- await showTargetInfo(deps, options.target);
51
- return;
52
- }
53
-
54
- console.log("");
55
- console.log(CLI_FORMAT_BOLD, "Project info");
56
- console.log("");
57
-
58
- const revision = await datasource.readRevision();
59
- console.log(` ${colorize("Revision", CLI_COLOR_CYAN)}: ${revision}`);
60
-
61
- console.log("");
62
-
63
- const attributes = await datasource.listAttributes();
64
- const segments = await datasource.listSegments();
65
- const features = await datasource.listFeatures();
66
- const groups = await datasource.listGroups();
67
- const targets = await datasource.listTargets();
68
-
69
- let variablesCount = 0;
70
- for (const featureKey of features) {
71
- const feature = await datasource.readFeature(featureKey);
72
-
73
- if (feature.variablesSchema) {
74
- variablesCount += Object.keys(feature.variablesSchema).length;
75
- }
76
- }
77
-
78
- console.log(` ${colorize("Total attributes", CLI_COLOR_CYAN)}: ${attributes.length}`);
79
- console.log(` ${colorize("Total segments", CLI_COLOR_CYAN)}: ${segments.length}`);
80
- console.log(` ${colorize("Total features", CLI_COLOR_CYAN)}: ${features.length}`);
81
- console.log(` ${colorize("Total variables", CLI_COLOR_CYAN)}: ${variablesCount}`);
82
- console.log(` ${colorize("Total groups", CLI_COLOR_CYAN)}: ${groups.length}`);
83
- console.log(` ${colorize("Total targets", CLI_COLOR_CYAN)}: ${targets.length}`);
84
-
85
- console.log("");
86
-
87
- const tests = await datasource.listTests();
88
- console.log(` ${colorize("Total test specs", CLI_COLOR_CYAN)}: ${tests.length}`);
89
-
90
- let assertionsCount = 0;
91
- for (const test of tests) {
92
- const testSpec = await datasource.readTest(test);
93
-
94
- for (const assertion of testSpec.assertions) {
95
- if (assertion.matrix) {
96
- const combinations = getMatrixCombinations(assertion.matrix);
97
- assertionsCount += combinations.length;
98
- } else {
99
- assertionsCount += 1;
100
- }
101
- }
102
- }
103
-
104
- console.log(` ${colorize("Total assertions", CLI_COLOR_CYAN)}: ${assertionsCount}`);
105
- }
106
-
107
- export const infoPlugin: Plugin = {
108
- command: "info",
109
- handler: async function ({ rootDirectoryPath, projectConfig, datasource, parsed }) {
110
- const executions = await getProjectSetExecutions(projectConfig, datasource, parsed.set);
111
-
112
- for (const execution of executions) {
113
- printSetHeader(projectConfig, execution.set);
114
-
115
- await showProjectInfo({
116
- rootDirectoryPath,
117
- projectConfig: execution.projectConfig,
118
- datasource: execution.datasource,
119
- options: parsed,
120
- });
121
- }
122
- },
123
- examples: [
124
- {
125
- command: "info",
126
- description: "show various stats for the project",
127
- },
128
- ],
129
- };
package/src/init/index.ts DELETED
@@ -1,65 +0,0 @@
1
- import axios from "axios";
2
- import * as tar from "tar";
3
-
4
- import { Plugin } from "../cli";
5
-
6
- export const DEFAULT_EXAMPLE = "yml";
7
-
8
- export const EXAMPLES_ORG_NAME = "featurevisor";
9
- export const EXAMPLES_REPO_NAME = "featurevisor";
10
- export const EXAMPLES_BRANCH_NAME = "main";
11
-
12
- export const EXAMPLES_TAR_URL = `https://codeload.github.com/${EXAMPLES_ORG_NAME}/${EXAMPLES_REPO_NAME}/tar.gz/${EXAMPLES_BRANCH_NAME}`;
13
-
14
- function getExamplePath(exampleName: string) {
15
- return `${EXAMPLES_REPO_NAME}-${EXAMPLES_BRANCH_NAME}/examples/example-${exampleName}/`;
16
- }
17
-
18
- export function initProject(
19
- directoryPath: string,
20
- exampleName: string = DEFAULT_EXAMPLE,
21
- ): Promise<boolean> {
22
- return new Promise(function (resolve) {
23
- axios.get(EXAMPLES_TAR_URL, { responseType: "stream" }).then((response) => {
24
- response.data
25
- .pipe(
26
- tar.x({
27
- C: directoryPath,
28
- filter: (path) => path.indexOf(getExamplePath(exampleName)) === 0,
29
- strip: 3,
30
- }),
31
- )
32
- .on("error", (e) => {
33
- console.error(e);
34
-
35
- resolve(false);
36
- })
37
- .on("finish", () => {
38
- console.log(`Project scaffolded in ${directoryPath}`);
39
- console.log(``);
40
- console.log(`Please run "npm install" in the directory above.`);
41
-
42
- resolve(true);
43
- });
44
- });
45
- });
46
- }
47
-
48
- export const initPlugin: Plugin = {
49
- command: "init",
50
- handler: async function (options) {
51
- const { rootDirectoryPath, parsed } = options;
52
-
53
- await initProject(rootDirectoryPath, parsed.example);
54
- },
55
- examples: [
56
- {
57
- command: "init",
58
- description: "scaffold a new project in current directory",
59
- },
60
- {
61
- command: "init --example=exampleName",
62
- description: "scaffold a new project in current directory from known example",
63
- },
64
- ],
65
- };
@@ -1,342 +0,0 @@
1
- import { z } from "zod";
2
-
3
- import { getAttributeZodSchema } from "./attributeSchema";
4
-
5
- function parseAttribute(input: unknown): z.ZodSafeParseResult<unknown> {
6
- return getAttributeZodSchema().safeParse(input);
7
- }
8
-
9
- function expectAttributeSuccess(input: unknown): void {
10
- const result = parseAttribute(input);
11
- expect(result.success).toBe(true);
12
- if (!result.success) {
13
- const error = (result as z.ZodSafeParseError<unknown>).error;
14
- const msg = error.issues.map((issue) => issue.message).join("; ");
15
- throw new Error(`Expected attribute to pass: ${msg}`);
16
- }
17
- }
18
-
19
- function expectAttributeFailure(input: unknown, messageSubstring?: string): z.ZodError {
20
- const result = parseAttribute(input);
21
- expect(result.success).toBe(false);
22
- if (result.success) {
23
- throw new Error("Expected attribute to fail");
24
- }
25
-
26
- const error = (result as z.ZodSafeParseError<unknown>).error;
27
-
28
- if (messageSubstring) {
29
- const messages = error.issues.map((issue) => issue.message).join(" ");
30
- expect(messages).toContain(messageSubstring);
31
- }
32
-
33
- return error;
34
- }
35
-
36
- describe("attributeSchema.ts :: getAttributeZodSchema", () => {
37
- it("accepts flat object attributes without additional schema details", () => {
38
- expectAttributeSuccess({
39
- description: "Traits",
40
- type: "object",
41
- });
42
- });
43
-
44
- it("accepts flat object properties and typed arrays", () => {
45
- expectAttributeSuccess({
46
- description: "Account",
47
- type: "object",
48
- required: ["plan"],
49
- properties: {
50
- plan: {
51
- type: "string",
52
- enum: ["free", "pro"],
53
- },
54
- locale: {
55
- type: "string",
56
- },
57
- permissions: {
58
- type: "array",
59
- items: {
60
- type: "string",
61
- enum: ["read", "write", "admin"],
62
- },
63
- },
64
- },
65
- });
66
- });
67
-
68
- it("accepts array attributes without items when they stay flat", () => {
69
- expectAttributeSuccess({
70
- description: "Tags",
71
- type: "array",
72
- });
73
- });
74
-
75
- it("accepts string-array enums on array attributes", () => {
76
- expectAttributeSuccess({
77
- description: "Permissions",
78
- type: "array",
79
- items: {
80
- type: "string",
81
- },
82
- enum: [["read"], ["write", "admin"]],
83
- });
84
- });
85
-
86
- it("accepts top-level oneOf attributes without type", () => {
87
- expectAttributeSuccess({
88
- description: "Version number of the app",
89
- oneOf: [{ type: "string" }, { type: "double" }],
90
- });
91
- });
92
-
93
- it("accepts top-level oneOf attributes with branch-specific enums", () => {
94
- expectAttributeSuccess({
95
- description: "Plan or score",
96
- oneOf: [
97
- { type: "string", enum: ["free", "pro"] },
98
- { type: "double", minimum: 0 },
99
- ],
100
- });
101
- });
102
-
103
- it("requires items when array schema adds extra constraints", () => {
104
- expectAttributeFailure(
105
- {
106
- description: "Permissions",
107
- type: "array",
108
- enum: [["read"], ["write"]],
109
- },
110
- "`items` is required",
111
- );
112
- });
113
-
114
- it("rejects attributes without top-level type or oneOf", () => {
115
- expectAttributeFailure(
116
- {
117
- description: "Country",
118
- },
119
- "either `type` or `oneOf`",
120
- );
121
- });
122
-
123
- it("rejects attributes with both top-level type and oneOf", () => {
124
- expectAttributeFailure(
125
- {
126
- description: "Version number of the app",
127
- type: "string",
128
- oneOf: [{ type: "string" }, { type: "double" }],
129
- },
130
- "cannot have both `type` and `oneOf`",
131
- );
132
- });
133
-
134
- it("rejects top-level oneOf attributes when a branch enum does not match its type", () => {
135
- expectAttributeFailure(
136
- {
137
- description: "Plan or score",
138
- oneOf: [{ type: "string", enum: ["free", 1] }, { type: "double" }],
139
- },
140
- 'does not match type "string"',
141
- );
142
- });
143
-
144
- it("rejects nested object properties inside object attributes", () => {
145
- expectAttributeFailure(
146
- {
147
- description: "Account",
148
- type: "object",
149
- properties: {
150
- metadata: {
151
- type: "object",
152
- properties: {
153
- locale: {
154
- type: "string",
155
- },
156
- },
157
- },
158
- },
159
- },
160
- "must stay flat",
161
- );
162
- });
163
-
164
- it("rejects object additionalProperties that allow nested objects", () => {
165
- expectAttributeFailure(
166
- {
167
- description: "Labels",
168
- type: "object",
169
- additionalProperties: {
170
- type: "object",
171
- properties: {
172
- locale: {
173
- type: "string",
174
- },
175
- },
176
- },
177
- },
178
- "must stay flat",
179
- );
180
- });
181
-
182
- it("rejects object properties whose oneOf allows nested objects", () => {
183
- expectAttributeFailure(
184
- {
185
- description: "Account",
186
- type: "object",
187
- properties: {
188
- metadata: {
189
- oneOf: [
190
- { type: "string" },
191
- {
192
- type: "object",
193
- properties: {
194
- locale: {
195
- type: "string",
196
- },
197
- },
198
- },
199
- ],
200
- },
201
- },
202
- },
203
- "must stay flat",
204
- );
205
- });
206
-
207
- it("rejects object additionalProperties whose oneOf allows nested objects", () => {
208
- expectAttributeFailure(
209
- {
210
- description: "Labels",
211
- type: "object",
212
- additionalProperties: {
213
- oneOf: [
214
- { type: "string" },
215
- {
216
- type: "object",
217
- properties: {
218
- locale: {
219
- type: "string",
220
- },
221
- },
222
- },
223
- ],
224
- },
225
- },
226
- "must stay flat",
227
- );
228
- });
229
-
230
- it("rejects non-string item types for array attributes", () => {
231
- expectAttributeFailure(
232
- {
233
- description: "Scores",
234
- type: "array",
235
- items: {
236
- type: "integer",
237
- },
238
- },
239
- "items.type",
240
- );
241
- });
242
-
243
- it("rejects non-string enum values for array attributes", () => {
244
- expectAttributeFailure(
245
- {
246
- description: "Scores",
247
- type: "array",
248
- enum: [[1, 2]],
249
- },
250
- "array of strings",
251
- );
252
- });
253
-
254
- it("rejects non-string const values for array attributes", () => {
255
- expectAttributeFailure(
256
- {
257
- description: "Scores",
258
- type: "array",
259
- items: {
260
- type: "string",
261
- },
262
- const: [1, 2],
263
- },
264
- "array of strings",
265
- );
266
- });
267
-
268
- it("rejects required keys that are not declared in properties", () => {
269
- expectAttributeFailure(
270
- {
271
- description: "Account",
272
- type: "object",
273
- required: ["plan", "tier"],
274
- properties: {
275
- plan: {
276
- type: "string",
277
- },
278
- },
279
- },
280
- "Unknown required field",
281
- );
282
- });
283
-
284
- it("accepts required keys on flat object attributes without declared properties", () => {
285
- expectAttributeSuccess({
286
- description: "Traits",
287
- type: "object",
288
- required: ["plan"],
289
- });
290
- });
291
-
292
- it("rejects enum values that do not match semver/date string-like types", () => {
293
- expectAttributeFailure(
294
- {
295
- description: "Browser version",
296
- type: "semver",
297
- enum: ["1.0.0", 2],
298
- },
299
- 'does not match type "semver"',
300
- );
301
- });
302
-
303
- it("rejects minimum values greater than maximum for numeric attributes", () => {
304
- expectAttributeFailure(
305
- {
306
- description: "Score",
307
- type: "double",
308
- minimum: 10,
309
- maximum: 5,
310
- },
311
- "minimum",
312
- );
313
- });
314
-
315
- it("rejects minLength values greater than maxLength for string attributes", () => {
316
- expectAttributeFailure(
317
- {
318
- description: "Country",
319
- type: "string",
320
- minLength: 5,
321
- maxLength: 2,
322
- },
323
- "minLength",
324
- );
325
- });
326
-
327
- it("rejects invalid string patterns nested under object properties", () => {
328
- expectAttributeFailure(
329
- {
330
- description: "Profile",
331
- type: "object",
332
- properties: {
333
- email: {
334
- type: "string",
335
- pattern: "[",
336
- },
337
- },
338
- },
339
- "valid ECMA-262",
340
- );
341
- });
342
- });