feat: add grouped TechLog route contracts

This commit is contained in:
DongHyeonka
2026-08-15 20:30:32 +09:00
parent 27dda3e0e3
commit adb8613cb9
15 changed files with 887 additions and 67 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
import { PLATFORM_ROUTE_RUNTIME_CONTRACT } from "../contracts/route-runtime-contract.ts";
import type { RouteRuntimeDefinition } from "../contracts/route-runtime-contract.ts";
import { PLATFORM_ROUTE_REGISTRY } from "../contracts/routes.ts";
import type { RouteDefinition } from "../contracts/routes.ts";
import {
composeSchemaRegistry,
PLATFORM_SCHEMA_REGISTRY,
@@ -20,11 +22,11 @@ export const INSTALLED_FEATURE_CONTRACTS = Object.freeze([
export const ROUTE_REGISTRY = Object.freeze({
...PLATFORM_ROUTE_REGISTRY,
...REFERENCE_FEATURE_CONTRACT.routes,
});
}) satisfies Readonly<Record<string, RouteDefinition>>;
export const ROUTE_RUNTIME_CONTRACT = Object.freeze({
...PLATFORM_ROUTE_RUNTIME_CONTRACT,
...REFERENCE_FEATURE_CONTRACT.routeRuntimeContracts,
});
}) satisfies Readonly<Record<string, RouteRuntimeDefinition>>;
export const API_OPERATIONS = composeApiOperations(
INSTALLED_FEATURE_CONTRACTS.map((contract) => contract.apiOperations),
);
@@ -4,10 +4,12 @@ import {
REFERENCE_FEATURE_ROUTE_CODECS,
REFERENCE_FEATURE_ROUTE_RUNTIME,
} from "./reference-feature/presentation/reference-feature-runtime.tsx";
import { TECH_LOG_ROUTE_CODECS } from "./tech-log/presentation/tech-log-route-codecs.ts";
export const ROUTE_CODECS = Object.freeze({
...PLATFORM_ROUTE_CODECS,
...REFERENCE_FEATURE_ROUTE_CODECS,
...TECH_LOG_ROUTE_CODECS,
});
export const ROUTE_RUNTIME = Object.freeze({
@@ -76,6 +76,7 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
REFERENCE_RESOURCE_LIST: Object.freeze({
routeId: "REFERENCE_RESOURCE_LIST",
path: "/examples/reference-resources",
layoutGroup: "PUBLIC",
paramsSchema: null,
searchSchema: "ReferenceResourceListQuery",
access: "session-required",
@@ -89,6 +90,7 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
REFERENCE_RESOURCE_DETAIL: Object.freeze({
routeId: "REFERENCE_RESOURCE_DETAIL",
path: "/examples/reference-resources/:resourceId",
layoutGroup: "PUBLIC",
paramsSchema: "ReferenceResourceParams",
searchSchema: null,
access: "session-required",
@@ -102,6 +104,7 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
REFERENCE_RESOURCE_FORM: Object.freeze({
routeId: "REFERENCE_RESOURCE_FORM",
path: "/examples/reference-resources/new",
layoutGroup: "PUBLIC",
paramsSchema: null,
searchSchema: null,
access: "session-required",
@@ -115,6 +118,7 @@ export const REFERENCE_FEATURE_CONTRACT = Object.freeze({
REFERENCE_RESOURCE_STATUS: Object.freeze({
routeId: "REFERENCE_RESOURCE_STATUS",
path: "/examples/reference-resources/status",
layoutGroup: "PUBLIC",
paramsSchema: null,
searchSchema: null,
access: "session-required",
@@ -0,0 +1,24 @@
import {
TECH_LOG_ROUTE_REGISTRY,
type TechLogRouteId,
} from "./tech-log-route-contract.ts";
export type TechLogRouteMessageKey =
| `route.${TechLogRouteId}.title`
| `route.${TechLogRouteId}.navigation`;
function createCatalog(): Readonly<Record<TechLogRouteMessageKey, string>> {
return Object.freeze(
Object.fromEntries(
Object.values(TECH_LOG_ROUTE_REGISTRY).flatMap((definition) => [
[`route.${definition.routeId}.title`, definition.title],
[`route.${definition.routeId}.navigation`, definition.title],
]),
),
) as Readonly<Record<TechLogRouteMessageKey, string>>;
}
export const TECH_LOG_MESSAGE_CATALOGS = Object.freeze({
"ko-KR": createCatalog(),
"en-US": createCatalog(),
});
@@ -0,0 +1,95 @@
import type {
RouteCodecId,
RouteRuntimeDefinition,
} from "../../../contracts/route-runtime-contract.ts";
import type {
RouteDefinition,
RouteLayoutGroup,
} from "../../../contracts/routes.ts";
type RouteSpec = Readonly<{
routeId: string;
path: string;
layoutGroup: RouteLayoutGroup;
paramsSchema: RouteCodecId | null;
searchSchema: RouteCodecId | null;
title: string;
navigationLabel: string | null;
navigationOrder: number | null;
}>;
const defineSpec = <const Spec extends RouteSpec>(spec: Spec): Spec => spec;
const TECH_LOG_ROUTE_SPECS = [
defineSpec({ routeId: "TECH_LOG_HOME", path: "/", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: "TechLogHomeSearch", title: "TechLog", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_EXPLORE", path: "/explore", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: "TechLogExploreSearch", title: "탐색", navigationLabel: "탐색", navigationOrder: 10 }),
defineSpec({ routeId: "TECH_LOG_EXPLORE_KIND", path: "/explore/:kind", layoutGroup: "PUBLIC", paramsSchema: "TechLogExploreKindParams", searchSchema: "TechLogExploreKindSearch", title: "유형별 탐색", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_CASE", path: "/cases/:slug", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: "TechLogCaseStateSearch", title: "Case", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_REFERENCE", path: "/references/:slug", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "Reference", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_QUESTION", path: "/questions/:slug", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "Open Question", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_TOPIC", path: "/topics/:slug", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "Topic", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_PROJECTS", path: "/projects", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: null, title: "프로젝트", navigationLabel: "프로젝트", navigationOrder: 20 }),
defineSpec({ routeId: "TECH_LOG_PROJECT", path: "/projects/:slug", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "프로젝트", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_PROJECT_RECORDS", path: "/projects/:slug/records", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "프로젝트 기록", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_PROJECT_DECISIONS", path: "/projects/:slug/decisions", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "프로젝트 결정", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_PROJECT_ACTIVITY", path: "/projects/:slug/activity", layoutGroup: "PUBLIC", paramsSchema: "TechLogSlugParams", searchSchema: null, title: "프로젝트 활동", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_RELEASES", path: "/releases", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: null, title: "변경 기록", navigationLabel: "변경 기록", navigationOrder: 30 }),
defineSpec({ routeId: "TECH_LOG_RELEASE", path: "/releases/:version", layoutGroup: "PUBLIC", paramsSchema: "TechLogVersionParams", searchSchema: null, title: "변경 기록", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_PROFILE", path: "/profile", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: null, title: "프로필", navigationLabel: "프로필", navigationOrder: 40 }),
defineSpec({ routeId: "TECH_LOG_SEARCH", path: "/search", layoutGroup: "PUBLIC", paramsSchema: null, searchSchema: "TechLogSearchQuery", title: "검색", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_HOME", path: "/studio", layoutGroup: "STUDIO", paramsSchema: null, searchSchema: null, title: "TechLog Studio", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENTS", path: "/studio/documents", layoutGroup: "STUDIO", paramsSchema: null, searchSchema: null, title: "작업본", navigationLabel: "작업본", navigationOrder: 10 }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENT_NEW", path: "/studio/documents/new", layoutGroup: "STUDIO", paramsSchema: null, searchSchema: null, title: "새 문서", navigationLabel: "새 문서", navigationOrder: 30 }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENT_EDIT", path: "/studio/documents/:id/edit", layoutGroup: "STUDIO", paramsSchema: "TechLogDocumentIdParams", searchSchema: null, title: "문서 편집", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENT_VALIDATION", path: "/studio/documents/:id/validation", layoutGroup: "STUDIO", paramsSchema: "TechLogDocumentIdParams", searchSchema: null, title: "문서 검증", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENT_PREVIEW", path: "/studio/documents/:id/preview", layoutGroup: "STUDIO", paramsSchema: "TechLogDocumentIdParams", searchSchema: null, title: "Public Preview", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_DOCUMENT_PUBLISH", path: "/studio/documents/:id/publish", layoutGroup: "STUDIO", paramsSchema: "TechLogDocumentIdParams", searchSchema: null, title: "게시", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_PUBLICATIONS", path: "/studio/publications", layoutGroup: "STUDIO", paramsSchema: null, searchSchema: null, title: "게시 기록", navigationLabel: "게시 기록", navigationOrder: 20 }),
defineSpec({ routeId: "TECH_LOG_STUDIO_PUBLICATION_PREVIEW", path: "/studio/publications/:publicationEventId/preview", layoutGroup: "STUDIO", paramsSchema: "TechLogPublicationEventIdParams", searchSchema: null, title: "게시 Snapshot", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "TECH_LOG_STUDIO_NOT_FOUND", path: "/studio/*", layoutGroup: "STUDIO", paramsSchema: "TechLogStudioSplat", searchSchema: null, title: "Studio 화면을 찾을 수 없습니다", navigationLabel: null, navigationOrder: null }),
defineSpec({ routeId: "NOT_FOUND", path: "*", layoutGroup: "PUBLIC", paramsSchema: "NotFoundSplat", searchSchema: null, title: "페이지를 찾을 수 없습니다.", navigationLabel: null, navigationOrder: null }),
] as const;
export type TechLogRouteId = (typeof TECH_LOG_ROUTE_SPECS)[number]["routeId"];
function chunkId(routeId: TechLogRouteId): string {
return routeId === "NOT_FOUND"
? "route-not-found"
: `route-${routeId.toLowerCase().replaceAll("_", "-")}`;
}
export const TECH_LOG_ROUTE_REGISTRY = Object.freeze(
Object.fromEntries(
TECH_LOG_ROUTE_SPECS.map((spec) => [
spec.routeId,
Object.freeze({
...spec,
access: "public",
loadingSurface: spec.path.endsWith("*") ? "none" : "app-shell",
errorSurface: spec.path.endsWith("*")
? "not-found"
: "feature-boundary",
chunkId: chunkId(spec.routeId),
} satisfies RouteDefinition),
]),
),
) as Readonly<Record<TechLogRouteId, RouteDefinition>>;
export const TECH_LOG_ROUTE_RUNTIME_CONTRACT = Object.freeze(
Object.fromEntries(
TECH_LOG_ROUTE_SPECS.map((spec) => [
spec.routeId,
Object.freeze({
routeId: spec.routeId,
moduleId: chunkId(spec.routeId),
paramsCodec: spec.paramsSchema ?? "none",
searchCodec: spec.searchSchema ?? "none",
} satisfies RouteRuntimeDefinition),
]),
),
) as Readonly<Record<TechLogRouteId, RouteRuntimeDefinition>>;
export const TECH_LOG_ROUTE_CONTRACT = Object.freeze({
routes: TECH_LOG_ROUTE_REGISTRY,
routeRuntimeContracts: TECH_LOG_ROUTE_RUNTIME_CONTRACT,
});
@@ -0,0 +1,56 @@
import { z } from "zod";
function first(value: unknown): unknown {
return Array.isArray(value) ? value[0] : value;
}
const optionalString = z.preprocess(first, z.string().optional());
const optionalSelection = z.preprocess((value) => {
const selected = first(value);
if (typeof selected !== "string") return selected;
const normalized = selected.trim();
return normalized || undefined;
}, z.string().optional());
const nonEmptyParams = <Key extends string>(key: Key) =>
z.object({ [key]: z.string().min(1) } as Record<Key, z.ZodString>).strict();
export const TECH_LOG_ROUTE_CODECS = Object.freeze({
TechLogExploreKindParams: nonEmptyParams("kind"),
TechLogSlugParams: nonEmptyParams("slug"),
TechLogVersionParams: nonEmptyParams("version"),
TechLogDocumentIdParams: nonEmptyParams("id"),
TechLogPublicationEventIdParams: nonEmptyParams("publicationEventId"),
TechLogStudioSplat: z
.object({ "*": z.string().min(1).optional() })
.strict(),
TechLogHomeSearch: z
.object({
focus: optionalString,
state: optionalString,
})
.strip(),
TechLogExploreSearch: z
.object({
type: optionalString,
topic: optionalSelection,
project: optionalSelection,
})
.strip(),
TechLogExploreKindSearch: z
.object({
topic: optionalSelection,
project: optionalSelection,
})
.strip(),
TechLogSearchQuery: z
.object({
q: optionalSelection,
})
.strip(),
TechLogCaseStateSearch: z
.object({
state: optionalString,
})
.strip(),
} as const);