Skip to content

Commit f759e87

Browse files
committed
不要なsafeParseをparseに、不要な再exportを削除
1 parent 2d6a4d9 commit f759e87

File tree

9 files changed

+30
-38
lines changed

9 files changed

+30
-38
lines changed

app/(docs)/@docs/[lang]/[pageId]/chatForm.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { useState, FormEvent, useEffect } from "react";
77
// QuestionExampleParams,
88
// } from "../actions/questionExample";
99
// import { getLanguageName } from "../pagesList";
10-
import { DynamicMarkdownSection } from "./pageContent";
1110
import { useEmbedContext } from "@/terminal/embedContext";
12-
import { PagePath } from "@/lib/docs";
11+
import { DynamicMarkdownSection, PagePath } from "@/lib/docs";
1312
import { useRouter } from "next/navigation";
1413
import { ChatStreamEvent } from "@/api/chat/route";
1514
import { useStreamingChatContext } from "@/(docs)/streamingChatContext";

app/(docs)/@docs/[lang]/[pageId]/pageContent.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import Link from "next/link";
1919
import { useChatId } from "@/(docs)/chatAreaState";
2020
import { ChatWithMessages } from "@/lib/chatHistory";
2121

22-
export type { DynamicMarkdownSection };
23-
2422
interface PageContentProps {
2523
splitMdContent: MarkdownSection[];
2624
langEntry: LanguageEntry;

app/actions/deleteChat.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
import { z } from "zod";
44
import { deleteChat, initContext } from "@/lib/chatHistory";
55

6-
const chatIdSchema = z.string().uuid();
7-
86
export async function deleteChatAction(chatId: string) {
9-
const parsed = chatIdSchema.safeParse(chatId);
10-
if (!parsed.success) {
11-
throw new Error(parsed.error.issues.map((e) => e.message).join(", "));
12-
}
7+
chatId = z.uuid().parse(chatId);
138
const ctx = await initContext();
14-
await deleteChat(parsed.data, ctx);
9+
await deleteChat(chatId, ctx);
1510
}

app/actions/getRedirectFromChat.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ import { LangId, PageSlug } from "@/lib/docs";
66
import { chat, section } from "@/schema/chat";
77
import { and, eq } from "drizzle-orm";
88

9-
const chatIdSchema = z.string().uuid();
10-
119
export async function getRedirectFromChat(chatId: string): Promise<string> {
12-
const parsed = chatIdSchema.safeParse(chatId);
13-
if (!parsed.success) {
14-
throw new Error(parsed.error.issues.map((e) => e.message).join(", "));
15-
}
10+
chatId = z.uuid().parse(chatId);
11+
1612
const { drizzle, userId } = await initContext();
1713
if (!userId) {
1814
throw new Error("Not authenticated");
1915
}
2016

2117
const chatData = (await drizzle.query.chat.findFirst({
22-
where: and(eq(chat.chatId, parsed.data), eq(chat.userId, userId)),
18+
where: and(eq(chat.chatId, chatId), eq(chat.userId, userId)),
2319
with: {
2420
section: true,
2521
},

app/api/chat/route.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
PagePathSchema,
1414
SectionId,
1515
} from "@/lib/docs";
16-
import { ReplCommandSchema, ReplOutputSchema } from "@my-code/runtime/interface";
16+
import {
17+
ReplCommandSchema,
18+
ReplOutputSchema,
19+
} from "@my-code/runtime/interface";
1720
import { z } from "zod";
1821

1922
const ChatParamsSchema = z.object({
@@ -25,8 +28,6 @@ const ChatParamsSchema = z.object({
2528
execResults: z.record(z.string(), z.array(ReplOutputSchema)),
2629
});
2730

28-
type ChatParams = z.output<typeof ChatParamsSchema>;
29-
3031
export type ChatStreamEvent =
3132
| { type: "chat"; chatId: string; sectionId: string }
3233
| { type: "chunk"; text: string }
@@ -41,14 +42,16 @@ export async function POST(request: NextRequest) {
4142

4243
const parseResult = ChatParamsSchema.safeParse(await request.json());
4344
if (!parseResult.success) {
44-
return new Response(
45-
parseResult.error.issues.map((e) => e.message).join(", "),
46-
{ status: 400 }
47-
);
45+
return new Response(JSON.stringify(parseResult.error), { status: 400 });
4846
}
49-
const params: ChatParams = parseResult.data;
50-
const { path, userQuestion, sectionContent, replOutputs, files, execResults } =
51-
params;
47+
const {
48+
path,
49+
userQuestion,
50+
sectionContent,
51+
replOutputs,
52+
files,
53+
execResults,
54+
} = parseResult.data;
5255

5356
const pagesList = await getPagesList();
5457
const langName = pagesList.find((lang) => lang.id === path.lang)?.name;
@@ -217,7 +220,7 @@ export async function POST(request: NextRequest) {
217220
prompt.join("\n")
218221
)) {
219222
console.log("Received chunk:", [chunk]);
220-
223+
221224
fullText += chunk;
222225

223226
if (!headerParsed) {
@@ -309,9 +312,7 @@ export async function POST(request: NextRequest) {
309312
await addMessagesAndDiffs(
310313
chatId,
311314
path,
312-
[
313-
{ role: "ai", content: cleanMessage },
314-
],
315+
[{ role: "ai", content: cleanMessage }],
315316
diffRaw,
316317
context
317318
);

app/lib/docs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const PagePathSchema = z.object({
2525
lang: z.string().transform((s) => s as LangId),
2626
page: z.string().transform((s) => s as PageSlug),
2727
});
28-
export type PagePath = z.output<typeof PagePathSchema>;
28+
export interface PagePath {
29+
lang: LangId;
30+
page: PageSlug;
31+
}
2932

3033
export const MarkdownSectionSchema = z.object({
3134
/**
@@ -68,7 +71,9 @@ export const DynamicMarkdownSectionSchema = MarkdownSectionSchema.extend({
6871
replacedContent: z.string(),
6972
replacedRange: z.array(ReplacedRangeSchema),
7073
});
71-
export type DynamicMarkdownSection = z.output<typeof DynamicMarkdownSectionSchema>;
74+
export type DynamicMarkdownSection = z.output<
75+
typeof DynamicMarkdownSectionSchema
76+
>;
7277

7378
/**
7479
* 各言語のindex.ymlから読み込んだデータにid,index等を追加したデータ型

app/markdown/markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import remarkCjkFriendly from "remark-cjk-friendly";
55
import {
66
MultiHighlightTag,
77
remarkMultiHighlight,
8-
ReplacedRange,
98
} from "./multiHighlight";
109
import { Heading } from "./heading";
1110
import { AutoCodeBlock } from "./codeBlock";
11+
import { ReplacedRange } from "@/lib/docs";
1212

1313
export function StyledMarkdown(props: {
1414
content: string;

app/markdown/multiHighlight.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { useChatId } from "@/(docs)/chatAreaState";
88
import Link from "next/link";
99
import type { ReplacedRange } from "@/lib/docs";
1010

11-
export type { ReplacedRange };
1211
export const remarkMultiHighlight: Plugin<[ReplacedRange[]], Root> = (
1312
replacedRange?: ReplacedRange[]
1413
) => {

app/sidebar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import Link from "next/link";
33
import { usePathname } from "next/navigation";
4-
import { LangId, LanguageEntry, PagePath, PageSlug } from "@/lib/docs";
4+
import { DynamicMarkdownSection, LangId, LanguageEntry, PagePath, PageSlug } from "@/lib/docs";
55
import { AccountMenu } from "./accountMenu";
66
import { ThemeToggle } from "./themeToggle";
77
import {
@@ -15,7 +15,6 @@ import {
1515
import clsx from "clsx";
1616
import { LanguageIcon } from "@/terminal/icons";
1717
import { RuntimeLang } from "@my-code/runtime/languages";
18-
import { DynamicMarkdownSection } from "./(docs)/@docs/[lang]/[pageId]/pageContent";
1918

2019
export interface ISidebarMdContext {
2120
loadedPath: PagePath | null;

0 commit comments

Comments
 (0)