import type { FunRouterOptions } from "../../options.ts"; import type { Petition } from "../../morphism.ts"; import common from "./common.ts"; import elements from "./queryElements.ts"; import unique from "./unique.ts"; import plugin from "../../exportable/plugin.ts"; /** * Native query application in vixeny * @param o * @returns */ export const f = (o?: FunRouterOptions) => /** * Here the petition, please remember to modify `query` to have extra functionalities * * @param p * @returns */ ( p: Petition, ): (url: string) => string | Record | null => p.query && p.query.name ? new Function(`return ${unique([p.query.name])}`)() : p.query && Array.isArray(p.query.only) ? new Function(`return ${elements(p.query.only)}`)() : ( (only) => only ? only.length > 0 ? new Function(`return ${elements(only)}`)() : new Function(`return ${common(o)(p)}`)() : new Function(`return ${common(o)(p)}`)() )(plugin.pluginIsUsing(p)("query")); export const isUsing = (o?: FunRouterOptions) => (p: Petition): string => ( (uses) => uses && uses?.length > 0 ? `[` + uses.map((x) => x + "?") + "]" : p.query?.unique ? "[" + p.query?.name + "?" + "]" : `Record | null` )( plugin.pluginIsUsing(p)("query"), );