Skip to content
Source
Sign inSign up

t3ProjectFile.ts

28 lines1.0 KB

1import * as Exit from "effect/Exit";
2import * as Schema from "effect/Schema";
3​
4import { T3ProjectFile, T3_PROJECT_FILE_SCHEMA_URL } from "@t3tools/contracts";
5​
6import { fromLenientJson } from "./schemaJson.ts";
7​
8export const T3ProjectFileFromJson = fromLenientJson(T3ProjectFile);
9​
10const decodeT3ProjectFile = Schema.decodeExit(T3ProjectFileFromJson);
11​
12export function parseT3ProjectFile(contents: string): T3ProjectFile | null {
13 const decoded = decodeT3ProjectFile(contents);
14 return Exit.isSuccess(decoded) ? decoded.value : null;
16​
17export 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;