2026-10-04 16:36:09 +00:00
|
|
|
import { z } from "zod/v4";
|
|
|
|
|
|
|
|
|
|
const title = z.string().min(1).max(100);
|
|
|
|
|
export const FieldTypeSchema = z.enum(["text", "number", "date", "boolean", "choice"]);
|
|
|
|
|
export const TemplateFieldSchema = z.strictObject({ fieldId: z.uuid(), required: z.boolean() });
|
|
|
|
|
export const AssetDefinitionSchema = z.discriminatedUnion("kind", [
|
|
|
|
|
z.strictObject({
|
|
|
|
|
kind: z.literal("field"),
|
|
|
|
|
name: title,
|
|
|
|
|
description: z.string().max(1000),
|
|
|
|
|
type: FieldTypeSchema,
|
|
|
|
|
unit: z.string().max(30),
|
|
|
|
|
choices: z.array(title).max(100),
|
|
|
|
|
}),
|
|
|
|
|
z.strictObject({
|
|
|
|
|
kind: z.literal("template"),
|
|
|
|
|
name: title,
|
|
|
|
|
description: z.string().max(1000),
|
|
|
|
|
fields: z.array(TemplateFieldSchema).min(1).max(100),
|
|
|
|
|
}),
|
2026-10-04 19:04:14 +00:00
|
|
|
z.strictObject({
|
|
|
|
|
kind: z.literal("relation"),
|
|
|
|
|
name: title,
|
|
|
|
|
inverseName: title,
|
|
|
|
|
description: z.string().max(1000),
|
|
|
|
|
symmetric: z.boolean(),
|
|
|
|
|
}),
|
2026-10-04 16:36:09 +00:00
|
|
|
]);
|
|
|
|
|
export type AssetDefinitionSpec = z.infer<typeof AssetDefinitionSchema>;
|
|
|
|
|
export type AssetFieldType = z.infer<typeof FieldTypeSchema>;
|
|
|
|
|
export class AssetCatalogError extends Error {
|
|
|
|
|
constructor(public readonly code: string) {
|
|
|
|
|
super(code);
|
|
|
|
|
}
|
|
|
|
|
}
|