Further cleanup
This commit is contained in:
parent
ffaeb4841e
commit
dfc65dacfa
2 changed files with 35 additions and 29 deletions
|
@ -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";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue