Skip to content

Commit 7504d1e

Browse files
committed
refactor(models): replace .describe('...') with recommended .meta({ description: '...' })
1 parent 169b915 commit 7504d1e

File tree

23 files changed

+242
-183
lines changed

23 files changed

+242
-183
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,39 @@ import { issueSchema } from './issue.js';
1010
import { tableSchema } from './table.js';
1111
import { treeSchema } from './tree.js';
1212

13-
export const auditValueSchema =
14-
nonnegativeNumberSchema.describe('Raw numeric value');
13+
export const auditValueSchema = nonnegativeNumberSchema.meta({
14+
description: 'Raw numeric value',
15+
});
1516
export const auditDisplayValueSchema = z
1617
.string()
1718
.optional()
18-
.describe("Formatted value (e.g. '0.9 s', '2.1 MB')");
19+
.meta({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" });
1920

2021
export const auditDetailsSchema = z
2122
.object({
22-
issues: z.array(issueSchema).describe('List of findings').optional(),
23+
issues: z
24+
.array(issueSchema)
25+
.meta({ description: 'List of findings' })
26+
.optional(),
2327
table: tableSchema('Table of related findings').optional(),
2428
trees: z
2529
.array(treeSchema)
26-
.describe('Findings in tree structure')
30+
.meta({ description: 'Findings in tree structure' })
2731
.optional(),
2832
})
29-
.describe('Detailed information');
33+
.meta({ description: 'Detailed information' });
3034
export type AuditDetails = z.infer<typeof auditDetailsSchema>;
3135

3236
export const auditOutputSchema = z
3337
.object({
34-
slug: slugSchema.describe('Reference to audit'),
38+
slug: slugSchema.meta({ description: 'Reference to audit' }),
3539
displayValue: auditDisplayValueSchema,
3640
value: auditValueSchema,
3741
score: scoreSchema,
3842
scoreTarget: scoreTargetSchema,
3943
details: auditDetailsSchema.optional(),
4044
})
41-
.describe('Audit information');
45+
.meta({ description: 'Audit information' });
4246

4347
export type AuditOutput = z.infer<typeof auditOutputSchema>;
4448

packages/models/src/lib/audit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { metaSchema, slugSchema } from './implementation/schemas.js';
44

55
export const auditSchema = z
66
.object({
7-
slug: slugSchema.describe('ID (unique within plugin)'),
7+
slug: slugSchema.meta({ description: 'ID (unique within plugin)' }),
88
})
99
.extend(
1010
metaSchema({
@@ -21,4 +21,4 @@ export const pluginAuditsSchema = z
2121
.array(auditSchema)
2222
.min(1)
2323
.check(createDuplicateSlugsCheck('Audit'))
24-
.describe('List of audits maintained in a plugin');
24+
.meta({ description: 'List of audits maintained in a plugin' });

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@ export const cacheConfigObjectSchema = z
44
.object({
55
read: z
66
.boolean()
7-
.describe('Whether to read from cache if available')
7+
.meta({ description: 'Whether to read from cache if available' })
88
.default(false),
99
write: z
1010
.boolean()
11-
.describe('Whether to write results to cache')
11+
.meta({ description: 'Whether to write results to cache' })
1212
.default(false),
1313
})
14-
.describe('Cache configuration object for read and/or write operations');
14+
.meta({
15+
description: 'Cache configuration object for read and/or write operations',
16+
});
1517
export type CacheConfigObject = z.infer<typeof cacheConfigObjectSchema>;
1618

17-
export const cacheConfigShorthandSchema = z
18-
.boolean()
19-
.describe(
19+
export const cacheConfigShorthandSchema = z.boolean().meta({
20+
description:
2021
'Cache configuration shorthand for both, read and write operations',
21-
);
22+
});
2223
export type CacheConfigShorthand = z.infer<typeof cacheConfigShorthandSchema>;
2324

2425
export const cacheConfigSchema = z
2526
.union([cacheConfigShorthandSchema, cacheConfigObjectSchema])
26-
.describe('Cache configuration for read and write operations')
27+
.meta({ description: 'Cache configuration for read and write operations' })
2728
.default(false);
2829

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

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ 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`)',
1818
).extend({
19-
type: z
20-
.enum(['audit', 'group'])
21-
.describe(
19+
type: z.enum(['audit', 'group']).meta({
20+
description:
2221
'Discriminant for reference kind, affects where `slug` is looked up',
23-
),
22+
}),
2423
plugin: slugSchema.describe(
2524
'Plugin slug (plugin should contain referenced audit or group)',
2625
),
@@ -70,4 +69,4 @@ function formatSerializedCategoryRefTargets(keys: string[]): string {
7069
export const categoriesSchema = z
7170
.array(categoryConfigSchema)
7271
.check(createDuplicateSlugsCheck('Category'))
73-
.describe('Categorization of individual audits');
72+
.meta({ description: 'Categorization of individual audits' });

packages/models/src/lib/commit.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ export const commitSchema = z
88
/^[\da-f]{40}$/,
99
'Commit SHA should be a 40-character hexadecimal string',
1010
)
11-
.describe('Commit SHA (full)'),
12-
message: z.string().describe('Commit message'),
13-
date: z.coerce.date().describe('Date and time when commit was authored'),
14-
author: z.string().trim().describe('Commit author name'),
11+
.meta({ description: 'Commit SHA (full)' }),
12+
message: z.string().meta({ description: 'Commit message' }),
13+
date: z.coerce
14+
.date()
15+
.meta({ description: 'Date and time when commit was authored' }),
16+
author: z.string().trim().meta({ description: 'Commit author name' }),
1517
})
16-
.describe('Git commit');
18+
.meta({ description: 'Git commit' });
1719

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

packages/models/src/lib/configuration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { globPathSchema } from './implementation/schemas.js';
55
* Generic schema for a tool command configuration, reusable across plugins.
66
*/
77
export const artifactGenerationCommandSchema = z.union([
8-
z.string().min(1).describe('Generate artifact files'),
8+
z.string().min(1).meta({ description: 'Generate artifact files' }),
99
z.object({
10-
command: z.string().min(1).describe('Generate artifact files'),
10+
command: z.string().min(1).meta({ description: 'Generate artifact files' }),
1111
args: z.array(z.string()).optional(),
1212
}),
1313
]);
@@ -16,7 +16,7 @@ export const pluginArtifactOptionsSchema = z.object({
1616
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
1717
artifactsPaths: z
1818
.union([globPathSchema, z.array(globPathSchema).min(1)])
19-
.describe('File paths or glob patterns for artifact files'),
19+
.meta({ description: 'File paths or glob patterns for artifact files' }),
2020
});
2121

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

packages/models/src/lib/group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ export const groupsSchema = z
4242
.array(groupSchema)
4343
.check(createDuplicateSlugsCheck('Group'))
4444
.optional()
45-
.describe('List of groups');
45+
.meta({ description: 'List of groups' });

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ export const slugSchema = z
4747
.max(MAX_SLUG_LENGTH, {
4848
message: `The slug can be max ${MAX_SLUG_LENGTH} characters long`,
4949
})
50-
.describe('Unique ID (human-readable, URL-safe)');
50+
.meta({ description: 'Unique ID (human-readable, URL-safe)' });
5151

5252
/** Schema for a general description property */
5353
export const descriptionSchema = z
5454
.string()
5555
.max(MAX_DESCRIPTION_LENGTH)
56-
.describe('Description (markdown)')
56+
.meta({ description: 'Description (markdown)' })
5757
.optional();
5858

5959
/* Schema for a URL */
@@ -79,20 +79,20 @@ export const docsUrlSchema = urlSchema
7979
}
8080
throw new ZodError(ctx.error.issues);
8181
})
82-
.describe('Documentation site');
82+
.meta({ description: 'Documentation site' });
8383

8484
/** Schema for a title of a plugin, category and audit */
8585
export const titleSchema = z
8686
.string()
8787
.max(MAX_TITLE_LENGTH)
88-
.describe('Descriptive name');
88+
.meta({ description: 'Descriptive name' });
8989

9090
/** Schema for score of audit, category or group */
9191
export const scoreSchema = z
9292
.number()
9393
.min(0)
9494
.max(1)
95-
.describe('Value between 0 and 1');
95+
.meta({ description: 'Value between 0 and 1' });
9696

9797
/** Schema for a property indicating whether an entity is filtered out */
9898
export const isSkippedSchema = z.boolean().optional();
@@ -153,9 +153,10 @@ export const globPathSchema = z
153153
message:
154154
'The path must be a valid file path or glob pattern (supports *, **, {}, [], !, ?)',
155155
})
156-
.describe(
157-
'Schema for a glob pattern (supports wildcards like *, **, {}, !, etc.)',
158-
);
156+
.meta({
157+
description:
158+
'Schema for a glob pattern (supports wildcards like *, **, {}, !, etc.)',
159+
});
159160

160161
/** Schema for a fileNameSchema */
161162
export const fileNameSchema = z
@@ -176,16 +177,16 @@ export function packageVersionSchema<
176177
>(options?: { versionDescription?: string; required?: TRequired }) {
177178
const { versionDescription = 'NPM version of the package', required } =
178179
options ?? {};
179-
const packageSchema = z.string().describe('NPM package name');
180-
const versionSchema = z.string().describe(versionDescription);
180+
const packageSchema = z.string().meta({ description: 'NPM package name' });
181+
const versionSchema = z.string().meta({ description: versionDescription });
181182
return z
182183
.object({
183184
packageName: required ? packageSchema : packageSchema.optional(),
184185
version: required ? versionSchema : versionSchema.optional(),
185186
})
186-
.describe(
187-
'NPM package name and version of a published package',
188-
) as ZodObject<{
187+
.meta({
188+
description: 'NPM package name and version of a published package',
189+
}) as ZodObject<{
189190
packageName: TRequired extends true ? ZodString : ZodOptional<ZodString>;
190191
version: TRequired extends true ? ZodString : ZodOptional<ZodString>;
191192
}>;
@@ -194,24 +195,27 @@ export function packageVersionSchema<
194195
/** Schema for a binary score threshold */
195196
export const scoreTargetSchema = nonnegativeNumberSchema
196197
.max(1)
197-
.describe('Pass/fail score threshold (0-1)')
198+
.meta({ description: 'Pass/fail score threshold (0-1)' })
198199
.optional();
199200

200201
/** Schema for a weight */
201-
export const weightSchema = nonnegativeNumberSchema.describe(
202-
'Coefficient for the given score (use weight 0 if only for display)',
203-
);
202+
export const weightSchema = nonnegativeNumberSchema.meta({
203+
description:
204+
'Coefficient for the given score (use weight 0 if only for display)',
205+
});
204206

205207
export function weightedRefSchema(
206208
description: string,
207209
slugDescription: string,
208210
) {
209211
return z
210212
.object({
211-
slug: slugSchema.describe(slugDescription),
212-
weight: weightSchema.describe('Weight used to calculate score'),
213+
slug: slugSchema.meta({ description: slugDescription }),
214+
weight: weightSchema.meta({
215+
description: 'Weight used to calculate score',
216+
}),
213217
})
214-
.describe(description);
218+
.meta({ description });
215219
}
216220

217221
export type WeightedRef = z.infer<ReturnType<typeof weightedRefSchema>>;
@@ -223,7 +227,9 @@ export function scorableSchema<T extends ReturnType<typeof weightedRefSchema>>(
223227
) {
224228
return z
225229
.object({
226-
slug: slugSchema.describe('Human-readable unique ID, e.g. "performance"'),
230+
slug: slugSchema.meta({
231+
description: 'Human-readable unique ID, e.g. "performance"',
232+
}),
227233
refs: z
228234
.array(refSchema)
229235
.min(1, { message: 'In a category, there has to be at least one ref' })
@@ -239,7 +245,7 @@ export function scorableSchema<T extends ReturnType<typeof weightedRefSchema>>(
239245

240246
export const materialIconSchema = z
241247
.enum(MATERIAL_ICONS)
242-
.describe('Icon from VSCode Material Icons extension');
248+
.meta({ description: 'Icon from VSCode Material Icons extension' });
243249
export type MaterialIcon = z.infer<typeof materialIconSchema>;
244250

245251
type Ref = { weight: number };
@@ -250,9 +256,11 @@ function hasNonZeroWeightedRef(refs: Ref[]) {
250256

251257
export const filePositionSchema = z
252258
.object({
253-
startLine: positiveIntSchema.describe('Start line'),
254-
startColumn: positiveIntSchema.describe('Start column').optional(),
255-
endLine: positiveIntSchema.describe('End line').optional(),
256-
endColumn: positiveIntSchema.describe('End column').optional(),
259+
startLine: positiveIntSchema.meta({ description: 'Start line' }),
260+
startColumn: positiveIntSchema
261+
.meta({ description: 'Start column' })
262+
.optional(),
263+
endLine: positiveIntSchema.meta({ description: 'End line' }).optional(),
264+
endColumn: positiveIntSchema.meta({ description: 'End column' }).optional(),
257265
})
258-
.describe('Location in file');
266+
.meta({ description: 'Location in file' });

packages/models/src/lib/issue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { sourceFileLocationSchema } from './source.js';
44

55
export const issueSeveritySchema = z
66
.enum(['info', 'warning', 'error'])
7-
.describe('Severity level');
7+
.meta({ description: 'Severity level' });
88
export type IssueSeverity = z.infer<typeof issueSeveritySchema>;
99

1010
export const issueSchema = z
1111
.object({
1212
message: z
1313
.string()
1414
.max(MAX_ISSUE_MESSAGE_LENGTH)
15-
.describe('Descriptive error message'),
15+
.meta({ description: 'Descriptive error message' }),
1616
severity: issueSeveritySchema,
1717
source: sourceFileLocationSchema.optional(),
1818
})
19-
.describe('Issue information');
19+
.meta({ description: 'Issue information' });
2020
export type Issue = z.infer<typeof issueSchema>;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ export const formatSchema = z.enum(['json', 'md']);
55
export type Format = z.infer<typeof formatSchema>;
66

77
export const persistConfigSchema = z.object({
8-
outputDir: filePathSchema.describe('Artifacts folder').optional(),
8+
outputDir: filePathSchema
9+
.meta({ description: 'Artifacts folder' })
10+
.optional(),
911
filename: fileNameSchema
10-
.describe('Artifacts file name (without extension)')
12+
.meta({ description: 'Artifacts file name (without extension)' })
1113
.optional(),
1214
format: z.array(formatSchema).optional(),
1315
skipReports: z.boolean().optional(),

0 commit comments

Comments
 (0)