mimiMonads / vixeny

💜 Vixeny: At the forefront of modern web development, runtime-independent, efficiency-driven library dedicated to upholding the principles of FP; Desgined for creating scalable, maintainable, and high-performance web applications.
https://vixeny.dev/
146 stars 6 forks source link

Plugin API re-design #32

Open aquapi opened 1 month ago

aquapi commented 1 month ago

As Vix uses dynamic code generation for optimizing request handling, it would be great to fully leverage that with an API that allows developers to directly inject code into the control flow.

This can be used to optimize things such as request validation since it can inline code directly into the handler.

mimiMonads commented 3 weeks ago

@emastho

Let's start with this, I think that one of the biggest problems with plugging is the way that we have to unwrap the plugin:

const hello  = plugin.type({
  name: Symbol.for("Unique Identifier"),
  type: "string",
  f: () => () => () => "hello world",
})

const serve = wrap({
  cyclePlugin:{
    hello
  }
})()
  .get({
    path: "/",
    f: ctx => ctx.hello
  })

// Code below will be replaced by `.serve()`
// On the next update 
  .testRequests()

await serve(
  new Request('http://localhost/')
).then(r => r.text())
  .then( console.log)

Where f is curried and that could be bothersome for some programmers