nestforge-generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +371 -0
- package/README.pt-BR.md +370 -0
- package/dist/features/auth-strategy.js +19 -0
- package/dist/features/auth-strategy.js.map +1 -0
- package/dist/features/database.js +59 -0
- package/dist/features/database.js.map +1 -0
- package/dist/features/dependencies.js +57 -0
- package/dist/features/dependencies.js.map +1 -0
- package/dist/features/language.js +172 -0
- package/dist/features/language.js.map +1 -0
- package/dist/features/markers.js +116 -0
- package/dist/features/markers.js.map +1 -0
- package/dist/generator.js +120 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.js +137 -0
- package/dist/prompts.js.map +1 -0
- package/package.json +76 -0
- package/templates/drizzle/.env.example +45 -0
- package/templates/drizzle/.env.test +38 -0
- package/templates/drizzle/.github/workflows/ci.yml +119 -0
- package/templates/drizzle/ARCHITECTURE.md +227 -0
- package/templates/drizzle/ARCHITECTURE.pt-BR.md +225 -0
- package/templates/drizzle/CODE_OF_CONDUCT.md +29 -0
- package/templates/drizzle/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/drizzle/CONTRIBUTING.md +57 -0
- package/templates/drizzle/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/drizzle/Dockerfile +43 -0
- package/templates/drizzle/LICENSE +21 -0
- package/templates/drizzle/README.md +257 -0
- package/templates/drizzle/README.pt-BR.md +257 -0
- package/templates/drizzle/ROADMAP.md +143 -0
- package/templates/drizzle/ROADMAP.pt-BR.md +143 -0
- package/templates/drizzle/TESTING.md +136 -0
- package/templates/drizzle/TESTING.pt-BR.md +136 -0
- package/templates/drizzle/docker-compose.yml +82 -0
- package/templates/drizzle/docs/adding-a-module.md +585 -0
- package/templates/drizzle/docs/features-markers.md +457 -0
- package/templates/drizzle/drizzle.config.ts +49 -0
- package/templates/drizzle/nest-cli.json +8 -0
- package/templates/drizzle/package.json +96 -0
- package/templates/drizzle/src/app.module.ts +72 -0
- package/templates/drizzle/src/auth/auth.controller.ts +283 -0
- package/templates/drizzle/src/auth/auth.module.ts +81 -0
- package/templates/drizzle/src/auth/auth.service.spec.ts +111 -0
- package/templates/drizzle/src/auth/auth.service.ts +631 -0
- package/templates/drizzle/src/auth/drizzle-session.store.ts +263 -0
- package/templates/drizzle/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/login.dto.ts +10 -0
- package/templates/drizzle/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/drizzle/src/auth/dto/register.dto.ts +11 -0
- package/templates/drizzle/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/drizzle/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/drizzle/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/drizzle/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/drizzle/src/auth/session.service.spec.ts +74 -0
- package/templates/drizzle/src/auth/session.service.ts +96 -0
- package/templates/drizzle/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/drizzle/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/drizzle/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/drizzle/src/auth/token.service.ts +175 -0
- package/templates/drizzle/src/common/constants/permissions.ts +8 -0
- package/templates/drizzle/src/common/constants/role-permissions.ts +9 -0
- package/templates/drizzle/src/common/constants/role.enum.ts +5 -0
- package/templates/drizzle/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/drizzle/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/drizzle/src/common/decorators/public.decorator.ts +4 -0
- package/templates/drizzle/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/drizzle/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/drizzle/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/drizzle/src/common/guards/permissions.guard.ts +28 -0
- package/templates/drizzle/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/drizzle/src/common/guards/roles.guard.ts +24 -0
- package/templates/drizzle/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/drizzle/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/drizzle/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/drizzle/src/common/utils/hash.util.ts +5 -0
- package/templates/drizzle/src/config/env.validation.ts +50 -0
- package/templates/drizzle/src/database/database-lifecycle.service.ts +30 -0
- package/templates/drizzle/src/database/database.constants.ts +2 -0
- package/templates/drizzle/src/database/database.decorators.ts +5 -0
- package/templates/drizzle/src/database/database.module.ts +96 -0
- package/templates/drizzle/src/database/database.types.ts +28 -0
- package/templates/drizzle/src/database/schema/index.ts +11 -0
- package/templates/drizzle/src/database/schema/mysql.schema.ts +215 -0
- package/templates/drizzle/src/database/schema/postgres.schema.ts +218 -0
- package/templates/drizzle/src/database/schema/sqlite.schema.ts +190 -0
- package/templates/drizzle/src/database/seed.ts +152 -0
- package/templates/drizzle/src/health/health.controller.ts +49 -0
- package/templates/drizzle/src/health/health.module.ts +19 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.spec.ts +71 -0
- package/templates/drizzle/src/health/indicators/drizzle-health.indicator.ts +52 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/drizzle/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/drizzle/src/mail/mail.module.ts +12 -0
- package/templates/drizzle/src/mail/mail.processor.ts +48 -0
- package/templates/drizzle/src/mail/mail.service.ts +24 -0
- package/templates/drizzle/src/mail/templates/email-templates.ts +28 -0
- package/templates/drizzle/src/main.ts +145 -0
- package/templates/drizzle/src/metrics/metrics.controller.ts +22 -0
- package/templates/drizzle/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/drizzle/src/metrics/metrics.module.ts +12 -0
- package/templates/drizzle/src/metrics/metrics.service.ts +34 -0
- package/templates/drizzle/src/types/express-session.d.ts +13 -0
- package/templates/drizzle/src/users/dto/create-user.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/drizzle/src/users/dto/update-user.dto.ts +6 -0
- package/templates/drizzle/src/users/entities/user.entity.ts +23 -0
- package/templates/drizzle/src/users/users.controller.ts +165 -0
- package/templates/drizzle/src/users/users.module.ts +10 -0
- package/templates/drizzle/src/users/users.service.spec.ts +301 -0
- package/templates/drizzle/src/users/users.service.ts +213 -0
- package/templates/drizzle/test/auth.e2e-spec.ts +114 -0
- package/templates/drizzle/test/session-auth.e2e-spec.ts +163 -0
- package/templates/drizzle/test/users.e2e-spec.ts +212 -0
- package/templates/drizzle/test/utils/clean-database.ts +104 -0
- package/templates/drizzle/test/utils/e2e-setup.ts +77 -0
- package/templates/drizzle/tsconfig.build.json +4 -0
- package/templates/drizzle/tsconfig.json +25 -0
- package/templates/drizzle/vitest.config.ts +20 -0
- package/templates/drizzle/vitest.e2e.config.ts +19 -0
- package/templates/prisma/.env.example +44 -0
- package/templates/prisma/.env.test +37 -0
- package/templates/prisma/.github/workflows/ci.yml +109 -0
- package/templates/prisma/ARCHITECTURE.md +70 -0
- package/templates/prisma/ARCHITECTURE.pt-BR.md +63 -0
- package/templates/prisma/CODE_OF_CONDUCT.md +29 -0
- package/templates/prisma/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/prisma/CONTRIBUTING.md +57 -0
- package/templates/prisma/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/prisma/Dockerfile +33 -0
- package/templates/prisma/LICENSE +21 -0
- package/templates/prisma/README.md +267 -0
- package/templates/prisma/README.pt-BR.md +267 -0
- package/templates/prisma/ROADMAP.md +75 -0
- package/templates/prisma/ROADMAP.pt-BR.md +65 -0
- package/templates/prisma/TESTING.md +123 -0
- package/templates/prisma/TESTING.pt-BR.md +123 -0
- package/templates/prisma/docker-compose.yml +78 -0
- package/templates/prisma/docs/adding-a-module.md +230 -0
- package/templates/prisma/docs/features-markers.md +50 -0
- package/templates/prisma/nest-cli.json +8 -0
- package/templates/prisma/package.json +95 -0
- package/templates/prisma/prisma/schema.prisma +105 -0
- package/templates/prisma/prisma/seed.ts +46 -0
- package/templates/prisma/src/app.module.ts +72 -0
- package/templates/prisma/src/auth/auth.controller.ts +283 -0
- package/templates/prisma/src/auth/auth.module.ts +59 -0
- package/templates/prisma/src/auth/auth.service.spec.ts +53 -0
- package/templates/prisma/src/auth/auth.service.ts +224 -0
- package/templates/prisma/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/login.dto.ts +10 -0
- package/templates/prisma/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/prisma/src/auth/dto/register.dto.ts +11 -0
- package/templates/prisma/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/prisma/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/prisma/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/prisma/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/prisma/src/auth/session.service.spec.ts +74 -0
- package/templates/prisma/src/auth/session.service.ts +96 -0
- package/templates/prisma/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/prisma/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/prisma/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/prisma/src/auth/token.service.ts +84 -0
- package/templates/prisma/src/common/constants/permissions.ts +8 -0
- package/templates/prisma/src/common/constants/role-permissions.ts +9 -0
- package/templates/prisma/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/prisma/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/prisma/src/common/decorators/public.decorator.ts +4 -0
- package/templates/prisma/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/prisma/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/prisma/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/prisma/src/common/guards/permissions.guard.ts +28 -0
- package/templates/prisma/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/prisma/src/common/guards/roles.guard.ts +24 -0
- package/templates/prisma/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/prisma/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/prisma/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/prisma/src/common/utils/hash.util.ts +5 -0
- package/templates/prisma/src/config/env.validation.ts +49 -0
- package/templates/prisma/src/database/prisma.module.ts +9 -0
- package/templates/prisma/src/database/prisma.service.ts +13 -0
- package/templates/prisma/src/health/health.controller.ts +49 -0
- package/templates/prisma/src/health/health.module.ts +19 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.spec.ts +22 -0
- package/templates/prisma/src/health/indicators/prisma-health.indicator.ts +19 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/prisma/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/prisma/src/mail/mail.module.ts +12 -0
- package/templates/prisma/src/mail/mail.processor.ts +48 -0
- package/templates/prisma/src/mail/mail.service.ts +24 -0
- package/templates/prisma/src/mail/templates/email-templates.ts +28 -0
- package/templates/prisma/src/main.ts +92 -0
- package/templates/prisma/src/metrics/metrics.controller.ts +22 -0
- package/templates/prisma/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/prisma/src/metrics/metrics.module.ts +12 -0
- package/templates/prisma/src/metrics/metrics.service.ts +34 -0
- package/templates/prisma/src/types/express-session.d.ts +13 -0
- package/templates/prisma/src/users/dto/create-user.dto.ts +12 -0
- package/templates/prisma/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/prisma/src/users/dto/update-user.dto.ts +6 -0
- package/templates/prisma/src/users/entities/user.entity.ts +20 -0
- package/templates/prisma/src/users/users.controller.ts +165 -0
- package/templates/prisma/src/users/users.module.ts +10 -0
- package/templates/prisma/src/users/users.service.spec.ts +104 -0
- package/templates/prisma/src/users/users.service.ts +114 -0
- package/templates/prisma/test/auth.e2e-spec.ts +75 -0
- package/templates/prisma/test/session-auth.e2e-spec.ts +163 -0
- package/templates/prisma/test/users.e2e-spec.ts +106 -0
- package/templates/prisma/test/utils/clean-database.ts +14 -0
- package/templates/prisma/test/utils/e2e-setup.ts +58 -0
- package/templates/prisma/tsconfig.build.json +4 -0
- package/templates/prisma/tsconfig.json +25 -0
- package/templates/prisma/vitest.config.ts +20 -0
- package/templates/prisma/vitest.e2e.config.ts +19 -0
- package/templates/typeorm/.env.example +45 -0
- package/templates/typeorm/.env.test +38 -0
- package/templates/typeorm/.github/workflows/ci.yml +116 -0
- package/templates/typeorm/ARCHITECTURE.md +158 -0
- package/templates/typeorm/ARCHITECTURE.pt-BR.md +156 -0
- package/templates/typeorm/CODE_OF_CONDUCT.md +29 -0
- package/templates/typeorm/CODE_OF_CONDUCT.pt-BR.md +27 -0
- package/templates/typeorm/CONTRIBUTING.md +57 -0
- package/templates/typeorm/CONTRIBUTING.pt-BR.md +54 -0
- package/templates/typeorm/Dockerfile +43 -0
- package/templates/typeorm/LICENSE +21 -0
- package/templates/typeorm/README.md +266 -0
- package/templates/typeorm/README.pt-BR.md +266 -0
- package/templates/typeorm/ROADMAP.md +79 -0
- package/templates/typeorm/ROADMAP.pt-BR.md +67 -0
- package/templates/typeorm/TESTING.md +114 -0
- package/templates/typeorm/TESTING.pt-BR.md +114 -0
- package/templates/typeorm/docker-compose.yml +78 -0
- package/templates/typeorm/docs/adding-a-module.md +369 -0
- package/templates/typeorm/docs/features-markers.md +50 -0
- package/templates/typeorm/nest-cli.json +8 -0
- package/templates/typeorm/package.json +98 -0
- package/templates/typeorm/src/app.module.ts +72 -0
- package/templates/typeorm/src/auth/auth.controller.ts +283 -0
- package/templates/typeorm/src/auth/auth.module.ts +86 -0
- package/templates/typeorm/src/auth/auth.service.spec.ts +111 -0
- package/templates/typeorm/src/auth/auth.service.ts +346 -0
- package/templates/typeorm/src/auth/dto/forgot-password.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/login.dto.ts +10 -0
- package/templates/typeorm/src/auth/dto/refresh-token.dto.ts +9 -0
- package/templates/typeorm/src/auth/dto/register.dto.ts +11 -0
- package/templates/typeorm/src/auth/dto/reset-password.dto.ts +10 -0
- package/templates/typeorm/src/auth/entities/email-verification-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/oauth-account.entity.ts +50 -0
- package/templates/typeorm/src/auth/entities/password-reset-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/refresh-token.entity.ts +69 -0
- package/templates/typeorm/src/auth/entities/session.entity.ts +50 -0
- package/templates/typeorm/src/auth/guards/github-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/google-auth.guard.ts +10 -0
- package/templates/typeorm/src/auth/guards/jwt-auth.guard.ts +25 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.spec.ts +77 -0
- package/templates/typeorm/src/auth/guards/session-auth.guard.ts +37 -0
- package/templates/typeorm/src/auth/session.service.spec.ts +74 -0
- package/templates/typeorm/src/auth/session.service.ts +96 -0
- package/templates/typeorm/src/auth/strategies/github.strategy.ts +41 -0
- package/templates/typeorm/src/auth/strategies/google.strategy.ts +43 -0
- package/templates/typeorm/src/auth/strategies/jwt.strategy.ts +25 -0
- package/templates/typeorm/src/auth/token.service.ts +115 -0
- package/templates/typeorm/src/common/constants/permissions.ts +8 -0
- package/templates/typeorm/src/common/constants/role-permissions.ts +9 -0
- package/templates/typeorm/src/common/constants/role.enum.ts +5 -0
- package/templates/typeorm/src/common/decorators/current-user.decorator.ts +8 -0
- package/templates/typeorm/src/common/decorators/permissions.decorator.ts +7 -0
- package/templates/typeorm/src/common/decorators/public.decorator.ts +4 -0
- package/templates/typeorm/src/common/decorators/roles.decorator.ts +6 -0
- package/templates/typeorm/src/common/filters/http-exception.filter.ts +34 -0
- package/templates/typeorm/src/common/guards/permissions.guard.spec.ts +54 -0
- package/templates/typeorm/src/common/guards/permissions.guard.ts +28 -0
- package/templates/typeorm/src/common/guards/roles.guard.spec.ts +37 -0
- package/templates/typeorm/src/common/guards/roles.guard.ts +24 -0
- package/templates/typeorm/src/common/interceptors/logging.interceptor.ts +23 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.spec.ts +97 -0
- package/templates/typeorm/src/common/middleware/csrf.middleware.ts +46 -0
- package/templates/typeorm/src/common/utils/avatar-storage.util.ts +32 -0
- package/templates/typeorm/src/common/utils/hash.util.ts +5 -0
- package/templates/typeorm/src/config/env.validation.ts +50 -0
- package/templates/typeorm/src/database/data-source.ts +20 -0
- package/templates/typeorm/src/database/database.module.ts +39 -0
- package/templates/typeorm/src/database/seed.ts +81 -0
- package/templates/typeorm/src/database/typeorm-options.ts +49 -0
- package/templates/typeorm/src/health/health.controller.ts +49 -0
- package/templates/typeorm/src/health/health.module.ts +19 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.spec.ts +54 -0
- package/templates/typeorm/src/health/indicators/redis-health.indicator.ts +33 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.spec.ts +49 -0
- package/templates/typeorm/src/health/indicators/typeorm-health.indicator.ts +37 -0
- package/templates/typeorm/src/mail/mail.module.ts +12 -0
- package/templates/typeorm/src/mail/mail.processor.ts +48 -0
- package/templates/typeorm/src/mail/mail.service.ts +24 -0
- package/templates/typeorm/src/mail/templates/email-templates.ts +28 -0
- package/templates/typeorm/src/main.ts +107 -0
- package/templates/typeorm/src/metrics/metrics.controller.ts +22 -0
- package/templates/typeorm/src/metrics/metrics.interceptor.ts +30 -0
- package/templates/typeorm/src/metrics/metrics.module.ts +12 -0
- package/templates/typeorm/src/metrics/metrics.service.ts +34 -0
- package/templates/typeorm/src/types/express-session.d.ts +13 -0
- package/templates/typeorm/src/users/dto/create-user.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/find-users-query.dto.ts +12 -0
- package/templates/typeorm/src/users/dto/update-user.dto.ts +6 -0
- package/templates/typeorm/src/users/entities/user.entity.ts +113 -0
- package/templates/typeorm/src/users/users.controller.ts +165 -0
- package/templates/typeorm/src/users/users.module.ts +13 -0
- package/templates/typeorm/src/users/users.service.spec.ts +183 -0
- package/templates/typeorm/src/users/users.service.ts +124 -0
- package/templates/typeorm/test/auth.e2e-spec.ts +111 -0
- package/templates/typeorm/test/session-auth.e2e-spec.ts +159 -0
- package/templates/typeorm/test/users.e2e-spec.ts +183 -0
- package/templates/typeorm/test/utils/clean-database.ts +65 -0
- package/templates/typeorm/test/utils/e2e-setup.ts +77 -0
- package/templates/typeorm/tsconfig.build.json +4 -0
- package/templates/typeorm/tsconfig.json +25 -0
- package/templates/typeorm/vitest.config.ts +20 -0
- package/templates/typeorm/vitest.e2e.config.ts +19 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const envSchema = z.object({
|
|
4
|
+
NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),
|
|
5
|
+
PORT: z.coerce.number().default(3000),
|
|
6
|
+
APP_URL: z.string().url().default('http://localhost:3000'),
|
|
7
|
+
CORS_ORIGINS: z.string().min(1).default('http://localhost:5173'),
|
|
8
|
+
DB_TYPE: z.enum(['postgres', 'mysql', 'sqlite']).default('postgres'),
|
|
9
|
+
DATABASE_URL: z.string().url(),
|
|
10
|
+
// nestforge:feature:auth:token
|
|
11
|
+
JWT_ACCESS_SECRET: z.string().min(16),
|
|
12
|
+
JWT_ACCESS_EXPIRES_IN: z.string().default('15m'),
|
|
13
|
+
JWT_REFRESH_SECRET: z.string().min(16),
|
|
14
|
+
JWT_REFRESH_EXPIRES_IN: z.string().default('7d'),
|
|
15
|
+
// nestforge:feature:auth:token:end
|
|
16
|
+
REDIS_HOST: z.string().default('localhost'),
|
|
17
|
+
REDIS_PORT: z.coerce.number().default(6379),
|
|
18
|
+
MAIL_HOST: z.string().default('localhost'),
|
|
19
|
+
MAIL_PORT: z.coerce.number().default(1025),
|
|
20
|
+
MAIL_FROM: z.string().default('NestForge <no-reply@nestforge.dev>'),
|
|
21
|
+
GOOGLE_CLIENT_ID: z.string().optional(),
|
|
22
|
+
GOOGLE_CLIENT_SECRET: z.string().optional(),
|
|
23
|
+
GITHUB_CLIENT_ID: z.string().optional(),
|
|
24
|
+
GITHUB_CLIENT_SECRET: z.string().optional(),
|
|
25
|
+
THROTTLE_TTL: z.coerce.number().default(60),
|
|
26
|
+
THROTTLE_LIMIT: z.coerce.number().default(100),
|
|
27
|
+
// nestforge:feature:auth:session
|
|
28
|
+
ENABLE_CSRF: z
|
|
29
|
+
.enum(['true', 'false'])
|
|
30
|
+
.transform((value) => value === 'true')
|
|
31
|
+
.default('true'),
|
|
32
|
+
SESSION_SECRET: z.string().min(32),
|
|
33
|
+
SESSION_MAX_AGE: z.coerce.number().positive().default(604800000),
|
|
34
|
+
// nestforge:feature:auth:session:end
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type EnvConfig = z.infer<typeof envSchema>;
|
|
38
|
+
|
|
39
|
+
export function validateEnv(config: Record<string, unknown>): EnvConfig {
|
|
40
|
+
const parsed = envSchema.safeParse(config);
|
|
41
|
+
|
|
42
|
+
if (!parsed.success) {
|
|
43
|
+
const issues = parsed.error.issues
|
|
44
|
+
.map((issue) => `${issue.path.join('.')}: ${issue.message}`)
|
|
45
|
+
.join('\n');
|
|
46
|
+
throw new Error(`Variáveis de ambiente inválidas:\n${issues}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return parsed.data;
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inject,
|
|
3
|
+
Injectable,
|
|
4
|
+
OnApplicationShutdown,
|
|
5
|
+
} from '@nestjs/common';
|
|
6
|
+
import { DATABASE_CLIENT } from './database.constants';
|
|
7
|
+
import type { DatabaseClient } from './database.types';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class DatabaseLifecycleService
|
|
11
|
+
implements OnApplicationShutdown {
|
|
12
|
+
constructor(
|
|
13
|
+
@Inject(DATABASE_CLIENT)
|
|
14
|
+
private readonly client: DatabaseClient,
|
|
15
|
+
) { }
|
|
16
|
+
|
|
17
|
+
async onApplicationShutdown(): Promise<void> {
|
|
18
|
+
// nestforge:feature:database:postgres
|
|
19
|
+
await this.client.end();
|
|
20
|
+
// nestforge:feature:database:postgres:end
|
|
21
|
+
|
|
22
|
+
// nestforge:feature:database:mysql
|
|
23
|
+
await this.client.end();
|
|
24
|
+
// nestforge:feature:database:mysql:end
|
|
25
|
+
|
|
26
|
+
// nestforge:feature:database:sqlite
|
|
27
|
+
this.client.close();
|
|
28
|
+
// nestforge:feature:database:sqlite:end
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Global, Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import * as schema from './schema';
|
|
4
|
+
import {
|
|
5
|
+
DATABASE_CLIENT,
|
|
6
|
+
DRIZZLE_DATABASE,
|
|
7
|
+
} from './database.constants';
|
|
8
|
+
import {
|
|
9
|
+
DatabaseClient,
|
|
10
|
+
DrizzleDatabase,
|
|
11
|
+
} from './database.types';
|
|
12
|
+
import { DatabaseLifecycleService } from './database-lifecycle.service';
|
|
13
|
+
|
|
14
|
+
// nestforge:feature:database:postgres
|
|
15
|
+
import { Pool } from 'pg';
|
|
16
|
+
import { drizzle as createDrizzle } from 'drizzle-orm/node-postgres';
|
|
17
|
+
// nestforge:feature:database:postgres:end
|
|
18
|
+
|
|
19
|
+
// nestforge:feature:database:mysql
|
|
20
|
+
import { createPool } from 'mysql2/promise';
|
|
21
|
+
import { drizzle as createDrizzle } from 'drizzle-orm/mysql2';
|
|
22
|
+
// nestforge:feature:database:mysql:end
|
|
23
|
+
|
|
24
|
+
// nestforge:feature:database:sqlite
|
|
25
|
+
import BetterSqlite3 from 'better-sqlite3';
|
|
26
|
+
import { drizzle as createDrizzle } from 'drizzle-orm/better-sqlite3';
|
|
27
|
+
// nestforge:feature:database:sqlite:end
|
|
28
|
+
|
|
29
|
+
@Global()
|
|
30
|
+
@Module({
|
|
31
|
+
providers: [
|
|
32
|
+
{
|
|
33
|
+
provide: DATABASE_CLIENT,
|
|
34
|
+
inject: [ConfigService],
|
|
35
|
+
useFactory: (
|
|
36
|
+
configService: ConfigService,
|
|
37
|
+
): DatabaseClient => {
|
|
38
|
+
const databaseUrl =
|
|
39
|
+
configService.getOrThrow<string>(
|
|
40
|
+
'DATABASE_URL',
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// nestforge:feature:database:postgres
|
|
44
|
+
return new Pool({
|
|
45
|
+
connectionString: databaseUrl,
|
|
46
|
+
});
|
|
47
|
+
// nestforge:feature:database:postgres:end
|
|
48
|
+
|
|
49
|
+
// nestforge:feature:database:mysql
|
|
50
|
+
return createPool(databaseUrl);
|
|
51
|
+
// nestforge:feature:database:mysql:end
|
|
52
|
+
|
|
53
|
+
// nestforge:feature:database:sqlite
|
|
54
|
+
const databasePath = databaseUrl.replace(
|
|
55
|
+
/^file:/,
|
|
56
|
+
'',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return new BetterSqlite3(databasePath);
|
|
60
|
+
// nestforge:feature:database:sqlite:end
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
provide: DRIZZLE_DATABASE,
|
|
65
|
+
inject: [DATABASE_CLIENT],
|
|
66
|
+
useFactory: (
|
|
67
|
+
client: DatabaseClient,
|
|
68
|
+
): DrizzleDatabase => {
|
|
69
|
+
// nestforge:feature:database:postgres
|
|
70
|
+
return createDrizzle(client, {
|
|
71
|
+
schema,
|
|
72
|
+
});
|
|
73
|
+
// nestforge:feature:database:postgres:end
|
|
74
|
+
|
|
75
|
+
// nestforge:feature:database:mysql
|
|
76
|
+
return createDrizzle(client, {
|
|
77
|
+
schema,
|
|
78
|
+
mode: 'default',
|
|
79
|
+
});
|
|
80
|
+
// nestforge:feature:database:mysql:end
|
|
81
|
+
|
|
82
|
+
// nestforge:feature:database:sqlite
|
|
83
|
+
return createDrizzle(client, {
|
|
84
|
+
schema,
|
|
85
|
+
});
|
|
86
|
+
// nestforge:feature:database:sqlite:end
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
DatabaseLifecycleService,
|
|
90
|
+
],
|
|
91
|
+
exports: [
|
|
92
|
+
DATABASE_CLIENT,
|
|
93
|
+
DRIZZLE_DATABASE,
|
|
94
|
+
],
|
|
95
|
+
})
|
|
96
|
+
export class DatabaseModule { }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as schema from './schema';
|
|
2
|
+
|
|
3
|
+
// nestforge:feature:database:postgres
|
|
4
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
5
|
+
import type { Pool } from 'pg';
|
|
6
|
+
|
|
7
|
+
export type DatabaseClient = Pool;
|
|
8
|
+
export type DrizzleDatabase =
|
|
9
|
+
NodePgDatabase<typeof schema>;
|
|
10
|
+
// nestforge:feature:database:postgres:end
|
|
11
|
+
|
|
12
|
+
// nestforge:feature:database:mysql
|
|
13
|
+
import type { MySql2Database } from 'drizzle-orm/mysql2';
|
|
14
|
+
import type { Pool as MySqlPool } from 'mysql2/promise';
|
|
15
|
+
|
|
16
|
+
export type DatabaseClient = MySqlPool;
|
|
17
|
+
export type DrizzleDatabase =
|
|
18
|
+
MySql2Database<typeof schema>;
|
|
19
|
+
// nestforge:feature:database:mysql:end
|
|
20
|
+
|
|
21
|
+
// nestforge:feature:database:sqlite
|
|
22
|
+
import type { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
23
|
+
import type BetterSqlite3 from 'better-sqlite3';
|
|
24
|
+
|
|
25
|
+
export type DatabaseClient = BetterSqlite3.Database;
|
|
26
|
+
export type DrizzleDatabase =
|
|
27
|
+
BetterSQLite3Database<typeof schema>;
|
|
28
|
+
// nestforge:feature:database:sqlite:end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// nestforge:feature:database:postgres
|
|
2
|
+
export * from './postgres.schema';
|
|
3
|
+
// nestforge:feature:database:postgres:end
|
|
4
|
+
|
|
5
|
+
// nestforge:feature:database:mysql
|
|
6
|
+
export * from './mysql.schema';
|
|
7
|
+
// nestforge:feature:database:mysql:end
|
|
8
|
+
|
|
9
|
+
// nestforge:feature:database:sqlite
|
|
10
|
+
export * from './sqlite.schema';
|
|
11
|
+
// nestforge:feature:database:sqlite:end
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// nestforge:feature-file:database:mysql
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { sql } from 'drizzle-orm';
|
|
4
|
+
import {
|
|
5
|
+
bigint,
|
|
6
|
+
datetime,
|
|
7
|
+
index,
|
|
8
|
+
mysqlEnum,
|
|
9
|
+
mysqlTable,
|
|
10
|
+
text,
|
|
11
|
+
uniqueIndex,
|
|
12
|
+
varchar,
|
|
13
|
+
} from 'drizzle-orm/mysql-core';
|
|
14
|
+
|
|
15
|
+
export const users = mysqlTable('users', {
|
|
16
|
+
id: varchar('id', { length: 36 })
|
|
17
|
+
.$defaultFn(() => randomUUID())
|
|
18
|
+
.primaryKey(),
|
|
19
|
+
name: varchar('name', { length: 120 }).notNull(),
|
|
20
|
+
email: varchar('email', { length: 255 })
|
|
21
|
+
.notNull()
|
|
22
|
+
.unique(),
|
|
23
|
+
passwordHash: varchar('password_hash', {
|
|
24
|
+
length: 255,
|
|
25
|
+
}),
|
|
26
|
+
role: mysqlEnum('role', [
|
|
27
|
+
'ADMIN',
|
|
28
|
+
'MANAGER',
|
|
29
|
+
'USER',
|
|
30
|
+
])
|
|
31
|
+
.default('USER')
|
|
32
|
+
.notNull(),
|
|
33
|
+
avatarUrl: varchar('avatar_url', { length: 500 }),
|
|
34
|
+
emailVerifiedAt: datetime('email_verified_at', {
|
|
35
|
+
mode: 'date',
|
|
36
|
+
}),
|
|
37
|
+
createdAt: datetime('created_at', {
|
|
38
|
+
mode: 'date',
|
|
39
|
+
})
|
|
40
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
41
|
+
.notNull(),
|
|
42
|
+
updatedAt: datetime('updated_at', {
|
|
43
|
+
mode: 'date',
|
|
44
|
+
})
|
|
45
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
46
|
+
.$onUpdate(() => new Date())
|
|
47
|
+
.notNull(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const oauthAccounts = mysqlTable(
|
|
51
|
+
'oauth_accounts',
|
|
52
|
+
{
|
|
53
|
+
id: varchar('id', { length: 36 })
|
|
54
|
+
.$defaultFn(() => randomUUID())
|
|
55
|
+
.primaryKey(),
|
|
56
|
+
provider: varchar('provider', {
|
|
57
|
+
length: 32,
|
|
58
|
+
}).notNull(),
|
|
59
|
+
providerUserId: varchar('provider_user_id', {
|
|
60
|
+
length: 255,
|
|
61
|
+
}).notNull(),
|
|
62
|
+
userId: varchar('user_id', { length: 36 })
|
|
63
|
+
.notNull()
|
|
64
|
+
.references(() => users.id, {
|
|
65
|
+
onDelete: 'cascade',
|
|
66
|
+
}),
|
|
67
|
+
createdAt: datetime('created_at', {
|
|
68
|
+
mode: 'date',
|
|
69
|
+
})
|
|
70
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
71
|
+
.notNull(),
|
|
72
|
+
},
|
|
73
|
+
(table) => [
|
|
74
|
+
uniqueIndex(
|
|
75
|
+
'oauth_accounts_provider_provider_user_id_key',
|
|
76
|
+
).on(table.provider, table.providerUserId),
|
|
77
|
+
index('oauth_accounts_user_id_idx').on(table.userId),
|
|
78
|
+
],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// nestforge:feature:auth:token
|
|
82
|
+
export const refreshTokens = mysqlTable(
|
|
83
|
+
'refresh_tokens',
|
|
84
|
+
{
|
|
85
|
+
id: varchar('id', { length: 36 })
|
|
86
|
+
.$defaultFn(() => randomUUID())
|
|
87
|
+
.primaryKey(),
|
|
88
|
+
tokenHash: varchar('token_hash', {
|
|
89
|
+
length: 64,
|
|
90
|
+
})
|
|
91
|
+
.notNull()
|
|
92
|
+
.unique(),
|
|
93
|
+
userId: varchar('user_id', { length: 36 })
|
|
94
|
+
.notNull()
|
|
95
|
+
.references(() => users.id, {
|
|
96
|
+
onDelete: 'cascade',
|
|
97
|
+
}),
|
|
98
|
+
expiresAt: datetime('expires_at', {
|
|
99
|
+
mode: 'date',
|
|
100
|
+
}).notNull(),
|
|
101
|
+
revokedAt: datetime('revoked_at', {
|
|
102
|
+
mode: 'date',
|
|
103
|
+
}),
|
|
104
|
+
createdAt: datetime('created_at', {
|
|
105
|
+
mode: 'date',
|
|
106
|
+
})
|
|
107
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
108
|
+
.notNull(),
|
|
109
|
+
},
|
|
110
|
+
(table) => [
|
|
111
|
+
index('refresh_tokens_user_id_idx').on(table.userId),
|
|
112
|
+
],
|
|
113
|
+
);
|
|
114
|
+
// nestforge:feature:auth:token:end
|
|
115
|
+
|
|
116
|
+
// nestforge:feature:redis,auth:password
|
|
117
|
+
export const passwordResetTokens = mysqlTable(
|
|
118
|
+
'password_reset_tokens',
|
|
119
|
+
{
|
|
120
|
+
id: varchar('id', { length: 36 })
|
|
121
|
+
.$defaultFn(() => randomUUID())
|
|
122
|
+
.primaryKey(),
|
|
123
|
+
tokenHash: varchar('token_hash', {
|
|
124
|
+
length: 64,
|
|
125
|
+
})
|
|
126
|
+
.notNull()
|
|
127
|
+
.unique(),
|
|
128
|
+
userId: varchar('user_id', { length: 36 })
|
|
129
|
+
.notNull()
|
|
130
|
+
.references(() => users.id, {
|
|
131
|
+
onDelete: 'cascade',
|
|
132
|
+
}),
|
|
133
|
+
expiresAt: datetime('expires_at', {
|
|
134
|
+
mode: 'date',
|
|
135
|
+
}).notNull(),
|
|
136
|
+
usedAt: datetime('used_at', {
|
|
137
|
+
mode: 'date',
|
|
138
|
+
}),
|
|
139
|
+
createdAt: datetime('created_at', {
|
|
140
|
+
mode: 'date',
|
|
141
|
+
})
|
|
142
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
143
|
+
.notNull(),
|
|
144
|
+
},
|
|
145
|
+
(table) => [
|
|
146
|
+
index('password_reset_tokens_user_id_idx').on(
|
|
147
|
+
table.userId,
|
|
148
|
+
),
|
|
149
|
+
],
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
export const emailVerificationTokens = mysqlTable(
|
|
153
|
+
'email_verification_tokens',
|
|
154
|
+
{
|
|
155
|
+
id: varchar('id', { length: 36 })
|
|
156
|
+
.$defaultFn(() => randomUUID())
|
|
157
|
+
.primaryKey(),
|
|
158
|
+
tokenHash: varchar('token_hash', {
|
|
159
|
+
length: 64,
|
|
160
|
+
})
|
|
161
|
+
.notNull()
|
|
162
|
+
.unique(),
|
|
163
|
+
userId: varchar('user_id', { length: 36 })
|
|
164
|
+
.notNull()
|
|
165
|
+
.references(() => users.id, {
|
|
166
|
+
onDelete: 'cascade',
|
|
167
|
+
}),
|
|
168
|
+
expiresAt: datetime('expires_at', {
|
|
169
|
+
mode: 'date',
|
|
170
|
+
}).notNull(),
|
|
171
|
+
usedAt: datetime('used_at', {
|
|
172
|
+
mode: 'date',
|
|
173
|
+
}),
|
|
174
|
+
createdAt: datetime('created_at', {
|
|
175
|
+
mode: 'date',
|
|
176
|
+
})
|
|
177
|
+
.default(sql`CURRENT_TIMESTAMP`)
|
|
178
|
+
.notNull(),
|
|
179
|
+
},
|
|
180
|
+
(table) => [
|
|
181
|
+
index('email_verification_tokens_user_id_idx').on(
|
|
182
|
+
table.userId,
|
|
183
|
+
),
|
|
184
|
+
],
|
|
185
|
+
);
|
|
186
|
+
// nestforge:feature:redis,auth:password:end
|
|
187
|
+
|
|
188
|
+
// nestforge:feature:auth:session
|
|
189
|
+
export const sessions = mysqlTable(
|
|
190
|
+
'sessions',
|
|
191
|
+
{
|
|
192
|
+
id: varchar('id', { length: 255 }).primaryKey(),
|
|
193
|
+
expiredAt: bigint('expired_at', {
|
|
194
|
+
mode: 'number',
|
|
195
|
+
}).notNull(),
|
|
196
|
+
json: text('json').notNull(),
|
|
197
|
+
destroyedAt: datetime('destroyed_at', {
|
|
198
|
+
mode: 'date',
|
|
199
|
+
}),
|
|
200
|
+
},
|
|
201
|
+
(table) => [
|
|
202
|
+
index('sessions_expired_at_idx').on(
|
|
203
|
+
table.expiredAt,
|
|
204
|
+
),
|
|
205
|
+
],
|
|
206
|
+
);
|
|
207
|
+
// nestforge:feature:auth:session:end
|
|
208
|
+
|
|
209
|
+
export type User = typeof users.$inferSelect;
|
|
210
|
+
export type NewUser = typeof users.$inferInsert;
|
|
211
|
+
|
|
212
|
+
export type OAuthAccount =
|
|
213
|
+
typeof oauthAccounts.$inferSelect;
|
|
214
|
+
export type NewOAuthAccount =
|
|
215
|
+
typeof oauthAccounts.$inferInsert;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// nestforge:feature-file:database:postgres
|
|
2
|
+
import {
|
|
3
|
+
bigint,
|
|
4
|
+
index,
|
|
5
|
+
pgEnum,
|
|
6
|
+
pgTable,
|
|
7
|
+
text,
|
|
8
|
+
timestamp,
|
|
9
|
+
uniqueIndex,
|
|
10
|
+
uuid,
|
|
11
|
+
varchar,
|
|
12
|
+
} from 'drizzle-orm/pg-core';
|
|
13
|
+
|
|
14
|
+
export const roleEnum = pgEnum('role', [
|
|
15
|
+
'ADMIN',
|
|
16
|
+
'MANAGER',
|
|
17
|
+
'USER',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
export const users = pgTable('users', {
|
|
21
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
22
|
+
name: varchar('name', { length: 120 }).notNull(),
|
|
23
|
+
email: varchar('email', { length: 255 })
|
|
24
|
+
.notNull()
|
|
25
|
+
.unique(),
|
|
26
|
+
passwordHash: varchar('password_hash', {
|
|
27
|
+
length: 255,
|
|
28
|
+
}),
|
|
29
|
+
role: roleEnum('role').default('USER').notNull(),
|
|
30
|
+
avatarUrl: varchar('avatar_url', { length: 500 }),
|
|
31
|
+
emailVerifiedAt: timestamp('email_verified_at', {
|
|
32
|
+
withTimezone: true,
|
|
33
|
+
mode: 'date',
|
|
34
|
+
}),
|
|
35
|
+
createdAt: timestamp('created_at', {
|
|
36
|
+
withTimezone: true,
|
|
37
|
+
mode: 'date',
|
|
38
|
+
})
|
|
39
|
+
.defaultNow()
|
|
40
|
+
.notNull(),
|
|
41
|
+
updatedAt: timestamp('updated_at', {
|
|
42
|
+
withTimezone: true,
|
|
43
|
+
mode: 'date',
|
|
44
|
+
})
|
|
45
|
+
.defaultNow()
|
|
46
|
+
.$onUpdate(() => new Date())
|
|
47
|
+
.notNull(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const oauthAccounts = pgTable(
|
|
51
|
+
'oauth_accounts',
|
|
52
|
+
{
|
|
53
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
54
|
+
provider: varchar('provider', {
|
|
55
|
+
length: 32,
|
|
56
|
+
}).notNull(),
|
|
57
|
+
providerUserId: varchar('provider_user_id', {
|
|
58
|
+
length: 255,
|
|
59
|
+
}).notNull(),
|
|
60
|
+
userId: uuid('user_id')
|
|
61
|
+
.notNull()
|
|
62
|
+
.references(() => users.id, {
|
|
63
|
+
onDelete: 'cascade',
|
|
64
|
+
}),
|
|
65
|
+
createdAt: timestamp('created_at', {
|
|
66
|
+
withTimezone: true,
|
|
67
|
+
mode: 'date',
|
|
68
|
+
})
|
|
69
|
+
.defaultNow()
|
|
70
|
+
.notNull(),
|
|
71
|
+
},
|
|
72
|
+
(table) => [
|
|
73
|
+
uniqueIndex(
|
|
74
|
+
'oauth_accounts_provider_provider_user_id_key',
|
|
75
|
+
).on(table.provider, table.providerUserId),
|
|
76
|
+
index('oauth_accounts_user_id_idx').on(table.userId),
|
|
77
|
+
],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// nestforge:feature:auth:token
|
|
81
|
+
export const refreshTokens = pgTable(
|
|
82
|
+
'refresh_tokens',
|
|
83
|
+
{
|
|
84
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
85
|
+
tokenHash: varchar('token_hash', {
|
|
86
|
+
length: 64,
|
|
87
|
+
})
|
|
88
|
+
.notNull()
|
|
89
|
+
.unique(),
|
|
90
|
+
userId: uuid('user_id')
|
|
91
|
+
.notNull()
|
|
92
|
+
.references(() => users.id, {
|
|
93
|
+
onDelete: 'cascade',
|
|
94
|
+
}),
|
|
95
|
+
expiresAt: timestamp('expires_at', {
|
|
96
|
+
withTimezone: true,
|
|
97
|
+
mode: 'date',
|
|
98
|
+
}).notNull(),
|
|
99
|
+
revokedAt: timestamp('revoked_at', {
|
|
100
|
+
withTimezone: true,
|
|
101
|
+
mode: 'date',
|
|
102
|
+
}),
|
|
103
|
+
createdAt: timestamp('created_at', {
|
|
104
|
+
withTimezone: true,
|
|
105
|
+
mode: 'date',
|
|
106
|
+
})
|
|
107
|
+
.defaultNow()
|
|
108
|
+
.notNull(),
|
|
109
|
+
},
|
|
110
|
+
(table) => [
|
|
111
|
+
index('refresh_tokens_user_id_idx').on(table.userId),
|
|
112
|
+
],
|
|
113
|
+
);
|
|
114
|
+
// nestforge:feature:auth:token:end
|
|
115
|
+
|
|
116
|
+
// nestforge:feature:redis,auth:password
|
|
117
|
+
export const passwordResetTokens = pgTable(
|
|
118
|
+
'password_reset_tokens',
|
|
119
|
+
{
|
|
120
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
121
|
+
tokenHash: varchar('token_hash', {
|
|
122
|
+
length: 64,
|
|
123
|
+
})
|
|
124
|
+
.notNull()
|
|
125
|
+
.unique(),
|
|
126
|
+
userId: uuid('user_id')
|
|
127
|
+
.notNull()
|
|
128
|
+
.references(() => users.id, {
|
|
129
|
+
onDelete: 'cascade',
|
|
130
|
+
}),
|
|
131
|
+
expiresAt: timestamp('expires_at', {
|
|
132
|
+
withTimezone: true,
|
|
133
|
+
mode: 'date',
|
|
134
|
+
}).notNull(),
|
|
135
|
+
usedAt: timestamp('used_at', {
|
|
136
|
+
withTimezone: true,
|
|
137
|
+
mode: 'date',
|
|
138
|
+
}),
|
|
139
|
+
createdAt: timestamp('created_at', {
|
|
140
|
+
withTimezone: true,
|
|
141
|
+
mode: 'date',
|
|
142
|
+
})
|
|
143
|
+
.defaultNow()
|
|
144
|
+
.notNull(),
|
|
145
|
+
},
|
|
146
|
+
(table) => [
|
|
147
|
+
index('password_reset_tokens_user_id_idx').on(
|
|
148
|
+
table.userId,
|
|
149
|
+
),
|
|
150
|
+
],
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
export const emailVerificationTokens = pgTable(
|
|
154
|
+
'email_verification_tokens',
|
|
155
|
+
{
|
|
156
|
+
id: uuid('id').defaultRandom().primaryKey(),
|
|
157
|
+
tokenHash: varchar('token_hash', {
|
|
158
|
+
length: 64,
|
|
159
|
+
})
|
|
160
|
+
.notNull()
|
|
161
|
+
.unique(),
|
|
162
|
+
userId: uuid('user_id')
|
|
163
|
+
.notNull()
|
|
164
|
+
.references(() => users.id, {
|
|
165
|
+
onDelete: 'cascade',
|
|
166
|
+
}),
|
|
167
|
+
expiresAt: timestamp('expires_at', {
|
|
168
|
+
withTimezone: true,
|
|
169
|
+
mode: 'date',
|
|
170
|
+
}).notNull(),
|
|
171
|
+
usedAt: timestamp('used_at', {
|
|
172
|
+
withTimezone: true,
|
|
173
|
+
mode: 'date',
|
|
174
|
+
}),
|
|
175
|
+
createdAt: timestamp('created_at', {
|
|
176
|
+
withTimezone: true,
|
|
177
|
+
mode: 'date',
|
|
178
|
+
})
|
|
179
|
+
.defaultNow()
|
|
180
|
+
.notNull(),
|
|
181
|
+
},
|
|
182
|
+
(table) => [
|
|
183
|
+
index('email_verification_tokens_user_id_idx').on(
|
|
184
|
+
table.userId,
|
|
185
|
+
),
|
|
186
|
+
],
|
|
187
|
+
);
|
|
188
|
+
// nestforge:feature:redis,auth:password:end
|
|
189
|
+
|
|
190
|
+
// nestforge:feature:auth:session
|
|
191
|
+
export const sessions = pgTable(
|
|
192
|
+
'sessions',
|
|
193
|
+
{
|
|
194
|
+
id: varchar('id', { length: 255 }).primaryKey(),
|
|
195
|
+
expiredAt: bigint('expired_at', {
|
|
196
|
+
mode: 'number',
|
|
197
|
+
}).notNull(),
|
|
198
|
+
json: text('json').notNull(),
|
|
199
|
+
destroyedAt: timestamp('destroyed_at', {
|
|
200
|
+
withTimezone: true,
|
|
201
|
+
mode: 'date',
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
(table) => [
|
|
205
|
+
index('sessions_expired_at_idx').on(
|
|
206
|
+
table.expiredAt,
|
|
207
|
+
),
|
|
208
|
+
],
|
|
209
|
+
);
|
|
210
|
+
// nestforge:feature:auth:session:end
|
|
211
|
+
|
|
212
|
+
export type User = typeof users.$inferSelect;
|
|
213
|
+
export type NewUser = typeof users.$inferInsert;
|
|
214
|
+
|
|
215
|
+
export type OAuthAccount =
|
|
216
|
+
typeof oauthAccounts.$inferSelect;
|
|
217
|
+
export type NewOAuthAccount =
|
|
218
|
+
typeof oauthAccounts.$inferInsert;
|