create-velox-app 0.6.84 → 0.6.86
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/CHANGELOG.md
CHANGED
package/GUIDE.md
CHANGED
|
@@ -17,9 +17,10 @@ Your app will be running at `http://localhost:3030`
|
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
19
|
npx create-velox-app my-app # Default REST API
|
|
20
|
-
npx create-velox-app my-app --auth # With authentication
|
|
21
|
-
npx create-velox-app my-app --trpc # tRPC-only setup
|
|
22
|
-
npx create-velox-app my-app --rsc # Full-stack
|
|
20
|
+
npx create-velox-app my-app --auth # With JWT authentication
|
|
21
|
+
npx create-velox-app my-app --trpc # tRPC-only setup (no REST)
|
|
22
|
+
npx create-velox-app my-app --rsc # Full-stack RSC with Vinxi
|
|
23
|
+
npx create-velox-app my-app --rsc-auth # Full-stack RSC + JWT authentication
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
## Project Structure
|
package/dist/templates/trpc.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tRPC
|
|
2
|
+
* tRPC Template (Full-Stack)
|
|
3
3
|
*
|
|
4
4
|
* Full-stack workspace template with:
|
|
5
|
-
* - apps/api:
|
|
5
|
+
* - apps/api: tRPC-only API with user CRUD operations
|
|
6
6
|
* - apps/web: React frontend with TanStack Router
|
|
7
7
|
*
|
|
8
8
|
* Showcases VeloxTS's type-safe frontend-backend communication:
|
|
9
|
-
* - tRPC endpoints
|
|
10
|
-
* - REST endpoints for external APIs (auto-generated)
|
|
9
|
+
* - tRPC endpoints only (no REST)
|
|
11
10
|
* - End-to-end type safety without code generation
|
|
11
|
+
* - Frontend imports types directly from router.ts
|
|
12
|
+
*
|
|
13
|
+
* For REST + tRPC hybrid, use --default template and add registerRpc().
|
|
12
14
|
*/
|
|
13
15
|
import type { TemplateConfig, TemplateFile } from './types.js';
|
|
14
16
|
export declare function generateTrpcTemplate(config: TemplateConfig): TemplateFile[];
|
package/dist/templates/trpc.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* tRPC
|
|
2
|
+
* tRPC Template (Full-Stack)
|
|
3
3
|
*
|
|
4
4
|
* Full-stack workspace template with:
|
|
5
|
-
* - apps/api:
|
|
5
|
+
* - apps/api: tRPC-only API with user CRUD operations
|
|
6
6
|
* - apps/web: React frontend with TanStack Router
|
|
7
7
|
*
|
|
8
8
|
* Showcases VeloxTS's type-safe frontend-backend communication:
|
|
9
|
-
* - tRPC endpoints
|
|
10
|
-
* - REST endpoints for external APIs (auto-generated)
|
|
9
|
+
* - tRPC endpoints only (no REST)
|
|
11
10
|
* - End-to-end type safety without code generation
|
|
11
|
+
* - Frontend imports types directly from router.ts
|
|
12
|
+
*
|
|
13
|
+
* For REST + tRPC hybrid, use --default template and add registerRpc().
|
|
12
14
|
*/
|
|
13
15
|
import { compileTemplate } from './compiler.js';
|
|
14
16
|
import { applyDatabaseDependencies, DEFAULT_CONFIG, TRPC_CONFIG } from './placeholders.js';
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Application Entry Point - tRPC
|
|
2
|
+
* Application Entry Point - tRPC Template
|
|
3
3
|
*
|
|
4
|
-
* VeloxTS
|
|
4
|
+
* VeloxTS tRPC-only API architecture:
|
|
5
5
|
* - tRPC at /trpc for type-safe frontend communication
|
|
6
|
-
* - REST
|
|
6
|
+
* - No REST endpoints (use --default template for REST)
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Frontend imports types directly from router.ts for full type safety.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import 'dotenv/config';
|
|
@@ -13,15 +13,13 @@ import 'dotenv/config';
|
|
|
13
13
|
// Side-effect import for declaration merging (extends ctx.db type)
|
|
14
14
|
import './types.js';
|
|
15
15
|
|
|
16
|
-
import { databasePlugin,
|
|
16
|
+
import { databasePlugin, registerRpc, veloxApp } from '@veloxts/velox';
|
|
17
17
|
|
|
18
18
|
import { config } from './config/app.js';
|
|
19
19
|
import { db } from './config/database.js';
|
|
20
|
-
// Import router definition (type-only safe for frontend imports)
|
|
21
20
|
import { collections } from './router.js';
|
|
22
21
|
|
|
23
|
-
// Re-export AppRouter for
|
|
24
|
-
// Frontend should import from ./router.js directly for type safety
|
|
22
|
+
// Re-export AppRouter for frontend type imports
|
|
25
23
|
export type { AppRouter } from './router.js';
|
|
26
24
|
|
|
27
25
|
// ============================================================================
|
|
@@ -37,19 +35,18 @@ const app = await veloxApp({
|
|
|
37
35
|
await app.register(databasePlugin({ client: db }));
|
|
38
36
|
|
|
39
37
|
// ============================================================================
|
|
40
|
-
//
|
|
38
|
+
// tRPC Registration
|
|
41
39
|
// ============================================================================
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
|
-
*
|
|
42
|
+
* Register tRPC routes at /trpc
|
|
45
43
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
44
|
+
* Endpoints: /trpc/users.listUsers, /trpc/health.getHealth, etc.
|
|
45
|
+
*
|
|
46
|
+
* No REST endpoints - this template is for internal TypeScript clients only.
|
|
47
|
+
* For REST + tRPC hybrid, use the --default template and add registerRpc().
|
|
48
48
|
*/
|
|
49
|
-
await
|
|
50
|
-
api: config.apiPrefix,
|
|
51
|
-
rpc: '/trpc',
|
|
52
|
-
});
|
|
49
|
+
await registerRpc(app, collections, { prefix: '/trpc' });
|
|
53
50
|
|
|
54
51
|
await app.start();
|
|
55
52
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Router Definition - tRPC Hybrid Template
|
|
3
3
|
*
|
|
4
|
-
* This file exports the router
|
|
4
|
+
* This file exports the typed tRPC router for frontend type safety.
|
|
5
5
|
* It MUST NOT have any side effects (like importing dotenv) so that
|
|
6
6
|
* the frontend can safely import types from here.
|
|
7
7
|
*
|
|
@@ -14,26 +14,52 @@
|
|
|
14
14
|
// This is NOT a runtime import - it only affects type checking.
|
|
15
15
|
/// <reference path="./types.ts" />
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { rpc } from '@veloxts/velox';
|
|
18
18
|
|
|
19
19
|
import { healthProcedures } from './procedures/health.js';
|
|
20
20
|
import { userProcedures } from './procedures/users.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Procedure collections for REST and tRPC registration
|
|
24
|
+
*
|
|
25
|
+
* IMPORTANT: Use `as const` to preserve literal types for full type inference.
|
|
26
|
+
*/
|
|
27
|
+
export const collections = [healthProcedures, userProcedures] as const;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create typed tRPC router using the rpc() helper
|
|
31
|
+
*
|
|
32
|
+
* The rpc() helper returns:
|
|
33
|
+
* - `router`: Fully typed tRPC router for client type inference
|
|
34
|
+
* - `register`: Async function to register tRPC routes with Fastify
|
|
35
|
+
*
|
|
36
|
+
* NOTE: `register` is not exported to avoid TypeScript portability issues.
|
|
37
|
+
* Use registerRpc() in index.ts instead.
|
|
38
|
+
*/
|
|
39
|
+
const { router } = rpc(collections, { prefix: '/trpc' });
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Typed tRPC router for client imports
|
|
43
|
+
*
|
|
44
|
+
* Use this for type-safe frontend-backend communication.
|
|
45
|
+
*/
|
|
46
|
+
export { router };
|
|
24
47
|
|
|
25
48
|
/**
|
|
26
49
|
* AppRouter type for frontend type safety
|
|
27
50
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
51
|
+
* This is the properly typed tRPC router that enables:
|
|
52
|
+
* - Full autocomplete for procedure names
|
|
53
|
+
* - Type-safe input validation
|
|
54
|
+
* - Inferred output types
|
|
30
55
|
*
|
|
31
56
|
* @example
|
|
32
57
|
* ```typescript
|
|
33
58
|
* import type { AppRouter } from '../../api/src/router.js';
|
|
34
|
-
* import {
|
|
59
|
+
* import { createTRPCClient } from '@trpc/client';
|
|
35
60
|
*
|
|
36
|
-
*
|
|
61
|
+
* const client = createTRPCClient<AppRouter>({ links: [...] });
|
|
62
|
+
* const users = await client.users.listUsers.query(); // Fully typed!
|
|
37
63
|
* ```
|
|
38
64
|
*/
|
|
39
65
|
export type AppRouter = typeof router;
|