express-zod-api 5.6.1 → 5.9.0-beta1
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/CHANGELOG.md +43 -0
- package/dist/common-helpers.d.ts +11 -11
- package/dist/common-helpers.js +13 -27
- package/dist/common-helpers.js.map +1 -1
- package/dist/depends-on-method.d.ts +2 -2
- package/dist/endpoint.d.ts +13 -14
- package/dist/endpoint.js +3 -3
- package/dist/endpoint.js.map +1 -1
- package/dist/endpoints-factory.d.ts +20 -48
- package/dist/endpoints-factory.js +7 -7
- package/dist/endpoints-factory.js.map +1 -1
- package/dist/extend-zod.js +5 -1
- package/dist/extend-zod.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +1 -0
- package/dist/middleware.js.map +1 -1
- package/dist/open-api-helpers.d.ts +7 -0
- package/dist/open-api-helpers.js +39 -5
- package/dist/open-api-helpers.js.map +1 -1
- package/dist/result-handler.d.ts +7 -35
- package/dist/server.js +5 -1
- package/dist/server.js.map +1 -1
- package/dist-esm/common-helpers.js +11 -24
- package/dist-esm/common-helpers.js.map +1 -1
- package/dist-esm/endpoint.js +4 -4
- package/dist-esm/endpoint.js.map +1 -1
- package/dist-esm/endpoints-factory.js +7 -7
- package/dist-esm/endpoints-factory.js.map +1 -1
- package/dist-esm/middleware.js.map +1 -1
- package/dist-esm/open-api-helpers.js +36 -4
- package/dist-esm/open-api-helpers.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
## Version 5
|
|
4
4
|
|
|
5
|
+
### v5.9.0-beta1
|
|
6
|
+
|
|
7
|
+
- In this build, improvements have been made to the `EndpointsFactory`, in terms of combining the input schemas of
|
|
8
|
+
middlewares and the endpoint itself. A custom type has been replaced with usage of `ZodIntersection` schema with
|
|
9
|
+
respect to the originals.
|
|
10
|
+
- The generated documentation has improved in this regard:
|
|
11
|
+
- Previously, fields from an object union were documented in a simplified way as optional.
|
|
12
|
+
- Instead, it is now documented using `oneOf` OpenAPI notation.
|
|
13
|
+
- In addition, you can now also use the new `z.discriminatedUnion()` as the input schema on the top level.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// example
|
|
17
|
+
const endpoint = defaultEndpointsFactory.build({
|
|
18
|
+
method: "post",
|
|
19
|
+
input: z.discriminatedUnion("type", [
|
|
20
|
+
z.object({
|
|
21
|
+
type: z.literal("text"),
|
|
22
|
+
str: z.string()
|
|
23
|
+
}),
|
|
24
|
+
z.object({
|
|
25
|
+
type: z.literal("numeric"),
|
|
26
|
+
num: z.number()
|
|
27
|
+
}),
|
|
28
|
+
]),
|
|
29
|
+
output: z.object({...}),
|
|
30
|
+
handler: async ({ input }) => {
|
|
31
|
+
// the type of the input:
|
|
32
|
+
// | { type: "text", str: string }
|
|
33
|
+
// | { type: "numeric", num: number }
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### v5.8.0
|
|
39
|
+
|
|
40
|
+
- `zod` version is 3.13.4.
|
|
41
|
+
- There is a new schema `z.nan()` and some fixes.
|
|
42
|
+
|
|
43
|
+
### v5.7.0
|
|
44
|
+
|
|
45
|
+
- `zod` version is 3.12.0.
|
|
46
|
+
- There is a new schema `z.discriminatedUnion()` and various fixes.
|
|
47
|
+
|
|
5
48
|
### v5.6.1
|
|
6
49
|
|
|
7
50
|
- `express` version is 4.17.3.
|
package/dist/common-helpers.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { CommonConfig, InputSources, LoggerConfig } from "./config-type";
|
|
4
|
-
import {
|
|
4
|
+
import { AnyMiddlewareDef } from "./middleware";
|
|
5
5
|
export declare type FlatObject = Record<string, any>;
|
|
6
6
|
declare type ObjectSchema = z.AnyZodObject;
|
|
7
|
-
declare type
|
|
8
|
-
declare type
|
|
9
|
-
declare type
|
|
10
|
-
export declare type IOSchema = ObjectSchema | UnionSchema | IntersectionSchema;
|
|
7
|
+
declare type UnionSchema = z.ZodUnion<[IOSchema, ...IOSchema[]]>;
|
|
8
|
+
declare type IntersectionSchema = z.ZodIntersection<IOSchema, IOSchema>;
|
|
9
|
+
declare type DiscUnionSchema = z.ZodDiscriminatedUnion<string, z.Primitive, ObjectSchema>;
|
|
10
|
+
export declare type IOSchema = ObjectSchema | UnionSchema | IntersectionSchema | DiscUnionSchema;
|
|
11
11
|
export declare type ArrayElement<T extends readonly unknown[]> = T extends readonly (infer K)[] ? K : never;
|
|
12
|
-
declare type UnionResult<T extends ObjectSchema[], F extends Extractable> = ArrayElement<T>[F];
|
|
13
|
-
declare type IntersectionResult<T extends IntersectionSchema, F extends Extractable> = T["_def"]["left"][F] & T["_def"]["right"][F];
|
|
14
|
-
declare type IOExtract<T extends IOSchema | any, F extends Extractable> = T extends ObjectSchema ? T[F] : T extends UnionSchema ? UnionResult<T["options"], F> : T extends IntersectionSchema ? IntersectionResult<T, F> : unknown;
|
|
15
|
-
export declare type Merge<A extends IOSchema, B extends IOSchema | any> = z.ZodObject<IOExtract<A, "shape"> & IOExtract<B, "shape">, IOExtract<A, "_unknownKeys">, IOExtract<A, "_catchall">, IOExtract<A, "_output"> & IOExtract<B, "_output">, IOExtract<A, "_input"> & IOExtract<B, "_input">>;
|
|
16
12
|
export declare type OutputMarker = IOSchema & {
|
|
17
13
|
_typeGuard: "OutputMarker";
|
|
18
14
|
};
|
|
@@ -22,8 +18,12 @@ export declare const routePathParamsRegex: RegExp;
|
|
|
22
18
|
export declare type ReplaceMarkerInShape<S extends z.ZodRawShape, OUT extends IOSchema> = {
|
|
23
19
|
[K in keyof S]: S[K] extends OutputMarker ? OUT : S[K];
|
|
24
20
|
};
|
|
25
|
-
export declare
|
|
26
|
-
|
|
21
|
+
export declare type ProbableIntersection<A extends IOSchema | null, B extends IOSchema> = A extends null ? B : A extends IOSchema ? z.ZodIntersection<A, B> : never;
|
|
22
|
+
/**
|
|
23
|
+
* @description intersects input schemas of middlewares and the endpoint
|
|
24
|
+
* @since 07.03.2022 former combineEndpointAndMiddlewareInputSchemas()
|
|
25
|
+
*/
|
|
26
|
+
export declare const getFinalEndpointInputSchema: <MIN extends IOSchema | null, IN extends IOSchema>(middlewares: AnyMiddlewareDef[], input: IN) => ProbableIntersection<MIN, IN>;
|
|
27
27
|
export declare const defaultInputSources: InputSources;
|
|
28
28
|
export declare function getInitialInput(request: Request, inputAssignment: CommonConfig["inputSources"]): any;
|
|
29
29
|
export declare function isLoggerConfig(logger: any): logger is LoggerConfig;
|
package/dist/common-helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errToObj = exports.hasUpload = exports.getRoutePathParams = exports.combinations = exports.getExamples = exports.getStatusCodeFromError = exports.getMessageFromError = exports.isValidDate = exports.isLoggerConfig = exports.getInitialInput = exports.defaultInputSources = exports.
|
|
3
|
+
exports.errToObj = exports.hasUpload = exports.getRoutePathParams = exports.combinations = exports.getExamples = exports.getStatusCodeFromError = exports.getMessageFromError = exports.isValidDate = exports.isLoggerConfig = exports.getInitialInput = exports.defaultInputSources = exports.getFinalEndpointInputSchema = exports.routePathParamsRegex = exports.markOutput = void 0;
|
|
4
4
|
const http_errors_1 = require("http-errors");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const config_type_1 = require("./config-type");
|
|
@@ -11,39 +11,25 @@ const markOutput = (output) => output;
|
|
|
11
11
|
exports.markOutput = markOutput;
|
|
12
12
|
/** @see https://expressjs.com/en/guide/routing.html */
|
|
13
13
|
exports.routePathParamsRegex = /:([A-Za-z0-9_]+)/g;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// intersection schema
|
|
24
|
-
objectSchema = subject._def.left.merge(subject._def.right);
|
|
25
|
-
}
|
|
26
|
-
return (0, metadata_1.copyMeta)(subject, objectSchema);
|
|
27
|
-
}
|
|
28
|
-
exports.extractObjectSchema = extractObjectSchema;
|
|
29
|
-
function combineEndpointAndMiddlewareInputSchemas(input, middlewares) {
|
|
30
|
-
if (middlewares.length === 0) {
|
|
31
|
-
return extractObjectSchema(input);
|
|
32
|
-
}
|
|
33
|
-
const mSchema = middlewares
|
|
34
|
-
.map((middleware) => middleware.input)
|
|
35
|
-
.reduce((carry, schema) => extractObjectSchema(carry).merge(extractObjectSchema(schema)));
|
|
36
|
-
const result = extractObjectSchema(mSchema).merge(extractObjectSchema(input));
|
|
14
|
+
/**
|
|
15
|
+
* @description intersects input schemas of middlewares and the endpoint
|
|
16
|
+
* @since 07.03.2022 former combineEndpointAndMiddlewareInputSchemas()
|
|
17
|
+
*/
|
|
18
|
+
const getFinalEndpointInputSchema = (middlewares, input) => {
|
|
19
|
+
const result = middlewares
|
|
20
|
+
.map(({ input: schema }) => schema)
|
|
21
|
+
.concat(input)
|
|
22
|
+
.reduce((acc, schema) => acc.and(schema));
|
|
37
23
|
for (const middleware of middlewares) {
|
|
38
24
|
(0, metadata_1.copyMeta)(middleware.input, result);
|
|
39
25
|
}
|
|
40
26
|
(0, metadata_1.copyMeta)(input, result);
|
|
41
27
|
return result;
|
|
42
|
-
}
|
|
43
|
-
exports.
|
|
28
|
+
};
|
|
29
|
+
exports.getFinalEndpointInputSchema = getFinalEndpointInputSchema;
|
|
44
30
|
function areFilesAvailable(request) {
|
|
45
31
|
const contentType = request.header("content-type") || "";
|
|
46
|
-
const isMultipart = contentType.
|
|
32
|
+
const isMultipart = contentType.slice(0, mime_1.mimeMultipart.length).toLowerCase() === mime_1.mimeMultipart;
|
|
47
33
|
return "files" in request && isMultipart;
|
|
48
34
|
}
|
|
49
35
|
exports.defaultInputSources = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":";;;AACA,6CAAwC;AACxC,6BAAwB;AACxB,+CAKuB;AACvB,yCAA+C;AAG/C,iCAAuC;AACvC,mDAA4C;
|
|
1
|
+
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":";;;AACA,6CAAwC;AACxC,6BAAwB;AACxB,+CAKuB;AACvB,yCAA+C;AAG/C,iCAAuC;AACvC,mDAA4C;AAuBrC,MAAM,UAAU,GAAG,CAAC,MAAgB,EAAE,EAAE,CAAC,MAAsB,CAAC;AAA1D,QAAA,UAAU,cAAgD;AAEvE,uDAAuD;AAC1C,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAcxD;;;GAGG;AACI,MAAM,2BAA2B,GAAG,CAIzC,WAA+B,EAC/B,KAAS,EACsB,EAAE;IACjC,MAAM,MAAM,GAAG,WAAW;SACvB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC;SAClC,MAAM,CAAC,KAAK,CAAC;SACb,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAkC,CAAC;IAC7E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,IAAA,mBAAQ,EAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KACpC;IACD,IAAA,mBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAhBW,QAAA,2BAA2B,+BAgBtC;AAEF,SAAS,iBAAiB,CAAC,OAAgB;IACzC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,WAAW,GACf,WAAW,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,IAAI,CAAC,SAAS,CAAC,CAAC;KACzC;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,QAAQ,EAAE;QAChC,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACpC;IACD,IAAI,MAAM,YAAY,OAAC,CAAC,UAAU,EAAE;QAClC,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KACzC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AA/BD,8BA+BC;AAQD,iDAAiD;AAC1C,MAAM,QAAQ,GAAG,CAAC,OAA+B,EAAE,EAAE,CAC1D,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;AAD/C,QAAA,QAAQ,YACuC"}
|
|
@@ -2,9 +2,9 @@ import { Endpoint } from "./endpoint";
|
|
|
2
2
|
import { Method } from "./method";
|
|
3
3
|
export declare class DependsOnMethod {
|
|
4
4
|
readonly methods: {
|
|
5
|
-
[K in Method]?: Endpoint<any, any, any,
|
|
5
|
+
[K in Method]?: Endpoint<any, any, any, K, any, any> | Endpoint<any, any, any, Method, any, any>;
|
|
6
6
|
};
|
|
7
7
|
constructor(methods: {
|
|
8
|
-
[K in Method]?: Endpoint<any, any, any,
|
|
8
|
+
[K in Method]?: Endpoint<any, any, any, K, any, any> | Endpoint<any, any, any, Method, any, any>;
|
|
9
9
|
});
|
|
10
10
|
}
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { Logger } from "winston";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { ApiResponse } from "./api-response";
|
|
5
5
|
import { CommonConfig } from "./config-type";
|
|
6
|
-
import {
|
|
6
|
+
import { FlatObject, IOSchema, OutputMarker, ReplaceMarkerInShape } from "./common-helpers";
|
|
7
7
|
import { Method, MethodsDefinition } from "./method";
|
|
8
|
-
import {
|
|
8
|
+
import { AnyMiddlewareDef } from "./middleware";
|
|
9
9
|
import { ResultHandlerDefinition } from "./result-handler";
|
|
10
10
|
export declare type Handler<IN, OUT, OPT> = (params: {
|
|
11
11
|
input: IN;
|
|
@@ -29,33 +29,32 @@ export declare abstract class AbstractEndpoint {
|
|
|
29
29
|
abstract getPositiveMimeTypes(): string[];
|
|
30
30
|
abstract getNegativeMimeTypes(): string[];
|
|
31
31
|
}
|
|
32
|
-
export declare type EndpointInput<T> = T extends Endpoint<infer IN, any,
|
|
33
|
-
export declare type EndpointOutput<T> = T extends Endpoint<any, infer OUT, any, any, any, any
|
|
32
|
+
export declare type EndpointInput<T> = T extends Endpoint<infer IN, any, any, any, any, any> ? z.input<IN> : never;
|
|
33
|
+
export declare type EndpointOutput<T> = T extends Endpoint<any, infer OUT, any, any, any, any> ? z.output<OUT> : never;
|
|
34
34
|
export declare type EndpointResponse<E extends AbstractEndpoint> = z.output<ReturnType<E["getPositiveResponseSchema"]> extends z.ZodObject<z.ZodRawShape> ? z.ZodObject<ReplaceMarkerInShape<ReturnType<E["getPositiveResponseSchema"]>["_shape"], ReturnType<E["getOutputSchema"]>>> : ReturnType<E["getPositiveResponseSchema"]> extends OutputMarker ? ReturnType<E["getOutputSchema"]> : ReturnType<E["getPositiveResponseSchema"]>> | z.output<ReturnType<E["getNegativeResponseSchema"]>>;
|
|
35
|
-
declare type EndpointProps<IN extends IOSchema, OUT extends IOSchema,
|
|
36
|
-
middlewares:
|
|
35
|
+
declare type EndpointProps<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, M extends Method, POS extends ApiResponse, NEG extends ApiResponse> = {
|
|
36
|
+
middlewares: AnyMiddlewareDef[];
|
|
37
37
|
inputSchema: IN;
|
|
38
38
|
mimeTypes: string[];
|
|
39
39
|
outputSchema: OUT;
|
|
40
|
-
handler: Handler<z.output<
|
|
40
|
+
handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
41
41
|
resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
42
42
|
description?: string;
|
|
43
43
|
} & MethodsDefinition<M>;
|
|
44
|
-
|
|
45
|
-
export declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, MwIN, OPT, M extends Method, POS extends ApiResponse, NEG extends ApiResponse> extends AbstractEndpoint {
|
|
44
|
+
export declare class Endpoint<IN extends IOSchema, OUT extends IOSchema, OPT extends FlatObject, M extends Method, POS extends ApiResponse, NEG extends ApiResponse> extends AbstractEndpoint {
|
|
46
45
|
#private;
|
|
47
46
|
protected readonly description?: string;
|
|
48
47
|
protected readonly methods: M[];
|
|
49
|
-
protected readonly middlewares:
|
|
50
|
-
protected readonly inputSchema:
|
|
48
|
+
protected readonly middlewares: AnyMiddlewareDef[];
|
|
49
|
+
protected readonly inputSchema: IN;
|
|
51
50
|
protected readonly mimeTypes: string[];
|
|
52
51
|
protected readonly outputSchema: OUT;
|
|
53
|
-
protected readonly handler: Handler<z.output<
|
|
52
|
+
protected readonly handler: Handler<z.output<IN>, z.input<OUT>, OPT>;
|
|
54
53
|
protected readonly resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
55
|
-
constructor({ middlewares, inputSchema, outputSchema, handler, resultHandler, description, mimeTypes, ...rest }: EndpointProps<IN, OUT,
|
|
54
|
+
constructor({ middlewares, inputSchema, outputSchema, handler, resultHandler, description, mimeTypes, ...rest }: EndpointProps<IN, OUT, OPT, M, POS, NEG>);
|
|
56
55
|
getDescription(): string | undefined;
|
|
57
56
|
getMethods(): M[];
|
|
58
|
-
getInputSchema():
|
|
57
|
+
getInputSchema(): IN;
|
|
59
58
|
getOutputSchema(): OUT;
|
|
60
59
|
getPositiveResponseSchema(): POS["schema"];
|
|
61
60
|
getNegativeResponseSchema(): NEG["schema"];
|
package/dist/endpoint.js
CHANGED
|
@@ -14,7 +14,6 @@ const result_handler_1 = require("./result-handler");
|
|
|
14
14
|
class AbstractEndpoint {
|
|
15
15
|
}
|
|
16
16
|
exports.AbstractEndpoint = AbstractEndpoint;
|
|
17
|
-
/** mIN, OPT - from Middlewares */
|
|
18
17
|
class Endpoint extends AbstractEndpoint {
|
|
19
18
|
constructor({ middlewares, inputSchema, outputSchema, handler, resultHandler, description, mimeTypes, ...rest }) {
|
|
20
19
|
super();
|
|
@@ -22,7 +21,7 @@ class Endpoint extends AbstractEndpoint {
|
|
|
22
21
|
this.methods = [];
|
|
23
22
|
this.middlewares = [];
|
|
24
23
|
this.middlewares = middlewares;
|
|
25
|
-
this.inputSchema =
|
|
24
|
+
this.inputSchema = inputSchema;
|
|
26
25
|
this.mimeTypes = mimeTypes;
|
|
27
26
|
this.outputSchema = outputSchema;
|
|
28
27
|
this.handler = handler;
|
|
@@ -150,7 +149,8 @@ _Endpoint_instances = new WeakSet(), _Endpoint_setupCorsHeaders = function _Endp
|
|
|
150
149
|
return { input, options, isStreamClosed };
|
|
151
150
|
}, _Endpoint_parseAndRunHandler = async function _Endpoint_parseAndRunHandler({ input, options, logger, }) {
|
|
152
151
|
return this.handler({
|
|
153
|
-
input
|
|
152
|
+
// final input types transformations for handler
|
|
153
|
+
input: (await this.inputSchema.parseAsync(input)),
|
|
154
154
|
options,
|
|
155
155
|
logger,
|
|
156
156
|
});
|
package/dist/endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;;;;AAEA,6BAAwB;AAGxB,qCAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;;;;AAEA,6BAAwB;AAGxB,qCAA8C;AAC9C,qDAM0B;AAG1B,qDAA8E;AAQ9E,MAAsB,gBAAgB;CAgBrC;AAhBD,4CAgBC;AA0DD,MAAa,QAOX,SAAQ,gBAAgB;IAUxB,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,OAAO,EACP,aAAa,EACb,WAAW,EACX,SAAS,EACT,GAAG,IA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2BAAkB,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;aAChD,CAAC,CAAC;SACJ;KACF;AACH,CAAC"}
|
|
@@ -2,45 +2,37 @@
|
|
|
2
2
|
import { Request, Response } from "express";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { ApiResponse } from "./api-response";
|
|
5
|
+
import { FlatObject, IOSchema, ProbableIntersection } from "./common-helpers";
|
|
5
6
|
import { Endpoint, Handler } from "./endpoint";
|
|
6
|
-
import { FlatObject, IOSchema, Merge } from "./common-helpers";
|
|
7
7
|
import { Method, MethodsDefinition } from "./method";
|
|
8
|
-
import { ExpressMiddleware, ExpressMiddlewareFeatures, MiddlewareDefinition } from "./middleware";
|
|
8
|
+
import { AnyMiddlewareDef, ExpressMiddleware, ExpressMiddlewareFeatures, MiddlewareDefinition } from "./middleware";
|
|
9
9
|
import { ResultHandlerDefinition } from "./result-handler";
|
|
10
|
-
declare type BuildProps<IN extends IOSchema, OUT extends IOSchema,
|
|
10
|
+
declare type BuildProps<IN extends IOSchema, OUT extends IOSchema, MIN extends IOSchema | null, OPT extends FlatObject, M extends Method> = {
|
|
11
11
|
input: IN;
|
|
12
12
|
output: OUT;
|
|
13
|
-
handler: Handler<z.output<
|
|
13
|
+
handler: Handler<z.output<ProbableIntersection<MIN, IN>>, z.input<OUT>, OPT>;
|
|
14
14
|
description?: string;
|
|
15
15
|
} & MethodsDefinition<M>;
|
|
16
|
-
export declare class EndpointsFactory<
|
|
16
|
+
export declare class EndpointsFactory<POS extends ApiResponse, NEG extends ApiResponse, IN extends IOSchema | null = null, OUT extends FlatObject = {}> {
|
|
17
17
|
#private;
|
|
18
18
|
protected resultHandler: ResultHandlerDefinition<POS, NEG>;
|
|
19
|
-
protected middlewares:
|
|
19
|
+
protected middlewares: AnyMiddlewareDef[];
|
|
20
20
|
constructor(resultHandler: ResultHandlerDefinition<POS, NEG>);
|
|
21
|
-
addMiddleware<
|
|
22
|
-
use: <R extends Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>,
|
|
23
|
-
addExpressMiddleware<R extends Request, S extends Response,
|
|
24
|
-
addOptions<
|
|
25
|
-
build<
|
|
21
|
+
addMiddleware<AIN extends IOSchema, AOUT extends FlatObject>(definition: MiddlewareDefinition<AIN, OUT, AOUT>): EndpointsFactory<POS, NEG, ProbableIntersection<IN, AIN>, OUT & AOUT>;
|
|
22
|
+
use: <R extends Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, S extends Response<any, Record<string, any>>, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT> | undefined) => EndpointsFactory<POS, NEG, IN, OUT & AOUT>;
|
|
23
|
+
addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = {}>(middleware: ExpressMiddleware<R, S>, features?: ExpressMiddlewareFeatures<R, S, AOUT>): EndpointsFactory<POS, NEG, IN, OUT & AOUT>;
|
|
24
|
+
addOptions<AOUT extends FlatObject>(options: AOUT): EndpointsFactory<POS, NEG, IN, OUT & AOUT>;
|
|
25
|
+
build<BIN extends IOSchema, BOUT extends IOSchema, M extends Method>({ input, handler, description, output: outputSchema, ...rest }: BuildProps<BIN, BOUT, IN, OUT, M>): Endpoint<ProbableIntersection<IN, BIN>, BOUT, OUT, M, POS, NEG>;
|
|
26
26
|
}
|
|
27
|
-
export declare const defaultEndpointsFactory: EndpointsFactory<
|
|
27
|
+
export declare const defaultEndpointsFactory: EndpointsFactory<ApiResponse<z.ZodObject<{
|
|
28
28
|
status: z.ZodLiteral<"success">;
|
|
29
29
|
data: import("./common-helpers").OutputMarker;
|
|
30
30
|
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
data?: unknown;
|
|
31
32
|
status: "success";
|
|
32
|
-
data: {
|
|
33
|
-
[x: string]: any;
|
|
34
|
-
[x: number]: any;
|
|
35
|
-
[x: symbol]: any;
|
|
36
|
-
};
|
|
37
33
|
}, {
|
|
34
|
+
data?: unknown;
|
|
38
35
|
status: "success";
|
|
39
|
-
data: {
|
|
40
|
-
[x: string]: any;
|
|
41
|
-
[x: number]: any;
|
|
42
|
-
[x: symbol]: any;
|
|
43
|
-
};
|
|
44
36
|
}> & {
|
|
45
37
|
_def: z.ZodObjectDef<{
|
|
46
38
|
status: z.ZodLiteral<"success">;
|
|
@@ -49,44 +41,24 @@ export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown,
|
|
|
49
41
|
status: z.ZodLiteral<"success">;
|
|
50
42
|
data: import("./common-helpers").OutputMarker;
|
|
51
43
|
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
data?: unknown;
|
|
52
45
|
status: "success";
|
|
53
|
-
data: {
|
|
54
|
-
[x: string]: any;
|
|
55
|
-
[x: number]: any;
|
|
56
|
-
[x: symbol]: any;
|
|
57
|
-
};
|
|
58
46
|
}, {
|
|
47
|
+
data?: unknown;
|
|
59
48
|
status: "success";
|
|
60
|
-
data: {
|
|
61
|
-
[x: string]: any;
|
|
62
|
-
[x: number]: any;
|
|
63
|
-
[x: symbol]: any;
|
|
64
|
-
};
|
|
65
49
|
}>>;
|
|
66
50
|
example: (example: {
|
|
51
|
+
data?: unknown;
|
|
67
52
|
status: "success";
|
|
68
|
-
data: {
|
|
69
|
-
[x: string]: any;
|
|
70
|
-
[x: number]: any;
|
|
71
|
-
[x: symbol]: any;
|
|
72
|
-
};
|
|
73
53
|
}) => z.ZodObject<{
|
|
74
54
|
status: z.ZodLiteral<"success">;
|
|
75
55
|
data: import("./common-helpers").OutputMarker;
|
|
76
56
|
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
data?: unknown;
|
|
77
58
|
status: "success";
|
|
78
|
-
data: {
|
|
79
|
-
[x: string]: any;
|
|
80
|
-
[x: number]: any;
|
|
81
|
-
[x: symbol]: any;
|
|
82
|
-
};
|
|
83
59
|
}, {
|
|
60
|
+
data?: unknown;
|
|
84
61
|
status: "success";
|
|
85
|
-
data: {
|
|
86
|
-
[x: string]: any;
|
|
87
|
-
[x: number]: any;
|
|
88
|
-
[x: symbol]: any;
|
|
89
|
-
};
|
|
90
62
|
}> & any;
|
|
91
63
|
}>, ApiResponse<z.ZodObject<{
|
|
92
64
|
status: z.ZodLiteral<"error">;
|
|
@@ -162,5 +134,5 @@ export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown,
|
|
|
162
134
|
message: string;
|
|
163
135
|
};
|
|
164
136
|
}> & any;
|
|
165
|
-
}
|
|
137
|
+
}>, null, {}>;
|
|
166
138
|
export {};
|
|
@@ -8,8 +8,8 @@ var _a, _EndpointsFactory_create;
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.defaultEndpointsFactory = exports.EndpointsFactory = void 0;
|
|
10
10
|
const zod_1 = require("zod");
|
|
11
|
-
const endpoint_1 = require("./endpoint");
|
|
12
11
|
const common_helpers_1 = require("./common-helpers");
|
|
12
|
+
const endpoint_1 = require("./endpoint");
|
|
13
13
|
const middleware_1 = require("./middleware");
|
|
14
14
|
const mime_1 = require("./mime");
|
|
15
15
|
const result_handler_1 = require("./result-handler");
|
|
@@ -18,7 +18,6 @@ class EndpointsFactory {
|
|
|
18
18
|
this.resultHandler = resultHandler;
|
|
19
19
|
this.middlewares = [];
|
|
20
20
|
this.use = this.addExpressMiddleware;
|
|
21
|
-
this.resultHandler = resultHandler;
|
|
22
21
|
}
|
|
23
22
|
addMiddleware(definition) {
|
|
24
23
|
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(definition), this.resultHandler);
|
|
@@ -46,14 +45,15 @@ class EndpointsFactory {
|
|
|
46
45
|
middleware: async () => options,
|
|
47
46
|
})), this.resultHandler);
|
|
48
47
|
}
|
|
49
|
-
build({ input,
|
|
48
|
+
build({ input, handler, description, output: outputSchema, ...rest }) {
|
|
49
|
+
const { middlewares, resultHandler } = this;
|
|
50
50
|
return new endpoint_1.Endpoint({
|
|
51
51
|
handler,
|
|
52
52
|
description,
|
|
53
|
-
middlewares
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
middlewares,
|
|
54
|
+
outputSchema,
|
|
55
|
+
resultHandler,
|
|
56
|
+
inputSchema: (0, common_helpers_1.getFinalEndpointInputSchema)(middlewares, input),
|
|
57
57
|
mimeTypes: (0, common_helpers_1.hasUpload)(input) ? [mime_1.mimeMultipart] : [mime_1.mimeJson],
|
|
58
58
|
...rest,
|
|
59
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;;;;AACA,6BAAwB;AAExB,yCAA+C;
|
|
1
|
+
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;;;;AACA,6BAAwB;AAExB,qDAM0B;AAC1B,yCAA+C;AAE/C,6CAMsB;AACtB,iCAAiD;AACjD,qDAG0B;AAe1B,MAAa,gBAAgB;IAQ3B,YAAsB,aAAgD;QAAhD,kBAAa,GAAb,aAAa,CAAmC;QAF5D,gBAAW,GAAuB,EAAE,CAAC;QAgCxC,QAAG,GAAG,IAAI,CAAC,oBAAoB,CAAC;IA9BkC,CAAC;IAgBnE,aAAa,CAClB,UAAgD;QAEhD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EAMrB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAyC,CAAC,EAClE,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAIM,oBAAoB,CAKzB,UAAmC,EACnC,QAAgD;QAEhD,MAAM,WAAW,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,KAAI,CAAC,CAAC,GAAU,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QACnE,MAAM,QAAQ,GAA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,YAAY,EACpB,GAAG,IAAI,EAC2B;QAQlC,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAC5C,OAAO,IAAI,mBAAQ,CAAC;YAClB,OAAO;YACP,WAAW;YACX,WAAW;YACX,YAAY;YACZ,aAAa;YACb,WAAW,EAAE,IAAA,4CAA2B,EAAU,WAAW,EAAE,KAAK,CAAC;YACrE,SAAS,EAAE,IAAA,0BAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAa,CAAC,CAAC,CAAC,CAAC,CAAC,eAAQ,CAAC;YAC1D,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;AA3GD,4CA2GC;oFA3FG,WAA+B,EAC/B,aAAkD;IAElD,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAAwB,aAAa,CAAC,CAAC;IAC3E,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AAuFU,QAAA,uBAAuB,GAAG,IAAI,gBAAgB,CACzD,qCAAoB,CACrB,CAAC"}
|
package/dist/extend-zod.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/extend-zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAA8B;AAC9B,qDAA6C;AAC7C,uDAA+C;AAC/C,+CAAwC;AACxC,mDAA4C;AAE5C,sCAAoB;AACP,QAAA,IAAI,GAAG,qBAAO,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,GAAG,yBAAS,CAAC,MAAM,CAAC;AAEvC;;;;KAIK;AACQ,QAAA,IAAI,GAAG,aAAO,CAAC,MAAM,CAAC;AACtB,QAAA,MAAM,GAAG,0BAAS,CAAC,MAAM,CAAC;AAC1B,QAAA,OAAO,GAAG,4BAAU,CAAC,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAKoB;AAJlB,4GAAA,gBAAgB,OAAA;AAMlB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAClD,mDAAoE;AAArC,4GAAA,UAAU,OAAA;AACzC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,mDAA6E;AAApE,qHAAA,mBAAmB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAClD,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AAEpB,mCAAuD;AAA9C,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AACpC,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAChB,mCAA4E;AAAnE,sGAAA,YAAY,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACzD,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AAErB,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface MiddlewareDefinition<IN extends IOSchema, OPT, OUT extends Flat
|
|
|
15
15
|
input: IN;
|
|
16
16
|
middleware: Middleware<z.output<IN>, OPT, OUT>;
|
|
17
17
|
}
|
|
18
|
+
export declare type AnyMiddlewareDef = MiddlewareDefinition<IOSchema, any, any>;
|
|
18
19
|
export declare const createMiddleware: <IN extends IOSchema, OPT, OUT extends FlatObject>(definition: MiddlewareDefinition<IN, OPT, OUT>) => MiddlewareDefinition<IN, OPT, OUT>;
|
|
19
20
|
export declare type ExpressMiddleware<R extends Request, S extends Response> = (request: R, response: S, next: (error?: any) => void) => void | Promise<void>;
|
|
20
21
|
export interface ExpressMiddlewareFeatures<R extends Request, S extends Response, OUT extends FlatObject> {
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":";;;AA6BO,MAAM,gBAAgB,GAAG,CAK9B,UAA8C,EAC9C,EAAE,CAAC,UAAU,CAAC;AANH,QAAA,gBAAgB,oBAMb"}
|
|
@@ -26,6 +26,7 @@ export declare const depictAny: DepictHelper<z.ZodAny>;
|
|
|
26
26
|
export declare const depictUpload: DepictHelper<ZodUpload>;
|
|
27
27
|
export declare const depictFile: DepictHelper<ZodFile>;
|
|
28
28
|
export declare const depictUnion: DepictHelper<z.ZodUnion<[z.ZodTypeAny, ...z.ZodTypeAny[]]>>;
|
|
29
|
+
export declare const depictDiscriminatedUnion: DepictHelper<z.ZodDiscriminatedUnion<string, z.Primitive, z.ZodObject<any>>>;
|
|
29
30
|
export declare const depictIntersection: DepictHelper<z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>>;
|
|
30
31
|
export declare const depictOptionalOrNullable: DepictHelper<z.ZodOptional<any> | z.ZodNullable<any>>;
|
|
31
32
|
export declare const depictEnum: DepictHelper<z.ZodEnum<any> | z.ZodNativeEnum<any>>;
|
|
@@ -49,6 +50,12 @@ export declare const depictObjectProperties: ({ schema: { shape }, isResponse, }
|
|
|
49
50
|
export declare const depictEffect: DepictHelper<z.ZodEffects<z.ZodTypeAny>>;
|
|
50
51
|
export declare const depictIOExamples: <T extends IOSchema>(schema: T, isResponse: boolean, omitProps?: string[]) => MediaExamples;
|
|
51
52
|
export declare const depictIOParamExamples: <T extends IOSchema>(schema: T, isResponse: boolean, param: string) => MediaExamples;
|
|
53
|
+
export declare function extractObjectSchema(subject: IOSchema): z.AnyZodObject | (z.AnyZodObject & {
|
|
54
|
+
_def: z.ZodObjectDef<any, any, any> & import("./metadata").MetaDef<z.AnyZodObject>;
|
|
55
|
+
example: (example: {
|
|
56
|
+
[x: string]: any;
|
|
57
|
+
}) => z.AnyZodObject & any;
|
|
58
|
+
});
|
|
52
59
|
export declare const depictRequestParams: ({ path, method, endpoint, inputSources, }: ReqResDepictHelperCommonProps & {
|
|
53
60
|
inputSources: InputSources[Method];
|
|
54
61
|
}) => ParameterObject[];
|