mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: separate schema to files
This commit is contained in:
1 parent
57d8f24930
commit
471b781d85
4 files changed
+64
-54
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const fileInputSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'folder']),
|
||||
})
|
||||
|
||||
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(),
|
||||
})
|
||||
@@ -1,54 +1,7 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementsSchema = z.object({
|
||||
requirements: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type IRequirements = z.infer<typeof requirementsSchema>
|
||||
|
||||
export const fileInputSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'folder']),
|
||||
})
|
||||
|
||||
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 const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']),
|
||||
content: z.string(),
|
||||
})
|
||||
|
||||
export const stageSchema = z.object({
|
||||
id: z.string().regex(/^[a-zA-Z0-9_-]+$/),
|
||||
name: z.string().optional(),
|
||||
requirements: z.array(z.string()),
|
||||
condition: conditionSchema,
|
||||
response: responseSchema,
|
||||
})
|
||||
|
||||
export type IStage = z.infer<typeof stageSchema>
|
||||
export { conditionSchema, ICondition } from './condition.js'
|
||||
export { stageSchema, IStage } from './stage.js'
|
||||
export {
|
||||
requirementsSchema,
|
||||
IRequirements,
|
||||
responseSchema,
|
||||
} from './requirements.js'
|
||||
@@ -0,0 +1,12 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementsSchema = z.object({
|
||||
requirements: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type IRequirements = z.infer<typeof requirementsSchema>
|
||||
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']),
|
||||
content: z.string(),
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema, responseSchema } from './index.js'
|
||||
|
||||
export const stageSchema = z.object({
|
||||
id: z.string().regex(/^[a-zA-Z0-9_-]+$/),
|
||||
name: z.string().optional(),
|
||||
requirements: z.array(z.string()),
|
||||
condition: conditionSchema,
|
||||
response: responseSchema,
|
||||
})
|
||||
|
||||
export type IStage = z.infer<typeof stageSchema>
|
||||
Reference in new issue
Block a user