mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
export const fileInputSchema = z.object({
|
|
path: z.string(),
|
|
type: z.enum(['file', 'directory']),
|
|
})
|
|
|
|
export type IFileInput = z.infer<typeof fileInputSchema>
|
|
|
|
export const fileExistenceInputSchema = fileInputSchema.extend({
|
|
exists: z.boolean(),
|
|
})
|
|
|
|
export type IFileExistenceInput = z.infer<typeof fileExistenceInputSchema>
|
|
|
|
const baseConditionSchema = z.object({
|
|
command: z.string().optional(),
|
|
output: z.string().optional(),
|
|
error: z.string().optional(),
|
|
pwd: z.string().optional(),
|
|
files: z.array(fileExistenceInputSchema).optional(),
|
|
})
|
|
|
|
export type ICondition = z.infer<typeof baseConditionSchema> & {
|
|
or?: ICondition[]
|
|
not?: ICondition
|
|
}
|
|
|
|
export const conditionSchema: z.ZodType<ICondition> =
|
|
baseConditionSchema.extend({
|
|
or: z.lazy(() => z.array(conditionSchema).optional()),
|
|
not: z.lazy(() => conditionSchema.optional()),
|
|
})
|
|
|
|
export interface IFileExistenceChecker {
|
|
exists(file: IFileInput): Promise<boolean>
|
|
}
|
|
|
|
export class VoidFileExistenceChecker implements IFileExistenceChecker {
|
|
// eslint-disable-next-line class-methods-use-this
|
|
async exists(_file: IFileInput): Promise<boolean> {
|
|
return false
|
|
}
|
|
}
|