Further cleanup

This commit is contained in:
Endeavorance 2025-04-04 14:07:59 -04:00
parent ffaeb4841e
commit dfc65dacfa
2 changed files with 35 additions and 29 deletions

View file

@ -7,21 +7,12 @@ import { type MusePlugin, loadPlugin } from "./plugins";
import {
type MuseEntry,
type MuseSource,
SourceSchema,
loadFromSource,
parseMuseFile,
sourceShorthandToSource,
} from "./sources";
const SourceSchema = z.union([
z.object({
file: z.string(),
}),
z.object({
url: z.string().url(),
}),
]);
type SourceShorthand = z.infer<typeof SourceSchema>;
// Function to parse an unknown object into parts of a binding
const BindingSchema = z.object({
contentKey: z.string().default("content"),
@ -65,24 +56,6 @@ export interface Binding<MetaShape = UnknownRecord> {
readonly options: UnknownRecord;
}
function sourceShorthandToSource(shorthand: SourceShorthand): MuseSource {
if ("file" in shorthand) {
return {
location: shorthand.file,
type: "file",
};
}
if ("url" in shorthand) {
return {
location: shorthand.url,
type: "url",
};
}
throw new MuseError("Invalid source shorthand");
}
/**
* Given a path, find the binding file
* If the path is to a directory, check for a binding inside

View file

@ -1,6 +1,39 @@
import { Glob } from "bun";
import { type LoadedFile, loadFileContent } from "./files";
import { type UnknownRecord, autoParseEntry } from "./records";
import { z } from "zod";
import { MuseError } from "#errors";
export const SourceSchema = z.union([
z.object({
file: z.string(),
}),
z.object({
url: z.string().url(),
}),
]);
export type SourceShorthand = z.infer<typeof SourceSchema>;
export function sourceShorthandToSource(
shorthand: SourceShorthand,
): MuseSource {
if ("file" in shorthand) {
return {
location: shorthand.file,
type: "file",
};
}
if ("url" in shorthand) {
return {
location: shorthand.url,
type: "url",
};
}
throw new MuseError("Invalid source shorthand");
}
export type SourceType = "file" | "url";