@alevnyacow/nzmt 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import z, { ZodType, type ZodObject } from 'zod';
|
|
2
|
+
import z, { type ZodType, type ZodObject, type ZodUnion } from 'zod';
|
|
3
3
|
import { type ControllerErrorModel, type ErrorBaseCreatingPayload } from './errors.utils';
|
|
4
4
|
export declare enum DefaultErrorCodes {
|
|
5
5
|
REQUEST_PARSING = "ZOD-CONTROLLER___REQUEST-PARSING",
|
|
@@ -7,8 +7,8 @@ export declare enum DefaultErrorCodes {
|
|
|
7
7
|
}
|
|
8
8
|
type SuccessResponse<ResponseZodSchema> = ResponseZodSchema extends undefined ? {} : z.infer<ResponseZodSchema>;
|
|
9
9
|
type ZodAPISchemas = {
|
|
10
|
-
body?: ZodObject
|
|
11
|
-
query?: ZodObject
|
|
10
|
+
body?: ZodObject | ZodUnion<[ZodObject<any>, ...ZodObject<any>[]]>;
|
|
11
|
+
query?: ZodObject | ZodUnion<[ZodObject<any>, ...ZodObject<any>[]]>;
|
|
12
12
|
response?: ZodType;
|
|
13
13
|
};
|
|
14
14
|
type ErrorResponse = {
|
|
@@ -26,7 +26,7 @@ export type OnErrorHandler = (request: {
|
|
|
26
26
|
req: NextRequest;
|
|
27
27
|
}) => Promise<void>;
|
|
28
28
|
type EndpointLogic<T extends ZodAPISchemas> = {
|
|
29
|
-
handler: (payload: (T['query'] extends
|
|
29
|
+
handler: (payload: (T['query'] extends ZodType ? z.infer<T['query']> : {}) & (T['body'] extends ZodType ? z.infer<T['body']> : {}), request: {
|
|
30
30
|
request: NextRequest;
|
|
31
31
|
flags: Record<string, boolean>;
|
|
32
32
|
endpointError: EndpointErrorGenerator;
|
|
@@ -34,9 +34,9 @@ type EndpointLogic<T extends ZodAPISchemas> = {
|
|
|
34
34
|
guards?: Guard[];
|
|
35
35
|
eventHandlers?: {
|
|
36
36
|
onSuccess?: Array<(data: {
|
|
37
|
-
requestPayload: (T['query'] extends
|
|
37
|
+
requestPayload: (T['query'] extends ZodType ? z.infer<T['query']> : {}) & (T['body'] extends ZodType ? z.infer<T['body']> : {});
|
|
38
38
|
request: NextRequest;
|
|
39
|
-
result: T['response'] extends
|
|
39
|
+
result: T['response'] extends ZodType ? z.infer<T['response']> : undefined;
|
|
40
40
|
flags: Record<string, boolean>;
|
|
41
41
|
}) => Promise<void>>;
|
|
42
42
|
onError?: Array<OnErrorHandler>;
|