create-velox-app 0.6.27 → 0.6.29

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 (47) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli.js +74 -6
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +7 -7
  7. package/dist/index.js.map +1 -1
  8. package/dist/templates/auth.d.ts.map +1 -1
  9. package/dist/templates/auth.js +9 -8
  10. package/dist/templates/auth.js.map +1 -1
  11. package/dist/templates/compiler.js +1 -1
  12. package/dist/templates/compiler.js.map +1 -1
  13. package/dist/templates/placeholders.d.ts +25 -2
  14. package/dist/templates/placeholders.d.ts.map +1 -1
  15. package/dist/templates/placeholders.js +109 -3
  16. package/dist/templates/placeholders.js.map +1 -1
  17. package/dist/templates/rsc.d.ts.map +1 -1
  18. package/dist/templates/rsc.js +9 -8
  19. package/dist/templates/rsc.js.map +1 -1
  20. package/dist/templates/spa.d.ts.map +1 -1
  21. package/dist/templates/spa.js +9 -8
  22. package/dist/templates/spa.js.map +1 -1
  23. package/dist/templates/trpc.d.ts.map +1 -1
  24. package/dist/templates/trpc.js +9 -8
  25. package/dist/templates/trpc.js.map +1 -1
  26. package/dist/templates/types.d.ts.map +1 -1
  27. package/dist/templates/types.js +1 -2
  28. package/dist/templates/types.js.map +1 -1
  29. package/package.json +5 -2
  30. package/src/templates/source/api/config/database.ts +76 -0
  31. package/src/templates/source/api/env.auth +1 -4
  32. package/src/templates/source/api/env.default +1 -4
  33. package/src/templates/source/api/prisma/schema.auth.prisma +1 -2
  34. package/src/templates/source/api/prisma/schema.default.prisma +1 -2
  35. package/src/templates/source/api/procedures/auth.ts +2 -2
  36. package/src/templates/source/api/procedures/health.ts +2 -2
  37. package/src/templates/source/api/procedures/users.auth.ts +2 -2
  38. package/src/templates/source/api/procedures/users.default.ts +2 -8
  39. package/src/templates/source/root/.cursorrules +3 -3
  40. package/src/templates/source/root/CLAUDE.auth.md +2 -2
  41. package/src/templates/source/root/CLAUDE.default.md +2 -2
  42. package/src/templates/source/rsc/env.example +1 -1
  43. package/src/templates/source/rsc/prisma/schema.prisma +1 -1
  44. package/src/templates/source/rsc/src/api/database.ts +76 -0
  45. package/src/templates/source/rsc/src/api/procedures/health.ts +2 -2
  46. package/src/templates/source/rsc/src/api/procedures/posts.ts +2 -2
  47. package/src/templates/source/rsc/src/api/procedures/users.ts +2 -2
@@ -1,8 +1,5 @@
1
1
  # Database URL
2
- # SQLite (local development):
3
- DATABASE_URL="file:./dev.db"
4
- # PostgreSQL (production):
5
- # DATABASE_URL="postgresql://user:password@localhost:5432/myapp"
2
+ DATABASE_URL="__DATABASE_URL__"
6
3
 
7
4
  # Server Configuration
8
5
  PORT=__API_PORT__
@@ -1,8 +1,5 @@
1
1
  # Database URL
2
- # SQLite (local development):
3
- DATABASE_URL="file:./dev.db"
4
- # PostgreSQL (production):
5
- # DATABASE_URL="postgresql://user:password@localhost:5432/myapp"
2
+ DATABASE_URL="__DATABASE_URL__"
6
3
 
7
4
  # Server Configuration
8
5
  PORT=__API_PORT__
@@ -1,7 +1,6 @@
1
1
  // Prisma Schema
2
2
  //
3
3
  // This schema defines the database structure with authentication support.
4
- // Using SQLite for simplicity - easily swap to PostgreSQL for production.
5
4
 
6
5
  generator client {
7
6
  provider = "prisma-client-js"
@@ -10,7 +9,7 @@ generator client {
10
9
  }
11
10
 
12
11
  datasource db {
13
- provider = "sqlite"
12
+ provider = "__DATABASE_PROVIDER__"
14
13
  }
15
14
 
16
15
  // ============================================================================
@@ -1,7 +1,6 @@
1
1
  // Prisma Schema
2
2
  //
3
3
  // This schema defines the database structure.
4
- // Using SQLite for simplicity - easily swap to PostgreSQL for production.
5
4
 
6
5
  generator client {
7
6
  provider = "prisma-client-js"
@@ -10,7 +9,7 @@ generator client {
10
9
  }
11
10
 
12
11
  datasource db {
13
- provider = "sqlite"
12
+ provider = "__DATABASE_PROVIDER__"
14
13
  }
15
14
 
16
15
  // ============================================================================
@@ -15,10 +15,10 @@ import {
15
15
  AuthError,
16
16
  authenticated,
17
17
  createAuthRateLimiter,
18
- defineProcedures,
19
18
  hashPassword,
20
19
  jwtManager,
21
20
  procedure,
21
+ procedures,
22
22
  verifyPassword,
23
23
  } from '@veloxts/velox';
24
24
 
@@ -104,7 +104,7 @@ const DUMMY_HASH = '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/X4.uy7dPSSXB5G6Uy
104
104
  // Auth Procedures
105
105
  // ============================================================================
106
106
 
107
- export const authProcedures = defineProcedures('auth', {
107
+ export const authProcedures = procedures('auth', {
108
108
  createAccount: procedure()
109
109
  .rest({ method: 'POST', path: '/auth/register' })
110
110
  .use(rateLimiter.register())
@@ -2,11 +2,11 @@
2
2
  * Health Check Procedures
3
3
  */
4
4
 
5
- import { defineProcedures, procedure, VELOX_VERSION } from '@veloxts/velox';
5
+ import { procedure, procedures, VELOX_VERSION } from '@veloxts/velox';
6
6
 
7
7
  import { HealthResponse } from '../schemas/health.js';
8
8
 
9
- export const healthProcedures = defineProcedures('health', {
9
+ export const healthProcedures = procedures('health', {
10
10
  getHealth: procedure()
11
11
  .rest({ method: 'GET', path: '/health' })
12
12
  .output(HealthResponse)
@@ -11,12 +11,12 @@
11
11
  import {
12
12
  AuthError,
13
13
  authenticated,
14
- defineProcedures,
15
14
  GuardError,
16
15
  hasRole,
17
16
  NotFoundError,
18
17
  paginationInputSchema,
19
18
  procedure,
19
+ procedures,
20
20
  z,
21
21
  } from '@veloxts/velox';
22
22
 
@@ -31,7 +31,7 @@ import {
31
31
  // User Procedures
32
32
  // ============================================================================
33
33
 
34
- export const userProcedures = defineProcedures('users', {
34
+ export const userProcedures = procedures('users', {
35
35
  getUser: procedure()
36
36
  .input(z.object({ id: z.string().uuid() }))
37
37
  .output(UserSchema)
@@ -7,13 +7,7 @@
7
7
  * - Output schema automatically serializes Date → string via withTimestamps()
8
8
  */
9
9
 
10
- import {
11
- defineProcedures,
12
- NotFoundError,
13
- paginationInputSchema,
14
- procedure,
15
- z,
16
- } from '@veloxts/velox';
10
+ import { NotFoundError, paginationInputSchema, procedure, procedures, z } from '@veloxts/velox';
17
11
 
18
12
  import {
19
13
  CreateUserInput,
@@ -22,7 +16,7 @@ import {
22
16
  UserSchema,
23
17
  } from '../schemas/user.js';
24
18
 
25
- export const userProcedures = defineProcedures('users', {
19
+ export const userProcedures = procedures('users', {
26
20
  getUser: procedure()
27
21
  .input(z.object({ id: z.string().uuid() }))
28
22
  .output(UserSchema)
@@ -53,9 +53,9 @@ CRITICAL - Never violate these rules:
53
53
  ### Procedure Pattern
54
54
 
55
55
  ```typescript
56
- import { defineProcedures, procedure, z } from '@veloxts/velox';
56
+ import { procedure, procedures, z } from '@veloxts/velox';
57
57
 
58
- export const entityProcedures = defineProcedures('entities', {
58
+ export const entityProcedures = procedures('entities', {
59
59
  getEntity: procedure()
60
60
  .input(z.object({ id: z.string().uuid() }))
61
61
  .output(EntitySchema)
@@ -144,7 +144,7 @@ __RUN_CMD__ db:studio # Open Prisma Studio
144
144
 
145
145
  ```typescript
146
146
  // VeloxTS imports (use umbrella package)
147
- import { defineProcedures, procedure, z } from '@veloxts/velox';
147
+ import { procedure, procedures, z } from '@veloxts/velox';
148
148
  /* @if auth */
149
149
  import { authenticated, hasRole } from '@veloxts/auth';
150
150
  /* @endif auth */
@@ -46,9 +46,9 @@ apps/
46
46
 
47
47
  ```typescript
48
48
  // apps/api/src/procedures/posts.ts
49
- import { defineProcedures, procedure, z } from '@veloxts/velox';
49
+ import { procedure, procedures, z } from '@veloxts/velox';
50
50
 
51
- export const postProcedures = defineProcedures('posts', {
51
+ export const postProcedures = procedures('posts', {
52
52
  // GET /api/posts/:id
53
53
  getPost: procedure()
54
54
  .input(z.object({ id: z.string().uuid() }))
@@ -45,9 +45,9 @@ apps/
45
45
 
46
46
  ```typescript
47
47
  // apps/api/src/procedures/posts.ts
48
- import { defineProcedures, procedure, z } from '@veloxts/velox';
48
+ import { procedure, procedures, z } from '@veloxts/velox';
49
49
 
50
- export const postProcedures = defineProcedures('posts', {
50
+ export const postProcedures = procedures('posts', {
51
51
  // GET /api/posts/:id
52
52
  getPost: procedure()
53
53
  .input(z.object({ id: z.string().uuid() }))
@@ -1,5 +1,5 @@
1
1
  # Database
2
- DATABASE_URL="file:./dev.db"
2
+ DATABASE_URL="__DATABASE_URL__"
3
3
 
4
4
  # Server
5
5
  PORT=__API_PORT__
@@ -6,7 +6,7 @@ generator client {
6
6
  }
7
7
 
8
8
  datasource db {
9
- provider = "sqlite"
9
+ provider = "__DATABASE_PROVIDER__"
10
10
  }
11
11
 
12
12
  model User {
@@ -13,16 +13,33 @@ import { createRequire } from 'node:module';
13
13
  import { dirname, resolve } from 'node:path';
14
14
  import { fileURLToPath } from 'node:url';
15
15
 
16
+ /* @if sqlite */
16
17
  // Type imports (erased at runtime, safe for ESM)
17
18
  import type { PrismaBetterSqlite3 as PrismaBetterSqlite3Type } from '@prisma/adapter-better-sqlite3';
19
+ /* @endif sqlite */
20
+ /* @if postgresql */
21
+ // Type imports (erased at runtime, safe for ESM)
22
+ import type { PrismaPg as PrismaPgType } from '@prisma/adapter-pg';
23
+ /* @endif postgresql */
18
24
  import type { PrismaClient as PrismaClientType } from '@prisma/client';
19
25
  import dotenv from 'dotenv';
26
+ import type { Pool as PoolType } from 'pg';
20
27
 
21
28
  // Runtime imports using createRequire for Node.js v24+ CJS interop
22
29
  const require = createRequire(import.meta.url);
30
+ /* @if sqlite */
23
31
  const { PrismaBetterSqlite3 } = require('@prisma/adapter-better-sqlite3') as {
24
32
  PrismaBetterSqlite3: typeof PrismaBetterSqlite3Type;
25
33
  };
34
+ /* @endif sqlite */
35
+ /* @if postgresql */
36
+ const { PrismaPg } = require('@prisma/adapter-pg') as {
37
+ PrismaPg: typeof PrismaPgType;
38
+ };
39
+ const { Pool } = require('pg') as {
40
+ Pool: typeof PoolType;
41
+ };
42
+ /* @endif postgresql */
26
43
  const { PrismaClient } = require('@prisma/client') as {
27
44
  PrismaClient: typeof PrismaClientType;
28
45
  };
@@ -39,8 +56,13 @@ declare global {
39
56
  // Allow global `var` declarations for hot reload in development
40
57
  // eslint-disable-next-line no-var
41
58
  var __db: PrismaClient | undefined;
59
+ /* @if postgresql */
60
+ // eslint-disable-next-line no-var
61
+ var __pool: InstanceType<typeof PoolType> | undefined;
62
+ /* @endif postgresql */
42
63
  }
43
64
 
65
+ /* @if sqlite */
44
66
  /**
45
67
  * Create a Prisma client instance using the SQLite adapter.
46
68
  *
@@ -63,10 +85,64 @@ function createPrismaClient(): PrismaClient {
63
85
  const adapter = new PrismaBetterSqlite3({ url: databaseUrl });
64
86
  return new PrismaClient({ adapter });
65
87
  }
88
+ /* @endif sqlite */
89
+ /* @if postgresql */
90
+ /**
91
+ * Create a PostgreSQL connection pool.
92
+ * Uses connection pooling for better performance in production.
93
+ */
94
+ function createPool(): InstanceType<typeof PoolType> {
95
+ const databaseUrl = process.env.DATABASE_URL;
66
96
 
97
+ if (!databaseUrl) {
98
+ throw new Error(
99
+ '[VeloxTS] DATABASE_URL environment variable is not set. ' +
100
+ 'Ensure .env file exists in project root with DATABASE_URL defined.'
101
+ );
102
+ }
103
+
104
+ return new Pool({
105
+ connectionString: databaseUrl,
106
+ max: 10, // Maximum connections in pool
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Create a Prisma client instance using the PostgreSQL adapter.
112
+ * Uses connection pooling for efficient database access.
113
+ */
114
+ function createPrismaClient(pool: InstanceType<typeof PoolType>): PrismaClient {
115
+ // Prisma 7 requires driver adapters for direct connections
116
+ const adapter = new PrismaPg(pool);
117
+ return new PrismaClient({ adapter });
118
+ }
119
+ /* @endif postgresql */
120
+
121
+ /* @if sqlite */
67
122
  // Use global singleton for hot reload in development
68
123
  export const db = globalThis.__db ?? createPrismaClient();
69
124
 
70
125
  if (process.env.NODE_ENV !== 'production') {
71
126
  globalThis.__db = db;
72
127
  }
128
+ /* @endif sqlite */
129
+ /* @if postgresql */
130
+ // Use global singletons for hot reload in development
131
+ const pool = globalThis.__pool ?? createPool();
132
+ export const db = globalThis.__db ?? createPrismaClient(pool);
133
+
134
+ if (process.env.NODE_ENV !== 'production') {
135
+ globalThis.__pool = pool;
136
+ globalThis.__db = db;
137
+ }
138
+
139
+ // Graceful shutdown - close pool on process exit
140
+ const shutdown = async () => {
141
+ await db.$disconnect();
142
+ await pool.end();
143
+ process.exit(0);
144
+ };
145
+
146
+ process.on('SIGTERM', shutdown);
147
+ process.on('SIGINT', shutdown);
148
+ /* @endif postgresql */
@@ -4,11 +4,11 @@
4
4
  * API endpoints for application health monitoring.
5
5
  */
6
6
 
7
- import { defineProcedures, procedure } from '@veloxts/router';
7
+ import { procedure, procedures } from '@veloxts/router';
8
8
 
9
9
  import { db } from '../database.js';
10
10
 
11
- export const healthProcedures = defineProcedures('health', {
11
+ export const healthProcedures = procedures('health', {
12
12
  /**
13
13
  * Basic health check
14
14
  * GET /api/health
@@ -6,7 +6,7 @@
6
6
  * Routes: /api/users/:userId/posts/*
7
7
  */
8
8
 
9
- import { defineProcedures, procedure } from '@veloxts/router';
9
+ import { procedure, procedures } from '@veloxts/router';
10
10
  import { z } from 'zod';
11
11
 
12
12
  import { db } from '../database.js';
@@ -17,7 +17,7 @@ import {
17
17
  UpdatePostSchema,
18
18
  } from '../schemas/post.js';
19
19
 
20
- export const postProcedures = defineProcedures('posts', {
20
+ export const postProcedures = procedures('posts', {
21
21
  /**
22
22
  * List all posts for a user
23
23
  * GET /api/users/:userId/posts
@@ -5,13 +5,13 @@
5
5
  * Uses direct db import for proper PrismaClient typing.
6
6
  */
7
7
 
8
- import { defineProcedures, procedure } from '@veloxts/router';
8
+ import { procedure, procedures } from '@veloxts/router';
9
9
  import { z } from 'zod';
10
10
 
11
11
  import { db } from '../database.js';
12
12
  import { CreateUserSchema, UpdateUserSchema, UserSchema } from '../schemas/user.js';
13
13
 
14
- export const userProcedures = defineProcedures('users', {
14
+ export const userProcedures = procedures('users', {
15
15
  /**
16
16
  * List all users
17
17
  * GET /api/users