UNPKG

4.73 kBTypeScriptView Raw
1import type { File, Options as FormidableOptions } from 'formidable';
2import type { Options as CoBodyOptions } from 'co-body';
3import type { Context } from 'koa';
4import { z } from 'zod';
5export declare enum HttpMethodEnum {
6 POST = "POST",
7 GET = "GET",
8 PUT = "PUT",
9 PATCH = "PATCH",
10 DELETE = "DELETE",
11 HEAD = "HEAD"
12}
13declare const HttpMethod: z.ZodNativeEnum<typeof HttpMethodEnum>;
14export declare type HttpMethod = z.infer<typeof HttpMethod>;
15export declare type ExtendedFormidableOptions = FormidableOptions & {
16 onFileBegin?: (name: string, file: File) => void;
17};
18export declare const KoaBodyMiddlewareOptionsSchema: z.ZodObject<{
19 /**
20 * {Boolean} Patch request body to Node's ctx.req, default false
21 *
22 * Note: You can patch request body to Node or Koa in same time if you want.
23 */
24 patchNode: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
25 /**
26 * {Boolean} Patch request body to Koa's ctx.request, default true
27 *
28 * Note: You can patch request body to Node or Koa in same time if you want.
29 */
30 patchKoa: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
31 /**
32 * {String|Integer} The byte (if integer) limit of the JSON body, default 1mb
33 */
34 jsonLimit: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
35 /**
36 * {String|Integer} The byte (if integer) limit of the form body, default 56kb
37 */
38 formLimit: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
39 /**
40 * {String|Integer} The byte (if integer) limit of the text body, default 56kb
41 */
42 textLimit: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
43 /**
44 * {String} Sets encoding for incoming form fields, default utf-8
45 */
46 encoding: z.ZodDefault<z.ZodOptional<z.ZodString>>;
47 /**
48 * {Boolean} Parse multipart bodies, default false
49 */
50 multipart: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
51 /**
52 * {Boolean} Parse urlencoded bodies, default true
53 */
54 urlencoded: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
55 /**
56 * {Boolean} Parse text bodies, default true
57 */
58 text: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
59 /**
60 * {Boolean} Parse json bodies, default true
61 */
62 json: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
63 /**
64 * Toggles co-body strict mode; if true, only parses arrays or objects, default true
65 */
66 jsonStrict: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
67 /**
68 * Toggles co-body returnRawBody mode; if true,
69 * the raw body will be available using a Symbol for 'unparsedBody'.
70 *
71 * ```
72 // Either:
73 const unparsed = require('koa-body/unparsed.js');
74 const unparsed = Symbol.for('unparsedBody');
75
76 // Then later, to access:
77 ctx.request.body[unparsed]
78 ```
79 * default false
80 */
81 includeUnparsed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
82 /**
83 * {String[]} What HTTP methods to enable body parsing for; should be used in preference to strict mode.
84 *
85 * GET, HEAD, and DELETE requests have no defined semantics for the request body,
86 * but this doesn't mean they may not be valid in certain use cases.
87 * koa-body will only parse HTTP request bodies for POST, PUT, and PATCH by default
88 *
89 * see http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.3
90 */
91 parsedMethods: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodNativeEnum<typeof HttpMethodEnum>, "many">>>;
92}, "strip", z.ZodTypeAny, {
93 json: boolean;
94 encoding: string;
95 multipart: boolean;
96 patchNode: boolean;
97 patchKoa: boolean;
98 jsonLimit: string | number;
99 formLimit: string | number;
100 textLimit: string | number;
101 urlencoded: boolean;
102 text: boolean;
103 jsonStrict: boolean;
104 includeUnparsed: boolean;
105 parsedMethods: HttpMethodEnum[];
106}, {
107 json?: boolean | undefined;
108 encoding?: string | undefined;
109 multipart?: boolean | undefined;
110 patchNode?: boolean | undefined;
111 patchKoa?: boolean | undefined;
112 jsonLimit?: string | number | undefined;
113 formLimit?: string | number | undefined;
114 textLimit?: string | number | undefined;
115 urlencoded?: boolean | undefined;
116 text?: boolean | undefined;
117 jsonStrict?: boolean | undefined;
118 includeUnparsed?: boolean | undefined;
119 parsedMethods?: HttpMethodEnum[] | undefined;
120}>;
121export declare type KoaBodyDirectOptions = z.infer<typeof KoaBodyMiddlewareOptionsSchema>;
122export declare type KoaBodyMiddlewareOptions = KoaBodyDirectOptions & {
123 onError?: (err: Error, ctx: Context) => void;
124 formidable?: ExtendedFormidableOptions;
125 queryString?: CoBodyOptions['queryString'];
126};
127export {};