Skip to content

Commit

Permalink
Refactor import statements to use type declaration for better code re…
Browse files Browse the repository at this point in the history
…adability and maintainability.
  • Loading branch information
yasuaki640 committed Jun 2, 2024
1 parent 12bec30 commit 1f720a4
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { DrizzleD1Database } from "drizzle-orm/d1";
import { beforeEach, describe, expect, it, vi } from "vitest";
import app from "./index";
import {
import type {
getMessagesByRoomId,
insertMessage,
} from "./repositories/message-repository";
import {
getAllRooms,
getRoom,
insertRoom,
type getRoom,
type insertRoom,
} from "./repositories/room-repository";
import { fetchCompletion } from "./utils/openai-client";
import type { fetchCompletion } from "./utils/openai-client";

const MOCK_BINDINGS = {
USERNAME: "test",
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
insertRoom,
updateRoom,
} from "./repositories/room-repository";
import { Messages } from "./schema";
import type { Messages } from "./schema";
import type { AppEnv } from "./types";
import { parseMarkdown } from "./utils/markdown";
import { fetchCompletion } from "./utils/openai-client";
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/basic-auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { basicAuth } from "hono/basic-auth";
import { createMiddleware } from "hono/factory";

import { AppEnv } from "../types";
import type { AppEnv } from "../types";

export const BasicAuthMiddleware = createMiddleware<AppEnv>(async (c, next) => {
const auth = basicAuth({
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/openai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMiddleware } from "hono/factory";
import OpenAI from "openai";
import { AppEnv } from "../types";
import type { AppEnv } from "../types";

export const OpenaiMiddleware = createMiddleware<AppEnv>(async (c, next) => {
const client = new OpenAI({
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/message-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { eq } from "drizzle-orm";
import { DrizzleD1Database } from "drizzle-orm/d1";
import type { DrizzleD1Database } from "drizzle-orm/d1";
import { Messages } from "../schema";

export const insertMessage = async (
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/room-repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { desc, eq } from "drizzle-orm";
import { DrizzleD1Database } from "drizzle-orm/d1";
import type { DrizzleD1Database } from "drizzle-orm/d1";
import { Rooms } from "../schema";

export const insertRoom = async (db: DrizzleD1Database, roomId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OpenAI from "openai";
import type OpenAI from "openai";

export type Bindings = {
USERNAME: string;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/format-tilte.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { Rooms } from "../schema";
import type { Rooms } from "../schema";
import { formatTitle } from "./format-tilte";

describe("formatTitle", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/format-tilte.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Rooms } from "../schema";
import type { Rooms } from "../schema";

export const formatTitle = (room: typeof Rooms.$inferSelect, len = 20) => {
if (!room.roomTitle) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/openai-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import OpenAI from "openai";
import type OpenAI from "openai";
import type { ChatCompletionMessageParam } from "openai/resources";

export const fetchCompletion = async (
Expand Down
2 changes: 1 addition & 1 deletion src/views/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "hono/dist/types/jsx";
import type { FC } from "hono/dist/types/jsx";

export const Layout: FC = ({ children }) => (
<html lang={"ja"}>
Expand Down
2 changes: 1 addition & 1 deletion src/views/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "hono/dist/types/jsx";
import type { FC } from "hono/dist/types/jsx";

type Props = { message?: string };

Expand Down
6 changes: 3 additions & 3 deletions src/views/Room.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from "hono/dist/types/jsx";
import { Messages, Rooms } from "../schema";
import type { FC } from "hono/dist/types/jsx";
import type { Messages, Rooms } from "../schema";
import { formatTitle } from "../utils/format-tilte";

type Props = {
Expand Down Expand Up @@ -30,7 +30,7 @@ export const Room: FC<{ props: Props }> = ({ props }) => (
<hr />
{props.message.length === 0 && <p>No messages.</p>}
{props.message.map((message) => (
<div>
<div key={message.messageId}>
<p>{message.messageCreated}</p>
<p>{message.sender}</p>
{/* biome-ignore lint: lint/security/noDangerouslySetInnerHtml */}
Expand Down
6 changes: 3 additions & 3 deletions src/views/RoomList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from "hono/dist/types/jsx";
import { Rooms } from "../schema";
import type { FC } from "hono/dist/types/jsx";
import type { Rooms } from "../schema";
import { formatTitle } from "../utils/format-tilte";

type Props = {
Expand All @@ -21,7 +21,7 @@ export const RoomList: FC<{ props: Props }> = ({ props }) => (
</thead>
<tbody>
{props.rooms.map((room) => (
<tr>
<tr key={room.roomId}>
<td>{formatTitle(room)}</td>
<td>{room.roomCreated}</td>
<td>{room.roomUpdated}</td>
Expand Down
2 changes: 1 addition & 1 deletion src/views/Top.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from "hono/dist/types/jsx";
import type { FC } from "hono/dist/types/jsx";

export const Top: FC = () => (
<>
Expand Down

0 comments on commit 1f720a4

Please sign in to comment.