rouzer 2.0.1 → 3.0.0
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 +33 -34
- package/dist/client/index.d.ts +29 -28
- package/dist/client/index.js +34 -16
- package/dist/http.d.ts +67 -0
- package/dist/http.js +44 -0
- package/dist/route.d.ts +19 -12
- package/dist/route.js +13 -8
- package/dist/server/router.d.ts +7 -3
- package/dist/server/router.js +35 -33
- package/dist/server/types.d.ts +25 -29
- package/dist/types.d.ts +26 -15
- package/docs/context.md +214 -42
- package/examples/basic-usage.ts +17 -16
- package/package.json +14 -10
package/examples/basic-usage.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HattipHandler } from '@hattip/core'
|
|
2
2
|
import * as z from 'zod'
|
|
3
|
-
import { $type, chain, createClient, createRouter
|
|
3
|
+
import { $type, chain, createClient, createRouter } from 'rouzer'
|
|
4
|
+
import * as http from 'rouzer/http'
|
|
4
5
|
|
|
5
6
|
type Profile = {
|
|
6
7
|
id: string
|
|
@@ -9,14 +10,14 @@ type Profile = {
|
|
|
9
10
|
requestId: string
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
13
|
+
export const profiles = http.resource('profiles/:id', {
|
|
14
|
+
get: http.get({
|
|
14
15
|
query: z.object({
|
|
15
16
|
includePosts: z.optional(z.boolean()),
|
|
16
17
|
}),
|
|
17
18
|
response: $type<Profile>(),
|
|
18
|
-
},
|
|
19
|
-
|
|
19
|
+
}),
|
|
20
|
+
update: http.patch({
|
|
20
21
|
body: z.object({
|
|
21
22
|
name: z.string().check(z.minLength(1)),
|
|
22
23
|
}),
|
|
@@ -24,10 +25,10 @@ export const profileRoute = route('profiles/:id', {
|
|
|
24
25
|
'content-type': z.literal('application/json'),
|
|
25
26
|
}),
|
|
26
27
|
response: $type<Profile>(),
|
|
27
|
-
},
|
|
28
|
+
}),
|
|
28
29
|
})
|
|
29
30
|
|
|
30
|
-
export const routes = {
|
|
31
|
+
export const routes = { profiles }
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* Tiny Hattip adapter used only to keep this example self-contained. Real apps
|
|
@@ -54,7 +55,7 @@ function createLocalFetch(handler: HattipHandler): typeof fetch {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export async function runBasicUsageExample() {
|
|
57
|
-
const
|
|
58
|
+
const profileMap = new Map([['42', { id: '42', name: 'Ada' }]])
|
|
58
59
|
|
|
59
60
|
const requestMiddleware = chain().use(ctx => ({
|
|
60
61
|
requestId: ctx.request.headers.get('x-request-id') ?? 'local',
|
|
@@ -63,9 +64,9 @@ export async function runBasicUsageExample() {
|
|
|
63
64
|
const handler = createRouter({ basePath: 'api/' })
|
|
64
65
|
.use(requestMiddleware)
|
|
65
66
|
.use(routes, {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const profile =
|
|
67
|
+
profiles: {
|
|
68
|
+
get(ctx) {
|
|
69
|
+
const profile = profileMap.get(ctx.path.id)
|
|
69
70
|
if (!profile) {
|
|
70
71
|
return new Response('Profile not found', { status: 404 })
|
|
71
72
|
}
|
|
@@ -75,13 +76,13 @@ export async function runBasicUsageExample() {
|
|
|
75
76
|
requestId: ctx.requestId,
|
|
76
77
|
}
|
|
77
78
|
},
|
|
78
|
-
|
|
79
|
-
const current =
|
|
79
|
+
update(ctx) {
|
|
80
|
+
const current = profileMap.get(ctx.path.id)
|
|
80
81
|
if (!current) {
|
|
81
82
|
return new Response('Profile not found', { status: 404 })
|
|
82
83
|
}
|
|
83
84
|
const profile = { ...current, name: ctx.body.name }
|
|
84
|
-
|
|
85
|
+
profileMap.set(ctx.path.id, profile)
|
|
85
86
|
return {
|
|
86
87
|
...profile,
|
|
87
88
|
includePosts: false,
|
|
@@ -100,13 +101,13 @@ export async function runBasicUsageExample() {
|
|
|
100
101
|
fetch: createLocalFetch(handler),
|
|
101
102
|
})
|
|
102
103
|
|
|
103
|
-
const fetched = await client.
|
|
104
|
+
const fetched = await client.profiles.get({
|
|
104
105
|
path: { id: '42' },
|
|
105
106
|
query: { includePosts: false },
|
|
106
107
|
headers: { 'x-request-id': 'docs' },
|
|
107
108
|
})
|
|
108
109
|
|
|
109
|
-
const updated = await client.
|
|
110
|
+
const updated = await client.profiles.update({
|
|
110
111
|
path: { id: '42' },
|
|
111
112
|
body: { name: 'Grace' },
|
|
112
113
|
})
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rouzer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./http": {
|
|
11
|
+
"types": "./dist/http.d.ts",
|
|
12
|
+
"import": "./dist/http.js"
|
|
9
13
|
}
|
|
10
14
|
},
|
|
11
15
|
"peerDependencies": {
|
|
@@ -14,20 +18,20 @@
|
|
|
14
18
|
"devDependencies": {
|
|
15
19
|
"@alloc/prettier-config": "^1.0.0",
|
|
16
20
|
"@hattip/adapter-test": "^0.0.49",
|
|
17
|
-
"@types/node": "^25.0
|
|
18
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
19
|
-
"prettier": "^3.
|
|
21
|
+
"@types/node": "^25.8.0",
|
|
22
|
+
"@typescript/native-preview": "7.0.0-dev.20260515.1",
|
|
23
|
+
"prettier": "^3.8.3",
|
|
20
24
|
"rouzer": "link:.",
|
|
21
25
|
"tsc-lint": "^0.1.9",
|
|
22
|
-
"typescript": "^
|
|
23
|
-
"vite": "^
|
|
24
|
-
"vitest": "^4.
|
|
25
|
-
"zod": "^4.
|
|
26
|
+
"typescript": "^6.0.3",
|
|
27
|
+
"vite": "^8.0.13",
|
|
28
|
+
"vitest": "^4.1.6",
|
|
29
|
+
"zod": "^4.4.3"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
32
|
"@hattip/core": "^0.0.49",
|
|
29
|
-
"@remix-run/route-pattern": "^0.
|
|
30
|
-
"alien-middleware": "^0.11.
|
|
33
|
+
"@remix-run/route-pattern": "^0.21.1",
|
|
34
|
+
"alien-middleware": "^0.11.6"
|
|
31
35
|
},
|
|
32
36
|
"prettier": "@alloc/prettier-config",
|
|
33
37
|
"license": "MIT",
|