Files
bookmanager/src/lib/kinds.ts
T
bobbanandClaude Sonnet 5.5 8a0e93f559 Automatiska ID, nya registertyper och ID-register
- Löpande ID per bok och typ enligt idöversikten (KI, FI, BI, DI, LI, UI, FD, RI,
  RD, SI, REI, PI, SCI, KD-R_/KD-E_), prefix samlade i src/lib/ids.ts
- Nya typer: Fordon, Skiss, Research, Referens, Appar, Hemsidor (grupp Register)
- Sida med ID-register med sök och filter
- Migration 0003_auto_ids med backfill av befintliga poster
- ID visas i listor, postsidor, kartpanel och scheman
- README och Register/-mallar

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-22 22:31:50 +02:00

65 lines
2.6 KiB
TypeScript

import type { EntityKind } from "@prisma/client";
export type KindInfo = {
kind: EntityKind;
slug: string;
color: string;
// world = berättelsens värld, register = stödregister (fordon, research, skisser ...)
group: "world" | "register";
};
// Ordningen styr menyer och översikt.
export const KINDS: KindInfo[] = [
{ kind: "CHARACTER", slug: "characters", color: "blue", group: "world" },
{ kind: "PET", slug: "pets", color: "orange", group: "world" },
{ kind: "HOME", slug: "homes", color: "green", group: "world" },
{ kind: "PLACE", slug: "places", color: "red", group: "world" },
{ kind: "COMPANY", slug: "companies", color: "purple", group: "world" },
{ kind: "PREMISES", slug: "premises", color: "teal", group: "world" },
{ kind: "EDUCATION", slug: "education", color: "cyan", group: "world" },
{ kind: "SCENARIO", slug: "scenarios", color: "pink", group: "world" },
{ kind: "VEHICLE", slug: "vehicles", color: "indigo", group: "register" },
{ kind: "SKETCH", slug: "sketches", color: "azure", group: "register" },
{ kind: "RESEARCH", slug: "research", color: "lime", group: "register" },
{ kind: "REFERENCE", slug: "references", color: "yellow", group: "register" },
{ kind: "APP", slug: "apps", color: "dark", group: "register" },
{ kind: "WEBSITE", slug: "websites", color: "secondary", group: "register" },
];
export const KIND_BY_SLUG = new Map(KINDS.map((k) => [k.slug, k]));
export const KIND_INFO = Object.fromEntries(KINDS.map((k) => [k.kind, k])) as Record<EntityKind, KindInfo>;
export function parseKind(value: unknown): EntityKind | null {
return typeof value === "string" && value in KIND_INFO ? (value as EntityKind) : null;
}
// Mallar finns för alla typer och dessutom för relationer.
export type TemplateKind = EntityKind | "RELATION";
export const RELATION_SLUG = "relations";
export function parseTemplateKind(value: unknown): TemplateKind | null {
return value === "RELATION" ? "RELATION" : parseKind(value);
}
export function templateSlug(kind: TemplateKind): string {
return kind === "RELATION" ? RELATION_SLUG : KIND_INFO[kind].slug;
}
export function templateKindFromSlug(slug: string): TemplateKind | null {
return slug === RELATION_SLUG ? "RELATION" : (KIND_BY_SLUG.get(slug)?.kind ?? null);
}
// Typer som kan ha arbetsplats i scheman
export const WORKPLACE_KINDS: EntityKind[] = ["COMPANY", "PREMISES", "PLACE", "EDUCATION"];
export const MARKER_COLORS: Record<string, string> = {
blue: "#206bc4",
red: "#d63939",
green: "#2fb344",
orange: "#f76707",
purple: "#ae3ec9",
pink: "#d6336c",
teal: "#0ca678",
yellow: "#f59f00",
};