Skip to content

v4.0.0 - Standard Schema 📗

Latest
Compare
Choose a tag to compare
@gustavoguichard gustavoguichard released this 07 Feb 13:47
6d29cf2

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

Full Changelog: v3.1.0...v4.0.0