The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import * as Exit from "effect/Exit"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | import { T3ProjectFile, T3_PROJECT_FILE_SCHEMA_URL } from "@t3tools/contracts"; |
| 5 | |
| 6 | import { fromLenientJson } from "./schemaJson.ts"; |
| 7 | |
| 8 | export const T3ProjectFileFromJson = fromLenientJson(T3ProjectFile); |
| 9 | |
| 10 | const decodeT3ProjectFile = Schema.decodeExit(T3ProjectFileFromJson); |
| 11 | |
| 12 | export function parseT3ProjectFile(contents: string): T3ProjectFile | null { |
| 13 | const decoded = decodeT3ProjectFile(contents); |
| 14 | return Exit.isSuccess(decoded) ? decoded.value : null; |
| 15 | } |
| 16 | |
| 17 | export function buildT3ProjectFileJsonSchema(): Record<string, unknown> { |
| 18 | const document = Schema.toJsonSchemaDocument(T3ProjectFile, { onExcessProperty: "error" }); |
| 19 | const jsonSchema: Record<string, unknown> = { |
| 20 | $schema: "https://json-schema.org/draft/2020-12/schema", |
| 21 | $id: T3_PROJECT_FILE_SCHEMA_URL, |
| 22 | ...document.schema, |
| 23 | }; |
| 24 | if (document.definitions && Object.keys(document.definitions).length > 0) { |
| 25 | jsonSchema.$defs = document.definitions; |
| 26 | } |
| 27 | return jsonSchema; |
| 28 | } |