0.0.14 • Published 10 months ago

reusableflows v0.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Reusable Flows

Reusable flows is a small package that helps you organize your code using Tanstack Query, it's used for declaring TS inputs and outputs, the objective is to type whatever your api is calling for (Thus aimed to non ts backends)

It's influenced by TRPC so the usage is similar

Just a drop in and use, but you have to configure tanstack working. Zod library is used for schema validations.

//First declare an object containing procedures
 const tickets = {
  closeTicket: Flow.procedure
    .input(
      z.object({
        id: z.string(),
      })
  )
    .output(z.object({ id: z.string() }))
    .mutation(async ({ input, ctx}) => {
      const { data } = await LocalRequestHelper({
        url: URLHelper("rrhh.tickets/closeTicket"),
        requestType: "post",
        data: input,
      })
      return data as z.infer<typeof ctx.schemeOutput>
    }, `cerrarTicket-tickets`),
}
//Then add it as a route which is an object with more objects
const routes = {
  other,
  tickets,
}
//And then build the api with apiBuilder
export const api = apiBuilder(routes)

That's all, others should be able to use your defined routes, with your specific inputs and outputs fully typed!

const closeTicket = api.tickets.closeTicket.useMutation({
    onSuccess: () => {
      //something
    },
  })

If you encounter problems about No QueryClient set, use QueryClientProvider to set one you must use the exported QueryClient and QueryProvider from the library.

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago