Skip to content

Commit a473c11

Browse files
committed
refactor(models): add meta.title to all named schemas
1 parent 7504d1e commit a473c11

File tree

23 files changed

+437
-282
lines changed

23 files changed

+437
-282
lines changed

packages/models/src/lib/audit-output.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export const auditDetailsSchema = z
3030
.meta({ description: 'Findings in tree structure' })
3131
.optional(),
3232
})
33-
.meta({ description: 'Detailed information' });
33+
.meta({
34+
title: 'AuditDetails',
35+
description: 'Detailed information',
36+
});
3437
export type AuditDetails = z.infer<typeof auditDetailsSchema>;
3538

3639
export const auditOutputSchema = z
@@ -42,14 +45,19 @@ export const auditOutputSchema = z
4245
scoreTarget: scoreTargetSchema,
4346
details: auditDetailsSchema.optional(),
4447
})
45-
.meta({ description: 'Audit information' });
48+
.meta({
49+
title: 'AuditOutput',
50+
description: 'Audit information',
51+
});
4652

4753
export type AuditOutput = z.infer<typeof auditOutputSchema>;
4854

4955
export const auditOutputsSchema = z
5056
.array(auditOutputSchema)
5157
.check(createDuplicateSlugsCheck('Audit'))
52-
.describe(
53-
'List of JSON formatted audit output emitted by the runner process of a plugin',
54-
);
58+
.meta({
59+
title: 'AuditOutputs',
60+
description:
61+
'List of JSON formatted audit output emitted by the runner process of a plugin',
62+
});
5563
export type AuditOutputs = z.infer<typeof auditOutputsSchema>;

packages/models/src/lib/audit.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ export const auditSchema = z
1414
description: 'List of scorable metrics for the given plugin',
1515
isSkippedDescription: 'Indicates whether the audit is skipped',
1616
}).shape,
17-
);
17+
)
18+
.meta({ title: 'Audit' });
1819

1920
export type Audit = z.infer<typeof auditSchema>;
2021
export const pluginAuditsSchema = z
2122
.array(auditSchema)
2223
.min(1)
2324
.check(createDuplicateSlugsCheck('Audit'))
24-
.meta({ description: 'List of audits maintained in a plugin' });
25+
.meta({
26+
title: 'PluginAudits',
27+
description: 'List of audits maintained in a plugin',
28+
});

packages/models/src/lib/cache-config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ export const cacheConfigObjectSchema = z
1212
.default(false),
1313
})
1414
.meta({
15+
title: 'CacheConfigObject',
1516
description: 'Cache configuration object for read and/or write operations',
1617
});
1718
export type CacheConfigObject = z.infer<typeof cacheConfigObjectSchema>;
1819

1920
export const cacheConfigShorthandSchema = z.boolean().meta({
21+
title: 'CacheConfigShorthand',
2022
description:
2123
'Cache configuration shorthand for both, read and write operations',
2224
});
2325
export type CacheConfigShorthand = z.infer<typeof cacheConfigShorthandSchema>;
2426

2527
export const cacheConfigSchema = z
2628
.union([cacheConfigShorthandSchema, cacheConfigObjectSchema])
27-
.meta({ description: 'Cache configuration for read and write operations' })
29+
.meta({
30+
title: 'CacheConfig',
31+
description: 'Cache configuration for read and write operations',
32+
})
2833
.default(false);
2934

3035
export type CacheConfig = z.infer<typeof cacheConfigSchema>;

packages/models/src/lib/category-config.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import { formatRef } from './implementation/utils.js';
1515
export const categoryRefSchema = weightedRefSchema(
1616
'Weighted references to audits and/or groups for the category',
1717
'Slug of an audit or group (depending on `type`)',
18-
).extend({
19-
type: z.enum(['audit', 'group']).meta({
20-
description:
21-
'Discriminant for reference kind, affects where `slug` is looked up',
22-
}),
23-
plugin: slugSchema.describe(
24-
'Plugin slug (plugin should contain referenced audit or group)',
25-
),
26-
});
18+
)
19+
.extend({
20+
type: z.enum(['audit', 'group']).meta({
21+
description:
22+
'Discriminant for reference kind, affects where `slug` is looked up',
23+
}),
24+
plugin: slugSchema.describe(
25+
'Plugin slug (plugin should contain referenced audit or group)',
26+
),
27+
})
28+
.meta({ title: 'CategoryRef' });
29+
2730
export type CategoryRef = z.infer<typeof categoryRefSchema>;
2831

2932
export const categoryConfigSchema = scorableSchema(
@@ -43,7 +46,8 @@ export const categoryConfigSchema = scorableSchema(
4346
description: 'Meta info for category',
4447
}).shape,
4548
)
46-
.extend({ scoreTarget: scoreTargetSchema });
49+
.extend({ scoreTarget: scoreTargetSchema })
50+
.meta({ title: 'CategoryConfig' });
4751

4852
export type CategoryConfig = z.infer<typeof categoryConfigSchema>;
4953

@@ -69,4 +73,7 @@ function formatSerializedCategoryRefTargets(keys: string[]): string {
6973
export const categoriesSchema = z
7074
.array(categoryConfigSchema)
7175
.check(createDuplicateSlugsCheck('Category'))
72-
.meta({ description: 'Categorization of individual audits' });
76+
.meta({
77+
title: 'Categories',
78+
description: 'Categorization of individual audits',
79+
});

packages/models/src/lib/commit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const commitSchema = z
1515
.meta({ description: 'Date and time when commit was authored' }),
1616
author: z.string().trim().meta({ description: 'Commit author name' }),
1717
})
18-
.meta({ description: 'Git commit' });
18+
.meta({
19+
title: 'Commit',
20+
description: 'Git commit',
21+
});
1922

2023
export type Commit = z.infer<typeof commitSchema>;

packages/models/src/lib/configuration.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ import { globPathSchema } from './implementation/schemas.js';
44
/**
55
* Generic schema for a tool command configuration, reusable across plugins.
66
*/
7-
export const artifactGenerationCommandSchema = z.union([
8-
z.string().min(1).meta({ description: 'Generate artifact files' }),
9-
z.object({
10-
command: z.string().min(1).meta({ description: 'Generate artifact files' }),
11-
args: z.array(z.string()).optional(),
12-
}),
13-
]);
7+
export const artifactGenerationCommandSchema = z
8+
.union([
9+
z.string().min(1).meta({ description: 'Generate artifact files' }),
10+
z.object({
11+
command: z
12+
.string()
13+
.min(1)
14+
.meta({ description: 'Generate artifact files' }),
15+
args: z.array(z.string()).optional(),
16+
}),
17+
])
18+
.meta({ title: 'ArtifactGenerationCommand' });
1419

15-
export const pluginArtifactOptionsSchema = z.object({
16-
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
17-
artifactsPaths: z
18-
.union([globPathSchema, z.array(globPathSchema).min(1)])
19-
.meta({ description: 'File paths or glob patterns for artifact files' }),
20-
});
20+
export const pluginArtifactOptionsSchema = z
21+
.object({
22+
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
23+
artifactsPaths: z
24+
.union([globPathSchema, z.array(globPathSchema).min(1)])
25+
.meta({ description: 'File paths or glob patterns for artifact files' }),
26+
})
27+
.meta({ title: 'PluginArtifactOptions' });
2128

2229
export type PluginArtifactOptions = z.infer<typeof pluginArtifactOptionsSchema>;

packages/models/src/lib/group.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { formatSlugsList } from './implementation/utils.js';
1313
export const groupRefSchema = weightedRefSchema(
1414
'Weighted reference to a group',
1515
"Reference slug to a group within this plugin (e.g. 'max-lines')",
16-
);
16+
).meta({ title: 'GroupRef' });
1717
export type GroupRef = z.infer<typeof groupRefSchema>;
1818

1919
export const groupMetaSchema = metaSchema({
@@ -22,7 +22,7 @@ export const groupMetaSchema = metaSchema({
2222
docsUrlDescription: 'Group documentation site',
2323
description: 'Group metadata',
2424
isSkippedDescription: 'Indicates whether the group is skipped',
25-
});
25+
}).meta({ title: 'GroupMeta' });
2626
export type GroupMeta = z.infer<typeof groupMetaSchema>;
2727

2828
export const groupSchema = scorableSchema(
@@ -34,12 +34,17 @@ export const groupSchema = scorableSchema(
3434
duplicates =>
3535
`Group has duplicate references to audits: ${formatSlugsList(duplicates)}`,
3636
),
37-
).merge(groupMetaSchema);
37+
)
38+
.merge(groupMetaSchema)
39+
.meta({ title: 'Group' });
3840

3941
export type Group = z.infer<typeof groupSchema>;
4042

4143
export const groupsSchema = z
4244
.array(groupSchema)
4345
.check(createDuplicateSlugsCheck('Group'))
4446
.optional()
45-
.meta({ description: 'List of groups' });
47+
.meta({
48+
title: 'Groups',
49+
description: 'List of groups',
50+
});

packages/models/src/lib/implementation/schemas.ts

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { filenameRegex, slugRegex } from './utils.js';
1616

1717
export const tableCellValueSchema = z
1818
.union([z.string(), z.number(), z.boolean(), z.null()])
19-
.default(null);
19+
.default(null)
20+
.meta({ title: 'TableCellValue' });
21+
2022
export type TableCellValue = z.infer<typeof tableCellValueSchema>;
2123

2224
/**
@@ -47,17 +49,23 @@ export const slugSchema = z
4749
.max(MAX_SLUG_LENGTH, {
4850
message: `The slug can be max ${MAX_SLUG_LENGTH} characters long`,
4951
})
50-
.meta({ description: 'Unique ID (human-readable, URL-safe)' });
52+
.meta({
53+
title: 'Slug',
54+
description: 'Unique ID (human-readable, URL-safe)',
55+
});
5156

5257
/** Schema for a general description property */
5358
export const descriptionSchema = z
5459
.string()
5560
.max(MAX_DESCRIPTION_LENGTH)
56-
.meta({ description: 'Description (markdown)' })
61+
.meta({
62+
title: 'Description',
63+
description: 'Description (markdown)',
64+
})
5765
.optional();
5866

5967
/* Schema for a URL */
60-
export const urlSchema = z.string().url();
68+
export const urlSchema = z.string().url().meta({ title: 'URL' });
6169

6270
/** Schema for a docsUrl */
6371
export const docsUrlSchema = urlSchema
@@ -79,23 +87,25 @@ export const docsUrlSchema = urlSchema
7987
}
8088
throw new ZodError(ctx.error.issues);
8189
})
82-
.meta({ description: 'Documentation site' });
90+
.meta({ title: 'DocsUrl', description: 'Documentation site' });
8391

8492
/** Schema for a title of a plugin, category and audit */
85-
export const titleSchema = z
86-
.string()
87-
.max(MAX_TITLE_LENGTH)
88-
.meta({ description: 'Descriptive name' });
93+
export const titleSchema = z.string().max(MAX_TITLE_LENGTH).meta({
94+
title: 'Title',
95+
description: 'Descriptive name',
96+
});
8997

9098
/** Schema for score of audit, category or group */
91-
export const scoreSchema = z
92-
.number()
93-
.min(0)
94-
.max(1)
95-
.meta({ description: 'Value between 0 and 1' });
99+
export const scoreSchema = z.number().min(0).max(1).meta({
100+
title: 'Score',
101+
description: 'Value between 0 and 1',
102+
});
96103

97104
/** Schema for a property indicating whether an entity is filtered out */
98-
export const isSkippedSchema = z.boolean().optional();
105+
export const isSkippedSchema = z
106+
.boolean()
107+
.optional()
108+
.meta({ title: 'IsSkipped' });
99109

100110
/**
101111
* Used for categories, plugins and audits
@@ -136,7 +146,8 @@ export function metaSchema(options?: {
136146
export const filePathSchema = z
137147
.string()
138148
.trim()
139-
.min(1, { message: 'The path is invalid' });
149+
.min(1, { message: 'The path is invalid' })
150+
.meta({ title: 'FilePath' });
140151

141152
/**
142153
* Regex for glob patterns - validates file paths and glob patterns
@@ -149,11 +160,9 @@ export const globPathSchema = z
149160
.string()
150161
.trim()
151162
.min(1, { message: 'The glob pattern is invalid' })
152-
.regex(globRegex, {
153-
message:
154-
'The path must be a valid file path or glob pattern (supports *, **, {}, [], !, ?)',
155-
})
163+
.regex(globRegex)
156164
.meta({
165+
title: 'GlobPath',
157166
description:
158167
'Schema for a glob pattern (supports wildcards like *, **, {}, !, etc.)',
159168
});
@@ -162,15 +171,21 @@ export const globPathSchema = z
162171
export const fileNameSchema = z
163172
.string()
164173
.trim()
165-
.regex(filenameRegex, {
166-
message: `The filename has to be valid`,
167-
})
168-
.min(1, { message: 'The file name is invalid' });
174+
.regex(filenameRegex)
175+
.min(1)
176+
.meta({ title: 'FileName' });
169177

170178
/** Schema for a positiveInt */
171-
export const positiveIntSchema = z.number().int().positive();
179+
export const positiveIntSchema = z
180+
.number()
181+
.int()
182+
.positive()
183+
.meta({ title: 'PositiveInt' });
172184

173-
export const nonnegativeNumberSchema = z.number().nonnegative();
185+
export const nonnegativeNumberSchema = z
186+
.number()
187+
.nonnegative()
188+
.meta({ title: 'NonnegativeNumber' });
174189

175190
export function packageVersionSchema<
176191
TRequired extends boolean = false,
@@ -195,11 +210,15 @@ export function packageVersionSchema<
195210
/** Schema for a binary score threshold */
196211
export const scoreTargetSchema = nonnegativeNumberSchema
197212
.max(1)
198-
.meta({ description: 'Pass/fail score threshold (0-1)' })
213+
.meta({
214+
title: 'ScoreTarget',
215+
description: 'Pass/fail score threshold (0-1)',
216+
})
199217
.optional();
200218

201219
/** Schema for a weight */
202220
export const weightSchema = nonnegativeNumberSchema.meta({
221+
title: 'Weight',
203222
description:
204223
'Coefficient for the given score (use weight 0 if only for display)',
205224
});
@@ -243,9 +262,10 @@ export function scorableSchema<T extends ReturnType<typeof weightedRefSchema>>(
243262
.describe(description);
244263
}
245264

246-
export const materialIconSchema = z
247-
.enum(MATERIAL_ICONS)
248-
.meta({ description: 'Icon from VSCode Material Icons extension' });
265+
export const materialIconSchema = z.enum(MATERIAL_ICONS).meta({
266+
title: 'MaterialIcon',
267+
description: 'Icon from VSCode Material Icons extension',
268+
});
249269
export type MaterialIcon = z.infer<typeof materialIconSchema>;
250270

251271
type Ref = { weight: number };
@@ -263,4 +283,7 @@ export const filePositionSchema = z
263283
endLine: positiveIntSchema.meta({ description: 'End line' }).optional(),
264284
endColumn: positiveIntSchema.meta({ description: 'End column' }).optional(),
265285
})
266-
.meta({ description: 'Location in file' });
286+
.meta({
287+
title: 'FilePosition',
288+
description: 'Location in file',
289+
});

0 commit comments

Comments
 (0)