server/packages/kit/schema.ts

102 lines
2.9 KiB
TypeScript
Raw Normal View History

import { z } from "zod/v4";
export const manifestSchema = z.object({
2025-05-01 16:27:34 +02:00
// biome-ignore lint/style/useNamingConvention: JSON schema requires this to be $schema
$schema: z.string().optional(),
name: z.string().min(3).max(100),
version: z
.string()
.regex(
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm,
"Version must be valid SemVer string",
),
description: z.string().min(1).max(4096),
authors: z
.array(
z.object({
name: z.string().min(1).max(100),
email: z.email().optional(),
url: z.url().optional(),
}),
)
.optional(),
repository: z
.object({
type: z
.enum([
"git",
"svn",
"mercurial",
"bzr",
"darcs",
"mtn",
"cvs",
"fossil",
"bazaar",
"arch",
"tla",
"archie",
"monotone",
"perforce",
"sourcevault",
"plastic",
"clearcase",
"accurev",
"surroundscm",
"bitkeeper",
"other",
])
.optional(),
url: z.url().optional(),
})
.optional(),
});
export type Manifest = {
name: string;
version: string;
description: string;
authors?:
| {
name: string;
email?: string | undefined;
url?: string | undefined;
}[]
| undefined;
repository?:
| {
type?:
| "git"
| "svn"
| "mercurial"
| "bzr"
| "darcs"
| "mtn"
| "cvs"
| "fossil"
| "bazaar"
| "arch"
| "tla"
| "archie"
| "monotone"
| "perforce"
| "sourcevault"
| "plastic"
| "clearcase"
| "accurev"
| "surroundscm"
| "bitkeeper"
| "other"
| undefined;
url?: string | undefined;
}
| undefined;
};
// This is a type guard to ensure that the schema and the type are in sync
function assert<_T extends never>() {
// ...
}
type TypeEqualityGuard<A, B> = Exclude<A, B> | Exclude<B, A>;
assert<TypeEqualityGuard<Manifest, z.infer<typeof manifestSchema>>>();