-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.ts
More file actions
77 lines (66 loc) · 2 KB
/
Copy pathschemas.ts
File metadata and controls
77 lines (66 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as v from 'valibot';
const CountSchema = v.pipe(v.number(), v.integer(), v.minValue(0));
const NonEmptyStringSchema = v.pipe(v.string(), v.minLength(1));
export const PackageMetadataSchema = v.object({
version: v.optional(NonEmptyStringSchema),
});
const AuditCheckNameSchema = v.picklist([
'referential-integrity',
'frontmatter',
'tags',
'duplicate-titles',
'duplicate-tags',
]);
export const SkillStatsSchema = v.object({
name: v.string(),
total: CountSchema,
capability: CountSchema,
efficiency: CountSchema,
high: CountSchema,
medium: CountSchema,
low: CountSchema,
});
export const StatsReportSchema = v.object({
generatedAt: v.string(),
totalRules: CountSchema,
skills: v.array(SkillStatsSchema),
impactDistribution: v.object({
HIGH: CountSchema,
MEDIUM: CountSchema,
LOW: CountSchema,
}),
topTags: v.array(
v.object({
tag: v.string(),
count: CountSchema,
})
),
rulesWithNoTags: v.array(v.string()),
});
export const AuditCheckSchema = v.object({
name: AuditCheckNameSchema,
passed: v.boolean(),
errors: CountSchema,
warnings: CountSchema,
});
export const AuditReportSchema = v.object({
generatedAt: v.string(),
passed: v.boolean(),
ruleCount: CountSchema,
checks: v.pipe(v.array(AuditCheckSchema), v.length(5)),
statistics: StatsReportSchema,
});
export type PackageMetadata = v.InferOutput<typeof PackageMetadataSchema>;
export type AuditCheck = v.InferOutput<typeof AuditCheckSchema>;
export type AuditReport = v.InferOutput<typeof AuditReportSchema>;
export type SkillStats = v.InferOutput<typeof SkillStatsSchema>;
export type StatsReport = v.InferOutput<typeof StatsReportSchema>;
export function parsePackageMetadata(input: unknown): PackageMetadata {
return v.parse(PackageMetadataSchema, input);
}
export function parseAuditReport(input: unknown): AuditReport {
return v.parse(AuditReportSchema, input);
}
export function parseStatsReport(input: unknown): StatsReport {
return v.parse(StatsReportSchema, input);
}