A tool for conquest of ATProto lexicons. https://jsr.io/@hotsocket/lexiconqueror
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5 */
6
7import * as z from "@zod/zod";
8import { did_z, didMethods, didPipe } from "./did_parts.ts";
9
10/** zod codec for getting did method and identifier */
11export const did_parts = z.codec(
12 did_z,
13 z.object({
14 method: didMethods,
15 identifier: z.string(),
16 }),
17 {
18 decode: (str) => {
19 const parts = str.split(":");
20 return {
21 method: parts[1]! as z.infer<typeof didMethods>,
22 identifier: parts[2]!,
23 };
24 },
25 encode: (obj) => didPipe.parse(`did:${obj.method}:${obj.identifier}`),
26 },
27);
28
29/** git input format */
30export const gitInput = z.union([
31 z.url({ protocol: /^git\+https?$/, normalize: true }),
32]);
33
34/** at:// input format */
35export const atInput = z.union([
36 z.templateLiteral(["at://", did_z]),
37 z.templateLiteral(["at://", z.hostname()]),
38]);
39
40/** file: input format */
41export const fileInput = z.union([
42 z.string().regex(/^file:.*/),
43]);
44
45/** zod union of all input formats */
46export const anyInput = z.union([atInput, gitInput, fileInput]);
47
48/** lxq.json format */
49export const config_z = z.object({
50 inputs: z.record(z.string().regex(/^(?!\.).*$/), anyInput),
51 dataDir: z.string(),
52 outputDir: z.string(),
53});