@idealyst/cli 1.0.92 → 1.0.93

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 (43) hide show
  1. package/dist/template/packages/api/README.md +400 -164
  2. package/dist/template/packages/api/package.json +11 -1
  3. package/dist/template/packages/api/src/context.ts +35 -2
  4. package/dist/template/packages/api/src/graphql/builder.ts +75 -0
  5. package/dist/template/packages/api/src/graphql/generated.ts +64 -0
  6. package/dist/template/packages/api/src/graphql/index.ts +75 -0
  7. package/dist/template/packages/api/src/graphql/types/index.ts +44 -0
  8. package/dist/template/packages/api/src/graphql/types/test.ts +245 -0
  9. package/dist/template/packages/api/src/index.ts +20 -3
  10. package/dist/template/packages/api/src/lib/database.ts +1 -1
  11. package/dist/template/packages/api/src/routers/test.ts +140 -38
  12. package/dist/template/packages/api/src/server.ts +23 -5
  13. package/dist/template/packages/api/tsconfig.json +1 -0
  14. package/dist/template/packages/shared/package.json +6 -0
  15. package/dist/template/packages/shared/src/components/App.tsx +13 -2
  16. package/dist/template/packages/shared/src/components/HelloWorld.tsx +333 -106
  17. package/dist/template/packages/shared/src/graphql/client.ts +34 -0
  18. package/dist/template/packages/shared/src/index.ts +8 -0
  19. package/dist/template/packages/web/vite.config.ts +2 -2
  20. package/package.json +1 -1
  21. package/template/packages/api/README.md +400 -164
  22. package/template/packages/api/package.json +11 -1
  23. package/template/packages/api/src/context.ts +35 -2
  24. package/template/packages/api/src/graphql/builder.ts +75 -0
  25. package/template/packages/api/src/graphql/generated.ts +64 -0
  26. package/template/packages/api/src/graphql/index.ts +75 -0
  27. package/template/packages/api/src/graphql/types/index.ts +44 -0
  28. package/template/packages/api/src/graphql/types/test.ts +245 -0
  29. package/template/packages/api/src/index.ts +20 -3
  30. package/template/packages/api/src/lib/database.ts +1 -1
  31. package/template/packages/api/src/routers/test.ts +140 -38
  32. package/template/packages/api/src/server.ts +23 -5
  33. package/template/packages/api/tsconfig.json +1 -0
  34. package/template/packages/shared/package.json +6 -0
  35. package/template/packages/shared/src/components/App.tsx +13 -2
  36. package/template/packages/shared/src/components/HelloWorld.tsx +333 -106
  37. package/template/packages/shared/src/graphql/client.ts +34 -0
  38. package/template/packages/shared/src/index.ts +8 -0
  39. package/template/packages/web/vite.config.ts +2 -2
  40. package/dist/template/packages/api/src/lib/crud.ts +0 -150
  41. package/dist/template/packages/api/src/routers/user.example.ts +0 -83
  42. package/template/packages/api/src/lib/crud.ts +0 -150
  43. package/template/packages/api/src/routers/user.example.ts +0 -83
@@ -1,150 +0,0 @@
1
- import type { Prisma } from '@{{workspaceScope}}/database/client';
2
- import { z } from 'zod';
3
- import { prisma } from '../lib/database.js';
4
- import { publicProcedure, router } from '../trpc.js';
5
-
6
- /**
7
- * Creates a standard CRUD router for any Prisma model
8
- *
9
- * @param modelName - The name of the Prisma model (e.g., 'user', 'post', 'test')
10
- * @param createSchema - Zod schema for creating new records
11
- * @param updateSchema - Zod schema for updating records (optional, defaults to createSchema.partial())
12
- * @returns tRPC router with standard CRUD operations
13
- */
14
- export function createCrudRouter<
15
- TModelName extends Prisma.ModelName,
16
- TCreateInput extends Record<string, any>,
17
- TUpdateInput extends Record<string, any> = Partial<TCreateInput>
18
- >(
19
- modelName: TModelName,
20
- createSchema: z.ZodSchema<TCreateInput>,
21
- updateSchema?: z.ZodSchema<TUpdateInput>
22
- ) {
23
- const model = (prisma as any)[modelName];
24
- const updateSchemaToUse = updateSchema || createSchema.partial();
25
-
26
- return router({
27
- // Get all records
28
- getAll: publicProcedure
29
- .input(z.object({
30
- skip: z.number().min(0).optional(),
31
- take: z.number().min(1).max(100).optional(),
32
- orderBy: z.record(z.enum(['asc', 'desc'])).optional(),
33
- }))
34
- .query(async ({ input }) => {
35
- return await model.findMany({
36
- skip: input.skip,
37
- take: input.take || 10,
38
- orderBy: input.orderBy,
39
- });
40
- }),
41
-
42
- // Get record by ID
43
- getById: publicProcedure
44
- .input(z.object({ id: z.string() }))
45
- .query(async ({ input }) => {
46
- const record = await model.findUnique({
47
- where: { id: input.id },
48
- });
49
-
50
- if (!record) {
51
- throw new Error(`${modelName} not found`);
52
- }
53
-
54
- return record;
55
- }),
56
-
57
- // Create new record
58
- create: publicProcedure
59
- .input(createSchema)
60
- .mutation(async ({ input }) => {
61
- return await model.create({
62
- data: input,
63
- });
64
- }),
65
-
66
- // Update record
67
- update: publicProcedure
68
- .input(z.object({
69
- id: z.string(),
70
- data: updateSchemaToUse,
71
- }))
72
- .mutation(async ({ input }) => {
73
- const existingRecord = await model.findUnique({
74
- where: { id: input.id },
75
- });
76
-
77
- if (!existingRecord) {
78
- throw new Error(`${modelName} not found`);
79
- }
80
-
81
- return await model.update({
82
- where: { id: input.id },
83
- data: input.data,
84
- });
85
- }),
86
-
87
- // Delete record
88
- delete: publicProcedure
89
- .input(z.object({ id: z.string() }))
90
- .mutation(async ({ input }) => {
91
- const existingRecord = await model.findUnique({
92
- where: { id: input.id },
93
- });
94
-
95
- if (!existingRecord) {
96
- throw new Error(`${modelName} not found`);
97
- }
98
-
99
- return await model.delete({
100
- where: { id: input.id },
101
- });
102
- }),
103
-
104
- // Get count
105
- count: publicProcedure
106
- .input(z.object({
107
- where: z.record(z.any()).optional(),
108
- }))
109
- .query(async ({ input }) => {
110
- return await model.count({
111
- where: input.where,
112
- });
113
- }),
114
- });
115
- }
116
-
117
- /**
118
- * Example usage:
119
- *
120
- * ```typescript
121
- * import { z } from 'zod';
122
- * import { createCrudRouter } from '../lib/crud.js';
123
- *
124
- * // Define schemas for your model
125
- * const createUserSchema = z.object({
126
- * email: z.string().email(),
127
- * name: z.string(),
128
- * });
129
- *
130
- * const updateUserSchema = z.object({
131
- * email: z.string().email().optional(),
132
- * name: z.string().optional(),
133
- * });
134
- *
135
- * // Create the CRUD router
136
- * export const userRouter = createCrudRouter(
137
- * 'user',
138
- * createUserSchema,
139
- * updateUserSchema
140
- * );
141
- * ```
142
- *
143
- * This will generate:
144
- * - users.getAll() - Get all users with pagination
145
- * - users.getById({ id }) - Get user by ID
146
- * - users.create({ email, name }) - Create new user
147
- * - users.update({ id, data: { email?, name? } }) - Update user
148
- * - users.delete({ id }) - Delete user
149
- * - users.count() - Get user count
150
- */
@@ -1,83 +0,0 @@
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,150 +0,0 @@
1
- import type { Prisma } from '@{{workspaceScope}}/database/client';
2
- import { z } from 'zod';
3
- import { prisma } from '../lib/database.js';
4
- import { publicProcedure, router } from '../trpc.js';
5
-
6
- /**
7
- * Creates a standard CRUD router for any Prisma model
8
- *
9
- * @param modelName - The name of the Prisma model (e.g., 'user', 'post', 'test')
10
- * @param createSchema - Zod schema for creating new records
11
- * @param updateSchema - Zod schema for updating records (optional, defaults to createSchema.partial())
12
- * @returns tRPC router with standard CRUD operations
13
- */
14
- export function createCrudRouter<
15
- TModelName extends Prisma.ModelName,
16
- TCreateInput extends Record<string, any>,
17
- TUpdateInput extends Record<string, any> = Partial<TCreateInput>
18
- >(
19
- modelName: TModelName,
20
- createSchema: z.ZodSchema<TCreateInput>,
21
- updateSchema?: z.ZodSchema<TUpdateInput>
22
- ) {
23
- const model = (prisma as any)[modelName];
24
- const updateSchemaToUse = updateSchema || createSchema.partial();
25
-
26
- return router({
27
- // Get all records
28
- getAll: publicProcedure
29
- .input(z.object({
30
- skip: z.number().min(0).optional(),
31
- take: z.number().min(1).max(100).optional(),
32
- orderBy: z.record(z.enum(['asc', 'desc'])).optional(),
33
- }))
34
- .query(async ({ input }) => {
35
- return await model.findMany({
36
- skip: input.skip,
37
- take: input.take || 10,
38
- orderBy: input.orderBy,
39
- });
40
- }),
41
-
42
- // Get record by ID
43
- getById: publicProcedure
44
- .input(z.object({ id: z.string() }))
45
- .query(async ({ input }) => {
46
- const record = await model.findUnique({
47
- where: { id: input.id },
48
- });
49
-
50
- if (!record) {
51
- throw new Error(`${modelName} not found`);
52
- }
53
-
54
- return record;
55
- }),
56
-
57
- // Create new record
58
- create: publicProcedure
59
- .input(createSchema)
60
- .mutation(async ({ input }) => {
61
- return await model.create({
62
- data: input,
63
- });
64
- }),
65
-
66
- // Update record
67
- update: publicProcedure
68
- .input(z.object({
69
- id: z.string(),
70
- data: updateSchemaToUse,
71
- }))
72
- .mutation(async ({ input }) => {
73
- const existingRecord = await model.findUnique({
74
- where: { id: input.id },
75
- });
76
-
77
- if (!existingRecord) {
78
- throw new Error(`${modelName} not found`);
79
- }
80
-
81
- return await model.update({
82
- where: { id: input.id },
83
- data: input.data,
84
- });
85
- }),
86
-
87
- // Delete record
88
- delete: publicProcedure
89
- .input(z.object({ id: z.string() }))
90
- .mutation(async ({ input }) => {
91
- const existingRecord = await model.findUnique({
92
- where: { id: input.id },
93
- });
94
-
95
- if (!existingRecord) {
96
- throw new Error(`${modelName} not found`);
97
- }
98
-
99
- return await model.delete({
100
- where: { id: input.id },
101
- });
102
- }),
103
-
104
- // Get count
105
- count: publicProcedure
106
- .input(z.object({
107
- where: z.record(z.any()).optional(),
108
- }))
109
- .query(async ({ input }) => {
110
- return await model.count({
111
- where: input.where,
112
- });
113
- }),
114
- });
115
- }
116
-
117
- /**
118
- * Example usage:
119
- *
120
- * ```typescript
121
- * import { z } from 'zod';
122
- * import { createCrudRouter } from '../lib/crud.js';
123
- *
124
- * // Define schemas for your model
125
- * const createUserSchema = z.object({
126
- * email: z.string().email(),
127
- * name: z.string(),
128
- * });
129
- *
130
- * const updateUserSchema = z.object({
131
- * email: z.string().email().optional(),
132
- * name: z.string().optional(),
133
- * });
134
- *
135
- * // Create the CRUD router
136
- * export const userRouter = createCrudRouter(
137
- * 'user',
138
- * createUserSchema,
139
- * updateUserSchema
140
- * );
141
- * ```
142
- *
143
- * This will generate:
144
- * - users.getAll() - Get all users with pagination
145
- * - users.getById({ id }) - Get user by ID
146
- * - users.create({ email, name }) - Create new user
147
- * - users.update({ id, data: { email?, name? } }) - Update user
148
- * - users.delete({ id }) - Delete user
149
- * - users.count() - Get user count
150
- */
@@ -1,83 +0,0 @@
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
- */