@idealyst/cli 1.0.46 → 1.0.48
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/dist/generators/fullstack.js +61 -3
- package/dist/generators/fullstack.js.map +1 -1
- package/dist/generators/native.js +12 -0
- package/dist/generators/native.js.map +1 -1
- package/dist/generators/utils.js +64 -31
- package/dist/generators/utils.js.map +1 -1
- package/dist/templates/api/README.md +207 -130
- package/dist/templates/api/package.json +5 -5
- package/dist/templates/api/src/controllers/TestController.ts +0 -0
- package/dist/templates/api/src/index.ts +2 -7
- package/dist/templates/api/src/lib/crud.ts +150 -0
- package/dist/templates/api/src/lib/database.ts +23 -0
- package/dist/templates/api/src/router/index.ts +104 -71
- package/dist/templates/api/src/routers/test.ts +59 -0
- package/dist/templates/api/src/routers/user.example.ts +83 -0
- package/dist/templates/api/src/server.ts +1 -1
- package/dist/templates/api/tsconfig.json +0 -1
- package/dist/templates/database/README.md +115 -1
- package/dist/templates/database/package.json +2 -0
- package/dist/templates/database/prisma/seed.ts +37 -1
- package/dist/templates/database/schema.prisma +11 -1
- package/dist/templates/native/index.js +1 -1
- package/dist/templates/native/metro.config.js +1 -1
- package/dist/templates/native/package.json +4 -0
- package/dist/templates/native/src/App.tsx +16 -0
- package/dist/templates/native/src/utils/trpc.ts +7 -127
- package/dist/templates/native/tsconfig.json +0 -2
- package/dist/templates/shared/package.json +8 -3
- package/dist/templates/shared/src/components/App.tsx +57 -0
- package/dist/templates/shared/src/components/HelloWorld.tsx +276 -86
- package/dist/templates/shared/src/components/index.ts +1 -1
- package/dist/templates/shared/src/index.ts +6 -2
- package/dist/templates/shared/src/trpc/client.ts +39 -0
- package/dist/templates/shared/tsconfig.json +1 -1
- package/dist/templates/web/README.md +65 -8
- package/dist/templates/web/package.json +3 -3
- package/dist/templates/web/src/App-with-trpc-and-shared.tsx +10 -6
- package/dist/templates/web/src/components/TestDemo.tsx +164 -0
- package/dist/templates/web/src/utils/trpc.ts +7 -93
- package/dist/templates/web/tsconfig.json +0 -1
- package/dist/templates/workspace/.devcontainer/devcontainer.json +4 -9
- package/dist/templates/workspace/.devcontainer/docker-compose.yml +1 -2
- package/dist/templates/workspace/.devcontainer/setup.sh +1 -1
- package/dist/templates/workspace/.env.example +1 -1
- package/dist/templates/workspace/Dockerfile +4 -4
- package/dist/templates/workspace/docker/nginx/prod.conf +2 -2
- package/dist/templates/workspace/docker/nginx.conf +1 -1
- package/dist/templates/workspace/docker/prometheus/prometheus.yml +1 -1
- package/dist/templates/workspace/docker-compose.yml +4 -5
- package/dist/templates/workspace/tsconfig.json +0 -1
- package/package.json +1 -1
- package/templates/api/README.md +207 -130
- package/templates/api/package.json +5 -5
- package/templates/api/src/controllers/TestController.ts +0 -0
- package/templates/api/src/index.ts +2 -7
- package/templates/api/src/lib/crud.ts +150 -0
- package/templates/api/src/lib/database.ts +23 -0
- package/templates/api/src/router/index.ts +104 -71
- package/templates/api/src/routers/test.ts +59 -0
- package/templates/api/src/routers/user.example.ts +83 -0
- package/templates/api/src/server.ts +1 -1
- package/templates/api/tsconfig.json +0 -1
- package/templates/database/README.md +115 -1
- package/templates/database/package.json +2 -0
- package/templates/database/prisma/seed.ts +37 -1
- package/templates/database/schema.prisma +11 -1
- package/templates/native/index.js +1 -1
- package/templates/native/metro.config.js +1 -1
- package/templates/native/package.json +4 -0
- package/templates/native/src/App.tsx +16 -0
- package/templates/native/src/utils/trpc.ts +7 -127
- package/templates/native/tsconfig.json +0 -2
- package/templates/shared/package.json +8 -3
- package/templates/shared/src/components/App.tsx +57 -0
- package/templates/shared/src/components/HelloWorld.tsx +276 -86
- package/templates/shared/src/components/index.ts +1 -1
- package/templates/shared/src/index.ts +6 -2
- package/templates/shared/src/trpc/client.ts +39 -0
- package/templates/shared/tsconfig.json +1 -1
- package/templates/web/README.md +65 -8
- package/templates/web/package.json +3 -3
- package/templates/web/src/App-with-trpc-and-shared.tsx +10 -6
- package/templates/web/src/components/TestDemo.tsx +164 -0
- package/templates/web/src/utils/trpc.ts +7 -93
- package/templates/web/tsconfig.json +0 -1
- package/templates/workspace/.devcontainer/devcontainer.json +4 -9
- package/templates/workspace/.devcontainer/docker-compose.yml +1 -2
- package/templates/workspace/.devcontainer/setup.sh +1 -1
- package/templates/workspace/.env.example +1 -1
- package/templates/workspace/Dockerfile +4 -4
- package/templates/workspace/docker/nginx/prod.conf +2 -2
- package/templates/workspace/docker/nginx.conf +1 -1
- package/templates/workspace/docker/prometheus/prometheus.yml +1 -1
- package/templates/workspace/docker-compose.yml +4 -5
- package/templates/workspace/tsconfig.json +0 -1
- package/dist/templates/api/src/controllers/UserController.ts +0 -102
- package/dist/templates/api/src/lib/controller.ts +0 -90
- package/dist/templates/api/src/lib/middleware.ts +0 -170
- package/dist/templates/api/src/middleware/auth.ts +0 -75
- package/dist/templates/api/src/middleware/common.ts +0 -103
- package/dist/templates/database/.env.example +0 -1
- package/dist/templates/native/App.tsx +0 -23
- package/dist/templates/native/src/App-with-trpc-and-shared.tsx +0 -12
- package/templates/api/src/controllers/UserController.ts +0 -102
- package/templates/api/src/lib/controller.ts +0 -90
- package/templates/api/src/lib/middleware.ts +0 -170
- package/templates/api/src/middleware/auth.ts +0 -75
- package/templates/api/src/middleware/common.ts +0 -103
- package/templates/database/.env.example +0 -1
- package/templates/native/App.tsx +0 -23
- package/templates/native/src/App-with-trpc-and-shared.tsx +0 -12
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { router, publicProcedure } from '../trpc.js';
|
|
3
|
+
import { testRouter } from '../routers/test.js';
|
|
3
4
|
|
|
4
5
|
export const appRouter = router({
|
|
5
6
|
// Simple hello world procedure
|
|
@@ -21,110 +22,142 @@ export const appRouter = router({
|
|
|
21
22
|
};
|
|
22
23
|
}),
|
|
23
24
|
|
|
24
|
-
//
|
|
25
|
+
// Test CRUD endpoints - generated automatically from Prisma model
|
|
26
|
+
test: testRouter,
|
|
27
|
+
|
|
28
|
+
// Add your model routers here
|
|
25
29
|
// Example:
|
|
26
30
|
// users: userRouter,
|
|
27
31
|
// posts: postRouter,
|
|
28
|
-
|
|
29
|
-
// Example controller integration:
|
|
30
|
-
// Uncomment the lines below and create the corresponding controllers
|
|
31
|
-
|
|
32
|
-
// 1. Import your controllers at the top:
|
|
33
|
-
// import { userRouter } from '../controllers/UserController.js';
|
|
34
|
-
|
|
35
|
-
// 2. Add them to the router:
|
|
36
|
-
// users: userRouter,
|
|
37
32
|
});
|
|
38
33
|
|
|
39
34
|
// Export type definition of API
|
|
40
35
|
export type AppRouter = typeof appRouter;
|
|
41
36
|
|
|
42
37
|
/*
|
|
43
|
-
|
|
38
|
+
SIMPLIFIED CRUD API SYSTEM:
|
|
44
39
|
|
|
45
|
-
This API template
|
|
40
|
+
This API template uses a simplified approach with automatic CRUD generation for Prisma models.
|
|
46
41
|
|
|
47
|
-
## Quick Start
|
|
42
|
+
## Quick Start:
|
|
48
43
|
|
|
49
|
-
1.
|
|
44
|
+
1. **Define your Prisma model** in packages/database/schema.prisma
|
|
45
|
+
2. **Create Zod schemas** for validation
|
|
46
|
+
3. **Generate CRUD router** using createCrudRouter()
|
|
47
|
+
4. **Add to main router**
|
|
48
|
+
|
|
49
|
+
## Example - Adding a User model:
|
|
50
|
+
|
|
51
|
+
### 1. Define Prisma model:
|
|
52
|
+
```prisma
|
|
53
|
+
model User {
|
|
54
|
+
id String @id @default(cuid())
|
|
55
|
+
email String @unique
|
|
56
|
+
name String
|
|
57
|
+
createdAt DateTime @default(now())
|
|
58
|
+
updatedAt DateTime @updatedAt
|
|
59
|
+
}
|
|
60
|
+
```
|
|
50
61
|
|
|
62
|
+
### 2. Create router file (src/routers/user.ts):
|
|
51
63
|
```typescript
|
|
52
64
|
import { z } from 'zod';
|
|
53
|
-
import {
|
|
54
|
-
import { requireAuth } from '../middleware/auth.js';
|
|
55
|
-
|
|
56
|
-
export class UserController extends BaseController {
|
|
57
|
-
getAll = this.createQueryWithMiddleware(
|
|
58
|
-
z.object({}),
|
|
59
|
-
[requireAuth],
|
|
60
|
-
async (input, ctx) => {
|
|
61
|
-
return await ctx.prisma.user.findMany();
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
+
import { createCrudRouter } from '../lib/crud.js';
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
const createUserSchema = z.object({
|
|
68
|
+
email: z.string().email(),
|
|
69
|
+
name: z.string().min(1),
|
|
68
70
|
});
|
|
69
|
-
```
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
const updateUserSchema = z.object({
|
|
73
|
+
email: z.string().email().optional(),
|
|
74
|
+
name: z.string().min(1).optional(),
|
|
75
|
+
});
|
|
72
76
|
|
|
77
|
+
export const userRouter = createCrudRouter(
|
|
78
|
+
'user',
|
|
79
|
+
createUserSchema,
|
|
80
|
+
updateUserSchema
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 3. Add to main router:
|
|
73
85
|
```typescript
|
|
74
|
-
import { userRouter } from '../
|
|
86
|
+
import { userRouter } from '../routers/user.js';
|
|
75
87
|
|
|
76
88
|
export const appRouter = router({
|
|
77
|
-
users: userRouter,
|
|
78
89
|
// ... other routes
|
|
90
|
+
users: userRouter,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 4. Use in frontend:
|
|
95
|
+
```typescript
|
|
96
|
+
// Get all users
|
|
97
|
+
const { data: users } = trpc.users.getAll.useQuery();
|
|
98
|
+
|
|
99
|
+
// Create user
|
|
100
|
+
const createUser = trpc.users.create.useMutation();
|
|
101
|
+
await createUser.mutateAsync({
|
|
102
|
+
email: 'user@example.com',
|
|
103
|
+
name: 'John Doe'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Update user
|
|
107
|
+
const updateUser = trpc.users.update.useMutation();
|
|
108
|
+
await updateUser.mutateAsync({
|
|
109
|
+
id: 'user-id',
|
|
110
|
+
data: { name: 'Jane Doe' }
|
|
79
111
|
});
|
|
80
112
|
```
|
|
81
113
|
|
|
82
|
-
## Available
|
|
114
|
+
## Available CRUD Operations:
|
|
83
115
|
|
|
84
|
-
|
|
85
|
-
- `
|
|
86
|
-
- `
|
|
87
|
-
- `
|
|
116
|
+
Each generated router includes:
|
|
117
|
+
- `getAll({ skip?, take?, orderBy? })` - List with pagination
|
|
118
|
+
- `getById({ id })` - Get single record
|
|
119
|
+
- `create(data)` - Create new record
|
|
120
|
+
- `update({ id, data })` - Update existing record
|
|
121
|
+
- `delete({ id })` - Delete record
|
|
122
|
+
- `count({ where? })` - Count records
|
|
88
123
|
|
|
89
|
-
|
|
90
|
-
- `logger` - Request/response logging
|
|
91
|
-
- `rateLimit(max, window)` - Rate limiting
|
|
92
|
-
- `responseTime` - Adds response time header
|
|
93
|
-
- `requestId` - Adds unique request ID
|
|
94
|
-
- `errorHandler` - Centralized error handling
|
|
124
|
+
## Advanced Usage:
|
|
95
125
|
|
|
96
|
-
|
|
126
|
+
### Custom procedures:
|
|
127
|
+
You can extend generated routers with custom procedures:
|
|
97
128
|
|
|
98
129
|
```typescript
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
getPrivateData = this.createQueryWithMiddleware(
|
|
104
|
-
schema,
|
|
105
|
-
[requireAuth],
|
|
106
|
-
handler
|
|
107
|
-
);
|
|
130
|
+
import { z } from 'zod';
|
|
131
|
+
import { router, publicProcedure } from '../trpc.js';
|
|
132
|
+
import { createCrudRouter } from '../lib/crud.js';
|
|
133
|
+
import { prisma } from '../lib/database.js';
|
|
108
134
|
|
|
109
|
-
|
|
110
|
-
adminAction = this.createMutationWithMiddleware(
|
|
111
|
-
schema,
|
|
112
|
-
[requireAuth, requireAdmin],
|
|
113
|
-
handler
|
|
114
|
-
);
|
|
135
|
+
const baseCrudRouter = createCrudRouter('user', createUserSchema);
|
|
115
136
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
137
|
+
export const userRouter = router({
|
|
138
|
+
...baseCrudRouter,
|
|
139
|
+
|
|
140
|
+
// Add custom procedures
|
|
141
|
+
getByEmail: publicProcedure
|
|
142
|
+
.input(z.object({ email: z.string().email() }))
|
|
143
|
+
.query(async ({ input }) => {
|
|
144
|
+
return await prisma.user.findUnique({
|
|
145
|
+
where: { email: input.email }
|
|
146
|
+
});
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Authentication & Authorization:
|
|
152
|
+
Use middleware for protected procedures:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { protectedProcedure } from '../trpc.js';
|
|
156
|
+
|
|
157
|
+
// Replace publicProcedure with protectedProcedure in createCrudRouter
|
|
158
|
+
// or create a custom version for authenticated routes
|
|
122
159
|
```
|
|
123
160
|
|
|
124
|
-
This system
|
|
125
|
-
|
|
126
|
-
✅ Reusable middleware
|
|
127
|
-
✅ Clean controller organization
|
|
128
|
-
✅ Easy testing
|
|
129
|
-
✅ Consistent error handling
|
|
161
|
+
This simplified system removes the controller layer complexity while providing
|
|
162
|
+
type-safe, validated CRUD operations for all your Prisma models.
|
|
130
163
|
*/
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createCrudRouter } from "../lib/crud.js";
|
|
3
|
+
|
|
4
|
+
// Define Zod schemas for the Test model based on the Prisma schema
|
|
5
|
+
const createTestSchema = z.object({
|
|
6
|
+
name: z.string().min(1, "Name is required"),
|
|
7
|
+
message: z.string().min(1, "Message is required"),
|
|
8
|
+
status: z.string().optional().default("active"),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const updateTestSchema = z.object({
|
|
12
|
+
name: z.string().min(1, "Name is required").optional(),
|
|
13
|
+
message: z.string().min(1, "Message is required").optional(),
|
|
14
|
+
status: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Create the CRUD router for the Test model
|
|
18
|
+
export const testRouter = createCrudRouter(
|
|
19
|
+
"Test",
|
|
20
|
+
createTestSchema,
|
|
21
|
+
updateTestSchema
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This generates the following endpoints:
|
|
26
|
+
*
|
|
27
|
+
* - test.getAll({ skip?, take?, orderBy? }) - Get all test records with pagination
|
|
28
|
+
* - test.getById({ id }) - Get test record by ID
|
|
29
|
+
* - test.create({ name, message, status? }) - Create new test record
|
|
30
|
+
* - test.update({ id, data: { name?, message?, status? } }) - Update test record
|
|
31
|
+
* - test.delete({ id }) - Delete test record
|
|
32
|
+
* - test.count({ where? }) - Get test record count
|
|
33
|
+
*
|
|
34
|
+
* Example usage in frontend:
|
|
35
|
+
*
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Get all tests
|
|
38
|
+
* const { data: tests } = trpc.test.getAll.useQuery({ take: 10 });
|
|
39
|
+
*
|
|
40
|
+
* // Create a new test
|
|
41
|
+
* const createTest = trpc.test.create.useMutation();
|
|
42
|
+
* await createTest.mutateAsync({
|
|
43
|
+
* name: 'My Test',
|
|
44
|
+
* message: 'This is a test message',
|
|
45
|
+
* status: 'active'
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Update a test
|
|
49
|
+
* const updateTest = trpc.test.update.useMutation();
|
|
50
|
+
* await updateTest.mutateAsync({
|
|
51
|
+
* id: 'test-id',
|
|
52
|
+
* data: { name: 'Updated Test' }
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Delete a test
|
|
56
|
+
* const deleteTest = trpc.test.delete.useMutation();
|
|
57
|
+
* await deleteTest.mutateAsync({ id: 'test-id' });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createCrudRouter } from '../lib/crud.js';
|
|
3
|
+
|
|
4
|
+
// Define Zod schemas for the User model
|
|
5
|
+
const createUserSchema = z.object({
|
|
6
|
+
email: z.string().email('Invalid email format'),
|
|
7
|
+
name: z.string().min(1, 'Name is required'),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const updateUserSchema = z.object({
|
|
11
|
+
email: z.string().email('Invalid email format').optional(),
|
|
12
|
+
name: z.string().min(1, 'Name is required').optional(),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Create the CRUD router for the User model
|
|
16
|
+
export const userRouter = createCrudRouter(
|
|
17
|
+
'user',
|
|
18
|
+
createUserSchema,
|
|
19
|
+
updateUserSchema
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This generates the following endpoints:
|
|
24
|
+
*
|
|
25
|
+
* - users.getAll({ skip?, take?, orderBy? }) - Get all users with pagination
|
|
26
|
+
* - users.getById({ id }) - Get user by ID
|
|
27
|
+
* - users.create({ name, email }) - Create new user
|
|
28
|
+
* - users.update({ id, data: { name?, email? } }) - Update user
|
|
29
|
+
* - users.delete({ id }) - Delete user
|
|
30
|
+
* - users.count({ where? }) - Get user count
|
|
31
|
+
*
|
|
32
|
+
* To use this router:
|
|
33
|
+
*
|
|
34
|
+
* 1. First add a User model to your Prisma schema:
|
|
35
|
+
*
|
|
36
|
+
* ```prisma
|
|
37
|
+
* model User {
|
|
38
|
+
* id String @id @default(cuid())
|
|
39
|
+
* email String @unique
|
|
40
|
+
* name String
|
|
41
|
+
* createdAt DateTime @default(now())
|
|
42
|
+
* updatedAt DateTime @updatedAt
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* 2. Run `yarn db:migrate` to apply the schema changes
|
|
47
|
+
*
|
|
48
|
+
* 3. Uncomment the users router in src/router/index.ts:
|
|
49
|
+
*
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { userRouter } from '../routers/user.js';
|
|
52
|
+
*
|
|
53
|
+
* export const appRouter = router({
|
|
54
|
+
* // ... other routes
|
|
55
|
+
* users: userRouter,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* 4. Use in your frontend:
|
|
60
|
+
*
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Get all users
|
|
63
|
+
* const { data: users } = trpc.users.getAll.useQuery({ take: 10 });
|
|
64
|
+
*
|
|
65
|
+
* // Create a new user
|
|
66
|
+
* const createUser = trpc.users.create.useMutation();
|
|
67
|
+
* await createUser.mutateAsync({
|
|
68
|
+
* name: 'John Doe',
|
|
69
|
+
* email: 'john@example.com'
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Update a user
|
|
73
|
+
* const updateUser = trpc.users.update.useMutation();
|
|
74
|
+
* await updateUser.mutateAsync({
|
|
75
|
+
* id: 'user-id',
|
|
76
|
+
* data: { name: 'Jane Doe' }
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Delete a user
|
|
80
|
+
* const deleteUser = trpc.users.delete.useMutation();
|
|
81
|
+
* await deleteUser.mutateAsync({ id: 'user-id' });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Database Package
|
|
2
2
|
|
|
3
|
-
This package provides database access and validation schemas for the workspace.
|
|
3
|
+
This package provides database access and validation schemas for the workspace using Prisma ORM.
|
|
4
4
|
|
|
5
5
|
## Setup
|
|
6
6
|
|
|
@@ -25,6 +25,120 @@ yarn db:generate
|
|
|
25
25
|
yarn db:push
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
5. Seed the database with test data:
|
|
29
|
+
```bash
|
|
30
|
+
yarn db:seed
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Database Schema
|
|
34
|
+
|
|
35
|
+
### Test Model
|
|
36
|
+
|
|
37
|
+
The Test model is included for quick testing and API demonstration:
|
|
38
|
+
|
|
39
|
+
```prisma
|
|
40
|
+
model Test {
|
|
41
|
+
id String @id @default(cuid())
|
|
42
|
+
name String
|
|
43
|
+
message String
|
|
44
|
+
status String @default("active")
|
|
45
|
+
createdAt DateTime @default(now())
|
|
46
|
+
updatedAt DateTime @updatedAt
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Fields:
|
|
51
|
+
- `id`: Unique identifier (CUID)
|
|
52
|
+
- `name`: Test name/title
|
|
53
|
+
- `message`: Test message content
|
|
54
|
+
- `status`: Test status (defaults to "active")
|
|
55
|
+
- `createdAt`: Record creation timestamp
|
|
56
|
+
- `updatedAt`: Record last update timestamp
|
|
57
|
+
|
|
58
|
+
### Sample Models
|
|
59
|
+
|
|
60
|
+
The schema also includes comprehensive example models for reference:
|
|
61
|
+
|
|
62
|
+
#### User Model
|
|
63
|
+
- Complete user management with authentication fields
|
|
64
|
+
- Email validation and profile information
|
|
65
|
+
- Timestamps for tracking
|
|
66
|
+
|
|
67
|
+
#### Post Model
|
|
68
|
+
- Blog post or content management
|
|
69
|
+
- User relationship for authorship
|
|
70
|
+
- Publishing status and timestamps
|
|
71
|
+
|
|
72
|
+
#### Comment Model
|
|
73
|
+
- Comment system for posts
|
|
74
|
+
- User and post relationships
|
|
75
|
+
- Moderation support
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
### In API Code
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { db } from '@{{workspaceScope}}/database';
|
|
83
|
+
|
|
84
|
+
// Create a test record
|
|
85
|
+
const test = await db.test.create({
|
|
86
|
+
data: {
|
|
87
|
+
name: 'My Test',
|
|
88
|
+
message: 'This is a test message',
|
|
89
|
+
status: 'active'
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Get all tests
|
|
94
|
+
const tests = await db.test.findMany();
|
|
95
|
+
|
|
96
|
+
// Update a test
|
|
97
|
+
const updatedTest = await db.test.update({
|
|
98
|
+
where: { id: 'test-id' },
|
|
99
|
+
data: { status: 'completed' }
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Prisma Commands
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Generate client
|
|
107
|
+
yarn prisma:generate
|
|
108
|
+
|
|
109
|
+
# Run migrations
|
|
110
|
+
yarn prisma:migrate
|
|
111
|
+
|
|
112
|
+
# Reset database
|
|
113
|
+
yarn prisma:reset
|
|
114
|
+
|
|
115
|
+
# Seed database
|
|
116
|
+
yarn prisma:seed
|
|
117
|
+
|
|
118
|
+
# Open Prisma Studio
|
|
119
|
+
yarn prisma:studio
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Quick Test
|
|
123
|
+
|
|
124
|
+
The database includes a simple `Test` model for immediate testing:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { prisma } from '@{{workspaceScope}}/{{name}}';
|
|
128
|
+
|
|
129
|
+
// Get all test entries
|
|
130
|
+
const tests = await prisma.test.findMany();
|
|
131
|
+
|
|
132
|
+
// Create a new test entry
|
|
133
|
+
const newTest = await prisma.test.create({
|
|
134
|
+
data: {
|
|
135
|
+
name: 'My Test',
|
|
136
|
+
message: 'Testing the database connection',
|
|
137
|
+
status: 'active',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
28
142
|
## Usage
|
|
29
143
|
|
|
30
144
|
```typescript
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"db:push": "prisma db push",
|
|
29
29
|
"db:migrate": "prisma migrate dev",
|
|
30
30
|
"db:studio": "prisma studio",
|
|
31
|
+
"db:seed": "tsx prisma/seed.ts",
|
|
31
32
|
"db:reset": "prisma migrate reset"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/node": "^20.10.0",
|
|
39
40
|
"prisma": "^5.19.1",
|
|
41
|
+
"tsx": "^4.7.0",
|
|
40
42
|
"typescript": "^5.3.3"
|
|
41
43
|
},
|
|
42
44
|
"files": [
|
|
@@ -6,7 +6,43 @@ async function main() {
|
|
|
6
6
|
// Add your seed data here
|
|
7
7
|
console.log('🌱 Seeding database...');
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// Create some test data for the Test model
|
|
10
|
+
console.log('📝 Creating test entries...');
|
|
11
|
+
|
|
12
|
+
const testEntries = await Promise.all([
|
|
13
|
+
prisma.test.create({
|
|
14
|
+
data: {
|
|
15
|
+
name: 'API Connection Test',
|
|
16
|
+
message: 'This test verifies that the API can connect to the database successfully.',
|
|
17
|
+
status: 'active',
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
prisma.test.create({
|
|
21
|
+
data: {
|
|
22
|
+
name: 'Data Validation Test',
|
|
23
|
+
message: 'This test ensures that data validation is working correctly across the stack.',
|
|
24
|
+
status: 'active',
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
prisma.test.create({
|
|
28
|
+
data: {
|
|
29
|
+
name: 'tRPC Integration Test',
|
|
30
|
+
message: 'This test confirms that tRPC endpoints are properly configured and accessible.',
|
|
31
|
+
status: 'active',
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
prisma.test.create({
|
|
35
|
+
data: {
|
|
36
|
+
name: 'Sample Inactive Test',
|
|
37
|
+
message: 'This is an example of an inactive test entry.',
|
|
38
|
+
status: 'inactive',
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
console.log(`✅ Created ${testEntries.length} test entries`);
|
|
44
|
+
|
|
45
|
+
// Example seed data for other models (uncommented for reference)
|
|
10
46
|
// const user = await prisma.user.create({
|
|
11
47
|
// data: {
|
|
12
48
|
// email: 'admin@example.com',
|
|
@@ -7,10 +7,20 @@ generator client {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
datasource db {
|
|
10
|
-
provider = "
|
|
10
|
+
provider = "postgres"
|
|
11
11
|
url = env("DATABASE_URL")
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
// Simple Test model for quick API testing
|
|
15
|
+
model Test {
|
|
16
|
+
id String @id @default(cuid())
|
|
17
|
+
name String
|
|
18
|
+
message String
|
|
19
|
+
status String @default("active") // "active", "inactive"
|
|
20
|
+
createdAt DateTime @default(now())
|
|
21
|
+
updatedAt DateTime @updatedAt
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
// Demo User model with profile information
|
|
15
25
|
model User {
|
|
16
26
|
id String @id @default(cuid())
|
|
@@ -16,7 +16,7 @@ const config = {
|
|
|
16
16
|
path.resolve(__dirname, '..', 'node_modules'),
|
|
17
17
|
],
|
|
18
18
|
// Important for Idealyst to use .native extensions for React Native (eg: @idealyst/components/src/Button/Button.native.tsx)
|
|
19
|
-
sourceExts: ['native.tsx', 'native.ts', 'tsx', 'ts', 'native.jsx', 'native.js', 'jsx', 'js', 'json'],
|
|
19
|
+
sourceExts: ['native.tsx', 'native.ts', 'tsx', 'ts', 'native.jsx', 'native.js', 'jsx', 'js', 'json', 'cjs'],
|
|
20
20
|
},
|
|
21
21
|
watcher: {
|
|
22
22
|
// When configuring custom components with .native extensions, make sure the watcher looks for them
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"@idealyst/components": "^1.0.21",
|
|
17
17
|
"@idealyst/navigation": "^1.0.21",
|
|
18
18
|
"@idealyst/theme": "^1.0.21",
|
|
19
|
+
"@tanstack/react-query": "^5.83.0",
|
|
20
|
+
"@trpc/client": "^11.5.1",
|
|
21
|
+
"@trpc/react-query": "^11.5.1",
|
|
22
|
+
"@trpc/server": "^11.5.1",
|
|
19
23
|
"react": "^18.2.0",
|
|
20
24
|
"react-native": "^0.73.0"
|
|
21
25
|
},
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { App } from '@{{workspaceScope}}/shared';
|
|
3
|
+
|
|
4
|
+
// Main App component using shared App wrapper
|
|
5
|
+
function AppWithShared() {
|
|
6
|
+
return (
|
|
7
|
+
<App
|
|
8
|
+
apiUrl="http://localhost:3000/trpc"
|
|
9
|
+
name="{{projectName}} Developer"
|
|
10
|
+
platform="mobile"
|
|
11
|
+
projectName="{{projectName}}"
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default AppWithShared;
|