UNPKG

@avonjs/avonjs

Version:

A fluent Node.js API generator.

88 lines (87 loc) 2.48 kB
import type { Request } from 'express'; import Collection from '../../Collections/Collection'; import type { AnyRecord, AnyValue, Logger } from '../../Contracts'; export default abstract class FormRequest { protected request: Request; /** * The logger instance. */ protected _logger?: Logger; constructor(request: Request); /** * Set the request logger. */ setLogger(logger: Logger): void; /** * Get the logger instance. */ logger(): Logger | undefined; /** * Get params from route. */ segments(): Collection<string>; /** * Get param from route. */ segment<T = AnyValue>(key: string, callback?: AnyValue): T; /** * Get params from route for the given key. */ route<T = AnyValue>(key: string, callback?: AnyValue): T; /** * Get collection of request attributes. */ collect(): Collection<AnyRecord>; /** * Get value from request. */ get<T = AnyValue>(key: string, callback?: AnyValue): T; /** * Get all attributes from request body and query. */ all(keys?: string[]): AnyRecord; /** * Get only given keys from request body and query. */ only<T = AnyValue>(keys?: string | string[]): Record<string, T>; /** * Get value from request body. */ input<T = AnyValue>(key: string, callback?: AnyValue): T; /** * Get value from query strings. */ query<T = AnyValue>(key: string, callback?: AnyValue): T; /** * Get value from request body and query as string. */ string(key: string, callback?: string): string; /** * Get value from request body and query as string. */ number(key: string, callback?: number): number; /** * Get value from request body and query as boolean. */ boolean(key: string, callback?: boolean): boolean; /** * Get value from request body and query as array. */ array<T = AnyValue>(key: string, callback?: []): T[]; /** * Check if given key exists in request body or query parameters and has valid value. */ filled(keys: string | string[]): boolean; /** * Check if given key exists in request body or query parameters. */ exists(keys: string | string[]): boolean; /** * Get the real request instance. */ getRequest(): Request; /** * Check the request method type. */ isMethod(method: string): boolean; }