UNPKG

@chubbyts/chubbyts-framework

Version:

A minimal, highly performant middleware PSR-15 inspired function based microframework built with as little complexity as possible, aimed primarily at those developers who want to understand all the vendors they use.

70 lines (69 loc) 2.31 kB
import type { Middleware } from '@chubbyts/chubbyts-http-types/dist/middleware'; import type { RequiredProperties } from '../types.js'; import type { PathOptions, Route } from './route.js'; export type GroupArgument = { path: string; children: Array<Group | Route>; middlewares?: Array<Middleware>; pathOptions?: PathOptions; }; /** * ```ts * import type { Group } from '@chubbyts/chubbyts-framework/dist/router/group'; * * const group: Group = { * path: '/api/users', * children: [listRoute, createRoute, readRoute, updateRoute, deleteRoute], * middlewares: [], * pathOptions: {}, * _group: 'Group', * } * ``` */ export type Group = RequiredProperties<GroupArgument, 'middlewares' | 'pathOptions'> & { _group: string; }; /** * ```ts * import type { Group } from '@chubbyts/chubbyts-framework/dist/router/group'; * import type { Route } from '@chubbyts/chubbyts-framework/dist/router/route'; * * const group: Group = { ..., _group: 'Group' }; * const route: Route = { ..., _route: 'Route' }; * * isGroup(group) // true * isGroup(route) // false * ``` */ export declare const isGroup: (group: unknown) => group is Group; /** * ```ts * import type { Group } from '@chubbyts/chubbyts-framework/dist/router/group'; * import { createGroup } from '@chubbyts/chubbyts-framework/dist/router/group'; * import type { Route } from '@chubbyts/chubbyts-framework/dist/router/route'; * * const listRoute: Route = ...; * const createRoute: Route = ...; * const readRoute: Route = ...; * const updateRoute: Route = ...; * const deleteRoute: Route = ...; * * const group: Group = createGroup({ * path: '/api/users', * children: [listRoute, createRoute, readRoute, updateRoute, deleteRoute], * }); * ``` */ export declare const createGroup: ({ path, children, middlewares, pathOptions }: GroupArgument) => Group; /** * ```ts * import type { Group } from '@chubbyts/chubbyts-framework/dist/router/group'; * import { createGroup, getRoutes } from '@chubbyts/chubbyts-framework/dist/router/group'; * import type { Route } from '@chubbyts/chubbyts-framework/dist/router/route'; * * const group: Group = createGroup({ ... }); * * const routes: Array<Route> = getRoutes(group); * ``` */ export declare const getRoutes: (group: Group) => Array<Route>;