BREAKING CHANGE(request): introduce lazy request body parsing via ctx.json()/text()/arrayBuffer()/formData and remove IRequestContext.body
This commit is contained in:
@@ -24,10 +24,8 @@ export type TRuntime = 'node' | 'deno' | 'bun';
|
||||
* Wraps Web Standard Request with additional utilities
|
||||
*/
|
||||
export interface IRequestContext<TBody = unknown> {
|
||||
/** Original Web Standards Request */
|
||||
/** Original Web Standards Request - body stream is never consumed by framework */
|
||||
readonly request: Request;
|
||||
/** Parsed request body (typed) */
|
||||
readonly body: TBody;
|
||||
/** URL path parameters extracted from route */
|
||||
readonly params: Record<string, string>;
|
||||
/** URL query parameters */
|
||||
@@ -44,6 +42,34 @@ export interface IRequestContext<TBody = unknown> {
|
||||
readonly runtime: TRuntime;
|
||||
/** Route-specific state bag for passing data between interceptors */
|
||||
state: Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* Lazily parse request body as JSON.
|
||||
* Result is cached after first call.
|
||||
* @returns Typed body parsed from JSON
|
||||
*/
|
||||
json(): Promise<TBody>;
|
||||
|
||||
/**
|
||||
* Lazily parse request body as text.
|
||||
* Result is cached after first call.
|
||||
* @returns Body as string
|
||||
*/
|
||||
text(): Promise<string>;
|
||||
|
||||
/**
|
||||
* Lazily parse request body as ArrayBuffer.
|
||||
* Result is cached after first call.
|
||||
* @returns Body as ArrayBuffer
|
||||
*/
|
||||
arrayBuffer(): Promise<ArrayBuffer>;
|
||||
|
||||
/**
|
||||
* Lazily parse request body as FormData.
|
||||
* Result is cached after first call.
|
||||
* @returns Body as FormData
|
||||
*/
|
||||
formData(): Promise<FormData>;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user