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.
@@ -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, route } from 'rouzer'
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 profileRoute = route('profiles/:id', {
13
- GET: {
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
- PATCH: {
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 = { profileRoute }
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 profiles = new Map([['42', { id: '42', name: 'Ada' }]])
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
- profileRoute: {
67
- GET(ctx) {
68
- const profile = profiles.get(ctx.path.id)
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
- PATCH(ctx) {
79
- const current = profiles.get(ctx.path.id)
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
- profiles.set(ctx.path.id, profile)
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.profileRoute.GET({
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.profileRoute.PATCH({
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": "2.0.1",
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.3",
18
- "@typescript/native-preview": "7.0.0-dev.20251208.1",
19
- "prettier": "^3.7.4",
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": "^5.9.3",
23
- "vite": "^7.3.0",
24
- "vitest": "^4.0.16",
25
- "zod": "^4.1.13"
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.15.3",
30
- "alien-middleware": "^0.11.4"
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",