@usefragments/core 1.10.2 → 2.0.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/dist/{chunk-MZ4SW3TP.js → chunk-3IOWHECM.js} +8 -1
- package/dist/{chunk-MZ4SW3TP.js.map → chunk-3IOWHECM.js.map} +1 -1
- package/dist/chunk-7ULGH74M.js +66 -0
- package/dist/chunk-7ULGH74M.js.map +1 -0
- package/dist/{chunk-XN3LSDPY.js → chunk-BMPYIUZE.js} +612 -344
- package/dist/chunk-BMPYIUZE.js.map +1 -0
- package/dist/{chunk-YF65VYRY.js → chunk-ML5S6QNU.js} +191 -169
- package/dist/chunk-ML5S6QNU.js.map +1 -0
- package/dist/{chunk-3LLRNCPX.js → chunk-MZ2FS7U4.js} +1 -1
- package/dist/chunk-MZ2FS7U4.js.map +1 -0
- package/dist/chunk-PWIJMOI4.js +202 -0
- package/dist/chunk-PWIJMOI4.js.map +1 -0
- package/dist/chunk-RYFULE43.js +578 -0
- package/dist/chunk-RYFULE43.js.map +1 -0
- package/dist/codes/index.d.ts +2 -2
- package/dist/codes/index.js +3 -2
- package/dist/compiled-types/index.d.ts +327 -2
- package/dist/compiled-types/index.js +1 -1
- package/dist/generate/index.d.ts +3 -2
- package/dist/{governance-CLk_wkP9.d.ts → governance-hOPXGbbs.d.ts} +474 -515
- package/dist/governance-telemetry.d.ts +6 -0
- package/dist/governance-telemetry.js +1 -1
- package/dist/{index-_sxhUNqx.d.ts → index-C8bcXVav.d.ts} +448 -448
- package/dist/index.d.ts +3280 -1305
- package/dist/index.js +2414 -350
- package/dist/index.js.map +1 -1
- package/dist/manifest.d.ts +228 -0
- package/dist/manifest.js +24 -0
- package/dist/manifest.js.map +1 -0
- package/dist/preview/index.js +45 -1
- package/dist/preview/index.js.map +1 -1
- package/dist/preview-runtime.d.ts +1 -2
- package/dist/preview-runtime.js +150 -14
- package/dist/preview-runtime.js.map +1 -1
- package/dist/react-types.d.ts +1 -2
- package/dist/registry.d.ts +1412 -203
- package/dist/registry.js +30 -3
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/index.js +3 -2
- package/dist/storyAdapter.d.ts +1 -2
- package/dist/storyAdapter.js +11 -49
- package/dist/storyAdapter.js.map +1 -1
- package/dist/test-utils.d.ts +3 -2
- package/dist/topology/index.d.ts +1 -1
- package/dist/topology/index.js +1 -1
- package/package.json +8 -2
- package/src/__tests__/contract-parser.test.ts +318 -277
- package/src/__tests__/preview-runtime-hook.test.tsx +315 -0
- package/src/__tests__/preview-runtime.test.tsx +30 -8
- package/src/__tests__/schema.test.ts +191 -14
- package/src/analysis-plan/analysis-plan-v1.test.ts +320 -0
- package/src/analysis-plan/coverage.ts +181 -0
- package/src/analysis-plan/digest.ts +141 -0
- package/src/analysis-plan/index.ts +34 -0
- package/src/analysis-plan/types.ts +207 -0
- package/src/approved-contract-tokens.test.ts +39 -0
- package/src/approved-contract-tokens.ts +18 -0
- package/src/codes/__tests__/codes.test.ts +13 -0
- package/src/codes/codes.ts +40 -0
- package/src/compiled-types/index.ts +640 -39
- package/src/compiled-types/parse.test.ts +145 -4
- package/src/component-contract.ts +95 -53
- package/src/composition.ts +7 -13
- package/src/constants.ts +3 -6
- package/src/contract/hash.test.ts +20 -0
- package/src/contract/hash.ts +66 -9
- package/src/contract/index.ts +24 -1
- package/src/contract/manifest.test.ts +94 -0
- package/src/contract/manifest.ts +68 -0
- package/src/contract/preimage.test.ts +219 -1
- package/src/contract/preimage.ts +326 -6
- package/src/contract/stamp.test.ts +3 -0
- package/src/contract/stamp.ts +1 -1
- package/src/contract-parser.ts +54 -30
- package/src/defineFragment.test.ts +476 -91
- package/src/defineFragment.ts +204 -114
- package/src/domain-ids.test.ts +35 -0
- package/src/domain-ids.ts +61 -0
- package/src/evaluation/evaluate.test.ts +522 -0
- package/src/evaluation/evaluate.ts +690 -0
- package/src/evaluation/evaluation-v2-receipt-v1.test.ts +772 -0
- package/src/evaluation/index.ts +58 -0
- package/src/evaluation/receipt.ts +753 -0
- package/src/evaluation/types.ts +406 -0
- package/src/facts/builders.ts +2 -0
- package/src/facts/compile.ts +29 -6
- package/src/facts/fact-index.ts +13 -3
- package/src/facts/fact-integrity-v1.test.ts +172 -0
- package/src/facts/facts.test.ts +15 -0
- package/src/facts/ids.ts +46 -3
- package/src/facts/index.ts +14 -1
- package/src/facts/integrity.ts +134 -0
- package/src/facts/types.ts +36 -0
- package/src/governance-integrity.test.ts +1 -0
- package/src/governance-integrity.ts +5 -3
- package/src/governance-telemetry.ts +8 -0
- package/src/governance.ts +70 -8
- package/src/index.ts +230 -37
- package/src/preview/validation.test.ts +62 -0
- package/src/preview/validation.ts +48 -2
- package/src/preview-runtime.tsx +227 -20
- package/src/registry-install-plan.ts +200 -109
- package/src/registry-shards.test.ts +263 -0
- package/src/registry.ts +237 -0
- package/src/repository-binding.test.ts +50 -0
- package/src/repository-binding.ts +96 -0
- package/src/rules/families.test.ts +36 -0
- package/src/rules/finding.ts +7 -2
- package/src/rules/index.ts +17 -1
- package/src/rules/rule-config.test.ts +66 -0
- package/src/rules/rule-config.ts +73 -0
- package/src/rules/rules.test.ts +26 -0
- package/src/rules/tokens-css-vars-must-be-defined.test.ts +51 -2
- package/src/rules/tokens-css-vars-must-be-defined.ts +34 -1
- package/src/schema.ts +293 -113
- package/src/schemas/index.ts +1 -1
- package/src/storyAdapter.test.ts +68 -12
- package/src/storyAdapter.ts +44 -75
- package/src/topology/resolve-area.ts +1 -1
- package/src/types.ts +258 -40
- package/dist/chunk-3LLRNCPX.js.map +0 -1
- package/dist/chunk-RANPUC6C.js +0 -72
- package/dist/chunk-RANPUC6C.js.map +0 -1
- package/dist/chunk-XN3LSDPY.js.map +0 -1
- package/dist/chunk-YF65VYRY.js.map +0 -1
- package/src/fragment-types.ts +0 -214
- package/src/react-create-element.test.ts +0 -22
- package/src/react-create-element.ts +0 -12
- package/src/storyFilters.test.ts +0 -350
- package/src/storyFilters.ts +0 -253
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
// src/compiled-types/index.ts
|
|
2
|
+
var CompiledFragmentsFileValidationError = class extends Error {
|
|
3
|
+
source;
|
|
4
|
+
issues;
|
|
5
|
+
constructor(source, issues) {
|
|
6
|
+
const orderedIssues = [...issues].sort(compareStrings);
|
|
7
|
+
super(`Invalid compiled Fragments catalog at ${source}: ${orderedIssues.join("; ")}`);
|
|
8
|
+
this.name = "CompiledFragmentsFileValidationError";
|
|
9
|
+
this.source = source;
|
|
10
|
+
this.issues = orderedIssues;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function parseCompiledFragmentsFile(input, source = "fragments.json") {
|
|
14
|
+
let value = input;
|
|
15
|
+
if (typeof input === "string") {
|
|
16
|
+
try {
|
|
17
|
+
value = JSON.parse(input);
|
|
18
|
+
} catch {
|
|
19
|
+
throw new CompiledFragmentsFileValidationError(source, ["invalid JSON"]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const issues = [];
|
|
23
|
+
if (!isRecord(value)) {
|
|
24
|
+
throw new CompiledFragmentsFileValidationError(source, ["root must be an object"]);
|
|
25
|
+
}
|
|
26
|
+
if (typeof value.version !== "string" || value.version.length === 0) {
|
|
27
|
+
issues.push("version must be a non-empty string");
|
|
28
|
+
}
|
|
29
|
+
if (typeof value.generatedAt !== "string" || value.generatedAt.length === 0) {
|
|
30
|
+
issues.push("generatedAt must be a non-empty string");
|
|
31
|
+
}
|
|
32
|
+
if (!isRecord(value.fragments)) {
|
|
33
|
+
issues.push("fragments must be an object");
|
|
34
|
+
} else {
|
|
35
|
+
const names = /* @__PURE__ */ new Map();
|
|
36
|
+
for (const [key, fragment] of sortedEntries(value.fragments)) {
|
|
37
|
+
validateCompiledFragment(key, fragment, issues);
|
|
38
|
+
if (!isRecord(fragment) || !isRecord(fragment.meta) || typeof fragment.meta.name !== "string") {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const previousKey = names.get(fragment.meta.name);
|
|
42
|
+
if (previousKey !== void 0) {
|
|
43
|
+
issues.push(
|
|
44
|
+
`fragments.${key}.meta.name duplicates fragments.${previousKey}.meta.name (${JSON.stringify(fragment.meta.name)})`
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
names.set(fragment.meta.name, key);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
validateOptionalString(value.generatorVersion, "generatorVersion", issues);
|
|
52
|
+
validateOptionalString(value.packageName, "packageName", issues);
|
|
53
|
+
validateOptionalStringArray(value.buildInputs, "buildInputs", issues);
|
|
54
|
+
validateCompiledBlockMap(value.blocks, "blocks", issues);
|
|
55
|
+
validateCompiledBlockMap(value.recipes, "recipes", issues);
|
|
56
|
+
validateCompiledTokens(value.tokens, issues);
|
|
57
|
+
validateSerializedGraph(value.graph, issues);
|
|
58
|
+
validatePerformanceSummary(value.performanceSummary, issues);
|
|
59
|
+
if (issues.length > 0) throw new CompiledFragmentsFileValidationError(source, issues);
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function validateCompiledFragment(key, value, issues) {
|
|
63
|
+
const path = `fragments.${key}`;
|
|
64
|
+
if (!isRecord(value)) {
|
|
65
|
+
issues.push(`${path} must be an object`);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
validateString(value.filePath, `${path}.filePath`, issues);
|
|
69
|
+
validateFragmentMeta(value.meta, `${path}.meta`, issues);
|
|
70
|
+
validateFragmentUsage(value.usage, `${path}.usage`, issues);
|
|
71
|
+
if (value.guidance !== void 0) {
|
|
72
|
+
validateFragmentUsage(value.guidance, `${path}.guidance`, issues);
|
|
73
|
+
}
|
|
74
|
+
validateFragmentProps(value.props, `${path}.props`, issues);
|
|
75
|
+
validateFragmentVariants(value.variants, `${path}.variants`, issues);
|
|
76
|
+
validateOptionalRecordArray(value.governance, `${path}.governance`, issues);
|
|
77
|
+
validateRelations(value.relations, `${path}.relations`, issues);
|
|
78
|
+
validateFragmentPreview(value.preview, `${path}.preview`, issues);
|
|
79
|
+
validateFragmentMatrix(value.matrix, `${path}.matrix`, issues);
|
|
80
|
+
validateFragmentDesign(value.design, `${path}.design`, issues);
|
|
81
|
+
validateOptionalStringArray(value.tokens, `${path}.tokens`, issues);
|
|
82
|
+
validateOptionalRecord(value.ai, `${path}.ai`, issues);
|
|
83
|
+
validateOptionalString(value.framework, `${path}.framework`, issues);
|
|
84
|
+
validateOptionalStringArray(value.propsSummary, `${path}.propsSummary`, issues);
|
|
85
|
+
validateOptionalString(value.sourcePath, `${path}.sourcePath`, issues);
|
|
86
|
+
validateOptionalString(value.exportName, `${path}.exportName`, issues);
|
|
87
|
+
validateFragmentProvenance(value.provenance, `${path}.provenance`, issues);
|
|
88
|
+
validateFragmentGenerated(value._generated, `${path}._generated`, issues);
|
|
89
|
+
validateObservedUsages(value.usages, `${path}.usages`, issues);
|
|
90
|
+
validatePerformanceData(value.performance, `${path}.performance`, issues);
|
|
91
|
+
}
|
|
92
|
+
function validateFragmentMeta(value, path, issues) {
|
|
93
|
+
if (!isRecord(value)) {
|
|
94
|
+
issues.push(`${path} must be an object`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
validateString(value.name, `${path}.name`, issues);
|
|
98
|
+
validateString(value.description, `${path}.description`, issues);
|
|
99
|
+
validateString(value.category, `${path}.category`, issues);
|
|
100
|
+
validateOptionalStringArray(value.aliases, `${path}.aliases`, issues);
|
|
101
|
+
validateOptionalStringArray(value.tags, `${path}.tags`, issues);
|
|
102
|
+
if (value.status !== void 0 && !["stable", "beta", "deprecated", "experimental"].includes(String(value.status))) {
|
|
103
|
+
issues.push(`${path}.status must be stable, beta, deprecated, or experimental`);
|
|
104
|
+
}
|
|
105
|
+
validateOptionalString(value.since, `${path}.since`, issues);
|
|
106
|
+
validateOptionalString(value.figma, `${path}.figma`, issues);
|
|
107
|
+
validateOptionalRecord(value.figmaProps, `${path}.figmaProps`, issues);
|
|
108
|
+
if (value.dependencies !== void 0) {
|
|
109
|
+
if (!Array.isArray(value.dependencies)) {
|
|
110
|
+
issues.push(`${path}.dependencies must be an array`);
|
|
111
|
+
} else {
|
|
112
|
+
value.dependencies.forEach((dependency, index) => {
|
|
113
|
+
const dependencyPath = `${path}.dependencies.${index}`;
|
|
114
|
+
if (!isRecord(dependency)) {
|
|
115
|
+
issues.push(`${dependencyPath} must be an object`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
validateString(dependency.name, `${dependencyPath}.name`, issues);
|
|
119
|
+
validateString(dependency.version, `${dependencyPath}.version`, issues);
|
|
120
|
+
validateOptionalString(dependency.reason, `${dependencyPath}.reason`, issues);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function validateFragmentUsage(value, path, issues) {
|
|
126
|
+
if (!isRecord(value)) {
|
|
127
|
+
issues.push(`${path} must be an object`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
validateStringArray(value.when, `${path}.when`, issues);
|
|
131
|
+
validateStringArray(value.whenNot, `${path}.whenNot`, issues);
|
|
132
|
+
validateOptionalStringArray(value.guidelines, `${path}.guidelines`, issues);
|
|
133
|
+
validateOptionalStringArray(value.accessibility, `${path}.accessibility`, issues);
|
|
134
|
+
if (value.choose !== void 0) {
|
|
135
|
+
validateStringRecord(value.choose, `${path}.choose`, issues);
|
|
136
|
+
}
|
|
137
|
+
if (value.dont !== void 0) {
|
|
138
|
+
if (!Array.isArray(value.dont)) {
|
|
139
|
+
issues.push(`${path}.dont must be an array`);
|
|
140
|
+
} else {
|
|
141
|
+
value.dont.forEach((entry, index) => {
|
|
142
|
+
const entryPath = `${path}.dont.${index}`;
|
|
143
|
+
if (!isRecord(entry)) {
|
|
144
|
+
issues.push(`${entryPath} must be an object`);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
validateString(entry.reason, `${entryPath}.reason`, issues);
|
|
148
|
+
validateString(entry.bad, `${entryPath}.bad`, issues);
|
|
149
|
+
validateString(entry.good, `${entryPath}.good`, issues);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function validateFragmentProps(value, path, issues) {
|
|
155
|
+
if (!isRecord(value)) {
|
|
156
|
+
issues.push(`${path} must be an object`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
for (const [name, prop] of sortedEntries(value)) {
|
|
160
|
+
const propPath = `${path}.${name}`;
|
|
161
|
+
if (!isRecord(prop)) {
|
|
162
|
+
issues.push(`${propPath} must be an object`);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
validateString(prop.type, `${propPath}.type`, issues);
|
|
166
|
+
validateString(prop.description, `${propPath}.description`, issues);
|
|
167
|
+
validateOptionalStringArray(prop.values, `${propPath}.values`, issues);
|
|
168
|
+
validateOptionalBoolean(prop.required, `${propPath}.required`, issues);
|
|
169
|
+
validateOptionalStringArray(prop.constraints, `${propPath}.constraints`, issues);
|
|
170
|
+
validateOptionalRecord(prop.typeDetails, `${propPath}.typeDetails`, issues);
|
|
171
|
+
validateOptionalString(prop.controlType, `${propPath}.controlType`, issues);
|
|
172
|
+
validateOptionalRecord(prop.controlOptions, `${propPath}.controlOptions`, issues);
|
|
173
|
+
if (prop.visibility !== void 0 && prop.visibility !== "public" && prop.visibility !== "internal" && prop.visibility !== "hidden") {
|
|
174
|
+
issues.push(`${propPath}.visibility must be public, internal, or hidden`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function validateFragmentVariants(value, path, issues) {
|
|
179
|
+
if (!Array.isArray(value)) {
|
|
180
|
+
issues.push(`${path} must be an array`);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const names = /* @__PURE__ */ new Set();
|
|
184
|
+
value.forEach((variant, index) => {
|
|
185
|
+
const variantPath = `${path}.${index}`;
|
|
186
|
+
if (!isRecord(variant)) {
|
|
187
|
+
issues.push(`${variantPath} must be an object`);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
validateString(variant.name, `${variantPath}.name`, issues);
|
|
191
|
+
validateString(variant.description, `${variantPath}.description`, issues);
|
|
192
|
+
validateOptionalString(variant.code, `${variantPath}.code`, issues);
|
|
193
|
+
validateOptionalString(variant.figma, `${variantPath}.figma`, issues);
|
|
194
|
+
validateOptionalBoolean(variant.canonical, `${variantPath}.canonical`, issues);
|
|
195
|
+
validateOptionalRecord(variant.args, `${variantPath}.args`, issues);
|
|
196
|
+
if (typeof variant.name === "string") {
|
|
197
|
+
if (names.has(variant.name)) {
|
|
198
|
+
issues.push(
|
|
199
|
+
`${variantPath}.name duplicates an earlier variant (${JSON.stringify(variant.name)})`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
names.add(variant.name);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function validateRelations(value, path, issues) {
|
|
207
|
+
if (value === void 0) return;
|
|
208
|
+
if (!Array.isArray(value)) {
|
|
209
|
+
issues.push(`${path} must be an array`);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
value.forEach((relation, index) => {
|
|
213
|
+
const relationPath = `${path}.${index}`;
|
|
214
|
+
if (!isRecord(relation)) {
|
|
215
|
+
issues.push(`${relationPath} must be an object`);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
validateString(relation.component, `${relationPath}.component`, issues);
|
|
219
|
+
validateString(relation.relationship, `${relationPath}.relationship`, issues);
|
|
220
|
+
validateString(relation.note, `${relationPath}.note`, issues);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function validateFragmentPreview(value, path, issues) {
|
|
224
|
+
if (value === void 0) return;
|
|
225
|
+
if (!isRecord(value)) {
|
|
226
|
+
issues.push(`${path} must be an object`);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
validateOptionalString(value.setupModule, `${path}.setupModule`, issues);
|
|
230
|
+
validateOptionalString(value.wrapperModule, `${path}.wrapperModule`, issues);
|
|
231
|
+
validateOptionalString(value.wrapperExport, `${path}.wrapperExport`, issues);
|
|
232
|
+
validateOptionalStringArray(value.css, `${path}.css`, issues);
|
|
233
|
+
validateOptionalStringArray(value.dynamicRegions, `${path}.dynamicRegions`, issues);
|
|
234
|
+
if (value.providers !== void 0 && !Array.isArray(value.providers)) {
|
|
235
|
+
issues.push(`${path}.providers must be an array`);
|
|
236
|
+
}
|
|
237
|
+
if (value.theme !== void 0 && value.theme !== "light" && value.theme !== "dark") {
|
|
238
|
+
issues.push(`${path}.theme must be light or dark`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function validateFragmentMatrix(value, path, issues) {
|
|
242
|
+
if (value === void 0) return;
|
|
243
|
+
if (!isRecord(value)) {
|
|
244
|
+
issues.push(`${path} must be an object`);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (value.axes !== void 0) {
|
|
248
|
+
if (!isRecord(value.axes)) {
|
|
249
|
+
issues.push(`${path}.axes must be an object`);
|
|
250
|
+
} else {
|
|
251
|
+
for (const [axis, values] of sortedEntries(value.axes)) {
|
|
252
|
+
if (values !== "auto" && !isStringArray(values)) {
|
|
253
|
+
issues.push(`${path}.axes.${axis} must be auto or an array of strings`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
validateOptionalStringArray(value.forced, `${path}.forced`, issues);
|
|
259
|
+
validateOptionalRecord(value.worstCase, `${path}.worstCase`, issues);
|
|
260
|
+
}
|
|
261
|
+
function validateFragmentDesign(value, path, issues) {
|
|
262
|
+
if (value === void 0) return;
|
|
263
|
+
if (!isRecord(value)) {
|
|
264
|
+
issues.push(`${path} must be an object`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
validateOptionalString(value.figmaNode, `${path}.figmaNode`, issues);
|
|
268
|
+
}
|
|
269
|
+
function validateFragmentProvenance(value, path, issues) {
|
|
270
|
+
if (value === void 0) return;
|
|
271
|
+
if (!isRecord(value)) {
|
|
272
|
+
issues.push(`${path} must be an object`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
validateString(value.source, `${path}.source`, issues);
|
|
276
|
+
validateBoolean(value.verified, `${path}.verified`, issues);
|
|
277
|
+
validateOptionalString(value.frameworkSupport, `${path}.frameworkSupport`, issues);
|
|
278
|
+
validateOptionalString(value.sourceHash, `${path}.sourceHash`, issues);
|
|
279
|
+
validateOptionalString(value.extractedAt, `${path}.extractedAt`, issues);
|
|
280
|
+
}
|
|
281
|
+
function validateFragmentGenerated(value, path, issues) {
|
|
282
|
+
if (value === void 0) return;
|
|
283
|
+
if (!isRecord(value)) {
|
|
284
|
+
issues.push(`${path} must be an object`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const sources = ["storybook", "manual", "ai", "scan", "extracted", "merged", "migrated"];
|
|
288
|
+
if (typeof value.source !== "string" || !sources.includes(value.source)) {
|
|
289
|
+
issues.push(`${path}.source must be a supported provenance source`);
|
|
290
|
+
}
|
|
291
|
+
validateOptionalString(value.sourceFile, `${path}.sourceFile`, issues);
|
|
292
|
+
validateOptionalNumber(value.confidence, `${path}.confidence`, issues);
|
|
293
|
+
validateOptionalBoolean(value.verified, `${path}.verified`, issues);
|
|
294
|
+
validateOptionalString(value.timestamp, `${path}.timestamp`, issues);
|
|
295
|
+
}
|
|
296
|
+
function validateObservedUsages(value, path, issues) {
|
|
297
|
+
if (value === void 0) return;
|
|
298
|
+
if (!Array.isArray(value)) {
|
|
299
|
+
issues.push(`${path} must be an array`);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
value.forEach((usage, index) => {
|
|
303
|
+
const usagePath = `${path}.${index}`;
|
|
304
|
+
if (!isRecord(usage)) {
|
|
305
|
+
issues.push(`${usagePath} must be an object`);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
validateString(usage.file, `${usagePath}.file`, issues);
|
|
309
|
+
validateNumber(usage.line, `${usagePath}.line`, issues);
|
|
310
|
+
validateNumber(usage.column, `${usagePath}.column`, issues);
|
|
311
|
+
validateOptionalString(usage.parentElement, `${usagePath}.parentElement`, issues);
|
|
312
|
+
validateOptionalBoolean(usage.conditional, `${usagePath}.conditional`, issues);
|
|
313
|
+
if (!Array.isArray(usage.props)) {
|
|
314
|
+
issues.push(`${usagePath}.props must be an array`);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
usage.props.forEach((prop, propIndex) => {
|
|
318
|
+
const propPath = `${usagePath}.props.${propIndex}`;
|
|
319
|
+
if (!isRecord(prop)) {
|
|
320
|
+
issues.push(`${propPath} must be an object`);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
validateString(prop.name, `${propPath}.name`, issues);
|
|
324
|
+
if (typeof prop.kind !== "string" || !["static", "dynamic", "spread", "jsx", "boolean", "null"].includes(prop.kind)) {
|
|
325
|
+
issues.push(`${propPath}.kind must be a supported observation kind`);
|
|
326
|
+
}
|
|
327
|
+
if (prop.value !== void 0 && prop.value !== null && typeof prop.value !== "string" && typeof prop.value !== "number" && typeof prop.value !== "boolean") {
|
|
328
|
+
issues.push(`${propPath}.value must be a JSON scalar`);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function validatePerformanceData(value, path, issues) {
|
|
334
|
+
if (value === void 0) return;
|
|
335
|
+
if (!isRecord(value)) {
|
|
336
|
+
issues.push(`${path} must be an object`);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
validateNumber(value.bundleSize, `${path}.bundleSize`, issues);
|
|
340
|
+
validateNumber(value.rawSize, `${path}.rawSize`, issues);
|
|
341
|
+
validateString(value.complexity, `${path}.complexity`, issues);
|
|
342
|
+
validateNumber(value.budgetPercent, `${path}.budgetPercent`, issues);
|
|
343
|
+
validateBoolean(value.overBudget, `${path}.overBudget`, issues);
|
|
344
|
+
validateString(value.measuredAt, `${path}.measuredAt`, issues);
|
|
345
|
+
if (value.imports !== void 0) {
|
|
346
|
+
if (!Array.isArray(value.imports)) {
|
|
347
|
+
issues.push(`${path}.imports must be an array`);
|
|
348
|
+
} else {
|
|
349
|
+
value.imports.forEach((entry, index) => {
|
|
350
|
+
const entryPath = `${path}.imports.${index}`;
|
|
351
|
+
if (!isRecord(entry)) {
|
|
352
|
+
issues.push(`${entryPath} must be an object`);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
validateString(entry.path, `${entryPath}.path`, issues);
|
|
356
|
+
validateNumber(entry.bytes, `${entryPath}.bytes`, issues);
|
|
357
|
+
validateNumber(entry.percent, `${entryPath}.percent`, issues);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function validateCompiledBlockMap(value, path, issues) {
|
|
363
|
+
if (value === void 0) return;
|
|
364
|
+
if (!isRecord(value)) {
|
|
365
|
+
issues.push(`${path} must be an object`);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const names = /* @__PURE__ */ new Set();
|
|
369
|
+
for (const [key, block] of sortedEntries(value)) {
|
|
370
|
+
const blockPath = `${path}.${key}`;
|
|
371
|
+
if (!isRecord(block)) {
|
|
372
|
+
issues.push(`${blockPath} must be an object`);
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
validateString(block.filePath, `${blockPath}.filePath`, issues);
|
|
376
|
+
validateString(block.name, `${blockPath}.name`, issues);
|
|
377
|
+
validateString(block.description, `${blockPath}.description`, issues);
|
|
378
|
+
validateString(block.category, `${blockPath}.category`, issues);
|
|
379
|
+
validateStringArray(block.components, `${blockPath}.components`, issues);
|
|
380
|
+
validateString(block.code, `${blockPath}.code`, issues);
|
|
381
|
+
validateOptionalStringArray(block.tags, `${blockPath}.tags`, issues);
|
|
382
|
+
if (typeof block.name === "string") {
|
|
383
|
+
if (names.has(block.name)) {
|
|
384
|
+
issues.push(
|
|
385
|
+
`${blockPath}.name duplicates an earlier block (${JSON.stringify(block.name)})`
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
names.add(block.name);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function validateCompiledTokens(value, issues) {
|
|
393
|
+
if (value === void 0) return;
|
|
394
|
+
if (!isRecord(value)) {
|
|
395
|
+
issues.push("tokens must be an object");
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
validateString(value.prefix, "tokens.prefix", issues);
|
|
399
|
+
validateNumber(value.total, "tokens.total", issues);
|
|
400
|
+
if (!isRecord(value.categories)) {
|
|
401
|
+
issues.push("tokens.categories must be an object");
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
for (const [category, entries] of sortedEntries(value.categories)) {
|
|
405
|
+
const categoryPath = `tokens.categories.${category}`;
|
|
406
|
+
if (!Array.isArray(entries)) {
|
|
407
|
+
issues.push(`${categoryPath} must be an array`);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
entries.forEach((entry, index) => {
|
|
411
|
+
const entryPath = `${categoryPath}.${index}`;
|
|
412
|
+
if (!isRecord(entry)) {
|
|
413
|
+
issues.push(`${entryPath} must be an object`);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
validateString(entry.name, `${entryPath}.name`, issues);
|
|
417
|
+
validateOptionalString(entry.value, `${entryPath}.value`, issues);
|
|
418
|
+
validateOptionalString(entry.description, `${entryPath}.description`, issues);
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function validateSerializedGraph(value, issues) {
|
|
423
|
+
if (value === void 0) return;
|
|
424
|
+
if (!isRecord(value)) {
|
|
425
|
+
issues.push("graph must be an object");
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (!Array.isArray(value.nodes)) {
|
|
429
|
+
issues.push("graph.nodes must be an array");
|
|
430
|
+
} else {
|
|
431
|
+
const nodeNames = /* @__PURE__ */ new Set();
|
|
432
|
+
value.nodes.forEach((node, index) => {
|
|
433
|
+
const nodePath = `graph.nodes.${index}`;
|
|
434
|
+
if (!isRecord(node)) {
|
|
435
|
+
issues.push(`${nodePath} must be an object`);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
validateString(node.name, `${nodePath}.name`, issues);
|
|
439
|
+
validateString(node.category, `${nodePath}.category`, issues);
|
|
440
|
+
validateString(node.status, `${nodePath}.status`, issues);
|
|
441
|
+
validateOptionalStringArray(node.subComponents, `${nodePath}.subComponents`, issues);
|
|
442
|
+
if (typeof node.name === "string") {
|
|
443
|
+
if (nodeNames.has(node.name)) {
|
|
444
|
+
issues.push(
|
|
445
|
+
`${nodePath}.name duplicates an earlier graph node (${JSON.stringify(node.name)})`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
nodeNames.add(node.name);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
if (!Array.isArray(value.edges)) {
|
|
453
|
+
issues.push("graph.edges must be an array");
|
|
454
|
+
} else {
|
|
455
|
+
value.edges.forEach((edge, index) => {
|
|
456
|
+
const edgePath = `graph.edges.${index}`;
|
|
457
|
+
if (!isRecord(edge)) {
|
|
458
|
+
issues.push(`${edgePath} must be an object`);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
validateString(edge.s, `${edgePath}.s`, issues);
|
|
462
|
+
validateString(edge.t, `${edgePath}.t`, issues);
|
|
463
|
+
validateString(edge.ty, `${edgePath}.ty`, issues);
|
|
464
|
+
validateNumber(edge.w, `${edgePath}.w`, issues);
|
|
465
|
+
validateOptionalString(edge.no, `${edgePath}.no`, issues);
|
|
466
|
+
validateString(edge.p, `${edgePath}.p`, issues);
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (!isRecord(value.health)) {
|
|
470
|
+
issues.push("graph.health must be an object");
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
validateStringArray(value.health.orphans, "graph.health.orphans", issues);
|
|
474
|
+
validateNumber(value.health.compositionCoverage, "graph.health.compositionCoverage", issues);
|
|
475
|
+
validateNumber(value.health.averageDegree, "graph.health.averageDegree", issues);
|
|
476
|
+
validateNumber(value.health.nodeCount, "graph.health.nodeCount", issues);
|
|
477
|
+
validateNumber(value.health.edgeCount, "graph.health.edgeCount", issues);
|
|
478
|
+
if (!Array.isArray(value.health.connectedComponents)) {
|
|
479
|
+
issues.push("graph.health.connectedComponents must be an array");
|
|
480
|
+
} else {
|
|
481
|
+
value.health.connectedComponents.forEach(
|
|
482
|
+
(component, index) => validateStringArray(component, `graph.health.connectedComponents.${index}`, issues)
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
if (!Array.isArray(value.health.hubs)) {
|
|
486
|
+
issues.push("graph.health.hubs must be an array");
|
|
487
|
+
} else {
|
|
488
|
+
value.health.hubs.forEach((hub, index) => {
|
|
489
|
+
const hubPath = `graph.health.hubs.${index}`;
|
|
490
|
+
if (!isRecord(hub)) {
|
|
491
|
+
issues.push(`${hubPath} must be an object`);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
validateString(hub.name, `${hubPath}.name`, issues);
|
|
495
|
+
validateNumber(hub.degree, `${hubPath}.degree`, issues);
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function validatePerformanceSummary(value, issues) {
|
|
500
|
+
if (value === void 0) return;
|
|
501
|
+
if (!isRecord(value)) {
|
|
502
|
+
issues.push("performanceSummary must be an object");
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
validateString(value.preset, "performanceSummary.preset", issues);
|
|
506
|
+
validateNumber(value.budget, "performanceSummary.budget", issues);
|
|
507
|
+
validateNumber(value.total, "performanceSummary.total", issues);
|
|
508
|
+
validateNumber(value.overBudget, "performanceSummary.overBudget", issues);
|
|
509
|
+
if (!isRecord(value.tiers)) {
|
|
510
|
+
issues.push("performanceSummary.tiers must be an object");
|
|
511
|
+
} else {
|
|
512
|
+
for (const [tier, count] of sortedEntries(value.tiers)) {
|
|
513
|
+
validateNumber(count, `performanceSummary.tiers.${tier}`, issues);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function validateString(value, path, issues) {
|
|
518
|
+
if (typeof value !== "string") issues.push(`${path} must be a string`);
|
|
519
|
+
}
|
|
520
|
+
function validateOptionalString(value, path, issues) {
|
|
521
|
+
if (value !== void 0) validateString(value, path, issues);
|
|
522
|
+
}
|
|
523
|
+
function validateNumber(value, path, issues) {
|
|
524
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
525
|
+
issues.push(`${path} must be a finite number`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function validateOptionalNumber(value, path, issues) {
|
|
529
|
+
if (value !== void 0) validateNumber(value, path, issues);
|
|
530
|
+
}
|
|
531
|
+
function validateBoolean(value, path, issues) {
|
|
532
|
+
if (typeof value !== "boolean") issues.push(`${path} must be a boolean`);
|
|
533
|
+
}
|
|
534
|
+
function validateOptionalBoolean(value, path, issues) {
|
|
535
|
+
if (value !== void 0) validateBoolean(value, path, issues);
|
|
536
|
+
}
|
|
537
|
+
function validateStringArray(value, path, issues) {
|
|
538
|
+
if (!isStringArray(value)) issues.push(`${path} must be an array of strings`);
|
|
539
|
+
}
|
|
540
|
+
function validateOptionalStringArray(value, path, issues) {
|
|
541
|
+
if (value !== void 0) validateStringArray(value, path, issues);
|
|
542
|
+
}
|
|
543
|
+
function validateStringRecord(value, path, issues) {
|
|
544
|
+
if (!isRecord(value)) {
|
|
545
|
+
issues.push(`${path} must be an object of strings`);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
for (const [key, entry] of sortedEntries(value)) {
|
|
549
|
+
validateString(entry, `${path}.${key}`, issues);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function validateOptionalRecord(value, path, issues) {
|
|
553
|
+
if (value !== void 0 && !isRecord(value)) issues.push(`${path} must be an object`);
|
|
554
|
+
}
|
|
555
|
+
function validateOptionalRecordArray(value, path, issues) {
|
|
556
|
+
if (value === void 0) return;
|
|
557
|
+
if (!Array.isArray(value) || value.some((entry) => !isRecord(entry))) {
|
|
558
|
+
issues.push(`${path} must be an array of objects`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function isStringArray(value) {
|
|
562
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
563
|
+
}
|
|
564
|
+
function sortedEntries(value) {
|
|
565
|
+
return Object.entries(value).sort(([left], [right]) => compareStrings(left, right));
|
|
566
|
+
}
|
|
567
|
+
function compareStrings(left, right) {
|
|
568
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
569
|
+
}
|
|
570
|
+
function isRecord(value) {
|
|
571
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export {
|
|
575
|
+
CompiledFragmentsFileValidationError,
|
|
576
|
+
parseCompiledFragmentsFile
|
|
577
|
+
};
|
|
578
|
+
//# sourceMappingURL=chunk-RYFULE43.js.map
|