@efebia/fastify-zod-reply 1.4.1 → 1.4.3
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/lib/cjs/index.d.ts +59 -9
- package/lib/cjs/index.js +1 -4
- package/lib/cjs/routeV4.d.ts +10 -1
- package/lib/cjs/routeV4.js +2 -2
- package/lib/cjs/sseRouteV4.d.ts +3 -0
- package/lib/cjs/sseRouteV4.js +2 -2
- package/lib/esm/index.d.ts +59 -9
- package/lib/esm/index.js +1 -4
- package/lib/esm/routeV4.d.ts +10 -1
- package/lib/esm/routeV4.js +2 -2
- package/lib/esm/sseRouteV4.d.ts +3 -0
- package/lib/esm/sseRouteV4.js +2 -2
- package/package.json +1 -1
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,61 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type CodePayload<TReply, TCode extends number, TFallback = unknown> = TReply extends {
|
|
2
|
+
send(payload?: infer TMap): any;
|
|
3
|
+
} ? TMap extends Record<TCode, infer T> ? T : TFallback : TFallback;
|
|
4
|
+
export type ResponseParam<TReply, TCode extends number> = CodePayload<TReply, TCode> extends Record<PropertyKey, unknown> ? CodePayload<TReply, TCode> & Record<string, unknown> : CodePayload<TReply, TCode>;
|
|
5
|
+
export type ValidateResponseParam<TThis, TCode extends number> = CodePayload<TThis, TCode, never> extends never ? string : CodePayload<TThis, TCode, never> extends {
|
|
6
|
+
message: infer M;
|
|
7
|
+
} ? M & string : never;
|
|
8
|
+
export type ErrorMethodParam<TThis, TCode extends number> = ValidateResponseParam<TThis, TCode> | ResponseParam<TThis, TCode>;
|
|
9
|
+
export type ErrorCodePayload<TVal> = [TVal] extends [string] ? {
|
|
10
|
+
message: TVal;
|
|
11
|
+
} : TVal;
|
|
12
|
+
type DefaultArgs<TReply, TCode extends number, TParam> = CodePayload<TReply, TCode, never> extends never ? [val?: undefined] : [val: TParam];
|
|
13
|
+
declare module "fastify" {
|
|
14
|
+
interface FastifyReply {
|
|
15
|
+
ok(...args: DefaultArgs<this, 200, ResponseParam<this, 200>>): CodePayload<this, 200, {
|
|
16
|
+
message: "ok";
|
|
17
|
+
}>;
|
|
18
|
+
ok(val: ResponseParam<this, 200>): CodePayload<this, 200>;
|
|
19
|
+
created(...args: DefaultArgs<this, 201, ResponseParam<this, 201>>): CodePayload<this, 201, {
|
|
20
|
+
message: "created";
|
|
21
|
+
}>;
|
|
22
|
+
created(val: ResponseParam<this, 201>): CodePayload<this, 201>;
|
|
23
|
+
accepted(...args: DefaultArgs<this, 202, ResponseParam<this, 202>>): CodePayload<this, 202, {
|
|
24
|
+
message: "accepted";
|
|
25
|
+
}>;
|
|
26
|
+
accepted(val: ResponseParam<this, 202>): CodePayload<this, 202>;
|
|
27
|
+
noContent(): CodePayload<this, 204, void>;
|
|
28
|
+
badRequest(...args: DefaultArgs<this, 400, ErrorMethodParam<this, 400>>): CodePayload<this, 400, {
|
|
29
|
+
message: "badRequest";
|
|
30
|
+
}>;
|
|
31
|
+
badRequest<TVal extends ErrorMethodParam<this, 400>>(val: TVal): ErrorCodePayload<TVal>;
|
|
32
|
+
unauthorized(...args: DefaultArgs<this, 401, ErrorMethodParam<this, 401>>): CodePayload<this, 401, {
|
|
33
|
+
message: "unauthorized";
|
|
34
|
+
}>;
|
|
35
|
+
unauthorized<TVal extends ErrorMethodParam<this, 401>>(val: TVal): ErrorCodePayload<TVal>;
|
|
36
|
+
forbidden(...args: DefaultArgs<this, 403, ErrorMethodParam<this, 403>>): CodePayload<this, 403, {
|
|
37
|
+
message: "forbidden";
|
|
38
|
+
}>;
|
|
39
|
+
forbidden<TVal extends ErrorMethodParam<this, 403>>(val: TVal): ErrorCodePayload<TVal>;
|
|
40
|
+
notFound(...args: DefaultArgs<this, 404, ErrorMethodParam<this, 404>>): CodePayload<this, 404, {
|
|
41
|
+
message: "notFound";
|
|
42
|
+
}>;
|
|
43
|
+
notFound<TVal extends ErrorMethodParam<this, 404>>(val: TVal): ErrorCodePayload<TVal>;
|
|
44
|
+
notAcceptable(...args: DefaultArgs<this, 406, ErrorMethodParam<this, 406>>): CodePayload<this, 406, {
|
|
45
|
+
message: "notAcceptable";
|
|
46
|
+
}>;
|
|
47
|
+
notAcceptable<TVal extends ErrorMethodParam<this, 406>>(val: TVal): ErrorCodePayload<TVal>;
|
|
48
|
+
conflict(...args: DefaultArgs<this, 409, ErrorMethodParam<this, 409>>): CodePayload<this, 409, {
|
|
49
|
+
message: "conflict";
|
|
50
|
+
}>;
|
|
51
|
+
conflict<TVal extends ErrorMethodParam<this, 409>>(val: TVal): ErrorCodePayload<TVal>;
|
|
52
|
+
internalServerError(...args: DefaultArgs<this, 500, ErrorMethodParam<this, 500>>): CodePayload<this, 500, {
|
|
53
|
+
message: "internalServerError";
|
|
54
|
+
}>;
|
|
55
|
+
internalServerError<TVal extends ErrorMethodParam<this, 500>>(val: TVal): ErrorCodePayload<TVal>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export type StatusCode<TCode extends number> = {
|
|
2
59
|
statusCode: TCode;
|
|
3
60
|
payload: any;
|
|
4
61
|
};
|
|
@@ -18,15 +75,8 @@ export interface FastifyStatusCode {
|
|
|
18
75
|
export type FastifyReplyPluginOptions = {
|
|
19
76
|
statusCodes?: {
|
|
20
77
|
[key in keyof FastifyStatusCode]?: FastifyStatusCode[key];
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
export type DecoratedReply = {
|
|
24
|
-
[key in keyof FastifyStatusCode]: <T>(val?: T) => T;
|
|
78
|
+
} & Record<string, StatusCode<any>>;
|
|
25
79
|
};
|
|
26
|
-
declare module "fastify" {
|
|
27
|
-
interface FastifyReply extends DecoratedReply {
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
80
|
declare const _default: import("fastify").FastifyPluginCallback<FastifyReplyPluginOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
31
81
|
export default _default;
|
|
32
82
|
export { buildHTTPErrorObject, FastifyZodReplyError } from "./error.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -33,10 +33,7 @@ const defaultOptions = {
|
|
|
33
33
|
notFound: { statusCode: 404, payload: { message: "notFound" } },
|
|
34
34
|
notAcceptable: { statusCode: 406, payload: { message: "notAcceptable" } },
|
|
35
35
|
conflict: { statusCode: 409, payload: { message: "conflict" } },
|
|
36
|
-
internalServerError: {
|
|
37
|
-
statusCode: 500,
|
|
38
|
-
payload: { message: "internalServerError" },
|
|
39
|
-
},
|
|
36
|
+
internalServerError: { statusCode: 500, payload: { message: "internalServerError" } },
|
|
40
37
|
},
|
|
41
38
|
};
|
|
42
39
|
exports.default = (0, fastify_plugin_1.default)(async (fastify, opts) => {
|
package/lib/cjs/routeV4.d.ts
CHANGED
|
@@ -10,12 +10,20 @@ export type BaseZodV4Schema = {
|
|
|
10
10
|
}>;
|
|
11
11
|
Security?: RouteSecurity[keyof RouteSecurity][];
|
|
12
12
|
Tags?: (keyof RouteTag)[];
|
|
13
|
+
Description?: string;
|
|
14
|
+
Summary?: string;
|
|
15
|
+
Notes?: string;
|
|
16
|
+
};
|
|
17
|
+
type ErrorReplyFallback<TReply> = {
|
|
18
|
+
[K in Exclude<400 | 401 | 403 | 404 | 406 | 409 | 500, keyof TReply>]?: {
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
13
21
|
};
|
|
14
22
|
export type FastifyZodV4Schema<TZodSchema extends BaseZodV4Schema> = {
|
|
15
23
|
Body: TZodSchema["Body"] extends z.ZodTypeAny ? z.output<TZodSchema["Body"]> : undefined;
|
|
16
24
|
Params: TZodSchema["Params"] extends z.ZodTypeAny ? z.output<TZodSchema["Params"]> : undefined;
|
|
17
25
|
Querystring: TZodSchema["Query"] extends z.ZodTypeAny ? z.output<TZodSchema["Query"]> : undefined;
|
|
18
|
-
Reply: TZodSchema["Reply"] extends z.ZodTypeAny ? z.input<TZodSchema["Reply"]>
|
|
26
|
+
Reply: TZodSchema["Reply"] extends z.ZodTypeAny ? z.input<TZodSchema["Reply"]> & ErrorReplyFallback<z.input<TZodSchema["Reply"]>> : undefined;
|
|
19
27
|
};
|
|
20
28
|
export type RouteV4Options = {
|
|
21
29
|
strict?: boolean | {
|
|
@@ -31,3 +39,4 @@ export declare const createRouteV4: <RequestAugmentation extends object = {}, Re
|
|
|
31
39
|
export declare const routeV4: <TSchema extends BaseZodV4Schema, FastifySchema extends FastifyZodV4Schema<TSchema> = FastifyZodV4Schema<TSchema>>(schema: TSchema, handler: NoInfer<APIHandler<FastifySchema, {}, {}>>, options?: RouteV4Options) => APIOptions<FastifySchema> & {
|
|
32
40
|
handler: APIHandler<FastifySchema>;
|
|
33
41
|
};
|
|
42
|
+
export {};
|
package/lib/cjs/routeV4.js
CHANGED
|
@@ -6,7 +6,7 @@ const error_js_1 = require("./error.js");
|
|
|
6
6
|
const routeHelpers_js_1 = require("./routeHelpers.js");
|
|
7
7
|
const createRouteV4 = ({ strict: globalStrict = false } = {}) => (schema, handler, options) => {
|
|
8
8
|
const strict = typeof (options === null || options === void 0 ? void 0 : options.strict) !== "undefined" ? options === null || options === void 0 ? void 0 : options.strict : globalStrict;
|
|
9
|
-
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
9
|
+
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
10
10
|
body: v4_1.z.toJSONSchema((0, routeHelpers_js_1.strictifySchema)(schema.Body, (0, routeHelpers_js_1.parseStrict)("body", strict)), { reused: "inline", target: "draft-7", io: "input" }),
|
|
11
11
|
})), (schema.Params && {
|
|
12
12
|
params: v4_1.z.toJSONSchema((0, routeHelpers_js_1.strictifySchema)(schema.Params, (0, routeHelpers_js_1.parseStrict)("params", strict)), { reused: "inline", target: "draft-7", io: "input" }),
|
|
@@ -17,7 +17,7 @@ const createRouteV4 = ({ strict: globalStrict = false } = {}) => (schema, handle
|
|
|
17
17
|
})), { response: v4_1.z.toJSONSchema(schema.Reply.partial(), {
|
|
18
18
|
reused: "inline",
|
|
19
19
|
target: "draft-7",
|
|
20
|
-
})["properties"] }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags }));
|
|
20
|
+
})["properties"] }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags })), (schema.Description && { description: schema.Description })), (schema.Summary && { summary: schema.Summary })), (schema.Notes && { notes: schema.Notes }));
|
|
21
21
|
return {
|
|
22
22
|
schema: finalResult,
|
|
23
23
|
handler,
|
package/lib/cjs/sseRouteV4.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export type SSEBaseZodV4Schema = {
|
|
|
17
17
|
}>;
|
|
18
18
|
Security?: RouteSecurity[keyof RouteSecurity][];
|
|
19
19
|
Tags?: (keyof RouteTag)[];
|
|
20
|
+
Description?: string;
|
|
21
|
+
Summary?: string;
|
|
22
|
+
Notes?: string;
|
|
20
23
|
};
|
|
21
24
|
type TransformSSETo200<T> = {
|
|
22
25
|
[K in keyof T as K extends "SSE" ? 200 : K]: T[K];
|
package/lib/cjs/sseRouteV4.js
CHANGED
|
@@ -22,7 +22,7 @@ function createSSERouteV4(globalOptions = {}) {
|
|
|
22
22
|
throw new Error("An SSE endpoint must define a schema for the 200 status code.");
|
|
23
23
|
}
|
|
24
24
|
delete responseJsonSchema["SSE"];
|
|
25
|
-
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
25
|
+
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
26
26
|
body: v4_1.z.toJSONSchema((0, routeHelpers_js_1.strictifySchema)(schema.Body, (0, routeHelpers_js_1.parseStrict)("body", strict)), {
|
|
27
27
|
reused: "inline",
|
|
28
28
|
target: "draft-7",
|
|
@@ -52,7 +52,7 @@ function createSSERouteV4(globalOptions = {}) {
|
|
|
52
52
|
schema: responseSSESchema,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
55
|
-
} }) }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags }));
|
|
55
|
+
} }) }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags })), (schema.Description && { description: schema.Description })), (schema.Summary && { summary: schema.Summary })), (schema.Notes && { notes: schema.Notes }));
|
|
56
56
|
return {
|
|
57
57
|
schema: finalResult,
|
|
58
58
|
handler,
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,61 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type CodePayload<TReply, TCode extends number, TFallback = unknown> = TReply extends {
|
|
2
|
+
send(payload?: infer TMap): any;
|
|
3
|
+
} ? TMap extends Record<TCode, infer T> ? T : TFallback : TFallback;
|
|
4
|
+
export type ResponseParam<TReply, TCode extends number> = CodePayload<TReply, TCode> extends Record<PropertyKey, unknown> ? CodePayload<TReply, TCode> & Record<string, unknown> : CodePayload<TReply, TCode>;
|
|
5
|
+
export type ValidateResponseParam<TThis, TCode extends number> = CodePayload<TThis, TCode, never> extends never ? string : CodePayload<TThis, TCode, never> extends {
|
|
6
|
+
message: infer M;
|
|
7
|
+
} ? M & string : never;
|
|
8
|
+
export type ErrorMethodParam<TThis, TCode extends number> = ValidateResponseParam<TThis, TCode> | ResponseParam<TThis, TCode>;
|
|
9
|
+
export type ErrorCodePayload<TVal> = [TVal] extends [string] ? {
|
|
10
|
+
message: TVal;
|
|
11
|
+
} : TVal;
|
|
12
|
+
type DefaultArgs<TReply, TCode extends number, TParam> = CodePayload<TReply, TCode, never> extends never ? [val?: undefined] : [val: TParam];
|
|
13
|
+
declare module "fastify" {
|
|
14
|
+
interface FastifyReply {
|
|
15
|
+
ok(...args: DefaultArgs<this, 200, ResponseParam<this, 200>>): CodePayload<this, 200, {
|
|
16
|
+
message: "ok";
|
|
17
|
+
}>;
|
|
18
|
+
ok(val: ResponseParam<this, 200>): CodePayload<this, 200>;
|
|
19
|
+
created(...args: DefaultArgs<this, 201, ResponseParam<this, 201>>): CodePayload<this, 201, {
|
|
20
|
+
message: "created";
|
|
21
|
+
}>;
|
|
22
|
+
created(val: ResponseParam<this, 201>): CodePayload<this, 201>;
|
|
23
|
+
accepted(...args: DefaultArgs<this, 202, ResponseParam<this, 202>>): CodePayload<this, 202, {
|
|
24
|
+
message: "accepted";
|
|
25
|
+
}>;
|
|
26
|
+
accepted(val: ResponseParam<this, 202>): CodePayload<this, 202>;
|
|
27
|
+
noContent(): CodePayload<this, 204, void>;
|
|
28
|
+
badRequest(...args: DefaultArgs<this, 400, ErrorMethodParam<this, 400>>): CodePayload<this, 400, {
|
|
29
|
+
message: "badRequest";
|
|
30
|
+
}>;
|
|
31
|
+
badRequest<TVal extends ErrorMethodParam<this, 400>>(val: TVal): ErrorCodePayload<TVal>;
|
|
32
|
+
unauthorized(...args: DefaultArgs<this, 401, ErrorMethodParam<this, 401>>): CodePayload<this, 401, {
|
|
33
|
+
message: "unauthorized";
|
|
34
|
+
}>;
|
|
35
|
+
unauthorized<TVal extends ErrorMethodParam<this, 401>>(val: TVal): ErrorCodePayload<TVal>;
|
|
36
|
+
forbidden(...args: DefaultArgs<this, 403, ErrorMethodParam<this, 403>>): CodePayload<this, 403, {
|
|
37
|
+
message: "forbidden";
|
|
38
|
+
}>;
|
|
39
|
+
forbidden<TVal extends ErrorMethodParam<this, 403>>(val: TVal): ErrorCodePayload<TVal>;
|
|
40
|
+
notFound(...args: DefaultArgs<this, 404, ErrorMethodParam<this, 404>>): CodePayload<this, 404, {
|
|
41
|
+
message: "notFound";
|
|
42
|
+
}>;
|
|
43
|
+
notFound<TVal extends ErrorMethodParam<this, 404>>(val: TVal): ErrorCodePayload<TVal>;
|
|
44
|
+
notAcceptable(...args: DefaultArgs<this, 406, ErrorMethodParam<this, 406>>): CodePayload<this, 406, {
|
|
45
|
+
message: "notAcceptable";
|
|
46
|
+
}>;
|
|
47
|
+
notAcceptable<TVal extends ErrorMethodParam<this, 406>>(val: TVal): ErrorCodePayload<TVal>;
|
|
48
|
+
conflict(...args: DefaultArgs<this, 409, ErrorMethodParam<this, 409>>): CodePayload<this, 409, {
|
|
49
|
+
message: "conflict";
|
|
50
|
+
}>;
|
|
51
|
+
conflict<TVal extends ErrorMethodParam<this, 409>>(val: TVal): ErrorCodePayload<TVal>;
|
|
52
|
+
internalServerError(...args: DefaultArgs<this, 500, ErrorMethodParam<this, 500>>): CodePayload<this, 500, {
|
|
53
|
+
message: "internalServerError";
|
|
54
|
+
}>;
|
|
55
|
+
internalServerError<TVal extends ErrorMethodParam<this, 500>>(val: TVal): ErrorCodePayload<TVal>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export type StatusCode<TCode extends number> = {
|
|
2
59
|
statusCode: TCode;
|
|
3
60
|
payload: any;
|
|
4
61
|
};
|
|
@@ -18,15 +75,8 @@ export interface FastifyStatusCode {
|
|
|
18
75
|
export type FastifyReplyPluginOptions = {
|
|
19
76
|
statusCodes?: {
|
|
20
77
|
[key in keyof FastifyStatusCode]?: FastifyStatusCode[key];
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
export type DecoratedReply = {
|
|
24
|
-
[key in keyof FastifyStatusCode]: <T>(val?: T) => T;
|
|
78
|
+
} & Record<string, StatusCode<any>>;
|
|
25
79
|
};
|
|
26
|
-
declare module "fastify" {
|
|
27
|
-
interface FastifyReply extends DecoratedReply {
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
80
|
declare const _default: import("fastify").FastifyPluginCallback<FastifyReplyPluginOptions, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
31
81
|
export default _default;
|
|
32
82
|
export { buildHTTPErrorObject, FastifyZodReplyError } from "./error.js";
|
package/lib/esm/index.js
CHANGED
|
@@ -13,10 +13,7 @@ const defaultOptions = {
|
|
|
13
13
|
notFound: { statusCode: 404, payload: { message: "notFound" } },
|
|
14
14
|
notAcceptable: { statusCode: 406, payload: { message: "notAcceptable" } },
|
|
15
15
|
conflict: { statusCode: 409, payload: { message: "conflict" } },
|
|
16
|
-
internalServerError: {
|
|
17
|
-
statusCode: 500,
|
|
18
|
-
payload: { message: "internalServerError" },
|
|
19
|
-
},
|
|
16
|
+
internalServerError: { statusCode: 500, payload: { message: "internalServerError" } },
|
|
20
17
|
},
|
|
21
18
|
};
|
|
22
19
|
export default fp(async (fastify, opts) => {
|
package/lib/esm/routeV4.d.ts
CHANGED
|
@@ -10,12 +10,20 @@ export type BaseZodV4Schema = {
|
|
|
10
10
|
}>;
|
|
11
11
|
Security?: RouteSecurity[keyof RouteSecurity][];
|
|
12
12
|
Tags?: (keyof RouteTag)[];
|
|
13
|
+
Description?: string;
|
|
14
|
+
Summary?: string;
|
|
15
|
+
Notes?: string;
|
|
16
|
+
};
|
|
17
|
+
type ErrorReplyFallback<TReply> = {
|
|
18
|
+
[K in Exclude<400 | 401 | 403 | 404 | 406 | 409 | 500, keyof TReply>]?: {
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
13
21
|
};
|
|
14
22
|
export type FastifyZodV4Schema<TZodSchema extends BaseZodV4Schema> = {
|
|
15
23
|
Body: TZodSchema["Body"] extends z.ZodTypeAny ? z.output<TZodSchema["Body"]> : undefined;
|
|
16
24
|
Params: TZodSchema["Params"] extends z.ZodTypeAny ? z.output<TZodSchema["Params"]> : undefined;
|
|
17
25
|
Querystring: TZodSchema["Query"] extends z.ZodTypeAny ? z.output<TZodSchema["Query"]> : undefined;
|
|
18
|
-
Reply: TZodSchema["Reply"] extends z.ZodTypeAny ? z.input<TZodSchema["Reply"]>
|
|
26
|
+
Reply: TZodSchema["Reply"] extends z.ZodTypeAny ? z.input<TZodSchema["Reply"]> & ErrorReplyFallback<z.input<TZodSchema["Reply"]>> : undefined;
|
|
19
27
|
};
|
|
20
28
|
export type RouteV4Options = {
|
|
21
29
|
strict?: boolean | {
|
|
@@ -31,3 +39,4 @@ export declare const createRouteV4: <RequestAugmentation extends object = {}, Re
|
|
|
31
39
|
export declare const routeV4: <TSchema extends BaseZodV4Schema, FastifySchema extends FastifyZodV4Schema<TSchema> = FastifyZodV4Schema<TSchema>>(schema: TSchema, handler: NoInfer<APIHandler<FastifySchema, {}, {}>>, options?: RouteV4Options) => APIOptions<FastifySchema> & {
|
|
32
40
|
handler: APIHandler<FastifySchema>;
|
|
33
41
|
};
|
|
42
|
+
export {};
|
package/lib/esm/routeV4.js
CHANGED
|
@@ -3,7 +3,7 @@ import { FastifyZodReplyError } from "./error.js";
|
|
|
3
3
|
import { findStatusCode, mapZodError, parse, parseStrict, strictifySchema, } from "./routeHelpers.js";
|
|
4
4
|
export const createRouteV4 = ({ strict: globalStrict = false } = {}) => (schema, handler, options) => {
|
|
5
5
|
const strict = typeof (options === null || options === void 0 ? void 0 : options.strict) !== "undefined" ? options === null || options === void 0 ? void 0 : options.strict : globalStrict;
|
|
6
|
-
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
6
|
+
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
7
7
|
body: z.toJSONSchema(strictifySchema(schema.Body, parseStrict("body", strict)), { reused: "inline", target: "draft-7", io: "input" }),
|
|
8
8
|
})), (schema.Params && {
|
|
9
9
|
params: z.toJSONSchema(strictifySchema(schema.Params, parseStrict("params", strict)), { reused: "inline", target: "draft-7", io: "input" }),
|
|
@@ -14,7 +14,7 @@ export const createRouteV4 = ({ strict: globalStrict = false } = {}) => (schema,
|
|
|
14
14
|
})), { response: z.toJSONSchema(schema.Reply.partial(), {
|
|
15
15
|
reused: "inline",
|
|
16
16
|
target: "draft-7",
|
|
17
|
-
})["properties"] }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags }));
|
|
17
|
+
})["properties"] }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags })), (schema.Description && { description: schema.Description })), (schema.Summary && { summary: schema.Summary })), (schema.Notes && { notes: schema.Notes }));
|
|
18
18
|
return {
|
|
19
19
|
schema: finalResult,
|
|
20
20
|
handler,
|
package/lib/esm/sseRouteV4.d.ts
CHANGED
|
@@ -17,6 +17,9 @@ export type SSEBaseZodV4Schema = {
|
|
|
17
17
|
}>;
|
|
18
18
|
Security?: RouteSecurity[keyof RouteSecurity][];
|
|
19
19
|
Tags?: (keyof RouteTag)[];
|
|
20
|
+
Description?: string;
|
|
21
|
+
Summary?: string;
|
|
22
|
+
Notes?: string;
|
|
20
23
|
};
|
|
21
24
|
type TransformSSETo200<T> = {
|
|
22
25
|
[K in keyof T as K extends "SSE" ? 200 : K]: T[K];
|
package/lib/esm/sseRouteV4.js
CHANGED
|
@@ -18,7 +18,7 @@ export function createSSERouteV4(globalOptions = {}) {
|
|
|
18
18
|
throw new Error("An SSE endpoint must define a schema for the 200 status code.");
|
|
19
19
|
}
|
|
20
20
|
delete responseJsonSchema["SSE"];
|
|
21
|
-
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
21
|
+
const finalResult = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (schema.Body && {
|
|
22
22
|
body: z.toJSONSchema(strictifySchema(schema.Body, parseStrict("body", strict)), {
|
|
23
23
|
reused: "inline",
|
|
24
24
|
target: "draft-7",
|
|
@@ -48,7 +48,7 @@ export function createSSERouteV4(globalOptions = {}) {
|
|
|
48
48
|
schema: responseSSESchema,
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
|
-
} }) }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags }));
|
|
51
|
+
} }) }), (schema.Security && { security: schema.Security })), (schema.Tags && { tags: schema.Tags })), (schema.Description && { description: schema.Description })), (schema.Summary && { summary: schema.Summary })), (schema.Notes && { notes: schema.Notes }));
|
|
52
52
|
return {
|
|
53
53
|
schema: finalResult,
|
|
54
54
|
handler,
|