wip: migrating game handler

This commit is contained in:
Justin Lin committed 2025-04-18 14:27:36 +08:00
1 parent 61d1871e95
commit 6043226142
26 files changed
+85 -364

No files matched your search

+10 -2
View File
@@ -2,7 +2,7 @@ import { z } from 'zod'
import { fileConditionSchema } from './file-condition.js'
import { toArray } from '../utils.js'
export const conditionSchema = z.object({
const conditionSchemaBase = z.object({
command: z.preprocess(toArray, z.array(z.string()).optional()),
output: z.preprocess(toArray, z.array(z.string()).optional()),
error: z.preprocess(toArray, z.array(z.string()).optional()),
@@ -10,4 +10,12 @@ export const conditionSchema = z.object({
files: z.array(fileConditionSchema).optional(),
})
export type Condition = z.infer<typeof conditionSchema>
export type Condition = z.infer<typeof conditionSchemaBase> & {
not?: Condition
or?: Condition[]
}
export const conditionSchema = conditionSchemaBase.extend({
not: z.lazy(() => conditionSchema).optional(),
or: z.lazy(() => z.array(conditionSchema)).optional(),
}) as z.ZodType<Condition>
+22
View File
@@ -0,0 +1,22 @@
import { z } from 'zod'
import { conditionSchema } from './condition.js'
import { responseSchema } from './response.js'
export const exceptionSchema = z.object({
condition: conditionSchema,
responses: z.array(responseSchema),
})
export type Exception = z.infer<typeof exceptionSchema>
export const stageExceptionSchema = exceptionSchema.extend({
catchAll: z.boolean().default(false),
})
export type StageException = z.infer<typeof stageExceptionSchema>
export const globalExceptionSchema = exceptionSchema.extend({
requirements: z.array(z.string()),
})
export type GlobalException = z.infer<typeof globalExceptionSchema>
@@ -1,11 +0,0 @@
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>
+1 -1
View File
@@ -6,6 +6,6 @@ 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 './exception.js'
export * from './quest.js'
export * from './quest-detail-response.js'
@@ -1,7 +1,7 @@
import { z } from 'zod'
export const questDetailResponseSchema = z.object({
_id: z.string(),
id: z.string(),
title: z.string(),
instruction: z.string(),
requirements: z.array(z.string()),
+1 -1
View File
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { stageSchema } from './stage.js'
import { globalExceptionSchema } from './global-exception.js'
import { globalExceptionSchema } from './exception.js'
import { requirementSchema } from './requirement.js'
export const questSchema = z.object({
@@ -1,10 +0,0 @@
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>
+1 -1
View File
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { stageExceptionSchema } from './stage-exception.js'
import { stageExceptionSchema } from './exception.js'
import { conditionSchema } from './condition.js'
import { responseSchema } from './response.js'
import { hintSchema } from './hint.js'