Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)|'
Expand All @@ -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:
Expand Down Expand Up @@ -93,6 +93,8 @@ sync-server:

sync-root:
bun install --frozen-lockfile
sync-common:
cd common; bun install --frozen-lockfile


# Static checks
Expand All @@ -117,7 +119,7 @@ format-check:
@exit 1

# type checks
type-check: copy-common
type-check:
make type-check-server
make type-check-web

Expand All @@ -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:
Expand 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
Binary file modified bun.lockb
Binary file not shown.
15 changes: 15 additions & 0 deletions common/README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added common/bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "common",
"type": "module",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"zod": "^3.23.8"
}
}
27 changes: 27 additions & 0 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
"license": "ISC",
"devDependencies": {
"@biomejs/biome": "^1.9.1",
"typescript": "^5.6.2"
},
"dependencies": {
"@types/bun": "^1.1.10",
"cspell": "^8.14.4",
"zod": "^3.23.8"
"typescript": "^5.6.2"
},
"trustedDependencies": ["@biomejs/biome"]
}
Binary file modified server/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions server/src/database/chat.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion server/src/database/courses.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion server/src/database/enrollments.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion server/src/database/interest.ts
Original file line number Diff line number Diff line change
@@ -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<InterestSubject[]> {
Expand Down
4 changes: 2 additions & 2 deletions server/src/database/matches.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 2 additions & 2 deletions server/src/database/picture.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down
4 changes: 2 additions & 2 deletions server/src/database/requests.ts
Original file line number Diff line number Diff line change
@@ -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";

// マッチリクエストの送信
Expand Down
4 changes: 2 additions & 2 deletions server/src/database/users.ts
Original file line number Diff line number Diff line change
@@ -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";

// ユーザーの作成
Expand Down
4 changes: 2 additions & 2 deletions server/src/firebase/auth/db.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions server/src/firebase/auth/lib.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
6 changes: 3 additions & 3 deletions server/src/functions/chat.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions server/src/functions/engines/recommendation.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion server/src/functions/img/compress.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions server/src/functions/user.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion server/src/lib/socket/socket.ts
Original file line number Diff line number Diff line change
@@ -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<UserID, Socket>();
Expand Down
10 changes: 5 additions & 5 deletions server/src/router/chat.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
4 changes: 2 additions & 2 deletions server/src/router/courses.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading
Loading