@sugardarius/anzen 1.0.0 → 1.0.1
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/README.md +37 -2
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -45,12 +45,13 @@ The example above shows how to use the factory to authorize your requests.
|
|
|
45
45
|
|
|
46
46
|
## Framework validation agnostic
|
|
47
47
|
|
|
48
|
-
By design the factory is framework validation agnostic 🌟. When doing your validations you can use whatever you want as framework validation as long as it implements the [Standard Schema](https://github.com/standard-schema/standard-schema) common interface. You can use your favorite validation library like [Zod](https://zod.dev/) or [decoders](https://decoders.cc/).
|
|
48
|
+
By design the factory is framework validation agnostic 🌟. When doing your validations you can use whatever you want as framework validation as long as it implements the [Standard Schema](https://github.com/standard-schema/standard-schema) common interface. You can use your favorite validation library like [Zod](https://zod.dev/), [Validbot](https://valibot.dev/) or [decoders](https://decoders.cc/).
|
|
49
49
|
|
|
50
50
|
```tsx
|
|
51
51
|
// (POST) /app/api/races/[id]/route.ts
|
|
52
52
|
import { z } from 'zod'
|
|
53
53
|
import { object, string, number } from 'decoders'
|
|
54
|
+
import { createSafeRouteHandler } from '@sugardarius/anzen'
|
|
54
55
|
|
|
55
56
|
export const POST = createSafeRouteHandler(
|
|
56
57
|
{
|
|
@@ -78,6 +79,40 @@ If you define an async validation then the route handler will throw an error.
|
|
|
78
79
|
|
|
79
80
|
Check the API and the available options to configure the factory as you wish.
|
|
80
81
|
|
|
82
|
+
### Function signature
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import {
|
|
86
|
+
type CreateSafeRouteHandlerOptions,
|
|
87
|
+
type SafeRouteHandlerContext,
|
|
88
|
+
createSafeRouteHandler
|
|
89
|
+
} from '@sugardarius/anzen'
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns a Next.js API route handler function.
|
|
93
|
+
*/
|
|
94
|
+
export const VERB = createSafeRouteHandler(
|
|
95
|
+
/**
|
|
96
|
+
* Options to configure the route handler
|
|
97
|
+
*/
|
|
98
|
+
options: CreateSafeRouteHandlerOptions,
|
|
99
|
+
/**
|
|
100
|
+
* The route handler function.
|
|
101
|
+
*/
|
|
102
|
+
async (
|
|
103
|
+
/**
|
|
104
|
+
* Context object providing:
|
|
105
|
+
* auth context
|
|
106
|
+
* validated segments, search params, body and form data
|
|
107
|
+
*/
|
|
108
|
+
ctx: SafeRouteHandlerContext,
|
|
109
|
+
/**
|
|
110
|
+
* Original request
|
|
111
|
+
*/
|
|
112
|
+
req: Request
|
|
113
|
+
): Promise<Response> => Response.json({}))
|
|
114
|
+
```
|
|
115
|
+
|
|
81
116
|
### Base options
|
|
82
117
|
|
|
83
118
|
When creating a safe route handler you can use a bunch of options for helping you achieve different tasks 👇🏻
|
|
@@ -102,7 +137,7 @@ export const POST = createSafeRouteHandler(
|
|
|
102
137
|
|
|
103
138
|
Function to use to authorize the request. By default it always authorize the request.
|
|
104
139
|
|
|
105
|
-
|
|
140
|
+
Returns a response when the request is not authorized.
|
|
106
141
|
|
|
107
142
|
```tsx
|
|
108
143
|
import { createSafeRouteHandler } from '@sugardarius/anzen'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sugardarius/anzen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A fast, framework validation agnostic, type-safe factory for creating Next.JS App Router route handlers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"packageManager": "npm@11.3.0",
|
|
@@ -67,18 +67,21 @@
|
|
|
67
67
|
"typescript": "^5"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@arethetypeswrong/cli": "^0.18.
|
|
71
|
-
"@eslint/js": "^9.
|
|
70
|
+
"@arethetypeswrong/cli": "^0.18.1",
|
|
71
|
+
"@eslint/js": "^9.27.0",
|
|
72
72
|
"@release-it/keep-a-changelog": "^7.0.0",
|
|
73
|
-
"@types/node": "^22.15.
|
|
74
|
-
"
|
|
73
|
+
"@types/node": "^22.15.19",
|
|
74
|
+
"@types/react": "^19.1.4",
|
|
75
|
+
"@types/react-dom": "^19.1.5",
|
|
76
|
+
"eslint": "^9.27.0",
|
|
75
77
|
"prettier": "^3.5.3",
|
|
76
78
|
"publint": "^0.3.12",
|
|
77
79
|
"release-it": "^19.0.2",
|
|
78
|
-
"tsup": "^8.
|
|
80
|
+
"tsup": "^8.5.0",
|
|
79
81
|
"turbo": "^2.5.3",
|
|
80
82
|
"typescript": "^5.8.3",
|
|
81
|
-
"typescript-eslint": "^8.32.
|
|
82
|
-
"vitest": "^3.1.
|
|
83
|
+
"typescript-eslint": "^8.32.1",
|
|
84
|
+
"vitest": "^3.1.4",
|
|
85
|
+
"zod": "^3.25.7"
|
|
83
86
|
}
|
|
84
87
|
}
|