What's Changed
There are 3 changes that may affect your DX in this release:
[BREAKING]: Now we follow the Standard Schema Spec:
Which means that you can use make-service
not only with Zod, but with all the other parsers that follow the standard schema spec.
This change is breaking because it requires [email protected]+
and there are some zod apis, such as .transform
that sometimes don't work well with the new spec.
ParseResponseError
constructor
From now on, whenever the response json or text doesn't match your provided schema, make-service will throw a ParseResponseError
which is a kind of error that carries the issues and so you can better inspect them:
try {
const response = await service.get("/users")
return await response.json(userSchema)
} catch(error) {
if (error instanceof ParseResponseError) {
console.log(error.issues)
}
}
Accept number
as param values:
This is a little improvement for the replaceURLParams
method and all its dependents. Now you don't need to wrap your numbers in a String
constructor:
// Before
const url = service.get('/users/:id', { params: { id: String(1) } })
// GET: https://myservice.com/users/1
// After
const url = service.get('/users/:id', { params: { id: 1 } })
// GET: https://myservice.com/users/1
I hope y'all enjoy the changes!
Pull requests
- Little refactoring on mergeHeaders aiming simplicity by @gustavoguichard in #55
- Use pnpm instead of npm by @gustavoguichard in #56
- Replace request transformer example with the global timeout recipe by @diogob in #52
- Accept standard-schema parsers instead of only zod by @gustavoguichard in #57
- Improve parsing errors by @gustavoguichard in #58
- Accept numbers as params by @gustavoguichard in #59
Full Changelog: v3.1.0...v4.0.0