Skip to content

Commit 376bffe

Browse files
authored
Merge pull request #18 from rhyek/use-nestjs-zod-fork
use nestjs zod fork
2 parents 93b30e0 + eee3e2b commit 376bffe

File tree

5 files changed

+116
-185
lines changed

5 files changed

+116
-185
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 1.3.1 (2025-05-26)
4+
5+
### Bugfixes
6+
7+
- Support OPTIONS HTTP method
8+
- Use my fork of @nestjs/zod until this is merged: https://github.com/BenLorantfy/nestjs-zod/pull/151
9+
310
## 1.3.0 (2025-04-12)
411

512
### Features

README.md

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,72 @@ const { data: greeting, error, status } = useHelloWorld();
5252
npm install nestjs-endpoints @nestjs/swagger zod
5353
```
5454

55-
## Usage
55+
## Setup
5656

5757
You can opt for either an automatic setup with endpoint scanning + file-based routing or a traditional one with manual imports and HTTP paths. You can also mix both in a single project.
5858

5959
### Option 1. Automatic setup
6060

61+
This is the preferred way of setting up nestjs-endpoints using file-based routing.
62+
63+
`src/app.module.ts`
64+
65+
```typescript
66+
import { EndpointsRouterModule } from 'nestjs-endpoints';
67+
68+
@Module({
69+
imports: [
70+
EndpointsRouterModule.register({
71+
rootDirectory: './endpoints',
72+
}),
73+
],
74+
})
75+
export class AppModule {}
76+
```
77+
78+
`src/endpoints/status/health.ts`
79+
80+
```typescript
81+
import { endpoint } from 'nestjs-endpoints';
82+
83+
export default endpoint({
84+
handler: () => 'ok',
85+
});
86+
```
87+
88+
Endpoint available at `/status/health`.
89+
90+
### Option 2. Traditional imports and paths
91+
92+
You can import endpoints like regular NestJS controllers. No need for `EndpointsRouterModule` in this case.
93+
94+
`src/app.module.ts`
95+
96+
```typescript
97+
import { Module } from '@nestjs/common';
98+
import { healthCheck } from './health-check';
99+
100+
@Module({
101+
controllers: [healthCheck],
102+
})
103+
class AppModule {}
104+
```
105+
106+
`src/health-check.ts`
107+
108+
```typescript
109+
import { endpoint } from 'nestjs-endpoints';
110+
111+
export const healthCheck = endpoint({
112+
path: '/status/health',
113+
handler: () => 'ok',
114+
});
115+
```
116+
117+
Endpoint available at `/status/health`.
118+
119+
## Usage
120+
61121
`src/app.module.ts`
62122

63123
```typescript
@@ -181,33 +241,6 @@ Examples (assume `rootDirectory` is `./endpoints`):
181241

182242
> _**Note:**_ Bundled projects via Webpack or similar are not supported.
183243
184-
### Option 2. Traditional imports and paths
185-
186-
You can import endpoints like regular NestJS controllers. No need for `EndpointsRouterModule` in this case.
187-
188-
`src/app.module.ts`
189-
190-
```typescript
191-
import { Module } from '@nestjs/common';
192-
import { healthCheck } from './health-check';
193-
194-
@Module({
195-
controllers: [healthCheck],
196-
})
197-
class AppModule {}
198-
```
199-
200-
`src/health-check.ts`
201-
202-
```typescript
203-
import { endpoint } from 'nestjs-endpoints';
204-
205-
export const healthCheck = endpoint({
206-
path: '/status/health',
207-
handler: () => 'ok',
208-
});
209-
```
210-
211244
## Codegen (optional)
212245

213246
You can automatically generate a client SDK for your API that can be used in other backend or frontend projects with the benefit of end-to-end type safety. It uses [orval](https://orval.dev/) internally and works with both scanned and manually imported endpoints.

packages/nestjs-endpoints/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"dependencies": {
4646
"@orval/query": "~7.8.0",
4747
"callsites": "^3.1.0",
48-
"nestjs-zod": "^4.2.0",
48+
"nestjs-zod": "npm:@rhyek/[email protected].0",
4949
"orval": "~7.8.0"
5050
},
5151
"peerDependencies": {

packages/nestjs-endpoints/src/endpoint-fn.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Get,
77
Head,
88
Inject,
9+
Options,
910
Patch,
1011
Post,
1112
Put,
@@ -30,14 +31,22 @@ import {
3031
moduleAls,
3132
} from './helpers';
3233

33-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head';
34+
type HttpMethod =
35+
| 'get'
36+
| 'post'
37+
| 'put'
38+
| 'delete'
39+
| 'patch'
40+
| 'head'
41+
| 'options';
3442
const httpMethodDecorators = {
3543
get: Get,
3644
post: Post,
3745
put: Put,
3846
delete: Delete,
3947
patch: Patch,
4048
head: Head,
49+
options: Options,
4150
} satisfies Record<HttpMethod, () => MethodDecorator>;
4251

4352
// eslint-disable-next-line @typescript-eslint/no-unused-vars

0 commit comments

Comments
 (0)