/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import * as z from "@zod/zod"; import { did_z, didMethods, didPipe } from "./did_parts.ts"; /** zod codec for getting did method and identifier */ export const did_parts = z.codec( did_z, z.object({ method: didMethods, identifier: z.string(), }), { decode: (str) => { const parts = str.split(":"); return { method: parts[1]! as z.infer, identifier: parts[2]!, }; }, encode: (obj) => didPipe.parse(`did:${obj.method}:${obj.identifier}`), }, ); /** git input format */ export const gitInput = z.union([ z.url({ protocol: /^git\+https?$/, normalize: true }), ]); /** at:// input format */ export const atInput = z.union([ z.templateLiteral(["at://", did_z]), z.templateLiteral(["at://", z.hostname()]), ]); /** file: input format */ export const fileInput = z.union([ z.string().regex(/^file:.*/), ]); /** zod union of all input formats */ export const anyInput = z.union([atInput, gitInput, fileInput]); /** lxq.json format */ export const config_z = z.object({ inputs: z.record(z.string().regex(/^(?!\.).*$/), anyInput), dataDir: z.string(), outputDir: z.string(), });