mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 13:58:08 +00:00
use frourio@0.19.1
This commit is contained in:
parent
bfd67b52e7
commit
b29abb5c0b
19 changed files with 4180 additions and 1699 deletions
7
frourio/.vscode/settings.json
vendored
7
frourio/.vscode/settings.json
vendored
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"eslint.run": "onSave",
|
||||
"editor.codeActionsOnSave": { "source.fixAll.eslint": true },
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"typescript.tsdk": "node_modules/typescript/lib"
|
||||
}
|
||||
}
|
10
frourio/jest.config.js
Normal file
10
frourio/jest.config.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
const { pathsToModuleNameMapper } = require('ts-jest/utils')
|
||||
const { compilerOptions } = require('./tsconfig')
|
||||
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
|
||||
prefix: '<rootDir>/'
|
||||
})
|
||||
}
|
|
@ -4,51 +4,51 @@
|
|||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "npm run migrate:up && run-p dev:*",
|
||||
"dev:front": "next dev",
|
||||
"dev:server": "cd server && node_modules/.bin/webpack --watch --mode=development",
|
||||
"dev:client": "next dev -p 3000",
|
||||
"dev:server": "npm run dev --prefix server",
|
||||
"dev:aspida": "aspida --watch",
|
||||
"dev:frourio": "cd server && node_modules/.bin/frourio --watch",
|
||||
"dev:prisma": "cd server && node_modules/.bin/prisma generate --watch",
|
||||
"build": "run-p build:front build:server",
|
||||
"build:front": "aspida && next build && next export",
|
||||
"build:server": "npm run migrate:up && npm run build:frourio && cd server && node_modules/.bin/webpack --mode=production",
|
||||
"build:frourio": "cd server && node_modules/.bin/prisma generate && node_modules/.bin/frourio",
|
||||
"build:types": "aspida && npm run build:frourio",
|
||||
"install:server": "cd server && yarn install",
|
||||
"build": "run-p build:client build:server",
|
||||
"build:client": "aspida && next build && next export",
|
||||
"build:server": "npm run build --prefix server",
|
||||
"build:types": "aspida && npm run build:frourio --prefix server",
|
||||
"lint": "eslint --ext .ts,.js,.tsx .",
|
||||
"lint:fix": "npm run lint -- --fix",
|
||||
"start": "run-p start:*",
|
||||
"start:front": "next start",
|
||||
"start:server": "cd server && cross-env NODE_ENV=production node index.js",
|
||||
"typecheck": "npm run build:types && tsc --noEmit && tsc --noEmit -p server",
|
||||
"migrate": "npm run migrate:save && npm run migrate:up",
|
||||
"migrate:save": "cd server && node_modules/.bin/prisma migrate save --create-db --experimental",
|
||||
"migrate:up": "cd server && node_modules/.bin/prisma migrate up --create-db --experimental",
|
||||
"migrate:down": "cd server && node_modules/.bin/prisma migrate down --experimental"
|
||||
"migrate:save": "npm run migrate:save --prefix server",
|
||||
"migrate:up": "npm run migrate:up --prefix server",
|
||||
"migrate:down": "npm run migrate:down --prefix server",
|
||||
"start": "run-p start:*",
|
||||
"start:client": "next start",
|
||||
"start:server": "npm start --prefix server",
|
||||
"test": "npm run build:types && jest",
|
||||
"typecheck": "npm run build:types && tsc --noEmit && tsc --noEmit -p server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aspida/fetch": "^0.10.0",
|
||||
"@aspida/swr": "^0.2.0",
|
||||
"@aspida/fetch": "^0.10.2",
|
||||
"@aspida/swr": "^0.2.2",
|
||||
"class-validator": "^0.12.2",
|
||||
"next": "9.5.3",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"swr": "^0.3.5"
|
||||
"next": "^10.0.1",
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"swr": "^0.3.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/node": "^14.11.2",
|
||||
"@types/react": "^16.9.49",
|
||||
"@typescript-eslint/eslint-plugin": "^4.3.0",
|
||||
"@typescript-eslint/parser": "^4.3.0",
|
||||
"@types/react": "^16.9.56",
|
||||
"@typescript-eslint/eslint-plugin": "^4.6.1",
|
||||
"@typescript-eslint/parser": "^4.6.1",
|
||||
"cross-env": "^7.0.2",
|
||||
"dotenv": "^8.2.0",
|
||||
"eslint": "^7.10.0",
|
||||
"eslint-config-prettier": "^6.12.0",
|
||||
"eslint": "^7.13.0",
|
||||
"eslint-config-prettier": "^6.15.0",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"eslint-plugin-react": "^7.21.2",
|
||||
"eslint-plugin-react": "^7.21.5",
|
||||
"jest": "^26.6.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.1.2",
|
||||
"ts-loader": "^8.0.4",
|
||||
"typescript": "^4.0.3"
|
||||
"ts-jest": "^26.4.3",
|
||||
"ts-loader": "^8.0.10",
|
||||
"typescript": "^4.0.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { useCallback, useState, FormEvent, ChangeEvent } from 'react'
|
|||
import useAspidaSWR from '@aspida/swr'
|
||||
import styles from '~/styles/Home.module.css'
|
||||
import { apiClient } from '~/utils/apiClient'
|
||||
import { Task } from '$/types'
|
||||
import { Task } from '$prisma/client'
|
||||
import UserBanner from '~/components/UserBanner'
|
||||
|
||||
const Home = () => {
|
||||
|
@ -43,7 +43,7 @@ const Home = () => {
|
|||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>frourio-todo-app</title>
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<link rel="icon" href="/favicon.png" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
BIN
frourio/public/favicon.png
Normal file
BIN
frourio/public/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -1,4 +1,4 @@
|
|||
import { Task } from '$/types'
|
||||
import { Task } from '$prisma/client'
|
||||
|
||||
export type Methods = {
|
||||
patch: {
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import { defineController } from './$relay'
|
||||
import { getTasks, createTask } from '$/service/tasks'
|
||||
|
||||
export default defineController(() => ({
|
||||
get: async () => ({ status: 200, body: await getTasks() }),
|
||||
const print = (text: string) => console.log(text)
|
||||
|
||||
export default defineController({ getTasks, print }, ({ getTasks, print }) => ({
|
||||
get: async ({ query }) => {
|
||||
if (query?.message) print(query.message)
|
||||
|
||||
return { status: 200, body: await getTasks(query?.limit) }
|
||||
},
|
||||
post: async ({ body }) => ({
|
||||
status: 201,
|
||||
body: await createTask(body.label)
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { Task } from '$/types'
|
||||
import { Task } from '$prisma/client'
|
||||
|
||||
export type Methods = {
|
||||
get: {
|
||||
query?: {
|
||||
limit?: number
|
||||
message?: string
|
||||
}
|
||||
|
||||
resBody: Task[]
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import { defineHooks } from './$relay'
|
||||
import { getUserIdByToken } from '$/service/user'
|
||||
|
||||
export type User = {
|
||||
id: string
|
||||
export type AdditionalRequest = {
|
||||
user: {
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
export default defineHooks((fastify) => ({
|
||||
|
|
|
@ -7,34 +7,42 @@
|
|||
"dev:server": "webpack --watch --mode=development",
|
||||
"dev:frourio": "frourio --watch",
|
||||
"dev:prisma": "prisma generate --watch",
|
||||
"build": "npm run migrate:up && prisma generate && frourio && webpack --mode=production",
|
||||
"build": "npm run build:frourio && webpack --mode=production",
|
||||
"build:frourio": "npm run migrate:up && prisma generate && frourio",
|
||||
"migrate": "npm run migrate:save && npm run migrate:up",
|
||||
"migrate:save": "prisma migrate save --create-db --experimental",
|
||||
"migrate:up": "prisma migrate up --create-db --experimental",
|
||||
"migrate:down": "prisma migrate down --experimental",
|
||||
"pm2:start": "pm2 start pm2.config.json --env production",
|
||||
"pm2:stop": "pm2 stop pm2.config.json",
|
||||
"pm2:delete": "pm2 delete pm2.config.json",
|
||||
"pm2:logs": "pm2 logs",
|
||||
"pm2:monit": "pm2 monit",
|
||||
"start": "cross-env NODE_ENV=production node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^2.8.0",
|
||||
"class-validator": "^0.12.2",
|
||||
"dotenv": "^8.2.0",
|
||||
"fastify": "^3.5.1",
|
||||
"fastify": "^3.7.0",
|
||||
"fastify-auth": "^1.0.1",
|
||||
"fastify-cors": "^4.1.0",
|
||||
"fastify-helmet": "^5.0.3",
|
||||
"fastify-multipart": "^3.2.0",
|
||||
"fastify-static": "^3.2.0"
|
||||
"fastify-multipart": "^3.3.0",
|
||||
"fastify-static": "^3.3.0",
|
||||
"pm2": "^4.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@prisma/cli": "^2.8.0",
|
||||
"@types/busboy": "^0.2.3",
|
||||
"cross-env": "^7.0.2",
|
||||
"frourio": "^0.17.1",
|
||||
"frourio": "^0.19.1",
|
||||
"nodemon-webpack-plugin": "^4.3.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"ts-loader": "^8.0.4",
|
||||
"ts-loader": "^8.0.10",
|
||||
"ts-node": "^9.0.0",
|
||||
"tsconfig-paths-webpack-plugin": "^3.3.0",
|
||||
"typescript": "^4.0.3",
|
||||
"typescript": "^4.0.5",
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-cli": "^3.3.12",
|
||||
"webpack-node-externals": "^2.5.2"
|
||||
|
|
7
frourio/server/pm2.config.json
Normal file
7
frourio/server/pm2.config.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "frourio",
|
||||
"script": "index.js",
|
||||
"env_production": {
|
||||
"NODE_ENV": "production"
|
||||
}
|
||||
}
|
|
@ -1,17 +1,20 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
import { Task } from '$/types'
|
||||
import { Task, TaskUpdateInput } from '$prisma/client'
|
||||
import { depend } from 'velona'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
export const getTasks = async (limit?: number) => (await prisma.task.findMany()).slice(0, limit)
|
||||
export const getTasks = depend(
|
||||
{ prisma: prisma as { task: { findMany(): Promise<Task[]> } } },
|
||||
async ({ prisma }, limit?: number) =>
|
||||
(await prisma.task.findMany()).slice(0, limit)
|
||||
)
|
||||
|
||||
export const createTask = (label: Task['label']) =>
|
||||
prisma.task.create({ data: { label } })
|
||||
|
||||
export const updateTask = (
|
||||
id: Task['id'],
|
||||
partialTask: Partial<Pick<Task, 'label' | 'done'>>
|
||||
) => prisma.task.update({ where: { id }, data: partialTask })
|
||||
export const updateTask = (id: Task['id'], partialTask: TaskUpdateInput) =>
|
||||
prisma.task.update({ where: { id }, data: partialTask })
|
||||
|
||||
export const deleteTask = (id: Task['id']) =>
|
||||
prisma.task.delete({ where: { id } })
|
||||
|
|
35
frourio/server/test/server.test.ts
Normal file
35
frourio/server/test/server.test.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import controller from '$/api/tasks/controller'
|
||||
import { getTasks } from '$/service/tasks'
|
||||
|
||||
test('dependency injection into controller', async () => {
|
||||
let printedMessage = ''
|
||||
|
||||
const injectedController = controller.inject({
|
||||
getTasks: getTasks.inject({
|
||||
prisma: {
|
||||
task: {
|
||||
findMany: () =>
|
||||
Promise.resolve([
|
||||
{ id: 0, label: 'task1', done: false },
|
||||
{ id: 1, label: 'task2', done: false },
|
||||
{ id: 2, label: 'task3', done: true },
|
||||
{ id: 3, label: 'task4', done: true },
|
||||
{ id: 4, label: 'task5', done: false }
|
||||
])
|
||||
}
|
||||
}
|
||||
}),
|
||||
print: (text: string) => {
|
||||
printedMessage = text
|
||||
}
|
||||
})()
|
||||
|
||||
const limit = 3
|
||||
const message = 'test message'
|
||||
const res = await injectedController.get({
|
||||
query: { limit, message }
|
||||
})
|
||||
|
||||
expect(res.body).toHaveLength(limit)
|
||||
expect(printedMessage).toBe(message)
|
||||
})
|
|
@ -9,7 +9,8 @@
|
|||
"moduleResolution": "node",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"$/*": ["./*"]
|
||||
"$/*": ["./*"],
|
||||
"$prisma/*": ["./node_modules/.prisma/*"]
|
||||
},
|
||||
"rootDir": ".",
|
||||
"strict": true,
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
export type Task = {
|
||||
id: number
|
||||
label: string
|
||||
done: boolean
|
||||
}
|
||||
|
||||
export type UserInfo = {
|
||||
id: string
|
||||
name: string
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,8 @@
|
|||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"~/*": ["./*"],
|
||||
"$/*": ["./server/*"]
|
||||
"$/*": ["./server/*"],
|
||||
"$prisma/*": ["./server/node_modules/.prisma/*"]
|
||||
},
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
|
|
4464
frourio/yarn.lock
4464
frourio/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue