initial commit
This commit is contained in:
3
.eslintrc.json
Normal file
3
.eslintrc.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals"
|
||||
}
|
||||
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
.yarn/install-state.gz
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 mmedr25
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
32
README.md
Normal file
32
README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# How to use typeORM in nextjs 13/14
|
||||
|
||||
## Description
|
||||
- This is a boilerplate for nextjs and typeorm. I am using postgres as a database but you can configure to your liking. I also created a custom loader to automatically add entities and other resources to the configuration.
|
||||
|
||||
- Any file that should not be loaded need to be in a folder named "abstract". You can check the structure of the project if is not very clear.
|
||||
|
||||
- There are custom commands in package.json to do migrations manually
|
||||
|
||||
- enjoy :-)
|
||||
|
||||
|
||||
## Requirements:
|
||||
* next >= 13
|
||||
* typeorm @latest
|
||||
|
||||
## Installation:
|
||||
|
||||
- clone the repo
|
||||
|
||||
#### or
|
||||
|
||||
1. install nextjs@latest
|
||||
2. copy the "schema" folder in the root directory or "src"
|
||||
3. if copied in "src" modifie the custom commands to migration to match with the new path
|
||||
4. Change connection config in "schema/data-source.ts". you can as well see how the loader from "schema/loader.ts" works
|
||||
5. Copy "app/connection.ts" into your "app" folder
|
||||
6. add the following to next tsconfig.json:
|
||||
- "emitDecoratorMetadata": true,
|
||||
- "experimentalDecorators": true,
|
||||
- target: "esnext",
|
||||
6. Test if everything is working
|
||||
3
app/connection.ts
Normal file
3
app/connection.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { dbSource } from "@/schema";
|
||||
|
||||
export const db = await dbSource()
|
||||
BIN
app/favicon.ico
Normal file
BIN
app/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
33
app/globals.css
Normal file
33
app/globals.css
Normal file
@ -0,0 +1,33 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
:root {
|
||||
--foreground-rgb: 0, 0, 0;
|
||||
--background-start-rgb: 214, 219, 220;
|
||||
--background-end-rgb: 255, 255, 255;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--foreground-rgb: 255, 255, 255;
|
||||
--background-start-rgb: 0, 0, 0;
|
||||
--background-end-rgb: 0, 0, 0;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
color: rgb(var(--foreground-rgb));
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
transparent,
|
||||
rgb(var(--background-end-rgb))
|
||||
)
|
||||
rgb(var(--background-start-rgb));
|
||||
}
|
||||
|
||||
@layer utilities {
|
||||
.text-balance {
|
||||
text-wrap: balance;
|
||||
}
|
||||
}
|
||||
23
app/layout.tsx
Normal file
23
app/layout.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import "reflect-metadata";
|
||||
import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={inter.className}>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
21
app/page.tsx
Normal file
21
app/page.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import Image from "next/image";
|
||||
import { db } from "./connection";
|
||||
|
||||
|
||||
export default async function Home() {
|
||||
const user = await db.userRepository.findOneBy({email: "montheeric1@gmail.com"})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>{user?.email}</div>
|
||||
<div className="size-10">
|
||||
<Image
|
||||
alt="user avatar"
|
||||
src={user?.image ?? ""}
|
||||
className="object-cover"
|
||||
fill
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
docker-compose.yaml
Normal file
22
docker-compose.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres:15
|
||||
restart: always
|
||||
environment:
|
||||
POSTGRES_DB: photo
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASSWORD: test
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./data:/var/lib/postgresql/data
|
||||
|
||||
adminer:
|
||||
image: adminer
|
||||
restart: always
|
||||
ports:
|
||||
- "8080:8080"
|
||||
depends_on:
|
||||
- db
|
||||
14
next.config.mjs
Normal file
14
next.config.mjs
Normal file
@ -0,0 +1,14 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
|
||||
const nextConfig = {
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: "https",
|
||||
hostname: "**"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
5670
package-lock.json
generated
Normal file
5670
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
35
package.json
Normal file
35
package.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "nextjs-typeorm",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"typeorm": "ts-node -P ./schema/tsconfig.json ./node_modules/typeorm/cli.js",
|
||||
"migration:create": "npm run typeorm migration:create ./schema/migration/migrated",
|
||||
"migration:generate": "npm run typeorm migration:generate ./schema/migration/migrated -- -d ./schema/data-source.ts",
|
||||
"migration:run": "npm run typeorm migration:run -- -d ./schema/data-source.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "14.1.3",
|
||||
"pg": "^8.11.3",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"reflect-metadata": "^0.2.1",
|
||||
"typeorm": "^0.3.20"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.12.7",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"autoprefixer": "^10.0.1",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "14.1.3",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.3.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
6
postcss.config.js
Normal file
6
postcss.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
};
|
||||
1
public/next.svg
Normal file
1
public/next.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
1
public/vercel.svg
Normal file
1
public/vercel.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>
|
||||
|
After Width: | Height: | Size: 629 B |
22
schema/data-source.ts
Normal file
22
schema/data-source.ts
Normal file
@ -0,0 +1,22 @@
|
||||
"use node"
|
||||
import "reflect-metadata"
|
||||
import { DataSource, EntitySchema } from "typeorm"
|
||||
import { classLoader } from "./loader"
|
||||
|
||||
const isProduction = process.env.NODE_ENV === "production"
|
||||
|
||||
export const dataSource = new DataSource({
|
||||
type: "postgres",
|
||||
host: "localhost",
|
||||
port: 5432,
|
||||
username: "test",
|
||||
password: "test",
|
||||
database: "photo",
|
||||
synchronize: !isProduction,
|
||||
logging: !isProduction,
|
||||
migrationsRun: false,
|
||||
entities: classLoader("entity") as EntitySchema[],
|
||||
migrations: classLoader("migration") as Function[],
|
||||
subscribers: [],
|
||||
installExtensions: true
|
||||
})
|
||||
59
schema/entity/AccountEntity.ts
Normal file
59
schema/entity/AccountEntity.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
// import UserEntity from "./UserEntity"
|
||||
// import { transformer } from "../utils/transformers"
|
||||
|
||||
@Entity({ name: "accounts" })
|
||||
export default class AccountEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column({ type: "uuid" })
|
||||
userId!: string
|
||||
|
||||
@Column()
|
||||
type!: string
|
||||
|
||||
@Column()
|
||||
provider!: string
|
||||
|
||||
@Column()
|
||||
providerAccountId!: string
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
refresh_token!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
access_token!: string | null
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: "bigint",
|
||||
transformer: transformer.bigint,
|
||||
})
|
||||
expires_at!: number | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
token_type!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
scope!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
id_token!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
session_state!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
oauth_token_secret!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
oauth_token!: string | null
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.accounts, {
|
||||
createForeignKeyConstraints: true,
|
||||
})
|
||||
user!: Relation<UserEntity>
|
||||
}
|
||||
22
schema/entity/SessionEntity.ts
Normal file
22
schema/entity/SessionEntity.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
|
||||
|
||||
@Entity({ name: "sessions" })
|
||||
export default class SessionEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column({ unique: true })
|
||||
sessionToken!: string
|
||||
|
||||
@Column({ type: "uuid" })
|
||||
userId!: string
|
||||
|
||||
@Column({ transformer: transformer.date })
|
||||
expires!: string
|
||||
|
||||
@ManyToOne(() => UserEntity, (user) => user.sessions)
|
||||
user!: Relation<UserEntity>
|
||||
}
|
||||
9
schema/entity/TestMigrationEntity.ts
Normal file
9
schema/entity/TestMigrationEntity.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Column, Entity } from "typeorm"
|
||||
import { UserEntity } from "./UserEntity"
|
||||
import AbstractBaseEntity from "./abstract/AbstractBaseEntity"
|
||||
|
||||
@Entity({ name: "haha" })
|
||||
export default class TestMigrationEntity extends AbstractBaseEntity{
|
||||
@Column()
|
||||
provider!: string
|
||||
}
|
||||
33
schema/entity/UserEntity.ts
Normal file
33
schema/entity/UserEntity.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Column, Entity, OneToMany, PrimaryGeneratedColumn, type Relation } from "typeorm"
|
||||
import SessionEntity from "./SessionEntity"
|
||||
import AccountEntity from "./AccountEntity"
|
||||
import { transformer } from "../utils/transformers"
|
||||
import AbstractBaseEntity from "./abstract/AbstractBaseEntity"
|
||||
|
||||
@Entity({ name: "users" })
|
||||
export class UserEntity extends AbstractBaseEntity {
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
name!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true })
|
||||
// password!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true, unique: true })
|
||||
email!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true, transformer: transformer.date })
|
||||
// emailVerified!: string | null
|
||||
|
||||
@Column({ type: "varchar", nullable: true })
|
||||
image!: string | null
|
||||
|
||||
// @Column({ type: "varchar", nullable: true })
|
||||
// role!: string | null
|
||||
|
||||
@OneToMany(() => SessionEntity, (session) => session.userId)
|
||||
sessions!: Relation<SessionEntity>[]
|
||||
|
||||
@OneToMany(() => AccountEntity, (account) => account.userId)
|
||||
accounts!: Relation<AccountEntity>[]
|
||||
}
|
||||
17
schema/entity/VerificationTokenEntity.ts
Normal file
17
schema/entity/VerificationTokenEntity.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"
|
||||
import { transformer } from "../utils/transformers"
|
||||
|
||||
@Entity({ name: "verification_tokens" })
|
||||
export default class VerificationTokenEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
|
||||
@Column()
|
||||
token!: string
|
||||
|
||||
@Column()
|
||||
identifier!: string
|
||||
|
||||
@Column({ transformer: transformer.date })
|
||||
expires!: string
|
||||
}
|
||||
6
schema/entity/abstract/AbstractBaseEntity.ts
Normal file
6
schema/entity/abstract/AbstractBaseEntity.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { PrimaryGeneratedColumn } from "typeorm";
|
||||
|
||||
export default abstract class AbstractBaseEntity {
|
||||
@PrimaryGeneratedColumn("uuid")
|
||||
id!: string
|
||||
}
|
||||
17
schema/index.ts
Normal file
17
schema/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
"use node"
|
||||
import { dataSource } from "./data-source";
|
||||
import { UserEntity } from "./entity/UserEntity";
|
||||
|
||||
|
||||
let dbInstance = dataSource;
|
||||
// you can add a try catch
|
||||
export const dbSource = async () => {
|
||||
|
||||
if(!dataSource.isInitialized) {
|
||||
dbInstance = await dataSource.initialize();
|
||||
}
|
||||
|
||||
return {
|
||||
userRepository: dbInstance.getRepository(UserEntity),
|
||||
}
|
||||
}
|
||||
44
schema/loader.ts
Normal file
44
schema/loader.ts
Normal file
@ -0,0 +1,44 @@
|
||||
"use node"
|
||||
import fs from 'fs'
|
||||
|
||||
const BASE_DIR = "./schema" // the root directory for typeorm projet
|
||||
|
||||
const isPath = (path: string) => fs.existsSync(path)
|
||||
|
||||
const makeDir = (path: string) => {
|
||||
fs.mkdirSync(path)
|
||||
}
|
||||
|
||||
// will include ts files and exclude abstract folder
|
||||
const fileValidation = (val: string | Buffer) => {
|
||||
val = val as string
|
||||
return val.endsWith(".ts") && !val.toLocaleLowerCase().includes("abstract")
|
||||
}
|
||||
|
||||
const directoryReader = (folder: string) => {
|
||||
const filesDir = `${BASE_DIR}/${folder}`;
|
||||
|
||||
// you can also throw an error instead of creating the file
|
||||
if (!isPath(filesDir)) {
|
||||
makeDir(filesDir);
|
||||
return []
|
||||
}
|
||||
|
||||
return fs
|
||||
.readdirSync(filesDir, {recursive: true})
|
||||
.filter(fileValidation) as string[]
|
||||
}
|
||||
|
||||
const filesClassReader = (files: string[], folder: string) => {
|
||||
return files.flatMap(filename => {
|
||||
filename = filename.split(".ts")[0]
|
||||
const entName = require(`./${folder}/${filename}`)
|
||||
|
||||
return Object.values(entName)
|
||||
})
|
||||
}
|
||||
|
||||
export const classLoader = (folder: string) => {
|
||||
const files = directoryReader(folder);
|
||||
return filesClassReader(files, folder);
|
||||
}
|
||||
26
schema/migration/1748809100005-migrated.ts
Normal file
26
schema/migration/1748809100005-migrated.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Migrated1748809100005 implements MigrationInterface {
|
||||
name = 'Migrated1748809100005'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE "sessions" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "sessionToken" character varying NOT NULL, "userId" uuid NOT NULL, "expires" character varying NOT NULL, CONSTRAINT "UQ_8b5e2ec52e335c0fe16d7ec3584" UNIQUE ("sessionToken"), CONSTRAINT "PK_3238ef96f18b355b671619111bc" PRIMARY KEY ("id"))`);
|
||||
await queryRunner.query(`CREATE TABLE "users" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "name" character varying, "email" character varying, "image" character varying, CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email"), CONSTRAINT "PK_a3ffb1c0c8416b9fc6f907b7433" PRIMARY KEY ("id"))`);
|
||||
await queryRunner.query(`CREATE TABLE "accounts" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "userId" uuid NOT NULL, "type" character varying NOT NULL, "provider" character varying NOT NULL, "providerAccountId" character varying NOT NULL, "refresh_token" character varying, "access_token" character varying, "expires_at" bigint, "token_type" character varying, "scope" character varying, "id_token" character varying, "session_state" character varying, "oauth_token_secret" character varying, "oauth_token" character varying, CONSTRAINT "PK_5a7a02c20412299d198e097a8fe" PRIMARY KEY ("id"))`);
|
||||
await queryRunner.query(`CREATE TABLE "haha" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "provider" character varying NOT NULL, CONSTRAINT "PK_ff5514d145b493f9462bf90639d" PRIMARY KEY ("id"))`);
|
||||
await queryRunner.query(`CREATE TABLE "verification_tokens" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "token" character varying NOT NULL, "identifier" character varying NOT NULL, "expires" character varying NOT NULL, CONSTRAINT "PK_f2d4d7a2aa57ef199e61567db22" PRIMARY KEY ("id"))`);
|
||||
await queryRunner.query(`ALTER TABLE "sessions" ADD CONSTRAINT "FK_57de40bc620f456c7311aa3a1e6" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE "accounts" ADD CONSTRAINT "FK_3aa23c0a6d107393e8b40e3e2a6" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "accounts" DROP CONSTRAINT "FK_3aa23c0a6d107393e8b40e3e2a6"`);
|
||||
await queryRunner.query(`ALTER TABLE "sessions" DROP CONSTRAINT "FK_57de40bc620f456c7311aa3a1e6"`);
|
||||
await queryRunner.query(`DROP TABLE "verification_tokens"`);
|
||||
await queryRunner.query(`DROP TABLE "haha"`);
|
||||
await queryRunner.query(`DROP TABLE "accounts"`);
|
||||
await queryRunner.query(`DROP TABLE "users"`);
|
||||
await queryRunner.query(`DROP TABLE "sessions"`);
|
||||
}
|
||||
|
||||
}
|
||||
109
schema/tsconfig.json
Normal file
109
schema/tsconfig.json
Normal file
@ -0,0 +1,109 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"lib": ["ESNext"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
"experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "NodeNext", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
||||
12
schema/utils/transformers.ts
Normal file
12
schema/utils/transformers.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { ValueTransformer } from "typeorm"
|
||||
|
||||
export const transformer: Record<"date" | "bigint", ValueTransformer> = {
|
||||
date: {
|
||||
from: (date: string | null) => date && new Date(parseInt(date, 10)),
|
||||
to: (date?: Date) => date?.valueOf().toString(),
|
||||
},
|
||||
bigint: {
|
||||
from: (bigInt: string | null) => bigInt && parseInt(bigInt, 10),
|
||||
to: (bigInt?: number) => bigInt?.toString(),
|
||||
},
|
||||
}
|
||||
20
tailwind.config.ts
Normal file
20
tailwind.config.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import type { Config } from "tailwindcss";
|
||||
|
||||
const config: Config = {
|
||||
content: [
|
||||
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
backgroundImage: {
|
||||
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
||||
"gradient-conic":
|
||||
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
};
|
||||
export default config;
|
||||
29
tsconfig.json
Normal file
29
tsconfig.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user