feat: zod 라이브러리 업데이트 및 JSON 스키마 정의 개선
This commit is contained in:
@@ -19,7 +19,7 @@ export const CrewTypeRequirementSchema = z.union([
|
||||
z.object({ type: z.literal('ReqChief') }),
|
||||
z.object({ type: z.literal('ReqNotChief') }),
|
||||
z.object({ type: z.literal('Impossible') }),
|
||||
z.looseObject({ type: z.string() }),
|
||||
z.object({ type: z.string() }).passthrough(),
|
||||
]);
|
||||
|
||||
export const CrewTypeDefinitionInputSchema = z.object({
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sammo-ts/logic": "workspace:*",
|
||||
"zod-to-json-schema": "^3.25.1"
|
||||
"zod": "^4.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.21.0",
|
||||
|
||||
@@ -2,32 +2,31 @@ import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import type { ZodTypeAny } from 'zod';
|
||||
import { zodToJsonSchema } from 'zod-to-json-schema';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
MapResourceSchema,
|
||||
ScenarioResourceSchema,
|
||||
TurnCommandProfileInputSchema,
|
||||
UnitSetDefinitionInputSchema,
|
||||
} from '@sammo-ts/logic';
|
||||
} from '@sammo-ts/logic/resources';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..', '..');
|
||||
const RESOURCE_ROOT = path.join(REPO_ROOT, 'resources');
|
||||
|
||||
const writeSchema = async (relativePath: string, schema: ZodTypeAny, name: string): Promise<void> => {
|
||||
const writeSchema = async (relativePath: string, schema: unknown): Promise<void> => {
|
||||
const outputPath = path.join(RESOURCE_ROOT, relativePath);
|
||||
const jsonSchema = zodToJsonSchema(schema, { name, target: 'jsonSchema7' });
|
||||
const jsonSchema = z.toJSONSchema(schema, { target: 'draft-07' });
|
||||
const serialized = `${JSON.stringify(jsonSchema, null, 4)}\n`;
|
||||
await fs.writeFile(outputPath, serialized, 'utf8');
|
||||
};
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
await writeSchema(path.join('map', 'schema.json'), MapResourceSchema, 'MapResource');
|
||||
await writeSchema(path.join('scenario', 'schema.json'), ScenarioResourceSchema, 'ScenarioResource');
|
||||
await writeSchema(path.join('unitset', 'schema.json'), UnitSetDefinitionInputSchema, 'UnitSetDefinition');
|
||||
await writeSchema(path.join('turn-commands', 'schema.json'), TurnCommandProfileInputSchema, 'TurnCommandProfile');
|
||||
await writeSchema(path.join('map', 'schema.json'), MapResourceSchema);
|
||||
await writeSchema(path.join('scenario', 'schema.json'), ScenarioResourceSchema);
|
||||
await writeSchema(path.join('unitset', 'schema.json'), UnitSetDefinitionInputSchema);
|
||||
await writeSchema(path.join('turn-commands', 'schema.json'), TurnCommandProfileInputSchema);
|
||||
};
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ScenarioResourceSchema,
|
||||
TurnCommandProfileInputSchema,
|
||||
UnitSetDefinitionInputSchema,
|
||||
} from '@sammo-ts/logic';
|
||||
} from '@sammo-ts/logic/resources';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
@@ -15,6 +15,5 @@
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "../logic" }]
|
||||
"include": ["src"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user