import { type Ctx } from "https://deno.land/x/endofunctor@v0.0.945/components/http/src/framework/optimizer/types.ts";
Type Parameters
Properties
Adds with query to the context
{
path: "/path",
f: async ctx => await ctx.req.blob()
}
{
path: '/path',
options: {add: ["req"]},
f: ctx => outOfContext(ctx)
};
Gets the Queries from the URL, utilize the ctx.query
.
{
path: '/path',
f: ctx => ctx.query?.name
};
// If the `ctx` goes out of context
{
path: '/path',
options: {add: ["query"]},
f: ctx => outOfContext(ctx)
};
Gets the parameters from the URL
{
path: '/hello/:name',
f: ctx => ctx.param.name
};
// If the `ctx` goes out of context
{
path: '/hello/:name',
options: {add: ["param"]},
f: ctx => outOfContext(ctx)
};
Adds a Date.now() returning the number of milliseconds elapsed since the epoch.
{
path: "/path"
f: ctx => ctx.date > Date.now()
? "unreachable"
: "date is created before ctx is passed to f"
}
This behavior can be set for testing purpose
{
path: "/",
options:{
setDate: 1694246953189
},
f: ctx => ctx.date === 1694246953189
? "Date is bind to a state"
: "unreachable"
}
Resolve Behavior
In a petition
that includes a resolve
, every element within the resolve
object is initially unknown.
It must be explicitly set within the containing petition
to be recognized and processed.
// Example
{
path: "/sample",
resolve: { name: "nestedElement", f: () => "Hello World"},
// 'nestedElement' is set here for the main function to recognize it
f: context => context.resolve.nestedElement
}
Ensure that every element you want to use from resolve
is appropriately defined in your petition
.
Generates a unique ID using crypto.randomUUID()
.
{
path: "/path",
f: ctx => ctx.hash === "some-random-uuid"
? "ID matches expected value"
: "Generated a unique ID"
}
This behavior can be set for testing purposes:
{
path: "/",
options:{
setHash: "specified-uuid-value"
},
f: ctx => ctx.hash === "specified-uuid-value"
? "UUID is bind to a state"
: "unreachable"
}
Retrieves cookies sent with the request using ctx.cookie
.
{
path: '/path',
f: ctx => ctx.cookie?.sessionID
};
// If the `ctx` goes out of context
{
path: '/path',
options: {add: ["cookie"]},
f: ctx => outOfContext(ctx)
};
Utilizes ctx.mutable
for scenarios where mutable state is needed in Vixeny.
{
path: '/mutable',
mutable: true,
// the function is "example", resolves with name "hello", which mutates "result"
resolve: {...example_r_$hello_m_$result_string},
f: ctx => ctx.mutable.result as string
};
The mutable state is global and can be accessed at any depth:
{
path: '/deepMutable',
mutable: true,
// the function is "example", resolves with name "hello", which mutates "result"
resolve: {...example_r_$hello_m_$result_string},
f: ctx => ctx.branch.function("Greetings") as string,
branch: {
name: "function",
f: c => `${c.arguments} ${c.mutable.result}`
}
};
Interacts with the arguments
property in ctx.branch
to receive input for branch functions.
{
path: '/path',
f: ctx => ctx.branch.hello("Greetings!"),
branch: {
name: "hello",
f: c => c.arguments
}
};
When invoking a branch function, any parameters passed are accessible as arguments
within the branch function.
{
path: '/multipleArgs',
f: ctx => ctx.branch.greet("Hello", "world!"),
branch: {
name: "greet",
f: c => `${c.arguments[0]} ${c.arguments[1]}`
}
};
In this example, multiple arguments are passed to the branch function, and they're accessed via index in the branch.