diff --git a/Makefile b/Makefile index 52564e1b..47e02cc4 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,12 @@ setup: @echo "- edit web/.env" @echo "- run make sync" -setup-ci: - if [ ${DATABASE_URL} == "" ]; then echo 'Please set DATABASE_URL_FOR_SQL_GENERATION!'; exit 1; fi +setup-ci: + if [ "" == ${DATABASE_URL} ]; then echo 'Please set DATABASE_URL_FOR_SQL_GENERATION!'; exit 1; fi make sync make generate-sql -sync: sync-server sync-web sync-root copy-common +sync: sync-server sync-web sync-root sync-common lefthook install || true @echo '----------------------------------------------------------------------------------------------------------' @echo '| Most work is done. now running prisma-generate-sql (which might fail if .env.dev is not set configured)|' @@ -42,17 +42,17 @@ test: dev-db cd ./test; ENV_FILE=../server/.env.dev bun test docker stop postgres -prepare-deploy-web: copy-common +prepare-deploy-web: sync-common cd web; bun install; bun run build -prepare-deploy-server: copy-common sync-server generate-sql +prepare-deploy-server: sync-common sync-server generate-sql deploy-server: cd server; bun src/main.ts -docker: copy-common +docker: @# deferring `docker compose down`. https://qiita.com/KEINOS/items/532dc395fe0f89c2b574 trap 'docker compose down' EXIT; docker compose up --build -docker-watch: copy-common +docker-watch: docker compose up --build --watch seed: @@ -93,6 +93,8 @@ sync-server: sync-root: bun install --frozen-lockfile +sync-common: + cd common; bun install --frozen-lockfile # Static checks @@ -117,7 +119,7 @@ format-check: @exit 1 # type checks -type-check: copy-common +type-check: make type-check-server make type-check-web @@ -133,9 +135,9 @@ type-check-web: start-all: build-web build-server make serve-all -build-web: copy-common-to-web +build-web: cd web; bun run build -build-server: copy-common-to-server +build-server: cd server; bun run build serve-all: @@ -145,17 +147,9 @@ serve-web: serve-server: cd server; bun run serve -watch-web: copy-common-to-web +watch-web: cd web; bun run dev -watch-server: copy-common-to-server +watch-server: cd server; bun run dev -copy-common: copy-common-to-server copy-common-to-web -copy-common-to-server: - @ if [ -d server/src/common ]; then rm -r server/src/common; fi - @ cp -r common server/src/common -copy-common-to-web: - @ if [ -d web/common ]; then rm -r web/common; fi - @ cp -r common web/common - .PHONY: test diff --git a/bun.lockb b/bun.lockb index 27ec7b10..760520a5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/common/README.md b/common/README.md new file mode 100644 index 00000000..2bfd5844 --- /dev/null +++ b/common/README.md @@ -0,0 +1,15 @@ +# common + +To install dependencies: + +```bash +bun install +``` + +To run: + +```bash +bun run index.ts +``` + +This project was created using `bun init` in bun v1.1.29. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/common/bun.lockb b/common/bun.lockb new file mode 100755 index 00000000..de9c51da Binary files /dev/null and b/common/bun.lockb differ diff --git a/common/package.json b/common/package.json new file mode 100644 index 00000000..8527e4ae --- /dev/null +++ b/common/package.json @@ -0,0 +1,13 @@ +{ + "name": "common", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "zod": "^3.23.8" + } +} diff --git a/common/tsconfig.json b/common/tsconfig.json new file mode 100644 index 00000000..238655f2 --- /dev/null +++ b/common/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/flake.lock b/flake.lock index 98ba3177..478bad12 100644 --- a/flake.lock +++ b/flake.lock @@ -8,11 +8,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1727764514, - "narHash": "sha256-tvN9v5gTxLI5zOKsNvYl1aUxIitHm8Nj3vKdXNfJo50=", + "lastModified": 1730442928, + "narHash": "sha256-U1DWb5c3EfkA7pqx5V1H4AWRA+EaE6UJ0lIRvK1RxgM=", "owner": "nix-community", "repo": "fenix", - "rev": "a9d2e5fa8d77af05240230c9569bbbddd28ccfaf", + "rev": "87b4d20f896c99018dde4702a9c6157b516f2a76", "type": "github" }, "original": { @@ -27,11 +27,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -60,11 +60,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1727509270, - "narHash": "sha256-WD2APik+VEDBHaYswnhP+lOUKFXgQ2kEQTbYfgXGqWw=", + "lastModified": 1731974111, + "narHash": "sha256-sq5EjHYtnJu9uF7qmadiMAw/EkI94JPW/bwMUWKUKs4=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f7d490f88874e5ffd89a5bb99c5381406958b2ef", + "rev": "ff377cce50a8af30c173382a166e6c74802ed9ae", "type": "github" }, "original": { @@ -120,11 +120,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1727706011, - "narHash": "sha256-xxgUHwwJ+1xQQoUWvLDo807IZ0MDldkfr9N1G4fvNJU=", + "lastModified": 1730386175, + "narHash": "sha256-0Uq+/B8eu7pw8B8pxuGdFYKjcVLwNMcHfDxU9sXh7rg=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "28830ff2f1158ee92f4852ef3ec35af0935d1562", + "rev": "0ba893e1a00d92557ac91efb771d72eee36ca687", "type": "github" }, "original": { diff --git a/package.json b/package.json index b3cfdd5a..99611cfe 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "devDependencies": { "@biomejs/biome": "^1.9.1", "@types/bun": "^1.1.10", - "lefthook": "^1.8.2", + "cspell": "^8.14.4", "typescript": "^5.6.2", - "cspell": "^8.14.4" + "lefthook": "^1.8.2" }, "dependencies": { "zod": "^3.23.8" diff --git a/server/bun.lockb b/server/bun.lockb index 936692b0..a3990a77 100755 Binary files a/server/bun.lockb and b/server/bun.lockb differ diff --git a/server/package.json b/server/package.json index 188e2cca..f2e0f362 100644 --- a/server/package.json +++ b/server/package.json @@ -17,6 +17,7 @@ "author": "", "license": "ISC", "dependencies": { + "common": "file:../common", "@prisma/client": "^5.20.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", diff --git a/server/src/database/chat.ts b/server/src/database/chat.ts index ea35a52e..37f8a7cf 100644 --- a/server/src/database/chat.ts +++ b/server/src/database/chat.ts @@ -1,5 +1,5 @@ -import { Err, Ok, type Result } from "../common/lib/result"; -import type { UserID } from "../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { UserID } from "common/types"; import type { DMOverview, DMRoom, @@ -11,7 +11,7 @@ import type { ShareRoomID, SharedRoom, SharedRoomOverview, -} from "../common/types"; +} from "common/types"; import { prisma } from "./client"; import { getRelation } from "./matches"; import { getMatchedUser } from "./requests"; diff --git a/server/src/database/courses.ts b/server/src/database/courses.ts index 5ddc0c48..356337aa 100644 --- a/server/src/database/courses.ts +++ b/server/src/database/courses.ts @@ -1,4 +1,4 @@ -import type { Course, Day, UserID } from "../common/types"; +import type { Course, Day, UserID } from "common/types"; import { prisma } from "./client"; export async function getCourseByCourseId( diff --git a/server/src/database/enrollments.ts b/server/src/database/enrollments.ts index a2ea0a36..49075b9a 100644 --- a/server/src/database/enrollments.ts +++ b/server/src/database/enrollments.ts @@ -1,4 +1,4 @@ -import type { Course, CourseID, UserID } from "../common/types"; +import type { Course, CourseID, UserID } from "common/types"; import { prisma } from "./client"; import { getCoursesByUserId } from "./courses"; diff --git a/server/src/database/interest.ts b/server/src/database/interest.ts index 00f4b10c..6b87edea 100644 --- a/server/src/database/interest.ts +++ b/server/src/database/interest.ts @@ -1,4 +1,4 @@ -import type { InterestSubject, UserID } from "../common/types"; +import type { InterestSubject, UserID } from "common/types"; import { prisma } from "./client"; export async function all(): Promise { diff --git a/server/src/database/matches.ts b/server/src/database/matches.ts index 4b8aec72..86df7857 100644 --- a/server/src/database/matches.ts +++ b/server/src/database/matches.ts @@ -1,5 +1,5 @@ -import { Err, Ok, type Result } from "../common/lib/result"; -import type { Relationship, UserID } from "../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { Relationship, UserID } from "common/types"; import asyncMap from "../lib/async/map"; import { prisma } from "./client"; diff --git a/server/src/database/picture.ts b/server/src/database/picture.ts index d4c39181..d7409d1a 100644 --- a/server/src/database/picture.ts +++ b/server/src/database/picture.ts @@ -1,5 +1,5 @@ -import { Err, Ok, type Result } from "../common/lib/result"; -import type { GUID } from "../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { GUID } from "common/types"; import { prisma } from "./client"; /** diff --git a/server/src/database/requests.ts b/server/src/database/requests.ts index 780de373..0642a3b1 100644 --- a/server/src/database/requests.ts +++ b/server/src/database/requests.ts @@ -1,5 +1,5 @@ -import { Err, Ok, type Result } from "../common/lib/result"; -import type { Relationship, User, UserID } from "../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { Relationship, User, UserID } from "common/types"; import { prisma } from "./client"; // マッチリクエストの送信 diff --git a/server/src/database/users.ts b/server/src/database/users.ts index 0ee23e0c..8ba7b9a1 100644 --- a/server/src/database/users.ts +++ b/server/src/database/users.ts @@ -1,5 +1,5 @@ -import { Err, Ok, type Result } from "../common/lib/result"; -import type { GUID, UpdateUser, User, UserID } from "../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { GUID, UpdateUser, User, UserID } from "common/types"; import { prisma } from "./client"; // ユーザーの作成 diff --git a/server/src/firebase/auth/db.ts b/server/src/firebase/auth/db.ts index dd9aa507..769e3c44 100644 --- a/server/src/firebase/auth/db.ts +++ b/server/src/firebase/auth/db.ts @@ -1,7 +1,7 @@ import { PrismaClient } from "@prisma/client"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { IDToken, UserID } from "common/types"; import type { Request } from "express"; -import { Err, Ok, type Result } from "../../common/lib/result"; -import type { IDToken, UserID } from "../../common/types"; import { getGUID, getGUIDFromToken } from "./lib"; import { prisma } from "../../database/client"; diff --git a/server/src/firebase/auth/lib.ts b/server/src/firebase/auth/lib.ts index 045a47a4..20d066b7 100644 --- a/server/src/firebase/auth/lib.ts +++ b/server/src/firebase/auth/lib.ts @@ -1,7 +1,7 @@ +import { Err, Ok, type Result } from "common/lib/result"; +import type { GUID, IDToken } from "common/types"; import type { Request } from "express"; import * as admin from "firebase-admin/auth"; -import { Err, Ok, type Result } from "../../common/lib/result"; -import type { GUID, IDToken } from "../../common/types"; import { app } from "../init"; const auth = admin.getAuth(app); diff --git a/server/src/functions/chat.ts b/server/src/functions/chat.ts index e715ca13..1277e54d 100644 --- a/server/src/functions/chat.ts +++ b/server/src/functions/chat.ts @@ -1,5 +1,5 @@ -import type { Result } from "../common/lib/result"; -import type { InitRoom, SharedRoom, UserID } from "../common/types"; +import type { Result } from "common/lib/result"; +import type { InitRoom, SharedRoom, UserID } from "common/types"; import type { DMRoom, Message, @@ -8,7 +8,7 @@ import type { RoomOverview, SendMessage, ShareRoomID, -} from "../common/types"; +} from "common/types"; import * as db from "../database/chat"; import { areAllMatched, areMatched, getRelation } from "../database/matches"; import { getUserByID } from "../database/users"; diff --git a/server/src/functions/engines/recommendation.ts b/server/src/functions/engines/recommendation.ts index ffcc620c..76850d01 100644 --- a/server/src/functions/engines/recommendation.ts +++ b/server/src/functions/engines/recommendation.ts @@ -1,6 +1,6 @@ import { recommend as sql } from "@prisma/client/sql"; -import { Err, Ok, type Result } from "../../common/lib/result"; -import type { User, UserID } from "../../common/types"; +import { Err, Ok, type Result } from "common/lib/result"; +import type { User, UserID } from "common/types"; import { prisma } from "../../database/client"; import { getUserByID } from "../../database/users"; diff --git a/server/src/functions/img/compress.ts b/server/src/functions/img/compress.ts index 38ae559b..b07baccc 100644 --- a/server/src/functions/img/compress.ts +++ b/server/src/functions/img/compress.ts @@ -1,5 +1,5 @@ +import { Err, Ok, type Result } from "common/lib/result"; import sharp from "sharp"; -import { Err, Ok, type Result } from "../../common/lib/result"; const IMAGE_SIZE_PX = 320; diff --git a/server/src/functions/user.ts b/server/src/functions/user.ts index d89f7b65..6a1a7644 100644 --- a/server/src/functions/user.ts +++ b/server/src/functions/user.ts @@ -1,5 +1,5 @@ -import { Result } from "../common/lib/result"; -import type { GUID, User, UserID } from "../common/types"; +import { Result } from "common/lib/result"; +import type { GUID, User, UserID } from "common/types"; import { getMatchedUser } from "../database/requests"; import * as db from "../database/users"; import * as http from "./share/http"; diff --git a/server/src/lib/socket/socket.ts b/server/src/lib/socket/socket.ts index 84124a55..c44faf04 100644 --- a/server/src/lib/socket/socket.ts +++ b/server/src/lib/socket/socket.ts @@ -1,7 +1,7 @@ import type { Server } from "node:http"; +import type { Message, UserID } from "common/types"; import type { CorsOptions } from "cors"; import { type Socket, Server as SocketIOServer } from "socket.io"; -import type { Message, UserID } from "../../common/types"; import { getUserIdFromToken } from "../../firebase/auth/db"; const users = new Map(); diff --git a/server/src/router/chat.ts b/server/src/router/chat.ts index 01369a4c..2f4c11de 100644 --- a/server/src/router/chat.ts +++ b/server/src/router/chat.ts @@ -1,13 +1,13 @@ -import express from "express"; -import { safeParseInt } from "../common/lib/result/safeParseInt"; -import type { MessageID, UserID } from "../common/types"; -import { parseUserID } from "../common/zod/methods"; +import { safeParseInt } from "common/lib/result/safeParseInt"; +import type { MessageID, UserID } from "common/types"; +import { parseUserID } from "common/zod/methods"; import { ContentSchema, InitRoomSchema, SendMessageSchema, SharedRoomSchema, -} from "../common/zod/schemas"; +} from "common/zod/schemas"; +import express from "express"; import * as db from "../database/chat"; import { safeGetUserId } from "../firebase/auth/db"; import * as core from "../functions/chat"; diff --git a/server/src/router/courses.ts b/server/src/router/courses.ts index 959ae4f3..4706be1a 100644 --- a/server/src/router/courses.ts +++ b/server/src/router/courses.ts @@ -1,6 +1,6 @@ +import type { Day } from "common/types"; +import { DaySchema, PeriodSchema } from "common/zod/schemas"; import express, { type Request, type Response } from "express"; -import type { Day } from "../common/types"; -import { DaySchema, PeriodSchema } from "../common/zod/schemas"; import { getCourseByCourseId, getCourseByDayPeriodAndUserId, diff --git a/server/src/router/matches.ts b/server/src/router/matches.ts index 6282be64..ef4d040a 100644 --- a/server/src/router/matches.ts +++ b/server/src/router/matches.ts @@ -1,6 +1,6 @@ +import { safeParseInt } from "common/lib/result/safeParseInt"; +import type { UserID } from "common/types"; import express, { type Request, type Response } from "express"; -import { safeParseInt } from "../common/lib/result/safeParseInt"; -import type { UserID } from "../common/types"; import { deleteMatch, getMatchesByUserId } from "../database/matches"; import { safeGetUserId } from "../firebase/auth/db"; diff --git a/server/src/router/requests.ts b/server/src/router/requests.ts index a4bf11e2..45218020 100644 --- a/server/src/router/requests.ts +++ b/server/src/router/requests.ts @@ -1,7 +1,7 @@ +import type { UserID } from "common/types"; import express, { type Request, type Response } from "express"; -import type { UserID } from "../common/types"; -import { safeParseInt } from "../common/lib/result/safeParseInt"; +import { safeParseInt } from "common/lib/result/safeParseInt"; import { approveRequest, cancelRequest, diff --git a/server/src/router/users.ts b/server/src/router/users.ts index 22f823d2..ae0dd6b3 100644 --- a/server/src/router/users.ts +++ b/server/src/router/users.ts @@ -1,11 +1,11 @@ -import express, { type Request, type Response } from "express"; -import type { GUID, UpdateUser } from "../common/types"; -import type { User } from "../common/types"; +import type { GUID, UpdateUser } from "common/types"; +import type { User } from "common/types"; import { GUIDSchema, InitUserSchema, UpdateUserSchema, -} from "../common/zod/schemas"; +} from "common/zod/schemas"; +import express, { type Request, type Response } from "express"; import { getPendingRequestsFromUser, getPendingRequestsToUser, diff --git a/server/src/seeds/test-data/data.ts b/server/src/seeds/test-data/data.ts index c4a2714c..64dd2dd4 100644 --- a/server/src/seeds/test-data/data.ts +++ b/server/src/seeds/test-data/data.ts @@ -1,4 +1,4 @@ -import type { Day } from "../../common/types"; +import type { Day } from "common/types"; export const subjects: Array<{ group: string; diff --git a/web/api/chat/chat.ts b/web/api/chat/chat.ts index c8d5dc4b..b18a8e35 100644 --- a/web/api/chat/chat.ts +++ b/web/api/chat/chat.ts @@ -9,13 +9,13 @@ import type { SharedRoom, UpdateRoom, UserID, -} from "~/common/types"; +} from "common/types"; import { ErrUnauthorized, credFetch } from "~/firebase/auth/lib"; import endpoints from "../internal/endpoints"; /* TODO -import { UserID } from "~/common/types"; -import type { User } from "~/common/types"; +import { UserID } from "common/types"; +import type { User } from "common/types"; */ //// DM グループチャット 共通//// diff --git a/web/api/chat/hooks.ts b/web/api/chat/hooks.ts index 009eebed..ecf35598 100644 --- a/web/api/chat/hooks.ts +++ b/web/api/chat/hooks.ts @@ -1,10 +1,10 @@ "use client"; +// import { useCallback, useEffect, useState } from "react"; +import type { Message, RoomOverview } from "common/types"; +import { MessageSchema, RoomOverviewSchema } from "common/zod/schemas"; import { useCallback } from "react"; import { z } from "zod"; -// import { useCallback, useEffect, useState } from "react"; -import type { Message, RoomOverview } from "~/common/types"; -import { MessageSchema, RoomOverviewSchema } from "~/common/zod/schemas"; import { type Hook, useCustomizedSWR } from "~/hooks/useCustomizedSWR"; import type { UserID } from "../internal/endpoints"; // import type { Hook } from "~/share/types"; diff --git a/web/api/course.hook.ts b/web/api/course.hook.ts index 086d8b1c..cf774c53 100644 --- a/web/api/course.hook.ts +++ b/web/api/course.hook.ts @@ -1,6 +1,6 @@ +import type { Course } from "common/types"; +import { CourseSchema } from "common/zod/schemas"; import { z } from "zod"; -import type { Course } from "~/common/types"; -import { CourseSchema } from "~/common/zod/schemas"; import { type Hook, useCustomizedSWR } from "~/hooks/useCustomizedSWR"; import { getMyCourses } from "./course"; diff --git a/web/api/course.ts b/web/api/course.ts index 8a09b707..e50ef45b 100644 --- a/web/api/course.ts +++ b/web/api/course.ts @@ -1,4 +1,4 @@ -import type { Course, CourseID, Day } from "~/common/types"; +import type { Course, CourseID, Day } from "common/types"; import { credFetch } from "~/firebase/auth/lib"; import endpoints from "./internal/endpoints"; diff --git a/web/api/internal/endpoints.ts b/web/api/internal/endpoints.ts index 1aa12839..2ebc350a 100644 --- a/web/api/internal/endpoints.ts +++ b/web/api/internal/endpoints.ts @@ -1,5 +1,5 @@ -import type { CourseID, Day, GUID } from "~/common/types"; -import type { MessageID, ShareRoomID } from "~/common/types"; +import type { CourseID, Day, GUID } from "common/types"; +import type { MessageID, ShareRoomID } from "common/types"; export const origin: string | null = process.env.NEXT_PUBLIC_API_ENDPOINT ?? ""; if (!origin) throw new Error("process.env.NEXT_PUBLIC_API_ENDPOINT not found!"); diff --git a/web/api/internal/fetch-func.ts b/web/api/internal/fetch-func.ts index a2dc1aee..46881c75 100644 --- a/web/api/internal/fetch-func.ts +++ b/web/api/internal/fetch-func.ts @@ -1,4 +1,4 @@ -import { Err, Ok, type Result } from "~/common/lib/result"; +import { Err, Ok, type Result } from "common/lib/result"; export async function safeFetch( path: string, diff --git a/web/api/user.ts b/web/api/user.ts index 7ad033b0..a45f53b2 100644 --- a/web/api/user.ts +++ b/web/api/user.ts @@ -1,7 +1,7 @@ +import type { GUID, UpdateUser, User, UserID } from "common/types.ts"; +import { parseUser } from "common/zod/methods.ts"; +import { UserIDSchema, UserSchema } from "common/zod/schemas.ts"; import { z } from "zod"; -import type { GUID, UpdateUser, User, UserID } from "~/common/types.ts"; -import { parseUser } from "~/common/zod/methods.ts"; -import { UserIDSchema, UserSchema } from "~/common/zod/schemas.ts"; import { credFetch } from "~/firebase/auth/lib.ts"; import { type Hook, useCustomizedSWR } from "~/hooks/useCustomizedSWR.ts"; import { useAuthorizedData } from "~/hooks/useData.ts"; diff --git a/web/app/edit/profile/page.tsx b/web/app/edit/profile/page.tsx index 55e20763..b811c00b 100644 --- a/web/app/edit/profile/page.tsx +++ b/web/app/edit/profile/page.tsx @@ -12,13 +12,13 @@ import { Typography, } from "@mui/material"; import type { SelectChangeEvent } from "@mui/material"; +import type { UpdateUser } from "common/types"; +import { UpdateUserSchema } from "common/zod/schemas"; import { useRouter } from "next/navigation"; import { enqueueSnackbar } from "notistack"; import { useEffect, useState } from "react"; import { update, useAboutMe } from "~/api/user"; import { facultiesAndDepartments } from "~/app/signup/data"; -import type { UpdateUser } from "~/common/types"; -import { UpdateUserSchema } from "~/common/zod/schemas"; import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress"; import { useAlert } from "~/components/common/alert/AlertProvider"; import PhotoModal from "~/components/config/PhotoModal"; diff --git a/web/app/login/page.tsx b/web/app/login/page.tsx index 327ebae2..a88075f6 100644 --- a/web/app/login/page.tsx +++ b/web/app/login/page.tsx @@ -1,11 +1,11 @@ "use client"; +import type { GUID } from "common/types"; import { GoogleAuthProvider, signInWithPopup } from "firebase/auth"; import { useRouter } from "next/navigation"; import { useSnackbar } from "notistack"; import * as user from "~/api/user"; import { getByGUID } from "~/api/user"; -import type { GUID } from "~/common/types"; import Header from "~/components/Header"; import { auth } from "~/firebase/config"; import "./style.css"; diff --git a/web/app/signup/functions.ts b/web/app/signup/functions.ts index d928ed40..34991ab7 100644 --- a/web/app/signup/functions.ts +++ b/web/app/signup/functions.ts @@ -1,9 +1,9 @@ +import type { GUID, User } from "common/types"; +import type { UpdateUser } from "common/types"; import { getAuth } from "firebase/auth"; import type { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"; import type { EnqueueSnackbar } from "notistack"; import * as userAPI from "~/api/user"; -import type { GUID, User } from "~/common/types"; -import type { UpdateUser } from "~/common/types"; type Dependencies = { router: AppRouterInstance; diff --git a/web/app/signup/page.tsx b/web/app/signup/page.tsx index bc96ff21..e4d541bb 100644 --- a/web/app/signup/page.tsx +++ b/web/app/signup/page.tsx @@ -3,8 +3,8 @@ import { useSnackbar } from "notistack"; import { useState } from "react"; +import type { Step1User } from "common/zod/types"; import { useRouter } from "next/navigation"; -import type { Step1User } from "~/common/zod/types"; import Header from "~/components/Header"; import { NavigateByAuthState } from "~/components/common/NavigateByAuthState"; import { register } from "./functions"; diff --git a/web/app/signup/steps/step1_profile.tsx b/web/app/signup/steps/step1_profile.tsx index f275c829..8c55a48f 100644 --- a/web/app/signup/steps/step1_profile.tsx +++ b/web/app/signup/steps/step1_profile.tsx @@ -10,10 +10,10 @@ import { Typography, } from "@mui/material"; import type { SelectChangeEvent } from "@mui/material"; +import { parseStep1UserSchema } from "common/zod/methods"; +import type { Step1User } from "common/zod/types"; import type { StepProps } from "~/app/signup/common"; import { facultiesAndDepartments } from "~/app/signup/data"; -import { parseStep1UserSchema } from "~/common/zod/methods"; -import type { Step1User } from "~/common/zod/types"; export default function Step1({ onSave, prev, caller }: StepProps) { const [name, setName] = useState(prev?.name ?? ""); diff --git a/web/app/signup/steps/step3_confirmation.tsx b/web/app/signup/steps/step3_confirmation.tsx index 7a4032e6..28d50201 100644 --- a/web/app/signup/steps/step3_confirmation.tsx +++ b/web/app/signup/steps/step3_confirmation.tsx @@ -1,6 +1,6 @@ import { Box, Typography } from "@mui/material"; +import type { Step1User } from "common/zod/types"; import type { BackProp, StepProps } from "~/app/signup/common"; -import type { Step1User } from "~/common/zod/types"; import UserAvatar from "~/components/human/avatar"; import type { Step2Data } from "./step2_img"; diff --git a/web/bun.lockb b/web/bun.lockb index d5338f3e..efb49f51 100755 Binary files a/web/bun.lockb and b/web/bun.lockb differ diff --git a/web/components/Card.tsx b/web/components/Card.tsx index e8fe5488..47c889c7 100644 --- a/web/components/Card.tsx +++ b/web/components/Card.tsx @@ -1,7 +1,7 @@ import ThreeSixtyIcon from "@mui/icons-material/ThreeSixty"; import { Chip } from "@mui/material"; +import type { User, UserID } from "common/types"; import { useState } from "react"; -import type { User, UserID } from "~/common/types"; import NonEditableCoursesTable from "./course/NonEditableCoursesTable"; import UserAvatar from "./human/avatar"; diff --git a/web/components/DraggableCard.tsx b/web/components/DraggableCard.tsx index 34e12d0f..91de23e9 100644 --- a/web/components/DraggableCard.tsx +++ b/web/components/DraggableCard.tsx @@ -1,9 +1,9 @@ import CloseIcon from "@mui/icons-material/Close"; import FavoriteIcon from "@mui/icons-material/Favorite"; import { Box, Typography } from "@mui/material"; +import type { User, UserID } from "common/types"; import { motion, useMotionValue, useMotionValueEvent } from "framer-motion"; import { useCallback, useState } from "react"; -import type { User, UserID } from "~/common/types"; import { Card } from "./Card"; const SWIPE_THRESHOLD = 30; diff --git a/web/components/chat/MessageInput.tsx b/web/components/chat/MessageInput.tsx index 9e359ccf..06fbd08a 100644 --- a/web/components/chat/MessageInput.tsx +++ b/web/components/chat/MessageInput.tsx @@ -1,7 +1,7 @@ +import type { DMOverview, SendMessage, UserID } from "common/types"; +import { parseContent } from "common/zod/methods"; import { useEffect, useState } from "react"; import { MdSend } from "react-icons/md"; -import type { DMOverview, SendMessage, UserID } from "~/common/types"; -import { parseContent } from "~/common/zod/methods"; type Props = { send: (to: UserID, m: SendMessage) => void; diff --git a/web/components/chat/Room.tsx b/web/components/chat/Room.tsx index 8e5a995d..71e5d075 100644 --- a/web/components/chat/Room.tsx +++ b/web/components/chat/Room.tsx @@ -1,4 +1,4 @@ -import type { DMOverview } from "~/common/types"; +import type { DMOverview } from "common/types"; import UserAvatar from "../human/avatar"; type Props = { diff --git a/web/components/chat/RoomHeader.tsx b/web/components/chat/RoomHeader.tsx index 8e6c1eb0..17b2b495 100644 --- a/web/components/chat/RoomHeader.tsx +++ b/web/components/chat/RoomHeader.tsx @@ -1,6 +1,6 @@ +import type { DMOverview } from "common/types"; import Link from "next/link"; import { MdArrowBack } from "react-icons/md"; -import type { DMOverview } from "~/common/types"; import UserAvatar from "../human/avatar"; type Props = { diff --git a/web/components/chat/RoomList.tsx b/web/components/chat/RoomList.tsx index 5d5513d7..3bc6fea3 100644 --- a/web/components/chat/RoomList.tsx +++ b/web/components/chat/RoomList.tsx @@ -1,8 +1,8 @@ "use client"; import { Box, List, Typography } from "@mui/material"; +import type { RoomOverview } from "common/types"; import { useRouter } from "next/navigation"; -import type { RoomOverview } from "~/common/types"; import { HumanListItem } from "../human/humanListItem"; type RoomListProps = { diff --git a/web/components/chat/RoomWindow.tsx b/web/components/chat/RoomWindow.tsx index f58e520d..23113e97 100644 --- a/web/components/chat/RoomWindow.tsx +++ b/web/components/chat/RoomWindow.tsx @@ -1,3 +1,11 @@ +import type { + DMOverview, + Message, + MessageID, + SendMessage, + UserID, +} from "common/types"; +import type { Content } from "common/zod/types"; import { useSearchParams } from "next/navigation"; import { useSnackbar } from "notistack"; import { useCallback, useEffect, useRef, useState } from "react"; @@ -5,14 +13,6 @@ import * as chat from "~/api/chat/chat"; import { useMessages } from "~/api/chat/hooks"; import * as user from "~/api/user"; import { useMyID } from "~/api/user"; -import type { - DMOverview, - Message, - MessageID, - SendMessage, - UserID, -} from "~/common/types"; -import type { Content } from "~/common/zod/types"; import { getIdToken } from "~/firebase/auth/lib"; import Dots from "../common/Dots"; import { socket } from "../data/socket"; diff --git a/web/components/common/modal/ModalProvider.tsx b/web/components/common/modal/ModalProvider.tsx index 73fbf975..788369f1 100644 --- a/web/components/common/modal/ModalProvider.tsx +++ b/web/components/common/modal/ModalProvider.tsx @@ -1,6 +1,6 @@ +import type { User } from "common/types"; import { type ReactNode, createContext, useContext, useState } from "react"; import { useMyID } from "~/api/user"; -import type { User } from "~/common/types"; import { Card } from "../../Card"; const ModalContext = createContext(undefined); diff --git a/web/components/course/EditableCoursesTable/index.tsx b/web/components/course/EditableCoursesTable/index.tsx index 5dd32447..95cb9cc3 100644 --- a/web/components/course/EditableCoursesTable/index.tsx +++ b/web/components/course/EditableCoursesTable/index.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; +import type { Course, Day, UserID } from "common/types"; import courseApi from "~/api/course"; -import type { Course, Day, UserID } from "~/common/types"; import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress"; import CoursesTableCore from "../components/CoursesTableCore"; import SelectCourseDialog from "../components/SelectCourseDialog"; diff --git a/web/components/course/NonEditableCoursesTable/index.tsx b/web/components/course/NonEditableCoursesTable/index.tsx index 7a9870e4..a5bf6014 100644 --- a/web/components/course/NonEditableCoursesTable/index.tsx +++ b/web/components/course/NonEditableCoursesTable/index.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; +import type { Course, UserID } from "common/types"; import courseApi from "~/api/course"; -import type { Course, UserID } from "~/common/types"; import FullScreenCircularProgress from "~/components/common/FullScreenCircularProgress"; import CoursesTableCore from "../components/CoursesTableCore"; diff --git a/web/components/course/components/CourseDeleteConfirmDialog.tsx b/web/components/course/components/CourseDeleteConfirmDialog.tsx index a425cda8..63397ae9 100644 --- a/web/components/course/components/CourseDeleteConfirmDialog.tsx +++ b/web/components/course/components/CourseDeleteConfirmDialog.tsx @@ -1,6 +1,6 @@ +import type { Course } from "common/types"; import { useEffect, useState } from "react"; import { deleteMyCourse, getMyCoursesOverlapWith } from "~/api/course"; -import type { Course } from "~/common/types"; export default function CourseDeleteRegisterConfirmDialog({ open, diff --git a/web/components/course/components/CourseRegisterConfirmDialog.tsx b/web/components/course/components/CourseRegisterConfirmDialog.tsx index 2bf80f8d..d6e4eeab 100644 --- a/web/components/course/components/CourseRegisterConfirmDialog.tsx +++ b/web/components/course/components/CourseRegisterConfirmDialog.tsx @@ -1,6 +1,6 @@ +import type { Course } from "common/types"; import { useEffect, useState } from "react"; import { addMyCourse, getMyCoursesOverlapWith } from "~/api/course"; -import type { Course } from "~/common/types"; export default function CourseRegisterConfirmDialog({ open, diff --git a/web/components/course/components/CoursesTableCore/index.tsx b/web/components/course/components/CoursesTableCore/index.tsx index a4dd7cba..dba0587e 100644 --- a/web/components/course/components/CoursesTableCore/index.tsx +++ b/web/components/course/components/CoursesTableCore/index.tsx @@ -1,6 +1,6 @@ +import { ACTIVE_DAYS, DAY_TO_JAPANESE_MAP } from "common/consts"; +import type { Course, Day } from "common/types"; import { useCallback, useEffect, useState } from "react"; -import { ACTIVE_DAYS, DAY_TO_JAPANESE_MAP } from "~/common/consts"; -import type { Course, Day } from "~/common/types"; import { truncateStr } from "./lib"; import styles from "./styles.module.css"; diff --git a/web/components/course/components/SelectCourseDialog.tsx b/web/components/course/components/SelectCourseDialog.tsx index 1b6e6d6c..b6f52515 100644 --- a/web/components/course/components/SelectCourseDialog.tsx +++ b/web/components/course/components/SelectCourseDialog.tsx @@ -1,7 +1,7 @@ +import { DAY_TO_JAPANESE_MAP } from "common/consts"; +import type { Course, Day } from "common/types"; import { useEffect, useState } from "react"; import courseApi from "~/api/course"; -import { DAY_TO_JAPANESE_MAP } from "~/common/consts"; -import type { Course, Day } from "~/common/types"; import CourseDeleteConfirmDialog from "./CourseDeleteConfirmDialog"; import CourseRegisterConfirmDialog from "./CourseRegisterConfirmDialog"; diff --git a/web/firebase/auth/AuthProvider.tsx b/web/firebase/auth/AuthProvider.tsx index 9a009760..37101d56 100644 --- a/web/firebase/auth/AuthProvider.tsx +++ b/web/firebase/auth/AuthProvider.tsx @@ -1,8 +1,8 @@ +import type { GUID, User } from "common/types"; import { getAuth, onAuthStateChanged } from "firebase/auth"; import type React from "react"; import { createContext, useContext, useEffect, useState } from "react"; import * as userAPI from "~/api/user"; -import type { GUID, User } from "~/common/types"; const AuthContext = createContext(undefined); diff --git a/web/firebase/auth/lib.ts b/web/firebase/auth/lib.ts index 4d6e852d..dbeeb190 100644 --- a/web/firebase/auth/lib.ts +++ b/web/firebase/auth/lib.ts @@ -1,6 +1,6 @@ +import type { IDToken } from "common/types"; import { getAuth, onAuthStateChanged } from "firebase/auth"; import type { User } from "firebase/auth"; -import type { IDToken } from "~/common/types"; import { app } from "../config"; export class ErrUnauthorized extends Error {} diff --git a/web/hooks/useData.ts b/web/hooks/useData.ts index 303699e8..4d2cbfce 100644 --- a/web/hooks/useData.ts +++ b/web/hooks/useData.ts @@ -1,5 +1,5 @@ +import { Err, Ok, type Result } from "common/lib/result"; import { useCallback, useEffect, useState } from "react"; -import { Err, Ok, type Result } from "~/common/lib/result"; import { credFetch } from "~/firebase/auth/lib"; // TODO: separate this into concrete types and urls s.t. there is no unsafe any diff --git a/web/package.json b/web/package.json index 2b2576cd..e7810dca 100644 --- a/web/package.json +++ b/web/package.json @@ -9,6 +9,7 @@ "preview": "next start" }, "dependencies": { + "common": "file:../common", "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", "@fontsource/roboto": "^5.0.13",