mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
wip: replace packages with pure files
This commit is contained in:
1 parent
2d95ca382f
commit
87b8ca5d04
112 files changed
+740
-522
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
const fileSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'directory']),
|
||||
discovered: z.boolean(),
|
||||
})
|
||||
|
||||
export const commandParamsSchema = z.object({
|
||||
discover: fileSchema.array().optional(),
|
||||
})
|
||||
|
||||
export type ICommandParams = z.infer<typeof commandParamsSchema>
|
||||
|
||||
export const commandSchema = z.object({
|
||||
command: z.string().optional(),
|
||||
output: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
pwd: z.string().optional(),
|
||||
params: commandParamsSchema.optional(),
|
||||
})
|
||||
|
||||
export type ICommand = z.infer<typeof commandSchema>
|
||||
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
import { requirementsSchema } from './requirements.js'
|
||||
|
||||
export const exceptionSchema = z.object({
|
||||
id: z.string(),
|
||||
condition: conditionSchema,
|
||||
response: responseSchema,
|
||||
})
|
||||
|
||||
export type IException = z.infer<typeof exceptionSchema>
|
||||
|
||||
export const stageExceptionSchema = exceptionSchema.extend({
|
||||
catchAll: z.boolean().default(false),
|
||||
})
|
||||
|
||||
export type IStageException = z.infer<typeof stageExceptionSchema>
|
||||
|
||||
export const globalExceptionSchema = exceptionSchema.extend({
|
||||
requirements: requirementsSchema.default([]),
|
||||
})
|
||||
|
||||
export type IGlobalException = z.infer<typeof globalExceptionSchema>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IFileNode } from '../../file-graph'
|
||||
|
||||
export * from './condition.js'
|
||||
export * from './stage.js'
|
||||
export * from './requirements.js'
|
||||
export * from './response.js'
|
||||
export * from './quest.js'
|
||||
export * from './exception.js'
|
||||
export * from './command.js'
|
||||
|
||||
export interface ISession {
|
||||
completedEvents: string[]
|
||||
graph: IFileNode
|
||||
}
|
||||
|
||||
export interface ITask {
|
||||
id: string
|
||||
name: string
|
||||
completed: boolean
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { stageSchema } from './stage.js'
|
||||
import { requirementsSchema } from './requirements.js'
|
||||
import { globalExceptionSchema } from './exception.js'
|
||||
|
||||
export const questSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string(),
|
||||
image: z.string(),
|
||||
instruction: z.string(),
|
||||
requirements: requirementsSchema.default([]),
|
||||
stages: z.array(stageSchema),
|
||||
exceptions: z.array(globalExceptionSchema).optional(),
|
||||
})
|
||||
|
||||
export type IQuest = z.infer<typeof questSchema>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementsSchema = z.array(z.string())
|
||||
|
||||
export type IRequirements = z.infer<typeof requirementsSchema>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']).default('narrative'),
|
||||
content: z.string(),
|
||||
hint: z.string().optional(),
|
||||
})
|
||||
|
||||
export type IResponse = z.infer<typeof responseSchema>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { z } from 'zod'
|
||||
import { conditionSchema } from './condition.js'
|
||||
import { responseSchema } from './response.js'
|
||||
import { stageExceptionSchema } from './exception.js'
|
||||
import { requirementsSchema } from './requirements.js'
|
||||
|
||||
export const stageSchema = z.object({
|
||||
id: z.string().regex(/^[a-zA-Z0-9_-]+$/),
|
||||
name: z.string().optional(),
|
||||
requirements: requirementsSchema.default([]),
|
||||
condition: conditionSchema,
|
||||
response: responseSchema,
|
||||
exceptions: stageExceptionSchema.array().optional(),
|
||||
})
|
||||
|
||||
export type IStage = z.infer<typeof stageSchema>
|
||||
Reference in new issue
Block a user