diff --git a/src/core/binding.ts b/src/core/binding.ts index d0528b5..1a768e5 100644 --- a/src/core/binding.ts +++ b/src/core/binding.ts @@ -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; - // 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 { 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 diff --git a/src/core/sources.ts b/src/core/sources.ts index 0ab1495..5c38e4b 100644 --- a/src/core/sources.ts +++ b/src/core/sources.ts @@ -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; + +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";