better-ts-stack 1.1.4 → 2.0.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.
Files changed (161) hide show
  1. package/README.md +113 -82
  2. package/dist/args.d.ts +12 -0
  3. package/dist/args.d.ts.map +1 -0
  4. package/dist/args.js +90 -0
  5. package/dist/args.js.map +1 -0
  6. package/dist/builder/configGenerator.d.ts.map +1 -1
  7. package/dist/builder/configGenerator.js +10 -3
  8. package/dist/builder/configGenerator.js.map +1 -1
  9. package/dist/builder/dependencyInstaller.d.ts.map +1 -1
  10. package/dist/builder/dependencyInstaller.js +8 -14
  11. package/dist/builder/dependencyInstaller.js.map +1 -1
  12. package/dist/builder/gitInitializer.d.ts.map +1 -1
  13. package/dist/builder/gitInitializer.js +8 -41
  14. package/dist/builder/gitInitializer.js.map +1 -1
  15. package/dist/builder/index.d.ts.map +1 -1
  16. package/dist/builder/index.js +24 -63
  17. package/dist/builder/index.js.map +1 -1
  18. package/dist/builder/moduleSelector.d.ts +1 -4
  19. package/dist/builder/moduleSelector.d.ts.map +1 -1
  20. package/dist/builder/moduleSelector.js +11 -15
  21. package/dist/builder/moduleSelector.js.map +1 -1
  22. package/dist/builder/templateContext.d.ts +2 -17
  23. package/dist/builder/templateContext.d.ts.map +1 -1
  24. package/dist/builder/templateContext.js +6 -5
  25. package/dist/builder/templateContext.js.map +1 -1
  26. package/dist/index.js +45 -20
  27. package/dist/index.js.map +1 -1
  28. package/dist/output/nextSteps.d.ts +1 -2
  29. package/dist/output/nextSteps.d.ts.map +1 -1
  30. package/dist/output/nextSteps.js +10 -19
  31. package/dist/output/nextSteps.js.map +1 -1
  32. package/dist/prompts/index.d.ts +3 -3
  33. package/dist/prompts/index.d.ts.map +1 -1
  34. package/dist/prompts/index.js +22 -58
  35. package/dist/prompts/index.js.map +1 -1
  36. package/dist/prompts/stack.d.ts +3 -2
  37. package/dist/prompts/stack.d.ts.map +1 -1
  38. package/dist/prompts/stack.js +81 -70
  39. package/dist/prompts/stack.js.map +1 -1
  40. package/dist/types/index.d.ts +20 -42
  41. package/dist/types/index.d.ts.map +1 -1
  42. package/dist/types/index.js +40 -38
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/ui/index.d.ts +3 -0
  45. package/dist/ui/index.d.ts.map +1 -0
  46. package/dist/ui/index.js +19 -0
  47. package/dist/ui/index.js.map +1 -0
  48. package/dist/ui/messages.d.ts +9 -0
  49. package/dist/ui/messages.d.ts.map +1 -0
  50. package/dist/ui/messages.js +100 -0
  51. package/dist/ui/messages.js.map +1 -0
  52. package/dist/ui/prompts.d.ts +20 -0
  53. package/dist/ui/prompts.d.ts.map +1 -0
  54. package/dist/ui/prompts.js +71 -0
  55. package/dist/ui/prompts.js.map +1 -0
  56. package/dist/ui/theme.d.ts +9 -0
  57. package/dist/ui/theme.d.ts.map +1 -0
  58. package/dist/ui/theme.js +24 -0
  59. package/dist/ui/theme.js.map +1 -0
  60. package/dist/validators/index.d.ts +1 -0
  61. package/dist/validators/index.d.ts.map +1 -1
  62. package/dist/validators/index.js +6 -0
  63. package/dist/validators/index.js.map +1 -1
  64. package/package.json +70 -66
  65. package/templates/backend/express/config.json +44 -44
  66. package/templates/backend/express/eslint.config.mjs +40 -40
  67. package/templates/backend/express/gitignore +36 -36
  68. package/templates/backend/express/src/index.ts +76 -76
  69. package/templates/backend/express/src/routes/health.ts +12 -12
  70. package/templates/backend/express/tsconfig.json +25 -25
  71. package/templates/backend/nestjs/.prettierignore +52 -0
  72. package/templates/backend/nestjs/.prettierrc +16 -0
  73. package/templates/backend/nestjs/config.json +44 -0
  74. package/templates/backend/nestjs/eslint.config.mjs +40 -0
  75. package/templates/backend/nestjs/gitignore +36 -0
  76. package/templates/backend/nestjs/nest-cli.json +9 -0
  77. package/templates/backend/nestjs/src/app.module.ts.hbs +34 -0
  78. package/templates/backend/nestjs/src/health/health.controller.ts +12 -0
  79. package/templates/backend/nestjs/src/main.ts +23 -0
  80. package/templates/backend/nestjs/tsconfig.eslint.json +9 -0
  81. package/templates/backend/nestjs/tsconfig.json +25 -0
  82. package/templates/frontend/nextjs/app/layout.tsx +13 -13
  83. package/templates/frontend/nextjs/app/page.tsx.hbs +97 -97
  84. package/templates/frontend/nextjs/components/ui/button.tsx +51 -51
  85. package/templates/frontend/nextjs/components/ui/card.tsx +60 -60
  86. package/templates/frontend/nextjs/components/ui/field.tsx +67 -67
  87. package/templates/frontend/nextjs/components/ui/input.tsx +18 -18
  88. package/templates/frontend/nextjs/components.json +19 -19
  89. package/templates/frontend/nextjs/config.json +38 -38
  90. package/templates/frontend/nextjs/eslint.config.mjs +11 -11
  91. package/templates/frontend/nextjs/gitignore +42 -42
  92. package/templates/frontend/nextjs/lib/utils.ts +6 -6
  93. package/templates/frontend/nextjs/next.config.ts.hbs +12 -12
  94. package/templates/frontend/nextjs/proxy.ts.hbs +24 -24
  95. package/templates/frontend/nextjs/tsconfig.json +34 -34
  96. package/templates/frontend/tanstack/config.json +48 -48
  97. package/templates/frontend/tanstack/src/routeTree.gen.ts +68 -68
  98. package/templates/frontend/tanstack/src/styles/app.css +85 -85
  99. package/templates/modules/auth/express/config.json +27 -26
  100. package/templates/modules/auth/express/src/controllers/authController.ts.hbs +116 -130
  101. package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +26 -26
  102. package/templates/modules/auth/express/src/services/userStore.ts.hbs +117 -117
  103. package/templates/modules/auth/nestjs/config.json +24 -0
  104. package/templates/modules/auth/nestjs/src/auth/auth.controller.ts +46 -0
  105. package/templates/modules/auth/nestjs/src/auth/auth.guard.ts +36 -0
  106. package/templates/modules/auth/nestjs/src/auth/auth.module.ts.hbs +22 -0
  107. package/templates/modules/auth/nestjs/src/auth/auth.schemas.ts +35 -0
  108. package/templates/modules/auth/nestjs/src/auth/auth.service.ts +70 -0
  109. package/templates/modules/auth/nestjs/src/auth/jwt.ts +27 -0
  110. package/templates/modules/auth/nestjs/src/auth/users.service.ts.hbs +144 -0
  111. package/templates/modules/auth/nestjs/src/auth/zod-validation.pipe.ts +16 -0
  112. package/templates/modules/auth/nextjs/app/dashboard/page.tsx +96 -96
  113. package/templates/modules/auth/nextjs/app/sign-in/page.tsx +35 -35
  114. package/templates/modules/auth/nextjs/app/sign-up/page.tsx +35 -35
  115. package/templates/modules/auth/nextjs/components/auth/sign-in-form.tsx +132 -132
  116. package/templates/modules/auth/nextjs/components/auth/sign-out-button.tsx +50 -50
  117. package/templates/modules/auth/nextjs/components/auth/sign-up-form.tsx +152 -152
  118. package/templates/modules/auth/nextjs/config.json +31 -31
  119. package/templates/modules/auth/nextjs/lib/auth-schema.ts +39 -39
  120. package/templates/modules/auth/nextjs/lib/auth.ts.hbs +37 -37
  121. package/templates/modules/auth/tanstack/src/lib/auth-functions.ts +4 -4
  122. package/templates/modules/auth/tanstack/src/routeTree.gen.ts +140 -140
  123. package/templates/modules/docker/.dockerignore +14 -14
  124. package/templates/modules/docker/Dockerfile.hbs +137 -133
  125. package/templates/modules/docker/config.json +19 -19
  126. package/templates/modules/docker/docker-compose.yml.hbs +9 -9
  127. package/templates/modules/drizzle/express/config.json +27 -27
  128. package/templates/modules/drizzle/express/drizzle.config.ts +13 -13
  129. package/templates/modules/drizzle/express/src/lib/db.ts +13 -13
  130. package/templates/modules/drizzle/express/src/lib/schema.ts +10 -10
  131. package/templates/modules/drizzle/nestjs/config.json +27 -0
  132. package/templates/modules/drizzle/nestjs/drizzle.config.ts +13 -0
  133. package/templates/modules/drizzle/nestjs/src/database/database.module.ts +30 -0
  134. package/templates/modules/drizzle/nestjs/src/database/schema.ts +10 -0
  135. package/templates/modules/drizzle/nextjs/config.json +29 -29
  136. package/templates/modules/drizzle/nextjs/lib/db.ts +13 -13
  137. package/templates/modules/drizzle/nextjs/lib/schema.ts.hbs +84 -84
  138. package/templates/modules/mongoose/express/config.json +16 -16
  139. package/templates/modules/mongoose/nestjs/config.json +16 -0
  140. package/templates/modules/mongoose/nestjs/src/users/user.schema.ts +21 -0
  141. package/templates/modules/mongoose/nextjs/config.json +16 -16
  142. package/templates/modules/mongoose/nextjs/lib/db.ts +36 -36
  143. package/templates/modules/mongoose/tanstack/config.json +17 -17
  144. package/templates/modules/mongoose/tanstack/src/lib/db.ts +37 -37
  145. package/templates/modules/prisma/express/config.json +28 -28
  146. package/templates/modules/prisma/express/prisma/schema.prisma +1 -1
  147. package/templates/modules/prisma/express/prisma.config.ts +12 -12
  148. package/templates/modules/prisma/express/src/lib/prisma.ts +24 -24
  149. package/templates/modules/prisma/nestjs/config.json +28 -0
  150. package/templates/modules/prisma/nestjs/prisma/schema.prisma +23 -0
  151. package/templates/modules/prisma/nestjs/prisma.config.ts +12 -0
  152. package/templates/modules/prisma/nestjs/src/prisma/prisma.module.ts +11 -0
  153. package/templates/modules/prisma/nestjs/src/prisma/prisma.service.ts +17 -0
  154. package/templates/modules/prisma/nextjs/config.json +29 -29
  155. package/templates/modules/prisma/nextjs/prisma/schema.prisma.hbs +91 -91
  156. package/templates/modules/prisma/tanstack/config.json +5 -5
  157. package/dist/intro.d.ts +0 -2
  158. package/dist/intro.d.ts.map +0 -1
  159. package/dist/intro.js +0 -27
  160. package/dist/intro.js.map +0 -1
  161. package/templates/backend/express/.eslintrc.js +0 -24
@@ -1,27 +1,27 @@
1
- {
2
- "id": "drizzle",
3
- "name": "Drizzle ORM",
4
- "description": "Drizzle ORM for Express with PostgreSQL",
5
- "type": "database",
6
- "dependencies": {
7
- "drizzle-orm": "^0.45.2",
8
- "pg": "^8.23.0",
9
- "dotenv": "^17.4.2"
10
- },
11
- "devDependencies": {
12
- "drizzle-kit": "^0.31.10",
13
- "@types/pg": "^8.23.1"
14
- },
15
- "scripts": {
16
- "db:generate": "drizzle-kit generate",
17
- "db:migrate": "drizzle-kit migrate",
18
- "db:studio": "drizzle-kit studio"
19
- },
20
- "envVars": {
21
- "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb?schema=public"
22
- },
23
- "templateFiles": [],
24
- "overrides": {
25
- "esbuild": "^0.28.2"
26
- }
27
- }
1
+ {
2
+ "id": "drizzle",
3
+ "name": "Drizzle ORM",
4
+ "description": "Drizzle ORM for Express with PostgreSQL",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "drizzle-orm": "^0.45.2",
8
+ "pg": "^8.23.0",
9
+ "dotenv": "^17.4.2"
10
+ },
11
+ "devDependencies": {
12
+ "drizzle-kit": "^0.31.10",
13
+ "@types/pg": "^8.23.1"
14
+ },
15
+ "scripts": {
16
+ "db:generate": "drizzle-kit generate",
17
+ "db:migrate": "drizzle-kit migrate",
18
+ "db:studio": "drizzle-kit studio"
19
+ },
20
+ "envVars": {
21
+ "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb?schema=public"
22
+ },
23
+ "templateFiles": [],
24
+ "overrides": {
25
+ "esbuild": "^0.28.2"
26
+ }
27
+ }
@@ -1,13 +1,13 @@
1
- import { config } from "dotenv";
2
- import { defineConfig } from "drizzle-kit";
3
-
4
- config({ path: ".env" });
5
-
6
- export default defineConfig({
7
- schema: "./src/lib/schema.ts",
8
- out: "./migrations",
9
- dialect: "postgresql",
10
- dbCredentials: {
11
- url: process.env.DATABASE_URL!,
12
- },
13
- });
1
+ import { config } from "dotenv";
2
+ import { defineConfig } from "drizzle-kit";
3
+
4
+ config({ path: ".env" });
5
+
6
+ export default defineConfig({
7
+ schema: "./src/lib/schema.ts",
8
+ out: "./migrations",
9
+ dialect: "postgresql",
10
+ dbCredentials: {
11
+ url: process.env.DATABASE_URL!,
12
+ },
13
+ });
@@ -1,13 +1,13 @@
1
- import { config } from "dotenv";
2
- import { drizzle } from "drizzle-orm/node-postgres";
3
- import { Pool } from "pg";
4
-
5
- import * as schema from "./schema";
6
-
7
- config({ path: ".env" }); // or .env.local
8
-
9
- const pool = new Pool({
10
- connectionString: process.env.DATABASE_URL,
11
- });
12
-
13
- export const db = drizzle(pool, { schema });
1
+ import { config } from "dotenv";
2
+ import { drizzle } from "drizzle-orm/node-postgres";
3
+ import { Pool } from "pg";
4
+
5
+ import * as schema from "./schema";
6
+
7
+ config({ path: ".env" }); // or .env.local
8
+
9
+ const pool = new Pool({
10
+ connectionString: process.env.DATABASE_URL,
11
+ });
12
+
13
+ export const db = drizzle(pool, { schema });
@@ -1,10 +1,10 @@
1
- import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
2
-
3
- export const users = pgTable("users", {
4
- id: uuid("id").primaryKey().defaultRandom(),
5
- email: text("email").notNull().unique(),
6
- name: text("name"),
7
- password: text("password").notNull(),
8
- createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
9
- updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
10
- });
1
+ import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
2
+
3
+ export const users = pgTable("users", {
4
+ id: uuid("id").primaryKey().defaultRandom(),
5
+ email: text("email").notNull().unique(),
6
+ name: text("name"),
7
+ password: text("password").notNull(),
8
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
9
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
10
+ });
@@ -0,0 +1,27 @@
1
+ {
2
+ "id": "drizzle",
3
+ "name": "Drizzle ORM",
4
+ "description": "Drizzle ORM for NestJS with PostgreSQL",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "drizzle-orm": "^0.45.2",
8
+ "pg": "^8.23.0",
9
+ "dotenv": "^17.4.2"
10
+ },
11
+ "devDependencies": {
12
+ "drizzle-kit": "^0.31.10",
13
+ "@types/pg": "^8.23.1"
14
+ },
15
+ "scripts": {
16
+ "db:generate": "drizzle-kit generate",
17
+ "db:migrate": "drizzle-kit migrate",
18
+ "db:studio": "drizzle-kit studio"
19
+ },
20
+ "envVars": {
21
+ "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb?schema=public"
22
+ },
23
+ "templateFiles": [],
24
+ "overrides": {
25
+ "esbuild": "^0.28.2"
26
+ }
27
+ }
@@ -0,0 +1,13 @@
1
+ import { config } from "dotenv";
2
+ import { defineConfig } from "drizzle-kit";
3
+
4
+ config({ path: ".env" });
5
+
6
+ export default defineConfig({
7
+ schema: "./src/database/schema.ts",
8
+ out: "./migrations",
9
+ dialect: "postgresql",
10
+ dbCredentials: {
11
+ url: process.env.DATABASE_URL!,
12
+ },
13
+ });
@@ -0,0 +1,30 @@
1
+ import { Global, Inject, Module, type OnModuleDestroy } from "@nestjs/common";
2
+ import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
3
+ import type { Pool } from "pg";
4
+
5
+ import * as schema from "./schema.js";
6
+
7
+ // Injection token for the Drizzle client: @Inject(DRIZZLE) private readonly db: Database
8
+ export const DRIZZLE = Symbol("DRIZZLE");
9
+
10
+ // $client is the connection pool that drizzle() creates from the URL
11
+ export type Database = NodePgDatabase<typeof schema> & { $client: Pool };
12
+
13
+ // Global so any module can inject the client without importing this one
14
+ @Global()
15
+ @Module({
16
+ providers: [
17
+ {
18
+ provide: DRIZZLE,
19
+ useFactory: () => drizzle(process.env.DATABASE_URL!, { schema }),
20
+ },
21
+ ],
22
+ exports: [DRIZZLE],
23
+ })
24
+ export class DatabaseModule implements OnModuleDestroy {
25
+ constructor(@Inject(DRIZZLE) private readonly db: Database) {}
26
+
27
+ async onModuleDestroy(): Promise<void> {
28
+ await this.db.$client.end();
29
+ }
30
+ }
@@ -0,0 +1,10 @@
1
+ import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
2
+
3
+ export const users = pgTable("users", {
4
+ id: uuid("id").primaryKey().defaultRandom(),
5
+ email: text("email").notNull().unique(),
6
+ name: text("name"),
7
+ password: text("password").notNull(),
8
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
9
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
10
+ });
@@ -1,29 +1,29 @@
1
- {
2
- "id": "drizzle",
3
- "name": "Drizzle ORM",
4
- "description": "Drizzle ORM for Next.js with PostgreSQL",
5
- "type": "database",
6
- "dependencies": {
7
- "drizzle-orm": "^0.45.2",
8
- "pg": "^8.23.0",
9
- "dotenv": "^17.4.2"
10
- },
11
- "devDependencies": {
12
- "drizzle-kit": "^0.31.10",
13
- "@types/pg": "^8.23.1"
14
- },
15
- "scripts": {
16
- "db:generate": "drizzle-kit generate",
17
- "db:migrate": "drizzle-kit migrate",
18
- "db:studio": "drizzle-kit studio"
19
- },
20
- "envVars": {
21
- "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb?schema=public"
22
- },
23
- "templateFiles": [
24
- "lib/schema.ts.hbs"
25
- ],
26
- "overrides": {
27
- "esbuild": "^0.28.2"
28
- }
29
- }
1
+ {
2
+ "id": "drizzle",
3
+ "name": "Drizzle ORM",
4
+ "description": "Drizzle ORM for Next.js with PostgreSQL",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "drizzle-orm": "^0.45.2",
8
+ "pg": "^8.23.0",
9
+ "dotenv": "^17.4.2"
10
+ },
11
+ "devDependencies": {
12
+ "drizzle-kit": "^0.31.10",
13
+ "@types/pg": "^8.23.1"
14
+ },
15
+ "scripts": {
16
+ "db:generate": "drizzle-kit generate",
17
+ "db:migrate": "drizzle-kit migrate",
18
+ "db:studio": "drizzle-kit studio"
19
+ },
20
+ "envVars": {
21
+ "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb?schema=public"
22
+ },
23
+ "templateFiles": [
24
+ "lib/schema.ts.hbs"
25
+ ],
26
+ "overrides": {
27
+ "esbuild": "^0.28.2"
28
+ }
29
+ }
@@ -1,13 +1,13 @@
1
- import { config } from "dotenv";
2
- import { drizzle } from "drizzle-orm/node-postgres";
3
- import { Pool } from "pg";
4
-
5
- import * as schema from "./schema";
6
-
7
- config({ path: ".env" }); // or .env.local
8
-
9
- const pool = new Pool({
10
- connectionString: process.env.DATABASE_URL,
11
- });
12
-
13
- export const db = drizzle(pool, { schema });
1
+ import { config } from "dotenv";
2
+ import { drizzle } from "drizzle-orm/node-postgres";
3
+ import { Pool } from "pg";
4
+
5
+ import * as schema from "./schema";
6
+
7
+ config({ path: ".env" }); // or .env.local
8
+
9
+ const pool = new Pool({
10
+ connectionString: process.env.DATABASE_URL,
11
+ });
12
+
13
+ export const db = drizzle(pool, { schema });
@@ -1,84 +1,84 @@
1
- {{#if useAuth}}
2
- import { boolean, pgTable, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
3
-
4
- export const user = pgTable("user", {
5
- id: text("id").primaryKey(),
6
- name: text("name").notNull(),
7
- email: text("email").notNull().unique(),
8
- emailVerified: boolean("email_verified").notNull().default(false),
9
- image: text("image"),
10
- createdAt: timestamp("created_at", { withTimezone: true })
11
- .notNull()
12
- .defaultNow(),
13
- updatedAt: timestamp("updated_at", { withTimezone: true })
14
- .notNull()
15
- .defaultNow(),
16
- });
17
-
18
- export const session = pgTable("session", {
19
- id: text("id").primaryKey(),
20
- expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
21
- token: text("token").notNull().unique(),
22
- createdAt: timestamp("created_at", { withTimezone: true })
23
- .notNull()
24
- .defaultNow(),
25
- updatedAt: timestamp("updated_at", { withTimezone: true })
26
- .notNull()
27
- .defaultNow(),
28
- ipAddress: text("ip_address"),
29
- userAgent: text("user_agent"),
30
- userId: text("user_id")
31
- .notNull()
32
- .references(() => user.id, { onDelete: "cascade" }),
33
- });
34
-
35
- export const account = pgTable("account", {
36
- id: text("id").primaryKey(),
37
- accountId: text("account_id").notNull(),
38
- providerId: text("provider_id").notNull(),
39
- userId: text("user_id")
40
- .notNull()
41
- .references(() => user.id, { onDelete: "cascade" }),
42
- accessToken: text("access_token"),
43
- refreshToken: text("refresh_token"),
44
- idToken: text("id_token"),
45
- accessTokenExpiresAt: timestamp("access_token_expires_at", {
46
- withTimezone: true,
47
- }),
48
- refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
49
- withTimezone: true,
50
- }),
51
- scope: text("scope"),
52
- password: text("password"),
53
- createdAt: timestamp("created_at", { withTimezone: true })
54
- .notNull()
55
- .defaultNow(),
56
- updatedAt: timestamp("updated_at", { withTimezone: true })
57
- .notNull()
58
- .defaultNow(),
59
- }, (table) => [uniqueIndex("account_provider_account_id_unique").on(table.providerId, table.accountId)]);
60
-
61
- export const verification = pgTable("verification", {
62
- id: text("id").primaryKey(),
63
- identifier: text("identifier").notNull(),
64
- value: text("value").notNull(),
65
- expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
66
- createdAt: timestamp("created_at", { withTimezone: true })
67
- .notNull()
68
- .defaultNow(),
69
- updatedAt: timestamp("updated_at", { withTimezone: true })
70
- .notNull()
71
- .defaultNow(),
72
- });
73
- {{else}}
74
- import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
75
-
76
- export const users = pgTable("users", {
77
- id: uuid("id").primaryKey().defaultRandom(),
78
- email: text("email").notNull().unique(),
79
- name: text("name"),
80
- password: text("password").notNull(),
81
- createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
82
- updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
83
- });
84
- {{/if}}
1
+ {{#if useAuth}}
2
+ import { boolean, pgTable, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
3
+
4
+ export const user = pgTable("user", {
5
+ id: text("id").primaryKey(),
6
+ name: text("name").notNull(),
7
+ email: text("email").notNull().unique(),
8
+ emailVerified: boolean("email_verified").notNull().default(false),
9
+ image: text("image"),
10
+ createdAt: timestamp("created_at", { withTimezone: true })
11
+ .notNull()
12
+ .defaultNow(),
13
+ updatedAt: timestamp("updated_at", { withTimezone: true })
14
+ .notNull()
15
+ .defaultNow(),
16
+ });
17
+
18
+ export const session = pgTable("session", {
19
+ id: text("id").primaryKey(),
20
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
21
+ token: text("token").notNull().unique(),
22
+ createdAt: timestamp("created_at", { withTimezone: true })
23
+ .notNull()
24
+ .defaultNow(),
25
+ updatedAt: timestamp("updated_at", { withTimezone: true })
26
+ .notNull()
27
+ .defaultNow(),
28
+ ipAddress: text("ip_address"),
29
+ userAgent: text("user_agent"),
30
+ userId: text("user_id")
31
+ .notNull()
32
+ .references(() => user.id, { onDelete: "cascade" }),
33
+ });
34
+
35
+ export const account = pgTable("account", {
36
+ id: text("id").primaryKey(),
37
+ accountId: text("account_id").notNull(),
38
+ providerId: text("provider_id").notNull(),
39
+ userId: text("user_id")
40
+ .notNull()
41
+ .references(() => user.id, { onDelete: "cascade" }),
42
+ accessToken: text("access_token"),
43
+ refreshToken: text("refresh_token"),
44
+ idToken: text("id_token"),
45
+ accessTokenExpiresAt: timestamp("access_token_expires_at", {
46
+ withTimezone: true,
47
+ }),
48
+ refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
49
+ withTimezone: true,
50
+ }),
51
+ scope: text("scope"),
52
+ password: text("password"),
53
+ createdAt: timestamp("created_at", { withTimezone: true })
54
+ .notNull()
55
+ .defaultNow(),
56
+ updatedAt: timestamp("updated_at", { withTimezone: true })
57
+ .notNull()
58
+ .defaultNow(),
59
+ }, (table) => [uniqueIndex("account_provider_account_id_unique").on(table.providerId, table.accountId)]);
60
+
61
+ export const verification = pgTable("verification", {
62
+ id: text("id").primaryKey(),
63
+ identifier: text("identifier").notNull(),
64
+ value: text("value").notNull(),
65
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
66
+ createdAt: timestamp("created_at", { withTimezone: true })
67
+ .notNull()
68
+ .defaultNow(),
69
+ updatedAt: timestamp("updated_at", { withTimezone: true })
70
+ .notNull()
71
+ .defaultNow(),
72
+ });
73
+ {{else}}
74
+ import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
75
+
76
+ export const users = pgTable("users", {
77
+ id: uuid("id").primaryKey().defaultRandom(),
78
+ email: text("email").notNull().unique(),
79
+ name: text("name"),
80
+ password: text("password").notNull(),
81
+ createdAt: timestamp("created_at", { withTimezone: true }).defaultNow(),
82
+ updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow(),
83
+ });
84
+ {{/if}}
@@ -1,16 +1,16 @@
1
- {
2
- "id": "mongoose",
3
- "name": "Mongoose (MongoDB)",
4
- "description": "MongoDB database integration for Express using Mongoose ODM",
5
- "type": "database",
6
- "dependencies": {
7
- "mongoose": "^9.9.5",
8
- "mongodb": "^7.6.0"
9
- },
10
- "devDependencies": {},
11
- "scripts": {},
12
- "envVars": {
13
- "MONGODB_URI": "mongodb://localhost:27017/myapp"
14
- },
15
- "templateFiles": []
16
- }
1
+ {
2
+ "id": "mongoose",
3
+ "name": "Mongoose (MongoDB)",
4
+ "description": "MongoDB database integration for Express using Mongoose ODM",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "mongoose": "^9.9.5",
8
+ "mongodb": "^7.6.0"
9
+ },
10
+ "devDependencies": {},
11
+ "scripts": {},
12
+ "envVars": {
13
+ "MONGODB_URI": "mongodb://localhost:27017/myapp"
14
+ },
15
+ "templateFiles": []
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "id": "mongoose",
3
+ "name": "Mongoose (MongoDB)",
4
+ "description": "MongoDB database integration for NestJS using Mongoose ODM",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "@nestjs/mongoose": "^12.0.0",
8
+ "mongoose": "^9.9.5"
9
+ },
10
+ "devDependencies": {},
11
+ "scripts": {},
12
+ "envVars": {
13
+ "MONGODB_URI": "mongodb://localhost:27017/myapp"
14
+ },
15
+ "templateFiles": []
16
+ }
@@ -0,0 +1,21 @@
1
+ import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
2
+
3
+ @Schema({ timestamps: true })
4
+ export class User {
5
+ @Prop({
6
+ type: String,
7
+ required: true,
8
+ unique: true,
9
+ lowercase: true,
10
+ trim: true,
11
+ })
12
+ email: string;
13
+
14
+ @Prop({ type: String, trim: true })
15
+ name?: string | null;
16
+
17
+ @Prop({ type: String, required: true })
18
+ password: string;
19
+ }
20
+
21
+ export const UserSchema = SchemaFactory.createForClass(User);
@@ -1,16 +1,16 @@
1
- {
2
- "id": "mongoose",
3
- "name": "Mongoose (MongoDB)",
4
- "description": "MongoDB database integration for Next.js using Mongoose ODM",
5
- "type": "database",
6
- "dependencies": {
7
- "mongoose": "^9.9.5",
8
- "mongodb": "^7.6.0"
9
- },
10
- "devDependencies": {},
11
- "scripts": {},
12
- "envVars": {
13
- "MONGODB_URI": "mongodb://localhost:27017/myapp"
14
- },
15
- "templateFiles": []
16
- }
1
+ {
2
+ "id": "mongoose",
3
+ "name": "Mongoose (MongoDB)",
4
+ "description": "MongoDB database integration for Next.js using Mongoose ODM",
5
+ "type": "database",
6
+ "dependencies": {
7
+ "mongoose": "^9.9.5",
8
+ "mongodb": "^7.6.0"
9
+ },
10
+ "devDependencies": {},
11
+ "scripts": {},
12
+ "envVars": {
13
+ "MONGODB_URI": "mongodb://localhost:27017/myapp"
14
+ },
15
+ "templateFiles": []
16
+ }
@@ -1,36 +1,36 @@
1
- import mongoose from "mongoose";
2
-
3
- // Reuse one connection across hot reloads and concurrent requests
4
- const globalForMongoose = globalThis as unknown as {
5
- mongooseConnection?: Promise<typeof mongoose>;
6
- };
7
-
8
- /**
9
- * Connects Mongoose once and returns the shared connection.
10
- * Call this in server code before querying Mongoose models.
11
- */
12
- export async function connectDB(): Promise<typeof mongoose> {
13
- const mongoUri = process.env.MONGODB_URI;
14
-
15
- if (!mongoUri) {
16
- throw new Error("MONGODB_URI environment variable is not defined");
17
- }
18
-
19
- globalForMongoose.mongooseConnection ??= mongoose
20
- .connect(mongoUri)
21
- .catch((error: unknown) => {
22
- // Let the next call retry instead of caching the failure
23
- globalForMongoose.mongooseConnection = undefined;
24
- throw error;
25
- });
26
-
27
- return globalForMongoose.mongooseConnection;
28
- }
29
-
30
- /**
31
- * Gracefully close the MongoDB connection
32
- */
33
- export async function disconnectDB(): Promise<void> {
34
- await mongoose.connection.close();
35
- globalForMongoose.mongooseConnection = undefined;
36
- }
1
+ import mongoose from "mongoose";
2
+
3
+ // Reuse one connection across hot reloads and concurrent requests
4
+ const globalForMongoose = globalThis as unknown as {
5
+ mongooseConnection?: Promise<typeof mongoose>;
6
+ };
7
+
8
+ /**
9
+ * Connects Mongoose once and returns the shared connection.
10
+ * Call this in server code before querying Mongoose models.
11
+ */
12
+ export async function connectDB(): Promise<typeof mongoose> {
13
+ const mongoUri = process.env.MONGODB_URI;
14
+
15
+ if (!mongoUri) {
16
+ throw new Error("MONGODB_URI environment variable is not defined");
17
+ }
18
+
19
+ globalForMongoose.mongooseConnection ??= mongoose
20
+ .connect(mongoUri)
21
+ .catch((error: unknown) => {
22
+ // Let the next call retry instead of caching the failure
23
+ globalForMongoose.mongooseConnection = undefined;
24
+ throw error;
25
+ });
26
+
27
+ return globalForMongoose.mongooseConnection;
28
+ }
29
+
30
+ /**
31
+ * Gracefully close the MongoDB connection
32
+ */
33
+ export async function disconnectDB(): Promise<void> {
34
+ await mongoose.connection.close();
35
+ globalForMongoose.mongooseConnection = undefined;
36
+ }