Skip to content

Commit ee6835d

Browse files
committed
chore: add contracts type
1 parent 014e038 commit ee6835d

15 files changed

Lines changed: 287 additions & 163 deletions

File tree

dev/typescript/presets.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const presets = {
3333
rpc: () => [
3434
/** RPC-style SDK with Zod validation */
3535
{
36+
contracts: {
37+
containerName: 'contract',
38+
},
3639
name: '@orpc/contract',
3740
},
3841
'zod',

packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/custom-router-name/@orpc/contract.gen.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const base = oc.$route({ inputStructure: 'detailed' });
99
/**
1010
* Get all users
1111
*/
12-
export const getUsersContract = base.route({
12+
export const getUsers = base.route({
1313
method: 'GET',
1414
operationId: 'getUsers',
1515
path: '/users',
@@ -20,7 +20,7 @@ export const getUsersContract = base.route({
2020
/**
2121
* Create a new user
2222
*/
23-
export const createUserContract = base.route({
23+
export const createUser = base.route({
2424
method: 'POST',
2525
operationId: 'createUser',
2626
path: '/users',
@@ -32,7 +32,7 @@ export const createUserContract = base.route({
3232
/**
3333
* Delete a user
3434
*/
35-
export const deleteUserContract = base.route({
35+
export const deleteUser = base.route({
3636
method: 'DELETE',
3737
operationId: 'deleteUser',
3838
path: '/users/{userId}',
@@ -43,7 +43,7 @@ export const deleteUserContract = base.route({
4343
/**
4444
* Get a user by ID
4545
*/
46-
export const getUserByIdContract = base.route({
46+
export const getUserById = base.route({
4747
method: 'GET',
4848
operationId: 'getUserById',
4949
path: '/users/{userId}',
@@ -54,7 +54,7 @@ export const getUserByIdContract = base.route({
5454
/**
5555
* Update a user
5656
*/
57-
export const updateUserContract = base.route({
57+
export const updateUser = base.route({
5858
method: 'PUT',
5959
operationId: 'updateUser',
6060
path: '/users/{userId}',
@@ -65,7 +65,7 @@ export const updateUserContract = base.route({
6565
/**
6666
* Get all posts
6767
*/
68-
export const getPostsContract = base.route({
68+
export const getPosts = base.route({
6969
method: 'GET',
7070
operationId: 'getPosts',
7171
path: '/posts',
@@ -76,7 +76,7 @@ export const getPostsContract = base.route({
7676
/**
7777
* Create a new post
7878
*/
79-
export const createPostContract = base.route({
79+
export const createPost = base.route({
8080
method: 'POST',
8181
operationId: 'createPost',
8282
path: '/posts',
@@ -88,7 +88,7 @@ export const createPostContract = base.route({
8888
/**
8989
* Get a post by ID
9090
*/
91-
export const getPostByIdContract = base.route({
91+
export const getPostById = base.route({
9292
method: 'GET',
9393
operationId: 'getPostById',
9494
path: '/posts/{postId}',
@@ -97,14 +97,14 @@ export const getPostByIdContract = base.route({
9797
}).input(zGetPostByIdData).output(zGetPostByIdResponse);
9898

9999
export const contract = {
100-
getUsers: getUsersContract,
101-
createUser: createUserContract,
102-
deleteUser: deleteUserContract,
103-
getUserById: getUserByIdContract,
104-
updateUser: updateUserContract,
105-
getPosts: getPostsContract,
106-
createPost: createPostContract,
107-
getPostById: getPostByIdContract
100+
getUsers,
101+
createUser,
102+
deleteUser,
103+
getUserById,
104+
updateUser,
105+
getPosts,
106+
createPost,
107+
getPostById
108108
};
109109

110110
export type Contract = typeof contract;

packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.0.x/default/@orpc/contract.gen.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const base = oc.$route({ inputStructure: 'detailed' });
99
/**
1010
* Get all users
1111
*/
12-
export const getUsersContract = base.route({
12+
export const getUsers = base.route({
1313
method: 'GET',
1414
operationId: 'getUsers',
1515
path: '/users',
@@ -20,7 +20,7 @@ export const getUsersContract = base.route({
2020
/**
2121
* Create a new user
2222
*/
23-
export const createUserContract = base.route({
23+
export const createUser = base.route({
2424
method: 'POST',
2525
operationId: 'createUser',
2626
path: '/users',
@@ -32,7 +32,7 @@ export const createUserContract = base.route({
3232
/**
3333
* Delete a user
3434
*/
35-
export const deleteUserContract = base.route({
35+
export const deleteUser = base.route({
3636
method: 'DELETE',
3737
operationId: 'deleteUser',
3838
path: '/users/{userId}',
@@ -43,7 +43,7 @@ export const deleteUserContract = base.route({
4343
/**
4444
* Get a user by ID
4545
*/
46-
export const getUserByIdContract = base.route({
46+
export const getUserById = base.route({
4747
method: 'GET',
4848
operationId: 'getUserById',
4949
path: '/users/{userId}',
@@ -54,7 +54,7 @@ export const getUserByIdContract = base.route({
5454
/**
5555
* Update a user
5656
*/
57-
export const updateUserContract = base.route({
57+
export const updateUser = base.route({
5858
method: 'PUT',
5959
operationId: 'updateUser',
6060
path: '/users/{userId}',
@@ -65,7 +65,7 @@ export const updateUserContract = base.route({
6565
/**
6666
* Get all posts
6767
*/
68-
export const getPostsContract = base.route({
68+
export const getPosts = base.route({
6969
method: 'GET',
7070
operationId: 'getPosts',
7171
path: '/posts',
@@ -76,7 +76,7 @@ export const getPostsContract = base.route({
7676
/**
7777
* Create a new post
7878
*/
79-
export const createPostContract = base.route({
79+
export const createPost = base.route({
8080
method: 'POST',
8181
operationId: 'createPost',
8282
path: '/posts',
@@ -88,7 +88,7 @@ export const createPostContract = base.route({
8888
/**
8989
* Get a post by ID
9090
*/
91-
export const getPostByIdContract = base.route({
91+
export const getPostById = base.route({
9292
method: 'GET',
9393
operationId: 'getPostById',
9494
path: '/posts/{postId}',
@@ -97,14 +97,14 @@ export const getPostByIdContract = base.route({
9797
}).input(zGetPostByIdData).output(zGetPostByIdResponse);
9898

9999
export const router = {
100-
getUsers: getUsersContract,
101-
createUser: createUserContract,
102-
deleteUser: deleteUserContract,
103-
getUserById: getUserByIdContract,
104-
updateUser: updateUserContract,
105-
getPosts: getPostsContract,
106-
createPost: createPostContract,
107-
getPostById: getPostByIdContract
100+
getUsers,
101+
createUser,
102+
deleteUser,
103+
getUserById,
104+
updateUser,
105+
getPosts,
106+
createPost,
107+
getPostById
108108
};
109109

110110
export type Router = typeof router;

packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/custom-router-name/@orpc/contract.gen.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const base = oc.$route({ inputStructure: 'detailed' });
99
/**
1010
* Get all users
1111
*/
12-
export const getUsersContract = base.route({
12+
export const getUsers = base.route({
1313
method: 'GET',
1414
operationId: 'getUsers',
1515
path: '/users',
@@ -20,7 +20,7 @@ export const getUsersContract = base.route({
2020
/**
2121
* Create a new user
2222
*/
23-
export const createUserContract = base.route({
23+
export const createUser = base.route({
2424
method: 'POST',
2525
operationId: 'createUser',
2626
path: '/users',
@@ -32,7 +32,7 @@ export const createUserContract = base.route({
3232
/**
3333
* Delete a user
3434
*/
35-
export const deleteUserContract = base.route({
35+
export const deleteUser = base.route({
3636
method: 'DELETE',
3737
operationId: 'deleteUser',
3838
path: '/users/{userId}',
@@ -43,7 +43,7 @@ export const deleteUserContract = base.route({
4343
/**
4444
* Get a user by ID
4545
*/
46-
export const getUserByIdContract = base.route({
46+
export const getUserById = base.route({
4747
method: 'GET',
4848
operationId: 'getUserById',
4949
path: '/users/{userId}',
@@ -54,7 +54,7 @@ export const getUserByIdContract = base.route({
5454
/**
5555
* Update a user
5656
*/
57-
export const updateUserContract = base.route({
57+
export const updateUser = base.route({
5858
method: 'PUT',
5959
operationId: 'updateUser',
6060
path: '/users/{userId}',
@@ -65,7 +65,7 @@ export const updateUserContract = base.route({
6565
/**
6666
* Get all posts
6767
*/
68-
export const getPostsContract = base.route({
68+
export const getPosts = base.route({
6969
method: 'GET',
7070
operationId: 'getPosts',
7171
path: '/posts',
@@ -76,7 +76,7 @@ export const getPostsContract = base.route({
7676
/**
7777
* Create a new post
7878
*/
79-
export const createPostContract = base.route({
79+
export const createPost = base.route({
8080
method: 'POST',
8181
operationId: 'createPost',
8282
path: '/posts',
@@ -88,7 +88,7 @@ export const createPostContract = base.route({
8888
/**
8989
* Get a post by ID
9090
*/
91-
export const getPostByIdContract = base.route({
91+
export const getPostById = base.route({
9292
method: 'GET',
9393
operationId: 'getPostById',
9494
path: '/posts/{postId}',
@@ -97,14 +97,14 @@ export const getPostByIdContract = base.route({
9797
}).input(zGetPostByIdData).output(zGetPostByIdResponse);
9898

9999
export const contract = {
100-
getUsers: getUsersContract,
101-
createUser: createUserContract,
102-
deleteUser: deleteUserContract,
103-
getUserById: getUserByIdContract,
104-
updateUser: updateUserContract,
105-
getPosts: getPostsContract,
106-
createPost: createPostContract,
107-
getPostById: getPostByIdContract
100+
getUsers,
101+
createUser,
102+
deleteUser,
103+
getUserById,
104+
updateUser,
105+
getPosts,
106+
createPost,
107+
getPostById
108108
};
109109

110110
export type Contract = typeof contract;

packages/openapi-ts-tests/@orpc/contract/v1/__snapshots__/3.1.x/default/@orpc/contract.gen.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const base = oc.$route({ inputStructure: 'detailed' });
99
/**
1010
* Get all users
1111
*/
12-
export const getUsersContract = base.route({
12+
export const getUsers = base.route({
1313
method: 'GET',
1414
operationId: 'getUsers',
1515
path: '/users',
@@ -20,7 +20,7 @@ export const getUsersContract = base.route({
2020
/**
2121
* Create a new user
2222
*/
23-
export const createUserContract = base.route({
23+
export const createUser = base.route({
2424
method: 'POST',
2525
operationId: 'createUser',
2626
path: '/users',
@@ -32,7 +32,7 @@ export const createUserContract = base.route({
3232
/**
3333
* Delete a user
3434
*/
35-
export const deleteUserContract = base.route({
35+
export const deleteUser = base.route({
3636
method: 'DELETE',
3737
operationId: 'deleteUser',
3838
path: '/users/{userId}',
@@ -43,7 +43,7 @@ export const deleteUserContract = base.route({
4343
/**
4444
* Get a user by ID
4545
*/
46-
export const getUserByIdContract = base.route({
46+
export const getUserById = base.route({
4747
method: 'GET',
4848
operationId: 'getUserById',
4949
path: '/users/{userId}',
@@ -54,7 +54,7 @@ export const getUserByIdContract = base.route({
5454
/**
5555
* Update a user
5656
*/
57-
export const updateUserContract = base.route({
57+
export const updateUser = base.route({
5858
method: 'PUT',
5959
operationId: 'updateUser',
6060
path: '/users/{userId}',
@@ -65,7 +65,7 @@ export const updateUserContract = base.route({
6565
/**
6666
* Get all posts
6767
*/
68-
export const getPostsContract = base.route({
68+
export const getPosts = base.route({
6969
method: 'GET',
7070
operationId: 'getPosts',
7171
path: '/posts',
@@ -76,7 +76,7 @@ export const getPostsContract = base.route({
7676
/**
7777
* Create a new post
7878
*/
79-
export const createPostContract = base.route({
79+
export const createPost = base.route({
8080
method: 'POST',
8181
operationId: 'createPost',
8282
path: '/posts',
@@ -88,7 +88,7 @@ export const createPostContract = base.route({
8888
/**
8989
* Get a post by ID
9090
*/
91-
export const getPostByIdContract = base.route({
91+
export const getPostById = base.route({
9292
method: 'GET',
9393
operationId: 'getPostById',
9494
path: '/posts/{postId}',
@@ -97,14 +97,14 @@ export const getPostByIdContract = base.route({
9797
}).input(zGetPostByIdData).output(zGetPostByIdResponse);
9898

9999
export const router = {
100-
getUsers: getUsersContract,
101-
createUser: createUserContract,
102-
deleteUser: deleteUserContract,
103-
getUserById: getUserByIdContract,
104-
updateUser: updateUserContract,
105-
getPosts: getPostsContract,
106-
createPost: createPostContract,
107-
getPostById: getPostByIdContract
100+
getUsers,
101+
createUser,
102+
deleteUser,
103+
getUserById,
104+
updateUser,
105+
getPosts,
106+
createPost,
107+
getPostById
108108
};
109109

110110
export type Router = typeof router;

0 commit comments

Comments
 (0)