UNPKG

@alessiofrittoli/next-api

Version:
103 lines (100 loc) 3.97 kB
import * as _alessiofrittoli_exception_code from '@alessiofrittoli/exception/code'; import * as _alessiofrittoli_stream_reader_types from '@alessiofrittoli/stream-reader/types'; import { NextResponse as NextResponse$1, NextRequest } from 'next/server'; import { Exception } from '@alessiofrittoli/exception'; import { C as CorsHeadersOptions, A as Api, N as NextResponseProps, a as NextResponseStreamInput } from './types-BCw6mdsz.mjs'; /** * This class extends the [`NextResponse` API](https://nextjs.org/docs/app/api-reference/functions/next-response) with additional convenience methods. * */ declare class NextResponse<Body = unknown> extends NextResponse$1<Body> { /** * The NextResponse CORS options. * */ static CorsOptions?: CorsHeadersOptions['options']; /** * The NextResponse CORS default allowed HTTP methods. * */ static CorsAllowedMethods: Api.RequestMethod[]; /** * The NextResponse CORS default allowed Headers. * */ static CorsAllowedHeaders: string[]; /** * The NextResponse CORS exposed Headers. * */ static CorsExposedHeaders: string[]; /** * Create a new NextResponse instance. * * @param props ( Optional ) An object with {@link NextResponseProps} properties. */ constructor(props?: NextResponseProps); /** * Send a JSON Response. * * @param body The JSON response body. * @param init The ResponseInit. * @returns The NextResponse instance. */ static json<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse$1<JsonBody>; /** * Send a JSON Success Response. * * @param body The JSON response body. * @param init ( Optional ) The ResponseInit. * @returns The NextResponse instance. */ static successJson<JsonBody>(body: JsonBody, init?: ResponseInit): NextResponse$1<Api.Route.ResponseBody<JsonBody>>; /** * Send a JSON Error Response. * * @param exception The `Exception` Error instance. * @param init ( Optional ) The ResponseInit. * * @returns The NextResponse instance. */ static errorJson<TCode = number>(exception: Exception<string, TCode>, init?: ResponseInit): NextResponse$1<Exception<string, TCode>>; static generatorToStream: <T = unknown>(generator: _alessiofrittoli_stream_reader_types.StreamGenerator<T>) => ReadableStream<T>; /** * Stream to Response. * * @param stream The Iterator or ReadableStream to stream. * @returns A new Response with ReadableStream Body. */ static stream<T = unknown>(stream: NextResponseStreamInput<T>, init?: ResponseInit): Response; /** * Send a JSON Empty Body Error Response. * * @param init ( Optional ) The ResponseInit. * @returns The NextResponse instance. */ static emptyBody(init?: ResponseInit): NextResponse$1<Exception<string, _alessiofrittoli_exception_code.ErrorCode>>; /** * Enables Cross Origin Resource Sharing. * * @param request The incoming NextRequest instance. * @param cors ( Optional ) An Object of {@link Api.CORS.Policy} defining custom policies for the API Response. * @returns The NextResponse instance allowing chaining methods. */ static cors(request?: NextRequest, cors?: Api.CORS.Policy): typeof NextResponse; /** * Get CORS ResponseInit. * * @param init ( Optional ) The ResponseInit. * @returns ResponseInit with CORS Response Headers, the given ResponseInit if CORS is disabled. */ static CorsInit(init?: ResponseInit): ResponseInit | undefined; /** * Get CORS Response Headers. * * @param param0 ( Optional ) An object with optional `options` and `headers`. @see {@link CorsHeadersOptions}. * @returns CORS Response Headers instance. */ static CorsHeaders({ options, headers }?: CorsHeadersOptions): Headers; } export { NextResponse as N };