Skip to content

Commit 690ba8e

Browse files
committed
test(models): add globPathSchema
1 parent d2de7bb commit 690ba8e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

packages/models/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export {
5757
export {
5858
fileNameSchema,
5959
filePathSchema,
60+
globPathSchema,
6061
materialIconSchema,
6162
type MaterialIcon,
6263
} from './lib/implementation/schemas.js';

packages/models/src/lib/configuration.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from 'zod';
2+
import { filePathSchema, globPathSchema } from './implementation/schemas.js';
23

34
/**
45
* Generic schema for a tool command configuration, reusable across plugins.
@@ -13,7 +14,14 @@ export const artifactGenerationCommandSchema = z.union([
1314

1415
export const pluginArtifactOptionsSchema = z.object({
1516
generateArtifactsCommand: artifactGenerationCommandSchema.optional(),
16-
artifactsPaths: z.union([z.string(), z.array(z.string()).min(1)]),
17+
artifactsPaths: z
18+
.union([
19+
filePathSchema,
20+
z.array(filePathSchema).min(1),
21+
globPathSchema,
22+
z.array(globPathSchema).min(1),
23+
])
24+
.describe('File paths or glob patterns for artifact files'),
1725
});
1826

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ export const filePathSchema = z
138138
.trim()
139139
.min(1, { message: 'The path is invalid' });
140140

141+
/**
142+
* Regex for glob patterns - validates file paths and glob patterns
143+
* Allows normal paths and paths with glob metacharacters: *, **, {}, [], !, ?
144+
* Excludes invalid path characters: <>"|
145+
*/
146+
const globRegex = /^!?[^<>"|]+$/;
147+
148+
/** Schema for a glob pattern (supports wildcards like *, **, {}, !, etc.) */
149+
export const globPathSchema = z
150+
.string()
151+
.trim()
152+
.min(1, { message: 'The glob pattern is invalid' })
153+
.regex(globRegex, {
154+
message:
155+
'The path must be a valid file path or glob pattern (supports *, **, {}, [], !, ?)',
156+
})
157+
.describe('File path or glob pattern (supports *, **, {}, !, etc.)');
158+
141159
/** Schema for a fileNameSchema */
142160
export const fileNameSchema = z
143161
.string()

0 commit comments

Comments
 (0)