Skip to content

Commit 3663649

Browse files
committed
chore: add contracts options
1 parent ee6835d commit 3663649

14 files changed

Lines changed: 1485 additions & 80 deletions

File tree

dev/typescript/presets.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export const presets = {
3434
/** RPC-style SDK with Zod validation */
3535
{
3636
contracts: {
37-
containerName: 'contract',
37+
// containerName: 'contract',
38+
strategy: 'single',
3839
},
3940
name: '@orpc/contract',
4041
},
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { oc } from '@orpc/contract';
4+
5+
import { zCreatePostData, zCreatePostResponse, zCreateUserData, zCreateUserResponse, zDeleteUserData, zGetPostByIdData, zGetPostByIdResponse, zGetPostsData, zGetPostsResponse, zGetUserByIdData, zGetUserByIdResponse, zGetUsersData, zGetUsersResponse, zUpdateUserData, zUpdateUserResponse } from '../zod.gen';
6+
7+
export const base = oc.$route({ inputStructure: 'detailed' });
8+
9+
/**
10+
* Get all users
11+
*/
12+
export const GetUsers = base.route({
13+
method: 'GET',
14+
operationId: 'getUsers',
15+
path: '/users',
16+
summary: 'Get all users',
17+
tags: ['users']
18+
}).input(zGetUsersData).output(zGetUsersResponse);
19+
20+
/**
21+
* Create a new user
22+
*/
23+
export const CreateUser = base.route({
24+
method: 'POST',
25+
operationId: 'createUser',
26+
path: '/users',
27+
successStatus: 201,
28+
summary: 'Create a new user',
29+
tags: ['users']
30+
}).input(zCreateUserData).output(zCreateUserResponse);
31+
32+
/**
33+
* Delete a user
34+
*/
35+
export const DeleteUser = base.route({
36+
method: 'DELETE',
37+
operationId: 'deleteUser',
38+
path: '/users/{userId}',
39+
summary: 'Delete a user',
40+
tags: ['users']
41+
}).input(zDeleteUserData);
42+
43+
/**
44+
* Get a user by ID
45+
*/
46+
export const GetUserById = base.route({
47+
method: 'GET',
48+
operationId: 'getUserById',
49+
path: '/users/{userId}',
50+
summary: 'Get a user by ID',
51+
tags: ['users']
52+
}).input(zGetUserByIdData).output(zGetUserByIdResponse);
53+
54+
/**
55+
* Update a user
56+
*/
57+
export const UpdateUser = base.route({
58+
method: 'PUT',
59+
operationId: 'updateUser',
60+
path: '/users/{userId}',
61+
summary: 'Update a user',
62+
tags: ['users']
63+
}).input(zUpdateUserData).output(zUpdateUserResponse);
64+
65+
export const usersContracts = {
66+
GetUsers,
67+
CreateUser,
68+
DeleteUser,
69+
GetUserById,
70+
UpdateUser
71+
};
72+
73+
/**
74+
* Get all posts
75+
*/
76+
export const GetPosts = base.route({
77+
method: 'GET',
78+
operationId: 'getPosts',
79+
path: '/posts',
80+
summary: 'Get all posts',
81+
tags: ['posts']
82+
}).input(zGetPostsData).output(zGetPostsResponse);
83+
84+
/**
85+
* Create a new post
86+
*/
87+
export const CreatePost = base.route({
88+
method: 'POST',
89+
operationId: 'createPost',
90+
path: '/posts',
91+
successStatus: 201,
92+
summary: 'Create a new post',
93+
tags: ['posts']
94+
}).input(zCreatePostData).output(zCreatePostResponse);
95+
96+
/**
97+
* Get a post by ID
98+
*/
99+
export const GetPostById = base.route({
100+
method: 'GET',
101+
operationId: 'getPostById',
102+
path: '/posts/{postId}',
103+
summary: 'Get a post by ID',
104+
tags: ['posts']
105+
}).input(zGetPostByIdData).output(zGetPostByIdResponse);
106+
107+
export const postsContracts = {
108+
GetPosts,
109+
CreatePost,
110+
GetPostById
111+
};
112+
113+
export const router = {
114+
getUsers: GetUsers,
115+
createUser: CreateUser,
116+
deleteUser: DeleteUser,
117+
getUserById: GetUserById,
118+
updateUser: UpdateUser,
119+
getPosts: GetPosts,
120+
createPost: CreatePost,
121+
getPostById: GetPostById
122+
};
123+
124+
export type Router = typeof router;
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import * as z from 'zod';
4+
5+
export const zUser = z.object({
6+
id: z.string(),
7+
email: z.email(),
8+
name: z.string(),
9+
createdAt: z.iso.datetime().optional()
10+
});
11+
12+
export const zCreateUserInput = z.object({
13+
email: z.email(),
14+
name: z.string(),
15+
password: z.string().min(8).optional()
16+
});
17+
18+
export const zUpdateUserInput = z.object({
19+
email: z.email().optional(),
20+
name: z.string().optional()
21+
});
22+
23+
export const zPost = z.object({
24+
id: z.string(),
25+
title: z.string(),
26+
content: z.string(),
27+
authorId: z.string(),
28+
status: z.enum([
29+
'draft',
30+
'published',
31+
'archived'
32+
]).optional(),
33+
createdAt: z.iso.datetime().optional()
34+
});
35+
36+
export const zCreatePostInput = z.object({
37+
title: z.string(),
38+
content: z.string(),
39+
status: z.enum(['draft', 'published']).optional()
40+
});
41+
42+
export const zGetUsersData = z.object({
43+
body: z.never().optional(),
44+
path: z.never().optional(),
45+
query: z.object({
46+
limit: z.int().optional().default(10),
47+
offset: z.int().optional().default(0)
48+
}).optional()
49+
});
50+
51+
/**
52+
* List of users
53+
*/
54+
export const zGetUsersResponse = z.array(zUser);
55+
56+
export const zCreateUserData = z.object({
57+
body: zCreateUserInput,
58+
path: z.never().optional(),
59+
query: z.never().optional()
60+
});
61+
62+
/**
63+
* User created
64+
*/
65+
export const zCreateUserResponse = zUser;
66+
67+
export const zDeleteUserData = z.object({
68+
body: z.never().optional(),
69+
path: z.object({
70+
userId: z.string()
71+
}),
72+
query: z.never().optional(),
73+
headers: z.object({
74+
'X-Request-Id': z.string().optional()
75+
}).optional()
76+
});
77+
78+
/**
79+
* User deleted
80+
*/
81+
export const zDeleteUserResponse = z.void();
82+
83+
export const zGetUserByIdData = z.object({
84+
body: z.never().optional(),
85+
path: z.object({
86+
userId: z.string()
87+
}),
88+
query: z.never().optional()
89+
});
90+
91+
/**
92+
* User found
93+
*/
94+
export const zGetUserByIdResponse = zUser;
95+
96+
export const zUpdateUserData = z.object({
97+
body: zUpdateUserInput,
98+
path: z.object({
99+
userId: z.string()
100+
}),
101+
query: z.never().optional()
102+
});
103+
104+
/**
105+
* User updated
106+
*/
107+
export const zUpdateUserResponse = zUser;
108+
109+
export const zGetPostsData = z.object({
110+
body: z.never().optional(),
111+
path: z.never().optional(),
112+
query: z.object({
113+
authorId: z.string().optional(),
114+
status: z.enum([
115+
'draft',
116+
'published',
117+
'archived'
118+
]).optional()
119+
}).optional()
120+
});
121+
122+
/**
123+
* List of posts
124+
*/
125+
export const zGetPostsResponse = z.array(zPost);
126+
127+
export const zCreatePostData = z.object({
128+
body: zCreatePostInput,
129+
path: z.never().optional(),
130+
query: z.never().optional(),
131+
headers: z.object({
132+
'X-Author-Id': z.string()
133+
})
134+
});
135+
136+
/**
137+
* Post created
138+
*/
139+
export const zCreatePostResponse = zPost;
140+
141+
export const zGetPostByIdData = z.object({
142+
body: z.never().optional(),
143+
path: z.object({
144+
postId: z.string()
145+
}),
146+
query: z.object({
147+
includeComments: z.boolean().optional().default(false)
148+
}).optional()
149+
});
150+
151+
/**
152+
* Post found
153+
*/
154+
export const zGetPostByIdResponse = zPost;

0 commit comments

Comments
 (0)