mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
refactor: remove unused quest-related schemas and consolidate exports
This commit is contained in:
1 parent
d2cdd1304a
commit
1d843f7355
29 files changed
+35
-161
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export * from './quest/index.js'
|
||||
export * from './session.js'
|
||||
|
||||
export const passwordPolicy = {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
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>
|
||||
@@ -1,21 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { fileConditionSchema } from './file-condition.js'
|
||||
import { toArray } from '../utils.js'
|
||||
|
||||
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()),
|
||||
pwd: z.preprocess(toArray, z.array(z.string()).optional()),
|
||||
files: z.array(fileConditionSchema).optional(),
|
||||
})
|
||||
|
||||
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>
|
||||
@@ -1,22 +0,0 @@
|
||||
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,9 +0,0 @@
|
||||
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>
|
||||
@@ -1,5 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const hintSchema = z.array(z.string())
|
||||
|
||||
export type Hint = z.infer<typeof hintSchema>
|
||||
@@ -1,11 +0,0 @@
|
||||
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 './exception.js'
|
||||
export * from './quest.js'
|
||||
export * from './quest-detail-response.js'
|
||||
@@ -1,10 +0,0 @@
|
||||
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>
|
||||
@@ -1,16 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { stageSchema } from './stage.js'
|
||||
import { globalExceptionSchema } from './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>
|
||||
@@ -1,5 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementSchema = z.array(z.string()).default([])
|
||||
|
||||
export type Requirement = z.infer<typeof requirementSchema>
|
||||
@@ -1,9 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { toArray } from '../utils.js'
|
||||
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']).default('narrative'),
|
||||
content: z.preprocess(toArray, z.array(z.string())),
|
||||
})
|
||||
|
||||
export type Response = z.infer<typeof responseSchema>
|
||||
@@ -1,18 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
import { stageExceptionSchema } from './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: stageExceptionSchema.array().default([]),
|
||||
requirements: requirementSchema,
|
||||
condition: conditionSchema,
|
||||
responses: z.array(responseSchema),
|
||||
hints: hintSchema.default([]),
|
||||
})
|
||||
|
||||
export type Stage = z.infer<typeof stageSchema>
|
||||
@@ -1,7 +1,10 @@
|
||||
{
|
||||
"name": "@linux-odyssey/game",
|
||||
"version": "1.0.0",
|
||||
"main": "dist/index.ts",
|
||||
"main": "dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc -b"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class CommandMatcher implements Matcher {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
ICommand,
|
||||
IFileExistenceChecker,
|
||||
IFileInput,
|
||||
ICondition,
|
||||
IFileExistenceInput,
|
||||
} from '../schema'
|
||||
import { PwdMatcher } from './PwdMatcher.js'
|
||||
import { CommandMatcher } from './CommandMatcher.js'
|
||||
@@ -14,7 +14,7 @@ import { NotMatcher } from './NotMatcher.js'
|
||||
import { checkFiles } from './FileMatcher.js'
|
||||
|
||||
export class Condition {
|
||||
private files: IFileInput[] = []
|
||||
private files: IFileExistenceInput[] = []
|
||||
private matchers: Matcher[] = []
|
||||
|
||||
constructor({ command, output, error, pwd, or, not, files }: ICondition) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Matcher } from './Matcher.js'
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
|
||||
export class ErrorMatcher implements Matcher {
|
||||
private matcher?: RegExp
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { FileExistenceInput, IFileExistenceChecker } from '../types'
|
||||
import { IFileExistenceInput, IFileExistenceChecker } from '../schema'
|
||||
|
||||
export async function checkFiles(
|
||||
checker: IFileExistenceChecker,
|
||||
files: FileExistenceInput[]
|
||||
files: IFileExistenceInput[]
|
||||
) {
|
||||
const existences = await Promise.all(
|
||||
files.map((file) => checker.exists(file))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
|
||||
export interface Matcher {
|
||||
match(command: ICommand): boolean
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class NotMatcher implements Matcher {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class OrMatcher implements Matcher {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class OutputMatcher implements Matcher {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ICommand } from '../types.js'
|
||||
import { ICommand } from '../schema'
|
||||
import { Matcher } from './Matcher.js'
|
||||
|
||||
export class PwdMatcher implements Matcher {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export * from './schema'
|
||||
export * from './Quest'
|
||||
export * from './Session'
|
||||
export * from './Event'
|
||||
export * from './Stage'
|
||||
export * from './Exception'
|
||||
@@ -1,9 +1,9 @@
|
||||
export * from './condition.js'
|
||||
export { stageSchema, IStage } from './stage.js'
|
||||
export { requirementsSchema, IRequirements } from './requirements.js'
|
||||
export { responseSchema, IResponse } from './response.js'
|
||||
export { questSchema, IQuest } from './quest.js'
|
||||
export { exceptionSchema, IException } from './exception.js'
|
||||
export * from './stage.js'
|
||||
export * from './requirements.js'
|
||||
export * from './response.js'
|
||||
export * from './quest.js'
|
||||
export * from './exception.js'
|
||||
|
||||
export interface ICommand {
|
||||
command?: string
|
||||
|
||||
@@ -3,6 +3,7 @@ import { z } from 'zod'
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']),
|
||||
content: z.string(),
|
||||
hint: z.string().optional(),
|
||||
})
|
||||
|
||||
export type IResponse = z.infer<typeof responseSchema>
|
||||
Whitespace-only changes.
@@ -2,7 +2,8 @@
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
"rootDir": "./src",
|
||||
"composite": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in new issue
Block a user