From f81cc391e771e1a9ee9783800658b348b0baee1b Mon Sep 17 00:00:00 2001 From: solufa Date: Tue, 9 Jul 2024 16:52:32 +0900 Subject: [PATCH] refactor: move common files under common dir --- client/common | 1 + client/features/tasks/TaskList.tsx | 4 ++-- client/features/ws/AuthedWebSocket.tsx | 4 ++-- client/hooks/useUser.ts | 2 +- client/layouts/Layout.tsx | 2 +- client/layouts/basicHeader/BasicHeader.tsx | 4 ++-- client/pages/_app.page.tsx | 2 +- client/pages/_document.page.tsx | 2 +- client/pages/login/index.page.tsx | 2 +- server/api/private/hooks.ts | 2 +- server/api/private/me/index.ts | 2 +- server/api/private/tasks/_taskId@string/index.ts | 2 +- server/api/private/tasks/di/index.ts | 2 +- server/api/private/tasks/index.ts | 4 ++-- server/{api/@constants/index.ts => common/constants.ts} | 0 server/{api/@types => common/types}/brandedId.ts | 2 +- server/{api/@types => common/types}/task.ts | 2 +- server/{api/@types => common/types}/user.ts | 0 server/{api/@types => common/types}/websocket.ts | 0 server/{api/@validators => common/validators}/task.ts | 0 server/domain/task/event/taskEvent.ts | 6 +++--- server/domain/task/model/taskEntity.ts | 2 +- server/domain/task/model/taskMethod.ts | 6 +++--- server/domain/task/repository/taskQuery.ts | 2 +- server/domain/task/service/taskValidator.ts | 2 +- server/domain/task/service/toTaskDto.ts | 2 +- server/domain/task/useCase/taskUseCase.ts | 6 +++--- server/domain/user/model/userEntity.ts | 2 +- server/domain/user/service/toUserDto.ts | 2 +- server/domain/user/useCase/userUseCase.ts | 2 +- server/service/app.ts | 2 +- server/service/brandedId.ts | 4 ++-- server/service/types.ts | 2 +- server/service/websocket.ts | 6 +++--- server/tests/api/apiClient.ts | 2 +- server/tests/api/private/di.test.ts | 4 ++-- server/tests/api/private/tasks.test.ts | 4 ++-- server/tests/api/utils.ts | 2 +- server/tsconfig.json | 9 +-------- tsconfig.json | 3 +-- 40 files changed, 51 insertions(+), 58 deletions(-) create mode 120000 client/common rename server/{api/@constants/index.ts => common/constants.ts} (100%) rename server/{api/@types => common/types}/brandedId.ts (84%) rename server/{api/@types => common/types}/task.ts (93%) rename server/{api/@types => common/types}/user.ts (100%) rename server/{api/@types => common/types}/websocket.ts (100%) rename server/{api/@validators => common/validators}/task.ts (100%) diff --git a/client/common b/client/common new file mode 120000 index 0000000..c1298ba --- /dev/null +++ b/client/common @@ -0,0 +1 @@ +../server/common \ No newline at end of file diff --git a/client/features/tasks/TaskList.tsx b/client/features/tasks/TaskList.tsx index 38b5e3d..a615c12 100644 --- a/client/features/tasks/TaskList.tsx +++ b/client/features/tasks/TaskList.tsx @@ -1,5 +1,5 @@ -import type { TaskDto } from 'api/@types/task'; -import { labelValidator } from 'api/@validators/task'; +import type { TaskDto } from 'common/types/task'; +import { labelValidator } from 'common/validators/task'; import { Loading } from 'components/loading/Loading'; import { usePickedLastMsg } from 'features/ws/AuthedWebSocket'; import { useAlert } from 'hooks/useAlert'; diff --git a/client/features/ws/AuthedWebSocket.tsx b/client/features/ws/AuthedWebSocket.tsx index 7da392c..50a188c 100644 --- a/client/features/ws/AuthedWebSocket.tsx +++ b/client/features/ws/AuthedWebSocket.tsx @@ -1,5 +1,5 @@ -import { IS_PROD, WS_PATH, WS_PING, WS_PONG } from 'api/@constants'; -import type { WebSocketData } from 'api/@types/websocket'; +import { IS_PROD, WS_PATH, WS_PING, WS_PONG } from 'common/constants'; +import type { WebSocketData } from 'common/types/websocket'; import { atom, useAtom } from 'jotai'; import { useEffect, useRef } from 'react'; import useWebSocket from 'react-use-websocket'; diff --git a/client/hooks/useUser.ts b/client/hooks/useUser.ts index 99da49d..ed24a71 100644 --- a/client/hooks/useUser.ts +++ b/client/hooks/useUser.ts @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import { atom, useAtom } from 'jotai'; import { useCallback } from 'react'; diff --git a/client/layouts/Layout.tsx b/client/layouts/Layout.tsx index 6fe6f65..8fbcb98 100644 --- a/client/layouts/Layout.tsx +++ b/client/layouts/Layout.tsx @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import { Loading } from 'components/loading/Loading'; import { useLoading } from 'components/loading/useLoading'; import { AuthedWebSocket } from 'features/ws/AuthedWebSocket'; diff --git a/client/layouts/basicHeader/BasicHeader.tsx b/client/layouts/basicHeader/BasicHeader.tsx index a1d4f58..d5c0861 100644 --- a/client/layouts/basicHeader/BasicHeader.tsx +++ b/client/layouts/basicHeader/BasicHeader.tsx @@ -1,7 +1,7 @@ import { AccountSettings } from '@aws-amplify/ui-react'; -import { APP_NAME } from 'api/@constants'; -import type { UserDto } from 'api/@types/user'; import { signOut } from 'aws-amplify/auth'; +import { APP_NAME } from 'common/constants'; +import type { UserDto } from 'common/types/user'; import { Spacer } from 'components/Spacer'; import { HumanIcon } from 'components/icons/HumanIcon'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'components/modal/Modal'; diff --git a/client/pages/_app.page.tsx b/client/pages/_app.page.tsx index 8dea717..43efa67 100644 --- a/client/pages/_app.page.tsx +++ b/client/pages/_app.page.tsx @@ -1,8 +1,8 @@ import { Authenticator, translations } from '@aws-amplify/ui-react'; import '@aws-amplify/ui-react/styles.css'; -import { APP_NAME } from 'api/@constants'; import { Amplify } from 'aws-amplify'; import { I18n } from 'aws-amplify/utils'; +import { APP_NAME } from 'common/constants'; import { AuthLoader } from 'features/auth/AuthLoader'; import type { AppProps } from 'next/app'; import dynamic from 'next/dynamic'; diff --git a/client/pages/_document.page.tsx b/client/pages/_document.page.tsx index 736b899..86d209b 100644 --- a/client/pages/_document.page.tsx +++ b/client/pages/_document.page.tsx @@ -1,4 +1,4 @@ -import { APP_NAME } from 'api/@constants'; +import { APP_NAME } from 'common/constants'; import { Head, Html, Main, NextScript } from 'next/document'; import { staticPath } from 'utils/$path'; diff --git a/client/pages/login/index.page.tsx b/client/pages/login/index.page.tsx index bdacd7d..85d5e97 100644 --- a/client/pages/login/index.page.tsx +++ b/client/pages/login/index.page.tsx @@ -1,6 +1,6 @@ import { Authenticator } from '@aws-amplify/ui-react'; -import { APP_NAME } from 'api/@constants'; import { signUp } from 'aws-amplify/auth'; +import { APP_NAME } from 'common/constants'; import { Spacer } from 'components/Spacer'; import { Loading } from 'components/loading/Loading'; import { useUser } from 'hooks/useUser'; diff --git a/server/api/private/hooks.ts b/server/api/private/hooks.ts index 6d406a7..34e8797 100644 --- a/server/api/private/hooks.ts +++ b/server/api/private/hooks.ts @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import { userUseCase } from 'domain/user/useCase/userUseCase'; import type { JwtUser } from 'service/types'; import { defineHooks } from './$relay'; diff --git a/server/api/private/me/index.ts b/server/api/private/me/index.ts index 7cce5c3..b4f8c11 100644 --- a/server/api/private/me/index.ts +++ b/server/api/private/me/index.ts @@ -1,5 +1,5 @@ -import type { UserDto } from 'api/@types/user'; import type { DefineMethods } from 'aspida'; +import type { UserDto } from 'common/types/user'; export type Methods = DefineMethods<{ get: { diff --git a/server/api/private/tasks/_taskId@string/index.ts b/server/api/private/tasks/_taskId@string/index.ts index fbf9add..ee9f459 100644 --- a/server/api/private/tasks/_taskId@string/index.ts +++ b/server/api/private/tasks/_taskId@string/index.ts @@ -1,5 +1,5 @@ -import type { TaskDto } from 'api/@types/task'; import type { DefineMethods } from 'aspida'; +import type { TaskDto } from 'common/types/task'; export type Methods = DefineMethods<{ patch: { diff --git a/server/api/private/tasks/di/index.ts b/server/api/private/tasks/di/index.ts index 4412b97..d5c6f9c 100644 --- a/server/api/private/tasks/di/index.ts +++ b/server/api/private/tasks/di/index.ts @@ -1,5 +1,5 @@ -import type { TaskDto } from 'api/@types/task'; import type { DefineMethods } from 'aspida'; +import type { TaskDto } from 'common/types/task'; export type Methods = DefineMethods<{ get: { diff --git a/server/api/private/tasks/index.ts b/server/api/private/tasks/index.ts index f75ac89..3704686 100644 --- a/server/api/private/tasks/index.ts +++ b/server/api/private/tasks/index.ts @@ -1,6 +1,6 @@ -import type { MaybeId } from 'api/@types/brandedId'; -import type { TaskCreateVal, TaskDto, TaskUpdateDoneDto } from 'api/@types/task'; import type { DefineMethods } from 'aspida'; +import type { MaybeId } from 'common/types/brandedId'; +import type { TaskCreateVal, TaskDto, TaskUpdateDoneDto } from 'common/types/task'; export type Methods = DefineMethods<{ get: { diff --git a/server/api/@constants/index.ts b/server/common/constants.ts similarity index 100% rename from server/api/@constants/index.ts rename to server/common/constants.ts diff --git a/server/api/@types/brandedId.ts b/server/common/types/brandedId.ts similarity index 84% rename from server/api/@types/brandedId.ts rename to server/common/types/brandedId.ts index b279be2..a67b580 100644 --- a/server/api/@types/brandedId.ts +++ b/server/common/types/brandedId.ts @@ -1,4 +1,4 @@ -import type { BRANDED_ID_NAMES } from 'api/@constants'; +import type { BRANDED_ID_NAMES } from 'common/constants'; import type { z } from 'zod'; type IdName = (typeof BRANDED_ID_NAMES)[number]; diff --git a/server/api/@types/task.ts b/server/common/types/task.ts similarity index 93% rename from server/api/@types/task.ts rename to server/common/types/task.ts index 6a0dd7d..ec6b185 100644 --- a/server/api/@types/task.ts +++ b/server/common/types/task.ts @@ -1,4 +1,4 @@ -import type { WS_TYPES } from 'api/@constants'; +import type { WS_TYPES } from 'common/constants'; import type { DtoId, MaybeId } from './brandedId'; export type TaskDto = { diff --git a/server/api/@types/user.ts b/server/common/types/user.ts similarity index 100% rename from server/api/@types/user.ts rename to server/common/types/user.ts diff --git a/server/api/@types/websocket.ts b/server/common/types/websocket.ts similarity index 100% rename from server/api/@types/websocket.ts rename to server/common/types/websocket.ts diff --git a/server/api/@validators/task.ts b/server/common/validators/task.ts similarity index 100% rename from server/api/@validators/task.ts rename to server/common/validators/task.ts diff --git a/server/domain/task/event/taskEvent.ts b/server/domain/task/event/taskEvent.ts index e492ea5..0414f3b 100644 --- a/server/domain/task/event/taskEvent.ts +++ b/server/domain/task/event/taskEvent.ts @@ -1,11 +1,11 @@ -import { WS_TYPES } from 'api/@constants'; +import { WS_TYPES } from 'common/constants'; import type { TaskCreatedEvent, TaskDeletedEvent, TaskDto, TaskUpdatedEvent, -} from 'api/@types/task'; -import type { UserDto } from 'api/@types/user'; +} from 'common/types/task'; +import type { UserDto } from 'common/types/user'; import { websocket } from 'service/websocket'; export const taskEvent = { diff --git a/server/domain/task/model/taskEntity.ts b/server/domain/task/model/taskEntity.ts index a831c39..64458e9 100644 --- a/server/domain/task/model/taskEntity.ts +++ b/server/domain/task/model/taskEntity.ts @@ -1,5 +1,5 @@ import type { MultipartFile } from '@fastify/multipart'; -import type { TaskDto } from 'api/@types/task'; +import type { TaskDto } from 'common/types/task'; import type { EntityId } from 'service/brandedId'; import type { S3PutParams } from 'service/s3Client'; diff --git a/server/domain/task/model/taskMethod.ts b/server/domain/task/model/taskMethod.ts index f3ade92..1cbc042 100644 --- a/server/domain/task/model/taskMethod.ts +++ b/server/domain/task/model/taskMethod.ts @@ -1,7 +1,7 @@ -import type { TaskUpdateDoneDto } from 'api/@types/task'; -import type { UserDto } from 'api/@types/user'; -import { labelValidator } from 'api/@validators/task'; import assert from 'assert'; +import type { TaskUpdateDoneDto } from 'common/types/task'; +import type { UserDto } from 'common/types/user'; +import { labelValidator } from 'common/validators/task'; import { brandedId } from 'service/brandedId'; import { s3 } from 'service/s3Client'; import { ulid } from 'ulid'; diff --git a/server/domain/task/repository/taskQuery.ts b/server/domain/task/repository/taskQuery.ts index da914e7..f94e49a 100644 --- a/server/domain/task/repository/taskQuery.ts +++ b/server/domain/task/repository/taskQuery.ts @@ -1,5 +1,5 @@ import type { Prisma, Task, User } from '@prisma/client'; -import type { DtoId, MaybeId } from 'api/@types/brandedId'; +import type { DtoId, MaybeId } from 'common/types/brandedId'; import { brandedId } from 'service/brandedId'; import { s3 } from 'service/s3Client'; import { depend } from 'velona'; diff --git a/server/domain/task/service/taskValidator.ts b/server/domain/task/service/taskValidator.ts index 4a915c2..3e06d43 100644 --- a/server/domain/task/service/taskValidator.ts +++ b/server/domain/task/service/taskValidator.ts @@ -1,5 +1,5 @@ import { multipartFileValidator } from 'api/$relay'; -import type { TaskUpdateDoneDto } from 'api/@types/task'; +import type { TaskUpdateDoneDto } from 'common/types/task'; import { brandedId } from 'service/brandedId'; import { z } from 'zod'; import type { TaskCreateServerVal } from '../model/taskEntity'; diff --git a/server/domain/task/service/toTaskDto.ts b/server/domain/task/service/toTaskDto.ts index 171a2da..2af01f4 100644 --- a/server/domain/task/service/toTaskDto.ts +++ b/server/domain/task/service/toTaskDto.ts @@ -1,4 +1,4 @@ -import type { TaskDto } from 'api/@types/task'; +import type { TaskDto } from 'common/types/task'; import { brandedId } from 'service/brandedId'; import type { TaskEntity } from '../model/taskEntity'; diff --git a/server/domain/task/useCase/taskUseCase.ts b/server/domain/task/useCase/taskUseCase.ts index 0064c26..a57ab97 100644 --- a/server/domain/task/useCase/taskUseCase.ts +++ b/server/domain/task/useCase/taskUseCase.ts @@ -1,6 +1,6 @@ -import type { MaybeId } from 'api/@types/brandedId'; -import type { TaskDto, TaskUpdateDoneDto } from 'api/@types/task'; -import type { UserDto } from 'api/@types/user'; +import type { MaybeId } from 'common/types/brandedId'; +import type { TaskDto, TaskUpdateDoneDto } from 'common/types/task'; +import type { UserDto } from 'common/types/user'; import { transaction } from 'service/prismaClient'; import { taskEvent } from '../event/taskEvent'; import type { TaskCreateServerVal } from '../model/taskEntity'; diff --git a/server/domain/user/model/userEntity.ts b/server/domain/user/model/userEntity.ts index 27d45f8..d69c95d 100644 --- a/server/domain/user/model/userEntity.ts +++ b/server/domain/user/model/userEntity.ts @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import type { EntityId } from 'service/brandedId'; export type UserEntity = Omit & { id: EntityId['user'] }; diff --git a/server/domain/user/service/toUserDto.ts b/server/domain/user/service/toUserDto.ts index 58c1b46..46b42d0 100644 --- a/server/domain/user/service/toUserDto.ts +++ b/server/domain/user/service/toUserDto.ts @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import { brandedId } from 'service/brandedId'; import type { UserEntity } from '../model/userEntity'; diff --git a/server/domain/user/useCase/userUseCase.ts b/server/domain/user/useCase/userUseCase.ts index 59289b9..27129c9 100644 --- a/server/domain/user/useCase/userUseCase.ts +++ b/server/domain/user/useCase/userUseCase.ts @@ -1,4 +1,4 @@ -import type { UserDto } from 'api/@types/user'; +import type { UserDto } from 'common/types/user'; import { prismaClient, transaction } from 'service/prismaClient'; import type { JwtUser } from 'service/types'; import { userMethod } from '../model/userMethod'; diff --git a/server/service/app.ts b/server/service/app.ts index e4b75de..747f9da 100644 --- a/server/service/app.ts +++ b/server/service/app.ts @@ -5,8 +5,8 @@ import fastifyHttpProxy from '@fastify/http-proxy'; import type { TokenOrHeader } from '@fastify/jwt'; import fastifyJwt from '@fastify/jwt'; import fastifyWebsocket from '@fastify/websocket'; -import { IS_PROD, WS_PATH } from 'api/@constants'; import assert from 'assert'; +import { IS_PROD, WS_PATH } from 'common/constants'; import type { FastifyInstance, FastifyRequest } from 'fastify'; import Fastify from 'fastify'; import buildGetJwks from 'get-jwks'; diff --git a/server/service/brandedId.ts b/server/service/brandedId.ts index ab8eb90..55286fd 100644 --- a/server/service/brandedId.ts +++ b/server/service/brandedId.ts @@ -1,5 +1,5 @@ -import { BRANDED_ID_NAMES } from 'api/@constants'; -import type { DtoId, MaybeId } from 'api/@types/brandedId'; +import { BRANDED_ID_NAMES } from 'common/constants'; +import type { DtoId, MaybeId } from 'common/types/brandedId'; import { z } from 'zod'; type IdName = (typeof BRANDED_ID_NAMES)[number]; diff --git a/server/service/types.ts b/server/service/types.ts index 96eb237..284f01e 100644 --- a/server/service/types.ts +++ b/server/service/types.ts @@ -1,3 +1,3 @@ -import type { DtoId } from 'api/@types/brandedId'; +import type { DtoId } from 'common/types/brandedId'; export type JwtUser = { sub: DtoId['user']; 'cognito:username': string; email: string }; diff --git a/server/service/websocket.ts b/server/service/websocket.ts index 7961481..1219fcb 100644 --- a/server/service/websocket.ts +++ b/server/service/websocket.ts @@ -1,6 +1,6 @@ -import { WS_PING, WS_PONG } from 'api/@constants'; -import type { DtoId } from 'api/@types/brandedId'; -import type { WebSocketData } from 'api/@types/websocket'; +import { WS_PING, WS_PONG } from 'common/constants'; +import type { DtoId } from 'common/types/brandedId'; +import type { WebSocketData } from 'common/types/websocket'; import type { FastifyInstance } from 'fastify'; import { WebSocket } from 'ws'; diff --git a/server/tests/api/apiClient.ts b/server/tests/api/apiClient.ts index 6ecc874..2757120 100644 --- a/server/tests/api/apiClient.ts +++ b/server/tests/api/apiClient.ts @@ -4,8 +4,8 @@ import { AdminInitiateAuthCommand, } from '@aws-sdk/client-cognito-identity-provider'; import api from 'api/$api'; -import { WS_PATH } from 'api/@constants'; import axios from 'axios'; +import { WS_PATH } from 'common/constants'; import { COOKIE_NAME } from 'service/constants'; import { API_BASE_PATH, diff --git a/server/tests/api/private/di.test.ts b/server/tests/api/private/di.test.ts index b9b7734..172da8e 100644 --- a/server/tests/api/private/di.test.ts +++ b/server/tests/api/private/di.test.ts @@ -1,7 +1,7 @@ import type { Prisma } from '@prisma/client'; -import type { DtoId } from 'api/@types/brandedId'; -import type { UserDto } from 'api/@types/user'; import controller from 'api/private/tasks/di/controller'; +import type { DtoId } from 'common/types/brandedId'; +import type { UserDto } from 'common/types/user'; import type { TaskEntity } from 'domain/task/model/taskEntity'; import fastify from 'fastify'; import { brandedId } from 'service/brandedId'; diff --git a/server/tests/api/private/tasks.test.ts b/server/tests/api/private/tasks.test.ts index cdc33d2..03bbc0b 100644 --- a/server/tests/api/private/tasks.test.ts +++ b/server/tests/api/private/tasks.test.ts @@ -1,5 +1,5 @@ -import { WS_TYPES } from 'api/@constants'; -import type { TaskCreatedEvent, TaskDeletedEvent, TaskUpdatedEvent } from 'api/@types/task'; +import { WS_TYPES } from 'common/constants'; +import type { TaskCreatedEvent, TaskDeletedEvent, TaskUpdatedEvent } from 'common/types/task'; import { expect, test } from 'vitest'; import { createSessionClients, noCookieClient } from '../apiClient'; import { DELETE, GET, PATCH, POST, WS } from '../utils'; diff --git a/server/tests/api/utils.ts b/server/tests/api/utils.ts index 3ebfbcc..784afa4 100644 --- a/server/tests/api/utils.ts +++ b/server/tests/api/utils.ts @@ -1,4 +1,4 @@ -import type { WS_TYPES } from 'api/@constants'; +import type { WS_TYPES } from 'common/constants'; import { SERVER_PORT } from 'service/envValues'; export const TEST_PORT = SERVER_PORT - 1; diff --git a/server/tsconfig.json b/server/tsconfig.json index 8f6e6e1..2608b5a 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -13,12 +13,5 @@ "strictPropertyInitialization": false, "target": "es6", "incremental": true - }, - "include": ["**/*.ts", "**/*.js"], - "exclude": [ - "node_modules", - "api/@types/$relay.ts", - "api/@constants/$relay.ts", - "api/@validators/$relay.ts" - ] + } } diff --git a/tsconfig.json b/tsconfig.json index 4426d1c..a3c52f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,5 @@ "jsx": "preserve", "types": ["vitest/importMeta"], "incremental": true - }, - "include": ["**/*.ts", "**/*.tsx"] + } }