File tree Expand file tree Collapse file tree 4 files changed +25
-11
lines changed
Expand file tree Collapse file tree 4 files changed +25
-11
lines changed Original file line number Diff line number Diff line change 3535 "@types/koa" : " ^3.0.0" ,
3636 "co-body" : " ^6.2.0" ,
3737 "formidable" : " ^3.5.4" ,
38+ "type-fest" : " ^5.3.1" ,
3839 "zod" : " ^4.1.12"
3940 },
4041 "devDependencies" : {
Original file line number Diff line number Diff line change 11import * as coBody from 'co-body' ;
22import type { Middleware , Next } from 'koa' ;
3+ import type { JsonValue } from 'type-fest' ;
34import type { KoaBodyMiddlewareOptions , ScalarOrArrayFiles } from './types.js' ;
45import { KoaBodyMiddlewareOptionsSchema } from './types.js' ;
56import {
@@ -17,15 +18,15 @@ export * from './types.js';
1718
1819declare module 'koa' {
1920 interface Request {
20- body ?: { [ key : string ] : unknown } | string ;
21+ body ?: JsonValue ;
2122 rawBody ?: string ;
2223 files ?: ScalarOrArrayFiles ;
2324 }
2425}
2526
2627declare module 'http' {
2728 interface IncomingMessage {
28- body ?: { [ key : string ] : unknown } | string ;
29+ body ?: JsonValue ;
2930 rawBody ?: string ;
3031 files ?: ScalarOrArrayFiles ;
3132 }
Original file line number Diff line number Diff line change 11import type { Context } from 'koa' ;
2+ import type { JsonValue } from 'type-fest' ;
23import type { ParseWithFormidableResult } from './parse-with-formidable.js' ;
34
4- export type ParseWithCoBodyTextResult = string ;
5- export type ParseWithCoBodyJsonResult = { [ key : string ] : unknown } ;
6- export type ParseWithCoBodyUrlEncodedResult = { [ key : string ] : unknown } ;
75export type ParseWithCoBodyIncludeUnparsedResult = { parsed : ParseWithCoBodyResult ; raw : string } ;
86
9- export type ParseWithCoBodyResult =
10- | ParseWithCoBodyTextResult
11- | ParseWithCoBodyJsonResult
12- | ParseWithCoBodyUrlEncodedResult ;
7+ export type ParseWithCoBodyResult = JsonValue ;
138
149type PatchOptions = {
1510 isMultipart : string | boolean | null ;
@@ -35,7 +30,7 @@ export function patchNodeAndKoa(
3530 ctx . req . body = parsed ;
3631 ctx . req . rawBody = raw ;
3732 } else {
38- ctx . req . body = body ;
33+ ctx . req . body = body as ParseWithCoBodyResult ;
3934 }
4035 }
4136 if ( patchKoa ) {
@@ -48,7 +43,7 @@ export function patchNodeAndKoa(
4843 ctx . request . body = parsed ;
4944 ctx . request . rawBody = raw ;
5045 } else {
51- ctx . request . body = body ;
46+ ctx . request . body = body as ParseWithCoBodyResult ;
5247 }
5348 }
5449}
You can’t perform that action at this time.
0 commit comments