Query

This is the standard method to retrieve query parameters from a request.

Optimization

In the Vixeny framework, there’s a component called the checker, which actively tries to optimize your functions.

Default Behavior

In this example, it understands that we are only using id.

import { wrap } from "vixeny";

const handler = wrap()()
  .stdPetition({
    path: "/",
    f: ({ query }) => query.id ?? "not found",
  })
  // `debugLast` shows all components used in the last request
  // query: [id?]
  .debugLast()
  .testRequests();

await handler(new Request("http://localhost/?id=123"))
  .then((x) => x.text())
  // Logging : 123
  .then(console.log);

There are cases where the checker will not be able to infer the elements used, which will trigger a default case. You can check this at any time using debugLast.

import { wrap } from "vixeny";

const handler = wrap()()
  .stdPetition({
    path: "/",
    f: ({ query }) => JSON.stringify(query) ?? "not found",
  })
  // `debugLast` shows all components used in the last request
  // query: Record<string, string|null> | null
  .debugLast()
  .testRequests();

await handler(new Request("http://localhost/?id=123&user=Avant"))
  .then((x) => x.text())
  // Logging : {"id":"123","user":"Avant"}
  .then(console.log);

Only

The only option restricts query parameters to only accept the parameters specified in it.

import { wrap } from "vixeny";

const handler = wrap()()
  .stdPetition({
    path: "/",
    query: {
      // Locking this path to use only the specified parameters
      only: ["id"],
    },
    f: ({ query }) => JSON.stringify(query) ?? "not found",
  })
  // `debugLast` shows all components used in the last request
  // query: [id?]
  .debugLast()
  .testRequests();

await handler(new Request("http://localhost/?id=123&user=Avant"))
  .then((x) => x.text())
  // Logging : {"id":"123"}
  .then(console.log);

Here’s a more naturally phrased version of your documentation:

Unique

This option simplifies handling by replacing the query object with the value of the specified name key, if present. This is a targeted optimization to streamline access to important parameters.

import { wrap } from "vixeny";

const handler = wrap()()
  .stdPetition({
    path: "/",
    query: {
      // Enabling unique
      unique: true,
      // Key to target
      name: "user",
    },
    // Directly returning the value of the specified query parameter
    f: ({ query }) => query ?? "not found",
  })
  // `debugLast` visualizes which components were utilized in the last request
  // query: [user?]
  .debugLast()
  .testRequests();

await handler(new Request("http://localhost/?id=123&user=Avant"))
  .then((x) => x.text())
  // Outputs the value of 'user', i.e., 'Avant'
  .then(console.log);

List

Crypto

If crypto with at least a globalKey is present.