nextlove 2.1.4 → 2.1.6

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.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,72 @@
1
1
  export * from 'nextjs-exception-middleware';
2
- export { checkRouteSpec, createWithRouteSpec } from './with-route-spec/index.js';
2
+ import { Middleware as Middleware$1 } from 'nextjs-middleware-wrappers';
3
3
  export { wrappers } from 'nextjs-middleware-wrappers';
4
- export { AuthMiddlewares, CreateWithRouteSpecFunction, Middleware, MiddlewareChainOutput, RouteFunction, RouteSpec, SetupParams } from './types/index.js';
5
- export { generateOpenAPI } from './generate-openapi/index.js';
6
- export { generateRouteTypes } from './generate-route-types/index.js';
7
- import './with-route-spec/middlewares/with-methods.js';
8
- import 'zod';
9
- import 'next';
10
- import 'openapi3-ts';
4
+ import { NextApiRequest, NextApiResponse } from 'next';
5
+ import { z } from 'zod';
6
+ import { SecuritySchemeObject, SecurityRequirementObject } from 'openapi3-ts/oas31';
7
+
8
+ declare type HTTPMethods = "GET" | "POST" | "DELETE" | "PUT" | "PATCH" | "HEAD" | "OPTIONS";
9
+
10
+ declare type Middleware<T, Dep = {}> = Middleware$1<T, Dep> & {
11
+ /**
12
+ * @deprecated moved to setupParams
13
+ */
14
+ securitySchema?: SecuritySchemeObject;
15
+ securityObjects?: SecurityRequirementObject[];
16
+ };
17
+ declare type ParamDef$1 = z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>;
18
+ interface RouteSpec<Auth extends string = string, Methods extends HTTPMethods[] = any, JsonBody extends ParamDef$1 = z.ZodObject<any, any, any, any, any>, QueryParams extends ParamDef$1 = z.ZodObject<any, any, any, any, any>, CommonParams extends ParamDef$1 = z.ZodObject<any, any, any, any, any>, Middlewares extends readonly Middleware<any, any>[] = any[], JsonResponse extends ParamDef$1 = z.ZodObject<any, any, any, any, any>, FormData extends ParamDef$1 = z.ZodTypeAny> {
19
+ methods: Methods;
20
+ auth: Auth;
21
+ jsonBody?: JsonBody;
22
+ queryParams?: QueryParams;
23
+ commonParams?: CommonParams;
24
+ middlewares?: Middlewares;
25
+ jsonResponse?: JsonResponse;
26
+ formData?: FormData;
27
+ }
28
+ declare type MiddlewareChainOutput<MWChain extends readonly Middleware<any, any>[]> = MWChain extends readonly [] ? {} : MWChain extends readonly [infer First, ...infer Rest] ? First extends Middleware<infer T, any> ? T & (Rest extends readonly Middleware<any, any>[] ? MiddlewareChainOutput<Rest> : never) : never : never;
29
+ declare type AuthMiddlewares = {
30
+ [auth_type: string]: Middleware<any, any>;
31
+ };
32
+ interface SetupParams<AuthMW extends AuthMiddlewares = AuthMiddlewares, GlobalMW extends Middleware<any, any>[] = any[]> {
33
+ authMiddlewareMap: AuthMW;
34
+ globalMiddlewares: GlobalMW;
35
+ exceptionHandlingMiddleware?: ((next: Function) => Function) | null;
36
+ apiName: string;
37
+ productionServerUrl: string;
38
+ addOkStatus?: boolean;
39
+ shouldValidateResponses?: boolean;
40
+ shouldValidateGetRequestBody?: boolean;
41
+ securitySchemas?: Record<string, SecuritySchemeObject>;
42
+ globalSchemas?: Record<string, z.ZodTypeAny>;
43
+ }
44
+ declare const defaultMiddlewareMap: {
45
+ readonly none: (next: any) => any;
46
+ };
47
+ declare type Send<T> = (body: T) => void;
48
+ declare type NextApiResponseWithoutJsonAndStatusMethods = Omit<NextApiResponse, "json" | "status">;
49
+ declare type SuccessfulNextApiResponseMethods<T> = {
50
+ status: (statusCode: 200 | 201) => NextApiResponseWithoutJsonAndStatusMethods & {
51
+ json: Send<T>;
52
+ };
53
+ json: Send<T>;
54
+ };
55
+ declare type ErrorNextApiResponseMethods = {
56
+ status: (statusCode: number) => NextApiResponseWithoutJsonAndStatusMethods & {
57
+ json: Send<any>;
58
+ };
59
+ json: Send<any>;
60
+ };
61
+ declare type RouteFunction<SP extends SetupParams<AuthMiddlewares>, RS extends RouteSpec> = (req: (SP["authMiddlewareMap"] & typeof defaultMiddlewareMap)[RS["auth"]] extends Middleware<infer AuthMWOut, any> ? Omit<NextApiRequest, "query" | "body"> & AuthMWOut & MiddlewareChainOutput<RS["middlewares"] extends readonly Middleware<any, any>[] ? [...SP["globalMiddlewares"], ...RS["middlewares"]] : SP["globalMiddlewares"]> & {
62
+ body: RS["formData"] extends z.ZodTypeAny ? z.infer<RS["formData"]> : RS["jsonBody"] extends z.ZodTypeAny ? z.infer<RS["jsonBody"]> : {};
63
+ query: RS["queryParams"] extends z.ZodTypeAny ? z.infer<RS["queryParams"]> : {};
64
+ commonParams: RS["commonParams"] extends z.ZodTypeAny ? z.infer<RS["commonParams"]> : {};
65
+ } : `unknown auth type: ${RS["auth"]}. You should configure this auth type in your auth_middlewares w/ createWithRouteSpec, or maybe you need to add "as const" to your route spec definition.`, res: NextApiResponseWithoutJsonAndStatusMethods & SuccessfulNextApiResponseMethods<RS["jsonResponse"] extends z.ZodTypeAny ? z.infer<RS["jsonResponse"]> : any> & ErrorNextApiResponseMethods) => Promise<void>;
66
+ declare type CreateWithRouteSpecFunction = <SP extends SetupParams<AuthMiddlewares, any>>(setupParams: SP) => <RS extends RouteSpec<string, any, any, any, any, any, z.ZodObject<any, any, any, any, any>, any>>(route_spec: RS) => (next: RouteFunction<SP, RS>) => any;
67
+
68
+ declare type ParamDef = z.ZodTypeAny | z.ZodEffects<z.ZodTypeAny>;
69
+ declare const checkRouteSpec: <AuthType extends string = string, Methods extends HTTPMethods[] = HTTPMethods[], JsonBody extends ParamDef = z.ZodTypeAny, QueryParams extends ParamDef = z.ZodTypeAny, CommonParams extends ParamDef = z.ZodTypeAny, Middlewares extends readonly Middleware$1<any, any>[] = readonly Middleware$1<any, any>[], FormData_1 extends ParamDef = z.ZodTypeAny, Spec extends RouteSpec<AuthType, Methods, JsonBody, QueryParams, CommonParams, Middlewares, FormData_1, z.ZodTypeAny> = RouteSpec<AuthType, Methods, JsonBody, QueryParams, CommonParams, Middlewares, FormData_1, z.ZodTypeAny>>(spec: Spec) => string extends Spec["auth"] ? "your route spec is underspecified, add \"as const\"" : Spec;
70
+ declare const createWithRouteSpec: CreateWithRouteSpecFunction;
71
+
72
+ export { AuthMiddlewares, CreateWithRouteSpecFunction, Middleware, MiddlewareChainOutput, RouteFunction, RouteSpec, SetupParams, checkRouteSpec, createWithRouteSpec };