Initial commit

This commit is contained in:
Rami Bitar
2026-05-02 09:18:15 -04:00
commit 7348e430c0
96 changed files with 15753 additions and 0 deletions

39
lib/schema.server.ts Normal file
View File

@@ -0,0 +1,39 @@
import fs from "node:fs/promises";
import path from "node:path";
export const SCHEMA_PATH = path.join(process.cwd(), "app.schema.json");
export type Schema = Record<string, { root: any; content: any[] }>;
const FALLBACK: Schema = {
"/": { root: { props: { title: "Untitled" } }, content: [] },
};
export async function readSchema(): Promise<Schema> {
try {
const raw = await fs.readFile(SCHEMA_PATH, "utf8");
const parsed = JSON.parse(raw);
if (parsed && typeof parsed === "object") return parsed as Schema;
return FALLBACK;
} catch {
return FALLBACK;
}
}
export async function writeSchema(schema: Schema): Promise<void> {
await fs.writeFile(
SCHEMA_PATH,
JSON.stringify(schema, null, 2) + "\n",
"utf8",
);
}
export async function patchRoute(
route: string,
data: { root: any; content: any[] },
): Promise<Schema> {
const current = await readSchema();
const next: Schema = { ...current, [route]: data };
await writeSchema(next);
return next;
}