express-zod-api 3.0.0 → 3.1.1
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 +50 -0
- package/README.md +55 -27
- package/dist/{helpers.d.ts → common-helpers.d.ts} +2 -0
- package/dist/{helpers.js → common-helpers.js} +16 -7
- package/dist/common-helpers.js.map +1 -0
- package/dist/config-type.d.ts +3 -2
- package/dist/config-type.js.map +1 -1
- package/dist/endpoint.d.ts +1 -1
- package/dist/endpoint.js +3 -3
- package/dist/endpoint.js.map +1 -1
- package/dist/endpoints-factory.d.ts +5 -5
- package/dist/file-schema.d.ts +1 -1
- package/dist/file-schema.js +3 -3
- package/dist/file-schema.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +2 -2
- package/dist/metadata.js.map +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/open-api-helpers.d.ts +24 -0
- package/dist/open-api-helpers.js +422 -0
- package/dist/open-api-helpers.js.map +1 -0
- package/dist/open-api.d.ts +2 -2
- package/dist/open-api.js +22 -386
- package/dist/open-api.js.map +1 -1
- package/dist/result-handler.d.ts +5 -5
- package/dist/result-handler.js +5 -5
- package/dist/result-handler.js.map +1 -1
- package/dist/routing.d.ts +2 -2
- package/dist/routing.js +13 -13
- package/dist/routing.js.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist-esm/{helpers.js → common-helpers.js} +14 -6
- package/dist-esm/common-helpers.js.map +1 -0
- package/dist-esm/config-type.js.map +1 -1
- package/dist-esm/endpoint.js +1 -1
- package/dist-esm/endpoint.js.map +1 -1
- package/dist-esm/file-schema.js +1 -1
- package/dist-esm/file-schema.js.map +1 -1
- package/dist-esm/index.js +1 -1
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/metadata.js +1 -1
- package/dist-esm/metadata.js.map +1 -1
- package/dist-esm/open-api-helpers.js +414 -0
- package/dist-esm/open-api-helpers.js.map +1 -0
- package/dist-esm/open-api.js +23 -387
- package/dist-esm/open-api.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/dist-esm/result-handler.js +1 -1
- package/dist-esm/result-handler.js.map +1 -1
- package/dist-esm/routing.js +13 -13
- package/dist-esm/routing.js.map +1 -1
- package/dist-esm/server.js +1 -1
- package/dist-esm/server.js.map +1 -1
- package/package.json +1 -1
- package/dist/helpers.js.map +0 -1
- package/dist-esm/helpers.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
## Version 3
|
|
4
4
|
|
|
5
|
+
### v3.1.1
|
|
6
|
+
|
|
7
|
+
- No changes. Releasing as 3.1.1 due to a typo in Readme I found after publishing 3.1.0.
|
|
8
|
+
|
|
9
|
+
### v3.1.0
|
|
10
|
+
|
|
11
|
+
- Feature #174: Route path params as the new input source.
|
|
12
|
+
- `request.params` is validated against the input schema.
|
|
13
|
+
- The schema for validating the path params can now be described along with other inputs.
|
|
14
|
+
- You no longer need a middleware like `paramsProviderMiddleware` to handle path params.
|
|
15
|
+
- The route path params are now reflected in the generated documentation.
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const routingExample: Routing = {
|
|
19
|
+
v1: {
|
|
20
|
+
user: {
|
|
21
|
+
// route path /v1/user/:id, where :id is the path param
|
|
22
|
+
":id": getUserEndpoint,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
const getUserEndpoint = endpointsFactory.build({
|
|
27
|
+
method: "get",
|
|
28
|
+
input: withMeta(
|
|
29
|
+
z.object({
|
|
30
|
+
// id is the route path param, always string
|
|
31
|
+
id: z.string().transform((value) => parseInt(value, 10)),
|
|
32
|
+
// other inputs (in query):
|
|
33
|
+
withExtendedInformation: z.boolean().optional(),
|
|
34
|
+
})
|
|
35
|
+
).example({
|
|
36
|
+
id: "12",
|
|
37
|
+
withExtendedInformation: true,
|
|
38
|
+
}),
|
|
39
|
+
// ...
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- The default configuration of `inputSources` has been changed.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
const newInputSourcesByDefault: InputSources = {
|
|
47
|
+
get: ["query", "params"],
|
|
48
|
+
post: ["body", "params", "files"],
|
|
49
|
+
put: ["body", "params"],
|
|
50
|
+
patch: ["body", "params"],
|
|
51
|
+
delete: ["body", "query", "params"],
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
5
55
|
### v3.0.0
|
|
6
56
|
|
|
7
57
|
- No changes. [November 20](https://en.wikipedia.org/wiki/Transgender_Day_of_Remembrance) release.
|
package/README.md
CHANGED
|
@@ -29,15 +29,16 @@ Start your API server with I/O schema validation and custom middlewares in minut
|
|
|
29
29
|
1. [Middlewares](#middlewares)
|
|
30
30
|
2. [Refinements](#refinements)
|
|
31
31
|
3. [Transformations](#transformations)
|
|
32
|
-
4. [
|
|
33
|
-
5. [
|
|
34
|
-
6. [
|
|
35
|
-
7. [
|
|
36
|
-
8. [
|
|
37
|
-
9. [
|
|
38
|
-
10. [
|
|
39
|
-
11. [
|
|
40
|
-
12. [
|
|
32
|
+
4. [Route path params](#route-path-params)
|
|
33
|
+
5. [Response customization](#response-customization)
|
|
34
|
+
6. [Non-object response](#non-object-response) including file downloads
|
|
35
|
+
7. [File uploads](#file-uploads)
|
|
36
|
+
8. [Customizing logger](#customizing-logger)
|
|
37
|
+
9. [Usage with your own express app](#usage-with-your-own-express-app)
|
|
38
|
+
10. [Multiple schemas for one route](#multiple-schemas-for-one-route)
|
|
39
|
+
11. [Customizing input sources](#customizing-input-sources)
|
|
40
|
+
12. [Exporting endpoint types to frontend](#exporting-endpoint-types-to-frontend)
|
|
41
|
+
13. [Creating a documentation](#creating-a-documentation)
|
|
41
42
|
5. [Known issues](#known-issues)
|
|
42
43
|
1. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
|
|
43
44
|
6. [Your input to my output](#your-input-to-my-output)
|
|
@@ -57,7 +58,7 @@ Therefore, many basic tasks can be accomplished faster and easier, in particular
|
|
|
57
58
|
you expect a number.
|
|
58
59
|
- Variables within an endpoint handler have types according to the declared schema, so your IDE and Typescript will
|
|
59
60
|
provide you with necessary hints to focus on bringing your vision to life.
|
|
60
|
-
- All of your endpoints can respond in a
|
|
61
|
+
- All of your endpoints can respond in a consistent way.
|
|
61
62
|
- The expected endpoint input and response types can be exported to the frontend, so you don't get confused about the
|
|
62
63
|
field names when you implement the client for your API.
|
|
63
64
|
- You can generate your API documentation in a Swagger / OpenAPI compatible format.
|
|
@@ -81,7 +82,7 @@ The object being validated is the combination of certain `request` properties.
|
|
|
81
82
|
It is available to the endpoint handler as the `input` parameter.
|
|
82
83
|
Middlewares have access to all `request` properties, they can provide endpoints with `options`.
|
|
83
84
|
The object returned by the endpoint handler is called `output`. It goes to the `ResultHandler` which is
|
|
84
|
-
responsible for
|
|
85
|
+
responsible for transmitting consistent responses containing the `output` or possible error.
|
|
85
86
|
Much can be customized to fit your needs.
|
|
86
87
|
|
|
87
88
|

|
|
@@ -205,38 +206,28 @@ You should receive the following response:
|
|
|
205
206
|
Middleware can authenticate using input or `request` headers, and can provide endpoint handlers with `options`.
|
|
206
207
|
Inputs of middlewares are also available to endpoint handlers within `input`.
|
|
207
208
|
|
|
208
|
-
Here is an example on how to provide
|
|
209
|
+
Here is an example on how to provide headers of the request.
|
|
209
210
|
|
|
210
211
|
```typescript
|
|
211
212
|
import { createMiddleware } from "express-zod-api";
|
|
212
213
|
|
|
213
|
-
const
|
|
214
|
+
const headersProviderMiddleware = createMiddleware({
|
|
214
215
|
input: z.object({}), // means no inputs
|
|
215
216
|
middleware: async ({ request }) => ({
|
|
216
|
-
|
|
217
|
+
headers: request.headers,
|
|
217
218
|
}),
|
|
218
219
|
});
|
|
219
220
|
```
|
|
220
221
|
|
|
221
|
-
Then, you can connect your endpoint to a path like `/user/:id`, where `id` is a parameter:
|
|
222
|
-
|
|
223
|
-
```typescript
|
|
224
|
-
const routing: Routing = {
|
|
225
|
-
user: {
|
|
226
|
-
":id": yourEndpoint,
|
|
227
|
-
},
|
|
228
|
-
};
|
|
229
|
-
```
|
|
230
|
-
|
|
231
222
|
By using `.addMiddleware()` method before `.build()` you can connect it to the endpoint:
|
|
232
223
|
|
|
233
224
|
```typescript
|
|
234
225
|
const yourEndpoint = defaultEndpointsFactory
|
|
235
|
-
.addMiddleware(
|
|
226
|
+
.addMiddleware(headersProviderMiddleware)
|
|
236
227
|
.build({
|
|
237
228
|
// ...,
|
|
238
229
|
handler: async ({ options }) => {
|
|
239
|
-
// options.
|
|
230
|
+
// options.headers === request.headers
|
|
240
231
|
},
|
|
241
232
|
});
|
|
242
233
|
```
|
|
@@ -322,9 +313,46 @@ const getUserEndpoint = endpointsFactory.build({
|
|
|
322
313
|
});
|
|
323
314
|
```
|
|
324
315
|
|
|
316
|
+
## Route path params
|
|
317
|
+
|
|
318
|
+
You can describe the route of the endpoint using parameters:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
import { Routing } from "express-zod-api";
|
|
322
|
+
|
|
323
|
+
const routing: Routing = {
|
|
324
|
+
v1: {
|
|
325
|
+
user: {
|
|
326
|
+
// route path /v1/user/:id, where :id is the path param
|
|
327
|
+
":id": getUserEndpoint,
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
You then need to specify these parameters in the endpoint input schema in the usual way:
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
const getUserEndpoint = endpointsFactory.build({
|
|
337
|
+
method: "get",
|
|
338
|
+
input: z.object({
|
|
339
|
+
// id is the route path param, always string
|
|
340
|
+
id: z.string().transform((value) => parseInt(value, 10)),
|
|
341
|
+
// other inputs (in query):
|
|
342
|
+
withExtendedInformation: z.boolean().optional(),
|
|
343
|
+
}),
|
|
344
|
+
output: z.object({
|
|
345
|
+
/* ... */
|
|
346
|
+
}),
|
|
347
|
+
handler: async ({ input: { id } }) => {
|
|
348
|
+
// id is the route path param, number
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
325
353
|
## Response customization
|
|
326
354
|
|
|
327
|
-
`ResultHandler` is responsible for
|
|
355
|
+
`ResultHandler` is responsible for transmitting consistent responses containing the endpoint output or an error.
|
|
328
356
|
The `defaultResultHandler` sets the HTTP status code and ensures the following type of the response:
|
|
329
357
|
|
|
330
358
|
```typescript
|
|
@@ -35,6 +35,8 @@ export declare const combinations: <T extends unknown>(a: T[], b: T[]) => {
|
|
|
35
35
|
type: "tuple";
|
|
36
36
|
value: [T, T][];
|
|
37
37
|
};
|
|
38
|
+
/** @see https://expressjs.com/en/guide/routing.html */
|
|
39
|
+
export declare function getRoutePathParams(path: string): string[];
|
|
38
40
|
export declare type ErrMessage = Exclude<Parameters<typeof z.ZodString.prototype.email>[0], undefined>;
|
|
39
41
|
export declare const errToObj: (message: ErrMessage | undefined) => {
|
|
40
42
|
message?: string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errToObj = exports.combinations = exports.getExamples = exports.getStatusCodeFromError = exports.getMessageFromError = exports.isLoggerConfig = exports.getInitialInput = exports.combineEndpointAndMiddlewareInputSchemas = exports.extractObjectSchema = exports.markOutput = void 0;
|
|
3
|
+
exports.errToObj = exports.getRoutePathParams = exports.combinations = exports.getExamples = exports.getStatusCodeFromError = exports.getMessageFromError = exports.isLoggerConfig = exports.getInitialInput = exports.combineEndpointAndMiddlewareInputSchemas = exports.extractObjectSchema = 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");
|
|
@@ -44,11 +44,11 @@ function areFilesAvailable(request) {
|
|
|
44
44
|
return "files" in request && isMultipart;
|
|
45
45
|
}
|
|
46
46
|
const defaultInputSources = {
|
|
47
|
-
get: ["query"],
|
|
48
|
-
post: ["body", "files"],
|
|
49
|
-
put: ["body"],
|
|
50
|
-
patch: ["body"],
|
|
51
|
-
delete: ["query", "
|
|
47
|
+
get: ["query", "params"],
|
|
48
|
+
post: ["body", "params", "files"],
|
|
49
|
+
put: ["body", "params"],
|
|
50
|
+
patch: ["body", "params"],
|
|
51
|
+
delete: ["body", "query", "params"],
|
|
52
52
|
};
|
|
53
53
|
const fallbackInputSource = defaultInputSources.delete;
|
|
54
54
|
function getInitialInput(request, inputAssignment) {
|
|
@@ -126,7 +126,16 @@ const combinations = (a, b) => {
|
|
|
126
126
|
return { type: "tuple", value: result };
|
|
127
127
|
};
|
|
128
128
|
exports.combinations = combinations;
|
|
129
|
+
/** @see https://expressjs.com/en/guide/routing.html */
|
|
130
|
+
function getRoutePathParams(path) {
|
|
131
|
+
const match = path.match(/:([A-Za-z0-9_]+)/g);
|
|
132
|
+
if (!match) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return match.map((param) => param.slice(1));
|
|
136
|
+
}
|
|
137
|
+
exports.getRoutePathParams = getRoutePathParams;
|
|
129
138
|
// the copy of the private Zod errorUtil.errToObj
|
|
130
139
|
const errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
131
140
|
exports.errToObj = errToObj;
|
|
132
|
-
//# sourceMappingURL=helpers.js.map
|
|
141
|
+
//# sourceMappingURL=common-helpers.js.map
|
|
@@ -0,0 +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;AAgDhC,MAAM,UAAU,GAAG,CAAC,MAAgB,EAAE,EAAE,CAAC,MAAsB,CAAC;AAA1D,QAAA,UAAU,cAAgD;AASvE,SAAgB,mBAAmB,CAA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V,OAAO,EAAE,CAAC;KACX;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC;AAND,gDAMC;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"}
|
package/dist/config-type.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextHandleFunction } from "connect";
|
|
2
|
-
import { Express } from "express";
|
|
2
|
+
import { Express, Request } from "express";
|
|
3
3
|
import fileUpload from "express-fileupload";
|
|
4
4
|
import { Logger } from "winston";
|
|
5
5
|
import { Method } from "./method";
|
|
@@ -24,7 +24,8 @@ export interface ServerConfig {
|
|
|
24
24
|
export interface AppConfig {
|
|
25
25
|
app: Express;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
declare type InputSource = keyof Pick<Request, "query" | "body" | "files" | "params">;
|
|
28
|
+
export declare type InputSources = Record<Method, InputSource[]>;
|
|
28
29
|
export interface CommonConfig {
|
|
29
30
|
cors: boolean;
|
|
30
31
|
errorHandler?: ResultHandlerDefinition<any, any>;
|
package/dist/config-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":";;;AAOa,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;
|
|
1
|
+
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":";;;AAOa,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;AAqDK,MAAM,YAAY,GAAG,CAG1B,MAAS,EACN,EAAE,CAAC,MAAM,CAAC;AAJF,QAAA,YAAY,gBAIV"}
|
package/dist/endpoint.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ 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 { IOSchema, Merge, OutputMarker, ReplaceMarkerInShape } from "./helpers";
|
|
6
|
+
import { IOSchema, Merge, OutputMarker, ReplaceMarkerInShape } from "./common-helpers";
|
|
7
7
|
import { Method, MethodsDefinition } from "./method";
|
|
8
8
|
import { MiddlewareDefinition } from "./middleware";
|
|
9
9
|
import { ResultHandlerDefinition } from "./result-handler";
|
package/dist/endpoint.js
CHANGED
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.Endpoint = exports.AbstractEndpoint = void 0;
|
|
10
10
|
const zod_1 = require("zod");
|
|
11
11
|
const errors_1 = require("./errors");
|
|
12
|
-
const
|
|
12
|
+
const common_helpers_1 = require("./common-helpers");
|
|
13
13
|
const result_handler_1 = require("./result-handler");
|
|
14
14
|
class AbstractEndpoint {
|
|
15
15
|
}
|
|
@@ -22,7 +22,7 @@ class Endpoint extends AbstractEndpoint {
|
|
|
22
22
|
this.methods = [];
|
|
23
23
|
this.middlewares = [];
|
|
24
24
|
this.middlewares = middlewares;
|
|
25
|
-
this.inputSchema = (0,
|
|
25
|
+
this.inputSchema = (0, common_helpers_1.combineEndpointAndMiddlewareInputSchemas)(inputSchema, middlewares);
|
|
26
26
|
this.mimeTypes = mimeTypes;
|
|
27
27
|
this.outputSchema = outputSchema;
|
|
28
28
|
this.handler = handler;
|
|
@@ -71,7 +71,7 @@ class Endpoint extends AbstractEndpoint {
|
|
|
71
71
|
if (request.method === "OPTIONS") {
|
|
72
72
|
return response.end();
|
|
73
73
|
}
|
|
74
|
-
const initialInput = (0,
|
|
74
|
+
const initialInput = (0, common_helpers_1.getInitialInput)(request, config.inputSources);
|
|
75
75
|
try {
|
|
76
76
|
const { input, options, isStreamClosed } = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_runMiddlewares).call(this, {
|
|
77
77
|
input: { ...initialInput },
|
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,qDAO0B;AAG1B,qDAA8E;AAQ9E,MAAsB,gBAAgB;CAgBrC;AAhBD,4CAgBC;AA6DD,kCAAkC;AAClC,MAAa,QAQX,SAAQ,gBAAgB;IAcxB,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,OAAO,EACP,aAAa,EACb,WAAW,EACX,SAAS,EACT,GAAG,IAAI,EACwC;QAC/C,KAAK,EAAE,CAAC;;QAtBS,YAAO,GAAQ,EAAE,CAAC;QAClB,gBAAW,GAA0C,EAAE,CAAC;QAsBzE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,IAAA,yDAAwC,EACzD,WAAW,EACX,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,SAAS,IAAI,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AAU,CAAC,IAAI,8CAA8C,EACnF,OAAO,CACR,CAAC;YACF,MAAM;SACP;KACF;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC,iCAED,KAAK,uCAAqB,EACxB,KAAK,EACL,OAAO,EACP,MAAM,GAKP;IACC,OAAO,IAAI,CAAC,OAAO,CAAC;QAClB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;QACpC,OAAO;QACP,MAAM;KACP,CAAC,CAAC;AACL,CAAC,2BAED,KAAK,iCAAe,EAClB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,MAAM,GAQP;IACC,IAAI;QACF,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAC/B,KAAK;YACL,MAAM;YACN,OAAO;YACP,QAAQ;YACR,MAAM;YACN,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,KAAK,EAAE;YACtB,IAAA,kCAAiB,EAAC;gBAChB,MAAM;gBACN,QAAQ;gBACR,KAAK,EAAE,IAAI,2BAAkB,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;aAChD,CAAC,CAAC;SACJ;KACF;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ApiResponse } from "./api-response";
|
|
3
3
|
import { Endpoint, Handler } from "./endpoint";
|
|
4
|
-
import { FlatObject, IOSchema, Merge } from "./helpers";
|
|
4
|
+
import { FlatObject, IOSchema, Merge } from "./common-helpers";
|
|
5
5
|
import { Method, MethodsDefinition } from "./method";
|
|
6
6
|
import { MiddlewareDefinition } from "./middleware";
|
|
7
7
|
import { ResultHandlerDefinition } from "./result-handler";
|
|
@@ -22,7 +22,7 @@ export declare class EndpointsFactory<MwIN, MwOUT, POS extends ApiResponse, NEG
|
|
|
22
22
|
}
|
|
23
23
|
export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown, ApiResponse<z.ZodObject<{
|
|
24
24
|
status: z.ZodLiteral<"success">;
|
|
25
|
-
data: import("./helpers").OutputMarker;
|
|
25
|
+
data: import("./common-helpers").OutputMarker;
|
|
26
26
|
}, "strip", z.ZodTypeAny, {
|
|
27
27
|
status: "success";
|
|
28
28
|
data: {
|
|
@@ -40,10 +40,10 @@ export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown,
|
|
|
40
40
|
}> & {
|
|
41
41
|
_def: z.ZodObjectDef<{
|
|
42
42
|
status: z.ZodLiteral<"success">;
|
|
43
|
-
data: import("./helpers").OutputMarker;
|
|
43
|
+
data: import("./common-helpers").OutputMarker;
|
|
44
44
|
}, "strip", z.ZodTypeAny> & import("./metadata").MetaDef<z.ZodObject<{
|
|
45
45
|
status: z.ZodLiteral<"success">;
|
|
46
|
-
data: import("./helpers").OutputMarker;
|
|
46
|
+
data: import("./common-helpers").OutputMarker;
|
|
47
47
|
}, "strip", z.ZodTypeAny, {
|
|
48
48
|
status: "success";
|
|
49
49
|
data: {
|
|
@@ -68,7 +68,7 @@ export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown,
|
|
|
68
68
|
};
|
|
69
69
|
}) => z.ZodObject<{
|
|
70
70
|
status: z.ZodLiteral<"success">;
|
|
71
|
-
data: import("./helpers").OutputMarker;
|
|
71
|
+
data: import("./common-helpers").OutputMarker;
|
|
72
72
|
}, "strip", z.ZodTypeAny, {
|
|
73
73
|
status: "success";
|
|
74
74
|
data: {
|
package/dist/file-schema.d.ts
CHANGED
package/dist/file-schema.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZodFile = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const common_helpers_1 = require("./common-helpers");
|
|
6
6
|
const zodFileKind = "ZodFile";
|
|
7
7
|
const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
8
8
|
class ZodFile extends zod_1.ZodType {
|
|
@@ -10,11 +10,11 @@ class ZodFile extends zod_1.ZodType {
|
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.binary = (message) => new ZodFile({
|
|
12
12
|
...this._def,
|
|
13
|
-
checks: [...this._def.checks, { kind: "binary", ...(0,
|
|
13
|
+
checks: [...this._def.checks, { kind: "binary", ...(0, common_helpers_1.errToObj)(message) }],
|
|
14
14
|
});
|
|
15
15
|
this.base64 = (message) => new ZodFile({
|
|
16
16
|
...this._def,
|
|
17
|
-
checks: [...this._def.checks, { kind: "base64", ...(0,
|
|
17
|
+
checks: [...this._def.checks, { kind: "base64", ...(0, common_helpers_1.errToObj)(message) }],
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
_parse(input) {
|
package/dist/file-schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-schema.js","sourceRoot":"","sources":["../src/file-schema.ts"],"names":[],"mappings":";;;AAAA,6BASa;AACb,
|
|
1
|
+
{"version":3,"file":"file-schema.js","sourceRoot":"","sources":["../src/file-schema.ts"],"names":[],"mappings":";;;AAAA,6BASa;AACb,qDAAwD;AAExD,MAAM,WAAW,GAAG,SAAS,CAAC;AAiB9B,MAAM,WAAW,GACf,kEAAkE,CAAC;AAErE,MAAa,OAAQ,SAAQ,aAA2B;IAAxD;;QA2BE,WAAM,GAAG,CAAC,OAAoB,EAAE,EAAE,CAChC,IAAI,OAAO,CAAC;YACV,GAAG,IAAI,CAAC,IAAI;YACZ,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAA,yBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC;SACxE,CAAC,CAAC;QAEL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AAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;IACrE,CAAC;;AA7CH,0BAoDC;AALQ,cAAM,GAAG,GAAG,EAAE,CACnB,IAAI,OAAO,CAAC;IACV,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { createConfig, LoggerConfig } from "./config-type";
|
|
|
2
2
|
export { AbstractEndpoint, EndpointInput, EndpointOutput, EndpointResponse, } from "./endpoint";
|
|
3
3
|
export { Method } from "./method";
|
|
4
4
|
export { EndpointsFactory, defaultEndpointsFactory } from "./endpoints-factory";
|
|
5
|
-
export { IOSchema, FlatObject, markOutput } from "./helpers";
|
|
5
|
+
export { IOSchema, FlatObject, markOutput } from "./common-helpers";
|
|
6
6
|
export { createApiResponse } from "./api-response";
|
|
7
7
|
export { createLogger } from "./logger";
|
|
8
8
|
export { createMiddleware } from "./middleware";
|
package/dist/index.js
CHANGED
|
@@ -30,8 +30,8 @@ Object.defineProperty(exports, "AbstractEndpoint", { enumerable: true, get: func
|
|
|
30
30
|
var endpoints_factory_1 = require("./endpoints-factory");
|
|
31
31
|
Object.defineProperty(exports, "EndpointsFactory", { enumerable: true, get: function () { return endpoints_factory_1.EndpointsFactory; } });
|
|
32
32
|
Object.defineProperty(exports, "defaultEndpointsFactory", { enumerable: true, get: function () { return endpoints_factory_1.defaultEndpointsFactory; } });
|
|
33
|
-
var
|
|
34
|
-
Object.defineProperty(exports, "markOutput", { enumerable: true, get: function () { return
|
|
33
|
+
var common_helpers_1 = require("./common-helpers");
|
|
34
|
+
Object.defineProperty(exports, "markOutput", { enumerable: true, get: function () { return common_helpers_1.markOutput; } });
|
|
35
35
|
var api_response_1 = require("./api-response");
|
|
36
36
|
Object.defineProperty(exports, "createApiResponse", { enumerable: true, get: function () { return api_response_1.createApiResponse; } });
|
|
37
37
|
var logger_1 = require("./logger");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,qCAAqD;AAAnC,0GAAA,eAAe,OAAA;AACjC,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;AAEjB,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
|
package/dist/metadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.copyMeta = exports.getMeta = exports.hasMeta = exports.withMeta = exports.metaProp = void 0;
|
|
4
|
-
const
|
|
4
|
+
const common_helpers_1 = require("./common-helpers");
|
|
5
5
|
const ramda_1 = require("ramda");
|
|
6
6
|
exports.metaProp = "expressZodApiMeta";
|
|
7
7
|
const withMeta = (schema) => {
|
|
@@ -41,7 +41,7 @@ const copyMeta = (src, dest) => {
|
|
|
41
41
|
}
|
|
42
42
|
dest = (0, exports.withMeta)(dest);
|
|
43
43
|
const def = dest._def;
|
|
44
|
-
const examplesCombinations = (0,
|
|
44
|
+
const examplesCombinations = (0, common_helpers_1.combinations)(def[exports.metaProp].examples, src._def[exports.metaProp].examples);
|
|
45
45
|
// general deep merge except examples
|
|
46
46
|
def[exports.metaProp] = (0, ramda_1.mergeDeepRight)({ ...def[exports.metaProp], examples: [] }, { ...src._def[exports.metaProp], examples: [] });
|
|
47
47
|
if (examplesCombinations.type === "single") {
|
package/dist/metadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD,iCAAuC;AAE1B,QAAA,QAAQ,GAAG,mBAAmB,CAAC;AAqBrC,MAAM,QAAQ,GAAG,CAAyB,MAAS,EAAE,EAAE;IAC5D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAkB,CAAC;IACtC,GAAG,CAAC,gBAAQ,CAAC,GAAG,GAAG,CAAC,gBAAQ,CA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QACjB,OAAO,IAAI,CAAC;KACb;IACD,IAAI,GAAG,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAC;IACtB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAkB,CAAC;IACpC,MAAM,oBAAoB,GAAG,IAAA,6BAAY,EACvC,GAAG,CAAC,gBAAQ,CAAC,CAAC,QAAQ,EACtB,GAAG,CAAC,IAAI,CAAC,gBAAQ,CAAC,CAAC,QAAQ,CAC5B,CAAC;IACF,qCAAqC;IACrC,GAAG,CAAC,gBAAQ,CAAC,GAAG,IAAA,sBAAc,EAC5B,EAAE,GAAG,GAAG,CAAC,gBAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,EAClC,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,gBAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CACxC,CAAC;IACF,IAAI,oBAAoB,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC1C,GAAG,CAAC,gBAAQ,CAAC,CAAC,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAAC;KACrD;SAAM;QACL,KAAK,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,oBAAoB,CAAC,KAAK,EAAE;YAClE,GAAG,CAAC,gBAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CACzB,IAAA,sBAAc,EAAC,EAAE,GAAG,WAAW,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CACtD,CAAC;SACH;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA5BW,QAAA,QAAQ,YA4BnB"}
|
package/dist/middleware.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Request, Response } from "express";
|
|
2
2
|
import { Logger } from "winston";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { FlatObject, IOSchema } from "./helpers";
|
|
4
|
+
import { FlatObject, IOSchema } from "./common-helpers";
|
|
5
5
|
interface MiddlewareParams<IN, OPT> {
|
|
6
6
|
input: IN;
|
|
7
7
|
options: OPT;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ParameterObject, SchemaObject } from "openapi3-ts";
|
|
2
|
+
import { RequestBodyObject, ResponseObject } from "openapi3-ts/src/model/OpenApi";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { AbstractEndpoint } from "./endpoint";
|
|
5
|
+
import { Method } from "./method";
|
|
6
|
+
declare type DepictHelper<T extends z.ZodType<any>> = (params: {
|
|
7
|
+
schema: T;
|
|
8
|
+
initial?: SchemaObject;
|
|
9
|
+
isResponse: boolean;
|
|
10
|
+
}) => SchemaObject;
|
|
11
|
+
interface ReqResDepictHelperCommonProps {
|
|
12
|
+
method: Method;
|
|
13
|
+
path: string;
|
|
14
|
+
endpoint: AbstractEndpoint;
|
|
15
|
+
}
|
|
16
|
+
export declare const depictRequestParams: ({ path, method, endpoint, }: ReqResDepictHelperCommonProps) => ParameterObject[];
|
|
17
|
+
export declare const depictSchema: DepictHelper<z.ZodTypeAny>;
|
|
18
|
+
export declare const excludeParamsFromDepiction: (depicted: SchemaObject, pathParams: string[]) => SchemaObject;
|
|
19
|
+
export declare const depictResponse: ({ method, path, description, endpoint, isPositive, }: ReqResDepictHelperCommonProps & {
|
|
20
|
+
description: string;
|
|
21
|
+
isPositive: boolean;
|
|
22
|
+
}) => ResponseObject;
|
|
23
|
+
export declare const depictRequest: ({ method, path, endpoint, }: ReqResDepictHelperCommonProps) => RequestBodyObject;
|
|
24
|
+
export {};
|