mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: parse quest using zod, basic
This commit is contained in:
1 parent
963655c1f7
commit
ed4d04b658
22 files changed
+390
-95
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export * from './quest.js'
|
||||
export * from './quest/index.js'
|
||||
export * from './session.js'
|
||||
|
||||
export const passwordPolicy = {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export interface QuestDetailResponse {
|
||||
_id: string
|
||||
title: string
|
||||
instruction: string
|
||||
requirements: string[]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
|
||||
export const commandResponderSchema = z.object({
|
||||
condition: conditionSchema.optional(),
|
||||
responses: z.array(responseSchema),
|
||||
hints: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type CommandResponder = z.infer<typeof commandResponderSchema>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { z } from 'zod'
|
||||
import { fileConditionSchema } from './file-condition.js'
|
||||
|
||||
export const conditionSchema = z.object({
|
||||
command: z.array(z.string()).optional(),
|
||||
output: z.array(z.string()).optional(),
|
||||
error: z.array(z.string()).optional(),
|
||||
pwd: z.array(z.string()).optional(),
|
||||
files: z.array(fileConditionSchema).optional(),
|
||||
})
|
||||
|
||||
export type Condition = z.infer<typeof conditionSchema>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const fileConditionSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.string().optional(),
|
||||
exists: z.boolean().default(true),
|
||||
})
|
||||
|
||||
export type FileCondition = z.infer<typeof fileConditionSchema>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
|
||||
export const globalExceptionSchema = z.object({
|
||||
condition: conditionSchema,
|
||||
responses: z.array(responseSchema),
|
||||
requirements: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type GlobalException = z.infer<typeof globalExceptionSchema>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const hintSchema = z.array(z.string())
|
||||
|
||||
export type Hint = z.infer<typeof hintSchema>
|
||||
@@ -0,0 +1,11 @@
|
||||
export * from './requirement.js'
|
||||
export * from './hint.js'
|
||||
export * from './file-condition.js'
|
||||
export * from './condition.js'
|
||||
export * from './response.js'
|
||||
export * from './command-responder.js'
|
||||
export * from './stage-exception.js'
|
||||
export * from './stage.js'
|
||||
export * from './global-exception.js'
|
||||
export * from './quest.js'
|
||||
export * from './quest-detail-response.js'
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const questDetailResponseSchema = z.object({
|
||||
_id: z.string(),
|
||||
title: z.string(),
|
||||
instruction: z.string(),
|
||||
requirements: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type QuestDetailResponse = z.infer<typeof questDetailResponseSchema>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { stageSchema } from './stage.js'
|
||||
import { globalExceptionSchema } from './global-exception.js'
|
||||
import { requirementSchema } from './requirement.js'
|
||||
|
||||
export const questSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
image: z.string(),
|
||||
instruction: z.string(),
|
||||
requirements: requirementSchema,
|
||||
stages: z.array(stageSchema),
|
||||
exceptions: z.array(globalExceptionSchema).default([]),
|
||||
})
|
||||
|
||||
export type Quest = z.infer<typeof questSchema>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementSchema = z.array(z.string()).default([])
|
||||
|
||||
export type Requirement = z.infer<typeof requirementSchema>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']).default('narrative'),
|
||||
content: z.string(),
|
||||
})
|
||||
|
||||
export type Response = z.infer<typeof responseSchema>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
|
||||
export const stageExceptionSchema = z.object({
|
||||
condition: conditionSchema,
|
||||
responses: z.array(responseSchema),
|
||||
})
|
||||
|
||||
export type StageException = z.infer<typeof stageExceptionSchema>
|
||||
@@ -0,0 +1,18 @@
|
||||
import { z } from 'zod'
|
||||
import { stageExceptionSchema } from './stage-exception.js'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
import { hintSchema } from './hint.js'
|
||||
import { requirementSchema } from './requirement.js'
|
||||
|
||||
export const stageSchema = z.object({
|
||||
id: z.string(),
|
||||
task: z.string(),
|
||||
exceptions: z.array(stageExceptionSchema).default([]),
|
||||
requirements: requirementSchema,
|
||||
condition: conditionSchema,
|
||||
responses: z.array(responseSchema),
|
||||
hints: hintSchema.default([]),
|
||||
})
|
||||
|
||||
export type Stage = z.infer<typeof stageSchema>
|
||||
Reference in new issue
Block a user